Skip to content

Commit d1dc889

Browse files
lyonlu13ursucarina
andauthored
feat: Launch Form Msgpack IDL Supporting (#888)
* msgpack idl supporting Signed-off-by: Lyon Lu <[email protected]> * code review fix Signed-off-by: Lyon Lu <[email protected]> * fix test Signed-off-by: Lyon Lu <[email protected]> * fix test and error display Signed-off-by: Lyon Lu <[email protected]> * display update Signed-off-by: Lyon Lu <[email protected]> * typo Signed-off-by: Carina Ursu <[email protected]> --------- Signed-off-by: Lyon Lu <[email protected]> Signed-off-by: Carina Ursu <[email protected]> Co-authored-by: Carina Ursu <[email protected]>
1 parent 8b0d3cc commit d1dc889

File tree

8 files changed

+68
-7
lines changed

8 files changed

+68
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"dependencies": {
5757
"@commitlint/cli": "^17.3.0",
5858
"@commitlint/config-conventional": "^17.3.0",
59+
"@msgpack/msgpack": "^3.0.0-beta2",
5960
"@semantic-release/changelog": "^5.0.1",
6061
"@semantic-release/commit-analyzer": "^8.0.1",
6162
"@semantic-release/exec": "^6.0.3",

packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, { FC, useCallback, useMemo, useState } from 'react';
1+
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
22
import { Form } from '@rjsf/mui';
33
import validator from '@rjsf/validator-ajv8';
44
import styled from '@mui/system/styled';
5+
import * as msgpack from '@msgpack/msgpack';
56
import { InputProps } from '../types';
67
import { protobufValueToPrimitive, PrimitiveType } from '../inputHelpers/struct';
78
import { StyledCard } from './StyledCard';

packages/oss-console/src/components/Launch/LaunchForm/inputHelpers/struct.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Protobuf from '@clients/common/flyteidl/protobuf';
22
import Core from '@clients/common/flyteidl/core';
3+
import * as msgpack from '@msgpack/msgpack';
34
import { InputType, InputValue } from '../types';
45
import { structPath } from './constants';
56
import { ConverterInput, InputHelper, InputValidatorParams } from './types';
@@ -90,9 +91,25 @@ function objectToProtobufStruct(obj: Dictionary<any>): Protobuf.IStruct {
9091
return { fields };
9192
}
9293

94+
function parseBinary(binary: Core.IBinary): string {
95+
if (!binary.value) {
96+
throw new Error('Binary value is empty');
97+
}
98+
99+
if (binary.tag === 'msgpack') {
100+
return JSON.stringify(msgpack.decode(binary.value));
101+
}
102+
103+
// unsupported binary type, it might be temporary
104+
return '';
105+
}
106+
93107
function fromLiteral(literal: Core.ILiteral): InputValue {
94-
const structValue = extractLiteralWithCheck<Protobuf.IStruct>(literal, structPath);
108+
if (literal.scalar?.binary) {
109+
return parseBinary(literal.scalar.binary);
110+
}
95111

112+
const structValue = extractLiteralWithCheck<Protobuf.IStruct>(literal, structPath);
96113
const finalValue = formatParameterValues(InputType.Struct, protobufStructToObject(structValue));
97114
return finalValue;
98115
}

packages/oss-console/src/components/Literals/helpers.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-use-before-define */
22
import Protobuf from '@clients/common/flyteidl/protobuf';
33
import Core from '@clients/common/flyteidl/core';
4+
import * as msgpack from '@msgpack/msgpack';
45
import Long from 'long';
56
import cloneDeep from 'lodash/cloneDeep';
67
import { formatDateUTC, protobufDurationToHMS } from '../../common/formatters';
@@ -79,8 +80,23 @@ function processBinary(binary?: Core.IBinary | null) {
7980
return 'invalid binary';
8081
}
8182

83+
if (!binary.value) {
84+
return {
85+
tag: `${tag}`,
86+
value: '(empty)',
87+
};
88+
}
89+
90+
if (tag === 'msgpack') {
91+
return {
92+
tag: 'msgpack',
93+
value: msgpack.decode(binary.value),
94+
};
95+
}
96+
8297
return {
83-
tag: `${tag} (binary data not shown)`,
98+
tag: `${tag}`,
99+
value: "(binary data not shown)",
84100
};
85101
}
86102

packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import Core from '@clients/common/flyteidl/core';
2+
import { encode } from '@msgpack/msgpack';
23
import { TestCaseList } from '../types';
34

5+
const testJson = {
6+
test1: 1,
7+
test2: '2',
8+
test3: true,
9+
};
10+
411
const scalarBinaryTestCases: TestCaseList<Core.IBinary> = {
12+
NORMAL_MSGPACK: {
13+
value: { value: encode(testJson), tag: 'msgpack' },
14+
expected: { result_var: { tag: 'msgpack', value: testJson } },
15+
},
516
WITH_VAL: {
617
value: { value: new Uint8Array(), tag: 'tag1' },
7-
expected: { result_var: { tag: 'tag1 (binary data not shown)' } },
18+
expected: { result_var: { tag: 'tag1', value: '(binary data not shown)' } },
819
},
9-
INT_WITH_SMALL_LOW: {
10-
value: { tag: 'tag2' },
11-
expected: { result_var: { tag: 'tag2 (binary data not shown)' } },
20+
EMPTY_VALUE: {
21+
value: { tag: 'msgpack' },
22+
expected: { result_var: { tag: 'msgpack', value: '(empty)' } },
1223
},
1324
};
1425

packages/oss-console/src/test/setupTests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import '@testing-library/jest-dom';
2+
import { TextEncoder, TextDecoder } from 'util';
3+
4+
Object.assign(global, { TextDecoder, TextEncoder });
25

36
jest.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({
47
prism: {},

script/test/jest-setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
import '@testing-library/jest-dom';
2+
3+
import { TextEncoder, TextDecoder } from 'util';
4+
5+
Object.assign(global, { TextDecoder, TextEncoder });

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,13 @@ __metadata:
35013501
languageName: node
35023502
linkType: hard
35033503

3504+
"@msgpack/msgpack@npm:^3.0.0-beta2":
3505+
version: 3.0.0-beta2
3506+
resolution: "@msgpack/msgpack@npm:3.0.0-beta2"
3507+
checksum: d86e5d48146051952d6bea35a6cf733a401cf65ad5614d79689aa48c7076021737ca2c782978dd1b6c0c9c45888b246e379e45ae906179e3a0e8ef4ee6f221c1
3508+
languageName: node
3509+
linkType: hard
3510+
35043511
"@mswjs/cookies@npm:^0.2.2":
35053512
version: 0.2.2
35063513
resolution: "@mswjs/cookies@npm:0.2.2"
@@ -14907,6 +14914,7 @@ __metadata:
1490714914
dependencies:
1490814915
"@commitlint/cli": ^17.3.0
1490914916
"@commitlint/config-conventional": ^17.3.0
14917+
"@msgpack/msgpack": ^3.0.0-beta2
1491014918
"@semantic-release/changelog": ^5.0.1
1491114919
"@semantic-release/commit-analyzer": ^8.0.1
1491214920
"@semantic-release/exec": ^6.0.3

0 commit comments

Comments
 (0)