@cadenza.io/service 2.17.12 → 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.
@@ -433,16 +433,16 @@ function normalizeServiceTransportConfig(value) {
433
433
  }
434
434
  function normalizeServiceTransportDescriptor(value) {
435
435
  const raw = value ?? {};
436
- const uuid5 = normalizeString(raw.uuid);
436
+ const uuid6 = 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 (!uuid5 || !serviceInstanceId || !config) {
441
+ if (!uuid6 || !serviceInstanceId || !config) {
442
442
  return null;
443
443
  }
444
444
  return {
445
- uuid: uuid5,
445
+ uuid: uuid6,
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 uuid5 = normalizeString2(raw.uuid);
507
+ const uuid6 = normalizeString2(raw.uuid);
508
508
  const serviceName = normalizeString2(raw.serviceName ?? raw.service_name);
509
- if (!uuid5 || !serviceName) {
509
+ if (!uuid6 || !serviceName) {
510
510
  return null;
511
511
  }
512
- const transports = normalizeTransportArray(raw.transports, uuid5);
512
+ const transports = normalizeTransportArray(raw.transports, uuid6);
513
513
  return {
514
- uuid: uuid5,
514
+ uuid: uuid6,
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 uuid5 = serviceInstance.uuid;
973
+ const uuid6 = 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 (uuid5 === this.serviceInstanceId) return;
978
+ if (uuid6 === this.serviceInstanceId) return;
963
979
  if (deleted) {
964
- const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid5);
965
- const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid5) ?? -1;
980
+ const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid6);
981
+ const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid6) ?? -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(uuid5, serviceName);
993
+ this.unregisterDependee(uuid6, 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 === uuid5);
999
+ const existing = instances.find((i) => i.uuid === uuid6);
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 === uuid5);
1009
+ const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid6);
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, uuid5, emit);
1022
+ this.reconcileBootstrapPlaceholderInstance(serviceName, uuid6, 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: uuid5,
1048
+ serviceInstanceId: uuid6,
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: uuid5,
1062
+ serviceInstanceId: uuid6,
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(
@@ -3394,6 +3413,8 @@ var RestController = class _RestController {
3394
3413
  if (delegateCtx.__remoteRoutineName === void 0) {
3395
3414
  return;
3396
3415
  }
3416
+ const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
3417
+ const deputyExecId = normalizedDelegateCtx.__metadata.__deputyExecId;
3397
3418
  fetchDiagnostics.delegationRequests++;
3398
3419
  fetchDiagnostics.updatedAt = Date.now();
3399
3420
  let resultContext;
@@ -3405,7 +3426,7 @@ var RestController = class _RestController {
3405
3426
  "Content-Type": "application/json"
3406
3427
  },
3407
3428
  method: "POST",
3408
- body: JSON.stringify(delegateCtx)
3429
+ body: JSON.stringify(normalizedDelegateCtx)
3409
3430
  },
3410
3431
  3e4
3411
3432
  );
@@ -3416,14 +3437,11 @@ var RestController = class _RestController {
3416
3437
  resultContext = {
3417
3438
  __error: `Error: ${error}`,
3418
3439
  errored: true,
3419
- ...delegateCtx,
3420
- ...delegateCtx.__metadata
3440
+ ...normalizedDelegateCtx,
3441
+ ...normalizedDelegateCtx.__metadata
3421
3442
  };
3422
3443
  } finally {
3423
- emit(
3424
- `meta.fetch.delegated:${delegateCtx.__metadata.__deputyExecId}`,
3425
- resultContext
3426
- );
3444
+ emit(`meta.fetch.delegated:${deputyExecId}`, resultContext);
3427
3445
  }
3428
3446
  return resultContext;
3429
3447
  },
@@ -4102,11 +4120,12 @@ var SocketController = class _SocketController {
4102
4120
  CadenzaService.emit("meta.socket.handshake", ctx);
4103
4121
  });
