@dokebi/cli 0.4.90 → 0.4.91
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/AI.md +11 -9
- package/catalog.json +6 -6
- package/dist/bin.js +19 -5
- package/dist/capability-guide.js +1 -0
- package/dist/commands.js +21 -9
- package/dist/config-edit.d.ts +13 -3
- package/dist/config-edit.js +54 -17
- package/dist/config-paths.d.ts +3 -1
- package/dist/config-paths.js +26 -5
- package/dist/config-show.d.ts +11 -1
- package/dist/config-show.js +11 -2
- package/dist/configuration.d.ts +6 -1
- package/dist/configuration.js +6 -2
- package/dist/deploy-templates.d.ts +12 -2
- package/dist/deploy-templates.js +42 -20
- package/dist/deploy.js +13 -3
- package/dist/log-writer.js +20 -6
- package/dist/output.d.ts +1 -1
- package/dist/output.js +1 -1
- package/dist/process-set.d.ts +1 -0
- package/dist/process-set.js +161 -0
- package/dist/process-tags.d.ts +10 -0
- package/dist/process-tags.js +31 -0
- package/dist/processes.d.ts +38 -0
- package/dist/processes.js +182 -0
- package/dist/project-inspector.js +46 -0
- package/dist/project-state.d.ts +6 -0
- package/dist/project-state.js +12 -1
- package/dist/project.d.ts +6 -2
- package/dist/project.js +46 -17
- package/dist/server.d.ts +8 -0
- package/dist/server.js +215 -32
- package/package.json +2 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// D-0251: what tells the processes of one folder apart without loading the settings code (the log
|
|
2
|
+
// writer and process-set import this): the variable naming the process, and their tagged lines.
|
|
3
|
+
/** The variable naming the process (as @dokebi/config's PROCESS_VARIABLE). */
|
|
4
|
+
export const PROCESS_VARIABLE = 'DOKEBI_PROCESS';
|
|
5
|
+
/**
|
|
6
|
+
* A line of process `name`'s output with its name: a JSON record gets a leading `"process"` field
|
|
7
|
+
* (no parse: the record's own fields follow, so a record that names a process keeps its own),
|
|
8
|
+
* anything else a `[name] ` prefix.
|
|
9
|
+
*/
|
|
10
|
+
export function tagLine(name, line) {
|
|
11
|
+
if (line.startsWith('{"'))
|
|
12
|
+
return `{"process":${JSON.stringify(name)},${line.slice(1)}`;
|
|
13
|
+
if (line.startsWith('{}'))
|
|
14
|
+
return `{"process":${JSON.stringify(name)}}${line.slice(2)}`;
|
|
15
|
+
if (line.length === 0 || line === '\n')
|
|
16
|
+
return line;
|
|
17
|
+
return `[${name}] ${line}`;
|
|
18
|
+
}
|
|
19
|
+
/** Whole lines of process `name` (a LineBuffer's output), each tagged (tagLine). */
|
|
20
|
+
export function tagLines(name, data) {
|
|
21
|
+
const text = data.toString('utf8');
|
|
22
|
+
let out = '';
|
|
23
|
+
let from = 0;
|
|
24
|
+
while (from < text.length) {
|
|
25
|
+
const end = text.indexOf('\n', from);
|
|
26
|
+
const line = end < 0 ? text.slice(from) : text.slice(from, end + 1);
|
|
27
|
+
out += tagLine(name, line);
|
|
28
|
+
from = end < 0 ? text.length : end + 1;
|
|
29
|
+
}
|
|
30
|
+
return Buffer.from(out, 'utf8');
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { PROCESS_VARIABLE, tagLine, tagLines } from './process-tags.js';
|
|
2
|
+
type Options = Record<string, unknown>;
|
|
3
|
+
export interface ProcessSet {
|
|
4
|
+
/** The processes this folder starts (`run`), in order. */
|
|
5
|
+
readonly run: readonly string[];
|
|
6
|
+
/** Every process the file declares, in order. */
|
|
7
|
+
readonly declared: readonly string[];
|
|
8
|
+
/** The options each declared process gets: the shared ones with its own merged in. */
|
|
9
|
+
readonly options: ReadonlyMap<string, Options>;
|
|
10
|
+
/** The shared `options` alone. */
|
|
11
|
+
readonly shared: Options;
|
|
12
|
+
}
|
|
13
|
+
/** The process set of a settings source; undefined when it declares no processes. */
|
|
14
|
+
export declare function processSetOf(source: string): ProcessSet | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The process set of the settings file the app reads (DOKEBI_CONFIG, else dokebi.yaml); undefined
|
|
17
|
+
* when it declares none or is not there. An invalid file is INVALID_CONFIG.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readProcessSet(root: string): Promise<ProcessSet | undefined>;
|
|
20
|
+
/** The process set, or undefined when the file cannot be read or parsed (doctor reports that). */
|
|
21
|
+
export declare function processSetOrNone(root: string): Promise<ProcessSet | undefined>;
|
|
22
|
+
/** Whether a process with these options opens its web port (D-0221: `listen: false` does not). */
|
|
23
|
+
export declare function listens(options: Options): boolean;
|
|
24
|
+
/** The first process of `run` that opens its web port: the one dev and start show and probe. */
|
|
25
|
+
export declare function webProcess(set: ProcessSet): string | undefined;
|
|
26
|
+
/** One finding about the process set, for doctor and start. */
|
|
27
|
+
export interface ProcessIssue {
|
|
28
|
+
readonly code: string;
|
|
29
|
+
readonly severity: 'error' | 'warning';
|
|
30
|
+
readonly message: string;
|
|
31
|
+
readonly fix: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What the declared processes leave undone or do twice. Only work of a plugin the file configures
|
|
35
|
+
* is judged (a section in the shared options or in a process); a process of `processes` that
|
|
36
|
+
* `run` leaves out runs elsewhere (another folder whose `run` names it) and counts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function processIssues(set: ProcessSet): ProcessIssue[];
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// D-0251: the processes one dokebi.yaml declares (`processes.<name>.options`, what each changes
|
|
2
|
+
// from the shared `options`) and the ones this folder starts (`run`). dev and start start one
|
|
3
|
+
// `node src/main.ts` per process of `run` with DOKEBI_PROCESS set; @dokebi/config gives each
|
|
4
|
+
// process its own options. Here: the options of every declared process, which one serves the web,
|
|
5
|
+
// what the set leaves undone (a queue no process takes, two processes on one port), and the
|
|
6
|
+
// `process` field that tells their log lines apart.
|
|
7
|
+
import { ConfigError, parseConfig } from '@dokebi/config';
|
|
8
|
+
import { readProjectSettings } from './configuration.js';
|
|
9
|
+
import { debug, describeError, isMissing } from './diagnostics.js';
|
|
10
|
+
import { CliError } from './errors.js';
|
|
11
|
+
export { PROCESS_VARIABLE, tagLine, tagLines } from './process-tags.js';
|
|
12
|
+
/** The process set of a settings source; undefined when it declares no processes. */
|
|
13
|
+
export function processSetOf(source) {
|
|
14
|
+
const shared = parseConfig(source, undefined, { process: null });
|
|
15
|
+
if (!shared.processes || !shared.run)
|
|
16
|
+
return undefined;
|
|
17
|
+
const options = new Map();
|
|
18
|
+
for (const name of shared.processes)
|
|
19
|
+
options.set(name, parseConfig(source, undefined, { process: name }).options);
|
|
20
|
+
return {
|
|
21
|
+
run: shared.run,
|
|
22
|
+
declared: shared.processes,
|
|
23
|
+
options,
|
|
24
|
+
shared: shared.options,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The process set of the settings file the app reads (DOKEBI_CONFIG, else dokebi.yaml); undefined
|
|
29
|
+
* when it declares none or is not there. An invalid file is INVALID_CONFIG.
|
|
30
|
+
*/
|
|
31
|
+
export async function readProcessSet(root) {
|
|
32
|
+
let source;
|
|
33
|
+
try {
|
|
34
|
+
source = (await readProjectSettings(root)).source;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (isMissing(error))
|
|
38
|
+
return undefined;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return processSetOf(source);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (!(error instanceof ConfigError))
|
|
46
|
+
throw error;
|
|
47
|
+
throw new CliError('INVALID_CONFIG', `Invalid settings file: ${error.message}`, {
|
|
48
|
+
cause: error,
|
|
49
|
+
details: {
|
|
50
|
+
code: error.code,
|
|
51
|
+
line: error.line ?? null,
|
|
52
|
+
column: error.column ?? null,
|
|
53
|
+
fix: error.fix,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The process set, or undefined when the file cannot be read or parsed (doctor reports that). */
|
|
59
|
+
export async function processSetOrNone(root) {
|
|
60
|
+
try {
|
|
61
|
+
return await readProcessSet(root);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
debug('Process set not read; one process', { error: describeError(error) });
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function section(options, key) {
|
|
69
|
+
const value = options[key];
|
|
70
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
71
|
+
? value
|
|
72
|
+
: {};
|
|
73
|
+
}
|
|
74
|
+
/** Whether a process with these options opens its web port (D-0221: `listen: false` does not). */
|
|
75
|
+
export function listens(options) {
|
|
76
|
+
return section(options, 'dokebi-web').listen !== false;
|
|
77
|
+
}
|
|
78
|
+
/** The first process of `run` that opens its web port: the one dev and start show and probe. */
|
|
79
|
+
export function webProcess(set) {
|
|
80
|
+
return set.run.find((name) => listens(set.options.get(name) ?? {}));
|
|
81
|
+
}
|
|
82
|
+
function names(list) {
|
|
83
|
+
return list.join(', ');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What the declared processes leave undone or do twice. Only work of a plugin the file configures
|
|
87
|
+
* is judged (a section in the shared options or in a process); a process of `processes` that
|
|
88
|
+
* `run` leaves out runs elsewhere (another folder whose `run` names it) and counts.
|
|
89
|
+
*/
|
|
90
|
+
export function processIssues(set) {
|
|
91
|
+
const issues = [];
|
|
92
|
+
const declared = set.declared;
|
|
93
|
+
const of = (name) => set.options.get(name) ?? {};
|
|
94
|
+
const configured = (key) => declared.some((name) => Object.hasOwn(of(name), key));
|
|
95
|
+
// Two processes of this folder on one port: the second one's start fails (EADDRINUSE).
|
|
96
|
+
const ports = new Map();
|
|
97
|
+
for (const name of configured('dokebi-web') ? set.run : []) {
|
|
98
|
+
const options = of(name);
|
|
99
|
+
if (!listens(options))
|
|
100
|
+
continue;
|
|
101
|
+
const web = section(options, 'dokebi-web');
|
|
102
|
+
const port = typeof web.port === 'number' ? web.port : 3000;
|
|
103
|
+
if (port === 0)
|
|
104
|
+
continue;
|
|
105
|
+
const host = typeof web.host === 'string' ? web.host : '';
|
|
106
|
+
const key = `${host}:${port}`;
|
|
107
|
+
ports.set(key, [...(ports.get(key) ?? []), name]);
|
|
108
|
+
}
|
|
109
|
+
for (const [key, list] of ports)
|
|
110
|
+
if (list.length > 1)
|
|
111
|
+
issues.push({
|
|
112
|
+
code: 'PROCESS_PORT_SHARED',
|
|
113
|
+
severity: 'error',
|
|
114
|
+
message: `Processes ${names(list)} both listen on port ${key.slice(key.lastIndexOf(':') + 1)}; the second one cannot start`,
|
|
115
|
+
fix: `keep one web process, or set dokebi-web.listen: false (or another port) in processes.<name>.options of the others`,
|
|
116
|
+
});
|
|
117
|
+
// A job queue whose jobs no declared process takes: they only pile up.
|
|
118
|
+
if (configured('dokebi-job')) {
|
|
119
|
+
const queues = new Set();
|
|
120
|
+
for (const name of declared)
|
|
121
|
+
for (const queue of Object.keys(section(section(of(name), 'dokebi-job'), 'queues')))
|
|
122
|
+
queues.add(queue);
|
|
123
|
+
for (const queue of queues) {
|
|
124
|
+
const taking = declared.filter((name) => section(section(section(of(name), 'dokebi-job'), 'queues'), queue).consume !== false);
|
|
125
|
+
if (taking.length === 0)
|
|
126
|
+
issues.push({
|
|
127
|
+
code: 'PROCESS_QUEUE_NOT_TAKEN',
|
|
128
|
+
severity: 'warning',
|
|
129
|
+
message: `No declared process takes the jobs of queue ${queue} (consume: false in ${names(declared)}): they only pile up`,
|
|
130
|
+
fix: `remove consume: false for queue ${queue} from the process that should run its jobs (processes.<worker>.options.dokebi-job.queues.${queue}), or declare that process`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// The outbox, the schedules and partition upkeep: run by at least one process.
|
|
135
|
+
const off = (key, isOff, what, fix) => {
|
|
136
|
+
if (!configured(key))
|
|
137
|
+
return;
|
|
138
|
+
if (declared.every((name) => isOff(section(of(name), key))))
|
|
139
|
+
issues.push({
|
|
140
|
+
code: 'PROCESS_WORK_NOT_RUN',
|
|
141
|
+
severity: 'warning',
|
|
142
|
+
message: `No declared process runs ${what} (${names(declared)} all turn it off)`,
|
|
143
|
+
fix,
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
off('dokebi-outbox', (outbox) => section(outbox, 'runner').enabled === false, 'the outbox (dokebi-outbox.runner.enabled: false)', 'set dokebi-outbox.runner.enabled: true in the options of the process that runs background work');
|
|
147
|
+
off('dokebi-scheduler', (scheduler) => scheduler.enabled === false, 'the schedules (dokebi-scheduler.enabled: false)', 'set dokebi-scheduler.enabled: true in the options of the process that runs the schedules');
|
|
148
|
+
off('dokebi-partitions', (partitions) => partitions.intervalMs === 0 && partitions.runAtStart === false, 'partition upkeep (dokebi-partitions.intervalMs: 0 and runAtStart: false)', 'give one process dokebi-partitions.intervalMs above 0 or runAtStart: true');
|
|
149
|
+
// The schedules in several processes without coordination: each runs every schedule.
|
|
150
|
+
if (configured('dokebi-scheduler')) {
|
|
151
|
+
const running = declared.filter((name) => {
|
|
152
|
+
const scheduler = section(of(name), 'dokebi-scheduler');
|
|
153
|
+
return scheduler.enabled !== false && scheduler.coordination === undefined;
|
|
154
|
+
});
|
|
155
|
+
if (running.length > 1)
|
|
156
|
+
issues.push({
|
|
157
|
+
code: 'PROCESS_SCHEDULES_TWICE',
|
|
158
|
+
severity: 'warning',
|
|
159
|
+
message: `Processes ${names(running)} each run the schedules without coordination: every schedule runs in each of them`,
|
|
160
|
+
fix: 'set dokebi-scheduler.enabled: false in all but one of them, or give the scheduler coordination (Redis) in every process',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// One websocket-hub server id for two processes: they would take each other's presence.
|
|
164
|
+
if (configured('dokebi-websocket-hub')) {
|
|
165
|
+
const ids = new Map();
|
|
166
|
+
for (const name of declared) {
|
|
167
|
+
const hub = section(of(name), 'dokebi-websocket-hub');
|
|
168
|
+
if (hub.mode !== 'cluster' || typeof hub.serverId !== 'string')
|
|
169
|
+
continue;
|
|
170
|
+
ids.set(hub.serverId, [...(ids.get(hub.serverId) ?? []), name]);
|
|
171
|
+
}
|
|
172
|
+
for (const [id, list] of ids)
|
|
173
|
+
if (list.length > 1)
|
|
174
|
+
issues.push({
|
|
175
|
+
code: 'PROCESS_SERVER_ID_SHARED',
|
|
176
|
+
severity: 'error',
|
|
177
|
+
message: `Processes ${names(list)} share the websocket-hub serverId ${id}`,
|
|
178
|
+
fix: 'give each process its own dokebi-websocket-hub.serverId in processes.<name>.options',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return issues;
|
|
182
|
+
}
|
|
@@ -20,6 +20,7 @@ import { dependencyMap, validateProjectPackage } from './npm-client.js';
|
|
|
20
20
|
import { optionsFix } from './option-fixes.js';
|
|
21
21
|
import { checkPlugin, checkPluginsOptions } from './plugin-lifecycle.js';
|
|
22
22
|
import { PluginOptionsValidator } from './plugin-options.js';
|
|
23
|
+
import { processIssues, processSetOf } from './processes.js';
|
|
23
24
|
import { AGENTS_FILE, guideEntries, INSTALLED_END, INSTALLED_START, installedBlockEdited, PROJECT_END, PROJECT_START, projectBlockState, } from './project-guide.js';
|
|
24
25
|
import { readState } from './project-state.js';
|
|
25
26
|
import { ADMIN_SECTION, LEGACY_ADMIN_SECTION, SEED_FILE } from './recipe-login.js';
|
|
@@ -88,6 +89,18 @@ export function lockDiagnostic(holder, transactions) {
|
|
|
88
89
|
* of the fix in the installed template and its absence in the copy.
|
|
89
90
|
*/
|
|
90
91
|
/** The apps under src/apps with an Inertia browser entry (views/app.js), sorted by name. */
|
|
92
|
+
/** A section under a process's own values: maps key by key, anything else replaced (D-0251). */
|
|
93
|
+
function mergeSection(base, own) {
|
|
94
|
+
const map = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
95
|
+
if (own === undefined)
|
|
96
|
+
return base;
|
|
97
|
+
if (!map(base) || !map(own))
|
|
98
|
+
return own;
|
|
99
|
+
const merged = { ...base };
|
|
100
|
+
for (const [key, value] of Object.entries(own))
|
|
101
|
+
merged[key] = Object.hasOwn(base, key) ? mergeSection(base[key], value) : value;
|
|
102
|
+
return merged;
|
|
103
|
+
}
|
|
91
104
|
async function inertiaAppNames(root) {
|
|
92
105
|
const apps = await securePath(root, 'src/apps');
|
|
93
106
|
if (!(await exists(apps)))
|
|
@@ -213,6 +226,20 @@ export class ProjectInspector {
|
|
|
213
226
|
});
|
|
214
227
|
}
|
|
215
228
|
});
|
|
229
|
+
// D-0251: the processes of the settings file: what they leave undone (a queue no process
|
|
230
|
+
// takes, two on one port), and each process's own options checked against the plugin schemas
|
|
231
|
+
// below.
|
|
232
|
+
const processSet = config
|
|
233
|
+
? await check(configFile, async () => processSetOf(await readProjectConfigSource(root, settingsTarget.path)) ?? null)
|
|
234
|
+
: null;
|
|
235
|
+
for (const found of processSet ? processIssues(processSet) : [])
|
|
236
|
+
result.diagnostics.push({
|
|
237
|
+
code: found.code,
|
|
238
|
+
severity: found.severity,
|
|
239
|
+
path: configFile,
|
|
240
|
+
plugin: null,
|
|
241
|
+
hint: `${found.message}: ${found.fix}`,
|
|
242
|
+
});
|
|
216
243
|
result.requiredPlugins =
|
|
217
244
|
(await check('node_modules/@dokebi/core/package.json', () => readRequiredPlugins(root))) ??
|
|
218
245
|
[];
|
|
@@ -495,6 +522,25 @@ export class ProjectInspector {
|
|
|
495
522
|
// The commands name the section (options.logging for the logger host, D-0151).
|
|
496
523
|
hint: optionsFix(plugin.id, checked.errors, `correct options.${optionsKey(plugin)} in dokebi.yaml (npx dokebi plugins info ${plugin.id} --json lists the option keys)`, optionsKey(plugin), checked.schema),
|
|
497
524
|
});
|
|
525
|
+
// D-0251: a process that changes this section has its own options checked too (the
|
|
526
|
+
// shared section with the secrets file merged, under the process's own values).
|
|
527
|
+
if (processSet && installed && !configMissing)
|
|
528
|
+
for (const name of processSet.declared) {
|
|
529
|
+
const own = processSet.options.get(name)?.[key];
|
|
530
|
+
if (JSON.stringify(own) === JSON.stringify(processSet.shared[key]))
|
|
531
|
+
continue;
|
|
532
|
+
const merged = mergeSection(options, own);
|
|
533
|
+
const ownChecked = await check(path, async () => optionsValidator.check(root, installed, merged ?? {}), plugin.id);
|
|
534
|
+
if (ownChecked?.errors.length)
|
|
535
|
+
result.diagnostics.push({
|
|
536
|
+
code: 'INVALID_PLUGIN_OPTIONS',
|
|
537
|
+
severity: 'error',
|
|
538
|
+
path: `${configFile} (processes.${name})`,
|
|
539
|
+
plugin: plugin.id,
|
|
540
|
+
details: ownChecked.errors,
|
|
541
|
+
hint: `correct processes.${name}.options.${key} in ${configFile} (npx dokebi plugins info ${plugin.id} --json lists the option keys)`,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
498
544
|
// D-0162: the plugin's own rules once its section passes the schema (checked below, all
|
|
499
545
|
// plugins in one restricted child).
|
|
500
546
|
if (settings.runChecks && installed && config && checked && !checked.errors.length)
|
package/dist/project-state.d.ts
CHANGED
|
@@ -41,6 +41,12 @@ export declare const APP_NAME: RegExp;
|
|
|
41
41
|
export interface ProjectConfig {
|
|
42
42
|
schemaVersion: 1;
|
|
43
43
|
options: Record<string, unknown>;
|
|
44
|
+
/** D-0251: the processes the file declares (`processes.<name>`), when it declares any. */
|
|
45
|
+
processes?: readonly string[];
|
|
46
|
+
/** D-0251: the processes this folder starts (`run`). */
|
|
47
|
+
run?: readonly string[];
|
|
48
|
+
/** D-0251: the process whose options `options` are (absent: the shared options). */
|
|
49
|
+
process?: string;
|
|
44
50
|
}
|
|
45
51
|
export declare function emptyState(generatedHash: string): ProjectState;
|
|
46
52
|
export declare function defaultInstallation(plugin: PluginManifest): Installation;
|
package/dist/project-state.js
CHANGED
|
@@ -125,5 +125,16 @@ export function readConfig(value) {
|
|
|
125
125
|
const config = object(value, 'config');
|
|
126
126
|
if (config.schemaVersion !== 1)
|
|
127
127
|
throw new CliError('INVALID_CONFIG', 'Unsupported config');
|
|
128
|
-
|
|
128
|
+
const names = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string')
|
|
129
|
+
? value
|
|
130
|
+
: undefined;
|
|
131
|
+
const processes = names(config.processes);
|
|
132
|
+
const run = names(config.run);
|
|
133
|
+
return {
|
|
134
|
+
schemaVersion: 1,
|
|
135
|
+
options: object(config.options, 'options'),
|
|
136
|
+
...(processes ? { processes } : {}),
|
|
137
|
+
...(run ? { run } : {}),
|
|
138
|
+
...(typeof config.process === 'string' ? { process: config.process } : {}),
|
|
139
|
+
};
|
|
129
140
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -164,7 +164,9 @@ export declare class Project {
|
|
|
164
164
|
configSet(root: string, assignments: readonly {
|
|
165
165
|
plugin: string;
|
|
166
166
|
set: SetOption;
|
|
167
|
-
}[], dryRun?: boolean
|
|
167
|
+
}[], dryRun?: boolean,
|
|
168
|
+
/** D-0251: set the options of this process (processes.<process>.options), not the shared. */
|
|
169
|
+
process?: string): Promise<OperationResult & {
|
|
168
170
|
file: string;
|
|
169
171
|
}>;
|
|
170
172
|
/**
|
|
@@ -179,7 +181,9 @@ export declare class Project {
|
|
|
179
181
|
configUnset(root: string, targets: readonly {
|
|
180
182
|
plugin: string;
|
|
181
183
|
path: readonly string[];
|
|
182
|
-
}[], dryRun?: boolean
|
|
184
|
+
}[], dryRun?: boolean,
|
|
185
|
+
/** D-0251: remove from this process's own options (processes.<process>.options). */
|
|
186
|
+
process?: string): Promise<OperationResult & {
|
|
183
187
|
file: string;
|
|
184
188
|
removed: {
|
|
185
189
|
option: string;
|
package/dist/project.js
CHANGED
|
@@ -458,6 +458,22 @@ async function projectStateText(root) {
|
|
|
458
458
|
throw new CliError('READ_FAILED', 'Cannot read .dokebi/state.json', { cause: error });
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* D-0251: `--process <name>` changes processes.<name>.options. The file must declare processes; a
|
|
463
|
+
* name it does not declare yet is added (with `run` left out, it then starts here too).
|
|
464
|
+
*/
|
|
465
|
+
function checkProcessTarget(source, name) {
|
|
466
|
+
if (!/^[a-z][a-z0-9-]{0,31}$/.test(name))
|
|
467
|
+
throw new CliError('USAGE', 'A process name is lower case letters, digits and dashes, starting with a letter', { phase: 'arguments' });
|
|
468
|
+
if (parseProjectConfig(source, { process: null }).processes)
|
|
469
|
+
return;
|
|
470
|
+
throw new CliError('PROCESS_UNKNOWN', `The settings file declares no processes, so --process ${name} has none to change`, {
|
|
471
|
+
phase: 'arguments',
|
|
472
|
+
details: {
|
|
473
|
+
fix: 'declare them first in the settings file: processes: { web: {}, worker: { options: {} } } and run: [web, worker]; then npx dokebi config set --process worker <plugin>.<path>=<value>',
|
|
474
|
+
},
|
|
475
|
+
});
|
|
476
|
+
}
|
|
461
477
|
export class Project {
|
|
462
478
|
npm;
|
|
463
479
|
constructor(npm = new NpmClient()) {
|
|
@@ -1889,11 +1905,18 @@ export class Project {
|
|
|
1889
1905
|
* `dokebi config set <plugin>.<path>=<value>…`: non-secret options in dokebi.yaml, checked
|
|
1890
1906
|
* against that plugin's schema (only missing required values are tolerated and reported).
|
|
1891
1907
|
*/
|
|
1892
|
-
async configSet(root, assignments, dryRun = false
|
|
1908
|
+
async configSet(root, assignments, dryRun = false,
|
|
1909
|
+
/** D-0251: set the options of this process (processes.<process>.options), not the shared. */
|
|
1910
|
+
process) {
|
|
1893
1911
|
const session = await this.#begin(root);
|
|
1894
1912
|
const { tx, state } = session;
|
|
1895
1913
|
try {
|
|
1896
1914
|
let configSource = session.configSource;
|
|
1915
|
+
if (process !== undefined)
|
|
1916
|
+
checkProcessTarget(configSource, process);
|
|
1917
|
+
// What the app reads afterwards: that process's options, or (no --process) the settings
|
|
1918
|
+
// as the DOKEBI_PROCESS rule reads them.
|
|
1919
|
+
const view = (source) => parseProjectConfig(source, process === undefined ? undefined : { process });
|
|
1897
1920
|
const warnings = envWarnings(session.root);
|
|
1898
1921
|
const byPlugin = new Map();
|
|
1899
1922
|
for (const { plugin, set } of assignments)
|
|
@@ -1905,13 +1928,13 @@ export class Project {
|
|
|
1905
1928
|
if (!plugin && id === 'logging') {
|
|
1906
1929
|
// options.logging without the logger: core's level and plugins only (D-0047).
|
|
1907
1930
|
checkCoreLogging(sets);
|
|
1908
|
-
configSource = applySetOptions(configSource, id, sets);
|
|
1931
|
+
configSource = applySetOptions(configSource, id, sets, process);
|
|
1909
1932
|
continue;
|
|
1910
1933
|
}
|
|
1911
1934
|
if (!plugin && id === RELOAD_OPTIONS_KEY) {
|
|
1912
1935
|
// options.reload: core's reload settings (D-0154), checked by core's declaration.
|
|
1913
|
-
configSource = applySetOptions(configSource, id, sets);
|
|
1914
|
-
checkCoreReload(optionsOf(
|
|
1936
|
+
configSource = applySetOptions(configSource, id, sets, process);
|
|
1937
|
+
checkCoreReload(optionsOf(view(configSource).options, id));
|
|
1915
1938
|
continue;
|
|
1916
1939
|
}
|
|
1917
1940
|
const settings = !plugin && (state.settings ?? []).includes(id);
|
|
@@ -1921,8 +1944,8 @@ export class Project {
|
|
|
1921
1944
|
// The section of the plugin: options.<id>, options.logging for the logger (D-0151); an
|
|
1922
1945
|
// application settings section is its own name (D-0155).
|
|
1923
1946
|
const section = plugin ? optionsKey(plugin) : id;
|
|
1924
|
-
configSource = applySetOptions(configSource, section, sets);
|
|
1925
|
-
const value = optionsOf(
|
|
1947
|
+
configSource = applySetOptions(configSource, section, sets, process);
|
|
1948
|
+
const value = optionsOf(view(configSource).options, section);
|
|
1926
1949
|
const checked = plugin
|
|
1927
1950
|
? await validator.check(session.root, plugin, value)
|
|
1928
1951
|
: await validator.checkSettings(session.root, section, value);
|
|
@@ -1944,7 +1967,7 @@ export class Project {
|
|
|
1944
1967
|
// D-0162: the plugin's own rules (cross-field checks) once the schema passes, so a value
|
|
1945
1968
|
// the app would refuse at start is never written (R2 Claude T4: unknownDomain = an app name).
|
|
1946
1969
|
if (plugin && !checked.errors.length) {
|
|
1947
|
-
const verdict = (await checkPluginsOptions(session.root, [plugin],
|
|
1970
|
+
const verdict = (await checkPluginsOptions(session.root, [plugin], view(configSource).options)).get(plugin.id);
|
|
1948
1971
|
if (verdict && 'failed' in verdict)
|
|
1949
1972
|
warnings.push({
|
|
1950
1973
|
code: 'PLUGIN_OPTIONS_CHECK_FAILED',
|
|
@@ -1956,10 +1979,10 @@ export class Project {
|
|
|
1956
1979
|
}
|
|
1957
1980
|
}
|
|
1958
1981
|
const installations = { ...state.installations };
|
|
1959
|
-
await this.#check(session.root, state.plugins,
|
|
1982
|
+
await this.#check(session.root, state.plugins, view(configSource), installations, Object.keys(dependencyMap(session.pkg)), { id: '', requires: [] }, configRequired, warnings);
|
|
1960
1983
|
state.installations = installations;
|
|
1961
1984
|
const paths = filePaths([[session.configFile, session.configSource, configSource]]);
|
|
1962
|
-
this.#checkPaths(paths, assignments.map(({ plugin, set }) => requestedPath(session.configSource, plugin, set.path)), dryRun, warnings);
|
|
1985
|
+
this.#checkPaths(paths, assignments.map(({ plugin, set }) => requestedPath(session.configSource, plugin, set.path, process)), dryRun, warnings);
|
|
1963
1986
|
await this.writeConfiguration(tx, state, configSource, session.configFile);
|
|
1964
1987
|
debug('Options set', { plugins: [...byPlugin.keys()], dryRun, file: session.configFile });
|
|
1965
1988
|
return {
|
|
@@ -1991,11 +2014,16 @@ export class Project {
|
|
|
1991
2014
|
* Removing may only leave issues the options already had, or missing required values
|
|
1992
2015
|
* (configRequired); issues that remain are a warning that carries the next fix.
|
|
1993
2016
|
*/
|
|
1994
|
-
async configUnset(root, targets, dryRun = false
|
|
2017
|
+
async configUnset(root, targets, dryRun = false,
|
|
2018
|
+
/** D-0251: remove from this process's own options (processes.<process>.options). */
|
|
2019
|
+
process) {
|
|
1995
2020
|
const session = await this.#begin(root);
|
|
1996
2021
|
const { tx, state } = session;
|
|
1997
2022
|
try {
|
|
1998
2023
|
let configSource = session.configSource;
|
|
2024
|
+
if (process !== undefined)
|
|
2025
|
+
checkProcessTarget(configSource, process);
|
|
2026
|
+
const view = (source) => parseProjectConfig(source, process === undefined ? undefined : { process });
|
|
1999
2027
|
const warnings = envWarnings(session.root);
|
|
2000
2028
|
const configRequired = [];
|
|
2001
2029
|
const removed = [];
|
|
@@ -2003,7 +2031,8 @@ export class Project {
|
|
|
2003
2031
|
for (const { plugin, path } of targets)
|
|
2004
2032
|
byPlugin.set(plugin, [...(byPlugin.get(plugin) ?? []), [...path]]);
|
|
2005
2033
|
const examplePath = await securePath(session.root, EXAMPLE);
|
|
2006
|
-
|
|
2034
|
+
// A process's own options are this file's alone: the sample is left as it is (D-0251).
|
|
2035
|
+
const exampleSource = process === undefined && (await exists(examplePath)) ? await tx.read(EXAMPLE) : undefined;
|
|
2007
2036
|
let example = exampleSource;
|
|
2008
2037
|
const validator = new PluginOptionsValidator({ allErrors: true });
|
|
2009
2038
|
const key = (error) => `${error.keyword} ${error.instancePath} ${error.additionalProperty ?? ''}`;
|
|
@@ -2040,7 +2069,7 @@ export class Project {
|
|
|
2040
2069
|
for (const [id, { plugin, notRead, paths: asked }] of bySection) {
|
|
2041
2070
|
// The same path typed twice through two names is one path.
|
|
2042
2071
|
const paths = [...new Map(asked.map((path) => [path.join('.'), path])).values()];
|
|
2043
|
-
const before =
|
|
2072
|
+
const before = view(configSource);
|
|
2044
2073
|
// D-0155: an application settings section is checked against its schema file too.
|
|
2045
2074
|
const settings = !plugin && (state.settings ?? []).includes(id);
|
|
2046
2075
|
const core = !plugin && (id === 'logging' || id === RELOAD_OPTIONS_KEY);
|
|
@@ -2078,10 +2107,10 @@ export class Project {
|
|
|
2078
2107
|
? validator.check(session.root, plugin, optionsOf(options, id))
|
|
2079
2108
|
: validator.checkSettings(session.root, id, optionsOf(options, id));
|
|
2080
2109
|
const checkedBefore = plugin || settings ? await checkSection(before.options) : undefined;
|
|
2081
|
-
const edited = applyUnsetOptions(configSource, id, paths);
|
|
2110
|
+
const edited = applyUnsetOptions(configSource, id, paths, process);
|
|
2082
2111
|
// Secret or not is decided on the values being removed; nothing of them is kept.
|
|
2083
2112
|
for (const path of edited.removed) {
|
|
2084
|
-
const value = optionAtPath(configSource, id, path);
|
|
2113
|
+
const value = optionAtPath(configSource, id, path, process);
|
|
2085
2114
|
if (commandLineSecret(path, value, checkedBefore?.schema ?? undefined))
|
|
2086
2115
|
warnings.push({
|
|
2087
2116
|
code: 'SECRET_REMOVED',
|
|
@@ -2137,7 +2166,7 @@ export class Project {
|
|
|
2137
2166
|
}
|
|
2138
2167
|
if (!checkedBefore)
|
|
2139
2168
|
continue;
|
|
2140
|
-
const checked = await checkSection(
|
|
2169
|
+
const checked = await checkSection(view(configSource).options);
|
|
2141
2170
|
const had = new Set(checkedBefore.errors.map(key));
|
|
2142
2171
|
const added = checked.errors.filter((error) => error.keyword !== 'required' && !had.has(key(error)));
|
|
2143
2172
|
if (added.length)
|
|
@@ -2158,14 +2187,14 @@ export class Project {
|
|
|
2158
2187
|
});
|
|
2159
2188
|
}
|
|
2160
2189
|
const installations = { ...state.installations };
|
|
2161
|
-
await this.#check(session.root, state.plugins,
|
|
2190
|
+
await this.#check(session.root, state.plugins, view(configSource), installations, Object.keys(dependencyMap(session.pkg)), { id: '', requires: [] }, configRequired, warnings);
|
|
2162
2191
|
const requirementsChanged = json(installations) !== json(state.installations);
|
|
2163
2192
|
state.installations = installations;
|
|
2164
2193
|
const paths = filePaths([
|
|
2165
2194
|
[session.configFile, session.configSource, configSource],
|
|
2166
2195
|
[EXAMPLE, exampleSource, example],
|
|
2167
2196
|
]);
|
|
2168
|
-
this.#checkPaths(paths, targets.map(({ plugin, path }) => requestedPath(session.configSource, plugin, path)), dryRun, warnings);
|
|
2197
|
+
this.#checkPaths(paths, targets.map(({ plugin, path }) => requestedPath(session.configSource, plugin, path, process)), dryRun, warnings);
|
|
2169
2198
|
// Nothing set: nothing written (a requirement refreshed by the checks is written too).
|
|
2170
2199
|
if (configSource !== session.configSource || requirementsChanged)
|
|
2171
2200
|
await this.writeConfiguration(tx, state, configSource, session.configFile);
|
package/dist/server.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface PidRecord {
|
|
|
27
27
|
readonly urls?: string[];
|
|
28
28
|
/** The log writer's loopback control port (D-0073 addendum); absent when it could not listen. */
|
|
29
29
|
readonly control?: number;
|
|
30
|
+
/** D-0251: the processes of `run` this start started (absent for one app without processes). */
|
|
31
|
+
readonly processes?: string[];
|
|
30
32
|
}
|
|
31
33
|
/** How a pid was shown to be this project's app (ServerStatus.proof). */
|
|
32
34
|
export type Proof = 'process' | 'http' | 'log-writer';
|
|
@@ -63,6 +65,8 @@ export interface ServerStatus {
|
|
|
63
65
|
};
|
|
64
66
|
/** The writer's own diagnostics, when it wrote any. */
|
|
65
67
|
readonly logWriterLog?: string;
|
|
68
|
+
/** D-0251: the processes the start started (the settings' `run`); absent for one app. */
|
|
69
|
+
readonly processes?: readonly string[];
|
|
66
70
|
}
|
|
67
71
|
export interface ProcessInfo {
|
|
68
72
|
startedAt: number;
|
|
@@ -135,6 +139,8 @@ export interface StartResult {
|
|
|
135
139
|
readonly urls: string[];
|
|
136
140
|
/** Addresses from the web plugin's listening log line (empty when it logged none). */
|
|
137
141
|
readonly listen: string[];
|
|
142
|
+
/** D-0251: the processes started (the settings file's `run`); absent without processes. */
|
|
143
|
+
readonly processes?: readonly string[];
|
|
138
144
|
readonly ms: number;
|
|
139
145
|
readonly warnings: string[];
|
|
140
146
|
}
|
|
@@ -227,6 +233,8 @@ export interface ReloadResult {
|
|
|
227
233
|
readonly proof?: Proof;
|
|
228
234
|
/** Who sent SIGHUP: this command, or the app's log writer (a sandbox per command). */
|
|
229
235
|
readonly via?: 'signal' | 'log-writer';
|
|
236
|
+
/** D-0251: each process's outcome code when several run. */
|
|
237
|
+
readonly processes?: Record<string, string>;
|
|
230
238
|
readonly warnings?: string[];
|
|
231
239
|
}
|
|
232
240
|
/**
|