@powersync/service-core 1.29.1 → 1.30.0-dev-20261127124135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @powersync/service-core
2
2
 
3
+ ## 1.30.0-dev-20261127124135
4
+
5
+ ### Patch Changes
6
+
7
+ - c47945b: Run internal storage migrations in the order of their names, instead of the order `fs.readdir` returns them in.
8
+ - Updated dependencies [67767c0]
9
+ - Updated dependencies [bc89e42]
10
+ - @powersync/service-sync-rules@0.45.2-dev-20261127124135
11
+ - @powersync/service-rust-types@0.1.0-dev-20261127124135
12
+ - @powersync/lib-services-framework@0.10.7-dev-20261127124135
13
+ - @powersync/service-rsocket-router@0.3.2-dev-20261127124135
14
+
3
15
  ## 1.29.1
4
16
 
5
17
  ### Patch Changes
@@ -1,5 +1,6 @@
1
1
  import { Command } from 'commander';
2
- import { logger } from '@powersync/lib-services-framework';
2
+ import { container, logger } from '@powersync/lib-services-framework';
3
+ import * as modules from '../modules/modules-index.js';
3
4
  import { registerCompactAction } from './commands/compact-action.js';
4
5
  import { registerMigrationAction } from './commands/migrate-action.js';
5
6
  import { registerStartAction } from './commands/start-action.js';
@@ -13,7 +14,18 @@ import { registerTestConnectionAction } from './commands/test-connection-action.
13
14
  */
