@fabricorg/platform 1.5.1 → 1.6.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +25 -2
  3. package/dist/actions/index.cjs +6 -6
  4. package/dist/actions/index.d.cts +3 -1
  5. package/dist/actions/index.d.ts +3 -1
  6. package/dist/actions/index.js +1 -1
  7. package/dist/certification/index.cjs +8 -7
  8. package/dist/certification/index.d.cts +1 -0
  9. package/dist/certification/index.d.ts +1 -0
  10. package/dist/certification/index.js +5 -4
  11. package/dist/{chunk-ZBXFRJON.cjs → chunk-2URHPZXL.cjs} +20 -7
  12. package/dist/chunk-2URHPZXL.cjs.map +1 -0
  13. package/dist/chunk-D4SWRBUH.cjs +22 -0
  14. package/dist/chunk-D4SWRBUH.cjs.map +1 -0
  15. package/dist/{chunk-MSABJAED.cjs → chunk-DDX5FKOM.cjs} +2 -2
  16. package/dist/chunk-DDX5FKOM.cjs.map +1 -0
  17. package/dist/chunk-LFE74IJX.js +20 -0
  18. package/dist/chunk-LFE74IJX.js.map +1 -0
  19. package/dist/{chunk-JG35DT2G.js → chunk-MLBALEUR.js} +5 -2
  20. package/dist/chunk-MLBALEUR.js.map +1 -0
  21. package/dist/{chunk-2W6FORTE.js → chunk-OZWUNGJE.js} +2 -2
  22. package/dist/chunk-OZWUNGJE.js.map +1 -0
  23. package/dist/{chunk-MC3GSVJ6.js → chunk-QHV6LOS6.js} +17 -4
  24. package/dist/chunk-QHV6LOS6.js.map +1 -0
  25. package/dist/{chunk-CXR6KEKQ.cjs → chunk-SNTV45LH.cjs} +5 -2
  26. package/dist/chunk-SNTV45LH.cjs.map +1 -0
  27. package/dist/{chunk-KIVQBZOA.cjs → chunk-TMMP4U2D.cjs} +7 -4
  28. package/dist/chunk-TMMP4U2D.cjs.map +1 -0
  29. package/dist/{chunk-DDO4EQ2J.js → chunk-UYCQV65U.js} +3 -3
  30. package/dist/{chunk-DDO4EQ2J.js.map → chunk-UYCQV65U.js.map} +1 -1
  31. package/dist/{chunk-PFKTD7V5.cjs → chunk-XS7EUS4T.cjs} +4 -4
  32. package/dist/{chunk-PFKTD7V5.cjs.map → chunk-XS7EUS4T.cjs.map} +1 -1
  33. package/dist/{chunk-GRBZYDEV.js → chunk-ZF5HDNSU.js} +6 -3
  34. package/dist/chunk-ZF5HDNSU.js.map +1 -0
  35. package/dist/discovery/index.cjs +12 -0
  36. package/dist/discovery/index.cjs.map +1 -0
  37. package/dist/discovery/index.d.cts +10 -0
  38. package/dist/discovery/index.d.ts +10 -0
  39. package/dist/discovery/index.js +3 -0
  40. package/dist/discovery/index.js.map +1 -0
  41. package/dist/governance/index.d.cts +1 -0
  42. package/dist/governance/index.d.ts +1 -0
  43. package/dist/index.cjs +62 -57
  44. package/dist/index.d.cts +1 -0
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.js +8 -7
  47. package/dist/manifest/index.cjs +10 -9
  48. package/dist/manifest/index.d.cts +3 -2
  49. package/dist/manifest/index.d.ts +3 -2
  50. package/dist/manifest/index.js +4 -3
  51. package/dist/modules/index.cjs +11 -10
  52. package/dist/modules/index.d.cts +1 -0
  53. package/dist/modules/index.d.ts +1 -0
  54. package/dist/modules/index.js +3 -2
  55. package/dist/policies/index.d.cts +1 -0
  56. package/dist/policies/index.d.ts +1 -0
  57. package/dist/projections/index.cjs +6 -5
  58. package/dist/projections/index.d.cts +2 -1
  59. package/dist/projections/index.d.ts +2 -1
  60. package/dist/projections/index.js +2 -1
  61. package/dist/testing/index.d.cts +1 -0
  62. package/dist/testing/index.d.ts +1 -0
  63. package/package.json +11 -1
  64. package/dist/chunk-2W6FORTE.js.map +0 -1
  65. package/dist/chunk-CXR6KEKQ.cjs.map +0 -1
  66. package/dist/chunk-GRBZYDEV.js.map +0 -1
  67. package/dist/chunk-JG35DT2G.js.map +0 -1
  68. package/dist/chunk-KIVQBZOA.cjs.map +0 -1
  69. package/dist/chunk-MC3GSVJ6.js.map +0 -1
  70. package/dist/chunk-MSABJAED.cjs.map +0 -1
  71. package/dist/chunk-ZBXFRJON.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @fabricorg/platform
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0b437ed: Add validated action/view discovery surface declarations with required reasons for internal entries.
8
+ Preserve them in public manifests and validate normalized manifests. Omitted declarations retain
9
+ public discovery and unchanged serialized shape. Discovery metadata never changes Host authority;
10
+ external catalogs must withhold internal entries and apply audience disclosure independently.
11
+
3
12
  ## 1.5.1
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -23,7 +23,7 @@ const greet: ActionDefinition<unknown> = {
23
23
 
24
24
  That's the smallest unit. From here, you compose actions into a `FabricModule<TDb>`, register the module at startup, and call `invokeAction("demo.greet", ...)` from any of three call paths (authenticated user, signed token, or system/agent). Every call passes through the same pipeline: **policy → state machine → handler → adapters → events → projections.**
25
25
 
26
- For a complete walkthrough see https://platform.fabric.pro/docs/getting-started/quickstart.
26
+ For a complete walkthrough see https://platform.techfabric.com/docs/getting-started/quickstart.
27
27
 
28
28
  ## Why use this
29
29
 
@@ -42,6 +42,7 @@ That's what this package gives you. Nothing more.
42
42
  | Subpath | What you get |
43
43
  |---|---|
44
44
  | `@fabricorg/platform` | Re-exports everything below |
45
+ | `@fabricorg/platform/discovery` | Portable discovery-surface declarations and validation |
45
46
  | `@fabricorg/platform/actions` | `ActionDefinition`, `ActionContext`, `SagaImplementation` |
46
47
  | `@fabricorg/platform/policies` | `PolicyEvaluator`, `PolicyContext`, code/data/hybrid evaluation |
47
48
  | `@fabricorg/platform/state-machines` | `StateMachineDefinition`, structural and guard-aware transition evaluation |
@@ -174,7 +175,29 @@ See [`CHANGELOG.md`](./CHANGELOG.md) for release history.
174
175
 
175
176
  ## Documentation
176
177
 
177
- Full reference docs at https://platform.fabric.pro
178
+ Full reference docs at https://platform.techfabric.com
179
+
180
+ ## Discovery surface declarations
181
+
182
+ Actions and views can declare `surface: "internal"` with a non-blank `surfaceReason`.
183
+ Omission means public discovery. Registration, manifest export and manifest normalization reject
184
+ unknown surfaces and missing reasons. Public manifests retain both fields, so contract digests
185
+ cover the declaration. Existing declarations without these fields preserve their exported shape.
186
+
187
+ External catalog consumers must omit internal entries, including their reason and schemas, and
188
+ apply their existing audience disclosure rules to public entries. This is discovery metadata:
189
+ it does not grant invocation/read access, bypass policy, or stop authorized workers from running
190
+ internal actions through the governed Host. A public entry is not a promise of an authored route.
191
+
192
+ `surface` controls definition discovery, while action `execution.sensitivity` and view
193
+ `usage.classification` describe execution/data disclosure. These are independent declarations.
194
+ `assertSurfaceDeclaration` is available from the root and `@fabricorg/platform/discovery`.
195
+ Reasons are authored public-package metadata; authors must keep them free of secrets.
196
+
197
+ No first-party compiler or generator artifact applies discovery filtering. All deliberately
198
+ retain internal contracts for trusted assembly and worker integration; none implements external
199
+ catalog disclosure. A usage contract or generated schema must not
200
+ be served as an audience catalog without the internal-surface and audience filters above.
178
201
 
179
202
  ## License
180
203
 
@@ -1,28 +1,28 @@
1
1
  'use strict';
2
2
 
3
- var chunkMSABJAED_cjs = require('../chunk-MSABJAED.cjs');
3
+ var chunkDDX5FKOM_cjs = require('../chunk-DDX5FKOM.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "ACTOR_TYPES", {
8
8
  enumerable: true,
9
- get: function () { return chunkMSABJAED_cjs.ACTOR_TYPES; }
9
+ get: function () { return chunkDDX5FKOM_cjs.ACTOR_TYPES; }
10
10
  });
11
11
  Object.defineProperty(exports, "assertActionId", {
12
12
  enumerable: true,
13
- get: function () { return chunkMSABJAED_cjs.assertActionId; }
13
+ get: function () { return chunkDDX5FKOM_cjs.assertActionId; }
14
14
  });
15
15
  Object.defineProperty(exports, "assertActorType", {
16
16
  enumerable: true,
17
- get: function () { return chunkMSABJAED_cjs.assertActorType; }
17
+ get: function () { return chunkDDX5FKOM_cjs.assertActorType; }
18
18
  });
19
19
  Object.defineProperty(exports, "createActionRegistry", {
20
20
  enumerable: true,
21
- get: function () { return chunkMSABJAED_cjs.createActionRegistry; }
21
+ get: function () { return chunkDDX5FKOM_cjs.createActionRegistry; }
22
22
  });
23
23
  Object.defineProperty(exports, "isActorType", {
24
24
  enumerable: true,
25
- get: function () { return chunkMSABJAED_cjs.isActorType; }
25
+ get: function () { return chunkDDX5FKOM_cjs.isActorType; }
26
26
  });
27
27
  //# sourceMappingURL=index.cjs.map
28
28
  //# sourceMappingURL=index.cjs.map
@@ -1,3 +1,5 @@
1
+ import { SurfaceDeclaration } from '../discovery/index.cjs';
2
+
1
3
  type ActionId = `${string}.${string}`;
