@bakers-build/addon-ports 0.8.0 → 0.8.1-next.2

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.
@@ -11,12 +11,13 @@ export interface PortsMachineConfig {
11
11
  };
12
12
  }
13
13
  /** No ports addon entry (or one without a transport) in either scope. */
14
- export declare const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/conductor.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
14
+ export declare const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/project.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
15
15
  /** The retired top-level machine `ports` key. */
16
16
  export declare const PORTS_RETIRED = "machine ports is retired: move it to addons: [{ use: '@bakers-build/addon-ports', with: { transport: \u2026 } }]";
17
17
  /** Throw the remediation when the machine config still carries `ports`. */
18
18
  export declare function assertNoMachinePorts(): Promise<void>;
19
- /** `addons[@bakers-build/addon-ports].with.<key> <message>` per finding. */
19
+ /** `addons[@bakers-build/addon-ports].with.<key> <message>` for the rule the
20
+ * options schema cannot express (a duplicate service key). */
20
21
  export declare function withProblems(value: unknown): string[];
21
22
  /** `portsSettings` plus the retired machine `ports` check — the transport
22
23
  * path; discovery (`list`) reads settings without it. */
@@ -5,7 +5,7 @@
5
5
  import { realpathSync } from 'node:fs';
6
6
  import { pathToFileURL } from 'node:url';
7
7
  import { machineUiConfigPath, projectConductorConfigPath, readConfigAddons, readEffectiveAddon, readMachineContext, resolveModuleEslintStyle, } from '@bakers-build/core';
8
- import { checkWith } from './service-config.js';
8
+ import { duplicateServiceKey } from './service-config.js';
9
9
  import { assertPortsTransport, InvalidTransportModuleError, } from './transport.js';
10
10
  /**
11
11
  * Resolution bases rooted at the running `bakers` HOST install, usable from
@@ -44,7 +44,7 @@ function hostInstallBases() {
44
44
  return [entryUrl.href, new URL('../host/dist/src/host.js', entryUrl).href];
45
45
  }
46
46
  /** No ports addon entry (or one without a transport) in either scope. */
47
- export const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/conductor.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
47
+ export const PORTS_NEEDS_ENTRY = "bakers ports needs '@bakers-build/addon-ports' in addons[] of ~/.bakers/machine.config.js or .bakers/project.config.js, with with.transport.use naming a transport package; see docs/addons/ports";
48
48
  /** The retired top-level machine `ports` key. */
49
49
  export const PORTS_RETIRED = "machine ports is retired: move it to addons: [{ use: '@bakers-build/addon-ports', with: { transport: … } }]";
50
50
  /** Throw the remediation when the machine config still carries `ports`. */
@@ -54,9 +54,11 @@ export async function assertNoMachinePorts() {
54
54
  throw new Error(PORTS_RETIRED);
55
55
  }
56
56
  const PORTS_SPEC = '@bakers-build/addon-ports';
57
- /** `addons[@bakers-build/addon-ports].with.<key> <message>` per finding. */
57
+ /** `addons[@bakers-build/addon-ports].with.<key> <message>` for the rule the
58
+ * options schema cannot express (a duplicate service key). */
58
59
  export function withProblems(value) {
59
- return checkWith(value).map((f) => `addons[${PORTS_SPEC}].with${f.key ? `.${f.key}` : ''} ${f.message}`);
60
+ const problem = duplicateServiceKey(value);
61
+ return problem ? [`addons[${PORTS_SPEC}].with.${problem}`] : [];
60
62
  }
61
63
  /** Throw the first malformed ports `with` in the machine or project config,
62
64
  * naming the file and key — a bad setting is never silently ignored. */
@@ -66,10 +68,9 @@ async function assertValidScopes(worktree) {
66
68
  if (path === undefined)
67
69
  continue;
68
70
  for (const entry of await readConfigAddons(path)) {
69
- if (typeof entry === 'string' ||
70
- (entry?.use ?? entry?.name) !== PORTS_SPEC)
71
+ if (typeof entry === 'string' || entry?.use !== PORTS_SPEC)
71
72
  continue;
72
- const [problem] = withProblems(entry.with ?? entry.options);
73
+ const [problem] = withProblems(entry.with);
73
74
  if (problem)
74
75
  throw new Error(`${path}: ${problem}`);
75
76
  }
@@ -94,7 +95,7 @@ export async function readPortsSettings(worktree) {
94
95
  });
