-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pre-emptively decode binary literals (#889)
* Revert "feat: Launch Form Msgpack IDL Supporting (#888)" This reverts commit d1dc889. * Pre-emptively decode binary literals Signed-off-by: Carina Ursu <[email protected]> * lint fixes Signed-off-by: Carina Ursu <[email protected]> * fix literal.helpers.test.ts Signed-off-by: Carina Ursu <[email protected]> --------- Signed-off-by: Carina Ursu <[email protected]>
- Loading branch information
1 parent
d1dc889
commit 17ef806
Showing
19 changed files
with
342 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { google } from '@flyteorg/flyteidl/gen/pb-js/flyteidl'; | ||
|
||
/** Message classes for google entities */ | ||
|
||
export default google; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import core from '@clients/common/flyteidl/core'; | ||
import google from '@clients/common/flyteidl/google'; | ||
import $protobuf from 'protobufjs'; | ||
import { unpack } from 'msgpackr'; | ||
import isNil from 'lodash/isNil'; | ||
import entries from 'lodash/entries'; | ||
|
||
// Convert a JavaScript object to Protobuf Struct | ||
function convertToStruct(obj: any) { | ||
const struct = new google.protobuf.Struct({ | ||
fields: {}, | ||
}); | ||
|
||
entries(obj).forEach(([key, value]) => { | ||
struct.fields[key] = convertToValue(value); | ||
}); | ||
|
||
return struct; | ||
} | ||
|
||
// Convert values to Protobuf Value type | ||
function convertToValue(value: any) { | ||
const protoValue = new google.protobuf.Value(); | ||
|
||
if (Array.isArray(value)) { | ||
const listValues = value.map(convertToValue); | ||
protoValue.listValue = new google.protobuf.ListValue({ values: listValues }); | ||
} else if (typeof value === 'object' && value !== null) { | ||
protoValue.structValue = convertToStruct(value); | ||
} else if (typeof value === 'string') { | ||
protoValue.stringValue = value; | ||
} else if (typeof value === 'number') { | ||
protoValue.numberValue = value; | ||
} else if (typeof value === 'boolean') { | ||
protoValue.boolValue = value; | ||
} else if (value === null) { | ||
protoValue.nullValue = google.protobuf.NullValue.NULL_VALUE; | ||
} | ||
|
||
return protoValue; | ||
} | ||
|
||
const originalLiteralDecode = core.Literal.decode; | ||
// Overriding the decode method of Literal to convert msgpack binary literals to protobuf structs | ||
core.Literal.decode = (reader: $protobuf.Reader | Uint8Array, length?: number) => { | ||
const result = originalLiteralDecode(reader, length); | ||
|
||
if (result?.scalar?.binary?.tag === 'msgpack') { | ||
// We know that a binary literal with tag 'msgpack' is a STRUCT | ||
const value = result?.scalar?.binary?.value; | ||
const msgpackResult = isNil(value) ? value : unpack(value); | ||
// Convert the msgpack result to a protobuf struct | ||
const protobufStruct = convertToStruct(msgpackResult); | ||
|
||
return { | ||
metadata: result.metadata, | ||
hash: result.hash, | ||
scalar: { | ||
generic: protobufStruct, | ||
}, | ||
} as core.Literal; | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/oss-console/src/components/Launch/LaunchForm/LaunchFormComponents/StructInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.