@fabricorg/platform 0.10.0 → 0.11.1

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 (61) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +8 -1
  3. package/dist/actions/index.cjs +11 -11
  4. package/dist/actions/index.d.cts +2 -0
  5. package/dist/actions/index.d.ts +2 -0
  6. package/dist/actions/index.js +1 -1
  7. package/dist/{chunk-JSTGOT6P.js → chunk-3WEHM2P3.cjs} +75 -3
  8. package/dist/chunk-3WEHM2P3.cjs.map +1 -0
  9. package/dist/chunk-4MMMXV4Q.js +135 -0
  10. package/dist/chunk-4MMMXV4Q.js.map +1 -0
  11. package/dist/{chunk-Q3WYIWCN.cjs → chunk-FN6IYVBK.js} +67 -5
  12. package/dist/chunk-FN6IYVBK.js.map +1 -0
  13. package/dist/{chunk-BWNPGRRV.cjs → chunk-HLRIXNVG.cjs} +2 -2
  14. package/dist/chunk-HLRIXNVG.cjs.map +1 -0
  15. package/dist/{chunk-54EQTOH6.cjs → chunk-JIT3UR27.cjs} +77 -10
  16. package/dist/chunk-JIT3UR27.cjs.map +1 -0
  17. package/dist/{chunk-4SMPJPJ6.js → chunk-JM55UQWK.js} +2 -2
  18. package/dist/chunk-JM55UQWK.js.map +1 -0
  19. package/dist/chunk-K27DUWRY.cjs +377 -0
  20. package/dist/chunk-K27DUWRY.cjs.map +1 -0
  21. package/dist/{chunk-N72WJ4AU.js → chunk-N3OUWEYA.js} +73 -8
  22. package/dist/chunk-N3OUWEYA.js.map +1 -0
  23. package/dist/chunk-NFHS5NWD.js +369 -0
  24. package/dist/chunk-NFHS5NWD.js.map +1 -0
  25. package/dist/chunk-OC4ZFJKD.cjs +141 -0
  26. package/dist/chunk-OC4ZFJKD.cjs.map +1 -0
  27. package/dist/index.cjs +67 -31
  28. package/dist/index.d.cts +4 -4
  29. package/dist/index.d.ts +4 -4
  30. package/dist/index.js +5 -5
  31. package/dist/manifest/index.cjs +17 -8
  32. package/dist/manifest/index.d.cts +39 -3
  33. package/dist/manifest/index.d.ts +39 -3
  34. package/dist/manifest/index.js +5 -4
  35. package/dist/modules/index.cjs +11 -10
  36. package/dist/modules/index.d.cts +49 -1
  37. package/dist/modules/index.d.ts +49 -1
  38. package/dist/modules/index.js +4 -3
  39. package/dist/objects/index.cjs +9 -5
  40. package/dist/objects/index.d.cts +58 -1
  41. package/dist/objects/index.d.ts +58 -1
  42. package/dist/objects/index.js +1 -1
  43. package/dist/projections/index.cjs +26 -2
  44. package/dist/projections/index.d.cts +38 -2
  45. package/dist/projections/index.d.ts +38 -2
  46. package/dist/projections/index.js +1 -1
  47. package/package.json +1 -1
  48. package/dist/chunk-35DD3H55.js +0 -187
  49. package/dist/chunk-35DD3H55.js.map +0 -1
  50. package/dist/chunk-4SMPJPJ6.js.map +0 -1
  51. package/dist/chunk-54EQTOH6.cjs.map +0 -1
  52. package/dist/chunk-BWNPGRRV.cjs.map +0 -1
  53. package/dist/chunk-I35B576X.js +0 -30
  54. package/dist/chunk-I35B576X.js.map +0 -1
  55. package/dist/chunk-JSTGOT6P.js.map +0 -1
  56. package/dist/chunk-N72WJ4AU.js.map +0 -1
  57. package/dist/chunk-Q3WYIWCN.cjs.map +0 -1
  58. package/dist/chunk-QETQGAXJ.cjs +0 -35
  59. package/dist/chunk-QETQGAXJ.cjs.map +0 -1
  60. package/dist/chunk-SSYKDXR4.cjs +0 -195
  61. package/dist/chunk-SSYKDXR4.cjs.map +0 -1
@@ -1,9 +1,30 @@
1
1
  'use strict';
2
2
 
3
- var chunkSSYKDXR4_cjs = require('./chunk-SSYKDXR4.cjs');
3
+ var chunkK27DUWRY_cjs = require('./chunk-K27DUWRY.cjs');
4
4
 
5
5
  // manifest/index.ts
