@fabricorg/platform 0.2.2 → 0.3.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.
- package/CHANGELOG.md +31 -0
- package/README.md +4 -5
- package/dist/actions/index.cjs +11 -11
- package/dist/actions/index.d.cts +29 -0
- package/dist/actions/index.d.ts +29 -0
- package/dist/actions/index.js +1 -1
- package/dist/{chunk-6FMW4NF6.js → chunk-BJYRMUN2.js} +2 -2
- package/dist/{chunk-6FMW4NF6.js.map → chunk-BJYRMUN2.js.map} +1 -1
- package/dist/{chunk-7KJHGAZY.cjs → chunk-EO4VSB2O.cjs} +3 -3
- package/dist/chunk-EO4VSB2O.cjs.map +1 -0
- package/dist/{chunk-LYX73U3P.cjs → chunk-GLUBIGV2.cjs} +8 -8
- package/dist/chunk-GLUBIGV2.cjs.map +1 -0
- package/dist/{chunk-3F6FKQZA.js → chunk-O5WVBQ7P.js} +2 -2
- package/dist/chunk-O5WVBQ7P.js.map +1 -0
- package/dist/{chunk-PXMKCAQI.js → chunk-PZT7TUG4.js} +5 -5
- package/dist/chunk-PZT7TUG4.js.map +1 -0
- package/dist/{chunk-KQEBNUZI.cjs → chunk-RMI3BIND.cjs} +2 -2
- package/dist/{chunk-KQEBNUZI.cjs.map → chunk-RMI3BIND.cjs.map} +1 -1
- package/dist/{chunk-3A6FU3KV.js → chunk-T2JLSZN6.js} +2 -2
- package/dist/chunk-T2JLSZN6.js.map +1 -0
- package/dist/{chunk-GB2PSZ33.cjs → chunk-UV252FLT.cjs} +2 -2
- package/dist/chunk-UV252FLT.cjs.map +1 -0
- package/dist/displays/index.cjs +5 -5
- package/dist/displays/index.d.cts +1 -1
- package/dist/displays/index.d.ts +1 -1
- package/dist/displays/index.js +1 -1
- package/dist/index.cjs +31 -31
- package/dist/index.js +4 -4
- package/dist/modules/index.cjs +11 -11
- package/dist/modules/index.d.cts +4 -3
- package/dist/modules/index.d.ts +4 -3
- package/dist/modules/index.js +4 -4
- package/dist/state-machines/index.cjs +7 -7
- package/dist/state-machines/index.d.cts +1 -1
- package/dist/state-machines/index.d.ts +1 -1
- package/dist/state-machines/index.js +1 -1
- package/package.json +196 -197
- package/dist/chunk-3A6FU3KV.js.map +0 -1
- package/dist/chunk-3F6FKQZA.js.map +0 -1
- package/dist/chunk-7KJHGAZY.cjs.map +0 -1
- package/dist/chunk-GB2PSZ33.cjs.map +0 -1
- package/dist/chunk-LYX73U3P.cjs.map +0 -1
- package/dist/chunk-PXMKCAQI.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,198 +1,197 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
2
|
+
"name": "@fabricorg/platform",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Generic, vertical-agnostic runtime for ontology-based business applications. Provides actions, modules, events, policies, state machines, adapters, displays, projections, privacy, and evidence contracts. Zero runtime dependencies; portable across any database client and any vertical (lending, insurance, healthcare, legal, etc.).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fabric",
|
|
7
|
+
"ontology",
|
|
8
|
+
"action-runtime",
|
|
9
|
+
"event-sourcing",
|
|
10
|
+
"saga",
|
|
11
|
+
"state-machine",
|
|
12
|
+
"policy-engine",
|
|
13
|
+
"adapter-registry"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Fabric",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/Fabric-Pro/fabric-platform.git",
|
|
20
|
+
"directory": "packages/platform"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/Fabric-Pro/fabric-platform#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Fabric-Pro/fabric-platform/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./actions": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/actions/index.d.ts",
|
|
44
|
+
"default": "./dist/actions/index.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/actions/index.d.cts",
|
|
48
|
+
"default": "./dist/actions/index.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./adapters": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/adapters/index.d.ts",
|
|
54
|
+
"default": "./dist/adapters/index.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/adapters/index.d.cts",
|
|
58
|
+
"default": "./dist/adapters/index.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"./displays": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/displays/index.d.ts",
|
|
64
|
+
"default": "./dist/displays/index.js"
|
|
65
|
+
},
|
|
66
|
+
"require": {
|
|
67
|
+
"types": "./dist/displays/index.d.cts",
|
|
68
|
+
"default": "./dist/displays/index.cjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"./events": {
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/events/index.d.ts",
|
|
74
|
+
"default": "./dist/events/index.js"
|
|
75
|
+
},
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./dist/events/index.d.cts",
|
|
78
|
+
"default": "./dist/events/index.cjs"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"./evidence": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/evidence/index.d.ts",
|
|
84
|
+
"default": "./dist/evidence/index.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/evidence/index.d.cts",
|
|
88
|
+
"default": "./dist/evidence/index.cjs"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"./ids": {
|
|
92
|
+
"import": {
|
|
93
|
+
"types": "./dist/ids/index.d.ts",
|
|
94
|
+
"default": "./dist/ids/index.js"
|
|
95
|
+
},
|
|
96
|
+
"require": {
|
|
97
|
+
"types": "./dist/ids/index.d.cts",
|
|
98
|
+
"default": "./dist/ids/index.cjs"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"./modules": {
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./dist/modules/index.d.ts",
|
|
104
|
+
"default": "./dist/modules/index.js"
|
|
105
|
+
},
|
|
106
|
+
"require": {
|
|
107
|
+
"types": "./dist/modules/index.d.cts",
|
|
108
|
+
"default": "./dist/modules/index.cjs"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"./objects": {
|
|
112
|
+
"import": {
|
|
113
|
+
"types": "./dist/objects/index.d.ts",
|
|
114
|
+
"default": "./dist/objects/index.js"
|
|
115
|
+
},
|
|
116
|
+
"require": {
|
|
117
|
+
"types": "./dist/objects/index.d.cts",
|
|
118
|
+
"default": "./dist/objects/index.cjs"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"./policies": {
|
|
122
|
+
"import": {
|
|
123
|
+
"types": "./dist/policies/index.d.ts",
|
|
124
|
+
"default": "./dist/policies/index.js"
|
|
125
|
+
},
|
|
126
|
+
"require": {
|
|
127
|
+
"types": "./dist/policies/index.d.cts",
|
|
128
|
+
"default": "./dist/policies/index.cjs"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"./privacy": {
|
|
132
|
+
"import": {
|
|
133
|
+
"types": "./dist/privacy/index.d.ts",
|
|
134
|
+
"default": "./dist/privacy/index.js"
|
|
135
|
+
},
|
|
136
|
+
"require": {
|
|
137
|
+
"types": "./dist/privacy/index.d.cts",
|
|
138
|
+
"default": "./dist/privacy/index.cjs"
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"./projections": {
|
|
142
|
+
"import": {
|
|
143
|
+
"types": "./dist/projections/index.d.ts",
|
|
144
|
+
"default": "./dist/projections/index.js"
|
|
145
|
+
},
|
|
146
|
+
"require": {
|
|
147
|
+
"types": "./dist/projections/index.d.cts",
|
|
148
|
+
"default": "./dist/projections/index.cjs"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"./state-machines": {
|
|
152
|
+
"import": {
|
|
153
|
+
"types": "./dist/state-machines/index.d.ts",
|
|
154
|
+
"default": "./dist/state-machines/index.js"
|
|
155
|
+
},
|
|
156
|
+
"require": {
|
|
157
|
+
"types": "./dist/state-machines/index.d.cts",
|
|
158
|
+
"default": "./dist/state-machines/index.cjs"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"./testing": {
|
|
162
|
+
"import": {
|
|
163
|
+
"types": "./dist/testing/index.d.ts",
|
|
164
|
+
"default": "./dist/testing/index.js"
|
|
165
|
+
},
|
|
166
|
+
"require": {
|
|
167
|
+
"types": "./dist/testing/index.d.cts",
|
|
168
|
+
"default": "./dist/testing/index.cjs"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
"files": [
|
|
173
|
+
"dist",
|
|
174
|
+
"README.md",
|
|
175
|
+
"CHANGELOG.md",
|
|
176
|
+
"LICENSE"
|
|
177
|
+
],
|
|
178
|
+
"dependencies": {},
|
|
179
|
+
"devDependencies": {
|
|
180
|
+
"@types/node": "^22.10.0",
|
|
181
|
+
"tsup": "^8.5.0",
|
|
182
|
+
"typescript": "^5.7.3",
|
|
183
|
+
"vitest": "^4.1.5"
|
|
184
|
+
},
|
|
185
|
+
"engines": {
|
|
186
|
+
"node": ">=20"
|
|
187
|
+
},
|
|
188
|
+
"publishConfig": {
|
|
189
|
+
"access": "public"
|
|
190
|
+
},
|
|
191
|
+
"scripts": {
|
|
192
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
193
|
+
"build": "tsup",
|
|
194
|
+
"type-check": "tsc --noEmit",
|
|
195
|
+
"test": "vitest run --passWithNoTests"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../state-machines/engine.ts"],"names":[],"mappings":";AAuBA,IAAM,QAAA,uBAAe,GAAA,EAAoC;AAMlD,SAAS,qBAAqB,GAAA,EAAmC;AACvE,EAAA,IAAI,QAAA,CAAS,GAAA,CAAI,GAAA,CAAI,UAAU,CAAA,EAAG;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,+BAAA,EAAkC,GAAA,CAAI,UAAU,CAAA,wBAAA,CAA0B,CAAA;AAAA,EAC3F;AACA,EAAA,QAAA,CAAS,GAAA,CAAI,GAAA,CAAI,UAAA,EAAY,GAAG,CAAA;AACjC;AAMO,SAAS,8BAA8B,GAAA,EAAmC;AAChF,EAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,GAAA,CAAI,UAAU,CAAA,EAAG;AAClC,IAAA,oBAAA,CAAqB,GAAG,CAAA;AAAA,EACzB;AACD;AAKO,SAAS,oBAAoB,UAAA,EAAwD;AAC3F,EAAA,OAAO,QAAA,CAAS,IAAI,UAAU,CAAA;AAC/B;AAMO,SAAS,kBAAA,CACf,UAAA,EACA,IAAA,EACA,EAAA,EACA,QAAA,EACqC;AACrC,EAAA,MAAM,EAAA,GAAK,QAAA,CAAS,GAAA,CAAI,UAAU,CAAA;AAClC,EAAA,IAAI,CAAC,EAAA,EAAI;AACR,IAAA,OAAO;AAAA,MACN,KAAA,EAAO,KAAA;AAAA,MACP,KAAA,EAAO,gDAAgD,UAAU,CAAA,EAAA;AAAA,KAClE;AAAA,EACD;AAEA,EAAA,MAAM,OAAA,GAAU,EAAA,CAAG,MAAA,CAAO,IAAI,CAAA;AAC9B,EAAA,IAAI,CAAC,OAAA,EAAS;AACb,IAAA,OAAO;AAAA,MACN,KAAA,EAAO,KAAA;AAAA,MACP,KAAA,EAAO,CAA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;AAC9F,EAAA,MAAM,EAAA,GAAK,QAAA,CAAS,GAAA,CAAI,UAAU,CAAA;AAClC,EAAA,IAAI,CAAC,EAAA,EAAI;AACR,IAAA,OAAO,MAAA;AAAA,EACR;AACA,EAAA,OAAO,EAAA,CAAG,MAAA,CAAO,KAAK,CAAA,EAAG,UAAA;AAC1B","file":"chunk-3A6FU3KV.js","sourcesContent":["import type { StateClass, StateDefinition } from \"./index\";\n\nexport interface StateMachineDefinition {\n\tentityType: string;\n\tstates: Record<string, StateDefinition>;\n\ttransitions: Array<{\n\t\tfrom: string;\n\t\tto: string;\n\t\tcausedByAction: string;\n\t\tguard?: (ctx: TransitionContext) => boolean | Promise<boolean>;\n\t}>;\n}\n\nexport type StateMachineDatabaseClient = any;\n\nexport interface TransitionContext<TDb = StateMachineDatabaseClient> {\n\tentity: Record<string, unknown>;\n\tactionInvocationId: string;\n\tactorId: string;\n\tparameters: unknown;\n\tdb: TDb;\n}\n\nconst registry = new Map<string, StateMachineDefinition>();\n\n/**\n * Register a state-machine definition for an entity type.\n * Throws if a definition for this entity type is already registered.\n */\nexport function registerStateMachine(def: StateMachineDefinition): void {\n\tif (registry.has(def.entityType)) {\n\t\tthrow new Error(`State machine for entity type \"${def.entityType}\" is already registered.`);\n\t}\n\tregistry.set(def.entityType, def);\n}\n\n/**\n * Register a state-machine definition only if one for this entity type\n * is not already registered. Idempotent — safe to call multiple times.\n */\nexport function registerStateMachineIfMissing(def: StateMachineDefinition): void {\n\tif (!registry.has(def.entityType)) {\n\t\tregisterStateMachine(def);\n\t}\n}\n\n/**\n * Resolve a previously registered state-machine definition by entity type.\n */\nexport function resolveStateMachine(entityType: string): StateMachineDefinition | undefined {\n\treturn registry.get(entityType);\n}\n\n/**\n * Validate whether a transition is allowed for the given entity type,\n * from state, to state, and action ID.\n */\nexport function validateTransition(\n\tentityType: string,\n\tfrom: string,\n\tto: string,\n\tactionId: string,\n): { valid: boolean; error?: string } {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `No state machine registered for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst fromDef = sm.states[from];\n\tif (!fromDef) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `State \"${from}\" does not exist in state machine for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst toDef = sm.states[to];\n\tif (!toDef) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `State \"${to}\" does not exist in state machine for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst transitionExists = sm.transitions.some(\n\t\t(t) => t.from === from && t.to === to && t.causedByAction === actionId,\n\t);\n\tif (!transitionExists) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `Transition from \"${from}\" to \"${to}\" via action \"${actionId}\" is not defined for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\treturn { valid: true };\n}\n\n/**\n * Get all allowed transitions from a given state for an entity type.\n */\nexport function getAllowedTransitions(\n\tentityType: string,\n\tfrom: string,\n): Array<{ to: string; causedByAction: string }> {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn [];\n\t}\n\treturn sm.transitions\n\t\t.filter((t) => t.from === from)\n\t\t.map((t) => ({ to: t.to, causedByAction: t.causedByAction }));\n}\n\n/**\n * Get the StateClass of a given state for an entity type.\n */\nexport function getEntityStateClass(entityType: string, state: string): StateClass | undefined {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn undefined;\n\t}\n\treturn sm.states[state]?.stateClass;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../displays/index.ts"],"names":[],"mappings":";;;AAoCA,IAAM,QAAA,uBAAe,GAAA,EAA6B;AAE3C,SAAS,uBAAA,CAAwB,WAAmB,QAAA,EAAiC;AAC3F,EAAA,QAAA,CAAS,GAAA,CAAI,WAAW,QAAQ,CAAA;AACjC;AAEO,SAAS,uBAAuB,SAA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EAAoB,EAAE,CAAA;AAChE,EAAA,MAAA,CAAO,WAAA,CAAY,QAAA,CAAS,KAAA,EAAO,kBAAkB,CAAA;AACrD,EAAA,MAAA,CAAO,WAAA,CAAY,QAAA,CAAS,QAAA,EAAU,qDAAqD,CAAA;AAG3F,EAAA,uBAAA,CAAwB,gBAAA,EAAkB,OAAO,QAAA,EAAU,GAAA,KAAQ;AAClE,IAAA,OAAO;AAAA,MACN,KAAA,EAAO,CAAA,OAAA,EAAU,GAAA,EAAK,QAAA,IAAY,QAAQ,CAAA;AAAA,KAC3C;AAAA,EACD,CAAC,CAAA;AACD,EAAA,MAAM,cAAc,MAAM,kBAAA;AAAA,IACzB,gBAAA;AAAA,IACA,EAAC;AAAA,IACD,EAAE,QAAA,EAAU,KAAA,EAAO,SAAS,KAAA,EAAO,EAAA,EAAI,EAAC;AAAE,GAC3C;AACA,EAAA,MAAA,CAAO,WAAA,CAAY,WAAA,CAAY,KAAA,EAAO,YAAY,CAAA;AAElD,EAAA,OAAA,CAAQ,IAAI,2CAAsC,CAAA;AACnD;AAEA,IAAI,YAAY,GAAA,KAAQ,CAAA,OAAA,EAAU,QAAQ,IAAA,CAAK,CAAC,CAAC,CAAA,CAAA,EAAI;AACpD,EAAA,eAAA,EAAgB,CAAE,KAAA,CAAM,CAAC,GAAA,KAAQ;AAChC,IAAA,OAAA,CAAQ,KAAA,CAAM,6CAAwC,GAAG,CAAA;AACzD,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EACf,CAAC,CAAA;AACF","file":"chunk-3F6FKQZA.js","sourcesContent":["import assert from \"node:assert\";\n\nexport interface DisplayDescriptor {\n\ttitle: string;\n\tsubtitle?: string;\n\tstateLabel?: string;\n\tprimaryFacts?: Array<{ label: string; value: string }>;\n}\n\nexport interface CachedDisplayDescriptor extends DisplayDescriptor {\n\t_cachedDisplay?: {\n\t\tsource: \"event_payload\" | \"projection_snapshot\";\n\t\tcursor?: string | null;\n\t\tchecksum?: string;\n\t\tgeneratedAt?: string;\n\t};\n}\n\nexport type DisplayDatabaseClient = any;\n\nexport interface DisplayContext<TDb = DisplayDatabaseClient> {\n\ttenantId: string;\n\tspaceId: string;\n\tdb: TDb;\n}\n\nexport type DisplayRenderer = (\n\tpayload: unknown,\n\tctx?: DisplayContext,\n) => DisplayDescriptor | Promise<DisplayDescriptor>;\n\nexport interface DisplayRendererRegistration {\n\teventType: string;\n\trenderer: DisplayRenderer;\n}\n\nconst registry = new Map<string, DisplayRenderer>();\n\nexport function registerDisplayRenderer(eventType: string, renderer: DisplayRenderer): void {\n\tregistry.set(eventType, renderer);\n}\n\nexport function resolveDisplayRenderer(eventType: string): DisplayRenderer | undefined {\n\treturn registry.get(eventType);\n}\n\nexport function denormalizeDisplaySnapshot(payload: unknown): CachedDisplayDescriptor | undefined {\n\tif (\n\t\tpayload !== null &&\n\t\ttypeof payload === \"object\" &&\n\t\t\"_displaySnapshot\" in payload &&\n\t\tpayload._displaySnapshot !== null &&\n\t\ttypeof payload._displaySnapshot === \"object\" &&\n\t\t\"title\" in payload._displaySnapshot\n\t) {\n\t\treturn payload._displaySnapshot as CachedDisplayDescriptor;\n\t}\n\n\tif (\n\t\tpayload !== null &&\n\t\ttypeof payload === \"object\" &&\n\t\t\"_projectionSnapshot\" in payload &&\n\t\tpayload._projectionSnapshot !== null &&\n\t\ttypeof payload._projectionSnapshot === \"object\" &&\n\t\t\"display\" in payload._projectionSnapshot &&\n\t\tpayload._projectionSnapshot.display !== null &&\n\t\ttypeof payload._projectionSnapshot.display === \"object\" &&\n\t\t\"title\" in payload._projectionSnapshot.display\n\t) {\n\t\tconst snapshot = payload._projectionSnapshot as {\n\t\t\tdisplay: DisplayDescriptor;\n\t\t\teventCursor?: string | null;\n\t\t\tchecksum?: string;\n\t\t\tupdatedAt?: string;\n\t\t};\n\t\treturn {\n\t\t\t...snapshot.display,\n\t\t\t_cachedDisplay: {\n\t\t\t\tsource: \"projection_snapshot\",\n\t\t\t\tcursor: snapshot.eventCursor,\n\t\t\t\tchecksum: snapshot.checksum,\n\t\t\t\tgeneratedAt: snapshot.updatedAt,\n\t\t\t},\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport async function renderEventDisplay(\n\teventType: string,\n\tpayload: unknown,\n\tctx?: DisplayContext,\n): Promise<CachedDisplayDescriptor> {\n\tconst snapshot = denormalizeDisplaySnapshot(payload);\n\tif (snapshot) {\n\t\treturn snapshot;\n\t}\n\n\tconst renderer = resolveDisplayRenderer(eventType);\n\tif (!renderer) {\n\t\treturn {\n\t\t\ttitle: eventType,\n\t\t\tsubtitle: \"No display renderer registered for this event type.\",\n\t\t};\n\t}\n\n\treturn await renderer(payload, ctx);\n}\n\n// Inline test: verify registry round-trip, snapshot denormalization, and fallback.\nasync function _runInlineTests(): Promise<void> {\n\tconst testEventType = \"__TestEvent__\";\n\n\t// 1. Registry round-trip\n\tregisterDisplayRenderer(testEventType, (payload) => ({\n\t\ttitle: `Test: ${(payload as { name: string }).name}`,\n\t\tsubtitle: \"registered renderer\",\n\t}));\n\n\tconst renderer = resolveDisplayRenderer(testEventType);\n\tassert.ok(renderer, \"resolveDisplayRenderer should return the registered renderer\");\n\n\tconst result = await renderEventDisplay(testEventType, { name: \"Alice\" });\n\tassert.strictEqual(result.title, \"Test: Alice\");\n\tassert.strictEqual(result.subtitle, \"registered renderer\");\n\n\t// 2. Snapshot denormalization takes precedence over renderer\n\tconst snapshot: DisplayDescriptor = {\n\t\ttitle: \"Snapshot Title\",\n\t\tsubtitle: \"snapshot subtitle\",\n\t\tstateLabel: \"archived\",\n\t\tprimaryFacts: [{ label: \"ID\", value: \"123\" }],\n\t};\n\tconst snapshotResult = await renderEventDisplay(testEventType, {\n\t\t_displaySnapshot: snapshot,\n\t});\n\tassert.deepStrictEqual(snapshotResult, snapshot);\n\n\t// 3. Fallback for unregistered event type\n\tconst fallback = await renderEventDisplay(\"__UnknownEvent__\", {});\n\tassert.strictEqual(fallback.title, \"__UnknownEvent__\");\n\tassert.strictEqual(fallback.subtitle, \"No display renderer registered for this event type.\");\n\n\t// 4. Async renderer with context\n\tregisterDisplayRenderer(\"__AsyncEvent__\", async (_payload, ctx) => {\n\t\treturn {\n\t\t\ttitle: `Async: ${ctx?.tenantId ?? \"no-ctx\"}`,\n\t\t};\n\t});\n\tconst asyncResult = await renderEventDisplay(\n\t\t\"__AsyncEvent__\",\n\t\t{},\n\t\t{ tenantId: \"t-1\", spaceId: \"s-1\", db: {} },\n\t);\n\tassert.strictEqual(asyncResult.title, \"Async: t-1\");\n\n\tconsole.log(\"✅ display engine inline tests passed\");\n}\n\nif (import.meta.url === `file://${process.argv[1]}`) {\n\t_runInlineTests().catch((err) => {\n\t\tconsole.error(\"❌ display engine inline tests failed\", err);\n\t\tprocess.exit(1);\n\t});\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../displays/index.ts"],"names":["assert"],"mappings":";;;;;;;;;;AAoCA,IAAM,QAAA,uBAAe,GAAA,EAA6B;AAE3C,SAAS,uBAAA,CAAwB,WAAmB,QAAA,EAAiC;AAC3F,EAAA,QAAA,CAAS,GAAA,CAAI,WAAW,QAAQ,CAAA;AACjC;AAEO,SAAS,uBAAuB,SAAA,EAAgD;AACtF,EAAA,OAAO,QAAA,CAAS,IAAI,SAAS,CAAA;AAC9B;AAEO,SAAS,2BAA2B,OAAA,EAAuD;AACjG,EAAA,IACC,YAAY,IAAA,IACZ,OAAO,OAAA,KAAY,QAAA,IACnB,sBAAsB,OAAA,IACtB,OAAA,CAAQ,gBAAA,KAAqB,IAAA,IAC7B,OAAO,OAAA,CAAQ,gBAAA,KAAqB,QAAA,IACpC,OAAA,IAAW,QAAQ,gBAAA,EAClB;AACD,IAAA,OAAO,OAAA,CAAQ,gBAAA;AAAA,EAChB;AAEA,EAAA,IACC,OAAA,KAAY,IAAA,IACZ,OAAO,OAAA,KAAY,QAAA,IACnB,qBAAA,IAAyB,OAAA,IACzB,OAAA,CAAQ,mBAAA,KAAwB,IAAA,I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AAU,KAAA,EAAO,SAAS,KAAA,EAAO,EAAA,EAAI,EAAC;AAAE,GAC3C;AACA,EAAAA,uBAAA,CAAO,WAAA,CAAY,WAAA,CAAY,KAAA,EAAO,YAAY,CAAA;AAElD,EAAA,OAAA,CAAQ,IAAI,2CAAsC,CAAA;AACnD;AAEA,IAAI,oQAAY,KAAQ,CAAA,OAAA,EAAU,QAAQ,IAAA,CAAK,CAAC,CAAC,CAAA,CAAA,EAAI;AACpD,EAAA,eAAA,EAAgB,CAAE,KAAA,CAAM,CAAC,GAAA,KAAQ;AAChC,IAAA,OAAA,CAAQ,KAAA,CAAM,6CAAwC,GAAG,CAAA;AACzD,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EACf,CAAC,CAAA;AACF","file":"chunk-7KJHGAZY.cjs","sourcesContent":["import assert from \"node:assert\";\n\nexport interface DisplayDescriptor {\n\ttitle: string;\n\tsubtitle?: string;\n\tstateLabel?: string;\n\tprimaryFacts?: Array<{ label: string; value: string }>;\n}\n\nexport interface CachedDisplayDescriptor extends DisplayDescriptor {\n\t_cachedDisplay?: {\n\t\tsource: \"event_payload\" | \"projection_snapshot\";\n\t\tcursor?: string | null;\n\t\tchecksum?: string;\n\t\tgeneratedAt?: string;\n\t};\n}\n\nexport type DisplayDatabaseClient = any;\n\nexport interface DisplayContext<TDb = DisplayDatabaseClient> {\n\ttenantId: string;\n\tspaceId: string;\n\tdb: TDb;\n}\n\nexport type DisplayRenderer = (\n\tpayload: unknown,\n\tctx?: DisplayContext,\n) => DisplayDescriptor | Promise<DisplayDescriptor>;\n\nexport interface DisplayRendererRegistration {\n\teventType: string;\n\trenderer: DisplayRenderer;\n}\n\nconst registry = new Map<string, DisplayRenderer>();\n\nexport function registerDisplayRenderer(eventType: string, renderer: DisplayRenderer): void {\n\tregistry.set(eventType, renderer);\n}\n\nexport function resolveDisplayRenderer(eventType: string): DisplayRenderer | undefined {\n\treturn registry.get(eventType);\n}\n\nexport function denormalizeDisplaySnapshot(payload: unknown): CachedDisplayDescriptor | undefined {\n\tif (\n\t\tpayload !== null &&\n\t\ttypeof payload === \"object\" &&\n\t\t\"_displaySnapshot\" in payload &&\n\t\tpayload._displaySnapshot !== null &&\n\t\ttypeof payload._displaySnapshot === \"object\" &&\n\t\t\"title\" in payload._displaySnapshot\n\t) {\n\t\treturn payload._displaySnapshot as CachedDisplayDescriptor;\n\t}\n\n\tif (\n\t\tpayload !== null &&\n\t\ttypeof payload === \"object\" &&\n\t\t\"_projectionSnapshot\" in payload &&\n\t\tpayload._projectionSnapshot !== null &&\n\t\ttypeof payload._projectionSnapshot === \"object\" &&\n\t\t\"display\" in payload._projectionSnapshot &&\n\t\tpayload._projectionSnapshot.display !== null &&\n\t\ttypeof payload._projectionSnapshot.display === \"object\" &&\n\t\t\"title\" in payload._projectionSnapshot.display\n\t) {\n\t\tconst snapshot = payload._projectionSnapshot as {\n\t\t\tdisplay: DisplayDescriptor;\n\t\t\teventCursor?: string | null;\n\t\t\tchecksum?: string;\n\t\t\tupdatedAt?: string;\n\t\t};\n\t\treturn {\n\t\t\t...snapshot.display,\n\t\t\t_cachedDisplay: {\n\t\t\t\tsource: \"projection_snapshot\",\n\t\t\t\tcursor: snapshot.eventCursor,\n\t\t\t\tchecksum: snapshot.checksum,\n\t\t\t\tgeneratedAt: snapshot.updatedAt,\n\t\t\t},\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport async function renderEventDisplay(\n\teventType: string,\n\tpayload: unknown,\n\tctx?: DisplayContext,\n): Promise<CachedDisplayDescriptor> {\n\tconst snapshot = denormalizeDisplaySnapshot(payload);\n\tif (snapshot) {\n\t\treturn snapshot;\n\t}\n\n\tconst renderer = resolveDisplayRenderer(eventType);\n\tif (!renderer) {\n\t\treturn {\n\t\t\ttitle: eventType,\n\t\t\tsubtitle: \"No display renderer registered for this event type.\",\n\t\t};\n\t}\n\n\treturn await renderer(payload, ctx);\n}\n\n// Inline test: verify registry round-trip, snapshot denormalization, and fallback.\nasync function _runInlineTests(): Promise<void> {\n\tconst testEventType = \"__TestEvent__\";\n\n\t// 1. Registry round-trip\n\tregisterDisplayRenderer(testEventType, (payload) => ({\n\t\ttitle: `Test: ${(payload as { name: string }).name}`,\n\t\tsubtitle: \"registered renderer\",\n\t}));\n\n\tconst renderer = resolveDisplayRenderer(testEventType);\n\tassert.ok(renderer, \"resolveDisplayRenderer should return the registered renderer\");\n\n\tconst result = await renderEventDisplay(testEventType, { name: \"Alice\" });\n\tassert.strictEqual(result.title, \"Test: Alice\");\n\tassert.strictEqual(result.subtitle, \"registered renderer\");\n\n\t// 2. Snapshot denormalization takes precedence over renderer\n\tconst snapshot: DisplayDescriptor = {\n\t\ttitle: \"Snapshot Title\",\n\t\tsubtitle: \"snapshot subtitle\",\n\t\tstateLabel: \"archived\",\n\t\tprimaryFacts: [{ label: \"ID\", value: \"123\" }],\n\t};\n\tconst snapshotResult = await renderEventDisplay(testEventType, {\n\t\t_displaySnapshot: snapshot,\n\t});\n\tassert.deepStrictEqual(snapshotResult, snapshot);\n\n\t// 3. Fallback for unregistered event type\n\tconst fallback = await renderEventDisplay(\"__UnknownEvent__\", {});\n\tassert.strictEqual(fallback.title, \"__UnknownEvent__\");\n\tassert.strictEqual(fallback.subtitle, \"No display renderer registered for this event type.\");\n\n\t// 4. Async renderer with context\n\tregisterDisplayRenderer(\"__AsyncEvent__\", async (_payload, ctx) => {\n\t\treturn {\n\t\t\ttitle: `Async: ${ctx?.tenantId ?? \"no-ctx\"}`,\n\t\t};\n\t});\n\tconst asyncResult = await renderEventDisplay(\n\t\t\"__AsyncEvent__\",\n\t\t{},\n\t\t{ tenantId: \"t-1\", spaceId: \"s-1\", db: {} },\n\t);\n\tassert.strictEqual(asyncResult.title, \"Async: t-1\");\n\n\tconsole.log(\"✅ display engine inline tests passed\");\n}\n\nif (import.meta.url === `file://${process.argv[1]}`) {\n\t_runInlineTests().catch((err) => {\n\t\tconsole.error(\"❌ display engine inline tests failed\", err);\n\t\tprocess.exit(1);\n\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A,IAAI,CAAC,EAAA,EAAI;AACR,IAAA,OAAO,MAAA;AAAA,EACR;AACA,EAAA,OAAO,EAAA,CAAG,MAAA,CAAO,KAAK,CAAA,EAAG,UAAA;AAC1B","file":"chunk-GB2PSZ33.cjs","sourcesContent":["import type { StateClass, StateDefinition } from \"./index\";\n\nexport interface StateMachineDefinition {\n\tentityType: string;\n\tstates: Record<string, StateDefinition>;\n\ttransitions: Array<{\n\t\tfrom: string;\n\t\tto: string;\n\t\tcausedByAction: string;\n\t\tguard?: (ctx: TransitionContext) => boolean | Promise<boolean>;\n\t}>;\n}\n\nexport type StateMachineDatabaseClient = any;\n\nexport interface TransitionContext<TDb = StateMachineDatabaseClient> {\n\tentity: Record<string, unknown>;\n\tactionInvocationId: string;\n\tactorId: string;\n\tparameters: unknown;\n\tdb: TDb;\n}\n\nconst registry = new Map<string, StateMachineDefinition>();\n\n/**\n * Register a state-machine definition for an entity type.\n * Throws if a definition for this entity type is already registered.\n */\nexport function registerStateMachine(def: StateMachineDefinition): void {\n\tif (registry.has(def.entityType)) {\n\t\tthrow new Error(`State machine for entity type \"${def.entityType}\" is already registered.`);\n\t}\n\tregistry.set(def.entityType, def);\n}\n\n/**\n * Register a state-machine definition only if one for this entity type\n * is not already registered. Idempotent — safe to call multiple times.\n */\nexport function registerStateMachineIfMissing(def: StateMachineDefinition): void {\n\tif (!registry.has(def.entityType)) {\n\t\tregisterStateMachine(def);\n\t}\n}\n\n/**\n * Resolve a previously registered state-machine definition by entity type.\n */\nexport function resolveStateMachine(entityType: string): StateMachineDefinition | undefined {\n\treturn registry.get(entityType);\n}\n\n/**\n * Validate whether a transition is allowed for the given entity type,\n * from state, to state, and action ID.\n */\nexport function validateTransition(\n\tentityType: string,\n\tfrom: string,\n\tto: string,\n\tactionId: string,\n): { valid: boolean; error?: string } {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `No state machine registered for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst fromDef = sm.states[from];\n\tif (!fromDef) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `State \"${from}\" does not exist in state machine for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst toDef = sm.states[to];\n\tif (!toDef) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `State \"${to}\" does not exist in state machine for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\tconst transitionExists = sm.transitions.some(\n\t\t(t) => t.from === from && t.to === to && t.causedByAction === actionId,\n\t);\n\tif (!transitionExists) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terror: `Transition from \"${from}\" to \"${to}\" via action \"${actionId}\" is not defined for entity type \"${entityType}\".`,\n\t\t};\n\t}\n\n\treturn { valid: true };\n}\n\n/**\n * Get all allowed transitions from a given state for an entity type.\n */\nexport function getAllowedTransitions(\n\tentityType: string,\n\tfrom: string,\n): Array<{ to: string; causedByAction: string }> {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn [];\n\t}\n\treturn sm.transitions\n\t\t.filter((t) => t.from === from)\n\t\t.map((t) => ({ to: t.to, causedByAction: t.causedByAction }));\n}\n\n/**\n * Get the StateClass of a given state for an entity type.\n */\nexport function getEntityStateClass(entityType: string, state: string): StateClass | undefined {\n\tconst sm = registry.get(entityType);\n\tif (!sm) {\n\t\treturn undefined;\n\t}\n\treturn sm.states[state]?.stateClass;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../modules/index.ts"],"names":["isValidEventType","registerObjectType","registerSubjectType","registerEventType","registerPolicyIfMissing","registerStateMachineIfMissing","registerActionIfMissing","registerDisplayRenderer"],"mappings":";;;;;;;;;;AAsFA,IAAM,0BAAA,uBAAiC,GAAA,EAAY;AAE5C,SAAS,6BAA6B,UAAA,EAA2C;AACvF,EAAA,OAAO,OAAO,UAAA,KAAe,QAAA,GAAW,UAAA,GAAa,UAAA,CAAW,SAAA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A,KAAA,MAAW,UAAU,OAAA,EAAS;AAC7B,IAAA,gBAAA,CAAiB,MAAA,EAAQ,EAAE,mBAAA,EAAqB,iBAAA,EAAmB,CAAA;AAAA,EACpE;AAEA,EAAA,MAAM,aAAA,GAAgB,wBAAwB,OAAO,CAAA;AACrD,EAAA,KAAA,MAAW,UAAU,aAAA,EAAe;AACnC,IAAA,oBAAA,CAAqB,MAAM,CAAA;AAAA,EAC5B;AAEA,EAAA,OAAO,aAAA;AACR","file":"chunk-LYX73U3P.cjs","sourcesContent":["import { registerActionIfMissing, type ActionDefinition } from \"../actions\";\nimport { registerDisplayRenderer, type DisplayRenderer } from \"../displays\";\nimport { isValidEventType, registerEventType, registerSubjectType } from \"../events\";\nimport { registerObjectType } from \"../objects\";\nimport { registerPolicyIfMissing, type PolicyEvaluator } from \"../policies\";\nimport { registerStateMachineIfMissing, type StateMachineDefinition } from \"../state-machines\";\n\nexport interface ModuleDependency {\n\tnamespace: string;\n\tversion?: string;\n\toptional?: boolean;\n}\n\nexport type ModuleDependencyInput = string | ModuleDependency;\n\nexport interface IdPrefixRegistration {\n\tprefix: string;\n\tname: string;\n\tmodule: string;\n}\n\nexport interface EventTypeRegistration {\n\teventType: string;\n\tschemaVersion: number;\n\tdescription?: string;\n}\n\nexport type EventTypeRegistrationInput = string | EventTypeRegistration;\n\nexport interface ObjectTypeRegistration {\n\ttype: string;\n\tdisplayName?: string;\n\tidPrefix?: string;\n\tisCoreModuleType?: boolean;\n}\n\nexport type ObjectTypeRegistrationInput = string | ObjectTypeRegistration;\n\nexport interface ModuleDisplayRendererRegistration {\n\teventType: string;\n\trenderer: (payload: unknown, ctx?: any) => unknown;\n}\n\nexport interface PolicyRegistration {\n\tid: string;\n\tversion?: string;\n\tdescription?: string;\n}\n\nexport interface StateMachineRegistration {\n\tentityType: string;\n\tstates: string[];\n}\n\nexport interface FabricModule<TDb = unknown> {\n\tnamespace: string;\n\tversion?: string;\n\tdisplayName?: string;\n\tdescription?: string;\n\tdependencies?: ModuleDependencyInput[];\n\tobjectTypes?: ObjectTypeRegistrationInput[];\n\tsubjectTypes?: string[];\n\tidPrefixes?: IdPrefixRegistration[];\n\teventTypes?: EventTypeRegistrationInput[];\n\tactions?: ActionDefinition<TDb>[];\n\tpolicies?: unknown[];\n\tstateMachines?: unknown[];\n\tdisplayRenderers?: ModuleDisplayRendererRegistration[];\n\tadapterDefinitions?: unknown[];\n\tpermissions?: unknown[];\n\troles?: unknown[];\n\tredactionRules?: unknown[];\n\tdataClassifications?: unknown[];\n\tretentionRules?: unknown[];\n\tevidenceRenderers?: unknown[];\n}\n\nexport interface ModuleRegistry<TDb = unknown> {\n\tmodules: ReadonlyMap<string, FabricModule<TDb>>;\n}\n\ninterface ModuleValidationContext {\n\tavailableNamespaces?: Set<string>;\n\tplannedEventTypes?: Set<string>;\n}\n\nconst registeredModuleNamespaces = new Set<string>();\n\nexport function getModuleDependencyNamespace(dependency: ModuleDependencyInput): string {\n\treturn typeof dependency === \"string\" ? dependency : dependency.namespace;\n}\n\nexport function getObjectTypeName(objectType: ObjectTypeRegistrationInput): string {\n\treturn typeof objectType === \"string\" ? objectType : objectType.type;\n}\n\nexport function getEventTypeName(eventType: EventTypeRegistrationInput): string {\n\treturn typeof eventType === \"string\" ? eventType : eventType.eventType;\n}\n\nexport function validateModuleNamespace(namespace: string): void {\n\tif (!namespace) {\n\t\tthrow new Error(\"Module namespace cannot be empty\");\n\t}\n\tif (!/^[a-z][a-z0-9-]*$/.test(namespace)) {\n\t\tthrow new Error(\n\t\t\t`Invalid module namespace: \"${namespace}\". Must be lowercase letters, numbers, and hyphens only.`,\n\t\t);\n\t}\n}\n\nexport function createModuleRegistry<TDb = unknown>(\n\tmodules: FabricModule<TDb>[] = [],\n): ModuleRegistry<TDb> {\n\tconst registered = new Map<string, FabricModule<TDb>>();\n\tfor (const module of modules) {\n\t\tvalidateModuleNamespace(module.namespace);\n\t\tif (registered.has(module.namespace)) {\n\t\t\tthrow new Error(`Duplicate FabricModule namespace \"${module.namespace}\".`);\n\t\t}\n\t\tregistered.set(module.namespace, module);\n\t}\n\treturn { modules: registered };\n}\n\nfunction validateIdentifierList(\n\tvalues: string[] | undefined,\n\tlabel: string,\n\tnamespace: string,\n): void {\n\tfor (const value of values ?? []) {\n\t\tif (!value) {\n\t\t\tthrow new Error(`Module \"${namespace}\" has an empty ${label} entry.`);\n\t\t}\n\t}\n}\n\nfunction validateManifest(module: FabricModule<any>, context: ModuleValidationContext = {}): void {\n\tvalidateModuleNamespace(module.namespace);\n\n\tconst dependencies = (module.dependencies ?? []).map(getModuleDependencyNamespace);\n\tconst objectTypes = (module.objectTypes ?? []).map(getObjectTypeName);\n\tconst eventTypes = (module.eventTypes ?? []).map(getEventTypeName);\n\n\tfor (const dependency of dependencies) {\n\t\tvalidateModuleNamespace(dependency);\n\t\tif (dependency === module.namespace) {\n\t\t\tthrow new Error(`Module \"${module.namespace}\" cannot depend on itself.`);\n\t\t}\n\t\tif (context.availableNamespaces && !context.availableNamespaces.has(dependency)) {\n\t\t\tthrow new Error(`Module \"${module.namespace}\" depends on missing module \"${dependency}\".`);\n\t\t}\n\t}\n\n\tvalidateIdentifierList(objectTypes, \"objectTypes\", module.namespace);\n\tvalidateIdentifierList(module.subjectTypes, \"subjectTypes\", module.namespace);\n\tvalidateIdentifierList(eventTypes, \"eventTypes\", module.namespace);\n\n\tfor (const objectType of objectTypes) {\n\t\tif (!/^[A-Z][a-zA-Z0-9]*$/.test(objectType)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid object type: \"${objectType}\". Object types must be PascalCase alphanumeric.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const action of module.actions ?? []) {\n\t\tif (!/^[a-z][a-z0-9-]*\\.[a-z][a-z0-9_]*$/.test(action.actionId)) {\n\t\t\tthrow new Error(`Invalid action ID: ${action.actionId}`);\n\t\t}\n\n\t\tif (action.namespace !== module.namespace) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" declares namespace \"${action.namespace}\" ` +\n\t\t\t\t\t`but is registered by module \"${module.namespace}\".`,\n\t\t\t);\n\t\t}\n\n\t\tif (!action.actionId.startsWith(`${module.namespace}.`)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" must start with module namespace \"${module.namespace}.\"`,\n\t\t\t);\n\t\t}\n\n\t\tif (action.mutatesDomain && action.emitsEvents.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" mutates domain but emits no events. ` +\n\t\t\t\t\t`Every mutating action must emit at least one AssetEvent.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const descriptor of module.displayRenderers ?? []) {\n\t\tconst isPlannedEventType = context.plannedEventTypes?.has(descriptor.eventType) ?? false;\n\t\tconst isModuleEventType = eventTypes.includes(descriptor.eventType);\n\t\tif (!isValidEventType(descriptor.eventType) && !isModuleEventType && !isPlannedEventType) {\n\t\t\tthrow new Error(\n\t\t\t\t`Display renderer registered for unknown event type \"${descriptor.eventType}\". ` +\n\t\t\t\t\t`Register the event type before adding a display renderer.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction sortModulesByDependency(\n\tmodules: FabricModule<any>[],\n\tregisteredNamespaces = registeredModuleNamespaces,\n): FabricModule<any>[] {\n\tconst modulesByNamespace = new Map<string, FabricModule<any>>();\n\n\tfor (const module of modules) {\n\t\tvalidateModuleNamespace(module.namespace);\n\t\tif (modulesByNamespace.has(module.namespace)) {\n\t\t\tthrow new Error(`Duplicate Fabric module namespace \"${module.namespace}\".`);\n\t\t}\n\t\tmodulesByNamespace.set(module.namespace, module);\n\t}\n\n\tconst sorted: FabricModule<any>[] = [];\n\tconst visiting = new Set<string>();\n\tconst visited = new Set<string>();\n\n\tfunction visit(module: FabricModule<any>, path: string[]): void {\n\t\tif (visited.has(module.namespace)) {\n\t\t\treturn;\n\t\t}\n\t\tif (visiting.has(module.namespace)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cyclic Fabric module dependency detected: ${[...path, module.namespace].join(\" -> \")}`,\n\t\t\t);\n\t\t}\n\n\t\tvisiting.add(module.namespace);\n\t\tfor (const dependency of (module.dependencies ?? []).map(getModuleDependencyNamespace)) {\n\t\t\tconst dependencyModule = modulesByNamespace.get(dependency);\n\t\t\tif (!dependencyModule) {\n\t\t\t\tif (registeredNamespaces.has(dependency)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Module \"${module.namespace}\" depends on missing module \"${dependency}\".`);\n\t\t\t}\n\t\t\tvisit(dependencyModule, [...path, module.namespace]);\n\t\t}\n\t\tvisiting.delete(module.namespace);\n\t\tvisited.add(module.namespace);\n\t\tsorted.push(module);\n\t}\n\n\tfor (const module of modules) {\n\t\tvisit(module, []);\n\t}\n\n\treturn sorted;\n}\n\nexport function registerFabricModule(module: FabricModule<any>): void {\n\tvalidateManifest(module, { availableNamespaces: registeredModuleNamespaces });\n\n\tfor (const objectType of module.objectTypes ?? []) {\n\t\tregisterObjectType(getObjectTypeName(objectType));\n\t}\n\n\tfor (const subjectType of module.subjectTypes ?? []) {\n\t\tregisterSubjectType(subjectType);\n\t}\n\n\tfor (const eventType of module.eventTypes ?? []) {\n\t\tregisterEventType(getEventTypeName(eventType));\n\t}\n\n\tfor (const policy of module.policies ?? []) {\n\t\tregisterPolicyIfMissing(policy as PolicyEvaluator);\n\t}\n\n\tfor (const machine of module.stateMachines ?? []) {\n\t\tregisterStateMachineIfMissing(machine as StateMachineDefinition);\n\t}\n\n\tfor (const action of module.actions ?? []) {\n\t\tregisterActionIfMissing(action);\n\t}\n\n\tfor (const descriptor of module.displayRenderers ?? []) {\n\t\tregisterDisplayRenderer(descriptor.eventType, descriptor.renderer as DisplayRenderer);\n\t}\n\n\tregisteredModuleNamespaces.add(module.namespace);\n}\n\nexport function registerFabricModules(modules: FabricModule<any>[]): FabricModule<any>[] {\n\tconst availableNamespaces = new Set([\n\t\t...registeredModuleNamespaces,\n\t\t...modules.map((module) => module.namespace),\n\t]);\n\tconst plannedEventTypes = new Set(\n\t\tmodules.flatMap((module) => (module.eventTypes ?? []).map(getEventTypeName)),\n\t);\n\n\tfor (const module of modules) {\n\t\tvalidateManifest(module, { availableNamespaces, plannedEventTypes });\n\t}\n\n\tconst sortedModules = sortModulesByDependency(modules);\n\tfor (const module of sortedModules) {\n\t\tregisterFabricModule(module);\n\t}\n\n\treturn sortedModules;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../modules/index.ts"],"names":[],"mappings":";;;;;;;;AAsFA,IAAM,0BAAA,uBAAiC,GAAA,EAAY;AAE5C,SAAS,6BAA6B,UAAA,EAA2C;AACvF,EAAA,OAAO,OAAO,UAAA,KAAe,QAAA,GAAW,UAAA,GAAa,UAAA,CAAW,SAAA;AACjE;AAEO,SAAS,kBAAkB,UAAA,EAAiD;AAClF,EAAA,OAAO,OAAO,UAAA,KAAe,QAAA,GAAW,UAAA,GAAa,UAAA,CAAW,IAAA;AACjE;AAEO,SAAS,iBAAiB,SAAA,EAA+C;AAC/E,EAAA,OAAO,OAAO,SAAA,KAAc,QAAA,GAAW,SAAA,GAAY,SAAA,CAAU,SAAA;AAC9D;AAEO,SAAS,wBAAwB,SAAA,EAAyB;AAChE,EAAA,IAAI,CAAC,SAAA,EAAW;AACf,IAAA,MAAM,IAAI,MAAM,kCAAkC,CAAA;AAAA,EACnD;AACA,EAAA,IAAI,CAAC,mBAAA,CAAoB,IAAA,CAAK,SAAS,CAAA,EAAG;AACzC,IAAA,MAAM,IAAI,KAAA;AAAA,MACT,8BAA8B,SAAS,CAAA,wDAAA;AAAA,KACxC;AAAA,EACD;AACD;AAEO,SAAS,oBAAA,CACf,OAAA,GAA+B,EAAC,EACV;AACtB,EAAA,MAAM,UAAA,uBAAiB,GAAA,EAA+B;AACtD,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC7B,IAAA,uBAAA,CAAwB,OAAO,SAAS,CAAA;AACxC,IAAA,IAAI,UA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AAA,EAAW,UAAA,CAAW,QAA2B,CAAA;AAAA,EACrF;AAEA,EAAA,0BAAA,CAA2B,GAAA,CAAI,OAAO,SAAS,CAAA;AAChD;AAEO,SAAS,sBAAsB,OAAA,EAAmD;AACxF,EAAA,MAAM,mBAAA,uBAA0B,GAAA,CAAI;AAAA,IACnC,GAAG,0BAAA;AAAA,IACH,GAAG,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,OAAO,SAAS;AAAA,GAC3C,CAAA;AACD,EAAA,MAAM,oBAAoB,IAAI,GAAA;AAAA,IAC7B,OAAA,CAAQ,OAAA,CAAQ,CAAC,MAAA,KAAA,CAAY,MAAA,CAAO,cAAc,EAAC,EAAG,GAAA,CAAI,gBAAgB,CAAC;AAAA,GAC5E;AAEA,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC7B,IAAA,gBAAA,CAAiB,MAAA,EAAQ,EAAE,mBAAA,EAAqB,iBAAA,EAAmB,CAAA;AAAA,EACpE;AAEA,EAAA,MAAM,aAAA,GAAgB,wBAAwB,OAAO,CAAA;AACrD,EAAA,KAAA,MAAW,UAAU,aAAA,EAAe;AACnC,IAAA,oBAAA,CAAqB,MAAM,CAAA;AAAA,EAC5B;AAEA,EAAA,OAAO,aAAA;AACR","file":"chunk-PXMKCAQI.js","sourcesContent":["import { registerActionIfMissing, type ActionDefinition } from \"../actions\";\nimport { registerDisplayRenderer, type DisplayRenderer } from \"../displays\";\nimport { isValidEventType, registerEventType, registerSubjectType } from \"../events\";\nimport { registerObjectType } from \"../objects\";\nimport { registerPolicyIfMissing, type PolicyEvaluator } from \"../policies\";\nimport { registerStateMachineIfMissing, type StateMachineDefinition } from \"../state-machines\";\n\nexport interface ModuleDependency {\n\tnamespace: string;\n\tversion?: string;\n\toptional?: boolean;\n}\n\nexport type ModuleDependencyInput = string | ModuleDependency;\n\nexport interface IdPrefixRegistration {\n\tprefix: string;\n\tname: string;\n\tmodule: string;\n}\n\nexport interface EventTypeRegistration {\n\teventType: string;\n\tschemaVersion: number;\n\tdescription?: string;\n}\n\nexport type EventTypeRegistrationInput = string | EventTypeRegistration;\n\nexport interface ObjectTypeRegistration {\n\ttype: string;\n\tdisplayName?: string;\n\tidPrefix?: string;\n\tisCoreModuleType?: boolean;\n}\n\nexport type ObjectTypeRegistrationInput = string | ObjectTypeRegistration;\n\nexport interface ModuleDisplayRendererRegistration {\n\teventType: string;\n\trenderer: (payload: unknown, ctx?: any) => unknown;\n}\n\nexport interface PolicyRegistration {\n\tid: string;\n\tversion?: string;\n\tdescription?: string;\n}\n\nexport interface StateMachineRegistration {\n\tentityType: string;\n\tstates: string[];\n}\n\nexport interface FabricModule<TDb = unknown> {\n\tnamespace: string;\n\tversion?: string;\n\tdisplayName?: string;\n\tdescription?: string;\n\tdependencies?: ModuleDependencyInput[];\n\tobjectTypes?: ObjectTypeRegistrationInput[];\n\tsubjectTypes?: string[];\n\tidPrefixes?: IdPrefixRegistration[];\n\teventTypes?: EventTypeRegistrationInput[];\n\tactions?: ActionDefinition<TDb>[];\n\tpolicies?: unknown[];\n\tstateMachines?: unknown[];\n\tdisplayRenderers?: ModuleDisplayRendererRegistration[];\n\tadapterDefinitions?: unknown[];\n\tpermissions?: unknown[];\n\troles?: unknown[];\n\tredactionRules?: unknown[];\n\tdataClassifications?: unknown[];\n\tretentionRules?: unknown[];\n\tevidenceRenderers?: unknown[];\n}\n\nexport interface ModuleRegistry<TDb = unknown> {\n\tmodules: ReadonlyMap<string, FabricModule<TDb>>;\n}\n\ninterface ModuleValidationContext {\n\tavailableNamespaces?: Set<string>;\n\tplannedEventTypes?: Set<string>;\n}\n\nconst registeredModuleNamespaces = new Set<string>();\n\nexport function getModuleDependencyNamespace(dependency: ModuleDependencyInput): string {\n\treturn typeof dependency === \"string\" ? dependency : dependency.namespace;\n}\n\nexport function getObjectTypeName(objectType: ObjectTypeRegistrationInput): string {\n\treturn typeof objectType === \"string\" ? objectType : objectType.type;\n}\n\nexport function getEventTypeName(eventType: EventTypeRegistrationInput): string {\n\treturn typeof eventType === \"string\" ? eventType : eventType.eventType;\n}\n\nexport function validateModuleNamespace(namespace: string): void {\n\tif (!namespace) {\n\t\tthrow new Error(\"Module namespace cannot be empty\");\n\t}\n\tif (!/^[a-z][a-z0-9-]*$/.test(namespace)) {\n\t\tthrow new Error(\n\t\t\t`Invalid module namespace: \"${namespace}\". Must be lowercase letters, numbers, and hyphens only.`,\n\t\t);\n\t}\n}\n\nexport function createModuleRegistry<TDb = unknown>(\n\tmodules: FabricModule<TDb>[] = [],\n): ModuleRegistry<TDb> {\n\tconst registered = new Map<string, FabricModule<TDb>>();\n\tfor (const module of modules) {\n\t\tvalidateModuleNamespace(module.namespace);\n\t\tif (registered.has(module.namespace)) {\n\t\t\tthrow new Error(`Duplicate FabricModule namespace \"${module.namespace}\".`);\n\t\t}\n\t\tregistered.set(module.namespace, module);\n\t}\n\treturn { modules: registered };\n}\n\nfunction validateIdentifierList(\n\tvalues: string[] | undefined,\n\tlabel: string,\n\tnamespace: string,\n): void {\n\tfor (const value of values ?? []) {\n\t\tif (!value) {\n\t\t\tthrow new Error(`Module \"${namespace}\" has an empty ${label} entry.`);\n\t\t}\n\t}\n}\n\nfunction validateManifest(module: FabricModule<any>, context: ModuleValidationContext = {}): void {\n\tvalidateModuleNamespace(module.namespace);\n\n\tconst dependencies = (module.dependencies ?? []).map(getModuleDependencyNamespace);\n\tconst objectTypes = (module.objectTypes ?? []).map(getObjectTypeName);\n\tconst eventTypes = (module.eventTypes ?? []).map(getEventTypeName);\n\n\tfor (const dependency of dependencies) {\n\t\tvalidateModuleNamespace(dependency);\n\t\tif (dependency === module.namespace) {\n\t\t\tthrow new Error(`Module \"${module.namespace}\" cannot depend on itself.`);\n\t\t}\n\t\tif (context.availableNamespaces && !context.availableNamespaces.has(dependency)) {\n\t\t\tthrow new Error(`Module \"${module.namespace}\" depends on missing module \"${dependency}\".`);\n\t\t}\n\t}\n\n\tvalidateIdentifierList(objectTypes, \"objectTypes\", module.namespace);\n\tvalidateIdentifierList(module.subjectTypes, \"subjectTypes\", module.namespace);\n\tvalidateIdentifierList(eventTypes, \"eventTypes\", module.namespace);\n\n\tfor (const objectType of objectTypes) {\n\t\tif (!/^[A-Z][a-zA-Z0-9]*$/.test(objectType)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid object type: \"${objectType}\". Object types must be PascalCase alphanumeric.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const action of module.actions ?? []) {\n\t\tif (!/^[a-z][a-z0-9-]*\\.[a-z][a-z0-9_]*$/.test(action.actionId)) {\n\t\t\tthrow new Error(`Invalid action ID: ${action.actionId}`);\n\t\t}\n\n\t\tif (action.namespace !== module.namespace) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" declares namespace \"${action.namespace}\" ` +\n\t\t\t\t\t`but is registered by module \"${module.namespace}\".`,\n\t\t\t);\n\t\t}\n\n\t\tif (!action.actionId.startsWith(`${module.namespace}.`)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" must start with module namespace \"${module.namespace}.\"`,\n\t\t\t);\n\t\t}\n\n\t\tif (action.mutatesDomain && action.emitsEvents.length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`Action \"${action.actionId}\" mutates domain but emits no events. ` +\n\t\t\t\t\t`Every mutating action must emit at least one AssetEvent.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const descriptor of module.displayRenderers ?? []) {\n\t\tconst isPlannedEventType = context.plannedEventTypes?.has(descriptor.eventType) ?? false;\n\t\tconst isModuleEventType = eventTypes.includes(descriptor.eventType);\n\t\tif (!isValidEventType(descriptor.eventType) && !isModuleEventType && !isPlannedEventType) {\n\t\t\tthrow new Error(\n\t\t\t\t`Display renderer registered for unknown event type \"${descriptor.eventType}\". ` +\n\t\t\t\t\t`Register the event type before adding a display renderer.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction sortModulesByDependency(\n\tmodules: FabricModule<any>[],\n\tregisteredNamespaces = registeredModuleNamespaces,\n): FabricModule<any>[] {\n\tconst modulesByNamespace = new Map<string, FabricModule<any>>();\n\n\tfor (const module of modules) {\n\t\tvalidateModuleNamespace(module.namespace);\n\t\tif (modulesByNamespace.has(module.namespace)) {\n\t\t\tthrow new Error(`Duplicate Fabric module namespace \"${module.namespace}\".`);\n\t\t}\n\t\tmodulesByNamespace.set(module.namespace, module);\n\t}\n\n\tconst sorted: FabricModule<any>[] = [];\n\tconst visiting = new Set<string>();\n\tconst visited = new Set<string>();\n\n\tfunction visit(module: FabricModule<any>, path: string[]): void {\n\t\tif (visited.has(module.namespace)) {\n\t\t\treturn;\n\t\t}\n\t\tif (visiting.has(module.namespace)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Cyclic Fabric module dependency detected: ${[...path, module.namespace].join(\" -> \")}`,\n\t\t\t);\n\t\t}\n\n\t\tvisiting.add(module.namespace);\n\t\tfor (const dependency of (module.dependencies ?? []).map(getModuleDependencyNamespace)) {\n\t\t\tconst dependencyModule = modulesByNamespace.get(dependency);\n\t\t\tif (!dependencyModule) {\n\t\t\t\tif (registeredNamespaces.has(dependency)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new Error(`Module \"${module.namespace}\" depends on missing module \"${dependency}\".`);\n\t\t\t}\n\t\t\tvisit(dependencyModule, [...path, module.namespace]);\n\t\t}\n\t\tvisiting.delete(module.namespace);\n\t\tvisited.add(module.namespace);\n\t\tsorted.push(module);\n\t}\n\n\tfor (const module of modules) {\n\t\tvisit(module, []);\n\t}\n\n\treturn sorted;\n}\n\nexport function registerFabricModule(module: FabricModule<any>): void {\n\tvalidateManifest(module, { availableNamespaces: registeredModuleNamespaces });\n\n\tfor (const objectType of module.objectTypes ?? []) {\n\t\tregisterObjectType(getObjectTypeName(objectType));\n\t}\n\n\tfor (const subjectType of module.subjectTypes ?? []) {\n\t\tregisterSubjectType(subjectType);\n\t}\n\n\tfor (const eventType of module.eventTypes ?? []) {\n\t\tregisterEventType(getEventTypeName(eventType));\n\t}\n\n\tfor (const policy of module.policies ?? []) {\n\t\tregisterPolicyIfMissing(policy as PolicyEvaluator);\n\t}\n\n\tfor (const machine of module.stateMachines ?? []) {\n\t\tregisterStateMachineIfMissing(machine as StateMachineDefinition);\n\t}\n\n\tfor (const action of module.actions ?? []) {\n\t\tregisterActionIfMissing(action);\n\t}\n\n\tfor (const descriptor of module.displayRenderers ?? []) {\n\t\tregisterDisplayRenderer(descriptor.eventType, descriptor.renderer as DisplayRenderer);\n\t}\n\n\tregisteredModuleNamespaces.add(module.namespace);\n}\n\nexport function registerFabricModules(modules: FabricModule<any>[]): FabricModule<any>[] {\n\tconst availableNamespaces = new Set([\n\t\t...registeredModuleNamespaces,\n\t\t...modules.map((module) => module.namespace),\n\t]);\n\tconst plannedEventTypes = new Set(\n\t\tmodules.flatMap((module) => (module.eventTypes ?? []).map(getEventTypeName)),\n\t);\n\n\tfor (const module of modules) {\n\t\tvalidateManifest(module, { availableNamespaces, plannedEventTypes });\n\t}\n\n\tconst sortedModules = sortModulesByDependency(modules);\n\tfor (const module of sortedModules) {\n\t\tregisterFabricModule(module);\n\t}\n\n\treturn sortedModules;\n}\n"]}
|