@rocket.chat/houston 0.27.0-next.3 → 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 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- 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,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentContext = currentContext;
|
|
4
|
+
exports.runWithContext = runWithContext;
|
|
5
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
6
|
+
const EMPTY_CONTEXT = Object.freeze({
|
|
7
|
+
actor: '',
|
|
8
|
+
origin: '',
|
|
9
|
+
jobId: '',
|
|
10
|
+
workspace: '',
|
|
11
|
+
});
|
|
12
|
+
const STORAGE = new node_async_hooks_1.AsyncLocalStorage();
|
|
13
|
+
function currentContext() {
|
|
14
|
+
return STORAGE.getStore() ?? EMPTY_CONTEXT;
|
|
15
|
+
}
|
|
16
|
+
function runWithContext(values, fn) {
|
|
17
|
+
return STORAGE.run({ ...currentContext(), ...values }, fn);
|
|
18
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Domain errors shared by the CLI and the web API.
|
|
4
|
+
*
|
|
5
|
+
* The CLI historically failed by calling a `die()` that exited the process, at ~75 sites.
|
|
6
|
+
* That is fine for a one-shot process but fatal for a long-lived server: a single bad request
|
|
7
|
+
* would exit the whole thing. The service layer instead raises these, and each front-end
|
|
8
|
+
* translates them:
|
|
9
|
+
*
|
|
10
|
+
* CLI -> catch (e) { if (e instanceof ReproError) fail(e); } // red line + exitCode
|
|
11
|
+
* API -> catch (e) { if (e instanceof ReproError) reply(e.httpStatus); }
|
|
12
|
+
*
|
|
13
|
+
* One taxonomy, three consumers. `httpStatus` lets the web layer map each cause to the
|
|
14
|
+
* right status code without the service layer importing anything web-specific;
|
|
15
|
+
* `exitCode` does the same for the CLI so a script or agent can tell "not ready yet"
|
|
16
|
+
* from "known dead" without parsing text; `code` is the stable identifier a
|
|
17
|
+
* machine-readable payload reports, so callers branch on it rather than on prose.
|
|
18
|
+
*
|
|
19
|
+
* `code` values are stable API. Renaming one is a breaking change; the MESSAGE attached
|
|
20
|
+
* to an exception is not stable and may be reworded freely. Errors are compared on
|
|
21
|
+
* `{code, exitCode, httpStatus, kind}` and never on the message, for exactly that reason.
|
|
22
|
+
*
|
|
23
|
+
* TWO SHAPES THE LANGUAGE FORCES, both narrow:
|
|
24
|
+
*
|
|
25
|
+
* 1. `code`/`exitCode`/`httpStatus` belong to the CLASS, and an instance must answer
|
|
26
|
+
* them. JavaScript has no instance lookup of a static that survives subclassing
|
|
27
|
+
* cleanly, so each constructor copies its class defaults onto the instance. The
|
|
28
|
+
* observable contract is the same and `errors.test.ts` pins it.
|
|
29
|
+
*
|
|
30
|
+
* 2. `MissingRecordError` is both a not-found error and a missing file -- deliberately
|
|
31
|
+
* BOTH, so a dozen callers that already treat it as a missing file keep working
|
|
32
|
+
* while `serve` still answers 404. TypeScript has no multiple
|
|
33
|
+
* inheritance, so it extends `NotFoundError` and carries `isFileNotFound` plus the
|
|
34
|
+
* `ENOENT` `errno` code. A caller that means "this workspace has no record" tests
|
|
35
|
+
* that flag; nothing tests the class name.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.EXIT_CODES = exports.ERROR_CLASSES = exports.RAISED_GATE_CODES = exports.GATE_CODES = exports.AuthorityGateError = exports.CreateFailedError = exports.PreflightError = exports.DockerError = exports.NotReadyError = exports.MissingRecordError = exports.NotFoundError = exports.ConflictError = exports.ValidationError = exports.ReproError = void 0;
|
|
39
|
+
exports.errorText = errorText;
|
|
40
|
+
exports.errorCodes = errorCodes;
|
|
41
|
+
exports.asPayload = asPayload;
|
|
42
|
+
class ReproError extends Error {
|
|
43
|
+
/**
|
|
44
|
+
* `exitCode` is for the one shape a class cannot carry: a plain ReproError (REPRO_ERROR
|
|
45
|
+
* in the event log) that exits N. The class, and so what
|
|
46
|
+
* `capabilities` advertises, is unchanged.
|
|
47
|
+
*/
|
|
48
|
+
constructor(message = '', options = {}) {
|
|
49
|
+
super(message);
|
|
50
|
+
const cls = new.target;
|
|
51
|
+
this.name = new.target.name;
|
|
52
|
+
this.httpStatus = cls.httpStatus;
|
|
53
|
+
this.exitCode = options.exitCode ?? cls.exitCode;
|
|
54
|
+
this.code = options.code || cls.code;
|
|
55
|
+
this.details = { ...(options.details ?? {}) };
|
|
56
|
+
// Without this an `instanceof` check fails for anything extending a built-in when
|
|
57
|
+
// the emit target is below ES2015. `target: es2020` makes it unnecessary, and it is
|
|
58
|
+
// kept because a future target change must not silently break every `catch`.
|
|
59
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ReproError = ReproError;
|
|
63
|
+
/** The web API status for this cause. */
|
|
64
|
+
ReproError.httpStatus = 400;
|
|
65
|
+
/** The stable identifier a machine-readable payload reports. */
|
|
66
|
+
ReproError.code = 'REPRO_ERROR';
|
|
67
|
+
/** The CLI process exit code. */
|
|
68
|
+
ReproError.exitCode = 1;
|
|
69
|
+
/**
|
|
70
|
+
* Whether this build can actually RAISE this class. `false` marks one the hierarchy
|
|
71
|
+
* knows about and nothing produces; `capabilities` must not advertise those, because
|
|
72
|
+
* a published code nothing can emit teaches a caller to write a branch that never
|
|
73
|
+
* runs.
|
|
74
|
+
*/
|
|
75
|
+
ReproError.advertised = true;
|
|
76
|
+
/** Bad input (port range, name, unknown --set param, bad version/preset). */
|
|
77
|
+
class ValidationError extends ReproError {
|
|
78
|
+
}
|
|
79
|
+
exports.ValidationError = ValidationError;
|
|
80
|
+
ValidationError.httpStatus = 400;
|
|
81
|
+
ValidationError.code = 'VALIDATION_FAILED';
|
|
82
|
+
// usage error: fix the call, retrying unchanged will not help
|
|
83
|
+
ValidationError.exitCode = 2;
|
|
84
|
+
/** A resource is already taken (host port / repro name / monitoring slot). */
|
|
85
|
+
class ConflictError extends ReproError {
|
|
86
|
+
}
|
|
87
|
+
exports.ConflictError = ConflictError;
|
|
88
|
+
ConflictError.httpStatus = 409;
|
|
89
|
+
ConflictError.code = 'CONFLICT';
|
|
90
|
+
// pick another name/port and retry
|
|
91
|
+
ConflictError.exitCode = 8;
|
|
92
|
+
/** No such repro / default repro missing. */
|
|
93
|
+
class NotFoundError extends ReproError {
|
|
94
|
+
}
|
|
95
|
+
exports.NotFoundError = NotFoundError;
|
|
96
|
+
NotFoundError.httpStatus = 404;
|
|
97
|
+
NotFoundError.code = 'NOT_FOUND';
|
|
98
|
+
NotFoundError.exitCode = 4;
|
|
99
|
+
/**
|
|
100
|
+
* A workspace directory with no readable `repro.json`.
|
|
101
|
+
*
|
|
102
|
+
* As a `NotFoundError` it carries `httpStatus = 404`, so `serve` answers a half-written
|
|
103
|
+
* workspace with the documented status instead of a 500 and a stack trace. As a
|
|
104
|
+
* file-not-found it is still what a dozen callers already mean to skip -- "this
|
|
105
|
+
* workspace has no record" genuinely is the thing they skip -- which is why the flag is
|
|
106
|
+
* here rather than each of those handlers being rewritten with one silent miss enough
|
|
107
|
+
* to turn a skip into a crash.
|
|
108
|
+
*/
|
|
109
|
+
class MissingRecordError extends NotFoundError {
|
|
110
|
+
constructor() {
|
|
111
|
+
super(...arguments);
|
|
112
|
+
this.isFileNotFound = true;
|
|
113
|
+
this.errno = 'ENOENT';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.MissingRecordError = MissingRecordError;
|
|
117
|
+
/** Docker is down, or Rocket.Chat is not serving / cannot be logged into. */
|
|
118
|
+
class NotReadyError extends ReproError {
|
|
119
|
+
}
|
|
120
|
+
exports.NotReadyError = NotReadyError;
|
|
121
|
+
NotReadyError.httpStatus = 409;
|
|
122
|
+
NotReadyError.code = 'NOT_READY';
|
|
123
|
+
// still unknown: the caller may poll again
|
|
124
|
+
NotReadyError.exitCode = 5;
|
|
125
|
+
/** A `docker`/`docker compose` invocation failed. */
|
|
126
|
+
class DockerError extends ReproError {
|
|
127
|
+
}
|
|
128
|
+
exports.DockerError = DockerError;
|
|
129
|
+
DockerError.httpStatus = 502;
|
|
130
|
+
DockerError.code = 'ENGINE_UNAVAILABLE';
|
|
131
|
+
// preflight/engine problem: run `houston doctor`
|
|
132
|
+
DockerError.exitCode = 3;
|
|
133
|
+
/**
|
|
134
|
+
* Environment or capacity preflight refused the request.
|
|
135
|
+
*
|
|
136
|
+
* Distinct from `ValidationError` (bad caller input) and `DockerError` (engine
|
|
137
|
+
* unreachable for compose). Capacity shortfalls and unsupported resize paths use this
|
|
138
|
+
* so they never masquerade as a successful preflight.
|
|
139
|
+
*/
|
|
140
|
+
class PreflightError extends ReproError {
|
|
141
|
+
}
|
|
142
|
+
exports.PreflightError = PreflightError;
|
|
143
|
+
PreflightError.httpStatus = 409;
|
|
144
|
+
PreflightError.code = 'PREFLIGHT_FAILED';
|
|
145
|
+
PreflightError.exitCode = 3;
|
|
146
|
+
/**
|
|
147
|
+
* A create hit a condition that cannot self-heal, so waiting is pointless.
|
|
148
|
+
*
|
|
149
|
+
* Distinct from `NotReadyError` on purpose: 5 means "still unknown, the clock ran out",
|
|
150
|
+
* 7 means "known dead, stop now". Collapsing them is what makes callers wait out a run
|
|
151
|
+
* that had already failed.
|
|
152
|
+
*/
|
|
153
|
+
class CreateFailedError extends ReproError {
|
|
154
|
+
}
|
|
155
|
+
exports.CreateFailedError = CreateFailedError;
|
|
156
|
+
CreateFailedError.httpStatus = 500;
|
|
157
|
+
CreateFailedError.code = 'CREATE_FAILED';
|
|
158
|
+
CreateFailedError.exitCode = 7;
|
|
159
|
+
/**
|
|
160
|
+
* An action needs a human decision houston is not authorised to make.
|
|
161
|
+
*
|
|
162
|
+
* Public exposure, an unapproved cluster, new credentials, deleting something houston
|
|
163
|
+
* does not own, retaining a run. Never retryable and never auto-approvable:
|
|
164
|
+
* `approveWith` is what to ask a HUMAN to run, not something the caller may run itself.
|
|
165
|
+
*/
|
|
166
|
+
class AuthorityGateError extends ReproError {
|
|
167
|
+
constructor(message, options = {}) {
|
|
168
|
+
super(message, {
|
|
169
|
+
...(options.code ? { code: options.code } : {}),
|
|
170
|
+
...(options.details !== undefined ? { details: options.details } : {}),
|
|
171
|
+
});
|
|
172
|
+
this.kind = options.kind ?? '';
|
|
173
|
+
this.subject = options.subject ?? '';
|
|
174
|
+
this.approveWith = options.approveWith ?? '';
|
|
175
|
+
}
|
|
176
|
+
asGate() {
|
|
177
|
+
const out = { kind: this.kind, subject: this.subject, approve_with: this.approveWith };
|
|
178
|
+
if (Object.keys(this.details).length > 0)
|
|
179
|
+
out.details = { ...this.details };
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.AuthorityGateError = AuthorityGateError;
|
|
184
|
+
AuthorityGateError.httpStatus = 403;
|
|
185
|
+
AuthorityGateError.code = 'GATE';
|
|
186
|
+
AuthorityGateError.exitCode = 6;
|
|
187
|
+
AuthorityGateError.advertised = true;
|
|
188
|
+
/**
|
|
189
|
+
* Every authority gate houston can raise, declared rather than invented at the call
|
|
190
|
+
* site. `AuthorityGateError` takes its code as an argument, so without this registry
|
|
191
|
+
* the published error-code set could only advertise the base "GATE" and a caller could
|
|
192
|
+
* not know what to expect. Adding a gate means adding it here, which is the point: a
|
|
193
|
+
* gate a caller cannot anticipate is one it cannot handle.
|
|
194
|
+
*/
|
|
195
|
+
exports.GATE_CODES = Object.freeze({
|
|
196
|
+
GATE_NOT_ONBOARDED: 'houston has not been onboarded on this machine',
|
|
197
|
+
GATE_OWNED_CLUSTER: 'the houston-owned local cluster was not authorised',
|
|
198
|
+
GATE_ENGINE_RESIZE: 'resizing the container engine was not authorised',
|
|
199
|
+
GATE_UNAPPROVED_CLUSTER: 'the target Kubernetes cluster is not an approved one',
|
|
200
|
+
GATE_DELETE_UNOWNED: 'the resource was not created by houston',
|
|
201
|
+
GATE_KEEP_UNOWNED: 'the cluster was not created by houston, so its expiry is not houston’s to move',
|
|
202
|
+
GATE_SHARE_UNOWNED: 'the cluster was not created by houston, so houston grants no access to it',
|
|
203
|
+
GATE_PUBLIC_EXPOSURE: 'the request would expose a workspace beyond loopback',
|
|
204
|
+
GATE_RETENTION: 'retaining this run was not authorised',
|
|
205
|
+
// DISTINCT from GATE_UNAPPROVED_CLUSTER, which already means "the CA private key may
|
|
206
|
+
// not go there". Giving one code two meanings breaks the premise jsonout rests on --
|
|
207
|
+
// that a caller branches on `code` -- and these two want opposite responses: one is
|
|
208
|
+
// about a secret leaving this box, the other about money leaving an account.
|
|
209
|
+
GATE_CLOUD_SPEND: 'creating a cluster that costs money was not authorised',
|
|
210
|
+
GATE_WRONG_ACCOUNT: 'the selected AWS account differs from the server identity',
|
|
211
|
+
GATE_WRONG_CLUSTER: 'AWS returned a different cluster than the one selected',
|
|
212
|
+
});
|
|
213
|
+
/**
|
|
214
|
+
* The gate codes this build can actually PRODUCE, as opposed to the ones it knows
|
|
215
|
+
* about. Publishing all of `GATE_CODES` is the exact failure the published code set
|
|
216
|
+
* exists to prevent -- a caller writing a branch that never runs. Advertising only the
|
|
217
|
+
* base "GATE" is the opposite failure, because the base is not what arrives: a gate
|
|
218
|
+
* carries its specific code.
|
|
219
|
+
*/
|
|
220
|
+
exports.RAISED_GATE_CODES = Object.freeze([
|
|
221
|
+
'GATE_UNAPPROVED_CLUSTER',
|
|
222
|
+
'GATE_CLOUD_SPEND',
|
|
223
|
+
'GATE_DELETE_UNOWNED',
|
|
224
|
+
'GATE_KEEP_UNOWNED',
|
|
225
|
+
'GATE_SHARE_UNOWNED',
|
|
226
|
+
'GATE_WRONG_ACCOUNT',
|
|
227
|
+
'GATE_WRONG_CLUSTER',
|
|
228
|
+
]);
|
|
229
|
+
/**
|
|
230
|
+
* The hierarchy, as a list.
|
|
231
|
+
*
|
|
232
|
+
* The published error-code set is derived from every subclass, so a new subclass cannot
|
|
233
|
+
* be forgotten. JavaScript keeps no subclass registry, so the walk has to become a list
|
|
234
|
+
* -- and a list is exactly the thing that drifts. `errors.test.ts` therefore reads this
|
|
235
|
+
* module's own source and fails if a class exported here is missing from it, which is the
|
|
236
|
+
* same guarantee by the same mechanism that holds `RAISED_GATE_CODES`
|
|
237
|
+
* (`invariants/error-codes.test.ts`).
|
|
238
|
+
*/
|
|
239
|
+
exports.ERROR_CLASSES = Object.freeze([
|
|
240
|
+
ReproError,
|
|
241
|
+
ValidationError,
|
|
242
|
+
ConflictError,
|
|
243
|
+
NotFoundError,
|
|
244
|
+
MissingRecordError,
|
|
245
|
+
NotReadyError,
|
|
246
|
+
DockerError,
|
|
247
|
+
PreflightError,
|
|
248
|
+
CreateFailedError,
|
|
249
|
+
AuthorityGateError,
|
|
250
|
+
]);
|
|
251
|
+
/**
|
|
252
|
+
* The message alone, not `String(error)`'s `"Error: …"`.
|
|
253
|
+
*
|
|
254
|
+
* `String(new Error('bad rule'))` is `Error: bad rule`, where the established wording
|
|
255
|
+
* interpolates `bad rule`. Every message that interpolates a caught exception
|
|
256
|
+
* (`bad slo: <error>`, `can't import - repro not ready: <error>`) keeps that wording, so the
|
|
257
|
+
* prefix is a difference a user would see.
|
|
258
|
+
*/
|
|
259
|
+
function errorText(error) {
|
|
260
|
+
return error instanceof Error ? error.message : String(error);
|
|
261
|
+
}
|
|
262
|
+
/** Every stable error code this build can actually emit, sorted. */
|
|
263
|
+
function errorCodes() {
|
|
264
|
+
const seen = new Set();
|
|
265
|
+
for (const cls of exports.ERROR_CLASSES) {
|
|
266
|
+
if (cls.code && cls.advertised)
|
|
267
|
+
seen.add(cls.code);
|
|
268
|
+
}
|
|
269
|
+
for (const code of exports.RAISED_GATE_CODES)
|
|
270
|
+
seen.add(code);
|
|
271
|
+
return [...seen].sort();
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* A failure as a machine-readable object, for any front-end that speaks JSON.
|
|
275
|
+
*
|
|
276
|
+
* `code` is the stable half. `kind` is still emitted because it costs nothing and
|
|
277
|
+
* something may already read it, but a class name is a refactor away from changing
|
|
278
|
+
* while renaming a `code` is a breaking change -- new callers use `code`.
|
|
279
|
+
*/
|
|
280
|
+
function asPayload(exc) {
|
|
281
|
+
const body = { error: exc.message, code: exc.code, kind: exc.name };
|
|
282
|
+
if (exc instanceof AuthorityGateError) {
|
|
283
|
+
body.gate = exc.asGate();
|
|
284
|
+
}
|
|
285
|
+
else if (Object.keys(exc.details).length > 0) {
|
|
286
|
+
body.details = { ...exc.details };
|
|
287
|
+
}
|
|
288
|
+
return body;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Every exit code this taxonomy can produce, with a short machine-readable label.
|
|
292
|
+
* Front-ends publish this rather than hardcoding the numbers, so the map has exactly
|
|
293
|
+
* one definition.
|
|
294
|
+
*/
|
|
295
|
+
exports.EXIT_CODES = Object.freeze({
|
|
296
|
+
0: 'ok',
|
|
297
|
+
1: 'internal',
|
|
298
|
+
2: 'usage',
|
|
299
|
+
3: 'preflight',
|
|
300
|
+
4: 'not_found',
|
|
301
|
+
5: 'not_ready',
|
|
302
|
+
6: 'gate',
|
|
303
|
+
7: 'create_failed',
|
|
304
|
+
8: 'conflict',
|
|
305
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Progress event model shared by every long-running service function.
|
|
4
|
+
*
|
|
5
|
+
* A single stream type unifies the two progress channels: `log=` callbacks (seed,
|
|
6
|
+
* config-import) and streamed subprocess output (docker, k6). A service function takes
|
|
7
|
+
* `emit: Emit` and calls it with `Event`s; the CLI prints them, the web layer buffers them
|
|
8
|
+
* per job and pushes them over SSE.
|
|
9
|
+
*
|
|
10
|
+
* **Progress is an Event, not a print.** A service function that writes to stdout
|
|
11
|
+
* instead of emitting is invisible in the GUI -- that is the whole cost of this module
|
|
12
|
+
* and the reason ~125 call sites go through it.
|
|
13
|
+
*
|
|
14
|
+
* NO LOCK GUARDS THE SINK REGISTRY. A server that ran service calls on worker threads
|
|
15
|
+
* would need one; Node has one JavaScript thread per process, so a lock would guard
|
|
16
|
+
* nothing: no other execution can interleave between reading `SINKS` and writing it. The
|
|
17
|
+
* SNAPSHOT before dispatch is kept and is not cosmetic -- a sink may install or uninstall
|
|
18
|
+
* while handling an event, and iterating the live map while it mutates is a real hazard in
|
|
19
|
+
* any language.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.NOTHING_LEFT = exports.UNPUBLISHED_PHASES = exports.PHASES = void 0;
|
|
23
|
+
exports.event = event;
|
|
24
|
+
exports.asDict = asDict;
|
|
25
|
+
exports.installSink = installSink;
|
|
26
|
+
exports.installedSinks = installedSinks;
|
|
27
|
+
exports.nullEmit = nullEmit;
|
|
28
|
+
exports.info = info;
|
|
29
|
+
exports.warn = warn;
|
|
30
|
+
/**
|
|
31
|
+
* THE PHASE VOCABULARY, AS A TYPE.
|
|
32
|
+
*
|
|
33
|
+
* `jsonout.PHASES` publishes this list as part of the `--json` contract, and re-exports
|
|
34
|
+
* it from here rather than keeping a second copy: two lists of the same names is how a
|
|
35
|
+
* phase gets emitted that the contract never published.
|
|
36
|
+
*
|
|
37
|
+
* A guard that runs a regex for `phase="..."` over the source can only see the phases
|
|
38
|
+
* spelled as a literal at the emit site and reports nothing about one built from a
|
|
39
|
+
* variable. Here the vocabulary is the TYPE of
|
|
40
|
+
* `Event.phase`, so an unpublished phase is a compile error at the call site and there
|
|
41
|
+
* is no spelling for it that the check cannot see.
|
|
42
|
+
*
|
|
43
|
+
* A phase name arriving from OUTSIDE this process -- a replayed event log, an event
|
|
44
|
+
* from an earlier release -- is still a plain string and still normalises to "info" with
|
|
45
|
+
* the original kept in `detail.phase_raw`; `jsonout.EventWriter.event` owns that and
|
|
46
|
+
* deliberately takes a `string`.
|
|
47
|
+
*/
|
|
48
|
+
exports.PHASES = Object.freeze([
|
|
49
|
+
'preflight', // engine, versions, disk, ports, connectivity checks
|
|
50
|
+
'resolve', // version / image / chart resolution
|
|
51
|
+
'provision', // create or verify the execution target itself
|
|
52
|
+
'plan', // work out what will be done, before doing any of it
|
|
53
|
+
'pull', // fetching images
|
|
54
|
+
'create', // building the workspace's own definition
|
|
55
|
+
'boot', // starting components
|
|
56
|
+
'wait', // waiting for readiness or health
|
|
57
|
+
'post_ready', // settings applied after Rocket.Chat serves
|
|
58
|
+
'config', // changing a running workspace's configuration
|
|
59
|
+
'tls', // certificates and the shared edge
|
|
60
|
+
'seed', // seeding users, channels, messages
|
|
61
|
+
'backup', // dumping data out
|
|
62
|
+
'restore', // loading data back in
|
|
63
|
+
'upgrade', // moving a workspace between Rocket.Chat versions
|
|
64
|
+
'monitor', // attaching or detaching Prometheus + Grafana
|
|
65
|
+
'teardown', // stopping and removing
|
|
66
|
+
'ready', // the workspace is serving
|
|
67
|
+
'done', // finished successfully
|
|
68
|
+
'failed', // terminal failure; carries detail.code
|
|
69
|
+
'queued', // accepted, waiting for a slot rather than working yet
|
|
70
|
+
'info', // uncategorised progress; never branch on it
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* PHASES THIS BUILD EMITS AND THE CONTRACT DOES NOT PUBLISH.
|
|
74
|
+
*
|
|
75
|
+
* Exactly one, and it is a DEFECT that is bounded here rather than hidden: `core/loadtest.ts`
|
|
76
|
+
* emits `phase: 'k6'` at eight sites, as earlier releases' load test does, and `k6` is
|
|
77
|
+
* not in `PHASES`. On the wire it normalises to `info` with `detail.phase_raw = "k6"`,
|
|
78
|
+
* exactly as it always has, so nothing a caller sees is wrong -- but a caller watching
|
|
79
|
+
* for k6 progress never fires, which is precisely what the published vocabulary exists to
|
|
80
|
+
* prevent.
|
|
81
|
+
*
|
|
82
|
+
* A SOURCE-SCANNING GUARD CANNOT SEE IT. Earlier releases' regex is `phase="([a-z_]+)"`,
|
|
83
|
+
* and `k6` has a digit in it, so their four emit sites match nothing and the guard has
|
|
84
|
+
* reported a clean vocabulary for as long as they have existed. Measured: that pattern
|
|
85
|
+
* finds nothing in `phase="k6"`.
|
|
86
|
+
*
|
|
87
|
+
* Adding `k6` to `PHASES` is the real fix and is NOT made here: `PHASES` is published by
|
|
88
|
+
* `capabilities`, whose baseline is a frozen fixture, and changing what a command emits
|
|
89
|
+
* would make its output differ from what earlier releases emitted. So it is named here
|
|
90
|
+
* instead, where the compiler enforces that the list of exceptions is CLOSED -- a second
|
|
91
|
+
* unpublished phase does not compile until somebody writes it down -- and
|
|
92
|
+
* `invariants/phase-vocabulary.test.ts` pins both that this is the only member and that it
|
|
93
|
+
* really does normalise to `info` with `phase_raw` on the wire.
|
|
94
|
+
*/
|
|
95
|
+
exports.UNPUBLISHED_PHASES = Object.freeze(['k6']);
|
|
96
|
+
/**
|
|
97
|
+
* The code of the warning a stopped or failed create's cleanup gives when it took back
|
|
98
|
+
* everything the create had made, so a job's closing line does not say that any of it stays.
|
|
99
|
+
*/
|
|
100
|
+
exports.NOTHING_LEFT = 'nothing-left';
|
|
101
|
+
/** Build an Event with the established defaults. */
|
|
102
|
+
function event(message, fields = {}) {
|
|
103
|
+
return {
|
|
104
|
+
message,
|
|
105
|
+
phase: fields.phase ?? 'info',
|
|
106
|
+
level: fields.level ?? 'info',
|
|
107
|
+
pct: fields.pct ?? null,
|
|
108
|
+
data: fields.data ?? {},
|
|
109
|
+
terminal: fields.terminal ?? false,
|
|
110
|
+
code: fields.code ?? '',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** The wire object for one Event, matching `Event.as_dict()`. */
|
|
114
|
+
function asDict(ev) {
|
|
115
|
+
return {
|
|
116
|
+
message: ev.message,
|
|
117
|
+
phase: ev.phase,
|
|
118
|
+
level: ev.level,
|
|
119
|
+
pct: ev.pct,
|
|
120
|
+
data: ev.data,
|
|
121
|
+
terminal: ev.terminal,
|
|
122
|
+
code: ev.code,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Sinks are keyed because two independently created front ends may want the same
|
|
127
|
+
* durable destination. The count is OWNERSHIP, not invocation multiplicity: two live
|
|
128
|
+
* apps lease the event log once each, while each Event still reaches it exactly once.
|
|
129
|
+
*/
|
|
130
|
+
const SINKS = new Map();
|
|
131
|
+
/**
|
|
132
|
+
* Lease one keyed sink and return an idempotent release callback.
|
|
133
|
+
*
|
|
134
|
+
* Reinstalling the exact same function adds an ownership lease. Reusing a key for a
|
|
135
|
+
* DIFFERENT function is an error rather than a silent replacement: otherwise one app
|
|
136
|
+
* starting could redirect another app's live event stream, and the first app's shutdown
|
|
137
|
+
* could then remove the replacement.
|
|
138
|
+
*/
|
|
139
|
+
function installSink(key, fn) {
|
|
140
|
+
if (!key)
|
|
141
|
+
throw new Error('an event sink key cannot be empty');
|
|
142
|
+
const current = SINKS.get(key);
|
|
143
|
+
if (current !== undefined && current.fn !== fn) {
|
|
144
|
+
throw new Error(`event sink ${JSON.stringify(key)} is already installed`);
|
|
145
|
+
}
|
|
146
|
+
SINKS.set(key, { fn, leases: current === undefined ? 1 : current.leases + 1 });
|
|
147
|
+
let released = false;
|
|
148
|
+
return function unregister() {
|
|
149
|
+
if (released)
|
|
150
|
+
return;
|
|
151
|
+
released = true;
|
|
152
|
+
const held = SINKS.get(key);
|
|
153
|
+
if (held === undefined || held.fn !== fn)
|
|
154
|
+
return;
|
|
155
|
+
if (held.leases === 1)
|
|
156
|
+
SINKS.delete(key);
|
|
157
|
+
else
|
|
158
|
+
SINKS.set(key, { fn, leases: held.leases - 1 });
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** How many sinks are installed. For tests and for `status`-style reporting. */
|
|
162
|
+
function installedSinks() {
|
|
163
|
+
return [...SINKS.keys()].sort();
|
|
164
|
+
}
|
|
165
|
+
/** Discard events (the default for callers that do not care about progress). */
|
|
166
|
+
function nullEmit(_event) {
|
|
167
|
+
/* deliberately empty */
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Deliver the event to a snapshot of the currently installed sinks.
|
|
171
|
+
*
|
|
172
|
+
* HERE, because this module is the single funnel every long-running function goes
|
|
173
|
+
* through -- so a sink covers every emit site without one of them being touched. The
|
|
174
|
+
* registry is the dependency inversion: this rank-1 module imports no sink.
|
|
175
|
+
*
|
|
176
|
+
* Each sink is isolated. Logging must never break the operation it describes, nor
|
|
177
|
+
* prevent a later sink from running.
|
|
178
|
+
*/
|
|
179
|
+
function tee(ev) {
|
|
180
|
+
const sinks = [...SINKS.values()].map((held) => held.fn);
|
|
181
|
+
for (const sink of sinks) {
|
|
182
|
+
try {
|
|
183
|
+
sink(ev);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// one broken sink must not block anything
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function info(emit, message, options = {}) {
|
|
191
|
+
const ev = event(message, {
|
|
192
|
+
phase: options.phase ?? 'info',
|
|
193
|
+
pct: options.pct ?? null,
|
|
194
|
+
data: options.data ?? {},
|
|
195
|
+
});
|
|
196
|
+
tee(ev);
|
|
197
|
+
emit(ev);
|
|
198
|
+
}
|
|
199
|
+
function warn(emit, message, options = {}) {
|
|
200
|
+
const ev = event(message, {
|
|
201
|
+
phase: options.phase ?? 'info',
|
|
202
|
+
level: 'warn',
|
|
203
|
+
data: options.data ?? {},
|
|
204
|
+
code: options.code ?? 'WARNING',
|
|
205
|
+
});
|
|
206
|
+
tee(ev);
|
|
207
|
+
emit(ev);
|
|
208
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonFloat = exports.STRIP_CHARS = void 0;
|
|
4
|
+
exports.floatString = floatString;
|
|
5
|
+
exports.stripText = stripText;
|
|
6
|
+
/**
|
|
7
|
+
* The text of a float, which is not `String(number)`.
|
|
8
|
+
*
|
|
9
|
+
* It is the shortest decimal that round-trips, switches to an exponent outside
|
|
10
|
+
* `[-4, 16)`, always keeps a decimal point (`2.0` is `'2.0'`) and pads the exponent to two
|
|
11
|
+
* digits (`1e-5` is `'1e-05'`). JavaScript's `String` switches at different
|
|
12
|
+
* bounds and drops the `.0`, so a settings dump holding a float would print differently
|
|
13
|
+
* from the import plan earlier releases printed.
|
|
14
|
+
*
|
|
15
|
+
* The shortest digits come from `toExponential()` with no argument, which is the
|
|
16
|
+
* shortest form that round-trips.
|
|
17
|
+
*
|
|
18
|
+
* NOT REPRODUCIBLE ACROSS THE WIRE: a JSON `2.0` and a JSON `2` both arrive as the number
|
|
19
|
+
* 2, so which of `'2.0'` and `'2'` the document meant cannot be recovered here. Every JSON
|
|
20
|
+
* parser on this side loses it, and the consequence is confined to the display string --
|
|
21
|
+
* the APPLIED value is the same number either way.
|
|
22
|
+
*
|
|
23
|
+
* This module is a rank-0 leaf rather than a section of `format.ts`, because a module at
|
|
24
|
+
* `format`'s own rank needs it: `redact.ts` builds its URL pattern from `STRIP_CHARS`,
|
|
25
|
+
* and two modules of rank 1 may not import each other. One implementation at
|
|
26
|
+
* the bottom, re-exported upward.
|
|
27
|
+
*/
|
|
28
|
+
function floatString(value) {
|
|
29
|
+
if (Number.isNaN(value))
|
|
30
|
+
return 'nan';
|
|
31
|
+
if (!Number.isFinite(value))
|
|
32
|
+
return value > 0 ? 'inf' : '-inf';
|
|
33
|
+
if (value === 0)
|
|
34
|
+
return Object.is(value, -0) ? '-0.0' : '0.0';
|
|
35
|
+
const [mantissa = '', expText = '0'] = value.toExponential().split('e');
|
|
36
|
+
const exponent = Number(expText);
|
|
37
|
+
const negative = mantissa.startsWith('-');
|
|
38
|
+
const digits = negative ? mantissa.slice(1).replace('.', '') : mantissa.replace('.', '');
|
|
39
|
+
const sign = negative ? '-' : '';
|
|
40
|
+
if (exponent < -4 || exponent >= 16) {
|
|
41
|
+
const head = digits.length > 1 ? `${digits[0]}.${digits.slice(1)}` : digits;
|
|
42
|
+
const marker = exponent < 0 ? '-' : '+';
|
|
43
|
+
return `${sign}${head}e${marker}${String(Math.abs(exponent)).padStart(2, '0')}`;
|
|
44
|
+
}
|
|
45
|
+
if (exponent >= 0) {
|
|
46
|
+
const pointAt = exponent + 1;
|
|
47
|
+
const body = digits.length > pointAt
|
|
48
|
+
? `${digits.slice(0, pointAt)}.${digits.slice(pointAt)}`
|
|
49
|
+
: `${digits.padEnd(pointAt, '0')}.0`;
|
|
50
|
+
return sign + body;
|
|
51
|
+
}
|
|
52
|
+
return `${sign}0.${'0'.repeat(-exponent - 1)}${digits}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Every character `stripText` removes, which is not the set JavaScript's `trim()` removes.
|
|
56
|
+
*
|
|
57
|
+
* The two disagree in both directions: this set holds the four information separators
|
|
58
|
+
* and NEL (`\x1c`-`\x1f`, `\x85`) and JavaScript's does not, while JavaScript strips the
|
|
59
|
+
* BOM (`\ufeff`) and this set does not. `String.prototype.trim` is therefore not `stripText`,
|
|
60
|
+
* and `scaleResult` was the first place that mattered. This is the one implementation.
|
|
61
|
+
*
|
|
62
|
+
* It is also exactly the `\s` of the established patterns, measured over every code point
|
|
63
|
+
* (`redact.test.ts` holds that measurement), so a pattern that must match as they did
|
|
64
|
+
* spells its `\s` from this set rather than from JavaScript's `\s`, which differs from it
|
|
65
|
+
* the same two ways `trim()` does.
|
|
66
|
+
*/
|
|
67
|
+
exports.STRIP_CHARS = new Set([
|
|
68
|
+
'\t',
|
|
69
|
+
'\n',
|
|
70
|
+
'\v',
|
|
71
|
+
'\f',
|
|
72
|
+
'\r',
|
|
73
|
+
' ',
|
|
74
|
+
'\u001c',
|
|
75
|
+
'\u001d',
|
|
76
|
+
'\u001e',
|
|
77
|
+
'\u001f',
|
|
78
|
+
'\u0085',
|
|
79
|
+
'\u00a0',
|
|
80
|
+
'\u1680',
|
|
81
|
+
'\u2000',
|
|
82
|
+
'\u2001',
|
|
83
|
+
'\u2002',
|
|
84
|
+
'\u2003',
|
|
85
|
+
'\u2004',
|
|
86
|
+
'\u2005',
|
|
87
|
+
'\u2006',
|
|
88
|
+
'\u2007',
|
|
89
|
+
'\u2008',
|
|
90
|
+
'\u2009',
|
|
91
|
+
'\u200a',
|
|
92
|
+
'\u2028',
|
|
93
|
+
'\u2029',
|
|
94
|
+
'\u202f',
|
|
95
|
+
'\u205f',
|
|
96
|
+
'\u3000',
|
|
97
|
+
]);
|
|
98
|
+
/** `text` with every `STRIP_CHARS` character stripped from both ends. */
|
|
99
|
+
function stripText(text) {
|
|
100
|
+
let start = 0;
|
|
101
|
+
let end = text.length;
|
|
102
|
+
while (start < end && exports.STRIP_CHARS.has(text[start]))
|
|
103
|
+
start += 1;
|
|
104
|
+
while (end > start && exports.STRIP_CHARS.has(text[end - 1]))
|
|
105
|
+
end -= 1;
|
|
106
|
+
return text.slice(start, end);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A number that is a FLOAT, so a writer keeps its `.0`.
|
|
110
|
+
*
|
|
111
|
+
* The JSON and the YAML writer both spell the float `1.0` as `1.0`, and JavaScript has one
|
|
112
|
+
* number type where that distinction is already gone by the time a value arrives. A caller
|
|
113
|
+
* that knows the value is a float wraps it here rather than guessing from the value: the
|
|
114
|
+
* backup manifest knows `dump_seconds` is a float, and config.yaml's reader knows which
|
|
115
|
+
* scalars the YAML 1.1 float resolver built.
|
|
116
|
+
*
|
|
117
|
+
* It sits at rank 0, below both of its writers -- `json-text` and `yaml-dump` -- and the
|
|
118
|
+
* reader that makes one for YAML (`config`), which could not reach it where it was, in
|
|
119
|
+
* `json-text` at rank 3. `json-text` re-exports it.
|
|
120
|
+
*/
|
|
121
|
+
class JsonFloat {
|
|
122
|
+
constructor(value) {
|
|
123
|
+
this.value = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.JsonFloat = JsonFloat;
|