@milaboratories/pl-middle-layer 1.23.18 → 1.24.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct_template_loader.d.ts","sourceRoot":"","sources":["../../../src/mutator/template/direct_template_loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"direct_template_loader.d.ts","sourceRoot":"","sources":["../../../src/mutator/template/direct_template_loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAgBlE,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAUhG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-middle-layer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "Pl Middle Layer",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
"yaml": "^2.6.1",
|
|
30
30
|
"zod": "~3.23.8",
|
|
31
31
|
"@milaboratories/pl-http": "^1.0.2",
|
|
32
|
-
"@milaboratories/resolve-helper": "^1.0.2",
|
|
33
32
|
"@milaboratories/computable": "^2.3.4",
|
|
34
|
-
"@platforma-sdk/block-tools": "^2.5.
|
|
35
|
-
"@milaboratories/
|
|
36
|
-
"@milaboratories/pl-drivers": "^1.5.
|
|
37
|
-
"@milaboratories/pl-model-common": "^1.10.
|
|
38
|
-
"@milaboratories/pl-
|
|
39
|
-
"@milaboratories/pl-tree": "^1.4.20",
|
|
40
|
-
"@platforma-sdk/model": "^1.21.10",
|
|
33
|
+
"@platforma-sdk/block-tools": "^2.5.3",
|
|
34
|
+
"@milaboratories/resolve-helper": "^1.0.2",
|
|
35
|
+
"@milaboratories/pl-drivers": "^1.5.9",
|
|
36
|
+
"@milaboratories/pl-model-common": "^1.10.3",
|
|
37
|
+
"@milaboratories/pl-client": "^2.7.2",
|
|
41
38
|
"@milaboratories/pl-model-backend": "^1.0.1",
|
|
42
|
-
"@milaboratories/
|
|
39
|
+
"@milaboratories/pl-tree": "^1.4.21",
|
|
40
|
+
"@platforma-sdk/model": "^1.21.20",
|
|
41
|
+
"@milaboratories/pl-model-middle-layer": "^1.6.11",
|
|
43
42
|
"@platforma-sdk/workflow-tengo": "2.9.6",
|
|
44
|
-
"@milaboratories/
|
|
45
|
-
"@milaboratories/pl-config": "^1.3.3"
|
|
43
|
+
"@milaboratories/ts-helpers": "^1.1.3",
|
|
44
|
+
"@milaboratories/pl-config": "^1.3.3",
|
|
45
|
+
"@milaboratories/pl-local": "^1.10.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"semver": "^7.6.3",
|
|
@@ -3,8 +3,18 @@ import { assertNever } from '@milaboratories/ts-helpers';
|
|
|
3
3
|
import type { ExplicitTemplate } from '../../model/template_spec';
|
|
4
4
|
import type { Hash } from 'node:crypto';
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
|
-
import type {
|
|
7
|
-
|
|
6
|
+
import type {
|
|
7
|
+
TemplateData,
|
|
8
|
+
TemplateLibData,
|
|
9
|
+
TemplateSoftwareData
|
|
10
|
+
} from '@milaboratories/pl-model-backend';
|
|
11
|
+
import {
|
|
12
|
+
PlTemplateLibV1,
|
|
13
|
+
PlTemplateSoftwareV1,
|
|
14
|
+
PlTemplateV1,
|
|
15
|
+
PlTemplateOverrideV1,
|
|
16
|
+
parseTemplate
|
|
17
|
+
} from '@milaboratories/pl-model-backend';
|
|
8
18
|
|
|
9
19
|
export function loadTemplateFromExplicitDirect(tx: PlTransaction, spec: ExplicitTemplate): AnyRef {
|
|
10
20
|
const templateInfo: TemplateData = parseTemplate(spec.content);
|
|
@@ -20,10 +30,10 @@ export function loadTemplateFromExplicitDirect(tx: PlTransaction, spec: Explicit
|
|
|
20
30
|
|
|
21
31
|
type Renderer<T> = {
|
|
22
32
|
hash: Hasher<T>;
|
|
23
|
-
render: (resource: T, tx: PlTransaction, creator: Creator
|
|
33
|
+
render: (resource: T, tx: PlTransaction, creator: Creator) => AnyResourceRef;
|
|
24
34
|
};
|
|
25
35
|
type Hasher<T> = (resource: T, hash: Hash) => void;
|
|
26
|
-
type Creator<T>
|
|
36
|
+
type Creator = <T>(resource: T, renderer: Renderer<T>) => AnyResourceRef;
|
|
27
37
|
|
|
28
38
|
const LibRenderer: Renderer<TemplateLibData> = {
|
|
29
39
|
hash(resource, hash) {
|
|
@@ -37,9 +47,9 @@ const LibRenderer: Renderer<TemplateLibData> = {
|
|
|
37
47
|
render(resource, tx, _creator) {
|
|
38
48
|
return tx.createValue(
|
|
39
49
|
PlTemplateLibV1.type,
|
|
40
|
-
JSON.stringify(PlTemplateLibV1.fromV2Data(resource).data)
|
|
50
|
+
JSON.stringify(PlTemplateLibV1.fromV2Data(resource).data)
|
|
41
51
|
);
|
|
42
|
-
}
|
|
52
|
+
}
|
|
43
53
|
};
|
|
44
54
|
|
|
45
55
|
const SoftwareInfoRenderer: Renderer<TemplateSoftwareData> = {
|
|
@@ -57,7 +67,22 @@ const SoftwareInfoRenderer: Renderer<TemplateSoftwareData> = {
|
|
|
57
67
|
tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));
|
|
58
68
|
tx.lock(ref);
|
|
59
69
|
return ref;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const HashOverrideRenderer: Renderer<TemplateData> = {
|
|
74
|
+
hash(resource, hash) {
|
|
75
|
+
hash
|
|
76
|
+
.update(PlTemplateOverrideV1.type.name)
|
|
77
|
+
.update(PlTemplateOverrideV1.type.version)
|
|
78
|
+
.update(resource.hashOverride ?? '');
|
|
60
79
|
},
|
|
80
|
+
render(resource, tx, _creator) {
|
|
81
|
+
return tx.createStruct(
|
|
82
|
+
PlTemplateOverrideV1.type,
|
|
83
|
+
JSON.stringify(PlTemplateOverrideV1.fromV2Data(resource))
|
|
84
|
+
);
|
|
85
|
+
}
|
|
61
86
|
};
|
|
62
87
|
|
|
63
88
|
const TemplateRenderer: Renderer<TemplateData> = {
|
|
@@ -70,8 +95,8 @@ const TemplateRenderer: Renderer<TemplateData> = {
|
|
|
70
95
|
.update(resource.version)
|
|
71
96
|
.update(resource.src);
|
|
72
97
|
|
|
73
|
-
const srt = <T>(entries: [string, T][])
|
|
74
|
-
entries.sort((a, b) => a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1);
|
|
98
|
+
const srt = <T>(entries: [string, T][]): [string, T][] => {
|
|
99
|
+
entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));
|
|
75
100
|
return entries;
|
|
76
101
|
};
|
|
77
102
|
|
|
@@ -93,32 +118,52 @@ const TemplateRenderer: Renderer<TemplateData> = {
|
|
|
93
118
|
}
|
|
94
119
|
},
|
|
95
120
|
render(resource, tx, _creator) {
|
|
96
|
-
|
|
121
|
+
const tplRef = tx.createStruct(
|
|
97
122
|
PlTemplateV1.type,
|
|
98
|
-
JSON.stringify(PlTemplateV1.fromV2Data(resource).data)
|
|
123
|
+
JSON.stringify(PlTemplateV1.fromV2Data(resource).data)
|
|
99
124
|
);
|
|
100
|
-
|
|
101
|
-
}
|
|
125
|
+
// Render libraries
|
|
126
|
+
for (const [libId, lib] of Object.entries(resource.libs ?? {})) {
|
|
127
|
+
const fld = PlTemplateV1.libField(tplRef, libId);
|
|
128
|
+
tx.createField(fld, 'Input');
|
|
129
|
+
tx.setField(fld, _creator(lib, LibRenderer));
|
|
130
|
+
}
|
|
102
131
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
.
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
132
|
+
// Render software and assets
|
|
133
|
+
for (const [swId, sw] of Object.entries(resource.software ?? {})) {
|
|
134
|
+
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
135
|
+
tx.createField(fld, 'Input');
|
|
136
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer));
|
|
137
|
+
}
|
|
138
|
+
for (const [swId, sw] of Object.entries(resource.assets ?? {})) {
|
|
139
|
+
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
140
|
+
tx.createField(fld, 'Input');
|
|
141
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Render dependency templates
|
|
145
|
+
for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {
|
|
146
|
+
const fld = PlTemplateV1.tplField(tplRef, depTplId);
|
|
147
|
+
tx.createField(fld, 'Input');
|
|
148
|
+
tx.setField(fld, _creator(depTpl, TemplateRenderer));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
tx.lock(tplRef);
|
|
152
|
+
|
|
153
|
+
if (!resource.hashOverride) return tplRef;
|
|
117
154
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
155
|
+
// Override template hash with proxy resource, when hash override is configured for template
|
|
156
|
+
const overrideRef = _creator(resource, HashOverrideRenderer);
|
|
157
|
+
const fld = PlTemplateOverrideV1.tplField(overrideRef);
|
|
158
|
+
tx.createField(fld, 'Service');
|
|
159
|
+
tx.setField(fld, tplRef);
|
|
160
|
+
tx.lock(tplRef);
|
|
161
|
+
return overrideRef;
|
|
121
162
|
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
function createTemplateV2Tree(tx: PlTransaction, tplInfo: TemplateData): AnyRef {
|
|
166
|
+
const resourceCache = new Map<string, AnyResourceRef>();
|
|
122
167
|
|
|
123
168
|
const createResource = <T>(resource: T, renderer: Renderer<T>): AnyResourceRef => {
|
|
124
169
|
const hasher: Hash = createHash('sha256');
|
|
@@ -133,45 +178,5 @@ function createTemplateV2Tree(tx: PlTransaction, tplInfo: TemplateData, resource
|
|
|
133
178
|
return resourceCache.get(rKey)!;
|
|
134
179
|
};
|
|
135
180
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// Render libraries
|
|
139
|
-
for (const [libId, lib] of Object.entries(tplInfo.libs ?? {})) {
|
|
140
|
-
const fld = PlTemplateV1.libField(tplRef, libId);
|
|
141
|
-
tx.createField(fld, 'Input');
|
|
142
|
-
tx.setField(fld, createResource(lib, LibRenderer));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Render software and assets
|
|
146
|
-
for (const [swId, sw] of Object.entries(tplInfo.software ?? {})) {
|
|
147
|
-
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
148
|
-
tx.createField(fld, 'Input');
|
|
149
|
-
tx.setField(fld, createResource(sw, SoftwareInfoRenderer));
|
|
150
|
-
}
|
|
151
|
-
for (const [swId, sw] of Object.entries(tplInfo.assets ?? {})) {
|
|
152
|
-
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
153
|
-
tx.createField(fld, 'Input');
|
|
154
|
-
tx.setField(fld, createResource(sw, SoftwareInfoRenderer));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Render dependency templates
|
|
158
|
-
for (const [depTplId, depTpl] of Object.entries(tplInfo.templates ?? {})) {
|
|
159
|
-
const fld = PlTemplateV1.tplField(tplRef, depTplId);
|
|
160
|
-
tx.createField(fld, 'Input');
|
|
161
|
-
tx.setField(fld, createTemplateV2Tree(tx, depTpl, resourceCache));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
tx.lock(tplRef);
|
|
165
|
-
|
|
166
|
-
if (!tplInfo.hashOverride) {
|
|
167
|
-
return tplRef;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Override template hash with proxy resource, when hash override is configured for template
|
|
171
|
-
const overrideRef = createResource(tplInfo, HashOverrideRenderer);
|
|
172
|
-
const fld = PlTemplateOverrideV1.tplField(overrideRef);
|
|
173
|
-
tx.createField(fld, 'Service');
|
|
174
|
-
tx.setField(fld, tplRef);
|
|
175
|
-
tx.lock(tplRef);
|
|
176
|
-
return overrideRef;
|
|
181
|
+
return createResource(tplInfo, TemplateRenderer);
|
|
177
182
|
}
|