@nicia-ai/typegraph 0.13.0 → 0.15.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.
Files changed (81) hide show
  1. package/dist/backend/postgres/index.cjs +34 -28
  2. package/dist/backend/postgres/index.cjs.map +1 -1
  3. package/dist/backend/postgres/index.d.cts +5 -5
  4. package/dist/backend/postgres/index.d.ts +5 -5
  5. package/dist/backend/postgres/index.js +16 -10
  6. package/dist/backend/postgres/index.js.map +1 -1
  7. package/dist/backend/sqlite/index.cjs +14 -14
  8. package/dist/backend/sqlite/index.d.cts +5 -5
  9. package/dist/backend/sqlite/index.d.ts +5 -5
  10. package/dist/backend/sqlite/index.js +4 -4
  11. package/dist/backend/sqlite/local.cjs +7 -7
  12. package/dist/backend/sqlite/local.cjs.map +1 -1
  13. package/dist/backend/sqlite/local.d.cts +3 -3
  14. package/dist/backend/sqlite/local.d.ts +3 -3
  15. package/dist/backend/sqlite/local.js +7 -7
  16. package/dist/backend/sqlite/local.js.map +1 -1
  17. package/dist/{chunk-7VITUTRA.cjs → chunk-3HQLOKS5.cjs} +163 -13
  18. package/dist/chunk-3HQLOKS5.cjs.map +1 -0
  19. package/dist/{chunk-NZMKJHE2.cjs → chunk-56RQFK7U.cjs} +22 -15
  20. package/dist/chunk-56RQFK7U.cjs.map +1 -0
  21. package/dist/{chunk-U3452TEU.js → chunk-6GWJH6AR.js} +15 -27
  22. package/dist/chunk-6GWJH6AR.js.map +1 -0
  23. package/dist/{chunk-2XPKLHHH.cjs → chunk-CRMN2NOM.cjs} +247 -208
  24. package/dist/chunk-CRMN2NOM.cjs.map +1 -0
  25. package/dist/{chunk-54WJF3DW.js → chunk-GNIYZKBI.js} +29 -3
  26. package/dist/chunk-GNIYZKBI.js.map +1 -0
  27. package/dist/{chunk-52WSY6G5.js → chunk-HWWF3FOP.js} +158 -119
  28. package/dist/chunk-HWWF3FOP.js.map +1 -0
  29. package/dist/{chunk-PYV4ADC6.js → chunk-L4ON6RJF.js} +164 -14
  30. package/dist/chunk-L4ON6RJF.js.map +1 -0
  31. package/dist/{chunk-JQDWEX6V.cjs → chunk-LELLOHJK.cjs} +22 -34
  32. package/dist/chunk-LELLOHJK.cjs.map +1 -0
  33. package/dist/{chunk-2WVFEIHR.cjs → chunk-MME3H4ZF.cjs} +40 -2
  34. package/dist/chunk-MME3H4ZF.cjs.map +1 -0
  35. package/dist/{chunk-J4SICP3X.js → chunk-XZBAGJJH.js} +15 -8
  36. package/dist/chunk-XZBAGJJH.js.map +1 -0
  37. package/dist/{ddl-BJg93HDN.d.cts → ddl-BBo2EcFc.d.cts} +2 -2
  38. package/dist/{ddl-CsfWcl_B.d.ts → ddl-D4jlcOH_.d.ts} +2 -2
  39. package/dist/index.cjs +473 -625
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +12 -9
  42. package/dist/index.d.ts +12 -9
  43. package/dist/index.js +434 -586
  44. package/dist/index.js.map +1 -1
  45. package/dist/indexes/index.cjs +16 -16
  46. package/dist/indexes/index.d.cts +2 -2
  47. package/dist/indexes/index.d.ts +2 -2
  48. package/dist/indexes/index.js +2 -2
  49. package/dist/interchange/index.d.cts +3 -3
  50. package/dist/interchange/index.d.ts +3 -3
  51. package/dist/{manager-DGSnJa1v.d.cts → manager-Bj1UEnhE.d.cts} +2 -2
  52. package/dist/{manager-BCLhWysp.d.ts → manager-Chhrq1vl.d.ts} +2 -2
  53. package/dist/profiler/index.cjs +6 -6
  54. package/dist/profiler/index.cjs.map +1 -1
  55. package/dist/profiler/index.d.cts +3 -3
  56. package/dist/profiler/index.d.ts +3 -3
  57. package/dist/profiler/index.js +6 -6
  58. package/dist/profiler/index.js.map +1 -1
  59. package/dist/schema/index.cjs +20 -20
  60. package/dist/schema/index.d.cts +4 -4
  61. package/dist/schema/index.d.ts +4 -4
  62. package/dist/schema/index.js +2 -2
  63. package/dist/{sqlite-H01wIXvB.d.ts → sqlite-Blq-AhmK.d.ts} +1 -1
  64. package/dist/{sqlite-DVca_IIy.d.cts → sqlite-DE-6NWtC.d.cts} +1 -1
  65. package/dist/{store-Bmdt_dS6.d.cts → store-BNercm8P.d.cts} +86 -31
  66. package/dist/{store-6-vH0ZIj.d.ts → store-CD_0yf2s.d.ts} +86 -31
  67. package/dist/{types-GLkwvQvS.d.cts → types-B3mmOMJV.d.cts} +20 -6
  68. package/dist/{types-C8Ra3ROE.d.cts → types-CZd2PEOc.d.cts} +8 -2
  69. package/dist/{types-CC8eB0PB.d.ts → types-Ceb01czq.d.ts} +8 -2
  70. package/dist/{types-1YJKodRv.d.ts → types-ThB4cFLp.d.ts} +20 -6
  71. package/package.json +1 -1
  72. package/dist/chunk-2WVFEIHR.cjs.map +0 -1
  73. package/dist/chunk-2XPKLHHH.cjs.map +0 -1
  74. package/dist/chunk-52WSY6G5.js.map +0 -1
  75. package/dist/chunk-54WJF3DW.js.map +0 -1
  76. package/dist/chunk-7VITUTRA.cjs.map +0 -1
  77. package/dist/chunk-J4SICP3X.js.map +0 -1
  78. package/dist/chunk-JQDWEX6V.cjs.map +0 -1
  79. package/dist/chunk-NZMKJHE2.cjs.map +0 -1
  80. package/dist/chunk-PYV4ADC6.js.map +0 -1
  81. package/dist/chunk-U3452TEU.js.map +0 -1
