@cadenza.io/service 2.17.13 → 2.17.14

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/index.js CHANGED
@@ -433,16 +433,16 @@ function normalizeServiceTransportConfig(value) {
433
433
  }
434
434
  function normalizeServiceTransportDescriptor(value) {
435
435
  const raw = value ?? {};
436
- const uuid6 = normalizeString(raw.uuid);
436
+ const uuid7 = normalizeString(raw.uuid);
437
437
  const serviceInstanceId = normalizeString(
438
438
  raw.serviceInstanceId ?? raw.service_instance_id
439
439
  );
440
440
  const config = normalizeServiceTransportConfig(raw);
441
- if (!uuid6 || !serviceInstanceId || !config) {
441
+ if (!uuid7 || !serviceInstanceId || !config) {
442
442
  return null;
443
443
  }
444
444
  return {
445
- uuid: uuid6,
445
+ uuid: uuid7,
446
446
  serviceInstanceId,
447
447
  role: config.role,
448
448
  origin: config.origin,
@@ -504,14 +504,14 @@ function normalizeTransportArray(value, serviceInstanceId) {
504
504
  }
505
505
  function normalizeServiceInstanceDescriptor(value) {
506
506
  const raw = value ?? {};
507
- const uuid6 = normalizeString2(raw.uuid);
507
+ const uuid7 = normalizeString2(raw.uuid);
508
508
  const serviceName = normalizeString2(raw.serviceName ?? raw.service_name);
509
- if (!uuid6 || !serviceName) {
509
+ if (!uuid7 || !serviceName) {
510
510
  return null;
511
511
  }
512
- const transports = normalizeTransportArray(raw.transports, uuid6);
512
+ const transports = normalizeTransportArray(raw.transports, uuid7);
513
513
  return {
514
- uuid: uuid6,
514
+ uuid: uuid7,
515
515
  serviceName,
516
516
  numberOfRunningGraphs: Math.max(
517
517
  0,
@@ -542,6 +542,22 @@ function getRouteableTransport(instance, role, protocol) {
542
542
  return selectTransportForRole(instance.transports ?? [], role, protocol);
543
543
  }
544
544
 
545
+ // src/utils/delegation.ts
546
+ var import_uuid2 = require("uuid");
547
+ function ensureDelegationContextMetadata(input) {
548
+ const context = input && typeof input === "object" ? { ...input } : {};
549
+ const metadata = context.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
550
+ const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof context.__deputyExecId === "string" && context.__deputyExecId.length > 0 ? context.__deputyExecId : (0, import_uuid2.v4)();
551
+ return {
552
+ ...context,
553
+ __deputyExecId: deputyExecId,
554
+ __metadata: {
555
+ ...metadata,
556
+ __deputyExecId: deputyExecId
557
+ }
558
+ };
559
+ }
560
+
545
561
  // src/utils/readiness.ts
546
562
  function evaluateDependencyReadiness(input) {
547
563
  const missedHeartbeats = Math.max(
@@ -954,15 +970,15 @@ var ServiceRegistry = class _ServiceRegistry {
954
970
  if (!serviceInstance) {
955
971
  return false;
956
972
  }
957
- const uuid6 = serviceInstance.uuid;
973
+ const uuid7 = serviceInstance.uuid;
958
974
  const serviceName = serviceInstance.serviceName;
959
975
  const deleted = Boolean(
960
976
  ctx.deleted ?? ctx.serviceInstance?.deleted ?? ctx.data?.deleted
961
977
  );
962
- if (uuid6 === this.serviceInstanceId) return;
978
+ if (uuid7 === this.serviceInstanceId) return;
963
979
  if (deleted) {
964
- const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid6);
965
- const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid6) ?? -1;
980
+ const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid7);
981
+ const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid7) ?? -1;
966
982
  if (indexToDelete >= 0 && existingInstance) {
967
983
  this.instances.get(serviceName)?.splice(indexToDelete, 1);
968
984
  for (const transport of existingInstance.transports) {
@@ -974,13 +990,13 @@ var ServiceRegistry = class _ServiceRegistry {
974
990
  if (this.instances.get(serviceName)?.length === 0) {
975
991
  this.instances.delete(serviceName);
976
992
  }
977
- this.unregisterDependee(uuid6, serviceName);
993
+ this.unregisterDependee(uuid7, serviceName);
978
994
  return;
979
995
  }
980
996
  if (!this.instances.has(serviceName))
981
997
  this.instances.set(serviceName, []);
982
998
  const instances = this.instances.get(serviceName);
983
- const existing = instances.find((i) => i.uuid === uuid6);
999
+ const existing = instances.find((i) => i.uuid === uuid7);
984
1000
  if (existing) {
985
1001
  Object.assign(existing, {
986
1002
  ...serviceInstance,
@@ -990,7 +1006,7 @@ var ServiceRegistry = class _ServiceRegistry {
990
1006
  } else {
991
1007
  instances.push(serviceInstance);
992
1008
  }
993
- const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid6);
1009
+ const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid7);
994
1010
  if (trackedInstance) {
995
1011
  const snapshot = this.resolveRuntimeStatusSnapshot(
996
1012
  trackedInstance.numberOfRunningGraphs ?? 0,
@@ -1003,7 +1019,7 @@ var ServiceRegistry = class _ServiceRegistry {
1003
1019
  trackedInstance.reportedAt = trackedInstance.reportedAt ?? (/* @__PURE__ */ new Date()).toISOString();
1004
1020
  }
1005
1021
  if (!serviceInstance.isBootstrapPlaceholder) {
1006
- this.reconcileBootstrapPlaceholderInstance(serviceName, uuid6, emit);
1022
+ this.reconcileBootstrapPlaceholderInstance(serviceName, uuid7, emit);
1007
1023
  }
1008
1024
  if (this.serviceName === serviceName) {
1009
1025
  return false;
@@ -1029,7 +1045,7 @@ var ServiceRegistry = class _ServiceRegistry {
1029
1045
  if (!clientCreated) {
1030
1046
  emit("meta.service_registry.dependee_registered", {
1031
1047
  serviceName,
1032
- serviceInstanceId: uuid6,
1048
+ serviceInstanceId: uuid7,
1033
1049
  serviceTransportId: trackedTransport.uuid,
1034
1050
  serviceOrigin: trackedTransport.origin,
1035
1051
  transportProtocols: trackedTransport.protocols,
@@ -1043,7 +1059,7 @@ var ServiceRegistry = class _ServiceRegistry {
1043
1059
  } else {
1044
1060
  emit("meta.service_registry.routeable_transport_missing", {
1045
1061
  serviceName,
1046
- serviceInstanceId: uuid6,
1062
+ serviceInstanceId: uuid7,
1047
1063
  requiredRole: this.getRoutingTransportRole(),
1048
1064
  isFrontend: this.isFrontend
1049
1065
  });
@@ -1506,6 +1522,9 @@ var ServiceRegistry = class _ServiceRegistry {
1506
1522
  this.getBalancedInstance = CadenzaService.createMetaTask(
1507
1523
  "Get balanced instance",
1508
1524
  (context, emit) => {
1525
+ if (context.__remoteRoutineName !== void 0) {
1526
+ context = ensureDelegationContextMetadata(context);
1527
+ }
1509
1528
  const {
1510
1529
  __serviceName,
1511
1530
  __triedInstances,
@@ -3185,7 +3204,7 @@ var ServiceRegistry = class _ServiceRegistry {
3185
3204
 
3186
3205
  // src/graph/definition/SignalTransmissionTask.ts
3187
3206
  var import_core2 = require("@cadenza.io/core");
3188
- var import_uuid2 = require("uuid");
3207
+ var import_uuid3 = require("uuid");
3189
3208
  var SignalTransmissionTask = class extends import_core2.Task {
3190
3209
  /**
3191
3210
  * Constructs a new instance of the class and initializes it with the provided parameters.
@@ -3214,7 +3233,7 @@ var SignalTransmissionTask = class extends import_core2.Task {
3214
3233
  */
3215
3234
  constructor(name, signalName, serviceName, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = true, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
3216
3235
  const taskFunction = (context) => {
3217
- context.__routineExecId = (0, import_uuid2.v4)();
3236
+ context.__routineExecId = (0, import_uuid3.v4)();
3218
3237
  return context;
3219
3238
  };
3220
3239
  super(
@@ -3284,7 +3303,7 @@ var import_node_http = __toESM(require("http"));
3284
3303
  var import_node_fs = __toESM(require("fs"));
3285
3304
  var import_node_https = __toESM(require("https"));
3286
3305
  var import_node_fetch = __toESM(require("node-fetch"));
3287
- var import_uuid3 = require("uuid");
3306
+ var import_uuid4 = require("uuid");
3288
3307
  var RestController = class _RestController {
3289
3308
  /**
3290
3309
  * Constructor for initializing the REST server and related configurations.
@@ -3460,10 +3479,8 @@ var RestController = class _RestController {
3460
3479
  }
3461
3480
  });
3462
3481
  app.post("/delegation", (req, res) => {
3463
- let deputyExecId;
3464
- let ctx2;
3465
- ctx2 = req.body;
3466
- deputyExecId = ctx2.__metadata.__deputyExecId;
3482
+ const ctx2 = ensureDelegationContextMetadata(req.body);
3483
+ const deputyExecId = ctx2.__metadata.__deputyExecId;
3467
3484
  const remoteRoutineName = ctx2.__remoteRoutineName;
3468
3485
  const targetNotFoundSignal = `meta.rest.delegation_target_not_found:${deputyExecId}`;
3469
3486
  let resolved = false;
@@ -3646,7 +3663,7 @@ var RestController = class _RestController {
3646
3663
  const internalOrigin = httpOrigin ?? httpsOrigin;
3647
3664
  if (internalOrigin) {
3648
3665
  transportData.unshift({
3649
- uuid: (0, import_uuid3.v4)(),
3666
+ uuid: (0, import_uuid4.v4)(),
3650
3667
  service_instance_id: ctx.__serviceInstanceId,
3651
3668
  role: "internal",
3652
3669
  origin: internalOrigin,
@@ -3812,6 +3829,8 @@ var RestController = class _RestController {
3812
3829
  if (ctx2.__remoteRoutineName === void 0) {
3813
3830
  return;
3814
3831
  }
3832
+ const delegateCtx = ensureDelegationContextMetadata(ctx2);
3833
+ const deputyExecId = delegateCtx.__metadata.__deputyExecId;
3815
3834
  fetchDiagnostics.delegationRequests++;
3816
3835
  fetchDiagnostics.updatedAt = Date.now();
3817
3836
  let resultContext;
@@ -3823,7 +3842,7 @@ var RestController = class _RestController {
3823
3842
  "Content-Type": "application/json"
3824
3843
  },
3825
3844
  method: "POST",
3826
- body: JSON.stringify(ctx2)
3845
+ body: JSON.stringify(delegateCtx)
3827
3846
  },
3828
3847
  3e4
3829
3848
  );
@@ -3845,14 +3864,11 @@ var RestController = class _RestController {
3845
3864
  resultContext = {
3846
3865
  __error: `Error: ${e}`,
3847
3866
  errored: true,
3848
- ...ctx2,
3849
- ...ctx2.__metadata
3867
+ ...delegateCtx,
3868
+ ...delegateCtx.__metadata
3850
3869
  };
3851
3870
  } finally {
3852
- emit(
3853
- `meta.fetch.delegated:${ctx2.__metadata.__deputyExecId}`,
3854
- resultContext
3855
- );
3871
+ emit(`meta.fetch.delegated:${deputyExecId}`, resultContext);
3856
3872
  }
3857
3873
  return resultContext;
3858
3874
  },
@@ -4561,11 +4577,12 @@ var SocketController = class _SocketController {
4561
4577
  CadenzaService.emit("meta.socket.handshake", ctx);
4562
4578
  });
4563
4579
  ws.on("delegation", (ctx, callback) => {
4564
- const deputyExecId = ctx.__metadata.__deputyExecId;
4580
+ const delegationCtx = ensureDelegationContextMetadata(ctx);
4581
+ const deputyExecId = delegationCtx.__metadata.__deputyExecId;
4565
4582
  CadenzaService.createEphemeralMetaTask(
4566
4583
  "Resolve delegation",
4567
- (delegationCtx) => {
4568
- callback(delegationCtx);
4584
+ (delegationCtx2) => {
4585
+ callback(delegationCtx2);
4569
4586
  },
4570
4587
  "Resolves a delegation request using client callback.",
4571
4588
  { register: false }
@@ -4588,8 +4605,8 @@ var SocketController = class _SocketController {
4588
4605
  `meta.node.graph_completed:${deputyExecId}`
4589
4606
  ).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
4590
4607
  CadenzaService.emit("meta.socket.delegation_requested", {
4591
- ...ctx,
4592
- __name: ctx.__remoteRoutineName
4608
+ ...delegationCtx,
4609
+ __name: delegationCtx.__remoteRoutineName
4593
4610
  });
4594
4611
  });
4595
4612
  ws.on("signal", (ctx, callback) => {
@@ -5209,9 +5226,10 @@ var SocketController = class _SocketController {
5209
5226
  if (delegateCtx.__remoteRoutineName === void 0) {
5210
5227
  return;
5211
5228
  }
5212
- delete delegateCtx.__isSubMeta;
5213
- delete delegateCtx.__broadcast;
5214
- const deputyExecId = delegateCtx.__metadata?.__deputyExecId;
5229
+ const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
5230
+ delete normalizedDelegateCtx.__isSubMeta;
5231
+ delete normalizedDelegateCtx.__broadcast;
5232
+ const deputyExecId = normalizedDelegateCtx.__metadata?.__deputyExecId;
5215
5233
  const requestSentAt = Date.now();
5216
5234
  if (deputyExecId) {
5217
5235
  runtimeHandle.pendingDelegationIds.add(deputyExecId);
@@ -5220,8 +5238,8 @@ var SocketController = class _SocketController {
5220
5238
  try {
5221
5239
  const resultContext = await runtimeHandle.emitWhenReady?.(
5222
5240
  "delegation",
5223
- delegateCtx,
5224
- delegateCtx.__timeout ?? 6e4
5241
+ normalizedDelegateCtx,
5242
+ normalizedDelegateCtx.__timeout ?? 6e4
5225
5243
  ) ?? {
5226
5244
  errored: true,
5227
5245
  __error: "Socket delegation returned no response"
@@ -8068,7 +8086,7 @@ function tableFieldTypeToSchemaType(type) {
8068
8086
  }
8069
8087
 
8070
8088
  // src/Cadenza.ts
8071
- var import_uuid4 = require("uuid");
8089
+ var import_uuid5 = require("uuid");
8072
8090
 
8073
8091
  // src/graph/controllers/GraphSyncController.ts
8074
8092
  var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
@@ -9176,7 +9194,7 @@ var CadenzaService = class {
9176
9194
  (transport) => !!transport
9177
9195
  ).map((transport) => ({
9178
9196
  ...transport,
9179
- uuid: (0, import_uuid4.v4)()
9197
+ uuid: (0, import_uuid5.v4)()
9180
9198
  }));
9181
9199
  }
9182
9200
  static createBootstrapTransport(serviceInstanceId, role, endpoint) {
@@ -9420,7 +9438,7 @@ var CadenzaService = class {
9420
9438
  }
9421
9439
  for (const responder of responders) {
9422
9440
  const { task, descriptor } = responder;
9423
- const inquiryId = (0, import_uuid4.v4)();
9441
+ const inquiryId = (0, import_uuid5.v4)();
9424
9442
  startTimeByTask.set(task, Date.now());
9425
9443
  const resolverTask = this.createEphemeralMetaTask(
9426
9444
  `Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
@@ -9911,7 +9929,7 @@ var CadenzaService = class {
9911
9929
  this.bootstrap();
9912
9930
  this.validateName(serviceName);
9913
9931
  this.validateServiceName(serviceName);
9914
- const serviceId = options.customServiceId ?? (0, import_uuid4.v4)();
9932
+ const serviceId = options.customServiceId ?? (0, import_uuid5.v4)();
9915
9933
  this.serviceRegistry.serviceName = serviceName;
9916
9934
  this.serviceRegistry.serviceInstanceId = serviceId;
9917
9935
  this.setHydrationResults(options.hydration);
@@ -10739,7 +10757,7 @@ CadenzaService.frontendSyncScheduled = false;
10739
10757
  var import_core5 = require("@cadenza.io/core");
10740
10758
 
10741
10759
  // src/ssr/createSSRInquiryBridge.ts
10742
- var import_uuid5 = require("uuid");
10760
+ var import_uuid6 = require("uuid");
10743
10761
  function ensureFetch() {
10744
10762
  if (typeof globalThis.fetch !== "function") {
10745
10763
  throw new Error("SSR inquiry bridge requires global fetch support.");
@@ -10828,7 +10846,7 @@ function createSSRInquiryBridge(options = {}) {
10828
10846
  __remoteRoutineName: remoteRoutineName,
10829
10847
  __metadata: {
10830
10848
  ...context.__metadata ?? {},
10831
- __deputyExecId: (0, import_uuid5.v4)()
10849
+ __deputyExecId: (0, import_uuid6.v4)()
10832
10850
  }
10833
10851
  }),
10834
10852
  signal