2
4
  interface SchemaParseIssue {
3
5
  path: PropertyKey[];
@@ -63,7 +65,7 @@ interface ActionStateMachineBinding {
63
65
  targetState: string | ((params: unknown) => string);
64
66
  getEntityId: (params: unknown) => string | undefined;
65
67
  }
66
- interface ActionDefinition<TDb = unknown> {
68
+ interface ActionDefinition<TDb = unknown> extends SurfaceDeclaration {
67
69
  actionId: ActionId;
68
70
  namespace: string;
69
71
  version: number;
@@ -1,3 +1,5 @@
1
+ import { SurfaceDeclaration } from '../discovery/index.js';
2
+
1
3
  type ActionId = `${string}.${string}`;
2
4
  interface SchemaParseIssue {
3
5
  path: PropertyKey[];
@@ -63,7 +65,7 @@ interface ActionStateMachineBinding {
63
65
  targetState: string | ((params: unknown) => string);
64
66
  getEntityId: (params: unknown) => string | undefined;
65
67
  }
66
- interface ActionDefinition<TDb = unknown> {
68
+ interface ActionDefinition<TDb = unknown> extends SurfaceDeclaration {
67
69
  actionId: ActionId;
68
70
  namespace: string;
69
71
  version: number;
@@ -1,3 +1,3 @@
1
- export { ACTOR_TYPES, assertActionId, assertActorType, createActionRegistry, isActorType } from '../chunk-2W6FORTE.js';
1
+ export { ACTOR_TYPES, assertActionId, assertActorType, createActionRegistry, isActorType } from '../chunk-OZWUNGJE.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -1,25 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var chunkPFKTD7V5_cjs = require('../chunk-PFKTD7V5.cjs');
4
- require('../chunk-ZBXFRJON.cjs');
5
- require('../chunk-KIVQBZOA.cjs');
3
+ var chunkXS7EUS4T_cjs = require('../chunk-XS7EUS4T.cjs');
4
+ require('../chunk-2URHPZXL.cjs');
5
+ require('../chunk-TMMP4U2D.cjs');
6
6
  require('../chunk-IFW43ELT.cjs');
7
- require('../chunk-CXR6KEKQ.cjs');
7
+ require('../chunk-SNTV45LH.cjs');
8
+ require('../chunk-D4SWRBUH.cjs');
8
9
  require('../chunk-2AE6TMAX.cjs');
9
10
 
10
11
 
11
12
 
12
13
  Object.defineProperty(exports, "STRICT_EXECUTION_CONTRACT_PROFILE", {
13
14
  enumerable: true,
14
- get: function () { return chunkPFKTD7V5_cjs.STRICT_EXECUTION_CONTRACT_PROFILE; }
15
+ get: function () { return chunkXS7EUS4T_cjs.STRICT_EXECUTION_CONTRACT_PROFILE; }
15
16
  });
16
17
  Object.defineProperty(exports, "STRICT_EXECUTION_CONTRACT_PROFILE_ID", {
17
18
  enumerable: true,
18
- get: function () { return chunkPFKTD7V5_cjs.STRICT_EXECUTION_CONTRACT_PROFILE_ID; }
19
+ get: function () { return chunkXS7EUS4T_cjs.STRICT_EXECUTION_CONTRACT_PROFILE_ID; }
19
20
  });
20
21
  Object.defineProperty(exports, "executionContractProfile", {
21
22
  enumerable: true,
22
- get: function () { return chunkPFKTD7V5_cjs.executionContractProfile; }
23
+ get: function () { return chunkXS7EUS4T_cjs.executionContractProfile; }
23
24
  });
24
25
  //# sourceMappingURL=index.cjs.map
25
26
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,7 @@
1
1
  import { ActionCompletionMode } from '../actions/index.cjs';
2
2
  import { ModuleManifest } from '../manifest/index.cjs';
3
3
  import { FabricModule } from '../modules/index.cjs';
4
+ import '../discovery/index.cjs';
4
5
  import '../objects/index.cjs';
5
6
  import '../policies/index.cjs';
6
7
  import '../state-machines/index.cjs';
@@ -1,6 +1,7 @@
1
1
  import { ActionCompletionMode } from '../actions/index.js';
2
2
  import { ModuleManifest } from '../manifest/index.js';
3
3
  import { FabricModule } from '../modules/index.js';
4
+ import '../discovery/index.js';
4
5
  import '../objects/index.js';
5
6
  import '../policies/index.js';
6
7
  import '../state-machines/index.js';
@@ -1,8 +1,9 @@
1
- export { STRICT_EXECUTION_CONTRACT_PROFILE, STRICT_EXECUTION_CONTRACT_PROFILE_ID, executionContractProfile } from '../chunk-DDO4EQ2J.js';
2
- import '../chunk-MC3GSVJ6.js';
3
- import '../chunk-GRBZYDEV.js';
1
+ export { STRICT_EXECUTION_CONTRACT_PROFILE, STRICT_EXECUTION_CONTRACT_PROFILE_ID, executionContractProfile } from '../chunk-UYCQV65U.js';
2
+ import '../chunk-QHV6LOS6.js';
3
+ import '../chunk-ZF5HDNSU.js';
4
4
  import '../chunk-ZAEVQSB5.js';
5
- import '../chunk-JG35DT2G.js';
5
+ import '../chunk-MLBALEUR.js';
6
+ import '../chunk-LFE74IJX.js';
6
7
  import '../chunk-B5DOGDPG.js';
7
8
  //# sourceMappingURL=index.js.map
8
9
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkKIVQBZOA_cjs = require('./chunk-KIVQBZOA.cjs');
3
+ var chunkTMMP4U2D_cjs = require('./chunk-TMMP4U2D.cjs');
4
+ var chunkD4SWRBUH_cjs = require('./chunk-D4SWRBUH.cjs');
4
5
 
5
6
  // manifest/index.ts
6
7
  var MODULE_MANIFEST_VERSION = 2;
@@ -9,10 +10,16 @@ function normalizeModuleManifest(manifest) {
9
10
  if (version !== 1 && version !== MODULE_MANIFEST_VERSION) {
10
11
  throw new Error(`Unsupported module manifest version: ${String(version)}`);
11
12
  }
13
+ const views = "views" in manifest && Array.isArray(manifest.views) ? manifest.views : [];
14
+ if (Array.isArray(manifest.actions))
15
+ for (const [index, action] of manifest.actions.entries())
16
+ chunkD4SWRBUH_cjs.assertSurfaceDeclaration(action, `Module "${manifest.namespace}" action[${index}] "${action?.actionId ?? "unknown"}"`);
17
+ for (const [index, view] of views.entries())
18
+ chunkD4SWRBUH_cjs.assertSurfaceDeclaration(view, `Module "${manifest.namespace}" view[${index}] "${view?.name ?? "unknown"}"`);
12
19
  return {
13
20
  ...manifest,
14
21
  manifestVersion: MODULE_MANIFEST_VERSION,
15
- views: "views" in manifest && Array.isArray(manifest.views) ? manifest.views : []
22
+ views
16
23
  };
17
24
  }
18
25
  function normalizeModuleManifestBundle(bundle) {
@@ -32,7 +39,7 @@ function isRecord(value) {
32
39
  return value !== null && typeof value === "object" && !Array.isArray(value);
33
40
  }
34
41
  function exportDependency(dependency) {
35
- const namespace = chunkKIVQBZOA_cjs.getModuleDependencyNamespace(dependency);
42
+ const namespace = chunkTMMP4U2D_cjs.getModuleDependencyNamespace(dependency);
36
43
  if (typeof dependency === "string") {
37
44
  return { namespace };
38
45
  }
@@ -45,7 +52,7 @@ function exportObjectType(objectType) {
45
52
  if (typeof objectType === "string") {
46
53
  return { type: objectType };
47
54
  }
48
- const normalized = { type: chunkKIVQBZOA_cjs.getObjectTypeName(objectType) };
55
+ const normalized = { type: chunkTMMP4U2D_cjs.getObjectTypeName(objectType) };
49
56
  if (objectType.displayName !== void 0) normalized.displayName = objectType.displayName;
50
57
  if (objectType.idPrefix !== void 0) normalized.idPrefix = objectType.idPrefix;
51
58
  if (objectType.schema !== void 0) normalized.schema = cloneJson(objectType.schema);
@@ -72,7 +79,7 @@ function exportEventType(eventType) {
72
79
  return { eventType, schemaVersion: 1 };
73
80
  }
74
81
  const normalized = {
75
- eventType: chunkKIVQBZOA_cjs.getEventTypeName(eventType),
82
+ eventType: chunkTMMP4U2D_cjs.getEventTypeName(eventType),
76
83
  schemaVersion: eventType.schemaVersion
77
84
  };
78
85
  if (eventType.description !== void 0) normalized.description = eventType.description;
@@ -80,6 +87,7 @@ function exportEventType(eventType) {
80
87
  return normalized;
81
88
  }
82
89
  function exportAction(action) {
90
+ chunkD4SWRBUH_cjs.assertSurfaceDeclaration(action, `Action "${action?.actionId ?? "unknown"}"`);
83
91
  const manifest = {
84
92
  actionId: action.actionId,
85
93
  version: action.version,
@@ -88,6 +96,8 @@ function exportAction(action) {
88
96
  mutatesDomain: action.mutatesDomain,
89
97
  emitsEvents: [...action.emitsEvents]
90
98
  };
99
+ if (action.surface !== void 0) manifest.surface = action.surface;
100
+ if (action.surfaceReason !== void 0) manifest.surfaceReason = action.surfaceReason;
91
101
  if (action.policies !== void 0) manifest.policies = [...action.policies];
92
102
  if (action.requiredRoles !== void 0) manifest.requiredRoles = [...action.requiredRoles];
93
103
  if (action.requiredPermissions !== void 0) {
@@ -180,6 +190,7 @@ function exportStateMachine(machine) {
180
190
  };
181
191
  }
182
192
  function exportView(view) {
193
+ chunkD4SWRBUH_cjs.assertSurfaceDeclaration(view, `View "${view?.name ?? "unknown"}"`);
183
194
  const output = {
184
195
  name: view.name,
185
196
  version: view.version,
@@ -191,6 +202,8 @@ function exportView(view) {
191
202
  scope: view.scope,
192
203
  snapshotVersion: view.snapshotVersion
193
204
  };
205
+ if (view.surface !== void 0) output.surface = view.surface;
206
+ if (view.surfaceReason !== void 0) output.surfaceReason = view.surfaceReason;
194
207
  if (view.parameterSchema !== void 0) output.parameterSchema = cloneJson(view.parameterSchema);
195
208
  if (view.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];
196
209
  if (view.usage) output.usage = cloneJson(view.usage);
@@ -232,5 +245,5 @@ exports.exportModuleManifestBundle = exportModuleManifestBundle;
232
245
  exports.isJsonSchemaExportableValidator = isJsonSchemaExportableValidator;
233
246
  exports.normalizeModuleManifest = normalizeModuleManifest;
234
247
  exports.normalizeModuleManifestBundle = normalizeModuleManifestBundle;
235
- //# sourceMappingURL=chunk-ZBXFRJON.cjs.map
236
- //# sourceMappingURL=chunk-ZBXFRJON.cjs.map
248
+ //# sourceMappingURL=chunk-2URHPZXL.cjs.map
249
+ //# sourceMappingURL=chunk-2URHPZXL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../manifest/index.ts"],"names":["assertSurfaceDeclaration","getModuleDependencyNamespace","getObjectTypeName","getEventTypeName"],"mappings":";;;;;;AA+BO,IAAM,uBAAA,GAA0B;AAkKhC,SAAS,wBACf,QAAA,EACiB;AACjB,EAAA,MAAM,UAAkB,QAAA,CAAS,eAAA;AACjC,EAAA,IAAI,OAAA,KAAY,CAAA,IAAK,OAAA,KAAY,uBAAA,EAAyB;AACzD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,MAAA,CAAO,OAAO,CAAC,CAAA,CAAE,CAAA;AAAA,EAC1E;AACA,EAAA,MAAM,KAAA,GAAQ,OAAA,IAAW,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,SAAS,KAAK,CAAA,GAAI,QAAA,CAAS,KAAA,GAAQ,EAAC;AAEvF,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,OAAO,CAAA;AACjC,IAAA,KAAA,MAAW,CAAC,KAAA,EAAO,MAAM,CAAA,IAAK,QAAA,CAAS,QAAQ,OAAA,EAAQ;AACtD,MAAAA,0CAAA,CAAyB,MAAA,EAAQ,CAAA,QAAA,EAAW,QAAA,CAAS,SAAS,CAAA,SAAA,EAAY,KAAK,CAAA,GAAA,EAAM,MAAA,EAAQ,QAAA,IAAY,SAAS,CAAA,CAAA,CAAG,CAAA;AACvH,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,IAAI,CAAA,IAAK,MAAM,OAAA,EAAQ;AACzC,IAAAA,0CAAA,CAAyB,IAAA,EAAM,CAAA,QAAA,EAAW,QAAA,CAAS,SAAS,CAAA,OAAA,EAAU,KAAK,CAAA,GAAA,EAAM,IAAA,EAAM,IAAA,IAAQ,SAAS,CAAA,CAAA,CAAG,CAAA;AAC5G,EAAA,OAAO;AA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c,MAAA,CAAO,WAAA;AACpE,EAAA,IAAI,OAAO,UAAA,KAAe,MAAA,WAAoB,UAAA,GAAa,SAAA,CAAU,OAAO,UAAU,CAAA;AAEtF,EAAA,OAAO,QAAA;AACR;AAMO,SAAS,2BACf,OAAA,EACuB;AACvB,EAAA,OAAO;AAAA,IACN,eAAA,EAAiB,uBAAA;AAAA,IACjB,OAAA,EAAS,OAAA,CAAQ,GAAA,CAAI,oBAAoB;AAAA,GAC1C;AACD","file":"chunk-2URHPZXL.cjs","sourcesContent":["import { assertSurfaceDeclaration, type SurfaceDeclaration } from \"../discovery\";\nimport type {\n\tActionExecutionContract,\n\tActionDefinition,\n\tAdapterStepRetryPolicy,\n\tSchemaValidator,\n} from \"../actions\";\nimport {\n\tgetEventTypeName,\n\tgetModuleDependencyNamespace,\n\tgetObjectTypeName,\n\ttype FabricModule,\n\ttype CapabilityMetadata,\n\ttype DeclarativeInvariant,\n\ttype ModuleDependency,\n\ttype ModuleDependencyInput,\n\ttype ObjectRelationDefinition,\n} from \"../modules\";\nimport type { JsonValue, PortableJsonSchema } from \"../objects\";\nimport type {\n\tDataPolicyDefinition,\n\tPolicyFallbackDefinition,\n\tPolicyKind,\n} from \"../policies\";\nimport type { StateDefinition, StateMachineDefinition } from \"../state-machines\";\nimport type { ViewContract } from \"../projections\";\n\n/**\n * Version of the module manifest contract. Bump when the serialized shape\n * changes in a way consumers must detect.\n */\nexport const MODULE_MANIFEST_VERSION = 2 as const;\n\nexport interface ModuleManifestObjectType {\n\ttype: string;\n\tdisplayName?: string;\n\tidPrefix?: string;\n\tschema?: PortableJsonSchema;\n\tsemantics?: Record<string, JsonValue>;\n\trelations?: ObjectRelationDefinition[];\n\tinvariants?: DeclarativeInvariant[];\n}\n\nexport interface ModuleManifestIdPrefix {\n\tprefix: string;\n\tname: string;\n}\n\nexport interface ModuleManifestEventType {\n\teventType: string;\n\tschemaVersion: number;\n\tdescription?: string;\n\tschema?: PortableJsonSchema;\n}\n\nexport interface ModuleManifestActionStateMachine {\n\tentityType: string;\n\t/** Present only when the binding declares a static target state. */\n\ttargetState?: string;\n}\n\nexport interface ModuleManifestAdapterStep {\n\tadapterType: string;\n\toperation: string;\n\tretryPolicy?: AdapterStepRetryPolicy;\n}\n\nexport interface ModuleManifestAction extends SurfaceDeclaration {\n\tactionId: string;\n\tversion: number;\n\tkind: \"atomic\" | \"saga\";\n\tidempotent: boolean;\n\tmutatesDomain: boolean;\n\temitsEvents: string[];\n\tpolicies?: string[];\n\trequiredRoles?: string[];\n\trequiredPermissions?: string[];\n\teventPhase?: \"before_adapters\" | \"after_adapters\";\n\texecution?: ActionExecutionContract;\n\t/**\n\t * JSON Schema for the action parameters, present only when the action's\n\t * `schema` validator implements {@link JsonSchemaExportableValidator}.\n\t */\n\tparameterSchema?: unknown;\n\tparameterSchemaFormat?: \"json-schema\";\n\tresultSchema?: unknown;\n\tresultSchemaFormat?: \"json-schema\";\n\tstateMachine?: ModuleManifestActionStateMachine;\n\tadapterSteps?: ModuleManifestAdapterStep[];\n}\n\nexport interface ModuleManifestCodePolicy {\n\ttype: \"code\";\n\tpolicyId: string;\n\tversion: number;\n\tpreviewSafe?: boolean;\n}\n\nexport interface ModuleManifestDataPolicy {\n\ttype: \"data\";\n\tpolicyId: string;\n\tpolicyVersion: number;\n\tkind: PolicyKind;\n\tdataDefinition?: DataPolicyDefinition;\n\tcodeEvaluatorPolicyId?: string;\n\tfallback?: PolicyFallbackDefinition;\n}\n\nexport type ModuleManifestPolicy = ModuleManifestCodePolicy | ModuleManifestDataPolicy;\n\nexport interface ModuleManifestStateMachineTransition {\n\tfrom: string;\n\tto: string;\n\tcausedByAction: string;\n\t/** `true` when the transition declares a guard function. The guard itself is never serialized. */\n\thasGuard: boolean;\n}\n\nexport interface ModuleManifestStateMachine {\n\tentityType: string;\n\t/** States in declaration order (`Object.values` order of the definition record). */\n\tstates: StateDefinition[];\n\ttransitions: ModuleManifestStateMachineTransition[];\n}\n\nexport interface ModuleManifestView extends SurfaceDeclaration {\n\tname: string;\n\tversion: string;\n\tshape: PortableJsonSchema;\n\tparameterSchema?: PortableJsonSchema;\n\tconsumes: Array<{ eventType: string; schemaVersions: number[] }>;\n\tscope: \"tenant-space\";\n\tsnapshotVersion: number;\n\tcompatibleSnapshotVersions?: number[];\n\tusage?: ViewContract[\"usage\"];\n}\n\n/**\n * Stable, JSON-serializable description of a {@link FabricModule}'s ontology:\n * object types, subject types, id prefixes, event types, actions, policies,\n * and state machines. Intended for downstream tooling (semantics exporters,\n * docs generators, tool generators) that cannot consume live module code.\n *\n * The manifest contains definitions only — never raw parameter values,\n * secrets, or runtime data. Function fields (`handler`, `evaluate`, `guard`,\n * dynamic `targetState`, adapter `getInput`) are never serialized.\n */\nexport interface ModuleManifest {\n\tmanifestVersion: typeof MODULE_MANIFEST_VERSION;\n\tnamespace: string;\n\tversion?: string;\n\tdisplayName?: string;\n\tdescription?: string;\n\tcapability?: CapabilityMetadata;\n\tdependencies: ModuleDependency[];\n\tobjectTypes: ModuleManifestObjectType[];\n\tsubjectTypes: string[];\n\tidPrefixes: ModuleManifestIdPrefix[];\n\teventTypes: ModuleManifestEventType[];\n\tactions: ModuleManifestAction[];\n\tpolicies: ModuleManifestPolicy[];\n\tstateMachines: ModuleManifestStateMachine[];\n\tviews: ModuleManifestView[];\n}\n\nexport interface ModuleManifestBundle {\n\tmanifestVersion: typeof MODULE_MANIFEST_VERSION;\n\t/** Manifests in the input module order. */\n\tmodules: ModuleManifest[];\n}\n\n/** Manifest v1 remains accepted by v2 readers; missing v2 fields normalize to absence. */\nexport type ModuleManifestObjectTypeV1 = Omit<\n\tModuleManifestObjectType,\n\t\"schema\" | \"semantics\" | \"relations\" | \"invariants\"\n>;\nexport type ModuleManifestActionV1 = Omit<\n\tModuleManifestAction,\n\t\"resultSchema\" | \"resultSchemaFormat\"\n>;\nexport type ModuleManifestV1 = Omit<\n\tModuleManifest,\n\t\"manifestVersion\" | \"objectTypes\" | \"actions\" | \"views\"\n> & {\n\tmanifestVersion: 1;\n\tobjectTypes: ModuleManifestObjectTypeV1[];\n\tactions: ModuleManifestActionV1[];\n};\nexport type ModuleManifestBundleV1 = Omit<ModuleManifestBundle, \"manifestVersion\" | \"modules\"> & {\n\tmanifestVersion: 1;\n\tmodules: ModuleManifestV1[];\n};\n\nexport function normalizeModuleManifest(\n\tmanifest: ModuleManifest | ModuleManifestV1,\n): ModuleManifest {\n\tconst version: number = manifest.manifestVersion;\n\tif (version !== 1 && version !== MODULE_MANIFEST_VERSION) {\n\t\tthrow new Error(`Unsupported module manifest version: ${String(version)}`);\n\t}\n\tconst views = \"views\" in manifest && Array.isArray(manifest.views) ? manifest.views : [];\n\t// Preserve the normalizer's legacy tolerance for absent/non-array fields.\n\tif (Array.isArray(manifest.actions))\n\t\tfor (const [index, action] of manifest.actions.entries())\n\t\t\tassertSurfaceDeclaration(action, `Module \"${manifest.namespace}\" action[${index}] \"${action?.actionId ?? \"unknown\"}\"`);\n\tfor (const [index, view] of views.entries())\n\t\tassertSurfaceDeclaration(view, `Module \"${manifest.namespace}\" view[${index}] \"${view?.name ?? \"unknown\"}\"`);\n\treturn {\n\t\t...manifest,\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tviews,\n\t};\n}\n\nexport function normalizeModuleManifestBundle(\n\tbundle: ModuleManifestBundle | ModuleManifestBundleV1,\n): ModuleManifestBundle {\n\tconst version: number = bundle.manifestVersion;\n\tif (version !== 1 && version !== MODULE_MANIFEST_VERSION) {\n\t\tthrow new Error(`Unsupported module manifest bundle version: ${String(version)}`);\n\t}\n\treturn {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tmodules: bundle.modules.map((manifest) => normalizeModuleManifest(manifest)),\n\t};\n}\n\n/**\n * A {@link SchemaValidator} that can also export its parameter schema as JSON\n * Schema (for example a Zod 4 schema via `z.toJSONSchema`). Keeps the platform\n * zero-dependency while letting schema-bearing actions flow into manifests.\n */\nexport interface JsonSchemaExportableValidator extends SchemaValidator {\n\ttoJSONSchema(): Record<string, unknown>;\n}\n\nexport function isJsonSchemaExportableValidator(\n\tschema: SchemaValidator,\n): schema is JsonSchemaExportableValidator {\n\treturn (\n\t\ttypeof (schema as Partial<JsonSchemaExportableValidator>).toJSONSchema === \"function\"\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction exportDependency(dependency: ModuleDependencyInput): ModuleDependency {\n\tconst namespace = getModuleDependencyNamespace(dependency);\n\tif (typeof dependency === \"string\") {\n\t\treturn { namespace };\n\t}\n\tconst normalized: ModuleDependency = { namespace };\n\tif (dependency.version !== undefined) normalized.version = dependency.version;\n\tif (dependency.optional !== undefined) normalized.optional = dependency.optional;\n\treturn normalized;\n}\n\nfunction exportObjectType(\n\tobjectType: NonNullable<FabricModule[\"objectTypes\"]>[number],\n): ModuleManifestObjectType {\n\tif (typeof objectType === \"string\") {\n\t\treturn { type: objectType };\n\t}\n\tconst normalized: ModuleManifestObjectType = { type: getObjectTypeName(objectType) };\n\tif (objectType.displayName !== undefined) normalized.displayName = objectType.displayName;\n\tif (objectType.idPrefix !== undefined) normalized.idPrefix = objectType.idPrefix;\n\tif (objectType.schema !== undefined) normalized.schema = cloneJson(objectType.schema);\n\tif (objectType.semantics !== undefined) normalized.semantics = cloneJson(objectType.semantics);\n\tif (objectType.relations !== undefined) {\n\t\tnormalized.relations = objectType.relations.map((relation) => ({ ...relation }));\n\t}\n\tif (objectType.invariants !== undefined) {\n\t\tnormalized.invariants = objectType.invariants.map((invariant) => ({ ...invariant }));\n\t}\n\treturn normalized;\n}\n\nfunction cloneJson<T>(value: T): T {\n\tif (Array.isArray(value)) return value.map((item) => cloneJson(item)) as T;\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value as Record<string, unknown>).map(([key, child]) => [key, cloneJson(child)]),\n\t\t) as T;\n\t}\n\treturn value;\n}\n\nfunction exportEventType(\n\teventType: NonNullable<FabricModule[\"eventTypes\"]>[number],\n): ModuleManifestEventType {\n\tif (typeof eventType === \"string\") {\n\t\t// String registrations carry no explicit schema version; the events\n\t\t// registry treats the bare name as the initial version of the type.\n\t\treturn { eventType, schemaVersion: 1 };\n\t}\n\tconst normalized: ModuleManifestEventType = {\n\t\teventType: getEventTypeName(eventType),\n\t\tschemaVersion: eventType.schemaVersion,\n\t};\n\tif (eventType.description !== undefined) normalized.description = eventType.description;\n\tif (eventType.schema !== undefined) normalized.schema = cloneJson(eventType.schema);\n\treturn normalized;\n}\n\nfunction exportAction(action: ActionDefinition): ModuleManifestAction {\n\tassertSurfaceDeclaration(action, `Action \"${action?.actionId ?? \"unknown\"}\"`);\n\tconst manifest: ModuleManifestAction = {\n\t\tactionId: action.actionId,\n\t\tversion: action.version,\n\t\tkind: action.kind ?? \"atomic\",\n\t\tidempotent: action.idempotent,\n\t\tmutatesDomain: action.mutatesDomain,\n\t\temitsEvents: [...action.emitsEvents],\n\t};\n\n\tif (action.surface !== undefined) manifest.surface = action.surface;\n\tif (action.surfaceReason !== undefined) manifest.surfaceReason = action.surfaceReason;\n\tif (action.policies !== undefined) manifest.policies = [...action.policies];\n\tif (action.requiredRoles !== undefined) manifest.requiredRoles = [...action.requiredRoles];\n\tif (action.requiredPermissions !== undefined) {\n\t\tmanifest.requiredPermissions = [...action.requiredPermissions];\n\t}\n\tif (action.eventPhase !== undefined) manifest.eventPhase = action.eventPhase;\n\tif (action.execution !== undefined) manifest.execution = cloneJson(action.execution);\n\n\tif (isJsonSchemaExportableValidator(action.schema)) {\n\t\ttry {\n\t\t\tmanifest.parameterSchema = action.schema.toJSONSchema();\n\t\t\tmanifest.parameterSchemaFormat = \"json-schema\";\n\t\t} catch {\n\t\t\t// Runtime-valid schemas that cannot be represented portably remain executable;\n\t\t\t// build-time consumers see the schema as unavailable rather than crashing export.\n\t\t}\n\t}\n\tif (action.resultSchema && isJsonSchemaExportableValidator(action.resultSchema)) {\n\t\ttry {\n\t\t\tmanifest.resultSchema = action.resultSchema.toJSONSchema();\n\t\t\tmanifest.resultSchemaFormat = \"json-schema\";\n\t\t} catch {\n\t\t\t// See parameter-schema behavior above.\n\t\t}\n\t}\n\n\tif (action.stateMachine !== undefined) {\n\t\tconst binding: ModuleManifestActionStateMachine = {\n\t\t\tentityType: action.stateMachine.entityType,\n\t\t};\n\t\tif (typeof action.stateMachine.targetState === \"string\") {\n\t\t\tbinding.targetState = action.stateMachine.targetState;\n\t\t}\n\t\tmanifest.stateMachine = binding;\n\t}\n\n\tif (action.adapterSteps !== undefined) {\n\t\tmanifest.adapterSteps = action.adapterSteps.map((step) => {\n\t\t\tconst exported: ModuleManifestAdapterStep = {\n\t\t\t\tadapterType: step.adapterType,\n\t\t\t\toperation: step.operation,\n\t\t\t};\n\t\t\tif (step.retryPolicy !== undefined) exported.retryPolicy = { ...step.retryPolicy };\n\t\t\treturn exported;\n\t\t});\n\t}\n\n\treturn manifest;\n}\n\nfunction exportPolicy(policy: unknown): ModuleManifestPolicy | undefined {\n\tif (!isRecord(policy) || typeof policy.policyId !== \"string\") {\n\t\treturn undefined;\n\t}\n\n\t// Code evaluator: identified by its `evaluate` function (never serialized).\n\tif (typeof policy.evaluate === \"function\") {\n\t\tconst exported: ModuleManifestCodePolicy = {\n\t\t\ttype: \"code\",\n\t\t\tpolicyId: policy.policyId,\n\t\t\tversion: typeof policy.version === \"number\" ? policy.version : 1,\n\t\t};\n\t\tif (typeof policy.previewSafe === \"boolean\") exported.previewSafe = policy.previewSafe;\n\t\treturn exported;\n\t}\n\n\t// Declarative runtime policy definition: pure data, serialized as-is.\n\tif (typeof policy.kind === \"string\" && typeof policy.policyVersion === \"number\") {\n\t\tconst exported: ModuleManifestDataPolicy = {\n\t\t\ttype: \"data\",\n\t\t\tpolicyId: policy.policyId,\n\t\t\tpolicyVersion: policy.policyVersion,\n\t\t\tkind: policy.kind as PolicyKind,\n\t\t};\n\t\tif (isRecord(policy.dataDefinition)) {\n\t\t\texported.dataDefinition = policy.dataDefinition as unknown as DataPolicyDefinition;\n\t\t}\n\t\tif (typeof policy.codeEvaluatorPolicyId === \"string\") {\n\t\t\texported.codeEvaluatorPolicyId = policy.codeEvaluatorPolicyId;\n\t\t}\n\t\tif (isRecord(policy.fallback)) {\n\t\t\texported.fallback = policy.fallback as unknown as PolicyFallbackDefinition;\n\t\t}\n\t\treturn exported;\n\t}\n\n\t// Unknown policy shape: omit rather than guess.\n\treturn undefined;\n}\n\nfunction exportStateMachine(machine: unknown): ModuleManifestStateMachine | undefined {\n\tif (\n\t\t!isRecord(machine) ||\n\t\ttypeof machine.entityType !== \"string\" ||\n\t\t!isRecord(machine.states) ||\n\t\t!Array.isArray(machine.transitions)\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst definition = machine as unknown as StateMachineDefinition;\n\treturn {\n\t\tentityType: definition.entityType,\n\t\tstates: Object.values(definition.states),\n\t\ttransitions: definition.transitions.map((transition) => ({\n\t\t\tfrom: transition.from,\n\t\t\tto: transition.to,\n\t\t\tcausedByAction: transition.causedByAction,\n\t\t\thasGuard: typeof transition.guard === \"function\",\n\t\t})),\n\t};\n}\n\nfunction exportView(view: ViewContract): ModuleManifestView {\n\tassertSurfaceDeclaration(view, `View \"${view?.name ?? \"unknown\"}\"`);\n\tconst output: ModuleManifestView = {\n\t\tname: view.name,\n\t\tversion: view.version,\n\t\tshape: cloneJson(view.shape),\n\t\tconsumes: view.consumes.map((consumption) => ({\n\t\t\teventType: consumption.eventType,\n\t\t\tschemaVersions: [...consumption.schemaVersions],\n\t\t})),\n\t\tscope: view.scope,\n\t\tsnapshotVersion: view.snapshotVersion,\n\t};\n\tif (view.surface !== undefined) output.surface = view.surface;\n\tif (view.surfaceReason !== undefined) output.surfaceReason = view.surfaceReason;\n\tif (view.parameterSchema !== undefined) output.parameterSchema = cloneJson(view.parameterSchema);\n\tif (view.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];\n\tif (view.usage) output.usage = cloneJson(view.usage);\n\treturn output;\n}\n\n/**\n * Export a stable, JSON-serializable manifest of a module's ontology.\n *\n * This is a pure function of the module object: it does not read or mutate the\n * global module/action/policy/state-machine registries, and the module does\n * not need to be registered first. Declaration order is preserved everywhere\n * (nothing is sorted), so the same module object always produces a\n * byte-identical `JSON.stringify` result.\n *\n * The manifest contains definitions only — never raw parameter values,\n * secrets, or runtime data. Function fields are elided (`handler`,\n * policy `evaluate`, transition `guard` → `hasGuard`, dynamic `targetState`,\n * adapter `getInput`).\n */\nexport function exportModuleManifest(module: FabricModule<unknown>): ModuleManifest {\n\tconst manifest: ModuleManifest = {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tnamespace: module.namespace,\n\t\tdependencies: (module.dependencies ?? []).map(exportDependency),\n\t\tobjectTypes: (module.objectTypes ?? []).map(exportObjectType),\n\t\tsubjectTypes: [...(module.subjectTypes ?? [])],\n\t\tidPrefixes: (module.idPrefixes ?? []).map((registration) => ({\n\t\t\tprefix: registration.prefix,\n\t\t\tname: registration.name,\n\t\t})),\n\t\teventTypes: (module.eventTypes ?? []).map(exportEventType),\n\t\tactions: (module.actions ?? []).map(exportAction),\n\t\tpolicies: (module.policies ?? [])\n\t\t\t.map(exportPolicy)\n\t\t\t.filter((policy): policy is ModuleManifestPolicy => policy !== undefined),\n\t\tstateMachines: (module.stateMachines ?? [])\n\t\t\t.map(exportStateMachine)\n\t\t\t.filter((machine): machine is ModuleManifestStateMachine => machine !== undefined),\n\t\tviews: (module.views ?? []).map(exportView),\n\t};\n\n\tif (module.version !== undefined) manifest.version = module.version;\n\tif (module.displayName !== undefined) manifest.displayName = module.displayName;\n\tif (module.description !== undefined) manifest.description = module.description;\n\tif (module.capability !== undefined) manifest.capability = cloneJson(module.capability);\n\n\treturn manifest;\n}\n\n/**\n * Export manifests for a set of modules, preserving the input order.\n * Like {@link exportModuleManifest}, this is pure and registry-free.\n */\nexport function exportModuleManifestBundle(\n\tmodules: FabricModule<unknown>[],\n): ModuleManifestBundle {\n\treturn {\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tmodules: modules.map(exportModuleManifest),\n\t};\n}\n"]}
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ // discovery/index.ts
4
+ function assertSurfaceDeclaration(value, label = "Contract") {
5
+ if (!value || typeof value !== "object" || Array.isArray(value))
6
+ throw new Error(`${label}: discovery surface declaration must be an object`);
7
+ const { surface, surfaceReason } = value;
8
+ if (surface !== void 0 && surface !== "public" && surface !== "internal") {
9
+ throw new Error(`${label}: Unknown discovery surface`);
10
+ }
11
+ if (surface === "internal") {
12
+ if (typeof surfaceReason !== "string" || !surfaceReason.trim()) {
13
+ throw new Error(`${label}: Internal discovery surface requires a reason`);
14
+ }
15
+ } else if (surfaceReason !== void 0) {
16
+ throw new Error(`${label}: Discovery surface reason requires an internal surface`);
17
+ }
18
+ }
19
+
20
+ exports.assertSurfaceDeclaration = assertSurfaceDeclaration;
21
+ //# sourceMappingURL=chunk-D4SWRBUH.cjs.map
22
+ //# sourceMappingURL=chunk-D4SWRBUH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../discovery/index.ts"],"names":[],"mappings":";;;AAQO,SAAS,wBAAA,CAAyB,KAAA,EAAgB,KAAA,GAAQ,UAAA,EAAiD;AACjH,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC7D,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,iDAAA,CAAmD,CAAA;AAC5E,EAAA,MAAM,EAAE,OAAA,EAAS,aAAA,EAAc,GAAI,KAAA;AACnC,EAAA,IAAI,OAAA,KAAY,MAAA,IAAa,OAAA,KAAY,QAAA,IAAY,YAAY,UAAA,EAAY;AAC5E,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,2BAAA,CAA6B,CAAA;AAAA,EACtD;AACA,EAAA,IAAI,YAAY,UAAA,EAAY;AAC3B,IAAA,IAAI,OAAO,aAAA,KAAkB,QAAA,IAAY,CAAC,aAAA,CAAc,MAAK,EAAG;AAC/D,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,8CAAA,CAAgD,CAAA;AAAA,IACzE;AAAA,EACD,CAAA,MAAA,IAAW,kBAAkB,MAAA,EAAW;AACvC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,uDAAA,CAAyD,CAAA;AAAA,EAClF;AACD","file":"chunk-D4SWRBUH.cjs","sourcesContent":["/** Portable discovery metadata. It never grants or denies runtime invocation authority. */\nexport interface SurfaceDeclaration {\n\t/** Omitted is public discovery; internal contracts are withheld from external catalogs. */\n\tsurface?: \"public\" | \"internal\";\n\t/** Required, non-blank explanation when surface is internal; never include sensitive data. */\n\tsurfaceReason?: string;\n}\n\nexport function assertSurfaceDeclaration(value: unknown, label = \"Contract\"): asserts value is SurfaceDeclaration {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(`${label}: discovery surface declaration must be an object`);\n\tconst { surface, surfaceReason } = value as SurfaceDeclaration;\n\tif (surface !== undefined && surface !== \"public\" && surface !== \"internal\") {\n\t\tthrow new Error(`${label}: Unknown discovery surface`);\n\t}\n\tif (surface === \"internal\") {\n\t\tif (typeof surfaceReason !== \"string\" || !surfaceReason.trim()) {\n\t\t\tthrow new Error(`${label}: Internal discovery surface requires a reason`);\n\t\t}\n\t} else if (surfaceReason !== undefined) {\n\t\tthrow new Error(`${label}: Discovery surface reason requires an internal surface`);\n\t}\n}\n"]}
@@ -49,5 +49,5 @@ exports.assertActionId = assertActionId;
49
49
  exports.assertActorType = assertActorType;
50
50
  exports.createActionRegistry = createActionRegistry;
51
51
  exports.isActorType = isActorType;
52
- //# sourceMappingURL=chunk-MSABJAED.cjs.map
53
- //# sourceMappingURL=chunk-MSABJAED.cjs.map
52
+ //# sourceMappingURL=ch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AAA,CAAW,QAAQ,CAAA,8FAAA,CAAgG,CAAA;AAAA,IAC/I;AACA,IAAA,OAAA,CAAQ,GAAA,CAAI,UAAA,CAAW,QAAA,EAAU,UAAU,CAAA;AAAA,EAC5C,CAAA;AACA,EAAA,KAAA,MAAW,UAAA,IAAc,WAAA,EAAa,QAAA,CAAS,UAAU,CAAA;AACzD,EAAA,OAAO;AAAA,IACN,QAAA;AAAA,IACA,kBAAkB,UAAA,EAAY;AAC7B,MAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,WAAW,QAAQ,CAAA,WAAY,UAAU,CAAA;AAAA,IAC3D,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,QAAA,KAAa,OAAA,CAAQ,IAAI,QAAQ,CAAA;AAAA,IAC3C,GAAA,EAAK,CAAC,QAAA,KAAmC,OAAA,CAAQ,IAAI,QAAoB,CAAA;AAAA,IACzE,KAAK,MAAM,KAAA,CAAM,IAAA,CAAK,OAAA,CAAQ,MAAM;AAAA,GACrC;AACD","file":"chunk-DDX5FKOM.cjs","sourcesContent":["import type { SurfaceDeclaration } from \"../discovery\";\nexport type ActionId = `${string}.${string}`;\n\nexport interface SchemaParseIssue {\n\tpath: PropertyKey[];\n\tmessage: string;\n}\n\nexport type SchemaParseResult<T = unknown> =\n\t| { success: true; data: T }\n\t| { success: false; error: { issues: SchemaParseIssue[] } };\n\nexport interface SchemaValidator<T = unknown> {\n\tparse(input: unknown): T;\n\tsafeParse(input: unknown): SchemaParseResult<T>;\n}\n\nexport type ActorType =\n\t| \"natural_person\"\n\t| \"agent\"\n\t| \"system\"\n\t| \"service_account\"\n\t| \"external_system\"\n\t| \"integration\";\n\nexport const ACTOR_TYPES: readonly ActorType[] = [\n\t\"natural_person\",\n\t\"agent\",\n\t\"system\",\n\t\"service_account\",\n\t\"external_system\",\n\t\"integration\",\n] as const;\n\nexport function isActorType(value: string): value is ActorType {\n\treturn (ACTOR_TYPES as readonly string[]).includes(value);\n}\n\nexport function assertActorType(value: string): asserts value is ActorType {\n\tif (!isActorType(value)) {\n\t\tthrow new Error(`Invalid actorType: ${value}`);\n\t}\n}\n\nexport type ActionStatus =\n\t| \"pending\"\n\t| \"running\"\n\t| \"completed\"\n\t| \"failed\"\n\t| \"blocked_by_policy\"\n\t| \"waiting_for_approval\"\n\t| \"reconciliation_required\"\n\t| \"validation_failed\";\n\nexport interface FabricRuntimeServices {\n\treadonly [serviceName: string]: unknown;\n}\n\nexport interface ActionContext<TDb = unknown> {\n\tactionInvocationId: string;\n\ttenantId: string;\n\tspaceId: string;\n\tactorId: string;\n\tactorType: ActorType;\n\tcorrelationId: string;\n\tcausationId?: string;\n\tprovenance?: { source: string; auditAttributes?: Record<string, string> };\n\tdb: TDb;\n\tservices?: FabricRuntimeServices;\n}\n\nexport interface ActionResult {\n\tsuccess: boolean;\n\tdata?: Record<string, unknown>;\n\terror?: string;\n}\n\nexport type ActionHandler<TDb = unknown> = (\n\tctx: ActionContext<TDb>,\n\tparams: unknown,\n) => Promise<ActionResult>;\n\nexport interface AdapterStepRetryPolicy {\n\tidempotent: boolean;\n\tmaxAttempts?: number;\n\tinitialDelayMs?: number;\n\tbackoffMultiplier?: number;\n\tmaxDelayMs?: number;\n}\n\nexport interface AdapterStep {\n\tadapterType: string;\n\toperation: string;\n\tretryPolicy?: AdapterStepRetryPolicy;\n\tgetInput: (\n\t\tparams: unknown,\n\t\thandlerResult: Record<string, unknown>,\n\t) => Record<string, unknown> | undefined;\n}\n\nexport interface ActionStateMachineBinding {\n\tentityType: string;\n\ttargetState: string | ((params: unknown) => string);\n\tgetEntityId: (params: unknown) => string | undefined;\n}\n\nexport interface ActionDefinition<TDb = unknown> extends SurfaceDeclaration {\n\tactionId: ActionId;\n\tnamespace: string;\n\tversion: number;\n\tschema: SchemaValidator;\n\t/** Optional validation contract for the public handler result data. */\n\tresultSchema?: SchemaValidator;\n\thandler?: ActionHandler<TDb>;\n\trequiredRoles?: string[];\n\trequiredPermissions?: string[];\n\tpolicies?: `${string}.v${number}`[];\n\temitsEvents: string[];\n\tidempotent: boolean;\n\tmutatesDomain: boolean;\n\t/** Portable execution semantics used by hosts, gateways, and generated capability contracts. */\n\texecution?: ActionExecutionContract;\n\tstateMachine?: ActionStateMachineBinding;\n\tadapterSteps?: AdapterStep[];\n\t/** Completion actions can attest only after all external adapter work succeeds. */\n\teventPhase?: \"before_adapters\" | \"after_adapters\";\n\t/**\n\t * If \"saga\", the action is a multi-step orchestration. The worker dispatches\n\t * to a registered saga implementation instead of running `handler` directly.\n\t */\n\tkind?: \"atomic\" | \"saga\";\n}\n\nexport type ActionConnectivity = \"online-required\" | \"offline-capturable\";\nexport type AuthorityMoment = \"capture\" | \"execution\" | \"both\";\nexport type ActionIdempotencyStance = \"required\" | \"supported\" | \"prohibited\";\nexport type ActionCompletionMode = \"immediate\" | \"accepted\" | \"long-running\";\nexport type ActionConsistency = \"authoritative-now\" | \"provisional-until-reconciled\";\nexport type ActionDataSensitivity = \"public\" | \"internal\" | \"confidential\" | \"restricted\";\n\nexport interface ActionExecutionContract {\n\tconnectivity: ActionConnectivity;\n\tauthorityMoment: AuthorityMoment;\n\tidempotency: ActionIdempotencyStance;\n\t/**\n\t * `immediate`: the invocation settles within the host's execution.\n\t * `accepted` and `long-running`: an adapter may hand the work to an\n\t * external system and the invocation stays running until that system\n\t * completes it by reference through the host's completion ingress.\n\t * Declare `completionDeadlineMs` on a `long-running` action so a callback\n\t * that never comes is noticed rather than waited on forever.\n\t */\n\tcompletion: ActionCompletionMode;\n\t/**\n\t * How long an accepted handoff may wait for its completion before the host\n\t * moves the invocation to reconciliation. Without it, nothing sweeps the\n\t * handoff. Refused on `immediate`, since nothing external completes it.\n\t */\n\tcompletionDeadlineMs?: number;\n\tconsistency: ActionConsistency;\n\tsensitivity?: ActionDataSensitivity;\n}\n\nexport interface SagaContext {\n\tactionInvocationId: string;\n\ttenantId: string;\n\tspaceId: string;\n\tparameters: unknown;\n\tsleep?: (delayMs: number) => Promise<void>;\n\tquery?: <T = unknown>(model: string, operation: string, args: unknown) => Promise<T>;\n\t/**\n\t * Wait for a named external signal carrying a payload of `T`, with a timeout.\n\t *\n\t * Resolves with the payload of the first signal received, or `null` if the timeout\n\t * fires first. Subsequent signals with the same name received before another\n\t * `awaitSignal` call are buffered (FIFO) so no signal is lost.\n\t *\n\t * Intended for agent-driven and webhook-driven coordination: replace polling loops\n\t * with push-based wakeups while preserving the saga's deterministic replay\n\t * semantics (the runtime is responsible for capturing signals into workflow history).\n\t *\n\t * Optional. Runtimes that cannot implement push-based signaling (e.g. an in-memory\n\t * test harness) may omit this; sagas should treat absence as a fallback condition\n\t * and use `sleep` + `query` polling instead.\n\t *\n\t * Signal *senders* are runtime-specific (e.g. a Temporal `WorkflowClient.signal()`\n\t * call from an action handler). Apps that need to send signals from action\n\t * handlers should expose a coordination service via `ActionContext.services`\n\t * — the platform does not prescribe the sender API.\n\t *\n\t * @example\n\t * const payload = await ctx.awaitSignal?.<{ result: Record<string, unknown> }>(\n\t * \"userInputProcessed\",\n\t * 5 * 60 * 1000,\n\t * );\n\t * if (payload) { /* handle pushed result *\\/ }\n\t * else { /* timeout — fall back to deterministic path *\\/ }\n\t */\n\tawaitSignal?: <T = unknown>(signalName: string, timeoutMs: number) => Promise<T | null>;\n}\n\nexport interface SagaChildActionInput {\n\tsuffix: string;\n\tactionId: string;\n\tparameters: Record<string, unknown>;\n}\n\nexport type SagaRunChild = (input: SagaChildActionInput) => Promise<Record<string, unknown>>;\n\nexport interface SagaCompletionEvent {\n\teventType: string;\n\tsubjectType: string;\n\tsubjectId: string;\n\tpayload: unknown;\n\teventSchemaVersion?: number;\n}\n\nexport interface SagaCompletion {\n\tresultData: Record<string, unknown>;\n\tevent?: SagaCompletionEvent;\n}\n\nexport type SagaImplementation = (\n\tctx: SagaContext,\n\trunChild: SagaRunChild,\n) => Promise<SagaCompletion>;\n\nexport function assertActionId(actionId: string): asserts actionId is ActionId {\n\tif (!/^[a-z][a-z0-9-]*\\.[a-z][a-z0-9_]*$/.test(actionId)) {\n\t\tthrow new Error(`Invalid action ID: ${actionId}`);\n\t}\n}\n\nexport interface ActionRegistry<TDb = unknown> {\n\tregister(definition: ActionDefinition<TDb>): void;\n\tregisterIfMissing(definition: ActionDefinition<TDb>): void;\n\tresolve(actionId: ActionId): ActionDefinition<TDb> | undefined;\n\thas(actionId: string): actionId is ActionId;\n\tids(): ActionId[];\n}\n\nexport function createActionRegistry<TDb = unknown>(definitions: readonly ActionDefinition<TDb>[] = []): ActionRegistry<TDb> {\n\tconst actions = new Map<ActionId, ActionDefinition<TDb>>();\n\tconst register = (definition: ActionDefinition<TDb>): void => {\n\t\tassertActionId(definition.actionId);\n\t\tif (actions.has(definition.actionId)) throw new Error(`Action \"${definition.actionId}\" is already registered`);\n\t\tif (definition.mutatesDomain && definition.emitsEvents.length === 0) {\n\t\t\tthrow new Error(`Action \"${definition.actionId}\" mutates domain but emits no events. Every mutating action must emit at least one AssetEvent.`);\n\t\t}\n\t\tactions.set(definition.actionId, definition);\n\t};\n\tfor (const definition of definitions) register(definition);\n\treturn {\n\t\tregister,\n\t\tregisterIfMissing(definition) {\n\t\t\tif (!actions.has(definition.actionId)) register(definition);\n\t\t},\n\t\tresolve: (actionId) => actions.get(actionId),\n\t\thas: (actionId): actionId is ActionId => actions.has(actionId as ActionId),\n\t\tids: () => Array.from(actions.keys()),\n\t};\n}\n"]}
@@ -0,0 +1,20 @@
1
+ // discovery/index.ts
2
+ function assertSurfaceDeclaration(value, label = "Contract") {
3
+ if (!value || typeof value !== "object" || Array.isArray(value))
4
+ throw new Error(`${label}: discovery surface declaration must be an object`);
5
+ const { surface, surfaceReason } = value;
6
+ if (surface !== void 0 && surface !== "public" && surface !== "internal") {
7
+ throw new Error(`${label}: Unknown discovery surface`);
8
+ }
9
+ if (surface === "internal") {
10
+ if (typeof surfaceReason !== "string" || !surfaceReason.trim()) {
11
+ throw new Error(`${label}: Internal discovery surface requires a reason`);
12
+ }
13
+ } else if (surfaceReason !== void 0) {
14
+ throw new Error(`${label}: Discovery surface reason requires an internal surface`);
15
+ }
16
+ }
17
+
18
+ export { assertSurfaceDeclaration };
19
+ //# sourceMappingURL=chunk-LFE74IJX.js.map
20
+ //# sourceMappingURL=chunk-LFE74IJX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../discovery/index.ts"],"names":[],"mappings":";AAQO,SAAS,wBAAA,CAAyB,KAAA,EAAgB,KAAA,GAAQ,UAAA,EAAiD;AACjH,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC7D,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,iDAAA,CAAmD,CAAA;AAC5E,EAAA,MAAM,EAAE,OAAA,EAAS,aAAA,EAAc,GAAI,KAAA;AACnC,EAAA,IAAI,OAAA,KAAY,MAAA,IAAa,OAAA,KAAY,QAAA,IAAY,YAAY,UAAA,EAAY;AAC5E,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,2BAAA,CAA6B,CAAA;AAAA,EACtD;AACA,EAAA,IAAI,YAAY,UAAA,EAAY;AAC3B,IAAA,IAAI,OAAO,aAAA,KAAkB,QAAA,IAAY,CAAC,aAAA,CAAc,MAAK,EAAG;AAC/D,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,8CAAA,CAAgD,CAAA;AAAA,IACzE;AAAA,EACD,CAAA,MAAA,IAAW,kBAAkB,MAAA,EAAW;AACvC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,uDAAA,CAAyD,CAAA;AAAA,EAClF;AACD","file":"chunk-LFE74IJX.js","sourcesContent":["/** Portable discovery metadata. It never grants or denies runtime invocation authority. */\nexport interface SurfaceDeclaration {\n\t/** Omitted is public discovery; internal contracts are withheld from external catalogs. */\n\tsurface?: \"public\" | \"internal\";\n\t/** Required, non-blank explanation when surface is internal; never include sensitive data. */\n\tsurfaceReason?: string;\n}\n\nexport function assertSurfaceDeclaration(value: unknown, label = \"Contract\"): asserts value is SurfaceDeclaration {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(`${label}: discovery surface declaration must be an object`);\n\tconst { surface, surfaceReason } = value as SurfaceDeclaration;\n\tif (surface !== undefined && surface !== \"public\" && surface !== \"internal\") {\n\t\tthrow new Error(`${label}: Unknown discovery surface`);\n\t}\n\tif (surface === \"internal\") {\n\t\tif (typeof surfaceReason !== \"string\" || !surfaceReason.trim()) {\n\t\t\tthrow new Error(`${label}: Internal discovery surface requires a reason`);\n\t\t}\n\t} else if (surfaceReason !== undefined) {\n\t\tthrow new Error(`${label}: Discovery surface reason requires an internal surface`);\n\t}\n}\n"]}
@@ -1,3 +1,5 @@
1
+ import { assertSurfaceDeclaration } from './chunk-LFE74IJX.js';
2
+
1
3
  // projections/index.ts
2
4
  function viewContractKey(view) {
3
5
  return `${view.name}@${view.version}`;
@@ -5,6 +7,7 @@ function viewContractKey(view) {
5
7
  function createViewRegistry(views = []) {
6
8
  const registered = /* @__PURE__ */ new Map();
7
9
  const register = (view) => {
10
+ assertSurfaceDeclaration(view, `View "${view?.name ?? "unknown"}"`);
8
11
  const key = viewContractKey(view);
9
12
  if (registered.has(key)) throw new Error(`View contract "${key}" is already registered.`);
10
13
  registered.set(key, view);
@@ -283,5 +286,5 @@ function toTimestamp(value) {
283
286
  }
284
287
 
285
288
  export { createViewRegistry, replayEvents, replayView, viewContractKey };
286
- //# sourceMappingURL=chunk-JG35DT2G.js.map
287
- //# sourceMappingURL=chunk-JG35DT2G.js.map
289
+ //# sourceMappingURL=chunk-MLBALEUR.js.map
290
+ //# sourceMappingURL=chunk-MLBALEUR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../projections/index.ts"],"names":[],"mappings":";;;AA2DO,SAAS,gBAAgB,IAAA,EAAsD;AACrF,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,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ClD,EAAA,OAAO,KAAA,YAAiB,OAAO,KAAA,CAAM,OAAA,KAAY,IAAI,IAAA,CAAK,KAAK,CAAA,CAAE,OAAA,EAAQ;AAC1E","file":"chunk-MLBALEUR.js","sourcesContent":["import { assertSurfaceDeclaration, type SurfaceDeclaration } from \"../discovery\";\nexport interface ReplayableAssetEvent<Payload = unknown> {\n\tid: string;\n\ttenantId: string;\n\tspaceId: string;\n\teventType: string;\n\teventSchemaVersion?: number;\n\tsubjectType: string;\n\tsubjectId: string;\n\tpayload: Payload;\n\t/**\n\t * Monotonic ordering cursor for the tenant/space event ledger. It is not\n\t * contiguous after a view filters event types or narrows to one subject.\n\t */\n\tsequence: number;\n\t/** Optional contiguous sequence local to this subject. */\n\tsubjectSequence?: number;\n\toccurredAt: Date | string;\n\trecordedAt: Date | string;\n\tactionInvocationId: string;\n\tcorrelationId: string;\n}\n\nimport type { PortableJsonSchema } from \"../objects\";\n\nexport interface ViewEventConsumption {\n\teventType: string;\n\tschemaVersions: number[];\n}\n\nexport interface ViewContract<State = unknown, Event extends ReplayableAssetEvent = ReplayableAssetEvent> extends SurfaceDeclaration {\n\t/** Stable module-qualified logical identity, for example `orders/summary`. */\n\tname: `${string}/${string}`;\n\tversion: string;\n\tshape: PortableJsonSchema;\n\t/** Optional JSON Schema for query parameters. Parameterized variants get isolated snapshots. */\n\tparameterSchema?: PortableJsonSchema;\n\tconsumes: ViewEventConsumption[];\n\tscope: \"tenant-space\";\n\tsnapshotVersion: number;\n\tcompatibleSnapshotVersions?: number[];\n\tusage?: ViewUsageMetadata;\n\t/** Required to transform any older compatible snapshot into the current state shape. */\n\tupgradeSnapshot?: (data: unknown, fromVersion: number) => State | Promise<State>;\n\tinitialState: State;\n\tapplyEvent: (state: State, event: Event) => State | Promise<State>;\n}\n\nexport interface ViewUsageMetadata {\n\tsemanticRole?: string;\n\tcollection?: {\n\t\tpagination: \"cursor\" | \"offset\" | \"none\";\n\t\tfilterSchema?: PortableJsonSchema;\n\t\tsortFields?: string[];\n\t};\n\tfreshness?: { maximumAgeSeconds?: number; offlineUsable?: boolean };\n\tclassification?: \"public\" | \"internal\" | \"confidential\" | \"restricted\";\n}\n\nexport function viewContractKey(view: Pick<ViewContract, \"name\" | \"version\">): string {\n\treturn `${view.name}@${view.version}`;\n}\n\nexport interface ViewRegistry {\n\tregister(view: ViewContract): void;\n\tregisterIfMissing(view: ViewContract): void;\n\tresolve(name: string, version: string): ViewContract | undefined;\n\tkeys(): string[];\n}\n\nexport function createViewRegistry(views: readonly ViewContract[] = []): ViewRegistry {\n\tconst registered = new Map<string, ViewContract>();\n\tconst register = (view: ViewContract): void => {\n\t\tassertSurfaceDeclaration(view, `View \"${view?.name ?? \"unknown\"}\"`);\n\t\tconst key = viewContractKey(view);\n\t\tif (registered.has(key)) throw new Error(`View contract \"${key}\" is already registered.`);\n\t\tregistered.set(key, view);\n\t};\n\tfor (const view of views) register(view);\n\treturn {\n\t\tregister,\n\t\tregisterIfMissing(view) {\n\t\t\tif (!registered.has(viewContractKey(view))) register(view);\n\t\t},\n\t\tresolve: (name, version) => registered.get(`${name}@${version}`),\n\t\tkeys: () => Array.from(registered.keys()).sort(),\n\t};\n}\n\nexport interface ReplayViewOptions<State, Event extends ReplayableAssetEvent = ReplayableAssetEvent> {\n\tview: ViewContract<State, Event>;\n\tevents: Iterable<Event> | AsyncIterable<Event>;\n\tscope: ReplayScope;\n\tsnapshot?: (ReplaySnapshot<State> & { snapshotVersion: number }) | null;\n\t/**\n\t * Set when the event source already applied the snapshot cursor and returns\n\t * only later events. The snapshot still seeds state, but replay must not try\n\t * to find its cursor in the supplied incremental stream.\n\t */\n\teventsStartAfterSnapshot?: boolean;\n}\n\nexport async function replayView<State, Event extends ReplayableAssetEvent = ReplayableAssetEvent>({\n\tview,\n\tevents,\n\tscope,\n\tsnapshot,\n\teventsStartAfterSnapshot = false,\n}: ReplayViewOptions<State, Event>): Promise<ReplayEventsResult<State, Event>> {\n\tif (\n\t\tsnapshot &&\n\t\tsnapshot.snapshotVersion !== view.snapshotVersion &&\n\t\t!view.compatibleSnapshotVersions?.includes(snapshot.snapshotVersion)\n\t) {\n\t\tthrow new Error(\n\t\t\t`View \"${viewContractKey(view)}\" cannot resume snapshot version ${snapshot.snapshotVersion}.`,\n\t\t);\n\t}\n\tif (snapshot && snapshot.snapshotVersion !== view.snapshotVersion && !view.upgradeSnapshot) {\n\t\tthrow new Error(\n\t\t\t`View \"${viewContractKey(view)}\" must provide upgradeSnapshot for snapshot version ${snapshot.snapshotVersion}.`,\n\t\t);\n\t}\n\tconst upgradedSnapshot = snapshot && snapshot.snapshotVersion !== view.snapshotVersion\n\t\t? { ...snapshot, snapshotVersion: view.snapshotVersion, snapshotData: await view.upgradeSnapshot!(snapshot.snapshotData, snapshot.snapshotVersion) }\n\t\t: snapshot;\n\tconst accepted = new Map(\n\t\tview.consumes.map((consumption) => [consumption.eventType, new Set(consumption.schemaVersions)]),\n\t);\n\tconst sourceEvents: Event[] = [];\n\tfor await (const event of events) sourceEvents.push(event);\n\tconst preprocessingWarnings: ReplayWarning[] = [];\n\tconst orderedScopedEvents = sortEvents(filterEventsByScope(sourceEvents, scope, preprocessingWarnings), Boolean(scope.subjectType && scope.subjectId));\n\tconst versionWarnings: ReplayWarning[] = [];\n\tconst replayable = async function* (): AsyncIterable<Event> {\n\t\tfor (const event of orderedScopedEvents) {\n\t\t\tconst versions = accepted.get(event.eventType);\n\t\t\tif (versions && !versions.has(event.eventSchemaVersion ?? 1)) {\n\t\t\t\tversionWarnings.push({ code: \"unsupported_event_version\", eventId: event.id, message: `View \"${viewContractKey(view)}\" does not consume ${event.eventType} schema version ${event.eventSchemaVersion ?? 1}; replay stopped before this event so a compatible view can resume it later.` });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tyield event;\n\t\t}\n\t};\n\tconst result = await replayEvents({\n\t\tevents: replayable(),\n\t\tscope,\n\t\tinitialState: view.initialState,\n\t\tsnapshot: upgradedSnapshot,\n\t\tapplyEvent: (state, event) => accepted.has(event.eventType) ? view.applyEvent(state, event) : state,\n\t\teventsStartAfterSnapshot,\n\t});\n\tconst preprocessingWarningKeys = new Set(preprocessingWarnings.map((warning) => JSON.stringify(warning)));\n\tconst resultWarnings = result.warnings.filter((warning) => !preprocessingWarningKeys.has(JSON.stringify(warning)));\n\treturn {\n\t\t...result,\n\t\teventCursor: result.eventCursor ?? upgradedSnapshot?.eventCursor ?? null,\n\t\teventSequence: result.appliedEvents.length\n\t\t\t? result.eventSequence\n\t\t\t: upgradedSnapshot?.eventSequence ?? result.eventSequence,\n\t\tsubjectSequences: result.appliedEvents.length\n\t\t\t? result.subjectSequences\n\t\t\t: upgradedSnapshot?.subjectSequences ?? result.subjectSequences,\n\t\twarnings: [...preprocessingWarnings, ...versionWarnings, ...resultWarnings],\n\t};\n}\n\nexport interface ReplayScope {\n\ttenantId: string;\n\tspaceId: string;\n\tsubjectType?: string;\n\tsubjectId?: string;\n}\n\nexport interface ReplaySnapshot<State = unknown> {\n\tsnapshotData: State;\n\teventCursor?: string | null;\n\teventSequence?: number | null;\n\t/** Per-subject high-water marks. Values prefer subjectSequence when supplied. */\n\tsubjectSequences?: Record<string, number>;\n}\n\nexport type ReplayWarningCode =\n\t| \"cursor_not_found\"\n\t| \"duplicate_event\"\n\t| \"missing_sequence\"\n\t| \"subject_scope_incomplete\"\n\t| \"unsupported_event_version\";\n\nexport interface ReplayWarning {\n\tcode: ReplayWarningCode;\n\tmessage: string;\n\teventId?: string;\n\tsubjectType?: string;\n\tsubjectId?: string;\n\texpectedSequence?: number;\n\tactualSequence?: number;\n}\n\nexport interface ReplayEventsOptions<State, Event extends ReplayableAssetEvent = ReplayableAssetEvent> {\n\tevents: Iterable<Event> | AsyncIterable<Event>;\n\tscope: ReplayScope;\n\tinitialState: State;\n\tsnapshot?: ReplaySnapshot<State> | null;\n\tapplyEvent: (state: State, event: Event) => State | Promise<State>;\n\t/** The supplied stream begins after the snapshot checkpoint. */\n\teventsStartAfterSnapshot?: boolean;\n}\n\nexport interface ReplayEventsResult<State, Event extends ReplayableAssetEvent = ReplayableAssetEvent> {\n\tstate: State;\n\tappliedEvents: Event[];\n\twarnings: ReplayWarning[];\n\teventCursor: string | null;\n\teventSequence: number;\n\tsubjectSequences: Record<string, number>;\n}\n\nexport async function replayEvents<State, Event extends ReplayableAssetEvent = ReplayableAssetEvent>({\n\tevents,\n\tscope,\n\tinitialState,\n\tsnapshot,\n\tapplyEvent,\n\teventsStartAfterSnapshot = false,\n}: ReplayEventsOptions<State, Event>): Promise<ReplayEventsResult<State, Event>> {\n\tif (eventsStartAfterSnapshot && !snapshot?.eventCursor) {\n\t\tthrow new Error(\"eventsStartAfterSnapshot requires a snapshot with an eventCursor checkpoint.\");\n\t}\n\n\tconst warnings: ReplayWarning[] = [];\n\tconst scopedEvents = filterEventsByScope(await collectEvents(events), scope, warnings);\n\tconst orderedEvents = sortEvents(scopedEvents, isSubjectScoped(scope));\n\tconst uniqueEvents = removeDuplicateEvents(orderedEvents, warnings);\n\tconst initialSubjectSequences = eventsStartAfterSnapshot\n\t\t? snapshotSubjectSequences(snapshot, scope)\n\t\t: undefined;\n\tconst subjectSequences = recordMissingSequenceWarnings(uniqueEvents, warnings, initialSubjectSequences);\n\tconst resumableEvents = applyCursor(\n\t\tuniqueEvents,\n\t\tsnapshot,\n\t\tisSubjectScoped(scope),\n\t\twarnings,\n\t\tinitialSubjectSequences,\n\t\teventsStartAfterSnapshot,\n\t);\n\n\tlet state = snapshot?.snapshotData ?? initialState;\n\tconst appliedEvents: Event[] = [];\n\tlet eventCursor = snapshot?.eventCursor ?? null;\n\tlet eventSequence = snapshot?.eventSequence ?? 0;\n\n\tfor (const event of resumableEvents) {\n\t\tstate = await applyEvent(state, event);\n\t\tappliedEvents.push(event);\n\t\teventCursor = event.id;\n\t\teventSequence = event.sequence;\n\t}\n\n\treturn {\n\t\tstate,\n\t\tappliedEvents,\n\t\twarnings,\n\t\teventCursor,\n\t\teventSequence,\n\t\tsubjectSequences: Object.fromEntries(\n\t\t\t[...subjectSequences.entries()].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0),\n\t\t),\n\t};\n}\n\nasync function collectEvents<Event extends ReplayableAssetEvent>(\n\tevents: Iterable<Event> | AsyncIterable<Event>,\n): Promise<Event[]> {\n\tconst collected: Event[] = [];\n\n\tif (Symbol.asyncIterator in events) {\n\t\tfor await (const event of events) {\n\t\t\tcollected.push(event);\n\t\t}\n\n\t\treturn collected;\n\t}\n\n\tfor (const event of events) {\n\t\tcollected.push(event);\n\t}\n\n\treturn collected;\n}\n\nfunction filterEventsByScope<Event extends ReplayableAssetEvent>(\n\tevents: Event[],\n\tscope: ReplayScope,\n\twarnings: ReplayWarning[],\n): Event[] {\n\tif ((scope.subjectType && !scope.subjectId) || (!scope.subjectType && scope.subjectId)) {\n\t\twarnings.push({\n\t\t\tcode: \"subject_scope_incomplete\",\n\t\t\tmessage: \"Both subjectType and subjectId are required for subject-scoped replay.\",\n\t\t\tsubjectType: scope.subjectType,\n\t\t\tsubjectId: scope.subjectId,\n\t\t});\n\t}\n\n\treturn events.filter((event) => {\n\t\tif (event.tenantId !== scope.tenantId || event.spaceId !== scope.spaceId) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (scope.subjectType && event.subjectType !== scope.subjectType) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (scope.subjectId && event.subjectId !== scope.subjectId) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t});\n}\n\nfunction removeDuplicateEvents<Event extends ReplayableAssetEvent>(\n\tevents: Event[],\n\twarnings: ReplayWarning[],\n): Event[] {\n\tconst seenEventIds = new Set<string>();\n\tconst uniqueEvents: Event[] = [];\n\n\tfor (const event of events) {\n\t\tif (seenEventIds.has(event.id)) {\n\t\t\twarnings.push({\n\t\t\t\tcode: \"duplicate_event\",\n\t\t\t\tmessage: `Duplicate event ${event.id} ignored during replay.`,\n\t\t\t\teventId: event.id,\n\t\t\t\tsubjectType: event.subjectType,\n\t\t\t\tsubjectId: event.subjectId,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tseenEventIds.add(event.id);\n\t\tuniqueEvents.push(event);\n\t}\n\n\treturn uniqueEvents;\n}\n\nfunction recordMissingSequenceWarnings<Event extends ReplayableAssetEvent>(\n\tevents: Event[],\n\twarnings: ReplayWarning[],\n\tinitialSequences?: ReadonlyMap<string, number>,\n): Map<string, number> {\n\tconst lastSequenceBySubject = new Map(initialSequences);\n\n\tfor (const event of events) {\n\t\tconst subjectKey = subjectSequenceKey(event.subjectType, event.subjectId);\n\t\tconst previousSequence = lastSequenceBySubject.get(subjectKey);\n\t\tconst sequence = event.subjectSequence ?? event.sequence;\n\t\tconst expectedSequence = previousSequence === undefined ? sequence : previousSequence + 1;\n\n\t\t// A ledger sequence orders the complete tenant/space stream. A projection\n\t\t// filters that stream by event type and often by subject, so gaps in it do\n\t\t// not prove event loss. Only an explicit subject-local sequence can make\n\t\t// that guarantee.\n\t\tif (\n\t\t\tevent.subjectSequence !== undefined &&\n\t\t\tpreviousSequence !== undefined &&\n\t\t\tsequence > expectedSequence\n\t\t) {\n\t\t\twarnings.push({\n\t\t\t\tcode: \"missing_sequence\",\n\t\t\t\tmessage: `Missing event sequence for ${subjectKey}: expected ${expectedSequence}, received ${sequence}.`,\n\t\t\t\teventId: event.id,\n\t\t\t\tsubjectType: event.subjectType,\n\t\t\t\tsubjectId: event.subjectId,\n\t\t\t\texpectedSequence,\n\t\t\t\tactualSequence: sequence,\n\t\t\t});\n\t\t}\n\n\t\tlastSequenceBySubject.set(subjectKey, Math.max(previousSequence ?? sequence, sequence));\n\t}\n\treturn lastSequenceBySubject;\n}\n\nfunction applyCursor<Event extends ReplayableAssetEvent>(\n\tevents: Event[],\n\tsnapshot: ReplaySnapshot | null | undefined,\n\tsubjectScoped: boolean,\n\twarnings: ReplayWarning[],\n\tinitialSubjectSequences?: ReadonlyMap<string, number>,\n\teventsStartAfterSnapshot = false,\n): Event[] {\n\tconst eventCursor = snapshot?.eventCursor;\n\n\tif (eventCursor && !eventsStartAfterSnapshot) {\n\t\tconst cursorIndex = events.findIndex((event) => event.id === eventCursor);\n\n\t\tif (cursorIndex >= 0) {\n\t\t\treturn events.slice(cursorIndex + 1);\n\t\t}\n\n\t\twarnings.push({\n\t\t\tcode: \"cursor_not_found\",\n\t\t\tmessage: `Snapshot cursor ${eventCursor} was not found in the scoped event stream.`,\n\t\t\teventId: eventCursor,\n\t\t});\n\t}\n\n\tif (initialSubjectSequences?.size) {\n\t\treturn events.filter((event) =>\n\t\t\t(event.subjectSequence ?? event.sequence) >\n\t\t\t(initialSubjectSequences.get(subjectSequenceKey(event.subjectType, event.subjectId)) ?? -1),\n\t\t);\n\t}\n\n\tif (subjectScoped && snapshot?.eventSequence !== undefined && snapshot.eventSequence !== null) {\n\t\treturn events.filter((event) => event.sequence > snapshot.eventSequence!);\n\t}\n\n\treturn events;\n}\n\nfunction snapshotSubjectSequences(\n\tsnapshot: ReplaySnapshot | null | undefined,\n\tscope: ReplayScope,\n): Map<string, number> {\n\tconst sequences = new Map(Object.entries(snapshot?.subjectSequences ?? {}));\n\tif (\n\t\tsequences.size === 0 &&\n\t\tscope.subjectType &&\n\t\tscope.subjectId &&\n\t\tsnapshot?.eventSequence !== undefined &&\n\t\tsnapshot.eventSequence !== null\n\t) {\n\t\tsequences.set(subjectSequenceKey(scope.subjectType, scope.subjectId), snapshot.eventSequence);\n\t}\n\treturn sequences;\n}\n\nfunction subjectSequenceKey(subjectType: string, subjectId: string): string {\n\treturn `${subjectType}:${subjectId}`;\n}\n\nfunction sortEvents<Event extends ReplayableAssetEvent>(events: Event[], subjectScoped: boolean): Event[] {\n\treturn [...events].sort((first, second) =>\n\t\tsubjectScoped ? compareSubjectEvents(first, second) : compareGlobalEvents(first, second),\n\t);\n}\n\nfunction compareSubjectEvents(first: ReplayableAssetEvent, second: ReplayableAssetEvent): number {\n\treturn compareValues(\n\t\t[first.subjectSequence ?? first.sequence, toTimestamp(first.recordedAt), toTimestamp(first.occurredAt), first.id],\n\t\t[second.subjectSequence ?? second.sequence, toTimestamp(second.recordedAt), toTimestamp(second.occurredAt), second.id],\n\t);\n}\n\nfunction compareGlobalEvents(first: ReplayableAssetEvent, second: ReplayableAssetEvent): number {\n\treturn compareValues(\n\t\t[\n\t\t\ttoTimestamp(first.recordedAt),\n\t\t\ttoTimestamp(first.occurredAt),\n\t\t\tfirst.actionInvocationId,\n\t\t\tfirst.correlationId,\n\t\t\tfirst.subjectType,\n\t\t\tfirst.subjectId,\n\t\t\tfirst.sequence,\n\t\t\tfirst.id,\n\t\t],\n\t\t[\n\t\t\ttoTimestamp(second.recordedAt),\n\t\t\ttoTimestamp(second.occurredAt),\n\t\t\tsecond.actionInvocationId,\n\t\t\tsecond.correlationId,\n\t\t\tsecond.subjectType,\n\t\t\tsecond.subjectId,\n\t\t\tsecond.sequence,\n\t\t\tsecond.id,\n\t\t],\n\t);\n}\n\nfunction compareValues(firstValues: Array<number | string>, secondValues: Array<number | string>): number {\n\tfor (const [index, firstValue] of firstValues.entries()) {\n\t\tconst secondValue = secondValues[index];\n\n\t\tif (firstValue < secondValue) {\n\t\t\treturn -1;\n\t\t}\n\n\t\tif (firstValue > secondValue) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n\nfunction isSubjectScoped(scope: ReplayScope): boolean {\n\treturn Boolean(scope.subjectType && scope.subjectId);\n}\n\nfunction toTimestamp(value: Date | string): number {\n\treturn value instanceof Date ? value.getTime() : new Date(value).getTime();\n}\n"]}
@@ -43,5 +43,5 @@ function createActionRegistry(definitions = []) {
43
43
  }
44
44
 
45
45
  export { ACTOR_TYPES, assertActionId, assertActorType, createActionRegistry, isActorType };
46
- //# sourceMappingURL=chunk-2W6FORTE.js.map
47
- //# sourceMappingURL=chunk-2W6FORTE.js.map
46
+ //# sourceMappingURL=chunk-OZWUNGJE.js.map
47
+ //# sourceMappingURL=chunk-OZWUNGJE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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AAA,CAAW,QAAA,EAAU,UAAU,CAAA;AAAA,EAC5C,CAAA;AACA,EAAA,KAAA,MAAW,UAAA,IAAc,WAAA,EAAa,QAAA,CAAS,UAAU,CAAA;AACzD,EAAA,OAAO;AAAA,IACN,QAAA;AAAA,IACA,kBAAkB,UAAA,EAAY;AAC7B,MAAA,IAAI,CAAC,OAAA,CAAQ,GAAA,CAAI,WAAW,QAAQ,CAAA,WAAY,UAAU,CAAA;AAAA,IAC3D,CAAA;AAAA,IACA,OAAA,EAAS,CAAC,QAAA,KAAa,OAAA,CAAQ,IAAI,QAAQ,CAAA;AAAA,IAC3C,GAAA,EAAK,CAAC,QAAA,KAAmC,OAAA,CAAQ,IAAI,QAAoB,CAAA;AAAA,IACzE,KAAK,MAAM,KAAA,CAAM,IAAA,CAAK,OAAA,CAAQ,MAAM;AAAA,GACrC;AACD","file":"chunk-OZWUNGJE.js","sourcesContent":["import type { SurfaceDeclaration } from \"../discovery\";\nexport type ActionId = `${string}.${string}`;\n\nexport interface SchemaParseIssue {\n\tpath: PropertyKey[];\n\tmessage: string;\n}\n\nexport type SchemaParseResult<T = unknown> =\n\t| { success: true; data: T }\n\t| { success: false; error: { issues: SchemaParseIssue[] } };\n\nexport interface SchemaValidator<T = unknown> {\n\tparse(input: unknown): T;\n\tsafeParse(input: unknown): SchemaParseResult<T>;\n}\n\nexport type ActorType =\n\t| \"natural_person\"\n\t| \"agent\"\n\t| \"system\"\n\t| \"service_account\"\n\t| \"external_system\"\n\t| \"integration\";\n\nexport const ACTOR_TYPES: readonly ActorType[] = [\n\t\"natural_person\",\n\t\"agent\",\n\t\"system\",\n\t\"service_account\",\n\t\"external_system\",\n\t\"integration\",\n] as const;\n\nexport function isActorType(value: string): value is ActorType {\n\treturn (ACTOR_TYPES as readonly string[]).includes(value);\n}\n\nexport function assertActorType(value: string): asserts value is ActorType {\n\tif (!isActorType(value)) {\n\t\tthrow new Error(`Invalid actorType: ${value}`);\n\t}\n}\n\nexport type ActionStatus =\n\t| \"pending\"\n\t| \"running\"\n\t| \"completed\"\n\t| \"failed\"\n\t| \"blocked_by_policy\"\n\t| \"waiting_for_approval\"\n\t| \"reconciliation_required\"\n\t| \"validation_failed\";\n\nexport interface FabricRuntimeServices {\n\treadonly [serviceName: string]: unknown;\n}\n\nexport interface ActionContext<TDb = unknown> {\n\tactionInvocationId: string;\n\ttenantId: string;\n\tspaceId: string;\n\tactorId: string;\n\tactorType: ActorType;\n\tcorrelationId: string;\n\tcausationId?: string;\n\tprovenance?: { source: string; auditAttributes?: Record<string, string> };\n\tdb: TDb;\n\tservices?: FabricRuntimeServices;\n}\n\nexport interface ActionResult {\n\tsuccess: boolean;\n\tdata?: Record<string, unknown>;\n\terror?: string;\n}\n\nexport type ActionHandler<TDb = unknown> = (\n\tctx: ActionContext<TDb>,\n\tparams: unknown,\n) => Promise<ActionResult>;\n\nexport interface AdapterStepRetryPolicy {\n\tidempotent: boolean;\n\tmaxAttempts?: number;\n\tinitialDelayMs?: number;\n\tbackoffMultiplier?: number;\n\tmaxDelayMs?: number;\n}\n\nexport interface AdapterStep {\n\tadapterType: string;\n\toperation: string;\n\tretryPolicy?: AdapterStepRetryPolicy;\n\tgetInput: (\n\t\tparams: unknown,\n\t\thandlerResult: Record<string, unknown>,\n\t) => Record<string, unknown> | undefined;\n}\n\nexport interface ActionStateMachineBinding {\n\tentityType: string;\n\ttargetState: string | ((params: unknown) => string);\n\tgetEntityId: (params: unknown) => string | undefined;\n}\n\nexport interface ActionDefinition<TDb = unknown> extends SurfaceDeclaration {\n\tactionId: ActionId;\n\tnamespace: string;\n\tversion: number;\n\tschema: SchemaValidator;\n\t/** Optional validation contract for the public handler result data. */\n\tresultSchema?: SchemaValidator;\n\thandler?: ActionHandler<TDb>;\n\trequiredRoles?: string[];\n\trequiredPermissions?: string[];\n\tpolicies?: `${string}.v${number}`[];\n\temitsEvents: string[];\n\tidempotent: boolean;\n\tmutatesDomain: boolean;\n\t/** Portable execution semantics used by hosts, gateways, and generated capability contracts. */\n\texecution?: ActionExecutionContract;\n\tstateMachine?: ActionStateMachineBinding;\n\tadapterSteps?: AdapterStep[];\n\t/** Completion actions can attest only after all external adapter work succeeds. */\n\teventPhase?: \"before_adapters\" | \"after_adapters\";\n\t/**\n\t * If \"saga\", the action is a multi-step orchestration. The worker dispatches\n\t * to a registered saga implementation instead of running `handler` directly.\n\t */\n\tkind?: \"atomic\" | \"saga\";\n}\n\nexport type ActionConnectivity = \"online-required\" | \"offline-capturable\";\nexport type AuthorityMoment = \"capture\" | \"execution\" | \"both\";\nexport type ActionIdempotencyStance = \"required\" | \"supported\" | \"prohibited\";\nexport type ActionCompletionMode = \"immediate\" | \"accepted\" | \"long-running\";\nexport type ActionConsistency = \"authoritative-now\" | \"provisional-until-reconciled\";\nexport type ActionDataSensitivity = \"public\" | \"internal\" | \"confidential\" | \"restricted\";\n\nexport interface ActionExecutionContract {\n\tconnectivity: ActionConnectivity;\n\tauthorityMoment: AuthorityMoment;\n\tidempotency: ActionIdempotencyStance;\n\t/**\n\t * `immediate`: the invocation settles within the host's execution.\n\t * `accepted` and `long-running`: an adapter may hand the work to an\n\t * external system and the invocation stays running until that system\n\t * completes it by reference through the host's completion ingress.\n\t * Declare `completionDeadlineMs` on a `long-running` action so a callback\n\t * that never comes is noticed rather than waited on forever.\n\t */\n\tcompletion: ActionCompletionMode;\n\t/**\n\t * How long an accepted handoff may wait for its completion before the host\n\t * moves the invocation to reconciliation. Without it, nothing sweeps the\n\t * handoff. Refused on `immediate`, since nothing external completes it.\n\t */\n\tcompletionDeadlineMs?: number;\n\tconsistency: ActionConsistency;\n\tsensitivity?: ActionDataSensitivity;\n}\n\nexport interface SagaContext {\n\tactionInvocationId: string;\n\ttenantId: string;\n\tspaceId: string;\n\tparameters: unknown;\n\tsleep?: (delayMs: number) => Promise<void>;\n\tquery?: <T = unknown>(model: string, operation: string, args: unknown) => Promise<T>;\n\t/**\n\t * Wait for a named external signal carrying a payload of `T`, with a timeout.\n\t *\n\t * Resolves with the payload of the first signal received, or `null` if the timeout\n\t * fires first. Subsequent signals with the same name received before another\n\t * `awaitSignal` call are buffered (FIFO) so no signal is lost.\n\t *\n\t * Intended for agent-driven and webhook-driven coordination: replace polling loops\n\t * with push-based wakeups while preserving the saga's deterministic replay\n\t * semantics (the runtime is responsible for capturing signals into workflow history).\n\t *\n\t * Optional. Runtimes that cannot implement push-based signaling (e.g. an in-memory\n\t * test harness) may omit this; sagas should treat absence as a fallback condition\n\t * and use `sleep` + `query` polling instead.\n\t *\n\t * Signal *senders* are runtime-specific (e.g. a Temporal `WorkflowClient.signal()`\n\t * call from an action handler). Apps that need to send signals from action\n\t * handlers should expose a coordination service via `ActionContext.services`\n\t * — the platform does not prescribe the sender API.\n\t *\n\t * @example\n\t * const payload = await ctx.awaitSignal?.<{ result: Record<string, unknown> }>(\n\t * \"userInputProcessed\",\n\t * 5 * 60 * 1000,\n\t * );\n\t * if (payload) { /* handle pushed result *\\/ }\n\t * else { /* timeout — fall back to deterministic path *\\/ }\n\t */\n\tawaitSignal?: <T = unknown>(signalName: string, timeoutMs: number) => Promise<T | null>;\n}\n\nexport interface SagaChildActionInput {\n\tsuffix: string;\n\tactionId: string;\n\tparameters: Record<string, unknown>;\n}\n\nexport type SagaRunChild = (input: SagaChildActionInput) => Promise<Record<string, unknown>>;\n\nexport interface SagaCompletionEvent {\n\teventType: string;\n\tsubjectType: string;\n\tsubjectId: string;\n\tpayload: unknown;\n\teventSchemaVersion?: number;\n}\n\nexport interface SagaCompletion {\n\tresultData: Record<string, unknown>;\n\tevent?: SagaCompletionEvent;\n}\n\nexport type SagaImplementation = (\n\tctx: SagaContext,\n\trunChild: SagaRunChild,\n) => Promise<SagaCompletion>;\n\nexport function assertActionId(actionId: string): asserts actionId is ActionId {\n\tif (!/^[a-z][a-z0-9-]*\\.[a-z][a-z0-9_]*$/.test(actionId)) {\n\t\tthrow new Error(`Invalid action ID: ${actionId}`);\n\t}\n}\n\nexport interface ActionRegistry<TDb = unknown> {\n\tregister(definition: ActionDefinition<TDb>): void;\n\tregisterIfMissing(definition: ActionDefinition<TDb>): void;\n\tresolve(actionId: ActionId): ActionDefinition<TDb> | undefined;\n\thas(actionId: string): actionId is ActionId;\n\tids(): ActionId[];\n}\n\nexport function createActionRegistry<TDb = unknown>(definitions: readonly ActionDefinition<TDb>[] = []): ActionRegistry<TDb> {\n\tconst actions = new Map<ActionId, ActionDefinition<TDb>>();\n\tconst register = (definition: ActionDefinition<TDb>): void => {\n\t\tassertActionId(definition.actionId);\n\t\tif (actions.has(definition.actionId)) throw new Error(`Action \"${definition.actionId}\" is already registered`);\n\t\tif (definition.mutatesDomain && definition.emitsEvents.length === 0) {\n\t\t\tthrow new Error(`Action \"${definition.actionId}\" mutates domain but emits no events. Every mutating action must emit at least one AssetEvent.`);\n\t\t}\n\t\tactions.set(definition.actionId, definition);\n\t};\n\tfor (const definition of definitions) register(definition);\n\treturn {\n\t\tregister,\n\t\tregisterIfMissing(definition) {\n\t\t\tif (!actions.has(definition.actionId)) register(definition);\n\t\t},\n\t\tresolve: (actionId) => actions.get(actionId),\n\t\thas: (actionId): actionId is ActionId => actions.has(actionId as ActionId),\n\t\tids: () => Array.from(actions.keys()),\n\t};\n}\n"]}