@highstate/contract 0.7.2 → 0.7.4
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 +240 -0
- package/package.json +8 -8
- package/src/component.spec.ts +166 -0
- package/src/component.ts +361 -0
- package/src/entity.ts +54 -0
- package/src/evaluation.ts +60 -0
- package/src/index.ts +42 -0
- package/src/instance.ts +165 -0
- package/src/types.ts +45 -0
- package/src/unit.ts +102 -0
- package/src/utils.ts +89 -0
- package/dist/index.d.ts +0 -326
- package/dist/index.mjs +0 -192
package/src/types.ts
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
import {
|
2
|
+
type Static,
|
3
|
+
type TAny,
|
4
|
+
type TArray,
|
5
|
+
type TBoolean,
|
6
|
+
type TLiteral,
|
7
|
+
type TNumber,
|
8
|
+
type TRecordOrObject,
|
9
|
+
type TString,
|
10
|
+
type TUnion,
|
11
|
+
} from "@sinclair/typebox"
|
12
|
+
|
13
|
+
export type ArgumentValueSchema =
|
14
|
+
| TString
|
15
|
+
| TNumber
|
16
|
+
| TBoolean
|
17
|
+
| TArray<TString>
|
18
|
+
| TArray<TNumber>
|
19
|
+
| TUnion<TLiteral[]>
|
20
|
+
| TRecordOrObject<TString, TAny>
|
21
|
+
| TArray
|
22
|
+
|
23
|
+
export type ArgumentValue = Static<ArgumentValueSchema>
|
24
|
+
|
25
|
+
/**
|
26
|
+
* The generic metadata of some contract.
|
27
|
+
*/
|
28
|
+
export type Meta = {
|
29
|
+
/**
|
30
|
+
* The display name of the entity which can be shown in the UI.
|
31
|
+
*/
|
32
|
+
displayName?: string
|
33
|
+
|
34
|
+
/**
|
35
|
+
* The description of the entity which can be shown in the UI.
|
36
|
+
*/
|
37
|
+
description?: string
|
38
|
+
|
39
|
+
/**
|
40
|
+
* The hex color of the entity which can be used in the UI.
|
41
|
+
*
|
42
|
+
* @example "#ff0000"
|
43
|
+
*/
|
44
|
+
color?: string
|
45
|
+
}
|
package/src/unit.ts
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
5
|
+
|
6
|
+
import type { ArgumentValue } from "./types"
|
7
|
+
import type { InstanceInput } from "./instance"
|
8
|
+
import { mapValues } from "remeda"
|
9
|
+
import {
|
10
|
+
type ArgumentOptionsMapToStatic,
|
11
|
+
type Component,
|
12
|
+
type ComponentArgument,
|
13
|
+
type ComponentArgumentOptions,
|
14
|
+
type ComponentInputOptions,
|
15
|
+
type ComponentInputOptionsMapToSpecMap,
|
16
|
+
type ComponentInputSpec,
|
17
|
+
type ComponentModel,
|
18
|
+
type ComponentOptions,
|
19
|
+
defineComponent,
|
20
|
+
mapArgument,
|
21
|
+
} from "./component"
|
22
|
+
|
23
|
+
type UnitOptions<
|
24
|
+
TArgs extends Record<string, ComponentArgumentOptions>,
|
25
|
+
TInputs extends Record<string, ComponentInputOptions>,
|
26
|
+
TOutputs extends Record<string, ComponentInputOptions>,
|
27
|
+
TSecrets extends Record<string, ComponentArgumentOptions>,
|
28
|
+
> = Omit<ComponentOptions<TArgs, TInputs, TOutputs>, "create"> & {
|
29
|
+
source: UnitSource
|
30
|
+
|
31
|
+
secrets?: TSecrets
|
32
|
+
}
|
33
|
+
|
34
|
+
export type UnitSource = {
|
35
|
+
package: string
|
36
|
+
path?: string
|
37
|
+
version?: string
|
38
|
+
}
|
39
|
+
|
40
|
+
export type UnitModel = ComponentModel & {
|
41
|
+
/**
|
42
|
+
* The source of the unit.
|
43
|
+
*/
|
44
|
+
source: UnitSource
|
45
|
+
|
46
|
+
/**
|
47
|
+
* The record of the secret argument schemas.
|
48
|
+
*/
|
49
|
+
secrets: Record<string, ComponentArgument>
|
50
|
+
}
|
51
|
+
|
52
|
+
export type Unit<
|
53
|
+
TArgs extends Record<string, ArgumentValue> = Record<string, never>,
|
54
|
+
TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,
|
55
|
+
TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,
|
56
|
+
TSecrets extends Record<string, ArgumentValue> = Record<string, never>,
|
57
|
+
> = Component<TArgs, TInputs, TOutputs> & {
|
58
|
+
__secrets: TSecrets
|
59
|
+
|
60
|
+
model: UnitModel
|
61
|
+
}
|
62
|
+
|
63
|
+
export function isUnitModel(model: ComponentModel): model is UnitModel {
|
64
|
+
return "source" in model
|
65
|
+
}
|
66
|
+
|
67
|
+
export function defineUnit<
|
68
|
+
TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,
|
69
|
+
TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,
|
70
|
+
TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>,
|
71
|
+
TSecrets extends Record<string, ComponentArgumentOptions> = Record<string, never>,
|
72
|
+
>(
|
73
|
+
options: UnitOptions<TArgs, TInputs, TOutputs, TSecrets>,
|
74
|
+
): Unit<
|
75
|
+
ArgumentOptionsMapToStatic<TArgs>,
|
76
|
+
ComponentInputOptionsMapToSpecMap<TInputs>,
|
77
|
+
ComponentInputOptionsMapToSpecMap<TOutputs>,
|
78
|
+
ArgumentOptionsMapToStatic<TSecrets>
|
79
|
+
> {
|
80
|
+
const component = defineComponent<TArgs, TInputs, TOutputs>({
|
81
|
+
...options,
|
82
|
+
|
83
|
+
create({ id }) {
|
84
|
+
const outputs: Record<string, InstanceInput[]> = {}
|
85
|
+
for (const key in options.outputs ?? {}) {
|
86
|
+
outputs[key] = [
|
87
|
+
{
|
88
|
+
instanceId: id,
|
89
|
+
output: key,
|
90
|
+
},
|
91
|
+
]
|
92
|
+
}
|
93
|
+
|
94
|
+
return outputs as any
|
95
|
+
},
|
96
|
+
}) as any
|
97
|
+
|
98
|
+
component.model.source = options.source ?? {}
|
99
|
+
component.model.secrets = mapValues(options.secrets ?? {}, mapArgument)
|
100
|
+
|
101
|
+
return component
|
102
|
+
}
|
package/src/utils.ts
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
export type EntityMap<T> = Record<string, T> & {
|
2
|
+
default?: T
|
3
|
+
}
|
4
|
+
|
5
|
+
export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
6
|
+
export type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
|
7
|
+
|
8
|
+
// TODO: refactor this shit
|
9
|
+
|
10
|
+
type PickUndefinedKeys<T extends Record<string, unknown>> = T extends Record<string, never>
|
11
|
+
? never
|
12
|
+
: Exclude<
|
13
|
+
{
|
14
|
+
[K in keyof T]: undefined extends T[K] ? K : never
|
15
|
+
}[keyof T],
|
16
|
+
undefined
|
17
|
+
>
|
18
|
+
|
19
|
+
type AllOptionalKeys<T extends Record<string, unknown>> = T extends Record<string, never>
|
20
|
+
? never
|
21
|
+
: Exclude<
|
22
|
+
{
|
23
|
+
[K in keyof T]: undefined extends T[K] ? K : never
|
24
|
+
}[keyof T],
|
25
|
+
undefined
|
26
|
+
>
|
27
|
+
|
28
|
+
type HasRequired<T extends Record<string, unknown>> = T extends Record<string, never>
|
29
|
+
? false
|
30
|
+
: [keyof T] extends [AllOptionalKeys<T>]
|
31
|
+
? false
|
32
|
+
: true
|
33
|
+
|
34
|
+
type PickRecordsWithAnyRequired<T extends Record<string, Record<string, unknown>>> =
|
35
|
+
T extends Record<string, never>
|
36
|
+
? never
|
37
|
+
: Exclude<
|
38
|
+
{
|
39
|
+
[K in keyof T]: HasRequired<T[K]> extends true ? K : never
|
40
|
+
}[keyof T],
|
41
|
+
undefined
|
42
|
+
>
|
43
|
+
|
44
|
+
export type OptionalEmptyRecords<T extends Record<string, Record<string, unknown>>> = {
|
45
|
+
[K in Exclude<keyof T, PickRecordsWithAnyRequired<T>>]?: OptionalUndefinedFields<T[K]>
|
46
|
+
} & {
|
47
|
+
[K in PickRecordsWithAnyRequired<T>]: OptionalUndefinedFields<T[K]>
|
48
|
+
}
|
49
|
+
|
50
|
+
export type OptionalUndefinedFields<T extends Record<string, unknown>> = {
|
51
|
+
[K in PickUndefinedKeys<T>]?: T[K]
|
52
|
+
} & {
|
53
|
+
[K in Exclude<keyof T, PickUndefinedKeys<T>>]: T[K]
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Formats a multiline string and trims the indentation.
|
58
|
+
*
|
59
|
+
* @param str The string to trim.
|
60
|
+
* @returns The trimmed string.
|
61
|
+
*/
|
62
|
+
export function text(array: TemplateStringsArray, ...values: unknown[]): string {
|
63
|
+
const str = array.reduce(
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
65
|
+
(result, part, i) => result + part + (values[i] ? String(values[i]) : ""),
|
66
|
+
"",
|
67
|
+
)
|
68
|
+
|
69
|
+
return trimIndentation(str)
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Removes the indentation from a multiline string.
|
74
|
+
*
|
75
|
+
* @param text The text to trim.
|
76
|
+
* @returns The trimmed text.
|
77
|
+
*/
|
78
|
+
export function trimIndentation(text: string): string {
|
79
|
+
const lines = text.split("\n")
|
80
|
+
const indent = lines
|
81
|
+
.filter(line => line.trim() !== "")
|
82
|
+
.map(line => line.match(/^\s*/)?.[0].length ?? 0)
|
83
|
+
.reduce((min, indent) => Math.min(min, indent), Infinity)
|
84
|
+
|
85
|
+
return lines
|
86
|
+
.map(line => line.slice(indent))
|
87
|
+
.join("\n")
|
88
|
+
.trim()
|
89
|
+
}
|
package/dist/index.d.ts
DELETED
@@ -1,326 +0,0 @@
|
|
1
|
-
import { Static, TString, TNumber, TBoolean, TArray, TUnion, TLiteral, TRecordOrObject, TAny, TSchema, TAnySchema, TOptional, TObject } from '@sinclair/typebox';
|
2
|
-
export { Static, Type } from '@sinclair/typebox';
|
3
|
-
|
4
|
-
declare const InstanceType: unique symbol;
|
5
|
-
type InstanceInput<TType extends string = string> = {
|
6
|
-
[InstanceType]?: TType;
|
7
|
-
instanceId: string;
|
8
|
-
output: string;
|
9
|
-
};
|
10
|
-
type HubInput = {
|
11
|
-
hubId: string;
|
12
|
-
};
|
13
|
-
type Position = {
|
14
|
-
x: number;
|
15
|
-
y: number;
|
16
|
-
};
|
17
|
-
type InstanceModel = {
|
18
|
-
/**
|
19
|
-
* The id of the instance unique within the project.
|
20
|
-
*
|
21
|
-
* The format is `${instanceType}:${instanceName}`.
|
22
|
-
*/
|
23
|
-
id: string;
|
24
|
-
/**
|
25
|
-
* The type of the instance.
|
26
|
-
*/
|
27
|
-
type: string;
|
28
|
-
/**
|
29
|
-
* The name of the instance.
|
30
|
-
*
|
31
|
-
* Must be unique within instances of the same type in the project.
|
32
|
-
*/
|
33
|
-
name: string;
|
34
|
-
/**
|
35
|
-
* The static arguments passed to the instance.
|
36
|
-
*/
|
37
|
-
args?: Record<string, unknown>;
|
38
|
-
/**
|
39
|
-
* The direct instances passed as inputs to the instance.
|
40
|
-
*/
|
41
|
-
inputs?: Record<string, InstanceInput[]>;
|
42
|
-
/**
|
43
|
-
* The inputs passed to the instance from the hubs.
|
44
|
-
*
|
45
|
-
* Only for designer-first instances.
|
46
|
-
*/
|
47
|
-
hubInputs?: Record<string, HubInput[]>;
|
48
|
-
/**
|
49
|
-
* The inputs injected to the instance from the hubs.
|
50
|
-
*
|
51
|
-
* While `hubInputs` allows to pass hubs to distinct inputs,
|
52
|
-
* `injectionInputs` allows to pass hubs to the instance as a whole filling all inputs with matching types.
|
53
|
-
*
|
54
|
-
* Only for designer-first instances.
|
55
|
-
*/
|
56
|
-
injectionInputs?: HubInput[];
|
57
|
-
/**
|
58
|
-
* The position of the instance on the canvas.
|
59
|
-
*
|
60
|
-
* Only for designer-first instances.
|
61
|
-
*/
|
62
|
-
position?: Position;
|
63
|
-
/**
|
64
|
-
* The id of the parent instance.
|
65
|
-
*
|
66
|
-
* Only for child instances of the composite instances.
|
67
|
-
*/
|
68
|
-
parentId?: string;
|
69
|
-
/**
|
70
|
-
* The direct instance inputs which instance returns as outputs.
|
71
|
-
*
|
72
|
-
* Only for computed composite instances.
|
73
|
-
*/
|
74
|
-
outputs?: Record<string, InstanceInput[]>;
|
75
|
-
};
|
76
|
-
/**
|
77
|
-
* Formats the instance id from the instance type and instance name.
|
78
|
-
*
|
79
|
-
* @param instanceType The type of the instance.
|
80
|
-
* @param instanceName The name of the instance.
|
81
|
-
*
|
82
|
-
* @returns The formatted instance id.
|
83
|
-
*/
|
84
|
-
declare function getInstanceId(instanceType: string, instanceName: string): string;
|
85
|
-
/**
|
86
|
-
* Parses the instance id into the instance type and instance name.
|
87
|
-
*
|
88
|
-
* @param instanceId The instance id to parse.
|
89
|
-
*
|
90
|
-
* @returns The instance type and instance name.
|
91
|
-
*/
|
92
|
-
declare function parseInstanceId(instanceId: string): [instanceType: string, instanceName: string];
|
93
|
-
|
94
|
-
type CompositeInstance = {
|
95
|
-
instance: InstanceModel;
|
96
|
-
children: InstanceModel[];
|
97
|
-
};
|
98
|
-
declare function resetEvaluation(): void;
|
99
|
-
declare function getInstances(): readonly InstanceModel[];
|
100
|
-
declare function getCompositeInstances(): readonly CompositeInstance[];
|
101
|
-
|
102
|
-
type ArgumentValueSchema = TString | TNumber | TBoolean | TArray<TString> | TArray<TNumber> | TUnion<TLiteral[]> | TRecordOrObject<TString, TAny> | TArray;
|
103
|
-
type ArgumentValue = Static<ArgumentValueSchema>;
|
104
|
-
/**
|
105
|
-
* The generic metadata of some contract.
|
106
|
-
*/
|
107
|
-
type Meta = {
|
108
|
-
/**
|
109
|
-
* The display name of the entity which can be shown in the UI.
|
110
|
-
*/
|
111
|
-
displayName?: string;
|
112
|
-
/**
|
113
|
-
* The description of the entity which can be shown in the UI.
|
114
|
-
*/
|
115
|
-
description?: string;
|
116
|
-
/**
|
117
|
-
* The hex color of the entity which can be used in the UI.
|
118
|
-
*
|
119
|
-
* @example "#ff0000"
|
120
|
-
*/
|
121
|
-
color?: string;
|
122
|
-
};
|
123
|
-
|
124
|
-
type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
125
|
-
type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
126
|
-
type ListRequiredKeys<T extends Record<string, unknown>> = T extends Record<string, never> ? never : {
|
127
|
-
[K in keyof T]-?: undefined extends T[K] ? never : K;
|
128
|
-
}[keyof T];
|
129
|
-
type PickOptionalRecords<T extends Record<string, Record<string, unknown>>> = {
|
130
|
-
[K in keyof T]: ListRequiredKeys<T[K]> extends never ? K : never;
|
131
|
-
}[keyof T];
|
132
|
-
type PickRequiredRecords<T extends Record<string, Record<string, unknown>>> = {
|
133
|
-
[K in keyof T]: ListRequiredKeys<T[K]> extends never ? never : K;
|
134
|
-
}[keyof T];
|
135
|
-
type OptionalEmptyRecords<T extends Record<string, Record<string, unknown>>> = {
|
136
|
-
[K in PickOptionalRecords<T>]?: T[K];
|
137
|
-
} & {
|
138
|
-
[K in PickRequiredRecords<T>]: T[K];
|
139
|
-
};
|
140
|
-
type PickUndefinedKeys<T extends Record<string, unknown>> = {
|
141
|
-
[K in keyof T]: undefined extends T[K] ? K : never;
|
142
|
-
}[keyof T];
|
143
|
-
type OptionalUndefinedFields<T extends Record<string, unknown>> = {
|
144
|
-
[K in PickUndefinedKeys<T>]?: T[K];
|
145
|
-
} & {
|
146
|
-
[K in Exclude<keyof T, PickUndefinedKeys<T>>]: T[K];
|
147
|
-
};
|
148
|
-
/**
|
149
|
-
* Formats a multiline string and trims the indentation.
|
150
|
-
*
|
151
|
-
* @param str The string to trim.
|
152
|
-
* @returns The trimmed string.
|
153
|
-
*/
|
154
|
-
declare function text(array: TemplateStringsArray, ...values: unknown[]): string;
|
155
|
-
/**
|
156
|
-
* Removes the indentation from a multiline string.
|
157
|
-
*
|
158
|
-
* @param text The text to trim.
|
159
|
-
* @returns The trimmed text.
|
160
|
-
*/
|
161
|
-
declare function trimIndentation(text: string): string;
|
162
|
-
|
163
|
-
/**
|
164
|
-
* The entity is some abstract object which can be passed from one component to another through their inputs and outputs.
|
165
|
-
* Every entity must have a type.
|
166
|
-
* Every component inputs and outputs will reference such types and only entities of the same type can be passed.
|
167
|
-
*/
|
168
|
-
type Entity<TType extends string = string, TEntitySchema extends TSchema = TSchema> = {
|
169
|
-
/**
|
170
|
-
* The static type of the entity.
|
171
|
-
*/
|
172
|
-
type: TType;
|
173
|
-
/**
|
174
|
-
* The JSON schema of the entity value.
|
175
|
-
*/
|
176
|
-
schema: TEntitySchema;
|
177
|
-
/**
|
178
|
-
* The extra metadata of the entity.
|
179
|
-
*/
|
180
|
-
meta: Meta;
|
181
|
-
};
|
182
|
-
type EntityOptions<TType extends string, TSchema extends TAnySchema> = PartialKeys<Entity<TType, TSchema>, "meta">;
|
183
|
-
declare function defineEntity<TType extends string, TSchema extends TAnySchema>(options: EntityOptions<TType, TSchema>): Entity<TType, TSchema>;
|
184
|
-
declare function isEntity(value: unknown): value is Entity;
|
185
|
-
|
186
|
-
type ComponentArgument = {
|
187
|
-
schema: ArgumentValueSchema;
|
188
|
-
required: boolean;
|
189
|
-
meta: Meta;
|
190
|
-
};
|
191
|
-
type ComponentArgumentFullOptions = Meta & {
|
192
|
-
schema: ArgumentValueSchema;
|
193
|
-
required?: boolean;
|
194
|
-
};
|
195
|
-
type ComponentArgumentOptions = ArgumentValueSchema | ComponentArgumentFullOptions;
|
196
|
-
type ComponentArgumentOptionsToSchema<T extends ComponentArgumentOptions> = T extends TSchema ? T : T["required"] extends false ? TOptional<T["schema"]> : T["schema"];
|
197
|
-
type ComponentArgumentMapToValue<T extends Record<string, ComponentArgumentOptions>> = {
|
198
|
-
[K in keyof T]: Static<ComponentArgumentOptionsToSchema<T[K]>>;
|
199
|
-
};
|
200
|
-
type ComponentInput = {
|
201
|
-
type: string;
|
202
|
-
required: boolean;
|
203
|
-
multiple: boolean;
|
204
|
-
meta: Meta;
|
205
|
-
};
|
206
|
-
type ComponentInputFullOptions = Meta & {
|
207
|
-
entity: Entity;
|
208
|
-
required?: boolean;
|
209
|
-
multiple?: boolean;
|
210
|
-
};
|
211
|
-
type ComponentInputOptions = Entity | ComponentInputFullOptions;
|
212
|
-
type ComponentInputOptionsToOutputRef<T extends ComponentInputOptions> = T extends Entity ? InstanceInput<T["type"]> : T extends ComponentInputFullOptions ? T["required"] extends false ? T["multiple"] extends true ? InstanceInput<T["entity"]["type"]>[] | undefined : InstanceInput<T["entity"]["type"]> | undefined : T["multiple"] extends true ? InstanceInput<T["entity"]["type"]>[] : InstanceInput<T["entity"]["type"]> : never;
|
213
|
-
type ComponentInputSpec = [entity: Entity, required: boolean, multiple: boolean];
|
214
|
-
type ComponentInputOptionsToSpec<T extends ComponentInputOptions> = T extends Entity ? [T, true, false] : T extends ComponentInputFullOptions ? T["required"] extends false ? T["multiple"] extends true ? [T["entity"], false, true] : [T["entity"], false, false] : T["multiple"] extends true ? [T["entity"], true, true] : [T["entity"], true, false] : never;
|
215
|
-
type ComponentInputOptionsMapToSpecMap<T extends Record<string, ComponentInputOptions>> = T extends Record<string, never> ? Record<string, never> : {
|
216
|
-
[K in keyof T]: ComponentInputOptionsToSpec<T[K]>;
|
217
|
-
};
|
218
|
-
type ComponentInputMapToValue<T extends Record<string, ComponentInputOptions>> = OptionalUndefinedFields<{
|
219
|
-
[K in keyof T]: ComponentInputOptionsToOutputRef<T[K]>;
|
220
|
-
}>;
|
221
|
-
type ComponentInputMapToReturnType<T extends Record<string, ComponentInputOptions>> = T extends Record<string, never> ? void : ComponentInputMapToValue<T>;
|
222
|
-
type ComponentParams<TArgs extends Record<string, ComponentArgumentOptions>, TInputs extends Record<string, ComponentInputOptions>> = {
|
223
|
-
id: string;
|
224
|
-
name: string;
|
225
|
-
args: ComponentArgumentMapToValue<TArgs>;
|
226
|
-
inputs: ComponentInputMapToValue<TInputs>;
|
227
|
-
};
|
228
|
-
type InputComponentParams<TArgs extends Record<string, ArgumentValue>, TInputs extends Record<string, unknown>> = {
|
229
|
-
name: string;
|
230
|
-
} & OptionalEmptyRecords<{
|
231
|
-
args: TArgs;
|
232
|
-
inputs: TInputs;
|
233
|
-
}>;
|
234
|
-
type ComponentOptions<TArgs extends Record<string, ComponentArgumentOptions>, TInputs extends Record<string, ComponentInputOptions>, TOutputs extends Record<string, ComponentInputOptions>> = {
|
235
|
-
type: string;
|
236
|
-
meta?: ComponentMeta;
|
237
|
-
args?: TArgs;
|
238
|
-
inputs?: TInputs;
|
239
|
-
outputs?: TOutputs;
|
240
|
-
create: (params: ComponentParams<TArgs, TInputs>) => ComponentInputMapToReturnType<TOutputs>;
|
241
|
-
};
|
242
|
-
type ComponentMeta = Meta & {
|
243
|
-
primaryIcon?: string;
|
244
|
-
primaryIconColor?: string;
|
245
|
-
secondaryIcon?: string;
|
246
|
-
secondaryIconColor?: string;
|
247
|
-
category?: string;
|
248
|
-
defaultNamePrefix?: string;
|
249
|
-
};
|
250
|
-
type ComponentModel = {
|
251
|
-
/**
|
252
|
-
* The type of the component.
|
253
|
-
*/
|
254
|
-
type: string;
|
255
|
-
/**
|
256
|
-
* The record of the argument schemas.
|
257
|
-
*/
|
258
|
-
args: Record<string, ComponentArgument>;
|
259
|
-
/**
|
260
|
-
* The record of the input schemas.
|
261
|
-
*/
|
262
|
-
inputs: Record<string, ComponentInput>;
|
263
|
-
/**
|
264
|
-
* The record of the output schemas.
|
265
|
-
*/
|
266
|
-
outputs: Record<string, ComponentInput>;
|
267
|
-
/**
|
268
|
-
* The extra metadata of the component.
|
269
|
-
*/
|
270
|
-
meta: ComponentMeta;
|
271
|
-
};
|
272
|
-
type InputSpecToOutputRef<T extends ComponentInputSpec> = T[1] extends true ? T[2] extends true ? InstanceInput<T[0]["type"]>[] : InstanceInput<T[0]["type"]> : T[2] extends true ? InstanceInput<T[0]["type"]>[] | undefined : InstanceInput<T[0]["type"]> | undefined;
|
273
|
-
type OutputRefMap<TInputs extends Record<string, ComponentInputSpec>> = TInputs extends Record<string, [string, never, never]> ? Record<string, never> : {
|
274
|
-
[K in keyof TInputs]: InputSpecToOutputRef<TInputs[K]>;
|
275
|
-
};
|
276
|
-
type Component<TArgs extends Record<string, ArgumentValue> = Record<string, never>, TInputs extends Record<string, ComponentInputSpec> = Record<string, never>, TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>> = {
|
277
|
-
/**
|
278
|
-
* The non-generic model of the component.
|
279
|
-
*/
|
280
|
-
model: ComponentModel;
|
281
|
-
/**
|
282
|
-
* The entities used in the inputs or outputs of the component.
|
283
|
-
*/
|
284
|
-
entities: Map<string, Entity>;
|
285
|
-
/**
|
286
|
-
* Creates the component at the evaluation time.
|
287
|
-
*/
|
288
|
-
(context: InputComponentParams<TArgs, OutputRefMap<TInputs>>): OutputRefMap<TOutputs>;
|
289
|
-
};
|
290
|
-
type ArgumentOptionsMapToStatic<T extends Record<string, ComponentArgumentOptions>> = T extends Record<string, never> ? Record<string, never> : Static<TObject<{
|
291
|
-
[K in keyof T]: ComponentArgumentOptionsToSchema<T[K]>;
|
292
|
-
}>>;
|
293
|
-
declare function defineComponent<TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>, TInputs extends Record<string, ComponentInputOptions> = Record<string, never>, TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>>(options: ComponentOptions<TArgs, TInputs, TOutputs>): Component<ArgumentOptionsMapToStatic<TArgs>, ComponentInputOptionsMapToSpecMap<TInputs>, ComponentInputOptionsMapToSpecMap<TOutputs>>;
|
294
|
-
declare function isComponent(value: unknown): value is Component;
|
295
|
-
|
296
|
-
type UnitOptions<TArgs extends Record<string, ComponentArgumentOptions>, TInputs extends Record<string, ComponentInputOptions>, TOutputs extends Record<string, ComponentInputOptions>, TSecrets extends Record<string, ComponentArgumentOptions>> = Omit<ComponentOptions<TArgs, TInputs, TOutputs>, "create"> & {
|
297
|
-
source?: UnitSource;
|
298
|
-
secrets?: TSecrets;
|
299
|
-
};
|
300
|
-
type UnitSource = {
|
301
|
-
type: "npm";
|
302
|
-
package: string;
|
303
|
-
path?: string;
|
304
|
-
version?: string;
|
305
|
-
} | {
|
306
|
-
type: "local";
|
307
|
-
path?: string;
|
308
|
-
};
|
309
|
-
type UnitModel = ComponentModel & {
|
310
|
-
/**
|
311
|
-
* The source of the unit.
|
312
|
-
*/
|
313
|
-
source?: UnitSource;
|
314
|
-
/**
|
315
|
-
* The record of the secret argument schemas.
|
316
|
-
*/
|
317
|
-
secrets: Record<string, ComponentArgument>;
|
318
|
-
};
|
319
|
-
type Unit<TArgs extends Record<string, ArgumentValue> = Record<string, never>, TInputs extends Record<string, ComponentInputSpec> = Record<string, never>, TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>, TSecrets extends Record<string, ArgumentValue> = Record<string, never>> = Component<TArgs, TInputs, TOutputs> & {
|
320
|
-
__secrets: TSecrets;
|
321
|
-
model: UnitModel;
|
322
|
-
};
|
323
|
-
declare function isUnitModel(model: ComponentModel): model is UnitModel;
|
324
|
-
declare function defineUnit<TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>, TInputs extends Record<string, ComponentInputOptions> = Record<string, never>, TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>, TSecrets extends Record<string, ComponentArgumentOptions> = Record<string, never>>(options: UnitOptions<TArgs, TInputs, TOutputs, TSecrets>): Unit<ArgumentOptionsMapToStatic<TArgs>, ComponentInputOptionsMapToSpecMap<TInputs>, ComponentInputOptionsMapToSpecMap<TOutputs>, ArgumentOptionsMapToStatic<TSecrets>>;
|
325
|
-
|
326
|
-
export { type ArgumentValue, type ArgumentValueSchema, type Component, type ComponentArgument, type ComponentInput, type ComponentInputSpec, type ComponentMeta, type ComponentModel, type CompositeInstance, type Entity, type HubInput, type InstanceInput, type InstanceModel, type PartialKeys, type Position, type RequiredKeys, type Unit, type UnitModel, type UnitSource, defineComponent, defineEntity, defineUnit, getCompositeInstances, getInstanceId, getInstances, isComponent, isEntity, isUnitModel, parseInstanceId, resetEvaluation, text, trimIndentation };
|