Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

JSON schema #257

wants to merge 4 commits into from

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented May 7, 2025

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

Copy link

changeset-bot bot commented May 7, 2025

🦋 Changeset detected

Latest commit: 866a7b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-types Minor
@powersync/service-core Minor
@powersync/service-schema Minor
@powersync/lib-service-postgres Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-core-tests Patch
@powersync/service-image Minor
test-client Patch

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

@stevensJourney stevensJourney marked this pull request as ready for review May 7, 2025 13:39
@stevensJourney stevensJourney requested a review from Copilot May 7, 2025 13:40
Copy link

@Copilot Copilot AI left a 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'));

@stevensJourney stevensJourney requested a review from rkistner May 7, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant