@sixb/cli 0.0.1
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/LICENSE +21 -0
- package/README.md +275 -0
- package/dist/commands/access-token-utils.d.ts +9 -0
- package/dist/commands/access-token-utils.d.ts.map +1 -0
- package/dist/commands/api.d.ts +13 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/app.d.ts +9 -0
- package/dist/commands/app.d.ts.map +1 -0
- package/dist/commands/atlas.d.ts +9 -0
- package/dist/commands/atlas.d.ts.map +1 -0
- package/dist/commands/auth.d.ts +8 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/build.d.ts +6 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/check.d.ts +5 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/db-migrate.d.ts +5 -0
- package/dist/commands/db-migrate.d.ts.map +1 -0
- package/dist/commands/dev.d.ts +12 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/lake-check.d.ts +5 -0
- package/dist/commands/lake-check.d.ts.map +1 -0
- package/dist/commands/lake-cleanup.d.ts +16 -0
- package/dist/commands/lake-cleanup.d.ts.map +1 -0
- package/dist/commands/orchestrator.d.ts +6 -0
- package/dist/commands/orchestrator.d.ts.map +1 -0
- package/dist/commands/rules.d.ts +6 -0
- package/dist/commands/rules.d.ts.map +1 -0
- package/dist/commands/scheduler.d.ts +6 -0
- package/dist/commands/scheduler.d.ts.map +1 -0
- package/dist/commands/service-account.d.ts +14 -0
- package/dist/commands/service-account.d.ts.map +1 -0
- package/dist/commands/token.d.ts +14 -0
- package/dist/commands/token.d.ts.map +1 -0
- package/dist/commands/typegen.d.ts +5 -0
- package/dist/commands/typegen.d.ts.map +1 -0
- package/dist/commands/worker-group.d.ts +8 -0
- package/dist/commands/worker-group.d.ts.map +1 -0
- package/dist/commands/worker.d.ts +8 -0
- package/dist/commands/worker.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/api-client.d.ts +26 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/browser-topology.d.ts +62 -0
- package/dist/lib/browser-topology.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +19 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/health.d.ts +25 -0
- package/dist/lib/health.d.ts.map +1 -0
- package/dist/lib/loadSixb.d.ts +49 -0
- package/dist/lib/loadSixb.d.ts.map +1 -0
- package/dist/lib/production-roles.d.ts +65 -0
- package/dist/lib/production-roles.d.ts.map +1 -0
- package/dist/lib/production.d.ts +29 -0
- package/dist/lib/production.d.ts.map +1 -0
- package/dist/lib/public-origin.d.ts +17 -0
- package/dist/lib/public-origin.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts +76 -0
- package/dist/lib/runtime.d.ts.map +1 -0
- package/dist/lib/shareable-providers.d.ts +20 -0
- package/dist/lib/shareable-providers.d.ts.map +1 -0
- package/dist/lib/storage-migration.d.ts +40 -0
- package/dist/lib/storage-migration.d.ts.map +1 -0
- package/dist/lib/typegen.d.ts +5 -0
- package/dist/lib/typegen.d.ts.map +1 -0
- package/dist/lib/worker-registry.d.ts +30 -0
- package/dist/lib/worker-registry.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/ui/index.d.ts +164 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/commands/access-token-utils.ts +63 -0
- package/src/commands/api.tsx +111 -0
- package/src/commands/app.tsx +91 -0
- package/src/commands/atlas.tsx +75 -0
- package/src/commands/auth.tsx +96 -0
- package/src/commands/build.tsx +90 -0
- package/src/commands/check.tsx +58 -0
- package/src/commands/db-migrate.tsx +27 -0
- package/src/commands/dev.tsx +141 -0
- package/src/commands/init.tsx +18 -0
- package/src/commands/lake-check.tsx +20 -0
- package/src/commands/lake-cleanup.tsx +63 -0
- package/src/commands/orchestrator.tsx +87 -0
- package/src/commands/rules.tsx +81 -0
- package/src/commands/scheduler.tsx +77 -0
- package/src/commands/service-account.tsx +304 -0
- package/src/commands/token.tsx +143 -0
- package/src/commands/typegen.tsx +18 -0
- package/src/commands/worker-group.tsx +120 -0
- package/src/commands/worker.tsx +96 -0
- package/src/index.tsx +390 -0
- package/src/lib/api-client.ts +132 -0
- package/src/lib/browser-topology.ts +292 -0
- package/src/lib/errors.ts +40 -0
- package/src/lib/health.ts +138 -0
- package/src/lib/loadSixb.ts +175 -0
- package/src/lib/production-roles.ts +48 -0
- package/src/lib/production.ts +104 -0
- package/src/lib/public-origin.ts +46 -0
- package/src/lib/runtime.ts +346 -0
- package/src/lib/shareable-providers.ts +67 -0
- package/src/lib/storage-migration.ts +120 -0
- package/src/lib/typegen.ts +12 -0
- package/src/lib/worker-registry.ts +191 -0
- package/src/ui/index.tsx +953 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ActionWorker } from "@sixb/action-worker"
|
|
2
|
+
import { AgentWorker } from "@sixb/agent-worker"
|
|
3
|
+
import type { Worker } from "@sixb/core/internal/workers"
|
|
4
|
+
import { PipelineWorker } from "@sixb/pipeline-worker"
|
|
5
|
+
import { ProjectionWorker } from "@sixb/projection-worker"
|
|
6
|
+
import { SyncWorker } from "@sixb/sync-worker"
|
|
7
|
+
import { WorkflowWorker } from "@sixb/workflow-worker"
|
|
8
|
+
import { SixbCliError } from "./errors"
|
|
9
|
+
import type { LoadedSixb } from "./loadSixb"
|
|
10
|
+
import { configuredOrigin } from "./public-origin"
|
|
11
|
+
|
|
12
|
+
export interface WorkerCreationOptions {
|
|
13
|
+
readonly agentApiBaseUrl?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface WorkerFactory {
|
|
17
|
+
readonly create: (sixb: LoadedSixb, options: WorkerCreationOptions) => Worker
|
|
18
|
+
/**
|
|
19
|
+
* Why this worker cannot be constructed with the given options, or `null` when it can.
|
|
20
|
+
* Asked before anything is constructed, so a group names every reason at once.
|
|
21
|
+
*
|
|
22
|
+
* A malformed input throws instead of answering: it is one bad value rather than one
|
|
23
|
+
* unsatisfied worker, and the list of workers it took down would say nothing about it.
|
|
24
|
+
*/
|
|
25
|
+
readonly unmetRequirement?: (options: WorkerCreationOptions) => string | null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const AGENT_ORIGIN_REQUIRED =
|
|
29
|
+
"requires --api-public-origin or SIXB_API_PUBLIC_ORIGIN (agent workers call the API)"
|
|
30
|
+
|
|
31
|
+
const workerFactories: Record<string, WorkerFactory> = {
|
|
32
|
+
sync: {
|
|
33
|
+
create: (sixb) => new SyncWorker(sixb),
|
|
34
|
+
},
|
|
35
|
+
action: {
|
|
36
|
+
create: (sixb) => new ActionWorker(sixb),
|
|
37
|
+
},
|
|
38
|
+
agent: {
|
|
39
|
+
create: (sixb, options) =>
|
|
40
|
+
new AgentWorker(sixb, {
|
|
41
|
+
apiBaseUrl: resolveAgentApiBaseUrl(options.agentApiBaseUrl),
|
|
42
|
+
}),
|
|
43
|
+
unmetRequirement: (options) =>
|
|
44
|
+
agentApiBaseUrl(options.agentApiBaseUrl) ? null : AGENT_ORIGIN_REQUIRED,
|
|
45
|
+
},
|
|
46
|
+
pipeline: {
|
|
47
|
+
create: (sixb) => new PipelineWorker(sixb),
|
|
48
|
+
},
|
|
49
|
+
projection: {
|
|
50
|
+
create: (sixb) => new ProjectionWorker(sixb),
|
|
51
|
+
},
|
|
52
|
+
workflow: {
|
|
53
|
+
create: (sixb) => new WorkflowWorker(sixb),
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createWorkerForType(
|
|
58
|
+
sixb: LoadedSixb,
|
|
59
|
+
workerType: string,
|
|
60
|
+
options: WorkerCreationOptions = {}
|
|
61
|
+
): Worker {
|
|
62
|
+
const factory = workerFactories[workerType]
|
|
63
|
+
if (!factory) {
|
|
64
|
+
throw new Error(`[SixbWorker] Unknown worker '${workerType}'. Available: ${knownWorkers()}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return factory.create(sixb, options)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function resolveWorkerTypeToStart(requestedWorker?: string): string {
|
|
71
|
+
if (!requestedWorker) {
|
|
72
|
+
throw new Error(`[SixbWorker] Usage: sixb worker <${knownWorkers().replaceAll(", ", "|")}>`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!workerFactories[requestedWorker]) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`[SixbWorker] Unknown worker '${requestedWorker}'. Available: ${knownWorkers()}`
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return requestedWorker
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Why this worker cannot be constructed with these options, or `null` when it can. Exported
|
|
86
|
+
* for `sixb worker`, which has to answer this before it migrates storage.
|
|
87
|
+
*/
|
|
88
|
+
export function unmetWorkerRequirement(
|
|
89
|
+
workerType: string,
|
|
90
|
+
options: WorkerCreationOptions
|
|
91
|
+
): string | null {
|
|
92
|
+
return workerFactories[workerType]?.unmetRequirement?.(options) ?? null
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface WorkerGroupInputs {
|
|
96
|
+
readonly workerTypes: readonly string[]
|
|
97
|
+
readonly options: WorkerCreationOptions
|
|
98
|
+
/**
|
|
99
|
+
* Whether the types were auto-selected rather than named on the command line. It changes the
|
|
100
|
+
* remedy only: an auto-selected type can also be dropped by naming the rest.
|
|
101
|
+
*/
|
|
102
|
+
readonly autoSelected: boolean
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Refuses a worker group that cannot start whole, naming every reason at once.
|
|
107
|
+
*
|
|
108
|
+
* Five of six workers means jobs piling up in a queue nobody claims, which looks exactly like
|
|
109
|
+
* an idle system — so the refusal is right, and it has to say which workers it took down.
|
|
110
|
+
*/
|
|
111
|
+
export function assertWorkerInputs(input: WorkerGroupInputs): void {
|
|
112
|
+
const unmet = input.workerTypes
|
|
113
|
+
.map((workerType) => ({
|
|
114
|
+
workerType,
|
|
115
|
+
reason: unmetWorkerRequirement(workerType, input.options),
|
|
116
|
+
}))
|
|
117
|
+
.filter((entry): entry is { workerType: string; reason: string } => entry.reason !== null)
|
|
118
|
+
|
|
119
|
+
if (unmet.length === 0) return
|
|
120
|
+
|
|
121
|
+
const blocked = unmet.map((entry) => `${entry.workerType} ${entry.reason}`).join("; ")
|
|
122
|
+
const ready = input.workerTypes.filter(
|
|
123
|
+
(workerType) => !unmet.some((entry) => entry.workerType === workerType)
|
|
124
|
+
)
|
|
125
|
+
const readyNote =
|
|
126
|
+
ready.length > 0
|
|
127
|
+
? ` No worker started, including the ${ready.length} that were ready (${ready.join(", ")}).`
|
|
128
|
+
: ""
|
|
129
|
+
// Only when there is something to name: with every auto-selected worker blocked, this
|
|
130
|
+
// offered the command that had just failed as the way out of its own failure.
|
|
131
|
+
const remediation =
|
|
132
|
+
input.autoSelected && ready.length > 0
|
|
133
|
+
? `These were selected automatically from what the project registers. Fix the above, or ` +
|
|
134
|
+
`name the workers you want: \`sixb worker-group ${ready.join(" ")}\`.`
|
|
135
|
+
: undefined
|
|
136
|
+
|
|
137
|
+
throw new SixbCliError(`[SixbCLI] \`sixb worker-group\` cannot start: ${blocked}.${readyNote}`, {
|
|
138
|
+
remediation,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function resolveRegisteredWorkerTypes(sixb: LoadedSixb): readonly string[] {
|
|
143
|
+
const workerTypes: string[] = []
|
|
144
|
+
|
|
145
|
+
if (sixb.listSyncs().length > 0) {
|
|
146
|
+
workerTypes.push("sync")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (sixb.listPipelines().length > 0) {
|
|
150
|
+
workerTypes.push("pipeline")
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (
|
|
154
|
+
sixb.listObjectProjections().length +
|
|
155
|
+
sixb.listLinkProjections().length +
|
|
156
|
+
sixb.listTelemetryProjections().length >
|
|
157
|
+
0
|
|
158
|
+
) {
|
|
159
|
+
workerTypes.push("projection")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (sixb.listActions().length > 0) {
|
|
163
|
+
workerTypes.push("action")
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (sixb.agents.list().length > 0 && sixb.storage.agents) {
|
|
167
|
+
workerTypes.push("agent")
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (sixb.workflows.list().length > 0) {
|
|
171
|
+
workerTypes.push("workflow")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return workerTypes
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function knownWorkers(): string {
|
|
178
|
+
return Object.keys(workerFactories).join(", ")
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function agentApiBaseUrl(value: string | undefined): string | null {
|
|
182
|
+
return configuredOrigin(value, "SIXB_API_PUBLIC_ORIGIN", "API public origin")
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function resolveAgentApiBaseUrl(value: string | undefined): string {
|
|
186
|
+
const apiBaseUrl = agentApiBaseUrl(value)
|
|
187
|
+
if (!apiBaseUrl) {
|
|
188
|
+
throw new Error(`[SixbWorker] The agent worker ${AGENT_ORIGIN_REQUIRED}.`)
|
|
189
|
+
}
|
|
190
|
+
return apiBaseUrl
|
|
191
|
+
}
|