@cadenza.io/service 2.9.0 → 2.11.0
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.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +401 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +366 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -30,25 +30,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Actor: () =>
|
|
33
|
+
Actor: () => import_core5.Actor,
|
|
34
34
|
DatabaseTask: () => DatabaseTask,
|
|
35
|
-
DebounceTask: () =>
|
|
35
|
+
DebounceTask: () => import_core5.DebounceTask,
|
|
36
36
|
DeputyTask: () => DeputyTask,
|
|
37
|
-
EphemeralTask: () =>
|
|
37
|
+
EphemeralTask: () => import_core5.EphemeralTask,
|
|
38
38
|
GraphMetadataController: () => GraphMetadataController,
|
|
39
|
-
GraphRoutine: () =>
|
|
39
|
+
GraphRoutine: () => import_core5.GraphRoutine,
|
|
40
40
|
RestController: () => RestController,
|
|
41
41
|
ServiceRegistry: () => ServiceRegistry,
|
|
42
42
|
SignalController: () => SignalController,
|
|
43
43
|
SignalTransmissionTask: () => SignalTransmissionTask,
|
|
44
44
|
SocketController: () => SocketController,
|
|
45
|
-
Task: () =>
|
|
45
|
+
Task: () => import_core5.Task,
|
|
46
46
|
default: () => index_default
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(index_exports);
|
|
49
49
|
|
|
50
50
|
// src/Cadenza.ts
|
|
51
|
-
var
|
|
51
|
+
var import_core4 = __toESM(require("@cadenza.io/core"));
|
|
52
52
|
|
|
53
53
|
// src/graph/definition/DeputyTask.ts
|
|
54
54
|
var import_uuid = require("uuid");
|
|
@@ -3346,6 +3346,44 @@ var SocketController = class _SocketController {
|
|
|
3346
3346
|
this.diagnosticsMaxClientEntries = 500;
|
|
3347
3347
|
this.destroyedDiagnosticsTtlMs = 15 * 6e4;
|
|
3348
3348
|
this.socketServerDefaultKey = "socket-server-default";
|
|
3349
|
+
this.socketServerInitialSessionState = {
|
|
3350
|
+
serverKey: this.socketServerDefaultKey,
|
|
3351
|
+
useSocket: false,
|
|
3352
|
+
status: "inactive",
|
|
3353
|
+
securityProfile: "medium",
|
|
3354
|
+
networkType: "internal",
|
|
3355
|
+
connectionCount: 0,
|
|
3356
|
+
lastStartedAt: null,
|
|
3357
|
+
lastConnectedAt: null,
|
|
3358
|
+
lastDisconnectedAt: null,
|
|
3359
|
+
lastShutdownAt: null,
|
|
3360
|
+
updatedAt: 0
|
|
3361
|
+
};
|
|
3362
|
+
this.socketClientInitialSessionState = {
|
|
3363
|
+
fetchId: "",
|
|
3364
|
+
serviceInstanceId: "",
|
|
3365
|
+
communicationTypes: [],
|
|
3366
|
+
serviceName: "",
|
|
3367
|
+
serviceAddress: "",
|
|
3368
|
+
servicePort: 0,
|
|
3369
|
+
protocol: "http",
|
|
3370
|
+
url: "",
|
|
3371
|
+
socketId: null,
|
|
3372
|
+
connected: false,
|
|
3373
|
+
handshake: false,
|
|
3374
|
+
pendingDelegations: 0,
|
|
3375
|
+
pendingTimers: 0,
|
|
3376
|
+
reconnectAttempts: 0,
|
|
3377
|
+
connectErrors: 0,
|
|
3378
|
+
reconnectErrors: 0,
|
|
3379
|
+
socketErrors: 0,
|
|
3380
|
+
errorCount: 0,
|
|
3381
|
+
destroyed: false,
|
|
3382
|
+
lastHandshakeAt: null,
|
|
3383
|
+
lastHandshakeError: null,
|
|
3384
|
+
lastDisconnectAt: null,
|
|
3385
|
+
updatedAt: 0
|
|
3386
|
+
};
|
|
3349
3387
|
this.socketServerActor = CadenzaService.createActor(
|
|
3350
3388
|
{
|
|
3351
3389
|
name: "SocketServerActor",
|
|
@@ -3354,9 +3392,7 @@ var SocketController = class _SocketController {
|
|
|
3354
3392
|
keyResolver: (input) => this.resolveSocketServerKey(input),
|
|
3355
3393
|
loadPolicy: "lazy",
|
|
3356
3394
|
writeContract: "overwrite",
|
|
3357
|
-
initState: this.
|
|
3358
|
-
this.socketServerDefaultKey
|
|
3359
|
-
)
|
|
3395
|
+
initState: this.socketServerInitialSessionState
|
|
3360
3396
|
},
|
|
3361
3397
|
{ isMeta: true }
|
|
3362
3398
|
);
|
|
@@ -3368,7 +3404,7 @@ var SocketController = class _SocketController {
|
|
|
3368
3404
|
keyResolver: (input) => this.resolveSocketClientFetchId(input),
|
|
3369
3405
|
loadPolicy: "lazy",
|
|
3370
3406
|
writeContract: "overwrite",
|
|
3371
|
-
initState: this.
|
|
3407
|
+
initState: this.socketClientInitialSessionState
|
|
3372
3408
|
},
|
|
3373
3409
|
{ isMeta: true }
|
|
3374
3410
|
);
|
|
@@ -4449,48 +4485,6 @@ var SocketController = class _SocketController {
|
|
|
4449
4485
|
"Connects to a specified socket server and wires runtime tasks."
|
|
4450
4486
|
).doOn("meta.fetch.handshake_complete").emitsOnFail("meta.socket_client.connect_failed");
|
|
4451
4487
|
}
|
|
4452
|
-
createInitialSocketServerSessionState(serverKey) {
|
|
4453
|
-
return {
|
|
4454
|
-
serverKey,
|
|
4455
|
-
useSocket: false,
|
|
4456
|
-
status: "inactive",
|
|
4457
|
-
securityProfile: "medium",
|
|
4458
|
-
networkType: "internal",
|
|
4459
|
-
connectionCount: 0,
|
|
4460
|
-
lastStartedAt: null,
|
|
4461
|
-
lastConnectedAt: null,
|
|
4462
|
-
lastDisconnectedAt: null,
|
|
4463
|
-
lastShutdownAt: null,
|
|
4464
|
-
updatedAt: 0
|
|
4465
|
-
};
|
|
4466
|
-
}
|
|
4467
|
-
createInitialSocketClientSessionState() {
|
|
4468
|
-
return {
|
|
4469
|
-
fetchId: "",
|
|
4470
|
-
serviceInstanceId: "",
|
|
4471
|
-
communicationTypes: [],
|
|
4472
|
-
serviceName: "",
|
|
4473
|
-
serviceAddress: "",
|
|
4474
|
-
servicePort: 0,
|
|
4475
|
-
protocol: "http",
|
|
4476
|
-
url: "",
|
|
4477
|
-
socketId: null,
|
|
4478
|
-
connected: false,
|
|
4479
|
-
handshake: false,
|
|
4480
|
-
pendingDelegations: 0,
|
|
4481
|
-
pendingTimers: 0,
|
|
4482
|
-
reconnectAttempts: 0,
|
|
4483
|
-
connectErrors: 0,
|
|
4484
|
-
reconnectErrors: 0,
|
|
4485
|
-
socketErrors: 0,
|
|
4486
|
-
errorCount: 0,
|
|
4487
|
-
destroyed: false,
|
|
4488
|
-
lastHandshakeAt: null,
|
|
4489
|
-
lastHandshakeError: null,
|
|
4490
|
-
lastDisconnectAt: null,
|
|
4491
|
-
updatedAt: 0
|
|
4492
|
-
};
|
|
4493
|
-
}
|
|
4494
4488
|
resolveSocketServerKey(input) {
|
|
4495
4489
|
return String(input.serverKey ?? input.__socketServerKey ?? this.socketServerDefaultKey).trim() || this.socketServerDefaultKey;
|
|
4496
4490
|
}
|
|
@@ -4823,6 +4817,7 @@ var SignalController = class _SignalController {
|
|
|
4823
4817
|
};
|
|
4824
4818
|
|
|
4825
4819
|
// src/graph/controllers/GraphMetadataController.ts
|
|
4820
|
+
var import_core3 = require("@cadenza.io/core");
|
|
4826
4821
|
var GraphMetadataController = class _GraphMetadataController {
|
|
4827
4822
|
static get instance() {
|
|
4828
4823
|
if (!this._instance) this._instance = new _GraphMetadataController();
|
|
@@ -5040,6 +5035,139 @@ var GraphMetadataController = class _GraphMetadataController {
|
|
|
5040
5035
|
"Handles task execution relationship creation",
|
|
5041
5036
|
{ concurrency: 100, isSubMeta: true }
|
|
5042
5037
|
).doOn("meta.node.mapped", "meta.node.detected_previous_task_execution").emits("global.meta.graph_metadata.relationship_executed");
|
|
5038
|
+
CadenzaService.createMetaTask("Handle actor creation", (ctx) => {
|
|
5039
|
+
return {
|
|
5040
|
+
data: {
|
|
5041
|
+
...ctx.data,
|
|
5042
|
+
service_name: CadenzaService.serviceRegistry.serviceName
|
|
5043
|
+
}
|
|
5044
|
+
};
|
|
5045
|
+
}).doOn("meta.actor.created").emits("global.meta.graph_metadata.actor_created");
|
|
5046
|
+
CadenzaService.createMetaTask("Handle actor task association", (ctx) => {
|
|
5047
|
+
return {
|
|
5048
|
+
data: {
|
|
5049
|
+
...ctx.data,
|
|
5050
|
+
service_name: CadenzaService.serviceRegistry.serviceName
|
|
5051
|
+
}
|
|
5052
|
+
};
|
|
5053
|
+
}).doOn("meta.actor.task_associated").emits("global.meta.graph_metadata.actor_task_associated");
|
|
5054
|
+
const actorSessionStateInsertTask = CadenzaService.get("dbInsertActorSessionState") ?? CadenzaService.get("Insert actor_session_state in CadenzaDB") ?? CadenzaService.createCadenzaDBInsertTask(
|
|
5055
|
+
"actor_session_state",
|
|
5056
|
+
{},
|
|
5057
|
+
{ concurrency: 100, isSubMeta: true }
|
|
5058
|
+
);
|
|
5059
|
+
const validateActorSessionStatePersistenceTask = CadenzaService.createMetaTask(
|
|
5060
|
+
"Validate actor session state persistence",
|
|
5061
|
+
(ctx) => {
|
|
5062
|
+
if (ctx.errored || ctx.failed || ctx.__success !== true) {
|
|
5063
|
+
throw new Error(
|
|
5064
|
+
String(
|
|
5065
|
+
ctx.__error ?? ctx.error ?? "actor_session_state persistence query failed"
|
|
5066
|
+
)
|
|
5067
|
+
);
|
|
5068
|
+
}
|
|
5069
|
+
const rowCount = Number(ctx.rowCount ?? 0);
|
|
5070
|
+
if (!Number.isFinite(rowCount) || rowCount <= 0) {
|
|
5071
|
+
throw new Error(
|
|
5072
|
+
"actor_session_state persistence did not affect any rows (possible stale durable_version)"
|
|
5073
|
+
);
|
|
5074
|
+
}
|
|
5075
|
+
return {
|
|
5076
|
+
__success: true,
|
|
5077
|
+
persisted: true,
|
|
5078
|
+
actor_name: ctx.actor_name,
|
|
5079
|
+
actor_version: ctx.actor_version,
|
|
5080
|
+
actor_key: ctx.actor_key,
|
|
5081
|
+
service_name: ctx.service_name,
|
|
5082
|
+
durable_version: ctx.durable_version
|
|
5083
|
+
};
|
|
5084
|
+
},
|
|
5085
|
+
"Enforces strict actor session persistence success contract.",
|
|
5086
|
+
{ isSubMeta: true, concurrency: 100 }
|
|
5087
|
+
);
|
|
5088
|
+
const insertAndValidateActorSessionStateTask = actorSessionStateInsertTask.then(
|
|
5089
|
+
validateActorSessionStatePersistenceTask
|
|
5090
|
+
);
|
|
5091
|
+
CadenzaService.createMetaTask(
|
|
5092
|
+
"Persist actor session state",
|
|
5093
|
+
(ctx) => {
|
|
5094
|
+
const actorName = typeof ctx.actor_name === "string" ? ctx.actor_name.trim() : "";
|
|
5095
|
+
const actorKey = typeof ctx.actor_key === "string" ? ctx.actor_key.trim() : "";
|
|
5096
|
+
const actorVersion = Number(ctx.actor_version ?? 1);
|
|
5097
|
+
const durableVersion = Number(ctx.durable_version);
|
|
5098
|
+
if (!actorName) {
|
|
5099
|
+
throw new Error("actor_name is required for actor session persistence");
|
|
5100
|
+
}
|
|
5101
|
+
if (!actorKey) {
|
|
5102
|
+
throw new Error("actor_key is required for actor session persistence");
|
|
5103
|
+
}
|
|
5104
|
+
if (!Number.isInteger(actorVersion) || actorVersion < 1) {
|
|
5105
|
+
throw new Error("actor_version must be a positive integer");
|
|
5106
|
+
}
|
|
5107
|
+
if (!Number.isInteger(durableVersion) || durableVersion < 0) {
|
|
5108
|
+
throw new Error("durable_version must be a non-negative integer");
|
|
5109
|
+
}
|
|
5110
|
+
if (typeof ctx.durable_state !== "object" || ctx.durable_state === null || Array.isArray(ctx.durable_state)) {
|
|
5111
|
+
throw new Error("durable_state must be a non-null object");
|
|
5112
|
+
}
|
|
5113
|
+
const serviceName = CadenzaService.serviceRegistry.serviceName;
|
|
5114
|
+
if (!serviceName) {
|
|
5115
|
+
throw new Error("service_name is not available for actor session persistence");
|
|
5116
|
+
}
|
|
5117
|
+
let expiresAt = null;
|
|
5118
|
+
if (ctx.expires_at !== void 0 && ctx.expires_at !== null) {
|
|
5119
|
+
if (ctx.expires_at instanceof Date) {
|
|
5120
|
+
expiresAt = ctx.expires_at.toISOString();
|
|
5121
|
+
} else if (typeof ctx.expires_at === "string" && ctx.expires_at.trim().length > 0) {
|
|
5122
|
+
expiresAt = ctx.expires_at;
|
|
5123
|
+
} else {
|
|
5124
|
+
throw new Error("expires_at must be null, Date, or non-empty string");
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5128
|
+
return {
|
|
5129
|
+
...ctx,
|
|
5130
|
+
actor_name: actorName,
|
|
5131
|
+
actor_key: actorKey,
|
|
5132
|
+
actor_version: actorVersion,
|
|
5133
|
+
durable_version: durableVersion,
|
|
5134
|
+
expires_at: expiresAt,
|
|
5135
|
+
service_name: serviceName,
|
|
5136
|
+
queryData: {
|
|
5137
|
+
data: {
|
|
5138
|
+
actor_name: actorName,
|
|
5139
|
+
actor_version: actorVersion,
|
|
5140
|
+
actor_key: actorKey,
|
|
5141
|
+
service_name: serviceName,
|
|
5142
|
+
durable_state: ctx.durable_state,
|
|
5143
|
+
durable_version: durableVersion,
|
|
5144
|
+
expires_at: expiresAt,
|
|
5145
|
+
updated: updatedAt
|
|
5146
|
+
},
|
|
5147
|
+
onConflict: {
|
|
5148
|
+
target: [
|
|
5149
|
+
"actor_name",
|
|
5150
|
+
"actor_version",
|
|
5151
|
+
"actor_key",
|
|
5152
|
+
"service_name"
|
|
5153
|
+
],
|
|
5154
|
+
action: {
|
|
5155
|
+
do: "update",
|
|
5156
|
+
set: {
|
|
5157
|
+
durable_state: "excluded",
|
|
5158
|
+
durable_version: "excluded",
|
|
5159
|
+
expires_at: "excluded",
|
|
5160
|
+
updated: "excluded"
|
|
5161
|
+
},
|
|
5162
|
+
where: "actor_session_state.durable_version <= excluded.durable_version"
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
};
|
|
5167
|
+
},
|
|
5168
|
+
"Validates and prepares actor_session_state payload for strict write-through persistence.",
|
|
5169
|
+
{ isSubMeta: true, concurrency: 100 }
|
|
5170
|
+
).then(insertAndValidateActorSessionStateTask).respondsTo(import_core3.META_ACTOR_SESSION_STATE_PERSIST_INTENT);
|
|
5043
5171
|
CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
|
|
5044
5172
|
const intentName = ctx.data?.name;
|
|
5045
5173
|
return {
|
|
@@ -6711,8 +6839,69 @@ function tableFieldTypeToSchemaType(type) {
|
|
|
6711
6839
|
var import_uuid3 = require("uuid");
|
|
6712
6840
|
|
|
6713
6841
|
// src/graph/controllers/GraphSyncController.ts
|
|
6842
|
+
var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
|
|
6843
|
+
function getActorTaskRuntimeMetadata(taskFunction) {
|
|
6844
|
+
if (typeof taskFunction !== "function") {
|
|
6845
|
+
return void 0;
|
|
6846
|
+
}
|
|
6847
|
+
return taskFunction[ACTOR_TASK_METADATA];
|
|
6848
|
+
}
|
|
6849
|
+
function sanitizeActorMetadataValue(value) {
|
|
6850
|
+
if (value === null) {
|
|
6851
|
+
return null;
|
|
6852
|
+
}
|
|
6853
|
+
if (value === void 0 || typeof value === "function") {
|
|
6854
|
+
return void 0;
|
|
6855
|
+
}
|
|
6856
|
+
if (Array.isArray(value)) {
|
|
6857
|
+
const items = [];
|
|
6858
|
+
for (const item of value) {
|
|
6859
|
+
const sanitizedItem = sanitizeActorMetadataValue(item);
|
|
6860
|
+
if (sanitizedItem !== void 0) {
|
|
6861
|
+
items.push(sanitizedItem);
|
|
6862
|
+
}
|
|
6863
|
+
}
|
|
6864
|
+
return items;
|
|
6865
|
+
}
|
|
6866
|
+
if (typeof value === "object") {
|
|
6867
|
+
const output = {};
|
|
6868
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
6869
|
+
const sanitizedNestedValue = sanitizeActorMetadataValue(nestedValue);
|
|
6870
|
+
if (sanitizedNestedValue !== void 0) {
|
|
6871
|
+
output[key] = sanitizedNestedValue;
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
return output;
|
|
6875
|
+
}
|
|
6876
|
+
return value;
|
|
6877
|
+
}
|
|
6878
|
+
function buildActorRegistrationData(actor) {
|
|
6879
|
+
const definition = sanitizeActorMetadataValue(
|
|
6880
|
+
typeof actor?.toDefinition === "function" ? actor.toDefinition() : {}
|
|
6881
|
+
);
|
|
6882
|
+
const stateDefinition = definition?.state && typeof definition.state === "object" ? definition.state : {};
|
|
6883
|
+
const actorKind = typeof definition?.kind === "string" ? definition.kind : actor?.kind;
|
|
6884
|
+
return {
|
|
6885
|
+
name: definition?.name ?? actor?.spec?.name ?? "",
|
|
6886
|
+
description: definition?.description ?? actor?.spec?.description ?? "",
|
|
6887
|
+
default_key: definition?.defaultKey ?? actor?.spec?.defaultKey ?? "default",
|
|
6888
|
+
load_policy: definition?.loadPolicy ?? actor?.spec?.loadPolicy ?? "eager",
|
|
6889
|
+
write_contract: definition?.writeContract ?? actor?.spec?.writeContract ?? "overwrite",
|
|
6890
|
+
runtime_read_guard: definition?.runtimeReadGuard ?? actor?.spec?.runtimeReadGuard ?? "none",
|
|
6891
|
+
consistency_profile: definition?.consistencyProfile ?? actor?.spec?.consistencyProfile ?? null,
|
|
6892
|
+
key_definition: definition?.key ?? null,
|
|
6893
|
+
state_definition: stateDefinition,
|
|
6894
|
+
retry_policy: definition?.retry ?? {},
|
|
6895
|
+
idempotency_policy: definition?.idempotency ?? {},
|
|
6896
|
+
session_policy: definition?.session ?? {},
|
|
6897
|
+
is_meta: actorKind === "meta",
|
|
6898
|
+
version: 1
|
|
6899
|
+
};
|
|
6900
|
+
}
|
|
6714
6901
|
var GraphSyncController = class _GraphSyncController {
|
|
6715
6902
|
constructor() {
|
|
6903
|
+
this.registeredActors = /* @__PURE__ */ new Set();
|
|
6904
|
+
this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
|
|
6716
6905
|
this.isCadenzaDBReady = false;
|
|
6717
6906
|
}
|
|
6718
6907
|
static get instance() {
|
|
@@ -6970,6 +7159,120 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
6970
7159
|
)
|
|
6971
7160
|
)
|
|
6972
7161
|
);
|
|
7162
|
+
this.splitActorsForRegistration = CadenzaService.createMetaTask(
|
|
7163
|
+
"Split actors for registration",
|
|
7164
|
+
function* (ctx) {
|
|
7165
|
+
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7166
|
+
delayMs: 3e3
|
|
7167
|
+
});
|
|
7168
|
+
const actors = ctx.actors ?? [];
|
|
7169
|
+
for (const actor of actors) {
|
|
7170
|
+
const data = {
|
|
7171
|
+
...buildActorRegistrationData(actor),
|
|
7172
|
+
service_name: CadenzaService.serviceRegistry.serviceName
|
|
7173
|
+
};
|
|
7174
|
+
if (!data.name) {
|
|
7175
|
+
continue;
|
|
7176
|
+
}
|
|
7177
|
+
const registrationKey = `${data.name}|${data.version}|${data.service_name}`;
|
|
7178
|
+
if (this.registeredActors.has(registrationKey)) {
|
|
7179
|
+
continue;
|
|
7180
|
+
}
|
|
7181
|
+
yield {
|
|
7182
|
+
data,
|
|
7183
|
+
__actorRegistrationKey: registrationKey
|
|
7184
|
+
};
|
|
7185
|
+
}
|
|
7186
|
+
}.bind(this)
|
|
7187
|
+
).then(
|
|
7188
|
+
(this.isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(
|
|
7189
|
+
"actor",
|
|
7190
|
+
{
|
|
7191
|
+
onConflict: {
|
|
7192
|
+
target: ["name", "service_name", "version"],
|
|
7193
|
+
action: {
|
|
7194
|
+
do: "nothing"
|
|
7195
|
+
}
|
|
7196
|
+
}
|
|
7197
|
+
},
|
|
7198
|
+
{ concurrency: 30 }
|
|
7199
|
+
) : CadenzaService.get("dbInsertActor"))?.then(
|
|
7200
|
+
CadenzaService.createMetaTask("Record actor registration", (ctx) => {
|
|
7201
|
+
if (!ctx.__syncing) {
|
|
7202
|
+
return;
|
|
7203
|
+
}
|
|
7204
|
+
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7205
|
+
delayMs: 3e3
|
|
7206
|
+
});
|
|
7207
|
+
this.registeredActors.add(ctx.__actorRegistrationKey);
|
|
7208
|
+
return true;
|
|
7209
|
+
}).then(
|
|
7210
|
+
CadenzaService.createUniqueMetaTask(
|
|
7211
|
+
"Gather actor registration",
|
|
7212
|
+
() => true
|
|
7213
|
+
).emits("meta.sync_controller.synced_actors")
|
|
7214
|
+
)
|
|
7215
|
+
)
|
|
7216
|
+
);
|
|
7217
|
+
this.registerActorTaskMapTask = CadenzaService.createMetaTask(
|
|
7218
|
+
"Split actor task maps",
|
|
7219
|
+
function* (ctx) {
|
|
7220
|
+
const task = ctx.task;
|
|
7221
|
+
if (task.hidden || !task.register) {
|
|
7222
|
+
return;
|
|
7223
|
+
}
|
|
7224
|
+
const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
|
|
7225
|
+
if (!metadata?.actorName) {
|
|
7226
|
+
return;
|
|
7227
|
+
}
|
|
7228
|
+
const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${CadenzaService.serviceRegistry.serviceName}`;
|
|
7229
|
+
if (this.registeredActorTaskMaps.has(registrationKey)) {
|
|
7230
|
+
return;
|
|
7231
|
+
}
|
|
7232
|
+
yield {
|
|
7233
|
+
data: {
|
|
7234
|
+
actor_name: metadata.actorName,
|
|
7235
|
+
actor_version: 1,
|
|
7236
|
+
task_name: task.name,
|
|
7237
|
+
task_version: task.version,
|
|
7238
|
+
service_name: CadenzaService.serviceRegistry.serviceName,
|
|
7239
|
+
mode: metadata.mode,
|
|
7240
|
+
description: task.description ?? metadata.actorDescription ?? "",
|
|
7241
|
+
is_meta: metadata.actorKind === "meta" || task.isMeta === true
|
|
7242
|
+
},
|
|
7243
|
+
__actorTaskMapRegistrationKey: registrationKey
|
|
7244
|
+
};
|
|
7245
|
+
}.bind(this)
|
|
7246
|
+
).then(
|
|
7247
|
+
(this.isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(
|
|
7248
|
+
"actor_task_map",
|
|
7249
|
+
{
|
|
7250
|
+
onConflict: {
|
|
7251
|
+
target: [
|
|
7252
|
+
"actor_name",
|
|
7253
|
+
"actor_version",
|
|
7254
|
+
"task_name",
|
|
7255
|
+
"task_version",
|
|
7256
|
+
"service_name"
|
|
7257
|
+
],
|
|
7258
|
+
action: {
|
|
7259
|
+
do: "nothing"
|
|
7260
|
+
}
|
|
7261
|
+
}
|
|
7262
|
+
},
|
|
7263
|
+
{ concurrency: 30 }
|
|
7264
|
+
) : CadenzaService.get("dbInsertActorTaskMap"))?.then(
|
|
7265
|
+
CadenzaService.createMetaTask("Record actor task map registration", (ctx) => {
|
|
7266
|
+
if (!ctx.__syncing) {
|
|
7267
|
+
return;
|
|
7268
|
+
}
|
|
7269
|
+
CadenzaService.debounce("meta.sync_controller.synced_resource", {
|
|
7270
|
+
delayMs: 3e3
|
|
7271
|
+
});
|
|
7272
|
+
this.registeredActorTaskMaps.add(ctx.__actorTaskMapRegistrationKey);
|
|
7273
|
+
})
|
|
7274
|
+
)
|
|
7275
|
+
);
|
|
6973
7276
|
const registerSignalTask = CadenzaService.createMetaTask(
|
|
6974
7277
|
"Record signal registration",
|
|
6975
7278
|
(ctx) => {
|
|
@@ -7211,12 +7514,19 @@ var GraphSyncController = class _GraphSyncController {
|
|
|
7211
7514
|
).then(this.splitSignalsTask);
|
|
7212
7515
|
CadenzaService.registry.getAllTasks.clone().doOn("meta.sync_controller.synced_signals").then(this.splitTasksForRegistration);
|
|
7213
7516
|
CadenzaService.registry.getAllRoutines.clone().doOn("meta.sync_controller.synced_tasks").then(this.splitRoutinesTask);
|
|
7517
|
+
CadenzaService.createMetaTask("Get all actors", (ctx) => {
|
|
7518
|
+
return {
|
|
7519
|
+
...ctx,
|
|
7520
|
+
actors: CadenzaService.getAllActors()
|
|
7521
|
+
};
|
|
7522
|
+
}).doOn("meta.sync_controller.synced_tasks").then(this.splitActorsForRegistration);
|
|
7214
7523
|
CadenzaService.registry.doForEachTask.clone().doOn("meta.sync_controller.synced_tasks").then(
|
|
7215
7524
|
this.registerTaskMapTask,
|
|
7216
7525
|
this.registerSignalToTaskMapTask,
|
|
7217
7526
|
this.registerIntentToTaskMapTask,
|
|
7218
7527
|
this.registerDeputyRelationshipTask
|
|
7219
7528
|
);
|
|
7529
|
+
CadenzaService.registry.doForEachTask.clone().doOn("meta.sync_controller.synced_tasks", "meta.sync_controller.synced_actors").then(this.registerActorTaskMapTask);
|
|
7220
7530
|
CadenzaService.registry.getAllRoutines.clone().doOn("meta.sync_controller.synced_routines").then(this.splitTasksInRoutines);
|
|
7221
7531
|
CadenzaService.createMetaTask("Finish sync", (ctx, emit) => {
|
|
7222
7532
|
emit("global.meta.sync_controller.synced", {
|
|
@@ -7261,12 +7571,12 @@ var CadenzaService = class {
|
|
|
7261
7571
|
static bootstrap() {
|
|
7262
7572
|
if (this.isBootstrapped) return;
|
|
7263
7573
|
this.isBootstrapped = true;
|
|
7264
|
-
|
|
7265
|
-
this.signalBroker =
|
|
7266
|
-
this.inquiryBroker =
|
|
7267
|
-
this.runner =
|
|
7268
|
-
this.metaRunner =
|
|
7269
|
-
this.registry =
|
|
7574
|
+
import_core4.default.bootstrap();
|
|
7575
|
+
this.signalBroker = import_core4.default.signalBroker;
|
|
7576
|
+
this.inquiryBroker = import_core4.default.inquiryBroker;
|
|
7577
|
+
this.runner = import_core4.default.runner;
|
|
7578
|
+
this.metaRunner = import_core4.default.metaRunner;
|
|
7579
|
+
this.registry = import_core4.default.registry;
|
|
7270
7580
|
this.serviceRegistry = ServiceRegistry.instance;
|
|
7271
7581
|
SignalController.instance;
|
|
7272
7582
|
RestController.instance;
|
|
@@ -7309,7 +7619,7 @@ var CadenzaService = class {
|
|
|
7309
7619
|
* @return {void} Does not return any value.
|
|
7310
7620
|
*/
|
|
7311
7621
|
static validateName(name) {
|
|
7312
|
-
|
|
7622
|
+
import_core4.default.validateName(name);
|
|
7313
7623
|
}
|
|
7314
7624
|
/**
|
|
7315
7625
|
* Gets the current run strategy from the Cadenza configuration.
|
|
@@ -7317,7 +7627,7 @@ var CadenzaService = class {
|
|
|
7317
7627
|
* @return {Function} The run strategy function defined in the Cadenza configuration.
|
|
7318
7628
|
*/
|
|
7319
7629
|
static get runStrategy() {
|
|
7320
|
-
return
|
|
7630
|
+
return import_core4.default.runStrategy;
|
|
7321
7631
|
}
|
|
7322
7632
|
/**
|
|
7323
7633
|
* Sets the mode for the Cadenza application.
|
|
@@ -7326,7 +7636,7 @@ var CadenzaService = class {
|
|
|
7326
7636
|
* @return {void} This method does not return a value.
|
|
7327
7637
|
*/
|
|
7328
7638
|
static setMode(mode) {
|
|
7329
|
-
|
|
7639
|
+
import_core4.default.setMode(mode);
|
|
7330
7640
|
}
|
|
7331
7641
|
/**
|
|
7332
7642
|
* Emits a signal with the specified data using the associated broker.
|
|
@@ -7344,16 +7654,16 @@ var CadenzaService = class {
|
|
|
7344
7654
|
* ```
|
|
7345
7655
|
*/
|
|
7346
7656
|
static emit(signal, data = {}, options = {}) {
|
|
7347
|
-
|
|
7657
|
+
import_core4.default.emit(signal, data, options);
|
|
7348
7658
|
}
|
|
7349
7659
|
static debounce(signal, context = {}, delayMs = 500) {
|
|
7350
|
-
|
|
7660
|
+
import_core4.default.debounce(signal, context, delayMs);
|
|
7351
7661
|
}
|
|
7352
7662
|
static schedule(signal, context, timeoutMs, exactDateTime) {
|
|
7353
|
-
|
|
7663
|
+
import_core4.default.schedule(signal, context, timeoutMs, exactDateTime);
|
|
7354
7664
|
}
|
|
7355
7665
|
static interval(signal, context, intervalMs, leading = false, startDateTime) {
|
|
7356
|
-
|
|
7666
|
+
import_core4.default.interval(signal, context, intervalMs, leading, startDateTime);
|
|
7357
7667
|
}
|
|
7358
7668
|
static defineIntent(intent) {
|
|
7359
7669
|
this.inquiryBroker?.addIntent(intent);
|
|
@@ -7601,10 +7911,18 @@ var CadenzaService = class {
|
|
|
7601
7911
|
});
|
|
7602
7912
|
}
|
|
7603
7913
|
static get(taskName) {
|
|
7604
|
-
return
|
|
7914
|
+
return import_core4.default.get(taskName);
|
|
7915
|
+
}
|
|
7916
|
+
static getActor(actorName) {
|
|
7917
|
+
const cadenzaWithActors = import_core4.default;
|
|
7918
|
+
return cadenzaWithActors.getActor?.(actorName);
|
|
7919
|
+
}
|
|
7920
|
+
static getAllActors() {
|
|
7921
|
+
const cadenzaWithActors = import_core4.default;
|
|
7922
|
+
return cadenzaWithActors.getAllActors?.() ?? [];
|
|
7605
7923
|
}
|
|
7606
7924
|
static getRoutine(routineName) {
|
|
7607
|
-
return
|
|
7925
|
+
return import_core4.default.getRoutine(routineName);
|
|
7608
7926
|
}
|
|
7609
7927
|
/**
|
|
7610
7928
|
* Creates a new DeputyTask instance based on the provided routine name, service name, and options.
|
|
@@ -8170,11 +8488,11 @@ var CadenzaService = class {
|
|
|
8170
8488
|
}
|
|
8171
8489
|
static createActor(spec, options = {}) {
|
|
8172
8490
|
this.bootstrap();
|
|
8173
|
-
return
|
|
8491
|
+
return import_core4.default.createActor(spec, options);
|
|
8174
8492
|
}
|
|
8175
8493
|
static createActorFromDefinition(definition, options = {}) {
|
|
8176
8494
|
this.bootstrap();
|
|
8177
|
-
return
|
|
8495
|
+
return import_core4.default.createActorFromDefinition(definition, options);
|
|
8178
8496
|
}
|
|
8179
8497
|
/**
|
|
8180
8498
|
* Creates and registers a new task with the provided name, function, and optional details.
|
|
@@ -8248,7 +8566,7 @@ var CadenzaService = class {
|
|
|
8248
8566
|
*/
|
|
8249
8567
|
static createTask(name, func, description, options = {}) {
|
|
8250
8568
|
this.bootstrap();
|
|
8251
|
-
return
|
|
8569
|
+
return import_core4.default.createTask(name, func, description, options);
|
|
8252
8570
|
}
|
|
8253
8571
|
/**
|
|
8254
8572
|
* Creates a meta task with the specified name, functionality, description, and options.
|
|
@@ -8264,7 +8582,7 @@ var CadenzaService = class {
|
|
|
8264
8582
|
*/
|
|
8265
8583
|
static createMetaTask(name, func, description, options = {}) {
|
|
8266
8584
|
this.bootstrap();
|
|
8267
|
-
return
|
|
8585
|
+
return import_core4.default.createMetaTask(name, func, description, options);
|
|
8268
8586
|
}
|
|
8269
8587
|
/**
|
|
8270
8588
|
* Creates a unique task by wrapping the provided task function with a uniqueness constraint.
|
|
@@ -8314,7 +8632,7 @@ var CadenzaService = class {
|
|
|
8314
8632
|
*/
|
|
8315
8633
|
static createUniqueTask(name, func, description, options = {}) {
|
|
8316
8634
|
this.bootstrap();
|
|
8317
|
-
return
|
|
8635
|
+
return import_core4.default.createUniqueTask(name, func, description, options);
|
|
8318
8636
|
}
|
|
8319
8637
|
/**
|
|
8320
8638
|
* Creates a unique meta task with the specified name, function, description, and options.
|
|
@@ -8328,7 +8646,7 @@ var CadenzaService = class {
|
|
|
8328
8646
|
*/
|
|
8329
8647
|
static createUniqueMetaTask(name, func, description, options = {}) {
|
|
8330
8648
|
this.bootstrap();
|
|
8331
|
-
return
|
|
8649
|
+
return import_core4.default.createUniqueMetaTask(name, func, description, options);
|
|
8332
8650
|
}
|
|
8333
8651
|
/**
|
|
8334
8652
|
* Creates a throttled task with a concurrency limit of 1, ensuring that only one instance of the task can run at a time for a specific throttle tag.
|
|
@@ -8361,7 +8679,7 @@ var CadenzaService = class {
|
|
|
8361
8679
|
*/
|
|
8362
8680
|
static createThrottledTask(name, func, throttledIdGetter = () => "default", description, options = {}) {
|
|
8363
8681
|
this.bootstrap();
|
|
8364
|
-
return
|
|
8682
|
+
return import_core4.default.createThrottledTask(
|
|
8365
8683
|
name,
|
|
8366
8684
|
func,
|
|
8367
8685
|
throttledIdGetter,
|
|
@@ -8382,7 +8700,7 @@ var CadenzaService = class {
|
|
|
8382
8700
|
*/
|
|
8383
8701
|
static createThrottledMetaTask(name, func, throttledIdGetter = () => "default", description, options = {}) {
|
|
8384
8702
|
this.bootstrap();
|
|
8385
|
-
return
|
|
8703
|
+
return import_core4.default.createThrottledMetaTask(
|
|
8386
8704
|
name,
|
|
8387
8705
|
func,
|
|
8388
8706
|
throttledIdGetter,
|
|
@@ -8425,7 +8743,7 @@ var CadenzaService = class {
|
|
|
8425
8743
|
*/
|
|
8426
8744
|
static createDebounceTask(name, func, description, debounceTime = 1e3, options = {}) {
|
|
8427
8745
|
this.bootstrap();
|
|
8428
|
-
return
|
|
8746
|
+
return import_core4.default.createDebounceTask(
|
|
8429
8747
|
name,
|
|
8430
8748
|
func,
|
|
8431
8749
|
description,
|
|
@@ -8446,7 +8764,7 @@ var CadenzaService = class {
|
|
|
8446
8764
|
*/
|
|
8447
8765
|
static createDebounceMetaTask(name, func, description, debounceTime = 1e3, options = {}) {
|
|
8448
8766
|
this.bootstrap();
|
|
8449
|
-
return
|
|
8767
|
+
return import_core4.default.createDebounceMetaTask(
|
|
8450
8768
|
name,
|
|
8451
8769
|
func,
|
|
8452
8770
|
description,
|
|
@@ -8516,7 +8834,7 @@ var CadenzaService = class {
|
|
|
8516
8834
|
*/
|
|
8517
8835
|
static createEphemeralTask(name, func, description, options = {}) {
|
|
8518
8836
|
this.bootstrap();
|
|
8519
|
-
return
|
|
8837
|
+
return import_core4.default.createEphemeralTask(name, func, description, options);
|
|
8520
8838
|
}
|
|
8521
8839
|
/**
|
|
8522
8840
|
* Creates an ephemeral meta task with the specified name, function, description, and options.
|
|
@@ -8530,7 +8848,7 @@ var CadenzaService = class {
|
|
|
8530
8848
|
*/
|
|
8531
8849
|
static createEphemeralMetaTask(name, func, description, options = {}) {
|
|
8532
8850
|
this.bootstrap();
|
|
8533
|
-
return
|
|
8851
|
+
return import_core4.default.createEphemeralMetaTask(name, func, description, options);
|
|
8534
8852
|
}
|
|
8535
8853
|
/**
|
|
8536
8854
|
* Creates a new routine with the specified name, tasks, and an optional description.
|
|
@@ -8562,7 +8880,7 @@ var CadenzaService = class {
|
|
|
8562
8880
|
*/
|
|
8563
8881
|
static createRoutine(name, tasks, description = "") {
|
|
8564
8882
|
this.bootstrap();
|
|
8565
|
-
return
|
|
8883
|
+
return import_core4.default.createRoutine(name, tasks, description);
|
|
8566
8884
|
}
|
|
8567
8885
|
/**
|
|
8568
8886
|
* Creates a meta routine with a given name, tasks, and optional description.
|
|
@@ -8577,10 +8895,10 @@ var CadenzaService = class {
|
|
|
8577
8895
|
*/
|
|
8578
8896
|
static createMetaRoutine(name, tasks, description = "") {
|
|
8579
8897
|
this.bootstrap();
|
|
8580
|
-
return
|
|
8898
|
+
return import_core4.default.createMetaRoutine(name, tasks, description);
|
|
8581
8899
|
}
|
|
8582
8900
|
static reset() {
|
|
8583
|
-
|
|
8901
|
+
import_core4.default.reset();
|
|
8584
8902
|
this.serviceRegistry.reset();
|
|
8585
8903
|
}
|
|
8586
8904
|
};
|
|
@@ -8589,7 +8907,7 @@ CadenzaService.serviceCreated = false;
|
|
|
8589
8907
|
CadenzaService.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
|
|
8590
8908
|
|
|
8591
8909
|
// src/index.ts
|
|
8592
|
-
var
|
|
8910
|
+
var import_core5 = require("@cadenza.io/core");
|
|
8593
8911
|
var index_default = CadenzaService;
|
|
8594
8912
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8595
8913
|
0 && (module.exports = {
|