@cadenza.io/service 2.9.0 → 2.10.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _cadenza_io_core from '@cadenza.io/core';
2
- import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, ActorSpec, ActorFactoryOptions, Actor, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
2
+ import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, Actor, TaskOptions, ActorSpec, ActorFactoryOptions, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
3
  export { Actor, ActorConsistencyProfileName, ActorDefinition, ActorFactoryOptions, ActorInvocationOptions, ActorKeyDefinition, ActorKind, ActorLoadPolicy, ActorRuntimeReadGuard, ActorSpec, ActorStateDefinition, ActorStateReducer, ActorStateStore, ActorTaskBindingDefinition, ActorTaskBindingOptions, ActorTaskContext, ActorTaskHandler, ActorTaskMode, ActorWriteContract, AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, IdempotencyPolicy, RetryPolicy, SessionPolicy, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
4
4
 
5
5
  /**
@@ -22223,6 +22223,8 @@ declare class CadenzaService {
22223
22223
  */
22224
22224
  static log(message: string, data?: any, level?: "info" | "warning" | "error" | "critical", subjectServiceName?: string | null, subjectServiceInstanceId?: string | null): void;
22225
22225
  static get(taskName: string): Task | undefined;
22226
+ static getActor<D extends Record<string, any> = AnyObject, R = AnyObject>(actorName: string): Actor<D, R> | undefined;
22227
+ static getAllActors<D extends Record<string, any> = AnyObject, R = AnyObject>(): Actor<D, R>[];
22226
22228
  static getRoutine(routineName: string): GraphRoutine | undefined;
22227
22229
  /**
22228
22230
  * Creates a new DeputyTask instance based on the provided routine name, service name, and options.
@@ -22858,6 +22860,8 @@ declare class SocketController {
22858
22860
  private readonly diagnosticsMaxClientEntries;
22859
22861
  private readonly destroyedDiagnosticsTtlMs;
22860
22862
  private readonly socketServerDefaultKey;
22863
+ private readonly socketServerInitialSessionState;
22864
+ private readonly socketClientInitialSessionState;
22861
22865
  private readonly socketServerActor;
22862
22866
  private readonly socketClientActor;
22863
22867
  private readonly socketClientDiagnosticsActor;
@@ -22865,8 +22869,6 @@ declare class SocketController {
22865
22869
  private registerDiagnosticsTasks;
22866
22870
  private registerSocketServerTasks;
22867
22871
  private registerSocketClientTasks;
22868
- private createInitialSocketServerSessionState;
22869
- private createInitialSocketClientSessionState;
22870
22872
  private resolveSocketServerKey;
22871
22873
  private resolveSocketClientFetchId;
22872
22874
  private resolveServicePort;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _cadenza_io_core from '@cadenza.io/core';
2
- import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, TaskOptions, ActorSpec, ActorFactoryOptions, Actor, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
2
+ import { Task, ThrottleTagGetter, Schema, GraphContext, AnyObject, InquiryOptions, TaskResult, GraphRoutine, SchemaDefinition, SignalBroker, InquiryBroker, GraphRunner, GraphRegistry, EmitOptions, CadenzaMode, Intent, Actor, TaskOptions, ActorSpec, ActorFactoryOptions, ActorDefinition, TaskFunction, DebounceOptions, DebounceTask, EphemeralTaskOptions, EphemeralTask } from '@cadenza.io/core';
3
3
  export { Actor, ActorConsistencyProfileName, ActorDefinition, ActorFactoryOptions, ActorInvocationOptions, ActorKeyDefinition, ActorKind, ActorLoadPolicy, ActorRuntimeReadGuard, ActorSpec, ActorStateDefinition, ActorStateReducer, ActorStateStore, ActorTaskBindingDefinition, ActorTaskBindingOptions, ActorTaskContext, ActorTaskHandler, ActorTaskMode, ActorWriteContract, AnyObject, DebounceOptions, DebounceTask, EphemeralTask, EphemeralTaskOptions, GraphRoutine, IdempotencyPolicy, RetryPolicy, SessionPolicy, Task, TaskFunction, TaskOptions, ThrottleTagGetter } from '@cadenza.io/core';
4
4
 
5
5
  /**
@@ -22223,6 +22223,8 @@ declare class CadenzaService {
22223
22223
  */
22224
22224
  static log(message: string, data?: any, level?: "info" | "warning" | "error" | "critical", subjectServiceName?: string | null, subjectServiceInstanceId?: string | null): void;
22225
22225
  static get(taskName: string): Task | undefined;
22226
+ static getActor<D extends Record<string, any> = AnyObject, R = AnyObject>(actorName: string): Actor<D, R> | undefined;
22227
+ static getAllActors<D extends Record<string, any> = AnyObject, R = AnyObject>(): Actor<D, R>[];
22226
22228
  static getRoutine(routineName: string): GraphRoutine | undefined;
22227
22229
  /**
22228
22230
  * Creates a new DeputyTask instance based on the provided routine name, service name, and options.
@@ -22858,6 +22860,8 @@ declare class SocketController {
22858
22860
  private readonly diagnosticsMaxClientEntries;
22859
22861
  private readonly destroyedDiagnosticsTtlMs;
22860
22862
  private readonly socketServerDefaultKey;
22863
+ private readonly socketServerInitialSessionState;
22864
+ private readonly socketClientInitialSessionState;
22861
22865
  private readonly socketServerActor;
22862
22866
  private readonly socketClientActor;
22863
22867
  private readonly socketClientDiagnosticsActor;
@@ -22865,8 +22869,6 @@ declare class SocketController {
22865
22869
  private registerDiagnosticsTasks;
22866
22870
  private registerSocketServerTasks;
22867
22871
  private registerSocketClientTasks;
22868
- private createInitialSocketServerSessionState;
22869
- private createInitialSocketClientSessionState;
22870
22872
  private resolveSocketServerKey;
22871
22873
  private resolveSocketClientFetchId;
22872
22874
  private resolveServicePort;
package/dist/index.js CHANGED
@@ -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.createInitialSocketServerSessionState(
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.createInitialSocketClientSessionState()
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
  }
@@ -5040,6 +5034,22 @@ var GraphMetadataController = class _GraphMetadataController {
5040
5034
  "Handles task execution relationship creation",
5041
5035
  { concurrency: 100, isSubMeta: true }
5042
5036
  ).doOn("meta.node.mapped", "meta.node.detected_previous_task_execution").emits("global.meta.graph_metadata.relationship_executed");
5037
+ CadenzaService.createMetaTask("Handle actor creation", (ctx) => {
5038
+ return {
5039
+ data: {
5040
+ ...ctx.data,
5041
+ service_name: CadenzaService.serviceRegistry.serviceName
5042
+ }
5043
+ };
5044
+ }).doOn("meta.actor.created").emits("global.meta.graph_metadata.actor_created");
5045
+ CadenzaService.createMetaTask("Handle actor task association", (ctx) => {
5046
+ return {
5047
+ data: {
5048
+ ...ctx.data,
5049
+ service_name: CadenzaService.serviceRegistry.serviceName
5050
+ }
5051
+ };
5052
+ }).doOn("meta.actor.task_associated").emits("global.meta.graph_metadata.actor_task_associated");
5043
5053
  CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
5044
5054
  const intentName = ctx.data?.name;
5045
5055
  return {
@@ -6711,8 +6721,69 @@ function tableFieldTypeToSchemaType(type) {
6711
6721
  var import_uuid3 = require("uuid");
6712
6722
 
6713
6723
  // src/graph/controllers/GraphSyncController.ts
6724
+ var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
6725
+ function getActorTaskRuntimeMetadata(taskFunction) {
6726
+ if (typeof taskFunction !== "function") {
6727
+ return void 0;
6728
+ }
6729
+ return taskFunction[ACTOR_TASK_METADATA];
6730
+ }
6731
+ function sanitizeActorMetadataValue(value) {
6732
+ if (value === null) {
6733
+ return null;
6734
+ }
6735
+ if (value === void 0 || typeof value === "function") {
6736
+ return void 0;
6737
+ }
6738
+ if (Array.isArray(value)) {
6739
+ const items = [];
6740
+ for (const item of value) {
6741
+ const sanitizedItem = sanitizeActorMetadataValue(item);
6742
+ if (sanitizedItem !== void 0) {
6743
+ items.push(sanitizedItem);
6744
+ }
6745
+ }
6746
+ return items;
6747
+ }
6748
+ if (typeof value === "object") {
6749
+ const output = {};
6750
+ for (const [key, nestedValue] of Object.entries(value)) {
6751
+ const sanitizedNestedValue = sanitizeActorMetadataValue(nestedValue);
6752
+ if (sanitizedNestedValue !== void 0) {
6753
+ output[key] = sanitizedNestedValue;
6754
+ }
6755
+ }
6756
+ return output;
6757
+ }
6758
+ return value;
6759
+ }
6760
+ function buildActorRegistrationData(actor) {
6761
+ const definition = sanitizeActorMetadataValue(
6762
+ typeof actor?.toDefinition === "function" ? actor.toDefinition() : {}
6763
+ );
6764
+ const stateDefinition = definition?.state && typeof definition.state === "object" ? definition.state : {};
6765
+ const actorKind = typeof definition?.kind === "string" ? definition.kind : actor?.kind;
6766
+ return {
6767
+ name: definition?.name ?? actor?.spec?.name ?? "",
6768
+ description: definition?.description ?? actor?.spec?.description ?? "",
6769
+ default_key: definition?.defaultKey ?? actor?.spec?.defaultKey ?? "default",
6770
+ load_policy: definition?.loadPolicy ?? actor?.spec?.loadPolicy ?? "eager",
6771
+ write_contract: definition?.writeContract ?? actor?.spec?.writeContract ?? "overwrite",
6772
+ runtime_read_guard: definition?.runtimeReadGuard ?? actor?.spec?.runtimeReadGuard ?? "none",
6773
+ consistency_profile: definition?.consistencyProfile ?? actor?.spec?.consistencyProfile ?? null,
6774
+ key_definition: definition?.key ?? null,
6775
+ state_definition: stateDefinition,
6776
+ retry_policy: definition?.retry ?? {},
6777
+ idempotency_policy: definition?.idempotency ?? {},
6778
+ session_policy: definition?.session ?? {},
6779
+ is_meta: actorKind === "meta",
6780
+ version: 1
6781
+ };
6782
+ }
6714
6783
  var GraphSyncController = class _GraphSyncController {
6715
6784
  constructor() {
6785
+ this.registeredActors = /* @__PURE__ */ new Set();
6786
+ this.registeredActorTaskMaps = /* @__PURE__ */ new Set();
6716
6787
  this.isCadenzaDBReady = false;
6717
6788
  }
