@nicia-ai/typegraph 0.24.1 → 0.25.1

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 +226 -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 +195 -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-7V335GHG.cjs +112 -0
  26. package/dist/chunk-7V335GHG.cjs.map +1 -0
  27. package/dist/chunk-AAA2CR3P.js +2628 -0
  28. package/dist/chunk-AAA2CR3P.js.map +1 -0
  29. package/dist/{chunk-QOLTW7OZ.js → chunk-CLEUFN2K.js} +195 -13
  30. package/dist/chunk-CLEUFN2K.js.map +1 -0
  31. package/dist/{chunk-OVJ2BE5Q.cjs → chunk-CLGC7AQ2.cjs} +215 -33
  32. package/dist/chunk-CLGC7AQ2.cjs.map +1 -0
  33. package/dist/{chunk-GUTQTMOV.js → chunk-CPFR3O7L.js} +2 -2
  34. package/dist/chunk-CPFR3O7L.js.map +1 -0
  35. package/dist/{chunk-5HVDOPZU.cjs → chunk-CQVNGKU7.cjs} +452 -104
  36. package/dist/chunk-CQVNGKU7.cjs.map +1 -0
  37. package/dist/chunk-CTHNVU6K.cjs +551 -0
  38. package/dist/chunk-CTHNVU6K.cjs.map +1 -0
  39. package/dist/chunk-D2GO3RBL.cjs +12 -0
  40. package/dist/chunk-D2GO3RBL.cjs.map +1 -0
  41. package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
  42. package/dist/chunk-DOTEN2FG.js.map +1 -0
  43. package/dist/chunk-E5JZSEGJ.cjs +301 -0
  44. package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
  45. package/dist/chunk-EG6TJ3I5.js +286 -0
  46. package/dist/chunk-EG6TJ3I5.js.map +1 -0
  47. package/dist/chunk-EJCDOA37.js +537 -0
  48. package/dist/chunk-EJCDOA37.js.map +1 -0
  49. package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
  50. package/dist/chunk-EK6RJ373.cjs.map +1 -0
  51. package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
  52. package/dist/chunk-JTI5WT4P.cjs.map +1 -0
  53. package/dist/chunk-NHQWXSTS.js +10 -0
  54. package/dist/chunk-NHQWXSTS.js.map +1 -0
  55. package/dist/chunk-NZ5PMBTG.js +105 -0
  56. package/dist/chunk-NZ5PMBTG.js.map +1 -0
  57. package/dist/{chunk-SUHW2UYL.cjs → chunk-OECDVACY.cjs} +2 -2
  58. package/dist/chunk-OECDVACY.cjs.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-EY4LBX3F.js → chunk-PSKUWVCB.js} +373 -38
  62. package/dist/chunk-PSKUWVCB.js.map +1 -0
  63. package/dist/chunk-QMQYK3IF.cjs +2680 -0
  64. package/dist/chunk-QMQYK3IF.cjs.map +1 -0
  65. package/dist/chunk-RCAJZG67.cjs +2069 -0
  66. package/dist/chunk-RCAJZG67.cjs.map +1 -0
  67. package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
  68. package/dist/chunk-W5MTHMTE.cjs.map +1 -0
  69. package/dist/chunk-WVQXAFP3.js +79 -0
  70. package/dist/chunk-WVQXAFP3.js.map +1 -0
  71. package/dist/chunk-X3244EKP.cjs +84 -0
  72. package/dist/chunk-X3244EKP.cjs.map +1 -0
  73. package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
  74. package/dist/chunk-YZZBDCLV.js.map +1 -0
  75. package/dist/{ddl-B_H8JM-E.d.cts → ddl-BqMmpNor.d.ts} +1328 -283
  76. package/dist/{ddl-1tFIvt9V.d.ts → ddl-Bwjh8Hff.d.cts} +1328 -283
  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-Vkz28eAC.d.cts → manager-Cy3dhwYO.d.cts} +194 -6
  104. package/dist/{manager-nIhmttD-.d.ts → manager-sZkU2VPC.d.ts} +194 -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-BhFswiAR.d.cts} +837 -120
  120. package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-h6dta1IJ.d.ts} +837 -120
  121. package/dist/{store-CpvwTMxV.d.cts → store-BS_hehiz.d.ts} +659 -23
  122. package/dist/{store-U3i2tUch.d.ts → store-CkCvqRUf.d.cts} +659 -23
  123. package/dist/{types-yH4_p0XB.d.cts → types-BpgACExN.d.cts} +3 -2
  124. package/dist/{types-qYFZ9SqD.d.ts → types-Bz-Pi681.d.ts} +3 -2
  125. package/dist/types-DptZHe-l.d.ts +2132 -0
  126. package/dist/types-WF5ItKQu.d.cts +2132 -0
  127. package/dist/where-C40InMIp.d.ts +11 -0
  128. package/dist/where-DZYMiXVq.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.js';
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.js';
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-DptZHe-l.js';
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,64 @@ 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. Also runs
490
+ * `ensureFulltextTable` on the success path: drizzle-kit-managed
491
+ * setups create every base table EXCEPT the strategy-owned fulltext
492
+ * table, and the missing-table-error fallback below doesn't trigger
493
+ * once `schema_versions` exists. The focused ensure closes that gap
494
+ * before any `searchable()` write runs.
495
+ */
496
+ declare function loadActiveSchemaWithBootstrap(backend: GraphBackend, graphId: string): Promise<SchemaVersionRow | undefined>;
497
+ /**
498
+ * Reads the active schema, parses it, and folds any persisted graph-extension
499
+ * document into the supplied compile-time graph. Returns the
500
+ * merged graph alongside the prefetched row + parsed schema so the
501
+ * caller can pass them through to `ensureSchema` without paying for a
502
+ * second `getActiveSchema` round trip or a second
503
+ * `serializedSchemaZod` walk.
504
+ *
505
+ * Throws `ConfigurationError` if the persisted graph-extension document
506
+ * references a compile-time kind that no longer exists (the
507
+ * startup-conflict case).
508
+ */
509
+ declare function loadAndMergeGraphExtensionDocument<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<Readonly<{
510
+ graph: G;
511
+ activeRow: SchemaVersionRow | undefined;
512
+ storedSchema: SerializedSchema | undefined;
513
+ }>>;
514
+ /**
515
+ * Returns a graph carrying the supplied deprecated-kind names. Used by
516
+ * the loader to propagate `SerializedSchema.deprecatedKinds` onto the
517
+ * `GraphDef` that the Store sees, and by `Store.deprecateKinds` /
518
+ * `Store.undeprecateKinds` to construct the next graph.
519
+ *
520
+ * Returns the original graph reference when the desired set already
521
+ * matches `graph.deprecatedKinds` — covers both the no-deprecations
522
+ * load path (empty equals empty) and the loader's restart-with-same-
523
+ * persisted-set hot path. Skips a Set allocation + spread + freeze.
524
+ */
525
+ declare function applyDeprecatedKinds<G extends GraphDef>(graph: G, names: Iterable<string> | undefined): G;
370
526
  /**
371
527
  * Result of schema validation.
528
+ *
529
+ * The `initialized` and `migrated` statuses carry the committed
530
+ * `SchemaVersionRow` directly so callers building post-commit metadata
531
+ * (e.g. `Store.deprecateKinds`) can skip a `getActiveSchema` round-trip.
372
532
  */
