@pgxsinkit/client 0.1.32 → 0.1.40
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 +11 -0
- package/dist/boot-report.d.ts +134 -0
- package/dist/boot-report.d.ts.map +1 -0
- package/dist/convergence.d.ts +76 -0
- package/dist/convergence.d.ts.map +1 -0
- package/dist/debug.d.ts +34 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/export-data.d.ts +100 -0
- package/dist/export-data.d.ts.map +1 -0
- package/dist/export-dump.d.ts +92 -0
- package/dist/export-dump.d.ts.map +1 -0
- package/dist/export-store.d.ts +214 -0
- package/dist/export-store.d.ts.map +1 -0
- package/dist/index.d.ts +615 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8083 -2286
- package/dist/index.js.map +81 -44
- package/dist/lazy-guard.d.ts +59 -0
- package/dist/lazy-guard.d.ts.map +1 -0
- package/dist/lifecycle-slot.d.ts +31 -0
- package/dist/lifecycle-slot.d.ts.map +1 -0
- package/dist/live-rows-sql.d.ts +21 -0
- package/dist/live-rows-sql.d.ts.map +1 -0
- package/dist/local-store.d.ts +56 -0
- package/dist/local-store.d.ts.map +1 -0
- package/dist/local-tables.d.ts +707 -0
- package/dist/local-tables.d.ts.map +1 -0
- package/dist/mutation-state.d.ts +69 -0
- package/dist/mutation-state.d.ts.map +1 -0
- package/dist/mutation.d.ts +129 -4
- package/dist/mutation.d.ts.map +1 -1
- package/dist/schema.d.ts +82 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/shape-sync.d.ts +190 -0
- package/dist/shape-sync.d.ts.map +1 -0
- package/dist/store-path.d.ts +132 -0
- package/dist/store-path.d.ts.map +1 -0
- package/dist/sync/apply.d.ts +51 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/copy.d.ts +43 -0
- package/dist/sync/copy.d.ts.map +1 -0
- package/dist/sync/drizzle-executor.d.ts +5 -0
- package/dist/sync/drizzle-executor.d.ts.map +1 -0
- package/dist/sync/index.d.ts +32 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/metadata-tables.d.ts +131 -0
- package/dist/sync/metadata-tables.d.ts.map +1 -0
- package/dist/sync/nudge.d.ts +49 -0
- package/dist/sync/nudge.d.ts.map +1 -0
- package/dist/sync/shape-inbox.d.ts +215 -0
- package/dist/sync/shape-inbox.d.ts.map +1 -0
- package/dist/sync/subscription-state.d.ts +39 -0
- package/dist/sync/subscription-state.d.ts.map +1 -0
- package/dist/sync/tags.d.ts +130 -0
- package/dist/sync/tags.d.ts.map +1 -0
- package/dist/sync/types.d.ts +126 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync-auth.d.ts +53 -0
- package/dist/sync-auth.d.ts.map +1 -0
- package/dist/testing.d.ts +27 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +17 -0
- package/dist/testing.js.map +11 -0
- package/dist/worker/attach-sync-client.d.ts +96 -0
- package/dist/worker/attach-sync-client.d.ts.map +1 -0
- package/dist/worker/define-sync-worker.d.ts +76 -0
- package/dist/worker/define-sync-worker.d.ts.map +1 -0
- package/dist/worker/live-diff.d.ts +44 -0
- package/dist/worker/live-diff.d.ts.map +1 -0
- package/dist/worker/protocol.d.ts +341 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/token-cache.d.ts +26 -0
- package/dist/worker/token-cache.d.ts.map +1 -0
- package/oxlint-plugin.js +143 -0
- package/package.json +20 -7
- package/skills/core/SKILL.md +210 -0
- package/skills/operating/SKILL.md +303 -0
- package/src/boot-report.ts +287 -0
- package/src/convergence.ts +197 -0
- package/src/debug.ts +151 -0
- package/src/export-data.ts +300 -0
- package/src/export-dump.ts +239 -0
- package/src/export-store.ts +309 -0
- package/src/index.ts +1652 -51
- package/src/lazy-guard.ts +135 -0
- package/src/lifecycle-slot.ts +66 -0
- package/src/live-rows-sql.ts +45 -0
- package/src/local-store.ts +193 -0
- package/src/local-tables.ts +546 -0
- package/src/mutation-state.ts +99 -0
- package/src/mutation.ts +1910 -562
- package/src/schema.ts +472 -28
- package/src/shape-sync.ts +498 -0
- package/src/store-path.ts +249 -0
- package/src/sync/apply.ts +530 -0
- package/src/sync/copy.ts +206 -0
- package/src/sync/drizzle-executor.ts +48 -0
- package/src/sync/index.ts +1087 -0
- package/src/sync/metadata-tables.ts +67 -0
- package/src/sync/nudge.ts +110 -0
- package/src/sync/shape-inbox.ts +566 -0
- package/src/sync/subscription-state.ts +135 -0
- package/src/sync/tags.ts +365 -0
- package/src/sync/types.ts +141 -0
- package/src/sync-auth.ts +117 -0
- package/src/testing.ts +53 -0
- package/src/worker/attach-sync-client.ts +653 -0
- package/src/worker/define-sync-worker.ts +762 -0
- package/src/worker/live-diff.ts +140 -0
- package/src/worker/protocol.ts +425 -0
- package/src/worker/token-cache.ts +84 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import type { SyncRuntimeStatus } from "@pgxsinkit/contracts";
|
|
2
|
+
import type { BootReport } from "../boot-report";
|
|
3
|
+
import type { ExportReport } from "../export-store";
|
|
4
|
+
export declare const BRIDGE_CHANNEL: "pgxsinkit-bridge";
|
|
5
|
+
export declare const BRIDGE_PROTOCOL_VERSION: 1;
|
|
6
|
+
/**
|
|
7
|
+
* A structured-clone transferable (an `ArrayBuffer`, a `MessagePort`, …). The library carries no DOM lib
|
|
8
|
+
* dependency (like the convergence triggers), so this is the toolkit's own name for the type a future
|
|
9
|
+
* columnar codec would hand to `postMessage`'s transfer list. v1's identity codec never produces one.
|
|
10
|
+
*/
|
|
11
|
+
export type BridgeTransferable = unknown;
|
|
12
|
+
/**
|
|
13
|
+
* The minimal MessagePort-shaped transport the bridge needs — the intersection of a real `MessagePort`,
|
|
14
|
+
* a `SharedWorker` port, and a dedicated `Worker`/`self`. Injected everywhere so the protocol layer is
|
|
15
|
+
* exercised with a plain `MessageChannel` (no Worker) in tests. `start()` is optional (MessagePort needs
|
|
16
|
+
* it, `Worker`/`self` do not); `close()` is optional (a dedicated `self` cannot be closed by the tab).
|
|
17
|
+
*/
|
|
18
|
+
export interface BridgePort {
|
|
19
|
+
postMessage: (message: unknown, transfer?: BridgeTransferable[]) => void;
|
|
20
|
+
addEventListener: (type: "message", listener: (event: {
|
|
21
|
+
data: unknown;
|
|
22
|
+
}) => void) => void;
|
|
23
|
+
removeEventListener: (type: "message", listener: (event: {
|
|
24
|
+
data: unknown;
|
|
25
|
+
}) => void) => void;
|
|
26
|
+
start?: () => void;
|
|
27
|
+
close?: () => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The wire envelope. `payload` is the codec-encoded body — opaque to the router, which only routes on
|
|
31
|
+
* `type` and correlates on `id`. Keeping the body opaque is what lets a future codec return a columnar
|
|
32
|
+
* buffer (a transferable) in `payload` without any change to routing.
|
|
33
|
+
*/
|
|
34
|
+
export interface BridgeEnvelope {
|
|
35
|
+
ch: typeof BRIDGE_CHANNEL;
|
|
36
|
+
v: typeof BRIDGE_PROTOCOL_VERSION;
|
|
37
|
+
type: BridgeMessageType;
|
|
38
|
+
/** Correlation id for request/response pairs (rpc, subscribe, token pull). Absent for fire-and-forget fanout. */
|
|
39
|
+
id?: string;
|
|
40
|
+
/** Codec-encoded body — opaque to the router; decode with the same {@link BridgeCodec}. */
|
|
41
|
+
payload: unknown;
|
|
42
|
+
}
|
|
43
|
+
export type BridgeMessageType = "provision" | "attach" | "detach" | "token-push" | "token-response" | "rpc" | "subscribe" | "unsubscribe" | "wake" | "set-online" | "provision-ack" | "attach-ack" | "token-request" | "rpc-result" | "live-initial" | "live-diff" | "event";
|
|
44
|
+
/** A single auth token snapshot the tab owns and pushes to the worker (ADR-0032 decision 3). */
|
|
45
|
+
export interface AuthTokenSnapshot {
|
|
46
|
+
accessToken: string;
|
|
47
|
+
/** Absolute expiry in epoch milliseconds (`Date.now()`-comparable), so the worker can apply an expiry margin. */
|
|
48
|
+
expiresAt: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* tab → worker: pre-spawn the store WITHOUT booting the engine (ADR-0032 decision 5). Sent at the
|
|
52
|
+
* login screen against the freshly-named spare worker: the worker only runs PGlite `create`/initdb
|
|
53
|
+
* (off every thread that matters) and holds the raw store idle — no schema, no shape streams, no token
|
|
54
|
+
* — until the real {@link AttachPayload} arrives (with config + token) and adopts the provisioned store.
|
|
55
|
+
* Role-agnostic on purpose: the spare is minted before the user (and role) is known, so provisioning
|
|
56
|
+
* carries no registry — the schema is applied at attach with the role-resolved registry.
|
|
57
|
+
*/
|
|
58
|
+
export interface ProvisionPayload {
|
|
59
|
+
/** The bound store id (informational; naming is done tab-side via the SharedWorker name). */
|
|
60
|
+
storeId?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The plain store PATH (ADR-0036) to `create` ahead of attach — a name, not a storage URL; the worker
|
|
63
|
+
* derives the backend (IndexedDB in a browser worker). When omitted, `storeId`/the worker default is used.
|
|
64
|
+
*/
|
|
65
|
+
storePath?: string;
|
|
66
|
+
/**
|
|
67
|
+
* @internal INTERNAL WIRE FIELD (not consumer config, ADR-0036). Carries the testing memory-backend
|
|
68
|
+
* override across the bridge, because a symbol-keyed marker does NOT survive `postMessage` structured
|
|
69
|
+
* clone — so the worker's memory-store selection travels as this explicit field. Set only by the test
|
|
70
|
+
* lane (via the attaching helper); a browser worker never sends it.
|
|
71
|
+
*/
|
|
72
|
+
testStoreBackend?: "memory";
|
|
73
|
+
}
|
|
74
|
+
/** worker → tab: the provision completed (or failed). Lets the login screen confirm the spare is warm. */
|
|
75
|
+
export interface ProvisionAckPayload {
|
|
76
|
+
ok: boolean;
|
|
77
|
+
storeId?: string;
|
|
78
|
+
/** Present when `!ok` — the initdb/create failed; the worker falls back to a fresh create at attach. */
|
|
79
|
+
error?: {
|
|
80
|
+
message: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* tab → worker: a store-backup tarball to restore from, carried on the boot {@link AttachPayload}
|
|
85
|
+
* (ADR-0035 decision 6). The mirror image of {@link ExportArtefactWire}: a `File`/`Blob` cannot cross the
|
|
86
|
+
* bridge as a transferable, so it is decomposed into its zero-copy `ArrayBuffer` (listed on `postMessage`'s
|
|
87
|
+
* transfer list) plus the metadata to rebuild it, and the worker reassembles a `Blob` from
|
|
88
|
+
* `buffer`/`mimeType` to hand `createSyncClient` as `restoreFrom`.
|
|
89
|
+
*/
|
|
90
|
+
export interface RestoreArtefactWire {
|
|
91
|
+
/** The backup tarball bytes — transferred, not copied. */
|
|
92
|
+
buffer: ArrayBuffer;
|
|
93
|
+
/** The backup file name (informational; PGlite's `loadDataDir` reads the bytes, not the name). */
|
|
94
|
+
fileName: string;
|
|
95
|
+
/** The backup MIME type (`application/x-gzip` / `application/x-tar`), used to rebuild the `Blob`. */
|
|
96
|
+
mimeType: string;
|
|
97
|
+
}
|
|
98
|
+
/** tab → worker: the attach handshake. The first attach boots the engine; later attaches join it. */
|
|
99
|
+
export interface AttachPayload {
|
|
100
|
+
/** The bound store id (SharedWorker naming resolves it tab-side before attach — ADR-0032 decision 5). */
|
|
101
|
+
storeId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Explicit plain store PATH (ADR-0036) if the worker should create its own store — a name, not a storage
|
|
104
|
+
* URL; the worker derives the backend. When omitted, `storeId`/the worker default is used.
|
|
105
|
+
*/
|
|
106
|
+
storePath?: string;
|
|
107
|
+
/**
|
|
108
|
+
* @internal INTERNAL WIRE FIELD (not consumer config, ADR-0036). Carries the testing memory-backend
|
|
109
|
+
* override across the bridge — a symbol-keyed marker does not survive structured clone, so the worker's
|
|
110
|
+
* memory-store selection travels as this explicit field. Set only by the test lane; never by a browser tab.
|
|
111
|
+
*/
|
|
112
|
+
testStoreBackend?: "memory";
|
|
113
|
+
/**
|
|
114
|
+
* Restore the store from a backup on THIS attach (ADR-0035 decision 6) — the worker-mode carrier of
|
|
115
|
+
* `createSyncClient`'s `restoreFrom`. Restore rides the FIRST attach (the boot attach): a `File`/`Blob`
|
|
116
|
+
* cannot cross `postMessage` as a transferable, so the tab decomposes it into a transferred `ArrayBuffer`
|
|
117
|
+
* plus its name/mime — the {@link ExportArtefactWire} pattern in reverse — and the worker recomposes it
|
|
118
|
+
* into a `Blob` and hands it to `createSyncClient`. Absent on every ordinary attach. An attach that carries
|
|
119
|
+
* this AFTER the engine has already booted is REFUSED (you cannot restore into a running store).
|
|
120
|
+
*/
|
|
121
|
+
restore?: RestoreArtefactWire;
|
|
122
|
+
/** The tab's current auth token at attach time, or null when unauthenticated. */
|
|
123
|
+
token: AuthTokenSnapshot | null;
|
|
124
|
+
/**
|
|
125
|
+
* Serializable per-attach config overrides (kept minimal; the urls are baked into the worker). `role`
|
|
126
|
+
* selects which baked registry the worker boots (ADR-0032 S3): the spare is minted role-agnostic, so
|
|
127
|
+
* the role is only known at claim/attach — a single worker file bakes BOTH registries and picks here.
|
|
128
|
+
* `freshStore` is the fresh-store prefetch-overlap hint (ADR-0032 S4): the tab's claim path knows a
|
|
129
|
+
* claimed spare is schemaless (fresh) while a mapped/returning store never is, and forwards that here so
|
|
130
|
+
* the worker's `createSyncClient` can overlap the shape catch-up with the local boot phases.
|
|
131
|
+
*/
|
|
132
|
+
config?: {
|
|
133
|
+
syncEnabled?: boolean;
|
|
134
|
+
role?: string;
|
|
135
|
+
freshStore?: boolean;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* tab → worker: gate the worker's outbound convergence (the board's Offline toggle, ADR-0032 S3). In
|
|
140
|
+
* in-process mode the toggle gates the local `autoSync` trigger; the worker owns convergence instead, so
|
|
141
|
+
* the tab forwards the flag and the worker suppresses/resumes its flush passes. Going back online fires
|
|
142
|
+
* one immediate pass so queued writes flush without waiting for the next interval tick.
|
|
143
|
+
*/
|
|
144
|
+
export interface SetOnlinePayload {
|
|
145
|
+
online: boolean;
|
|
146
|
+
}
|
|
147
|
+
/** worker → tab: attach acknowledged. `alreadyBooted` is false for the attach that booted the engine. */
|
|
148
|
+
export interface AttachAckPayload {
|
|
149
|
+
alreadyBooted: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* True when the engine's initial sync had ALREADY fired by the time this attach was acked (a late
|
|
152
|
+
* attach, ADR-0032 FIX 3). `ready` is monotonic in-process — once it resolves it stays resolved even if
|
|
153
|
+
* the phase later degrades — so a tab attaching after that moment must resolve `ready` immediately from
|
|
154
|
+
* the ack, rather than wait for a phase-"ready" status that may never come again.
|
|
155
|
+
*/
|
|
156
|
+
engineReady?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Present when the engine boot REJECTED for this attach: the tab rejects `attachSyncClient` with this
|
|
159
|
+
* message instead of hanging forever on the ack (ADR-0032 FIX 1). A later attach retries the boot.
|
|
160
|
+
*/
|
|
161
|
+
error?: {
|
|
162
|
+
message: string;
|
|
163
|
+
detail?: unknown;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** worker → tab: a broadcast pull-request — any attached tab may answer, first response wins (ADR-0032 decision 3). */
|
|
167
|
+
export interface TokenRequestPayload {
|
|
168
|
+
requestId: string;
|
|
169
|
+
}
|
|
170
|
+
/** tab → worker: the answer to a {@link TokenRequestPayload}. `token: null` = the tab has none. */
|
|
171
|
+
export interface TokenResponsePayload {
|
|
172
|
+
requestId: string;
|
|
173
|
+
token: AuthTokenSnapshot | null;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The RPC ops the attach facade proxies to the worker's booted client — the write API (mirrors
|
|
177
|
+
* `client.mutate`/flush), mutation-state reads, and the one-shot raw inspection reads (`rawQuery`/`rawExec`).
|
|
178
|
+
*/
|
|
179
|
+
export type RpcOp = "create" | "update" | "delete" | "batch" | "transaction" | "flush" | "reconcile" | "retryFailed" | "recoverSending" | "discardConflict" | "discardQuarantined" | "desync" | "discardEphemeral" | "readMutationDetails" | "diagnostics" | "rawQuery" | "rawExec" | "bootReport" | "exportStore" | "exportDiagnostics" | "exportData";
|
|
180
|
+
/** tab → worker: a write/read-of-mutation-state RPC. `id` correlates the matching {@link RpcResultPayload}. */
|
|
181
|
+
export interface RpcPayload {
|
|
182
|
+
op: RpcOp;
|
|
183
|
+
args: unknown[];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* worker → tab: the wire form of ANY local-store export (ADR-0035) — the store backup's tarball OR the
|
|
187
|
+
* diagnostic dump's SQL — carried as the `value` of an {@link RpcResultPayload}. The artefact crosses as a
|
|
188
|
+
* transferred `ArrayBuffer` (zero-copy — the sender lists `buffer` in `postMessage`'s transfer list) plus
|
|
189
|
+
* the metadata to rebuild it; the tab reconstructs a `File` from `buffer`/`fileName`/`mimeType`. A `File`
|
|
190
|
+
* cannot itself be transferred, so it is decomposed here and reassembled tab-side, exactly the pattern the
|
|
191
|
+
* codec's transferable seam anticipates for a zero-copy live-diff payload. `report` is the discriminated
|
|
192
|
+
* {@link ExportReport} union, so the tab knows which export it round-tripped.
|
|
193
|
+
*/
|
|
194
|
+
export interface ExportArtefactWire {
|
|
195
|
+
/** The artefact bytes (tarball or SQL) — transferred, not copied. */
|
|
196
|
+
buffer: ArrayBuffer;
|
|
197
|
+
/** The generated (or caller-supplied) artefact file name. */
|
|
198
|
+
fileName: string;
|
|
199
|
+
/** The artefact MIME type (`application/x-gzip` / `application/x-tar` for a backup, `application/sql` for a dump). */
|
|
200
|
+
mimeType: string;
|
|
201
|
+
/** The export report (ADR-0035), structured-cloned as a plain object — the `kind`-discriminated union. */
|
|
202
|
+
report: ExportReport;
|
|
203
|
+
}
|
|
204
|
+
/** worker → tab: an RPC outcome, mirroring today's in-process resolve/reject semantics. */
|
|
205
|
+
export interface RpcResultPayload {
|
|
206
|
+
ok: boolean;
|
|
207
|
+
/** The resolved value (present when `ok`). */
|
|
208
|
+
value?: unknown;
|
|
209
|
+
/** The rejection message + optional structured detail (present when `!ok`). */
|
|
210
|
+
error?: {
|
|
211
|
+
message: string;
|
|
212
|
+
detail?: unknown;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** tab → worker: register a live query. `id` correlates the initial snapshot; `queryId` keys subsequent diffs. */
|
|
216
|
+
export interface SubscribePayload {
|
|
217
|
+
queryId: string;
|
|
218
|
+
sql: string;
|
|
219
|
+
params: unknown[];
|
|
220
|
+
/**
|
|
221
|
+
* The unique output aliases the worker wraps the query's columns under so it is safe to MATERIALISE
|
|
222
|
+
* (one per output column, in the compiled SQL's column order). ADDITIVE and backward-compatible: an
|
|
223
|
+
* older tab omits it and the worker leaves the SQL untouched (name-keyed rows, as before); a newer tab
|
|
224
|
+
* supplies it for a JOIN with same-named columns, which `live.query`/`live.incrementalQuery` otherwise
|
|
225
|
+
* refuse to materialise (`column "title" specified more than once`). When present, result columns are
|
|
226
|
+
* the aliases, so {@link pkColumns} must name a PK by its alias.
|
|
227
|
+
*/
|
|
228
|
+
fields?: string[];
|
|
229
|
+
/**
|
|
230
|
+
* The result's primary-key columns, driving diff keying (§4). One column → the incremental path
|
|
231
|
+
* (`live.incrementalQuery`); many → worker-side diff by composite PK; empty/absent → value-identity
|
|
232
|
+
* fallback for a keyless query. When {@link fields} is supplied these name the ALIASED result columns.
|
|
233
|
+
*/
|
|
234
|
+
pkColumns?: string[];
|
|
235
|
+
/** Lazy relations to activate before the query runs (ADR-0021), forwarded to the worker's `prepareQuery`. */
|
|
236
|
+
use?: string[];
|
|
237
|
+
}
|
|
238
|
+
/** worker → tab: the initial ordered snapshot for a subscription. `id` correlates the `subscribe` request. */
|
|
239
|
+
export interface LiveInitialPayload {
|
|
240
|
+
queryId: string;
|
|
241
|
+
rows: Record<string, unknown>[];
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* worker → tab: a DIFF update for a subscription (§4). Never a full result-set resend after the initial
|
|
245
|
+
* snapshot. `order` is the full ordered list of row keys (cheap — keys only, no row bodies); `added`/
|
|
246
|
+
* `changed` carry only the delta row bodies; `removed` carries only the dropped keys. The tab materializer
|
|
247
|
+
* rebuilds the ordered array from `order`, reusing cached row objects for keys not in `added`/`changed` so
|
|
248
|
+
* an unchanged row keeps its object identity (React memo bails on `===`).
|
|
249
|
+
*/
|
|
250
|
+
export interface LiveDiffPayload {
|
|
251
|
+
queryId: string;
|
|
252
|
+
/** Every result key in ORDER BY order (the query's delivered order). */
|
|
253
|
+
order: string[];
|
|
254
|
+
added: {
|
|
255
|
+
key: string;
|
|
256
|
+
row: Record<string, unknown>;
|
|
257
|
+
}[];
|
|
258
|
+
changed: {
|
|
259
|
+
key: string;
|
|
260
|
+
row: Record<string, unknown>;
|
|
261
|
+
}[];
|
|
262
|
+
removed: string[];
|
|
263
|
+
}
|
|
264
|
+
/** worker → tab: the single broadcast event stream (ADR-0032 decision 7), re-exposed as today's callbacks. */
|
|
265
|
+
export type BridgeEvent = {
|
|
266
|
+
kind: "status";
|
|
267
|
+
status: SyncRuntimeStatus;
|
|
268
|
+
} | {
|
|
269
|
+
kind: "groupReady";
|
|
270
|
+
groupKey: string;
|
|
271
|
+
} | {
|
|
272
|
+
kind: "conflict";
|
|
273
|
+
details: unknown;
|
|
274
|
+
} | {
|
|
275
|
+
kind: "quarantine";
|
|
276
|
+
details: unknown;
|
|
277
|
+
} | {
|
|
278
|
+
kind: "reject";
|
|
279
|
+
details: unknown;
|
|
280
|
+
} | {
|
|
281
|
+
kind: "schema-change";
|
|
282
|
+
event: unknown;
|
|
283
|
+
} | {
|
|
284
|
+
kind: "sync-error";
|
|
285
|
+
message: string;
|
|
286
|
+
} | {
|
|
287
|
+
kind: "timing";
|
|
288
|
+
label: string;
|
|
289
|
+
ms: number;
|
|
290
|
+
data?: Record<string, unknown>;
|
|
291
|
+
} | {
|
|
292
|
+
kind: "boot-report";
|
|
293
|
+
report: BootReport;
|
|
294
|
+
} | {
|
|
295
|
+
kind: "debug";
|
|
296
|
+
stamp: number;
|
|
297
|
+
line: string;
|
|
298
|
+
data?: Record<string, unknown>;
|
|
299
|
+
};
|
|
300
|
+
/** tab → worker: an app-driven wake (online/visibilitychange), treated as a convergence pass request. */
|
|
301
|
+
export interface WakePayload {
|
|
302
|
+
reason: "online" | "visibility" | "manual";
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The codec every bridge payload crosses through (owner-mandated seam, ADR-0032 S2 §1). v1 ships exactly
|
|
306
|
+
* ONE codec — {@link identityCodec}, which relies on the transport's own structured clone. The seam exists
|
|
307
|
+
* so a columnar/transferable codec (e.g. one that packs live-diff rows into a shared `ArrayBuffer` and
|
|
308
|
+
* returns it as a transferable) can be swapped in later WITHOUT any protocol change: the router already
|
|
309
|
+
* treats `BridgeEnvelope.payload` as opaque, and `encode` may return `{ payload, transfer }` so the sender
|
|
310
|
+
* hands transferables to `postMessage`. Keep encode/decode inverse and side-effect free.
|
|
311
|
+
*/
|
|
312
|
+
export interface BridgeCodec {
|
|
313
|
+
/** Encode a raw payload into the envelope body. May declare transferables for a future zero-copy codec. */
|
|
314
|
+
encode: (payload: unknown) => {
|
|
315
|
+
payload: unknown;
|
|
316
|
+
transfer?: BridgeTransferable[];
|
|
317
|
+
};
|
|
318
|
+
/** Decode an envelope body back into the raw payload. Inverse of {@link encode}. */
|
|
319
|
+
decode: (payload: unknown) => unknown;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The v1 identity codec: the body IS the payload, and the transport's structured clone does the real
|
|
323
|
+
* copying. No transferables. The only codec shipped in S2 — swapping in a columnar codec later touches
|
|
324
|
+
* only this object, never the message types or the router.
|
|
325
|
+
*/
|
|
326
|
+
export declare const identityCodec: BridgeCodec;
|
|
327
|
+
/** Build a wire envelope, running the payload through the codec. Returns the envelope + any transferables. */
|
|
328
|
+
export declare function encodeEnvelope(codec: BridgeCodec, type: BridgeMessageType, payload: unknown, id?: string): {
|
|
329
|
+
envelope: BridgeEnvelope;
|
|
330
|
+
transfer?: BridgeTransferable[];
|
|
331
|
+
};
|
|
332
|
+
/** Type-guard a received message as a bridge envelope of the current protocol version (ignore foreign traffic). */
|
|
333
|
+
export declare function isBridgeEnvelope(data: unknown): data is BridgeEnvelope;
|
|
334
|
+
/**
|
|
335
|
+
* Send a typed message over a port: encode → post (with any transferables). The one write choke point.
|
|
336
|
+
* `transfer` lets a caller declare payload-specific transferables (e.g. a store-backup's `ArrayBuffer`,
|
|
337
|
+
* ADR-0035) WITHOUT teaching the shared codec about that op — they are merged after any the codec itself
|
|
338
|
+
* produces, so both the codec's future zero-copy path and per-message transfers coexist.
|
|
339
|
+
*/
|
|
340
|
+
export declare function postBridgeMessage(port: BridgePort, codec: BridgeCodec, type: BridgeMessageType, payload: unknown, id?: string, transfer?: BridgeTransferable[]): void;
|
|
341
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/worker/protocol.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,cAAc,EAAG,kBAA2B,CAAC;AAC1D,eAAO,MAAM,uBAAuB,EAAG,CAAU,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IACzE,gBAAgB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IAC1F,mBAAmB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,KAAK,IAAI,CAAC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EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAEnF,yGAAyG;AACzG,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAAC;CAC5C;AAID;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,2GAA2G;IAC3G,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAA;KAAE,CAAC;IACpF,oFAAoF;IACpF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CACvC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WAG3B,CAAC;AAIF,8GAA8G;AAC9G,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,OAAO,EAChB,EAAE,CAAC,EAAE,MAAM,GACV;IAAE,QAAQ,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAU/D;AAED,mHAAmH;AACnH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAOtE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,OAAO,EAChB,EAAE,CAAC,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,kBAAkB,EAAE,GAC9B,IAAI,CAQN"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuthTokenSnapshot } from "./protocol";
|
|
2
|
+
export interface WorkerTokenCache {
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the access token for a shape/flush request. Returns the cached token when it is comfortably
|
|
5
|
+
* ahead of expiry; otherwise broadcasts ONE pull (deduped across concurrent callers) and resolves when a
|
|
6
|
+
* tab answers. Falls back to the (stale) cached token if a pull yields nothing.
|
|
7
|
+
*/
|
|
8
|
+
getToken: () => Promise<string | undefined>;
|
|
9
|
+
/** The tab pushed a fresh token (auth state change or the initial attach) — cache it and satisfy any pull. */
|
|
10
|
+
push: (token: AuthTokenSnapshot | null) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Seed the cache from a LATER attach's token, but only if it is strictly fresher than what is cached
|
|
13
|
+
* (ADR-0032 FIX 5). Attach seeding must never CLOBBER a fresher cached token with an older/null one —
|
|
14
|
+
* only the explicit `push` path (the tab as auth owner saying "this is current") may overwrite
|
|
15
|
+
* unconditionally, including null on logout.
|
|
16
|
+
*/
|
|
17
|
+
pushIfFresher: (token: AuthTokenSnapshot | null) => void;
|
|
18
|
+
/** A tab answered a pull-request. First matching answer wins; later duplicates are ignored. */
|
|
19
|
+
respond: (requestId: string, token: AuthTokenSnapshot | null) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createWorkerTokenCache(options: {
|
|
22
|
+
marginMs: number;
|
|
23
|
+
broadcastRequest: (requestId: string) => void;
|
|
24
|
+
now?: () => number;
|
|
25
|
+
}): WorkerTokenCache;
|
|
26
|
+
//# sourceMappingURL=token-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-cache.d.ts","sourceRoot":"","sources":["../../src/worker/token-cache.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5C,8GAA8G;IAC9G,IAAI,EAAE,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IAChD;;;;;OAKG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IACzD,+FAA+F;IAC/F,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;CACvE;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB,GAAG,gBAAgB,CAmDnB"}
|
package/oxlint-plugin.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Custom oxlint plugin for pgxsinkit's guarded-query surface (ADR-0021).
|
|
2
|
+
//
|
|
3
|
+
// The type split makes `use` structurally absent on the pure `client.query` / `queryRow` path (they take
|
|
4
|
+
// the builder callback directly). This rule catches the two provenance facts the type system cannot see:
|
|
5
|
+
// A) a raw `sql` fragment smuggled into the pure path — the compiled-SQL scan can miss a lazy relation
|
|
6
|
+
// named as a bare/unquoted identifier there, silently losing the guard; and
|
|
7
|
+
// B) a `use` on the raw path (`queryRaw` / `useLiveQueryRaw`) whose builder is actually pure Drizzle — the
|
|
8
|
+
// scan already detects every relation, so the `use` is redundant (autofixed away).
|
|
9
|
+
//
|
|
10
|
+
// Shipped with @pgxsinkit/client via the `./oxlint` subpath export, so consumers can enable it in their
|
|
11
|
+
// own oxlint config: `"jsPlugins": ["@pgxsinkit/client/oxlint"]` + `"pgxsinkit/guarded-query-purity": "error"`.
|
|
12
|
+
// Plain JS (not TS, and outside src/) on purpose: it is a tooling artifact loaded by oxlint at lint time,
|
|
13
|
+
// not part of the library's typed surface, so it is neither built nor typechecked nor self-linted.
|
|
14
|
+
//
|
|
15
|
+
// NOTE: this plugin has NO version logic — it runs under whatever oxlint loads it (1.72, 1.73, …), not
|
|
16
|
+
// only the version it was written against. But oxlint's jsPlugins feature is alpha and NOT semver-covered:
|
|
17
|
+
// the plugin API it relies on (create/context/report, ESTree node `.range`, `fixer.removeRange`) can
|
|
18
|
+
// change on a *minor* oxlint bump without that being flagged as breaking. That is why oxlint is pinned to
|
|
19
|
+
// an EXACT version in package.json (no `^`) — so upgrades are deliberate. On every oxlint bump, re-run
|
|
20
|
+
// lint and confirm this rule still loads and fires; adjust it here if the alpha API drifted.
|
|
21
|
+
|
|
22
|
+
const PURE_METHODS = new Set(["query", "queryRow"]);
|
|
23
|
+
const RAW_METHODS = new Set(["queryRaw", "queryRawRow", "useLiveQueryRaw", "useLiveQueryRawRow"]);
|
|
24
|
+
|
|
25
|
+
/** Depth-first visit of every descendant AST node. */
|
|
26
|
+
function walk(node, visit) {
|
|
27
|
+
if (!node || typeof node !== "object") return;
|
|
28
|
+
if (typeof node.type === "string") visit(node);
|
|
29
|
+
for (const key in node) {
|
|
30
|
+
if (key === "parent") continue;
|
|
31
|
+
const child = node[key];
|
|
32
|
+
if (Array.isArray(child)) {
|
|
33
|
+
for (const item of child) walk(item, visit);
|
|
34
|
+
} else if (child && typeof child === "object") {
|
|
35
|
+
walk(child, visit);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** True if this build function embeds a raw SQL fragment: a ``sql`…` `` tagged template or `sql.raw(...)`. */
|
|
41
|
+
function usesRawSql(fn) {
|
|
42
|
+
let found = false;
|
|
43
|
+
walk(fn.body, (n) => {
|
|
44
|
+
if (found) return;
|
|
45
|
+
if (n.type === "TaggedTemplateExpression") {
|
|
46
|
+
const tag = n.tag;
|
|
47
|
+
if (tag && tag.type === "Identifier" && tag.name === "sql") found = true;
|
|
48
|
+
else if (tag && tag.type === "MemberExpression" && tag.property && tag.property.name === "sql") found = true;
|
|
49
|
+
} else if (n.type === "CallExpression") {
|
|
50
|
+
const c = n.callee;
|
|
51
|
+
if (
|
|
52
|
+
c &&
|
|
53
|
+
c.type === "MemberExpression" &&
|
|
54
|
+
c.object &&
|
|
55
|
+
c.object.name === "sql" &&
|
|
56
|
+
c.property &&
|
|
57
|
+
c.property.name === "raw"
|
|
58
|
+
) {
|
|
59
|
+
found = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isFunction(node) {
|
|
67
|
+
return !!node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const guardedQueryPurity = {
|
|
71
|
+
meta: {
|
|
72
|
+
type: "problem",
|
|
73
|
+
fixable: "code",
|
|
74
|
+
docs: { description: "Guard the pure/raw split of the pgxsinkit client query surface (ADR-0021)." },
|
|
75
|
+
},
|
|
76
|
+
create(context) {
|
|
77
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
78
|
+
return {
|
|
79
|
+
CallExpression(node) {
|
|
80
|
+
const callee = node.callee;
|
|
81
|
+
const method =
|
|
82
|
+
callee && callee.type === "MemberExpression"
|
|
83
|
+
? callee.property && callee.property.name
|
|
84
|
+
: callee && callee.type === "Identifier"
|
|
85
|
+
? callee.name
|
|
86
|
+
: undefined;
|
|
87
|
+
if (!method || (!PURE_METHODS.has(method) && !RAW_METHODS.has(method))) return;
|
|
88
|
+
|
|
89
|
+
const arg0 = node.arguments && node.arguments[0];
|
|
90
|
+
let buildFn;
|
|
91
|
+
let useProp;
|
|
92
|
+
if (isFunction(arg0)) {
|
|
93
|
+
buildFn = arg0; // pure callback form: query(fn) / queryRow(fn)
|
|
94
|
+
} else if (arg0 && arg0.type === "ObjectExpression") {
|
|
95
|
+
for (const p of arg0.properties) {
|
|
96
|
+
if (p.type !== "Property" || !p.key) continue;
|
|
97
|
+
if (p.key.name === "build") buildFn = p.value;
|
|
98
|
+
else if (p.key.name === "use") useProp = p;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!isFunction(buildFn)) return;
|
|
102
|
+
|
|
103
|
+
const raw = usesRawSql(buildFn);
|
|
104
|
+
|
|
105
|
+
// A) raw sql on the PURE path — the scan can miss a bare identifier → a real safety hole.
|
|
106
|
+
if (PURE_METHODS.has(method) && raw) {
|
|
107
|
+
const rawEquivalent = method === "queryRow" ? "queryRawRow" : "queryRaw";
|
|
108
|
+
context.report({
|
|
109
|
+
node: buildFn,
|
|
110
|
+
message:
|
|
111
|
+
`${method}() is the pure-Drizzle path but its build() embeds a raw \`sql\` fragment, which the ` +
|
|
112
|
+
`lazy-relation scan can miss (a bare identifier). Use client.${rawEquivalent}({ use, build }) and ` +
|
|
113
|
+
`declare the lazy relations in \`use\` (ADR-0021).`,
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// B) `use` on the raw path with a pure build — redundant. Autofix: drop the `use` property.
|
|
119
|
+
if (RAW_METHODS.has(method) && useProp && !raw) {
|
|
120
|
+
context.report({
|
|
121
|
+
node: useProp,
|
|
122
|
+
message:
|
|
123
|
+
"`use` is redundant here: build() is pure Drizzle, so the compiled-SQL scan detects every " +
|
|
124
|
+
"relation it reads. Drop `use` and prefer the pure query method (ADR-0021).",
|
|
125
|
+
fix(fixer) {
|
|
126
|
+
const text = sourceCode.getText();
|
|
127
|
+
const start = useProp.range[0];
|
|
128
|
+
let end = useProp.range[1];
|
|
129
|
+
while (end < text.length && /\s/.test(text[end])) end++;
|
|
130
|
+
if (text[end] === ",") end++;
|
|
131
|
+
return fixer.removeRange([start, end]);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export default {
|
|
141
|
+
meta: { name: "pgxsinkit" },
|
|
142
|
+
rules: { "guarded-query-purity": guardedQueryPurity },
|
|
143
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"tanstack-intent"
|
|
6
|
+
],
|
|
7
|
+
"license": "MIT",
|
|
4
8
|
"files": [
|
|
5
9
|
"dist",
|
|
6
10
|
"src",
|
|
7
|
-
"README.md"
|
|
11
|
+
"README.md",
|
|
12
|
+
"skills",
|
|
13
|
+
"oxlint-plugin.js"
|
|
8
14
|
],
|
|
9
15
|
"type": "module",
|
|
10
16
|
"main": "./dist/index.js",
|
|
@@ -13,7 +19,12 @@
|
|
|
13
19
|
".": {
|
|
14
20
|
"types": "./dist/index.d.ts",
|
|
15
21
|
"default": "./dist/index.js"
|
|
16
|
-
}
|
|
22
|
+
},
|
|
23
|
+
"./testing": {
|
|
24
|
+
"types": "./dist/testing.d.ts",
|
|
25
|
+
"default": "./dist/testing.js"
|
|
26
|
+
},
|
|
27
|
+
"./oxlint": "./oxlint-plugin.js"
|
|
17
28
|
},
|
|
18
29
|
"publishConfig": {
|
|
19
30
|
"access": "public"
|
|
@@ -22,12 +33,14 @@
|
|
|
22
33
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
23
34
|
},
|
|
24
35
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
36
|
+
"@electric-sql/client": "^1.5.24",
|
|
37
|
+
"@electric-sql/experimental": "^6.0.24",
|
|
38
|
+
"@electric-sql/pglite-tools": "0.4.4",
|
|
39
|
+
"@pgxsinkit/contracts": "0.1.40"
|
|
27
40
|
},
|
|
28
41
|
"peerDependencies": {
|
|
29
|
-
"@electric-sql/pglite": "0.5.
|
|
30
|
-
"drizzle-orm": "1.0.0-rc.
|
|
42
|
+
"@electric-sql/pglite": "0.5.4",
|
|
43
|
+
"drizzle-orm": "1.0.0-rc.4",
|
|
31
44
|
"zod": "^4.4.3"
|
|
32
45
|
},
|
|
33
46
|
"repository": {
|