@nicia-ai/typegraph 0.24.1 → 0.25.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.
Files changed (159) hide show
  1. package/dist/backend/postgres/index.cjs +178 -55
  2. package/dist/backend/postgres/index.cjs.map +1 -1
  3. package/dist/backend/postgres/index.d.cts +6 -7
  4. package/dist/backend/postgres/index.d.ts +6 -7
  5. package/dist/backend/postgres/index.js +151 -28
  6. package/dist/backend/postgres/index.js.map +1 -1
  7. package/dist/backend/sqlite/index.cjs +19 -17
  8. package/dist/backend/sqlite/index.d.cts +6 -7
  9. package/dist/backend/sqlite/index.d.ts +6 -7
  10. package/dist/backend/sqlite/index.js +9 -7
  11. package/dist/backend/sqlite/libsql.cjs +12 -10
  12. package/dist/backend/sqlite/libsql.cjs.map +1 -1
  13. package/dist/backend/sqlite/libsql.d.cts +4 -5
  14. package/dist/backend/sqlite/libsql.d.ts +4 -5
  15. package/dist/backend/sqlite/libsql.js +9 -7
  16. package/dist/backend/sqlite/libsql.js.map +1 -1
  17. package/dist/backend/sqlite/local.cjs +14 -12
  18. package/dist/backend/sqlite/local.cjs.map +1 -1
  19. package/dist/backend/sqlite/local.d.cts +4 -5
  20. package/dist/backend/sqlite/local.d.ts +4 -5
  21. package/dist/backend/sqlite/local.js +9 -7
  22. package/dist/backend/sqlite/local.js.map +1 -1
  23. package/dist/chunk-4BOWVUGQ.js +2029 -0
  24. package/dist/chunk-4BOWVUGQ.js.map +1 -0
  25. package/dist/{chunk-SUHW2UYL.cjs → chunk-7CDXX3QZ.cjs} +2 -2
  26. package/dist/chunk-7CDXX3QZ.cjs.map +1 -0
  27. package/dist/chunk-7V335GHG.cjs +112 -0
  28. package/dist/chunk-7V335GHG.cjs.map +1 -0
  29. package/dist/chunk-7W3KAMVQ.cjs +2678 -0
  30. package/dist/chunk-7W3KAMVQ.cjs.map +1 -0
  31. package/dist/chunk-CTHNVU6K.cjs +551 -0
  32. package/dist/chunk-CTHNVU6K.cjs.map +1 -0
  33. package/dist/chunk-D2GO3RBL.cjs +12 -0
  34. package/dist/chunk-D2GO3RBL.cjs.map +1 -0
  35. package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
  36. package/dist/chunk-DOTEN2FG.js.map +1 -0
  37. package/dist/chunk-E5JZSEGJ.cjs +301 -0
  38. package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
  39. package/dist/chunk-EG6TJ3I5.js +286 -0
  40. package/dist/chunk-EG6TJ3I5.js.map +1 -0
  41. package/dist/chunk-EJCDOA37.js +537 -0
  42. package/dist/chunk-EJCDOA37.js.map +1 -0
  43. package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
  44. package/dist/chunk-EK6RJ373.cjs.map +1 -0
  45. package/dist/{chunk-GUTQTMOV.js → chunk-FPCOUJSL.js} +2 -2
  46. package/dist/chunk-FPCOUJSL.js.map +1 -0
  47. package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
  48. package/dist/chunk-JTI5WT4P.cjs.map +1 -0
  49. package/dist/chunk-LVCSL6A3.js +2626 -0
  50. package/dist/chunk-LVCSL6A3.js.map +1 -0
  51. package/dist/chunk-NHQWXSTS.js +10 -0
  52. package/dist/chunk-NHQWXSTS.js.map +1 -0
  53. package/dist/chunk-NZ5PMBTG.js +105 -0
  54. package/dist/chunk-NZ5PMBTG.js.map +1 -0
  55. package/dist/{chunk-5HVDOPZU.cjs → chunk-O2P3KAUT.cjs} +416 -93
  56. package/dist/chunk-O2P3KAUT.cjs.map +1 -0
  57. package/dist/{chunk-QOLTW7OZ.js → chunk-OJ6IQVZG.js} +151 -13
  58. package/dist/chunk-OJ6IQVZG.js.map +1 -0
  59. package/dist/{chunk-EYELZHKY.js → chunk-OOS2RKRH.js} +5 -140
  60. package/dist/chunk-OOS2RKRH.js.map +1 -0
  61. package/dist/chunk-RCAJZG67.cjs +2069 -0
  62. package/dist/chunk-RCAJZG67.cjs.map +1 -0
  63. package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
  64. package/dist/chunk-W5MTHMTE.cjs.map +1 -0
  65. package/dist/{chunk-EY4LBX3F.js → chunk-WI5VRP3X.js} +337 -26
  66. package/dist/chunk-WI5VRP3X.js.map +1 -0
  67. package/dist/chunk-WVQXAFP3.js +79 -0
  68. package/dist/chunk-WVQXAFP3.js.map +1 -0
  69. package/dist/chunk-X3244EKP.cjs +84 -0
  70. package/dist/chunk-X3244EKP.cjs.map +1 -0
  71. package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
  72. package/dist/chunk-YZZBDCLV.js.map +1 -0
  73. package/dist/{chunk-OVJ2BE5Q.cjs → chunk-ZEMNF3QK.cjs} +171 -33
  74. package/dist/chunk-ZEMNF3QK.cjs.map +1 -0
  75. package/dist/{ddl-B_H8JM-E.d.cts → ddl-B2jjLjpR.d.cts} +762 -99
  76. package/dist/{ddl-1tFIvt9V.d.ts → ddl-DpaeAKPp.d.ts} +762 -99
  77. package/dist/extension-types-D07e_NTw.d.cts +543 -0
  78. package/dist/extension-types-D07e_NTw.d.ts +543 -0
  79. package/dist/graph-extension/index.cjs +71 -0
  80. package/dist/graph-extension/index.cjs.map +1 -0
  81. package/dist/graph-extension/index.d.cts +278 -0
  82. package/dist/graph-extension/index.d.ts +278 -0
  83. package/dist/graph-extension/index.js +6 -0
  84. package/dist/graph-extension/index.js.map +1 -0
  85. package/dist/{index-DXkEXpNz.d.ts → index-CT6nvtxL.d.cts} +114 -5
  86. package/dist/{index-DXkEXpNz.d.cts → index-DQheiVQV.d.ts} +114 -5
  87. package/dist/index.cjs +2672 -901
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.d.cts +29 -10
  90. package/dist/index.d.ts +29 -10
  91. package/dist/index.js +2248 -598
  92. package/dist/index.js.map +1 -1
  93. package/dist/indexes/index.cjs +25 -23
  94. package/dist/indexes/index.d.cts +40 -22
  95. package/dist/indexes/index.d.ts +40 -22
  96. package/dist/indexes/index.js +5 -3
  97. package/dist/interchange/index.cjs +8 -7
  98. package/dist/interchange/index.cjs.map +1 -1
  99. package/dist/interchange/index.d.cts +5 -4
  100. package/dist/interchange/index.d.ts +5 -4
  101. package/dist/interchange/index.js +3 -2
  102. package/dist/interchange/index.js.map +1 -1
  103. package/dist/{manager-nIhmttD-.d.ts → manager-BKaPQbns.d.ts} +189 -6
  104. package/dist/{manager-Vkz28eAC.d.cts → manager-BpjBW1JK.d.cts} +189 -6
  105. package/dist/materialize-indexes-BB9N5uQl.d.cts +68 -0
  106. package/dist/materialize-indexes-BYpU2RKh.d.ts +68 -0
  107. package/dist/profiler/index.cjs +10 -8
  108. package/dist/profiler/index.cjs.map +1 -1
  109. package/dist/profiler/index.d.cts +8 -7
  110. package/dist/profiler/index.d.ts +8 -7
  111. package/dist/profiler/index.js +3 -1
  112. package/dist/profiler/index.js.map +1 -1
  113. package/dist/schema/index.cjs +43 -22
  114. package/dist/schema/index.cjs.map +1 -1
  115. package/dist/schema/index.d.cts +17 -8
  116. package/dist/schema/index.d.ts +17 -8
  117. package/dist/schema/index.js +9 -4
  118. package/dist/schema/index.js.map +1 -1
  119. package/dist/{sqlite-D0aceIe0.d.cts → sqlite-CU3j6rc7.d.ts} +837 -120
  120. package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-Myo8e3Lr.d.cts} +837 -120
  121. package/dist/{store-U3i2tUch.d.ts → store-BAGuOHDh.d.cts} +659 -23
  122. package/dist/{store-CpvwTMxV.d.cts → store-De98Lod4.d.ts} +659 -23
  123. package/dist/types--0EslBx5.d.cts +2123 -0
  124. package/dist/{types-qYFZ9SqD.d.ts → types-BLmJq4wI.d.ts} +3 -2
  125. package/dist/types-BNWYZ-0-.d.ts +2123 -0
  126. package/dist/{types-yH4_p0XB.d.cts → types-CYga3lZp.d.cts} +3 -2
  127. package/dist/where-CluR73rs.d.ts +11 -0
  128. package/dist/where-m1uWsdua.d.cts +11 -0
  129. package/package.json +33 -73
  130. package/dist/ast-C8S37w1A.d.ts +0 -497
  131. package/dist/ast-dgLhLOg0.d.cts +0 -497
  132. package/dist/chunk-3JK66E3I.cjs.map +0 -1
  133. package/dist/chunk-3PPEHLGK.js +0 -1116
  134. package/dist/chunk-3PPEHLGK.js.map +0 -1
  135. package/dist/chunk-5HVDOPZU.cjs.map +0 -1
  136. package/dist/chunk-753F33CV.js.map +0 -1
  137. package/dist/chunk-EY4LBX3F.js.map +0 -1
  138. package/dist/chunk-EYELZHKY.js.map +0 -1
  139. package/dist/chunk-GFGVREHH.js +0 -1381
  140. package/dist/chunk-GFGVREHH.js.map +0 -1
  141. package/dist/chunk-GUTQTMOV.js.map +0 -1
  142. package/dist/chunk-LBORRUNJ.js +0 -135
  143. package/dist/chunk-LBORRUNJ.js.map +0 -1
  144. package/dist/chunk-O5PST6TB.cjs.map +0 -1
  145. package/dist/chunk-OLROXS2S.cjs +0 -147
  146. package/dist/chunk-OLROXS2S.cjs.map +0 -1
  147. package/dist/chunk-OVJ2BE5Q.cjs.map +0 -1
  148. package/dist/chunk-PAUN562Y.cjs +0 -1417
  149. package/dist/chunk-PAUN562Y.cjs.map +0 -1
  150. package/dist/chunk-PEE4EWXZ.cjs +0 -1131
  151. package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
  152. package/dist/chunk-QOLTW7OZ.js.map +0 -1
  153. package/dist/chunk-SUHW2UYL.cjs.map +0 -1
  154. package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
  155. package/dist/chunk-WFMTAEEN.js.map +0 -1
  156. package/dist/types-C-zfYDJB.d.ts +0 -159
  157. package/dist/types-CQx4iW5Y.d.cts +0 -159
  158. package/dist/types-Qk2l3IkQ.d.cts +0 -1254
  159. package/dist/types-Qk2l3IkQ.d.ts +0 -1254
