@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/browser/index.js +62 -42
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +62 -42
- package/dist/browser/index.mjs.map +1 -1
- package/dist/index.js +66 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -382,16 +382,16 @@ function normalizeServiceTransportConfig(value) {
|
|
|
382
382
|
}
|
|
383
383
|
function normalizeServiceTransportDescriptor(value) {
|
|
384
384
|
const raw = value ?? {};
|
|
385
|
-
const
|
|
385
|
+
const uuid6 = normalizeString(raw.uuid);
|
|
386
386
|
const serviceInstanceId = normalizeString(
|
|
387
387
|
raw.serviceInstanceId ?? raw.service_instance_id
|
|
388
388
|
);
|
|
389
389
|
const config = normalizeServiceTransportConfig(raw);
|
|
390
|
-
if (!
|
|
390
|
+
if (!uuid6 || !serviceInstanceId || !config) {
|
|
391
391
|
return null;
|
|
392
392
|
}
|
|
393
393
|
return {
|
|
394
|
-
uuid:
|
|
394
|
+
uuid: uuid6,
|
|
395
395
|
serviceInstanceId,
|
|
396
396
|
role: config.role,
|
|
397
397
|
origin: config.origin,
|
|
@@ -453,14 +453,14 @@ function normalizeTransportArray(value, serviceInstanceId) {
|
|
|
453
453
|
}
|
|
454
454
|
function normalizeServiceInstanceDescriptor(value) {
|
|
455
455
|
const raw = value ?? {};
|
|
456
|
-
const
|
|
456
|
+
const uuid6 = normalizeString2(raw.uuid);
|
|
457
457
|
const serviceName = normalizeString2(raw.serviceName ?? raw.service_name);
|
|
458
|
-
if (!
|
|
458
|
+
if (!uuid6 || !serviceName) {
|
|
459
459
|
return null;
|
|
460
460
|
}
|
|
461
|
-
const transports = normalizeTransportArray(raw.transports,
|
|
461
|
+
const transports = normalizeTransportArray(raw.transports, uuid6);
|
|
462
462
|
return {
|
|
463
|
-
uuid:
|
|
463
|
+
uuid: uuid6,
|
|
464
464
|
serviceName,
|
|
465
465
|
numberOfRunningGraphs: Math.max(
|
|
466
466
|
0,
|
|
@@ -491,6 +491,22 @@ function getRouteableTransport(instance, role, protocol) {
|
|
|
491
491
|
return selectTransportForRole(instance.transports ?? [], role, protocol);
|
|
492
492
|
}
|
|
493
493
|
|
|
494
|
+
// src/utils/delegation.ts
|
|
495
|
+
import { v4 as uuid2 } from "uuid";
|
|
496
|
+
function ensureDelegationContextMetadata(input) {
|
|
497
|
+
const context = input && typeof input === "object" ? { ...input } : {};
|
|
498
|
+
const metadata = context.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
|
|
499
|
+
const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof context.__deputyExecId === "string" && context.__deputyExecId.length > 0 ? context.__deputyExecId : uuid2();
|
|
500
|
+
return {
|
|
501
|
+
...context,
|
|
502
|
+
__deputyExecId: deputyExecId,
|
|
503
|
+
__metadata: {
|
|
504
|
+
...metadata,
|
|
505
|
+
__deputyExecId: deputyExecId
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
494
510
|
// src/utils/readiness.ts
|
|
495
511
|
function evaluateDependencyReadiness(input) {
|
|
496
512
|
const missedHeartbeats = Math.max(
|
|
@@ -903,15 +919,15 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
903
919
|
if (!serviceInstance) {
|
|
904
920
|
return false;
|
|
905
921
|
}
|
|
906
|
-
const
|
|
922
|
+
const uuid6 = serviceInstance.uuid;
|
|
907
923
|
const serviceName = serviceInstance.serviceName;
|
|
908
924
|
const deleted = Boolean(
|
|
909
925
|
ctx.deleted ?? ctx.serviceInstance?.deleted ?? ctx.data?.deleted
|
|
910
926
|
);
|
|
911
|
-
if (
|
|
927
|
+
if (uuid6 === this.serviceInstanceId) return;
|
|
912
928
|
if (deleted) {
|
|
913
|
-
const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid ===
|
|
914
|
-
const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid ===
|
|
929
|
+
const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid6);
|
|
930
|
+
const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid6) ?? -1;
|
|
915
931
|
if (indexToDelete >= 0 && existingInstance) {
|
|
916
932
|
this.instances.get(serviceName)?.splice(indexToDelete, 1);
|
|
917
933
|
for (const transport of existingInstance.transports) {
|
|
@@ -923,13 +939,13 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
923
939
|
if (this.instances.get(serviceName)?.length === 0) {
|
|
924
940
|
this.instances.delete(serviceName);
|
|
925
941
|
}
|
|
926
|
-
this.unregisterDependee(
|
|
942
|
+
this.unregisterDependee(uuid6, serviceName);
|
|
927
943
|
return;
|
|
928
944
|
}
|
|
929
945
|
if (!this.instances.has(serviceName))
|
|
930
946
|
this.instances.set(serviceName, []);
|
|
931
947
|
const instances = this.instances.get(serviceName);
|
|
932
|
-
const existing = instances.find((i) => i.uuid ===
|
|
948
|
+
const existing = instances.find((i) => i.uuid === uuid6);
|
|
933
949
|
if (existing) {
|
|
934
950
|
Object.assign(existing, {
|
|
935
951
|
...serviceInstance,
|
|
@@ -939,7 +955,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
939
955
|
} else {
|
|
940
956
|
instances.push(serviceInstance);
|
|
941
957
|
}
|
|
942
|
-
const trackedInstance = existing ?? instances.find((instance) => instance.uuid ===
|
|
958
|
+
const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid6);
|
|
943
959
|
if (trackedInstance) {
|
|
944
960
|
const snapshot = this.resolveRuntimeStatusSnapshot(
|
|
945
961
|
trackedInstance.numberOfRunningGraphs ?? 0,
|
|
@@ -952,7 +968,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
952
968
|
trackedInstance.reportedAt = trackedInstance.reportedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
953
969
|
}
|
|
954
970
|
if (!serviceInstance.isBootstrapPlaceholder) {
|
|
955
|
-
this.reconcileBootstrapPlaceholderInstance(serviceName,
|
|
971
|
+
this.reconcileBootstrapPlaceholderInstance(serviceName, uuid6, emit);
|
|
956
972
|
}
|
|
957
973
|
if (this.serviceName === serviceName) {
|
|
958
974
|
return false;
|
|
@@ -978,7 +994,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
978
994
|
if (!clientCreated) {
|
|
979
995
|
emit("meta.service_registry.dependee_registered", {
|
|
980
996
|
serviceName,
|
|
981
|
-
serviceInstanceId:
|
|
997
|
+
serviceInstanceId: uuid6,
|
|
982
998
|
serviceTransportId: trackedTransport.uuid,
|
|
983
999
|
serviceOrigin: trackedTransport.origin,
|
|
984
1000
|
transportProtocols: trackedTransport.protocols,
|
|
@@ -992,7 +1008,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
992
1008
|
} else {
|
|
993
1009
|
emit("meta.service_registry.routeable_transport_missing", {
|
|
994
1010
|
serviceName,
|
|
995
|
-
serviceInstanceId:
|
|
1011
|
+
serviceInstanceId: uuid6,
|
|
996
1012
|
requiredRole: this.getRoutingTransportRole(),
|
|
997
1013
|
isFrontend: this.isFrontend
|
|
998
1014
|
});
|
|
@@ -1455,6 +1471,9 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
1455
1471
|
this.getBalancedInstance = CadenzaService.createMetaTask(
|
|
1456
1472
|
"Get balanced instance",
|
|
1457
1473
|
(context, emit) => {
|
|
1474
|
+
if (context.__remoteRoutineName !== void 0) {
|
|
1475
|
+
context = ensureDelegationContextMetadata(context);
|
|
1476
|
+
}
|
|
1458
1477
|
const {
|
|
1459
1478
|
__serviceName,
|
|
1460
1479
|
__triedInstances,
|
|
@@ -3134,7 +3153,7 @@ var ServiceRegistry = class _ServiceRegistry {
|
|
|
3134
3153
|
|
|
3135
3154
|
// src/graph/definition/SignalTransmissionTask.ts
|
|
3136
3155
|
import { Task as Task2 } from "@cadenza.io/core";
|
|
3137
|
-
import { v4 as
|
|
3156
|
+
import { v4 as uuid3 } from "uuid";
|
|
3138
3157
|
var SignalTransmissionTask = class extends Task2 {
|
|
3139
3158
|
/**
|
|
3140
3159
|
* Constructs a new instance of the class and initializes it with the provided parameters.
|
|
@@ -3163,7 +3182,7 @@ var SignalTransmissionTask = class extends Task2 {
|
|
|
3163
3182
|
*/
|
|
3164
3183
|
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) {
|
|
3165
3184
|
const taskFunction = (context) => {
|
|
3166
|
-
context.__routineExecId =
|
|
3185
|
+
context.__routineExecId = uuid3();
|
|
3167
3186
|
return context;
|
|
3168
3187
|
};
|
|
3169
3188
|
super(
|
|
@@ -3343,6 +3362,8 @@ var RestController = class _RestController {
|
|
|
3343
3362
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
3344
3363
|
return;
|
|
3345
3364
|
}
|
|
3365
|
+
const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
|
|
3366
|
+
const deputyExecId = normalizedDelegateCtx.__metadata.__deputyExecId;
|
|
3346
3367
|
fetchDiagnostics.delegationRequests++;
|
|
3347
3368
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3348
3369
|
let resultContext;
|
|
@@ -3354,7 +3375,7 @@ var RestController = class _RestController {
|
|
|
3354
3375
|
"Content-Type": "application/json"
|
|
3355
3376
|
},
|
|
3356
3377
|
method: "POST",
|
|
3357
|
-
body: JSON.stringify(
|
|
3378
|
+
body: JSON.stringify(normalizedDelegateCtx)
|
|
3358
3379
|
},
|
|
3359
3380
|
3e4
|
|
3360
3381
|
);
|
|
@@ -3365,14 +3386,11 @@ var RestController = class _RestController {
|
|
|
3365
3386
|
resultContext = {
|
|
3366
3387
|
__error: `Error: ${error}`,
|
|
3367
3388
|
errored: true,
|
|
3368
|
-
...
|
|
3369
|
-
...
|
|
3389
|
+
...normalizedDelegateCtx,
|
|
3390
|
+
...normalizedDelegateCtx.__metadata
|
|
3370
3391
|
};
|
|
3371
3392
|
} finally {
|
|
3372
|
-
emit(
|
|
3373
|
-
`meta.fetch.delegated:${delegateCtx.__metadata.__deputyExecId}`,
|
|
3374
|
-
resultContext
|
|
3375
|
-
);
|
|
3393
|
+
emit(`meta.fetch.delegated:${deputyExecId}`, resultContext);
|
|
3376
3394
|
}
|
|
3377
3395
|
return resultContext;
|
|
3378
3396
|
},
|
|
@@ -4051,11 +4069,12 @@ var SocketController = class _SocketController {
|
|
|
4051
4069
|
CadenzaService.emit("meta.socket.handshake", ctx);
|
|
4052
4070
|
});
|
|
4053
4071
|
ws.on("delegation", (ctx, callback) => {
|
|
4054
|
-
const
|
|
4072
|
+
const delegationCtx = ensureDelegationContextMetadata(ctx);
|
|
4073
|
+
const deputyExecId = delegationCtx.__metadata.__deputyExecId;
|
|
4055
4074
|
CadenzaService.createEphemeralMetaTask(
|
|
4056
4075
|
"Resolve delegation",
|
|
4057
|
-
(
|
|
4058
|
-
callback(
|
|
4076
|
+
(delegationCtx2) => {
|
|
4077
|
+
callback(delegationCtx2);
|
|
4059
4078
|
},
|
|
4060
4079
|
"Resolves a delegation request using client callback.",
|
|
4061
4080
|
{ register: false }
|
|
@@ -4078,8 +4097,8 @@ var SocketController = class _SocketController {
|
|
|
4078
4097
|
`meta.node.graph_completed:${deputyExecId}`
|
|
4079
4098
|
).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
|
|
4080
4099
|
CadenzaService.emit("meta.socket.delegation_requested", {
|
|
4081
|
-
...
|
|
4082
|
-
__name:
|
|
4100
|
+
...delegationCtx,
|
|
4101
|
+
__name: delegationCtx.__remoteRoutineName
|
|
4083
4102
|
});
|
|
4084
4103
|
});
|
|
4085
4104
|
ws.on("signal", (ctx, callback) => {
|
|
@@ -4699,9 +4718,10 @@ var SocketController = class _SocketController {
|
|
|
4699
4718
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
4700
4719
|
return;
|
|
4701
4720
|
}
|
|
4702
|
-
|
|
4703
|
-
delete
|
|
4704
|
-
|
|
4721
|
+
const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
|
|
4722
|
+
delete normalizedDelegateCtx.__isSubMeta;
|
|
4723
|
+
delete normalizedDelegateCtx.__broadcast;
|
|
4724
|
+
const deputyExecId = normalizedDelegateCtx.__metadata?.__deputyExecId;
|
|
4705
4725
|
const requestSentAt = Date.now();
|
|
4706
4726
|
if (deputyExecId) {
|
|
4707
4727
|
runtimeHandle.pendingDelegationIds.add(deputyExecId);
|
|
@@ -4710,8 +4730,8 @@ var SocketController = class _SocketController {
|
|
|
4710
4730
|
try {
|
|
4711
4731
|
const resultContext = await runtimeHandle.emitWhenReady?.(
|
|
4712
4732
|
"delegation",
|
|
4713
|
-
|
|
4714
|
-
|
|
4733
|
+
normalizedDelegateCtx,
|
|
4734
|
+
normalizedDelegateCtx.__timeout ?? 6e4
|
|
4715
4735
|
) ?? {
|
|
4716
4736
|
errored: true,
|
|
4717
4737
|
__error: "Socket delegation returned no response"
|
|
@@ -5576,7 +5596,7 @@ var DatabaseController = class _DatabaseController {
|
|
|
5576
5596
|
};
|
|
5577
5597
|
|
|
5578
5598
|
// src/Cadenza.ts
|
|
5579
|
-
import { v4 as
|
|
5599
|
+
import { v4 as uuid4 } from "uuid";
|
|
5580
5600
|
|
|
5581
5601
|
// src/graph/controllers/GraphSyncController.ts
|
|
5582
5602
|
var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
|
|
@@ -6684,7 +6704,7 @@ var CadenzaService = class {
|
|
|
6684
6704
|
(transport) => !!transport
|
|
6685
6705
|
).map((transport) => ({
|
|
6686
6706
|
...transport,
|
|
6687
|
-
uuid:
|
|
6707
|
+
uuid: uuid4()
|
|
6688
6708
|
}));
|
|
6689
6709
|
}
|
|
6690
6710
|
static createBootstrapTransport(serviceInstanceId, role, endpoint) {
|
|
@@ -6928,7 +6948,7 @@ var CadenzaService = class {
|
|
|
6928
6948
|
}
|
|
6929
6949
|
for (const responder of responders) {
|
|
6930
6950
|
const { task, descriptor } = responder;
|
|
6931
|
-
const inquiryId =
|
|
6951
|
+
const inquiryId = uuid4();
|
|
6932
6952
|
startTimeByTask.set(task, Date.now());
|
|
6933
6953
|
const resolverTask = this.createEphemeralMetaTask(
|
|
6934
6954
|
`Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
|
|
@@ -7419,7 +7439,7 @@ var CadenzaService = class {
|
|
|
7419
7439
|
this.bootstrap();
|
|
7420
7440
|
this.validateName(serviceName);
|
|
7421
7441
|
this.validateServiceName(serviceName);
|
|
7422
|
-
const serviceId = options.customServiceId ??
|
|
7442
|
+
const serviceId = options.customServiceId ?? uuid4();
|
|
7423
7443
|
this.serviceRegistry.serviceName = serviceName;
|
|
7424
7444
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
7425
7445
|
this.setHydrationResults(options.hydration);
|
|
@@ -8253,7 +8273,7 @@ import {
|
|
|
8253
8273
|
} from "@cadenza.io/core";
|
|
8254
8274
|
|
|
8255
8275
|
// src/ssr/createSSRInquiryBridge.ts
|
|
8256
|
-
import { v4 as
|
|
8276
|
+
import { v4 as uuid5 } from "uuid";
|
|
8257
8277
|
function ensureFetch() {
|
|
8258
8278
|
if (typeof globalThis.fetch !== "function") {
|
|
8259
8279
|
throw new Error("SSR inquiry bridge requires global fetch support.");
|
|
@@ -8342,7 +8362,7 @@ function createSSRInquiryBridge(options = {}) {
|
|
|
8342
8362
|
__remoteRoutineName: remoteRoutineName,
|
|
8343
8363
|
__metadata: {
|
|
8344
8364
|
...context.__metadata ?? {},
|
|
8345
|
-
__deputyExecId:
|
|
8365
|
+
__deputyExecId: uuid5()
|
|
8346
8366
|
}
|
|
8347
8367
|
}),
|
|
8348
8368
|
signal
|