@fabricorg/platform 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/actions/index.d.ts +3 -1
  2. package/dist/actions/index.js +1 -57
  3. package/dist/actions/index.js.map +1 -1
  4. package/dist/adapters/index.js +1 -99
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/chunk-3A6FU3KV.js +67 -0
  7. package/dist/chunk-3A6FU3KV.js.map +1 -0
  8. package/dist/chunk-3F6FKQZA.js +89 -0
  9. package/dist/chunk-3F6FKQZA.js.map +1 -0
  10. package/dist/chunk-3ZW5USXF.js +101 -0
  11. package/dist/chunk-3ZW5USXF.js.map +1 -0
  12. package/dist/chunk-4YQOGV7H.js +55 -0
  13. package/dist/chunk-4YQOGV7H.js.map +1 -0
  14. package/dist/chunk-6FMW4NF6.js +59 -0
  15. package/dist/chunk-6FMW4NF6.js.map +1 -0
  16. package/dist/chunk-I35B576X.js +30 -0
  17. package/dist/chunk-I35B576X.js.map +1 -0
  18. package/dist/chunk-IFMZPLM4.js +27 -0
  19. package/dist/chunk-IFMZPLM4.js.map +1 -0
  20. package/dist/chunk-JSTGOT6P.js +181 -0
  21. package/dist/chunk-JSTGOT6P.js.map +1 -0
  22. package/dist/chunk-KOC4A7A4.js +544 -0
  23. package/dist/chunk-KOC4A7A4.js.map +1 -0
  24. package/dist/chunk-N24NLCZ6.js +6 -0
  25. package/dist/chunk-N24NLCZ6.js.map +1 -0
  26. package/dist/chunk-OZLZHISS.js +3 -0
  27. package/dist/chunk-OZLZHISS.js.map +1 -0
  28. package/dist/chunk-PXMKCAQI.js +187 -0
  29. package/dist/chunk-PXMKCAQI.js.map +1 -0
  30. package/dist/chunk-RALMUSOX.js +55 -0
  31. package/dist/chunk-RALMUSOX.js.map +1 -0
  32. package/dist/displays/index.js +1 -87
  33. package/dist/displays/index.js.map +1 -1
  34. package/dist/events/index.js +1 -53
  35. package/dist/events/index.js.map +1 -1
  36. package/dist/evidence/index.js +1 -1
  37. package/dist/ids/index.js +1 -53
  38. package/dist/ids/index.js.map +1 -1
  39. package/dist/index.js +13 -1355
  40. package/dist/index.js.map +1 -1
  41. package/dist/modules/index.js +7 -373
  42. package/dist/modules/index.js.map +1 -1
  43. package/dist/objects/index.js +1 -28
  44. package/dist/objects/index.js.map +1 -1
  45. package/dist/policies/index.js +1 -542
  46. package/dist/policies/index.js.map +1 -1
  47. package/dist/privacy/index.js +1 -4
  48. package/dist/privacy/index.js.map +1 -1
  49. package/dist/projections/index.js +1 -179
  50. package/dist/projections/index.js.map +1 -1
  51. package/dist/state-machines/index.js +1 -65
  52. package/dist/state-machines/index.js.map +1 -1
  53. package/dist/testing/index.js +2 -56
  54. package/dist/testing/index.js.map +1 -1
  55. package/package.json +111 -112
