@rocket.chat/houston 0.27.0-next.2 → 2.1.8
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 +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,1398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.YAML11_OPTIONS = exports.FALSE_WORDS = exports.TRUE_WORDS = exports.HOME_ID_FILE = exports.LEGACY_ENV_PREFIX = exports.ENV_PREFIX = exports.E2EE_ROOM_DEFAULT_SETTINGS = exports.RC_RATE_LIMITER_SETTING = exports.CLOUD_ACCOUNTS_KEY = exports.KUBE_CONTEXT_KEY = exports.EXTRA_CONTEXT = exports.EXTRA_DEPLOYMENT = exports.EXTRA_RUNTIME = exports.WEBHOOKS_TOKEN = exports.WEBHOOKS_INCOMING = exports.WEBHOOKS_OUTGOING = exports.WEBHOOKS_RECEIVER = exports.EXTRA_MAILPIT_URL = exports.MONGO_OPLOG_URL = exports.MONGO_URL = exports.DEFAULT_BIND_HOST = exports.TRAEFIK_TAG = exports.MONITOR_PORTS = exports.PRESET_PORTS = exports.ADMIN_NAME = exports.ADMIN_EMAIL = exports.ADMIN_PASSWORD = exports.ADMIN_USERNAME = exports.PROJECT_PREFIX = exports.RC_CONTAINER_PORT = void 0;
|
|
37
|
+
exports.generateAdminPassword = generateAdminPassword;
|
|
38
|
+
exports.legacyEnvUsed = legacyEnvUsed;
|
|
39
|
+
exports.env = env;
|
|
40
|
+
exports.resetLegacyEnvWarnings = resetLegacyEnvWarnings;
|
|
41
|
+
exports.home = home;
|
|
42
|
+
exports.homeId = homeId;
|
|
43
|
+
exports.reprosDir = reprosDir;
|
|
44
|
+
exports.presetDir = presetDir;
|
|
45
|
+
exports.reportsDir = reportsDir;
|
|
46
|
+
exports.configFile = configFile;
|
|
47
|
+
exports.dataPath = dataPath;
|
|
48
|
+
exports.truthy = truthy;
|
|
49
|
+
exports.yamlDateText = yamlDateText;
|
|
50
|
+
exports.isYamlDate = isYamlDate;
|
|
51
|
+
exports.parseConfigYaml = parseConfigYaml;
|
|
52
|
+
exports.safeLoadYaml = safeLoadYaml;
|
|
53
|
+
exports.safeLoadConstructed = safeLoadConstructed;
|
|
54
|
+
exports.stringifyConfigYaml = stringifyConfigYaml;
|
|
55
|
+
exports.safeDumpYaml = safeDumpYaml;
|
|
56
|
+
exports.loadConfig = loadConfig;
|
|
57
|
+
exports.saveConfig = saveConfig;
|
|
58
|
+
exports.updateConfig = updateConfig;
|
|
59
|
+
exports.approvedAwsAccounts = approvedAwsAccounts;
|
|
60
|
+
exports.defaultKubeContext = defaultKubeContext;
|
|
61
|
+
/**
|
|
62
|
+
* Paths, constants, and the small persisted config for houston.
|
|
63
|
+
*
|
|
64
|
+
* State lives under `~/.houston` (override with `HOUSTON_HOME`):
|
|
65
|
+
*
|
|
66
|
+
* ~/.houston/
|
|
67
|
+
* config.yaml # default_repro, bind_host, acme.*, gui.* -- NO secrets:
|
|
68
|
+
* # reg_token is env/flag only and is never persisted
|
|
69
|
+
* # (see updateConfig, which reads with env off)
|
|
70
|
+
* presets/ # user/team presets (override built-ins)
|
|
71
|
+
* repros/<name>/ # one workspace per repro
|
|
72
|
+
*
|
|
73
|
+
* ONE KNOWN GAP, and it is the same one `lock.ts` records: there is no cross-PROCESS lock
|
|
74
|
+
* around the read-modify-write of config.yaml. That would take an `flock` plus an additive
|
|
75
|
+
* OFD lock, and the native addon that would provide them is ruled out; within the process
|
|
76
|
+
* no lock is needed, since Node runs one JavaScript thread. The atomic temp-file plus rename
|
|
77
|
+
* below still prevents a TORN file; it does not prevent a LOST UPDATE, and those are
|
|
78
|
+
* different problems. The `IMPLEMENTATION` marker is what keeps two builds off one home.
|
|
79
|
+
*/
|
|
80
|
+
const crypto = __importStar(require("crypto"));
|
|
81
|
+
const fs = __importStar(require("fs"));
|
|
82
|
+
const path = __importStar(require("path"));
|
|
83
|
+
const YAML = __importStar(require("yaml"));
|
|
84
|
+
const errors_1 = require("./errors");
|
|
85
|
+
const home_1 = require("./home");
|
|
86
|
+
const format_1 = require("./format");
|
|
87
|
+
const mkdir_parents_1 = require("./mkdir-parents");
|
|
88
|
+
const float_text_1 = require("./float-text");
|
|
89
|
+
const yaml_dump_1 = require("./yaml-dump");
|
|
90
|
+
/** Container-internal Rocket.Chat port. The published host port is chosen per repro. */
|
|
91
|
+
exports.RC_CONTAINER_PORT = 3000;
|
|
92
|
+
/**
|
|
93
|
+
* Docker compose project (and container) name prefix, so houston's stacks are easy to
|
|
94
|
+
* tell apart from unrelated compose projects.
|
|
95
|
+
*/
|
|
96
|
+
exports.PROJECT_PREFIX = 'houston-';
|
|
97
|
+
/**
|
|
98
|
+
* Admin user auto-provisioned into every repro (see presets / compose).
|
|
99
|
+
*
|
|
100
|
+
* ADMIN_PASSWORD is the LOOPBACK password, and that is the whole of its contract.
|
|
101
|
+
* `DEFAULT_BIND_HOST` below explains why a fixed weak credential is acceptable at all:
|
|
102
|
+
* nothing outside this machine can reach the workspace. A workspace that gets a public
|
|
103
|
+
* name or a non-loopback bind removes that premise, and a password is generated per
|
|
104
|
+
* workspace instead.
|
|
105
|
+
*/
|
|
106
|
+
exports.ADMIN_USERNAME = 'admin';
|
|
107
|
+
exports.ADMIN_PASSWORD = 'admin123';
|
|
108
|
+
exports.ADMIN_EMAIL = 'admin@example.com';
|
|
109
|
+
exports.ADMIN_NAME = 'Admin';
|
|
110
|
+
/**
|
|
111
|
+
* Bytes of entropy in a generated workspace admin password. 15 bytes is 120 bits
|
|
112
|
+
* through base64url, which is 20 characters -- long enough that the answer to "is this
|
|
113
|
+
* brute-forcible from the internet" is not a calculation, short enough to read off a
|
|
114
|
+
* terminal and type into a browser once.
|
|
115
|
+
*/
|
|
116
|
+
const ADMIN_PASSWORD_BYTES = 15;
|
|
117
|
+
/**
|
|
118
|
+
* A fresh admin password for one workspace.
|
|
119
|
+
*
|
|
120
|
+
* `crypto.randomBytes`, never `Math.random`: a cryptographic source against a predictable
|
|
121
|
+
* one, and it is the only thing that matters here. `base64url` is the URL-safe alphabet
|
|
122
|
+
* earlier releases generated from, 20 characters for 15 bytes.
|
|
123
|
+
*/
|
|
124
|
+
function generateAdminPassword() {
|
|
125
|
+
return crypto.randomBytes(ADMIN_PASSWORD_BYTES).toString('base64url');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The PREFERRED host ports of preset side services. ONE registry, so presets cannot
|
|
129
|
+
* silently collide with each other -- a new preset picks a port by looking here. The first
|
|
130
|
+
* workspace on a machine gets these; another with the same preset gets the next free port,
|
|
131
|
+
* recorded in its own record and kept from then on (`core/lifecycle/ports.ts`).
|
|
132
|
+
*/
|
|
133
|
+
exports.PRESET_PORTS = Object.freeze({
|
|
134
|
+
saml: Object.freeze([8081]), // Keycloak (SAML)
|
|
135
|
+
oidc: Object.freeze([8085]), // Keycloak (OIDC; same port inside+out)
|
|
136
|
+
email: Object.freeze([8025]), // Mailpit web UI / API
|
|
137
|
+
s3_minio: Object.freeze([9000, 9001]), // MinIO S3 API + console
|
|
138
|
+
livechat: Object.freeze([8090]), // demo "customer website" embedding the widget
|
|
139
|
+
ldap: Object.freeze([8082]), // phpLDAPadmin -- browse the directory the preset seeded
|
|
140
|
+
webhooks: Object.freeze([8086]), // webhook-tester, the inbox every outgoing call lands in
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* The PREFERRED host ports of the --monitor add-on (Prometheus, Grafana). Not a preset, so
|
|
144
|
+
* kept separate from PRESET_PORTS but allocated the same way: the first monitored workspace
|
|
145
|
+
* gets these, another the next free ones (`extra.monitoring_ports` records which).
|
|
146
|
+
*/
|
|
147
|
+
exports.MONITOR_PORTS = Object.freeze([9090, 5050]);
|
|
148
|
+
/**
|
|
149
|
+
* Traefik, for the shared HTTPS edge and the multi-instance preset's load balancer: one pin,
|
|
150
|
+
* so a workspace that uses both runs one version. v3.4 stopped at 3.4.5 in July 2025; v3.7
|
|
151
|
+
* is the maintained line (3.7.0 in May 2026). Floating on the minor, for its patches.
|
|
152
|
+
*/
|
|
153
|
+
exports.TRAEFIK_TAG = 'v3.7';
|
|
154
|
+
/**
|
|
155
|
+
* Host interface published ports bind to.
|
|
156
|
+
*
|
|
157
|
+
* LOOPBACK. Repros use weak fixed credentials, so they must not be reachable from the
|
|
158
|
+
* local network unless the user opts in (`up --bind 0.0.0.0` or `HOUSTON_BIND_HOST`).
|
|
159
|
+
* Matches the official rocketchat-compose posture for local and backing services.
|
|
160
|
+
*/
|
|
161
|
+
exports.DEFAULT_BIND_HOST = '127.0.0.1';
|
|
162
|
+
/** In-network addresses of the Mongo replica set (compose service DNS). */
|
|
163
|
+
exports.MONGO_URL = 'mongodb://mongodb:27017/rocketchat?replicaSet=rs0';
|
|
164
|
+
exports.MONGO_OPLOG_URL = 'mongodb://mongodb:27017/local?replicaSet=rs0';
|
|
165
|
+
/** Key under `Metadata.extra` where the email preset records Mailpit's URL. */
|
|
166
|
+
exports.EXTRA_MAILPIT_URL = 'mailpit_url';
|
|
167
|
+
/**
|
|
168
|
+
* The webhooks preset's receiver (webhook-tester): the compose/Kubernetes DNS name
|
|
169
|
+
* Rocket.Chat reaches it at, the Service being named after the service. It records any
|
|
170
|
+
* request whose path starts with a session's uuid; post-ready makes the session through
|
|
171
|
+
* its API (answering JSON: the kind the receiver makes by itself answers an empty body,
|
|
172
|
+
* a failed call to Rocket.Chat) and records the uuid the receiver chose. Here, below every
|
|
173
|
+
* preset and core module, so the post-ready action and the lifecycle import no builder.
|
|
174
|
+
*/
|
|
175
|
+
exports.WEBHOOKS_RECEIVER = 'http://webhooks:8080';
|
|
176
|
+
/** The sample integrations post-ready creates, found again by name on every re-run. */
|
|
177
|
+
exports.WEBHOOKS_OUTGOING = 'houston-outgoing';
|
|
178
|
+
exports.WEBHOOKS_INCOMING = 'houston-incoming';
|
|
179
|
+
/** The Omnichannel webhook's secret, sent as X-RocketChat-Livechat-Token. */
|
|
180
|
+
exports.WEBHOOKS_TOKEN = 'houston';
|
|
181
|
+
/**
|
|
182
|
+
* Key under `Metadata.extra` naming the runtime a workspace runs on. ABSENT means
|
|
183
|
+
* docker -- every workspace created before this key existed is a compose one.
|
|
184
|
+
*/
|
|
185
|
+
exports.EXTRA_RUNTIME = 'runtime';
|
|
186
|
+
/** Key under `Metadata.extra` naming HOW Rocket.Chat is arranged. */
|
|
187
|
+
exports.EXTRA_DEPLOYMENT = 'deployment';
|
|
188
|
+
/** Key under `Metadata.extra` naming WHICH Kubernetes cluster a workspace runs in. */
|
|
189
|
+
exports.EXTRA_CONTEXT = 'context';
|
|
190
|
+
/**
|
|
191
|
+
* Stored config key: the default `--context` for this box. FLAT, not dotted, and the
|
|
192
|
+
* reason is mechanical rather than stylistic -- the env-override map below keys on flat
|
|
193
|
+
* names only, so a dotted stored key could never have an env override.
|
|
194
|
+
*/
|
|
195
|
+
exports.KUBE_CONTEXT_KEY = 'kubernetes_context';
|
|
196
|
+
/**
|
|
197
|
+
* Stored config key: which AWS accounts this box may build a cluster in. Comma
|
|
198
|
+
* separated, absent meaning none, and none meaning every create is gated.
|
|
199
|
+
*
|
|
200
|
+
* Keyed on the ACCOUNT rather than a cluster name or a context, because the account is
|
|
201
|
+
* the thing that gets BILLED -- the unit somebody actually owns and can consent to.
|
|
202
|
+
*/
|
|
203
|
+
exports.CLOUD_ACCOUNTS_KEY = 'cluster_approved_accounts';
|
|
204
|
+
/** RC's REST rate limiter -- disabled for the duration of a load test, then restored. */
|
|
205
|
+
exports.RC_RATE_LIMITER_SETTING = 'API_Enable_Rate_Limiter';
|
|
206
|
+
/**
|
|
207
|
+
* The settings that make Rocket.Chat create new DMs and private rooms encrypted -- off for
|
|
208
|
+
* the duration of a seed, then restored, because the seeder sends plaintext and Rocket.Chat
|
|
209
|
+
* refuses plaintext in an encrypted room. The last exists from 8.8.0.
|
|
210
|
+
*/
|
|
211
|
+
exports.E2EE_ROOM_DEFAULT_SETTINGS = Object.freeze([
|
|
212
|
+
'E2E_Enabled_Default_DirectRooms',
|
|
213
|
+
'E2E_Enabled_Default_PrivateRooms',
|
|
214
|
+
'E2E_Force_Encryption_For_Private_Rooms',
|
|
215
|
+
]);
|
|
216
|
+
exports.ENV_PREFIX = 'HOUSTON_';
|
|
217
|
+
/**
|
|
218
|
+
* Environment variables were spelled `RC_REPRO_*` before the rename. They are read as
|
|
219
|
+
* deprecated aliases rather than dropped: a rename that only taught the tool the new
|
|
220
|
+
* name would make an `RC_REPRO_HOME` sitting in someone's shell profile do nothing at
|
|
221
|
+
* all -- not fail, just quietly resolve state to `~/.houston` while every workspace they
|
|
222
|
+
* own is somewhere else. Silence is the wrong failure for a variable whose only job is
|
|
223
|
+
* to say where the state lives.
|
|
224
|
+
*/
|
|
225
|
+
exports.LEGACY_ENV_PREFIX = 'RC_REPRO_';
|
|
226
|
+
/** Legacy names already warned about, so the notice fires once per process. */
|
|
227
|
+
const legacyEnvWarned = new Set();
|
|
228
|
+
/**
|
|
229
|
+
* Pre-rename variable names set in THIS environment, sorted.
|
|
230
|
+
*
|
|
231
|
+
* Read from the environment rather than from a record of what this process happened to
|
|
232
|
+
* look up. A historical record answers "did anything read one yet", which depends on
|
|
233
|
+
* which commands ran in what order -- so `doctor` would report a variable that is no
|
|
234
|
+
* longer set, or stay silent about one that is simply not read on this code path.
|
|
235
|
+
*/
|
|
236
|
+
function legacyEnvUsed() {
|
|
237
|
+
return Object.keys(process.env)
|
|
238
|
+
.filter((name) => name.startsWith(exports.LEGACY_ENV_PREFIX))
|
|
239
|
+
.sort();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Read `HOUSTON_<X>`, falling back to the pre-rename `RC_REPRO_<X>`.
|
|
243
|
+
*
|
|
244
|
+
* The new spelling always wins, so a box part-way through the migration with both set
|
|
245
|
+
* behaves as the new one says. The warning goes to STDERR, never stdout: under `--json`
|
|
246
|
+
* stdout carries the envelope and nothing else.
|
|
247
|
+
*/
|
|
248
|
+
function env(name, fallback = '') {
|
|
249
|
+
const value = process.env[name];
|
|
250
|
+
if (value !== undefined)
|
|
251
|
+
return value;
|
|
252
|
+
if (name.startsWith(exports.ENV_PREFIX)) {
|
|
253
|
+
const legacy = exports.LEGACY_ENV_PREFIX + name.slice(exports.ENV_PREFIX.length);
|
|
254
|
+
const legacyValue = process.env[legacy];
|
|
255
|
+
if (legacyValue !== undefined) {
|
|
256
|
+
if (!legacyEnvWarned.has(legacy)) {
|
|
257
|
+
legacyEnvWarned.add(legacy);
|
|
258
|
+
process.stderr.write(`${legacy} is the pre-rename name for ${name} and will stop being read; rename it.\n`);
|
|
259
|
+
}
|
|
260
|
+
return legacyValue;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return fallback;
|
|
264
|
+
}
|
|
265
|
+
/** For tests: a fresh process has warned about nothing. */
|
|
266
|
+
function resetLegacyEnvWarnings() {
|
|
267
|
+
legacyEnvWarned.clear();
|
|
268
|
+
}
|
|
269
|
+
const ENV_OVERRIDES = Object.freeze({
|
|
270
|
+
reg_token: 'HOUSTON_REG_TOKEN',
|
|
271
|
+
rc_image: 'HOUSTON_RC_IMAGE',
|
|
272
|
+
bind_host: 'HOUSTON_BIND_HOST',
|
|
273
|
+
[exports.KUBE_CONTEXT_KEY]: 'HOUSTON_KUBE_CONTEXT',
|
|
274
|
+
});
|
|
275
|
+
/**
|
|
276
|
+
* Root state directory. RESOLVES a path; it does not create anything.
|
|
277
|
+
*
|
|
278
|
+
* The `mkdir` lives in the writers below (0700, because accounts and sessions live in
|
|
279
|
+
* here), so a reader who trusted a "created on demand" promise would file the resulting
|
|
280
|
+
* ENOENT against the wrong function.
|
|
281
|
+
*
|
|
282
|
+
* `pathHome()`, not `os.homedir()`: with `HOME` set but empty the home is `/.houston`, and
|
|
283
|
+
* `os.homedir()` made this `.houston` in whatever directory the command ran from -- a
|
|
284
|
+
* different home per working directory, and never the one earlier releases used.
|
|
285
|
+
* `lib/home.ts` has the measured table.
|
|
286
|
+
*/
|
|
287
|
+
function home() {
|
|
288
|
+
// `HOUSTON_HOME`, or `.houston` in the home, joined component by component -- and every
|
|
289
|
+
// path under it is joined the same way, with `joinPath`, never `path.join`. The raw
|
|
290
|
+
// value came back here and each site `path.join`ed it, which folds `..` against the text
|
|
291
|
+
// before it: `HOUSTON_HOME=link/../hh` with `link -> other/sub` is `other/hh` to the
|
|
292
|
+
// kernel, and was `hh` in the working directory here, so an earlier version of this build
|
|
293
|
+
// and the releases before it kept every workspace, account and setting in two different
|
|
294
|
+
// directories and each claimed its own. A `HOME` holding `..` split the default home the
|
|
295
|
+
// same way, and a trailing `/` or a doubled one printed where the established path has
|
|
296
|
+
// neither.
|
|
297
|
+
const root = env('HOUSTON_HOME');
|
|
298
|
+
return root ? (0, home_1.joinPath)(root) : (0, home_1.joinPath)((0, home_1.pathHome)(), '.houston');
|
|
299
|
+
}
|
|
300
|
+
/** What `homeId` keeps in the home, and the shape it must have to be believed. */
|
|
301
|
+
exports.HOME_ID_FILE = 'home-id';
|
|
302
|
+
const HOME_ID = /^[0-9a-f]{16}$/u;
|
|
303
|
+
/**
|
|
304
|
+
* This home's own id, made on first use and kept in the home.
|
|
305
|
+
*
|
|
306
|
+
* WHAT TELLS TWO HOMES APART on one Kubernetes cluster. A workspace's name, its namespace
|
|
307
|
+
* and even its owner's account name are the same in two homes -- a laptop and the server,
|
|
308
|
+
* or two people with no accounts -- so a namespace one home made was adopted, and deleted,
|
|
309
|
+
* by the other. Random rather than derived from the host or the path, so a home keeps it
|
|
310
|
+
* when either changes. A file of its own, so a 1.x reading config.yaml never sees it.
|
|
311
|
+
*/
|
|
312
|
+
function homeId() {
|
|
313
|
+
const file = (0, home_1.joinPath)(home(), exports.HOME_ID_FILE);
|
|
314
|
+
// '' when there is no file yet; null when one is there and holds no id.
|
|
315
|
+
const read = () => {
|
|
316
|
+
let text;
|
|
317
|
+
try {
|
|
318
|
+
text = fs.readFileSync(file, 'utf8').trim();
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
if (error.code === 'ENOENT')
|
|
322
|
+
return '';
|
|
323
|
+
// Not damage, so not the remedy for it: deleting a file that only could not be read
|
|
324
|
+
// would give this home a new id. A `sudo houston` that left it root's is the usual cause.
|
|
325
|
+
throw new errors_1.ConflictError(`could not read ${file}, this home's id on Kubernetes clusters (${(0, format_1.fileErrorText)(error)}) ` +
|
|
326
|
+
'- fix its permissions rather than deleting it');
|
|
327
|
+
}
|
|
328
|
+
return HOME_ID.test(text) ? text : null;
|
|
329
|
+
};
|
|
330
|
+
const damaged = () => {
|
|
331
|
+
throw new errors_1.ConflictError(`${file} does not hold this home's id (16 hex digits), and a new one would make every ` +
|
|
332
|
+
"namespace this home marked read as another home's. Put the id back -- `kubectl get " +
|
|
333
|
+
'namespaces -L houston.io/home` shows the ones in use -- or delete the file to start a ' +
|
|
334
|
+
"new id, then claim each of this home's namespaces with `kubectl label namespace <ns> " +
|
|
335
|
+
'houston.io/home=<new id> --overwrite`');
|
|
336
|
+
};
|
|
337
|
+
const known = read();
|
|
338
|
+
if (known === null)
|
|
339
|
+
return damaged();
|
|
340
|
+
if (known !== '')
|
|
341
|
+
return known;
|
|
342
|
+
(0, mkdir_parents_1.mkdirParents)(home(), 0o700);
|
|
343
|
+
const tmp = `${file}.${String(process.pid)}.${crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
344
|
+
fs.writeFileSync(tmp, `${crypto.randomBytes(8).toString('hex')}\n`, { mode: 0o600 });
|
|
345
|
+
try {
|
|
346
|
+
// LINKED, never renamed into place: two first commands at once must agree on ONE id,
|
|
347
|
+
// and a link refuses to replace what the other one made. Renamed only where nothing is
|
|
348
|
+
// there and the filesystem has no links to make.
|
|
349
|
+
fs.linkSync(tmp, file);
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
if (read() === '')
|
|
353
|
+
fs.renameSync(tmp, file);
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
fs.rmSync(tmp, { force: true });
|
|
357
|
+
}
|
|
358
|
+
return read() ?? damaged();
|
|
359
|
+
}
|
|
360
|
+
function reprosDir() {
|
|
361
|
+
return (0, home_1.joinPath)(home(), 'repros');
|
|
362
|
+
}
|
|
363
|
+
function presetDir() {
|
|
364
|
+
return (0, home_1.joinPath)(home(), 'presets');
|
|
365
|
+
}
|
|
366
|
+
/** Where loadtest and capacity reports are written by default. */
|
|
367
|
+
function reportsDir() {
|
|
368
|
+
return (0, home_1.joinPath)(home(), 'reports');
|
|
369
|
+
}
|
|
370
|
+
function configFile() {
|
|
371
|
+
return (0, home_1.joinPath)(home(), 'config.yaml');
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Shipped package data (`versions.yaml`, the preset catalogue, Grafana dashboards, the
|
|
375
|
+
* k6 scripts, the GUI assets).
|
|
376
|
+
*
|
|
377
|
+
* This is the package's own data directory, found from this module, and it is the reason
|
|
378
|
+
* this tree has no bundler: a bundler rewrites exactly this lookup, and `versions.ts` then
|
|
379
|
+
* falls back to the live endpoint while presets report "not found" -- at runtime, in
|
|
380
|
+
* production, with a green build.
|
|
381
|
+
*
|
|
382
|
+
* It resolves relative to the EMITTED module, walking up out of `dist/lib/` or
|
|
383
|
+
* `src/lib/` to the package root. Both layouts are two directories deep, so one
|
|
384
|
+
* expression serves the compiled build and `@swc/jest` alike.
|
|
385
|
+
*
|
|
386
|
+
* `data/` sits at the package root: the build that ships owns its data.
|
|
387
|
+
*/
|
|
388
|
+
function dataPath(...parts) {
|
|
389
|
+
return path.join(__dirname, '..', '..', 'data', ...parts);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* What a person may type for a boolean setting, and what it means. Both directions are
|
|
393
|
+
* listed because only one of them was ever exercised.
|
|
394
|
+
*
|
|
395
|
+
* Exported because `config set acme.staging` accepts exactly these words (minus the empty
|
|
396
|
+
* one). It kept a literal list of its own that left out `y`, `t`, `n` and `f`, so
|
|
397
|
+
* `config set acme.staging y` was refused, where it has always stored `true`.
|
|
398
|
+
*/
|
|
399
|
+
exports.TRUE_WORDS = Object.freeze(['1', 'true', 'yes', 'on', 'y', 't']);
|
|
400
|
+
exports.FALSE_WORDS = Object.freeze([
|
|
401
|
+
'0',
|
|
402
|
+
'false',
|
|
403
|
+
'no',
|
|
404
|
+
'off',
|
|
405
|
+
'n',
|
|
406
|
+
'f',
|
|
407
|
+
'',
|
|
408
|
+
]);
|
|
409
|
+
/**
|
|
410
|
+
* Read a remembered boolean, however it happens to be stored.
|
|
411
|
+
*
|
|
412
|
+
* `Boolean("false")` IS TRUE, and the same one-line coercion made
|
|
413
|
+
* `config set acme.staging false` impossible to obey: `config set` wrote the raw string
|
|
414
|
+
* and every reader coerced it, so turning staging ON worked while turning it OFF did
|
|
415
|
+
* nothing at all. The asymmetry is what hid it -- the value people set first is the one
|
|
416
|
+
* that works.
|
|
417
|
+
*
|
|
418
|
+
* Needed on the READ side and not only where the value is written, because every
|
|
419
|
+
* config.yaml already written holds a string.
|
|
420
|
+
*/
|
|
421
|
+
function truthy(value, fallback = false) {
|
|
422
|
+
if (typeof value === 'boolean')
|
|
423
|
+
return value;
|
|
424
|
+
if (value === null || value === undefined)
|
|
425
|
+
return fallback;
|
|
426
|
+
if (typeof value === 'number')
|
|
427
|
+
return Boolean(value);
|
|
428
|
+
// `stripText`, not `trim()`: the two disagree both ways. `\x1ctrue` is true by the
|
|
429
|
+
// established rule and was refused here, and a BOM-led `\ufefftrue` was true here and
|
|
430
|
+
// is refused by it -- on the value `config set` stores and on every remembered one read back.
|
|
431
|
+
const text = (0, float_text_1.stripText)(String(value)).toLowerCase();
|
|
432
|
+
if (exports.TRUE_WORDS.includes(text))
|
|
433
|
+
return true;
|
|
434
|
+
if (exports.FALSE_WORDS.includes(text))
|
|
435
|
+
return false;
|
|
436
|
+
return fallback;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The established YAML 1.1 scalar schema -- the one every existing config.yaml was written
|
|
440
|
+
* and read with -- reimplemented as tag overrides for the `yaml` package.
|
|
441
|
+
*
|
|
442
|
+
* `config.yaml` is a shared file, and the package's schema disagrees with the established
|
|
443
|
+
* one on exactly the cells a human is most likely to write by hand. Measured (the corpus
|
|
444
|
+
* lives in `config.test.ts`):
|
|
445
|
+
*
|
|
446
|
+
* - the package's YAML 1.1 mode resolves `y`/`Y`/`n`/`N` to booleans; the established
|
|
447
|
+
* schema reserves those for the full words only, so `y` stays a string;
|
|
448
|
+
* - the package resolves `1e5` (an exponent with no decimal point) to a float; the
|
|
449
|
+
* established float grammar requires the dot, so `1e5` stays a string;
|
|
450
|
+
* - the package resolves `-.5` to a float; the established grammar requires a digit
|
|
451
|
+
* after the leading dot, so it stays a string;
|
|
452
|
+
* - the package resolves a sexagesimal that starts with 0 (`0:00:00`) to an int;
|
|
453
|
+
* the established grammar requires the first group to start 1-9;
|
|
454
|
+
* - the package accepts a single-digit month in a bare date (`2026-9-17`);
|
|
455
|
+
* the established date-only grammar requires two.
|
|
456
|
+
*
|
|
457
|
+
* Each of those is a value the two schemas read differently -- a string the one writes
|
|
458
|
+
* bare because it is a string to it is a boolean, a float, an int or a date to the other.
|
|
459
|
+
* The fix is to make this build's resolver the established one, cell for cell, rather than
|
|
460
|
+
* to remember a list of exceptions.
|
|
461
|
+
*
|
|
462
|
+
* The mechanism is the package's own: `customTags` as a function receives the
|
|
463
|
+
* built-in 1.1 schema's tag list, so the tags whose grammar differs are dropped
|
|
464
|
+
* and the established equivalents prepended. `default: true` on each makes the scalar
|
|
465
|
+
* composer consider them, and the prepend makes them win over any built-in
|
|
466
|
+
* survivor that would otherwise match first.
|
|
467
|
+
*/
|
|
468
|
+
/** Date-only scalars, marked so a writer can re-emit them as a date and not a timestamp. */
|
|
469
|
+
const yamlDates = new WeakSet();
|
|
470
|
+
function resolveFloat(str) {
|
|
471
|
+
const sign = str.startsWith('-') ? -1 : 1;
|
|
472
|
+
const body = str.replace(/^[-+]/, '').replace(/_/g, '');
|
|
473
|
+
const low = body.toLowerCase();
|
|
474
|
+
if (low === '.inf')
|
|
475
|
+
return sign * Infinity;
|
|
476
|
+
if (low === '.nan')
|
|
477
|
+
return NaN;
|
|
478
|
+
if (body.includes(':')) {
|
|
479
|
+
const [whole = '', frac] = body.split('.');
|
|
480
|
+
const parts = whole.split(':').map(Number);
|
|
481
|
+
let value = 0;
|
|
482
|
+
for (const part of parts)
|
|
483
|
+
value = value * 60 + part;
|
|
484
|
+
return sign * (value + Number(`0.${frac ?? '0'}`));
|
|
485
|
+
}
|
|
486
|
+
return sign * parseFloat(body);
|
|
487
|
+
}
|
|
488
|
+
// The three float grammars the established resolver accepts, as one tag. The package's
|
|
489
|
+
// own EXP float (a dotless exponent) is deliberately NOT included, and neither is
|
|
490
|
+
// its `.e5` form: the established resolver leaves both as strings.
|
|
491
|
+
//
|
|
492
|
+
// The leading-dot branch is `\.[0-9][0-9_]*`, a DIGIT first. It was `\.[0-9_]+`, which
|
|
493
|
+
// took `._5` for 0.5 and `._` and `.__` for nan -- strings to the established resolver,
|
|
494
|
+
// which `config set bind_host ._5` therefore writes bare, so this build read a config.yaml
|
|
495
|
+
// an earlier release wrote as a different type and value, and its next `config set`
|
|
496
|
+
// rewrote the key as `0.5` or `nan`.
|
|
497
|
+
const YAML11_FLOAT_TEST = /^[-+]?(?:[0-9][0-9_]*)\.[0-9_]*(?:[eE][-+][0-9]+)?$|^\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?$|^[-+]?(?:[0-9][0-9_]*)(?::[0-5]?[0-9])+\.[0-9_]*$|^[-+]?\.(?:inf|Inf|INF)$|^\.(?:nan|NaN|NAN)$/;
|
|
498
|
+
const YAML11_FLOAT = {
|
|
499
|
+
tag: 'tag:yaml.org,2002:float',
|
|
500
|
+
default: true,
|
|
501
|
+
identify: (value) => typeof value === 'number',
|
|
502
|
+
test: YAML11_FLOAT_TEST,
|
|
503
|
+
resolve: resolveFloat,
|
|
504
|
+
};
|
|
505
|
+
/** The established bool words. The package's 1.1 mode adds the single letters; these do not. */
|
|
506
|
+
const YAML11_BOOL = {
|
|
507
|
+
tag: 'tag:yaml.org,2002:bool',
|
|
508
|
+
default: true,
|
|
509
|
+
identify: (value) => typeof value === 'boolean',
|
|
510
|
+
test: /^(?:yes|Yes|YES|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$/,
|
|
511
|
+
resolve: (str) => ['yes', 'Yes', 'YES', 'true', 'True', 'TRUE', 'on', 'On', 'ON'].includes(str),
|
|
512
|
+
};
|
|
513
|
+
// The established int grammars, one tag: binary, octal, decimal, hex, then
|
|
514
|
+
// sexagesimal. The package's sexagesimal allows a leading 0 (`0:00:00`) and its
|
|
515
|
+
// binary spelling differs; both are corrected here.
|
|
516
|
+
const YAML11_INT_TEST = /^[-+]?0b[0-1_]+$|^[-+]?0[0-7_]+$|^[-+]?(?:0|[1-9][0-9_]*)$|^[-+]?0x[0-9a-fA-F_]+$|^[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+$/;
|
|
517
|
+
const YAML11_INT = {
|
|
518
|
+
tag: 'tag:yaml.org,2002:int',
|
|
519
|
+
default: true,
|
|
520
|
+
identify: (value) => typeof value === 'number' && Number.isInteger(value),
|
|
521
|
+
test: YAML11_INT_TEST,
|
|
522
|
+
resolve: (str) => {
|
|
523
|
+
const sign = str.startsWith('-') ? -1 : 1;
|
|
524
|
+
const body = str.replace(/^[-+]/, '').replace(/_/g, '');
|
|
525
|
+
if (body.includes(':')) {
|
|
526
|
+
const parts = body.split(':').map(Number);
|
|
527
|
+
let value = 0;
|
|
528
|
+
for (const part of parts)
|
|
529
|
+
value = value * 60 + part;
|
|
530
|
+
return sign * value;
|
|
531
|
+
}
|
|
532
|
+
let value;
|
|
533
|
+
if (/^0b/i.test(body))
|
|
534
|
+
value = sign * Number.parseInt(body.slice(2), 2);
|
|
535
|
+
else if (/^0x/i.test(body))
|
|
536
|
+
value = sign * Number.parseInt(body.slice(2), 16);
|
|
537
|
+
else if (/^0[0-7]+$/.test(body))
|
|
538
|
+
value = sign * Number.parseInt(body, 8);
|
|
539
|
+
else
|
|
540
|
+
value = sign * Number.parseInt(body, 10);
|
|
541
|
+
// An int has no negative zero: `-0` read as -0 here, and the compose writer spelled it
|
|
542
|
+
// `-0` where the established file holds `0`.
|
|
543
|
+
return value === 0 ? 0 : value;
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
const YAML11_STR = {
|
|
547
|
+
tag: 'tag:yaml.org,2002:str',
|
|
548
|
+
default: true,
|
|
549
|
+
identify: (value) => typeof value === 'string',
|
|
550
|
+
resolve: (str) => str,
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* The timestamp constructor's pattern, which is wider than the resolver's: a date alone may
|
|
554
|
+
* have a one-digit month or day. Its `$` also matches before a final newline (`\n?$`). The
|
|
555
|
+
* groups are: year, month, day, hour, minute, second, fraction, tz, tz_sign, tz_hour,
|
|
556
|
+
* tz_minute.
|
|
557
|
+
*/
|
|
558
|
+
const TIMESTAMP_CONSTRUCT = /^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\.([0-9]*))?(?:[ \t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?)?\n?$/u;
|
|
559
|
+
/**
|
|
560
|
+
* What the writer writes for a timestamp read from this text: the ISO form, date and time
|
|
561
|
+
* split by a space, of the datetime the text stands for, so naive stays naive, an offset
|
|
562
|
+
* stays the offset it was written with (`Z` is `+00:00`), and a fraction is six digits or
|
|
563
|
+
* none -- or null when the text is not a full timestamp.
|
|
564
|
+
*/
|
|
565
|
+
function datetimeText(text) {
|
|
566
|
+
const match = TIMESTAMP_CONSTRUCT.exec(text);
|
|
567
|
+
if (match === null || match[4] === undefined)
|
|
568
|
+
return null;
|
|
569
|
+
const [, year, month, day, hour, minute, second, fraction, tz, tzSign, tzHour, tzMinute] = match;
|
|
570
|
+
const pad = (value, width = 2) => String(Number(value)).padStart(width, '0');
|
|
571
|
+
let out = `${pad(year ?? '', 4)}-${pad(month ?? '')}-${pad(day ?? '')} `;
|
|
572
|
+
out += `${pad(hour)}:${pad(minute ?? '')}:${pad(second ?? '')}`;
|
|
573
|
+
const micro = fraction === undefined || fraction === '' ? 0 : Number(fraction.slice(0, 6).padEnd(6, '0'));
|
|
574
|
+
if (micro !== 0)
|
|
575
|
+
out += `.${pad(micro, 6)}`;
|
|
576
|
+
if (tz !== undefined) {
|
|
577
|
+
const offset = tzSign === undefined
|
|
578
|
+
? 0
|
|
579
|
+
: (Number(tzHour) * 3600 + Number(tzMinute ?? 0) * 60) * (tzSign === '-' ? -1 : 1);
|
|
580
|
+
const size = Math.abs(offset);
|
|
581
|
+
out += `${offset < 0 ? '-' : '+'}${pad(Math.floor(size / 3600))}:${pad(Math.floor((size % 3600) / 60))}`;
|
|
582
|
+
}
|
|
583
|
+
return out;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Each full timestamp this build read, as the representer for datetimes writes it back. A Date is
|
|
587
|
+
* an instant: a naive `10:00:00` became one in the box's zone and an offset became UTC, so a
|
|
588
|
+
* rewrite of config.yaml turned `x: 2026-01-01 10:00:00` into `04:30:00Z` on a box in IST,
|
|
589
|
+
* and `10:00:00.5+02:00` into `08:00:00Z` -- an unrelated key's value changed by any
|
|
590
|
+
* `config set`. The file must keep what it held.
|
|
591
|
+
*/
|
|
592
|
+
const yamlStamps = new WeakMap();
|
|
593
|
+
/** The established timestamp grammar: date-only requires two-digit month and day. */
|
|
594
|
+
const YAML11_TIMESTAMP = {
|
|
595
|
+
tag: 'tag:yaml.org,2002:timestamp',
|
|
596
|
+
default: true,
|
|
597
|
+
identify: (value) => value instanceof Date,
|
|
598
|
+
test: /^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])$|^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?(?:[Tt]|[ \t]+)[0-9][0-9]?:[0-9][0-9]:[0-9][0-9](?:\.[0-9]*)?(?:[ \t]*(?:Z|[-+][0-9][0-9]?(?::[0-9][0-9])?))?)$/,
|
|
599
|
+
resolve: (str) => {
|
|
600
|
+
const date = new Date(str);
|
|
601
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(str))
|
|
602
|
+
yamlDates.add(date);
|
|
603
|
+
const written = datetimeText(str);
|
|
604
|
+
if (written !== null)
|
|
605
|
+
yamlStamps.set(date, written);
|
|
606
|
+
return date;
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
/**
|
|
610
|
+
* What the representer for dates writes for a Date this build's reader made: the ISO text
|
|
611
|
+
* of the date, the year to four digits, or of the datetime (a space between) as
|
|
612
|
+
* `yamlStamps` recorded it. Undefined for a Date the reader did not make, which the writer
|
|
613
|
+
* spells as the UTC datetime of its instant.
|
|
614
|
+
*/
|
|
615
|
+
function yamlDateText(value) {
|
|
616
|
+
if (yamlDates.has(value)) {
|
|
617
|
+
const pad = (n, width = 2) => String(n).padStart(width, '0');
|
|
618
|
+
return `${pad(value.getUTCFullYear(), 4)}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())}`;
|
|
619
|
+
}
|
|
620
|
+
return yamlStamps.get(value);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* The same grammar, resolved to the scalar's own TEXT rather than to a Date.
|
|
624
|
+
*
|
|
625
|
+
* For the compose document, which is read to be WRITTEN BACK: `monitor`, `env` and
|
|
626
|
+
* `upgrade` edit what `readCompose` returns and re-emit it through `compose.ts`, whose
|
|
627
|
+
* emitter spells a Date as an instant -- a bare `2026-01-01` would come back as
|
|
628
|
+
* `"2026-01-01T00:00:00.000Z"`, a different value in the container. A date's text is also
|
|
629
|
+
* exactly how the date is shown. A full timestamp's text is not always how the timestamp is
|
|
630
|
+
* shown (a `t` separator, an offset, a fraction are normalised there), and only a
|
|
631
|
+
* hand-edited file holds one: the writer quotes every such string.
|
|
632
|
+
*/
|
|
633
|
+
const YAML11_TIMESTAMP_TEXT = { ...YAML11_TIMESTAMP, resolve: (str) => str };
|
|
634
|
+
/**
|
|
635
|
+
* An EXPLICIT standard tag -- `!!float 3`, `!!null x`, `!!int 0o17` -- is the tag's
|
|
636
|
+
* constructor applied to the text, whatever the text is: the tag's implicit grammar decides
|
|
637
|
+
* only which PLAIN scalars get the tag without being told. The yaml library asks the tag's
|
|
638
|
+
* `test` of an explicit one too, so every text outside the grammar was "could not
|
|
639
|
+
* determine a constructor" and a JavaScript stack, where the established reader reads
|
|
640
|
+
* `3.0`, null and `15` -- or refuses with the constructor's own refusal: `!!int 1e3`
|
|
641
|
+
* is `'1e3' is not an integer`, `!!bool y` is
|
|
642
|
+
* `'y' is not a boolean (want yes, no, true, false, on or off)`.
|
|
643
|
+
*
|
|
644
|
+
* So each tag has a second, `test`-less entry, which the library takes for every explicit
|
|
645
|
+
* use of that tag and never for a plain scalar, running the constructor line for line. A
|
|
646
|
+
* refusal is not thrown from `resolve`, where the library would turn it into a parse error
|
|
647
|
+
* at the tag; it becomes the node's value, and `safeLoadYaml` raises whichever refusal
|
|
648
|
+
* building the document meets first.
|
|
649
|
+
*/
|
|
650
|
+
class ConstructFailure {
|
|
651
|
+
constructor(error) {
|
|
652
|
+
this.error = error;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
/** A tag's refusal of its text, named `InvalidValue` as `format`'s are. */
|
|
656
|
+
function loaderError(message) {
|
|
657
|
+
const error = new Error(message);
|
|
658
|
+
error.name = 'InvalidValue';
|
|
659
|
+
return error;
|
|
660
|
+
}
|
|
661
|
+
/** The first character, refused for an empty string: `!!int ''` and `!!float` bare. */
|
|
662
|
+
function firstChar(value) {
|
|
663
|
+
if (value === '')
|
|
664
|
+
throw loaderError('an empty value is not a number');
|
|
665
|
+
return value.slice(0, 1);
|
|
666
|
+
}
|
|
667
|
+
/** The `!!int` constructor: sign, `0b`, `0x`, a leading `0` for octal, sexagesimal, decimal. */
|
|
668
|
+
function constructInt(text) {
|
|
669
|
+
let value = text.replace(/_/gu, '');
|
|
670
|
+
const sign = firstChar(value) === '-' ? -1 : 1;
|
|
671
|
+
if ('+-'.includes(firstChar(value)))
|
|
672
|
+
value = value.slice(1);
|
|
673
|
+
let result;
|
|
674
|
+
if (value === '0')
|
|
675
|
+
return 0;
|
|
676
|
+
if (value.startsWith('0b'))
|
|
677
|
+
result = sign * (0, format_1.intFromText)(value.slice(2), 2);
|
|
678
|
+
else if (value.startsWith('0x'))
|
|
679
|
+
result = sign * (0, format_1.intFromText)(value.slice(2), 16);
|
|
680
|
+
else if (firstChar(value) === '0')
|
|
681
|
+
result = sign * (0, format_1.intFromText)(value, 8);
|
|
682
|
+
else if (value.includes(':')) {
|
|
683
|
+
const digits = value
|
|
684
|
+
.split(':')
|
|
685
|
+
.map((part) => (0, format_1.intFromText)(part, 10))
|
|
686
|
+
.reverse();
|
|
687
|
+
let base = 1;
|
|
688
|
+
result = 0;
|
|
689
|
+
for (const digit of digits) {
|
|
690
|
+
result += digit * base;
|
|
691
|
+
base *= 60;
|
|
692
|
+
}
|
|
693
|
+
result *= sign;
|
|
694
|
+
}
|
|
695
|
+
else
|
|
696
|
+
result = sign * (0, format_1.intFromText)(value, 10);
|
|
697
|
+
// An int has no negative zero: `!!int -0b0` is 0.
|
|
698
|
+
return result === 0 ? 0 : result;
|
|
699
|
+
}
|
|
700
|
+
/** The `!!float` constructor: the float grammar is given the lowered, sign-less text. */
|
|
701
|
+
function constructFloat(text) {
|
|
702
|
+
let value = text.replace(/_/gu, '').toLowerCase();
|
|
703
|
+
const sign = firstChar(value) === '-' ? -1 : 1;
|
|
704
|
+
if ('+-'.includes(firstChar(value)))
|
|
705
|
+
value = value.slice(1);
|
|
706
|
+
if (value === '.inf')
|
|
707
|
+
return sign * Infinity;
|
|
708
|
+
if (value === '.nan')
|
|
709
|
+
return NaN;
|
|
710
|
+
if (value.includes(':')) {
|
|
711
|
+
const digits = value
|
|
712
|
+
.split(':')
|
|
713
|
+
.map((part) => (0, format_1.parseFloat_)(part))
|
|
714
|
+
.reverse();
|
|
715
|
+
let base = 1;
|
|
716
|
+
let result = 0;
|
|
717
|
+
for (const digit of digits) {
|
|
718
|
+
result += digit * base;
|
|
719
|
+
base *= 60;
|
|
720
|
+
}
|
|
721
|
+
return sign * result;
|
|
722
|
+
}
|
|
723
|
+
return sign * (0, format_1.parseFloat_)(value);
|
|
724
|
+
}
|
|
725
|
+
/** The `!!bool` constructor's words, looked up with the text lowered. */
|
|
726
|
+
const YAML11_BOOL_VALUES = new Map([
|
|
727
|
+
['yes', true],
|
|
728
|
+
['no', false],
|
|
729
|
+
['true', true],
|
|
730
|
+
['false', false],
|
|
731
|
+
['on', true],
|
|
732
|
+
['off', false],
|
|
733
|
+
]);
|
|
734
|
+
function constructBool(text) {
|
|
735
|
+
const key = text.toLowerCase();
|
|
736
|
+
const value = YAML11_BOOL_VALUES.get(key);
|
|
737
|
+
if (value === undefined) {
|
|
738
|
+
throw loaderError(`${(0, format_1.quotedText)(text)} is not a boolean (want yes, no, true, false, on or off)`);
|
|
739
|
+
}
|
|
740
|
+
return value;
|
|
741
|
+
}
|
|
742
|
+
/** A calendar date's checks, in the established order and words. */
|
|
743
|
+
function checkDate(year, month, day) {
|
|
744
|
+
if (year < 1 || year > 9999)
|
|
745
|
+
throw loaderError(`year ${String(year)} is out of range`);
|
|
746
|
+
if (month < 1 || month > 12)
|
|
747
|
+
throw loaderError('month must be in 1..12');
|
|
748
|
+
const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
749
|
+
const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
750
|
+
if (day < 1 || day > days)
|
|
751
|
+
throw loaderError('day is out of range for month');
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* The `!!timestamp` constructor's refusals, in the established order: text that is not a
|
|
755
|
+
* timestamp, then an offset of a day or more, then the date and the time.
|
|
756
|
+
* Whether the text is a date alone.
|
|
757
|
+
*/
|
|
758
|
+
function checkTimestamp(text) {
|
|
759
|
+
const match = TIMESTAMP_CONSTRUCT.exec(text);
|
|
760
|
+
if (match === null) {
|
|
761
|
+
throw loaderError(`${(0, format_1.quotedText)(text)} is not a timestamp`);
|
|
762
|
+
}
|
|
763
|
+
const [, year, month, day, hour, minute, second, , , tzSign, tzHour, tzMinute] = match;
|
|
764
|
+
const date = [year, month, day].map(Number);
|
|
765
|
+
if (hour === undefined) {
|
|
766
|
+
checkDate(...date);
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
if (tzSign !== undefined) {
|
|
770
|
+
const total = (Number(tzHour) * 3600 + Number(tzMinute ?? 0) * 60) * (tzSign === '-' ? -1 : 1);
|
|
771
|
+
if (total <= -86400 || total >= 86400) {
|
|
772
|
+
const offset = `${tzSign}${String(tzHour)}:${String(tzMinute ?? '00')}`;
|
|
773
|
+
throw loaderError(`the offset ${offset} is not under 24 hours`);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
checkDate(...date);
|
|
777
|
+
if (Number(hour) > 23)
|
|
778
|
+
throw loaderError('hour must be in 0..23');
|
|
779
|
+
if (Number(minute) > 59)
|
|
780
|
+
throw loaderError('minute must be in 0..59');
|
|
781
|
+
if (Number(second) > 59)
|
|
782
|
+
throw loaderError('second must be in 0..59');
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* An explicit `!!timestamp`: a date alone is the `date` it names, however its month and day
|
|
787
|
+
* are padded, and a full timestamp is what the implicit tag makes of the same text, which
|
|
788
|
+
* its grammar shares. `asText` is the compose reader's variant, whose dates are their
|
|
789
|
+
* `YYYY-MM-DD` text.
|
|
790
|
+
*/
|
|
791
|
+
function constructTimestamp(text, asText) {
|
|
792
|
+
const bare = text.endsWith('\n') ? text.slice(0, -1) : text;
|
|
793
|
+
if (!checkTimestamp(bare)) {
|
|
794
|
+
return asText
|
|
795
|
+
? YAML11_TIMESTAMP_TEXT.resolve(bare, () => undefined, {})
|
|
796
|
+
: YAML11_TIMESTAMP.resolve(bare, () => undefined, {});
|
|
797
|
+
}
|
|
798
|
+
const [year, month, day] = bare.split('-').map(Number);
|
|
799
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
800
|
+
const shown = `${String(year).padStart(4, '0')}-${pad(month)}-${pad(day)}`;
|
|
801
|
+
if (asText)
|
|
802
|
+
return shown;
|
|
803
|
+
const date = new Date(`${shown}T00:00:00Z`);
|
|
804
|
+
yamlDates.add(date);
|
|
805
|
+
return date;
|
|
806
|
+
}
|
|
807
|
+
/** The `test`-less twin of a standard tag, for its explicit uses. */
|
|
808
|
+
function explicitTag(tag, construct) {
|
|
809
|
+
return {
|
|
810
|
+
tag,
|
|
811
|
+
resolve: (text) => {
|
|
812
|
+
try {
|
|
813
|
+
return construct(text);
|
|
814
|
+
}
|
|
815
|
+
catch (error) {
|
|
816
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
817
|
+
return new YAML.Scalar(new ConstructFailure(failure));
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
const YAML11_EXPLICIT = [
|
|
823
|
+
explicitTag('tag:yaml.org,2002:null', () => null),
|
|
824
|
+
explicitTag('tag:yaml.org,2002:bool', constructBool),
|
|
825
|
+
explicitTag('tag:yaml.org,2002:int', constructInt),
|
|
826
|
+
explicitTag('tag:yaml.org,2002:float', constructFloat),
|
|
827
|
+
];
|
|
828
|
+
const YAML11_TIMESTAMP_EXPLICIT = explicitTag('tag:yaml.org,2002:timestamp', (text) => constructTimestamp(text, false));
|
|
829
|
+
const YAML11_TIMESTAMP_EXPLICIT_TEXT = explicitTag('tag:yaml.org,2002:timestamp', (text) => constructTimestamp(text, true));
|
|
830
|
+
const YAML11_DROPPED = new Set([
|
|
831
|
+
'tag:yaml.org,2002:float',
|
|
832
|
+
'tag:yaml.org,2002:bool',
|
|
833
|
+
'tag:yaml.org,2002:int',
|
|
834
|
+
'tag:yaml.org,2002:timestamp',
|
|
835
|
+
'tag:yaml.org,2002:str',
|
|
836
|
+
]);
|
|
837
|
+
/** The tag list with the five grammars that differ from the established ones swapped in. */
|
|
838
|
+
function yaml11Tags(tags) {
|
|
839
|
+
return [
|
|
840
|
+
YAML11_BOOL,
|
|
841
|
+
YAML11_INT,
|
|
842
|
+
YAML11_FLOAT,
|
|
843
|
+
YAML11_TIMESTAMP,
|
|
844
|
+
YAML11_STR,
|
|
845
|
+
...tags.filter((tag) => typeof tag !== 'string' && !YAML11_DROPPED.has(tag.tag)),
|
|
846
|
+
// Last, and harmless there: the library returns the first `test`-less tag of an
|
|
847
|
+
// explicit tag's name wherever it sits, and never considers one for a plain scalar.
|
|
848
|
+
...YAML11_EXPLICIT,
|
|
849
|
+
YAML11_TIMESTAMP_EXPLICIT,
|
|
850
|
+
];
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* The PARSER's options: the established safe grammar, for every YAML file houston reads.
|
|
854
|
+
* Nothing here is written with the package's emitter: config.yaml and a workspace's
|
|
855
|
+
* compose file are written by `yaml-dump.ts`'s `safeDump`.
|
|
856
|
+
*/
|
|
857
|
+
exports.YAML11_OPTIONS = {
|
|
858
|
+
version: '1.1',
|
|
859
|
+
// A doubled key keeps its last value; the yaml library's default refused the file, and
|
|
860
|
+
// every command that read config.yaml ended with a stack.
|
|
861
|
+
uniqueKeys: false,
|
|
862
|
+
// No alias budget: the established reader has none, and the yaml library's default of
|
|
863
|
+
// 100 refused a document with a hundred references to one anchor.
|
|
864
|
+
maxAliasCount: -1,
|
|
865
|
+
customTags: yaml11Tags,
|
|
866
|
+
// No warnings on stderr: the established loader prints none. `toJS` warned through
|
|
867
|
+
// `process.emitWarning` for a key a plain object cannot hold -- a hand-written
|
|
868
|
+
// `2026-01-01: note` in config.yaml added two `(node:<pid>) Warning: Keys with collection
|
|
869
|
+
// values will be stringified` lines, with a pid and a local-time date in them, to every
|
|
870
|
+
// command that read the file. `error` silences only that; every refusal
|
|
871
|
+
// still stands (`silent` would also have dropped the MULTIPLE_DOCS one).
|
|
872
|
+
logLevel: 'error',
|
|
873
|
+
};
|
|
874
|
+
/** `YAML11_OPTIONS` with timestamps kept as their text: see `YAML11_TIMESTAMP_TEXT`. */
|
|
875
|
+
const YAML11_TEXT_TIMESTAMP_OPTIONS = {
|
|
876
|
+
...exports.YAML11_OPTIONS,
|
|
877
|
+
customTags: (tags) => yaml11Tags(tags).map((tag) => tag === YAML11_TIMESTAMP
|
|
878
|
+
? YAML11_TIMESTAMP_TEXT
|
|
879
|
+
: tag === YAML11_TIMESTAMP_EXPLICIT
|
|
880
|
+
? YAML11_TIMESTAMP_EXPLICIT_TEXT
|
|
881
|
+
: tag),
|
|
882
|
+
};
|
|
883
|
+
/** Whether a value is a date-only scalar this build's resolver produced. */
|
|
884
|
+
function isYamlDate(value) {
|
|
885
|
+
return value instanceof Date && yamlDates.has(value);
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Parse one document of YAML 1.1 with the established safe grammar.
|
|
889
|
+
*
|
|
890
|
+
* The compose document is read by the same grammar (`record.ts`'s `readCompose`), with
|
|
891
|
+
* its timestamps kept as text; it is written by `compose.ts`'s own emitter.
|
|
892
|
+
*/
|
|
893
|
+
function parseConfigYaml(text) {
|
|
894
|
+
return safeLoadYaml(text);
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* `text` read with the established safe grammar, refusals included: a tag the safe loader
|
|
898
|
+
* has no constructor for is refused, where the yaml library only warns -- on
|
|
899
|
+
* stderr, as a Node warning -- and reads the value as a plain string, so a user preset
|
|
900
|
+
* `name: !foo bar` was a preset called `bar`, where it is UNREADABLE. The message is the
|
|
901
|
+
* established one, its mark and snippet drawn as they always have been.
|
|
902
|
+
*
|
|
903
|
+
* `timestampsAsText` resolves a timestamp to its text instead of a Date, for a document that
|
|
904
|
+
* is written back through an emitter that would spell the Date differently.
|
|
905
|
+
*/
|
|
906
|
+
function safeLoadYaml(text, { mapAsMap = false, timestampsAsText = false } = {}) {
|
|
907
|
+
return safeLoadDocument(text, timestampsAsText).toJS({ maxAliasCount: -1, mapAsMap });
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* The document with every type it holds kept, where `safeLoadYaml` is what JavaScript can:
|
|
911
|
+
* every mapping a `Map` with its keys as typed, an integral float a `JsonFloat`, an int past
|
|
912
|
+
* 2**53 a `bigint`, a date or timestamp the Date `yamlDateText` spells (`constructNode`).
|
|
913
|
+
* For a reader that writes a value out in its displayed form -- a user preset's env, which
|
|
914
|
+
* `compose.ts` writes through `toTextYaml`.
|
|
915
|
+
*/
|
|
916
|
+
function safeLoadConstructed(text) {
|
|
917
|
+
return constructNode(safeLoadDocument(text));
|
|
918
|
+
}
|
|
919
|
+
/** `safeLoadYaml`'s document, parsed and checked for every refusal the safe loader makes. */
|
|
920
|
+
function safeLoadDocument(text, timestampsAsText = false) {
|
|
921
|
+
const doc = YAML.parseDocument(text, timestampsAsText ? YAML11_TEXT_TIMESTAMP_OPTIONS : exports.YAML11_OPTIONS);
|
|
922
|
+
const [failure] = doc.errors;
|
|
923
|
+
if (failure !== undefined)
|
|
924
|
+
throw failure;
|
|
925
|
+
const refused = firstConstructionFailure(doc, text);
|
|
926
|
+
if (refused !== null)
|
|
927
|
+
throw refused;
|
|
928
|
+
return doc;
|
|
929
|
+
}
|
|
930
|
+
/** A node as the constructor receives it: an alias is the node it names. */
|
|
931
|
+
function constructed(doc, node) {
|
|
932
|
+
return YAML.isAlias(node) ? node.resolve(doc) : node;
|
|
933
|
+
}
|
|
934
|
+
/** Whether a mapping key is the merge key `<<`, which merging removes. */
|
|
935
|
+
function isMergeKey(key) {
|
|
936
|
+
return YAML.isScalar(key) && typeof key.value === 'symbol' && key.value.description === '<<';
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* A mapping's key and value nodes as the constructor visits them: merges first, which
|
|
940
|
+
* put every merged mapping's items ahead of the mapping's own, a list of merges in
|
|
941
|
+
* reverse.
|
|
942
|
+
*/
|
|
943
|
+
function mappingItems(doc, map) {
|
|
944
|
+
const merged = [];
|
|
945
|
+
const own = [];
|
|
946
|
+
for (const pair of map.items) {
|
|
947
|
+
if (!isMergeKey(pair.key)) {
|
|
948
|
+
own.push(pair.key, pair.value);
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
const source = constructed(doc, pair.value);
|
|
952
|
+
if (YAML.isMap(source))
|
|
953
|
+
merged.push(...mappingItems(doc, source));
|
|
954
|
+
else if (YAML.isSeq(source)) {
|
|
955
|
+
const each = source.items.map((item) => {
|
|
956
|
+
const one = constructed(doc, item);
|
|
957
|
+
return YAML.isMap(one) ? mappingItems(doc, one) : [];
|
|
958
|
+
});
|
|
959
|
+
for (const items of each.reverse())
|
|
960
|
+
merged.push(...items);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return [...merged, ...own];
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* A key as the established mapping compares it: `True` is `1` and `False` is `0` (so `1: a`
|
|
967
|
+
* then `true: c` is one key, `1`, holding `c`), a number is its value (`1.0` is `1`, `-0.0`
|
|
968
|
+
* is `0`, and every `.nan` is one key), a date or datetime its text, bytes their contents.
|
|
969
|
+
* Two aware datetimes at one instant in different offsets are equal by that rule and not
|
|
970
|
+
* here; nothing writes one.
|
|
971
|
+
*/
|
|
972
|
+
function keyIdentity(key) {
|
|
973
|
+
if (typeof key === 'boolean')
|
|
974
|
+
return Number(key);
|
|
975
|
+
if (key instanceof float_text_1.JsonFloat)
|
|
976
|
+
return key.value;
|
|
977
|
+
if (key instanceof Date)
|
|
978
|
+
return Symbol.for(`timestamp ${yamlDateText(key) ?? key.getTime()}`);
|
|
979
|
+
if (key instanceof Uint8Array)
|
|
980
|
+
return Symbol.for(`bytes ${Buffer.from(key).toString('base64')}`);
|
|
981
|
+
return key;
|
|
982
|
+
}
|
|
983
|
+
/** Each pair set into a mapping that keeps the key it first saw. */
|
|
984
|
+
function fillDict(out, pairs) {
|
|
985
|
+
const held = new Map();
|
|
986
|
+
for (const [key, value] of pairs) {
|
|
987
|
+
const identity = keyIdentity(key);
|
|
988
|
+
if (!held.has(identity))
|
|
989
|
+
held.set(identity, key);
|
|
990
|
+
out.set(held.get(identity), value);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Whether a scalar is a float the `!!float` constructor built that a number cannot say is one:
|
|
995
|
+
* an integral value (`1.0`, `3.0`, `-0.0`), resolved by the float grammar or tagged
|
|
996
|
+
* `!!float`. The int and float grammars are disjoint -- a float has a dot -- so the grammar
|
|
997
|
+
* alone tells a plain `3.0` from a plain `3`.
|
|
998
|
+
*/
|
|
999
|
+
function isIntegralFloat(node) {
|
|
1000
|
+
if (typeof node.value !== 'number' || !Number.isInteger(node.value))
|
|
1001
|
+
return false;
|
|
1002
|
+
if (node.tag !== undefined)
|
|
1003
|
+
return node.tag === 'tag:yaml.org,2002:float';
|
|
1004
|
+
return node.type === 'PLAIN' && YAML11_FLOAT_TEST.test(node.source ?? '');
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* The `!!int` constructor in exact integers, for an int a double cannot hold: past 2**53,
|
|
1008
|
+
* `12345678901234567890` read as `12345678901234567000`. Undefined when the scalar is not
|
|
1009
|
+
* such an int, or its text is one `BigInt` does not take (the double then stands).
|
|
1010
|
+
*/
|
|
1011
|
+
function exactInt(node) {
|
|
1012
|
+
if (typeof node.value !== 'number' || !Number.isInteger(node.value))
|
|
1013
|
+
return undefined;
|
|
1014
|
+
if (Number.isSafeInteger(node.value))
|
|
1015
|
+
return undefined;
|
|
1016
|
+
const tagged = node.tag !== undefined;
|
|
1017
|
+
if (tagged ? node.tag !== 'tag:yaml.org,2002:int' : node.type !== 'PLAIN')
|
|
1018
|
+
return undefined;
|
|
1019
|
+
const text = node.source ?? '';
|
|
1020
|
+
if (!tagged && !YAML11_INT_TEST.test(text))
|
|
1021
|
+
return undefined;
|
|
1022
|
+
try {
|
|
1023
|
+
let value = text.replace(/_/gu, '');
|
|
1024
|
+
const sign = value.startsWith('-') ? -1n : 1n;
|
|
1025
|
+
if (value.startsWith('-') || value.startsWith('+'))
|
|
1026
|
+
value = value.slice(1);
|
|
1027
|
+
if (value.startsWith('0b'))
|
|
1028
|
+
return sign * BigInt(`0b${value.slice(2)}`);
|
|
1029
|
+
if (value.startsWith('0x'))
|
|
1030
|
+
return sign * BigInt(`0x${value.slice(2)}`);
|
|
1031
|
+
if (value.startsWith('0'))
|
|
1032
|
+
return sign * BigInt(`0o${value.slice(1)}`);
|
|
1033
|
+
if (value.includes(':')) {
|
|
1034
|
+
let result = 0n;
|
|
1035
|
+
for (const part of value.split(':'))
|
|
1036
|
+
result = result * 60n + BigInt(part);
|
|
1037
|
+
return sign * result;
|
|
1038
|
+
}
|
|
1039
|
+
return sign * BigInt(value);
|
|
1040
|
+
}
|
|
1041
|
+
catch {
|
|
1042
|
+
return undefined;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* The document as the safe constructor builds it, where `toJS` builds what JavaScript can
|
|
1047
|
+
* hold: a mapping is a `Map` with its keys as they were typed, in the order they were met;
|
|
1048
|
+
* a `!!set` is a `Set`; an `!!omap` or `!!pairs` is a list of `[key, value]` pairs, as
|
|
1049
|
+
* the established reader makes it; a node named twice is one value. Only `saveConfig`
|
|
1050
|
+
* reads it, to write config.yaml back as it has always been written.
|
|
1051
|
+
*
|
|
1052
|
+
* An integral float is a `JsonFloat`, key or value. It was the number, which the writer
|
|
1053
|
+
* spells as an int: a hand-edited `custom_float: 1.0`, `ratio: 3.0` or `3.0: x` came back
|
|
1054
|
+
* from any `config set`, `use`, `up --pin`, `down --volumes` or `prune` as `1`, `3` and
|
|
1055
|
+
* `3: x`, where `updateConfig` must write back the float it read. A `-0.0` key was worse off:
|
|
1056
|
+
* a `Map` keeps -0 as 0. An int past 2**53 is a `bigint`, the digits it was written with,
|
|
1057
|
+
* where the double rounded them.
|
|
1058
|
+
*/
|
|
1059
|
+
function constructNode(doc) {
|
|
1060
|
+
const made = new Map();
|
|
1061
|
+
const build = (raw) => {
|
|
1062
|
+
const node = constructed(doc, raw);
|
|
1063
|
+
if (node === null || node === undefined)
|
|
1064
|
+
return null;
|
|
1065
|
+
if (made.has(node))
|
|
1066
|
+
return made.get(node);
|
|
1067
|
+
if (YAML.isScalar(node)) {
|
|
1068
|
+
const value = isIntegralFloat(node)
|
|
1069
|
+
? new float_text_1.JsonFloat(node.value)
|
|
1070
|
+
: (exactInt(node) ?? node.value);
|
|
1071
|
+
made.set(node, value);
|
|
1072
|
+
return value;
|
|
1073
|
+
}
|
|
1074
|
+
if (YAML.isMap(node)) {
|
|
1075
|
+
const pairs = [];
|
|
1076
|
+
const items = mappingItems(doc, node);
|
|
1077
|
+
if (node.tag === 'tag:yaml.org,2002:set') {
|
|
1078
|
+
const out = new Set();
|
|
1079
|
+
made.set(node, out);
|
|
1080
|
+
for (let at = 0; at < items.length; at += 2)
|
|
1081
|
+
pairs.push([build(items[at]), null]);
|
|
1082
|
+
const members = new Map();
|
|
1083
|
+
fillDict(members, pairs);
|
|
1084
|
+
for (const member of members.keys())
|
|
1085
|
+
out.add(member);
|
|
1086
|
+
return out;
|
|
1087
|
+
}
|
|
1088
|
+
const out = new Map();
|
|
1089
|
+
made.set(node, out);
|
|
1090
|
+
for (let at = 0; at < items.length; at += 2) {
|
|
1091
|
+
pairs.push([build(items[at]), build(items[at + 1])]);
|
|
1092
|
+
}
|
|
1093
|
+
fillDict(out, pairs);
|
|
1094
|
+
return out;
|
|
1095
|
+
}
|
|
1096
|
+
if (YAML.isSeq(node)) {
|
|
1097
|
+
const out = [];
|
|
1098
|
+
made.set(node, out);
|
|
1099
|
+
const tuples = node.tag === 'tag:yaml.org,2002:omap' || node.tag === 'tag:yaml.org,2002:pairs';
|
|
1100
|
+
for (const item of node.items) {
|
|
1101
|
+
if (!YAML.isPair(item))
|
|
1102
|
+
out.push(build(item));
|
|
1103
|
+
else if (tuples)
|
|
1104
|
+
out.push([build(item.key), build(item.value)]);
|
|
1105
|
+
else
|
|
1106
|
+
out.push(new Map([[build(item.key), build(item.value)]]));
|
|
1107
|
+
}
|
|
1108
|
+
return out;
|
|
1109
|
+
}
|
|
1110
|
+
return null;
|
|
1111
|
+
};
|
|
1112
|
+
return build(doc.contents);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* The document behind each object `loadConfig` handed out: the top-level mapping as
|
|
1116
|
+
* `constructNode` built it, and a fingerprint of each property as it was read, so a rewrite
|
|
1117
|
+
* can tell which ones a command changed.
|
|
1118
|
+
*/
|
|
1119
|
+
const yamlDocuments = new WeakMap();
|
|
1120
|
+
/** A value's identity for `rewriteScalars`: its dump, which changes when anything inside it does. */
|
|
1121
|
+
function fingerprint(value) {
|
|
1122
|
+
return (0, yaml_dump_1.safeDump)(value, { dateText: yamlDateText });
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* The mapping to write after a command changed `cfg`: the mapping the loader built, with
|
|
1126
|
+
* each property the command set written in its place, each it deleted left out, and each
|
|
1127
|
+
* it added at the end, in the order it added them.
|
|
1128
|
+
*
|
|
1129
|
+
* `loadConfig` hands out a plain object, and a plain object cannot hold what the mapping held:
|
|
1130
|
+
* its keys are strings (`1: a`, `~: b`, `true: c` became `'1'`, `''` and `'true'`), it lists
|
|
1131
|
+
* an integer-like key first (`'10'` and `'2'` moved ahead of `bind_host`), and `toJS` made
|
|
1132
|
+
* an `!!omap` a Map, written back as a mapping where it belongs as a list of pairs. Any
|
|
1133
|
+
* `config set`, `config unset` or `use` rewrote a hand-edited config.yaml in those shapes,
|
|
1134
|
+
* where it must be rewritten as it was read. So what a command did not touch is written
|
|
1135
|
+
* from the mapping, and what it did from the object. A key that is not a string is one no
|
|
1136
|
+
* command can name, and keeps its value.
|
|
1137
|
+
*/
|
|
1138
|
+
function rewriteScalars(cfg) {
|
|
1139
|
+
const document = typeof cfg === 'object' && cfg !== null ? yamlDocuments.get(cfg) : undefined;
|
|
1140
|
+
if (document === undefined)
|
|
1141
|
+
return cfg;
|
|
1142
|
+
const now = cfg;
|
|
1143
|
+
const unchanged = (key) => document.read.get(key) === fingerprint(now[key]);
|
|
1144
|
+
const out = new Map();
|
|
1145
|
+
const named = new Set();
|
|
1146
|
+
for (const [key, value] of document.items) {
|
|
1147
|
+
if (typeof key !== 'string') {
|
|
1148
|
+
out.set(key, value);
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
named.add(key);
|
|
1152
|
+
if (Object.hasOwn(now, key))
|
|
1153
|
+
out.set(key, unchanged(key) ? value : now[key]);
|
|
1154
|
+
}
|
|
1155
|
+
for (const key of Object.keys(now)) {
|
|
1156
|
+
// A property standing for a key that is not a string (`'1'` for `1`) is skipped while
|
|
1157
|
+
// it is as it was read: the key itself is already written.
|
|
1158
|
+
if (named.has(key) || (document.read.has(key) && unchanged(key)))
|
|
1159
|
+
continue;
|
|
1160
|
+
out.set(key, now[key]);
|
|
1161
|
+
}
|
|
1162
|
+
return out;
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* What the safe loader raises while CONSTRUCTING, in the order it would meet it: a tag with
|
|
1166
|
+
* no constructor (`constructorError`) or a constructor's own refusal (`ConstructFailure`).
|
|
1167
|
+
*
|
|
1168
|
+
* Building the document fills a mapping or a sequence only after its parent is done, so a
|
|
1169
|
+
* collection's scalars come after every scalar of the collection
|
|
1170
|
+
* holding it: in `a: [!!int x]` then `b: !!int y` the established reader reports `'y'`.
|
|
1171
|
+
* The first-warning rule this replaces was document order, which reported `'x'`. A node is
|
|
1172
|
+
* built once, however many aliases name it.
|
|
1173
|
+
*
|
|
1174
|
+
* An unresolved tag's warning is placed at its tag, the node at its content: the node a
|
|
1175
|
+
* warning belongs to is the first, in document order, that starts at or after the tag ends.
|
|
1176
|
+
*/
|
|
1177
|
+
function firstConstructionFailure(doc, text) {
|
|
1178
|
+
const nodes = [];
|
|
1179
|
+
YAML.visit(doc, {
|
|
1180
|
+
Node: (_key, node) => {
|
|
1181
|
+
nodes.push(node);
|
|
1182
|
+
},
|
|
1183
|
+
});
|
|
1184
|
+
const owners = new Map();
|
|
1185
|
+
const orphans = [];
|
|
1186
|
+
for (const warning of doc.warnings) {
|
|
1187
|
+
if (warning.code !== 'TAG_RESOLVE_FAILED')
|
|
1188
|
+
continue;
|
|
1189
|
+
const owner = nodes.find((node) => (node.range?.[0] ?? -1) >= warning.pos[1]);
|
|
1190
|
+
if (owner === undefined || owners.has(owner))
|
|
1191
|
+
orphans.push(warning);
|
|
1192
|
+
else
|
|
1193
|
+
owners.set(owner, warning);
|
|
1194
|
+
}
|
|
1195
|
+
const built = new Set();
|
|
1196
|
+
const pending = [];
|
|
1197
|
+
const build = (raw) => {
|
|
1198
|
+
const node = constructed(doc, raw);
|
|
1199
|
+
if (node === null || node === undefined || built.has(node))
|
|
1200
|
+
return null;
|
|
1201
|
+
built.add(node);
|
|
1202
|
+
const warning = owners.get(node);
|
|
1203
|
+
if (warning !== undefined)
|
|
1204
|
+
return constructorError(text, warning);
|
|
1205
|
+
if (YAML.isScalar(node) && node.value instanceof ConstructFailure)
|
|
1206
|
+
return node.value.error;
|
|
1207
|
+
if (YAML.isMap(node) || YAML.isSeq(node))
|
|
1208
|
+
pending.push(node);
|
|
1209
|
+
return null;
|
|
1210
|
+
};
|
|
1211
|
+
let failure = build(doc.contents);
|
|
1212
|
+
for (let next = 0; failure === null && next < pending.length; next += 1) {
|
|
1213
|
+
const collection = pending[next];
|
|
1214
|
+
const children = YAML.isMap(collection)
|
|
1215
|
+
? mappingItems(doc, collection)
|
|
1216
|
+
: collection.items.flatMap((item) => (YAML.isPair(item) ? [item.key, item.value] : [item]));
|
|
1217
|
+
for (const child of children) {
|
|
1218
|
+
failure = build(child);
|
|
1219
|
+
if (failure !== null)
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (failure !== null)
|
|
1224
|
+
return failure;
|
|
1225
|
+
// Nothing the walk reached: an unresolved tag it could not place is still refused, as
|
|
1226
|
+
// the first-warning rule refused it, and so is a refusal in a node it never visited.
|
|
1227
|
+
const [orphan] = orphans;
|
|
1228
|
+
if (orphan !== undefined)
|
|
1229
|
+
return constructorError(text, orphan);
|
|
1230
|
+
const stray = nodes.find((node) => YAML.isScalar(node) && node.value instanceof ConstructFailure);
|
|
1231
|
+
return stray === undefined ? null : stray.value.error;
|
|
1232
|
+
}
|
|
1233
|
+
function constructorError(text, warning) {
|
|
1234
|
+
const tag = /Unresolved tag: (\S+)/u.exec(warning.message)?.[1] ?? '';
|
|
1235
|
+
const pointer = warning.pos[0];
|
|
1236
|
+
const breaks = '\0\r\n\u0085\u2028\u2029';
|
|
1237
|
+
let start = pointer;
|
|
1238
|
+
let head = '';
|
|
1239
|
+
while (start > 0 && !breaks.includes(text[start - 1])) {
|
|
1240
|
+
start -= 1;
|
|
1241
|
+
if (pointer - start > 75 / 2 - 1) {
|
|
1242
|
+
head = ' ... ';
|
|
1243
|
+
start += 5;
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
let end = pointer;
|
|
1248
|
+
let tail = '';
|
|
1249
|
+
while (end < text.length && !breaks.includes(text[end])) {
|
|
1250
|
+
end += 1;
|
|
1251
|
+
if (end - pointer > 75 / 2 - 1) {
|
|
1252
|
+
tail = ' ... ';
|
|
1253
|
+
end -= 5;
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
const before = text.slice(0, pointer);
|
|
1258
|
+
const line = (before.match(/\r\n|[\n\r\u0085\u2028\u2029]/gu) ?? []).length + 1;
|
|
1259
|
+
const lineStart = Math.max(...[...breaks].map((mark) => before.lastIndexOf(mark))) + 1;
|
|
1260
|
+
const column = pointer - lineStart + 1;
|
|
1261
|
+
const snippet = ` ${head}${text.slice(start, end)}${tail}\n` +
|
|
1262
|
+
`${' '.repeat(4 + pointer - start + head.length)}^`;
|
|
1263
|
+
const error = new Error(`could not determine a constructor for the tag ${tag.includes("'") && !tag.includes('"') ? `"${tag}"` : `'${tag}'`}\n` +
|
|
1264
|
+
` at line ${String(line)}, column ${String(column)}:\n${snippet}`);
|
|
1265
|
+
error.name = 'YamlTagError';
|
|
1266
|
+
return error;
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* config.yaml's text, in block style with its keys in their own order, through
|
|
1270
|
+
* `yaml-dump.ts`'s emitter.
|
|
1271
|
+
*
|
|
1272
|
+
* It was the `yaml` package's emitter with options and tags shaped to match, which closed
|
|
1273
|
+
* the scalar choices one at a time and could not close the rest: a double-quoted value was
|
|
1274
|
+
* never folded at the 80th column and spelled `a\ \nb` where the established file holds
|
|
1275
|
+
* `"a \nb"`; a value holding a single quote was double-quoted where the established
|
|
1276
|
+
* emitter doubles the quote, `'''q'''`, and `...` and `---` were written bare; a list under
|
|
1277
|
+
* a key was indented and an anchor named `&a1` where the established file holds `- a` at
|
|
1278
|
+
* the key's column and `&id001`; and a plain scalar folded a word earlier. Each read back
|
|
1279
|
+
* to the same value, and each made any `config set` or `use` rewrite the lines an earlier
|
|
1280
|
+
* release had written. The scalar representers this replaces -- a float's `.nan` and
|
|
1281
|
+
* `1.0e-07`, the quoted `=` and `<<`, the escapes of non-ASCII -- are `yaml-dump.ts`'s own
|
|
1282
|
+
* behaviour; a Date is written as the reader recorded it (`yamlDateText`).
|
|
1283
|
+
*/
|
|
1284
|
+
function stringifyConfigYaml(value) {
|
|
1285
|
+
return (0, yaml_dump_1.safeDump)(rewriteScalars(value), { dateText: yamlDateText });
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* A document `safeLoadYaml` read and a command edited, written through `yaml-dump.ts`'s
|
|
1289
|
+
* emitter with its keys in their own order: a Date the reader made is written back as the
|
|
1290
|
+
* text it was read from. For a file that is not config.yaml -- a Kubernetes workspace's
|
|
1291
|
+
* `values.yaml`.
|
|
1292
|
+
*/
|
|
1293
|
+
function safeDumpYaml(value) {
|
|
1294
|
+
return (0, yaml_dump_1.safeDump)(value, { dateText: yamlDateText });
|
|
1295
|
+
}
|
|
1296
|
+
/** Whether a loaded YAML value is a mapping: an object of no other kind than `{}`. */
|
|
1297
|
+
function isPlainMapping(value) {
|
|
1298
|
+
if (value === null || typeof value !== 'object')
|
|
1299
|
+
return false;
|
|
1300
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1301
|
+
return prototype === Object.prototype || prototype === null;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Load `~/.houston/config.yaml` (or `{}`), with env-var overrides applied.
|
|
1305
|
+
*
|
|
1306
|
+
* Pass `withEnv: false` when the object will be written back through `saveConfig` --
|
|
1307
|
+
* otherwise ephemeral env values (notably `HOUSTON_REG_TOKEN`) would be persisted into
|
|
1308
|
+
* the file.
|
|
1309
|
+
*/
|
|
1310
|
+
function loadConfig(withEnv = true) {
|
|
1311
|
+
const file = configFile();
|
|
1312
|
+
let data = {};
|
|
1313
|
+
if (fs.existsSync(file)) {
|
|
1314
|
+
const doc = safeLoadDocument(fs.readFileSync(file, 'utf8'));
|
|
1315
|
+
const loaded = doc.toJS({ maxAliasCount: -1 });
|
|
1316
|
+
// A MAPPING, which the loader builds as a plain object. Any object that was not an
|
|
1317
|
+
// array passed, so a whole document that is a timestamp, a
|
|
1318
|
+
// `!!set`, an `!!omap` or `!!binary` became the Date, Set, Map or Uint8Array the next
|
|
1319
|
+
// write set the key on as a property -- which the emitter drops, so `config set` and
|
|
1320
|
+
// `use` reported success and stored nothing, and the file was rewritten as the same
|
|
1321
|
+
// non-mapping. Anything else now starts from `{}`, and the write stores the one key.
|
|
1322
|
+
if (isPlainMapping(loaded)) {
|
|
1323
|
+
data = loaded;
|
|
1324
|
+
const items = constructNode(doc);
|
|
1325
|
+
if (items instanceof Map) {
|
|
1326
|
+
const read = new Map(Object.keys(data).map((key) => [key, fingerprint(data[key])]));
|
|
1327
|
+
yamlDocuments.set(data, { items, read });
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
if (withEnv) {
|
|
1332
|
+
for (const [key, name] of Object.entries(ENV_OVERRIDES)) {
|
|
1333
|
+
const value = env(name);
|
|
1334
|
+
if (value)
|
|
1335
|
+
data[key] = value;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
return data;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Persist config.yaml atomically (temp file + rename).
|
|
1342
|
+
*
|
|
1343
|
+
* A plain write could be read half-written -- the web GUI runs service calls
|
|
1344
|
+
* concurrently, so concurrent readers are real.
|
|
1345
|
+
*/
|
|
1346
|
+
function saveConfig(cfg) {
|
|
1347
|
+
// 0700 ON CREATE, so a box that never runs `serve` is not left depending on the
|
|
1348
|
+
// umask. This directory also holds the audit log, the accounts file and the ACME
|
|
1349
|
+
// material. config.yaml itself holds no secret, so this is depth rather than a fix. On
|
|
1350
|
+
// the home ALONE: a parent it makes takes the umask's mode.
|
|
1351
|
+
(0, mkdir_parents_1.mkdirParents)(home(), 0o700);
|
|
1352
|
+
const file = configFile();
|
|
1353
|
+
const tmp = (0, home_1.joinPath)(path.dirname(file), `${path.basename(file)}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`);
|
|
1354
|
+
try {
|
|
1355
|
+
// 0600 via an explicit mode rather than the default, which would take the umask.
|
|
1356
|
+
fs.writeFileSync(tmp, stringifyConfigYaml(cfg), { encoding: 'utf8', mode: 0o600 });
|
|
1357
|
+
fs.renameSync(tmp, file);
|
|
1358
|
+
}
|
|
1359
|
+
finally {
|
|
1360
|
+
try {
|
|
1361
|
+
fs.unlinkSync(tmp);
|
|
1362
|
+
}
|
|
1363
|
+
catch {
|
|
1364
|
+
// no-op after a successful rename
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Read-modify-write config.yaml; `mutate(cfg)` edits in place.
|
|
1370
|
+
*
|
|
1371
|
+
* Reads with env overrides OFF on purpose: this writes the file back, and an ephemeral
|
|
1372
|
+
* `HOUSTON_REG_TOKEN` must never be persisted into it.
|
|
1373
|
+
*/
|
|
1374
|
+
function updateConfig(mutate) {
|
|
1375
|
+
const cfg = loadConfig(false);
|
|
1376
|
+
mutate(cfg);
|
|
1377
|
+
saveConfig(cfg);
|
|
1378
|
+
return cfg;
|
|
1379
|
+
}
|
|
1380
|
+
/** Accounts this box has been told it may spend in. Empty by default. */
|
|
1381
|
+
function approvedAwsAccounts() {
|
|
1382
|
+
const raw = String(loadConfig()[exports.CLOUD_ACCOUNTS_KEY] ?? '');
|
|
1383
|
+
return new Set(raw
|
|
1384
|
+
.split(',')
|
|
1385
|
+
.map((part) => part.trim())
|
|
1386
|
+
.filter(Boolean));
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* The box's default `--context`, or "".
|
|
1390
|
+
*
|
|
1391
|
+
* ONE reader, because three callers need the same answer and disagreeing is a real
|
|
1392
|
+
* failure rather than an untidiness: `up` decides where a workspace goes, the capacity
|
|
1393
|
+
* preflight decides whose RAM to reserve, and `doctor` reports on a cluster. A default
|
|
1394
|
+
* honoured by two of the three makes `doctor` a second opinion about the boot.
|
|
1395
|
+
*/
|
|
1396
|
+
function defaultKubeContext() {
|
|
1397
|
+
return String(loadConfig()[exports.KUBE_CONTEXT_KEY] ?? '').trim();
|
|
1398
|
+
}
|