@@ -1,4 +1,5 @@
1
- import { r as NodeRegistration, f as EdgeRegistration, O as OntologyRelation, b as DeleteBehavior, T as TemporalMode, N as NodeType, A as AnyEdgeType, n as GraphDefaults, W as SerializedNodeDef, X as SerializedEdgeDef, $ as SerializedSchema, G as GraphBackend, a4 as SchemaVersionRow } from './types-Qk2l3IkQ.cjs';
1
+ import { b as NodeRegistration, E as EdgeRegistration, D as DeleteBehavior, T as TemporalMode, G as GraphExtension, N as NodeType, A as AnyEdgeType, c as GraphDefaults, I as IndexEntity } from './extension-types-D07e_NTw.cjs';
2
+ import { O as OntologyRelation, I as IndexDeclaration, S as SerializedNodeDef, d as SerializedEdgeDef, h as SerializedSchema, y as SchemaVersionRow, G as GraphBackend } from './types--0EslBx5.cjs';
2
3
 
3
4
  /** Brand key for GraphDef */
4
5
  declare const GRAPH_DEF_BRAND: "__graphDef";
@@ -31,6 +32,23 @@ type GraphDefConfig<TNodes extends Record<string, NodeRegistration>, TEdges exte
31
32
  ontology?: TOntology;