@@ -0,0 +1,187 @@
1
+ import { registerObjectType } from './chunk-I35B576X.js';
2
+ import { registerPolicyIfMissing } from './chunk-KOC4A7A4.js';
3
+ import { registerStateMachineIfMissing } from './chunk-3A6FU3KV.js';
4
+ import { registerActionIfMissing } from './chunk-6FMW4NF6.js';
5
+ import { registerDisplayRenderer } from './chunk-3F6FKQZA.js';
6
+ import { registerSubjectType, registerEventType, isValidEventType } from './chunk-4YQOGV7H.js';
7
+
8
+ // modules/index.ts
9
+ var registeredModuleNamespaces = /* @__PURE__ */ new Set();
10
+ function getModuleDependencyNamespace(dependency) {
11
+ return typeof dependency === "string" ? dependency : dependency.namespace;
12
+ }
13
+ function getObjectTypeName(objectType) {
14
+ return typeof objectType === "string" ? objectType : objectType.type;
15
+ }
16
+ function getEventTypeName(eventType) {
17
+ return typeof eventType === "string" ? eventType : eventType.eventType;
18
+ }
19
+ function validateModuleNamespace(namespace) {
20
+ if (!namespace) {
21
+ throw new Error("Module namespace cannot be empty");
22
+ }
23
+ if (!/^[a-z][a-z0-9-]*$/.test(namespace)) {
24
+ throw new Error(
25
+ `Invalid module namespace: "${namespace}". Must be lowercase letters, numbers, and hyphens only.`
26
+ );
27
+ }
28
+ }
29
+ function createModuleRegistry(modules = []) {
30
+ const registered = /* @__PURE__ */ new Map();
31
+ for (const module of modules) {
32
+ validateModuleNamespace(module.namespace);
33
+ if (registered.has(module.namespace)) {
34
+ throw new Error(`Duplicate FabricModule namespace "${module.namespace}".`);
35
+ }
36
+ registered.set(module.namespace, module);
37
+ }
38
+ return { modules: registered };
39
+ }
40
+ function validateIdentifierList(values, label, namespace) {
41
+ for (const value of values ?? []) {
42
+ if (!value) {
43
+ throw new Error(`Module "${namespace}" has an empty ${label} entry.`);
44
+ }
45
+ }
46
+ }
47
+ function validateManifest(module, context = {}) {
48
+ validateModuleNamespace(module.namespace);
49
+ const dependencies = (module.dependencies ?? []).map(getModuleDependencyNamespace);
50
+ const objectTypes = (module.objectTypes ?? []).map(getObjectTypeName);
51
+ const eventTypes = (module.eventTypes ?? []).map(getEventTypeName);
52
+ for (const dependency of dependencies) {
53
+ validateModuleNamespace(dependency);
54
+ if (dependency === module.namespace) {
55
+ throw new Error(`Module "${module.namespace}" cannot depend on itself.`);
56
+ }
57
+ if (context.availableNamespaces && !context.availableNamespaces.has(dependency)) {
58
+ throw new Error(`Module "${module.namespace}" depends on missing module "${dependency}".`);
59
+ }
60
+ }
61
+ validateIdentifierList(objectTypes, "objectTypes", module.namespace);
62
+ validateIdentifierList(module.subjectTypes, "subjectTypes", module.namespace);
63
+ validateIdentifierList(eventTypes, "eventTypes", module.namespace);
64
+ for (const objectType of objectTypes) {
65
+ if (!/^[A-Z][a-zA-Z0-9]*$/.test(objectType)) {
66
+ throw new Error(
67
+ `Invalid object type: "${objectType}". Object types must be PascalCase alphanumeric.`
68
+ );
69
+ }
70
+ }
71
+ for (const action of module.actions ?? []) {
72
+ if (!/^[a-z][a-z0-9-]*\.[a-z][a-z0-9_]*$/.test(action.actionId)) {
73
+ throw new Error(`Invalid action ID: ${action.actionId}`);
74
+ }
75
+ if (action.namespace !== module.namespace) {
76
+ throw new Error(
77
+ `Action "${action.actionId}" declares namespace "${action.namespace}" but is registered by module "${module.namespace}".`
78
+ );
79
+ }
80
+ if (!action.actionId.startsWith(`${module.namespace}.`)) {
81
+ throw new Error(
82
+ `Action "${action.actionId}" must start with module namespace "${module.namespace}."`
83
+ );
84
+ }
85
+ if (action.mutatesDomain && action.emitsEvents.length === 0) {
86
+ throw new Error(
87
+ `Action "${action.actionId}" mutates domain but emits no events. Every mutating action must emit at least one AssetEvent.`
88
+ );
89
+ }
90
+ }
91
+ for (const descriptor of module.displayRenderers ?? []) {
92
+ const isPlannedEventType = context.plannedEventTypes?.has(descriptor.eventType) ?? false;
93
+ const isModuleEventType = eventTypes.includes(descriptor.eventType);
94
+ if (!isValidEventType(descriptor.eventType) && !isModuleEventType && !isPlannedEventType) {
95
+ throw new Error(
96
+ `Display renderer registered for unknown event type "${descriptor.eventType}". Register the event type before adding a display renderer.`
97
+ );
98
+ }
99
+ }
100
+ }
101
+ function sortModulesByDependency(modules, registeredNamespaces = registeredModuleNamespaces) {
102
+ const modulesByNamespace = /* @__PURE__ */ new Map();
103
+ for (const module of modules) {
104
+ validateModuleNamespace(module.namespace);
105
+ if (modulesByNamespace.has(module.namespace)) {
106
+ throw new Error(`Duplicate Fabric module namespace "${module.namespace}".`);
107
+ }
108
+ modulesByNamespace.set(module.namespace, module);
109
+ }
110
+ const sorted = [];
111
+ const visiting = /* @__PURE__ */ new Set();
112
+ const visited = /* @__PURE__ */ new Set();
113
+ function visit(module, path) {
114
+ if (visited.has(module.namespace)) {
115
+ return;
116
+ }
117
+ if (visiting.has(module.namespace)) {
118
+ throw new Error(
119
+ `Cyclic Fabric module dependency detected: ${[...path, module.namespace].join(" -> ")}`
120
+ );
121
+ }
122
+ visiting.add(module.namespace);
123
+ for (const dependency of (module.dependencies ?? []).map(getModuleDependencyNamespace)) {
124
+ const dependencyModule = modulesByNamespace.get(dependency);
125
+ if (!dependencyModule) {
126
+ if (registeredNamespaces.has(dependency)) {
127
+ continue;
128
+ }
129
+ throw new Error(`Module "${module.namespace}" depends on missing module "${dependency}".`);
130
+ }
131
+ visit(dependencyModule, [...path, module.namespace]);
132
+ }
133
+ visiting.delete(module.namespace);
134
+ visited.add(module.namespace);
135
+ sorted.push(module);
136
+ }
137
+ for (const module of modules) {
138
+ visit(module, []);
139
+ }
140
+ return sorted;
141
+ }
142
+ function registerFabricModule(module) {
143
+ validateManifest(module, { availableNamespaces: registeredModuleNamespaces });
144
+ for (const objectType of module.objectTypes ?? []) {
145
+ registerObjectType(getObjectTypeName(objectType));
146
+ }
147
+ for (const subjectType of module.subjectTypes ?? []) {
148
+ registerSubjectType(subjectType);
149
+ }
150
+ for (const eventType of module.eventTypes ?? []) {
151
+ registerEventType(getEventTypeName(eventType));
152
+ }
153
+ for (const policy of module.policies ?? []) {
154
+ registerPolicyIfMissing(policy);
155
+ }
156
+ for (const machine of module.stateMachines ?? []) {
157
+ registerStateMachineIfMissing(machine);
158
+ }
159
+ for (const action of module.actions ?? []) {
160
+ registerActionIfMissing(action);
161
+ }
162
+ for (const descriptor of module.displayRenderers ?? []) {
163
+ registerDisplayRenderer(descriptor.eventType, descriptor.renderer);
164
+ }
165
+ registeredModuleNamespaces.add(module.namespace);
166
+ }
167
+ function registerFabricModules(modules) {
168
+ const availableNamespaces = /* @__PURE__ */ new Set([
169
+ ...registeredModuleNamespaces,
170
+ ...modules.map((module) => module.namespace)
171
+ ]);
172
+ const plannedEventTypes = new Set(
173
+ modules.flatMap((module) => (module.eventTypes ?? []).map(getEventTypeName))
174
+ );
175
+ for (const module of modules) {
176
+ validateManifest(module, { availableNamespaces, plannedEventTypes });
177
+ }
178
+ const sortedModules = sortModulesByDependency(modules);
179
+ for (const module of sortedModules) {
180
+ registerFabricModule(module);
181
+ }
182
+ return sortedModules;
183
+ }
184
+
185
+ export { createModuleRegistry, getEventTypeName, getModuleDependencyNamespace, getObjectTypeName, registerFabricModule, registerFabricModules, validateModuleNamespace };
186
+ //# sourceMappingURL=chunk-PXMKCAQI.js.map
187
+ //#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,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"]}
@@ -0,0 +1,55 @@
1
+ // ids/index.ts
2
+ var CROCKFORD_BASE32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
3
+ var FABRIC_ID_PREFIXES = {
4
+ assetEvent: "evt",
5
+ actionInvocation: "act",
6
+ policyEvaluation: "pol",
7
+ adapterInvocation: "adp",
8
+ adapterDeadLetterQueue: "dlq",
9
+ accessEvent: "acc",
10
+ projectionSnapshot: "psn",
11
+ complianceEvidencePacket: "cep"
12
+ };
13
+ var ID_REGEX = /^([a-z][a-z0-9]{1,7})_([0-9A-Z]{26})$/;
14
+ function randomBase32(length) {
15
+ let output = "";
16
+ const randomValues = new Uint8Array(length);
17
+ globalThis.crypto.getRandomValues(randomValues);
18
+ for (const value of randomValues) {
19
+ output += CROCKFORD_BASE32[value % CROCKFORD_BASE32.length];
20
+ }
21
+ return output;
22
+ }
23
+ function createSortableRandomId() {
24
+ let timestamp = Date.now();
25
+ let encodedTime = "";
26
+ for (let index = 0; index < 10; index++) {
27
+ encodedTime = CROCKFORD_BASE32[timestamp % 32] + encodedTime;
28
+ timestamp = Math.floor(timestamp / 32);
29
+ }
30
+ return `${encodedTime}${randomBase32(16)}`;
31
+ }
32
+ function createFabricId(prefix) {
33
+ if (!/^[a-z][a-z0-9]{1,7}$/.test(prefix)) {
34
+ throw new Error(`Invalid Fabric ID prefix: ${prefix}`);
35
+ }
36
+ return `${prefix}_${createSortableRandomId()}`;
37
+ }
38
+ function isFabricId(id, prefix) {
39
+ const match = ID_REGEX.exec(id);
40
+ if (!match) {
41
+ return false;
42
+ }
43
+ return prefix ? match[1] === prefix : true;
44
+ }
45
+ function parseFabricId(id) {
46
+ const match = ID_REGEX.exec(id);
47
+ if (!match) {
48
+ return null;
49
+ }
50
+ return { prefix: match[1], ulid: match[2] };
51
+ }
52
+
53
+ export { FABRIC_ID_PREFIXES, createFabricId, isFabricId, parseFabricId };
54
+ //# sourceMappingURL=chunk-RALMUSOX.js.map
55
+ //# sourceMappingURL=chunk-RALMUSOX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../ids/index.ts"],"names":[],"mappings":";AAAA,IAAM,gBAAA,GAAmB,kCAAA;AAElB,IAAM,kBAAA,GAAqB;AAAA,EACjC,UAAA,EAAY,KAAA;AAAA,EACZ,gBAAA,EAAkB,KAAA;AAAA,EAClB,gBAAA,EAAkB,KAAA;AAAA,EAClB,iBAAA,EAAmB,KAAA;AAAA,EACnB,sBAAA,EAAwB,KAAA;AAAA,EACxB,WAAA,EAAa,KAAA;AAAA,EACb,kBAAA,EAAoB,KAAA;AAAA,EACpB,wBAAA,EAA0B;AAC3B;AAIA,IAAM,QAAA,GAAW,uCAAA;AAEjB,SAAS,aAAa,MAAA,EAAwB;AAC7C,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,MAAM,YAAA,GAAe,IAAI,UAAA,CAAW,MAAM,CAAA;AAC1C,EAAA,UAAA,CAAW,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAC9C,EAAA,KAAA,MAAW,SAAS,YAAA,EAAc;AACjC,IAAA,MAAA,IAAU,gBAAA,CAAiB,KAAA,GAAQ,gBAAA,CAAiB,MAAM,CAAA;AAAA,E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AA,CAAM,CAAC,GAAG,IAAA,EAAM,KAAA,CAAM,CAAC,CAAA,EAAE;AAC3C","file":"chunk-RALMUSOX.js","sourcesContent":["const CROCKFORD_BASE32 = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\nexport const FABRIC_ID_PREFIXES = {\n\tassetEvent: \"evt\",\n\tactionInvocation: \"act\",\n\tpolicyEvaluation: \"pol\",\n\tadapterInvocation: \"adp\",\n\tadapterDeadLetterQueue: \"dlq\",\n\taccessEvent: \"acc\",\n\tprojectionSnapshot: \"psn\",\n\tcomplianceEvidencePacket: \"cep\",\n} as const;\n\nexport type FabricIdPrefix = (typeof FABRIC_ID_PREFIXES)[keyof typeof FABRIC_ID_PREFIXES] | string;\n\nconst ID_REGEX = /^([a-z][a-z0-9]{1,7})_([0-9A-Z]{26})$/;\n\nfunction randomBase32(length: number): string {\n\tlet output = \"\";\n\tconst randomValues = new Uint8Array(length);\n\tglobalThis.crypto.getRandomValues(randomValues);\n\tfor (const value of randomValues) {\n\t\toutput += CROCKFORD_BASE32[value % CROCKFORD_BASE32.length];\n\t}\n\treturn output;\n}\n\nfunction createSortableRandomId(): string {\n\tlet timestamp = Date.now();\n\tlet encodedTime = \"\";\n\tfor (let index = 0; index < 10; index++) {\n\t\tencodedTime = CROCKFORD_BASE32[timestamp % 32] + encodedTime;\n\t\ttimestamp = Math.floor(timestamp / 32);\n\t}\n\treturn `${encodedTime}${randomBase32(16)}`;\n}\n\nexport function createFabricId(prefix: FabricIdPrefix): string {\n\tif (!/^[a-z][a-z0-9]{1,7}$/.test(prefix)) {\n\t\tthrow new Error(`Invalid Fabric ID prefix: ${prefix}`);\n\t}\n\treturn `${prefix}_${createSortableRandomId()}`;\n}\n\nexport function isFabricId(id: string, prefix?: FabricIdPrefix): boolean {\n\tconst match = ID_REGEX.exec(id);\n\tif (!match) {\n\t\treturn false;\n\t}\n\treturn prefix ? match[1] === prefix : true;\n}\n\nexport function parseFabricId(id: string): { prefix: string; ulid: string } | null {\n\tconst match = ID_REGEX.exec(id);\n\tif (!match) {\n\t\treturn null;\n\t}\n\treturn { prefix: match[1], ulid: match[2] };\n}\n"]}
@@ -1,89 +1,3 @@
1
- import assert from 'assert';
2
-
3
- // displays/index.ts
4
- var registry = /* @__PURE__ */ new Map();
5
- function registerDisplayRenderer(eventType, renderer) {
6
- registry.set(eventType, renderer);
7
- }
8
- function resolveDisplayRenderer(eventType) {
9
- return registry.get(eventType);
10
- }
11
- function denormalizeDisplaySnapshot(payload) {
12
- if (payload !== null && typeof payload === "object" && "_displaySnapshot" in payload && payload._displaySnapshot !== null && typeof payload._displaySnapshot === "object" && "title" in payload._displaySnapshot) {
13
- return payload._displaySnapshot;
14
- }
15
- if (payload !== null && typeof payload === "object" && "_projectionSnapshot" in payload && payload._projectionSnapshot !== null && typeof payload._projectionSnapshot === "object" && "display" in payload._projectionSnapshot && payload._projectionSnapshot.display !== null && typeof payload._projectionSnapshot.display === "object" && "title" in payload._projectionSnapshot.display) {
16
- const snapshot = payload._projectionSnapshot;
17
- return {
18
- ...snapshot.display,
19
- _cachedDisplay: {
20
- source: "projection_snapshot",
21
- cursor: snapshot.eventCursor,
22
- checksum: snapshot.checksum,
23
- generatedAt: snapshot.updatedAt
24
- }
25
- };
26
- }
27
- return void 0;
28
- }
29
- async function renderEventDisplay(eventType, payload, ctx) {
30
- const snapshot = denormalizeDisplaySnapshot(payload);
31
- if (snapshot) {
32
- return snapshot;
33
- }
34
- const renderer = resolveDisplayRenderer(eventType);
35
- if (!renderer) {
36
- return {
37
- title: eventType,
38
- subtitle: "No display renderer registered for this event type."
39
- };
40
- }
41
- return await renderer(payload, ctx);
42
- }
43
- async function _runInlineTests() {
44
- const testEventType = "__TestEvent__";
45
- registerDisplayRenderer(testEventType, (payload) => ({
46
- title: `Test: ${payload.name}`,
47
- subtitle: "registered renderer"
48
- }));
49
- const renderer = resolveDisplayRenderer(testEventType);
50
- assert.ok(renderer, "resolveDisplayRenderer should return the registered renderer");
51
- const result = await renderEventDisplay(testEventType, { name: "Alice" });
52
- assert.strictEqual(result.title, "Test: Alice");
53
- assert.strictEqual(result.subtitle, "registered renderer");
54
- const snapshot = {
55
- title: "Snapshot Title",
56
- subtitle: "snapshot subtitle",
57
- stateLabel: "archived",
58
- primaryFacts: [{ label: "ID", value: "123" }]
59
- };
60
- const snapshotResult = await renderEventDisplay(testEventType, {
61
- _displaySnapshot: snapshot
62
- });
63
- assert.deepStrictEqual(snapshotResult, snapshot);
64
- const fallback = await renderEventDisplay("__UnknownEvent__", {});
65
- assert.strictEqual(fallback.title, "__UnknownEvent__");
66
- assert.strictEqual(fallback.subtitle, "No display renderer registered for this event type.");
67
- registerDisplayRenderer("__AsyncEvent__", async (_payload, ctx) => {
68
- return {
69
- title: `Async: ${ctx?.tenantId ?? "no-ctx"}`
70
- };
71
- });
72
- const asyncResult = await renderEventDisplay(
73
- "__AsyncEvent__",
74
- {},
75
- { tenantId: "t-1", spaceId: "s-1", db: {} }
76
- );
77
- assert.strictEqual(asyncResult.title, "Async: t-1");
78
- console.log("\u2705 display engine inline tests passed");
79
- }
80
- if (import.meta.url === `file://${process.argv[1]}`) {
81
- _runInlineTests().catch((err) => {
82
- console.error("\u274C display engine inline tests failed", err);
83
- process.exit(1);
84
- });
85
- }
86
-
87
- export { denormalizeDisplaySnapshot, registerDisplayRenderer, renderEventDisplay, resolveDisplayRenderer };
1
+ export { denormalizeDisplaySnapshot, registerDisplayRenderer, renderEventDisplay, resolveDisplayRenderer } from '../chunk-3F6FKQZA.js';
88
2
  //# sourceMappingURL=index.js.map
