From 03d1e4a9623ce6cbc25f2cfc8aa6f6484ac7f383 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Thu, 19 Mar 2026 13:22:30 +0100 Subject: [PATCH] Migrate command: Use sync-config-tools package --- cli/package.json | 2 +- cli/src/commands/migrate/sync-rules.ts | 6 ++-- cli/test/commands/migrate.test.ts | 44 ++++++++++++++++++++++++++ pnpm-lock.yaml | 16 +++++----- 4 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 cli/test/commands/migrate.test.ts diff --git a/cli/package.json b/cli/package.json index 11c039d..1ca2423 100644 --- a/cli/package.json +++ b/cli/package.json @@ -16,7 +16,7 @@ "@oclif/plugin-commands": "^4.1.40", "@oclif/plugin-help": "^6", "@oclif/plugin-plugins": "^5", - "@powersync-community/sync-config-rewriter": "^0.1.4", + "@powersync/sync-config-tools": "^0.1.1", "@powersync/cli-core": "workspace:*", "@powersync/cli-plugin-config-edit": "workspace:*", "@powersync/cli-plugin-docker": "workspace:*", diff --git a/cli/src/commands/migrate/sync-rules.ts b/cli/src/commands/migrate/sync-rules.ts index 6cd7049..e0b93d0 100644 --- a/cli/src/commands/migrate/sync-rules.ts +++ b/cli/src/commands/migrate/sync-rules.ts @@ -1,6 +1,6 @@ import { Flags, ux } from '@oclif/core'; -import { instantiate } from '@powersync-community/sync-config-rewriter'; import { SharedInstanceCommand, SYNC_FILENAME, YAML_SYNC_RULES_SCHEMA } from '@powersync/cli-core'; +import { instantiate } from '@powersync/sync-config-tools'; import { access, readFile, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -37,9 +37,7 @@ export default class MigrateSyncRules extends SharedInstanceCommand { const syncInputContent = await readFile(syncInputPath, 'utf8'); - const wasmBuffer = await readFile( - fileURLToPath(import.meta.resolve('@powersync-community/sync-config-rewriter/compiled.wasm')) - ); + const wasmBuffer = await readFile(fileURLToPath(import.meta.resolve('@powersync/sync-config-tools/compiled.wasm'))); const SyncStreamsRewriter = await instantiate(wasmBuffer); diff --git a/cli/test/commands/migrate.test.ts b/cli/test/commands/migrate.test.ts new file mode 100644 index 0000000..d6a34cd --- /dev/null +++ b/cli/test/commands/migrate.test.ts @@ -0,0 +1,44 @@ +import { runCommand } from '@oclif/test'; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { expect, onTestFinished, test } from 'vitest'; + +import { root } from '../helpers/root.js'; + +test('migrates from sync rules to sync streams', async () => { + const testDirectory = mkdtempSync(join(tmpdir(), 'migrate-test-')); + onTestFinished(() => rmSync(testDirectory, { recursive: true })); + + const inputFile = join(testDirectory, 'input.yaml'); + const outputFile = join(testDirectory, 'output.yaml'); + writeFileSync( + inputFile, + ` +bucket_definitions: + user_lists: + parameters: SELECT request.user_id() as user_id + data: + - SELECT * FROM lists WHERE owner_id = bucket.user_id +` + ); + + const result = await runCommand(`migrate sync-rules --input-file ${inputFile} --output-file ${outputFile}`, { root }); + expect(result.error).toBeUndefined(); + + const transformed = readFileSync(outputFile).toString('utf-8'); + expect(transformed) + .toStrictEqual(`# Adds YAML Schema support for VSCode users with the YAML extension installed. This enables features like validation and autocompletion based on the provided schema. +# yaml-language-server: $schema=https://unpkg.com/@powersync/service-sync-rules@latest/schema/sync_rules.json +config: + edition: 3 +streams: + # This Sync Stream has been translated from bucket definitions. There may be more efficient ways to express these queries. + # You can add additional queries to this list if you need them. + # For details, see the documentation: https://docs.powersync.com/sync/streams/overview + migrated_to_streams: + auto_subscribe: true + queries: + - SELECT * FROM lists WHERE owner_id = auth.user_id() +`); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c22c330..5bd6b85 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,9 +88,6 @@ importers: '@oclif/plugin-plugins': specifier: ^5 version: 5.4.55 - '@powersync-community/sync-config-rewriter': - specifier: ^0.1.4 - version: 0.1.4 '@powersync/cli-core': specifier: workspace:* version: link:../packages/cli-core @@ -115,6 +112,9 @@ importers: '@powersync/service-types': specifier: 'catalog:' version: 0.15.0 + '@powersync/sync-config-tools': + specifier: ^0.1.1 + version: 0.1.1 bson: specifier: ^7.2.0 version: 7.2.0 @@ -1605,9 +1605,6 @@ packages: resolution: {integrity: sha512-h104Kh26rR8tm+a3Qkc5S4VLYint3FE48as7+/5oCEcKR2idC/pF1G6AhIXKI+eHPJa/3J9i5z0Al47IeGHPkA==} engines: {node: '>=12'} - '@powersync-community/sync-config-rewriter@0.1.4': - resolution: {integrity: sha512-xJez2HuLg7XIdy6D5BMe1OyzAML7I80eBaYzHEsZlsmoAyp5xpoouWXFlnquQYM662phv+eYm3TtOuGXHk6ewQ==} - '@powersync/management-client@0.0.6': resolution: {integrity: sha512-s5tvk/3JUw9B1ry0X8YH30sMscqf5xkbGK0XNSZ4X6o0ATtJWxxe97Fgg1HoNTfN2W7lMSyTyZnBdf9jsVOluQ==} @@ -1629,6 +1626,9 @@ packages: '@powersync/service-types@0.15.0': resolution: {integrity: sha512-wIdHCT+vhwoJAMZ414/dwG8fd51+fEWnPbwShkwNE5XTwA0UGOT8aGyVZqzT8PT0sVos5famYYqG203Mjb7q6g==} + '@powersync/sync-config-tools@0.1.1': + resolution: {integrity: sha512-+lSmE6uGDUmUFc+XnYIatp746LMMLCw0DK+VyWnheuk4LRxENSqaZwLYySekWTDg9fBsXQJakAQ6sHHVMSTsbg==} + '@radix-ui/primitive@1.1.3': resolution: {integrity: sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==} @@ -8960,8 +8960,6 @@ snapshots: '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 - '@powersync-community/sync-config-rewriter@0.1.4': {} - '@powersync/management-client@0.0.6(@types/debug@4.1.12)(@types/json-schema@7.0.15)(jiti@2.6.1)(jsdom@27.4.0)(tsx@4.21.0)(yaml@2.8.2)': dependencies: '@journeyapps-labs/common-sdk': 1.0.3(@types/debug@4.1.12)(@types/json-schema@7.0.15)(jiti@2.6.1)(jsdom@27.4.0)(tsx@4.21.0)(yaml@2.8.2) @@ -9072,6 +9070,8 @@ snapshots: transitivePeerDependencies: - babel-plugin-macros + '@powersync/sync-config-tools@0.1.1': {} + '@radix-ui/primitive@1.1.3': {} '@radix-ui/react-accordion@1.2.12(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.4(react@19.2.4))(react@19.2.4)':