@cadenza.io/service 2.10.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.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: () => import_core4.Actor,
33
+ Actor: () => import_core5.Actor,
34
34
  DatabaseTask: () => DatabaseTask,
35
- DebounceTask: () => import_core4.DebounceTask,
35
+ DebounceTask: () => import_core5.DebounceTask,
36
36
  DeputyTask: () => DeputyTask,
37
- EphemeralTask: () => import_core4.EphemeralTask,
37
+ EphemeralTask: () => import_core5.EphemeralTask,
38
38
  GraphMetadataController: () => GraphMetadataController,
39
- GraphRoutine: () => import_core4.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: () => import_core4.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 import_core3 = __toESM(require("@cadenza.io/core"));
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");
@@ -4817,6 +4817,7 @@ var SignalController = class _SignalController {
4817
4817
  };
4818
4818
 
4819
4819
  // src/graph/controllers/GraphMetadataController.ts
4820
+ var import_core3 = require("@cadenza.io/core");
4820
4821
  var GraphMetadataController = class _GraphMetadataController {
4821
4822
  static get instance() {
4822
4823
  if (!this._instance) this._instance = new _GraphMetadataController();
@@ -5050,6 +5051,123 @@ var GraphMetadataController = class _GraphMetadataController {
5050
5051
  }
5051
5052
  };
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);
5053
5171
  CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
5054
5172
  const intentName = ctx.data?.name;
