@typicalday/firegraph 0.2.0 → 0.4.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/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Firestore } from '@google-cloud/firestore';
2
- import { G as GraphClientOptions, D as DynamicRegistryConfig, a as DynamicGraphClient, b as GraphClient, R as RegistryEntry, c as DiscoveryResult, d as GraphRegistry, e as GraphReader, f as GraphRecord, F as FindEdgesParams, Q as QueryPlan, g as FindNodesParams, T as TraversalBuilder, h as QueryFilter } from './index-wSlVH5Nv.cjs';
3
- export { B as BulkBatchError, i as BulkOptions, j as BulkProgress, k as BulkResult, C as CascadeResult, l as CodegenOptions, m as DefineTypeOptions, n as DiscoveredEntity, E as EdgeTopology, o as EdgeTypeData, p as FiregraphConfig, q as GraphBatch, r as GraphTransaction, s as GraphWriter, H as HopDefinition, t as HopResult, N as NodeTypeData, u as QueryMode, v as QueryOptions, S as ScanProtection, w as StoredGraphRecord, x as TraversalOptions, y as TraversalResult, V as ViewContext, z as ViewDefaultsConfig, A as ViewResolverConfig, W as WhereClause, I as defineConfig, J as generateTypes, K as resolveView } from './index-wSlVH5Nv.cjs';
2
+ import { G as GraphClientOptions, D as DynamicRegistryConfig, a as DynamicGraphClient, b as GraphClient, c as GraphRegistry, R as RegistryEntry, d as DiscoveryResult, e as GraphReader, f as GraphRecord, F as FindEdgesParams, Q as QueryPlan, g as FindNodesParams, T as TraversalBuilder, h as QueryFilter } from './index-DR3jF5_b.cjs';
3
+ export { B as BulkBatchError, i as BulkOptions, j as BulkProgress, k as BulkResult, C as CascadeResult, l as CodegenOptions, m as DefineTypeOptions, n as DiscoveredEntity, E as EdgeTopology, o as EdgeTypeData, p as FiregraphConfig, q as GraphBatch, r as GraphTransaction, s as GraphWriter, H as HopDefinition, t as HopResult, N as NodeTypeData, u as QueryMode, v as QueryOptions, S as ScanProtection, w as StoredGraphRecord, x as TraversalOptions, y as TraversalResult, V as ViewContext, z as ViewDefaultsConfig, A as ViewResolverConfig, W as WhereClause, I as defineConfig, J as generateTypes, K as resolveView } from './index-DR3jF5_b.cjs';
4
4
  export { E as EntityViewConfig, a as EntityViewMeta, V as ViewComponentClass, b as ViewMeta, c as ViewRegistry, d as ViewRegistryInput, e as defineViews } from './views-DL60k0cf.cjs';
5
5
  export { Q as QueryClient, a as QueryClientError, b as QueryClientErrorCode, c as QueryClientOptions } from './client-Bk2Cm6xv.cjs';
6
6
 
