@marktiderman/genesis-config 0.0.0-stage → 0.10.0
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 +461 -2
- package/dist/blocks.d.ts +473 -0
- package/dist/blocks.js +5 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chunk-B6WRD3WF.js +6 -0
- package/dist/chunk-B6WRD3WF.js.map +1 -0
- package/dist/chunk-HIOKZIZP.js +218 -0
- package/dist/chunk-HIOKZIZP.js.map +1 -0
- package/dist/chunk-M7IY6LUN.js +123 -0
- package/dist/chunk-M7IY6LUN.js.map +1 -0
- package/dist/chunk-OW46SL2G.js +10 -0
- package/dist/chunk-OW46SL2G.js.map +1 -0
- package/dist/chunk-SEFG2QV6.js +413 -0
- package/dist/chunk-SEFG2QV6.js.map +1 -0
- package/dist/chunk-UD7SPYZH.js +354 -0
- package/dist/chunk-UD7SPYZH.js.map +1 -0
- package/dist/chunk-VYUX7VAX.js +52 -0
- package/dist/chunk-VYUX7VAX.js.map +1 -0
- package/dist/chunk-Y7NUBTWA.js +494 -0
- package/dist/chunk-Y7NUBTWA.js.map +1 -0
- package/dist/gate-CNTkn-Fv.d.ts +202 -0
- package/dist/gate-react.d.ts +48 -0
- package/dist/gate-react.js +37 -0
- package/dist/gate-react.js.map +1 -0
- package/dist/gate.d.ts +18 -0
- package/dist/gate.js +5 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/model-uON71G4u.d.ts +437 -0
- package/dist/node.d.ts +159 -0
- package/dist/node.js +486 -0
- package/dist/node.js.map +1 -0
- package/dist/packages-CWhdXtzS.d.ts +203 -0
- package/dist/platforms-NR0liM8L.d.ts +10 -0
- package/dist/react.d.ts +60 -0
- package/dist/react.js +236 -0
- package/dist/react.js.map +1 -0
- package/dist/settings-protocol.d.ts +515 -0
- package/dist/settings-protocol.js +4 -0
- package/dist/settings-protocol.js.map +1 -0
- package/dist/settings-react.d.ts +143 -0
- package/dist/settings-react.js +943 -0
- package/dist/settings-react.js.map +1 -0
- package/dist/settings.d.ts +373 -0
- package/dist/settings.js +3 -0
- package/dist/settings.js.map +1 -0
- package/dist/types-D4hs16bJ.d.ts +39 -0
- package/package.json +141 -4
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// src/settings.ts
|
|
2
|
+
var SETTINGS_PRESETS = ["max", "standard", "min"];
|
|
3
|
+
var DEFAULT_PRESET = "max";
|
|
4
|
+
var SETTING_TYPES = ["boolean", "number", "string", "list", "object"];
|
|
5
|
+
var SETTINGS_LAYERS = ["default", "preset", "file", "database", "tenant", "person"];
|
|
6
|
+
var SettingsError = class extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "SettingsError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var NAMESPACE = /^[a-z][a-zA-Z0-9]*(?:-[a-z0-9]+)*$/;
|
|
13
|
+
var KEY = /^[a-z][a-zA-Z0-9]*$/;
|
|
14
|
+
var SETTING_KEY = /^[a-z][a-zA-Z0-9]*(?:-[a-z0-9]+)*\.[a-z][a-zA-Z0-9]*$/;
|
|
15
|
+
var SECRET_NAME = /^[A-Z][A-Z0-9_]*$/;
|
|
16
|
+
var SETUP_STEP_ID = /^[a-z][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)*$/;
|
|
17
|
+
var SPEC_KEYS = /* @__PURE__ */ new Set(["type", "default", "scope", "applies", "requires", "min", "max", "options", "needs", "store", "feature", "flag", "summary", "setup", "integer"]);
|
|
18
|
+
var SCOPES = ["app", "tenant", "person"];
|
|
19
|
+
var APPLIES = ["build", "runtime"];
|
|
20
|
+
var STORES = ["vault", "edge", "server-env", "ci"];
|
|
21
|
+
function isPlainObject(v) {
|
|
22
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
23
|
+
const proto = Object.getPrototypeOf(v);
|
|
24
|
+
return proto === Object.prototype || proto === null;
|
|
25
|
+
}
|
|
26
|
+
function own(obj, key) {
|
|
27
|
+
return Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : void 0;
|
|
28
|
+
}
|
|
29
|
+
function dict() {
|
|
30
|
+
return /* @__PURE__ */ Object.create(null);
|
|
31
|
+
}
|
|
32
|
+
function isPresetDefaults(v) {
|
|
33
|
+
if (!isPlainObject(v)) return false;
|
|
34
|
+
const keys = Object.keys(v).sort();
|
|
35
|
+
return keys.length === 3 && keys[0] === "max" && keys[1] === "min" && keys[2] === "standard";
|
|
36
|
+
}
|
|
37
|
+
function settingValueProblem(def, value) {
|
|
38
|
+
if (value === null) return def.nullable ? null : "can't be null: it has a default, so set a value";
|
|
39
|
+
switch (def.type) {
|
|
40
|
+
case "boolean":
|
|
41
|
+
if (typeof value !== "boolean") return "must be true or false";
|
|
42
|
+
return null;
|
|
43
|
+
case "number":
|
|
44
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return "must be a number";
|
|
45
|
+
if (def.integer && !Number.isInteger(value)) return "must be a whole number";
|
|
46
|
+
if (def.min !== void 0 && value < def.min) return `must be at least ${def.min}`;
|
|
47
|
+
if (def.max !== void 0 && value > def.max) return `must be at most ${def.max}`;
|
|
48
|
+
if (def.options && !def.options.includes(value)) return `must be one of ${def.options.join(", ")}`;
|
|
49
|
+
return null;
|
|
50
|
+
case "string":
|
|
51
|
+
if (typeof value !== "string") return "must be a string";
|
|
52
|
+
if (def.options && !def.options.includes(value)) return `must be one of ${def.options.map((o) => JSON.stringify(o)).join(", ")}`;
|
|
53
|
+
return null;
|
|
54
|
+
case "list":
|
|
55
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" && typeof item !== "number")) return "must be a list of strings or numbers";
|
|
56
|
+
if (def.min !== void 0 && value.length < def.min) return `must have at least ${def.min} items`;
|
|
57
|
+
if (def.max !== void 0 && value.length > def.max) return `must have at most ${def.max} items`;
|
|
58
|
+
if (def.options) {
|
|
59
|
+
const bad = value.find((item) => !def.options.includes(item));
|
|
60
|
+
if (bad !== void 0) return `has ${JSON.stringify(bad)}, which isn't one of ${def.options.map((o) => JSON.stringify(o)).join(", ")}`;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
case "object":
|
|
64
|
+
if (!isPlainObject(value)) return "must be an object";
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function defineKey(namespace, name, spec) {
|
|
69
|
+
const key = `${namespace}.${name}`;
|
|
70
|
+
const fail = (msg) => {
|
|
71
|
+
throw new SettingsError(`defineSettings("${namespace}"): ${key} ${msg}`);
|
|
72
|
+
};
|
|
73
|
+
if (!KEY.test(name)) fail(`isn't a valid key name (camelCase letters and digits)`);
|
|
74
|
+
if (!isPlainObject(spec)) fail("must be an object");
|
|
75
|
+
for (const k of Object.keys(spec)) if (!SPEC_KEYS.has(k)) fail(`has an unknown field "${k}"`);
|
|
76
|
+
if (!SETTING_TYPES.includes(spec.type)) fail(`has type ${JSON.stringify(spec.type)} (one of ${SETTING_TYPES.join(", ")})`);
|
|
77
|
+
if (!Object.prototype.hasOwnProperty.call(spec, "default")) fail("needs a default (null for none)");
|
|
78
|
+
const scope = spec.scope ?? "app";
|
|
79
|
+
const applies = spec.applies ?? "runtime";
|
|
80
|
+
if (!SCOPES.includes(scope)) fail(`has scope ${JSON.stringify(scope)} (app, tenant or person)`);
|
|
81
|
+
if (!APPLIES.includes(applies)) fail(`has applies ${JSON.stringify(applies)} (build or runtime)`);
|
|
82
|
+
if (applies === "build" && scope !== "app") fail(`applies at build time, so it can't have a ${scope} scope (a build is the app's)`);
|
|
83
|
+
for (const bound of ["min", "max"]) {
|
|
84
|
+
const v = spec[bound];
|
|
85
|
+
if (v !== void 0 && (typeof v !== "number" || !Number.isFinite(v))) fail(`${bound} must be a number`);
|
|
86
|
+
if (v !== void 0 && spec.type !== "number" && spec.type !== "list") fail(`has ${bound}, which only a number or a list takes`);
|
|
87
|
+
}
|
|
88
|
+
if (spec.min !== void 0 && spec.max !== void 0 && spec.min > spec.max) fail("has min above max");
|
|
89
|
+
if (spec.options !== void 0) {
|
|
90
|
+
if (!Array.isArray(spec.options) || spec.options.length === 0) fail("options must be a non-empty list");
|
|
91
|
+
if (spec.type === "boolean" || spec.type === "object") fail(`has options, which a ${spec.type} doesn't take`);
|
|
92
|
+
}
|
|
93
|
+
const requires = spec.requires ?? [];
|
|
94
|
+
if (!Array.isArray(requires)) fail("requires must be a list of keys");
|
|
95
|
+
for (const r of requires) {
|
|
96
|
+
if (typeof r !== "string" || !SETTING_KEY.test(r)) fail(`requires ${JSON.stringify(r)}, which isn't a full key (namespace.key)`);
|
|
97
|
+
if (r === key) fail("requires itself");
|
|
98
|
+
}
|
|
99
|
+
let secret;
|
|
100
|
+
if (spec.needs !== void 0) {
|
|
101
|
+
const m = typeof spec.needs === "string" ? /^secret:(.+)$/.exec(spec.needs) : null;
|
|
102
|
+
if (!m || !SECRET_NAME.test(m[1])) fail(`needs ${JSON.stringify(spec.needs)}: write "secret:NAME" with the secret's NAME in capitals (never its value)`);
|
|
103
|
+
const store = spec.store ?? "edge";
|
|
104
|
+
if (!STORES.includes(store)) fail(`has store ${JSON.stringify(store)} (vault, edge, server-env or ci)`);
|
|
105
|
+
secret = { name: m[1], store };
|
|
106
|
+
} else if (spec.store !== void 0) {
|
|
107
|
+
fail("has a store but no needs: the store is where the secret it needs lives");
|
|
108
|
+
}
|
|
109
|
+
for (const link of ["feature", "flag"]) {
|
|
110
|
+
const v = spec[link];
|
|
111
|
+
if (v !== void 0 && (typeof v !== "string" || !v.trim())) fail(`${link} must be a non-empty id`);
|
|
112
|
+
}
|
|
113
|
+
if (spec.setup !== void 0 && (typeof spec.setup !== "string" || !SETUP_STEP_ID.test(spec.setup))) fail(`setup must be a step id like "github.issues" (got ${JSON.stringify(spec.setup)})`);
|
|
114
|
+
if (spec.feature !== void 0 && spec.type !== "boolean") fail("switches a feature, so it must be a boolean");
|
|
115
|
+
if (spec.integer !== void 0 && (typeof spec.integer !== "boolean" || spec.type !== "number")) fail("integer is a boolean, and only a number takes it");
|
|
116
|
+
const byPreset = isPresetDefaults(spec.default);
|
|
117
|
+
const defaults = byPreset ? { ...spec.default } : { max: spec.default, standard: spec.default, min: spec.default };
|
|
118
|
+
const nullable = SETTINGS_PRESETS.some((preset) => defaults[preset] === null);
|
|
119
|
+
const shape = { type: spec.type, min: spec.min, max: spec.max, options: spec.options, nullable, integer: spec.integer === true };
|
|
120
|
+
for (const preset of SETTINGS_PRESETS) {
|
|
121
|
+
const problem = settingValueProblem(shape, defaults[preset]);
|
|
122
|
+
if (problem) fail(`default${byPreset ? ` for ${preset}` : ""} ${problem}`);
|
|
123
|
+
}
|
|
124
|
+
const def = {
|
|
125
|
+
key,
|
|
126
|
+
namespace,
|
|
127
|
+
type: spec.type,
|
|
128
|
+
defaults: Object.freeze(defaults),
|
|
129
|
+
byPreset,
|
|
130
|
+
nullable,
|
|
131
|
+
scope,
|
|
132
|
+
applies,
|
|
133
|
+
requires: Object.freeze([...requires]),
|
|
134
|
+
...spec.min !== void 0 ? { min: spec.min } : {},
|
|
135
|
+
...spec.max !== void 0 ? { max: spec.max } : {},
|
|
136
|
+
...spec.options !== void 0 ? { options: Object.freeze([...spec.options]) } : {},
|
|
137
|
+
...secret ? { secret: Object.freeze(secret) } : {},
|
|
138
|
+
...spec.feature !== void 0 ? { feature: spec.feature } : {},
|
|
139
|
+
...spec.flag !== void 0 ? { flag: spec.flag } : {},
|
|
140
|
+
...spec.summary !== void 0 ? { summary: spec.summary } : {},
|
|
141
|
+
...spec.setup !== void 0 ? { setup: spec.setup } : {},
|
|
142
|
+
...spec.integer === true ? { integer: true } : {}
|
|
143
|
+
};
|
|
144
|
+
return Object.freeze(def);
|
|
145
|
+
}
|
|
146
|
+
function defineSettings(namespace, keys) {
|
|
147
|
+
if (typeof namespace !== "string" || !NAMESPACE.test(namespace)) {
|
|
148
|
+
throw new SettingsError(`defineSettings: ${JSON.stringify(namespace)} isn't a valid namespace (lower camelCase or kebab-case, like "support")`);
|
|
149
|
+
}
|
|
150
|
+
if (!isPlainObject(keys) || Object.keys(keys).length === 0) throw new SettingsError(`defineSettings("${namespace}"): declare at least one key`);
|
|
151
|
+
const out = dict();
|
|
152
|
+
for (const [name, spec] of Object.entries(keys)) {
|
|
153
|
+
const def = defineKey(namespace, name, spec);
|
|
154
|
+
out[def.key] = def;
|
|
155
|
+
}
|
|
156
|
+
return Object.freeze({ namespace, keys: Object.freeze(out) });
|
|
157
|
+
}
|
|
158
|
+
function settingsCatalogue(declarations) {
|
|
159
|
+
const keys = dict();
|
|
160
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
161
|
+
for (const decl of declarations) {
|
|
162
|
+
if (namespaces.has(decl.namespace)) throw new SettingsError(`settingsCatalogue: the namespace "${decl.namespace}" is declared twice`);
|
|
163
|
+
namespaces.add(decl.namespace);
|
|
164
|
+
for (const [key, def] of Object.entries(decl.keys)) {
|
|
165
|
+
if (!SETTING_KEY.test(key) || !isPlainObject(def) || def.key !== key || !key.startsWith(`${decl.namespace}.`)) {
|
|
166
|
+
throw new SettingsError(`settingsCatalogue: ${JSON.stringify(key)} in "${decl.namespace}" isn't a key defineSettings declared`);
|
|
167
|
+
}
|
|
168
|
+
if (own(keys, key)) throw new SettingsError(`settingsCatalogue: ${key} is declared twice`);
|
|
169
|
+
keys[key] = def;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const def of Object.values(keys)) {
|
|
173
|
+
for (const r of def.requires) if (!own(keys, r)) throw new SettingsError(`settingsCatalogue: ${def.key} requires ${r}, which no package declares`);
|
|
174
|
+
}
|
|
175
|
+
return Object.freeze({ keys: Object.freeze(keys) });
|
|
176
|
+
}
|
|
177
|
+
var OVERRIDE_LAYERS = ["file", "database", "tenant", "person"];
|
|
178
|
+
function sameValue(a, b) {
|
|
179
|
+
if (a === b) return true;
|
|
180
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
181
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
182
|
+
const ka = Object.keys(a);
|
|
183
|
+
const kb = Object.keys(b);
|
|
184
|
+
return ka.length === kb.length && ka.every((k) => sameValue(a[k], b[k]));
|
|
185
|
+
}
|
|
186
|
+
function isOn(value) {
|
|
187
|
+
return value !== false && value !== null && value !== void 0;
|
|
188
|
+
}
|
|
189
|
+
var SCOPE_LAYERS = Object.freeze({
|
|
190
|
+
app: Object.freeze(["file", "database"]),
|
|
191
|
+
tenant: Object.freeze(["file", "database", "tenant"]),
|
|
192
|
+
person: Object.freeze(["file", "database", "person"])
|
|
193
|
+
});
|
|
194
|
+
function layerRefusal(def, layer) {
|
|
195
|
+
if (def.applies === "build" && layer !== "file") {
|
|
196
|
+
return { kind: "build-only", message: `${def.key} applies at build time: only genesis.config.json sets it, not the ${layer} layer` };
|
|
197
|
+
}
|
|
198
|
+
if (!SCOPE_LAYERS[def.scope].includes(layer)) return { kind: "scope", message: `${def.key} has scope "${def.scope}": the ${layer} layer can't change it` };
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
function resolveSettings(catalogue, layers = {}) {
|
|
202
|
+
const problems = [];
|
|
203
|
+
let preset = layers.preset ?? DEFAULT_PRESET;
|
|
204
|
+
if (!SETTINGS_PRESETS.includes(preset)) {
|
|
205
|
+
problems.push({ kind: "preset", key: "preset", layer: "preset", message: `unknown preset ${JSON.stringify(preset)} (max, standard or min): resolved on ${DEFAULT_PRESET}` });
|
|
206
|
+
preset = DEFAULT_PRESET;
|
|
207
|
+
}
|
|
208
|
+
const values = dict();
|
|
209
|
+
const sources = dict();
|
|
210
|
+
for (const def of Object.values(catalogue.keys)) {
|
|
211
|
+
if (def.byPreset) {
|
|
212
|
+
values[def.key] = def.defaults[preset];
|
|
213
|
+
sources[def.key] = { layer: "preset" };
|
|
214
|
+
} else {
|
|
215
|
+
values[def.key] = def.defaults[DEFAULT_PRESET];
|
|
216
|
+
sources[def.key] = { layer: "default" };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const layer of OVERRIDE_LAYERS) {
|
|
220
|
+
const entries = layers[layer];
|
|
221
|
+
if (!entries) continue;
|
|
222
|
+
for (const [key, entry] of Object.entries(entries)) {
|
|
223
|
+
const def = own(catalogue.keys, key);
|
|
224
|
+
if (!def) {
|
|
225
|
+
problems.push({ kind: "unknown-key", key, layer, message: `${key} isn't a setting any installed package declares` });
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const refusal = layerRefusal(def, layer);
|
|
229
|
+
if (refusal) {
|
|
230
|
+
problems.push({ ...refusal, key, layer });
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const source = sources[key];
|
|
234
|
+
if (!isPlainObject(entry) || !Object.prototype.hasOwnProperty.call(entry, "value")) {
|
|
235
|
+
problems.push({ kind: "type", key, layer, message: `${key} in the ${layer} layer has no value` });
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const bad = settingValueProblem(def, entry.value);
|
|
239
|
+
if (bad) {
|
|
240
|
+
const locks = entry.locked === true && !source.lockedBy;
|
|
241
|
+
if (locks) sources[key] = { layer: source.layer, lockedBy: layer };
|
|
242
|
+
problems.push({ kind: "type", key, layer, message: `${key} ${bad} (the ${layer} layer has ${JSON.stringify(entry.value)})${locks ? `; its lock still holds the value from the ${source.layer} layer` : ""}` });
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (source.lockedBy) {
|
|
246
|
+
if (!sameValue(values[key], entry.value)) {
|
|
247
|
+
problems.push({ kind: "locked", key, layer, message: `${key} is locked by the ${source.lockedBy} layer: the ${layer} layer can't change it` });
|
|
248
|
+
}
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
values[key] = entry.value;
|
|
252
|
+
sources[key] = entry.locked === true ? { layer, lockedBy: layer } : { layer };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
for (const def of Object.values(catalogue.keys)) {
|
|
256
|
+
if (!def.requires.length || !isOn(values[def.key])) continue;
|
|
257
|
+
const off = def.requires.filter((r) => !isOn(values[r]));
|
|
258
|
+
if (off.length) {
|
|
259
|
+
problems.push({ kind: "requires", key: def.key, layer: sources[def.key].layer, message: `${def.key} is on but needs ${off.join(" and ")}, which ${off.length === 1 ? "is" : "are"} off` });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return Object.freeze({ preset, values: Object.freeze(values), sources: Object.freeze(sources), problems: Object.freeze(problems) });
|
|
263
|
+
}
|
|
264
|
+
function settingsLayerFromFile(settings) {
|
|
265
|
+
const out = dict();
|
|
266
|
+
for (const [key, raw] of Object.entries(settings ?? {})) out[key] = isLockedEntry(raw) ? { value: raw.value, locked: raw.locked } : { value: raw };
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
function isLockedEntry(raw) {
|
|
270
|
+
if (!isPlainObject(raw)) return false;
|
|
271
|
+
const keys = Object.keys(raw).sort();
|
|
272
|
+
return keys.length === 2 && keys[0] === "locked" && keys[1] === "value" && typeof raw.locked === "boolean";
|
|
273
|
+
}
|
|
274
|
+
function settingsLayerFromRows(rows) {
|
|
275
|
+
const out = dict();
|
|
276
|
+
for (const row of rows) out[row.key] = row.locked ? { value: row.value, locked: true } : { value: row.value };
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
function settingsSecrets(catalogue) {
|
|
280
|
+
return Object.values(catalogue.keys).filter((def) => def.secret !== void 0).map((def) => ({ key: def.key, name: def.secret.name, store: def.secret.store }));
|
|
281
|
+
}
|
|
282
|
+
function settingsGateContext(catalogue, resolved) {
|
|
283
|
+
const off = /* @__PURE__ */ new Set();
|
|
284
|
+
const flags = dict();
|
|
285
|
+
const lockedFeatures = /* @__PURE__ */ new Set();
|
|
286
|
+
const lockedFlags = /* @__PURE__ */ new Set();
|
|
287
|
+
for (const def of Object.values(catalogue.keys)) {
|
|
288
|
+
const value = own(resolved.values, def.key);
|
|
289
|
+
const lockedBy = own(resolved.sources, def.key)?.lockedBy;
|
|
290
|
+
const locked = lockedBy !== void 0 && APP_LOCK_LAYERS.includes(lockedBy);
|
|
291
|
+
if (def.feature && value === false) off.add(def.feature);
|
|
292
|
+
if (def.feature && locked) lockedFeatures.add(def.feature);
|
|
293
|
+
if (def.flag && value !== null && value !== void 0) {
|
|
294
|
+
flags[def.flag] = value;
|
|
295
|
+
if (locked) lockedFlags.add(def.flag);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return { off: [...off].sort(), flags, locked: { features: [...lockedFeatures].sort(), flags: [...lockedFlags].sort() } };
|
|
299
|
+
}
|
|
300
|
+
var APP_LOCK_LAYERS = Object.freeze(["file", "database"]);
|
|
301
|
+
function idTest(set) {
|
|
302
|
+
if (set === void 0) return () => false;
|
|
303
|
+
if (typeof set === "function") return set;
|
|
304
|
+
if (Array.isArray(set)) return (id) => set.includes(id);
|
|
305
|
+
const s = set;
|
|
306
|
+
return (id) => s.has(id);
|
|
307
|
+
}
|
|
308
|
+
function withSettings(ctx, catalogue, resolved) {
|
|
309
|
+
const gate = settingsGateContext(catalogue, resolved);
|
|
310
|
+
const ctxOff = idTest(ctx.off);
|
|
311
|
+
const ctxSettingsOff = idTest(ctx.settingsOff);
|
|
312
|
+
const settingsOff = new Set(gate.off);
|
|
313
|
+
const lockedFeatures = new Set(gate.locked.features);
|
|
314
|
+
const lockedFlags = new Set(gate.locked.flags);
|
|
315
|
+
const flags = ctx.flags;
|
|
316
|
+
const flagOf = flags === void 0 ? () => void 0 : typeof flags === "function" ? flags : (name) => Object.prototype.hasOwnProperty.call(flags, name) ? flags[name] : void 0;
|
|
317
|
+
return {
|
|
318
|
+
...ctx,
|
|
319
|
+
settingsOff: (id) => settingsOff.has(id) || ctxSettingsOff(id),
|
|
320
|
+
off: (id) => !lockedFeatures.has(id) && ctxOff(id),
|
|
321
|
+
flags: (name) => {
|
|
322
|
+
const setting = own(gate.flags, name);
|
|
323
|
+
if (lockedFlags.has(name)) return setting;
|
|
324
|
+
const fromCtx = flagOf(name);
|
|
325
|
+
return fromCtx !== void 0 ? fromCtx : setting;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function catalogueManifest(catalogue) {
|
|
330
|
+
const out = dict();
|
|
331
|
+
for (const def of Object.values(catalogue.keys)) {
|
|
332
|
+
out[def.key] = {
|
|
333
|
+
type: def.type,
|
|
334
|
+
applies: def.applies,
|
|
335
|
+
scope: def.scope,
|
|
336
|
+
...def.min !== void 0 ? { min: def.min } : {},
|
|
337
|
+
...def.max !== void 0 ? { max: def.max } : {},
|
|
338
|
+
...def.options !== void 0 ? { options: def.options } : {},
|
|
339
|
+
...def.nullable ? { nullable: true } : {},
|
|
340
|
+
...def.integer ? { integer: true } : {}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
return out;
|
|
344
|
+
}
|
|
345
|
+
function settingsFromManifest(raw, where = "genesis.settings") {
|
|
346
|
+
if (!isPlainObject(raw) || typeof raw.namespace !== "string" || !isPlainObject(raw.keys)) {
|
|
347
|
+
throw new SettingsError(`${where} must be { "namespace": "\u2026", "keys": { \u2026 } }`);
|
|
348
|
+
}
|
|
349
|
+
return defineSettings(raw.namespace, raw.keys);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export { APP_LOCK_LAYERS, DEFAULT_PRESET, SCOPE_LAYERS, SETTINGS_LAYERS, SETTINGS_PRESETS, SETTING_KEY, SETTING_TYPES, SETUP_STEP_ID, SettingsError, catalogueManifest, defineSettings, isLockedEntry, isPresetDefaults, resolveSettings, settingValueProblem, settingsCatalogue, settingsFromManifest, settingsGateContext, settingsLayerFromFile, settingsLayerFromRows, settingsSecrets, withSettings };
|
|
353
|
+
//# sourceMappingURL=chunk-UD7SPYZH.js.map
|
|
354
|
+
//# sourceMappingURL=chunk-UD7SPYZH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/settings.ts"],"names":[],"mappings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AA,EAAS,IAAA,KAAkB;AAAC,KAClD;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT;AASO,SAAS,oBAAA,CAAqB,GAAA,EAAc,KAAA,GAAQ,kBAAA,EAAyC;AAClG,EAAA,IAAI,CAAC,aAAA,CAAc,GAAG,CAAA,IAAK,OAAO,GAAA,CAAI,SAAA,KAAc,QAAA,IAAY,CAAC,aAAA,CAAc,GAAA,CAAI,IAAI,CAAA,EAAG;AACxF,IAAA,MAAM,IAAI,aAAA,CAAc,CAAA,EAAG,KAAK,CAAA,sDAAA,CAA8C,CAAA;AAAA,EAChF;AACA,EAAA,OAAO,cAAA,CAAe,GAAA,CAAI,SAAA,EAAW,GAAA,CAAI,IAAsC,CAAA;AACjF","file":"chunk-UD7SPYZH.js","sourcesContent":["/**\n * Settings: every Genesis package declares its settings with {@link defineSettings}, the app builds\n * one catalogue from them ({@link settingsCatalogue}), and one resolver ({@link resolveSettings})\n * turns the layers into values, with where each came from and what was wrong.\n *\n * Layers, low to high (a later layer wins unless an earlier layer locked the value):\n *\n * 1. default the declared default (for a per-preset default, the `max` value)\n * 2. preset `max` (Genesis's default), `standard` or `min`: keys with a per-preset default\n * 3. file genesis.config.json `settings`, committed and reviewed like code\n * 4. database the app's `genesis_settings` table, changed live by platform admins\n * 5. tenant only keys declared `scope: \"tenant\"`\n * 6. person only keys declared `scope: \"person\"`\n *\n * A key declared `applies: \"build\"` takes effect only from a new build, so only the default,\n * preset and file layers set it. Secrets are never settings: a key names the secret it needs\n * (`needs: \"secret:NAME\"`) and the store it lives in, never its value.\n *\n * Feeding the gate: a boolean key linked to a feature (`feature`) that resolves to false puts the\n * feature in `GateContext.off`; a key linked to a flag (`flag`) gives that flag its value\n * ({@link settingsGateContext}, {@link withSettings}). There is no second gate.\n *\n * No zod, React, Node built-ins or DOM globals here: it ships to browsers, phones, edge functions\n * and servers (`@marktiderman/genesis-config/settings`).\n */\nimport type { GateContext, IdSet } from \"./gate\";\nimport type { FlagValue } from \"./types\";\n\n/** The presets: `max` (the default) turns everything on. @stability Beta */\nexport const SETTINGS_PRESETS = [\"max\", \"standard\", \"min\"] as const;\n/** @stability Beta */\nexport type SettingsPreset = (typeof SETTINGS_PRESETS)[number];\n/** Genesis's default preset: zero config is everything on. @stability Beta */\nexport const DEFAULT_PRESET: SettingsPreset = \"max\";\n\n/** @stability Beta */\nexport const SETTING_TYPES = [\"boolean\", \"number\", \"string\", \"list\", \"object\"] as const;\n/** @stability Beta */\nexport type SettingType = (typeof SETTING_TYPES)[number];\n\n/** The lowest layer that may change a key: the app (file, database), a tenant, or a person. @stability Beta */\nexport type SettingScope = \"app\" | \"tenant\" | \"person\";\n/** `build`: needs a new binary or bundle. `runtime`: takes effect live. @stability Beta */\nexport type SettingApplies = \"build\" | \"runtime\";\n/** Where a secret a key needs is kept (config-layer §9). @stability Beta */\nexport type SecretStore = \"vault\" | \"edge\" | \"server-env\" | \"ci\";\n\n/** The layers, low to high. @stability Beta */\nexport const SETTINGS_LAYERS = [\"default\", \"preset\", \"file\", \"database\", \"tenant\", \"person\"] as const;\n/** @stability Beta */\nexport type SettingsLayer = (typeof SETTINGS_LAYERS)[number];\n\n/** A value by preset. All three are given. @stability Beta */\nexport interface PresetDefaults<T> {\n max: T;\n standard: T;\n min: T;\n}\n\n/** The value a type holds. @stability Beta */\nexport type SettingValueOf<K extends SettingType> = K extends \"boolean\"\n ? boolean\n : K extends \"number\"\n ? number\n : K extends \"string\"\n ? string\n : K extends \"list\"\n ? readonly (string | number)[]\n : { readonly [key: string]: unknown };\n\n/**\n * One key, as a package declares it.\n *\n * @stability Beta\n */\nexport interface SettingSpec<K extends SettingType = SettingType> {\n type: K;\n /** The default, or one per preset (`{ max, standard, min }`). `null` means \"not set\" (a string to fill in, say). */\n default: SettingValueOf<K> | null | PresetDefaults<SettingValueOf<K> | null>;\n /** The lowest layer that may change it. Default `app`. */\n scope?: SettingScope;\n /** Default `runtime`. A `build` key can't have a tenant or person scope. */\n applies?: SettingApplies;\n /** Other keys (`namespace.key`) that must be on while this one is on. */\n requires?: readonly string[];\n /** A number's bounds, or a list's length. */\n min?: number;\n max?: number;\n /** The values a string or number may take, or a list's items. */\n options?: readonly (string | number)[];\n /** The secret it needs, by name only: `\"secret:GITHUB_TOKEN\"`. The value is never a setting. */\n needs?: `secret:${string}`;\n /** Where that secret is kept. Default `edge` (an Edge Function secret). Only with `needs`. */\n store?: SecretStore;\n /** A feature id (features.ts) this boolean switches: false puts it in `GateContext.off`. */\n feature?: string;\n /** A flag name (flags.json) this key gives its value to. */\n flag?: string;\n /** One line for the Settings screen and the agent. */\n summary?: string;\n /**\n * The guided setup step that configures it, when it needs an outside service (`github.issues`):\n * `genesis setup --step <id>`. The doctor's `setup-incomplete` names it while the key is unset.\n */\n setup?: string;\n /** A number that must be whole (a count, days, milliseconds). Only a number takes it. */\n integer?: boolean;\n}\n\n/** A declared key with its namespace folded in and its defaults filled. @stability Beta */\nexport interface SettingDef {\n /** `namespace.key` */\n readonly key: string;\n readonly namespace: string;\n readonly type: SettingType;\n /** The default for each preset (the same value three times for a plain default). */\n readonly defaults: Readonly<PresetDefaults<unknown>>;\n /** True when the default differs by preset (resolved by the preset layer). */\n readonly byPreset: boolean;\n /** True when a default is `null` (\"not set\"): only then may a layer set `null`. */\n readonly nullable: boolean;\n readonly scope: SettingScope;\n readonly applies: SettingApplies;\n readonly requires: readonly string[];\n readonly min?: number;\n readonly max?: number;\n readonly options?: readonly (string | number)[];\n readonly secret?: { readonly name: string; readonly store: SecretStore };\n readonly feature?: string;\n readonly flag?: string;\n readonly summary?: string;\n readonly setup?: string;\n readonly integer?: true;\n}\n\n/** What {@link defineSettings} returns: one package's keys. @stability Beta */\nexport interface SettingsDeclaration<N extends string = string, Keys extends string = string> {\n readonly namespace: N;\n readonly keys: { readonly [K in Keys as `${N}.${K}`]: SettingDef };\n}\n\n/** A declaration or catalogue that can't be used. @stability Beta */\nexport class SettingsError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SettingsError\";\n }\n}\n\nconst NAMESPACE = /^[a-z][a-zA-Z0-9]*(?:-[a-z0-9]+)*$/;\nconst KEY = /^[a-z][a-zA-Z0-9]*$/;\n/** A full key: `namespace.key`, or `namespace.group.key` is not allowed (one level). */\nexport const SETTING_KEY = /^[a-z][a-zA-Z0-9]*(?:-[a-z0-9]+)*\\.[a-z][a-zA-Z0-9]*$/;\nconst SECRET_NAME = /^[A-Z][A-Z0-9_]*$/;\n/** A setup step id: `github.issues`, `ai.key-budget`. */\nexport const SETUP_STEP_ID = /^[a-z][a-z0-9-]*(?:\\.[a-z0-9][a-z0-9-]*)*$/;\nconst SPEC_KEYS = new Set([\"type\", \"default\", \"scope\", \"applies\", \"requires\", \"min\", \"max\", \"options\", \"needs\", \"store\", \"feature\", \"flag\", \"summary\", \"setup\", \"integer\"]);\nconst SCOPES: readonly SettingScope[] = [\"app\", \"tenant\", \"person\"];\nconst APPLIES: readonly SettingApplies[] = [\"build\", \"runtime\"];\nconst STORES: readonly SecretStore[] = [\"vault\", \"edge\", \"server-env\", \"ci\"];\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n if (typeof v !== \"object\" || v === null || Array.isArray(v)) return false;\n const proto = Object.getPrototypeOf(v) as unknown;\n return proto === Object.prototype || proto === null;\n}\n\n/** `obj[key]` when `key` is its own property: never `__proto__`, `constructor` or `toString` from a prototype. */\nfunction own<T>(obj: { readonly [key: string]: T }, key: string): T | undefined {\n return Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : undefined;\n}\n\n/** An empty map with no prototype, so no key (`__proto__`, `constructor`) means anything but itself. */\nfunction dict<T>(): Record<string, T> {\n return Object.create(null) as Record<string, T>;\n}\n\n/** A per-preset default: an object with exactly `max`, `standard` and `min`. */\nexport function isPresetDefaults(v: unknown): v is PresetDefaults<unknown> {\n if (!isPlainObject(v)) return false;\n const keys = Object.keys(v).sort();\n return keys.length === 3 && keys[0] === \"max\" && keys[1] === \"min\" && keys[2] === \"standard\";\n}\n\n/**\n * Why a value doesn't fit a key's type and bounds, or null when it does. `null` (\"not set\") fits\n * only a key whose default is `null` (`nullable`).\n */\nexport function settingValueProblem(def: Pick<SettingDef, \"type\" | \"min\" | \"max\" | \"options\"> & { nullable?: boolean; integer?: boolean }, value: unknown): string | null {\n if (value === null) return def.nullable ? null : \"can't be null: it has a default, so set a value\";\n switch (def.type) {\n case \"boolean\":\n if (typeof value !== \"boolean\") return \"must be true or false\";\n return null;\n case \"number\":\n if (typeof value !== \"number\" || !Number.isFinite(value)) return \"must be a number\";\n if (def.integer && !Number.isInteger(value)) return \"must be a whole number\";\n if (def.min !== undefined && value < def.min) return `must be at least ${def.min}`;\n if (def.max !== undefined && value > def.max) return `must be at most ${def.max}`;\n if (def.options && !def.options.includes(value)) return `must be one of ${def.options.join(\", \")}`;\n return null;\n case \"string\":\n if (typeof value !== \"string\") return \"must be a string\";\n if (def.options && !def.options.includes(value)) return `must be one of ${def.options.map((o) => JSON.stringify(o)).join(\", \")}`;\n return null;\n case \"list\":\n if (!Array.isArray(value) || value.some((item) => typeof item !== \"string\" && typeof item !== \"number\")) return \"must be a list of strings or numbers\";\n if (def.min !== undefined && value.length < def.min) return `must have at least ${def.min} items`;\n if (def.max !== undefined && value.length > def.max) return `must have at most ${def.max} items`;\n if (def.options) {\n const bad = value.find((item) => !def.options!.includes(item));\n if (bad !== undefined) return `has ${JSON.stringify(bad)}, which isn't one of ${def.options.map((o) => JSON.stringify(o)).join(\", \")}`;\n }\n return null;\n case \"object\":\n if (!isPlainObject(value)) return \"must be an object\";\n return null;\n }\n}\n\n/** One key's spec, checked and normalised. Throws a SettingsError naming the key. */\nfunction defineKey(namespace: string, name: string, spec: SettingSpec): SettingDef {\n const key = `${namespace}.${name}`;\n const fail = (msg: string): never => {\n throw new SettingsError(`defineSettings(\"${namespace}\"): ${key} ${msg}`);\n };\n if (!KEY.test(name)) fail(`isn't a valid key name (camelCase letters and digits)`);\n if (!isPlainObject(spec)) fail(\"must be an object\");\n for (const k of Object.keys(spec)) if (!SPEC_KEYS.has(k)) fail(`has an unknown field \"${k}\"`);\n if (!SETTING_TYPES.includes(spec.type)) fail(`has type ${JSON.stringify(spec.type)} (one of ${SETTING_TYPES.join(\", \")})`);\n if (!Object.prototype.hasOwnProperty.call(spec, \"default\")) fail(\"needs a default (null for none)\");\n const scope = spec.scope ?? \"app\";\n const applies = spec.applies ?? \"runtime\";\n if (!SCOPES.includes(scope)) fail(`has scope ${JSON.stringify(scope)} (app, tenant or person)`);\n if (!APPLIES.includes(applies)) fail(`has applies ${JSON.stringify(applies)} (build or runtime)`);\n if (applies === \"build\" && scope !== \"app\") fail(`applies at build time, so it can't have a ${scope} scope (a build is the app's)`);\n for (const bound of [\"min\", \"max\"] as const) {\n const v = spec[bound];\n if (v !== undefined && (typeof v !== \"number\" || !Number.isFinite(v))) fail(`${bound} must be a number`);\n if (v !== undefined && spec.type !== \"number\" && spec.type !== \"list\") fail(`has ${bound}, which only a number or a list takes`);\n }\n if (spec.min !== undefined && spec.max !== undefined && spec.min > spec.max) fail(\"has min above max\");\n if (spec.options !== undefined) {\n if (!Array.isArray(spec.options) || spec.options.length === 0) fail(\"options must be a non-empty list\");\n if (spec.type === \"boolean\" || spec.type === \"object\") fail(`has options, which a ${spec.type} doesn't take`);\n }\n const requires = spec.requires ?? [];\n if (!Array.isArray(requires)) fail(\"requires must be a list of keys\");\n for (const r of requires) {\n if (typeof r !== \"string\" || !SETTING_KEY.test(r)) fail(`requires ${JSON.stringify(r)}, which isn't a full key (namespace.key)`);\n if (r === key) fail(\"requires itself\");\n }\n let secret: SettingDef[\"secret\"];\n if (spec.needs !== undefined) {\n const m = typeof spec.needs === \"string\" ? /^secret:(.+)$/.exec(spec.needs) : null;\n if (!m || !SECRET_NAME.test(m[1]!)) fail(`needs ${JSON.stringify(spec.needs)}: write \"secret:NAME\" with the secret's NAME in capitals (never its value)`);\n const store = spec.store ?? \"edge\";\n if (!STORES.includes(store)) fail(`has store ${JSON.stringify(store)} (vault, edge, server-env or ci)`);\n secret = { name: m![1]!, store };\n } else if (spec.store !== undefined) {\n fail(\"has a store but no needs: the store is where the secret it needs lives\");\n }\n for (const link of [\"feature\", \"flag\"] as const) {\n const v = spec[link];\n if (v !== undefined && (typeof v !== \"string\" || !v.trim())) fail(`${link} must be a non-empty id`);\n }\n if (spec.setup !== undefined && (typeof spec.setup !== \"string\" || !SETUP_STEP_ID.test(spec.setup))) fail(`setup must be a step id like \"github.issues\" (got ${JSON.stringify(spec.setup)})`);\n if (spec.feature !== undefined && spec.type !== \"boolean\") fail(\"switches a feature, so it must be a boolean\");\n if (spec.integer !== undefined && (typeof spec.integer !== \"boolean\" || spec.type !== \"number\")) fail(\"integer is a boolean, and only a number takes it\");\n const byPreset = isPresetDefaults(spec.default);\n const defaults = byPreset\n ? { ...(spec.default as PresetDefaults<unknown>) }\n : { max: spec.default as unknown, standard: spec.default as unknown, min: spec.default as unknown };\n const nullable = SETTINGS_PRESETS.some((preset) => defaults[preset] === null);\n const shape = { type: spec.type, min: spec.min, max: spec.max, options: spec.options, nullable, integer: spec.integer === true };\n for (const preset of SETTINGS_PRESETS) {\n const problem = settingValueProblem(shape, defaults[preset]);\n if (problem) fail(`default${byPreset ? ` for ${preset}` : \"\"} ${problem}`);\n }\n const def: SettingDef = {\n key,\n namespace,\n type: spec.type,\n defaults: Object.freeze(defaults),\n byPreset,\n nullable,\n scope,\n applies,\n requires: Object.freeze([...requires]),\n ...(spec.min !== undefined ? { min: spec.min } : {}),\n ...(spec.max !== undefined ? { max: spec.max } : {}),\n ...(spec.options !== undefined ? { options: Object.freeze([...spec.options]) } : {}),\n ...(secret ? { secret: Object.freeze(secret) } : {}),\n ...(spec.feature !== undefined ? { feature: spec.feature } : {}),\n ...(spec.flag !== undefined ? { flag: spec.flag } : {}),\n ...(spec.summary !== undefined ? { summary: spec.summary } : {}),\n ...(spec.setup !== undefined ? { setup: spec.setup } : {}),\n ...(spec.integer === true ? { integer: true as const } : {}),\n };\n return Object.freeze(def);\n}\n\n/**\n * A package's settings, declared next to its `defineBlock`. Keys are `namespace.key`.\n *\n * ```ts\n * export const supportSettings = defineSettings(\"support\", {\n * messenger: { type: \"boolean\", default: { max: true, standard: true, min: false }, scope: \"tenant\" },\n * dumpRetentionDays: { type: \"number\", default: 90, min: 7, max: 365 },\n * githubRepo: { type: \"string\", default: null, needs: \"secret:GITHUB_TOKEN\", store: \"edge\" },\n * });\n * ```\n *\n * Throws a {@link SettingsError} for a declaration that can't be used (an unknown field, a\n * default outside its bounds, a build-time key with a tenant scope, a secret value instead of a name).\n *\n * @stability Beta\n */\nexport function defineSettings<const N extends string, const S extends { readonly [key: string]: SettingSpec }>(\n namespace: N,\n keys: S,\n): SettingsDeclaration<N, Extract<keyof S, string>> {\n if (typeof namespace !== \"string\" || !NAMESPACE.test(namespace)) {\n throw new SettingsError(`defineSettings: ${JSON.stringify(namespace)} isn't a valid namespace (lower camelCase or kebab-case, like \"support\")`);\n }\n if (!isPlainObject(keys) || Object.keys(keys).length === 0) throw new SettingsError(`defineSettings(\"${namespace}\"): declare at least one key`);\n const out = dict<SettingDef>();\n for (const [name, spec] of Object.entries(keys)) {\n const def = defineKey(namespace, name, spec as SettingSpec);\n out[def.key] = def;\n }\n return Object.freeze({ namespace, keys: Object.freeze(out) }) as unknown as SettingsDeclaration<N, Extract<keyof S, string>>;\n}\n\n/** Every package's keys in one place. @stability Beta */\nexport interface SettingsCatalogue {\n readonly keys: { readonly [key: string]: SettingDef };\n}\n\n/**\n * One catalogue from every package's declarations (the way features.ts builds the registry).\n * Throws a {@link SettingsError} when two declarations share a namespace or a key, or a key\n * requires one no declaration has.\n *\n * @stability Beta\n */\nexport function settingsCatalogue(declarations: readonly SettingsDeclaration[]): SettingsCatalogue {\n const keys = dict<SettingDef>();\n const namespaces = new Set<string>();\n for (const decl of declarations) {\n if (namespaces.has(decl.namespace)) throw new SettingsError(`settingsCatalogue: the namespace \"${decl.namespace}\" is declared twice`);\n namespaces.add(decl.namespace);\n for (const [key, def] of Object.entries(decl.keys)) {\n // Only what defineSettings made: a hand-built declaration with a key like `__proto__` is refused.\n if (!SETTING_KEY.test(key) || !isPlainObject(def) || (def as SettingDef).key !== key || !key.startsWith(`${decl.namespace}.`)) {\n throw new SettingsError(`settingsCatalogue: ${JSON.stringify(key)} in \"${decl.namespace}\" isn't a key defineSettings declared`);\n }\n if (own(keys, key)) throw new SettingsError(`settingsCatalogue: ${key} is declared twice`);\n keys[key] = def as SettingDef;\n }\n }\n for (const def of Object.values(keys)) {\n for (const r of def.requires) if (!own(keys, r)) throw new SettingsError(`settingsCatalogue: ${def.key} requires ${r}, which no package declares`);\n }\n return Object.freeze({ keys: Object.freeze(keys) });\n}\n\n/**\n * One key's value in a layer. `locked: true` stops every later layer from changing it.\n *\n * @stability Beta\n */\nexport interface SettingEntry {\n value: unknown;\n locked?: boolean;\n}\n\n/** A layer's values by full key. @stability Beta */\nexport type SettingsLayerValues = { readonly [key: string]: SettingEntry };\n\n/**\n * The layers to resolve. Leave out what the caller doesn't have: no `preset` is `max`, no\n * `tenant` means no tenant has changed anything.\n *\n * @stability Beta\n */\nexport interface SettingsLayers {\n preset?: SettingsPreset;\n file?: SettingsLayerValues;\n database?: SettingsLayerValues;\n tenant?: SettingsLayerValues;\n person?: SettingsLayerValues;\n}\n\n/** @stability Beta */\nexport type SettingsProblemKind = \"unknown-key\" | \"type\" | \"scope\" | \"build-only\" | \"locked\" | \"requires\" | \"preset\";\n\n/**\n * Something wrong in the layers: the value was ignored (every kind but `requires`, which keeps\n * the value and says what it needs).\n *\n * @stability Beta\n */\nexport interface SettingsProblem {\n kind: SettingsProblemKind;\n key: string;\n /** The layer the problem is in. For `requires`, the layer that set the key. */\n layer: SettingsLayer;\n message: string;\n}\n\n/** Where a value came from, and the layer that locked it, if any. @stability Beta */\nexport interface SettingSource {\n layer: SettingsLayer;\n lockedBy?: SettingsLayer;\n}\n\n/** @stability Beta */\nexport interface ResolvedSettings {\n readonly preset: SettingsPreset;\n readonly values: { readonly [key: string]: unknown };\n readonly sources: { readonly [key: string]: SettingSource };\n readonly problems: readonly SettingsProblem[];\n}\n\nconst OVERRIDE_LAYERS = [\"file\", \"database\", \"tenant\", \"person\"] as const;\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const ka = Object.keys(a as object);\n const kb = Object.keys(b as object);\n return ka.length === kb.length && ka.every((k) => sameValue((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]));\n}\n\n/** On, for `requires`: anything but false, null or not set. */\nfunction isOn(value: unknown): boolean {\n return value !== false && value !== null && value !== undefined;\n}\n\n/**\n * The scope rule, in one place: which override layers may set a key of each scope. The app's own\n * layers (file, database) set every key; the tenant layer only keys declared `scope: \"tenant\"`,\n * the person layer only keys declared `scope: \"person\"` (decision C2, read literally). Changing\n * this table is the whole change if that reading changes.\n *\n * @stability Beta\n */\nexport const SCOPE_LAYERS: Readonly<Record<SettingScope, readonly SettingsLayer[]>> = Object.freeze({\n app: Object.freeze([\"file\", \"database\"] as SettingsLayer[]),\n tenant: Object.freeze([\"file\", \"database\", \"tenant\"] as SettingsLayer[]),\n person: Object.freeze([\"file\", \"database\", \"person\"] as SettingsLayer[]),\n});\n\n/** Why a layer may not set a key at all, or null. */\nfunction layerRefusal(def: SettingDef, layer: (typeof OVERRIDE_LAYERS)[number]): { kind: SettingsProblemKind; message: string } | null {\n if (def.applies === \"build\" && layer !== \"file\") {\n return { kind: \"build-only\", message: `${def.key} applies at build time: only genesis.config.json sets it, not the ${layer} layer` };\n }\n if (!SCOPE_LAYERS[def.scope].includes(layer)) return { kind: \"scope\", message: `${def.key} has scope \"${def.scope}\": the ${layer} layer can't change it` };\n return null;\n}\n\n/**\n * Resolve every key in the catalogue through the layers. Later layers win unless an earlier one\n * locked the value. Problems never throw: a bad entry is reported and skipped, so one typo in a\n * table never takes the app down.\n *\n * - `unknown-key`: no package declares it.\n * - `type`: the value doesn't fit the key's type or bounds.\n * - `scope`: a tenant or person entry for a key not declared with that scope.\n * - `build-only`: a database, tenant or person entry for a key that applies at build time.\n * - `locked`: a later layer tried to change a value an earlier layer locked (setting the same\n * value again isn't a problem).\n * - `requires`: a key is on while a key it requires is off. The value stays; the screen and the\n * doctor show what's missing.\n * - `preset`: an unknown preset; the layers resolve on `max`.\n *\n * A lock whose own value is bad still locks: the value from the layers below stays, pinned, and\n * the bad value is reported (`type`). A lock never fails open.\n *\n * @stability Beta\n */\nexport function resolveSettings(catalogue: SettingsCatalogue, layers: SettingsLayers = {}): ResolvedSettings {\n const problems: SettingsProblem[] = [];\n let preset: SettingsPreset = layers.preset ?? DEFAULT_PRESET;\n if (!SETTINGS_PRESETS.includes(preset)) {\n problems.push({ kind: \"preset\", key: \"preset\", layer: \"preset\", message: `unknown preset ${JSON.stringify(preset)} (max, standard or min): resolved on ${DEFAULT_PRESET}` });\n preset = DEFAULT_PRESET;\n }\n const values = dict<unknown>();\n const sources = dict<SettingSource>();\n for (const def of Object.values(catalogue.keys)) {\n if (def.byPreset) {\n values[def.key] = def.defaults[preset];\n sources[def.key] = { layer: \"preset\" };\n } else {\n values[def.key] = def.defaults[DEFAULT_PRESET];\n sources[def.key] = { layer: \"default\" };\n }\n }\n for (const layer of OVERRIDE_LAYERS) {\n const entries = layers[layer];\n if (!entries) continue;\n for (const [key, entry] of Object.entries(entries)) {\n const def = own(catalogue.keys, key);\n if (!def) {\n problems.push({ kind: \"unknown-key\", key, layer, message: `${key} isn't a setting any installed package declares` });\n continue;\n }\n const refusal = layerRefusal(def, layer);\n if (refusal) {\n problems.push({ ...refusal, key, layer });\n continue;\n }\n const source = sources[key]!;\n if (!isPlainObject(entry) || !Object.prototype.hasOwnProperty.call(entry, \"value\")) {\n problems.push({ kind: \"type\", key, layer, message: `${key} in the ${layer} layer has no value` });\n continue;\n }\n const bad = settingValueProblem(def, entry.value);\n if (bad) {\n // A bad value under a lock still locks: what the layers below gave stays, pinned.\n const locks = entry.locked === true && !source.lockedBy;\n if (locks) sources[key] = { layer: source.layer, lockedBy: layer };\n problems.push({ kind: \"type\", key, layer, message: `${key} ${bad} (the ${layer} layer has ${JSON.stringify(entry.value)})${locks ? `; its lock still holds the value from the ${source.layer} layer` : \"\"}` });\n continue;\n }\n if (source.lockedBy) {\n if (!sameValue(values[key], entry.value)) {\n problems.push({ kind: \"locked\", key, layer, message: `${key} is locked by the ${source.lockedBy} layer: the ${layer} layer can't change it` });\n }\n continue;\n }\n values[key] = entry.value;\n sources[key] = entry.locked === true ? { layer, lockedBy: layer } : { layer };\n }\n }\n for (const def of Object.values(catalogue.keys)) {\n if (!def.requires.length || !isOn(values[def.key])) continue;\n const off = def.requires.filter((r) => !isOn(values[r]));\n if (off.length) {\n problems.push({ kind: \"requires\", key: def.key, layer: sources[def.key]!.layer, message: `${def.key} is on but needs ${off.join(\" and \")}, which ${off.length === 1 ? \"is\" : \"are\"} off` });\n }\n }\n return Object.freeze({ preset, values: Object.freeze(values), sources: Object.freeze(sources), problems: Object.freeze(problems) });\n}\n\n/**\n * genesis.config.json's `settings`, as a layer. Each key holds its value, or `{ \"value\": …,\n * \"locked\": true }` to lock it: an object with exactly `value` and `locked` (a boolean) is that\n * wrapper; any other object is the value itself.\n *\n * @stability Beta\n */\nexport function settingsLayerFromFile(settings: { readonly [key: string]: unknown } | undefined): SettingsLayerValues {\n const out = dict<SettingEntry>();\n for (const [key, raw] of Object.entries(settings ?? {})) out[key] = isLockedEntry(raw) ? { value: raw.value, locked: raw.locked } : { value: raw };\n return out;\n}\n\n/** `{ value, locked }` exactly, with a boolean lock: the file's way to lock a value. @stability Beta */\nexport function isLockedEntry(raw: unknown): raw is { value: unknown; locked: boolean } {\n if (!isPlainObject(raw)) return false;\n const keys = Object.keys(raw).sort();\n return keys.length === 2 && keys[0] === \"locked\" && keys[1] === \"value\" && typeof raw.locked === \"boolean\";\n}\n\n/** Rows (`{ key, value, locked }`, as the database returns them) as a layer. @stability Beta */\nexport function settingsLayerFromRows(rows: readonly { key: string; value: unknown; locked?: boolean | null }[]): SettingsLayerValues {\n const out = dict<SettingEntry>();\n for (const row of rows) out[row.key] = row.locked ? { value: row.value, locked: true } : { value: row.value };\n return out;\n}\n\n/** The secrets the catalogue's keys need, by name and store, never by value. @stability Beta */\nexport function settingsSecrets(catalogue: SettingsCatalogue): Array<{ key: string; name: string; store: SecretStore }> {\n return Object.values(catalogue.keys)\n .filter((def): def is SettingDef & { secret: NonNullable<SettingDef[\"secret\"]> } => def.secret !== undefined)\n .map((def) => ({ key: def.key, name: def.secret.name, store: def.secret.store }));\n}\n\n/** What the resolved settings say to the gate. @stability Beta */\nexport interface SettingsGate {\n /** Features a boolean key linked with `feature` switched off (resolved to false). */\n off: string[];\n /** Flag values from keys linked with `flag`, when set. */\n flags: { [name: string]: FlagValue };\n /** The features and flags whose keys the app locked (file or database): the context's own switches and flag values don't change them. */\n locked: { features: string[]; flags: string[] };\n}\n\n/**\n * What the resolved settings say to the gate: the features switched off (a boolean key linked\n * with `feature` that resolved to false), flag values (a key linked with `flag`, when set), and\n * which of those are locked.\n *\n * @stability Beta\n */\nexport function settingsGateContext(catalogue: SettingsCatalogue, resolved: ResolvedSettings): SettingsGate {\n const off = new Set<string>();\n const flags = dict<FlagValue>();\n const lockedFeatures = new Set<string>();\n const lockedFlags = new Set<string>();\n for (const def of Object.values(catalogue.keys)) {\n const value = own(resolved.values, def.key);\n // Only the app's own locks (genesis.config.json, the database) outrank the gate context. A tenant\n // or person lock stops later settings layers, nothing more: it never beats a platform flag, an\n // entitlement, or (for a person) the tenant's switch.\n const lockedBy = own(resolved.sources, def.key)?.lockedBy;\n const locked = lockedBy !== undefined && (APP_LOCK_LAYERS as readonly string[]).includes(lockedBy);\n if (def.feature && value === false) off.add(def.feature);\n if (def.feature && locked) lockedFeatures.add(def.feature);\n if (def.flag && value !== null && value !== undefined) {\n flags[def.flag] = value as FlagValue;\n if (locked) lockedFlags.add(def.flag);\n }\n }\n return { off: [...off].sort(), flags, locked: { features: [...lockedFeatures].sort(), flags: [...lockedFlags].sort() } };\n}\n\n/** The layers whose locks outrank the gate context: the app's own. @stability Beta */\nexport const APP_LOCK_LAYERS: readonly SettingsLayer[] = Object.freeze([\"file\", \"database\"] as SettingsLayer[]);\n\nfunction idTest(set: IdSet | undefined): (id: string) => boolean {\n if (set === undefined) return () => false;\n if (typeof set === \"function\") return set;\n if (Array.isArray(set)) return (id) => set.includes(id);\n const s = set as ReadonlySet<string>;\n return (id) => s.has(id);\n}\n\n/**\n * A gate context with the resolved settings folded in. The gate itself doesn't change:\n *\n * - a feature a setting switched off goes in `settingsOff`, so `featureOn` answers `reason:\n * \"setting\"`;\n * - a flag the context doesn't set takes the setting's value;\n * - a setting the app locked (genesis.config.json or the database) wins over the context: the\n * tenant's switch (`off`) can't turn off a feature whose key the app locked on, and the context's\n * flag value can't change a flag the app locked. A tenant or person lock only stops later\n * settings layers: the context's switch and flags still apply over it.\n *\n * ```ts\n * const ctx = withSettings({ platform: \"web\", entitlements, off: tenantOff }, catalogue, resolved);\n * featureOn({ features }, ctx, \"support-messenger\");\n * ```\n *\n * @stability Beta\n */\nexport function withSettings(ctx: GateContext, catalogue: SettingsCatalogue, resolved: ResolvedSettings): GateContext {\n const gate = settingsGateContext(catalogue, resolved);\n const ctxOff = idTest(ctx.off);\n const ctxSettingsOff = idTest(ctx.settingsOff);\n const settingsOff = new Set(gate.off);\n const lockedFeatures = new Set(gate.locked.features);\n const lockedFlags = new Set(gate.locked.flags);\n const flags = ctx.flags;\n const flagOf: (name: string) => FlagValue | undefined =\n flags === undefined\n ? () => undefined\n : typeof flags === \"function\"\n ? flags\n : (name) => (Object.prototype.hasOwnProperty.call(flags, name) ? flags[name] : undefined);\n return {\n ...ctx,\n settingsOff: (id: string) => settingsOff.has(id) || ctxSettingsOff(id),\n off: (id: string) => !lockedFeatures.has(id) && ctxOff(id),\n flags: (name: string) => {\n const setting = own(gate.flags, name);\n if (lockedFlags.has(name)) return setting;\n const fromCtx = flagOf(name);\n return fromCtx !== undefined ? fromCtx : setting;\n },\n };\n}\n\n/** One key as the database checks it (genesis_app_manifest.catalogue): no defaults, no secrets. @stability Beta */\nexport interface SettingManifestEntry {\n type: SettingType;\n applies: SettingApplies;\n scope: SettingScope;\n min?: number;\n max?: number;\n options?: readonly (string | number)[];\n /** Present (true) only when the key may be `null` (\"not set\"). */\n nullable?: true;\n /** Present (true) only for a number that must be whole. */\n integer?: true;\n}\n\n/**\n * The catalogue as the database's manifest stores it, so `set_genesis_setting` can check a value\n * (type, bounds, runtime only) without the packages' code. Written on deploy with the manifest.\n *\n * @stability Beta\n */\nexport function catalogueManifest(catalogue: SettingsCatalogue): { [key: string]: SettingManifestEntry } {\n const out = dict<SettingManifestEntry>();\n for (const def of Object.values(catalogue.keys)) {\n out[def.key] = {\n type: def.type,\n applies: def.applies,\n scope: def.scope,\n ...(def.min !== undefined ? { min: def.min } : {}),\n ...(def.max !== undefined ? { max: def.max } : {}),\n ...(def.options !== undefined ? { options: def.options } : {}),\n ...(def.nullable ? { nullable: true as const } : {}),\n ...(def.integer ? { integer: true as const } : {}),\n };\n }\n return out;\n}\n\n/**\n * A package's settings as its package.json declares them (`genesis.settings`: `{ namespace, keys }`),\n * for tools that read packages without running them (the CLI's doctor). The same checks as\n * {@link defineSettings}.\n *\n * @stability Beta\n */\nexport function settingsFromManifest(raw: unknown, where = \"genesis.settings\"): SettingsDeclaration {\n if (!isPlainObject(raw) || typeof raw.namespace !== \"string\" || !isPlainObject(raw.keys)) {\n throw new SettingsError(`${where} must be { \"namespace\": \"…\", \"keys\": { … } }`);\n }\n return defineSettings(raw.namespace, raw.keys as { [key: string]: SettingSpec });\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/graph.ts
|
|
2
|
+
function requiresProblems(nodes, options) {
|
|
3
|
+
const { skip = /* @__PURE__ */ new Set() } = options;
|
|
4
|
+
const problems = [];
|
|
5
|
+
for (const [id, node] of Object.entries(nodes)) {
|
|
6
|
+
if (skip.has(id)) continue;
|
|
7
|
+
for (const req of node.requires ?? []) {
|
|
8
|
+
const problem = requirementProblem(nodes, id, req, options);
|
|
9
|
+
if (problem) problems.push(problem);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [...problems, ...cycleProblems(nodes, skip)];
|
|
13
|
+
}
|
|
14
|
+
function requirementProblem(nodes, id, req, options) {
|
|
15
|
+
const known = options.isKnown ?? ((r) => Object.hasOwn(nodes, r));
|
|
16
|
+
if (req === id) return `${id}.requires: a ${options.noun} can't require itself`;
|
|
17
|
+
if (!known(req)) return `${id}.requires: ${options.unknown ? options.unknown(req, id) : `"${req}" is not a ${options.noun}`}`;
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
function cycleProblems(nodes, skip = /* @__PURE__ */ new Set()) {
|
|
21
|
+
const has = (id) => Object.hasOwn(nodes, id);
|
|
22
|
+
const problems = [];
|
|
23
|
+
const state = /* @__PURE__ */ new Map();
|
|
24
|
+
const visit = (id, path) => {
|
|
25
|
+
state.set(id, "open");
|
|
26
|
+
if (skip.has(id)) return;
|
|
27
|
+
for (const req of nodes[id]?.requires ?? []) {
|
|
28
|
+
if (!has(req) || req === id) continue;
|
|
29
|
+
if (state.get(req) === "open") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(" \u2192 ")}`);
|
|
30
|
+
else if (!state.has(req)) visit(req, [...path, id]);
|
|
31
|
+
}
|
|
32
|
+
state.set(id, "done");
|
|
33
|
+
};
|
|
34
|
+
for (const id of Object.keys(nodes)) if (!state.has(id)) visit(id, []);
|
|
35
|
+
return problems;
|
|
36
|
+
}
|
|
37
|
+
function dependencyOrder(nodes) {
|
|
38
|
+
const order = [];
|
|
39
|
+
const seen = /* @__PURE__ */ new Set();
|
|
40
|
+
const visit = (id) => {
|
|
41
|
+
if (seen.has(id)) return;
|
|
42
|
+
seen.add(id);
|
|
43
|
+
for (const req of nodes[id]?.requires ?? []) if (Object.hasOwn(nodes, req)) visit(req);
|
|
44
|
+
order.push(id);
|
|
45
|
+
};
|
|
46
|
+
for (const id of Object.keys(nodes)) visit(id);
|
|
47
|
+
return order;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { cycleProblems, dependencyOrder, requirementProblem, requiresProblems };
|
|
51
|
+
//# sourceMappingURL=chunk-VYUX7VAX.js.map
|
|
52
|
+
//# sourceMappingURL=chunk-VYUX7VAX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/graph.ts"],"names":[],"mappings":";AA6BO,SAAS,gBAAA,CAAiB,OAA+C,OAAA,EAA4C;AAC1H,EAAA,MAAM,EAAE,IAAA,mBAAO,IAAI,GAAA,IAAc,GAAI,OAAA;AACrC,EAAA,MAAM,WAAqB,EAAC;AAC5B,EAAA,KAAA,MAAW,CAAC,EAAA,EAAI,IAAI,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC9C,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,IAAA,KAAA,MAAW,GAAA,IAAO,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACrC,MAAA,MAAM,OAAA,GAAU,kBAAA,CAAmB,KAAA,EAAO,EAAA,EAAI,KAAK,OAAO,CAAA;AAC1D,MAAA,IAAI,OAAA,EAAS,QAAA,CAAS,IAAA,CAAK,OAAO,CAAA;AAAA,IACpC;AAAA,EACF;AACA,EAAA,OAAO,CAAC,GAAG,QAAA,EAAU,GAAG,aAAA,CAAc,KAAA,EAAO,IAAI,CAAC,CAAA;AACpD;AAGO,SAAS,kBAAA,CACd,KAAA,EACA,EAAA,EACA,GAAA,EACA,OAAA,EACoB;AACpB,EAAA,MAAM,KAAA,GAAQ,QAAQ,OAAA,KAAY,CAAC,MAAc,MAAA,CAAO,MAAA,CAAO,OAAO,CAAC,CAAA,CAAA;AACvE,EAAA,IAAI,QAAQ,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,CAAI,GAAG,CAAA,EAAG,KAAA,CAAM,GAAA,EAAK,CAAC,GAAG,IAAA,EAAM,EAAE,CAAC,CAAA;AAAA,IACpD;AACA,IAAA,KAAA,CAAM,GAAA,CAAI,IAAI,MAAM,CAAA;AAAA,EACtB,CAAA;AACA,EAAA,KAAA,MAAW,EAAA,IAAM,MAAA,CAAO,IAAA,CAAK,KAAK,GAAG,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,EAAE,CAAA,EAAG,KAAA,CAAM,EAAA,EAAI,EAAE,CAAA;AACrE,EAAA,OAAO,QAAA;AACT;AAOO,SAAS,gBAAgB,KAAA,EAAyD;AACvF,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,MAAM,KAAA,GAAQ,CAAC,EAAA,KAAe;AAC5B,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,IAAA,IAAA,CAAK,IAAI,EAAE,CAAA;AACX,IAAA,KAAA,MAAW,GAAA,IAAO,KAAA,CAAM,EAAE,CAAA,EAAG,YAAY,EAAC,EAAG,IAAI,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,GAAG,CAAA,QAAS,GAAG,CAAA;AACrF,IAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AAAA,EACf,CAAA;AACA,EAAA,KAAA,MAAW,MAAM,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,QAAS,EAAE,CAAA;AAC7C,EAAA,OAAO,KAAA;AACT","file":"chunk-VYUX7VAX.js","sourcesContent":["/**\n * The `requires` graph checks shared by the feature registry\n * (`defineFeatures`) and blocks (`resolveBlocks`). No zod here: blocks import\n * this from a platform-neutral entry that ships to phones.\n */\n\n/** A node with the ids it needs. */\nexport interface RequiresNode {\n readonly requires?: readonly string[];\n}\n\nexport interface RequiresProblemsOptions {\n /** What a node is called in messages: `feature` or `block`. */\n noun: string;\n /** Whether an id may be required. Default: it is a node of the graph. */\n isKnown?: (id: string) => boolean;\n /** The message for a requirement `isKnown` refuses. Default `\"x\" is not a <noun>`. */\n unknown?: (req: string, id: string) => string;\n /** Nodes already reported invalid: their edges can't be trusted, so they are skipped. */\n skip?: ReadonlySet<string>;\n}\n\n/**\n * Self-requirements, unknown requirements and cycles through `requires`, as\n * problem strings (`a.requires: …`). Each cycle is reported once, from where\n * the depth-first search found it: `a.requires: a cycle: a → b → a`.\n *\n * @stability Beta\n */\nexport function requiresProblems(nodes: Readonly<Record<string, RequiresNode>>, options: RequiresProblemsOptions): string[] {\n const { skip = new Set<string>() } = options;\n const problems: string[] = [];\n for (const [id, node] of Object.entries(nodes)) {\n if (skip.has(id)) continue;\n for (const req of node.requires ?? []) {\n const problem = requirementProblem(nodes, id, req, options);\n if (problem) problems.push(problem);\n }\n }\n return [...problems, ...cycleProblems(nodes, skip)];\n}\n\n/** One requirement's problem (itself, or an unknown id), or undefined when it is fine. @stability Beta */\nexport function requirementProblem(\n nodes: Readonly<Record<string, RequiresNode>>,\n id: string,\n req: string,\n options: RequiresProblemsOptions,\n): string | undefined {\n const known = options.isKnown ?? ((r: string) => Object.hasOwn(nodes, r));\n if (req === id) return `${id}.requires: a ${options.noun} can't require itself`;\n if (!known(req)) return `${id}.requires: ${options.unknown ? options.unknown(req, id) : `\"${req}\" is not a ${options.noun}`}`;\n return undefined;\n}\n\n/** Cycles through `requires`, each reported once, from where the depth-first search found it. @stability Beta */\nexport function cycleProblems(nodes: Readonly<Record<string, RequiresNode>>, skip: ReadonlySet<string> = new Set()): string[] {\n const has = (id: string) => Object.hasOwn(nodes, id);\n const problems: string[] = [];\n const state = new Map<string, \"open\" | \"done\">();\n const visit = (id: string, path: string[]): void => {\n state.set(id, \"open\");\n if (skip.has(id)) return;\n for (const req of nodes[id]?.requires ?? []) {\n if (!has(req) || req === id) continue;\n if (state.get(req) === \"open\") problems.push(`${id}.requires: a cycle: ${[...path.slice(path.indexOf(req)), id, req].join(\" → \")}`);\n else if (!state.has(req)) visit(req, [...path, id]);\n }\n state.set(id, \"done\");\n };\n for (const id of Object.keys(nodes)) if (!state.has(id)) visit(id, []);\n return problems;\n}\n\n/**\n * The ids in dependency order (what a node requires comes first), ties kept\n * in the given order. Requirements outside `nodes` are ignored. Assumes no\n * cycles ({@link requiresProblems} reports them).\n */\nexport function dependencyOrder(nodes: Readonly<Record<string, RequiresNode>>): string[] {\n const order: string[] = [];\n const seen = new Set<string>();\n const visit = (id: string) => {\n if (seen.has(id)) return;\n seen.add(id);\n for (const req of nodes[id]?.requires ?? []) if (Object.hasOwn(nodes, req)) visit(req);\n order.push(id);\n };\n for (const id of Object.keys(nodes)) visit(id);\n return order;\n}\n"]}
|