373
533
  type SchemaValidationResult = {
374
534
  status: "initialized";
375
535
  version: number;
536
+ committedRow: SchemaVersionRow;
376
537
  } | {
377
538
  status: "unchanged";
378
539
  version: number;
@@ -381,6 +542,7 @@ type SchemaValidationResult = {
381
542
  fromVersion: number;
382
543
  toVersion: number;
383
544
  diff: SchemaDiff;
545
+ committedRow: SchemaVersionRow;
384
546
  } | {
385
547
  status: "pending";
386
548
  version: number;
@@ -431,11 +593,27 @@ type SchemaManagerOptions = Readonly<{
431
593
  * @returns The result of schema validation
432
594
  * @throws MigrationError if breaking changes detected and throwOnBreaking is true
433
595
  */
434
- declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions): Promise<SchemaValidationResult>;
596
+ declare function ensureSchema<G extends GraphDef>(backend: GraphBackend, graph: G, options?: SchemaManagerOptions & {
597
+ /**
598
+ * Pre-fetched active row + parsed stored schema. When the loader
599
+ * (`createStoreWithSchema`) has already paid for `getActiveSchema`
600
+ * and `parseSerializedSchema` to peek at `extension`, it
601
+ * passes the results through here so `ensureSchema` doesn't repeat
602
+ * the round trip + Zod walk on every Store boot.
603
+ */
604
+ preloaded?: Readonly<{
605
+ activeRow: SchemaVersionRow | undefined;
606
+ storedSchema: SerializedSchema | undefined;
607
+ }>;
608
+ }): Promise<SchemaValidationResult>;
435
609
  /**
436
610
  * Initializes the schema for a new graph.
437
611
  *
438
- * Creates version 1 of the schema and marks it as active.
612
+ * Creates version 1 of the schema and marks it as active. Goes through
613
+ * the same `commitSchemaVersion` primitive as `migrateSchema` so the
614
+ * initial-commit race (two processes booting against an empty database
615
+ * simultaneously) resolves with `StaleVersionError` or idempotent
616
+ * success rather than a raw PK violation.
439
617
  *
440
618
  * @param backend - The database backend
441
619
  * @param graph - The graph definition
@@ -445,8 +623,12 @@ declare function initializeSchema<G extends GraphDef>(backend: GraphBackend, gra
445
623
  /**
446
624
  * Migrates the schema to match the current graph definition.
447
625
  *
448
- * This creates a new schema version and marks it as active.
449
- * The old version is preserved for history/rollback.
626
+ * Creates a new schema version and atomically activates it via the
627
+ * `commitSchemaVersion` backend primitive — insert and activate happen
628
+ * in a single transactional unit with optimistic compare-and-swap on
629
+ * the currently-active version. If another writer has advanced the
630
+ * active version since `currentVersion` was read, this throws
631
+ * `StaleVersionError`; the caller should refetch and retry.
450
632
  *
451
633
  * @param backend - The database backend
452
634
  * @param graph - The current graph definition
@@ -460,10 +642,16 @@ declare function migrateSchema<G extends GraphDef>(backend: GraphBackend, graph:
460
642
  * The target version must already exist in the version history.
461
643
  * This does not delete newer versions — it simply switches the active pointer.
462
644
  *
645
+ * Uses the `setActiveVersion` backend primitive, which performs the flip
646
+ * atomically with optimistic compare-and-swap on the currently-active
647
+ * version. Concurrent rollbacks or commits surface as
648
+ * `StaleVersionError`.
649
+ *
463
650
  * @param backend - The database backend
464
651
  * @param graphId - The graph ID
465
652
  * @param targetVersion - The version to roll back to
466
653
  * @throws MigrationError if the target version does not exist
654
+ * @throws StaleVersionError if another writer changed the active version concurrently
467
655
  */
468
656
  declare function rollbackSchema(backend: GraphBackend, graphId: string, targetVersion: number): Promise<void>;
469
657
  /**
@@ -491,4 +679,4 @@ declare function isSchemaInitialized(backend: GraphBackend, graphId: string): Pr
491
679
  */
492
680
  declare function getSchemaChanges<G extends GraphDef>(backend: GraphBackend, graph: G): Promise<SchemaDiff | undefined>;
493
681
 
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 };
682
+ 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) {