-
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: Support Schema type in the Launch form (#110)
* feat: support schema as a launch input type * test: add value test cases for schema
- Loading branch information
Showing
13 changed files
with
446 additions
and
216 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Core } from 'flyteidl'; | ||
import { InputValue } from '../types'; | ||
import { schemaUriPath } from './constants'; | ||
import { ConverterInput, InputHelper, InputValidatorParams } from './types'; | ||
import { extractLiteralWithCheck } from './utils'; | ||
|
||
function fromLiteral(literal: Core.ILiteral): InputValue { | ||
return extractLiteralWithCheck<string>(literal, schemaUriPath); | ||
} | ||
|
||
function toLiteral({ typeDefinition, value }: ConverterInput): Core.ILiteral { | ||
const uri = typeof value === 'string' ? value : value.toString(); | ||
// Note: schema type may be undefined if user is working with a generic schema. | ||
const { | ||
literalType: { schema: type } | ||
} = typeDefinition; | ||
return { scalar: { schema: { type, uri } } }; | ||
} | ||
|
||
function validate({ value }: InputValidatorParams) { | ||
if (typeof value !== 'string') { | ||
throw new Error('Value is not a string'); | ||
} | ||
} | ||
|
||
export const schemaHelper: InputHelper = { | ||
fromLiteral, | ||
toLiteral, | ||
validate | ||
}; |
Oops, something went wrong.