@spooky-sync/core 1.0.0-beta.2 → 1.0.0-beta.3
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/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { a as renderOrderSql, c as serializeMergeRow, d as resolveRelations, f a
|
|
|
2
2
|
import { QueryBuilder, RecordId, baseFieldOfParam, cyrb53 } from "@spooky-sync/query-builder";
|
|
3
3
|
import { DateTime, Duration, RecordId as RecordId$1, Surreal, Uuid, applyDiagnostics, createRemoteEngines } from "surrealdb";
|
|
4
4
|
import pino from "pino";
|
|
5
|
-
import
|
|
5
|
+
import jsonPatch from "fast-json-patch";
|
|
6
6
|
import init, { Sp00kyProcessor } from "@spooky-sync/ssp-wasm";
|
|
7
7
|
import { decode, encode, isBlurhashValid } from "blurhash";
|
|
8
8
|
|
|
@@ -3659,8 +3659,8 @@ function trimHistory(history, cap) {
|
|
|
3659
3659
|
|
|
3660
3660
|
//#endregion
|
|
3661
3661
|
//#region src/modules/devtools/index.ts
|
|
3662
|
-
const CORE_VERSION = "1.0.0-beta.
|
|
3663
|
-
const WASM_VERSION = "1.0.0-beta.
|
|
3662
|
+
const CORE_VERSION = "1.0.0-beta.3";
|
|
3663
|
+
const WASM_VERSION = "1.0.0-beta.3";
|
|
3664
3664
|
const SURREAL_VERSION = "3.1.0";
|
|
3665
3665
|
var DevToolsService = class DevToolsService {
|
|
3666
3666
|
version = CORE_VERSION;
|
|
@@ -12497,7 +12497,8 @@ var SqliteCacheEngine = class {
|
|
|
12497
12497
|
});
|
|
12498
12498
|
}
|
|
12499
12499
|
async patch(table, id, patches) {
|
|
12500
|
-
const
|
|
12500
|
+
const existing = await this.getById(table, id) ?? { id: stableKey(id) };
|
|
12501
|
+
const next = jsonPatch.applyPatch(existing, patches).newDocument;
|
|
12501
12502
|
await this.upsert(table, id, next, "replace");
|
|
12502
12503
|
}
|
|
12503
12504
|
async delete(table, id) {
|
|
@@ -17618,7 +17619,7 @@ function createTabsCoordinator(config, s, host) {
|
|
|
17618
17619
|
return new TabsCoordinator({
|
|
17619
17620
|
tabId: s.tabId,
|
|
17620
17621
|
fingerprint: computeTabsFingerprint({
|
|
17621
|
-
coreVersion: "1.0.0-beta.
|
|
17622
|
+
coreVersion: "1.0.0-beta.3",
|
|
17622
17623
|
schemaHash: hash53(config.schemaSurql),
|
|
17623
17624
|
endpoint: config.database.endpoint ?? "",
|
|
17624
17625
|
namespace: config.database.namespace,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spooky-sync/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./dist/sqlite-worker.js"
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@spooky-sync/query-builder": "1.0.0-beta.
|
|
85
|
-
"@spooky-sync/ssp-wasm": "1.0.0-beta.
|
|
84
|
+
"@spooky-sync/query-builder": "1.0.0-beta.3",
|
|
85
|
+
"@spooky-sync/ssp-wasm": "1.0.0-beta.3",
|
|
86
86
|
"@sqlite.org/sqlite-wasm": "3.53.0-build1",
|
|
87
87
|
"@surrealdb/wasm": "^3.1.0",
|
|
88
88
|
"@surrealdb/wasm-native": "^3.3.4",
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
// has none of them; an access at module top level would throw on import);
|
|
8
8
|
// - `/sw` does not even pull in the `surrealdb` SDK.
|
|
9
9
|
// Each entry is then really imported in this Node process (no DOM globals)
|
|
10
|
-
// to catch top-level side effects the static scan cannot see
|
|
10
|
+
// to catch top-level side effects the static scan cannot see, and so is
|
|
11
|
+
// dist/index.js, which must load in Node ESM too. Prints the
|
|
11
12
|
// gzipped size of each entry (own code, and fully bundled with its npm
|
|
12
13
|
// dependencies when rolldown is reachable). Run after `tsdown` in the build.
|
|
13
14
|
import { readFileSync, existsSync } from 'node:fs';
|
|
@@ -133,6 +134,18 @@ for (const entry of ENTRIES) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
// The main entry carries the wasm engines, so none of the scans above apply,
|
|
138
|
+
// but it must still load in Node ESM: the client bindings import it during
|
|
139
|
+
// SSR and consumers import it from Vitest. Node resolves a CommonJS
|
|
140
|
+
// dependency through its `main`, where a named import the CJS export lexer
|
|
141
|
+
// cannot see fails at link time (`import { applyPatch } from 'fast-json-patch'`
|
|
142
|
+
// did, with "does not provide an export named 'applyPatch'").
|
|
143
|
+
try {
|
|
144
|
+
await import(pathToFileURL(join(dist, 'index.js')).href);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
problems.push(`index.js fails to import in Node: ${error?.message ?? error}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
136
149
|
// Fully bundled size (entry + npm deps, minified), when rolldown is reachable
|
|
137
150
|
// through tsdown. Informational only.
|
|
138
151
|
async function bundledGzip(entry) {
|
|
@@ -166,7 +179,7 @@ for (const s of sizes) {
|
|
|
166
179
|
if (problems.length > 0) {
|
|
167
180
|
for (const p of problems) console.error(`check-worker-entries: ${p}`);
|
|
168
181
|
console.error(
|
|
169
|
-
'The /pure, /live and /sw entries must stay free of wasm, the logger and DOM globals.'
|
|
182
|
+
'The /pure, /live and /sw entries must stay free of wasm, the logger and DOM globals, and every entry must import in Node.'
|
|
170
183
|
);
|
|
171
184
|
process.exit(1);
|
|
172
185
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
2
|
import { RecordId } from 'surrealdb';
|
|
3
3
|
import { pureWriteOpResult, SqliteCacheEngine } from './sqlite-cache-engine';
|
|
4
4
|
import { stubTransport } from './sqlite-transport.fixture';
|
|
@@ -570,6 +570,27 @@ describe('create() tx result shaping (fast path parity)', () => {
|
|
|
570
570
|
});
|
|
571
571
|
|
|
572
572
|
|
|
573
|
+
// patch() applies RFC6902 ops through fast-json-patch's default export (a
|
|
574
|
+
// named import broke loading dist/index.js in Node ESM). Exercise the call so
|
|
575
|
+
// a regression to an unusable binding fails here, not only at build time.
|
|
576
|
+
describe('SqliteCacheEngine.patch', () => {
|
|
577
|
+
it('applies RFC6902 ops read-modify-write and stores the result', async () => {
|
|
578
|
+
const engine = new SqliteCacheEngine({ namespace: 'n', database: 'd' } as any, makeLogger());
|
|
579
|
+
vi.spyOn(engine, 'getById').mockResolvedValue({ id: 'game:1', title: 'a', tags: ['x'] });
|
|
580
|
+
const upsert = vi.spyOn(engine, 'upsert').mockResolvedValue(undefined);
|
|
581
|
+
await engine.patch('game', 'game:1', [
|
|
582
|
+
{ op: 'replace', path: '/title', value: 'b' },
|
|
583
|
+
{ op: 'add', path: '/tags/-', value: 'y' },
|
|
584
|
+
]);
|
|
585
|
+
expect(upsert).toHaveBeenCalledWith(
|
|
586
|
+
'game',
|
|
587
|
+
'game:1',
|
|
588
|
+
{ id: 'game:1', title: 'b', tags: ['x', 'y'] },
|
|
589
|
+
'replace'
|
|
590
|
+
);
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
573
594
|
// The circuit snapshot + version scan the boot-time prime reads through this
|
|
574
595
|
// engine. Bytes and meta must round-trip as ONE batch (a reader must never see
|
|
575
596
|
// new bytes with old meta) and a table that does not exist yet scans as empty.
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { applyPatch
|
|
1
|
+
// Default import, not `{ applyPatch }`: fast-json-patch 3.x is CommonJS for
|
|
2
|
+
// Node (its ESM build is reachable only through the `module` field bundlers
|
|
3
|
+
// read) and fills `module.exports` via Object.assign, which Node's CJS export
|
|
4
|
+
// lexer cannot see. A named import makes `dist/index.js` throw a SyntaxError on
|
|
5
|
+
// load in Node ESM (SSR, Vitest). Same pattern as `pino` in services/logger.
|
|
6
|
+
import jsonPatch, { type Operation } from 'fast-json-patch';
|
|
2
7
|
import { DEFAULT_LOCAL_OP_TIMEOUT_MS, LocalOpTimeoutError } from './errors';
|
|
3
8
|
import { withTimeout } from '../../utils/index';
|
|
4
9
|
import type { QueryPlan, RelationPlan, WhereNode } from '@spooky-sync/query-builder';
|
|
@@ -998,7 +1003,7 @@ export class SqliteCacheEngine implements LocalStore {
|
|
|
998
1003
|
// RFC6902 (fast-json-patch) applied read-modify-write — SQLite's json_patch
|
|
999
1004
|
// is RFC7396 merge-patch and would misinterpret op arrays.
|
|
1000
1005
|
const existing = (await this.getById(table, id)) ?? { id: stableKey(id) };
|
|
1001
|
-
const next = applyPatch(existing, patches as Operation[]).newDocument as Row;
|
|
1006
|
+
const next = jsonPatch.applyPatch(existing, patches as Operation[]).newDocument as Row;
|
|
1002
1007
|
await this.upsert(table, id, next, 'replace');
|
|
1003
1008
|
}
|
|
1004
1009
|
|