@lucern/graph-sync 1.0.28 → 1.0.30
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/CHANGELOG.md +8 -0
- package/dist/index.d.ts +198 -17
- package/dist/index.js +465 -373
- package/dist/index.js.map +1 -1
- package/dist/neo4jDriver.js +2 -4
- package/dist/neo4jDriver.js.map +1 -1
- package/dist/neo4jEdgeAPI.d.ts +93 -5
- package/dist/neo4jEdgeAPI.js +118 -107
- package/dist/neo4jEdgeAPI.js.map +1 -1
- package/dist/neo4jQueries-D14Putpd.d.ts +839 -0
- package/dist/neo4jQueries.d.ts +2 -1
- package/dist/neo4jQueries.js +72 -44
- package/dist/neo4jQueries.js.map +1 -1
- package/dist/neo4jQueryRoute.js +92 -45
- package/dist/neo4jQueryRoute.js.map +1 -1
- package/dist/neo4jSync.d.ts +106 -10
- package/dist/neo4jSync.js +159 -162
- package/dist/neo4jSync.js.map +1 -1
- package/dist/neo4jSyncHelpers-DWr-lF-A.d.ts +208 -0
- package/dist/neo4jSyncHelpers.d.ts +3 -1
- package/dist/neo4jSyncHelpers.js +44 -26
- package/dist/neo4jSyncHelpers.js.map +1 -1
- package/dist/proof-attestation.json +1 -1
- package/package.json +3 -3
- package/dist/neo4jQueries-j3LrFKpY.d.ts +0 -301
- package/dist/neo4jSyncHelpers-vxe1-Gvw.d.ts +0 -58
package/dist/neo4jSync.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use node";
|
|
2
|
-
import { v } from 'convex/values';
|
|
3
|
-
import { NODE_TYPE_TO_LABEL, EDGE_TYPE_TO_REL } from '@lucern/graph-primitives/graphTypes';
|
|
4
2
|
import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
|
|
5
|
-
import {
|
|
3
|
+
import { NODE_TYPE_TO_LABEL, EDGE_TYPE_TO_REL } from '@lucern/graph-primitives/graphTypes';
|
|
4
|
+
import { v } from 'convex/values';
|
|
5
|
+
import { unsafeConvexAnyApi } from '@lucern/contracts/convex/unsafeAnyApi';
|
|
6
|
+
import { internalActionGeneric } from 'convex/server';
|
|
6
7
|
import neo4j from 'neo4j-driver';
|
|
7
8
|
|
|
8
|
-
var internal =
|
|
9
|
+
var internal = unsafeConvexAnyApi(
|
|
10
|
+
"graph-sync top-level module bundle lacks a committed Convex _generated/api surface"
|
|
11
|
+
);
|
|
9
12
|
var internalAction = internalActionGeneric;
|
|
10
13
|
var VALID_NODE_LABELS = /* @__PURE__ */ new Set([
|
|
11
14
|
// Ontological
|
|
@@ -98,7 +101,7 @@ function getDriver() {
|
|
|
98
101
|
const uri = process.env.NEO4J_URI;
|
|
99
102
|
const user = process.env.NEO4J_USER;
|
|
100
103
|
const password = process.env.NEO4J_PASSWORD;
|
|
101
|
-
if (!uri
|
|
104
|
+
if (!(uri && user && password)) {
|
|
102
105
|
throw new Error(
|
|
103
106
|
"[Neo4j Driver] Missing credentials. Set NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD via `npx convex env set`"
|
|
104
107
|
);
|
|
@@ -159,9 +162,7 @@ async function runWriteTransaction(query, params = {}, timeoutMs = DEFAULT_QUERY
|
|
|
159
162
|
try {
|
|
160
163
|
const neo4jParams = toNeo4jParams(params);
|
|
161
164
|
const result = await session.executeWrite(
|
|
162
|
-
async (tx) =>
|
|
163
|
-
return await tx.run(query, neo4jParams);
|
|
164
|
-
},
|
|
165
|
+
async (tx) => await tx.run(query, neo4jParams),
|
|
165
166
|
{ timeout: timeoutMs }
|
|
166
167
|
);
|
|
167
168
|
return result.records.map((record) => {
|
|
@@ -339,6 +340,9 @@ function convertNeo4jValue(value) {
|
|
|
339
340
|
}
|
|
340
341
|
|
|
341
342
|
// src/neo4jSync.ts
|
|
343
|
+
var graphSyncHelpers = internal.neo4jSyncHelpers;
|
|
344
|
+
var graphSyncActions = internal.neo4jSync;
|
|
345
|
+
var graphSyncEdgeApi = internal.neo4jEdgeAPI;
|
|
342
346
|
function buildSyncResponse(entityType, operation, fields) {
|
|
343
347
|
return {
|
|
344
348
|
entityType,
|
|
@@ -359,53 +363,100 @@ function buildSyncFailure(entityType, operation, error, fields) {
|
|
|
359
363
|
...fields
|
|
360
364
|
});
|
|
361
365
|
}
|
|
366
|
+
function readRecord(value) {
|
|
367
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
368
|
+
}
|
|
369
|
+
function readString(value) {
|
|
370
|
+
return typeof value === "string" ? value : "";
|
|
371
|
+
}
|
|
372
|
+
function readFirstString(...values) {
|
|
373
|
+
for (const value of values) {
|
|
374
|
+
const stringValue = readString(value);
|
|
375
|
+
if (stringValue.length > 0) {
|
|
376
|
+
return stringValue;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
function readArrayLength(value) {
|
|
382
|
+
return Array.isArray(value) ? value.length : 0;
|
|
383
|
+
}
|
|
384
|
+
function nodeSyncEventType(operation) {
|
|
385
|
+
return operation === "delete" ? "node_deleted" : "node_updated";
|
|
386
|
+
}
|
|
387
|
+
function edgeSyncEventType(operation) {
|
|
388
|
+
return operation === "delete" ? "edge_deleted" : "edge_created";
|
|
389
|
+
}
|
|
390
|
+
function readNeo4jEndpointFailure(edge, operation) {
|
|
391
|
+
if (edge.fromGlobalId && edge.toGlobalId) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
console.warn(
|
|
395
|
+
"[Neo4j Sync] Edge missing fromGlobalId or toGlobalId, skipping"
|
|
396
|
+
);
|
|
397
|
+
return buildSyncFailure(
|
|
398
|
+
"edge",
|
|
399
|
+
operation,
|
|
400
|
+
"Edge missing connected node globalIds",
|
|
401
|
+
{
|
|
402
|
+
skippedReason: "edge_endpoint_missing"
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
async function applyEdgeOperation(edge, operation, edgeId) {
|
|
407
|
+
const relType = EDGE_TYPE_TO_REL[edge.edgeType] || edge.edgeType.toUpperCase();
|
|
408
|
+
if (operation === "delete") {
|
|
409
|
+
await deleteEdge(edge.globalId);
|
|
410
|
+
console.log(`[Neo4j Sync] Deleted edge ${edge.globalId}`);
|
|
411
|
+
return relType;
|
|
412
|
+
}
|
|
413
|
+
await upsertEdge(
|
|
414
|
+
relType,
|
|
415
|
+
edge.globalId,
|
|
416
|
+
edge.fromGlobalId ?? "",
|
|
417
|
+
edge.toGlobalId ?? "",
|
|
418
|
+
{
|
|
419
|
+
...buildEdgeProperties(edge),
|
|
420
|
+
convexId: edgeId
|
|
421
|
+
}
|
|
422
|
+
);
|
|
423
|
+
console.log(`[Neo4j Sync] Upserted edge ${edge.globalId} as ${relType}`);
|
|
424
|
+
return relType;
|
|
425
|
+
}
|
|
362
426
|
function buildNodeProperties(node) {
|
|
363
|
-
const metadata = node.metadata
|
|
364
|
-
const
|
|
365
|
-
const stage = metadata.stage || metadata.beliefStage || "";
|
|
366
|
-
const criticality = metadata.criticality || "";
|
|
367
|
-
const synthesizedFrom = metadata.synthesizedFrom || [];
|
|
368
|
-
const epistemicStatus = node.epistemicStatus || "";
|
|
369
|
-
const methodology = node.methodology || "";
|
|
370
|
-
const informationAsymmetry = node.informationAsymmetry || "";
|
|
371
|
-
const questionType = node.questionType || "";
|
|
372
|
-
const questionPriority = node.questionPriority || "";
|
|
373
|
-
const answerQuality = node.answerQuality || "";
|
|
374
|
-
const reversibility = node.reversibility || "";
|
|
375
|
-
const predictionMeta = node.predictionMeta;
|
|
427
|
+
const metadata = readRecord(node.metadata);
|
|
428
|
+
const predictionMeta = readRecord(node.predictionMeta);
|
|
376
429
|
return {
|
|
377
|
-
|
|
430
|
+
answerQuality: readString(node.answerQuality),
|
|
378
431
|
canonicalText: node.canonicalText || "",
|
|
379
|
-
title: node.title || "",
|
|
380
|
-
status: node.status || "active",
|
|
381
|
-
subtype: node.subtype || "",
|
|
382
|
-
domain: node.domain || "",
|
|
383
432
|
confidence: node.confidence || 0,
|
|
384
|
-
|
|
385
|
-
sourceType: node.sourceType || "unknown",
|
|
433
|
+
convexId: node._id,
|
|
386
434
|
createdAt: node.createdAt,
|
|
387
|
-
updatedAt: node.updatedAt || Date.now(),
|
|
388
435
|
createdBy: node.createdBy || "",
|
|
389
|
-
|
|
436
|
+
criticality: readString(metadata.criticality),
|
|
437
|
+
domain: node.domain || "",
|
|
390
438
|
epistemicLayer: node.epistemicLayer || "",
|
|
391
|
-
|
|
439
|
+
epistemicStatus: readString(node.epistemicStatus),
|
|
440
|
+
expectedBy: predictionMeta?.expectedBy ? String(predictionMeta.expectedBy) : "",
|
|
441
|
+
informationAsymmetry: readString(node.informationAsymmetry),
|
|
442
|
+
isPrediction: predictionMeta?.isPrediction ? "true" : "false",
|
|
443
|
+
methodology: readString(node.methodology),
|
|
444
|
+
nodeType: node.nodeType,
|
|
445
|
+
pillar: readFirstString(metadata.pillar, metadata.topic),
|
|
392
446
|
projectId: node.projectId || "",
|
|
447
|
+
questionPriority: readString(node.questionPriority),
|
|
448
|
+
questionType: readString(node.questionType),
|
|
449
|
+
reversibility: readString(node.reversibility),
|
|
450
|
+
sourceType: node.sourceType || "unknown",
|
|
451
|
+
stage: readFirstString(metadata.stage, metadata.beliefStage),
|
|
452
|
+
status: node.status || "active",
|
|
453
|
+
subtype: node.subtype || "",
|
|
454
|
+
synthesizedFromCount: readArrayLength(metadata.synthesizedFrom),
|
|
393
455
|
tenantId: node.tenantId || "",
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
synthesizedFromCount: synthesizedFrom.length,
|
|
399
|
-
// Classification fields (Logic Machine)
|
|
400
|
-
epistemicStatus,
|
|
401
|
-
methodology,
|
|
402
|
-
informationAsymmetry,
|
|
403
|
-
questionType,
|
|
404
|
-
questionPriority,
|
|
405
|
-
answerQuality,
|
|
406
|
-
reversibility,
|
|
407
|
-
isPrediction: predictionMeta?.isPrediction ? "true" : "false",
|
|
408
|
-
expectedBy: predictionMeta?.expectedBy ? String(predictionMeta.expectedBy) : ""
|
|
456
|
+
title: node.title || "",
|
|
457
|
+
updatedAt: node.updatedAt || Date.now(),
|
|
458
|
+
verificationStatus: node.verificationStatus || "unverified",
|
|
459
|
+
workspaceId: node.workspaceId || ""
|
|
409
460
|
};
|
|
410
461
|
}
|
|
411
462
|
function buildEdgeProperties(edge) {
|
|
@@ -445,7 +496,7 @@ var syncNodeToNeo4j = internalAction({
|
|
|
445
496
|
skippedReason: "credentials_missing"
|
|
446
497
|
});
|
|
447
498
|
}
|
|
448
|
-
const node = await ctx.runQuery(
|
|
499
|
+
const node = await ctx.runQuery(graphSyncHelpers.getNodeForSync, {
|
|
449
500
|
nodeId: args.nodeId
|
|
450
501
|
});
|
|
451
502
|
if (!node) {
|
|
@@ -468,7 +519,7 @@ var syncNodeToNeo4j = internalAction({
|
|
|
468
519
|
} else {
|
|
469
520
|
const props = buildNodeProperties(node);
|
|
470
521
|
const embedding = await ctx.runQuery(
|
|
471
|
-
|
|
522
|
+
graphSyncHelpers.getEmbeddingForSync,
|
|
472
523
|
{ nodeId: args.nodeId }
|
|
473
524
|
);
|
|
474
525
|
if (embedding) {
|
|
@@ -479,8 +530,8 @@ var syncNodeToNeo4j = internalAction({
|
|
|
479
530
|
`[Neo4j Sync] Upserted node ${node.globalId} as ${label} with projectId=${node.projectId}` + (embedding ? ` (with ${embedding.length}-dim embedding)` : "")
|
|
480
531
|
);
|
|
481
532
|
}
|
|
482
|
-
await ctx.runMutation(
|
|
483
|
-
eventType: args.operation
|
|
533
|
+
await ctx.runMutation(graphSyncHelpers.logSyncEvent, {
|
|
534
|
+
eventType: nodeSyncEventType(args.operation),
|
|
484
535
|
entityId: args.nodeId,
|
|
485
536
|
entityType: node.nodeType,
|
|
486
537
|
status: "success"
|
|
@@ -489,14 +540,14 @@ var syncNodeToNeo4j = internalAction({
|
|
|
489
540
|
} catch (error) {
|
|
490
541
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
491
542
|
console.error("[Neo4j Sync] Node sync error:", errorMsg);
|
|
492
|
-
await ctx.runMutation(
|
|
543
|
+
await ctx.runMutation(graphSyncHelpers.logSyncEvent, {
|
|
493
544
|
eventType: args.operation === "delete" ? "node_deleted" : "node_updated",
|
|
494
545
|
entityId: args.nodeId,
|
|
495
546
|
entityType: node.nodeType,
|
|
496
547
|
status: "failed",
|
|
497
548
|
error: errorMsg
|
|
498
549
|
});
|
|
499
|
-
await ctx.runMutation(
|
|
550
|
+
await ctx.runMutation(graphSyncHelpers.queueForRetry, {
|
|
500
551
|
entityType: "node",
|
|
501
552
|
entityId: args.nodeId,
|
|
502
553
|
operation: args.operation,
|
|
@@ -522,7 +573,7 @@ var syncEdgeToNeo4j = internalAction({
|
|
|
522
573
|
skippedReason: "credentials_missing"
|
|
523
574
|
});
|
|
524
575
|
}
|
|
525
|
-
const edge = await ctx.runQuery(
|
|
576
|
+
const edge = await ctx.runQuery(graphSyncHelpers.getEdgeForSync, {
|
|
526
577
|
edgeId: args.edgeId
|
|
527
578
|
});
|
|
528
579
|
if (!edge) {
|
|
@@ -537,53 +588,18 @@ var syncEdgeToNeo4j = internalAction({
|
|
|
537
588
|
skippedReason: "source_edge_missing"
|
|
538
589
|
});
|
|
539
590
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
"Edge missing connected node globalIds",
|
|
548
|
-
{
|
|
549
|
-
skippedReason: "edge_endpoint_missing"
|
|
550
|
-
}
|
|
551
|
-
);
|
|
591
|
+
const edgeForSync = edge;
|
|
592
|
+
const endpointFailure = readNeo4jEndpointFailure(
|
|
593
|
+
edgeForSync,
|
|
594
|
+
args.operation
|
|
595
|
+
);
|
|
596
|
+
if (endpointFailure) {
|
|
597
|
+
return endpointFailure;
|
|
552
598
|
}
|
|
553
|
-
const relType = EDGE_TYPE_TO_REL[edge.edgeType] || edge.edgeType.toUpperCase();
|
|
554
599
|
try {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
} else {
|
|
559
|
-
await upsertEdge(
|
|
560
|
-
relType,
|
|
561
|
-
edge.globalId,
|
|
562
|
-
edge.fromGlobalId,
|
|
563
|
-
edge.toGlobalId,
|
|
564
|
-
{
|
|
565
|
-
convexId: args.edgeId,
|
|
566
|
-
weight: edge.weight || 1,
|
|
567
|
-
confidence: edge.confidence || 0,
|
|
568
|
-
context: edge.context || "",
|
|
569
|
-
derivationType: edge.derivationType || "",
|
|
570
|
-
createdAt: edge.createdAt,
|
|
571
|
-
createdBy: edge.createdBy || "",
|
|
572
|
-
edgeType: edge.edgeType,
|
|
573
|
-
fromLayer: edge.fromLayer || "",
|
|
574
|
-
toLayer: edge.toLayer || "",
|
|
575
|
-
// Classification fields (Logic Machine)
|
|
576
|
-
reasoningMethod: edge.reasoningMethod || "",
|
|
577
|
-
logicalRole: edge.logicalRole || "",
|
|
578
|
-
temporalClass: edge.temporalClass || ""
|
|
579
|
-
}
|
|
580
|
-
);
|
|
581
|
-
console.log(
|
|
582
|
-
`[Neo4j Sync] Upserted edge ${edge.globalId} as ${relType}`
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
await ctx.runMutation(internal.neo4jSyncHelpers.logSyncEvent, {
|
|
586
|
-
eventType: args.operation === "delete" ? "edge_deleted" : "edge_created",
|
|
600
|
+
await applyEdgeOperation(edgeForSync, args.operation, args.edgeId);
|
|
601
|
+
await ctx.runMutation(graphSyncHelpers.logSyncEvent, {
|
|
602
|
+
eventType: edgeSyncEventType(args.operation),
|
|
587
603
|
entityId: args.edgeId,
|
|
588
604
|
entityType: edge.edgeType,
|
|
589
605
|
status: "success"
|
|
@@ -592,14 +608,14 @@ var syncEdgeToNeo4j = internalAction({
|
|
|
592
608
|
} catch (error) {
|
|
593
609
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
594
610
|
console.error("[Neo4j Sync] Edge sync error:", errorMsg);
|
|
595
|
-
await ctx.runMutation(
|
|
596
|
-
eventType: args.operation
|
|
611
|
+
await ctx.runMutation(graphSyncHelpers.logSyncEvent, {
|
|
612
|
+
eventType: edgeSyncEventType(args.operation),
|
|
597
613
|
entityId: args.edgeId,
|
|
598
614
|
entityType: edge.edgeType,
|
|
599
615
|
status: "failed",
|
|
600
616
|
error: errorMsg
|
|
601
617
|
});
|
|
602
|
-
await ctx.runMutation(
|
|
618
|
+
await ctx.runMutation(graphSyncHelpers.queueForRetry, {
|
|
603
619
|
entityType: "edge",
|
|
604
620
|
entityId: args.edgeId,
|
|
605
621
|
operation: args.operation,
|
|
@@ -617,13 +633,10 @@ var syncAllNodesToNeo4j = internalAction({
|
|
|
617
633
|
returns: permissiveReturn,
|
|
618
634
|
handler: async (ctx, args) => {
|
|
619
635
|
const batchSize = args.batchSize ?? 100;
|
|
620
|
-
const result = await ctx.runQuery(
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
cursor: args.cursor
|
|
625
|
-
}
|
|
626
|
-
);
|
|
636
|
+
const result = await ctx.runQuery(graphSyncHelpers.getNodeBatchForSync, {
|
|
637
|
+
limit: batchSize,
|
|
638
|
+
cursor: args.cursor
|
|
639
|
+
});
|
|
627
640
|
if (result.nodes.length === 0) {
|
|
628
641
|
return { synced: 0, failed: 0, hasMore: false };
|
|
629
642
|
}
|
|
@@ -668,19 +681,16 @@ var syncAllEdgesToNeo4j = internalAction({
|
|
|
668
681
|
returns: permissiveReturn,
|
|
669
682
|
handler: async (ctx, args) => {
|
|
670
683
|
const batchSize = args.batchSize ?? 100;
|
|
671
|
-
const result = await ctx.runQuery(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
cursor: args.cursor
|
|
676
|
-
}
|
|
677
|
-
);
|
|
684
|
+
const result = await ctx.runQuery(graphSyncHelpers.getEdgeBatchForSync, {
|
|
685
|
+
limit: batchSize,
|
|
686
|
+
cursor: args.cursor
|
|
687
|
+
});
|
|
678
688
|
if (result.edges.length === 0) {
|
|
679
689
|
return { synced: 0, failed: 0, hasMore: false };
|
|
680
690
|
}
|
|
681
691
|
const edgesToSync = [];
|
|
682
692
|
for (const edge of result.edges) {
|
|
683
|
-
if (!edge.fromGlobalId
|
|
693
|
+
if (!(edge.fromGlobalId && edge.toGlobalId)) {
|
|
684
694
|
console.warn(
|
|
685
695
|
`[Neo4j Sync] Skipping edge ${edge.globalId} - missing globalIds`
|
|
686
696
|
);
|
|
@@ -726,16 +736,13 @@ var backfillAllToNeo4j = internalAction({
|
|
|
726
736
|
console.log("[Neo4j Sync] Starting full backfill...");
|
|
727
737
|
let nodeCursor;
|
|
728
738
|
do {
|
|
729
|
-
const result = await ctx.runAction(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
cursor: nodeCursor
|
|
734
|
-
}
|
|
735
|
-
);
|
|
739
|
+
const result = await ctx.runAction(graphSyncActions.syncAllNodesToNeo4j, {
|
|
740
|
+
batchSize,
|
|
741
|
+
cursor: nodeCursor
|
|
742
|
+
});
|
|
736
743
|
totalNodes += result.synced;
|
|
737
744
|
totalFailed += result.failed;
|
|
738
|
-
nodeCursor = result.hasMore ? result.nextCursor : void 0;
|
|
745
|
+
nodeCursor = result.hasMore ? result.nextCursor ?? void 0 : void 0;
|
|
739
746
|
console.log(
|
|
740
747
|
`[Neo4j Sync] Nodes progress: ${totalNodes} synced, ${totalFailed} failed`
|
|
741
748
|
);
|
|
@@ -743,16 +750,13 @@ var backfillAllToNeo4j = internalAction({
|
|
|
743
750
|
console.log(`[Neo4j Sync] Finished nodes: ${totalNodes} synced`);
|
|
744
751
|
let edgeCursor;
|
|
745
752
|
do {
|
|
746
|
-
const result = await ctx.runAction(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
cursor: edgeCursor
|
|
751
|
-
}
|
|
752
|
-
);
|
|
753
|
+
const result = await ctx.runAction(graphSyncActions.syncAllEdgesToNeo4j, {
|
|
754
|
+
batchSize,
|
|
755
|
+
cursor: edgeCursor
|
|
756
|
+
});
|
|
753
757
|
totalEdges += result.synced;
|
|
754
758
|
totalFailed += result.failed;
|
|
755
|
-
edgeCursor = result.hasMore ? result.nextCursor : void 0;
|
|
759
|
+
edgeCursor = result.hasMore ? result.nextCursor ?? void 0 : void 0;
|
|
756
760
|
console.log(
|
|
757
761
|
`[Neo4j Sync] Edges progress: ${totalEdges} synced, ${totalFailed} failed`
|
|
758
762
|
);
|
|
@@ -775,7 +779,7 @@ var processRetryQueue = internalAction({
|
|
|
775
779
|
handler: async (ctx, args) => {
|
|
776
780
|
const limit = args.limit ?? 10;
|
|
777
781
|
const pendingItems = await ctx.runQuery(
|
|
778
|
-
|
|
782
|
+
graphSyncHelpers.getPendingRetries,
|
|
779
783
|
{ limit }
|
|
780
784
|
);
|
|
781
785
|
if (pendingItems.length === 0) {
|
|
@@ -784,31 +788,31 @@ var processRetryQueue = internalAction({
|
|
|
784
788
|
let succeeded = 0;
|
|
785
789
|
let failed = 0;
|
|
786
790
|
for (const item of pendingItems) {
|
|
787
|
-
await ctx.runMutation(
|
|
791
|
+
await ctx.runMutation(graphSyncHelpers.updateQueueStatus, {
|
|
788
792
|
queueId: item._id,
|
|
789
793
|
status: "in_progress"
|
|
790
794
|
});
|
|
791
795
|
let result;
|
|
792
796
|
if (item.entityType === "node") {
|
|
793
|
-
result = await ctx.runAction(
|
|
797
|
+
result = await ctx.runAction(graphSyncActions.syncNodeToNeo4j, {
|
|
794
798
|
nodeId: item.entityId,
|
|
795
799
|
operation: item.operation
|
|
796
800
|
});
|
|
797
801
|
} else {
|
|
798
802
|
const resolved = await ctx.runQuery(
|
|
799
|
-
|
|
803
|
+
graphSyncHelpers.resolveEdgeRetryTarget,
|
|
800
804
|
{
|
|
801
805
|
entityId: item.entityId
|
|
802
806
|
}
|
|
803
807
|
);
|
|
804
808
|
if (resolved.mode === "convex_id" || resolved.mode === "global_id_in_convex") {
|
|
805
|
-
result = await ctx.runAction(
|
|
809
|
+
result = await ctx.runAction(graphSyncActions.syncEdgeToNeo4j, {
|
|
806
810
|
edgeId: resolved.edgeId,
|
|
807
811
|
operation: item.operation
|
|
808
812
|
});
|
|
809
813
|
} else {
|
|
810
814
|
result = await ctx.runAction(
|
|
811
|
-
|
|
815
|
+
graphSyncEdgeApi.retryProjectionByGlobalId,
|
|
812
816
|
{
|
|
813
817
|
globalId: resolved.edgeGlobalId
|
|
814
818
|
}
|
|
@@ -816,14 +820,14 @@ var processRetryQueue = internalAction({
|
|
|
816
820
|
}
|
|
817
821
|
}
|
|
818
822
|
if (result.success) {
|
|
819
|
-
await ctx.runMutation(
|
|
823
|
+
await ctx.runMutation(graphSyncHelpers.updateQueueStatus, {
|
|
820
824
|
queueId: item._id,
|
|
821
825
|
status: "succeeded"
|
|
822
826
|
});
|
|
823
827
|
succeeded++;
|
|
824
828
|
} else {
|
|
825
829
|
const updated = await ctx.runMutation(
|
|
826
|
-
|
|
830
|
+
graphSyncHelpers.incrementAttempts,
|
|
827
831
|
{
|
|
828
832
|
queueId: item._id,
|
|
829
833
|
error: result.error || "Unknown error"
|
|
@@ -849,7 +853,7 @@ var syncEmbeddingToNeo4j = internalAction({
|
|
|
849
853
|
skippedReason: "credentials_missing"
|
|
850
854
|
});
|
|
851
855
|
}
|
|
852
|
-
const node = await ctx.runQuery(
|
|
856
|
+
const node = await ctx.runQuery(graphSyncHelpers.getNodeForSync, {
|
|
853
857
|
nodeId: args.nodeId
|
|
854
858
|
});
|
|
855
859
|
if (!node?.globalId) {
|
|
@@ -857,10 +861,9 @@ var syncEmbeddingToNeo4j = internalAction({
|
|
|
857
861
|
skippedReason: "source_node_missing"
|
|
858
862
|
});
|
|
859
863
|
}
|
|
860
|
-
const embedding = await ctx.runQuery(
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
);
|
|
864
|
+
const embedding = await ctx.runQuery(graphSyncHelpers.getEmbeddingForSync, {
|
|
865
|
+
nodeId: args.nodeId
|
|
866
|
+
});
|
|
864
867
|
if (!embedding) {
|
|
865
868
|
return buildSyncFailure("embedding", "sync", "Embedding not found", {
|
|
866
869
|
skippedReason: "embedding_missing"
|
|
@@ -910,20 +913,17 @@ var resyncAllNodes = internalAction({
|
|
|
910
913
|
returns: permissiveReturn,
|
|
911
914
|
handler: async (ctx, args) => {
|
|
912
915
|
const batchSize = args.batchSize ?? 50;
|
|
913
|
-
const result = await ctx.runQuery(
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
cursor: args.cursor
|
|
919
|
-
}
|
|
920
|
-
);
|
|
916
|
+
const result = await ctx.runQuery(graphSyncHelpers.getAllNodesForResync, {
|
|
917
|
+
nodeType: args.nodeType,
|
|
918
|
+
limit: batchSize,
|
|
919
|
+
cursor: args.cursor
|
|
920
|
+
});
|
|
921
921
|
let synced = 0;
|
|
922
922
|
let failed = 0;
|
|
923
923
|
for (const node of result.nodes) {
|
|
924
924
|
try {
|
|
925
925
|
const syncResult = await ctx.runAction(
|
|
926
|
-
|
|
926
|
+
graphSyncActions.syncNodeToNeo4j,
|
|
927
927
|
{
|
|
928
928
|
nodeId: node._id,
|
|
929
929
|
operation: "upsert"
|
|
@@ -956,19 +956,16 @@ var resyncAllEdges = internalAction({
|
|
|
956
956
|
returns: permissiveReturn,
|
|
957
957
|
handler: async (ctx, args) => {
|
|
958
958
|
const batchSize = args.batchSize ?? 50;
|
|
959
|
-
const result = await ctx.runQuery(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
cursor: args.cursor
|
|
964
|
-
}
|
|
965
|
-
);
|
|
959
|
+
const result = await ctx.runQuery(graphSyncHelpers.getAllEdgesForResync, {
|
|
960
|
+
limit: batchSize,
|
|
961
|
+
cursor: args.cursor
|
|
962
|
+
});
|
|
966
963
|
let synced = 0;
|
|
967
964
|
let failed = 0;
|
|
968
965
|
for (const edge of result.edges) {
|
|
969
966
|
try {
|
|
970
967
|
const syncResult = await ctx.runAction(
|
|
971
|
-
|
|
968
|
+
graphSyncActions.syncEdgeToNeo4j,
|
|
972
969
|
{
|
|
973
970
|
edgeId: edge._id,
|
|
974
971
|
operation: "upsert"
|