@nichoth/simple-sync 0.0.0-stage → 0.0.5
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/README.md +469 -2
- package/dist/client/db.d.ts +67 -0
- package/dist/client/db.d.ts.map +1 -0
- package/dist/client/db.js +1 -0
- package/dist/client/db.js.map +7 -0
- package/dist/client/idb.d.ts +12 -0
- package/dist/client/idb.d.ts.map +1 -0
- package/dist/client/idb.js +72 -0
- package/dist/client/idb.js.map +7 -0
- package/dist/client/index.d.ts +143 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +362 -0
- package/dist/client/index.js.map +7 -0
- package/dist/client/sqlite-opfs-rpc.d.ts +21 -0
- package/dist/client/sqlite-opfs-rpc.d.ts.map +1 -0
- package/dist/client/sqlite-opfs-rpc.js +55 -0
- package/dist/client/sqlite-opfs-rpc.js.map +7 -0
- package/dist/client/sqlite-opfs.d.ts +15 -0
- package/dist/client/sqlite-opfs.d.ts.map +1 -0
- package/dist/client/sqlite-opfs.js +31 -0
- package/dist/client/sqlite-opfs.js.map +7 -0
- package/dist/client/sqlite-opfs.worker.d.ts +6 -0
- package/dist/client/sqlite-opfs.worker.d.ts.map +1 -0
- package/dist/client/sqlite-opfs.worker.js +47 -0
- package/dist/client/sqlite-opfs.worker.js.map +7 -0
- package/dist/client/sqlite.d.ts +25 -0
- package/dist/client/sqlite.d.ts.map +1 -0
- package/dist/client/sqlite.js +117 -0
- package/dist/client/sqlite.js.map +7 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +11 -0
- package/dist/client.js.map +7 -0
- package/dist/hash.d.ts +23 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +29 -0
- package/dist/hash.js.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +7 -0
- package/dist/meta.json +511 -0
- package/dist/op.d.ts +41 -0
- package/dist/op.d.ts.map +1 -0
- package/dist/op.js +46 -0
- package/dist/op.js.map +7 -0
- package/dist/reduce.d.ts +55 -0
- package/dist/reduce.d.ts.map +1 -0
- package/dist/reduce.js +173 -0
- package/dist/reduce.js.map +7 -0
- package/dist/server/errors.d.ts +16 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +14 -0
- package/dist/server/errors.js.map +7 -0
- package/dist/server/index.d.ts +75 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +324 -0
- package/dist/server/index.js.map +7 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +5 -0
- package/dist/server.js.map +7 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/package.json +118 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main-thread OPFS executor and sqliteOpfs function.
|
|
3
|
+
* Never imports @sqlite.org/sqlite-wasm directly.
|
|
4
|
+
*/
|
|
5
|
+
import type { ClientDB } from './db.js';
|
|
6
|
+
import type { SqlExecutor } from './sqlite.js';
|
|
7
|
+
export interface OpfsExecutorOptions {
|
|
8
|
+
dbName: string;
|
|
9
|
+
vfs?: 'opfs-sahpool' | 'opfs';
|
|
10
|
+
wasmUrl?: string | URL;
|
|
11
|
+
workerUrl?: string | URL;
|
|
12
|
+
}
|
|
13
|
+
export declare function opfsExecutor(opts: OpfsExecutorOptions): Promise<SqlExecutor>;
|
|
14
|
+
export declare function sqliteOpfs(opts: OpfsExecutorOptions): Promise<ClientDB>;
|
|
15
|
+
//# sourceMappingURL=sqlite-opfs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-opfs.d.ts","sourceRoot":"","sources":["../../src/client/sqlite-opfs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAC,MAAM,CAAA;IACb,GAAG,CAAC,EAAC,cAAc,GAAG,MAAM,CAAA;IAC5B,OAAO,CAAC,EAAC,MAAM,GAAG,GAAG,CAAA;IACrB,SAAS,CAAC,EAAC,MAAM,GAAG,GAAG,CAAA;CAC1B;AAED,wBAAsB,YAAY,CAC9B,IAAI,EAAC,mBAAmB,GAC1B,OAAO,CAAC,WAAW,CAAC,CAiBrB;AAED,wBAAsB,UAAU,CAC5B,IAAI,EAAC,mBAAmB,GAC1B,OAAO,CAAC,QAAQ,CAAC,CAElB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { sqlite } from "./sqlite.js";
|
|
4
|
+
import { rpcClient } from "./sqlite-opfs-rpc.js";
|
|
5
|
+
async function opfsExecutor(opts) {
|
|
6
|
+
const worker = new Worker(
|
|
7
|
+
opts.workerUrl ?? new URL("./sqlite-opfs.worker.js", import.meta.url),
|
|
8
|
+
{ type: "module" }
|
|
9
|
+
);
|
|
10
|
+
const client = rpcClient(worker);
|
|
11
|
+
worker.addEventListener("error", () => {
|
|
12
|
+
client.failAll(new Error("sqlite-opfs worker error"));
|
|
13
|
+
});
|
|
14
|
+
await client.request({
|
|
15
|
+
kind: "init",
|
|
16
|
+
dbName: opts.dbName,
|
|
17
|
+
vfs: opts.vfs ?? "opfs-sahpool",
|
|
18
|
+
wasmUrl: opts.wasmUrl ? String(opts.wasmUrl) : void 0
|
|
19
|
+
});
|
|
20
|
+
return { exec: client.exec, close: client.close };
|
|
21
|
+
}
|
|
22
|
+
__name(opfsExecutor, "opfsExecutor");
|
|
23
|
+
async function sqliteOpfs(opts) {
|
|
24
|
+
return sqlite(await opfsExecutor(opts));
|
|
25
|
+
}
|
|
26
|
+
__name(sqliteOpfs, "sqliteOpfs");
|
|
27
|
+
export {
|
|
28
|
+
opfsExecutor,
|
|
29
|
+
sqliteOpfs
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=sqlite-opfs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/client/sqlite-opfs.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Main-thread OPFS executor and sqliteOpfs function.\n * Never imports @sqlite.org/sqlite-wasm directly.\n */\n\nimport { sqlite } from './sqlite.js'\nimport { rpcClient } from './sqlite-opfs-rpc.js'\nimport type { ClientDB } from './db.js'\nimport type { SqlExecutor } from './sqlite.js'\n\nexport interface OpfsExecutorOptions {\n dbName:string // OPFS filename\n vfs?:'opfs-sahpool' | 'opfs' // default: 'opfs-sahpool'\n wasmUrl?:string | URL // override .wasm asset location\n workerUrl?:string | URL // override worker asset location\n}\n\nexport async function opfsExecutor (\n opts:OpfsExecutorOptions\n):Promise<SqlExecutor> {\n const worker = new Worker(\n opts.workerUrl ??\n new URL('./sqlite-opfs.worker.js', import.meta.url),\n { type: 'module' }\n )\n const client = rpcClient(worker)\n worker.addEventListener('error', () => {\n client.failAll(new Error('sqlite-opfs worker error'))\n })\n await client.request({\n kind: 'init',\n dbName: opts.dbName,\n vfs: opts.vfs ?? 'opfs-sahpool',\n wasmUrl: opts.wasmUrl ? String(opts.wasmUrl) : undefined\n })\n return { exec: client.exec, close: client.close }\n}\n\nexport async function sqliteOpfs (\n opts:OpfsExecutorOptions\n):Promise<ClientDB> {\n return sqlite(await opfsExecutor(opts))\n}\n"],
|
|
5
|
+
"mappings": ";;AAKA,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAW1B,eAAsB,aAClB,MACmB;AACnB,QAAM,SAAS,IAAI;AAAA,IACf,KAAK,aACD,IAAI,IAAI,2BAA2B,YAAY,GAAG;AAAA,IACtD,EAAE,MAAM,SAAS;AAAA,EACrB;AACA,QAAM,SAAS,UAAU,MAAM;AAC/B,SAAO,iBAAiB,SAAS,MAAM;AACnC,WAAO,QAAQ,IAAI,MAAM,0BAA0B,CAAC;AAAA,EACxD,CAAC;AACD,QAAM,OAAO,QAAQ;AAAA,IACjB,MAAM;AAAA,IACN,QAAQ,KAAK;AAAA,IACb,KAAK,KAAK,OAAO;AAAA,IACjB,SAAS,KAAK,UAAU,OAAO,KAAK,OAAO,IAAI;AAAA,EACnD,CAAC;AACD,SAAO,EAAE,MAAM,OAAO,MAAM,OAAO,OAAO,MAAM;AACpD;AAnBsB;AAqBtB,eAAsB,WAClB,MACgB;AAChB,SAAO,OAAO,MAAM,aAAa,IAAI,CAAC;AAC1C;AAJsB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-opfs.worker.d.ts","sourceRoot":"","sources":["../../src/client/sqlite-opfs.worker.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
|
|
4
|
+
const ctx = self;
|
|
5
|
+
let db = null;
|
|
6
|
+
let sqlite3 = null;
|
|
7
|
+
async function init(msg) {
|
|
8
|
+
const initFn = sqlite3InitModule;
|
|
9
|
+
sqlite3 = await initFn(
|
|
10
|
+
msg.wasmUrl ? { locateFile: /* @__PURE__ */ __name(() => msg.wasmUrl, "locateFile") } : void 0
|
|
11
|
+
);
|
|
12
|
+
if (msg.vfs === "opfs") {
|
|
13
|
+
db = new sqlite3.oo1.OpfsDb(msg.dbName);
|
|
14
|
+
} else {
|
|
15
|
+
const pool = await sqlite3.installOpfsSAHPoolVfs({});
|
|
16
|
+
const name = msg.dbName.startsWith("/") ? msg.dbName : "/" + msg.dbName;
|
|
17
|
+
db = new pool.OpfsSAHPoolDb(name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
__name(init, "init");
|
|
21
|
+
function exec(msg) {
|
|
22
|
+
if (!db) throw new Error("sqlite-opfs: exec before init");
|
|
23
|
+
return db.exec({
|
|
24
|
+
sql: msg.sql,
|
|
25
|
+
bind: msg.params && msg.params.length ? msg.params : void 0,
|
|
26
|
+
rowMode: "object",
|
|
27
|
+
returnValue: "resultRows"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
__name(exec, "exec");
|
|
31
|
+
ctx.addEventListener("message", async (e) => {
|
|
32
|
+
const msg = e.data;
|
|
33
|
+
try {
|
|
34
|
+
let rows = [];
|
|
35
|
+
if (msg.kind === "init") await init(msg);
|
|
36
|
+
else if (msg.kind === "exec") rows = exec(msg);
|
|
37
|
+
else if (msg.kind === "close") {
|
|
38
|
+
if (db) db.close();
|
|
39
|
+
db = null;
|
|
40
|
+
}
|
|
41
|
+
ctx.postMessage({ reqId: msg.reqId, ok: true, rows });
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
44
|
+
ctx.postMessage({ reqId: msg.reqId, ok: false, error });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=sqlite-opfs.worker.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/client/sqlite-opfs.worker.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * OPFS SQLite worker \u2014 the ONLY module importing\n * @sqlite.org/sqlite-wasm. Serves init/exec/close RPC.\n */\n\nimport sqlite3InitModule from '@sqlite.org/sqlite-wasm'\nimport type {\n Sqlite3Static,\n Database,\n ExecBaseOptions,\n ExecRowModeObjectOptions,\n ExecReturnResultRowsOptions\n} from '@sqlite.org/sqlite-wasm'\n\nconst ctx = self as unknown as DedicatedWorkerGlobalScope\n\ninterface InitMsg {\n kind:'init'\n reqId:number\n dbName:string\n vfs:string\n wasmUrl?:string\n}\n\ninterface ExecMsg {\n kind:'exec'\n reqId:number\n sql:string\n params?:unknown[]\n}\n\ninterface CloseMsg {\n kind:'close'\n reqId:number\n}\n\ntype Msg = InitMsg | ExecMsg | CloseMsg\n\n// sqlite-wasm db handle\nlet db:Database | null = null\nlet sqlite3:Sqlite3Static | null = null\n\nasync function init (msg:InitMsg):Promise<void> {\n // sqlite-wasm's types omit init's param (upstream PR #129); the\n // runtime honors Module.locateFile. Cast to pass wasmUrl through.\n const initFn = sqlite3InitModule as (cfg?:{\n locateFile:(path:string)=>string\n })=>Promise<Sqlite3Static>\n sqlite3 = await initFn(\n msg.wasmUrl ? { locateFile: () => msg.wasmUrl as string } : undefined\n )\n if (msg.vfs === 'opfs') {\n // Requires COOP/COEP; only used when the consumer opts in.\n db = new sqlite3.oo1.OpfsDb(msg.dbName)\n } else {\n const pool = await sqlite3.installOpfsSAHPoolVfs({})\n const name = msg.dbName.startsWith('/') ? msg.dbName : '/' + msg.dbName\n db = new pool.OpfsSAHPoolDb(name)\n }\n}\n\nfunction exec (msg:ExecMsg):unknown[] {\n if (!db) throw new Error('sqlite-opfs: exec before init')\n // Call exec with options, casting through unknown to work around\n // complex overload resolution. At runtime, the options are correct.\n return db.exec({\n sql: msg.sql,\n bind: (msg.params && msg.params.length) ?\n msg.params :\n undefined,\n rowMode: 'object' as const,\n returnValue: 'resultRows' as const\n } as unknown as ExecBaseOptions &\n ExecRowModeObjectOptions &\n ExecReturnResultRowsOptions & { sql:string })\n}\n\nctx.addEventListener('message', async (e:MessageEvent) => {\n const msg = e.data as Msg\n try {\n let rows:unknown[] = []\n if (msg.kind === 'init') await init(msg)\n else if (msg.kind === 'exec') rows = exec(msg)\n else if (msg.kind === 'close') {\n if (db) db.close()\n db = null\n }\n ctx.postMessage({ reqId: msg.reqId, ok: true, rows })\n } catch (err) {\n const error = (err instanceof Error) ? err.message : String(err)\n ctx.postMessage({ reqId: msg.reqId, ok: false, error })\n }\n})\n"],
|
|
5
|
+
"mappings": ";;AAKA,OAAO,uBAAuB;AAS9B,MAAM,MAAM;AAyBZ,IAAI,KAAqB;AACzB,IAAI,UAA+B;AAEnC,eAAe,KAAM,KAA2B;AAG5C,QAAM,SAAS;AAGf,YAAU,MAAM;AAAA,IACZ,IAAI,UAAU,EAAE,YAAY,6BAAM,IAAI,SAAV,cAA4B,IAAI;AAAA,EAChE;AACA,MAAI,IAAI,QAAQ,QAAQ;AAEpB,SAAK,IAAI,QAAQ,IAAI,OAAO,IAAI,MAAM;AAAA,EAC1C,OAAO;AACH,UAAM,OAAO,MAAM,QAAQ,sBAAsB,CAAC,CAAC;AACnD,UAAM,OAAO,IAAI,OAAO,WAAW,GAAG,IAAI,IAAI,SAAS,MAAM,IAAI;AACjE,SAAK,IAAI,KAAK,cAAc,IAAI;AAAA,EACpC;AACJ;AAjBe;AAmBf,SAAS,KAAM,KAAuB;AAClC,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,+BAA+B;AAGxD,SAAO,GAAG,KAAK;AAAA,IACX,KAAK,IAAI;AAAA,IACT,MAAO,IAAI,UAAU,IAAI,OAAO,SAC5B,IAAI,SACJ;AAAA,IACJ,SAAS;AAAA,IACT,aAAa;AAAA,EACjB,CAEgD;AACpD;AAdS;AAgBT,IAAI,iBAAiB,WAAW,OAAO,MAAmB;AACtD,QAAM,MAAM,EAAE;AACd,MAAI;AACA,QAAI,OAAiB,CAAC;AACtB,QAAI,IAAI,SAAS,OAAQ,OAAM,KAAK,GAAG;AAAA,aAC9B,IAAI,SAAS,OAAQ,QAAO,KAAK,GAAG;AAAA,aACpC,IAAI,SAAS,SAAS;AAC3B,UAAI,GAAI,IAAG,MAAM;AACjB,WAAK;AAAA,IACT;AACA,QAAI,YAAY,EAAE,OAAO,IAAI,OAAO,IAAI,MAAM,KAAK,CAAC;AAAA,EACxD,SAAS,KAAK;AACV,UAAM,QAAS,eAAe,QAAS,IAAI,UAAU,OAAO,GAAG;AAC/D,QAAI,YAAY,EAAE,OAAO,IAAI,OAAO,IAAI,OAAO,MAAM,CAAC;AAAA,EAC1D;AACJ,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agnostic SQLite adapter for ClientDB interface.
|
|
3
|
+
* Imports no SQLite package — any object implementing SqlExecutor drives it.
|
|
4
|
+
*/
|
|
5
|
+
import type { ClientDB } from './db.js';
|
|
6
|
+
export type SqlRow = Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* SQL executor contract — a minimal interface that any storage backend
|
|
9
|
+
* (in-memory, OPFS, worker-based, etc.) can implement.
|
|
10
|
+
*/
|
|
11
|
+
export interface SqlExecutor {
|
|
12
|
+
/**
|
|
13
|
+
* Run one statement with positional `?` params. Resolve with result
|
|
14
|
+
* rows as plain objects keyed by column name (`[]` for non-SELECT).
|
|
15
|
+
* Implementations must support SQLite `?` placeholders and
|
|
16
|
+
* TEXT/REAL/INTEGER/NULL values.
|
|
17
|
+
*/
|
|
18
|
+
exec(sql: string, params?: readonly unknown[]): Promise<SqlRow[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Release the underlying db (and worker, if any). Idempotent.
|
|
21
|
+
*/
|
|
22
|
+
close(): void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function sqlite(executor: SqlExecutor): Promise<ClientDB>;
|
|
25
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/client/sqlite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB;;;;;OAKG;IACH,IAAI,CAAE,GAAG,EAAC,MAAM,EAAE,MAAM,CAAC,EAAC,SAAS,OAAO,EAAE,GAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/D;;OAEG;IACH,KAAK,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC;AAcD,wBAAsB,MAAM,CAAE,QAAQ,EAAC,WAAW,GAAE,OAAO,CAAC,QAAQ,CAAC,CA4GpE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const CREATE_OPS = `CREATE TABLE IF NOT EXISTS ops (
|
|
4
|
+
seq INTEGER PRIMARY KEY,
|
|
5
|
+
id TEXT NOT NULL, type TEXT NOT NULL, target TEXT,
|
|
6
|
+
value TEXT NOT NULL,
|
|
7
|
+
ts REAL NOT NULL,
|
|
8
|
+
sig TEXT )`;
|
|
9
|
+
const CREATE_STATES = `CREATE TABLE IF NOT EXISTS states (
|
|
10
|
+
id TEXT PRIMARY KEY, hash TEXT NOT NULL,
|
|
11
|
+
ts_json TEXT NOT NULL DEFAULT '{}',
|
|
12
|
+
value TEXT NOT NULL )`;
|
|
13
|
+
async function sqlite(executor) {
|
|
14
|
+
await executor.exec(CREATE_OPS);
|
|
15
|
+
await executor.exec(CREATE_STATES);
|
|
16
|
+
function rowToOp(r) {
|
|
17
|
+
const base = {
|
|
18
|
+
seq: r.seq,
|
|
19
|
+
id: r.id,
|
|
20
|
+
type: r.type,
|
|
21
|
+
target: r.target ?? null,
|
|
22
|
+
value: JSON.parse(r.value),
|
|
23
|
+
ts: r.ts
|
|
24
|
+
};
|
|
25
|
+
if (r.sig === null || r.sig === void 0) return base;
|
|
26
|
+
return { ...base, sig: r.sig };
|
|
27
|
+
}
|
|
28
|
+
__name(rowToOp, "rowToOp");
|
|
29
|
+
function rowToState(r) {
|
|
30
|
+
return {
|
|
31
|
+
id: r.id,
|
|
32
|
+
hash: r.hash,
|
|
33
|
+
__ts: JSON.parse(r.ts_json),
|
|
34
|
+
value: JSON.parse(r.value)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
__name(rowToState, "rowToState");
|
|
38
|
+
return {
|
|
39
|
+
async write(op) {
|
|
40
|
+
await executor.exec(
|
|
41
|
+
`INSERT OR REPLACE INTO ops
|
|
42
|
+
(seq, id, type, target, value, ts, sig)
|
|
43
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
44
|
+
[
|
|
45
|
+
op.seq,
|
|
46
|
+
op.id,
|
|
47
|
+
op.type,
|
|
48
|
+
op.target,
|
|
49
|
+
// Coerce undefined to null: value column is TEXT NOT NULL
|
|
50
|
+
JSON.stringify(op.value ?? null),
|
|
51
|
+
op.ts,
|
|
52
|
+
op.sig ?? null
|
|
53
|
+
]
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
async readFrom(fromSeq) {
|
|
57
|
+
const rows = await executor.exec(
|
|
58
|
+
`SELECT seq, id, type, target, value, ts, sig
|
|
59
|
+
FROM ops WHERE seq > ? ORDER BY seq`,
|
|
60
|
+
[fromSeq]
|
|
61
|
+
);
|
|
62
|
+
return rows.map(rowToOp);
|
|
63
|
+
},
|
|
64
|
+
async readRange(loSeq, hiSeq) {
|
|
65
|
+
const rows = await executor.exec(
|
|
66
|
+
`SELECT seq, id, type, target, value, ts, sig
|
|
67
|
+
FROM ops WHERE seq BETWEEN ? AND ? ORDER BY seq`,
|
|
68
|
+
[loSeq, hiSeq]
|
|
69
|
+
);
|
|
70
|
+
return rows.map(rowToOp);
|
|
71
|
+
},
|
|
72
|
+
async last() {
|
|
73
|
+
const rows = await executor.exec("SELECT MAX(seq) AS m FROM ops");
|
|
74
|
+
const m = rows[0] ? rows[0].m : null;
|
|
75
|
+
return typeof m === "number" ? m : 0;
|
|
76
|
+
},
|
|
77
|
+
async deleteBelow(seq) {
|
|
78
|
+
await executor.exec("DELETE FROM ops WHERE seq < ?", [seq]);
|
|
79
|
+
},
|
|
80
|
+
async putState(state) {
|
|
81
|
+
await executor.exec(
|
|
82
|
+
`INSERT OR REPLACE INTO states (id, hash, ts_json, value)
|
|
83
|
+
VALUES (?, ?, ?, ?)`,
|
|
84
|
+
[
|
|
85
|
+
state.id,
|
|
86
|
+
state.hash,
|
|
87
|
+
JSON.stringify(state.__ts ?? {}),
|
|
88
|
+
JSON.stringify(state.value ?? {})
|
|
89
|
+
]
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
async getState(id) {
|
|
93
|
+
const rows = await executor.exec(
|
|
94
|
+
"SELECT id, hash, ts_json, value FROM states WHERE id = ?",
|
|
95
|
+
[id]
|
|
96
|
+
);
|
|
97
|
+
return rows[0] ? rowToState(rows[0]) : null;
|
|
98
|
+
},
|
|
99
|
+
async getAllStates() {
|
|
100
|
+
const rows = await executor.exec(
|
|
101
|
+
"SELECT id, hash, ts_json, value FROM states"
|
|
102
|
+
);
|
|
103
|
+
return rows.map(rowToState);
|
|
104
|
+
},
|
|
105
|
+
async deleteState(id) {
|
|
106
|
+
await executor.exec("DELETE FROM states WHERE id = ?", [id]);
|
|
107
|
+
},
|
|
108
|
+
close() {
|
|
109
|
+
void executor.close();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
__name(sqlite, "sqlite");
|
|
114
|
+
export {
|
|
115
|
+
sqlite
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/client/sqlite.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Agnostic SQLite adapter for ClientDB interface.\n * Imports no SQLite package \u2014 any object implementing SqlExecutor drives it.\n */\n\nimport type { ClientDB } from './db.js'\nimport type { Op, OpType, ReducedState } from '../types.js'\n\nexport type SqlRow = Record<string, unknown>\n\n/**\n * SQL executor contract \u2014 a minimal interface that any storage backend\n * (in-memory, OPFS, worker-based, etc.) can implement.\n */\nexport interface SqlExecutor {\n /**\n * Run one statement with positional `?` params. Resolve with result\n * rows as plain objects keyed by column name (`[]` for non-SELECT).\n * Implementations must support SQLite `?` placeholders and\n * TEXT/REAL/INTEGER/NULL values.\n */\n exec (sql:string, params?:readonly unknown[]):Promise<SqlRow[]>\n /**\n * Release the underlying db (and worker, if any). Idempotent.\n */\n close ():void | Promise<void>\n}\n\nconst CREATE_OPS = `CREATE TABLE IF NOT EXISTS ops (\n seq INTEGER PRIMARY KEY,\n id TEXT NOT NULL, type TEXT NOT NULL, target TEXT,\n value TEXT NOT NULL,\n ts REAL NOT NULL,\n sig TEXT )`\n\nconst CREATE_STATES = `CREATE TABLE IF NOT EXISTS states (\n id TEXT PRIMARY KEY, hash TEXT NOT NULL,\n ts_json TEXT NOT NULL DEFAULT '{}',\n value TEXT NOT NULL )`\n\nexport async function sqlite (executor:SqlExecutor):Promise<ClientDB> {\n await executor.exec(CREATE_OPS)\n await executor.exec(CREATE_STATES)\n\n function rowToOp (r:SqlRow):Op {\n const base:Op = {\n seq: r.seq as number,\n id: r.id as string,\n type: r.type as OpType,\n target: (r.target ?? null) as string | null,\n value: JSON.parse(r.value as string),\n ts: r.ts as number\n }\n if (r.sig === null || r.sig === undefined) return base\n return { ...base, sig: r.sig as string }\n }\n\n function rowToState (r:SqlRow):ReducedState {\n return {\n id: r.id as string,\n hash: r.hash as string,\n __ts: JSON.parse(r.ts_json as string),\n value: JSON.parse(r.value as string)\n }\n }\n\n return {\n async write (op:Op):Promise<void> {\n await executor.exec(\n `INSERT OR REPLACE INTO ops\n (seq, id, type, target, value, ts, sig)\n VALUES (?, ?, ?, ?, ?, ?, ?)`,\n [\n op.seq, op.id, op.type, op.target,\n // Coerce undefined to null: value column is TEXT NOT NULL\n JSON.stringify(op.value ?? null), op.ts,\n op.sig ?? null\n ]\n )\n },\n\n async readFrom (fromSeq:number):Promise<Op[]> {\n const rows = await executor.exec(\n `SELECT seq, id, type, target, value, ts, sig\n FROM ops WHERE seq > ? ORDER BY seq`,\n [fromSeq]\n )\n return rows.map(rowToOp)\n },\n\n async readRange (loSeq:number, hiSeq:number):Promise<Op[]> {\n const rows = await executor.exec(\n `SELECT seq, id, type, target, value, ts, sig\n FROM ops WHERE seq BETWEEN ? AND ? ORDER BY seq`,\n [loSeq, hiSeq]\n )\n return rows.map(rowToOp)\n },\n\n async last ():Promise<number> {\n const rows = await executor.exec('SELECT MAX(seq) AS m FROM ops')\n const m = rows[0] ? rows[0].m : null\n return (typeof m === 'number') ? m : 0\n },\n\n async deleteBelow (seq) {\n // No `seq <= 0` guard needed (unlike the idb backend): the\n // predicate `seq < ?` is a natural no-op for seq <= 0 and on\n // an empty table.\n await executor.exec('DELETE FROM ops WHERE seq < ?', [seq])\n },\n\n async putState (state:ReducedState):Promise<void> {\n await executor.exec(\n `INSERT OR REPLACE INTO states (id, hash, ts_json, value)\n VALUES (?, ?, ?, ?)`,\n [\n state.id, state.hash,\n JSON.stringify(state.__ts ?? {}),\n JSON.stringify(state.value ?? {})\n ]\n )\n },\n\n async getState (id:string):Promise<ReducedState | null> {\n const rows = await executor.exec(\n 'SELECT id, hash, ts_json, value FROM states WHERE id = ?',\n [id]\n )\n return rows[0] ? rowToState(rows[0]) : null\n },\n\n async getAllStates ():Promise<ReducedState[]> {\n const rows = await executor.exec(\n 'SELECT id, hash, ts_json, value FROM states'\n )\n return rows.map(rowToState)\n },\n\n async deleteState (id:string):Promise<void> {\n await executor.exec('DELETE FROM states WHERE id = ?', [id])\n },\n\n close ():void {\n // eslint-disable-next-line no-void\n void executor.close()\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AA4BA,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAOnB,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAKtB,eAAsB,OAAQ,UAAwC;AAClE,QAAM,SAAS,KAAK,UAAU;AAC9B,QAAM,SAAS,KAAK,aAAa;AAEjC,WAAS,QAAS,GAAa;AAC3B,UAAM,OAAU;AAAA,MACZ,KAAK,EAAE;AAAA,MACP,IAAI,EAAE;AAAA,MACN,MAAM,EAAE;AAAA,MACR,QAAS,EAAE,UAAU;AAAA,MACrB,OAAO,KAAK,MAAM,EAAE,KAAe;AAAA,MACnC,IAAI,EAAE;AAAA,IACV;AACA,QAAI,EAAE,QAAQ,QAAQ,EAAE,QAAQ,OAAW,QAAO;AAClD,WAAO,EAAE,GAAG,MAAM,KAAK,EAAE,IAAc;AAAA,EAC3C;AAXS;AAaT,WAAS,WAAY,GAAuB;AACxC,WAAO;AAAA,MACH,IAAI,EAAE;AAAA,MACN,MAAM,EAAE;AAAA,MACR,MAAM,KAAK,MAAM,EAAE,OAAiB;AAAA,MACpC,OAAO,KAAK,MAAM,EAAE,KAAe;AAAA,IACvC;AAAA,EACJ;AAPS;AAST,SAAO;AAAA,IACH,MAAM,MAAO,IAAqB;AAC9B,YAAM,SAAS;AAAA,QACX;AAAA;AAAA;AAAA,QAGA;AAAA,UACI,GAAG;AAAA,UAAK,GAAG;AAAA,UAAI,GAAG;AAAA,UAAM,GAAG;AAAA;AAAA,UAE3B,KAAK,UAAU,GAAG,SAAS,IAAI;AAAA,UAAG,GAAG;AAAA,UACrC,GAAG,OAAO;AAAA,QACd;AAAA,MACJ;AAAA,IACJ;AAAA,IAEA,MAAM,SAAU,SAA8B;AAC1C,YAAM,OAAO,MAAM,SAAS;AAAA,QACxB;AAAA;AAAA,QAEA,CAAC,OAAO;AAAA,MACZ;AACA,aAAO,KAAK,IAAI,OAAO;AAAA,IAC3B;AAAA,IAEA,MAAM,UAAW,OAAc,OAA4B;AACvD,YAAM,OAAO,MAAM,SAAS;AAAA,QACxB;AAAA;AAAA,QAEA,CAAC,OAAO,KAAK;AAAA,MACjB;AACA,aAAO,KAAK,IAAI,OAAO;AAAA,IAC3B;AAAA,IAEA,MAAM,OAAwB;AAC1B,YAAM,OAAO,MAAM,SAAS,KAAK,+BAA+B;AAChE,YAAM,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,IAAI;AAChC,aAAQ,OAAO,MAAM,WAAY,IAAI;AAAA,IACzC;AAAA,IAEA,MAAM,YAAa,KAAK;AAIpB,YAAM,SAAS,KAAK,iCAAiC,CAAC,GAAG,CAAC;AAAA,IAC9D;AAAA,IAEA,MAAM,SAAU,OAAkC;AAC9C,YAAM,SAAS;AAAA,QACX;AAAA;AAAA,QAEA;AAAA,UACI,MAAM;AAAA,UAAI,MAAM;AAAA,UAChB,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC;AAAA,UAC/B,KAAK,UAAU,MAAM,SAAS,CAAC,CAAC;AAAA,QACpC;AAAA,MACJ;AAAA,IACJ;AAAA,IAEA,MAAM,SAAU,IAAwC;AACpD,YAAM,OAAO,MAAM,SAAS;AAAA,QACxB;AAAA,QACA,CAAC,EAAE;AAAA,MACP;AACA,aAAO,KAAK,CAAC,IAAI,WAAW,KAAK,CAAC,CAAC,IAAI;AAAA,IAC3C;AAAA,IAEA,MAAM,eAAwC;AAC1C,YAAM,OAAO,MAAM,SAAS;AAAA,QACxB;AAAA,MACJ;AACA,aAAO,KAAK,IAAI,UAAU;AAAA,IAC9B;AAAA,IAEA,MAAM,YAAa,IAAyB;AACxC,YAAM,SAAS,KAAK,mCAAmC,CAAC,EAAE,CAAC;AAAA,IAC/D;AAAA,IAEA,QAAc;AAEV,WAAK,SAAS,MAAM;AAAA,IACxB;AAAA,EACJ;AACJ;AA5GsB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SyncClient, type SyncClientOptions, type SyncEvents, type StateOrigin, type ServerEnvelope } from './client/index.js';
|
|
2
|
+
export { idb } from './client/idb.js';
|
|
3
|
+
export { sqlite } from './client/sqlite.js';
|
|
4
|
+
export type { ClientDB } from './client/db.js';
|
|
5
|
+
export type { SqlExecutor, SqlRow } from './client/sqlite.js';
|
|
6
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n SyncClient,\n type SyncClientOptions,\n type SyncEvents,\n type StateOrigin,\n type ServerEnvelope\n} from './client/index.js'\nexport { idb } from './client/idb.js'\nexport { sqlite } from './client/sqlite.js'\nexport type { ClientDB } from './client/db.js'\nexport type { SqlExecutor, SqlRow } from './client/sqlite.js'\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACI;AAAA,OAKG;AACP,SAAS,WAAW;AACpB,SAAS,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic hashing and canonical JSON serialization for state
|
|
3
|
+
* verification and content-addressable storage.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Produces canonical JSON string with keys sorted alphabetically.
|
|
7
|
+
* Arrays preserve original order (order is semantic, not incidental).
|
|
8
|
+
* Primitives and null pass through untouched.
|
|
9
|
+
*
|
|
10
|
+
* This ensures deterministic serialization: the same logical value
|
|
11
|
+
* always produces the same JSON string, regardless of key order.
|
|
12
|
+
*/
|
|
13
|
+
export declare function canonicalJSON(value: unknown): string;
|
|
14
|
+
/**
|
|
15
|
+
* Computes SHA-256 hash of canonical JSON as lowercase hex.
|
|
16
|
+
* Returns a 64-character hex string suitable for content
|
|
17
|
+
* addressing and collision detection.
|
|
18
|
+
*
|
|
19
|
+
* The hash is deterministic: same logical value always
|
|
20
|
+
* produces same hash, regardless of key order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hashState(value: unknown): Promise<string>;
|
|
23
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAE,KAAK,EAAC,OAAO,GAAE,MAAM,CAiBnD;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC3B,KAAK,EAAC,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,CAOhB"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function canonicalJSON(value) {
|
|
4
|
+
function sortReplacer(_key, val) {
|
|
5
|
+
if (val !== null && typeof val === "object" && !Array.isArray(val)) {
|
|
6
|
+
const sorted = {};
|
|
7
|
+
for (const k of Object.keys(val).sort()) {
|
|
8
|
+
sorted[k] = val[k];
|
|
9
|
+
}
|
|
10
|
+
return sorted;
|
|
11
|
+
}
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
__name(sortReplacer, "sortReplacer");
|
|
15
|
+
return JSON.stringify(value, sortReplacer);
|
|
16
|
+
}
|
|
17
|
+
__name(canonicalJSON, "canonicalJSON");
|
|
18
|
+
async function hashState(value) {
|
|
19
|
+
const json = canonicalJSON(value);
|
|
20
|
+
const bytes = new TextEncoder().encode(json);
|
|
21
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
22
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
23
|
+
}
|
|
24
|
+
__name(hashState, "hashState");
|
|
25
|
+
export {
|
|
26
|
+
canonicalJSON,
|
|
27
|
+
hashState
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/hash.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Cryptographic hashing and canonical JSON serialization for state\n * verification and content-addressable storage.\n */\n\n/**\n * Produces canonical JSON string with keys sorted alphabetically.\n * Arrays preserve original order (order is semantic, not incidental).\n * Primitives and null pass through untouched.\n *\n * This ensures deterministic serialization: the same logical value\n * always produces the same JSON string, regardless of key order.\n */\nexport function canonicalJSON (value:unknown):string {\n function sortReplacer (_key:string, val:unknown):unknown {\n if (\n val !== null &&\n typeof val === 'object' &&\n !Array.isArray(val)\n ) {\n const sorted:Record<string, unknown> = {}\n for (const k of Object.keys(val as object).sort()) {\n sorted[k] = (val as Record<string, unknown>)[k]\n }\n return sorted\n }\n return val\n }\n\n return JSON.stringify(value, sortReplacer)\n}\n\n/**\n * Computes SHA-256 hash of canonical JSON as lowercase hex.\n * Returns a 64-character hex string suitable for content\n * addressing and collision detection.\n *\n * The hash is deterministic: same logical value always\n * produces same hash, regardless of key order.\n */\nexport async function hashState (\n value:unknown\n):Promise<string> {\n const json = canonicalJSON(value)\n const bytes = new TextEncoder().encode(json)\n const digest = await crypto.subtle.digest('SHA-256', bytes)\n return [...new Uint8Array(digest)]\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n}\n"],
|
|
5
|
+
"mappings": ";;AAaO,SAAS,cAAe,OAAsB;AACjD,WAAS,aAAc,MAAa,KAAqB;AACrD,QACI,QAAQ,QACR,OAAO,QAAQ,YACf,CAAC,MAAM,QAAQ,GAAG,GACpB;AACE,YAAM,SAAiC,CAAC;AACxC,iBAAW,KAAK,OAAO,KAAK,GAAa,EAAE,KAAK,GAAG;AAC/C,eAAO,CAAC,IAAK,IAAgC,CAAC;AAAA,MAClD;AACA,aAAO;AAAA,IACX;AACA,WAAO;AAAA,EACX;AAbS;AAeT,SAAO,KAAK,UAAU,OAAO,YAAY;AAC7C;AAjBgB;AA2BhB,eAAsB,UAClB,OACc;AACd,QAAM,OAAO,cAAc,KAAK;AAChC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,IAAI;AAC3C,QAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC1D,SAAO,CAAC,GAAG,IAAI,WAAW,MAAM,CAAC,EAC5B,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EACxC,KAAK,EAAE;AAChB;AATsB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Op, OpType, Envelope, ReducedState, StateRef, DeleteValue, PatchValue } from './types.js';
|
|
2
|
+
export { op, type DraftOp } from './op.js';
|
|
3
|
+
export { lastWriteWins } from './reduce.js';
|
|
4
|
+
export { hashState, canonicalJSON } from './hash.js';
|
|
5
|
+
export { idb } from './client/idb.js';
|
|
6
|
+
export { sqlite } from './client/sqlite.js';
|
|
7
|
+
export type { ClientDB } from './client/db.js';
|
|
8
|
+
export type { SqlExecutor, SqlRow } from './client/sqlite.js';
|
|
9
|
+
export { SyncClient, type SyncClientOptions, type SyncEvents, type StateOrigin, type ServerEnvelope } from './client/index.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACR,EAAE,EACF,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,UAAU,EACb,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,EAAE,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EACH,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACtB,MAAM,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { op } from "./op.js";
|
|
2
|
+
import { lastWriteWins } from "./reduce.js";
|
|
3
|
+
import { hashState, canonicalJSON } from "./hash.js";
|
|
4
|
+
import { idb } from "./client/idb.js";
|
|
5
|
+
import { sqlite } from "./client/sqlite.js";
|
|
6
|
+
import {
|
|
7
|
+
SyncClient
|
|
8
|
+
} from "./client/index.js";
|
|
9
|
+
export {
|
|
10
|
+
SyncClient,
|
|
11
|
+
canonicalJSON,
|
|
12
|
+
hashState,
|
|
13
|
+
idb,
|
|
14
|
+
lastWriteWins,
|
|
15
|
+
op,
|
|
16
|
+
sqlite
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["// Public entry point for the simple-sync library (future API surface).\nexport type {\n Op,\n OpType,\n Envelope,\n ReducedState,\n StateRef,\n DeleteValue,\n PatchValue\n} from './types.js'\nexport { op, type DraftOp } from './op.js'\nexport { lastWriteWins } from './reduce.js'\nexport { hashState, canonicalJSON } from './hash.js'\nexport { idb } from './client/idb.js'\nexport { sqlite } from './client/sqlite.js'\nexport type { ClientDB } from './client/db.js'\nexport type { SqlExecutor, SqlRow } from './client/sqlite.js'\nexport {\n SyncClient,\n type SyncClientOptions,\n type SyncEvents,\n type StateOrigin,\n type ServerEnvelope\n} from './client/index.js'\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,UAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,WAAW,qBAAqB;AACzC,SAAS,WAAW;AACpB,SAAS,cAAc;AAGvB;AAAA,EACI;AAAA,OAKG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|