@nicia-ai/typegraph 0.38.0 → 0.39.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 (95) hide show
  1. package/dist/backend/postgres/index.cjs +16 -16
  2. package/dist/backend/postgres/index.js +3 -3
  3. package/dist/backend/postgres/pglite-store.cjs +11 -11
  4. package/dist/backend/postgres/pglite-store.d.cts +1 -1
  5. package/dist/backend/postgres/pglite-store.d.ts +1 -1
  6. package/dist/backend/postgres/pglite-store.js +8 -8
  7. package/dist/backend/postgres/pglite.cjs +5 -5
  8. package/dist/backend/postgres/pglite.js +4 -4
  9. package/dist/backend/sqlite/index.cjs +6 -6
  10. package/dist/backend/sqlite/index.js +3 -3
  11. package/dist/backend/sqlite/libsql.cjs +5 -5
  12. package/dist/backend/sqlite/libsql.js +3 -3
  13. package/dist/backend/sqlite/local-store.cjs +11 -11
  14. package/dist/backend/sqlite/local-store.d.cts +1 -1
  15. package/dist/backend/sqlite/local-store.d.ts +1 -1
  16. package/dist/backend/sqlite/local-store.js +9 -9
  17. package/dist/backend/sqlite/local.cjs +6 -6
  18. package/dist/backend/sqlite/local.js +4 -4
  19. package/dist/{chunk-UPXDVI3T.js → chunk-3SK4SVTW.js} +3 -3
  20. package/dist/{chunk-UPXDVI3T.js.map → chunk-3SK4SVTW.js.map} +1 -1
  21. package/dist/{chunk-NU23DUSJ.cjs → chunk-3YFDFOYB.cjs} +7 -7
  22. package/dist/{chunk-NU23DUSJ.cjs.map → chunk-3YFDFOYB.cjs.map} +1 -1
  23. package/dist/{chunk-NWYCOFEZ.cjs → chunk-5ELKD2FQ.cjs} +4 -4
  24. package/dist/chunk-5ELKD2FQ.cjs.map +1 -0
  25. package/dist/{chunk-2SL7OGPR.cjs → chunk-6SRLCSAV.cjs} +478 -338
  26. package/dist/chunk-6SRLCSAV.cjs.map +1 -0
  27. package/dist/{chunk-A2FGSWMQ.js → chunk-CBK2IVI2.js} +167 -27
  28. package/dist/chunk-CBK2IVI2.js.map +1 -0
  29. package/dist/{chunk-TE5ZA4VX.js → chunk-DOKUXLFH.js} +14 -10
  30. package/dist/chunk-DOKUXLFH.js.map +1 -0
  31. package/dist/{chunk-KCLZHYPU.cjs → chunk-E2Q7SP2K.cjs} +52 -52
  32. package/dist/{chunk-KCLZHYPU.cjs.map → chunk-E2Q7SP2K.cjs.map} +1 -1
  33. package/dist/{chunk-YLINFV7Z.cjs → chunk-GKQU44SQ.cjs} +67 -63
  34. package/dist/chunk-GKQU44SQ.cjs.map +1 -0
  35. package/dist/{chunk-O5H62ZWJ.cjs → chunk-HP6LWBLB.cjs} +14 -2
  36. package/dist/chunk-HP6LWBLB.cjs.map +1 -0
  37. package/dist/{chunk-7VLCN3JB.cjs → chunk-HTQOBY75.cjs} +59 -59
  38. package/dist/{chunk-7VLCN3JB.cjs.map → chunk-HTQOBY75.cjs.map} +1 -1
  39. package/dist/{chunk-RQPRCEIO.js → chunk-IFDXG2YJ.js} +3 -3
  40. package/dist/chunk-IFDXG2YJ.js.map +1 -0
  41. package/dist/{chunk-YJDSPA5E.js → chunk-IFRPHG7O.js} +4 -4
  42. package/dist/{chunk-YJDSPA5E.js.map → chunk-IFRPHG7O.js.map} +1 -1
  43. package/dist/{chunk-LZ3TVJY4.cjs → chunk-JD2YC62H.cjs} +17 -17
  44. package/dist/{chunk-LZ3TVJY4.cjs.map → chunk-JD2YC62H.cjs.map} +1 -1
  45. package/dist/{chunk-XD6X7O5R.js → chunk-KAFXPB2L.js} +4 -4
  46. package/dist/{chunk-XD6X7O5R.js.map → chunk-KAFXPB2L.js.map} +1 -1
  47. package/dist/{chunk-ZHX4KEM7.cjs → chunk-KIZSHRUI.cjs} +7 -7
  48. package/dist/{chunk-ZHX4KEM7.cjs.map → chunk-KIZSHRUI.cjs.map} +1 -1
  49. package/dist/{chunk-G32AO634.js → chunk-KXFUQNF2.js} +3 -3
  50. package/dist/{chunk-G32AO634.js.map → chunk-KXFUQNF2.js.map} +1 -1
  51. package/dist/{chunk-E6YZRKMM.js → chunk-NQBYTLPW.js} +4 -4
  52. package/dist/{chunk-E6YZRKMM.js.map → chunk-NQBYTLPW.js.map} +1 -1
  53. package/dist/{chunk-VBH7ZXSZ.js → chunk-SU7VQOJ3.js} +3 -3
  54. package/dist/{chunk-VBH7ZXSZ.js.map → chunk-SU7VQOJ3.js.map} +1 -1
  55. package/dist/{chunk-KFLXWVUJ.js → chunk-UUIBACKJ.js} +14 -3
  56. package/dist/chunk-UUIBACKJ.js.map +1 -0
  57. package/dist/{chunk-CQC6VBAF.cjs → chunk-VXAFOF6Z.cjs} +5 -5
  58. package/dist/{chunk-CQC6VBAF.cjs.map → chunk-VXAFOF6Z.cjs.map} +1 -1
  59. package/dist/{chunk-XFY73JWD.cjs → chunk-Y6UA55YS.cjs} +5 -5
  60. package/dist/{chunk-XFY73JWD.cjs.map → chunk-Y6UA55YS.cjs.map} +1 -1
  61. package/dist/{chunk-6G5CQ6JX.js → chunk-YPUNPG2T.js} +4 -4
  62. package/dist/{chunk-6G5CQ6JX.js.map → chunk-YPUNPG2T.js.map} +1 -1
  63. package/dist/graph-merge/index.cjs +30 -32
  64. package/dist/graph-merge/index.cjs.map +1 -1
  65. package/dist/graph-merge/index.d.cts +10 -5
  66. package/dist/graph-merge/index.d.ts +10 -5
  67. package/dist/graph-merge/index.js +9 -11
  68. package/dist/graph-merge/index.js.map +1 -1
  69. package/dist/index.cjs +68 -68
  70. package/dist/index.d.cts +2 -2
  71. package/dist/index.d.ts +2 -2
  72. package/dist/index.js +5 -5
  73. package/dist/interchange/index.cjs +23 -23
  74. package/dist/interchange/index.d.cts +1 -1
  75. package/dist/interchange/index.d.ts +1 -1
  76. package/dist/interchange/index.js +4 -4
  77. package/dist/profiler/index.d.cts +1 -1
  78. package/dist/profiler/index.d.ts +1 -1
  79. package/dist/provenance/index.cjs +11 -11
  80. package/dist/provenance/index.d.cts +1 -1
  81. package/dist/provenance/index.d.ts +1 -1
  82. package/dist/provenance/index.js +2 -2
  83. package/dist/schema/index.cjs +22 -22
  84. package/dist/schema/index.js +3 -3
  85. package/dist/{store-view-BoHqdHjB.d.cts → store-view-BJd6Vwpt.d.cts} +39 -17
  86. package/dist/{store-view-Ctq-3OHy.d.ts → store-view-CLIhwMMX.d.ts} +39 -17
  87. package/package.json +1 -1
  88. package/dist/chunk-2SL7OGPR.cjs.map +0 -1
  89. package/dist/chunk-A2FGSWMQ.js.map +0 -1
  90. package/dist/chunk-KFLXWVUJ.js.map +0 -1
  91. package/dist/chunk-NWYCOFEZ.cjs.map +0 -1
  92. package/dist/chunk-O5H62ZWJ.cjs.map +0 -1
  93. package/dist/chunk-RQPRCEIO.js.map +0 -1
  94. package/dist/chunk-TE5ZA4VX.js.map +0 -1
  95. package/dist/chunk-YLINFV7Z.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { createPostgresBackend } from './chunk-YJDSPA5E.js';
