@bian-womp/spark-remote 0.3.66 → 0.3.67

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/lib/cjs/index.cjs CHANGED
@@ -377,6 +377,43 @@ async function createServerRuntimeAdapter(id, createRegistry, send, extensions)
377
377
  let graphRuntime;
378
378
  let engine;
379
379
  let extData = {};
380
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
381
+ const getCustomNodeDataFromExtData = (data) => {
382
+ if (!data)
383
+ return undefined;
384
+ const custom = isRecord(data.custom) ? data.custom : undefined;
385
+ if (!custom)
386
+ return undefined;
387
+ const nodes = isRecord(custom.nodes) ? custom.nodes : undefined;
388
+ if (!nodes)
389
+ return undefined;
390
+ const sanitized = {};
391
+ for (const [nodeId, nodeData] of Object.entries(nodes)) {
392
+ if (isRecord(nodeData))
393
+ sanitized[nodeId] = nodeData;
394
+ }
395
+ return Object.keys(sanitized).length > 0 ? sanitized : undefined;
396
+ };
397
+ const areCustomNodeDataEqual = (left, right) => {
398
+ if (!left && !right)
399
+ return true;
400
+ if (!left || !right)
401
+ return false;
402
+ return JSON.stringify(left) === JSON.stringify(right);
403
+ };
404
+ const syncCustomNodeDataToRuntime = () => {
405
+ if (!graphRuntime)
406
+ return;
407
+ const customNodeData = getCustomNodeDataFromExtData(extData);
408
+ const existingCustomNodeData = graphRuntime.getCustomNodeData();
409
+ const sanitizedExisting = Object.keys(existingCustomNodeData).length
410
+ ? existingCustomNodeData
411
+ : undefined;
412
+ if (areCustomNodeDataEqual(sanitizedExisting, customNodeData)) {
413
+ return;
414
+ }
415
+ graphRuntime.setCustomNodeData(customNodeData ?? {});
416
+ };
380
417
  // Helper to get current context
381
418
  const getContext = () => ({
382
419
  registry,
@@ -469,6 +506,7 @@ async function createServerRuntimeAdapter(id, createRegistry, send, extensions)
469
506
  environment,
470
507
  startPaused: opts?.startPaused,
471
508
  });
509
+ syncCustomNodeDataToRuntime();
472
510
  graphRuntime.on("value", (p) => send({ message: { type: "value", payload: p } }));
473
511
  graphRuntime.on("invalidate", (p) => send({ message: { type: "invalidate", payload: p } }));
474
512
  graphRuntime.on("error", (p) => send({ message: { type: "error", payload: p } }));
@@ -478,11 +516,13 @@ async function createServerRuntimeAdapter(id, createRegistry, send, extensions)
478
516
  if (!data || typeof data !== "object") {
479
517
  // Clear all extData when called with non-object (backward-compatible)
480
518
  extData = {};
519
+ syncCustomNodeDataToRuntime();
481
520
  return;
482
521
  }
483
522
  // Merge with existing extData so that callers can update a subset of fields
484
523
  // (e.g., { ui } or { runtime }) without dropping the other ones.
485
524
  extData = { ...extData, ...data };
525
+ syncCustomNodeDataToRuntime();
486
526
  },
487
527
  updateExtData: async (updates) => {
488
528
  if (!extData || typeof extData !== "object" || Array.isArray(extData)) {
@@ -496,6 +536,9 @@ async function createServerRuntimeAdapter(id, createRegistry, send, extensions)
496
536
  hasCustomUpdate = true;
497
537
  }
498
538
  }
539
+ if (hasCustomUpdate) {
540
+ syncCustomNodeDataToRuntime();
541
+ }
499
542
  return hasCustomUpdate;
500
543
  },
501
544
  snapshot: async () => {