@highstate/contract 0.8.0 → 0.9.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.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/instance.ts","../src/evaluation.ts","../src/unit.ts","../src/component.ts","../src/utils.ts","../src/entity.ts","../src/types.ts","../src/index.ts"],"sourcesContent":["declare const type: unique symbol\n\nexport type InstanceInput<TType extends string = string> = {\n [type]?: TType\n [boundaryInput]?: InstanceInput\n instanceId: string\n output: string\n}\n\nexport const boundaryInput = Symbol(\"boundaryInput\")\n\nexport type HubInput = {\n hubId: string\n}\n\nexport type Position = {\n x: number\n y: number\n}\n\nexport type InstanceModel = {\n /**\n * The id of the instance unique within the project.\n *\n * The format is `${instanceType}:${instanceName}`.\n */\n id: string\n\n /**\n * The type of the instance.\n */\n type: string\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: string\n\n /**\n * The static arguments passed to the instance.\n */\n args?: Record<string, unknown>\n\n /**\n * The direct instances passed as inputs to the instance.\n */\n inputs?: Record<string, InstanceInput[]>\n\n /**\n * The resolved unit inputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedInputs?: Record<string, InstanceInput[]>\n\n /**\n * The inputs passed to the instance from the hubs.\n *\n * Only for designer-first instances.\n */\n hubInputs?: Record<string, HubInput[]>\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?: HubInput[]\n\n /**\n * The position of the instance on the canvas.\n *\n * Only for designer-first instances.\n */\n position?: Position\n\n /**\n * The id of the top level parent instance.\n *\n * Only for child instances of the composite instances.\n */\n parentId?: string\n\n /**\n * The direct instance inputs and same-level children outputs returned by the instance as outputs.\n *\n * Only for computed composite instances.\n */\n outputs?: Record<string, InstanceInput[]>\n\n /**\n * The resolved unit outputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedOutputs?: Record<string, InstanceInput[]>\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: string, instanceName: string): string {\n return `${instanceType}:${instanceName}`\n}\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(instanceId: string): [instanceType: string, instanceName: string] {\n const parts = instanceId.split(\":\")\n\n if (parts.length !== 2) {\n throw new Error(`Invalid instance key: ${instanceId}`)\n }\n\n return parts as [string, string]\n}\n\nexport function findInput<T extends string>(\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 string>(\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 string>(\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 string>(\n inputs: InstanceInput<T>[],\n names: string[],\n): InstanceInput<T>[] {\n return names.map(name => findRequiredInput(inputs, name))\n}\n","import type { ComponentModel } from \"./component\"\nimport { mapValues } from \"remeda\"\nimport { boundaryInput, type InstanceInput, type InstanceModel } from \"./instance\"\nimport { isUnitModel } from \"./unit\"\n\nexport type CompositeInstance = {\n instance: InstanceModel\n children: InstanceModel[]\n}\n\nconst compositeInstances: Map<string, CompositeInstance> = new Map()\nlet currentCompositeInstance: CompositeInstance | null = null\n\nexport function resetEvaluation(): void {\n compositeInstances.clear()\n currentCompositeInstance = null\n}\n\nexport function getCompositeInstances(): CompositeInstance[] {\n return Array.from(compositeInstances.values())\n}\n\nexport function registerInstance<T>(\n component: ComponentModel,\n instance: InstanceModel,\n fn: () => T,\n): T {\n if (currentCompositeInstance) {\n instance.parentId = currentCompositeInstance.instance.id\n currentCompositeInstance.children.push(instance)\n }\n\n let previousParentInstance: CompositeInstance | null = null\n if (!isUnitModel(component)) {\n previousParentInstance = currentCompositeInstance\n currentCompositeInstance = { instance, children: [] }\n compositeInstances.set(currentCompositeInstance.instance.id, currentCompositeInstance)\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 currentCompositeInstance = previousParentInstance\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { ArgumentValue } from \"./types\"\nimport type { InstanceInput } from \"./instance\"\nimport { mapValues } from \"remeda\"\nimport {\n type ComponentArgumentSpec,\n type Component,\n type ComponentArgument,\n type ComponentArgumentOptions,\n type ComponentInputOptions,\n type ComponentInputOptionsMapToSpecMap,\n type ComponentInputSpec,\n type ComponentModel,\n type ComponentOptions,\n defineComponent,\n mapArgument,\n type ComponentArgumentOptionsMapToSpecMap,\n} from \"./component\"\n\ntype UnitOptions<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n TSecrets extends Record<string, ComponentArgumentOptions>,\n> = Omit<ComponentOptions<TArgs, TInputs, TOutputs>, \"create\"> & {\n source: UnitSource\n\n secrets?: TSecrets\n}\n\nexport type UnitSource = {\n package: string\n path?: string\n version?: string\n}\n\nexport type UnitModel = ComponentModel & {\n /**\n * The source of the unit.\n */\n source: UnitSource\n\n /**\n * The record of the secret argument schemas.\n */\n secrets: Record<string, ComponentArgument>\n}\n\nexport type Unit<\n TArgs extends Record<string, ComponentArgumentSpec> = 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, ArgumentValue> = Record<string, never>,\n> = Component<TArgs, TInputs, TOutputs> & {\n __secrets: TSecrets\n\n model: UnitModel\n}\n\nexport function isUnitModel(model: ComponentModel): model is UnitModel {\n return \"source\" in model\n}\n\nexport function defineUnit<\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, ComponentArgumentOptions> = Record<string, never>,\n>(\n options: UnitOptions<TArgs, TInputs, TOutputs, TSecrets>,\n): Unit<\n ComponentArgumentOptionsMapToSpecMap<TArgs>,\n ComponentInputOptionsMapToSpecMap<TInputs>,\n ComponentInputOptionsMapToSpecMap<TOutputs>,\n ComponentArgumentOptionsMapToSpecMap<TSecrets>\n> {\n const component = defineComponent<TArgs, TInputs, TOutputs>({\n ...options,\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 component.model.source = options.source ?? {}\n component.model.secrets = mapValues(options.secrets ?? {}, mapArgument)\n\n return component\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport type { Entity } from \"./entity\"\nimport type { ArgumentValue, ArgumentValueSchema, Meta } from \"./types\"\nimport {\n type Static,\n type TObject,\n type TOptional,\n type TSchema,\n OptionalKind,\n} from \"@sinclair/typebox\"\nimport { isNonNullish, mapValues, pickBy } from \"remeda\"\nimport { Ajv } from \"ajv\"\nimport { boundaryInput, type InstanceInput } from \"./instance\"\nimport { type OptionalUndefinedFields, type OptionalEmptyRecords } from \"./utils\"\nimport { registerInstance } from \"./evaluation\"\n\nconst ajv = new Ajv({ strict: false })\n\n// Argument\nexport type ComponentArgument = {\n schema: ArgumentValueSchema\n required: boolean\n meta: Meta\n}\n\ntype ComponentArgumentFullOptions = Meta & {\n schema: ArgumentValueSchema\n required?: boolean\n}\n\nexport type ComponentArgumentOptions = ArgumentValueSchema | ComponentArgumentFullOptions\nexport type ComponentArgumentSpec = [schema: ArgumentValueSchema, required: boolean]\n\nexport type ComponentArgumentOptionsToSpec<T extends ComponentArgumentOptions> =\n T extends ArgumentValueSchema\n ? T extends { default: unknown }\n ? [T, false]\n : [T, true]\n : T extends ComponentArgumentFullOptions\n ? T[\"required\"] extends false\n ? [T[\"schema\"], false]\n : [T[\"schema\"], true]\n : never\n\nexport type ComponentArgumentOptionsMapToSpecMap<\n T extends Record<string, ComponentArgumentOptions>,\n> =\n T extends Record<string, never>\n ? Record<string, never>\n : { [K in keyof T]: ComponentArgumentOptionsToSpec<T[K]> }\n\nexport type ComponentArgumentSpecMapToInputStatic<T extends Record<string, ComponentArgumentSpec>> =\n T extends Record<string, never>\n ? Record<string, never>\n : Static<TObject<{ [K in keyof T]: T[K][1] extends true ? T[K][0] : TOptional<T[K][0]> }>>\n\nexport type ComponentArgumentSpecToStatic<T extends Record<string, ComponentArgumentSpec>> =\n T extends Record<string, never>\n ? Record<string, never>\n : Static<TObject<{ [K in keyof T]: T[K][0] }>>\n\nexport type ComponentArgumentOptionsToSchema<T extends ComponentArgumentOptions> = T extends TSchema\n ? T\n : T[\"required\"] extends false\n ? TOptional<T[\"schema\"]>\n : T[\"schema\"]\n\ntype ComponentArgumentMapToValue<T extends Record<string, ComponentArgumentOptions>> = {\n [K in keyof T]: Static<ComponentArgumentOptionsToSchema<T[K]>>\n}\n\n// Input\nexport type ComponentInput = {\n type: string\n required: boolean\n multiple: boolean\n meta: Meta\n}\n\ntype ComponentInputFullOptions = Meta & {\n entity: Entity\n required?: boolean\n multiple?: boolean\n}\n\nexport type ComponentInputOptions = Entity | ComponentInputFullOptions\n\ntype ComponentInputOptionsToOutputRef<T extends ComponentInputOptions> = T extends Entity\n ? InstanceInput<T[\"type\"]>\n : T extends ComponentInputFullOptions\n ? T[\"required\"] extends false\n ? T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][\"type\"]>[] | undefined\n : InstanceInput<T[\"entity\"][\"type\"]> | undefined\n : T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][\"type\"]>[]\n : InstanceInput<T[\"entity\"][\"type\"]>\n : never\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 ComponentInputFullOptions\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 T extends Record<string, never> ? void : ComponentInputMapToValue<T>\n\n// Params & Options\nexport type ComponentParams<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = {\n id: string\n name: string\n args: ComponentArgumentMapToValue<TArgs>\n inputs: ComponentInputMapToValue<TInputs>\n}\n\nexport type InputComponentParams<\n TArgs extends Record<string, ArgumentValue>,\n TInputs extends Record<string, unknown>,\n> = {\n name: string\n} & OptionalEmptyRecords<{\n args: TArgs\n inputs: TInputs\n}>\n\nexport type ComponentOptions<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n> = {\n type: string\n meta?: ComponentMeta\n\n args?: TArgs\n inputs?: TInputs\n outputs?: TOutputs\n\n create: (params: ComponentParams<TArgs, TInputs>) => ComponentInputMapToReturnType<TOutputs>\n}\n\n// Models\nexport type ComponentMeta = Meta & {\n primaryIcon?: string\n primaryIconColor?: string\n secondaryIcon?: string\n secondaryIconColor?: string\n category?: string\n defaultNamePrefix?: string\n}\n\nexport type ComponentModel = {\n /**\n * The type of the component.\n */\n type: string\n\n /**\n * The record of the argument schemas.\n */\n args: Record<string, ComponentArgument>\n\n /**\n * The record of the input schemas.\n */\n inputs: Record<string, ComponentInput>\n\n /**\n * The record of the output schemas.\n */\n outputs: Record<string, ComponentInput>\n\n /**\n * The extra metadata of the component.\n */\n meta: ComponentMeta\n\n /**\n * The hash of the component definition.\n */\n definitionHash: string\n}\n\ntype InputSpecToOutputRef<T extends ComponentInputSpec> = T[1] extends true\n ? T[2] extends true\n ? InstanceInput<T[0][\"type\"]>[]\n : InstanceInput<T[0][\"type\"]>\n : T[2] extends true\n ? InstanceInput<T[0][\"type\"]>[] | undefined\n : InstanceInput<T[0][\"type\"]> | undefined\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\")\n\nexport type Component<\n TArgs extends Record<string, ComponentArgumentSpec> = 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 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 * Creates the component at the evaluation time.\n */\n (\n context: InputComponentParams<\n ComponentArgumentSpecMapToInputStatic<TArgs>,\n OutputRefMap<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 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<TArgs, TInputs, TOutputs>,\n): Component<\n ComponentArgumentOptionsMapToSpecMap<TArgs>,\n ComponentInputOptionsMapToSpecMap<TInputs>,\n ComponentInputOptionsMapToSpecMap<TOutputs>\n> {\n function create(params: InputComponentParams<any, any>): any {\n const { name, args, inputs } = params\n const id = `${options.type}:${name}`\n\n const flatInputs = mapValues(pickBy(inputs ?? {}, isNonNullish), inputs => [inputs].flat(2))\n\n return registerInstance(\n create.model as ComponentModel,\n {\n id,\n type: options.type,\n name,\n args: args ?? {},\n inputs: mapValues(flatInputs, inputs => inputs.map(input => input[boundaryInput] ?? input)),\n resolvedInputs: flatInputs,\n },\n () => {\n const markedInputs = mapValues(flatInputs, (inputs, key) => {\n const result = inputs.map(input => ({\n ...input,\n [boundaryInput]: { instanceId: id, output: key },\n }))\n\n return (create.model as ComponentModel).inputs?.[key]?.multiple === false\n ? result[0]\n : result\n })\n\n const outputs: Record<string, InstanceInput[]> =\n options.create({\n id,\n name,\n args: validateArgsAndFillDefaults(\n id,\n create.model as ComponentModel,\n args ? { ...args } : {},\n ) as any,\n inputs: markedInputs as any,\n }) ?? {}\n\n return mapValues(pickBy(outputs, isNonNullish), outputs => [outputs].flat(2))\n },\n )\n }\n\n create.entities = new Map<string, Entity>()\n const mapInput = createInputMapper(create.entities)\n\n create.model = {\n type: options.type,\n args: mapValues(options.args ?? {}, mapArgument),\n inputs: mapValues(options.inputs ?? {}, mapInput),\n outputs: mapValues(options.outputs ?? {}, mapInput),\n meta: options.meta ?? {},\n }\n\n create[originalCreate] = options.create\n\n return create as any\n}\n\nexport function isComponent(value: unknown): value is Component {\n return typeof value === \"function\" && \"model\" in value\n}\n\nexport function mapArgument(value: ComponentArgumentOptions) {\n if (\"schema\" in value) {\n return {\n schema: value.schema,\n required: value.required ?? (!value.schema[OptionalKind] && !value.schema.default),\n meta: {\n displayName: value.displayName,\n description: value.description,\n color: value.color,\n },\n }\n }\n\n return {\n schema: value,\n required: !value[OptionalKind] && !value.default,\n meta: {},\n }\n}\n\nexport function createInputMapper(entities: Map<string, Entity>) {\n return (value: ComponentInputOptions) => {\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 displayName: value.displayName,\n description: value.description,\n color: value.color,\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 }\n }\n}\n\nfunction validateArgsAndFillDefaults(\n instanceId: string,\n model: ComponentModel,\n args: Record<string, unknown>,\n) {\n for (const [key, argModel] of Object.entries(model.args)) {\n let value = args[key]\n if (!value) {\n if (argModel.required) {\n throw new Error(`Missing required argument \"${key}\" for instance \"${instanceId}\"`)\n }\n\n value = argModel.schema.default\n args[key] = value\n }\n\n if (value && !ajv.validate(argModel.schema, value)) {\n throw new Error(`Invalid argument \"${key}\" for instance \"${instanceId}\": ${ajv.errorsText()}`)\n }\n }\n\n return args as Record<string, ArgumentValue>\n}\n","export type EntityMap<T> = Record<string, T> & {\n default?: T\n}\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>\n\n// TODO: refactor this shit\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 * 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(array: TemplateStringsArray, ...values: unknown[]): string {\n const str = array.reduce(\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n (result, part, i) => result + part + (values[i] ? String(values[i]) : \"\"),\n \"\",\n )\n\n return trimIndentation(str)\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","import type { TAnySchema, TSchema } from \"@sinclair/typebox\"\nimport type { Meta } from \"./types\"\nimport type { PartialKeys } from \"./utils\"\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 type Entity<TType extends string = string, TEntitySchema extends TSchema = TSchema> = {\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: TEntitySchema\n\n /**\n * The extra metadata of the entity.\n */\n meta: Meta\n\n /**\n * The hash of the entity definition.\n */\n definitionHash: string\n}\n\nexport type EntityOptions<TType extends string, TSchema extends TAnySchema> = Omit<\n PartialKeys<Entity<TType, TSchema>, \"meta\">,\n \"definitionHash\"\n>\n\nexport function defineEntity<TType extends string, TSchema extends TAnySchema>(\n options: EntityOptions<TType, TSchema>,\n): Entity<TType, TSchema> {\n return {\n meta: {},\n ...options,\n } as Entity<TType, TSchema>\n}\n\nexport function isEntity(value: unknown): value is Entity {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n \"schema\" in value &&\n \"meta\" in value\n )\n}\n","import {\n type Static,\n type TAny,\n type TArray,\n type TBoolean,\n type TLiteral,\n type TNumber,\n type TRecordOrObject,\n type TString,\n type TUnion,\n} from \"@sinclair/typebox\"\n\nexport type ArgumentValueSchema =\n | TString\n | TNumber\n | TBoolean\n | TArray<TString>\n | TArray<TNumber>\n | TUnion<TLiteral[]>\n | TRecordOrObject<TString, TAny>\n | TArray\n\nexport type ArgumentValue = Static<ArgumentValueSchema>\n\n/**\n * The generic metadata of some contract.\n */\nexport type Meta = {\n /**\n * The display name of the entity which can be shown in the UI.\n */\n displayName?: string\n\n /**\n * The description of the entity which can be shown in the UI.\n */\n description?: string\n\n /**\n * The hex color of the entity which can be used in the UI.\n *\n * @example \"#ff0000\"\n */\n color?: string\n}\n","export {\n type InstanceInput,\n type HubInput,\n type InstanceModel,\n type Position,\n getInstanceId,\n parseInstanceId,\n findInput,\n findRequiredInput,\n findInputs,\n findRequiredInputs,\n} from \"./instance\"\nexport { getCompositeInstances, resetEvaluation, type CompositeInstance } from \"./evaluation\"\nexport { type Entity, defineEntity, isEntity } from \"./entity\"\nexport {\n type Component,\n type ComponentModel,\n type ComponentMeta,\n type ComponentArgument,\n type ComponentInput,\n type ComponentInputSpec,\n type ComponentArgumentSpec,\n type ComponentArgumentSpecToStatic,\n defineComponent,\n isComponent,\n originalCreate,\n} from \"./component\"\nexport { type Unit, type UnitModel, type UnitSource, defineUnit, isUnitModel } from \"./unit\"\nexport { type RequiredKeys, type PartialKeys, text, trimIndentation } from \"./utils\"\nexport { type ArgumentValue, type ArgumentValueSchema } from \"./types\"\nexport { type Static } from \"@sinclair/typebox\"\n\nimport {\n Type as BaseType,\n type Static,\n type TLiteral,\n type TSchema,\n type TUnion,\n} from \"@sinclair/typebox\"\n\ntype MapToLiteral<T extends readonly string[]> = {\n [K in keyof T]: T[K] extends string ? TLiteral<T[K]> : never\n}\n\nfunction StringEnum<T extends string[]>(values: [...T]): TUnion<MapToLiteral<T>> {\n return Type.Union(values.map(value => Type.Literal(value))) as TUnion<MapToLiteral<T>>\n}\n\nfunction Default<T extends TSchema>(\n schema: T,\n defaultValue: Static<T>,\n): T & { default: Static<T> } {\n return { ...schema, default: defaultValue }\n}\n\nexport const Type = {\n ...BaseType,\n StringEnum,\n Default,\n} as typeof BaseType & {\n StringEnum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AA,QACH,CAAC,aAAa,GAAG,EAAE,YAAY,SAAS,IAAI,QAAQ,UAAU;AAAA,MAChE,EAAE;AAAA,IACJ;AAAA,EACF,UAAE;AACA,QAAI,wBAAwB;AAC1B,iCAA2B;AAAA,IAC7B;AAAA,EACF;AACF;;;AIvBO,SAAS,aACd,SACwB;AACxB,SAAO;AAAA,IACL,MAAM,CAAC;AAAA,IACP,GAAG;AAAA,EACL;AACF;AAEO,SAAS,SAAS,OAAiC;AACxD,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,YAAY,SACZ,UAAU;AAEd;;;ACrDA,OAUO;;;ACoBP,eAA4B;AAE5B;AAAA,EACE,QAAQ;AAAA,OAKH;AAMP,SAAS,WAA+B,QAAyC;AAC/E,SAAO,KAAK,MAAM,OAAO,IAAI,WAAS,KAAK,QAAQ,KAAK,CAAC,CAAC;AAC5D;AAEA,SAAS,QACP,QACA,cAC4B;AAC5B,SAAO,EAAE,GAAG,QAAQ,SAAS,aAAa;AAC5C;AAEO,IAAM,OAAO;AAAA,EAClB,GAAG;AAAA,EACH;AAAA,EACA;AACF;","names":["mapValues","mapValues","text","indent","inputs","outputs","mapValues","mapValues","outputs"]}
1
+ {"version":3,"sources":["../src/instance.ts","../src/evaluation.ts","../src/unit.ts","../src/component.ts","../src/utils.ts","../src/entity.ts","../src/types.ts","../src/index.ts"],"sourcesContent":["declare const type: unique symbol\n\nexport type InstanceInput<TType extends string = string> = {\n [type]?: TType\n [boundaryInput]?: InstanceInput\n instanceId: string\n output: string\n}\n\nexport const boundaryInput = Symbol(\"boundaryInput\")\n\nexport type HubInput = {\n hubId: string\n}\n\nexport type Position = {\n x: number\n y: number\n}\n\nexport type InstanceModel = {\n /**\n * The id of the instance unique within the project.\n *\n * The format is `${instanceType}:${instanceName}`.\n */\n id: string\n\n /**\n * The type of the instance.\n */\n type: string\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: string\n\n /**\n * The static arguments passed to the instance.\n */\n args?: Record<string, unknown>\n\n /**\n * The direct instances passed as inputs to the instance.\n */\n inputs?: Record<string, InstanceInput[]>\n\n /**\n * The resolved unit inputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedInputs?: Record<string, InstanceInput[]>\n\n /**\n * The inputs passed to the instance from the hubs.\n *\n * Only for designer-first instances.\n */\n hubInputs?: Record<string, HubInput[]>\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?: HubInput[]\n\n /**\n * The position of the instance on the canvas.\n *\n * Only for designer-first instances.\n */\n position?: Position\n\n /**\n * The id of the top level parent instance.\n *\n * Only for child instances of the composite instances.\n */\n parentId?: string\n\n /**\n * The direct instance inputs and same-level children outputs returned by the instance as outputs.\n *\n * Only for computed composite instances.\n */\n outputs?: Record<string, InstanceInput[]>\n\n /**\n * The resolved unit outputs for the instance.\n *\n * Only for computed composite instances.\n */\n resolvedOutputs?: Record<string, InstanceInput[]>\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: string, instanceName: string): string {\n return `${instanceType}:${instanceName}`\n}\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(instanceId: string): [instanceType: string, instanceName: string] {\n const parts = instanceId.split(\":\")\n\n if (parts.length !== 2) {\n throw new Error(`Invalid instance key: ${instanceId}`)\n }\n\n return parts as [string, string]\n}\n\nexport function findInput<T extends string>(\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 string>(\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 string>(\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 string>(\n inputs: InstanceInput<T>[],\n names: string[],\n): InstanceInput<T>[] {\n return names.map(name => findRequiredInput(inputs, name))\n}\n","import type { ComponentModel } from \"./component\"\nimport { mapValues } from \"remeda\"\nimport { boundaryInput, type InstanceInput, type InstanceModel } from \"./instance\"\nimport { isUnitModel } from \"./unit\"\n\nexport type CompositeInstance = {\n instance: InstanceModel\n children: InstanceModel[]\n}\n\nconst compositeInstances: Map<string, CompositeInstance> = new Map()\nlet currentCompositeInstance: CompositeInstance | null = null\n\nexport function resetEvaluation(): void {\n compositeInstances.clear()\n currentCompositeInstance = null\n}\n\nexport function getCompositeInstances(): CompositeInstance[] {\n return Array.from(compositeInstances.values())\n}\n\nexport function registerInstance<T>(\n component: ComponentModel,\n instance: InstanceModel,\n fn: () => T,\n): T {\n if (currentCompositeInstance) {\n instance.parentId = currentCompositeInstance.instance.id\n currentCompositeInstance.children.push(instance)\n }\n\n let previousParentInstance: CompositeInstance | null = null\n if (!isUnitModel(component)) {\n previousParentInstance = currentCompositeInstance\n currentCompositeInstance = { instance, children: [] }\n compositeInstances.set(currentCompositeInstance.instance.id, currentCompositeInstance)\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 currentCompositeInstance = previousParentInstance\n }\n }\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\nimport type { ArgumentValue } from \"./types\"\nimport type { InstanceInput } from \"./instance\"\nimport { mapValues } from \"remeda\"\nimport {\n type ComponentArgumentSpec,\n type Component,\n type ComponentArgument,\n type ComponentArgumentOptions,\n type ComponentInputOptions,\n type ComponentInputOptionsMapToSpecMap,\n type ComponentInputSpec,\n type ComponentModel,\n type ComponentOptions,\n defineComponent,\n mapArgument,\n type ComponentArgumentOptionsMapToSpecMap,\n} from \"./component\"\n\ntype UnitOptions<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n TSecrets extends Record<string, ComponentArgumentOptions>,\n> = Omit<ComponentOptions<TArgs, TInputs, TOutputs>, \"create\"> & {\n source: UnitSource\n\n secrets?: TSecrets\n}\n\nexport type UnitSource = {\n package: string\n path?: string\n version?: string\n}\n\nexport type UnitModel = ComponentModel & {\n /**\n * The source of the unit.\n */\n source: UnitSource\n\n /**\n * The record of the secret argument schemas.\n */\n secrets: Record<string, ComponentArgument>\n}\n\nexport type Unit<\n TArgs extends Record<string, ComponentArgumentSpec> = 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, ArgumentValue> = Record<string, never>,\n> = Component<TArgs, TInputs, TOutputs> & {\n __secrets: TSecrets\n\n model: UnitModel\n}\n\nexport function isUnitModel(model: ComponentModel): model is UnitModel {\n return \"source\" in model\n}\n\nexport function defineUnit<\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, ComponentArgumentOptions> = Record<string, never>,\n>(\n options: UnitOptions<TArgs, TInputs, TOutputs, TSecrets>,\n): Unit<\n ComponentArgumentOptionsMapToSpecMap<TArgs>,\n ComponentInputOptionsMapToSpecMap<TInputs>,\n ComponentInputOptionsMapToSpecMap<TOutputs>,\n ComponentArgumentOptionsMapToSpecMap<TSecrets>\n> {\n const component = defineComponent<TArgs, TInputs, TOutputs>({\n ...options,\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 component.model.source = options.source ?? {}\n component.model.secrets = mapValues(options.secrets ?? {}, mapArgument)\n\n return component\n}\n","/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport type { Entity } from \"./entity\"\nimport type { ArgumentValue, ArgumentValueSchema, Meta } from \"./types\"\nimport {\n type Static,\n type TObject,\n type TOptional,\n type TSchema,\n OptionalKind,\n} from \"@sinclair/typebox\"\nimport { isNonNullish, mapValues, pickBy } from \"remeda\"\nimport { Ajv } from \"ajv\"\nimport { boundaryInput, type InstanceInput } from \"./instance\"\nimport { type OptionalUndefinedFields, type OptionalEmptyRecords } from \"./utils\"\nimport { registerInstance } from \"./evaluation\"\n\nconst ajv = new Ajv({ strict: false })\n\n// Argument\nexport type ComponentArgument = {\n schema: ArgumentValueSchema\n required: boolean\n meta: Meta\n}\n\ntype ComponentArgumentFullOptions = Meta & {\n schema: ArgumentValueSchema\n required?: boolean\n}\n\nexport type ComponentArgumentOptions = ArgumentValueSchema | ComponentArgumentFullOptions\nexport type ComponentArgumentSpec = [schema: ArgumentValueSchema, required: boolean]\n\nexport type ComponentArgumentOptionsToSpec<T extends ComponentArgumentOptions> =\n T extends ArgumentValueSchema\n ? T extends { default: unknown }\n ? [T, false]\n : [T, true]\n : T extends ComponentArgumentFullOptions\n ? T[\"required\"] extends false\n ? [T[\"schema\"], false]\n : [T[\"schema\"], true]\n : never\n\nexport type ComponentArgumentOptionsMapToSpecMap<\n T extends Record<string, ComponentArgumentOptions>,\n> =\n T extends Record<string, never>\n ? Record<string, never>\n : { [K in keyof T]: ComponentArgumentOptionsToSpec<T[K]> }\n\nexport type ComponentArgumentSpecMapToInputStatic<T extends Record<string, ComponentArgumentSpec>> =\n T extends Record<string, never>\n ? Record<string, never>\n : Static<TObject<{ [K in keyof T]: T[K][1] extends true ? T[K][0] : TOptional<T[K][0]> }>>\n\nexport type ComponentArgumentSpecToStatic<T extends Record<string, ComponentArgumentSpec>> =\n T extends Record<string, never>\n ? Record<string, never>\n : Static<TObject<{ [K in keyof T]: T[K][0] }>>\n\nexport type ComponentArgumentOptionsToSchema<T extends ComponentArgumentOptions> = T extends TSchema\n ? T\n : T[\"required\"] extends false\n ? TOptional<T[\"schema\"]>\n : T[\"schema\"]\n\ntype ComponentArgumentMapToValue<T extends Record<string, ComponentArgumentOptions>> = {\n [K in keyof T]: Static<ComponentArgumentOptionsToSchema<T[K]>>\n}\n\n// Input\nexport type ComponentInput = {\n type: string\n required: boolean\n multiple: boolean\n meta: Meta\n}\n\ntype ComponentInputFullOptions = Meta & {\n entity: Entity\n required?: boolean\n multiple?: boolean\n}\n\nexport type ComponentInputOptions = Entity | ComponentInputFullOptions\n\ntype ComponentInputOptionsToOutputRef<T extends ComponentInputOptions> = T extends Entity\n ? InstanceInput<T[\"type\"]>\n : T extends ComponentInputFullOptions\n ? T[\"required\"] extends false\n ? T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][\"type\"]>[] | undefined\n : InstanceInput<T[\"entity\"][\"type\"]> | undefined\n : T[\"multiple\"] extends true\n ? InstanceInput<T[\"entity\"][\"type\"]>[]\n : InstanceInput<T[\"entity\"][\"type\"]>\n : never\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 ComponentInputFullOptions\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 T extends Record<string, never> ? void : ComponentInputMapToValue<T>\n\n// Params & Options\nexport type ComponentParams<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n> = {\n id: string\n name: string\n args: ComponentArgumentMapToValue<TArgs>\n inputs: ComponentInputMapToValue<TInputs>\n}\n\nexport type InputComponentParams<\n TArgs extends Record<string, ArgumentValue>,\n TInputs extends Record<string, unknown>,\n> = {\n name: string\n} & OptionalEmptyRecords<{\n args: TArgs\n inputs: TInputs\n}>\n\nexport type ComponentOptions<\n TArgs extends Record<string, ComponentArgumentOptions>,\n TInputs extends Record<string, ComponentInputOptions>,\n TOutputs extends Record<string, ComponentInputOptions>,\n> = {\n type: string\n meta?: ComponentMeta\n\n args?: TArgs\n inputs?: TInputs\n outputs?: TOutputs\n\n create: (params: ComponentParams<TArgs, TInputs>) => ComponentInputMapToReturnType<TOutputs>\n}\n\n// Models\nexport type ComponentMeta = Meta & {\n primaryIcon?: string\n primaryIconColor?: string\n secondaryIcon?: string\n secondaryIconColor?: string\n category?: string\n defaultNamePrefix?: string\n}\n\nexport type ComponentModel = {\n /**\n * The type of the component.\n */\n type: string\n\n /**\n * The record of the argument schemas.\n */\n args: Record<string, ComponentArgument>\n\n /**\n * The record of the input schemas.\n */\n inputs: Record<string, ComponentInput>\n\n /**\n * The record of the output schemas.\n */\n outputs: Record<string, ComponentInput>\n\n /**\n * The extra metadata of the component.\n */\n meta: ComponentMeta\n\n /**\n * The hash of the component definition.\n */\n definitionHash: string\n}\n\ntype InputSpecToInputRef<T extends ComponentInputSpec> = T[1] extends true\n ? T[2] extends true\n ? InstanceInput<T[0][\"type\"]>[]\n : InstanceInput<T[0][\"type\"]>\n : T[2] extends true\n ? InstanceInput<T[0][\"type\"]>[] | undefined\n : InstanceInput<T[0][\"type\"]> | undefined\n\ntype InputSpecToOutputRef<T extends ComponentInputSpec> = T[2] extends true\n ? InstanceInput<T[0][\"type\"]>[]\n : InstanceInput<T[0][\"type\"]>\n\nexport type InputRefMap<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\")\n\nexport type Component<\n TArgs extends Record<string, ComponentArgumentSpec> = 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 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 * Creates the component at the evaluation time.\n */\n (\n context: InputComponentParams<\n ComponentArgumentSpecMapToInputStatic<TArgs>,\n InputRefMap<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 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<TArgs, TInputs, TOutputs>,\n): Component<\n ComponentArgumentOptionsMapToSpecMap<TArgs>,\n ComponentInputOptionsMapToSpecMap<TInputs>,\n ComponentInputOptionsMapToSpecMap<TOutputs>\n> {\n function create(params: InputComponentParams<any, any>): any {\n const { name, args, inputs } = params\n const id = `${options.type}:${name}`\n\n const flatInputs = mapValues(pickBy(inputs ?? {}, isNonNullish), inputs => [inputs].flat(2))\n\n return registerInstance(\n create.model as ComponentModel,\n {\n id,\n type: options.type,\n name,\n args: args ?? {},\n inputs: mapValues(flatInputs, inputs => inputs.map(input => input[boundaryInput] ?? input)),\n resolvedInputs: flatInputs,\n },\n () => {\n const markedInputs = mapValues(flatInputs, (inputs, key) => {\n const result = inputs.map(input => ({\n ...input,\n [boundaryInput]: { instanceId: id, output: key },\n }))\n\n return (create.model as ComponentModel).inputs?.[key]?.multiple === false\n ? result[0]\n : result\n })\n\n const outputs: Record<string, InstanceInput[]> =\n options.create({\n id,\n name,\n args: validateArgsAndFillDefaults(\n id,\n create.model as ComponentModel,\n args ? { ...args } : {},\n ) as any,\n inputs: markedInputs as any,\n }) ?? {}\n\n return mapValues(pickBy(outputs, isNonNullish), outputs => [outputs].flat(2))\n },\n )\n }\n\n create.entities = new Map<string, Entity>()\n const mapInput = createInputMapper(create.entities)\n\n create.model = {\n type: options.type,\n args: mapValues(options.args ?? {}, mapArgument),\n inputs: mapValues(options.inputs ?? {}, mapInput),\n outputs: mapValues(options.outputs ?? {}, mapInput),\n meta: options.meta ?? {},\n }\n\n create[originalCreate] = options.create\n\n return create as any\n}\n\nexport function isComponent(value: unknown): value is Component {\n return typeof value === \"function\" && \"model\" in value\n}\n\nexport function mapArgument(value: ComponentArgumentOptions) {\n if (\"schema\" in value) {\n return {\n schema: value.schema,\n required: value.required ?? (!value.schema[OptionalKind] && !value.schema.default),\n meta: {\n displayName: value.displayName,\n description: value.description,\n color: value.color,\n },\n }\n }\n\n return {\n schema: value,\n required: !value[OptionalKind] && !value.default,\n meta: {},\n }\n}\n\nexport function createInputMapper(entities: Map<string, Entity>) {\n return (value: ComponentInputOptions) => {\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 displayName: value.displayName,\n description: value.description,\n color: value.color,\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 }\n }\n}\n\nfunction validateArgsAndFillDefaults(\n instanceId: string,\n model: ComponentModel,\n args: Record<string, unknown>,\n) {\n for (const [key, argModel] of Object.entries(model.args)) {\n let value = args[key]\n if (!value) {\n if (argModel.required) {\n throw new Error(`Missing required argument \"${key}\" for instance \"${instanceId}\"`)\n }\n\n value = argModel.schema.default\n args[key] = value\n }\n\n if (value && !ajv.validate(argModel.schema, value)) {\n throw new Error(`Invalid argument \"${key}\" for instance \"${instanceId}\": ${ajv.errorsText()}`)\n }\n }\n\n return args as Record<string, ArgumentValue>\n}\n","export type EntityMap<T> = Record<string, T> & {\n default?: T\n}\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>\n\n// TODO: refactor this shit\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 * 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(array: TemplateStringsArray, ...values: unknown[]): string {\n const str = array.reduce(\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n (result, part, i) => result + part + (values[i] ? String(values[i]) : \"\"),\n \"\",\n )\n\n return trimIndentation(str)\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","import type { TAnySchema, TSchema } from \"@sinclair/typebox\"\nimport type { Meta } from \"./types\"\nimport type { PartialKeys } from \"./utils\"\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 type Entity<TType extends string = string, TEntitySchema extends TSchema = TSchema> = {\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: TEntitySchema\n\n /**\n * The extra metadata of the entity.\n */\n meta: Meta\n\n /**\n * The hash of the entity definition.\n */\n definitionHash: string\n}\n\nexport type EntityOptions<TType extends string, TSchema extends TAnySchema> = Omit<\n PartialKeys<Entity<TType, TSchema>, \"meta\">,\n \"definitionHash\"\n>\n\nexport function defineEntity<TType extends string, TSchema extends TAnySchema>(\n options: EntityOptions<TType, TSchema>,\n): Entity<TType, TSchema> {\n return {\n meta: {},\n ...options,\n } as Entity<TType, TSchema>\n}\n\nexport function isEntity(value: unknown): value is Entity {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n \"schema\" in value &&\n \"meta\" in value\n )\n}\n","import {\n type Static,\n type TAny,\n type TArray,\n type TBoolean,\n type TLiteral,\n type TNumber,\n type TObject,\n type TRecordOrObject,\n type TString,\n type TUnion,\n} from \"@sinclair/typebox\"\n\nexport type ArgumentValueSchema =\n | TString\n | TNumber\n | TBoolean\n | TArray<TString>\n | TArray<TNumber>\n | TUnion<TLiteral[]>\n | TRecordOrObject<TString, TAny>\n | TObject\n | TArray\n | TUnion<TObject[]>\n\nexport type ArgumentValue = Static<ArgumentValueSchema>\n\n/**\n * The generic metadata of some contract.\n */\nexport type Meta = {\n /**\n * The display name of the entity which can be shown in the UI.\n */\n displayName?: string\n\n /**\n * The description of the entity which can be shown in the UI.\n */\n description?: string\n\n /**\n * The hex color of the entity which can be used in the UI.\n *\n * @example \"#ff0000\"\n */\n color?: string\n}\n","export {\n type InstanceInput,\n type HubInput,\n type InstanceModel,\n type Position,\n getInstanceId,\n parseInstanceId,\n findInput,\n findRequiredInput,\n findInputs,\n findRequiredInputs,\n} from \"./instance\"\nexport { getCompositeInstances, resetEvaluation, type CompositeInstance } from \"./evaluation\"\nexport { type Entity, defineEntity, isEntity } from \"./entity\"\nexport {\n type Component,\n type ComponentModel,\n type ComponentMeta,\n type ComponentArgument,\n type ComponentInput,\n type ComponentInputSpec,\n type ComponentArgumentSpec,\n type ComponentArgumentSpecToStatic,\n defineComponent,\n isComponent,\n originalCreate,\n} from \"./component\"\nexport { type Unit, type UnitModel, type UnitSource, defineUnit, isUnitModel } from \"./unit\"\nexport { type RequiredKeys, type PartialKeys, text, trimIndentation } from \"./utils\"\nexport { type ArgumentValue, type ArgumentValueSchema } from \"./types\"\nexport { type Static } from \"@sinclair/typebox\"\n\nimport {\n Type as BaseType,\n type Static,\n type TLiteral,\n type TSchema,\n type TUnion,\n} from \"@sinclair/typebox\"\n\ntype MapToLiteral<T extends readonly string[]> = {\n [K in keyof T]: T[K] extends string ? TLiteral<T[K]> : never\n}\n\nfunction StringEnum<T extends string[]>(values: [...T]): TUnion<MapToLiteral<T>> {\n return Type.Union(values.map(value => Type.Literal(value))) as TUnion<MapToLiteral<T>>\n}\n\nfunction Default<T extends TSchema>(\n schema: T,\n defaultValue: Static<T>,\n): T & { default: Static<T> } {\n return { ...schema, default: defaultValue }\n}\n\nexport const Type = {\n ...BaseType,\n StringEnum,\n Default,\n} as typeof BaseType & {\n StringEnum: typeof StringEnum\n Default: typeof Default\n}\n"],"mappings":";AASO,IAAM,gBAAgB,OAAO,eAAe;AAsG5C,SAAS,cAAc,cAAsB,cAA8B;AAChF,SAAO,GAAG,YAAY,IAAI,YAAY;AACxC;AASO,SAAS,gBAAgB,YAAkE;AAChG,QAAM,QAAQ,WAAW,MAAM,GAAG;AAElC,MAAI,MAAM,WAAW,GAAG;AACtB,UAAM,IAAI,MAAM,yBAAyB,UAAU,EAAE;AAAA,EACvD;AAEA,SAAO;AACT;AAEO,SAAS,UACd,QACA,MACyB;AACzB,QAAM,gBAAgB,OAAO;AAAA,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DA,OAWO;;;ACmBP,eAA4B;AAE5B;AAAA,EACE,QAAQ;AAAA,OAKH;AAMP,SAAS,WAA+B,QAAyC;AAC/E,SAAO,KAAK,MAAM,OAAO,IAAI,WAAS,KAAK,QAAQ,KAAK,CAAC,CAAC;AAC5D;AAEA,SAAS,QACP,QACA,cAC4B;AAC5B,SAAO,EAAE,GAAG,QAAQ,SAAS,aAAa;AAC5C;AAEO,IAAM,OAAO;AAAA,EAClB,GAAG;AAAA,EACH;AAAA,EACA;AACF;","names":["mapValues","mapValues","text","indent","inputs","outputs","mapValues","mapValues","outputs"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highstate/contract",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -29,5 +29,5 @@
29
29
  "highstate-cli-bootstrap": "npm:@highstate/cli@0.7.6",
30
30
  "vitest": "^2.1.8"
31
31
  },
32
- "gitHead": "8590eea089a016c9b4b797299fc94ddc9afe10ba"
32
+ "gitHead": "b64df0df33afcadf019936eaa2a2ca7ffc82940b"
33
33
  }