6
- var MODULE_MANIFEST_VERSION = 1;
6
+ var MODULE_MANIFEST_VERSION = 2;
7
+ function normalizeModuleManifest(manifest) {
8
+ const version = manifest.manifestVersion;
9
+ if (version !== 1 && version !== MODULE_MANIFEST_VERSION) {
10
+ throw new Error(`Unsupported module manifest version: ${String(version)}`);
11
+ }
12
+ return {
13
+ ...manifest,
14
+ manifestVersion: MODULE_MANIFEST_VERSION,
15
+ views: "views" in manifest && Array.isArray(manifest.views) ? manifest.views : []
16
+ };
17
+ }
18
+ function normalizeModuleManifestBundle(bundle) {
19
+ const version = bundle.manifestVersion;
20
+ if (version !== 1 && version !== MODULE_MANIFEST_VERSION) {
21
+ throw new Error(`Unsupported module manifest bundle version: ${String(version)}`);
22
+ }
23
+ return {
24
+ manifestVersion: MODULE_MANIFEST_VERSION,
25
+ modules: bundle.modules.map((manifest) => normalizeModuleManifest(manifest))
26
+ };
27
+ }
7
28
  function isJsonSchemaExportableValidator(schema) {
8
29
  return typeof schema.toJSONSchema === "function";
9
30
  }
@@ -11,7 +32,7 @@ function isRecord(value) {
11
32
  return value !== null && typeof value === "object" && !Array.isArray(value);
12
33
  }
13
34
  function exportDependency(dependency) {
14
- const namespace = chunkSSYKDXR4_cjs.getModuleDependencyNamespace(dependency);
35
+ const namespace = chunkK27DUWRY_cjs.getModuleDependencyNamespace(dependency);
15
36
  if (typeof dependency === "string") {
16
37
  return { namespace };
17
38
  }
@@ -24,17 +45,34 @@ function exportObjectType(objectType) {
24
45
  if (typeof objectType === "string") {
25
46
  return { type: objectType };
26
47
  }
27
- const normalized = { type: chunkSSYKDXR4_cjs.getObjectTypeName(objectType) };
48
+ const normalized = { type: chunkK27DUWRY_cjs.getObjectTypeName(objectType) };
28
49
  if (objectType.displayName !== void 0) normalized.displayName = objectType.displayName;
29
50
  if (objectType.idPrefix !== void 0) normalized.idPrefix = objectType.idPrefix;
51
+ if (objectType.schema !== void 0) normalized.schema = cloneJson(objectType.schema);
52
+ if (objectType.semantics !== void 0) normalized.semantics = cloneJson(objectType.semantics);
53
+ if (objectType.relations !== void 0) {
54
+ normalized.relations = objectType.relations.map((relation) => ({ ...relation }));
55
+ }
56
+ if (objectType.invariants !== void 0) {
57
+ normalized.invariants = objectType.invariants.map((invariant) => ({ ...invariant }));
58
+ }
30
59
  return normalized;
31
60
  }
61
+ function cloneJson(value) {
62
+ if (Array.isArray(value)) return value.map((item) => cloneJson(item));
63
+ if (value !== null && typeof value === "object") {
64
+ return Object.fromEntries(
65
+ Object.entries(value).map(([key, child]) => [key, cloneJson(child)])
66
+ );
67
+ }
68
+ return value;
69
+ }
32
70
  function exportEventType(eventType) {
33
71
  if (typeof eventType === "string") {
34
72
  return { eventType, schemaVersion: 1 };
35
73
  }
36
74
  const normalized = {
37
- eventType: chunkSSYKDXR4_cjs.getEventTypeName(eventType),
75
+ eventType: chunkK27DUWRY_cjs.getEventTypeName(eventType),
38
76
  schemaVersion: eventType.schemaVersion
39
77
  };
40
78
  if (eventType.description !== void 0) normalized.description = eventType.description;
@@ -56,8 +94,18 @@ function exportAction(action) {
56
94
  }
57
95
  if (action.eventPhase !== void 0) manifest.eventPhase = action.eventPhase;
58
96
  if (isJsonSchemaExportableValidator(action.schema)) {
59
- manifest.parameterSchema = action.schema.toJSONSchema();
60
- manifest.parameterSchemaFormat = "json-schema";
97
+ try {
98
+ manifest.parameterSchema = action.schema.toJSONSchema();
99
+ manifest.parameterSchemaFormat = "json-schema";
100
+ } catch {
101
+ }
102
+ }
103
+ if (action.resultSchema && isJsonSchemaExportableValidator(action.resultSchema)) {
104
+ try {
105
+ manifest.resultSchema = action.resultSchema.toJSONSchema();
106
+ manifest.resultSchemaFormat = "json-schema";
107
+ } catch {
108
+ }
61
109
  }
62
110
  if (action.stateMachine !== void 0) {
63
111
  const binding = {
@@ -129,6 +177,21 @@ function exportStateMachine(machine) {
129
177
  }))
130
178
  };
131
179
  }