89
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,SAAA,EA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B,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":"index.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
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1,55 +1,3 @@
1
- // events/index.ts
2
- var subjectTypeRegistry = /* @__PURE__ */ new Set([
3
- "ActionInvocation",
4
- "PolicyEvaluation",
5
- "AdapterInvocation"
6
- ]);
7
- var eventTypeRegistry = /* @__PURE__ */ new Set([
8
- "ComplianceBlocked",
9
- "StateTransitioned",
10
- "AdapterInvocationStarted",
11
- "AdapterInvocationSucceeded",
12
- "AdapterInvocationFailed",
13
- "WebhookReceived"
14
- ]);
15
- var dynamicSubjectTypes = /* @__PURE__ */ new Set();
16
- var dynamicEventTypes = /* @__PURE__ */ new Set();
17
- function registerSubjectType(type) {
18
- dynamicSubjectTypes.add(type);
19
- }
20
- function isValidSubjectType(type) {
21
- return subjectTypeRegistry.has(type) || dynamicSubjectTypes.has(type);
22
- }
23
- function getRegisteredSubjectTypes() {
24
- return Array.from(/* @__PURE__ */ new Set([...subjectTypeRegistry, ...dynamicSubjectTypes]));
25
- }
26
- function registerEventType(type) {
27
- dynamicEventTypes.add(type);
28
- }
29
- function isValidEventType(type) {
30
- return eventTypeRegistry.has(type) || dynamicEventTypes.has(type);
31
- }
32
- function getRegisteredEventTypes() {
33
- return Array.from(/* @__PURE__ */ new Set([...eventTypeRegistry, ...dynamicEventTypes]));
34
- }
35
- function createEventTypeRegistry(initialEventTypes = []) {
36
- const eventTypes = new Set(initialEventTypes);
37
- return {
38
- register(eventType) {
39
- if (!eventType) {
40
- throw new Error("Event type cannot be empty");
41
- }
42
- eventTypes.add(eventType);
43
- },
44
- has(eventType) {
45
- return eventTypes.has(eventType);
46
- },
47
- list() {
48
- return Array.from(eventTypes).sort();
49
- }
50
- };
51
- }
52
-
53
- export { createEventTypeRegistry, getRegisteredEventTypes, getRegisteredSubjectTypes, isValidEventType, isValidSubjectType, registerEventType, registerSubjectType };
1
+ export { createEventTypeRegistry, getRegisteredEventTypes, getRegisteredSubjectTypes, isValidEventType, isValidSubjectType, registerEventType, registerSubjectType } from '../chunk-4YQOGV7H.js';
54
2
  //# sourceMappingURL=index.js.map