@@ -26,6 +26,17 @@ declare function createGraphClient(db: Firestore, collectionPath: string, option
26
26
  * ```
27
27
  */
28
28
  declare function createRegistry(input: RegistryEntry[] | DiscoveryResult): GraphRegistry;
29
+ /**
30
+ * Create a merged registry where `base` entries take priority and `extension`
31
+ * entries fill in gaps. Lookups and validation check `base` first; only if the
32
+ * triple is not found there does the merged registry fall through to
33
+ * `extension`.
34
+ *
35
+ * The `entries()` method returns a deduplicated list (base wins on collision).
36
+ * The `lookupByAxbType()` method merges results from both registries,
37
+ * deduplicating by triple key with base entries winning.
38
+ */
39
+ declare function createMergedRegistry(base: GraphRegistry, extension: GraphRegistry): GraphRegistry;
29
40
 
30
41
  /** The aType used for node type definition meta-nodes. */
31
42
  declare const META_NODE_TYPE = "nodeType";
@@ -71,7 +82,18 @@ declare function buildEdgeRecord(aType: string, aUid: string, axbType: string, b
71
82
  declare function buildEdgeQueryPlan(params: FindEdgesParams): QueryPlan;
72
83
  declare function buildNodeQueryPlan(params: FindNodesParams): QueryPlan;
73
84
 
74
- declare function createTraversal(reader: GraphReader, startUid: string): TraversalBuilder;
85
+ /**
86
+ * Create a traversal builder for multi-hop graph traversal.
87
+ *
88
+ * Accepts either a `GraphReader` (backwards compatible) or a `GraphClient`.
89
+ * When a `GraphClient` is provided, cross-graph traversal via `targetGraph`
90
+ * is supported — the traversal can follow edges into subgraphs.
91
+ *
92
+ * @param reader - A `GraphClient` or `GraphReader` to execute queries against
93
+ * @param startUid - UID of the starting node
94
+ * @param registry - Optional registry for automatic `targetGraph` resolution
95
+ */
96
+ declare function createTraversal(reader: GraphClient | GraphReader, startUid: string, registry?: GraphRegistry): TraversalBuilder;
75
97
 
76
98
  declare class FiregraphError extends Error {
77
99
  readonly code: string;
@@ -187,6 +209,52 @@ declare function matchScope(scopePath: string, pattern: string): boolean;
187
209
  */
188
210
  declare function matchScopeAny(scopePath: string, patterns: string[]): boolean;
189
211
 
212
+ /**
213
+ * Cross-graph edge resolution utilities.
214
+ *
215
+ * Provides path-scanning resolution for determining whether an edge's source
216
+ * (aUid) is an ancestor node by checking if the UID appears in the Firestore
217
+ * collection path.
218
+ *
219
+ * Firestore paths have a rigid alternating structure:
220
+ * collection / docId / collection / docId / collection
221
+ *
222
+ * Given a path like `graph/A/workspace/B/context`, segments at even indices
223
+ * are collection names and odd indices are document IDs. When we find a UID
224
+ * at an odd index, the collection containing that document is the path up to
225
+ * (and including) the preceding even-index segment.
226
+ */
227
+ /**
228
+ * Parse a Firestore collection path and determine the collection path
229
+ * where a given UID's document lives, if that UID is an ancestor in the path.
230
+ *
231
+ * @param collectionPath - The full Firestore collection path of the current client
232
+ * @param uid - The UID to search for in the path
233
+ * @returns The collection path containing the UID, or `null` if not found in the path
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * // Path: graph/A/workspace/B/context
238
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'A')
239
+ * // → 'graph'
240
+ *
241
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'B')
242
+ * // → 'graph/A/workspace'
243
+ *
244
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'unknown')
245
+ * // → null
246
+ * ```
247
+ */
248
+ declare function resolveAncestorCollection(collectionPath: string, uid: string): string | null;
249
+ /**
250
+ * Check whether a UID belongs to an ancestor node by scanning the collection path.
251
+ *
252
+ * @param collectionPath - The full Firestore collection path of the current client
253
+ * @param uid - The UID to check
254
+ * @returns `true` if the UID appears as a document segment in the path
255
+ */
256
+ declare function isAncestorUid(collectionPath: string, uid: string): boolean;
257
+
190
258
  /**
191
259
  * JSON Schema validation and introspection utilities.
192
260
  *
@@ -226,7 +294,7 @@ interface FirestoreIndexField {
226
294
  }
227
295
  interface FirestoreIndex {
228
296
  collectionGroup: string;
229
- queryScope: 'COLLECTION';
297
+ queryScope: 'COLLECTION' | 'COLLECTION_GROUP';
230
298
  fields: FirestoreIndexField[];
231
299
  }
232
300
  interface FirestoreIndexConfig {
@@ -241,10 +309,17 @@ interface FirestoreIndexConfig {
241
309
  * patterns on node data fields:
242
310
  * (aType, axbType, data.{field})
243
311
  *
312
+ * When registry entries with `targetGraph` are provided, also generates
313
+ * collection group indexes for `findEdgesGlobal()` queries. The collection
314
+ * group name defaults to `'graph'` (the standard subgraph name) but can be
315
+ * overridden per `targetGraph` value.
316
+ *
244
317
  * @param collection - Firestore collection name (e.g. 'graph')
245
318
  * @param entities - Optional discovery result for per-entity data field indexes
319
+ * @param registryEntries - Optional registry entries; when any have `targetGraph`,
320
+ * collection group indexes are generated for the distinct subgraph names
246
321
  */
247
- declare function generateIndexConfig(collection: string, entities?: DiscoveryResult): FirestoreIndexConfig;
322
+ declare function generateIndexConfig(collection: string, entities?: DiscoveryResult, registryEntries?: ReadonlyArray<RegistryEntry>): FirestoreIndexConfig;
248
323
 
249
324
  /**
250
325
  * Result of analyzing a query for collection scan risk.
@@ -272,4 +347,4 @@ declare function analyzeQuerySafety(filters: QueryFilter[]): QuerySafetyResult;
272
347
  */
273
348
  declare const DEFAULT_QUERY_LIMIT = 500;
274
349
 
275
- export { BOOTSTRAP_ENTRIES, DEFAULT_QUERY_LIMIT, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, type FirestoreIndex, type FirestoreIndexConfig, type FirestoreIndexField, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryFilter, QueryPlan, QuerySafetyError, type QuerySafetyResult, RegistryEntry, RegistryScopeError, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, analyzeQuerySafety, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, generateIndexConfig, jsonSchemaToFieldMeta, matchScope, matchScopeAny };
350
+ export { BOOTSTRAP_ENTRIES, DEFAULT_QUERY_LIMIT, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, type FirestoreIndex, type FirestoreIndexConfig, type FirestoreIndexField, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryFilter, QueryPlan, QuerySafetyError, type QuerySafetyResult, RegistryEntry, RegistryScopeError, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, analyzeQuerySafety, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createMergedRegistry, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, generateIndexConfig, isAncestorUid, jsonSchemaToFieldMeta, matchScope, matchScopeAny, resolveAncestorCollection };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Firestore } from '@google-cloud/firestore';
2
- import { G as GraphClientOptions, D as DynamicRegistryConfig, a as DynamicGraphClient, b as GraphClient, R as RegistryEntry, c as DiscoveryResult, d as GraphRegistry, e as GraphReader, f as GraphRecord, F as FindEdgesParams, Q as QueryPlan, g as FindNodesParams, T as TraversalBuilder, h as QueryFilter } from './index-wSlVH5Nv.js';
3
- export { B as BulkBatchError, i as BulkOptions, j as BulkProgress, k as BulkResult, C as CascadeResult, l as CodegenOptions, m as DefineTypeOptions, n as DiscoveredEntity, E as EdgeTopology, o as EdgeTypeData, p as FiregraphConfig, q as GraphBatch, r as GraphTransaction, s as GraphWriter, H as HopDefinition, t as HopResult, N as NodeTypeData, u as QueryMode, v as QueryOptions, S as ScanProtection, w as StoredGraphRecord, x as TraversalOptions, y as TraversalResult, V as ViewContext, z as ViewDefaultsConfig, A as ViewResolverConfig, W as WhereClause, I as defineConfig, J as generateTypes, K as resolveView } from './index-wSlVH5Nv.js';
2
+ import { G as GraphClientOptions, D as DynamicRegistryConfig, a as DynamicGraphClient, b as GraphClient, c as GraphRegistry, R as RegistryEntry, d as DiscoveryResult, e as GraphReader, f as GraphRecord, F as FindEdgesParams, Q as QueryPlan, g as FindNodesParams, T as TraversalBuilder, h as QueryFilter } from './index-DR3jF5_b.js';
3
+ export { B as BulkBatchError, i as BulkOptions, j as BulkProgress, k as BulkResult, C as CascadeResult, l as CodegenOptions, m as DefineTypeOptions, n as DiscoveredEntity, E as EdgeTopology, o as EdgeTypeData, p as FiregraphConfig, q as GraphBatch, r as GraphTransaction, s as GraphWriter, H as HopDefinition, t as HopResult, N as NodeTypeData, u as QueryMode, v as QueryOptions, S as ScanProtection, w as StoredGraphRecord, x as TraversalOptions, y as TraversalResult, V as ViewContext, z as ViewDefaultsConfig, A as ViewResolverConfig, W as WhereClause, I as defineConfig, J as generateTypes, K as resolveView } from './index-DR3jF5_b.js';
4
4
  export { E as EntityViewConfig, a as EntityViewMeta, V as ViewComponentClass, b as ViewMeta, c as ViewRegistry, d as ViewRegistryInput, e as defineViews } from './views-DL60k0cf.js';
