Skip to content

Commit

Permalink
feat: Launch Form Msgpack IDL Supporting (#888)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
lyonlu13 and ursucarina authored Oct 17, 2024
1 parent 8b0d3cc commit d1dc889
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@msgpack/msgpack": "^3.0.0-beta2",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/exec": "^6.0.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, useCallback, useMemo, useState } from 'react';
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { Form } from '@rjsf/mui';
import validator from '@rjsf/validator-ajv8';
import styled from '@mui/system/styled';
import * as msgpack from '@msgpack/msgpack';
import { InputProps } from '../types';
import { protobufValueToPrimitive, PrimitiveType } from '../inputHelpers/struct';
import { StyledCard } from './StyledCard';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Protobuf from '@clients/common/flyteidl/protobuf';
import Core from '@clients/common/flyteidl/core';
import * as msgpack from '@msgpack/msgpack';
import { InputType, InputValue } from '../types';
import { structPath } from './constants';
import { ConverterInput, InputHelper, InputValidatorParams } from './types';
Expand Down Expand Up @@ -90,9 +91,25 @@ function objectToProtobufStruct(obj: Dictionary<any>): Protobuf.IStruct {
return { fields };
}

function parseBinary(binary: Core.IBinary): string {
if (!binary.value) {
throw new Error('Binary value is empty');
}

if (binary.tag === 'msgpack') {
return JSON.stringify(msgpack.decode(binary.value));
}

// unsupported binary type, it might be temporary
return '';
}

function fromLiteral(literal: Core.ILiteral): InputValue {
const structValue = extractLiteralWithCheck<Protobuf.IStruct>(literal, structPath);
if (literal.scalar?.binary) {
return parseBinary(literal.scalar.binary);
}

const structValue = extractLiteralWithCheck<Protobuf.IStruct>(literal, structPath);
const finalValue = formatParameterValues(InputType.Struct, protobufStructToObject(structValue));
return finalValue;
}
Expand Down
18 changes: 17 additions & 1 deletion packages/oss-console/src/components/Literals/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-use-before-define */
import Protobuf from '@clients/common/flyteidl/protobuf';
import Core from '@clients/common/flyteidl/core';
import * as msgpack from '@msgpack/msgpack';
import Long from 'long';
import cloneDeep from 'lodash/cloneDeep';
import { formatDateUTC, protobufDurationToHMS } from '../../common/formatters';
Expand Down Expand Up @@ -79,8 +80,23 @@ function processBinary(binary?: Core.IBinary | null) {
return 'invalid binary';
}

if (!binary.value) {
return {
tag: `${tag}`,
value: '(empty)',
};
}

if (tag === 'msgpack') {
return {
tag: 'msgpack',
value: msgpack.decode(binary.value),
};
}

return {
tag: `${tag} (binary data not shown)`,
tag: `${tag}`,
value: "(binary data not shown)",
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import Core from '@clients/common/flyteidl/core';
import { encode } from '@msgpack/msgpack';
import { TestCaseList } from '../types';

const testJson = {
test1: 1,
test2: '2',
test3: true,
};

const scalarBinaryTestCases: TestCaseList<Core.IBinary> = {
NORMAL_MSGPACK: {
value: { value: encode(testJson), tag: 'msgpack' },
expected: { result_var: { tag: 'msgpack', value: testJson } },
},
WITH_VAL: {
value: { value: new Uint8Array(), tag: 'tag1' },
expected: { result_var: { tag: 'tag1 (binary data not shown)' } },
expected: { result_var: { tag: 'tag1', value: '(binary data not shown)' } },
},
INT_WITH_SMALL_LOW: {
value: { tag: 'tag2' },
expected: { result_var: { tag: 'tag2 (binary data not shown)' } },
EMPTY_VALUE: {
value: { tag: 'msgpack' },
expected: { result_var: { tag: 'msgpack', value: '(empty)' } },
},
};

Expand Down
3 changes: 3 additions & 0 deletions packages/oss-console/src/test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import '@testing-library/jest-dom';
import { TextEncoder, TextDecoder } from 'util';

Object.assign(global, { TextDecoder, TextEncoder });

jest.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({
prism: {},
Expand Down
4 changes: 4 additions & 0 deletions script/test/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import '@testing-library/jest-dom';

import { TextEncoder, TextDecoder } from 'util';

Object.assign(global, { TextDecoder, TextEncoder });
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,13 @@ __metadata:
languageName: node
linkType: hard

"@msgpack/msgpack@npm:^3.0.0-beta2":
version: 3.0.0-beta2
resolution: "@msgpack/msgpack@npm:3.0.0-beta2"
checksum: d86e5d48146051952d6bea35a6cf733a401cf65ad5614d79689aa48c7076021737ca2c782978dd1b6c0c9c45888b246e379e45ae906179e3a0e8ef4ee6f221c1
languageName: node
linkType: hard

"@mswjs/cookies@npm:^0.2.2":
version: 0.2.2
resolution: "@mswjs/cookies@npm:0.2.2"
Expand Down Expand Up @@ -14907,6 +14914,7 @@ __metadata:
dependencies:
"@commitlint/cli": ^17.3.0
"@commitlint/config-conventional": ^17.3.0
"@msgpack/msgpack": ^3.0.0-beta2
"@semantic-release/changelog": ^5.0.1
"@semantic-release/commit-analyzer": ^8.0.1
"@semantic-release/exec": ^6.0.3
Expand Down

0 comments on commit d1dc889

Please sign in to comment.