@nicia-ai/typegraph 0.67.0 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/backend/drizzle/engine/index.cjs +6 -6
  3. package/dist/backend/drizzle/engine/index.js +1 -1
  4. package/dist/backend/postgres/index.cjs +15 -15
  5. package/dist/backend/postgres/index.js +1 -1
  6. package/dist/backend/postgres/pglite-store.cjs +1 -1
  7. package/dist/backend/postgres/pglite-store.js +1 -1
  8. package/dist/backend/postgres/pglite.cjs +3 -3
  9. package/dist/backend/postgres/pglite.js +2 -2
  10. package/dist/backend/sqlite/index.cjs +14 -14
  11. package/dist/backend/sqlite/index.js +1 -1
  12. package/dist/backend/sqlite/libsql.cjs +6 -6
  13. package/dist/backend/sqlite/libsql.js +1 -1
  14. package/dist/backend/sqlite/local-store.cjs +1 -1
  15. package/dist/backend/sqlite/local-store.js +1 -1
  16. package/dist/backend/sqlite/local.cjs +3 -3
  17. package/dist/backend/sqlite/local.js +2 -2
  18. package/dist/{chunk-ZONDBN6H.js → chunk-6DY26DPE.js} +3 -3
  19. package/dist/{chunk-ZONDBN6H.js.map → chunk-6DY26DPE.js.map} +1 -1
  20. package/dist/{chunk-YHMXF7OZ.js → chunk-6J3VUPI6.js} +3 -3
  21. package/dist/{chunk-YHMXF7OZ.js.map → chunk-6J3VUPI6.js.map} +1 -1
  22. package/dist/{chunk-MN325MG4.cjs → chunk-7MQL7FEN.cjs} +11 -2
  23. package/dist/chunk-7MQL7FEN.cjs.map +1 -0
  24. package/dist/{chunk-WWSYGZED.cjs → chunk-E6XL3KMZ.cjs} +6 -6
  25. package/dist/{chunk-WWSYGZED.cjs.map → chunk-E6XL3KMZ.cjs.map} +1 -1
  26. package/dist/{chunk-2DJKHZQ4.js → chunk-EORFWD6O.js} +11 -2
  27. package/dist/chunk-EORFWD6O.js.map +1 -0
  28. package/dist/{chunk-ANMCKLZQ.cjs → chunk-ZRIXU33S.cjs} +12 -12
  29. package/dist/{chunk-ANMCKLZQ.cjs.map → chunk-ZRIXU33S.cjs.map} +1 -1
  30. package/dist/graph-merge/index.cjs +520 -2
  31. package/dist/graph-merge/index.cjs.map +1 -1
  32. package/dist/graph-merge/index.d.cts +298 -1
  33. package/dist/graph-merge/index.d.ts +298 -1
  34. package/dist/graph-merge/index.js +507 -3
  35. package/dist/graph-merge/index.js.map +1 -1
  36. package/dist/{local-store-impl-E23EDYPV.js → local-store-impl-CCMWTLGY.js} +4 -4
  37. package/dist/{local-store-impl-E23EDYPV.js.map → local-store-impl-CCMWTLGY.js.map} +1 -1
  38. package/dist/{local-store-impl-7SPBIS4M.cjs → local-store-impl-GI6S4J6B.cjs} +6 -6
  39. package/dist/{local-store-impl-7SPBIS4M.cjs.map → local-store-impl-GI6S4J6B.cjs.map} +1 -1
  40. package/dist/{pglite-store-impl-U55HQ5ZY.cjs → pglite-store-impl-HAPAJUIO.cjs} +6 -6
  41. package/dist/{pglite-store-impl-U55HQ5ZY.cjs.map → pglite-store-impl-HAPAJUIO.cjs.map} +1 -1
  42. package/dist/{pglite-store-impl-VAIEJZOU.js → pglite-store-impl-HDLFOZWS.js} +4 -4
  43. package/dist/{pglite-store-impl-VAIEJZOU.js.map → pglite-store-impl-HDLFOZWS.js.map} +1 -1
  44. package/package.json +1 -1
  45. package/dist/chunk-2DJKHZQ4.js.map +0 -1
  46. package/dist/chunk-MN325MG4.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkMN325MG4_cjs = require('./chunk-MN325MG4.cjs');
