@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.
- package/dist/backend/sqlite/index.cjs +2 -2
- package/dist/backend/sqlite/index.js +1 -1
- package/dist/backend/sqlite/libsql.cjs +2 -2
- package/dist/backend/sqlite/libsql.js +1 -1
- package/dist/backend/sqlite/local.cjs +2 -2
- package/dist/backend/sqlite/local.js +1 -1
- package/dist/{chunk-NBP2WTJW.cjs → chunk-5AVRFNP4.cjs} +134 -190
- package/dist/chunk-5AVRFNP4.cjs.map +1 -0
- package/dist/{chunk-JBNOGRKW.cjs → chunk-EJYMTO3K.cjs} +16 -2
- package/dist/chunk-EJYMTO3K.cjs.map +1 -0
- package/dist/{chunk-552KNYQJ.js → chunk-GA4TT3DH.js} +134 -190
- package/dist/chunk-GA4TT3DH.js.map +1 -0
- package/dist/{chunk-J4IUSYFF.js → chunk-UV3WP5WZ.js} +16 -2
- package/dist/chunk-UV3WP5WZ.js.map +1 -0
- package/dist/graph-merge/index.cjs +3 -3
- package/dist/graph-merge/index.js +1 -1
- package/dist/index.cjs +36 -36
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-552KNYQJ.js.map +0 -1
- package/dist/chunk-J4IUSYFF.js.map +0 -1
- package/dist/chunk-JBNOGRKW.cjs.map +0 -1
- package/dist/chunk-NBP2WTJW.cjs.map +0 -1
|
@@ -10736,6 +10736,13 @@ function buildCompileTimeReferentIndex(graph, runtimeEdgeNames) {
|
|
|
10736
10736
|
// src/store/algorithms/context.ts
|
|
10737
10737
|
var DEFAULT_ALGORITHM_MAX_HOPS = 10;
|
|
10738
10738
|
var DEFAULT_NEIGHBOR_DEPTH = 1;
|
|
10739
|
+
function pickTemporalOptions(options) {
|
|
10740
|
+
return {
|
|
10741
|
+
...options.temporalMode === void 0 ? {} : { temporalMode: options.temporalMode },
|
|
10742
|
+
...options.asOf === void 0 ? {} : { asOf: options.asOf },
|
|
10743
|
+
...options.recordedAsOf === void 0 ? {} : { recordedAsOf: options.recordedAsOf }
|
|
10744
|
+
};
|
|
10745
|
+
}
|
|
10739
10746
|
function resolveTemporalOptions(ctx, options) {
|
|
10740
10747
|
const { valid } = resolveReadCoordinate(
|
|
10741
10748
|
options.temporalMode ?? ctx.defaultTemporalMode,
|
|
@@ -10850,6 +10857,11 @@ function compileDirectionFilter(ctx, direction, nodeId, nodesTable) {
|
|
|
10850
10857
|
}
|
|
10851
10858
|
}
|
|
10852
10859
|
}
|
|
10860
|
+
function frontierIndexIdentifier(context) {
|
|
10861
|
+
return sql.identifier(
|
|
10862
|
+
`typegraph_iterative_${context.runId.replaceAll("-", "_")}_frontier`
|
|
10863
|
+
);
|
|
10864
|
+
}
|
|
10853
10865
|
var DEFAULT_MAX_BIND_PARAMETERS = 999;
|
|
10854
10866
|
var RESERVED_TEMPORAL_BIND_PARAMETERS_PER_BRANCH = 12;
|
|
10855
10867
|
var RESERVED_WEIGHT_BIND_PARAMETERS_PER_BRANCH = 4;
|
|
@@ -11041,147 +11053,90 @@ function nodeIdentityKeyFromRow(id, kind) {
|
|
|
11041
11053
|
return nodeIdentityKey({ id, kind });
|
|
11042
11054
|
}
|
|
11043
11055
|
function compareNodeIdentity(left, right) {
|
|
11044
|
-
return
|
|
11056
|
+
return compareCodePoints(left.id, right.id) || compareCodePoints(left.kind, right.kind);
|
|
11045
11057
|
}
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11058
|
+
var OUTGOING_DIRECTION_FIELDS = {
|
|
11059
|
+
joinField: "from_id",
|
|
11060
|
+
joinKindField: "from_kind",
|
|
11061
|
+
targetField: "to_id",
|
|
11062
|
+
targetKindField: "to_kind"
|
|
11063
|
+
};
|
|
11064
|
+
var INCOMING_DIRECTION_FIELDS = {
|
|
11065
|
+
joinField: "to_id",
|
|
11066
|
+
joinKindField: "to_kind",
|
|
11067
|
+
targetField: "from_id",
|
|
11068
|
+
targetKindField: "from_kind"
|
|
11069
|
+
};
|
|
11070
|
+
function fieldsForDirection(direction) {
|
|
11052
11071
|
switch (direction) {
|
|
11053
11072
|
case "out": {
|
|
11054
|
-
return
|
|
11073
|
+
return [OUTGOING_DIRECTION_FIELDS];
|
|
11055
11074
|
}
|
|
11056
11075
|
case "in": {
|
|
11057
|
-
return
|
|
11076
|
+
return [INCOMING_DIRECTION_FIELDS];
|
|
11058
11077
|
}
|
|
11059
11078
|
case "both": {
|
|
11060
|
-
|
|
11061
|
-
operation,
|
|
11062
|
-
sql`working_set`,
|
|
11063
|
-
sql`TRUE`,
|
|
11064
|
-
edgeKinds,
|
|
11065
|
-
"from_id",
|
|
11066
|
-
"from_kind",
|
|
11067
|
-
"to_id",
|
|
11068
|
-
"to_kind"
|
|
11069
|
-
);
|
|
11070
|
-
const incoming = compileDirectionalExpansion(
|
|
11071
|
-
operation,
|
|
11072
|
-
sql`working_set`,
|
|
11073
|
-
sql`TRUE`,
|
|
11074
|
-
edgeKinds,
|
|
11075
|
-
"to_id",
|
|
11076
|
-
"to_kind",
|
|
11077
|
-
"from_id",
|
|
11078
|
-
"from_kind"
|
|
11079
|
-
);
|
|
11080
|
-
return sql`${workingCte} ${outgoing} UNION ALL ${incoming}`;
|
|
11079
|
+
return [OUTGOING_DIRECTION_FIELDS, INCOMING_DIRECTION_FIELDS];
|
|
11081
11080
|
}
|
|
11082
11081
|
}
|
|
11083
11082
|
}
|
|
11083
|
+
function compileDirectionUnion(direction, compileDirection) {
|
|
11084
|
+
return sql.join(
|
|
11085
|
+
fieldsForDirection(direction).map((fields) => compileDirection(fields)),
|
|
11086
|
+
sql` UNION ALL `
|
|
11087
|
+
);
|
|
11088
|
+
}
|
|
11089
|
+
function compileExpansionQuery(operation, workingSet, direction, edgeKinds) {
|
|
11090
|
+
const workingValues = sql.join(
|
|
11091
|
+
workingSet.map((node) => sql`(${node.id}, ${node.kind})`),
|
|
11092
|
+
sql`, `
|
|
11093
|
+
);
|
|
11094
|
+
const workingCte = sql`WITH working_set(node_id, node_kind) AS (VALUES ${workingValues})`;
|
|
11095
|
+
const expansion = compileDirectionUnion(
|
|
11096
|
+
direction,
|
|
11097
|
+
(fields) => compileDirectionalExpansion(
|
|
11098
|
+
operation,
|
|
11099
|
+
sql`working_set`,
|
|
11100
|
+
sql`TRUE`,
|
|
11101
|
+
edgeKinds,
|
|
11102
|
+
fields.joinField,
|
|
11103
|
+
fields.joinKindField,
|
|
11104
|
+
fields.targetField,
|
|
11105
|
+
fields.targetKindField
|
|
11106
|
+
)
|
|
11107
|
+
);
|
|
11108
|
+
return sql`${workingCte} ${expansion}`;
|
|
11109
|
+
}
|
|
11084
11110
|
function compileWorkingTableExpansion(operation, workingTable, sourceFilter, direction, edgeKinds) {
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
case "in": {
|
|
11099
|
-
return compileDirectionalExpansion(
|
|
11100
|
-
operation,
|
|
11101
|
-
workingTable,
|
|
11102
|
-
sourceFilter,
|
|
11103
|
-
edgeKinds,
|
|
11104
|
-
"to_id",
|
|
11105
|
-
"to_kind",
|
|
11106
|
-
"from_id",
|
|
11107
|
-
"from_kind"
|
|
11108
|
-
);
|
|
11109
|
-
}
|
|
11110
|
-
case "both": {
|
|
11111
|
-
const outgoing = compileDirectionalExpansion(
|
|
11112
|
-
operation,
|
|
11113
|
-
workingTable,
|
|
11114
|
-
sourceFilter,
|
|
11115
|
-
edgeKinds,
|
|
11116
|
-
"from_id",
|
|
11117
|
-
"from_kind",
|
|
11118
|
-
"to_id",
|
|
11119
|
-
"to_kind"
|
|
11120
|
-
);
|
|
11121
|
-
const incoming = compileDirectionalExpansion(
|
|
11122
|
-
operation,
|
|
11123
|
-
workingTable,
|
|
11124
|
-
sourceFilter,
|
|
11125
|
-
edgeKinds,
|
|
11126
|
-
"to_id",
|
|
11127
|
-
"to_kind",
|
|
11128
|
-
"from_id",
|
|
11129
|
-
"from_kind"
|
|
11130
|
-
);
|
|
11131
|
-
return sql`${outgoing} UNION ALL ${incoming}`;
|
|
11132
|
-
}
|
|
11133
|
-
}
|
|
11111
|
+
return compileDirectionUnion(
|
|
11112
|
+
direction,
|
|
11113
|
+
(fields) => compileDirectionalExpansion(
|
|
11114
|
+
operation,
|
|
11115
|
+
workingTable,
|
|
11116
|
+
sourceFilter,
|
|
11117
|
+
edgeKinds,
|
|
11118
|
+
fields.joinField,
|
|
11119
|
+
fields.joinKindField,
|
|
11120
|
+
fields.targetField,
|
|
11121
|
+
fields.targetKindField
|
|
11122
|
+
)
|
|
11123
|
+
);
|
|
11134
11124
|
}
|
|
11135
|
-
function compileWorkingTableEdgeExpansion(operation, workingTable, sourceFilter, direction, edgeKinds) {
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
|
|
11150
|
-
return compileDirectionalEdgeExpansion(
|
|
11151
|
-
operation,
|
|
11152
|
-
workingTable,
|
|
11153
|
-
sourceFilter,
|
|
11154
|
-
edgeKinds,
|
|
11155
|
-
"to_id",
|
|
11156
|
-
"to_kind",
|
|
11157
|
-
"from_id",
|
|
11158
|
-
"from_kind"
|
|
11159
|
-
);
|
|
11160
|
-
}
|
|
11161
|
-
case "both": {
|
|
11162
|
-
const outgoing = compileDirectionalEdgeExpansion(
|
|
11163
|
-
operation,
|
|
11164
|
-
workingTable,
|
|
11165
|
-
sourceFilter,
|
|
11166
|
-
edgeKinds,
|
|
11167
|
-
"from_id",
|
|
11168
|
-
"from_kind",
|
|
11169
|
-
"to_id",
|
|
11170
|
-
"to_kind"
|
|
11171
|
-
);
|
|
11172
|
-
const incoming = compileDirectionalEdgeExpansion(
|
|
11173
|
-
operation,
|
|
11174
|
-
workingTable,
|
|
11175
|
-
sourceFilter,
|
|
11176
|
-
edgeKinds,
|
|
11177
|
-
"to_id",
|
|
11178
|
-
"to_kind",
|
|
11179
|
-
"from_id",
|
|
11180
|
-
"from_kind"
|
|
11181
|
-
);
|
|
11182
|
-
return sql`${outgoing} UNION ALL ${incoming}`;
|
|
11183
|
-
}
|
|
11184
|
-
}
|
|
11125
|
+
function compileWorkingTableEdgeExpansion(operation, workingTable, sourceFilter, direction, edgeKinds, sourceProjection) {
|
|
11126
|
+
return compileDirectionUnion(
|
|
11127
|
+
direction,
|
|
11128
|
+
(fields) => compileDirectionalEdgeExpansion(
|
|
11129
|
+
operation,
|
|
11130
|
+
workingTable,
|
|
11131
|
+
sourceFilter,
|
|
11132
|
+
edgeKinds,
|
|
11133
|
+
fields.joinField,
|
|
11134
|
+
fields.joinKindField,
|
|
11135
|
+
fields.targetField,
|
|
11136
|
+
fields.targetKindField,
|
|
11137
|
+
sourceProjection
|
|
11138
|
+
)
|
|
11139
|
+
);
|
|
11185
11140
|
}
|
|
11186
11141
|
function compileDirectionalExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField) {
|
|
11187
11142
|
const edgeExpansion = compileDirectionalEdgeExpansion(
|
|
@@ -11197,10 +11152,11 @@ function compileDirectionalExpansion(operation, workingRelation, sourceFilter, e
|
|
|
11197
11152
|
const weightColumn = operation.weightExpression === void 0 ? sql`` : sql`, expanded.weight`;
|
|
11198
11153
|
return 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}`;
|
|
11199
11154
|
}
|
|
11200
|
-
function compileDirectionalEdgeExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField) {
|
|
11155
|
+
function compileDirectionalEdgeExpansion(operation, workingRelation, sourceFilter, edgeKinds, joinField, joinKindField, targetField, targetKindField, sourceProjection) {
|
|
11201
11156
|
const edgeKindFilter = compileKindFilter(sql.raw("e.kind"), edgeKinds);
|
|
11202
11157
|
const weightColumn = operation.weightExpression === void 0 ? sql`` : sql`, ${operation.weightExpression} AS weight`;
|
|
11203
|
-
|
|
11158
|
+
const sourceColumns = sourceProjection === void 0 ? sql`` : sql`, ${sourceProjection}`;
|
|
11159
|
+
return sql`SELECT w.node_id AS source_id, w.node_kind AS source_kind${sourceColumns}, e.${sql.raw(targetField)} AS target_id, e.${sql.raw(targetKindField)} AS target_kind${weightColumn} FROM ${workingRelation} w JOIN ${operation.schema.edgesTable} e ON e.${sql.raw(joinField)} = w.node_id AND e.${sql.raw(joinKindField)} = w.node_kind AND e.graph_id = ${operation.ctx.graphId} WHERE ${sourceFilter} AND ${edgeKindFilter} AND ${operation.edgeTemporalFilter}`;
|
|
11204
11160
|
}
|
|
11205
11161
|
function chunkValues(values, chunkSize) {
|
|
11206
11162
|
const chunks = [];
|
|
@@ -11283,7 +11239,7 @@ function compileWeightExpression(dialect, weightProperty, defaultWeight) {
|
|
|
11283
11239
|
return defaultWeight === void 0 ? extracted : sql`COALESCE(${extracted}, ${defaultWeight})`;
|
|
11284
11240
|
}
|
|
11285
11241
|
function supportsTemporaryIteration(ctx) {
|
|
11286
|
-
return ctx.backend.capabilities.transactions && ctx.backend.capabilities.returning !== false && ctx.backend.executeTemporaryStatement !== void 0;
|
|
11242
|
+
return ctx.backend.capabilities.transactions && ctx.backend.capabilities.graphAnalytics?.supported !== false && ctx.backend.capabilities.returning !== false && ctx.backend.executeTemporaryStatement !== void 0;
|
|
11287
11243
|
}
|
|
11288
11244
|
function requireTemporaryStatements(backend) {
|
|
11289
11245
|
if (backend.executeTemporaryStatement === void 0) {
|
|
@@ -11467,6 +11423,11 @@ async function expandWorkingTableRound(context, side, currentDepth, nextDepth, d
|
|
|
11467
11423
|
const oppositeSide = side === "forward" ? "reverse" : "forward";
|
|
11468
11424
|
let insertedCount = 0;
|
|
11469
11425
|
let meeting;
|
|
11426
|
+
const { dialect } = context.operation.ctx;
|
|
11427
|
+
const targetKind = dialect.binaryText(sql`expanded.target_kind`);
|
|
11428
|
+
const targetId = dialect.binaryText(sql`expanded.target_id`);
|
|
11429
|
+
const sourceId = dialect.binaryText(sql`expanded.source_id`);
|
|
11430
|
+
const sourceKind = dialect.binaryText(sql`expanded.source_kind`);
|
|
11470
11431
|
for (const edgeKinds of context.operation.edgeKindChunks) {
|
|
11471
11432
|
const sourceFilter = sql`
|
|
11472
11433
|
w.graph_id = ${context.graphId}
|
|
@@ -11502,8 +11463,8 @@ async function expandWorkingTableRound(context, side, currentDepth, nextDepth, d
|
|
|
11502
11463
|
FROM (
|
|
11503
11464
|
SELECT expanded.*,
|
|
11504
11465
|
ROW_NUMBER() OVER (
|
|
11505
|
-
PARTITION BY
|
|
11506
|
-
ORDER BY
|
|
11466
|
+
PARTITION BY ${targetKind}, ${targetId}
|
|
11467
|
+
ORDER BY ${sourceId}, ${sourceKind}
|
|
11507
11468
|
) AS candidate_rank
|
|
11508
11469
|
FROM (${expansion}) expanded
|
|
11509
11470
|
) ranked
|
|
@@ -11606,7 +11567,6 @@ async function readWorkingRows(context, side) {
|
|
|
11606
11567
|
WHERE graph_id = ${context.graphId}
|
|
11607
11568
|
AND run_id = ${context.runId}
|
|
11608
11569
|
AND ${sideFilter}
|
|
11609
|
-
ORDER BY side, depth, node_id, node_kind
|
|
11610
11570
|
`)
|
|
11611
11571
|
);
|
|
11612
11572
|
}
|
|
@@ -11738,8 +11698,12 @@ function findMeetingNodeKey(candidates, activeVisited, oppositeVisited) {
|
|
|
11738
11698
|
const active = activeVisited.get(key);
|
|
11739
11699
|
const opposite = oppositeVisited.get(key);
|
|
11740
11700
|
if (active === void 0 || opposite === void 0) continue;
|
|
11741
|
-
const meeting = {
|
|
11742
|
-
|
|
11701
|
+
const meeting = {
|
|
11702
|
+
key,
|
|
11703
|
+
node: { id: candidate.id, kind: candidate.kind },
|
|
11704
|
+
depth: active.depth + opposite.depth
|
|
11705
|
+
};
|
|
11706
|
+
if (best === void 0 || meeting.depth < best.depth || meeting.depth === best.depth && compareNodeIdentity(meeting.node, best.node) < 0) {
|
|
11743
11707
|
best = meeting;
|
|
11744
11708
|
}
|
|
11745
11709
|
}
|
|
@@ -11831,13 +11795,7 @@ async function executeNeighbors(ctx, sourceId, options) {
|
|
|
11831
11795
|
maxHops: depth,
|
|
11832
11796
|
direction: options.direction ?? "out",
|
|
11833
11797
|
cyclePolicy: options.cyclePolicy ?? "prevent",
|
|
11834
|
-
...options
|
|
11835
|
-
temporalMode: options.temporalMode
|
|
11836
|
-
},
|
|
11837
|
-
...options.asOf !== void 0 && { asOf: options.asOf },
|
|
11838
|
-
...options.recordedAsOf !== void 0 && {
|
|
11839
|
-
recordedAsOf: options.recordedAsOf
|
|
11840
|
-
},
|
|
11798
|
+
...pickTemporalOptions(options),
|
|
11841
11799
|
...options.workingMemory !== void 0 && {
|
|
11842
11800
|
workingMemory: options.workingMemory
|
|
11843
11801
|
},
|
|
@@ -11870,9 +11828,7 @@ async function executeWeaklyConnectedComponents(ctx, options) {
|
|
|
11870
11828
|
const traversalOptions = {
|
|
11871
11829
|
edges: options.edges,
|
|
11872
11830
|
direction: "both",
|
|
11873
|
-
...options
|
|
11874
|
-
...options.asOf === void 0 ? {} : { asOf: options.asOf },
|
|
11875
|
-
...options.recordedAsOf === void 0 ? {} : { recordedAsOf: options.recordedAsOf },
|
|
11831
|
+
...pickTemporalOptions(options),
|
|
11876
11832
|
...options.workingMemory === void 0 ? {} : { workingMemory: options.workingMemory }
|
|
11877
11833
|
};
|
|
11878
11834
|
return runIterativeGraphOperation(ctx, traversalOptions, {
|
|
@@ -11913,6 +11869,7 @@ function createWorkingTable2(context) {
|
|
|
11913
11869
|
label_kind TEXT NOT NULL,
|
|
11914
11870
|
next_label_id TEXT NOT NULL,
|
|
11915
11871
|
next_label_kind TEXT NOT NULL,
|
|
11872
|
+
improved_round INTEGER NOT NULL,
|
|
11916
11873
|
PRIMARY KEY (graph_id, run_id, node_kind, node_id)
|
|
11917
11874
|
)
|
|
11918
11875
|
`;
|
|
@@ -11923,14 +11880,18 @@ async function initializeWorkingTable(context, nodeKinds) {
|
|
|
11923
11880
|
await context.executeTemporary(sql`
|
|
11924
11881
|
INSERT INTO ${workingTable}
|
|
11925
11882
|
(graph_id, run_id, node_id, node_kind, label_id, label_kind,
|
|
11926
|
-
next_label_id, next_label_kind)
|
|
11883
|
+
next_label_id, next_label_kind, improved_round)
|
|
11927
11884
|
SELECT
|
|
11928
|
-
${graphId}, ${runId}, n.id, n.kind, n.id, n.kind, n.id, n.kind
|
|
11885
|
+
${graphId}, ${runId}, n.id, n.kind, n.id, n.kind, n.id, n.kind, 0
|
|
11929
11886
|
FROM ${operation.schema.nodesTable} n
|
|
11930
11887
|
WHERE n.graph_id = ${graphId}
|
|
11931
11888
|
AND ${nodeKindFilter}
|
|
11932
11889
|
AND ${operation.nodeTemporalFilter}
|
|
11933
11890
|
`);
|
|
11891
|
+
await context.executeTemporary(sql`
|
|
11892
|
+
CREATE INDEX ${frontierIndexIdentifier(context)}
|
|
11893
|
+
ON ${workingTable} (graph_id, run_id, improved_round)
|
|
11894
|
+
`);
|
|
11934
11895
|
const rows = await context.backend.execute(
|
|
11935
11896
|
asCompiledRowsSql(sql`
|
|
11936
11897
|
SELECT COUNT(*) AS count
|
|
@@ -11941,32 +11902,29 @@ async function initializeWorkingTable(context, nodeKinds) {
|
|
|
11941
11902
|
const workingTableSize = Number(rows[0]?.count ?? 0);
|
|
11942
11903
|
return { changedCount: workingTableSize, workingTableSize };
|
|
11943
11904
|
}
|
|
11944
|
-
async function runLabelPropagationRound(context, state) {
|
|
11945
|
-
await resetNextLabels(context);
|
|
11905
|
+
async function runLabelPropagationRound(context, state, iteration) {
|
|
11946
11906
|
for (const edgeKinds of context.operation.edgeKindChunks) {
|
|
11947
|
-
await propagateChunkLabels(context, edgeKinds);
|
|
11907
|
+
await propagateChunkLabels(context, edgeKinds, iteration);
|
|
11948
11908
|
}
|
|
11949
|
-
const changedRows = await applyNextLabels(context);
|
|
11909
|
+
const changedRows = await applyNextLabels(context, iteration);
|
|
11950
11910
|
return {
|
|
11951
11911
|
changedCount: changedRows.length,
|
|
11952
11912
|
workingTableSize: state.workingTableSize
|
|
11953
11913
|
};
|
|
11954
11914
|
}
|
|
11955
|
-
async function
|
|
11956
|
-
await context.executeTemporary(sql`
|
|
11957
|
-
UPDATE ${context.workingTable}
|
|
11958
|
-
SET next_label_id = label_id, next_label_kind = label_kind
|
|
11959
|
-
WHERE graph_id = ${context.graphId} AND run_id = ${context.runId}
|
|
11960
|
-
`);
|
|
11961
|
-
}
|
|
11962
|
-
async function propagateChunkLabels(context, edgeKinds) {
|
|
11915
|
+
async function propagateChunkLabels(context, edgeKinds, iteration) {
|
|
11963
11916
|
const { operation, workingTable, graphId, runId } = context;
|
|
11964
11917
|
const expansion = compileWorkingTableEdgeExpansion(
|
|
11965
11918
|
operation,
|
|
11966
11919
|
workingTable,
|
|
11967
|
-
sql`
|
|
11920
|
+
sql`
|
|
11921
|
+
w.graph_id = ${graphId}
|
|
11922
|
+
AND w.run_id = ${runId}
|
|
11923
|
+
AND w.improved_round = ${iteration - 1}
|
|
11924
|
+
`,
|
|
11968
11925
|
"both",
|
|
11969
|
-
edgeKinds
|
|
11926
|
+
edgeKinds,
|
|
11927
|
+
sql`w.label_id AS source_label_id, w.label_kind AS source_label_kind`
|
|
11970
11928
|
);
|
|
11971
11929
|
const candidateId = operation.ctx.dialect.binaryText(sql`ranked.label_id`);
|
|
11972
11930
|
const candidateKind = operation.ctx.dialect.binaryText(
|
|
@@ -11985,14 +11943,9 @@ async function propagateChunkLabels(context, edgeKinds) {
|
|
|
11985
11943
|
SELECT
|
|
11986
11944
|
expanded.target_id,
|
|
11987
11945
|
expanded.target_kind,
|
|
11988
|
-
|
|
11989
|
-
|
|
11946
|
+
expanded.source_label_id AS label_id,
|
|
11947
|
+
expanded.source_label_kind AS label_kind
|
|
11990
11948
|
FROM (${expansion}) expanded
|
|
11991
|
-
JOIN ${workingTable} source
|
|
11992
|
-
ON source.graph_id = ${graphId}
|
|
11993
|
-
AND source.run_id = ${runId}
|
|
11994
|
-
AND source.node_id = expanded.source_id
|
|
11995
|
-
AND source.node_kind = expanded.source_kind
|
|
11996
11949
|
JOIN ${workingTable} scoped_target
|
|
11997
11950
|
ON scoped_target.graph_id = ${graphId}
|
|
11998
11951
|
AND scoped_target.run_id = ${runId}
|
|
@@ -12028,11 +11981,13 @@ async function propagateChunkLabels(context, edgeKinds) {
|
|
|
12028
11981
|
)
|
|
12029
11982
|
`);
|
|
12030
11983
|
}
|
|
12031
|
-
function applyNextLabels(context) {
|
|
11984
|
+
function applyNextLabels(context, iteration) {
|
|
12032
11985
|
return context.backend.execute(
|
|
12033
11986
|
asCompiledRowsSql(sql`
|
|
12034
11987
|
UPDATE ${context.workingTable}
|
|
12035
|
-
SET label_id = next_label_id,
|
|
11988
|
+
SET label_id = next_label_id,
|
|
11989
|
+
label_kind = next_label_kind,
|
|
11990
|
+
improved_round = ${iteration}
|
|
12036
11991
|
WHERE graph_id = ${context.graphId}
|
|
12037
11992
|
AND run_id = ${context.runId}
|
|
12038
11993
|
AND (
|
|
@@ -12069,10 +12024,7 @@ async function extractMemberships(context) {
|
|
|
12069
12024
|
componentId: row.component_id,
|
|
12070
12025
|
componentKind: row.component_kind,
|
|
12071
12026
|
size: Number(row.component_size)
|
|
12072
|
-
}))
|
|
12073
|
-
}
|
|
12074
|
-
function compareMemberships(left, right) {
|
|
12075
|
-
return compareCodePoints(left.componentId, right.componentId) || compareCodePoints(left.componentKind, right.componentKind) || compareCodePoints(left.id, right.id) || compareCodePoints(left.kind, right.kind);
|
|
12027
|
+
}));
|
|
12076
12028
|
}
|
|
12077
12029
|
var DEFAULT_WEIGHTED_SHORTEST_PATH_MAX_ITERATIONS = 1e3;
|
|
12078
12030
|
var WEIGHTED_ALGORITHM_NAME = "weightedShortestPath";
|
|
@@ -12189,9 +12141,6 @@ function formatWeightValue(value) {
|
|
|
12189
12141
|
}
|
|
12190
12142
|
return JSON.stringify(value);
|
|
12191
12143
|
}
|
|
12192
|
-
function compareNodeIdentityCodePoints(left, right) {
|
|
12193
|
-
return compareCodePoints(left.id, right.id) || compareCodePoints(left.kind, right.kind);
|
|
12194
|
-
}
|
|
12195
12144
|
async function findWeightedShortestPathInWorkingTable(ctx, sourceId, targetId, maxIterations, options) {
|
|
12196
12145
|
return runIterativeGraphOperation(ctx, options, {
|
|
12197
12146
|
algorithm: WEIGHTED_ALGORITHM_NAME,
|
|
@@ -12247,11 +12196,6 @@ async function findWeightedShortestPathInWorkingTable(ctx, sourceId, targetId, m
|
|
|
12247
12196
|
}
|
|
12248
12197
|
});
|
|
12249
12198
|
}
|
|
12250
|
-
function frontierIndexIdentifier(context) {
|
|
12251
|
-
return sql.identifier(
|
|
12252
|
-
`typegraph_iterative_${context.runId.replaceAll("-", "_")}_frontier`
|
|
12253
|
-
);
|
|
12254
|
-
}
|
|
12255
12199
|
async function hasVisibleNode(operation, nodeId) {
|
|
12256
12200
|
const rows = await operation.backend.execute(
|
|
12257
12201
|
asCompiledRowsSql(sql`
|
|
@@ -12420,7 +12364,7 @@ async function findWeightedSelfPath(ctx, nodeId, options) {
|
|
|
12420
12364
|
);
|
|
12421
12365
|
const nodes = await fetchVisibleWorkingNodes(operation, [nodeId]);
|
|
12422
12366
|
const node = nodes.toSorted(
|
|
12423
|
-
(left, right) =>
|
|
12367
|
+
(left, right) => compareNodeIdentity(left, right)
|
|
12424
12368
|
)[0];
|
|
12425
12369
|
if (node === void 0) return;
|
|
12426
12370
|
return { nodes: [node], depth: 0, totalWeight: 0 };
|
|
@@ -12496,7 +12440,7 @@ async function findWeightedShortestPathInline(ctx, sourceId, targetId, maxIterat
|
|
|
12496
12440
|
}
|
|
12497
12441
|
}
|
|
12498
12442
|
frontier = improved.toSorted(
|
|
12499
|
-
(left, right) =>
|
|
12443
|
+
(left, right) => compareNodeIdentity(left, right)
|
|
12500
12444
|
);
|
|
12501
12445
|
}
|
|
12502
12446
|
return buildWeightedPathResult(settled, targetId);
|
|
@@ -12508,7 +12452,7 @@ function reduceWeightedCandidate(existing, expansion, settled) {
|
|
|
12508
12452
|
const sourceEntry = settled.get(nodeIdentityKey(expansion.source));
|
|
12509
12453
|
if (sourceEntry === void 0) return existing;
|
|
12510
12454
|
const candidateDistance = sourceEntry.distance + weight;
|
|
12511
|
-
if (existing !== void 0 && (existing.distance < candidateDistance || existing.distance === candidateDistance &&
|
|
12455
|
+
if (existing !== void 0 && (existing.distance < candidateDistance || existing.distance === candidateDistance && compareNodeIdentity(
|
|
12512
12456
|
{ id: existing.parentId, kind: existing.parentKind },
|
|
12513
12457
|
expansion.source
|
|
12514
12458
|
) <= 0)) {
|
|
@@ -12527,7 +12471,7 @@ function buildWeightedPathResult(visited, targetId) {
|
|
|
12527
12471
|
let target;
|
|
12528
12472
|
for (const node of visited.values()) {
|
|
12529
12473
|
if (node.id !== targetId) continue;
|
|
12530
|
-
if (target === void 0 || node.distance < target.distance || node.distance === target.distance &&
|
|
12474
|
+
if (target === void 0 || node.distance < target.distance || node.distance === target.distance && compareNodeIdentity(node, target) < 0) {
|
|
12531
12475
|
target = node;
|
|
12532
12476
|
}
|
|
12533
12477
|
}
|
|
@@ -17755,5 +17699,5 @@ async function createVerifiedStore(graph, backend, options) {
|
|
|
17755
17699
|
}
|
|
17756
17700
|
|
|
17757
17701
|
export { ExecutableAggregateQuery, ExecutableQuery, MAX_EXPLICIT_RECURSIVE_DEPTH, MAX_RECURSIVE_DEPTH, PreparedQuery, QueryBuilder, RecordedStoreView, StoreSearch, StoreView, UnionableQuery, avg, composeFragments, count, countDistinct, countDistinctEdges, countEdges, createFragment, createQueryBuilder, createStore, createStoreWithSchema, createVerifiedStore, defineSubgraphProject, field, having, havingEq, havingGt, havingGte, havingLt, havingLte, limitFragment, max, min, offsetFragment, orderByFragment, sum };
|
|
17758
|
-
//# sourceMappingURL=chunk-
|
|
17759
|
-
//# sourceMappingURL=chunk-
|
|
17702
|
+
//# sourceMappingURL=chunk-GA4TT3DH.js.map
|
|
17703
|
+
//# sourceMappingURL=chunk-GA4TT3DH.js.map
|