@zveltio/sdk 3.0.0-beta.1 → 3.0.0-beta.100
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 +17 -4
- package/dist/client.d.ts +103 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +117 -27
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +21 -3
- package/dist/crdt.d.ts.map +1 -1
- package/dist/crdt.js +11 -2
- package/dist/ddl/index.d.ts +20 -0
- package/dist/ddl/index.d.ts.map +1 -1
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +124 -0
- package/dist/extension/action-refusal.d.ts +27 -0
- package/dist/extension/action-refusal.d.ts.map +1 -0
- package/dist/extension/action-refusal.js +29 -0
- package/dist/extension/capabilities.d.ts +71 -0
- package/dist/extension/capabilities.d.ts.map +1 -0
- package/dist/extension/capabilities.js +79 -0
- package/dist/extension/dates.d.ts +7 -0
- package/dist/extension/dates.d.ts.map +1 -0
- package/dist/extension/dates.js +14 -0
- package/dist/extension/index.d.ts +1086 -38
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +16 -0
- package/dist/extension/jsonb.d.ts +62 -0
- package/dist/extension/jsonb.d.ts.map +1 -0
- package/dist/extension/jsonb.js +64 -0
- package/dist/extension/multipart.d.ts +58 -0
- package/dist/extension/multipart.d.ts.map +1 -0
- package/dist/extension/multipart.js +61 -0
- package/dist/extension/numeric.d.ts +94 -0
- package/dist/extension/numeric.d.ts.map +1 -0
- package/dist/extension/numeric.js +162 -0
- package/dist/extension/permission-gate.d.ts +15 -0
- package/dist/extension/permission-gate.d.ts.map +1 -1
- package/dist/extension/permission-gate.js +33 -1
- package/dist/extension/reserved-paths.d.ts +10 -0
- package/dist/extension/reserved-paths.d.ts.map +1 -0
- package/dist/extension/reserved-paths.js +23 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/local-store.d.ts +14 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +92 -13
- package/dist/offline/index.d.ts +25 -55
- package/dist/offline/index.d.ts.map +1 -1
- package/dist/offline/index.js +173 -157
- package/dist/publish/index.d.ts.map +1 -1
- package/dist/publish/index.js +6 -1
- package/dist/realtime.d.ts +25 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +47 -3
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +2 -0
- package/dist/schema-codegen.d.ts +25 -1
- package/dist/schema-codegen.d.ts.map +1 -1
- package/dist/schema-codegen.js +141 -7
- package/dist/schema-watcher.d.ts +10 -2
- package/dist/schema-watcher.d.ts.map +1 -1
- package/dist/schema-watcher.js +25 -10
- package/dist/studio/index.d.ts +1 -0
- package/dist/studio/index.d.ts.map +1 -1
- package/dist/studio/index.js +3 -0
- package/dist/studio/slot-owner-registry.d.ts +13 -0
- package/dist/studio/slot-owner-registry.d.ts.map +1 -0
- package/dist/studio/slot-owner-registry.js +21 -0
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +4 -2
- package/dist/sync-manager.d.ts +49 -4
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +173 -15
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +23 -1
- package/dist/testing/with-test-db.d.ts +1 -1
- package/dist/testing/with-test-db.d.ts.map +1 -1
- package/dist/testing/with-test-db.js +22 -15
- package/dist/tests/action-refusal.test.d.ts +2 -0
- package/dist/tests/action-refusal.test.d.ts.map +1 -0
- package/dist/tests/action-refusal.test.js +13 -0
- package/dist/tests/client.test.d.ts +2 -0
- package/dist/tests/client.test.d.ts.map +1 -0
- package/dist/tests/client.test.js +164 -0
- package/dist/tests/crdt-orset.test.d.ts +2 -0
- package/dist/tests/crdt-orset.test.d.ts.map +1 -0
- package/dist/tests/crdt-orset.test.js +23 -0
- package/dist/tests/local-store.test.js +44 -0
- package/dist/tests/migration-parse.test.d.ts +2 -0
- package/dist/tests/migration-parse.test.d.ts.map +1 -0
- package/dist/tests/migration-parse.test.js +17 -0
- package/dist/tests/multipart.test.d.ts +2 -0
- package/dist/tests/multipart.test.d.ts.map +1 -0
- package/dist/tests/multipart.test.js +37 -0
- package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
- package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
- package/dist/tests/offline-provider-crdt.test.js +206 -0
- package/dist/tests/realtime.test.d.ts +2 -0
- package/dist/tests/realtime.test.d.ts.map +1 -0
- package/dist/tests/realtime.test.js +220 -0
- package/dist/tests/reserved-paths.test.d.ts +2 -0
- package/dist/tests/reserved-paths.test.d.ts.map +1 -0
- package/dist/tests/reserved-paths.test.js +21 -0
- package/dist/tests/sync-manager.test.d.ts +2 -0
- package/dist/tests/sync-manager.test.d.ts.map +1 -0
- package/dist/tests/sync-manager.test.js +123 -0
- package/dist/tests/today-in.test.d.ts +2 -0
- package/dist/tests/today-in.test.d.ts.map +1 -0
- package/dist/tests/today-in.test.js +14 -0
- package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
- package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-actions.test.js +82 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-dependencies.test.js +27 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
- package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
- package/dist/tests/with-test-db.test.d.ts +2 -0
- package/dist/tests/with-test-db.test.d.ts.map +1 -0
- package/dist/tests/with-test-db.test.js +57 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/validate/index.d.ts +53 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +693 -7
- package/dist/validate/migration-parse.d.ts +10 -5
- package/dist/validate/migration-parse.d.ts.map +1 -1
- package/dist/validate/migration-parse.js +1 -1
- package/dist/validate/shared-message-keys.d.ts +16 -0
- package/dist/validate/shared-message-keys.d.ts.map +1 -0
- package/dist/validate/shared-message-keys.js +227 -0
- package/package.json +8 -8
- package/dist/client/Auth.d.ts +0 -19
- package/dist/client/Auth.d.ts.map +0 -1
- package/dist/client/Auth.js +0 -45
- package/dist/client/QueryBuilder.d.ts +0 -17
- package/dist/client/QueryBuilder.d.ts.map +0 -1
- package/dist/client/QueryBuilder.js +0 -85
- package/dist/client/RealtimeClient.d.ts +0 -22
- package/dist/client/RealtimeClient.d.ts.map +0 -1
- package/dist/client/RealtimeClient.js +0 -98
- package/dist/client/ZveltioClient.d.ts +0 -20
- package/dist/client/ZveltioClient.d.ts.map +0 -1
- package/dist/client/ZveltioClient.js +0 -78
- package/dist/generate-types.d.ts +0 -37
- package/dist/generate-types.d.ts.map +0 -1
- package/dist/generate-types.js +0 -157
package/dist/schema-codegen.js
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* column names in editors and `tsc` catches typos.
|
|
9
9
|
*
|
|
10
10
|
* Scope intentionally narrow:
|
|
11
|
-
* -
|
|
11
|
+
* - Reads only the UP half of each file (everything before `-- DOWN`).
|
|
12
|
+
* - Handles `CREATE TABLE [IF NOT EXISTS]`, `ALTER TABLE … ADD COLUMN`
|
|
13
|
+
* and `ALTER TABLE … DROP COLUMN`.
|
|
12
14
|
* - Maps the common Postgres types we see in extension migrations to TS.
|
|
13
15
|
* - Ignores constraint-only ALTER TABLE statements (PRIMARY KEY, FK).
|
|
14
16
|
* - Ignores CREATE INDEX, CREATE TYPE, CREATE FUNCTION, etc.
|
|
@@ -90,6 +92,19 @@ function mapPgTypeToTs(pgType) {
|
|
|
90
92
|
return isArray ? `${tsBase}[]` : tsBase;
|
|
91
93
|
}
|
|
92
94
|
// ─── SQL parsing ───────────────────────────────────────────────────────────
|
|
95
|
+
/**
|
|
96
|
+
* Keep only the UP half of a migration file. Extension migrations carry their
|
|
97
|
+
* rollback in the same file, after a line that is exactly `-- DOWN`; the
|
|
98
|
+
* engine's runner (`parseMigrationSql`) splits on that marker and only ever
|
|
99
|
+
* executes the UP half. Codegen read both halves, so a `DROP TABLE` /
|
|
100
|
+
* `ADD COLUMN` written for rollback described the generated types as much as
|
|
101
|
+
* the real schema did. Same anchored regex as the runner — a loose `-- DOWN`
|
|
102
|
+
* prefix match once cost the engine half a schema.
|
|
103
|
+
*/
|
|
104
|
+
function upSection(sql) {
|
|
105
|
+
const i = sql.search(/^--\s*DOWN\s*$/im);
|
|
106
|
+
return i < 0 ? sql : sql.slice(0, i);
|
|
107
|
+
}
|
|
93
108
|
/**
|
|
94
109
|
* Strip line comments (`-- …`) and block comments (`/* … * /`) so they don't
|
|
95
110
|
* confuse the table/column regexes. Dollar-quoted blocks are preserved
|
|
@@ -301,13 +316,18 @@ export function parseSchema(sqlChunks) {
|
|
|
301
316
|
}
|
|
302
317
|
return tables.get(name);
|
|
303
318
|
};
|
|
304
|
-
const allSql = sqlChunks.map(stripComments).join('\n');
|
|
319
|
+
const allSql = sqlChunks.map(upSection).map(stripComments).join('\n');
|
|
305
320
|
// CREATE TABLE [IF NOT EXISTS] <name> ( <body> )
|
|
306
321
|
const createRe = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s*\(/gi;
|
|
307
|
-
|
|
308
|
-
while ((m = createRe.exec(allSql)) !== null) {
|
|
322
|
+
for (const m of allSql.matchAll(createRe)) {
|
|
309
323
|
const tableName = m[1] ?? m[2];
|
|
310
|
-
|
|
324
|
+
// From the MATCH, not from the regex's `lastIndex`.
|
|
325
|
+
//
|
|
326
|
+
// `matchAll` clones the regex internally, so `createRe.lastIndex` stays 0
|
|
327
|
+
// here — it is only advanced by `exec`. Converting this loop from
|
|
328
|
+
// `while ((m = createRe.exec(...)))` and keeping `lastIndex` silently made
|
|
329
|
+
// every table body start at the top of the file; five tests caught it.
|
|
330
|
+
const openIdx = m.index + m[0].length - 1; // position of '('
|
|
311
331
|
const closeIdx = findMatchingParen(allSql, openIdx);
|
|
312
332
|
if (closeIdx < 0)
|
|
313
333
|
continue; // unbalanced — skip
|
|
@@ -316,11 +336,10 @@ export function parseSchema(sqlChunks) {
|
|
|
316
336
|
const tableCols = ensureTable(tableName);
|
|
317
337
|
for (const c of columns)
|
|
318
338
|
tableCols.set(c.name, c);
|
|
319
|
-
createRe.lastIndex = closeIdx + 1;
|
|
320
339
|
}
|
|
321
340
|
// ALTER TABLE <name> ADD COLUMN [IF NOT EXISTS] <col> <type> <rest>
|
|
322
341
|
const alterRe = /ALTER\s+TABLE\s+(?:"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s+ADD\s+COLUMN\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s+([^;]+?)(?=;|$)/gi;
|
|
323
|
-
|
|
342
|
+
for (const m of allSql.matchAll(alterRe)) {
|
|
324
343
|
const tableName = m[1] ?? m[2];
|
|
325
344
|
const colName = m[3] ?? m[4];
|
|
326
345
|
const tail = m[5];
|
|
@@ -330,6 +349,21 @@ export function parseSchema(sqlChunks) {
|
|
|
330
349
|
tableCols.set(col.name, col);
|
|
331
350
|
}
|
|
332
351
|
}
|
|
352
|
+
// ALTER TABLE <name> DROP COLUMN [IF EXISTS] <col>
|
|
353
|
+
//
|
|
354
|
+
// Run last, after every CREATE and ADD COLUMN: a column the migrations
|
|
355
|
+
// removed used to stay in the generated types, so `ctx.db` promised a
|
|
356
|
+
// column Postgres no longer has — the silent runtime failure this module
|
|
357
|
+
// exists to prevent.
|
|
358
|
+
//
|
|
359
|
+
// ponytail: a third pass, not an ordered walk of the statements. A column
|
|
360
|
+
// dropped and then re-added by a later migration would be lost; no
|
|
361
|
+
// extension does that today. Make the parser statement-ordered if one does.
|
|
362
|
+
const dropRe = /ALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))\s+DROP\s+COLUMN\s+(?:IF\s+EXISTS\s+)?(?:"([^"]+)"|([a-zA-Z_][a-zA-Z0-9_]*))/gi;
|
|
363
|
+
for (const m of allSql.matchAll(dropRe)) {
|
|
364
|
+
// Never `ensureTable` here — a DROP alone must not invent a table.
|
|
365
|
+
tables.get(m[1] ?? m[2])?.delete(m[3] ?? m[4]);
|
|
366
|
+
}
|
|
333
367
|
return {
|
|
334
368
|
tables: order.map((name) => ({ name, columns: [...tables.get(name).values()] })),
|
|
335
369
|
};
|
|
@@ -367,3 +401,103 @@ export function emitTypeScript(schema, opts = {}) {
|
|
|
367
401
|
function quoteIdentifierIfNeeded(name) {
|
|
368
402
|
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name) ? name : `'${name.replace(/'/g, "\\'")}'`;
|
|
369
403
|
}
|
|
404
|
+
// ── Collection types (RFC schema-as-code §8) ─────────────────────────────────
|
|
405
|
+
//
|
|
406
|
+
// One generator for both `zveltio generate-types` paths: the engine's
|
|
407
|
+
// `/api/admin/types` (which knows every registered field type, extensions'
|
|
408
|
+
// included) and `--from schema/` (no engine; core types only). Same fields in,
|
|
409
|
+
// same text out.
|
|
410
|
+
/**
|
|
411
|
+
* TypeScript input type of each core field type. The engine registers the same
|
|
412
|
+
* types in `field-types/index.ts`; a unit test there keeps the two equal.
|
|
413
|
+
*/
|
|
414
|
+
export const CORE_FIELD_TS_TYPES = {
|
|
415
|
+
text: 'string',
|
|
416
|
+
number: 'number',
|
|
417
|
+
boolean: 'boolean',
|
|
418
|
+
date: 'string',
|
|
419
|
+
datetime: 'string',
|
|
420
|
+
email: 'string',
|
|
421
|
+
url: 'string',
|
|
422
|
+
uuid: 'string',
|
|
423
|
+
json: 'Record<string, any>',
|
|
424
|
+
richtext: 'string',
|
|
425
|
+
file: '{ url: string; name: string; size: number; type: string }',
|
|
426
|
+
enum: 'string',
|
|
427
|
+
reference: 'string',
|
|
428
|
+
m2o: 'string',
|
|
429
|
+
location: '{ lat: number; lng: number }',
|
|
430
|
+
computed: 'never',
|
|
431
|
+
integer: 'number',
|
|
432
|
+
float: 'number',
|
|
433
|
+
textarea: 'string',
|
|
434
|
+
password: 'string',
|
|
435
|
+
slug: 'string',
|
|
436
|
+
color: 'string',
|
|
437
|
+
phone: 'string',
|
|
438
|
+
tags: 'string[]',
|
|
439
|
+
image: '{ url: string; name: string; size: number; width?: number; height?: number; alt?: string }',
|
|
440
|
+
o2m: 'string[]',
|
|
441
|
+
m2m: 'string[]',
|
|
442
|
+
m2a: '{ collection: string; id: string }[]',
|
|
443
|
+
geometry: '{ type: string; coordinates: any }',
|
|
444
|
+
vector: 'number[]',
|
|
445
|
+
smallint: 'number',
|
|
446
|
+
real: 'number',
|
|
447
|
+
decimal: 'number',
|
|
448
|
+
money: 'string',
|
|
449
|
+
varchar: 'string',
|
|
450
|
+
char: 'string',
|
|
451
|
+
time: 'string',
|
|
452
|
+
timetz: 'string',
|
|
453
|
+
interval: 'string',
|
|
454
|
+
bytea: 'string',
|
|
455
|
+
tsvector: 'string',
|
|
456
|
+
inet: 'string',
|
|
457
|
+
cidr: 'string',
|
|
458
|
+
macaddr: 'string',
|
|
459
|
+
xml: 'string',
|
|
460
|
+
bit: 'string',
|
|
461
|
+
varbit: 'string',
|
|
462
|
+
int4range: 'string',
|
|
463
|
+
int8range: 'string',
|
|
464
|
+
numrange: 'string',
|
|
465
|
+
daterange: 'string',
|
|
466
|
+
tsrange: 'string',
|
|
467
|
+
tstzrange: 'string',
|
|
468
|
+
};
|
|
469
|
+
/** A type `tsTypeOf` does not know is `any`. */
|
|
470
|
+
export function emitCollectionTypes(collection, tsTypeOf = (t) => CORE_FIELD_TS_TYPES[t]) {
|
|
471
|
+
const typeName = collection.name.charAt(0).toUpperCase() + collection.name.slice(1);
|
|
472
|
+
const inputFields = collection.fields
|
|
473
|
+
.map((f) => ` ${f.name}${f.required ? '' : '?'}: ${tsTypeOf(f.type) || 'any'};`)
|
|
474
|
+
.join('\n');
|
|
475
|
+
return `export interface ${typeName}Input {
|
|
476
|
+
${inputFields}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export interface ${typeName} extends ${typeName}Input {
|
|
480
|
+
id: string;
|
|
481
|
+
created_at: string;
|
|
482
|
+
updated_at: string;
|
|
483
|
+
status: string;
|
|
484
|
+
}`;
|
|
485
|
+
}
|
|
486
|
+
/** The whole `zveltio.d.ts`. */
|
|
487
|
+
export function emitCollectionTypesFile(collections, tsTypeOf) {
|
|
488
|
+
const types = collections.map((c) => emitCollectionTypes(c, tsTypeOf)).join('\n\n');
|
|
489
|
+
return `// Auto-generated by Zveltio\n// Do not edit manually\n\n${types}`;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* The collections of a schema directory, as `{ path: content }` (the shape
|
|
493
|
+
* `zveltio schema pull` writes), in name order.
|
|
494
|
+
*/
|
|
495
|
+
export function collectionsFromSchemaFiles(files) {
|
|
496
|
+
return Object.keys(files)
|
|
497
|
+
.filter((p) => /^collections\/[^/]+\.json$/.test(p))
|
|
498
|
+
.sort()
|
|
499
|
+
.map((p) => {
|
|
500
|
+
const file = JSON.parse(files[p]);
|
|
501
|
+
return { name: file.name, fields: file.fields ?? [] };
|
|
502
|
+
});
|
|
503
|
+
}
|
package/dist/schema-watcher.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* updated, or deleted.
|
|
7
7
|
*
|
|
8
8
|
* Usage (in `zveltio dev --watch`):
|
|
9
|
-
* import { watchSchema } from '@zveltio/sdk
|
|
9
|
+
* import { watchSchema } from '@zveltio/sdk';
|
|
10
10
|
* await watchSchema('http://localhost:3000', './src/zveltio-types.d.ts');
|
|
11
11
|
*/
|
|
12
12
|
export interface CollectionField {
|
|
@@ -20,8 +20,16 @@ export interface CollectionSchema {
|
|
|
20
20
|
fields: CollectionField[];
|
|
21
21
|
}
|
|
22
22
|
export interface WatchSchemaOptions {
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* A root-tenant API key holding the explicit scope
|
|
25
|
+
* `{ collection: '$schema', actions: ['read'] }` — a `*` scope does not include it.
|
|
26
|
+
*/
|
|
24
27
|
apiKey?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Extra headers for the collections fetch and the socket upgrade — e.g. a
|
|
30
|
+
* `cookie` carrying the session of a user who may alter collections.
|
|
31
|
+
*/
|
|
32
|
+
headers?: Record<string, string>;
|
|
25
33
|
/** Reconnect delay in ms (default: 3000) */
|
|
26
34
|
reconnectDelay?: number;
|
|
27
35
|
/** Called after each successful type regeneration */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-watcher.d.ts","sourceRoot":"","sources":["../src/schema-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"schema-watcher.d.ts","sourceRoot":"","sources":["../src/schema-watcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACrD,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAChC;AA8GD;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,MAAM,IAAI,CAAC,CAuFrB;AAED,iDAAiD;AACjD,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
package/dist/schema-watcher.js
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* updated, or deleted.
|
|
7
7
|
*
|
|
8
8
|
* Usage (in `zveltio dev --watch`):
|
|
9
|
-
* import { watchSchema } from '@zveltio/sdk
|
|
9
|
+
* import { watchSchema } from '@zveltio/sdk';
|
|
10
10
|
* await watchSchema('http://localhost:3000', './src/zveltio-types.d.ts');
|
|
11
11
|
*/
|
|
12
|
+
import { openWebSocket, WS_UNAUTHORIZED } from './realtime.js';
|
|
12
13
|
const TYPE_MAP = {
|
|
13
14
|
text: 'string',
|
|
14
15
|
textarea: 'string',
|
|
@@ -81,8 +82,8 @@ function toPascalCase(str) {
|
|
|
81
82
|
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
82
83
|
.join('');
|
|
83
84
|
}
|
|
84
|
-
async function fetchCollections(engineUrl, apiKey) {
|
|
85
|
-
const headers = { 'Content-Type': 'application/json' };
|
|
85
|
+
async function fetchCollections(engineUrl, apiKey, extra) {
|
|
86
|
+
const headers = { 'Content-Type': 'application/json', ...extra };
|
|
86
87
|
if (apiKey)
|
|
87
88
|
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
88
89
|
const res = await fetch(`${engineUrl}/api/collections`, { headers });
|
|
@@ -108,10 +109,10 @@ async function writeTypes(outputPath, content) {
|
|
|
108
109
|
* Returns a cleanup function that closes the WebSocket.
|
|
109
110
|
*/
|
|
110
111
|
export async function watchSchema(engineUrl, outputPath, options = {}) {
|
|
111
|
-
const { apiKey, reconnectDelay = 3000, onUpdate, onError } = options;
|
|
112
|
+
const { apiKey, headers, reconnectDelay = 3000, onUpdate, onError } = options;
|
|
112
113
|
// Generate initial types on startup
|
|
113
114
|
try {
|
|
114
|
-
const collections = await fetchCollections(engineUrl, apiKey);
|
|
115
|
+
const collections = await fetchCollections(engineUrl, apiKey, headers);
|
|
115
116
|
const content = generateTypesFile(collections);
|
|
116
117
|
await writeTypes(outputPath, content);
|
|
117
118
|
console.log(`[zveltio] ✓ Types generated at ${outputPath} (${collections.length} collections)`);
|
|
@@ -128,21 +129,29 @@ export async function watchSchema(engineUrl, outputPath, options = {}) {
|
|
|
128
129
|
function connect() {
|
|
129
130
|
if (stopped)
|
|
130
131
|
return;
|
|
131
|
-
|
|
132
|
+
// The key `fetchCollections` sends, on the upgrade too: without it the
|
|
133
|
+
// engine refuses the socket (401) and the watcher only ever reconnected.
|
|
134
|
+
ws = openWebSocket(wsUrl, { ...headers, ...(apiKey ? { 'X-API-Key': apiKey } : {}) });
|
|
132
135
|
ws.onopen = () => {
|
|
133
136
|
console.log('[zveltio] Schema watcher connected.');
|
|
134
|
-
//
|
|
135
|
-
|
|
137
|
+
// The engine's schema channel: `$` cannot start a collection name, so it
|
|
138
|
+
// never collides with a collection's record events.
|
|
139
|
+
ws.send(JSON.stringify({ type: 'subscribe', channel: '$schema' }));
|
|
136
140
|
};
|
|
137
141
|
ws.onmessage = async (event) => {
|
|
138
142
|
try {
|
|
139
143
|
const msg = JSON.parse(event.data);
|
|
144
|
+
// The subscribe was refused: this principal may not alter collections.
|
|
145
|
+
if (msg.type === 'error') {
|
|
146
|
+
onError?.(new Error(`Schema watcher: ${msg.message ?? 'subscribe refused'}`));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
140
149
|
const isSchemaChange = msg.event === 'schema:changed' ||
|
|
141
150
|
msg.type === 'schema:changed' ||
|
|
142
151
|
['create_collection', 'drop_collection', 'add_field', 'drop_field'].includes(msg.event);
|
|
143
152
|
if (!isSchemaChange)
|
|
144
153
|
return;
|
|
145
|
-
const collections = await fetchCollections(engineUrl, apiKey);
|
|
154
|
+
const collections = await fetchCollections(engineUrl, apiKey, headers);
|
|
146
155
|
const content = generateTypesFile(collections);
|
|
147
156
|
await writeTypes(outputPath, content);
|
|
148
157
|
const changed = msg.collection ?? msg.data?.collection ?? '?';
|
|
@@ -153,7 +162,13 @@ export async function watchSchema(engineUrl, outputPath, options = {}) {
|
|
|
153
162
|
// Non-fatal: keep watching
|
|
154
163
|
}
|
|
155
164
|
};
|
|
156
|
-
ws.onclose = () => {
|
|
165
|
+
ws.onclose = (event) => {
|
|
166
|
+
if (!stopped && event?.code === WS_UNAUTHORIZED) {
|
|
167
|
+
// The API key was revoked or expired: every retry would be refused.
|
|
168
|
+
stopped = true;
|
|
169
|
+
onError?.(new Error('Schema watcher stopped: the engine revoked its credentials.'));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
157
172
|
if (!stopped) {
|
|
158
173
|
console.log(`[zveltio] Schema watcher disconnected. Reconnecting in ${reconnectDelay}ms…`);
|
|
159
174
|
setTimeout(connect, reconnectDelay);
|
package/dist/studio/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare function applyFormAlterHooks(hooks: FormAlterHook[], schema: Form
|
|
|
35
35
|
export declare function sortSlotContributions<T extends {
|
|
36
36
|
priority?: number;
|
|
37
37
|
}>(items: T[]): T[];
|
|
38
|
+
export { removeOwnerFromSlots, registerOwnedOnSlot, type OwnedSlotContribution, } from './slot-owner-registry.js';
|
|
38
39
|
/** Register a top-level Studio page contributed by this extension. */
|
|
39
40
|
export declare function registerRoute(route: StudioRoute): void;
|
|
40
41
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/studio/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EAEV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAE/B,UAAU,SAAU,SAAQ,YAAY;IACtC,qDAAqD;IACrD,MAAM,IAAI,UAAU,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAoE5D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,EAAE,EACtB,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAChC,UAAU,CAWZ;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAGtF;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/studio/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EAEV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAE/B,UAAU,SAAU,SAAQ,YAAY;IACtC,qDAAqD;IACrD,MAAM,IAAI,UAAU,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAoE5D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,EAAE,EACtB,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAChC,UAAU,CAWZ;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAGtF;AAED,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC;AAqClC,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAE/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAE3E;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,eAAe,GAAG,IAAI,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAEvE;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,IAAI,MAAM,CAIrC;AAID,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,SAAS,GACV,MAAM,uBAAuB,CAAC"}
|
package/dist/studio/index.js
CHANGED
|
@@ -109,9 +109,11 @@ export function sortSlotContributions(items) {
|
|
|
109
109
|
// We rely on Array.prototype.sort being stable (TC39 since 2019).
|
|
110
110
|
return items.slice().sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
111
111
|
}
|
|
112
|
+
export { removeOwnerFromSlots, registerOwnedOnSlot, } from './slot-owner-registry.js';
|
|
112
113
|
function getStudioGlobal() {
|
|
113
114
|
if (typeof window === 'undefined')
|
|
114
115
|
return null;
|
|
116
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
115
117
|
const g = window.__zveltio;
|
|
116
118
|
if (!g) {
|
|
117
119
|
console.warn('[zveltio/sdk/studio] window.__zveltio is not installed. Is the bundle running inside Studio?');
|
|
@@ -176,5 +178,6 @@ export function registerAssetPreview(handler) {
|
|
|
176
178
|
export function getEngineUrl() {
|
|
177
179
|
if (typeof window === 'undefined')
|
|
178
180
|
return '';
|
|
181
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
179
182
|
return window.__ZVELTIO_ENGINE_URL__ || getStudioGlobal()?.engineUrl || '';
|
|
180
183
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SlotContribution } from '../extension/index.js';
|
|
2
|
+
/** Owner tag set by compile-time `contribute.ts` modules; absent on legacy window.__zveltio calls. */
|
|
3
|
+
export type OwnedSlotContribution = SlotContribution & {
|
|
4
|
+
owner?: string;
|
|
5
|
+
};
|
|
6
|
+
/** Remove every contribution registered by `owner` across all slot names. */
|
|
7
|
+
export declare function removeOwnerFromSlots(slots: Record<string, OwnedSlotContribution[]>, owner: string): Record<string, OwnedSlotContribution[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Register (or replace) a single owner's contribution on one slot.
|
|
10
|
+
* Prior entries from the same owner on that slot are dropped first.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerOwnedOnSlot(slots: Record<string, OwnedSlotContribution[]>, owner: string, slotName: string, contribution: SlotContribution): Record<string, OwnedSlotContribution[]>;
|
|
13
|
+
//# sourceMappingURL=slot-owner-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot-owner-registry.d.ts","sourceRoot":"","sources":["../../src/studio/slot-owner-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,sGAAsG;AACtG,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,EAC9C,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAOzC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,EAC9C,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,gBAAgB,GAC7B,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAMzC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Remove every contribution registered by `owner` across all slot names. */
|
|
2
|
+
export function removeOwnerFromSlots(slots, owner) {
|
|
3
|
+
const out = {};
|
|
4
|
+
for (const [name, list] of Object.entries(slots)) {
|
|
5
|
+
const kept = list.filter((c) => c.owner !== owner);
|
|
6
|
+
if (kept.length > 0)
|
|
7
|
+
out[name] = kept;
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register (or replace) a single owner's contribution on one slot.
|
|
13
|
+
* Prior entries from the same owner on that slot are dropped first.
|
|
14
|
+
*/
|
|
15
|
+
export function registerOwnedOnSlot(slots, owner, slotName, contribution) {
|
|
16
|
+
const out = { ...slots };
|
|
17
|
+
const prev = out[slotName] ?? [];
|
|
18
|
+
const kept = prev.filter((c) => c.owner !== owner);
|
|
19
|
+
out[slotName] = [...kept, { ...contribution, owner }];
|
|
20
|
+
return out;
|
|
21
|
+
}
|
package/dist/svelte.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ```svelte
|
|
7
7
|
* <script lang="ts">
|
|
8
8
|
* import { SyncManager } from '@zveltio/sdk';
|
|
9
|
-
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk
|
|
9
|
+
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk';
|
|
10
10
|
*
|
|
11
11
|
* let todos = $state<any[]>([]);
|
|
12
12
|
* const unsub = useSyncCollection(sync, 'todos', (records) => { todos = records; });
|
package/dist/svelte.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,UAAU,EAAE,MAAM,EAElB,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,GAC/B,MAAM,IAAI,CAGZ;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,EACnF,UAAU,SAAO,GAChB,MAAM,IAAI,CAeZ"}
|
package/dist/svelte.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ```svelte
|
|
7
7
|
* <script lang="ts">
|
|
8
8
|
* import { SyncManager } from '@zveltio/sdk';
|
|
9
|
-
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk
|
|
9
|
+
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk';
|
|
10
10
|
*
|
|
11
11
|
* let todos = $state<any[]>([]);
|
|
12
12
|
* const unsub = useSyncCollection(sync, 'todos', (records) => { todos = records; });
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* Calls `setter` immediately with current state and on each update.
|
|
24
24
|
* Returns the unsubscribe function.
|
|
25
25
|
*/
|
|
26
|
-
export function useSyncCollection(sync, collection,
|
|
26
|
+
export function useSyncCollection(sync, collection,
|
|
27
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
28
|
+
setter) {
|
|
27
29
|
const col = sync.collection(collection);
|
|
28
30
|
return col.subscribe(setter);
|
|
29
31
|
}
|
package/dist/sync-manager.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export declare class SyncManager {
|
|
|
20
20
|
private syncTimer;
|
|
21
21
|
private isOnline;
|
|
22
22
|
private isSyncing;
|
|
23
|
+
/** Set by `stop()`; `start()` checks it after every await it makes. */
|
|
24
|
+
private stopped;
|
|
25
|
+
private readonly onOnline;
|
|
26
|
+
private readonly onOffline;
|
|
23
27
|
private listeners;
|
|
24
28
|
constructor(client: ZveltioClient, config?: SyncManagerConfig);
|
|
25
29
|
start(realtimeUrl?: string): Promise<void>;
|
|
@@ -32,22 +36,22 @@ export declare class SyncManager {
|
|
|
32
36
|
collection(name: string): {
|
|
33
37
|
/** List records — reads LOCAL instantly */
|
|
34
38
|
list: () => Promise<{
|
|
35
|
-
_syncStatus: "
|
|
39
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
36
40
|
id: string;
|
|
37
41
|
}[]>;
|
|
38
42
|
/** Get one record — reads LOCAL instantly */
|
|
39
43
|
get: (id: string) => Promise<{
|
|
40
|
-
_syncStatus: "
|
|
44
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
41
45
|
id: string;
|
|
42
46
|
} | null>;
|
|
43
47
|
/** Create — writes LOCAL + queues sync */
|
|
44
48
|
create: (data: Record<string, any>) => Promise<{
|
|
45
|
-
_syncStatus: "
|
|
49
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
46
50
|
id: string;
|
|
47
51
|
}>;
|
|
48
52
|
/** Update — writes LOCAL + queues sync */
|
|
49
53
|
update: (id: string, data: Record<string, any>) => Promise<{
|
|
50
|
-
_syncStatus: "
|
|
54
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
51
55
|
id: string;
|
|
52
56
|
}>;
|
|
53
57
|
/** Delete — soft delete LOCAL + queues sync */
|
|
@@ -62,12 +66,53 @@ export declare class SyncManager {
|
|
|
62
66
|
/** Force sync now (non-blocking) */
|
|
63
67
|
syncNow(): Promise<void>;
|
|
64
68
|
private notifyListeners;
|
|
69
|
+
/**
|
|
70
|
+
* Open the local store without starting background sync.
|
|
71
|
+
*
|
|
72
|
+
* `start()` opens the store, attaches online/offline listeners, connects
|
|
73
|
+
* realtime and installs a periodic timer. A caller driving `pull()` and
|
|
74
|
+
* `push()` explicitly — the `OfflineProvider` contract in `offline/` — wants
|
|
75
|
+
* the store and none of the rest, and a timer firing `syncNow()` underneath it
|
|
76
|
+
* makes "how many operations did that push send" unanswerable.
|
|
77
|
+
*/
|
|
78
|
+
open(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Pull rows for the named collections from the server into the local store.
|
|
81
|
+
*
|
|
82
|
+
* There was no way to do this. Records reached the local store only through
|
|
83
|
+
* realtime events, one at a time, which means a client that was offline while
|
|
84
|
+
* a row was created never learns it exists: it missed the event and nothing
|
|
85
|
+
* ever asks the server what it has. `syncNow()` is push-only despite the name.
|
|
86
|
+
*
|
|
87
|
+
* Reads `POST /api/sync/pull`, which returns what changed since the cursors
|
|
88
|
+
* kept in the local store, deletes included. Paging `list()` instead — what
|
|
89
|
+
* this did before — never removed anything: a row deleted on the server
|
|
90
|
+
* stayed in every local store that had pulled it.
|
|
91
|
+
*
|
|
92
|
+
* A collection pulled for the first time, or one the server answers with
|
|
93
|
+
* `resync`, loses its synced local rows before the page is applied; local
|
|
94
|
+
* edits not yet pushed stay. `/api/sync` takes sessions only, so a client
|
|
95
|
+
* authenticated by an API key (403) falls back to paging `list()`, without
|
|
96
|
+
* deletes.
|
|
97
|
+
*/
|
|
98
|
+
pull(collections: string[], pageSize?: number): Promise<number>;
|
|
99
|
+
private pullChanges;
|
|
100
|
+
/** Pages through `list()`; stops on the first page that comes back short. */
|
|
101
|
+
private pullPages;
|
|
65
102
|
/** Status: pending operations count, conflicts count */
|
|
66
103
|
getStatus(): Promise<{
|
|
67
104
|
pending: number;
|
|
68
105
|
conflicts: number;
|
|
69
106
|
isOnline: boolean;
|
|
70
107
|
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Delete everything the local store holds — records, pending writes, blobs,
|
|
110
|
+
* pull positions — so the next user of this browser neither sees this user's
|
|
111
|
+
* data nor sends this user's queued writes under their own session. Call it
|
|
112
|
+
* after sign-out (a sync started then is refused and stores nothing); call
|
|
113
|
+
* `syncNow()` before sign-out to push what is pending, which is lost otherwise.
|
|
114
|
+
*/
|
|
115
|
+
clearLocalData(): Promise<void>;
|
|
71
116
|
stop(): Promise<void>;
|
|
72
117
|
}
|
|
73
118
|
//# sourceMappingURL=sync-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../src/sync-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../src/sync-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAUjD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IAEpD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC9C,mHAAmH;IACnH,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;CAC7C;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,SAAS,CAA+C;IAChE,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAAkB;IACnC,uEAAuE;IACvE,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGvB;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAExB;IAEF,OAAO,CAAC,SAAS,CAAyD;gBAE9D,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,iBAAsB;IAY3D,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BhD;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;QAEnB,2CAA2C;;;;;QAU3C,6CAA6C;kBAC7B,MAAM;;;;QAUtB,0CAA0C;uBAErB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAYxC,0CAA0C;qBAEvB,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAapD,+CAA+C;qBAC5B,MAAM;QAMzB,qDAAqD;8BAE/B,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI;QA8C9C,8CAA8C;;QAK9C,kCAAkC;8BAEN,MAAM,gBAAgB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;IAQzE,oCAAoC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAwGhB,eAAe;IAmB7B;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;;;;;;;;;;;;;;;OAkBG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,SAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAgBpD,WAAW;IAoCzB,6EAA6E;YAC/D,SAAS;IAsBvB,wDAAwD;IAClD,SAAS,IAAI,OAAO,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IAUF;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAY5B"}
|