@highstate/contract 0.20.0 → 0.26.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.js +671 -850
- package/package.json +11 -12
- package/src/component.spec.ts +3 -2
- package/src/component.ts +18 -17
- package/src/entity.ts +59 -10
- package/src/evaluation.ts +1 -2
- package/src/index.ts +11 -2
- package/src/instance-input.ts +1 -1
- package/src/instance.ts +1 -8
- package/src/runtime.ts +74 -0
- package/src/shared.ts +15 -0
- package/src/unit.ts +1 -2
- package/src/worker.ts +10 -0
- package/LICENSE +0 -21
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export { z } from 'zod';
|
|
3
|
-
import { sha256 } from '@noble/hashes/sha2.js';
|
|
4
|
-
import { mapValues, pickBy, isNonNullish, uniqueBy } from 'remeda';
|
|
5
|
-
import { parse } from 'yaml';
|
|
6
|
-
|
|
1
|
+
// @bun
|
|
7
2
|
// src/entity.ts
|
|
3
|
+
import { z as z2 } from "zod";
|
|
4
|
+
|
|
5
|
+
// src/cuidv2d.ts
|
|
6
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
8
7
|
var cuidv2DefaultLength = 24;
|
|
9
8
|
function bufToBigInt(buf) {
|
|
10
9
|
const bits = 8n;
|
|
@@ -24,8 +23,8 @@ function normalizeCuid2Prefix(prefix) {
|
|
|
24
23
|
return prefix;
|
|
25
24
|
}
|
|
26
25
|
if (prefix >= "0" && prefix <= "9") {
|
|
27
|
-
const digit = prefix.charCodeAt(0) -
|
|
28
|
-
return String.fromCharCode(
|
|
26
|
+
const digit = prefix.charCodeAt(0) - 48;
|
|
27
|
+
return String.fromCharCode(97 + digit);
|
|
29
28
|
}
|
|
30
29
|
throw new Error(`Invalid CUID prefix character: ${prefix}`);
|
|
31
30
|
}
|
|
@@ -38,7 +37,7 @@ function cuidv2d(namespace, identity) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
// src/i18n.ts
|
|
41
|
-
var knownAbbreviationsMap =
|
|
40
|
+
var knownAbbreviationsMap = new Map;
|
|
42
41
|
function registerKnownAbbreviations(abbreviations) {
|
|
43
42
|
for (const abbr of abbreviations) {
|
|
44
43
|
const lower = abbr.toLowerCase();
|
|
@@ -50,8 +49,8 @@ function registerKnownAbbreviations(abbreviations) {
|
|
|
50
49
|
function clearKnownAbbreviations() {
|
|
51
50
|
knownAbbreviationsMap.clear();
|
|
52
51
|
}
|
|
53
|
-
function camelCaseToHumanReadable(
|
|
54
|
-
const words =
|
|
52
|
+
function camelCaseToHumanReadable(text) {
|
|
53
|
+
const words = text.split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|_|-|\./).filter((word) => word.length > 0);
|
|
55
54
|
return words.map((word) => {
|
|
56
55
|
const lower = word.toLowerCase();
|
|
57
56
|
if (knownAbbreviationsMap.has(lower)) {
|
|
@@ -81,7 +80,7 @@ function fixJsonSchema(schema) {
|
|
|
81
80
|
otherSchemas.push(item);
|
|
82
81
|
}
|
|
83
82
|
if (objectSchemas.length > 1) {
|
|
84
|
-
const required =
|
|
83
|
+
const required = new Set;
|
|
85
84
|
const properties = {};
|
|
86
85
|
let additionalProperties;
|
|
87
86
|
for (const objectSchema of objectSchemas) {
|
|
@@ -97,7 +96,7 @@ function fixJsonSchema(schema) {
|
|
|
97
96
|
if (isRecord(objectProperties)) {
|
|
98
97
|
for (const [key, value] of Object.entries(objectProperties)) {
|
|
99
98
|
const existing = properties[key];
|
|
100
|
-
if (existing ===
|
|
99
|
+
if (existing === undefined) {
|
|
101
100
|
properties[key] = value;
|
|
102
101
|
continue;
|
|
103
102
|
}
|
|
@@ -105,7 +104,7 @@ function fixJsonSchema(schema) {
|
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
if ("additionalProperties" in objectSchema) {
|
|
108
|
-
if (additionalProperties ===
|
|
107
|
+
if (additionalProperties === undefined) {
|
|
109
108
|
additionalProperties = objectSchema.additionalProperties;
|
|
110
109
|
} else if (additionalProperties !== objectSchema.additionalProperties) {
|
|
111
110
|
additionalProperties = false;
|
|
@@ -116,7 +115,7 @@ function fixJsonSchema(schema) {
|
|
|
116
115
|
type: "object",
|
|
117
116
|
properties,
|
|
118
117
|
...required.size > 0 ? { required: Array.from(required) } : {},
|
|
119
|
-
...additionalProperties !==
|
|
118
|
+
...additionalProperties !== undefined ? { additionalProperties } : { additionalProperties: false }
|
|
120
119
|
};
|
|
121
120
|
const merged = otherSchemas.length === 0 ? mergedObjectSchema : {
|
|
122
121
|
...schema,
|
|
@@ -136,9 +135,7 @@ function fixJsonSchema(schema) {
|
|
|
136
135
|
next.oneOf = next.oneOf.map(fixJsonSchema);
|
|
137
136
|
}
|
|
138
137
|
if (isRecord(next.properties)) {
|
|
139
|
-
next.properties = Object.fromEntries(
|
|
140
|
-
Object.entries(next.properties).map(([key, value]) => [key, fixJsonSchema(value)])
|
|
141
|
-
);
|
|
138
|
+
next.properties = Object.fromEntries(Object.entries(next.properties).map(([key, value]) => [key, fixJsonSchema(value)]));
|
|
142
139
|
}
|
|
143
140
|
if (isRecord(next.items)) {
|
|
144
141
|
next.items = fixJsonSchema(next.items);
|
|
@@ -150,58 +147,18 @@ function fixJsonSchema(schema) {
|
|
|
150
147
|
}
|
|
151
148
|
return next;
|
|
152
149
|
}
|
|
150
|
+
|
|
151
|
+
// src/meta.ts
|
|
152
|
+
import { z } from "zod";
|
|
153
153
|
var objectMetaSchema = z.object({
|
|
154
|
-
/**
|
|
155
|
-
* Human-readable name of the object.
|
|
156
|
-
*
|
|
157
|
-
* Used in UI components for better user experience.
|
|
158
|
-
*/
|
|
159
154
|
title: z.string().optional(),
|
|
160
|
-
/**
|
|
161
|
-
* The title used globally for the object.
|
|
162
|
-
*
|
|
163
|
-
* For example, the title of an instance secret is "Password" which is okay
|
|
164
|
-
* to display in the instance secret list, but when the secret is displayed in a
|
|
165
|
-
* global secret list the name should be more descriptive, like "Proxmox Password".
|
|
166
|
-
*/
|
|
167
155
|
globalTitle: z.string().optional(),
|
|
168
|
-
/**
|
|
169
|
-
* Description of the object.
|
|
170
|
-
*
|
|
171
|
-
* Provides additional context for users and developers.
|
|
172
|
-
*/
|
|
173
156
|
description: z.string().optional(),
|
|
174
|
-
/**
|
|
175
|
-
* The color of the object.
|
|
176
|
-
*
|
|
177
|
-
* Used in UI components to visually distinguish objects.
|
|
178
|
-
*/
|
|
179
157
|
color: z.string().optional(),
|
|
180
|
-
/**
|
|
181
|
-
* Primary icon identifier.
|
|
182
|
-
*
|
|
183
|
-
* Should reference a iconify icon name, like "mdi:server" or "gg:remote".
|
|
184
|
-
*/
|
|
185
158
|
icon: z.string().optional(),
|
|
186
|
-
/**
|
|
187
|
-
* The color of the primary icon.
|
|
188
|
-
*/
|
|
189
159
|
iconColor: z.string().optional(),
|
|
190
|
-
/**
|
|
191
|
-
* The URL of the custom image that should be used as the icon or avatar.
|
|
192
|
-
*/
|
|
193
160
|
avatarUrl: z.string().optional(),
|
|
194
|
-
/**
|
|
195
|
-
* The secondary icon identifier.
|
|
196
|
-
*
|
|
197
|
-
* Used to provide additional context or actions related to the object.
|
|
198
|
-
*
|
|
199
|
-
* Should reference a iconify icon name, like "mdi:edit" or "mdi:delete".
|
|
200
|
-
*/
|
|
201
161
|
secondaryIcon: z.string().optional(),
|
|
202
|
-
/**
|
|
203
|
-
* The color of the secondary icon.
|
|
204
|
-
*/
|
|
205
162
|
secondaryIconColor: z.string().optional()
|
|
206
163
|
});
|
|
207
164
|
var commonObjectMetaSchema = objectMetaSchema.pick({
|
|
@@ -229,24 +186,12 @@ var serviceAccountMetaSchema = objectMetaSchema.pick({
|
|
|
229
186
|
iconColor: true
|
|
230
187
|
}).required({ title: true });
|
|
231
188
|
var timestampsSchema = z.object({
|
|
232
|
-
/**
|
|
233
|
-
* The timestamp when the object was created.
|
|
234
|
-
*/
|
|
235
189
|
createdAt: z.date(),
|
|
236
|
-
/**
|
|
237
|
-
* The timestamp when the object was last updated.
|
|
238
|
-
*/
|
|
239
190
|
updatedAt: z.date()
|
|
240
191
|
});
|
|
241
|
-
var genericNameSchema = z.string().regex(
|
|
242
|
-
/^[a-z][a-z0-9-.]+$/,
|
|
243
|
-
"Name must start with a letter and can only contain lowercase letters, numbers, dashes (-) and dots (.)"
|
|
244
|
-
).min(2).max(64);
|
|
192
|
+
var genericNameSchema = z.string().regex(/^[a-z][a-z0-9-.]+$/, "Name must start with a letter and can only contain lowercase letters, numbers, dashes (-) and dots (.)").min(2).max(64);
|
|
245
193
|
var versionedNameSchema = z.union([
|
|
246
194
|
z.templateLiteral([genericNameSchema, z.literal("."), z.literal("v"), z.number().int().min(1)]),
|
|
247
|
-
// to prevent TypeScript matching "proxmox.virtual-machine.v2" as
|
|
248
|
-
// 1. "proxmox.v"
|
|
249
|
-
// 2. "irtual-machine.v2" and thinking it should be a number
|
|
250
195
|
z.templateLiteral([
|
|
251
196
|
genericNameSchema,
|
|
252
197
|
z.literal("."),
|
|
@@ -282,53 +227,19 @@ function parseVersionedName(name) {
|
|
|
282
227
|
var fieldNameSchema = z.string().regex(/^[a-z][a-zA-Z0-9]+$/, "Field name must start with a letter and be in camelCase format").min(2).max(64);
|
|
283
228
|
|
|
284
229
|
// src/entity.ts
|
|
285
|
-
var entityInclusionSchema =
|
|
286
|
-
/**
|
|
287
|
-
* The static type of the included entity.
|
|
288
|
-
*/
|
|
230
|
+
var entityInclusionSchema = z2.object({
|
|
289
231
|
type: versionedNameSchema,
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
*/
|
|
294
|
-
required: z.boolean(),
|
|
295
|
-
/**
|
|
296
|
-
* Whether the included entity is multiple.
|
|
297
|
-
*/
|
|
298
|
-
multiple: z.boolean(),
|
|
299
|
-
/**
|
|
300
|
-
* The name of the field where the included entity is embedded.
|
|
301
|
-
*/
|
|
302
|
-
field: z.string()
|
|
232
|
+
required: z2.boolean(),
|
|
233
|
+
multiple: z2.boolean(),
|
|
234
|
+
field: z2.string()
|
|
303
235
|
});
|
|
304
|
-
var entityModelSchema =
|
|
305
|
-
/**
|
|
306
|
-
* The static type of the entity.
|
|
307
|
-
*/
|
|
236
|
+
var entityModelSchema = z2.object({
|
|
308
237
|
type: versionedNameSchema,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
*/
|
|
312
|
-
extensions: z.string().array().optional(),
|
|
313
|
-
/**
|
|
314
|
-
* The list of directly extended entity types.
|
|
315
|
-
*/
|
|
316
|
-
directExtensions: z.string().array().optional(),
|
|
317
|
-
/**
|
|
318
|
-
* The list of all included entities (directly or inherited from extensions).
|
|
319
|
-
*/
|
|
238
|
+
extensions: z2.string().array().optional(),
|
|
239
|
+
directExtensions: z2.string().array().optional(),
|
|
320
240
|
inclusions: entityInclusionSchema.array().optional(),
|
|
321
|
-
/**
|
|
322
|
-
* The list of directly included entities.
|
|
323
|
-
*/
|
|
324
241
|
directInclusions: entityInclusionSchema.array().optional(),
|
|
325
|
-
|
|
326
|
-
* The JSON schema of the entity value.
|
|
327
|
-
*/
|
|
328
|
-
schema: z.custom(),
|
|
329
|
-
/**
|
|
330
|
-
* The extra metadata of the entity.
|
|
331
|
-
*/
|
|
242
|
+
schema: z2.custom(),
|
|
332
243
|
meta: objectMetaSchema.required({ title: true }).pick({
|
|
333
244
|
title: true,
|
|
334
245
|
description: true,
|
|
@@ -336,10 +247,7 @@ var entityModelSchema = z.object({
|
|
|
336
247
|
icon: true,
|
|
337
248
|
iconColor: true
|
|
338
249
|
}),
|
|
339
|
-
|
|
340
|
-
* The CRC32 of the entity definition.
|
|
341
|
-
*/
|
|
342
|
-
definitionHash: z.number()
|
|
250
|
+
definitionHash: z2.number()
|
|
343
251
|
});
|
|
344
252
|
function isEntityIncludeRef(value) {
|
|
345
253
|
if (typeof value !== "object" || value === null || !("entity" in value)) {
|
|
@@ -348,6 +256,22 @@ function isEntityIncludeRef(value) {
|
|
|
348
256
|
const entity = value.entity;
|
|
349
257
|
return typeof entity === "function" || isEntity(entity);
|
|
350
258
|
}
|
|
259
|
+
var objectEntity = {
|
|
260
|
+
type: "system.object.v1",
|
|
261
|
+
schema: z2.object().loose(),
|
|
262
|
+
model: {
|
|
263
|
+
type: "system.object.v1",
|
|
264
|
+
definitionHash: 0,
|
|
265
|
+
schema: z2.object().loose().toJSONSchema(),
|
|
266
|
+
meta: {
|
|
267
|
+
title: "Object",
|
|
268
|
+
description: "The common ancestor of all entities. Any entity can be assigned to this entity.",
|
|
269
|
+
color: "#9e9e9e",
|
|
270
|
+
icon: "mdi:cube",
|
|
271
|
+
iconColor: "#9e9e9e"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
351
275
|
function defineEntity(options) {
|
|
352
276
|
try {
|
|
353
277
|
entityModelSchema.shape.type.parse(options.type);
|
|
@@ -357,63 +281,64 @@ function defineEntity(options) {
|
|
|
357
281
|
if (!options.schema) {
|
|
358
282
|
throw new Error("Entity schema is required");
|
|
359
283
|
}
|
|
360
|
-
const includeRefs = Object.entries(options.includes ?? {}).map(
|
|
361
|
-
(
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
getEntity2 = entity;
|
|
369
|
-
} else {
|
|
370
|
-
const entity = entityRef.entity;
|
|
371
|
-
getEntity2 = () => entity;
|
|
372
|
-
}
|
|
373
|
-
return { field, required, multiple, getEntity: getEntity2 };
|
|
374
|
-
}
|
|
375
|
-
const getEntity = () => entityRef;
|
|
376
|
-
return { field, required: true, multiple: false, getEntity };
|
|
377
|
-
}
|
|
378
|
-
);
|
|
379
|
-
const inclusionShape = includeRefs.reduce(
|
|
380
|
-
(shape, includeRef) => {
|
|
381
|
-
let schema = z.lazy(() => includeRef.getEntity().schema);
|
|
382
|
-
if (includeRef.multiple) {
|
|
383
|
-
schema = includeRef.required ? schema.array().min(1) : schema.array().default([]);
|
|
284
|
+
const includeRefs = Object.entries(options.includes ?? {}).map(([field, entityRef]) => {
|
|
285
|
+
if (isEntityIncludeRef(entityRef)) {
|
|
286
|
+
const required = entityRef.required ?? true;
|
|
287
|
+
const multiple = entityRef.multiple ?? false;
|
|
288
|
+
let getEntity2;
|
|
289
|
+
if (typeof entityRef.entity === "function") {
|
|
290
|
+
const entity = entityRef.entity;
|
|
291
|
+
getEntity2 = entity;
|
|
384
292
|
} else {
|
|
385
|
-
|
|
293
|
+
const entity = entityRef.entity;
|
|
294
|
+
getEntity2 = () => entity;
|
|
386
295
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
{}
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
296
|
+
return { field, required, multiple, getEntity: getEntity2 };
|
|
297
|
+
}
|
|
298
|
+
const getEntity = () => entityRef;
|
|
299
|
+
return { field, required: true, multiple: false, getEntity };
|
|
300
|
+
});
|
|
301
|
+
const inclusionShape = includeRefs.reduce((shape, includeRef) => {
|
|
302
|
+
let schema = z2.lazy(() => includeRef.getEntity().schema);
|
|
303
|
+
if (includeRef.multiple) {
|
|
304
|
+
schema = includeRef.required ? schema.array().min(1) : schema.array().default([]);
|
|
305
|
+
} else {
|
|
306
|
+
schema = includeRef.required ? schema : schema.optional();
|
|
307
|
+
}
|
|
308
|
+
shape[includeRef.field] = schema;
|
|
309
|
+
return shape;
|
|
310
|
+
}, {});
|
|
311
|
+
const inheritedExtensions = [...Object.values(options.extends ?? {}), objectEntity].filter((entity) => entity.type !== options.type);
|
|
312
|
+
const uniqueExtensions = Array.from(new Map(inheritedExtensions.map((entity) => [entity.type, entity])).values());
|
|
313
|
+
const schemaExtensions = uniqueExtensions.filter((entity) => entity.type !== objectEntity.type);
|
|
314
|
+
const strictIntersectionBase = (schema) => {
|
|
315
|
+
if (schema instanceof z2.ZodObject) {
|
|
316
|
+
return schema.strict();
|
|
317
|
+
}
|
|
318
|
+
return schema;
|
|
319
|
+
};
|
|
320
|
+
let finalSchema = schemaExtensions.reduce((schema, entity) => z2.intersection(schema, strictIntersectionBase(entity.schema)), strictIntersectionBase(options.schema));
|
|
396
321
|
if (includeRefs.length > 0) {
|
|
397
|
-
finalSchema =
|
|
322
|
+
finalSchema = z2.intersection(finalSchema, strictIntersectionBase(z2.object(inclusionShape)));
|
|
398
323
|
}
|
|
399
|
-
finalSchema =
|
|
324
|
+
finalSchema = z2.intersection(finalSchema, strictIntersectionBase(entityWithMetaSchema));
|
|
400
325
|
const directInclusions = () => includeRefs.map((includeRef) => ({
|
|
401
326
|
type: includeRef.getEntity().type,
|
|
402
327
|
required: includeRef.required,
|
|
403
328
|
multiple: includeRef.multiple,
|
|
404
329
|
field: includeRef.field
|
|
405
330
|
}));
|
|
406
|
-
const directExtensions =
|
|
331
|
+
const directExtensions = uniqueExtensions.map((entity) => entity.type);
|
|
407
332
|
const getInclusions = () => {
|
|
408
333
|
const incs = [...directInclusions()];
|
|
409
|
-
for (const entity of
|
|
334
|
+
for (const entity of uniqueExtensions) {
|
|
410
335
|
if (entity.model.inclusions) {
|
|
411
336
|
incs.push(...entity.model.inclusions);
|
|
412
337
|
}
|
|
413
338
|
}
|
|
414
339
|
return incs;
|
|
415
340
|
};
|
|
416
|
-
const extensions =
|
|
341
|
+
const extensions = uniqueExtensions.reduce((exts, entity) => {
|
|
417
342
|
exts.push(...entity.model.extensions ?? [], entity.type);
|
|
418
343
|
return exts;
|
|
419
344
|
}, []);
|
|
@@ -424,19 +349,19 @@ function defineEntity(options) {
|
|
|
424
349
|
schema: finalSchema,
|
|
425
350
|
model: {
|
|
426
351
|
type: options.type,
|
|
427
|
-
extensions: extensions.length > 0 ? extensions :
|
|
428
|
-
directExtensions: directExtensions.length > 0 ? directExtensions :
|
|
352
|
+
extensions: extensions.length > 0 ? extensions : undefined,
|
|
353
|
+
directExtensions: directExtensions.length > 0 ? directExtensions : undefined,
|
|
429
354
|
get inclusions() {
|
|
430
355
|
const incs = getInclusions();
|
|
431
|
-
return incs.length > 0 ? incs :
|
|
356
|
+
return incs.length > 0 ? incs : undefined;
|
|
432
357
|
},
|
|
433
358
|
get directInclusions() {
|
|
434
359
|
const incs = directInclusions();
|
|
435
|
-
return incs.length > 0 ? incs :
|
|
360
|
+
return incs.length > 0 ? incs : undefined;
|
|
436
361
|
},
|
|
437
362
|
get schema() {
|
|
438
363
|
if (!_schema) {
|
|
439
|
-
const rawSchema =
|
|
364
|
+
const rawSchema = z2.toJSONSchema(finalSchema, {
|
|
440
365
|
target: "draft-7",
|
|
441
366
|
unrepresentable: "any"
|
|
442
367
|
});
|
|
@@ -448,10 +373,8 @@ function defineEntity(options) {
|
|
|
448
373
|
...options.meta,
|
|
449
374
|
title: options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0])
|
|
450
375
|
},
|
|
451
|
-
// will be calculated by the library loader
|
|
452
376
|
definitionHash: null
|
|
453
377
|
}
|
|
454
|
-
// biome-ignore lint/suspicious/noExplicitAny: we already typed return type
|
|
455
378
|
};
|
|
456
379
|
} catch (error) {
|
|
457
380
|
throw new Error(`Failed to define entity "${options.type}"`, { cause: error });
|
|
@@ -469,22 +392,10 @@ function isAssignableTo(entity, target) {
|
|
|
469
392
|
}
|
|
470
393
|
return entity.inclusions?.some((implementation) => implementation.type === target) ?? false;
|
|
471
394
|
}
|
|
472
|
-
var entityMetaSchema =
|
|
473
|
-
/**
|
|
474
|
-
* The type of the entity.
|
|
475
|
-
*/
|
|
395
|
+
var entityMetaSchema = z2.object({
|
|
476
396
|
type: versionedNameSchema,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
*
|
|
480
|
-
* Anonymous entities are forbidden.
|
|
481
|
-
*/
|
|
482
|
-
identity: z.string(),
|
|
483
|
-
/**
|
|
484
|
-
* The IDs of the entities to reference by this entity.
|
|
485
|
-
* Must already exist in the system (or be at least defined by this unit).
|
|
486
|
-
*/
|
|
487
|
-
references: z.record(z.string(), z.string().array()).optional(),
|
|
397
|
+
identity: z2.string(),
|
|
398
|
+
references: z2.record(z2.string(), z2.string().array()).optional(),
|
|
488
399
|
...objectMetaSchema.pick({
|
|
489
400
|
title: true,
|
|
490
401
|
description: true,
|
|
@@ -492,10 +403,10 @@ var entityMetaSchema = z.object({
|
|
|
492
403
|
iconColor: true
|
|
493
404
|
}).shape
|
|
494
405
|
});
|
|
495
|
-
var entityWithMetaSchema =
|
|
406
|
+
var entityWithMetaSchema = z2.object({
|
|
496
407
|
$meta: entityMetaSchema
|
|
497
408
|
});
|
|
498
|
-
var entityIdCache =
|
|
409
|
+
var entityIdCache = new WeakMap;
|
|
499
410
|
var entityIdNamespace = "3cd37048-7c50-43a9-a2b9-ff7ff2b5ee79";
|
|
500
411
|
function getEntityId(entity) {
|
|
501
412
|
if (!entity.$meta) {
|
|
@@ -510,103 +421,17 @@ function getEntityId(entity) {
|
|
|
510
421
|
entityIdCache.set(entity, id);
|
|
511
422
|
return id;
|
|
512
423
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
result = `${parent.id} -> ${result}`;
|
|
525
|
-
instance = parent;
|
|
526
|
-
}
|
|
527
|
-
return result;
|
|
528
|
-
}
|
|
529
|
-
var InstanceNameConflictError = class extends Error {
|
|
530
|
-
constructor(instanceId, firstPath, secondPath) {
|
|
531
|
-
super(
|
|
532
|
-
`Multiple instances produced with the same instance ID "${instanceId}":
|
|
533
|
-
1. ${firstPath}
|
|
534
|
-
2. ${secondPath}`
|
|
535
|
-
);
|
|
536
|
-
this.instanceId = instanceId;
|
|
537
|
-
this.firstPath = firstPath;
|
|
538
|
-
this.secondPath = secondPath;
|
|
539
|
-
this.name = "InstanceNameConflictError";
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
var currentInstance = null;
|
|
543
|
-
var runtimeInstances = /* @__PURE__ */ new Map();
|
|
544
|
-
function resetEvaluation() {
|
|
545
|
-
runtimeInstances.clear();
|
|
546
|
-
currentInstance = null;
|
|
547
|
-
}
|
|
548
|
-
function getRuntimeInstances() {
|
|
549
|
-
return Array.from(runtimeInstances.values());
|
|
550
|
-
}
|
|
551
|
-
function registerInstance(component, instance, fn) {
|
|
552
|
-
const conflicting = runtimeInstances.get(instance.id);
|
|
553
|
-
if (conflicting) {
|
|
554
|
-
throw new InstanceNameConflictError(
|
|
555
|
-
instance.id,
|
|
556
|
-
formatInstancePath(conflicting.instance),
|
|
557
|
-
formatInstancePath(instance)
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
runtimeInstances.set(instance.id, { instance, component });
|
|
561
|
-
let previousParentInstance = null;
|
|
562
|
-
if (currentInstance) {
|
|
563
|
-
instance.parentId = currentInstance.id;
|
|
564
|
-
}
|
|
565
|
-
if (component.model.kind === "composite") {
|
|
566
|
-
previousParentInstance = currentInstance;
|
|
567
|
-
currentInstance = instance;
|
|
568
|
-
}
|
|
569
|
-
try {
|
|
570
|
-
const rawOutputs = fn();
|
|
571
|
-
const outputs = mapValues(rawOutputs ?? {}, (outputGroup) => {
|
|
572
|
-
return [outputGroup].flat(2).filter(Boolean);
|
|
573
|
-
});
|
|
574
|
-
const toStableInputs = (outputGroup, useBoundaryFallback) => {
|
|
575
|
-
return outputGroup.map((output) => useBoundaryFallback ? output[boundaryInput] : output).filter(isStableInstanceInput).map((output) => {
|
|
576
|
-
return output.path ? {
|
|
577
|
-
instanceId: output.instanceId,
|
|
578
|
-
output: output.output,
|
|
579
|
-
path: output.path
|
|
580
|
-
} : {
|
|
581
|
-
instanceId: output.instanceId,
|
|
582
|
-
output: output.output
|
|
583
|
-
};
|
|
584
|
-
});
|
|
585
|
-
};
|
|
586
|
-
instance.resolvedOutputs = mapValues(
|
|
587
|
-
outputs ?? {},
|
|
588
|
-
(outputGroup) => toStableInputs(outputGroup, false)
|
|
589
|
-
);
|
|
590
|
-
instance.outputs = mapValues(outputs ?? {}, (outputGroup) => toStableInputs(outputGroup, true));
|
|
591
|
-
return mapValues(rawOutputs, (rawOutputGroup, outputKey) => {
|
|
592
|
-
const outputRefs = (outputs[outputKey] ?? []).map((output) => {
|
|
593
|
-
if (output.provided) {
|
|
594
|
-
output[boundaryInput] = { instanceId: instance.id, output: outputKey };
|
|
595
|
-
}
|
|
596
|
-
return output;
|
|
597
|
-
});
|
|
598
|
-
if (component.model.outputs[outputKey]?.multiple) {
|
|
599
|
-
const multipleOutput = Array.isArray(rawOutputGroup) ? rawOutputGroup : outputRefs;
|
|
600
|
-
multipleOutput[boundaryInput] ??= { instanceId: instance.id, output: outputKey };
|
|
601
|
-
return multipleOutput;
|
|
602
|
-
}
|
|
603
|
-
return rawOutputGroup ?? outputRefs[0];
|
|
604
|
-
});
|
|
605
|
-
} finally {
|
|
606
|
-
if (previousParentInstance) {
|
|
607
|
-
currentInstance = previousParentInstance;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
424
|
+
// src/instance.ts
|
|
425
|
+
import { z as z4 } from "zod";
|
|
426
|
+
|
|
427
|
+
// src/shared.ts
|
|
428
|
+
import { z as z3 } from "zod";
|
|
429
|
+
var componentKindSchema = z3.enum(["composite", "unit"]);
|
|
430
|
+
var runtimeSchema = Symbol("runtimeSchema");
|
|
431
|
+
var kind = Symbol("kind");
|
|
432
|
+
var boundaryInput = Symbol("boundaryInput");
|
|
433
|
+
function inputKey(input) {
|
|
434
|
+
return input.path ? `${input.instanceId}:${input.output}:${input.path}` : `${input.instanceId}:${input.output}`;
|
|
610
435
|
}
|
|
611
436
|
|
|
612
437
|
// src/instance-input.ts
|
|
@@ -614,7 +439,7 @@ function appendInputPath(currentPath, segment) {
|
|
|
614
439
|
return currentPath ? `${currentPath}.${segment}` : segment;
|
|
615
440
|
}
|
|
616
441
|
function createRuntimeInputAccessor(input, boundary) {
|
|
617
|
-
const accessorCache = input.provided ?
|
|
442
|
+
const accessorCache = input.provided ? undefined : new Map;
|
|
618
443
|
let currentBoundary = boundary;
|
|
619
444
|
return new Proxy(input, {
|
|
620
445
|
get(target, property, receiver) {
|
|
@@ -700,7 +525,7 @@ function createMultipleInputAccessor(inputs, boundary) {
|
|
|
700
525
|
return [];
|
|
701
526
|
}
|
|
702
527
|
const selected = input[property];
|
|
703
|
-
if (selected ===
|
|
528
|
+
if (selected === undefined || selected === null) {
|
|
704
529
|
return [];
|
|
705
530
|
}
|
|
706
531
|
if (Array.isArray(selected)) {
|
|
@@ -717,7 +542,7 @@ function createDeepOutputAccessor(output) {
|
|
|
717
542
|
if (!normalizedOutput.provided) {
|
|
718
543
|
return normalizedOutput;
|
|
719
544
|
}
|
|
720
|
-
const accessorCache =
|
|
545
|
+
const accessorCache = new Map;
|
|
721
546
|
return new Proxy(normalizedOutput, {
|
|
722
547
|
get(target, property, receiver) {
|
|
723
548
|
if (typeof property !== "string") {
|
|
@@ -730,17 +555,14 @@ function createDeepOutputAccessor(output) {
|
|
|
730
555
|
return Reflect.get(target, property, receiver);
|
|
731
556
|
}
|
|
732
557
|
const cached = accessorCache.get(property);
|
|
733
|
-
if (cached !==
|
|
558
|
+
if (cached !== undefined) {
|
|
734
559
|
return cached;
|
|
735
560
|
}
|
|
736
561
|
const providedTarget = target;
|
|
737
|
-
const nextInput = createInput(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
},
|
|
742
|
-
{ boundary: providedTarget[boundaryInput] }
|
|
743
|
-
);
|
|
562
|
+
const nextInput = createInput({
|
|
563
|
+
...providedTarget,
|
|
564
|
+
path: appendInputPath(providedTarget.path, property)
|
|
565
|
+
}, { boundary: providedTarget[boundaryInput] });
|
|
744
566
|
const resolved = createDeepOutputAccessor(nextInput);
|
|
745
567
|
accessorCache.set(property, resolved);
|
|
746
568
|
return resolved;
|
|
@@ -748,31 +570,236 @@ function createDeepOutputAccessor(output) {
|
|
|
748
570
|
});
|
|
749
571
|
}
|
|
750
572
|
|
|
573
|
+
// src/instance.ts
|
|
574
|
+
var positionSchema = z4.object({
|
|
575
|
+
x: z4.number(),
|
|
576
|
+
y: z4.number()
|
|
577
|
+
});
|
|
578
|
+
var instanceIdSchema = z4.templateLiteral([versionedNameSchema, ":", genericNameSchema]);
|
|
579
|
+
var instanceInputSchema = z4.object({
|
|
580
|
+
instanceId: instanceIdSchema,
|
|
581
|
+
output: z4.string(),
|
|
582
|
+
path: z4.string().optional()
|
|
583
|
+
});
|
|
584
|
+
var hubInputSchema = z4.object({
|
|
585
|
+
hubId: z4.string()
|
|
586
|
+
});
|
|
587
|
+
var instanceModelPatchSchema = z4.object({
|
|
588
|
+
args: z4.record(z4.string(), z4.unknown()).optional(),
|
|
589
|
+
inputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
|
|
590
|
+
hubInputs: z4.record(z4.string(), z4.array(hubInputSchema)).optional(),
|
|
591
|
+
injectionInputs: z4.array(hubInputSchema).optional(),
|
|
592
|
+
position: positionSchema.optional()
|
|
593
|
+
});
|
|
594
|
+
var instanceModelSchema = z4.object({
|
|
595
|
+
id: instanceIdSchema,
|
|
596
|
+
kind: componentKindSchema,
|
|
597
|
+
type: versionedNameSchema,
|
|
598
|
+
name: genericNameSchema,
|
|
599
|
+
...instanceModelPatchSchema.shape,
|
|
600
|
+
resolvedInputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
|
|
601
|
+
parentId: instanceIdSchema.optional(),
|
|
602
|
+
outputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
|
|
603
|
+
resolvedOutputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional()
|
|
604
|
+
});
|
|
605
|
+
var hubModelPatchSchema = z4.object({
|
|
606
|
+
position: positionSchema.optional(),
|
|
607
|
+
inputs: z4.array(instanceInputSchema).optional(),
|
|
608
|
+
injectionInputs: z4.array(hubInputSchema).optional()
|
|
609
|
+
});
|
|
610
|
+
var hubModelSchema = z4.object({
|
|
611
|
+
id: z4.cuid2(),
|
|
612
|
+
...hubModelPatchSchema.shape
|
|
613
|
+
});
|
|
614
|
+
function parseInstanceId(instanceId) {
|
|
615
|
+
const parts = instanceId.split(":");
|
|
616
|
+
if (parts.length !== 2) {
|
|
617
|
+
throw new Error(`Invalid instance ID: ${instanceId}`);
|
|
618
|
+
}
|
|
619
|
+
return parts;
|
|
620
|
+
}
|
|
621
|
+
function selectInput(inputs, name) {
|
|
622
|
+
const groupBoundary = inputs[boundaryInput] ?? inputs[0]?.[boundaryInput];
|
|
623
|
+
if (inputs.length === 0 && !groupBoundary) {
|
|
624
|
+
throw new Error(`Cannot select input "${name}": empty input group has no boundary metadata to build a missing input reference.`);
|
|
625
|
+
}
|
|
626
|
+
const input = inputs.find((input2) => input2.provided && (input2.instanceId === name || parseInstanceId(input2.instanceId)[1] === name));
|
|
627
|
+
if (!input || !input.provided) {
|
|
628
|
+
const fallbackBoundary = groupBoundary ?? inputs.find((input2) => Boolean(input2[boundaryInput]))?.[boundaryInput] ?? inputs[0]?.[boundaryInput];
|
|
629
|
+
if (!fallbackBoundary) {
|
|
630
|
+
throw new Error(`Cannot select input "${name}": input group has no boundary metadata to build a missing input reference.`);
|
|
631
|
+
}
|
|
632
|
+
return createNonProvidedInput(fallbackBoundary);
|
|
633
|
+
}
|
|
634
|
+
const boundary = groupBoundary ?? input[boundaryInput];
|
|
635
|
+
return createInput(input, { boundary });
|
|
636
|
+
}
|
|
637
|
+
var HighstateSignature;
|
|
638
|
+
((HighstateSignature2) => {
|
|
639
|
+
HighstateSignature2["Artifact"] = "d55c63ac-3174-4756-808f-f778e99af0d1";
|
|
640
|
+
HighstateSignature2["Yaml"] = "c857cac5-caa6-4421-b82c-e561fbce6367";
|
|
641
|
+
HighstateSignature2["Secret"] = "240e5789-6ae4-4b22-b9d8-87169e8b4bab";
|
|
642
|
+
})(HighstateSignature ||= {});
|
|
643
|
+
var yamlValueSchema = z4.object({
|
|
644
|
+
["c857cac5-caa6-4421-b82c-e561fbce6367" /* Yaml */]: z4.literal(true),
|
|
645
|
+
value: z4.string()
|
|
646
|
+
});
|
|
647
|
+
var fileMetaSchema = z4.object({
|
|
648
|
+
name: z4.string(),
|
|
649
|
+
contentType: z4.string().optional(),
|
|
650
|
+
size: z4.number().optional(),
|
|
651
|
+
mode: z4.number().optional()
|
|
652
|
+
});
|
|
653
|
+
var WellKnownInstanceCustomStatus;
|
|
654
|
+
((WellKnownInstanceCustomStatus2) => {
|
|
655
|
+
WellKnownInstanceCustomStatus2["Healthy"] = "healthy";
|
|
656
|
+
WellKnownInstanceCustomStatus2["Degraded"] = "degraded";
|
|
657
|
+
WellKnownInstanceCustomStatus2["Down"] = "down";
|
|
658
|
+
WellKnownInstanceCustomStatus2["Warning"] = "warning";
|
|
659
|
+
WellKnownInstanceCustomStatus2["Progressing"] = "progressing";
|
|
660
|
+
WellKnownInstanceCustomStatus2["Error"] = "error";
|
|
661
|
+
})(WellKnownInstanceCustomStatus ||= {});
|
|
662
|
+
var instanceStatusFieldValueSchema = z4.union([
|
|
663
|
+
z4.string(),
|
|
664
|
+
z4.number(),
|
|
665
|
+
z4.boolean(),
|
|
666
|
+
z4.string().array()
|
|
667
|
+
]);
|
|
668
|
+
var instanceStatusFieldSchema = z4.object({
|
|
669
|
+
name: z4.string(),
|
|
670
|
+
meta: objectMetaSchema.pick({
|
|
671
|
+
title: true,
|
|
672
|
+
icon: true,
|
|
673
|
+
iconColor: true
|
|
674
|
+
}).required({ title: true }),
|
|
675
|
+
complementaryTo: z4.string().optional(),
|
|
676
|
+
value: instanceStatusFieldValueSchema.optional()
|
|
677
|
+
});
|
|
678
|
+
function secretSchema(schema) {
|
|
679
|
+
const secretType = z4.object({
|
|
680
|
+
["240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */]: z4.literal(true),
|
|
681
|
+
value: schema
|
|
682
|
+
});
|
|
683
|
+
return z4.codec(z4.union([secretType, schema]), secretType, {
|
|
684
|
+
decode: (value) => typeof value === "object" && value !== null && ("240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */ in value) ? value : { ["240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */]: true, value },
|
|
685
|
+
encode: (value) => value
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
function isSecret(value) {
|
|
689
|
+
return typeof value === "object" && value !== null && "240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */ in value;
|
|
690
|
+
}
|
|
691
|
+
// src/unit.ts
|
|
692
|
+
import { mapValues as mapValues3 } from "remeda";
|
|
693
|
+
import { z as z6 } from "zod";
|
|
694
|
+
|
|
695
|
+
// src/component.ts
|
|
696
|
+
import { isNonNullish, mapValues as mapValues2, pickBy, uniqueBy } from "remeda";
|
|
697
|
+
import { z as z5 } from "zod";
|
|
698
|
+
|
|
699
|
+
// src/evaluation.ts
|
|
700
|
+
import { mapValues } from "remeda";
|
|
701
|
+
function isStableInstanceInput(value) {
|
|
702
|
+
return typeof value === "object" && value !== null && "instanceId" in value && "output" in value && typeof value.instanceId === "string" && typeof value.output === "string";
|
|
703
|
+
}
|
|
704
|
+
function formatInstancePath(instance) {
|
|
705
|
+
let result = instance.id;
|
|
706
|
+
while (instance.parentId) {
|
|
707
|
+
const parent = runtimeInstances.get(instance.parentId)?.instance;
|
|
708
|
+
if (!parent) {
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
result = `${parent.id} -> ${result}`;
|
|
712
|
+
instance = parent;
|
|
713
|
+
}
|
|
714
|
+
return result;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
class InstanceNameConflictError extends Error {
|
|
718
|
+
instanceId;
|
|
719
|
+
firstPath;
|
|
720
|
+
secondPath;
|
|
721
|
+
constructor(instanceId, firstPath, secondPath) {
|
|
722
|
+
super(`Multiple instances produced with the same instance ID "${instanceId}":
|
|
723
|
+
` + `1. ${firstPath}
|
|
724
|
+
` + `2. ${secondPath}`);
|
|
725
|
+
this.instanceId = instanceId;
|
|
726
|
+
this.firstPath = firstPath;
|
|
727
|
+
this.secondPath = secondPath;
|
|
728
|
+
this.name = "InstanceNameConflictError";
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
var currentInstance = null;
|
|
732
|
+
var runtimeInstances = new Map;
|
|
733
|
+
function resetEvaluation() {
|
|
734
|
+
runtimeInstances.clear();
|
|
735
|
+
currentInstance = null;
|
|
736
|
+
}
|
|
737
|
+
function getRuntimeInstances() {
|
|
738
|
+
return Array.from(runtimeInstances.values());
|
|
739
|
+
}
|
|
740
|
+
function registerInstance(component, instance, fn) {
|
|
741
|
+
const conflicting = runtimeInstances.get(instance.id);
|
|
742
|
+
if (conflicting) {
|
|
743
|
+
throw new InstanceNameConflictError(instance.id, formatInstancePath(conflicting.instance), formatInstancePath(instance));
|
|
744
|
+
}
|
|
745
|
+
runtimeInstances.set(instance.id, { instance, component });
|
|
746
|
+
let previousParentInstance = null;
|
|
747
|
+
if (currentInstance) {
|
|
748
|
+
instance.parentId = currentInstance.id;
|
|
749
|
+
}
|
|
750
|
+
if (component.model.kind === "composite") {
|
|
751
|
+
previousParentInstance = currentInstance;
|
|
752
|
+
currentInstance = instance;
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
const rawOutputs = fn();
|
|
756
|
+
const outputs = mapValues(rawOutputs ?? {}, (outputGroup) => {
|
|
757
|
+
return [outputGroup].flat(2).filter(Boolean);
|
|
758
|
+
});
|
|
759
|
+
const toStableInputs = (outputGroup, useBoundaryFallback) => {
|
|
760
|
+
return outputGroup.map((output) => useBoundaryFallback ? output[boundaryInput] : output).filter(isStableInstanceInput).map((output) => {
|
|
761
|
+
return output.path ? {
|
|
762
|
+
instanceId: output.instanceId,
|
|
763
|
+
output: output.output,
|
|
764
|
+
path: output.path
|
|
765
|
+
} : {
|
|
766
|
+
instanceId: output.instanceId,
|
|
767
|
+
output: output.output
|
|
768
|
+
};
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
instance.resolvedOutputs = mapValues(outputs ?? {}, (outputGroup) => toStableInputs(outputGroup, false));
|
|
772
|
+
instance.outputs = mapValues(outputs ?? {}, (outputGroup) => toStableInputs(outputGroup, true));
|
|
773
|
+
return mapValues(rawOutputs, (rawOutputGroup, outputKey) => {
|
|
774
|
+
const outputRefs = (outputs[outputKey] ?? []).map((output) => {
|
|
775
|
+
if (output.provided) {
|
|
776
|
+
output[boundaryInput] = { instanceId: instance.id, output: outputKey };
|
|
777
|
+
}
|
|
778
|
+
return output;
|
|
779
|
+
});
|
|
780
|
+
if (component.model.outputs[outputKey]?.multiple) {
|
|
781
|
+
const multipleOutput = Array.isArray(rawOutputGroup) ? rawOutputGroup : outputRefs;
|
|
782
|
+
multipleOutput[boundaryInput] ??= { instanceId: instance.id, output: outputKey };
|
|
783
|
+
return multipleOutput;
|
|
784
|
+
}
|
|
785
|
+
return rawOutputGroup ?? outputRefs[0];
|
|
786
|
+
});
|
|
787
|
+
} finally {
|
|
788
|
+
if (previousParentInstance) {
|
|
789
|
+
currentInstance = previousParentInstance;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
751
794
|
// src/component.ts
|
|
752
|
-
var runtimeSchema = /* @__PURE__ */ Symbol("runtimeSchema");
|
|
753
795
|
var validationEnabled = true;
|
|
754
796
|
function setValidationEnabled(enabled) {
|
|
755
797
|
validationEnabled = enabled;
|
|
756
798
|
}
|
|
757
|
-
var
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
*/
|
|
762
|
-
schema: z.custom(),
|
|
763
|
-
/**
|
|
764
|
-
* The original Zod schema of the argument.
|
|
765
|
-
*
|
|
766
|
-
* Only available at runtime.
|
|
767
|
-
*/
|
|
768
|
-
[runtimeSchema]: z.instanceof(z.ZodType).optional(),
|
|
769
|
-
/**
|
|
770
|
-
* Whether the argument is required.
|
|
771
|
-
*/
|
|
772
|
-
required: z.boolean(),
|
|
773
|
-
/**
|
|
774
|
-
* The extra metadata of the argument.
|
|
775
|
-
*/
|
|
799
|
+
var componentArgumentSchema = z5.object({
|
|
800
|
+
schema: z5.custom(),
|
|
801
|
+
[runtimeSchema]: z5.instanceof(z5.ZodType).optional(),
|
|
802
|
+
required: z5.boolean(),
|
|
776
803
|
meta: objectMetaSchema.required({ title: true }).pick({
|
|
777
804
|
title: true,
|
|
778
805
|
globalTitle: true,
|
|
@@ -782,57 +809,22 @@ var componentArgumentSchema = z.object({
|
|
|
782
809
|
iconColor: true
|
|
783
810
|
})
|
|
784
811
|
});
|
|
785
|
-
var componentInputSchema =
|
|
786
|
-
/**
|
|
787
|
-
* The type of the entity passed through the input.
|
|
788
|
-
*/
|
|
812
|
+
var componentInputSchema = z5.object({
|
|
789
813
|
type: versionedNameSchema,
|
|
790
|
-
/**
|
|
791
|
-
* The input name this output type is derived from.
|
|
792
|
-
*
|
|
793
|
-
* If set, the output uses the referenced input as its fallback type source.
|
|
794
|
-
*/
|
|
795
814
|
fromInput: fieldNameSchema.optional(),
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
*/
|
|
799
|
-
required: z.boolean(),
|
|
800
|
-
/**
|
|
801
|
-
* Whether the input can have multiple values.
|
|
802
|
-
*/
|
|
803
|
-
multiple: z.boolean(),
|
|
804
|
-
/**
|
|
805
|
-
* The extra metadata of the input.
|
|
806
|
-
*/
|
|
815
|
+
required: z5.boolean(),
|
|
816
|
+
multiple: z5.boolean(),
|
|
807
817
|
meta: objectMetaSchema.required({ title: true }).pick({
|
|
808
818
|
title: true,
|
|
809
819
|
description: true
|
|
810
820
|
})
|
|
811
821
|
});
|
|
812
|
-
var componentModelSchema =
|
|
813
|
-
/**
|
|
814
|
-
* The type of the component.
|
|
815
|
-
*/
|
|
822
|
+
var componentModelSchema = z5.object({
|
|
816
823
|
type: genericNameSchema,
|
|
817
|
-
/**
|
|
818
|
-
* The kind of the component.
|
|
819
|
-
*/
|
|
820
824
|
kind: componentKindSchema,
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
args: z.record(fieldNameSchema, componentArgumentSchema),
|
|
825
|
-
/**
|
|
826
|
-
* The record of the input schemas.
|
|
827
|
-
*/
|
|
828
|
-
inputs: z.record(fieldNameSchema, componentInputSchema),
|
|
829
|
-
/**
|
|
830
|
-
* The record of the output schemas.
|
|
831
|
-
*/
|
|
832
|
-
outputs: z.record(fieldNameSchema, componentInputSchema),
|
|
833
|
-
/**
|
|
834
|
-
* The extra metadata of the component.
|
|
835
|
-
*/
|
|
825
|
+
args: z5.record(fieldNameSchema, componentArgumentSchema),
|
|
826
|
+
inputs: z5.record(fieldNameSchema, componentInputSchema),
|
|
827
|
+
outputs: z5.record(fieldNameSchema, componentInputSchema),
|
|
836
828
|
meta: objectMetaSchema.required({ title: true }).pick({
|
|
837
829
|
title: true,
|
|
838
830
|
description: true,
|
|
@@ -842,26 +834,12 @@ var componentModelSchema = z.object({
|
|
|
842
834
|
secondaryIcon: true,
|
|
843
835
|
secondaryIconColor: true
|
|
844
836
|
}).extend({
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
*
|
|
848
|
-
* Used to group components in the UI.
|
|
849
|
-
*/
|
|
850
|
-
category: z.string().optional(),
|
|
851
|
-
/**
|
|
852
|
-
* The default name prefix for the component instances.
|
|
853
|
-
*
|
|
854
|
-
* Used to generate default names for the instances.
|
|
855
|
-
*/
|
|
856
|
-
defaultNamePrefix: z.string()
|
|
837
|
+
category: z5.string().optional(),
|
|
838
|
+
defaultNamePrefix: z5.string()
|
|
857
839
|
}),
|
|
858
|
-
|
|
859
|
-
* The CRC32 of the component definition.
|
|
860
|
-
*/
|
|
861
|
-
definitionHash: z.number()
|
|
840
|
+
definitionHash: z5.number()
|
|
862
841
|
});
|
|
863
|
-
var originalCreate =
|
|
864
|
-
var kind = /* @__PURE__ */ Symbol("kind");
|
|
842
|
+
var originalCreate = Symbol("originalCreate");
|
|
865
843
|
function defineComponent(options) {
|
|
866
844
|
try {
|
|
867
845
|
componentModelSchema.shape.type.parse(options.type);
|
|
@@ -871,21 +849,20 @@ function defineComponent(options) {
|
|
|
871
849
|
if (!options.create) {
|
|
872
850
|
throw new Error("Component create function is required");
|
|
873
851
|
}
|
|
874
|
-
const entities =
|
|
852
|
+
const entities = new Map;
|
|
875
853
|
const mapInput = createInputMapper(entities);
|
|
876
854
|
const mapOutput = createOutputMapper(options.inputs, entities);
|
|
877
855
|
const model = {
|
|
878
856
|
type: options.type,
|
|
879
857
|
kind: options[kind] ?? "composite",
|
|
880
|
-
args:
|
|
881
|
-
inputs:
|
|
882
|
-
outputs:
|
|
858
|
+
args: mapValues2(options.args ?? {}, mapArgument),
|
|
859
|
+
inputs: mapValues2(options.inputs ?? {}, mapInput),
|
|
860
|
+
outputs: mapValues2(options.outputs ?? {}, mapOutput),
|
|
883
861
|
meta: {
|
|
884
862
|
...options.meta,
|
|
885
863
|
title: options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0]),
|
|
886
864
|
defaultNamePrefix: options.meta?.defaultNamePrefix || parseVersionedName(options.type)[0].split(".").slice(-1)[0]
|
|
887
865
|
},
|
|
888
|
-
// will be calculated by library loader
|
|
889
866
|
definitionHash: null
|
|
890
867
|
};
|
|
891
868
|
function create(params) {
|
|
@@ -916,54 +893,48 @@ function defineComponent(options) {
|
|
|
916
893
|
tracedInputs[key] = uniqueBy(group, inputKey);
|
|
917
894
|
flatInputs[key] = uniqueBy(inputs2, runtimeInputKey);
|
|
918
895
|
}
|
|
919
|
-
return registerInstance(
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const input = flatInputs[key]?.[0];
|
|
940
|
-
if (input?.provided) {
|
|
941
|
-
return createDeepOutputAccessor({
|
|
942
|
-
...input,
|
|
943
|
-
[boundaryInput]: { instanceId, output: key }
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
return createNonProvidedInput({ instanceId, output: key });
|
|
947
|
-
}
|
|
948
|
-
const inputs2 = (flatInputs[key] ?? []).filter(isProvidedRuntimeInput).map(
|
|
949
|
-
(input) => createDeepOutputAccessor({
|
|
896
|
+
return registerInstance(create, {
|
|
897
|
+
id: instanceId,
|
|
898
|
+
type: options.type,
|
|
899
|
+
kind: options[kind] ?? "composite",
|
|
900
|
+
name,
|
|
901
|
+
args,
|
|
902
|
+
inputs: tracedInputs,
|
|
903
|
+
resolvedInputs: mapValues2(flatInputs, (inputs2) => {
|
|
904
|
+
return inputs2.filter((input) => input.provided).map((input) => ({
|
|
905
|
+
instanceId: input.instanceId,
|
|
906
|
+
output: input.output,
|
|
907
|
+
...input.path ? { path: input.path } : {}
|
|
908
|
+
}));
|
|
909
|
+
})
|
|
910
|
+
}, () => {
|
|
911
|
+
const markedInputs = mapValues2(model.inputs, (componentInput, key) => {
|
|
912
|
+
if (!componentInput.multiple) {
|
|
913
|
+
const input = flatInputs[key]?.[0];
|
|
914
|
+
if (input?.provided) {
|
|
915
|
+
return createDeepOutputAccessor({
|
|
950
916
|
...input,
|
|
951
917
|
[boundaryInput]: { instanceId, output: key }
|
|
952
|
-
})
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
return createNonProvidedInput({ instanceId, output: key });
|
|
921
|
+
}
|
|
922
|
+
const inputs2 = (flatInputs[key] ?? []).filter(isProvidedRuntimeInput).map((input) => createDeepOutputAccessor({
|
|
923
|
+
...input,
|
|
924
|
+
[boundaryInput]: { instanceId, output: key }
|
|
925
|
+
}));
|
|
926
|
+
const multipleBoundary = { instanceId, output: key };
|
|
927
|
+
return createMultipleInputAccessor(inputs2, multipleBoundary);
|
|
928
|
+
});
|
|
929
|
+
const outputs = options.create({
|
|
930
|
+
id: instanceId,
|
|
931
|
+
name,
|
|
932
|
+
args: processArgs(instanceId, create.model, args),
|
|
933
|
+
inputs: markedInputs
|
|
934
|
+
}) ?? {};
|
|
935
|
+
const normalizedOutputs = normalizeCreateOutputs(outputs, model, instanceId);
|
|
936
|
+
return withDeepOutputAccessors(normalizedOutputs, model, instanceId);
|
|
937
|
+
});
|
|
967
938
|
function normalizeIncomingInput(input, inputName) {
|
|
968
939
|
if (isStableInstanceInput2(input)) {
|
|
969
940
|
return createInput(input);
|
|
@@ -977,9 +948,7 @@ function defineComponent(options) {
|
|
|
977
948
|
};
|
|
978
949
|
return createInput(runtimeInput, { boundary: inputBoundary });
|
|
979
950
|
}
|
|
980
|
-
return createNonProvidedInput(
|
|
981
|
-
runtimeInput[boundaryInput] ?? { instanceId, output: inputName }
|
|
982
|
-
);
|
|
951
|
+
return createNonProvidedInput(runtimeInput[boundaryInput] ?? { instanceId, output: inputName });
|
|
983
952
|
}
|
|
984
953
|
function normalizeIncomingInputGroup(inputGroup, inputName) {
|
|
985
954
|
const group = [];
|
|
@@ -1024,9 +993,7 @@ function processArgs(instanceId, model, args) {
|
|
|
1024
993
|
if (arg.schema) {
|
|
1025
994
|
const result = arg[runtimeSchema].safeParse(args[key]);
|
|
1026
995
|
if (!result.success) {
|
|
1027
|
-
throw new Error(
|
|
1028
|
-
`Invalid argument "${key}" in instance "${instanceId}": ${result.error.message}`
|
|
1029
|
-
);
|
|
996
|
+
throw new Error(`Invalid argument "${key}" in instance "${instanceId}": ${result.error.message}`);
|
|
1030
997
|
}
|
|
1031
998
|
validatedArgs[key] = result.data;
|
|
1032
999
|
} else {
|
|
@@ -1036,7 +1003,7 @@ function processArgs(instanceId, model, args) {
|
|
|
1036
1003
|
return validatedArgs;
|
|
1037
1004
|
}
|
|
1038
1005
|
function withDeepOutputAccessors(outputs, model, instanceId) {
|
|
1039
|
-
return
|
|
1006
|
+
return mapValues2(outputs, (outputGroup, outputName) => {
|
|
1040
1007
|
const outputSpec = model.outputs[outputName];
|
|
1041
1008
|
if (!outputSpec) {
|
|
1042
1009
|
return outputGroup[0];
|
|
@@ -1068,9 +1035,7 @@ function normalizeCreateOutputGroup(outputGroup, instanceId, outputName) {
|
|
|
1068
1035
|
};
|
|
1069
1036
|
return createInput(runtimeOutput, { boundary: stableBoundary });
|
|
1070
1037
|
}
|
|
1071
|
-
return createNonProvidedInput(
|
|
1072
|
-
runtimeOutput[boundaryInput] ?? { instanceId, output: outputName }
|
|
1073
|
-
);
|
|
1038
|
+
return createNonProvidedInput(runtimeOutput[boundaryInput] ?? { instanceId, output: outputName });
|
|
1074
1039
|
});
|
|
1075
1040
|
}
|
|
1076
1041
|
function normalizeCreateOutputs(outputs, model, instanceId) {
|
|
@@ -1086,9 +1051,7 @@ function normalizeCreateOutputs(outputs, model, instanceId) {
|
|
|
1086
1051
|
}
|
|
1087
1052
|
const normalizedGroup = normalizeCreateOutputGroup(outputGroup, instanceId, outputName);
|
|
1088
1053
|
if (outputSpec.multiple && normalizedGroup.some((output) => !output.provided)) {
|
|
1089
|
-
throw new Error(
|
|
1090
|
-
`Multiple output "${outputName}" in instance "${instanceId}" cannot contain non-provided items`
|
|
1091
|
-
);
|
|
1054
|
+
throw new Error(`Multiple output "${outputName}" in instance "${instanceId}" cannot contain non-provided items`);
|
|
1092
1055
|
}
|
|
1093
1056
|
if (model.kind === "unit") {
|
|
1094
1057
|
if (normalizedGroup.length === 0 || normalizedGroup.some((output) => !output.provided)) {
|
|
@@ -1119,12 +1082,12 @@ function isComponent(value) {
|
|
|
1119
1082
|
return typeof value === "function" && "model" in value;
|
|
1120
1083
|
}
|
|
1121
1084
|
function isSchemaOptional(schema) {
|
|
1122
|
-
return schema.safeParse(
|
|
1085
|
+
return schema.safeParse(undefined).success;
|
|
1123
1086
|
}
|
|
1124
1087
|
function mapArgument(value, key) {
|
|
1125
1088
|
if ("schema" in value) {
|
|
1126
1089
|
return {
|
|
1127
|
-
schema:
|
|
1090
|
+
schema: z5.toJSONSchema(value.schema, {
|
|
1128
1091
|
target: "draft-7",
|
|
1129
1092
|
io: "input",
|
|
1130
1093
|
unrepresentable: "any"
|
|
@@ -1138,7 +1101,7 @@ function mapArgument(value, key) {
|
|
|
1138
1101
|
};
|
|
1139
1102
|
}
|
|
1140
1103
|
return {
|
|
1141
|
-
schema:
|
|
1104
|
+
schema: z5.toJSONSchema(value, { target: "draft-7", io: "input", unrepresentable: "any" }),
|
|
1142
1105
|
[runtimeSchema]: value,
|
|
1143
1106
|
required: !isSchemaOptional(value),
|
|
1144
1107
|
meta: {
|
|
@@ -1185,9 +1148,7 @@ function createOutputMapper(inputs, entities) {
|
|
|
1185
1148
|
}
|
|
1186
1149
|
const sourceInput = inputs?.[value.fromInput];
|
|
1187
1150
|
if (!sourceInput) {
|
|
1188
|
-
throw new Error(
|
|
1189
|
-
`Output "${key}" references missing input "${value.fromInput}" via fromInput.`
|
|
1190
|
-
);
|
|
1151
|
+
throw new Error(`Output "${key}" references missing input "${value.fromInput}" via fromInput.`);
|
|
1191
1152
|
}
|
|
1192
1153
|
const mappedInput = mapInput(sourceInput, value.fromInput);
|
|
1193
1154
|
return {
|
|
@@ -1205,13 +1166,13 @@ function getInstanceId(instanceType, instanceName) {
|
|
|
1205
1166
|
return `${instanceType}:${instanceName}`;
|
|
1206
1167
|
}
|
|
1207
1168
|
function toFullComponentArgumentOptions(args) {
|
|
1208
|
-
return
|
|
1169
|
+
return mapValues2(args, (arg) => ("schema" in arg) ? arg : { schema: arg });
|
|
1209
1170
|
}
|
|
1210
1171
|
function toFullComponentInputOptions(inputs) {
|
|
1211
|
-
return
|
|
1172
|
+
return mapValues2(inputs, (input) => ("entity" in input) ? input : { entity: input });
|
|
1212
1173
|
}
|
|
1213
1174
|
function toFullComponentOutputOptions(outputs) {
|
|
1214
|
-
return
|
|
1175
|
+
return mapValues2(outputs, (output) => {
|
|
1215
1176
|
if (typeof output !== "object" || output === null) {
|
|
1216
1177
|
return { entity: output };
|
|
1217
1178
|
}
|
|
@@ -1265,244 +1226,19 @@ function $addInputDescription(input, description) {
|
|
|
1265
1226
|
};
|
|
1266
1227
|
}
|
|
1267
1228
|
|
|
1268
|
-
// src/
|
|
1269
|
-
function inputKey(input) {
|
|
1270
|
-
return input.path ? `${input.instanceId}:${input.output}:${input.path}` : `${input.instanceId}:${input.output}`;
|
|
1271
|
-
}
|
|
1272
|
-
var positionSchema = z.object({
|
|
1273
|
-
x: z.number(),
|
|
1274
|
-
y: z.number()
|
|
1275
|
-
});
|
|
1276
|
-
var instanceIdSchema = z.templateLiteral([versionedNameSchema, ":", genericNameSchema]);
|
|
1277
|
-
var instanceInputSchema = z.object({
|
|
1278
|
-
instanceId: instanceIdSchema,
|
|
1279
|
-
output: z.string(),
|
|
1280
|
-
path: z.string().optional()
|
|
1281
|
-
});
|
|
1282
|
-
var hubInputSchema = z.object({
|
|
1283
|
-
hubId: z.string()
|
|
1284
|
-
});
|
|
1285
|
-
var instanceModelPatchSchema = z.object({
|
|
1286
|
-
/**
|
|
1287
|
-
* The static arguments passed to the instance.
|
|
1288
|
-
*/
|
|
1289
|
-
args: z.record(z.string(), z.unknown()).optional(),
|
|
1290
|
-
/**
|
|
1291
|
-
* The direct instances passed as inputs to the instance.
|
|
1292
|
-
*/
|
|
1293
|
-
inputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),
|
|
1294
|
-
/**
|
|
1295
|
-
* The resolved unit inputs for the instance.
|
|
1296
|
-
*
|
|
1297
|
-
* Only for computed composite instances.
|
|
1298
|
-
*/
|
|
1299
|
-
hubInputs: z.record(z.string(), z.array(hubInputSchema)).optional(),
|
|
1300
|
-
/**
|
|
1301
|
-
* The inputs injected to the instance from the hubs.
|
|
1302
|
-
*
|
|
1303
|
-
* While `hubInputs` allows to pass hubs to distinct inputs,
|
|
1304
|
-
* `injectionInputs` allows to pass hubs to the instance as a whole filling all inputs with matching types.
|
|
1305
|
-
*
|
|
1306
|
-
* Only for designer-first instances.
|
|
1307
|
-
*/
|
|
1308
|
-
injectionInputs: z.array(hubInputSchema).optional(),
|
|
1309
|
-
/**
|
|
1310
|
-
* The position of the instance on the canvas.
|
|
1311
|
-
*
|
|
1312
|
-
* Only for designer-first instances.
|
|
1313
|
-
*/
|
|
1314
|
-
position: positionSchema.optional()
|
|
1315
|
-
});
|
|
1316
|
-
var instanceModelSchema = z.object({
|
|
1317
|
-
/**
|
|
1318
|
-
* The id of the instance unique within the project.
|
|
1319
|
-
*
|
|
1320
|
-
* The format is `${instanceType}:${instanceName}`.
|
|
1321
|
-
*/
|
|
1322
|
-
id: instanceIdSchema,
|
|
1323
|
-
/**
|
|
1324
|
-
* The kind of the instance.
|
|
1325
|
-
*
|
|
1326
|
-
* Can be either "unit" or "composite".
|
|
1327
|
-
*/
|
|
1328
|
-
kind: componentKindSchema,
|
|
1329
|
-
/**
|
|
1330
|
-
* The type of the instance.
|
|
1331
|
-
*/
|
|
1332
|
-
type: versionedNameSchema,
|
|
1333
|
-
/**
|
|
1334
|
-
* The name of the instance.
|
|
1335
|
-
*
|
|
1336
|
-
* Must be unique within instances of the same type in the project.
|
|
1337
|
-
*/
|
|
1338
|
-
name: genericNameSchema,
|
|
1339
|
-
...instanceModelPatchSchema.shape,
|
|
1340
|
-
/**
|
|
1341
|
-
* The id of the top level parent instance.
|
|
1342
|
-
*
|
|
1343
|
-
* Only for child instances of the composite instances.
|
|
1344
|
-
*/
|
|
1345
|
-
resolvedInputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),
|
|
1346
|
-
/**
|
|
1347
|
-
* The ID of the parent instance.
|
|
1348
|
-
*
|
|
1349
|
-
* Only for child instances of the composite instances.
|
|
1350
|
-
*/
|
|
1351
|
-
parentId: instanceIdSchema.optional(),
|
|
1352
|
-
/**
|
|
1353
|
-
* The direct instance outputs returned by the instance as outputs.
|
|
1354
|
-
*
|
|
1355
|
-
* Only for computed composite instances.
|
|
1356
|
-
*/
|
|
1357
|
-
outputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),
|
|
1358
|
-
/**
|
|
1359
|
-
* The resolved unit outputs for the instance.
|
|
1360
|
-
*
|
|
1361
|
-
* Only for computed composite instances.
|
|
1362
|
-
*/
|
|
1363
|
-
resolvedOutputs: z.record(z.string(), z.array(instanceInputSchema)).optional()
|
|
1364
|
-
});
|
|
1365
|
-
var hubModelPatchSchema = z.object({
|
|
1366
|
-
/**
|
|
1367
|
-
* The position of the hub on the canvas.
|
|
1368
|
-
*/
|
|
1369
|
-
position: positionSchema.optional(),
|
|
1370
|
-
/**
|
|
1371
|
-
* The inputs of the hub.
|
|
1372
|
-
*/
|
|
1373
|
-
inputs: z.array(instanceInputSchema).optional(),
|
|
1374
|
-
/**
|
|
1375
|
-
* The inputs injected to the hub from the hubs.
|
|
1376
|
-
*
|
|
1377
|
-
* While `inputs` allows to pass hubs to distinct inputs,
|
|
1378
|
-
* `injectionInputs` allows to pass hubs to the hub as a whole filling all inputs with matching types.
|
|
1379
|
-
*/
|
|
1380
|
-
injectionInputs: z.array(hubInputSchema).optional()
|
|
1381
|
-
});
|
|
1382
|
-
var hubModelSchema = z.object({
|
|
1383
|
-
/**
|
|
1384
|
-
* The id of the hub unique within the project.
|
|
1385
|
-
*/
|
|
1386
|
-
id: z.cuid2(),
|
|
1387
|
-
...hubModelPatchSchema.shape
|
|
1388
|
-
});
|
|
1389
|
-
function parseInstanceId(instanceId) {
|
|
1390
|
-
const parts = instanceId.split(":");
|
|
1391
|
-
if (parts.length !== 2) {
|
|
1392
|
-
throw new Error(`Invalid instance ID: ${instanceId}`);
|
|
1393
|
-
}
|
|
1394
|
-
return parts;
|
|
1395
|
-
}
|
|
1396
|
-
function selectInput(inputs, name) {
|
|
1397
|
-
const groupBoundary = inputs[boundaryInput] ?? inputs[0]?.[boundaryInput];
|
|
1398
|
-
if (inputs.length === 0 && !groupBoundary) {
|
|
1399
|
-
throw new Error(
|
|
1400
|
-
`Cannot select input "${name}": empty input group has no boundary metadata to build a missing input reference.`
|
|
1401
|
-
);
|
|
1402
|
-
}
|
|
1403
|
-
const input = inputs.find(
|
|
1404
|
-
(input2) => input2.provided && (input2.instanceId === name || parseInstanceId(input2.instanceId)[1] === name)
|
|
1405
|
-
);
|
|
1406
|
-
if (!input || !input.provided) {
|
|
1407
|
-
const fallbackBoundary = groupBoundary ?? inputs.find((input2) => Boolean(input2[boundaryInput]))?.[boundaryInput] ?? inputs[0]?.[boundaryInput];
|
|
1408
|
-
if (!fallbackBoundary) {
|
|
1409
|
-
throw new Error(
|
|
1410
|
-
`Cannot select input "${name}": input group has no boundary metadata to build a missing input reference.`
|
|
1411
|
-
);
|
|
1412
|
-
}
|
|
1413
|
-
return createNonProvidedInput(fallbackBoundary);
|
|
1414
|
-
}
|
|
1415
|
-
const boundary = groupBoundary ?? input[boundaryInput];
|
|
1416
|
-
return createInput(input, { boundary });
|
|
1417
|
-
}
|
|
1418
|
-
var HighstateSignature = /* @__PURE__ */ ((HighstateSignature2) => {
|
|
1419
|
-
HighstateSignature2["Artifact"] = "d55c63ac-3174-4756-808f-f778e99af0d1";
|
|
1420
|
-
HighstateSignature2["Yaml"] = "c857cac5-caa6-4421-b82c-e561fbce6367";
|
|
1421
|
-
HighstateSignature2["Secret"] = "240e5789-6ae4-4b22-b9d8-87169e8b4bab";
|
|
1422
|
-
return HighstateSignature2;
|
|
1423
|
-
})(HighstateSignature || {});
|
|
1424
|
-
var yamlValueSchema = z.object({
|
|
1425
|
-
["c857cac5-caa6-4421-b82c-e561fbce6367" /* Yaml */]: z.literal(true),
|
|
1426
|
-
value: z.string()
|
|
1427
|
-
});
|
|
1428
|
-
var fileMetaSchema = z.object({
|
|
1429
|
-
name: z.string(),
|
|
1430
|
-
contentType: z.string().optional(),
|
|
1431
|
-
size: z.number().optional(),
|
|
1432
|
-
mode: z.number().optional()
|
|
1433
|
-
});
|
|
1434
|
-
var WellKnownInstanceCustomStatus = /* @__PURE__ */ ((WellKnownInstanceCustomStatus2) => {
|
|
1435
|
-
WellKnownInstanceCustomStatus2["Healthy"] = "healthy";
|
|
1436
|
-
WellKnownInstanceCustomStatus2["Degraded"] = "degraded";
|
|
1437
|
-
WellKnownInstanceCustomStatus2["Down"] = "down";
|
|
1438
|
-
WellKnownInstanceCustomStatus2["Warning"] = "warning";
|
|
1439
|
-
WellKnownInstanceCustomStatus2["Progressing"] = "progressing";
|
|
1440
|
-
WellKnownInstanceCustomStatus2["Error"] = "error";
|
|
1441
|
-
return WellKnownInstanceCustomStatus2;
|
|
1442
|
-
})(WellKnownInstanceCustomStatus || {});
|
|
1443
|
-
var instanceStatusFieldValueSchema = z.union([
|
|
1444
|
-
z.string(),
|
|
1445
|
-
z.number(),
|
|
1446
|
-
z.boolean(),
|
|
1447
|
-
z.string().array()
|
|
1448
|
-
]);
|
|
1449
|
-
var instanceStatusFieldSchema = z.object({
|
|
1450
|
-
name: z.string(),
|
|
1451
|
-
meta: objectMetaSchema.pick({
|
|
1452
|
-
title: true,
|
|
1453
|
-
icon: true,
|
|
1454
|
-
iconColor: true
|
|
1455
|
-
}).required({ title: true }),
|
|
1456
|
-
complementaryTo: z.string().optional(),
|
|
1457
|
-
value: instanceStatusFieldValueSchema.optional()
|
|
1458
|
-
});
|
|
1459
|
-
function secretSchema(schema) {
|
|
1460
|
-
const secretType = z.object({
|
|
1461
|
-
["240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */]: z.literal(true),
|
|
1462
|
-
value: schema
|
|
1463
|
-
});
|
|
1464
|
-
return z.codec(z.union([secretType, schema]), secretType, {
|
|
1465
|
-
decode: (value) => typeof value === "object" && value !== null && "240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */ in value ? value : { ["240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */]: true, value },
|
|
1466
|
-
encode: (value) => value
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
function isSecret(value) {
|
|
1470
|
-
return typeof value === "object" && value !== null && "240e5789-6ae4-4b22-b9d8-87169e8b4bab" /* Secret */ in value;
|
|
1471
|
-
}
|
|
1229
|
+
// src/unit.ts
|
|
1472
1230
|
var componentSecretSchema = componentArgumentSchema.extend({
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
*/
|
|
1476
|
-
readonly: z.boolean(),
|
|
1477
|
-
/**
|
|
1478
|
-
* The secret value is computed by the unit and should not be passed to it when invoked.
|
|
1479
|
-
*/
|
|
1480
|
-
computed: z.boolean()
|
|
1231
|
+
readonly: z6.boolean(),
|
|
1232
|
+
computed: z6.boolean()
|
|
1481
1233
|
});
|
|
1482
|
-
var unitSourceSchema =
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
*
|
|
1486
|
-
* May be both: local monorepo package or a remote NPM package.
|
|
1487
|
-
*/
|
|
1488
|
-
package: z.string(),
|
|
1489
|
-
/**
|
|
1490
|
-
* The path to the unit implementation within the package.
|
|
1491
|
-
*
|
|
1492
|
-
* If not provided, the root of the package is assumed.
|
|
1493
|
-
*/
|
|
1494
|
-
path: z.string().optional()
|
|
1234
|
+
var unitSourceSchema = z6.object({
|
|
1235
|
+
package: z6.string(),
|
|
1236
|
+
path: z6.string().optional()
|
|
1495
1237
|
});
|
|
1496
|
-
var unitModelSchema =
|
|
1238
|
+
var unitModelSchema = z6.object({
|
|
1497
1239
|
...componentModelSchema.shape,
|
|
1498
|
-
/**
|
|
1499
|
-
* The source of the unit.
|
|
1500
|
-
*/
|
|
1501
1240
|
source: unitSourceSchema,
|
|
1502
|
-
|
|
1503
|
-
* The record of the secret specs.
|
|
1504
|
-
*/
|
|
1505
|
-
secrets: z.record(z.string(), componentSecretSchema)
|
|
1241
|
+
secrets: z6.record(z6.string(), componentSecretSchema)
|
|
1506
1242
|
});
|
|
1507
1243
|
function defineUnit(options) {
|
|
1508
1244
|
if (!options.source) {
|
|
@@ -1529,7 +1265,7 @@ function defineUnit(options) {
|
|
|
1529
1265
|
});
|
|
1530
1266
|
try {
|
|
1531
1267
|
component.model.source = options.source ?? {};
|
|
1532
|
-
component.model.secrets =
|
|
1268
|
+
component.model.secrets = mapValues3(options.secrets ?? {}, mapSecret);
|
|
1533
1269
|
} catch (error) {
|
|
1534
1270
|
throw new Error(`Failed to map secrets for unit "${options.type}"`, { cause: error });
|
|
1535
1271
|
}
|
|
@@ -1555,13 +1291,22 @@ function mapSecret(value, key) {
|
|
|
1555
1291
|
function isUnitModel(model) {
|
|
1556
1292
|
return "source" in model;
|
|
1557
1293
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1294
|
+
// src/terminal.ts
|
|
1295
|
+
import { z as z9 } from "zod";
|
|
1296
|
+
|
|
1297
|
+
// src/pulumi.ts
|
|
1298
|
+
import { parse } from "yaml";
|
|
1299
|
+
import { z as z8 } from "zod";
|
|
1300
|
+
|
|
1301
|
+
// src/trigger.ts
|
|
1302
|
+
import { z as z7 } from "zod";
|
|
1303
|
+
var triggerSpecSchema = z7.union([
|
|
1304
|
+
z7.object({
|
|
1305
|
+
type: z7.literal("before-destroy")
|
|
1561
1306
|
})
|
|
1562
1307
|
]);
|
|
1563
|
-
var unitTriggerSchema =
|
|
1564
|
-
name:
|
|
1308
|
+
var unitTriggerSchema = z7.object({
|
|
1309
|
+
name: z7.string(),
|
|
1565
1310
|
meta: objectMetaSchema.pick({
|
|
1566
1311
|
title: true,
|
|
1567
1312
|
globalTitle: true,
|
|
@@ -1569,165 +1314,85 @@ var unitTriggerSchema = z.object({
|
|
|
1569
1314
|
icon: true,
|
|
1570
1315
|
iconColor: true
|
|
1571
1316
|
}).required({ title: true }),
|
|
1572
|
-
/**
|
|
1573
|
-
* The specification of the trigger.
|
|
1574
|
-
*
|
|
1575
|
-
* Defines the type of trigger and its behavior.
|
|
1576
|
-
*/
|
|
1577
1317
|
spec: triggerSpecSchema
|
|
1578
1318
|
});
|
|
1579
|
-
var triggerInvocationSchema =
|
|
1580
|
-
|
|
1581
|
-
* The name of the trigger being invoked.
|
|
1582
|
-
*/
|
|
1583
|
-
name: z.string()
|
|
1319
|
+
var triggerInvocationSchema = z7.object({
|
|
1320
|
+
name: z7.string()
|
|
1584
1321
|
});
|
|
1585
1322
|
|
|
1586
1323
|
// src/pulumi.ts
|
|
1587
|
-
var unitInputSourceSchema =
|
|
1324
|
+
var unitInputSourceSchema = z8.object({
|
|
1588
1325
|
...instanceInputSchema.shape
|
|
1589
1326
|
});
|
|
1590
|
-
var unitInputValueSchema =
|
|
1591
|
-
|
|
1592
|
-
* Inline resolved value passed to the unit.
|
|
1593
|
-
*
|
|
1594
|
-
* The backend is responsible for resolving the correct entity snapshot value
|
|
1595
|
-
* and applying any inclusion transformations.
|
|
1596
|
-
*/
|
|
1597
|
-
value: z.unknown(),
|
|
1598
|
-
/**
|
|
1599
|
-
* Optional provenance of the value.
|
|
1600
|
-
*/
|
|
1327
|
+
var unitInputValueSchema = z8.object({
|
|
1328
|
+
value: z8.unknown(),
|
|
1601
1329
|
source: unitInputSourceSchema.optional()
|
|
1602
1330
|
});
|
|
1603
|
-
var unitConfigSchema =
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* The state ID of the instance.
|
|
1610
|
-
*/
|
|
1611
|
-
stateId: z.string(),
|
|
1612
|
-
/**
|
|
1613
|
-
* The record of argument values for the unit.
|
|
1614
|
-
*/
|
|
1615
|
-
args: z.record(z.string(), z.unknown()),
|
|
1616
|
-
/**
|
|
1617
|
-
* The record of input references for the unit.
|
|
1618
|
-
*/
|
|
1619
|
-
inputs: z.record(z.string(), unitInputValueSchema.array()),
|
|
1620
|
-
/**
|
|
1621
|
-
* The list of triggers that have been invoked for this unit.
|
|
1622
|
-
*/
|
|
1331
|
+
var unitConfigSchema = z8.object({
|
|
1332
|
+
instanceId: z8.string(),
|
|
1333
|
+
stateId: z8.string(),
|
|
1334
|
+
args: z8.record(z8.string(), z8.unknown()),
|
|
1335
|
+
inputs: z8.record(z8.string(), unitInputValueSchema.array()),
|
|
1623
1336
|
invokedTriggers: triggerInvocationSchema.array(),
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
*
|
|
1627
|
-
* It is stored in Pulumi stack config as a secret.
|
|
1628
|
-
*/
|
|
1629
|
-
secretValues: z.record(z.string(), z.unknown()),
|
|
1630
|
-
/**
|
|
1631
|
-
* The base path for imports.
|
|
1632
|
-
* Used to resolve dynamic dependencies in strict environments (like in pnpm node_modules isolation).
|
|
1633
|
-
*/
|
|
1634
|
-
importBasePath: z.string()
|
|
1337
|
+
secretValues: z8.record(z8.string(), z8.unknown()),
|
|
1338
|
+
importBasePath: z8.string()
|
|
1635
1339
|
});
|
|
1636
|
-
var yamlResultCache =
|
|
1340
|
+
var yamlResultCache = new WeakMap;
|
|
1637
1341
|
function parseArgumentValue(value) {
|
|
1638
1342
|
const yamlResult = yamlValueSchema.safeParse(value);
|
|
1639
1343
|
if (!yamlResult.success) {
|
|
1640
1344
|
return value;
|
|
1641
1345
|
}
|
|
1642
1346
|
const existingResult = yamlResultCache.get(value);
|
|
1643
|
-
if (existingResult !==
|
|
1347
|
+
if (existingResult !== undefined) {
|
|
1644
1348
|
return existingResult;
|
|
1645
1349
|
}
|
|
1646
1350
|
const result = parse(yamlResult.data.value);
|
|
1647
1351
|
yamlResultCache.set(value, result);
|
|
1648
1352
|
return result;
|
|
1649
1353
|
}
|
|
1650
|
-
var HighstateConfigKey
|
|
1354
|
+
var HighstateConfigKey;
|
|
1355
|
+
((HighstateConfigKey2) => {
|
|
1651
1356
|
HighstateConfigKey2["Config"] = "highstate";
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
var
|
|
1655
|
-
|
|
1656
|
-
[
|
|
1657
|
-
|
|
1658
|
-
[unitArtifactId]: z.string().optional(),
|
|
1659
|
-
hash: z.string(),
|
|
1357
|
+
})(HighstateConfigKey ||= {});
|
|
1358
|
+
var unitArtifactId = Symbol("unitArtifactId");
|
|
1359
|
+
var unitArtifactSchema = z8.object({
|
|
1360
|
+
["d55c63ac-3174-4756-808f-f778e99af0d1" /* Artifact */]: z8.literal(true),
|
|
1361
|
+
[unitArtifactId]: z8.string().optional(),
|
|
1362
|
+
hash: z8.string(),
|
|
1660
1363
|
meta: commonObjectMetaSchema.optional()
|
|
1661
1364
|
});
|
|
1662
|
-
var fileContentSchema =
|
|
1663
|
-
|
|
1664
|
-
type:
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
*
|
|
1668
|
-
* If true, the `value` will be a base64 encoded string.
|
|
1669
|
-
*/
|
|
1670
|
-
isBinary: z.boolean().optional(),
|
|
1671
|
-
/**
|
|
1672
|
-
* The content of the file.
|
|
1673
|
-
*
|
|
1674
|
-
* If `isBinary` is true, this will be a base64 encoded string.
|
|
1675
|
-
*/
|
|
1676
|
-
value: z.string()
|
|
1365
|
+
var fileContentSchema = z8.union([
|
|
1366
|
+
z8.object({
|
|
1367
|
+
type: z8.literal("embedded"),
|
|
1368
|
+
isBinary: z8.boolean().optional(),
|
|
1369
|
+
value: z8.string()
|
|
1677
1370
|
}),
|
|
1678
|
-
|
|
1679
|
-
type:
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
*
|
|
1683
|
-
* If true, the `value` will be a base64 encoded string.
|
|
1684
|
-
*/
|
|
1685
|
-
isBinary: z.boolean().optional(),
|
|
1686
|
-
/**
|
|
1687
|
-
* The content of the file wrapped as a Highstate secret.
|
|
1688
|
-
*
|
|
1689
|
-
* If `isBinary` is true, this will be a base64 encoded string.
|
|
1690
|
-
*/
|
|
1691
|
-
value: secretSchema(z.string())
|
|
1371
|
+
z8.object({
|
|
1372
|
+
type: z8.literal("embedded-secret"),
|
|
1373
|
+
isBinary: z8.boolean().optional(),
|
|
1374
|
+
value: secretSchema(z8.string())
|
|
1692
1375
|
}),
|
|
1693
|
-
|
|
1694
|
-
type:
|
|
1376
|
+
z8.object({
|
|
1377
|
+
type: z8.literal("artifact"),
|
|
1695
1378
|
...unitArtifactSchema.shape
|
|
1696
1379
|
})
|
|
1697
1380
|
]);
|
|
1698
|
-
var fileSchema =
|
|
1381
|
+
var fileSchema = z8.object({
|
|
1699
1382
|
meta: fileMetaSchema,
|
|
1700
1383
|
content: fileContentSchema
|
|
1701
1384
|
});
|
|
1702
1385
|
|
|
1703
1386
|
// src/terminal.ts
|
|
1704
|
-
var terminalSpecSchema =
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
* The command to run in the terminal.
|
|
1711
|
-
*/
|
|
1712
|
-
command: z.string().array(),
|
|
1713
|
-
/**
|
|
1714
|
-
* The working directory to run the command in.
|
|
1715
|
-
*/
|
|
1716
|
-
cwd: z.string().optional(),
|
|
1717
|
-
/**
|
|
1718
|
-
* The environment variables to set in the terminal.
|
|
1719
|
-
*/
|
|
1720
|
-
env: z.record(z.string(), z.string()).optional(),
|
|
1721
|
-
/**
|
|
1722
|
-
* The files to mount in the terminal.
|
|
1723
|
-
*
|
|
1724
|
-
* The key is the path where the file will be mounted,
|
|
1725
|
-
* and the value is the file content or a reference to an artifact.
|
|
1726
|
-
*/
|
|
1727
|
-
files: z.record(z.string(), fileSchema).optional()
|
|
1387
|
+
var terminalSpecSchema = z9.object({
|
|
1388
|
+
image: z9.string(),
|
|
1389
|
+
command: z9.string().array(),
|
|
1390
|
+
cwd: z9.string().optional(),
|
|
1391
|
+
env: z9.record(z9.string(), z9.string()).optional(),
|
|
1392
|
+
files: z9.record(z9.string(), fileSchema).optional()
|
|
1728
1393
|
});
|
|
1729
|
-
var unitTerminalSchema =
|
|
1730
|
-
name:
|
|
1394
|
+
var unitTerminalSchema = z9.object({
|
|
1395
|
+
name: z9.string(),
|
|
1731
1396
|
meta: objectMetaSchema.pick({
|
|
1732
1397
|
title: true,
|
|
1733
1398
|
globalTitle: true,
|
|
@@ -1737,24 +1402,26 @@ var unitTerminalSchema = z.object({
|
|
|
1737
1402
|
}).required({ title: true }),
|
|
1738
1403
|
spec: terminalSpecSchema
|
|
1739
1404
|
});
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1405
|
+
// src/page.ts
|
|
1406
|
+
import { z as z10 } from "zod";
|
|
1407
|
+
var pageBlockSchema = z10.union([
|
|
1408
|
+
z10.object({
|
|
1409
|
+
type: z10.literal("markdown"),
|
|
1410
|
+
content: z10.string()
|
|
1744
1411
|
}),
|
|
1745
|
-
|
|
1746
|
-
type:
|
|
1747
|
-
content:
|
|
1748
|
-
showContent:
|
|
1749
|
-
language:
|
|
1412
|
+
z10.object({
|
|
1413
|
+
type: z10.literal("qr"),
|
|
1414
|
+
content: z10.string(),
|
|
1415
|
+
showContent: z10.coerce.boolean(),
|
|
1416
|
+
language: z10.string().optional()
|
|
1750
1417
|
}),
|
|
1751
|
-
|
|
1752
|
-
type:
|
|
1418
|
+
z10.object({
|
|
1419
|
+
type: z10.literal("file"),
|
|
1753
1420
|
file: fileSchema
|
|
1754
1421
|
})
|
|
1755
1422
|
]);
|
|
1756
|
-
var unitPageSchema =
|
|
1757
|
-
name:
|
|
1423
|
+
var unitPageSchema = z10.object({
|
|
1424
|
+
name: z10.string(),
|
|
1758
1425
|
meta: objectMetaSchema.pick({
|
|
1759
1426
|
title: true,
|
|
1760
1427
|
globalTitle: true,
|
|
@@ -1764,52 +1431,105 @@ var unitPageSchema = z.object({
|
|
|
1764
1431
|
}).required({ title: true }),
|
|
1765
1432
|
content: pageBlockSchema.array()
|
|
1766
1433
|
});
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1434
|
+
// src/worker.ts
|
|
1435
|
+
import { z as z11 } from "zod";
|
|
1436
|
+
var unitWorkerSchema = z11.object({
|
|
1437
|
+
name: z11.string(),
|
|
1438
|
+
image: z11.string(),
|
|
1439
|
+
params: z11.record(z11.string(), z11.unknown())
|
|
1440
|
+
});
|
|
1441
|
+
var workerRunOptionsSchema = z11.object({
|
|
1442
|
+
projectId: z11.cuid2(),
|
|
1443
|
+
workerVersionId: z11.cuid2(),
|
|
1444
|
+
workerInstanceId: z11.cuid2(),
|
|
1445
|
+
apiUrl: z11.url(),
|
|
1446
|
+
dataEndpoint: z11.string().min(1),
|
|
1447
|
+
apiKey: z11.string()
|
|
1448
|
+
});
|
|
1449
|
+
// src/runtime.ts
|
|
1450
|
+
import { z as z12 } from "zod";
|
|
1451
|
+
var runtimeConfigGetInputSchema = z12.void();
|
|
1452
|
+
var runtimeConfigGetOutputSchema = unitConfigSchema;
|
|
1453
|
+
var runtimeResultSubmitInputSchema = z12.record(z12.string(), z12.unknown());
|
|
1454
|
+
var runtimeResultSubmitOutputSchema = z12.object({});
|
|
1455
|
+
var runtimeSidecarFileSchema = z12.object({
|
|
1456
|
+
path: z12.string(),
|
|
1457
|
+
content: z12.string(),
|
|
1458
|
+
secret: z12.boolean().default(false),
|
|
1459
|
+
mode: z12.number().int().optional()
|
|
1460
|
+
});
|
|
1461
|
+
var runtimeSidecarPortSchema = z12.object({
|
|
1462
|
+
name: z12.string(),
|
|
1463
|
+
containerPort: z12.number().int().positive().max(65535),
|
|
1464
|
+
protocol: z12.literal("tcp").default("tcp")
|
|
1465
|
+
});
|
|
1466
|
+
var runtimeSidecarReadinessSchema = z12.discriminatedUnion("type", [
|
|
1467
|
+
z12.object({
|
|
1468
|
+
type: z12.literal("tcp"),
|
|
1469
|
+
port: z12.string(),
|
|
1470
|
+
timeoutSeconds: z12.number().int().positive().default(30)
|
|
1471
|
+
}),
|
|
1472
|
+
z12.object({
|
|
1473
|
+
type: z12.literal("http"),
|
|
1474
|
+
port: z12.string(),
|
|
1475
|
+
path: z12.string(),
|
|
1476
|
+
statuses: z12.number().int().positive().array().default([200]),
|
|
1477
|
+
timeoutSeconds: z12.number().int().positive().default(30)
|
|
1478
|
+
}),
|
|
1479
|
+
z12.object({
|
|
1480
|
+
type: z12.literal("log"),
|
|
1481
|
+
pattern: z12.string(),
|
|
1482
|
+
timeoutSeconds: z12.number().int().positive().default(30)
|
|
1483
|
+
})
|
|
1484
|
+
]);
|
|
1485
|
+
var runtimeSidecarStartInputSchema = z12.object({
|
|
1486
|
+
identity: z12.string().regex(/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/),
|
|
1487
|
+
image: z12.string(),
|
|
1488
|
+
command: z12.string().array().optional(),
|
|
1489
|
+
args: z12.string().array().default([]),
|
|
1490
|
+
env: z12.record(z12.string(), z12.string()).default({}),
|
|
1491
|
+
files: runtimeSidecarFileSchema.array().default([]),
|
|
1492
|
+
ports: runtimeSidecarPortSchema.array().default([]),
|
|
1493
|
+
readiness: runtimeSidecarReadinessSchema.optional()
|
|
1771
1494
|
});
|
|
1772
|
-
var
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
*/
|
|
1780
|
-
workerVersionId: z.cuid2(),
|
|
1781
|
-
/**
|
|
1782
|
-
* The URL of the backend API to connect to.
|
|
1783
|
-
*/
|
|
1784
|
-
apiUrl: z.url(),
|
|
1785
|
-
/**
|
|
1786
|
-
* The API key used to authenticate the worker with the backend.
|
|
1787
|
-
*/
|
|
1788
|
-
apiKey: z.string()
|
|
1495
|
+
var runtimeSidecarStartOutputSchema = z12.object({
|
|
1496
|
+
id: z12.string(),
|
|
1497
|
+
host: z12.string(),
|
|
1498
|
+
ports: z12.record(z12.string(), z12.object({
|
|
1499
|
+
host: z12.string(),
|
|
1500
|
+
port: z12.number().int().positive().max(65535)
|
|
1501
|
+
}))
|
|
1789
1502
|
});
|
|
1503
|
+
// src/utils.ts
|
|
1504
|
+
import { isNonNullish as isNonNullish2, pickBy as pickBy2 } from "remeda";
|
|
1790
1505
|
function text(strings, ...values) {
|
|
1791
1506
|
const stringValues = values.map(String);
|
|
1792
1507
|
let result = "";
|
|
1793
|
-
for (let i = 0;
|
|
1508
|
+
for (let i = 0;i < strings.length; i++) {
|
|
1794
1509
|
result += strings[i];
|
|
1795
1510
|
if (i < stringValues.length) {
|
|
1796
1511
|
const value = stringValues[i];
|
|
1797
|
-
const lines = value.split(
|
|
1512
|
+
const lines = value.split(`
|
|
1513
|
+
`);
|
|
1798
1514
|
const lastLineIndentMatch = strings[i].match(/(?:^|\n)([ \t]*)$/);
|
|
1799
1515
|
const indent = lastLineIndentMatch ? lastLineIndentMatch[1] : "";
|
|
1800
|
-
result += lines.map((line, j) => j === 0 ? line : indent + line).join(
|
|
1516
|
+
result += lines.map((line, j) => j === 0 ? line : indent + line).join(`
|
|
1517
|
+
`);
|
|
1801
1518
|
}
|
|
1802
1519
|
}
|
|
1803
1520
|
return trimIndentation(result);
|
|
1804
1521
|
}
|
|
1805
1522
|
function trimIndentation(text2) {
|
|
1806
|
-
const lines = text2.split(
|
|
1523
|
+
const lines = text2.split(`
|
|
1524
|
+
`);
|
|
1807
1525
|
const indent = lines.filter((line) => line.trim() !== "").map((line) => line.match(/^\s*/)?.[0].length ?? 0).reduce((min, indent2) => Math.min(min, indent2), Infinity);
|
|
1808
|
-
return lines.map((line) => line.slice(indent)).join(
|
|
1526
|
+
return lines.map((line) => line.slice(indent)).join(`
|
|
1527
|
+
`).trim();
|
|
1809
1528
|
}
|
|
1810
1529
|
function bytesToHumanReadable(bytes) {
|
|
1811
1530
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
1812
|
-
if (bytes === 0)
|
|
1531
|
+
if (bytes === 0)
|
|
1532
|
+
return "0 Bytes";
|
|
1813
1533
|
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
1814
1534
|
return `${parseFloat((bytes / 1024 ** i).toFixed(2))} ${sizes[i]}`;
|
|
1815
1535
|
}
|
|
@@ -1818,7 +1538,7 @@ function check(schema, value) {
|
|
|
1818
1538
|
}
|
|
1819
1539
|
function getOrCreate(map, key, createFn) {
|
|
1820
1540
|
const existing = map.get(key);
|
|
1821
|
-
if (existing !==
|
|
1541
|
+
if (existing !== undefined) {
|
|
1822
1542
|
return existing;
|
|
1823
1543
|
}
|
|
1824
1544
|
const value = createFn(key);
|
|
@@ -1826,9 +1546,110 @@ function getOrCreate(map, key, createFn) {
|
|
|
1826
1546
|
return value;
|
|
1827
1547
|
}
|
|
1828
1548
|
function stripNullish(obj) {
|
|
1829
|
-
return
|
|
1549
|
+
return pickBy2(obj, isNonNullish2);
|
|
1830
1550
|
}
|
|
1831
1551
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1552
|
+
// src/index.ts
|
|
1553
|
+
import { z as z13 } from "zod";
|
|
1554
|
+
export {
|
|
1555
|
+
z13 as z,
|
|
1556
|
+
yamlValueSchema,
|
|
1557
|
+
workerRunOptionsSchema,
|
|
1558
|
+
versionedNameSchema,
|
|
1559
|
+
unitWorkerSchema,
|
|
1560
|
+
unitTriggerSchema,
|
|
1561
|
+
unitTerminalSchema,
|
|
1562
|
+
unitSourceSchema,
|
|
1563
|
+
unitPageSchema,
|
|
1564
|
+
unitModelSchema,
|
|
1565
|
+
unitInputValueSchema,
|
|
1566
|
+
unitInputSourceSchema,
|
|
1567
|
+
unitConfigSchema,
|
|
1568
|
+
unitArtifactSchema,
|
|
1569
|
+
unitArtifactId,
|
|
1570
|
+
trimIndentation,
|
|
1571
|
+
triggerSpecSchema,
|
|
1572
|
+
triggerInvocationSchema,
|
|
1573
|
+
timestampsSchema,
|
|
1574
|
+
text,
|
|
1575
|
+
terminalSpecSchema,
|
|
1576
|
+
stripNullish,
|
|
1577
|
+
setValidationEnabled,
|
|
1578
|
+
serviceAccountMetaSchema,
|
|
1579
|
+
selectInput,
|
|
1580
|
+
secretSchema,
|
|
1581
|
+
runtimeSidecarStartOutputSchema,
|
|
1582
|
+
runtimeSidecarStartInputSchema,
|
|
1583
|
+
runtimeSidecarReadinessSchema,
|
|
1584
|
+
runtimeSidecarPortSchema,
|
|
1585
|
+
runtimeSidecarFileSchema,
|
|
1586
|
+
runtimeSchema,
|
|
1587
|
+
runtimeResultSubmitOutputSchema,
|
|
1588
|
+
runtimeResultSubmitInputSchema,
|
|
1589
|
+
runtimeConfigGetOutputSchema,
|
|
1590
|
+
runtimeConfigGetInputSchema,
|
|
1591
|
+
resetEvaluation,
|
|
1592
|
+
registerKnownAbbreviations,
|
|
1593
|
+
positionSchema,
|
|
1594
|
+
parseVersionedName,
|
|
1595
|
+
parseInstanceId,
|
|
1596
|
+
parseArgumentValue,
|
|
1597
|
+
pageBlockSchema,
|
|
1598
|
+
originalCreate,
|
|
1599
|
+
objectMetaSchema,
|
|
1600
|
+
objectEntity,
|
|
1601
|
+
kind,
|
|
1602
|
+
isUnitModel,
|
|
1603
|
+
isSecret,
|
|
1604
|
+
isEntity,
|
|
1605
|
+
isComponent,
|
|
1606
|
+
isAssignableTo,
|
|
1607
|
+
instanceStatusFieldValueSchema,
|
|
1608
|
+
instanceStatusFieldSchema,
|
|
1609
|
+
instanceModelSchema,
|
|
1610
|
+
instanceModelPatchSchema,
|
|
1611
|
+
instanceInputSchema,
|
|
1612
|
+
instanceIdSchema,
|
|
1613
|
+
inputKey,
|
|
1614
|
+
hubModelSchema,
|
|
1615
|
+
hubModelPatchSchema,
|
|
1616
|
+
hubInputSchema,
|
|
1617
|
+
globalCommonObjectMetaSchema,
|
|
1618
|
+
getRuntimeInstances,
|
|
1619
|
+
getOrCreate,
|
|
1620
|
+
getInstanceId,
|
|
1621
|
+
getEntityId,
|
|
1622
|
+
genericNameSchema,
|
|
1623
|
+
fileSchema,
|
|
1624
|
+
fileMetaSchema,
|
|
1625
|
+
fileContentSchema,
|
|
1626
|
+
fieldNameSchema,
|
|
1627
|
+
entityModelSchema,
|
|
1628
|
+
defineUnit,
|
|
1629
|
+
defineEntity,
|
|
1630
|
+
defineComponent,
|
|
1631
|
+
cuidv2d,
|
|
1632
|
+
createNonProvidedInput,
|
|
1633
|
+
createInput,
|
|
1634
|
+
componentSecretSchema,
|
|
1635
|
+
componentModelSchema,
|
|
1636
|
+
componentKindSchema,
|
|
1637
|
+
componentInputSchema,
|
|
1638
|
+
componentArgumentSchema,
|
|
1639
|
+
commonObjectMetaSchema,
|
|
1640
|
+
clearKnownAbbreviations,
|
|
1641
|
+
check,
|
|
1642
|
+
camelCaseToHumanReadable,
|
|
1643
|
+
bytesToHumanReadable,
|
|
1644
|
+
boundaryInput,
|
|
1645
|
+
WellKnownInstanceCustomStatus,
|
|
1646
|
+
InstanceNameConflictError,
|
|
1647
|
+
HighstateSignature,
|
|
1648
|
+
HighstateConfigKey,
|
|
1649
|
+
$secrets,
|
|
1650
|
+
$outputs,
|
|
1651
|
+
$inputs,
|
|
1652
|
+
$args,
|
|
1653
|
+
$addInputDescription,
|
|
1654
|
+
$addArgumentDescription
|
|
1655
|
+
};
|