-
Notifications
You must be signed in to change notification settings - Fork 18
JSON schema #257
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
base: main
Are you sure you want to change the base?
JSON schema #257
Conversation
🦋 Changeset detectedLatest commit: 866a7b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a JSON Schema for the PowerSync service configuration file to provide validations and autocomplete suggestions for self-hosters. The key changes include:
- Updating the configuration collector to use a precompiled JSON schema (PowerSyncConfigJSONSchema) for validation.
- Adding a new script to compile a merged JSON schema from various module configurations.
- Incorporating documentation, license, changelog, and changeset updates for the new schema package.
Reviewed Changes
Copilot reviewed 8 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/service-core/src/util/config/collectors/config-collector.ts | Updated schema validation to use PowerSyncConfigJSONSchema instead of generating a schema inline. |
packages/schema/src/scripts/compile-json-schema.ts | Added a script to merge module configuration options and generate a JSON schema file. |
packages/schema/src/index.ts | Minimal index file referencing the built service-types dependency. |
packages/schema/README.md | Documentation added for using the JSON schema in configuration files. |
packages/schema/LICENSE | New license file included as part of the schema package. |
packages/schema/CHANGELOG.md | Changelog entry for the new @powersync/service-schema package. |
.changeset/lemon-hotels-fold.md | Changeset entry introducing the schema export for PowerSyncConfig. |
Files not reviewed (6)
- .changeset/config.json: Language not supported
- packages/schema/.gitignore: Language not supported
- packages/schema/package.json: Language not supported
- packages/schema/tsconfig.json: Language not supported
- packages/types/package.json: Language not supported
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)
packages/service-core/src/util/config/collectors/config-collector.ts:26
- The change from generating the schema using ts-codec to directly using configFile.PowerSyncConfigJSONSchema improves clarity, but please ensure that the precompiled JSON schema contains all the necessary metadata and validation rules previously generated dynamically.
const configSchemaValidator = schema.parseJSONSchema(configFile.PowerSyncConfigJSONSchema).validator();
packages/schema/src/scripts/compile-json-schema.ts:43
- Consider adding error handling for the file write operation to gracefully handle potential file system issues during the schema compilation process.
fs.writeFileSync(path.join(schemaDir, 'powersync-config.json'), JSON.stringify(mergedConfigSchema, null, '\t'));
Overview
This adds a JSON Schema for the PowerSync service configuration file. This schema can be used by self hosters to validate and get autocomplete suggestions in their configuration YAML files.
This uses the existing PowerSyncConfig TS-Codec definition to generate the schema. Additional meta data is added in order to provided a description/comment for fields.
Our modular architecture uses a distributed configuration declaration. The
service-core
package declares a generic configuration structure, while the various modules declare the specific connection configuration. The schema generated here is a combination of the various module configuration options. This should give the best DX for validations and autocomplete.The schema is compiled and shipped in a new
@powersync/service-schema
NPM package. Users can use this package to fetch the JSON schema.E.g in VS Code:
# yaml-language-server: $schema=https://unpkg.com/@powersync/service-schema@latest/json-schema/powersync-config.json
autocomplete.mp4