Skip to content

Commit

Permalink
msgpack idl supporting
Browse files Browse the repository at this point in the history
Signed-off-by: Lyon Lu <[email protected]>
  • Loading branch information
lyonlu13 committed Oct 14, 2024
1 parent 8b0d3cc commit 67ba812
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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 Expand Up @@ -60,6 +61,7 @@ export const StructInput: FC<InputProps> = (props) => {
typeDefinition: { literalType },
value = '',
hasCollectionParent,
initialValue,
} = props;

const { jsonFormRenderable, parsedJson } = useMemo(() => {
Expand Down Expand Up @@ -99,6 +101,16 @@ export const StructInput: FC<InputProps> = (props) => {
setParamData(formData);
}, []);

useEffect(() => {
if (!jsonFormRenderable && initialValue) {
const value = initialValue.scalar?.binary?.value;
if (value) {
const parsedValue = msgpack.decode(value);
onChange(JSON.stringify(parsedValue));
}
}
}, [jsonFormRenderable, initialValue]);

return jsonFormRenderable ? (
<StyledCard error={error} label={label} name={name}>
<StyledForm
Expand Down
8 changes: 8 additions & 0 deletions 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,6 +80,13 @@ function processBinary(binary?: Core.IBinary | null) {
return 'invalid binary';
}

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

return {
tag: `${tag} (binary data not shown)`,
};
Expand Down
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 67ba812

Please sign in to comment.