package/src/component.ts CHANGED
@@ -206,7 +206,7 @@ export type ComponentModel = {
206
206
  definitionHash: string
207
207
  }
208
208
 
209
- type InputSpecToOutputRef<T extends ComponentInputSpec> = T[1] extends true
209
+ type InputSpecToInputRef<T extends ComponentInputSpec> = T[1] extends true
210
210
  ? T[2] extends true
211
211
  ? InstanceInput<T[0]["type"]>[]
212
212
  : InstanceInput<T[0]["type"]>
@@ -214,6 +214,15 @@ type InputSpecToOutputRef<T extends ComponentInputSpec> = T[1] extends true
214
214
  ? InstanceInput<T[0]["type"]>[] | undefined
215
215
  : InstanceInput<T[0]["type"]> | undefined
216
216
 
217
+ type InputSpecToOutputRef<T extends ComponentInputSpec> = T[2] extends true
218
+ ? InstanceInput<T[0]["type"]>[]
219
+ : InstanceInput<T[0]["type"]>
220
+
221
+ export type InputRefMap<TInputs extends Record<string, ComponentInputSpec>> =
222
+ TInputs extends Record<string, [string, never, never]>
223
+ ? Record<string, never>
224
+ : { [K in keyof TInputs]: InputSpecToInputRef<TInputs[K]> }
225
+
217
226
  export type OutputRefMap<TInputs extends Record<string, ComponentInputSpec>> =
218
227
  TInputs extends Record<string, [string, never, never]>
219
228
  ? Record<string, never>
@@ -242,7 +251,7 @@ export type Component<
242
251
  (
243
252
  context: InputComponentParams<
244
253
  ComponentArgumentSpecMapToInputStatic<TArgs>,
245
- OutputRefMap<TInputs>
254
+ InputRefMap<TInputs>
246
255
  >,
247
256
  ): OutputRefMap<TOutputs>
248
257
 
package/src/types.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type TBoolean,
6
6
  type TLiteral,
7
7
  type TNumber,
8
+ type TObject,
8
9
  type TRecordOrObject,
9
10
  type TString,
10
11
  type TUnion,
@@ -18,7 +19,9 @@ export type ArgumentValueSchema =
18
19
  | TArray<TNumber>
19
20
  | TUnion<TLiteral[]>
20
21
  | TRecordOrObject<TString, TAny>
22
+ | TObject
21
23
  | TArray
24
+ | TUnion<TObject[]>
22
25
 
23
26
  export type ArgumentValue = Static<ArgumentValueSchema>
24
27