14
15
  export function generateEntryProgram(startHandlers) {
15
16
  const entryProgram = new Command();
16
- entryProgram.name('powersync-runner').description('CLI to initiate a PowerSync service runner');
17
+ entryProgram
18
+ .name('powersync-runner')
19
+ .description('CLI to initiate a PowerSync service runner')
20
+ .option('--rust-addon <path>', 'Path to the Rust .node module');
21
+ entryProgram.hook('preAction', (program) => {
22
+ const addonPath = program.opts().rustAddon;
23
+ if (addonPath) {
24
+ container
25
+ .getImplementation(modules.ModuleManager)
26
+ .register([new modules.RustModule({ name: 'Rust', addonPath })]);
27
+ }
28
+ });
17
29
  registerTearDownAction(entryProgram);
18
30
  registerMigrationAction(entryProgram);
19
31
  registerCompactAction(entryProgram);
@@ -1 +1 @@
1
- {"version":3,"file":"cli-entry.js","sourceRoot":"","sources":["../../src/entry/cli-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,aAAyD;IAC5F,MAAM,YAAY,GAAG,IAAI,OAAO,EAAE,CAAC;IACnC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,WAAW,CAAC,4CAA4C,CAAC,CAAC;IAEhG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACrC,uBAAuB,CAAC,YAAY,CAAC,CAAC;IACtC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACpC,4BAA4B,CAAC,YAAY,CAAC,CAAC;IAE3C,IAAI,aAAa,EAAE,CAAC;QAClB,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,OAAO,EAAE,YAAY;QACrB;;WAEG;QACH,OAAO,EAAE,KAAK,UAAU,UAAU;YAChC,IAAI,CAAC;gBACH,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;YAClC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,CAAC,CAAC,CAAC;gBAChE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACH,C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CAAC,YAAY,CAAC,CAAC;IACpC,4BAA4B,CAAC,YAAY,CAAC,CAAC;IAE3C,IAAI,aAAa,EAAE,CAAC;QAClB,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,OAAO;QACL,OAAO,EAAE,YAAY;QACrB;;WAEG;QACH,OAAO,EAAE,KAAK,UAAU,UAAU;YAChC,IAAI,CAAC;gBACH,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;YAClC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,CAAC,CAAC,CAAC;gBAChE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -5,7 +5,9 @@ import { pathToFileURL } from 'url';
5
5
  export class AbstractPowerSyncMigrationAgent extends framework.AbstractMigrationAgent {
6
6
  async loadInternalMigrations() {
7
7
  const migrationsDir = this.getInternalScriptsDir();
8
- const files = await fs.readdir(migrationsDir);
8
+ // readdir does not guarantee any order, and migrations must run in the order of their names,
9
+ // which start with a timestamp.
10
+ const files = (await fs.readdir(migrationsDir)).sort();
9
11
  const migrations = files.filter((file) => {
10
12
  return '.js' == path.extname(file);
11
13
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PowerSyncMigrationManager.js","sourceRoot":"","sources":["../../src/migrations/PowerSyncMigrationManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAgBpC,MAAM,OAAgB,+BAAgC,SAAQ,SAAS,CAAC,sBAAkD;IAGxH,KAAK,CAAC,sBAAsB;QAC1B,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;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aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACvC,OAAO,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;YACjC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACxF,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;gBACnE,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import { RustAddon } from '@powersync/service-rust-types';
2
+ import { ServiceContextContainer } from '../system/ServiceContext.js';
3
+ import { AbstractModule, AbstractModuleOptions, TearDownOptions } from './AbstractModule.js';
4
+ export interface RustModuleOptions extends AbstractModuleOptions {
5
+ addonPath: string;
6
+ }
7
+ /**
8
+ * Loads Rust code for the PowerSync Service.
9
+ *
10
+ * The `.node` addon file to load is configurable, as different editions of the service use different Rust entrypoints.
11
+ */
12
+ export declare class RustModule extends AbstractModule {
13
+ #private;
14
+ constructor(options: RustModuleOptions);
15
+ initialize(_context: ServiceContextContainer): Promise<void>;
16
+ loadRust(): Promise<RustAddon.InitializedRustModule>;
17
+ teardown(_options: TearDownOptions): Promise<void>;
18
+ }
@@ -0,0 +1,25 @@
1
+ import { loadRustAddon } from '@powersync/service-rust-types';
2
+ import { AbstractModule } from './AbstractModule.js';
3
+ /**
4
+ * Loads Rust code for the PowerSync Service.
5
+ *
6
+ * The `.node` addon file to load is configurable, as different editions of the service use different Rust entrypoints.
7
+ */
8
+ export class RustModule extends AbstractModule {
9
+ #addonPath;
10
+ constructor(options) {
11
+ super(options);
12
+ this.#addonPath = options.addonPath;
13
+ }
14
+ async initialize(_context) {
15
+ await this.loadRust();
16
+ // Currently, we just initialize the module for testing purposes. In the future, we'd register Rust-backed
17
+ // implementations on the service container.
18
+ }
19
+ async loadRust() {
20
+ const addon = loadRustAddon(this.#addonPath);
21
+ return addon.initializeRust({ logger: this.logger });
22
+ }
23
+ async teardown(_options) { }
24
+ }
25
+ //# sourceMappingURL=RustModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RustModule.js","sourceRoot":"","sources":["../../src/modules/RustModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAE,cAAc,EAA0C,MAAM,qBAAqB,CAAC;AAM7F;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,cAAc;IACnC,UAAU,CAAS;IAE5B,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACtC,CAAC;IAEe,KAAK,CAAC,UAAU,CAAC,QAAiC;QAChE,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QAEtB,0GAA0G;QAC1G,4CAA4C;IAC9C,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,QAAyB,IAAkB,CAAC;CAC5E"}
@@ -1,3 +1,4 @@
1
1
  export * from './AbstractModule.js';
2
2
  export * from './loader.js';
3
3
  export * from './ModuleManager.js';
4
+ export * from './RustModule.js';
@@ -1,4 +1,5 @@
1
1
  export * from './AbstractModule.js';
2
2
  export * from './loader.js';
3
3
  export * from './ModuleManager.js';
4
+ export * from './RustModule.js';
4
5
  //# sourceMappingURL=modules-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modules-index.js","sourceRoot":"","sources":["../../src/modules/modules-index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"modules-index.js","sourceRoot":"","sources":["../../src/modules/modules-index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "1.29.1",
7
+ "version": "1.30.0-dev-20261127124135",
8
8
  "license": "Apache-2.0",
9
9
  "type": "module",
10
10
  "exports": "./dist/index.js",
@@ -32,10 +32,11 @@
32
32
  "uuid": "^14.0.0",
33
33
  "winston": "^3.13.0",
34
34
  "yaml": "^2.8.3",
35
- "@powersync/lib-services-framework": "0.10.6",
35
+ "@powersync/lib-services-framework": "0.10.7-dev-20261127124135",
36
36
  "@powersync/service-jsonbig": "0.18.0",
37
- "@powersync/service-rsocket-router": "0.3.1",
38
- "@powersync/service-sync-rules": "0.45.1",
37
+ "@powersync/service-rsocket-router": "0.3.2-dev-20261127124135",
38
+ "@powersync/service-rust-types": "0.1.0-dev-20261127124135",
39
+ "@powersync/service-sync-rules": "0.45.2-dev-20261127124135",
39
40
  "@powersync/service-types": "0.21.0"
40
41
  },
41
42
  "devDependencies": {
@@ -43,7 +44,8 @@
43
44
  "@types/lodash": "^4.17.5",
44
45
  "@types/negotiator": "^0.6.4",
45
46
  "fastify": "^5.12.7",
46
- "fastify-plugin": "^5.0.1"
47
+ "fastify-plugin": "^5.0.1",
48
+ "@powersync/service-core-tests": "0.18.6"
47
49
  },
48
50
  "scripts": {
49
51
  "build": "tsc -b",
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
 
3
- import { logger } from '@powersync/lib-services-framework';
3
+ import { container, logger } from '@powersync/lib-services-framework';
4
+ import * as modules from '../modules/modules-index.js';
4
5
  import * as utils from '../util/util-index.js';
5
6
  import { registerCompactAction } from './commands/compact-action.js';
6
7
  import { registerMigrationAction } from './commands/migrate-action.js';
@@ -16,7 +17,19 @@ import { registerTestConnectionAction } from './commands/test-connection-action.
16
17
  */
17
18
  export function generateEntryProgram(startHandlers?: Record<utils.ServiceRunner, utils.Runner>) {
18
19
  const entryProgram = new Command();
19
- entryProgram.name('powersync-runner').description('CLI to initiate a PowerSync service runner');
20
+ entryProgram
21
+ .name('powersync-runner')
22
+ .description('CLI to initiate a PowerSync service runner')
23
+ .option('--rust-addon <path>', 'Path to the Rust .node module');
24
+
25
+ entryProgram.hook('preAction', (program) => {
26
+ const addonPath: string | undefined = program.opts().rustAddon;
27
+ if (addonPath) {
28
+ container
29
+ .getImplementation(modules.ModuleManager)
30
+ .register([new modules.RustModule({ name: 'Rust', addonPath })]);
31
+ }
32
+ });
20
33
 
21
34
  registerTearDownAction(entryProgram);
22
35
  registerMigrationAction(entryProgram);
@@ -22,7 +22,9 @@ export abstract class AbstractPowerSyncMigrationAgent extends framework.Abstract
22
22
 
23
23
  async loadInternalMigrations(): Promise<framework.Migration<PowerSyncMigrationContext>[]> {
24
24
  const migrationsDir = this.getInternalScriptsDir();
25
- const files = await fs.readdir(migrationsDir);
25
+ // readdir does not guarantee any order, and migrations must run in the order of their names,
26
+ // which start with a timestamp.
27
+ const files = (await fs.readdir(migrationsDir)).sort();
26
28
  const migrations = files.filter((file) => {
27
29
  return '.js' == path.extname(file);
28
30
  });
@@ -0,0 +1,36 @@
1
+ import { loadRustAddon, RustAddon } from '@powersync/service-rust-types';
2
+
3
+ import { ServiceContextContainer } from '../system/ServiceContext.js';
4
+ import { AbstractModule, AbstractModuleOptions, TearDownOptions } from './AbstractModule.js';
5
+
6
+ export interface RustModuleOptions extends AbstractModuleOptions {
7
+ addonPath: string;
8
+ }
9
+
10
+ /**
11
+ * Loads Rust code for the PowerSync Service.
12
+ *
13
+ * The `.node` addon file to load is configurable, as different editions of the service use different Rust entrypoints.
14
+ */
15
+ export class RustModule extends AbstractModule {
16
+ readonly #addonPath: string;
17
+
18
+ constructor(options: RustModuleOptions) {
19
+ super(options);
20
+ this.#addonPath = options.addonPath;
21
+ }
22
+
23
+ public override async initialize(_context: ServiceContextContainer): Promise<void> {
24
+ await this.loadRust();
25
+
26
+ // Currently, we just initialize the module for testing purposes. In the future, we'd register Rust-backed
27
+ // implementations on the service container.
28
+ }
29
+
30
+ async loadRust(): Promise<RustAddon.InitializedRustModule> {
31
+ const addon = loadRustAddon(this.#addonPath);
32
+ return addon.initializeRust({ logger: this.logger });
33
+ }
34
+
35
+ public override async teardown(_options: TearDownOptions): Promise<void> {}
36
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './AbstractModule.js';
2
2
  export * from './loader.js';
3
3
  export * from './ModuleManager.js';
4
+ export * from './RustModule.js';
@@ -0,0 +1,57 @@
1
+ import { AbstractPowerSyncMigrationAgent } from '@/index.js';
2
+ import fs from 'fs/promises';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { afterEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ class DirectoryMigrationAgent extends AbstractPowerSyncMigrationAgent {
8
+ constructor(private dir: string) {
9
+ super();
10
+ }
11
+
12
+ getInternalScriptsDir(): string {
13
+ return this.dir;
14
+ }
15
+
16
+ get store(): never {
17
+ throw new Error('not used');
18
+ }
19
+
20
+ get locks(): never {
21
+ throw new Error('not used');
22
+ }
23
+
24
+ async [Symbol.asyncDispose]() {}
25
+ }
26
+
27
+ describe('loadInternalMigrations', () => {
28
+ afterEach(() => {
29
+ vi.restoreAllMocks();
30
+ });
31
+
32
+ it('returns migrations sorted by name, whatever order readdir lists them in', async () => {
33
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'powersync-migrations-'));
34
+ try {
35
+ const names = ['1684951997326-init', '1688556755264-initial-sync-rules', '1702295701188-sync-rule-state'];
36
+ for (const name of names) {
37
+ await fs.writeFile(path.join(dir, `${name}.js`), 'export const up = async () => {};\n');
38
+ }
39
+ await fs.writeFile(path.join(dir, 'README.md'), '');
40
+
41
+ // fs.readdir does not promise any order. Node happens to sort on common filesystems; other
42
+ // runtimes and filesystems return directory order, so list the files backwards here.
43
+ const readdir = fs.readdir;
44
+ vi.spyOn(fs, 'readdir').mockImplementation((async (dirPath: string) => {
45
+ const files = (await readdir(dirPath)) as string[];
46
+ return [...files].sort().reverse();
47
+ }) as typeof fs.readdir);
48
+
49
+ const migrations = await new DirectoryMigrationAgent(dir).loadInternalMigrations();
50
+
51
+ expect(fs.readdir).toHaveBeenCalled();
52
+ expect(migrations.map((m) => m.name)).toEqual(names);
53
+ } finally {
54
+ await fs.rm(dir, { recursive: true, force: true });
55
+ }
56
+ });
57
+ });
@@ -0,0 +1,30 @@
1
+ import { logger } from '@powersync/lib-services-framework';
2
+ import { expect, test, vi } from 'vitest';
3
+
4
+ import { modules } from '@/index.js';
5
+ import { resolveRustAddonPath } from '@powersync/service-rust-types/testing';
6
+
7
+ const rustModuleTest = test.extend('rustAddonPath', { scope: 'worker' }, async ({}, { onCleanup }) => {
8
+ const [path, cleanup] = await resolveRustAddonPath();
9
+ onCleanup(cleanup);
10
+
11
+ return path;
12
+ });
13
+
14
+ rustModuleTest('can initialize rust module', async ({ rustAddonPath }) => {
15
+ // The module's child logger inherits log() from the shared logger, so the Rust side binds this spy.
16
+ const log = vi.spyOn(logger, 'log');
17
+
18
+ const module = new modules.RustModule({ name: 'Rust', addonPath: rustAddonPath });
19
+ await module.loadRust();
20
+
21
+ // Log events are forwarded asynchronously through a threadsafe function, so we can't inspect them synchronously.
22
+ await vi.waitFor(() => {
23
+ expect(log).toHaveBeenCalledWith(
24
+ expect.objectContaining({
25
+ level: 'info',
26
+ message: 'Initializing Rust module for PowerSync Open Edition'
27
+ })
28
+ );
29
+ });
30
+ });
@@ -11,6 +11,9 @@
11
11
  "references": [
12
12
  {
13
13
  "path": "../"
14
+ },
15
+ {
16
+ "path": "../../service-core-tests"
14
17
  }
15
18
  ]
16
19
  }
package/tsconfig.json CHANGED
@@ -15,6 +15,9 @@
15
15
  {
16
16
  "path": "../jsonbig"
17
17
  },
18
+ {
19
+ "path": "../rust-types"
20
+ },
18
21
  {
19
22
  "path": "../sync-rules"
20
23
  },