@nicia-ai/typegraph 0.20.0 → 0.21.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/{ast-Bh2NDeaK.d.cts → ast-CSLbPIOC.d.ts} +56 -3
- package/dist/{ast-COMyNeMn.d.ts → ast-DogwbBqA.d.cts} +56 -3
- package/dist/backend/postgres/index.cjs +123 -45
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +15 -7
- package/dist/backend/postgres/index.d.ts +15 -7
- package/dist/backend/postgres/index.js +101 -23
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +15 -15
- package/dist/backend/sqlite/index.d.cts +11 -7
- package/dist/backend/sqlite/index.d.ts +11 -7
- package/dist/backend/sqlite/index.js +5 -5
- package/dist/backend/sqlite/libsql.cjs +8 -8
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +5 -5
- package/dist/backend/sqlite/local.cjs +9 -9
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +5 -5
- package/dist/{chunk-LELLOHJK.cjs → chunk-2X7P7AD5.cjs} +35 -35
- package/dist/{chunk-LELLOHJK.cjs.map → chunk-2X7P7AD5.cjs.map} +1 -1
- package/dist/{chunk-GNIYZKBI.js → chunk-4XNE2JG3.js} +376 -8
- package/dist/chunk-4XNE2JG3.js.map +1 -0
- package/dist/{chunk-HXJXTOXR.cjs → chunk-CQL6FOTT.cjs} +82 -21
- package/dist/chunk-CQL6FOTT.cjs.map +1 -0
- package/dist/{chunk-K7SQ3SWP.js → chunk-EYELZHKY.js} +120 -12
- package/dist/chunk-EYELZHKY.js.map +1 -0
- package/dist/{chunk-MME3H4ZF.cjs → chunk-FQCQM3KG.cjs} +385 -9
- package/dist/chunk-FQCQM3KG.cjs.map +1 -0
- package/dist/{chunk-X33WV2UF.cjs → chunk-HRNQ3DVJ.cjs} +24 -21
- package/dist/chunk-HRNQ3DVJ.cjs.map +1 -0
- package/dist/{chunk-W6M7XWKX.js → chunk-JYUQA77I.js} +21 -18
- package/dist/chunk-JYUQA77I.js.map +1 -0
- package/dist/{chunk-LLHFS53Q.js → chunk-NRNJ52AA.js} +72 -11
- package/dist/chunk-NRNJ52AA.js.map +1 -0
- package/dist/{chunk-IYWWXOVK.cjs → chunk-Q73OWTJY.cjs} +204 -89
- package/dist/chunk-Q73OWTJY.cjs.map +1 -0
- package/dist/{chunk-G5CYWKRF.js → chunk-RS5OLGEW.js} +2 -2
- package/dist/{chunk-G5CYWKRF.js.map → chunk-RS5OLGEW.js.map} +1 -1
- package/dist/{chunk-6GWJH6AR.js → chunk-SMMOAVJ5.js} +4 -4
- package/dist/{chunk-6GWJH6AR.js.map → chunk-SMMOAVJ5.js.map} +1 -1
- package/dist/{chunk-QFZQGEQ3.js → chunk-UQVBVBVG.js} +151 -36
- package/dist/chunk-UQVBVBVG.js.map +1 -0
- package/dist/{chunk-P5CNM325.cjs → chunk-UVZHTBZ5.cjs} +123 -11
- package/dist/chunk-UVZHTBZ5.cjs.map +1 -0
- package/dist/{chunk-5GZMPJOP.cjs → chunk-WRWVWKQL.cjs} +2 -2
- package/dist/{chunk-5GZMPJOP.cjs.map → chunk-WRWVWKQL.cjs.map} +1 -1
- package/dist/{ddl-BBo2EcFc.d.cts → ddl-BqkTShcR.d.ts} +28 -6
- package/dist/{ddl-D4jlcOH_.d.ts → ddl-Dk1NDN3M.d.cts} +28 -6
- package/dist/index.cjs +1705 -490
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +1552 -361
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +17 -17
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +3 -3
- package/dist/interchange/index.cjs +6 -6
- package/dist/interchange/index.d.cts +4 -5
- package/dist/interchange/index.d.ts +4 -5
- package/dist/interchange/index.js +1 -1
- package/dist/{manager-Chhrq1vl.d.ts → manager-0jVZtiE8.d.ts} +1 -2
- package/dist/{manager-Bj1UEnhE.d.cts → manager-BPK-2PUI.d.cts} +1 -2
- package/dist/profiler/index.cjs +15 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -8
- package/dist/profiler/index.d.ts +7 -8
- package/dist/profiler/index.js +8 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +21 -21
- package/dist/schema/index.d.cts +4 -5
- package/dist/schema/index.d.ts +4 -5
- package/dist/schema/index.js +3 -3
- package/dist/{sqlite-DE-6NWtC.d.cts → sqlite-D1rrwcir.d.cts} +14 -1
- package/dist/{sqlite-Blq-AhmK.d.ts → sqlite-W3rmJMlc.d.ts} +14 -1
- package/dist/{store-BMrRi_mY.d.ts → store-2QW2SIRk.d.cts} +404 -5
- package/dist/{store-DRRvALu8.d.cts → store-C0q13mtJ.d.ts} +404 -5
- package/dist/{types-B3mmOMJV.d.cts → types-CQF88McG.d.cts} +475 -2
- package/dist/{types-ThB4cFLp.d.ts → types-CQF88McG.d.ts} +475 -2
- package/dist/{types-COPePE8_.d.ts → types-CglvhPKz.d.ts} +1 -1
- package/dist/{types-CVtGFpB9.d.cts → types-D23slCOA.d.cts} +1 -1
- package/dist/{types-Ceb01czq.d.ts → types-IMQCuser.d.ts} +2 -2
- package/dist/{types-CZd2PEOc.d.cts → types-vgjar7Ch.d.cts} +2 -2
- package/package.json +9 -9
- package/dist/chunk-GNIYZKBI.js.map +0 -1
- package/dist/chunk-HXJXTOXR.cjs.map +0 -1
- package/dist/chunk-IYWWXOVK.cjs.map +0 -1
- package/dist/chunk-K7SQ3SWP.js.map +0 -1
- package/dist/chunk-LLHFS53Q.js.map +0 -1
- package/dist/chunk-MME3H4ZF.cjs.map +0 -1
- package/dist/chunk-P5CNM325.cjs.map +0 -1
- package/dist/chunk-QFZQGEQ3.js.map +0 -1
- package/dist/chunk-W6M7XWKX.js.map +0 -1
- package/dist/chunk-X33WV2UF.cjs.map +0 -1
- package/dist/types-DMzKq0d5.d.cts +0 -181
- package/dist/types-DMzKq0d5.d.ts +0 -181
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TemporalMode } from './types-
|
|
1
|
+
import { T as TemporalMode, j as FulltextQueryMode } from './types-CQF88McG.js';
|
|
2
2
|
|
|
3
3
|
declare const MAX_JSON_POINTER_DEPTH: 5;
|
|
4
4
|
type JsonPointer = string & {
|
|
@@ -233,10 +233,61 @@ type VectorSimilarityPredicate = Readonly<{
|
|
|
233
233
|
/** Optional minimum similarity score (0-1 for cosine) */
|
|
234
234
|
minScore?: number;
|
|
235
235
|
}>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A fulltext MATCH predicate.
|
|
239
|
+
*
|
|
240
|
+
* Finds nodes whose combined searchable content matches the query. Affects
|
|
241
|
+
* query execution by joining with the fulltext table, adding an ORDER BY
|
|
242
|
+
* on relevance rank (descending), and applying a LIMIT (top k).
|
|
243
|
+
*/
|
|
244
|
+
type FulltextMatchPredicate = Readonly<{
|
|
245
|
+
__type: "fulltext_match";
|
|
246
|
+
/**
|
|
247
|
+
* Reserved for forward compatibility with per-field fulltext dispatch.
|
|
248
|
+
* Today only `field.alias` is consumed: the MATCH always targets the
|
|
249
|
+
* combined `content` column, so `field.path` is a synthetic
|
|
250
|
+
* `["$fulltext"]` marker rather than a real props path. Future
|
|
251
|
+
* strategies (per-field indexes, `setweight()`-style boosts) can use
|
|
252
|
+
* the full `FieldRef` without breaking the AST shape.
|
|
253
|
+
*/
|
|
254
|
+
field: FieldRef;
|
|
255
|
+
/** The user-supplied query string. */
|
|
256
|
+
query: string;
|
|
257
|
+
/** Parse mode for the query string. Default: "websearch". */
|
|
258
|
+
mode: FulltextQueryMode;
|
|
259
|
+
/** Language override for query parsing. */
|
|
260
|
+
language?: string;
|
|
261
|
+
/** Maximum number of results to return. */
|
|
262
|
+
limit: number;
|
|
263
|
+
/** Minimum relevance to include (backend-native units). */
|
|
264
|
+
minScore?: number;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Fusion options for hybrid (vector + fulltext) queries.
|
|
268
|
+
*
|
|
269
|
+
* Shared between:
|
|
270
|
+
* - Query-builder path: `QueryBuilder.fuseWith()` stores this on `QueryAst`.
|
|
271
|
+
* - Store path: `store.search.hybrid(kind, { fusion })` accepts the same shape.
|
|
272
|
+
*
|
|
273
|
+
* Only applied when the query contains both a vector and a fulltext
|
|
274
|
+
* predicate. Defaults (when omitted): RRF with k=60 and equal weights.
|
|
275
|
+
*/
|
|
276
|
+
type HybridFusionOptions = Readonly<{
|
|
277
|
+
/** RRF is the only currently supported fusion method. */
|
|
278
|
+
method?: "rrf";
|
|
279
|
+
/** RRF constant. The classic value is 60. */
|
|
280
|
+
k?: number;
|
|
281
|
+
/** Per-source weights. Default: { vector: 1, fulltext: 1 }. */
|
|
282
|
+
weights?: Readonly<{
|
|
283
|
+
vector?: number;
|
|
284
|
+
fulltext?: number;
|
|
285
|
+
}>;
|
|
286
|
+
}>;
|
|
236
287
|
/**
|
|
237
288
|
* All predicate expression types.
|
|
238
289
|
*/
|
|
239
|
-
type PredicateExpression = ComparisonPredicate | StringPredicate | NullPredicate | BetweenPredicate | ArrayPredicate | ObjectPredicate | AndPredicate | OrPredicate | NotPredicate | AggregateComparisonPredicate | ExistsSubquery | InSubquery | VectorSimilarityPredicate;
|
|
290
|
+
type PredicateExpression = ComparisonPredicate | StringPredicate | NullPredicate | BetweenPredicate | ArrayPredicate | ObjectPredicate | AndPredicate | OrPredicate | NotPredicate | AggregateComparisonPredicate | ExistsSubquery | InSubquery | VectorSimilarityPredicate | FulltextMatchPredicate;
|
|
240
291
|
/**
|
|
241
292
|
* The starting point of a query (the FROM clause).
|
|
242
293
|
*/
|
|
@@ -419,6 +470,8 @@ type QueryAst = Readonly<{
|
|
|
419
470
|
* fields instead of the full props blob, enabling covered index usage.
|
|
420
471
|
*/
|
|
421
472
|
selectiveFields?: readonly SelectiveField[];
|
|
473
|
+
/** Fusion options for hybrid queries. Ignored unless both predicates present. */
|
|
474
|
+
fusion?: HybridFusionOptions;
|
|
422
475
|
}>;
|
|
423
476
|
/**
|
|
424
477
|
* Set operation types for combining queries.
|
|
@@ -441,4 +494,4 @@ type SetOperation = Readonly<{
|
|
|
441
494
|
*/
|
|
442
495
|
type ComposableQuery = QueryAst | SetOperation;
|
|
443
496
|
|
|
444
|
-
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
497
|
+
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type HybridFusionOptions as H, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TemporalMode } from './types-
|
|
1
|
+
import { T as TemporalMode, j as FulltextQueryMode } from './types-CQF88McG.cjs';
|
|
2
2
|
|
|
3
3
|
declare const MAX_JSON_POINTER_DEPTH: 5;
|
|
4
4
|
type JsonPointer = string & {
|
|
@@ -233,10 +233,61 @@ type VectorSimilarityPredicate = Readonly<{
|
|
|
233
233
|
/** Optional minimum similarity score (0-1 for cosine) */
|
|
234
234
|
minScore?: number;
|
|
235
235
|
}>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A fulltext MATCH predicate.
|
|
239
|
+
*
|
|
240
|
+
* Finds nodes whose combined searchable content matches the query. Affects
|
|
241
|
+
* query execution by joining with the fulltext table, adding an ORDER BY
|
|
242
|
+
* on relevance rank (descending), and applying a LIMIT (top k).
|
|
243
|
+
*/
|
|
244
|
+
type FulltextMatchPredicate = Readonly<{
|
|
245
|
+
__type: "fulltext_match";
|
|
246
|
+
/**
|
|
247
|
+
* Reserved for forward compatibility with per-field fulltext dispatch.
|
|
248
|
+
* Today only `field.alias` is consumed: the MATCH always targets the
|
|
249
|
+
* combined `content` column, so `field.path` is a synthetic
|
|
250
|
+
* `["$fulltext"]` marker rather than a real props path. Future
|
|
251
|
+
* strategies (per-field indexes, `setweight()`-style boosts) can use
|
|
252
|
+
* the full `FieldRef` without breaking the AST shape.
|
|
253
|
+
*/
|
|
254
|
+
field: FieldRef;
|
|
255
|
+
/** The user-supplied query string. */
|
|
256
|
+
query: string;
|
|
257
|
+
/** Parse mode for the query string. Default: "websearch". */
|
|
258
|
+
mode: FulltextQueryMode;
|
|
259
|
+
/** Language override for query parsing. */
|
|
260
|
+
language?: string;
|
|
261
|
+
/** Maximum number of results to return. */
|
|
262
|
+
limit: number;
|
|
263
|
+
/** Minimum relevance to include (backend-native units). */
|
|
264
|
+
minScore?: number;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Fusion options for hybrid (vector + fulltext) queries.
|
|
268
|
+
*
|
|
269
|
+
* Shared between:
|
|
270
|
+
* - Query-builder path: `QueryBuilder.fuseWith()` stores this on `QueryAst`.
|
|
271
|
+
* - Store path: `store.search.hybrid(kind, { fusion })` accepts the same shape.
|
|
272
|
+
*
|
|
273
|
+
* Only applied when the query contains both a vector and a fulltext
|
|
274
|
+
* predicate. Defaults (when omitted): RRF with k=60 and equal weights.
|
|
275
|
+
*/
|
|
276
|
+
type HybridFusionOptions = Readonly<{
|
|
277
|
+
/** RRF is the only currently supported fusion method. */
|
|
278
|
+
method?: "rrf";
|
|
279
|
+
/** RRF constant. The classic value is 60. */
|
|
280
|
+
k?: number;
|
|
281
|
+
/** Per-source weights. Default: { vector: 1, fulltext: 1 }. */
|
|
282
|
+
weights?: Readonly<{
|
|
283
|
+
vector?: number;
|
|
284
|
+
fulltext?: number;
|
|
285
|
+
}>;
|
|
286
|
+
}>;
|
|
236
287
|
/**
|
|
237
288
|
* All predicate expression types.
|
|
238
289
|
*/
|
|
239
|
-
type PredicateExpression = ComparisonPredicate | StringPredicate | NullPredicate | BetweenPredicate | ArrayPredicate | ObjectPredicate | AndPredicate | OrPredicate | NotPredicate | AggregateComparisonPredicate | ExistsSubquery | InSubquery | VectorSimilarityPredicate;
|
|
290
|
+
type PredicateExpression = ComparisonPredicate | StringPredicate | NullPredicate | BetweenPredicate | ArrayPredicate | ObjectPredicate | AndPredicate | OrPredicate | NotPredicate | AggregateComparisonPredicate | ExistsSubquery | InSubquery | VectorSimilarityPredicate | FulltextMatchPredicate;
|
|
240
291
|
/**
|
|
241
292
|
* The starting point of a query (the FROM clause).
|
|
242
293
|
*/
|
|
@@ -419,6 +470,8 @@ type QueryAst = Readonly<{
|
|
|
419
470
|
* fields instead of the full props blob, enabling covered index usage.
|
|
420
471
|
*/
|
|
421
472
|
selectiveFields?: readonly SelectiveField[];
|
|
473
|
+
/** Fusion options for hybrid queries. Ignored unless both predicates present. */
|
|
474
|
+
fusion?: HybridFusionOptions;
|
|
422
475
|
}>;
|
|
423
476
|
/**
|
|
424
477
|
* Set operation types for combining queries.
|
|
@@ -441,4 +494,4 @@ type SetOperation = Readonly<{
|
|
|
441
494
|
*/
|
|
442
495
|
type ComposableQuery = QueryAst | SetOperation;
|
|
443
496
|
|
|
444
|
-
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
497
|
+
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type HybridFusionOptions as H, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkQ73OWTJY_cjs = require('../../chunk-Q73OWTJY.cjs');
|
|
4
4
|
require('../../chunk-O5PST6TB.cjs');
|
|
5
|
-
require('../../chunk-
|
|
6
|
-
require('../../chunk-
|
|
7
|
-
require('../../chunk-
|
|
5
|
+
require('../../chunk-2X7P7AD5.cjs');
|
|
6
|
+
var chunkFQCQM3KG_cjs = require('../../chunk-FQCQM3KG.cjs');
|
|
7
|
+
require('../../chunk-UVZHTBZ5.cjs');
|
|
8
8
|
var drizzleOrm = require('drizzle-orm');
|
|
9
9
|
|
|
10
10
|
// src/backend/drizzle/execution/postgres-execution.ts
|
|
@@ -31,7 +31,7 @@ function createPgPreparedStatement(pgClient, sqlText) {
|
|
|
31
31
|
function createPostgresExecutionAdapter(db) {
|
|
32
32
|
const pgClient = resolvePgClient(db);
|
|
33
33
|
function compile(query) {
|
|
34
|
-
return
|
|
34
|
+
return chunkQ73OWTJY_cjs.compileQueryWithDialect(db, query, "PostgreSQL");
|
|
35
35
|
}
|
|
36
36
|
if (pgClient === void 0) {
|
|
37
37
|
return {
|
|
@@ -86,10 +86,10 @@ var POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(
|
|
|
86
86
|
1,
|
|
87
87
|
POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT
|
|
88
88
|
);
|
|
89
|
-
var toNodeRow =
|
|
90
|
-
var toEdgeRow =
|
|
91
|
-
var toUniqueRow =
|
|
92
|
-
var toSchemaVersionRow =
|
|
89
|
+
var toNodeRow = chunkQ73OWTJY_cjs.createNodeRowMapper(chunkQ73OWTJY_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
90
|
+
var toEdgeRow = chunkQ73OWTJY_cjs.createEdgeRowMapper(chunkQ73OWTJY_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
91
|
+
var toUniqueRow = chunkQ73OWTJY_cjs.createUniqueRowMapper(chunkQ73OWTJY_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
92
|
+
var toSchemaVersionRow = chunkQ73OWTJY_cjs.createSchemaVersionRowMapper(chunkQ73OWTJY_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
93
93
|
function toEmbeddingRow(row) {
|
|
94
94
|
let embedding;
|
|
95
95
|
if (typeof row.embedding === "string") {
|
|
@@ -107,39 +107,60 @@ function toEmbeddingRow(row) {
|
|
|
107
107
|
field_path: row.field_path,
|
|
108
108
|
embedding,
|
|
109
109
|
dimensions: row.dimensions,
|
|
110
|
-
created_at:
|
|
111
|
-
updated_at:
|
|
110
|
+
created_at: chunkQ73OWTJY_cjs.formatPostgresTimestamp(row.created_at) ?? "",
|
|
111
|
+
updated_at: chunkQ73OWTJY_cjs.formatPostgresTimestamp(row.updated_at) ?? ""
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// pgvector limit
|
|
114
|
+
function coerceNumericScore(value) {
|
|
115
|
+
if (typeof value === "number") return value;
|
|
116
|
+
const parsed = Number.parseFloat(value);
|
|
117
|
+
if (Number.isNaN(parsed)) {
|
|
118
|
+
throw new TypeError(
|
|
119
|
+
`Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`
|
|
120
|
+
);
|
|
122
121
|
}
|
|
123
|
-
|
|
122
|
+
return parsed;
|
|
123
|
+
}
|
|
124
|
+
function buildPostgresCapabilities(strategy) {
|
|
125
|
+
return {
|
|
126
|
+
...chunkQ73OWTJY_cjs.POSTGRES_CAPABILITIES,
|
|
127
|
+
vector: {
|
|
128
|
+
supported: true,
|
|
129
|
+
metrics: ["cosine", "l2", "inner_product"],
|
|
130
|
+
indexTypes: ["hnsw", "ivfflat", "none"],
|
|
131
|
+
maxDimensions: 16e3
|
|
132
|
+
// pgvector limit
|
|
133
|
+
},
|
|
134
|
+
fulltext: chunkFQCQM3KG_cjs.buildFulltextCapabilities(strategy)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
124
137
|
function createPostgresBackend(db, options = {}) {
|
|
125
|
-
const tables2 = options.tables ??
|
|
138
|
+
const tables2 = options.tables ?? chunkQ73OWTJY_cjs.tables;
|
|
139
|
+
const fulltextStrategy = options.fulltext ?? chunkFQCQM3KG_cjs.tsvectorStrategy;
|
|
140
|
+
const capabilities = buildPostgresCapabilities(fulltextStrategy);
|
|
126
141
|
const executionAdapter = createPostgresExecutionAdapter(db);
|
|
127
142
|
const tableNames = {
|
|
128
143
|
nodes: drizzleOrm.getTableName(tables2.nodes),
|
|
129
144
|
edges: drizzleOrm.getTableName(tables2.edges),
|
|
130
|
-
embeddings: drizzleOrm.getTableName(tables2.embeddings)
|
|
145
|
+
embeddings: drizzleOrm.getTableName(tables2.embeddings),
|
|
146
|
+
fulltext: tables2.fulltextTableName
|
|
131
147
|
};
|
|
132
|
-
const operationStrategy =
|
|
148
|
+
const operationStrategy = chunkQ73OWTJY_cjs.createPostgresOperationStrategy(
|
|
149
|
+
tables2,
|
|
150
|
+
fulltextStrategy
|
|
151
|
+
);
|
|
133
152
|
const operations = createPostgresOperationBackend({
|
|
134
153
|
db,
|
|
135
154
|
executionAdapter,
|
|
136
155
|
operationStrategy,
|
|
137
|
-
tableNames
|
|
156
|
+
tableNames,
|
|
157
|
+
capabilities,
|
|
158
|
+
fulltextStrategy
|
|
138
159
|
});
|
|
139
160
|
const backend = {
|
|
140
161
|
...operations,
|
|
141
162
|
async bootstrapTables() {
|
|
142
|
-
const statements =
|
|
163
|
+
const statements = chunkQ73OWTJY_cjs.generatePostgresDDL(tables2, fulltextStrategy);
|
|
143
164
|
for (const statement of statements) {
|
|
144
165
|
await db.execute(drizzleOrm.sql.raw(statement));
|
|
145
166
|
}
|
|
@@ -157,7 +178,9 @@ function createPostgresBackend(db, options = {}) {
|
|
|
157
178
|
const txBackend = createTransactionBackend({
|
|
158
179
|
db: tx,
|
|
159
180
|
operationStrategy,
|
|
160
|
-
tableNames
|
|
181
|
+
tableNames,
|
|
182
|
+
capabilities,
|
|
183
|
+
fulltextStrategy
|
|
161
184
|
});
|
|
162
185
|
return fn(txBackend);
|
|
163
186
|
}, txConfig);
|
|
@@ -168,7 +191,14 @@ function createPostgresBackend(db, options = {}) {
|
|
|
168
191
|
return backend;
|
|
169
192
|
}
|
|
170
193
|
function createPostgresOperationBackend(options) {
|
|
171
|
-
const {
|
|
194
|
+
const {
|
|
195
|
+
db,
|
|
196
|
+
executionAdapter,
|
|
197
|
+
operationStrategy,
|
|
198
|
+
tableNames,
|
|
199
|
+
capabilities,
|
|
200
|
+
fulltextStrategy
|
|
201
|
+
} = options;
|
|
172
202
|
async function execAll(query) {
|
|
173
203
|
const result = await db.execute(query);
|
|
174
204
|
return result.rows;
|
|
@@ -180,7 +210,7 @@ function createPostgresOperationBackend(options) {
|
|
|
180
210
|
async function execRun(query) {
|
|
181
211
|
await db.execute(query);
|
|
182
212
|
}
|
|
183
|
-
const commonBackend =
|
|
213
|
+
const commonBackend = chunkQ73OWTJY_cjs.createCommonOperationBackend({
|
|
184
214
|
batchConfig: {
|
|
185
215
|
checkUniqueBatchChunkSize: POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE,
|
|
186
216
|
edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,
|
|
@@ -193,7 +223,7 @@ function createPostgresOperationBackend(options) {
|
|
|
193
223
|
execGet,
|
|
194
224
|
execRun
|
|
195
225
|
},
|
|
196
|
-
nowIso:
|
|
226
|
+
nowIso: chunkQ73OWTJY_cjs.nowIso,
|
|
197
227
|
operationStrategy,
|
|
198
228
|
rowMappers: {
|
|
199
229
|
toEdgeRow,
|
|
@@ -211,12 +241,13 @@ function createPostgresOperationBackend(options) {
|
|
|
211
241
|
const operationBackend = {
|
|
212
242
|
...commonBackend,
|
|
213
243
|
...executeRawMethod,
|
|
214
|
-
capabilities
|
|
244
|
+
capabilities,
|
|
245
|
+
fulltextStrategy,
|
|
215
246
|
dialect: "postgres",
|
|
216
247
|
tableNames,
|
|
217
248
|
// === Embedding Operations ===
|
|
218
249
|
async upsertEmbedding(params) {
|
|
219
|
-
const timestamp =
|
|
250
|
+
const timestamp = chunkQ73OWTJY_cjs.nowIso();
|
|
220
251
|
const query = operationStrategy.buildUpsertEmbedding(params, timestamp);
|
|
221
252
|
await execRun(query);
|
|
222
253
|
},
|
|
@@ -255,23 +286,68 @@ function createPostgresOperationBackend(options) {
|
|
|
255
286
|
...params.indexParams?.efConstruction === void 0 ? {} : { hnswEfConstruction: params.indexParams.efConstruction },
|
|
256
287
|
...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists }
|
|
257
288
|
};
|
|
258
|
-
const result = await
|
|
289
|
+
const result = await chunkQ73OWTJY_cjs.createPostgresVectorIndex(db, indexOptions);
|
|
259
290
|
if (!result.success) {
|
|
260
291
|
throw new Error(
|
|
261
292
|
result.message ?? "Failed to create PostgreSQL vector index"
|
|
262
293
|
);
|
|
263
294
|
}
|
|
264
295
|
},
|
|
296
|
+
// === Fulltext Operations ===
|
|
297
|
+
async upsertFulltext(params) {
|
|
298
|
+
const timestamp = chunkQ73OWTJY_cjs.nowIso();
|
|
299
|
+
const statements = operationStrategy.buildUpsertFulltext(
|
|
300
|
+
params,
|
|
301
|
+
timestamp
|
|
302
|
+
);
|
|
303
|
+
for (const stmt of statements) {
|
|
304
|
+
await execRun(stmt);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
async deleteFulltext(params) {
|
|
308
|
+
const statements = operationStrategy.buildDeleteFulltext(params);
|
|
309
|
+
for (const stmt of statements) {
|
|
310
|
+
await execRun(stmt);
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
async upsertFulltextBatch(params) {
|
|
314
|
+
if (params.rows.length === 0) return;
|
|
315
|
+
const timestamp = chunkQ73OWTJY_cjs.nowIso();
|
|
316
|
+
const statements = operationStrategy.buildUpsertFulltextBatch(
|
|
317
|
+
params,
|
|
318
|
+
timestamp
|
|
319
|
+
);
|
|
320
|
+
for (const stmt of statements) {
|
|
321
|
+
await execRun(stmt);
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
async deleteFulltextBatch(params) {
|
|
325
|
+
if (params.nodeIds.length === 0) return;
|
|
326
|
+
const statements = operationStrategy.buildDeleteFulltextBatch(params);
|
|
327
|
+
for (const stmt of statements) {
|
|
328
|
+
await execRun(stmt);
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
async fulltextSearch(params) {
|
|
332
|
+
const query = operationStrategy.buildFulltextSearch(params);
|
|
333
|
+
const rows = await execAll(query);
|
|
334
|
+
return rows.map((row, index) => ({
|
|
335
|
+
nodeId: row.node_id,
|
|
336
|
+
score: coerceNumericScore(row.score),
|
|
337
|
+
rank: index + 1,
|
|
338
|
+
...row.snippet === null ? {} : { snippet: row.snippet }
|
|
339
|
+
}));
|
|
340
|
+
},
|
|
265
341
|
async dropVectorIndex(params) {
|
|
266
|
-
const metrics =
|
|
342
|
+
const metrics = capabilities.vector?.metrics ?? ["cosine"];
|
|
267
343
|
for (const metric of metrics) {
|
|
268
|
-
const indexName =
|
|
344
|
+
const indexName = chunkQ73OWTJY_cjs.generateVectorIndexName(
|
|
269
345
|
params.graphId,
|
|
270
346
|
params.nodeKind,
|
|
271
347
|
params.fieldPath,
|
|
272
348
|
metric
|
|
273
349
|
);
|
|
274
|
-
const result = await
|
|
350
|
+
const result = await chunkQ73OWTJY_cjs.dropPostgresVectorIndex(db, indexName);
|
|
275
351
|
if (!result.success) {
|
|
276
352
|
throw new Error(
|
|
277
353
|
result.message ?? "Failed to drop PostgreSQL vector index"
|
|
@@ -295,45 +371,47 @@ function createTransactionBackend(options) {
|
|
|
295
371
|
db: options.db,
|
|
296
372
|
executionAdapter: txExecutionAdapter,
|
|
297
373
|
operationStrategy: options.operationStrategy,
|
|
298
|
-
tableNames: options.tableNames
|
|
374
|
+
tableNames: options.tableNames,
|
|
375
|
+
capabilities: options.capabilities,
|
|
376
|
+
fulltextStrategy: options.fulltextStrategy
|
|
299
377
|
});
|
|
300
378
|
}
|
|
301
379
|
|
|
302
380
|
Object.defineProperty(exports, "createPostgresTables", {
|
|
303
381
|
enumerable: true,
|
|
304
|
-
get: function () { return
|
|
382
|
+
get: function () { return chunkQ73OWTJY_cjs.createPostgresTables; }
|
|
305
383
|
});
|
|
306
384
|
Object.defineProperty(exports, "edges", {
|
|
307
385
|
enumerable: true,
|
|
308
|
-
get: function () { return
|
|
386
|
+
get: function () { return chunkQ73OWTJY_cjs.edges; }
|
|
309
387
|
});
|
|
310
388
|
Object.defineProperty(exports, "embeddings", {
|
|
311
389
|
enumerable: true,
|
|
312
|
-
get: function () { return
|
|
390
|
+
get: function () { return chunkQ73OWTJY_cjs.embeddings; }
|
|
313
391
|
});
|
|
314
392
|
Object.defineProperty(exports, "generatePostgresDDL", {
|
|
315
393
|
enumerable: true,
|
|
316
|
-
get: function () { return
|
|
394
|
+
get: function () { return chunkQ73OWTJY_cjs.generatePostgresDDL; }
|
|
317
395
|
});
|
|
318
396
|
Object.defineProperty(exports, "generatePostgresMigrationSQL", {
|
|
319
397
|
enumerable: true,
|
|
320
|
-
get: function () { return
|
|
398
|
+
get: function () { return chunkQ73OWTJY_cjs.generatePostgresMigrationSQL; }
|
|
321
399
|
});
|
|
322
400
|
Object.defineProperty(exports, "nodes", {
|
|
323
401
|
enumerable: true,
|
|
324
|
-
get: function () { return
|
|
402
|
+
get: function () { return chunkQ73OWTJY_cjs.nodes; }
|
|
325
403
|
});
|
|
326
404
|
Object.defineProperty(exports, "schemaVersions", {
|
|
327
405
|
enumerable: true,
|
|
328
|
-
get: function () { return
|
|
406
|
+
get: function () { return chunkQ73OWTJY_cjs.schemaVersions; }
|
|
329
407
|
});
|
|
330
408
|
Object.defineProperty(exports, "tables", {
|
|
331
409
|
enumerable: true,
|
|
332
|
-
get: function () { return
|
|
410
|
+
get: function () { return chunkQ73OWTJY_cjs.tables; }
|
|
333
411
|
});
|
|
334
412
|
Object.defineProperty(exports, "uniques", {
|
|
335
413
|
enumerable: true,
|
|
336
|
-
get: function () { return
|
|
414
|
+
get: function () { return chunkQ73OWTJY_cjs.uniques; }
|
|
337
415
|
});
|
|
338
416
|
exports.createPostgresBackend = createPostgresBackend;
|
|
339
417
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/backend/drizzle/execution/postgres-execution.ts","../../../src/backend/drizzle/postgres.ts"],"names":["compileQueryWithDialect","createNodeRowMapper","POSTGRES_ROW_MAPPER_CONFIG","createEdgeRowMapper","createUniqueRowMapper","createSchemaVersionRowMapper","formatPostgresTimestamp","POSTGRES_CAPABILITIES","tables","getTableName","createPostgresOperationStrategy","generatePostgresDDL","sql","options","createCommonOperationBackend","nowIso","createPostgresVectorIndex","generateVectorIndexName","dropPostgresVectorIndex"],"mappings":";;;;;;;;;;AA0BA,SAAS,gBAAgB,EAAA,EAA8C;AACrE,EAAA,MAAM,kBAAA,GAAqB,EAAA;AAC3B,EAAA,MAAM,WAAW,kBAAA,CAAmB,OAAA;AACpC,EAAA,IAAI,QAAA,EAAU,UAAU,MAAA,EAAW;AACjC,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,QAAA;AACT;AAEA,eAAe,mBAAA,CACb,IACA,KAAA,EAC0B;AAC1B,EAAA,MAAM,MAAA,GAAU,MAAM,EAAA,CAAG,OAAA,CAAQ,KAAK,CAAA;AAGtC,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAEA,SAAS,yBAAA,CACP,UACA,OAAA,EACsB;AACtB,EAAA,OAAO;A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AM,MAAA,GAAS,MAAMC,yCAAA,CAAwB,EAAA,EAAI,SAAS,CAAA;AAC1D,QAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,OAAO,OAAA,IAAW;AAAA,WACpB;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAA;AAAA;AAAA,IAIA,MAAM,QAAW,KAAA,EAAmC;AAClD,MAAA,OAAO,gBAAA,CAAiB,QAAW,KAAK,CAAA;AAAA,IAC1C,CAAA;AAAA,IAEA,WAAW,KAAA,EAAmE;AAC5E,MAAA,OAAO,gBAAA,CAAiB,QAAQ,KAAK,CAAA;AAAA,IACvC;AAAA,GACF;AAEA,EAAA,OAAO,gBAAA;AACT;AAEA,SAAS,yBACP,OAAA,EACoB;AACpB,EAAA,MAAM,kBAAA,GACJ,OAAA,CAAQ,gBAAA,IAAoB,8BAAA,CAA+B,QAAQ,EAAE,CAAA;AAEvE,EAAA,OAAO,8BAAA,CAA+B;AAAA,IACpC,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":"index.cjs","sourcesContent":["import { type SQL } from \"drizzle-orm\";\nimport { type PgDatabase, type PgQueryResultHKT } from \"drizzle-orm/pg-core\";\n\nimport {\n type CompiledSqlQuery,\n compileQueryWithDialect,\n type PreparedSqlStatement,\n type SqlExecutionAdapter,\n} from \"./types\";\n\ntype PgQueryResult = Readonly<{\n rows: readonly unknown[];\n}>;\n\ntype PgQueryClient = Readonly<{\n query: (sqlText: string, params: readonly unknown[]) => Promise<PgQueryResult>;\n}>;\n\ntype PgClientCarrier = Readonly<{\n $client?: PgQueryClient;\n}>;\n\nexport type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;\n\nexport type PostgresExecutionAdapter = SqlExecutionAdapter;\n\nfunction resolvePgClient(db: AnyPgDatabase): PgQueryClient | undefined {\n const databaseWithClient = db as PgClientCarrier;\n const pgClient = databaseWithClient.$client;\n if (pgClient?.query === undefined) {\n return undefined;\n }\n return pgClient;\n}\n\nasync function executeDrizzleQuery<TRow>(\n db: AnyPgDatabase,\n query: SQL,\n): Promise<readonly TRow[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: readonly TRow[];\n }>;\n return result.rows;\n}\n\nfunction createPgPreparedStatement(\n pgClient: PgQueryClient,\n sqlText: string,\n): PreparedSqlStatement {\n return {\n async execute<TRow>(params: readonly unknown[]): Promise<readonly TRow[]> {\n const result = await pgClient.query(sqlText, params);\n return result.rows as readonly TRow[];\n },\n };\n}\n\nexport function createPostgresExecutionAdapter(\n db: AnyPgDatabase,\n): PostgresExecutionAdapter {\n const pgClient = resolvePgClient(db);\n\n function compile(query: SQL): CompiledSqlQuery {\n return compileQueryWithDialect(db, query, \"PostgreSQL\");\n }\n\n if (pgClient === undefined) {\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n };\n }\n\n const pgQueryClient = pgClient;\n\n async function executeCompiled<TRow>(\n compiledQuery: CompiledSqlQuery,\n ): Promise<readonly TRow[]> {\n const result = await pgQueryClient.query(\n compiledQuery.sql,\n compiledQuery.params,\n );\n return result.rows as readonly TRow[];\n }\n\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n executeCompiled,\n prepare(sqlText: string): PreparedSqlStatement {\n return createPgPreparedStatement(pgQueryClient, sqlText);\n },\n };\n}\n","/**\n * PostgreSQL backend adapter for TypeGraph.\n *\n * Works with any Drizzle PostgreSQL database instance:\n * - node-postgres (pg)\n * - PGlite\n * - Neon\n * - Vercel Postgres\n * - Supabase\n *\n * @example\n * ```typescript\n * import { drizzle } from \"drizzle-orm/node-postgres\";\n * import { Pool } from \"pg\";\n * import { createPostgresBackend, tables } from \"@nicia-ai/typegraph/postgres\";\n *\n * const pool = new Pool({ connectionString: process.env.DATABASE_URL });\n * const db = drizzle(pool);\n * const backend = createPostgresBackend(db, { tables });\n * ```\n */\nimport { getTableName, type SQL, sql } from \"drizzle-orm\";\n\nimport type { SqlTableNames } from \"../../query/compiler/schema\";\nimport {\n type BackendCapabilities,\n type CreateVectorIndexParams,\n type DeleteEmbeddingParams,\n type DropVectorIndexParams,\n type EmbeddingRow,\n type GraphBackend,\n POSTGRES_CAPABILITIES,\n type TransactionBackend,\n type TransactionOptions,\n type UpsertEmbeddingParams,\n type VectorSearchParams,\n type VectorSearchResult,\n} from \"../types\";\nimport { generatePostgresDDL } from \"./ddl\";\nimport {\n type AnyPgDatabase,\n createPostgresExecutionAdapter,\n type PostgresExecutionAdapter,\n} from \"./execution/postgres-execution\";\nimport { createCommonOperationBackend } from \"./operation-backend-core\";\nimport { createPostgresOperationStrategy } from \"./operations/strategy\";\nimport {\n createEdgeRowMapper,\n createNodeRowMapper,\n createSchemaVersionRowMapper,\n createUniqueRowMapper,\n formatPostgresTimestamp,\n nowIso,\n POSTGRES_ROW_MAPPER_CONFIG,\n} from \"./row-mappers\";\nimport {\n type PostgresTables,\n tables as defaultTables,\n} from \"./schema/postgres\";\nimport {\n createPostgresVectorIndex,\n dropPostgresVectorIndex,\n generateVectorIndexName,\n type VectorIndexOptions,\n} from \"./vector-index\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a PostgreSQL backend.\n */\nexport type PostgresBackendOptions = Readonly<{\n /**\n * Custom table definitions. Use createPostgresTables() to customize table names.\n * Defaults to standard TypeGraph table names.\n */\n tables?: PostgresTables;\n}>;\n\nconst POSTGRES_MAX_BIND_PARAMETERS = 65_535;\nconst NODE_INSERT_PARAM_COUNT = 9;\nconst EDGE_INSERT_PARAM_COUNT = 12;\nconst POSTGRES_NODE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 2,\n);\nconst POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 1,\n);\nconst CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT = 3;\nconst POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT,\n);\n\n// ============================================================\n// Utilities\n// ============================================================\n\nconst toNodeRow = createNodeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toEdgeRow = createEdgeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toUniqueRow = createUniqueRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toSchemaVersionRow = createSchemaVersionRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\n\n/**\n * Converts a database row to EmbeddingRow type.\n * Raw SQL returns snake_case column names.\n */\nfunction toEmbeddingRow(row: Record<string, unknown>): EmbeddingRow {\n // pgvector returns embedding as a string '[1,2,3]' or as parsed array\n let embedding: readonly number[];\n if (typeof row.embedding === \"string\") {\n const content = row.embedding.slice(1, -1);\n embedding = content === \"\" ? [] : content.split(\",\").map((s) => Number.parseFloat(s.trim()));\n } else if (Array.isArray(row.embedding)) {\n embedding = row.embedding as number[];\n } else {\n embedding = [];\n }\n\n return {\n graph_id: row.graph_id as string,\n node_kind: row.node_kind as string,\n node_id: row.node_id as string,\n field_path: row.field_path as string,\n embedding,\n dimensions: row.dimensions as number,\n created_at: formatPostgresTimestamp(row.created_at) ?? \"\",\n updated_at: formatPostgresTimestamp(row.updated_at) ?? \"\",\n };\n}\n\n/**\n * PostgreSQL capabilities with vector search support.\n * Extends base POSTGRES_CAPABILITIES with vector operations.\n */\nconst POSTGRES_VECTOR_CAPABILITIES: BackendCapabilities = {\n ...POSTGRES_CAPABILITIES,\n vector: {\n supported: true,\n metrics: [\"cosine\", \"l2\", \"inner_product\"] as const,\n indexTypes: [\"hnsw\", \"ivfflat\", \"none\"] as const,\n maxDimensions: 16_000, // pgvector limit\n },\n};\n\n// ============================================================\n// Backend Factory\n// ============================================================\n\n/**\n * Creates a TypeGraph backend for PostgreSQL databases.\n *\n * Works with any Drizzle PostgreSQL instance regardless of the underlying driver.\n *\n * @param db - A Drizzle PostgreSQL database instance\n * @param options - Backend configuration\n * @returns A GraphBackend implementation\n */\nexport function createPostgresBackend(\n db: AnyPgDatabase,\n options: PostgresBackendOptions = {},\n): GraphBackend {\n const tables = options.tables ?? defaultTables;\n const executionAdapter = createPostgresExecutionAdapter(db);\n const tableNames: SqlTableNames = {\n nodes: getTableName(tables.nodes),\n edges: getTableName(tables.edges),\n embeddings: getTableName(tables.embeddings),\n };\n const operationStrategy = createPostgresOperationStrategy(tables);\n const operations = createPostgresOperationBackend({\n db,\n executionAdapter,\n operationStrategy,\n tableNames,\n });\n\n const backend: GraphBackend = {\n ...operations,\n\n async bootstrapTables(): Promise<void> {\n const statements = generatePostgresDDL(tables);\n for (const statement of statements) {\n await db.execute(sql.raw(statement));\n }\n },\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 const txConfig = options?.isolationLevel\n ? {\n isolationLevel: options.isolationLevel.replace(\"_\", \" \") as\n | \"read uncommitted\"\n | \"read committed\"\n | \"repeatable read\"\n | \"serializable\",\n }\n : undefined;\n\n return db.transaction(async (tx) => {\n const txBackend = createTransactionBackend({\n db: tx as AnyPgDatabase,\n operationStrategy,\n tableNames,\n });\n return fn(txBackend);\n }, txConfig);\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\ntype CreatePostgresOperationBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n}>;\n\ntype CreatePostgresTransactionBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter?: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n}>;\n\nfunction createPostgresOperationBackend(\n options: CreatePostgresOperationBackendOptions,\n): TransactionBackend {\n const { db, executionAdapter, operationStrategy, tableNames } = options;\n\n async function execAll<T>(query: SQL): Promise<T[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows;\n }\n\n async function execGet<T>(query: SQL): Promise<T | undefined> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows[0];\n }\n\n async function execRun(query: SQL): Promise<void> {\n await db.execute(query);\n }\n\n const commonBackend = createCommonOperationBackend({\n batchConfig: {\n checkUniqueBatchChunkSize: POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE,\n edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,\n getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,\n getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,\n nodeInsertBatchSize: POSTGRES_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 async executeRaw<T>(\n sqlText: string,\n params: readonly unknown[],\n ): Promise<readonly T[]> {\n return executeCompiled<T>({ params, sql: sqlText });\n },\n };\n\n const operationBackend: TransactionBackend = {\n ...commonBackend,\n ...executeRawMethod,\n capabilities: POSTGRES_VECTOR_CAPABILITIES,\n dialect: \"postgres\",\n tableNames,\n\n // === Embedding Operations ===\n\n async upsertEmbedding(params: UpsertEmbeddingParams): Promise<void> {\n const timestamp = nowIso();\n const query = operationStrategy.buildUpsertEmbedding(params, timestamp);\n await execRun(query);\n },\n\n async deleteEmbedding(params: DeleteEmbeddingParams): Promise<void> {\n const query = operationStrategy.buildDeleteEmbedding(params);\n await execRun(query);\n },\n\n async getEmbedding(\n graphId: string,\n nodeKind: string,\n nodeId: string,\n fieldPath: string,\n ): Promise<EmbeddingRow | undefined> {\n const query = operationStrategy.buildGetEmbedding(\n graphId,\n nodeKind,\n nodeId,\n fieldPath,\n );\n const row = await execGet<Record<string, unknown>>(query);\n return row ? toEmbeddingRow(row) : undefined;\n },\n\n async vectorSearch(\n params: VectorSearchParams,\n ): Promise<readonly VectorSearchResult[]> {\n const query = operationStrategy.buildVectorSearch(params);\n const rows = await execAll<{ node_id: string; score: number }>(query);\n return rows.map((row) => ({\n nodeId: row.node_id,\n score: row.score,\n }));\n },\n\n async 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 embeddingsTableName: tableNames.embeddings,\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 = await createPostgresVectorIndex(db, indexOptions);\n\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to create PostgreSQL vector index\",\n );\n }\n },\n\n async dropVectorIndex(params: DropVectorIndexParams): Promise<void> {\n const metrics =\n POSTGRES_VECTOR_CAPABILITIES.vector?.metrics ?? ([\"cosine\"] as const);\n\n for (const metric of metrics) {\n const indexName = generateVectorIndexName(\n params.graphId,\n params.nodeKind,\n params.fieldPath,\n metric,\n );\n const result = await dropPostgresVectorIndex(db, indexName);\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to drop PostgreSQL vector index\",\n );\n }\n }\n },\n\n // === Query Execution ===\n\n async execute<T>(query: SQL): Promise<readonly T[]> {\n return executionAdapter.execute<T>(query);\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\nfunction createTransactionBackend(\n options: CreatePostgresTransactionBackendOptions,\n): TransactionBackend {\n const txExecutionAdapter =\n options.executionAdapter ?? createPostgresExecutionAdapter(options.db);\n\n return createPostgresOperationBackend({\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 { PostgresTableNames,PostgresTables } from \"./schema/postgres\";\nexport { createPostgresTables, tables } from \"./schema/postgres\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/backend/drizzle/execution/postgres-execution.ts","../../../src/backend/drizzle/postgres.ts"],"names":["compileQueryWithDialect","createNodeRowMapper","POSTGRES_ROW_MAPPER_CONFIG","createEdgeRowMapper","createUniqueRowMapper","createSchemaVersionRowMapper","formatPostgresTimestamp","POSTGRES_CAPABILITIES","buildFulltextCapabilities","tables","tsvectorStrategy","getTableName","createPostgresOperationStrategy","generatePostgresDDL","sql","options","createCommonOperationBackend","nowIso","createPostgresVectorIndex","generateVectorIndexName","dropPostgresVectorIndex"],"mappings":";;;;;;;;;;AA0BA,SAAS,gBA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GAC3B,CAAA;AACH","file":"index.cjs","sourcesContent":["import { type SQL } from \"drizzle-orm\";\nimport { type PgDatabase, type PgQueryResultHKT } from \"drizzle-orm/pg-core\";\n\nimport {\n type CompiledSqlQuery,\n compileQueryWithDialect,\n type PreparedSqlStatement,\n type SqlExecutionAdapter,\n} from \"./types\";\n\ntype PgQueryResult = Readonly<{\n rows: readonly unknown[];\n}>;\n\ntype PgQueryClient = Readonly<{\n query: (sqlText: string, params: readonly unknown[]) => Promise<PgQueryResult>;\n}>;\n\ntype PgClientCarrier = Readonly<{\n $client?: PgQueryClient;\n}>;\n\nexport type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;\n\nexport type PostgresExecutionAdapter = SqlExecutionAdapter;\n\nfunction resolvePgClient(db: AnyPgDatabase): PgQueryClient | undefined {\n const databaseWithClient = db as PgClientCarrier;\n const pgClient = databaseWithClient.$client;\n if (pgClient?.query === undefined) {\n return undefined;\n }\n return pgClient;\n}\n\nasync function executeDrizzleQuery<TRow>(\n db: AnyPgDatabase,\n query: SQL,\n): Promise<readonly TRow[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: readonly TRow[];\n }>;\n return result.rows;\n}\n\nfunction createPgPreparedStatement(\n pgClient: PgQueryClient,\n sqlText: string,\n): PreparedSqlStatement {\n return {\n async execute<TRow>(params: readonly unknown[]): Promise<readonly TRow[]> {\n const result = await pgClient.query(sqlText, params);\n return result.rows as readonly TRow[];\n },\n };\n}\n\nexport function createPostgresExecutionAdapter(\n db: AnyPgDatabase,\n): PostgresExecutionAdapter {\n const pgClient = resolvePgClient(db);\n\n function compile(query: SQL): CompiledSqlQuery {\n return compileQueryWithDialect(db, query, \"PostgreSQL\");\n }\n\n if (pgClient === undefined) {\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n };\n }\n\n const pgQueryClient = pgClient;\n\n async function executeCompiled<TRow>(\n compiledQuery: CompiledSqlQuery,\n ): Promise<readonly TRow[]> {\n const result = await pgQueryClient.query(\n compiledQuery.sql,\n compiledQuery.params,\n );\n return result.rows as readonly TRow[];\n }\n\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n executeCompiled,\n prepare(sqlText: string): PreparedSqlStatement {\n return createPgPreparedStatement(pgQueryClient, sqlText);\n },\n };\n}\n","/**\n * PostgreSQL backend adapter for TypeGraph.\n *\n * Works with any Drizzle PostgreSQL database instance:\n * - node-postgres (pg)\n * - PGlite\n * - Neon\n * - Vercel Postgres\n * - Supabase\n *\n * @example\n * ```typescript\n * import { drizzle } from \"drizzle-orm/node-postgres\";\n * import { Pool } from \"pg\";\n * import { createPostgresBackend, tables } from \"@nicia-ai/typegraph/postgres\";\n *\n * const pool = new Pool({ connectionString: process.env.DATABASE_URL });\n * const db = drizzle(pool);\n * const backend = createPostgresBackend(db, { tables });\n * ```\n */\nimport { getTableName, type SQL, sql } from \"drizzle-orm\";\n\nimport type { SqlTableNames } from \"../../query/compiler/schema\";\nimport {\n buildFulltextCapabilities,\n type FulltextStrategy,\n tsvectorStrategy,\n} from \"../../query/dialect/fulltext-strategy\";\nimport {\n type BackendCapabilities,\n type CreateVectorIndexParams,\n type DeleteEmbeddingParams,\n type DeleteFulltextBatchParams,\n type DeleteFulltextParams,\n type DropVectorIndexParams,\n type EmbeddingRow,\n type FulltextSearchParams,\n type FulltextSearchResult,\n type GraphBackend,\n POSTGRES_CAPABILITIES,\n type TransactionBackend,\n type TransactionOptions,\n type UpsertEmbeddingParams,\n type UpsertFulltextBatchParams,\n type UpsertFulltextParams,\n type VectorSearchParams,\n type VectorSearchResult,\n} from \"../types\";\nimport { generatePostgresDDL } from \"./ddl\";\nimport {\n type AnyPgDatabase,\n createPostgresExecutionAdapter,\n type PostgresExecutionAdapter,\n} from \"./execution/postgres-execution\";\nimport { createCommonOperationBackend } from \"./operation-backend-core\";\nimport { createPostgresOperationStrategy } from \"./operations/strategy\";\nimport {\n createEdgeRowMapper,\n createNodeRowMapper,\n createSchemaVersionRowMapper,\n createUniqueRowMapper,\n formatPostgresTimestamp,\n nowIso,\n POSTGRES_ROW_MAPPER_CONFIG,\n} from \"./row-mappers\";\nimport {\n type PostgresTables,\n tables as defaultTables,\n} from \"./schema/postgres\";\nimport {\n createPostgresVectorIndex,\n dropPostgresVectorIndex,\n generateVectorIndexName,\n type VectorIndexOptions,\n} from \"./vector-index\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a PostgreSQL backend.\n */\nexport type PostgresBackendOptions = Readonly<{\n /**\n * Custom table definitions. Use createPostgresTables() to customize table names.\n * Defaults to standard TypeGraph table names.\n */\n tables?: PostgresTables;\n /**\n * Fulltext strategy override. Defaults to `tsvectorStrategy`\n * (Postgres built-in `tsvector` + GIN). Pass a custom strategy here to\n * swap the entire fulltext stack — DDL, MATCH condition, rank\n * expression, and snippet generation — for alternate Postgres\n * backends like ParadeDB (`pg_search`), pg_trgm similarity, or\n * pgroonga without forking TypeGraph.\n */\n fulltext?: FulltextStrategy;\n}>;\n\nconst POSTGRES_MAX_BIND_PARAMETERS = 65_535;\nconst NODE_INSERT_PARAM_COUNT = 9;\nconst EDGE_INSERT_PARAM_COUNT = 12;\nconst POSTGRES_NODE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 2,\n);\nconst POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 1,\n);\nconst CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT = 3;\nconst POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - CHECK_UNIQUE_BATCH_FIXED_PARAM_COUNT,\n);\n\n// ============================================================\n// Utilities\n// ============================================================\n\nconst toNodeRow = createNodeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toEdgeRow = createEdgeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toUniqueRow = createUniqueRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toSchemaVersionRow = createSchemaVersionRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\n\n/**\n * Converts a database row to EmbeddingRow type.\n * Raw SQL returns snake_case column names.\n */\nfunction toEmbeddingRow(row: Record<string, unknown>): EmbeddingRow {\n // pgvector returns embedding as a string '[1,2,3]' or as parsed array\n let embedding: readonly number[];\n if (typeof row.embedding === \"string\") {\n const content = row.embedding.slice(1, -1);\n embedding = content === \"\" ? [] : content.split(\",\").map((s) => Number.parseFloat(s.trim()));\n } else if (Array.isArray(row.embedding)) {\n embedding = row.embedding as number[];\n } else {\n embedding = [];\n }\n\n return {\n graph_id: row.graph_id as string,\n node_kind: row.node_kind as string,\n node_id: row.node_id as string,\n field_path: row.field_path as string,\n embedding,\n dimensions: row.dimensions as number,\n created_at: formatPostgresTimestamp(row.created_at) ?? \"\",\n updated_at: formatPostgresTimestamp(row.updated_at) ?? \"\",\n };\n}\n\nfunction coerceNumericScore(value: number | string): number {\n if (typeof value === \"number\") return value;\n const parsed = Number.parseFloat(value);\n if (Number.isNaN(parsed)) {\n throw new TypeError(\n `Backend returned non-numeric fulltext score: ${JSON.stringify(value)}`,\n );\n }\n return parsed;\n}\n\nfunction buildPostgresCapabilities(\n strategy: FulltextStrategy,\n): BackendCapabilities {\n return {\n ...POSTGRES_CAPABILITIES,\n vector: {\n supported: true,\n metrics: [\"cosine\", \"l2\", \"inner_product\"] as const,\n indexTypes: [\"hnsw\", \"ivfflat\", \"none\"] as const,\n maxDimensions: 16_000, // pgvector limit\n },\n fulltext: buildFulltextCapabilities(strategy),\n };\n}\n\n// ============================================================\n// Backend Factory\n// ============================================================\n\n/**\n * Creates a TypeGraph backend for PostgreSQL databases.\n *\n * Works with any Drizzle PostgreSQL instance regardless of the underlying driver.\n *\n * @param db - A Drizzle PostgreSQL database instance\n * @param options - Backend configuration\n * @returns A GraphBackend implementation\n */\nexport function createPostgresBackend(\n db: AnyPgDatabase,\n options: PostgresBackendOptions = {},\n): GraphBackend {\n const tables = options.tables ?? defaultTables;\n const fulltextStrategy = options.fulltext ?? tsvectorStrategy;\n const capabilities = buildPostgresCapabilities(fulltextStrategy);\n const executionAdapter = createPostgresExecutionAdapter(db);\n const tableNames: SqlTableNames = {\n nodes: getTableName(tables.nodes),\n edges: getTableName(tables.edges),\n embeddings: getTableName(tables.embeddings),\n fulltext: tables.fulltextTableName,\n };\n const operationStrategy = createPostgresOperationStrategy(\n tables,\n fulltextStrategy,\n );\n const operations = createPostgresOperationBackend({\n db,\n executionAdapter,\n operationStrategy,\n tableNames,\n capabilities,\n fulltextStrategy,\n });\n\n const backend: GraphBackend = {\n ...operations,\n\n async bootstrapTables(): Promise<void> {\n const statements = generatePostgresDDL(tables, fulltextStrategy);\n for (const statement of statements) {\n await db.execute(sql.raw(statement));\n }\n },\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 const txConfig = options?.isolationLevel\n ? {\n isolationLevel: options.isolationLevel.replace(\"_\", \" \") as\n | \"read uncommitted\"\n | \"read committed\"\n | \"repeatable read\"\n | \"serializable\",\n }\n : undefined;\n\n return db.transaction(async (tx) => {\n const txBackend = createTransactionBackend({\n db: tx,\n operationStrategy,\n tableNames,\n capabilities,\n fulltextStrategy,\n });\n return fn(txBackend);\n }, txConfig);\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\ntype CreatePostgresOperationBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n capabilities: BackendCapabilities;\n fulltextStrategy: FulltextStrategy;\n}>;\n\ntype CreatePostgresTransactionBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter?: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n capabilities: BackendCapabilities;\n fulltextStrategy: FulltextStrategy;\n}>;\n\nfunction createPostgresOperationBackend(\n options: CreatePostgresOperationBackendOptions,\n): TransactionBackend {\n const {\n db,\n executionAdapter,\n operationStrategy,\n tableNames,\n capabilities,\n fulltextStrategy,\n } = options;\n\n async function execAll<T>(query: SQL): Promise<T[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows;\n }\n\n async function execGet<T>(query: SQL): Promise<T | undefined> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows[0];\n }\n\n async function execRun(query: SQL): Promise<void> {\n await db.execute(query);\n }\n\n const commonBackend = createCommonOperationBackend({\n batchConfig: {\n checkUniqueBatchChunkSize: POSTGRES_CHECK_UNIQUE_BATCH_CHUNK_SIZE,\n edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,\n getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,\n getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,\n nodeInsertBatchSize: POSTGRES_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 async executeRaw<T>(\n sqlText: string,\n params: readonly unknown[],\n ): Promise<readonly T[]> {\n return executeCompiled<T>({ params, sql: sqlText });\n },\n };\n\n const operationBackend: TransactionBackend = {\n ...commonBackend,\n ...executeRawMethod,\n capabilities,\n fulltextStrategy,\n dialect: \"postgres\",\n tableNames,\n\n // === Embedding Operations ===\n\n async upsertEmbedding(params: UpsertEmbeddingParams): Promise<void> {\n const timestamp = nowIso();\n const query = operationStrategy.buildUpsertEmbedding(params, timestamp);\n await execRun(query);\n },\n\n async deleteEmbedding(params: DeleteEmbeddingParams): Promise<void> {\n const query = operationStrategy.buildDeleteEmbedding(params);\n await execRun(query);\n },\n\n async getEmbedding(\n graphId: string,\n nodeKind: string,\n nodeId: string,\n fieldPath: string,\n ): Promise<EmbeddingRow | undefined> {\n const query = operationStrategy.buildGetEmbedding(\n graphId,\n nodeKind,\n nodeId,\n fieldPath,\n );\n const row = await execGet<Record<string, unknown>>(query);\n return row ? toEmbeddingRow(row) : undefined;\n },\n\n async vectorSearch(\n params: VectorSearchParams,\n ): Promise<readonly VectorSearchResult[]> {\n const query = operationStrategy.buildVectorSearch(params);\n const rows = await execAll<{ node_id: string; score: number }>(query);\n return rows.map((row) => ({\n nodeId: row.node_id,\n score: row.score,\n }));\n },\n\n async 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 embeddingsTableName: tableNames.embeddings,\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 = await createPostgresVectorIndex(db, indexOptions);\n\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to create PostgreSQL vector index\",\n );\n }\n },\n\n // === Fulltext Operations ===\n\n async upsertFulltext(params: UpsertFulltextParams): Promise<void> {\n const timestamp = nowIso();\n const statements = operationStrategy.buildUpsertFulltext(\n params,\n timestamp,\n );\n for (const stmt of statements) {\n await execRun(stmt);\n }\n },\n\n async deleteFulltext(params: DeleteFulltextParams): Promise<void> {\n const statements = operationStrategy.buildDeleteFulltext(params);\n for (const stmt of statements) {\n await execRun(stmt);\n }\n },\n\n async upsertFulltextBatch(\n params: UpsertFulltextBatchParams,\n ): Promise<void> {\n if (params.rows.length === 0) return;\n const timestamp = nowIso();\n const statements = operationStrategy.buildUpsertFulltextBatch(\n params,\n timestamp,\n );\n for (const stmt of statements) {\n await execRun(stmt);\n }\n },\n\n async deleteFulltextBatch(\n params: DeleteFulltextBatchParams,\n ): Promise<void> {\n if (params.nodeIds.length === 0) return;\n const statements = operationStrategy.buildDeleteFulltextBatch(params);\n for (const stmt of statements) {\n await execRun(stmt);\n }\n },\n\n async fulltextSearch(\n params: FulltextSearchParams,\n ): Promise<readonly FulltextSearchResult[]> {\n const query = operationStrategy.buildFulltextSearch(params);\n // pg returns `numeric` as a string to preserve precision; coerce at the\n // backend boundary so FulltextSearchResult.score is always `number`.\n const rows = await execAll<{\n node_id: string;\n score: number | string;\n snippet: string | null;\n }>(query);\n return rows.map((row, index) => ({\n nodeId: row.node_id,\n score: coerceNumericScore(row.score),\n rank: index + 1,\n ...(row.snippet === null ? {} : { snippet: row.snippet }),\n }));\n },\n\n async dropVectorIndex(params: DropVectorIndexParams): Promise<void> {\n const metrics = capabilities.vector?.metrics ?? ([\"cosine\"] as const);\n\n for (const metric of metrics) {\n const indexName = generateVectorIndexName(\n params.graphId,\n params.nodeKind,\n params.fieldPath,\n metric,\n );\n const result = await dropPostgresVectorIndex(db, indexName);\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to drop PostgreSQL vector index\",\n );\n }\n }\n },\n\n // === Query Execution ===\n\n async execute<T>(query: SQL): Promise<readonly T[]> {\n return executionAdapter.execute<T>(query);\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\nfunction createTransactionBackend(\n options: CreatePostgresTransactionBackendOptions,\n): TransactionBackend {\n const txExecutionAdapter =\n options.executionAdapter ?? createPostgresExecutionAdapter(options.db);\n\n return createPostgresOperationBackend({\n db: options.db,\n executionAdapter: txExecutionAdapter,\n operationStrategy: options.operationStrategy,\n tableNames: options.tableNames,\n capabilities: options.capabilities,\n fulltextStrategy: options.fulltextStrategy,\n });\n}\n\n// Re-export schema utilities\nexport type { PostgresTableNames,PostgresTables } from \"./schema/postgres\";\nexport { createPostgresTables, tables } from \"./schema/postgres\";\n"]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { G as GraphBackend } from '../../types-
|
|
1
|
+
import { m as FulltextStrategy, G as GraphBackend } from '../../types-CQF88McG.cjs';
|
|
2
2
|
import { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { P as PostgresTables } from '../../ddl-
|
|
4
|
-
export { C as CreatePostgresTablesOptions, b as PostgresTableNames, c as createPostgresTables, e as edges, d as embeddings, f as generatePostgresDDL, h as generatePostgresMigrationSQL, n as nodes, s as schemaVersions, t as tables, u as uniques } from '../../ddl-
|
|
3
|
+
import { P as PostgresTables } from '../../ddl-Dk1NDN3M.cjs';
|
|
4
|
+
export { C as CreatePostgresTablesOptions, b as PostgresTableNames, c as createPostgresTables, e as edges, d as embeddings, f as generatePostgresDDL, h as generatePostgresMigrationSQL, n as nodes, s as schemaVersions, t as tables, u as uniques } from '../../ddl-Dk1NDN3M.cjs';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
|
-
import '../../types-DMzKq0d5.cjs';
|
|
7
6
|
import 'zod';
|
|
8
|
-
import '../../types-
|
|
9
|
-
import '../../ast-
|
|
10
|
-
import '../../sqlite-
|
|
7
|
+
import '../../types-vgjar7Ch.cjs';
|
|
8
|
+
import '../../ast-DogwbBqA.cjs';
|
|
9
|
+
import '../../sqlite-D1rrwcir.cjs';
|
|
11
10
|
import 'drizzle-orm/sqlite-core';
|
|
12
11
|
|
|
13
12
|
type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
|
|
@@ -21,6 +20,15 @@ type PostgresBackendOptions = Readonly<{
|
|
|
21
20
|
* Defaults to standard TypeGraph table names.
|
|
22
21
|
*/
|
|
23
22
|
tables?: PostgresTables;
|
|
23
|
+
/**
|
|
24
|
+
* Fulltext strategy override. Defaults to `tsvectorStrategy`
|
|
25
|
+
* (Postgres built-in `tsvector` + GIN). Pass a custom strategy here to
|
|
26
|
+
* swap the entire fulltext stack — DDL, MATCH condition, rank
|
|
27
|
+
* expression, and snippet generation — for alternate Postgres
|
|
28
|
+
* backends like ParadeDB (`pg_search`), pg_trgm similarity, or
|
|
29
|
+
* pgroonga without forking TypeGraph.
|
|
30
|
+
*/
|
|
31
|
+
fulltext?: FulltextStrategy;
|
|
24
32
|
}>;
|
|
25
33
|
/**
|
|
26
34
|
* Creates a TypeGraph backend for PostgreSQL databases.
|