@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.
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 } from './index-CG3R68Hu.cjs';
3
- export { B as BulkBatchError, h as BulkOptions, i as BulkProgress, j as BulkResult, C as CascadeResult, k as CodegenOptions, l as DefineTypeOptions, m as DiscoveredEntity, E as EdgeTopology, n as EdgeTypeData, o as FiregraphConfig, p as GraphBatch, q as GraphTransaction, r as GraphWriter, H as HopDefinition, s as HopResult, N as NodeTypeData, t as QueryFilter, u as QueryMode, v as QueryOptions, S as StoredGraphRecord, w as TraversalOptions, x as TraversalResult, V as ViewContext, y as ViewDefaultsConfig, z as ViewResolverConfig, W as WhereClause, A as defineConfig, I as generateTypes, J as resolveView } from './index-CG3R68Hu.cjs';
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';
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
 
@@ -99,6 +99,12 @@ declare class TraversalError extends FiregraphError {
99
99
  declare class DynamicRegistryError extends FiregraphError {
100
100
  constructor(message: string);
101
101
  }
102
+ declare class QuerySafetyError extends FiregraphError {
103
+ constructor(message: string);
104
+ }
105
+ declare class RegistryScopeError extends FiregraphError {
106
+ constructor(aType: string, axbType: string, bType: string, scopePath: string, allowedIn: string[]);
107
+ }
102
108
 
103
109
  /**
104
110
  * Entity Discovery — convention-based auto-discovery of entities from
@@ -150,6 +156,37 @@ interface DiscoverResult {
150
156
  */
151
157
  declare function discoverEntities(entitiesDir: string): DiscoverResult;
152
158
 
159
+ /**
160
+ * Scope path matching for subgraph-level registry constraints.
161
+ *
162
+ * Scope paths are slash-separated names derived from the chain of
163
+ * `subgraph()` calls (e.g., `'agents'`, `'agents/memories'`).
164
+ * The root graph has an empty scope path (`''`).
165
+ *
166
+ * Patterns:
167
+ * - `'root'` — matches only the root graph (empty scope path)
168
+ * - `'agents'` — matches exactly `'agents'`
169
+ * - `'agents/memories'` — matches exactly `'agents/memories'`
170
+ * - `'*​/agents'` — `*` matches one segment: `'foo/agents'` but not `'a/b/agents'`
171
+ * - `'**​/memories'` — `**` matches zero or more segments
172
+ * - `'**'` — matches everything including root
173
+ */
174
+ /**
175
+ * Test whether a scope path matches a single pattern.
176
+ *
177
+ * @param scopePath - The current scope path (empty string for root)
178
+ * @param pattern - The pattern to match against
179
+ */
180
+ declare function matchScope(scopePath: string, pattern: string): boolean;
181
+ /**
182
+ * Test whether a scope path matches any pattern in a list.
183
+ * Returns `true` if the list is empty or undefined (allowed everywhere).
184
+ *
185
+ * @param scopePath - The current scope path (empty string for root)
186
+ * @param patterns - Array of patterns to match against
187
+ */
188
+ declare function matchScopeAny(scopePath: string, patterns: string[]): boolean;
189
+
153
190
  /**
154
191
  * JSON Schema validation and introspection utilities.
155
192
  *
@@ -183,4 +220,56 @@ declare function compileSchema(schema: object, label?: string): (data: unknown)
183
220
  */
184
221
  declare function jsonSchemaToFieldMeta(schema: any): FieldMeta[];
185
222
 
186
- export { BOOTSTRAP_ENTRIES, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryPlan, RegistryEntry, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, jsonSchemaToFieldMeta };
223
+ interface FirestoreIndexField {
224
+ fieldPath: string;
225
+ order: 'ASCENDING' | 'DESCENDING';
226
+ }
227
+ interface FirestoreIndex {
228
+ collectionGroup: string;
229
+ queryScope: 'COLLECTION';
230
+ fields: FirestoreIndexField[];
231
+ }
232
+ interface FirestoreIndexConfig {
233
+ indexes: FirestoreIndex[];
234
+ fieldOverrides: unknown[];
235
+ }
236
+ /**
237
+ * Generates a Firestore index configuration for a firegraph collection.
238
+ *
239
+ * Always includes the 4 base composite indexes. If an entity discovery result
240
+ * is provided, generates additional data-field indexes for common query
241
+ * patterns on node data fields:
242
+ * (aType, axbType, data.{field})
243
+ *
244
+ * @param collection - Firestore collection name (e.g. 'graph')
245
+ * @param entities - Optional discovery result for per-entity data field indexes
246
+ */
247
+ declare function generateIndexConfig(collection: string, entities?: DiscoveryResult): FirestoreIndexConfig;
248
+
249
+ /**
250
+ * Result of analyzing a query for collection scan risk.
251
+ */
252
+ interface QuerySafetyResult {
253
+ /** Whether the query matches a known indexed pattern. */
254
+ safe: boolean;
255
+ /** Human-readable explanation when the query is unsafe. */
256
+ reason?: string;
257
+ }
258
+ /**
259
+ * Analyzes a set of query filters to determine whether the query would
260
+ * likely cause a full collection scan on Firestore Enterprise.
261
+ *
262
+ * A query is considered "safe" if the builtin fields present in the filters
263
+ * match at least one known composite index pattern. Queries that only use
264
+ * `data.*` fields without a safe base pattern are flagged as unsafe.
265
+ */
266
+ declare function analyzeQuerySafety(filters: QueryFilter[]): QuerySafetyResult;
267
+
268
+ /**
269
+ * Default result limit applied to findEdges/findNodes queries
270
+ * when no explicit limit is provided. Prevents unbounded result sets
271
+ * that could be expensive on Enterprise Firestore.
272
+ */
273
+ declare const DEFAULT_QUERY_LIMIT = 500;
274
+
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 };
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 } from './index-CG3R68Hu.js';
3
- export { B as BulkBatchError, h as BulkOptions, i as BulkProgress, j as BulkResult, C as CascadeResult, k as CodegenOptions, l as DefineTypeOptions, m as DiscoveredEntity, E as EdgeTopology, n as EdgeTypeData, o as FiregraphConfig, p as GraphBatch, q as GraphTransaction, r as GraphWriter, H as HopDefinition, s as HopResult, N as NodeTypeData, t as QueryFilter, u as QueryMode, v as QueryOptions, S as StoredGraphRecord, w as TraversalOptions, x as TraversalResult, V as ViewContext, y as ViewDefaultsConfig, z as ViewResolverConfig, W as WhereClause, A as defineConfig, I as generateTypes, J as resolveView } from './index-CG3R68Hu.js';
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';
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
 
