@nicia-ai/typegraph 0.4.0 → 0.6.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/README.md +2 -2
- package/dist/{ast-CXFx6bF6.d.ts → ast-CG87Zr6p.d.ts} +2 -2
- package/dist/{ast-D-3bOanX.d.cts → ast-Cq9qrnNP.d.cts} +2 -2
- package/dist/backend/postgres/index.cjs +295 -23
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +33 -10
- package/dist/backend/postgres/index.d.ts +33 -10
- package/dist/backend/postgres/index.js +285 -5
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +21 -90
- package/dist/backend/sqlite/index.cjs.map +1 -1
- package/dist/backend/sqlite/index.d.cts +22 -58
- package/dist/backend/sqlite/index.d.ts +22 -58
- package/dist/backend/sqlite/index.js +3 -78
- package/dist/backend/sqlite/index.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +83 -0
- package/dist/backend/sqlite/local.cjs.map +1 -0
- package/dist/backend/sqlite/local.d.cts +66 -0
- package/dist/backend/sqlite/local.d.ts +66 -0
- package/dist/backend/sqlite/local.js +77 -0
- package/dist/backend/sqlite/local.js.map +1 -0
- package/dist/chunk-23NGZHUN.cjs +2132 -0
- package/dist/chunk-23NGZHUN.cjs.map +1 -0
- package/dist/{chunk-ZO2FRJ2U.js → chunk-2DKSQNPW.js} +3 -4
- package/dist/chunk-2DKSQNPW.js.map +1 -0
- package/dist/chunk-JPO7W262.js +2093 -0
- package/dist/chunk-JPO7W262.js.map +1 -0
- package/dist/{chunk-NYDXJGA3.cjs → chunk-K5O7TOJO.cjs} +15 -16
- package/dist/chunk-K5O7TOJO.cjs.map +1 -0
- package/dist/{backend/drizzle/schema/postgres.d.ts → ddl-Bcyb4DW1.d.cts} +17 -17
- package/dist/{backend/drizzle/schema/postgres.d.cts → ddl-D7DQx8w8.d.ts} +17 -17
- package/dist/{index-DyrR_d-H.d.cts → index-QTnQwakS.d.cts} +1 -1
- package/dist/{index-DyrR_d-H.d.ts → index-QTnQwakS.d.ts} +1 -1
- package/dist/index.cjs +238 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +238 -1
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.d.cts +5 -6
- package/dist/indexes/index.d.ts +5 -6
- package/dist/interchange/index.d.cts +5 -6
- package/dist/interchange/index.d.ts +5 -6
- package/dist/{manager-0NysX4s6.d.cts → manager-BImRiYwz.d.cts} +3 -3
- package/dist/{manager-DFKe7ql3.d.ts → manager-DGQ9UF18.d.ts} +3 -3
- package/dist/profiler/index.d.cts +7 -8
- package/dist/profiler/index.d.ts +7 -8
- package/dist/schema/index.d.cts +6 -7
- package/dist/schema/index.d.ts +6 -7
- package/dist/{backend/drizzle/schema/sqlite.d.ts → sqlite-CSJ-fgIm.d.ts} +2 -25
- package/dist/{backend/drizzle/schema/sqlite.d.cts → sqlite-FWGZLwDd.d.cts} +2 -25
- package/dist/{store-SiovWEYA.d.ts → store-CscQUG-S.d.ts} +57 -6
- package/dist/{store-DhoA5uRc.d.cts → store-DNv1yd3n.d.cts} +57 -6
- package/dist/{types-DHRsi6j9.d.cts → types-BbMn2Ycv.d.cts} +2 -2
- package/dist/{types-ZT5mlism.d.ts → types-C2rhqkg7.d.ts} +2 -2
- package/dist/{types-6EKrWTs9.d.ts → types-D5ggX07j.d.ts} +7 -3
- package/dist/{types-BL1GyVku.d.cts → types-DEMAqkA1.d.cts} +1 -1
- package/dist/{types-DCGa53O2.d.ts → types-DJZoHy5R.d.ts} +1 -1
- package/dist/{types-DTJEu_-h.d.ts → types-DolHw9pJ.d.cts} +14 -1
- package/dist/{types-DTJEu_-h.d.cts → types-DolHw9pJ.d.ts} +14 -1
- package/dist/{types-BUy-pHKH.d.cts → types-SVDEKnU6.d.cts} +7 -3
- package/package.json +6 -46
- package/dist/backend/drizzle/index.cjs +0 -40
- package/dist/backend/drizzle/index.cjs.map +0 -1
- package/dist/backend/drizzle/index.d.cts +0 -13
- package/dist/backend/drizzle/index.d.ts +0 -13
- package/dist/backend/drizzle/index.js +0 -11
- package/dist/backend/drizzle/index.js.map +0 -1
- package/dist/backend/drizzle/postgres.cjs +0 -26
- package/dist/backend/drizzle/postgres.cjs.map +0 -1
- package/dist/backend/drizzle/postgres.d.cts +0 -35
- package/dist/backend/drizzle/postgres.d.ts +0 -35
- package/dist/backend/drizzle/postgres.js +0 -9
- package/dist/backend/drizzle/postgres.js.map +0 -1
- package/dist/backend/drizzle/schema/postgres.cjs +0 -39
- package/dist/backend/drizzle/schema/postgres.cjs.map +0 -1
- package/dist/backend/drizzle/schema/postgres.js +0 -6
- package/dist/backend/drizzle/schema/postgres.js.map +0 -1
- package/dist/backend/drizzle/schema/sqlite.cjs +0 -39
- package/dist/backend/drizzle/schema/sqlite.cjs.map +0 -1
- package/dist/backend/drizzle/schema/sqlite.js +0 -6
- package/dist/backend/drizzle/schema/sqlite.js.map +0 -1
- package/dist/backend/drizzle/sqlite.cjs +0 -26
- package/dist/backend/drizzle/sqlite.cjs.map +0 -1
- package/dist/backend/drizzle/sqlite.d.cts +0 -35
- package/dist/backend/drizzle/sqlite.d.ts +0 -35
- package/dist/backend/drizzle/sqlite.js +0 -9
- package/dist/backend/drizzle/sqlite.js.map +0 -1
- package/dist/chunk-3PURVEA4.js +0 -193
- package/dist/chunk-3PURVEA4.js.map +0 -1
- package/dist/chunk-7RVSDXT3.cjs +0 -1509
- package/dist/chunk-7RVSDXT3.cjs.map +0 -1
- package/dist/chunk-LUARLSYT.cjs +0 -289
- package/dist/chunk-LUARLSYT.cjs.map +0 -1
- package/dist/chunk-NU2XNMVI.cjs +0 -201
- package/dist/chunk-NU2XNMVI.cjs.map +0 -1
- package/dist/chunk-NYDXJGA3.cjs.map +0 -1
- package/dist/chunk-OGGLFYFA.js +0 -177
- package/dist/chunk-OGGLFYFA.js.map +0 -1
- package/dist/chunk-Q6PXIKRQ.js +0 -287
- package/dist/chunk-Q6PXIKRQ.js.map +0 -1
- package/dist/chunk-SMLIWLS7.js +0 -236
- package/dist/chunk-SMLIWLS7.js.map +0 -1
- package/dist/chunk-UYMT4LO2.cjs +0 -241
- package/dist/chunk-UYMT4LO2.cjs.map +0 -1
- package/dist/chunk-XZL6MCZJ.cjs +0 -185
- package/dist/chunk-XZL6MCZJ.cjs.map +0 -1
- package/dist/chunk-ZO2FRJ2U.js.map +0 -1
- package/dist/chunk-ZQGOBVXZ.js +0 -1488
- package/dist/chunk-ZQGOBVXZ.js.map +0 -1
- package/dist/test-helpers-CIq1Hhj1.d.ts +0 -26
- package/dist/test-helpers-DPRFVky4.d.cts +0 -26
- package/dist/types-BRzHlhKC.d.cts +0 -14
- package/dist/types-BRzHlhKC.d.ts +0 -14
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var chunkXZL6MCZJ_cjs = require('./chunk-XZL6MCZJ.cjs');
|
|
3
|
+
var chunk23NGZHUN_cjs = require('./chunk-23NGZHUN.cjs');
|
|
5
4
|
var chunk44SXEVF4_cjs = require('./chunk-44SXEVF4.cjs');
|
|
6
5
|
var drizzleOrm = require('drizzle-orm');
|
|
7
6
|
|
|
@@ -103,7 +102,7 @@ function createSqliteExecutionAdapter(db, statementCacheMaxOrOptions = {}) {
|
|
|
103
102
|
isSync: profileBase.isSync,
|
|
104
103
|
supportsCompiledExecution
|
|
105
104
|
};
|
|
106
|
-
const compile = (query) =>
|
|
105
|
+
const compile = (query) => chunk23NGZHUN_cjs.compileQueryWithDialect(db, query, "SQLite");
|
|
107
106
|
if (supportsCompiledExecution) {
|
|
108
107
|
let executeCompiled2 = function(compiledQuery) {
|
|
109
108
|
const preparedStatement = getOrCreatePreparedStatement(
|
|
@@ -169,10 +168,10 @@ var SQLITE_GET_EDGES_ID_CHUNK_SIZE = Math.max(
|
|
|
169
168
|
1,
|
|
170
169
|
SQLITE_MAX_BIND_PARAMETERS - 1
|
|
171
170
|
);
|
|
172
|
-
var toNodeRow =
|
|
173
|
-
var toEdgeRow =
|
|
174
|
-
var toUniqueRow =
|
|
175
|
-
var toSchemaVersionRow =
|
|
171
|
+
var toNodeRow = chunk23NGZHUN_cjs.createNodeRowMapper(chunk23NGZHUN_cjs.SQLITE_ROW_MAPPER_CONFIG);
|
|
172
|
+
var toEdgeRow = chunk23NGZHUN_cjs.createEdgeRowMapper(chunk23NGZHUN_cjs.SQLITE_ROW_MAPPER_CONFIG);
|
|
173
|
+
var toUniqueRow = chunk23NGZHUN_cjs.createUniqueRowMapper(chunk23NGZHUN_cjs.SQLITE_ROW_MAPPER_CONFIG);
|
|
174
|
+
var toSchemaVersionRow = chunk23NGZHUN_cjs.createSchemaVersionRowMapper(chunk23NGZHUN_cjs.SQLITE_ROW_MAPPER_CONFIG);
|
|
176
175
|
function createSerializedExecutionQueue() {
|
|
177
176
|
let tail = Promise.resolve();
|
|
178
177
|
return {
|
|
@@ -218,7 +217,7 @@ function createSqliteOperationBackend(options) {
|
|
|
218
217
|
if (result instanceof Promise) await result;
|
|
219
218
|
});
|
|
220
219
|
}
|
|
221
|
-
const commonBackend =
|
|
220
|
+
const commonBackend = chunk23NGZHUN_cjs.createCommonOperationBackend({
|
|
222
221
|
batchConfig: {
|
|
223
222
|
edgeInsertBatchSize: SQLITE_EDGE_INSERT_BATCH_SIZE,
|
|
224
223
|
getEdgesChunkSize: SQLITE_GET_EDGES_ID_CHUNK_SIZE,
|
|
@@ -230,7 +229,7 @@ function createSqliteOperationBackend(options) {
|
|
|
230
229
|
execGet,
|
|
231
230
|
execRun
|
|
232
231
|
},
|
|
233
|
-
nowIso:
|
|
232
|
+
nowIso: chunk23NGZHUN_cjs.nowIso,
|
|
234
233
|
operationStrategy,
|
|
235
234
|
rowMappers: {
|
|
236
235
|
toEdgeRow,
|
|
@@ -266,14 +265,14 @@ function createSqliteOperationBackend(options) {
|
|
|
266
265
|
...params.indexParams?.efConstruction === void 0 ? {} : { hnswEfConstruction: params.indexParams.efConstruction },
|
|
267
266
|
...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists }
|
|
268
267
|
};
|
|
269
|
-
const result =
|
|
268
|
+
const result = chunk23NGZHUN_cjs.createSqliteVectorIndex(indexOptions);
|
|
270
269
|
if (!result.success) {
|
|
271
270
|
throw new Error(result.message ?? "Failed to create SQLite vector index");
|
|
272
271
|
}
|
|
273
272
|
return Promise.resolve();
|
|
274
273
|
},
|
|
275
274
|
dropVectorIndex(params) {
|
|
276
|
-
const result =
|
|
275
|
+
const result = chunk23NGZHUN_cjs.dropSqliteVectorIndex(
|
|
277
276
|
params.graphId,
|
|
278
277
|
params.nodeKind,
|
|
279
278
|
params.fieldPath
|
|
@@ -297,17 +296,17 @@ function createSqliteOperationBackend(options) {
|
|
|
297
296
|
return operationBackend;
|
|
298
297
|
}
|
|
299
298
|
function createSqliteBackend(db, options = {}) {
|
|
300
|
-
const tables2 = options.tables ??
|
|
299
|
+
const tables2 = options.tables ?? chunk23NGZHUN_cjs.tables;
|
|
301
300
|
const profileHints = options.executionProfile ?? {};
|
|
302
301
|
const executionAdapter = createSqliteExecutionAdapter(db, { profileHints });
|
|
303
302
|
const { isD1, isSync } = executionAdapter.profile;
|
|
304
|
-
const capabilities = isD1 ?
|
|
303
|
+
const capabilities = isD1 ? chunk23NGZHUN_cjs.D1_CAPABILITIES : chunk23NGZHUN_cjs.SQLITE_CAPABILITIES;
|
|
305
304
|
const tableNames = {
|
|
306
305
|
nodes: drizzleOrm.getTableName(tables2.nodes),
|
|
307
306
|
edges: drizzleOrm.getTableName(tables2.edges),
|
|
308
307
|
embeddings: drizzleOrm.getTableName(tables2.embeddings)
|
|
309
308
|
};
|
|
310
|
-
const operationStrategy =
|
|
309
|
+
const operationStrategy = chunk23NGZHUN_cjs.createSqliteOperationStrategy(tables2);
|
|
311
310
|
const serializedQueue = isSync ? createSerializedExecutionQueue() : void 0;
|
|
312
311
|
const operations = createSqliteOperationBackend({
|
|
313
312
|
capabilities,
|
|
@@ -386,5 +385,5 @@ function createTransactionBackend(options) {
|
|
|
386
385
|
}
|
|
387
386
|
|
|
388
387
|
exports.createSqliteBackend = createSqliteBackend;
|
|
389
|
-
//# sourceMappingURL=chunk-
|
|
390
|
-
//# sourceMappingURL=chunk-
|
|
388
|
+
//# sourceMappingURL=chunk-K5O7TOJO.cjs.map
|
|
389
|
+
//# sourceMappingURL=chunk-K5O7TOJO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/drizzle/execution/sqlite-execution.ts","../src/backend/drizzle/sqlite.ts"],"names":["sql","compileQueryWithDialect","executeCompiled","createNodeRowMapper","SQLITE_ROW_MAPPER_CONFIG","createEdgeRowMapper","createUniqueRowMapper","createSchemaVersionRowMapper","createCommonOperationBackend","nowIso","createSqliteVectorIndex","dropSqliteVectorIndex","tables","D1_CAPABILITIES","SQLITE_CAPABILITIES","getTableName","createSqliteOperationStrategy","ConfigurationError"],"mappings":";;;;;;AAUA,IAAM,oCAAA,GAAuC,GAAA;AAoD7C,SAAS,eAAe,EAAA,EAA2C;AACjE,EAAA,MAAM,mBAAA,GAAsB,EAAA;AAC5B,EAAA,MAAM,kBAAA,GAAqB,mBAAA,CAAoB,OAAA,EAAS,WAAA,EAAa,IAAA;AACrE,EAAA,IAAI,uBAAuB,MAAA,EAAW;AACpC,IAAA,OAAO,kBAAA;AAAA,EACT;AAEA,EAAA,OAAO,mBAAA,CAAoB,CAAA,EAAG,OAAA,EAAS,WAAA,EAAa,IAAA;AACtD;AAEA,SAAS,0BAA0B,EAAA,EAAgC;AACjE,EAAA,OAAO,cAAA,CAAe,EAAE,CAAA,KAAM,iBAAA;AAChC;AAEA,SAAS,4BAA4B,EAAA,EAAgC;AACnE,EAAA,MAAM,WAAA,GAAc,eAAe,EAAE,CAAA;AACrC,EAAA,OACE,WAAA,KAAgB,yBAAyB,WAA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CAAA;AAAA,MACH;AAEA,MAAA,OAAO,EAAA,CAAG,WAAA,CAAY,OAAO,EAAA,KAAO;AAClC,QAAA,MAAM,YAAY,wBAAA,CAAyB;AAAA,UACzC,YAAA;AAAA,UACA,EAAA,EAAI,EAAA;AAAA,UACJ,iBAAA;AAAA,UACA,YAAA,EAAc,EAAE,IAAA,EAAM,KAAA,EAAO,QAAQ,KAAA,EAAM;AAAA,UAC3C;AAAA,SACD,CAAA;AACD,QAAA,OAAO,GAAG,SAAS,CAAA;AAAA,MACrB,CAAC,CAAA;AAAA,IACH,CAAA;AAAA,IAEA,MAAM,KAAA,GAAuB;AAAA,IAG7B;AAAA,GACF;AAEA,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,yBACP,OAAA,EACoB;AACpB,EAAA,MAAM,kBAAA,GACJ,OAAA,CAAQ,gBAAA,IACR,4BAAA,CAA6B,QAAQ,EAAA,EAAI;AAAA,IACvC,cAAc,OAAA,CAAQ;AAAA,GACvB,CAAA;AAEH,EAAA,OAAO,4BAAA,CAA6B;AAAA,IAClC,cAAc,OAAA,CAAQ,YAAA;AAAA,IACtB,IAAI,OAAA,CAAQ,EAAA;AAAA,IACZ,gBAAA,EAAkB,kBAAA;AAAA,IAClB,mBAAmB,OAAA,CAAQ,iBAAA;AAAA,IAC3B,YAAY,OAAA,CAAQ;AAAA,GACrB,CAAA;AACH","file":"chunk-K5O7TOJO.cjs","sourcesContent":["import { type SQL, sql } from \"drizzle-orm\";\nimport { type BaseSQLiteDatabase } from \"drizzle-orm/sqlite-core\";\n\nimport {\n type CompiledSqlQuery,\n compileQueryWithDialect,\n type PreparedSqlStatement,\n type SqlExecutionAdapter,\n} from \"./types\";\n\nconst DEFAULT_PREPARED_STATEMENT_CACHE_MAX = 256;\n\ntype PreparedAllStatement = Readonly<{\n all: (...params: readonly unknown[]) => readonly unknown[];\n}>;\n\ntype SqliteClientWithPrepare = Readonly<{\n prepare: (sqlText: string) => PreparedAllStatement;\n}>;\n\ntype SqliteClientCarrier = Readonly<{\n $client?: SqliteClientWithPrepare;\n}>;\n\ntype SessionLike = Readonly<{\n constructor?: Readonly<{\n name?: string;\n }>;\n}>;\n\ntype DatabaseWithSession = Readonly<{\n _?: Readonly<{\n session?: SessionLike;\n }>;\n session?: SessionLike;\n}>;\n\nexport type SqliteExecutionProfileHints = Readonly<{\n isD1?: boolean;\n isSync?: boolean;\n}>;\n\ntype SqliteExecutionAdapterOptions = Readonly<{\n profileHints?: SqliteExecutionProfileHints;\n statementCacheMax?: number;\n}>;\n\nexport type AnySqliteDatabase = BaseSQLiteDatabase<\"sync\" | \"async\", unknown>;\n\nexport type SqliteExecutionProfile = Readonly<{\n isD1: boolean;\n isSync: boolean;\n supportsCompiledExecution: boolean;\n}>;\n\nexport type SqliteExecutionAdapter = Readonly<\n SqlExecutionAdapter & {\n clearStatementCache: () => void;\n profile: SqliteExecutionProfile;\n }\n>;\n\nfunction getSessionName(db: AnySqliteDatabase): string | undefined {\n const databaseWithSession = db as DatabaseWithSession;\n const primarySessionName = databaseWithSession.session?.constructor?.name;\n if (primarySessionName !== undefined) {\n return primarySessionName;\n }\n\n return databaseWithSession._?.session?.constructor?.name;\n}\n\nfunction isD1DatabaseBySessionName(db: AnySqliteDatabase): boolean {\n return getSessionName(db) === \"SQLiteD1Session\";\n}\n\nfunction isSyncDatabaseBySessionName(db: AnySqliteDatabase): boolean {\n const sessionName = getSessionName(db);\n return (\n sessionName === \"BetterSQLiteSession\" || sessionName === \"BunSQLiteSession\"\n );\n}\n\nfunction detectSyncProfile(\n db: AnySqliteDatabase,\n profileHints: SqliteExecutionProfileHints,\n): boolean {\n if (profileHints.isSync !== undefined) {\n return profileHints.isSync;\n }\n\n const sessionName = getSessionName(db);\n if (sessionName === \"BetterSQLiteSession\" || sessionName === \"BunSQLiteSession\") {\n return true;\n }\n if (sessionName === \"SQLiteD1Session\") {\n return false;\n }\n\n try {\n const probeResult = db.get(sql`SELECT 1 AS __typegraph_sync_probe__`);\n return !(probeResult instanceof Promise);\n } catch {\n return isSyncDatabaseBySessionName(db);\n }\n}\n\nfunction detectD1Profile(\n db: AnySqliteDatabase,\n profileHints: SqliteExecutionProfileHints,\n): boolean {\n if (profileHints.isD1 !== undefined) {\n return profileHints.isD1;\n }\n\n return isD1DatabaseBySessionName(db);\n}\n\nfunction resolveSqliteClient(\n db: AnySqliteDatabase,\n): SqliteClientWithPrepare | undefined {\n const databaseWithClient = db as SqliteClientCarrier;\n const sqliteClient = databaseWithClient.$client;\n if (sqliteClient?.prepare === undefined) {\n return undefined;\n }\n return sqliteClient;\n}\n\nfunction getOrCreatePreparedStatement(\n cache: Map<string, PreparedAllStatement>,\n sqliteClient: SqliteClientWithPrepare,\n sqlText: string,\n cacheMax: number,\n): PreparedAllStatement {\n const cachedStatement = cache.get(sqlText);\n if (cachedStatement !== undefined) {\n // Promote to most-recently-used position for LRU eviction\n cache.delete(sqlText);\n cache.set(sqlText, cachedStatement);\n return cachedStatement;\n }\n\n const preparedStatement = sqliteClient.prepare(sqlText);\n cache.set(sqlText, preparedStatement);\n\n if (cache.size > cacheMax) {\n const oldestSqlText = cache.keys().next().value;\n if (typeof oldestSqlText === \"string\") {\n cache.delete(oldestSqlText);\n }\n }\n\n return preparedStatement;\n}\n\nasync function executeDrizzleQuery<TRow>(\n db: AnySqliteDatabase,\n query: SQL,\n): Promise<readonly TRow[]> {\n const rows = db.all(query);\n return (rows instanceof Promise ? await rows : rows) as readonly TRow[];\n}\n\nfunction createPreparedStatementExecutor(\n sqliteClient: SqliteClientWithPrepare,\n cache: Map<string, PreparedAllStatement>,\n sqlText: string,\n cacheMax: number,\n): PreparedSqlStatement {\n return {\n execute<TRow>(params: readonly unknown[]): Promise<readonly TRow[]> {\n const preparedStatement = getOrCreatePreparedStatement(\n cache,\n sqliteClient,\n sqlText,\n cacheMax,\n );\n const rows = preparedStatement.all(...params);\n return Promise.resolve(rows as readonly TRow[]);\n },\n };\n}\n\nexport function createSqliteExecutionAdapter(\n db: AnySqliteDatabase,\n statementCacheMaxOrOptions: number | SqliteExecutionAdapterOptions = {},\n): SqliteExecutionAdapter {\n const options: SqliteExecutionAdapterOptions =\n typeof statementCacheMaxOrOptions === \"number\"\n ? { statementCacheMax: statementCacheMaxOrOptions }\n : statementCacheMaxOrOptions;\n const statementCacheMax =\n options.statementCacheMax ?? DEFAULT_PREPARED_STATEMENT_CACHE_MAX;\n const profileHints = options.profileHints ?? {};\n\n const profileBase: Readonly<{\n isD1: boolean;\n isSync: boolean;\n sqliteClient: SqliteClientWithPrepare | undefined;\n }> = {\n isD1: detectD1Profile(db, profileHints),\n isSync: detectSyncProfile(db, profileHints),\n sqliteClient: resolveSqliteClient(db),\n };\n\n const supportsCompiledExecution =\n profileBase.isSync &&\n !profileBase.isD1 &&\n profileBase.sqliteClient !== undefined;\n\n const profile: SqliteExecutionProfile = {\n isD1: profileBase.isD1,\n isSync: profileBase.isSync,\n supportsCompiledExecution,\n };\n\n const compile = (query: SQL): CompiledSqlQuery =>\n compileQueryWithDialect(db, query, \"SQLite\");\n\n if (supportsCompiledExecution) {\n const sqliteClient = profileBase.sqliteClient;\n const statementCache = new Map<string, PreparedAllStatement>();\n\n function executeCompiled<TRow>(\n compiledQuery: CompiledSqlQuery,\n ): Promise<readonly TRow[]> {\n const preparedStatement = getOrCreatePreparedStatement(\n statementCache,\n sqliteClient,\n compiledQuery.sql,\n statementCacheMax,\n );\n const rows = preparedStatement.all(...compiledQuery.params);\n return Promise.resolve(rows as readonly TRow[]);\n }\n\n return {\n clearStatementCache() {\n statementCache.clear();\n },\n compile,\n execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n const compiledQuery = compile(query);\n return executeCompiled<TRow>(compiledQuery);\n },\n executeCompiled,\n prepare(sqlText: string): PreparedSqlStatement {\n return createPreparedStatementExecutor(\n sqliteClient,\n statementCache,\n sqlText,\n statementCacheMax,\n );\n },\n profile,\n };\n }\n\n return {\n clearStatementCache() {\n // No-op: no statement cache in async/D1 mode\n },\n compile,\n execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n profile,\n };\n}\n","/**\n * SQLite backend adapter for TypeGraph.\n *\n * Works with any Drizzle SQLite database instance:\n * - better-sqlite3\n * - libsql / Turso\n * - Cloudflare D1\n * - bun:sqlite\n * - sql.js\n *\n * @example\n * ```typescript\n * import { drizzle } from \"drizzle-orm/better-sqlite3\";\n * import Database from \"better-sqlite3\";\n * import { createSqliteBackend, tables } from \"@nicia-ai/typegraph/sqlite\";\n *\n * const sqlite = new Database(\"app.db\");\n * const db = drizzle(sqlite);\n * const backend = createSqliteBackend(db, { tables });\n * ```\n */\nimport { getTableName, type SQL, sql } from \"drizzle-orm\";\n\nimport { ConfigurationError } from \"../../errors\";\nimport type { SqlTableNames } from \"../../query/compiler/schema\";\nimport {\n type CreateVectorIndexParams,\n D1_CAPABILITIES,\n type DropVectorIndexParams,\n type GraphBackend,\n SQLITE_CAPABILITIES,\n type TransactionBackend,\n type TransactionOptions,\n} from \"../types\";\nimport {\n type AnySqliteDatabase,\n createSqliteExecutionAdapter,\n type SqliteExecutionAdapter,\n type SqliteExecutionProfileHints,\n} from \"./execution/sqlite-execution\";\nimport { createCommonOperationBackend } from \"./operation-backend-core\";\nimport { createSqliteOperationStrategy } from \"./operations/strategy\";\nimport {\n createEdgeRowMapper,\n createNodeRowMapper,\n createSchemaVersionRowMapper,\n createUniqueRowMapper,\n nowIso,\n SQLITE_ROW_MAPPER_CONFIG,\n} from \"./row-mappers\";\nimport { type SqliteTables, tables as defaultTables } from \"./schema/sqlite\";\nimport {\n createSqliteVectorIndex,\n dropSqliteVectorIndex,\n type VectorIndexOptions,\n} from \"./vector-index\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a SQLite backend.\n */\nexport type SqliteBackendOptions = Readonly<{\n /**\n * Custom table definitions. Use createSqliteTables() to customize table names.\n * Defaults to standard TypeGraph table names.\n */\n tables?: SqliteTables;\n /**\n * Optional execution profile hints used to avoid runtime driver reflection.\n * Set `isD1: true` when using Cloudflare D1.\n */\n executionProfile?: SqliteExecutionProfileHints;\n}>;\n\nconst SQLITE_MAX_BIND_PARAMETERS = 999;\nconst NODE_INSERT_PARAM_COUNT = 9;\nconst EDGE_INSERT_PARAM_COUNT = 12;\nconst SQLITE_NODE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(SQLITE_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT),\n);\nconst SQLITE_EDGE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(SQLITE_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT),\n);\nconst SQLITE_GET_NODES_ID_CHUNK_SIZE = Math.max(\n 1,\n SQLITE_MAX_BIND_PARAMETERS - 2,\n);\nconst SQLITE_GET_EDGES_ID_CHUNK_SIZE = Math.max(\n 1,\n SQLITE_MAX_BIND_PARAMETERS - 1,\n);\n\ntype SerializedExecutionQueue = Readonly<{\n runExclusive: <T>(task: () => Promise<T>) => Promise<T>;\n}>;\n\n// ============================================================\n// Utilities\n// ============================================================\n\nconst toNodeRow = createNodeRowMapper(SQLITE_ROW_MAPPER_CONFIG);\nconst toEdgeRow = createEdgeRowMapper(SQLITE_ROW_MAPPER_CONFIG);\nconst toUniqueRow = createUniqueRowMapper(SQLITE_ROW_MAPPER_CONFIG);\nconst toSchemaVersionRow = createSchemaVersionRowMapper(SQLITE_ROW_MAPPER_CONFIG);\n\nfunction createSerializedExecutionQueue(): SerializedExecutionQueue {\n let tail: Promise<unknown> = Promise.resolve();\n\n return {\n async runExclusive<T>(task: () => Promise<T>): Promise<T> {\n const runTask = async (): Promise<T> => task();\n const result = tail.then(runTask, runTask);\n tail = result.then(\n () => 0,\n () => 0,\n );\n return result;\n },\n };\n}\n\nasync function runWithSerializedQueue<T>(\n queue: SerializedExecutionQueue | undefined,\n task: () => Promise<T>,\n): Promise<T> {\n if (queue === undefined) return task();\n return queue.runExclusive(task);\n}\n\n// ============================================================\n// Backend Factory\n// ============================================================\n\n/**\n * Creates a TypeGraph backend for SQLite databases.\n *\n * Works with any Drizzle SQLite instance regardless of the underlying driver.\n *\n * @param db - A Drizzle SQLite database instance\n * @param options - Backend configuration\n * @returns A GraphBackend implementation\n */\ntype CreateSqliteOperationBackendOptions = Readonly<{\n capabilities: GraphBackend[\"capabilities\"];\n db: AnySqliteDatabase;\n executionAdapter: SqliteExecutionAdapter;\n operationStrategy: ReturnType<typeof createSqliteOperationStrategy>;\n serializedQueue?: SerializedExecutionQueue;\n tableNames: SqlTableNames;\n}>;\n\ntype CreateSqliteTransactionBackendOptions = Readonly<{\n capabilities: GraphBackend[\"capabilities\"];\n db: AnySqliteDatabase;\n executionAdapter?: SqliteExecutionAdapter;\n operationStrategy: ReturnType<typeof createSqliteOperationStrategy>;\n profileHints: SqliteExecutionProfileHints;\n tableNames: SqlTableNames;\n}>;\n\nfunction createSqliteOperationBackend(\n options: CreateSqliteOperationBackendOptions,\n): TransactionBackend {\n const {\n capabilities,\n db,\n executionAdapter,\n operationStrategy,\n serializedQueue,\n tableNames,\n } = options;\n\n async function execGet<T>(query: SQL): Promise<T | undefined> {\n return runWithSerializedQueue(serializedQueue, async () => {\n const result = db.get(query);\n return (result instanceof Promise ? await result : result) as T | undefined;\n });\n }\n\n async function execAll<T>(query: SQL): Promise<T[]> {\n return runWithSerializedQueue(serializedQueue, async () => {\n const result = db.all(query);\n return (result instanceof Promise ? await result : result) as T[];\n });\n }\n\n async function execRun(query: SQL): Promise<void> {\n await runWithSerializedQueue(serializedQueue, async () => {\n const result = db.run(query);\n if (result instanceof Promise) await result;\n });\n }\n\n const commonBackend = createCommonOperationBackend({\n batchConfig: {\n edgeInsertBatchSize: SQLITE_EDGE_INSERT_BATCH_SIZE,\n getEdgesChunkSize: SQLITE_GET_EDGES_ID_CHUNK_SIZE,\n getNodesChunkSize: SQLITE_GET_NODES_ID_CHUNK_SIZE,\n nodeInsertBatchSize: SQLITE_NODE_INSERT_BATCH_SIZE,\n },\n execution: {\n execAll,\n execGet,\n execRun,\n },\n nowIso,\n operationStrategy,\n rowMappers: {\n toEdgeRow,\n toNodeRow,\n toSchemaVersionRow,\n toUniqueRow,\n },\n });\n\n const executeCompiled = executionAdapter.executeCompiled;\n const executeRawMethod: Pick<TransactionBackend, \"executeRaw\"> =\n executeCompiled === undefined ?\n {}\n : {\n executeRaw<T>(\n sqlText: string,\n params: readonly unknown[],\n ): Promise<readonly T[]> {\n return runWithSerializedQueue(serializedQueue, async () =>\n executeCompiled<T>({ params, sql: sqlText }),\n );\n },\n };\n\n const operationBackend: TransactionBackend = {\n ...commonBackend,\n ...executeRawMethod,\n capabilities,\n dialect: \"sqlite\",\n tableNames,\n\n createVectorIndex(params: CreateVectorIndexParams): Promise<void> {\n const indexOptions: VectorIndexOptions = {\n graphId: params.graphId,\n nodeKind: params.nodeKind,\n fieldPath: params.fieldPath,\n dimensions: params.dimensions,\n indexType: params.indexType,\n metric: params.metric,\n ...(params.indexParams?.m === undefined\n ? {}\n : { hnswM: params.indexParams.m }),\n ...(params.indexParams?.efConstruction === undefined\n ? {}\n : { hnswEfConstruction: params.indexParams.efConstruction }),\n ...(params.indexParams?.lists === undefined\n ? {}\n : { ivfflatLists: params.indexParams.lists }),\n };\n\n const result = createSqliteVectorIndex(indexOptions);\n\n if (!result.success) {\n throw new Error(result.message ?? \"Failed to create SQLite vector index\");\n }\n return Promise.resolve();\n },\n\n dropVectorIndex(params: DropVectorIndexParams): Promise<void> {\n const result = dropSqliteVectorIndex(\n params.graphId,\n params.nodeKind,\n params.fieldPath,\n );\n if (!result.success) {\n throw new Error(result.message ?? \"Failed to drop SQLite vector index\");\n }\n return Promise.resolve();\n },\n\n // === Query Execution ===\n\n async execute<T>(query: SQL): Promise<readonly T[]> {\n return runWithSerializedQueue(serializedQueue, async () =>\n executionAdapter.execute<T>(query),\n );\n },\n\n compileSql(query: SQL): Readonly<{ sql: string; params: readonly unknown[] }> {\n return executionAdapter.compile(query);\n },\n };\n\n return operationBackend;\n}\n\nexport function createSqliteBackend(\n db: AnySqliteDatabase,\n options: SqliteBackendOptions = {},\n): GraphBackend {\n const tables = options.tables ?? defaultTables;\n const profileHints = options.executionProfile ?? {};\n const executionAdapter = createSqliteExecutionAdapter(db, { profileHints });\n const { isD1, isSync } = executionAdapter.profile;\n const capabilities = isD1 ? D1_CAPABILITIES : SQLITE_CAPABILITIES;\n\n const tableNames: SqlTableNames = {\n nodes: getTableName(tables.nodes),\n edges: getTableName(tables.edges),\n embeddings: getTableName(tables.embeddings),\n };\n const operationStrategy = createSqliteOperationStrategy(tables);\n const serializedQueue = isSync ? createSerializedExecutionQueue() : undefined;\n const operations = createSqliteOperationBackend({\n capabilities,\n db,\n executionAdapter,\n operationStrategy,\n tableNames,\n ...(serializedQueue === undefined ? {} : { serializedQueue }),\n });\n\n const backend: GraphBackend = {\n ...operations,\n\n async setActiveSchema(graphId: string, version: number): Promise<void> {\n await backend.transaction(async (txBackend) => {\n await txBackend.setActiveSchema(graphId, version);\n });\n },\n\n async transaction<T>(\n fn: (tx: TransactionBackend) => Promise<T>,\n _options?: TransactionOptions,\n ): Promise<T> {\n if (isD1) {\n throw new ConfigurationError(\n \"Cloudflare D1 does not support atomic transactions. \" +\n \"Operations within a transaction are not rolled back on failure. \" +\n \"Use backend.capabilities.transactions to check for transaction support, \" +\n \"or use individual operations with manual error handling.\",\n {\n backend: \"D1\",\n capability: \"transactions\",\n supportsTransactions: false,\n },\n );\n }\n\n if (isSync) {\n return runWithSerializedQueue(serializedQueue, async () => {\n const txBackend = createTransactionBackend({\n capabilities,\n db,\n executionAdapter,\n operationStrategy,\n profileHints: { isD1: false, isSync: true },\n tableNames,\n });\n db.run(sql`BEGIN`);\n\n try {\n const result = await fn(txBackend);\n db.run(sql`COMMIT`);\n return result;\n } catch (error) {\n db.run(sql`ROLLBACK`);\n throw error;\n }\n });\n }\n\n return db.transaction(async (tx) => {\n const txBackend = createTransactionBackend({\n capabilities,\n db: tx as AnySqliteDatabase,\n operationStrategy,\n profileHints: { isD1: false, isSync: false },\n tableNames,\n });\n return fn(txBackend);\n }) as Promise<T>;\n },\n\n async close(): Promise<void> {\n // Drizzle doesn't expose a close method\n // Users manage connection lifecycle themselves\n },\n };\n\n return backend;\n}\n\nfunction createTransactionBackend(\n options: CreateSqliteTransactionBackendOptions,\n): TransactionBackend {\n const txExecutionAdapter =\n options.executionAdapter ??\n createSqliteExecutionAdapter(options.db, {\n profileHints: options.profileHints,\n });\n\n return createSqliteOperationBackend({\n capabilities: options.capabilities,\n db: options.db,\n executionAdapter: txExecutionAdapter,\n operationStrategy: options.operationStrategy,\n tableNames: options.tableNames,\n });\n}\n\n// Re-export schema utilities\nexport type { SqliteTableNames,SqliteTables } from \"./schema/sqlite\";\nexport { createSqliteTables, tables } from \"./schema/sqlite\";\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
import { T as TypeGraphIndex } from '
|
|
3
|
-
import '
|
|
4
|
-
import '../../../types-DTJEu_-h.js';
|
|
5
|
-
import '../../../ast-CXFx6bF6.js';
|
|
2
|
+
import { T as TypeGraphIndex } from './types-BbMn2Ycv.cjs';
|
|
3
|
+
import { S as SqliteTables } from './sqlite-FWGZLwDd.cjs';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Table name configuration.
|
|
@@ -2396,25 +2394,27 @@ declare const embeddings: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
2396
2394
|
* Type representing the tables object returned by createPostgresTables.
|
|
2397
2395
|
*/
|
|
2398
2396
|
type PostgresTables = ReturnType<typeof createPostgresTables>;
|
|
2397
|
+
|
|
2399
2398
|
/**
|
|
2400
|
-
*
|
|
2401
|
-
*/
|
|
2402
|
-
type NodesTable = PostgresTables["nodes"];
|
|
2403
|
-
/**
|
|
2404
|
-
* Type for edges table.
|
|
2399
|
+
* Generates all DDL statements for the given SQLite tables.
|
|
2405
2400
|
*/
|
|
2406
|
-
|
|
2401
|
+
declare function generateSqliteDDL(tables?: SqliteTables): string[];
|
|
2407
2402
|
/**
|
|
2408
|
-
*
|
|
2403
|
+
* Generates a single SQL string for SQLite migrations.
|
|
2404
|
+
* Convenience function that joins all DDL statements.
|
|
2409
2405
|
*/
|
|
2410
|
-
|
|
2406
|
+
declare function generateSqliteMigrationSQL(tables?: SqliteTables): string;
|
|
2411
2407
|
/**
|
|
2412
|
-
*
|
|
2408
|
+
* Generates all DDL statements for the given PostgreSQL tables.
|
|
2413
2409
|
*/
|
|
2414
|
-
|
|
2410
|
+
declare function generatePostgresDDL(tables?: PostgresTables): string[];
|
|
2415
2411
|
/**
|
|
2416
|
-
*
|
|
2412
|
+
* Generates a single SQL string for PostgreSQL migrations.
|
|
2413
|
+
* Convenience function that joins all DDL statements.
|
|
2414
|
+
*
|
|
2415
|
+
* Includes CREATE EXTENSION for pgvector since the embeddings table
|
|
2416
|
+
* uses the native VECTOR type.
|
|
2417
2417
|
*/
|
|
2418
|
-
|
|
2418
|
+
declare function generatePostgresMigrationSQL(tables?: PostgresTables): string;
|
|
2419
2419
|
|
|
2420
|
-
export { type CreatePostgresTablesOptions
|
|
2420
|
+
export { type CreatePostgresTablesOptions as C, type PostgresTables as P, generateSqliteMigrationSQL as a, type PostgresTableNames as b, createPostgresTables as c, embeddings as d, edges as e, generatePostgresDDL as f, generateSqliteDDL as g, generatePostgresMigrationSQL as h, nodes as n, schemaVersions as s, tables as t, uniques as u };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
import { T as TypeGraphIndex } from '
|
|
3
|
-
import '
|
|
4
|
-
import '../../../types-DTJEu_-h.cjs';
|
|
5
|
-
import '../../../ast-D-3bOanX.cjs';
|
|
2
|
+
import { T as TypeGraphIndex } from './types-C2rhqkg7.js';
|
|
3
|
+
import { S as SqliteTables } from './sqlite-CSJ-fgIm.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Table name configuration.
|
|
@@ -2396,25 +2394,27 @@ declare const embeddings: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
|
2396
2394
|
* Type representing the tables object returned by createPostgresTables.
|
|
2397
2395
|
*/
|
|
2398
2396
|
type PostgresTables = ReturnType<typeof createPostgresTables>;
|
|
2397
|
+
|
|
2399
2398
|
/**
|
|
2400
|
-
*
|
|
2401
|
-
*/
|
|
2402
|
-
type NodesTable = PostgresTables["nodes"];
|
|
2403
|
-
/**
|
|
2404
|
-
* Type for edges table.
|
|
2399
|
+
* Generates all DDL statements for the given SQLite tables.
|
|
2405
2400
|
*/
|
|
2406
|
-
|
|
2401
|
+
declare function generateSqliteDDL(tables?: SqliteTables): string[];
|
|
2407
2402
|
/**
|
|
2408
|
-
*
|
|
2403
|
+
* Generates a single SQL string for SQLite migrations.
|
|
2404
|
+
* Convenience function that joins all DDL statements.
|
|
2409
2405
|
*/
|
|
2410
|
-
|
|
2406
|
+
declare function generateSqliteMigrationSQL(tables?: SqliteTables): string;
|
|
2411
2407
|
/**
|
|
2412
|
-
*
|
|
2408
|
+
* Generates all DDL statements for the given PostgreSQL tables.
|
|
2413
2409
|
*/
|
|
2414
|
-
|
|
2410
|
+
declare function generatePostgresDDL(tables?: PostgresTables): string[];
|
|
2415
2411
|
/**
|
|
2416
|
-
*
|
|
2412
|
+
* Generates a single SQL string for PostgreSQL migrations.
|
|
2413
|
+
* Convenience function that joins all DDL statements.
|
|
2414
|
+
*
|
|
2415
|
+
* Includes CREATE EXTENSION for pgvector since the embeddings table
|
|
2416
|
+
* uses the native VECTOR type.
|
|
2417
2417
|
*/
|
|
2418
|
-
|
|
2418
|
+
declare function generatePostgresMigrationSQL(tables?: PostgresTables): string;
|
|
2419
2419
|
|
|
2420
|
-
export { type CreatePostgresTablesOptions
|
|
2420
|
+
export { type CreatePostgresTablesOptions as C, type PostgresTables as P, generateSqliteMigrationSQL as a, type PostgresTableNames as b, createPostgresTables as c, embeddings as d, edges as e, generatePostgresDDL as f, generateSqliteDDL as g, generatePostgresMigrationSQL as h, nodes as n, schemaVersions as s, tables as t, uniques as u };
|
|
@@ -378,4 +378,4 @@ declare function isConstraintError(error: unknown): boolean;
|
|
|
378
378
|
*/
|
|
379
379
|
declare function getErrorSuggestion(error: unknown): string | undefined;
|
|
380
380
|
|
|
381
|
-
export { CardinalityError as C, DatabaseOperationError as D, EdgeNotFoundError as E, KindNotFoundError as K, MigrationError as M, NodeConstraintNotFoundError as N, RestrictedDeleteError as R, SchemaMismatchError as S, TypeGraphError as T, UniquenessError as U,
|
|
381
|
+
export { CardinalityError as C, DatabaseOperationError as D, EdgeNotFoundError as E, KindNotFoundError as K, MigrationError as M, NodeConstraintNotFoundError as N, RestrictedDeleteError as R, SchemaMismatchError as S, TypeGraphError as T, UniquenessError as U, ValidationError as V, CompilerInvariantError as a, ConfigurationError as b, DisjointError as c, EndpointError as d, EndpointNotFoundError as e, type ErrorCategory as f, NodeNotFoundError as g, type TypeGraphErrorOptions as h, UnsupportedPredicateError as i, type ValidationErrorDetails as j, type ValidationIssue as k, VersionConflictError as l, getErrorSuggestion as m, isConstraintError as n, isSystemError as o, isTypeGraphError as p, isUserRecoverable as q };
|
|
@@ -378,4 +378,4 @@ declare function isConstraintError(error: unknown): boolean;
|
|
|
378
378
|
*/
|
|
379
379
|
declare function getErrorSuggestion(error: unknown): string | undefined;
|
|
380
380
|
|
|
381
|
-
export { CardinalityError as C, DatabaseOperationError as D, EdgeNotFoundError as E, KindNotFoundError as K, MigrationError as M, NodeConstraintNotFoundError as N, RestrictedDeleteError as R, SchemaMismatchError as S, TypeGraphError as T, UniquenessError as U,
|
|
381
|
+
export { CardinalityError as C, DatabaseOperationError as D, EdgeNotFoundError as E, KindNotFoundError as K, MigrationError as M, NodeConstraintNotFoundError as N, RestrictedDeleteError as R, SchemaMismatchError as S, TypeGraphError as T, UniquenessError as U, ValidationError as V, CompilerInvariantError as a, ConfigurationError as b, DisjointError as c, EndpointError as d, EndpointNotFoundError as e, type ErrorCategory as f, NodeNotFoundError as g, type TypeGraphErrorOptions as h, UnsupportedPredicateError as i, type ValidationErrorDetails as j, type ValidationIssue as k, VersionConflictError as l, getErrorSuggestion as m, isConstraintError as n, isSystemError as o, isTypeGraphError as p, isUserRecoverable as q };
|
package/dist/index.cjs
CHANGED
|
@@ -8547,6 +8547,23 @@ function createEdgeCollection(config) {
|
|
|
8547
8547
|
}
|
|
8548
8548
|
await deleteAll(backend);
|
|
8549
8549
|
},
|
|
8550
|
+
async findByEndpoints(from, to, options) {
|
|
8551
|
+
const findOptions = {};
|
|
8552
|
+
if (options?.matchOn !== void 0)
|
|
8553
|
+
findOptions.matchOn = options.matchOn;
|
|
8554
|
+
if (options?.props !== void 0)
|
|
8555
|
+
findOptions.props = options.props;
|
|
8556
|
+
const result = await config.executeFindByEndpoints(
|
|
8557
|
+
kind,
|
|
8558
|
+
from.kind,
|
|
8559
|
+
from.id,
|
|
8560
|
+
to.kind,
|
|
8561
|
+
to.id,
|
|
8562
|
+
backend,
|
|
8563
|
+
findOptions
|
|
8564
|
+
);
|
|
8565
|
+
return result === void 0 ? void 0 : narrowEdge(result);
|
|
8566
|
+
},
|
|
8550
8567
|
async getOrCreateByEndpoints(from, to, props, options) {
|
|
8551
8568
|
const getOrCreateOptions = {};
|
|
8552
8569
|
if (options?.matchOn !== void 0)
|
|
@@ -8637,7 +8654,9 @@ function createNodeCollection(config) {
|
|
|
8637
8654
|
matchesTemporalMode,
|
|
8638
8655
|
createQuery,
|
|
8639
8656
|
executeGetOrCreateByConstraint,
|
|
8640
|
-
executeBulkGetOrCreateByConstraint
|
|
8657
|
+
executeBulkGetOrCreateByConstraint,
|
|
8658
|
+
executeFindByConstraint,
|
|
8659
|
+
executeBulkFindByConstraint
|
|
8641
8660
|
} = config;
|
|
8642
8661
|
return {
|
|
8643
8662
|
async create(props, options) {
|
|
@@ -8886,6 +8905,30 @@ function createNodeCollection(config) {
|
|
|
8886
8905
|
}
|
|
8887
8906
|
await deleteAll(backend);
|
|
8888
8907
|
},
|
|
8908
|
+
async findByConstraint(constraintName, props) {
|
|
8909
|
+
const result = await executeFindByConstraint(
|
|
8910
|
+
kind,
|
|
8911
|
+
constraintName,
|
|
8912
|
+
props,
|
|
8913
|
+
backend
|
|
8914
|
+
);
|
|
8915
|
+
return result === void 0 ? void 0 : narrowNode(result);
|
|
8916
|
+
},
|
|
8917
|
+
async bulkFindByConstraint(constraintName, items) {
|
|
8918
|
+
if (items.length === 0) return [];
|
|
8919
|
+
const mappedItems = items.map((item) => ({
|
|
8920
|
+
props: item.props
|
|
8921
|
+
}));
|
|
8922
|
+
const results = await executeBulkFindByConstraint(
|
|
8923
|
+
kind,
|
|
8924
|
+
constraintName,
|
|
8925
|
+
mappedItems,
|
|
8926
|
+
backend
|
|
8927
|
+
);
|
|
8928
|
+
return results.map(
|
|
8929
|
+
(result) => result === void 0 ? void 0 : narrowNode(result)
|
|
8930
|
+
);
|
|
8931
|
+
},
|
|
8889
8932
|
async getOrCreateByConstraint(constraintName, props, options) {
|
|
8890
8933
|
const execute = async (target) => {
|
|
8891
8934
|
const result = await executeGetOrCreateByConstraint(
|
|
@@ -9746,6 +9789,28 @@ function findMatchingEdge(rows, matchOn, inputProps) {
|
|
|
9746
9789
|
}
|
|
9747
9790
|
return { liveRow, deletedRow };
|
|
9748
9791
|
}
|
|
9792
|
+
async function executeEdgeFindByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, backend, options) {
|
|
9793
|
+
const matchOn = options?.matchOn ?? [];
|
|
9794
|
+
const props = options?.props ?? {};
|
|
9795
|
+
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
9796
|
+
const edgeKind = registration.type;
|
|
9797
|
+
if (matchOn.length > 0) {
|
|
9798
|
+
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
9799
|
+
}
|
|
9800
|
+
const candidateRows = await backend.findEdgesByKind({
|
|
9801
|
+
graphId: ctx.graphId,
|
|
9802
|
+
kind,
|
|
9803
|
+
fromKind,
|
|
9804
|
+
fromId,
|
|
9805
|
+
toKind,
|
|
9806
|
+
toId,
|
|
9807
|
+
excludeDeleted: true
|
|
9808
|
+
});
|
|
9809
|
+
if (candidateRows.length === 0) return void 0;
|
|
9810
|
+
if (matchOn.length === 0) return rowToEdge(candidateRows[0]);
|
|
9811
|
+
const { liveRow } = findMatchingEdge(candidateRows, matchOn, props);
|
|
9812
|
+
return liveRow === void 0 ? void 0 : rowToEdge(liveRow);
|
|
9813
|
+
}
|
|
9749
9814
|
async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, props, backend, options) {
|
|
9750
9815
|
const ifExists = options?.ifExists ?? "return";
|
|
9751
9816
|
const matchOn = options?.matchOn ?? [];
|
|
@@ -10844,6 +10909,142 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
|
|
|
10844
10909
|
}
|
|
10845
10910
|
return { node: rowToNode(existingRow), action: "found" };
|
|
10846
10911
|
}
|
|
10912
|
+
async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
|
|
10913
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10914
|
+
const nodeKind = registration.type;
|
|
10915
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
10916
|
+
kind,
|
|
10917
|
+
operation: "create"
|
|
10918
|
+
});
|
|
10919
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10920
|
+
if (!checkWherePredicate(constraint, validatedProps)) return void 0;
|
|
10921
|
+
const key = computeUniqueKey(
|
|
10922
|
+
validatedProps,
|
|
10923
|
+
constraint.fields,
|
|
10924
|
+
constraint.collation
|
|
10925
|
+
);
|
|
10926
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10927
|
+
kind,
|
|
10928
|
+
constraint.scope,
|
|
10929
|
+
ctx.registry
|
|
10930
|
+
);
|
|
10931
|
+
let existingUniqueRow;
|
|
10932
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10933
|
+
const row = await backend.checkUnique({
|
|
10934
|
+
graphId: ctx.graphId,
|
|
10935
|
+
nodeKind: kindToCheck,
|
|
10936
|
+
constraintName: constraint.name,
|
|
10937
|
+
key,
|
|
10938
|
+
includeDeleted: false
|
|
10939
|
+
});
|
|
10940
|
+
if (row !== void 0) {
|
|
10941
|
+
existingUniqueRow = row;
|
|
10942
|
+
break;
|
|
10943
|
+
}
|
|
10944
|
+
}
|
|
10945
|
+
if (existingUniqueRow === void 0) return void 0;
|
|
10946
|
+
const existingRow = await backend.getNode(
|
|
10947
|
+
ctx.graphId,
|
|
10948
|
+
existingUniqueRow.concrete_kind,
|
|
10949
|
+
existingUniqueRow.node_id
|
|
10950
|
+
);
|
|
10951
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0)
|
|
10952
|
+
return void 0;
|
|
10953
|
+
return rowToNode(existingRow);
|
|
10954
|
+
}
|
|
10955
|
+
async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
|
|
10956
|
+
if (items.length === 0) return [];
|
|
10957
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10958
|
+
const nodeKind = registration.type;
|
|
10959
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10960
|
+
const validated = [];
|
|
10961
|
+
for (const item of items) {
|
|
10962
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, item.props, {
|
|
10963
|
+
kind,
|
|
10964
|
+
operation: "create"
|
|
10965
|
+
});
|
|
10966
|
+
const applies = checkWherePredicate(constraint, validatedProps);
|
|
10967
|
+
const key = applies ? computeUniqueKey(
|
|
10968
|
+
validatedProps,
|
|
10969
|
+
constraint.fields,
|
|
10970
|
+
constraint.collation
|
|
10971
|
+
) : void 0;
|
|
10972
|
+
validated.push({ validatedProps, key });
|
|
10973
|
+
}
|
|
10974
|
+
const uniqueKeys = [
|
|
10975
|
+
...new Set(
|
|
10976
|
+
validated.map((v) => v.key).filter((k) => k !== void 0)
|
|
10977
|
+
)
|
|
10978
|
+
];
|
|
10979
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10980
|
+
kind,
|
|
10981
|
+
constraint.scope,
|
|
10982
|
+
ctx.registry
|
|
10983
|
+
);
|
|
10984
|
+
const existingByKey = /* @__PURE__ */ new Map();
|
|
10985
|
+
if (uniqueKeys.length > 0) {
|
|
10986
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10987
|
+
if (backend.checkUniqueBatch === void 0) {
|
|
10988
|
+
for (const key of uniqueKeys) {
|
|
10989
|
+
if (existingByKey.has(key)) continue;
|
|
10990
|
+
const row = await backend.checkUnique({
|
|
10991
|
+
graphId: ctx.graphId,
|
|
10992
|
+
nodeKind: kindToCheck,
|
|
10993
|
+
constraintName: constraint.name,
|
|
10994
|
+
key,
|
|
10995
|
+
includeDeleted: false
|
|
10996
|
+
});
|
|
10997
|
+
if (row !== void 0) {
|
|
10998
|
+
existingByKey.set(row.key, row);
|
|
10999
|
+
}
|
|
11000
|
+
}
|
|
11001
|
+
} else {
|
|
11002
|
+
const rows = await backend.checkUniqueBatch({
|
|
11003
|
+
graphId: ctx.graphId,
|
|
11004
|
+
nodeKind: kindToCheck,
|
|
11005
|
+
constraintName: constraint.name,
|
|
11006
|
+
keys: uniqueKeys,
|
|
11007
|
+
includeDeleted: false
|
|
11008
|
+
});
|
|
11009
|
+
for (const row of rows) {
|
|
11010
|
+
if (!existingByKey.has(row.key)) {
|
|
11011
|
+
existingByKey.set(row.key, row);
|
|
11012
|
+
}
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
const results = Array.from({ length: items.length });
|
|
11018
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
11019
|
+
for (const [index, { key }] of validated.entries()) {
|
|
11020
|
+
if (key === void 0) {
|
|
11021
|
+
results[index] = void 0;
|
|
11022
|
+
continue;
|
|
11023
|
+
}
|
|
11024
|
+
const previousIndex = seenKeys.get(key);
|
|
11025
|
+
if (previousIndex !== void 0) {
|
|
11026
|
+
results[index] = results[previousIndex];
|
|
11027
|
+
continue;
|
|
11028
|
+
}
|
|
11029
|
+
seenKeys.set(key, index);
|
|
11030
|
+
const existing = existingByKey.get(key);
|
|
11031
|
+
if (existing === void 0) {
|
|
11032
|
+
results[index] = void 0;
|
|
11033
|
+
continue;
|
|
11034
|
+
}
|
|
11035
|
+
const existingRow = await backend.getNode(
|
|
11036
|
+
ctx.graphId,
|
|
11037
|
+
existing.concrete_kind,
|
|
11038
|
+
existing.node_id
|
|
11039
|
+
);
|
|
11040
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0) {
|
|
11041
|
+
results[index] = void 0;
|
|
11042
|
+
continue;
|
|
11043
|
+
}
|
|
11044
|
+
results[index] = rowToNode(existingRow);
|
|
11045
|
+
}
|
|
11046
|
+
return results;
|
|
11047
|
+
}
|
|
10847
11048
|
async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName, items, backend, options) {
|
|
10848
11049
|
if (items.length === 0) return [];
|
|
10849
11050
|
const ifExists = options?.ifExists ?? "return";
|
|
@@ -11123,6 +11324,14 @@ var Store = class {
|
|
|
11123
11324
|
items,
|
|
11124
11325
|
backend,
|
|
11125
11326
|
options
|
|
11327
|
+
),
|
|
11328
|
+
executeFindByConstraint: (kind, constraintName, props, backend) => executeNodeFindByConstraint(ctx, kind, constraintName, props, backend),
|
|
11329
|
+
executeBulkFindByConstraint: (kind, constraintName, items, backend) => executeNodeBulkFindByConstraint(
|
|
11330
|
+
ctx,
|
|
11331
|
+
kind,
|
|
11332
|
+
constraintName,
|
|
11333
|
+
items,
|
|
11334
|
+
backend
|
|
11126
11335
|
)
|
|
11127
11336
|
};
|
|
11128
11337
|
}
|
|
@@ -11160,6 +11369,16 @@ var Store = class {
|
|
|
11160
11369
|
items,
|
|
11161
11370
|
backend,
|
|
11162
11371
|
options
|
|
11372
|
+
),
|
|
11373
|
+
executeFindByEndpoints: (kind, fromKind, fromId, toKind, toId, backend, options) => executeEdgeFindByEndpoints(
|
|
11374
|
+
ctx,
|
|
11375
|
+
kind,
|
|
11376
|
+
fromKind,
|
|
11377
|
+
fromId,
|
|
11378
|
+
toKind,
|
|
11379
|
+
toId,
|
|
11380
|
+
backend,
|
|
11381
|
+
options
|
|
11163
11382
|
)
|
|
11164
11383
|
};
|
|
11165
11384
|
}
|
|
@@ -11227,6 +11446,24 @@ var Store = class {
|
|
|
11227
11446
|
return fn({ nodes, edges });
|
|
11228
11447
|
});
|
|
11229
11448
|
}
|
|
11449
|
+
// === Graph Lifecycle ===
|
|
11450
|
+
/**
|
|
11451
|
+
* Hard-deletes all data for this graph from the database.
|
|
11452
|
+
*
|
|
11453
|
+
* Removes all nodes, edges, uniqueness entries, embeddings, and schema versions
|
|
11454
|
+
* for this graph's ID. No hooks, no per-row logic. Wrapped in a transaction
|
|
11455
|
+
* when the backend supports it.
|
|
11456
|
+
*
|
|
11457
|
+
* The store is usable after clearing — new data can be created immediately.
|
|
11458
|
+
*/
|
|
11459
|
+
async clear() {
|
|
11460
|
+
const doClear = async (target) => {
|
|
11461
|
+
await target.clearGraph(this.graphId);
|
|
11462
|
+
};
|
|
11463
|
+
await (this.#backend.capabilities.transactions ? this.#backend.transaction(async (tx) => doClear(tx)) : doClear(this.#backend));
|
|
11464
|
+
this.#nodeCollections = void 0;
|
|
11465
|
+
this.#edgeCollections = void 0;
|
|
11466
|
+
}
|
|
11230
11467
|
// === Lifecycle ===
|
|
11231
11468
|
/**
|
|
11232
11469
|
* Closes the store and releases underlying resources.
|