-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Packages/utils/schema #2877
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
Merged
heath-freenome
merged 23 commits into
rjsf-team:rjsf-v5
from
heath-freenome:packages-utils-schema
Jun 24, 2022
Merged
Packages/utils/schema #2877
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
29e4736
Implemented the utils package
heath-freenome 48cf1f1
- More changes
heath-freenome 66803a2
- Added all of the non-validation-based utilities and many of the tests
heath-freenome 18ec36f
- removed schema related files temporarily
heath-freenome 8b2a3a1
- revert `package-lock.json` for antd, core and playground
heath-freenome 8b5220e
- The schema utilities that require validation
heath-freenome b0e9010
- More changes
heath-freenome 150ff09
- completed conversion to Typescript with some changes that were needed
heath-freenome c8ad992
- Updated various files to make some parameters optional, to add gene…
heath-freenome dca2450
- Implemented createSchemaUtils
heath-freenome cbb27aa
- More fixes and adding missing generics
heath-freenome 39d9d44
- Converted all the schema based tests over still missing 100% coverage
heath-freenome 51dbca6
- Completed 100% unit testing
heath-freenome 1ead960
- Added documentation for most of the files and cleaned up some optio…
heath-freenome bbb3de2
- Completed all of the documentation of the schema-based utils
heath-freenome 251f850
- Changed the `_NAME` constants to `_KEY`
heath-freenome 7c6a348
- Added missing generics on a few types
heath-freenome fed0877
- Added `ERRORS_KEY` constant for use in validation
heath-freenome f3ef93a
- Fixed types based on implementation of validator
heath-freenome 97f40bc
- Added missing generic to the `ValidationData` type for `ErrorSchema`
heath-freenome 55ae809
- Fixed tests for the missing generic type
heath-freenome 5249a66
- Incorporated #2876 by making props for UISchemaSubmitButtonOptions …
heath-freenome c6217d3
- Added generic `<T>` to the return value of `toIdSchema()` and `toPa…
heath-freenome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
import { RJSFSchema, SchemaUtilsType, UiSchema, ValidatorType } from './types'; | ||
import { | ||
getDefaultFormState, | ||
getDisplayLabel, | ||
getMatchingOption, | ||
isFilesArray, | ||
isMultiSelect, | ||
isSelect, | ||
retrieveSchema, | ||
stubExistingAdditionalProperties, | ||
toIdSchema, | ||
toPathSchema, | ||
} from './schema'; | ||
|
||
export class SchemaUtils<T = any> implements SchemaUtilsType<T> { | ||
rootSchema: RJSFSchema; | ||
validator: ValidatorType; | ||
|
||
constructor(validator: ValidatorType, rootSchema: RJSFSchema) { | ||
this.rootSchema = rootSchema; | ||
this.validator = validator; | ||
} | ||
|
||
getDefaultFormState(schema: RJSFSchema, formData?: T, includeUndefinedValues = false): T | T[] | undefined { | ||
return getDefaultFormState<T>(this.validator, schema, formData, this.rootSchema, includeUndefinedValues); | ||
} | ||
|
||
getDisplayLabel<F = any>(schema: RJSFSchema, uiSchema: UiSchema<T, F>) { | ||
return getDisplayLabel<T, F>(this.validator, schema, uiSchema, this.rootSchema); | ||
} | ||
|
||
getMatchingOption(formData: T, options: RJSFSchema[]) { | ||
return getMatchingOption<T>(this.validator, formData, options, this.rootSchema); | ||
} | ||
|
||
isFilesArray<F = any>(schema: RJSFSchema, uiSchema: UiSchema<T, F>) { | ||
return isFilesArray<T, F>(this.validator, schema, uiSchema, this.rootSchema); | ||
} | ||
|
||
isMultiSelect(schema: RJSFSchema) { | ||
return isMultiSelect<T>(this.validator, schema, this.rootSchema); | ||
} | ||
|
||
isSelect(schema: RJSFSchema) { | ||
return isSelect<T>(this.validator, schema, this.rootSchema); | ||
} | ||
|
||
retrieveSchema(schema: RJSFSchema, rawFormData: T) { | ||
return retrieveSchema<T>(this.validator, schema, this.rootSchema, rawFormData); | ||
} | ||
|
||
stubExistingAdditionalProperties(schema: RJSFSchema, formData: T) { | ||
return stubExistingAdditionalProperties<T>(this.validator, schema, this.rootSchema, formData); | ||
} | ||
|
||
toIdSchema(schema: RJSFSchema, id: string, formData: T, idPrefix = 'root', idSeparator = '_') { | ||
return toIdSchema<T>(this.validator, schema, id, this.rootSchema, formData, idPrefix, idSeparator); | ||
} | ||
|
||
toPathSchema(schema: RJSFSchema, name: string, formData: T) { | ||
return toPathSchema<T>(this.validator, schema, name, this.rootSchema, formData); | ||
} | ||
} | ||
|
||
export default function createSchemaUtils<T = any>( | ||
validator: ValidatorType, rootSchema: RJSFSchema | ||
): SchemaUtilsType<T> { | ||
return new SchemaUtils<T>(validator, rootSchema); | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.