generated from Exabyte-io/template-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
SOF-6535: new JSONSchema logic #57
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
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
2c54a8c
update: TS interfaces
k0stik 7fd496c
chore: remove eslint comment
k0stik e0c6fc2
chore: test installation
k0stik e9f6f45
chore: add scripts to package exports
k0stik 111ec9e
chore: add scripts to files in package.json
k0stik 5c992a7
chore: add buildInterfaces to postinstall
k0stik af4dcb8
chore: change types file name
k0stik 99098c3
update: new JSONSchema logic
k0stik cb14401
chore: clean package.json
k0stik 28ce39d
chore: use new esse interface
k0stik ae2e2ad
chore: export all schema utils
k0stik c73e50c
chore: export esse chema
k0stik fd3b655
update: remove this.customJsonSchemaProperties functionality
k0stik d996141
chore: test old code
k0stik 6855d2d
chore: test old code
k0stik b3a5dad
chore: test old code
k0stik a0ad0bc
chore: use new esse
k0stik d594ee9
chore: fix files
k0stik 21bed98
chore: test
k0stik 8c133b3
chore: fix files
k0stik 957a84d
update: remove old schemas usage
k0stik 8d21d4b
chore: new deref lib
k0stik 145522d
chore: new deref lib deasync
k0stik 63c892a
chore: move buildInterfaces script
k0stik 4abe511
fix: compileTS script
k0stik 16e323a
fix: compileTS script
k0stik c361067
chore: export compileTs
k0stik aa6c81c
chore: export compileTs
k0stik ec689cc
chore: export schemas
k0stik da1d51e
chore: bin folder with scripts
k0stik 1403076
chore: import schemas for meteor
k0stik 8cc292c
chore: import schemas for meteor
k0stik caf2872
chore: clean package.json
k0stik d4e2de5
chore: resolve esse schemas
k0stik 63abf8f
chore: fix tests
k0stik 0a6d42f
fix: merge conflicts
k0stik e1255b7
chore: add docstrings
k0stik c6eff53
chore: updated esse
k0stik 743564d
chore: new esse
k0stik ba8ebb8
chore: new esse
k0stik 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,62 @@ | ||
| import { makeFlatSchemaKey, makeFlatSchemaRef } from "@exabyte-io/esse.js/lib/js/esse/schemaUtils"; | ||
| import fs from "fs/promises"; | ||
| import { compile } from "json-schema-to-typescript"; | ||
|
|
||
| /** | ||
| * Compiles ESSE JSON schemas to TypeScript interfaces/types | ||
| * @param {Object} globalSchema | ||
| * @param {String} savePath | ||
| * @returns {Promise<void>} | ||
| * @example | ||
| * await compileTS(esseSchema, "./dist/types.ts"); | ||
| */ | ||
| export async function compileTS(globalSchema, savePath) { | ||
| const preparedDefinitions = Object.entries(globalSchema.definitions).reduce( | ||
| (newDefinitions, [key, schema]) => { | ||
| if (schema.allOf && schema.properties) { | ||
| /** | ||
| * The current version of json-schema-to-typescript ignores properties if there is allOf array in the schema. | ||
| * To fix the issue here we are creating a separate schema from properties and add it to the allOf array | ||
| */ | ||
| return [ | ||
| ...newDefinitions, | ||
| [ | ||
| key, | ||
| { | ||
| ...schema, | ||
| allOf: [ | ||
| ...schema.allOf, | ||
| makeFlatSchemaRef(`${schema.schemaId}-properties`), | ||
| ], | ||
| properties: null, | ||
| }, | ||
| ], | ||
| [ | ||
| makeFlatSchemaKey(`${schema.schemaId}-properties`), | ||
| { | ||
| schemaId: `${schema.schemaId}-properties`, | ||
| type: "object", | ||
| properties: schema.properties, | ||
| }, | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| return [...newDefinitions, [key, schema]]; | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| const compiled = await compile( | ||
| { | ||
| ...globalSchema, | ||
| definitions: Object.fromEntries(preparedDefinitions), | ||
| }, | ||
| "", | ||
| { | ||
| unreachableDefinitions: true, | ||
| }, | ||
| ); | ||
|
|
||
| await fs.writeFile(savePath, compiled); | ||
| } | ||
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.