@nicia-ai/typegraph 0.42.0 → 0.43.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 +2 -2
- package/dist/backend/postgres/index.js +1 -1
- package/dist/backend/postgres/pglite-store.cjs +7 -7
- package/dist/backend/postgres/pglite-store.d.cts +1 -1
- package/dist/backend/postgres/pglite-store.d.ts +1 -1
- package/dist/backend/postgres/pglite-store.js +5 -5
- package/dist/backend/postgres/pglite.cjs +3 -3
- package/dist/backend/postgres/pglite.js +2 -2
- package/dist/backend/sqlite/local-store.cjs +4 -4
- package/dist/backend/sqlite/local-store.d.cts +1 -1
- package/dist/backend/sqlite/local-store.d.ts +1 -1
- package/dist/backend/sqlite/local-store.js +3 -3
- package/dist/{chunk-RTUCOEIO.cjs → chunk-5Q3P6OIC.cjs} +4 -4
- package/dist/{chunk-RTUCOEIO.cjs.map → chunk-5Q3P6OIC.cjs.map} +1 -1
- package/dist/{chunk-7TOT7RKY.cjs → chunk-5ZPRE4CV.cjs} +97 -57
- package/dist/chunk-5ZPRE4CV.cjs.map +1 -0
- package/dist/{chunk-5P6IPIT6.cjs → chunk-64LERBFM.cjs} +17 -17
- package/dist/{chunk-5P6IPIT6.cjs.map → chunk-64LERBFM.cjs.map} +1 -1
- package/dist/{chunk-K2HHCWZO.cjs → chunk-BLBG2VZ5.cjs} +51 -51
- package/dist/{chunk-K2HHCWZO.cjs.map → chunk-BLBG2VZ5.cjs.map} +1 -1
- package/dist/{chunk-EVFL2ZY5.js → chunk-CTWZPYJW.js} +2 -2
- package/dist/chunk-CTWZPYJW.js.map +1 -0
- package/dist/{chunk-DP7KC6CL.js → chunk-JNXZQBN3.js} +72 -25
- package/dist/chunk-JNXZQBN3.js.map +1 -0
- package/dist/{chunk-2SO5I5AI.cjs → chunk-KDRF3NR2.cjs} +2 -2
- package/dist/chunk-KDRF3NR2.cjs.map +1 -0
- package/dist/{chunk-WYQILW5V.js → chunk-L2BYRYHC.js} +4 -4
- package/dist/{chunk-WYQILW5V.js.map → chunk-L2BYRYHC.js.map} +1 -1
- package/dist/{chunk-6NB73BXV.js → chunk-L5AUCL5P.js} +3 -3
- package/dist/{chunk-6NB73BXV.js.map → chunk-L5AUCL5P.js.map} +1 -1
- package/dist/{chunk-277UZV7X.cjs → chunk-NDQLPKBX.cjs} +315 -268
- package/dist/chunk-NDQLPKBX.cjs.map +1 -0
- package/dist/{chunk-LTVBD56M.js → chunk-NXIZL7ZZ.js} +3 -3
- package/dist/{chunk-LTVBD56M.js.map → chunk-NXIZL7ZZ.js.map} +1 -1
- package/dist/{chunk-BGXKXGDI.js → chunk-YPVQYM3L.js} +99 -59
- package/dist/chunk-YPVQYM3L.js.map +1 -0
- package/dist/graph-merge/index.cjs +25 -25
- package/dist/graph-merge/index.d.cts +1 -1
- package/dist/graph-merge/index.d.ts +1 -1
- package/dist/graph-merge/index.js +4 -4
- package/dist/index.cjs +49 -49
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/interchange/index.cjs +22 -22
- package/dist/interchange/index.d.cts +1 -1
- package/dist/interchange/index.d.ts +1 -1
- package/dist/interchange/index.js +3 -3
- package/dist/profiler/index.d.cts +1 -1
- package/dist/profiler/index.d.ts +1 -1
- package/dist/provenance/index.cjs +10 -10
- package/dist/provenance/index.d.cts +1 -1
- package/dist/provenance/index.d.ts +1 -1
- package/dist/provenance/index.js +1 -1
- package/dist/{store-view-CNcOG8bQ.d.cts → store-view-D1F6KqsE.d.cts} +18 -1
- package/dist/{store-view-6C2vTWqf.d.ts → store-view-DdwBNjZQ.d.ts} +18 -1
- package/package.json +1 -1
- package/dist/chunk-277UZV7X.cjs.map +0 -1
- package/dist/chunk-2SO5I5AI.cjs.map +0 -1
- package/dist/chunk-7TOT7RKY.cjs.map +0 -1
- package/dist/chunk-BGXKXGDI.js.map +0 -1
- package/dist/chunk-DP7KC6CL.js.map +0 -1
- package/dist/chunk-EVFL2ZY5.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPostgresBackend } from './chunk-
|
|
1
|
+
import { createPostgresBackend } from './chunk-YPVQYM3L.js';
|
|
2
2
|
import { tables, generatePostgresMigrationSQL, generatePostgresDDL } from './chunk-Z3WIL6S3.js';
|
|
3
3
|
import { wrapWithManagedClose, closeAfterFailure } from './chunk-UZLEQFTV.js';
|
|
4
4
|
import { ConfigurationError } from './chunk-OYJSYDIH.js';
|
|
@@ -43,5 +43,5 @@ async function createLocalPgliteBackend(options = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export { createLocalPgliteBackend };
|
|
46
|
-
//# sourceMappingURL=chunk-
|
|
47
|
-
//# sourceMappingURL=chunk-
|
|
46
|
+
//# sourceMappingURL=chunk-NXIZL7ZZ.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-NXIZL7ZZ.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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AA,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-NXIZL7ZZ.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,10 +1,10 @@
|
|
|
1
|
-
import { createPostgresOperationStrategy, createCachedTableExistence, createContributionMaterializer, gateFulltextMethods, lockPostgresTrustedImportTables, assertTrustedImportDatabaseEmpty, suspendPostgresSecondaryIndexes, createPostgresTrustedImportSession, restoreSecondaryIndexes, analyzeImportedTables,
|
|
1
|
+
import { createPostgresOperationStrategy, createCachedTableExistence, createContributionMaterializer, gateFulltextMethods, lockPostgresTrustedImportTables, assertTrustedImportDatabaseEmpty, suspendPostgresSecondaryIndexes, createPostgresTrustedImportSession, restoreSecondaryIndexes, analyzeImportedTables, createCommonOperationBackend, vectorSlotFromParams, buildLiveNodeCandidates, mapVectorWriteError, mapHybridSearchRow, mapContributionMaterializationRow, POSTGRES_CONTRIBUTION_MAT_TIMESTAMPS, buildContributionInsertValues, buildContributionOnConflictSet, assertAdoptedDialect, buildKindRemovalInsertValues, POSTGRES_KIND_REMOVAL_TIMESTAMPS, buildKindRemovalOnConflictSet, mapKindRemovalRow, buildMaterializationInsertValues, POSTGRES_INDEX_MAT_TIMESTAMPS, buildMaterializationOnConflictSet, mapMaterializationRow, vectorSlotFromDropIndexParams, vectorSlotFromCreateIndexParams, EMBEDDING_UPSERT_PARAM_COUNT, gateFulltext, getOrCreateLru } from './chunk-HHBKGPEI.js';
|
|
2
2
|
import { pgvectorStrategy, assertPgvectorEfSearch } from './chunk-ZGOUVMVS.js';
|
|
3
3
|
import { createNodeRowMapper, POSTGRES_ROW_MAPPER_CONFIG, createEdgeRowMapper, createUniqueRowMapper, createSchemaVersionRowMapper, nowIso, coerceNumericScore } from './chunk-CVNGKTHO.js';
|
|
4
4
|
import { tables, generatePgCreateTableSQL, generatePostgresDDL } from './chunk-Z3WIL6S3.js';
|
|
5
5
|
import { toDrizzleSql, compileQueryWithDialect } from './chunk-UJRWOV5B.js';
|
|
6
6
|
import { chunk } from './chunk-35S6P5ZU.js';
|
|
7
|
-
import { normalizeGraphAnalyticsCapabilities, createBackendOverlay,
|
|
7
|
+
import { POSTGRES_MAX_BIND_PARAMETERS, normalizeGraphAnalyticsCapabilities, createBackendOverlay, INTERNAL_TEMPORARY_WRITES, POSTGRES_CAPABILITIES } from './chunk-UZLEQFTV.js';
|
|
8
8
|
import { isMissingTableError, isInsufficientResourcesError } from './chunk-CUPJL6TS.js';
|
|
9
9
|
import { tsvectorStrategy, assertVectorSearchLimit, buildFulltextCapabilities, buildVectorCapabilities } from './chunk-42XYPKZU.js';
|
|
10
10
|
import { sql, isSqlFragment, shouldForceCustomPlan, annIndexScanTypes } from './chunk-M4GYQF2H.js';
|
|
@@ -27,6 +27,10 @@ function isPgNativeClient(candidate) {
|
|
|
27
27
|
function isPgliteClient(candidate) {
|
|
28
28
|
return typeof candidate === "object" && hasFunctionProperty(candidate, "query") && hasFunctionProperty(candidate, "dumpDataDir");
|
|
29
29
|
}
|
|
30
|
+
var PGLITE_MAX_BIND_PARAMETERS = 32767;
|
|
31
|
+
function isPgliteDatabase(db) {
|
|
32
|
+
return isPgliteClient(db.$client);
|
|
33
|
+
}
|
|
30
34
|
function transactionSession(carrier) {
|
|
31
35
|
return carrier.session ?? carrier._?.session;
|
|
32
36
|
}
|
|
@@ -138,9 +142,10 @@ async function executeDrizzleQuery(db, query) {
|
|
|
138
142
|
}
|
|
139
143
|
return result.rows;
|
|
140
144
|
}
|
|
141
|
-
function createPgPreparedStatement(pgClient, sqlText) {
|
|
145
|
+
function createPgPreparedStatement(pgClient, sqlText, maxBindParameters) {
|
|
142
146
|
return {
|
|
143
147
|
async execute(params) {
|
|
148
|
+
assertWithinBindParameterLimit(params.length, maxBindParameters);
|
|
144
149
|
const result = await pgClient.query(sqlText, params);
|
|
145
150
|
return result.rows;
|
|
146
151
|
}
|
|
@@ -149,6 +154,7 @@ function createPgPreparedStatement(pgClient, sqlText) {
|
|
|
149
154
|
function createPostgresExecutionAdapter(db, options = {}) {
|
|
150
155
|
const prepareStatements = options.prepareStatements ?? true;
|
|
151
156
|
const cacheMax = options.preparedStatementCacheMax ?? DEFAULT_POSTGRES_STATEMENT_CACHE_MAX;
|
|
157
|
+
const maxBindParameters = options.maxBindParameters;
|
|
152
158
|
const pgClient = resolvePgClient(
|
|
153
159
|
db,
|
|
154
160
|
prepareStatements,
|
|
@@ -158,10 +164,17 @@ function createPostgresExecutionAdapter(db, options = {}) {
|
|
|
158
164
|
function compile(query) {
|
|
159
165
|
return compileQueryWithDialect(db, query, "PostgreSQL");
|
|
160
166
|
}
|
|
167
|
+
function assertCompiledWithinBindParameterLimit(compiledQuery) {
|
|
168
|
+
assertWithinBindParameterLimit(
|
|
169
|
+
compiledQuery.params.length,
|
|
170
|
+
maxBindParameters
|
|
171
|
+
);
|
|
172
|
+
}
|
|
161
173
|
if (pgClient === void 0) {
|
|
162
174
|
return {
|
|
163
175
|
compile,
|
|
164
176
|
async execute(query) {
|
|
177
|
+
assertCompiledWithinBindParameterLimit(compile(query));
|
|
165
178
|
return executeDrizzleQuery(
|
|
166
179
|
db,
|
|
167
180
|
isSqlFragment(query) ? toDrizzleSql(query, "postgres") : query
|
|
@@ -171,6 +184,7 @@ function createPostgresExecutionAdapter(db, options = {}) {
|
|
|
171
184
|
}
|
|
172
185
|
const pgQueryClient = pgClient;
|
|
173
186
|
async function executeCompiled(compiledQuery) {
|
|
187
|
+
assertCompiledWithinBindParameterLimit(compiledQuery);
|
|
174
188
|
const result = await pgQueryClient.query(
|
|
175
189
|
compiledQuery.sql,
|
|
176
190
|
compiledQuery.params
|
|
@@ -181,6 +195,7 @@ function createPostgresExecutionAdapter(db, options = {}) {
|
|
|
181
195
|
compile,
|
|
182
196
|
async execute(query) {
|
|
183
197
|
const compiled = compile(query);
|
|
198
|
+
assertCompiledWithinBindParameterLimit(compiled);
|
|
184
199
|
if (isSqlFragment(query) && shouldForceCustomPlan(query)) {
|
|
185
200
|
const result = await pgQueryClient.queryUnnamed(
|
|
186
201
|
compiled.sql,
|
|
@@ -192,10 +207,30 @@ function createPostgresExecutionAdapter(db, options = {}) {
|
|
|
192
207
|
},
|
|
193
208
|
executeCompiled,
|
|
194
209
|
prepare(sqlText) {
|
|
195
|
-
return createPgPreparedStatement(
|
|
210
|
+
return createPgPreparedStatement(
|
|
211
|
+
pgQueryClient,
|
|
212
|
+
sqlText,
|
|
213
|
+
maxBindParameters
|
|
214
|
+
);
|
|
196
215
|
}
|
|
197
216
|
};
|
|
198
217
|
}
|
|
218
|
+
function assertWithinBindParameterLimit(parameterCount, maxBindParameters) {
|
|
219
|
+
if (maxBindParameters === void 0 || parameterCount <= maxBindParameters) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
throw new ConfigurationError(
|
|
223
|
+
`PostgreSQL statement uses ${parameterCount} bound parameters, exceeding this backend's limit of ${maxBindParameters}.`,
|
|
224
|
+
{
|
|
225
|
+
capability: "maxBindParameters",
|
|
226
|
+
maxBindParameters,
|
|
227
|
+
parameterCount
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
suggestion: "Split the operation into smaller batches or lower the batch size before retrying."
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
199
234
|
|
|
200
235
|
// src/backend/drizzle/execution/statement-queue.ts
|
|
201
236
|
function ignoreOutcome() {
|
|
@@ -251,42 +286,52 @@ function createSerialExecutionAdapter(adapter) {
|
|
|
251
286
|
// src/backend/drizzle/postgres.ts
|
|
252
287
|
var NODE_INSERT_PARAM_COUNT = 9;
|
|
253
288
|
var EDGE_INSERT_PARAM_COUNT = 12;
|
|
254
|
-
var
|
|
255
|
-
|
|
256
|
-
Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT)
|
|
257
|
-
);
|
|
258
|
-
var POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(
|
|
259
|
-
1,
|
|
260
|
-
Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT)
|
|
261
|
-
);
|
|
262
|
-
var POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(
|
|
263
|
-
1,
|
|
264
|
-
POSTGRES_MAX_BIND_PARAMETERS - 2
|
|
265
|
-
);
|
|
266
|
-
var POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(
|
|
267
|
-
1,
|
|
268
|
-
POSTGRES_MAX_BIND_PARAMETERS - 1
|
|
269
|
-
);
|
|
289
|
+
var GET_NODES_FIXED_PARAM_COUNT = 2;
|
|
290
|
+
var GET_EDGES_FIXED_PARAM_COUNT = 1;
|
|
270
291
|
var FULLTEXT_UPSERT_PARAM_COUNT = 6;
|
|
271
292
|
var FULLTEXT_DELETE_FIXED_PARAM_COUNT = 2;
|
|
272
|
-
var POSTGRES_FULLTEXT_UPSERT_BATCH_SIZE = Math.max(
|
|
273
|
-
1,
|
|
274
|
-
Math.floor(POSTGRES_MAX_BIND_PARAMETERS / FULLTEXT_UPSERT_PARAM_COUNT)
|
|
275
|
-
);
|
|
276
|
-
var POSTGRES_FULLTEXT_DELETE_CHUNK_SIZE = Math.max(
|
|
277
|
-
1,
|
|
278
|
-
POSTGRES_MAX_BIND_PARAMETERS - FULLTEXT_DELETE_FIXED_PARAM_COUNT
|
|
279
|
-
);
|
|
280
293
|
var CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT = 3;
|
|
281
|
-
var POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(
|
|
282
|
-
1,
|
|
283
|
-
POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
|
|
284
|
-
);
|
|
285
294
|
var UNIQUE_INSERT_PARAM_COUNT = 6;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
295
|
+
function computePostgresBatchChunkSizes(maxBindParameters) {
|
|
296
|
+
return {
|
|
297
|
+
checkUniqueBatchChunkSize: Math.max(
|
|
298
|
+
1,
|
|
299
|
+
maxBindParameters - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
|
|
300
|
+
),
|
|
301
|
+
edgeInsertBatchSize: Math.max(
|
|
302
|
+
1,
|
|
303
|
+
Math.floor(maxBindParameters / EDGE_INSERT_PARAM_COUNT)
|
|
304
|
+
),
|
|
305
|
+
embeddingUpsertBatchSize: Math.max(
|
|
306
|
+
1,
|
|
307
|
+
Math.floor(maxBindParameters / EMBEDDING_UPSERT_PARAM_COUNT)
|
|
308
|
+
),
|
|
309
|
+
fulltextDeleteChunkSize: Math.max(
|
|
310
|
+
1,
|
|
311
|
+
maxBindParameters - FULLTEXT_DELETE_FIXED_PARAM_COUNT
|
|
312
|
+
),
|
|
313
|
+
fulltextUpsertBatchSize: Math.max(
|
|
314
|
+
1,
|
|
315
|
+
Math.floor(maxBindParameters / FULLTEXT_UPSERT_PARAM_COUNT)
|
|
316
|
+
),
|
|
317
|
+
getEdgesChunkSize: Math.max(
|
|
318
|
+
1,
|
|
319
|
+
maxBindParameters - GET_EDGES_FIXED_PARAM_COUNT
|
|
320
|
+
),
|
|
321
|
+
getNodesChunkSize: Math.max(
|
|
322
|
+
1,
|
|
323
|
+
maxBindParameters - GET_NODES_FIXED_PARAM_COUNT
|
|
324
|
+
),
|
|
325
|
+
nodeInsertBatchSize: Math.max(
|
|
326
|
+
1,
|
|
327
|
+
Math.floor(maxBindParameters / NODE_INSERT_PARAM_COUNT)
|
|
328
|
+
),
|
|
329
|
+
uniqueInsertBatchSize: Math.max(
|
|
330
|
+
1,
|
|
331
|
+
Math.floor(maxBindParameters / UNIQUE_INSERT_PARAM_COUNT)
|
|
332
|
+
)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
290
335
|
var toNodeRow = createNodeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
|
|
291
336
|
var toEdgeRow = createEdgeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
|
|
292
337
|
var toUniqueRow = createUniqueRowMapper(POSTGRES_ROW_MAPPER_CONFIG);
|
|
@@ -316,14 +361,23 @@ function createPostgresBackend(db, options = {}) {
|
|
|
316
361
|
supported: false
|
|
317
362
|
}
|
|
318
363
|
} : {};
|
|
364
|
+
const configuredMaxBindParameters = options.capabilities?.maxBindParameters ?? POSTGRES_MAX_BIND_PARAMETERS;
|
|
365
|
+
const driverBindParameterOverrides = isPgliteDatabase(db) ? {
|
|
366
|
+
maxBindParameters: Math.min(
|
|
367
|
+
configuredMaxBindParameters,
|
|
368
|
+
PGLITE_MAX_BIND_PARAMETERS
|
|
369
|
+
)
|
|
370
|
+
} : {};
|
|
319
371
|
const capabilities = normalizeGraphAnalyticsCapabilities({
|
|
320
372
|
...baseCapabilities,
|
|
321
373
|
...httpOnlyOverrides,
|
|
322
|
-
...options.capabilities
|
|
374
|
+
...options.capabilities,
|
|
375
|
+
...driverBindParameterOverrides
|
|
323
376
|
});
|
|
324
377
|
const adapterOptions = {
|
|
325
378
|
...options.prepareStatements === void 0 ? {} : { prepareStatements: options.prepareStatements },
|
|
326
|
-
...options.preparedStatementCacheMax === void 0 ? {} : { preparedStatementCacheMax: options.preparedStatementCacheMax }
|
|
379
|
+
...options.preparedStatementCacheMax === void 0 ? {} : { preparedStatementCacheMax: options.preparedStatementCacheMax },
|
|
380
|
+
maxBindParameters: capabilities.maxBindParameters ?? POSTGRES_MAX_BIND_PARAMETERS
|
|
327
381
|
};
|
|
328
382
|
const executionAdapter = createPostgresExecutionAdapter(db, adapterOptions);
|
|
329
383
|
const tableNames = {
|
|
@@ -946,23 +1000,9 @@ function createPostgresOperationBackend(options) {
|
|
|
946
1000
|
return txAdapter.execute(query);
|
|
947
1001
|
});
|
|
948
1002
|
}
|
|
949
|
-
const batchConfig =
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
// Unlike the static siblings, the embedding upsert honors a runtime
|
|
953
|
-
// `maxBindParameters` override so its chunk size tracks the connection's
|
|
954
|
-
// actual bind budget.
|
|
955
|
-
embeddingUpsertBatchSize: Math.max(
|
|
956
|
-
1,
|
|
957
|
-
Math.floor(
|
|
958
|
-
(capabilities.maxBindParameters ?? POSTGRES_MAX_BIND_PARAMETERS) / EMBEDDING_UPSERT_PARAM_COUNT
|
|
959
|
-
)
|
|
960
|
-
),
|
|
961
|
-
getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,
|
|
962
|
-
getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,
|
|
963
|
-
nodeInsertBatchSize: POSTGRES_NODE_INSERT_BATCH_SIZE,
|
|
964
|
-
uniqueInsertBatchSize: POSTGRES_UNIQUE_INSERT_BATCH_SIZE
|
|
965
|
-
};
|
|
1003
|
+
const batchConfig = computePostgresBatchChunkSizes(
|
|
1004
|
+
capabilities.maxBindParameters ?? POSTGRES_MAX_BIND_PARAMETERS
|
|
1005
|
+
);
|
|
966
1006
|
const commonBackend = createCommonOperationBackend({
|
|
967
1007
|
batchConfig,
|
|
968
1008
|
execution: {
|
|
@@ -1205,7 +1245,7 @@ function createPostgresOperationBackend(options) {
|
|
|
1205
1245
|
const timestamp = nowIso();
|
|
1206
1246
|
for (const rows of chunk(
|
|
1207
1247
|
params.rows,
|
|
1208
|
-
|
|
1248
|
+
batchConfig.fulltextUpsertBatchSize
|
|
1209
1249
|
)) {
|
|
1210
1250
|
const statements = operationStrategy.buildUpsertFulltextBatch(
|
|
1211
1251
|
{ ...params, rows },
|
|
@@ -1220,7 +1260,7 @@ function createPostgresOperationBackend(options) {
|
|
|
1220
1260
|
if (params.nodeIds.length === 0) return;
|
|
1221
1261
|
for (const nodeIds of chunk(
|
|
1222
1262
|
params.nodeIds,
|
|
1223
|
-
|
|
1263
|
+
batchConfig.fulltextDeleteChunkSize
|
|
1224
1264
|
)) {
|
|
1225
1265
|
const statements = operationStrategy.buildDeleteFulltextBatch({
|
|
1226
1266
|
...params,
|
|
@@ -1293,5 +1333,5 @@ function createTransactionBackend(options) {
|
|
|
1293
1333
|
}
|
|
1294
1334
|
|
|
1295
1335
|
export { createPostgresBackend };
|
|
1296
|
-
//# sourceMappingURL=chunk-
|
|
1297
|
-
//# sourceMappingURL=chunk-
|
|
1336
|
+
//# sourceMappingURL=chunk-YPVQYM3L.js.map
|
|
1337
|
+
//# sourceMappingURL=chunk-YPVQYM3L.js.map
|