@valbuild/shared 0.148.7 → 0.149.7

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 (70) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/client/dist/valbuild-shared-client.cjs.dev.js +2 -1
  3. package/client/dist/valbuild-shared-client.cjs.prod.js +2 -1
  4. package/client/dist/valbuild-shared-client.esm.js +2 -1
  5. package/dist/acquireTypes-50960f2c.esm.js +1801 -0
  6. package/dist/acquireTypes-de10005d.cjs.dev.js +1815 -0
  7. package/dist/acquireTypes-e9467a2a.cjs.prod.js +1815 -0
  8. package/dist/createForOfIteratorHelper-3db5d737.esm.js +121 -0
  9. package/dist/createForOfIteratorHelper-90e6a8b6.cjs.prod.js +129 -0
  10. package/dist/createForOfIteratorHelper-d86bb352.cjs.dev.js +129 -0
  11. package/dist/declarations/src/internal/ApiRoutes.d.ts +3 -3
  12. package/dist/declarations/src/internal/index.d.ts +1 -0
  13. package/dist/declarations/src/internal/selfCheck.d.ts +51 -0
  14. package/dist/declarations/src/publish/buildProposal.d.ts +106 -0
  15. package/dist/declarations/src/publish/builder.d.ts +22 -0
  16. package/dist/declarations/src/publish/callJson.d.ts +21 -0
  17. package/dist/declarations/src/publish/index.d.ts +23 -0
  18. package/dist/declarations/src/publish/jobClient.d.ts +96 -0
  19. package/dist/declarations/src/publish/loadedLayer.d.ts +50 -0
  20. package/dist/declarations/src/publish/proposalProject.d.ts +2 -0
  21. package/dist/declarations/src/publish/publishClient.d.ts +95 -0
  22. package/dist/declarations/src/publish/runStudioDeploy.d.ts +244 -0
  23. package/dist/declarations/src/publish/runStudioJob.d.ts +102 -0
  24. package/dist/declarations/src/publish/runStudioPublish.d.ts +80 -0
  25. package/dist/declarations/src/typecheck/acquireTypes.d.ts +109 -0
  26. package/dist/declarations/src/typecheck/adeptSources.d.ts +9 -0
  27. package/dist/declarations/src/typecheck/index.d.ts +20 -0
  28. package/dist/declarations/src/typecheck/linkedFileSystem.d.ts +53 -0
  29. package/dist/declarations/src/typecheck/lockedVersions.d.ts +14 -0
  30. package/dist/declarations/src/typecheck/pnpmLayout.d.ts +95 -0
  31. package/dist/declarations/src/typecheck/pnpmLockfile.d.ts +57 -0
  32. package/dist/declarations/src/typecheck/proposalTypecheck.d.ts +76 -0
  33. package/dist/declarations/src/typecheck/testing/index.d.ts +6 -0
  34. package/dist/declarations/src/typecheck/testing/nodeModulesSources.d.ts +5 -0
  35. package/dist/declarations/src/typecheck/typecheckProject.d.ts +89 -0
  36. package/dist/declarations/src/typecheck/typescriptCompiler.d.ts +52 -0
  37. package/dist/{getSitemapTree-40d76bf8.cjs.prod.js → getSitemapTree-0fa0569c.cjs.dev.js} +5 -131
  38. package/dist/{getSitemapTree-cd006a36.esm.js → getSitemapTree-5afbc3ac.esm.js} +2 -121
  39. package/dist/{getSitemapTree-a7f2cc6d.cjs.dev.js → getSitemapTree-667bcb3c.cjs.prod.js} +5 -131
  40. package/dist/proposalProject-28550146.cjs.prod.js +18 -0
  41. package/dist/proposalProject-a3d3ad76.esm.js +16 -0
  42. package/dist/proposalProject-cdc53711.cjs.dev.js +18 -0
  43. package/dist/protocol-1c13de0d.cjs.prod.js +433 -0
  44. package/dist/protocol-3b9ef786.esm.js +413 -0
  45. package/dist/protocol-d8a6efda.cjs.dev.js +433 -0
  46. package/dist/slicedToArray-62e428df.cjs.dev.js +309 -0
  47. package/dist/slicedToArray-6cd80315.esm.js +299 -0
  48. package/dist/slicedToArray-af50e684.cjs.prod.js +309 -0
  49. package/internal/dist/valbuild-shared-internal.cjs.dev.js +419 -888
  50. package/internal/dist/valbuild-shared-internal.cjs.prod.js +419 -888
  51. package/internal/dist/valbuild-shared-internal.esm.js +236 -707
  52. package/package.json +27 -4
  53. package/publish/dist/valbuild-shared-publish.cjs.d.ts +2 -0
  54. package/publish/dist/valbuild-shared-publish.cjs.dev.js +2466 -0
  55. package/publish/dist/valbuild-shared-publish.cjs.js +7 -0
  56. package/publish/dist/valbuild-shared-publish.cjs.prod.js +2466 -0
  57. package/publish/dist/valbuild-shared-publish.esm.js +2428 -0
  58. package/publish/package.json +4 -0
  59. package/typecheck/dist/valbuild-shared-typecheck.cjs.d.ts +2 -0
  60. package/typecheck/dist/valbuild-shared-typecheck.cjs.dev.js +1173 -0
  61. package/typecheck/dist/valbuild-shared-typecheck.cjs.js +7 -0
  62. package/typecheck/dist/valbuild-shared-typecheck.cjs.prod.js +1173 -0
  63. package/typecheck/dist/valbuild-shared-typecheck.esm.js +1152 -0
  64. package/typecheck/package.json +4 -0
  65. package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.d.ts +2 -0
  66. package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.dev.js +202 -0
  67. package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.js +7 -0
  68. package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.prod.js +202 -0
  69. package/typecheck/testing/dist/valbuild-shared-typecheck-testing.esm.js +177 -0
  70. package/typecheck/testing/package.json +4 -0
