@dotbep/core 0.2.7 → 0.2.8

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 (77) hide show
  1. package/dist/index.d.ts +7 -5
  2. package/dist/index.js +604 -596
  3. package/package.json +4 -1
  4. package/examples/01-participants.ts +0 -127
  5. package/examples/02-files.ts +0 -100
  6. package/examples/03-workflows.ts +0 -149
  7. package/examples/04-bim-uses.ts +0 -70
  8. package/examples/05-standards.ts +0 -60
  9. package/examples/06-schedule.ts +0 -124
  10. package/examples/07-loin.ts +0 -133
  11. package/examples/08-deliverables.ts +0 -126
  12. package/examples/09-notes.ts +0 -73
  13. package/examples/10-llm.ts +0 -109
  14. package/examples/11-resolved.ts +0 -133
  15. package/examples/12-history.ts +0 -166
  16. package/examples/13-engine.ts +0 -152
  17. package/examples/bep.d.ts +0 -38
  18. package/examples/example.bep +0 -0
  19. package/examples/run-all.ts +0 -38
  20. package/src/base/entity.ts +0 -148
  21. package/src/base/history.ts +0 -497
  22. package/src/base/index.ts +0 -5
  23. package/src/base/singleton.ts +0 -26
  24. package/src/entities/actions.ts +0 -25
  25. package/src/entities/adapters.ts +0 -16
  26. package/src/entities/annexes.ts +0 -17
  27. package/src/entities/assetTypes.ts +0 -30
  28. package/src/entities/automations.ts +0 -24
  29. package/src/entities/bimUses.ts +0 -50
  30. package/src/entities/deliverables.ts +0 -66
  31. package/src/entities/disciplines.ts +0 -21
  32. package/src/entities/effects.ts +0 -28
  33. package/src/entities/env.ts +0 -17
  34. package/src/entities/events.ts +0 -24
  35. package/src/entities/extensions.ts +0 -16
  36. package/src/entities/flags.ts +0 -17
  37. package/src/entities/guides.ts +0 -26
  38. package/src/entities/index.ts +0 -32
  39. package/src/entities/lbsNodes.ts +0 -193
  40. package/src/entities/lods.ts +0 -22
  41. package/src/entities/loin.ts +0 -127
  42. package/src/entities/lois.ts +0 -22
  43. package/src/entities/members.ts +0 -137
  44. package/src/entities/milestones.ts +0 -32
  45. package/src/entities/notes.ts +0 -27
  46. package/src/entities/objectives.ts +0 -17
  47. package/src/entities/phases.ts +0 -17
  48. package/src/entities/remoteData.ts +0 -17
  49. package/src/entities/resolvers.ts +0 -20
  50. package/src/entities/roles.ts +0 -29
  51. package/src/entities/softwares.ts +0 -26
  52. package/src/entities/standards.ts +0 -68
  53. package/src/entities/teams.ts +0 -42
  54. package/src/entities/workflows.ts +0 -256
  55. package/src/index.ts +0 -464
  56. package/src/runtime/Engine.ts +0 -352
  57. package/src/runtime/MemoryStorage.ts +0 -31
  58. package/src/runtime/Runtime.ts +0 -106
  59. package/src/runtime/index.ts +0 -4
  60. package/src/runtime/transitions.ts +0 -456
  61. package/src/runtime/types.ts +0 -279
  62. package/src/types/history.ts +0 -37
  63. package/src/types/index.ts +0 -24
  64. package/src/types/resolved.ts +0 -137
  65. package/src/types/schema.ts +0 -757
  66. package/src/utils/diff.ts +0 -109
  67. package/src/utils/index.ts +0 -9
  68. package/src/utils/integrity.ts +0 -108
  69. package/src/utils/lbs.ts +0 -116
  70. package/src/utils/mermaid.ts +0 -110
  71. package/src/utils/naming.ts +0 -62
  72. package/src/utils/nomenclature.ts +0 -107
  73. package/src/utils/normalize.ts +0 -35
  74. package/src/utils/raci.ts +0 -25
  75. package/src/utils/textFile.ts +0 -24
  76. package/tsconfig.json +0 -12
  77. package/vite.config.ts +0 -24
