@highstate/backend 0.7.2 → 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} +1254 -915
- 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
@@ -0,0 +1,262 @@
|
|
1
|
+
import { omit } from "remeda"
|
2
|
+
import { z } from "zod"
|
3
|
+
|
4
|
+
export const instanceStatusSchema = z.enum([
|
5
|
+
"not_created",
|
6
|
+
"updating",
|
7
|
+
"previewing",
|
8
|
+
"destroying",
|
9
|
+
"refreshing",
|
10
|
+
"created",
|
11
|
+
"error",
|
12
|
+
"pending",
|
13
|
+
"unknown",
|
14
|
+
])
|
15
|
+
|
16
|
+
export const instanceStatusFieldSchema = z.object({
|
17
|
+
name: z.string(),
|
18
|
+
value: z.string().optional(),
|
19
|
+
displayName: z.string().optional(),
|
20
|
+
sensitive: z.boolean().optional(),
|
21
|
+
url: z.string().optional(),
|
22
|
+
complementaryTo: z.string().optional(),
|
23
|
+
})
|
24
|
+
|
25
|
+
export const instanceFileMetaSchema = z.object({
|
26
|
+
name: z.string(),
|
27
|
+
contentType: z.string(),
|
28
|
+
size: z.number(),
|
29
|
+
isBinary: z.boolean().optional(),
|
30
|
+
})
|
31
|
+
|
32
|
+
export const instanceFileSchema = z.object({
|
33
|
+
meta: instanceFileMetaSchema,
|
34
|
+
content: z.string(),
|
35
|
+
})
|
36
|
+
|
37
|
+
export const instancePageBlockSchema = z.union([
|
38
|
+
z.object({
|
39
|
+
type: z.literal("markdown"),
|
40
|
+
content: z.string(),
|
41
|
+
}),
|
42
|
+
z.object({
|
43
|
+
type: z.literal("qr"),
|
44
|
+
content: z.string(),
|
45
|
+
showContent: z.coerce.boolean(),
|
46
|
+
language: z.string().optional(),
|
47
|
+
}),
|
48
|
+
z.object({
|
49
|
+
type: z.literal("file"),
|
50
|
+
fileMeta: instanceFileMetaSchema,
|
51
|
+
}),
|
52
|
+
])
|
53
|
+
|
54
|
+
export const instancePageMetaSchema = z.object({
|
55
|
+
name: z.string(),
|
56
|
+
title: z.string(),
|
57
|
+
})
|
58
|
+
|
59
|
+
export const instancePageSchema = z.object({
|
60
|
+
...instancePageMetaSchema.shape,
|
61
|
+
content: z.array(instancePageBlockSchema),
|
62
|
+
})
|
63
|
+
|
64
|
+
export const instanceTerminalMetaSchema = z.object({
|
65
|
+
name: z.string(),
|
66
|
+
title: z.string(),
|
67
|
+
description: z.string().optional(),
|
68
|
+
})
|
69
|
+
|
70
|
+
export const instanceTerminalFileSchema = z.object({
|
71
|
+
content: z.string().optional(),
|
72
|
+
isBinary: z.boolean().optional(),
|
73
|
+
mode: z.number().optional(),
|
74
|
+
})
|
75
|
+
|
76
|
+
export const instanceTerminalSchema = z.object({
|
77
|
+
...instanceTerminalMetaSchema.shape,
|
78
|
+
image: z.string(),
|
79
|
+
command: z.string().array(),
|
80
|
+
cwd: z.string().optional(),
|
81
|
+
env: z.record(z.string()).optional(),
|
82
|
+
files: z.record(instanceTerminalFileSchema).optional(),
|
83
|
+
})
|
84
|
+
|
85
|
+
export const instanceTriggerSpecSchema = z.union([
|
86
|
+
z.object({
|
87
|
+
type: z.literal("before-destroy"),
|
88
|
+
}),
|
89
|
+
z.object({
|
90
|
+
type: z.literal("schedule"),
|
91
|
+
schedule: z.string(),
|
92
|
+
}),
|
93
|
+
])
|
94
|
+
|
95
|
+
export const instanceTriggerSchema = z.object({
|
96
|
+
name: z.string(),
|
97
|
+
title: z.string(),
|
98
|
+
description: z.string().optional(),
|
99
|
+
spec: instanceTriggerSpecSchema,
|
100
|
+
})
|
101
|
+
|
102
|
+
export const instanceTriggerInvocationSchema = z.object({
|
103
|
+
name: z.string(),
|
104
|
+
})
|
105
|
+
|
106
|
+
export const instanceStateSchema = z.object({
|
107
|
+
id: z.string(),
|
108
|
+
parentId: z.string().nullable().default(null),
|
109
|
+
status: instanceStatusSchema,
|
110
|
+
dependencyIds: z.array(z.string()).default(() => []),
|
111
|
+
|
112
|
+
latestOperationId: z.string().nullable().default(null),
|
113
|
+
|
114
|
+
currentResourceCount: z.number().nullable().default(null),
|
115
|
+
totalResourceCount: z.number().nullable().default(null),
|
116
|
+
inputHash: z.string().nullable().default(null),
|
117
|
+
outputHash: z.string().nullable().default(null),
|
118
|
+
|
119
|
+
error: z.string().nullable().default(null),
|
120
|
+
evaluationError: z.string().nullable().default(null),
|
121
|
+
|
122
|
+
statusFields: z.array(instanceStatusFieldSchema).default(() => []),
|
123
|
+
files: z.array(instanceFileMetaSchema).default(() => []),
|
124
|
+
pages: z.array(instancePageMetaSchema).default(() => []),
|
125
|
+
terminals: z.array(instanceTerminalMetaSchema).default(() => []),
|
126
|
+
triggers: z.array(instanceTriggerSchema).default(() => []),
|
127
|
+
})
|
128
|
+
|
129
|
+
export const instanceStateUpdateSchema = z
|
130
|
+
.object({
|
131
|
+
...instanceStateSchema.shape,
|
132
|
+
|
133
|
+
// secrets updated by the unit
|
134
|
+
secrets: z.record(z.string()).nullable(),
|
135
|
+
|
136
|
+
// log line emitted by the unit
|
137
|
+
logLine: z.string().nullable(),
|
138
|
+
})
|
139
|
+
.partial()
|
140
|
+
|
141
|
+
export type InstanceStatusField = z.infer<typeof instanceStatusFieldSchema>
|
142
|
+
export type InstanceTerminal = z.infer<typeof instanceTerminalSchema>
|
143
|
+
|
144
|
+
export type InstanceStatus = z.infer<typeof instanceStatusSchema>
|
145
|
+
export type InstanceState = z.infer<typeof instanceStateSchema>
|
146
|
+
|
147
|
+
export type InstanceStateUpdate = z.infer<typeof instanceStateUpdateSchema>
|
148
|
+
|
149
|
+
export type InstancePageBlock = z.infer<typeof instancePageBlockSchema>
|
150
|
+
export type InstancePageMeta = z.infer<typeof instancePageMetaSchema>
|
151
|
+
export type InstanceFileMeta = z.infer<typeof instanceFileMetaSchema>
|
152
|
+
|
153
|
+
export type InstanceTriggerSpec = z.infer<typeof instanceTriggerSpecSchema>
|
154
|
+
export type InstanceTrigger = z.infer<typeof instanceTriggerSchema>
|
155
|
+
export type InstanceTriggerInvocation = z.infer<typeof instanceTriggerInvocationSchema>
|
156
|
+
|
157
|
+
export function createInstanceState(
|
158
|
+
id: string,
|
159
|
+
status: InstanceStatus = "not_created",
|
160
|
+
fields: Partial<InstanceState> = {},
|
161
|
+
): InstanceState {
|
162
|
+
return {
|
163
|
+
id,
|
164
|
+
parentId: null,
|
165
|
+
dependencyIds: [],
|
166
|
+
status: status,
|
167
|
+
|
168
|
+
latestOperationId: null,
|
169
|
+
|
170
|
+
currentResourceCount: null,
|
171
|
+
totalResourceCount: null,
|
172
|
+
inputHash: null,
|
173
|
+
outputHash: null,
|
174
|
+
|
175
|
+
error: null,
|
176
|
+
evaluationError: null,
|
177
|
+
|
178
|
+
statusFields: [],
|
179
|
+
files: [],
|
180
|
+
pages: [],
|
181
|
+
terminals: [],
|
182
|
+
triggers: [],
|
183
|
+
|
184
|
+
...fields,
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
export function applyPartialInstanceState(
|
189
|
+
states: Map<string, InstanceState>,
|
190
|
+
patch: Partial<InstanceState>,
|
191
|
+
): InstanceState {
|
192
|
+
if (!patch.id) {
|
193
|
+
throw new Error("The ID of the instance state is required.")
|
194
|
+
}
|
195
|
+
|
196
|
+
let state = states.get(patch.id) ?? createInstanceState(patch.id, "unknown")
|
197
|
+
state = { ...state, ...patch }
|
198
|
+
|
199
|
+
states.set(state.id, state)
|
200
|
+
return state
|
201
|
+
}
|
202
|
+
|
203
|
+
export function createInstanceStatePatch(update: InstanceStateUpdate): Partial<InstanceState> {
|
204
|
+
return omit(update, ["secrets", "logLine"])
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Builds a map where instance id -> instance state ids that directly depend on the instance.
|
209
|
+
*
|
210
|
+
* @param instanceStates The instance states to build the map from.
|
211
|
+
*/
|
212
|
+
export function buildDependentInstanceStateMap(
|
213
|
+
instanceStates: Map<string, InstanceState>,
|
214
|
+
): Map<string, string[]> {
|
215
|
+
const dependentMap = new Map<string, string[]>()
|
216
|
+
|
217
|
+
for (const state of instanceStates.values()) {
|
218
|
+
for (const dependency of state.dependencyIds) {
|
219
|
+
let dependents = dependentMap.get(dependency)
|
220
|
+
if (!dependents) {
|
221
|
+
dependents = []
|
222
|
+
dependentMap.set(dependency, dependents)
|
223
|
+
}
|
224
|
+
|
225
|
+
dependents.push(state.id)
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
return dependentMap
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Gets all instance ids that depend on the given instance id (including recursively).
|
234
|
+
* The instance id itself is not included in the result.
|
235
|
+
*
|
236
|
+
* @param dependentMap The dependent map.
|
237
|
+
* @param instanceId The instance id to get all dependent instance ids.
|
238
|
+
*/
|
239
|
+
export function getAllDependentInstanceIds(
|
240
|
+
dependentMap: Map<string, string[]>,
|
241
|
+
instanceId: string,
|
242
|
+
): string[] {
|
243
|
+
const result = new Set<string>()
|
244
|
+
const visited = new Set<string>()
|
245
|
+
|
246
|
+
const traverse = (id: string) => {
|
247
|
+
if (visited.has(id)) return
|
248
|
+
visited.add(id)
|
249
|
+
|
250
|
+
const dependents = dependentMap.get(id)
|
251
|
+
if (!dependents) return
|
252
|
+
|
253
|
+
for (const dependent of dependents) {
|
254
|
+
result.add(dependent)
|
255
|
+
traverse(dependent)
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
traverse(instanceId)
|
260
|
+
|
261
|
+
return Array.from(result)
|
262
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { z } from "zod"
|
2
|
+
|
3
|
+
export const terminalSessionSchema = z.object({
|
4
|
+
id: z.string().nanoid(),
|
5
|
+
projectId: z.string(),
|
6
|
+
instanceId: z.string(),
|
7
|
+
terminalName: z.string(),
|
8
|
+
terminalTitle: z.string(),
|
9
|
+
createdAt: z.coerce.date(),
|
10
|
+
finishedAt: z.coerce.date().optional(),
|
11
|
+
})
|
12
|
+
|
13
|
+
export type TerminalSession = z.infer<typeof terminalSessionSchema>
|
@@ -0,0 +1,222 @@
|
|
1
|
+
import {
|
2
|
+
type CompositeInstance,
|
3
|
+
type InstanceState,
|
4
|
+
type ProjectOperation,
|
5
|
+
type TerminalSession,
|
6
|
+
} from "../shared"
|
7
|
+
|
8
|
+
export type LogEntry = [instanceId: string, line: string]
|
9
|
+
export type TerminalHistoryEntry = [sessionId: string, entry: string]
|
10
|
+
|
11
|
+
export interface StateBackend {
|
12
|
+
/**
|
13
|
+
* Gets the active operations which are not completed or failed.
|
14
|
+
*/
|
15
|
+
getActiveOperations(signal?: AbortSignal): Promise<ProjectOperation[]>
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Gets recent operations of the project.
|
19
|
+
* If `beforeOperationId` is provided, returns the operations before the specified operation ID.
|
20
|
+
* The page size is fixed to 10.
|
21
|
+
*
|
22
|
+
* @param projectId The ID of the project.
|
23
|
+
* @param beforeOperationId The ID of the operation to get the operations before.
|
24
|
+
*/
|
25
|
+
getOperations(projectId: string, beforeOperationId?: string): Promise<ProjectOperation[]>
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Gets the current (cached) instance states of the project.
|
29
|
+
* Actual states should be retrieved from the runner (and they are still may not be up-to-date).
|
30
|
+
*
|
31
|
+
* @param projectId The ID of the project.
|
32
|
+
*/
|
33
|
+
getAllInstanceStates(projectId: string, signal?: AbortSignal): Promise<InstanceState[]>
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Gets the current (cached) state of the instance.
|
37
|
+
*
|
38
|
+
* @param projectId The ID of the project.
|
39
|
+
* @param instanceId The ID of the instance.
|
40
|
+
*/
|
41
|
+
getInstanceState(projectId: string, instanceId: string): Promise<InstanceState | null>
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Gets the current (cached) state of the instances.
|
45
|
+
*
|
46
|
+
* @param projectId The ID of the project.
|
47
|
+
* @param instanceIds The IDs of the instances.
|
48
|
+
*/
|
49
|
+
getInstanceStates(projectId: string, instanceIds: string[]): Promise<InstanceState[]>
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Gets the affected instance states at the moment of the operation completion.
|
53
|
+
* The logs are not included.
|
54
|
+
*
|
55
|
+
* @param operationId The ID of the operation.
|
56
|
+
*/
|
57
|
+
getAffectedInstanceStates(operationId: string): Promise<InstanceState[]>
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Gets the full logs of the instance at the moment of the operation completion.
|
61
|
+
*
|
62
|
+
* @param operationId The ID of the operation.
|
63
|
+
* @param instanceId The ID of the instance.
|
64
|
+
*/
|
65
|
+
getInstanceLogs(operationId: string, instanceId: string): Promise<string[]>
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Puts the operation to the state.
|
69
|
+
* The operation must have a unique ID sortable chronologically.
|
70
|
+
* Also, the operation must have the project ID.
|
71
|
+
*
|
72
|
+
* @param operation The operation to put.
|
73
|
+
*/
|
74
|
+
putOperation(operation: ProjectOperation): Promise<void>
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Puts the instance states affected by the operation to the state.
|
78
|
+
*
|
79
|
+
* @param projectId The ID of the project.
|
80
|
+
* @param operationId The ID of the operation.
|
81
|
+
* @param states The instance states to put.
|
82
|
+
*/
|
83
|
+
putAffectedInstanceStates(
|
84
|
+
projectId: string,
|
85
|
+
operationId: string,
|
86
|
+
states: InstanceState[],
|
87
|
+
): Promise<void>
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Puts the instance states of the project to the state.
|
91
|
+
*
|
92
|
+
* @param projectId The ID of the project.
|
93
|
+
* @param states The instance states to put.
|
94
|
+
*/
|
95
|
+
putInstanceStates(projectId: string, states: InstanceState[]): Promise<void>
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Appends the log lines to the instance logs.
|
99
|
+
*
|
100
|
+
* @param operationId The ID of the operation.
|
101
|
+
* @param logs The logs to append. Each log is a tuple of the instance ID and the log line.
|
102
|
+
*/
|
103
|
+
appendInstanceLogs(operationId: string, logs: LogEntry[]): Promise<void>
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Gets all the evaluated composite instances of the project.
|
107
|
+
*
|
108
|
+
* @param projectId The ID of the project.
|
109
|
+
*/
|
110
|
+
getCompositeInstances(projectId: string, signal?: AbortSignal): Promise<CompositeInstance[]>
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Gets the IDs of the composite instances which are children (level 2+) of the top-level composite instances.
|
114
|
+
*
|
115
|
+
* Used to track the evaluated composite instances and clear them when the top-level composite instances are cleared/changed.
|
116
|
+
*
|
117
|
+
* @param projectId The ID of the project.
|
118
|
+
* @param instanceIds The IDs of the top-level composite instances.
|
119
|
+
*/
|
120
|
+
getTopLevelCompositeChildrenIds(
|
121
|
+
projectId: string,
|
122
|
+
instanceIds: string[],
|
123
|
+
signal?: AbortSignal,
|
124
|
+
): Promise<Record<string, string[]>>
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Puts the IDs of the composite instances which are children (level 2+) of the top-level composite instances.
|
128
|
+
*
|
129
|
+
* @param projectId The ID of the project.
|
130
|
+
* @param childrenIds The IDs of the composite instances (key is the top-level instance ID).
|
131
|
+
*/
|
132
|
+
putTopLevelCompositeChildrenIds(
|
133
|
+
projectId: string,
|
134
|
+
childrenIds: Record<string, string[]>,
|
135
|
+
): Promise<void>
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Gets the evaluated composite instance of the project.
|
139
|
+
*
|
140
|
+
* @param projectId The ID of the project.
|
141
|
+
* @param instanceId The ID of the instance.
|
142
|
+
*/
|
143
|
+
getCompositeInstance(projectId: string, instanceId: string): Promise<CompositeInstance | null>
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Gets the input hash of the evaluated composite instance.
|
147
|
+
*
|
148
|
+
* @param projectId The ID of the project.
|
149
|
+
* @param instanceId The ID of the instance.
|
150
|
+
*/
|
151
|
+
getCompositeInstanceInputHash(projectId: string, instanceId: string): Promise<string | null>
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Puts the evaluated composite instances of the project to the state.
|
155
|
+
*
|
156
|
+
* @param projectId The ID of the project.
|
157
|
+
* @param instances The instances to put.
|
158
|
+
*/
|
159
|
+
putCompositeInstances(projectId: string, instances: CompositeInstance[]): Promise<void>
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Clears the evaluation state of the instance.
|
163
|
+
*
|
164
|
+
* @param projectId The ID of the project.
|
165
|
+
* @param instanceIds The IDs of the instances to clear.
|
166
|
+
*/
|
167
|
+
clearCompositeInstances(projectId: string, instanceIds: string[]): Promise<void>
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Gets all the terminal sessions of the instance.
|
171
|
+
*
|
172
|
+
* @param projectId The ID of the project.
|
173
|
+
* @param instanceId The ID of the instance.
|
174
|
+
*/
|
175
|
+
getTerminalSessions(projectId: string, instanceId: string): Promise<TerminalSession[]>
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Gets the IDs of all the active terminal sessions.
|
179
|
+
*/
|
180
|
+
getActiveTerminalSessions(): Promise<TerminalSession[]>
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Puts the IDs of the active terminal sessions.
|
184
|
+
*/
|
185
|
+
putActiveTerminalSessions(sessions: TerminalSession[]): Promise<void>
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Gets the terminal session.
|
189
|
+
*
|
190
|
+
* @param projectId The ID of the project.
|
191
|
+
* @param instanceId The ID of the instance.
|
192
|
+
* @param sessionId The ID of the session.
|
193
|
+
*/
|
194
|
+
getTerminalSession(
|
195
|
+
projectId: string,
|
196
|
+
instanceId: string,
|
197
|
+
sessionId: string,
|
198
|
+
): Promise<TerminalSession | null>
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Puts the terminal sessions of the instance to the state.
|
202
|
+
*
|
203
|
+
* @param projectId The ID of the project.
|
204
|
+
* @param instanceId The ID of the instance.
|
205
|
+
* @param session The terminal session to put.
|
206
|
+
*/
|
207
|
+
putTerminalSession(projectId: string, instanceId: string, session: TerminalSession): Promise<void>
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Gets the history lines of the terminal session.
|
211
|
+
*
|
212
|
+
* @param sessionId The ID of the session.
|
213
|
+
*/
|
214
|
+
getTerminalSessionHistory(sessionId: string): Promise<string[]>
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Appends the history lines to the terminal sessions.
|
218
|
+
*
|
219
|
+
* @param entries The entries to append.
|
220
|
+
*/
|
221
|
+
appendTerminalSessionHistory(entries: TerminalHistoryEntry[]): Promise<void>
|
222
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { StateBackend } from "./abstractions"
|
2
|
+
import type { Logger } from "pino"
|
3
|
+
import type { LocalPulumiHost } from "../common"
|
4
|
+
import { z } from "zod"
|
5
|
+
import { LocalStateBackend, localStateBackendConfig } from "./local"
|
6
|
+
|
7
|
+
export const stateBackendConfig = z.object({
|
8
|
+
HIGHSTATE_BACKEND_STATE_TYPE: z.enum(["local"]).default("local"),
|
9
|
+
...localStateBackendConfig.shape,
|
10
|
+
})
|
11
|
+
|
12
|
+
export function createStateBackend(
|
13
|
+
config: z.infer<typeof stateBackendConfig>,
|
14
|
+
localPulumiHost: LocalPulumiHost,
|
15
|
+
logger: Logger,
|
16
|
+
): Promise<StateBackend> {
|
17
|
+
switch (config.HIGHSTATE_BACKEND_STATE_TYPE) {
|
18
|
+
case "local": {
|
19
|
+
return LocalStateBackend.create(config, localPulumiHost, logger)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|