32
33
  /** Graph-wide defaults */
33
34
  defaults?: GraphDefaults;
35
+ /**
36
+ * Index declarations attached to this graph.
37
+ *
38
+ * Accepts the outputs of `defineNodeIndex` / `defineEdgeIndex` (which
39
+ * already return `IndexDeclaration` values) or pre-built declarations
40
+ * reconstructed from a stored schema or graph extension.
41
+ *
42
+ * Validated at definition time: every index must reference a `kind`
43
+ * that exists in `nodes` / `edges`, and index `name`s must be unique
44
+ * within the graph.
45
+ *
46
+ * Index DDL is **not** generated by `defineGraph`. Indexes flow into
47
+ * `SerializedSchema.indexes` so they can later be materialized via
48
+ * `store.materializeIndexes()` — lifting the storage concern out of
49
+ * the schema-version commit path.
50
+ */
51
+ indexes?: readonly IndexDeclaration[];
34
52
  }>;
35
53
  /**
36
54
  * A graph definition.
@@ -48,6 +66,35 @@ type GraphDef<TNodes extends Record<string, NodeRegistration> = Record<string, N
48
66
  onNodeDelete: DeleteBehavior;
49
67
  temporalMode: TemporalMode;
50
68
  }>;
69
+ /**
70
+ * Index declarations attached to this graph. Preserves whatever the
71
+ * caller passed to `defineGraph` (including an explicit empty array)
72
+ * for introspection purposes.
73
+ *
74
+ * The serialized canonical form is order-canonicalized (sorted by
75
+ * `name`) and treats `undefined` and `[]` as the same "no slice" form
76
+ * — an empty array does not bump the schema hash, since indexes are
77
+ * an unordered set keyed by name and `[]` carries no semantic meaning
78
+ * that an absent slice doesn't.
79
+ */
80
+ indexes: readonly IndexDeclaration[] | undefined;
81
+ /**
82
+ * Graph extension this graph was merged with, if any. Set by
83
+ * `mergeGraphExtension`; never set by `defineGraph` directly.
84
+ * Exists solely so re-serialization is stable — the rest of the
85
+ * system reads the merged kinds through `nodes` / `edges` /
86
+ * `ontology` and never inspects this field. Absent on graphs that
87
+ * have never been extended; legacy graphs hash byte-identically.
88
+ */
89
+ extension: GraphExtension | undefined;
90
+ /**
91
+ * Soft-deprecated kind names attached to this graph. Set by the
92
+ * loader from the persisted schema and by `store.deprecateKinds(...)`
93
+ * / `store.undeprecateKinds(...)`. A purely informational signal
94
+ * surfaced for introspection — does not gate reads, writes, or
95
+ * queries. Defaults to the empty set on freshly-defined graphs.
96
+ */
97
+ deprecatedKinds: ReadonlySet<string>;
51
98
  }>;