@@ -1,279 +0,0 @@
1
- // Runtime types for dotBEP workflow engine.
2
- // These are separate from the BEP schema (bep.json) — instances live outside
3
- // the plan file and represent the live execution state of each workflow.
4
-
5
- // ─── Status ───────────────────────────────────────────────────────────────────
6
-
7
- export type InstanceStatus = 'active' | 'completed' | 'suspended' | 'error'
8
-
9
- // ─── Incoming event ───────────────────────────────────────────────────────────
10
-
11
- /** What a software or user emits to trigger a transition. */
12
- export interface IncomingEvent {
13
- /** ref FlowEvent.id */
14
- eventId: string
15
- /** ref Software.id — identifies which software is emitting. */
16
- softwareId?: string
17
- /** Member.email of the person or system acting. */
18
- actor: string
19
- /** Key-value payload validated against FlowEvent.payload definition. */
20
- payload?: Record<string, unknown>
21
- }
22
-
23
- // ─── Transition log ───────────────────────────────────────────────────────────
24
-
25
- /** Immutable log entry written after each successful transition. */
26
- export interface TransitionEvent {
27
- id: string
28
- /** ref FlowEdge key */
29
- edgeId: string
30
- fromNodeId: string
31
- toNodeId: string
32
- /** The event that triggered this transition. */
33
- trigger: IncomingEvent
34
- /** Member.email */
35
- actor: string
36
- /** ISO 8601 datetime */
37
- timestamp: string
38
- /**
39
- * True when this transition was performed automatically by the engine
40
- * (e.g. decision node auto-traversal). The actor and trigger fields still
41
- * reflect the event that caused the automation, not a human action.
42
- */
43
- auto?: boolean
44
- notes?: string
45
- }
46
-
47
- // ─── Workflow instance ────────────────────────────────────────────────────────
48
-
49
- export interface WorkflowInstance {
50
- id: string
51
- /** ref Workflow.id */
52
- workflowId: string
53
- /** BEP version at the time this instance was created — used to load the correct workflow definition. */
54
- bepVersion: string
55
-
56
- /** The asset this instance is tracking. */
57
- trackedAsset: {
58
- /** ref AssetType.id */
59
- assetTypeId: string
60
- /**
61
- * Namespace that identifies where the asset lives.
62
- * Format: "bep:<entityName>" for BEP-internal entities (e.g. "bep:deliverables"),
63
- * or "external:<softwareId>" for assets in external systems (e.g. "external:software-acc").
64
- * The softwareId must match a Software.id declared in the BEP (which cannot contain colons).
65
- */
66
- source: string
67
- /** ID of the asset — ref to the entity within the source. */
68
- id: string
69
- label: string
70
- }
71
-
72
- /** Key of the current FlowNode. Not a decision node — engine auto-traverses those. */
73
- currentNodeId: string
74
- status: InstanceStatus
75
- /** Ordered log of all transitions, oldest first. */
76
- history: TransitionEvent[]
77
-
78
- /** Set when this instance was spawned by a parent instance. */
79
- parentInstanceId?: string
80
- /** FlowNode key in the parent workflow that spawned this instance. */
81
- parentNodeId?: string
82
-
83
- /** ISO 8601 datetime */
84
- createdAt: string
85
- /** ISO 8601 datetime */
86
- updatedAt: string
87
- /** Member.email */
88
- initiatedBy: string
89
- }
90
-
91
- // ─── Instance filter ──────────────────────────────────────────────────────────
92
-
93
- export interface InstanceFilter {
94
- /** ref Workflow.id */
95
- workflowId?: string
96
- status?: InstanceStatus
97
- /** Member.email — returns instances where this actor has a pending RACI action. */
98
- pendingActionFor?: string
99
- /** ref AssetType.id */
100
- trackedAssetTypeId?: string
101
- /** ID of the asset in the external system. */
102
- trackedAssetId?: string
103
- }
104
-
105
- // ─── Node config ──────────────────────────────────────────────────────────────
106
-
107
- /** Role reference with minimal resolved fields. */
108
- export interface RoleRef {
109
- id: string
110
- name: string
111
- }
112
-
113
- /** Team reference with minimal resolved fields. */
114
- export interface TeamRef {
115
- id: string
116
- name: string
117
- }
118
-
119
- /**
120
- * Resolved RACI assignment for one letter (R/A/C/I) at a node.
121
- * Three levels of specificity: emails > teams+roles > roles.
122
- */
123
- export interface RaciLevel {
124
- roles: RoleRef[]
125
- teams: TeamRef[]
126
- /** Explicit member emails authorized regardless of role or team. */
127
- emails: string[]
128
- }
129
-
130
- /** Describes what a specific actor can do from the current node of an instance. */
131
- export interface NodeConfig {
132
- currentNode: {
133
- id: string
134
- type: string
135
- label: string
136
- }
137
-
138
- /** Transitions this actor can trigger right now. */
139
- availableTransitions: {
140
- edgeId: string
141
- label: string
142
- /** eventId to emit */
143
- emits: string
144
- requiredPayload: { key: string; type: string; required: boolean }[]
145
- }[]
146
-
147
- /** Transitions that exist but this actor cannot trigger. */
148
- blockedTransitions: {
149
- edgeId: string
150
- label: string
151
- reason: 'UNAUTHORIZED' | 'GUARD_UNSATISFIABLE'
152
- /** What the node requires to authorize this transition. */
153
- required: RaciLevel
154
- }[]
155
-
156
- /** RACI assignment for the current node — resolved to roles, teams and emails. */
157
- raci: {
158
- responsible: RaciLevel
159
- accountable: RaciLevel
160
- consulted: RaciLevel
161
- informed: RaciLevel
162
- }
163
-
164
- /** True if the current node is type "end". */
165
- isTerminal: boolean
166
- }
167
-
168
- // ─── Engine result types ──────────────────────────────────────────────────────
169
-
170
- export type ProcessEventError =
171
- | 'INSTANCE_NOT_ACTIVE'
172
- | 'NO_MATCHING_EDGE'
173
- | 'AMBIGUOUS_TRANSITION'
174
- | 'DECISION_LOOP'
175
- | 'UNAUTHORIZED'
176
- | 'INVALID_PAYLOAD'
177
-
178
- export interface PayloadFieldError {
179
- field: string
180
- reason: 'missing' | 'wrong_type' | 'unknown_field'
181
- }
182
-
183
- export interface TransitionStep {
184
- edgeId: string
185
- fromNodeId: string
186
- toNodeId: string
187
- }
188
-
189
- // ─── Effect execution ─────────────────────────────────────────────────────────
190
-
191
- /**
192
- * Handler registered for a specific effectId.
193
- * Receives the instance and the payload filtered to the keys defined
194
- * in FlowEffect.payload (resolved from instance.context).
195
- */
196
- export type EffectHandler = (
197
- instance: WorkflowInstance,
198
- payload: Record<string, unknown>,
199
- ) => Promise<void>
200
-
201
- /**
202
- * Handler registered for a specific Resolver.id.
203
- * Fetches and transforms data from an external source, returning a raw payload
204
- * for the lens to render. Never handles authentication tokens directly —
205
- * credentials are passed via env.
206
- */
207
- export type ResolverHandler = (
208
- url: string,
209
- env: Record<string, string>,
210
- ) => Promise<unknown>
211
-
212
- /**
213
- * Handler registered for a specific Adapter.id.
214
- * Receives the raw output of a resolver and returns a transformed payload
215
- * compatible with the target lens input schema.
216
- */
217
- export type AdapterHandler = (data: unknown) => unknown
218
-
219
- /**
220
- * Handler for an automation node. Receives the instance and the payload filtered
221
- * from instance.context according to FlowAutomation.payload. Must return an object
222
- * with an eventId matching the FlowEvent declared on the outgoing edge, plus any
223
- * additional payload fields used by guards.
224
- */
225
- export type AutomationHandler = (
226
- instance: WorkflowInstance,
227
- payload: Record<string, unknown>,
228
- ) => Promise<{ eventId: string } & Record<string, unknown>>
229
-
230
- export interface EffectOutcome {
231
- effectId: string
232
- fromEdgeId: string
233
- /** executed = handler ran ok | skipped = no handler or missing required fields | failed = handler threw */
234
- status: 'executed' | 'skipped' | 'failed'
235
- /** Required context fields that were missing. Present when status = 'skipped'. */
236
- missingFields?: string[]
237
- /** Error message thrown by the handler. Present when status = 'failed'. */
238
- error?: string
239
- }
240
-
241
- /** Public result returned by Runtime.emit(). */
242
- export interface EventResult {
243
- ok: boolean
244
- instance?: WorkflowInstance
245
- transitionsApplied?: TransitionStep[]
246
- effects?: EffectOutcome[]
247
- error?: ProcessEventError
248
- /** Present when error = 'INVALID_PAYLOAD'. */
249
- payloadErrors?: PayloadFieldError[]
250
- }
251
-
252
- // ─── Lifecycle listeners ──────────────────────────────────────────────────────
253
-
254
- /** Fires after every successful emit() — transitions applied and effects executed. */
255
- export type TransitionListener = (
256
- instance: WorkflowInstance,
257
- transitionsApplied: TransitionStep[],
258
- effects: EffectOutcome[],
259
- ) => Promise<void>
260
-
261
- /** Fires after createInstance() persists the new instance. */
262
- export type LifecycleListener = (instance: WorkflowInstance) => Promise<void>
263
-
264
- /** Fires when an effect handler throws or returns status 'failed'. */
265
- export type EffectFailedListener = (
266
- instance: WorkflowInstance,
267
- outcome: EffectOutcome,
268
- ) => Promise<void>
269
-
270
- // ─── Storage interface ────────────────────────────────────────────────────────
271
-
272
- /** Abstraction over where instances are persisted. */
273
- export interface InstanceStore {
274
- listInstances(filter?: InstanceFilter): Promise<WorkflowInstance[]>
275
- getInstance(instanceId: string): Promise<WorkflowInstance | null>
276
- saveInstance(instance: WorkflowInstance): Promise<void>
277
- deleteInstance(instanceId: string): Promise<void>
278
- }
279
-
@@ -1,37 +0,0 @@
1
- import type { BEPVersion } from './schema.js'
2
-
3
- export type SectionDiff = { added: string[]; removed: string[]; modified: string[] }
4
-
5
- export type BepDiff = {
6
- /** Changed fields in bep.project, or null if the project object is unchanged. */
7
- project: { changed: true; fields: string[] } | null
8
- /** Per-entity diff (only entities with at least one change are included). */
9
- sections: Record<string, SectionDiff>
10
- /** Top-level keys that changed — 'project' + entity array keys with changes. */
11
- changedKeys: string[]
12
- }
13
-
14
- export type StandardChange = {
15
- id: string
16
- name: string
17
- status: 'added' | 'removed' | 'modified' | 'content-modified'
18
- }
19
-
20
- export type BepStatus = BepDiff & {
21
- hasPendingChanges: boolean
22
- standards: StandardChange[]
23
- }
24
-
25
- // Omit doesn't distribute over unions in TypeScript — DistributiveOmit does.
26
- type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never
27
-
28
- /** Input params for commit — computed fields (version, date, diff) are excluded. */
29
- export type CommitParams = DistributiveOmit<BEPVersion, 'version' | 'date' | 'diff'>
30
-
31
- export type SquashParams = {
32
- /** New terminus version — must be X.0 format and greater than current. */
33
- newBase: string
34
- author: string
35
- description: string
36
- approvedBy: string[]
37
- }
@@ -1,24 +0,0 @@
1
- export * from './schema.js'
2
- export type {
3
- RaciAssignment,
4
- RaciRow,
5
- RaciMatrix,
6
- MemberResolved,
7
- TeamResolved,
8
- MilestoneResolved,
9
- LBSNodeResolved,
10
- AssetTypeResolved,
11
- SoftwareResolved,
12
- BIMUseResolved,
13
- FlowNodeResolved,
14
- FlowDiagramResolved,
15
- WorkflowResolved,
16
- GuideResolved,
17
- ActionResolved,
18
- RaciEntry,
19
- LOINMilestoneResolved,
20
- LOINResolved,
21
- DeliverableResolved,
22
- NoteResolved,
23
- } from './resolved.js'
24
- export type { SectionDiff, BepDiff, BepStatus, StandardChange, CommitParams, SquashParams } from './history.js'
@@ -1,137 +0,0 @@
1
- import type {
2
- Action, Annex, FlowAutomation, BIMUse, Deliverable, Discipline,
3
- AssetType, Extension, Role, Guide, LBSNode,
4
- LOD, LOI, LOIN, LOINMilestone, Member, Milestone, Note,
5
- Objective, Phase, Software, Team, Workflow, FlowDiagram, NodeType, NodeTimeout,
6
- } from './schema.js'
7
-
8
- // ─── RACI ─────────────────────────────────────────────────────────────────────
9
-
10
- export type RaciAssignment = {
11
- role: Role
12
- members: MemberResolved[]
13
- team: TeamResolved | null
14
- }
15
-
16
- export type RaciRow = {
17
- workflow: { id: string; name: string }
18
- nodeId: string
19
- label: string
20
- actionId?: string
21
- description?: string
22
- responsible: RaciAssignment[]
23
- accountable: RaciAssignment[]
24
- consulted: RaciAssignment[]
25
- informed: RaciAssignment[]
26
- }
27
-
28
- export type RaciMatrix = {
29
- /** All unique roles present across all rows — use as column headers. */
30
- roles: Role[]
31
- rows: RaciRow[]
32
- }
33
-
34
- export type MemberResolved = Omit<Member, 'roleId'> & {
35
- role: Role | null
36
- team: { id: string; name: string } | null
37
- isRepresentative: boolean
38
- }
39
-
40
- export type TeamResolved = Omit<Team, 'representativeEmail' | 'memberEmails' | 'disciplineIds'> & {
41
- representative: MemberResolved | null
42
- members: MemberResolved[]
43
- disciplines: Discipline[]
44
- }
45
-
46
- export type MilestoneResolved = Omit<Milestone, 'phaseId'> & {
47
- phase: Phase | null
48
- }
49
-
50
- export type LBSNodeResolved = Omit<LBSNode, 'lbsNodeIds'> & {
51
- isRoot: boolean
52
- parent: Pick<LBSNode, 'id' | 'name' | 'type'> | null
53
- children: LBSNode[]
54
- }
55
-
56
- export type AssetTypeResolved = Omit<AssetType, 'extensionIds'> & {
57
- extensions: Extension[]
58
- }
59
-
60
- export type SoftwareResolved = Omit<Software, 'assetTypeIds'> & {
61
- assetTypes: AssetTypeResolved[]
62
- }
63
-
64
- export type BIMUseResolved = Omit<BIMUse, 'objectiveIds' | 'milestoneIds' | 'workflowIds'> & {
65
- objectives: Objective[]
66
- milestones: MilestoneResolved[]
67
- workflows: WorkflowResolved[]
68
- }
69
-
70
- /** Resolved RACI assignment for one letter (R/A/C/I) at a node. */
71
- export type RaciEntry = {
72
- roles: Role[]
73
- teams: Team[]
74
- members: Member[]
75
- }
76
-
77
- export type FlowNodeResolved = {
78
- type: NodeType
79
- label?: string
80
- workflowId?: string
81
- blocking?: boolean
82
- timeouts?: NodeTimeout[]
83
- action: Action | null
84
- automation: FlowAutomation | null
85
- responsible: RaciEntry
86
- accountable: RaciEntry
87
- consulted: RaciEntry
88
- informed: RaciEntry
89
- }
90
-
91
- export type FlowDiagramResolved = Omit<FlowDiagram, 'nodes'> & {
92
- nodes: Record<string, FlowNodeResolved>
93
- }
94
-
95
- export type WorkflowResolved = Omit<Workflow, 'diagram'> & {
96
- diagram: FlowDiagramResolved
97
- }
98
-
99
- export type GuideResolved = Omit<Guide, 'annexIds'> & {
100
- annexes: Annex[]
101
- }
102
-
103
- export type ActionResolved = Omit<Action, 'guideIds' | 'softwareIds'> & {
104
- guides: GuideResolved[]
105
- softwares: Software[]
106
- }
107
-
108
- export type LOINMilestoneResolved = Omit<LOINMilestone, 'milestoneId' | 'lodId' | 'loiId'> & {
109
- milestone: Milestone | null
110
- lod: LOD | null
111
- loi: LOI | null
112
- }
113
-
114
- export type LOINResolved = Omit<LOIN, 'disciplineId' | 'milestones'> & {
115
- discipline: Discipline | null
116
- milestones: LOINMilestoneResolved[]
117
- }
118
-
119
- export type DeliverableResolved = Omit<
120
- Deliverable,
121
- 'lbsNodeId' | 'disciplineId' | 'assetTypeId' | 'extensionIds' | 'responsibleId' | 'milestoneId' | 'predecessorId'
122
- > & {
123
- nomenclatureCode: string
124
- /** Resolved delivery date: dueDate if set, otherwise the milestone's date. */
125
- effectiveDate: string
126
- lbsNode: LBSNodeResolved | null
127
- discipline: Discipline | null
128
- assetType: AssetTypeResolved | null
129
- extensions: Extension[]
130
- responsible: TeamResolved | null
131
- milestone: MilestoneResolved | null
132
- predecessor: DeliverableResolved | null
133
- }
134
-
135
- export type NoteResolved = Omit<Note, 'memberEmail'> & {
136
- member: MemberResolved | null
137
- }