@lorion-org/composition-graph 1.0.0-beta.1 → 1.0.0-beta.5
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/README.md +45 -4
- package/dist/index.cjs +71 -12
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +69 -11
- package/package.json +9 -4
- package/src/compositionSelection.ts +109 -0
- package/src/descriptorCatalog.ts +163 -0
- package/src/descriptorGraph.ts +327 -0
- package/src/descriptorMap.ts +127 -0
- package/src/index.ts +38 -0
- package/src/types.ts +133 -0
- package/examples/deployment-composition.js +0 -49
- package/examples/deployment-composition.ts +0 -59
package/src/types.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export type DescriptorId = string;
|
|
2
|
+
|
|
3
|
+
export type DescriptorIds = DescriptorId[];
|
|
4
|
+
|
|
5
|
+
export type VersionConstraintMap = Record<DescriptorId, string>;
|
|
6
|
+
|
|
7
|
+
export type RelationId = string;
|
|
8
|
+
|
|
9
|
+
export type Descriptor = {
|
|
10
|
+
id: DescriptorId;
|
|
11
|
+
version: string;
|
|
12
|
+
providesFor?: DescriptorId | DescriptorId[];
|
|
13
|
+
defaultFor?: DescriptorId | DescriptorId[];
|
|
14
|
+
capabilities?: string[];
|
|
15
|
+
dependencies?: VersionConstraintMap;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
location?: string;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type DescriptorMap = Map<DescriptorId, Descriptor>;
|
|
22
|
+
|
|
23
|
+
export type RelationDescriptor = {
|
|
24
|
+
direction?: 'outgoing' | 'incoming';
|
|
25
|
+
id: RelationId;
|
|
26
|
+
field?: string;
|
|
27
|
+
targetMode?: 'keys' | 'values';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type DescriptorEdge = {
|
|
31
|
+
from: DescriptorId;
|
|
32
|
+
to: DescriptorId;
|
|
33
|
+
relation: RelationId;
|
|
34
|
+
source: 'descriptor' | 'derived';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ResolutionStep = {
|
|
38
|
+
from: DescriptorId;
|
|
39
|
+
to: DescriptorId;
|
|
40
|
+
relation: RelationId;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type CompositionOriginType = 'selected' | 'base' | 'resolved';
|
|
44
|
+
|
|
45
|
+
export type CompositionProvenanceOrigin = {
|
|
46
|
+
originType: CompositionOriginType;
|
|
47
|
+
path: ResolutionStep[];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type CompositionProvenance = {
|
|
51
|
+
descriptorId: DescriptorId;
|
|
52
|
+
origins: CompositionProvenanceOrigin[];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type DescriptorGraph = {
|
|
56
|
+
descriptorMap: DescriptorMap;
|
|
57
|
+
edges: DescriptorEdge[];
|
|
58
|
+
outgoing: Map<DescriptorId, DescriptorEdge[]>;
|
|
59
|
+
incoming: Map<DescriptorId, DescriptorEdge[]>;
|
|
60
|
+
relationDescriptors: Map<RelationId, RelationDescriptor>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type DescriptorProfile = {
|
|
64
|
+
id: DescriptorId;
|
|
65
|
+
location?: string;
|
|
66
|
+
disabled: boolean;
|
|
67
|
+
providesFor?: DescriptorId | DescriptorId[];
|
|
68
|
+
capabilities: string[];
|
|
69
|
+
outgoing: Record<RelationId, string[]>;
|
|
70
|
+
incoming: Record<RelationId, string[]>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type CompositionPolicy = {
|
|
74
|
+
resolutionRelationIds: RelationId[];
|
|
75
|
+
provenanceRelationIds: RelationId[];
|
|
76
|
+
inspectionRelationIds: RelationId[];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type DescriptorCatalog = {
|
|
80
|
+
getDescriptorMap: () => DescriptorMap;
|
|
81
|
+
getAllDescriptors: () => Descriptor[];
|
|
82
|
+
getDescriptor: (id: DescriptorId) => Descriptor | undefined;
|
|
83
|
+
getGraph: () => DescriptorGraph;
|
|
84
|
+
getRelationDescriptors: () => RelationDescriptor[];
|
|
85
|
+
getProfiles: (input?: { ids?: DescriptorId[]; includeDisabled?: boolean }) => DescriptorProfile[];
|
|
86
|
+
getIncomingRelationMap: (relationId: RelationId) => Map<DescriptorId, DescriptorId[]>;
|
|
87
|
+
getTransitiveTargets: (input: {
|
|
88
|
+
start: DescriptorId[];
|
|
89
|
+
relationIds: RelationId[];
|
|
90
|
+
}) => DescriptorIds;
|
|
91
|
+
getDependents: (input: {
|
|
92
|
+
target: DescriptorId;
|
|
93
|
+
relationIds: RelationId[];
|
|
94
|
+
transitive?: boolean;
|
|
95
|
+
}) => DescriptorIds;
|
|
96
|
+
explain: (input: {
|
|
97
|
+
from: DescriptorId;
|
|
98
|
+
to: DescriptorId;
|
|
99
|
+
relationIds: RelationId[];
|
|
100
|
+
}) => ResolutionStep[];
|
|
101
|
+
explainPathsBatch: (input: {
|
|
102
|
+
pairs: Array<{ from: DescriptorId; to: DescriptorId }>;
|
|
103
|
+
relationIds: RelationId[];
|
|
104
|
+
}) => Array<{ from: DescriptorId; to: DescriptorId; path: ResolutionStep[] }>;
|
|
105
|
+
resolveSelection: (input: {
|
|
106
|
+
selected?: DescriptorId[];
|
|
107
|
+
baseDescriptors?: DescriptorId[];
|
|
108
|
+
policy?: Partial<CompositionPolicy>;
|
|
109
|
+
}) => CompositionSelection;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type CompositionSelection = {
|
|
113
|
+
getCatalog: () => DescriptorCatalog;
|
|
114
|
+
getGraph: () => DescriptorGraph;
|
|
115
|
+
getSelected: () => DescriptorIds;
|
|
116
|
+
getBaseDescriptors: () => DescriptorIds;
|
|
117
|
+
getResolved: () => DescriptorIds;
|
|
118
|
+
getResolvedDescriptors: () => Descriptor[];
|
|
119
|
+
getProvenance: () => CompositionProvenance[];
|
|
120
|
+
getDependentsFor: (
|
|
121
|
+
target: DescriptorId,
|
|
122
|
+
input?: { transitive?: boolean; relationIds?: RelationId[] },
|
|
123
|
+
) => DescriptorIds;
|
|
124
|
+
explain: (input: {
|
|
125
|
+
from: DescriptorId;
|
|
126
|
+
to: DescriptorId;
|
|
127
|
+
relationIds?: RelationId[];
|
|
128
|
+
}) => ResolutionStep[];
|
|
129
|
+
explainPathsBatch: (input: {
|
|
130
|
+
pairs: Array<{ from: DescriptorId; to: DescriptorId }>;
|
|
131
|
+
relationIds?: RelationId[];
|
|
132
|
+
}) => Array<{ from: DescriptorId; to: DescriptorId; path: ResolutionStep[] }>;
|
|
133
|
+
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
import { createDescriptorCatalog } from '../dist/index.js';
|
|
3
|
-
|
|
4
|
-
const catalog = createDescriptorCatalog({
|
|
5
|
-
descriptors: [
|
|
6
|
-
{
|
|
7
|
-
id: 'web',
|
|
8
|
-
version: '1.0.0',
|
|
9
|
-
dependencies: {
|
|
10
|
-
checkout: '^1.0.0',
|
|
11
|
-
payments: '^1.0.0',
|
|
12
|
-
'payment-provider-invoice': '^1.0.0',
|
|
13
|
-
'payment-provider-stripe': '^1.0.0',
|
|
14
|
-
shops: '^1.0.0',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: 'checkout',
|
|
19
|
-
version: '1.0.0',
|
|
20
|
-
dependencies: { payments: '^1.0.0' },
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: 'payments',
|
|
24
|
-
version: '1.0.0',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 'shops',
|
|
28
|
-
version: '1.0.0',
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: 'payment-provider-invoice',
|
|
32
|
-
version: '1.0.0',
|
|
33
|
-
providesFor: 'payment-checkout',
|
|
34
|
-
dependencies: { payments: '^1.0.0' },
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: 'payment-provider-stripe',
|
|
38
|
-
version: '1.0.0',
|
|
39
|
-
providesFor: 'payment-checkout',
|
|
40
|
-
dependencies: { payments: '^1.0.0' },
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const selection = catalog.resolveSelection({
|
|
46
|
-
selected: ['web'],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
process.stdout.write(`${selection.getResolved().join(', ')}\n`);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createDescriptorCatalog } from '@lorion-org/composition-graph';
|
|
2
|
-
|
|
3
|
-
const catalog = createDescriptorCatalog({
|
|
4
|
-
descriptors: [
|
|
5
|
-
{
|
|
6
|
-
id: 'web',
|
|
7
|
-
version: '1.0.0',
|
|
8
|
-
dependencies: {
|
|
9
|
-
checkout: '^1.0.0',
|
|
10
|
-
payments: '^1.0.0',
|
|
11
|
-
'payment-provider-invoice': '^1.0.0',
|
|
12
|
-
'payment-provider-stripe': '^1.0.0',
|
|
13
|
-
shops: '^1.0.0',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: 'checkout',
|
|
18
|
-
version: '1.0.0',
|
|
19
|
-
dependencies: { payments: '^1.0.0' },
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
id: 'payments',
|
|
23
|
-
version: '1.0.0',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
id: 'shops',
|
|
27
|
-
version: '1.0.0',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
id: 'payment-provider-invoice',
|
|
31
|
-
version: '1.0.0',
|
|
32
|
-
providesFor: 'payment-checkout',
|
|
33
|
-
dependencies: { payments: '^1.0.0' },
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
id: 'payment-provider-stripe',
|
|
37
|
-
version: '1.0.0',
|
|
38
|
-
providesFor: 'payment-checkout',
|
|
39
|
-
dependencies: { payments: '^1.0.0' },
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const selection = catalog.resolveSelection({
|
|
45
|
-
selected: ['web'],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
console.log(selection.getResolved());
|
|
49
|
-
// ['checkout', 'payment-provider-invoice', 'payment-provider-stripe', 'payments', 'shops', 'web']
|
|
50
|
-
|
|
51
|
-
console.log(selection.getProvenance());
|
|
52
|
-
// [
|
|
53
|
-
// { descriptorId: 'checkout', origins: ['resolved'] },
|
|
54
|
-
// { descriptorId: 'payment-provider-invoice', origins: ['resolved'] },
|
|
55
|
-
// { descriptorId: 'payment-provider-stripe', origins: ['resolved'] },
|
|
56
|
-
// { descriptorId: 'payments', origins: ['resolved'] },
|
|
57
|
-
// { descriptorId: 'shops', origins: ['resolved'] },
|
|
58
|
-
// { descriptorId: 'web', origins: ['selected'] }
|
|
59
|
-
// ]
|