@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/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 uuid7 = 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 (!uuid7 || !serviceInstanceId || !config) {
|
|
391
391
|
return null;
|
|
392
392
|
}
|
|
393
393
|
return {
|
|
394
|
-
uuid:
|
|
394
|
+
uuid: uuid7,
|
|
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 uuid7 = normalizeString2(raw.uuid);
|
|
457
457
|
const serviceName = normalizeString2(raw.serviceName ?? raw.service_name);
|
|
458
|
-
if (!
|
|
458
|
+
if (!uuid7 || !serviceName) {
|
|
459
459
|
return null;
|
|
460
460
|
}
|
|
461
|
-
const transports = normalizeTransportArray(raw.transports,
|
|
461
|
+
const transports = normalizeTransportArray(raw.transports, uuid7);
|
|
462
462
|
return {
|
|
463
|
-
uuid:
|
|
463
|
+
uuid: uuid7,
|
|
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 uuid7 = 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 (uuid7 === 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 === uuid7);
|
|
930
|
+
const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid7) ?? -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(uuid7, 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 === uuid7);
|
|
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 === uuid7);
|
|
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, uuid7, 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: uuid7,
|
|
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: uuid7,
|
|
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(
|
|
@@ -3233,7 +3252,7 @@ import http from "http";
|
|
|
3233
3252
|
import fs from "fs";
|
|
3234
3253
|
import https from "https";
|
|
3235
3254
|
import fetch from "node-fetch";
|
|
3236
|
-
import { v4 as
|
|
3255
|
+
import { v4 as uuid4 } from "uuid";
|
|
3237
3256
|
var RestController = class _RestController {
|
|
3238
3257
|
/**
|
|
3239
3258
|
* Constructor for initializing the REST server and related configurations.
|
|
@@ -3409,10 +3428,8 @@ var RestController = class _RestController {
|
|
|
3409
3428
|
}
|
|
3410
3429
|
});
|
|
3411
3430
|
app.post("/delegation", (req, res) => {
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
ctx2 = req.body;
|
|
3415
|
-
deputyExecId = ctx2.__metadata.__deputyExecId;
|
|
3431
|
+
const ctx2 = ensureDelegationContextMetadata(req.body);
|
|
3432
|
+
const deputyExecId = ctx2.__metadata.__deputyExecId;
|
|
3416
3433
|
const remoteRoutineName = ctx2.__remoteRoutineName;
|
|
3417
3434
|
const targetNotFoundSignal = `meta.rest.delegation_target_not_found:${deputyExecId}`;
|
|
3418
3435
|
let resolved = false;
|
|
@@ -3595,7 +3612,7 @@ var RestController = class _RestController {
|
|
|
3595
3612
|
const internalOrigin = httpOrigin ?? httpsOrigin;
|
|
3596
3613
|
if (internalOrigin) {
|
|
3597
3614
|
transportData.unshift({
|
|
3598
|
-
uuid:
|
|
3615
|
+
uuid: uuid4(),
|
|
3599
3616
|
service_instance_id: ctx.__serviceInstanceId,
|
|
3600
3617
|
role: "internal",
|
|
3601
3618
|
origin: internalOrigin,
|
|
@@ -3761,6 +3778,8 @@ var RestController = class _RestController {
|
|
|
3761
3778
|
if (ctx2.__remoteRoutineName === void 0) {
|
|
3762
3779
|
return;
|
|
3763
3780
|
}
|
|
3781
|
+
const delegateCtx = ensureDelegationContextMetadata(ctx2);
|
|
3782
|
+
const deputyExecId = delegateCtx.__metadata.__deputyExecId;
|
|
3764
3783
|
fetchDiagnostics.delegationRequests++;
|
|
3765
3784
|
fetchDiagnostics.updatedAt = Date.now();
|
|
3766
3785
|
let resultContext;
|
|
@@ -3772,7 +3791,7 @@ var RestController = class _RestController {
|
|
|
3772
3791
|
"Content-Type": "application/json"
|
|
3773
3792
|
},
|
|
3774
3793
|
method: "POST",
|
|
3775
|
-
body: JSON.stringify(
|
|
3794
|
+
body: JSON.stringify(delegateCtx)
|
|
3776
3795
|
},
|
|
3777
3796
|
3e4
|
|
3778
3797
|
);
|
|
@@ -3794,14 +3813,11 @@ var RestController = class _RestController {
|
|
|
3794
3813
|
resultContext = {
|
|
3795
3814
|
__error: `Error: ${e}`,
|
|
3796
3815
|
errored: true,
|
|
3797
|
-
...
|
|
3798
|
-
...
|
|
3816
|
+
...delegateCtx,
|
|
3817
|
+
...delegateCtx.__metadata
|
|
3799
3818
|
};
|
|
3800
3819
|
} finally {
|
|
3801
|
-
emit(
|
|
3802
|
-
`meta.fetch.delegated:${ctx2.__metadata.__deputyExecId}`,
|
|
3803
|
-
resultContext
|
|
3804
|
-
);
|
|
3820
|
+
emit(`meta.fetch.delegated:${deputyExecId}`, resultContext);
|
|
3805
3821
|
}
|
|
3806
3822
|
return resultContext;
|
|
3807
3823
|
},
|
|
@@ -4510,11 +4526,12 @@ var SocketController = class _SocketController {
|
|
|
4510
4526
|
CadenzaService.emit("meta.socket.handshake", ctx);
|
|
4511
4527
|
});
|
|
4512
4528
|
ws.on("delegation", (ctx, callback) => {
|
|
4513
|
-
const
|
|
4529
|
+
const delegationCtx = ensureDelegationContextMetadata(ctx);
|
|
4530
|
+
const deputyExecId = delegationCtx.__metadata.__deputyExecId;
|
|
4514
4531
|
CadenzaService.createEphemeralMetaTask(
|
|
4515
4532
|
"Resolve delegation",
|
|
4516
|
-
(
|
|
4517
|
-
callback(
|
|
4533
|
+
(delegationCtx2) => {
|
|
4534
|
+
callback(delegationCtx2);
|
|
4518
4535
|
},
|
|
4519
4536
|
"Resolves a delegation request using client callback.",
|
|
4520
4537
|
{ register: false }
|
|
@@ -4537,8 +4554,8 @@ var SocketController = class _SocketController {
|
|
|
4537
4554
|
`meta.node.graph_completed:${deputyExecId}`
|
|
4538
4555
|
).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
|
|
4539
4556
|
CadenzaService.emit("meta.socket.delegation_requested", {
|
|
4540
|
-
...
|
|
4541
|
-
__name:
|
|
4557
|
+
...delegationCtx,
|
|
4558
|
+
__name: delegationCtx.__remoteRoutineName
|
|
4542
4559
|
});
|
|
4543
4560
|
});
|
|
4544
4561
|
ws.on("signal", (ctx, callback) => {
|
|
@@ -5158,9 +5175,10 @@ var SocketController = class _SocketController {
|
|
|
5158
5175
|
if (delegateCtx.__remoteRoutineName === void 0) {
|
|
5159
5176
|
return;
|
|
5160
5177
|
}
|
|
5161
|
-
|
|
5162
|
-
delete
|
|
5163
|
-
|
|
5178
|
+
const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
|
|
5179
|
+
delete normalizedDelegateCtx.__isSubMeta;
|
|
5180
|
+
delete normalizedDelegateCtx.__broadcast;
|
|
5181
|
+
const deputyExecId = normalizedDelegateCtx.__metadata?.__deputyExecId;
|
|
5164
5182
|
const requestSentAt = Date.now();
|
|
5165
5183
|
if (deputyExecId) {
|
|
5166
5184
|
runtimeHandle.pendingDelegationIds.add(deputyExecId);
|
|
@@ -5169,8 +5187,8 @@ var SocketController = class _SocketController {
|
|
|
5169
5187
|
try {
|
|
5170
5188
|
const resultContext = await runtimeHandle.emitWhenReady?.(
|
|
5171
5189
|
"delegation",
|
|
5172
|
-
|
|
5173
|
-
|
|
5190
|
+
normalizedDelegateCtx,
|
|
5191
|
+
normalizedDelegateCtx.__timeout ?? 6e4
|
|
5174
5192
|
) ?? {
|
|
5175
5193
|
errored: true,
|
|
5176
5194
|
__error: "Socket delegation returned no response"
|
|
@@ -8017,7 +8035,7 @@ function tableFieldTypeToSchemaType(type) {
|
|
|
8017
8035
|
}
|
|
8018
8036
|
|
|
8019
8037
|
// src/Cadenza.ts
|
|
8020
|
-
import { v4 as
|
|
8038
|
+
import { v4 as uuid5 } from "uuid";
|
|
8021
8039
|
|
|
8022
8040
|
// src/graph/controllers/GraphSyncController.ts
|
|
8023
8041
|
var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
|
|
@@ -9125,7 +9143,7 @@ var CadenzaService = class {
|
|
|
9125
9143
|
(transport) => !!transport
|
|
9126
9144
|
).map((transport) => ({
|
|
9127
9145
|
...transport,
|
|
9128
|
-
uuid:
|
|
9146
|
+
uuid: uuid5()
|
|
9129
9147
|
}));
|
|
9130
9148
|
}
|
|
9131
9149
|
static createBootstrapTransport(serviceInstanceId, role, endpoint) {
|
|
@@ -9369,7 +9387,7 @@ var CadenzaService = class {
|
|
|
9369
9387
|
}
|
|
9370
9388
|
for (const responder of responders) {
|
|
9371
9389
|
const { task, descriptor } = responder;
|
|
9372
|
-
const inquiryId =
|
|
9390
|
+
const inquiryId = uuid5();
|
|
9373
9391
|
startTimeByTask.set(task, Date.now());
|
|
9374
9392
|
const resolverTask = this.createEphemeralMetaTask(
|
|
9375
9393
|
`Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
|
|
@@ -9860,7 +9878,7 @@ var CadenzaService = class {
|
|
|
9860
9878
|
this.bootstrap();
|
|
9861
9879
|
this.validateName(serviceName);
|
|
9862
9880
|
this.validateServiceName(serviceName);
|
|
9863
|
-
const serviceId = options.customServiceId ??
|
|
9881
|
+
const serviceId = options.customServiceId ?? uuid5();
|
|
9864
9882
|
this.serviceRegistry.serviceName = serviceName;
|
|
9865
9883
|
this.serviceRegistry.serviceInstanceId = serviceId;
|
|
9866
9884
|
this.setHydrationResults(options.hydration);
|
|
@@ -10694,7 +10712,7 @@ import {
|
|
|
10694
10712
|
} from "@cadenza.io/core";
|
|
10695
10713
|
|
|
10696
10714
|
// src/ssr/createSSRInquiryBridge.ts
|
|
10697
|
-
import { v4 as
|
|
10715
|
+
import { v4 as uuid6 } from "uuid";
|
|
10698
10716
|
function ensureFetch() {
|
|
10699
10717
|
if (typeof globalThis.fetch !== "function") {
|
|
10700
10718
|
throw new Error("SSR inquiry bridge requires global fetch support.");
|
|
@@ -10783,7 +10801,7 @@ function createSSRInquiryBridge(options = {}) {
|
|
|
10783
10801
|
__remoteRoutineName: remoteRoutineName,
|
|
10784
10802
|
__metadata: {
|
|
10785
10803
|
...context.__metadata ?? {},
|
|
10786
|
-
__deputyExecId:
|
|
10804
|
+
__deputyExecId: uuid6()
|
|
10787
10805
|
}
|
|
10788
10806
|
}),
|
|
10789
10807
|
signal
|