@highstate/backend 0.7.1 → 0.7.3
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.mjs → index.js} +1255 -916
- package/dist/library/source-resolution-worker.js +55 -0
- package/dist/library/worker/main.js +207 -0
- package/dist/{terminal-CqIsctlZ.mjs → library-BW5oPM7V.js} +210 -87
- package/dist/shared/index.js +6 -0
- package/dist/utils-ByadNcv4.js +102 -0
- package/package.json +14 -18
- package/src/common/index.ts +3 -0
- package/src/common/local.ts +22 -0
- package/src/common/pulumi.ts +230 -0
- package/src/common/utils.ts +137 -0
- package/src/config.ts +40 -0
- package/src/index.ts +6 -0
- package/src/library/abstractions.ts +83 -0
- package/src/library/factory.ts +20 -0
- package/src/library/index.ts +2 -0
- package/src/library/local.ts +404 -0
- package/src/library/source-resolution-worker.ts +96 -0
- package/src/library/worker/evaluator.ts +119 -0
- package/src/library/worker/loader.ts +93 -0
- package/src/library/worker/main.ts +82 -0
- package/src/library/worker/protocol.ts +38 -0
- package/src/orchestrator/index.ts +1 -0
- package/src/orchestrator/manager.ts +165 -0
- package/src/orchestrator/operation-workset.ts +483 -0
- package/src/orchestrator/operation.ts +647 -0
- package/src/preferences/shared.ts +1 -0
- package/src/project/abstractions.ts +89 -0
- package/src/project/factory.ts +11 -0
- package/src/project/index.ts +4 -0
- package/src/project/local.ts +412 -0
- package/src/project/lock.ts +39 -0
- package/src/project/manager.ts +374 -0
- package/src/runner/abstractions.ts +146 -0
- package/src/runner/factory.ts +22 -0
- package/src/runner/index.ts +2 -0
- package/src/runner/local.ts +698 -0
- package/src/secret/abstractions.ts +59 -0
- package/src/secret/factory.ts +22 -0
- package/src/secret/index.ts +2 -0
- package/src/secret/local.ts +152 -0
- package/src/services.ts +133 -0
- package/src/shared/index.ts +10 -0
- package/src/shared/library.ts +77 -0
- package/src/shared/operation.ts +85 -0
- package/src/shared/project.ts +62 -0
- package/src/shared/resolvers/graph-resolver.ts +111 -0
- package/src/shared/resolvers/input-hash.ts +77 -0
- package/src/shared/resolvers/input.ts +314 -0
- package/src/shared/resolvers/registry.ts +10 -0
- package/src/shared/resolvers/validation.ts +94 -0
- package/src/shared/state.ts +262 -0
- package/src/shared/terminal.ts +13 -0
- package/src/state/abstractions.ts +222 -0
- package/src/state/factory.ts +22 -0
- package/src/state/index.ts +3 -0
- package/src/state/local.ts +605 -0
- package/src/state/manager.ts +33 -0
- package/src/terminal/docker.ts +90 -0
- package/src/terminal/factory.ts +20 -0
- package/src/terminal/index.ts +3 -0
- package/src/terminal/manager.ts +330 -0
- package/src/terminal/run.sh.ts +37 -0
- package/src/terminal/shared.ts +50 -0
- package/src/workspace/abstractions.ts +41 -0
- package/src/workspace/factory.ts +14 -0
- package/src/workspace/index.ts +2 -0
- package/src/workspace/local.ts +54 -0
- package/dist/index.d.ts +0 -760
- package/dist/library/worker/main.mjs +0 -164
- package/dist/runner/source-resolution-worker.mjs +0 -22
- package/dist/shared/index.d.ts +0 -85
- package/dist/shared/index.mjs +0 -54
- package/dist/terminal-Cm2WqcyB.d.ts +0 -1589
@@ -1,164 +0,0 @@
|
|
1
|
-
import { workerData, parentPort } from 'node:worker_threads';
|
2
|
-
import { createJiti } from 'jiti';
|
3
|
-
import { pino } from 'pino';
|
4
|
-
import { mapValues } from 'remeda';
|
5
|
-
import { isComponent, isEntity, resetEvaluation, getCompositeInstances, getInstances } from '@highstate/contract';
|
6
|
-
|
7
|
-
async function loadLibrary(jiti, logger, modulePaths) {
|
8
|
-
const modules = {};
|
9
|
-
for (const modulePath of modulePaths) {
|
10
|
-
try {
|
11
|
-
logger.debug("loading module", { modulePath });
|
12
|
-
modules[modulePath] = await jiti.import(modulePath);
|
13
|
-
logger.debug("module loaded", { modulePath });
|
14
|
-
} catch (error) {
|
15
|
-
logger.error("module load failed", { modulePath, error });
|
16
|
-
}
|
17
|
-
}
|
18
|
-
const components = {};
|
19
|
-
const entities = {};
|
20
|
-
_loadLibrary(modules, components, entities);
|
21
|
-
logger.info("library loaded", {
|
22
|
-
componentCount: Object.keys(components).length,
|
23
|
-
entityCount: Object.keys(entities).length
|
24
|
-
});
|
25
|
-
logger.trace("library content", { components, entities });
|
26
|
-
return { components, entities };
|
27
|
-
}
|
28
|
-
function _loadLibrary(value, components, entities) {
|
29
|
-
if (isComponent(value)) {
|
30
|
-
components[value.model.type] = value;
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
if (isEntity(value)) {
|
34
|
-
entities[value.type] = value;
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
if (typeof value !== "object" || value === null) {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
for (const key in value) {
|
41
|
-
_loadLibrary(value[key], components, entities);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
async function evaluateModules(jiti, logger, modulePaths) {
|
46
|
-
resetEvaluation();
|
47
|
-
for (const modulePath of modulePaths) {
|
48
|
-
try {
|
49
|
-
logger.debug("loading module", { modulePath });
|
50
|
-
await jiti.import(modulePath);
|
51
|
-
logger.debug("module loaded", { modulePath });
|
52
|
-
} catch (error) {
|
53
|
-
logger.error("module load failed", { modulePath, error });
|
54
|
-
}
|
55
|
-
}
|
56
|
-
return getInstances();
|
57
|
-
}
|
58
|
-
function evaluateInstances(logger, library, allInstances, instanceIds) {
|
59
|
-
resetEvaluation();
|
60
|
-
const allInstancesMap = new Map(allInstances.map((instance) => [instance.id, instance]));
|
61
|
-
const instanceOutputs = /* @__PURE__ */ new Map();
|
62
|
-
for (const instanceId of instanceIds ?? allInstancesMap.keys()) {
|
63
|
-
logger.debug("evaluating top-level instance", { instanceId });
|
64
|
-
evaluateInstance(instanceId);
|
65
|
-
}
|
66
|
-
return getCompositeInstances();
|
67
|
-
function evaluateInstance(instanceId) {
|
68
|
-
let outputs = instanceOutputs.get(instanceId);
|
69
|
-
if (!outputs) {
|
70
|
-
outputs = _evaluateInstance(instanceId);
|
71
|
-
instanceOutputs.set(instanceId, outputs);
|
72
|
-
}
|
73
|
-
return outputs;
|
74
|
-
}
|
75
|
-
function _evaluateInstance(instanceId) {
|
76
|
-
const inputs = {};
|
77
|
-
const instance = allInstancesMap.get(instanceId);
|
78
|
-
logger.info("evaluating instance", { instanceId });
|
79
|
-
if (!instance) {
|
80
|
-
throw new Error(`Instance not found: ${instanceId}`);
|
81
|
-
}
|
82
|
-
for (const [inputName, input] of Object.entries(instance.inputs ?? {})) {
|
83
|
-
inputs[inputName] = input.map((input2) => {
|
84
|
-
const evaluated = evaluateInstance(input2.instanceId);
|
85
|
-
return evaluated[input2.output];
|
86
|
-
});
|
87
|
-
}
|
88
|
-
const component = library.components[instance.type];
|
89
|
-
if (!component) {
|
90
|
-
throw new Error(`Component not found: ${instance.type}, required by instance: ${instanceId}`);
|
91
|
-
}
|
92
|
-
return component({
|
93
|
-
name: instance.name,
|
94
|
-
args: instance.args,
|
95
|
-
inputs
|
96
|
-
});
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
const data = workerData;
|
101
|
-
const logger = pino({ name: "library-worker", level: data.logLevel });
|
102
|
-
let jiti;
|
103
|
-
let library;
|
104
|
-
try {
|
105
|
-
logger.info("worker started");
|
106
|
-
logger.trace("worker data", data);
|
107
|
-
jiti = createJiti(import.meta.filename);
|
108
|
-
logger.debug("jiti created", { filename: import.meta.filename });
|
109
|
-
library = await loadLibrary(jiti, logger, data.modulePaths);
|
110
|
-
parentPort.postMessage({
|
111
|
-
type: "library",
|
112
|
-
library: {
|
113
|
-
components: mapValues(library.components, (component) => component.model),
|
114
|
-
entities: library.entities
|
115
|
-
}
|
116
|
-
});
|
117
|
-
logger.info("library loaded and sent");
|
118
|
-
} catch (error) {
|
119
|
-
logger.error("failed to load library", error);
|
120
|
-
parentPort.postMessage({
|
121
|
-
type: "error",
|
122
|
-
error: error instanceof Error ? error.stack ?? error.message : error
|
123
|
-
});
|
124
|
-
}
|
125
|
-
parentPort.on("message", async (message) => {
|
126
|
-
try {
|
127
|
-
const messageData = message;
|
128
|
-
if (messageData.type === "evaluate-composite-instances") {
|
129
|
-
logger.info("received evaluation request", {
|
130
|
-
totalInstanceCount: messageData.allInstances.length,
|
131
|
-
requestedInstanceCount: messageData.instanceIds?.length ?? -1
|
132
|
-
});
|
133
|
-
logger.trace("evaluation request data", messageData);
|
134
|
-
const instances = evaluateInstances(
|
135
|
-
logger,
|
136
|
-
library,
|
137
|
-
messageData.allInstances,
|
138
|
-
messageData.instanceIds
|
139
|
-
);
|
140
|
-
logger.info("evaluation completed", { instanceCount: instances.length });
|
141
|
-
parentPort.postMessage({
|
142
|
-
type: "instances",
|
143
|
-
instances
|
144
|
-
});
|
145
|
-
} else {
|
146
|
-
logger.info("received module evaluation request", {
|
147
|
-
moduleCount: messageData.modulePaths.length
|
148
|
-
});
|
149
|
-
logger.trace("module evaluation request data", messageData);
|
150
|
-
const instances = await evaluateModules(jiti, logger, messageData.modulePaths);
|
151
|
-
logger.info("module evaluation completed", { instanceCount: instances.length });
|
152
|
-
parentPort.postMessage({
|
153
|
-
type: "instances",
|
154
|
-
instances
|
155
|
-
});
|
156
|
-
}
|
157
|
-
} catch (error) {
|
158
|
-
logger.error("failed to evaluate", error);
|
159
|
-
parentPort.postMessage({
|
160
|
-
type: "error",
|
161
|
-
error: error instanceof Error ? error.stack ?? error.message : error
|
162
|
-
});
|
163
|
-
}
|
164
|
-
});
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { workerData, parentPort } from 'node:worker_threads';
|
2
|
-
import { fileURLToPath } from 'node:url';
|
3
|
-
import { dirname } from 'node:path';
|
4
|
-
import pino from 'pino';
|
5
|
-
import { resolve } from 'import-meta-resolve';
|
6
|
-
import { readPackageJSON } from 'pkg-types';
|
7
|
-
|
8
|
-
const { source, logLevel } = workerData;
|
9
|
-
const logger = pino({ name: "source-resolution-worker", level: logLevel ?? "silent" });
|
10
|
-
const fullPath = source.path ? `${source.package}/${source.path}` : source.package;
|
11
|
-
const url = resolve(fullPath, import.meta.url);
|
12
|
-
const path = fileURLToPath(url);
|
13
|
-
const projectPath = dirname(path);
|
14
|
-
logger.info("source path resolved", { url, path, projectPath });
|
15
|
-
const packageJson = await readPackageJSON(projectPath);
|
16
|
-
const allowedDependencies = Object.keys(packageJson.peerDependencies ?? {});
|
17
|
-
logger.info("package.json read", { packageJson, allowedDependencies });
|
18
|
-
parentPort.postMessage({
|
19
|
-
type: "result",
|
20
|
-
projectPath,
|
21
|
-
allowedDependencies
|
22
|
-
});
|
package/dist/shared/index.d.ts
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
import { H as HubModel, b as InstanceState } from '../terminal-Cm2WqcyB.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, $ as OperationOptions, _ as OperationStatus, Z as OperationType, P as ProjectOperation, g as ProjectOperationRequest, T as TerminalSession, O as applyPartialInstanceState, R as buildDependentInstanceStateMap, l as compositeInstanceSchema, N as createInstanceState, Q as createInstanceStateFrontendPatch, S as getAllDependentInstanceIds, 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, a0 as isFinalOperationStatus, W as operationOptionsSchema, V as operationStatusSchema, U as operationTypeSchema, p as positionSchema, X as projectOperationRequestSchema, Y as projectOperationSchema, a1 as terminalSessionSchema } from '../terminal-Cm2WqcyB.js';
|
3
|
-
import { Logger } from 'pino';
|
4
|
-
import { InstanceModel, ComponentModel, InstanceInput } from '@highstate/contract';
|
5
|
-
import 'zod';
|
6
|
-
|
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;
|
16
|
-
}
|
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[]);
|
21
|
-
}
|
22
|
-
declare function createDefaultGraphResolverBackend<TOutput>(): GraphResolverBackend<TOutput>;
|
23
|
-
declare function defineGraphResolver<TInput, TOutput>(options: GraphResolverOptions<TInput, TOutput>): GraphResolverFactory<TInput, TOutput>;
|
24
|
-
|
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
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import { q as defineGraphResolver } from '../terminal-CqIsctlZ.mjs';
|
2
|
-
export { M as CircularDependencyError, o as applyPartialInstanceState, G as buildDependentInstanceStateMap, k as compositeInstanceSchema, N as createDefaultGraphResolverBackend, a as createInputHashResolver, c as createInputResolver, b as createInstanceState, n as createInstanceStateFrontendPatch, H as getAllDependentInstanceIds, R as getMatchedInjectionInstanceInputs, O as getResolvedHubInputs, Q as getResolvedInjectionInstanceInputs, P 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, K as operationOptionsSchema, J as operationStatusSchema, I as operationTypeSchema, r as positionSchema, L as projectOperationRequestSchema, p as projectOperationSchema, t as terminalSessionSchema } from '../terminal-CqIsctlZ.mjs';
|
3
|
-
import { Ajv } from 'ajv';
|
4
|
-
import 'zod';
|
5
|
-
import 'remeda';
|
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 };
|