5055
5173
  return {
@@ -7453,12 +7571,12 @@ var CadenzaService = class {
7453
7571
  static bootstrap() {
7454
7572
  if (this.isBootstrapped) return;
7455
7573
  this.isBootstrapped = true;
7456
- import_core3.default.bootstrap();
7457
- this.signalBroker = import_core3.default.signalBroker;
7458
- this.inquiryBroker = import_core3.default.inquiryBroker;
7459
- this.runner = import_core3.default.runner;
7460
- this.metaRunner = import_core3.default.metaRunner;
7461
- this.registry = import_core3.default.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;
7462
7580
  this.serviceRegistry = ServiceRegistry.instance;
7463
7581
  SignalController.instance;
7464
7582
  RestController.instance;
@@ -7501,7 +7619,7 @@ var CadenzaService = class {
7501
7619
  * @return {void} Does not return any value.
7502
7620
  */
7503
7621
  static validateName(name) {
7504
- import_core3.default.validateName(name);
7622
+ import_core4.default.validateName(name);
7505
7623
  }
7506
7624
  /**
7507
7625
  * Gets the current run strategy from the Cadenza configuration.
@@ -7509,7 +7627,7 @@ var CadenzaService = class {
7509
7627
  * @return {Function} The run strategy function defined in the Cadenza configuration.
7510
7628
  */
7511
7629
  static get runStrategy() {
7512
- return import_core3.default.runStrategy;
7630
+ return import_core4.default.runStrategy;
7513
7631
  }
7514
7632
  /**
7515
7633
  * Sets the mode for the Cadenza application.
@@ -7518,7 +7636,7 @@ var CadenzaService = class {
7518
7636
  * @return {void} This method does not return a value.
7519
7637
  */
7520
7638
  static setMode(mode) {
7521
- import_core3.default.setMode(mode);
7639
+ import_core4.default.setMode(mode);
7522
7640
  }
7523
7641
  /**
7524
7642
  * Emits a signal with the specified data using the associated broker.
@@ -7536,16 +7654,16 @@ var CadenzaService = class {
7536
7654
  * ```
7537
7655
  */
7538
7656
  static emit(signal, data = {}, options = {}) {
7539
- import_core3.default.emit(signal, data, options);
7657
+ import_core4.default.emit(signal, data, options);
7540
7658
  }
7541
7659
  static debounce(signal, context = {}, delayMs = 500) {
7542
- import_core3.default.debounce(signal, context, delayMs);
7660
+ import_core4.default.debounce(signal, context, delayMs);
7543
7661
  }
7544
7662
  static schedule(signal, context, timeoutMs, exactDateTime) {
7545
- import_core3.default.schedule(signal, context, timeoutMs, exactDateTime);
7663
+ import_core4.default.schedule(signal, context, timeoutMs, exactDateTime);
7546
7664
  }
7547
7665
  static interval(signal, context, intervalMs, leading = false, startDateTime) {
7548
- import_core3.default.interval(signal, context, intervalMs, leading, startDateTime);
7666
+ import_core4.default.interval(signal, context, intervalMs, leading, startDateTime);
7549
7667
  }
7550
7668
  static defineIntent(intent) {
7551
7669
  this.inquiryBroker?.addIntent(intent);
@@ -7793,18 +7911,18 @@ var CadenzaService = class {
7793
7911
  });
7794
7912
  }
7795
7913
  static get(taskName) {
7796
- return import_core3.default.get(taskName);
7914
+ return import_core4.default.get(taskName);
7797
7915
  }
7798
7916
  static getActor(actorName) {
7799
- const cadenzaWithActors = import_core3.default;
7917
+ const cadenzaWithActors = import_core4.default;
7800
7918
  return cadenzaWithActors.getActor?.(actorName);
7801
7919
  }
7802
7920
  static getAllActors() {
7803
- const cadenzaWithActors = import_core3.default;
7921
+ const cadenzaWithActors = import_core4.default;
7804
7922
  return cadenzaWithActors.getAllActors?.() ?? [];
7805
7923
  }
7806
7924
  static getRoutine(routineName) {
7807
- return import_core3.default.getRoutine(routineName);
7925
+ return import_core4.default.getRoutine(routineName);
7808
7926
  }
7809
7927
  /**
7810
7928
  * Creates a new DeputyTask instance based on the provided routine name, service name, and options.
@@ -8370,11 +8488,11 @@ var CadenzaService = class {
8370
8488
  }
8371
8489
  static createActor(spec, options = {}) {
8372
8490
  this.bootstrap();
8373
- return import_core3.default.createActor(spec, options);
8491
+ return import_core4.default.createActor(spec, options);
8374
8492
  }
8375
8493
  static createActorFromDefinition(definition, options = {}) {
8376
8494
  this.bootstrap();
8377
- return import_core3.default.createActorFromDefinition(definition, options);
8495
+ return import_core4.default.createActorFromDefinition(definition, options);
8378
8496
  }
8379
8497
  /**
8380
8498
  * Creates and registers a new task with the provided name, function, and optional details.
@@ -8448,7 +8566,7 @@ var CadenzaService = class {
8448
8566
  */
8449
8567
  static createTask(name, func, description, options = {}) {
8450
8568
  this.bootstrap();
8451
- return import_core3.default.createTask(name, func, description, options);
8569
+ return import_core4.default.createTask(name, func, description, options);
8452
8570
  }
8453
8571
  /**
8454
8572
  * Creates a meta task with the specified name, functionality, description, and options.
@@ -8464,7 +8582,7 @@ var CadenzaService = class {
8464
8582
  */
8465
8583
  static createMetaTask(name, func, description, options = {}) {
8466
8584
  this.bootstrap();
8467
- return import_core3.default.createMetaTask(name, func, description, options);
8585
+ return import_core4.default.createMetaTask(name, func, description, options);
8468
8586
  }
8469
8587
  /**
8470
8588
  * Creates a unique task by wrapping the provided task function with a uniqueness constraint.
@@ -8514,7 +8632,7 @@ var CadenzaService = class {
8514
8632
  */
8515
8633
  static createUniqueTask(name, func, description, options = {}) {
8516
8634
  this.bootstrap();
8517
- return import_core3.default.createUniqueTask(name, func, description, options);
8635
+ return import_core4.default.createUniqueTask(name, func, description, options);
8518
8636
  }
8519
8637
  /**
8520
8638
  * Creates a unique meta task with the specified name, function, description, and options.
@@ -8528,7 +8646,7 @@ var CadenzaService = class {
8528
8646
  */
8529
8647
  static createUniqueMetaTask(name, func, description, options = {}) {
8530
8648
  this.bootstrap();
8531
- return import_core3.default.createUniqueMetaTask(name, func, description, options);
8649
+ return import_core4.default.createUniqueMetaTask(name, func, description, options);
8532
8650
  }
8533
8651
  /**
8534
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.
@@ -8561,7 +8679,7 @@ var CadenzaService = class {
8561
8679
  */
8562
8680
  static createThrottledTask(name, func, throttledIdGetter = () => "default", description, options = {}) {
8563
8681
  this.bootstrap();
8564
- return import_core3.default.createThrottledTask(
8682
+ return import_core4.default.createThrottledTask(
8565
8683
  name,
8566
8684
  func,
8567
8685
  throttledIdGetter,
@@ -8582,7 +8700,7 @@ var CadenzaService = class {
8582
8700
  */
8583
8701
  static createThrottledMetaTask(name, func, throttledIdGetter = () => "default", description, options = {}) {
8584
8702
  this.bootstrap();
8585
- return import_core3.default.createThrottledMetaTask(
8703
+ return import_core4.default.createThrottledMetaTask(
8586
8704
  name,
8587
8705
  func,
8588
8706
  throttledIdGetter,
@@ -8625,7 +8743,7 @@ var CadenzaService = class {
8625
8743
  */
8626
8744
  static createDebounceTask(name, func, description, debounceTime = 1e3, options = {}) {
8627
8745
  this.bootstrap();
8628
- return import_core3.default.createDebounceTask(
8746
+ return import_core4.default.createDebounceTask(
8629
8747
  name,
8630
8748
  func,
8631
8749
  description,
@@ -8646,7 +8764,7 @@ var CadenzaService = class {
8646
8764
  */
8647
8765
  static createDebounceMetaTask(name, func, description, debounceTime = 1e3, options = {}) {
8648
8766
  this.bootstrap();
8649
- return import_core3.default.createDebounceMetaTask(
8767
+ return import_core4.default.createDebounceMetaTask(
8650
8768
  name,
8651
8769
  func,
8652
8770
  description,
@@ -8716,7 +8834,7 @@ var CadenzaService = class {
8716
8834
  */
8717
8835
  static createEphemeralTask(name, func, description, options = {}) {
8718
8836
  this.bootstrap();
8719
- return import_core3.default.createEphemeralTask(name, func, description, options);
8837
+ return import_core4.default.createEphemeralTask(name, func, description, options);
8720
8838
  }
8721
8839
  /**
8722
8840
  * Creates an ephemeral meta task with the specified name, function, description, and options.
@@ -8730,7 +8848,7 @@ var CadenzaService = class {
8730
8848
  */
8731
8849
  static createEphemeralMetaTask(name, func, description, options = {}) {
8732
8850
  this.bootstrap();
8733
- return import_core3.default.createEphemeralMetaTask(name, func, description, options);
8851
+ return import_core4.default.createEphemeralMetaTask(name, func, description, options);
8734
8852
  }
8735
8853
  /**
8736
8854
  * Creates a new routine with the specified name, tasks, and an optional description.
@@ -8762,7 +8880,7 @@ var CadenzaService = class {
8762
8880
  */
8763
8881
  static createRoutine(name, tasks, description = "") {
8764
8882
  this.bootstrap();
8765
- return import_core3.default.createRoutine(name, tasks, description);
8883
+ return import_core4.default.createRoutine(name, tasks, description);
8766
8884
  }
8767
8885
  /**
8768
8886
  * Creates a meta routine with a given name, tasks, and optional description.
@@ -8777,10 +8895,10 @@ var CadenzaService = class {
8777
8895
  */
8778
8896
  static createMetaRoutine(name, tasks, description = "") {
8779
8897
  this.bootstrap();
8780
- return import_core3.default.createMetaRoutine(name, tasks, description);
8898
+ return import_core4.default.createMetaRoutine(name, tasks, description);
8781
8899
  }
8782
8900
  static reset() {
8783
- import_core3.default.reset();
8901
+ import_core4.default.reset();
8784
8902
  this.serviceRegistry.reset();
8785
8903
  }
8786
8904
  };
@@ -8789,7 +8907,7 @@ CadenzaService.serviceCreated = false;
8789
8907
  CadenzaService.warnedInvalidMetaIntentResponderKeys = /* @__PURE__ */ new Set();
8790
8908
 
8791
8909
  // src/index.ts
8792
- var import_core4 = require("@cadenza.io/core");
8910
+ var import_core5 = require("@cadenza.io/core");
8793
8911
  var index_default = CadenzaService;
8794
8912
  // Annotate the CommonJS export names for ESM import in node:
8795
8913
  0 && (module.exports = {