4104
4122
  ws.on("delegation", (ctx, callback) => {
4105
- const deputyExecId = ctx.__metadata.__deputyExecId;
4123
+ const delegationCtx = ensureDelegationContextMetadata(ctx);
4124
+ const deputyExecId = delegationCtx.__metadata.__deputyExecId;
4106
4125
  CadenzaService.createEphemeralMetaTask(
4107
4126
  "Resolve delegation",
4108
- (delegationCtx) => {
4109
- callback(delegationCtx);
4127
+ (delegationCtx2) => {
4128
+ callback(delegationCtx2);
4110
4129
  },
4111
4130
  "Resolves a delegation request using client callback.",
4112
4131
  { register: false }
@@ -4129,8 +4148,8 @@ var SocketController = class _SocketController {
4129
4148
  `meta.node.graph_completed:${deputyExecId}`
4130
4149
  ).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
4131
4150
  CadenzaService.emit("meta.socket.delegation_requested", {
4132
- ...ctx,
4133
- __name: ctx.__remoteRoutineName
4151
+ ...delegationCtx,
4152
+ __name: delegationCtx.__remoteRoutineName
4134
4153
  });
4135
4154
  });
4136
4155
  ws.on("signal", (ctx, callback) => {
@@ -4750,9 +4769,10 @@ var SocketController = class _SocketController {
4750
4769
  if (delegateCtx.__remoteRoutineName === void 0) {
4751
4770
  return;
4752
4771
  }
4753
- delete delegateCtx.__isSubMeta;
4754
- delete delegateCtx.__broadcast;
4755
- const deputyExecId = delegateCtx.__metadata?.__deputyExecId;
4772
+ const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
4773
+ delete normalizedDelegateCtx.__isSubMeta;
4774
+ delete normalizedDelegateCtx.__broadcast;
4775
+ const deputyExecId = normalizedDelegateCtx.__metadata?.__deputyExecId;
4756
4776
  const requestSentAt = Date.now();
4757
4777
  if (deputyExecId) {
4758
4778
  runtimeHandle.pendingDelegationIds.add(deputyExecId);
@@ -4761,8 +4781,8 @@ var SocketController = class _SocketController {
4761
4781
  try {
4762
4782
  const resultContext = await runtimeHandle.emitWhenReady?.(
4763
4783
  "delegation",
4764
- delegateCtx,
4765
- delegateCtx.__timeout ?? 6e4
4784
+ normalizedDelegateCtx,
4785
+ normalizedDelegateCtx.__timeout ?? 6e4
4766
4786
  ) ?? {
4767
4787
  errored: true,
4768
4788
  __error: "Socket delegation returned no response"
@@ -5627,7 +5647,7 @@ var DatabaseController = class _DatabaseController {
5627
5647
  };
5628
5648
 
5629
5649
  // src/Cadenza.ts
5630
- var import_uuid3 = require("uuid");
5650
+ var import_uuid4 = require("uuid");
5631
5651
 
5632
5652
  // src/graph/controllers/GraphSyncController.ts
5633
5653
  var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
@@ -6735,7 +6755,7 @@ var CadenzaService = class {
6735
6755
  (transport) => !!transport
6736
6756
  ).map((transport) => ({
6737
6757
  ...transport,
6738
- uuid: (0, import_uuid3.v4)()
6758
+ uuid: (0, import_uuid4.v4)()
6739
6759
  }));
6740
6760
  }
6741
6761
  static createBootstrapTransport(serviceInstanceId, role, endpoint) {
@@ -6979,7 +6999,7 @@ var CadenzaService = class {
6979
6999
  }
6980
7000
  for (const responder of responders) {
6981
7001
  const { task, descriptor } = responder;
6982
- const inquiryId = (0, import_uuid3.v4)();
7002
+ const inquiryId = (0, import_uuid4.v4)();
6983
7003
  startTimeByTask.set(task, Date.now());
6984
7004
  const resolverTask = this.createEphemeralMetaTask(
6985
7005
  `Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
@@ -7320,8 +7340,10 @@ var CadenzaService = class {
7320
7340
  this.bootstrap();
7321
7341
  this.validateName(tableName);
7322
7342
  this.validateName(operation);
7323
- const name = `${operation.charAt(0).toUpperCase() + operation.slice(1)} ${tableName} in ${databaseServiceName ?? "default database service"}`;
7324
- const description = `Executes a ${operation} on table ${tableName} in ${databaseServiceName ?? "default database service"}`;
7343
+ const resolvedDatabaseServiceName = databaseServiceName ?? this.defaultDatabaseServiceName ?? void 0;
7344
+ const targetDatabaseServiceName = resolvedDatabaseServiceName ?? "default database service";
7345
+ const name = `${operation.charAt(0).toUpperCase() + operation.slice(1)} ${tableName} in ${targetDatabaseServiceName}`;
7346
+ const description = `Executes a ${operation} on table ${tableName} in ${targetDatabaseServiceName}`;
7325
7347
  const taskName = `${operation.charAt(0).toUpperCase() + operation.slice(1)} ${tableName}`;
7326
7348
  options = {
7327
7349
  concurrency: 100,
@@ -7345,7 +7367,7 @@ var CadenzaService = class {
7345
7367
  return new DatabaseTask(
7346
7368
  name,
7347
7369
  taskName,
7348
- databaseServiceName,
7370
+ resolvedDatabaseServiceName,
7349
7371
  description,
7350
7372
  queryData,
7351
7373
  options.concurrency,
@@ -7468,7 +7490,7 @@ var CadenzaService = class {
7468
7490
  this.bootstrap();
7469
7491
  this.validateName(serviceName);
7470
7492
  this.validateServiceName(serviceName);
7471
- const serviceId = options.customServiceId ?? (0, import_uuid3.v4)();
7493
+ const serviceId = options.customServiceId ?? (0, import_uuid4.v4)();
7472
7494
  this.serviceRegistry.serviceName = serviceName;
7473
7495
  this.serviceRegistry.serviceInstanceId = serviceId;
7474
7496
  this.setHydrationResults(options.hydration);
@@ -7720,6 +7742,7 @@ var CadenzaService = class {
7720
7742
  this.bootstrap();
7721
7743
  this.validateName(name);
7722
7744
  this.validateServiceName(name);
7745
+ this.defaultDatabaseServiceName = name;
7723
7746
  const databaseController = DatabaseController.instance;
7724
7747
  const actorOptions = this.normalizePostgresActorOptions(name, {
7725
7748
  ...options,
@@ -8278,6 +8301,7 @@ var CadenzaService = class {
8278
8301
  this.serviceRegistry?.reset();
8279
8302
  this.isBootstrapped = false;
8280
8303
  this.serviceCreated = false;
8304
+ this.defaultDatabaseServiceName = null;
8281
8305
  this.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
8282
8306
  this.hydratedInquiryResults = /* @__PURE__ */ new Map();
8283
8307
  this.frontendSyncScheduled = false;
@@ -8285,6 +8309,7 @@ var CadenzaService = class {
8285
8309
  };
8286
8310
  CadenzaService.isBootstrapped = false;
8287
8311
  CadenzaService.serviceCreated = false;
8312
+ CadenzaService.defaultDatabaseServiceName = null;
8288
8313
  CadenzaService.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
8289
8314
  CadenzaService.hydratedInquiryResults = /* @__PURE__ */ new Map();
8290
8315
  CadenzaService.frontendSyncScheduled = false;
@@ -8293,7 +8318,7 @@ CadenzaService.frontendSyncScheduled = false;
8293
8318
  var import_core5 = require("@cadenza.io/core");
8294
8319
 
8295
8320
  // src/ssr/createSSRInquiryBridge.ts
8296
- var import_uuid4 = require("uuid");
8321
+ var import_uuid5 = require("uuid");
8297
8322
  function ensureFetch() {
8298
8323
  if (typeof globalThis.fetch !== "function") {
8299
8324
  throw new Error("SSR inquiry bridge requires global fetch support.");
@@ -8382,7 +8407,7 @@ function createSSRInquiryBridge(options = {}) {
8382
8407
  __remoteRoutineName: remoteRoutineName,
8383
8408
  __metadata: {
8384
8409
  ...context.__metadata ?? {},
8385
- __deputyExecId: (0, import_uuid4.v4)()
8410
+ __deputyExecId: (0, import_uuid5.v4)()
8386
8411
  }
8387
8412
  }),
8388
8413
  signal