@pgxsinkit/client 0.1.31 → 0.1.36

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.
Files changed (85) hide show
  1. package/README.md +11 -0
  2. package/dist/convergence.d.ts +76 -0
  3. package/dist/convergence.d.ts.map +1 -0
  4. package/dist/debug.d.ts +34 -0
  5. package/dist/debug.d.ts.map +1 -0
  6. package/dist/index.d.ts +421 -7
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +7214 -2234
  9. package/dist/index.js.map +74 -44
  10. package/dist/lazy-guard.d.ts +58 -0
  11. package/dist/lazy-guard.d.ts.map +1 -0
  12. package/dist/local-store.d.ts +56 -0
  13. package/dist/local-store.d.ts.map +1 -0
  14. package/dist/local-tables.d.ts +707 -0
  15. package/dist/local-tables.d.ts.map +1 -0
  16. package/dist/mutation-state.d.ts +62 -0
  17. package/dist/mutation-state.d.ts.map +1 -0
  18. package/dist/mutation.d.ts +117 -4
  19. package/dist/mutation.d.ts.map +1 -1
  20. package/dist/schema.d.ts +49 -0
  21. package/dist/schema.d.ts.map +1 -1
  22. package/dist/shape-sync.d.ts +180 -0
  23. package/dist/shape-sync.d.ts.map +1 -0
  24. package/dist/sync/apply.d.ts +51 -0
  25. package/dist/sync/apply.d.ts.map +1 -0
  26. package/dist/sync/copy.d.ts +43 -0
  27. package/dist/sync/copy.d.ts.map +1 -0
  28. package/dist/sync/drizzle-executor.d.ts +5 -0
  29. package/dist/sync/drizzle-executor.d.ts.map +1 -0
  30. package/dist/sync/index.d.ts +32 -0
  31. package/dist/sync/index.d.ts.map +1 -0
  32. package/dist/sync/metadata-tables.d.ts +131 -0
  33. package/dist/sync/metadata-tables.d.ts.map +1 -0
  34. package/dist/sync/nudge.d.ts +49 -0
  35. package/dist/sync/nudge.d.ts.map +1 -0
  36. package/dist/sync/shape-inbox.d.ts +215 -0
  37. package/dist/sync/shape-inbox.d.ts.map +1 -0
  38. package/dist/sync/subscription-state.d.ts +39 -0
  39. package/dist/sync/subscription-state.d.ts.map +1 -0
  40. package/dist/sync/tags.d.ts +130 -0
  41. package/dist/sync/tags.d.ts.map +1 -0
  42. package/dist/sync/types.d.ts +118 -0
  43. package/dist/sync/types.d.ts.map +1 -0
  44. package/dist/sync-auth.d.ts +53 -0
  45. package/dist/sync-auth.d.ts.map +1 -0
  46. package/dist/worker/attach-sync-client.d.ts +75 -0
  47. package/dist/worker/attach-sync-client.d.ts.map +1 -0
  48. package/dist/worker/define-sync-worker.d.ts +75 -0
  49. package/dist/worker/define-sync-worker.d.ts.map +1 -0
  50. package/dist/worker/live-diff.d.ts +44 -0
  51. package/dist/worker/live-diff.d.ts.map +1 -0
  52. package/dist/worker/protocol.d.ts +260 -0
  53. package/dist/worker/protocol.d.ts.map +1 -0
  54. package/dist/worker/token-cache.d.ts +26 -0
  55. package/dist/worker/token-cache.d.ts.map +1 -0
  56. package/oxlint-plugin.js +143 -0
  57. package/package.json +19 -7
  58. package/skills/core/SKILL.md +197 -0
  59. package/skills/operating/SKILL.md +243 -0
  60. package/src/convergence.ts +197 -0
  61. package/src/debug.ts +151 -0
  62. package/src/index.ts +1104 -44
  63. package/src/lazy-guard.ts +121 -0
  64. package/src/local-store.ts +193 -0
  65. package/src/local-tables.ts +546 -0
  66. package/src/mutation-state.ts +90 -0
  67. package/src/mutation.ts +1868 -562
  68. package/src/schema.ts +352 -27
  69. package/src/shape-sync.ts +477 -0
  70. package/src/sync/apply.ts +530 -0
  71. package/src/sync/copy.ts +206 -0
  72. package/src/sync/drizzle-executor.ts +48 -0
  73. package/src/sync/index.ts +1076 -0
  74. package/src/sync/metadata-tables.ts +67 -0
  75. package/src/sync/nudge.ts +110 -0
  76. package/src/sync/shape-inbox.ts +566 -0
  77. package/src/sync/subscription-state.ts +135 -0
  78. package/src/sync/tags.ts +365 -0
  79. package/src/sync/types.ts +132 -0
  80. package/src/sync-auth.ts +117 -0
  81. package/src/worker/attach-sync-client.ts +558 -0
  82. package/src/worker/define-sync-worker.ts +596 -0
  83. package/src/worker/live-diff.ts +140 -0
  84. package/src/worker/protocol.ts +325 -0
  85. package/src/worker/token-cache.ts +84 -0
