@highstate/contract 0.19.1 → 0.20.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 +682 -426
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/component.spec.ts +912 -3
- package/src/component.ts +524 -89
- package/src/cuidv2d.spec.ts +39 -0
- package/src/cuidv2d.ts +54 -0
- package/src/entity.ts +321 -81
- package/src/evaluation.ts +62 -12
- package/src/index.ts +9 -1
- package/src/instance-input.ts +219 -0
- package/src/instance.ts +307 -65
- package/src/json-schema.ts +115 -0
- package/src/pulumi.ts +45 -16
- package/src/unit.ts +26 -10
- package/src/compaction.spec.ts +0 -215
- package/src/compaction.ts +0 -381
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/i18n.ts","../src/meta.ts","../src/entity.ts","../src/evaluation.ts","../src/component.ts","../src/instance.ts","../src/unit.ts","../src/trigger.ts","../src/pulumi.ts","../src/terminal.ts","../src/page.ts","../src/worker.ts","../src/compaction.ts","../src/utils.ts"],"names":["text","z","outputs","mapValues","inputs","HighstateSignature","WellKnownInstanceCustomStatus","HighstateConfigKey","visitedIds","indent","pickBy","isNonNullish"],"mappings":";;;;;;;;AAAA,IAAM,qBAAA,uBAA4B,GAAA,EAAoB;AAE/C,SAAS,2BAA2B,aAAA,EAAyB;AAClE,EAAA,KAAA,MAAW,QAAQ,aAAA,EAAe;AAChC,IAAA,MAAM,KAAA,GAAQ,KAAK,WAAA,EAAY;AAC/B,IAAA,IAAI,CAAC,qBAAA,CAAsB,GAAA,CAAI,KAAK,CAAA,EAAG;AACrC,MAAA,qBAAA,CAAsB,GAAA,CAAI,OAAO,IAAI,CAAA;AAAA,IACvC;AAAA,EACF;AACF;AAEO,SAAS,uBAAA,GAA0B;AACxC,EAAA,qBAAA,CAAsB,KAAA,EAAM;AAC9B;AAEO,SAAS,yBAAyBA,KAAAA,EAAc;AAGrD,E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AAA,CAAI,KAAK,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,IAAI,CAAC,CAAA;AACrD,EAAA,OAAO,CAAA,EAAG,UAAA,CAAA,CAAY,KAAA,GAAQ,IAAA,IAAQ,CAAA,EAAG,OAAA,CAAQ,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAClE;AASO,SAAS,KAAA,CACd,QACA,KAAA,EAC2B;AAC3B,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA,CAAE,OAAA;AACjC;AAUO,SAAS,WAAA,CACd,GAAA,EACA,GAAA,EACA,QAAA,EACQ;AACR,EAAA,MAAM,QAAA,GAAW,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AAC5B,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,MAAM,KAAA,GAAQ,SAAS,GAAG,CAAA;AAC1B,EAAA,GAAA,CAAI,GAAA,CAAI,KAAK,KAAK,CAAA;AAClB,EAAA,OAAO,KAAA;AACT;AAQO,SAAS,aAAgD,GAAA,EAAQ;AACtE,EAAA,OAAOC,MAAAA,CAAO,KAAKC,YAAY,CAAA;AACjC","file":"index.js","sourcesContent":["const knownAbbreviationsMap = new Map<string, string>()\n\nexport function registerKnownAbbreviations(abbreviations: string[]) {\n for (const abbr of abbreviations) {\n const lower = abbr.toLowerCase()\n if (!knownAbbreviationsMap.has(lower)) {\n knownAbbreviationsMap.set(lower, abbr)\n }\n }\n}\n\nexport function clearKnownAbbreviations() {\n knownAbbreviationsMap.clear()\n}\n\nexport function camelCaseToHumanReadable(text: string) {\n // split on: word boundaries between consecutive uppercase and lowercase letters,\n // single uppercase letters followed by lowercase, and separators\n const words = text\n .split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|_|-|\\./)\n .filter(word => word.length > 0)\n\n return words\n .map(word => {\n const lower = word.toLowerCase()\n if (knownAbbreviationsMap.has(lower)) {\n return knownAbbreviationsMap.get(lower)\n }\n\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join(\" \")\n}\n","import { z } from \"zod\"\n\nexport const objectMetaSchema = z.object({\n /**\n * Human-readable name of the object.\n *\n * Used in UI components for better user experience.\n */\n title: z.string().optional(),\n\n /**\n * The title used globally for the object.\n *\n * For example, the title of an instance secret is \"Password\" which is okay\n * to display in the instance secret list, but when the secret is displayed in a\n * global secret list the name should be more descriptive, like \"Proxmox Password\".\n */\n globalTitle: z.string().optional(),\n\n /**\n * Description of the object.\n *\n * Provides additional context for users and developers.\n */\n description: z.string().optional(),\n\n /**\n * The color of the object.\n *\n * Used in UI components to visually distinguish objects.\n */\n color: z.string().optional(),\n\n /**\n * Primary icon identifier.\n *\n * Should reference a iconify icon name, like \"mdi:server\" or \"gg:remote\".\n */\n icon: z.string().optional(),\n\n /**\n * The color of the primary icon.\n */\n iconColor: z.string().optional(),\n\n /**\n * The URL of the custom image that should be used as the icon or avatar.\n */\n avatarUrl: z.string().optional(),\n\n /**\n * The secondary icon identifier.\n *\n * Used to provide additional context or actions related to the object.\n *\n * Should reference a iconify icon name, like \"mdi:edit\" or \"mdi:delete\".\n */\n secondaryIcon: z.string().optional(),\n\n /**\n * The color of the secondary icon.\n */\n secondaryIconColor: z.string().optional(),\n})\n\n/**\n * The schema for object metadata used in more than a half of the Highstate objects.\n *\n * Consists of `title`, `description`, `icon`, and `iconColor` fields where the `title` is required.\n */\nexport const commonObjectMetaSchema = objectMetaSchema\n .pick({\n title: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({\n title: true,\n })\n\nexport const globalCommonObjectMetaSchema = objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({\n title: true,\n })\n\nexport const serviceAccountMetaSchema = objectMetaSchema\n .pick({\n title: true,\n description: true,\n avatarUrl: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true })\n\nexport const timestampsSchema = z.object({\n /**\n * The timestamp when the object was created.\n */\n createdAt: z.date(),\n\n /**\n * The timestamp when the object was last updated.\n */\n updatedAt: z.date(),\n})\n\n/**\n * The schema for strings that represent names in Highstate.\n *\n * The name:\n * - must be alphanumeric;\n * - can include dashes (`-`) as word separators and dots (`.`) as namespace separators;\n * - must begin with a letter;\n * - must be lowercase;\n * - must include from 2 to 64 characters.\n */\nexport const genericNameSchema = z\n .string()\n .regex(\n /^[a-z][a-z0-9-.]+$/,\n \"Name must start with a letter and can only contain lowercase letters, numbers, dashes (-) and dots (.)\",\n )\n .min(2)\n .max(64)\n\nexport const versionedNameSchema = z.union([\n z.templateLiteral([genericNameSchema, z.literal(\".\"), z.literal(\"v\"), z.number().int().min(1)]),\n\n // to prevent TypeScript matching \"proxmox.virtual-machine.v2\" as\n // 1. \"proxmox.v\"\n // 2. \"irtual-machine.v2\" and thinking it should be a number\n z.templateLiteral([\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n z.literal(\"v\"),\n z.number().int().min(1),\n ]),\n z.templateLiteral([\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n z.literal(\"v\"),\n z.number().int().min(1),\n ]),\n])\n\n/**\n * Parses a versioned name into its base name and version.\n *\n * @param name The versioned name to parse.\n * @returns A tuple containing the base name and version number.\n * @throws If the name is not in the correct format or if the version is invalid.\n */\nexport function parseVersionedName(name: string): [name: string, version: number] {\n const lastDotVIndex = name.lastIndexOf(\".v\")\n if (lastDotVIndex === -1) {\n throw new Error(`Invalid versioned name: ${name}`)\n }\n\n const baseName = name.substring(0, lastDotVIndex)\n const versionPart = name.substring(lastDotVIndex + 2) // +2 to skip \".v\"\n\n const version = parseInt(versionPart, 10)\n if (Number.isNaN(version) || version < 0) {\n throw new Error(`Invalid version in versioned name: ${name}`)\n }\n\n return [baseName, version]\n}\n\n/**\n * The schema for field names in Highstate.\n *\n * The field name:\n * - must be alphanumeric;\n * - must be in camelCase;\n * - must begin with a letter;\n * - must include from 2 to 64 characters.\n */\nexport const fieldNameSchema = z\n .string()\n .regex(/^[a-z][a-zA-Z0-9]+$/, \"Field name must start with a letter and be in camelCase format\")\n .min(2)\n .max(64)\n\nexport type ObjectMeta = z.infer<typeof objectMetaSchema>\nexport type CommonObjectMeta = z.infer<typeof commonObjectMetaSchema>\nexport type GlobalCommonObjectMeta = z.infer<typeof globalCommonObjectMetaSchema>\nexport type ServiceAccountMeta = z.infer<typeof serviceAccountMetaSchema>\nexport type GenericName = z.infer<typeof genericNameSchema>\nexport type VersionedName = z.infer<typeof versionedNameSchema>\nexport type FieldName = z.infer<typeof fieldNameSchema>\n","import type { IsEmptyObject, Simplify } from \"type-fest\"\nimport type { PartialKeys } from \"./utils\"\nimport { z } from \"zod\"\nimport { camelCaseToHumanReadable } from \"./i18n\"\nimport {\n objectMetaSchema,\n parseVersionedName,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\nexport const entityInclusionSchema = z.object({\n /**\n * The static type of the included entity.\n */\n type: versionedNameSchema,\n\n /**\n * Whether the included entity is required.\n * If false, the entity may be omitted.\n */\n required: z.boolean(),\n\n /**\n * Whether the included entity is multiple.\n */\n multiple: z.boolean(),\n\n /**\n * The name of the field where the included entity is embedded.\n */\n field: z.string(),\n})\n\n/**\n * The entity is some abstract object which can be passed from one component to another through their inputs and outputs.\n * Every entity must have a type.\n * Every component inputs and outputs will reference such types and only entities of the same type can be passed.\n */\nexport const entityModelSchema = z.object({\n /**\n * The static type of the entity.\n */\n type: versionedNameSchema,\n\n /**\n * The list of all extended entity types (direct and indirect).\n */\n extensions: z.string().array().optional(),\n\n /**\n * The list of directly extended entity types.\n */\n directExtensions: z.string().array().optional(),\n\n /**\n * The list of all included entities (directly or inherited from extensions).\n */\n inclusions: entityInclusionSchema.array().optional(),\n\n /**\n * The list of directly included entities.\n */\n directInclusions: entityInclusionSchema.array().optional(),\n\n /**\n * The JSON schema of the entity value.\n */\n schema: z.custom<z.core.JSONSchema.BaseSchema>(),\n\n /**\n * The extra metadata of the entity.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n }),\n\n /**\n * The CRC32 of the entity definition.\n */\n definitionHash: z.number(),\n})\n\nexport type EntityInclusion = z.infer<typeof entityInclusionSchema>\nexport type EntityModel = z.infer<typeof entityModelSchema>\nexport type EntityTypes = Record<VersionedName, true>\n\nexport declare const implementedTypes: unique symbol\n\nexport type Entity<\n TType extends VersionedName = VersionedName,\n TImplementedTypes extends EntityTypes = EntityTypes,\n TSchema extends z.ZodTypeAny = z.ZodTypeAny,\n> = {\n /**\n * The static type of the entity.\n */\n type: TType\n\n /**\n * The all types implemented by this entity including its own type.\n *\n * Does not exist at runtime.\n */\n [implementedTypes]: TImplementedTypes\n\n /**\n * The zod schema of the entity value.\n */\n schema: TSchema\n\n /**\n * The model of the entity.\n */\n model: EntityModel\n}\n\ntype EntityOptions<\n TType extends VersionedName,\n TSchema extends z.ZodType,\n TExtends extends Record<string, Entity>,\n TIncludes extends Record<string, EntityIncludeRef>,\n> = {\n /**\n * The static type of the entity.\n */\n type: TType\n\n /**\n * The JSON schema of the entity value.\n */\n schema: TSchema\n\n /**\n * The extra metadata of the entity.\n */\n meta?: PartialKeys<z.infer<typeof objectMetaSchema>, \"title\">\n\n /**\n * The list of entities to extend.\n *\n * The intersection of them will be used as the base schema and then intersected again with the provided schema.\n *\n * Note: Intersection does not mean inheritance or blind property merging.\n * If two base types have field with the same name but different types,\n * the resulting type of the field will be the intersection of the two types (and most likely `never`).\n */\n extends?: TExtends\n\n /**\n * The list of entities to include.\n *\n * Inclusion is more powerful mechanism that allows to embed other entities into this entity\n * and then substitute them instead of this entity when connected to component inputs of included types.\n */\n includes?: TIncludes\n}\n\nexport type EntityIncludeRef = Entity | { entity: Entity; multiple?: boolean; required?: boolean }\n\nfunction isEntityIncludeRef(\n value: EntityIncludeRef,\n): value is { entity: Entity; multiple?: boolean; required?: boolean } {\n return typeof value === \"object\" && value !== null && \"entity\" in value\n}\n\ntype InclusionShape<TImplements extends Record<string, EntityIncludeRef>> = {\n [K in keyof TImplements]: TImplements[K] extends {\n entity: infer E\n multiple?: infer M\n required?: infer R\n }\n ? E extends Entity\n ? M extends true\n ? R extends false\n ? z.ZodOptional<z.ZodArray<E[\"schema\"]>>\n : z.ZodArray<E[\"schema\"]>\n : R extends false\n ? z.ZodOptional<E[\"schema\"]>\n : E[\"schema\"]\n : never\n : TImplements[K] extends Entity\n ? TImplements[K][\"schema\"]\n : never\n}\n\ntype AddSchemaExtensions<\n TSchema extends z.ZodTypeAny,\n TExtends extends Record<string, Entity>,\n> = TExtends extends Record<string, never>\n ? TSchema\n : IsEmptyObject<TExtends> extends true\n ? TSchema\n : {\n [K in keyof TExtends]: AddSchemaExtensions<\n z.ZodIntersection<TSchema, TExtends[K][\"schema\"]>,\n Omit<TExtends, K>\n >\n }[keyof TExtends]\n\ntype AddTypeExtensions<\n TImplementedTypes extends EntityTypes,\n TExtends extends Record<string, Entity>,\n> = TExtends extends Record<string, never>\n ? TImplementedTypes\n : IsEmptyObject<TExtends> extends true\n ? TImplementedTypes\n : {\n [K in keyof TExtends]: AddTypeExtensions<\n TImplementedTypes & TExtends[K][typeof implementedTypes],\n Omit<TExtends, K>\n >\n }[keyof TExtends]\n\ntype AddSchemaInclusions<\n TSchema extends z.ZodTypeAny,\n TImplements extends Record<string, EntityIncludeRef>,\n> = TImplements extends Record<string, never>\n ? TSchema\n : z.ZodIntersection<TSchema, z.ZodObject<InclusionShape<TImplements>>>\n\ntype AddTypeInclusions<\n TImplementedTypes extends EntityTypes,\n TImplements extends Record<string, EntityIncludeRef>,\n> = TImplements extends Record<string, never>\n ? TImplementedTypes\n : {\n [K in keyof TImplements]: TImplements[K] extends {\n entity: infer E\n }\n ? E extends Entity\n ? AddTypeInclusions<TImplementedTypes & E[typeof implementedTypes], Omit<TImplements, K>>\n : TImplementedTypes\n : TImplements[K] extends Entity\n ? AddTypeInclusions<\n TImplementedTypes & TImplements[K][typeof implementedTypes],\n Omit<TImplements, K>\n >\n : TImplementedTypes\n }[keyof TImplements]\n\nexport function defineEntity<\n TType extends VersionedName,\n TSchema extends z.ZodType,\n TExtends extends Record<string, Entity> = Record<string, never>,\n TImplements extends Record<string, EntityIncludeRef> = Record<string, never>,\n>(\n options: EntityOptions<TType, TSchema, TExtends, TImplements>,\n): Entity<\n TType,\n Simplify<AddTypeInclusions<AddTypeExtensions<{ [K in TType]: true }, TExtends>, TImplements>>,\n AddSchemaExtensions<AddSchemaInclusions<TSchema, TImplements>, TExtends>\n> {\n try {\n entityModelSchema.shape.type.parse(options.type)\n } catch (error) {\n throw new Error(`Invalid entity type \"${options.type}\"`, { cause: error })\n }\n\n if (!options.schema) {\n throw new Error(\"Entity schema is required\")\n }\n\n const includedEntities = Object.entries(options.includes ?? {}).map(([field, entityRef]) => {\n if (isEntityIncludeRef(entityRef)) {\n return {\n entity: entityRef.entity,\n inclusion: {\n type: entityRef.entity.type,\n required: entityRef.required ?? true,\n multiple: entityRef.multiple ?? false,\n field,\n },\n }\n }\n\n return {\n entity: entityRef,\n inclusion: {\n type: entityRef.type,\n required: true,\n multiple: false,\n field,\n },\n }\n })\n\n const inclusionShape = includedEntities.reduce(\n (shape, { entity, inclusion }) => {\n if (inclusion.multiple) {\n shape[inclusion.field] = inclusion.required\n ? entity.schema.array()\n : entity.schema.array().optional()\n } else {\n shape[inclusion.field] = inclusion.required ? entity.schema : entity.schema.optional()\n }\n\n return shape\n },\n {} as Record<string, z.ZodTypeAny>,\n )\n\n let finalSchema = Object.values(options.extends ?? {}).reduce(\n (schema, entity) => z.intersection(schema, entity.schema),\n options.schema as z.ZodType,\n )\n\n if (includedEntities.length > 0) {\n finalSchema = z.intersection(finalSchema, z.object(inclusionShape))\n }\n\n const directInclusions = includedEntities.map(({ inclusion }) => inclusion)\n const directExtensions = Object.values(options.extends ?? {}).map(entity => entity.type)\n\n const inclusions = Object.values(options.extends ?? {}).reduce(\n (incs, entity) => {\n if (entity.model.inclusions) {\n incs.push(...entity.model.inclusions)\n }\n\n return incs\n },\n [...directInclusions],\n )\n\n const extensions = Object.values(options.extends ?? {}).reduce((exts, entity) => {\n exts.push(...(entity.model.extensions ?? []), entity.type)\n\n return exts\n }, [] as string[])\n\n try {\n let _schema: z.core.JSONSchema.BaseSchema\n\n return {\n type: options.type,\n schema: finalSchema,\n model: {\n type: options.type,\n extensions: extensions.length > 0 ? extensions : undefined,\n directExtensions: directExtensions.length > 0 ? directExtensions : undefined,\n inclusions: inclusions.length > 0 ? inclusions : undefined,\n directInclusions: directInclusions.length > 0 ? directInclusions : undefined,\n get schema() {\n if (!_schema) {\n // TODO: forbid unrepresentable types (and find way to filter out \"undefined\" literals)\n _schema = z.toJSONSchema(finalSchema, { target: \"draft-7\", unrepresentable: \"any\" })\n }\n\n return _schema\n },\n meta: {\n ...options.meta,\n title:\n options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0]),\n },\n // will be calculated by the library loader\n definitionHash: null!,\n },\n // biome-ignore lint/suspicious/noExplicitAny: we already typed return type\n } as any\n } catch (error) {\n throw new Error(`Failed to define entity \"${options.type}\"`, { cause: error })\n }\n}\n\nexport function isEntity(value: unknown): value is Entity {\n return typeof value === \"object\" && value !== null && \"model\" in value\n}\n\n/**\n * Checks whether the given entity can be assigned to the target type.\n *\n * An entity is considered assignable to a target type if:\n * - The entity's type is exactly the same as the target type.\n * - The entity extends the target type (either directly or indirectly).\n * - The entity includes the target type (either directly or indirectly).\n *\n * @param entity The entity to check.\n * @param target The target versioned name to check against.\n * @returns True if the entity is assignable to the target type, false otherwise.\n */\nexport function isAssignableTo(entity: EntityModel, target: VersionedName): boolean {\n if (entity.type === target) {\n return true\n }\n\n if (entity.extensions?.includes(target)) {\n return true\n }\n\n return entity.inclusions?.some(implementation => implementation.type === target) ?? false\n}\n","import type { Component } from \"./component\"\nimport type { InstanceInput, InstanceModel } from \"./instance\"\nimport { mapValues } from \"remeda\"\n\nexport type RuntimeInstance = {\n instance: InstanceModel\n component: Component\n}\n\nexport const boundaryInput = Symbol(\"boundaryInput\")\nexport const boundaryInputs = Symbol(\"boundaryInputs\")\n\nfunction formatInstancePath(instance: InstanceModel): string {\n let result = instance.id\n while (instance.parentId) {\n const parent = runtimeInstances.get(instance.parentId)?.instance\n if (!parent) {\n break\n }\n\n result = `${parent.id} -> ${result}`\n instance = parent\n }\n\n return result\n}\n\nexport class InstanceNameConflictError extends Error {\n constructor(\n readonly instanceId: string,\n readonly firstPath: string,\n readonly secondPath: string,\n ) {\n super(\n `Multiple instances produced with the same instance ID \"${instanceId}\":\\n` +\n `1. ${firstPath}\\n` +\n `2. ${secondPath}`,\n )\n\n this.name = \"InstanceNameConflictError\"\n }\n}\n\nlet currentInstance: InstanceModel | null = null\n\nconst runtimeInstances: Map<string, RuntimeInstance> = new Map()\n\n/**\n * Resets the evaluation state, clearing all collected composite instances and runtime instances.\n */\nexport function resetEvaluation(): void {\n runtimeInstances.clear()\n currentInstance = null\n}\n\n/**\n * Returns all runtime instances collected during the evaluation.\n *\n * Note that these instances are not serializable.\n */\nexport function getRuntimeInstances(): RuntimeInstance[] {\n return Array.from(runtimeInstances.values())\n}\n\nexport function registerInstance<T>(component: Component, instance: InstanceModel, fn: () => T): T {\n const conflicting = runtimeInstances.get(instance.id)\n if (conflicting) {\n throw new InstanceNameConflictError(\n instance.id,\n formatInstancePath(conflicting.instance),\n formatInstancePath(instance),\n )\n }\n\n runtimeInstances.set(instance.id, { instance, component })\n\n let previousParentInstance: InstanceModel | null = null\n\n if (currentInstance) {\n instance.parentId = currentInstance.id\n }\n\n if (component.model.kind === \"composite\") {\n previousParentInstance = currentInstance\n currentInstance = instance\n }\n\n try {\n const outputs = fn() as Record<string, InstanceInput[]>\n\n instance.resolvedOutputs = outputs\n instance.outputs = mapValues(outputs ?? {}, outputs =>\n outputs.map(output => output[boundaryInput] ?? output),\n )\n\n // mark all outputs with the boundary input of the instance\n return mapValues(outputs, (outputs, outputKey) =>\n outputs.map(output => ({\n ...output,\n [boundaryInput]: { instanceId: instance.id, output: outputKey },\n })),\n ) as T\n } finally {\n if (previousParentInstance) {\n currentInstance = previousParentInstance\n }\n }\n}\n","/** biome-ignore-all lint/suspicious/noExplicitAny: maybe fix later */\n\nimport type { Simplify } from \"type-fest\"\nimport type { Entity, implementedTypes } from \"./entity\"\nimport type { OptionalEmptyRecords, OptionalUndefinedFields, PartialKeys } from \"./utils\"\nimport { isNonNullish, mapValues, pickBy, uniqueBy } from \"remeda\"\nimport { z } from \"zod\"\nimport { boundaryInput, boundaryInputs, registerInstance } from \"./evaluation\"\nimport { camelCaseToHumanReadable } from \"./i18n\"\nimport { type InstanceId, type InstanceInput, type InstanceInputGroup, inputKey } from \"./instance\"\nimport {\n fieldNameSchema,\n genericNameSchema,\n objectMetaSchema,\n parseVersionedName,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\nexport const runtimeSchema = Symbol(\"runtimeSchema\")\n\nlet validationEnabled = true\n\nexport function setValidationEnabled(enabled: boolean): void {\n validationEnabled = enabled\n}\n\nexport const componentKindSchema = z.enum([\"composite\", \"unit\"])\nexport type ComponentKind = z.infer<typeof componentKindSchema>\n\nexport const componentArgumentSchema = z.object({\n /**\n * The JSON schema of the argument value.\n */\n schema: z.custom<z.core.JSONSchema.BaseSchema>(),\n\n /**\n * The original Zod schema of the argument.\n *\n * Only available at runtime.\n */\n [runtimeSchema]: z.instanceof(z.ZodType).optional(),\n\n /**\n * Whether the argument is required.\n */\n required: z.boolean(),\n\n /**\n * The extra metadata of the argument.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n globalTitle: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n }),\n})\n\nexport type ComponentArgument = z.infer<typeof componentArgumentSchema>\n\nexport type FullComponentArgumentOptions = {\n schema: z.ZodType\n meta?: PartialKeys<ComponentArgument[\"meta\"], \"title\">\n}\n\nexport type ComponentArgumentOptions = z.ZodType | FullComponentArgumentOptions\n\nexport type ComponentArgumentOptionsToSchema<T extends ComponentArgumentOptions> =\n T extends FullComponentArgumentOptions ? T[\"schema\"] : T\n\nexport const componentInputSchema = z.object({\n /**\n * The type of the entity passed through the input.\n */\n type: versionedNameSchema,\n\n /**\n * Whether the input is required.\n */\n required: z.boolean(),\n\n /**\n * Whether the input can have multiple values.\n */\n multiple: z.boolean(),\n\n /**\n * The extra metadata of the input.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n description: true,\n }),\n})\n\nexport type ComponentInput = z.infer<typeof componentInputSchema>\n\nexport type FullComponentInputOptions = {\n entity: Entity\n required?: boolean\n multiple?: boolean\n meta?: PartialKeys<ComponentInput[\"meta\"], \"title\">\n}\n\nexport type ComponentInputOptions = Entity | FullComponentInputOptions\n\ntype ComponentInputOptionsToOutputRef<T extends ComponentInputOptions> = T extends Entity\n ? InstanceInput<T[typeof implementedTypes]>\n : T extends FullComponentInputOptions\n ? T[\"required\"] extends false\n ? T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][typeof implementedTypes]>[] | undefined\n : InstanceInput<T[\"entity\"][typeof implementedTypes]> | undefined\n : T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][typeof implementedTypes]>[]\n : InstanceInput<T[\"entity\"][typeof implementedTypes]>\n : never\n\n/**\n * The type-level specification of a component input hold by the component model.\n */\nexport type ComponentInputSpec = [entity: Entity, required: boolean, multiple: boolean]\n\nexport type ComponentInputOptionsToSpec<T extends ComponentInputOptions> = T extends Entity\n ? [T, true, false] // [Entity, required, multiple]\n : T extends FullComponentInputOptions\n ? T[\"required\"] extends false\n ? T[\"multiple\"] extends true\n ? [T[\"entity\"], false, true]\n : [T[\"entity\"], false, false]\n : T[\"multiple\"] extends true\n ? [T[\"entity\"], true, true]\n : [T[\"entity\"], true, false]\n : never\n\nexport type ComponentInputOptionsMapToSpecMap<T extends Record<string, ComponentInputOptions>> =\n T extends Record<string, never>\n ? Record<string, never>\n : { [K in keyof T]: ComponentInputOptionsToSpec<T[K]> }\n\ntype ComponentInputMapToValue<T extends Record<string, ComponentInputOptions>> =\n OptionalUndefinedFields<{\n [K in keyof T]: ComponentInputOptionsToOutputRef<T[K]>\n }>\n\ntype ComponentInputMapToReturnType<T extends Record<string, ComponentInputOptions>> =\n // biome-ignore lint/suspicious/noConfusingVoidType: this is return type\n T extends Record<string, never> ? void : ComponentInputMapToValue<T>\n\nexport type ComponentParams<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = {\n id: InstanceId\n name: string\n args: { [K in keyof TArgs]: z.infer<ComponentArgumentOptionsToSchema<TArgs[K]>> }\n inputs: ComponentInputMapToValue<TInputs>\n}\n\nexport type InputComponentParams<\n TArgs extends Record<string, unknown>,\n TInputs extends Record<string, unknown>,\n> = {\n name: string\n} & OptionalEmptyRecords<{\n args: TArgs\n inputs: TInputs\n}>\n\nexport type ComponentOptions<\n TType extends VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n> = {\n /**\n * The type of the component.\n * Must be a valid versioned name.\n *\n * Examples: `proxmox.virtual-machine.v1`, `common.server.v1`.\n */\n type: TType\n\n /**\n * The extra metadata of the component.\n *\n * If title or defaultNamePrefix is not provided, they will be generated from the type.\n */\n meta?: PartialKeys<ComponentModel[\"meta\"], \"title\" | \"defaultNamePrefix\">\n\n /**\n * The specification of the component arguments.\n */\n args?: TArgs\n\n /**\n * The specification of the component inputs.\n */\n inputs?: TInputs\n\n /**\n * The specification of the component outputs.\n */\n outputs?: TOutputs\n\n /**\n * The create function of the component.\n *\n * It can create instances of other components and return their outputs.\n *\n * Note: All created instances must guarantee unique ids within the project.\n * Their names are not automatically prefixed with the component name,\n * so you must prefix them manually if needed or guarantee uniqueness in another way.\n */\n create: (params: ComponentParams<TArgs, TInputs>) => ComponentInputMapToReturnType<TOutputs>\n\n /**\n * For internal use only.\n */\n [kind]?: ComponentKind\n}\n\n// Models\nexport const componentModelSchema = z.object({\n /**\n * The type of the component.\n */\n type: genericNameSchema,\n\n /**\n * The kind of the component.\n */\n kind: componentKindSchema,\n\n /**\n * The record of the argument schemas.\n */\n args: z.record(fieldNameSchema, componentArgumentSchema),\n\n /**\n * The record of the input schemas.\n */\n inputs: z.record(fieldNameSchema, componentInputSchema),\n\n /**\n * The record of the output schemas.\n */\n outputs: z.record(fieldNameSchema, componentInputSchema),\n\n /**\n * The extra metadata of the component.\n */\n meta: objectMetaSchema\n .required({ title: true })\n .pick({\n title: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n secondaryIcon: true,\n secondaryIconColor: true,\n })\n .extend({\n /**\n * The category of the component.\n *\n * Used to group components in the UI.\n */\n category: z.string().optional(),\n\n /**\n * The default name prefix for the component instances.\n *\n * Used to generate default names for the instances.\n */\n defaultNamePrefix: z.string(),\n }),\n\n /**\n * The CRC32 of the component definition.\n */\n definitionHash: z.number(),\n})\n\nexport type ComponentModel = z.infer<typeof componentModelSchema>\n\ntype InputSpecToInputRef<T extends ComponentInputSpec> = T[1] extends true\n ? T[2] extends true\n ? InstanceInput<T[0][typeof implementedTypes]>[]\n : InstanceInput<T[0][typeof implementedTypes]>\n : T[2] extends true\n ? InstanceInput<T[0][typeof implementedTypes]>[] | undefined\n : InstanceInput<T[0][typeof implementedTypes]> | undefined\n\ntype InputSpecToOutputRef<T extends ComponentInputSpec> = T[2] extends true\n ? InstanceInput<T[0][typeof implementedTypes]>[]\n : InstanceInput<T[0][typeof implementedTypes]>\n\nexport type InputSpecMapToInputRefMap<TInputs extends Record<string, ComponentInputSpec>> =\n TInputs extends Record<string, [string, never, never]>\n ? Record<string, never>\n : { [K in keyof TInputs]: InputSpecToInputRef<TInputs[K]> }\n\nexport type OutputRefMap<TInputs extends Record<string, ComponentInputSpec>> =\n TInputs extends Record<string, [string, never, never]>\n ? Record<string, never>\n : { [K in keyof TInputs]: InputSpecToOutputRef<TInputs[K]> }\n\nexport const originalCreate = Symbol(\"originalCreate\")\nexport const kind = Symbol(\"kind\")\n\nexport type Component<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, z.ZodType> = Record<string, never>,\n TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n> = {\n /**\n * The type of the component.\n */\n type: TType\n\n /**\n * The non-generic model of the component.\n */\n model: ComponentModel\n\n /**\n * The entities used in the inputs or outputs of the component.\n */\n entities: Map<string, Entity>\n\n (\n context: InputComponentParams<\n { [K in keyof TArgs]: z.input<TArgs[K]> },\n InputSpecMapToInputRefMap<TInputs>\n >,\n ): OutputRefMap<TOutputs>\n\n /**\n * The original create function.\n *\n * Used to calculate the definition hash.\n */\n [originalCreate]: (params: InputComponentParams<any, any>) => any\n}\n\nexport function defineComponent<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,\n TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n>(\n options: ComponentOptions<TType, TArgs, TInputs, TOutputs>,\n): Component<\n TType,\n { [K in keyof TArgs]: ComponentArgumentOptionsToSchema<TArgs[K]> },\n { [K in keyof TInputs]: ComponentInputOptionsToSpec<TInputs[K]> },\n { [K in keyof TOutputs]: ComponentInputOptionsToSpec<TOutputs[K]> }\n> {\n try {\n componentModelSchema.shape.type.parse(options.type)\n } catch (error) {\n throw new Error(`Invalid component type \"${options.type}\"`, { cause: error })\n }\n\n if (!options.create) {\n throw new Error(\"Component create function is required\")\n }\n\n const entities = new Map<string, Entity>()\n const mapInput = createInputMapper(entities)\n\n const model: ComponentModel = {\n type: options.type,\n kind: options[kind] ?? \"composite\",\n args: mapValues(options.args ?? {}, mapArgument),\n inputs: mapValues(options.inputs ?? {}, mapInput),\n outputs: mapValues(options.outputs ?? {}, mapInput),\n meta: {\n ...options.meta,\n title: options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0]),\n defaultNamePrefix:\n options.meta?.defaultNamePrefix ||\n parseVersionedName(options.type)[0].split(\".\").slice(-1)[0],\n },\n // will be calculated by library loader\n definitionHash: null!,\n }\n\n function create(\n params: InputComponentParams<any, Record<string, InstanceInput | InstanceInputGroup>>,\n ): any {\n const { name, args = {}, inputs } = params\n const instanceId = getInstanceId(options.type, name)\n\n const flatInputs: Record<string, InstanceInputGroup> = {}\n const tracedInputs: Record<string, InstanceInput[]> = {}\n\n for (const [key, inputGroup] of Object.entries(inputs ?? {})) {\n if (!inputGroup) {\n continue\n }\n\n if (!Array.isArray(inputGroup)) {\n if (inputGroup[boundaryInput]) {\n tracedInputs[key] = [inputGroup[boundaryInput]]\n }\n\n flatInputs[key] = [inputGroup]\n continue\n }\n\n // merge \"boundaryInputs\" attached to array with \"boundaryInput\"s attached to individual items\n const group: InstanceInput[] = [...(inputGroup[boundaryInputs] ?? [])]\n const inputs: InstanceInput[] = []\n\n for (const item of inputGroup.flat(1)) {\n if (item[boundaryInput]) {\n group.push(item[boundaryInput])\n }\n\n inputs.push(item)\n }\n\n tracedInputs[key] = uniqueBy(group, inputKey)\n flatInputs[key] = uniqueBy(inputs, inputKey)\n }\n\n return registerInstance(\n create as unknown as Component,\n {\n id: instanceId,\n type: options.type,\n kind: options[kind] ?? \"composite\",\n name,\n args,\n inputs: tracedInputs,\n resolvedInputs: mapValues(flatInputs, inputs =>\n inputs.filter(input => !(\"provided\" in input && input.provided === false)),\n ),\n },\n () => {\n const markedInputs = mapValues(model.inputs, (componentInput, key) => {\n if (!componentInput.multiple) {\n // for single component use first available input and attach boundaryInput\n // technically, caller can pass multiple inputs or array of inputs ignoring the TypeScript restriction,\n // but we don't care about that\n const input = flatInputs[key]?.[0]\n\n if (input) {\n // return the input with boundaryInput attached\n // the input can also be \"OptionalInstanceInput\" with \"provided: false\", but this is still correct\n return { ...input, [boundaryInput]: { instanceId: instanceId, output: key } }\n }\n\n // create a new \"not provided\" input with boundaryInput attached\n return { provided: false, [boundaryInput]: { instanceId: instanceId, output: key } }\n }\n\n // then handle array of inputs\n // caller can provide array of array which will be flattened with boundaryInputs preserved\n // regardless of the number of inputs, we always attach boundaryInputs to the whole array\n const inputs = flatInputs[key] ?? []\n inputs[boundaryInputs] = [{ instanceId, output: key }]\n\n return inputs\n })\n\n const outputs: Record<string, InstanceInput[]> =\n options.create({\n id: instanceId,\n name,\n args: processArgs(instanceId, create.model, args) as any,\n inputs: markedInputs as any,\n }) ?? {}\n\n return mapValues(pickBy(outputs, isNonNullish), outputs => [outputs].flat(2))\n },\n )\n }\n\n try {\n create.entities = entities\n create.model = model\n\n create[originalCreate] = options.create\n\n return create as any\n } catch (error) {\n throw new Error(`Failed to define component \"${options.type}\"`, { cause: error })\n }\n}\n\nfunction processArgs(\n instanceId: InstanceId,\n model: ComponentModel,\n args: Record<string, unknown>,\n): Record<string, unknown> {\n if (!validationEnabled) {\n return args\n }\n\n const validatedArgs: Record<string, unknown> = {}\n\n for (const [key, arg] of Object.entries(model.args)) {\n if (arg.schema) {\n const result = arg[runtimeSchema]!.safeParse(args[key])\n\n if (!result.success) {\n throw new Error(\n `Invalid argument \"${key}\" in instance \"${instanceId}\": ${result.error.message}`,\n )\n }\n\n validatedArgs[key] = result.data\n } else {\n validatedArgs[key] = args[key]\n }\n }\n\n return validatedArgs\n}\n\n/**\n * Checks if the value is a Highstate component.\n *\n * Does not guarantee that the value is a valid component, only that it has the expected structure.\n *\n * @param value The value to check.\n * @returns True if the value is a component, false otherwise.\n */\nexport function isComponent(value: unknown): value is Component {\n return typeof value === \"function\" && \"model\" in value\n}\n\nfunction isSchemaOptional(schema: z.ZodType): boolean {\n return schema.safeParse(undefined).success\n}\n\nexport function mapArgument(value: ComponentArgumentOptions, key: string): ComponentArgument {\n if (\"schema\" in value) {\n return {\n schema: z.toJSONSchema(value.schema, {\n target: \"draft-7\",\n io: \"input\",\n unrepresentable: \"any\",\n }),\n [runtimeSchema]: value.schema,\n required: !isSchemaOptional(value.schema),\n meta: {\n ...value.meta,\n title: value.meta?.title || camelCaseToHumanReadable(key),\n },\n }\n }\n\n return {\n schema: z.toJSONSchema(value, { target: \"draft-7\", io: \"input\", unrepresentable: \"any\" }),\n [runtimeSchema]: value,\n required: !isSchemaOptional(value),\n meta: {\n title: camelCaseToHumanReadable(key),\n },\n }\n}\n\nexport function createInputMapper(entities: Map<string, Entity>) {\n return (value: ComponentInputOptions, key: string): ComponentInput => {\n if (!value) {\n throw new Error(`Input/output \"${key}\" is undefined in the component model.`)\n }\n\n if (\"entity\" in value) {\n entities.set(value.entity.type, value.entity)\n\n return {\n type: value.entity.type,\n required: value.required ?? true,\n multiple: value.multiple ?? false,\n meta: {\n ...value.meta,\n title: value.meta?.title || camelCaseToHumanReadable(key),\n },\n }\n }\n\n entities.set(value.type, value)\n\n return {\n type: value.type,\n required: true,\n multiple: false,\n meta: {\n title: camelCaseToHumanReadable(key),\n },\n }\n }\n}\n\n/**\n * Formats the instance id from the instance type and instance name.\n *\n * @param instanceType The type of the instance.\n * @param instanceName The name of the instance.\n *\n * @returns The formatted instance id.\n */\nexport function getInstanceId(instanceType: VersionedName, instanceName: string): InstanceId {\n return `${instanceType}:${instanceName}`\n}\n\nexport type ToFullComponentArgumentOptions<T extends Record<string, ComponentArgumentOptions>> =\n Simplify<{\n [K in keyof T]: T[K] extends z.ZodType ? { schema: T[K] } : T[K]\n }>\n\nexport function toFullComponentArgumentOptions<T extends Record<string, ComponentArgumentOptions>>(\n args: T,\n): ToFullComponentArgumentOptions<T> {\n return mapValues(args, arg => (\"schema\" in arg ? arg : { schema: arg })) as any\n}\n\ntype ToFullComponentInputOptions<T extends Record<string, ComponentInputOptions>> = Simplify<{\n [K in keyof T]: T[K] extends Entity ? { entity: T[K] } : T[K]\n}>\n\nfunction toFullComponentInputOptions<T extends Record<string, ComponentInputOptions>>(\n inputs: T,\n): ToFullComponentInputOptions<T> {\n return mapValues(inputs, input => (\"entity\" in input ? input : { entity: input })) as any\n}\n\n/**\n * The helper marker for component arguments.\n *\n * Helps validating arguments types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $args<T extends Record<string, ComponentArgumentOptions>>(\n args: T,\n): ToFullComponentArgumentOptions<T> {\n return toFullComponentArgumentOptions(args)\n}\n\n/**\n * The helper marker for component inputs.\n *\n * Helps validating inputs types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $inputs<T extends Record<string, ComponentInputOptions>>(\n inputs: T,\n): ToFullComponentInputOptions<T> {\n return toFullComponentInputOptions(inputs)\n}\n\n/**\n * The helper marker for component outputs.\n *\n * Helps validating outputs types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $outputs<T extends Record<string, ComponentInputOptions>>(\n outputs: T,\n): ToFullComponentInputOptions<T> {\n return toFullComponentInputOptions(outputs)\n}\n\n/**\n * Adds a description to the argument which can be both a schema or full argument options.\n *\n * Used by the compiler to inject descriptions into the argument schema.\n * You probably won't need to use it directly.\n */\nexport function $addArgumentDescription(\n argument: ComponentArgumentOptions,\n description: string,\n): FullComponentArgumentOptions {\n if (\"schema\" in argument) {\n return {\n ...argument,\n meta: {\n ...argument.meta,\n description: argument.meta?.description ?? description,\n },\n }\n }\n\n return {\n schema: argument,\n meta: {\n description: description,\n },\n }\n}\n\n/**\n * Adds a description to the input which can be both an entity or full input options.\n *\n * Used by the compiler to inject descriptions into the input schema.\n * You probably won't need to use it directly.\n */\nexport function $addInputDescription(\n input: ComponentInputOptions,\n description: string,\n): ComponentInputOptions {\n if (\"entity\" in input) {\n return {\n ...input,\n meta: {\n ...input.meta,\n description: input.meta?.description ?? description,\n },\n }\n }\n\n return {\n entity: input,\n meta: {\n description: description,\n },\n }\n}\n","import type { Entity, EntityTypes } from \"./entity\"\nimport type { boundaryInput, boundaryInputs } from \"./evaluation\"\nimport { z } from \"zod\"\nimport { componentKindSchema } from \"./component\"\nimport {\n type GenericName,\n genericNameSchema,\n objectMetaSchema,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\ndeclare const type: unique symbol\n\nexport type InstanceInput<TTypes extends EntityTypes = EntityTypes> = {\n [type]?: TTypes\n [boundaryInput]?: InstanceInput\n instanceId: InstanceId\n output: string\n}\n\nexport type EntityInput<TEntity extends Entity> = TEntity extends Entity<\n VersionedName,\n infer TImplementedTypes\n>\n ? InstanceInput<TImplementedTypes>\n : never\n\nexport type OptionalInstanceInput<TTypes extends EntityTypes = EntityTypes> =\n | ({ provided: true } & InstanceInput<TTypes>)\n | { provided: false; [boundaryInput]?: InstanceInput }\n\nexport type InstanceInputGroup<TTypes extends EntityTypes = EntityTypes> =\n InstanceInput<TTypes>[] & {\n [boundaryInputs]?: InstanceInputGroup<TTypes>\n }\n\nexport function inputKey(input: InstanceInput): string {\n return `${input.instanceId}:${input.output}`\n}\n\nexport const positionSchema = z.object({\n x: z.number(),\n y: z.number(),\n})\n\nexport type Position = z.infer<typeof positionSchema>\n\nexport const instanceIdSchema = z.templateLiteral([versionedNameSchema, \":\", genericNameSchema])\n\nexport type InstanceId = z.infer<typeof instanceIdSchema>\n\nexport const instanceInputSchema = z.object({\n instanceId: instanceIdSchema,\n output: z.string(),\n})\n\nexport const hubInputSchema = z.object({\n hubId: z.string(),\n})\n\nexport type HubInput = z.infer<typeof hubInputSchema>\n\nexport const instanceModelPatchSchema = z.object({\n /**\n * The static arguments passed to the instance.\n */\n args: z.record(z.string(), z.unknown()).optional(),\n\n /**\n * The direct instances passed as inputs to the instance.\n */\n inputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The resolved unit inputs for the instance.\n *\n * Only for computed composite instances.\n */\n hubInputs: z.record(z.string(), z.array(hubInputSchema)).optional(),\n\n /**\n * The inputs injected to the instance from the hubs.\n *\n * While `hubInputs` allows to pass hubs to distinct inputs,\n * `injectionInputs` allows to pass hubs to the instance as a whole filling all inputs with matching types.\n *\n * Only for designer-first instances.\n */\n injectionInputs: z.array(hubInputSchema).optional(),\n\n /**\n * The position of the instance on the canvas.\n *\n * Only for designer-first instances.\n */\n position: positionSchema.optional(),\n})\n\nexport const instanceModelSchema = z.object({\n /**\n * The id of the instance unique within the project.\n *\n * The format is `${instanceType}:${instanceName}`.\n */\n id: instanceIdSchema,\n\n /**\n * The kind of the instance.\n *\n * Can be either \"unit\" or \"composite\".\n */\n kind: componentKindSchema,\n\n /**\n * The type of the instance.\n */\n type: versionedNameSchema,\n\n /**\n * The name of the instance.\n *\n * Must be unique within instances of the same type in the project.\n */\n name: genericNameSchema,\n\n ...instanceModelPatchSchema.shape,\n\n /**\n * The id of the top level parent instance.\n *\n * Only for child instances of the composite instances.\n */\n resolvedInputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The ID of the parent instance.\n *\n * Only for child instances of the composite instances.\n */\n parentId: instanceIdSchema.optional(),\n\n /**\n * The direct instance outputs returned by the instance as outputs.\n *\n * Only for computed composite instances.\n */\n outputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The resolved unit outputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedOutputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n})\n\nexport type InstanceModel = z.infer<typeof instanceModelSchema>\n\nexport const hubModelPatchSchema = z.object({\n /**\n * The position of the hub on the canvas.\n */\n position: positionSchema.optional(),\n\n /**\n * The inputs of the hub.\n */\n inputs: z.array(instanceInputSchema).optional(),\n\n /**\n * The inputs injected to the hub from the hubs.\n *\n * While `inputs` allows to pass hubs to distinct inputs,\n * `injectionInputs` allows to pass hubs to the hub as a whole filling all inputs with matching types.\n */\n injectionInputs: z.array(hubInputSchema).optional(),\n})\n\nexport const hubModelSchema = z.object({\n /**\n * The id of the hub unique within the project.\n */\n id: z.cuid2(),\n\n ...hubModelPatchSchema.shape,\n})\n\nexport type InstanceModelPatch = z.infer<typeof instanceModelPatchSchema>\nexport type HubModel = z.infer<typeof hubModelSchema>\nexport type HubModelPatch = z.infer<typeof hubModelPatchSchema>\n\n/**\n * Parses the instance id into the instance type and instance name.\n *\n * @param instanceId The instance id to parse.\n *\n * @returns The instance type and instance name.\n */\nexport function parseInstanceId(\n instanceId: string,\n): [instanceType: VersionedName, instanceName: GenericName] {\n const parts = instanceId.split(\":\")\n\n if (parts.length !== 2) {\n throw new Error(`Invalid instance ID: ${instanceId}`)\n }\n\n return parts as [VersionedName, GenericName]\n}\n\nexport function findInput<T extends EntityTypes>(\n inputs: InstanceInput<T>[],\n name: string,\n): InstanceInput<T> | null {\n const matchedInputs = inputs.filter(\n input => parseInstanceId(input.instanceId)[1] === name || input.instanceId === name,\n )\n\n if (matchedInputs.length === 0) {\n return null\n }\n\n if (matchedInputs.length > 1) {\n throw new Error(\n `Multiple inputs found for \"${name}\": ${matchedInputs.map(input => input.instanceId).join(\", \")}. Specify the full instance id to disambiguate.`,\n )\n }\n\n return matchedInputs[0]\n}\n\nexport function findRequiredInput<T extends EntityTypes>(\n inputs: InstanceInput<T>[],\n name: string,\n): InstanceInput<T> {\n const input = findInput(inputs, name)\n\n if (input === null) {\n throw new Error(`Required input \"${name}\" not found.`)\n }\n\n return input\n}\n\nexport function findInputs<T extends EntityTypes>(\n inputs: InstanceInput<T>[],\n names: string[],\n): InstanceInput<T>[] {\n return names.map(name => findInput(inputs, name)).filter(Boolean) as InstanceInput<T>[]\n}\n\nexport function findRequiredInputs<T extends EntityTypes>(\n inputs: InstanceInput<T>[],\n names: string[],\n): InstanceInput<T>[] {\n return names.map(name => findRequiredInput(inputs, name))\n}\n\n/**\n * The field names that indicate special objects which Highstate understands regardless of the context.\n *\n * UUIDs are used to prevent conflicts with user-defined fields.\n */\nexport enum HighstateSignature {\n Artifact = \"d55c63ac-3174-4756-808f-f778e99af0d1\",\n Yaml = \"c857cac5-caa6-4421-b82c-e561fbce6367\",\n Id = \"348d020e-0d9e-4ae7-9415-b91af99f5339\",\n Ref = \"6d7f9da0-9cb6-496d-b72e-cf85ee4d9cf8\",\n}\n\nexport const yamlValueSchema = z.object({\n [HighstateSignature.Yaml]: z.literal(true),\n value: z.string(),\n})\n\nexport const objectWithIdSchema = z.object({\n [HighstateSignature.Id]: z.literal(true),\n id: z.number(),\n value: z.unknown(),\n})\n\nexport const objectRefSchema = z.object({\n [HighstateSignature.Ref]: z.literal(true),\n id: z.number(),\n})\n\nexport type YamlValue = z.infer<typeof yamlValueSchema>\n\nexport const fileMetaSchema = z.object({\n name: z.string(),\n contentType: z.string().optional(),\n size: z.number().optional(),\n mode: z.number().optional(),\n})\n\nexport enum WellKnownInstanceCustomStatus {\n /**\n * The instance is in a healthy state.\n */\n Healthy = \"healthy\",\n\n /**\n * The instance is in a degraded state.\n */\n Degraded = \"degraded\",\n\n /**\n * The instance is in a down state/completely broken.\n */\n Down = \"down\",\n\n /**\n * The instance is in a warning state.\n */\n Warning = \"warning\",\n\n /**\n * The instance is progressing with some external sync operation,\n * such as a deployment or a data migration.\n */\n Progressing = \"progressing\",\n\n /**\n * The instance is in an error state.\n */\n Error = \"error\",\n}\n\nexport const instanceStatusFieldValueSchema = z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.string().array(),\n])\n\nexport const instanceStatusFieldSchema = z.object({\n name: z.string(),\n\n meta: objectMetaSchema\n .pick({\n title: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n\n complementaryTo: z.string().optional(),\n value: instanceStatusFieldValueSchema.optional(),\n})\n\nexport type InstanceStatusFieldValue = z.infer<typeof instanceStatusFieldValueSchema>\nexport type InstanceStatusField = z.infer<typeof instanceStatusFieldSchema>\n","/** biome-ignore-all lint/suspicious/noExplicitAny: maybe fix later */\n\nimport type { InstanceInput } from \"./instance\"\nimport type { VersionedName } from \"./meta\"\nimport { mapValues } from \"remeda\"\nimport { z } from \"zod\"\nimport {\n type Component,\n type ComponentArgumentOptions,\n type ComponentArgumentOptionsToSchema,\n type ComponentInputOptions,\n type ComponentInputOptionsToSpec,\n type ComponentInputSpec,\n type ComponentModel,\n type ComponentOptions,\n componentArgumentSchema,\n componentModelSchema,\n defineComponent,\n type FullComponentArgumentOptions,\n kind,\n mapArgument,\n type ToFullComponentArgumentOptions,\n toFullComponentArgumentOptions,\n} from \"./component\"\n\nexport const componentSecretSchema = componentArgumentSchema.extend({\n /**\n * The secret cannot be modified by the user, but can be modified by the unit.\n */\n readonly: z.boolean(),\n\n /**\n * The secret value is computed by the unit and should not be passed to it when invoked.\n */\n computed: z.boolean(),\n})\n\nexport type ComponentSecret = z.infer<typeof componentSecretSchema>\n\nexport type FullComponentSecretOptions = FullComponentArgumentOptions & {\n readonly?: boolean\n computed?: boolean\n}\n\nexport type ComponentSecretOptions = z.ZodType | FullComponentSecretOptions\n\ntype UnitOptions<\n TType extends VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n TSecrets extends Record<string, ComponentSecretOptions>,\n> = Omit<ComponentOptions<TType, TArgs, TInputs, TOutputs>, \"create\"> & {\n source: UnitSource\n\n secrets?: TSecrets\n}\n\nexport const unitSourceSchema = z.object({\n /**\n * The package where the unit implementation is located.\n *\n * May be both: local monorepo package or a remote NPM package.\n */\n package: z.string(),\n\n /**\n * The path to the unit implementation within the package.\n *\n * If not provided, the root of the package is assumed.\n */\n path: z.string().optional(),\n})\n\nexport const unitModelSchema = z.object({\n ...componentModelSchema.shape,\n\n /**\n * The source of the unit.\n */\n source: unitSourceSchema,\n\n /**\n * The record of the secret specs.\n */\n secrets: z.record(z.string(), componentSecretSchema),\n})\n\nexport type UnitModel = z.infer<typeof unitModelSchema>\nexport type UnitSource = z.infer<typeof unitSourceSchema>\n\ndeclare const secrets: unique symbol\n\nexport type Unit<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, z.ZodType> = Record<string, never>,\n TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TSecrets extends Record<string, unknown> = Record<string, never>,\n> = Component<TType, TArgs, TInputs, TOutputs> & {\n /**\n * Holds the type of the unit secrets.\n *\n * Does not exist at runtime, only for type checking.\n */\n [secrets]: TSecrets\n\n /**\n * The model of the unit.\n */\n model: UnitModel\n}\n\nexport function defineUnit<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,\n TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n TSecrets extends Record<string, ComponentSecretOptions> = Record<string, never>,\n>(\n options: UnitOptions<TType, TArgs, TInputs, TOutputs, TSecrets>,\n): Unit<\n TType,\n { [K in keyof TArgs]: ComponentArgumentOptionsToSchema<TArgs[K]> },\n { [K in keyof TInputs]: ComponentInputOptionsToSpec<TInputs[K]> },\n { [K in keyof TOutputs]: ComponentInputOptionsToSpec<TOutputs[K]> },\n { [K in keyof TSecrets]: ComponentArgumentOptionsToSchema<TSecrets[K]> }\n> {\n if (!options.source) {\n throw new Error(\"Unit source is required\")\n }\n\n const component = defineComponent<TType, TArgs, TInputs, TOutputs>({\n ...options,\n [kind]: \"unit\",\n\n create({ id }) {\n const outputs: Record<string, InstanceInput[]> = {}\n for (const key in options.outputs ?? {}) {\n outputs[key] = [\n {\n instanceId: id,\n output: key,\n },\n ]\n }\n\n return outputs as any\n },\n }) as any\n\n try {\n component.model.source = options.source ?? {}\n component.model.secrets = mapValues(options.secrets ?? {}, mapSecret)\n } catch (error) {\n throw new Error(`Failed to map secrets for unit \"${options.type}\"`, { cause: error })\n }\n\n return component\n}\n\n/**\n * The helper marker for component secrets.\n *\n * Helps validating secrets types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $secrets<T extends Record<string, ComponentArgumentOptions>>(\n secrets: T,\n): ToFullComponentArgumentOptions<T> {\n return toFullComponentArgumentOptions(secrets)\n}\n\nfunction mapSecret(value: ComponentSecretOptions, key: string): ComponentSecret {\n if (\"schema\" in value) {\n return {\n ...mapArgument(value, key),\n readonly: value.readonly ?? false,\n computed: value.computed ?? false,\n }\n }\n\n return {\n ...mapArgument(value, key),\n readonly: false,\n computed: false,\n }\n}\n\n/**\n * Checks if the given model is a unit model.\n *\n * @param model The model to check.\n *\n * @returns `true` if the model is a unit model, `false` otherwise.\n */\nexport function isUnitModel(model: ComponentModel): model is UnitModel {\n return \"source\" in model\n}\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\n\nexport const triggerSpecSchema = z.union([\n z.object({\n type: z.literal(\"before-destroy\"),\n }),\n])\n\nexport type TriggerSpec = z.infer<typeof triggerSpecSchema>\n\n/**\n * Trigger schema for unit API.\n * This is what units provide - excludes id since it's set by the system.\n */\nexport const unitTriggerSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n\n /**\n * The specification of the trigger.\n *\n * Defines the type of trigger and its behavior.\n */\n spec: triggerSpecSchema,\n})\n\nexport type UnitTrigger = z.infer<typeof unitTriggerSchema>\n\nexport const triggerInvocationSchema = z.object({\n /**\n * The name of the trigger being invoked.\n */\n name: z.string(),\n})\n\nexport type TriggerInvocation = z.infer<typeof triggerInvocationSchema>\n","import { parse } from \"yaml\"\nimport { z } from \"zod\"\nimport { entityInclusionSchema } from \"./entity\"\nimport {\n fileMetaSchema,\n HighstateSignature,\n instanceIdSchema,\n instanceInputSchema,\n yamlValueSchema,\n} from \"./instance\"\nimport { commonObjectMetaSchema } from \"./meta\"\nimport { triggerInvocationSchema } from \"./trigger\"\n\nexport type UnitInputReference = z.infer<typeof unitInputReference>\n\nexport const unitInputReference = z.object({\n ...instanceInputSchema.shape,\n\n /**\n * The resolved inclusion needed to extract the input value.\n */\n inclusion: entityInclusionSchema.optional(),\n})\n\nexport const unitConfigSchema = z.object({\n /**\n * The ID of the instance.\n */\n instanceId: z.string(),\n\n /**\n * The record of argument values for the unit.\n */\n args: z.record(z.string(), z.unknown()),\n\n /**\n * The record of input references for the unit.\n */\n inputs: z.record(z.string(), unitInputReference.array()),\n\n /**\n * The list of triggers that have been invoked for this unit.\n */\n invokedTriggers: triggerInvocationSchema.array(),\n\n /**\n * The list of secret names that exists and provided to the unit.\n */\n secretNames: z.string().array(),\n\n /**\n * The map of instance ID to state ID in order to resolve instance references.\n */\n stateIdMap: z.record(instanceIdSchema, z.string()),\n\n /**\n * The base path for imports.\n * Used to resolve dynamic dependencies in strict environments (like in pnpm node_modules isolation).\n */\n importBasePath: z.string(),\n})\n\nexport type UnitConfig = z.infer<typeof unitConfigSchema>\n\nconst yamlResultCache = new WeakMap<object, unknown>()\n\n/**\n * Parses an argument value which can be wrapped in a YAML structure.\n *\n * @param value The value to parse.\n */\nexport function parseArgumentValue(value: unknown): unknown {\n const yamlResult = yamlValueSchema.safeParse(value)\n if (!yamlResult.success) {\n return value\n }\n\n const existingResult = yamlResultCache.get(value as object)\n if (existingResult !== undefined) {\n return existingResult\n }\n\n const result = parse(yamlResult.data.value) as unknown\n yamlResultCache.set(value as object, result)\n return result\n}\n\nexport enum HighstateConfigKey {\n Config = \"highstate\",\n Secrets = \"highstate.secrets\",\n}\n\nexport const unitArtifactId = Symbol(\"unitArtifactId\")\n\nexport const unitArtifactSchema = z.object({\n [HighstateSignature.Artifact]: z.literal(true),\n // only for internal use\n [unitArtifactId]: z.string().optional(),\n hash: z.string(),\n meta: commonObjectMetaSchema.optional(),\n})\n\nexport const fileContentSchema = z.union([\n z.object({\n type: z.literal(\"embedded\"),\n\n /**\n * Whether the content is binary or not.\n *\n * If true, the `value` will be a base64 encoded string.\n */\n isBinary: z.boolean().optional(),\n\n /**\n * The content of the file.\n *\n * If `isBinary` is true, this will be a base64 encoded string.\n */\n value: z.string(),\n }),\n z.object({\n type: z.literal(\"artifact\"),\n ...unitArtifactSchema.shape,\n }),\n])\n\nexport const fileSchema = z.object({\n meta: fileMetaSchema,\n content: fileContentSchema,\n})\n\nexport type FileMeta = z.infer<typeof fileMetaSchema>\nexport type FileContent = z.infer<typeof fileContentSchema>\nexport type UnitArtifact = z.infer<typeof unitArtifactSchema>\nexport type File = z.infer<typeof fileSchema>\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\nimport { fileSchema } from \"./pulumi\"\n\n/**\n * Contains all the information needed to run a terminal,\n * including the image, command, working directory, environment variables, and files.\n */\nexport const terminalSpecSchema = z.object({\n /**\n * The Docker image to run the terminal.\n */\n image: z.string(),\n\n /**\n * The command to run in the terminal.\n */\n command: z.string().array(),\n\n /**\n * The working directory to run the command in.\n */\n cwd: z.string().optional(),\n\n /**\n * The environment variables to set in the terminal.\n */\n env: z.record(z.string(), z.string()).optional(),\n\n /**\n * The files to mount in the terminal.\n *\n * The key is the path where the file will be mounted,\n * and the value is the file content or a reference to an artifact.\n */\n files: z.record(z.string(), fileSchema).optional(),\n})\n\nexport type TerminalSpec = z.infer<typeof terminalSpecSchema>\n\n/**\n * Terminal schema for unit API.\n */\nexport const unitTerminalSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n spec: terminalSpecSchema,\n})\n\nexport type UnitTerminal = z.infer<typeof unitTerminalSchema>\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\nimport { fileSchema } from \"./pulumi\"\n\n/**\n * Page block schema for database storage and unit API.\n */\nexport const pageBlockSchema = z.union([\n z.object({\n type: z.literal(\"markdown\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"qr\"),\n content: z.string(),\n showContent: z.coerce.boolean(),\n language: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"file\"),\n file: fileSchema,\n }),\n])\n\nexport type PageBlock = z.infer<typeof pageBlockSchema>\n\n/**\n * Page schema for unit API.\n * This is what units provide - excludes id, instanceId and some fields from meta since those are set by the system.\n */\nexport const unitPageSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n content: pageBlockSchema.array(),\n})\n\nexport type UnitPage = z.infer<typeof unitPageSchema>\n","import { z } from \"zod\"\n\nexport const unitWorkerSchema = z.object({\n name: z.string(),\n image: z.string(),\n params: z.record(z.string(), z.unknown()),\n})\n\nexport type UnitWorker = z.infer<typeof unitWorkerSchema>\n\nexport const workerRunOptionsSchema = z.object({\n /**\n * The ID of the project for which the worker is running.\n */\n projectId: z.cuid2(),\n\n /**\n * The ID of the worker version.\n */\n workerVersionId: z.cuid2(),\n\n /**\n * The URL of the backend API to connect to.\n */\n apiUrl: z.url(),\n\n /**\n * The API key used to authenticate the worker with the backend.\n */\n apiKey: z.string(),\n})\n\nexport type WorkerRunOptions = z.infer<typeof workerRunOptionsSchema>\n","import { mapValues } from \"remeda\"\nimport { HighstateSignature, objectRefSchema, objectWithIdSchema } from \"./instance\"\n\nexport function compact<T>(value: T): unknown {\n const counts = new WeakMap<object, number>()\n const cyclic = new WeakSet<object>()\n const expanded = new WeakSet<object>()\n const inStack = new WeakSet<object>()\n const stack: object[] = []\n\n function countIdentities(current: unknown): void {\n if (current === null || typeof current !== \"object\") {\n return\n }\n\n counts.set(current, (counts.get(current) ?? 0) + 1)\n\n if (inStack.has(current)) {\n cyclic.add(current)\n\n for (const entry of stack) {\n cyclic.add(entry)\n }\n return\n }\n\n if (expanded.has(current)) {\n return\n }\n\n expanded.add(current)\n inStack.add(current)\n stack.push(current)\n\n if (Array.isArray(current)) {\n try {\n for (const item of current) {\n countIdentities(item)\n }\n return\n } finally {\n stack.pop()\n inStack.delete(current)\n }\n }\n\n try {\n for (const entryValue of Object.values(current)) {\n countIdentities(entryValue)\n }\n } finally {\n stack.pop()\n inStack.delete(current)\n }\n }\n\n countIdentities(value)\n\n type DefinitionSite = { parent: object; key: string | number }\n\n const ids = new WeakMap<object, number>()\n const definitionSites = new WeakMap<object, DefinitionSite>()\n let nextId = 1\n\n function ensureId(current: object): number {\n const existing = ids.get(current)\n if (existing !== undefined) {\n return existing\n }\n\n const allocated = nextId\n nextId += 1\n ids.set(current, allocated)\n return allocated\n }\n\n function assignDefinitionSitesBfs(root: unknown): void {\n if (root === null || typeof root !== \"object\") {\n return\n }\n\n const queue: Array<{ parent: object; key: string | number; value: unknown }> = []\n const expandedQueue = new WeakSet<object>()\n\n if (Array.isArray(root)) {\n for (let index = 0; index < root.length; index += 1) {\n queue.push({ parent: root, key: index, value: root[index] })\n }\n } else {\n for (const [key, entryValue] of Object.entries(root)) {\n queue.push({ parent: root, key, value: entryValue })\n }\n }\n\n while (queue.length > 0) {\n const current = queue.shift()\n if (current === undefined) {\n continue\n }\n\n if (current.value === null || typeof current.value !== \"object\") {\n continue\n }\n\n const occurrences = counts.get(current.value) ?? 0\n if (occurrences > 1 && definitionSites.get(current.value) === undefined) {\n definitionSites.set(current.value, { parent: current.parent, key: current.key })\n ensureId(current.value)\n }\n\n if (expandedQueue.has(current.value)) {\n continue\n }\n\n expandedQueue.add(current.value)\n\n if (Array.isArray(current.value)) {\n for (let index = 0; index < current.value.length; index += 1) {\n queue.push({ parent: current.value, key: index, value: current.value[index] })\n }\n continue\n }\n\n for (const [key, entryValue] of Object.entries(current.value)) {\n queue.push({ parent: current.value, key, value: entryValue })\n }\n }\n }\n\n assignDefinitionSitesBfs(value)\n\n const emitted = new WeakSet<object>()\n\n function buildTreeChildren(current: object, rootOfIdValue?: object): unknown {\n if (Array.isArray(current)) {\n return current.map(item => buildTree(item, rootOfIdValue))\n }\n\n return mapValues(current, entryValue => buildTree(entryValue, rootOfIdValue))\n }\n\n function buildTree(current: unknown, rootOfIdValue?: object): unknown {\n if (current === null || typeof current !== \"object\") {\n return current\n }\n\n // Inside an Id value, never emit nested Id wrappers.\n // Match existing real-world snapshot: do not introduce refs for nested objects\n // unless the nested object has already been defined earlier.\n if (rootOfIdValue !== undefined && emitted.has(current)) {\n const id = ids.get(current)\n if (id === undefined) {\n throw new Error(\"Compaction invariant violation: missing id for repeated object\")\n }\n\n return {\n [HighstateSignature.Ref]: true,\n id,\n }\n }\n\n // Cycles inside an Id value require defining the cyclic objects inline,\n // otherwise we would infinitely recurse.\n if (rootOfIdValue !== undefined && cyclic.has(current) && !emitted.has(current)) {\n const id = ensureId(current)\n emitted.add(current)\n\n return {\n [HighstateSignature.Id]: true,\n id,\n value: buildTreeChildren(current, current),\n }\n }\n\n return buildTreeChildren(current, rootOfIdValue)\n }\n\n function buildAt(parent: object, key: string | number, current: unknown): unknown {\n if (current === null || typeof current !== \"object\") {\n return current\n }\n\n const occurrences = counts.get(current) ?? 0\n if (occurrences <= 1) {\n if (Array.isArray(current)) {\n return current.map((item, index) => buildAt(current, index, item))\n }\n\n return mapValues(current, (entryValue, entryKey) => buildAt(current, entryKey, entryValue))\n }\n\n const site = definitionSites.get(current)\n const shouldDefineHere = site?.parent === parent && site.key === key\n\n const id = ids.get(current)\n if (id === undefined) {\n throw new Error(\"Compaction invariant violation: missing id for repeated object\")\n }\n\n if (!shouldDefineHere || emitted.has(current)) {\n return {\n [HighstateSignature.Ref]: true,\n id,\n }\n }\n\n emitted.add(current)\n\n return {\n [HighstateSignature.Id]: true,\n id,\n value: buildTreeChildren(current, current),\n }\n }\n\n // Prefer keeping the top-level value unwrapped for stability.\n if (value === null || typeof value !== \"object\") {\n return value\n }\n\n const topLevelOccurrences = counts.get(value) ?? 0\n if (topLevelOccurrences > 1) {\n const id = ensureId(value)\n emitted.add(value)\n\n return {\n [HighstateSignature.Id]: true,\n id,\n value: buildTreeChildren(value, value),\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((item, index) => buildAt(value, index, item))\n }\n\n return mapValues(value as Record<string, unknown>, (entryValue, entryKey) =>\n buildAt(value as Record<string, unknown>, entryKey, entryValue),\n )\n}\n\nexport function decompact<T>(value: unknown): T {\n const rawValuesById = new Map<number, unknown>()\n const placeholdersById = new Map<number, unknown>()\n\n function collect(current: unknown, visited: WeakSet<object>): void {\n const result = objectWithIdSchema.safeParse(current)\n if (result.success) {\n const { id } = result.data\n if (rawValuesById.has(id)) {\n throw new Error(`Duplicate compacted id ${id}`)\n }\n\n rawValuesById.set(id, result.data.value)\n collect(result.data.value, visited)\n return\n }\n\n if (current === null || current === undefined || typeof current !== \"object\") {\n return\n }\n\n if (visited.has(current)) {\n return\n }\n\n visited.add(current)\n\n if (Array.isArray(current)) {\n for (const item of current) {\n collect(item, visited)\n }\n return\n }\n\n for (const entryValue of Object.values(current)) {\n collect(entryValue, visited)\n }\n }\n\n function ensurePlaceholder(id: number): unknown {\n const existing = placeholdersById.get(id)\n if (existing !== undefined) {\n return existing\n }\n\n const raw = rawValuesById.get(id)\n if (raw === undefined) {\n throw new Error(`Unresolved compacted ref id ${id}`)\n }\n\n let placeholder: unknown\n if (raw !== null && typeof raw === \"object\") {\n placeholder = Array.isArray(raw) ? [] : {}\n } else {\n placeholder = raw\n }\n\n placeholdersById.set(id, placeholder)\n return placeholder\n }\n\n function resolve(current: unknown): unknown {\n const refResult = objectRefSchema.safeParse(current)\n if (refResult.success) {\n return ensurePlaceholder(refResult.data.id)\n }\n\n const withIdResult = objectWithIdSchema.safeParse(current)\n if (withIdResult.success) {\n return ensurePlaceholder(withIdResult.data.id)\n }\n\n if (current === null || current === undefined || typeof current !== \"object\") {\n return current\n }\n\n if (Array.isArray(current)) {\n return current.map(item => resolve(item))\n }\n\n return mapValues(current, entryValue => resolve(entryValue))\n }\n\n function fillPlaceholder(id: number, visitedIds: Set<number>): void {\n if (visitedIds.has(id)) {\n return\n }\n\n visitedIds.add(id)\n\n const raw = rawValuesById.get(id)\n if (raw === undefined) {\n throw new Error(`Unresolved compacted ref id ${id}`)\n }\n\n const placeholder = ensurePlaceholder(id)\n if (placeholder === null || typeof placeholder !== \"object\") {\n return\n }\n\n if (raw === null || typeof raw !== \"object\") {\n throw new Error(`Compaction invariant violation: id ${id} points to non-object value`)\n }\n\n const resolved = resolve(raw)\n\n if (Array.isArray(placeholder)) {\n if (!Array.isArray(resolved)) {\n throw new Error(`Compaction invariant violation: id ${id} array placeholder mismatch`)\n }\n\n placeholder.length = 0\n for (const item of resolved) {\n placeholder.push(item)\n }\n return\n }\n\n if (Array.isArray(resolved) || resolved === null || typeof resolved !== \"object\") {\n throw new Error(`Compaction invariant violation: id ${id} object placeholder mismatch`)\n }\n\n for (const [key, entryValue] of Object.entries(resolved)) {\n ;(placeholder as Record<string, unknown>)[key] = entryValue\n }\n }\n\n collect(value, new WeakSet<object>())\n\n for (const id of rawValuesById.keys()) {\n ensurePlaceholder(id)\n }\n\n const visitedIds = new Set<number>()\n for (const id of rawValuesById.keys()) {\n fillPlaceholder(id, visitedIds)\n }\n\n return resolve(value) as T\n}\n","import type { z } from \"zod\"\nimport { isNonNullish, pickBy } from \"remeda\"\n\ntype PickUndefinedKeys<T extends Record<string, unknown>> = T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: undefined extends T[K] ? K : never\n }[keyof T],\n undefined\n >\n\ntype AllOptionalKeys<T extends Record<string, unknown>> = T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: undefined extends T[K] ? K : never\n }[keyof T],\n undefined\n >\n\ntype HasRequired<T extends Record<string, unknown>> = T extends Record<string, never>\n ? false\n : [keyof T] extends [AllOptionalKeys<T>]\n ? false\n : true\n\ntype PickRecordsWithAnyRequired<T extends Record<string, Record<string, unknown>>> =\n T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: HasRequired<T[K]> extends true ? K : never\n }[keyof T],\n undefined\n >\n\nexport type OptionalEmptyRecords<T extends Record<string, Record<string, unknown>>> = {\n [K in Exclude<keyof T, PickRecordsWithAnyRequired<T>>]?: OptionalUndefinedFields<T[K]>\n} & {\n [K in PickRecordsWithAnyRequired<T>]: OptionalUndefinedFields<T[K]>\n}\n\nexport type OptionalUndefinedFields<T extends Record<string, unknown>> = {\n [K in PickUndefinedKeys<T>]?: T[K]\n} & {\n [K in Exclude<keyof T, PickUndefinedKeys<T>>]: T[K]\n}\n\n/**\n * Marks specific keys in a type as optional.\n *\n * @template T The type to modify.\n * @template K The keys to make optional.\n */\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\n\n/**\n * Marks specific keys in a type as required.\n *\n * @template T The type to modify.\n * @template K The keys to make required.\n */\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>\n\n/**\n * Formats a multiline string and trims the indentation.\n *\n * @param str The string to trim.\n * @returns The trimmed string.\n */\nexport function text(strings: TemplateStringsArray, ...values: unknown[]): string {\n // Convert all values to strings\n const stringValues = values.map(String)\n\n // Build full string with values interpolated\n let result = \"\"\n for (let i = 0; i < strings.length; i++) {\n result += strings[i]\n if (i < stringValues.length) {\n const value = stringValues[i]\n const lines = value.split(\"\\n\")\n const lastLineIndentMatch = strings[i].match(/(?:^|\\n)([ \\t]*)$/)\n const indent = lastLineIndentMatch ? lastLineIndentMatch[1] : \"\"\n\n result += lines.map((line, j) => (j === 0 ? line : indent + line)).join(\"\\n\")\n }\n }\n\n return trimIndentation(result)\n}\n\n/**\n * Removes the indentation from a multiline string.\n *\n * @param text The text to trim.\n * @returns The trimmed text.\n */\nexport function trimIndentation(text: string): string {\n const lines = text.split(\"\\n\")\n const indent = lines\n .filter(line => line.trim() !== \"\")\n .map(line => line.match(/^\\s*/)?.[0].length ?? 0)\n .reduce((min, indent) => Math.min(min, indent), Infinity)\n\n return lines\n .map(line => line.slice(indent))\n .join(\"\\n\")\n .trim()\n}\n\n/**\n * Converts bytes to a human-readable format.\n *\n * @param bytes The number of bytes.\n * @returns The human-readable string representation of the bytes.\n */\nexport function bytesToHumanReadable(bytes: number): string {\n const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\", \"TB\"]\n if (bytes === 0) return \"0 Bytes\"\n\n const i = Math.floor(Math.log(bytes) / Math.log(1024))\n return `${parseFloat((bytes / 1024 ** i).toFixed(2))} ${sizes[i]}`\n}\n\n/**\n * Checks if a value matches the given Zod schema and narrows the type accordingly.\n *\n * @param schema The Zod schema to check against.\n * @param value The value to check.\n * @returns `true` if the value matches the schema, `false` otherwise.\n */\nexport function check<TSchema extends z.ZodType>(\n schema: TSchema,\n value: unknown,\n): value is z.infer<TSchema> {\n return schema.safeParse(value).success\n}\n\n/**\n * Gets or creates a value in a map, using a factory function if the key does not exist.\n *\n * @param map The map to check.\n * @param key The key to look for.\n * @param createFn The function to create a new value if the key does not exist.\n * @returns The value associated with the key.\n */\nexport function getOrCreate<TKey, TValue>(\n map: Map<TKey, TValue>,\n key: TKey,\n createFn: (key: TKey) => TValue,\n): TValue {\n const existing = map.get(key)\n if (existing !== undefined) {\n return existing\n }\n\n const value = createFn(key)\n map.set(key, value)\n return value\n}\n\n/**\n * Strips nullish values from an object.\n *\n * @param obj The object to strip.\n * @returns A new object with all nullish values removed.\n */\nexport function stripNullish<T extends Record<string, unknown>>(obj: T) {\n return pickBy(obj, isNonNullish)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/cuidv2d.ts","../src/i18n.ts","../src/json-schema.ts","../src/meta.ts","../src/entity.ts","../src/evaluation.ts","../src/instance-input.ts","../src/component.ts","../src/instance.ts","../src/unit.ts","../src/trigger.ts","../src/pulumi.ts","../src/terminal.ts","../src/page.ts","../src/worker.ts","../src/utils.ts"],"names":["text","z","getEntity","boundary","mapValues","inputs","isStableInstanceInput","input","HighstateSignature","WellKnownInstanceCustomStatus","HighstateConfigKey","indent","pickBy","isNonNullish"],"mappings":";;;;;;;AAEA,IAAM,mBAAA,GAAsB,EAAA;AAE5B,SAAS,YAAY,GAAA,EAAyB;AAC5C,EAAA,MAAM,IAAA,GAAO,EAAA;AAEb,EAAA,IAAI,KAAA,GAAQ,EAAA;AACZ,EAAA,KAAA,MAAW,IAAA,IAAQ,GAAA,CAAI,MAAA,EAAO,EAAG;AAC/B,IAAA,KAAA,GAAA,CAAS,KAAA,IAAS,IAAA,IAAQ,MAAA,CAAO,IAAI,CAAA;AAAA,EACvC;AAEA,EAAA,OAAO,KAAA;A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AQO,SAAS,qBAAqB,KAAA,EAAuB;AAC1D,EAAA,MAAM,QAAQ,CAAC,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,MAAM,IAAI,CAAA;AAC9C,EAAA,IAAI,KAAA,KAAU,GAAG,OAAO,SAAA;AAExB,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,IAAI,CAAC,CAAA;AACrD,EAAA,OAAO,CAAA,EAAG,UAAA,CAAA,CAAY,KAAA,GAAQ,IAAA,IAAQ,CAAA,EAAG,OAAA,CAAQ,CAAC,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAClE;AASO,SAAS,KAAA,CACd,QACA,KAAA,EAC2B;AAC3B,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA,CAAE,OAAA;AACjC;AAUO,SAAS,WAAA,CACd,GAAA,EACA,GAAA,EACA,QAAA,EACQ;AACR,EAAA,MAAM,QAAA,GAAW,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AAC5B,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,MAAM,KAAA,GAAQ,SAAS,GAAG,CAAA;AAC1B,EAAA,GAAA,CAAI,GAAA,CAAI,KAAK,KAAK,CAAA;AAClB,EAAA,OAAO,KAAA;AACT;AAQO,SAAS,aAAgD,GAAA,EAAQ;AACtE,EAAA,OAAOC,MAAAA,CAAO,KAAKC,YAAY,CAAA;AACjC","file":"index.js","sourcesContent":["import { sha256 } from \"@noble/hashes/sha2.js\"\n\nconst cuidv2DefaultLength = 24\n\nfunction bufToBigInt(buf: Uint8Array): bigint {\n const bits = 8n\n\n let value = 0n\n for (const byte of buf.values()) {\n value = (value << bits) + BigInt(byte)\n }\n\n return value\n}\n\nfunction hashCuid2(input: string): string {\n const bytes = new TextEncoder().encode(input)\n const digest = sha256(bytes)\n\n return bufToBigInt(digest).toString(36).slice(1)\n}\n\nfunction normalizeCuid2Prefix(prefix: string): string {\n if (prefix >= \"a\" && prefix <= \"z\") {\n return prefix\n }\n\n if (prefix >= \"0\" && prefix <= \"9\") {\n const digit = prefix.charCodeAt(0) - \"0\".charCodeAt(0)\n return String.fromCharCode(\"a\".charCodeAt(0) + digit)\n }\n\n throw new Error(`Invalid CUID prefix character: ${prefix}`)\n}\n\n/**\n * Generates a CUIDv2d string from the given namespace and identity.\n *\n * CUIDv2d is a Highstate-specific ID format that generates a deterministic ID in the same format as CUIDv2.\n *\n * It uses the same encoding as CUIDv2, but instead of randomly generated values, it generates the ID based on the given namespace and identity.\n *\n * The generated ID is always 24 characters long.\n * The first character is guaranteed to be a letter (`a-z`) to match CUIDv2 expectations.\n * If the hash-derived first character would be a digit (`0-9`), it is deterministically mapped to a letter (`a-j`).\n */\nexport function cuidv2d(namespace: string, identity: string): string {\n const hashInput = `${namespace}:${identity}`\n const hashed = hashCuid2(hashInput)\n const raw = hashed.slice(0, cuidv2DefaultLength)\n const prefix = normalizeCuid2Prefix(raw[0]!)\n\n return `${prefix}${raw.slice(1)}`\n}\n","const knownAbbreviationsMap = new Map<string, string>()\n\nexport function registerKnownAbbreviations(abbreviations: string[]) {\n for (const abbr of abbreviations) {\n const lower = abbr.toLowerCase()\n if (!knownAbbreviationsMap.has(lower)) {\n knownAbbreviationsMap.set(lower, abbr)\n }\n }\n}\n\nexport function clearKnownAbbreviations() {\n knownAbbreviationsMap.clear()\n}\n\nexport function camelCaseToHumanReadable(text: string) {\n // split on: word boundaries between consecutive uppercase and lowercase letters,\n // single uppercase letters followed by lowercase, and separators\n const words = text\n .split(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|_|-|\\./)\n .filter(word => word.length > 0)\n\n return words\n .map(word => {\n const lower = word.toLowerCase()\n if (knownAbbreviationsMap.has(lower)) {\n return knownAbbreviationsMap.get(lower)\n }\n\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join(\" \")\n}\n","function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n}\n\n/**\n * Normalizes JSON schema produced by Zod exports.\n *\n * In particular, it merges intersections of object schemas represented as\n * `allOf: [{ type: \"object\", ... }, { type: \"object\", ... }, ...]` into a single\n * object schema so that validators treat `additionalProperties` consistently.\n */\nexport function fixJsonSchema(schema: unknown): unknown {\n if (!isRecord(schema)) {\n return schema\n }\n\n const allOf = schema.allOf\n if (Array.isArray(allOf) && allOf.length > 0) {\n const objectSchemas: Record<string, unknown>[] = []\n const otherSchemas: unknown[] = []\n\n for (const item of allOf) {\n if (isRecord(item) && item.type === \"object\") {\n objectSchemas.push(item)\n continue\n }\n\n otherSchemas.push(item)\n }\n\n if (objectSchemas.length > 1) {\n const required = new Set<string>()\n const properties: Record<string, unknown> = {}\n let additionalProperties: unknown\n\n for (const objectSchema of objectSchemas) {\n const objectRequired = objectSchema.required\n if (Array.isArray(objectRequired)) {\n for (const key of objectRequired) {\n if (typeof key === \"string\") {\n required.add(key)\n }\n }\n }\n\n const objectProperties = objectSchema.properties\n if (isRecord(objectProperties)) {\n for (const [key, value] of Object.entries(objectProperties)) {\n const existing = properties[key]\n if (existing === undefined) {\n properties[key] = value\n continue\n }\n\n properties[key] = { allOf: [existing, value] }\n }\n }\n\n if (\"additionalProperties\" in objectSchema) {\n if (additionalProperties === undefined) {\n additionalProperties = objectSchema.additionalProperties\n } else if (additionalProperties !== objectSchema.additionalProperties) {\n additionalProperties = false\n }\n }\n }\n\n const mergedObjectSchema: Record<string, unknown> = {\n type: \"object\",\n properties,\n ...(required.size > 0 ? { required: Array.from(required) } : {}),\n ...(additionalProperties !== undefined\n ? { additionalProperties }\n : { additionalProperties: false }),\n }\n\n const merged =\n otherSchemas.length === 0\n ? mergedObjectSchema\n : {\n ...schema,\n allOf: [mergedObjectSchema, ...otherSchemas],\n }\n\n return fixJsonSchema(merged)\n }\n }\n\n const next: Record<string, unknown> = { ...schema }\n\n if (Array.isArray(next.allOf)) {\n next.allOf = next.allOf.map(fixJsonSchema)\n }\n if (Array.isArray(next.anyOf)) {\n next.anyOf = next.anyOf.map(fixJsonSchema)\n }\n if (Array.isArray(next.oneOf)) {\n next.oneOf = next.oneOf.map(fixJsonSchema)\n }\n if (isRecord(next.properties)) {\n next.properties = Object.fromEntries(\n Object.entries(next.properties).map(([key, value]) => [key, fixJsonSchema(value)]),\n )\n }\n if (isRecord(next.items)) {\n next.items = fixJsonSchema(next.items)\n } else if (Array.isArray(next.items)) {\n next.items = next.items.map(fixJsonSchema)\n }\n if (isRecord(next.additionalProperties)) {\n next.additionalProperties = fixJsonSchema(next.additionalProperties)\n }\n\n return next\n}\n","import { z } from \"zod\"\n\nexport const objectMetaSchema = z.object({\n /**\n * Human-readable name of the object.\n *\n * Used in UI components for better user experience.\n */\n title: z.string().optional(),\n\n /**\n * The title used globally for the object.\n *\n * For example, the title of an instance secret is \"Password\" which is okay\n * to display in the instance secret list, but when the secret is displayed in a\n * global secret list the name should be more descriptive, like \"Proxmox Password\".\n */\n globalTitle: z.string().optional(),\n\n /**\n * Description of the object.\n *\n * Provides additional context for users and developers.\n */\n description: z.string().optional(),\n\n /**\n * The color of the object.\n *\n * Used in UI components to visually distinguish objects.\n */\n color: z.string().optional(),\n\n /**\n * Primary icon identifier.\n *\n * Should reference a iconify icon name, like \"mdi:server\" or \"gg:remote\".\n */\n icon: z.string().optional(),\n\n /**\n * The color of the primary icon.\n */\n iconColor: z.string().optional(),\n\n /**\n * The URL of the custom image that should be used as the icon or avatar.\n */\n avatarUrl: z.string().optional(),\n\n /**\n * The secondary icon identifier.\n *\n * Used to provide additional context or actions related to the object.\n *\n * Should reference a iconify icon name, like \"mdi:edit\" or \"mdi:delete\".\n */\n secondaryIcon: z.string().optional(),\n\n /**\n * The color of the secondary icon.\n */\n secondaryIconColor: z.string().optional(),\n})\n\n/**\n * The schema for object metadata used in more than a half of the Highstate objects.\n *\n * Consists of `title`, `description`, `icon`, and `iconColor` fields where the `title` is required.\n */\nexport const commonObjectMetaSchema = objectMetaSchema\n .pick({\n title: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({\n title: true,\n })\n\nexport const globalCommonObjectMetaSchema = objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({\n title: true,\n })\n\nexport const serviceAccountMetaSchema = objectMetaSchema\n .pick({\n title: true,\n description: true,\n avatarUrl: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true })\n\nexport const timestampsSchema = z.object({\n /**\n * The timestamp when the object was created.\n */\n createdAt: z.date(),\n\n /**\n * The timestamp when the object was last updated.\n */\n updatedAt: z.date(),\n})\n\n/**\n * The schema for strings that represent names in Highstate.\n *\n * The name:\n * - must be alphanumeric;\n * - can include dashes (`-`) as word separators and dots (`.`) as namespace separators;\n * - must begin with a letter;\n * - must be lowercase;\n * - must include from 2 to 64 characters.\n */\nexport const genericNameSchema = z\n .string()\n .regex(\n /^[a-z][a-z0-9-.]+$/,\n \"Name must start with a letter and can only contain lowercase letters, numbers, dashes (-) and dots (.)\",\n )\n .min(2)\n .max(64)\n\nexport const versionedNameSchema = z.union([\n z.templateLiteral([genericNameSchema, z.literal(\".\"), z.literal(\"v\"), z.number().int().min(1)]),\n\n // to prevent TypeScript matching \"proxmox.virtual-machine.v2\" as\n // 1. \"proxmox.v\"\n // 2. \"irtual-machine.v2\" and thinking it should be a number\n z.templateLiteral([\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n z.literal(\"v\"),\n z.number().int().min(1),\n ]),\n z.templateLiteral([\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n genericNameSchema,\n z.literal(\".\"),\n z.literal(\"v\"),\n z.number().int().min(1),\n ]),\n])\n\n/**\n * Parses a versioned name into its base name and version.\n *\n * @param name The versioned name to parse.\n * @returns A tuple containing the base name and version number.\n * @throws If the name is not in the correct format or if the version is invalid.\n */\nexport function parseVersionedName(name: string): [name: string, version: number] {\n const lastDotVIndex = name.lastIndexOf(\".v\")\n if (lastDotVIndex === -1) {\n throw new Error(`Invalid versioned name: ${name}`)\n }\n\n const baseName = name.substring(0, lastDotVIndex)\n const versionPart = name.substring(lastDotVIndex + 2) // +2 to skip \".v\"\n\n const version = parseInt(versionPart, 10)\n if (Number.isNaN(version) || version < 0) {\n throw new Error(`Invalid version in versioned name: ${name}`)\n }\n\n return [baseName, version]\n}\n\n/**\n * The schema for field names in Highstate.\n *\n * The field name:\n * - must be alphanumeric;\n * - must be in camelCase;\n * - must begin with a letter;\n * - must include from 2 to 64 characters.\n */\nexport const fieldNameSchema = z\n .string()\n .regex(/^[a-z][a-zA-Z0-9]+$/, \"Field name must start with a letter and be in camelCase format\")\n .min(2)\n .max(64)\n\nexport type ObjectMeta = z.infer<typeof objectMetaSchema>\nexport type CommonObjectMeta = z.infer<typeof commonObjectMetaSchema>\nexport type GlobalCommonObjectMeta = z.infer<typeof globalCommonObjectMetaSchema>\nexport type ServiceAccountMeta = z.infer<typeof serviceAccountMetaSchema>\nexport type GenericName = z.infer<typeof genericNameSchema>\nexport type VersionedName = z.infer<typeof versionedNameSchema>\nexport type FieldName = z.infer<typeof fieldNameSchema>\n","import type { IsEmptyObject, Simplify } from \"type-fest\"\nimport type { PartialKeys } from \"./utils\"\nimport { z } from \"zod\"\nimport { cuidv2d } from \"./cuidv2d\"\nimport { camelCaseToHumanReadable } from \"./i18n\"\nimport { fixJsonSchema } from \"./json-schema\"\nimport {\n objectMetaSchema,\n parseVersionedName,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\nexport const entityInclusionSchema = z.object({\n /**\n * The static type of the included entity.\n */\n type: versionedNameSchema,\n\n /**\n * Whether the included entity is required.\n * If false, the entity may be omitted.\n */\n required: z.boolean(),\n\n /**\n * Whether the included entity is multiple.\n */\n multiple: z.boolean(),\n\n /**\n * The name of the field where the included entity is embedded.\n */\n field: z.string(),\n})\n\n/**\n * The entity is some abstract object which can be passed from one component to another through their inputs and outputs.\n * Every entity must have a type.\n * Every component inputs and outputs will reference such types and only entities of the same type can be passed.\n */\nexport const entityModelSchema = z.object({\n /**\n * The static type of the entity.\n */\n type: versionedNameSchema,\n\n /**\n * The list of all extended entity types (direct and indirect).\n */\n extensions: z.string().array().optional(),\n\n /**\n * The list of directly extended entity types.\n */\n directExtensions: z.string().array().optional(),\n\n /**\n * The list of all included entities (directly or inherited from extensions).\n */\n inclusions: entityInclusionSchema.array().optional(),\n\n /**\n * The list of directly included entities.\n */\n directInclusions: entityInclusionSchema.array().optional(),\n\n /**\n * The JSON schema of the entity value.\n */\n schema: z.custom<z.core.JSONSchema.BaseSchema>(),\n\n /**\n * The extra metadata of the entity.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n }),\n\n /**\n * The CRC32 of the entity definition.\n */\n definitionHash: z.number(),\n})\n\nexport type EntityInclusion = z.infer<typeof entityInclusionSchema>\nexport type EntityModel = z.infer<typeof entityModelSchema>\nexport type EntityTypes = Record<VersionedName, true>\n\nexport declare const implementedTypes: unique symbol\nexport declare const entityOutput: unique symbol\nexport declare const entityInput: unique symbol\nexport declare const entityIncludes: unique symbol\n\nexport type Entity<\n TType extends VersionedName = VersionedName,\n TImplementedTypes extends EntityTypes = EntityTypes,\n TSchema extends z.ZodTypeAny = z.ZodTypeAny,\n TOutput = z.output<TSchema>,\n TInput = z.input<TSchema>,\n TIncludes extends Record<string, unknown> = Record<string, unknown>,\n> = {\n /**\n * The static type of the entity.\n */\n type: TType\n\n /**\n * The all types implemented by this entity including its own type.\n *\n * Does not exist at runtime.\n */\n [implementedTypes]: TImplementedTypes\n\n /**\n * The zod schema of the entity value.\n */\n schema: TSchema\n\n /**\n * The inferred value type of the entity.\n *\n * Does not exist at runtime.\n */\n [entityOutput]: TOutput\n\n /**\n * The inferred input type of the entity.\n *\n * Does not exist at runtime.\n */\n [entityInput]: TInput\n\n /**\n * The record of entity inclusions defined in `defineEntity({ includes: ... })`.\n *\n * Does not exist at runtime.\n */\n [entityIncludes]: TIncludes\n\n /**\n * The model of the entity.\n */\n model: EntityModel\n}\n\nexport type EntityValue<TEntity> = TEntity extends { [entityOutput]: infer TValue } ? TValue : never\n\n/**\n * The input type accepted by the entity schema.\n */\nexport type EntityValueInput<TEntity> = TEntity extends { [entityInput]: infer TValue }\n ? TValue\n : never\n\ntype DistributiveSimplify<T> = T extends unknown ? Simplify<T> : never\n\ntype ResolveIncludeEntity<TIncludeRef> = TIncludeRef extends { entity: infer E }\n ? E extends () => infer ER\n ? ER\n : E\n : TIncludeRef\n\ntype IsIncludeMultiple<TIncludeRef> = TIncludeRef extends { multiple?: infer M }\n ? M extends true\n ? true\n : false\n : false\n\ntype IsIncludeRequired<TIncludeRef> = TIncludeRef extends { required?: infer R }\n ? R extends false\n ? false\n : true\n : true\n\ntype IsOptionalOutputInclude<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true\n ? false\n : IsIncludeRequired<TIncludeRef> extends false\n ? true\n : false\n\ntype IsOptionalInputInclude<TIncludeRef> = IsIncludeRequired<TIncludeRef> extends false\n ? true\n : false\n\ntype IncludeOutputValue<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true\n ? EntityValue<ResolveIncludeEntity<TIncludeRef>>[]\n : EntityValue<ResolveIncludeEntity<TIncludeRef>>\n\ntype IncludeInputValue<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true\n ? EntityValueInput<ResolveIncludeEntity<TIncludeRef>>[]\n : EntityValueInput<ResolveIncludeEntity<TIncludeRef>>\n\ntype InclusionValueShape<TIncludes extends Record<string, EntityIncludeRef>> =\n TIncludes extends Record<string, never>\n ? Record<never, never>\n : {\n -readonly [K in keyof TIncludes as IsOptionalOutputInclude<TIncludes[K]> extends true\n ? never\n : K]-?: IncludeOutputValue<TIncludes[K]>\n } & {\n -readonly [K in keyof TIncludes as IsOptionalOutputInclude<TIncludes[K]> extends true\n ? K\n : never]?: IncludeOutputValue<TIncludes[K]>\n }\n\ntype InclusionInputShape<TIncludes extends Record<string, EntityIncludeRef>> =\n TIncludes extends Record<string, never>\n ? Record<never, never>\n : {\n -readonly [K in keyof TIncludes as IsOptionalInputInclude<TIncludes[K]> extends true\n ? never\n : K]-?: IncludeInputValue<TIncludes[K]>\n } & {\n -readonly [K in keyof TIncludes as IsOptionalInputInclude<TIncludes[K]> extends true\n ? K\n : never]?: IncludeInputValue<TIncludes[K]>\n }\n\ntype DefineEntityValue<\n TSchema extends z.ZodType,\n TExtends extends Record<string, Entity>,\n TIncludes extends Record<string, EntityIncludeRef>,\n> = DistributiveSimplify<\n z.output<MakeEntitySchema<AddSchemaExtensions<TSchema, TExtends>>> &\n InclusionValueShape<TIncludes>\n>\n\ntype DefineEntityInput<\n TSchema extends z.ZodType,\n TExtends extends Record<string, Entity>,\n TIncludes extends Record<string, EntityIncludeRef>,\n> = DistributiveSimplify<\n z.input<MakeEntitySchema<AddSchemaExtensions<TSchema, TExtends>>> & InclusionInputShape<TIncludes>\n>\n\ntype MakeEntitySchema<TSchema extends z.ZodTypeAny> = z.ZodIntersection<\n TSchema,\n typeof entityWithMetaSchema\n>\n\ntype EntityOptions<\n TType extends VersionedName,\n TSchema extends z.ZodType,\n TExtends extends Record<string, Entity>,\n TIncludes extends Record<string, EntityIncludeRef>,\n> = {\n /**\n * The static type of the entity.\n */\n type: TType\n\n /**\n * The JSON schema of the entity value.\n */\n schema: TSchema\n\n /**\n * The extra metadata of the entity.\n */\n meta?: PartialKeys<z.infer<typeof objectMetaSchema>, \"title\">\n\n /**\n * The list of entities to extend.\n *\n * The intersection of them will be used as the base schema and then intersected again with the provided schema.\n *\n * Note: Intersection does not mean inheritance or blind property merging.\n * If two base types have field with the same name but different types,\n * the resulting type of the field will be the intersection of the two types (and most likely `never`).\n */\n extends?: TExtends\n\n /**\n * The list of entities to include.\n *\n * Inclusion is more powerful mechanism that allows to embed other entities into this entity\n * and then substitute them instead of this entity when connected to component inputs of included types.\n */\n includes?: TIncludes\n}\n\nexport type EntityIncludeRef =\n | Entity\n | { entity: Entity; multiple?: boolean; required?: boolean }\n | { entity: () => Entity; multiple?: boolean; required?: boolean }\n\ntype EntityIncludeObjectRef = Exclude<EntityIncludeRef, Entity>\n\nfunction isEntityIncludeRef(value: EntityIncludeRef): value is EntityIncludeObjectRef {\n if (typeof value !== \"object\" || value === null || !(\"entity\" in value)) {\n return false\n }\n\n const entity = (value as { entity: unknown }).entity\n return typeof entity === \"function\" || isEntity(entity)\n}\n\ntype InclusionShape<TImplements extends Record<string, EntityIncludeRef>> = {\n -readonly [K in keyof TImplements]: TImplements[K] extends {\n entity: () => infer E\n multiple?: infer M\n required?: infer R\n }\n ? M extends true\n ? R extends false\n ? z.ZodDefault<z.ZodArray<z.ZodType<EntityValue<E>>>>\n : z.ZodArray<z.ZodType<EntityValue<E>>>\n : R extends false\n ? z.ZodOptional<z.ZodType<EntityValue<E>>>\n : z.ZodType<EntityValue<E>>\n : TImplements[K] extends {\n entity: infer E\n multiple?: infer M\n required?: infer R\n }\n ? M extends true\n ? R extends false\n ? z.ZodDefault<z.ZodArray<z.ZodType<EntityValue<E>>>>\n : z.ZodArray<z.ZodType<EntityValue<E>>>\n : R extends false\n ? z.ZodOptional<z.ZodType<EntityValue<E>>>\n : z.ZodType<EntityValue<E>>\n : TImplements[K] extends Entity\n ? z.ZodType<EntityValue<TImplements[K]>>\n : never\n}\n\ntype AddSchemaExtensions<\n TSchema extends z.ZodTypeAny,\n TExtends extends Record<string, Entity>,\n> = TExtends extends Record<string, never>\n ? TSchema\n : IsEmptyObject<TExtends> extends true\n ? TSchema\n : {\n [K in keyof TExtends]: AddSchemaExtensions<\n z.ZodIntersection<TSchema, TExtends[K][\"schema\"]>,\n Omit<TExtends, K>\n >\n }[keyof TExtends]\n\ntype AddTypeExtensions<\n TImplementedTypes extends EntityTypes,\n TExtends extends Record<string, Entity>,\n> = TExtends extends Record<string, never>\n ? TImplementedTypes\n : IsEmptyObject<TExtends> extends true\n ? TImplementedTypes\n : {\n [K in keyof TExtends]: AddTypeExtensions<\n TImplementedTypes & TExtends[K][typeof implementedTypes],\n Omit<TExtends, K>\n >\n }[keyof TExtends]\n\ntype AddIncludeExtensions<\n TIncludes extends Record<string, EntityIncludeRef>,\n TExtends extends Record<string, Entity>,\n> = TExtends extends Record<string, never>\n ? TIncludes\n : IsEmptyObject<TExtends> extends true\n ? TIncludes\n : {\n [K in keyof TExtends]: AddIncludeExtensions<\n TIncludes & ExtractEntityIncludes<TExtends[K][typeof entityIncludes]>,\n Omit<TExtends, K>\n >\n }[keyof TExtends]\n\ntype ExtractEntityIncludes<T> = T extends Record<string, EntityIncludeRef>\n ? T\n : Record<string, never>\n\ntype AddSchemaInclusions<\n TSchema extends z.ZodTypeAny,\n TImplements extends Record<string, EntityIncludeRef>,\n> = TImplements extends Record<string, never>\n ? TSchema\n : z.ZodIntersection<TSchema, z.ZodObject<InclusionShape<TImplements>>>\n\nexport function defineEntity<\n TType extends VersionedName,\n TSchema extends z.ZodType,\n const TExtends extends Record<string, Entity> = Record<string, never>,\n const TIncludes extends Record<string, EntityIncludeRef> = Record<never, never>,\n>(\n options: EntityOptions<TType, TSchema, TExtends, TIncludes>,\n): Entity<\n TType,\n Simplify<AddTypeExtensions<{ [K in TType]: true }, TExtends>>,\n MakeEntitySchema<AddSchemaExtensions<AddSchemaInclusions<TSchema, TIncludes>, TExtends>>,\n DefineEntityValue<TSchema, TExtends, AddIncludeExtensions<TIncludes, TExtends>>,\n DefineEntityInput<TSchema, TExtends, AddIncludeExtensions<TIncludes, TExtends>>,\n AddIncludeExtensions<TIncludes, TExtends>\n> {\n try {\n entityModelSchema.shape.type.parse(options.type)\n } catch (error) {\n throw new Error(`Invalid entity type \"${options.type}\"`, { cause: error })\n }\n\n if (!options.schema) {\n throw new Error(\"Entity schema is required\")\n }\n\n type IncludeRef = {\n field: string\n required: boolean\n multiple: boolean\n getEntity: () => Entity\n }\n\n const includeRefs: IncludeRef[] = Object.entries(options.includes ?? {}).map(\n ([field, entityRef]) => {\n if (isEntityIncludeRef(entityRef)) {\n const required = entityRef.required ?? true\n const multiple = entityRef.multiple ?? false\n\n let getEntity: () => Entity\n\n if (typeof entityRef.entity === \"function\") {\n const entity = entityRef.entity\n getEntity = entity\n } else {\n const entity = entityRef.entity\n getEntity = () => entity\n }\n\n return { field, required, multiple, getEntity }\n }\n\n const getEntity = () => entityRef\n return { field, required: true, multiple: false, getEntity }\n },\n )\n\n const inclusionShape = includeRefs.reduce(\n (shape, includeRef) => {\n let schema: z.ZodTypeAny = z.lazy(() => includeRef.getEntity().schema)\n\n if (includeRef.multiple) {\n schema = includeRef.required ? schema.array().min(1) : schema.array().default([])\n } else {\n schema = includeRef.required ? schema : schema.optional()\n }\n\n shape[includeRef.field] = schema\n return shape\n },\n {} as Record<string, z.ZodTypeAny>,\n )\n\n let finalSchema = Object.values(options.extends ?? {}).reduce(\n (schema, entity) => z.intersection(schema, entity.schema),\n options.schema as z.ZodType,\n )\n\n if (includeRefs.length > 0) {\n finalSchema = z.intersection(finalSchema, z.object(inclusionShape))\n }\n\n finalSchema = z.intersection(finalSchema, entityWithMetaSchema)\n\n const directInclusions = () =>\n includeRefs.map(includeRef => ({\n type: includeRef.getEntity().type,\n required: includeRef.required,\n multiple: includeRef.multiple,\n field: includeRef.field,\n }))\n const directExtensions = Object.values(options.extends ?? {}).map(entity => entity.type)\n\n const getInclusions = () => {\n const incs = [...directInclusions()]\n\n for (const entity of Object.values(options.extends ?? {})) {\n if (entity.model.inclusions) {\n incs.push(...entity.model.inclusions)\n }\n }\n\n return incs\n }\n\n const extensions = Object.values(options.extends ?? {}).reduce((exts, entity) => {\n exts.push(...(entity.model.extensions ?? []), entity.type)\n\n return exts\n }, [] as string[])\n\n try {\n let _schema: z.core.JSONSchema.BaseSchema\n\n return {\n type: options.type,\n schema: finalSchema,\n model: {\n type: options.type,\n extensions: extensions.length > 0 ? extensions : undefined,\n directExtensions: directExtensions.length > 0 ? directExtensions : undefined,\n get inclusions() {\n const incs = getInclusions()\n return incs.length > 0 ? incs : undefined\n },\n get directInclusions() {\n const incs = directInclusions()\n return incs.length > 0 ? incs : undefined\n },\n get schema() {\n if (!_schema) {\n // TODO: forbid unrepresentable types (and find way to filter out \"undefined\" literals)\n const rawSchema = z.toJSONSchema(finalSchema, {\n target: \"draft-7\",\n unrepresentable: \"any\",\n })\n\n _schema = fixJsonSchema(rawSchema) as z.core.JSONSchema.BaseSchema\n }\n\n return _schema\n },\n meta: {\n ...options.meta,\n title:\n options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0]),\n },\n // will be calculated by the library loader\n definitionHash: null!,\n },\n // biome-ignore lint/suspicious/noExplicitAny: we already typed return type\n } as any\n } catch (error) {\n throw new Error(`Failed to define entity \"${options.type}\"`, { cause: error })\n }\n}\n\nexport function isEntity(value: unknown): value is Entity {\n return typeof value === \"object\" && value !== null && \"model\" in value\n}\n\n/**\n * Checks whether the given entity can be assigned to the target type.\n *\n * An entity is considered assignable to a target type if:\n * - The entity's type is exactly the same as the target type.\n * - The entity extends the target type (either directly or indirectly).\n * - The entity includes the target type (either directly or indirectly).\n *\n * @param entity The entity to check.\n * @param target The target versioned name to check against.\n * @returns True if the entity is assignable to the target type, false otherwise.\n */\nexport function isAssignableTo(entity: EntityModel, target: VersionedName): boolean {\n if (entity.type === target) {\n return true\n }\n\n if (entity.extensions?.includes(target)) {\n return true\n }\n\n return entity.inclusions?.some(implementation => implementation.type === target) ?? false\n}\n\nexport const entityMetaSchema = z.object({\n /**\n * The type of the entity.\n */\n type: versionedNameSchema,\n\n /**\n * The globally unique identity of the entity.\n *\n * Anonymous entities are forbidden.\n */\n identity: z.string(),\n\n /**\n * The IDs of the entities to reference by this entity.\n * Must already exist in the system (or be at least defined by this unit).\n */\n references: z.record(z.string(), z.string().array()).optional(),\n\n ...objectMetaSchema.pick({\n title: true,\n description: true,\n icon: true,\n iconColor: true,\n }).shape,\n})\n\nexport type EntityMeta = z.infer<typeof entityMetaSchema>\n\nexport const entityWithMetaSchema = z.object({\n $meta: entityMetaSchema,\n})\n\nexport type EntityWithMeta = z.infer<typeof entityWithMetaSchema>\n\nexport type EntityWithRequiredMeta = EntityWithMeta & {\n $meta: EntityMeta\n}\n\nconst entityIdCache = new WeakMap<EntityWithMeta, string>()\nconst entityIdNamespace = \"3cd37048-7c50-43a9-a2b9-ff7ff2b5ee79\"\n\n/**\n * Gets the unique ID of an entity based on its type and identity.\n *\n * The ID is generated using a hash of the entity's type and identity, and is cached for future retrievals.\n *\n * @param entity The entity to get the ID for.\n * @returns The unique ID of the entity.\n */\nexport function getEntityId(entity: EntityWithMeta): string {\n if (!entity.$meta) {\n throw new Error(\"Entity $meta is required to generate an entity id\")\n }\n\n const existingId = entityIdCache.get(entity)\n\n if (existingId) {\n return existingId\n }\n\n const { type, identity } = entity.$meta\n\n const id = cuidv2d(entityIdNamespace, `${type}:${identity}`)\n entityIdCache.set(entity, id)\n\n return id\n}\n","import type { Component } from \"./component\"\nimport type { InstanceInput, InstanceModel, RuntimeInput } from \"./instance\"\nimport { mapValues } from \"remeda\"\n\nexport type RuntimeInstance = {\n instance: InstanceModel\n component: Component\n}\n\nexport const boundaryInput = Symbol(\"boundaryInput\")\n\nfunction isStableInstanceInput(value: unknown): value is InstanceInput {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"instanceId\" in value &&\n \"output\" in value &&\n typeof (value as { instanceId: unknown }).instanceId === \"string\" &&\n typeof (value as { output: unknown }).output === \"string\"\n )\n}\n\nfunction formatInstancePath(instance: InstanceModel): string {\n let result = instance.id\n while (instance.parentId) {\n const parent = runtimeInstances.get(instance.parentId)?.instance\n if (!parent) {\n break\n }\n\n result = `${parent.id} -> ${result}`\n instance = parent\n }\n\n return result\n}\n\nexport class InstanceNameConflictError extends Error {\n constructor(\n readonly instanceId: string,\n readonly firstPath: string,\n readonly secondPath: string,\n ) {\n super(\n `Multiple instances produced with the same instance ID \"${instanceId}\":\\n` +\n `1. ${firstPath}\\n` +\n `2. ${secondPath}`,\n )\n\n this.name = \"InstanceNameConflictError\"\n }\n}\n\nlet currentInstance: InstanceModel | null = null\n\nconst runtimeInstances: Map<string, RuntimeInstance> = new Map()\n\n/**\n * Resets the evaluation state, clearing all collected composite instances and runtime instances.\n */\nexport function resetEvaluation(): void {\n runtimeInstances.clear()\n currentInstance = null\n}\n\n/**\n * Returns all runtime instances collected during the evaluation.\n *\n * Note that these instances are not serializable.\n */\nexport function getRuntimeInstances(): RuntimeInstance[] {\n return Array.from(runtimeInstances.values())\n}\n\nexport function registerInstance<T>(component: Component, instance: InstanceModel, fn: () => T): T {\n const conflicting = runtimeInstances.get(instance.id)\n if (conflicting) {\n throw new InstanceNameConflictError(\n instance.id,\n formatInstancePath(conflicting.instance),\n formatInstancePath(instance),\n )\n }\n\n runtimeInstances.set(instance.id, { instance, component })\n\n let previousParentInstance: InstanceModel | null = null\n\n if (currentInstance) {\n instance.parentId = currentInstance.id\n }\n\n if (component.model.kind === \"composite\") {\n previousParentInstance = currentInstance\n currentInstance = instance\n }\n\n try {\n const rawOutputs = fn() as Record<string, RuntimeInput | RuntimeInput[] | undefined>\n const outputs = mapValues(rawOutputs ?? {}, outputGroup => {\n return [outputGroup].flat(2).filter(Boolean) as RuntimeInput[]\n })\n\n const toStableInputs = (\n outputGroup: RuntimeInput[],\n useBoundaryFallback: boolean,\n ): InstanceInput[] => {\n return outputGroup\n .map(output => (useBoundaryFallback ? output[boundaryInput] : output))\n .filter(isStableInstanceInput)\n .map(output => {\n return output.path\n ? {\n instanceId: output.instanceId,\n output: output.output,\n path: output.path,\n }\n : {\n instanceId: output.instanceId,\n output: output.output,\n }\n })\n }\n\n instance.resolvedOutputs = mapValues(outputs ?? {}, outputGroup =>\n toStableInputs(outputGroup, false),\n )\n instance.outputs = mapValues(outputs ?? {}, outputGroup => toStableInputs(outputGroup, true))\n\n // mark all outputs with the boundary input of the instance\n // keep object identity to preserve proxy-based deep accessors\n return mapValues(rawOutputs, (rawOutputGroup, outputKey) => {\n const outputRefs = (outputs[outputKey] ?? []).map(output => {\n if (output.provided) {\n output[boundaryInput] = { instanceId: instance.id, output: outputKey }\n }\n\n return output\n })\n\n if (component.model.outputs[outputKey]?.multiple) {\n const multipleOutput = (\n Array.isArray(rawOutputGroup) ? rawOutputGroup : outputRefs\n ) as RuntimeInput[] & Partial<{ [boundaryInput]: InstanceInput }>\n\n multipleOutput[boundaryInput] ??= { instanceId: instance.id, output: outputKey }\n\n return multipleOutput\n }\n\n return rawOutputGroup ?? outputRefs[0]\n }) as T\n } finally {\n if (previousParentInstance) {\n currentInstance = previousParentInstance\n }\n }\n}\n","import type { InstanceInput, MultipleInput, RequiredInput, RuntimeInput } from \"./instance\"\nimport { boundaryInput } from \"./evaluation\"\n\ntype CreateInputOptions = {\n boundary?: InstanceInput\n}\n\nfunction appendInputPath(currentPath: string | undefined, segment: string): string {\n return currentPath ? `${currentPath}.${segment}` : segment\n}\n\nfunction createRuntimeInputAccessor(input: RuntimeInput, boundary: InstanceInput): RuntimeInput {\n const accessorCache = input.provided ? undefined : new Map<string, RuntimeInput>()\n let currentBoundary = boundary\n\n return new Proxy(input as Record<string | symbol, unknown>, {\n get(target, property, receiver): unknown {\n const runtimeTarget = target as RuntimeInput\n\n if (property === boundaryInput) {\n return currentBoundary\n }\n\n if (typeof property !== \"string\") {\n return Reflect.get(target, property, receiver)\n }\n\n if (property in target) {\n return Reflect.get(target, property, receiver)\n }\n\n if (property === \"instanceId\" || property === \"output\" || property === \"path\") {\n return Reflect.get(target, property, receiver)\n }\n\n if (runtimeTarget.provided) {\n return Reflect.get(runtimeTarget, property, receiver)\n }\n\n const cached = accessorCache?.get(property)\n if (cached) {\n return cached\n }\n\n const nested = createNonProvidedInput(boundary, appendInputPath(runtimeTarget.path, property))\n accessorCache?.set(property, nested)\n\n return nested\n },\n\n set(target, property, value, receiver): boolean {\n if (property === boundaryInput) {\n currentBoundary = value as InstanceInput\n return true\n }\n\n return Reflect.set(target, property, value, receiver)\n },\n }) as RuntimeInput\n}\n\n/**\n * Creates a runtime input object with boundary and nested accessor behavior.\n *\n * If the source input is non-provided, this function returns a non-provided proxy\n * that can still safely chain nested properties.\n *\n * @param input The source input reference.\n * @param options Optional boundary override.\n */\nexport function createInput(\n input: RuntimeInput | InstanceInput,\n options: CreateInputOptions = {},\n): RuntimeInput {\n if (!(\"provided\" in input)) {\n const boundary = options.boundary ?? input\n\n const normalizedInput: RequiredInput = {\n provided: true,\n instanceId: input.instanceId,\n output: input.output,\n ...(input.path ? { path: input.path } : {}),\n [boundaryInput]: boundary,\n }\n\n return createRuntimeInputAccessor(normalizedInput, boundary)\n }\n\n if (!input.provided) {\n const boundary = options.boundary ?? input[boundaryInput]\n\n if (!boundary) {\n throw new Error(\"Cannot create non-provided input without boundary metadata\")\n }\n\n return createNonProvidedInput(boundary, input.path)\n }\n\n const boundary = options.boundary ?? input[boundaryInput]\n\n if (!boundary) {\n throw new Error(\"Cannot create provided input without boundary metadata\")\n }\n\n return createRuntimeInputAccessor(input as RequiredInput, boundary)\n}\n\n/**\n * Creates a non-provided runtime input with recursive chained access support.\n *\n * @param boundary The boundary reference propagated across chained properties.\n * @param path Optional path to assign to the non-provided input.\n */\nexport function createNonProvidedInput(boundary: InstanceInput, path?: string): RuntimeInput {\n const target: RuntimeInput = {\n provided: false,\n ...(path ? { path } : {}),\n [boundaryInput]: boundary,\n }\n\n return createRuntimeInputAccessor(target, boundary)\n}\n\nexport function createMultipleInputAccessor(\n inputs: RuntimeInput[],\n boundary: InstanceInput,\n): MultipleInput {\n const arrayInputs = [...inputs] as MultipleInput\n arrayInputs[boundaryInput] = boundary\n\n return new Proxy(arrayInputs as RuntimeInput[], {\n get(target, property, receiver): unknown {\n if (typeof property !== \"string\") {\n return Reflect.get(target, property, receiver)\n }\n\n if (\n property === \"length\" ||\n property === \"map\" ||\n property === \"filter\" ||\n property === \"path\" ||\n property in target\n ) {\n return Reflect.get(target, property, receiver)\n }\n\n const unfolded = target.flatMap(input => {\n if (!input.provided) {\n return []\n }\n\n const selected = (input as Record<string, unknown>)[property]\n\n if (selected === undefined || selected === null) {\n return []\n }\n\n if (Array.isArray(selected)) {\n return selected as RuntimeInput[]\n }\n\n return [selected as RuntimeInput]\n })\n\n return createMultipleInputAccessor(unfolded, boundary)\n },\n }) as MultipleInput\n}\n\nexport function createDeepOutputAccessor(output: RuntimeInput): RuntimeInput {\n const normalizedOutput = createInput(output)\n\n if (!normalizedOutput.provided) {\n return normalizedOutput\n }\n\n const accessorCache = new Map<string, unknown>()\n\n return new Proxy(normalizedOutput as Record<string | symbol, unknown>, {\n get(target, property, receiver): unknown {\n if (typeof property !== \"string\") {\n return Reflect.get(target, property, receiver)\n }\n\n if (\n property === \"provided\" ||\n property === \"instanceId\" ||\n property === \"output\" ||\n property === \"path\"\n ) {\n return Reflect.get(target, property, receiver)\n }\n\n if (property in target) {\n return Reflect.get(target, property, receiver)\n }\n\n const cached = accessorCache.get(property)\n if (cached !== undefined) {\n return cached\n }\n\n const providedTarget = target as RequiredInput\n\n const nextInput = createInput(\n {\n ...providedTarget,\n path: appendInputPath(providedTarget.path, property),\n },\n { boundary: providedTarget[boundaryInput] },\n )\n\n const resolved = createDeepOutputAccessor(nextInput)\n accessorCache.set(property, resolved)\n\n return resolved\n },\n }) as RuntimeInput\n}\n","/** biome-ignore-all lint/suspicious/noExplicitAny: maybe fix later */\n\nimport type { Simplify } from \"type-fest\"\nimport type { Entity, implementedTypes } from \"./entity\"\nimport type { OptionalEmptyRecords, PartialKeys } from \"./utils\"\nimport { isNonNullish, mapValues, pickBy, uniqueBy } from \"remeda\"\nimport { z } from \"zod\"\nimport { boundaryInput, registerInstance } from \"./evaluation\"\nimport { camelCaseToHumanReadable } from \"./i18n\"\nimport {\n type EntityInput,\n type InstanceId,\n type InstanceInput,\n inputKey,\n type MultipleInput,\n type RequiredInput,\n type RequiredMultipleInput,\n type RuntimeInput,\n} from \"./instance\"\nimport {\n createDeepOutputAccessor,\n createInput,\n createMultipleInputAccessor,\n createNonProvidedInput,\n} from \"./instance-input\"\nimport {\n fieldNameSchema,\n genericNameSchema,\n objectMetaSchema,\n parseVersionedName,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\nexport const runtimeSchema = Symbol(\"runtimeSchema\")\n\nlet validationEnabled = true\n\nexport function setValidationEnabled(enabled: boolean): void {\n validationEnabled = enabled\n}\n\nexport const componentKindSchema = z.enum([\"composite\", \"unit\"])\nexport type ComponentKind = z.infer<typeof componentKindSchema>\n\nexport const componentArgumentSchema = z.object({\n /**\n * The JSON schema of the argument value.\n */\n schema: z.custom<z.core.JSONSchema.BaseSchema>(),\n\n /**\n * The original Zod schema of the argument.\n *\n * Only available at runtime.\n */\n [runtimeSchema]: z.instanceof(z.ZodType).optional(),\n\n /**\n * Whether the argument is required.\n */\n required: z.boolean(),\n\n /**\n * The extra metadata of the argument.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n globalTitle: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n }),\n})\n\nexport type ComponentArgument = z.infer<typeof componentArgumentSchema>\n\nexport type FullComponentArgumentOptions = {\n schema: z.ZodType\n meta?: PartialKeys<ComponentArgument[\"meta\"], \"title\">\n}\n\nexport type ComponentArgumentOptions = z.ZodType | FullComponentArgumentOptions\n\nexport type ComponentArgumentOptionsToSchema<T extends ComponentArgumentOptions> =\n T extends FullComponentArgumentOptions ? T[\"schema\"] : T\n\nexport const componentInputSchema = z.object({\n /**\n * The type of the entity passed through the input.\n */\n type: versionedNameSchema,\n\n /**\n * The input name this output type is derived from.\n *\n * If set, the output uses the referenced input as its fallback type source.\n */\n fromInput: fieldNameSchema.optional(),\n\n /**\n * Whether the input is required.\n */\n required: z.boolean(),\n\n /**\n * Whether the input can have multiple values.\n */\n multiple: z.boolean(),\n\n /**\n * The extra metadata of the input.\n */\n meta: objectMetaSchema.required({ title: true }).pick({\n title: true,\n description: true,\n }),\n})\n\nexport type ComponentInput = z.infer<typeof componentInputSchema>\n\nexport type FullComponentInputOptions = {\n entity: Entity\n required?: boolean\n multiple?: boolean\n meta?: PartialKeys<ComponentInput[\"meta\"], \"title\">\n}\n\nexport type ComponentInputOptions = Entity | FullComponentInputOptions\n\nexport type FromInputComponentOutputOptions<TInputName extends string = string> = {\n fromInput: TInputName\n meta?: PartialKeys<ComponentInput[\"meta\"], \"title\">\n}\n\nexport type ComponentOutputOptions<\n TInputs extends Record<string, ComponentInputOptions> = Record<string, ComponentInputOptions>,\n> = ComponentInputOptions | FromInputComponentOutputOptions<Extract<keyof TInputs, string>>\n\ntype ComponentInputOptionsToOutputRef<T extends ComponentInputOptions> = T extends Entity\n ? EntityInput<T>\n : T extends FullComponentInputOptions\n ? T[\"multiple\"] extends true\n ? RequiredMultipleInput<EntityInput<T[\"entity\"]>>\n : EntityInput<T[\"entity\"]>\n : never\n\ntype MultipleInputConstructorValue<TEntity extends Entity> =\n | MultipleInput<EntityInput<TEntity>>\n | EntityInput<TEntity>[]\n | InstanceInput[]\n | Array<MultipleInput<EntityInput<TEntity>> | EntityInput<TEntity>[] | InstanceInput[]>\n\n/**\n * The type-level specification of a component input hold by the component model.\n */\nexport type ComponentInputSpec<TEntity extends Entity = Entity> = [\n entity: TEntity,\n required: boolean,\n multiple: boolean,\n]\n\nexport type ComponentInputOptionsToSpec<T extends ComponentInputOptions> = T extends Entity\n ? [T, true, false]\n : T extends FullComponentInputOptions\n ? T[\"required\"] extends false\n ? T[\"multiple\"] extends true\n ? ComponentInputSpec<T[\"entity\"]> extends infer Spec\n ? Spec extends ComponentInputSpec\n ? [Spec[0], false, true]\n : never\n : never\n : ComponentInputSpec<T[\"entity\"]> extends infer Spec\n ? Spec extends ComponentInputSpec\n ? [Spec[0], false, false]\n : never\n : never\n : T[\"multiple\"] extends true\n ? ComponentInputSpec<T[\"entity\"]> extends infer Spec\n ? Spec extends ComponentInputSpec\n ? [Spec[0], true, true]\n : never\n : never\n : ComponentInputSpec<T[\"entity\"]> extends infer Spec\n ? Spec extends ComponentInputSpec\n ? [Spec[0], true, false]\n : never\n : never\n : never\n\nexport type ComponentOutputOptionsToSpec<\n TOutput extends ComponentOutputOptions<TInputs>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = TOutput extends FromInputComponentOutputOptions<infer TInputName>\n ? TInputName extends keyof TInputs\n ? ComponentInputOptionsToSpec<TInputs[TInputName]>\n : never\n : TOutput extends ComponentInputOptions\n ? ComponentInputOptionsToSpec<TOutput>\n : never\n\nexport type ComponentInputOptionsMapToSpecMap<T extends Record<string, ComponentInputOptions>> =\n T extends Record<string, never>\n ? Record<string, never>\n : { [K in keyof T]: ComponentInputOptionsToSpec<T[K]> }\n\ntype ComponentInputMapToValue<T extends Record<string, ComponentInputOptions>> = {\n [K in keyof T]: ComponentInputOptionsToOutputRef<T[K]>\n}\n\ntype ComponentOutputMapToCreateOutputValue<\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = {\n [K in keyof TOutputs]: InputSpecToInputRef<ComponentOutputOptionsToSpec<TOutputs[K], TInputs>>\n}\n\ntype ComponentOutputMapToReturnType<\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = TOutputs extends Record<string, never> // biome-ignore lint/suspicious/noConfusingVoidType: this is return type\n ? void\n : Partial<ComponentOutputMapToCreateOutputValue<TOutputs, TInputs>>\n\nexport type ComponentParams<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = {\n id: InstanceId\n name: string\n args: { [K in keyof TArgs]: z.infer<ComponentArgumentOptionsToSchema<TArgs[K]>> }\n inputs: ComponentInputMapToValue<TInputs>\n}\n\nexport type InputComponentParams<\n TArgs extends Record<string, unknown>,\n TInputs extends Record<string, unknown>,\n> = {\n name: string\n} & OptionalEmptyRecords<{\n args: TArgs\n inputs: TInputs\n}>\n\nexport type ComponentOptions<\n TType extends VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>>,\n> = {\n /**\n * The type of the component.\n * Must be a valid versioned name.\n *\n * Examples: `proxmox.virtual-machine.v1`, `common.server.v1`.\n */\n type: TType\n\n /**\n * The extra metadata of the component.\n *\n * If title or defaultNamePrefix is not provided, they will be generated from the type.\n */\n meta?: PartialKeys<ComponentModel[\"meta\"], \"title\" | \"defaultNamePrefix\">\n\n /**\n * The specification of the component arguments.\n */\n args?: TArgs\n\n /**\n * The specification of the component inputs.\n */\n inputs?: TInputs\n\n /**\n * The specification of the component outputs.\n */\n outputs?: TOutputs\n\n /**\n * The create function of the component.\n *\n * It can create instances of other components and return their outputs.\n *\n * Note: All created instances must guarantee unique ids within the project.\n * Their names are not automatically prefixed with the component name,\n * so you must prefix them manually if needed or guarantee uniqueness in another way.\n */\n create: (\n params: ComponentParams<TArgs, TInputs>,\n ) => ComponentOutputMapToReturnType<TOutputs, TInputs>\n\n /**\n * For internal use only.\n */\n [kind]?: ComponentKind\n}\n\n// Models\nexport const componentModelSchema = z.object({\n /**\n * The type of the component.\n */\n type: genericNameSchema,\n\n /**\n * The kind of the component.\n */\n kind: componentKindSchema,\n\n /**\n * The record of the argument schemas.\n */\n args: z.record(fieldNameSchema, componentArgumentSchema),\n\n /**\n * The record of the input schemas.\n */\n inputs: z.record(fieldNameSchema, componentInputSchema),\n\n /**\n * The record of the output schemas.\n */\n outputs: z.record(fieldNameSchema, componentInputSchema),\n\n /**\n * The extra metadata of the component.\n */\n meta: objectMetaSchema\n .required({ title: true })\n .pick({\n title: true,\n description: true,\n color: true,\n icon: true,\n iconColor: true,\n secondaryIcon: true,\n secondaryIconColor: true,\n })\n .extend({\n /**\n * The category of the component.\n *\n * Used to group components in the UI.\n */\n category: z.string().optional(),\n\n /**\n * The default name prefix for the component instances.\n *\n * Used to generate default names for the instances.\n */\n defaultNamePrefix: z.string(),\n }),\n\n /**\n * The CRC32 of the component definition.\n */\n definitionHash: z.number(),\n})\n\nexport type ComponentModel = z.infer<typeof componentModelSchema>\n\ntype InputSpecToInputRef<T extends ComponentInputSpec> = T[1] extends true\n ? T[2] extends true\n ? MultipleInputConstructorValue<T[0]>\n : EntityInput<T[0]> | InstanceInput\n : T[2] extends true\n ? MultipleInputConstructorValue<T[0]>\n : EntityInput<T[0]> | InstanceInput\n\ntype InputSpecToUnitOutputRef<T extends ComponentInputSpec> = T[2] extends true\n ? RequiredMultipleInput<EntityInput<T[0]>>\n : RequiredInput<EntityInput<T[0]>>\n\ntype InputSpecToCompositeOutputRef<T extends ComponentInputSpec> = T[2] extends true\n ? RequiredMultipleInput<EntityInput<T[0]>>\n : EntityInput<T[0]>\n\nexport type InputSpecMapToInputRefMap<TInputs extends Record<string, ComponentInputSpec>> =\n TInputs extends Record<string, [string, never, never]>\n ? Record<string, never>\n : {\n [K in keyof TInputs as TInputs[K][1] extends true ? K : never]-?: InputSpecToInputRef<\n TInputs[K]\n >\n } & {\n [K in keyof TInputs as TInputs[K][1] extends true ? never : K]?: InputSpecToInputRef<\n TInputs[K]\n >\n }\n\nexport type OutputRefMap<\n TInputs extends Record<string, ComponentInputSpec>,\n TKind extends ComponentKind = \"composite\",\n> = TInputs extends Record<string, [string, never, never]>\n ? Record<string, never>\n : {\n [K in keyof TInputs]: TKind extends \"unit\"\n ? InputSpecToUnitOutputRef<TInputs[K]>\n : InputSpecToCompositeOutputRef<TInputs[K]>\n }\n\ntype StaticOutputRefByKind<\n TOutputSpec extends ComponentInputSpec,\n TKind extends ComponentKind,\n> = TKind extends \"unit\"\n ? InputSpecToUnitOutputRef<TOutputSpec>\n : InputSpecToCompositeOutputRef<TOutputSpec>\n\ntype ResolveForwardedOutputRef<\n TForwardedInputName extends string,\n TCallInputs extends Record<string, unknown>,\n TFallbackSpec extends ComponentInputSpec,\n TKind extends ComponentKind,\n> = TForwardedInputName extends keyof TCallInputs\n ? NonNullable<TCallInputs[TForwardedInputName]>\n : StaticOutputRefByKind<TFallbackSpec, TKind>\n\ntype ResolveOutputRefForCall<\n TOutputOption,\n TCallInputs extends Record<string, unknown>,\n TFallbackSpec extends ComponentInputSpec,\n TKind extends ComponentKind,\n> = TOutputOption extends FromInputComponentOutputOptions<infer TInputName>\n ? ResolveForwardedOutputRef<TInputName, TCallInputs, TFallbackSpec, TKind>\n : StaticOutputRefByKind<TFallbackSpec, TKind>\n\ntype ResolveOutputRefMapForCall<\n TOutputSpecs extends Record<string, ComponentInputSpec>,\n TOutputOptions extends Record<string, ComponentOutputOptions<TInputOptions>>,\n TInputOptions extends Record<string, ComponentInputOptions>,\n TCallInputs extends Record<string, unknown>,\n TKind extends ComponentKind,\n> = {\n [K in keyof TOutputSpecs]: K extends keyof TOutputOptions\n ? [TOutputOptions[K]] extends [never]\n ? StaticOutputRefByKind<TOutputSpecs[K], TKind>\n : ResolveOutputRefForCall<TOutputOptions[K], TCallInputs, TOutputSpecs[K], TKind>\n : StaticOutputRefByKind<TOutputSpecs[K], TKind>\n}\n\ntype IncludesAllExpectedTypes<\n TProvided extends Record<string, unknown>,\n TExpected extends Record<string, unknown>,\n> = Exclude<keyof TExpected, keyof TProvided> extends never ? true : false\n\ntype ExtractProvidedInputTypes<TValue> = TValue extends RuntimeInput<infer TTypes, any>\n ? TTypes\n : TValue extends Array<infer TItem>\n ? ExtractProvidedInputTypes<TItem>\n : never\n\ntype ValidateProvidedInputValue<TValue, TExpectedSpec extends ComponentInputSpec> = [\n ExtractProvidedInputTypes<TValue>,\n] extends [never]\n ? TValue\n : ExtractProvidedInputTypes<TValue> extends infer TProvidedTypes\n ? TProvidedTypes extends Record<string, unknown>\n ? IncludesAllExpectedTypes<\n TProvidedTypes,\n TExpectedSpec[0][typeof implementedTypes]\n > extends true\n ? TValue\n : never\n : never\n : never\n\ntype ValidateCallInputs<\n TCallInputs extends Record<string, unknown>,\n TInputSpecs extends Record<string, ComponentInputSpec>,\n> = {\n [K in keyof TCallInputs]: K extends keyof TInputSpecs\n ? ValidateProvidedInputValue<TCallInputs[K], TInputSpecs[K]>\n : TCallInputs[K]\n}\n\nexport const originalCreate = Symbol(\"originalCreate\")\nexport const kind = Symbol(\"kind\")\n\nexport type Component<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, z.ZodType> = Record<string, never>,\n TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TKind extends ComponentKind = \"composite\",\n TInputOptions extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputOptions extends Record<string, ComponentOutputOptions<TInputOptions>> = Record<\n string,\n never\n >,\n> = {\n /**\n * The type of the component.\n */\n type: TType\n\n /**\n * The non-generic model of the component.\n */\n model: ComponentModel\n\n /**\n * The entities used in the inputs or outputs of the component.\n */\n entities: Map<string, Entity>\n\n <TCallInputs extends InputSpecMapToInputRefMap<TInputs> = InputSpecMapToInputRefMap<TInputs>>(\n context: InputComponentParams<\n { [K in keyof TArgs]: z.input<TArgs[K]> },\n InputSpecMapToInputRefMap<TInputs>\n > & {\n inputs?: ValidateCallInputs<TCallInputs, TInputs>\n },\n ): ResolveOutputRefMapForCall<TOutputs, TOutputOptions, TInputOptions, TCallInputs, TKind>\n\n /**\n * The original create function.\n *\n * Used to calculate the definition hash.\n */\n [originalCreate]: (params: InputComponentParams<any, any>) => any\n}\n\nexport function defineComponent<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,\n TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>> = Record<string, never>,\n TKind extends ComponentKind = \"composite\",\n>(\n options: ComponentOptions<TType, TArgs, TInputs, TOutputs> & { [kind]?: TKind },\n): Component<\n TType,\n { [K in keyof TArgs]: ComponentArgumentOptionsToSchema<TArgs[K]> },\n { [K in keyof TInputs]: ComponentInputOptionsToSpec<TInputs[K]> },\n { [K in keyof TOutputs]: ComponentOutputOptionsToSpec<TOutputs[K], TInputs> },\n TKind,\n TInputs,\n TOutputs\n> {\n try {\n componentModelSchema.shape.type.parse(options.type)\n } catch (error) {\n throw new Error(`Invalid component type \"${options.type}\"`, { cause: error })\n }\n\n if (!options.create) {\n throw new Error(\"Component create function is required\")\n }\n\n const entities = new Map<string, Entity>()\n const mapInput = createInputMapper(entities)\n const mapOutput = createOutputMapper(options.inputs, entities)\n\n const model: ComponentModel = {\n type: options.type,\n kind: options[kind] ?? \"composite\",\n args: mapValues(options.args ?? {}, mapArgument),\n inputs: mapValues(options.inputs ?? {}, mapInput),\n outputs: mapValues(options.outputs ?? {}, mapOutput),\n meta: {\n ...options.meta,\n title: options.meta?.title || camelCaseToHumanReadable(parseVersionedName(options.type)[0]),\n defaultNamePrefix:\n options.meta?.defaultNamePrefix ||\n parseVersionedName(options.type)[0].split(\".\").slice(-1)[0],\n },\n // will be calculated by library loader\n definitionHash: null!,\n }\n\n type RuntimeCreateInputGroup =\n | RuntimeInput\n | InstanceInput\n | (Array<RuntimeCreateInputGroup> & Partial<{ [boundaryInput]: InstanceInput }>)\n\n function create(params: InputComponentParams<any, Record<string, RuntimeCreateInputGroup>>): any {\n const { name, args = {}, inputs } = params\n const instanceId = getInstanceId(options.type, name)\n\n const flatInputs: Record<string, RuntimeInput[]> = {}\n const tracedInputs: Record<string, InstanceInput[]> = {}\n const runtimeInputKey = (input: RuntimeInput): string => {\n if (input.provided) {\n return inputKey(input)\n }\n\n return `missing:${input[boundaryInput].instanceId}:${input[boundaryInput].output}`\n }\n\n for (const [key, inputGroup] of Object.entries(inputs ?? {})) {\n if (!(key in model.inputs)) {\n continue\n }\n\n if (!inputGroup) {\n continue\n }\n\n if (!Array.isArray(inputGroup)) {\n const normalizedInput = normalizeIncomingInput(inputGroup, key)\n tracedInputs[key] = [normalizedInput[boundaryInput]]\n flatInputs[key] = [normalizedInput]\n continue\n }\n\n const { group, inputs } = normalizeIncomingInputGroup(inputGroup, key)\n\n tracedInputs[key] = uniqueBy(group, inputKey)\n flatInputs[key] = uniqueBy(inputs, runtimeInputKey)\n }\n\n return registerInstance(\n create as unknown as Component,\n {\n id: instanceId,\n type: options.type,\n kind: options[kind] ?? \"composite\",\n name,\n args,\n inputs: tracedInputs,\n resolvedInputs: mapValues(flatInputs, inputs => {\n return inputs\n .filter(input => input.provided)\n .map(input => ({\n instanceId: input.instanceId,\n output: input.output,\n ...(input.path ? { path: input.path } : {}),\n }))\n }),\n },\n () => {\n const markedInputs = mapValues(model.inputs, (componentInput, key) => {\n if (!componentInput.multiple) {\n const input = flatInputs[key]?.[0]\n\n if (input?.provided) {\n return createDeepOutputAccessor({\n ...input,\n [boundaryInput]: { instanceId: instanceId, output: key },\n })\n }\n\n return createNonProvidedInput({ instanceId: instanceId, output: key })\n }\n\n const inputs = (flatInputs[key] ?? []).filter(isProvidedRuntimeInput).map(input =>\n createDeepOutputAccessor({\n ...input,\n [boundaryInput]: { instanceId: instanceId, output: key },\n }),\n )\n\n const multipleBoundary = { instanceId, output: key }\n return createMultipleInputAccessor(inputs, multipleBoundary)\n })\n\n const outputs: Record<string, RuntimeInput | MultipleInput | null | undefined> =\n options.create({\n id: instanceId,\n name,\n args: processArgs(instanceId, create.model, args) as any,\n inputs: markedInputs as any,\n }) ?? {}\n\n const normalizedOutputs = normalizeCreateOutputs(outputs, model, instanceId)\n\n return withDeepOutputAccessors(normalizedOutputs, model, instanceId)\n },\n )\n\n function normalizeIncomingInput(\n input: RuntimeInput | InstanceInput,\n inputName: string,\n ): RuntimeInput {\n if (isStableInstanceInput(input)) {\n return createInput(input)\n }\n\n const runtimeInput = input as RuntimeInput\n\n if (runtimeInput.provided) {\n const inputBoundary = runtimeInput[boundaryInput] ?? {\n instanceId: runtimeInput.instanceId,\n output: runtimeInput.output,\n ...(runtimeInput.path ? { path: runtimeInput.path } : {}),\n }\n\n return createInput(runtimeInput, { boundary: inputBoundary })\n }\n\n return createNonProvidedInput(\n runtimeInput[boundaryInput] ?? { instanceId, output: inputName },\n )\n }\n\n function normalizeIncomingInputGroup(\n inputGroup: RuntimeCreateInputGroup,\n inputName: string,\n ): { group: InstanceInput[]; inputs: RuntimeInput[] } {\n const group: InstanceInput[] = []\n const inputs: RuntimeInput[] = []\n\n const visit = (value: RuntimeCreateInputGroup): void => {\n if (Array.isArray(value)) {\n const arrayBoundary = (value as Partial<{ [boundaryInput]: InstanceInput }>)[\n boundaryInput\n ]\n\n if (arrayBoundary) {\n group.push(arrayBoundary)\n }\n\n for (const item of value) {\n if (!item) {\n continue\n }\n\n visit(item)\n }\n\n return\n }\n\n const normalizedInput = normalizeIncomingInput(value, inputName)\n group.push(normalizedInput[boundaryInput])\n inputs.push(normalizedInput)\n }\n\n visit(inputGroup)\n\n return { group, inputs }\n }\n }\n\n try {\n create.entities = entities\n create.model = model\n\n create[originalCreate] = options.create\n\n return create as any\n } catch (error) {\n throw new Error(`Failed to define component \"${options.type}\"`, { cause: error })\n }\n}\n\nfunction processArgs(\n instanceId: InstanceId,\n model: ComponentModel,\n args: Record<string, unknown>,\n): Record<string, unknown> {\n if (!validationEnabled) {\n return args\n }\n\n const validatedArgs: Record<string, unknown> = {}\n\n for (const [key, arg] of Object.entries(model.args)) {\n if (arg.schema) {\n const result = arg[runtimeSchema]!.safeParse(args[key])\n\n if (!result.success) {\n throw new Error(\n `Invalid argument \"${key}\" in instance \"${instanceId}\": ${result.error.message}`,\n )\n }\n\n validatedArgs[key] = result.data\n } else {\n validatedArgs[key] = args[key]\n }\n }\n\n return validatedArgs\n}\n\nfunction withDeepOutputAccessors(\n outputs: Record<string, RuntimeInput[]>,\n model: ComponentModel,\n instanceId: InstanceId,\n): Record<string, RuntimeInput | MultipleInput> {\n return mapValues(outputs, (outputGroup, outputName) => {\n const outputSpec = model.outputs[outputName]\n if (!outputSpec) {\n return outputGroup[0]!\n }\n\n const normalizedOutputs = outputGroup.map(output => createDeepOutputAccessor(output))\n\n if (outputSpec.multiple) {\n return createMultipleInputAccessor(normalizedOutputs, {\n instanceId,\n output: outputName,\n })\n }\n\n return normalizedOutputs[0]!\n })\n}\n\nfunction isProvidedRuntimeInput(input: RuntimeInput): input is RequiredInput {\n return input.provided\n}\n\nfunction normalizeCreateOutputGroup(\n outputGroup: RuntimeInput | InstanceInput | Array<RuntimeInput | InstanceInput>,\n instanceId: InstanceId,\n outputName: string,\n): RuntimeInput[] {\n return [outputGroup]\n .flat(2)\n .filter(isNonNullish)\n .map(output => {\n if (isStableInstanceInput(output)) {\n return createInput(output)\n }\n\n const runtimeOutput = output as RuntimeInput\n\n if (runtimeOutput.provided) {\n const stableBoundary = runtimeOutput[boundaryInput] ?? {\n instanceId: runtimeOutput.instanceId,\n output: runtimeOutput.output,\n ...(runtimeOutput.path ? { path: runtimeOutput.path } : {}),\n }\n\n return createInput(runtimeOutput, { boundary: stableBoundary })\n }\n\n return createNonProvidedInput(\n runtimeOutput[boundaryInput] ?? { instanceId, output: outputName },\n )\n })\n}\n\nfunction normalizeCreateOutputs(\n outputs: Record<string, RuntimeInput | MultipleInput | null | undefined>,\n model: ComponentModel,\n instanceId: InstanceId,\n): Record<string, RuntimeInput[]> {\n const normalizedOutputs: Record<string, RuntimeInput[]> = {}\n\n for (const [outputName, outputSpec] of Object.entries(model.outputs)) {\n const outputGroup = outputs[outputName]\n\n if (!isNonNullish(outputGroup)) {\n if (model.kind === \"unit\") {\n throw new Error(`Unit output \"${outputName}\" in instance \"${instanceId}\" must be provided`)\n }\n\n normalizedOutputs[outputName] = outputSpec.multiple\n ? []\n : [createNonProvidedInput({ instanceId, output: outputName })]\n continue\n }\n\n const normalizedGroup = normalizeCreateOutputGroup(outputGroup, instanceId, outputName)\n\n if (outputSpec.multiple && normalizedGroup.some(output => !output.provided)) {\n throw new Error(\n `Multiple output \"${outputName}\" in instance \"${instanceId}\" cannot contain non-provided items`,\n )\n }\n\n if (model.kind === \"unit\") {\n if (normalizedGroup.length === 0 || normalizedGroup.some(output => !output.provided)) {\n throw new Error(`Unit output \"${outputName}\" in instance \"${instanceId}\" must be provided`)\n }\n }\n\n normalizedOutputs[outputName] =\n outputSpec.multiple || normalizedGroup.length > 0\n ? normalizedGroup\n : [createNonProvidedInput({ instanceId, output: outputName })]\n }\n\n for (const [outputName, outputGroup] of Object.entries(pickBy(outputs, isNonNullish))) {\n if (!(outputName in model.outputs) || outputName in normalizedOutputs) {\n continue\n }\n\n normalizedOutputs[outputName] = normalizeCreateOutputGroup(outputGroup, instanceId, outputName)\n }\n\n return normalizedOutputs\n}\n\nfunction isStableInstanceInput(value: unknown): value is InstanceInput {\n if (!value || typeof value !== \"object\") {\n return false\n }\n\n if (\"provided\" in value) {\n return false\n }\n\n const input = value as Partial<InstanceInput>\n\n return typeof input.instanceId === \"string\" && typeof input.output === \"string\"\n}\n\n/**\n * Checks if the value is a Highstate component.\n *\n * Does not guarantee that the value is a valid component, only that it has the expected structure.\n *\n * @param value The value to check.\n * @returns True if the value is a component, false otherwise.\n */\nexport function isComponent(value: unknown): value is Component {\n return typeof value === \"function\" && \"model\" in value\n}\n\nfunction isSchemaOptional(schema: z.ZodType): boolean {\n return schema.safeParse(undefined).success\n}\n\nexport function mapArgument(value: ComponentArgumentOptions, key: string): ComponentArgument {\n if (\"schema\" in value) {\n return {\n schema: z.toJSONSchema(value.schema, {\n target: \"draft-7\",\n io: \"input\",\n unrepresentable: \"any\",\n }),\n [runtimeSchema]: value.schema,\n required: !isSchemaOptional(value.schema),\n meta: {\n ...value.meta,\n title: value.meta?.title || camelCaseToHumanReadable(key),\n },\n }\n }\n\n return {\n schema: z.toJSONSchema(value, { target: \"draft-7\", io: \"input\", unrepresentable: \"any\" }),\n [runtimeSchema]: value,\n required: !isSchemaOptional(value),\n meta: {\n title: camelCaseToHumanReadable(key),\n },\n }\n}\n\nexport function createInputMapper(entities: Map<string, Entity>) {\n return (value: ComponentInputOptions, key: string): ComponentInput => {\n if (!value) {\n throw new Error(`Input/output \"${key}\" is undefined in the component model.`)\n }\n\n if (\"entity\" in value) {\n entities.set(value.entity.type, value.entity)\n\n return {\n type: value.entity.type,\n required: value.required ?? true,\n multiple: value.multiple ?? false,\n meta: {\n ...value.meta,\n title: value.meta?.title || camelCaseToHumanReadable(key),\n },\n }\n }\n\n entities.set(value.type, value)\n\n return {\n type: value.type,\n required: true,\n multiple: false,\n meta: {\n title: camelCaseToHumanReadable(key),\n },\n }\n }\n}\n\nfunction isFromInputOutputOptions(\n value: ComponentOutputOptions,\n): value is FromInputComponentOutputOptions {\n return typeof value === \"object\" && value !== null && \"fromInput\" in value\n}\n\nfunction createOutputMapper(\n inputs: Record<string, ComponentInputOptions> | undefined,\n entities: Map<string, Entity>,\n) {\n const mapInput = createInputMapper(entities)\n\n return (value: ComponentOutputOptions, key: string): ComponentInput => {\n if (!isFromInputOutputOptions(value)) {\n return mapInput(value, key)\n }\n\n const sourceInput = inputs?.[value.fromInput]\n if (!sourceInput) {\n throw new Error(\n `Output \"${key}\" references missing input \"${value.fromInput}\" via fromInput.`,\n )\n }\n\n const mappedInput = mapInput(sourceInput, value.fromInput)\n\n return {\n ...mappedInput,\n fromInput: value.fromInput,\n meta: {\n ...mappedInput.meta,\n ...value.meta,\n title: value.meta?.title || camelCaseToHumanReadable(key),\n },\n }\n }\n}\n\n/**\n * Formats the instance id from the instance type and instance name.\n *\n * @param instanceType The type of the instance.\n * @param instanceName The name of the instance.\n *\n * @returns The formatted instance id.\n */\nexport function getInstanceId(instanceType: VersionedName, instanceName: string): InstanceId {\n return `${instanceType}:${instanceName}`\n}\n\nexport type ToFullComponentArgumentOptions<T extends Record<string, ComponentArgumentOptions>> =\n Simplify<{\n [K in keyof T]: T[K] extends z.ZodType ? { schema: T[K] } : T[K]\n }>\n\nexport function toFullComponentArgumentOptions<T extends Record<string, ComponentArgumentOptions>>(\n args: T,\n): ToFullComponentArgumentOptions<T> {\n return mapValues(args, arg => (\"schema\" in arg ? arg : { schema: arg })) as any\n}\n\ntype ToFullComponentInputOptions<T extends Record<string, ComponentInputOptions>> = Simplify<{\n [K in keyof T]: T[K] extends Entity ? { entity: T[K] } : T[K]\n}>\n\nfunction toFullComponentInputOptions<T extends Record<string, ComponentInputOptions>>(\n inputs: T,\n): ToFullComponentInputOptions<T> {\n return mapValues(inputs, input => (\"entity\" in input ? input : { entity: input })) as any\n}\n\ntype ToFullComponentOutputOptions<T extends Record<string, ComponentOutputOptions>> = Simplify<{\n [K in keyof T]: T[K] extends Entity ? { entity: T[K] } : T[K]\n}>\n\nfunction toFullComponentOutputOptions<T extends Record<string, ComponentOutputOptions>>(\n outputs: T,\n): ToFullComponentOutputOptions<T> {\n return mapValues(outputs, output => {\n if (typeof output !== \"object\" || output === null) {\n return { entity: output }\n }\n\n if (\"entity\" in output || \"fromInput\" in output) {\n return output\n }\n\n return { entity: output }\n }) as any\n}\n\n/**\n * The helper marker for component arguments.\n *\n * Helps validating arguments types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $args<T extends Record<string, ComponentArgumentOptions>>(\n args: T,\n): ToFullComponentArgumentOptions<T> {\n return toFullComponentArgumentOptions(args)\n}\n\n/**\n * The helper marker for component inputs.\n *\n * Helps validating inputs types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $inputs<T extends Record<string, ComponentInputOptions>>(\n inputs: T,\n): ToFullComponentInputOptions<T> {\n return toFullComponentInputOptions(inputs)\n}\n\n/**\n * The helper marker for component outputs.\n *\n * Helps validating outputs types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $outputs<T extends Record<string, ComponentOutputOptions>>(\n outputs: T,\n): ToFullComponentOutputOptions<T> {\n return toFullComponentOutputOptions(outputs)\n}\n\n/**\n * Adds a description to the argument which can be both a schema or full argument options.\n *\n * Used by the compiler to inject descriptions into the argument schema.\n * You probably won't need to use it directly.\n */\nexport function $addArgumentDescription(\n argument: ComponentArgumentOptions,\n description: string,\n): FullComponentArgumentOptions {\n if (\"schema\" in argument) {\n return {\n ...argument,\n meta: {\n ...argument.meta,\n description: argument.meta?.description ?? description,\n },\n }\n }\n\n return {\n schema: argument,\n meta: {\n description: description,\n },\n }\n}\n\n/**\n * Adds a description to the input which can be both an entity or full input options.\n *\n * Used by the compiler to inject descriptions into the input schema.\n * You probably won't need to use it directly.\n */\nexport function $addInputDescription(\n input: ComponentInputOptions,\n description: string,\n): ComponentInputOptions {\n if (\"entity\" in input) {\n return {\n ...input,\n meta: {\n ...input.meta,\n description: input.meta?.description ?? description,\n },\n }\n }\n\n return {\n entity: input,\n meta: {\n description: description,\n },\n }\n}\n","/** biome-ignore-all lint/suspicious/noExplicitAny: for simplicity of the API, maybe fix later */\n\nimport type { Entity, EntityIncludeRef, EntityTypes } from \"./entity\"\nimport { z } from \"zod\"\nimport { componentKindSchema } from \"./component\"\nimport { boundaryInput } from \"./evaluation\"\nimport { createInput, createNonProvidedInput } from \"./instance-input\"\nimport {\n type GenericName,\n genericNameSchema,\n objectMetaSchema,\n type VersionedName,\n versionedNameSchema,\n} from \"./meta\"\n\ndeclare const type: unique symbol\n\nexport type InstanceInput = z.infer<typeof instanceInputSchema>\n\nexport type RuntimeInput<\n TTypes extends EntityTypes = EntityTypes,\n TPath extends string | undefined = string | undefined,\n> = {\n [type]?: TTypes\n [boundaryInput]: InstanceInput\n} & (\n | ({\n provided: true\n instanceId: InstanceId\n output: string\n } & (undefined extends TPath ? { path?: string } : { path: TPath }))\n | {\n provided: false\n path?: string\n }\n)\n\nexport type MultipleInput<\n TInput extends RuntimeInput = RuntimeInput,\n TSelectors extends Record<string, unknown> = Record<never, never>,\n> = TInput[] &\n TSelectors & {\n [boundaryInput]: InstanceInput\n path?: string\n }\n\ntype RequiredInputChildValue<TValue> = TValue extends RuntimeInput\n ? RequiredInput<TValue>\n : TValue extends MultipleInput<infer TItem, infer TSelectors>\n ? MultipleInput<RequiredInput<TItem>, RequiredInputChildSelectors<TSelectors>>\n : TValue extends Array<infer TItem>\n ? Array<RequiredInputChildValue<TItem>>\n : TValue\n\ntype RequiredInputChildSelectors<TSelectors extends Record<string, unknown>> = {\n [K in keyof TSelectors]: RequiredInputChildValue<TSelectors[K]>\n}\n\ntype RequiredInputChildren<TInput extends RuntimeInput> = {\n [K in keyof TInput as K extends\n | \"instanceId\"\n | \"output\"\n | \"path\"\n | \"provided\"\n | typeof boundaryInput\n | typeof type\n ? never\n : K]: RequiredInputChildValue<TInput[K]>\n}\n\ntype RequiredInputProvidedBranch<TInput extends RuntimeInput> = Extract<TInput, { provided: true }>\n\ntype StrictRequiredInput<TInput extends RuntimeInput> = RequiredInputProvidedBranch<TInput> &\n RequiredInputChildren<RequiredInputProvidedBranch<TInput>>\n\nexport type RequiredInput<TInput extends RuntimeInput = RuntimeInput> = StrictRequiredInput<TInput>\n\ntype RequiredMultipleInputSelectors<TInput extends RuntimeInput> = LiftMultipleSelectorFields<\n RequiredInputChildren<RequiredInputProvidedBranch<TInput>>\n>\n\nexport type RequiredMultipleInput<TInput extends RuntimeInput = RuntimeInput> = MultipleInput<\n RequiredInput<TInput>,\n RequiredMultipleInputSelectors<TInput>\n>\n\nexport type RequiredMultipleInputs<TInput extends RuntimeInput = RuntimeInput> =\n RequiredMultipleInput<TInput>\n\nexport type EntityInput<TEntity extends Entity> = TEntity extends Entity<\n VersionedName,\n infer TImplementedTypes,\n z.ZodTypeAny,\n unknown,\n unknown,\n infer TIncludes\n>\n ? RuntimeInput<TImplementedTypes, undefined> &\n (TIncludes extends Record<string, EntityIncludeRef>\n ? EntityInputIncludes<TIncludes>\n : Record<never, never>)\n : never\n\nexport type RequiredEntityInput<TEntity extends Entity> = RequiredInput<EntityInput<TEntity>>\n\ntype EntityInputDepth = [1, 1, 1, 1]\n\ntype DecDepth<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest]\n ? Rest\n : readonly []\n\ntype ResolveIncludeEntity<TIncludeRef> = TIncludeRef extends { entity: infer E }\n ? E extends () => infer ER\n ? ER\n : E\n : TIncludeRef\n\ntype IncludeMultiple<TIncludeRef> = TIncludeRef extends { multiple?: infer M }\n ? M extends true\n ? true\n : false\n : false\n\ntype IncludeRequired<TIncludeRef> = TIncludeRef extends { required?: infer R }\n ? R extends false\n ? false\n : true\n : true\n\ntype IncludeRefValue<\n TIncludeRef,\n TDepth extends readonly unknown[],\n> = ResolveIncludeEntity<TIncludeRef> extends infer TEntity\n ? TEntity extends Entity\n ? IncludeMultiple<TIncludeRef> extends true\n ? MultipleInput<\n EntityInputWithDepth<TEntity, TDepth>,\n TDepth extends readonly []\n ? Record<never, never>\n : TEntity extends Entity<\n VersionedName,\n EntityTypes,\n z.ZodTypeAny,\n unknown,\n unknown,\n infer TIncludes\n >\n ? TIncludes extends Record<string, EntityIncludeRef>\n ? LiftMultipleSelectorFields<EntityInputIncludes<TIncludes, DecDepth<TDepth>>>\n : Record<never, never>\n : Record<never, never>\n >\n : IncludeRequired<TIncludeRef> extends false\n ? OptionalEntityInput<TEntity, TDepth>\n : EntityInputWithDepth<TEntity, TDepth>\n : never\n : never\n\ntype OptionalEntityInput<TEntity extends Entity, TDepth extends readonly unknown[]> =\n | ({ provided: true } & EntityInputWithDepth<TEntity, TDepth>)\n | ({ provided: false; [boundaryInput]: InstanceInput } & OptionalizedInputFields<\n EntityInputWithDepth<TEntity, TDepth>\n >)\n\ntype OptionalizeInputValue<T> = [T] extends [InstanceInput]\n ? RuntimeInput\n : T extends MultipleInput<infer TItem, infer TSelectors>\n ? MultipleInput<OptionalizeInputValue<TItem>, OptionalizedSelectorFields<TSelectors>>\n : T extends Array<infer TItem>\n ? Array<OptionalizeInputValue<TItem>>\n : T\n\ntype OptionalizedSelectorFields<TSelectors extends Record<string, unknown>> = {\n [K in keyof TSelectors]: OptionalizeInputValue<TSelectors[K]>\n}\n\ntype RuntimeInputSelectorFields<TInput extends RuntimeInput> = {\n [K in keyof TInput as K extends\n | \"instanceId\"\n | \"output\"\n | \"path\"\n | \"provided\"\n | typeof boundaryInput\n | typeof type\n ? never\n : K]: LiftMultipleSelectorValue<TInput[K]>\n}\n\ntype LiftMultipleSelectorValue<T> = T extends MultipleInput<infer TItem, infer TSelectors>\n ? MultipleInput<TItem, LiftMultipleSelectorFields<TSelectors>>\n : T extends RuntimeInput\n ? MultipleInput<T, RuntimeInputSelectorFields<T>>\n : T\n\ntype LiftMultipleSelectorFields<TSelectors extends Record<string, unknown>> = {\n [K in keyof TSelectors]: LiftMultipleSelectorValue<TSelectors[K]>\n}\n\ntype OptionalizedInputFields<TInput extends RuntimeInput> = {\n [K in keyof TInput as K extends \"instanceId\" | \"output\" | \"provided\" | typeof boundaryInput\n ? never\n : K]: OptionalizeInputValue<TInput[K]>\n}\n\ntype EntityInputWithDepth<\n TEntity extends Entity,\n TDepth extends readonly unknown[],\n> = TEntity extends Entity<\n VersionedName,\n infer TImplementedTypes,\n z.ZodTypeAny,\n unknown,\n unknown,\n infer TIncludes\n>\n ? RuntimeInput<TImplementedTypes, undefined> &\n (TDepth extends readonly []\n ? Record<never, never>\n : TIncludes extends Record<string, EntityIncludeRef>\n ? EntityInputIncludes<TIncludes, DecDepth<TDepth>>\n : Record<never, never>)\n : never\n\ntype EntityInputIncludes<\n TIncludes extends Record<string, EntityIncludeRef>,\n TDepth extends readonly unknown[] = EntityInputDepth,\n> = TIncludes extends Record<string, never>\n ? Record<never, never>\n : string extends keyof TIncludes\n ? Record<never, never>\n : {\n [K in keyof TIncludes]: IncludeRefValue<TIncludes[K], TDepth>\n }\n\nexport type InstanceInputGroup<TTypes extends EntityTypes = EntityTypes> = MultipleInput<\n RuntimeInput<TTypes>\n>\n\ntype SelectInputResult<TInput extends RuntimeInput> = TInput extends RequiredInput<infer TRuntime>\n ? TRuntime\n : TInput\n\nexport function inputKey(input: InstanceInput): string {\n return input.path\n ? `${input.instanceId}:${input.output}:${input.path}`\n : `${input.instanceId}:${input.output}`\n}\n\nexport const positionSchema = z.object({\n x: z.number(),\n y: z.number(),\n})\n\nexport type Position = z.infer<typeof positionSchema>\n\nexport const instanceIdSchema = z.templateLiteral([versionedNameSchema, \":\", genericNameSchema])\n\nexport type InstanceId = z.infer<typeof instanceIdSchema>\n\nexport const instanceInputSchema = z.object({\n instanceId: instanceIdSchema,\n output: z.string(),\n path: z.string().optional(),\n})\n\nexport const hubInputSchema = z.object({\n hubId: z.string(),\n})\n\nexport type HubInput = z.infer<typeof hubInputSchema>\n\nexport const instanceModelPatchSchema = z.object({\n /**\n * The static arguments passed to the instance.\n */\n args: z.record(z.string(), z.unknown()).optional(),\n\n /**\n * The direct instances passed as inputs to the instance.\n */\n inputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The resolved unit inputs for the instance.\n *\n * Only for computed composite instances.\n */\n hubInputs: z.record(z.string(), z.array(hubInputSchema)).optional(),\n\n /**\n * The inputs injected to the instance from the hubs.\n *\n * While `hubInputs` allows to pass hubs to distinct inputs,\n * `injectionInputs` allows to pass hubs to the instance as a whole filling all inputs with matching types.\n *\n * Only for designer-first instances.\n */\n injectionInputs: z.array(hubInputSchema).optional(),\n\n /**\n * The position of the instance on the canvas.\n *\n * Only for designer-first instances.\n */\n position: positionSchema.optional(),\n})\n\nexport const instanceModelSchema = z.object({\n /**\n * The id of the instance unique within the project.\n *\n * The format is `${instanceType}:${instanceName}`.\n */\n id: instanceIdSchema,\n\n /**\n * The kind of the instance.\n *\n * Can be either \"unit\" or \"composite\".\n */\n kind: componentKindSchema,\n\n /**\n * The type of the instance.\n */\n type: versionedNameSchema,\n\n /**\n * The name of the instance.\n *\n * Must be unique within instances of the same type in the project.\n */\n name: genericNameSchema,\n\n ...instanceModelPatchSchema.shape,\n\n /**\n * The id of the top level parent instance.\n *\n * Only for child instances of the composite instances.\n */\n resolvedInputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The ID of the parent instance.\n *\n * Only for child instances of the composite instances.\n */\n parentId: instanceIdSchema.optional(),\n\n /**\n * The direct instance outputs returned by the instance as outputs.\n *\n * Only for computed composite instances.\n */\n outputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n\n /**\n * The resolved unit outputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedOutputs: z.record(z.string(), z.array(instanceInputSchema)).optional(),\n})\n\nexport type InstanceModel = z.infer<typeof instanceModelSchema>\n\nexport const hubModelPatchSchema = z.object({\n /**\n * The position of the hub on the canvas.\n */\n position: positionSchema.optional(),\n\n /**\n * The inputs of the hub.\n */\n inputs: z.array(instanceInputSchema).optional(),\n\n /**\n * The inputs injected to the hub from the hubs.\n *\n * While `inputs` allows to pass hubs to distinct inputs,\n * `injectionInputs` allows to pass hubs to the hub as a whole filling all inputs with matching types.\n */\n injectionInputs: z.array(hubInputSchema).optional(),\n})\n\nexport const hubModelSchema = z.object({\n /**\n * The id of the hub unique within the project.\n */\n id: z.cuid2(),\n\n ...hubModelPatchSchema.shape,\n})\n\nexport type InstanceModelPatch = z.infer<typeof instanceModelPatchSchema>\nexport type HubModel = z.infer<typeof hubModelSchema>\nexport type HubModelPatch = z.infer<typeof hubModelPatchSchema>\n\n/**\n * Parses the instance id into the instance type and instance name.\n *\n * @param instanceId The instance id to parse.\n *\n * @returns The instance type and instance name.\n */\nexport function parseInstanceId(\n instanceId: string,\n): [instanceType: VersionedName, instanceName: GenericName] {\n const parts = instanceId.split(\":\")\n\n if (parts.length !== 2) {\n throw new Error(`Invalid instance ID: ${instanceId}`)\n }\n\n return parts as [VersionedName, GenericName]\n}\n\n/**\n * Selects a single input from a group by instance id or instance name.\n *\n * The function accepts a plain array but still preserves Highstate boundary semantics.\n * It first tries to read boundary metadata from the array object itself and then falls back\n * to the first item boundary when needed.\n *\n * @param inputs The input group to search in.\n * @param name The instance id or instance name to select.\n * @returns The selected input with inherited group boundary, or a provided-false input when missing.\n */\nexport function selectInput<TInput extends RuntimeInput>(\n inputs: TInput[] & Partial<{ [boundaryInput]: InstanceInput }>,\n name: string,\n): SelectInputResult<TInput> {\n const groupBoundary = inputs[boundaryInput] ?? inputs[0]?.[boundaryInput]\n\n if (inputs.length === 0 && !groupBoundary) {\n throw new Error(\n `Cannot select input \"${name}\": empty input group has no boundary metadata to build a missing input reference.`,\n )\n }\n\n const input = inputs.find(\n input =>\n input.provided &&\n (input.instanceId === name || parseInstanceId(input.instanceId)[1] === name),\n )\n\n if (!input || !input.provided) {\n const fallbackBoundary =\n groupBoundary ??\n inputs.find(input => Boolean(input[boundaryInput]))?.[boundaryInput] ??\n inputs[0]?.[boundaryInput]\n\n if (!fallbackBoundary) {\n throw new Error(\n `Cannot select input \"${name}\": input group has no boundary metadata to build a missing input reference.`,\n )\n }\n\n return createNonProvidedInput(fallbackBoundary) as SelectInputResult<TInput>\n }\n\n const boundary = groupBoundary ?? input[boundaryInput]\n return createInput(input, { boundary }) as SelectInputResult<TInput>\n}\n\n/**\n * The field names that indicate special objects which Highstate understands regardless of the context.\n *\n * UUIDs are used to prevent conflicts with user-defined fields.\n */\nexport enum HighstateSignature {\n Artifact = \"d55c63ac-3174-4756-808f-f778e99af0d1\",\n Yaml = \"c857cac5-caa6-4421-b82c-e561fbce6367\",\n Secret = \"240e5789-6ae4-4b22-b9d8-87169e8b4bab\",\n}\n\nexport const yamlValueSchema = z.object({\n [HighstateSignature.Yaml]: z.literal(true),\n value: z.string(),\n})\n\nexport type YamlValue = z.infer<typeof yamlValueSchema>\n\nexport const fileMetaSchema = z.object({\n name: z.string(),\n contentType: z.string().optional(),\n size: z.number().optional(),\n mode: z.number().optional(),\n})\n\nexport enum WellKnownInstanceCustomStatus {\n /**\n * The instance is in a healthy state.\n */\n Healthy = \"healthy\",\n\n /**\n * The instance is in a degraded state.\n */\n Degraded = \"degraded\",\n\n /**\n * The instance is in a down state/completely broken.\n */\n Down = \"down\",\n\n /**\n * The instance is in a warning state.\n */\n Warning = \"warning\",\n\n /**\n * The instance is progressing with some external sync operation,\n * such as a deployment or a data migration.\n */\n Progressing = \"progressing\",\n\n /**\n * The instance is in an error state.\n */\n Error = \"error\",\n}\n\nexport const instanceStatusFieldValueSchema = z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.string().array(),\n])\n\nexport const instanceStatusFieldSchema = z.object({\n name: z.string(),\n\n meta: objectMetaSchema\n .pick({\n title: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n\n complementaryTo: z.string().optional(),\n value: instanceStatusFieldValueSchema.optional(),\n})\n\nexport type InstanceStatusFieldValue = z.infer<typeof instanceStatusFieldValueSchema>\nexport type InstanceStatusField = z.infer<typeof instanceStatusFieldSchema>\n\nexport function secretSchema<TSchema extends z.ZodType>(\n schema: TSchema,\n): z.ZodCodec<\n z.ZodUnion<\n [\n z.ZodObject<{\n [HighstateSignature.Secret]: z.ZodLiteral<true>\n value: TSchema\n }>,\n TSchema,\n ]\n >,\n z.ZodObject<{\n [HighstateSignature.Secret]: z.ZodLiteral<true>\n value: TSchema\n }>\n> {\n const secretType = z.object({\n [HighstateSignature.Secret]: z.literal(true),\n value: schema,\n })\n\n return z.codec(z.union([secretType, schema]), secretType, {\n decode: value =>\n typeof value === \"object\" && value !== null && HighstateSignature.Secret in value\n ? (value as any)\n : { [HighstateSignature.Secret]: true, value },\n encode: value => value as any,\n })\n}\n\nexport type Secret<T> = {\n [HighstateSignature.Secret]: true\n value: T\n}\n\n/**\n * Checks if the given value is a Secret.\n *\n * @param value The value to check.\n * @returns True if the value is a Secret, false otherwise.\n */\nexport function isSecret<T>(value: unknown): value is Secret<T> {\n return typeof value === \"object\" && value !== null && HighstateSignature.Secret in value\n}\n","/** biome-ignore-all lint/suspicious/noExplicitAny: maybe fix later */\n\nimport type { InstanceInput } from \"./instance\"\nimport type { VersionedName } from \"./meta\"\nimport { mapValues } from \"remeda\"\nimport { z } from \"zod\"\nimport {\n type Component,\n type ComponentArgumentOptions,\n type ComponentArgumentOptionsToSchema,\n type ComponentInputOptions,\n type ComponentInputOptionsToSpec,\n type ComponentInputSpec,\n type ComponentModel,\n type ComponentOptions,\n type ComponentOutputOptions,\n type ComponentOutputOptionsToSpec,\n componentArgumentSchema,\n componentModelSchema,\n defineComponent,\n type FullComponentArgumentOptions,\n kind,\n mapArgument,\n type ToFullComponentArgumentOptions,\n toFullComponentArgumentOptions,\n} from \"./component\"\nimport { boundaryInput } from \"./evaluation\"\n\nexport const componentSecretSchema = componentArgumentSchema.extend({\n /**\n * The secret cannot be modified by the user, but can be modified by the unit.\n */\n readonly: z.boolean(),\n\n /**\n * The secret value is computed by the unit and should not be passed to it when invoked.\n */\n computed: z.boolean(),\n})\n\nexport type ComponentSecret = z.infer<typeof componentSecretSchema>\n\nexport type FullComponentSecretOptions = FullComponentArgumentOptions & {\n readonly?: boolean\n computed?: boolean\n}\n\nexport type ComponentSecretOptions = z.ZodType | FullComponentSecretOptions\n\ntype UnitOptions<\n TType extends VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>>,\n TSecrets extends Record<string, ComponentSecretOptions>,\n> = Omit<ComponentOptions<TType, TArgs, TInputs, TOutputs>, \"create\"> & {\n source: UnitSource\n\n secrets?: TSecrets\n}\n\nexport const unitSourceSchema = z.object({\n /**\n * The package where the unit implementation is located.\n *\n * May be both: local monorepo package or a remote NPM package.\n */\n package: z.string(),\n\n /**\n * The path to the unit implementation within the package.\n *\n * If not provided, the root of the package is assumed.\n */\n path: z.string().optional(),\n})\n\nexport const unitModelSchema = z.object({\n ...componentModelSchema.shape,\n\n /**\n * The source of the unit.\n */\n source: unitSourceSchema,\n\n /**\n * The record of the secret specs.\n */\n secrets: z.record(z.string(), componentSecretSchema),\n})\n\nexport type UnitModel = z.infer<typeof unitModelSchema>\nexport type UnitSource = z.infer<typeof unitSourceSchema>\n\ndeclare const secrets: unique symbol\n\nexport type Unit<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, z.ZodType> = Record<string, never>,\n TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,\n TSecrets extends Record<string, unknown> = Record<string, never>,\n TInputOptions extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputOptions extends Record<string, ComponentOutputOptions<TInputOptions>> = Record<\n string,\n never\n >,\n> = Component<TType, TArgs, TInputs, TOutputs, \"unit\", TInputOptions, TOutputOptions> & {\n /**\n * Holds the type of the unit secrets.\n *\n * Does not exist at runtime, only for type checking.\n */\n [secrets]: TSecrets\n\n /**\n * The model of the unit.\n */\n model: UnitModel\n}\n\nexport function defineUnit<\n TType extends VersionedName = VersionedName,\n TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,\n TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,\n TOutputs extends Record<string, ComponentOutputOptions<TInputs>> = Record<string, never>,\n TSecrets extends Record<string, ComponentSecretOptions> = Record<string, never>,\n>(\n options: UnitOptions<TType, TArgs, TInputs, TOutputs, TSecrets>,\n): Unit<\n TType,\n { [K in keyof TArgs]: ComponentArgumentOptionsToSchema<TArgs[K]> },\n { [K in keyof TInputs]: ComponentInputOptionsToSpec<TInputs[K]> },\n { [K in keyof TOutputs]: ComponentOutputOptionsToSpec<TOutputs[K], TInputs> },\n { [K in keyof TSecrets]: ComponentArgumentOptionsToSchema<TSecrets[K]> },\n TInputs,\n TOutputs\n> {\n if (!options.source) {\n throw new Error(\"Unit source is required\")\n }\n\n const component = defineComponent<TType, TArgs, TInputs, TOutputs, \"unit\">({\n ...options,\n [kind]: \"unit\",\n\n create({ id }) {\n const outputs: Record<\n string,\n InstanceInput & { provided: true; [boundaryInput]: InstanceInput }\n > = {}\n for (const key in options.outputs ?? {}) {\n outputs[key] = {\n provided: true,\n instanceId: id,\n output: key,\n [boundaryInput]: {\n instanceId: id,\n output: key,\n },\n }\n }\n\n return outputs as any\n },\n }) as any\n\n try {\n component.model.source = options.source ?? {}\n component.model.secrets = mapValues(options.secrets ?? {}, mapSecret)\n } catch (error) {\n throw new Error(`Failed to map secrets for unit \"${options.type}\"`, { cause: error })\n }\n\n return component\n}\n\n/**\n * The helper marker for component secrets.\n *\n * Helps validating secrets types and gives the compiler a hint for generating `meta` fields.\n */\nexport function $secrets<T extends Record<string, ComponentArgumentOptions>>(\n secrets: T,\n): ToFullComponentArgumentOptions<T> {\n return toFullComponentArgumentOptions(secrets)\n}\n\nfunction mapSecret(value: ComponentSecretOptions, key: string): ComponentSecret {\n if (\"schema\" in value) {\n return {\n ...mapArgument(value, key),\n readonly: value.readonly ?? false,\n computed: value.computed ?? false,\n }\n }\n\n return {\n ...mapArgument(value, key),\n readonly: false,\n computed: false,\n }\n}\n\n/**\n * Checks if the given model is a unit model.\n *\n * @param model The model to check.\n *\n * @returns `true` if the model is a unit model, `false` otherwise.\n */\nexport function isUnitModel(model: ComponentModel): model is UnitModel {\n return \"source\" in model\n}\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\n\nexport const triggerSpecSchema = z.union([\n z.object({\n type: z.literal(\"before-destroy\"),\n }),\n])\n\nexport type TriggerSpec = z.infer<typeof triggerSpecSchema>\n\n/**\n * Trigger schema for unit API.\n * This is what units provide - excludes id since it's set by the system.\n */\nexport const unitTriggerSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n\n /**\n * The specification of the trigger.\n *\n * Defines the type of trigger and its behavior.\n */\n spec: triggerSpecSchema,\n})\n\nexport type UnitTrigger = z.infer<typeof unitTriggerSchema>\n\nexport const triggerInvocationSchema = z.object({\n /**\n * The name of the trigger being invoked.\n */\n name: z.string(),\n})\n\nexport type TriggerInvocation = z.infer<typeof triggerInvocationSchema>\n","import { parse } from \"yaml\"\nimport { z } from \"zod\"\nimport {\n fileMetaSchema,\n HighstateSignature,\n instanceInputSchema,\n secretSchema,\n yamlValueSchema,\n} from \"./instance\"\nimport { commonObjectMetaSchema } from \"./meta\"\nimport { triggerInvocationSchema } from \"./trigger\"\n\nexport const unitInputSourceSchema = z.object({\n ...instanceInputSchema.shape,\n})\n\nexport type UnitInputSource = z.infer<typeof unitInputSourceSchema>\n\nexport const unitInputValueSchema = z.object({\n /**\n * Inline resolved value passed to the unit.\n *\n * The backend is responsible for resolving the correct entity snapshot value\n * and applying any inclusion transformations.\n */\n value: z.unknown(),\n\n /**\n * Optional provenance of the value.\n */\n source: unitInputSourceSchema.optional(),\n})\n\nexport type UnitInputValue = z.infer<typeof unitInputValueSchema>\n\nexport const unitConfigSchema = z.object({\n /**\n * The ID of the instance.\n */\n instanceId: z.string(),\n\n /**\n * The state ID of the instance.\n */\n stateId: z.string(),\n\n /**\n * The record of argument values for the unit.\n */\n args: z.record(z.string(), z.unknown()),\n\n /**\n * The record of input references for the unit.\n */\n inputs: z.record(z.string(), unitInputValueSchema.array()),\n\n /**\n * The list of triggers that have been invoked for this unit.\n */\n invokedTriggers: triggerInvocationSchema.array(),\n\n /**\n * The record of secret values provided to the unit.\n *\n * It is stored in Pulumi stack config as a secret.\n */\n secretValues: z.record(z.string(), z.unknown()),\n\n /**\n * The base path for imports.\n * Used to resolve dynamic dependencies in strict environments (like in pnpm node_modules isolation).\n */\n importBasePath: z.string(),\n})\n\nexport type UnitConfig = z.infer<typeof unitConfigSchema>\n\nconst yamlResultCache = new WeakMap<object, unknown>()\n\n/**\n * Parses an argument value which can be wrapped in a YAML structure.\n *\n * @param value The value to parse.\n */\nexport function parseArgumentValue(value: unknown): unknown {\n const yamlResult = yamlValueSchema.safeParse(value)\n if (!yamlResult.success) {\n return value\n }\n\n const existingResult = yamlResultCache.get(value as object)\n if (existingResult !== undefined) {\n return existingResult\n }\n\n const result = parse(yamlResult.data.value) as unknown\n yamlResultCache.set(value as object, result)\n return result\n}\n\nexport enum HighstateConfigKey {\n Config = \"highstate\",\n}\n\nexport const unitArtifactId = Symbol(\"unitArtifactId\")\n\nexport const unitArtifactSchema = z.object({\n [HighstateSignature.Artifact]: z.literal(true),\n // only for internal use\n [unitArtifactId]: z.string().optional(),\n hash: z.string(),\n meta: commonObjectMetaSchema.optional(),\n})\n\nexport const fileContentSchema = z.union([\n z.object({\n type: z.literal(\"embedded\"),\n\n /**\n * Whether the content is binary or not.\n *\n * If true, the `value` will be a base64 encoded string.\n */\n isBinary: z.boolean().optional(),\n\n /**\n * The content of the file.\n *\n * If `isBinary` is true, this will be a base64 encoded string.\n */\n value: z.string(),\n }),\n z.object({\n type: z.literal(\"embedded-secret\"),\n\n /**\n * Whether the content is binary or not.\n *\n * If true, the `value` will be a base64 encoded string.\n */\n isBinary: z.boolean().optional(),\n\n /**\n * The content of the file wrapped as a Highstate secret.\n *\n * If `isBinary` is true, this will be a base64 encoded string.\n */\n value: secretSchema(z.string()),\n }),\n z.object({\n type: z.literal(\"artifact\"),\n ...unitArtifactSchema.shape,\n }),\n])\n\nexport const fileSchema = z.object({\n meta: fileMetaSchema,\n content: fileContentSchema,\n})\n\nexport type FileMeta = z.infer<typeof fileMetaSchema>\nexport type FileContent = z.infer<typeof fileContentSchema>\nexport type UnitArtifact = z.infer<typeof unitArtifactSchema>\nexport type File = z.infer<typeof fileSchema>\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\nimport { fileSchema } from \"./pulumi\"\n\n/**\n * Contains all the information needed to run a terminal,\n * including the image, command, working directory, environment variables, and files.\n */\nexport const terminalSpecSchema = z.object({\n /**\n * The Docker image to run the terminal.\n */\n image: z.string(),\n\n /**\n * The command to run in the terminal.\n */\n command: z.string().array(),\n\n /**\n * The working directory to run the command in.\n */\n cwd: z.string().optional(),\n\n /**\n * The environment variables to set in the terminal.\n */\n env: z.record(z.string(), z.string()).optional(),\n\n /**\n * The files to mount in the terminal.\n *\n * The key is the path where the file will be mounted,\n * and the value is the file content or a reference to an artifact.\n */\n files: z.record(z.string(), fileSchema).optional(),\n})\n\nexport type TerminalSpec = z.infer<typeof terminalSpecSchema>\n\n/**\n * Terminal schema for unit API.\n */\nexport const unitTerminalSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n spec: terminalSpecSchema,\n})\n\nexport type UnitTerminal = z.infer<typeof unitTerminalSchema>\n","import { z } from \"zod\"\nimport { objectMetaSchema } from \"./meta\"\nimport { fileSchema } from \"./pulumi\"\n\n/**\n * Page block schema for database storage and unit API.\n */\nexport const pageBlockSchema = z.union([\n z.object({\n type: z.literal(\"markdown\"),\n content: z.string(),\n }),\n z.object({\n type: z.literal(\"qr\"),\n content: z.string(),\n showContent: z.coerce.boolean(),\n language: z.string().optional(),\n }),\n z.object({\n type: z.literal(\"file\"),\n file: fileSchema,\n }),\n])\n\nexport type PageBlock = z.infer<typeof pageBlockSchema>\n\n/**\n * Page schema for unit API.\n * This is what units provide - excludes id, instanceId and some fields from meta since those are set by the system.\n */\nexport const unitPageSchema = z.object({\n name: z.string(),\n meta: objectMetaSchema\n .pick({\n title: true,\n globalTitle: true,\n description: true,\n icon: true,\n iconColor: true,\n })\n .required({ title: true }),\n content: pageBlockSchema.array(),\n})\n\nexport type UnitPage = z.infer<typeof unitPageSchema>\n","import { z } from \"zod\"\n\nexport const unitWorkerSchema = z.object({\n name: z.string(),\n image: z.string(),\n params: z.record(z.string(), z.unknown()),\n})\n\nexport type UnitWorker = z.infer<typeof unitWorkerSchema>\n\nexport const workerRunOptionsSchema = z.object({\n /**\n * The ID of the project for which the worker is running.\n */\n projectId: z.cuid2(),\n\n /**\n * The ID of the worker version.\n */\n workerVersionId: z.cuid2(),\n\n /**\n * The URL of the backend API to connect to.\n */\n apiUrl: z.url(),\n\n /**\n * The API key used to authenticate the worker with the backend.\n */\n apiKey: z.string(),\n})\n\nexport type WorkerRunOptions = z.infer<typeof workerRunOptionsSchema>\n","import type { z } from \"zod\"\nimport { isNonNullish, pickBy } from \"remeda\"\n\ntype PickUndefinedKeys<T extends Record<string, unknown>> = T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: undefined extends T[K] ? K : never\n }[keyof T],\n undefined\n >\n\ntype AllOptionalKeys<T extends Record<string, unknown>> = T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: undefined extends T[K] ? K : never\n }[keyof T],\n undefined\n >\n\ntype HasRequired<T extends Record<string, unknown>> = T extends Record<string, never>\n ? false\n : [keyof T] extends [AllOptionalKeys<T>]\n ? false\n : true\n\ntype PickRecordsWithAnyRequired<T extends Record<string, Record<string, unknown>>> =\n T extends Record<string, never>\n ? never\n : Exclude<\n {\n [K in keyof T]: HasRequired<T[K]> extends true ? K : never\n }[keyof T],\n undefined\n >\n\nexport type OptionalEmptyRecords<T extends Record<string, Record<string, unknown>>> = {\n [K in Exclude<keyof T, PickRecordsWithAnyRequired<T>>]?: OptionalUndefinedFields<T[K]>\n} & {\n [K in PickRecordsWithAnyRequired<T>]: OptionalUndefinedFields<T[K]>\n}\n\nexport type OptionalUndefinedFields<T extends Record<string, unknown>> = {\n [K in PickUndefinedKeys<T>]?: T[K]\n} & {\n [K in Exclude<keyof T, PickUndefinedKeys<T>>]: T[K]\n}\n\n/**\n * Marks specific keys in a type as optional.\n *\n * @template T The type to modify.\n * @template K The keys to make optional.\n */\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\n\n/**\n * Marks specific keys in a type as required.\n *\n * @template T The type to modify.\n * @template K The keys to make required.\n */\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>\n\n/**\n * Formats a multiline string and trims the indentation.\n *\n * @param str The string to trim.\n * @returns The trimmed string.\n */\nexport function text(strings: TemplateStringsArray, ...values: unknown[]): string {\n // Convert all values to strings\n const stringValues = values.map(String)\n\n // Build full string with values interpolated\n let result = \"\"\n for (let i = 0; i < strings.length; i++) {\n result += strings[i]\n if (i < stringValues.length) {\n const value = stringValues[i]\n const lines = value.split(\"\\n\")\n const lastLineIndentMatch = strings[i].match(/(?:^|\\n)([ \\t]*)$/)\n const indent = lastLineIndentMatch ? lastLineIndentMatch[1] : \"\"\n\n result += lines.map((line, j) => (j === 0 ? line : indent + line)).join(\"\\n\")\n }\n }\n\n return trimIndentation(result)\n}\n\n/**\n * Removes the indentation from a multiline string.\n *\n * @param text The text to trim.\n * @returns The trimmed text.\n */\nexport function trimIndentation(text: string): string {\n const lines = text.split(\"\\n\")\n const indent = lines\n .filter(line => line.trim() !== \"\")\n .map(line => line.match(/^\\s*/)?.[0].length ?? 0)\n .reduce((min, indent) => Math.min(min, indent), Infinity)\n\n return lines\n .map(line => line.slice(indent))\n .join(\"\\n\")\n .trim()\n}\n\n/**\n * Converts bytes to a human-readable format.\n *\n * @param bytes The number of bytes.\n * @returns The human-readable string representation of the bytes.\n */\nexport function bytesToHumanReadable(bytes: number): string {\n const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\", \"TB\"]\n if (bytes === 0) return \"0 Bytes\"\n\n const i = Math.floor(Math.log(bytes) / Math.log(1024))\n return `${parseFloat((bytes / 1024 ** i).toFixed(2))} ${sizes[i]}`\n}\n\n/**\n * Checks if a value matches the given Zod schema and narrows the type accordingly.\n *\n * @param schema The Zod schema to check against.\n * @param value The value to check.\n * @returns `true` if the value matches the schema, `false` otherwise.\n */\nexport function check<TSchema extends z.ZodType>(\n schema: TSchema,\n value: unknown,\n): value is z.infer<TSchema> {\n return schema.safeParse(value).success\n}\n\n/**\n * Gets or creates a value in a map, using a factory function if the key does not exist.\n *\n * @param map The map to check.\n * @param key The key to look for.\n * @param createFn The function to create a new value if the key does not exist.\n * @returns The value associated with the key.\n */\nexport function getOrCreate<TKey, TValue>(\n map: Map<TKey, TValue>,\n key: TKey,\n createFn: (key: TKey) => TValue,\n): TValue {\n const existing = map.get(key)\n if (existing !== undefined) {\n return existing\n }\n\n const value = createFn(key)\n map.set(key, value)\n return value\n}\n\n/**\n * Strips nullish values from an object.\n *\n * @param obj The object to strip.\n * @returns A new object with all nullish values removed.\n */\nexport function stripNullish<T extends Record<string, unknown>>(obj: T) {\n return pickBy(obj, isNonNullish)\n}\n"]}
|