@highstate/backend 0.9.15 → 0.9.16
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/chunk-RCB4AFGD.js +159 -0
- package/dist/chunk-RCB4AFGD.js.map +1 -0
- package/dist/chunk-WHALQHEZ.js +2017 -0
- package/dist/chunk-WHALQHEZ.js.map +1 -0
- package/dist/highstate.manifest.json +3 -3
- package/dist/index.js +6158 -2178
- package/dist/index.js.map +1 -1
- package/dist/library/worker/main.js +47 -155
- package/dist/library/worker/main.js.map +1 -1
- package/dist/shared/index.js +159 -41
- package/package.json +25 -7
- package/src/artifact/abstractions.ts +46 -0
- package/src/artifact/encryption.ts +69 -0
- package/src/artifact/factory.ts +36 -0
- package/src/artifact/index.ts +3 -0
- package/src/artifact/local.ts +142 -0
- package/src/business/api-key.ts +65 -0
- package/src/business/artifact.ts +288 -0
- package/src/business/backend-unlock.ts +10 -0
- package/src/business/index.ts +9 -0
- package/src/business/instance-lock.ts +124 -0
- package/src/business/instance-state.ts +292 -0
- package/src/business/operation.ts +251 -0
- package/src/business/project-unlock.ts +242 -0
- package/src/business/secret.ts +187 -0
- package/src/business/worker.ts +161 -0
- package/src/common/index.ts +2 -1
- package/src/common/performance.ts +44 -0
- package/src/common/tree.ts +33 -0
- package/src/common/utils.ts +40 -1
- package/src/config.ts +14 -10
- package/src/hotstate/abstractions.ts +48 -0
- package/src/hotstate/factory.ts +17 -0
- package/src/{secret → hotstate}/index.ts +1 -0
- package/src/hotstate/manager.ts +192 -0
- package/src/hotstate/memory.ts +100 -0
- package/src/hotstate/validation.ts +101 -0
- package/src/index.ts +2 -1
- package/src/library/abstractions.ts +10 -23
- package/src/library/factory.ts +2 -2
- package/src/library/local.ts +89 -102
- package/src/library/worker/evaluator.ts +9 -42
- package/src/library/worker/loader.lite.ts +41 -0
- package/src/library/worker/main.ts +14 -65
- package/src/library/worker/protocol.ts +8 -24
- package/src/lock/abstractions.ts +6 -0
- package/src/lock/factory.ts +15 -0
- package/src/{workspace → lock}/index.ts +1 -0
- package/src/lock/manager.ts +82 -0
- package/src/lock/memory.ts +19 -0
- package/src/orchestrator/manager.ts +129 -82
- package/src/orchestrator/operation-workset.ts +168 -77
- package/src/orchestrator/operation.ts +967 -284
- package/src/project/abstractions.ts +20 -7
- package/src/project/factory.ts +1 -1
- package/src/project/index.ts +0 -1
- package/src/project/local.ts +73 -17
- package/src/project/manager.ts +272 -131
- package/src/pubsub/abstractions.ts +13 -0
- package/src/pubsub/factory.ts +19 -0
- package/src/pubsub/index.ts +3 -0
- package/src/pubsub/local.ts +36 -0
- package/src/pubsub/manager.ts +100 -0
- package/src/pubsub/validation.ts +33 -0
- package/src/runner/abstractions.ts +135 -68
- package/src/runner/artifact-env.ts +160 -0
- package/src/runner/factory.ts +20 -5
- package/src/runner/force-abort.ts +117 -0
- package/src/runner/local.ts +281 -371
- package/src/{common → runner}/pulumi.ts +86 -37
- package/src/services.ts +193 -35
- package/src/shared/index.ts +3 -11
- package/src/shared/models/backend/index.ts +3 -0
- package/src/shared/models/backend/project.ts +63 -0
- package/src/shared/models/backend/unlock-method.ts +20 -0
- package/src/shared/models/base.ts +151 -0
- package/src/shared/models/errors.ts +5 -0
- package/src/shared/models/index.ts +4 -0
- package/src/shared/models/project/api-key.ts +62 -0
- package/src/shared/models/project/artifact.ts +113 -0
- package/src/shared/models/project/component.ts +45 -0
- package/src/shared/models/project/index.ts +14 -0
- package/src/shared/{project.ts → models/project/instance.ts} +12 -0
- package/src/shared/models/project/lock.ts +91 -0
- package/src/shared/{operation.ts → models/project/operation.ts} +28 -7
- package/src/shared/models/project/page.ts +57 -0
- package/src/shared/models/project/secret.ts +112 -0
- package/src/shared/models/project/service-account.ts +22 -0
- package/src/shared/models/project/state.ts +432 -0
- package/src/shared/models/project/terminal.ts +99 -0
- package/src/shared/models/project/trigger.ts +56 -0
- package/src/shared/models/project/unlock-method.ts +31 -0
- package/src/shared/models/project/worker.ts +105 -0
- package/src/shared/resolvers/graph-resolver.ts +28 -0
- package/src/shared/resolvers/index.ts +5 -0
- package/src/shared/resolvers/input-hash.ts +53 -15
- package/src/shared/resolvers/input.ts +1 -9
- package/src/shared/resolvers/registry.ts +3 -2
- package/src/shared/resolvers/state.ts +2 -2
- package/src/shared/resolvers/validation.ts +61 -20
- package/src/shared/{async-batcher.ts → utils/async-batcher.ts} +13 -1
- package/src/shared/utils/hash.ts +6 -0
- package/src/shared/utils/index.ts +3 -0
- package/src/shared/utils/promise-tracker.ts +23 -0
- package/src/state/abstractions.ts +330 -101
- package/src/state/encryption.ts +59 -0
- package/src/state/factory.ts +3 -5
- package/src/state/index.ts +3 -0
- package/src/state/keyring.ts +22 -0
- package/src/state/local/backend.ts +299 -0
- package/src/state/local/collection.ts +342 -0
- package/src/state/local/index.ts +2 -0
- package/src/state/manager.ts +804 -18
- package/src/state/repository/index.ts +2 -0
- package/src/state/repository/repository.index.ts +193 -0
- package/src/state/repository/repository.ts +458 -0
- package/src/terminal/{shared.ts → abstractions.ts} +3 -3
- package/src/terminal/docker.ts +18 -14
- package/src/terminal/factory.ts +3 -3
- package/src/terminal/index.ts +1 -1
- package/src/terminal/manager.ts +131 -79
- package/src/terminal/run.sh.ts +21 -11
- package/src/worker/abstractions.ts +42 -0
- package/src/worker/docker.ts +83 -0
- package/src/worker/factory.ts +20 -0
- package/src/worker/index.ts +3 -0
- package/src/worker/manager.ts +139 -0
- package/dist/chunk-KTGKNSKM.js +0 -979
- package/dist/chunk-KTGKNSKM.js.map +0 -1
- package/dist/chunk-WXDYCRTT.js +0 -234
- package/dist/chunk-WXDYCRTT.js.map +0 -1
- package/src/library/worker/loader.ts +0 -114
- package/src/preferences/shared.ts +0 -1
- package/src/project/lock.ts +0 -39
- package/src/secret/abstractions.ts +0 -59
- package/src/secret/factory.ts +0 -22
- package/src/secret/local.ts +0 -152
- package/src/shared/state.ts +0 -247
- package/src/shared/terminal.ts +0 -14
- package/src/state/local.ts +0 -612
- package/src/workspace/abstractions.ts +0 -41
- package/src/workspace/factory.ts +0 -14
- package/src/workspace/local.ts +0 -54
- /package/src/shared/{library.ts → models/backend/library.ts} +0 -0
|
@@ -1,115 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
errorToString
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-RCB4AFGD.js";
|
|
4
4
|
|
|
5
5
|
// src/library/worker/main.ts
|
|
6
6
|
import { parentPort, workerData } from "node:worker_threads";
|
|
7
|
-
import { createJiti } from "jiti";
|
|
8
7
|
import { pino } from "pino";
|
|
9
|
-
import { mapValues } from "remeda";
|
|
10
8
|
|
|
11
|
-
// src/library/worker/
|
|
12
|
-
import Module from "node:module";
|
|
9
|
+
// src/library/worker/evaluator.ts
|
|
13
10
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
isUnitModel,
|
|
17
|
-
originalCreate
|
|
11
|
+
getCompositeInstances,
|
|
12
|
+
resetEvaluation
|
|
18
13
|
} from "@highstate/contract";
|
|
19
|
-
|
|
20
|
-
import { sha256 } from "crypto-hash";
|
|
21
|
-
var originalLoad = Module._load;
|
|
22
|
-
Module._load = function(request, parent, isMain) {
|
|
23
|
-
if (request === "trace_events") {
|
|
24
|
-
return {};
|
|
25
|
-
}
|
|
26
|
-
return originalLoad(request, parent, isMain);
|
|
27
|
-
};
|
|
28
|
-
async function loadLibrary(jiti2, logger2, modulePaths) {
|
|
29
|
-
const modules = {};
|
|
30
|
-
for (const modulePath of modulePaths) {
|
|
31
|
-
try {
|
|
32
|
-
logger2.debug({ modulePath }, "loading module");
|
|
33
|
-
modules[modulePath] = await jiti2.import(modulePath);
|
|
34
|
-
logger2.debug({ modulePath }, "module loaded");
|
|
35
|
-
} catch (err) {
|
|
36
|
-
logger2.error({ modulePath, err }, "module load failed");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const components = {};
|
|
40
|
-
const entities = {};
|
|
41
|
-
await _loadLibrary(modules, components, entities);
|
|
42
|
-
logger2.info(
|
|
43
|
-
{
|
|
44
|
-
componentCount: Object.keys(components).length,
|
|
45
|
-
entityCount: Object.keys(entities).length
|
|
46
|
-
},
|
|
47
|
-
"library loaded"
|
|
48
|
-
);
|
|
49
|
-
logger2.trace({ components, entities }, "library content");
|
|
50
|
-
return { components, entities };
|
|
51
|
-
}
|
|
52
|
-
async function _loadLibrary(value, components, entities) {
|
|
53
|
-
if (isComponent(value)) {
|
|
54
|
-
components[value.model.type] = value;
|
|
55
|
-
value.model.definitionHash = await calculateComponentDefinitionHash(value);
|
|
56
|
-
for (const entity of value.entities.values()) {
|
|
57
|
-
entity.definitionHash ??= await calculateEntityDefinitionHash(entity);
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (isEntity(value)) {
|
|
62
|
-
entities[value.type] = value;
|
|
63
|
-
entities[value.type].definitionHash ??= await calculateEntityDefinitionHash(value);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (typeof value !== "object" || value === null) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
for (const key in value) {
|
|
70
|
-
await _loadLibrary(value[key], components, entities);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async function calculateComponentDefinitionHash(component) {
|
|
74
|
-
if (isUnitModel(component.model)) {
|
|
75
|
-
return await sha256(JSON.stringify(component.model));
|
|
76
|
-
}
|
|
77
|
-
const serializedCreate = await serializeFunction(component[originalCreate]);
|
|
78
|
-
return await sha256(JSON.stringify(component.model) + serializedCreate.text);
|
|
79
|
-
}
|
|
80
|
-
async function calculateEntityDefinitionHash(entity) {
|
|
81
|
-
return await sha256(JSON.stringify(entity));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/library/worker/evaluator.ts
|
|
85
|
-
import { getCompositeInstances, resetEvaluation } from "@highstate/contract";
|
|
86
|
-
import { BetterLock } from "better-lock";
|
|
87
|
-
var lock = new BetterLock();
|
|
88
|
-
function evaluateModules(jiti2, logger2, modulePaths) {
|
|
89
|
-
return lock.acquire(async () => {
|
|
90
|
-
resetEvaluation();
|
|
91
|
-
let lastModulePath = "";
|
|
92
|
-
try {
|
|
93
|
-
for (const modulePath of modulePaths) {
|
|
94
|
-
logger2.info("loading module: %s", modulePath);
|
|
95
|
-
lastModulePath = modulePath;
|
|
96
|
-
await jiti2.import(modulePath);
|
|
97
|
-
logger2.debug("module loaded: %s", modulePath);
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
success: true,
|
|
101
|
-
compositeInstances: getCompositeInstances()
|
|
102
|
-
};
|
|
103
|
-
} catch (error) {
|
|
104
|
-
return {
|
|
105
|
-
success: false,
|
|
106
|
-
modulePath: lastModulePath,
|
|
107
|
-
error: errorToString(error)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function evaluateInstances(logger2, library2, allInstances, resolvedInputs, instanceIds) {
|
|
14
|
+
function evaluateInstances(logger2, components, allInstances, resolvedInputs, instanceIds) {
|
|
113
15
|
const results = [];
|
|
114
16
|
const allInstancesMap = new Map(allInstances.map((instance) => [instance.id, instance]));
|
|
115
17
|
for (const instanceId of instanceIds ?? []) {
|
|
@@ -154,7 +56,7 @@ function evaluateInstances(logger2, library2, allInstances, resolvedInputs, inst
|
|
|
154
56
|
return evaluated[input2.input.output];
|
|
155
57
|
});
|
|
156
58
|
}
|
|
157
|
-
const component =
|
|
59
|
+
const component = components[instance.type];
|
|
158
60
|
if (!component) {
|
|
159
61
|
throw new Error(`Component not found: ${instance.type}, required by instance: ${instanceId}`);
|
|
160
62
|
}
|
|
@@ -166,65 +68,55 @@ function evaluateInstances(logger2, library2, allInstances, resolvedInputs, inst
|
|
|
166
68
|
}
|
|
167
69
|
}
|
|
168
70
|
|
|
71
|
+
// src/library/worker/loader.lite.ts
|
|
72
|
+
import { isComponent } from "@highstate/contract";
|
|
73
|
+
async function loadComponents(logger2, modulePaths) {
|
|
74
|
+
const modules = {};
|
|
75
|
+
for (const modulePath of modulePaths) {
|
|
76
|
+
try {
|
|
77
|
+
logger2.debug({ modulePath }, "loading module");
|
|
78
|
+
modules[modulePath] = await import(modulePath);
|
|
79
|
+
logger2.debug({ modulePath }, "module loaded");
|
|
80
|
+
} catch (err) {
|
|
81
|
+
logger2.error({ modulePath, err }, "module load failed");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const components = {};
|
|
85
|
+
await _loadLibrary(modules, components);
|
|
86
|
+
logger2.debug("library loaded with %s components", Object.keys(components).length);
|
|
87
|
+
return components;
|
|
88
|
+
}
|
|
89
|
+
async function _loadLibrary(value, components) {
|
|
90
|
+
if (isComponent(value)) {
|
|
91
|
+
components[value.model.type] = value;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (typeof value !== "object" || value === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const key in value) {
|
|
98
|
+
await _loadLibrary(value[key], components);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
169
102
|
// src/library/worker/main.ts
|
|
170
103
|
var data = workerData;
|
|
171
104
|
var logger = pino({ name: "library-worker", level: data.logLevel });
|
|
172
|
-
var jiti;
|
|
173
|
-
var library;
|
|
174
105
|
try {
|
|
175
|
-
logger.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
entities: library.entities
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
logger.info("library loaded and sent");
|
|
106
|
+
const library = await loadComponents(logger, data.libraryModulePaths);
|
|
107
|
+
const results = evaluateInstances(
|
|
108
|
+
logger,
|
|
109
|
+
library,
|
|
110
|
+
data.allInstances,
|
|
111
|
+
data.resolvedInputs,
|
|
112
|
+
data.instanceIds
|
|
113
|
+
);
|
|
114
|
+
parentPort.postMessage({ type: "results", results });
|
|
188
115
|
} catch (error) {
|
|
189
|
-
logger.error({ error }, "failed to
|
|
116
|
+
logger.error({ error }, "failed to evaluate");
|
|
190
117
|
parentPort.postMessage({
|
|
191
118
|
type: "error",
|
|
192
119
|
error: errorToString(error)
|
|
193
120
|
});
|
|
194
121
|
}
|
|
195
|
-
parentPort.on("message", async (message) => {
|
|
196
|
-
try {
|
|
197
|
-
const request = message;
|
|
198
|
-
switch (request.type) {
|
|
199
|
-
case "evaluate-composite-instances": {
|
|
200
|
-
const results = evaluateInstances(
|
|
201
|
-
logger,
|
|
202
|
-
library,
|
|
203
|
-
request.allInstances,
|
|
204
|
-
request.resolvedInputs,
|
|
205
|
-
request.instanceIds
|
|
206
|
-
);
|
|
207
|
-
parentPort.postMessage({
|
|
208
|
-
type: "instance-evaluation-results",
|
|
209
|
-
results
|
|
210
|
-
});
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case "evaluate-modules": {
|
|
214
|
-
const result = await evaluateModules(jiti, logger, request.modulePaths);
|
|
215
|
-
parentPort.postMessage({
|
|
216
|
-
type: "module-evaluation-result",
|
|
217
|
-
result
|
|
218
|
-
});
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
} catch (error) {
|
|
223
|
-
logger.error({ error }, "failed to evaluate");
|
|
224
|
-
parentPort.postMessage({
|
|
225
|
-
type: "error",
|
|
226
|
-
error: errorToString(error)
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
122
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/library/worker/main.ts","../../../src/library/worker/loader.ts","../../../src/library/worker/evaluator.ts"],"sourcesContent":["import type { WorkerData, WorkerRequest, WorkerResponse } from \"./protocol\"\nimport { parentPort, workerData } from \"node:worker_threads\"\nimport { createJiti, type Jiti } from \"jiti\"\nimport { pino } from \"pino\"\nimport { mapValues } from \"remeda\"\nimport { errorToString } from \"../../common\"\nimport { loadLibrary, type Library } from \"./loader\"\nimport { evaluateInstances, evaluateModules } from \"./evaluator\"\n\nconst data = workerData as WorkerData\n\nconst logger = pino({ name: \"library-worker\", level: data.logLevel })\nlet jiti: Jiti\nlet library: Library\n\ntry {\n logger.info(\"worker started\")\n logger.trace({ data }, \"worker data\")\n\n jiti = createJiti(import.meta.filename)\n logger.debug({ filename: import.meta.filename }, \"jiti created\")\n\n library = await loadLibrary(jiti, logger, data.modulePaths)\n\n parentPort!.postMessage({\n type: \"library\",\n library: {\n components: mapValues(library.components, component => component.model),\n entities: library.entities,\n },\n } satisfies WorkerResponse)\n\n logger.info(\"library loaded and sent\")\n} catch (error) {\n logger.error({ error }, \"failed to load library\")\n\n parentPort!.postMessage({\n type: \"error\",\n error: errorToString(error),\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-misused-promises\nparentPort!.on(\"message\", async message => {\n try {\n const request = message as WorkerRequest\n\n switch (request.type) {\n case \"evaluate-composite-instances\": {\n const results = evaluateInstances(\n logger,\n library,\n request.allInstances,\n request.resolvedInputs,\n request.instanceIds,\n )\n\n parentPort!.postMessage({\n type: \"instance-evaluation-results\",\n results,\n } satisfies WorkerResponse)\n break\n }\n case \"evaluate-modules\": {\n const result = await evaluateModules(jiti, logger, request.modulePaths)\n\n parentPort!.postMessage({\n type: \"module-evaluation-result\",\n result,\n } satisfies WorkerResponse)\n break\n }\n }\n } catch (error) {\n logger.error({ error }, \"failed to evaluate\")\n\n parentPort!.postMessage({\n type: \"error\",\n error: errorToString(error),\n } satisfies WorkerResponse)\n }\n})\n","import type { Logger } from \"pino\"\nimport type { Jiti } from \"jiti\"\nimport Module from \"node:module\"\nimport {\n type Component,\n type Entity,\n isComponent,\n isEntity,\n isUnitModel,\n originalCreate,\n} from \"@highstate/contract\"\nimport { serializeFunction } from \"@pulumi/pulumi/runtime/index.js\"\nimport { sha256 } from \"crypto-hash\"\n\ndeclare module \"module\" {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Module {\n function _load(request: unknown, parent: unknown, isMain: boolean): unknown\n }\n}\n\nconst originalLoad = Module._load\n\nModule._load = function (request: unknown, parent: unknown, isMain: boolean) {\n if (request === \"trace_events\") {\n return {}\n }\n\n return originalLoad(request, parent, isMain)\n}\n\nexport type Library = Readonly<{\n components: Readonly<Record<string, Component>>\n entities: Readonly<Record<string, Entity>>\n}>\n\nexport async function loadLibrary(\n jiti: Jiti,\n logger: Logger,\n modulePaths: string[],\n): Promise<Library> {\n const modules: Record<string, unknown> = {}\n for (const modulePath of modulePaths) {\n try {\n logger.debug({ modulePath }, \"loading module\")\n modules[modulePath] = await jiti.import(modulePath)\n\n logger.debug({ modulePath }, \"module loaded\")\n } catch (err) {\n logger.error({ modulePath, err }, \"module load failed\")\n }\n }\n\n const components: Record<string, Component> = {}\n const entities: Record<string, Entity> = {}\n\n await _loadLibrary(modules, components, entities)\n\n logger.info(\n {\n componentCount: Object.keys(components).length,\n entityCount: Object.keys(entities).length,\n },\n \"library loaded\",\n )\n\n logger.trace({ components, entities }, \"library content\")\n\n return { components, entities }\n}\n\nasync function _loadLibrary(\n value: unknown,\n components: Record<string, Component>,\n entities: Record<string, Entity>,\n): Promise<void> {\n if (isComponent(value)) {\n components[value.model.type] = value\n value.model.definitionHash = await calculateComponentDefinitionHash(value)\n\n for (const entity of value.entities.values()) {\n entity.definitionHash ??= await calculateEntityDefinitionHash(entity)\n }\n return\n }\n\n if (isEntity(value)) {\n entities[value.type] = value\n entities[value.type].definitionHash ??= await calculateEntityDefinitionHash(value)\n return\n }\n\n if (typeof value !== \"object\" || value === null) {\n return\n }\n\n for (const key in value) {\n await _loadLibrary((value as Record<string, unknown>)[key], components, entities)\n }\n}\n\nasync function calculateComponentDefinitionHash(component: Component): Promise<string> {\n if (isUnitModel(component.model)) {\n return await sha256(JSON.stringify(component.model))\n }\n\n const serializedCreate = await serializeFunction(component[originalCreate])\n\n return await sha256(JSON.stringify(component.model) + serializedCreate.text)\n}\n\nasync function calculateEntityDefinitionHash(entity: Entity): Promise<string> {\n return await sha256(JSON.stringify(entity))\n}\n","import type { Logger } from \"pino\"\nimport type { Library } from \"./loader\"\nimport type { Jiti } from \"jiti\"\nimport type { InstanceEvaluationResult, ModuleEvaluationResult } from \"../abstractions\"\nimport type { ResolvedInstanceInput } from \"../../shared\"\nimport { getCompositeInstances, resetEvaluation, type InstanceModel } from \"@highstate/contract\"\nimport { BetterLock } from \"better-lock\"\nimport { errorToString } from \"../../common\"\n\nconst lock = new BetterLock()\n\nexport function evaluateModules(\n jiti: Jiti,\n logger: Logger,\n modulePaths: string[],\n): Promise<ModuleEvaluationResult> {\n return lock.acquire(async () => {\n resetEvaluation()\n let lastModulePath = \"\"\n\n try {\n for (const modulePath of modulePaths) {\n logger.info(\"loading module: %s\", modulePath)\n\n lastModulePath = modulePath\n await jiti.import(modulePath)\n\n logger.debug(\"module loaded: %s\", modulePath)\n }\n\n return {\n success: true,\n compositeInstances: getCompositeInstances(),\n }\n } catch (error) {\n return {\n success: false,\n modulePath: lastModulePath,\n error: errorToString(error),\n }\n }\n })\n}\n\nexport function evaluateInstances(\n logger: Logger,\n library: Library,\n allInstances: InstanceModel[],\n resolvedInputs: Record<string, Record<string, ResolvedInstanceInput[]>>,\n instanceIds: string[],\n): InstanceEvaluationResult[] {\n const results: InstanceEvaluationResult[] = []\n const allInstancesMap = new Map(allInstances.map(instance => [instance.id, instance]))\n\n for (const instanceId of instanceIds ?? []) {\n try {\n logger.debug({ instanceId }, \"evaluating top-level instance\")\n resetEvaluation()\n\n evaluateInstance(instanceId)\n\n results.push({\n success: true,\n instanceId,\n compositeInstances: getCompositeInstances().filter(\n instance =>\n instanceId.includes(instance.instance.id) || !allInstancesMap.has(instance.instance.id),\n ),\n })\n } catch (error) {\n results.push({\n success: false,\n instanceId,\n error: errorToString(error),\n })\n }\n }\n\n return results\n\n function evaluateInstance(\n instanceId: string,\n instanceOutputs: Map<string, Record<string, unknown>> = new Map(),\n ): Record<string, unknown> {\n let outputs = instanceOutputs.get(instanceId)\n\n if (!outputs) {\n outputs = _evaluateInstance(instanceId, instanceOutputs)\n instanceOutputs.set(instanceId, outputs)\n }\n\n return outputs\n }\n\n function _evaluateInstance(\n instanceId: string,\n instanceOutputs: Map<string, Record<string, unknown>>,\n ): Record<string, unknown> {\n const inputs: Record<string, unknown> = {}\n const instance = allInstancesMap.get(instanceId)\n\n logger.info(\"evaluating instance\", { instanceId })\n\n if (!instance) {\n throw new Error(`Instance not found: ${instanceId}`)\n }\n\n for (const [inputName, input] of Object.entries(resolvedInputs[instanceId] ?? {})) {\n inputs[inputName] = input.map(input => {\n const evaluated = evaluateInstance(input.input.instanceId, instanceOutputs)\n\n return evaluated[input.input.output]\n })\n }\n\n const component = library.components[instance.type]\n if (!component) {\n throw new Error(`Component not found: ${instance.type}, required by instance: ${instanceId}`)\n }\n\n return component({\n name: instance.name,\n args: instance.args as Record<string, never>,\n inputs: inputs as Record<string, never>,\n })\n }\n}\n"],"mappings":";;;;;AACA,SAAS,YAAY,kBAAkB;AACvC,SAAS,kBAA6B;AACtC,SAAS,YAAY;AACrB,SAAS,iBAAiB;;;ACF1B,OAAO,YAAY;AACnB;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,cAAc;AASvB,IAAM,eAAe,OAAO;AAE5B,OAAO,QAAQ,SAAU,SAAkB,QAAiB,QAAiB;AAC3E,MAAI,YAAY,gBAAgB;AAC9B,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,aAAa,SAAS,QAAQ,MAAM;AAC7C;AAOA,eAAsB,YACpBA,OACAC,SACA,aACkB;AAClB,QAAM,UAAmC,CAAC;AAC1C,aAAW,cAAc,aAAa;AACpC,QAAI;AACF,MAAAA,QAAO,MAAM,EAAE,WAAW,GAAG,gBAAgB;AAC7C,cAAQ,UAAU,IAAI,MAAMD,MAAK,OAAO,UAAU;AAElD,MAAAC,QAAO,MAAM,EAAE,WAAW,GAAG,eAAe;AAAA,IAC9C,SAAS,KAAK;AACZ,MA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YAAY,QAAQ;AACtC,SAAO,MAAM,EAAE,UAAU,YAAY,SAAS,GAAG,cAAc;AAE/D,YAAU,MAAM,YAAY,MAAM,QAAQ,KAAK,WAAW;AAE1D,aAAY,YAAY;AAAA,IACtB,MAAM;AAAA,IACN,SAAS;AAAA,MACP,YAAY,UAAU,QAAQ,YAAY,eAAa,UAAU,KAAK;AAAA,MACtE,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF,CAA0B;AAE1B,SAAO,KAAK,yBAAyB;AACvC,SAAS,OAAO;AACd,SAAO,MAAM,EAAE,MAAM,GAAG,wBAAwB;AAEhD,aAAY,YAAY;AAAA,IACtB,MAAM;AAAA,IACN,OAAO,cAAc,KAAK;AAAA,EAC5B,CAAC;AACH;AAGA,WAAY,GAAG,WAAW,OAAM,YAAW;AACzC,MAAI;AACF,UAAM,UAAU;AAEhB,YAAQ,QAAQ,MAAM;AAAA,MACpB,KAAK,gCAAgC;AACnC,cAAM,UAAU;AAAA,UACd;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,UACR,QAAQ;AAAA,UACR,QAAQ;AAAA,QACV;AAEA,mBAAY,YAAY;AAAA,UACtB,MAAM;AAAA,UACN;AAAA,QACF,CAA0B;AAC1B;AAAA,MACF;AAAA,MACA,KAAK,oBAAoB;AACvB,cAAM,SAAS,MAAM,gBAAgB,MAAM,QAAQ,QAAQ,WAAW;AAEtE,mBAAY,YAAY;AAAA,UACtB,MAAM;AAAA,UACN;AAAA,QACF,CAA0B;AAC1B;AAAA,MACF;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,WAAO,MAAM,EAAE,MAAM,GAAG,oBAAoB;AAE5C,eAAY,YAAY;AAAA,MACtB,MAAM;AAAA,MACN,OAAO,cAAc,KAAK;AAAA,IAC5B,CAA0B;AAAA,EAC5B;AACF,CAAC;","names":["jiti","logger","jiti","logger","library","input"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/library/worker/main.ts","../../../src/library/worker/evaluator.ts","../../../src/library/worker/loader.lite.ts"],"sourcesContent":["import type { WorkerData, WorkerResponse } from \"./protocol\"\nimport { parentPort, workerData } from \"node:worker_threads\"\nimport { pino } from \"pino\"\nimport { errorToString } from \"../../common\"\nimport { evaluateInstances } from \"./evaluator\"\nimport { loadComponents } from \"./loader.lite\"\n\nconst data = workerData as WorkerData\n\nconst logger = pino({ name: \"library-worker\", level: data.logLevel })\n\ntry {\n const library = await loadComponents(logger, data.libraryModulePaths)\n\n const results = evaluateInstances(\n logger,\n library,\n data.allInstances,\n data.resolvedInputs,\n data.instanceIds,\n )\n\n parentPort!.postMessage({ type: \"results\", results } satisfies WorkerResponse)\n} catch (error) {\n logger.error({ error }, \"failed to evaluate\")\n\n parentPort!.postMessage({\n type: \"error\",\n error: errorToString(error),\n } satisfies WorkerResponse)\n}\n","import type { Logger } from \"pino\"\nimport type { InstanceEvaluationResult } from \"../abstractions\"\nimport type { ResolvedInstanceInput } from \"../../shared\"\nimport {\n getCompositeInstances,\n resetEvaluation,\n type Component,\n type InstanceModel,\n} from \"@highstate/contract\"\nimport { errorToString } from \"../../common\"\n\nexport function evaluateInstances(\n logger: Logger,\n components: Readonly<Record<string, Component>>,\n allInstances: InstanceModel[],\n resolvedInputs: Record<string, Record<string, ResolvedInstanceInput[]>>,\n instanceIds: string[],\n): InstanceEvaluationResult[] {\n const results: InstanceEvaluationResult[] = []\n const allInstancesMap = new Map(allInstances.map(instance => [instance.id, instance]))\n\n for (const instanceId of instanceIds ?? []) {\n try {\n logger.debug({ instanceId }, \"evaluating top-level instance\")\n resetEvaluation()\n\n evaluateInstance(instanceId)\n\n results.push({\n success: true,\n instanceId,\n compositeInstances: getCompositeInstances().filter(\n instance =>\n instanceId.includes(instance.instance.id) || !allInstancesMap.has(instance.instance.id),\n ),\n })\n } catch (error) {\n results.push({\n success: false,\n instanceId,\n error: errorToString(error),\n })\n }\n }\n\n return results\n\n function evaluateInstance(\n instanceId: string,\n instanceOutputs: Map<string, Record<string, unknown>> = new Map(),\n ): Record<string, unknown> {\n let outputs = instanceOutputs.get(instanceId)\n\n if (!outputs) {\n outputs = _evaluateInstance(instanceId, instanceOutputs)\n instanceOutputs.set(instanceId, outputs)\n }\n\n return outputs\n }\n\n function _evaluateInstance(\n instanceId: string,\n instanceOutputs: Map<string, Record<string, unknown>>,\n ): Record<string, unknown> {\n const inputs: Record<string, unknown> = {}\n const instance = allInstancesMap.get(instanceId)\n\n logger.info(\"evaluating instance\", { instanceId })\n\n if (!instance) {\n throw new Error(`Instance not found: ${instanceId}`)\n }\n\n for (const [inputName, input] of Object.entries(resolvedInputs[instanceId] ?? {})) {\n inputs[inputName] = input.map(input => {\n const evaluated = evaluateInstance(input.input.instanceId, instanceOutputs)\n\n return evaluated[input.input.output]\n })\n }\n\n const component = components[instance.type]\n if (!component) {\n throw new Error(`Component not found: ${instance.type}, required by instance: ${instanceId}`)\n }\n\n return component({\n name: instance.name,\n args: instance.args as Record<string, never>,\n inputs: inputs as Record<string, never>,\n })\n }\n}\n","import type { Logger } from \"pino\"\nimport { isComponent, type Component } from \"@highstate/contract\"\n\nexport async function loadComponents(\n logger: Logger,\n modulePaths: string[],\n): Promise<Readonly<Record<string, Component>>> {\n const modules: Record<string, unknown> = {}\n for (const modulePath of modulePaths) {\n try {\n logger.debug({ modulePath }, \"loading module\")\n modules[modulePath] = await import(modulePath)\n\n logger.debug({ modulePath }, \"module loaded\")\n } catch (err) {\n logger.error({ modulePath, err }, \"module load failed\")\n }\n }\n\n const components: Record<string, Component> = {}\n\n await _loadLibrary(modules, components)\n logger.debug(\"library loaded with %s components\", Object.keys(components).length)\n\n return components\n}\n\nasync function _loadLibrary(value: unknown, components: Record<string, Component>): Promise<void> {\n if (isComponent(value)) {\n components[value.model.type] = value\n return\n }\n\n if (typeof value !== \"object\" || value === null) {\n return\n }\n\n for (const key in value) {\n await _loadLibrary((value as Record<string, unknown>)[key], components)\n }\n}\n"],"mappings":";;;;;AACA,SAAS,YAAY,kBAAkB;AACvC,SAAS,YAAY;;;ACC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B,OAAO,KAAK,SAAS,CAAC;AAEpE,IAAI;AACF,QAAM,UAAU,MAAM,eAAe,QAAQ,KAAK,kBAAkB;AAEpE,QAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AAEA,aAAY,YAAY,EAAE,MAAM,WAAW,QAAQ,CAA0B;AAC/E,SAAS,OAAO;AACd,SAAO,MAAM,EAAE,MAAM,GAAG,oBAAoB;AAE5C,aAAY,YAAY;AAAA,IACtB,MAAM;AAAA,IACN,OAAO,cAAc,KAAK;AAAA,EAC5B,CAA0B;AAC5B;","names":["logger","input","logger"]}
|
package/dist/shared/index.js
CHANGED
|
@@ -1,99 +1,217 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AccessError,
|
|
2
3
|
GraphResolver,
|
|
3
4
|
InputHashResolver,
|
|
4
5
|
InputResolver,
|
|
6
|
+
PromiseTracker,
|
|
5
7
|
ValidationResolver,
|
|
8
|
+
WellKnownInstanceCustomStatus,
|
|
9
|
+
WellKnownSecretDescriptors,
|
|
6
10
|
applyLibraryUpdate,
|
|
7
|
-
|
|
11
|
+
applyStatePatch,
|
|
12
|
+
artifactSchema,
|
|
13
|
+
artifactUsageSchema,
|
|
14
|
+
backendUnlockMethodSchema,
|
|
15
|
+
collectionQuerySchema,
|
|
16
|
+
compareArtifactUsage,
|
|
17
|
+
compareInstanceLockSpecs,
|
|
18
|
+
componentArgumentSchema,
|
|
19
|
+
componentInputSchema,
|
|
20
|
+
componentMetaSchema,
|
|
21
|
+
componentModelSchema,
|
|
22
|
+
compositeInstanceEventSchema,
|
|
8
23
|
compositeInstanceSchema,
|
|
9
24
|
createAsyncBatcher,
|
|
10
|
-
createInstanceState,
|
|
11
|
-
createInstanceStatePatch,
|
|
12
25
|
diffLibraries,
|
|
13
|
-
|
|
26
|
+
entitySchema,
|
|
27
|
+
fileContentSchema,
|
|
28
|
+
fileMetaSchema,
|
|
29
|
+
fileSchema,
|
|
30
|
+
formatSecretDescriptor,
|
|
14
31
|
getMatchedInjectionInstanceInputs,
|
|
15
32
|
getResolvedHubInputs,
|
|
16
33
|
getResolvedInjectionInstanceInputs,
|
|
17
34
|
getResolvedInstanceInputs,
|
|
35
|
+
getWorkerIdentity,
|
|
36
|
+
hasObjectMeta,
|
|
18
37
|
hubInstanceInputSchema,
|
|
19
38
|
hubModelPatchSchema,
|
|
20
39
|
hubModelSchema,
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
instanceActionSchema,
|
|
41
|
+
instanceCustomStatusSchema,
|
|
42
|
+
instanceEvaluationStatusSchema,
|
|
43
|
+
instanceEvaludationStatusEnumSchema,
|
|
23
44
|
instanceInputSchema,
|
|
45
|
+
instanceLockEventSchema,
|
|
46
|
+
instanceLockSchema,
|
|
47
|
+
instanceLockSpecSchema,
|
|
24
48
|
instanceModelPatchSchema,
|
|
25
49
|
instanceModelSchema,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
instanceOperationStatusEnumSchema,
|
|
51
|
+
instanceOperationStatusSchema,
|
|
52
|
+
instanceStateEventSchema,
|
|
53
|
+
instanceStateExtraSchema,
|
|
54
|
+
instanceStatePatchSchema,
|
|
29
55
|
instanceStateSchema,
|
|
30
|
-
instanceStateUpdateSchema,
|
|
31
56
|
instanceStatusFieldSchema,
|
|
32
57
|
instanceStatusFieldValueSchema,
|
|
33
|
-
|
|
34
|
-
instanceTerminalFileSchema,
|
|
35
|
-
instanceTerminalMetaSchema,
|
|
36
|
-
instanceTerminalSchema,
|
|
37
|
-
instanceTriggerInvocationSchema,
|
|
38
|
-
instanceTriggerSchema,
|
|
39
|
-
instanceTriggerSpecSchema,
|
|
58
|
+
int32ToBytes,
|
|
40
59
|
isFinalOperationStatus,
|
|
60
|
+
isStableOperationStatus,
|
|
61
|
+
isStateEmpty,
|
|
62
|
+
isTransientOperationStatus,
|
|
63
|
+
metaSchema,
|
|
64
|
+
objectMetaSchema,
|
|
65
|
+
operationEventSchema,
|
|
66
|
+
operationLogEntrySchema,
|
|
41
67
|
operationOptionsSchema,
|
|
68
|
+
operationRequestSchema,
|
|
69
|
+
operationSchema,
|
|
42
70
|
operationStatusSchema,
|
|
43
71
|
operationTypeSchema,
|
|
72
|
+
pageBlockSchema,
|
|
73
|
+
pageContentSchema,
|
|
74
|
+
pageSchema,
|
|
75
|
+
parseSecretDescriptor,
|
|
44
76
|
positionSchema,
|
|
45
|
-
|
|
46
|
-
|
|
77
|
+
projectAccessActionDescriptions,
|
|
78
|
+
projectAccessScope,
|
|
79
|
+
projectApiKeySchema,
|
|
80
|
+
projectModelSchema,
|
|
81
|
+
projectSchema,
|
|
82
|
+
projectUnlockStateSchema,
|
|
83
|
+
projectUnlockSuiteSchema,
|
|
47
84
|
resolverFactories,
|
|
48
|
-
|
|
49
|
-
|
|
85
|
+
secretDescriptorSchema,
|
|
86
|
+
secretSchema,
|
|
87
|
+
serviceAccountActionSchema,
|
|
88
|
+
serviceAccountSchema,
|
|
89
|
+
terminalSchema,
|
|
90
|
+
terminalSessionSchema,
|
|
91
|
+
terminalSpecSchema,
|
|
92
|
+
triggerInvocationSchema,
|
|
93
|
+
triggerSchema,
|
|
94
|
+
triggerSpecSchema,
|
|
95
|
+
unitArtifactSchema,
|
|
96
|
+
unitInstanceStatusFieldSchema,
|
|
97
|
+
unitPageSchema,
|
|
98
|
+
unitTerminalSchema,
|
|
99
|
+
unitTriggerSchema,
|
|
100
|
+
unitWorkerSchema,
|
|
101
|
+
unlockMethodSchema,
|
|
102
|
+
unlockMethodType,
|
|
103
|
+
userObjectMetaSchema,
|
|
104
|
+
validateInstanceAccess,
|
|
105
|
+
workerSchema,
|
|
106
|
+
workerStatus,
|
|
107
|
+
workerUnitRegistrationSchema
|
|
108
|
+
} from "../chunk-WHALQHEZ.js";
|
|
50
109
|
export {
|
|
110
|
+
AccessError,
|
|
51
111
|
GraphResolver,
|
|
52
112
|
InputHashResolver,
|
|
53
113
|
InputResolver,
|
|
114
|
+
PromiseTracker,
|
|
54
115
|
ValidationResolver,
|
|
116
|
+
WellKnownInstanceCustomStatus,
|
|
117
|
+
WellKnownSecretDescriptors,
|
|
55
118
|
applyLibraryUpdate,
|
|
56
|
-
|
|
119
|
+
applyStatePatch,
|
|
120
|
+
artifactSchema,
|
|
121
|
+
artifactUsageSchema,
|
|
122
|
+
backendUnlockMethodSchema,
|
|
123
|
+
collectionQuerySchema,
|
|
124
|
+
compareArtifactUsage,
|
|
125
|
+
compareInstanceLockSpecs,
|
|
126
|
+
componentArgumentSchema,
|
|
127
|
+
componentInputSchema,
|
|
128
|
+
componentMetaSchema,
|
|
129
|
+
componentModelSchema,
|
|
130
|
+
compositeInstanceEventSchema,
|
|
57
131
|
compositeInstanceSchema,
|
|
58
132
|
createAsyncBatcher,
|
|
59
|
-
createInstanceState,
|
|
60
|
-
createInstanceStatePatch,
|
|
61
133
|
diffLibraries,
|
|
62
|
-
|
|
134
|
+
entitySchema,
|
|
135
|
+
fileContentSchema,
|
|
136
|
+
fileMetaSchema,
|
|
137
|
+
fileSchema,
|
|
138
|
+
formatSecretDescriptor,
|
|
63
139
|
getMatchedInjectionInstanceInputs,
|
|
64
140
|
getResolvedHubInputs,
|
|
65
141
|
getResolvedInjectionInstanceInputs,
|
|
66
142
|
getResolvedInstanceInputs,
|
|
143
|
+
getWorkerIdentity,
|
|
144
|
+
hasObjectMeta,
|
|
67
145
|
hubInstanceInputSchema,
|
|
68
146
|
hubModelPatchSchema,
|
|
69
147
|
hubModelSchema,
|
|
70
|
-
|
|
71
|
-
|
|
148
|
+
instanceActionSchema,
|
|
149
|
+
instanceCustomStatusSchema,
|
|
150
|
+
instanceEvaluationStatusSchema,
|
|
151
|
+
instanceEvaludationStatusEnumSchema,
|
|
72
152
|
instanceInputSchema,
|
|
153
|
+
instanceLockEventSchema,
|
|
154
|
+
instanceLockSchema,
|
|
155
|
+
instanceLockSpecSchema,
|
|
73
156
|
instanceModelPatchSchema,
|
|
74
157
|
instanceModelSchema,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
158
|
+
instanceOperationStatusEnumSchema,
|
|
159
|
+
instanceOperationStatusSchema,
|
|
160
|
+
instanceStateEventSchema,
|
|
161
|
+
instanceStateExtraSchema,
|
|
162
|
+
instanceStatePatchSchema,
|
|
78
163
|
instanceStateSchema,
|
|
79
|
-
instanceStateUpdateSchema,
|
|
80
164
|
instanceStatusFieldSchema,
|
|
81
165
|
instanceStatusFieldValueSchema,
|
|
82
|
-
|
|
83
|
-
instanceTerminalFileSchema,
|
|
84
|
-
instanceTerminalMetaSchema,
|
|
85
|
-
instanceTerminalSchema,
|
|
86
|
-
instanceTriggerInvocationSchema,
|
|
87
|
-
instanceTriggerSchema,
|
|
88
|
-
instanceTriggerSpecSchema,
|
|
166
|
+
int32ToBytes,
|
|
89
167
|
isFinalOperationStatus,
|
|
168
|
+
isStableOperationStatus,
|
|
169
|
+
isStateEmpty,
|
|
170
|
+
isTransientOperationStatus,
|
|
171
|
+
metaSchema,
|
|
172
|
+
objectMetaSchema,
|
|
173
|
+
operationEventSchema,
|
|
174
|
+
operationLogEntrySchema,
|
|
90
175
|
operationOptionsSchema,
|
|
176
|
+
operationRequestSchema,
|
|
177
|
+
operationSchema,
|
|
91
178
|
operationStatusSchema,
|
|
92
179
|
operationTypeSchema,
|
|
180
|
+
pageBlockSchema,
|
|
181
|
+
pageContentSchema,
|
|
182
|
+
pageSchema,
|
|
183
|
+
parseSecretDescriptor,
|
|
93
184
|
positionSchema,
|
|
94
|
-
|
|
95
|
-
|
|
185
|
+
projectAccessActionDescriptions,
|
|
186
|
+
projectAccessScope,
|
|
187
|
+
projectApiKeySchema,
|
|
188
|
+
projectModelSchema,
|
|
189
|
+
projectSchema,
|
|
190
|
+
projectUnlockStateSchema,
|
|
191
|
+
projectUnlockSuiteSchema,
|
|
96
192
|
resolverFactories,
|
|
97
|
-
|
|
193
|
+
secretDescriptorSchema,
|
|
194
|
+
secretSchema,
|
|
195
|
+
serviceAccountActionSchema,
|
|
196
|
+
serviceAccountSchema,
|
|
197
|
+
terminalSchema,
|
|
198
|
+
terminalSessionSchema,
|
|
199
|
+
terminalSpecSchema,
|
|
200
|
+
triggerInvocationSchema,
|
|
201
|
+
triggerSchema,
|
|
202
|
+
triggerSpecSchema,
|
|
203
|
+
unitArtifactSchema,
|
|
204
|
+
unitInstanceStatusFieldSchema,
|
|
205
|
+
unitPageSchema,
|
|
206
|
+
unitTerminalSchema,
|
|
207
|
+
unitTriggerSchema,
|
|
208
|
+
unitWorkerSchema,
|
|
209
|
+
unlockMethodSchema,
|
|
210
|
+
unlockMethodType,
|
|
211
|
+
userObjectMetaSchema,
|
|
212
|
+
validateInstanceAccess,
|
|
213
|
+
workerSchema,
|
|
214
|
+
workerStatus,
|
|
215
|
+
workerUnitRegistrationSchema
|
|
98
216
|
};
|
|
99
217
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@highstate/backend",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.16",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"highstate": {
|
|
6
|
+
"sourceHash": {
|
|
7
|
+
"mode": "manual",
|
|
8
|
+
"version": ""
|
|
9
|
+
}
|
|
10
|
+
},
|
|
5
11
|
"files": [
|
|
6
12
|
"dist",
|
|
7
13
|
"src",
|
|
@@ -26,25 +32,36 @@
|
|
|
26
32
|
"build": "highstate build"
|
|
27
33
|
},
|
|
28
34
|
"dependencies": {
|
|
29
|
-
"@
|
|
35
|
+
"@aws-crypto/crc32": "^5.2.0",
|
|
36
|
+
"@highstate/contract": "^0.9.16",
|
|
37
|
+
"@msgpack/msgpack": "^3.1.2",
|
|
38
|
+
"@napi-rs/keyring": "^1.1.8",
|
|
39
|
+
"@noble/ciphers": "^1.3.0",
|
|
40
|
+
"@noble/hashes": "^1.8.0",
|
|
30
41
|
"@types/node": "^22.10.1",
|
|
42
|
+
"age-encryption": "^0.2.3",
|
|
31
43
|
"ajv": "^8.17.1",
|
|
44
|
+
"ansi-colors": "^4.1.3",
|
|
45
|
+
"ansi-styles": "^6.2.1",
|
|
32
46
|
"better-lock": "^3.2.0",
|
|
33
47
|
"consola": "^3.2.3",
|
|
34
48
|
"crypto-hash": "^3.1.0",
|
|
35
49
|
"dotenv": "^16.4.7",
|
|
50
|
+
"execa": "^9.6.0",
|
|
51
|
+
"flexsearch": "^0.8.205",
|
|
36
52
|
"import-meta-resolve": "^4.1.0",
|
|
37
|
-
"
|
|
53
|
+
"lru-cache": "^11.1.0",
|
|
38
54
|
"nano-spawn": "^0.2.0",
|
|
39
55
|
"nypm": "^0.6.0",
|
|
40
56
|
"pino": "^9.6.0",
|
|
41
57
|
"pkg-types": "^1.2.1",
|
|
42
58
|
"remeda": "^2.21.0",
|
|
43
59
|
"rev-dep": "^1.5.4",
|
|
44
|
-
"
|
|
60
|
+
"ulid": "^3.0.1",
|
|
61
|
+
"uuid": "^11.1.0",
|
|
45
62
|
"watcher": "^2.3.1",
|
|
46
63
|
"yaml": "^2.7.1",
|
|
47
|
-
"zod": "^
|
|
64
|
+
"zod": "^4.0.5"
|
|
48
65
|
},
|
|
49
66
|
"peerDependencies": {
|
|
50
67
|
"@pulumi/pulumi": "^3.163.0",
|
|
@@ -59,11 +76,12 @@
|
|
|
59
76
|
}
|
|
60
77
|
},
|
|
61
78
|
"devDependencies": {
|
|
62
|
-
"classic-level": "^
|
|
79
|
+
"classic-level": "^3.0.0",
|
|
63
80
|
"highstate-cli-bootstrap": "npm:@highstate/cli@0.7.6",
|
|
64
81
|
"pino-pretty": "^13.0.0",
|
|
65
82
|
"rollup": "^4.28.1",
|
|
83
|
+
"type-fest": "^4.41.0",
|
|
66
84
|
"typescript": "^5.7.2"
|
|
67
85
|
},
|
|
68
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "458d6f1f9f6d4aec0ba75a2b2c4c01408cb9c8df"
|
|
69
87
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface ArtifactBackend {
|
|
2
|
+
/**
|
|
3
|
+
* Stores content and returns its hash.
|
|
4
|
+
* If content with the same hash already exists, returns existing hash.
|
|
5
|
+
*
|
|
6
|
+
* @param projectId The project ID to which the content belongs.
|
|
7
|
+
* @param hsah The content hash.
|
|
8
|
+
* @param chunkSize The size of each chunk to store. Only the last chunk may be smaller.
|
|
9
|
+
* @param content The async iterable of content chunks.
|
|
10
|
+
*/
|
|
11
|
+
store(
|
|
12
|
+
projectId: string,
|
|
13
|
+
hash: string,
|
|
14
|
+
chunkSize: number,
|
|
15
|
+
content: AsyncIterable<Uint8Array>,
|
|
16
|
+
): Promise<void>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves content by hash.
|
|
20
|
+
*
|
|
21
|
+
* @param projectId The project ID to which the content belongs.
|
|
22
|
+
* @param hash The content hash.
|
|
23
|
+
* @param chunkSize The size of each chunk to retrieve. Only the last chunk may be smaller.
|
|
24
|
+
*/
|
|
25
|
+
retrieve(
|
|
26
|
+
projectId: string,
|
|
27
|
+
hash: string,
|
|
28
|
+
chunkSize: number,
|
|
29
|
+
): Promise<AsyncIterable<Uint8Array> | null>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Deletes content by hash.
|
|
33
|
+
*
|
|
34
|
+
* @param projectId The project ID to which the content belongs.
|
|
35
|
+
* @param hash The content hash.
|
|
36
|
+
*/
|
|
37
|
+
delete(projectId: string, hash: string): Promise<void>
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks if content exists by hash.
|
|
41
|
+
*
|
|
42
|
+
* @param projectId The project ID to which the content belongs.
|
|
43
|
+
* @param hash The content hash.
|
|
44
|
+
*/
|
|
45
|
+
exists(projectId: string, hash: string): Promise<boolean>
|
|
46
|
+
}
|