@typicalday/firegraph 0.11.2 → 0.13.0
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 +355 -78
- package/dist/backend-DuvHGgK1.d.cts +1897 -0
- package/dist/backend-DuvHGgK1.d.ts +1897 -0
- package/dist/backend.cjs +365 -5
- package/dist/backend.cjs.map +1 -1
- package/dist/backend.d.cts +25 -5
- package/dist/backend.d.ts +25 -5
- package/dist/backend.js +209 -7
- package/dist/backend.js.map +1 -1
- package/dist/chunk-2DHMNTV6.js +16 -0
- package/dist/chunk-2DHMNTV6.js.map +1 -0
- package/dist/chunk-4MMQ5W74.js +288 -0
- package/dist/chunk-4MMQ5W74.js.map +1 -0
- package/dist/{chunk-5753Y42M.js → chunk-C2QMD7RY.js} +6 -10
- package/dist/chunk-C2QMD7RY.js.map +1 -0
- package/dist/chunk-D4J7Z4FE.js +67 -0
- package/dist/chunk-D4J7Z4FE.js.map +1 -0
- package/dist/chunk-EQJUUVFG.js +14 -0
- package/dist/chunk-EQJUUVFG.js.map +1 -0
- package/dist/chunk-N5HFDWQX.js +23 -0
- package/dist/chunk-N5HFDWQX.js.map +1 -0
- package/dist/chunk-PAD7WFFU.js +573 -0
- package/dist/chunk-PAD7WFFU.js.map +1 -0
- package/dist/chunk-TK64DNVK.js +256 -0
- package/dist/chunk-TK64DNVK.js.map +1 -0
- package/dist/{chunk-NJSOD64C.js → chunk-WRTFC5NG.js} +438 -30
- package/dist/chunk-WRTFC5NG.js.map +1 -0
- package/dist/client-BKi3vk0Q.d.ts +34 -0
- package/dist/client-BrsaXtDV.d.cts +34 -0
- package/dist/cloudflare/index.cjs +1386 -74
- package/dist/cloudflare/index.cjs.map +1 -1
- package/dist/cloudflare/index.d.cts +217 -13
- package/dist/cloudflare/index.d.ts +217 -13
- package/dist/cloudflare/index.js +639 -180
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/codegen/index.d.cts +1 -1
- package/dist/codegen/index.d.ts +1 -1
- package/dist/errors-BRc3I_eH.d.cts +73 -0
- package/dist/errors-BRc3I_eH.d.ts +73 -0
- package/dist/firestore-enterprise/index.cjs +3877 -0
- package/dist/firestore-enterprise/index.cjs.map +1 -0
- package/dist/firestore-enterprise/index.d.cts +141 -0
- package/dist/firestore-enterprise/index.d.ts +141 -0
- package/dist/firestore-enterprise/index.js +985 -0
- package/dist/firestore-enterprise/index.js.map +1 -0
- package/dist/firestore-standard/index.cjs +3117 -0
- package/dist/firestore-standard/index.cjs.map +1 -0
- package/dist/firestore-standard/index.d.cts +49 -0
- package/dist/firestore-standard/index.d.ts +49 -0
- package/dist/firestore-standard/index.js +283 -0
- package/dist/firestore-standard/index.js.map +1 -0
- package/dist/index.cjs +809 -534
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -100
- package/dist/index.d.ts +24 -100
- package/dist/index.js +184 -531
- package/dist/index.js.map +1 -1
- package/dist/registry-Bc7h6WTM.d.cts +64 -0
- package/dist/registry-C2KUPVZj.d.ts +64 -0
- package/dist/{scope-path-B1G3YiA7.d.ts → scope-path-CROFZGr9.d.cts} +1 -56
- package/dist/{scope-path-B1G3YiA7.d.cts → scope-path-CROFZGr9.d.ts} +1 -56
- package/dist/{serialization-ZZ7RSDRX.js → serialization-OE2PFZMY.js} +6 -4
- package/dist/sqlite/index.cjs +3631 -0
- package/dist/sqlite/index.cjs.map +1 -0
- package/dist/sqlite/index.d.cts +111 -0
- package/dist/sqlite/index.d.ts +111 -0
- package/dist/sqlite/index.js +1164 -0
- package/dist/sqlite/index.js.map +1 -0
- package/package.json +33 -3
- package/dist/backend-U-MLShlg.d.ts +0 -97
- package/dist/backend-np4gEVhB.d.cts +0 -97
- package/dist/chunk-5753Y42M.js.map +0 -1
- package/dist/chunk-NJSOD64C.js.map +0 -1
- package/dist/chunk-R7CRGYY4.js +0 -94
- package/dist/chunk-R7CRGYY4.js.map +0 -1
- package/dist/types-BGWxcpI_.d.cts +0 -736
- package/dist/types-BGWxcpI_.d.ts +0 -736
- /package/dist/{serialization-ZZ7RSDRX.js.map → serialization-OE2PFZMY.js.map} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { W as WritableRecord, U as UpdatePayload, S as StorageBackend, T as TransactionBackend,
|
|
2
|
-
|
|
1
|
+
import { W as WritableRecord, f as WriteMode, U as UpdatePayload, G as GraphRegistry, I as IndexSpec, p as QueryFilter, ai as QueryOptions, z as AggregateSpec, O as CascadeResult, F as FindEdgesParams, H as BulkOptions, L as BulkResult, b as BulkUpdatePatch, E as ExpandParams, S as StorageBackend, B as BackendCapabilities, t as GraphClient, Z as DynamicGraphClient, m as StoredGraphRecord, T as TransactionBackend, a as BatchBackend, u as GraphReader, e as ExpandResult, a8 as GraphClientOptions, $ as DynamicRegistryConfig } from '../backend-DuvHGgK1.cjs';
|
|
2
|
+
export { A as AggregateExtension, w as AggregateField, x as AggregateOp, y as AggregateResult, N as Capability, d as DmlExtension, J as JoinExtension, g as createCapabilities, h as deleteField, j as intersectCapabilities } from '../backend-DuvHGgK1.cjs';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
+
export { M as META_EDGE_TYPE, a as META_NODE_TYPE, b as createMergedRegistry, d as createRegistry, f as generateId } from '../registry-Bc7h6WTM.cjs';
|
|
5
|
+
export { C as CapabilityNotSupportedError } from '../errors-BRc3I_eH.cjs';
|
|
4
6
|
import '@google-cloud/firestore';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -40,6 +42,30 @@ interface DORecordWire {
|
|
|
40
42
|
createdAtMs: number;
|
|
41
43
|
updatedAtMs: number;
|
|
42
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Discriminator for one projected column on the DO backend. The decoder
|
|
47
|
+
* uses this to recover the JS-shape of the requested field. Mirrors the
|
|
48
|
+
* shared-SQLite `ProjectedColumnKind` — same kinds, same decode rules. The
|
|
49
|
+
* two share no module so the symbol is duplicated; the contract is locked
|
|
50
|
+
* by the cross-backend test in `tests/unit/cloudflare-sql.test.ts`.
|
|
51
|
+
*/
|
|
52
|
+
type DOProjectedColumnKind = 'builtin-text' | 'builtin-int' | 'builtin-timestamp' | 'data' | 'json';
|
|
53
|
+
/** Per-column metadata returned alongside the compiled projection statement. */
|
|
54
|
+
interface DOProjectedColumnSpec {
|
|
55
|
+
/** Original caller-supplied field name. Used as the alias in the SQL
|
|
56
|
+
* projection list AND as the key in the returned JS row. */
|
|
57
|
+
field: string;
|
|
58
|
+
/** Kind discriminator — see `DOProjectedColumnKind`. */
|
|
59
|
+
kind: DOProjectedColumnKind;
|
|
60
|
+
/**
|
|
61
|
+
* For `kind === 'json'` only: alias of the paired `json_type` companion
|
|
62
|
+
* column. Uses a positional sentinel (`__fg_t_<idx>`) keyed by the
|
|
63
|
+
* field's position in the unique projection list rather than the
|
|
64
|
+
* historical `<field>__t` suffix, which would collide if the caller
|
|
65
|
+
* projected both `'foo'` and `'foo__t'` (both legal user input).
|
|
66
|
+
*/
|
|
67
|
+
typeAlias?: string;
|
|
68
|
+
}
|
|
43
69
|
|
|
44
70
|
/**
|
|
45
71
|
* `FiregraphDO` — the Durable Object class that holds a single subgraph's
|
|
@@ -124,6 +150,7 @@ type BatchOp = {
|
|
|
124
150
|
kind: 'set';
|
|
125
151
|
docId: string;
|
|
126
152
|
record: WritableRecord;
|
|
153
|
+
mode: WriteMode;
|
|
127
154
|
} | {
|
|
128
155
|
kind: 'update';
|
|
129
156
|
docId: string;
|
|
@@ -185,7 +212,15 @@ declare class FiregraphDO extends DurableObject<unknown> {
|
|
|
185
212
|
constructor(ctx: DurableObjectStateLike, env: unknown, options?: FiregraphDOOptions);
|
|
186
213
|
_fgGetDoc(docId: string): Promise<DORecordWire | null>;
|
|
187
214
|
_fgQuery(filters: QueryFilter[], options?: QueryOptions): Promise<DORecordWire[]>;
|
|
188
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Aggregate query (capability `query.aggregate`). Compiles a single
|
|
217
|
+
* `SELECT` projecting one column per alias; SQLite handles count, sum,
|
|
218
|
+
* avg, min, max natively. Empty-set fix-ups (NULL → 0 for sum/min/max,
|
|
219
|
+
* NaN for avg) happen on the client side in `DORPCBackend.aggregate` so
|
|
220
|
+
* the wire payload stays a plain row of (alias → number | null).
|
|
221
|
+
*/
|
|
222
|
+
_fgAggregate(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number | null>>;
|
|
223
|
+
_fgSetDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
189
224
|
_fgUpdateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
190
225
|
_fgDeleteDoc(docId: string): Promise<void>;
|
|
191
226
|
/**
|
|
@@ -197,6 +232,21 @@ declare class FiregraphDO extends DurableObject<unknown> {
|
|
|
197
232
|
_fgBatch(ops: BatchOp[]): Promise<void>;
|
|
198
233
|
_fgRemoveNodeCascade(uid: string): Promise<CascadeResult>;
|
|
199
234
|
_fgBulkRemoveEdges(params: FindEdgesParams, _options?: BulkOptions): Promise<BulkResult>;
|
|
235
|
+
_fgBulkDelete(filters: QueryFilter[], _options?: BulkOptions): Promise<BulkResult>;
|
|
236
|
+
_fgBulkUpdate(filters: QueryFilter[], patch: BulkUpdatePatch, _options?: BulkOptions): Promise<BulkResult>;
|
|
237
|
+
_fgExpand(params: ExpandParams): Promise<ExpandResultWire>;
|
|
238
|
+
_fgFindEdgesProjected(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<{
|
|
239
|
+
rows: Array<Record<string, unknown>>;
|
|
240
|
+
columns: DOProjectedColumnSpec[];
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Run a DML statement with `RETURNING "doc_id"` so the affected-row count
|
|
244
|
+
* comes back authoritatively. Errors are caught and surfaced via the
|
|
245
|
+
* `BulkResult.errors` array (single batch, batchIndex 0) so the wire
|
|
246
|
+
* payload stays a regular `BulkResult` and the client doesn't have to
|
|
247
|
+
* differentiate "RPC threw" from "single-statement failure."
|
|
248
|
+
*/
|
|
249
|
+
private execDmlWithReturning;
|
|
200
250
|
/**
|
|
201
251
|
* Wipe every row. Called by the client when tearing down a subgraph DO as
|
|
202
252
|
* part of cascade — the DO itself can't be destroyed (DO IDs persist
|
|
@@ -257,14 +307,80 @@ interface DurableObjectIdLike {
|
|
|
257
307
|
interface FiregraphStub {
|
|
258
308
|
_fgGetDoc(docId: string): Promise<DORecordWire | null>;
|
|
259
309
|
_fgQuery(filters: QueryFilter[], options?: QueryOptions): Promise<DORecordWire[]>;
|
|
260
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Optional — added in Phase 4 (`query.aggregate`). Marked optional so
|
|
312
|
+
* external worker code that hand-rolls a stub wrapper around a real DO
|
|
313
|
+
* stub (e.g. for testing or for layering structured-clone shims) keeps
|
|
314
|
+
* compiling without modification. `FiregraphDO` always implements this
|
|
315
|
+
* method, but callers of `DORPCBackend.aggregate` must either assert the
|
|
316
|
+
* stub supports it or be prepared for `UNSUPPORTED_OPERATION` at runtime.
|
|
317
|
+
*/
|
|
318
|
+
_fgAggregate?(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number | null>>;
|
|
319
|
+
_fgSetDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
261
320
|
_fgUpdateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
262
321
|
_fgDeleteDoc(docId: string): Promise<void>;
|
|
263
322
|
_fgBatch(ops: BatchOp[]): Promise<void>;
|
|
264
323
|
_fgRemoveNodeCascade(uid: string): Promise<CascadeResult>;
|
|
265
324
|
_fgBulkRemoveEdges(params: FindEdgesParams, options?: BulkOptions): Promise<BulkResult>;
|
|
325
|
+
/**
|
|
326
|
+
* Optional — added in Phase 5 (`query.dml`). Same back-compat rationale as
|
|
327
|
+
* `_fgAggregate`: external worker code that hand-rolls a stub wrapper keeps
|
|
328
|
+
* compiling without modification. `FiregraphDO` always implements this
|
|
329
|
+
* method; callers of `DORPCBackend.bulkDelete` either assert support or
|
|
330
|
+
* accept `UNSUPPORTED_OPERATION` at runtime.
|
|
331
|
+
*/
|
|
332
|
+
_fgBulkDelete?(filters: QueryFilter[], options?: BulkOptions): Promise<BulkResult>;
|
|
333
|
+
/**
|
|
334
|
+
* Optional — added in Phase 5 (`query.dml`). See `_fgBulkDelete`.
|
|
335
|
+
*/
|
|
336
|
+
_fgBulkUpdate?(filters: QueryFilter[], patch: BulkUpdatePatch, options?: BulkOptions): Promise<BulkResult>;
|
|
337
|
+
/**
|
|
338
|
+
* Optional — added in Phase 6 (`query.join`). Same back-compat rationale as
|
|
339
|
+
* `_fgAggregate` / `_fgBulkDelete`: external worker code that hand-rolls a
|
|
340
|
+
* stub wrapper keeps compiling without modification. `FiregraphDO` always
|
|
341
|
+
* implements this method; callers of `DORPCBackend.expand` either assert
|
|
342
|
+
* the stub supports it or accept `UNSUPPORTED_OPERATION` at runtime.
|
|
343
|
+
*
|
|
344
|
+
* The wire shape uses `ExpandResultWire` so `StoredGraphRecord` instances
|
|
345
|
+
* (which carry `Timestamp` wrappers) survive the structured-clone hop —
|
|
346
|
+
* they're rehydrated on this side via `hydrateDORecord`, just like the
|
|
347
|
+
* `query()` and `_fgBulkRemoveEdges` paths.
|
|
348
|
+
*/
|
|
349
|
+
_fgExpand?(params: ExpandParams): Promise<ExpandResultWire>;
|
|
350
|
+
/**
|
|
351
|
+
* Optional — added in Phase 7 (`query.select`). Same back-compat rationale
|
|
352
|
+
* as `_fgAggregate` / `_fgBulkDelete` / `_fgExpand`: external worker code
|
|
353
|
+
* that hand-rolls a stub wrapper keeps compiling without modification.
|
|
354
|
+
* `FiregraphDO` always implements this method; callers of
|
|
355
|
+
* `DORPCBackend.findEdgesProjected` either assert the stub supports it or
|
|
356
|
+
* accept `UNSUPPORTED_OPERATION` at runtime.
|
|
357
|
+
*
|
|
358
|
+
* The wire shape returns `{ rows, columns }` — raw row objects from the
|
|
359
|
+
* SQLite executor plus the per-column metadata produced by
|
|
360
|
+
* `compileDOFindEdgesProjected`. Decoding (BigInt → number, timestamp
|
|
361
|
+
* rehydration, paired `__t` resolution for `data.*` paths) happens on
|
|
362
|
+
* the client side via `decodeDOProjectedRow`. We deliberately do NOT
|
|
363
|
+
* decode inside the DO because `GraphTimestampImpl` instances do not
|
|
364
|
+
* survive workerd's structured-clone boundary as class instances —
|
|
365
|
+
* decoding must happen on the side that owns the prototype.
|
|
366
|
+
*/
|
|
367
|
+
_fgFindEdgesProjected?(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<{
|
|
368
|
+
rows: Array<Record<string, unknown>>;
|
|
369
|
+
columns: DOProjectedColumnSpec[];
|
|
370
|
+
}>;
|
|
266
371
|
_fgDestroy(): Promise<void>;
|
|
267
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Wire shape for `_fgExpand`. The DO returns rows as `DORecordWire` (the
|
|
375
|
+
* SQLite row layout) and the backend re-hydrates them on this side, so
|
|
376
|
+
* `Timestamp` wrappers are reconstructed locally and never round-trip
|
|
377
|
+
* through workerd's structured-clone boundary as plain objects.
|
|
378
|
+
*/
|
|
379
|
+
interface ExpandResultWire {
|
|
380
|
+
edges: DORecordWire[];
|
|
381
|
+
/** Aligned with `edges`; absent when the caller didn't request hydration. */
|
|
382
|
+
targets?: Array<DORecordWire | null>;
|
|
383
|
+
}
|
|
268
384
|
interface FiregraphNamespace {
|
|
269
385
|
idFromName(name: string): DurableObjectIdLike;
|
|
270
386
|
get(id: DurableObjectIdLike): FiregraphStub;
|
|
@@ -303,9 +419,26 @@ interface DORPCBackendOptions {
|
|
|
303
419
|
* own overload signatures.
|
|
304
420
|
* @internal
|
|
305
421
|
*/
|
|
306
|
-
makeSiblingClient?: (siblingStorageKey: string) => GraphClient | DynamicGraphClient
|
|
422
|
+
makeSiblingClient?: (siblingStorageKey: string) => GraphClient<CloudflareCapability> | DynamicGraphClient<CloudflareCapability>;
|
|
307
423
|
}
|
|
308
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Capability union declared by the DO RPC backend.
|
|
426
|
+
*
|
|
427
|
+
* Note the absence of `core.transactions`: `runTransaction` throws
|
|
428
|
+
* `UNSUPPORTED_OPERATION` because holding a synchronous SQLite transaction
|
|
429
|
+
* across async RPC calls would block the DO's single-threaded executor (see
|
|
430
|
+
* `transactionsUnsupported` above). `raw.sql` is also intentionally absent —
|
|
431
|
+
* the SQL surface lives inside the DO and isn't exposed across the RPC
|
|
432
|
+
* boundary.
|
|
433
|
+
*
|
|
434
|
+
* Conservative declaration matters: the type-level capability gate (Phase 3)
|
|
435
|
+
* relies on the union and the runtime cap-set agreeing. Adding a cap here
|
|
436
|
+
* without a corresponding runtime method would let callers reach a method
|
|
437
|
+
* that doesn't exist.
|
|
438
|
+
*/
|
|
439
|
+
type CloudflareCapability = 'core.read' | 'core.write' | 'core.batch' | 'core.subgraph' | 'query.aggregate' | 'query.dml' | 'query.join' | 'query.select';
|
|
440
|
+
declare class DORPCBackend implements StorageBackend<CloudflareCapability> {
|
|
441
|
+
readonly capabilities: BackendCapabilities<CloudflareCapability>;
|
|
309
442
|
readonly collectionPath = "firegraph";
|
|
310
443
|
readonly scopePath: string;
|
|
311
444
|
/** @internal */
|
|
@@ -314,13 +447,21 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
314
447
|
readonly namespace: FiregraphNamespace;
|
|
315
448
|
private readonly registryAccessor?;
|
|
316
449
|
/** @internal — see `DORPCBackendOptions.makeSiblingClient` for the union-type rationale. */
|
|
317
|
-
readonly makeSiblingClient?: (siblingStorageKey: string) => GraphClient | DynamicGraphClient
|
|
450
|
+
readonly makeSiblingClient?: (siblingStorageKey: string) => GraphClient<CloudflareCapability> | DynamicGraphClient<CloudflareCapability>;
|
|
318
451
|
private cachedStub;
|
|
319
452
|
constructor(namespace: FiregraphNamespace, options: DORPCBackendOptions);
|
|
320
453
|
private get stub();
|
|
321
454
|
getDoc(docId: string): Promise<StoredGraphRecord | null>;
|
|
322
455
|
query(filters: QueryFilter[], options?: QueryOptions): Promise<StoredGraphRecord[]>;
|
|
323
|
-
|
|
456
|
+
/**
|
|
457
|
+
* Run an aggregate query inside the backing DO. The DO returns a row of
|
|
458
|
+
* `{ alias: number | null }` (null = SQLite NULL for SUM/MIN/MAX over an
|
|
459
|
+
* empty set, or the count being literally 0); this method resolves NULL
|
|
460
|
+
* to 0 for SUM/MIN/MAX and to NaN for AVG, matching the SQLite backend
|
|
461
|
+
* and the Firestore Standard helper.
|
|
462
|
+
*/
|
|
463
|
+
aggregate(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number>>;
|
|
464
|
+
setDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
324
465
|
updateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
325
466
|
deleteDoc(docId: string): Promise<void>;
|
|
326
467
|
runTransaction<T>(_fn: (tx: TransactionBackend) => Promise<T>): Promise<T>;
|
|
@@ -328,6 +469,57 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
328
469
|
subgraph(parentNodeUid: string, name: string): StorageBackend;
|
|
329
470
|
removeNodeCascade(uid: string, reader: GraphReader, options?: BulkOptions): Promise<CascadeResult>;
|
|
330
471
|
bulkRemoveEdges(params: FindEdgesParams, _reader: GraphReader, options?: BulkOptions): Promise<BulkResult>;
|
|
472
|
+
/**
|
|
473
|
+
* Single-statement bulk DELETE inside the backing DO. The DO compiles
|
|
474
|
+
* the filter list to one `DELETE … WHERE …` statement and returns a
|
|
475
|
+
* `BulkResult` whose `deleted` is the affected-row count.
|
|
476
|
+
*
|
|
477
|
+
* Defensive `_fgBulkDelete` presence check mirrors `aggregate()`: the
|
|
478
|
+
* RPC method is optional on `FiregraphStub` so external worker code with
|
|
479
|
+
* a hand-rolled stub wrapper still type-checks. Surface a clear
|
|
480
|
+
* `UNSUPPORTED_OPERATION` rather than `TypeError: stub._fgBulkDelete is
|
|
481
|
+
* not a function` when the wrapper hasn't forwarded the method.
|
|
482
|
+
*/
|
|
483
|
+
bulkDelete(filters: QueryFilter[], options?: BulkOptions): Promise<BulkResult>;
|
|
484
|
+
/**
|
|
485
|
+
* Single-statement bulk UPDATE inside the backing DO. Same contract as
|
|
486
|
+
* `bulkDelete` for the missing-method case; the DO compiles the patch to
|
|
487
|
+
* one `UPDATE … SET data = json_patch(...) WHERE …` statement.
|
|
488
|
+
*/
|
|
489
|
+
bulkUpdate(filters: QueryFilter[], patch: BulkUpdatePatch, options?: BulkOptions): Promise<BulkResult>;
|
|
490
|
+
/**
|
|
491
|
+
* Multi-source fan-out — `query.join` capability. Routes the call through
|
|
492
|
+
* the DO's `_fgExpand` RPC, which compiles to one `SELECT … WHERE
|
|
493
|
+
* "aUid" IN (?, …)` statement (plus, when `params.hydrate === true`, a
|
|
494
|
+
* second IN-clause statement against the node rows).
|
|
495
|
+
*
|
|
496
|
+
* Defensive `_fgExpand` presence check matches the bulk-DML pattern: the
|
|
497
|
+
* RPC method is optional on `FiregraphStub` so external worker code with
|
|
498
|
+
* a hand-rolled stub wrapper still type-checks. We surface a clear
|
|
499
|
+
* `UNSUPPORTED_OPERATION` rather than `TypeError: stub._fgExpand is not a
|
|
500
|
+
* function` if the wrapper hasn't forwarded the method.
|
|
501
|
+
*/
|
|
502
|
+
expand(params: ExpandParams): Promise<ExpandResult>;
|
|
503
|
+
/**
|
|
504
|
+
* Server-side projection — `query.select` capability. Forwards the call to
|
|
505
|
+
* the DO's `_fgFindEdgesProjected` RPC, which compiles to a single
|
|
506
|
+
* `SELECT json_extract(...) AS …, json_type(...) AS …__t FROM <table>
|
|
507
|
+
* WHERE …` statement. The DO returns raw rows + per-column metadata; this
|
|
508
|
+
* method decodes each row locally via `decodeDOProjectedRow`.
|
|
509
|
+
*
|
|
510
|
+
* Decoding lives on this side (not inside the DO) because
|
|
511
|
+
* `GraphTimestampImpl` is a class — its prototype does not survive
|
|
512
|
+
* workerd's structured-clone boundary — so timestamp rehydration must
|
|
513
|
+
* happen wherever the rows are consumed by the GraphClient.
|
|
514
|
+
*
|
|
515
|
+
* Defensive `_fgFindEdgesProjected` presence check matches the `expand` /
|
|
516
|
+
* bulk-DML / aggregate pattern: the RPC method is optional on
|
|
517
|
+
* `FiregraphStub` so external worker code with a hand-rolled stub wrapper
|
|
518
|
+
* still type-checks. Surface a clear `UNSUPPORTED_OPERATION` rather than
|
|
519
|
+
* `TypeError: stub._fgFindEdgesProjected is not a function` if the
|
|
520
|
+
* wrapper hasn't forwarded the method.
|
|
521
|
+
*/
|
|
522
|
+
findEdgesProjected(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<Array<Record<string, unknown>>>;
|
|
331
523
|
/**
|
|
332
524
|
* Wipe this DO's storage. The DO itself can't be deleted — its ID
|
|
333
525
|
* persists forever — but its rows can be emptied, which is what the
|
|
@@ -440,6 +632,18 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
440
632
|
* ```
|
|
441
633
|
*/
|
|
442
634
|
|
|
635
|
+
/**
|
|
636
|
+
* The DO declares a strict subset of `Capability` (no `search.*`,
|
|
637
|
+
* `realtime.listen`, or `raw.*`). Local variables and helper closures
|
|
638
|
+
* that round-trip the client need to use the narrower form so that a
|
|
639
|
+
* `GraphClient<CloudflareCapability>` (which doesn't promise, e.g.,
|
|
640
|
+
* `findNearest`) is assignable. Using the unparameterized
|
|
641
|
+
* `GraphClient` here would require the DO to implement every
|
|
642
|
+
* extension method, which would defeat the whole point of the
|
|
643
|
+
* capability gate.
|
|
644
|
+
*/
|
|
645
|
+
type DOGraphClient = GraphClient<CloudflareCapability>;
|
|
646
|
+
type DODynamicGraphClient = DynamicGraphClient<CloudflareCapability>;
|
|
443
647
|
/**
|
|
444
648
|
* Options for `createDOClient`. Same shape as `GraphClientOptions`; the DO
|
|
445
649
|
* backend does not expose a table label of its own — the DO owns its SQLite
|
|
@@ -461,8 +665,8 @@ type DOClientOptions = GraphClientOptions;
|
|
|
461
665
|
*/
|
|
462
666
|
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options: DOClientOptions & {
|
|
463
667
|
registryMode: DynamicRegistryConfig;
|
|
464
|
-
}):
|
|
465
|
-
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options?: DOClientOptions):
|
|
668
|
+
}): DODynamicGraphClient;
|
|
669
|
+
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options?: DOClientOptions): DOGraphClient;
|
|
466
670
|
/**
|
|
467
671
|
* Construct a peer `GraphClient` that shares `client`'s DO namespace and
|
|
468
672
|
* construction options but targets a different root DO (i.e. a different
|
|
@@ -495,8 +699,8 @@ declare function createDOClient(namespace: FiregraphNamespace, rootKey: string,
|
|
|
495
699
|
* as `createDOClient`'s `rootKey`: non-empty,
|
|
496
700
|
* no `/`.
|
|
497
701
|
*/
|
|
498
|
-
declare function createSiblingClient(client:
|
|
499
|
-
declare function createSiblingClient(client:
|
|
702
|
+
declare function createSiblingClient(client: DOGraphClient, siblingRootKey: string): DOGraphClient;
|
|
703
|
+
declare function createSiblingClient(client: DODynamicGraphClient, siblingRootKey: string): DODynamicGraphClient;
|
|
500
704
|
|
|
501
705
|
/**
|
|
502
706
|
* Flat SQLite schema for a single firegraph DO.
|
|
@@ -551,4 +755,4 @@ interface BuildDOSchemaOptions {
|
|
|
551
755
|
*/
|
|
552
756
|
declare function buildDOSchemaStatements(table: string, options?: BuildDOSchemaOptions): string[];
|
|
553
757
|
|
|
554
|
-
export { type BatchOp, type BuildDOSchemaOptions, type DOClientOptions, DORPCBackend, type DORPCBackendOptions, type DOSqlCursor, type DOSqlExecutor, type DOStorage, type DurableObjectIdLike, type DurableObjectStateLike, FiregraphDO, type FiregraphDOOptions, type FiregraphNamespace, type FiregraphStub, buildDOSchemaStatements, createDOClient, createSiblingClient };
|
|
758
|
+
export { AggregateSpec, BackendCapabilities, type BatchOp, type BuildDOSchemaOptions, BulkUpdatePatch, type CloudflareCapability, type DOClientOptions, DORPCBackend, type DORPCBackendOptions, type DOSqlCursor, type DOSqlExecutor, type DOStorage, type DurableObjectIdLike, type DurableObjectStateLike, ExpandParams, ExpandResult, FiregraphDO, type FiregraphDOOptions, type FiregraphNamespace, type FiregraphStub, buildDOSchemaStatements, createDOClient, createSiblingClient };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { W as WritableRecord, U as UpdatePayload, S as StorageBackend, T as TransactionBackend,
|
|
2
|
-
|
|
1
|
+
import { W as WritableRecord, f as WriteMode, U as UpdatePayload, G as GraphRegistry, I as IndexSpec, p as QueryFilter, ai as QueryOptions, z as AggregateSpec, O as CascadeResult, F as FindEdgesParams, H as BulkOptions, L as BulkResult, b as BulkUpdatePatch, E as ExpandParams, S as StorageBackend, B as BackendCapabilities, t as GraphClient, Z as DynamicGraphClient, m as StoredGraphRecord, T as TransactionBackend, a as BatchBackend, u as GraphReader, e as ExpandResult, a8 as GraphClientOptions, $ as DynamicRegistryConfig } from '../backend-DuvHGgK1.js';
|
|
2
|
+
export { A as AggregateExtension, w as AggregateField, x as AggregateOp, y as AggregateResult, N as Capability, d as DmlExtension, J as JoinExtension, g as createCapabilities, h as deleteField, j as intersectCapabilities } from '../backend-DuvHGgK1.js';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
+
export { M as META_EDGE_TYPE, a as META_NODE_TYPE, b as createMergedRegistry, d as createRegistry, f as generateId } from '../registry-C2KUPVZj.js';
|
|
5
|
+
export { C as CapabilityNotSupportedError } from '../errors-BRc3I_eH.js';
|
|
4
6
|
import '@google-cloud/firestore';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -40,6 +42,30 @@ interface DORecordWire {
|
|
|
40
42
|
createdAtMs: number;
|
|
41
43
|
updatedAtMs: number;
|
|
42
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Discriminator for one projected column on the DO backend. The decoder
|
|
47
|
+
* uses this to recover the JS-shape of the requested field. Mirrors the
|
|
48
|
+
* shared-SQLite `ProjectedColumnKind` — same kinds, same decode rules. The
|
|
49
|
+
* two share no module so the symbol is duplicated; the contract is locked
|
|
50
|
+
* by the cross-backend test in `tests/unit/cloudflare-sql.test.ts`.
|
|
51
|
+
*/
|
|
52
|
+
type DOProjectedColumnKind = 'builtin-text' | 'builtin-int' | 'builtin-timestamp' | 'data' | 'json';
|
|
53
|
+
/** Per-column metadata returned alongside the compiled projection statement. */
|
|
54
|
+
interface DOProjectedColumnSpec {
|
|
55
|
+
/** Original caller-supplied field name. Used as the alias in the SQL
|
|
56
|
+
* projection list AND as the key in the returned JS row. */
|
|
57
|
+
field: string;
|
|
58
|
+
/** Kind discriminator — see `DOProjectedColumnKind`. */
|
|
59
|
+
kind: DOProjectedColumnKind;
|
|
60
|
+
/**
|
|
61
|
+
* For `kind === 'json'` only: alias of the paired `json_type` companion
|
|
62
|
+
* column. Uses a positional sentinel (`__fg_t_<idx>`) keyed by the
|
|
63
|
+
* field's position in the unique projection list rather than the
|
|
64
|
+
* historical `<field>__t` suffix, which would collide if the caller
|
|
65
|
+
* projected both `'foo'` and `'foo__t'` (both legal user input).
|
|
66
|
+
*/
|
|
67
|
+
typeAlias?: string;
|
|
68
|
+
}
|
|
43
69
|
|
|
44
70
|
/**
|
|
45
71
|
* `FiregraphDO` — the Durable Object class that holds a single subgraph's
|
|
@@ -124,6 +150,7 @@ type BatchOp = {
|
|
|
124
150
|
kind: 'set';
|
|
125
151
|
docId: string;
|
|
126
152
|
record: WritableRecord;
|
|
153
|
+
mode: WriteMode;
|
|
127
154
|
} | {
|
|
128
155
|
kind: 'update';
|
|
129
156
|
docId: string;
|
|
@@ -185,7 +212,15 @@ declare class FiregraphDO extends DurableObject<unknown> {
|
|
|
185
212
|
constructor(ctx: DurableObjectStateLike, env: unknown, options?: FiregraphDOOptions);
|
|
186
213
|
_fgGetDoc(docId: string): Promise<DORecordWire | null>;
|
|
187
214
|
_fgQuery(filters: QueryFilter[], options?: QueryOptions): Promise<DORecordWire[]>;
|
|
188
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Aggregate query (capability `query.aggregate`). Compiles a single
|
|
217
|
+
* `SELECT` projecting one column per alias; SQLite handles count, sum,
|
|
218
|
+
* avg, min, max natively. Empty-set fix-ups (NULL → 0 for sum/min/max,
|
|
219
|
+
* NaN for avg) happen on the client side in `DORPCBackend.aggregate` so
|
|
220
|
+
* the wire payload stays a plain row of (alias → number | null).
|
|
221
|
+
*/
|
|
222
|
+
_fgAggregate(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number | null>>;
|
|
223
|
+
_fgSetDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
189
224
|
_fgUpdateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
190
225
|
_fgDeleteDoc(docId: string): Promise<void>;
|
|
191
226
|
/**
|
|
@@ -197,6 +232,21 @@ declare class FiregraphDO extends DurableObject<unknown> {
|
|
|
197
232
|
_fgBatch(ops: BatchOp[]): Promise<void>;
|
|
198
233
|
_fgRemoveNodeCascade(uid: string): Promise<CascadeResult>;
|
|
199
234
|
_fgBulkRemoveEdges(params: FindEdgesParams, _options?: BulkOptions): Promise<BulkResult>;
|
|
235
|
+
_fgBulkDelete(filters: QueryFilter[], _options?: BulkOptions): Promise<BulkResult>;
|
|
236
|
+
_fgBulkUpdate(filters: QueryFilter[], patch: BulkUpdatePatch, _options?: BulkOptions): Promise<BulkResult>;
|
|
237
|
+
_fgExpand(params: ExpandParams): Promise<ExpandResultWire>;
|
|
238
|
+
_fgFindEdgesProjected(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<{
|
|
239
|
+
rows: Array<Record<string, unknown>>;
|
|
240
|
+
columns: DOProjectedColumnSpec[];
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Run a DML statement with `RETURNING "doc_id"` so the affected-row count
|
|
244
|
+
* comes back authoritatively. Errors are caught and surfaced via the
|
|
245
|
+
* `BulkResult.errors` array (single batch, batchIndex 0) so the wire
|
|
246
|
+
* payload stays a regular `BulkResult` and the client doesn't have to
|
|
247
|
+
* differentiate "RPC threw" from "single-statement failure."
|
|
248
|
+
*/
|
|
249
|
+
private execDmlWithReturning;
|
|
200
250
|
/**
|
|
201
251
|
* Wipe every row. Called by the client when tearing down a subgraph DO as
|
|
202
252
|
* part of cascade — the DO itself can't be destroyed (DO IDs persist
|
|
@@ -257,14 +307,80 @@ interface DurableObjectIdLike {
|
|
|
257
307
|
interface FiregraphStub {
|
|
258
308
|
_fgGetDoc(docId: string): Promise<DORecordWire | null>;
|
|
259
309
|
_fgQuery(filters: QueryFilter[], options?: QueryOptions): Promise<DORecordWire[]>;
|
|
260
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Optional — added in Phase 4 (`query.aggregate`). Marked optional so
|
|
312
|
+
* external worker code that hand-rolls a stub wrapper around a real DO
|
|
313
|
+
* stub (e.g. for testing or for layering structured-clone shims) keeps
|
|
314
|
+
* compiling without modification. `FiregraphDO` always implements this
|
|
315
|
+
* method, but callers of `DORPCBackend.aggregate` must either assert the
|
|
316
|
+
* stub supports it or be prepared for `UNSUPPORTED_OPERATION` at runtime.
|
|
317
|
+
*/
|
|
318
|
+
_fgAggregate?(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number | null>>;
|
|
319
|
+
_fgSetDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
261
320
|
_fgUpdateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
262
321
|
_fgDeleteDoc(docId: string): Promise<void>;
|
|
263
322
|
_fgBatch(ops: BatchOp[]): Promise<void>;
|
|
264
323
|
_fgRemoveNodeCascade(uid: string): Promise<CascadeResult>;
|
|
265
324
|
_fgBulkRemoveEdges(params: FindEdgesParams, options?: BulkOptions): Promise<BulkResult>;
|
|
325
|
+
/**
|
|
326
|
+
* Optional — added in Phase 5 (`query.dml`). Same back-compat rationale as
|
|
327
|
+
* `_fgAggregate`: external worker code that hand-rolls a stub wrapper keeps
|
|
328
|
+
* compiling without modification. `FiregraphDO` always implements this
|
|
329
|
+
* method; callers of `DORPCBackend.bulkDelete` either assert support or
|
|
330
|
+
* accept `UNSUPPORTED_OPERATION` at runtime.
|
|
331
|
+
*/
|
|
332
|
+
_fgBulkDelete?(filters: QueryFilter[], options?: BulkOptions): Promise<BulkResult>;
|
|
333
|
+
/**
|
|
334
|
+
* Optional — added in Phase 5 (`query.dml`). See `_fgBulkDelete`.
|
|
335
|
+
*/
|
|
336
|
+
_fgBulkUpdate?(filters: QueryFilter[], patch: BulkUpdatePatch, options?: BulkOptions): Promise<BulkResult>;
|
|
337
|
+
/**
|
|
338
|
+
* Optional — added in Phase 6 (`query.join`). Same back-compat rationale as
|
|
339
|
+
* `_fgAggregate` / `_fgBulkDelete`: external worker code that hand-rolls a
|
|
340
|
+
* stub wrapper keeps compiling without modification. `FiregraphDO` always
|
|
341
|
+
* implements this method; callers of `DORPCBackend.expand` either assert
|
|
342
|
+
* the stub supports it or accept `UNSUPPORTED_OPERATION` at runtime.
|
|
343
|
+
*
|
|
344
|
+
* The wire shape uses `ExpandResultWire` so `StoredGraphRecord` instances
|
|
345
|
+
* (which carry `Timestamp` wrappers) survive the structured-clone hop —
|
|
346
|
+
* they're rehydrated on this side via `hydrateDORecord`, just like the
|
|
347
|
+
* `query()` and `_fgBulkRemoveEdges` paths.
|
|
348
|
+
*/
|
|
349
|
+
_fgExpand?(params: ExpandParams): Promise<ExpandResultWire>;
|
|
350
|
+
/**
|
|
351
|
+
* Optional — added in Phase 7 (`query.select`). Same back-compat rationale
|
|
352
|
+
* as `_fgAggregate` / `_fgBulkDelete` / `_fgExpand`: external worker code
|
|
353
|
+
* that hand-rolls a stub wrapper keeps compiling without modification.
|
|
354
|
+
* `FiregraphDO` always implements this method; callers of
|
|
355
|
+
* `DORPCBackend.findEdgesProjected` either assert the stub supports it or
|
|
356
|
+
* accept `UNSUPPORTED_OPERATION` at runtime.
|
|
357
|
+
*
|
|
358
|
+
* The wire shape returns `{ rows, columns }` — raw row objects from the
|
|
359
|
+
* SQLite executor plus the per-column metadata produced by
|
|
360
|
+
* `compileDOFindEdgesProjected`. Decoding (BigInt → number, timestamp
|
|
361
|
+
* rehydration, paired `__t` resolution for `data.*` paths) happens on
|
|
362
|
+
* the client side via `decodeDOProjectedRow`. We deliberately do NOT
|
|
363
|
+
* decode inside the DO because `GraphTimestampImpl` instances do not
|
|
364
|
+
* survive workerd's structured-clone boundary as class instances —
|
|
365
|
+
* decoding must happen on the side that owns the prototype.
|
|
366
|
+
*/
|
|
367
|
+
_fgFindEdgesProjected?(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<{
|
|
368
|
+
rows: Array<Record<string, unknown>>;
|
|
369
|
+
columns: DOProjectedColumnSpec[];
|
|
370
|
+
}>;
|
|
266
371
|
_fgDestroy(): Promise<void>;
|
|
267
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Wire shape for `_fgExpand`. The DO returns rows as `DORecordWire` (the
|
|
375
|
+
* SQLite row layout) and the backend re-hydrates them on this side, so
|
|
376
|
+
* `Timestamp` wrappers are reconstructed locally and never round-trip
|
|
377
|
+
* through workerd's structured-clone boundary as plain objects.
|
|
378
|
+
*/
|
|
379
|
+
interface ExpandResultWire {
|
|
380
|
+
edges: DORecordWire[];
|
|
381
|
+
/** Aligned with `edges`; absent when the caller didn't request hydration. */
|
|
382
|
+
targets?: Array<DORecordWire | null>;
|
|
383
|
+
}
|
|
268
384
|
interface FiregraphNamespace {
|
|
269
385
|
idFromName(name: string): DurableObjectIdLike;
|
|
270
386
|
get(id: DurableObjectIdLike): FiregraphStub;
|
|
@@ -303,9 +419,26 @@ interface DORPCBackendOptions {
|
|
|
303
419
|
* own overload signatures.
|
|
304
420
|
* @internal
|
|
305
421
|
*/
|
|
306
|
-
makeSiblingClient?: (siblingStorageKey: string) => GraphClient | DynamicGraphClient
|
|
422
|
+
makeSiblingClient?: (siblingStorageKey: string) => GraphClient<CloudflareCapability> | DynamicGraphClient<CloudflareCapability>;
|
|
307
423
|
}
|
|
308
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Capability union declared by the DO RPC backend.
|
|
426
|
+
*
|
|
427
|
+
* Note the absence of `core.transactions`: `runTransaction` throws
|
|
428
|
+
* `UNSUPPORTED_OPERATION` because holding a synchronous SQLite transaction
|
|
429
|
+
* across async RPC calls would block the DO's single-threaded executor (see
|
|
430
|
+
* `transactionsUnsupported` above). `raw.sql` is also intentionally absent —
|
|
431
|
+
* the SQL surface lives inside the DO and isn't exposed across the RPC
|
|
432
|
+
* boundary.
|
|
433
|
+
*
|
|
434
|
+
* Conservative declaration matters: the type-level capability gate (Phase 3)
|
|
435
|
+
* relies on the union and the runtime cap-set agreeing. Adding a cap here
|
|
436
|
+
* without a corresponding runtime method would let callers reach a method
|
|
437
|
+
* that doesn't exist.
|
|
438
|
+
*/
|
|
439
|
+
type CloudflareCapability = 'core.read' | 'core.write' | 'core.batch' | 'core.subgraph' | 'query.aggregate' | 'query.dml' | 'query.join' | 'query.select';
|
|
440
|
+
declare class DORPCBackend implements StorageBackend<CloudflareCapability> {
|
|
441
|
+
readonly capabilities: BackendCapabilities<CloudflareCapability>;
|
|
309
442
|
readonly collectionPath = "firegraph";
|
|
310
443
|
readonly scopePath: string;
|
|
311
444
|
/** @internal */
|
|
@@ -314,13 +447,21 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
314
447
|
readonly namespace: FiregraphNamespace;
|
|
315
448
|
private readonly registryAccessor?;
|
|
316
449
|
/** @internal — see `DORPCBackendOptions.makeSiblingClient` for the union-type rationale. */
|
|
317
|
-
readonly makeSiblingClient?: (siblingStorageKey: string) => GraphClient | DynamicGraphClient
|
|
450
|
+
readonly makeSiblingClient?: (siblingStorageKey: string) => GraphClient<CloudflareCapability> | DynamicGraphClient<CloudflareCapability>;
|
|
318
451
|
private cachedStub;
|
|
319
452
|
constructor(namespace: FiregraphNamespace, options: DORPCBackendOptions);
|
|
320
453
|
private get stub();
|
|
321
454
|
getDoc(docId: string): Promise<StoredGraphRecord | null>;
|
|
322
455
|
query(filters: QueryFilter[], options?: QueryOptions): Promise<StoredGraphRecord[]>;
|
|
323
|
-
|
|
456
|
+
/**
|
|
457
|
+
* Run an aggregate query inside the backing DO. The DO returns a row of
|
|
458
|
+
* `{ alias: number | null }` (null = SQLite NULL for SUM/MIN/MAX over an
|
|
459
|
+
* empty set, or the count being literally 0); this method resolves NULL
|
|
460
|
+
* to 0 for SUM/MIN/MAX and to NaN for AVG, matching the SQLite backend
|
|
461
|
+
* and the Firestore Standard helper.
|
|
462
|
+
*/
|
|
463
|
+
aggregate(spec: AggregateSpec, filters: QueryFilter[]): Promise<Record<string, number>>;
|
|
464
|
+
setDoc(docId: string, record: WritableRecord, mode: WriteMode): Promise<void>;
|
|
324
465
|
updateDoc(docId: string, update: UpdatePayload): Promise<void>;
|
|
325
466
|
deleteDoc(docId: string): Promise<void>;
|
|
326
467
|
runTransaction<T>(_fn: (tx: TransactionBackend) => Promise<T>): Promise<T>;
|
|
@@ -328,6 +469,57 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
328
469
|
subgraph(parentNodeUid: string, name: string): StorageBackend;
|
|
329
470
|
removeNodeCascade(uid: string, reader: GraphReader, options?: BulkOptions): Promise<CascadeResult>;
|
|
330
471
|
bulkRemoveEdges(params: FindEdgesParams, _reader: GraphReader, options?: BulkOptions): Promise<BulkResult>;
|
|
472
|
+
/**
|
|
473
|
+
* Single-statement bulk DELETE inside the backing DO. The DO compiles
|
|
474
|
+
* the filter list to one `DELETE … WHERE …` statement and returns a
|
|
475
|
+
* `BulkResult` whose `deleted` is the affected-row count.
|
|
476
|
+
*
|
|
477
|
+
* Defensive `_fgBulkDelete` presence check mirrors `aggregate()`: the
|
|
478
|
+
* RPC method is optional on `FiregraphStub` so external worker code with
|
|
479
|
+
* a hand-rolled stub wrapper still type-checks. Surface a clear
|
|
480
|
+
* `UNSUPPORTED_OPERATION` rather than `TypeError: stub._fgBulkDelete is
|
|
481
|
+
* not a function` when the wrapper hasn't forwarded the method.
|
|
482
|
+
*/
|
|
483
|
+
bulkDelete(filters: QueryFilter[], options?: BulkOptions): Promise<BulkResult>;
|
|
484
|
+
/**
|
|
485
|
+
* Single-statement bulk UPDATE inside the backing DO. Same contract as
|
|
486
|
+
* `bulkDelete` for the missing-method case; the DO compiles the patch to
|
|
487
|
+
* one `UPDATE … SET data = json_patch(...) WHERE …` statement.
|
|
488
|
+
*/
|
|
489
|
+
bulkUpdate(filters: QueryFilter[], patch: BulkUpdatePatch, options?: BulkOptions): Promise<BulkResult>;
|
|
490
|
+
/**
|
|
491
|
+
* Multi-source fan-out — `query.join` capability. Routes the call through
|
|
492
|
+
* the DO's `_fgExpand` RPC, which compiles to one `SELECT … WHERE
|
|
493
|
+
* "aUid" IN (?, …)` statement (plus, when `params.hydrate === true`, a
|
|
494
|
+
* second IN-clause statement against the node rows).
|
|
495
|
+
*
|
|
496
|
+
* Defensive `_fgExpand` presence check matches the bulk-DML pattern: the
|
|
497
|
+
* RPC method is optional on `FiregraphStub` so external worker code with
|
|
498
|
+
* a hand-rolled stub wrapper still type-checks. We surface a clear
|
|
499
|
+
* `UNSUPPORTED_OPERATION` rather than `TypeError: stub._fgExpand is not a
|
|
500
|
+
* function` if the wrapper hasn't forwarded the method.
|
|
501
|
+
*/
|
|
502
|
+
expand(params: ExpandParams): Promise<ExpandResult>;
|
|
503
|
+
/**
|
|
504
|
+
* Server-side projection — `query.select` capability. Forwards the call to
|
|
505
|
+
* the DO's `_fgFindEdgesProjected` RPC, which compiles to a single
|
|
506
|
+
* `SELECT json_extract(...) AS …, json_type(...) AS …__t FROM <table>
|
|
507
|
+
* WHERE …` statement. The DO returns raw rows + per-column metadata; this
|
|
508
|
+
* method decodes each row locally via `decodeDOProjectedRow`.
|
|
509
|
+
*
|
|
510
|
+
* Decoding lives on this side (not inside the DO) because
|
|
511
|
+
* `GraphTimestampImpl` is a class — its prototype does not survive
|
|
512
|
+
* workerd's structured-clone boundary — so timestamp rehydration must
|
|
513
|
+
* happen wherever the rows are consumed by the GraphClient.
|
|
514
|
+
*
|
|
515
|
+
* Defensive `_fgFindEdgesProjected` presence check matches the `expand` /
|
|
516
|
+
* bulk-DML / aggregate pattern: the RPC method is optional on
|
|
517
|
+
* `FiregraphStub` so external worker code with a hand-rolled stub wrapper
|
|
518
|
+
* still type-checks. Surface a clear `UNSUPPORTED_OPERATION` rather than
|
|
519
|
+
* `TypeError: stub._fgFindEdgesProjected is not a function` if the
|
|
520
|
+
* wrapper hasn't forwarded the method.
|
|
521
|
+
*/
|
|
522
|
+
findEdgesProjected(select: ReadonlyArray<string>, filters: QueryFilter[], options?: QueryOptions): Promise<Array<Record<string, unknown>>>;
|
|
331
523
|
/**
|
|
332
524
|
* Wipe this DO's storage. The DO itself can't be deleted — its ID
|
|
333
525
|
* persists forever — but its rows can be emptied, which is what the
|
|
@@ -440,6 +632,18 @@ declare class DORPCBackend implements StorageBackend {
|
|
|
440
632
|
* ```
|
|
441
633
|
*/
|
|
442
634
|
|
|
635
|
+
/**
|
|
636
|
+
* The DO declares a strict subset of `Capability` (no `search.*`,
|
|
637
|
+
* `realtime.listen`, or `raw.*`). Local variables and helper closures
|
|
638
|
+
* that round-trip the client need to use the narrower form so that a
|
|
639
|
+
* `GraphClient<CloudflareCapability>` (which doesn't promise, e.g.,
|
|
640
|
+
* `findNearest`) is assignable. Using the unparameterized
|
|
641
|
+
* `GraphClient` here would require the DO to implement every
|
|
642
|
+
* extension method, which would defeat the whole point of the
|
|
643
|
+
* capability gate.
|
|
644
|
+
*/
|
|
645
|
+
type DOGraphClient = GraphClient<CloudflareCapability>;
|
|
646
|
+
type DODynamicGraphClient = DynamicGraphClient<CloudflareCapability>;
|
|
443
647
|
/**
|
|
444
648
|
* Options for `createDOClient`. Same shape as `GraphClientOptions`; the DO
|
|
445
649
|
* backend does not expose a table label of its own — the DO owns its SQLite
|
|
@@ -461,8 +665,8 @@ type DOClientOptions = GraphClientOptions;
|
|
|
461
665
|
*/
|
|
462
666
|
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options: DOClientOptions & {
|
|
463
667
|
registryMode: DynamicRegistryConfig;
|
|
464
|
-
}):
|
|
465
|
-
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options?: DOClientOptions):
|
|
668
|
+
}): DODynamicGraphClient;
|
|
669
|
+
declare function createDOClient(namespace: FiregraphNamespace, rootKey: string, options?: DOClientOptions): DOGraphClient;
|
|
466
670
|
/**
|
|
467
671
|
* Construct a peer `GraphClient` that shares `client`'s DO namespace and
|
|
468
672
|
* construction options but targets a different root DO (i.e. a different
|
|
@@ -495,8 +699,8 @@ declare function createDOClient(namespace: FiregraphNamespace, rootKey: string,
|
|
|
495
699
|
* as `createDOClient`'s `rootKey`: non-empty,
|
|
496
700
|
* no `/`.
|
|
497
701
|
*/
|
|
498
|
-
declare function createSiblingClient(client:
|
|
499
|
-
declare function createSiblingClient(client:
|
|
702
|
+
declare function createSiblingClient(client: DOGraphClient, siblingRootKey: string): DOGraphClient;
|
|
703
|
+
declare function createSiblingClient(client: DODynamicGraphClient, siblingRootKey: string): DODynamicGraphClient;
|
|
500
704
|
|
|
501
705
|
/**
|
|
502
706
|
* Flat SQLite schema for a single firegraph DO.
|
|
@@ -551,4 +755,4 @@ interface BuildDOSchemaOptions {
|
|
|
551
755
|
*/
|
|
552
756
|
declare function buildDOSchemaStatements(table: string, options?: BuildDOSchemaOptions): string[];
|
|
553
757
|
|
|
554
|
-
export { type BatchOp, type BuildDOSchemaOptions, type DOClientOptions, DORPCBackend, type DORPCBackendOptions, type DOSqlCursor, type DOSqlExecutor, type DOStorage, type DurableObjectIdLike, type DurableObjectStateLike, FiregraphDO, type FiregraphDOOptions, type FiregraphNamespace, type FiregraphStub, buildDOSchemaStatements, createDOClient, createSiblingClient };
|
|
758
|
+
export { AggregateSpec, BackendCapabilities, type BatchOp, type BuildDOSchemaOptions, BulkUpdatePatch, type CloudflareCapability, type DOClientOptions, DORPCBackend, type DORPCBackendOptions, type DOSqlCursor, type DOSqlExecutor, type DOStorage, type DurableObjectIdLike, type DurableObjectStateLike, ExpandParams, ExpandResult, FiregraphDO, type FiregraphDOOptions, type FiregraphNamespace, type FiregraphStub, buildDOSchemaStatements, createDOClient, createSiblingClient };
|