@fabricorg/archetypes 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @fabricorg/archetypes
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Require the Platform 0.12 semantic manifest contracts.
8
+
9
+ ## 0.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Close final uplift audit gaps: align Host 2.x documentation and migration evidence, surface every
14
+ compiler/generator API to LLM consumers, make memory outbox egress directly usable, sanitize relay
15
+ failures, validate complete archetype state maps, support recursive JSON Schema generation, reject
16
+ cross-platform path traversal, synchronize artifact version stamps, and include package licenses.
17
+ - Consume Platform as a peer dependency so applications keep a single copy of the public contracts.
18
+ - Updated dependencies
19
+ - @fabricorg/platform@0.11.1
20
+
3
21
  ## 0.2.0
4
22
 
5
23
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -118,6 +118,10 @@ function validateObject(manifest, objectType) {
118
118
  findings.push({ code: "missing_state_machine", objectType: objectType.type, message: `Object "${objectType.type}" needs a state machine for archetype conformance.` });
119
119
  return { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };
120
120
  }
121
+ const declaredStates = new Set(machine.states.map((state) => state.id));
122
+ for (const state of Object.keys(reference.stateMap)) {
123
+ if (!declaredStates.has(state)) findings.push({ code: "unknown_mapped_state", objectType: objectType.type, state, message: `State mapping "${state}" does not name a declared state.` });
124
+ }
121
125
  for (const state of machine.states) {
122
126
  const mapped = reference.stateMap[state.id];
123
127
  if (!mapped) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["import {\n\texportModuleManifest,\n\ttype FabricModule,\n\ttype JsonValue,\n\ttype ModuleManifest,\n\ttype ModuleManifestObjectType,\n\ttype StateClass,\n} from \"@fabricorg/platform\";\n\nexport const ARCHETYPE_SEMANTIC_KEY = \"fabric.archetype\" as const;\n\nexport type ArchetypeId =\n\t| \"fabric.Party\"\n\t| \"fabric.Offering\"\n\t| \"fabric.Agreement\"\n\t| \"fabric.Resource\"\n\t| \"fabric.Activity\"\n\t| \"fabric.Settlement\";\n\nexport interface ArchetypeReference {\n\tid: ArchetypeId;\n\tversion: string;\n\tstateMap: Record<string, string>;\n}\n\nexport interface ArchetypeState {\n\tid: string;\n\tstateClass: StateClass;\n}\n\nexport interface ArchetypeTransition {\n\tfrom: string;\n\tto: string;\n\trequired?: boolean;\n}\n\nexport interface ArchetypeDefinition {\n\tid: ArchetypeId;\n\tversion: string;\n\tdescription: string;\n\tstates: Record<string, ArchetypeState>;\n\ttransitions: ArchetypeTransition[];\n\tobligations: string[];\n}\n\nexport type ConformanceFindingCode =\n\t| \"invalid_annotation\"\n\t| \"unknown_archetype\"\n\t| \"unsupported_archetype_version\"\n\t| \"missing_state_machine\"\n\t| \"unmapped_state\"\n\t| \"unknown_archetype_state\"\n\t| \"incompatible_state_class\"\n\t| \"transition_not_permitted\"\n\t| \"exception_transition_unguarded\"\n\t| \"required_transition_unreachable\";\n\nexport interface ConformanceFinding {\n\tcode: ConformanceFindingCode;\n\tmessage: string;\n\tobjectType: string;\n\tstate?: string;\n\ttarget?: string;\n}\n\nexport interface ArchetypeConformanceReport {\n\tconforms: boolean;\n\tobjectType: string;\n\tarchetype?: string;\n\tfindings: ConformanceFinding[];\n}\n\nexport interface ManifestConformanceAdapter {\n\tid: string;\n\tevaluate(manifest: ModuleManifest): ArchetypeConformanceReport[];\n}\n\nconst states = (definitions: Array<[string, StateClass]>): Record<string, ArchetypeState> =>\n\tObject.fromEntries(definitions.map(([id, stateClass]) => [id, { id, stateClass }]));\n\nexport const ARCHETYPES: Readonly<Record<ArchetypeId, ArchetypeDefinition>> = {\n\t\"fabric.Party\": {\n\t\tid: \"fabric.Party\", version: \"0.1\", description: \"A person or organization participating in business relationships.\",\n\t\tstates: states([[\"prospective\", \"initial\"], [\"active\", \"active\"], [\"inactive\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"prospective\", to: \"active\", required: true }, { from: \"active\", to: \"inactive\" }, { from: \"prospective\", to: \"exception\" }, { from: \"active\", to: \"exception\" }],\n\t\tobligations: [\"identity is tenant-scoped\", \"participation is attributable\"],\n\t},\n\t\"fabric.Offering\": {\n\t\tid: \"fabric.Offering\", version: \"0.1\", description: \"Something a party makes available under defined terms.\",\n\t\tstates: states([[\"available\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"retired\" }, { from: \"available\", to: \"exception\" }],\n\t\tobligations: [\"terms are identifiable\", \"availability is explicit\"],\n\t},\n\t\"fabric.Agreement\": {\n\t\tid: \"fabric.Agreement\", version: \"0.1\", description: \"A governed commitment between parties.\",\n\t\tstates: states([[\"proposed\", \"initial\"], [\"committed\", \"active\"], [\"resolved\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"proposed\", to: \"committed\", required: true }, { from: \"committed\", to: \"resolved\", required: true }, { from: \"proposed\", to: \"exception\" }, { from: \"committed\", to: \"exception\" }],\n\t\tobligations: [\"participating parties are attributable\", \"commitment and resolution are auditable\"],\n\t},\n\t\"fabric.Resource\": {\n\t\tid: \"fabric.Resource\", version: \"0.1\", description: \"A capacity or asset allocated by activities.\",\n\t\tstates: states([[\"available\", \"initial\"], [\"allocated\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"allocated\", required: true }, { from: \"allocated\", to: \"available\" }, { from: \"available\", to: \"retired\" }, { from: \"allocated\", to: \"exception\" }],\n\t\tobligations: [\"allocation is identifiable\", \"conflicting allocation is governed\"],\n\t},\n\t\"fabric.Activity\": {\n\t\tid: \"fabric.Activity\", version: \"0.1\", description: \"Work planned and performed toward an outcome.\",\n\t\tstates: states([[\"planned\", \"initial\"], [\"executing\", \"active\"], [\"waiting\", \"waiting\"], [\"completed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"planned\", to: \"executing\", required: true }, { from: \"executing\", to: \"waiting\" }, { from: \"waiting\", to: \"executing\" }, { from: \"executing\", to: \"completed\", required: true }, { from: \"waiting\", to: \"completed\" }, { from: \"planned\", to: \"exception\" }, { from: \"executing\", to: \"exception\" }, { from: \"waiting\", to: \"exception\" }],\n\t\tobligations: [\"responsible party is attributable\", \"resource use and outcome are auditable\"],\n\t},\n\t\"fabric.Settlement\": {\n\t\tid: \"fabric.Settlement\", version: \"0.1\", description: \"Resolution of value exchange associated with an agreement.\",\n\t\tstates: states([[\"pending\", \"initial\"], [\"settled\", \"terminal\"], [\"reversed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"pending\", to: \"settled\", required: true }, { from: \"settled\", to: \"reversed\" }, { from: \"pending\", to: \"exception\" }],\n\t\tobligations: [\"value and currency are explicit\", \"settlement is attributable to an agreement\"],\n\t},\n};\n\nexport function archetypeSemantics(reference: ArchetypeReference): Record<string, JsonValue> {\n\treturn { [ARCHETYPE_SEMANTIC_KEY]: reference as unknown as JsonValue };\n}\n\nexport function readArchetypeReference(\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeReference | undefined {\n\tconst value = objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY];\n\tif (value === undefined) return undefined;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, JsonValue>;\n\tif (typeof record.id !== \"string\" || typeof record.version !== \"string\" || !record.stateMap || typeof record.stateMap !== \"object\" || Array.isArray(record.stateMap)) return undefined;\n\tif (!Object.values(record.stateMap).every((state) => typeof state === \"string\")) return undefined;\n\treturn { id: record.id as ArchetypeId, version: record.version, stateMap: record.stateMap as Record<string, string> };\n}\n\nconst transitionKey = (from: string, to: string) => `${from}->${to}`;\n\nexport function validateArchetypeConformance(\n\tmanifest: ModuleManifest,\n): ArchetypeConformanceReport[] {\n\treturn manifest.objectTypes\n\t\t.filter((objectType) => objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY] !== undefined)\n\t\t.map((objectType) => validateObject(manifest, objectType));\n}\n\nfunction validateObject(\n\tmanifest: ModuleManifest,\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeConformanceReport {\n\tconst findings: ConformanceFinding[] = [];\n\tconst reference = readArchetypeReference(objectType);\n\tif (!reference) {\n\t\tfindings.push({ code: \"invalid_annotation\", objectType: objectType.type, message: `Object \"${objectType.type}\" has an invalid ${ARCHETYPE_SEMANTIC_KEY} annotation.` });\n\t\treturn { conforms: false, objectType: objectType.type, findings };\n\t}\n\tconst definition = ARCHETYPES[reference.id];\n\tif (!definition) {\n\t\tfindings.push({ code: \"unknown_archetype\", objectType: objectType.type, message: `Unknown archetype \"${reference.id}\".` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tif (reference.version !== definition.version) {\n\t\tfindings.push({ code: \"unsupported_archetype_version\", objectType: objectType.type, message: `Archetype \"${reference.id}\" supports version ${definition.version}, received ${reference.version}.` });\n\t}\n\tconst machine = (manifest.stateMachines ?? []).find((candidate) => candidate.entityType === objectType.type);\n\tif (!machine) {\n\t\tfindings.push({ code: \"missing_state_machine\", objectType: objectType.type, message: `Object \"${objectType.type}\" needs a state machine for archetype conformance.` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tfor (const state of machine.states) {\n\t\tconst mapped = reference.stateMap[state.id];\n\t\tif (!mapped) {\n\t\t\tfindings.push({ code: \"unmapped_state\", objectType: objectType.type, state: state.id, message: `State \"${state.id}\" is not mapped.` });\n\t\t\tcontinue;\n\t\t}\n\t\tconst base = definition.states[mapped];\n\t\tif (!base) {\n\t\t\tfindings.push({ code: \"unknown_archetype_state\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" maps to unknown archetype state \"${mapped}\".` });\n\t\t} else if (base.stateClass !== state.stateClass) {\n\t\t\tfindings.push({ code: \"incompatible_state_class\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" (${state.stateClass}) is incompatible with \"${mapped}\" (${base.stateClass}).` });\n\t\t}\n\t}\n\tconst permitted = new Set(definition.transitions.map((transition) => transitionKey(transition.from, transition.to)));\n\tconst realized = new Set<string>();\n\tfor (const transition of machine.transitions) {\n\t\tconst from = reference.stateMap[transition.from];\n\t\tconst to = reference.stateMap[transition.to];\n\t\tif (!from || !to) continue;\n\t\tif (to === \"exception\" && !transition.hasGuard) {\n\t\t\tfindings.push({ code: \"exception_transition_unguarded\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Exception transition \"${transition.from}\" -> \"${transition.to}\" must declare a governance guard.` });\n\t\t}\n\t\tif (from !== to && !permitted.has(transitionKey(from, to))) {\n\t\t\tfindings.push({ code: \"transition_not_permitted\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Transition \"${transition.from}\" -> \"${transition.to}\" maps to disallowed archetype transition \"${from}\" -> \"${to}\".` });\n\t\t} else if (from !== to) {\n\t\t\trealized.add(transitionKey(from, to));\n\t\t}\n\t}\n\tfor (const required of definition.transitions.filter((transition) => transition.required)) {\n\t\tif (!realized.has(transitionKey(required.from, required.to))) {\n\t\t\tfindings.push({ code: \"required_transition_unreachable\", objectType: objectType.type, state: required.from, target: required.to, message: `Required archetype transition \"${required.from}\" -> \"${required.to}\" is not realized.` });\n\t\t}\n\t}\n\treturn { conforms: findings.length === 0, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n}\n\nexport function assertArchetypeConformance(module: FabricModule<unknown>): void {\n\tconst failures = validateArchetypeConformance(exportModuleManifest(module)).filter((report) => !report.conforms);\n\tif (failures.length > 0) {\n\t\tthrow new Error(`Archetype conformance failed:\\n${failures.flatMap((report) => report.findings.map((finding) => `- ${report.objectType}: ${finding.message}`)).join(\"\\n\")}`);\n\t}\n}\n\nexport const archetypeConformanceAdapter: Manif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ifest,\n\ttype ModuleManifestObjectType,\n\ttype StateClass,\n} from \"@fabricorg/platform\";\n\nexport const ARCHETYPE_SEMANTIC_KEY = \"fabric.archetype\" as const;\n\nexport type ArchetypeId =\n\t| \"fabric.Party\"\n\t| \"fabric.Offering\"\n\t| \"fabric.Agreement\"\n\t| \"fabric.Resource\"\n\t| \"fabric.Activity\"\n\t| \"fabric.Settlement\";\n\nexport interface ArchetypeReference {\n\tid: ArchetypeId;\n\tversion: string;\n\tstateMap: Record<string, string>;\n}\n\nexport interface ArchetypeState {\n\tid: string;\n\tstateClass: StateClass;\n}\n\nexport interface ArchetypeTransition {\n\tfrom: string;\n\tto: string;\n\trequired?: boolean;\n}\n\nexport interface ArchetypeDefinition {\n\tid: ArchetypeId;\n\tversion: string;\n\tdescription: string;\n\tstates: Record<string, ArchetypeState>;\n\ttransitions: ArchetypeTransition[];\n\tobligations: string[];\n}\n\nexport type ConformanceFindingCode =\n\t| \"invalid_annotation\"\n\t| \"unknown_archetype\"\n\t| \"unsupported_archetype_version\"\n\t| \"missing_state_machine\"\n\t| \"unmapped_state\"\n\t| \"unknown_mapped_state\"\n\t| \"unknown_archetype_state\"\n\t| \"incompatible_state_class\"\n\t| \"transition_not_permitted\"\n\t| \"exception_transition_unguarded\"\n\t| \"required_transition_unreachable\";\n\nexport interface ConformanceFinding {\n\tcode: ConformanceFindingCode;\n\tmessage: string;\n\tobjectType: string;\n\tstate?: string;\n\ttarget?: string;\n}\n\nexport interface ArchetypeConformanceReport {\n\tconforms: boolean;\n\tobjectType: string;\n\tarchetype?: string;\n\tfindings: ConformanceFinding[];\n}\n\nexport interface ManifestConformanceAdapter {\n\tid: string;\n\tevaluate(manifest: ModuleManifest): ArchetypeConformanceReport[];\n}\n\nconst states = (definitions: Array<[string, StateClass]>): Record<string, ArchetypeState> =>\n\tObject.fromEntries(definitions.map(([id, stateClass]) => [id, { id, stateClass }]));\n\nexport const ARCHETYPES: Readonly<Record<ArchetypeId, ArchetypeDefinition>> = {\n\t\"fabric.Party\": {\n\t\tid: \"fabric.Party\", version: \"0.1\", description: \"A person or organization participating in business relationships.\",\n\t\tstates: states([[\"prospective\", \"initial\"], [\"active\", \"active\"], [\"inactive\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"prospective\", to: \"active\", required: true }, { from: \"active\", to: \"inactive\" }, { from: \"prospective\", to: \"exception\" }, { from: \"active\", to: \"exception\" }],\n\t\tobligations: [\"identity is tenant-scoped\", \"participation is attributable\"],\n\t},\n\t\"fabric.Offering\": {\n\t\tid: \"fabric.Offering\", version: \"0.1\", description: \"Something a party makes available under defined terms.\",\n\t\tstates: states([[\"available\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"retired\" }, { from: \"available\", to: \"exception\" }],\n\t\tobligations: [\"terms are identifiable\", \"availability is explicit\"],\n\t},\n\t\"fabric.Agreement\": {\n\t\tid: \"fabric.Agreement\", version: \"0.1\", description: \"A governed commitment between parties.\",\n\t\tstates: states([[\"proposed\", \"initial\"], [\"committed\", \"active\"], [\"resolved\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"proposed\", to: \"committed\", required: true }, { from: \"committed\", to: \"resolved\", required: true }, { from: \"proposed\", to: \"exception\" }, { from: \"committed\", to: \"exception\" }],\n\t\tobligations: [\"participating parties are attributable\", \"commitment and resolution are auditable\"],\n\t},\n\t\"fabric.Resource\": {\n\t\tid: \"fabric.Resource\", version: \"0.1\", description: \"A capacity or asset allocated by activities.\",\n\t\tstates: states([[\"available\", \"initial\"], [\"allocated\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"allocated\", required: true }, { from: \"allocated\", to: \"available\" }, { from: \"available\", to: \"retired\" }, { from: \"allocated\", to: \"exception\" }],\n\t\tobligations: [\"allocation is identifiable\", \"conflicting allocation is governed\"],\n\t},\n\t\"fabric.Activity\": {\n\t\tid: \"fabric.Activity\", version: \"0.1\", description: \"Work planned and performed toward an outcome.\",\n\t\tstates: states([[\"planned\", \"initial\"], [\"executing\", \"active\"], [\"waiting\", \"waiting\"], [\"completed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"planned\", to: \"executing\", required: true }, { from: \"executing\", to: \"waiting\" }, { from: \"waiting\", to: \"executing\" }, { from: \"executing\", to: \"completed\", required: true }, { from: \"waiting\", to: \"completed\" }, { from: \"planned\", to: \"exception\" }, { from: \"executing\", to: \"exception\" }, { from: \"waiting\", to: \"exception\" }],\n\t\tobligations: [\"responsible party is attributable\", \"resource use and outcome are auditable\"],\n\t},\n\t\"fabric.Settlement\": {\n\t\tid: \"fabric.Settlement\", version: \"0.1\", description: \"Resolution of value exchange associated with an agreement.\",\n\t\tstates: states([[\"pending\", \"initial\"], [\"settled\", \"terminal\"], [\"reversed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"pending\", to: \"settled\", required: true }, { from: \"settled\", to: \"reversed\" }, { from: \"pending\", to: \"exception\" }],\n\t\tobligations: [\"value and currency are explicit\", \"settlement is attributable to an agreement\"],\n\t},\n};\n\nexport function archetypeSemantics(reference: ArchetypeReference): Record<string, JsonValue> {\n\treturn { [ARCHETYPE_SEMANTIC_KEY]: reference as unknown as JsonValue };\n}\n\nexport function readArchetypeReference(\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeReference | undefined {\n\tconst value = objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY];\n\tif (value === undefined) return undefined;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, JsonValue>;\n\tif (typeof record.id !== \"string\" || typeof record.version !== \"string\" || !record.stateMap || typeof record.stateMap !== \"object\" || Array.isArray(record.stateMap)) return undefined;\n\tif (!Object.values(record.stateMap).every((state) => typeof state === \"string\")) return undefined;\n\treturn { id: record.id as ArchetypeId, version: record.version, stateMap: record.stateMap as Record<string, string> };\n}\n\nconst transitionKey = (from: string, to: string) => `${from}->${to}`;\n\nexport function validateArchetypeConformance(\n\tmanifest: ModuleManifest,\n): ArchetypeConformanceReport[] {\n\treturn manifest.objectTypes\n\t\t.filter((objectType) => objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY] !== undefined)\n\t\t.map((objectType) => validateObject(manifest, objectType));\n}\n\nfunction validateObject(\n\tmanifest: ModuleManifest,\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeConformanceReport {\n\tconst findings: ConformanceFinding[] = [];\n\tconst reference = readArchetypeReference(objectType);\n\tif (!reference) {\n\t\tfindings.push({ code: \"invalid_annotation\", objectType: objectType.type, message: `Object \"${objectType.type}\" has an invalid ${ARCHETYPE_SEMANTIC_KEY} annotation.` });\n\t\treturn { conforms: false, objectType: objectType.type, findings };\n\t}\n\tconst definition = ARCHETYPES[reference.id];\n\tif (!definition) {\n\t\tfindings.push({ code: \"unknown_archetype\", objectType: objectType.type, message: `Unknown archetype \"${reference.id}\".` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tif (reference.version !== definition.version) {\n\t\tfindings.push({ code: \"unsupported_archetype_version\", objectType: objectType.type, message: `Archetype \"${reference.id}\" supports version ${definition.version}, received ${reference.version}.` });\n\t}\n\tconst machine = (manifest.stateMachines ?? []).find((candidate) => candidate.entityType === objectType.type);\n\tif (!machine) {\n\t\tfindings.push({ code: \"missing_state_machine\", objectType: objectType.type, message: `Object \"${objectType.type}\" needs a state machine for archetype conformance.` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tconst declaredStates = new Set(machine.states.map((state) => state.id));\n\tfor (const state of Object.keys(reference.stateMap)) {\n\t\tif (!declaredStates.has(state)) findings.push({ code: \"unknown_mapped_state\", objectType: objectType.type, state, message: `State mapping \"${state}\" does not name a declared state.` });\n\t}\n\tfor (const state of machine.states) {\n\t\tconst mapped = reference.stateMap[state.id];\n\t\tif (!mapped) {\n\t\t\tfindings.push({ code: \"unmapped_state\", objectType: objectType.type, state: state.id, message: `State \"${state.id}\" is not mapped.` });\n\t\t\tcontinue;\n\t\t}\n\t\tconst base = definition.states[mapped];\n\t\tif (!base) {\n\t\t\tfindings.push({ code: \"unknown_archetype_state\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" maps to unknown archetype state \"${mapped}\".` });\n\t\t} else if (base.stateClass !== state.stateClass) {\n\t\t\tfindings.push({ code: \"incompatible_state_class\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" (${state.stateClass}) is incompatible with \"${mapped}\" (${base.stateClass}).` });\n\t\t}\n\t}\n\tconst permitted = new Set(definition.transitions.map((transition) => transitionKey(transition.from, transition.to)));\n\tconst realized = new Set<string>();\n\tfor (const transition of machine.transitions) {\n\t\tconst from = reference.stateMap[transition.from];\n\t\tconst to = reference.stateMap[transition.to];\n\t\tif (!from || !to) continue;\n\t\tif (to === \"exception\" && !transition.hasGuard) {\n\t\t\tfindings.push({ code: \"exception_transition_unguarded\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Exception transition \"${transition.from}\" -> \"${transition.to}\" must declare a governance guard.` });\n\t\t}\n\t\tif (from !== to && !permitted.has(transitionKey(from, to))) {\n\t\t\tfindings.push({ code: \"transition_not_permitted\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Transition \"${transition.from}\" -> \"${transition.to}\" maps to disallowed archetype transition \"${from}\" -> \"${to}\".` });\n\t\t} else if (from !== to) {\n\t\t\trealized.add(transitionKey(from, to));\n\t\t}\n\t}\n\tfor (const required of definition.transitions.filter((transition) => transition.required)) {\n\t\tif (!realized.has(transitionKey(required.from, required.to))) {\n\t\t\tfindings.push({ code: \"required_transition_unreachable\", objectType: objectType.type, state: required.from, target: required.to, message: `Required archetype transition \"${required.from}\" -> \"${required.to}\" is not realized.` });\n\t\t}\n\t}\n\treturn { conforms: findings.length === 0, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n}\n\nexport function assertArchetypeConformance(module: FabricModule<unknown>): void {\n\tconst failures = validateArchetypeConformance(exportModuleManifest(module)).filter((report) => !report.conforms);\n\tif (failures.length > 0) {\n\t\tthrow new Error(`Archetype conformance failed:\\n${failures.flatMap((report) => report.findings.map((finding) => `- ${report.objectType}: ${finding.message}`)).join(\"\\n\")}`);\n\t}\n}\n\nexport const archetypeConformanceAdapter: ManifestConformanceAdapter = {\n\tid: \"@fabricorg/archetypes\",\n\tevaluate: validateArchetypeConformance,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AAEA,IAAM,yBAAyB;AAqEtC,IAAM,SAAS,CAAC,gBACf,OAAO,YAAY,YAAY,IAAI,CAAC,CAAC,IAAI,UAAU,MAAM,CAAC,IAAI,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC;AAE5E,IAAM,aAAiE;AAAA,EAC7E,gBAAgB;AAAA,IACf,IAAI;AAAA,IAAgB,SAAS;AAAA,IAAO,aAAa;AAAA,IACjD,QAAQ,OAAO,CAAC,CAAC,eAAe,SAAS,GAAG,CAAC,UAAU,QAAQ,GAAG,CAAC,YAAY,UAAU,GAAG,CAAC,aAAa,WAAW,CAAC,CAAC;AAAA,IACvH,aAAa,CAAC,EAAE,MAAM,eAAe,IAAI,UAAU,UAAU,KAAK,GAAG,EAAE,MAAM,UAAU,IAAI,WAAW,GAAG,EAAE,MAAM,eAAe,IAAI,YAAY,GAAG,EAAE,MAAM,UAAU,IAAI,YAAY,CAAC;AAAA,IACtL,aAAa,CAAC,6BAA6B,+BAA+B;AAAA,EAC3E;AAAA,EACA,mBAAmB;AAAA,IAClB,IAAI;AAAA,IAAmB,SAAS;AAAA,IAAO,aAAa;AAAA,IACpD,QAAQ,OAAO,CAAC,CAAC,aAAa,QAAQ,GAAG,CAAC,WAAW,UAAU,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AU,EAAE,IAAI,UAAU,OAAO,IAAI,SAAS;AACpI;AAEO,SAAS,2BAA2BA,SAAqC;AAC/E,QAAM,WAAW,iCAA6B,sCAAqBA,OAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,QAAQ;AAC/G,MAAI,SAAS,SAAS,GAAG;AACxB,UAAM,IAAI,MAAM;AAAA,EAAkC,SAAS,QAAQ,CAAC,WAAW,OAAO,SAAS,IAAI,CAAC,YAAY,KAAK,OAAO,UAAU,KAAK,QAAQ,OAAO,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC5K;AACD;AAEO,IAAM,8BAA0D;AAAA,EACtE,IAAI;AAAA,EACJ,UAAU;AACX;","names":["module"]}
package/dist/index.d.cts CHANGED
@@ -24,7 +24,7 @@ interface ArchetypeDefinition {
24
24
  transitions: ArchetypeTransition[];
25
25
  obligations: string[];
26
26
  }
27
- type ConformanceFindingCode = "invalid_annotation" | "unknown_archetype" | "unsupported_archetype_version" | "missing_state_machine" | "unmapped_state" | "unknown_archetype_state" | "incompatible_state_class" | "transition_not_permitted" | "exception_transition_unguarded" | "required_transition_unreachable";
27
+ type ConformanceFindingCode = "invalid_annotation" | "unknown_archetype" | "unsupported_archetype_version" | "missing_state_machine" | "unmapped_state" | "unknown_mapped_state" | "unknown_archetype_state" | "incompatible_state_class" | "transition_not_permitted" | "exception_transition_unguarded" | "required_transition_unreachable";
28
28
  interface ConformanceFinding {
29
29
  code: ConformanceFindingCode;
30
30
  message: string;
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ interface ArchetypeDefinition {
24
24
  transitions: ArchetypeTransition[];
25
25
  obligations: string[];
26
26
  }
27
- type ConformanceFindingCode = "invalid_annotation" | "unknown_archetype" | "unsupported_archetype_version" | "missing_state_machine" | "unmapped_state" | "unknown_archetype_state" | "incompatible_state_class" | "transition_not_permitted" | "exception_transition_unguarded" | "required_transition_unreachable";
27
+ type ConformanceFindingCode = "invalid_annotation" | "unknown_archetype" | "unsupported_archetype_version" | "missing_state_machine" | "unmapped_state" | "unknown_mapped_state" | "unknown_archetype_state" | "incompatible_state_class" | "transition_not_permitted" | "exception_transition_unguarded" | "required_transition_unreachable";
28
28
  interface ConformanceFinding {
29
29
  code: ConformanceFindingCode;
30
30
  message: string;
package/dist/index.js CHANGED
@@ -90,6 +90,10 @@ function validateObject(manifest, objectType) {
90
90
  findings.push({ code: "missing_state_machine", objectType: objectType.type, message: `Object "${objectType.type}" needs a state machine for archetype conformance.` });
91
91
  return { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };
92
92
  }
93
+ const declaredStates = new Set(machine.states.map((state) => state.id));
94
+ for (const state of Object.keys(reference.stateMap)) {
95
+ if (!declaredStates.has(state)) findings.push({ code: "unknown_mapped_state", objectType: objectType.type, state, message: `State mapping "${state}" does not name a declared state.` });
96
+ }
93
97
  for (const state of machine.states) {
94
98
  const mapped = reference.stateMap[state.id];
95
99
  if (!mapped) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"sourcesContent":["import {\n\texportModuleManifest,\n\ttype FabricModule,\n\ttype JsonValue,\n\ttype ModuleManifest,\n\ttype ModuleManifestObjectType,\n\ttype StateClass,\n} from \"@fabricorg/platform\";\n\nexport const ARCHETYPE_SEMANTIC_KEY = \"fabric.archetype\" as const;\n\nexport type ArchetypeId =\n\t| \"fabric.Party\"\n\t| \"fabric.Offering\"\n\t| \"fabric.Agreement\"\n\t| \"fabric.Resource\"\n\t| \"fabric.Activity\"\n\t| \"fabric.Settlement\";\n\nexport interface ArchetypeReference {\n\tid: ArchetypeId;\n\tversion: string;\n\tstateMap: Record<string, string>;\n}\n\nexport interface ArchetypeState {\n\tid: string;\n\tstateClass: StateClass;\n}\n\nexport interface ArchetypeTransition {\n\tfrom: string;\n\tto: string;\n\trequired?: boolean;\n}\n\nexport interface ArchetypeDefinition {\n\tid: ArchetypeId;\n\tversion: string;\n\tdescription: string;\n\tstates: Record<string, ArchetypeState>;\n\ttransitions: ArchetypeTransition[];\n\tobligations: string[];\n}\n\nexport type ConformanceFindingCode =\n\t| \"invalid_annotation\"\n\t| \"unknown_archetype\"\n\t| \"unsupported_archetype_version\"\n\t| \"missing_state_machine\"\n\t| \"unmapped_state\"\n\t| \"unknown_archetype_state\"\n\t| \"incompatible_state_class\"\n\t| \"transition_not_permitted\"\n\t| \"exception_transition_unguarded\"\n\t| \"required_transition_unreachable\";\n\nexport interface ConformanceFinding {\n\tcode: ConformanceFindingCode;\n\tmessage: string;\n\tobjectType: string;\n\tstate?: string;\n\ttarget?: string;\n}\n\nexport interface ArchetypeConformanceReport {\n\tconforms: boolean;\n\tobjectType: string;\n\tarchetype?: string;\n\tfindings: ConformanceFinding[];\n}\n\nexport interface ManifestConformanceAdapter {\n\tid: string;\n\tevaluate(manifest: ModuleManifest): ArchetypeConformanceReport[];\n}\n\nconst states = (definitions: Array<[string, StateClass]>): Record<string, ArchetypeState> =>\n\tObject.fromEntries(definitions.map(([id, stateClass]) => [id, { id, stateClass }]));\n\nexport const ARCHETYPES: Readonly<Record<ArchetypeId, ArchetypeDefinition>> = {\n\t\"fabric.Party\": {\n\t\tid: \"fabric.Party\", version: \"0.1\", description: \"A person or organization participating in business relationships.\",\n\t\tstates: states([[\"prospective\", \"initial\"], [\"active\", \"active\"], [\"inactive\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"prospective\", to: \"active\", required: true }, { from: \"active\", to: \"inactive\" }, { from: \"prospective\", to: \"exception\" }, { from: \"active\", to: \"exception\" }],\n\t\tobligations: [\"identity is tenant-scoped\", \"participation is attributable\"],\n\t},\n\t\"fabric.Offering\": {\n\t\tid: \"fabric.Offering\", version: \"0.1\", description: \"Something a party makes available under defined terms.\",\n\t\tstates: states([[\"available\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"retired\" }, { from: \"available\", to: \"exception\" }],\n\t\tobligations: [\"terms are identifiable\", \"availability is explicit\"],\n\t},\n\t\"fabric.Agreement\": {\n\t\tid: \"fabric.Agreement\", version: \"0.1\", description: \"A governed commitment between parties.\",\n\t\tstates: states([[\"proposed\", \"initial\"], [\"committed\", \"active\"], [\"resolved\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"proposed\", to: \"committed\", required: true }, { from: \"committed\", to: \"resolved\", required: true }, { from: \"proposed\", to: \"exception\" }, { from: \"committed\", to: \"exception\" }],\n\t\tobligations: [\"participating parties are attributable\", \"commitment and resolution are auditable\"],\n\t},\n\t\"fabric.Resource\": {\n\t\tid: \"fabric.Resource\", version: \"0.1\", description: \"A capacity or asset allocated by activities.\",\n\t\tstates: states([[\"available\", \"initial\"], [\"allocated\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"allocated\", required: true }, { from: \"allocated\", to: \"available\" }, { from: \"available\", to: \"retired\" }, { from: \"allocated\", to: \"exception\" }],\n\t\tobligations: [\"allocation is identifiable\", \"conflicting allocation is governed\"],\n\t},\n\t\"fabric.Activity\": {\n\t\tid: \"fabric.Activity\", version: \"0.1\", description: \"Work planned and performed toward an outcome.\",\n\t\tstates: states([[\"planned\", \"initial\"], [\"executing\", \"active\"], [\"waiting\", \"waiting\"], [\"completed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"planned\", to: \"executing\", required: true }, { from: \"executing\", to: \"waiting\" }, { from: \"waiting\", to: \"executing\" }, { from: \"executing\", to: \"completed\", required: true }, { from: \"waiting\", to: \"completed\" }, { from: \"planned\", to: \"exception\" }, { from: \"executing\", to: \"exception\" }, { from: \"waiting\", to: \"exception\" }],\n\t\tobligations: [\"responsible party is attributable\", \"resource use and outcome are auditable\"],\n\t},\n\t\"fabric.Settlement\": {\n\t\tid: \"fabric.Settlement\", version: \"0.1\", description: \"Resolution of value exchange associated with an agreement.\",\n\t\tstates: states([[\"pending\", \"initial\"], [\"settled\", \"terminal\"], [\"reversed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"pending\", to: \"settled\", required: true }, { from: \"settled\", to: \"reversed\" }, { from: \"pending\", to: \"exception\" }],\n\t\tobligations: [\"value and currency are explicit\", \"settlement is attributable to an agreement\"],\n\t},\n};\n\nexport function archetypeSemantics(reference: ArchetypeReference): Record<string, JsonValue> {\n\treturn { [ARCHETYPE_SEMANTIC_KEY]: reference as unknown as JsonValue };\n}\n\nexport function readArchetypeReference(\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeReference | undefined {\n\tconst value = objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY];\n\tif (value === undefined) return undefined;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, JsonValue>;\n\tif (typeof record.id !== \"string\" || typeof record.version !== \"string\" || !record.stateMap || typeof record.stateMap !== \"object\" || Array.isArray(record.stateMap)) return undefined;\n\tif (!Object.values(record.stateMap).every((state) => typeof state === \"string\")) return undefined;\n\treturn { id: record.id as ArchetypeId, version: record.version, stateMap: record.stateMap as Record<string, string> };\n}\n\nconst transitionKey = (from: string, to: string) => `${from}->${to}`;\n\nexport function validateArchetypeConformance(\n\tmanifest: ModuleManifest,\n): ArchetypeConformanceReport[] {\n\treturn manifest.objectTypes\n\t\t.filter((objectType) => objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY] !== undefined)\n\t\t.map((objectType) => validateObject(manifest, objectType));\n}\n\nfunction validateObject(\n\tmanifest: ModuleManifest,\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeConformanceReport {\n\tconst findings: ConformanceFinding[] = [];\n\tconst reference = readArchetypeReference(objectType);\n\tif (!reference) {\n\t\tfindings.push({ code: \"invalid_annotation\", objectType: objectType.type, message: `Object \"${objectType.type}\" has an invalid ${ARCHETYPE_SEMANTIC_KEY} annotation.` });\n\t\treturn { conforms: false, objectType: objectType.type, findings };\n\t}\n\tconst definition = ARCHETYPES[reference.id];\n\tif (!definition) {\n\t\tfindings.push({ code: \"unknown_archetype\", objectType: objectType.type, message: `Unknown archetype \"${reference.id}\".` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tif (reference.version !== definition.version) {\n\t\tfindings.push({ code: \"unsupported_archetype_version\", objectType: objectType.type, message: `Archetype \"${reference.id}\" supports version ${definition.version}, received ${reference.version}.` });\n\t}\n\tconst machine = (manifest.stateMachines ?? []).find((candidate) => candidate.entityType === objectType.type);\n\tif (!machine) {\n\t\tfindings.push({ code: \"missing_state_machine\", objectType: objectType.type, message: `Object \"${objectType.type}\" needs a state machine for archetype conformance.` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tfor (const state of machine.states) {\n\t\tconst mapped = reference.stateMap[state.id];\n\t\tif (!mapped) {\n\t\t\tfindings.push({ code: \"unmapped_state\", objectType: objectType.type, state: state.id, message: `State \"${state.id}\" is not mapped.` });\n\t\t\tcontinue;\n\t\t}\n\t\tconst base = definition.states[mapped];\n\t\tif (!base) {\n\t\t\tfindings.push({ code: \"unknown_archetype_state\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" maps to unknown archetype state \"${mapped}\".` });\n\t\t} else if (base.stateClass !== state.stateClass) {\n\t\t\tfindings.push({ code: \"incompatible_state_class\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" (${state.stateClass}) is incompatible with \"${mapped}\" (${base.stateClass}).` });\n\t\t}\n\t}\n\tconst permitted = new Set(definition.transitions.map((transition) => transitionKey(transition.from, transition.to)));\n\tconst realized = new Set<string>();\n\tfor (const transition of machine.transitions) {\n\t\tconst from = reference.stateMap[transition.from];\n\t\tconst to = reference.stateMap[transition.to];\n\t\tif (!from || !to) continue;\n\t\tif (to === \"exception\" && !transition.hasGuard) {\n\t\t\tfindings.push({ code: \"exception_transition_unguarded\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Exception transition \"${transition.from}\" -> \"${transition.to}\" must declare a governance guard.` });\n\t\t}\n\t\tif (from !== to && !permitted.has(transitionKey(from, to))) {\n\t\t\tfindings.push({ code: \"transition_not_permitted\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Transition \"${transition.from}\" -> \"${transition.to}\" maps to disallowed archetype transition \"${from}\" -> \"${to}\".` });\n\t\t} else if (from !== to) {\n\t\t\trealized.add(transitionKey(from, to));\n\t\t}\n\t}\n\tfor (const required of definition.transitions.filter((transition) => transition.required)) {\n\t\tif (!realized.has(transitionKey(required.from, required.to))) {\n\t\t\tfindings.push({ code: \"required_transition_unreachable\", objectType: objectType.type, state: required.from, target: required.to, message: `Required archetype transition \"${required.from}\" -> \"${required.to}\" is not realized.` });\n\t\t}\n\t}\n\treturn { conforms: findings.length === 0, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n}\n\nexport function assertArchetypeConformance(module: FabricModule<unknown>): void {\n\tconst failures = validateArchetypeConformance(exportModuleManifest(module)).filter((report) => !report.conforms);\n\tif (failures.length > 0) {\n\t\tthrow new Error(`Archetype conformance failed:\\n${failures.flatMap((report) => report.findings.map((finding) => `- ${report.objectType}: ${finding.message}`)).join(\"\\n\")}`);\n\t}\n}\n\nexport const archetypeConformanceAdapter: ManifestConformanceAdapter = {\n\tid: \"@fabricorg/archetypes\",\n\tevaluate: validateArchetypeConformance,\n};\n"],"mappings":";AAAA;AAAA,EACC;AAAA,OAMM;AAEA,IAAM,yBAAyB;AAoEtC,IAAM,SAAS,CAAC,gBACf,OAAO,YAAY,YAAY,IAAI,CAAC,CAAC,IAAI,UAAU,MAAM,CAAC,IAAI,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC;AAE5E,IAAM,aAAiE;AAAA,EAC7E,gBAAgB;AAAA,IACf,IAAI;AAAA,IAAgB,SAAS;AAAA,IAAO,aAAa;AAAA,IACjD,QAAQ,OAAO,CAAC,CAAC,eA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AAW,MAAM,OAAO,SAAS,MAAM,QAAQ,SAAS,IAAI,SAAS,kCAAkC,SAAS,IAAI,SAAS,SAAS,EAAE,qBAAqB,CAAC;AAAA,IACpO;AAAA,EACD;AACA,SAAO,EAAE,UAAU,SAAS,WAAW,GAAG,YAAY,WAAW,MAAM,WAAW,GAAG,UAAU,EAAE,IAAI,UAAU,OAAO,IAAI,SAAS;AACpI;AAEO,SAAS,2BAA2B,QAAqC;AAC/E,QAAM,WAAW,6BAA6B,qBAAqB,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,QAAQ;AAC/G,MAAI,SAAS,SAAS,GAAG;AACxB,UAAM,IAAI,MAAM;AAAA,EAAkC,SAAS,QAAQ,CAAC,WAAW,OAAO,SAAS,IAAI,CAAC,YAAY,KAAK,OAAO,UAAU,KAAK,QAAQ,OAAO,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;AAAA,EAC5K;AACD;AAEO,IAAM,8BAA0D;AAAA,EACtE,IAAI;AAAA,EACJ,UAAU;AACX;","names":[]}
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import {\n\texportModuleManifest,\n\ttype FabricModule,\n\ttype JsonValue,\n\ttype ModuleManifest,\n\ttype ModuleManifestObjectType,\n\ttype StateClass,\n} from \"@fabricorg/platform\";\n\nexport const ARCHETYPE_SEMANTIC_KEY = \"fabric.archetype\" as const;\n\nexport type ArchetypeId =\n\t| \"fabric.Party\"\n\t| \"fabric.Offering\"\n\t| \"fabric.Agreement\"\n\t| \"fabric.Resource\"\n\t| \"fabric.Activity\"\n\t| \"fabric.Settlement\";\n\nexport interface ArchetypeReference {\n\tid: ArchetypeId;\n\tversion: string;\n\tstateMap: Record<string, string>;\n}\n\nexport interface ArchetypeState {\n\tid: string;\n\tstateClass: StateClass;\n}\n\nexport interface ArchetypeTransition {\n\tfrom: string;\n\tto: string;\n\trequired?: boolean;\n}\n\nexport interface ArchetypeDefinition {\n\tid: ArchetypeId;\n\tversion: string;\n\tdescription: string;\n\tstates: Record<string, ArchetypeState>;\n\ttransitions: ArchetypeTransition[];\n\tobligations: string[];\n}\n\nexport type ConformanceFindingCode =\n\t| \"invalid_annotation\"\n\t| \"unknown_archetype\"\n\t| \"unsupported_archetype_version\"\n\t| \"missing_state_machine\"\n\t| \"unmapped_state\"\n\t| \"unknown_mapped_state\"\n\t| \"unknown_archetype_state\"\n\t| \"incompatible_state_class\"\n\t| \"transition_not_permitted\"\n\t| \"exception_transition_unguarded\"\n\t| \"required_transition_unreachable\";\n\nexport interface ConformanceFinding {\n\tcode: ConformanceFindingCode;\n\tmessage: string;\n\tobjectType: string;\n\tstate?: string;\n\ttarget?: string;\n}\n\nexport interface ArchetypeConformanceReport {\n\tconforms: boolean;\n\tobjectType: string;\n\tarchetype?: string;\n\tfindings: ConformanceFinding[];\n}\n\nexport interface ManifestConformanceAdapter {\n\tid: string;\n\tevaluate(manifest: ModuleManifest): ArchetypeConformanceReport[];\n}\n\nconst states = (definitions: Array<[string, StateClass]>): Record<string, ArchetypeState> =>\n\tObject.fromEntries(definitions.map(([id, stateClass]) => [id, { id, stateClass }]));\n\nexport const ARCHETYPES: Readonly<Record<ArchetypeId, ArchetypeDefinition>> = {\n\t\"fabric.Party\": {\n\t\tid: \"fabric.Party\", version: \"0.1\", description: \"A person or organization participating in business relationships.\",\n\t\tstates: states([[\"prospective\", \"initial\"], [\"active\", \"active\"], [\"inactive\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"prospective\", to: \"active\", required: true }, { from: \"active\", to: \"inactive\" }, { from: \"prospective\", to: \"exception\" }, { from: \"active\", to: \"exception\" }],\n\t\tobligations: [\"identity is tenant-scoped\", \"participation is attributable\"],\n\t},\n\t\"fabric.Offering\": {\n\t\tid: \"fabric.Offering\", version: \"0.1\", description: \"Something a party makes available under defined terms.\",\n\t\tstates: states([[\"available\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"retired\" }, { from: \"available\", to: \"exception\" }],\n\t\tobligations: [\"terms are identifiable\", \"availability is explicit\"],\n\t},\n\t\"fabric.Agreement\": {\n\t\tid: \"fabric.Agreement\", version: \"0.1\", description: \"A governed commitment between parties.\",\n\t\tstates: states([[\"proposed\", \"initial\"], [\"committed\", \"active\"], [\"resolved\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"proposed\", to: \"committed\", required: true }, { from: \"committed\", to: \"resolved\", required: true }, { from: \"proposed\", to: \"exception\" }, { from: \"committed\", to: \"exception\" }],\n\t\tobligations: [\"participating parties are attributable\", \"commitment and resolution are auditable\"],\n\t},\n\t\"fabric.Resource\": {\n\t\tid: \"fabric.Resource\", version: \"0.1\", description: \"A capacity or asset allocated by activities.\",\n\t\tstates: states([[\"available\", \"initial\"], [\"allocated\", \"active\"], [\"retired\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"available\", to: \"allocated\", required: true }, { from: \"allocated\", to: \"available\" }, { from: \"available\", to: \"retired\" }, { from: \"allocated\", to: \"exception\" }],\n\t\tobligations: [\"allocation is identifiable\", \"conflicting allocation is governed\"],\n\t},\n\t\"fabric.Activity\": {\n\t\tid: \"fabric.Activity\", version: \"0.1\", description: \"Work planned and performed toward an outcome.\",\n\t\tstates: states([[\"planned\", \"initial\"], [\"executing\", \"active\"], [\"waiting\", \"waiting\"], [\"completed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"planned\", to: \"executing\", required: true }, { from: \"executing\", to: \"waiting\" }, { from: \"waiting\", to: \"executing\" }, { from: \"executing\", to: \"completed\", required: true }, { from: \"waiting\", to: \"completed\" }, { from: \"planned\", to: \"exception\" }, { from: \"executing\", to: \"exception\" }, { from: \"waiting\", to: \"exception\" }],\n\t\tobligations: [\"responsible party is attributable\", \"resource use and outcome are auditable\"],\n\t},\n\t\"fabric.Settlement\": {\n\t\tid: \"fabric.Settlement\", version: \"0.1\", description: \"Resolution of value exchange associated with an agreement.\",\n\t\tstates: states([[\"pending\", \"initial\"], [\"settled\", \"terminal\"], [\"reversed\", \"terminal\"], [\"exception\", \"exception\"]]),\n\t\ttransitions: [{ from: \"pending\", to: \"settled\", required: true }, { from: \"settled\", to: \"reversed\" }, { from: \"pending\", to: \"exception\" }],\n\t\tobligations: [\"value and currency are explicit\", \"settlement is attributable to an agreement\"],\n\t},\n};\n\nexport function archetypeSemantics(reference: ArchetypeReference): Record<string, JsonValue> {\n\treturn { [ARCHETYPE_SEMANTIC_KEY]: reference as unknown as JsonValue };\n}\n\nexport function readArchetypeReference(\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeReference | undefined {\n\tconst value = objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY];\n\tif (value === undefined) return undefined;\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, JsonValue>;\n\tif (typeof record.id !== \"string\" || typeof record.version !== \"string\" || !record.stateMap || typeof record.stateMap !== \"object\" || Array.isArray(record.stateMap)) return undefined;\n\tif (!Object.values(record.stateMap).every((state) => typeof state === \"string\")) return undefined;\n\treturn { id: record.id as ArchetypeId, version: record.version, stateMap: record.stateMap as Record<string, string> };\n}\n\nconst transitionKey = (from: string, to: string) => `${from}->${to}`;\n\nexport function validateArchetypeConformance(\n\tmanifest: ModuleManifest,\n): ArchetypeConformanceReport[] {\n\treturn manifest.objectTypes\n\t\t.filter((objectType) => objectType.semantics?.[ARCHETYPE_SEMANTIC_KEY] !== undefined)\n\t\t.map((objectType) => validateObject(manifest, objectType));\n}\n\nfunction validateObject(\n\tmanifest: ModuleManifest,\n\tobjectType: ModuleManifestObjectType,\n): ArchetypeConformanceReport {\n\tconst findings: ConformanceFinding[] = [];\n\tconst reference = readArchetypeReference(objectType);\n\tif (!reference) {\n\t\tfindings.push({ code: \"invalid_annotation\", objectType: objectType.type, message: `Object \"${objectType.type}\" has an invalid ${ARCHETYPE_SEMANTIC_KEY} annotation.` });\n\t\treturn { conforms: false, objectType: objectType.type, findings };\n\t}\n\tconst definition = ARCHETYPES[reference.id];\n\tif (!definition) {\n\t\tfindings.push({ code: \"unknown_archetype\", objectType: objectType.type, message: `Unknown archetype \"${reference.id}\".` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tif (reference.version !== definition.version) {\n\t\tfindings.push({ code: \"unsupported_archetype_version\", objectType: objectType.type, message: `Archetype \"${reference.id}\" supports version ${definition.version}, received ${reference.version}.` });\n\t}\n\tconst machine = (manifest.stateMachines ?? []).find((candidate) => candidate.entityType === objectType.type);\n\tif (!machine) {\n\t\tfindings.push({ code: \"missing_state_machine\", objectType: objectType.type, message: `Object \"${objectType.type}\" needs a state machine for archetype conformance.` });\n\t\treturn { conforms: false, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n\t}\n\tconst declaredStates = new Set(machine.states.map((state) => state.id));\n\tfor (const state of Object.keys(reference.stateMap)) {\n\t\tif (!declaredStates.has(state)) findings.push({ code: \"unknown_mapped_state\", objectType: objectType.type, state, message: `State mapping \"${state}\" does not name a declared state.` });\n\t}\n\tfor (const state of machine.states) {\n\t\tconst mapped = reference.stateMap[state.id];\n\t\tif (!mapped) {\n\t\t\tfindings.push({ code: \"unmapped_state\", objectType: objectType.type, state: state.id, message: `State \"${state.id}\" is not mapped.` });\n\t\t\tcontinue;\n\t\t}\n\t\tconst base = definition.states[mapped];\n\t\tif (!base) {\n\t\t\tfindings.push({ code: \"unknown_archetype_state\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" maps to unknown archetype state \"${mapped}\".` });\n\t\t} else if (base.stateClass !== state.stateClass) {\n\t\t\tfindings.push({ code: \"incompatible_state_class\", objectType: objectType.type, state: state.id, target: mapped, message: `State \"${state.id}\" (${state.stateClass}) is incompatible with \"${mapped}\" (${base.stateClass}).` });\n\t\t}\n\t}\n\tconst permitted = new Set(definition.transitions.map((transition) => transitionKey(transition.from, transition.to)));\n\tconst realized = new Set<string>();\n\tfor (const transition of machine.transitions) {\n\t\tconst from = reference.stateMap[transition.from];\n\t\tconst to = reference.stateMap[transition.to];\n\t\tif (!from || !to) continue;\n\t\tif (to === \"exception\" && !transition.hasGuard) {\n\t\t\tfindings.push({ code: \"exception_transition_unguarded\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Exception transition \"${transition.from}\" -> \"${transition.to}\" must declare a governance guard.` });\n\t\t}\n\t\tif (from !== to && !permitted.has(transitionKey(from, to))) {\n\t\t\tfindings.push({ code: \"transition_not_permitted\", objectType: objectType.type, state: transition.from, target: transition.to, message: `Transition \"${transition.from}\" -> \"${transition.to}\" maps to disallowed archetype transition \"${from}\" -> \"${to}\".` });\n\t\t} else if (from !== to) {\n\t\t\trealized.add(transitionKey(from, to));\n\t\t}\n\t}\n\tfor (const required of definition.transitions.filter((transition) => transition.required)) {\n\t\tif (!realized.has(transitionKey(required.from, required.to))) {\n\t\t\tfindings.push({ code: \"required_transition_unreachable\", objectType: objectType.type, state: required.from, target: required.to, message: `Required archetype transition \"${required.from}\" -> \"${required.to}\" is not realized.` });\n\t\t}\n\t}\n\treturn { conforms: findings.length === 0, objectType: objectType.type, archetype: `${reference.id}@${reference.version}`, findings };\n}\n\nexport function assertArchetypeConformance(module: FabricModule<unknown>): void {\n\tconst failures = validateArchetypeConformance(exportModuleManifest(module)).filter((report) => !report.conforms);\n\tif (failures.length > 0) {\n\t\tthrow new Error(`Archetype conformance failed:\\n${failures.flatMap((report) => report.findings.map((finding) => `- ${report.objectType}: ${finding.message}`)).join(\"\\n\")}`);\n\t}\n}\n\nexport const archetypeConformanceAdapter: ManifestConformanceAdapter = {\n\tid: \"@fabricorg/archetypes\",\n\tevaluate: validateArchetypeConformance,\n};\n"],"mappings":";AAAA;AAAA,EACC;AAAA,OAMM;AAEA,IAAM,yBAAyB;AAqEtC,IAAM,SAAS,CAAC,gBACf,OAAO,YAAY,YAAY,IAAI,CAAC,CAAC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1.0.0",
4
4
  "description": "Optional cross-industry archetype vocabulary and conformance tools for Fabric module manifests.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,14 +24,15 @@
24
24
  "README.md",
25
25
  "CHANGELOG.md"
26
26
  ],
27
- "dependencies": {
28
- "@fabricorg/platform": "^0.11.0"
27
+ "peerDependencies": {
28
+ "@fabricorg/platform": "^0.12.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.10.0",
32
32
  "tsup": "^8.5.0",
33
33
  "typescript": "^5.7.3",
34
- "vitest": "^4.1.5"
34
+ "vitest": "^4.1.5",
35
+ "@fabricorg/platform": "^0.12.0"
35
36
  },
36
37
  "engines": {
37
38
  "node": ">=20"