@@ -0,0 +1,2428 @@
1
+ import { _ as _inherits, a as _createClass, b as _asyncToGenerator, c as _wrapNativeSuper, d as _regenerator, e as _classCallCheck, f as _callSuper, g as _slicedToArray, h as _toConsumableArray } from '../../dist/slicedToArray-6cd80315.esm.js';
2
+ import { _ as _typeof, b as _objectSpread2, c as _defineProperty, a as _createForOfIteratorHelper } from '../../dist/createForOfIteratorHelper-3db5d737.esm.js';
3
+ import { p as parseBuildTarget, a as parseDeclare, b as parseArtifacts, c as parseVerify, d as parsePromote, e as parseStatus, f as parseProjectSource, g as parseProblems, h as parsePress, i as parseRequestStatus, j as parseJob, k as parseRenew, l as parseCancel, m as parseDiscard, n as parseNewestCiRun, _ as _objectWithoutProperties } from '../../dist/protocol-3b9ef786.esm.js';
4
+ import { z } from 'zod';
5
+ export { p as proposalProject } from '../../dist/proposalProject-a3d3ad76.esm.js';
6
+ import 'zod-validation-error';
7
+
8
+ /*
9
+ * The one JSON call the Studio makes through its own origin's publish proxy,
10
+ * and the errors it throws. Apart from `publishClient.ts` (which re-exports
11
+ * all three) so that a worker can make the same call without importing the
12
+ * publish client's parsers, and `@valbuild/shared` with them.
13
+ */
14
+
15
+ /**
16
+ * Who hears of a refusal's body before it is thrown: the Studio's shell, which
17
+ * says a refusal of the project's plan with the next step (`planRefusal.ts` in
18
+ * `@valbuild/ui`). One listener; setting it again replaces it.
19
+ */
20
+ var refusalListener = null;
21
+ function onPublishRefusal(listener) {
22
+ refusalListener = listener;
23
+ }
24
+
25
+ /** The publish API refused, and said why. */
26
+ var StudioPublishError = /*#__PURE__*/function (_Error) {
27
+ function StudioPublishError(statusCode, message, body) {
28
+ var _this;
29
+ _classCallCheck(this, StudioPublishError);
30
+ _this = _callSuper(this, StudioPublishError, [message]);
31
+ _defineProperty(_this, "statusCode", void 0);
32
+ _defineProperty(_this, "body", void 0);
33
+ _this.name = "StudioPublishError";
34
+ _this.statusCode = statusCode;
35
+ _this.body = body;
36
+ return _this;
37
+ }
38
+ _inherits(StudioPublishError, _Error);
39
+ return _createClass(StudioPublishError);
40
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
41
+
42
+ /**
43
+ * Was this a failure that asking again could get past?
44
+ *
45
+ * No answer at all (the request never got through) and the answers that mean
46
+ * "not now" -- a timeout, too many requests, a server or gateway error. Every
47
+ * other status is content answering, and the same request gets the same
48
+ * answer.
49
+ */
50
+ function isTransientPublishError(error) {
51
+ if (!(error instanceof StudioPublishError)) return true;
52
+ return error.statusCode >= 500 || error.statusCode === 408 || error.statusCode === 429;
53
+ }
54
+
55
+ /**
56
+ * One JSON call through this origin, with the session cookie: its body, or a
57
+ * `StudioPublishError` carrying the answer's own message.
58
+ */
59
+ function callJson(_x, _x2, _x3, _x4) {
60
+ return _callJson.apply(this, arguments);
61
+ }
62
+ function _callJson() {
63
+ _callJson = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fetchImpl, url, method, body) {
64
+ var res, text, parsed, _refusalListener, message;
65
+ return _regenerator().w(function (_context) {
66
+ while (1) switch (_context.n) {
67
+ case 0:
68
+ _context.n = 1;
69
+ return fetchImpl(url, _objectSpread2({
70
+ method: method,
71
+ // The session cookie is the whole credential this end has.
72
+ credentials: "same-origin"
73
+ }, body === undefined ? {} : {
74
+ headers: {
75
+ "Content-Type": "application/json"
76
+ },
77
+ body: JSON.stringify(body)
78
+ }));
79
+ case 1:
80
+ res = _context.v;
81
+ _context.n = 2;
82
+ return res.text();
83
+ case 2:
84
+ text = _context.v;
85
+ try {
86
+ parsed = text === "" ? undefined : JSON.parse(text);
87
+ } catch (_unused) {
88
+ parsed = undefined;
89
+ }
90
+ if (res.ok) {
91
+ _context.n = 3;
92
+ break;
93
+ }
94
+ // A publish the plan does not allow (a trial's 3 publishes, a trial that
95
+ // ended): the shell says it, with the next step. See `planRefusal`.
96
+ (_refusalListener = refusalListener) === null || _refusalListener === void 0 || _refusalListener(parsed);
97
+ message = _typeof(parsed) === "object" && parsed !== null && "message" in parsed && typeof parsed.message === "string" ? parsed.message : "The publish API answered ".concat(res.status, ".");
98
+ throw new StudioPublishError(res.status, message, parsed);
99
+ case 3:
100
+ return _context.a(2, parsed);
101
+ }
102
+ }, _callee);
103
+ }));
104
+ return _callJson.apply(this, arguments);
105
+ }
106
+
107
+ /** An artifact the live build has and this publish re-declares by hash. */
108
+
109
+ /** See {@link StudioPublishClient.publicFiles}. */
110
+
111
+ /** Object storage refused the bytes, or could not be reached. */
112
+ var StudioUploadError = /*#__PURE__*/function (_Error) {
113
+ function StudioUploadError(statusCode, key, message) {
114
+ var _this;
115
+ _classCallCheck(this, StudioUploadError);
116
+ _this = _callSuper(this, StudioUploadError, [message]);
117
+ _defineProperty(_this, "statusCode", void 0);
118
+ _defineProperty(_this, "key", void 0);
119
+ _this.name = "StudioUploadError";
120
+ _this.statusCode = statusCode;
121
+ _this.key = key;
122
+ return _this;
123
+ }
124
+ _inherits(StudioUploadError, _Error);
125
+ return _createClass(StudioUploadError);
126
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
127
+ /**
128
+ * A slot's permission to write has run out.
129
+ *
130
+ * Its own shape because it is not a failure: the answer is to declare again for
131
+ * fresh slots, and a publish that treated it as one would give up an upload
132
+ * short of the finish.
133
+ */
134
+
135
+ /*
136
+ * One request for both halves of the answer. A client lives for one deploy,
137
+ * so this is the source as that deploy read it -- two requests could read
138
+ * two different builds' files.
139
+ */
140
+
141
+ function isExpiredSlot(error) {
142
+ return error instanceof StudioUploadError && error.statusCode === 403;
143
+ }
144
+
145
+ /**
146
+ * Where content's publish API is reached: through Val's proxy on this origin
147
+ * (`api`, the Studio), or directly (`publishApi`, `<content>/v1`: home's
148
+ * upgrade page, whose `fetchImpl` adds the project token).
149
+ */
150
+
151
+ function publishApiOf(at) {
152
+ return "publishApi" in at ? at.publishApi.replace(/\/+$/, "") : "".concat(at.api.replace(/\/+$/, ""), "/publish-api");
153
+ }
154
+ function createStudioPublishClient(options) {
155
+ var _options$fetchImpl;
156
+ var fetchImpl = (_options$fetchImpl = options.fetchImpl) !== null && _options$fetchImpl !== void 0 ? _options$fetchImpl : fetch;
157
+ var proxy = publishApiOf(options);
158
+ var call = function call(path, method, body) {
159
+ return callJson(fetchImpl, "".concat(proxy).concat(path), method, body);
160
+ };
161
+ var source = null;
162
+ var readSource = function readSource() {
163
+ return source !== null && source !== void 0 ? source : source = call("/project-source", "GET").then(parseProjectSource);
164
+ };
165
+ return {
166
+ buildTarget: function () {
167
+ var _buildTarget = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
168
+ var _t;
169
+ return _regenerator().w(function (_context) {
170
+ while (1) switch (_context.n) {
171
+ case 0:
172
+ _t = parseBuildTarget;
173
+ _context.n = 1;
174
+ return call("/build-target", "GET");
175
+ case 1:
176
+ return _context.a(2, _t(_context.v));
177
+ }
178
+ }, _callee);
179
+ }));
180
+ function buildTarget() {
181
+ return _buildTarget.apply(this, arguments);
182
+ }
183
+ return buildTarget;
184
+ }(),
185
+ projectSource: function () {
186
+ var _projectSource = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
187
+ return _regenerator().w(function (_context2) {
188
+ while (1) switch (_context2.n) {
189
+ case 0:
190
+ _context2.n = 1;
191
+ return readSource();
192
+ case 1:
193
+ return _context2.a(2, _context2.v.files);
194
+ }
195
+ }, _callee2);
196
+ }));
197
+ function projectSource() {
198
+ return _projectSource.apply(this, arguments);
199
+ }
200
+ return projectSource;
201
+ }(),
202
+ publicFiles: function () {
203
+ var _publicFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
204
+ var _yield$readSource, publicFiles, publicPaths;
205
+ return _regenerator().w(function (_context3) {
206
+ while (1) switch (_context3.n) {
207
+ case 0:
208
+ _context3.n = 1;
209
+ return readSource();
210
+ case 1:
211
+ _yield$readSource = _context3.v;
212
+ publicFiles = _yield$readSource.publicFiles;
213
+ publicPaths = _yield$readSource.publicPaths;
214
+ if (!publicFiles) {
215
+ _context3.n = 2;
216
+ break;
217
+ }
218
+ return _context3.a(2, {
219
+ carried: publicFiles
220
+ });
221
+ case 2:
222
+ if (!publicPaths) {
223
+ _context3.n = 3;
224
+ break;
225
+ }
226
+ return _context3.a(2, {
227
+ paths: publicPaths
228
+ });
229
+ case 3:
230
+ return _context3.a(2, null);
231
+ }
232
+ }, _callee3);
233
+ }));
234
+ function publicFiles() {
235
+ return _publicFiles.apply(this, arguments);
236
+ }
237
+ return publicFiles;
238
+ }(),
239
+ declare: function () {
240
+ var _declare = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(body) {
241
+ var _t2;
242
+ return _regenerator().w(function (_context4) {
243
+ while (1) switch (_context4.n) {
244
+ case 0:
245
+ _t2 = parseDeclare;
246
+ _context4.n = 1;
247
+ return call("/publish", "POST", body);
248
+ case 1:
249
+ return _context4.a(2, _t2(_context4.v));
250
+ }
251
+ }, _callee4);
252
+ }));
253
+ function declare(_x) {
254
+ return _declare.apply(this, arguments);
255
+ }
256
+ return declare;
257
+ }(),
258
+ confirmArtifacts: function () {
259
+ var _confirmArtifacts = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(publishId) {
260
+ var _t3;
261
+ return _regenerator().w(function (_context5) {
262
+ while (1) switch (_context5.n) {
263
+ case 0:
264
+ _t3 = parseArtifacts;
265
+ _context5.n = 1;
266
+ return call(publishStep(publishId, "artifacts"), "POST");
267
+ case 1:
268
+ return _context5.a(2, _t3(_context5.v));
269
+ }
270
+ }, _callee5);
271
+ }));
272
+ function confirmArtifacts(_x2) {
273
+ return _confirmArtifacts.apply(this, arguments);
274
+ }
275
+ return confirmArtifacts;
276
+ }(),
277
+ verify: function () {
278
+ var _verify = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(publishId) {
279
+ var _t4;
280
+ return _regenerator().w(function (_context6) {
281
+ while (1) switch (_context6.n) {
282
+ case 0:
283
+ _t4 = parseVerify;
284
+ _context6.n = 1;
285
+ return call(publishStep(publishId, "verify"), "POST");
286
+ case 1:
287
+ return _context6.a(2, _t4(_context6.v));
288
+ }
289
+ }, _callee6);
290
+ }));
291
+ function verify(_x3) {
292
+ return _verify.apply(this, arguments);
293
+ }
294
+ return verify;
295
+ }(),
296
+ promote: function () {
297
+ var _promote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(publishId) {
298
+ var _t5;
299
+ return _regenerator().w(function (_context7) {
300
+ while (1) switch (_context7.n) {
301
+ case 0:
302
+ _t5 = parsePromote;
303
+ _context7.n = 1;
304
+ return call(publishStep(publishId, "promote"), "POST");
305
+ case 1:
306
+ return _context7.a(2, _t5(_context7.v));
307
+ }
308
+ }, _callee7);
309
+ }));
310
+ function promote(_x4) {
311
+ return _promote.apply(this, arguments);
312
+ }
313
+ return promote;
314
+ }(),
315
+ status: function () {
316
+ var _status = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(publishId) {
317
+ var _t6;
318
+ return _regenerator().w(function (_context8) {
319
+ while (1) switch (_context8.n) {
320
+ case 0:
321
+ _t6 = parseStatus;
322
+ _context8.n = 1;
323
+ return call(publishStep(publishId), "GET");
324
+ case 1:
325
+ return _context8.a(2, _t6(_context8.v));
326
+ }
327
+ }, _callee8);
328
+ }));
329
+ function status(_x5) {
330
+ return _status.apply(this, arguments);
331
+ }
332
+ return status;
333
+ }(),
334
+ upload: function () {
335
+ var _upload = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(slot, body) {
336
+ var res, _t7;
337
+ return _regenerator().w(function (_context9) {
338
+ while (1) switch (_context9.p = _context9.n) {
339
+ case 0:
340
+ _context9.p = 0;
341
+ _context9.n = 1;
342
+ return fetchImpl(slot.url, {
343
+ method: slot.method,
344
+ headers: slot.headers,
345
+ body: body,
346
+ /*
347
+ * A presigned URL authorises itself. Sending this origin's cookies to
348
+ * a storage host would leak a session to somewhere that has no use
349
+ * for it and no reason to be trusted with it.
350
+ */
351
+ credentials: "omit"
352
+ });
353
+ case 1:
354
+ res = _context9.v;
355
+ _context9.n = 3;
356
+ break;
357
+ case 2:
358
+ _context9.p = 2;
359
+ _t7 = _context9.v;
360
+ throw new StudioUploadError(0, slot.key, "Could not reach storage for '".concat(slot.key, "': ").concat(_t7 instanceof Error ? _t7.message : String(_t7)));
361
+ case 3:
362
+ if (res.ok) {
363
+ _context9.n = 4;
364
+ break;
365
+ }
366
+ throw new StudioUploadError(res.status, slot.key, "Storage refused '".concat(slot.key, "' with ").concat(res.status, "."));
367
+ case 4:
368
+ return _context9.a(2);
369
+ }
370
+ }, _callee9, null, [[0, 2]]);
371
+ }));
372
+ function upload(_x6, _x7) {
373
+ return _upload.apply(this, arguments);
374
+ }
375
+ return upload;
376
+ }()
377
+ };
378
+ }
379
+ var publishStep = function publishStep(publishId, step) {
380
+ return "/publish/".concat(encodeURIComponent(publishId)).concat(step ? "/".concat(step) : "");
381
+ };
382
+
383
+ /** Which step the publish is on, for the one line an editor is shown. */
384
+
385
+ /**
386
+ * How many times to declare again.
387
+ *
388
+ * Declaring mints upload slots, and a slot expires. Three rounds covers an
389
+ * upload that ran past the hour and a storage write that content did not see;
390
+ * a fourth would be the same failure a third time.
391
+ */
392
+ var DECLARE_ROUNDS = 3;
393
+ function runStudioPublish(_x) {
394
+ return _runStudioPublish.apply(this, arguments);
395
+ }
396
+
397
+ /** The problems a refusal carries, or none when its body names none. */
398
+ function _runStudioPublish() {
399
+ _runStudioPublish = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(args) {
400
+ var client, artifacts, onPhase, bodyOf, publishId, confirmed, round, declared, slots, expired, _iterator, _step, _step$value, index, slot, body, confirmation, verified, promoted, _t, _t2, _t3;
401
+ return _regenerator().w(function (_context) {
402
+ while (1) switch (_context.p = _context.n) {
403
+ case 0:
404
+ client = args.client, artifacts = args.artifacts, onPhase = args.onPhase;
405
+ bodyOf = new Map(artifacts.map(function (a) {
406
+ return [a.key, a.body];
407
+ }));
408
+ publishId = null;
409
+ _context.p = 1;
410
+ confirmed = false;
411
+ round = 1;
412
+ case 2:
413
+ if (!(round <= DECLARE_ROUNDS && !confirmed)) {
414
+ _context.n = 23;
415
+ break;
416
+ }
417
+ onPhase({
418
+ kind: "declaring"
419
+ });
420
+ _context.n = 3;
421
+ return client.declare(args.declare);
422
+ case 3:
423
+ declared = _context.v;
424
+ publishId = declared.publishId;
425
+ if (!(declared.state === "live")) {
426
+ _context.n = 5;
427
+ break;
428
+ }
429
+ if (!(args.until === "confirmed")) {
430
+ _context.n = 4;
431
+ break;
432
+ }
433
+ return _context.a(2, {
434
+ status: "uploaded",
435
+ publishId: declared.publishId
436
+ });
437
+ case 4:
438
+ return _context.a(2, {
439
+ status: "already-live",
440
+ publishId: declared.publishId,
441
+ url: declared.project.siteUrl
442
+ });
443
+ case 5:
444
+ slots = declared.uploads;
445
+ expired = false;
446
+ _iterator = _createForOfIteratorHelper(slots.entries());
447
+ _context.p = 6;
448
+ _iterator.s();
449
+ case 7:
450
+ if ((_step = _iterator.n()).done) {
451
+ _context.n = 13;
452
+ break;
453
+ }
454
+ _step$value = _slicedToArray(_step.value, 2), index = _step$value[0], slot = _step$value[1];
455
+ onPhase({
456
+ kind: "uploading",
457
+ done: index,
458
+ total: slots.length
459
+ });
460
+ body = bodyOf.get(slot.key);
461
+ if (!(body === undefined)) {
462
+ _context.n = 8;
463
+ break;
464
+ }
465
+ return _context.a(2, {
466
+ status: "failed",
467
+ publishId: publishId,
468
+ message: "Content asked for an artifact this build did not produce: '".concat(slot.key, "'."),
469
+ problems: []
470
+ });
471
+ case 8:
472
+ _context.p = 8;
473
+ _context.n = 9;
474
+ return client.upload(slot, body);
475
+ case 9:
476
+ _context.n = 12;
477
+ break;
478
+ case 10:
479
+ _context.p = 10;
480
+ _t = _context.v;
481
+ if (!isExpiredSlot(_t)) {
482
+ _context.n = 11;
483
+ break;
484
+ }
485
+ // Not a failure: the hour on the slots ran out while they were
486
+ // being used. Declaring again mints fresh ones.
487
+ expired = true;
488
+ return _context.a(3, 13);
489
+ case 11:
490
+ throw _t;
491
+ case 12:
492
+ _context.n = 7;
493
+ break;
494
+ case 13:
495
+ _context.n = 15;
496
+ break;
497
+ case 14:
498
+ _context.p = 14;
499
+ _t2 = _context.v;
500
+ _iterator.e(_t2);
501
+ case 15:
502
+ _context.p = 15;
503
+ _iterator.f();
504
+ return _context.f(15);
505
+ case 16:
506
+ if (!expired) {
507
+ _context.n = 17;
508
+ break;
509
+ }
510
+ return _context.a(3, 22);
511
+ case 17:
512
+ onPhase({
513
+ kind: "uploading",
514
+ done: slots.length,
515
+ total: slots.length
516
+ });
517
+ onPhase({
518
+ kind: "confirming"
519
+ });
520
+ _context.n = 18;
521
+ return client.confirmArtifacts(declared.publishId);
522
+ case 18:
523
+ confirmation = _context.v;
524
+ if (!(confirmation.state === "awaiting-artifacts")) {
525
+ _context.n = 20;
526
+ break;
527
+ }
528
+ if (!(round === DECLARE_ROUNDS)) {
529
+ _context.n = 19;
530
+ break;
531
+ }
532
+ return _context.a(2, {
533
+ status: "failed",
534
+ publishId: publishId,
535
+ message: "Some artifacts did not arrive as declared.",
536
+ problems: confirmation.problems
537
+ });
538
+ case 19:
539
+ return _context.a(3, 22);
540
+ case 20:
541
+ if (!(confirmation.state !== "ready")) {
542
+ _context.n = 21;
543
+ break;
544
+ }
545
+ return _context.a(2, {
546
+ status: "failed",
547
+ publishId: publishId,
548
+ message: "Content left this publish in \"".concat(confirmation.state, "\" after confirming the artifacts."),
549
+ problems: confirmation.problems
550
+ });
551
+ case 21:
552
+ confirmed = true;
553
+ case 22:
554
+ round++;
555
+ _context.n = 2;
556
+ break;
557
+ case 23:
558
+ if (!(!confirmed || publishId === null)) {
559
+ _context.n = 24;
560
+ break;
561
+ }
562
+ return _context.a(2, {
563
+ status: "failed",
564
+ publishId: publishId,
565
+ message: "The artifacts were not confirmed after ".concat(DECLARE_ROUNDS, " attempts."),
566
+ problems: []
567
+ });
568
+ case 24:
569
+ if (!(args.until === "confirmed")) {
570
+ _context.n = 25;
571
+ break;
572
+ }
573
+ return _context.a(2, {
574
+ status: "uploaded",
575
+ publishId: publishId
576
+ });
577
+ case 25:
578
+ onPhase({
579
+ kind: "verifying"
580
+ });
581
+ _context.n = 26;
582
+ return client.verify(publishId);
583
+ case 26:
584
+ verified = _context.v;
585
+ if (verified.ok) {
586
+ _context.n = 27;
587
+ break;
588
+ }
589
+ return _context.a(2, {
590
+ status: "failed",
591
+ publishId: publishId,
592
+ message: "The build was uploaded but did not render, so nothing was published.",
593
+ problems: verified.problems
594
+ });
595
+ case 27:
596
+ onPhase({
597
+ kind: "promoting"
598
+ });
599
+ _context.n = 28;
600
+ return client.promote(publishId);
601
+ case 28:
602
+ promoted = _context.v;
603
+ if (!(promoted.state !== "live")) {
604
+ _context.n = 29;
605
+ break;
606
+ }
607
+ return _context.a(2, {
608
+ status: "failed",
609
+ publishId: publishId,
610
+ message: "The site was not moved to this build: it is \"".concat(promoted.state, "\"."),
611
+ problems: []
612
+ });
613
+ case 29:
614
+ return _context.a(2, {
615
+ status: "live",
616
+ publishId: publishId,
617
+ url: promoted.url
618
+ });
619
+ case 30:
620
+ _context.p = 30;
621
+ _t3 = _context.v;
622
+ return _context.a(2, {
623
+ status: "failed",
624
+ publishId: publishId,
625
+ message: _t3 instanceof StudioPublishError || _t3 instanceof Error ? _t3.message : String(_t3),
626
+ /*
627
+ * Content refuses with `{ statusCode, message, details }`, and the
628
+ * publish routes put EVERY problem in `details`. Without them the editor
629
+ * reads "This publish cannot be declared" and nothing about why.
630
+ */
631
+ problems: _t3 instanceof StudioPublishError ? problemsOf(_t3.body) : []
632
+ });
633
+ }
634
+ }, _callee, null, [[8, 10], [6, 14, 15, 16], [1, 30]]);
635
+ }));
636
+ return _runStudioPublish.apply(this, arguments);
637
+ }
638
+ var problemsOf = function problemsOf(body) {
639
+ return _typeof(body) === "object" && body !== null && "details" in body ? parseProblems(body.details) : [];
640
+ };
641
+
642
+ /**
643
+ * Has the site moved onto other dependencies since this page loaded?
644
+ *
645
+ * A managed project's Studio is served by the site's own live build, so the
646
+ * Studio on screen -- its builder, its Val -- is the version that build was
647
+ * made with. When the site is updated (Settings → Updates, in this tab or
648
+ * another), every Studio opened before that is the OLD version, and a publish
649
+ * from one would build the site with the old builder, or, if it read its build
650
+ * target before the update went live, put the old dependencies back.
651
+ *
652
+ * So the page remembers which dependency layer the live build had when it
653
+ * loaded, and a publish compares that with the live build's now. They differ
654
+ * only when somebody moved the site's dependencies in between; the answer is
655
+ * to reload, which loses nothing -- unpublished changes are the server's.
656
+ *
657
+ * Read from `/__api/head`, which the platform answers on every site without a
658
+ * credential and which names the layer (`projectVendorRev`). Anything that
659
+ * cannot answer -- not on the platform, the loader unreachable, an older
660
+ * loader -- reads as "cannot tell", and "cannot tell" never blocks a publish.
661
+ */
662
+
663
+ /**
664
+ * The layer, or `undefined` for "cannot tell". `null` is never READ -- a head
665
+ * that names no layer is "cannot tell" too, see `readLiveLayer` -- but is what
666
+ * a build target says for a project with none, which is why it is comparable.
667
+ */
668
+
669
+ function readLiveLayer() {
670
+ return _readLiveLayer.apply(this, arguments);
671
+ }
672
+
673
+ /**
674
+ * Stale only on a positive answer from both readings. A page that could not
675
+ * tell what it loaded on, or cannot tell now, publishes as before.
676
+ */
677
+ function _readLiveLayer() {
678
+ _readLiveLayer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
679
+ var fetchImpl,
680
+ res,
681
+ body,
682
+ _args = arguments;
683
+ return _regenerator().w(function (_context) {
684
+ while (1) switch (_context.p = _context.n) {
685
+ case 0:
686
+ fetchImpl = _args.length > 0 && _args[0] !== undefined ? _args[0] : fetch;
687
+ _context.p = 1;
688
+ _context.n = 2;
689
+ return fetchImpl("/__api/head", {
690
+ credentials: "same-origin",
691
+ cache: "no-store"
692
+ });
693
+ case 2:
694
+ res = _context.v;
695
+ if (res.ok) {
696
+ _context.n = 3;
697
+ break;
698
+ }
699
+ return _context.a(2, undefined);
700
+ case 3:
701
+ _context.n = 4;
702
+ return res.json()["catch"](function () {
703
+ return undefined;
704
+ });
705
+ case 4:
706
+ body = _context.v;
707
+ if (!(_typeof(body) !== "object" || body === null || !("hash" in body))) {
708
+ _context.n = 5;
709
+ break;
710
+ }
711
+ return _context.a(2, undefined);
712
+ case 5:
713
+ return _context.a(2, "projectVendorRev" in body && typeof body.projectVendorRev === "string" ? body.projectVendorRev : undefined);
714
+ case 6:
715
+ _context.p = 6;
716
+ _context.v;
717
+ return _context.a(2, undefined);
718
+ }
719
+ }, _callee, null, [[1, 6]]);
720
+ }));
721
+ return _readLiveLayer.apply(this, arguments);
722
+ }
723
+ function layerMoved(loaded, now) {
724
+ if (loaded === undefined || now === undefined) return false;
725
+ return loaded !== now;
726
+ }
727
+ var loaded = null;
728
+
729
+ /**
730
+ * Take the reading this page is compared against. Once per page: the first
731
+ * call wins, because a later one would record the layer an update just moved
732
+ * to and make a stale page look current.
733
+ */
734
+ function rememberLoadedLayer() {
735
+ var fetchImpl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : fetch;
736
+ loaded !== null && loaded !== void 0 ? loaded : loaded = readLiveLayer(fetchImpl);
737
+ }
738
+
739
+ /** What {@link rememberLoadedLayer} read, or `undefined` if it never ran. */
740
+ function loadedLayer() {
741
+ return loaded !== null && loaded !== void 0 ? loaded : Promise.resolve(undefined);
742
+ }
743
+
744
+ /** Has the live build's layer moved since this page loaded? */
745
+ function siteMovedSinceLoad() {
746
+ return _siteMovedSinceLoad.apply(this, arguments);
747
+ }
748
+
749
+ /** The code a deploy refuses with when this page is out of date. */
750
+ function _siteMovedSinceLoad() {
751
+ _siteMovedSinceLoad = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
752
+ var fetchImpl,
753
+ before,
754
+ _args2 = arguments,
755
+ _t2,
756
+ _t3;
757
+ return _regenerator().w(function (_context2) {
758
+ while (1) switch (_context2.n) {
759
+ case 0:
760
+ fetchImpl = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : fetch;
761
+ _context2.n = 1;
762
+ return loadedLayer();
763
+ case 1:
764
+ before = _context2.v;
765
+ if (!(before === undefined)) {
766
+ _context2.n = 2;
767
+ break;
768
+ }
769
+ return _context2.a(2, false);
770
+ case 2:
771
+ _t2 = layerMoved;
772
+ _t3 = before;
773
+ _context2.n = 3;
774
+ return readLiveLayer(fetchImpl);
775
+ case 3:
776
+ return _context2.a(2, _t2(_t3, _context2.v));
777
+ }
778
+ }, _callee2);
779
+ }));
780
+ return _siteMovedSinceLoad.apply(this, arguments);
781
+ }
782
+ var STUDIO_OUT_OF_DATE = "STUDIO_OUT_OF_DATE";
783
+ var STUDIO_OUT_OF_DATE_MESSAGE = "Your site was updated after this Studio was opened. Reload to publish. " + "Your changes are kept.";
784
+
785
+ /*
786
+ * Whether this page has been told it is out of date. Module state rather than
787
+ * React state, because it is found in two places that share no component -- a
788
+ * publish's pre-check and the deploy under it -- and shown in a third.
789
+ */
790
+ /**
791
+ * How many times a publish has been refused for it. A count rather than a
792
+ * flag, so a dialog dismissed once is shown again by the next refused press.
793
+ */
794
+ var refusals = 0;
795
+ var listeners = new Set();
796
+ function markStudioOutOfDate() {
797
+ refusals++;
798
+ var _iterator = _createForOfIteratorHelper(listeners),
799
+ _step;
800
+ try {
801
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
802
+ var listener = _step.value;
803
+ listener();
804
+ }
805
+ } catch (err) {
806
+ _iterator.e(err);
807
+ } finally {
808
+ _iterator.f();
809
+ }
810
+ }
811
+ function studioOutOfDateRefusals() {
812
+ return refusals;
813
+ }
814
+ function subscribeStudioOutOfDate(listener) {
815
+ listeners.add(listener);
816
+ return function () {
817
+ return listeners["delete"](listener);
818
+ };
819
+ }
820
+
821
+ /** For tests: forget everything this module has learnt. */
822
+ function resetLoadedLayerForTests() {
823
+ loaded = null;
824
+ refusals = 0;
825
+ listeners.clear();
826
+ }
827
+
828
+ /**
829
+ * Where a project's route files live, if it has any.
830
+ *
831
+ * Spelled here rather than imported as `ROUTES_DIR` so this module keeps its
832
+ * one runtime reach into the builder package behind `loadBuilder` — the
833
+ * constant is four characters and the guard that says so is worth more. See
834
+ * `onlyBuilderRoot.test.ts`.
835
+ */
836
+ var ROUTES_PREFIX = "src/routes/";
837
+
838
+ /**
839
+ * Where a project's served-as-is files live, and the artifact prefix they are
840
+ * published under -- the same four letters either way, which is the contract
841
+ * (`public/favicon.ico` is requested as `/favicon.ico`). Spelled here for the
842
+ * reason `ROUTES_PREFIX` is.
843
+ */
844
+ var PUBLIC_PREFIX = "public/";
845
+
846
+ /**
847
+ * The binary files a commit wrote, as `/save` answered them.
848
+ *
849
+ * `unread` is files the server could not read back before committing. The
850
+ * build refuses over them: the site would link a file it does not serve.
851
+ */
852
+
853
+ function runStudioDeploy(_x) {
854
+ return _runStudioDeploy.apply(this, arguments);
855
+ }
856
+
857
+ /**
858
+ * The stored source with a commit's files laid over it.
859
+ *
860
+ * A new record rather than an edit of the one read, which the caller may still
861
+ * hold. Val names module files with a leading `/`; the stored record does
862
+ * not, so the slash is dropped -- two spellings of one path would build the
863
+ * old file and publish the new one beside it.
864
+ */
865
+ function _runStudioDeploy() {
866
+ _runStudioDeploy = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
867
+ var _options$committedFil3, _git$commit, _git, _git$branch, _git2;
868
+ var client, onPhase, failed, publishByName, builder, target, source, carried, refetched, _options$target, _options$committedBin, _options$committedBin2, _options$committedFil, _yield$Promise$all, _yield$Promise$all2, readTarget, readSource, readPublic, unread, _options$committedFil2, build, git, wiredSource, _ref8, _options$branch, _yield$builder$bakedG, _options$committedBin3, _options$committedBin4, branch, wired, fileBased, generateRouteTree, binaries, extraInputs, input, name, held, live, artifacts, _live, declared, published, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12, _t13, _t14, _t15, _t16, _t17, _t18, _t19, _t20, _t21;
869
+ return _regenerator().w(function (_context2) {
870
+ while (1) switch (_context2.p = _context2.n) {
871
+ case 0:
872
+ client = options.client, onPhase = options.onPhase;
873
+ failed = function failed(message) {
874
+ return {
875
+ status: "failed",
876
+ message: message,
877
+ problems: []
878
+ };
879
+ };
880
+ /*
881
+ * The build content already holds under this name, published as any build
882
+ * is -- or `null` when content holds none, or cannot be asked by name (one
883
+ * from before the question existed refuses an empty declaration), and the
884
+ * build has to be made.
885
+ *
886
+ * `null` only for a refusal of the DECLARE: once content has taken the
887
+ * build, what happens to it is that publish's outcome, a failure included.
888
+ * Building it again would not change it.
889
+ */
890
+ publishByName = /*#__PURE__*/function () {
891
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(name, at) {
892
+ var _at$git$commit, _at$git, _at$git$branch, _at$git2;
893
+ var published;
894
+ return _regenerator().w(function (_context) {
895
+ while (1) switch (_context.n) {
896
+ case 0:
897
+ _context.n = 1;
898
+ return runStudioPublish(_objectSpread2({
899
+ client: client,
900
+ artifacts: [],
901
+ declare: {
902
+ buildHash: name,
903
+ commit: (_at$git$commit = (_at$git = at.git) === null || _at$git === void 0 ? void 0 : _at$git.commit) !== null && _at$git$commit !== void 0 ? _at$git$commit : null,
904
+ branch: (_at$git$branch = (_at$git2 = at.git) === null || _at$git2 === void 0 ? void 0 : _at$git2.branch) !== null && _at$git$branch !== void 0 ? _at$git$branch : null,
905
+ layerRev: at.layerRev,
906
+ // The build's, which content has: this tab built nothing to ask.
907
+ linksOwnCss: null,
908
+ artifacts: [],
909
+ byReference: true
910
+ },
911
+ onPhase: onPhase
912
+ }, options.until !== undefined ? {
913
+ until: options.until
914
+ } : {}));
915
+ case 1:
916
+ published = _context.v;
917
+ if (!(published.status === "failed" && published.publishId === null)) {
918
+ _context.n = 2;
919
+ break;
920
+ }
921
+ return _context.a(2, null);
922
+ case 2:
923
+ return _context.a(2, asDeployResult(published));
924
+ }
925
+ }, _callee);
926
+ }));
927
+ return function publishByName(_x5, _x6) {
928
+ return _ref7.apply(this, arguments);
929
+ };
930
+ }();
931
+ _context2.p = 1;
932
+ onPhase({
933
+ kind: "getting-ready"
934
+ });
935
+ _context2.n = 2;
936
+ return options.loadBuilder();
937
+ case 2:
938
+ builder = _context2.v;
939
+ _context2.n = 4;
940
+ break;
941
+ case 3:
942
+ _context2.p = 3;
943
+ _t = _context2.v;
944
+ return _context2.a(2, failed(messageOf$2(_t)));
945
+ case 4:
946
+ _context2.p = 4;
947
+ onPhase({
948
+ kind: "reading"
949
+ });
950
+ /*
951
+ * Together, because they are one answer with two halves and neither is
952
+ * useful alone -- and because the round trip is the cost, not the work.
953
+ */
954
+ _context2.n = 5;
955
+ return Promise.all([(_options$target = options.target) !== null && _options$target !== void 0 ? _options$target : client.buildTarget(), client.projectSource(), client.publicFiles()]);
956
+ case 5:
957
+ _yield$Promise$all = _context2.v;
958
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
959
+ readTarget = _yield$Promise$all2[0];
960
+ readSource = _yield$Promise$all2[1];
961
+ readPublic = _yield$Promise$all2[2];
962
+ if (!(readSource === null)) {
963
+ _context2.n = 6;
964
+ break;
965
+ }
966
+ return _context2.a(2, failed("This project has no published source to build from. Publish it once " + "from a checkout before editing it here."));
967
+ case 6:
968
+ if (!(readTarget.project.rev === null)) {
969
+ _context2.n = 7;
970
+ break;
971
+ }
972
+ return _context2.a(2, failed("This project has no dependency layer yet, and one cannot be built " + "from the browser. Publish it once from a checkout, which builds it."));
973
+ case 7:
974
+ if (!(options.target === undefined && layerMoved(options.loadedLayer, readTarget.project.rev))) {
975
+ _context2.n = 8;
976
+ break;
977
+ }
978
+ return _context2.a(2, {
979
+ status: "failed",
980
+ message: STUDIO_OUT_OF_DATE_MESSAGE,
981
+ problems: [{
982
+ code: STUDIO_OUT_OF_DATE,
983
+ message: STUDIO_OUT_OF_DATE_MESSAGE
984
+ }]
985
+ });
986
+ case 8:
987
+ if (!(readPublic === null || "paths" in readPublic && options.fetchPublicFile === undefined)) {
988
+ _context2.n = 9;
989
+ break;
990
+ }
991
+ return _context2.a(2, failed("The Studio cannot tell which images and other public files this " + "site serves, so publishing would remove them. Publish it once from " + "a checkout with `val publish`, and the Studio can publish it from " + "then on."));
992
+ case 9:
993
+ unread = (_options$committedBin = (_options$committedBin2 = options.committedBinaryFiles) === null || _options$committedBin2 === void 0 ? void 0 : _options$committedBin2.unread) !== null && _options$committedBin !== void 0 ? _options$committedBin : [];
994
+ if (!(unread.length > 0)) {
995
+ _context2.n = 10;
996
+ break;
997
+ }
998
+ return _context2.a(2, failed("Your changes are saved, but ".concat(unread.join(", "), " could not be read ") + "back to build with, and the site would link a file it does not " + "serve. Try publishing again."));
999
+ case 10:
1000
+ target = readTarget;
1001
+ source = withCommittedFiles(readSource, (_options$committedFil = options.committedFiles) !== null && _options$committedFil !== void 0 ? _options$committedFil : null);
1002
+ if (!("carried" in readPublic)) {
1003
+ _context2.n = 11;
1004
+ break;
1005
+ }
1006
+ carried = readPublic.carried;
1007
+ refetched = {};
1008
+ _context2.n = 13;
1009
+ break;
1010
+ case 11:
1011
+ /*
1012
+ * Content has no record of the live build -- a project cloned from a
1013
+ * template seed -- but the loader knows what it serves, and this page is
1014
+ * ON the site. So the files come from the site and go into the build;
1015
+ * content holds their hashes after this publish and the next one
1016
+ * carries them without fetching.
1017
+ */
1018
+ carried = [];
1019
+ _context2.n = 12;
1020
+ return refetchPublicFiles(readPublic.paths, (_options$committedFil2 = options.committedFiles) !== null && _options$committedFil2 !== void 0 ? _options$committedFil2 : null, options.fetchPublicFile);
1021
+ case 12:
1022
+ refetched = _context2.v;
1023
+ case 13:
1024
+ _context2.n = 15;
1025
+ break;
1026
+ case 14:
1027
+ _context2.p = 14;
1028
+ _t2 = _context2.v;
1029
+ return _context2.a(2, failed(messageOf$2(_t2)));
1030
+ case 15:
1031
+ _context2.p = 15;
1032
+ onPhase({
1033
+ kind: "building"
1034
+ });
1035
+ /*
1036
+ * The branch the last build was wired at, which is the only place one can
1037
+ * be read from here -- `/stat` does not carry one and neither does
1038
+ * `/save`. `null` when the record names none, which is a project that has
1039
+ * only ever published commitlessly; content then answers from the
1040
+ * project's own chain, where the answer always came from for a project
1041
+ * whose content service is its store of record.
1042
+ *
1043
+ * The pair goes in BEFORE the build, and into the record published back as
1044
+ * source, so the next publish reads it back and the two never disagree
1045
+ * about which commit this build is wired at.
1046
+ */
1047
+ if (!((_options$branch = options.branch) !== null && _options$branch !== void 0)) {
1048
+ _context2.n = 16;
1049
+ break;
1050
+ }
1051
+ _t4 = _options$branch;
1052
+ _context2.n = 21;
1053
+ break;
1054
+ case 16:
1055
+ _context2.n = 17;
1056
+ return builder.bakedGit(source);
1057
+ case 17:
1058
+ _t6 = _yield$builder$bakedG = _context2.v;
1059
+ _t5 = _t6 === null;
1060
+ if (_t5) {
1061
+ _context2.n = 18;
1062
+ break;
1063
+ }
1064
+ _t5 = _yield$builder$bakedG === void 0;
1065
+ case 18:
1066
+ if (!_t5) {
1067
+ _context2.n = 19;
1068
+ break;
1069
+ }
1070
+ _t7 = void 0;
1071
+ _context2.n = 20;
1072
+ break;
1073
+ case 19:
1074
+ _t7 = _yield$builder$bakedG.branch;
1075
+ case 20:
1076
+ _t4 = _t7;
1077
+ case 21:
1078
+ _t8 = _ref8 = _t4;
1079
+ _t3 = _t8 !== null;
1080
+ if (!_t3) {
1081
+ _context2.n = 22;
1082
+ break;
1083
+ }
1084
+ _t3 = _ref8 !== void 0;
1085
+ case 22:
1086
+ if (!_t3) {
1087
+ _context2.n = 23;
1088
+ break;
1089
+ }
1090
+ _t9 = _ref8;
1091
+ _context2.n = 24;
1092
+ break;
1093
+ case 23:
1094
+ _t9 = null;
1095
+ case 24:
1096
+ branch = _t9;
1097
+ git = options.commit === null || branch === null ? null : {
1098
+ commit: options.commit,
1099
+ branch: branch
1100
+ };
1101
+ _context2.n = 25;
1102
+ return builder.rebakeGit(source, git, options.job);
1103
+ case 25:
1104
+ wired = _context2.v;
1105
+ wiredSource = wired;
1106
+ fileBased = Object.keys(wired).some(function (path) {
1107
+ return path.startsWith(ROUTES_PREFIX);
1108
+ });
1109
+ /*
1110
+ * Read out before the branch, so the guard below and the call are the same
1111
+ * narrowing rather than two that agree by inspection.
1112
+ */
1113
+ generateRouteTree = options.generateRouteTree;
1114
+ if (!(fileBased && generateRouteTree === undefined)) {
1115
+ _context2.n = 26;
1116
+ break;
1117
+ }
1118
+ return _context2.a(2, failed("This project's pages are files under src/routes, and building those " + "needs a route generator this page was not given. Publish it from a " + "checkout, or mount the Studio in a deployment that supplies one."));
1119
+ case 26:
1120
+ binaries = splitBinaryFiles((_options$committedBin3 = (_options$committedBin4 = options.committedBinaryFiles) === null || _options$committedBin4 === void 0 ? void 0 : _options$committedBin4.files) !== null && _options$committedBin3 !== void 0 ? _options$committedBin3 : {});
1121
+ /*
1122
+ * What this build ships that it is not built from, so the build's name
1123
+ * (`buildInputId`) changes with it: the live build's public files carried
1124
+ * over by sha, and -- below -- the live stylesheet in place of an empty one.
1125
+ */
1126
+ extraInputs = Object.fromEntries(carried.map(function (_ref9) {
1127
+ var key = _ref9.key,
1128
+ sha256 = _ref9.sha256;
1129
+ return ["carried:".concat(key), sha256];
1130
+ }));
1131
+ if (!(fileBased && generateRouteTree !== undefined)) {
1132
+ _context2.n = 28;
1133
+ break;
1134
+ }
1135
+ _context2.n = 27;
1136
+ return generateRouteTree(wired);
1137
+ case 27:
1138
+ _t0 = _context2.v;
1139
+ _context2.n = 29;
1140
+ break;
1141
+ case 28:
1142
+ _t0 = wired;
1143
+ case 29:
1144
+ _t1 = _t0;
1145
+ _t10 = _objectSpread2(_objectSpread2({}, refetched), binaries.publicFiles);
1146
+ _t11 = binaries.assets;
1147
+ _t12 = wired;
1148
+ _t13 = target;
1149
+ _t14 = extraInputs;
1150
+ input = {
1151
+ files: _t1,
1152
+ publicFiles: _t10,
1153
+ assets: _t11,
1154
+ projectSource: _t12,
1155
+ target: _t13,
1156
+ extraInputs: _t14
1157
+ };
1158
+ _context2.n = 30;
1159
+ return builder.buildInputId(input)["catch"](function () {
1160
+ return null;
1161
+ });
1162
+ case 30:
1163
+ name = _context2.v;
1164
+ if (!(name !== null)) {
1165
+ _context2.n = 33;
1166
+ break;
1167
+ }
1168
+ _context2.n = 31;
1169
+ return publishByName(name, {
1170
+ git: git,
1171
+ layerRev: target.project.rev
1172
+ });
1173
+ case 31:
1174
+ held = _context2.v;
1175
+ if (!(held !== null)) {
1176
+ _context2.n = 32;
1177
+ break;
1178
+ }
1179
+ return _context2.a(2, held);
1180
+ case 32:
1181
+ onPhase({
1182
+ kind: "building"
1183
+ });
1184
+ case 33:
1185
+ _context2.n = 34;
1186
+ return builder.buildUserApp(input);
1187
+ case 34:
1188
+ build = _context2.v;
1189
+ if (!(build.cssCode === "" && options.liveStylesheet)) {
1190
+ _context2.n = 37;
1191
+ break;
1192
+ }
1193
+ _context2.n = 35;
1194
+ return options.liveStylesheet();
1195
+ case 35:
1196
+ live = _context2.v;
1197
+ if (!(live !== "")) {
1198
+ _context2.n = 37;
1199
+ break;
1200
+ }
1201
+ _t15 = _objectSpread2;
1202
+ _t16 = _objectSpread2({}, build);
1203
+ _t17 = {};
1204
+ _t18 = live;
1205
+ _context2.n = 36;
1206
+ return builder.buildInputId(_objectSpread2(_objectSpread2({}, input), {}, {
1207
+ extraInputs: _objectSpread2(_objectSpread2({}, extraInputs), {}, {
1208
+ liveStylesheet: live
1209
+ })
1210
+ }));
1211
+ case 36:
1212
+ _t19 = _context2.v;
1213
+ build = _t15(_t16, _t17, {
1214
+ cssCode: _t18,
1215
+ hash: _t19
1216
+ });
1217
+ case 37:
1218
+ _context2.n = 39;
1219
+ break;
1220
+ case 38:
1221
+ _context2.p = 38;
1222
+ _t20 = _context2.v;
1223
+ return _context2.a(2, failed(messageOf$2(_t20)));
1224
+ case 39:
1225
+ _context2.p = 39;
1226
+ _context2.n = 40;
1227
+ return builder.publishArtifacts(build, {
1228
+ projectSource: wiredSource
1229
+ });
1230
+ case 40:
1231
+ artifacts = _context2.v;
1232
+ _context2.n = 42;
1233
+ break;
1234
+ case 41:
1235
+ _context2.p = 41;
1236
+ _t21 = _context2.v;
1237
+ return _context2.a(2, failed(messageOf$2(_t21)));
1238
+ case 42:
1239
+ if (!(options.target === undefined && options.liveLayer !== undefined)) {
1240
+ _context2.n = 44;
1241
+ break;
1242
+ }
1243
+ _context2.n = 43;
1244
+ return options.liveLayer()["catch"](function () {
1245
+ return undefined;
1246
+ });
1247
+ case 43:
1248
+ _live = _context2.v;
1249
+ if (!layerMoved(options.loadedLayer, _live)) {
1250
+ _context2.n = 44;
1251
+ break;
1252
+ }
1253
+ return _context2.a(2, {
1254
+ status: "failed",
1255
+ message: STUDIO_OUT_OF_DATE_MESSAGE,
1256
+ problems: [{
1257
+ code: STUDIO_OUT_OF_DATE,
1258
+ message: STUDIO_OUT_OF_DATE_MESSAGE
1259
+ }]
1260
+ });
1261
+ case 44:
1262
+ declared = [].concat(_toConsumableArray(artifacts.map(function (_ref0) {
1263
+ var key = _ref0.key,
1264
+ sha256 = _ref0.sha256,
1265
+ bytes = _ref0.bytes;
1266
+ return {
1267
+ key: key,
1268
+ sha256: sha256,
1269
+ bytes: bytes
1270
+ };
1271
+ })), _toConsumableArray(carriedInto(artifacts, carried, (_options$committedFil3 = options.committedFiles) !== null && _options$committedFil3 !== void 0 ? _options$committedFil3 : null)));
1272
+ _context2.n = 45;
1273
+ return runStudioPublish(_objectSpread2({
1274
+ client: client,
1275
+ artifacts: artifacts,
1276
+ declare: {
1277
+ buildHash: build.hash,
1278
+ /*
1279
+ * What went into the build, not what the caller asked for. A declare
1280
+ * naming a commit the bundle was not wired at labels a build as
1281
+ * something it is not.
1282
+ */
1283
+ commit: (_git$commit = (_git = git) === null || _git === void 0 ? void 0 : _git.commit) !== null && _git$commit !== void 0 ? _git$commit : null,
1284
+ branch: (_git$branch = (_git2 = git) === null || _git2 === void 0 ? void 0 : _git2.branch) !== null && _git$branch !== void 0 ? _git$branch : null,
1285
+ layerRev: target.project.rev,
1286
+ // The base layer this build was compiled against, so the platform can
1287
+ // refuse it if it has been deployed since.
1288
+ baseRev: build.vendorRev,
1289
+ linksOwnCss: build.linksOwnCss,
1290
+ artifacts: declared
1291
+ },
1292
+ onPhase: onPhase
1293
+ }, options.until !== undefined ? {
1294
+ until: options.until
1295
+ } : {}));
1296
+ case 45:
1297
+ published = _context2.v;
1298
+ return _context2.a(2, asDeployResult(published));
1299
+ }
1300
+ }, _callee2, null, [[39, 41], [15, 38], [4, 14], [1, 3]]);
1301
+ }));
1302
+ return _runStudioDeploy.apply(this, arguments);
1303
+ }
1304
+ function withCommittedFiles(source, committed) {
1305
+ if (committed === null) return source;
1306
+ var out = _objectSpread2({}, source);
1307
+ for (var _i = 0, _Object$entries = Object.entries(committed); _i < _Object$entries.length; _i++) {
1308
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1309
+ path = _Object$entries$_i[0],
1310
+ content = _Object$entries$_i[1];
1311
+ var key = path.replace(/^\/+/, "");
1312
+ if (content === null) delete out[key];else out[key] = content;
1313
+ }
1314
+ return out;
1315
+ }
1316
+
1317
+ /**
1318
+ * A commit's binary files, as the build takes them: `public/...` served as is,
1319
+ * everything else an asset an import can reach. Keys lose the leading `/`
1320
+ * Val's paths carry, as in {@link withCommittedFiles}.
1321
+ */
1322
+ function splitBinaryFiles(files) {
1323
+ var publicFiles = {};
1324
+ var assets = {};
1325
+ for (var _i2 = 0, _Object$entries2 = Object.entries(files); _i2 < _Object$entries2.length; _i2++) {
1326
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
1327
+ path = _Object$entries2$_i[0],
1328
+ base64 = _Object$entries2$_i[1];
1329
+ var key = path.replace(/^\/+/, "");
1330
+ if (key.startsWith(PUBLIC_PREFIX)) publicFiles[key] = base64;else assets[key] = base64;
1331
+ }
1332
+ return {
1333
+ publicFiles: publicFiles,
1334
+ assets: assets
1335
+ };
1336
+ }
1337
+
1338
+ /**
1339
+ * The live site's public files, fetched to be built with, as `public/<path>`.
1340
+ *
1341
+ * All of them but the ones the commit deleted -- a replaced one is overridden
1342
+ * by the commit's own bytes where the two are merged. A file that cannot be
1343
+ * fetched fails the publish by name: leaving it out is the hole this exists
1344
+ * to prevent.
1345
+ */
1346
+ function refetchPublicFiles(_x2, _x3, _x4) {
1347
+ return _refetchPublicFiles.apply(this, arguments);
1348
+ }
1349
+ /**
1350
+ * The live build's public files this build keeps, re-declared by hash.
1351
+ *
1352
+ * All of them, except the ones this build produced itself (a file the commit
1353
+ * replaced) and the ones the commit deleted. Content holds the bytes already,
1354
+ * so this uploads nothing -- and if it has lost one, it asks for it, and
1355
+ * `runStudioPublish` refuses rather than publishing a hole.
1356
+ */
1357
+ function _refetchPublicFiles() {
1358
+ _refetchPublicFiles = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(paths, committed, fetchPublicFile) {
1359
+ var deleted, out, _iterator, _step, path, key, _t22, _t23;
1360
+ return _regenerator().w(function (_context3) {
1361
+ while (1) switch (_context3.p = _context3.n) {
1362
+ case 0:
1363
+ deleted = new Set(Object.entries(committed !== null && committed !== void 0 ? committed : {}).filter(function (_ref1) {
1364
+ var _ref10 = _slicedToArray(_ref1, 2),
1365
+ content = _ref10[1];
1366
+ return content === null;
1367
+ }).map(function (_ref11) {
1368
+ var _ref12 = _slicedToArray(_ref11, 1),
1369
+ path = _ref12[0];
1370
+ return path.replace(/^\/+/, "");
1371
+ }));
1372
+ out = {};
1373
+ _iterator = _createForOfIteratorHelper(paths);
1374
+ _context3.p = 1;
1375
+ _iterator.s();
1376
+ case 2:
1377
+ if ((_step = _iterator.n()).done) {
1378
+ _context3.n = 8;
1379
+ break;
1380
+ }
1381
+ path = _step.value;
1382
+ key = PUBLIC_PREFIX + path.replace(/^\/+/, "");
1383
+ if (!deleted.has(key)) {
1384
+ _context3.n = 3;
1385
+ break;
1386
+ }
1387
+ return _context3.a(3, 7);
1388
+ case 3:
1389
+ if (!(fetchPublicFile === undefined)) {
1390
+ _context3.n = 4;
1391
+ break;
1392
+ }
1393
+ throw new Error("No way to read /".concat(path, " from the site to build with."));
1394
+ case 4:
1395
+ _context3.p = 4;
1396
+ _context3.n = 5;
1397
+ return fetchPublicFile(path.replace(/^\/+/, ""));
1398
+ case 5:
1399
+ out[key] = _context3.v;
1400
+ _context3.n = 7;
1401
+ break;
1402
+ case 6:
1403
+ _context3.p = 6;
1404
+ _t22 = _context3.v;
1405
+ throw new Error("The site's /".concat(path, " could not be read to build with, and leaving it ") + "out would remove it: ".concat(messageOf$2(_t22)), {
1406
+ cause: _t22
1407
+ });
1408
+ case 7:
1409
+ _context3.n = 2;
1410
+ break;
1411
+ case 8:
1412
+ _context3.n = 10;
1413
+ break;
1414
+ case 9:
1415
+ _context3.p = 9;
1416
+ _t23 = _context3.v;
1417
+ _iterator.e(_t23);
1418
+ case 10:
1419
+ _context3.p = 10;
1420
+ _iterator.f();
1421
+ return _context3.f(10);
1422
+ case 11:
1423
+ return _context3.a(2, out);
1424
+ }
1425
+ }, _callee3, null, [[4, 6], [1, 9, 10, 11]]);
1426
+ }));
1427
+ return _refetchPublicFiles.apply(this, arguments);
1428
+ }
1429
+ function carriedInto(built, carried, committed) {
1430
+ var produced = new Set(built.map(function (_ref) {
1431
+ var key = _ref.key;
1432
+ return key;
1433
+ }));
1434
+ var deleted = new Set(Object.entries(committed !== null && committed !== void 0 ? committed : {}).filter(function (_ref2) {
1435
+ var _ref3 = _slicedToArray(_ref2, 2),
1436
+ content = _ref3[1];
1437
+ return content === null;
1438
+ }).map(function (_ref4) {
1439
+ var _ref5 = _slicedToArray(_ref4, 1),
1440
+ path = _ref5[0];
1441
+ return path.replace(/^\/+/, "");
1442
+ }));
1443
+ return carried.filter(function (_ref6) {
1444
+ var key = _ref6.key;
1445
+ return key.startsWith(PUBLIC_PREFIX) && !produced.has(key) && !deleted.has(key);
1446
+ });
1447
+ }
1448
+ var asDeployResult = function asDeployResult(published) {
1449
+ switch (published.status) {
1450
+ case "live":
1451
+ return {
1452
+ status: "live",
1453
+ url: published.url
1454
+ };
1455
+ case "already-live":
1456
+ return {
1457
+ status: "already-live",
1458
+ url: published.url
1459
+ };
1460
+ case "uploaded":
1461
+ return {
1462
+ status: "uploaded",
1463
+ publishId: published.publishId
1464
+ };
1465
+ case "failed":
1466
+ return {
1467
+ status: "failed",
1468
+ message: published.message,
1469
+ problems: published.problems
1470
+ };
1471
+ }
1472
+ };
1473
+
1474
+ /**
1475
+ * A thrown thing, as a sentence.
1476
+ *
1477
+ * `String(error)` on an Error gives `Error: ...`, which reads as a stack trace
1478
+ * leaking into the page. The message alone is what was written for a person.
1479
+ */
1480
+ var messageOf$2 = function messageOf(error) {
1481
+ return error instanceof Error ? error.message : String(error);
1482
+ };
1483
+
1484
+ var _excluded = ["buildable"];
1485
+
1486
+ /**
1487
+ * Publishing as a queued job, as a Studio tab speaks it.
1488
+ *
1489
+ * valbuild/home's docs/app-mode.md, "Publishing is a queued job", is the
1490
+ * design: a press is a REQUEST that returns at once; the tab that pressed runs
1491
+ * the job it is given -- prepare, build, upload -- and content runs verify and
1492
+ * the seal. Everything goes through this deployment: the job routes through
1493
+ * the publish proxy, and the prepare through this server's own route, which is
1494
+ * the one place a job's sources can be computed.
1495
+ */
1496
+
1497
+ /** What the tab builds a job from: `/api/val/publish-job-prepare`'s answer. */
1498
+
1499
+ function createStudioJobClient(options) {
1500
+ var _options$fetchImpl;
1501
+ var fetchImpl = (_options$fetchImpl = options.fetchImpl) !== null && _options$fetchImpl !== void 0 ? _options$fetchImpl : fetch;
1502
+ var publishApi = publishApiOf(options);
1503
+ var proposalsApi = "proposalsApi" in options ? options.proposalsApi.replace(/\/+$/, "") : "".concat(options.api.replace(/\/+$/, ""), "/proposals-api");
1504
+ var proxy = function proxy(path, method, body) {
1505
+ return callJson(fetchImpl, "".concat(publishApi).concat(path), method, body);
1506
+ };
1507
+ var job = function job(jobId, step) {
1508
+ return "/publish-jobs/".concat(encodeURIComponent(jobId), "/").concat(step);
1509
+ };
1510
+ return {
1511
+ press: function () {
1512
+ var _press = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(requestId, tab) {
1513
+ var _t;
1514
+ return _regenerator().w(function (_context) {
1515
+ while (1) switch (_context.n) {
1516
+ case 0:
1517
+ _t = parsePress;
1518
+ _context.n = 1;
1519
+ return proxy("/publish-requests", "POST", {
1520
+ requestId: requestId,
1521
+ tab: tab
1522
+ });
1523
+ case 1:
1524
+ return _context.a(2, _t(_context.v, "POST /v1/publish-requests"));
1525
+ }
1526
+ }, _callee);
1527
+ }));
1528
+ function press(_x, _x2) {
1529
+ return _press.apply(this, arguments);
1530
+ }
1531
+ return press;
1532
+ }(),
1533
+ pressMerge: function () {
1534
+ var _pressMerge = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(proposal, requestId, tab, anyway) {
1535
+ var _t2;
1536
+ return _regenerator().w(function (_context2) {
1537
+ while (1) switch (_context2.n) {
1538
+ case 0:
1539
+ _t2 = parsePress;
1540
+ _context2.n = 1;
1541
+ return callJson(fetchImpl, "".concat(proposalsApi, "/").concat(encodeURIComponent(proposal), "/merge"), "POST", _objectSpread2({
1542
+ requestId: requestId,
1543
+ tab: tab
1544
+ }, anyway !== undefined && anyway.length > 0 ? {
1545
+ anyway: anyway
1546
+ } : {}));
1547
+ case 1:
1548
+ return _context2.a(2, _t2(_context2.v, "POST /v1/proposals/{name}/merge"));
1549
+ }
1550
+ }, _callee2);
1551
+ }));
1552
+ function pressMerge(_x3, _x4, _x5, _x6) {
1553
+ return _pressMerge.apply(this, arguments);
1554
+ }
1555
+ return pressMerge;
1556
+ }(),
1557
+ tryAgain: function () {
1558
+ var _tryAgain = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(requestId, tab) {
1559
+ var _t3;
1560
+ return _regenerator().w(function (_context3) {
1561
+ while (1) switch (_context3.n) {
1562
+ case 0:
1563
+ _t3 = parsePress;
1564
+ _context3.n = 1;
1565
+ return proxy("/publish-requests/try-again", "POST", {
1566
+ requestId: requestId,
1567
+ tab: tab
1568
+ });
1569
+ case 1:
1570
+ return _context3.a(2, _t3(_context3.v, "POST /v1/publish-requests/try-again"));
1571
+ }
1572
+ }, _callee3);
1573
+ }));
1574
+ function tryAgain(_x7, _x8) {
1575
+ return _tryAgain.apply(this, arguments);
1576
+ }
1577
+ return tryAgain;
1578
+ }(),
1579
+ requestStatus: function () {
1580
+ var _requestStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(requestId) {
1581
+ var _t4;
1582
+ return _regenerator().w(function (_context4) {
1583
+ while (1) switch (_context4.n) {
1584
+ case 0:
1585
+ _t4 = parseRequestStatus;
1586
+ _context4.n = 1;
1587
+ return proxy("/publish-requests/".concat(encodeURIComponent(requestId)), "GET");
1588
+ case 1:
1589
+ return _context4.a(2, _t4(_context4.v).request);
1590
+ }
1591
+ }, _callee4);
1592
+ }));
1593
+ function requestStatus(_x9) {
1594
+ return _requestStatus.apply(this, arguments);
1595
+ }
1596
+ return requestStatus;
1597
+ }(),
1598
+ next: function () {
1599
+ var _next = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(tab) {
1600
+ var _t5;
1601
+ return _regenerator().w(function (_context5) {
1602
+ while (1) switch (_context5.n) {
1603
+ case 0:
1604
+ _t5 = parseJob;
1605
+ _context5.n = 1;
1606
+ return proxy("/publish-jobs/next", "POST", {
1607
+ tab: tab
1608
+ });
1609
+ case 1:
1610
+ return _context5.a(2, _t5(_context5.v, "POST /v1/publish-jobs/next").job);
1611
+ }
1612
+ }, _callee5);
1613
+ }));
1614
+ function next(_x0) {
1615
+ return _next.apply(this, arguments);
1616
+ }
1617
+ return next;
1618
+ }(),
1619
+ prepare: function () {
1620
+ var _prepare = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(tabJob, tab) {
1621
+ var merged, answer, _t6;
1622
+ return _regenerator().w(function (_context6) {
1623
+ while (1) switch (_context6.n) {
1624
+ case 0:
1625
+ if (!tabJob.patches.some(isMergeChange)) {
1626
+ _context6.n = 2;
1627
+ break;
1628
+ }
1629
+ _t6 = MergePrepareAnswer;
1630
+ _context6.n = 1;
1631
+ return proxy(job(tabJob.id, "merge-prepare"), "POST", {
1632
+ tab: tab
1633
+ });
1634
+ case 1:
1635
+ merged = _t6.parse.call(_t6, _context6.v);
1636
+ return _context6.a(2, _objectSpread2({
1637
+ job: merged.job,
1638
+ sourceFiles: merged.sourceFiles,
1639
+ binaryFiles: {},
1640
+ binaryFilesUnread: [],
1641
+ branch: null,
1642
+ buildable: true
1643
+ }, merged.target !== undefined ? {
1644
+ target: parseBuildTarget(merged.target)
1645
+ } : {}));
1646
+ case 2:
1647
+ if ("api" in options) {
1648
+ _context6.n = 3;
1649
+ break;
1650
+ }
1651
+ throw new Error("Only a merge's job can be run here: a site change's job needs the Studio.");
1652
+ case 3:
1653
+ _context6.n = 4;
1654
+ return callJson(fetchImpl, "".concat(options.api.replace(/\/+$/, ""), "/publish-job-prepare"), "POST", {
1655
+ jobId: tabJob.id,
1656
+ tab: tab,
1657
+ patchIds: tabJob.patches
1658
+ });
1659
+ case 4:
1660
+ answer = _context6.v;
1661
+ return _context6.a(2, parsePreparedJob(answer));
1662
+ }
1663
+ }, _callee6);
1664
+ }));
1665
+ function prepare(_x1, _x10) {
1666
+ return _prepare.apply(this, arguments);
1667
+ }
1668
+ return prepare;
1669
+ }(),
1670
+ step: function () {
1671
+ var _step = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(jobId, body) {
1672
+ var _t7;
1673
+ return _regenerator().w(function (_context7) {
1674
+ while (1) switch (_context7.n) {
1675
+ case 0:
1676
+ _t7 = parseJob;
1677
+ _context7.n = 1;
1678
+ return proxy(job(jobId, "steps"), "POST", body);
1679
+ case 1:
1680
+ return _context7.a(2, _t7(_context7.v, "POST /v1/publish-jobs/{id}/steps").job);
1681
+ }
1682
+ }, _callee7);
1683
+ }));
1684
+ function step(_x11, _x12) {
1685
+ return _step.apply(this, arguments);
1686
+ }
1687
+ return step;
1688
+ }(),
1689
+ renew: function () {
1690
+ var _renew = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(jobId, tab) {
1691
+ var _t8;
1692
+ return _regenerator().w(function (_context8) {
1693
+ while (1) switch (_context8.n) {
1694
+ case 0:
1695
+ _t8 = parseRenew;
1696
+ _context8.n = 1;
1697
+ return proxy(job(jobId, "renew"), "POST", {
1698
+ tab: tab
1699
+ });
1700
+ case 1:
1701
+ return _context8.a(2, _t8(_context8.v).renewed);
1702
+ }
1703
+ }, _callee8);
1704
+ }));
1705
+ function renew(_x13, _x14) {
1706
+ return _renew.apply(this, arguments);
1707
+ }
1708
+ return renew;
1709
+ }(),
1710
+ cancel: function () {
1711
+ var _cancel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(jobId) {
1712
+ var _t9;
1713
+ return _regenerator().w(function (_context9) {
1714
+ while (1) switch (_context9.n) {
1715
+ case 0:
1716
+ _t9 = parseCancel;
1717
+ _context9.n = 1;
1718
+ return proxy(job(jobId, "cancel"), "POST", {});
1719
+ case 1:
1720
+ return _context9.a(2, _t9(_context9.v).cancelled);
1721
+ }
1722
+ }, _callee9);
1723
+ }));
1724
+ function cancel(_x15) {
1725
+ return _cancel.apply(this, arguments);
1726
+ }
1727
+ return cancel;
1728
+ }(),
1729
+ discard: function () {
1730
+ var _discard = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(jobId) {
1731
+ var _t0;
1732
+ return _regenerator().w(function (_context0) {
1733
+ while (1) switch (_context0.n) {
1734
+ case 0:
1735
+ _t0 = parseDiscard;
1736
+ _context0.n = 1;
1737
+ return proxy(job(jobId, "discard"), "POST", {});
1738
+ case 1:
1739
+ return _context0.a(2, _t0(_context0.v).stillHeld);
1740
+ }
1741
+ }, _callee0);
1742
+ }));
1743
+ function discard(_x16) {
1744
+ return _discard.apply(this, arguments);
1745
+ }
1746
+ return discard;
1747
+ }(),
1748
+ newestCiRun: function () {
1749
+ var _newestCiRun = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
1750
+ var _t1;
1751
+ return _regenerator().w(function (_context1) {
1752
+ while (1) switch (_context1.n) {
1753
+ case 0:
1754
+ _t1 = parseNewestCiRun;
1755
+ _context1.n = 1;
1756
+ return proxy("/ci-runs/newest", "GET");
1757
+ case 1:
1758
+ return _context1.a(2, _t1(_context1.v).run);
1759
+ }
1760
+ }, _callee1);
1761
+ }));
1762
+ function newestCiRun() {
1763
+ return _newestCiRun.apply(this, arguments);
1764
+ }
1765
+ return newestCiRun;
1766
+ }()
1767
+ };
1768
+ }
1769
+
1770
+ /** A job's change that merges a proposal: `merge:<name>` (content's `mergeChange`). */
1771
+ function isMergeChange(change) {
1772
+ return change.startsWith("merge:");
1773
+ }
1774
+
1775
+ /** `/publish-jobs/:id/merge-prepare`'s answer: the merge's files, from content. */
1776
+ var MergePrepareAnswer = z.object({
1777
+ job: z.object({
1778
+ id: z.string(),
1779
+ step: z["enum"](["prepare", "build", "upload"]).nullable(),
1780
+ base: z.string().nullable(),
1781
+ patches: z.array(z.string()),
1782
+ /*
1783
+ * A merge that changes only content goes live on the live build, and
1784
+ * this tab builds nothing (valbuild/home `docs/hosted-publishing.md`,
1785
+ * step 8). Dropped by an object that did not name it, and the tab then
1786
+ * read a job nobody builds as one it had lost.
1787
+ */
1788
+ contentOnly: z.literal(true).optional()
1789
+ }).nullable(),
1790
+ sourceFiles: z.record(z.string(), z.string().nullable()),
1791
+ /*
1792
+ * The proposal's own build target, when it changed the dependencies. Read
1793
+ * by `parseBuildTarget`, the one reading of a build target there is.
1794
+ */
1795
+ target: z.unknown().optional()
1796
+ });
1797
+
1798
+ /** `/api/val/publish-job-prepare`'s answer, checked: it crossed a network. */
1799
+ var preparedJob = z.object({
1800
+ sourceFiles: z.record(z.string(), z.string().nullable()),
1801
+ binaryFiles: z.record(z.string(), z.string()),
1802
+ binaryFilesUnread: z.array(z.string()),
1803
+ branch: z.string().nullable(),
1804
+ buildable: z["boolean"]().optional()
1805
+ });
1806
+ function parsePreparedJob(body) {
1807
+ var job = parseJob(body, "POST /api/val/publish-job-prepare").job;
1808
+ var parsed = preparedJob.safeParse(body);
1809
+ if (!parsed.success) throw new Error("The server's publish prepare answered with something this Studio cannot read.");
1810
+ var _parsed$data = parsed.data,
1811
+ buildable = _parsed$data.buildable,
1812
+ rest = _objectWithoutProperties(_parsed$data, _excluded);
1813
+ return _objectSpread2(_objectSpread2({
1814
+ job: job
1815
+ }, rest), {}, {
1816
+ buildable: buildable !== null && buildable !== void 0 ? buildable : true
1817
+ });
1818
+ }
1819
+
1820
+ /**
1821
+ * A publish job, as the tab that holds it runs it: prepare, build, upload --
1822
+ * and then it is content's (valbuild/home, docs/app-mode.md, "Publishing is a
1823
+ * queued job"). Content runs verify and the seal, and "Live" arrives on the
1824
+ * websocket, so a tab that closes after its upload costs nothing.
1825
+ *
1826
+ * The tab holds the job by a lease, renewed on a timer while it works. A
1827
+ * renewal answered `false` means the job is no longer this tab's -- its lease
1828
+ * lapsed and its requests went back to the queue, or it was cancelled -- and
1829
+ * the tab stops: another tab, or this one's next job, will build it.
1830
+ *
1831
+ * Every step is reported by name, so a report retried after a lost answer
1832
+ * does nothing twice, and a failure is reported as the step's: content counts
1833
+ * the attempts and, after the last, fails the job with Try again.
1834
+ */
1835
+
1836
+ /** How often the tab renews its lease. Content's job lease is 30 s. */
1837
+ var RENEW_EVERY_MS = 10000;
1838
+ function runStudioJob(_x) {
1839
+ return _runStudioJob.apply(this, arguments);
1840
+ }
1841
+ function _runStudioJob() {
1842
+ _runStudioJob = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(options) {
1843
+ var _options$renewEveryMs;
1844
+ var client, job, tab, onPhase, lost, renewing, lostResult, _options$canBuild, _options$canBuild2, _options$canBuild3, _options$canBuild4, prepared, message, handed, deployed, _message, built, uploaded, _t;
1845
+ return _regenerator().w(function (_context) {
1846
+ while (1) switch (_context.p = _context.n) {
1847
+ case 0:
1848
+ client = options.client, job = options.job, tab = options.tab, onPhase = options.onPhase;
1849
+ lost = false;
1850
+ renewing = setInterval(function () {
1851
+ client.renew(job.id, tab).then(function (renewed) {
1852
+ if (!renewed) lost = true;
1853
+ },
1854
+ // A renewal that did not get through is not a lost job: the lease is
1855
+ // 30 s and the next one may.
1856
+ function () {});
1857
+ }, (_options$renewEveryMs = options.renewEveryMs) !== null && _options$renewEveryMs !== void 0 ? _options$renewEveryMs : RENEW_EVERY_MS);
1858
+ lostResult = {
1859
+ status: "lost",
1860
+ jobId: job.id
1861
+ };
1862
+ _context.p = 1;
1863
+ onPhase({
1864
+ kind: "preparing"
1865
+ });
1866
+ _context.p = 2;
1867
+ _context.n = 3;
1868
+ return client.prepare(job, tab);
1869
+ case 3:
1870
+ prepared = _context.v;
1871
+ _context.n = 6;
1872
+ break;
1873
+ case 4:
1874
+ _context.p = 4;
1875
+ _t = _context.v;
1876
+ /*
1877
+ * 502 is content answering the prepare with a failure, which content
1878
+ * has already counted as an attempt at the step. Anything else never
1879
+ * reached it, so the tab reports it.
1880
+ */
1881
+ message = messageOf$1(_t);
1882
+ if (_t instanceof StudioPublishError && _t.statusCode === 502) {
1883
+ _context.n = 5;
1884
+ break;
1885
+ }
1886
+ _context.n = 5;
1887
+ return client.step(job.id, {
1888
+ tab: tab,
1889
+ step: "prepare",
1890
+ ok: false,
1891
+ message: message
1892
+ })["catch"](function () {
1893
+ return null;
1894
+ });
1895
+ case 5:
1896
+ return _context.a(2, {
1897
+ status: "failed",
1898
+ jobId: job.id,
1899
+ message: message
1900
+ });
1901
+ case 6:
1902
+ if (!(lost || prepared.job === null)) {
1903
+ _context.n = 7;
1904
+ break;
1905
+ }
1906
+ return _context.a(2, lostResult);
1907
+ case 7:
1908
+ if (!(prepared.job.step === null)) {
1909
+ _context.n = 8;
1910
+ break;
1911
+ }
1912
+ return _context.a(2, _objectSpread2({
1913
+ status: "handed-off",
1914
+ jobId: job.id,
1915
+ built: false
1916
+ }, prepared.job.contentOnly ? {
1917
+ contentOnly: true
1918
+ } : {}));
1919
+ case 8:
1920
+ if (!(prepared.job.step !== "build")) {
1921
+ _context.n = 9;
1922
+ break;
1923
+ }
1924
+ return _context.a(2, lostResult);
1925
+ case 9:
1926
+ if (!(options.buildsElsewhere && !((_options$canBuild = (_options$canBuild2 = options.canBuild) === null || _options$canBuild2 === void 0 ? void 0 : _options$canBuild2.call(options)) !== null && _options$canBuild !== void 0 ? _options$canBuild : true))) {
1927
+ _context.n = 10;
1928
+ break;
1929
+ }
1930
+ return _context.a(2, {
1931
+ status: "needs-builder",
1932
+ jobId: job.id
1933
+ });
1934
+ case 10:
1935
+ if (!(!prepared.buildable || !((_options$canBuild3 = (_options$canBuild4 = options.canBuild) === null || _options$canBuild4 === void 0 ? void 0 : _options$canBuild4.call(options)) !== null && _options$canBuild3 !== void 0 ? _options$canBuild3 : true))) {
1936
+ _context.n = 13;
1937
+ break;
1938
+ }
1939
+ onPhase({
1940
+ kind: "handing-off"
1941
+ });
1942
+ _context.n = 11;
1943
+ return client.step(job.id, {
1944
+ tab: tab,
1945
+ step: "build",
1946
+ ok: true,
1947
+ noBuild: true
1948
+ });
1949
+ case 11:
1950
+ handed = _context.v;
1951
+ if (!(lost || handed === null || handed.step !== null)) {
1952
+ _context.n = 12;
1953
+ break;
1954
+ }
1955
+ return _context.a(2, lostResult);
1956
+ case 12:
1957
+ return _context.a(2, {
1958
+ status: "handed-off",
1959
+ jobId: job.id,
1960
+ built: false
1961
+ });
1962
+ case 13:
1963
+ _context.n = 14;
1964
+ return options.deploy(prepared, function (phase) {
1965
+ return onPhase({
1966
+ kind: "deploying",
1967
+ phase: phase
1968
+ });
1969
+ });
1970
+ case 14:
1971
+ deployed = _context.v;
1972
+ if (!lost) {
1973
+ _context.n = 15;
1974
+ break;
1975
+ }
1976
+ return _context.a(2, lostResult);
1977
+ case 15:
1978
+ if (!(deployed.status !== "uploaded")) {
1979
+ _context.n = 17;
1980
+ break;
1981
+ }
1982
+ _message = deployed.status === "failed" ? deployed.message : "The build went further than a job's build should.";
1983
+ /*
1984
+ * With the reason: if the build fails for good, content's failure is
1985
+ * what every Studio shows, and without it that said "build failed 3
1986
+ * times" and nothing else.
1987
+ */
1988
+ _context.n = 16;
1989
+ return client.step(job.id, {
1990
+ tab: tab,
1991
+ step: "build",
1992
+ ok: false,
1993
+ message: _message
1994
+ })["catch"](function () {
1995
+ return null;
1996
+ });
1997
+ case 16:
1998
+ return _context.a(2, {
1999
+ status: "failed",
2000
+ jobId: job.id,
2001
+ message: _message
2002
+ });
2003
+ case 17:
2004
+ onPhase({
2005
+ kind: "handing-off"
2006
+ });
2007
+ _context.n = 18;
2008
+ return client.step(job.id, {
2009
+ tab: tab,
2010
+ step: "build",
2011
+ ok: true,
2012
+ build: deployed.publishId
2013
+ });
2014
+ case 18:
2015
+ built = _context.v;
2016
+ if (!(built === null || built.step !== "upload")) {
2017
+ _context.n = 19;
2018
+ break;
2019
+ }
2020
+ return _context.a(2, lostResult);
2021
+ case 19:
2022
+ _context.n = 20;
2023
+ return client.step(job.id, {
2024
+ tab: tab,
2025
+ step: "upload",
2026
+ ok: true
2027
+ });
2028
+ case 20:
2029
+ uploaded = _context.v;
2030
+ if (!(lost || uploaded === null || uploaded.step !== null)) {
2031
+ _context.n = 21;
2032
+ break;
2033
+ }
2034
+ return _context.a(2, lostResult);
2035
+ case 21:
2036
+ return _context.a(2, {
2037
+ status: "handed-off",
2038
+ jobId: job.id,
2039
+ built: true
2040
+ });
2041
+ case 22:
2042
+ _context.p = 22;
2043
+ clearInterval(renewing);
2044
+ return _context.f(22);
2045
+ case 23:
2046
+ return _context.a(2);
2047
+ }
2048
+ }, _callee, null, [[2, 4], [1,, 22, 23]]);
2049
+ }));
2050
+ return _runStudioJob.apply(this, arguments);
2051
+ }
2052
+ var messageOf$1 = function messageOf(error) {
2053
+ return error instanceof Error ? error.message : String(error);
2054
+ };
2055
+
2056
+ /**
2057
+ * How many times one job is built in a row. Content counts the attempts at a
2058
+ * step and fails the job after its last (`MAX_STEP_ATTEMPTS`, 3), so this is
2059
+ * only a backstop for failures content never heard about.
2060
+ */
2061
+ var MAX_RUNS = 5;
2062
+
2063
+ /**
2064
+ * Run a job until this tab's part of it is over: handed off, lost, or failed
2065
+ * for good.
2066
+ *
2067
+ * A failed step is counted by content, which keeps the job at that step for
2068
+ * the tab to run again -- until its last attempt, when it fails the job.
2069
+ * Whether it is still this tab's is the renewal's answer, so a failure is
2070
+ * followed by one, and a `true` runs it again.
2071
+ */
2072
+ function runJobToEnd(_x2) {
2073
+ return _runJobToEnd.apply(this, arguments);
2074
+ }
2075
+ function _runJobToEnd() {
2076
+ _runJobToEnd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
2077
+ var result, runs, again;
2078
+ return _regenerator().w(function (_context2) {
2079
+ while (1) switch (_context2.n) {
2080
+ case 0:
2081
+ result = {
2082
+ status: "lost",
2083
+ jobId: options.job.id
2084
+ };
2085
+ runs = 0;
2086
+ case 1:
2087
+ if (!(runs < MAX_RUNS)) {
2088
+ _context2.n = 6;
2089
+ break;
2090
+ }
2091
+ _context2.n = 2;
2092
+ return options.run()["catch"](function (error) {
2093
+ return {
2094
+ status: "failed",
2095
+ jobId: options.job.id,
2096
+ message: messageOf$1(error)
2097
+ };
2098
+ });
2099
+ case 2:
2100
+ result = _context2.v;
2101
+ if (!(result.status !== "failed")) {
2102
+ _context2.n = 3;
2103
+ break;
2104
+ }
2105
+ return _context2.a(2, result);
2106
+ case 3:
2107
+ _context2.n = 4;
2108
+ return options.client.renew(options.job.id, options.tab)["catch"](function () {
2109
+ return false;
2110
+ });
2111
+ case 4:
2112
+ again = _context2.v;
2113
+ if (again) {
2114
+ _context2.n = 5;
2115
+ break;
2116
+ }
2117
+ return _context2.a(2, result);
2118
+ case 5:
2119
+ runs++;
2120
+ _context2.n = 1;
2121
+ break;
2122
+ case 6:
2123
+ return _context2.a(2, result);
2124
+ }
2125
+ }, _callee2);
2126
+ }));
2127
+ return _runJobToEnd.apply(this, arguments);
2128
+ }
2129
+
2130
+ /*
2131
+ * Building a proposal's staged files and serving the build at its address:
2132
+ * valbuild/home `docs/hosted-publishing.md`, step 7. The Studio builds one
2133
+ * from its proposals bar, and home's upgrade page builds an upgrade's; each
2134
+ * reaches content its own way, so the client is the caller's.
2135
+ */
2136
+
2137
+ /** A proposal as content answers it, as far as a build reads it. */
2138
+
2139
+ /** The calls a build of a proposal makes. An error carries content's `status`. */
2140
+
2141
+ /** The HTTP status an error carries, if it is an answer at all. */
2142
+ function statusOf(error) {
2143
+ return _typeof(error) === "object" && error !== null && "status" in error && typeof error.status === "number" ? error.status : null;
2144
+ }
2145
+ function messageOf(error) {
2146
+ return error instanceof Error ? error.message : String(error);
2147
+ }
2148
+
2149
+ /** What a build of the proposal came to. */
2150
+
2151
+ /**
2152
+ * Where a build of the proposal is, around the deploy: the deploy's own steps
2153
+ * are the Studio's deploy state (`useStudioDeployState`), and these are the
2154
+ * parts before and after it.
2155
+ *
2156
+ * - `reading`: the proposal's files and the target to build them on.
2157
+ * - `deploying`: the deploy is running; its state says which step.
2158
+ * - `serving`: content is putting the build up at the proposal's address.
2159
+ * - `waiting`: that request did not come back -- a gateway gave up on it --
2160
+ * and content is asked until it says the proposal is built.
2161
+ */
2162
+
2163
+ /**
2164
+ * Files that never go into a build: lockfiles, at any depth. The same list as
2165
+ * content's `NEVER_SHIPPED` (valbuild/home `content/src/val/dependencyFiles.ts`).
2166
+ *
2167
+ * A merge builds from the site's source with the proposal's files over it,
2168
+ * without these (`shippedFiles` there). The proposal's own build has to be
2169
+ * made of the same files, or the two are named differently: a merge then
2170
+ * never finds the proposal's build held, and builds the whole site again --
2171
+ * which is every upgrade, since an upgrade stages a `pnpm-lock.yaml`.
2172
+ */
2173
+ var NEVER_SHIPPED = new Set(["pnpm-lock.yaml", "pnpm-workspace.yaml", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "bun.lock", "bun.lockb"]);
2174
+ function withoutLockfiles(files) {
2175
+ return Object.fromEntries(Object.entries(files).filter(function (_ref) {
2176
+ var _ref2 = _slicedToArray(_ref, 1),
2177
+ path = _ref2[0];
2178
+ return !NEVER_SHIPPED.has(path.slice(path.lastIndexOf("/") + 1));
2179
+ }));
2180
+ }
2181
+
2182
+ /**
2183
+ * Whether serving got no answer from content rather than a refusal: the
2184
+ * connection failed, or a gateway stopped waiting -- Cloudflare's 52x (524 is
2185
+ * "no answer in 100 seconds"), and the 502-504 of anything else in between.
2186
+ * Content goes on with the request either way, so the build may well be
2187
+ * served.
2188
+ */
2189
+ function gatewayGaveUp(error) {
2190
+ // No answer at all: `fetch` rejects with a TypeError when the connection
2191
+ // fails or is cut. Anything else is a failure with words of its own.
2192
+ if (error instanceof TypeError) return true;
2193
+ var status = statusOf(error);
2194
+ if (status === null) return false;
2195
+ return status === 502 || status === 503 || status === 504 || status >= 520 && status <= 527;
2196
+ }
2197
+
2198
+ /** How long, and how often, content is asked whether it served the build. */
2199
+ var SERVE_WAIT_MS = 4 * 60000;
2200
+ var SERVE_POLL_MS = 5000;
2201
+
2202
+ /**
2203
+ * Build the proposal's staged files and serve the build at its address.
2204
+ *
2205
+ * The files and what they are for (`inputs`) come in one answer, so the build
2206
+ * names exactly what it was made of; content refuses it if they were staged
2207
+ * again meanwhile. The tab builds as for a publish and stops once the build is
2208
+ * uploaded -- nothing goes live -- and content hands it to the platform.
2209
+ *
2210
+ * Serving can take longer than a gateway waits for an answer, and content
2211
+ * finishes it all the same. So a gateway that gives up is not a failure: the
2212
+ * proposal is read until it says it is built from these inputs, and served
2213
+ * once more only if it never does.
2214
+ */
2215
+ function buildProposal(_x) {
2216
+ return _buildProposal.apply(this, arguments);
2217
+ }
2218
+ function _buildProposal() {
2219
+ _buildProposal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(deps) {
2220
+ var _deps$now, _deps$sleep, _deps$onStep;
2221
+ var now, sleep, step, read, _read, files, staged, inputs, target, asked, built, serve, servedNow, builtOf, since, served, _t2, _t3, _t4, _t5, _t6, _t7;
2222
+ return _regenerator().w(function (_context3) {
2223
+ while (1) switch (_context3.p = _context3.n) {
2224
+ case 0:
2225
+ now = (_deps$now = deps.now) !== null && _deps$now !== void 0 ? _deps$now : Date.now;
2226
+ sleep = (_deps$sleep = deps.sleep) !== null && _deps$sleep !== void 0 ? _deps$sleep : function (ms) {
2227
+ return new Promise(function (resolve) {
2228
+ return setTimeout(resolve, ms);
2229
+ });
2230
+ };
2231
+ step = (_deps$onStep = deps.onStep) !== null && _deps$onStep !== void 0 ? _deps$onStep : function () {};
2232
+ if (deps.canBuildHere()) {
2233
+ _context3.n = 1;
2234
+ break;
2235
+ }
2236
+ return _context3.a(2, {
2237
+ status: "failed",
2238
+ message: "This browser cannot build in this tab. Open the proposal in Chrome, Edge or Firefox and build it there"
2239
+ });
2240
+ case 1:
2241
+ step({
2242
+ kind: "reading"
2243
+ });
2244
+ _context3.p = 2;
2245
+ _context3.n = 3;
2246
+ return deps.client.files(deps.name);
2247
+ case 3:
2248
+ read = _context3.v;
2249
+ _context3.n = 5;
2250
+ break;
2251
+ case 4:
2252
+ _context3.p = 4;
2253
+ _t2 = _context3.v;
2254
+ return _context3.a(2, {
2255
+ status: "failed",
2256
+ message: messageOf(_t2)
2257
+ });
2258
+ case 5:
2259
+ _read = read, files = _read.files, staged = _read.staged;
2260
+ if (!(staged.inputs === null)) {
2261
+ _context3.n = 6;
2262
+ break;
2263
+ }
2264
+ return _context3.a(2, {
2265
+ status: "nothing-staged"
2266
+ });
2267
+ case 6:
2268
+ if (staged.buildRequired) {
2269
+ _context3.n = 7;
2270
+ break;
2271
+ }
2272
+ return _context3.a(2, {
2273
+ status: "already-built",
2274
+ hash: null
2275
+ });
2276
+ case 7:
2277
+ inputs = staged.inputs;
2278
+ _context3.p = 8;
2279
+ _context3.n = 9;
2280
+ return deps.client.buildTarget(deps.name);
2281
+ case 9:
2282
+ asked = _context3.v;
2283
+ target = asked.layer === "own" ? asked.target : undefined;
2284
+ _context3.n = 11;
2285
+ break;
2286
+ case 10:
2287
+ _context3.p = 10;
2288
+ _t3 = _context3.v;
2289
+ if (!(statusOf(_t3) !== 404)) {
2290
+ _context3.n = 11;
2291
+ break;
2292
+ }
2293
+ return _context3.a(2, {
2294
+ status: "failed",
2295
+ message: messageOf(_t3)
2296
+ });
2297
+ case 11:
2298
+ step({
2299
+ kind: "deploying"
2300
+ });
2301
+ _context3.n = 12;
2302
+ return deps.deploy(withoutLockfiles(files), target);
2303
+ case 12:
2304
+ built = _context3.v;
2305
+ if (!(built.status !== "uploaded")) {
2306
+ _context3.n = 13;
2307
+ break;
2308
+ }
2309
+ return _context3.a(2, {
2310
+ status: "failed",
2311
+ message: built.status === "failed" ? built.message : "The build went live instead of stopping once uploaded."
2312
+ });
2313
+ case 13:
2314
+ serve = /*#__PURE__*/function () {
2315
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2316
+ return _regenerator().w(function (_context) {
2317
+ while (1) switch (_context.n) {
2318
+ case 0:
2319
+ step({
2320
+ kind: "serving",
2321
+ since: now()
2322
+ });
2323
+ return _context.a(2, deps.client.serveBuild(deps.name, {
2324
+ publishId: built.publishId,
2325
+ inputs: inputs
2326
+ }));
2327
+ }
2328
+ }, _callee);
2329
+ }));
2330
+ return function serve() {
2331
+ return _ref3.apply(this, arguments);
2332
+ };
2333
+ }();
2334
+ servedNow = /*#__PURE__*/function () {
2335
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
2336
+ var _proposal$staged, _proposal$built, proposal;
2337
+ return _regenerator().w(function (_context2) {
2338
+ while (1) switch (_context2.p = _context2.n) {
2339
+ case 0:
2340
+ _context2.p = 0;
2341
+ _context2.n = 1;
2342
+ return deps.client.get(deps.name);
2343
+ case 1:
2344
+ proposal = _context2.v;
2345
+ return _context2.a(2, ((_proposal$staged = proposal.staged) === null || _proposal$staged === void 0 ? void 0 : _proposal$staged.inputs) === inputs && proposal.staged.buildRequired === false && (_proposal$built = proposal.built) !== null && _proposal$built !== void 0 && _proposal$built.hash ? proposal : null);
2346
+ case 2:
2347
+ _context2.p = 2;
2348
+ _context2.v;
2349
+ return _context2.a(2, null);
2350
+ }
2351
+ }, _callee2, null, [[0, 2]]);
2352
+ }));
2353
+ return function servedNow() {
2354
+ return _ref4.apply(this, arguments);
2355
+ };
2356
+ }();
2357
+ builtOf = function builtOf(proposal) {
2358
+ var _proposal$built$hash, _proposal$built2;
2359
+ return {
2360
+ status: "built",
2361
+ hash: (_proposal$built$hash = (_proposal$built2 = proposal.built) === null || _proposal$built2 === void 0 ? void 0 : _proposal$built2.hash) !== null && _proposal$built$hash !== void 0 ? _proposal$built$hash : null,
2362
+ proposal: proposal
2363
+ };
2364
+ };
2365
+ _context3.p = 14;
2366
+ _t4 = builtOf;
2367
+ _context3.n = 15;
2368
+ return serve();
2369
+ case 15:
2370
+ return _context3.a(2, _t4(_context3.v));
2371
+ case 16:
2372
+ _context3.p = 16;
2373
+ _t5 = _context3.v;
2374
+ if (gatewayGaveUp(_t5)) {
2375
+ _context3.n = 17;
2376
+ break;
2377
+ }
2378
+ return _context3.a(2, {
2379
+ status: "failed",
2380
+ message: messageOf(_t5)
2381
+ });
2382
+ case 17:
2383
+ since = now();
2384
+ step({
2385
+ kind: "waiting",
2386
+ since: since
2387
+ });
2388
+ case 18:
2389
+ if (!(now() - since < SERVE_WAIT_MS)) {
2390
+ _context3.n = 22;
2391
+ break;
2392
+ }
2393
+ _context3.n = 19;
2394
+ return sleep(SERVE_POLL_MS);
2395
+ case 19:
2396
+ _context3.n = 20;
2397
+ return servedNow();
2398
+ case 20:
2399
+ served = _context3.v;
2400
+ if (!(served !== null)) {
2401
+ _context3.n = 21;
2402
+ break;
2403
+ }
2404
+ return _context3.a(2, builtOf(served));
2405
+ case 21:
2406
+ _context3.n = 18;
2407
+ break;
2408
+ case 22:
2409
+ _context3.p = 22;
2410
+ _t6 = builtOf;
2411
+ _context3.n = 23;
2412
+ return serve();
2413
+ case 23:
2414
+ return _context3.a(2, _t6(_context3.v));
2415
+ case 24:
2416
+ _context3.p = 24;
2417
+ _t7 = _context3.v;
2418
+ return _context3.a(2, {
2419
+ status: "failed",
2420
+ message: messageOf(_t7)
2421
+ });
2422
+ }
2423
+ }, _callee3, null, [[22, 24], [14, 16], [8, 10], [2, 4]]);
2424
+ }));
2425
+ return _buildProposal.apply(this, arguments);
2426
+ }
2427
+
2428
+ export { MergePrepareAnswer, RENEW_EVERY_MS, SERVE_POLL_MS, SERVE_WAIT_MS, STUDIO_OUT_OF_DATE, STUDIO_OUT_OF_DATE_MESSAGE, StudioPublishError, StudioUploadError, buildProposal, callJson, carriedInto, createStudioJobClient, createStudioPublishClient, isExpiredSlot, isMergeChange, isTransientPublishError, layerMoved, loadedLayer, markStudioOutOfDate, onPublishRefusal, publishApiOf, readLiveLayer, rememberLoadedLayer, resetLoadedLayerForTests, runJobToEnd, runStudioDeploy, runStudioJob, runStudioPublish, siteMovedSinceLoad, splitBinaryFiles, studioOutOfDateRefusals, subscribeStudioOutOfDate, withCommittedFiles, withoutLockfiles };