diff --git a/package.json b/package.json index e11218f62..1b79b153b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx b/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx index 208d39086..b000604b4 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx +++ b/packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx @@ -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'; diff --git a/packages/oss-console/src/components/Launch/LaunchForm/inputHelpers/struct.ts b/packages/oss-console/src/components/Launch/LaunchForm/inputHelpers/struct.ts index 05b439cfa..188641bc6 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/inputHelpers/struct.ts +++ b/packages/oss-console/src/components/Launch/LaunchForm/inputHelpers/struct.ts @@ -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'; @@ -90,9 +91,25 @@ function objectToProtobufStruct(obj: Dictionary): 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(literal, structPath); + if (literal.scalar?.binary) { + return parseBinary(literal.scalar.binary); + } + const structValue = extractLiteralWithCheck(literal, structPath); const finalValue = formatParameterValues(InputType.Struct, protobufStructToObject(structValue)); return finalValue; } diff --git a/packages/oss-console/src/components/Literals/helpers.ts b/packages/oss-console/src/components/Literals/helpers.ts index ea2b05b97..12b7f6ba0 100644 --- a/packages/oss-console/src/components/Literals/helpers.ts +++ b/packages/oss-console/src/components/Literals/helpers.ts @@ -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'; @@ -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)", }; } diff --git a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts index f2452e202..a40470242 100644 --- a/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts +++ b/packages/oss-console/src/components/Literals/test/helpers/genScalarBinaryTestCase.mock.ts @@ -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 = { + 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)' } }, }, }; diff --git a/packages/oss-console/src/test/setupTests.ts b/packages/oss-console/src/test/setupTests.ts index 808b7d01d..a12789316 100644 --- a/packages/oss-console/src/test/setupTests.ts +++ b/packages/oss-console/src/test/setupTests.ts @@ -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: {}, diff --git a/script/test/jest-setup.ts b/script/test/jest-setup.ts index 7b0828bfa..9e7e2d759 100644 --- a/script/test/jest-setup.ts +++ b/script/test/jest-setup.ts @@ -1 +1,5 @@ import '@testing-library/jest-dom'; + +import { TextEncoder, TextDecoder } from 'util'; + +Object.assign(global, { TextDecoder, TextEncoder }); diff --git a/yarn.lock b/yarn.lock index 8d1ce1572..1a43afe7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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