@highstate/pulumi 0.9.18 → 0.9.20
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/highstate.manifest.json +1 -1
- package/dist/index.js +181 -332
- package/dist/index.js.map +1 -1
- package/package.json +13 -7
- package/src/file.ts +68 -0
- package/src/index.ts +1 -1
- package/src/unit.ts +263 -469
- package/src/utils.ts +56 -141
- package/src/secret.ts +0 -61
package/dist/index.js
CHANGED
@@ -1,75 +1,115 @@
|
|
1
|
-
import {
|
1
|
+
import { output, secret, Config, StackReference } from '@pulumi/pulumi';
|
2
2
|
export * from '@pulumi/pulumi';
|
3
|
-
import {
|
4
|
-
import { mapValues
|
5
|
-
import { Ajv } from 'ajv';
|
3
|
+
import { HighstateConfigKey, unitConfigSchema, z, parseArgumentValue, runtimeSchema, parseInstanceId, camelCaseToHumanReadable, unitArtifactSchema } from '@highstate/contract';
|
4
|
+
import { mapValues } from 'remeda';
|
6
5
|
|
7
6
|
// src/index.ts
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
};
|
7
|
+
function fileFromString(name, content, { contentType = "text/plain", isSecret = false, mode } = {}) {
|
8
|
+
return output({
|
9
|
+
meta: {
|
10
|
+
name,
|
11
|
+
contentType,
|
12
|
+
size: output(content).apply((content2) => Buffer.byteLength(content2, "utf8")),
|
13
|
+
mode
|
14
|
+
},
|
15
|
+
content: {
|
16
|
+
type: "embedded",
|
17
|
+
value: isSecret ? secret(content) : content
|
18
|
+
}
|
19
|
+
});
|
21
20
|
}
|
22
|
-
function
|
23
|
-
|
24
|
-
return {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
function fileFromBuffer(name, content, { contentType = "application/octet-stream", isSecret = false, mode } = {}) {
|
22
|
+
const base64Content = content.toString("base64");
|
23
|
+
return output({
|
24
|
+
meta: {
|
25
|
+
name,
|
26
|
+
contentType,
|
27
|
+
size: output(content).apply((content2) => content2.byteLength),
|
28
|
+
mode
|
29
|
+
},
|
30
|
+
content: {
|
31
|
+
type: "embedded",
|
32
|
+
isBinary: true,
|
33
|
+
value: isSecret ? secret(base64Content) : base64Content
|
34
|
+
}
|
35
|
+
});
|
36
|
+
}
|
37
|
+
function toPromise(input) {
|
38
|
+
return new Promise((resolve) => output(input).apply(resolve));
|
39
|
+
}
|
40
|
+
function normalize(item, collection) {
|
41
|
+
if (item && collection) {
|
42
|
+
return [item, ...collection];
|
43
|
+
}
|
44
|
+
if (item) {
|
45
|
+
return [item];
|
46
|
+
}
|
47
|
+
return collection ?? [];
|
48
|
+
}
|
49
|
+
function normalizeInputs(item, collection) {
|
50
|
+
return output({ item, collection }).apply(({ item: item2, collection: collection2 }) => normalize(item2, collection2));
|
51
|
+
}
|
52
|
+
function normalizeInputsAndMap(item, collection, mapFn) {
|
53
|
+
return normalizeInputs(item, collection).apply((values) => values.map(mapFn));
|
54
|
+
}
|
55
|
+
function apply(fn) {
|
56
|
+
return (input) => output(input).apply(fn);
|
29
57
|
}
|
30
58
|
|
31
59
|
// src/unit.ts
|
32
|
-
var ajv = new Ajv({ strict: false });
|
33
60
|
var stackRefMap = /* @__PURE__ */ new Map();
|
34
|
-
var [projectId, instanceName] = getStack().split("_");
|
35
61
|
var instanceId;
|
62
|
+
var instanceName;
|
36
63
|
function getUnitInstanceId() {
|
37
64
|
if (!instanceId) {
|
38
|
-
throw new Error(
|
65
|
+
throw new Error(`Instance id is not set. Did you call "forUnit" function?`);
|
39
66
|
}
|
40
67
|
return instanceId;
|
41
68
|
}
|
42
|
-
function getResourceComment() {
|
43
|
-
return `Managed by Highstate Unit (${getUnitInstanceId()})`;
|
44
|
-
}
|
45
69
|
function getUnitInstanceName() {
|
70
|
+
if (!instanceName) {
|
71
|
+
throw new Error(`Instance name is not set. Did you call "forUnit" function?`);
|
72
|
+
}
|
46
73
|
return instanceName;
|
47
74
|
}
|
48
|
-
function
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
75
|
+
function getResourceComment() {
|
76
|
+
return `Managed by Highstate (${getUnitInstanceId()})`;
|
77
|
+
}
|
78
|
+
function getStackRef(config, input) {
|
79
|
+
const [instanceType] = parseInstanceId(input.instanceId);
|
80
|
+
const stateId = config.stateIdMap[input.instanceId];
|
81
|
+
if (!stateId) {
|
82
|
+
throw new Error(`State ID for instance "${input.instanceId}" not found in the unit config.`);
|
83
|
+
}
|
84
|
+
const key = `organization/${instanceType}/${stateId}`;
|
85
|
+
let stackRef = stackRefMap.get(key);
|
86
|
+
if (!stackRef) {
|
87
|
+
stackRef = new StackReference(key);
|
88
|
+
stackRefMap.set(key, stackRef);
|
53
89
|
}
|
54
|
-
return
|
90
|
+
return stackRef;
|
55
91
|
}
|
56
|
-
function getOutput(unit, input, refs) {
|
92
|
+
function getOutput(config, unit, input, refs) {
|
57
93
|
const entity = unit.entities.get(input.type);
|
58
94
|
if (!entity) {
|
59
|
-
throw new Error(`Entity
|
95
|
+
throw new Error(`Entity "${input.type}" not found in the unit "${unit.model.type}".`);
|
60
96
|
}
|
61
97
|
const _getOutput = (ref) => {
|
62
|
-
const value = getStackRef(ref).requireOutput(ref.output);
|
98
|
+
const value = getStackRef(config, ref).requireOutput(ref.output);
|
63
99
|
return value.apply((value2) => {
|
64
100
|
if (Array.isArray(value2)) {
|
65
101
|
for (const [index, item] of value2.entries()) {
|
66
|
-
|
67
|
-
|
102
|
+
const result = entity.schema.safeParse(item);
|
103
|
+
if (!result.success) {
|
104
|
+
throw new Error(
|
105
|
+
`Invalid output for "${input.type}[${index}]": ${z.prettifyError(result.error)}`
|
106
|
+
);
|
68
107
|
}
|
69
108
|
}
|
70
109
|
} else {
|
71
|
-
|
72
|
-
|
110
|
+
const result = entity.schema.safeParse(value2);
|
111
|
+
if (!result.success) {
|
112
|
+
throw new Error(`Invalid output for "${input.type}": ${z.prettifyError(result.error)}`);
|
73
113
|
}
|
74
114
|
}
|
75
115
|
if (Array.isArray(value2)) {
|
@@ -84,137 +124,65 @@ function getOutput(unit, input, refs) {
|
|
84
124
|
}
|
85
125
|
return values;
|
86
126
|
}
|
87
|
-
function isAnyOfSchema(schema, itemType) {
|
88
|
-
if (schema.anyOf) {
|
89
|
-
return Object.values(schema.anyOf).every((schema2) => isAnyOfSchema(schema2, itemType));
|
90
|
-
}
|
91
|
-
return schema.type === itemType;
|
92
|
-
}
|
93
|
-
function isStringSchema(schema) {
|
94
|
-
if (schema.type === "string") {
|
95
|
-
return true;
|
96
|
-
}
|
97
|
-
if (isAnyOfSchema(schema, "string")) {
|
98
|
-
return true;
|
99
|
-
}
|
100
|
-
return false;
|
101
|
-
}
|
102
|
-
function isNumberSchema(schema) {
|
103
|
-
if (schema.type === "number") {
|
104
|
-
return true;
|
105
|
-
}
|
106
|
-
if (isAnyOfSchema(schema, "number")) {
|
107
|
-
return true;
|
108
|
-
}
|
109
|
-
return false;
|
110
|
-
}
|
111
|
-
function isBooleanSchema(schema) {
|
112
|
-
if (schema.type === "boolean") {
|
113
|
-
return true;
|
114
|
-
}
|
115
|
-
if (isAnyOfSchema(schema, "boolean")) {
|
116
|
-
return true;
|
117
|
-
}
|
118
|
-
return false;
|
119
|
-
}
|
120
127
|
function forUnit(unit) {
|
121
128
|
const config = new Config();
|
129
|
+
const rawHSConfig = config.requireObject(HighstateConfigKey.Config);
|
130
|
+
const hsConfig = unitConfigSchema.parse(rawHSConfig);
|
131
|
+
const rawHsSecrets = config.requireSecretObject(HighstateConfigKey.Secrets).apply((secrets2) => z.record(z.string(), z.unknown()).parse(secrets2));
|
122
132
|
const args = mapValues(unit.model.args, (arg, argName) => {
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
return config.get(argName) || arg.schema.default;
|
129
|
-
}
|
130
|
-
case isNumberSchema(arg.schema): {
|
131
|
-
if (arg.required) {
|
132
|
-
return config.requireNumber(argName);
|
133
|
-
}
|
134
|
-
const value = config.get(argName);
|
135
|
-
if (!value) {
|
136
|
-
return arg.schema.default;
|
137
|
-
}
|
138
|
-
return config.getNumber(argName) ?? arg.schema.default;
|
139
|
-
}
|
140
|
-
case isBooleanSchema(arg.schema): {
|
141
|
-
if (arg.required) {
|
142
|
-
return config.requireBoolean(argName);
|
143
|
-
}
|
144
|
-
const value = config.get(argName);
|
145
|
-
if (!value) {
|
146
|
-
return arg.schema.default;
|
147
|
-
}
|
148
|
-
return config.getBoolean(argName) ?? arg.schema.default;
|
149
|
-
}
|
150
|
-
default: {
|
151
|
-
if (!arg.required) {
|
152
|
-
const value2 = config.get(argName);
|
153
|
-
if (!value2) {
|
154
|
-
return arg.schema.default;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
const value = arg.required ? config.requireObject(argName) : config.getObject(argName);
|
158
|
-
if (value === void 0) return arg.schema.default;
|
159
|
-
if (!ajv.validate(arg.schema, value)) {
|
160
|
-
throw new Error(`Invalid config for '${argName}': ${ajv.errorsText()}`);
|
161
|
-
}
|
162
|
-
return value;
|
163
|
-
}
|
133
|
+
const value = parseArgumentValue(hsConfig.args[argName]);
|
134
|
+
const result = arg[runtimeSchema].safeParse(value);
|
135
|
+
if (!result.success) {
|
136
|
+
throw new Error(`Invalid argument "${argName}": ${z.prettifyError(result.error)}`);
|
164
137
|
}
|
138
|
+
return result.data;
|
165
139
|
});
|
166
|
-
const secretIds = config.requireObject("$secretIds");
|
167
|
-
const getSecretValue = (secretName, secret2) => {
|
168
|
-
switch (true) {
|
169
|
-
case isStringSchema(secret2.schema): {
|
170
|
-
return secret2.required ? config.requireSecret(secretName) : config.getSecret(secretName);
|
171
|
-
}
|
172
|
-
case isNumberSchema(secret2.schema): {
|
173
|
-
return secret2.required ? config.requireSecretNumber(secretName) : config.getSecretNumber(secretName);
|
174
|
-
}
|
175
|
-
case isBooleanSchema(secret2.schema): {
|
176
|
-
return secret2.required ? config.requireSecretBoolean(secretName) : config.getSecretBoolean(secretName);
|
177
|
-
}
|
178
|
-
default: {
|
179
|
-
const value = secret2.required ? config.requireSecretObject(secretName) : config.getSecretObject(secretName);
|
180
|
-
if (!ajv.validate(secret2.schema, value)) {
|
181
|
-
throw new Error(`Invalid secret for '${secretName}': ${ajv.errorsText()}`);
|
182
|
-
}
|
183
|
-
return value;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
};
|
187
140
|
const secrets = mapValues(unit.model.secrets, (secret2, secretName) => {
|
188
|
-
const
|
189
|
-
if (!
|
190
|
-
|
141
|
+
const hasValue = hsConfig.secretNames.includes(secretName);
|
142
|
+
if (!hasValue && !secret2.required) {
|
143
|
+
return secret2.schema.default ? secret(secret2.schema.default) : void 0;
|
191
144
|
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
145
|
+
if (!hasValue && secret2.required) {
|
146
|
+
throw new Error(`Secret "${secretName}" is required but not provided.`);
|
147
|
+
}
|
148
|
+
return rawHsSecrets[secretName].apply((rawValue) => {
|
149
|
+
const value = parseArgumentValue(rawValue);
|
150
|
+
const result = secret2[runtimeSchema].safeParse(value);
|
151
|
+
if (!result.success) {
|
152
|
+
throw new Error(`Invalid secret "${secretName}": ${z.prettifyError(result.error)}`);
|
153
|
+
}
|
154
|
+
return secret(result.data);
|
155
|
+
});
|
197
156
|
});
|
198
157
|
const inputs = mapValues(unit.model.inputs, (input, inputName) => {
|
199
|
-
const value =
|
158
|
+
const value = hsConfig.inputs[inputName];
|
200
159
|
if (!value) {
|
201
160
|
if (input.multiple) {
|
202
|
-
return
|
161
|
+
return [];
|
203
162
|
}
|
204
163
|
return void 0;
|
205
164
|
}
|
206
|
-
return getOutput(unit, input, value);
|
165
|
+
return getOutput(hsConfig, unit, input, value);
|
207
166
|
});
|
208
|
-
const type =
|
209
|
-
instanceId =
|
167
|
+
const [type, name] = parseInstanceId(hsConfig.instanceId);
|
168
|
+
instanceId = hsConfig.instanceId;
|
169
|
+
instanceName = name;
|
210
170
|
return {
|
211
|
-
|
212
|
-
instanceId,
|
171
|
+
instanceId: hsConfig.instanceId,
|
213
172
|
type,
|
214
|
-
name
|
173
|
+
name,
|
174
|
+
args,
|
215
175
|
secrets,
|
216
176
|
inputs,
|
217
|
-
invokedTriggers:
|
177
|
+
invokedTriggers: hsConfig.invokedTriggers,
|
178
|
+
getSecret: (name2, factory) => {
|
179
|
+
if (!factory) {
|
180
|
+
return secrets[name2];
|
181
|
+
}
|
182
|
+
const value = secrets[name2] ?? secret(factory());
|
183
|
+
secrets[name2] = value;
|
184
|
+
return value;
|
185
|
+
},
|
218
186
|
outputs: async (outputs = {}) => {
|
219
187
|
const result = mapValues(outputs, (outputValue, outputName) => {
|
220
188
|
if (outputName === "$statusFields") {
|
@@ -229,74 +197,58 @@ function forUnit(unit) {
|
|
229
197
|
if (outputName === "$triggers") {
|
230
198
|
return output(outputValue).apply(mapTriggers);
|
231
199
|
}
|
200
|
+
if (outputName === "$workers") {
|
201
|
+
return output(outputValue).apply(mapWorkers);
|
202
|
+
}
|
232
203
|
if (outputName.startsWith("$")) {
|
233
|
-
throw new Error(`Unknown extra output
|
204
|
+
throw new Error(`Unknown extra output "${outputName}".`);
|
234
205
|
}
|
235
206
|
const outputModel = unit.model.outputs[outputName];
|
236
207
|
if (!outputModel) {
|
237
|
-
throw new Error(
|
208
|
+
throw new Error(
|
209
|
+
`Output "${outputName}" not found in the unit "${unit.model.type}", but was passed to outputs(...).`
|
210
|
+
);
|
238
211
|
}
|
239
212
|
const entity = unit.entities.get(outputModel.type);
|
240
213
|
if (!entity) {
|
241
214
|
throw new Error(
|
242
|
-
`Entity
|
215
|
+
`Entity "${outputModel.type}" not found in the unit "${unit.model.type}". It looks like a bug in the unit definition.`
|
243
216
|
);
|
244
217
|
}
|
245
218
|
return output(outputValue).apply((value) => {
|
246
|
-
if (value === void 0) {
|
247
|
-
if (outputModel.required) {
|
248
|
-
throw new Error(`Output '${outputName}' is required.`);
|
249
|
-
}
|
250
|
-
return void 0;
|
251
|
-
}
|
252
219
|
const schema = outputModel.multiple ? entity.schema.array() : entity.schema;
|
253
|
-
|
254
|
-
|
220
|
+
const result2 = schema.safeParse(value);
|
221
|
+
if (!result2.success) {
|
222
|
+
throw new Error(
|
223
|
+
`Invalid output "${outputName}" of type "${outputModel.type}": ${z.prettifyError(result2.error)}`
|
224
|
+
);
|
255
225
|
}
|
256
|
-
return
|
226
|
+
return result2.data;
|
257
227
|
});
|
258
228
|
});
|
259
|
-
await Promise.all(Object.values(result).map((o) =>
|
260
|
-
result.$secrets =
|
261
|
-
const secretsMap = {};
|
262
|
-
for (const [outputName, outputValue] of Object.entries(outputs)) {
|
263
|
-
if (!outputName.startsWith("$")) {
|
264
|
-
const resolvedValue = await outputToPromise(outputValue);
|
265
|
-
const secrets2 = extractObjectsFromValue(unitSecretSchema, resolvedValue);
|
266
|
-
if (secrets2.length > 0) {
|
267
|
-
secretsMap[outputName] = secrets2;
|
268
|
-
}
|
269
|
-
}
|
270
|
-
}
|
229
|
+
await Promise.all(Object.values(result).map((o) => toPromise(o)));
|
230
|
+
result.$secrets = secrets;
|
271
231
|
const artifactsMap = {};
|
272
232
|
for (const [outputName, outputValue] of Object.entries(outputs)) {
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
artifactsMap[outputName] = artifacts;
|
278
|
-
}
|
233
|
+
const resolvedValue = await toPromise(outputValue);
|
234
|
+
const artifacts = extractObjectsFromValue(unitArtifactSchema, resolvedValue);
|
235
|
+
if (artifacts.length > 0) {
|
236
|
+
artifactsMap[outputName] = artifacts;
|
279
237
|
}
|
280
238
|
}
|
281
239
|
if (Object.keys(artifactsMap).length > 0) {
|
282
|
-
result.$
|
283
|
-
}
|
284
|
-
if (Object.keys(secretsMap).length > 0) {
|
285
|
-
result.$exportedSecretIds = mapValues(secretsMap, (v) => v.map((secret2) => secret2.id));
|
240
|
+
result.$artifacts = artifactsMap;
|
286
241
|
}
|
287
242
|
return result;
|
288
243
|
}
|
289
244
|
};
|
290
245
|
}
|
291
|
-
function outputToPromise(o) {
|
292
|
-
return new Promise((resolve) => output(o).apply(resolve));
|
293
|
-
}
|
294
246
|
function mapStatusFields(status) {
|
295
247
|
if (!status) {
|
296
248
|
return [];
|
297
249
|
}
|
298
250
|
if (Array.isArray(status)) {
|
299
|
-
return status.filter((field) =>
|
251
|
+
return status.filter((field) => field?.value !== void 0).map((field) => {
|
300
252
|
return {
|
301
253
|
name: field.name,
|
302
254
|
meta: {
|
@@ -327,47 +279,25 @@ function mapStatusFields(status) {
|
|
327
279
|
},
|
328
280
|
name
|
329
281
|
};
|
330
|
-
}).filter((field) =>
|
282
|
+
}).filter((field) => field?.value !== void 0);
|
331
283
|
}
|
332
284
|
function mapPages(pages) {
|
333
285
|
if (!pages) {
|
334
|
-
return [];
|
286
|
+
return output([]);
|
335
287
|
}
|
336
|
-
if (Array.isArray(pages)) {
|
337
|
-
|
288
|
+
if (!Array.isArray(pages)) {
|
289
|
+
pages = Object.entries(pages).map(([name, page]) => {
|
290
|
+
if (!page) {
|
291
|
+
return void 0;
|
292
|
+
}
|
293
|
+
return { ...page, name };
|
294
|
+
});
|
338
295
|
}
|
339
|
-
return
|
340
|
-
}
|
341
|
-
function fileFromString(name, content, contentType = "text/plain", isSecret = false) {
|
342
|
-
return {
|
343
|
-
meta: {
|
344
|
-
name,
|
345
|
-
contentType,
|
346
|
-
size: Buffer.byteLength(content, "utf8")
|
347
|
-
},
|
348
|
-
content: {
|
349
|
-
type: "embedded",
|
350
|
-
value: isSecret ? secret(content) : content
|
351
|
-
}
|
352
|
-
};
|
353
|
-
}
|
354
|
-
function fileFromBuffer(name, content, contentType = "application/octet-stream", isSecret = false) {
|
355
|
-
return {
|
356
|
-
meta: {
|
357
|
-
name,
|
358
|
-
contentType,
|
359
|
-
size: content.byteLength,
|
360
|
-
isBinary: true
|
361
|
-
},
|
362
|
-
content: {
|
363
|
-
type: "embedded",
|
364
|
-
value: isSecret ? secret(content.toString("base64")) : content.toString("base64")
|
365
|
-
}
|
366
|
-
};
|
296
|
+
return output(pages.filter((page) => !!page));
|
367
297
|
}
|
368
298
|
function mapTerminals(terminals) {
|
369
299
|
if (!terminals) {
|
370
|
-
return [];
|
300
|
+
return output([]);
|
371
301
|
}
|
372
302
|
if (!Array.isArray(terminals)) {
|
373
303
|
terminals = Object.entries(terminals).map(([name, terminal]) => {
|
@@ -377,46 +307,35 @@ function mapTerminals(terminals) {
|
|
377
307
|
return { ...terminal, name };
|
378
308
|
});
|
379
309
|
}
|
380
|
-
return terminals.filter((terminal) => !!terminal)
|
381
|
-
if (!terminal.spec.files) {
|
382
|
-
return terminal;
|
383
|
-
}
|
384
|
-
return {
|
385
|
-
...terminal,
|
386
|
-
spec: {
|
387
|
-
...terminal.spec,
|
388
|
-
files: pipe(
|
389
|
-
terminal.spec.files,
|
390
|
-
mapValues((file) => {
|
391
|
-
if (typeof file === "string") {
|
392
|
-
return {
|
393
|
-
meta: {
|
394
|
-
name: "content",
|
395
|
-
contentType: "text/plain",
|
396
|
-
size: Buffer.byteLength(file, "utf8")
|
397
|
-
},
|
398
|
-
content: {
|
399
|
-
type: "embedded",
|
400
|
-
value: file
|
401
|
-
}
|
402
|
-
};
|
403
|
-
}
|
404
|
-
return file;
|
405
|
-
}),
|
406
|
-
pickBy((value) => !!value)
|
407
|
-
)
|
408
|
-
}
|
409
|
-
};
|
410
|
-
});
|
310
|
+
return output(terminals.filter((terminal) => !!terminal));
|
411
311
|
}
|
412
312
|
function mapTriggers(triggers) {
|
413
313
|
if (!triggers) {
|
414
|
-
return [];
|
314
|
+
return output([]);
|
415
315
|
}
|
416
|
-
if (Array.isArray(triggers)) {
|
417
|
-
|
316
|
+
if (!Array.isArray(triggers)) {
|
317
|
+
triggers = Object.entries(triggers).map(([name, trigger]) => {
|
318
|
+
if (!trigger) {
|
319
|
+
return void 0;
|
320
|
+
}
|
321
|
+
return { ...trigger, name };
|
322
|
+
});
|
418
323
|
}
|
419
|
-
return
|
324
|
+
return output(triggers.filter((trigger) => !!trigger));
|
325
|
+
}
|
326
|
+
function mapWorkers(workers) {
|
327
|
+
if (!workers) {
|
328
|
+
return output([]);
|
329
|
+
}
|
330
|
+
if (!Array.isArray(workers)) {
|
331
|
+
workers = Object.entries(workers).map(([name, worker]) => {
|
332
|
+
if (!worker) {
|
333
|
+
return void 0;
|
334
|
+
}
|
335
|
+
return { ...worker, name };
|
336
|
+
});
|
337
|
+
}
|
338
|
+
return output(workers.filter((worker) => !!worker));
|
420
339
|
}
|
421
340
|
function extractObjectsFromValue(schema, data) {
|
422
341
|
const result = [];
|
@@ -442,77 +361,7 @@ function extractObjectsFromValue(schema, data) {
|
|
442
361
|
traverse(data);
|
443
362
|
return result;
|
444
363
|
}
|
445
|
-
function flattenInputs(...values) {
|
446
|
-
return all(values).apply((allValues) => {
|
447
|
-
const result = [];
|
448
|
-
for (const value of allValues) {
|
449
|
-
if (Array.isArray(value)) {
|
450
|
-
result.push(...value);
|
451
|
-
} else if (value) {
|
452
|
-
result.push(value);
|
453
|
-
}
|
454
|
-
}
|
455
|
-
return result;
|
456
|
-
});
|
457
|
-
}
|
458
|
-
function mapInputs(array, fn) {
|
459
|
-
return output(array).apply((array2) => {
|
460
|
-
return array2?.map((v, index) => fn(v, index, array2)) ?? [];
|
461
|
-
});
|
462
|
-
}
|
463
|
-
function flatMapInput(...args) {
|
464
|
-
const fn = args.pop();
|
465
|
-
const values = args;
|
466
|
-
return mapInputs(flattenInputs(...values), fn);
|
467
|
-
}
|
468
|
-
function mapOptional(input, func) {
|
469
|
-
if (input === void 0) {
|
470
|
-
return void 0;
|
471
|
-
}
|
472
|
-
return func(input);
|
473
|
-
}
|
474
|
-
function toPromise(input) {
|
475
|
-
return new Promise((resolve) => output(input).apply(resolve));
|
476
|
-
}
|
477
|
-
function singleton(factory) {
|
478
|
-
let instance;
|
479
|
-
return () => {
|
480
|
-
if (instance === void 0) {
|
481
|
-
instance = factory();
|
482
|
-
}
|
483
|
-
return instance;
|
484
|
-
};
|
485
|
-
}
|
486
|
-
function providerFactory(factory) {
|
487
|
-
const instances = /* @__PURE__ */ new Map();
|
488
|
-
return (name) => {
|
489
|
-
if (!instances.has(name)) {
|
490
|
-
instances.set(name, factory(name));
|
491
|
-
}
|
492
|
-
return instances.get(name);
|
493
|
-
};
|
494
|
-
}
|
495
|
-
function mergeInputObjects(...objects) {
|
496
|
-
return output(objects).apply((array) => {
|
497
|
-
return Object.assign({}, ...array);
|
498
|
-
});
|
499
|
-
}
|
500
|
-
function normalize(item, collection) {
|
501
|
-
if (item && collection) {
|
502
|
-
return [item, ...collection];
|
503
|
-
}
|
504
|
-
if (item) {
|
505
|
-
return [item];
|
506
|
-
}
|
507
|
-
return collection ?? [];
|
508
|
-
}
|
509
|
-
function apply(fn) {
|
510
|
-
return (input) => output(input).apply(fn);
|
511
|
-
}
|
512
|
-
function applyMap(fn) {
|
513
|
-
return (input) => output(input).apply((array) => array.map(fn));
|
514
|
-
}
|
515
364
|
|
516
|
-
export { apply,
|
365
|
+
export { apply, fileFromBuffer, fileFromString, forUnit, getResourceComment, getUnitInstanceId, getUnitInstanceName, normalize, normalizeInputs, normalizeInputsAndMap, toPromise };
|
517
366
|
//# sourceMappingURL=index.js.map
|
518
367
|
//# sourceMappingURL=index.js.map
|