@@ -1,11 +1,32 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk44SXEVF4_cjs = require('./chunk-44SXEVF4.cjs');
4
- var chunkJQDWEX6V_cjs = require('./chunk-JQDWEX6V.cjs');
5
- var sqliteCore = require('drizzle-orm/sqlite-core');
4
+ var chunkLELLOHJK_cjs = require('./chunk-LELLOHJK.cjs');
5
+ var chunkMME3H4ZF_cjs = require('./chunk-MME3H4ZF.cjs');
6
6
  var pgCore = require('drizzle-orm/pg-core');
7
+ var sqliteCore = require('drizzle-orm/sqlite-core');
7
8
  var drizzleOrm = require('drizzle-orm');
8
9
 
10
+ var vector = pgCore.customType({
11
+ dataType(config) {
12
+ return config?.dimensions ? `vector(${config.dimensions})` : "vector";
13
+ },
14
+ toDriver(value) {
15
+ return `[${value.join(",")}]`;
16
+ },
17
+ fromDriver(value) {
18
+ if (Array.isArray(value)) {
19
+ return value;
20
+ }
21
+ const content = value.slice(1, -1);
22
+ if (content === "") {
23
+ return [];
24
+ }
25
+ return content.split(",").map((s) => Number.parseFloat(s.trim()));
26
+ }
27
+ });
28
+
29
+ // src/backend/drizzle/schema/postgres.ts
9
30
  var DEFAULT_TABLE_NAMES = {
10
31
  nodes: "typegraph_nodes",
11
32
  edges: "typegraph_edges",
@@ -13,60 +34,60 @@ var DEFAULT_TABLE_NAMES = {
13
34
  schemaVersions: "typegraph_schema_versions",
14
35
  embeddings: "typegraph_node_embeddings"
15
36
  };
16
- function createSqliteTables(names = {}, options = {}) {
37
+ function createPostgresTables(names = {}, options = {}) {
17
38
  const n = { ...DEFAULT_TABLE_NAMES, ...names };
18
39
  const indexes = options.indexes ?? [];
19
- const nodes3 = sqliteCore.sqliteTable(
40
+ const nodes3 = pgCore.pgTable(
20
41
  n.nodes,
21
42
  {
22
- graphId: sqliteCore.text("graph_id").notNull(),
23
- kind: sqliteCore.text("kind").notNull(),
24
- id: sqliteCore.text("id").notNull(),
25
- props: sqliteCore.text("props").notNull(),
26
- version: sqliteCore.integer("version").notNull().default(1),
27
- validFrom: sqliteCore.text("valid_from"),
28
- validTo: sqliteCore.text("valid_to"),
29
- createdAt: sqliteCore.text("created_at").notNull(),
30
- updatedAt: sqliteCore.text("updated_at").notNull(),
31
- deletedAt: sqliteCore.text("deleted_at")
43
+ graphId: pgCore.text("graph_id").notNull(),
44
+ kind: pgCore.text("kind").notNull(),
45
+ id: pgCore.text("id").notNull(),
46
+ props: pgCore.jsonb("props").notNull(),
47
+ version: pgCore.integer("version").notNull().default(1),
48
+ validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
49
+ validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
50
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
51
+ updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
52
+ deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
32
53
  },
33
54
  (t) => [
34
- sqliteCore.primaryKey({ columns: [t.graphId, t.kind, t.id] }),
35
- sqliteCore.index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
36
- sqliteCore.index(`${n.nodes}_kind_created_idx`).on(
55
+ pgCore.primaryKey({ columns: [t.graphId, t.kind, t.id] }),
56
+ pgCore.index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
57
+ pgCore.index(`${n.nodes}_kind_created_idx`).on(
37
58
  t.graphId,
38
59
  t.kind,
39
60
  t.deletedAt,
40
61
  t.createdAt
41
62
  ),
42
- sqliteCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
43
- sqliteCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
44
- ...chunkJQDWEX6V_cjs.buildSqliteNodeIndexBuilders(t, indexes)
63
+ pgCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
64
+ pgCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
65
+ ...chunkLELLOHJK_cjs.buildPostgresNodeIndexBuilders(t, indexes)
45
66
  ]
46
67
  );
47
- const edges3 = sqliteCore.sqliteTable(
68
+ const edges3 = pgCore.pgTable(
48
69
  n.edges,
49
70
  {
50
- graphId: sqliteCore.text("graph_id").notNull(),
51
- id: sqliteCore.text("id").notNull(),
52
- kind: sqliteCore.text("kind").notNull(),
53
- fromKind: sqliteCore.text("from_kind").notNull(),
54
- fromId: sqliteCore.text("from_id").notNull(),
55
- toKind: sqliteCore.text("to_kind").notNull(),
56
- toId: sqliteCore.text("to_id").notNull(),
57
- props: sqliteCore.text("props").notNull(),
58
- validFrom: sqliteCore.text("valid_from"),
59
- validTo: sqliteCore.text("valid_to"),
60
- createdAt: sqliteCore.text("created_at").notNull(),
61
- updatedAt: sqliteCore.text("updated_at").notNull(),
62
- deletedAt: sqliteCore.text("deleted_at")
71
+ graphId: pgCore.text("graph_id").notNull(),
72
+ id: pgCore.text("id").notNull(),
73
+ kind: pgCore.text("kind").notNull(),
74
+ fromKind: pgCore.text("from_kind").notNull(),
75
+ fromId: pgCore.text("from_id").notNull(),
76
+ toKind: pgCore.text("to_kind").notNull(),
77
+ toId: pgCore.text("to_id").notNull(),
78
+ props: pgCore.jsonb("props").notNull(),
79
+ validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
80
+ validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
81
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
82
+ updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
83
+ deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
63
84
  },
64
85
  (t) => [
65
- sqliteCore.primaryKey({ columns: [t.graphId, t.id] }),
66
- sqliteCore.index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
86
+ pgCore.primaryKey({ columns: [t.graphId, t.id] }),
87
+ pgCore.index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
67
88
  // Directional traversal index (outgoing): supports endpoint lookups
68
89
  // and extra filtering by edge kind / target kind.
69
- sqliteCore.index(`${n.edges}_from_idx`).on(
90
+ pgCore.index(`${n.edges}_from_idx`).on(
70
91
  t.graphId,
71
92
  t.fromKind,
72
93
  t.fromId,
@@ -76,7 +97,7 @@ function createSqliteTables(names = {}, options = {}) {
76
97
  t.validTo
77
98
  ),
78
99
  // Directional traversal index (incoming): mirrors from_idx for reverse traversals.
79
- sqliteCore.index(`${n.edges}_to_idx`).on(
100
+ pgCore.index(`${n.edges}_to_idx`).on(
80
101
  t.graphId,
81
102
  t.toKind,
82
103
  t.toId,
@@ -85,87 +106,83 @@ function createSqliteTables(names = {}, options = {}) {
85
106
  t.deletedAt,
86
107
  t.validTo
87
108
  ),
88
- sqliteCore.index(`${n.edges}_kind_created_idx`).on(
109
+ pgCore.index(`${n.edges}_kind_created_idx`).on(
89
110
  t.graphId,
90
111
  t.kind,
91
112
  t.deletedAt,
92
113
  t.createdAt
93
114
  ),
94
- sqliteCore.index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
95
- sqliteCore.index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
96
- sqliteCore.index(`${n.edges}_cardinality_idx`).on(
115
+ pgCore.index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
116
+ pgCore.index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
117
+ pgCore.index(`${n.edges}_cardinality_idx`).on(
97
118
  t.graphId,
98
119
  t.kind,
99
120
  t.fromKind,
100
121
  t.fromId,
101
122
  t.validTo
102
123
  ),
103
- ...chunkJQDWEX6V_cjs.buildSqliteEdgeIndexBuilders(t, indexes)
124
+ ...chunkLELLOHJK_cjs.buildPostgresEdgeIndexBuilders(t, indexes)
104
125
  ]
105
126
  );
106
- const uniques3 = sqliteCore.sqliteTable(
127
+ const uniques3 = pgCore.pgTable(
107
128
  n.uniques,
108
129
  {
109
- graphId: sqliteCore.text("graph_id").notNull(),
110
- nodeKind: sqliteCore.text("node_kind").notNull(),
111
- constraintName: sqliteCore.text("constraint_name").notNull(),
112
- key: sqliteCore.text("key").notNull(),
113
- nodeId: sqliteCore.text("node_id").notNull(),
114
- concreteKind: sqliteCore.text("concrete_kind").notNull(),
115
- deletedAt: sqliteCore.text("deleted_at")
130
+ graphId: pgCore.text("graph_id").notNull(),
131
+ nodeKind: pgCore.text("node_kind").notNull(),
132
+ constraintName: pgCore.text("constraint_name").notNull(),
133
+ key: pgCore.text("key").notNull(),
134
+ nodeId: pgCore.text("node_id").notNull(),
135
+ concreteKind: pgCore.text("concrete_kind").notNull(),
136
+ deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
116
137
  },
117
138
  (t) => [
118
- sqliteCore.primaryKey({
139
+ pgCore.primaryKey({
119
140
  columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
120
141
  }),
121
- sqliteCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
142
+ pgCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
122
143
  ]
123
144
  );
124
- const schemaVersions3 = sqliteCore.sqliteTable(
145
+ const schemaVersions3 = pgCore.pgTable(
125
146
  n.schemaVersions,
126
147
  {
127
- graphId: sqliteCore.text("graph_id").notNull(),
128
- version: sqliteCore.integer("version").notNull(),
129
- schemaHash: sqliteCore.text("schema_hash").notNull(),
130
- schemaDoc: sqliteCore.text("schema_doc").notNull(),
131
- createdAt: sqliteCore.text("created_at").notNull(),
132
- isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(false)
148
+ graphId: pgCore.text("graph_id").notNull(),
149
+ version: pgCore.integer("version").notNull(),
150
+ schemaHash: pgCore.text("schema_hash").notNull(),
151
+ schemaDoc: pgCore.jsonb("schema_doc").notNull(),
152
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
153
+ isActive: pgCore.boolean("is_active").notNull().default(false)
133
154
  },
134
155
  (t) => [
135
- sqliteCore.primaryKey({ columns: [t.graphId, t.version] }),
136
- sqliteCore.index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
156
+ pgCore.primaryKey({ columns: [t.graphId, t.version] }),
157
+ pgCore.index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
137
158
  ]
138
159
  );
139
- const embeddings3 = sqliteCore.sqliteTable(
160
+ const embeddings3 = pgCore.pgTable(
140
161
  n.embeddings,
141
162
  {
142
- graphId: sqliteCore.text("graph_id").notNull(),
143
- nodeKind: sqliteCore.text("node_kind").notNull(),
144
- nodeId: sqliteCore.text("node_id").notNull(),
145
- fieldPath: sqliteCore.text("field_path").notNull(),
146
- /**
147
- * Embedding vector.
148
- * Stored as BLOB for sqlite-vec binary format, or JSON text for fallback.
149
- * For sqlite-vec: use vec_f32() to convert JSON array to binary.
150
- */
151
- embedding: sqliteCore.blob("embedding", { mode: "buffer" }).notNull(),
163
+ graphId: pgCore.text("graph_id").notNull(),
164
+ nodeKind: pgCore.text("node_kind").notNull(),
165
+ nodeId: pgCore.text("node_id").notNull(),
166
+ fieldPath: pgCore.text("field_path").notNull(),
167
+ /** Embedding vector stored as native pgvector type */
168
+ embedding: vector("embedding").notNull(),
152
169
  /** Number of dimensions (for validation) */
153
- dimensions: sqliteCore.integer("dimensions").notNull(),
154
- createdAt: sqliteCore.text("created_at").notNull(),
155
- updatedAt: sqliteCore.text("updated_at").notNull()
170
+ dimensions: pgCore.integer("dimensions").notNull(),
171
+ createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
172
+ updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull()
156
173
  },
157
174
  (t) => [
158
- sqliteCore.primaryKey({
175
+ pgCore.primaryKey({
159
176
  columns: [t.graphId, t.nodeKind, t.nodeId, t.fieldPath]
160
177
  }),
161
178
  // Index for looking up embeddings by node
162
- sqliteCore.index(`${n.embeddings}_node_idx`).on(
179
+ pgCore.index(`${n.embeddings}_node_idx`).on(
163
180
  t.graphId,
164
181
  t.nodeKind,
165
182
  t.nodeId
166
183
  ),
167
184
  // Index for filtering by kind and field (used in vector search)
168
- sqliteCore.index(`${n.embeddings}_kind_field_idx`).on(
185
+ pgCore.index(`${n.embeddings}_kind_field_idx`).on(
169
186
  t.graphId,
170
187
  t.nodeKind,
171
188
  t.fieldPath
@@ -174,28 +191,8 @@ function createSqliteTables(names = {}, options = {}) {
174
191
  );
175
192
  return { nodes: nodes3, edges: edges3, uniques: uniques3, schemaVersions: schemaVersions3, embeddings: embeddings3 };
176
193
  }
177
- var tables = createSqliteTables();
194
+ var tables = createPostgresTables();
178
195
  var { nodes, edges, uniques, schemaVersions, embeddings } = tables;
179
- var vector = pgCore.customType({
180
- dataType(config) {
181
- return config?.dimensions ? `vector(${config.dimensions})` : "vector";
182
- },
183
- toDriver(value) {
184
- return `[${value.join(",")}]`;
185
- },
186
- fromDriver(value) {
187
- if (Array.isArray(value)) {
188
- return value;
189
- }
190
- const content = value.slice(1, -1);
191
- if (content === "") {
192
- return [];
193
- }
194
- return content.split(",").map((s) => Number.parseFloat(s.trim()));
195
- }
196
- });
197
-
198
- // src/backend/drizzle/schema/postgres.ts
199
196
  var DEFAULT_TABLE_NAMES2 = {
200
197
  nodes: "typegraph_nodes",
201
198
  edges: "typegraph_edges",
@@ -203,60 +200,60 @@ var DEFAULT_TABLE_NAMES2 = {
203
200
  schemaVersions: "typegraph_schema_versions",
204
201
  embeddings: "typegraph_node_embeddings"
205
202
  };
206
- function createPostgresTables(names = {}, options = {}) {
203
+ function createSqliteTables(names = {}, options = {}) {
207
204
  const n = { ...DEFAULT_TABLE_NAMES2, ...names };
208
205
  const indexes = options.indexes ?? [];
209
- const nodes3 = pgCore.pgTable(
206
+ const nodes3 = sqliteCore.sqliteTable(
210
207
  n.nodes,
211
208
  {
212
- graphId: pgCore.text("graph_id").notNull(),
213
- kind: pgCore.text("kind").notNull(),
214
- id: pgCore.text("id").notNull(),
215
- props: pgCore.jsonb("props").notNull(),
216
- version: pgCore.integer("version").notNull().default(1),
217
- validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
218
- validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
219
- createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
220
- updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
221
- deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
209
+ graphId: sqliteCore.text("graph_id").notNull(),
210
+ kind: sqliteCore.text("kind").notNull(),
211
+ id: sqliteCore.text("id").notNull(),
212
+ props: sqliteCore.text("props").notNull(),
213
+ version: sqliteCore.integer("version").notNull().default(1),
214
+ validFrom: sqliteCore.text("valid_from"),
215
+ validTo: sqliteCore.text("valid_to"),
216
+ createdAt: sqliteCore.text("created_at").notNull(),
217
+ updatedAt: sqliteCore.text("updated_at").notNull(),
218
+ deletedAt: sqliteCore.text("deleted_at")
222
219
  },
223
220
  (t) => [
224
- pgCore.primaryKey({ columns: [t.graphId, t.kind, t.id] }),
225
- pgCore.index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
226
- pgCore.index(`${n.nodes}_kind_created_idx`).on(
221
+ sqliteCore.primaryKey({ columns: [t.graphId, t.kind, t.id] }),
222
+ sqliteCore.index(`${n.nodes}_kind_idx`).on(t.graphId, t.kind),
223
+ sqliteCore.index(`${n.nodes}_kind_created_idx`).on(
227
224
  t.graphId,
228
225
  t.kind,
229
226
  t.deletedAt,
230
227
  t.createdAt
231
228
  ),
232
- pgCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
233
- pgCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
234
- ...chunkJQDWEX6V_cjs.buildPostgresNodeIndexBuilders(t, indexes)
229
+ sqliteCore.index(`${n.nodes}_deleted_idx`).on(t.graphId, t.deletedAt),
230
+ sqliteCore.index(`${n.nodes}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
231
+ ...chunkLELLOHJK_cjs.buildSqliteNodeIndexBuilders(t, indexes)
235
232
  ]
236
233
  );
237
- const edges3 = pgCore.pgTable(
234
+ const edges3 = sqliteCore.sqliteTable(
238
235
  n.edges,
239
236
  {
240
- graphId: pgCore.text("graph_id").notNull(),
241
- id: pgCore.text("id").notNull(),
242
- kind: pgCore.text("kind").notNull(),
243
- fromKind: pgCore.text("from_kind").notNull(),
244
- fromId: pgCore.text("from_id").notNull(),
245
- toKind: pgCore.text("to_kind").notNull(),
246
- toId: pgCore.text("to_id").notNull(),
247
- props: pgCore.jsonb("props").notNull(),
248
- validFrom: pgCore.timestamp("valid_from", { withTimezone: true }),
249
- validTo: pgCore.timestamp("valid_to", { withTimezone: true }),
250
- createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
251
- updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull(),
252
- deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
237
+ graphId: sqliteCore.text("graph_id").notNull(),
238
+ id: sqliteCore.text("id").notNull(),
239
+ kind: sqliteCore.text("kind").notNull(),
240
+ fromKind: sqliteCore.text("from_kind").notNull(),
241
+ fromId: sqliteCore.text("from_id").notNull(),
242
+ toKind: sqliteCore.text("to_kind").notNull(),
243
+ toId: sqliteCore.text("to_id").notNull(),
244
+ props: sqliteCore.text("props").notNull(),
245
+ validFrom: sqliteCore.text("valid_from"),
246
+ validTo: sqliteCore.text("valid_to"),
247
+ createdAt: sqliteCore.text("created_at").notNull(),
248
+ updatedAt: sqliteCore.text("updated_at").notNull(),
249
+ deletedAt: sqliteCore.text("deleted_at")
253
250
  },
254
251
  (t) => [
255
- pgCore.primaryKey({ columns: [t.graphId, t.id] }),
256
- pgCore.index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
252
+ sqliteCore.primaryKey({ columns: [t.graphId, t.id] }),
253
+ sqliteCore.index(`${n.edges}_kind_idx`).on(t.graphId, t.kind),
257
254
  // Directional traversal index (outgoing): supports endpoint lookups
258
255
  // and extra filtering by edge kind / target kind.
259
- pgCore.index(`${n.edges}_from_idx`).on(
256
+ sqliteCore.index(`${n.edges}_from_idx`).on(
260
257
  t.graphId,
261
258
  t.fromKind,
262
259
  t.fromId,
@@ -266,7 +263,7 @@ function createPostgresTables(names = {}, options = {}) {
266
263
  t.validTo
267
264
  ),
268
265
  // Directional traversal index (incoming): mirrors from_idx for reverse traversals.
269
- pgCore.index(`${n.edges}_to_idx`).on(
266
+ sqliteCore.index(`${n.edges}_to_idx`).on(
270
267
  t.graphId,
271
268
  t.toKind,
272
269
  t.toId,
@@ -275,83 +272,87 @@ function createPostgresTables(names = {}, options = {}) {
275
272
  t.deletedAt,
276
273
  t.validTo
277
274
  ),
278
- pgCore.index(`${n.edges}_kind_created_idx`).on(
275
+ sqliteCore.index(`${n.edges}_kind_created_idx`).on(
279
276
  t.graphId,
280
277
  t.kind,
281
278
  t.deletedAt,
282
279
  t.createdAt
283
280
  ),
284
- pgCore.index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
285
- pgCore.index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
286
- pgCore.index(`${n.edges}_cardinality_idx`).on(
281
+ sqliteCore.index(`${n.edges}_deleted_idx`).on(t.graphId, t.deletedAt),
282
+ sqliteCore.index(`${n.edges}_valid_idx`).on(t.graphId, t.validFrom, t.validTo),
283
+ sqliteCore.index(`${n.edges}_cardinality_idx`).on(
287
284
  t.graphId,
288
285
  t.kind,
289
286
  t.fromKind,
290
287
  t.fromId,
291
288
  t.validTo
292
289
  ),
293
- ...chunkJQDWEX6V_cjs.buildPostgresEdgeIndexBuilders(t, indexes)
290
+ ...chunkLELLOHJK_cjs.buildSqliteEdgeIndexBuilders(t, indexes)
294
291
  ]
295
292
  );
296
- const uniques3 = pgCore.pgTable(
293
+ const uniques3 = sqliteCore.sqliteTable(
297
294
  n.uniques,
298
295
  {
299
- graphId: pgCore.text("graph_id").notNull(),
300
- nodeKind: pgCore.text("node_kind").notNull(),
301
- constraintName: pgCore.text("constraint_name").notNull(),
302
- key: pgCore.text("key").notNull(),
303
- nodeId: pgCore.text("node_id").notNull(),
304
- concreteKind: pgCore.text("concrete_kind").notNull(),
305
- deletedAt: pgCore.timestamp("deleted_at", { withTimezone: true })
296
+ graphId: sqliteCore.text("graph_id").notNull(),
297
+ nodeKind: sqliteCore.text("node_kind").notNull(),
298
+ constraintName: sqliteCore.text("constraint_name").notNull(),
299
+ key: sqliteCore.text("key").notNull(),
300
+ nodeId: sqliteCore.text("node_id").notNull(),
301
+ concreteKind: sqliteCore.text("concrete_kind").notNull(),
302
+ deletedAt: sqliteCore.text("deleted_at")
306
303
  },
307
304
  (t) => [
308
- pgCore.primaryKey({
305
+ sqliteCore.primaryKey({
309
306
  columns: [t.graphId, t.nodeKind, t.constraintName, t.key]
310
307
  }),
311
- pgCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
308
+ sqliteCore.index(`${n.uniques}_node_idx`).on(t.graphId, t.concreteKind, t.nodeId)
312
309
  ]
313
310
  );
314
- const schemaVersions3 = pgCore.pgTable(
311
+ const schemaVersions3 = sqliteCore.sqliteTable(
315
312
  n.schemaVersions,
316
313
  {
317
- graphId: pgCore.text("graph_id").notNull(),
318
- version: pgCore.integer("version").notNull(),
319
- schemaHash: pgCore.text("schema_hash").notNull(),
320
- schemaDoc: pgCore.jsonb("schema_doc").notNull(),
321
- createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
322
- isActive: pgCore.boolean("is_active").notNull().default(false)
314
+ graphId: sqliteCore.text("graph_id").notNull(),
315
+ version: sqliteCore.integer("version").notNull(),
316
+ schemaHash: sqliteCore.text("schema_hash").notNull(),
317
+ schemaDoc: sqliteCore.text("schema_doc").notNull(),
318
+ createdAt: sqliteCore.text("created_at").notNull(),
319
+ isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(false)
323
320
  },
324
321
  (t) => [
325
- pgCore.primaryKey({ columns: [t.graphId, t.version] }),
326
- pgCore.index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
322
+ sqliteCore.primaryKey({ columns: [t.graphId, t.version] }),
323
+ sqliteCore.index(`${n.schemaVersions}_active_idx`).on(t.graphId, t.isActive)
327
324
  ]
328
325
  );
329
- const embeddings3 = pgCore.pgTable(
326
+ const embeddings3 = sqliteCore.sqliteTable(
330
327
  n.embeddings,
331
328
  {
332
- graphId: pgCore.text("graph_id").notNull(),
333
- nodeKind: pgCore.text("node_kind").notNull(),
334
- nodeId: pgCore.text("node_id").notNull(),
335
- fieldPath: pgCore.text("field_path").notNull(),
336
- /** Embedding vector stored as native pgvector type */
337
- embedding: vector("embedding").notNull(),
329
+ graphId: sqliteCore.text("graph_id").notNull(),
330
+ nodeKind: sqliteCore.text("node_kind").notNull(),
331
+ nodeId: sqliteCore.text("node_id").notNull(),
332
+ fieldPath: sqliteCore.text("field_path").notNull(),
333
+ /**
334
+ * Embedding vector.
335
+ * Stored as BLOB for sqlite-vec binary format, or JSON text for fallback.
336
+ * For sqlite-vec: use vec_f32() to convert JSON array to binary.
337
+ */
338
+ embedding: sqliteCore.blob("embedding", { mode: "buffer" }).notNull(),
338
339
  /** Number of dimensions (for validation) */
339
- dimensions: pgCore.integer("dimensions").notNull(),
340
- createdAt: pgCore.timestamp("created_at", { withTimezone: true }).notNull(),
341
- updatedAt: pgCore.timestamp("updated_at", { withTimezone: true }).notNull()
340
+ dimensions: sqliteCore.integer("dimensions").notNull(),
341
+ createdAt: sqliteCore.text("created_at").notNull(),
342
+ updatedAt: sqliteCore.text("updated_at").notNull()
342
343
  },
343
344
  (t) => [
344
- pgCore.primaryKey({
345
+ sqliteCore.primaryKey({
345
346
  columns: [t.graphId, t.nodeKind, t.nodeId, t.fieldPath]
346
347
  }),
347
348
  // Index for looking up embeddings by node
348
- pgCore.index(`${n.embeddings}_node_idx`).on(
349
+ sqliteCore.index(`${n.embeddings}_node_idx`).on(
349
350
  t.graphId,
350
351
  t.nodeKind,
351
352
  t.nodeId
352
353
  ),
353
354
  // Index for filtering by kind and field (used in vector search)
354
- pgCore.index(`${n.embeddings}_kind_field_idx`).on(
355
+ sqliteCore.index(`${n.embeddings}_kind_field_idx`).on(
355
356
  t.graphId,
356
357
  t.nodeKind,
357
358
  t.fieldPath
@@ -360,7 +361,7 @@ function createPostgresTables(names = {}, options = {}) {
360
361
  );
361
362
  return { nodes: nodes3, edges: edges3, uniques: uniques3, schemaVersions: schemaVersions3, embeddings: embeddings3 };
362
363
  }
363
- var tables2 = createPostgresTables();
364
+ var tables2 = createSqliteTables();
364
365
  var { nodes: nodes2, edges: edges2, uniques: uniques2, schemaVersions: schemaVersions2, embeddings: embeddings2 } = tables2;
365
366
  function getSqliteColumnType(column) {
366
367
  switch (column.columnType) {
@@ -480,7 +481,7 @@ function generateSqliteCreateIndexSQL(table) {
480
481
  }
481
482
  return statements;
482
483
  }
483
- function generateSqliteDDL(tables3 = tables) {
484
+ function generateSqliteDDL(tables3 = tables2) {
484
485
  const statements = [];
485
486
  for (const table of Object.values(tables3)) {
486
487
  statements.push(generateSqliteCreateTableSQL(table));
@@ -490,7 +491,7 @@ function generateSqliteDDL(tables3 = tables) {
490
491
  }
491
492
  return statements;
492
493
  }
493
- function generateSqliteMigrationSQL(tables3 = tables) {
494
+ function generateSqliteMigrationSQL(tables3 = tables2) {
494
495
  return generateSqliteDDL(tables3).join("\n\n");
495
496
  }
496
497
  function getPgColumnType(column) {
@@ -572,7 +573,7 @@ function generatePgCreateIndexSQL(table) {
572
573
  }
573
574
  return statements;
574
575
  }
575
- function generatePostgresDDL(tables3 = tables2) {
576
+ function generatePostgresDDL(tables3 = tables) {
576
577
  const statements = [];
577
578
  for (const table of Object.values(tables3)) {
578
579
  statements.push(generatePgCreateTableSQL(table));
@@ -582,7 +583,7 @@ function generatePostgresDDL(tables3 = tables2) {
582
583
  }
583
584
  return statements;
584
585
  }
585
- function generatePostgresMigrationSQL(tables3 = tables2) {
586
+ function generatePostgresMigrationSQL(tables3 = tables) {
586
587
  const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
587
588
  const ddlSql = generatePostgresDDL(tables3).join("\n\n");
588
589
  return `${extensionSql}
@@ -626,6 +627,24 @@ function requireTimestamp(value, field) {
626
627
  }
627
628
  return value;
628
629
  }
630
+ function asString(value, field) {
631
+ if (typeof value !== "string") {
632
+ throw new chunk44SXEVF4_cjs.DatabaseOperationError(
633
+ `Expected ${field} to be string, got ${typeof value}`,
634
+ { operation: "select", entity: "row" }
635
+ );
636
+ }
637
+ return value;
638
+ }
639
+ function asNumber(value, field) {
640
+ if (typeof value !== "number") {
641
+ throw new chunk44SXEVF4_cjs.DatabaseOperationError(
642
+ `Expected ${field} to be number, got ${typeof value}`,
643
+ { operation: "select", entity: "row" }
644
+ );
645
+ }
646
+ return value;
647
+ }
629
648
  function nowIso() {
630
649
  return (/* @__PURE__ */ new Date()).toISOString();
631
650
  }
@@ -647,8 +666,25 @@ function normalizeJsonColumn(value) {
647
666
  return typeof value === "string" ? value : JSON.stringify(value ?? {});
648
667
  }
649
668
  var SQLITE_ROW_MAPPER_CONFIG = {
650
- formatTimestamp: (value) => nullToUndefined(value),
651
- normalizeJson: (value) => value
669
+ formatTimestamp: (value) => {
670
+ if (value === null || value === void 0) return;
671
+ if (typeof value !== "string") {
672
+ throw new chunk44SXEVF4_cjs.DatabaseOperationError(
673
+ `Expected timestamp to be string, got ${typeof value}`,
674
+ { operation: "select", entity: "row" }
675
+ );
676
+ }
677
+ return value;
678
+ },
679
+ normalizeJson: (value) => {
680
+ if (typeof value !== "string") {
681
+ throw new chunk44SXEVF4_cjs.DatabaseOperationError(
682
+ `Expected JSON column to be string, got ${typeof value}`,
683
+ { operation: "select", entity: "row" }
684
+ );
685
+ }
686
+ return value;
687
+ }
652
688
  };
653
689
  var POSTGRES_ROW_MAPPER_CONFIG = {
654
690
  formatTimestamp: formatPostgresTimestamp,
@@ -656,11 +692,11 @@ var POSTGRES_ROW_MAPPER_CONFIG = {
656
692
  };
657
693
  function createNodeRowMapper(config) {
658
694
  return (row) => ({
659
- graph_id: row.graph_id,
660
- kind: row.kind,
661
- id: row.id,
695
+ graph_id: asString(row.graph_id, "graph_id"),
696
+ kind: asString(row.kind, "kind"),
697
+ id: asString(row.id, "id"),
662
698
  props: config.normalizeJson(row.props),
663
- version: row.version,
699
+ version: asNumber(row.version, "version"),
664
700
  valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
665
701
  valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
666
702
  created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
@@ -670,13 +706,13 @@ function createNodeRowMapper(config) {
670
706
  }
671
707
  function createEdgeRowMapper(config) {
672
708
  return (row) => ({
673
- graph_id: row.graph_id,
674
- id: row.id,
675
- kind: row.kind,
676
- from_kind: row.from_kind,
677
- from_id: row.from_id,
678
- to_kind: row.to_kind,
679
- to_id: row.to_id,
709
+ graph_id: asString(row.graph_id, "graph_id"),
710
+ id: asString(row.id, "id"),
711
+ kind: asString(row.kind, "kind"),
712
+ from_kind: asString(row.from_kind, "from_kind"),
713
+ from_id: asString(row.from_id, "from_id"),
714
+ to_kind: asString(row.to_kind, "to_kind"),
715
+ to_id: asString(row.to_id, "to_id"),
680
716
  props: config.normalizeJson(row.props),
681
717
  valid_from: nullToUndefined(config.formatTimestamp(row.valid_from)),
682
718
  valid_to: nullToUndefined(config.formatTimestamp(row.valid_to)),
@@ -687,12 +723,12 @@ function createEdgeRowMapper(config) {
687
723
  }
688
724
  function createUniqueRowMapper(config) {
689
725
  return (row) => ({
690
- graph_id: row.graph_id,
691
- node_kind: row.node_kind,
692
- constraint_name: row.constraint_name,
693
- key: row.key,
694
- node_id: row.node_id,
695
- concrete_kind: row.concrete_kind,
726
+ graph_id: asString(row.graph_id, "graph_id"),
727
+ node_kind: asString(row.node_kind, "node_kind"),
728
+ constraint_name: asString(row.constraint_name, "constraint_name"),
729
+ key: asString(row.key, "key"),
730
+ node_id: asString(row.node_id, "node_id"),
731
+ concrete_kind: asString(row.concrete_kind, "concrete_kind"),
696
732
  deleted_at: nullToUndefined(config.formatTimestamp(row.deleted_at))
697
733
  });
698
734
  }
@@ -701,9 +737,9 @@ function createSchemaVersionRowMapper(config) {
701
737
  const isActiveValue = row.is_active;
702
738
  const isActive = isActiveValue === true || isActiveValue === 1 || isActiveValue === "1";
703
739
  return {
704
- graph_id: row.graph_id,
705
- version: row.version,
706
- schema_hash: row.schema_hash,
740
+ graph_id: asString(row.graph_id, "graph_id"),
741
+ version: asNumber(row.version, "version"),
742
+ schema_hash: asString(row.schema_hash, "schema_hash"),
707
743
  schema_doc: config.normalizeJson(row.schema_doc),
708
744
  created_at: requireTimestamp(config.formatTimestamp(row.created_at), "created_at"),
709
745
  is_active: isActive
@@ -992,10 +1028,14 @@ function buildTemporalConditions(table, params) {
992
1028
  conditions.push(drizzleOrm.sql`${table.deletedAt} IS NULL`);
993
1029
  }
994
1030
  if (mode === "current" || mode === "asOf") {
995
- const asOf = params.asOf;
1031
+ if (params.asOf === void 0) {
1032
+ throw new Error(
1033
+ `asOf timestamp is required for temporal mode "${mode}"`
1034
+ );
1035
+ }
996
1036
  conditions.push(
997
- drizzleOrm.sql`(${table.validFrom} IS NULL OR ${table.validFrom} <= ${asOf})`,
998
- drizzleOrm.sql`(${table.validTo} IS NULL OR ${table.validTo} > ${asOf})`
1037
+ drizzleOrm.sql`(${table.validFrom} IS NULL OR ${table.validFrom} <= ${params.asOf})`,
1038
+ drizzleOrm.sql`(${table.validTo} IS NULL OR ${table.validTo} > ${params.asOf})`
999
1039
  );
1000
1040
  }
1001
1041
  return conditions;
@@ -1909,7 +1949,6 @@ function assertSafeIdentifier(value, name) {
1909
1949
  );
1910
1950
  }
1911
1951
  }
1912
- var MAX_IDENTIFIER_LENGTH = 63;
1913
1952
  function sanitizeIdentifier(s) {
1914
1953
  return s.toLowerCase().replaceAll(/[^a-z0-9_]/g, "_");
1915
1954
  }
@@ -1939,11 +1978,11 @@ function generateVectorIndexName(graphId, nodeKind, fieldPath, metric = "cosine"
1939
1978
  metric
1940
1979
  ];
1941
1980
  const name = parts.join("_");
1942
- if (name.length <= MAX_IDENTIFIER_LENGTH) {
1981
+ if (name.length <= chunkMME3H4ZF_cjs.MAX_PG_IDENTIFIER_LENGTH) {
1943
1982
  return name;
1944
1983
  }
1945
1984
  const hash = shortHash(name);
1946
- const truncated = name.slice(0, MAX_IDENTIFIER_LENGTH - 1 - hash.length);
1985
+ const truncated = name.slice(0, chunkMME3H4ZF_cjs.MAX_PG_IDENTIFIER_LENGTH - 1 - hash.length);
1947
1986
  return `${truncated}_${hash}`;
1948
1987
  }
1949
1988
  function getOperatorClass(metric) {
@@ -2121,5 +2160,5 @@ exports.tables = tables;
2121
2160
  exports.tables2 = tables2;
2122
2161
  exports.uniques = uniques;
2123
2162
  exports.uniques2 = uniques2;
2124
- //# sourceMappingURL=chunk-2XPKLHHH.cjs.map
2125
- //# sourceMappingURL=chunk-2XPKLHHH.cjs.map
2163
+ //# sourceMappingURL=chunk-CRMN2NOM.cjs.map
2164
+ //# sourceMappingURL=chunk-CRMN2NOM.cjs.map