@typicalday/firegraph 0.4.0 → 0.5.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.
@@ -113,6 +113,8 @@ interface GraphRecord {
113
113
  data: Record<string, unknown>;
114
114
  createdAt: Timestamp | FieldValue;
115
115
  updatedAt: Timestamp | FieldValue;
116
+ /** Schema version — set automatically when the registry entry has migrations. */
117
+ v?: number;
116
118
  }
117
119
  interface StoredGraphRecord {
118
120
  aType: string;
@@ -123,6 +125,8 @@ interface StoredGraphRecord {
123
125
  data: Record<string, unknown>;
124
126
  createdAt: Timestamp;
125
127
  updatedAt: Timestamp;
128
+ /** Schema version — set automatically when the registry entry has migrations. */
129
+ v?: number;
126
130
  }
127
131
  interface WhereClause {
128
132
  field: string;
@@ -175,6 +179,45 @@ interface QueryFilter {
175
179
  op: WhereFilterOp;
176
180
  value: unknown;
177
181
  }
182
+ /**
183
+ * An executable migration function that transforms data from one schema
184
+ * version to the next. Can be synchronous or asynchronous.
185
+ */
186
+ type MigrationFn = (data: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
187
+ /**
188
+ * A single migration step in a registry entry.
189
+ * Transforms data from `fromVersion` to `toVersion`.
190
+ */
191
+ interface MigrationStep {
192
+ fromVersion: number;
193
+ toVersion: number;
194
+ up: MigrationFn;
195
+ }
196
+ /**
197
+ * A stored migration step for dynamic registry types.
198
+ * The `up` field is a source code string that will be compiled at runtime.
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * { fromVersion: 0, toVersion: 1, up: "(data) => ({ ...data, status: 'draft' })" }
203
+ * ```
204
+ */
205
+ interface StoredMigrationStep {
206
+ fromVersion: number;
207
+ toVersion: number;
208
+ up: string;
209
+ }
210
+ /**
211
+ * Pluggable executor interface for compiling migration function source
212
+ * strings into executable functions. Used for dynamic registry migrations.
213
+ *
214
+ * The default executor uses SES (Secure ECMAScript) Compartments with
215
+ * JSON marshaling for isolation. Users can supply an alternative via
216
+ * `GraphClientOptions.migrationSandbox`.
217
+ */
218
+ type MigrationExecutor = (source: string) => MigrationFn;
219
+ /** Write-back mode for auto-migrated records. */
220
+ type MigrationWriteBack = 'off' | 'eager' | 'background';
178
221
  interface RegistryEntry {
179
222
  aType: string;
180
223
  axbType: string;
@@ -220,6 +263,24 @@ interface RegistryEntry {
220
263
  * ```
221
264
  */
222
265
  targetGraph?: string;
266
+ /**
267
+ * Schema version for this type's data payload.
268
+ * **Computed automatically** from `migrations` as `max(toVersion)`.
269
+ * Do not set directly — provide migrations instead.
270
+ */
271
+ schemaVersion?: number;
272
+ /**
273
+ * Ordered list of migrations to transform data from older versions
274
+ * to the current version. The schema version is derived as the highest
275
+ * `toVersion` in this array.
276
+ */
277
+ migrations?: MigrationStep[];
278
+ /**
279
+ * Per-entry write-back override for auto-migrated records.
280
+ * Takes precedence over `GraphClientOptions.migrationWriteBack`.
281
+ * Omit to inherit the global setting.
282
+ */
283
+ migrationWriteBack?: MigrationWriteBack;
223
284
  }
224
285
  /** Topology declaration for an edge (from edge.json). */
225
286
  interface EdgeTopology {
@@ -255,6 +316,10 @@ interface DiscoveredEntity {
255
316
  allowedIn?: string[];
256
317
  /** Subgraph name where cross-graph edges of this type live. */
257
318
  targetGraph?: string;
319
+ /** Migration steps loaded from migrations.ts. */
320
+ migrations?: MigrationStep[];
321
+ /** Per-entity write-back override from meta.json. */
322
+ migrationWriteBack?: MigrationWriteBack;
258
323
  }
259
324
  /** Result of scanning an entities directory. */
260
325
  interface DiscoveryResult {
@@ -287,6 +352,18 @@ interface DefineTypeOptions {
287
352
  viewCss?: string;
288
353
  /** Scope patterns constraining where this type can exist in subgraphs. */
289
354
  allowedIn?: string[];
355
+ /**
356
+ * Migration steps. Accepts function objects (auto-serialized via .toString())
357
+ * or strings (stored as-is). The schema version is derived as the highest
358
+ * `toVersion` in this array.
359
+ */
360
+ migrations?: Array<{
361
+ fromVersion: number;
362
+ toVersion: number;
363
+ up: MigrationFn | string;
364
+ }>;
365
+ /** Per-type write-back override for auto-migrated records. */
366
+ migrationWriteBack?: MigrationWriteBack;
290
367
  }
291
368
  /** Data shape stored in a `nodeType` meta-node. */
292
369
  interface NodeTypeData {
@@ -298,6 +375,8 @@ interface NodeTypeData {
298
375
  viewTemplate?: string;
299
376
  viewCss?: string;
300
377
  allowedIn?: string[];
378
+ migrations?: StoredMigrationStep[];
379
+ migrationWriteBack?: MigrationWriteBack;
301
380
  }
302
381
  /** Data shape stored in an `edgeType` meta-node. */
303
382
  interface EdgeTypeData {
@@ -313,6 +392,8 @@ interface EdgeTypeData {
313
392
  viewCss?: string;
314
393
  allowedIn?: string[];
315
394
  targetGraph?: string;
395
+ migrations?: StoredMigrationStep[];
396
+ migrationWriteBack?: MigrationWriteBack;
316
397
  }
317
398
  type ScanProtection = 'error' | 'warn' | 'off';
318
399
  interface GraphClientOptions {
@@ -352,6 +433,25 @@ interface GraphClientOptions {
352
433
  * - `'off'` — No scan protection.
353
434
  */
354
435
  scanProtection?: ScanProtection;
436
+ /**
437
+ * Global default for write-back of auto-migrated records on read.
438
+ *
439
+ * - `'off'` (default) — Migrated data is returned but NOT written back.
440
+ * - `'eager'` — Migrated data is written back immediately after migration.
441
+ * - `'background'` — Write-back happens asynchronously; errors are logged.
442
+ *
443
+ * Per-entry `migrationWriteBack` on `RegistryEntry` overrides this setting.
444
+ */
445
+ migrationWriteBack?: MigrationWriteBack;
446
+ /**
447
+ * Custom executor for compiling dynamic registry migration source strings.
448
+ * Defaults to SES Compartments with JSON marshaling. Supply an
449
+ * alternative for custom sandboxing.
450
+ *
451
+ * Only used for dynamic registry migrations — static registry migrations
452
+ * are already in-memory functions and never go through this executor.
453
+ */
454
+ migrationSandbox?: MigrationExecutor;
355
455
  }
356
456
  interface GraphRegistry {
357
457
  validate(aType: string, axbType: string, bType: string, data: unknown, scopePath?: string): void;
@@ -540,4 +640,4 @@ interface CodegenOptions {
540
640
  */
541
641
  declare function generateTypes(discovery: DiscoveryResult, options?: CodegenOptions): Promise<string>;
542
642
 
543
- 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 GraphRegistry as c, type DiscoveryResult 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 };
643
+ export { type ScanProtection 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, type TraversalOptions as I, type TraversalResult as J, type ViewDefaultsConfig as K, type ViewResolverConfig as L, type MigrationExecutor as M, type NodeTypeData as N, defineConfig as O, generateTypes as P, type QueryPlan as Q, type RegistryEntry as R, type StoredMigrationStep as S, type TraversalBuilder as T, resolveView as U, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type GraphRegistry as c, type DiscoveryResult as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type MigrationFn as h, type MigrationStep as i, type StoredGraphRecord as j, type MigrationWriteBack as k, type QueryFilter as l, type BulkOptions as m, type BulkProgress as n, type BulkResult as o, type CodegenOptions as p, type DefineTypeOptions as q, type DiscoveredEntity as r, type EdgeTypeData as s, type FiregraphConfig as t, type GraphBatch as u, type GraphTransaction as v, type GraphWriter as w, type HopResult as x, type QueryMode as y, type QueryOptions as z };
@@ -113,6 +113,8 @@ interface GraphRecord {
113
113
  data: Record<string, unknown>;
114
114
  createdAt: Timestamp | FieldValue;
115
115
  updatedAt: Timestamp | FieldValue;
116
+ /** Schema version — set automatically when the registry entry has migrations. */
117
+ v?: number;
116
118
  }
117
119
  interface StoredGraphRecord {
118
120
  aType: string;
@@ -123,6 +125,8 @@ interface StoredGraphRecord {
123
125
  data: Record<string, unknown>;
124
126
  createdAt: Timestamp;
125
127
  updatedAt: Timestamp;
128
+ /** Schema version — set automatically when the registry entry has migrations. */
129
+ v?: number;
126
130
  }
127
131
  interface WhereClause {
128
132
  field: string;
@@ -175,6 +179,45 @@ interface QueryFilter {
175
179
  op: WhereFilterOp;
176
180
  value: unknown;
177
181
  }
182
+ /**
183
+ * An executable migration function that transforms data from one schema
184
+ * version to the next. Can be synchronous or asynchronous.
185
+ */
186
+ type MigrationFn = (data: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>;
187
+ /**
188
+ * A single migration step in a registry entry.
189
+ * Transforms data from `fromVersion` to `toVersion`.
190
+ */
191
+ interface MigrationStep {
192
+ fromVersion: number;
193
+ toVersion: number;
194
+ up: MigrationFn;
195
+ }
196
+ /**
197
+ * A stored migration step for dynamic registry types.
198
+ * The `up` field is a source code string that will be compiled at runtime.
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * { fromVersion: 0, toVersion: 1, up: "(data) => ({ ...data, status: 'draft' })" }
203
+ * ```
204
+ */
205
+ interface StoredMigrationStep {
206
+ fromVersion: number;
207
+ toVersion: number;
208
+ up: string;
209
+ }
210
+ /**
211
+ * Pluggable executor interface for compiling migration function source
212
+ * strings into executable functions. Used for dynamic registry migrations.
213
+ *
214
+ * The default executor uses SES (Secure ECMAScript) Compartments with
215
+ * JSON marshaling for isolation. Users can supply an alternative via
216
+ * `GraphClientOptions.migrationSandbox`.
217
+ */
218
+ type MigrationExecutor = (source: string) => MigrationFn;
219
+ /** Write-back mode for auto-migrated records. */
220
+ type MigrationWriteBack = 'off' | 'eager' | 'background';
178
221
  interface RegistryEntry {
179
222
  aType: string;
180
223
  axbType: string;
@@ -220,6 +263,24 @@ interface RegistryEntry {
220
263
  * ```
221
264
  */
222
265
  targetGraph?: string;
266
+ /**
267
+ * Schema version for this type's data payload.
268
+ * **Computed automatically** from `migrations` as `max(toVersion)`.
269
+ * Do not set directly — provide migrations instead.
270
+ */
271
+ schemaVersion?: number;
272
+ /**
273
+ * Ordered list of migrations to transform data from older versions
274
+ * to the current version. The schema version is derived as the highest
275
+ * `toVersion` in this array.
276
+ */
277
+ migrations?: MigrationStep[];
278
+ /**
279
+ * Per-entry write-back override for auto-migrated records.
280
+ * Takes precedence over `GraphClientOptions.migrationWriteBack`.
281
+ * Omit to inherit the global setting.
282
+ */
283
+ migrationWriteBack?: MigrationWriteBack;
223
284
  }
224
285
  /** Topology declaration for an edge (from edge.json). */
225
286
  interface EdgeTopology {
@@ -255,6 +316,10 @@ interface DiscoveredEntity {
255
316
  allowedIn?: string[];
256
317
  /** Subgraph name where cross-graph edges of this type live. */
257
318
  targetGraph?: string;
319
+ /** Migration steps loaded from migrations.ts. */
320
+ migrations?: MigrationStep[];
321
+ /** Per-entity write-back override from meta.json. */
322
+ migrationWriteBack?: MigrationWriteBack;
258
323
  }
259
324
  /** Result of scanning an entities directory. */
260
325
  interface DiscoveryResult {
@@ -287,6 +352,18 @@ interface DefineTypeOptions {
287
352
  viewCss?: string;
288
353
  /** Scope patterns constraining where this type can exist in subgraphs. */
289
354
  allowedIn?: string[];
355
+ /**
356
+ * Migration steps. Accepts function objects (auto-serialized via .toString())
357
+ * or strings (stored as-is). The schema version is derived as the highest
358
+ * `toVersion` in this array.
359
+ */
360
+ migrations?: Array<{
361
+ fromVersion: number;
362
+ toVersion: number;
363
+ up: MigrationFn | string;
364
+ }>;
365
+ /** Per-type write-back override for auto-migrated records. */
366
+ migrationWriteBack?: MigrationWriteBack;
290
367
  }
291
368
  /** Data shape stored in a `nodeType` meta-node. */
292
369
  interface NodeTypeData {
@@ -298,6 +375,8 @@ interface NodeTypeData {
298
375
  viewTemplate?: string;
299
376
  viewCss?: string;
300
377
  allowedIn?: string[];
378
+ migrations?: StoredMigrationStep[];
379
+ migrationWriteBack?: MigrationWriteBack;
301
380
  }
302
381
  /** Data shape stored in an `edgeType` meta-node. */
303
382
  interface EdgeTypeData {
@@ -313,6 +392,8 @@ interface EdgeTypeData {
313
392
  viewCss?: string;
314
393
  allowedIn?: string[];
315
394
  targetGraph?: string;
395
+ migrations?: StoredMigrationStep[];
396
+ migrationWriteBack?: MigrationWriteBack;
316
397
  }
317
398
  type ScanProtection = 'error' | 'warn' | 'off';
318
399
  interface GraphClientOptions {
@@ -352,6 +433,25 @@ interface GraphClientOptions {
352
433
  * - `'off'` — No scan protection.
353
434
  */
354
435
  scanProtection?: ScanProtection;
436
+ /**
437
+ * Global default for write-back of auto-migrated records on read.
438
+ *
439
+ * - `'off'` (default) — Migrated data is returned but NOT written back.
440
+ * - `'eager'` — Migrated data is written back immediately after migration.
441
+ * - `'background'` — Write-back happens asynchronously; errors are logged.
442
+ *
443
+ * Per-entry `migrationWriteBack` on `RegistryEntry` overrides this setting.
444
+ */
445
+ migrationWriteBack?: MigrationWriteBack;
446
+ /**
447
+ * Custom executor for compiling dynamic registry migration source strings.
448
+ * Defaults to SES Compartments with JSON marshaling. Supply an
449
+ * alternative for custom sandboxing.
450
+ *
451
+ * Only used for dynamic registry migrations — static registry migrations
452
+ * are already in-memory functions and never go through this executor.
453
+ */
454
+ migrationSandbox?: MigrationExecutor;
355
455
  }
356
456
  interface GraphRegistry {
357
457
  validate(aType: string, axbType: string, bType: string, data: unknown, scopePath?: string): void;
@@ -540,4 +640,4 @@ interface CodegenOptions {
540
640
  */
541
641
  declare function generateTypes(discovery: DiscoveryResult, options?: CodegenOptions): Promise<string>;
542
642
 
543
- 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 GraphRegistry as c, type DiscoveryResult 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 };
643
+ export { type ScanProtection 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, type TraversalOptions as I, type TraversalResult as J, type ViewDefaultsConfig as K, type ViewResolverConfig as L, type MigrationExecutor as M, type NodeTypeData as N, defineConfig as O, generateTypes as P, type QueryPlan as Q, type RegistryEntry as R, type StoredMigrationStep as S, type TraversalBuilder as T, resolveView as U, type ViewContext as V, type WhereClause as W, type DynamicGraphClient as a, type GraphClient as b, type GraphRegistry as c, type DiscoveryResult as d, type GraphReader as e, type GraphRecord as f, type FindNodesParams as g, type MigrationFn as h, type MigrationStep as i, type StoredGraphRecord as j, type MigrationWriteBack as k, type QueryFilter as l, type BulkOptions as m, type BulkProgress as n, type BulkResult as o, type CodegenOptions as p, type DefineTypeOptions as q, type DiscoveredEntity as r, type EdgeTypeData as s, type FiregraphConfig as t, type GraphBatch as u, type GraphTransaction as v, type GraphWriter as w, type HopResult as x, type QueryMode as y, type QueryOptions as z };