55
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../events/index.ts"],"names":[],"mappings":";AAmBA,IAAM,mBAAA,uBAA0B,GAAA,CAAY;AAAA,EAC3C,kBAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACD,CAAC,CAAA;AAED,IAAM,iBAAA,uBAAwB,GAAA,CAAY;AAAA,EACzC,mBAAA;AAAA,EACA,mBAAA;AAAA,EACA,0BAAA;AAAA,EACA,4BAAA;AAAA,EACA,yBAAA;AAAA,EACA;AACD,CAAC,CAAA;AAED,IAAM,mBAAA,uBAA0B,GAAA,EAAY;AAC5C,IAAM,iBAAA,uBAAwB,GAAA,EAAY;AAMnC,SAAS,oBAAoB,IAAA,EAAoB;AACvD,EAAA,mBAAA,CAAoB,IAAI,IAAI,CAAA;AAC7B;AAEO,SAAS,mBAAmB,IAAA,EAAuB;AACzD,EAAA,OAAO,oBAAoB,GAAA,CAAI,IAAI,CAAA,IAAK,mBAAA,CAAoB,IAAI,IAAI,CAAA;AACrE;AAEO,SAAS,yBAAA,GAAsC;AACrD,EAAA,OAAO,KAAA,CAAM,IAAA,iBAAK,IAAI,GAAA,CAAI,CAAC,GAAG,mBAAA,EAAqB,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAC5E;AAEO,SAAS,kBAAkB,IAAA,EAAoB;AACrD,EAAA,iBAAA,CAAkB,IAAI,IAAI,CAAA;AAC3B;AAEO,SAAS,iBAAiB,IAAA,EAAuB;AACvD,EAAA,OAAO,kBAAkB,GAAA,CAAI,IAAI,CAAA,IAAK,iBAAA,CAAkB,IAAI,IAAI,CAAA;AACjE;AAEO,SAAS,uBAAA,GAAoC;AACnD,EAAA,OAAO,KAAA,CAAM,IAAA,iBAAK,IAAI,GAAA,CAAI,CAAC,GAAG,iBAAA,EAAmB,GAAG,iBAAiB,CAAC,CAAC,CAAA;AACxE;AAQO,SAAS,uBAAA,CAAwB,iBAAA,GAA8B,EAAC,EAAsB;AAC5F,EAAA,MAAM,UAAA,GAAa,IAAI,GAAA,CAAI,iBAAiB,CAAA;AAC5C,EAAA,OAAO;AAAA,IACN,SAAS,SAAA,EAAW;AACnB,MAAA,IAAI,CAAC,SAAA,EAAW;AACf,QAAA,MAAM,IAAI,MAAM,4BAA4B,CAAA;AAAA,MAC7C;AACA,MAAA,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IACzB,CAAA;AAAA,IACA,IAAI,SAAA,EAAW;AACd,MAAA,OAAO,UAAA,CAAW,IAAI,SAAS,CAAA;AAAA,IAChC,CAAA;AAAA,IACA,IAAA,GAAO;AACN,MAAA,OAAO,KAAA,CAAM,IAAA,CAAK,UAAU,CAAA,CAAE,IAAA,EAAK;AAAA,IACpC;AAAA,GACD;AACD","file":"index.js","sourcesContent":["export interface AssetEventEnvelope<TPayload = unknown> {\n\tid: string;\n\ttenantId: string;\n\tspaceId: string;\n\teventType: string;\n\teventSchemaVersion: number;\n\tsubjectType: string;\n\tsubjectId: string;\n\tactorId: string;\n\tactorType: string;\n\tactionInvocationId?: string;\n\tpayload: TPayload;\n\tsequence: number;\n\toccurredAt: Date;\n\trecordedAt: Date;\n\tcorrelationId: string;\n\tcausationId?: string;\n}\n\nconst subjectTypeRegistry = new Set<string>([\n\t\"ActionInvocation\",\n\t\"PolicyEvaluation\",\n\t\"AdapterInvocation\",\n]);\n\nconst eventTypeRegistry = new Set<string>([\n\t\"ComplianceBlocked\",\n\t\"StateTransitioned\",\n\t\"AdapterInvocationStarted\",\n\t\"AdapterInvocationSucceeded\",\n\t\"AdapterInvocationFailed\",\n\t\"WebhookReceived\",\n]);\n\nconst dynamicSubjectTypes = new Set<string>();\nconst dynamicEventTypes = new Set<string>();\n\nexport type AssetEventSubjectType = string;\nexport type AssetEventType = string;\nexport type AssetEventActorType = \"natural_person\" | \"agent\" | \"adapter\" | \"system\" | \"service_account\" | \"external_system\" | \"integration\";\n\nexport function registerSubjectType(type: string): void {\n\tdynamicSubjectTypes.add(type);\n}\n\nexport function isValidSubjectType(type: string): boolean {\n\treturn subjectTypeRegistry.has(type) || dynamicSubjectTypes.has(type);\n}\n\nexport function getRegisteredSubjectTypes(): string[] {\n\treturn Array.from(new Set([...subjectTypeRegistry, ...dynamicSubjectTypes]));\n}\n\nexport function registerEventType(type: string): void {\n\tdynamicEventTypes.add(type);\n}\n\nexport function isValidEventType(type: string): boolean {\n\treturn eventTypeRegistry.has(type) || dynamicEventTypes.has(type);\n}\n\nexport function getRegisteredEventTypes(): string[] {\n\treturn Array.from(new Set([...eventTypeRegistry, ...dynamicEventTypes]));\n}\n\nexport interface EventTypeRegistry {\n\tregister(eventType: string): void;\n\thas(eventType: string): boolean;\n\tlist(): string[];\n}\n\nexport function createEventTypeRegistry(initialEventTypes: string[] = []): EventTypeRegistry {\n\tconst eventTypes = new Set(initialEventTypes);\n\treturn {\n\t\tregister(eventType) {\n\t\t\tif (!eventType) {\n\t\t\t\tthrow new Error(\"Event type cannot be empty\");\n\t\t\t}\n\t\t\teventTypes.add(eventType);\n\t\t},\n\t\thas(eventType) {\n\t\t\treturn eventTypes.has(eventType);\n\t\t},\n\t\tlist() {\n\t\t\treturn Array.from(eventTypes).sort();\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1,3 +1,3 @@
1
-
1
+ import '../chunk-OZLZHISS.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/ids/index.js CHANGED
@@ -1,55 +1,3 @@
1
- // ids/index.ts
2
- var CROCKFORD_BASE32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
3
- var FABRIC_ID_PREFIXES = {
4
- assetEvent: "evt",
5
- actionInvocation: "act",
6
- policyEvaluation: "pol",
7
- adapterInvocation: "adp",
8
- adapterDeadLetterQueue: "dlq",
9
- accessEvent: "acc",
10
- projectionSnapshot: "psn",
11
- complianceEvidencePacket: "cep"
12
- };
13
- var ID_REGEX = /^([a-z][a-z0-9]{1,7})_([0-9A-Z]{26})$/;
14
- function randomBase32(length) {
15
- let output = "";
16
- const randomValues = new Uint8Array(length);
17
- globalThis.crypto.getRandomValues(randomValues);
18
- for (const value of randomValues) {
19
- output += CROCKFORD_BASE32[value % CROCKFORD_BASE32.length];
20
- }
21
- return output;
22
- }
23
- function createSortableRandomId() {
24
- let timestamp = Date.now();
25
- let encodedTime = "";
26
- for (let index = 0; index < 10; index++) {
27
- encodedTime = CROCKFORD_BASE32[timestamp % 32] + encodedTime;
28
- timestamp = Math.floor(timestamp / 32);
29
- }
30
- return `${encodedTime}${randomBase32(16)}`;
31
- }
32
- function createFabricId(prefix) {
33
- if (!/^[a-z][a-z0-9]{1,7}$/.test(prefix)) {
34
- throw new Error(`Invalid Fabric ID prefix: ${prefix}`);
35
- }
36
- return `${prefix}_${createSortableRandomId()}`;
37
- }
38
- function isFabricId(id, prefix) {
39
- const match = ID_REGEX.exec(id);
40
- if (!match) {
41
- return false;
42
- }
43
- return prefix ? match[1] === prefix : true;
44
- }
45
- function parseFabricId(id) {
46
- const match = ID_REGEX.exec(id);
47
- if (!match) {
48
- return null;
49
- }
50
- return { prefix: match[1], ulid: match[2] };
51
- }
52
-
53
- export { FABRIC_ID_PREFIXES, createFabricId, isFabricId, parseFabricId };
1
+ export { FABRIC_ID_PREFIXES, createFabricId, isFabricId, parseFabricId } from '../chunk-RALMUSOX.js';
54
2
  //# sourceMappingURL=index.js.map
55
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ids/index.ts"],"names":[],"mappings":";AAAA,IAAM,gBAAA,GAAmB,kCAAA;AAElB,IAAM,kBAAA,GAAqB;AAAA,EACjC,UAAA,EAAY,KAAA;AAAA,EACZ,gBAAA,EAAkB,KAAA;AAAA,EAClB,gBAAA,EAAkB,KAAA;AAAA,EAClB,iBAAA,EAAmB,KAAA;AAAA,EACnB,sBAAA,EAAwB,KAAA;AAAA,EACxB,WAAA,EAAa,KAAA;AAAA,EACb,kBAAA,EAAoB,KAAA;AAAA,EACpB,wBAAA,EAA0B;AAC3B;AAIA,IAAM,QAAA,GAAW,uCAAA;AAEjB,SAAS,aAAa,MAAA,EAAwB;AAC7C,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,MAAM,YAAA,GAAe,IAAI,UAAA,CAAW,MAAM,CAAA;AAC1C,EAAA,UAAA,CAAW,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAC9C,EAAA,KAAA,MAAW,SAAS,YAAA,EAAc;AACjC,IAAA,MAAA,IAAU,gBAAA,CAAiB,KAAA,GAAQ,gBAAA,CAAiB,MAAM,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,MAAA;AACR;AAEA,SAAS,sBAAA,GAAiC;AACzC,EAAA,IAAI,SAAA,GAAY,KAAK,GAAA,EAAI;AACzB,EAAA,IAAI,WAAA,GAAc,EAAA;AAClB,EAAA,KAAA,IAAS,KAAA,GAAQ,CAAA,EAAG,KAAA,GAAQ,EAAA,EAAI,KAAA,EAAA,EAAS;AACxC,IAAA,WAAA,GAAc,gBAAA,CAAiB,SAAA,GAAY,EAAE,CAAA,GAAI,WAAA;AACjD,IAAA,SAAA,GAAY,IAAA,CAAK,KAAA,CAAM,SAAA,GAAY,EAAE,CAAA;AAAA,EACtC;AACA,EAAA,OAAO,CAAA,EAAG,WAAW,CAAA,EAAG,YAAA,CAAa,EAAE,CAAC,CAAA,CAAA;AACzC;AAEO,SAAS,eAAe,MAAA,EAAgC;AAC9D,EAAA,IAAI,CAAC,sBAAA,CAAuB,IAAA,CAAK,MAAM,CAAA,EAAG;AACzC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,0BAAA,EAA6B,MAAM,CAAA,CAAE,CAAA;AAAA,EACtD;AACA,EAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,sBAAA,EAAwB,CAAA,CAAA;AAC7C;AAEO,SAAS,UAAA,CAAW,IAAY,MAAA,EAAkC;AACxE,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,IAAA,CAAK,EAAE,CAAA;AAC9B,EAAA,IAAI,CAAC,KAAA,EAAO;AACX,IAAA,OAAO,KAAA;AAAA,EACR;AACA,EAAA,OAAO,MAAA,GAAS,KAAA,CAAM,CAAC,CAAA,KAAM,MAAA,GAAS,IAAA;AACvC;AAEO,SAAS,cAAc,EAAA,EAAqD;AAClF,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,IAAA,CAAK,EAAE,CAAA;AAC9B,EAAA,IAAI,CAAC,KAAA,EAAO;AACX,IAAA,OAAO,IAAA;AAAA,EACR;AACA,EAAA,OAAO,EAAE,QAAQ,KAAA,CAAM,CAAC,GAAG,IAAA,EAAM,KAAA,CAAM,CAAC,CAAA,EAAE;AAC3C","file":"index.js","sourcesContent":["const CROCKFORD_BASE32 = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\nexport const FABRIC_ID_PREFIXES = {\n\tassetEvent: \"evt\",\n\tactionInvocation: \"act\",\n\tpolicyEvaluation: \"pol\",\n\tadapterInvocation: \"adp\",\n\tadapterDeadLetterQueue: \"dlq\",\n\taccessEvent: \"acc\",\n\tprojectionSnapshot: \"psn\",\n\tcomplianceEvidencePacket: \"cep\",\n} as const;\n\nexport type FabricIdPrefix = (typeof FABRIC_ID_PREFIXES)[keyof typeof FABRIC_ID_PREFIXES] | string;\n\nconst ID_REGEX = /^([a-z][a-z0-9]{1,7})_([0-9A-Z]{26})$/;\n\nfunction randomBase32(length: number): string {\n\tlet output = \"\";\n\tconst randomValues = new Uint8Array(length);\n\tglobalThis.crypto.getRandomValues(randomValues);\n\tfor (const value of randomValues) {\n\t\toutput += CROCKFORD_BASE32[value % CROCKFORD_BASE32.length];\n\t}\n\treturn output;\n}\n\nfunction createSortableRandomId(): string {\n\tlet timestamp = Date.now();\n\tlet encodedTime = \"\";\n\tfor (let index = 0; index < 10; index++) {\n\t\tencodedTime = CROCKFORD_BASE32[timestamp % 32] + encodedTime;\n\t\ttimestamp = Math.floor(timestamp / 32);\n\t}\n\treturn `${encodedTime}${randomBase32(16)}`;\n}\n\nexport function createFabricId(prefix: FabricIdPrefix): string {\n\tif (!/^[a-z][a-z0-9]{1,7}$/.test(prefix)) {\n\t\tthrow new Error(`Invalid Fabric ID prefix: ${prefix}`);\n\t}\n\treturn `${prefix}_${createSortableRandomId()}`;\n}\n\nexport function isFabricId(id: string, prefix?: FabricIdPrefix): boolean {\n\tconst match = ID_REGEX.exec(id);\n\tif (!match) {\n\t\treturn false;\n\t}\n\treturn prefix ? match[1] === prefix : true;\n}\n\nexport function parseFabricId(id: string): { prefix: string; ulid: string } | null {\n\tconst match = ID_REGEX.exec(id);\n\tif (!match) {\n\t\treturn null;\n\t}\n\treturn { prefix: match[1], ulid: match[2] };\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}