95
96
  if (found === undefined || typeof found.entry === 'string')
96
97
  return undefined;
97
- return found.entry.with ?? found.entry.options;
98
+ return found.entry.with;
98
99
  }
99
100
  /** `home`, the running `bakers` host install, then `process.cwd()` — see
100
101
  * `loadPortsTransport`. */
@@ -19,7 +19,7 @@ export declare function processStartTime(pid: number): Promise<number | null>;
19
19
  /**
20
20
  * BB-681 Task 4 — a process whose cmdline carries ANY pluggable-transport
21
21
  * package's own ownership marker: `addon-ports-cloudflare-quick`'s private
22
- * per-route `--config <BB_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
22
+ * per-route `--config <BAKERS_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
23
23
  * or a Named Cloudflare connector's `tunnel run` invocation. This generic
24
24
  * legacy-reap scan predates per-route managed processes (BB-676) and its
25
25
  * only signal for "legacy" is `cmdline.includes('--url')` (see
@@ -115,7 +115,7 @@ export async function processStartTime(pid) {
115
115
  /**
116
116
  * BB-681 Task 4 — a process whose cmdline carries ANY pluggable-transport
117
117
  * package's own ownership marker: `addon-ports-cloudflare-quick`'s private
118
- * per-route `--config <BB_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
118
+ * per-route `--config <BAKERS_HOME>/ports/quick/<hash>/gen-<n>/config.yaml`,
119
119
  * or a Named Cloudflare connector's `tunnel run` invocation. This generic
120
120
  * legacy-reap scan predates per-route managed processes (BB-676) and its
121
121
  * only signal for "legacy" is `cmdline.includes('--url')` (see
package/dist/src/index.js CHANGED
@@ -286,7 +286,7 @@ export function quickTunnelNotice(url) {
286
286
  return undefined;
287
287
  return 'Quick Tunnel: no fixed name, no uptime guarantee, 200 in-flight request limit, no SSE';
288
288
  }
289
- const NO_CONDUCTOR = 'no running conductor for this checkout — the conductor is the only writer of the tunnel routes (start it with `bakers oven start`)';
289
+ const NO_CONDUCTOR = 'no running conductor for this checkout — the conductor is the only writer of the tunnel routes (start it with `bakers conductor start`)';
290
290
  /** The live conductor endpoint whose workspace root holds `worktree`; the
291
291
  * most specific root wins. A dead pid's leftover file does not count. */