2
- import { tables, generatePostgresMigrationSQL, generatePostgresDDL } from './chunk-G32AO634.js';
1
+ import { createPostgresBackend } from './chunk-IFRPHG7O.js';
2
+ import { tables, generatePostgresMigrationSQL, generatePostgresDDL } from './chunk-KXFUQNF2.js';
3
3
  import { wrapWithManagedClose, closeAfterFailure } from './chunk-PZHC5GCD.js';
4
4
  import { ConfigurationError } from './chunk-DPNA466P.js';
5
5
  import { PGlite } from '@electric-sql/pglite';
@@ -43,5 +43,5 @@ async function createLocalPgliteBackend(options = {}) {
43
43
  }
44
44
 
45
45
  export { createLocalPgliteBackend };
46
- //# sourceMappingURL=chunk-6G5CQ6JX.js.map
47
- //# sourceMappingURL=chunk-6G5CQ6JX.js.map
46
+ //# sourceMappingURL=chunk-YPUNPG2T.js.map
47
+ //# sourceMappingURL=chunk-YPUNPG2T.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/backend/postgres/pglite.ts"],"names":["tables"],"mappings":";;;;;;;AAiIA,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,IAAI,kBAAA;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,MAAMA,OAAAA,GAAS,QAAQ,MAAA,IAAU,MAAA;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,MAAM,MAAA,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,gBACE,4BAAA,CAA6BA,OAAM,IACnC,mBAAA,CAAoBA,OAAM,CAAA,CAAE,IAAA,CAAK,MAAM,CAAA;AAC3C,IAAA,MAAM,MAAA,CAAO,KAAK,YAAY,CAAA;AAE9B,IAAA,MAAM,EAAA,GAAK,QAAQ,MAAM,CAAA;AACzB,IAAA,MAAM,OAAA,GAAU,sBAAsB,EAAA,EAAI;AAAA,MACxC,MAAA,EAAAA,OAAAA;AAAA,MACA,GAAI,aAAA,GAAgB,EAAC,GAAI,EAAE,QAAQ,KAAA;AAAM,KAC1C,CAAA;AACD,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,OAAA,EAAS,YAAY;AAC/D,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAO,EAAE,OAAA,EAAS,cAAA,EAAgB,EAAA,EAAI,MAAA,EAAO;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,iBAAA,CAAkB,QAAQ,KAAK,CAAA;AAAA,EACxC;AACF","file":"chunk-6G5CQ6JX.js","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 {\n generatePostgresDDL,\n generatePostgresMigrationSQL,\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 wrapWithManagedClose,\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/**\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)\n : generatePostgresDDL(tables).join(\"\\n\\n\");\n await client.exec(migrationSql);\n\n const db = drizzle(client);\n const backend = createPostgresBackend(db, {\n tables,\n ...(vectorEnabled ? {} : { vector: false }),\n });\n const managedBackend = wrapWithManagedClose(backend, async () => {\n await client.close();\n });\n\n return { backend: managedBackend, db, client };\n } catch (error) {\n return closeAfterFailure(client, error);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/backend/postgres/pglite.ts"],"names":["tables"],"mappings":";;;;;;;AAiIA,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,IAAI,kBAAA;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,MAAMA,OAAAA,GAAS,QAAQ,MAAA,IAAU,MAAA;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,MAAM,MAAA,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,gBACE,4BAAA,CAA6BA,OAAM,IACnC,mBAAA,CAAoBA,OAAM,CAAA,CAAE,IAAA,CAAK,MAAM,CAAA;AAC3C,IAAA,MAAM,MAAA,CAAO,KAAK,YAAY,CAAA;AAE9B,IAAA,MAAM,EAAA,GAAK,QAAQ,MAAM,CAAA;AACzB,IAAA,MAAM,OAAA,GAAU,sBAAsB,EAAA,EAAI;AAAA,MACxC,MAAA,EAAAA,OAAAA;AAAA,MACA,GAAI,aAAA,GAAgB,EAAC,GAAI,EAAE,QAAQ,KAAA;AAAM,KAC1C,CAAA;AACD,IAAA,MAAM,cAAA,GAAiB,oBAAA,CAAqB,OAAA,EAAS,YAAY;AAC/D,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB,CAAC,CAAA;AAED,IAAA,OAAO,EAAE,OAAA,EAAS,cAAA,EAAgB,EAAA,EAAI,MAAA,EAAO;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,iBAAA,CAAkB,QAAQ,KAAK,CAAA;AAAA,EACxC;AACF","file":"chunk-YPUNPG2T.js","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 {\n generatePostgresDDL,\n generatePostgresMigrationSQL,\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 wrapWithManagedClose,\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/**\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)\n : generatePostgresDDL(tables).join(\"\\n\\n\");\n await client.exec(migrationSql);\n\n const db = drizzle(client);\n const backend = createPostgresBackend(db, {\n tables,\n ...(vectorEnabled ? {} : { vector: false }),\n });\n const managedBackend = wrapWithManagedClose(backend, async () => {\n await client.close();\n });\n\n return { backend: managedBackend, db, client };\n } catch (error) {\n return closeAfterFailure(client, error);\n }\n}\n"]}
@@ -1,19 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var chunk2SL7OGPR_cjs = require('../chunk-2SL7OGPR.cjs');
3
+ var chunk6SRLCSAV_cjs = require('../chunk-6SRLCSAV.cjs');
4
4
  var chunkTRF4EBJT_cjs = require('../chunk-TRF4EBJT.cjs');