5
5
  export { Q as QueryClient, a as QueryClientError, b as QueryClientErrorCode, c as QueryClientOptions } from './client-Bk2Cm6xv.js';
6
6
 
@@ -26,6 +26,17 @@ declare function createGraphClient(db: Firestore, collectionPath: string, option
26
26
  * ```
27
27
  */
28
28
  declare function createRegistry(input: RegistryEntry[] | DiscoveryResult): GraphRegistry;
29
+ /**
30
+ * Create a merged registry where `base` entries take priority and `extension`
31
+ * entries fill in gaps. Lookups and validation check `base` first; only if the
32
+ * triple is not found there does the merged registry fall through to
33
+ * `extension`.
34
+ *
35
+ * The `entries()` method returns a deduplicated list (base wins on collision).
36
+ * The `lookupByAxbType()` method merges results from both registries,
37
+ * deduplicating by triple key with base entries winning.
38
+ */
39
+ declare function createMergedRegistry(base: GraphRegistry, extension: GraphRegistry): GraphRegistry;
29
40
 
30
41
  /** The aType used for node type definition meta-nodes. */
31
42
  declare const META_NODE_TYPE = "nodeType";
@@ -71,7 +82,18 @@ declare function buildEdgeRecord(aType: string, aUid: string, axbType: string, b
71
82
  declare function buildEdgeQueryPlan(params: FindEdgesParams): QueryPlan;
72
83
  declare function buildNodeQueryPlan(params: FindNodesParams): QueryPlan;
73
84
 
74
- declare function createTraversal(reader: GraphReader, startUid: string): TraversalBuilder;
85
+ /**
86
+ * Create a traversal builder for multi-hop graph traversal.
87
+ *
88
+ * Accepts either a `GraphReader` (backwards compatible) or a `GraphClient`.
89
+ * When a `GraphClient` is provided, cross-graph traversal via `targetGraph`
90
+ * is supported — the traversal can follow edges into subgraphs.
91
+ *
92
+ * @param reader - A `GraphClient` or `GraphReader` to execute queries against
93
+ * @param startUid - UID of the starting node
94
+ * @param registry - Optional registry for automatic `targetGraph` resolution
95
+ */
96
+ declare function createTraversal(reader: GraphClient | GraphReader, startUid: string, registry?: GraphRegistry): TraversalBuilder;
75
97
 
76
98
  declare class FiregraphError extends Error {
77
99
  readonly code: string;
@@ -187,6 +209,52 @@ declare function matchScope(scopePath: string, pattern: string): boolean;
187
209
  */
188
210
  declare function matchScopeAny(scopePath: string, patterns: string[]): boolean;
189
211
 
212
+ /**
213
+ * Cross-graph edge resolution utilities.
214
+ *
215
+ * Provides path-scanning resolution for determining whether an edge's source
216
+ * (aUid) is an ancestor node by checking if the UID appears in the Firestore
217
+ * collection path.
218
+ *
219
+ * Firestore paths have a rigid alternating structure:
220
+ * collection / docId / collection / docId / collection
221
+ *
222
+ * Given a path like `graph/A/workspace/B/context`, segments at even indices
223
+ * are collection names and odd indices are document IDs. When we find a UID
224
+ * at an odd index, the collection containing that document is the path up to
225
+ * (and including) the preceding even-index segment.
226
+ */
227
+ /**
228
+ * Parse a Firestore collection path and determine the collection path
229
+ * where a given UID's document lives, if that UID is an ancestor in the path.
230
+ *
231
+ * @param collectionPath - The full Firestore collection path of the current client
232
+ * @param uid - The UID to search for in the path
233
+ * @returns The collection path containing the UID, or `null` if not found in the path
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * // Path: graph/A/workspace/B/context
238
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'A')
239
+ * // → 'graph'
240
+ *
241
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'B')
242
+ * // → 'graph/A/workspace'
243
+ *
244
+ * resolveAncestorCollection('graph/A/workspace/B/context', 'unknown')
245
+ * // → null
246
+ * ```
247
+ */
248
+ declare function resolveAncestorCollection(collectionPath: string, uid: string): string | null;
249
+ /**
250
+ * Check whether a UID belongs to an ancestor node by scanning the collection path.
251
+ *
252
+ * @param collectionPath - The full Firestore collection path of the current client
253
+ * @param uid - The UID to check
254
+ * @returns `true` if the UID appears as a document segment in the path
255
+ */
256
+ declare function isAncestorUid(collectionPath: string, uid: string): boolean;
257
+
190
258
  /**
191
259
  * JSON Schema validation and introspection utilities.
192
260
  *
@@ -226,7 +294,7 @@ interface FirestoreIndexField {
226
294
  }
227
295
  interface FirestoreIndex {
228
296
  collectionGroup: string;
229
- queryScope: 'COLLECTION';
297
+ queryScope: 'COLLECTION' | 'COLLECTION_GROUP';
230
298
  fields: FirestoreIndexField[];
231
299
  }
232
300
  interface FirestoreIndexConfig {
@@ -241,10 +309,17 @@ interface FirestoreIndexConfig {
241
309
  * patterns on node data fields:
242
310
  * (aType, axbType, data.{field})
243
311
  *
312
+ * When registry entries with `targetGraph` are provided, also generates
313
+ * collection group indexes for `findEdgesGlobal()` queries. The collection
314
+ * group name defaults to `'graph'` (the standard subgraph name) but can be
315
+ * overridden per `targetGraph` value.
316
+ *
244
317
  * @param collection - Firestore collection name (e.g. 'graph')
245
318
  * @param entities - Optional discovery result for per-entity data field indexes
319
+ * @param registryEntries - Optional registry entries; when any have `targetGraph`,
320
+ * collection group indexes are generated for the distinct subgraph names
246
321
  */
247
- declare function generateIndexConfig(collection: string, entities?: DiscoveryResult): FirestoreIndexConfig;
322
+ declare function generateIndexConfig(collection: string, entities?: DiscoveryResult, registryEntries?: ReadonlyArray<RegistryEntry>): FirestoreIndexConfig;
248
323
 
249
324
  /**
250
325
  * Result of analyzing a query for collection scan risk.
@@ -272,4 +347,4 @@ declare function analyzeQuerySafety(filters: QueryFilter[]): QuerySafetyResult;
272
347
  */
273
348
  declare const DEFAULT_QUERY_LIMIT = 500;
274
349
 
275
- export { BOOTSTRAP_ENTRIES, DEFAULT_QUERY_LIMIT, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, type FirestoreIndex, type FirestoreIndexConfig, type FirestoreIndexField, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryFilter, QueryPlan, QuerySafetyError, type QuerySafetyResult, RegistryEntry, RegistryScopeError, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, analyzeQuerySafety, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, generateIndexConfig, jsonSchemaToFieldMeta, matchScope, matchScopeAny };
350
+ export { BOOTSTRAP_ENTRIES, DEFAULT_QUERY_LIMIT, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, type FirestoreIndex, type FirestoreIndexConfig, type FirestoreIndexField, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryFilter, QueryPlan, QuerySafetyError, type QuerySafetyResult, RegistryEntry, RegistryScopeError, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, analyzeQuerySafety, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createMergedRegistry, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, generateIndexConfig, isAncestorUid, jsonSchemaToFieldMeta, matchScope, matchScopeAny, resolveAncestorCollection };