52
99
  /**
53
100
  * Extract node kind names from a GraphDef.
@@ -314,6 +361,56 @@ type OntologyChange = Readonly<{
314
361
  severity: ChangeSeverity;
315
362
  details: string;
316
363
  }>;
364
+ /**
365
+ * A change to an index declaration.
366
+ *
367
+ * Index changes are always `safe`-severity: index DDL is materialized
368
+ * separately and never blocks schema-version commits or migrations.
369
+ * Adding, removing, or modifying an index never invalidates existing
370
+ * data — it only changes which physical indexes the deployment will
371
+ * materialize on its next pass.
372
+ */
373
+ type IndexChange = Readonly<{
374
+ type: ChangeType;
375
+ /** Index name (the diffing identity key). */
376
+ name: string;
377
+ /**
378
+ * Whether this index is on a node, edge, or vector field. Vector
379
+ * index changes flow through the same diff classification as
380
+ * relational ones.
381
+ */
382
+ entity: IndexEntity;
383
+ severity: ChangeSeverity;
384
+ details: string;
385
+ before?: IndexDeclaration | undefined;
386
+ after?: IndexDeclaration | undefined;
387
+ }>;
388
+ /**
389
+ * A change to the persisted graph-extension document.
390
+ *
391
+ * Graph-extension document changes are committed only through the
392
+ * graph-extension lifecycle verbs (`evolve` and `removeKinds`), so the
393
+ * extension-slice change itself is `safe`-severity. The detailed
394
+ * per-kind effect is captured in the corresponding node/edge/ontology
395
+ * changes the merged document produced.
396
+ */
397
+ type ExtensionChange = Readonly<{
398
+ type: ChangeType;
399
+ severity: ChangeSeverity;
400
+ details: string;
401
+ }>;
402
+ /**
403
+ * Change to the soft-deprecated kind set. `safe`-severity by
404
+ * construction — deprecation is a metadata signal that doesn't gate
405
+ * reads, writes, or queries. The `added` and `removed` arrays carry
406
+ * the per-name deltas so consumers can render granular diffs.
407
+ */
408
+ type DeprecatedKindsChange = Readonly<{
409
+ added: readonly string[];
410
+ removed: readonly string[];
411
+ severity: ChangeSeverity;
412
+ details: string;
413
+ }>;
317
414
  /**
318
415
  * A complete diff between two schema versions.
319
416
  */