180
+ function exportView(view) {
181
+ const output = {
182
+ name: view.name,
183
+ version: view.version,
184
+ shape: cloneJson(view.shape),
185
+ consumes: view.consumes.map((consumption) => ({
186
+ eventType: consumption.eventType,
187
+ schemaVersions: [...consumption.schemaVersions]
188
+ })),
189
+ scope: view.scope,
190
+ snapshotVersion: view.snapshotVersion
191
+ };
192
+ if (view.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];
193
+ return output;
194
+ }
132
195
  function exportModuleManifest(module) {
133
196
  const manifest = {
134
197
  manifestVersion: MODULE_MANIFEST_VERSION,
@@ -143,11 +206,13 @@ function exportModuleManifest(module) {
143
206
  eventTypes: (module.eventTypes ?? []).map(exportEventType),
144
207
  actions: (module.actions ?? []).map(exportAction),
145
208
  policies: (module.policies ?? []).map(exportPolicy).filter((policy) => policy !== void 0),
146
- stateMachines: (module.stateMachines ?? []).map(exportStateMachine).filter((machine) => machine !== void 0)
209
+ stateMachines: (module.stateMachines ?? []).map(exportStateMachine).filter((machine) => machine !== void 0),
210
+ views: (module.views ?? []).map(exportView)
147
211
  };
148
212
  if (module.version !== void 0) manifest.version = module.version;
149
213
  if (module.displayName !== void 0) manifest.displayName = module.displayName;
150
214
  if (module.description !== void 0) manifest.description = module.description;
215
+ if (module.capability !== void 0) manifest.capability = cloneJson(module.capability);
151
216
  return manifest;
152
217
  }
153
218
  function exportModuleManifestBundle(modules) {
@@ -161,5 +226,7 @@ exports.MODULE_MANIFEST_VERSION = MODULE_MANIFEST_VERSION;
161
226
  exports.exportModuleManifest = exportModuleManifest;
162
227
  exports.exportModuleManifestBundle = exportModuleManifestBundle;
163
228
  exports.isJsonSchemaExportableValidator = isJsonSchemaExportableValidator;
164
- //# sourceMappingURL=chunk-54EQTOH6.cjs.map
165
- //# sourceMappingURL=chunk-54EQTOH6.cjs.map
229
+ exports.normalizeModuleManifest = normalizeModuleManifest;
230
+ exports.normalizeModuleManifestBundle = normalizeModuleManifestBundle;
231
+ //# sourceMappingURL=chunk-JIT3UR27.cjs.map
232
+ //# sourceMappingURL=chunk-JIT3UR27.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../manifest/index.ts"],"names":["getModuleDependencyNamespace","getObjectTypeName","getEventTypeName"],"mappings":";;;;;AA6BO,IAAM,uBAAA,GAA0B;AA8JhC,SAAS,wBACf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QAAA,EAAA,CAAW,MAAA,CAAO,QAAA,IAAY,EAAC,EAC7B,GAAA,CAAI,YAAY,CAAA,CAChB,MAAA,CAAO,CAAC,MAAA,KAA2C,MAAA,KAAW,MAAS,CAAA;AAAA,IACzE,aAAA,EAAA,CAAgB,MAAA,CAAO,aAAA,IAAiB,EAAC,EACvC,GAAA,CAAI,kBAAkB,CAAA,CACtB,MAAA,CAAO,CAAC,OAAA,KAAmD,OAAA,KAAY,MAAS,CAAA;AAAA,IAClF,QAAQ,MAAA,CAAO,KAAA,IAAS,EAAC,EAAG,IAAI,UAAU;AAAA,GAC3C;AAEA,EAAA,IAAI,MAAA,CAAO,OAAA,KAAY,MAAA,EAAW,QAAA,CAAS,UAAU,MAAA,CAAO,OAAA;AAC5D,EAAA,IAAI,MAAA,CAAO,WAAA,KAAgB,MAAA,EAAW,QAAA,CAAS,cAAc,MAAA,CAAO,WAAA;AACpE,EAAA,IAAI,MAAA,CAAO,WAAA,KAAgB,MAAA,EAAW,QAAA,CAAS,cAAc,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-JIT3UR27.cjs","sourcesContent":["import type {\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}\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 {\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\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 {\n\tname: string;\n\tversion: string;\n\tshape: PortableJsonSchema;\n\tconsumes: Array<{ eventType: string; schemaVersions: number[] }>;\n\tscope: \"tenant-space\";\n\tsnapshotVersion: number;\n\tcompatibleSnapshotVersions?: number[];\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\treturn {\n\t\t...manifest,\n\t\tmanifestVersion: MODULE_MANIFEST_VERSION,\n\t\tviews: \"views\" in manifest && Array.isArray(manifest.views) ? manifest.views : [],\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\treturn normalized;\n}\n\nfunction exportAction(action: ActionDefinition): ModuleManifestAction {\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.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\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\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.compatibleSnapshotVersions) output.compatibleSnapshotVersions = [...view.compatibleSnapshotVersions];\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"]}
@@ -55,5 +55,5 @@ function registerActionIfMissing(definition) {
55
55
  }
56
56
 
57
57
  export { ACTOR_TYPES, assertActionId, assertActorType, getRegisteredActionIds, isActorType, isRegisteredActionId, registerAction, registerActionIfMissing, resolveAction, resolveRegisteredAction };
58
- //# sourceMappingURL=chunk-4SMPJPJ6.js.map
59
- //# sourceMappingURL=chunk-4SMPJPJ6.js.map
58
+ //# sourceMappingURL=chunk-JM55UQWK.js.map
59
+ //# sourceMappingURL=chunk-JM55UQWK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../actions/index.ts"],"names":[],"mappings":";AAwBO,IAAM,WAAA,GAAoC;AAAA,EAChD,gBAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,iBAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACD;AAEO,SAAS,YAAY,KAAA,EAAmC;AAC9D,EAAA,OAAQ,WAAA,CAAkC,SAAS,KAAK,CAAA;AACzD;AAEO,SAAS,gBAAgB,KAAA,EAA2C;AAC1E,EAAA,IAAI,CAAC,WAAA,CAAY,KAAK,CAAA,EAAG;AACxB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mBAAA,EAAsB,KAAK,CAAA,CAAE,CAAA;AAAA,EAC9C;AACD;AAuJA,IAAM,QAAA,uBAAe,GAAA,EAAgC;AAE9C,SAAS,eAAe,QAAA,EAAgD;AAC9E,EAAA,IAAI,CAAC,oCAAA,CAAqC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACzD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mBAAA,EAAsB,QAAQ,CAAA,CAAE,CAAA;AAAA,EACjD;AACD;AAEO,SAAS,eAAe,UAAA,EAAoC;AAClE,EAAA,cAAA,CAAe,WAAW,QAAQ,CAAA;AAElC,EAAA,IAAI,QAAA,CAAS,GAAA,CAAI,UAAA,CAAW,QAAQ,CAAA,EAAG;AACtC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,UAAA,CAAW,QAAQ,CAAA,uBAAA,CAAyB,CAAA;AAAA,EACxE;AAEA,EAAA,IAAI,UAAA,CAAW,aAAA,IAAiB,UAAA,CAAW,WAAA,CAAY,WAAW,CAAA,EAAG;AACpE,IAAA,MAAM,IAAI,KAAA;AAAA,MACT,CAAA,QAAA,EAAW,WAAW,QAAQ,CAAA,8FAAA;AAAA,KAE/B;AAAA,EACD;AAEA,EAAA,QAAA,CAAS,GAAA,CAAI,UAAA,CAAW,QAAA,EAAU,UAAU,CAAA;AAC7C;AAEO,SAAS,cAAc,QAAA,EAAkD;AAC/E,EAAA,OAAO,QAAA,CAAS,IAAI,QAAQ,CAAA;AAC7B;AAEO,SAAS,qBAAqB,QAAA,EAAwC;AAC5E,EAAA,OAAO,QAAA,CAAS,IAAI,QAAoB,CAAA;AACzC;AAEO,SAAS,wBAAwB,QAAA,EAAgD;AACvF,EAAA,IAAI,CAAC,oBAAA,CAAqB,QAAQ,CAAA,EAAG;AACpC,IAAA,OAAO,MAAA;AAAA,EACR;AAEA,EAAA,OAAO,cAAc,QAAQ,CAAA;AAC9B;AAEO,SAAS,sBAAA,GAAqC;AACpD,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,QAAA,CAAS,IAAA,EAAM,CAAA;AAClC;AAEO,SAAS,wBAAwB,UAAA,EAAoC;AAC3E,EAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,UAAA,CAAW,QAAQ,CAAA,EAAG;AACvC,IAAA,cAAA,CAAe,UAAU,CAAA;AAAA,EAC1B;AACD","file":"chunk-JM55UQWK.js","sourcesContent":["export 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| \"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\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> {\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\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 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\nconst registry = new Map<ActionId, ActionDefinition>();\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 function registerAction(definition: ActionDefinition): void {\n\tassertActionId(definition.actionId);\n\n\tif (registry.has(definition.actionId)) {\n\t\tthrow new Error(`Action \"${definition.actionId}\" is already registered`);\n\t}\n\n\tif (definition.mutatesDomain && definition.emitsEvents.length === 0) {\n\t\tthrow new Error(\n\t\t\t`Action \"${definition.actionId}\" mutates domain but emits no events. ` +\n\t\t\t\t`Every mutating action must emit at least one AssetEvent.`,\n\t\t);\n\t}\n\n\tregistry.set(definition.actionId, definition);\n}\n\nexport function resolveAction(actionId: ActionId): ActionDefinition | undefined {\n\treturn registry.get(actionId);\n}\n\nexport function isRegisteredActionId(actionId: string): actionId is ActionId {\n\treturn registry.has(actionId as ActionId);\n}\n\nexport function resolveRegisteredAction(actionId: string): ActionDefinition | undefined {\n\tif (!isRegisteredActionId(actionId)) {\n\t\treturn undefined;\n\t}\n\n\treturn resolveAction(actionId);\n}\n\nexport function getRegisteredActionIds(): ActionId[] {\n\treturn Array.from(registry.keys());\n}\n\nexport function registerActionIfMissing(definition: ActionDefinition): void {\n\tif (!registry.has(definition.actionId)) {\n\t\tregisterAction(definition);\n\t}\n}\n"]}
@@ -0,0 +1,377 @@
1
+ 'use strict';
2
+
3
+ var chunkOC4ZFJKD_cjs = require('./chunk-OC4ZFJKD.cjs');
4
+ var chunkNJL3US7H_cjs = require('./chunk-NJL3US7H.cjs');
5
+ var chunk3WEHM2P3_cjs = require('./chunk-3WEHM2P3.cjs');
6
+ var chunkUV252FLT_cjs = require('./chunk-UV252FLT.cjs');
7
+ var chunkHLRIXNVG_cjs = require('./chunk-HLRIXNVG.cjs');
8
+ var chunkEO4VSB2O_cjs = require('./chunk-EO4VSB2O.cjs');
9
+ var chunkJAXDEK5Z_cjs = require('./chunk-JAXDEK5Z.cjs');
10
+
11
+ // modules/index.ts
12
+ var registeredModuleNamespaces = /* @__PURE__ */ new Set();
13
+ var registeredQualifiedObjectTypes = /* @__PURE__ */ new Set();
14
+ var registeredObjectDefinitions = /* @__PURE__ */ new Map();
15
+ function getModuleDependencyNamespace(dependency) {
16
+ return typeof dependency === "string" ? dependency : dependency.namespace;
17
+ }
18
+ function getObjectTypeName(objectType) {
19
+ return typeof objectType === "string" ? objectType : objectType.type;
20
+ }
21
+ function getEventTypeName(eventType) {
22
+ return typeof eventType === "string" ? eventType : eventType.eventType;
23
+ }
24
+ function validateModuleNamespace(namespace) {
25
+ if (!namespace) {
26
+ throw new Error("Module namespace cannot be empty");
27
+ }
28
+ if (!/^[a-z][a-z0-9-]*$/.test(namespace)) {
29
+ throw new Error(
30
+ `Invalid module namespace: "${namespace}". Must be lowercase letters, numbers, and hyphens only.`
31
+ );
32
+ }
33
+ }
34
+ function createModuleRegistry(modules = []) {
35
+ const registered = /* @__PURE__ */ new Map();
36
+ for (const module of modules) {
37
+ validateModuleNamespace(module.namespace);
38
+ if (registered.has(module.namespace)) {
39
+ throw new Error(`Duplicate FabricModule namespace "${module.namespace}".`);
40
+ }
41
+ registered.set(module.namespace, module);
42
+ }
43
+ return { modules: registered };
44
+ }
45
+ function validateIdentifierList(values, label, namespace) {
46
+ for (const value of values ?? []) {
47
+ if (!value) {
48
+ throw new Error(`Module "${namespace}" has an empty ${label} entry.`);
49
+ }
50
+ }
51
+ }
52
+ function assertJsonValue(value, path) {
53
+ if (value === null || typeof value === "string" || typeof value === "boolean") return;
54
+ if (typeof value === "number" && Number.isFinite(value)) return;
55
+ if (Array.isArray(value)) {
56
+ value.forEach((item, index) => assertJsonValue(item, `${path}[${index}]`));
57
+ return;
58
+ }
59
+ if (typeof value === "object") {
60
+ for (const [key, child] of Object.entries(value)) {
61
+ assertJsonValue(child, `${path}.${key}`);
62
+ }
63
+ return;
64
+ }
65
+ throw new Error(`${path} must contain JSON-serializable values.`);
66
+ }
67
+ function qualifiedObjectType(namespace, type) {
68
+ return `${namespace}.${type}`;
69
+ }
70
+ function validateObjectDefinition(objectType, namespace, context) {
71
+ if (typeof objectType === "string") return;
72
+ if (objectType.schema !== void 0) {
73
+ chunkOC4ZFJKD_cjs.assertPortableJsonSchema(objectType.schema, `Module "${namespace}" object "${objectType.type}" schema`);
74
+ }
75
+ if (objectType.semantics !== void 0) {
76
+ assertJsonValue(objectType.semantics, `Module "${namespace}" object "${objectType.type}" semantics`);
77
+ }
78
+ const relationNames = /* @__PURE__ */ new Set();
79
+ for (const relation of objectType.relations ?? []) {
80
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(relation.name)) {
81
+ throw new Error(`Module "${namespace}" object "${objectType.type}" has invalid relation name "${relation.name}".`);
82
+ }
83
+ if (relationNames.has(relation.name)) {
84
+ throw new Error(`Module "${namespace}" object "${objectType.type}" has duplicate relation "${relation.name}".`);
85
+ }
86
+ relationNames.add(relation.name);
87
+ if (!/^[a-z][a-z0-9-]*\.[A-Z][a-zA-Z0-9]*$/.test(relation.target)) {
88
+ throw new Error(`Relation "${relation.name}" target "${relation.target}" must be module-qualified.`);
89
+ }
90
+ if (context.availableObjectTypes && !context.availableObjectTypes.has(relation.target)) {
91
+ throw new Error(`Relation "${relation.name}" targets missing object type "${relation.target}".`);
92
+ }
93
+ if (relation.required && relation.onTargetDelete === "set-null") {
94
+ throw new Error(`Required relation "${relation.name}" cannot use onTargetDelete "set-null".`);
95
+ }
96
+ }
97
+ const invariantIds = /* @__PURE__ */ new Set();
98
+ for (const invariant of objectType.invariants ?? []) {
99
+ if (!invariant.id.trim() || !invariant.description.trim()) {
100
+ throw new Error(`Module "${namespace}" object "${objectType.type}" has an invariant without an id or description.`);
101
+ }
102
+ if (invariantIds.has(invariant.id)) {
103
+ throw new Error(`Module "${namespace}" object "${objectType.type}" has duplicate invariant "${invariant.id}".`);
104
+ }
105
+ invariantIds.add(invariant.id);
106
+ if (invariant.required && !invariant.enforcementRef?.trim()) {
107
+ throw new Error(`Required invariant "${invariant.id}" must declare enforcementRef.`);
108
+ }
109
+ }
110
+ }
111
+ function validateManifest(module, context = {}) {
112
+ validateModuleNamespace(module.namespace);
113
+ const dependencies = (module.dependencies ?? []).map(getModuleDependencyNamespace);
114
+ const objectTypes = (module.objectTypes ?? []).map(getObjectTypeName);
115
+ const eventTypes = (module.eventTypes ?? []).map(getEventTypeName);
116
+ if (module.capability) {
117
+ if (!module.capability.displayName.trim() || !module.capability.description.trim()) {
118
+ throw new Error(`Module "${module.namespace}" capability requires displayName and description.`);
119
+ }
120
+ if (new Set(module.capability.roles ?? []).size !== (module.capability.roles ?? []).length || (module.capability.roles ?? []).some((role) => !/^[a-z][a-z0-9-]*$/.test(role))) {
121
+ throw new Error(`Module "${module.namespace}" capability has invalid or duplicate roles.`);
122
+ }
123
+ const slots = /* @__PURE__ */ new Set();
124
+ for (const slot of module.capability.slots ?? []) {
125
+ if (!/^[a-z][a-z0-9-]*$/.test(slot.name) || slots.has(slot.name)) {
126
+ throw new Error(`Module "${module.namespace}" capability has invalid or duplicate slot "${slot.name}".`);
127
+ }
128
+ slots.add(slot.name);
129
+ if (slot.shape) chunkOC4ZFJKD_cjs.assertPortableJsonSchema(slot.shape, `Capability slot "${slot.name}" shape`);
130
+ }
131
+ }
132
+ for (const dependency of dependencies) {
133
+ validateModuleNamespace(dependency);
134
+ if (dependency === module.namespace) {
135
+ throw new Error(`Module "${module.namespace}" cannot depend on itself.`);
136
+ }
137
+ if (context.availableNamespaces && !context.availableNamespaces.has(dependency)) {
138
+ throw new Error(`Module "${module.namespace}" depends on missing module "${dependency}".`);
139
+ }
140
+ }
141
+ validateIdentifierList(objectTypes, "objectTypes", module.namespace);
142
+ validateIdentifierList(module.subjectTypes, "subjectTypes", module.namespace);
143
+ validateIdentifierList(eventTypes, "eventTypes", module.namespace);
144
+ for (const objectType of objectTypes) {
145
+ if (!/^[A-Z][a-zA-Z0-9]*$/.test(objectType)) {
146
+ throw new Error(
147
+ `Invalid object type: "${objectType}". Object types must be PascalCase alphanumeric.`
148
+ );
149
+ }
150
+ }
151
+ for (const objectType of module.objectTypes ?? []) {
152
+ if (typeof objectType !== "string") {
153
+ for (const relation of objectType.relations ?? []) {
154
+ const targetNamespace = relation.target.slice(0, relation.target.indexOf("."));
155
+ if (targetNamespace !== module.namespace && !dependencies.includes(targetNamespace)) {
156
+ throw new Error(`Module "${module.namespace}" relation "${relation.name}" targets module "${targetNamespace}" without declaring it as a dependency.`);
157
+ }
158
+ }
159
+ }
160
+ validateObjectDefinition(objectType, module.namespace, context);
161
+ }
162
+ for (const action of module.actions ?? []) {
163
+ let parameterSchema;
164
+ try {
165
+ parameterSchema = action.schema.toJSONSchema?.();
166
+ } catch {
167
+ parameterSchema = void 0;
168
+ }
169
+ if (parameterSchema !== void 0) chunkOC4ZFJKD_cjs.assertPortableJsonSchema(parameterSchema, `Action "${action.actionId}" parameters`);
170
+ let resultSchema;
171
+ try {
172
+ resultSchema = action.resultSchema?.toJSONSchema?.();
173
+ } catch {
174
+ resultSchema = void 0;
175
+ }
176
+ if (resultSchema !== void 0) chunkOC4ZFJKD_cjs.assertPortableJsonSchema(resultSchema, `Action "${action.actionId}" result`);
177
+ if (!/^[a-z][a-z0-9-]*\.[a-z][a-z0-9_]*$/.test(action.actionId)) {
178
+ throw new Error(`Invalid action ID: ${action.actionId}`);
179
+ }
180
+ if (action.namespace !== module.namespace) {
181
+ throw new Error(
182
+ `Action "${action.actionId}" declares namespace "${action.namespace}" but is registered by module "${module.namespace}".`
183
+ );
184
+ }
185
+ if (!action.actionId.startsWith(`${module.namespace}.`)) {
186
+ throw new Error(
187
+ `Action "${action.actionId}" must start with module namespace "${module.namespace}."`
188
+ );
189
+ }
190
+ if (action.mutatesDomain && action.emitsEvents.length === 0) {
191
+ throw new Error(
192
+ `Action "${action.actionId}" mutates domain but emits no events. Every mutating action must emit at least one AssetEvent.`
193
+ );
194
+ }
195
+ }
196
+ for (const descriptor of module.displayRenderers ?? []) {
197
+ const isPlannedEventType = context.plannedEventTypes?.has(descriptor.eventType) ?? false;
198
+ const isModuleEventType = eventTypes.includes(descriptor.eventType);
199
+ if (!chunkJAXDEK5Z_cjs.isValidEventType(descriptor.eventType) && !isModuleEventType && !isPlannedEventType) {
200
+ throw new Error(
201
+ `Display renderer registered for unknown event type "${descriptor.eventType}". Register the event type before adding a display renderer.`
202
+ );
203
+ }
204
+ }
205
+ const viewKeys = /* @__PURE__ */ new Set();
206
+ for (const view of module.views ?? []) {
207
+ if (!view.name.startsWith(`${module.namespace}/`) || !/^[a-z][a-z0-9-]*\/[a-z][a-z0-9/_-]*$/.test(view.name)) {
208
+ throw new Error(`View "${view.name}" must start with module namespace "${module.namespace}/" and use lowercase path segments.`);
209
+ }
210
+ if (!view.version.trim()) throw new Error(`View "${view.name}" must declare a version.`);
211
+ const key = `${view.name}@${view.version}`;
212
+ if (viewKeys.has(key)) throw new Error(`Module "${module.namespace}" has duplicate view contract "${key}".`);
213
+ viewKeys.add(key);
214
+ chunkOC4ZFJKD_cjs.assertPortableJsonSchema(view.shape, `View "${key}" shape`);
215
+ if (!Number.isInteger(view.snapshotVersion) || view.snapshotVersion < 1) {
216
+ throw new Error(`View "${key}" snapshotVersion must be a positive integer.`);
217
+ }
218
+ if ((view.compatibleSnapshotVersions?.some((version) => version !== view.snapshotVersion) ?? false) && !view.upgradeSnapshot) {
219
+ throw new Error(`View "${key}" declares older compatible snapshots but no upgradeSnapshot function.`);
220
+ }
221
+ for (const consumption of view.consumes) {
222
+ const isPlanned = context.plannedEventTypes?.has(consumption.eventType) ?? false;
223
+ const isModuleEvent = eventTypes.includes(consumption.eventType);
224
+ if (!chunkJAXDEK5Z_cjs.isValidEventType(consumption.eventType) && !isPlanned && !isModuleEvent) {
225
+ throw new Error(`View "${key}" consumes unknown event type "${consumption.eventType}".`);
226
+ }
227
+ if (consumption.schemaVersions.length === 0 || consumption.schemaVersions.some((version) => !Number.isInteger(version) || version < 1)) {
228
+ throw new Error(`View "${key}" must declare positive consumed schema versions for "${consumption.eventType}".`);
229
+ }
230
+ }
231
+ }
232
+ }
233
+ function sortModulesByDependency(modules, registeredNamespaces = registeredModuleNamespaces) {
234
+ const modulesByNamespace = /* @__PURE__ */ new Map();
235
+ for (const module of modules) {
236
+ validateModuleNamespace(module.namespace);
237
+ if (modulesByNamespace.has(module.namespace)) {
238
+ throw new Error(`Duplicate Fabric module namespace "${module.namespace}".`);
239
+ }
240
+ modulesByNamespace.set(module.namespace, module);
241
+ }
242
+ const sorted = [];
243
+ const visiting = /* @__PURE__ */ new Set();
244
+ const visited = /* @__PURE__ */ new Set();
245
+ function visit(module, path) {
246
+ if (visited.has(module.namespace)) {
247
+ return;
248
+ }
249
+ if (visiting.has(module.namespace)) {
250
+ throw new Error(
251
+ `Cyclic Fabric module dependency detected: ${[...path, module.namespace].join(" -> ")}`
252
+ );
253
+ }
254
+ visiting.add(module.namespace);
255
+ for (const dependency of (module.dependencies ?? []).map(getModuleDependencyNamespace)) {
256
+ const dependencyModule = modulesByNamespace.get(dependency);
257
+ if (!dependencyModule) {
258
+ if (registeredNamespaces.has(dependency)) {
259
+ continue;
260
+ }
261
+ throw new Error(`Module "${module.namespace}" depends on missing module "${dependency}".`);
262
+ }
263
+ visit(dependencyModule, [...path, module.namespace]);
264
+ }
265
+ visiting.delete(module.namespace);
266
+ visited.add(module.namespace);
267
+ sorted.push(module);
268
+ }
269
+ for (const module of modules) {
270
+ visit(module, []);
271
+ }
272
+ return sorted;
273
+ }
274
+ function assertAcyclicRelations(modules) {
275
+ const relationKinds = [
276
+ { label: "owned containment", include: (relation) => relation.semantics === "owned" },
277
+ { label: "cascade-delete", include: (relation) => relation.onTargetDelete === "cascade" },
278
+ { label: "required-construction", include: (relation) => relation.required === true }
279
+ ];
280
+ for (const kind of relationKinds) {
281
+ const edges = /* @__PURE__ */ new Map();
282
+ for (const [source, objectType] of registeredObjectDefinitions) {
283
+ edges.set(source, (objectType.relations ?? []).filter(kind.include).map((relation) => relation.target));
284
+ }
285
+ for (const module of modules) {
286
+ for (const objectType of module.objectTypes ?? []) {
287
+ if (typeof objectType === "string") continue;
288
+ const source = qualifiedObjectType(module.namespace, objectType.type);
289
+ edges.set(source, (objectType.relations ?? []).filter(kind.include).map((relation) => relation.target));
290
+ }
291
+ }
292
+ const visiting = /* @__PURE__ */ new Set();
293
+ const visited = /* @__PURE__ */ new Set();
294
+ const visit = (node, path) => {
295
+ if (visiting.has(node)) {
296
+ throw new Error(`${kind.label} relation cycle detected: ${[...path, node].join(" -> ")}`);
297
+ }
298
+ if (visited.has(node)) return;
299
+ visiting.add(node);
300
+ for (const target of edges.get(node) ?? []) visit(target, [...path, node]);
301
+ visiting.delete(node);
302
+ visited.add(node);
303
+ };
304
+ for (const node of edges.keys()) visit(node, []);
305
+ }
306
+ }
307
+ function registerValidatedFabricModule(module) {
308
+ for (const objectType of module.objectTypes ?? []) {
309
+ chunkOC4ZFJKD_cjs.registerObjectType(getObjectTypeName(objectType));
310
+ const qualified = qualifiedObjectType(module.namespace, getObjectTypeName(objectType));
311
+ registeredQualifiedObjectTypes.add(qualified);
312
+ if (typeof objectType !== "string") registeredObjectDefinitions.set(qualified, objectType);
313
+ }
314
+ for (const subjectType of module.subjectTypes ?? []) {
315
+ chunkJAXDEK5Z_cjs.registerSubjectType(subjectType);
316
+ }
317
+ for (const eventType of module.eventTypes ?? []) {
318
+ chunkJAXDEK5Z_cjs.registerEventType(getEventTypeName(eventType));
319
+ }
320
+ for (const policy of module.policies ?? []) {
321
+ chunkNJL3US7H_cjs.registerPolicyIfMissing(policy);
322
+ }
323
+ for (const machine of module.stateMachines ?? []) {
324
+ chunkUV252FLT_cjs.registerStateMachineIfMissing(machine);
325
+ }
326
+ for (const action of module.actions ?? []) {
327
+ chunkHLRIXNVG_cjs.registerActionIfMissing(action);
328
+ }
329
+ for (const descriptor of module.displayRenderers ?? []) {
330
+ chunkEO4VSB2O_cjs.registerDisplayRenderer(descriptor.eventType, descriptor.renderer);
331
+ }
332
+ for (const view of module.views ?? []) chunk3WEHM2P3_cjs.registerViewContractIfMissing(view);
333
+ registeredModuleNamespaces.add(module.namespace);
334
+ }
335
+ function registerFabricModule(module) {
336
+ const availableObjectTypes = /* @__PURE__ */ new Set([
337
+ ...registeredQualifiedObjectTypes,
338
+ ...(module.objectTypes ?? []).map((objectType) => qualifiedObjectType(module.namespace, getObjectTypeName(objectType)))
339
+ ]);
340
+ validateManifest(module, { availableNamespaces: registeredModuleNamespaces, availableObjectTypes });
341
+ assertAcyclicRelations([module]);
342
+ registerValidatedFabricModule(module);
343
+ }
344
+ function registerFabricModules(modules) {
345
+ const availableNamespaces = /* @__PURE__ */ new Set([
346
+ ...registeredModuleNamespaces,
347
+ ...modules.map((module) => module.namespace)
348
+ ]);
349
+ const plannedEventTypes = new Set(
350
+ modules.flatMap((module) => (module.eventTypes ?? []).map(getEventTypeName))
351
+ );
352
+ const availableObjectTypes = /* @__PURE__ */ new Set([
353
+ ...registeredQualifiedObjectTypes,
354
+ ...modules.flatMap(
355
+ (module) => (module.objectTypes ?? []).map((objectType) => qualifiedObjectType(module.namespace, getObjectTypeName(objectType)))
356
+ )
357
+ ]);
358
+ for (const module of modules) {
359
+ validateManifest(module, { availableNamespaces, plannedEventTypes, availableObjectTypes });
360
+ }
361
+ assertAcyclicRelations(modules);
362
+ const sortedModules = sortModulesByDependency(modules);
363
+ for (const module of sortedModules) {
364
+ registerValidatedFabricModule(module);
365
+ }
366
+ return sortedModules;
367
+ }
368
+
369
+ exports.createModuleRegistry = createModuleRegistry;
370
+ exports.getEventTypeName = getEventTypeName;
371
+ exports.getModuleDependencyNamespace = getModuleDependencyNamespace;
372
+ exports.getObjectTypeName = getObjectTypeName;
373
+ exports.registerFabricModule = registerFabricModule;
374
+ exports.registerFabricModules = registerFabricModules;
375
+ exports.validateModuleNamespace = validateModuleNamespace;
376
+ //# sourceMappingURL=chunk-K27DUWRY.cjs.map
377
+ //# sourceMappingURL=chunk-K27DUWRY.cjs.map