6718
6789
  static get instance() {
@@ -6970,6 +7041,120 @@ var GraphSyncController = class _GraphSyncController {
6970
7041
  )
6971
7042
  )
6972
7043
  );
7044
+ this.splitActorsForRegistration = CadenzaService.createMetaTask(
7045
+ "Split actors for registration",
7046
+ function* (ctx) {
7047
+ CadenzaService.debounce("meta.sync_controller.synced_resource", {
7048
+ delayMs: 3e3
7049
+ });
7050
+ const actors = ctx.actors ?? [];
7051
+ for (const actor of actors) {
7052
+ const data = {
7053
+ ...buildActorRegistrationData(actor),
7054
+ service_name: CadenzaService.serviceRegistry.serviceName
7055
+ };
7056
+ if (!data.name) {
7057
+ continue;
7058
+ }
7059
+ const registrationKey = `${data.name}|${data.version}|${data.service_name}`;
7060
+ if (this.registeredActors.has(registrationKey)) {
7061
+ continue;
7062
+ }
7063
+ yield {
7064
+ data,
7065
+ __actorRegistrationKey: registrationKey
7066
+ };
7067
+ }
7068
+ }.bind(this)
7069
+ ).then(
7070
+ (this.isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(
7071
+ "actor",
7072
+ {
7073
+ onConflict: {
7074
+ target: ["name", "service_name", "version"],
7075
+ action: {
7076
+ do: "nothing"
7077
+ }
7078
+ }
7079
+ },
7080
+ { concurrency: 30 }
7081
+ ) : CadenzaService.get("dbInsertActor"))?.then(
7082
+ CadenzaService.createMetaTask("Record actor registration", (ctx) => {
7083
+ if (!ctx.__syncing) {
7084
+ return;
7085
+ }
7086
+ CadenzaService.debounce("meta.sync_controller.synced_resource", {
7087
+ delayMs: 3e3
7088
+ });
7089
+ this.registeredActors.add(ctx.__actorRegistrationKey);
7090
+ return true;
7091
+ }).then(
7092
+ CadenzaService.createUniqueMetaTask(
7093
+ "Gather actor registration",
7094
+ () => true
7095
+ ).emits("meta.sync_controller.synced_actors")
7096
+ )
7097
+ )
7098
+ );
7099
+ this.registerActorTaskMapTask = CadenzaService.createMetaTask(
7100
+ "Split actor task maps",
7101
+ function* (ctx) {
7102
+ const task = ctx.task;
7103
+ if (task.hidden || !task.register) {
7104
+ return;
7105
+ }
7106
+ const metadata = getActorTaskRuntimeMetadata(task.taskFunction);
7107
+ if (!metadata?.actorName) {
7108
+ return;
7109
+ }
7110
+ const registrationKey = `${metadata.actorName}|${task.name}|${task.version}|${CadenzaService.serviceRegistry.serviceName}`;
7111
+ if (this.registeredActorTaskMaps.has(registrationKey)) {
7112
+ return;
7113
+ }
7114
+ yield {
7115
+ data: {
7116
+ actor_name: metadata.actorName,
7117
+ actor_version: 1,
7118
+ task_name: task.name,
7119
+ task_version: task.version,
7120
+ service_name: CadenzaService.serviceRegistry.serviceName,
7121
+ mode: metadata.mode,
7122
+ description: task.description ?? metadata.actorDescription ?? "",
7123
+ is_meta: metadata.actorKind === "meta" || task.isMeta === true
7124
+ },
7125
+ __actorTaskMapRegistrationKey: registrationKey
7126
+ };
7127
+ }.bind(this)
7128
+ ).then(
7129
+ (this.isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(
7130
+ "actor_task_map",
7131
+ {
7132
+ onConflict: {
7133
+ target: [
7134
+ "actor_name",
7135
+ "actor_version",
7136
+ "task_name",
7137
+ "task_version",
7138
+ "service_name"
7139
+ ],
7140
+ action: {
7141
+ do: "nothing"
7142
+ }
7143
+ }
7144
+ },
7145
+ { concurrency: 30 }
7146
+ ) : CadenzaService.get("dbInsertActorTaskMap"))?.then(
7147
+ CadenzaService.createMetaTask("Record actor task map registration", (ctx) => {
7148
+ if (!ctx.__syncing) {
7149
+ return;
7150
+ }
7151
+ CadenzaService.debounce("meta.sync_controller.synced_resource", {
7152
+ delayMs: 3e3
7153
+ });
7154
+ this.registeredActorTaskMaps.add(ctx.__actorTaskMapRegistrationKey);
7155
+ })
7156
+ )
7157
+ );
6973
7158
  const registerSignalTask = CadenzaService.createMetaTask(
6974
7159
  "Record signal registration",
6975
7160
  (ctx) => {
@@ -7211,12 +7396,19 @@ var GraphSyncController = class _GraphSyncController {
7211
7396
  ).then(this.splitSignalsTask);
7212
7397
  CadenzaService.registry.getAllTasks.clone().doOn("meta.sync_controller.synced_signals").then(this.splitTasksForRegistration);
7213
7398
  CadenzaService.registry.getAllRoutines.clone().doOn("meta.sync_controller.synced_tasks").then(this.splitRoutinesTask);
7399
+ CadenzaService.createMetaTask("Get all actors", (ctx) => {
7400
+ return {
7401
+ ...ctx,
7402
+ actors: CadenzaService.getAllActors()
7403
+ };
7404
+ }).doOn("meta.sync_controller.synced_tasks").then(this.splitActorsForRegistration);
7214
7405
  CadenzaService.registry.doForEachTask.clone().doOn("meta.sync_controller.synced_tasks").then(
7215
7406
  this.registerTaskMapTask,
7216
7407
  this.registerSignalToTaskMapTask,
7217
7408
  this.registerIntentToTaskMapTask,
7218
7409
  this.registerDeputyRelationshipTask
7219
7410
  );
7411
+ CadenzaService.registry.doForEachTask.clone().doOn("meta.sync_controller.synced_tasks", "meta.sync_controller.synced_actors").then(this.registerActorTaskMapTask);
7220
7412
  CadenzaService.registry.getAllRoutines.clone().doOn("meta.sync_controller.synced_routines").then(this.splitTasksInRoutines);
7221
7413
  CadenzaService.createMetaTask("Finish sync", (ctx, emit) => {
7222
7414
  emit("global.meta.sync_controller.synced", {
@@ -7603,6 +7795,14 @@ var CadenzaService = class {
7603
7795
  static get(taskName) {
7604
7796
  return import_core3.default.get(taskName);
7605
7797
  }
7798
+ static getActor(actorName) {
7799
+ const cadenzaWithActors = import_core3.default;
7800
+ return cadenzaWithActors.getActor?.(actorName);
7801
+ }
7802
+ static getAllActors() {
7803
+ const cadenzaWithActors = import_core3.default;
7804
+ return cadenzaWithActors.getAllActors?.() ?? [];
7805
+ }
7606
7806
  static getRoutine(routineName) {
7607
7807
  return import_core3.default.getRoutine(routineName);
7608
7808
  }
@@ -8170,7 +8370,7 @@ var CadenzaService = class {
8170
8370
  }
8171
8371
  static createActor(spec, options = {}) {
8172
8372
  this.bootstrap();
8173
- return new import_core3.Actor(spec, options);
8373
+ return import_core3.default.createActor(spec, options);
8174
8374
  }
8175
8375
  static createActorFromDefinition(definition, options = {}) {
8176
8376
  this.bootstrap();