@@ -326,6 +423,18 @@ type SchemaDiff = Readonly<{
326
423
  edges: readonly EdgeChange[];
327
424
  /** Changes to ontology */
328
425
  ontology: readonly OntologyChange[];
426
+ /** Changes to index declarations */
427
+ indexes: readonly IndexChange[];
428
+ /**
429
+ * Change to the graph-extension document, if any. `undefined` when
430
+ * the slice is unchanged on both sides (the common case).
431
+ */
432
+ extension?: ExtensionChange;
433
+ /**
434
+ * Change to the soft-deprecated kind set, if any. `undefined` when
435
+ * the set is unchanged on both sides.
436
+ */
437
+ deprecatedKinds?: DeprecatedKindsChange;
329
438
  /** Whether any breaking changes exist */
330
439
  hasBreakingChanges: boolean;
331
440
  /** Whether the change is backwards compatible (no breaking changes) */
@@ -367,12 +476,59 @@ declare function getMigrationActions(diff: SchemaDiff): readonly string[];
367
476
  * - Error reporting for breaking changes
368
477
  */
369
478
 
479
+ /**
480
+ * Parses and validates a serialized schema document from the database.
481
+ *
482
+ * Uses the Zod schema to validate the full nested structure, catching
483
+ * corruption, incompatible schema versions, or truncated JSON at the
484
+ * parse boundary rather than letting invalid data propagate silently.
485
+ */
486
+ declare function parseSerializedSchema(json: string): SerializedSchema;
487
+ /**
488
+ * Reads the active schema row, bootstrapping the base tables on the
489
+ * first call against an empty database.
490
+ */
491
+ declare function loadActiveSchemaWithBootstrap(backend: GraphBackend, graphId: string): Promise<SchemaVersionRow | undefined>;
492
+ /**
493
+ * Reads the active schema, parses it, and folds any persisted graph-extension
494
+ * document into the supplied compile-time graph. Returns the
495
+ * merged graph alongside the prefetched row + parsed schema so the
496
+ * caller can pass them through to `ensureSchema` without paying for a
497
+ * second `getActiveSchema` round trip or a second
498
+ * `serializedSchemaZod` walk.
499
+ *
500
+ * Throws `ConfigurationError` if the persisted graph-extension document
501
+ * references a compile-time kind that no longer exists (the
502
+ * startup-conflict case).
503
+ */
504
+ declare function loadAndMergeGraphExtensionDocument<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<Readonly<{
505
+ graph: G;
506
+ activeRow: SchemaVersionRow | undefined;
507
+ storedSchema: SerializedSchema | undefined;
508
+ }>>;
509
+ /**
510
+ * Returns a graph carrying the supplied deprecated-kind names. Used by
511
+ * the loader to propagate `SerializedSchema.deprecatedKinds` onto the
512
+ * `GraphDef` that the Store sees, and by `Store.deprecateKinds` /
513
+ * `Store.undeprecateKinds` to construct the next graph.
514
+ *
515
+ * Returns the original graph reference when the desired set already
516
+ * matches `graph.deprecatedKinds` — covers both the no-deprecations
517
+ * load path (empty equals empty) and the loader's restart-with-same-
518
+ * persisted-set hot path. Skips a Set allocation + spread + freeze.
519
+ */
520
+ declare function applyDeprecatedKinds<G extends GraphDef>(graph: G, names: Iterable<string> | undefined): G;
370
521
  /**
371
522
  * Result of schema validation.
523
+ *
524
+ * The `initialized` and `migrated` statuses carry the committed
525
+ * `SchemaVersionRow` directly so callers building post-commit metadata
526
+ * (e.g. `Store.deprecateKinds`) can skip a `getActiveSchema` round-trip.
372
527
  */
373
528
  type SchemaValidationResult = {
374
529
  status: "initialized";
375
530
  version: number;
531
+ committedRow: SchemaVersionRow;
376
532
  } | {
377
533
  status: "unchanged";
378
534
  version: number;
@@ -381,6 +537,7 @@ type SchemaValidationResult = {
381
537
  fromVersion: number;
382
538
  toVersion: number;
383
539
  diff: SchemaDiff;
540
+ committedRow: SchemaVersionRow;
384
541
  } | {
385
542
  status: "pending";
386
543
  version: number;
@@ -431,11 +588,27 @@ type SchemaManagerOptions = Readonly<{
431
588
  * @returns The result of schema validation
432
589
  * @throws MigrationError if breaking changes detected and throwOnBreaking is true
433
590
  */
434
- declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions): Promise<SchemaValidationResult>;
591
+ declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions & {
592
+ /**
593
+ * Pre-fetched active row + parsed stored schema. When the loader
594
+ * (`createStoreWithSchema`) has already paid for `getActiveSchema`
595
+ * and `parseSerializedSchema` to peek at `extension`, it
596
+ * passes the results through here so `ensureSchema` doesn't repeat
597
+ * the round trip + Zod walk on every Store boot.
598
+ */
599
+ preloaded?: Readonly<{
600
+ activeRow: SchemaVersionRow | undefined;
601
+ storedSchema: SerializedSchema | undefined;
602
+ }>;
603
+ }): Promise<SchemaValidationResult>;
435
604
  /**
436
605
  * Initializes the schema for a new graph.
437
606
  *
438
- * Creates version 1 of the schema and marks it as active.
607
+ * Creates version 1 of the schema and marks it as active. Goes through
608
+ * the same `commitSchemaVersion` primitive as `migrateSchema` so the
609
+ * initial-commit race (two processes booting against an empty database
610
+ * simultaneously) resolves with `StaleVersionError` or idempotent
611
+ * success rather than a raw PK violation.
439
612
  *
440
613
  * @param backend - The database backend
441
614
  * @param graph - The graph definition
@@ -445,8 +618,12 @@ declare function initializeSchema<G extends GraphDef>(backend: GraphBackend, gra
445
618
  /**
446
619
  * Migrates the schema to match the current graph definition.
447
620
  *
448
- * This creates a new schema version and marks it as active.
449
- * The old version is preserved for history/rollback.
621
+ * Creates a new schema version and atomically activates it via the
622
+ * `commitSchemaVersion` backend primitive — insert and activate happen
623
+ * in a single transactional unit with optimistic compare-and-swap on
624
+ * the currently-active version. If another writer has advanced the
625
+ * active version since `currentVersion` was read, this throws
626
+ * `StaleVersionError`; the caller should refetch and retry.
450
627
  *
451
628
  * @param backend - The database backend
452
629
  * @param graph - The current graph definition
@@ -460,10 +637,16 @@ declare function migrateSchema<G extends GraphDef>(backend: GraphBackend, graph:
460
637
  * The target version must already exist in the version history.
461
638
  * This does not delete newer versions — it simply switches the active pointer.
462
639
  *
640
+ * Uses the `setActiveVersion` backend primitive, which performs the flip
641
+ * atomically with optimistic compare-and-swap on the currently-active
642
+ * version. Concurrent rollbacks or commits surface as
643
+ * `StaleVersionError`.
644
+ *
463
645
  * @param backend - The database backend
464
646
  * @param graphId - The graph ID
465
647
  * @param targetVersion - The version to roll back to
466
648
  * @throws MigrationError if the target version does not exist
649
+ * @throws StaleVersionError if another writer changed the active version concurrently
467
650
  */
468
651
  declare function rollbackSchema(backend: GraphBackend, graphId: string, targetVersion: number): Promise<void>;
469
652
  /**
@@ -491,4 +674,4 @@ declare function isSchemaInitialized(backend: GraphBackend, graphId: string): Pr
491
674
  */
492
675
  declare function getSchemaChanges<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<SchemaDiff | undefined>;
493
676
 
494
- export { type AllEdgeTypes as A, type ChangeSeverity as C, type EdgeKinds as E, type GraphDef as G, KindRegistry as K, type MigrationHookContext as M, type NodeKinds as N, type OntologyChange as O, type SchemaManagerOptions as S, type AllNodeTypes as a, type GetEdgeType as b, type GetNodeType as c, type SchemaValidationResult as d, defineGraph as e, getNodeKinds as f, getEdgeKinds as g, type ChangeType as h, isGraphDef as i, type EdgeChange as j, type NodeChange as k, type SchemaDiff as l, computeSchemaDiff as m, ensureSchema as n, getActiveSchema as o, getMigrationActions as p, getSchemaChanges as q, initializeSchema as r, isBackwardsCompatible as s, isSchemaInitialized as t, migrateSchema as u, rollbackSchema as v };
677
+ export { type AllEdgeTypes as A, isGraphDef as B, type ChangeSeverity as C, type DeprecatedKindsChange as D, type EdgeChange as E, type GraphDef as G, type IndexChange as I, KindRegistry as K, type MigrationHookContext as M, type NodeChange as N, type OntologyChange as O, type SchemaDiff as S, type ChangeType as a, type ExtensionChange as b, type SchemaManagerOptions as c, type SchemaValidationResult as d, applyDeprecatedKinds as e, computeSchemaDiff as f, ensureSchema as g, getActiveSchema as h, getMigrationActions as i, getSchemaChanges as j, initializeSchema as k, isBackwardsCompatible as l, isSchemaInitialized as m, loadActiveSchemaWithBootstrap as n, loadAndMergeGraphExtensionDocument as o, migrateSchema as p, parseSerializedSchema as q, rollbackSchema as r, type AllNodeTypes as s, type EdgeKinds as t, type GetEdgeType as u, type GetNodeType as v, type NodeKinds as w, defineGraph as x, getEdgeKinds as y, getNodeKinds as z };
@@ -0,0 +1,68 @@
1
+ import { I as IndexEntity } from './extension-types-D07e_NTw.cjs';
2
+
3
+ /**
4
+ * Index materialization — runs declared index DDL against the live
5
+ * database and tracks per-deployment status in
6
+ * `typegraph_index_materializations`.
7
+ *
8
+ * Reads `IndexDeclaration[]` from `GraphDef.indexes`, generates DDL via
9
+ * `generateIndexDDL`, executes via `backend.executeDdl` (Postgres path
10
+ * uses `CREATE INDEX CONCURRENTLY`, which cannot run inside a
11
+ * transaction — `executeDdl` runs at the top-level backend, never inside
12
+ * `transaction(...)`), and upserts a status row per index.
13
+ *
14
+ * Caveats baked in to the algorithm:
15
+ *
16
+ * - SQL index names are physical, database-global identifiers.
17
+ * Cross-graph collisions (two graphs declaring the same name with
18
+ * different shapes) surface as a `failed` result with reason
19
+ * "signature drift", because the existing recorded signature won't
20
+ * match the new one.
21
+ * - On Postgres, `CREATE INDEX CONCURRENTLY IF NOT EXISTS` does NOT
22
+ * prove the existing physical index has the same shape as ours —
23
+ * only that something with that name exists. Drift detection here
24
+ * relies on TypeGraph's recorded signature, not on PG metadata.
25
+ * - Failed `CONCURRENTLY` builds leave invalid indexes behind
26
+ * (`pg_index.indisvalid = false`). v1 surfaces this as a `failed`
27
+ * result; the operator must drop the invalid index manually before
28
+ * retry.
29
+ */
30
+
31
+ type MaterializeIndexesOptions = Readonly<{
32
+ /** Restrict to indexes whose `kind` is in this set. */
33
+ kinds?: readonly string[];
34
+ /** Stop on the first failure. Default: false (best-effort). */
35
+ stopOnError?: boolean;
36
+ }>;
37
+ /**
38
+ * Per-index outcome from `materializeIndexes()`.
39
+ *
40
+ * Status values:
41
+ * - `created`: DDL ran successfully and a new physical index now exists.
42
+ * - `alreadyMaterialized`: status table shows a prior successful
43
+ * materialization with the same signature; no DDL ran.
44
+ * - `failed`: the DDL or status write failed; `error` carries the
45
+ * captured exception. Best-effort mode continues to the next index;
46
+ * `stopOnError: true` halts.
47
+ * - `skipped`: the backend can't materialize this index variant in its
48
+ * current configuration (e.g. vector indexes against SQLite without
49
+ * sqlite-vec, or `indexType: "none"` declared on an embedding). The
50
+ * declaration is recognized but intentionally not acted on. Status
51
+ * table is NOT updated for skipped entries.
52
+ */
53
+ type MaterializeIndexesEntry = Readonly<{
54
+ indexName: string;
55
+ entity: IndexEntity;
56
+ kind: string;
57
+ status: "created" | "alreadyMaterialized" | "failed" | "skipped";
58
+ error?: Error;
59
+ /**
60
+ * Human-readable reason. Required for `skipped`; optional otherwise.
61
+ */
62
+ reason?: string;
63
+ }>;
64
+ type MaterializeIndexesResult = Readonly<{
65
+ results: readonly MaterializeIndexesEntry[];
66
+ }>;
67
+
68
+ export type { MaterializeIndexesResult as M, MaterializeIndexesEntry as a, MaterializeIndexesOptions as b };
@@ -0,0 +1,68 @@
1
+ import { I as IndexEntity } from './extension-types-D07e_NTw.js';
2
+
3
+ /**
4
+ * Index materialization — runs declared index DDL against the live
5
+ * database and tracks per-deployment status in
6
+ * `typegraph_index_materializations`.
7
+ *
8
+ * Reads `IndexDeclaration[]` from `GraphDef.indexes`, generates DDL via
9
+ * `generateIndexDDL`, executes via `backend.executeDdl` (Postgres path
10
+ * uses `CREATE INDEX CONCURRENTLY`, which cannot run inside a
11
+ * transaction — `executeDdl` runs at the top-level backend, never inside
12
+ * `transaction(...)`), and upserts a status row per index.
13
+ *
14
+ * Caveats baked in to the algorithm:
15
+ *
16
+ * - SQL index names are physical, database-global identifiers.
17
+ * Cross-graph collisions (two graphs declaring the same name with
18
+ * different shapes) surface as a `failed` result with reason
19
+ * "signature drift", because the existing recorded signature won't
20
+ * match the new one.
21
+ * - On Postgres, `CREATE INDEX CONCURRENTLY IF NOT EXISTS` does NOT
22
+ * prove the existing physical index has the same shape as ours —
23
+ * only that something with that name exists. Drift detection here
24
+ * relies on TypeGraph's recorded signature, not on PG metadata.
25
+ * - Failed `CONCURRENTLY` builds leave invalid indexes behind
26
+ * (`pg_index.indisvalid = false`). v1 surfaces this as a `failed`
27
+ * result; the operator must drop the invalid index manually before
28
+ * retry.
29
+ */
30
+
31
+ type MaterializeIndexesOptions = Readonly<{
32
+ /** Restrict to indexes whose `kind` is in this set. */
33
+ kinds?: readonly string[];
34
+ /** Stop on the first failure. Default: false (best-effort). */
35
+ stopOnError?: boolean;
36
+ }>;
37
+ /**
38
+ * Per-index outcome from `materializeIndexes()`.
39
+ *
40
+ * Status values:
41
+ * - `created`: DDL ran successfully and a new physical index now exists.
42
+ * - `alreadyMaterialized`: status table shows a prior successful
43
+ * materialization with the same signature; no DDL ran.
44
+ * - `failed`: the DDL or status write failed; `error` carries the
45
+ * captured exception. Best-effort mode continues to the next index;
46
+ * `stopOnError: true` halts.
47
+ * - `skipped`: the backend can't materialize this index variant in its
48
+ * current configuration (e.g. vector indexes against SQLite without
49
+ * sqlite-vec, or `indexType: "none"` declared on an embedding). The
50
+ * declaration is recognized but intentionally not acted on. Status
51
+ * table is NOT updated for skipped entries.
52
+ */
53
+ type MaterializeIndexesEntry = Readonly<{
54
+ indexName: string;
55
+ entity: IndexEntity;
56
+ kind: string;
57
+ status: "created" | "alreadyMaterialized" | "failed" | "skipped";
58
+ error?: Error;
59
+ /**
60
+ * Human-readable reason. Required for `skipped`; optional otherwise.
61
+ */
62
+ reason?: string;
63
+ }>;
64
+ type MaterializeIndexesResult = Readonly<{
65
+ results: readonly MaterializeIndexesEntry[];
66
+ }>;
67
+
68
+ export type { MaterializeIndexesResult as M, MaterializeIndexesEntry as a, MaterializeIndexesOptions as b };
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkUVZHTBZ5_cjs = require('../chunk-UVZHTBZ5.cjs');
3
+ var chunkEK6RJ373_cjs = require('../chunk-EK6RJ373.cjs');
4
+ require('../chunk-X3244EKP.cjs');
5
+ var chunk7V335GHG_cjs = require('../chunk-7V335GHG.cjs');
4
6
 
5
7
  // src/profiler/ast-extractor.ts
6
8
  function extractPropertyAccesses(ast) {
@@ -175,7 +177,7 @@ function extractFromSelectiveField(field, ast) {
175
177
  kindNames: resolved.kindNames,
176
178
  target: {
177
179
  __type: "prop",
178
- pointer: chunkUVZHTBZ5_cjs.jsonPointer(field.field.split("."))
180
+ pointer: chunk7V335GHG_cjs.jsonPointer(field.field.split("."))
179
181
  },
180
182
  context: "select"
181
183
  };
@@ -215,7 +217,7 @@ function extractTargetFromFieldRef(ref) {
215
217
  return { __type: "prop", pointer: ref.jsonPointer };
216
218
  }
217
219
  if (ref.path.length > 1 && ref.path[0] === "props") {
218
- return { __type: "prop", pointer: chunkUVZHTBZ5_cjs.jsonPointer(ref.path.slice(1)) };
220
+ return { __type: "prop", pointer: chunk7V335GHG_cjs.jsonPointer(ref.path.slice(1)) };
219
221
  }
220
222
  if (ref.path.length === 1) {
221
223
  return { __type: "system", field: ref.path[0] };
@@ -256,7 +258,7 @@ function keyToPath(key) {
256
258
  target: { __type: "system", field: systemField }
257
259
  };
258
260
  }
259
- const pointer = chunkUVZHTBZ5_cjs.normalizeJsonPointer(
261
+ const pointer = chunk7V335GHG_cjs.normalizeJsonPointer(
260
262
  targetPart
261
263
  );
262
264
  return {
@@ -516,7 +518,7 @@ var QueryProfiler = class {
516
518
  );
517
519
  }
518
520
  this.#attached = true;
519
- this.#schemaIntrospector = chunkUVZHTBZ5_cjs.createSchemaIntrospector(
521
+ this.#schemaIntrospector = chunkEK6RJ373_cjs.createSchemaIntrospector(
520
522
  buildNodeSchemaMap(store.graph),
521
523
  buildEdgeSchemaMap(store.graph)
522
524
  );
@@ -677,7 +679,7 @@ function getNodeEnv() {
677
679
  return process.env.NODE_ENV;
678
680
  }
679
681
  function hasPointerInSchema(schemaIntrospector, entityType, kindName, pointer) {
680
- const segments = chunkUVZHTBZ5_cjs.parseJsonPointer(pointer);
682
+ const segments = chunk7V335GHG_cjs.parseJsonPointer(pointer);
681
683
  const [first, ...rest] = segments;
682
684
  if (!first) {
683
685
  return false;
@@ -690,9 +692,9 @@ function hasPointerInSchema(schemaIntrospector, entityType, kindName, pointer) {
690
692
  return true;
691
693
  }
692
694
  try {
693
- const resolved = chunkUVZHTBZ5_cjs.resolveFieldTypeInfoAtJsonPointer(
695
+ const resolved = chunkEK6RJ373_cjs.resolveFieldTypeInfoAtJsonPointer(
694
696
  rootInfo,
695
- chunkUVZHTBZ5_cjs.jsonPointer(rest)
697
+ chunk7V335GHG_cjs.jsonPointer(rest)
696
698
  );
697
699
  return resolved !== void 0;
698
700
  } catch (error) {