@rebasepro/types 0.9.1-canary.58368ce → 0.9.1-canary.73476f2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/data.d.ts +2 -44
- package/dist/controllers/data_driver.d.ts +3 -45
- package/dist/types/entity_callbacks.d.ts +3 -3
- package/dist/types/websockets.d.ts +0 -27
- package/package.json +2 -2
- package/src/controllers/data.ts +2 -42
- package/src/controllers/data_driver.ts +3 -47
- package/src/types/entity_callbacks.ts +3 -3
- package/src/types/websockets.ts +0 -24
|
@@ -149,15 +149,6 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
149
149
|
* @returns The created entity
|
|
150
150
|
*/
|
|
151
151
|
create(data: Partial<EntityValues<M>>, id?: string | number): Promise<Entity<M>>;
|
|
152
|
-
/**
|
|
153
|
-
* Create many records in a single transaction.
|
|
154
|
-
*
|
|
155
|
-
* See {@link SDKCollectionClient.createMany}. Optional: not every driver can
|
|
156
|
-
* write in bulk, and callers should fall back to `create` per record.
|
|
157
|
-
*/
|
|
158
|
-
createMany?(data: Partial<EntityValues<M>>[], options?: {
|
|
159
|
-
upsert?: boolean;
|
|
160
|
-
}): Promise<Entity<M>[]>;
|
|
161
152
|
/**
|
|
162
153
|
* Update an existing record by ID.
|
|
163
154
|
* @returns The updated entity
|
|
@@ -271,43 +262,10 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
271
262
|
/**
|
|
272
263
|
* Create a new record.
|
|
273
264
|
* @param data The record data to create (the collection's `Insert` shape).
|
|
274
|
-
* @param id Optional specific
|
|
275
|
-
* whose key *is* `id`: the value goes in as that column. For a table keyed
|
|
276
|
-
* on anything else (a `sku`, a composite key), there is no `id` column to
|
|
277
|
-
* receive it — put the key in `data` instead, where it belongs among the
|
|
278
|
-
* columns.
|
|
265
|
+
* @param id Optional specific ID to use for the new record.
|
|
279
266
|
* @returns The created row
|
|
280
267
|
*/
|
|
281
268
|
create(data: I, id?: string | number): Promise<M>;
|
|
282
|
-
/**
|
|
283
|
-
* Write many records in a single request and a single transaction.
|
|
284
|
-
*
|
|
285
|
-
* Built for imports and ETL, where one call per row means one HTTP round
|
|
286
|
-
* trip and one transaction per row. Every record still runs the normal
|
|
287
|
-
* pipeline — callbacks, relations, row-level security — and the batch is
|
|
288
|
-
* all-or-nothing: if any record is rejected, none of them land and the
|
|
289
|
-
* error names the offending index.
|
|
290
|
-
*
|
|
291
|
-
* A record carrying its primary key updates that row; one without inserts.
|
|
292
|
-
* With `{ upsert: true }` each record is written as INSERT ... ON CONFLICT
|
|
293
|
-
* DO UPDATE on the primary key instead, which is what makes a re-runnable
|
|
294
|
-
* import idempotent.
|
|
295
|
-
*
|
|
296
|
-
* Batches are capped server-side (1000 rows by default) because one batch
|
|
297
|
-
* holds its locks for the whole transaction — chunk larger jobs.
|
|
298
|
-
*
|
|
299
|
-
* @returns The written rows, in the order given.
|
|
300
|
-
*
|
|
301
|
-
* @example
|
|
302
|
-
* ```ts
|
|
303
|
-
* for (const chunk of chunks(rows, 1000)) {
|
|
304
|
-
* await client.data.products.createMany(chunk, { upsert: true });
|
|
305
|
-
* }
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
createMany(data: I[], options?: {
|
|
309
|
-
upsert?: boolean;
|
|
310
|
-
}): Promise<M[]>;
|
|
311
269
|
/**
|
|
312
270
|
* Update an existing record by ID.
|
|
313
271
|
* @param data The fields to update (the collection's `Update` shape).
|
|
@@ -387,7 +345,7 @@ export type RebaseData<DB = unknown> = {
|
|
|
387
345
|
* - The frontend SDK client (`client.data.products.find()`)
|
|
388
346
|
* - Backend framework callbacks & scripts (`context.data.products.find()`)
|
|
389
347
|
*
|
|
390
|
-
* Every accessor returns flat rows (
|
|
348
|
+
* Every accessor returns flat rows (`{ id, ...columns }`) via
|
|
391
349
|
* {@link SDKCollectionClient} — access fields directly (`row.title`), never
|
|
392
350
|
* `row.values.title`. The admin CMS uses {@link RebaseData} (Entity) instead.
|
|
393
351
|
*
|
|
@@ -65,30 +65,6 @@ export interface SaveProps<M extends Record<string, unknown> = Record<string, un
|
|
|
65
65
|
previousValues?: Partial<EntityValues<M>>;
|
|
66
66
|
collection?: CollectionConfig<M>;
|
|
67
67
|
status: EntityStatus;
|
|
68
|
-
/**
|
|
69
|
-
* Write the row with INSERT ... ON CONFLICT DO UPDATE on the primary key
|
|
70
|
-
* instead of choosing between insert and update up front.
|
|
71
|
-
*
|
|
72
|
-
* One statement, so it does not lose the race a read-then-write can, and it
|
|
73
|
-
* succeeds whether or not the row is already there — what a re-runnable
|
|
74
|
-
* import needs. Requires every primary key column to be present; without
|
|
75
|
-
* them there is no conflict target and the row is inserted normally.
|
|
76
|
-
*/
|
|
77
|
-
upsert?: boolean;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
export interface SaveManyProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
83
|
-
path: string;
|
|
84
|
-
/**
|
|
85
|
-
* The rows to write. A row carrying its primary key updates (or, with
|
|
86
|
-
* `upsert`, inserts-or-updates) that row; one without inserts.
|
|
87
|
-
*/
|
|
88
|
-
rows: Partial<EntityValues<M>>[];
|
|
89
|
-
collection?: CollectionConfig<M>;
|
|
90
|
-
/** Apply every row as INSERT ... ON CONFLICT DO UPDATE. See {@link SaveProps.upsert}. */
|
|
91
|
-
upsert?: boolean;
|
|
92
68
|
}
|
|
93
69
|
/**
|
|
94
70
|
* @internal
|
|
@@ -159,19 +135,6 @@ export interface DataDriver {
|
|
|
159
135
|
* @param props
|
|
160
136
|
*/
|
|
161
137
|
save<M extends Record<string, unknown> = Record<string, unknown>>(props: SaveProps<M>): Promise<Record<string, unknown>>;
|
|
162
|
-
/**
|
|
163
|
-
* Save many rows as one unit of work.
|
|
164
|
-
*
|
|
165
|
-
* Every row runs the same pipeline as {@link save} — callbacks, relations
|
|
166
|
-
* and row-level security all still apply — but they share a single
|
|
167
|
-
* transaction, so the batch either lands whole or not at all. That, and the
|
|
168
|
-
* single round trip, is what makes importing tens of thousands of rows
|
|
169
|
-
* viable without dropping to raw SQL.
|
|
170
|
-
*
|
|
171
|
-
* Optional: drivers that cannot do this leave it undefined and callers fall
|
|
172
|
-
* back to `save` per row.
|
|
173
|
-
*/
|
|
174
|
-
saveMany?<M extends Record<string, unknown> = Record<string, unknown>>(props: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
|
|
175
138
|
/**
|
|
176
139
|
* Delete a entity
|
|
177
140
|
* @param props
|
|
@@ -240,14 +203,9 @@ export interface DataDriver {
|
|
|
240
203
|
* REST-optimised fetch service exposed by drivers that support
|
|
241
204
|
* eager-loading of relations via `include`.
|
|
242
205
|
*
|
|
243
|
-
* The methods return flattened rows
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* through the REST API / SDK client.
|
|
247
|
-
*
|
|
248
|
-
* No synthesized `id`: identity is a primary key, which may be named anything
|
|
249
|
-
* and span several columns, so an address is derived by whoever needs one (see
|
|
250
|
-
* `buildCompositeId`) rather than written into the row on top of the data.
|
|
206
|
+
* The methods return flattened rows (`{ id, ...columns }`) with
|
|
207
|
+
* included relations inlined as plain nested rows — the shape served
|
|
208
|
+
* to app developers through the REST API / SDK client.
|
|
251
209
|
*
|
|
252
210
|
* @group DataDriver
|
|
253
211
|
*/
|
|
@@ -74,7 +74,7 @@ export interface AfterReadProps<M extends Record<string, unknown> = Record<strin
|
|
|
74
74
|
*/
|
|
75
75
|
path: string;
|
|
76
76
|
/**
|
|
77
|
-
* Fetched row (flat —
|
|
77
|
+
* Fetched row (flat — `{ id, ...columns }`)
|
|
78
78
|
*/
|
|
79
79
|
row: Record<string, unknown>;
|
|
80
80
|
/**
|
|
@@ -149,7 +149,7 @@ export interface BeforeDeleteProps<M extends Record<string, unknown> = Record<st
|
|
|
149
149
|
*/
|
|
150
150
|
id: string | number;
|
|
151
151
|
/**
|
|
152
|
-
* Deleted row (flat —
|
|
152
|
+
* Deleted row (flat — `{ id, ...columns }`)
|
|
153
153
|
*/
|
|
154
154
|
row: Record<string, unknown>;
|
|
155
155
|
/**
|
|
@@ -175,7 +175,7 @@ export interface AfterDeleteProps<M extends Record<string, unknown> = Record<str
|
|
|
175
175
|
*/
|
|
176
176
|
id: string | number;
|
|
177
177
|
/**
|
|
178
|
-
* Deleted row (flat —
|
|
178
|
+
* Deleted row (flat — `{ id, ...columns }`)
|
|
179
179
|
*/
|
|
180
180
|
row: Record<string, unknown>;
|
|
181
181
|
/**
|
|
@@ -15,34 +15,10 @@ export interface WebSocketMessage {
|
|
|
15
15
|
row?: Record<string, unknown> | null;
|
|
16
16
|
error?: string;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* The key columns a collection's rows are addressed by.
|
|
20
|
-
*
|
|
21
|
-
* A row is exactly its columns and carries no address, so a subscriber that has
|
|
22
|
-
* to recognise one — to patch it, or to keep its reference across a refetch —
|
|
23
|
-
* derives the address from these. The SDK is usable with no collections
|
|
24
|
-
* declared at all, so the server is the only side that knows them.
|
|
25
|
-
*
|
|
26
|
-
* Undefined when the server cannot resolve them: a table with no primary key
|
|
27
|
-
* and no `id` column has no address, and rows of it cannot be recognised by
|
|
28
|
-
* anyone.
|
|
29
|
-
*/
|
|
30
|
-
export type WirePrimaryKeys = {
|
|
31
|
-
fieldName: string;
|
|
32
|
-
type: "string" | "number";
|
|
33
|
-
isUUID?: boolean;
|
|
34
|
-
}[];
|
|
35
18
|
export interface CollectionUpdateMessage extends WebSocketMessage {
|
|
36
19
|
type: "collection_update";
|
|
37
20
|
subscriptionId: string;
|
|
38
21
|
rows: Record<string, unknown>[];
|
|
39
|
-
/**
|
|
40
|
-
* See {@link WirePrimaryKeys}. Sent with the rows themselves — and not only
|
|
41
|
-
* with a patch — because a CDC-originated change sends no patch at all: it
|
|
42
|
-
* invalidates and goes straight to a refetch, and the merge that preserves
|
|
43
|
-
* unchanged rows' references needs an address to match them by.
|
|
44
|
-
*/
|
|
45
|
-
pks?: WirePrimaryKeys;
|
|
46
22
|
}
|
|
47
23
|
export interface SingleUpdateMessage extends WebSocketMessage {
|
|
48
24
|
type: "single_update";
|
|
@@ -58,12 +34,9 @@ export interface SingleUpdateMessage extends WebSocketMessage {
|
|
|
58
34
|
export interface CollectionPatchMessage extends WebSocketMessage {
|
|
59
35
|
type: "collection_patch";
|
|
60
36
|
subscriptionId: string;
|
|
61
|
-
/** The address of the row this patch refers to — derived, never read off it. */
|
|
62
37
|
id: string;
|
|
63
38
|
/** The updated row, or null if deleted */
|
|
64
39
|
row: Record<string, unknown> | null;
|
|
65
|
-
/** See {@link WirePrimaryKeys}: how the subscriber finds {@link id} in its cache. */
|
|
66
|
-
pks?: WirePrimaryKeys;
|
|
67
40
|
}
|
|
68
41
|
/**
|
|
69
42
|
* Column metadata returned by table introspection.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/types",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.1-canary.
|
|
4
|
+
"version": "0.9.1-canary.73476f2",
|
|
5
5
|
"description": "Rebase type definitions — shared interfaces and controller types",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"scripts": {
|
|
93
93
|
"watch": "vite build --watch",
|
|
94
|
-
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json
|
|
94
|
+
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
95
95
|
"test:lint": "eslint \"src/**\" --quiet",
|
|
96
96
|
"test": "jest --passWithNoTests",
|
|
97
97
|
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
package/src/controllers/data.ts
CHANGED
|
@@ -161,14 +161,6 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
161
161
|
*/
|
|
162
162
|
create(data: Partial<EntityValues<M>>, id?: string | number): Promise<Entity<M>>;
|
|
163
163
|
|
|
164
|
-
/**
|
|
165
|
-
* Create many records in a single transaction.
|
|
166
|
-
*
|
|
167
|
-
* See {@link SDKCollectionClient.createMany}. Optional: not every driver can
|
|
168
|
-
* write in bulk, and callers should fall back to `create` per record.
|
|
169
|
-
*/
|
|
170
|
-
createMany?(data: Partial<EntityValues<M>>[], options?: { upsert?: boolean }): Promise<Entity<M>[]>;
|
|
171
|
-
|
|
172
164
|
/**
|
|
173
165
|
* Update an existing record by ID.
|
|
174
166
|
* @returns The updated entity
|
|
@@ -302,43 +294,11 @@ export interface SDKCollectionClient<
|
|
|
302
294
|
/**
|
|
303
295
|
* Create a new record.
|
|
304
296
|
* @param data The record data to create (the collection's `Insert` shape).
|
|
305
|
-
* @param id Optional specific
|
|
306
|
-
* whose key *is* `id`: the value goes in as that column. For a table keyed
|
|
307
|
-
* on anything else (a `sku`, a composite key), there is no `id` column to
|
|
308
|
-
* receive it — put the key in `data` instead, where it belongs among the
|
|
309
|
-
* columns.
|
|
297
|
+
* @param id Optional specific ID to use for the new record.
|
|
310
298
|
* @returns The created row
|
|
311
299
|
*/
|
|
312
300
|
create(data: I, id?: string | number): Promise<M>;
|
|
313
301
|
|
|
314
|
-
/**
|
|
315
|
-
* Write many records in a single request and a single transaction.
|
|
316
|
-
*
|
|
317
|
-
* Built for imports and ETL, where one call per row means one HTTP round
|
|
318
|
-
* trip and one transaction per row. Every record still runs the normal
|
|
319
|
-
* pipeline — callbacks, relations, row-level security — and the batch is
|
|
320
|
-
* all-or-nothing: if any record is rejected, none of them land and the
|
|
321
|
-
* error names the offending index.
|
|
322
|
-
*
|
|
323
|
-
* A record carrying its primary key updates that row; one without inserts.
|
|
324
|
-
* With `{ upsert: true }` each record is written as INSERT ... ON CONFLICT
|
|
325
|
-
* DO UPDATE on the primary key instead, which is what makes a re-runnable
|
|
326
|
-
* import idempotent.
|
|
327
|
-
*
|
|
328
|
-
* Batches are capped server-side (1000 rows by default) because one batch
|
|
329
|
-
* holds its locks for the whole transaction — chunk larger jobs.
|
|
330
|
-
*
|
|
331
|
-
* @returns The written rows, in the order given.
|
|
332
|
-
*
|
|
333
|
-
* @example
|
|
334
|
-
* ```ts
|
|
335
|
-
* for (const chunk of chunks(rows, 1000)) {
|
|
336
|
-
* await client.data.products.createMany(chunk, { upsert: true });
|
|
337
|
-
* }
|
|
338
|
-
* ```
|
|
339
|
-
*/
|
|
340
|
-
createMany(data: I[], options?: { upsert?: boolean }): Promise<M[]>;
|
|
341
|
-
|
|
342
302
|
/**
|
|
343
303
|
* Update an existing record by ID.
|
|
344
304
|
* @param data The fields to update (the collection's `Update` shape).
|
|
@@ -426,7 +386,7 @@ export type RebaseData<DB = unknown> = {
|
|
|
426
386
|
* - The frontend SDK client (`client.data.products.find()`)
|
|
427
387
|
* - Backend framework callbacks & scripts (`context.data.products.find()`)
|
|
428
388
|
*
|
|
429
|
-
* Every accessor returns flat rows (
|
|
389
|
+
* Every accessor returns flat rows (`{ id, ...columns }`) via
|
|
430
390
|
* {@link SDKCollectionClient} — access fields directly (`row.title`), never
|
|
431
391
|
* `row.values.title`. The admin CMS uses {@link RebaseData} (Entity) instead.
|
|
432
392
|
*
|
|
@@ -77,31 +77,6 @@ export interface SaveProps<M extends Record<string, unknown> = Record<string, un
|
|
|
77
77
|
previousValues?: Partial<EntityValues<M>>;
|
|
78
78
|
collection?: CollectionConfig<M>;
|
|
79
79
|
status: EntityStatus;
|
|
80
|
-
/**
|
|
81
|
-
* Write the row with INSERT ... ON CONFLICT DO UPDATE on the primary key
|
|
82
|
-
* instead of choosing between insert and update up front.
|
|
83
|
-
*
|
|
84
|
-
* One statement, so it does not lose the race a read-then-write can, and it
|
|
85
|
-
* succeeds whether or not the row is already there — what a re-runnable
|
|
86
|
-
* import needs. Requires every primary key column to be present; without
|
|
87
|
-
* them there is no conflict target and the row is inserted normally.
|
|
88
|
-
*/
|
|
89
|
-
upsert?: boolean;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @internal
|
|
94
|
-
*/
|
|
95
|
-
export interface SaveManyProps<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
96
|
-
path: string;
|
|
97
|
-
/**
|
|
98
|
-
* The rows to write. A row carrying its primary key updates (or, with
|
|
99
|
-
* `upsert`, inserts-or-updates) that row; one without inserts.
|
|
100
|
-
*/
|
|
101
|
-
rows: Partial<EntityValues<M>>[];
|
|
102
|
-
collection?: CollectionConfig<M>;
|
|
103
|
-
/** Apply every row as INSERT ... ON CONFLICT DO UPDATE. See {@link SaveProps.upsert}. */
|
|
104
|
-
upsert?: boolean;
|
|
105
80
|
}
|
|
106
81
|
|
|
107
82
|
/**
|
|
@@ -179,20 +154,6 @@ export interface DataDriver {
|
|
|
179
154
|
*/
|
|
180
155
|
save<M extends Record<string, unknown> = Record<string, unknown>>(props: SaveProps<M>): Promise<Record<string, unknown>>;
|
|
181
156
|
|
|
182
|
-
/**
|
|
183
|
-
* Save many rows as one unit of work.
|
|
184
|
-
*
|
|
185
|
-
* Every row runs the same pipeline as {@link save} — callbacks, relations
|
|
186
|
-
* and row-level security all still apply — but they share a single
|
|
187
|
-
* transaction, so the batch either lands whole or not at all. That, and the
|
|
188
|
-
* single round trip, is what makes importing tens of thousands of rows
|
|
189
|
-
* viable without dropping to raw SQL.
|
|
190
|
-
*
|
|
191
|
-
* Optional: drivers that cannot do this leave it undefined and callers fall
|
|
192
|
-
* back to `save` per row.
|
|
193
|
-
*/
|
|
194
|
-
saveMany?<M extends Record<string, unknown> = Record<string, unknown>>(props: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
|
|
195
|
-
|
|
196
157
|
/**
|
|
197
158
|
* Delete a entity
|
|
198
159
|
* @param props
|
|
@@ -291,14 +252,9 @@ export interface DataDriver {
|
|
|
291
252
|
* REST-optimised fetch service exposed by drivers that support
|
|
292
253
|
* eager-loading of relations via `include`.
|
|
293
254
|
*
|
|
294
|
-
* The methods return flattened rows
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* through the REST API / SDK client.
|
|
298
|
-
*
|
|
299
|
-
* No synthesized `id`: identity is a primary key, which may be named anything
|
|
300
|
-
* and span several columns, so an address is derived by whoever needs one (see
|
|
301
|
-
* `buildCompositeId`) rather than written into the row on top of the data.
|
|
255
|
+
* The methods return flattened rows (`{ id, ...columns }`) with
|
|
256
|
+
* included relations inlined as plain nested rows — the shape served
|
|
257
|
+
* to app developers through the REST API / SDK client.
|
|
302
258
|
*
|
|
303
259
|
* @group DataDriver
|
|
304
260
|
*/
|
|
@@ -91,7 +91,7 @@ export interface AfterReadProps<M extends Record<string, unknown> = Record<strin
|
|
|
91
91
|
path: string;
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* Fetched row (flat —
|
|
94
|
+
* Fetched row (flat — `{ id, ...columns }`)
|
|
95
95
|
*/
|
|
96
96
|
row: Record<string, unknown>
|
|
97
97
|
|
|
@@ -185,7 +185,7 @@ export interface BeforeDeleteProps<M extends Record<string, unknown> = Record<st
|
|
|
185
185
|
id: string | number;
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
* Deleted row (flat —
|
|
188
|
+
* Deleted row (flat — `{ id, ...columns }`)
|
|
189
189
|
*/
|
|
190
190
|
row: Record<string, unknown>;
|
|
191
191
|
|
|
@@ -217,7 +217,7 @@ export interface AfterDeleteProps<M extends Record<string, unknown> = Record<str
|
|
|
217
217
|
id: string | number;
|
|
218
218
|
|
|
219
219
|
/**
|
|
220
|
-
* Deleted row (flat —
|
|
220
|
+
* Deleted row (flat — `{ id, ...columns }`)
|
|
221
221
|
*/
|
|
222
222
|
row: Record<string, unknown>;
|
|
223
223
|
|
package/src/types/websockets.ts
CHANGED
|
@@ -14,31 +14,10 @@ export interface WebSocketMessage {
|
|
|
14
14
|
error?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* The key columns a collection's rows are addressed by.
|
|
19
|
-
*
|
|
20
|
-
* A row is exactly its columns and carries no address, so a subscriber that has
|
|
21
|
-
* to recognise one — to patch it, or to keep its reference across a refetch —
|
|
22
|
-
* derives the address from these. The SDK is usable with no collections
|
|
23
|
-
* declared at all, so the server is the only side that knows them.
|
|
24
|
-
*
|
|
25
|
-
* Undefined when the server cannot resolve them: a table with no primary key
|
|
26
|
-
* and no `id` column has no address, and rows of it cannot be recognised by
|
|
27
|
-
* anyone.
|
|
28
|
-
*/
|
|
29
|
-
export type WirePrimaryKeys = { fieldName: string; type: "string" | "number"; isUUID?: boolean }[];
|
|
30
|
-
|
|
31
17
|
export interface CollectionUpdateMessage extends WebSocketMessage {
|
|
32
18
|
type: "collection_update";
|
|
33
19
|
subscriptionId: string;
|
|
34
20
|
rows: Record<string, unknown>[];
|
|
35
|
-
/**
|
|
36
|
-
* See {@link WirePrimaryKeys}. Sent with the rows themselves — and not only
|
|
37
|
-
* with a patch — because a CDC-originated change sends no patch at all: it
|
|
38
|
-
* invalidates and goes straight to a refetch, and the merge that preserves
|
|
39
|
-
* unchanged rows' references needs an address to match them by.
|
|
40
|
-
*/
|
|
41
|
-
pks?: WirePrimaryKeys;
|
|
42
21
|
}
|
|
43
22
|
|
|
44
23
|
export interface SingleUpdateMessage extends WebSocketMessage {
|
|
@@ -56,12 +35,9 @@ export interface SingleUpdateMessage extends WebSocketMessage {
|
|
|
56
35
|
export interface CollectionPatchMessage extends WebSocketMessage {
|
|
57
36
|
type: "collection_patch";
|
|
58
37
|
subscriptionId: string;
|
|
59
|
-
/** The address of the row this patch refers to — derived, never read off it. */
|
|
60
38
|
id: string;
|
|
61
39
|
/** The updated row, or null if deleted */
|
|
62
40
|
row: Record<string, unknown> | null;
|
|
63
|
-
/** See {@link WirePrimaryKeys}: how the subscriber finds {@link id} in its cache. */
|
|
64
|
-
pks?: WirePrimaryKeys;
|
|
65
41
|
}
|
|
66
42
|
|
|
67
43
|
/**
|