Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Launch Form Msgpack IDL Supporting #888

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to stringify binary.value and return that instead?

}

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 {
ursucarina marked this conversation as resolved.
Show resolved Hide resolved
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
Loading