5
5
  require('../chunk-E6TXEISH.cjs');
6
- var chunkLZ3TVJY4_cjs = require('../chunk-LZ3TVJY4.cjs');
7
- require('../chunk-KCLZHYPU.cjs');
8
- var chunkNWYCOFEZ_cjs = require('../chunk-NWYCOFEZ.cjs');
6
+ var chunkJD2YC62H_cjs = require('../chunk-JD2YC62H.cjs');
7
+ require('../chunk-E2Q7SP2K.cjs');
8
+ var chunk5ELKD2FQ_cjs = require('../chunk-5ELKD2FQ.cjs');
9
9
  require('../chunk-ZDH3DX3C.cjs');
10
10
  require('../chunk-GNPGGLAE.cjs');
11
11
  require('../chunk-SVUKGWSN.cjs');
12
- var chunkCQC6VBAF_cjs = require('../chunk-CQC6VBAF.cjs');
12
+ var chunkVXAFOF6Z_cjs = require('../chunk-VXAFOF6Z.cjs');
13
13
  var chunkRW24SAHI_cjs = require('../chunk-RW24SAHI.cjs');
14
14
  require('../chunk-X4PVHAZ6.cjs');
15
15
  var chunkACSVZPK7_cjs = require('../chunk-ACSVZPK7.cjs');
