@nicia-ai/typegraph 0.24.1 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/postgres/index.cjs +178 -55
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +6 -7
- package/dist/backend/postgres/index.d.ts +6 -7
- package/dist/backend/postgres/index.js +151 -28
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +19 -17
- package/dist/backend/sqlite/index.d.cts +6 -7
- package/dist/backend/sqlite/index.d.ts +6 -7
- package/dist/backend/sqlite/index.js +9 -7
- package/dist/backend/sqlite/libsql.cjs +12 -10
- package/dist/backend/sqlite/libsql.cjs.map +1 -1
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +9 -7
- package/dist/backend/sqlite/libsql.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +14 -12
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +9 -7
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/chunk-4BOWVUGQ.js +2029 -0
- package/dist/chunk-4BOWVUGQ.js.map +1 -0
- package/dist/{chunk-SUHW2UYL.cjs → chunk-7CDXX3QZ.cjs} +2 -2
- package/dist/chunk-7CDXX3QZ.cjs.map +1 -0
- package/dist/chunk-7V335GHG.cjs +112 -0
- package/dist/chunk-7V335GHG.cjs.map +1 -0
- package/dist/chunk-7W3KAMVQ.cjs +2678 -0
- package/dist/chunk-7W3KAMVQ.cjs.map +1 -0
- package/dist/chunk-CTHNVU6K.cjs +551 -0
- package/dist/chunk-CTHNVU6K.cjs.map +1 -0
- package/dist/chunk-D2GO3RBL.cjs +12 -0
- package/dist/chunk-D2GO3RBL.cjs.map +1 -0
- package/dist/{chunk-WFMTAEEN.js → chunk-DOTEN2FG.js} +81 -7
- package/dist/chunk-DOTEN2FG.js.map +1 -0
- package/dist/chunk-E5JZSEGJ.cjs +301 -0
- package/dist/chunk-E5JZSEGJ.cjs.map +1 -0
- package/dist/chunk-EG6TJ3I5.js +286 -0
- package/dist/chunk-EG6TJ3I5.js.map +1 -0
- package/dist/chunk-EJCDOA37.js +537 -0
- package/dist/chunk-EJCDOA37.js.map +1 -0
- package/dist/{chunk-UVZHTBZ5.cjs → chunk-EK6RJ373.cjs} +7 -150
- package/dist/chunk-EK6RJ373.cjs.map +1 -0
- package/dist/{chunk-GUTQTMOV.js → chunk-FPCOUJSL.js} +2 -2
- package/dist/chunk-FPCOUJSL.js.map +1 -0
- package/dist/{chunk-3JK66E3I.cjs → chunk-JTI5WT4P.cjs} +630 -59
- package/dist/chunk-JTI5WT4P.cjs.map +1 -0
- package/dist/chunk-LVCSL6A3.js +2626 -0
- package/dist/chunk-LVCSL6A3.js.map +1 -0
- package/dist/chunk-NHQWXSTS.js +10 -0
- package/dist/chunk-NHQWXSTS.js.map +1 -0
- package/dist/chunk-NZ5PMBTG.js +105 -0
- package/dist/chunk-NZ5PMBTG.js.map +1 -0
- package/dist/{chunk-5HVDOPZU.cjs → chunk-O2P3KAUT.cjs} +416 -93
- package/dist/chunk-O2P3KAUT.cjs.map +1 -0
- package/dist/{chunk-QOLTW7OZ.js → chunk-OJ6IQVZG.js} +151 -13
- package/dist/chunk-OJ6IQVZG.js.map +1 -0
- package/dist/{chunk-EYELZHKY.js → chunk-OOS2RKRH.js} +5 -140
- package/dist/chunk-OOS2RKRH.js.map +1 -0
- package/dist/chunk-RCAJZG67.cjs +2069 -0
- package/dist/chunk-RCAJZG67.cjs.map +1 -0
- package/dist/{chunk-O5PST6TB.cjs → chunk-W5MTHMTE.cjs} +83 -6
- package/dist/chunk-W5MTHMTE.cjs.map +1 -0
- package/dist/{chunk-EY4LBX3F.js → chunk-WI5VRP3X.js} +337 -26
- package/dist/chunk-WI5VRP3X.js.map +1 -0
- package/dist/chunk-WVQXAFP3.js +79 -0
- package/dist/chunk-WVQXAFP3.js.map +1 -0
- package/dist/chunk-X3244EKP.cjs +84 -0
- package/dist/chunk-X3244EKP.cjs.map +1 -0
- package/dist/{chunk-753F33CV.js → chunk-YZZBDCLV.js} +617 -44
- package/dist/chunk-YZZBDCLV.js.map +1 -0
- package/dist/{chunk-OVJ2BE5Q.cjs → chunk-ZEMNF3QK.cjs} +171 -33
- package/dist/chunk-ZEMNF3QK.cjs.map +1 -0
- package/dist/{ddl-B_H8JM-E.d.cts → ddl-B2jjLjpR.d.cts} +762 -99
- package/dist/{ddl-1tFIvt9V.d.ts → ddl-DpaeAKPp.d.ts} +762 -99
- package/dist/extension-types-D07e_NTw.d.cts +543 -0
- package/dist/extension-types-D07e_NTw.d.ts +543 -0
- package/dist/graph-extension/index.cjs +71 -0
- package/dist/graph-extension/index.cjs.map +1 -0
- package/dist/graph-extension/index.d.cts +278 -0
- package/dist/graph-extension/index.d.ts +278 -0
- package/dist/graph-extension/index.js +6 -0
- package/dist/graph-extension/index.js.map +1 -0
- package/dist/{index-DXkEXpNz.d.ts → index-CT6nvtxL.d.cts} +114 -5
- package/dist/{index-DXkEXpNz.d.cts → index-DQheiVQV.d.ts} +114 -5
- package/dist/index.cjs +2672 -901
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.js +2248 -598
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +25 -23
- package/dist/indexes/index.d.cts +40 -22
- package/dist/indexes/index.d.ts +40 -22
- package/dist/indexes/index.js +5 -3
- package/dist/interchange/index.cjs +8 -7
- package/dist/interchange/index.cjs.map +1 -1
- package/dist/interchange/index.d.cts +5 -4
- package/dist/interchange/index.d.ts +5 -4
- package/dist/interchange/index.js +3 -2
- package/dist/interchange/index.js.map +1 -1
- package/dist/{manager-nIhmttD-.d.ts → manager-BKaPQbns.d.ts} +189 -6
- package/dist/{manager-Vkz28eAC.d.cts → manager-BpjBW1JK.d.cts} +189 -6
- package/dist/materialize-indexes-BB9N5uQl.d.cts +68 -0
- package/dist/materialize-indexes-BYpU2RKh.d.ts +68 -0
- package/dist/profiler/index.cjs +10 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +8 -7
- package/dist/profiler/index.d.ts +8 -7
- package/dist/profiler/index.js +3 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +43 -22
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +17 -8
- package/dist/schema/index.d.ts +17 -8
- package/dist/schema/index.js +9 -4
- package/dist/schema/index.js.map +1 -1
- package/dist/{sqlite-D0aceIe0.d.cts → sqlite-CU3j6rc7.d.ts} +837 -120
- package/dist/{sqlite-SUxbZqfy.d.ts → sqlite-Myo8e3Lr.d.cts} +837 -120
- package/dist/{store-U3i2tUch.d.ts → store-BAGuOHDh.d.cts} +659 -23
- package/dist/{store-CpvwTMxV.d.cts → store-De98Lod4.d.ts} +659 -23
- package/dist/types--0EslBx5.d.cts +2123 -0
- package/dist/{types-qYFZ9SqD.d.ts → types-BLmJq4wI.d.ts} +3 -2
- package/dist/types-BNWYZ-0-.d.ts +2123 -0
- package/dist/{types-yH4_p0XB.d.cts → types-CYga3lZp.d.cts} +3 -2
- package/dist/where-CluR73rs.d.ts +11 -0
- package/dist/where-m1uWsdua.d.cts +11 -0
- package/package.json +33 -73
- package/dist/ast-C8S37w1A.d.ts +0 -497
- package/dist/ast-dgLhLOg0.d.cts +0 -497
- package/dist/chunk-3JK66E3I.cjs.map +0 -1
- package/dist/chunk-3PPEHLGK.js +0 -1116
- package/dist/chunk-3PPEHLGK.js.map +0 -1
- package/dist/chunk-5HVDOPZU.cjs.map +0 -1
- package/dist/chunk-753F33CV.js.map +0 -1
- package/dist/chunk-EY4LBX3F.js.map +0 -1
- package/dist/chunk-EYELZHKY.js.map +0 -1
- package/dist/chunk-GFGVREHH.js +0 -1381
- package/dist/chunk-GFGVREHH.js.map +0 -1
- package/dist/chunk-GUTQTMOV.js.map +0 -1
- package/dist/chunk-LBORRUNJ.js +0 -135
- package/dist/chunk-LBORRUNJ.js.map +0 -1
- package/dist/chunk-O5PST6TB.cjs.map +0 -1
- package/dist/chunk-OLROXS2S.cjs +0 -147
- package/dist/chunk-OLROXS2S.cjs.map +0 -1
- package/dist/chunk-OVJ2BE5Q.cjs.map +0 -1
- package/dist/chunk-PAUN562Y.cjs +0 -1417
- package/dist/chunk-PAUN562Y.cjs.map +0 -1
- package/dist/chunk-PEE4EWXZ.cjs +0 -1131
- package/dist/chunk-PEE4EWXZ.cjs.map +0 -1
- package/dist/chunk-QOLTW7OZ.js.map +0 -1
- package/dist/chunk-SUHW2UYL.cjs.map +0 -1
- package/dist/chunk-UVZHTBZ5.cjs.map +0 -1
- package/dist/chunk-WFMTAEEN.js.map +0 -1
- package/dist/types-C-zfYDJB.d.ts +0 -159
- package/dist/types-CQx4iW5Y.d.cts +0 -159
- package/dist/types-Qk2l3IkQ.d.cts +0 -1254
- package/dist/types-Qk2l3IkQ.d.ts +0 -1254
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { parseJsonPointer } from './chunk-
|
|
1
|
+
import { parseJsonPointer, jsonPointer } from './chunk-NZ5PMBTG.js';
|
|
2
2
|
import { sql } from 'drizzle-orm';
|
|
3
|
+
import { CasingCache } from 'drizzle-orm/casing';
|
|
4
|
+
import { uniqueIndex, index } from 'drizzle-orm/pg-core';
|
|
5
|
+
import { uniqueIndex as uniqueIndex$1, index as index$1 } from 'drizzle-orm/sqlite-core';
|
|
3
6
|
|
|
4
7
|
function sqlNull(value) {
|
|
5
8
|
return value ?? sql.raw("NULL");
|
|
@@ -358,21 +361,6 @@ var fts5Strategy = {
|
|
|
358
361
|
return stmt === void 0 ? [] : [stmt];
|
|
359
362
|
}
|
|
360
363
|
};
|
|
361
|
-
|
|
362
|
-
// src/constants.ts
|
|
363
|
-
var MAX_PG_IDENTIFIER_LENGTH = 63;
|
|
364
|
-
var TRUNCATED_IDENTIFIER_MAX_LENGTH = 54;
|
|
365
|
-
var IDENTIFIER_COMPONENT_MAX_LENGTH = 20;
|
|
366
|
-
var FNV1A_OFFSET_BASIS = 2166136261;
|
|
367
|
-
var FNV1A_PRIME = 16777619;
|
|
368
|
-
var DEFAULT_PAGINATION_LIMIT = 20;
|
|
369
|
-
var DEFAULT_STREAM_BATCH_SIZE = 1e3;
|
|
370
|
-
var NODE_INDEX_TYPE_MARKER = "typegraph_node_index";
|
|
371
|
-
var EDGE_INDEX_TYPE_MARKER = "typegraph_edge_index";
|
|
372
|
-
var SQLITE_PATH_DELIMITER = "|";
|
|
373
|
-
var PG_PATH_ELEMENT_SEPARATOR = ",";
|
|
374
|
-
var PG_ARRAY_START = "{";
|
|
375
|
-
var PG_ARRAY_END = "}";
|
|
376
364
|
function escapePostgresLiteral(value) {
|
|
377
365
|
return `'${value.replaceAll("'", "''")}'`;
|
|
378
366
|
}
|
|
@@ -740,36 +728,621 @@ var DIALECT_ADAPTERS = {
|
|
|
740
728
|
function getDialect(dialect) {
|
|
741
729
|
return DIALECT_ADAPTERS[dialect];
|
|
742
730
|
}
|
|
731
|
+
function compileNodeIndexKeys(index, dialect, propsColumn, systemColumn) {
|
|
732
|
+
const adapter = getDialect(dialect);
|
|
733
|
+
const keys = [];
|
|
734
|
+
for (const column of getNodeScopeColumns(index.scope)) {
|
|
735
|
+
keys.push(systemColumn(column));
|
|
736
|
+
}
|
|
737
|
+
const allPointers = [...index.fields, ...index.coveringFields];
|
|
738
|
+
const allValueTypes = [
|
|
739
|
+
...index.fieldValueTypes,
|
|
740
|
+
...index.coveringFieldValueTypes
|
|
741
|
+
];
|
|
742
|
+
for (const [pointerIndex, pointer] of allPointers.entries()) {
|
|
743
|
+
const valueType = allValueTypes[pointerIndex];
|
|
744
|
+
const extracted = compileIndexKeyValue(
|
|
745
|
+
adapter,
|
|
746
|
+
propsColumn,
|
|
747
|
+
pointer,
|
|
748
|
+
valueType
|
|
749
|
+
);
|
|
750
|
+
keys.push(sql`(${extracted})`);
|
|
751
|
+
}
|
|
752
|
+
return { keys };
|
|
753
|
+
}
|
|
754
|
+
function compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn) {
|
|
755
|
+
const adapter = getDialect(dialect);
|
|
756
|
+
const keys = [];
|
|
757
|
+
for (const column of getEdgeScopeColumns(index.scope, index.direction)) {
|
|
758
|
+
keys.push(systemColumn(column));
|
|
759
|
+
}
|
|
760
|
+
const allPointers = [...index.fields, ...index.coveringFields];
|
|
761
|
+
const allValueTypes = [
|
|
762
|
+
...index.fieldValueTypes,
|
|
763
|
+
...index.coveringFieldValueTypes
|
|
764
|
+
];
|
|
765
|
+
for (const [pointerIndex, pointer] of allPointers.entries()) {
|
|
766
|
+
const valueType = allValueTypes[pointerIndex];
|
|
767
|
+
const extracted = compileIndexKeyValue(
|
|
768
|
+
adapter,
|
|
769
|
+
propsColumn,
|
|
770
|
+
pointer,
|
|
771
|
+
valueType
|
|
772
|
+
);
|
|
773
|
+
keys.push(sql`(${extracted})`);
|
|
774
|
+
}
|
|
775
|
+
return { keys };
|
|
776
|
+
}
|
|
777
|
+
function compileIndexKeyValue(dialect, propsColumn, pointer, valueType) {
|
|
778
|
+
switch (valueType) {
|
|
779
|
+
case "number": {
|
|
780
|
+
return dialect.jsonExtractNumber(propsColumn, pointer);
|
|
781
|
+
}
|
|
782
|
+
case "boolean": {
|
|
783
|
+
return dialect.jsonExtractBoolean(propsColumn, pointer);
|
|
784
|
+
}
|
|
785
|
+
case "date": {
|
|
786
|
+
return dialect.jsonExtractDate(propsColumn, pointer);
|
|
787
|
+
}
|
|
788
|
+
case "string":
|
|
789
|
+
case "unknown":
|
|
790
|
+
case void 0: {
|
|
791
|
+
return dialect.jsonExtractText(propsColumn, pointer);
|
|
792
|
+
}
|
|
793
|
+
case "array":
|
|
794
|
+
case "object":
|
|
795
|
+
case "embedding": {
|
|
796
|
+
return dialect.jsonExtract(propsColumn, pointer);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function getNodeScopeColumns(scope) {
|
|
801
|
+
switch (scope) {
|
|
802
|
+
case "graphAndKind": {
|
|
803
|
+
return ["graph_id", "kind"];
|
|
804
|
+
}
|
|
805
|
+
case "graph": {
|
|
806
|
+
return ["graph_id"];
|
|
807
|
+
}
|
|
808
|
+
case "none": {
|
|
809
|
+
return [];
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function getEdgeScopeColumns(scope, direction) {
|
|
814
|
+
const base = scope === "graphAndKind" ? ["graph_id", "kind"] : scope === "graph" ? ["graph_id"] : [];
|
|
815
|
+
if (direction === "out") {
|
|
816
|
+
return [...base, "from_id"];
|
|
817
|
+
}
|
|
818
|
+
if (direction === "in") {
|
|
819
|
+
return [...base, "to_id"];
|
|
820
|
+
}
|
|
821
|
+
return [...base];
|
|
822
|
+
}
|
|
823
|
+
function isIndexWhereLiteralList(value) {
|
|
824
|
+
return Array.isArray(value);
|
|
825
|
+
}
|
|
826
|
+
function compileIndexWhere(ctx, expression) {
|
|
827
|
+
switch (expression.__type) {
|
|
828
|
+
case "index_where_and": {
|
|
829
|
+
return sql`(${sql.join(
|
|
830
|
+
expression.predicates.map((p) => compileIndexWhere(ctx, p)),
|
|
831
|
+
sql` AND `
|
|
832
|
+
)})`;
|
|
833
|
+
}
|
|
834
|
+
case "index_where_or": {
|
|
835
|
+
return sql`(${sql.join(
|
|
836
|
+
expression.predicates.map((p) => compileIndexWhere(ctx, p)),
|
|
837
|
+
sql` OR `
|
|
838
|
+
)})`;
|
|
839
|
+
}
|
|
840
|
+
case "index_where_not": {
|
|
841
|
+
return sql`(NOT ${compileIndexWhere(ctx, expression.predicate)})`;
|
|
842
|
+
}
|
|
843
|
+
case "index_where_null_check": {
|
|
844
|
+
const operand = compileIndexWhereOperand(ctx, expression.operand);
|
|
845
|
+
return expression.op === "isNull" ? sql`${operand} IS NULL` : sql`${operand} IS NOT NULL`;
|
|
846
|
+
}
|
|
847
|
+
case "index_where_comparison": {
|
|
848
|
+
const left = compileIndexWhereOperand(ctx, expression.left);
|
|
849
|
+
const right = expression.right;
|
|
850
|
+
if (isIndexWhereLiteralList(right)) {
|
|
851
|
+
if (expression.op !== "in" && expression.op !== "notIn") {
|
|
852
|
+
throw new Error(
|
|
853
|
+
`Operator "${expression.op}" does not support list comparison in index WHERE clause`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
const values = right.map(
|
|
857
|
+
(literal) => compileIndexWhereLiteral(ctx.dialect, literal)
|
|
858
|
+
);
|
|
859
|
+
const operator = expression.op === "in" ? sql`IN` : sql`NOT IN`;
|
|
860
|
+
return sql`${left} ${operator} (${sql.join(values, sql`, `)})`;
|
|
861
|
+
}
|
|
862
|
+
if (expression.op === "in" || expression.op === "notIn") {
|
|
863
|
+
throw new Error(
|
|
864
|
+
`Operator "${expression.op}" requires a list of values in index WHERE clause`
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
const rightLiteral = compileIndexWhereLiteral(ctx.dialect, right);
|
|
868
|
+
const opSql = compileComparisonOperator(expression.op);
|
|
869
|
+
return sql`${left} ${opSql} ${rightLiteral}`;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function compileIndexWhereOperand(ctx, operand) {
|
|
874
|
+
if (operand.__type === "index_operand_system") {
|
|
875
|
+
return ctx.systemColumn(operand.column);
|
|
876
|
+
}
|
|
877
|
+
const adapter = getDialect(ctx.dialect);
|
|
878
|
+
const pointer = jsonPointer([operand.field]);
|
|
879
|
+
switch (operand.valueType) {
|
|
880
|
+
case "number": {
|
|
881
|
+
return adapter.jsonExtractNumber(ctx.propsColumn, pointer);
|
|
882
|
+
}
|
|
883
|
+
case "boolean": {
|
|
884
|
+
return adapter.jsonExtractBoolean(ctx.propsColumn, pointer);
|
|
885
|
+
}
|
|
886
|
+
case "date": {
|
|
887
|
+
return adapter.jsonExtractDate(ctx.propsColumn, pointer);
|
|
888
|
+
}
|
|
889
|
+
case "array":
|
|
890
|
+
case "object":
|
|
891
|
+
case "embedding": {
|
|
892
|
+
return adapter.jsonExtract(ctx.propsColumn, pointer);
|
|
893
|
+
}
|
|
894
|
+
case "string":
|
|
895
|
+
case "unknown":
|
|
896
|
+
case void 0: {
|
|
897
|
+
return adapter.jsonExtractText(ctx.propsColumn, pointer);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function compileIndexWhereLiteral(dialect, literal) {
|
|
902
|
+
switch (literal.valueType) {
|
|
903
|
+
case "string":
|
|
904
|
+
case "date": {
|
|
905
|
+
return sql.raw(escapeStringLiteral(literal.value.toString()));
|
|
906
|
+
}
|
|
907
|
+
case "number": {
|
|
908
|
+
return sql.raw(literal.value.toString());
|
|
909
|
+
}
|
|
910
|
+
case "boolean": {
|
|
911
|
+
return getDialect(dialect).booleanLiteral(literal.value);
|
|
912
|
+
}
|
|
913
|
+
case "array":
|
|
914
|
+
case "object":
|
|
915
|
+
case "embedding":
|
|
916
|
+
case "unknown": {
|
|
917
|
+
return sql.raw(escapeStringLiteral(literal.value.toString()));
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
function compileComparisonOperator(op) {
|
|
922
|
+
switch (op) {
|
|
923
|
+
case "eq": {
|
|
924
|
+
return sql`=`;
|
|
925
|
+
}
|
|
926
|
+
case "neq": {
|
|
927
|
+
return sql`<>`;
|
|
928
|
+
}
|
|
929
|
+
case "gt": {
|
|
930
|
+
return sql`>`;
|
|
931
|
+
}
|
|
932
|
+
case "gte": {
|
|
933
|
+
return sql`>=`;
|
|
934
|
+
}
|
|
935
|
+
case "lt": {
|
|
936
|
+
return sql`<`;
|
|
937
|
+
}
|
|
938
|
+
case "lte": {
|
|
939
|
+
return sql`<=`;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function escapeStringLiteral(value) {
|
|
944
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
945
|
+
}
|
|
743
946
|
|
|
744
|
-
// src/
|
|
745
|
-
function
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
947
|
+
// src/indexes/ddl.ts
|
|
948
|
+
function generateIndexDDL(index, dialect, options = {}) {
|
|
949
|
+
if (index.entity === "node") {
|
|
950
|
+
return generateNodeIndexDDL(index, dialect, options);
|
|
951
|
+
}
|
|
952
|
+
return generateEdgeIndexDDL(index, dialect, options);
|
|
953
|
+
}
|
|
954
|
+
function generateNodeIndexDDL(index, dialect, options = {}) {
|
|
955
|
+
const tableName = options.nodesTableName ?? "typegraph_nodes";
|
|
956
|
+
return generateTableIndexDDL(index, dialect, tableName, options);
|
|
957
|
+
}
|
|
958
|
+
function generateEdgeIndexDDL(index, dialect, options = {}) {
|
|
959
|
+
const tableName = options.edgesTableName ?? "typegraph_edges";
|
|
960
|
+
return generateTableIndexDDL(index, dialect, tableName, options);
|
|
961
|
+
}
|
|
962
|
+
function generateTableIndexDDL(index, dialect, tableName, options) {
|
|
963
|
+
const ifNotExists = options.ifNotExists ?? true;
|
|
964
|
+
const propsColumn = sql.raw('"props"');
|
|
965
|
+
const systemColumn = (column) => sql.raw(quoteIdentifier2(column));
|
|
966
|
+
const keys = index.entity === "node" ? compileNodeIndexKeys(index, dialect, propsColumn, systemColumn).keys : compileEdgeIndexKeys(index, dialect, propsColumn, systemColumn).keys;
|
|
967
|
+
const whereSql = index.where ? sqlToInlineString(
|
|
968
|
+
compileIndexWhere(
|
|
969
|
+
{
|
|
970
|
+
dialect,
|
|
971
|
+
propsColumn,
|
|
972
|
+
systemColumn
|
|
973
|
+
},
|
|
974
|
+
index.where
|
|
975
|
+
),
|
|
976
|
+
dialect
|
|
977
|
+
) : void 0;
|
|
978
|
+
const keySql = keys.map((k) => sqlToInlineString(k, dialect)).join(", ");
|
|
979
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
980
|
+
const concurrent = options.concurrent === true && dialect === "postgres" ? "CONCURRENTLY " : "";
|
|
981
|
+
const ifNotExistsSql = ifNotExists ? "IF NOT EXISTS " : "";
|
|
982
|
+
const whereClause = whereSql ? ` WHERE ${whereSql}` : "";
|
|
983
|
+
return `CREATE ${unique}INDEX ${concurrent}${ifNotExistsSql}${quoteIdentifier2(index.name)} ON ${quoteIdentifier2(tableName)} (${keySql})${whereClause};`;
|
|
984
|
+
}
|
|
985
|
+
function quoteIdentifier2(identifier) {
|
|
986
|
+
return `"${identifier.replaceAll('"', '""')}"`;
|
|
987
|
+
}
|
|
988
|
+
function sqlToInlineString(object, dialect) {
|
|
989
|
+
const query = object.toQuery({
|
|
990
|
+
casing: new CasingCache(),
|
|
991
|
+
escapeName: (name) => name,
|
|
992
|
+
escapeParam: (_number, value) => inlineParam(value, dialect),
|
|
993
|
+
escapeString: (value) => escapeStringLiteral2(value),
|
|
994
|
+
inlineParams: true,
|
|
995
|
+
invokeSource: "indexes"
|
|
996
|
+
});
|
|
997
|
+
if (query.params.length > 0) {
|
|
998
|
+
throw new Error(
|
|
999
|
+
"Index DDL generation produced parameters; expected fully inlined SQL"
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
return query.sql;
|
|
1003
|
+
}
|
|
1004
|
+
function inlineParam(value, dialect) {
|
|
1005
|
+
if (value === null || value === void 0) {
|
|
1006
|
+
return "NULL";
|
|
1007
|
+
}
|
|
1008
|
+
if (value instanceof Date) {
|
|
1009
|
+
return escapeStringLiteral2(value.toISOString());
|
|
1010
|
+
}
|
|
1011
|
+
if (typeof value === "string") {
|
|
1012
|
+
return escapeStringLiteral2(value);
|
|
1013
|
+
}
|
|
1014
|
+
if (typeof value === "number") {
|
|
1015
|
+
return value.toString();
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof value === "boolean") {
|
|
1018
|
+
return getDialect(dialect).booleanLiteralString(value);
|
|
1019
|
+
}
|
|
1020
|
+
if (typeof value === "bigint") {
|
|
1021
|
+
return value.toString();
|
|
1022
|
+
}
|
|
1023
|
+
throw new TypeError(
|
|
1024
|
+
"Index DDL generation received an unsupported SQL parameter value"
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
function escapeStringLiteral2(value) {
|
|
1028
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
1029
|
+
}
|
|
1030
|
+
function buildPostgresNodeIndexBuilders(table, indexes) {
|
|
1031
|
+
const nodeIndexes = indexes.filter(
|
|
1032
|
+
(index) => index.entity === "node"
|
|
1033
|
+
);
|
|
1034
|
+
return nodeIndexes.map((index$1) => {
|
|
1035
|
+
const propsColumn = sql`${table.props}`;
|
|
1036
|
+
const systemColumn = (column) => sql`${getPostgresNodeSystemColumn(table, column)}`;
|
|
1037
|
+
const { keys } = compileNodeIndexKeys(
|
|
1038
|
+
index$1,
|
|
1039
|
+
"postgres",
|
|
1040
|
+
propsColumn,
|
|
1041
|
+
systemColumn
|
|
1042
|
+
);
|
|
1043
|
+
assertNonEmpty(keys, `node index "${index$1.name}"`);
|
|
1044
|
+
const base = index$1.unique ? uniqueIndex(index$1.name) : index(index$1.name);
|
|
1045
|
+
const builder = base.on(...keys);
|
|
1046
|
+
if (index$1.where) {
|
|
1047
|
+
const ctx = {
|
|
1048
|
+
dialect: "postgres",
|
|
1049
|
+
propsColumn,
|
|
1050
|
+
systemColumn
|
|
1051
|
+
};
|
|
1052
|
+
builder.where(compileIndexWhere(ctx, index$1.where));
|
|
1053
|
+
}
|
|
1054
|
+
return builder;
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
function buildPostgresEdgeIndexBuilders(table, indexes) {
|
|
1058
|
+
const edgeIndexes = indexes.filter(
|
|
1059
|
+
(index) => index.entity === "edge"
|
|
1060
|
+
);
|
|
1061
|
+
return edgeIndexes.map((index$1) => {
|
|
1062
|
+
const propsColumn = sql`${table.props}`;
|
|
1063
|
+
const systemColumn = (column) => sql`${getPostgresEdgeSystemColumn(table, column)}`;
|
|
1064
|
+
const { keys } = compileEdgeIndexKeys(
|
|
1065
|
+
index$1,
|
|
1066
|
+
"postgres",
|
|
1067
|
+
propsColumn,
|
|
1068
|
+
systemColumn
|
|
1069
|
+
);
|
|
1070
|
+
assertNonEmpty(keys, `edge index "${index$1.name}"`);
|
|
1071
|
+
const base = index$1.unique ? uniqueIndex(index$1.name) : index(index$1.name);
|
|
1072
|
+
const builder = base.on(...keys);
|
|
1073
|
+
if (index$1.where) {
|
|
1074
|
+
const ctx = {
|
|
1075
|
+
dialect: "postgres",
|
|
1076
|
+
propsColumn,
|
|
1077
|
+
systemColumn
|
|
1078
|
+
};
|
|
1079
|
+
builder.where(compileIndexWhere(ctx, index$1.where));
|
|
1080
|
+
}
|
|
1081
|
+
return builder;
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function getPostgresNodeSystemColumn(table, column) {
|
|
1085
|
+
switch (column) {
|
|
1086
|
+
case "graph_id": {
|
|
1087
|
+
return table.graphId;
|
|
1088
|
+
}
|
|
1089
|
+
case "kind": {
|
|
1090
|
+
return table.kind;
|
|
1091
|
+
}
|
|
1092
|
+
case "id": {
|
|
1093
|
+
return table.id;
|
|
1094
|
+
}
|
|
1095
|
+
case "from_kind":
|
|
1096
|
+
case "from_id":
|
|
1097
|
+
case "to_kind":
|
|
1098
|
+
case "to_id": {
|
|
1099
|
+
throw new Error(`Unsupported node system column for indexes: ${column}`);
|
|
1100
|
+
}
|
|
1101
|
+
case "deleted_at": {
|
|
1102
|
+
return table.deletedAt;
|
|
1103
|
+
}
|
|
1104
|
+
case "valid_from": {
|
|
1105
|
+
return table.validFrom;
|
|
1106
|
+
}
|
|
1107
|
+
case "valid_to": {
|
|
1108
|
+
return table.validTo;
|
|
1109
|
+
}
|
|
1110
|
+
case "created_at": {
|
|
1111
|
+
return table.createdAt;
|
|
1112
|
+
}
|
|
1113
|
+
case "updated_at": {
|
|
1114
|
+
return table.updatedAt;
|
|
1115
|
+
}
|
|
1116
|
+
case "version": {
|
|
1117
|
+
return table.version;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
function getPostgresEdgeSystemColumn(table, column) {
|
|
1122
|
+
switch (column) {
|
|
1123
|
+
case "graph_id": {
|
|
1124
|
+
return table.graphId;
|
|
1125
|
+
}
|
|
1126
|
+
case "kind": {
|
|
1127
|
+
return table.kind;
|
|
1128
|
+
}
|
|
1129
|
+
case "id": {
|
|
1130
|
+
return table.id;
|
|
1131
|
+
}
|
|
1132
|
+
case "from_kind": {
|
|
1133
|
+
return table.fromKind;
|
|
1134
|
+
}
|
|
1135
|
+
case "from_id": {
|
|
1136
|
+
return table.fromId;
|
|
1137
|
+
}
|
|
1138
|
+
case "to_kind": {
|
|
1139
|
+
return table.toKind;
|
|
1140
|
+
}
|
|
1141
|
+
case "to_id": {
|
|
1142
|
+
return table.toId;
|
|
1143
|
+
}
|
|
1144
|
+
case "deleted_at": {
|
|
1145
|
+
return table.deletedAt;
|
|
1146
|
+
}
|
|
1147
|
+
case "valid_from": {
|
|
1148
|
+
return table.validFrom;
|
|
1149
|
+
}
|
|
1150
|
+
case "valid_to": {
|
|
1151
|
+
return table.validTo;
|
|
1152
|
+
}
|
|
1153
|
+
case "created_at": {
|
|
1154
|
+
return table.createdAt;
|
|
1155
|
+
}
|
|
1156
|
+
case "updated_at": {
|
|
1157
|
+
return table.updatedAt;
|
|
1158
|
+
}
|
|
1159
|
+
case "version": {
|
|
1160
|
+
throw new Error(`Unsupported edge system column for indexes: ${column}`);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
function buildSqliteNodeIndexBuilders(table, indexes) {
|
|
1165
|
+
const nodeIndexes = indexes.filter(
|
|
1166
|
+
(index) => index.entity === "node"
|
|
1167
|
+
);
|
|
1168
|
+
return nodeIndexes.map((index) => {
|
|
1169
|
+
const propsColumn = sql`${table.props}`;
|
|
1170
|
+
const systemColumn = (column) => sql`${getSqliteNodeSystemColumn(table, column)}`;
|
|
1171
|
+
const { keys } = compileNodeIndexKeys(
|
|
1172
|
+
index,
|
|
1173
|
+
"sqlite",
|
|
1174
|
+
propsColumn,
|
|
1175
|
+
systemColumn
|
|
1176
|
+
);
|
|
1177
|
+
assertNonEmpty(keys, `node index "${index.name}"`);
|
|
1178
|
+
const base = index.unique ? uniqueIndex$1(index.name) : index$1(index.name);
|
|
1179
|
+
const builder = base.on(...keys);
|
|
1180
|
+
if (index.where) {
|
|
1181
|
+
const ctx = {
|
|
1182
|
+
dialect: "sqlite",
|
|
1183
|
+
propsColumn,
|
|
1184
|
+
systemColumn
|
|
1185
|
+
};
|
|
1186
|
+
builder.where(compileIndexWhere(ctx, index.where));
|
|
1187
|
+
}
|
|
1188
|
+
return builder;
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
function buildSqliteEdgeIndexBuilders(table, indexes) {
|
|
1192
|
+
const edgeIndexes = indexes.filter(
|
|
1193
|
+
(index) => index.entity === "edge"
|
|
1194
|
+
);
|
|
1195
|
+
return edgeIndexes.map((index) => {
|
|
1196
|
+
const propsColumn = sql`${table.props}`;
|
|
1197
|
+
const systemColumn = (column) => sql`${getSqliteEdgeSystemColumn(table, column)}`;
|
|
1198
|
+
const { keys } = compileEdgeIndexKeys(
|
|
1199
|
+
index,
|
|
1200
|
+
"sqlite",
|
|
1201
|
+
propsColumn,
|
|
1202
|
+
systemColumn
|
|
1203
|
+
);
|
|
1204
|
+
assertNonEmpty(keys, `edge index "${index.name}"`);
|
|
1205
|
+
const base = index.unique ? uniqueIndex$1(index.name) : index$1(index.name);
|
|
1206
|
+
const builder = base.on(...keys);
|
|
1207
|
+
if (index.where) {
|
|
1208
|
+
const ctx = {
|
|
1209
|
+
dialect: "sqlite",
|
|
1210
|
+
propsColumn,
|
|
1211
|
+
systemColumn
|
|
1212
|
+
};
|
|
1213
|
+
builder.where(compileIndexWhere(ctx, index.where));
|
|
1214
|
+
}
|
|
1215
|
+
return builder;
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
function getSqliteNodeSystemColumn(table, column) {
|
|
1219
|
+
switch (column) {
|
|
1220
|
+
case "graph_id": {
|
|
1221
|
+
return table.graphId;
|
|
1222
|
+
}
|
|
1223
|
+
case "kind": {
|
|
1224
|
+
return table.kind;
|
|
1225
|
+
}
|
|
1226
|
+
case "id": {
|
|
1227
|
+
return table.id;
|
|
1228
|
+
}
|
|
1229
|
+
case "from_kind":
|
|
1230
|
+
case "from_id":
|
|
1231
|
+
case "to_kind":
|
|
1232
|
+
case "to_id": {
|
|
1233
|
+
throw new Error(`Unsupported node system column for indexes: ${column}`);
|
|
1234
|
+
}
|
|
1235
|
+
case "deleted_at": {
|
|
1236
|
+
return table.deletedAt;
|
|
1237
|
+
}
|
|
1238
|
+
case "valid_from": {
|
|
1239
|
+
return table.validFrom;
|
|
1240
|
+
}
|
|
1241
|
+
case "valid_to": {
|
|
1242
|
+
return table.validTo;
|
|
1243
|
+
}
|
|
1244
|
+
case "created_at": {
|
|
1245
|
+
return table.createdAt;
|
|
1246
|
+
}
|
|
1247
|
+
case "updated_at": {
|
|
1248
|
+
return table.updatedAt;
|
|
1249
|
+
}
|
|
1250
|
+
case "version": {
|
|
1251
|
+
return table.version;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
function getSqliteEdgeSystemColumn(table, column) {
|
|
1256
|
+
switch (column) {
|
|
1257
|
+
case "graph_id": {
|
|
1258
|
+
return table.graphId;
|
|
1259
|
+
}
|
|
1260
|
+
case "kind": {
|
|
1261
|
+
return table.kind;
|
|
1262
|
+
}
|
|
1263
|
+
case "id": {
|
|
1264
|
+
return table.id;
|
|
1265
|
+
}
|
|
1266
|
+
case "from_kind": {
|
|
1267
|
+
return table.fromKind;
|
|
1268
|
+
}
|
|
1269
|
+
case "from_id": {
|
|
1270
|
+
return table.fromId;
|
|
1271
|
+
}
|
|
1272
|
+
case "to_kind": {
|
|
1273
|
+
return table.toKind;
|
|
1274
|
+
}
|
|
1275
|
+
case "to_id": {
|
|
1276
|
+
return table.toId;
|
|
1277
|
+
}
|
|
1278
|
+
case "deleted_at": {
|
|
1279
|
+
return table.deletedAt;
|
|
1280
|
+
}
|
|
1281
|
+
case "valid_from": {
|
|
1282
|
+
return table.validFrom;
|
|
1283
|
+
}
|
|
1284
|
+
case "valid_to": {
|
|
1285
|
+
return table.validTo;
|
|
1286
|
+
}
|
|
1287
|
+
case "created_at": {
|
|
1288
|
+
return table.createdAt;
|
|
1289
|
+
}
|
|
1290
|
+
case "updated_at": {
|
|
1291
|
+
return table.updatedAt;
|
|
1292
|
+
}
|
|
1293
|
+
case "version": {
|
|
1294
|
+
throw new Error(`Unsupported edge system column for indexes: ${column}`);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function assertNonEmpty(values, label) {
|
|
1299
|
+
if (values.length === 0) {
|
|
1300
|
+
throw new Error(`Index must have at least one key (${label})`);
|
|
752
1301
|
}
|
|
753
|
-
return (hash >>> 0).toString(36);
|
|
754
1302
|
}
|
|
755
1303
|
|
|
756
|
-
// src/
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
1304
|
+
// src/indexes/profiler.ts
|
|
1305
|
+
function toDeclaredIndex(index) {
|
|
1306
|
+
return {
|
|
1307
|
+
entityType: index.entity,
|
|
1308
|
+
kind: index.kind,
|
|
1309
|
+
fields: [...index.fields],
|
|
1310
|
+
unique: index.unique,
|
|
1311
|
+
name: index.name
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function toDeclaredIndexes(indexes) {
|
|
1315
|
+
return indexes.filter(
|
|
1316
|
+
(index) => index.entity === "node" || index.entity === "edge"
|
|
1317
|
+
).map((index) => toDeclaredIndex(index));
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// src/indexes/where.ts
|
|
1321
|
+
function andWhere(...predicates) {
|
|
1322
|
+
if (predicates.length === 1) {
|
|
1323
|
+
return predicates[0];
|
|
1324
|
+
}
|
|
1325
|
+
return {
|
|
1326
|
+
__type: "index_where_and",
|
|
1327
|
+
predicates
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
function orWhere(...predicates) {
|
|
1331
|
+
if (predicates.length === 1) {
|
|
1332
|
+
return predicates[0];
|
|
1333
|
+
}
|
|
1334
|
+
return {
|
|
1335
|
+
__type: "index_where_or",
|
|
1336
|
+
predicates
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
function notWhere(predicate) {
|
|
1340
|
+
return {
|
|
1341
|
+
__type: "index_where_not",
|
|
1342
|
+
predicate
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
772
1345
|
|
|
773
|
-
export {
|
|
774
|
-
//# sourceMappingURL=chunk-
|
|
775
|
-
//# sourceMappingURL=chunk-
|
|
1346
|
+
export { andWhere, buildFulltextCapabilities, buildPostgresEdgeIndexBuilders, buildPostgresNodeIndexBuilders, buildSqliteEdgeIndexBuilders, buildSqliteNodeIndexBuilders, edgeColumnList, fts5Strategy, generateEdgeIndexDDL, generateIndexDDL, generateNodeIndexDDL, getDialect, nodeColumnList, notWhere, orWhere, quotedColumn, quotedTableName, sqlNull, toDeclaredIndex, toDeclaredIndexes, tsvectorStrategy };
|
|
1347
|
+
//# sourceMappingURL=chunk-YZZBDCLV.js.map
|
|
1348
|
+
//# sourceMappingURL=chunk-YZZBDCLV.js.map
|