3
+ var chunk7MQL7FEN_cjs = require('./chunk-7MQL7FEN.cjs');
4
4
  var chunkI7SBZJI2_cjs = require('./chunk-I7SBZJI2.cjs');
5
5
  var chunk6JRVV2SS_cjs = require('./chunk-6JRVV2SS.cjs');
6
6
  var chunk7XYPLAPL_cjs = require('./chunk-7XYPLAPL.cjs');
@@ -20,7 +20,7 @@ async function loadDefaultPgvectorExtension() {
20
20
  }
21
21
  }
22
22
  async function createLocalPgliteBackend(options = {}) {
23
- const tables2 = options.tables ?? chunkMN325MG4_cjs.tables;
23
+ const tables2 = options.tables ?? chunk7MQL7FEN_cjs.tables;
24
24
  const vectorExtension = options.vector === false ? void 0 : options.vector ?? await loadDefaultPgvectorExtension();
25
25
  const vectorEnabled = vectorExtension !== void 0;
26
26
  const client = await pglite.PGlite.create({
@@ -28,10 +28,10 @@ async function createLocalPgliteBackend(options = {}) {
28
28
  ...vectorExtension === void 0 ? {} : { extensions: { vector: vectorExtension } }
29
29
  });
30
30
  try {
31
- const migrationSql = vectorEnabled ? chunkMN325MG4_cjs.generatePostgresMigrationSQL(tables2, options.fulltext) : chunkMN325MG4_cjs.generateVectorlessPostgresMigrationSQL(tables2, options.fulltext);
31
+ const migrationSql = vectorEnabled ? chunk7MQL7FEN_cjs.generatePostgresMigrationSQL(tables2, options.fulltext) : chunk7MQL7FEN_cjs.generateVectorlessPostgresMigrationSQL(tables2, options.fulltext);
32
32
  await client.exec(migrationSql);
33
33
  const db = pglite$1.drizzle(client);
34
- const backend = chunkMN325MG4_cjs.createPostgresBackend(db, {
34
+ const backend = chunk7MQL7FEN_cjs.createPostgresBackend(db, {
35
35
  ...options.schemaProvisioning === void 0 ? {} : { schemaProvisioning: options.schemaProvisioning },
36
36
  tables: tables2,
37
37
  ...vectorEnabled ? {} : { vector: false },
@@ -51,5 +51,5 @@ async function createLocalPgliteBackend(options = {}) {
51
51
  }
52
52
 
53
53
  exports.createLocalPgliteBackend = createLocalPgliteBackend;
54
- //# sourceMappingURL=chunk-WWSYGZED.cjs.map
55
- //# sourceMappingURL=chunk-WWSYGZED.cjs.map
54
+ //# sourceMappingURL=chunk-E6XL3KMZ.cjs.map
55
+ //# sourceMappingURL=chunk-E6XL3KMZ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/backend/postgres/pglite.ts"],"names":["ConfigurationError","tables","PGlite","generatePostgresMigrationSQL","generateVectorlessPostgresMigrationSQL","drizzle","createPostgresBackend","wrapWithManagedClose","markBundledRootAutocommitEligible","closeAfterFailure"],"mappings":";;;;;;;;;AAsJA,eAAe,4BAAA,GAAmD;AAChE,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,MAAM,OAAO,+BAA+B,CAAA;AAC5D,IAAA,OAAO,OAAA,CAAQ,MAAA;AAAA,EACjB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIA,oCAAA;AAAA,MACR,2PAAA;AAAA,MAIA,EAAE,OAAA,EAAS,QAAA,EAAU,UAAA,EAAY,+BAAA,EAAgC;AAAA,MACjE,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAoBA,eAAsB,wBAAA,CACpB,OAAA,GAAqC,EAAC,EACH;AACnC,EAAA,MAAMC,OAAAA,GAAS,QAAQ,MAAA,IAAUA,wBAAA;AAMjC,EAAA,MAAM,eAAA,GACJ,QAAQ,MAAA,KAAW,KAAA,GACjB,SACC,OAAA,CAAQ,MAAA,IAAW,MAAM,4BAAA,EAA6B;AAC3D,EAAA,MAAM,gBAAgB,eAAA,KAAoB,MAAA;AAO1C,EAAA,MAAM,MAAA,GAAS,MAAMC,aAAA,CAAO,MAAA,CAAO;AAAA,IACjC,GAAI,QAAQ,OAAA,KAAY,MAAA,GAAY,EAAC,GAAI,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAQ;AAAA,IACpE,GAAI,eAAA,KAAoB,MAAA,GACtB,EAAC,GACD,EAAE,UAAA,EAAY,EAAE,MAAA,EAAQ,eAAA,EAAgB;AAAE,GAC7C,CAAA;AAED,EAAA,IAAI;AAGF,IAAA,MAAM,YAAA,GACJ,aAAA,GACEC,8CAAA,CAA6BF,OAAAA,EAAQ,OAAA,CAAQ,QAAQ,CAAA,GACrDG,wDAAA,CAAuCH,OAAAA,EAAQ,OAAA,CAAQ,QAAQ,CAAA;AACnE,IAAA,MAAM,MAAA,CAAO,KAAK,YAAY,CAAA;AAE9B,IAAA,MAAM,EAAA,GAAKI,iBAAQ,MAAM,CAAA;AACzB,IAAA,MAAM,OAAA,GAAUC,wCAAsB,EAAA,EAAI;AAAA,MACxC,GAAI,QAAQ,kBAAA,KAAuB,KAAA,CAAA,GACjC,EAAC,GACD,EAAE,kBAAA,EAAoB,OAAA,CAAQ,kBAAA,EAAmB;AAAA,MACnD,MAAA,EAAAL,OAAAA;AAAA,MACA,GAAI,aAAA,GAAgB,EAAC,GAAI,EAAE,QAAQ,KAAA,EAAM;AAAA,MACzC,GAAI,QAAQ,QAAA,KAAa,KAAA,CAAA,GAAY,EAAC,GAAI,EAAE,QAAA,EAAU,OAAA,CAAQ,QAAA;AAAS,KACxE,CAAA;AACD,IAAA,MAAM,cAAA,GAAiBM,sCAAA,CAAqB,OAAA,EAAS,YAAY;AAC/D,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAO;AAAA,MACL,OAAA,EAASC,oDAAkC,cAAc,CAAA;AAAA,MACzD,EAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,mCAAA,CAAkB,QAAQ,KAAK,CAAA;AAAA,EACxC;AACF","file":"chunk-WWSYGZED.cjs","sourcesContent":["/**\n * Local PGlite backend — Postgres-in-WASM, running in-process.\n *\n * [PGlite](https://pglite.dev/) is a full Postgres compiled to WebAssembly\n * that runs inside the Node/Bun/Deno/browser process with no server and no\n * native addon. This is the batteries-included Postgres analog of\n * `createLocalSqliteBackend`: it constructs a PGlite instance, loads the\n * pgvector extension, runs the schema DDL, and returns a ready\n * `{ backend, db }` pair whose `close()` disposes the engine.\n *\n * `@electric-sql/pglite` is an optional peer dependency. Vector support\n * additionally needs `@electric-sql/pglite-pgvector` (PGlite ≥ 0.5 ships\n * pgvector as a separate package). Install what you need:\n *\n * ```bash\n * pnpm add @electric-sql/pglite @electric-sql/pglite-pgvector\n * ```\n *\n * @example In-memory database (default, vector enabled)\n * ```typescript\n * import { createLocalPgliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/postgres/pglite\";\n *\n * const { backend } = await createLocalPgliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example Persistent on-disk database\n * ```typescript\n * const { backend, db } = await createLocalPgliteBackend({ dataDir: \"./pgdata\" });\n * ```\n *\n * @example No vector support (skip the pgvector extension)\n * ```typescript\n * const { backend } = await createLocalPgliteBackend({ vector: false });\n * ```\n *\n * PGlite is single-connection and serial: there is no pooling, so concurrent\n * `store.transaction()` calls queue rather than run in parallel.\n */\nimport { type Extension, PGlite } from \"@electric-sql/pglite\";\nimport { drizzle, type PgliteDatabase } from \"drizzle-orm/pglite\";\n\nimport { ConfigurationError } from \"../../errors\";\nimport { type FulltextStrategy } from \"../../query/dialect/fulltext-strategy\";\nimport { markBundledRootAutocommitEligible } from \"../capabilities/autocommit-single-statement\";\nimport { wrapWithManagedClose } from \"../derive-backend\";\nexport type { GraphIdentityConfig } from \"../../core/define-graph\";\nimport {\n generatePostgresMigrationSQL,\n generateVectorlessPostgresMigrationSQL,\n} from \"../drizzle/ddl\";\nimport { type AnyPgTransaction } from \"../drizzle/execution\";\nexport type { AnyPgDatabase, AnyPgTransaction } from \"../drizzle/execution\";\nimport {\n createPostgresBackend,\n type PostgresTables,\n tables as defaultTables,\n} from \"../drizzle/postgres\";\nimport {\n type AdapterBackend,\n closeAfterFailure,\n type SchemaProvisioning,\n} from \"../types\";\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../types\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a local PGlite backend.\n */\nexport type LocalPgliteBackendOptions = Readonly<{\n /**\n * PGlite data directory. Omit for an in-memory database (the default).\n * Accepts any PGlite data-dir spec: a filesystem path (`\"./pgdata\"`),\n * `\"memory://\"`, or a browser/runtime-specific scheme such as\n * `\"idb://my-db\"`.\n */\n dataDir?: string;\n\n /**\n * Custom table definitions. Defaults to standard TypeGraph table names.\n */\n tables?: PostgresTables;\n\n /**\n * Controls the pgvector stack:\n *\n * - **omitted (default)** — load pgvector from `@electric-sql/pglite-pgvector`\n * and run `CREATE EXTENSION vector`, so embedding fields work out of the\n * box. Throws a {@link ConfigurationError} if the package isn't installed.\n * - **`false`** — skip the extension entirely; the backend advertises no\n * vector capability (mirroring a SQLite connection without sqlite-vec).\n * Use when a graph carries no embeddings, or to avoid the extension dep.\n * - **a PGlite `Extension`** — bring your own pgvector build or custom\n * extension packaging. Decouples this helper from a specific pgvector\n * package version.\n */\n vector?: false | Extension;\n\n /**\n * Override the fulltext strategy. Defaults to `tsvectorStrategy`. Pass\n * `false` to disable fulltext support entirely — the backend then\n * advertises no `capabilities.fulltext` and omits the fulltext CRUD/search\n * methods, and the installation DDL never creates the fulltext table,\n * mirroring `vector: false`.\n */\n fulltext?: FulltextStrategy | false;\n /** Opt in to provisioning within caller-owned schema transactions. */\n schemaProvisioning?: SchemaProvisioning;\n}>;\n\n/**\n * Result of creating a local PGlite backend.\n */\nexport type LocalPgliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore. Its `close()`\n * disposes the underlying PGlite engine.\n */\n backend: AdapterBackend<AnyPgTransaction>;\n\n /**\n * The underlying Drizzle database instance. Useful for direct SQL access.\n */\n db: PgliteDatabase;\n\n /**\n * The raw PGlite instance, for engine-specific operations such as\n * `dumpDataDir()` / `clone()` not surfaced through Drizzle.\n */\n client: PGlite;\n}>;\n\n// ============================================================\n// Vector extension loading\n// ============================================================\n\n/**\n * Dynamically loads the default pgvector extension from\n * `@electric-sql/pglite-pgvector`. Kept as a runtime import so the package\n * stays an optional peer dependency — callers using `vector: false` or\n * supplying their own extension never need it installed.\n */\nasync function loadDefaultPgvectorExtension(): Promise<Extension> {\n try {\n const module_ = await import(\"@electric-sql/pglite-pgvector\");\n return module_.vector;\n } catch (error) {\n throw new ConfigurationError(\n \"createLocalPgliteBackend needs the pgvector extension but \" +\n \"`@electric-sql/pglite-pgvector` could not be loaded. Install it \" +\n \"(`pnpm add @electric-sql/pglite-pgvector`), pass your own `vector` \" +\n \"extension, or set `vector: false` to disable vector support.\",\n { backend: \"pglite\", dependency: \"@electric-sql/pglite-pgvector\" },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a TypeGraph backend backed by an in-process PGlite database.\n *\n * Constructs the PGlite engine (loading pgvector unless disabled), executes\n * the schema DDL, and wires the standard Postgres backend. The returned\n * backend owns the engine: call `backend.close()` to dispose it.\n *\n * For production Postgres, or a PGlite instance you construct yourself,\n * use `createPostgresBackend` directly with your own Drizzle database — the\n * execution fast path detects PGlite and routes it correctly.\n *\n * @param options - Configuration options\n * @returns Backend, Drizzle database, and raw PGlite client\n */\nexport async function createLocalPgliteBackend(\n options: LocalPgliteBackendOptions = {},\n): Promise<LocalPgliteBackendResult> {\n const tables = options.tables ?? defaultTables;\n\n // pgvector lives in the WASM instance, so the extension must be passed at\n // construction — `CREATE EXTENSION vector` alone can't pull it in. An\n // explicitly supplied extension wins; `false` disables; otherwise load the\n // default package.\n const vectorExtension =\n options.vector === false ?\n undefined\n : (options.vector ?? (await loadDefaultPgvectorExtension()));\n const vectorEnabled = vectorExtension !== undefined;\n\n // Construct via the single options-object form (passing `dataDir` as a\n // field), not the positional `create(dataDir, options)` overload: with a\n // leading `undefined` dataDir, that overload silently drops `extensions`\n // (\"extension vector is not available\"). The options form loads them for\n // both the in-memory and on-disk cases.\n const client = await PGlite.create({\n ...(options.dataDir === undefined ? {} : { dataDir: options.dataDir }),\n ...(vectorExtension === undefined ?\n {}\n : { extensions: { vector: vectorExtension } }),\n });\n\n try {\n // `exec` runs a multi-statement batch (DDL + the pgvector `CREATE\n // EXTENSION` when enabled) in one round trip.\n const migrationSql =\n vectorEnabled ?\n generatePostgresMigrationSQL(tables, options.fulltext)\n : generateVectorlessPostgresMigrationSQL(tables, options.fulltext);\n await client.exec(migrationSql);\n\n const db = drizzle(client);\n const backend = createPostgresBackend(db, {\n ...(options.schemaProvisioning === undefined ?\n {}\n : { schemaProvisioning: options.schemaProvisioning }),\n tables,\n ...(vectorEnabled ? {} : { vector: false }),\n ...(options.fulltext === undefined ? {} : { fulltext: options.fulltext }),\n });\n const managedBackend = wrapWithManagedClose(backend, async () => {\n await client.close();\n });\n\n return {\n backend: markBundledRootAutocommitEligible(managedBackend),\n db,\n client,\n };\n } catch (error) {\n return closeAfterFailure(client, error);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/backend/postgres/pglite.ts"],"names":["ConfigurationError","tables","PGlite","generatePostgresMigrationSQL","generateVectorlessPostgresMigrationSQL","drizzle","createPostgresBackend","wrapWithManagedClose","markBundledRootAutocommitEligible","closeAfterFailure"],"mappings":";;;;;;;;;AAsJA,eAAe,4BAAA,GAAmD;AAChE,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,MAAM,OAAO,+BAA+B,CAAA;AAC5D,IAAA,OAAO,OAAA,CAAQ,MAAA;AAAA,EACjB,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIA,oCAAA;AAAA,MACR,2PAAA;AAAA,MAIA,EAAE,OAAA,EAAS,QAAA,EAAU,UAAA,EAAY,+BAAA,EAAgC;AAAA,MACjE,EAAE,OAAO,KAAA;AAAM,KACjB;AAAA,EACF;AACF;AAoBA,eAAsB,wBAAA,CACpB,OAAA,GAAqC,EAAC,EACH;AACnC,EAAA,MAAMC,OAAAA,GAAS,QAAQ,MAAA,IAAUA,wBAAA;AAMjC,EAAA,MAAM,eAAA,GACJ,QAAQ,MAAA,KAAW,KAAA,GACjB,SACC,OAAA,CAAQ,MAAA,IAAW,MAAM,4BAAA,EAA6B;AAC3D,EAAA,MAAM,gBAAgB,eAAA,KAAoB,MAAA;AAO1C,EAAA,MAAM,MAAA,GAAS,MAAMC,aAAA,CAAO,MAAA,CAAO;AAAA,IACjC,GAAI,QAAQ,OAAA,KAAY,MAAA,GAAY,EAAC,GAAI,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAQ;AAAA,IACpE,GAAI,eAAA,KAAoB,MAAA,GACtB,EAAC,GACD,EAAE,UAAA,EAAY,EAAE,MAAA,EAAQ,eAAA,EAAgB;AAAE,GAC7C,CAAA;AAED,EAAA,IAAI;AAGF,IAAA,MAAM,YAAA,GACJ,aAAA,GACEC,8CAAA,CAA6BF,OAAAA,EAAQ,OAAA,CAAQ,QAAQ,CAAA,GACrDG,wDAAA,CAAuCH,OAAAA,EAAQ,OAAA,CAAQ,QAAQ,CAAA;AACnE,IAAA,MAAM,MAAA,CAAO,KAAK,YAAY,CAAA;AAE9B,IAAA,MAAM,EAAA,GAAKI,iBAAQ,MAAM,CAAA;AACzB,IAAA,MAAM,OAAA,GAAUC,wCAAsB,EAAA,EAAI;AAAA,MACxC,GAAI,QAAQ,kBAAA,KAAuB,KAAA,CAAA,GACjC,EAAC,GACD,EAAE,kBAAA,EAAoB,OAAA,CAAQ,kBAAA,EAAmB;AAAA,MACnD,MAAA,EAAAL,OAAAA;AAAA,MACA,GAAI,aAAA,GAAgB,EAAC,GAAI,EAAE,QAAQ,KAAA,EAAM;AAAA,MACzC,GAAI,QAAQ,QAAA,KAAa,KAAA,CAAA,GAAY,EAAC,GAAI,EAAE,QAAA,EAAU,OAAA,CAAQ,QAAA;AAAS,KACxE,CAAA;AACD,IAAA,MAAM,cAAA,GAAiBM,sCAAA,CAAqB,OAAA,EAAS,YAAY;AAC/D,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAO;AAAA,MACL,OAAA,EAASC,oDAAkC,cAAc,CAAA;AAAA,MACzD,EAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,mCAAA,CAAkB,QAAQ,KAAK,CAAA;AAAA,EACxC;AACF","file":"chunk-E6XL3KMZ.cjs","sourcesContent":["/**\n * Local PGlite backend — Postgres-in-WASM, running in-process.\n *\n * [PGlite](https://pglite.dev/) is a full Postgres compiled to WebAssembly\n * that runs inside the Node/Bun/Deno/browser process with no server and no\n * native addon. This is the batteries-included Postgres analog of\n * `createLocalSqliteBackend`: it constructs a PGlite instance, loads the\n * pgvector extension, runs the schema DDL, and returns a ready\n * `{ backend, db }` pair whose `close()` disposes the engine.\n *\n * `@electric-sql/pglite` is an optional peer dependency. Vector support\n * additionally needs `@electric-sql/pglite-pgvector` (PGlite ≥ 0.5 ships\n * pgvector as a separate package). Install what you need:\n *\n * ```bash\n * pnpm add @electric-sql/pglite @electric-sql/pglite-pgvector\n * ```\n *\n * @example In-memory database (default, vector enabled)\n * ```typescript\n * import { createLocalPgliteBackend } from \"@nicia-ai/typegraph/adapters/drizzle/postgres/pglite\";\n *\n * const { backend } = await createLocalPgliteBackend();\n * const store = createStore(graph, backend);\n * ```\n *\n * @example Persistent on-disk database\n * ```typescript\n * const { backend, db } = await createLocalPgliteBackend({ dataDir: \"./pgdata\" });\n * ```\n *\n * @example No vector support (skip the pgvector extension)\n * ```typescript\n * const { backend } = await createLocalPgliteBackend({ vector: false });\n * ```\n *\n * PGlite is single-connection and serial: there is no pooling, so concurrent\n * `store.transaction()` calls queue rather than run in parallel.\n */\nimport { type Extension, PGlite } from \"@electric-sql/pglite\";\nimport { drizzle, type PgliteDatabase } from \"drizzle-orm/pglite\";\n\nimport { ConfigurationError } from \"../../errors\";\nimport { type FulltextStrategy } from \"../../query/dialect/fulltext-strategy\";\nimport { markBundledRootAutocommitEligible } from \"../capabilities/autocommit-single-statement\";\nimport { wrapWithManagedClose } from \"../derive-backend\";\nexport type { GraphIdentityConfig } from \"../../core/define-graph\";\nimport {\n generatePostgresMigrationSQL,\n generateVectorlessPostgresMigrationSQL,\n} from \"../drizzle/ddl\";\nimport { type AnyPgTransaction } from \"../drizzle/execution\";\nexport type { AnyPgDatabase, AnyPgTransaction } from \"../drizzle/execution\";\nimport {\n createPostgresBackend,\n type PostgresTables,\n tables as defaultTables,\n} from \"../drizzle/postgres\";\nimport {\n type AdapterBackend,\n closeAfterFailure,\n type SchemaProvisioning,\n} from \"../types\";\nexport type {\n ContributionDiagnostic,\n ContributionDiagnosticState,\n ContributionRepairEntry,\n ContributionRepairResult,\n} from \"../types\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a local PGlite backend.\n */\nexport type LocalPgliteBackendOptions = Readonly<{\n /**\n * PGlite data directory. Omit for an in-memory database (the default).\n * Accepts any PGlite data-dir spec: a filesystem path (`\"./pgdata\"`),\n * `\"memory://\"`, or a browser/runtime-specific scheme such as\n * `\"idb://my-db\"`.\n */\n dataDir?: string;\n\n /**\n * Custom table definitions. Defaults to standard TypeGraph table names.\n */\n tables?: PostgresTables;\n\n /**\n * Controls the pgvector stack:\n *\n * - **omitted (default)** — load pgvector from `@electric-sql/pglite-pgvector`\n * and run `CREATE EXTENSION vector`, so embedding fields work out of the\n * box. Throws a {@link ConfigurationError} if the package isn't installed.\n * - **`false`** — skip the extension entirely; the backend advertises no\n * vector capability (mirroring a SQLite connection without sqlite-vec).\n * Use when a graph carries no embeddings, or to avoid the extension dep.\n * - **a PGlite `Extension`** — bring your own pgvector build or custom\n * extension packaging. Decouples this helper from a specific pgvector\n * package version.\n */\n vector?: false | Extension;\n\n /**\n * Override the fulltext strategy. Defaults to `tsvectorStrategy`. Pass\n * `false` to disable fulltext support entirely — the backend then\n * advertises no `capabilities.fulltext` and omits the fulltext CRUD/search\n * methods, and the installation DDL never creates the fulltext table,\n * mirroring `vector: false`.\n */\n fulltext?: FulltextStrategy | false;\n /** Opt in to provisioning within caller-owned schema transactions. */\n schemaProvisioning?: SchemaProvisioning;\n}>;\n\n/**\n * Result of creating a local PGlite backend.\n */\nexport type LocalPgliteBackendResult = Readonly<{\n /**\n * The GraphBackend instance for use with createStore. Its `close()`\n * disposes the underlying PGlite engine.\n */\n backend: AdapterBackend<AnyPgTransaction>;\n\n /**\n * The underlying Drizzle database instance. Useful for direct SQL access.\n */\n db: PgliteDatabase;\n\n /**\n * The raw PGlite instance, for engine-specific operations such as\n * `dumpDataDir()` / `clone()` not surfaced through Drizzle.\n */\n client: PGlite;\n}>;\n\n// ============================================================\n// Vector extension loading\n// ============================================================\n\n/**\n * Dynamically loads the default pgvector extension from\n * `@electric-sql/pglite-pgvector`. Kept as a runtime import so the package\n * stays an optional peer dependency — callers using `vector: false` or\n * supplying their own extension never need it installed.\n */\nasync function loadDefaultPgvectorExtension(): Promise<Extension> {\n try {\n const module_ = await import(\"@electric-sql/pglite-pgvector\");\n return module_.vector;\n } catch (error) {\n throw new ConfigurationError(\n \"createLocalPgliteBackend needs the pgvector extension but \" +\n \"`@electric-sql/pglite-pgvector` could not be loaded. Install it \" +\n \"(`pnpm add @electric-sql/pglite-pgvector`), pass your own `vector` \" +\n \"extension, or set `vector: false` to disable vector support.\",\n { backend: \"pglite\", dependency: \"@electric-sql/pglite-pgvector\" },\n { cause: error },\n );\n }\n}\n\n// ============================================================\n// Factory Function\n// ============================================================\n\n/**\n * Creates a TypeGraph backend backed by an in-process PGlite database.\n *\n * Constructs the PGlite engine (loading pgvector unless disabled), executes\n * the schema DDL, and wires the standard Postgres backend. The returned\n * backend owns the engine: call `backend.close()` to dispose it.\n *\n * For production Postgres, or a PGlite instance you construct yourself,\n * use `createPostgresBackend` directly with your own Drizzle database — the\n * execution fast path detects PGlite and routes it correctly.\n *\n * @param options - Configuration options\n * @returns Backend, Drizzle database, and raw PGlite client\n */\nexport async function createLocalPgliteBackend(\n options: LocalPgliteBackendOptions = {},\n): Promise<LocalPgliteBackendResult> {\n const tables = options.tables ?? defaultTables;\n\n // pgvector lives in the WASM instance, so the extension must be passed at\n // construction — `CREATE EXTENSION vector` alone can't pull it in. An\n // explicitly supplied extension wins; `false` disables; otherwise load the\n // default package.\n const vectorExtension =\n options.vector === false ?\n undefined\n : (options.vector ?? (await loadDefaultPgvectorExtension()));\n const vectorEnabled = vectorExtension !== undefined;\n\n // Construct via the single options-object form (passing `dataDir` as a\n // field), not the positional `create(dataDir, options)` overload: with a\n // leading `undefined` dataDir, that overload silently drops `extensions`\n // (\"extension vector is not available\"). The options form loads them for\n // both the in-memory and on-disk cases.\n const client = await PGlite.create({\n ...(options.dataDir === undefined ? {} : { dataDir: options.dataDir }),\n ...(vectorExtension === undefined ?\n {}\n : { extensions: { vector: vectorExtension } }),\n });\n\n try {\n // `exec` runs a multi-statement batch (DDL + the pgvector `CREATE\n // EXTENSION` when enabled) in one round trip.\n const migrationSql =\n vectorEnabled ?\n generatePostgresMigrationSQL(tables, options.fulltext)\n : generateVectorlessPostgresMigrationSQL(tables, options.fulltext);\n await client.exec(migrationSql);\n\n const db = drizzle(client);\n const backend = createPostgresBackend(db, {\n ...(options.schemaProvisioning === undefined ?\n {}\n : { schemaProvisioning: options.schemaProvisioning }),\n tables,\n ...(vectorEnabled ? {} : { vector: false }),\n ...(options.fulltext === undefined ? {} : { fulltext: options.fulltext }),\n });\n const managedBackend = wrapWithManagedClose(backend, async () => {\n await client.close();\n });\n\n return {\n backend: markBundledRootAutocommitEligible(managedBackend),\n db,\n client,\n };\n } catch (error) {\n return closeAfterFailure(client, error);\n }\n}\n"]}
@@ -3729,6 +3729,15 @@ function buildClearGraph(tables3, graphId, fulltextStrategy) {
3729
3729
  {
3730
3730
  query: sql`DELETE FROM ${tables3.reconciliationMarkers} WHERE ${tables3.reconciliationMarkers.graphId} = ${graphId}`
3731
3731
  },
3732
+ // Tolerates absence for the same reason the recorded relations do: the
3733
+ // marker table is provisioned lazily by the materializer's ensure, so a
3734
+ // database that never materialized a contribution has no such table, and
3735
+ // clearing a graph must not become the operation that fails on it.
3736
+ {
3737
+ query: sql`DELETE FROM ${tables3.contributionMaterializations} WHERE ${tables3.contributionMaterializations.graphId} = ${graphId}`,
3738
+ ignoreMissingTable: true,
3739
+ requiredTableName: getTableName(tables3.contributionMaterializations)
3740
+ },
3732
3741
  {
3733
3742
  query: sql`DELETE FROM ${tables3.schemaVersions} WHERE ${tables3.schemaVersions.graphId} = ${graphId}`
3734
3743
  }
@@ -17460,5 +17469,5 @@ function createTransactionBackend2(options) {
17460
17469
  }
17461
17470
 
17462
17471
  export { CURRENT_BASE_SCHEMA_VERSION, DERIVABLE_ENGINE_PROFILE_KEYS, ORDERED_AGGREGATE_PROBE_SQL, assertNoLegacyTransactionCapability, buildPostgresEngineProfile, buildSqliteEngineProfile, createPostgresBackend, createPostgresTables, createSqlBackend, createSqliteBackend, createSqliteTables, deriveEngineProfile, edgeClaims, edgeClaims2, edges, edges2, fulltext, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorlessPostgresMigrationSQL, isLocalLibsqlClient, nodes, nodes2, planSqliteEdgeMatchIdentityAdoption, quoteDdlIdentifier, recordedClock, recordedClock2, recordedEdges, recordedEdges2, recordedNodes, recordedNodes2, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
17463
- //# sourceMappingURL=chunk-2DJKHZQ4.js.map
17464
- //# sourceMappingURL=chunk-2DJKHZQ4.js.map
17472
+ //# sourceMappingURL=chunk-EORFWD6O.js.map
17473
+ //# sourceMappingURL=chunk-EORFWD6O.js.map