@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.mjs CHANGED
@@ -4768,6 +4768,7 @@ var SignalController = class _SignalController {
4768
4768
  };
4769
4769
 
4770
4770
  // src/graph/controllers/GraphMetadataController.ts
4771
+ import { META_ACTOR_SESSION_STATE_PERSIST_INTENT } from "@cadenza.io/core";
4771
4772
  var GraphMetadataController = class _GraphMetadataController {
4772
4773
  static get instance() {
4773
4774
  if (!this._instance) this._instance = new _GraphMetadataController();
@@ -5001,6 +5002,123 @@ var GraphMetadataController = class _GraphMetadataController {
5001
5002
  }
5002
5003
  };
5003
5004
  }).doOn("meta.actor.task_associated").emits("global.meta.graph_metadata.actor_task_associated");
5005
+ const actorSessionStateInsertTask = CadenzaService.get("dbInsertActorSessionState") ?? CadenzaService.get("Insert actor_session_state in CadenzaDB") ?? CadenzaService.createCadenzaDBInsertTask(
5006
+ "actor_session_state",
5007
+ {},
5008
+ { concurrency: 100, isSubMeta: true }
5009
+ );
5010
+ const validateActorSessionStatePersistenceTask = CadenzaService.createMetaTask(
5011
+ "Validate actor session state persistence",
5012
+ (ctx) => {
5013
+ if (ctx.errored || ctx.failed || ctx.__success !== true) {
5014
+ throw new Error(
5015
+ String(
5016
+ ctx.__error ?? ctx.error ?? "actor_session_state persistence query failed"
5017
+ )
5018
+ );
5019
+ }
5020
+ const rowCount = Number(ctx.rowCount ?? 0);
5021
+ if (!Number.isFinite(rowCount) || rowCount <= 0) {
5022
+ throw new Error(
5023
+ "actor_session_state persistence did not affect any rows (possible stale durable_version)"
5024
+ );
5025
+ }
5026
+ return {
5027
+ __success: true,
5028
+ persisted: true,
5029
+ actor_name: ctx.actor_name,
5030
+ actor_version: ctx.actor_version,
5031
+ actor_key: ctx.actor_key,
5032
+ service_name: ctx.service_name,
5033
+ durable_version: ctx.durable_version
5034
+ };
5035
+ },
5036
+ "Enforces strict actor session persistence success contract.",
5037
+ { isSubMeta: true, concurrency: 100 }
5038
+ );
5039
+ const insertAndValidateActorSessionStateTask = actorSessionStateInsertTask.then(
5040
+ validateActorSessionStatePersistenceTask
5041
+ );
5042
+ CadenzaService.createMetaTask(
5043
+ "Persist actor session state",
5044
+ (ctx) => {
5045
+ const actorName = typeof ctx.actor_name === "string" ? ctx.actor_name.trim() : "";
5046
+ const actorKey = typeof ctx.actor_key === "string" ? ctx.actor_key.trim() : "";
5047
+ const actorVersion = Number(ctx.actor_version ?? 1);
5048
+ const durableVersion = Number(ctx.durable_version);
5049
+ if (!actorName) {
5050
+ throw new Error("actor_name is required for actor session persistence");
5051
+ }
5052
+ if (!actorKey) {
5053
+ throw new Error("actor_key is required for actor session persistence");
5054
+ }
5055
+ if (!Number.isInteger(actorVersion) || actorVersion < 1) {
5056
+ throw new Error("actor_version must be a positive integer");
5057
+ }
5058
+ if (!Number.isInteger(durableVersion) || durableVersion < 0) {
5059
+ throw new Error("durable_version must be a non-negative integer");
5060
+ }
5061
+ if (typeof ctx.durable_state !== "object" || ctx.durable_state === null || Array.isArray(ctx.durable_state)) {
5062
+ throw new Error("durable_state must be a non-null object");
5063
+ }
5064
+ const serviceName = CadenzaService.serviceRegistry.serviceName;
5065
+ if (!serviceName) {
5066
+ throw new Error("service_name is not available for actor session persistence");
5067
+ }
5068
+ let expiresAt = null;
5069
+ if (ctx.expires_at !== void 0 && ctx.expires_at !== null) {
5070
+ if (ctx.expires_at instanceof Date) {
5071
+ expiresAt = ctx.expires_at.toISOString();
5072
+ } else if (typeof ctx.expires_at === "string" && ctx.expires_at.trim().length > 0) {
5073
+ expiresAt = ctx.expires_at;
5074
+ } else {
5075
+ throw new Error("expires_at must be null, Date, or non-empty string");
5076
+ }
5077
+ }
5078
+ const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
5079
+ return {
5080
+ ...ctx,
5081
+ actor_name: actorName,
5082
+ actor_key: actorKey,
5083
+ actor_version: actorVersion,
5084
+ durable_version: durableVersion,
5085
+ expires_at: expiresAt,
5086
+ service_name: serviceName,
5087
+ queryData: {
5088
+ data: {
5089
+ actor_name: actorName,
5090
+ actor_version: actorVersion,
5091
+ actor_key: actorKey,
5092
+ service_name: serviceName,
5093
+ durable_state: ctx.durable_state,
5094
+ durable_version: durableVersion,
5095
+ expires_at: expiresAt,
5096
+ updated: updatedAt
5097
+ },
5098
+ onConflict: {
5099
+ target: [
5100
+ "actor_name",
5101
+ "actor_version",
5102
+ "actor_key",
5103
+ "service_name"
5104
+ ],
5105
+ action: {
5106
+ do: "update",
5107
+ set: {
5108
+ durable_state: "excluded",
5109
+ durable_version: "excluded",
5110
+ expires_at: "excluded",
5111
+ updated: "excluded"
5112
+ },
5113
+ where: "actor_session_state.durable_version <= excluded.durable_version"
5114
+ }
5115
+ }
5116
+ }
5117
+ };
5118
+ },
5119
+ "Validates and prepares actor_session_state payload for strict write-through persistence.",
5120
+ { isSubMeta: true, concurrency: 100 }
5121
+ ).then(insertAndValidateActorSessionStateTask).respondsTo(META_ACTOR_SESSION_STATE_PERSIST_INTENT);
5004
5122
  CadenzaService.createMetaTask("Handle Intent Creation", (ctx) => {
5005
5123
  const intentName = ctx.data?.name;
5006
5124
  return {