@@ -0,0 +1,58 @@
1
+ import type { SyncTableRegistry } from "@pgxsinkit/contracts";
2
+ /**
3
+ * Lazy-relation safety (ADR-0021).
4
+ *
5
+ * A `lazy` relation is held out of the eager boot and only subscribed on first reference. The hazard is
6
+ * a query reading it *before* it is hydrated — which silently returns empty/stale rows. This pure,
7
+ * React-free core detects which lazy relations a query reads by scanning its **compiled** SQL, so the
8
+ * caller can activate them (and hydrate-then-run) before the query executes.
9
+ *
10
+ * Why a single SQL scan is sufficient (and why there is no Proxy / builder-AST walk): Drizzle compiles
11
+ * a query to parameterised SQL — values are bound (`$1`, `$2`), never inlined — and emits every relation
12
+ * as a **quoted** identifier (`"name"`, or `"schema"."name"` when it carries a schema). So the compiled
13
+ * SQL is ground truth: a relation the query reads must appear there by name, and the only things in the
14
+ * text are quoted identifiers, keywords and `$n` placeholders. The index is built from the *same* Drizzle
15
+ * objects that emit the SQL (`getTableConfig`/`getViewConfig`), so a token matches emission by
16
+ * construction — schema and all. See "Known limitations" in ADR-0021 for the residual edges.
17
+ */
18
+ /** Static index of a registry's lazy relations and the exact quoted tokens their reads compile to. */
19
+ export interface LazyGuardIndex {
20
+ /** Registry keys whose subscription timing is `lazy`. */
21
+ readonly lazyKeys: ReadonlySet<string>;
22
+ /**
23
+ * Per lazy key, the exact quoted reference token(s) the compiled SQL emits when reading it: the synced
24
+ * table (and, for readwrite, its read-model view) as `"name"` or `"schema"."name"`. Schema-qualified
25
+ * when the Drizzle object carries a schema — which makes the token collision-proof against bare
26
+ * aliases/CTEs.
27
+ */
28
+ readonly lazyTokens: ReadonlyMap<string, readonly string[]>;
29
+ }
30
+ /** Build the {@link LazyGuardIndex} for a registry. Cheap and pure — cache it per client. */
31
+ export declare function buildLazyGuardIndex(registry: SyncTableRegistry): LazyGuardIndex;
32
+ /**
33
+ * The compiled-SQL scan: the lazy registry keys whose quoted reference token appears in `sql`. Because
34
+ * the token is fully quoted it is self-delimiting (`"a"` cannot match inside `"ab"`), so a substring test
35
+ * is exact. A *bare* token sitting in alias position (`… as "name"`, which Drizzle emits for `.as("name")`)
36
+ * is excluded — the one realistic collision for a schema-less relation; a schema-qualified token cannot be
37
+ * aliased and so needs no such guard.
38
+ */
39
+ export declare function findReferencedLazyKeysInSql(sql: string, index: LazyGuardIndex): Set<string>;
40
+ /**
41
+ * The activation backstop (ADR-0021): throw if a query references a lazy relation that is still not
42
+ * active. Called *after* the referenced lazy relations have been activated, so in the normal path every
43
+ * scanned relation is now active and this passes. It fires only when activation could not make a
44
+ * referenced relation active (a start that failed, or a lazy relation with no consistency group) —
45
+ * converting a would-be silent empty/stale read into a loud error.
46
+ */
47
+ export declare function assertLazyRefsActivated(args: {
48
+ sql: string;
49
+ index: LazyGuardIndex;
50
+ isActive: (key: string) => boolean;
51
+ }): void;
52
+ /** Thrown by the backstop ({@link assertLazyRefsActivated}) when a referenced lazy relation could not be activated. */
53
+ export declare class LazyRelationNotActivatedError extends Error {
54
+ /** The lazy registry keys that were referenced but could not be activated. */
55
+ readonly relations: readonly string[];
56
+ constructor(relations: readonly string[]);
57
+ }
58
+ //# sourceMappingURL=lazy-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-guard.d.ts","sourceRoot":"","sources":["../src/lazy-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AAEH,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;CAC7D;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,CAmB/E;AAOD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,CAM3F;AAaD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,GAAG,IAAI,CAIP;AAED,uHAAuH;AACvH,qBAAa,6BAA8B,SAAQ,KAAK;IACtD,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAEtC,YAAY,SAAS,EAAE,SAAS,MAAM,EAAE,EAUvC;CACF"}
@@ -0,0 +1,56 @@
1
+ import { type MutationDiagnostics, type SyncTableRegistry } from "@pgxsinkit/contracts";
2
+ import type { MutationDb } from "./mutation";
3
+ /**
4
+ * The fingerprint-keyed local store (ADR-0006). The registry fingerprint the local PGlite
5
+ * database was provisioned under is recorded in the local-meta table; comparing it to the
6
+ * current fingerprint on boot is how a registry change is *detected* (rather than a
7
+ * hand-bumped `idb://…-vN` suffix), which drives the drain-then-drop read-cache rebuild.
8
+ */
9
+ /** A boot-time registry-version reconciliation outcome (ADR-0006 drain-then-drop). */
10
+ export interface LocalStoreVersionEvent {
11
+ status: "rebuilt" | "deferred";
12
+ previousFingerprint: string;
13
+ nextFingerprint: string;
14
+ /** Mutations still owed to the server (pending + sending + failed + quarantined). */
15
+ owedMutations: number;
16
+ }
17
+ /** The minimal mutation-runtime surface the version reconciliation needs. */
18
+ interface VersionReconcileRuntime {
19
+ registryVersion: string;
20
+ readMutationStats: () => Promise<MutationDiagnostics>;
21
+ }
22
+ /** The registry fingerprint the local store was last provisioned under, or null if unstamped. */
23
+ export declare function readStoredRegistryFingerprint(db: MutationDb, registry: SyncTableRegistry): Promise<string | null>;
24
+ /**
25
+ * The consistency-group keys of `lazy + persistent` groups that were activated on a previous boot
26
+ * (ADR-0021 §2). On boot these are promoted into the eager subscription set, so a once-activated durable
27
+ * lazy group resumes permanently with no per-session re-evaluation. (`ephemeral` activation is never
28
+ * persisted, so it never appears here.)
29
+ */
30
+ export declare function readActivatedLazyGroups(db: MutationDb, registry: SyncTableRegistry): Promise<Set<string>>;
31
+ /** Persist a `lazy + persistent` group's activation, so the next boot promotes it to eager (ADR-0021 §2). */
32
+ export declare function writeLazyGroupActivation(db: MutationDb, registry: SyncTableRegistry, groupKey: string): Promise<void>;
33
+ /** Clear a persisted lazy activation — an explicit `desync` reverts the group to dormant next boot (ADR-0021 §2). */
34
+ export declare function clearLazyGroupActivation(db: MutationDb, registry: SyncTableRegistry, groupKey: string): Promise<void>;
35
+ /** Stamp the local store with the fingerprint it is now provisioned under. */
36
+ export declare function writeStoredRegistryFingerprint(db: MutationDb, registry: SyncTableRegistry, fingerprint: string): Promise<void>;
37
+ /**
38
+ * Reconcile the local store against the current registry fingerprint (ADR-0006). A fresh
39
+ * (unstamped) store is stamped; an unchanged fingerprint is a no-op. On a change, the read
40
+ * cache is dropped and rebuilt at the new shape **only when nothing is owed locally** —
41
+ * otherwise the rebuild is deferred (and retried on a later boot) so un-flushed/quarantined
42
+ * writes are never silently dropped. The drain happens across sessions: pending writes flush
43
+ * and reconcile during normal use, and the rebuild completes once the journal is clear.
44
+ *
45
+ * An unstamped store is always treated as brand-new. There is no pre-fingerprint-store path:
46
+ * the fingerprint mechanism shipped before launch, so every store in existence was
47
+ * provisioned with it (and a stamped store's journal therefore always has `registry_version`).
48
+ */
49
+ export declare function reconcileLocalStoreVersion<TRegistry extends SyncTableRegistry>(args: {
50
+ db: MutationDb;
51
+ registry: TRegistry;
52
+ runtime: VersionReconcileRuntime;
53
+ onSchemaChange?: (event: LocalStoreVersionEvent) => void | Promise<void>;
54
+ }): Promise<LocalStoreVersionEvent | null>;
55
+ export {};
56
+ //# sourceMappingURL=local-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-store.d.ts","sourceRoot":"","sources":["../src/local-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAS7C;;;;;GAKG;AAEH,sFAAsF;AACtF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,qFAAqF;IACrF,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,6EAA6E;AAC7E,UAAU,uBAAuB;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACvD;AAED,iGAAiG;AACjG,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWxB;AAKD;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAS/G;AAaD,6GAA6G;AAC7G,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,qHAAqH;AACrH,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAOf;AAED,8EAA8E;AAC9E,wBAAsB,8BAA8B,CAClD,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,0BAA0B,CAAC,SAAS,SAAS,iBAAiB,EAAE,IAAI,EAAE;IAC1F,EAAE,EAAE,UAAU,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,uBAAuB,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1E,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAezC"}