@nicia-ai/typegraph 0.48.0 → 0.49.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/backend/postgres/index.cjs +3 -3
- package/dist/backend/postgres/index.js +2 -2
- package/dist/backend/postgres/pglite-store.cjs +4 -4
- package/dist/backend/postgres/pglite-store.d.cts +2 -2
- package/dist/backend/postgres/pglite-store.d.ts +2 -2
- package/dist/backend/postgres/pglite-store.js +3 -3
- package/dist/backend/postgres/pglite.cjs +4 -4
- package/dist/backend/postgres/pglite.js +3 -3
- package/dist/backend/sqlite/index.cjs +3 -3
- package/dist/backend/sqlite/index.js +2 -2
- package/dist/backend/sqlite/libsql.cjs +4 -4
- package/dist/backend/sqlite/libsql.js +2 -2
- package/dist/backend/sqlite/local-store.cjs +5 -5
- package/dist/backend/sqlite/local-store.d.cts +2 -2
- package/dist/backend/sqlite/local-store.d.ts +2 -2
- package/dist/backend/sqlite/local-store.js +4 -4
- package/dist/backend/sqlite/local.cjs +5 -5
- package/dist/backend/sqlite/local.js +3 -3
- package/dist/{chunk-TKZXMWQF.cjs → chunk-2O4PCIZ6.cjs} +4 -4
- package/dist/{chunk-TKZXMWQF.cjs.map → chunk-2O4PCIZ6.cjs.map} +1 -1
- package/dist/{chunk-OTUPEF2W.cjs → chunk-3G5W2U2L.cjs} +30 -4
- package/dist/chunk-3G5W2U2L.cjs.map +1 -0
- package/dist/{chunk-WCCATHMB.cjs → chunk-3QNZ5SAJ.cjs} +3 -3
- package/dist/chunk-3QNZ5SAJ.cjs.map +1 -0
- package/dist/{chunk-OD4SSY2U.js → chunk-7LZJNLA5.js} +3 -3
- package/dist/{chunk-OD4SSY2U.js.map → chunk-7LZJNLA5.js.map} +1 -1
- package/dist/{chunk-7XUYFFR4.cjs → chunk-7UOLHNWC.cjs} +5 -5
- package/dist/{chunk-7XUYFFR4.cjs.map → chunk-7UOLHNWC.cjs.map} +1 -1
- package/dist/{chunk-2SYZXD54.js → chunk-D4QLTJSM.js} +3 -3
- package/dist/{chunk-2SYZXD54.js.map → chunk-D4QLTJSM.js.map} +1 -1
- package/dist/{chunk-CT3ZKTOF.js → chunk-JPD2CTC3.js} +3 -3
- package/dist/{chunk-CT3ZKTOF.js.map → chunk-JPD2CTC3.js.map} +1 -1
- package/dist/{chunk-AX6JGVTZ.js → chunk-LTXQOEIC.js} +30 -5
- package/dist/chunk-LTXQOEIC.js.map +1 -0
- package/dist/{chunk-PFBRJBUL.cjs → chunk-UGHQV7MP.cjs} +55 -55
- package/dist/{chunk-PFBRJBUL.cjs.map → chunk-UGHQV7MP.cjs.map} +1 -1
- package/dist/{chunk-4WMMBDS5.js → chunk-WIC7DRXW.js} +3 -3
- package/dist/{chunk-4WMMBDS5.js.map → chunk-WIC7DRXW.js.map} +1 -1
- package/dist/{chunk-2HIYYMWY.cjs → chunk-YYUHLYM2.cjs} +54 -54
- package/dist/{chunk-2HIYYMWY.cjs.map → chunk-YYUHLYM2.cjs.map} +1 -1
- package/dist/{chunk-ACGSAMD3.js → chunk-Z2JCLZFJ.js} +3 -3
- package/dist/chunk-Z2JCLZFJ.js.map +1 -0
- package/dist/graph-merge/index.cjs +28 -5
- package/dist/graph-merge/index.cjs.map +1 -1
- package/dist/graph-merge/index.d.cts +7 -4
- package/dist/graph-merge/index.d.ts +7 -4
- package/dist/graph-merge/index.js +24 -1
- package/dist/graph-merge/index.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/ingestion-import-target-XPxZYw89.d.cts +17 -0
- package/dist/ingestion-import-target-dNeL7iAv.d.ts +17 -0
- package/dist/interchange/index.cjs +25 -25
- package/dist/interchange/index.d.cts +9 -6
- package/dist/interchange/index.d.ts +9 -6
- package/dist/interchange/index.js +2 -2
- package/dist/profiler/index.d.cts +1 -1
- package/dist/profiler/index.d.ts +1 -1
- package/dist/provenance/index.d.cts +1 -1
- package/dist/provenance/index.d.ts +1 -1
- package/dist/{store-UzrGvZOo.d.ts → store-DRrFCx5x.d.ts} +9 -1
- package/dist/{store-JUVvtmR4.d.cts → store-bphCSo7z.d.cts} +9 -1
- package/package.json +2 -3
- package/dist/chunk-ACGSAMD3.js.map +0 -1
- package/dist/chunk-AX6JGVTZ.js.map +0 -1
- package/dist/chunk-OTUPEF2W.cjs.map +0 -1
- package/dist/chunk-WCCATHMB.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/identity/rebuild.ts","../src/identity/types.ts","../src/backend/migrate-vectors.ts"],"names":["storeRuntime","ValidationError","DEFAULT_EMBEDDING_METRIC","DEFAULT_EMBEDDING_INDEX_TYPE","LEGACY_EMBEDDINGS_TABLE_NAME","createDataKeyedBag","isMissingTableError","embedding","EmbeddingDimensionChangedError","requireDefined","sql","asCompiledRowsSql"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,eAAsB,uBAEpB,KAAA,EAAgC;AAChC,EAAA,MAAMA,8BAAA,CAAa,KAAK,CAAA,CAAE,sBAAA,EAAuB;AACnD;;;AC+CO,SAAS,sBAAsB,KAAA,EAAoC;AACxE,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,IAAA,MAAM,IAAIC,iCAAA;AAAA,MACR,mDAAA;AAAA,MACA;AAAA,QACE,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,IAAA,EAAM,uBAAA;AAAA,YACN,OAAA,EAAS;AAAA;AACX;AACF,OACF;AAAA,MACA;AAAA,QACE,UAAA,EAAY;AAAA;AACd,KACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;;;ACjBA,IAAM,kBAAA,GAAqB,GAAA;AAY3B,IAAM,mBAAA,GAAuCC,0CAAA;AAC7C,IAAM,uBAAA,GACJC,8CAAA;AA8HF,eAAsB,wBACpB,OAAA,EACwC;A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D,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,qBAAA,EAAwB,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC3C,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,GAAA,CAAI,OAAO,CAAA,wCAAA;AAAA,KAE/C;AAAA,EACF;AACA,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,KAAK,CAAA,IAAK,MAAA,CAAO,SAAQ,EAAG;AAC7C,IAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACxD,MAAA,MAAM,IAAI,SAAA;AAAA,QACR,wBAAwB,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC3C,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,IAAI,OAAO,CAAA,kCAAA,EACzB,KAAK,CAAA,EAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA,CAAA;AAAA,OAC7C;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["import { type GraphDef, type GraphIdentityConfig } from \"../core/define-graph\";\nimport { storeRuntime } from \"../store/runtime-port\";\nimport { type Store } from \"../store/store\";\n\n/**\n * Rebuilds the derived current identity closure for an identity-enabled store.\n * This is a repair operation: it does not change graph revision or assertions.\n */\nexport async function rebuildIdentityClosure<\n G extends GraphDef & Readonly<{ identity: GraphIdentityConfig }>,\n>(store: Store<G>): Promise<void> {\n await storeRuntime(store).rebuildIdentityClosure();\n}\n","import {\n type AllNodeTypes,\n type GraphDef,\n type NodeKinds,\n} from \"../core/define-graph\";\nimport { ValidationError } from \"../errors\";\nimport {\n type DynamicNode,\n type DynamicNodeReference,\n type GraphNodeReference,\n type Node,\n type NodeRef,\n} from \"../store/types\";\n\n/**\n * The accepted *input* form for every identity facade method: a whole node or\n * a `{ kind, id }` pair for any compile-time graph kind, plus a proof-bearing\n * node or reference produced through the runtime collection lane. Runtime\n * values stay nominal so accepting them does not make an arbitrary\n * `{ kind: string, id: string }` object type-safe.\n *\n * Identity results use {@link IdentityNodeReference}, which honestly includes\n * runtime kinds because an evolved kind can belong to a class reached from a\n * compile-time node.\n */\nexport type IdentityNodeRefInput<G extends GraphDef> =\n NodeRef<AllNodeTypes<G>> | DynamicNode | DynamicNodeReference;\n\n/**\n * A node reference returned by Operational Identity.\n *\n * Identity classes can contain runtime-evolved kinds even when a read starts\n * from a compile-time node, so results honestly include both lanes.\n */\nexport type IdentityNodeReference<G extends GraphDef> =\n GraphNodeReference<G> | DynamicNodeReference;\n\n/** A hydrated compile-time or runtime identity member. */\nexport type IdentityNode<G extends GraphDef> =\n | {\n [K in NodeKinds<G>]: Node<G[\"nodes\"][K][\"type\"]>;\n }[NodeKinds<G>]\n | DynamicNode;\n\ndeclare const __identityAssertionId: unique symbol;\n\nexport type IdentityAssertionId = string &\n Readonly<{ [__identityAssertionId]: true }>;\n\n/**\n * Brands a non-empty string as an {@link IdentityAssertionId}.\n *\n * Use this when a persisted identity assertion id has round-tripped through\n * untyped storage or an external boundary and must be passed back to a\n * retraction surface such as `retractAssertion` or `bulkRetractAssertions`.\n * Mirrors the `asNodeId` / `asEdgeId` precedent.\n *\n * @throws {ValidationError} when `value` is empty.\n */\nexport function asIdentityAssertionId(value: string): IdentityAssertionId {\n if (value.length === 0) {\n throw new ValidationError(\n \"asIdentityAssertionId must be a non-empty string.\",\n {\n issues: [\n {\n path: \"asIdentityAssertionId\",\n message: \"Expected a non-empty string.\",\n },\n ],\n },\n {\n suggestion: \"Use a persisted identity assertion id value.\",\n },\n );\n }\n return value as IdentityAssertionId;\n}\n\n/**\n * What one assertion claims about a pair of nodes: `\"same\"` merges them into\n * one equivalence set, `\"different\"` records a disjointness that a later\n * `\"same\"` claim must not contradict.\n */\nexport type IdentityRelation = \"same\" | \"different\";\n\n/**\n * One persisted identity claim about an ordered pair of nodes. Returned by the\n * assertion writers and by `identity.assertionsOf(...)`; `validTo` is set when\n * the assertion has been retracted, so a historical read can still see it.\n */\nexport type IdentityAssertion<G extends GraphDef> = Readonly<{\n id: IdentityAssertionId;\n relation: IdentityRelation;\n a: IdentityNodeReference<G>;\n b: IdentityNodeReference<G>;\n validFrom: string;\n validTo?: string;\n}>;\n\n/** Result of an idempotent assertion write. */\nexport type IdentityAssertionResult<G extends GraphDef> = Readonly<{\n assertion: IdentityAssertion<G>;\n action: \"created\" | \"existing\";\n}>;\n\n/** The half-open effective-time window of an identity assertion. */\nexport type IdentityValidityWindow = Readonly<{\n validFrom?: string;\n validTo?: string;\n}>;\n\n/** One ordered node pair handed to `bulkAssertSame` / `bulkAssertDifferent`. */\nexport type IdentityPair<G extends GraphDef> = Readonly<{\n a: IdentityNodeRefInput<G>;\n b: IdentityNodeRefInput<G>;\n}> &\n IdentityValidityWindow;\n\n/**\n * The read half of the identity surface: equivalence-set membership,\n * representative selection, and the assertions behind them.\n *\n * Obtained from a read-only lens — `store.asOf(...).identity`,\n * `store.snapshot().identity` — where it answers at that view's coordinate.\n * The full read+write surface is {@link IdentityFacade}.\n */\nexport type IdentityReadFacade<G extends GraphDef> = Readonly<{\n representativeOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<IdentityNodeReference<G> | undefined>;\n membersOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNodeReference<G>[]>;\n nodesOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNode<G>[]>;\n areSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n areDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n assertionsOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityAssertion<G>[]>;\n}>;\n\n/**\n * The full TypeGraph Identity Profile surface: {@link IdentityReadFacade} plus\n * the assertion writers and retractions.\n *\n * Obtained from `store.identity` or `tx.identity`, and present only on graphs\n * that declared `identity: { ... }` in `defineGraph`. Every writer is\n * idempotent — re-asserting an existing claim returns it with\n * `action: \"existing\"` rather than duplicating it.\n */\nexport type IdentityFacade<G extends GraphDef> = IdentityReadFacade<G> &\n Readonly<{\n assertSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n assertDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n bulkAssertSame: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n bulkAssertDifferent: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n retractAssertion: (\n id: IdentityAssertionId,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractSameAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractDifferentAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n bulkRetractAssertions: (\n ids: readonly IdentityAssertionId[],\n ) => Promise<readonly IdentityAssertion<G>[]>;\n }>;\n\n/**\n * Per-transaction identity write counts carried by a transaction receipt.\n * `total` is the sum of the three preceding counters.\n */\nexport type IdentityWriteSummary = Readonly<{\n sameAssertions: number;\n differentAssertions: number;\n retractions: number;\n total: number;\n}>;\n","/**\n * One-time offline migration: legacy shared embeddings table → per-field\n * strategy storage.\n *\n * ## What this is for\n *\n * The cross-backend vector cutover (#157) dropped the single shared\n * `typegraph_node_embeddings` table. Each\n * `VectorStrategy` now OWNS one typed, fixed-dimension structure per\n * `(nodeKind, fieldPath)` — the only layout that can be ANN-indexed on\n * libSQL and sqlite-vec, not just pgvector.\n *\n * Deployments that wrote embeddings under the old shared table before\n * upgrading still hold those rows. This utility drains them into the new\n * per-field storage **once**, during the upgrade, so existing embedded\n * data survives the cutover without re-embedding from source.\n *\n * It is an explicitly-run, offline step — not wired into `materializeIndexes`\n * or any boot path. Run it once after deploying the new version and before\n * (or alongside) the first `materializeIndexes()`, then drop the legacy\n * table at your leisure.\n *\n * ## How it works\n *\n * - Skips cleanly (returns a zero summary) when the legacy table is absent —\n * a fresh install, or a re-run after the table was dropped.\n * - Reads rows in keyset-paginated batches (never the whole table at once),\n * decoding the engine-native embedding column to a numeric array at the SQL\n * level: sqlite-vec stored a `vec_f32` blob (`vec_to_json` decodes it);\n * pgvector stored a native `vector` (`::text` yields a `[…]` literal).\n * - Re-inserts each row through `backend.upsertEmbedding`, which routes the\n * active strategy's `buildUpsert` and idempotently provisions the per-field\n * storage (the same `(nodeKind, fieldPath)` slot a fresh store write uses).\n * The migration stays graph-agnostic and execution-correct on both the\n * sync (better-sqlite3) and async (libsql / Postgres) backends — it does\n * not re-implement the backend's statement-execution glue.\n *\n * Idempotent and resumable: a partial run followed by a full run converges\n * to the same per-field tables, because every write is an upsert keyed by\n * `(graph_id, node_id)` in the strategy's owned storage.\n */\nimport {\n DEFAULT_EMBEDDING_INDEX_TYPE,\n DEFAULT_EMBEDDING_METRIC,\n type EmbeddingIndexType,\n type EmbeddingMetric,\n} from \"../core/embedding\";\nimport { EmbeddingDimensionChangedError } from \"../errors\";\nimport { sql, type SqlFragment } from \"../query/sql-fragment\";\nimport { asCompiledRowsSql } from \"../query/sql-intent\";\nimport { createDataKeyedBag } from \"../utils/object\";\nimport { requireDefined } from \"../utils/presence\";\nimport { isMissingTableError } from \"../utils/sql-errors\";\nimport { LEGACY_EMBEDDINGS_TABLE_NAME } from \"./drizzle/schema/sqlite\";\nimport { type GraphBackend } from \"./types\";\n\n/**\n * Default rows read per round-trip. Large enough to amortize round-trip\n * latency, small enough to bound peak memory regardless of table size.\n */\nconst DEFAULT_BATCH_SIZE = 500;\n\n/**\n * Metric / index type applied to a migrated field when no\n * {@link MigrateLegacyEmbeddingsOptions.resolveSlotConfig} is supplied (or\n * it returns `undefined`). Matches the defaults `embedding()` and\n * `resolveEmbeddingFields` apply, so a migrated field lands in storage shaped\n * identically to one written fresh through the store. Migrated data is only\n * ever brute-forceable until `materializeIndexes()` builds the ANN index, so\n * the index-type default governs only which ANN structure the per-field\n * storage DDL provisions, not the migration's correctness.\n */\nconst DEFAULT_SLOT_METRIC: EmbeddingMetric = DEFAULT_EMBEDDING_METRIC;\nconst DEFAULT_SLOT_INDEX_TYPE: EmbeddingIndexType =\n DEFAULT_EMBEDDING_INDEX_TYPE;\n\n/**\n * The resolved storage config for one `(nodeKind, fieldPath)` slot that the\n * legacy table did not record. The legacy shared table stored only the\n * vector and its dimension count — not the metric or index type — so a\n * caller that wants migrated fields to match a specific graph's `embedding()`\n * declarations supplies this resolver.\n */\nexport type LegacyEmbeddingSlotConfig = Readonly<{\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n}>;\n\n/**\n * Options for {@link migrateLegacyEmbeddings}.\n */\nexport type MigrateLegacyEmbeddingsOptions = Readonly<{\n /**\n * The backend to migrate, wired with the destination `VectorStrategy`\n * (i.e. the post-cutover backend). Its `vectorStrategy` owns the per-field\n * storage rows are written into and its `upsertEmbedding` performs the\n * writes.\n */\n backend: GraphBackend;\n\n /**\n * Restrict the migration to a single graph. When omitted, every graph's\n * rows in the legacy table are migrated (the table is graph-scoped by its\n * `graph_id` column).\n */\n graphId?: string;\n\n /**\n * Resolves the metric / index type for a `(nodeKind, fieldPath)` slot the\n * legacy table didn't persist. Return `undefined` to fall back to the\n * cosine / hnsw defaults. Supply this (typically reading the graph's\n * `embedding()` declarations) when migrated fields must match a specific\n * metric — e.g. an `l2` field, which scores incorrectly under the cosine\n * default.\n */\n resolveSlotConfig?: (\n nodeKind: string,\n fieldPath: string,\n ) => LegacyEmbeddingSlotConfig | undefined;\n\n /** Rows read per round-trip. Defaults to {@link DEFAULT_BATCH_SIZE}. */\n batchSize?: number;\n\n /**\n * Physical name of the legacy table to drain. Defaults to\n * {@link LEGACY_EMBEDDINGS_TABLE_NAME}. Override only for a non-default\n * deployment that renamed the embeddings table.\n */\n legacyTableName?: string;\n}>;\n\n/**\n * Summary of a {@link migrateLegacyEmbeddings} run.\n */\nexport type MigrateLegacyEmbeddingsResult = Readonly<{\n /** Total embedding rows re-inserted into per-field storage. */\n migrated: number;\n /**\n * Per-`(nodeKind, fieldPath)` counts, keyed `\"<nodeKind>.<fieldPath>\"`\n * (the strategy's logical-slot key form). Empty when the legacy table was\n * absent or held no rows for the requested scope.\n */\n perField: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their vector length didn't match the per-field\n * table's fixed dimension. The legacy shared column allowed mixed\n * dimensions for one `(nodeKind, fieldPath)` (e.g. an unmigrated model\n * change); the first migrated row fixes the typed table's dimension and\n * any differently-sized rows for that slot are skipped rather than aborting\n * the whole migration. Keyed `\"<nodeKind>.<fieldPath>\"`. Non-empty here\n * means those fields need a deliberate re-embed at a single dimension.\n */\n skippedDimensionMismatch: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their legacy embedding could not be decoded into a\n * finite-number array — a corrupt value (e.g. a pgvector `vector` column\n * permits `NaN`/`Infinity`, which is not valid JSON). Keyed\n * `\"<nodeKind>.<fieldPath>\"`. Skipping + reporting keeps one bad row from\n * aborting the whole migration; non-empty here means those rows need manual\n * repair.\n */\n skippedDecodeError: Readonly<Record<string, number>>;\n /**\n * Whether the legacy table existed. `false` means the run was a clean\n * no-op (fresh install, or already-dropped table on a re-run).\n */\n legacyTablePresent: boolean;\n}>;\n\n/**\n * A single legacy embedding row, with the engine-native vector already\n * decoded to a JSON array string by the dialect-specific SELECT. The\n * legacy `dimensions` column is intentionally not read: the decoded array's\n * length is the authoritative fixed dimension for the destination slot, and\n * relying on it sidesteps the per-driver string/number coercion the legacy\n * integer column would otherwise need.\n */\ntype LegacyEmbeddingRow = Readonly<{\n graph_id: string;\n node_kind: string;\n node_id: string;\n field_path: string;\n /** JSON array text, e.g. `\"[0.1,0.2,0.3]\"` — decoded per dialect. */\n embedding_json: string;\n}>;\n\n/**\n * Re-inserts every embedding from the legacy shared\n * `typegraph_node_embeddings` table into the active\n * `backend.vectorStrategy`'s per-`(nodeKind, fieldPath)` storage.\n *\n * One-time, explicitly-run upgrade step for the shared-table → per-field\n * cutover (#157). Idempotent, batched, and a clean no-op when the legacy\n * table is absent. See the module doc comment for the full contract.\n *\n * @throws Error when the backend exposes no `vectorStrategy` /\n * `upsertEmbedding` (nothing to migrate *into*) — a configuration\n * error the caller must fix by wiring the destination strategy\n * before migrating.\n */\nexport async function migrateLegacyEmbeddings(\n options: MigrateLegacyEmbeddingsOptions,\n): Promise<MigrateLegacyEmbeddingsResult> {\n const {\n backend,\n graphId,\n resolveSlotConfig,\n batchSize = DEFAULT_BATCH_SIZE,\n legacyTableName = LEGACY_EMBEDDINGS_TABLE_NAME,\n } = options;\n\n if (\n backend.vectorStrategy === undefined ||\n backend.upsertEmbedding === undefined\n ) {\n throw new Error(\n \"migrateLegacyEmbeddings requires a backend wired with a vectorStrategy \" +\n \"(the destination per-field storage). Pass the post-cutover backend.\",\n );\n }\n if (!Number.isInteger(batchSize) || batchSize <= 0) {\n throw new RangeError(\n `batchSize must be a positive integer, got: ${batchSize}`,\n );\n }\n const upsertEmbedding = backend.upsertEmbedding;\n const ensureVectorSlotContribution = backend.ensureVectorSlotContribution;\n\n // Data-keyed: slot keys are built from a row's `node_kind` / `field_path`.\n const perField = createDataKeyedBag<number>();\n const skippedDimensionMismatch = createDataKeyedBag<number>();\n const skippedDecodeError = createDataKeyedBag<number>();\n // (kind, field) slots whose per-field table + durable marker this run has\n // already provisioned, mapped to the dimension the table was fixed at.\n // `upsertEmbedding` asserts the marker (#135) and no longer self-creates\n // the table, so this offline migration (privileged) provisions each slot\n // once — at the first row's dimension, which fixes the typed table just as\n // the original lazy write did. Differently-sized later rows for the same\n // slot are detected against this map and skipped BEFORE the upsert: the\n // marker assert would otherwise read the differently-dimensioned slot as\n // stale and abort the whole migration, and the ensure is deliberately not\n // re-run per row (that would trip the marker drift-guard).\n const ensuredSlots = new Map<string, number>();\n let migrated = 0;\n\n let cursor: LegacyRowCursor | undefined;\n for (;;) {\n let batch: readonly LegacyEmbeddingRow[];\n try {\n batch = await readLegacyBatch(backend, {\n legacyTableName,\n graphId,\n batchSize,\n after: cursor,\n });\n } catch (error) {\n // A missing legacy table is the expected \"nothing to migrate\" path on\n // the first read — surface it as a clean no-op, not a failure.\n if (cursor === undefined && isMissingTableError(error)) {\n return {\n migrated: 0,\n perField: {},\n skippedDimensionMismatch: {},\n skippedDecodeError: {},\n legacyTablePresent: false,\n };\n }\n throw error;\n }\n\n if (batch.length === 0) break;\n\n for (const row of batch) {\n const slotKey = `${row.node_kind}.${row.field_path}`;\n\n let embedding: readonly number[];\n try {\n embedding = decodeEmbeddingJson(row);\n } catch {\n // A corrupt legacy value (e.g. a pgvector `vector` column permits\n // NaN/Infinity, which is not valid JSON) is skipped + reported rather\n // than aborting the whole migration on one bad row.\n skippedDecodeError[slotKey] = (skippedDecodeError[slotKey] ?? 0) + 1;\n continue;\n }\n const config = resolveSlotConfig?.(row.node_kind, row.field_path);\n // The decoded length is the authoritative fixed dimension — the\n // strategy provisions its column type (e.g. `F32_BLOB(N)`) from it.\n const slot = {\n graphId: row.graph_id,\n nodeKind: row.node_kind,\n fieldPath: row.field_path,\n dimensions: embedding.length,\n metric: config?.metric ?? DEFAULT_SLOT_METRIC,\n indexType: config?.indexType ?? DEFAULT_SLOT_INDEX_TYPE,\n };\n\n // Provision the per-field table + durable marker before the first\n // write into this slot. Once per (graph, kind, field): the first row's\n // dimension fixes the table. Keyed by graph id too — the legacy table\n // is graph-scoped, so the same `kind.field` can recur across graphs.\n const ensuredKey = JSON.stringify([\n row.graph_id,\n row.node_kind,\n row.field_path,\n ]);\n if (\n ensureVectorSlotContribution !== undefined &&\n !ensuredSlots.has(ensuredKey)\n ) {\n await ensureVectorSlotContribution(slot);\n ensuredSlots.set(ensuredKey, slot.dimensions);\n }\n\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension. Skip a differently-sized row up front —\n // its slot would fail the marker assert as stale (different\n // signature), aborting the migration instead of skipping the row.\n const provisionedDimensions = ensuredSlots.get(ensuredKey);\n if (\n provisionedDimensions !== undefined &&\n provisionedDimensions !== embedding.length\n ) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n\n try {\n await upsertEmbedding({ ...slot, nodeId: row.node_id, embedding });\n } catch (error) {\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension, so a differently-sized row is skipped and\n // reported rather than aborting the whole migration.\n if (error instanceof EmbeddingDimensionChangedError) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n throw error;\n }\n\n migrated += 1;\n perField[slotKey] = (perField[slotKey] ?? 0) + 1;\n }\n\n if (batch.length < batchSize) break;\n const last = requireDefined(batch.at(-1));\n cursor = {\n graphId: last.graph_id,\n nodeKind: last.node_kind,\n nodeId: last.node_id,\n fieldPath: last.field_path,\n };\n }\n\n // SPREAD at the boundary. The three maps are null-prototype accumulators\n // because their keys are slot names built from row data; that protection is\n // internal, and returning the bags as-is handed a caller three maps with no\n // `toString` and `instanceof Object === false` — while the early\n // \"nothing to migrate\" return above hands back `{}` literals, so the same\n // exported function answered with two different kinds of object depending on\n // whether the legacy table existed. Spread copies own properties with\n // CreateDataProperty, so a `__proto__` slot key survives as an own key.\n return {\n migrated,\n perField: { ...perField },\n skippedDimensionMismatch: { ...skippedDimensionMismatch },\n skippedDecodeError: { ...skippedDecodeError },\n legacyTablePresent: true,\n };\n}\n\n/**\n * Composite keyset cursor over the legacy table's primary key\n * `(graph_id, node_kind, node_id, field_path)`. Stable under concurrent\n * writes and immune to OFFSET drift, so a batched walk reads every row once.\n */\ntype LegacyRowCursor = Readonly<{\n graphId: string;\n nodeKind: string;\n nodeId: string;\n fieldPath: string;\n}>;\n\ntype ReadLegacyBatchParams = Readonly<{\n legacyTableName: string;\n graphId: string | undefined;\n batchSize: number;\n after: LegacyRowCursor | undefined;\n}>;\n\n/**\n * Reads one keyset-paginated batch of legacy rows, ordered by the primary\n * key, with the engine-native embedding column decoded to a JSON array\n * string by the dialect.\n */\nasync function readLegacyBatch(\n backend: GraphBackend,\n params: ReadLegacyBatchParams,\n): Promise<readonly LegacyEmbeddingRow[]> {\n const table = sql.identifier(params.legacyTableName);\n const embeddingJson = legacyEmbeddingDecodeExpression(backend);\n\n const conditions: SqlFragment[] = [];\n if (params.graphId !== undefined) {\n conditions.push(sql`\"graph_id\" = ${params.graphId}`);\n }\n if (params.after !== undefined) {\n conditions.push(keysetAfterCondition(params.after));\n }\n\n const whereClause =\n conditions.length === 0 ?\n sql``\n : sql` WHERE ${sql.join(conditions, sql` AND `)}`;\n\n const query = sql`\n SELECT\n \"graph_id\" AS graph_id,\n \"node_kind\" AS node_kind,\n \"node_id\" AS node_id,\n \"field_path\" AS field_path,\n ${embeddingJson} AS embedding_json\n FROM ${table}${whereClause}\n ORDER BY \"graph_id\" ASC, \"node_kind\" ASC, \"node_id\" ASC, \"field_path\" ASC\n LIMIT ${params.batchSize}\n `;\n\n return backend.execute<LegacyEmbeddingRow>(asCompiledRowsSql(query));\n}\n\n/**\n * The strict `>` comparison over the composite primary key, expressed as\n * the standard lexicographic OR-chain so it works on every dialect (SQLite\n * supports row-value comparison, but Postgres + SQLite both accept this\n * portable form).\n */\nfunction keysetAfterCondition(after: LegacyRowCursor): SqlFragment {\n return sql`\n (\n \"graph_id\" > ${after.graphId}\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" > ${after.nodeKind})\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" = ${after.nodeKind} AND \"node_id\" > ${after.nodeId})\n OR (\n \"graph_id\" = ${after.graphId}\n AND \"node_kind\" = ${after.nodeKind}\n AND \"node_id\" = ${after.nodeId}\n AND \"field_path\" > ${after.fieldPath}\n )\n )\n `;\n}\n\n/**\n * The SQL expression that decodes the legacy engine-native embedding column\n * into a JSON array string `embedding_json`. The single dialect branch in\n * this whole module: the legacy storage formats are genuinely engine-\n * specific, and there is no longer a strategy abstraction over the *legacy*\n * table to delegate to.\n */\nfunction legacyEmbeddingDecodeExpression(backend: GraphBackend): SqlFragment {\n switch (backend.dialect) {\n case \"sqlite\": {\n // Legacy SQLite embeddings were written via `vec_f32('[…]')`\n // (sqlite-vec binary). `vec_to_json` is its inverse, yielding the\n // JSON array text. Requires sqlite-vec on the connection — which the\n // legacy write path also required, so any deployment with legacy rows\n // has it loaded.\n return sql`vec_to_json(\"embedding\")`;\n }\n case \"postgres\": {\n // pgvector's native `vector` casts to its `[…]` text literal, which is\n // valid JSON for `JSON.parse`.\n return sql`\"embedding\"::text`;\n }\n default: {\n const _exhaustive: never = backend.dialect;\n throw new Error(\n `migrateLegacyEmbeddings does not support dialect: ${String(_exhaustive)}`,\n );\n }\n }\n}\n\n/**\n * Parses a decoded `embedding_json` array, asserting it is a non-empty array\n * of finite numbers. A bad decode (wrong type, NaN) names the offending row\n * loudly instead of writing a corrupt vector into per-field storage.\n */\nfunction decodeEmbeddingJson(row: LegacyEmbeddingRow): readonly number[] {\n let parsed: unknown;\n try {\n parsed = JSON.parse(row.embedding_json) as unknown;\n } catch (error) {\n throw new Error(\n `Failed to decode legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}): not valid JSON.`,\n { cause: error },\n );\n }\n if (!Array.isArray(parsed) || parsed.length === 0) {\n throw new Error(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) decoded to a non-array ` +\n `or empty value.`,\n );\n }\n for (const [index, value] of parsed.entries()) {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new TypeError(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) has a non-finite ` +\n `value at index ${index}: ${String(value)}.`,\n );\n }\n }\n return parsed as readonly number[];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/identity/rebuild.ts","../src/identity/types.ts","../src/backend/migrate-vectors.ts"],"names":["storeRuntime","ValidationError","DEFAULT_EMBEDDING_METRIC","DEFAULT_EMBEDDING_INDEX_TYPE","LEGACY_EMBEDDINGS_TABLE_NAME","createDataKeyedBag","isMissingTableError","embedding","EmbeddingDimensionChangedError","requireDefined","sql","asCompiledRowsSql"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,eAAsB,uBAEpB,KAAA,EAAgC;AAChC,EAAA,MAAMA,8BAAA,CAAa,KAAK,CAAA,CAAE,sBAAA,EAAuB;AACnD;;;AC+CO,SAAS,sBAAsB,KAAA,EAAoC;AACxE,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,IAAA,MAAM,IAAIC,iCAAA;AAAA,MACR,mDAAA;AAAA,MACA;AAAA,QACE,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,IAAA,EAAM,uBAAA;AAAA,YACN,OAAA,EAAS;AAAA;AACX;AACF,OACF;AAAA,MACA;AAAA,QACE,UAAA,EAAY;AAAA;AACd,KACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;;;ACjBA,IAAM,kBAAA,GAAqB,GAAA;AAY3B,IAAM,mBAAA,GAAuCC,0CAAA;AAC7C,IAAM,uBAAA,GACJC,8CAAA;AA8HF,eAAsB,wBACpB,OAAA,EACwC;AACxC,EAAA,MAAM;AAAA,IACJ,OAAA;AAAA,IACA,OAAA;AAAA,IACA,iBAAA;AAAA,IACA,SAAA,GAAY,kBAAA;AAAA,IACZ,eAAA,GAAkBC;AAAA,GAC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A,CAAI,QAAQ,CAAA,OAAA,EAAU,GAAA,CAAI,OAAO,CAAA,wCAAA;AAAA,KAE/C;AAAA,EACF;AACA,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,KAAK,CAAA,IAAK,MAAA,CAAO,SAAQ,EAAG;AAC7C,IAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACxD,MAAA,MAAM,IAAI,SAAA;AAAA,QACR,wBAAwB,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC3C,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,IAAI,OAAO,CAAA,kCAAA,EACzB,KAAK,CAAA,EAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA,CAAA;AAAA,OAC7C;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["import { type GraphDef, type GraphIdentityConfig } from \"../core/define-graph\";\nimport { storeRuntime } from \"../store/runtime-port\";\nimport { type Store } from \"../store/store\";\n\n/**\n * Rebuilds the derived current identity closure for an identity-enabled store.\n * This is a repair operation: it does not change graph revision or assertions.\n */\nexport async function rebuildIdentityClosure<\n G extends GraphDef & Readonly<{ identity: GraphIdentityConfig }>,\n>(store: Store<G>): Promise<void> {\n await storeRuntime(store).rebuildIdentityClosure();\n}\n","import {\n type AllNodeTypes,\n type GraphDef,\n type NodeKinds,\n} from \"../core/define-graph\";\nimport { ValidationError } from \"../errors\";\nimport {\n type DynamicNode,\n type DynamicNodeReference,\n type GraphNodeReference,\n type Node,\n type NodeRef,\n} from \"../store/types\";\n\n/**\n * The accepted *input* form for every identity facade method: a whole node or\n * a `{ kind, id }` pair for any compile-time graph kind, plus a proof-bearing\n * node or reference produced through the runtime collection lane. Runtime\n * values stay nominal so accepting them does not make an arbitrary\n * `{ kind: string, id: string }` object type-safe.\n *\n * Identity results use {@link IdentityNodeReference}, which honestly includes\n * runtime kinds because an evolved kind can belong to a class reached from a\n * compile-time node.\n */\nexport type IdentityNodeRefInput<G extends GraphDef> =\n NodeRef<AllNodeTypes<G>> | DynamicNode | DynamicNodeReference;\n\n/**\n * A node reference returned by Operational Identity.\n *\n * Identity classes can contain runtime-evolved kinds even when a read starts\n * from a compile-time node, so results honestly include both lanes.\n */\nexport type IdentityNodeReference<G extends GraphDef> =\n GraphNodeReference<G> | DynamicNodeReference;\n\n/** A hydrated compile-time or runtime identity member. */\nexport type IdentityNode<G extends GraphDef> =\n | {\n [K in NodeKinds<G>]: Node<G[\"nodes\"][K][\"type\"]>;\n }[NodeKinds<G>]\n | DynamicNode;\n\ndeclare const __identityAssertionId: unique symbol;\n\nexport type IdentityAssertionId = string &\n Readonly<{ [__identityAssertionId]: true }>;\n\n/**\n * Brands a non-empty string as an {@link IdentityAssertionId}.\n *\n * Use this when a persisted identity assertion id has round-tripped through\n * untyped storage or an external boundary and must be passed back to a\n * retraction surface such as `retractAssertion` or `bulkRetractAssertions`.\n * Mirrors the `asNodeId` / `asEdgeId` precedent.\n *\n * @throws {ValidationError} when `value` is empty.\n */\nexport function asIdentityAssertionId(value: string): IdentityAssertionId {\n if (value.length === 0) {\n throw new ValidationError(\n \"asIdentityAssertionId must be a non-empty string.\",\n {\n issues: [\n {\n path: \"asIdentityAssertionId\",\n message: \"Expected a non-empty string.\",\n },\n ],\n },\n {\n suggestion: \"Use a persisted identity assertion id value.\",\n },\n );\n }\n return value as IdentityAssertionId;\n}\n\n/**\n * What one assertion claims about a pair of nodes: `\"same\"` merges them into\n * one equivalence set, `\"different\"` records a disjointness that a later\n * `\"same\"` claim must not contradict.\n */\nexport type IdentityRelation = \"same\" | \"different\";\n\n/**\n * One persisted identity claim about an ordered pair of nodes. Returned by the\n * assertion writers and by `identity.assertionsOf(...)`; `validTo` is set when\n * the assertion has been retracted, so a historical read can still see it.\n */\nexport type IdentityAssertion<G extends GraphDef> = Readonly<{\n id: IdentityAssertionId;\n relation: IdentityRelation;\n a: IdentityNodeReference<G>;\n b: IdentityNodeReference<G>;\n validFrom: string;\n validTo?: string;\n}>;\n\n/** Result of an idempotent assertion write. */\nexport type IdentityAssertionResult<G extends GraphDef> = Readonly<{\n assertion: IdentityAssertion<G>;\n action: \"created\" | \"existing\";\n}>;\n\n/** The half-open effective-time window of an identity assertion. */\nexport type IdentityValidityWindow = Readonly<{\n validFrom?: string;\n validTo?: string;\n}>;\n\n/** One ordered node pair handed to `bulkAssertSame` / `bulkAssertDifferent`. */\nexport type IdentityPair<G extends GraphDef> = Readonly<{\n a: IdentityNodeRefInput<G>;\n b: IdentityNodeRefInput<G>;\n}> &\n IdentityValidityWindow;\n\n/**\n * The read half of the identity surface: equivalence-set membership,\n * representative selection, and the assertions behind them.\n *\n * Obtained from a read-only lens — `store.asOf(...).identity`,\n * `store.snapshot().identity` — where it answers at that view's coordinate.\n * The full read+write surface is {@link IdentityFacade}.\n */\nexport type IdentityReadFacade<G extends GraphDef> = Readonly<{\n representativeOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<IdentityNodeReference<G> | undefined>;\n membersOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNodeReference<G>[]>;\n nodesOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNode<G>[]>;\n areSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n areDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n assertionsOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityAssertion<G>[]>;\n}>;\n\n/**\n * The full TypeGraph Identity Profile surface: {@link IdentityReadFacade} plus\n * the assertion writers and retractions.\n *\n * Obtained from `store.identity` or `tx.identity`, and present only on graphs\n * that declared `identity: { ... }` in `defineGraph`. Every writer is\n * idempotent — re-asserting an existing claim returns it with\n * `action: \"existing\"` rather than duplicating it.\n */\nexport type IdentityFacade<G extends GraphDef> = IdentityReadFacade<G> &\n Readonly<{\n assertSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n assertDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n bulkAssertSame: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n bulkAssertDifferent: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n retractAssertion: (\n id: IdentityAssertionId,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractSameAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractDifferentAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n bulkRetractAssertions: (\n ids: readonly IdentityAssertionId[],\n ) => Promise<readonly IdentityAssertion<G>[]>;\n }>;\n\n/**\n * The assertion-only write surface of the TypeGraph Identity Profile.\n *\n * This deliberately excludes reads and retractions so constrained staging\n * handles can accept incoming identity claims without exposing the broader\n * operational identity surface.\n */\nexport type IdentityAssertionWriteFacade<G extends GraphDef> = Pick<\n IdentityFacade<G>,\n \"assertSame\" | \"assertDifferent\" | \"bulkAssertSame\" | \"bulkAssertDifferent\"\n>;\n\n/**\n * Per-transaction identity write counts carried by a transaction receipt.\n * `total` is the sum of the three preceding counters.\n */\nexport type IdentityWriteSummary = Readonly<{\n sameAssertions: number;\n differentAssertions: number;\n retractions: number;\n total: number;\n}>;\n","/**\n * One-time offline migration: legacy shared embeddings table → per-field\n * strategy storage.\n *\n * ## What this is for\n *\n * The cross-backend vector cutover (#157) dropped the single shared\n * `typegraph_node_embeddings` table. Each\n * `VectorStrategy` now OWNS one typed, fixed-dimension structure per\n * `(nodeKind, fieldPath)` — the only layout that can be ANN-indexed on\n * libSQL and sqlite-vec, not just pgvector.\n *\n * Deployments that wrote embeddings under the old shared table before\n * upgrading still hold those rows. This utility drains them into the new\n * per-field storage **once**, during the upgrade, so existing embedded\n * data survives the cutover without re-embedding from source.\n *\n * It is an explicitly-run, offline step — not wired into `materializeIndexes`\n * or any boot path. Run it once after deploying the new version and before\n * (or alongside) the first `materializeIndexes()`, then drop the legacy\n * table at your leisure.\n *\n * ## How it works\n *\n * - Skips cleanly (returns a zero summary) when the legacy table is absent —\n * a fresh install, or a re-run after the table was dropped.\n * - Reads rows in keyset-paginated batches (never the whole table at once),\n * decoding the engine-native embedding column to a numeric array at the SQL\n * level: sqlite-vec stored a `vec_f32` blob (`vec_to_json` decodes it);\n * pgvector stored a native `vector` (`::text` yields a `[…]` literal).\n * - Re-inserts each row through `backend.upsertEmbedding`, which routes the\n * active strategy's `buildUpsert` and idempotently provisions the per-field\n * storage (the same `(nodeKind, fieldPath)` slot a fresh store write uses).\n * The migration stays graph-agnostic and execution-correct on both the\n * sync (better-sqlite3) and async (libsql / Postgres) backends — it does\n * not re-implement the backend's statement-execution glue.\n *\n * Idempotent and resumable: a partial run followed by a full run converges\n * to the same per-field tables, because every write is an upsert keyed by\n * `(graph_id, node_id)` in the strategy's owned storage.\n */\nimport {\n DEFAULT_EMBEDDING_INDEX_TYPE,\n DEFAULT_EMBEDDING_METRIC,\n type EmbeddingIndexType,\n type EmbeddingMetric,\n} from \"../core/embedding\";\nimport { EmbeddingDimensionChangedError } from \"../errors\";\nimport { sql, type SqlFragment } from \"../query/sql-fragment\";\nimport { asCompiledRowsSql } from \"../query/sql-intent\";\nimport { createDataKeyedBag } from \"../utils/object\";\nimport { requireDefined } from \"../utils/presence\";\nimport { isMissingTableError } from \"../utils/sql-errors\";\nimport { LEGACY_EMBEDDINGS_TABLE_NAME } from \"./drizzle/schema/sqlite\";\nimport { type GraphBackend } from \"./types\";\n\n/**\n * Default rows read per round-trip. Large enough to amortize round-trip\n * latency, small enough to bound peak memory regardless of table size.\n */\nconst DEFAULT_BATCH_SIZE = 500;\n\n/**\n * Metric / index type applied to a migrated field when no\n * {@link MigrateLegacyEmbeddingsOptions.resolveSlotConfig} is supplied (or\n * it returns `undefined`). Matches the defaults `embedding()` and\n * `resolveEmbeddingFields` apply, so a migrated field lands in storage shaped\n * identically to one written fresh through the store. Migrated data is only\n * ever brute-forceable until `materializeIndexes()` builds the ANN index, so\n * the index-type default governs only which ANN structure the per-field\n * storage DDL provisions, not the migration's correctness.\n */\nconst DEFAULT_SLOT_METRIC: EmbeddingMetric = DEFAULT_EMBEDDING_METRIC;\nconst DEFAULT_SLOT_INDEX_TYPE: EmbeddingIndexType =\n DEFAULT_EMBEDDING_INDEX_TYPE;\n\n/**\n * The resolved storage config for one `(nodeKind, fieldPath)` slot that the\n * legacy table did not record. The legacy shared table stored only the\n * vector and its dimension count — not the metric or index type — so a\n * caller that wants migrated fields to match a specific graph's `embedding()`\n * declarations supplies this resolver.\n */\nexport type LegacyEmbeddingSlotConfig = Readonly<{\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n}>;\n\n/**\n * Options for {@link migrateLegacyEmbeddings}.\n */\nexport type MigrateLegacyEmbeddingsOptions = Readonly<{\n /**\n * The backend to migrate, wired with the destination `VectorStrategy`\n * (i.e. the post-cutover backend). Its `vectorStrategy` owns the per-field\n * storage rows are written into and its `upsertEmbedding` performs the\n * writes.\n */\n backend: GraphBackend;\n\n /**\n * Restrict the migration to a single graph. When omitted, every graph's\n * rows in the legacy table are migrated (the table is graph-scoped by its\n * `graph_id` column).\n */\n graphId?: string;\n\n /**\n * Resolves the metric / index type for a `(nodeKind, fieldPath)` slot the\n * legacy table didn't persist. Return `undefined` to fall back to the\n * cosine / hnsw defaults. Supply this (typically reading the graph's\n * `embedding()` declarations) when migrated fields must match a specific\n * metric — e.g. an `l2` field, which scores incorrectly under the cosine\n * default.\n */\n resolveSlotConfig?: (\n nodeKind: string,\n fieldPath: string,\n ) => LegacyEmbeddingSlotConfig | undefined;\n\n /** Rows read per round-trip. Defaults to {@link DEFAULT_BATCH_SIZE}. */\n batchSize?: number;\n\n /**\n * Physical name of the legacy table to drain. Defaults to\n * {@link LEGACY_EMBEDDINGS_TABLE_NAME}. Override only for a non-default\n * deployment that renamed the embeddings table.\n */\n legacyTableName?: string;\n}>;\n\n/**\n * Summary of a {@link migrateLegacyEmbeddings} run.\n */\nexport type MigrateLegacyEmbeddingsResult = Readonly<{\n /** Total embedding rows re-inserted into per-field storage. */\n migrated: number;\n /**\n * Per-`(nodeKind, fieldPath)` counts, keyed `\"<nodeKind>.<fieldPath>\"`\n * (the strategy's logical-slot key form). Empty when the legacy table was\n * absent or held no rows for the requested scope.\n */\n perField: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their vector length didn't match the per-field\n * table's fixed dimension. The legacy shared column allowed mixed\n * dimensions for one `(nodeKind, fieldPath)` (e.g. an unmigrated model\n * change); the first migrated row fixes the typed table's dimension and\n * any differently-sized rows for that slot are skipped rather than aborting\n * the whole migration. Keyed `\"<nodeKind>.<fieldPath>\"`. Non-empty here\n * means those fields need a deliberate re-embed at a single dimension.\n */\n skippedDimensionMismatch: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their legacy embedding could not be decoded into a\n * finite-number array — a corrupt value (e.g. a pgvector `vector` column\n * permits `NaN`/`Infinity`, which is not valid JSON). Keyed\n * `\"<nodeKind>.<fieldPath>\"`. Skipping + reporting keeps one bad row from\n * aborting the whole migration; non-empty here means those rows need manual\n * repair.\n */\n skippedDecodeError: Readonly<Record<string, number>>;\n /**\n * Whether the legacy table existed. `false` means the run was a clean\n * no-op (fresh install, or already-dropped table on a re-run).\n */\n legacyTablePresent: boolean;\n}>;\n\n/**\n * A single legacy embedding row, with the engine-native vector already\n * decoded to a JSON array string by the dialect-specific SELECT. The\n * legacy `dimensions` column is intentionally not read: the decoded array's\n * length is the authoritative fixed dimension for the destination slot, and\n * relying on it sidesteps the per-driver string/number coercion the legacy\n * integer column would otherwise need.\n */\ntype LegacyEmbeddingRow = Readonly<{\n graph_id: string;\n node_kind: string;\n node_id: string;\n field_path: string;\n /** JSON array text, e.g. `\"[0.1,0.2,0.3]\"` — decoded per dialect. */\n embedding_json: string;\n}>;\n\n/**\n * Re-inserts every embedding from the legacy shared\n * `typegraph_node_embeddings` table into the active\n * `backend.vectorStrategy`'s per-`(nodeKind, fieldPath)` storage.\n *\n * One-time, explicitly-run upgrade step for the shared-table → per-field\n * cutover (#157). Idempotent, batched, and a clean no-op when the legacy\n * table is absent. See the module doc comment for the full contract.\n *\n * @throws Error when the backend exposes no `vectorStrategy` /\n * `upsertEmbedding` (nothing to migrate *into*) — a configuration\n * error the caller must fix by wiring the destination strategy\n * before migrating.\n */\nexport async function migrateLegacyEmbeddings(\n options: MigrateLegacyEmbeddingsOptions,\n): Promise<MigrateLegacyEmbeddingsResult> {\n const {\n backend,\n graphId,\n resolveSlotConfig,\n batchSize = DEFAULT_BATCH_SIZE,\n legacyTableName = LEGACY_EMBEDDINGS_TABLE_NAME,\n } = options;\n\n if (\n backend.vectorStrategy === undefined ||\n backend.upsertEmbedding === undefined\n ) {\n throw new Error(\n \"migrateLegacyEmbeddings requires a backend wired with a vectorStrategy \" +\n \"(the destination per-field storage). Pass the post-cutover backend.\",\n );\n }\n if (!Number.isInteger(batchSize) || batchSize <= 0) {\n throw new RangeError(\n `batchSize must be a positive integer, got: ${batchSize}`,\n );\n }\n const upsertEmbedding = backend.upsertEmbedding;\n const ensureVectorSlotContribution = backend.ensureVectorSlotContribution;\n\n // Data-keyed: slot keys are built from a row's `node_kind` / `field_path`.\n const perField = createDataKeyedBag<number>();\n const skippedDimensionMismatch = createDataKeyedBag<number>();\n const skippedDecodeError = createDataKeyedBag<number>();\n // (kind, field) slots whose per-field table + durable marker this run has\n // already provisioned, mapped to the dimension the table was fixed at.\n // `upsertEmbedding` asserts the marker (#135) and no longer self-creates\n // the table, so this offline migration (privileged) provisions each slot\n // once — at the first row's dimension, which fixes the typed table just as\n // the original lazy write did. Differently-sized later rows for the same\n // slot are detected against this map and skipped BEFORE the upsert: the\n // marker assert would otherwise read the differently-dimensioned slot as\n // stale and abort the whole migration, and the ensure is deliberately not\n // re-run per row (that would trip the marker drift-guard).\n const ensuredSlots = new Map<string, number>();\n let migrated = 0;\n\n let cursor: LegacyRowCursor | undefined;\n for (;;) {\n let batch: readonly LegacyEmbeddingRow[];\n try {\n batch = await readLegacyBatch(backend, {\n legacyTableName,\n graphId,\n batchSize,\n after: cursor,\n });\n } catch (error) {\n // A missing legacy table is the expected \"nothing to migrate\" path on\n // the first read — surface it as a clean no-op, not a failure.\n if (cursor === undefined && isMissingTableError(error)) {\n return {\n migrated: 0,\n perField: {},\n skippedDimensionMismatch: {},\n skippedDecodeError: {},\n legacyTablePresent: false,\n };\n }\n throw error;\n }\n\n if (batch.length === 0) break;\n\n for (const row of batch) {\n const slotKey = `${row.node_kind}.${row.field_path}`;\n\n let embedding: readonly number[];\n try {\n embedding = decodeEmbeddingJson(row);\n } catch {\n // A corrupt legacy value (e.g. a pgvector `vector` column permits\n // NaN/Infinity, which is not valid JSON) is skipped + reported rather\n // than aborting the whole migration on one bad row.\n skippedDecodeError[slotKey] = (skippedDecodeError[slotKey] ?? 0) + 1;\n continue;\n }\n const config = resolveSlotConfig?.(row.node_kind, row.field_path);\n // The decoded length is the authoritative fixed dimension — the\n // strategy provisions its column type (e.g. `F32_BLOB(N)`) from it.\n const slot = {\n graphId: row.graph_id,\n nodeKind: row.node_kind,\n fieldPath: row.field_path,\n dimensions: embedding.length,\n metric: config?.metric ?? DEFAULT_SLOT_METRIC,\n indexType: config?.indexType ?? DEFAULT_SLOT_INDEX_TYPE,\n };\n\n // Provision the per-field table + durable marker before the first\n // write into this slot. Once per (graph, kind, field): the first row's\n // dimension fixes the table. Keyed by graph id too — the legacy table\n // is graph-scoped, so the same `kind.field` can recur across graphs.\n const ensuredKey = JSON.stringify([\n row.graph_id,\n row.node_kind,\n row.field_path,\n ]);\n if (\n ensureVectorSlotContribution !== undefined &&\n !ensuredSlots.has(ensuredKey)\n ) {\n await ensureVectorSlotContribution(slot);\n ensuredSlots.set(ensuredKey, slot.dimensions);\n }\n\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension. Skip a differently-sized row up front —\n // its slot would fail the marker assert as stale (different\n // signature), aborting the migration instead of skipping the row.\n const provisionedDimensions = ensuredSlots.get(ensuredKey);\n if (\n provisionedDimensions !== undefined &&\n provisionedDimensions !== embedding.length\n ) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n\n try {\n await upsertEmbedding({ ...slot, nodeId: row.node_id, embedding });\n } catch (error) {\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension, so a differently-sized row is skipped and\n // reported rather than aborting the whole migration.\n if (error instanceof EmbeddingDimensionChangedError) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n throw error;\n }\n\n migrated += 1;\n perField[slotKey] = (perField[slotKey] ?? 0) + 1;\n }\n\n if (batch.length < batchSize) break;\n const last = requireDefined(batch.at(-1));\n cursor = {\n graphId: last.graph_id,\n nodeKind: last.node_kind,\n nodeId: last.node_id,\n fieldPath: last.field_path,\n };\n }\n\n // SPREAD at the boundary. The three maps are null-prototype accumulators\n // because their keys are slot names built from row data; that protection is\n // internal, and returning the bags as-is handed a caller three maps with no\n // `toString` and `instanceof Object === false` — while the early\n // \"nothing to migrate\" return above hands back `{}` literals, so the same\n // exported function answered with two different kinds of object depending on\n // whether the legacy table existed. Spread copies own properties with\n // CreateDataProperty, so a `__proto__` slot key survives as an own key.\n return {\n migrated,\n perField: { ...perField },\n skippedDimensionMismatch: { ...skippedDimensionMismatch },\n skippedDecodeError: { ...skippedDecodeError },\n legacyTablePresent: true,\n };\n}\n\n/**\n * Composite keyset cursor over the legacy table's primary key\n * `(graph_id, node_kind, node_id, field_path)`. Stable under concurrent\n * writes and immune to OFFSET drift, so a batched walk reads every row once.\n */\ntype LegacyRowCursor = Readonly<{\n graphId: string;\n nodeKind: string;\n nodeId: string;\n fieldPath: string;\n}>;\n\ntype ReadLegacyBatchParams = Readonly<{\n legacyTableName: string;\n graphId: string | undefined;\n batchSize: number;\n after: LegacyRowCursor | undefined;\n}>;\n\n/**\n * Reads one keyset-paginated batch of legacy rows, ordered by the primary\n * key, with the engine-native embedding column decoded to a JSON array\n * string by the dialect.\n */\nasync function readLegacyBatch(\n backend: GraphBackend,\n params: ReadLegacyBatchParams,\n): Promise<readonly LegacyEmbeddingRow[]> {\n const table = sql.identifier(params.legacyTableName);\n const embeddingJson = legacyEmbeddingDecodeExpression(backend);\n\n const conditions: SqlFragment[] = [];\n if (params.graphId !== undefined) {\n conditions.push(sql`\"graph_id\" = ${params.graphId}`);\n }\n if (params.after !== undefined) {\n conditions.push(keysetAfterCondition(params.after));\n }\n\n const whereClause =\n conditions.length === 0 ?\n sql``\n : sql` WHERE ${sql.join(conditions, sql` AND `)}`;\n\n const query = sql`\n SELECT\n \"graph_id\" AS graph_id,\n \"node_kind\" AS node_kind,\n \"node_id\" AS node_id,\n \"field_path\" AS field_path,\n ${embeddingJson} AS embedding_json\n FROM ${table}${whereClause}\n ORDER BY \"graph_id\" ASC, \"node_kind\" ASC, \"node_id\" ASC, \"field_path\" ASC\n LIMIT ${params.batchSize}\n `;\n\n return backend.execute<LegacyEmbeddingRow>(asCompiledRowsSql(query));\n}\n\n/**\n * The strict `>` comparison over the composite primary key, expressed as\n * the standard lexicographic OR-chain so it works on every dialect (SQLite\n * supports row-value comparison, but Postgres + SQLite both accept this\n * portable form).\n */\nfunction keysetAfterCondition(after: LegacyRowCursor): SqlFragment {\n return sql`\n (\n \"graph_id\" > ${after.graphId}\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" > ${after.nodeKind})\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" = ${after.nodeKind} AND \"node_id\" > ${after.nodeId})\n OR (\n \"graph_id\" = ${after.graphId}\n AND \"node_kind\" = ${after.nodeKind}\n AND \"node_id\" = ${after.nodeId}\n AND \"field_path\" > ${after.fieldPath}\n )\n )\n `;\n}\n\n/**\n * The SQL expression that decodes the legacy engine-native embedding column\n * into a JSON array string `embedding_json`. The single dialect branch in\n * this whole module: the legacy storage formats are genuinely engine-\n * specific, and there is no longer a strategy abstraction over the *legacy*\n * table to delegate to.\n */\nfunction legacyEmbeddingDecodeExpression(backend: GraphBackend): SqlFragment {\n switch (backend.dialect) {\n case \"sqlite\": {\n // Legacy SQLite embeddings were written via `vec_f32('[…]')`\n // (sqlite-vec binary). `vec_to_json` is its inverse, yielding the\n // JSON array text. Requires sqlite-vec on the connection — which the\n // legacy write path also required, so any deployment with legacy rows\n // has it loaded.\n return sql`vec_to_json(\"embedding\")`;\n }\n case \"postgres\": {\n // pgvector's native `vector` casts to its `[…]` text literal, which is\n // valid JSON for `JSON.parse`.\n return sql`\"embedding\"::text`;\n }\n default: {\n const _exhaustive: never = backend.dialect;\n throw new Error(\n `migrateLegacyEmbeddings does not support dialect: ${String(_exhaustive)}`,\n );\n }\n }\n}\n\n/**\n * Parses a decoded `embedding_json` array, asserting it is a non-empty array\n * of finite numbers. A bad decode (wrong type, NaN) names the offending row\n * loudly instead of writing a corrupt vector into per-field storage.\n */\nfunction decodeEmbeddingJson(row: LegacyEmbeddingRow): readonly number[] {\n let parsed: unknown;\n try {\n parsed = JSON.parse(row.embedding_json) as unknown;\n } catch (error) {\n throw new Error(\n `Failed to decode legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}): not valid JSON.`,\n { cause: error },\n );\n }\n if (!Array.isArray(parsed) || parsed.length === 0) {\n throw new Error(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) decoded to a non-array ` +\n `or empty value.`,\n );\n }\n for (const [index, value] of parsed.entries()) {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new TypeError(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) has a non-finite ` +\n `value at index ${index}: ${String(value)}.`,\n );\n }\n }\n return parsed as readonly number[];\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ export { D as DEFAULT_SEARCHABLE_LANGUAGE, b as EmbeddingSchema, c as EmbeddingV
|
|
|
4
4
|
export { R as RecordedInstant, a as asRecordedInstant, c as compareRecordedInstants, r as recordedInstantRevision, b as recordedInstantWallTime } from './temporal-5GqpYCk2.cjs';
|
|
5
5
|
import { dk as AggregateExpr, dl as FieldRef, dm as ComparisonOp, dn as AggregateComparisonPredicate, d8 as GraphDef, dp as TraversalDirection, aR as GraphIdentityConfig, cL as VectorStrategy, aM as GraphBackend, dg as NodeType, dq as OntologyRelation, b9 as InferenceType, dr as EdgeType } from './types-BqFZTQmV.cjs';
|
|
6
6
|
export { b as AdapterBackend, c as AdapterBackendTransactions, ds as AllEdgeTypes, dt as AllNodeTypes, dh as AnyEdgeType, d as BackendCapabilities, e as BackendIdentity, f as BackendLifecycle, g as BackendMaintenance, h as BackendTransactions, du as CURRENT_GRAPH_EXTENSION_VERSION, C as Cardinality, l as Collation, m as CommitSchemaVersionExpected, n as CommitSchemaVersionIfKindsEmptyResult, o as CommitSchemaVersionParams, p as CompiledRowsSql, q as CompiledSelectSql, r as CompiledStatementSql, t as ContributionCapabilities, u as ContributionDiagnostic, v as ContributionDiagnosticState, w as ContributionMaterializationBackend, z as ContributionProbeContribution, D as ContributionProbeEntry, E as ContributionProbeResult, F as ContributionProbeState, G as ContributionRebuildResult, H as ContributionRebuildScope, J as ContributionRepairEntry, K as ContributionRepairResult, L as ContributionRepopulationStats, dv as DEFAULT_SQL_SCHEMA, S as DeleteBehavior, W as DeleteFulltextBatchParams, a4 as EdgeEntityReadBackend, a5 as EdgeEntityWriteBackend, dw as EdgeId, da as EdgeIndexConfig, a7 as EdgeIndexDeclaration, a8 as EdgeIndexDirection, db as EdgeIndexWhereBuilder, dx as EdgeKinds, dy as EdgeProps, dz as EdgeRegistration, dA as EdgeTypeWithEndpoints, aa as EndpointExistence, dB as ExternalRecordedReadSource, ax as FilteredApproximateSearch, ay as FilteredApproximateSearchMode, aA as FindEdgesByHeterogeneousEndpointSetParams, aE as FulltextBatchRow, aF as FulltextCapabilities, aG as FulltextOperationBackend, aH as FulltextQueryMode, aI as FulltextSearchParams, aJ as FulltextSearchResult, aK as FulltextStrategy, dC as GetEdgeType, dD as GetNodeType, aL as GraphAnalyticsCapabilities, dE as GraphDefaults, aN as GraphEntityReadBackend, aO as GraphEntityWriteBackend, aP as GraphExtension, aQ as GraphExtensionVersion, aS as GraphLifecycleBackend, aW as HardDeleteUniquesByNodeIdsParams, dF as HybridFusionOptions, I as IndexDeclaration, b1 as IndexMaterializationBackend, b3 as IndexOrigin, b4 as IndexScope, b5 as IndexWhereExpression, dc as IndexWhereFieldBuilder, dd as IndexWhereInput, be as IntentSql, bf as JsonPointer, dG as JsonPointerFor, dH as JsonPointerInput, dI as JsonPointerSegment, dJ as JsonPointerSegments, dK as JsonPointerSegmentsFor, bh as JsonValue, bi as KindAnnotations, dL as LEGACY_GRAPH_EXTENSION_VERSION, bm as LockSchemaVersionForWriteParams, dM as MAX_JSON_POINTER_DEPTH, dN as MetaEdge, dO as MetaEdgeProperties, bp as NodeEntityReadBackend, bq as NodeEntityWriteBackend, dP as NodeId, de as NodeIndexConfig, br as NodeIndexDeclaration, df as NodeIndexWhereBuilder, dQ as NodeKinds, dR as NodeProps, dS as NodeRegistration, dT as OrderSpec, dU as ParameterRef, bw as Placeholder, bx as PopulatedSchemaKind, by as QueryExecutionBackend, bz as RawQueryExecutionBackend, bA as RawStatementExecutionBackend, dV as RecordedRelationOptions, bH as RemovalMaterializationBackend, bI as RenderedSql, dW as ResolveJsonPointer, dX as ResolveJsonPointerSegments, bJ as ResolvedSqlTableNames, bK as RowProps, bN as SchemaCommitBackend, bP as SchemaKindEmptinessProbe, bQ as SchemaReadBackend, bR as SchemaVersionRow, bS as SchemaWriteFenceBackend, bZ as SerializedSchema, b$ as SetActiveVersionParams, dY as SortDirection, c0 as SqlChunk, c2 as SqlDialect, c3 as SqlFragment, c4 as SqlIdentifierChunk, c5 as SqlIntent, c6 as SqlParameterChunk, c7 as SqlPlaceholderChunk, di as SqlSchema, c8 as SqlTableNames, c9 as SqlTag, ca as SqlTextChunk, cb as StrategyTableContribution, cd as TableContribution, ce as TemporalMode, cg as TransactionBackend, ch as TransactionOptions, ci as TransactionReadBackend, dZ as TraversalExpansion, cj as TrustedImportOptions, ck as TrustedImportSession, d_ as UniqueConstraint, cl as UniqueConstraintBackend, cn as UniquenessScope, cq as UpdateNodeSetParams, cr as UpdateNodeSetResult, cv as UpsertFulltextBatchParams, cz as VectorCapabilities, cG as VectorOperationBackend, cH as VectorSearchFrontierTuning, cK as VectorSlot, d$ as asEdgeId, e0 as asNodeId, cQ as buildVectorCapabilities, e1 as createSqlSchema, e2 as defineGraph, cR as fts5Strategy, e3 as getEdgeKinds, e4 as getNodeKinds, e5 as isEdgeType, e6 as isEdgeTypeWithEndpoints, e7 as isGraphDef, e8 as isMetaEdge, e9 as isNodeType, cT as isSqlFragment, ea as joinJsonPointers, eb as jsonPointer, ec as normalizeJsonPointer, ed as parseJsonPointer, ee as recordedRelation, cY as renderPostgres, cZ as renderSql, c_ as renderSqlInline, c$ as renderSqlite, d0 as rowPropsToJsonText, d1 as rowPropsToObject, d3 as sql, d4 as tsvectorStrategy } from './types-BqFZTQmV.cjs';
|
|
7
|
-
import { A as AliasMap, E as EdgeAliasMap, m as RecursiveAliasMap, Q as QueryCoordinateState, n as QueryBuilder, o as EmptyRecursiveAliasMap, T as TraversalBuilder, a as Store } from './store-
|
|
8
|
-
export { p as AdapterHistoryStore, q as AdapterHistoryTransactionContext, r as AdapterRecordedReadStore, s as AdapterStore, t as AdapterTransactionContext, u as AggregateResult, v as AlgorithmCyclePolicy, w as AnyEdge, x as AnyNode, B as BaseStoreOptions, y as BaseTraversalOptions, z as BatchResults, C as BatchableQuery, D as BulkEdgeSourceGroup, F as BulkFindEdgesFromParams, G as BulkFindEdgesFromResult, J as BulkOperationHookContext, K as ConstraintNames, M as CreateEdgeInput, N as CreateNodeInput, O as DegreeOptions, P as DynamicEdgeAccessor, V as DynamicEdgeCollection, W as DynamicEdgeType, X as DynamicFieldBuilder, Y as DynamicNode, Z as DynamicNodeAccessor, _ as DynamicNodeCollection, $ as DynamicNodeKind, a0 as DynamicNodeReference, a1 as DynamicNodeType, a2 as DynamicSelectableEdge, a3 as DynamicSelectableNode, a4 as Edge, a5 as EdgeAccessor, a6 as EdgeBatchReads, a7 as EdgeBulkFindEndpointOptions, a8 as EdgeBulkFindOptions, a9 as EdgeCollection, aa as EdgeFindByEndpointsOptions, ab as EdgeGetOrCreateByEndpointsOptions, ac as EdgeGetOrCreateByEndpointsResult, ad as EdgeIntrospection, ae as EdgeTemporalReads, af as EdgeWrites, ag as EmptyAliasMap, ah as EmptyEdgeAliasMap, ai as ExecutableAggregateQuery, aj as ExecutableQuery, ak as FieldAccessor, al as FulltextSearchHit, am as FulltextSearchOptions, an as GetOrCreateAction, ao as GraphAlgorithms, ap as GraphEdgeCollections, aq as GraphEdgeForKinds, ar as GraphNodeCollections, as as GraphNodeReference, b as HistoryStore, at as HistoryStoreBackend, H as HistoryStoreOptions, au as HookContext, av as HybridFulltextOptions, aw as HybridSearchHit, ax as HybridSearchOptions, ay as HybridVectorOptions, I as IdentityAssertion, d as IdentityAssertionId, e as IdentityAssertionResult, f as IdentityFacade, g as IdentityNode, h as IdentityNodeRefInput,
|
|
7
|
+
import { A as AliasMap, E as EdgeAliasMap, m as RecursiveAliasMap, Q as QueryCoordinateState, n as QueryBuilder, o as EmptyRecursiveAliasMap, T as TraversalBuilder, a as Store } from './store-bphCSo7z.cjs';
|
|
8
|
+
export { p as AdapterHistoryStore, q as AdapterHistoryTransactionContext, r as AdapterRecordedReadStore, s as AdapterStore, t as AdapterTransactionContext, u as AggregateResult, v as AlgorithmCyclePolicy, w as AnyEdge, x as AnyNode, B as BaseStoreOptions, y as BaseTraversalOptions, z as BatchResults, C as BatchableQuery, D as BulkEdgeSourceGroup, F as BulkFindEdgesFromParams, G as BulkFindEdgesFromResult, J as BulkOperationHookContext, K as ConstraintNames, M as CreateEdgeInput, N as CreateNodeInput, O as DegreeOptions, P as DynamicEdgeAccessor, V as DynamicEdgeCollection, W as DynamicEdgeType, X as DynamicFieldBuilder, Y as DynamicNode, Z as DynamicNodeAccessor, _ as DynamicNodeCollection, $ as DynamicNodeKind, a0 as DynamicNodeReference, a1 as DynamicNodeType, a2 as DynamicSelectableEdge, a3 as DynamicSelectableNode, a4 as Edge, a5 as EdgeAccessor, a6 as EdgeBatchReads, a7 as EdgeBulkFindEndpointOptions, a8 as EdgeBulkFindOptions, a9 as EdgeCollection, aa as EdgeFindByEndpointsOptions, ab as EdgeGetOrCreateByEndpointsOptions, ac as EdgeGetOrCreateByEndpointsResult, ad as EdgeIntrospection, ae as EdgeTemporalReads, af as EdgeWrites, ag as EmptyAliasMap, ah as EmptyEdgeAliasMap, ai as ExecutableAggregateQuery, aj as ExecutableQuery, ak as FieldAccessor, al as FulltextSearchHit, am as FulltextSearchOptions, an as GetOrCreateAction, ao as GraphAlgorithms, ap as GraphEdgeCollections, aq as GraphEdgeForKinds, ar as GraphNodeCollections, as as GraphNodeReference, b as HistoryStore, at as HistoryStoreBackend, H as HistoryStoreOptions, au as HookContext, av as HybridFulltextOptions, aw as HybridSearchHit, ax as HybridSearchOptions, ay as HybridVectorOptions, I as IdentityAssertion, d as IdentityAssertionId, e as IdentityAssertionResult, az as IdentityAssertionWriteFacade, f as IdentityFacade, g as IdentityNode, h as IdentityNodeRefInput, aA as IdentityNodeReference, i as IdentityPair, j as IdentityReadFacade, k as IdentityRelation, aB as IdentityTraversalOption, aC as IdentityValidityWindow, l as IdentityWriteSummary, aD as IfExistsMode, aE as InitialQueryBuilder, aF as KindIntrospection, aG as LabelPropagationMembership, aH as LabelPropagationOptions, L as LiveStoreOptions, aI as MaterializeRemovalsEntry, aJ as MaterializeRemovalsOptions, aK as MaterializeRemovalsResult, aL as MeasurableAdapterHistoryTransactionContext, aM as MeasurableAdapterTransactionContext, aN as MeasurableTransactionContext, aO as NeighborsOptions, aP as NoRecordedCoordinate, aQ as Node, aR as NodeAccessor, aS as NodeAlias, aT as NodeBulkFindByIndexOptions, aU as NodeCollection, aV as NodeCurrentReads, aW as NodeGetOrCreateByConstraintOptions, aX as NodeGetOrCreateByConstraintResult, aY as NodeIdentifier, aZ as NodeRef, a_ as NodeTemporalReads, a$ as NodeWrites, b0 as OntologyIntrospection, b1 as OperationHookContext, b2 as PageRankOptions, b3 as PageRankScore, b4 as PaginateOptions, b5 as PaginatedResult, b6 as PathNode, b7 as PersonalizedPageRankOptions, b8 as PersonalizedPageRankSeed, b9 as Predicate, ba as PreparedQuery, bb as PropsAccessor, bc as QueryHookContext, bd as QueryOptions, be as ReachableNode, bf as ReachableOptions, bg as RebuildContributionOptions, bh as RebuildFulltextOptions, bi as RebuildFulltextResult, bj as ReclaimedVectorFieldEntry, bk as ReconciledSchema, c as RecordedReadStore, R as RecordedReadStoreOptions, bl as RecordedScanOptions, bm as RecordedScanPage, bn as RecordedStoreView, bo as RecordedStoreViewEdgeCollection, bp as RecordedStoreViewEdgeCollections, bq as RecordedStoreViewNodeCollection, br as RecordedStoreViewNodeCollections, bs as RecursiveTraversalOptions, bt as ReembedFunction, bu as ReembedVectorFieldOptions, bv as ReembedVectorFieldResult, bw as SchemaIntrospection, bx as ScopedMeasure, by as SearchScopeOptions, bz as SelectContext, bA as SelectableEdge, bB as SelectableNode, bC as ShortestPathOptions, bD as ShortestPathResult, bE as SqlAvailability, bF as StoreHooks, S as StoreOptions, bG as StoreProjection, bH as StoreRef, bI as StoreSearch, bJ as StoreView, bK as StoreViewCanReachOptions, bL as StoreViewCoordinate, bM as StoreViewDegreeOptions, bN as StoreViewEdgeCollection, bO as StoreViewEdgeCollections, bP as StoreViewGraphAlgorithms, bQ as StoreViewLabelPropagationOptions, bR as StoreViewNeighborsOptions, bS as StoreViewNodeCollection, bT as StoreViewNodeCollections, bU as StoreViewPageRankOptions, bV as StoreViewPersonalizedPageRankOptions, bW as StoreViewReachableOptions, bX as StoreViewShortestPathOptions, bY as StoreViewSubgraphOptions, bZ as StoreViewWeaklyConnectedComponentsOptions, b_ as StoreViewWeightedShortestPathOptions, b$ as StreamOptions, c0 as SubgraphEdgeResult, c1 as SubgraphNodeResult, c2 as SubgraphOptions, c3 as SubgraphResult, c4 as SubsetEdge, c5 as SubsetNode, c6 as TemporalAlgorithmOptions, c7 as TransactionContext, c8 as TransactionOutcome, c9 as TransactionReceipt, ca as TraversalDirection, cb as TypedEdgeCollection, cc as TypedRecordedStoreViewEdgeCollection, cd as TypedStoreViewEdgeCollection, U as UnboundLiveStoreOptions, ce as UnionableQuery, cf as UniqueIntrospection, cg as UpdateEdgeInput, ch as UpdateNodeInput, ci as ValidityEndMutation, cj as VectorSearchHit, ck as VectorSearchOptions, cl as WeaklyConnectedComponentMembership, cm as WeaklyConnectedComponentsOptions, cn as WeightedShortestPathOptions, co as WeightedShortestPathResult, cp as asIdentityAssertionId, cq as createAdapterStore, cr as createAdapterStoreWithSchema, cs as createQueryBuilder, ct as createStore, cu as createStoreWithSchema, cv as createVerifiedAdapterStore, cw as createVerifiedStore, cx as defineSubgraphProject, cy as exists, cz as fieldRef, cA as inSubquery, cB as isParameterRef, cC as notExists, cD as notInSubquery, cE as param } from './store-bphCSo7z.cjs';
|
|
9
9
|
export { D as DeleteLegacyRecordedAnchorMapOptions, M as MigrateLegacyRecordedTimeOptions, a as MigrateLegacyRecordedTimeResult, b as MigrateRecordedAnchorOptions, R as RepairInvertedWindowsOptions, c as RepairInvertedWindowsReport, d as RepairRelation, e as RepairRelationScope, f as deleteLegacyRecordedAnchorMap, m as migrateLegacyRecordedTime, g as migrateRecordedAnchor, r as repairInvertedValidityWindows } from './repair-validity-windows-BFNZvd_H.cjs';
|
|
10
10
|
export { B as BackendDisposedError, C as CardinalityError, b as CardinalityErrorDetails, c as CompilerInvariantError, d as ConfigurationError, e as ContributionRebuildRefusal, f as ContributionRebuildUnsupportedError, g as ContributionUnavailableError, h as ContributionUnavailableErrorDetails, D as DatabaseOperationError, i as DatabaseOperationErrorDetails, j as DisjointError, k as DisjointErrorDetails, E as EDGE_IDENTITY_MISMATCH_CODE, l as ENTITY_ALREADY_EXISTS_CODE, m as EagerMaterializationError, n as EagerMaterializationErrorDetails, o as EdgeNotFoundError, p as EdgeNotFoundErrorDetails, q as EmbeddingDimensionChangedError, r as EmbeddingDimensionChangedErrorDetails, s as EndpointError, t as EndpointErrorDetails, u as EndpointNotFoundError, v as EndpointNotFoundErrorDetails, w as ErrorCategory, x as ExportStreamCancelledError, y as ExportStreamIdleTimeoutError, G as GraphAlgorithmConvergenceError, I as IMMUTABLE_VALIDITY_LOWER_BOUND_CODE, z as INVERTED_VALIDITY_WINDOW_CODE, A as IdentityContradictionError, F as IdentityContradictionErrorDetails, H as IdentityEndpointValidityError, J as IdentityEndpointValidityErrorDetails, K as IdentitySeparationViolationError, L as IdentitySeparationViolationErrorDetails, M as IdentityValidityWindowError, N as IdentityValidityWindowErrorDetails, O as InvalidEdgeWeightError, P as InvalidEdgeWeightErrorDetails, Q as InvalidEdgeWeightReason, R as KindNotFoundError, S as KindNotFoundErrorDetails, T as MIGRATION_FAILURE_REASONS, U as MigrationError, W as MigrationErrorDetails, X as MigrationFailureReason, Y as NodeConstraintNotFoundError, Z as NodeConstraintNotFoundErrorDetails, _ as NodeIndexNotFoundError, $ as NodeIndexNotFoundErrorDetails, a0 as NodeNotFoundError, a1 as NodeNotFoundErrorDetails, a2 as RECORDED_CAPTURE_GUARD_CODES, a3 as RecordedCaptureGuardCode, a4 as RecordedCaptureGuardError, a5 as RestrictedDeleteError, a6 as RestrictedDeleteErrorDetails, a7 as SchemaContentConflictError, a8 as SchemaContentConflictErrorDetails, a9 as SchemaMismatchError, aa as SchemaMismatchErrorDetails, ab as StaleVersionError, ac as StaleVersionErrorDetails, ad as StoreNotInitializedError, ae as StoreNotInitializedErrorDetails, af as StoreNotInitializedReason, ag as TransactionClosedError, ah as TrustedImportError, ai as TrustedImportErrorReason, aj as TypeGraphError, ak as TypeGraphErrorOptions, al as UniquenessError, am as UniquenessErrorDetails, an as UnsupportedBackendCapabilityError, ao as UnsupportedPredicateError, a as ValidationError, ap as ValidationErrorDetails, V as ValidationIssue, aq as VersionConflictError, ar as VersionConflictErrorDetails, as as getErrorSuggestion, at as isConstraintError, au as isRecordedCaptureGuardError, av as isSystemError, aw as isTypeGraphError, ax as isUserRecoverable } from './index-COs_z6nV.cjs';
|
|
11
11
|
export { I as IdentityChange, h as MaterializeIndexesEntry, j as MaterializeIndexesOptions, M as MaterializeIndexesResult, k as MaterializeSystemIndexesOptions } from './materialize-indexes-DTtAnvfY.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export { D as DEFAULT_SEARCHABLE_LANGUAGE, b as EmbeddingSchema, c as EmbeddingV
|
|
|
4
4
|
export { R as RecordedInstant, a as asRecordedInstant, c as compareRecordedInstants, r as recordedInstantRevision, b as recordedInstantWallTime } from './temporal-CbnLzTmM.js';
|
|
5
5
|
import { dk as AggregateExpr, dl as FieldRef, dm as ComparisonOp, dn as AggregateComparisonPredicate, d8 as GraphDef, dp as TraversalDirection, aR as GraphIdentityConfig, cL as VectorStrategy, aM as GraphBackend, dg as NodeType, dq as OntologyRelation, b9 as InferenceType, dr as EdgeType } from './types-BqFZTQmV.js';
|
|
6
6
|
export { b as AdapterBackend, c as AdapterBackendTransactions, ds as AllEdgeTypes, dt as AllNodeTypes, dh as AnyEdgeType, d as BackendCapabilities, e as BackendIdentity, f as BackendLifecycle, g as BackendMaintenance, h as BackendTransactions, du as CURRENT_GRAPH_EXTENSION_VERSION, C as Cardinality, l as Collation, m as CommitSchemaVersionExpected, n as CommitSchemaVersionIfKindsEmptyResult, o as CommitSchemaVersionParams, p as CompiledRowsSql, q as CompiledSelectSql, r as CompiledStatementSql, t as ContributionCapabilities, u as ContributionDiagnostic, v as ContributionDiagnosticState, w as ContributionMaterializationBackend, z as ContributionProbeContribution, D as ContributionProbeEntry, E as ContributionProbeResult, F as ContributionProbeState, G as ContributionRebuildResult, H as ContributionRebuildScope, J as ContributionRepairEntry, K as ContributionRepairResult, L as ContributionRepopulationStats, dv as DEFAULT_SQL_SCHEMA, S as DeleteBehavior, W as DeleteFulltextBatchParams, a4 as EdgeEntityReadBackend, a5 as EdgeEntityWriteBackend, dw as EdgeId, da as EdgeIndexConfig, a7 as EdgeIndexDeclaration, a8 as EdgeIndexDirection, db as EdgeIndexWhereBuilder, dx as EdgeKinds, dy as EdgeProps, dz as EdgeRegistration, dA as EdgeTypeWithEndpoints, aa as EndpointExistence, dB as ExternalRecordedReadSource, ax as FilteredApproximateSearch, ay as FilteredApproximateSearchMode, aA as FindEdgesByHeterogeneousEndpointSetParams, aE as FulltextBatchRow, aF as FulltextCapabilities, aG as FulltextOperationBackend, aH as FulltextQueryMode, aI as FulltextSearchParams, aJ as FulltextSearchResult, aK as FulltextStrategy, dC as GetEdgeType, dD as GetNodeType, aL as GraphAnalyticsCapabilities, dE as GraphDefaults, aN as GraphEntityReadBackend, aO as GraphEntityWriteBackend, aP as GraphExtension, aQ as GraphExtensionVersion, aS as GraphLifecycleBackend, aW as HardDeleteUniquesByNodeIdsParams, dF as HybridFusionOptions, I as IndexDeclaration, b1 as IndexMaterializationBackend, b3 as IndexOrigin, b4 as IndexScope, b5 as IndexWhereExpression, dc as IndexWhereFieldBuilder, dd as IndexWhereInput, be as IntentSql, bf as JsonPointer, dG as JsonPointerFor, dH as JsonPointerInput, dI as JsonPointerSegment, dJ as JsonPointerSegments, dK as JsonPointerSegmentsFor, bh as JsonValue, bi as KindAnnotations, dL as LEGACY_GRAPH_EXTENSION_VERSION, bm as LockSchemaVersionForWriteParams, dM as MAX_JSON_POINTER_DEPTH, dN as MetaEdge, dO as MetaEdgeProperties, bp as NodeEntityReadBackend, bq as NodeEntityWriteBackend, dP as NodeId, de as NodeIndexConfig, br as NodeIndexDeclaration, df as NodeIndexWhereBuilder, dQ as NodeKinds, dR as NodeProps, dS as NodeRegistration, dT as OrderSpec, dU as ParameterRef, bw as Placeholder, bx as PopulatedSchemaKind, by as QueryExecutionBackend, bz as RawQueryExecutionBackend, bA as RawStatementExecutionBackend, dV as RecordedRelationOptions, bH as RemovalMaterializationBackend, bI as RenderedSql, dW as ResolveJsonPointer, dX as ResolveJsonPointerSegments, bJ as ResolvedSqlTableNames, bK as RowProps, bN as SchemaCommitBackend, bP as SchemaKindEmptinessProbe, bQ as SchemaReadBackend, bR as SchemaVersionRow, bS as SchemaWriteFenceBackend, bZ as SerializedSchema, b$ as SetActiveVersionParams, dY as SortDirection, c0 as SqlChunk, c2 as SqlDialect, c3 as SqlFragment, c4 as SqlIdentifierChunk, c5 as SqlIntent, c6 as SqlParameterChunk, c7 as SqlPlaceholderChunk, di as SqlSchema, c8 as SqlTableNames, c9 as SqlTag, ca as SqlTextChunk, cb as StrategyTableContribution, cd as TableContribution, ce as TemporalMode, cg as TransactionBackend, ch as TransactionOptions, ci as TransactionReadBackend, dZ as TraversalExpansion, cj as TrustedImportOptions, ck as TrustedImportSession, d_ as UniqueConstraint, cl as UniqueConstraintBackend, cn as UniquenessScope, cq as UpdateNodeSetParams, cr as UpdateNodeSetResult, cv as UpsertFulltextBatchParams, cz as VectorCapabilities, cG as VectorOperationBackend, cH as VectorSearchFrontierTuning, cK as VectorSlot, d$ as asEdgeId, e0 as asNodeId, cQ as buildVectorCapabilities, e1 as createSqlSchema, e2 as defineGraph, cR as fts5Strategy, e3 as getEdgeKinds, e4 as getNodeKinds, e5 as isEdgeType, e6 as isEdgeTypeWithEndpoints, e7 as isGraphDef, e8 as isMetaEdge, e9 as isNodeType, cT as isSqlFragment, ea as joinJsonPointers, eb as jsonPointer, ec as normalizeJsonPointer, ed as parseJsonPointer, ee as recordedRelation, cY as renderPostgres, cZ as renderSql, c_ as renderSqlInline, c$ as renderSqlite, d0 as rowPropsToJsonText, d1 as rowPropsToObject, d3 as sql, d4 as tsvectorStrategy } from './types-BqFZTQmV.js';
|
|
7
|
-
import { A as AliasMap, E as EdgeAliasMap, m as RecursiveAliasMap, Q as QueryCoordinateState, n as QueryBuilder, o as EmptyRecursiveAliasMap, T as TraversalBuilder, a as Store } from './store-
|
|
8
|
-
export { p as AdapterHistoryStore, q as AdapterHistoryTransactionContext, r as AdapterRecordedReadStore, s as AdapterStore, t as AdapterTransactionContext, u as AggregateResult, v as AlgorithmCyclePolicy, w as AnyEdge, x as AnyNode, B as BaseStoreOptions, y as BaseTraversalOptions, z as BatchResults, C as BatchableQuery, D as BulkEdgeSourceGroup, F as BulkFindEdgesFromParams, G as BulkFindEdgesFromResult, J as BulkOperationHookContext, K as ConstraintNames, M as CreateEdgeInput, N as CreateNodeInput, O as DegreeOptions, P as DynamicEdgeAccessor, V as DynamicEdgeCollection, W as DynamicEdgeType, X as DynamicFieldBuilder, Y as DynamicNode, Z as DynamicNodeAccessor, _ as DynamicNodeCollection, $ as DynamicNodeKind, a0 as DynamicNodeReference, a1 as DynamicNodeType, a2 as DynamicSelectableEdge, a3 as DynamicSelectableNode, a4 as Edge, a5 as EdgeAccessor, a6 as EdgeBatchReads, a7 as EdgeBulkFindEndpointOptions, a8 as EdgeBulkFindOptions, a9 as EdgeCollection, aa as EdgeFindByEndpointsOptions, ab as EdgeGetOrCreateByEndpointsOptions, ac as EdgeGetOrCreateByEndpointsResult, ad as EdgeIntrospection, ae as EdgeTemporalReads, af as EdgeWrites, ag as EmptyAliasMap, ah as EmptyEdgeAliasMap, ai as ExecutableAggregateQuery, aj as ExecutableQuery, ak as FieldAccessor, al as FulltextSearchHit, am as FulltextSearchOptions, an as GetOrCreateAction, ao as GraphAlgorithms, ap as GraphEdgeCollections, aq as GraphEdgeForKinds, ar as GraphNodeCollections, as as GraphNodeReference, b as HistoryStore, at as HistoryStoreBackend, H as HistoryStoreOptions, au as HookContext, av as HybridFulltextOptions, aw as HybridSearchHit, ax as HybridSearchOptions, ay as HybridVectorOptions, I as IdentityAssertion, d as IdentityAssertionId, e as IdentityAssertionResult, f as IdentityFacade, g as IdentityNode, h as IdentityNodeRefInput,
|
|
7
|
+
import { A as AliasMap, E as EdgeAliasMap, m as RecursiveAliasMap, Q as QueryCoordinateState, n as QueryBuilder, o as EmptyRecursiveAliasMap, T as TraversalBuilder, a as Store } from './store-DRrFCx5x.js';
|
|
8
|
+
export { p as AdapterHistoryStore, q as AdapterHistoryTransactionContext, r as AdapterRecordedReadStore, s as AdapterStore, t as AdapterTransactionContext, u as AggregateResult, v as AlgorithmCyclePolicy, w as AnyEdge, x as AnyNode, B as BaseStoreOptions, y as BaseTraversalOptions, z as BatchResults, C as BatchableQuery, D as BulkEdgeSourceGroup, F as BulkFindEdgesFromParams, G as BulkFindEdgesFromResult, J as BulkOperationHookContext, K as ConstraintNames, M as CreateEdgeInput, N as CreateNodeInput, O as DegreeOptions, P as DynamicEdgeAccessor, V as DynamicEdgeCollection, W as DynamicEdgeType, X as DynamicFieldBuilder, Y as DynamicNode, Z as DynamicNodeAccessor, _ as DynamicNodeCollection, $ as DynamicNodeKind, a0 as DynamicNodeReference, a1 as DynamicNodeType, a2 as DynamicSelectableEdge, a3 as DynamicSelectableNode, a4 as Edge, a5 as EdgeAccessor, a6 as EdgeBatchReads, a7 as EdgeBulkFindEndpointOptions, a8 as EdgeBulkFindOptions, a9 as EdgeCollection, aa as EdgeFindByEndpointsOptions, ab as EdgeGetOrCreateByEndpointsOptions, ac as EdgeGetOrCreateByEndpointsResult, ad as EdgeIntrospection, ae as EdgeTemporalReads, af as EdgeWrites, ag as EmptyAliasMap, ah as EmptyEdgeAliasMap, ai as ExecutableAggregateQuery, aj as ExecutableQuery, ak as FieldAccessor, al as FulltextSearchHit, am as FulltextSearchOptions, an as GetOrCreateAction, ao as GraphAlgorithms, ap as GraphEdgeCollections, aq as GraphEdgeForKinds, ar as GraphNodeCollections, as as GraphNodeReference, b as HistoryStore, at as HistoryStoreBackend, H as HistoryStoreOptions, au as HookContext, av as HybridFulltextOptions, aw as HybridSearchHit, ax as HybridSearchOptions, ay as HybridVectorOptions, I as IdentityAssertion, d as IdentityAssertionId, e as IdentityAssertionResult, az as IdentityAssertionWriteFacade, f as IdentityFacade, g as IdentityNode, h as IdentityNodeRefInput, aA as IdentityNodeReference, i as IdentityPair, j as IdentityReadFacade, k as IdentityRelation, aB as IdentityTraversalOption, aC as IdentityValidityWindow, l as IdentityWriteSummary, aD as IfExistsMode, aE as InitialQueryBuilder, aF as KindIntrospection, aG as LabelPropagationMembership, aH as LabelPropagationOptions, L as LiveStoreOptions, aI as MaterializeRemovalsEntry, aJ as MaterializeRemovalsOptions, aK as MaterializeRemovalsResult, aL as MeasurableAdapterHistoryTransactionContext, aM as MeasurableAdapterTransactionContext, aN as MeasurableTransactionContext, aO as NeighborsOptions, aP as NoRecordedCoordinate, aQ as Node, aR as NodeAccessor, aS as NodeAlias, aT as NodeBulkFindByIndexOptions, aU as NodeCollection, aV as NodeCurrentReads, aW as NodeGetOrCreateByConstraintOptions, aX as NodeGetOrCreateByConstraintResult, aY as NodeIdentifier, aZ as NodeRef, a_ as NodeTemporalReads, a$ as NodeWrites, b0 as OntologyIntrospection, b1 as OperationHookContext, b2 as PageRankOptions, b3 as PageRankScore, b4 as PaginateOptions, b5 as PaginatedResult, b6 as PathNode, b7 as PersonalizedPageRankOptions, b8 as PersonalizedPageRankSeed, b9 as Predicate, ba as PreparedQuery, bb as PropsAccessor, bc as QueryHookContext, bd as QueryOptions, be as ReachableNode, bf as ReachableOptions, bg as RebuildContributionOptions, bh as RebuildFulltextOptions, bi as RebuildFulltextResult, bj as ReclaimedVectorFieldEntry, bk as ReconciledSchema, c as RecordedReadStore, R as RecordedReadStoreOptions, bl as RecordedScanOptions, bm as RecordedScanPage, bn as RecordedStoreView, bo as RecordedStoreViewEdgeCollection, bp as RecordedStoreViewEdgeCollections, bq as RecordedStoreViewNodeCollection, br as RecordedStoreViewNodeCollections, bs as RecursiveTraversalOptions, bt as ReembedFunction, bu as ReembedVectorFieldOptions, bv as ReembedVectorFieldResult, bw as SchemaIntrospection, bx as ScopedMeasure, by as SearchScopeOptions, bz as SelectContext, bA as SelectableEdge, bB as SelectableNode, bC as ShortestPathOptions, bD as ShortestPathResult, bE as SqlAvailability, bF as StoreHooks, S as StoreOptions, bG as StoreProjection, bH as StoreRef, bI as StoreSearch, bJ as StoreView, bK as StoreViewCanReachOptions, bL as StoreViewCoordinate, bM as StoreViewDegreeOptions, bN as StoreViewEdgeCollection, bO as StoreViewEdgeCollections, bP as StoreViewGraphAlgorithms, bQ as StoreViewLabelPropagationOptions, bR as StoreViewNeighborsOptions, bS as StoreViewNodeCollection, bT as StoreViewNodeCollections, bU as StoreViewPageRankOptions, bV as StoreViewPersonalizedPageRankOptions, bW as StoreViewReachableOptions, bX as StoreViewShortestPathOptions, bY as StoreViewSubgraphOptions, bZ as StoreViewWeaklyConnectedComponentsOptions, b_ as StoreViewWeightedShortestPathOptions, b$ as StreamOptions, c0 as SubgraphEdgeResult, c1 as SubgraphNodeResult, c2 as SubgraphOptions, c3 as SubgraphResult, c4 as SubsetEdge, c5 as SubsetNode, c6 as TemporalAlgorithmOptions, c7 as TransactionContext, c8 as TransactionOutcome, c9 as TransactionReceipt, ca as TraversalDirection, cb as TypedEdgeCollection, cc as TypedRecordedStoreViewEdgeCollection, cd as TypedStoreViewEdgeCollection, U as UnboundLiveStoreOptions, ce as UnionableQuery, cf as UniqueIntrospection, cg as UpdateEdgeInput, ch as UpdateNodeInput, ci as ValidityEndMutation, cj as VectorSearchHit, ck as VectorSearchOptions, cl as WeaklyConnectedComponentMembership, cm as WeaklyConnectedComponentsOptions, cn as WeightedShortestPathOptions, co as WeightedShortestPathResult, cp as asIdentityAssertionId, cq as createAdapterStore, cr as createAdapterStoreWithSchema, cs as createQueryBuilder, ct as createStore, cu as createStoreWithSchema, cv as createVerifiedAdapterStore, cw as createVerifiedStore, cx as defineSubgraphProject, cy as exists, cz as fieldRef, cA as inSubquery, cB as isParameterRef, cC as notExists, cD as notInSubquery, cE as param } from './store-DRrFCx5x.js';
|
|
9
9
|
export { D as DeleteLegacyRecordedAnchorMapOptions, M as MigrateLegacyRecordedTimeOptions, a as MigrateLegacyRecordedTimeResult, b as MigrateRecordedAnchorOptions, R as RepairInvertedWindowsOptions, c as RepairInvertedWindowsReport, d as RepairRelation, e as RepairRelationScope, f as deleteLegacyRecordedAnchorMap, m as migrateLegacyRecordedTime, g as migrateRecordedAnchor, r as repairInvertedValidityWindows } from './repair-validity-windows-DlUSqwCg.js';
|
|
10
10
|
export { B as BackendDisposedError, C as CardinalityError, b as CardinalityErrorDetails, c as CompilerInvariantError, d as ConfigurationError, e as ContributionRebuildRefusal, f as ContributionRebuildUnsupportedError, g as ContributionUnavailableError, h as ContributionUnavailableErrorDetails, D as DatabaseOperationError, i as DatabaseOperationErrorDetails, j as DisjointError, k as DisjointErrorDetails, E as EDGE_IDENTITY_MISMATCH_CODE, l as ENTITY_ALREADY_EXISTS_CODE, m as EagerMaterializationError, n as EagerMaterializationErrorDetails, o as EdgeNotFoundError, p as EdgeNotFoundErrorDetails, q as EmbeddingDimensionChangedError, r as EmbeddingDimensionChangedErrorDetails, s as EndpointError, t as EndpointErrorDetails, u as EndpointNotFoundError, v as EndpointNotFoundErrorDetails, w as ErrorCategory, x as ExportStreamCancelledError, y as ExportStreamIdleTimeoutError, G as GraphAlgorithmConvergenceError, I as IMMUTABLE_VALIDITY_LOWER_BOUND_CODE, z as INVERTED_VALIDITY_WINDOW_CODE, A as IdentityContradictionError, F as IdentityContradictionErrorDetails, H as IdentityEndpointValidityError, J as IdentityEndpointValidityErrorDetails, K as IdentitySeparationViolationError, L as IdentitySeparationViolationErrorDetails, M as IdentityValidityWindowError, N as IdentityValidityWindowErrorDetails, O as InvalidEdgeWeightError, P as InvalidEdgeWeightErrorDetails, Q as InvalidEdgeWeightReason, R as KindNotFoundError, S as KindNotFoundErrorDetails, T as MIGRATION_FAILURE_REASONS, U as MigrationError, W as MigrationErrorDetails, X as MigrationFailureReason, Y as NodeConstraintNotFoundError, Z as NodeConstraintNotFoundErrorDetails, _ as NodeIndexNotFoundError, $ as NodeIndexNotFoundErrorDetails, a0 as NodeNotFoundError, a1 as NodeNotFoundErrorDetails, a2 as RECORDED_CAPTURE_GUARD_CODES, a3 as RecordedCaptureGuardCode, a4 as RecordedCaptureGuardError, a5 as RestrictedDeleteError, a6 as RestrictedDeleteErrorDetails, a7 as SchemaContentConflictError, a8 as SchemaContentConflictErrorDetails, a9 as SchemaMismatchError, aa as SchemaMismatchErrorDetails, ab as StaleVersionError, ac as StaleVersionErrorDetails, ad as StoreNotInitializedError, ae as StoreNotInitializedErrorDetails, af as StoreNotInitializedReason, ag as TransactionClosedError, ah as TrustedImportError, ai as TrustedImportErrorReason, aj as TypeGraphError, ak as TypeGraphErrorOptions, al as UniquenessError, am as UniquenessErrorDetails, an as UnsupportedBackendCapabilityError, ao as UnsupportedPredicateError, a as ValidationError, ap as ValidationErrorDetails, V as ValidationIssue, aq as VersionConflictError, ar as VersionConflictErrorDetails, as as getErrorSuggestion, at as isConstraintError, au as isRecordedCaptureGuardError, av as isSystemError, aw as isTypeGraphError, ax as isUserRecoverable } from './index-D7d1u2gr.js';
|
|
11
11
|
export { I as IdentityChange, h as MaterializeIndexesEntry, j as MaterializeIndexesOptions, M as MaterializeIndexesResult, k as MaterializeSystemIndexesOptions } from './materialize-indexes-DJ3ykH59.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/identity/rebuild.ts","../src/identity/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AAA,kCAAA,EACzB,KAAK,CAAA,EAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA,CAAA;AAAA,OAC7C;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import { type GraphDef, type GraphIdentityConfig } from \"../core/define-graph\";\nimport { storeRuntime } from \"../store/runtime-port\";\nimport { type Store } from \"../store/store\";\n\n/**\n * Rebuilds the derived current identity closure for an identity-enabled store.\n * This is a repair operation: it does not change graph revision or assertions.\n */\nexport async function rebuildIdentityClosure<\n G extends GraphDef & Readonly<{ identity: GraphIdentityConfig }>,\n>(store: Store<G>): Promise<void> {\n await storeRuntime(store).rebuildIdentityClosure();\n}\n","import {\n type AllNodeTypes,\n type GraphDef,\n type NodeKinds,\n} from \"../core/define-graph\";\nimport { ValidationError } from \"../errors\";\nimport {\n type DynamicNode,\n type DynamicNodeReference,\n type GraphNodeReference,\n type Node,\n type NodeRef,\n} from \"../store/types\";\n\n/**\n * The accepted *input* form for every identity facade method: a whole node or\n * a `{ kind, id }` pair for any compile-time graph kind, plus a proof-bearing\n * node or reference produced through the runtime collection lane. Runtime\n * values stay nominal so accepting them does not make an arbitrary\n * `{ kind: string, id: string }` object type-safe.\n *\n * Identity results use {@link IdentityNodeReference}, which honestly includes\n * runtime kinds because an evolved kind can belong to a class reached from a\n * compile-time node.\n */\nexport type IdentityNodeRefInput<G extends GraphDef> =\n NodeRef<AllNodeTypes<G>> | DynamicNode | DynamicNodeReference;\n\n/**\n * A node reference returned by Operational Identity.\n *\n * Identity classes can contain runtime-evolved kinds even when a read starts\n * from a compile-time node, so results honestly include both lanes.\n */\nexport type IdentityNodeReference<G extends GraphDef> =\n GraphNodeReference<G> | DynamicNodeReference;\n\n/** A hydrated compile-time or runtime identity member. */\nexport type IdentityNode<G extends GraphDef> =\n | {\n [K in NodeKinds<G>]: Node<G[\"nodes\"][K][\"type\"]>;\n }[NodeKinds<G>]\n | DynamicNode;\n\ndeclare const __identityAssertionId: unique symbol;\n\nexport type IdentityAssertionId = string &\n Readonly<{ [__identityAssertionId]: true }>;\n\n/**\n * Brands a non-empty string as an {@link IdentityAssertionId}.\n *\n * Use this when a persisted identity assertion id has round-tripped through\n * untyped storage or an external boundary and must be passed back to a\n * retraction surface such as `retractAssertion` or `bulkRetractAssertions`.\n * Mirrors the `asNodeId` / `asEdgeId` precedent.\n *\n * @throws {ValidationError} when `value` is empty.\n */\nexport function asIdentityAssertionId(value: string): IdentityAssertionId {\n if (value.length === 0) {\n throw new ValidationError(\n \"asIdentityAssertionId must be a non-empty string.\",\n {\n issues: [\n {\n path: \"asIdentityAssertionId\",\n message: \"Expected a non-empty string.\",\n },\n ],\n },\n {\n suggestion: \"Use a persisted identity assertion id value.\",\n },\n );\n }\n return value as IdentityAssertionId;\n}\n\n/**\n * What one assertion claims about a pair of nodes: `\"same\"` merges them into\n * one equivalence set, `\"different\"` records a disjointness that a later\n * `\"same\"` claim must not contradict.\n */\nexport type IdentityRelation = \"same\" | \"different\";\n\n/**\n * One persisted identity claim about an ordered pair of nodes. Returned by the\n * assertion writers and by `identity.assertionsOf(...)`; `validTo` is set when\n * the assertion has been retracted, so a historical read can still see it.\n */\nexport type IdentityAssertion<G extends GraphDef> = Readonly<{\n id: IdentityAssertionId;\n relation: IdentityRelation;\n a: IdentityNodeReference<G>;\n b: IdentityNodeReference<G>;\n validFrom: string;\n validTo?: string;\n}>;\n\n/** Result of an idempotent assertion write. */\nexport type IdentityAssertionResult<G extends GraphDef> = Readonly<{\n assertion: IdentityAssertion<G>;\n action: \"created\" | \"existing\";\n}>;\n\n/** The half-open effective-time window of an identity assertion. */\nexport type IdentityValidityWindow = Readonly<{\n validFrom?: string;\n validTo?: string;\n}>;\n\n/** One ordered node pair handed to `bulkAssertSame` / `bulkAssertDifferent`. */\nexport type IdentityPair<G extends GraphDef> = Readonly<{\n a: IdentityNodeRefInput<G>;\n b: IdentityNodeRefInput<G>;\n}> &\n IdentityValidityWindow;\n\n/**\n * The read half of the identity surface: equivalence-set membership,\n * representative selection, and the assertions behind them.\n *\n * Obtained from a read-only lens — `store.asOf(...).identity`,\n * `store.snapshot().identity` — where it answers at that view's coordinate.\n * The full read+write surface is {@link IdentityFacade}.\n */\nexport type IdentityReadFacade<G extends GraphDef> = Readonly<{\n representativeOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<IdentityNodeReference<G> | undefined>;\n membersOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNodeReference<G>[]>;\n nodesOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNode<G>[]>;\n areSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n areDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n assertionsOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityAssertion<G>[]>;\n}>;\n\n/**\n * The full TypeGraph Identity Profile surface: {@link IdentityReadFacade} plus\n * the assertion writers and retractions.\n *\n * Obtained from `store.identity` or `tx.identity`, and present only on graphs\n * that declared `identity: { ... }` in `defineGraph`. Every writer is\n * idempotent — re-asserting an existing claim returns it with\n * `action: \"existing\"` rather than duplicating it.\n */\nexport type IdentityFacade<G extends GraphDef> = IdentityReadFacade<G> &\n Readonly<{\n assertSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n assertDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n bulkAssertSame: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n bulkAssertDifferent: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n retractAssertion: (\n id: IdentityAssertionId,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractSameAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractDifferentAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n bulkRetractAssertions: (\n ids: readonly IdentityAssertionId[],\n ) => Promise<readonly IdentityAssertion<G>[]>;\n }>;\n\n/**\n * Per-transaction identity write counts carried by a transaction receipt.\n * `total` is the sum of the three preceding counters.\n */\nexport type IdentityWriteSummary = Readonly<{\n sameAssertions: number;\n differentAssertions: number;\n retractions: number;\n total: number;\n}>;\n","/**\n * One-time offline migration: legacy shared embeddings table → per-field\n * strategy storage.\n *\n * ## What this is for\n *\n * The cross-backend vector cutover (#157) dropped the single shared\n * `typegraph_node_embeddings` table. Each\n * `VectorStrategy` now OWNS one typed, fixed-dimension structure per\n * `(nodeKind, fieldPath)` — the only layout that can be ANN-indexed on\n * libSQL and sqlite-vec, not just pgvector.\n *\n * Deployments that wrote embeddings under the old shared table before\n * upgrading still hold those rows. This utility drains them into the new\n * per-field storage **once**, during the upgrade, so existing embedded\n * data survives the cutover without re-embedding from source.\n *\n * It is an explicitly-run, offline step — not wired into `materializeIndexes`\n * or any boot path. Run it once after deploying the new version and before\n * (or alongside) the first `materializeIndexes()`, then drop the legacy\n * table at your leisure.\n *\n * ## How it works\n *\n * - Skips cleanly (returns a zero summary) when the legacy table is absent —\n * a fresh install, or a re-run after the table was dropped.\n * - Reads rows in keyset-paginated batches (never the whole table at once),\n * decoding the engine-native embedding column to a numeric array at the SQL\n * level: sqlite-vec stored a `vec_f32` blob (`vec_to_json` decodes it);\n * pgvector stored a native `vector` (`::text` yields a `[…]` literal).\n * - Re-inserts each row through `backend.upsertEmbedding`, which routes the\n * active strategy's `buildUpsert` and idempotently provisions the per-field\n * storage (the same `(nodeKind, fieldPath)` slot a fresh store write uses).\n * The migration stays graph-agnostic and execution-correct on both the\n * sync (better-sqlite3) and async (libsql / Postgres) backends — it does\n * not re-implement the backend's statement-execution glue.\n *\n * Idempotent and resumable: a partial run followed by a full run converges\n * to the same per-field tables, because every write is an upsert keyed by\n * `(graph_id, node_id)` in the strategy's owned storage.\n */\nimport {\n DEFAULT_EMBEDDING_INDEX_TYPE,\n DEFAULT_EMBEDDING_METRIC,\n type EmbeddingIndexType,\n type EmbeddingMetric,\n} from \"../core/embedding\";\nimport { EmbeddingDimensionChangedError } from \"../errors\";\nimport { sql, type SqlFragment } from \"../query/sql-fragment\";\nimport { asCompiledRowsSql } from \"../query/sql-intent\";\nimport { createDataKeyedBag } from \"../utils/object\";\nimport { requireDefined } from \"../utils/presence\";\nimport { isMissingTableError } from \"../utils/sql-errors\";\nimport { LEGACY_EMBEDDINGS_TABLE_NAME } from \"./drizzle/schema/sqlite\";\nimport { type GraphBackend } from \"./types\";\n\n/**\n * Default rows read per round-trip. Large enough to amortize round-trip\n * latency, small enough to bound peak memory regardless of table size.\n */\nconst DEFAULT_BATCH_SIZE = 500;\n\n/**\n * Metric / index type applied to a migrated field when no\n * {@link MigrateLegacyEmbeddingsOptions.resolveSlotConfig} is supplied (or\n * it returns `undefined`). Matches the defaults `embedding()` and\n * `resolveEmbeddingFields` apply, so a migrated field lands in storage shaped\n * identically to one written fresh through the store. Migrated data is only\n * ever brute-forceable until `materializeIndexes()` builds the ANN index, so\n * the index-type default governs only which ANN structure the per-field\n * storage DDL provisions, not the migration's correctness.\n */\nconst DEFAULT_SLOT_METRIC: EmbeddingMetric = DEFAULT_EMBEDDING_METRIC;\nconst DEFAULT_SLOT_INDEX_TYPE: EmbeddingIndexType =\n DEFAULT_EMBEDDING_INDEX_TYPE;\n\n/**\n * The resolved storage config for one `(nodeKind, fieldPath)` slot that the\n * legacy table did not record. The legacy shared table stored only the\n * vector and its dimension count — not the metric or index type — so a\n * caller that wants migrated fields to match a specific graph's `embedding()`\n * declarations supplies this resolver.\n */\nexport type LegacyEmbeddingSlotConfig = Readonly<{\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n}>;\n\n/**\n * Options for {@link migrateLegacyEmbeddings}.\n */\nexport type MigrateLegacyEmbeddingsOptions = Readonly<{\n /**\n * The backend to migrate, wired with the destination `VectorStrategy`\n * (i.e. the post-cutover backend). Its `vectorStrategy` owns the per-field\n * storage rows are written into and its `upsertEmbedding` performs the\n * writes.\n */\n backend: GraphBackend;\n\n /**\n * Restrict the migration to a single graph. When omitted, every graph's\n * rows in the legacy table are migrated (the table is graph-scoped by its\n * `graph_id` column).\n */\n graphId?: string;\n\n /**\n * Resolves the metric / index type for a `(nodeKind, fieldPath)` slot the\n * legacy table didn't persist. Return `undefined` to fall back to the\n * cosine / hnsw defaults. Supply this (typically reading the graph's\n * `embedding()` declarations) when migrated fields must match a specific\n * metric — e.g. an `l2` field, which scores incorrectly under the cosine\n * default.\n */\n resolveSlotConfig?: (\n nodeKind: string,\n fieldPath: string,\n ) => LegacyEmbeddingSlotConfig | undefined;\n\n /** Rows read per round-trip. Defaults to {@link DEFAULT_BATCH_SIZE}. */\n batchSize?: number;\n\n /**\n * Physical name of the legacy table to drain. Defaults to\n * {@link LEGACY_EMBEDDINGS_TABLE_NAME}. Override only for a non-default\n * deployment that renamed the embeddings table.\n */\n legacyTableName?: string;\n}>;\n\n/**\n * Summary of a {@link migrateLegacyEmbeddings} run.\n */\nexport type MigrateLegacyEmbeddingsResult = Readonly<{\n /** Total embedding rows re-inserted into per-field storage. */\n migrated: number;\n /**\n * Per-`(nodeKind, fieldPath)` counts, keyed `\"<nodeKind>.<fieldPath>\"`\n * (the strategy's logical-slot key form). Empty when the legacy table was\n * absent or held no rows for the requested scope.\n */\n perField: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their vector length didn't match the per-field\n * table's fixed dimension. The legacy shared column allowed mixed\n * dimensions for one `(nodeKind, fieldPath)` (e.g. an unmigrated model\n * change); the first migrated row fixes the typed table's dimension and\n * any differently-sized rows for that slot are skipped rather than aborting\n * the whole migration. Keyed `\"<nodeKind>.<fieldPath>\"`. Non-empty here\n * means those fields need a deliberate re-embed at a single dimension.\n */\n skippedDimensionMismatch: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their legacy embedding could not be decoded into a\n * finite-number array — a corrupt value (e.g. a pgvector `vector` column\n * permits `NaN`/`Infinity`, which is not valid JSON). Keyed\n * `\"<nodeKind>.<fieldPath>\"`. Skipping + reporting keeps one bad row from\n * aborting the whole migration; non-empty here means those rows need manual\n * repair.\n */\n skippedDecodeError: Readonly<Record<string, number>>;\n /**\n * Whether the legacy table existed. `false` means the run was a clean\n * no-op (fresh install, or already-dropped table on a re-run).\n */\n legacyTablePresent: boolean;\n}>;\n\n/**\n * A single legacy embedding row, with the engine-native vector already\n * decoded to a JSON array string by the dialect-specific SELECT. The\n * legacy `dimensions` column is intentionally not read: the decoded array's\n * length is the authoritative fixed dimension for the destination slot, and\n * relying on it sidesteps the per-driver string/number coercion the legacy\n * integer column would otherwise need.\n */\ntype LegacyEmbeddingRow = Readonly<{\n graph_id: string;\n node_kind: string;\n node_id: string;\n field_path: string;\n /** JSON array text, e.g. `\"[0.1,0.2,0.3]\"` — decoded per dialect. */\n embedding_json: string;\n}>;\n\n/**\n * Re-inserts every embedding from the legacy shared\n * `typegraph_node_embeddings` table into the active\n * `backend.vectorStrategy`'s per-`(nodeKind, fieldPath)` storage.\n *\n * One-time, explicitly-run upgrade step for the shared-table → per-field\n * cutover (#157). Idempotent, batched, and a clean no-op when the legacy\n * table is absent. See the module doc comment for the full contract.\n *\n * @throws Error when the backend exposes no `vectorStrategy` /\n * `upsertEmbedding` (nothing to migrate *into*) — a configuration\n * error the caller must fix by wiring the destination strategy\n * before migrating.\n */\nexport async function migrateLegacyEmbeddings(\n options: MigrateLegacyEmbeddingsOptions,\n): Promise<MigrateLegacyEmbeddingsResult> {\n const {\n backend,\n graphId,\n resolveSlotConfig,\n batchSize = DEFAULT_BATCH_SIZE,\n legacyTableName = LEGACY_EMBEDDINGS_TABLE_NAME,\n } = options;\n\n if (\n backend.vectorStrategy === undefined ||\n backend.upsertEmbedding === undefined\n ) {\n throw new Error(\n \"migrateLegacyEmbeddings requires a backend wired with a vectorStrategy \" +\n \"(the destination per-field storage). Pass the post-cutover backend.\",\n );\n }\n if (!Number.isInteger(batchSize) || batchSize <= 0) {\n throw new RangeError(\n `batchSize must be a positive integer, got: ${batchSize}`,\n );\n }\n const upsertEmbedding = backend.upsertEmbedding;\n const ensureVectorSlotContribution = backend.ensureVectorSlotContribution;\n\n // Data-keyed: slot keys are built from a row's `node_kind` / `field_path`.\n const perField = createDataKeyedBag<number>();\n const skippedDimensionMismatch = createDataKeyedBag<number>();\n const skippedDecodeError = createDataKeyedBag<number>();\n // (kind, field) slots whose per-field table + durable marker this run has\n // already provisioned, mapped to the dimension the table was fixed at.\n // `upsertEmbedding` asserts the marker (#135) and no longer self-creates\n // the table, so this offline migration (privileged) provisions each slot\n // once — at the first row's dimension, which fixes the typed table just as\n // the original lazy write did. Differently-sized later rows for the same\n // slot are detected against this map and skipped BEFORE the upsert: the\n // marker assert would otherwise read the differently-dimensioned slot as\n // stale and abort the whole migration, and the ensure is deliberately not\n // re-run per row (that would trip the marker drift-guard).\n const ensuredSlots = new Map<string, number>();\n let migrated = 0;\n\n let cursor: LegacyRowCursor | undefined;\n for (;;) {\n let batch: readonly LegacyEmbeddingRow[];\n try {\n batch = await readLegacyBatch(backend, {\n legacyTableName,\n graphId,\n batchSize,\n after: cursor,\n });\n } catch (error) {\n // A missing legacy table is the expected \"nothing to migrate\" path on\n // the first read — surface it as a clean no-op, not a failure.\n if (cursor === undefined && isMissingTableError(error)) {\n return {\n migrated: 0,\n perField: {},\n skippedDimensionMismatch: {},\n skippedDecodeError: {},\n legacyTablePresent: false,\n };\n }\n throw error;\n }\n\n if (batch.length === 0) break;\n\n for (const row of batch) {\n const slotKey = `${row.node_kind}.${row.field_path}`;\n\n let embedding: readonly number[];\n try {\n embedding = decodeEmbeddingJson(row);\n } catch {\n // A corrupt legacy value (e.g. a pgvector `vector` column permits\n // NaN/Infinity, which is not valid JSON) is skipped + reported rather\n // than aborting the whole migration on one bad row.\n skippedDecodeError[slotKey] = (skippedDecodeError[slotKey] ?? 0) + 1;\n continue;\n }\n const config = resolveSlotConfig?.(row.node_kind, row.field_path);\n // The decoded length is the authoritative fixed dimension — the\n // strategy provisions its column type (e.g. `F32_BLOB(N)`) from it.\n const slot = {\n graphId: row.graph_id,\n nodeKind: row.node_kind,\n fieldPath: row.field_path,\n dimensions: embedding.length,\n metric: config?.metric ?? DEFAULT_SLOT_METRIC,\n indexType: config?.indexType ?? DEFAULT_SLOT_INDEX_TYPE,\n };\n\n // Provision the per-field table + durable marker before the first\n // write into this slot. Once per (graph, kind, field): the first row's\n // dimension fixes the table. Keyed by graph id too — the legacy table\n // is graph-scoped, so the same `kind.field` can recur across graphs.\n const ensuredKey = JSON.stringify([\n row.graph_id,\n row.node_kind,\n row.field_path,\n ]);\n if (\n ensureVectorSlotContribution !== undefined &&\n !ensuredSlots.has(ensuredKey)\n ) {\n await ensureVectorSlotContribution(slot);\n ensuredSlots.set(ensuredKey, slot.dimensions);\n }\n\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension. Skip a differently-sized row up front —\n // its slot would fail the marker assert as stale (different\n // signature), aborting the migration instead of skipping the row.\n const provisionedDimensions = ensuredSlots.get(ensuredKey);\n if (\n provisionedDimensions !== undefined &&\n provisionedDimensions !== embedding.length\n ) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n\n try {\n await upsertEmbedding({ ...slot, nodeId: row.node_id, embedding });\n } catch (error) {\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension, so a differently-sized row is skipped and\n // reported rather than aborting the whole migration.\n if (error instanceof EmbeddingDimensionChangedError) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n throw error;\n }\n\n migrated += 1;\n perField[slotKey] = (perField[slotKey] ?? 0) + 1;\n }\n\n if (batch.length < batchSize) break;\n const last = requireDefined(batch.at(-1));\n cursor = {\n graphId: last.graph_id,\n nodeKind: last.node_kind,\n nodeId: last.node_id,\n fieldPath: last.field_path,\n };\n }\n\n // SPREAD at the boundary. The three maps are null-prototype accumulators\n // because their keys are slot names built from row data; that protection is\n // internal, and returning the bags as-is handed a caller three maps with no\n // `toString` and `instanceof Object === false` — while the early\n // \"nothing to migrate\" return above hands back `{}` literals, so the same\n // exported function answered with two different kinds of object depending on\n // whether the legacy table existed. Spread copies own properties with\n // CreateDataProperty, so a `__proto__` slot key survives as an own key.\n return {\n migrated,\n perField: { ...perField },\n skippedDimensionMismatch: { ...skippedDimensionMismatch },\n skippedDecodeError: { ...skippedDecodeError },\n legacyTablePresent: true,\n };\n}\n\n/**\n * Composite keyset cursor over the legacy table's primary key\n * `(graph_id, node_kind, node_id, field_path)`. Stable under concurrent\n * writes and immune to OFFSET drift, so a batched walk reads every row once.\n */\ntype LegacyRowCursor = Readonly<{\n graphId: string;\n nodeKind: string;\n nodeId: string;\n fieldPath: string;\n}>;\n\ntype ReadLegacyBatchParams = Readonly<{\n legacyTableName: string;\n graphId: string | undefined;\n batchSize: number;\n after: LegacyRowCursor | undefined;\n}>;\n\n/**\n * Reads one keyset-paginated batch of legacy rows, ordered by the primary\n * key, with the engine-native embedding column decoded to a JSON array\n * string by the dialect.\n */\nasync function readLegacyBatch(\n backend: GraphBackend,\n params: ReadLegacyBatchParams,\n): Promise<readonly LegacyEmbeddingRow[]> {\n const table = sql.identifier(params.legacyTableName);\n const embeddingJson = legacyEmbeddingDecodeExpression(backend);\n\n const conditions: SqlFragment[] = [];\n if (params.graphId !== undefined) {\n conditions.push(sql`\"graph_id\" = ${params.graphId}`);\n }\n if (params.after !== undefined) {\n conditions.push(keysetAfterCondition(params.after));\n }\n\n const whereClause =\n conditions.length === 0 ?\n sql``\n : sql` WHERE ${sql.join(conditions, sql` AND `)}`;\n\n const query = sql`\n SELECT\n \"graph_id\" AS graph_id,\n \"node_kind\" AS node_kind,\n \"node_id\" AS node_id,\n \"field_path\" AS field_path,\n ${embeddingJson} AS embedding_json\n FROM ${table}${whereClause}\n ORDER BY \"graph_id\" ASC, \"node_kind\" ASC, \"node_id\" ASC, \"field_path\" ASC\n LIMIT ${params.batchSize}\n `;\n\n return backend.execute<LegacyEmbeddingRow>(asCompiledRowsSql(query));\n}\n\n/**\n * The strict `>` comparison over the composite primary key, expressed as\n * the standard lexicographic OR-chain so it works on every dialect (SQLite\n * supports row-value comparison, but Postgres + SQLite both accept this\n * portable form).\n */\nfunction keysetAfterCondition(after: LegacyRowCursor): SqlFragment {\n return sql`\n (\n \"graph_id\" > ${after.graphId}\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" > ${after.nodeKind})\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" = ${after.nodeKind} AND \"node_id\" > ${after.nodeId})\n OR (\n \"graph_id\" = ${after.graphId}\n AND \"node_kind\" = ${after.nodeKind}\n AND \"node_id\" = ${after.nodeId}\n AND \"field_path\" > ${after.fieldPath}\n )\n )\n `;\n}\n\n/**\n * The SQL expression that decodes the legacy engine-native embedding column\n * into a JSON array string `embedding_json`. The single dialect branch in\n * this whole module: the legacy storage formats are genuinely engine-\n * specific, and there is no longer a strategy abstraction over the *legacy*\n * table to delegate to.\n */\nfunction legacyEmbeddingDecodeExpression(backend: GraphBackend): SqlFragment {\n switch (backend.dialect) {\n case \"sqlite\": {\n // Legacy SQLite embeddings were written via `vec_f32('[…]')`\n // (sqlite-vec binary). `vec_to_json` is its inverse, yielding the\n // JSON array text. Requires sqlite-vec on the connection — which the\n // legacy write path also required, so any deployment with legacy rows\n // has it loaded.\n return sql`vec_to_json(\"embedding\")`;\n }\n case \"postgres\": {\n // pgvector's native `vector` casts to its `[…]` text literal, which is\n // valid JSON for `JSON.parse`.\n return sql`\"embedding\"::text`;\n }\n default: {\n const _exhaustive: never = backend.dialect;\n throw new Error(\n `migrateLegacyEmbeddings does not support dialect: ${String(_exhaustive)}`,\n );\n }\n }\n}\n\n/**\n * Parses a decoded `embedding_json` array, asserting it is a non-empty array\n * of finite numbers. A bad decode (wrong type, NaN) names the offending row\n * loudly instead of writing a corrupt vector into per-field storage.\n */\nfunction decodeEmbeddingJson(row: LegacyEmbeddingRow): readonly number[] {\n let parsed: unknown;\n try {\n parsed = JSON.parse(row.embedding_json) as unknown;\n } catch (error) {\n throw new Error(\n `Failed to decode legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}): not valid JSON.`,\n { cause: error },\n );\n }\n if (!Array.isArray(parsed) || parsed.length === 0) {\n throw new Error(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) decoded to a non-array ` +\n `or empty value.`,\n );\n }\n for (const [index, value] of parsed.entries()) {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new TypeError(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) has a non-finite ` +\n `value at index ${index}: ${String(value)}.`,\n );\n }\n }\n return parsed as readonly number[];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/identity/rebuild.ts","../src/identity/types.ts","../src/backend/migrate-vectors.ts"],"names":["embedding"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,eAAsB,uBAEpB,KAAA,EAAgC;AAChC,EAAA,MAAM,YAAA,CAAa,KAAK,CAAA,CAAE,sBAAA,EAAuB;AACnD;;;AC+CO,SAAS,sBAAsB,KAAA,EAAoC;AACxE,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,eAAA;AAAA,MACR,mDAAA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CAAA,EAAyC,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC5D,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,GAAA,CAAI,OAAO,CAAA,kBAAA,CAAA;AAAA,MAC7C,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACA,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,IAAK,MAAA,CAAO,WAAW,CAAA,EAAG;AACjD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,qBAAA,EAAwB,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC3C,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,GAAA,CAAI,OAAO,CAAA,wCAAA;AAAA,KAE/C;AAAA,EACF;AACA,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,KAAK,CAAA,IAAK,MAAA,CAAO,SAAQ,EAAG;AAC7C,IAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACxD,MAAA,MAAM,IAAI,SAAA;AAAA,QACR,wBAAwB,GAAA,CAAI,SAAS,CAAA,CAAA,EAAI,GAAA,CAAI,UAAU,CAAA,QAAA,EAC3C,GAAA,CAAI,QAAQ,CAAA,OAAA,EAAU,IAAI,OAAO,CAAA,kCAAA,EACzB,KAAK,CAAA,EAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA,CAAA;AAAA,OAC7C;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import { type GraphDef, type GraphIdentityConfig } from \"../core/define-graph\";\nimport { storeRuntime } from \"../store/runtime-port\";\nimport { type Store } from \"../store/store\";\n\n/**\n * Rebuilds the derived current identity closure for an identity-enabled store.\n * This is a repair operation: it does not change graph revision or assertions.\n */\nexport async function rebuildIdentityClosure<\n G extends GraphDef & Readonly<{ identity: GraphIdentityConfig }>,\n>(store: Store<G>): Promise<void> {\n await storeRuntime(store).rebuildIdentityClosure();\n}\n","import {\n type AllNodeTypes,\n type GraphDef,\n type NodeKinds,\n} from \"../core/define-graph\";\nimport { ValidationError } from \"../errors\";\nimport {\n type DynamicNode,\n type DynamicNodeReference,\n type GraphNodeReference,\n type Node,\n type NodeRef,\n} from \"../store/types\";\n\n/**\n * The accepted *input* form for every identity facade method: a whole node or\n * a `{ kind, id }` pair for any compile-time graph kind, plus a proof-bearing\n * node or reference produced through the runtime collection lane. Runtime\n * values stay nominal so accepting them does not make an arbitrary\n * `{ kind: string, id: string }` object type-safe.\n *\n * Identity results use {@link IdentityNodeReference}, which honestly includes\n * runtime kinds because an evolved kind can belong to a class reached from a\n * compile-time node.\n */\nexport type IdentityNodeRefInput<G extends GraphDef> =\n NodeRef<AllNodeTypes<G>> | DynamicNode | DynamicNodeReference;\n\n/**\n * A node reference returned by Operational Identity.\n *\n * Identity classes can contain runtime-evolved kinds even when a read starts\n * from a compile-time node, so results honestly include both lanes.\n */\nexport type IdentityNodeReference<G extends GraphDef> =\n GraphNodeReference<G> | DynamicNodeReference;\n\n/** A hydrated compile-time or runtime identity member. */\nexport type IdentityNode<G extends GraphDef> =\n | {\n [K in NodeKinds<G>]: Node<G[\"nodes\"][K][\"type\"]>;\n }[NodeKinds<G>]\n | DynamicNode;\n\ndeclare const __identityAssertionId: unique symbol;\n\nexport type IdentityAssertionId = string &\n Readonly<{ [__identityAssertionId]: true }>;\n\n/**\n * Brands a non-empty string as an {@link IdentityAssertionId}.\n *\n * Use this when a persisted identity assertion id has round-tripped through\n * untyped storage or an external boundary and must be passed back to a\n * retraction surface such as `retractAssertion` or `bulkRetractAssertions`.\n * Mirrors the `asNodeId` / `asEdgeId` precedent.\n *\n * @throws {ValidationError} when `value` is empty.\n */\nexport function asIdentityAssertionId(value: string): IdentityAssertionId {\n if (value.length === 0) {\n throw new ValidationError(\n \"asIdentityAssertionId must be a non-empty string.\",\n {\n issues: [\n {\n path: \"asIdentityAssertionId\",\n message: \"Expected a non-empty string.\",\n },\n ],\n },\n {\n suggestion: \"Use a persisted identity assertion id value.\",\n },\n );\n }\n return value as IdentityAssertionId;\n}\n\n/**\n * What one assertion claims about a pair of nodes: `\"same\"` merges them into\n * one equivalence set, `\"different\"` records a disjointness that a later\n * `\"same\"` claim must not contradict.\n */\nexport type IdentityRelation = \"same\" | \"different\";\n\n/**\n * One persisted identity claim about an ordered pair of nodes. Returned by the\n * assertion writers and by `identity.assertionsOf(...)`; `validTo` is set when\n * the assertion has been retracted, so a historical read can still see it.\n */\nexport type IdentityAssertion<G extends GraphDef> = Readonly<{\n id: IdentityAssertionId;\n relation: IdentityRelation;\n a: IdentityNodeReference<G>;\n b: IdentityNodeReference<G>;\n validFrom: string;\n validTo?: string;\n}>;\n\n/** Result of an idempotent assertion write. */\nexport type IdentityAssertionResult<G extends GraphDef> = Readonly<{\n assertion: IdentityAssertion<G>;\n action: \"created\" | \"existing\";\n}>;\n\n/** The half-open effective-time window of an identity assertion. */\nexport type IdentityValidityWindow = Readonly<{\n validFrom?: string;\n validTo?: string;\n}>;\n\n/** One ordered node pair handed to `bulkAssertSame` / `bulkAssertDifferent`. */\nexport type IdentityPair<G extends GraphDef> = Readonly<{\n a: IdentityNodeRefInput<G>;\n b: IdentityNodeRefInput<G>;\n}> &\n IdentityValidityWindow;\n\n/**\n * The read half of the identity surface: equivalence-set membership,\n * representative selection, and the assertions behind them.\n *\n * Obtained from a read-only lens — `store.asOf(...).identity`,\n * `store.snapshot().identity` — where it answers at that view's coordinate.\n * The full read+write surface is {@link IdentityFacade}.\n */\nexport type IdentityReadFacade<G extends GraphDef> = Readonly<{\n representativeOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<IdentityNodeReference<G> | undefined>;\n membersOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNodeReference<G>[]>;\n nodesOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityNode<G>[]>;\n areSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n areDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<boolean>;\n assertionsOf: (\n ref: IdentityNodeRefInput<G>,\n ) => Promise<readonly IdentityAssertion<G>[]>;\n}>;\n\n/**\n * The full TypeGraph Identity Profile surface: {@link IdentityReadFacade} plus\n * the assertion writers and retractions.\n *\n * Obtained from `store.identity` or `tx.identity`, and present only on graphs\n * that declared `identity: { ... }` in `defineGraph`. Every writer is\n * idempotent — re-asserting an existing claim returns it with\n * `action: \"existing\"` rather than duplicating it.\n */\nexport type IdentityFacade<G extends GraphDef> = IdentityReadFacade<G> &\n Readonly<{\n assertSame: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n assertDifferent: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n window?: IdentityValidityWindow,\n ) => Promise<IdentityAssertionResult<G>>;\n bulkAssertSame: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n bulkAssertDifferent: (\n pairs: readonly IdentityPair<G>[],\n ) => Promise<readonly IdentityAssertionResult<G>[]>;\n retractAssertion: (\n id: IdentityAssertionId,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractSameAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n retractDifferentAssertion: (\n a: IdentityNodeRefInput<G>,\n b: IdentityNodeRefInput<G>,\n ) => Promise<IdentityAssertion<G> | undefined>;\n bulkRetractAssertions: (\n ids: readonly IdentityAssertionId[],\n ) => Promise<readonly IdentityAssertion<G>[]>;\n }>;\n\n/**\n * The assertion-only write surface of the TypeGraph Identity Profile.\n *\n * This deliberately excludes reads and retractions so constrained staging\n * handles can accept incoming identity claims without exposing the broader\n * operational identity surface.\n */\nexport type IdentityAssertionWriteFacade<G extends GraphDef> = Pick<\n IdentityFacade<G>,\n \"assertSame\" | \"assertDifferent\" | \"bulkAssertSame\" | \"bulkAssertDifferent\"\n>;\n\n/**\n * Per-transaction identity write counts carried by a transaction receipt.\n * `total` is the sum of the three preceding counters.\n */\nexport type IdentityWriteSummary = Readonly<{\n sameAssertions: number;\n differentAssertions: number;\n retractions: number;\n total: number;\n}>;\n","/**\n * One-time offline migration: legacy shared embeddings table → per-field\n * strategy storage.\n *\n * ## What this is for\n *\n * The cross-backend vector cutover (#157) dropped the single shared\n * `typegraph_node_embeddings` table. Each\n * `VectorStrategy` now OWNS one typed, fixed-dimension structure per\n * `(nodeKind, fieldPath)` — the only layout that can be ANN-indexed on\n * libSQL and sqlite-vec, not just pgvector.\n *\n * Deployments that wrote embeddings under the old shared table before\n * upgrading still hold those rows. This utility drains them into the new\n * per-field storage **once**, during the upgrade, so existing embedded\n * data survives the cutover without re-embedding from source.\n *\n * It is an explicitly-run, offline step — not wired into `materializeIndexes`\n * or any boot path. Run it once after deploying the new version and before\n * (or alongside) the first `materializeIndexes()`, then drop the legacy\n * table at your leisure.\n *\n * ## How it works\n *\n * - Skips cleanly (returns a zero summary) when the legacy table is absent —\n * a fresh install, or a re-run after the table was dropped.\n * - Reads rows in keyset-paginated batches (never the whole table at once),\n * decoding the engine-native embedding column to a numeric array at the SQL\n * level: sqlite-vec stored a `vec_f32` blob (`vec_to_json` decodes it);\n * pgvector stored a native `vector` (`::text` yields a `[…]` literal).\n * - Re-inserts each row through `backend.upsertEmbedding`, which routes the\n * active strategy's `buildUpsert` and idempotently provisions the per-field\n * storage (the same `(nodeKind, fieldPath)` slot a fresh store write uses).\n * The migration stays graph-agnostic and execution-correct on both the\n * sync (better-sqlite3) and async (libsql / Postgres) backends — it does\n * not re-implement the backend's statement-execution glue.\n *\n * Idempotent and resumable: a partial run followed by a full run converges\n * to the same per-field tables, because every write is an upsert keyed by\n * `(graph_id, node_id)` in the strategy's owned storage.\n */\nimport {\n DEFAULT_EMBEDDING_INDEX_TYPE,\n DEFAULT_EMBEDDING_METRIC,\n type EmbeddingIndexType,\n type EmbeddingMetric,\n} from \"../core/embedding\";\nimport { EmbeddingDimensionChangedError } from \"../errors\";\nimport { sql, type SqlFragment } from \"../query/sql-fragment\";\nimport { asCompiledRowsSql } from \"../query/sql-intent\";\nimport { createDataKeyedBag } from \"../utils/object\";\nimport { requireDefined } from \"../utils/presence\";\nimport { isMissingTableError } from \"../utils/sql-errors\";\nimport { LEGACY_EMBEDDINGS_TABLE_NAME } from \"./drizzle/schema/sqlite\";\nimport { type GraphBackend } from \"./types\";\n\n/**\n * Default rows read per round-trip. Large enough to amortize round-trip\n * latency, small enough to bound peak memory regardless of table size.\n */\nconst DEFAULT_BATCH_SIZE = 500;\n\n/**\n * Metric / index type applied to a migrated field when no\n * {@link MigrateLegacyEmbeddingsOptions.resolveSlotConfig} is supplied (or\n * it returns `undefined`). Matches the defaults `embedding()` and\n * `resolveEmbeddingFields` apply, so a migrated field lands in storage shaped\n * identically to one written fresh through the store. Migrated data is only\n * ever brute-forceable until `materializeIndexes()` builds the ANN index, so\n * the index-type default governs only which ANN structure the per-field\n * storage DDL provisions, not the migration's correctness.\n */\nconst DEFAULT_SLOT_METRIC: EmbeddingMetric = DEFAULT_EMBEDDING_METRIC;\nconst DEFAULT_SLOT_INDEX_TYPE: EmbeddingIndexType =\n DEFAULT_EMBEDDING_INDEX_TYPE;\n\n/**\n * The resolved storage config for one `(nodeKind, fieldPath)` slot that the\n * legacy table did not record. The legacy shared table stored only the\n * vector and its dimension count — not the metric or index type — so a\n * caller that wants migrated fields to match a specific graph's `embedding()`\n * declarations supplies this resolver.\n */\nexport type LegacyEmbeddingSlotConfig = Readonly<{\n metric: EmbeddingMetric;\n indexType: EmbeddingIndexType;\n}>;\n\n/**\n * Options for {@link migrateLegacyEmbeddings}.\n */\nexport type MigrateLegacyEmbeddingsOptions = Readonly<{\n /**\n * The backend to migrate, wired with the destination `VectorStrategy`\n * (i.e. the post-cutover backend). Its `vectorStrategy` owns the per-field\n * storage rows are written into and its `upsertEmbedding` performs the\n * writes.\n */\n backend: GraphBackend;\n\n /**\n * Restrict the migration to a single graph. When omitted, every graph's\n * rows in the legacy table are migrated (the table is graph-scoped by its\n * `graph_id` column).\n */\n graphId?: string;\n\n /**\n * Resolves the metric / index type for a `(nodeKind, fieldPath)` slot the\n * legacy table didn't persist. Return `undefined` to fall back to the\n * cosine / hnsw defaults. Supply this (typically reading the graph's\n * `embedding()` declarations) when migrated fields must match a specific\n * metric — e.g. an `l2` field, which scores incorrectly under the cosine\n * default.\n */\n resolveSlotConfig?: (\n nodeKind: string,\n fieldPath: string,\n ) => LegacyEmbeddingSlotConfig | undefined;\n\n /** Rows read per round-trip. Defaults to {@link DEFAULT_BATCH_SIZE}. */\n batchSize?: number;\n\n /**\n * Physical name of the legacy table to drain. Defaults to\n * {@link LEGACY_EMBEDDINGS_TABLE_NAME}. Override only for a non-default\n * deployment that renamed the embeddings table.\n */\n legacyTableName?: string;\n}>;\n\n/**\n * Summary of a {@link migrateLegacyEmbeddings} run.\n */\nexport type MigrateLegacyEmbeddingsResult = Readonly<{\n /** Total embedding rows re-inserted into per-field storage. */\n migrated: number;\n /**\n * Per-`(nodeKind, fieldPath)` counts, keyed `\"<nodeKind>.<fieldPath>\"`\n * (the strategy's logical-slot key form). Empty when the legacy table was\n * absent or held no rows for the requested scope.\n */\n perField: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their vector length didn't match the per-field\n * table's fixed dimension. The legacy shared column allowed mixed\n * dimensions for one `(nodeKind, fieldPath)` (e.g. an unmigrated model\n * change); the first migrated row fixes the typed table's dimension and\n * any differently-sized rows for that slot are skipped rather than aborting\n * the whole migration. Keyed `\"<nodeKind>.<fieldPath>\"`. Non-empty here\n * means those fields need a deliberate re-embed at a single dimension.\n */\n skippedDimensionMismatch: Readonly<Record<string, number>>;\n /**\n * Rows skipped because their legacy embedding could not be decoded into a\n * finite-number array — a corrupt value (e.g. a pgvector `vector` column\n * permits `NaN`/`Infinity`, which is not valid JSON). Keyed\n * `\"<nodeKind>.<fieldPath>\"`. Skipping + reporting keeps one bad row from\n * aborting the whole migration; non-empty here means those rows need manual\n * repair.\n */\n skippedDecodeError: Readonly<Record<string, number>>;\n /**\n * Whether the legacy table existed. `false` means the run was a clean\n * no-op (fresh install, or already-dropped table on a re-run).\n */\n legacyTablePresent: boolean;\n}>;\n\n/**\n * A single legacy embedding row, with the engine-native vector already\n * decoded to a JSON array string by the dialect-specific SELECT. The\n * legacy `dimensions` column is intentionally not read: the decoded array's\n * length is the authoritative fixed dimension for the destination slot, and\n * relying on it sidesteps the per-driver string/number coercion the legacy\n * integer column would otherwise need.\n */\ntype LegacyEmbeddingRow = Readonly<{\n graph_id: string;\n node_kind: string;\n node_id: string;\n field_path: string;\n /** JSON array text, e.g. `\"[0.1,0.2,0.3]\"` — decoded per dialect. */\n embedding_json: string;\n}>;\n\n/**\n * Re-inserts every embedding from the legacy shared\n * `typegraph_node_embeddings` table into the active\n * `backend.vectorStrategy`'s per-`(nodeKind, fieldPath)` storage.\n *\n * One-time, explicitly-run upgrade step for the shared-table → per-field\n * cutover (#157). Idempotent, batched, and a clean no-op when the legacy\n * table is absent. See the module doc comment for the full contract.\n *\n * @throws Error when the backend exposes no `vectorStrategy` /\n * `upsertEmbedding` (nothing to migrate *into*) — a configuration\n * error the caller must fix by wiring the destination strategy\n * before migrating.\n */\nexport async function migrateLegacyEmbeddings(\n options: MigrateLegacyEmbeddingsOptions,\n): Promise<MigrateLegacyEmbeddingsResult> {\n const {\n backend,\n graphId,\n resolveSlotConfig,\n batchSize = DEFAULT_BATCH_SIZE,\n legacyTableName = LEGACY_EMBEDDINGS_TABLE_NAME,\n } = options;\n\n if (\n backend.vectorStrategy === undefined ||\n backend.upsertEmbedding === undefined\n ) {\n throw new Error(\n \"migrateLegacyEmbeddings requires a backend wired with a vectorStrategy \" +\n \"(the destination per-field storage). Pass the post-cutover backend.\",\n );\n }\n if (!Number.isInteger(batchSize) || batchSize <= 0) {\n throw new RangeError(\n `batchSize must be a positive integer, got: ${batchSize}`,\n );\n }\n const upsertEmbedding = backend.upsertEmbedding;\n const ensureVectorSlotContribution = backend.ensureVectorSlotContribution;\n\n // Data-keyed: slot keys are built from a row's `node_kind` / `field_path`.\n const perField = createDataKeyedBag<number>();\n const skippedDimensionMismatch = createDataKeyedBag<number>();\n const skippedDecodeError = createDataKeyedBag<number>();\n // (kind, field) slots whose per-field table + durable marker this run has\n // already provisioned, mapped to the dimension the table was fixed at.\n // `upsertEmbedding` asserts the marker (#135) and no longer self-creates\n // the table, so this offline migration (privileged) provisions each slot\n // once — at the first row's dimension, which fixes the typed table just as\n // the original lazy write did. Differently-sized later rows for the same\n // slot are detected against this map and skipped BEFORE the upsert: the\n // marker assert would otherwise read the differently-dimensioned slot as\n // stale and abort the whole migration, and the ensure is deliberately not\n // re-run per row (that would trip the marker drift-guard).\n const ensuredSlots = new Map<string, number>();\n let migrated = 0;\n\n let cursor: LegacyRowCursor | undefined;\n for (;;) {\n let batch: readonly LegacyEmbeddingRow[];\n try {\n batch = await readLegacyBatch(backend, {\n legacyTableName,\n graphId,\n batchSize,\n after: cursor,\n });\n } catch (error) {\n // A missing legacy table is the expected \"nothing to migrate\" path on\n // the first read — surface it as a clean no-op, not a failure.\n if (cursor === undefined && isMissingTableError(error)) {\n return {\n migrated: 0,\n perField: {},\n skippedDimensionMismatch: {},\n skippedDecodeError: {},\n legacyTablePresent: false,\n };\n }\n throw error;\n }\n\n if (batch.length === 0) break;\n\n for (const row of batch) {\n const slotKey = `${row.node_kind}.${row.field_path}`;\n\n let embedding: readonly number[];\n try {\n embedding = decodeEmbeddingJson(row);\n } catch {\n // A corrupt legacy value (e.g. a pgvector `vector` column permits\n // NaN/Infinity, which is not valid JSON) is skipped + reported rather\n // than aborting the whole migration on one bad row.\n skippedDecodeError[slotKey] = (skippedDecodeError[slotKey] ?? 0) + 1;\n continue;\n }\n const config = resolveSlotConfig?.(row.node_kind, row.field_path);\n // The decoded length is the authoritative fixed dimension — the\n // strategy provisions its column type (e.g. `F32_BLOB(N)`) from it.\n const slot = {\n graphId: row.graph_id,\n nodeKind: row.node_kind,\n fieldPath: row.field_path,\n dimensions: embedding.length,\n metric: config?.metric ?? DEFAULT_SLOT_METRIC,\n indexType: config?.indexType ?? DEFAULT_SLOT_INDEX_TYPE,\n };\n\n // Provision the per-field table + durable marker before the first\n // write into this slot. Once per (graph, kind, field): the first row's\n // dimension fixes the table. Keyed by graph id too — the legacy table\n // is graph-scoped, so the same `kind.field` can recur across graphs.\n const ensuredKey = JSON.stringify([\n row.graph_id,\n row.node_kind,\n row.field_path,\n ]);\n if (\n ensureVectorSlotContribution !== undefined &&\n !ensuredSlots.has(ensuredKey)\n ) {\n await ensureVectorSlotContribution(slot);\n ensuredSlots.set(ensuredKey, slot.dimensions);\n }\n\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension. Skip a differently-sized row up front —\n // its slot would fail the marker assert as stale (different\n // signature), aborting the migration instead of skipping the row.\n const provisionedDimensions = ensuredSlots.get(ensuredKey);\n if (\n provisionedDimensions !== undefined &&\n provisionedDimensions !== embedding.length\n ) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n\n try {\n await upsertEmbedding({ ...slot, nodeId: row.node_id, embedding });\n } catch (error) {\n // The legacy shared column allowed mixed dimensions for one\n // (nodeKind, fieldPath); the per-field table is fixed at the first\n // migrated row's dimension, so a differently-sized row is skipped and\n // reported rather than aborting the whole migration.\n if (error instanceof EmbeddingDimensionChangedError) {\n skippedDimensionMismatch[slotKey] =\n (skippedDimensionMismatch[slotKey] ?? 0) + 1;\n continue;\n }\n throw error;\n }\n\n migrated += 1;\n perField[slotKey] = (perField[slotKey] ?? 0) + 1;\n }\n\n if (batch.length < batchSize) break;\n const last = requireDefined(batch.at(-1));\n cursor = {\n graphId: last.graph_id,\n nodeKind: last.node_kind,\n nodeId: last.node_id,\n fieldPath: last.field_path,\n };\n }\n\n // SPREAD at the boundary. The three maps are null-prototype accumulators\n // because their keys are slot names built from row data; that protection is\n // internal, and returning the bags as-is handed a caller three maps with no\n // `toString` and `instanceof Object === false` — while the early\n // \"nothing to migrate\" return above hands back `{}` literals, so the same\n // exported function answered with two different kinds of object depending on\n // whether the legacy table existed. Spread copies own properties with\n // CreateDataProperty, so a `__proto__` slot key survives as an own key.\n return {\n migrated,\n perField: { ...perField },\n skippedDimensionMismatch: { ...skippedDimensionMismatch },\n skippedDecodeError: { ...skippedDecodeError },\n legacyTablePresent: true,\n };\n}\n\n/**\n * Composite keyset cursor over the legacy table's primary key\n * `(graph_id, node_kind, node_id, field_path)`. Stable under concurrent\n * writes and immune to OFFSET drift, so a batched walk reads every row once.\n */\ntype LegacyRowCursor = Readonly<{\n graphId: string;\n nodeKind: string;\n nodeId: string;\n fieldPath: string;\n}>;\n\ntype ReadLegacyBatchParams = Readonly<{\n legacyTableName: string;\n graphId: string | undefined;\n batchSize: number;\n after: LegacyRowCursor | undefined;\n}>;\n\n/**\n * Reads one keyset-paginated batch of legacy rows, ordered by the primary\n * key, with the engine-native embedding column decoded to a JSON array\n * string by the dialect.\n */\nasync function readLegacyBatch(\n backend: GraphBackend,\n params: ReadLegacyBatchParams,\n): Promise<readonly LegacyEmbeddingRow[]> {\n const table = sql.identifier(params.legacyTableName);\n const embeddingJson = legacyEmbeddingDecodeExpression(backend);\n\n const conditions: SqlFragment[] = [];\n if (params.graphId !== undefined) {\n conditions.push(sql`\"graph_id\" = ${params.graphId}`);\n }\n if (params.after !== undefined) {\n conditions.push(keysetAfterCondition(params.after));\n }\n\n const whereClause =\n conditions.length === 0 ?\n sql``\n : sql` WHERE ${sql.join(conditions, sql` AND `)}`;\n\n const query = sql`\n SELECT\n \"graph_id\" AS graph_id,\n \"node_kind\" AS node_kind,\n \"node_id\" AS node_id,\n \"field_path\" AS field_path,\n ${embeddingJson} AS embedding_json\n FROM ${table}${whereClause}\n ORDER BY \"graph_id\" ASC, \"node_kind\" ASC, \"node_id\" ASC, \"field_path\" ASC\n LIMIT ${params.batchSize}\n `;\n\n return backend.execute<LegacyEmbeddingRow>(asCompiledRowsSql(query));\n}\n\n/**\n * The strict `>` comparison over the composite primary key, expressed as\n * the standard lexicographic OR-chain so it works on every dialect (SQLite\n * supports row-value comparison, but Postgres + SQLite both accept this\n * portable form).\n */\nfunction keysetAfterCondition(after: LegacyRowCursor): SqlFragment {\n return sql`\n (\n \"graph_id\" > ${after.graphId}\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" > ${after.nodeKind})\n OR (\"graph_id\" = ${after.graphId} AND \"node_kind\" = ${after.nodeKind} AND \"node_id\" > ${after.nodeId})\n OR (\n \"graph_id\" = ${after.graphId}\n AND \"node_kind\" = ${after.nodeKind}\n AND \"node_id\" = ${after.nodeId}\n AND \"field_path\" > ${after.fieldPath}\n )\n )\n `;\n}\n\n/**\n * The SQL expression that decodes the legacy engine-native embedding column\n * into a JSON array string `embedding_json`. The single dialect branch in\n * this whole module: the legacy storage formats are genuinely engine-\n * specific, and there is no longer a strategy abstraction over the *legacy*\n * table to delegate to.\n */\nfunction legacyEmbeddingDecodeExpression(backend: GraphBackend): SqlFragment {\n switch (backend.dialect) {\n case \"sqlite\": {\n // Legacy SQLite embeddings were written via `vec_f32('[…]')`\n // (sqlite-vec binary). `vec_to_json` is its inverse, yielding the\n // JSON array text. Requires sqlite-vec on the connection — which the\n // legacy write path also required, so any deployment with legacy rows\n // has it loaded.\n return sql`vec_to_json(\"embedding\")`;\n }\n case \"postgres\": {\n // pgvector's native `vector` casts to its `[…]` text literal, which is\n // valid JSON for `JSON.parse`.\n return sql`\"embedding\"::text`;\n }\n default: {\n const _exhaustive: never = backend.dialect;\n throw new Error(\n `migrateLegacyEmbeddings does not support dialect: ${String(_exhaustive)}`,\n );\n }\n }\n}\n\n/**\n * Parses a decoded `embedding_json` array, asserting it is a non-empty array\n * of finite numbers. A bad decode (wrong type, NaN) names the offending row\n * loudly instead of writing a corrupt vector into per-field storage.\n */\nfunction decodeEmbeddingJson(row: LegacyEmbeddingRow): readonly number[] {\n let parsed: unknown;\n try {\n parsed = JSON.parse(row.embedding_json) as unknown;\n } catch (error) {\n throw new Error(\n `Failed to decode legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}): not valid JSON.`,\n { cause: error },\n );\n }\n if (!Array.isArray(parsed) || parsed.length === 0) {\n throw new Error(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) decoded to a non-array ` +\n `or empty value.`,\n );\n }\n for (const [index, value] of parsed.entries()) {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new TypeError(\n `Legacy embedding for ${row.node_kind}.${row.field_path} ` +\n `(graph ${row.graph_id}, node ${row.node_id}) has a non-finite ` +\n `value at index ${index}: ${String(value)}.`,\n );\n }\n }\n return parsed as readonly number[];\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { d8 as GraphDef } from './types-BqFZTQmV.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Private capability bridge from an opaque ingestion branch to interchange.
|
|
5
|
+
*
|
|
6
|
+
* The branch handle must not expose its relaxed-schema Store, but interchange
|
|
7
|
+
* still needs the real Store so it can reuse the one import implementation that
|
|
8
|
+
* owns validation, temporal windows, edge endpoints, and stream leases.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
declare const INGESTION_IMPORT_TARGET_BRAND: unique symbol;
|
|
12
|
+
/** Opaque capability implemented by ingestion branches accepted by import. */
|
|
13
|
+
type IngestionImportTarget<G extends GraphDef> = Readonly<{
|
|
14
|
+
[INGESTION_IMPORT_TARGET_BRAND]: G;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type { IngestionImportTarget as I };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { d8 as GraphDef } from './types-BqFZTQmV.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Private capability bridge from an opaque ingestion branch to interchange.
|
|
5
|
+
*
|
|
6
|
+
* The branch handle must not expose its relaxed-schema Store, but interchange
|
|
7
|
+
* still needs the real Store so it can reuse the one import implementation that
|
|
8
|
+
* owns validation, temporal windows, edge endpoints, and stream leases.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
declare const INGESTION_IMPORT_TARGET_BRAND: unique symbol;
|
|
12
|
+
/** Opaque capability implemented by ingestion branches accepted by import. */
|
|
13
|
+
type IngestionImportTarget<G extends GraphDef> = Readonly<{
|
|
14
|
+
[INGESTION_IMPORT_TARGET_BRAND]: G;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export type { IngestionImportTarget as I };
|