@typicalday/firegraph 0.1.0 → 0.2.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.
@@ -141,9 +141,19 @@ interface FindEdgesParams {
141
141
  direction?: 'asc' | 'desc';
142
142
  };
143
143
  where?: WhereClause[];
144
+ /** Set to true to allow queries that may cause full collection scans. */
145
+ allowCollectionScan?: boolean;
144
146
  }
145
147
  interface FindNodesParams {
146
148
  aType: string;
149
+ limit?: number;
150
+ orderBy?: {
151
+ field: string;
152
+ direction?: 'asc' | 'desc';
153
+ };
154
+ where?: WhereClause[];
155
+ /** Set to true to allow queries that may cause full collection scans. */
156
+ allowCollectionScan?: boolean;
147
157
  }
148
158
  interface QueryOptions {
149
159
  limit?: number;
@@ -177,6 +187,18 @@ interface RegistryEntry {
177
187
  titleField?: string;
178
188
  /** Data field to use as the display subtitle (e.g. 'status', 'difficulty'). */
179
189
  subtitleField?: string;
190
+ /**
191
+ * Scope patterns constraining where this type can exist.
192
+ * Omit or leave empty to allow everywhere (backwards compatible).
193
+ *
194
+ * Patterns:
195
+ * - `'root'` — top-level collection only
196
+ * - `'agents'` — exact subgraph name match
197
+ * - `'workflow/agents'` — exact path match
198
+ * - `'*​/agents'` — `*` matches one segment
199
+ * - `'**​/agents'` — `**` matches zero or more segments
200
+ */
201
+ allowedIn?: string[];
180
202
  }
181
203
  /** Topology declaration for an edge (from edge.json). */
182
204
  interface EdgeTopology {
@@ -203,6 +225,8 @@ interface DiscoveredEntity {
203
225
  viewsPath?: string;
204
226
  /** Sample data from sample.json. */
205
227
  sampleData?: Record<string, unknown>;
228
+ /** Scope patterns constraining where this type can exist in subgraphs. */
229
+ allowedIn?: string[];
206
230
  }
207
231
  /** Result of scanning an entities directory. */
208
232
  interface DiscoveryResult {
@@ -233,6 +257,8 @@ interface DefineTypeOptions {
233
257
  viewTemplate?: string;
234
258
  /** Scoped CSS for the view template (injected via Shadow DOM). */
235
259
  viewCss?: string;
260
+ /** Scope patterns constraining where this type can exist in subgraphs. */
261
+ allowedIn?: string[];
236
262
  }
237
263
  /** Data shape stored in a `nodeType` meta-node. */
238
264
  interface NodeTypeData {
@@ -243,6 +269,7 @@ interface NodeTypeData {
243
269
  subtitleField?: string;
244
270
  viewTemplate?: string;
245
271
  viewCss?: string;
272
+ allowedIn?: string[];
246
273
  }
247
274
  /** Data shape stored in an `edgeType` meta-node. */
248
275
  interface EdgeTypeData {
@@ -256,7 +283,9 @@ interface EdgeTypeData {
256
283
  subtitleField?: string;
257
284
  viewTemplate?: string;
258
285
  viewCss?: string;
286
+ allowedIn?: string[];
259
287
  }
288
+ type ScanProtection = 'error' | 'warn' | 'off';
260
289
  interface GraphClientOptions {
261
290
  /** Static registry built from code/discovery. Ignored if registryMode is set. */
262
291
  registry?: GraphRegistry;
@@ -275,9 +304,19 @@ interface GraphClientOptions {
275
304
  * `'standard'` regardless of this setting (emulator doesn't support pipelines).
276
305
  */
277
306
  queryMode?: QueryMode;
307
+ /**
308
+ * Controls query safety behavior for full collection scan prevention.
309
+ *
310
+ * - `'error'` (default) — Throws `QuerySafetyError` for queries that would
311
+ * likely cause a full collection scan. Override per-query with
312
+ * `allowCollectionScan: true`.
313
+ * - `'warn'` — Logs a warning but executes the query.
314
+ * - `'off'` — No scan protection.
315
+ */
316
+ scanProtection?: ScanProtection;
278
317
  }
279
318
  interface GraphRegistry {
280
- validate(aType: string, axbType: string, bType: string, data: unknown): void;
319
+ validate(aType: string, axbType: string, bType: string, data: unknown, scopePath?: string): void;
281
320
  lookup(aType: string, axbType: string, bType: string): RegistryEntry | undefined;
282
321
  entries(): ReadonlyArray<RegistryEntry>;
283
322
  }
@@ -302,6 +341,21 @@ interface GraphClient extends GraphReader, GraphWriter {
302
341
  removeNodeCascade(uid: string, options?: BulkOptions): Promise<CascadeResult>;
303
342
  /** Find all edges matching `params` and delete them in chunked batches. */
304
343
  bulkRemoveEdges(params: FindEdgesParams, options?: BulkOptions): Promise<BulkResult>;
344
+ /**
345
+ * Create a scoped client for a Firestore subcollection under the given
346
+ * parent node's document.
347
+ *
348
+ * The returned client shares a snapshot of the parent's registry at
349
+ * the time of this call. If the parent is a `DynamicGraphClient` and
350
+ * `reloadRegistry()` is called later, existing subgraph clients will
351
+ * NOT see the updated types — create a new subgraph client after
352
+ * reloading to pick up changes.
353
+ *
354
+ * @param parentNodeUid - UID of the parent node whose document owns the subcollection
355
+ * @param name - Subcollection name (defaults to `'graph'`). Must not contain `/`.
356
+ * @returns A `GraphClient` scoped to `{collectionPath}/{parentNodeUid}/{name}`
357
+ */
358
+ subgraph(parentNodeUid: string, name?: string): GraphClient;
305
359
  }
306
360
  interface DynamicGraphClient extends GraphClient {
307
361
  /** Define or update a node type in the dynamic registry. */
@@ -357,6 +411,11 @@ interface BulkOptions {
357
411
  maxRetries?: number;
358
412
  /** Called after each batch commits. */
359
413
  onProgress?: (progress: BulkProgress) => void;
414
+ /**
415
+ * Recursively delete subcollections (subgraphs) under the node's document.
416
+ * Defaults to `true` for `removeNodeCascade`.
417
+ */
418
+ deleteSubcollections?: boolean;
360
419
  }
361
420
  interface BulkProgress {
362
421
  /** Batches committed so far. */
@@ -411,4 +470,4 @@ interface CodegenOptions {
411
470
  */
412
471
  declare function generateTypes(discovery: DiscoveryResult, options?: CodegenOptions): Promise<string>;
413
472
 
414
- export { defineConfig as A, type BulkBatchError as B, type CascadeResult as C, type DynamicRegistryConfig as D, type EdgeTopology as E, type FindEdgesParams as F, type GraphClientOptions as G, type HopDefinition as H, generateTypes as I, resolveView as J, type NodeTypeData as N, type QueryPlan as Q, type RegistryEntry as R, type StoredGraphRecord as S, type TraversalBuilder as T, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type DiscoveryResult as c, type GraphRegistry as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type BulkOptions as h, type BulkProgress as i, type BulkResult as j, type CodegenOptions as k, type DefineTypeOptions as l, type DiscoveredEntity as m, type EdgeTypeData as n, type FiregraphConfig as o, type GraphBatch as p, type GraphTransaction as q, type GraphWriter as r, type HopResult as s, type QueryFilter as t, type QueryMode as u, type QueryOptions as v, type TraversalOptions as w, type TraversalResult as x, type ViewDefaultsConfig as y, type ViewResolverConfig as z };
473
+ export { type ViewResolverConfig as A, type BulkBatchError as B, type CascadeResult as C, type DynamicRegistryConfig as D, type EdgeTopology as E, type FindEdgesParams as F, type GraphClientOptions as G, type HopDefinition as H, defineConfig as I, generateTypes as J, resolveView as K, type NodeTypeData as N, type QueryPlan as Q, type RegistryEntry as R, type ScanProtection as S, type TraversalBuilder as T, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type DiscoveryResult as c, type GraphRegistry as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type QueryFilter as h, type BulkOptions as i, type BulkProgress as j, type BulkResult as k, type CodegenOptions as l, type DefineTypeOptions as m, type DiscoveredEntity as n, type EdgeTypeData as o, type FiregraphConfig as p, type GraphBatch as q, type GraphTransaction as r, type GraphWriter as s, type HopResult as t, type QueryMode as u, type QueryOptions as v, type StoredGraphRecord as w, type TraversalOptions as x, type TraversalResult as y, type ViewDefaultsConfig as z };
@@ -141,9 +141,19 @@ interface FindEdgesParams {
141
141
  direction?: 'asc' | 'desc';
142
142
  };
143
143
  where?: WhereClause[];
144
+ /** Set to true to allow queries that may cause full collection scans. */
145
+ allowCollectionScan?: boolean;
144
146
  }
145
147
  interface FindNodesParams {
146
148
  aType: string;
149
+ limit?: number;
150
+ orderBy?: {
151
+ field: string;
152
+ direction?: 'asc' | 'desc';
153
+ };
154
+ where?: WhereClause[];
155
+ /** Set to true to allow queries that may cause full collection scans. */
156
+ allowCollectionScan?: boolean;
147
157
  }
148
158
  interface QueryOptions {
149
159
  limit?: number;
@@ -177,6 +187,18 @@ interface RegistryEntry {
177
187
  titleField?: string;
178
188
  /** Data field to use as the display subtitle (e.g. 'status', 'difficulty'). */
179
189
  subtitleField?: string;
190
+ /**
191
+ * Scope patterns constraining where this type can exist.
192
+ * Omit or leave empty to allow everywhere (backwards compatible).
193
+ *
194
+ * Patterns:
195
+ * - `'root'` — top-level collection only
196
+ * - `'agents'` — exact subgraph name match
197
+ * - `'workflow/agents'` — exact path match
198
+ * - `'*​/agents'` — `*` matches one segment
199
+ * - `'**​/agents'` — `**` matches zero or more segments
200
+ */
201
+ allowedIn?: string[];
180
202
  }
181
203
  /** Topology declaration for an edge (from edge.json). */
182
204
  interface EdgeTopology {
@@ -203,6 +225,8 @@ interface DiscoveredEntity {
203
225
  viewsPath?: string;
204
226
  /** Sample data from sample.json. */
205
227
  sampleData?: Record<string, unknown>;
228
+ /** Scope patterns constraining where this type can exist in subgraphs. */
229
+ allowedIn?: string[];
206
230
  }
207
231
  /** Result of scanning an entities directory. */
208
232
  interface DiscoveryResult {
@@ -233,6 +257,8 @@ interface DefineTypeOptions {
233
257
  viewTemplate?: string;
234
258
  /** Scoped CSS for the view template (injected via Shadow DOM). */
235
259
  viewCss?: string;
260
+ /** Scope patterns constraining where this type can exist in subgraphs. */
261
+ allowedIn?: string[];
236
262
  }
237
263
  /** Data shape stored in a `nodeType` meta-node. */
238
264
  interface NodeTypeData {
@@ -243,6 +269,7 @@ interface NodeTypeData {
243
269
  subtitleField?: string;
244
270
  viewTemplate?: string;
245
271
  viewCss?: string;
272
+ allowedIn?: string[];
246
273
  }
247
274
  /** Data shape stored in an `edgeType` meta-node. */
248
275
  interface EdgeTypeData {
@@ -256,7 +283,9 @@ interface EdgeTypeData {
256
283
  subtitleField?: string;
257
284
  viewTemplate?: string;
258
285
  viewCss?: string;
286
+ allowedIn?: string[];
259
287
  }
288
+ type ScanProtection = 'error' | 'warn' | 'off';
260
289
  interface GraphClientOptions {
261
290
  /** Static registry built from code/discovery. Ignored if registryMode is set. */
262
291
  registry?: GraphRegistry;
@@ -275,9 +304,19 @@ interface GraphClientOptions {
275
304
  * `'standard'` regardless of this setting (emulator doesn't support pipelines).
276
305
  */
277
306
  queryMode?: QueryMode;
307
+ /**
308
+ * Controls query safety behavior for full collection scan prevention.
309
+ *
310
+ * - `'error'` (default) — Throws `QuerySafetyError` for queries that would
311
+ * likely cause a full collection scan. Override per-query with
312
+ * `allowCollectionScan: true`.
313
+ * - `'warn'` — Logs a warning but executes the query.
314
+ * - `'off'` — No scan protection.
315
+ */
316
+ scanProtection?: ScanProtection;
278
317
  }
279
318
  interface GraphRegistry {
280
- validate(aType: string, axbType: string, bType: string, data: unknown): void;
319
+ validate(aType: string, axbType: string, bType: string, data: unknown, scopePath?: string): void;
281
320
  lookup(aType: string, axbType: string, bType: string): RegistryEntry | undefined;
282
321
  entries(): ReadonlyArray<RegistryEntry>;
283
322
  }
@@ -302,6 +341,21 @@ interface GraphClient extends GraphReader, GraphWriter {
302
341
  removeNodeCascade(uid: string, options?: BulkOptions): Promise<CascadeResult>;
303
342
  /** Find all edges matching `params` and delete them in chunked batches. */
304
343
  bulkRemoveEdges(params: FindEdgesParams, options?: BulkOptions): Promise<BulkResult>;
344
+ /**
345
+ * Create a scoped client for a Firestore subcollection under the given
346
+ * parent node's document.
347
+ *
348
+ * The returned client shares a snapshot of the parent's registry at
349
+ * the time of this call. If the parent is a `DynamicGraphClient` and
350
+ * `reloadRegistry()` is called later, existing subgraph clients will
351
+ * NOT see the updated types — create a new subgraph client after
352
+ * reloading to pick up changes.
353
+ *
354
+ * @param parentNodeUid - UID of the parent node whose document owns the subcollection
355
+ * @param name - Subcollection name (defaults to `'graph'`). Must not contain `/`.
356
+ * @returns A `GraphClient` scoped to `{collectionPath}/{parentNodeUid}/{name}`
357
+ */
358
+ subgraph(parentNodeUid: string, name?: string): GraphClient;
305
359
  }
306
360
  interface DynamicGraphClient extends GraphClient {
307
361
  /** Define or update a node type in the dynamic registry. */
@@ -357,6 +411,11 @@ interface BulkOptions {
357
411
  maxRetries?: number;
358
412
  /** Called after each batch commits. */
359
413
  onProgress?: (progress: BulkProgress) => void;
414
+ /**
415
+ * Recursively delete subcollections (subgraphs) under the node's document.
416
+ * Defaults to `true` for `removeNodeCascade`.
417
+ */
418
+ deleteSubcollections?: boolean;
360
419
  }
361
420
  interface BulkProgress {
362
421
  /** Batches committed so far. */
@@ -411,4 +470,4 @@ interface CodegenOptions {
411
470
  */
412
471
  declare function generateTypes(discovery: DiscoveryResult, options?: CodegenOptions): Promise<string>;
413
472
 
414
- export { defineConfig as A, type BulkBatchError as B, type CascadeResult as C, type DynamicRegistryConfig as D, type EdgeTopology as E, type FindEdgesParams as F, type GraphClientOptions as G, type HopDefinition as H, generateTypes as I, resolveView as J, type NodeTypeData as N, type QueryPlan as Q, type RegistryEntry as R, type StoredGraphRecord as S, type TraversalBuilder as T, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type DiscoveryResult as c, type GraphRegistry as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type BulkOptions as h, type BulkProgress as i, type BulkResult as j, type CodegenOptions as k, type DefineTypeOptions as l, type DiscoveredEntity as m, type EdgeTypeData as n, type FiregraphConfig as o, type GraphBatch as p, type GraphTransaction as q, type GraphWriter as r, type HopResult as s, type QueryFilter as t, type QueryMode as u, type QueryOptions as v, type TraversalOptions as w, type TraversalResult as x, type ViewDefaultsConfig as y, type ViewResolverConfig as z };
473
+ export { type ViewResolverConfig as A, type BulkBatchError as B, type CascadeResult as C, type DynamicRegistryConfig as D, type EdgeTopology as E, type FindEdgesParams as F, type GraphClientOptions as G, type HopDefinition as H, defineConfig as I, generateTypes as J, resolveView as K, type NodeTypeData as N, type QueryPlan as Q, type RegistryEntry as R, type ScanProtection as S, type TraversalBuilder as T, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type DiscoveryResult as c, type GraphRegistry as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type QueryFilter as h, type BulkOptions as i, type BulkProgress as j, type BulkResult as k, type CodegenOptions as l, type DefineTypeOptions as m, type DiscoveredEntity as n, type EdgeTypeData as o, type FiregraphConfig as p, type GraphBatch as q, type GraphTransaction as r, type GraphWriter as s, type HopResult as t, type QueryMode as u, type QueryOptions as v, type StoredGraphRecord as w, type TraversalOptions as x, type TraversalResult as y, type ViewDefaultsConfig as z };