292
292
  function conductorEndpoint(worktree) {
@@ -3,5 +3,5 @@ import type { BbPreset } from '@bakers-build/core';
3
3
  export declare const commands: BbPreset['commands'];
4
4
  export declare const inbox: Preset['inbox'];
5
5
  export declare const scopes: BbPreset['scopes'];
6
- export { checkWith, mergeWith } from './service-config.js';
6
+ export { mergeWith } from './service-config.js';
7
7
  export declare const tools: Preset['tools'];
@@ -28,8 +28,9 @@ export const inbox = {
28
28
  };
29
29
  // Configurable on either level; the machine entry's with wins.
30
30
  export const scopes = ['machine', 'project'];
31
- // Merge and check the entry's own settings (services, all_node, transport).
32
- export { checkWith, mergeWith } from './service-config.js';
31
+ // Merge the entry's own settings across scopes (services, all_node, transport);
32
+ // options.schema.json describes them.
33
+ export { mergeWith } from './service-config.js';
33
34
  // Agent tools the conductor serves to every run (and the CLI calls through
34
35
  // it): the conductor is the only writer of the tunnel routes.
35
36
  export const tools = {
@@ -8,14 +8,13 @@ export interface ServiceRules {
8
8
  readonly entries: readonly ServiceRule[];
9
9
  readonly allNode: boolean;
10
10
  }
11
- export interface WithFinding {
12
- /** Relative to the entry's `with`: `services[1].key`, `all_node`, `foo`. */
13
- readonly key: string;
14
- readonly message: string;
15
- }
16
11
  export declare const DEFAULT_STORYBOOK: ServiceRule;
17
- /** Every problem in a ports entry's `with`; `[]` when it is valid or absent. */
18
- export declare function checkWith(value: unknown): WithFinding[];
12
+ /**
13
+ * The one rule options.schema.json cannot express: two `services` entries
14
+ * with the same key. Returns `services[i].key duplicates '<key>'`, or
15
+ * undefined. Types, unknown keys and the label pattern are the schema's.
16
+ */
17
+ export declare function duplicateServiceKey(value: unknown): string | undefined;
19
18
  /**
20
19
  * The ports addon in both scopes: the machine wins. `services` merge per key
21
20
  * (machine entries first); every other key is taken whole from the machine
@@ -10,73 +10,24 @@ export const DEFAULT_STORYBOOK = {
10
10
  key: 'storybook',
11
11
  match: 'storybook',
12
12
  };
13
- const WITH_KEYS = new Set(['transport', 'services', 'all_node', 'claimers']);
14
- const ENTRY_KEYS = new Set(['key', 'match']);
15
13
  const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
16
- /** Every problem in a ports entry's `with`; `[]` when it is valid or absent. */
17
- export function checkWith(value) {
18
- if (value === undefined)
19
- return [];
20
- if (!isObject(value))
21
- return [{ key: '', message: 'must be an object' }];
22
- const out = [];
23
- for (const k of Object.keys(value))
24
- if (!WITH_KEYS.has(k))
25
- out.push({
26
- key: k,
27
- message: 'is not a ports setting (transport, services, all_node, claimers)',
28
- });
29
- const { transport, services, all_node, claimers } = value;
30
- if (claimers !== undefined &&
31
- (!Array.isArray(claimers) ||
32
- !claimers.every((c) => typeof c === 'string' && c !== '')))
33
- out.push({ key: 'claimers', message: 'must be an array of package names' });
34
- if (transport !== undefined) {
35
- if (!isObject(transport))
36
- out.push({ key: 'transport', message: 'must be an object' });
37
- else if (typeof transport.use !== 'string' || transport.use === '')
38
- out.push({
39
- key: 'transport.use',
40
- message: 'must name a transport package',
41
- });
42
- }
43
- if (all_node !== undefined && typeof all_node !== 'boolean')
44
- out.push({ key: 'all_node', message: 'must be true or false' });
45
- if (services !== undefined) {
46
- if (!Array.isArray(services))
47
- out.push({ key: 'services', message: 'must be an array' });
48
- else {
49
- const seen = new Set();
50
- services.forEach((entry, i) => {
51
- const at = `services[${i}]`;
52
- if (!isObject(entry)) {
53
- out.push({ key: at, message: 'must be { key, match }' });
54
- return;
55
- }
56
- for (const k of Object.keys(entry))
57
- if (!ENTRY_KEYS.has(k))
58
- out.push({
59
- key: `${at}.${k}`,
60
- message: 'is not a service field (key, match)',
61
- });
62
- if (typeof entry.key !== 'string' || !LABEL_RE.test(entry.key))
63
- out.push({
64
- key: `${at}.key`,
65
- message: 'must be a DNS-safe label (a-z, 0-9, -)',
66
- });
67
- else if (seen.has(entry.key))
68
- out.push({ key: `${at}.key`, message: `duplicates '${entry.key}'` });
69
- else
70
- seen.add(entry.key);
71
- if (typeof entry.match !== 'string' || entry.match === '')
72
- out.push({
73
- key: `${at}.match`,
74
- message: 'must be a non-empty string',
75
- });
76
- });
77
- }
14
+ /**
15
+ * The one rule options.schema.json cannot express: two `services` entries
16
+ * with the same key. Returns `services[i].key duplicates '<key>'`, or
17
+ * undefined. Types, unknown keys and the label pattern are the schema's.
18
+ */
19
+ export function duplicateServiceKey(value) {
20
+ const services = isObject(value) ? value.services : undefined;
21
+ if (!Array.isArray(services))
22
+ return undefined;
23
+ const seen = new Set();
24
+ for (const [i, entry] of services.entries()) {
25
+ const key = isObject(entry) ? entry.key : undefined;
26
+ if (seen.has(key))
27
+ return `services[${i}].key duplicates '${key}'`;
28
+ seen.add(key);
78
29
  }
79
- return out;
30
+ return undefined;
80
31
  }
81
32
  /**
82
33
  * The ports addon in both scopes: the machine wins. `services` merge per key
@@ -0,0 +1,55 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://bakers.build/schema/addon-ports/options.schema.json",
4
+ "title": "@bakers-build/addon-ports options",
5
+ "description": "The ports addon entry's with. A duplicate services key is rejected at load by the addon itself.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "transport": {
10
+ "type": "object",
11
+ "additionalProperties": false,
12
+ "required": ["use"],
13
+ "properties": {
14
+ "use": {
15
+ "type": "string",
16
+ "minLength": 1,
17
+ "description": "The transport package."
18
+ },
19
+ "with": {
20
+ "description": "The transport package's own settings, checked by that package's options.schema.json."
21
+ }
22
+ }
23
+ },
24
+ "services": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "required": ["key", "match"],
30
+ "properties": {
31
+ "key": {
32
+ "type": "string",
33
+ "pattern": "^[a-z0-9]([a-z0-9-]*[a-z0-9])?$",
34
+ "description": "A DNS-safe label."
35
+ },
36
+ "match": {
37
+ "type": "string",
38
+ "minLength": 1,
39
+ "description": "A command-line substring of the process."
40
+ }
41
+ }
42
+ }
43
+ },
44
+ "all_node": {
45
+ "type": "boolean"
46
+ },
47
+ "claimers": {
48
+ "type": "array",
49
+ "items": {
50
+ "type": "string",
51
+ "minLength": 1
52
+ }
53
+ }
54
+ }
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-ports",
3
- "version": "0.8.0",
3
+ "version": "0.8.1-next.2",
4
4
  "description": "bakers.build ports command plugin: discover a ticket worktree's running services (claimer packages' containers, Storybook, ad-hoc listeners) and bring shareable tunnels up and down. The command half of BB-475; usable without the cockpit half.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,10 +9,12 @@
9
9
  "./preset": "./dist/src/preset.js",
10
10
  "./core": "./dist/src/core.js",
11
11
  "./transport": "./dist/src/transport-contract.js",
12
- "./node": "./dist/src/deps-node.js"
12
+ "./node": "./dist/src/deps-node.js",
13
+ "./options.schema.json": "./options.schema.json"
13
14
  },
14
15
  "files": [
15
- "dist/src"
16
+ "dist/src",
17
+ "options.schema.json"
16
18
  ],
17
19
  "publishConfig": {
18
20
  "access": "public"
@@ -23,15 +25,15 @@
23
25
  "directory": "bakers-cli/addons/ports"
24
26
  },
25
27
  "dependencies": {
26
- "@bakers-build/addon-docker-compose": "^0.8.0",
28
+ "@bakers-build/addon-docker-compose": "^0.8.1-next.2",
27
29
  "commander": "^12.1.0"
28
30
  },
29
31
  "peerDependencies": {
30
- "@bakers-build/conductor": "^0.8.0",
31
- "@bakers-build/core": "^0.8.0"
32
+ "@bakers-build/conductor": "^0.8.1-next.2",
33
+ "@bakers-build/core": "^0.8.1-next.2"
32
34
  },
33
35
  "bakersBuild": {
34
- "commit": "082d8c57436f78e751f5a9a26a4446cec42209ce",
35
- "channel": "latest"
36
+ "commit": "0177880667693d1c36c65ffced82d2f3a17cbf2a",
37
+ "channel": "next"
36
38
  }
37
39
  }