@highstate/backend 0.9.14 → 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 +6146 -2174
- package/dist/index.js.map +1 -1
- package/dist/library/worker/main.js +51 -159
- package/dist/library/worker/main.js.map +1 -1
- package/dist/shared/index.js +159 -43
- 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 +14 -47
- 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 +131 -82
- package/src/orchestrator/operation-workset.ts +188 -77
- package/src/orchestrator/operation.ts +975 -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 -372
- 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} +43 -8
- 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 +74 -13
- 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 +7 -2
- package/src/shared/resolvers/state.ts +12 -0
- 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 +134 -80
- package/src/terminal/run.sh.ts +22 -10
- 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-C2TJAQAD.js +0 -937
- package/dist/chunk-C2TJAQAD.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 -270
- package/src/shared/terminal.ts +0 -13
- 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
package/dist/chunk-C2TJAQAD.js
DELETED
|
@@ -1,937 +0,0 @@
|
|
|
1
|
-
// src/shared/project.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var positionSchema = z.object({
|
|
4
|
-
x: z.number(),
|
|
5
|
-
y: z.number()
|
|
6
|
-
});
|
|
7
|
-
var instanceInputSchema = z.object({
|
|
8
|
-
instanceId: z.string(),
|
|
9
|
-
output: z.string()
|
|
10
|
-
});
|
|
11
|
-
var hubInstanceInputSchema = z.object({
|
|
12
|
-
hubId: z.string()
|
|
13
|
-
});
|
|
14
|
-
var instanceModelPatchSchema = z.object({
|
|
15
|
-
args: z.record(z.unknown()).optional(),
|
|
16
|
-
inputs: z.record(z.array(instanceInputSchema)).optional(),
|
|
17
|
-
hubInputs: z.record(z.array(hubInstanceInputSchema)).optional(),
|
|
18
|
-
injectionInputs: z.array(hubInstanceInputSchema).optional(),
|
|
19
|
-
position: positionSchema.optional()
|
|
20
|
-
});
|
|
21
|
-
var instanceModelSchema = z.object({
|
|
22
|
-
id: z.string(),
|
|
23
|
-
type: z.string(),
|
|
24
|
-
name: z.string(),
|
|
25
|
-
...instanceModelPatchSchema.shape,
|
|
26
|
-
resolvedInputs: z.record(z.array(instanceInputSchema)).optional(),
|
|
27
|
-
parentId: z.string().optional(),
|
|
28
|
-
outputs: z.record(z.array(instanceInputSchema)).optional(),
|
|
29
|
-
resolvedOutputs: z.record(z.array(instanceInputSchema)).optional()
|
|
30
|
-
});
|
|
31
|
-
var compositeInstanceSchema = z.object({
|
|
32
|
-
instance: instanceModelSchema,
|
|
33
|
-
children: z.array(instanceModelSchema),
|
|
34
|
-
inputHash: z.string().optional()
|
|
35
|
-
});
|
|
36
|
-
var hubModelPatchSchema = z.object({
|
|
37
|
-
position: positionSchema.optional(),
|
|
38
|
-
inputs: z.array(instanceInputSchema).optional(),
|
|
39
|
-
injectionInputs: z.array(hubInstanceInputSchema).optional()
|
|
40
|
-
});
|
|
41
|
-
var hubModelSchema = z.object({
|
|
42
|
-
id: z.string().nanoid(),
|
|
43
|
-
position: positionSchema,
|
|
44
|
-
inputs: z.array(instanceInputSchema).optional(),
|
|
45
|
-
injectionInputs: z.array(hubInstanceInputSchema).optional()
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// src/shared/state.ts
|
|
49
|
-
import { omit } from "remeda";
|
|
50
|
-
import { z as z2 } from "zod";
|
|
51
|
-
var instanceStatusSchema = z2.enum([
|
|
52
|
-
"not_created",
|
|
53
|
-
"updating",
|
|
54
|
-
"previewing",
|
|
55
|
-
"destroying",
|
|
56
|
-
"refreshing",
|
|
57
|
-
"created",
|
|
58
|
-
"error",
|
|
59
|
-
"pending",
|
|
60
|
-
"unknown"
|
|
61
|
-
]);
|
|
62
|
-
var instanceStatusFieldValueSchema = z2.union([
|
|
63
|
-
z2.string(),
|
|
64
|
-
z2.number(),
|
|
65
|
-
z2.boolean(),
|
|
66
|
-
z2.array(z2.string())
|
|
67
|
-
]);
|
|
68
|
-
var instanceStatusFieldSchema = z2.object({
|
|
69
|
-
name: z2.string(),
|
|
70
|
-
value: instanceStatusFieldValueSchema.optional(),
|
|
71
|
-
displayName: z2.string().optional(),
|
|
72
|
-
sensitive: z2.boolean().optional(),
|
|
73
|
-
url: z2.string().optional(),
|
|
74
|
-
complementaryTo: z2.string().optional()
|
|
75
|
-
});
|
|
76
|
-
var instanceFileMetaSchema = z2.object({
|
|
77
|
-
name: z2.string(),
|
|
78
|
-
contentType: z2.string(),
|
|
79
|
-
size: z2.number(),
|
|
80
|
-
isBinary: z2.boolean().optional()
|
|
81
|
-
});
|
|
82
|
-
var instanceFileSchema = z2.object({
|
|
83
|
-
meta: instanceFileMetaSchema,
|
|
84
|
-
content: z2.string()
|
|
85
|
-
});
|
|
86
|
-
var instancePageBlockSchema = z2.union([
|
|
87
|
-
z2.object({
|
|
88
|
-
type: z2.literal("markdown"),
|
|
89
|
-
content: z2.string()
|
|
90
|
-
}),
|
|
91
|
-
z2.object({
|
|
92
|
-
type: z2.literal("qr"),
|
|
93
|
-
content: z2.string(),
|
|
94
|
-
showContent: z2.coerce.boolean(),
|
|
95
|
-
language: z2.string().optional()
|
|
96
|
-
}),
|
|
97
|
-
z2.object({
|
|
98
|
-
type: z2.literal("file"),
|
|
99
|
-
fileMeta: instanceFileMetaSchema
|
|
100
|
-
})
|
|
101
|
-
]);
|
|
102
|
-
var instancePageMetaSchema = z2.object({
|
|
103
|
-
name: z2.string(),
|
|
104
|
-
title: z2.string()
|
|
105
|
-
});
|
|
106
|
-
var instancePageSchema = z2.object({
|
|
107
|
-
...instancePageMetaSchema.shape,
|
|
108
|
-
content: z2.array(instancePageBlockSchema)
|
|
109
|
-
});
|
|
110
|
-
var instanceTerminalMetaSchema = z2.object({
|
|
111
|
-
name: z2.string(),
|
|
112
|
-
title: z2.string(),
|
|
113
|
-
description: z2.string().optional()
|
|
114
|
-
});
|
|
115
|
-
var instanceTerminalFileSchema = z2.object({
|
|
116
|
-
content: z2.string().optional(),
|
|
117
|
-
isBinary: z2.boolean().optional(),
|
|
118
|
-
mode: z2.number().optional()
|
|
119
|
-
});
|
|
120
|
-
var instanceTerminalSchema = z2.object({
|
|
121
|
-
...instanceTerminalMetaSchema.shape,
|
|
122
|
-
image: z2.string(),
|
|
123
|
-
command: z2.string().array(),
|
|
124
|
-
cwd: z2.string().optional(),
|
|
125
|
-
env: z2.record(z2.string()).optional(),
|
|
126
|
-
files: z2.record(instanceTerminalFileSchema).optional()
|
|
127
|
-
});
|
|
128
|
-
var instanceTriggerSpecSchema = z2.union([
|
|
129
|
-
z2.object({
|
|
130
|
-
type: z2.literal("before-destroy")
|
|
131
|
-
}),
|
|
132
|
-
z2.object({
|
|
133
|
-
type: z2.literal("schedule"),
|
|
134
|
-
schedule: z2.string()
|
|
135
|
-
})
|
|
136
|
-
]);
|
|
137
|
-
var instanceTriggerSchema = z2.object({
|
|
138
|
-
name: z2.string(),
|
|
139
|
-
title: z2.string(),
|
|
140
|
-
description: z2.string().optional(),
|
|
141
|
-
spec: instanceTriggerSpecSchema
|
|
142
|
-
});
|
|
143
|
-
var instanceTriggerInvocationSchema = z2.object({
|
|
144
|
-
name: z2.string()
|
|
145
|
-
});
|
|
146
|
-
var instanceStateSchema = z2.object({
|
|
147
|
-
id: z2.string(),
|
|
148
|
-
parentId: z2.string().nullable().default(null),
|
|
149
|
-
status: instanceStatusSchema,
|
|
150
|
-
dependencyIds: z2.array(z2.string()).default(() => []),
|
|
151
|
-
latestOperationId: z2.string().nullable().default(null),
|
|
152
|
-
currentResourceCount: z2.number().nullable().default(null),
|
|
153
|
-
totalResourceCount: z2.number().nullable().default(null),
|
|
154
|
-
inputHash: z2.string().nullable().default(null),
|
|
155
|
-
outputHash: z2.string().nullable().default(null),
|
|
156
|
-
error: z2.string().nullable().default(null),
|
|
157
|
-
evaluationError: z2.string().nullable().default(null),
|
|
158
|
-
statusFields: z2.array(instanceStatusFieldSchema).default(() => []),
|
|
159
|
-
files: z2.array(instanceFileMetaSchema).default(() => []),
|
|
160
|
-
pages: z2.array(instancePageMetaSchema).default(() => []),
|
|
161
|
-
terminals: z2.array(instanceTerminalMetaSchema).default(() => []),
|
|
162
|
-
triggers: z2.array(instanceTriggerSchema).default(() => [])
|
|
163
|
-
});
|
|
164
|
-
var instanceStateUpdateSchema = z2.object({
|
|
165
|
-
...instanceStateSchema.shape,
|
|
166
|
-
// secrets updated by the unit
|
|
167
|
-
secrets: z2.record(z2.string()).nullable(),
|
|
168
|
-
// log line emitted by the unit
|
|
169
|
-
logLine: z2.string().nullable()
|
|
170
|
-
}).partial();
|
|
171
|
-
function createInstanceState(id, status = "not_created", fields = {}) {
|
|
172
|
-
return {
|
|
173
|
-
id,
|
|
174
|
-
parentId: null,
|
|
175
|
-
dependencyIds: [],
|
|
176
|
-
status,
|
|
177
|
-
latestOperationId: null,
|
|
178
|
-
currentResourceCount: null,
|
|
179
|
-
totalResourceCount: null,
|
|
180
|
-
inputHash: null,
|
|
181
|
-
outputHash: null,
|
|
182
|
-
error: null,
|
|
183
|
-
evaluationError: null,
|
|
184
|
-
statusFields: [],
|
|
185
|
-
files: [],
|
|
186
|
-
pages: [],
|
|
187
|
-
terminals: [],
|
|
188
|
-
triggers: [],
|
|
189
|
-
...fields
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function applyPartialInstanceState(states, patch) {
|
|
193
|
-
if (!patch.id) {
|
|
194
|
-
throw new Error("The ID of the instance state is required.");
|
|
195
|
-
}
|
|
196
|
-
let state = states.get(patch.id) ?? createInstanceState(patch.id, "unknown");
|
|
197
|
-
state = { ...state, ...patch };
|
|
198
|
-
states.set(state.id, state);
|
|
199
|
-
return state;
|
|
200
|
-
}
|
|
201
|
-
function createInstanceStatePatch(update) {
|
|
202
|
-
return omit(update, ["secrets", "logLine"]);
|
|
203
|
-
}
|
|
204
|
-
function buildDependentInstanceStateMap(instanceStates) {
|
|
205
|
-
const dependentMap = /* @__PURE__ */ new Map();
|
|
206
|
-
for (const state of instanceStates.values()) {
|
|
207
|
-
for (const dependency of state.dependencyIds) {
|
|
208
|
-
let dependents = dependentMap.get(dependency);
|
|
209
|
-
if (!dependents) {
|
|
210
|
-
dependents = [];
|
|
211
|
-
dependentMap.set(dependency, dependents);
|
|
212
|
-
}
|
|
213
|
-
dependents.push(state.id);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return dependentMap;
|
|
217
|
-
}
|
|
218
|
-
function getAllDependentInstanceIds(dependentMap, instanceId) {
|
|
219
|
-
const result = /* @__PURE__ */ new Set();
|
|
220
|
-
const visited = /* @__PURE__ */ new Set();
|
|
221
|
-
const traverse = (id) => {
|
|
222
|
-
if (visited.has(id)) return;
|
|
223
|
-
visited.add(id);
|
|
224
|
-
const dependents = dependentMap.get(id);
|
|
225
|
-
if (!dependents) return;
|
|
226
|
-
for (const dependent of dependents) {
|
|
227
|
-
result.add(dependent);
|
|
228
|
-
traverse(dependent);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
traverse(instanceId);
|
|
232
|
-
return Array.from(result);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// src/shared/operation.ts
|
|
236
|
-
import { z as z3 } from "zod";
|
|
237
|
-
var operationTypeSchema = z3.enum(["update", "preview", "destroy", "recreate", "refresh"]);
|
|
238
|
-
var operationStatusSchema = z3.enum([
|
|
239
|
-
"pending",
|
|
240
|
-
"running",
|
|
241
|
-
"completed",
|
|
242
|
-
"failed",
|
|
243
|
-
"cancelled"
|
|
244
|
-
]);
|
|
245
|
-
var operationOptionsSchema = z3.object({
|
|
246
|
-
/**
|
|
247
|
-
* Whether to force update all dependencies of the instances even if they are not changed.
|
|
248
|
-
*
|
|
249
|
-
* Only applicable for `update`, `preview`, `recreate`, and `refresh` operations.
|
|
250
|
-
* By default, `false`.
|
|
251
|
-
*/
|
|
252
|
-
forceUpdateDependencies: z3.boolean().default(false),
|
|
253
|
-
/**
|
|
254
|
-
* Whether to force update all children of the composite instances even if they are not changed.
|
|
255
|
-
*
|
|
256
|
-
* Only applicable for `update`, `preview`, `recreate`, and `refresh` operations.
|
|
257
|
-
* By default, `false`.
|
|
258
|
-
*/
|
|
259
|
-
forceUpdateChildren: z3.boolean().default(false),
|
|
260
|
-
/**
|
|
261
|
-
* Whether to destroy all dependents of the instances when destroying them.
|
|
262
|
-
*
|
|
263
|
-
* Only applicable for `destroy`.
|
|
264
|
-
* By default, `true`.
|
|
265
|
-
*/
|
|
266
|
-
destroyDependentInstances: z3.boolean().default(true),
|
|
267
|
-
/**
|
|
268
|
-
* Whether to invoke destroy triggers when destroying the instances.
|
|
269
|
-
*
|
|
270
|
-
* Only applicable for `destroy`.
|
|
271
|
-
* By default, `true`.
|
|
272
|
-
*/
|
|
273
|
-
invokeDestroyTriggers: z3.boolean().default(true),
|
|
274
|
-
/**
|
|
275
|
-
* Whether to delete unreachable resources when updating or destroying the instances.
|
|
276
|
-
* This is potentially dangerous and should be used with caution.
|
|
277
|
-
*
|
|
278
|
-
* By default, `false`.
|
|
279
|
-
*/
|
|
280
|
-
deleteUnreachableResources: z3.boolean().default(false),
|
|
281
|
-
/**
|
|
282
|
-
* Whether to delete the stack state even if the destroy operation fails.
|
|
283
|
-
* This is very dangerous and should be used only when the stack is unrecoverable.
|
|
284
|
-
*
|
|
285
|
-
* By default, `false`.
|
|
286
|
-
*/
|
|
287
|
-
forceDeleteState: z3.boolean().default(false),
|
|
288
|
-
/**
|
|
289
|
-
* Whether to refresh the state before running the operation.
|
|
290
|
-
*
|
|
291
|
-
* By default, `false`.
|
|
292
|
-
*/
|
|
293
|
-
refresh: z3.boolean().default(false)
|
|
294
|
-
});
|
|
295
|
-
var projectOperationRequestSchema = z3.object({
|
|
296
|
-
projectId: z3.string(),
|
|
297
|
-
type: operationTypeSchema,
|
|
298
|
-
instanceIds: z3.array(z3.string()),
|
|
299
|
-
options: operationOptionsSchema.partial().optional()
|
|
300
|
-
});
|
|
301
|
-
var projectOperationSchema = z3.object({
|
|
302
|
-
id: z3.string().uuid(),
|
|
303
|
-
status: operationStatusSchema,
|
|
304
|
-
projectId: z3.string(),
|
|
305
|
-
type: operationTypeSchema,
|
|
306
|
-
requestedInstanceIds: z3.array(z3.string()),
|
|
307
|
-
instanceIdsToUpdate: z3.array(z3.string()).default(() => []),
|
|
308
|
-
instanceIdsToDestroy: z3.array(z3.string()).default(() => []),
|
|
309
|
-
options: operationOptionsSchema.default(() => ({})),
|
|
310
|
-
error: z3.string().nullable(),
|
|
311
|
-
startedAt: z3.number(),
|
|
312
|
-
completedAt: z3.number().nullable()
|
|
313
|
-
});
|
|
314
|
-
function isFinalOperationStatus(status) {
|
|
315
|
-
return status === "completed" || status === "failed" || status === "cancelled";
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// src/shared/resolvers/graph-resolver.ts
|
|
319
|
-
import { unique } from "remeda";
|
|
320
|
-
var GraphResolver = class {
|
|
321
|
-
constructor(nodes, logger, outputHandler) {
|
|
322
|
-
this.nodes = nodes;
|
|
323
|
-
this.logger = logger;
|
|
324
|
-
this.outputHandler = outputHandler;
|
|
325
|
-
}
|
|
326
|
-
workset = /* @__PURE__ */ new Set();
|
|
327
|
-
dependentMap = /* @__PURE__ */ new Map();
|
|
328
|
-
outputMap = /* @__PURE__ */ new Map();
|
|
329
|
-
addToWorkset(nodeId) {
|
|
330
|
-
this.workset.add(nodeId);
|
|
331
|
-
}
|
|
332
|
-
addAllNodesToWorkset() {
|
|
333
|
-
for (const nodeId of this.nodes.keys()) {
|
|
334
|
-
this.workset.add(nodeId);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* The map of calculated outputs.
|
|
339
|
-
*/
|
|
340
|
-
get outputs() {
|
|
341
|
-
return this.outputMap;
|
|
342
|
-
}
|
|
343
|
-
requireOutput(nodeId) {
|
|
344
|
-
const output = this.outputMap.get(nodeId);
|
|
345
|
-
if (!output) {
|
|
346
|
-
throw new Error(`Output for node ${nodeId} is not available`);
|
|
347
|
-
}
|
|
348
|
-
return output;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Invalidates the node and all nodes that depend on it.
|
|
352
|
-
*
|
|
353
|
-
* Also adds the node to the work set for processing.
|
|
354
|
-
*/
|
|
355
|
-
invalidate(nodeId) {
|
|
356
|
-
const stack = [nodeId];
|
|
357
|
-
while (stack.length > 0) {
|
|
358
|
-
const nodeId2 = stack.pop();
|
|
359
|
-
if (!this.nodes.has(nodeId2)) {
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
this.outputMap.delete(nodeId2);
|
|
363
|
-
this.workset.add(nodeId2);
|
|
364
|
-
const dependents = this.dependentMap.get(nodeId2);
|
|
365
|
-
if (!dependents) {
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
for (const dependentId of dependents) {
|
|
369
|
-
if (this.outputMap.has(dependentId)) {
|
|
370
|
-
stack.push(dependentId);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
this.dependentMap.delete(nodeId2);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Resolves all not-resolved or invalidated nodes in the graph.
|
|
378
|
-
*
|
|
379
|
-
* The abort signal of the previous operation must be called before calling this method again.
|
|
380
|
-
*/
|
|
381
|
-
async process(signal) {
|
|
382
|
-
while (this.workset.size > 0) {
|
|
383
|
-
const rootNodeId = this.workset.values().next().value;
|
|
384
|
-
const stack = [{ nodeId: rootNodeId, resolved: false, dependencies: [] }];
|
|
385
|
-
while (stack.length > 0) {
|
|
386
|
-
const stackItem = stack[stack.length - 1];
|
|
387
|
-
const { nodeId, resolved } = stackItem;
|
|
388
|
-
const node = this.nodes.get(nodeId);
|
|
389
|
-
if (!node) {
|
|
390
|
-
this.logger.warn({ nodeId }, "node not found in the graph, skipping");
|
|
391
|
-
stack.pop();
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (this.outputMap.has(nodeId)) {
|
|
395
|
-
stack.pop();
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (!resolved) {
|
|
399
|
-
stackItem.dependencies = unique(this.getNodeDependencies(node));
|
|
400
|
-
let hasUnresolvedDependencies = false;
|
|
401
|
-
for (const depId of stackItem.dependencies) {
|
|
402
|
-
if (!this.nodes.has(depId)) {
|
|
403
|
-
this.logger.warn({ depId, nodeId }, "dependency not found in the graph, skipping");
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
if (!this.outputMap.has(depId)) {
|
|
407
|
-
stack.push({ nodeId: depId, resolved: false, dependencies: [] });
|
|
408
|
-
hasUnresolvedDependencies = true;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
if (hasUnresolvedDependencies) {
|
|
412
|
-
stackItem.resolved = true;
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const output = await this.processNode(node, this.logger);
|
|
417
|
-
if (signal?.aborted) {
|
|
418
|
-
this.logger.warn({ nodeId }, "processing aborted, skipping output");
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
for (const depId of stackItem.dependencies) {
|
|
422
|
-
let dependantSet = this.dependentMap.get(depId);
|
|
423
|
-
if (!dependantSet) {
|
|
424
|
-
dependantSet = /* @__PURE__ */ new Set();
|
|
425
|
-
this.dependentMap.set(depId, dependantSet);
|
|
426
|
-
}
|
|
427
|
-
dependantSet.add(nodeId);
|
|
428
|
-
}
|
|
429
|
-
this.outputMap.set(nodeId, output);
|
|
430
|
-
this.outputHandler?.(nodeId, output);
|
|
431
|
-
stack.pop();
|
|
432
|
-
}
|
|
433
|
-
this.workset.delete(rootNodeId);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
// src/shared/resolvers/input.ts
|
|
439
|
-
import {
|
|
440
|
-
isUnitModel
|
|
441
|
-
} from "@highstate/contract";
|
|
442
|
-
import { fromEntries, mapValues } from "remeda";
|
|
443
|
-
var InputResolver = class extends GraphResolver {
|
|
444
|
-
// constructor(
|
|
445
|
-
// nodes: ReadonlyMap<string, InputResolverNode>,
|
|
446
|
-
// logger: Logger,
|
|
447
|
-
// outputHandler?: ResolverOutputHandler<InputResolverOutput>,
|
|
448
|
-
// ) {
|
|
449
|
-
// super(nodes, logger, outputHandler)
|
|
450
|
-
// }
|
|
451
|
-
getNodeDependencies(node) {
|
|
452
|
-
const dependencies = [];
|
|
453
|
-
if (node.kind === "hub") {
|
|
454
|
-
for (const input of node.hub.inputs ?? []) {
|
|
455
|
-
dependencies.push(`instance:${input.instanceId}`);
|
|
456
|
-
}
|
|
457
|
-
for (const input of node.hub.injectionInputs ?? []) {
|
|
458
|
-
dependencies.push(`hub:${input.hubId}`);
|
|
459
|
-
}
|
|
460
|
-
return dependencies;
|
|
461
|
-
}
|
|
462
|
-
for (const inputs of Object.values(node.instance.inputs ?? {})) {
|
|
463
|
-
for (const input of inputs) {
|
|
464
|
-
dependencies.push(`instance:${input.instanceId}`);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
for (const inputs of Object.values(node.instance.hubInputs ?? {})) {
|
|
468
|
-
for (const input of inputs) {
|
|
469
|
-
dependencies.push(`hub:${input.hubId}`);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
for (const input of node.instance.injectionInputs ?? []) {
|
|
473
|
-
dependencies.push(`hub:${input.hubId}`);
|
|
474
|
-
}
|
|
475
|
-
return dependencies;
|
|
476
|
-
}
|
|
477
|
-
processNode(node) {
|
|
478
|
-
const getHubOutput = (input) => {
|
|
479
|
-
const output = this.outputs.get(`hub:${input.hubId}`);
|
|
480
|
-
if (!output) {
|
|
481
|
-
return { resolvedInputs: [] };
|
|
482
|
-
}
|
|
483
|
-
if (output.kind !== "hub") {
|
|
484
|
-
throw new Error("Expected hub node");
|
|
485
|
-
}
|
|
486
|
-
return output;
|
|
487
|
-
};
|
|
488
|
-
const getInstanceOutput = (input) => {
|
|
489
|
-
const output = this.outputs.get(`instance:${input.instanceId}`);
|
|
490
|
-
if (!output) {
|
|
491
|
-
return {
|
|
492
|
-
component: null,
|
|
493
|
-
resolvedInputs: [],
|
|
494
|
-
resolvedOutputs: []
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
if (output.kind !== "instance") {
|
|
498
|
-
throw new Error("Expected instance node");
|
|
499
|
-
}
|
|
500
|
-
return {
|
|
501
|
-
component: output.component,
|
|
502
|
-
resolvedInputs: output.resolvedInputs[input.output] ?? [],
|
|
503
|
-
resolvedOutputs: output.resolvedOutputs?.[input.output]
|
|
504
|
-
};
|
|
505
|
-
};
|
|
506
|
-
if (node.kind === "hub") {
|
|
507
|
-
const hubResult = /* @__PURE__ */ new Map();
|
|
508
|
-
const addHubResult = (input) => {
|
|
509
|
-
hubResult.set(`${input.input.instanceId}:${input.input.output}`, input);
|
|
510
|
-
};
|
|
511
|
-
for (const input of node.hub.inputs ?? []) {
|
|
512
|
-
const { component } = getInstanceOutput(input);
|
|
513
|
-
const componentInput = component?.outputs[input.output];
|
|
514
|
-
if (!componentInput) {
|
|
515
|
-
this.logger.warn({ msg: "output not found in the component", input, component });
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
addHubResult({ input, type: componentInput.type });
|
|
519
|
-
}
|
|
520
|
-
for (const injectionInput of node.hub.injectionInputs ?? []) {
|
|
521
|
-
const { resolvedInputs: resolvedInputs2 } = getHubOutput(injectionInput);
|
|
522
|
-
for (const input of resolvedInputs2) {
|
|
523
|
-
addHubResult(input);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return {
|
|
527
|
-
kind: "hub",
|
|
528
|
-
resolvedInputs: Array.from(hubResult.values())
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
if (node.instance.resolvedInputs) {
|
|
532
|
-
return {
|
|
533
|
-
kind: "instance",
|
|
534
|
-
instance: node.instance,
|
|
535
|
-
component: node.component,
|
|
536
|
-
resolvedInputs: mapValues(node.instance.resolvedInputs, (inputs, inputName) => {
|
|
537
|
-
const componentInput = node.component.inputs[inputName];
|
|
538
|
-
if (!componentInput) {
|
|
539
|
-
this.logger.warn({
|
|
540
|
-
msg: "input not found in the component",
|
|
541
|
-
inputName,
|
|
542
|
-
component: node.component
|
|
543
|
-
});
|
|
544
|
-
return [];
|
|
545
|
-
}
|
|
546
|
-
return inputs.map((input) => ({ input, type: componentInput.type }));
|
|
547
|
-
}),
|
|
548
|
-
resolvedOutputs: node.instance.resolvedOutputs ?? {},
|
|
549
|
-
resolvedInjectionInputs: [],
|
|
550
|
-
matchedInjectionInputs: []
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
const resolvedInputsMap = /* @__PURE__ */ new Map();
|
|
554
|
-
const addInstanceResult = (inputName, input) => {
|
|
555
|
-
let inputs = resolvedInputsMap.get(inputName);
|
|
556
|
-
if (!inputs) {
|
|
557
|
-
inputs = /* @__PURE__ */ new Map();
|
|
558
|
-
resolvedInputsMap.set(inputName, inputs);
|
|
559
|
-
}
|
|
560
|
-
inputs.set(`${input.input.instanceId}:${input.input.output}`, input);
|
|
561
|
-
};
|
|
562
|
-
const addInstanceInput = (inputName, input) => {
|
|
563
|
-
const componentInput = node.component.inputs[inputName];
|
|
564
|
-
if (!componentInput) {
|
|
565
|
-
this.logger.warn({
|
|
566
|
-
msg: "input not found in the component",
|
|
567
|
-
input,
|
|
568
|
-
component: node.component
|
|
569
|
-
});
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const { component, resolvedOutputs } = getInstanceOutput(input);
|
|
573
|
-
if (!component) {
|
|
574
|
-
this.logger.warn({ instanceId: node.instance.id, input }, "no output found for the input");
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
if (isUnitModel(component)) {
|
|
578
|
-
addInstanceResult(inputName, { input, type: componentInput.type });
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
if (resolvedOutputs) {
|
|
582
|
-
for (const output of resolvedOutputs) {
|
|
583
|
-
addInstanceResult(inputName, { input: output, type: componentInput.type });
|
|
584
|
-
}
|
|
585
|
-
} else {
|
|
586
|
-
addInstanceResult(inputName, { input, type: componentInput.type });
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
for (const [inputName, inputs] of Object.entries(node.instance.inputs ?? {})) {
|
|
590
|
-
for (const input of inputs) {
|
|
591
|
-
addInstanceInput(inputName, input);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
const injectionInputs = /* @__PURE__ */ new Map();
|
|
595
|
-
const matchedInjectionInputs = /* @__PURE__ */ new Map();
|
|
596
|
-
for (const injectionInput of node.instance.injectionInputs ?? []) {
|
|
597
|
-
const { resolvedInputs: resolvedInputs2 } = getHubOutput(injectionInput);
|
|
598
|
-
for (const input of resolvedInputs2) {
|
|
599
|
-
injectionInputs.set(`${input.input.instanceId}:${input.input.output}`, input);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
for (const [inputName, componentInput] of Object.entries(node.component.inputs ?? {})) {
|
|
603
|
-
const allInputs = new Map(injectionInputs);
|
|
604
|
-
const hubInputs = node.instance.hubInputs?.[inputName] ?? [];
|
|
605
|
-
for (const hubInput of hubInputs) {
|
|
606
|
-
const { resolvedInputs: resolvedInputs2 } = getHubOutput(hubInput);
|
|
607
|
-
for (const input of resolvedInputs2) {
|
|
608
|
-
allInputs.set(`${input.input.instanceId}:${input.input.output}`, input);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
for (const input of allInputs.values()) {
|
|
612
|
-
if (input.type === componentInput.type) {
|
|
613
|
-
addInstanceInput(inputName, input.input);
|
|
614
|
-
const key = `${input.input.instanceId}:${input.input.output}`;
|
|
615
|
-
if (injectionInputs.has(key)) {
|
|
616
|
-
matchedInjectionInputs.set(key, input);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
const resolvedInputs = fromEntries(
|
|
622
|
-
Array.from(resolvedInputsMap.entries()).map(([inputName, inputs]) => [
|
|
623
|
-
inputName,
|
|
624
|
-
Array.from(inputs.values())
|
|
625
|
-
])
|
|
626
|
-
);
|
|
627
|
-
return {
|
|
628
|
-
kind: "instance",
|
|
629
|
-
instance: node.instance,
|
|
630
|
-
component: node.component,
|
|
631
|
-
resolvedInputs,
|
|
632
|
-
resolvedOutputs: node.instance.resolvedOutputs,
|
|
633
|
-
resolvedInjectionInputs: Array.from(injectionInputs.values()),
|
|
634
|
-
matchedInjectionInputs: Array.from(matchedInjectionInputs.values())
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
function getResolvedHubInputs(output) {
|
|
639
|
-
if (output.kind !== "hub") {
|
|
640
|
-
throw new Error("Expected hub node");
|
|
641
|
-
}
|
|
642
|
-
return output.resolvedInputs;
|
|
643
|
-
}
|
|
644
|
-
function getResolvedInstanceInputs(output) {
|
|
645
|
-
if (output.kind !== "instance") {
|
|
646
|
-
throw new Error("Expected instance node");
|
|
647
|
-
}
|
|
648
|
-
return output.resolvedInputs;
|
|
649
|
-
}
|
|
650
|
-
function getResolvedInjectionInstanceInputs(output) {
|
|
651
|
-
if (output.kind !== "instance") {
|
|
652
|
-
throw new Error("Expected instance node");
|
|
653
|
-
}
|
|
654
|
-
return output.resolvedInjectionInputs;
|
|
655
|
-
}
|
|
656
|
-
function getMatchedInjectionInstanceInputs(output) {
|
|
657
|
-
if (output.kind !== "instance") {
|
|
658
|
-
throw new Error("Expected instance node");
|
|
659
|
-
}
|
|
660
|
-
return output.matchedInjectionInputs;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// src/shared/resolvers/input-hash.ts
|
|
664
|
-
import { isUnitModel as isUnitModel2 } from "@highstate/contract";
|
|
665
|
-
import { sha256 } from "crypto-hash";
|
|
666
|
-
var InputHashResolver = class extends GraphResolver {
|
|
667
|
-
getNodeDependencies({ resolvedInputs }) {
|
|
668
|
-
const dependencies = [];
|
|
669
|
-
for (const inputs of Object.values(resolvedInputs ?? {})) {
|
|
670
|
-
for (const input of inputs) {
|
|
671
|
-
dependencies.push(input.input.instanceId);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
return dependencies;
|
|
675
|
-
}
|
|
676
|
-
async processNode({
|
|
677
|
-
instance,
|
|
678
|
-
component,
|
|
679
|
-
resolvedInputs,
|
|
680
|
-
sourceHash,
|
|
681
|
-
state
|
|
682
|
-
}) {
|
|
683
|
-
let sink = component.definitionHash + JSON.stringify(instance.args ?? {});
|
|
684
|
-
if (sourceHash) {
|
|
685
|
-
sink += sourceHash;
|
|
686
|
-
} else if (isUnitModel2(component)) {
|
|
687
|
-
this.logger.warn(
|
|
688
|
-
{ instanceId: instance.id },
|
|
689
|
-
"missing source hash for unit model, this may lead to incorrect input hash"
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
const sortedInputs = Object.entries(resolvedInputs).sort(([a], [b]) => a.localeCompare(b));
|
|
693
|
-
for (const [inputKey, inputs] of sortedInputs) {
|
|
694
|
-
if (Object.keys(inputs).length === 0) {
|
|
695
|
-
continue;
|
|
696
|
-
}
|
|
697
|
-
sink += inputKey;
|
|
698
|
-
const instanceIds = inputs.map((input) => input.input.instanceId);
|
|
699
|
-
instanceIds.sort();
|
|
700
|
-
for (const instanceId of instanceIds) {
|
|
701
|
-
const dependency = this.outputs.get(instanceId);
|
|
702
|
-
if (!dependency) continue;
|
|
703
|
-
sink += dependency.inputHash;
|
|
704
|
-
sink += dependency.outputHash;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
return {
|
|
708
|
-
inputHash: await sha256(sink),
|
|
709
|
-
outputHash: state?.outputHash ?? ""
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// src/shared/resolvers/validation.ts
|
|
715
|
-
import { Ajv } from "ajv";
|
|
716
|
-
var ValidationResolver = class extends GraphResolver {
|
|
717
|
-
getNodeDependencies({ resolvedInputs }) {
|
|
718
|
-
const dependencies = [];
|
|
719
|
-
for (const inputs of Object.values(resolvedInputs)) {
|
|
720
|
-
for (const input of inputs) {
|
|
721
|
-
dependencies.push(input.input.instanceId);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
return dependencies;
|
|
725
|
-
}
|
|
726
|
-
processNode({ instance, component, resolvedInputs }) {
|
|
727
|
-
const ajv = new Ajv({ strict: false });
|
|
728
|
-
this.logger.debug({ instanceId: instance.id }, "validating instance");
|
|
729
|
-
for (const [name, argument] of Object.entries(component.args)) {
|
|
730
|
-
if (!argument.required && !instance.args?.[name]) {
|
|
731
|
-
continue;
|
|
732
|
-
}
|
|
733
|
-
if (!ajv.validate(argument.schema, instance.args?.[name])) {
|
|
734
|
-
this.logger.debug({ instanceId: instance.id, argumentName: name }, "invalid argument");
|
|
735
|
-
return {
|
|
736
|
-
status: "invalid-args",
|
|
737
|
-
errorText: `invalid argument "${name}": ${ajv.errorsText()}`
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
for (const inputs of Object.values(resolvedInputs)) {
|
|
742
|
-
for (const input of inputs) {
|
|
743
|
-
const inputInstance = this.outputs.get(input.input.instanceId);
|
|
744
|
-
if (inputInstance?.status !== "ok") {
|
|
745
|
-
return {
|
|
746
|
-
status: "invalid-inputs",
|
|
747
|
-
errorText: `instance "${input.input.instanceId}" has errors`
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
for (const [name, input] of Object.entries(component.inputs)) {
|
|
753
|
-
if (!input.required) {
|
|
754
|
-
continue;
|
|
755
|
-
}
|
|
756
|
-
if (!resolvedInputs[name] || !resolvedInputs[name].length) {
|
|
757
|
-
return {
|
|
758
|
-
status: "missing-inputs",
|
|
759
|
-
errorText: `input "${name}" is missing`
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return { status: "ok" };
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
// src/shared/resolvers/registry.ts
|
|
768
|
-
var resolverFactories = {
|
|
769
|
-
InputResolver,
|
|
770
|
-
InputHashResolver,
|
|
771
|
-
ValidationResolver
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
// src/shared/terminal.ts
|
|
775
|
-
import { z as z4 } from "zod";
|
|
776
|
-
var terminalSessionSchema = z4.object({
|
|
777
|
-
id: z4.string().nanoid(),
|
|
778
|
-
projectId: z4.string(),
|
|
779
|
-
instanceId: z4.string(),
|
|
780
|
-
terminalName: z4.string(),
|
|
781
|
-
terminalTitle: z4.string(),
|
|
782
|
-
createdAt: z4.coerce.date(),
|
|
783
|
-
finishedAt: z4.coerce.date().optional()
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
// src/shared/library.ts
|
|
787
|
-
function diffLibraries(oldLibrary, newLibrary) {
|
|
788
|
-
const updates = [];
|
|
789
|
-
for (const [componentType, newComponent] of Object.entries(newLibrary.components)) {
|
|
790
|
-
const existingComponent = oldLibrary.components[componentType];
|
|
791
|
-
if (existingComponent?.definitionHash !== newComponent.definitionHash) {
|
|
792
|
-
updates.push({ type: "component-updated", component: newComponent });
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
for (const componentType of Object.keys(oldLibrary.components)) {
|
|
796
|
-
if (!newLibrary.components[componentType]) {
|
|
797
|
-
updates.push({ type: "component-removed", componentType });
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
for (const [entityType, newEntity] of Object.entries(newLibrary.entities)) {
|
|
801
|
-
const existingEntity = oldLibrary.entities[entityType];
|
|
802
|
-
if (existingEntity?.definitionHash !== newEntity.definitionHash) {
|
|
803
|
-
updates.push({ type: "entity-updated", entity: newEntity });
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
for (const entityType of Object.keys(oldLibrary.entities)) {
|
|
807
|
-
if (!newLibrary.entities[entityType]) {
|
|
808
|
-
updates.push({ type: "entity-removed", entityType });
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return updates;
|
|
812
|
-
}
|
|
813
|
-
function applyLibraryUpdate(components, entities, update) {
|
|
814
|
-
switch (update.type) {
|
|
815
|
-
case "component-updated":
|
|
816
|
-
components[update.component.type] = update.component;
|
|
817
|
-
break;
|
|
818
|
-
case "entity-updated":
|
|
819
|
-
entities[update.entity.type] = update.entity;
|
|
820
|
-
break;
|
|
821
|
-
case "component-removed":
|
|
822
|
-
delete components[update.componentType];
|
|
823
|
-
break;
|
|
824
|
-
case "entity-removed":
|
|
825
|
-
delete entities[update.entityType];
|
|
826
|
-
break;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// src/shared/async-batcher.ts
|
|
831
|
-
function createAsyncBatcher(fn, { waitMs = 100, maxWaitTimeMs = 1e3 } = {}) {
|
|
832
|
-
let batch = [];
|
|
833
|
-
let activeTimeout = null;
|
|
834
|
-
let maxWaitTimeout = null;
|
|
835
|
-
let firstCallTimestamp = null;
|
|
836
|
-
async function processBatch() {
|
|
837
|
-
if (batch.length === 0) return;
|
|
838
|
-
const currentBatch = batch;
|
|
839
|
-
batch = [];
|
|
840
|
-
await fn(currentBatch);
|
|
841
|
-
if (maxWaitTimeout) {
|
|
842
|
-
clearTimeout(maxWaitTimeout);
|
|
843
|
-
maxWaitTimeout = null;
|
|
844
|
-
}
|
|
845
|
-
firstCallTimestamp = null;
|
|
846
|
-
}
|
|
847
|
-
function schedule() {
|
|
848
|
-
if (activeTimeout) clearTimeout(activeTimeout);
|
|
849
|
-
activeTimeout = setTimeout(() => {
|
|
850
|
-
activeTimeout = null;
|
|
851
|
-
void processBatch();
|
|
852
|
-
}, waitMs);
|
|
853
|
-
if (!firstCallTimestamp) {
|
|
854
|
-
firstCallTimestamp = Date.now();
|
|
855
|
-
maxWaitTimeout = setTimeout(() => {
|
|
856
|
-
if (activeTimeout) clearTimeout(activeTimeout);
|
|
857
|
-
activeTimeout = null;
|
|
858
|
-
void processBatch();
|
|
859
|
-
}, maxWaitTimeMs);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return {
|
|
863
|
-
/**
|
|
864
|
-
* Add an item to the batch.
|
|
865
|
-
*/
|
|
866
|
-
call(item) {
|
|
867
|
-
batch.push(item);
|
|
868
|
-
schedule();
|
|
869
|
-
},
|
|
870
|
-
/**
|
|
871
|
-
* Immediately flush the pending batch (if any).
|
|
872
|
-
*/
|
|
873
|
-
async flush() {
|
|
874
|
-
if (activeTimeout) {
|
|
875
|
-
clearTimeout(activeTimeout);
|
|
876
|
-
activeTimeout = null;
|
|
877
|
-
}
|
|
878
|
-
if (maxWaitTimeout) {
|
|
879
|
-
clearTimeout(maxWaitTimeout);
|
|
880
|
-
maxWaitTimeout = null;
|
|
881
|
-
}
|
|
882
|
-
await processBatch();
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
export {
|
|
888
|
-
positionSchema,
|
|
889
|
-
instanceInputSchema,
|
|
890
|
-
hubInstanceInputSchema,
|
|
891
|
-
instanceModelPatchSchema,
|
|
892
|
-
instanceModelSchema,
|
|
893
|
-
compositeInstanceSchema,
|
|
894
|
-
hubModelPatchSchema,
|
|
895
|
-
hubModelSchema,
|
|
896
|
-
instanceStatusSchema,
|
|
897
|
-
instanceStatusFieldValueSchema,
|
|
898
|
-
instanceStatusFieldSchema,
|
|
899
|
-
instanceFileMetaSchema,
|
|
900
|
-
instanceFileSchema,
|
|
901
|
-
instancePageBlockSchema,
|
|
902
|
-
instancePageMetaSchema,
|
|
903
|
-
instancePageSchema,
|
|
904
|
-
instanceTerminalMetaSchema,
|
|
905
|
-
instanceTerminalFileSchema,
|
|
906
|
-
instanceTerminalSchema,
|
|
907
|
-
instanceTriggerSpecSchema,
|
|
908
|
-
instanceTriggerSchema,
|
|
909
|
-
instanceTriggerInvocationSchema,
|
|
910
|
-
instanceStateSchema,
|
|
911
|
-
instanceStateUpdateSchema,
|
|
912
|
-
createInstanceState,
|
|
913
|
-
applyPartialInstanceState,
|
|
914
|
-
createInstanceStatePatch,
|
|
915
|
-
buildDependentInstanceStateMap,
|
|
916
|
-
getAllDependentInstanceIds,
|
|
917
|
-
operationTypeSchema,
|
|
918
|
-
operationStatusSchema,
|
|
919
|
-
operationOptionsSchema,
|
|
920
|
-
projectOperationRequestSchema,
|
|
921
|
-
projectOperationSchema,
|
|
922
|
-
isFinalOperationStatus,
|
|
923
|
-
GraphResolver,
|
|
924
|
-
InputResolver,
|
|
925
|
-
getResolvedHubInputs,
|
|
926
|
-
getResolvedInstanceInputs,
|
|
927
|
-
getResolvedInjectionInstanceInputs,
|
|
928
|
-
getMatchedInjectionInstanceInputs,
|
|
929
|
-
InputHashResolver,
|
|
930
|
-
ValidationResolver,
|
|
931
|
-
resolverFactories,
|
|
932
|
-
terminalSessionSchema,
|
|
933
|
-
diffLibraries,
|
|
934
|
-
applyLibraryUpdate,
|
|
935
|
-
createAsyncBatcher
|
|
936
|
-
};
|
|
937
|
-
//# sourceMappingURL=chunk-C2TJAQAD.js.map
|