@nicia-ai/typegraph 0.42.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/postgres/index.cjs +2 -2
- package/dist/backend/postgres/index.js +1 -1
- package/dist/backend/postgres/pglite-store.cjs +3 -3
- package/dist/backend/postgres/pglite-store.js +2 -2
- package/dist/backend/postgres/pglite.cjs +3 -3
- package/dist/backend/postgres/pglite.js +2 -2
- 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-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/package.json +1 -1
- package/dist/chunk-7TOT7RKY.cjs.map +0 -1
- package/dist/chunk-BGXKXGDI.js.map +0 -1
|
@@ -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
|