16
- require('../chunk-O5H62ZWJ.cjs');
16
+ require('../chunk-HP6LWBLB.cjs');
17
17
  var chunkNT6ILURI_cjs = require('../chunk-NT6ILURI.cjs');
18
18
  require('../chunk-DDCYVIVV.cjs');
19
19
  require('../chunk-CWX77JB4.cjs');
@@ -267,12 +267,12 @@ async function diffAgainstBase(baseStore, forkStore, captureForkState = true) {
267
267
  const forkNodeVersions = /* @__PURE__ */ new Map();
268
268
  for (const kind of nodeKinds) {
269
269
  const baseRows = await enumerateAllNodes(
270
- chunkNWYCOFEZ_cjs.storeBackend(baseStore),
270
+ chunk5ELKD2FQ_cjs.storeBackend(baseStore),
271
271
  baseStore.graphId,
272
272
  kind
273
273
  );
274
274
  const forkRows = await enumerateAllNodes(
275
- chunkNWYCOFEZ_cjs.storeBackend(forkStore),
275
+ chunk5ELKD2FQ_cjs.storeBackend(forkStore),
276
276
  forkStore.graphId,
277
277
  kind
278
278
  );
@@ -298,12 +298,12 @@ async function diffAgainstBase(baseStore, forkStore, captureForkState = true) {
298
298
  const forkEdgeSignatures = /* @__PURE__ */ new Map();
299
299
  for (const kind of edgeKinds) {
300
300
  const baseRows = await enumerateAllEdges(
301
- chunkNWYCOFEZ_cjs.storeBackend(baseStore),
301
+ chunk5ELKD2FQ_cjs.storeBackend(baseStore),
302
302
  baseStore.graphId,
303
303
  kind
304
304
  );
305
305
  const forkRows = await enumerateAllEdges(
306
- chunkNWYCOFEZ_cjs.storeBackend(forkStore),
306
+ chunk5ELKD2FQ_cjs.storeBackend(forkStore),
307
307
  forkStore.graphId,
308
308
  kind
309
309
  );
@@ -369,10 +369,10 @@ async function readActiveSchemaVersion(backend, graphId) {
369
369
  }
370
370
  async function computeSchemaComponent(store) {
371
371
  const version = await readActiveSchemaVersion(
372
- chunkNWYCOFEZ_cjs.storeBackend(store),
372
+ chunk5ELKD2FQ_cjs.storeBackend(store),
373
373
  store.graphId
374
374
  );
375
- return chunkCQC6VBAF_cjs.computeSchemaHash(chunkCQC6VBAF_cjs.serializeSchema(store.graph, version));
375
+ return chunkVXAFOF6Z_cjs.computeSchemaHash(chunkVXAFOF6Z_cjs.serializeSchema(store.graph, version));
376
376
  }
377
377
  function byDigestEntry(left, right) {
378
378
  const byKind = chunkTRF4EBJT_cjs.compareStrings(left.kind, right.kind);
@@ -437,7 +437,7 @@ async function computeBaseVersion(store) {
437
437
  }
438
438
  const [schemaComponent, contentComponent] = await Promise.all([
439
439
  computeSchemaComponent(store),
440
- computeContentComponent(chunkNWYCOFEZ_cjs.storeBackend(store), store.graphId, store.graph)
440
+ computeContentComponent(chunk5ELKD2FQ_cjs.storeBackend(store), store.graphId, store.graph)
441
441
  ]);
442
442
  return asBaseVersion(
443
443
  `${schemaComponent}${TOKEN_SEPARATOR}${contentComponent}`
@@ -543,7 +543,7 @@ function cloneWorkingCopyStrategy(makeBackend) {
543
543
  create: async (baseStore) => {
544
544
  const backend = await makeBackend();
545
545
  try {
546
- const [freshStore] = await chunk2SL7OGPR_cjs.createStoreWithSchema(
546
+ const [freshStore] = await chunk6SRLCSAV_cjs.createStoreWithSchema(
547
547
  baseStore.graph,
548
548
  backend,
549
549
  {
@@ -552,9 +552,9 @@ function cloneWorkingCopyStrategy(makeBackend) {
552
552
  revisionTracking: baseStore.revisionTrackingEnabled
553
553
  }
554
554
  );
555
- const result = await chunkLZ3TVJY4_cjs.importGraphStream(
555
+ const result = await chunkJD2YC62H_cjs.importGraphStream(
556
556
  freshStore,
557
- chunkLZ3TVJY4_cjs.exportGraphStream(baseStore, {
557
+ chunkJD2YC62H_cjs.exportGraphStream(baseStore, {
558
558
  includeMeta: true,
559
559
  includeTemporal: true,
560
560
  includeDeleted: false,
@@ -589,7 +589,7 @@ function cloneWorkingCopyStrategy(makeBackend) {
589
589
  async function branch(baseStore, makeBackend, options, strategy) {
590
590
  try {
591
591
  const base = await computeBaseVersion(baseStore);
592
- const id = options?.id ?? asBranchId(chunkNWYCOFEZ_cjs.generateId());
592
+ const id = options?.id ?? asBranchId(chunk5ELKD2FQ_cjs.generateId());
593
593
  const workingCopyStrategy = strategy ?? cloneWorkingCopyStrategy(makeBackend);
594
594
  const store = await workingCopyStrategy.create(baseStore);
595
595
  return chunkN2V3HJFV_cjs.ok({ id, base, store });
@@ -618,7 +618,7 @@ function constraintSignature(node, constraint) {
618
618
  return void 0;
619
619
  }
620
620
  }
621
- return `${constraint.name}${KEY_PART_SEPARATOR}${chunkNWYCOFEZ_cjs.computeUniqueKey(
621
+ return `${constraint.name}${KEY_PART_SEPARATOR}${chunk5ELKD2FQ_cjs.computeUniqueKey(
622
622
  props,
623
623
  constraint.fields,
624
624
  constraint.collation
@@ -2191,8 +2191,9 @@ function buildProvenanceGraph(targetGraphId) {
2191
2191
  edges: {}
2192
2192
  });
2193
2193
  }
2194
- async function openProvenanceStore(backend, targetGraphId) {
2195
- const [store] = await chunk2SL7OGPR_cjs.createStoreWithSchema(
2194
+ async function openProvenanceStore(...args) {
2195
+ const [backend, targetGraphId] = args.length === 1 ? [chunk5ELKD2FQ_cjs.storeBackend(args[0]), args[0].graphId] : args;
2196
+ const [store] = await chunk6SRLCSAV_cjs.createStoreWithSchema(
2196
2197
  buildProvenanceGraph(targetGraphId),
2197
2198
  backend
2198
2199
  );
@@ -3421,7 +3422,7 @@ async function applyMergePlan(plan, nodesApi, edgesApi) {
3421
3422
  return { nodes: committedNodeIds.size, edges: committedEdges };
3422
3423
  }
3423
3424
  async function commitPlan(target, plan, expectedBaseVersion) {
3424
- if (!chunkNWYCOFEZ_cjs.storeBackend(target).capabilities.transactions) {
3425
+ if (!chunk5ELKD2FQ_cjs.storeBackend(target).capabilities.transactions) {
3425
3426
  throw new MergeError(
3426
3427
  "merge() requires a transaction-capable target backend. The merged plan (canonical upserts, soft-deletes, edge upserts) must commit atomically; a non-transactional fallback would leave a partially-merged graph on a mid-commit failure. (mergeIncremental() enforces the same requirement.)",
3427
3428
  { details: { capability: "transactions" } }
@@ -3431,7 +3432,7 @@ async function commitPlan(target, plan, expectedBaseVersion) {
3431
3432
  () => target.transaction(async (tx) => {
3432
3433
  if (expectedBaseVersion !== void 0) {
3433
3434
  await assertTargetUnchanged(
3434
- chunkNWYCOFEZ_cjs.transactionBackend(tx),
3435
+ chunk5ELKD2FQ_cjs.transactionBackend(tx),
3435
3436
  target,
3436
3437
  expectedBaseVersion
3437
3438
  );
@@ -3452,9 +3453,9 @@ function mergeCommitTransactionOptions(target) {
3452
3453
  }
3453
3454
  async function assertTargetUnchanged(txBackend, target, expectedBaseVersion) {
3454
3455
  if (hasRevisionAnchor(expectedBaseVersion)) {
3455
- await chunkNWYCOFEZ_cjs.lockRecordedGraphWrite(txBackend, target.graphId);
3456
+ await chunk5ELKD2FQ_cjs.lockRecordedGraphWrite(txBackend, target.graphId);
3456
3457
  const expectedOrigin = revisionOriginOf(expectedBaseVersion);
3457
- const liveOrigin = await chunkNWYCOFEZ_cjs.readRevisionOrigin(
3458
+ const liveOrigin = await chunk5ELKD2FQ_cjs.readRevisionOrigin(
3458
3459
  txBackend,
3459
3460
  target.revisionSchema,
3460
3461
  target.graphId
@@ -3468,7 +3469,7 @@ async function assertTargetUnchanged(txBackend, target, expectedBaseVersion) {
3468
3469
  }
3469
3470
  );
3470
3471
  }
3471
- const liveRevision = await chunkNWYCOFEZ_cjs.readRecordedClock(
3472
+ const liveRevision = await chunk5ELKD2FQ_cjs.readRecordedClock(
3472
3473
  txBackend,
3473
3474
  target.revisionSchema,
3474
3475
  target.graphId
@@ -3595,7 +3596,7 @@ async function resolveMerge(store, target, branches, options, useBaseSources, in
3595
3596
  options.embedder
3596
3597
  );
3597
3598
  const ctx = {
3598
- backend: chunkNWYCOFEZ_cjs.storeBackend(store),
3599
+ backend: chunk5ELKD2FQ_cjs.storeBackend(store),
3599
3600
  ...embeddings === void 0 ? {} : { embeddings }
3600
3601
  };
3601
3602
  const candidates = await generateAllCandidates(
@@ -3637,10 +3638,7 @@ async function resolveMerge(store, target, branches, options, useBaseSources, in
3637
3638
  let provenancePersisted;
3638
3639
  if (options.persistProvenance) {
3639
3640
  try {
3640
- const provenanceStore = await openProvenanceStore(
3641
- chunkNWYCOFEZ_cjs.storeBackend(target),
3642
- target.graphId
3643
- );
3641
+ const provenanceStore = await openProvenanceStore(target);
3644
3642
  const count = await persistProvenanceRecords(
3645
3643
  provenanceStore,
3646
3644
  target.graphId,
@@ -4154,7 +4152,7 @@ async function assertInheritedEdgesUnchanged(edgesApi, guard, plan) {
4154
4152
  });
4155
4153
  }
4156
4154
  async function commitIncrementalPlan(target, plan, guard) {
4157
- if (!chunkNWYCOFEZ_cjs.storeBackend(target).capabilities.transactions) {
4155
+ if (!chunk5ELKD2FQ_cjs.storeBackend(target).capabilities.transactions) {
4158
4156
  throw new MergeError(
4159
4157
  "mergeIncremental() requires a transaction-capable target backend. Incremental writes must preflight existing rows and commit atomically; non-transactional fallback would allow partial graph writes.",
4160
4158
  { details: { capability: "transactions" } }
@@ -4163,7 +4161,7 @@ async function commitIncrementalPlan(target, plan, guard) {
4163
4161
  return withTxConflictRetry(
4164
4162
  () => target.transaction(async (tx) => {
4165
4163
  if (target.revisionTrackingEnabled) {
4166
- await chunkNWYCOFEZ_cjs.lockRecordedGraphWrite(chunkNWYCOFEZ_cjs.transactionBackend(tx), target.graphId);
4164
+ await chunk5ELKD2FQ_cjs.lockRecordedGraphWrite(chunk5ELKD2FQ_cjs.transactionBackend(tx), target.graphId);
4167
4165
  }
4168
4166
  const nodesApi = tx.nodes;
4169
4167
  const edgesApi = tx.edges;