@typicalday/firegraph 0.11.0 → 0.11.2
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 +2 -10
- package/dist/{chunk-6SB34IPQ.js → chunk-NJSOD64C.js} +21 -12
- package/dist/chunk-NJSOD64C.js.map +1 -0
- package/dist/cloudflare/index.cjs +51 -29
- package/dist/cloudflare/index.cjs.map +1 -1
- package/dist/cloudflare/index.d.cts +37 -12
- package/dist/cloudflare/index.d.ts +37 -12
- package/dist/cloudflare/index.js +32 -19
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -8
- package/dist/index.d.ts +38 -8
- package/dist/index.js +1 -1
- package/package.json +8 -3
- package/dist/chunk-6SB34IPQ.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { W as WritableRecord, U as UpdatePayload, S as StorageBackend, T as TransactionBackend, B as BatchBackend } from '../backend-np4gEVhB.cjs';
|
|
2
2
|
import { c as GraphRegistry, I as IndexSpec, i as QueryFilter, z as QueryOptions, C as CascadeResult, F as FindEdgesParams, m as BulkOptions, o as BulkResult, a as GraphClient, D as DynamicGraphClient, S as StoredGraphRecord, d as GraphReader, G as GraphClientOptions, e as DynamicRegistryConfig } from '../types-BGWxcpI_.cjs';
|
|
3
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
3
4
|
import '@google-cloud/firestore';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -79,14 +80,26 @@ interface DORecordWire {
|
|
|
79
80
|
* }
|
|
80
81
|
* ```
|
|
81
82
|
*
|
|
82
|
-
* ## Why
|
|
83
|
+
* ## Why `extends DurableObject`?
|
|
83
84
|
*
|
|
84
|
-
* Cloudflare
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
85
|
+
* Cloudflare's modern Durable Objects RPC dispatcher only accepts arbitrary
|
|
86
|
+
* method invocations on stubs whose backing class extends the special
|
|
87
|
+
* `DurableObject` base from `cloudflare:workers`. Plain classes with the
|
|
88
|
+
* `(state, env)` constructor shape still load and serve `fetch()`, but a
|
|
89
|
+
* stub method call (`stub._fgGetDoc(...)`) on a plain-class DO throws:
|
|
90
|
+
*
|
|
91
|
+
* The receiving Durable Object does not support RPC, because its class
|
|
92
|
+
* was not declared with `extends DurableObject`.
|
|
93
|
+
*
|
|
94
|
+
* `DORPCBackend` calls every operation as a stub method (see
|
|
95
|
+
* `src/cloudflare/backend.ts`), so extending `DurableObject` is mandatory
|
|
96
|
+
* for this library's design to work on production Workers.
|
|
97
|
+
*
|
|
98
|
+
* The `cloudflare:workers` import is virtual — only the workerd runtime
|
|
99
|
+
* resolves it. For Node tests we route the import through a vitest alias
|
|
100
|
+
* to a tiny stub class (`tests/__shims__/cloudflare-workers.ts`) that just
|
|
101
|
+
* captures `ctx`/`env`. Tests instantiating `FiregraphDO` directly still
|
|
102
|
+
* work; they just go through the stub instead of the real base class.
|
|
90
103
|
*/
|
|
91
104
|
|
|
92
105
|
interface DOSqlCursor<T> {
|
|
@@ -146,11 +159,23 @@ interface FiregraphDOOptions {
|
|
|
146
159
|
*/
|
|
147
160
|
coreIndexes?: IndexSpec[];
|
|
148
161
|
}
|
|
149
|
-
declare class FiregraphDO {
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
declare class FiregraphDO extends DurableObject<unknown> {
|
|
163
|
+
/**
|
|
164
|
+
* @internal — locally-narrowed alias for `this.ctx`, used only by
|
|
165
|
+
* FiregraphDO's own SQL helpers. Same runtime object as the inherited
|
|
166
|
+
* `this.ctx`, but typed as `DurableObjectStateLike` (just `storage.sql`
|
|
167
|
+
* / `transactionSync` / `blockConcurrencyWhile`) so internal calls
|
|
168
|
+
* don't trip over workers-types' stricter
|
|
169
|
+
* `SqlStorage.exec<T extends Record<string, SqlStorageValue>>`
|
|
170
|
+
* constraint vs the `Record<string, unknown>` rows firegraph passes.
|
|
171
|
+
*
|
|
172
|
+
* **Subclasses should use `this.ctx`, not `this.state`.** `this.state`
|
|
173
|
+
* deliberately exposes only the slice FiregraphDO needs internally;
|
|
174
|
+
* subclasses that want `id`, `acceptWebSocket`, `setAlarm`, `getAlarm`,
|
|
175
|
+
* `waitUntil`, `props`, etc. must reach for the inherited `this.ctx`
|
|
176
|
+
* (the full workers-types `DurableObjectState`).
|
|
177
|
+
*/
|
|
178
|
+
protected readonly state: DurableObjectStateLike;
|
|
154
179
|
/** @internal — table name used by every compiled statement. */
|
|
155
180
|
protected readonly table: string;
|
|
156
181
|
/** @internal — registry consulted by `runSchema` for per-entry indexes. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { W as WritableRecord, U as UpdatePayload, S as StorageBackend, T as TransactionBackend, B as BatchBackend } from '../backend-U-MLShlg.js';
|
|
2
2
|
import { c as GraphRegistry, I as IndexSpec, i as QueryFilter, z as QueryOptions, C as CascadeResult, F as FindEdgesParams, m as BulkOptions, o as BulkResult, a as GraphClient, D as DynamicGraphClient, S as StoredGraphRecord, d as GraphReader, G as GraphClientOptions, e as DynamicRegistryConfig } from '../types-BGWxcpI_.js';
|
|
3
|
+
import { DurableObject } from 'cloudflare:workers';
|
|
3
4
|
import '@google-cloud/firestore';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -79,14 +80,26 @@ interface DORecordWire {
|
|
|
79
80
|
* }
|
|
80
81
|
* ```
|
|
81
82
|
*
|
|
82
|
-
* ## Why
|
|
83
|
+
* ## Why `extends DurableObject`?
|
|
83
84
|
*
|
|
84
|
-
* Cloudflare
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
85
|
+
* Cloudflare's modern Durable Objects RPC dispatcher only accepts arbitrary
|
|
86
|
+
* method invocations on stubs whose backing class extends the special
|
|
87
|
+
* `DurableObject` base from `cloudflare:workers`. Plain classes with the
|
|
88
|
+
* `(state, env)` constructor shape still load and serve `fetch()`, but a
|
|
89
|
+
* stub method call (`stub._fgGetDoc(...)`) on a plain-class DO throws:
|
|
90
|
+
*
|
|
91
|
+
* The receiving Durable Object does not support RPC, because its class
|
|
92
|
+
* was not declared with `extends DurableObject`.
|
|
93
|
+
*
|
|
94
|
+
* `DORPCBackend` calls every operation as a stub method (see
|
|
95
|
+
* `src/cloudflare/backend.ts`), so extending `DurableObject` is mandatory
|
|
96
|
+
* for this library's design to work on production Workers.
|
|
97
|
+
*
|
|
98
|
+
* The `cloudflare:workers` import is virtual — only the workerd runtime
|
|
99
|
+
* resolves it. For Node tests we route the import through a vitest alias
|
|
100
|
+
* to a tiny stub class (`tests/__shims__/cloudflare-workers.ts`) that just
|
|
101
|
+
* captures `ctx`/`env`. Tests instantiating `FiregraphDO` directly still
|
|
102
|
+
* work; they just go through the stub instead of the real base class.
|
|
90
103
|
*/
|
|
91
104
|
|
|
92
105
|
interface DOSqlCursor<T> {
|
|
@@ -146,11 +159,23 @@ interface FiregraphDOOptions {
|
|
|
146
159
|
*/
|
|
147
160
|
coreIndexes?: IndexSpec[];
|
|
148
161
|
}
|
|
149
|
-
declare class FiregraphDO {
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
declare class FiregraphDO extends DurableObject<unknown> {
|
|
163
|
+
/**
|
|
164
|
+
* @internal — locally-narrowed alias for `this.ctx`, used only by
|
|
165
|
+
* FiregraphDO's own SQL helpers. Same runtime object as the inherited
|
|
166
|
+
* `this.ctx`, but typed as `DurableObjectStateLike` (just `storage.sql`
|
|
167
|
+
* / `transactionSync` / `blockConcurrencyWhile`) so internal calls
|
|
168
|
+
* don't trip over workers-types' stricter
|
|
169
|
+
* `SqlStorage.exec<T extends Record<string, SqlStorageValue>>`
|
|
170
|
+
* constraint vs the `Record<string, unknown>` rows firegraph passes.
|
|
171
|
+
*
|
|
172
|
+
* **Subclasses should use `this.ctx`, not `this.state`.** `this.state`
|
|
173
|
+
* deliberately exposes only the slice FiregraphDO needs internally;
|
|
174
|
+
* subclasses that want `id`, `acceptWebSocket`, `setAlarm`, `getAlarm`,
|
|
175
|
+
* `waitUntil`, `props`, etc. must reach for the inherited `this.ctx`
|
|
176
|
+
* (the full workers-types `DurableObjectState`).
|
|
177
|
+
*/
|
|
178
|
+
protected readonly state: DurableObjectStateLike;
|
|
154
179
|
/** @internal — table name used by every compiled statement. */
|
|
155
180
|
protected readonly table: string;
|
|
156
181
|
/** @internal — registry consulted by `runSchema` for per-entry indexes. */
|
package/dist/cloudflare/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
computeEdgeDocId,
|
|
6
6
|
computeNodeDocId,
|
|
7
7
|
createGraphClientFromBackend
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-NJSOD64C.js";
|
|
9
9
|
import {
|
|
10
10
|
FiregraphError
|
|
11
11
|
} from "../chunk-R7CRGYY4.js";
|
|
@@ -697,15 +697,28 @@ function createSiblingClient(client, siblingRootKey) {
|
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
// src/cloudflare/do.ts
|
|
700
|
+
import { DurableObject } from "cloudflare:workers";
|
|
700
701
|
var DEFAULT_OPTIONS = {
|
|
701
702
|
table: "firegraph",
|
|
702
703
|
autoMigrate: true
|
|
703
704
|
};
|
|
704
|
-
var FiregraphDO = class {
|
|
705
|
-
/**
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
705
|
+
var FiregraphDO = class extends DurableObject {
|
|
706
|
+
/**
|
|
707
|
+
* @internal — locally-narrowed alias for `this.ctx`, used only by
|
|
708
|
+
* FiregraphDO's own SQL helpers. Same runtime object as the inherited
|
|
709
|
+
* `this.ctx`, but typed as `DurableObjectStateLike` (just `storage.sql`
|
|
710
|
+
* / `transactionSync` / `blockConcurrencyWhile`) so internal calls
|
|
711
|
+
* don't trip over workers-types' stricter
|
|
712
|
+
* `SqlStorage.exec<T extends Record<string, SqlStorageValue>>`
|
|
713
|
+
* constraint vs the `Record<string, unknown>` rows firegraph passes.
|
|
714
|
+
*
|
|
715
|
+
* **Subclasses should use `this.ctx`, not `this.state`.** `this.state`
|
|
716
|
+
* deliberately exposes only the slice FiregraphDO needs internally;
|
|
717
|
+
* subclasses that want `id`, `acceptWebSocket`, `setAlarm`, `getAlarm`,
|
|
718
|
+
* `waitUntil`, `props`, etc. must reach for the inherited `this.ctx`
|
|
719
|
+
* (the full workers-types `DurableObjectState`).
|
|
720
|
+
*/
|
|
721
|
+
state;
|
|
709
722
|
/** @internal — table name used by every compiled statement. */
|
|
710
723
|
table;
|
|
711
724
|
/** @internal — registry consulted by `runSchema` for per-entry indexes. */
|
|
@@ -713,8 +726,8 @@ var FiregraphDO = class {
|
|
|
713
726
|
/** @internal — overrides `DEFAULT_CORE_INDEXES` when set. */
|
|
714
727
|
coreIndexes;
|
|
715
728
|
constructor(ctx, env, options = {}) {
|
|
716
|
-
|
|
717
|
-
this.
|
|
729
|
+
super(ctx, env);
|
|
730
|
+
this.state = ctx;
|
|
718
731
|
const table = options.table ?? DEFAULT_OPTIONS.table;
|
|
719
732
|
validateDOTableName(table);
|
|
720
733
|
this.table = table;
|
|
@@ -722,7 +735,7 @@ var FiregraphDO = class {
|
|
|
722
735
|
this.coreIndexes = options.coreIndexes;
|
|
723
736
|
const autoMigrate = options.autoMigrate ?? DEFAULT_OPTIONS.autoMigrate;
|
|
724
737
|
if (autoMigrate) {
|
|
725
|
-
void this.
|
|
738
|
+
void this.state.blockConcurrencyWhile(async () => {
|
|
726
739
|
this.runSchema();
|
|
727
740
|
});
|
|
728
741
|
}
|
|
@@ -754,7 +767,7 @@ var FiregraphDO = class {
|
|
|
754
767
|
async _fgUpdateDoc(docId, update) {
|
|
755
768
|
const stmt = compileDOUpdate(this.table, docId, update, Date.now());
|
|
756
769
|
const sqlWithReturning = `${stmt.sql} RETURNING "doc_id"`;
|
|
757
|
-
const rows = this.
|
|
770
|
+
const rows = this.state.storage.sql.exec(sqlWithReturning, ...stmt.params).toArray();
|
|
758
771
|
if (rows.length === 0) {
|
|
759
772
|
throw new FiregraphError(`updateDoc: no document found for doc_id=${docId}`, "NOT_FOUND");
|
|
760
773
|
}
|
|
@@ -785,9 +798,9 @@ var FiregraphDO = class {
|
|
|
785
798
|
return compileDODelete(this.table, op.docId);
|
|
786
799
|
}
|
|
787
800
|
});
|
|
788
|
-
this.
|
|
801
|
+
this.state.storage.transactionSync(() => {
|
|
789
802
|
for (const stmt of statements) {
|
|
790
|
-
this.
|
|
803
|
+
this.state.storage.sql.exec(stmt.sql, ...stmt.params).toArray();
|
|
791
804
|
}
|
|
792
805
|
});
|
|
793
806
|
}
|
|
@@ -836,9 +849,9 @@ var FiregraphDO = class {
|
|
|
836
849
|
};
|
|
837
850
|
}
|
|
838
851
|
try {
|
|
839
|
-
this.
|
|
852
|
+
this.state.storage.transactionSync(() => {
|
|
840
853
|
for (const stmt of statements) {
|
|
841
|
-
this.
|
|
854
|
+
this.state.storage.sql.exec(stmt.sql, ...stmt.params).toArray();
|
|
842
855
|
}
|
|
843
856
|
});
|
|
844
857
|
return {
|
|
@@ -878,9 +891,9 @@ var FiregraphDO = class {
|
|
|
878
891
|
}
|
|
879
892
|
const deleteStmts = docIds.map((id) => compileDODelete(this.table, id));
|
|
880
893
|
try {
|
|
881
|
-
this.
|
|
894
|
+
this.state.storage.transactionSync(() => {
|
|
882
895
|
for (const stmt of deleteStmts) {
|
|
883
|
-
this.
|
|
896
|
+
this.state.storage.sql.exec(stmt.sql, ...stmt.params).toArray();
|
|
884
897
|
}
|
|
885
898
|
});
|
|
886
899
|
return { deleted: deleteStmts.length, batches: 1, errors: [] };
|
|
@@ -914,14 +927,14 @@ var FiregraphDO = class {
|
|
|
914
927
|
registry: this.registry
|
|
915
928
|
});
|
|
916
929
|
for (const sql of statements) {
|
|
917
|
-
this.
|
|
930
|
+
this.state.storage.sql.exec(sql).toArray();
|
|
918
931
|
}
|
|
919
932
|
}
|
|
920
933
|
execAll(stmt) {
|
|
921
|
-
return this.
|
|
934
|
+
return this.state.storage.sql.exec(stmt.sql, ...stmt.params).toArray();
|
|
922
935
|
}
|
|
923
936
|
execRun(stmt) {
|
|
924
|
-
this.
|
|
937
|
+
this.state.storage.sql.exec(stmt.sql, ...stmt.params).toArray();
|
|
925
938
|
}
|
|
926
939
|
};
|
|
927
940
|
export {
|