@@ -99,6 +99,12 @@ declare class TraversalError extends FiregraphError {
99
99
  declare class DynamicRegistryError extends FiregraphError {
100
100
  constructor(message: string);
101
101
  }
102
+ declare class QuerySafetyError extends FiregraphError {
103
+ constructor(message: string);
104
+ }
105
+ declare class RegistryScopeError extends FiregraphError {
106
+ constructor(aType: string, axbType: string, bType: string, scopePath: string, allowedIn: string[]);
107
+ }
102
108
 
103
109
  /**
104
110
  * Entity Discovery — convention-based auto-discovery of entities from
@@ -150,6 +156,37 @@ interface DiscoverResult {
150
156
  */
151
157
  declare function discoverEntities(entitiesDir: string): DiscoverResult;
152
158
 
159
+ /**
160
+ * Scope path matching for subgraph-level registry constraints.
161
+ *
162
+ * Scope paths are slash-separated names derived from the chain of
163
+ * `subgraph()` calls (e.g., `'agents'`, `'agents/memories'`).
164
+ * The root graph has an empty scope path (`''`).
165
+ *
166
+ * Patterns:
167
+ * - `'root'` — matches only the root graph (empty scope path)
168
+ * - `'agents'` — matches exactly `'agents'`
169
+ * - `'agents/memories'` — matches exactly `'agents/memories'`
170
+ * - `'*​/agents'` — `*` matches one segment: `'foo/agents'` but not `'a/b/agents'`
171
+ * - `'**​/memories'` — `**` matches zero or more segments
172
+ * - `'**'` — matches everything including root
173
+ */
174
+ /**
175
+ * Test whether a scope path matches a single pattern.
176
+ *
177
+ * @param scopePath - The current scope path (empty string for root)
178
+ * @param pattern - The pattern to match against
179
+ */
180
+ declare function matchScope(scopePath: string, pattern: string): boolean;
181
+ /**
182
+ * Test whether a scope path matches any pattern in a list.
183
+ * Returns `true` if the list is empty or undefined (allowed everywhere).
184
+ *
185
+ * @param scopePath - The current scope path (empty string for root)
186
+ * @param patterns - Array of patterns to match against
187
+ */
188
+ declare function matchScopeAny(scopePath: string, patterns: string[]): boolean;
189
+
153
190
  /**
154
191
  * JSON Schema validation and introspection utilities.
155
192
  *
@@ -183,4 +220,56 @@ declare function compileSchema(schema: object, label?: string): (data: unknown)
183
220
  */
184
221
  declare function jsonSchemaToFieldMeta(schema: any): FieldMeta[];
185
222
 
186
- export { BOOTSTRAP_ENTRIES, type DiscoverResult, DiscoveryError, DiscoveryResult, type DiscoveryWarning, DynamicGraphClient, DynamicRegistryConfig, DynamicRegistryError, EDGE_TYPE_SCHEMA, EdgeNotFoundError, type FieldMeta, FindEdgesParams, FindNodesParams, FiregraphError, GraphClient, GraphClientOptions, GraphReader, GraphRecord, GraphRegistry, InvalidQueryError, META_EDGE_TYPE, META_NODE_TYPE, NODE_TYPE_SCHEMA, NodeNotFoundError, QueryPlan, RegistryEntry, RegistryViolationError, TraversalBuilder, TraversalError, ValidationError, buildEdgeQueryPlan, buildEdgeRecord, buildNodeQueryPlan, buildNodeRecord, compileSchema, computeEdgeDocId, computeNodeDocId, createBootstrapRegistry, createGraphClient, createRegistry, createRegistryFromGraph, createTraversal, discoverEntities, generateDeterministicUid, generateId, jsonSchemaToFieldMeta };
223
+ interface FirestoreIndexField {
224
+ fieldPath: string;
225
+ order: 'ASCENDING' | 'DESCENDING';
226
+ }
227
+ interface FirestoreIndex {
228
+ collectionGroup: string;
229
+ queryScope: 'COLLECTION';
230
+ fields: FirestoreIndexField[];
231
+ }
232
+ interface FirestoreIndexConfig {
233
+ indexes: FirestoreIndex[];
234
+ fieldOverrides: unknown[];
235
+ }
236
+ /**
237
+ * Generates a Firestore index configuration for a firegraph collection.
238
+ *
239
+ * Always includes the 4 base composite indexes. If an entity discovery result
240
+ * is provided, generates additional data-field indexes for common query
241
+ * patterns on node data fields:
242
+ * (aType, axbType, data.{field})
243
+ *
244
+ * @param collection - Firestore collection name (e.g. 'graph')
245
+ * @param entities - Optional discovery result for per-entity data field indexes
246
+ */
247
+ declare function generateIndexConfig(collection: string, entities?: DiscoveryResult): FirestoreIndexConfig;
248
+
249
+ /**
250
+ * Result of analyzing a query for collection scan risk.
251
+ */
252
+ interface QuerySafetyResult {
253
+ /** Whether the query matches a known indexed pattern. */
254
+ safe: boolean;
255
+ /** Human-readable explanation when the query is unsafe. */
256
+ reason?: string;
257
+ }
258
+ /**
259
+ * Analyzes a set of query filters to determine whether the query would
260
+ * likely cause a full collection scan on Firestore Enterprise.
261
+ *
262
+ * A query is considered "safe" if the builtin fields present in the filters
263
+ * match at least one known composite index pattern. Queries that only use
264
+ * `data.*` fields without a safe base pattern are flagged as unsafe.
265
+ */
266
+ declare function analyzeQuerySafety(filters: QueryFilter[]): QuerySafetyResult;
267
+
268
+ /**
269
+ * Default result limit applied to findEdges/findNodes queries
270
+ * when no explicit limit is provided. Prevents unbounded result sets
271
+ * that could be expensive on Enterprise Firestore.
272
+ */
273
+ declare const DEFAULT_QUERY_LIMIT = 500;
274
+
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 };