@nicia-ai/typegraph 0.37.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkJBNOGRKW_cjs = require('../../chunk-JBNOGRKW.cjs');
3
+ var chunkEJYMTO3K_cjs = require('../../chunk-EJYMTO3K.cjs');
4
4
  var chunkDIQ3AV5W_cjs = require('../../chunk-DIQ3AV5W.cjs');
5
5
  var chunk3C2RYI6L_cjs = require('../../chunk-3C2RYI6L.cjs');
6
6
  require('../../chunk-XPCZADMT.cjs');
@@ -20,7 +20,7 @@ require('../../chunk-TDXIBCGY.cjs');
20
20
 
21
21
  Object.defineProperty(exports, "createSqliteBackend", {
22
22
  enumerable: true,
23
- get: function () { return chunkJBNOGRKW_cjs.createSqliteBackend; }
23
+ get: function () { return chunkEJYMTO3K_cjs.createSqliteBackend; }
24
24
  });
25
25
  Object.defineProperty(exports, "generateSqliteDDL", {
26
26
  enumerable: true,
@@ -1,4 +1,4 @@
1
- export { createSqliteBackend } from '../../chunk-J4IUSYFF.js';
1
+ export { createSqliteBackend } from '../../chunk-UV3WP5WZ.js';
2
2
  export { generateSqliteDDL, generateSqliteMigrationSQL } from '../../chunk-K3Q3LJY3.js';
3
3
  export { createSqliteTables, edges, nodes, recordedClock, recordedEdges, recordedNodes, schemaVersions, tables, uniques } from '../../chunk-UXLSNRYL.js';
4
4
  import '../../chunk-QERAIDRJ.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkJBNOGRKW_cjs = require('../../chunk-JBNOGRKW.cjs');
3
+ var chunkEJYMTO3K_cjs = require('../../chunk-EJYMTO3K.cjs');
4
4
  var chunkDIQ3AV5W_cjs = require('../../chunk-DIQ3AV5W.cjs');
5
5
  var chunk2N6EOBTH_cjs = require('../../chunk-2N6EOBTH.cjs');
6
6
  require('../../chunk-CUHM5CWJ.cjs');
@@ -24,7 +24,7 @@ async function createLibsqlBackend(client, options = {}) {
24
24
  const db = libsql.drizzle(client);
25
25
  const ddlStatements = chunkDIQ3AV5W_cjs.generateSqliteDDL(tables2);
26
26
  await client.executeMultiple(ddlStatements.join(";\n"));
27
- const backend = chunkJBNOGRKW_cjs.createSqliteBackend(db, {
27
+ const backend = chunkEJYMTO3K_cjs.createSqliteBackend(db, {
28
28
  executionProfile: {
29
29
  isSync: false,
30
30
  transactionMode: client.protocol === "file" ? "sql" : "drizzle"
@@ -1,4 +1,4 @@
1
- import { createSqliteBackend } from '../../chunk-J4IUSYFF.js';
1
+ import { createSqliteBackend } from '../../chunk-UV3WP5WZ.js';
2
2
  import { generateSqliteDDL } from '../../chunk-K3Q3LJY3.js';
3
3
  import { libsqlVectorStrategy } from '../../chunk-XWV4JT34.js';
4
4
  import '../../chunk-DFVLCOP6.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkJBNOGRKW_cjs = require('../../chunk-JBNOGRKW.cjs');
3
+ var chunkEJYMTO3K_cjs = require('../../chunk-EJYMTO3K.cjs');
4
4
  var chunkDIQ3AV5W_cjs = require('../../chunk-DIQ3AV5W.cjs');
5
5
  var chunk3XXGYU62_cjs = require('../../chunk-3XXGYU62.cjs');
6
6
  require('../../chunk-CUHM5CWJ.cjs');
@@ -154,7 +154,7 @@ function createLocalSqliteBackend(options = {}) {
154
154
  for (const statement of ddlStatements) {
155
155
  sqlite.exec(statement);
156
156
  }
157
- const backend = chunkJBNOGRKW_cjs.createSqliteBackend(db, {
157
+ const backend = chunkEJYMTO3K_cjs.createSqliteBackend(db, {
158
158
  executionProfile: {
159
159
  isSync: true
160
160
  },
@@ -1,4 +1,4 @@
1
- import { createSqliteBackend } from '../../chunk-J4IUSYFF.js';
1
+ import { createSqliteBackend } from '../../chunk-UV3WP5WZ.js';
2
2
  import { generateSqliteDDL } from '../../chunk-K3Q3LJY3.js';
3
3
  import { sqliteVecStrategy } from '../../chunk-UYQMBBWJ.js';
4
4
  import '../../chunk-DFVLCOP6.js';
@@ -10738,6 +10738,13 @@ function buildCompileTimeReferentIndex(graph, runtimeEdgeNames) {
10738
10738
  // src/store/algorithms/context.ts
10739
10739
  var DEFAULT_ALGORITHM_MAX_HOPS = 10;
10740
10740
  var DEFAULT_NEIGHBOR_DEPTH = 1;
10741
+ function pickTemporalOptions(options) {
10742
+ return {
10743
+ ...options.temporalMode === void 0 ? {} : { temporalMode: options.temporalMode },
10744
+ ...options.asOf === void 0 ? {} : { asOf: options.asOf },
10745
+ ...options.recordedAsOf === void 0 ? {} : { recordedAsOf: options.recordedAsOf }
10746
+ };
10747
+ }
10741
10748
  function resolveTemporalOptions(ctx, options) {
10742
10749
  const { valid } = chunkWOJMKB3N_cjs.resolveReadCoordinate(
10743
10750
  options.temporalMode ?? ctx.defaultTemporalMode,
@@ -10852,6 +10859,11 @@ function compileDirectionFilter(ctx, direction, nodeId, nodesTable) {
10852
10859
  }
10853
10860
  }
10854
10861
  }
10862
+ function frontierIndexIdentifier(context) {
10863
+ return drizzleOrm.sql.identifier(
10864
+ `typegraph_iterative_${context.runId.replaceAll("-", "_")}_frontier`
10865
+ );
10866
+ }
10855
10867
  var DEFAULT_MAX_BIND_PARAMETERS = 999;
10856
10868
  var RESERVED_TEMPORAL_BIND_PARAMETERS_PER_BRANCH = 12;
10857
10869
  var RESERVED_WEIGHT_BIND_PARAMETERS_PER_BRANCH = 4;
@@ -11043,147 +11055,90 @@ function nodeIdentityKeyFromRow(id, kind) {
11043
11055
  return nodeIdentityKey({ id, kind });
11044
11056
  }
11045
11057
  function compareNodeIdentity(left, right) {
11046
- return chunkA42GCBGX_cjs.compareStrings(left.id, right.id) || chunkA42GCBGX_cjs.compareStrings(left.kind, right.kind);
11058
+ return chunkA42GCBGX_cjs.compareCodePoints(left.id, right.id) || chunkA42GCBGX_cjs.compareCodePoints(left.kind, right.kind);
11047
11059
  }
11048
- function compileExpansionQuery(operation, workingSet, direction, edgeKinds) {
11049
- const workingValues = drizzleOrm.sql.join(
11050
- workingSet.map((node) => drizzleOrm.sql`(${node.id}, ${node.kind})`),
11051
- drizzleOrm.sql`, `
11052
- );
11053
- const workingCte = drizzleOrm.sql`WITH working_set(node_id, node_kind) AS (VALUES ${workingValues})`;
11060
+ var OUTGOING_DIRECTION_FIELDS = {
11061
+ joinField: "from_id",
11062
+ joinKindField: "from_kind",
11063
+ targetField: "to_id",
11064
+ targetKindField: "to_kind"
11065
+ };
11066
+ var INCOMING_DIRECTION_FIELDS = {
11067
+ joinField: "to_id",
11068
+ joinKindField: "to_kind",
11069
+ targetField: "from_id",
11070
+ targetKindField: "from_kind"
11071
+ };
11072
+ function fieldsForDirection(direction) {
11054
11073
  switch (direction) {
11055
11074
  case "out": {
11056
- return drizzleOrm.sql`${workingCte} ${compileDirectionalExpansion(operation, drizzleOrm.sql`working_set`, drizzleOrm.sql`TRUE`, edgeKinds, "from_id", "from_kind", "to_id", "to_kind")}`;
11075
+ return [OUTGOING_DIRECTION_FIELDS];
11057
11076
  }
11058
11077
  case "in": {
11059
- return drizzleOrm.sql`${workingCte} ${compileDirectionalExpansion(operation, drizzleOrm.sql`working_set`, drizzleOrm.sql`TRUE`, edgeKinds, "to_id", "to_kind", "from_id", "from_kind")}`;
11078
+ return [INCOMING_DIRECTION_FIELDS];
11060
11079
  }
11061
11080
  case "both": {
11062
- const outgoing = compileDirectionalExpansion(
11063
- operation,
11064
- drizzleOrm.sql`working_set`,
11065
- drizzleOrm.sql`TRUE`,
11066
- edgeKinds,
11067
- "from_id",
11068
- "from_kind",
11069
- "to_id",
11070
- "to_kind"
11071
- );
11072
- const incoming = compileDirectionalExpansion(
11073
- operation,
11074
- drizzleOrm.sql`working_set`,
11075
- drizzleOrm.sql`TRUE`,
11076
- edgeKinds,
11077
- "to_id",
11078
- "to_kind",
11079
- "from_id",
11080
- "from_kind"
11081
- );
11082
- return drizzleOrm.sql`${workingCte} ${outgoing} UNION ALL ${incoming}`;
11081
+ return [OUTGOING_DIRECTION_FIELDS, INCOMING_DIRECTION_FIELDS];
11083
11082
  }
11084
11083
  }
11085
11084
  }
11085
+ function compileDirectionUnion(direction, compileDirection) {
11086
+ return drizzleOrm.sql.join(
11087
+ fieldsForDirection(direction).map((fields) => compileDirection(fields)),
11088
+ drizzleOrm.sql` UNION ALL `
11089
+ );
11090
+ }
11091
+ function compileExpansionQuery(operation, workingSet, direction, edgeKinds) {
11092
+ const workingValues = drizzleOrm.sql.join(
11093
+ workingSet.map((node) => drizzleOrm.sql`(${node.id}, ${node.kind})`),
11094
+ drizzleOrm.sql`, `
11095
+ );
11096
+ const workingCte = drizzleOrm.sql`WITH working_set(node_id, node_kind) AS (VALUES ${workingValues})`;
11097
+ const expansion = compileDirectionUnion(
11098
+ direction,
11099
+ (fields) => compileDirectionalExpansion(
11100
+ operation,
11101
+ drizzleOrm.sql`working_set`,
11102
+ drizzleOrm.sql`TRUE`,
11103
+ edgeKinds,
11104
+ fields.joinField,
11105
+ fields.joinKindField,
11106
+ fields.targetField,
11107
+ fields.targetKindField
11108
+ )
11109
+ );
11110
+ return drizzleOrm.sql`${workingCte} ${expansion}`;
11111
+ }
11086
11112
  function compileWorkingTableExpansion(operation, workingTable, sourceFilter, direction, edgeKinds) {
11087
- switch (direction) {
11088
- case "out": {
11089
- return compileDirectionalExpansion(
11090
- operation,
11091
- workingTable,
11092
- sourceFilter,
11093
- edgeKinds,
11094
- "from_id",
11095
- "from_kind",
11096
- "to_id",
11097
- "to_kind"
11098
- );
11099
- }
11100
- case "in": {
11101
- return compileDirectionalExpansion(
11102
- operation,
11103
- workingTable,
11104
- sourceFilter,
11105
- edgeKinds,
11106
- "to_id",
11107
- "to_kind",
11108
- "from_id",
11109
- "from_kind"
11110
- );
11111
- }
11112
- case "both": {
11113
- const outgoing = compileDirectionalExpansion(
11114
- operation,
11115
- workingTable,
11116
- sourceFilter,
11117
- edgeKinds,
11118
- "from_id",
11119
- "from_kind",
11120
- "to_id",
11121
- "to_kind"
11122
- );
11123
- const incoming = compileDirectionalExpansion(
11124
- operation,
11125
- workingTable,
11126
- sourceFilter,
11127
- edgeKinds,
11128
- "to_id",
11129
- "to_kind",
11130
- "from_id",
11131
- "from_kind"
11132
- );
11133
- return drizzleOrm.sql`${outgoing} UNION ALL ${incoming}`;
11134
- }
11135
- }
11113
+ return compileDirectionUnion(
11114
+ direction,
11115
+ (fields) => compileDirectionalExpansion(
11116
+ operation,
11117
+ workingTable,
11118
+ sourceFilter,
11119
+ edgeKinds,
11120
+ fields.joinField,
11121
+ fields.joinKindField,
11122
+ fields.targetField,
11123
+ fields.targetKindField
11124
+ )
11125
+ );
11136
11126
  }
11137
- function compileWorkingTableEdgeExpansion(operation, workingTable, sourceFilter, direction, edgeKinds) {
11138
- switch (direction) {
11139
- case "out": {
11140
- return compileDirectionalEdgeExpansion(
11141
- operation,
11142
- workingTable,
11143
- sourceFilter,
11144
- edgeKinds,
11145
- "from_id",
11146
- "from_kind",
11147
- "to_id",
11148
- "to_kind"
11149
- );
11150
- }
11151
- case "in": {
11152
- return compileDirectionalEdgeExpansion(
11153
- operation,
11154
- workingTable,
11155
- sourceFilter,
11156
- edgeKinds,
11157
- "to_id",
11158
- "to_kind",
11159
- "from_id",
11160
- "from_kind"
11161
- );
11162
- }
11163
- case "both": {
11164
- const outgoing = compileDirectionalEdgeExpansion(
11165
- operation,
11166
- workingTable,
11167
- sourceFilter,
11168
- edgeKinds,
11169
- "from_id",
11170
- "from_kind",
11171
- "to_id",
11172
- "to_kind"
11173
- );
11174
- const incoming = compileDirectionalEdgeExpansion(
11175
- operation,
11176
- workingTable,
11177
- sourceFilter,
11178
- edgeKinds,
11179
- "to_id",
11180
- "to_kind",
11181
- "from_id",
11182
- "from_kind"
11183
- );
11184
- return drizzleOrm.sql`${outgoing} UNION ALL ${incoming}`;
11185
- }
11186
- }
11127
+ function compileWorkingTableEdgeExpansion(operation, workingTable, sourceFilter, direction, edgeKinds, sourceProjection) {
11128
+ return compileDirectionUnion(
11129
+ direction,
11130
+ (fields) => compileDirectionalEdgeExpansion(
11131
+ operation,
11132
+ workingTable,
11133
+ sourceFilter,
11134
+ edgeKinds,
11135
+ fields.joinField,
11136
+ fields.joinKindField,
11137
+ fields.targetField,
11138
+ fields.targetKindField,
11139
+ sourceProjection
11140
+ )
11141
+ );
11187
11142
  }
11188
11143
  function compileDirectionalExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField) {
11189
11144
  const edgeExpansion = compileDirectionalEdgeExpansion(
@@ -11199,10 +11154,11 @@ function compileDirectionalExpansion(operation, workingRelation, sourceFilter, e
11199
11154
  const weightColumn = operation.weightExpression === void 0 ? drizzleOrm.sql`` : drizzleOrm.sql`, expanded.weight`;
11200
11155
  return drizzleOrm.sql`SELECT expanded.source_id, expanded.source_kind, n.id AS target_id, n.kind AS target_kind${weightColumn} FROM (${edgeExpansion}) expanded JOIN ${operation.schema.nodesTable} n ON n.graph_id = ${operation.ctx.graphId} AND n.id = expanded.target_id AND n.kind = expanded.target_kind WHERE ${operation.nodeTemporalFilter}`;
11201
11156
  }
11202
- function compileDirectionalEdgeExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField) {
11157
+ function compileDirectionalEdgeExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField, sourceProjection) {
11203
11158
  const edgeKindFilter = chunkIPSVVTWT_cjs.compileKindFilter(drizzleOrm.sql.raw("e.kind"), edgeKinds);
11204
11159
  const weightColumn = operation.weightExpression === void 0 ? drizzleOrm.sql`` : drizzleOrm.sql`, ${operation.weightExpression} AS weight`;
11205
- return drizzleOrm.sql`SELECT w.node_id AS source_id, w.node_kind AS source_kind, e.${drizzleOrm.sql.raw(targetField)} AS target_id, e.${drizzleOrm.sql.raw(targetKindField)} AS target_kind${weightColumn} FROM ${workingRelation} w JOIN ${operation.schema.edgesTable} e ON e.${drizzleOrm.sql.raw(joinField)} = w.node_id AND e.${drizzleOrm.sql.raw(joinKindField)} = w.node_kind AND e.graph_id = ${operation.ctx.graphId} WHERE ${sourceFilter} AND ${edgeKindFilter} AND ${operation.edgeTemporalFilter}`;
11160
+ const sourceColumns = sourceProjection === void 0 ? drizzleOrm.sql`` : drizzleOrm.sql`, ${sourceProjection}`;
11161
+ return drizzleOrm.sql`SELECT w.node_id AS source_id, w.node_kind AS source_kind${sourceColumns}, e.${drizzleOrm.sql.raw(targetField)} AS target_id, e.${drizzleOrm.sql.raw(targetKindField)} AS target_kind${weightColumn} FROM ${workingRelation} w JOIN ${operation.schema.edgesTable} e ON e.${drizzleOrm.sql.raw(joinField)} = w.node_id AND e.${drizzleOrm.sql.raw(joinKindField)} = w.node_kind AND e.graph_id = ${operation.ctx.graphId} WHERE ${sourceFilter} AND ${edgeKindFilter} AND ${operation.edgeTemporalFilter}`;
11206
11162
  }
11207
11163
  function chunkValues(values, chunkSize) {
11208
11164
  const chunks = [];
@@ -11285,7 +11241,7 @@ function compileWeightExpression(dialect, weightProperty, defaultWeight) {
11285
11241
  return defaultWeight === void 0 ? extracted : drizzleOrm.sql`COALESCE(${extracted}, ${defaultWeight})`;
11286
11242
  }
11287
11243
  function supportsTemporaryIteration(ctx) {
11288
- return ctx.backend.capabilities.transactions && ctx.backend.capabilities.returning !== false && ctx.backend.executeTemporaryStatement !== void 0;
11244
+ return ctx.backend.capabilities.transactions && ctx.backend.capabilities.graphAnalytics?.supported !== false && ctx.backend.capabilities.returning !== false && ctx.backend.executeTemporaryStatement !== void 0;
11289
11245
  }
11290
11246
  function requireTemporaryStatements(backend) {
11291
11247
  if (backend.executeTemporaryStatement === void 0) {
@@ -11469,6 +11425,11 @@ async function expandWorkingTableRound(context, side, currentDepth, nextDepth, d
11469
11425
  const oppositeSide = side === "forward" ? "reverse" : "forward";
11470
11426
  let insertedCount = 0;
11471
11427
  let meeting;
11428
+ const { dialect } = context.operation.ctx;
11429
+ const targetKind = dialect.binaryText(drizzleOrm.sql`expanded.target_kind`);
11430
+ const targetId = dialect.binaryText(drizzleOrm.sql`expanded.target_id`);
11431
+ const sourceId = dialect.binaryText(drizzleOrm.sql`expanded.source_id`);
11432
+ const sourceKind = dialect.binaryText(drizzleOrm.sql`expanded.source_kind`);
11472
11433
  for (const edgeKinds of context.operation.edgeKindChunks) {
11473
11434
  const sourceFilter = drizzleOrm.sql`
11474
11435
  w.graph_id = ${context.graphId}
@@ -11504,8 +11465,8 @@ async function expandWorkingTableRound(context, side, currentDepth, nextDepth, d
11504
11465
  FROM (
11505
11466
  SELECT expanded.*,
11506
11467
  ROW_NUMBER() OVER (
11507
- PARTITION BY expanded.target_kind, expanded.target_id
11508
- ORDER BY expanded.source_id, expanded.source_kind
11468
+ PARTITION BY ${targetKind}, ${targetId}
11469
+ ORDER BY ${sourceId}, ${sourceKind}
11509
11470
  ) AS candidate_rank
11510
11471
  FROM (${expansion}) expanded
11511
11472
  ) ranked
@@ -11608,7 +11569,6 @@ async function readWorkingRows(context, side) {
11608
11569
  WHERE graph_id = ${context.graphId}
11609
11570
  AND run_id = ${context.runId}
11610
11571
  AND ${sideFilter}
11611
- ORDER BY side, depth, node_id, node_kind
11612
11572
  `)
11613
11573
  );
11614
11574
  }
@@ -11740,8 +11700,12 @@ function findMeetingNodeKey(candidates, activeVisited, oppositeVisited) {
11740
11700
  const active = activeVisited.get(key);
11741
11701
  const opposite = oppositeVisited.get(key);
11742
11702
  if (active === void 0 || opposite === void 0) continue;
11743
- const meeting = { key, depth: active.depth + opposite.depth };
11744
- if (best === void 0 || meeting.depth < best.depth || meeting.depth === best.depth && chunkA42GCBGX_cjs.compareStrings(meeting.key, best.key) < 0) {
11703
+ const meeting = {
11704
+ key,
11705
+ node: { id: candidate.id, kind: candidate.kind },
11706
+ depth: active.depth + opposite.depth
11707
+ };
11708
+ if (best === void 0 || meeting.depth < best.depth || meeting.depth === best.depth && compareNodeIdentity(meeting.node, best.node) < 0) {
11745
11709
  best = meeting;
11746
11710
  }
11747
11711
  }
@@ -11833,13 +11797,7 @@ async function executeNeighbors(ctx, sourceId, options) {
11833
11797
  maxHops: depth,
11834
11798
  direction: options.direction ?? "out",
11835
11799
  cyclePolicy: options.cyclePolicy ?? "prevent",
11836
- ...options.temporalMode !== void 0 && {
11837
- temporalMode: options.temporalMode
11838
- },
11839
- ...options.asOf !== void 0 && { asOf: options.asOf },
11840
- ...options.recordedAsOf !== void 0 && {
11841
- recordedAsOf: options.recordedAsOf
11842
- },
11800
+ ...pickTemporalOptions(options),
11843
11801
  ...options.workingMemory !== void 0 && {
11844
11802
  workingMemory: options.workingMemory
11845
11803
  },
@@ -11872,9 +11830,7 @@ async function executeWeaklyConnectedComponents(ctx, options) {
11872
11830
  const traversalOptions = {
11873
11831
  edges: options.edges,
11874
11832
  direction: "both",
11875
- ...options.temporalMode === void 0 ? {} : { temporalMode: options.temporalMode },
11876
- ...options.asOf === void 0 ? {} : { asOf: options.asOf },
11877
- ...options.recordedAsOf === void 0 ? {} : { recordedAsOf: options.recordedAsOf },
11833
+ ...pickTemporalOptions(options),
11878
11834
  ...options.workingMemory === void 0 ? {} : { workingMemory: options.workingMemory }
11879
11835
  };
11880
11836
  return runIterativeGraphOperation(ctx, traversalOptions, {
@@ -11915,6 +11871,7 @@ function createWorkingTable2(context) {
11915
11871
  label_kind TEXT NOT NULL,
11916
11872
  next_label_id TEXT NOT NULL,
11917
11873
  next_label_kind TEXT NOT NULL,
11874
+ improved_round INTEGER NOT NULL,
11918
11875
  PRIMARY KEY (graph_id, run_id, node_kind, node_id)
11919
11876
  )
11920
11877
  `;
@@ -11925,14 +11882,18 @@ async function initializeWorkingTable(context, nodeKinds) {
11925
11882
  await context.executeTemporary(drizzleOrm.sql`
11926
11883
  INSERT INTO ${workingTable}
11927
11884
  (graph_id, run_id, node_id, node_kind, label_id, label_kind,
11928
- next_label_id, next_label_kind)
11885
+ next_label_id, next_label_kind, improved_round)
11929
11886
  SELECT
11930
- ${graphId}, ${runId}, n.id, n.kind, n.id, n.kind, n.id, n.kind
11887
+ ${graphId}, ${runId}, n.id, n.kind, n.id, n.kind, n.id, n.kind, 0
11931
11888
  FROM ${operation.schema.nodesTable} n
11932
11889
  WHERE n.graph_id = ${graphId}
11933
11890
  AND ${nodeKindFilter}
11934
11891
  AND ${operation.nodeTemporalFilter}
11935
11892
  `);
11893
+ await context.executeTemporary(drizzleOrm.sql`
11894
+ CREATE INDEX ${frontierIndexIdentifier(context)}
11895
+ ON ${workingTable} (graph_id, run_id, improved_round)
11896
+ `);
11936
11897
  const rows = await context.backend.execute(
11937
11898
  chunkIPSVVTWT_cjs.asCompiledRowsSql(drizzleOrm.sql`
11938
11899
  SELECT COUNT(*) AS count
@@ -11943,32 +11904,29 @@ async function initializeWorkingTable(context, nodeKinds) {
11943
11904
  const workingTableSize = Number(rows[0]?.count ?? 0);
11944
11905
  return { changedCount: workingTableSize, workingTableSize };
11945
11906
  }
11946
- async function runLabelPropagationRound(context, state) {
11947
- await resetNextLabels(context);
11907
+ async function runLabelPropagationRound(context, state, iteration) {
11948
11908
  for (const edgeKinds of context.operation.edgeKindChunks) {
11949
- await propagateChunkLabels(context, edgeKinds);
11909
+ await propagateChunkLabels(context, edgeKinds, iteration);
11950
11910
  }
11951
- const changedRows = await applyNextLabels(context);
11911
+ const changedRows = await applyNextLabels(context, iteration);
11952
11912
  return {
11953
11913
  changedCount: changedRows.length,
11954
11914
  workingTableSize: state.workingTableSize
11955
11915
  };
11956
11916
  }
11957
- async function resetNextLabels(context) {
11958
- await context.executeTemporary(drizzleOrm.sql`
11959
- UPDATE ${context.workingTable}
11960
- SET next_label_id = label_id, next_label_kind = label_kind
11961
- WHERE graph_id = ${context.graphId} AND run_id = ${context.runId}
11962
- `);
11963
- }
11964
- async function propagateChunkLabels(context, edgeKinds) {
11917
+ async function propagateChunkLabels(context, edgeKinds, iteration) {
11965
11918
  const { operation, workingTable, graphId, runId } = context;
11966
11919
  const expansion = compileWorkingTableEdgeExpansion(
11967
11920
  operation,
11968
11921
  workingTable,
11969
- drizzleOrm.sql`w.graph_id = ${graphId} AND w.run_id = ${runId}`,
11922
+ drizzleOrm.sql`
11923
+ w.graph_id = ${graphId}
11924
+ AND w.run_id = ${runId}
11925
+ AND w.improved_round = ${iteration - 1}
11926
+ `,
11970
11927
  "both",
11971
- edgeKinds
11928
+ edgeKinds,
11929
+ drizzleOrm.sql`w.label_id AS source_label_id, w.label_kind AS source_label_kind`
11972
11930
  );
11973
11931
  const candidateId = operation.ctx.dialect.binaryText(drizzleOrm.sql`ranked.label_id`);
11974
11932
  const candidateKind = operation.ctx.dialect.binaryText(
@@ -11987,14 +11945,9 @@ async function propagateChunkLabels(context, edgeKinds) {
11987
11945
  SELECT
11988
11946
  expanded.target_id,
11989
11947
  expanded.target_kind,
11990
- source.label_id,
11991
- source.label_kind
11948
+ expanded.source_label_id AS label_id,
11949
+ expanded.source_label_kind AS label_kind
11992
11950
  FROM (${expansion}) expanded
11993
- JOIN ${workingTable} source
11994
- ON source.graph_id = ${graphId}
11995
- AND source.run_id = ${runId}
11996
- AND source.node_id = expanded.source_id
11997
- AND source.node_kind = expanded.source_kind
11998
11951
  JOIN ${workingTable} scoped_target
11999
11952
  ON scoped_target.graph_id = ${graphId}
12000
11953
  AND scoped_target.run_id = ${runId}
@@ -12030,11 +11983,13 @@ async function propagateChunkLabels(context, edgeKinds) {
12030
11983
  )
12031
11984
  `);
12032
11985
  }
12033
- function applyNextLabels(context) {
11986
+ function applyNextLabels(context, iteration) {
12034
11987
  return context.backend.execute(
12035
11988
  chunkIPSVVTWT_cjs.asCompiledRowsSql(drizzleOrm.sql`
12036
11989
  UPDATE ${context.workingTable}
12037
- SET label_id = next_label_id, label_kind = next_label_kind
11990
+ SET label_id = next_label_id,
11991
+ label_kind = next_label_kind,
11992
+ improved_round = ${iteration}
12038
11993
  WHERE graph_id = ${context.graphId}
12039
11994
  AND run_id = ${context.runId}
12040
11995
  AND (
@@ -12071,10 +12026,7 @@ async function extractMemberships(context) {
12071
12026
  componentId: row.component_id,
12072
12027
  componentKind: row.component_kind,
12073
12028
  size: Number(row.component_size)
12074
- })).toSorted(compareMemberships);
12075
- }
12076
- function compareMemberships(left, right) {
12077
- return chunkA42GCBGX_cjs.compareCodePoints(left.componentId, right.componentId) || chunkA42GCBGX_cjs.compareCodePoints(left.componentKind, right.componentKind) || chunkA42GCBGX_cjs.compareCodePoints(left.id, right.id) || chunkA42GCBGX_cjs.compareCodePoints(left.kind, right.kind);
12029
+ }));
12078
12030
  }
12079
12031
  var DEFAULT_WEIGHTED_SHORTEST_PATH_MAX_ITERATIONS = 1e3;
12080
12032
  var WEIGHTED_ALGORITHM_NAME = "weightedShortestPath";
@@ -12191,9 +12143,6 @@ function formatWeightValue(value) {
12191
12143
  }
12192
12144
  return JSON.stringify(value);
12193
12145
  }
12194
- function compareNodeIdentityCodePoints(left, right) {
12195
- return chunkA42GCBGX_cjs.compareCodePoints(left.id, right.id) || chunkA42GCBGX_cjs.compareCodePoints(left.kind, right.kind);
12196
- }
12197
12146
  async function findWeightedShortestPathInWorkingTable(ctx, sourceId, targetId, maxIterations, options) {
12198
12147
  return runIterativeGraphOperation(ctx, options, {
12199
12148
  algorithm: WEIGHTED_ALGORITHM_NAME,
@@ -12249,11 +12198,6 @@ async function findWeightedShortestPathInWorkingTable(ctx, sourceId, targetId, m
12249
12198
  }
12250
12199
  });
12251
12200
  }
12252
- function frontierIndexIdentifier(context) {
12253
- return drizzleOrm.sql.identifier(
12254
- `typegraph_iterative_${context.runId.replaceAll("-", "_")}_frontier`
12255
- );
12256
- }
12257
12201
  async function hasVisibleNode(operation, nodeId) {
12258
12202
  const rows = await operation.backend.execute(
12259
12203
  chunkIPSVVTWT_cjs.asCompiledRowsSql(drizzleOrm.sql`
@@ -12422,7 +12366,7 @@ async function findWeightedSelfPath(ctx, nodeId, options) {
12422
12366
  );
12423
12367
  const nodes = await fetchVisibleWorkingNodes(operation, [nodeId]);
12424
12368
  const node = nodes.toSorted(
12425
- (left, right) => compareNodeIdentityCodePoints(left, right)
12369
+ (left, right) => compareNodeIdentity(left, right)
12426
12370
  )[0];
12427
12371
  if (node === void 0) return;
12428
12372
  return { nodes: [node], depth: 0, totalWeight: 0 };
@@ -12498,7 +12442,7 @@ async function findWeightedShortestPathInline(ctx, sourceId, targetId, maxIterat
12498
12442
  }
12499
12443
  }
12500
12444
  frontier = improved.toSorted(
12501
- (left, right) => compareNodeIdentityCodePoints(left, right)
12445
+ (left, right) => compareNodeIdentity(left, right)
12502
12446
  );
12503
12447
  }
12504
12448
  return buildWeightedPathResult(settled, targetId);
@@ -12510,7 +12454,7 @@ function reduceWeightedCandidate(existing, expansion, settled) {
12510
12454
  const sourceEntry = settled.get(nodeIdentityKey(expansion.source));
12511
12455
  if (sourceEntry === void 0) return existing;
12512
12456
  const candidateDistance = sourceEntry.distance + weight;
12513
- if (existing !== void 0 && (existing.distance < candidateDistance || existing.distance === candidateDistance && compareNodeIdentityCodePoints(
12457
+ if (existing !== void 0 && (existing.distance < candidateDistance || existing.distance === candidateDistance && compareNodeIdentity(
12514
12458
  { id: existing.parentId, kind: existing.parentKind },
12515
12459
  expansion.source
12516
12460
  ) <= 0)) {
@@ -12529,7 +12473,7 @@ function buildWeightedPathResult(visited, targetId) {
12529
12473
  let target;
12530
12474
  for (const node of visited.values()) {
12531
12475
  if (node.id !== targetId) continue;
12532
- if (target === void 0 || node.distance < target.distance || node.distance === target.distance && compareNodeIdentityCodePoints(node, target) < 0) {
12476
+ if (target === void 0 || node.distance < target.distance || node.distance === target.distance && compareNodeIdentity(node, target) < 0) {
12533
12477
  target = node;
12534
12478
  }
12535
12479
  }
@@ -17791,5 +17735,5 @@ exports.min = min;
17791
17735
  exports.offsetFragment = offsetFragment;
17792
17736
  exports.orderByFragment = orderByFragment;
17793
17737
  exports.sum = sum;
17794
- //# sourceMappingURL=chunk-NBP2WTJW.cjs.map
17795
- //# sourceMappingURL=chunk-NBP2WTJW.cjs.map
17738
+ //# sourceMappingURL=chunk-5AVRFNP4.cjs.map
17739
+ //# sourceMappingURL=chunk-5AVRFNP4.cjs.map