@highstate/backend 0.4.4 → 0.4.6
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.d.ts +93 -47
- package/dist/index.mjs +907 -393
- package/dist/library/worker/main.mjs +3 -8
- package/dist/shared/index.d.ts +80 -16
- package/dist/shared/index.mjs +52 -2
- package/dist/terminal-C1HuyJ6e.mjs +512 -0
- package/dist/terminal-_gg6j6_K.d.ts +1417 -0
- package/package.json +6 -5
- package/dist/input-hash-C8HEDMjz.mjs +0 -292
- package/dist/operation-8k4Tv4dw.d.ts +0 -841
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { workerData, parentPort } from 'node:worker_threads';
|
2
2
|
import { createJiti } from 'jiti';
|
3
3
|
import { pino } from 'pino';
|
4
4
|
import { mapValues } from 'remeda';
|
5
|
-
import { isComponent, isEntity, resetEvaluation,
|
5
|
+
import { isComponent, isEntity, resetEvaluation, getCompositeInstances, getInstances } from '@highstate/contract';
|
6
6
|
|
7
7
|
async function loadLibrary(jiti, logger, modulePaths) {
|
8
8
|
const modules = {};
|
@@ -79,12 +79,7 @@ function evaluateInstances(logger, library, allInstances, instanceIds) {
|
|
79
79
|
if (!instance) {
|
80
80
|
throw new Error(`Instance not found: ${instanceId}`);
|
81
81
|
}
|
82
|
-
for (const [inputName, input] of Object.entries(instance.inputs)) {
|
83
|
-
if (!Array.isArray(input)) {
|
84
|
-
const outputs = evaluateInstance(input.instanceId);
|
85
|
-
inputs[inputName] = outputs[input.output];
|
86
|
-
continue;
|
87
|
-
}
|
82
|
+
for (const [inputName, input] of Object.entries(instance.inputs ?? {})) {
|
88
83
|
inputs[inputName] = input.map((input2) => {
|
89
84
|
const evaluated = evaluateInstance(input2.instanceId);
|
90
85
|
return evaluated[input2.output];
|
package/dist/shared/index.d.ts
CHANGED
@@ -1,21 +1,85 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { H as HubModel, b as InstanceState } from '../terminal-_gg6j6_K.js';
|
2
|
+
export { C as CompositeInstance, a as HubModelPatch, J as InstanceFileMeta, I as InstanceModelPatch, e as InstancePageBlock, G as InstancePageMeta, d as InstanceStatePatch, c as InstanceStatus, F as InstanceStatusField, f as InstanceTerminal, L as InstanceTrigger, M as InstanceTriggerInvocation, K as InstanceTriggerSpec, X as OperationStatus, W as OperationType, P as ProjectOperation, g as ProjectOperationRequest, T as TerminalSession, O as applyPartialInstanceState, l as compositeInstanceSchema, N as createInstanceState, Q as createInstanceStateFrontendPatch, h as hubInstanceInputSchema, m as hubModelPatchSchema, n as hubModelSchema, r as instanceFileMetaSchema, s as instanceFileSchema, i as instanceInputSchema, j as instanceModelPatchSchema, k as instanceModelSchema, t as instancePageBlockSchema, u as instancePageMetaSchema, v as instancePageSchema, E as instanceStatePatchSchema, D as instanceStateSchema, q as instanceStatusFieldSchema, o as instanceStatusSchema, x as instanceTerminalFileSchema, w as instanceTerminalMetaSchema, y as instanceTerminalSchema, B as instanceTriggerInvocationSchema, A as instanceTriggerSchema, z as instanceTriggerSpecSchema, Y as isFinalOperationStatus, S as operationStatusSchema, R as operationTypeSchema, p as positionSchema, V as projectOperationRequestSchema, U as projectOperationSchema, Z as terminalSessionSchema } from '../terminal-_gg6j6_K.js';
|
3
|
+
import { Logger } from 'pino';
|
4
|
+
import { InstanceModel, ComponentModel, InstanceInput } from '@highstate/contract';
|
3
5
|
import 'zod';
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
type GraphResolverOptions<TNode, TOutput> = {
|
8
|
+
getNodeId(input: TNode): string;
|
9
|
+
getNodeDependencies(input: TNode): string[];
|
10
|
+
process(node: TNode, dependencies: Map<string, TOutput>, logger: Logger): TOutput | Promise<TOutput>;
|
11
|
+
};
|
12
|
+
interface GraphResolverBackend<TOutput> {
|
13
|
+
promiseCache: Map<string, Promise<TOutput>>;
|
14
|
+
setOutput(id: string, value: TOutput): void;
|
15
|
+
setDependencies(id: string, dependencies: string[]): void;
|
9
16
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
constructor(instances: Map<string, BaseInstanceModel>);
|
15
|
-
reset(instanceId: string): void;
|
16
|
-
calculate(instance: BaseInstanceModel): Promise<string>;
|
17
|
-
calculateFull(instance: BaseInstanceModel): Promise<CacheEntry>;
|
18
|
-
private _calculate;
|
17
|
+
type GraphResolverFactory<TNode, TOutput> = (nodes: ReadonlyMap<string, TNode>, logger: Logger, backend?: GraphResolverBackend<TOutput>) => GraphResolver<TOutput>;
|
18
|
+
type GraphResolver<TOutput> = (id: string) => Promise<TOutput>;
|
19
|
+
declare class CircularDependencyError extends Error {
|
20
|
+
constructor(path: string[]);
|
19
21
|
}
|
22
|
+
declare function createDefaultGraphResolverBackend<TOutput>(): GraphResolverBackend<TOutput>;
|
23
|
+
declare function defineGraphResolver<TInput, TOutput>(options: GraphResolverOptions<TInput, TOutput>): GraphResolverFactory<TInput, TOutput>;
|
20
24
|
|
21
|
-
|
25
|
+
type InputResolverNode = {
|
26
|
+
kind: "instance";
|
27
|
+
instance: InstanceModel;
|
28
|
+
component: ComponentModel;
|
29
|
+
} | {
|
30
|
+
kind: "hub";
|
31
|
+
hub: HubModel;
|
32
|
+
};
|
33
|
+
type ResolvedInstanceInput = {
|
34
|
+
input: InstanceInput;
|
35
|
+
type: string;
|
36
|
+
};
|
37
|
+
type InputResolverOutput = {
|
38
|
+
kind: "instance";
|
39
|
+
component: ComponentModel;
|
40
|
+
resolvedInputs: Record<string, ResolvedInstanceInput[]>;
|
41
|
+
resolvedInjectionInputs: ResolvedInstanceInput[];
|
42
|
+
matchedInjectionInputs: ResolvedInstanceInput[];
|
43
|
+
} | {
|
44
|
+
kind: "hub";
|
45
|
+
resolvedInputs: ResolvedInstanceInput[];
|
46
|
+
};
|
47
|
+
/**
|
48
|
+
* Resolves the all recursive instance and hub inputs based on its direct inputs and injected inputs.
|
49
|
+
*/
|
50
|
+
declare const createInputResolver: GraphResolverFactory<InputResolverNode, InputResolverOutput>;
|
51
|
+
declare function getResolvedHubInputs(output: InputResolverOutput): ResolvedInstanceInput[];
|
52
|
+
declare function getResolvedInstanceInputs(output: InputResolverOutput): Record<string, ResolvedInstanceInput[]>;
|
53
|
+
declare function getResolvedInjectionInstanceInputs(output: InputResolverOutput): ResolvedInstanceInput[];
|
54
|
+
declare function getMatchedInjectionInstanceInputs(output: InputResolverOutput): ResolvedInstanceInput[];
|
55
|
+
|
56
|
+
type InputHashNode = {
|
57
|
+
instance: InstanceModel;
|
58
|
+
resolvedInputs: Record<string, ResolvedInstanceInput[]>;
|
59
|
+
state: InstanceState | undefined;
|
60
|
+
sourceHash: string | undefined;
|
61
|
+
};
|
62
|
+
/**
|
63
|
+
* Resolves the hash of the instance based on its args, resolved input hashes, source hash, and the output hash.
|
64
|
+
*/
|
65
|
+
declare const createInputHashResolver: GraphResolverFactory<InputHashNode, string>;
|
66
|
+
|
67
|
+
type ValidationNode = {
|
68
|
+
instance: InstanceModel;
|
69
|
+
component: ComponentModel;
|
70
|
+
resolvedInputs: Record<string, ResolvedInstanceInput[]>;
|
71
|
+
};
|
72
|
+
type InstanceValidationResult = {
|
73
|
+
status: "ok";
|
74
|
+
} | {
|
75
|
+
status: "invalid-args";
|
76
|
+
errorsText: string;
|
77
|
+
} | {
|
78
|
+
status: "invalid-inputs" | "missing-inputs";
|
79
|
+
};
|
80
|
+
/**
|
81
|
+
* Validates the instance based on its arguments and inputs.
|
82
|
+
*/
|
83
|
+
declare const createInstanceValidationResolver: GraphResolverFactory<ValidationNode, InstanceValidationResult>;
|
84
|
+
|
85
|
+
export { CircularDependencyError, type GraphResolver, type GraphResolverBackend, type GraphResolverFactory, type GraphResolverOptions, HubModel, type InputHashNode, type InputResolverNode, type InputResolverOutput, InstanceState, type InstanceValidationResult, type ResolvedInstanceInput, type ValidationNode, createDefaultGraphResolverBackend, createInputHashResolver, createInputResolver, createInstanceValidationResolver, defineGraphResolver, getMatchedInjectionInstanceInputs, getResolvedHubInputs, getResolvedInjectionInstanceInputs, getResolvedInstanceInputs };
|
package/dist/shared/index.mjs
CHANGED
@@ -1,4 +1,54 @@
|
|
1
|
-
|
1
|
+
import { q as defineGraphResolver } from '../terminal-C1HuyJ6e.mjs';
|
2
|
+
export { J as CircularDependencyError, n as applyPartialInstanceState, k as compositeInstanceSchema, K as createDefaultGraphResolverBackend, a as createInputHashResolver, c as createInputResolver, b as createInstanceState, o as createInstanceStateFrontendPatch, O as getMatchedInjectionInstanceInputs, L as getResolvedHubInputs, N as getResolvedInjectionInstanceInputs, M as getResolvedInstanceInputs, u as hubInstanceInputSchema, w as hubModelPatchSchema, h as hubModelSchema, y as instanceFileMetaSchema, f as instanceFileSchema, s as instanceInputSchema, v as instanceModelPatchSchema, i as instanceModelSchema, z as instancePageBlockSchema, A as instancePageMetaSchema, e as instancePageSchema, F as instanceStatePatchSchema, l as instanceStateSchema, g as instanceStatusFieldSchema, x as instanceStatusSchema, C as instanceTerminalFileSchema, B as instanceTerminalMetaSchema, d as instanceTerminalSchema, E as instanceTriggerInvocationSchema, j as instanceTriggerSchema, D as instanceTriggerSpecSchema, m as isFinalOperationStatus, H as operationStatusSchema, G as operationTypeSchema, r as positionSchema, I as projectOperationRequestSchema, p as projectOperationSchema, t as terminalSessionSchema } from '../terminal-C1HuyJ6e.mjs';
|
3
|
+
import { Ajv } from 'ajv';
|
2
4
|
import 'zod';
|
3
|
-
import '
|
5
|
+
import 'remeda';
|
4
6
|
import 'crypto-hash';
|
7
|
+
|
8
|
+
const createInstanceValidationResolver = defineGraphResolver({
|
9
|
+
getNodeId: (node) => node.instance.id,
|
10
|
+
getNodeDependencies({ resolvedInputs }) {
|
11
|
+
const dependencies = [];
|
12
|
+
for (const inputs of Object.values(resolvedInputs)) {
|
13
|
+
for (const input of inputs) {
|
14
|
+
dependencies.push(input.input.instanceId);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return dependencies;
|
18
|
+
},
|
19
|
+
process({ instance, component, resolvedInputs }, dependencies, logger) {
|
20
|
+
const ajv = new Ajv();
|
21
|
+
logger.debug({ instanceId: instance.id }, "validating instance");
|
22
|
+
for (const [name, argument] of Object.entries(component.args)) {
|
23
|
+
if (!argument.required && !instance.args?.[name]) {
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
if (!ajv.validate(argument.schema, instance.args?.[name])) {
|
27
|
+
logger.debug({ instanceId: instance.id, argumentName: name }, "invalid argument");
|
28
|
+
return {
|
29
|
+
status: "invalid-args",
|
30
|
+
errorsText: ajv.errorsText()
|
31
|
+
};
|
32
|
+
}
|
33
|
+
}
|
34
|
+
for (const inputs of Object.values(resolvedInputs)) {
|
35
|
+
for (const input of inputs) {
|
36
|
+
const inputInstance = dependencies.get(input.input.instanceId);
|
37
|
+
if (inputInstance?.status !== "ok") {
|
38
|
+
return { status: "invalid-inputs" };
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
for (const [name, input] of Object.entries(component.inputs)) {
|
43
|
+
if (!input.required || input.multiple) {
|
44
|
+
continue;
|
45
|
+
}
|
46
|
+
if (!resolvedInputs[name] || !resolvedInputs[name].length) {
|
47
|
+
return { status: "missing-inputs" };
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return { status: "ok" };
|
51
|
+
}
|
52
|
+
});
|
53
|
+
|
54
|
+
export { createInstanceValidationResolver, defineGraphResolver };
|