@elevasis/core 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +157 -100
- package/dist/index.js +116 -46
- package/dist/knowledge/index.d.ts +22 -22
- package/dist/organization-model/index.d.ts +157 -100
- package/dist/organization-model/index.js +116 -46
- package/dist/test-utils/index.d.ts +18 -18
- package/dist/test-utils/index.js +22 -20
- package/package.json +3 -3
- package/src/organization-model/__tests__/define-domain-record.test.ts +289 -0
- package/src/organization-model/__tests__/om-spine-doc-contract.test.ts +56 -0
- package/src/organization-model/domains/actions.ts +13 -0
- package/src/organization-model/domains/customers.ts +95 -78
- package/src/organization-model/domains/entities.ts +157 -144
- package/src/organization-model/domains/goals.ts +100 -83
- package/src/organization-model/domains/knowledge.ts +106 -93
- package/src/organization-model/domains/offerings.ts +88 -71
- package/src/organization-model/domains/policies.ts +115 -102
- package/src/organization-model/domains/roles.ts +109 -96
- package/src/organization-model/domains/statuses.ts +351 -339
- package/src/organization-model/domains/systems.ts +176 -164
- package/src/organization-model/helpers.ts +331 -306
- package/src/organization-model/index.ts +42 -0
- package/src/organization-model/published.ts +27 -2
- package/src/platform/constants/versions.ts +1 -1
- package/src/reference/_generated/contracts.md +24 -24
|
@@ -1,306 +1,331 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function
|
|
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
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function
|
|
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
|
-
return
|
|
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
|
-
export function
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*/
|
|
230
|
-
export function
|
|
231
|
-
model
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
includeDescendants
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { OrganizationModel, OrganizationModelSystemEntry } from './types'
|
|
3
|
+
import type { JsonValue } from './domains/systems'
|
|
4
|
+
import type { ResourceEntry } from './domains/resources'
|
|
5
|
+
import type { OmTopologyRelationship } from './domains/topology'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Generic domain-record factory. Validates every entry through the given Zod
|
|
9
|
+
* schema (throws `ZodError` on invalid input) and returns an id-keyed map.
|
|
10
|
+
*
|
|
11
|
+
* Each entry MUST carry an `id` field — validated at runtime via the parsed
|
|
12
|
+
* result. Use the per-domain `defineX` / `defineXs` wrappers at call sites for
|
|
13
|
+
* schema-specific type inference; this function is the shared implementation.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const actions = defineDomainRecord(ActionSchema, [
|
|
17
|
+
* { id: 'my-action', order: 10, label: 'My Action', invocations: [] }
|
|
18
|
+
* ])
|
|
19
|
+
* // → { 'my-action': { id: 'my-action', order: 10, label: 'My Action', invocations: [], ... } }
|
|
20
|
+
*/
|
|
21
|
+
export function defineDomainRecord<TSchema extends z.ZodTypeAny>(
|
|
22
|
+
schema: TSchema,
|
|
23
|
+
entries: readonly z.input<TSchema>[]
|
|
24
|
+
): Record<string, z.infer<TSchema>> {
|
|
25
|
+
return Object.fromEntries(
|
|
26
|
+
entries.map((entry) => {
|
|
27
|
+
const parsed = schema.parse(entry) as z.infer<TSchema> & { id: string }
|
|
28
|
+
return [parsed.id, parsed]
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Phase 4: removed locally-scoped inferred types for deleted compound-domain schemas
|
|
34
|
+
// (SalesPipeline, ProspectingBuildTemplate, etc.). migration-helpers.ts imports them directly.
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* SystemEntry extended with the recursive tree slots (`systems`, `subsystems`).
|
|
38
|
+
* `OrganizationModelSystemEntry` is inferred from `SystemEntrySchema: ZodType<SystemEntry>`
|
|
39
|
+
* so it already carries these fields; this alias re-exports it under the tree-walker name
|
|
40
|
+
* for clarity at call sites.
|
|
41
|
+
*/
|
|
42
|
+
export type SystemEntryWithTree = OrganizationModelSystemEntry
|
|
43
|
+
|
|
44
|
+
function childSystemsOf(system: SystemEntryWithTree): Record<string, SystemEntryWithTree> {
|
|
45
|
+
return system.systems ?? system.subsystems ?? {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function defaultPathFor(id: string): string {
|
|
49
|
+
return `/${id.replaceAll('.', '/')}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function parentIdOf(id: string): string | undefined {
|
|
53
|
+
const index = id.lastIndexOf('.')
|
|
54
|
+
return index === -1 ? undefined : id.slice(0, index)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Return all entries of an OM domain map sorted by their declared `order` field.
|
|
59
|
+
* Use this whenever iteration order matters for UI or deterministic output.
|
|
60
|
+
*/
|
|
61
|
+
export function listDomain<T extends { id: string; order: number }>(record: Record<string, T>): T[] {
|
|
62
|
+
return Object.values(record).sort((a, b) => a.order - b.order)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function findById(
|
|
66
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
67
|
+
id: string
|
|
68
|
+
): OrganizationModelSystemEntry | undefined {
|
|
69
|
+
return systems[id]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function findByPath(
|
|
73
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
74
|
+
path: string
|
|
75
|
+
): OrganizationModelSystemEntry | undefined {
|
|
76
|
+
return Object.values(systems).find((system) => (system.path ?? system.ui?.path ?? defaultPathFor(system.id)) === path)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function childrenOf(
|
|
80
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
81
|
+
id: string
|
|
82
|
+
): OrganizationModelSystemEntry[] {
|
|
83
|
+
const prefix = `${id}.`
|
|
84
|
+
return Object.values(systems).filter(
|
|
85
|
+
(system) => system.id.startsWith(prefix) && !system.id.slice(prefix.length).includes('.')
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function topLevel(systems: Record<string, OrganizationModelSystemEntry>): OrganizationModelSystemEntry[] {
|
|
90
|
+
return Object.values(systems).filter((system) => !system.id.includes('.'))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function ancestorsOf(
|
|
94
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
95
|
+
id: string
|
|
96
|
+
): OrganizationModelSystemEntry[] {
|
|
97
|
+
const segments = id.split('.')
|
|
98
|
+
const ids = segments.map((_, index) => segments.slice(0, index + 1).join('.'))
|
|
99
|
+
return ids
|
|
100
|
+
.map((ancestorId) => findById(systems, ancestorId))
|
|
101
|
+
.filter((system): system is OrganizationModelSystemEntry => Boolean(system))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function parentOf(
|
|
105
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
106
|
+
id: string
|
|
107
|
+
): OrganizationModelSystemEntry | undefined {
|
|
108
|
+
const parentId = parentIdOf(id)
|
|
109
|
+
return parentId ? findById(systems, parentId) : undefined
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function inheritedValue<T>(
|
|
113
|
+
systems: Record<string, OrganizationModelSystemEntry>,
|
|
114
|
+
id: string,
|
|
115
|
+
getValue: (system: OrganizationModelSystemEntry) => T | undefined
|
|
116
|
+
): T | undefined {
|
|
117
|
+
return ancestorsOf(systems, id)
|
|
118
|
+
.slice()
|
|
119
|
+
.reverse()
|
|
120
|
+
.map(getValue)
|
|
121
|
+
.find((value): value is T => value !== undefined)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function uiPositionFor(systems: Record<string, OrganizationModelSystemEntry>, id: string) {
|
|
125
|
+
return inheritedValue(systems, id, (system) => system.uiPosition)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function requiresAdminFor(systems: Record<string, OrganizationModelSystemEntry>, id: string): boolean {
|
|
129
|
+
return inheritedValue(systems, id, (system) => system.requiresAdmin) ?? false
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function devOnlyFor(systems: Record<string, OrganizationModelSystemEntry>, id: string): boolean {
|
|
133
|
+
return inheritedValue(systems, id, (system) => system.devOnly || system.lifecycle === 'beta' || undefined) ?? false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// Recursive system-tree helpers (Wave 1B)
|
|
138
|
+
// These operate on the NEW recursive System shape introduced by W1A, where
|
|
139
|
+
// `model.systems` is `Record<LocalId, SystemEntry>` (nested via `subsystems`).
|
|
140
|
+
// `SystemEntry` here is the extended interface defined at the top of this file.
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Resolve a system by its dot-separated path string.
|
|
145
|
+
*
|
|
146
|
+
* `getSystem(model, 'sales.crm.dispositions')` walks:
|
|
147
|
+
* `model.systems['sales'] → .subsystems['crm'] → .subsystems['dispositions']`
|
|
148
|
+
*
|
|
149
|
+
* Returns `undefined` if any segment is missing.
|
|
150
|
+
*/
|
|
151
|
+
export function getSystem(model: OrganizationModel, path: string): SystemEntryWithTree | undefined {
|
|
152
|
+
const segments = path.split('.')
|
|
153
|
+
// model.systems is typed as Record<string, OrganizationModelSystemEntry>; cast
|
|
154
|
+
// to SystemEntryWithTree (which extends it with optional content + subsystems).
|
|
155
|
+
let current: Record<string, SystemEntryWithTree> = model.systems as Record<string, SystemEntryWithTree>
|
|
156
|
+
let node: SystemEntryWithTree | undefined
|
|
157
|
+
for (const seg of segments) {
|
|
158
|
+
node = current[seg]
|
|
159
|
+
if (node === undefined) return undefined
|
|
160
|
+
current = childSystemsOf(node)
|
|
161
|
+
}
|
|
162
|
+
return node
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Return the root-first ancestor chain for a system path, including the system
|
|
167
|
+
* itself as the last element.
|
|
168
|
+
*
|
|
169
|
+
* `getSystemAncestors(model, 'sales.crm')` → `[salesEntry, crmEntry]`
|
|
170
|
+
*
|
|
171
|
+
* Returns an empty array if the path cannot be resolved.
|
|
172
|
+
*/
|
|
173
|
+
export function getSystemAncestors(model: OrganizationModel, path: string): SystemEntryWithTree[] {
|
|
174
|
+
const segments = path.split('.')
|
|
175
|
+
const result: SystemEntryWithTree[] = []
|
|
176
|
+
let current: Record<string, SystemEntryWithTree> = model.systems as Record<string, SystemEntryWithTree>
|
|
177
|
+
for (const seg of segments) {
|
|
178
|
+
const node = current[seg]
|
|
179
|
+
if (node === undefined) return []
|
|
180
|
+
result.push(node)
|
|
181
|
+
current = childSystemsOf(node)
|
|
182
|
+
}
|
|
183
|
+
return result
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Flat depth-first enumeration of every system in the model tree.
|
|
188
|
+
* Each entry carries the computed full path and the system node.
|
|
189
|
+
* Order: parent before children (pre-order DFS).
|
|
190
|
+
*
|
|
191
|
+
* Example result paths: `'sales'`, `'sales.crm'`, `'sales.crm.dispositions'`
|
|
192
|
+
*/
|
|
193
|
+
export function listAllSystems(model: OrganizationModel): Array<{ path: string; system: SystemEntryWithTree }> {
|
|
194
|
+
const results: Array<{ path: string; system: SystemEntryWithTree }> = []
|
|
195
|
+
|
|
196
|
+
function walk(map: Record<string, SystemEntryWithTree>, prefix: string): void {
|
|
197
|
+
for (const [localId, system] of Object.entries(map)) {
|
|
198
|
+
const fullPath = prefix ? `${prefix}.${localId}` : localId
|
|
199
|
+
results.push({ path: fullPath, system })
|
|
200
|
+
const childSystems = childSystemsOf(system)
|
|
201
|
+
if (Object.keys(childSystems).length > 0) {
|
|
202
|
+
walk(childSystems, fullPath)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
walk(model.systems as Record<string, SystemEntryWithTree>, '')
|
|
208
|
+
return results
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function isPlainJsonObject(value: JsonValue | undefined): value is Record<string, JsonValue> {
|
|
212
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function mergeJsonConfig(
|
|
216
|
+
base: Record<string, JsonValue>,
|
|
217
|
+
override: Record<string, JsonValue>
|
|
218
|
+
): Record<string, JsonValue> {
|
|
219
|
+
const result: Record<string, JsonValue> = { ...base }
|
|
220
|
+
|
|
221
|
+
for (const [key, value] of Object.entries(override)) {
|
|
222
|
+
const existing = result[key]
|
|
223
|
+
result[key] = isPlainJsonObject(existing) && isPlainJsonObject(value) ? mergeJsonConfig(existing, value) : value
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return result
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Resolve a system's effective local config from first-class `System.config`. */
|
|
230
|
+
export function resolveSystemConfig(model: OrganizationModel, path: string): Record<string, JsonValue> {
|
|
231
|
+
const system = getSystem(model, path)
|
|
232
|
+
if (system === undefined) return {}
|
|
233
|
+
|
|
234
|
+
return mergeJsonConfig({}, system.config ?? {})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Return all resources whose `systemPath` belongs to the given system.
|
|
239
|
+
*
|
|
240
|
+
* When `includeDescendants` is false (default), only resources whose
|
|
241
|
+
* `systemPath` exactly matches `systemPath` are returned.
|
|
242
|
+
*
|
|
243
|
+
* When `includeDescendants` is true, resources attached to any descendant
|
|
244
|
+
* system are also included. Descendant matching is segment-aware: the path
|
|
245
|
+
* `'sales'` does NOT match `'salesforce.foo'` because segment boundaries are
|
|
246
|
+
* enforced by splitting on `'.'`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* getResourcesForSystem(model, 'sales')
|
|
250
|
+
* // → resources where systemPath === 'sales'
|
|
251
|
+
*
|
|
252
|
+
* getResourcesForSystem(model, 'sales', { includeDescendants: true })
|
|
253
|
+
* // → resources where systemPath === 'sales' OR systemPath starts with 'sales.'
|
|
254
|
+
*/
|
|
255
|
+
export function getResourcesForSystem(
|
|
256
|
+
model: OrganizationModel,
|
|
257
|
+
systemPath: string,
|
|
258
|
+
options: { includeDescendants?: boolean } = {}
|
|
259
|
+
): ResourceEntry[] {
|
|
260
|
+
const { includeDescendants = false } = options
|
|
261
|
+
const prefix = systemPath + '.'
|
|
262
|
+
return Object.values(model.resources ?? {}).filter(
|
|
263
|
+
(r) => r.systemPath === systemPath || (includeDescendants && r.systemPath.startsWith(prefix))
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface SystemTopologyEdge {
|
|
268
|
+
id: string
|
|
269
|
+
relationship: OmTopologyRelationship
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface SystemDeprecationDependents {
|
|
273
|
+
resources: ResourceEntry[]
|
|
274
|
+
topologyEdges: SystemTopologyEdge[]
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function systemPathIsInScope(candidate: string, systemPath: string, includeDescendants: boolean): boolean {
|
|
278
|
+
return candidate === systemPath || (includeDescendants && candidate.startsWith(`${systemPath}.`))
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function topologyRelationshipTouchesSystem(
|
|
282
|
+
relationship: OmTopologyRelationship,
|
|
283
|
+
systemPath: string,
|
|
284
|
+
resourceIds: Set<string>,
|
|
285
|
+
includeDescendants: boolean
|
|
286
|
+
): boolean {
|
|
287
|
+
if (
|
|
288
|
+
relationship.systemPath !== undefined &&
|
|
289
|
+
systemPathIsInScope(relationship.systemPath, systemPath, includeDescendants)
|
|
290
|
+
) {
|
|
291
|
+
return true
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
for (const ref of [relationship.from, relationship.to]) {
|
|
295
|
+
if (ref.kind === 'system' && systemPathIsInScope(ref.id, systemPath, includeDescendants)) return true
|
|
296
|
+
if (ref.kind === 'resource' && resourceIds.has(ref.id)) return true
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return false
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function getTopologyEdgesForSystem(
|
|
303
|
+
model: OrganizationModel,
|
|
304
|
+
systemPath: string,
|
|
305
|
+
options: { includeDescendants?: boolean; resourceIds?: Iterable<string> } = {}
|
|
306
|
+
): SystemTopologyEdge[] {
|
|
307
|
+
const { includeDescendants = false } = options
|
|
308
|
+
const resourceIds = new Set(
|
|
309
|
+
options.resourceIds ?? getResourcesForSystem(model, systemPath, { includeDescendants }).map((r) => r.id)
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
return Object.entries(model.topology?.relationships ?? {})
|
|
313
|
+
.filter(([, relationship]) =>
|
|
314
|
+
topologyRelationshipTouchesSystem(relationship, systemPath, resourceIds, includeDescendants)
|
|
315
|
+
)
|
|
316
|
+
.map(([id, relationship]) => ({ id, relationship }))
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function getSystemDeprecationDependents(
|
|
320
|
+
model: OrganizationModel,
|
|
321
|
+
systemPath: string,
|
|
322
|
+
options: { includeDescendants?: boolean } = {}
|
|
323
|
+
): SystemDeprecationDependents {
|
|
324
|
+
const resources = getResourcesForSystem(model, systemPath, options).filter((resource) => resource.status === 'active')
|
|
325
|
+
const resourceIds = new Set(resources.map((resource) => resource.id))
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
resources,
|
|
329
|
+
topologyEdges: getTopologyEdgesForSystem(model, systemPath, { ...options, resourceIds })
|
|
330
|
+
}
|
|
331
|
+
}
|