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