@valbuild/server 0.151.0 → 0.152.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
- package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
- package/browser/dist/valbuild-server-browser.esm.js +2 -2
- package/dist/{ValRouter-ca467c83.cjs.dev.js → ValRouter-541c76f5.cjs.dev.js} +228 -374
- package/dist/{ValRouter-2827d620.esm.js → ValRouter-b4125d35.esm.js} +229 -375
- package/dist/{ValRouter-d43e0a33.cjs.prod.js → ValRouter-e1e0101b.cjs.prod.js} +228 -374
- package/dist/{ValRouterCore-eb1f53f5.cjs.prod.js → ValRouterCore-0c0359fe.cjs.prod.js} +48 -5
- package/dist/{ValRouterCore-0921fe9c.cjs.dev.js → ValRouterCore-bd3e9b6c.cjs.dev.js} +48 -5
- package/dist/{ValRouterCore-6c29fb75.esm.js → ValRouterCore-eea19e82.esm.js} +48 -5
- package/dist/declarations/src/ValOps.d.ts +20 -2
- package/dist/declarations/src/ValOpsHttp.d.ts +4 -39
- package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +1 -1
- package/dist/{inTabFetch-35cf5698.cjs.prod.js → inTabFetch-5caf8250.cjs.prod.js} +1 -1
- package/dist/{inTabFetch-49db354b.cjs.dev.js → inTabFetch-6d54acd8.cjs.dev.js} +1 -1
- package/dist/{inTabFetch-0cd45721.esm.js → inTabFetch-de7cf596.esm.js} +1 -1
- package/dist/{publishKit-3afe011d.cjs.dev.js → publishKit-42f08a69.cjs.dev.js} +2 -2
- package/dist/{publishKit-24e1406b.cjs.prod.js → publishKit-9600ecef.cjs.prod.js} +2 -2
- package/dist/{publishKit-d2e3e44d.esm.js → publishKit-c13ba76f.esm.js} +3 -3
- package/dist/valbuild-server.cjs.dev.js +2 -2
- package/dist/valbuild-server.cjs.prod.js +2 -2
- package/dist/valbuild-server.esm.js +4 -4
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
- package/internal/dist/valbuild-server-internal.cjs.dev.js +2 -2
- package/internal/dist/valbuild-server-internal.cjs.prod.js +2 -2
- package/internal/dist/valbuild-server-internal.esm.js +2 -2
- package/package.json +4 -4
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@valbuild/core');
|
|
4
4
|
var server = require('@valbuild/ui/server');
|
|
5
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
5
|
+
var ValRouterCore = require('./ValRouterCore-bd3e9b6c.cjs.dev.js');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var ts = require('typescript');
|
|
8
8
|
var z = require('zod');
|
|
@@ -619,7 +619,7 @@ function jsonValuesRecordKeys(source) {
|
|
|
619
619
|
* as written. An error for anything that is not a literal.
|
|
620
620
|
*
|
|
621
621
|
* What a staging records for a module (`stagedModuleSources`): without the
|
|
622
|
-
* markers, an entry the
|
|
622
|
+
* markers, an entry the assistant added to a record was in the module's code
|
|
623
623
|
* and not in its Source, and an edit into it was undone.
|
|
624
624
|
*/
|
|
625
625
|
function evaluateModuleSource(source) {
|
|
@@ -2205,7 +2205,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
|
|
|
2205
2205
|
* as a bundler does.
|
|
2206
2206
|
*/
|
|
2207
2207
|
function loadTypeScriptKit() {
|
|
2208
|
-
return Promise.resolve().then(function () { return require('./publishKit-
|
|
2208
|
+
return Promise.resolve().then(function () { return require('./publishKit-42f08a69.cjs.dev.js'); });
|
|
2209
2209
|
}
|
|
2210
2210
|
|
|
2211
2211
|
/** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
|
|
@@ -4895,146 +4895,6 @@ function sameJson(a, b) {
|
|
|
4895
4895
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
4896
4896
|
}
|
|
4897
4897
|
|
|
4898
|
-
/**
|
|
4899
|
-
* A module's file with a patch written into it: what a save does to a
|
|
4900
|
-
* `.val.ts`, for one file and one patch, with nothing pending around it.
|
|
4901
|
-
*
|
|
4902
|
-
* The design tab's `create_patch` (valbuild/home `docs/design-tab.md`): there
|
|
4903
|
-
* the assistant changes a proposal's code, and content it writes goes into the
|
|
4904
|
-
* module's file and is staged with the code -- so a field it just added can
|
|
4905
|
-
* be filled in the same change, and is built and rendered with it.
|
|
4906
|
-
*
|
|
4907
|
-
* Only the module's own file. A `.jsonValues()` entry lives in a `*.val.json`
|
|
4908
|
-
* of its own, which a save routes to op by op (`ValOps.prepare`); a patch that
|
|
4909
|
-
* reaches into one fails here, and the message says to write that file.
|
|
4910
|
-
*/
|
|
4911
|
-
async function patchModuleText(text, patch$1) {
|
|
4912
|
-
// The TypeScript compiler, loaded when a patch asks for it, as a save loads
|
|
4913
|
-
// it: see `publishKit.ts`.
|
|
4914
|
-
const {
|
|
4915
|
-
tsOps,
|
|
4916
|
-
parseValFile
|
|
4917
|
-
} = await Promise.resolve().then(function () { return require('./publishKit-3afe011d.cjs.dev.js'); });
|
|
4918
|
-
const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
|
|
4919
|
-
if (fp.result.isErr(applied)) {
|
|
4920
|
-
const reason = messagesOf(applied.error).join(" ");
|
|
4921
|
-
return fp.result.err(text.includes(".jsonValues(") ? `${reason} This module keeps entries in .val.json files of their own: change an entry by writing its file with write_files.` : reason);
|
|
4922
|
-
}
|
|
4923
|
-
const sourceFile = applied.value;
|
|
4924
|
-
// As a save writes it: https://github.com/microsoft/TypeScript/issues/36174
|
|
4925
|
-
return fp.result.ok(unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u")));
|
|
4926
|
-
}
|
|
4927
|
-
|
|
4928
|
-
/**
|
|
4929
|
-
* A patch written into a module's files: {@link patchModuleText}, and an op
|
|
4930
|
-
* that reaches INTO a `.jsonValues()` entry written into that entry's own
|
|
4931
|
-
* `*.val.json`, as a save routes it (`ValOps.prepare`).
|
|
4932
|
-
*
|
|
4933
|
-
* The design tab's `create_patch` used to refuse those, and the assistant
|
|
4934
|
-
* rewrote the whole entry file to change one field -- over whatever had been
|
|
4935
|
-
* saved into it since it read it.
|
|
4936
|
-
*
|
|
4937
|
-
* Only into an entry that is already there. Adding, replacing or removing a
|
|
4938
|
-
* whole entry is a key in the `.val.ts` and a file beside it, which a save
|
|
4939
|
-
* writes from the record's schema; here that is still `write_files`, and the
|
|
4940
|
-
* error says so.
|
|
4941
|
-
*
|
|
4942
|
-
* `readFile` answers a file by its path without a leading slash: the
|
|
4943
|
-
* proposal's copy, else the build's, `null` for one the proposal deleted.
|
|
4944
|
-
* `moduleText` is `null` when no op is the module file's own; `entries` is
|
|
4945
|
-
* each entry file written, by the same kind of path.
|
|
4946
|
-
*/
|
|
4947
|
-
async function patchModuleFiles(moduleFilePath, text, readFile, patch$1) {
|
|
4948
|
-
const entryFiles = await jsonEntryFilesOf(moduleFilePath, text);
|
|
4949
|
-
const textOps = [];
|
|
4950
|
-
const entryOps = new Map();
|
|
4951
|
-
for (const op of patch$1) {
|
|
4952
|
-
const key = op.path[0];
|
|
4953
|
-
// The record itself, or one of its entries as a whole -- a new one too,
|
|
4954
|
-
// which would otherwise be written into the record's text inline.
|
|
4955
|
-
if (entryFiles.size > 0 && op.path.length <= 1) {
|
|
4956
|
-
return fp.result.err(`${key !== undefined ? `"${key}" is a whole entry` : "This is the whole record"} of a .jsonValues() record: add, replace or remove an entry by writing ${moduleFilePath} and the entry's .val.json with write_files.`);
|
|
4957
|
-
}
|
|
4958
|
-
const entryFile = key !== undefined ? entryFiles.get(key) : undefined;
|
|
4959
|
-
if (key === undefined || entryFile === undefined) {
|
|
4960
|
-
textOps.push(op);
|
|
4961
|
-
continue;
|
|
4962
|
-
}
|
|
4963
|
-
if (op.op === "file") {
|
|
4964
|
-
return fp.result.err(`A file in a .jsonValues() entry is uploaded by the Studio, not written here.`);
|
|
4965
|
-
}
|
|
4966
|
-
if ((op.op === "move" || op.op === "copy") && op.from[0] !== key) {
|
|
4967
|
-
return fp.result.err(`An op from one .jsonValues() entry into another is not written here: write the entries' .val.json files with write_files.`);
|
|
4968
|
-
}
|
|
4969
|
-
const rebased = internal.rebaseContentOp(op, 1);
|
|
4970
|
-
if (fp.result.isErr(rebased)) return fp.result.err(rebased.error.message);
|
|
4971
|
-
entryOps.set(entryFile, [...(entryOps.get(entryFile) ?? []), rebased.value]);
|
|
4972
|
-
}
|
|
4973
|
-
let moduleText = null;
|
|
4974
|
-
if (textOps.length > 0) {
|
|
4975
|
-
const patched = await patchModuleText(text, textOps);
|
|
4976
|
-
if (fp.result.isErr(patched)) return patched;
|
|
4977
|
-
moduleText = patched.value;
|
|
4978
|
-
}
|
|
4979
|
-
const entries = {};
|
|
4980
|
-
for (const [entryFile, ops] of entryOps) {
|
|
4981
|
-
const raw = readFile(entryFile);
|
|
4982
|
-
if (raw === null || raw === undefined) {
|
|
4983
|
-
return fp.result.err(`${entryFile} is ${raw === null ? "deleted in this proposal" : "not in this proposal or on the site"}.`);
|
|
4984
|
-
}
|
|
4985
|
-
let content;
|
|
4986
|
-
try {
|
|
4987
|
-
content = JSON.parse(raw);
|
|
4988
|
-
} catch {
|
|
4989
|
-
return fp.result.err(`${entryFile} is not JSON.`);
|
|
4990
|
-
}
|
|
4991
|
-
const applied = patch.applyPatch(patch.deepClone(content), new patch.JSONOps(), ops);
|
|
4992
|
-
if (fp.result.isErr(applied)) {
|
|
4993
|
-
return fp.result.err(`${entryFile}: ${messagesOf(applied.error).join(" ")}`);
|
|
4994
|
-
}
|
|
4995
|
-
entries[entryFile] = applied.value;
|
|
4996
|
-
}
|
|
4997
|
-
return fp.result.ok({
|
|
4998
|
-
moduleText,
|
|
4999
|
-
entries
|
|
5000
|
-
});
|
|
5001
|
-
}
|
|
5002
|
-
|
|
5003
|
-
/**
|
|
5004
|
-
* Each `.jsonValues()` entry's file, by key, without a leading slash: from the
|
|
5005
|
-
* `c.json(() => import("..."))` thunks in the module's text. Empty for a
|
|
5006
|
-
* module that has none, or whose text cannot be read that way.
|
|
5007
|
-
*/
|
|
5008
|
-
async function jsonEntryFilesOf(moduleFilePath, text) {
|
|
5009
|
-
const files = new Map();
|
|
5010
|
-
if (!text.includes(".jsonValues(")) return files;
|
|
5011
|
-
const {
|
|
5012
|
-
parseValFile,
|
|
5013
|
-
analyzeValModule,
|
|
5014
|
-
analyzeJsonValuesEntries
|
|
5015
|
-
} = await Promise.resolve().then(function () { return require('./publishKit-3afe011d.cjs.dev.js'); });
|
|
5016
|
-
try {
|
|
5017
|
-
const analysis = analyzeValModule(parseValFile(text));
|
|
5018
|
-
if (fp.result.isErr(analysis)) return files;
|
|
5019
|
-
for (const [key, entry] of analyzeJsonValuesEntries(analysis.value.source)) {
|
|
5020
|
-
files.set(key, ValRouterCore.resolveExistingJsonPath(moduleFilePath, entry.importPath).replace(/^\/+/, ""));
|
|
5021
|
-
}
|
|
5022
|
-
} catch {
|
|
5023
|
-
// No `c.define` (`analyzeValModule` throws): no entries.
|
|
5024
|
-
}
|
|
5025
|
-
return files;
|
|
5026
|
-
}
|
|
5027
|
-
|
|
5028
|
-
/**
|
|
5029
|
-
* A patch error, or a tree of syntax errors, as sentences. Walked here rather
|
|
5030
|
-
* than with `syntax.ts`'s `flattenErrors`, which would bring the compiler in
|
|
5031
|
-
* with this module.
|
|
5032
|
-
*/
|
|
5033
|
-
|
|
5034
|
-
function messagesOf(error) {
|
|
5035
|
-
return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
|
|
5036
|
-
}
|
|
5037
|
-
|
|
5038
4898
|
/**
|
|
5039
4899
|
* The Source each staged module file declares, read from its text: what a
|
|
5040
4900
|
* staging sends content beside the files (`POST /proposals/:name/files`,
|
|
@@ -5042,15 +4902,15 @@ function messagesOf(error) {
|
|
|
5042
4902
|
*
|
|
5043
4903
|
* A proposal's address serves a module's Source from what the proposal has
|
|
5044
4904
|
* SAVED, over the site's, over the build -- never from the text. A save writes
|
|
5045
|
-
* both, so they agree. A staging wrote only the text, so after the
|
|
5046
|
-
*
|
|
4905
|
+
* both, so they agree. A staging wrote only the text, so after the assistant
|
|
4906
|
+
* added a button to a module, its text and its build had
|
|
5047
4907
|
* the button and the Source the server served and saved did not. The Studio,
|
|
5048
4908
|
* lined up with that Source, could not apply an edit into the new button: the
|
|
5049
4909
|
* canvas showed it, and then it was gone.
|
|
5050
4910
|
*
|
|
5051
4911
|
* Only what can be read without running anything: a `c.define(...)` whose
|
|
5052
4912
|
* Source is a literal, a `.jsonValues()` record's entries as the markers its
|
|
5053
|
-
* stored Source holds (`evaluateModuleSource`) -- so an entry the
|
|
4913
|
+
* stored Source holds (`evaluateModuleSource`) -- so an entry the assistant
|
|
5054
4914
|
* adds is one the proposal has. Anything else -- a Source built by code, a
|
|
5055
4915
|
* file of shared schemas -- is left out, and content keeps the Source it has
|
|
5056
4916
|
* for it, as before this existed.
|
|
@@ -5066,7 +4926,7 @@ async function stagedModuleSources(files) {
|
|
|
5066
4926
|
parseValFile,
|
|
5067
4927
|
analyzeValModule,
|
|
5068
4928
|
evaluateModuleSource
|
|
5069
|
-
} = await Promise.resolve().then(function () { return require('./publishKit-
|
|
4929
|
+
} = await Promise.resolve().then(function () { return require('./publishKit-42f08a69.cjs.dev.js'); });
|
|
5070
4930
|
const sources = {};
|
|
5071
4931
|
for (const {
|
|
5072
4932
|
path,
|
|
@@ -5303,6 +5163,126 @@ function createHttpSketchpadStore(options) {
|
|
|
5303
5163
|
};
|
|
5304
5164
|
}
|
|
5305
5165
|
|
|
5166
|
+
/**
|
|
5167
|
+
* What to tell a person when the content service did not do what was asked.
|
|
5168
|
+
*
|
|
5169
|
+
* Written because the old sentences guessed, and guessed wrong. The patches
|
|
5170
|
+
* request answered "It is most likely due to a network issue. Check your
|
|
5171
|
+
* network connection" for ANY non-2xx answer -- including a 500 from a content
|
|
5172
|
+
* service whose database was missing a column, while the editor's network was
|
|
5173
|
+
* fine. A status code is an answer, and an answer means the network worked.
|
|
5174
|
+
*
|
|
5175
|
+
* So there are two shapes and they say different things:
|
|
5176
|
+
*
|
|
5177
|
+
* - **The service answered** with an error (`status`). It is named, the
|
|
5178
|
+
* sentence says it answered with an error or refused, and the status line
|
|
5179
|
+
* and the service's own words go in `details` for whoever has to report it.
|
|
5180
|
+
* - **The service could not be reached** (`unreachable`: `fetch` threw). That
|
|
5181
|
+
* IS a connection failure -- but between this site's server and the
|
|
5182
|
+
* service, not the editor's: the editor reached this server, or nothing
|
|
5183
|
+
* would have asked. So it never says "your connection" either.
|
|
5184
|
+
*
|
|
5185
|
+
* `retryable` is what decides whether a caller offers Try again: a 5xx, a
|
|
5186
|
+
* timeout or a service that could not be reached may well work the next time;
|
|
5187
|
+
* a 4xx is the same refusal again, and a button that leads to the same error
|
|
5188
|
+
* is worse than none.
|
|
5189
|
+
*/
|
|
5190
|
+
|
|
5191
|
+
/** Long enough for a database error, short enough for a dialog. */
|
|
5192
|
+
const MAX_BODY_LENGTH = 500;
|
|
5193
|
+
|
|
5194
|
+
/**
|
|
5195
|
+
* The content service, by a name a person would recognise.
|
|
5196
|
+
*
|
|
5197
|
+
* `content.val.build` is Val Build. Anything else -- a self-hosted engine, a
|
|
5198
|
+
* staging host, the e2e mock -- is named by its host, so the person can tell
|
|
5199
|
+
* WHICH service failed rather than being told "the server", which in a page
|
|
5200
|
+
* that is itself a server says nothing.
|
|
5201
|
+
*/
|
|
5202
|
+
function contentServiceName(contentUrl) {
|
|
5203
|
+
let host;
|
|
5204
|
+
try {
|
|
5205
|
+
host = new URL(contentUrl).host;
|
|
5206
|
+
} catch {
|
|
5207
|
+
return "the content service";
|
|
5208
|
+
}
|
|
5209
|
+
if (host === "val.build" || host.endsWith(".val.build")) {
|
|
5210
|
+
return "Val Build";
|
|
5211
|
+
}
|
|
5212
|
+
return `the content service at ${host}`;
|
|
5213
|
+
}
|
|
5214
|
+
|
|
5215
|
+
/**
|
|
5216
|
+
* The service answered `status`.
|
|
5217
|
+
*
|
|
5218
|
+
* `what` completes "could not ...": "load your changes", "save your change".
|
|
5219
|
+
* `body` is the raw response text; a JSON body is read the way the rest of
|
|
5220
|
+
* `ValOpsHttp` reads one, so `home`'s `{ message: "Internal Server Error",
|
|
5221
|
+
* details: "<the real cause>" }` keeps the real cause.
|
|
5222
|
+
*/
|
|
5223
|
+
function contentServiceAnswered(service, what, response) {
|
|
5224
|
+
const retryable = response.status >= 500 || response.status === 408 || response.status === 429;
|
|
5225
|
+
const Service = capitalize(service);
|
|
5226
|
+
const message = retryable ? `${Service} answered with an error, so Val could not ${what}.` : `${Service} refused to ${what}.`;
|
|
5227
|
+
const statusLine = `HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ""} from ${service}`;
|
|
5228
|
+
const said = bodyText(response.body);
|
|
5229
|
+
return {
|
|
5230
|
+
message,
|
|
5231
|
+
details: said === null ? statusLine : `${statusLine}: ${said}`,
|
|
5232
|
+
retryable
|
|
5233
|
+
};
|
|
5234
|
+
}
|
|
5235
|
+
|
|
5236
|
+
/** `fetch` threw: the service was never heard from. */
|
|
5237
|
+
function contentServiceUnreachable(service, what, error) {
|
|
5238
|
+
return {
|
|
5239
|
+
message: `${capitalize(service)} could not be reached from this site's server, so Val could not ${what}.`,
|
|
5240
|
+
details: errorText(error),
|
|
5241
|
+
retryable: true
|
|
5242
|
+
};
|
|
5243
|
+
}
|
|
5244
|
+
function bodyText(body) {
|
|
5245
|
+
const trimmed = body.trim();
|
|
5246
|
+
if (trimmed === "") return null;
|
|
5247
|
+
let text = trimmed;
|
|
5248
|
+
try {
|
|
5249
|
+
const json = JSON.parse(trimmed);
|
|
5250
|
+
text = internal.getErrorMessageFromUnknownJson(json, trimmed);
|
|
5251
|
+
} catch {
|
|
5252
|
+
// Not JSON: the text is what the service said.
|
|
5253
|
+
}
|
|
5254
|
+
return text.length <= MAX_BODY_LENGTH ? text : `${text.slice(0, MAX_BODY_LENGTH)}…`;
|
|
5255
|
+
}
|
|
5256
|
+
|
|
5257
|
+
/**
|
|
5258
|
+
* The reason a `fetch` threw, with its cause.
|
|
5259
|
+
*
|
|
5260
|
+
* Node's `fetch` throws `TypeError: fetch failed` and hides what failed in
|
|
5261
|
+
* `cause` (`ECONNREFUSED`, a DNS miss, a certificate), which is the half
|
|
5262
|
+
* support needs.
|
|
5263
|
+
*/
|
|
5264
|
+
function errorText(error) {
|
|
5265
|
+
if (!(error instanceof Error)) {
|
|
5266
|
+
return String(error);
|
|
5267
|
+
}
|
|
5268
|
+
const cause = error.cause;
|
|
5269
|
+
if (cause instanceof Error && cause.message !== error.message) {
|
|
5270
|
+
return `${error.message}: ${cause.message}`;
|
|
5271
|
+
}
|
|
5272
|
+
return error.message;
|
|
5273
|
+
}
|
|
5274
|
+
function capitalize(text) {
|
|
5275
|
+
return text.length === 0 ? text : text[0].toUpperCase() + text.slice(1);
|
|
5276
|
+
}
|
|
5277
|
+
|
|
5278
|
+
/**
|
|
5279
|
+
* One string, for the error shapes that carry only a `message`: the sentence
|
|
5280
|
+
* first, the evidence after it in brackets.
|
|
5281
|
+
*/
|
|
5282
|
+
function contentServiceFailureText(failure) {
|
|
5283
|
+
return `${failure.message} (${failure.details})`;
|
|
5284
|
+
}
|
|
5285
|
+
|
|
5306
5286
|
const textEncoder$2 = new TextEncoder();
|
|
5307
5287
|
|
|
5308
5288
|
/** The body of the content API's 403 for a write the project's plan refuses. */
|
|
@@ -5310,13 +5290,6 @@ const PlanRefusedBody = z.z.object({
|
|
|
5310
5290
|
error: internal.PlanRefusalError
|
|
5311
5291
|
});
|
|
5312
5292
|
|
|
5313
|
-
/** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
|
|
5314
|
-
const PatchFileBody = z.z.object({
|
|
5315
|
-
moduleFilePath: z.z.string().regex(/^\/.+\.val\.(ts|js)$/),
|
|
5316
|
-
patch: internal.Patch,
|
|
5317
|
-
message: z.z.string().max(500).optional()
|
|
5318
|
-
});
|
|
5319
|
-
|
|
5320
5293
|
/** A staging's body, as `write_files` sends it. */
|
|
5321
5294
|
const StageFilesBody = z.z.object({
|
|
5322
5295
|
files: z.z.record(z.z.string(), z.z.string().nullable())
|
|
@@ -5345,11 +5318,6 @@ async function withStagedModuleSources(body) {
|
|
|
5345
5318
|
modules
|
|
5346
5319
|
});
|
|
5347
5320
|
}
|
|
5348
|
-
|
|
5349
|
-
/** What `patchFileInProposal` reads of content's answer for a proposal's files. */
|
|
5350
|
-
const ProposalFilesRead = z.z.object({
|
|
5351
|
-
files: z.z.record(z.z.string(), z.z.string().nullable())
|
|
5352
|
-
});
|
|
5353
5321
|
const PatchId = z.z.string().refine(s => !!s); // TODO: validate
|
|
5354
5322
|
const CommitSha = z.z.string().refine(s => !!s); // TODO: validate
|
|
5355
5323
|
z.z.string().refine(s => !!s); // TODO: validate
|
|
@@ -6275,38 +6243,15 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6275
6243
|
};
|
|
6276
6244
|
}
|
|
6277
6245
|
|
|
6278
|
-
/**
|
|
6279
|
-
* The writes the SITE's server may make to a proposal's files: what the
|
|
6280
|
-
* design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
|
|
6281
|
-
* code, build it, and report its typecheck. The tab is served by the site's
|
|
6282
|
-
* build so that a build the assistant breaks in the proposal cannot take
|
|
6283
|
-
* down the tools it would fix it with; at the proposal's address those
|
|
6284
|
-
* tools run on the proposal's own code.
|
|
6285
|
-
*
|
|
6286
|
-
* The typecheck too, though it blocks the proposal's Publish (adept.md,
|
|
6287
|
-
* decision 20): it is the proposal's staged files checked against the
|
|
6288
|
-
* site's, the same program from either address, and the content service
|
|
6289
|
-
* keeps it only for the inputs it was made from. Without it the tab's
|
|
6290
|
-
* Types check, and the assistant's `typecheck`, had nothing to show.
|
|
6291
|
-
*
|
|
6292
|
-
* And a quick preview: the browser half of a build of the staged files,
|
|
6293
|
-
* which Val Build makes and nothing serves.
|
|
6294
|
-
*
|
|
6295
|
-
* The rest stay the proposal's own: Update from the site and the lockfile
|
|
6296
|
-
* are answered from the proposal's build and schemas, and bringing back a
|
|
6297
|
-
* point's code is the Studio at its address finishing a restore.
|
|
6298
|
-
*/
|
|
6299
|
-
static SITE_MAY_WRITE = new Set(["files", "build", "quick-preview", "typecheck"]);
|
|
6300
|
-
|
|
6301
6246
|
/**
|
|
6302
6247
|
* Whether this server may make a write to a proposal's files: the
|
|
6303
|
-
* proposal's own server,
|
|
6304
|
-
*
|
|
6305
|
-
*
|
|
6248
|
+
* proposal's own server, to its own files, and no other. The site's server
|
|
6249
|
+
* makes none -- code is changed in the proposal's own Studio, in code mode
|
|
6250
|
+
* -- and a proposal's address none to another proposal. Either way the
|
|
6251
|
+
* site's own files change only when a proposal is merged.
|
|
6306
6252
|
*/
|
|
6307
6253
|
mayWriteFiles(write) {
|
|
6308
|
-
|
|
6309
|
-
return ValOpsHttp.SITE_MAY_WRITE.has(write.write);
|
|
6254
|
+
return this.proposal !== null && write.name === this.proposal.name;
|
|
6310
6255
|
}
|
|
6311
6256
|
|
|
6312
6257
|
/**
|
|
@@ -6333,17 +6278,13 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6333
6278
|
return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
|
|
6334
6279
|
}
|
|
6335
6280
|
async proposalsApi(path, init, profileId) {
|
|
6336
|
-
var _exec, _exec2, _exec3, _exec4
|
|
6281
|
+
var _exec, _exec2, _exec3, _exec4;
|
|
6337
6282
|
const json = "application/json";
|
|
6338
6283
|
const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
|
|
6339
6284
|
if (updating !== undefined && init.method === "POST") {
|
|
6340
6285
|
return this.updateContentFromSite(updating, init.body, profileId);
|
|
6341
6286
|
}
|
|
6342
|
-
const
|
|
6343
|
-
if (patching !== undefined && init.method === "POST") {
|
|
6344
|
-
return this.patchFileInProposal(patching, init.body, profileId);
|
|
6345
|
-
}
|
|
6346
|
-
const withCode = (_exec3 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
|
|
6287
|
+
const withCode = (_exec2 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
|
|
6347
6288
|
if (withCode !== undefined && init.method === "POST") {
|
|
6348
6289
|
return this.updateCodeFromSite(withCode, init.body, profileId);
|
|
6349
6290
|
}
|
|
@@ -6353,11 +6294,11 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6353
6294
|
* build's schemas (step 8.2). Anywhere else they go to content as they
|
|
6354
6295
|
* are, and the site's pending changes block as they always did.
|
|
6355
6296
|
*/
|
|
6356
|
-
const checking = (
|
|
6297
|
+
const checking = (_exec3 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
|
|
6357
6298
|
if (checking !== undefined && init.method === "GET" && (await this.answersMovesFor(checking, profileId))) {
|
|
6358
6299
|
return this.mergeChecksWithMoves(checking, profileId);
|
|
6359
6300
|
}
|
|
6360
|
-
const pressing = (
|
|
6301
|
+
const pressing = (_exec4 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
|
|
6361
6302
|
if (pressing !== undefined && init.method === "POST" && (await this.answersMovesFor(pressing, profileId))) {
|
|
6362
6303
|
return this.pressMergeWithMoves(pressing, init.body, profileId);
|
|
6363
6304
|
}
|
|
@@ -6409,147 +6350,6 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6409
6350
|
};
|
|
6410
6351
|
}
|
|
6411
6352
|
|
|
6412
|
-
/**
|
|
6413
|
-
* A patch written into a module's FILE in a proposal, and staged there as
|
|
6414
|
-
* code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
|
|
6415
|
-
* The assistant there changes the proposal's code, so content it writes goes
|
|
6416
|
-
* with that code -- a field it just added is filled in the same change, and
|
|
6417
|
-
* built and rendered with it -- rather than into the proposal's saves, which
|
|
6418
|
-
* the site's server does not write.
|
|
6419
|
-
*
|
|
6420
|
-
* Answered here, at `POST /<name>/patch-file`: the file is the proposal's
|
|
6421
|
-
* copy if it has one, otherwise the one this build was made from, and the
|
|
6422
|
-
* patch is written into it as a save writes one (`patchModuleText`). Who may
|
|
6423
|
-
* is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
|
|
6424
|
-
*/
|
|
6425
|
-
async patchFileInProposal(name, body, profileId) {
|
|
6426
|
-
var _this$projectSource, _this$options2;
|
|
6427
|
-
const json = "application/json";
|
|
6428
|
-
const answer = (status, value) => ({
|
|
6429
|
-
status,
|
|
6430
|
-
contentType: json,
|
|
6431
|
-
body: JSON.stringify(value)
|
|
6432
|
-
});
|
|
6433
|
-
if (!this.mayWriteFiles({
|
|
6434
|
-
name,
|
|
6435
|
-
write: "files"
|
|
6436
|
-
})) {
|
|
6437
|
-
return answer(403, {
|
|
6438
|
-
message: "Files are changed in the proposal this Studio is open in, not in another."
|
|
6439
|
-
});
|
|
6440
|
-
}
|
|
6441
|
-
let parsedBody;
|
|
6442
|
-
try {
|
|
6443
|
-
parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
|
|
6444
|
-
} catch {
|
|
6445
|
-
return answer(400, {
|
|
6446
|
-
message: "The patch's body is not JSON."
|
|
6447
|
-
});
|
|
6448
|
-
}
|
|
6449
|
-
const request = PatchFileBody.safeParse(parsedBody);
|
|
6450
|
-
if (!request.success) {
|
|
6451
|
-
return answer(400, {
|
|
6452
|
-
message: `Invalid patch: ${zodValidationError.fromError(request.error).toString()}`
|
|
6453
|
-
});
|
|
6454
|
-
}
|
|
6455
|
-
const {
|
|
6456
|
-
moduleFilePath,
|
|
6457
|
-
patch,
|
|
6458
|
-
message
|
|
6459
|
-
} = request.data;
|
|
6460
|
-
const content = this.proposalContent(name, profileId);
|
|
6461
|
-
const read = await content("/files");
|
|
6462
|
-
if (!read.ok) {
|
|
6463
|
-
return {
|
|
6464
|
-
status: read.status,
|
|
6465
|
-
contentType: json,
|
|
6466
|
-
body: await read.text()
|
|
6467
|
-
};
|
|
6468
|
-
}
|
|
6469
|
-
const files = ProposalFilesRead.safeParse(await read.json());
|
|
6470
|
-
if (!files.success) {
|
|
6471
|
-
return answer(502, {
|
|
6472
|
-
message: `Content answered the proposal's files in a shape this Val does not read: ${zodValidationError.fromError(files.error).toString()}`
|
|
6473
|
-
});
|
|
6474
|
-
}
|
|
6475
|
-
const filePath = moduleFilePath.replace(/^\/+/, "");
|
|
6476
|
-
const own = files.data.files[filePath];
|
|
6477
|
-
if (own === null) {
|
|
6478
|
-
return answer(409, {
|
|
6479
|
-
message: `${moduleFilePath} is deleted in this proposal.`
|
|
6480
|
-
});
|
|
6481
|
-
}
|
|
6482
|
-
if (own === undefined && this.projectSource === null) {
|
|
6483
|
-
return answer(409, {
|
|
6484
|
-
message: `This build does not carry its source, so ${moduleFilePath} can only be patched once the proposal has its own copy: write it with write_files.`
|
|
6485
|
-
});
|
|
6486
|
-
}
|
|
6487
|
-
const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
|
|
6488
|
-
if (text === undefined) {
|
|
6489
|
-
return answer(404, {
|
|
6490
|
-
message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
|
|
6491
|
-
});
|
|
6492
|
-
}
|
|
6493
|
-
const patched = await patchModuleFiles(moduleFilePath, text, path => {
|
|
6494
|
-
var _this$projectSource2;
|
|
6495
|
-
const proposalCopy = files.data.files[path];
|
|
6496
|
-
return proposalCopy !== undefined ? proposalCopy : (_this$projectSource2 = this.projectSource) === null || _this$projectSource2 === void 0 ? void 0 : _this$projectSource2[path];
|
|
6497
|
-
}, patch);
|
|
6498
|
-
if (fp.result.isErr(patched)) {
|
|
6499
|
-
return answer(422, {
|
|
6500
|
-
message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
|
|
6501
|
-
});
|
|
6502
|
-
}
|
|
6503
|
-
const formatter = (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.formatter;
|
|
6504
|
-
const format = async (written, path) => {
|
|
6505
|
-
if (!formatter) return fp.result.ok(written);
|
|
6506
|
-
try {
|
|
6507
|
-
return fp.result.ok(await formatter(written, path));
|
|
6508
|
-
} catch (error) {
|
|
6509
|
-
return fp.result.err(`The patched ${path} could not be formatted: ${error instanceof Error ? error.message : String(error)}`);
|
|
6510
|
-
}
|
|
6511
|
-
};
|
|
6512
|
-
const staging = {};
|
|
6513
|
-
if (patched.value.moduleText !== null) {
|
|
6514
|
-
const formatted = await format(patched.value.moduleText, moduleFilePath);
|
|
6515
|
-
if (fp.result.isErr(formatted)) {
|
|
6516
|
-
return answer(422, {
|
|
6517
|
-
message: formatted.error
|
|
6518
|
-
});
|
|
6519
|
-
}
|
|
6520
|
-
staging[filePath] = formatted.value;
|
|
6521
|
-
}
|
|
6522
|
-
// An entry's file as a save writes it: see `ValOps.prepare`.
|
|
6523
|
-
for (const [entryFile, content] of Object.entries(patched.value.entries)) {
|
|
6524
|
-
const formatted = await format(JSON.stringify(content, null, 2), `/${entryFile}`);
|
|
6525
|
-
if (fp.result.isErr(formatted)) {
|
|
6526
|
-
return answer(422, {
|
|
6527
|
-
message: formatted.error
|
|
6528
|
-
});
|
|
6529
|
-
}
|
|
6530
|
-
staging[entryFile] = formatted.value;
|
|
6531
|
-
}
|
|
6532
|
-
const modules = await stagedModuleSources(staging);
|
|
6533
|
-
const staged = await content("/files", {
|
|
6534
|
-
method: "POST",
|
|
6535
|
-
body: JSON.stringify({
|
|
6536
|
-
files: staging,
|
|
6537
|
-
// The Source the patched text declares: see `stagedModuleSources`.
|
|
6538
|
-
...(Object.keys(modules).length > 0 ? {
|
|
6539
|
-
modules
|
|
6540
|
-
} : {}),
|
|
6541
|
-
...(message !== undefined ? {
|
|
6542
|
-
message
|
|
6543
|
-
} : {})
|
|
6544
|
-
})
|
|
6545
|
-
});
|
|
6546
|
-
return {
|
|
6547
|
-
status: staged.status,
|
|
6548
|
-
contentType: staged.headers.get("Content-Type") ?? json,
|
|
6549
|
-
body: await staged.text()
|
|
6550
|
-
};
|
|
6551
|
-
}
|
|
6552
|
-
|
|
6553
6353
|
/**
|
|
6554
6354
|
* Update from the site, for a proposal that changes only content
|
|
6555
6355
|
* (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
|
|
@@ -7460,7 +7260,7 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7460
7260
|
return {
|
|
7461
7261
|
status: "error",
|
|
7462
7262
|
error: {
|
|
7463
|
-
message:
|
|
7263
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "connect for live updates", e))
|
|
7464
7264
|
}
|
|
7465
7265
|
};
|
|
7466
7266
|
});
|
|
@@ -7726,7 +7526,12 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7726
7526
|
}
|
|
7727
7527
|
};
|
|
7728
7528
|
}
|
|
7729
|
-
|
|
7529
|
+
const failure = contentServiceAnswered(contentServiceName(this.contentUrl), "load your changes", {
|
|
7530
|
+
status: patchesRes.status,
|
|
7531
|
+
statusText: patchesRes.statusText,
|
|
7532
|
+
body: await patchesRes.text().catch(() => "")
|
|
7533
|
+
});
|
|
7534
|
+
core.Internal.log.error(`Could not get patches. ${failure.message} ${failure.details}`);
|
|
7730
7535
|
if (patchesRes.status === 401) {
|
|
7731
7536
|
return {
|
|
7732
7537
|
patches,
|
|
@@ -7735,19 +7540,29 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7735
7540
|
}
|
|
7736
7541
|
};
|
|
7737
7542
|
}
|
|
7543
|
+
/*
|
|
7544
|
+
* The service ANSWERED, so this is not a network problem -- it used to
|
|
7545
|
+
* say "most likely due to a network issue. Check your network
|
|
7546
|
+
* connection" about a 500, to an editor whose network was fine. What it
|
|
7547
|
+
* said goes in `details`. The Studio asks again on the next `/stat`,
|
|
7548
|
+
* which fails fast and is retried while the service is failing.
|
|
7549
|
+
*/
|
|
7738
7550
|
return {
|
|
7739
7551
|
patches,
|
|
7740
7552
|
error: {
|
|
7741
|
-
message:
|
|
7553
|
+
message: failure.message,
|
|
7554
|
+
details: failure.details
|
|
7742
7555
|
}
|
|
7743
7556
|
};
|
|
7744
7557
|
} catch (err) {
|
|
7745
|
-
|
|
7558
|
+
const failure = contentServiceUnreachable(contentServiceName(this.contentUrl), "load your changes", err);
|
|
7559
|
+
core.Internal.log.error(`Could not get patches. ${failure.message} ${failure.details}`);
|
|
7746
7560
|
return {
|
|
7747
7561
|
patches: [],
|
|
7748
7562
|
networkError: true,
|
|
7749
7563
|
error: {
|
|
7750
|
-
message:
|
|
7564
|
+
message: failure.message,
|
|
7565
|
+
details: failure.details
|
|
7751
7566
|
}
|
|
7752
7567
|
};
|
|
7753
7568
|
}
|
|
@@ -7781,7 +7596,6 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7781
7596
|
coreVersion: core.Internal.VERSION.core
|
|
7782
7597
|
})
|
|
7783
7598
|
}).then(async res => {
|
|
7784
|
-
var _res$headers$get3;
|
|
7785
7599
|
if (res.ok) {
|
|
7786
7600
|
const parsed = SavePatchResponse.safeParse(await res.json());
|
|
7787
7601
|
if (parsed.success) {
|
|
@@ -7803,8 +7617,27 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7803
7617
|
message: "Conflict: " + (await res.text())
|
|
7804
7618
|
});
|
|
7805
7619
|
}
|
|
7806
|
-
|
|
7807
|
-
|
|
7620
|
+
const body = await res.text();
|
|
7621
|
+
const failure = contentServiceAnswered(contentServiceName(this.contentUrl), "save your change", {
|
|
7622
|
+
status: res.status,
|
|
7623
|
+
statusText: res.statusText,
|
|
7624
|
+
body
|
|
7625
|
+
});
|
|
7626
|
+
if (failure.retryable) {
|
|
7627
|
+
/*
|
|
7628
|
+
* The SERVICE failed -- a 500 from a database missing a column was
|
|
7629
|
+
* the one that found this. It used to be an `other`, which the
|
|
7630
|
+
* Studio is told is a bad patch and drops: the field went back to
|
|
7631
|
+
* its old value and the status bar said "All changes saved".
|
|
7632
|
+
*/
|
|
7633
|
+
return fp.result.err({
|
|
7634
|
+
errorType: "service-error",
|
|
7635
|
+
message: failure.message,
|
|
7636
|
+
details: failure.details
|
|
7637
|
+
});
|
|
7638
|
+
}
|
|
7639
|
+
const json = parseJsonOrNull(body);
|
|
7640
|
+
if (json !== null) {
|
|
7808
7641
|
const message = internal.getErrorMessageFromUnknownJson(json, "Unknown error");
|
|
7809
7642
|
/*
|
|
7810
7643
|
* Refused for the plan: the patch is fine, and the reason comes as
|
|
@@ -7829,12 +7662,14 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7829
7662
|
}
|
|
7830
7663
|
return fp.result.err({
|
|
7831
7664
|
errorType: "other",
|
|
7832
|
-
message:
|
|
7665
|
+
message: `${failure.message} ${failure.details}`
|
|
7833
7666
|
});
|
|
7834
7667
|
}).catch(e => {
|
|
7668
|
+
const failure = contentServiceUnreachable(contentServiceName(this.contentUrl), "save your change", e);
|
|
7835
7669
|
return fp.result.err({
|
|
7836
|
-
errorType: "
|
|
7837
|
-
message:
|
|
7670
|
+
errorType: "service-error",
|
|
7671
|
+
message: failure.message,
|
|
7672
|
+
details: failure.details
|
|
7838
7673
|
});
|
|
7839
7674
|
});
|
|
7840
7675
|
}
|
|
@@ -7875,13 +7710,17 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7875
7710
|
}
|
|
7876
7711
|
return {
|
|
7877
7712
|
error: {
|
|
7878
|
-
message: "
|
|
7713
|
+
message: contentServiceFailureText(contentServiceAnswered(contentServiceName(this.contentUrl), "save the file", {
|
|
7714
|
+
status: res.status,
|
|
7715
|
+
statusText: res.statusText,
|
|
7716
|
+
body: await res.text().catch(() => "")
|
|
7717
|
+
}))
|
|
7879
7718
|
}
|
|
7880
7719
|
};
|
|
7881
7720
|
}).catch(e => {
|
|
7882
7721
|
return {
|
|
7883
7722
|
error: {
|
|
7884
|
-
message:
|
|
7723
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "save the file", e))
|
|
7885
7724
|
}
|
|
7886
7725
|
};
|
|
7887
7726
|
});
|
|
@@ -7919,13 +7758,17 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7919
7758
|
}
|
|
7920
7759
|
return {
|
|
7921
7760
|
error: {
|
|
7922
|
-
message:
|
|
7761
|
+
message: contentServiceFailureText(contentServiceAnswered(contentServiceName(this.contentUrl), "load the files", {
|
|
7762
|
+
status: res.status,
|
|
7763
|
+
statusText: res.statusText,
|
|
7764
|
+
body: await res.text().catch(() => "")
|
|
7765
|
+
}))
|
|
7923
7766
|
}
|
|
7924
7767
|
};
|
|
7925
7768
|
}).catch(e => {
|
|
7926
7769
|
return {
|
|
7927
7770
|
error: {
|
|
7928
|
-
message:
|
|
7771
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "load the files", e))
|
|
7929
7772
|
}
|
|
7930
7773
|
};
|
|
7931
7774
|
});
|
|
@@ -8071,14 +7914,18 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
8071
7914
|
}
|
|
8072
7915
|
return {
|
|
8073
7916
|
errors: [{
|
|
8074
|
-
message:
|
|
7917
|
+
message: contentServiceFailureText(contentServiceAnswered(contentServiceName(this.contentUrl), "read the file's details", {
|
|
7918
|
+
status: metadataRes.status,
|
|
7919
|
+
statusText: metadataRes.statusText,
|
|
7920
|
+
body: await metadataRes.text().catch(() => "")
|
|
7921
|
+
})),
|
|
8075
7922
|
filePath
|
|
8076
7923
|
}]
|
|
8077
7924
|
};
|
|
8078
7925
|
} catch (err) {
|
|
8079
7926
|
return {
|
|
8080
7927
|
errors: [{
|
|
8081
|
-
message:
|
|
7928
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "read the file's details", err))
|
|
8082
7929
|
}]
|
|
8083
7930
|
};
|
|
8084
7931
|
}
|
|
@@ -8143,13 +7990,17 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
8143
7990
|
}
|
|
8144
7991
|
return {
|
|
8145
7992
|
error: {
|
|
8146
|
-
message:
|
|
7993
|
+
message: contentServiceFailureText(contentServiceAnswered(contentServiceName(this.contentUrl), "discard the changes", {
|
|
7994
|
+
status: res.status,
|
|
7995
|
+
statusText: res.statusText,
|
|
7996
|
+
body: await res.text().catch(() => "")
|
|
7997
|
+
}))
|
|
8147
7998
|
}
|
|
8148
7999
|
};
|
|
8149
8000
|
}).catch(e => {
|
|
8150
8001
|
return {
|
|
8151
8002
|
error: {
|
|
8152
|
-
message:
|
|
8003
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "discard the changes", e))
|
|
8153
8004
|
}
|
|
8154
8005
|
};
|
|
8155
8006
|
});
|
|
@@ -8162,7 +8013,7 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
8162
8013
|
*/
|
|
8163
8014
|
intoProposal) {
|
|
8164
8015
|
try {
|
|
8165
|
-
var _this$proposal4
|
|
8016
|
+
var _this$proposal4;
|
|
8166
8017
|
/*
|
|
8167
8018
|
* A save in a proposal is a commit on the proposal's branch, at its own
|
|
8168
8019
|
* route: the site's `/commit` refuses a proposal's patches, which is
|
|
@@ -8256,34 +8107,37 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
8256
8107
|
}
|
|
8257
8108
|
};
|
|
8258
8109
|
}
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
isNotFastForward: true,
|
|
8266
|
-
error: {
|
|
8267
|
-
message: "Could not commit. Not a fast-forward commit"
|
|
8268
|
-
}
|
|
8269
|
-
};
|
|
8270
|
-
}
|
|
8271
|
-
const message = internal.getErrorMessageFromUnknownJson(json, "Unknown error");
|
|
8110
|
+
const body = await res.text().catch(() => "");
|
|
8111
|
+
const payload = parseJsonOrNull(body);
|
|
8112
|
+
const notFastForward = z.z.object({
|
|
8113
|
+
isNotFastForward: z.z.boolean().optional()
|
|
8114
|
+
}).safeParse(payload);
|
|
8115
|
+
if (notFastForward.success && notFastForward.data.isNotFastForward) {
|
|
8272
8116
|
return {
|
|
8117
|
+
isNotFastForward: true,
|
|
8273
8118
|
error: {
|
|
8274
|
-
message
|
|
8119
|
+
message: "Could not commit. Not a fast-forward commit"
|
|
8275
8120
|
}
|
|
8276
8121
|
};
|
|
8277
8122
|
}
|
|
8123
|
+
/*
|
|
8124
|
+
* The service's own words, read from the PAYLOAD. This used to hand
|
|
8125
|
+
* `getErrorMessageFromUnknownJson` the zod `safeParse` result, which
|
|
8126
|
+
* has no `message`, so every commit failure read "Unknown error".
|
|
8127
|
+
*/
|
|
8278
8128
|
return {
|
|
8279
8129
|
error: {
|
|
8280
|
-
message:
|
|
8130
|
+
message: contentServiceFailureText(contentServiceAnswered(contentServiceName(this.contentUrl), "publish", {
|
|
8131
|
+
status: res.status,
|
|
8132
|
+
statusText: res.statusText,
|
|
8133
|
+
body
|
|
8134
|
+
}))
|
|
8281
8135
|
}
|
|
8282
8136
|
};
|
|
8283
8137
|
} catch (err) {
|
|
8284
8138
|
return {
|
|
8285
8139
|
error: {
|
|
8286
|
-
message:
|
|
8140
|
+
message: contentServiceFailureText(contentServiceUnreachable(contentServiceName(this.contentUrl), "publish", err))
|
|
8287
8141
|
}
|
|
8288
8142
|
};
|
|
8289
8143
|
}
|
|
@@ -8322,9 +8176,9 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
8322
8176
|
});
|
|
8323
8177
|
}
|
|
8324
8178
|
if (!res.ok) {
|
|
8325
|
-
var _res$headers$
|
|
8179
|
+
var _res$headers$get3;
|
|
8326
8180
|
let message = `${res.status} ${res.statusText}`;
|
|
8327
|
-
if ((_res$headers$
|
|
8181
|
+
if ((_res$headers$get3 = res.headers.get("Content-Type")) !== null && _res$headers$get3 !== void 0 && _res$headers$get3.includes("application/json")) {
|
|
8328
8182
|
message = internal.getErrorMessageFromUnknownJson(await res.json(), message);
|
|
8329
8183
|
}
|
|
8330
8184
|
// A 5xx from the service reading a record it says it has is a real
|