@rocket.chat/houston 0.27.0-next.3 → 2.1.9

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.
Files changed (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,672 @@
1
+ "use strict";
2
+ /**
3
+ * Build a docker-compose document for one repro.
4
+ *
5
+ * Built as a plain object (then dumped to YAML) rather than a fixed template, so presets can
6
+ * deep-merge extra services / env / RC patches into it.
7
+ *
8
+ * **THIS MODULE IS PURE, and it sits below the service layer on purpose.** `docker compose
9
+ * config` is an external check this code does not control: this module's document for
10
+ * every preset x version x bind x instances combination was normalised under it and found
11
+ * to be the same document as the one earlier releases generated.
12
+ *
13
+ * **Emission is the established safe dump's.** A YAML 1.2 emitter, measured, writes
14
+ * `ALLOW_EMPTY_PASSWORD: yes` bare, which is CORRECT 1.2 -- and compose reads YAML 1.1,
15
+ * where bare `yes` is a boolean, and rejects the value. The document is written by the
16
+ * emitter in `yaml-dump.ts`, whose YAML 1.1 resolver quotes it, and READ back with the
17
+ * established grammar (`record.ts`'s `readCompose`), since that emitter's output is what
18
+ * every workspace earlier releases made holds.
19
+ */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || (function () {
37
+ var ownKeys = function(o) {
38
+ ownKeys = Object.getOwnPropertyNames || function (o) {
39
+ var ar = [];
40
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
+ return ar;
42
+ };
43
+ return ownKeys(o);
44
+ };
45
+ return function (mod) {
46
+ if (mod && mod.__esModule) return mod;
47
+ var result = {};
48
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
49
+ __setModuleDefault(result, mod);
50
+ return result;
51
+ };
52
+ })();
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.HEADER = exports.LICENSE_ENV_FILE = void 0;
55
+ exports.spec = spec;
56
+ exports.rcServiceNames = rcServiceNames;
57
+ exports.splitImage = splitImage;
58
+ exports.imageRef = imageRef;
59
+ exports.forEngine = forEngine;
60
+ exports.isAmd64Only = isAmd64Only;
61
+ exports.build = build;
62
+ exports.bindPorts = bindPorts;
63
+ exports.toYaml = toYaml;
64
+ const config_1 = require("./config");
65
+ const errors_1 = require("./errors");
66
+ const monitoring = __importStar(require("./monitoring"));
67
+ const format_1 = require("./format");
68
+ const yaml_dump_1 = require("./yaml-dump");
69
+ /** A `Spec` with the established defaults. */
70
+ function spec(fields) {
71
+ return {
72
+ rcImage: '',
73
+ rcTag: '',
74
+ mongoTag: '',
75
+ mongoFlavor: '',
76
+ mongoShell: '',
77
+ oplog: false,
78
+ rootUrl: '',
79
+ publicUrl: '',
80
+ hostPort: 0,
81
+ regToken: null,
82
+ licensed: false,
83
+ monitoring: false,
84
+ envOverrides: {},
85
+ containerPort: config_1.RC_CONTAINER_PORT,
86
+ bindHost: config_1.DEFAULT_BIND_HOST,
87
+ adminPassword: '',
88
+ ...fields,
89
+ };
90
+ }
91
+ /**
92
+ * The rocketchat service name(s) in the compose doc: one 'rocketchat', or
93
+ * 'rocketchat-1..N' for a multi-instance repro. Used for Prometheus targets.
94
+ */
95
+ function rcServiceNames(instances) {
96
+ const n = Math.max(1, instances || 1);
97
+ if (n === 1)
98
+ return ['rocketchat'];
99
+ return Array.from({ length: n }, (_v, i) => `rocketchat-${i + 1}`);
100
+ }
101
+ function isPlainObject(value) {
102
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
103
+ }
104
+ /** Recursively merge `patch` into `base` (patch wins), returning `base`. */
105
+ function deepMerge(base, patch) {
106
+ for (const [key, value] of Object.entries(patch)) {
107
+ const existing = base[key];
108
+ if (isPlainObject(value) && isPlainObject(existing)) {
109
+ deepMerge(existing, value);
110
+ }
111
+ else {
112
+ base[key] = value;
113
+ }
114
+ }
115
+ return base;
116
+ }
117
+ /** A deep copy, matching `copy.deepcopy` for the JSON-shaped values used here. */
118
+ function clone(value) {
119
+ return structuredClone(value);
120
+ }
121
+ function rcEnvironment(s) {
122
+ const env = {
123
+ ROOT_URL: s.rootUrl,
124
+ PORT: String(s.containerPort),
125
+ DEPLOY_METHOD: 'docker',
126
+ DEPLOY_PLATFORM: 'compose',
127
+ MONGO_URL: config_1.MONGO_URL,
128
+ ALLOW_UNSAFE_QUERY_AND_FIELDS_API_PARAMS: 'false',
129
+ // Every repro should be usable out of the box: skip the setup wizard (houston also
130
+ // finalizes it over the API on `ready`) and auto-provision the first admin. Presets
131
+ // only add their scenario-specific settings.
132
+ OVERWRITE_SETTING_Show_Setup_Wizard: 'completed',
133
+ // NO `INITIAL_USER`, and its absence is measured rather than assumed. It used to be
134
+ // here as "yes", and Rocket.Chat parses this one as JSON: every boot of every
135
+ // workspace logged `Error processing environment variable INITIAL_USER SyntaxError:
136
+ // Unexpected token 'y', "yes" is not valid JSON`, on both runtimes, forever -- noise
137
+ // in exactly the artefact a support engineer reads to find the customer's real
138
+ // problem. `true` is what RC's docs use and it is WORSE: RC parses it, finds no
139
+ // `_id`, and logs `No _id provided; Ignoring environment variable INITIAL_USER`.
140
+ // Removing it entirely is what works, because the admin never came from it --
141
+ // ADMIN_USERNAME/ADMIN_PASS/ADMIN_EMAIL below do that.
142
+ ADMIN_USERNAME: config_1.ADMIN_USERNAME,
143
+ ADMIN_NAME: config_1.ADMIN_NAME,
144
+ ADMIN_EMAIL: config_1.ADMIN_EMAIL,
145
+ ADMIN_PASS: s.adminPassword || config_1.ADMIN_PASSWORD,
146
+ };
147
+ if (s.oplog) {
148
+ // RC < 8 only; deprecated in 8.x.
149
+ env.MONGO_OPLOG_URL = config_1.MONGO_OPLOG_URL;
150
+ }
151
+ if (s.regToken)
152
+ env.REG_TOKEN = s.regToken;
153
+ // Preset env (OVERWRITE_SETTING_* etc.) wins over base defaults. The displayed form of
154
+ // the value the preset's YAML holds: `String` wrote `true`, `null`, `Infinity`, `1,2`, `[object
155
+ // Object]` and a date in the box's time zone where the established values are `True`,
156
+ // `None`, `inf`, `[1, 2]`, `{'a': 1}` and `2026-01-01`.
157
+ for (const [k, v] of Object.entries(s.preset.env))
158
+ env[k] = (0, format_1.toTextYaml)(v, config_1.yamlDateText);
159
+ // Explicit user overrides win over everything, including the base keys: this is a
160
+ // reproduction tool, so pointing MONGO_URL or ROOT_URL somewhere odd is a legitimate
161
+ // thing to want. A null value means "remove this key entirely", which is how you unset
162
+ // a base or preset default rather than merely blanking it.
163
+ for (const [k, v] of Object.entries(s.envOverrides)) {
164
+ if (v === null)
165
+ delete env[k];
166
+ else
167
+ env[k] = String(v);
168
+ }
169
+ return env;
170
+ }
171
+ /**
172
+ * mongod asks for 64000 open files and warns on every boot that 1024 is too low. Docker's
173
+ * default soft limit IS 1024, and normal Rocket.Chat traffic survives it -- but building
174
+ * many collections and indexes at once does not: a `houston restore` hit EMFILE inside
175
+ * WiredTiger, which panics and aborts the whole mongod rather than failing the one
176
+ * operation. The container's hard limit is far higher, so raising the soft limit costs
177
+ * nothing.
178
+ */
179
+ const MONGO_ULIMITS = { nofile: { soft: 64000, hard: 64000 } };
180
+ function mongoServiceBitnami(s) {
181
+ // Bitnami auto-initiates the replica set via REPLICA_SET_MODE=primary, so no separate
182
+ // init container is needed.
183
+ return {
184
+ mongodb: {
185
+ image: `docker.io/bitnamilegacy/mongodb:${s.mongoTag}`,
186
+ restart: 'always',
187
+ ulimits: clone(MONGO_ULIMITS),
188
+ // Bitnami MongoDB images are published for amd64 only; pin the platform so they
189
+ // run (under emulation) on Apple Silicon too.
190
+ platform: 'linux/amd64',
191
+ volumes: ['mongodb_data:/bitnami/mongodb'],
192
+ environment: {
193
+ MONGODB_REPLICA_SET_MODE: 'primary',
194
+ MONGODB_REPLICA_SET_NAME: 'rs0',
195
+ MONGODB_PORT_NUMBER: '27017',
196
+ MONGODB_INITIAL_PRIMARY_HOST: 'mongodb',
197
+ MONGODB_INITIAL_PRIMARY_PORT_NUMBER: '27017',
198
+ MONGODB_ADVERTISED_HOSTNAME: 'mongodb',
199
+ MONGODB_ENABLE_JOURNAL: 'true',
200
+ ALLOW_EMPTY_PASSWORD: 'yes',
201
+ },
202
+ },
203
+ };
204
+ }
205
+ function mongoServiceOfficial(s) {
206
+ // Mirrors the official RocketChat/rocketchat-compose: MongoDB Inc's community-server
207
+ // image (runs as uid 1001), so a fix-permission container chowns the data dir first,
208
+ // then a one-shot container initiates the replica set. `directConnection=true` lets
209
+ // mongosh reach the node before rs.initiate.
210
+ const image = `docker.io/mongodb/mongodb-community-server:${s.mongoTag}-ubi8`;
211
+ const sh = s.mongoShell; // mongosh for Mongo >= 5
212
+ const uri = 'mongodb://mongodb:27017/?directConnection=true';
213
+ // RETRIED, a minute at most. mongod checks that `mongodb` resolves to itself, and one
214
+ // failed lookup made this single shot exit 1 and the whole `up` fail -- on rootless Podman
215
+ // its DNS misses for a moment whenever a neighbouring workspace's network comes or goes
216
+ // (measured: 3 in 38,302 lookups during a neighbour's up and down, `NodeNotFound` at
217
+ // `replSetInitiate`). `var`, which every shell this image may carry parses.
218
+ const initiate = 'for (var i = 1; ; i++) { try { rs.status(); break } catch (e) { ' +
219
+ "try { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongodb:27017' }] }); " +
220
+ 'break } catch (f) { if (i >= 30) throw f; sleep(2000) } } }';
221
+ return {
222
+ 'mongodb-fix-permission': {
223
+ image,
224
+ user: '0',
225
+ restart: 'on-failure',
226
+ volumes: ['mongodb_data:/data/db:rw'],
227
+ entrypoint: ['sh', '-c', 'chown -R 1001 /data/db'],
228
+ },
229
+ mongodb: {
230
+ image,
231
+ user: '1001',
232
+ restart: 'always',
233
+ ulimits: clone(MONGO_ULIMITS),
234
+ depends_on: { 'mongodb-fix-permission': { condition: 'service_completed_successfully' } },
235
+ volumes: ['mongodb_data:/data/db:rw'],
236
+ entrypoint: ['mongod', '--replSet', 'rs0', '--bind_ip_all'],
237
+ environment: { ALLOW_EMPTY_PASSWORD: 'yes' },
238
+ healthcheck: {
239
+ test: ['CMD', sh, uri, '--eval', "db.adminCommand('ping')"],
240
+ interval: '10s',
241
+ timeout: '10s',
242
+ retries: 30,
243
+ start_period: '20s',
244
+ },
245
+ },
246
+ // THE CONNECTION RETRIED TOO, not only the initiate: the shell connects before `--eval`
247
+ // runs, so a lookup of `mongodb` that missed at that moment ended this one shot -- a
248
+ // fresh `up` under Podman's DNS churn lost one boot in fifteen, and every `restart`
249
+ // re-runs it. The address and the script travel as environment so the shell quotes
250
+ // nothing; `$$` is compose's escape for a `$` the shell is to read.
251
+ 'mongo-init': {
252
+ image,
253
+ restart: 'no',
254
+ depends_on: { mongodb: { condition: 'service_healthy' } },
255
+ entrypoint: [
256
+ 'sh',
257
+ '-c',
258
+ `for i in 1 2 3 4 5 6 7 8 9 10; do ${sh} "$$MONGO_URI" --eval "$$RS_INIT" && exit 0; ` +
259
+ 'sleep 2; done; exit 1',
260
+ ],
261
+ environment: { MONGO_URI: uri, RS_INIT: initiate },
262
+ },
263
+ };
264
+ }
265
+ /**
266
+ * Healthcheck for a Rocket.Chat instance. Uses `node` (always in the RC image) to hit
267
+ * /api/info, so we do not depend on curl/wget being present.
268
+ */
269
+ const RC_HEALTHCHECK = {
270
+ test: [
271
+ 'CMD',
272
+ 'node',
273
+ '-e',
274
+ "require('http').get('http://localhost:3000/api/info'," +
275
+ "r=>process.exit(r.statusCode===200?0:1)).on('error',()=>process.exit(1))",
276
+ ],
277
+ interval: '10s',
278
+ timeout: '5s',
279
+ retries: 30,
280
+ start_period: '60s',
281
+ };
282
+ /** Normalise a depends_on (plain list or condition-map) to a condition-map. */
283
+ function asConditionMap(deps) {
284
+ if (isPlainObject(deps))
285
+ return { ...deps };
286
+ const out = {};
287
+ for (const d of Array.isArray(deps) ? deps : [])
288
+ out[String(d)] = { condition: 'service_started' };
289
+ return out;
290
+ }
291
+ /**
292
+ * Clone the rocketchat service into N instances (rocketchat-1..N).
293
+ *
294
+ * Instances coordinate over NATS (the moleculer transporter), matching the official
295
+ * RocketChat/rocketchat-compose. INSTANCE_IP is intentionally left unset -- the legacy
296
+ * DDP-mesh address is not used once NATS is the transporter.
297
+ *
298
+ * The load balancer owns the workspace port (hostPort); each instance is ALSO published
299
+ * directly on hostPort+i so you can open a specific instance in the browser (e.g. to
300
+ * post on one and watch it arrive on another). Traefik reaches them over the compose
301
+ * network by service name regardless.
302
+ *
303
+ * Cold start is serialised: only rocketchat-1 boots against the empty database (running
304
+ * migrations and seeding settings); rocketchat-2..N wait for it to be healthy first, so
305
+ * they never race it to insert the same records -- which on a fresh DB otherwise crashes
306
+ * an instance with E11000 duplicate-key errors.
307
+ */
308
+ function instanceServices(base, n, hostPort, containerPort) {
309
+ const out = {};
310
+ for (let i = 1; i <= n; i += 1) {
311
+ const inst = clone(base);
312
+ inst.ports = [`${hostPort + i}:${containerPort}`]; // direct access
313
+ inst.environment.TRANSPORTER = 'monolith+nats://nats:4222';
314
+ inst.healthcheck = clone(RC_HEALTHCHECK);
315
+ if (i > 1) {
316
+ const deps = asConditionMap(inst.depends_on);
317
+ deps['rocketchat-1'] = { condition: 'service_healthy' };
318
+ inst.depends_on = deps;
319
+ }
320
+ out[`rocketchat-${i}`] = inst;
321
+ }
322
+ return out;
323
+ }
324
+ /** Add each name in `extra` to a service's depends_on (list or condition-dict). */
325
+ function addDepends(svc, extra) {
326
+ const deps = svc.depends_on;
327
+ for (const dep of extra) {
328
+ if (Array.isArray(deps)) {
329
+ if (!deps.includes(dep))
330
+ deps.push(dep);
331
+ }
332
+ else if (isPlainObject(deps)) {
333
+ if (!(dep in deps))
334
+ deps[dep] = { condition: 'service_started' };
335
+ }
336
+ }
337
+ }
338
+ /** The Prometheus/Grafana add-on, wired to every Rocket.Chat instance. */
339
+ function attachMonitoring(doc, rcServices, s) {
340
+ if (!s.monitoring)
341
+ return;
342
+ deepMerge(doc.services, monitoring.services(s.publicUrl, s.monitorPorts)); // bare ports; bound below
343
+ Object.assign(doc.volumes, monitoring.volumes());
344
+ for (const svc of Object.values(rcServices)) {
345
+ svc.environment[monitoring.RC_METRICS_ENV] = 'true';
346
+ }
347
+ }
348
+ /** Give the published host port to the preset's front end, and to nothing else. */
349
+ function publishThroughEntryService(doc, rcServices, s) {
350
+ // A preset can hand the published host port to a front-end service (a load balancer)
351
+ // instead of rocketchat -- the port is not known until `up`, so it is injected here
352
+ // rather than in the preset.
353
+ const entry = s.preset.entryService;
354
+ if (!entry)
355
+ return;
356
+ if (!(entry in doc.services)) {
357
+ // Silently skipping meant NOTHING published the host port: the repro booted and was
358
+ // unreachable at its own advertised rootUrl.
359
+ throw new Error(`preset ${JSON.stringify(s.preset.name)} sets entry_service ${JSON.stringify(entry)}, ` +
360
+ `which is not one of its services (${Object.keys(doc.services).sort().join(', ')})`);
361
+ }
362
+ doc.services[entry].ports = [`${s.hostPort}:80`];
363
+ // The front-end owns the published port now. Leaving the same host port on the RC
364
+ // service too binds it twice and `up` fails with "port is already allocated" -- which
365
+ // a single-instance preset setting entry_service would hit every time. Drop only the
366
+ // colliding mapping, so multi-instance keeps its direct per-instance ports on
367
+ // hostPort+i.
368
+ for (const [svcName, svc] of Object.entries(rcServices)) {
369
+ if (svcName === entry)
370
+ continue;
371
+ const ports = Array.isArray(svc.ports) ? svc.ports : [];
372
+ const kept = ports.filter((p) => String(p).split(':')[0] !== String(s.hostPort));
373
+ if (kept.length > 0)
374
+ svc.ports = kept;
375
+ else
376
+ delete svc.ports;
377
+ }
378
+ }
379
+ /**
380
+ * `[repository, tag]` for the chart, which wants them separately, and `imageRef`.
381
+ *
382
+ * `versions.resolve` returns the REPOSITORY only -- compose composes it as
383
+ * `${image}:${tag}` -- so a naive split on the last ':' of a tagless string returns the
384
+ * whole repository as the tag. That is truthy, so an `|| rcVersion` fallback does not save
385
+ * it, and the chart fed it to `semverCompare`, which failed the install with "invalid
386
+ * semantic version" rather than anything naming the image.
387
+ *
388
+ * A colon only introduces a tag when nothing after it looks like a path segment:
389
+ * `registry:5000/org/img` is a host with a port, not a tag.
390
+ */
391
+ function splitImage(rcImage, rcVersion) {
392
+ const at = rcImage.lastIndexOf(':');
393
+ if (at >= 0) {
394
+ const tail = rcImage.slice(at + 1);
395
+ if (!tail.includes('/'))
396
+ return [rcImage.slice(0, at), tail];
397
+ }
398
+ return [rcImage, rcVersion];
399
+ }
400
+ /**
401
+ * The image reference to run: the image as given when it already names a tag (a CI build,
402
+ * `--rc-image repo:tag`), else `<image>:<version>`. Appending unconditionally rendered
403
+ * `repo:tag:8.5.1`, which no registry can resolve.
404
+ */
405
+ function imageRef(rcImage, rcVersion) {
406
+ const [repo, tag] = splitImage(rcImage, rcVersion);
407
+ return `${repo}:${tag}`;
408
+ }
409
+ const DOCKER_SOCKET = '/var/run/docker.sock';
410
+ const DOCKER_CONTAINERS = '/var/lib/docker/containers';
411
+ /**
412
+ * The document as the engine it will run on needs it. Docker's is returned as it is, the
413
+ * same object, so its bytes cannot move. On Podman (measured rootless, 4.9.3 and 6.1.3):
414
+ * - logs to files (`k8s-file`), where its default is journald, which leaves nothing for the
415
+ * log collector to tail; the collector already reads that CRI line format;
416
+ * - the Docker paths a service mounts become Podman's own: its socket for the API, and its
417
+ * container store for the logs (`/var/lib/docker` does not exist; creating it is refused);
418
+ * - `label=disable`, so a host with SELinux lets the containers read the files houston
419
+ * mounts (harmless where there is none).
420
+ */
421
+ function forEngine(doc, engine) {
422
+ if (engine === null || engine.kind !== 'podman')
423
+ return doc;
424
+ const out = clone(doc);
425
+ for (const service of Object.values(out.services)) {
426
+ service.logging = { driver: 'k8s-file' };
427
+ const options = Array.isArray(service.security_opt) ? service.security_opt.map(String) : [];
428
+ // Idempotent: a document re-applied (monitoring attached later) is not doubled.
429
+ if (!options.includes('label=disable'))
430
+ service.security_opt = [...options, 'label=disable'];
431
+ if (!Array.isArray(service.volumes))
432
+ continue;
433
+ service.volumes = service.volumes.map((volume) => {
434
+ const text = String(volume);
435
+ if (text.startsWith(`${DOCKER_SOCKET}:`))
436
+ return `${engine.socket}${text.slice(DOCKER_SOCKET.length)}`;
437
+ if (text.startsWith(`${DOCKER_CONTAINERS}:`)) {
438
+ return `${engine.rootDir}/overlay-containers${text.slice(DOCKER_CONTAINERS.length)}`;
439
+ }
440
+ return volume;
441
+ });
442
+ }
443
+ return out;
444
+ }
445
+ /** The workspace file holding `ROCKETCHAT_LICENSE`, 0600, beside the compose document. */
446
+ exports.LICENSE_ENV_FILE = '.license.env';
447
+ /** A FIPS build is published for amd64 only (measured on ghcr, 2026-10-08). */
448
+ function isAmd64Only(rcImage) {
449
+ return /-fips(-gha-run-[0-9]+)?$/u.test(splitImage(rcImage, '')[1]);
450
+ }
451
+ /** The Rocket.Chat service, or N clones of it behind a load balancer. */
452
+ function rocketchatServices(n, official, s) {
453
+ const rocketchat = {
454
+ image: imageRef(s.rcImage, s.rcTag),
455
+ ...(isAmd64Only(s.rcImage) ? { platform: 'linux/amd64' } : {}),
456
+ restart: 'always',
457
+ environment: rcEnvironment(s),
458
+ // The licence from a file of its own, never in `environment`: this document is printed
459
+ // by `env`, read by the GUI and kept in the workspace for anyone to open.
460
+ ...(s.licensed ? { env_file: [exports.LICENSE_ENV_FILE] } : {}),
461
+ ports: [`${s.hostPort}:${s.containerPort}`],
462
+ // The same probe the cloned instances have always had. Without it Docker reports no
463
+ // health for this service, and `detail()` then falls back to the container STATE --
464
+ // which is "running" from the moment the process starts, minutes before Rocket.Chat
465
+ // serves anything. The panel said "Health: running" on a workspace whose /api/info
466
+ // was refusing the connection outright, which is the one question that field exists
467
+ // to answer.
468
+ //
469
+ // Informational only: nothing declares depends_on service_healthy against the
470
+ // single-instance service, so this changes what is REPORTED and not what anything
471
+ // waits for.
472
+ healthcheck: clone(RC_HEALTHCHECK),
473
+ depends_on: official
474
+ ? { 'mongo-init': { condition: 'service_completed_successfully' } }
475
+ : ['mongodb'],
476
+ };
477
+ // Single instance (the default): one `rocketchat` service, unchanged. Many instances:
478
+ // clone it into rocketchat-1..N behind a load balancer.
479
+ return n === 1 ? { rocketchat } : instanceServices(rocketchat, n, s.hostPort, s.containerPort);
480
+ }
481
+ /** Return the compose document for `spec`. */
482
+ function build(s) {
483
+ const official = s.mongoFlavor === 'official';
484
+ const n = Math.max(1, s.preset.instances || 1);
485
+ const rcServices = rocketchatServices(n, official, s);
486
+ const services = { ...rcServices };
487
+ Object.assign(services, official ? mongoServiceOfficial(s) : mongoServiceBitnami(s));
488
+ const doc = {
489
+ name: s.projectName,
490
+ services,
491
+ volumes: { mongodb_data: { driver: 'local' } },
492
+ };
493
+ // --- apply the preset's backing services / volumes / RC patch / depends_on ---
494
+ if (Object.keys(s.preset.services).length > 0) {
495
+ deepMerge(doc.services, clone(s.preset.services));
496
+ }
497
+ if (Object.keys(s.preset.volumes).length > 0) {
498
+ Object.assign(doc.volumes, clone(s.preset.volumes));
499
+ }
500
+ // The RC patch and extra depends_on apply to EVERY rocketchat instance.
501
+ for (const svc of Object.values(rcServices)) {
502
+ if (Object.keys(s.preset.rocketchat).length > 0)
503
+ deepMerge(svc, clone(s.preset.rocketchat));
504
+ addDepends(svc, s.preset.dependsOn);
505
+ }
506
+ publishThroughEntryService(doc, rcServices, s);
507
+ // --- HTTPS ---
508
+ // Nothing here. A workspace never terminates TLS: the edge does, for all of them, and
509
+ // it reaches this one over the private network compose already made.
510
+ //
511
+ // So this document is IDENTICAL whether the workspace serves https or not, which is
512
+ // the property the whole design rests on -- adding or removing a name is a route file
513
+ // appearing or disappearing, and no container is ever rebuilt to gain or lose TLS.
514
+ //
515
+ // RC keeps its published http port. houston's own API calls use it, so nothing
516
+ // internal has to trust the local CA, and `curl http://localhost:<port>` still works.
517
+ attachMonitoring(doc, rcServices, s);
518
+ bindPorts(doc, s.bindHost);
519
+ return doc;
520
+ }
521
+ /** "8000-8005:8000-8005", and the single-sided "8000-8005" form. */
522
+ const RANGE_RE = /^\d+-\d+(:\d+(-\d+)?)?$/;
523
+ /**
524
+ * Prefix every published port with the bind host, unless one is already given. Applied
525
+ * to ALL services in one pass -- RC, multi-instance direct ports, the load balancer, and
526
+ * preset sidecars -- mirroring the official rocketchat-compose
527
+ * `${BIND_IP}:${HOST_PORT}:${PORT}` pattern.
528
+ */
529
+ /** A bind on one address that is not this machine's loopback: narrower than every address. */
530
+ function narrowerBind(bind) {
531
+ const b = bind.trim().toLowerCase();
532
+ return (!['', '0.0.0.0', '::', '[::]', '*', 'localhost', '::1'].includes(b) && !b.startsWith('127.'));
533
+ }
534
+ function bindPorts(doc, bind) {
535
+ if (!bind)
536
+ return;
537
+ for (const [name, svc] of Object.entries(doc.services)) {
538
+ const ports = svc.ports;
539
+ if (!Array.isArray(ports) || ports.length === 0)
540
+ continue;
541
+ const out = [];
542
+ for (const p of ports) {
543
+ // THE TYPE CHECK COMES FIRST. Stringifying compose long syntax gives the object's
544
+ // text containing two colons, which matched the already-IP-qualified branch below
545
+ // -- the object's text was appended as a ports entry. Any shape that is not a
546
+ // string has to be recognised before it is stringified.
547
+ if (isPlainObject(p)) {
548
+ const long = { ...p };
549
+ if ('published' in long && (long.host_ip ?? '') === '')
550
+ long.host_ip = bind;
551
+ out.push(long);
552
+ continue;
553
+ }
554
+ const str = String(p);
555
+ // The shape is read without a protocol suffix ("20000-20019/udp" is a range, "3478/udp"
556
+ // a bare port); the entry keeps it.
557
+ const shape = str.replace(/\/(tcp|udp)$/u, '');
558
+ const colons = str.split(':').length - 1;
559
+ const head = str.split(':')[0] ?? '';
560
+ if (colons >= 2) {
561
+ // Already IP-qualified ("127.0.0.1:8025:8025") -- prefixing again would produce
562
+ // a double-IP mapping. One a preset opened to every address (voice's call ports, once
563
+ // voip_domain names one) follows a bind chosen on purpose: `--bind 10.0.0.5` keeps
564
+ // them on 10.0.0.5 rather than on every interface.
565
+ out.push(str.startsWith('0.0.0.0:') && narrowerBind(bind) ? `${bind}:${str.slice(8)}` : str);
566
+ }
567
+ else if (colons === 1 && head !== '' && /^[0-9]+$/.test(head)) {
568
+ out.push(`${bind}:${str}`); // "8025:8025"
569
+ }
570
+ else if (shape !== '' && /^[0-9]+$/.test(shape)) {
571
+ // A BARE container port. "127.0.0.1:8025" would be parsed as host:container with
572
+ // an invalid host port, so use compose's IP::CONTAINER form: an ephemeral host
573
+ // port, still bound to `bind` rather than every interface.
574
+ out.push(`${bind}::${str}`);
575
+ }
576
+ else if (RANGE_RE.test(shape)) {
577
+ // A PORT RANGE ("8000-8005:8000-8005"). This fell through to the `else` below
578
+ // and was appended UNCHANGED, so it published on every interface while `info`
579
+ // and the detail panel both reported the workspace as loopback-bound: a silent
580
+ // opt-out of the default posture, on a workspace running fixed weak credentials.
581
+ // Legal Compose, and reachable through the custom presets the README documents.
582
+ // A one-sided range means CONTAINER ports with ephemeral host ports.
583
+ // Preserve that with IP::RANGE; IP:RANGE is invalid HOST:CONTAINER.
584
+ out.push(str.includes(':') ? `${bind}:${str}` : `${bind}::${str}`);
585
+ }
586
+ else {
587
+ // NOT SILENTLY PASSED THROUGH. Everything above is a shape this function
588
+ // understands; anything else is a published port it would be leaving on every
589
+ // interface, which is the one outcome that must never be the default. Named so
590
+ // the preset author can see what to change.
591
+ throw new errors_1.ValidationError(`port entry ${JSON.stringify(p)} in service ${JSON.stringify(name)} is a shape ` +
592
+ `houston cannot bind to ${bind}. Write it as "HOST:CONTAINER", a range, or ` +
593
+ 'compose long syntax with `published:` -- leaving it unbound would publish ' +
594
+ 'it on every interface.');
595
+ }
596
+ }
597
+ svc.ports = out;
598
+ }
599
+ }
600
+ exports.HEADER = '# Generated by houston. Do not edit by hand -- re-run `houston up`.\n';
601
+ const TIME = String.raw `(?:[01]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9](?:[.,][0-9]+)?`;
602
+ /**
603
+ * The plain scalars docker compose's reader types and this module's resolver does not --
604
+ * the same three patterns earlier releases register, so the two writers stay equal byte for
605
+ * byte.
606
+ *
607
+ * The safe dump writes a string PLAIN when its resolver, a YAML 1.1 one, would read the
608
+ * bare text back as a string. compose-go reads the file with yaml.v3's resolver -- YAML
609
+ * 1.2's numbers, plus the underscores, `0b` and timestamps it kept -- so the string reached
610
+ * the container as a number: `env --set E1=1e8` gave E1=1e+08, `0o17` gave 15, `-.5` gave
611
+ * -0.5, `12e03` gave 12000, `08` gave 8, `2001-1-2` gave `2001-01-02 00:00:00 +0000 UTC`,
612
+ * and `2001-1-2T3:4:5+24:00` made docker refuse the whole file. Measured with `docker compose
613
+ * -f FILE config --format json` over every string of up to four characters of
614
+ * `0-9 + - . _ : a-f E o x O X B` and the lookalikes: 8,133 of 558,352 came back other than
615
+ * they went in, every one written plain. Earlier releases' writer had the same defect. With
616
+ * these the emitter quotes such a string by its own rules, in single quotes, as it already
617
+ * quotes `'3000'` and `'yes'`.
618
+ *
619
+ * They are yaml.v3's `resolve()`: from a sign or a digit, with every `_` taken out, a Go
620
+ * integer literal or a decimal float with an optional unsigned exponent; from a `.`,
621
+ * `strconv.ParseFloat`; and the `time.Parse` layouts `2006-1-2`, with `T`/`t`, `15:4:5`, a
622
+ * fraction and `Z` or `±hh:mm`, or with spaces and the time alone. A magnitude is past
623
+ * them -- `1e999`, an integer past 64 bits in `0x`/`0o`/`0b`, 29 February of a common year
624
+ * are strings to yaml.v3 and are quoted anyway, which reads back the same. `config.yaml`,
625
+ * which only houston reads, is written without them.
626
+ */
627
+ const COMPOSE_READER_TYPES = [
628
+ [
629
+ 'tag:yaml.org,2002:int',
630
+ new RegExp(String.raw `^(?:[-+]_*)?(?:0_*[xX]_*(?:[0-9a-fA-F]_*)+|0_*[oO]_*(?:[0-7]_*)+` +
631
+ String.raw `|0_*[bB]_*(?:[01]_*)+|(?:(?:[0-9]_*)+(?:\._*(?:[0-9]_*)*)?|\._*(?:[0-9]_*)+)` +
632
+ String.raw `(?:[eE]_*(?:[-+]_*)?(?:[0-9]_*)+)?)\n?$`),
633
+ '-+0123456789',
634
+ ],
635
+ ['tag:yaml.org,2002:float', /^\.[0-9]+(?:_[0-9]+)*(?:[eE][-+]?[0-9]+(?:_[0-9]+)*)?\n?$/, '.'],
636
+ [
637
+ 'tag:yaml.org,2002:timestamp',
638
+ new RegExp(String.raw `^[0-9]{4}-(?:(?:0?[13578]|1[02])-(?:0?[1-9]|[12][0-9]|3[01])` +
639
+ String.raw `|(?:0?[469]|11)-(?:0?[1-9]|[12][0-9]|30)|0?2-(?:0?[1-9]|[12][0-9]))` +
640
+ String.raw `(?:[Tt]${TIME}(?:Z|[-+](?:[01][0-9]|2[0-4]):(?:[0-5][0-9]|60))| +${TIME})?\n?$`),
641
+ '0123456789',
642
+ ],
643
+ ];
644
+ /**
645
+ * The compose document as YAML: the header, then the document in block style with its keys
646
+ * in their own order, through the emitter in `yaml-dump.ts`.
647
+ *
648
+ * It was the `yaml` package's emitter with `compat: 'yaml-1.1'`, and the package's choices
649
+ * are not the established ones: `PORT: "3000"` where the established file holds `'3000'`,
650
+ * the mongo init command on one 110-column line where the established file folds it at 80,
651
+ * `1e8`, `0o17`, `-.5`, `y` and `N` quoted where the established resolver leaves them
652
+ * plain, `café` raw where the established file escapes it, an empty key as `""` where the
653
+ * established file holds `? ''`, anchors `&a1`, escapes in lower case. Every generated
654
+ * document differed in its bytes from the established one, and every `env --set`,
655
+ * `monitor` or `upgrade` of a workspace an earlier release made rewrote 7 to 16 of its
656
+ * lines. The generated documents are now the established ones byte for byte, which is
657
+ * stronger than `docker compose config` agreeing on them.
658
+ *
659
+ * What the package needed patching for is this emitter's own behaviour and needs nothing
660
+ * more: `yes` is quoted because the resolver reads it as a bool, as it reads `=` and `<<`
661
+ * as the value and merge tags; a tab, DEL, C1, U+2028/U+2029 and U+FFFE/U+FFFF are
662
+ * double-quoted and escaped because the analyser calls them special; and a value of blank
663
+ * lines holding spaces is double-quoted because a space before a line break rules out every
664
+ * other style.
665
+ *
666
+ * Both writers quote `1e8`, `0o17` and `-.5` again since, for docker compose's reader rather
667
+ * than the package's reasons: the resolver is the safe dump's and then
668
+ * `COMPOSE_READER_TYPES`, here as in earlier releases, while `y` and `N` stay plain.
669
+ */
670
+ function toYaml(doc) {
671
+ return exports.HEADER + (0, yaml_dump_1.safeDump)(doc, { implicitResolvers: COMPOSE_READER_TYPES });
672
+ }