@valbuild/server 0.152.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 +15 -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-afcba447.cjs.dev.js → ValRouter-541c76f5.cjs.dev.js} +16 -336
- package/dist/{ValRouter-05fcb0da.esm.js → ValRouter-b4125d35.esm.js} +17 -337
- package/dist/{ValRouter-b4e5b412.cjs.prod.js → ValRouter-e1e0101b.cjs.prod.js} +16 -336
- package/dist/{ValRouterCore-d16c3327.cjs.dev.js → ValRouterCore-0c0359fe.cjs.prod.js} +2 -2
- package/dist/{ValRouterCore-a0ea46bf.cjs.prod.js → ValRouterCore-bd3e9b6c.cjs.dev.js} +2 -2
- package/dist/{ValRouterCore-b5d70504.esm.js → ValRouterCore-eea19e82.esm.js} +2 -2
- package/dist/declarations/src/ValOpsHttp.d.ts +4 -39
- package/dist/declarations/src/patch/ts/jsonValuesModule.d.ts +1 -1
- package/dist/{inTabFetch-095bb2be.cjs.prod.js → inTabFetch-5caf8250.cjs.prod.js} +1 -1
- package/dist/{inTabFetch-2cbbfaa4.cjs.dev.js → inTabFetch-6d54acd8.cjs.dev.js} +1 -1
- package/dist/{inTabFetch-91c3e85e.esm.js → inTabFetch-de7cf596.esm.js} +1 -1
- package/dist/{publishKit-4e2b0014.cjs.dev.js → publishKit-42f08a69.cjs.dev.js} +2 -2
- package/dist/{publishKit-6e52ffa6.cjs.prod.js → publishKit-9600ecef.cjs.prod.js} +2 -2
- package/dist/{publishKit-af14cd7a.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 +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @valbuild/server
|
|
2
2
|
|
|
3
|
+
## 0.152.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1019](https://github.com/valbuild/val/pull/1019) [`b9089c8`](https://github.com/valbuild/val/commit/b9089c8787da8075722cc4ef3672beb61b288af4) Thanks [@freekh](https://github.com/freekh)! - **What the design tab needed is removed with it.** The page's canvas bridge
|
|
8
|
+
now answers `read_page`, `screenshot_page` and a quick preview only to the
|
|
9
|
+
Studio at the page's own origin, and no longer asks the server whether another
|
|
10
|
+
origin is the site's design tab. The site's server no longer writes a
|
|
11
|
+
proposal's files or offers the `patch-file` route: code and content are
|
|
12
|
+
changed in the proposal's own Studio. The assistant's `build_proposal` no
|
|
13
|
+
longer takes a `reason`.
|
|
14
|
+
- Updated dependencies [[`b9089c8`](https://github.com/valbuild/val/commit/b9089c8787da8075722cc4ef3672beb61b288af4), [`b9089c8`](https://github.com/valbuild/val/commit/b9089c8787da8075722cc4ef3672beb61b288af4), [`b9089c8`](https://github.com/valbuild/val/commit/b9089c8787da8075722cc4ef3672beb61b288af4), [`b9089c8`](https://github.com/valbuild/val/commit/b9089c8787da8075722cc4ef3672beb61b288af4)]:
|
|
15
|
+
- @valbuild/ui@0.152.1
|
|
16
|
+
- @valbuild/shared@0.152.1
|
|
17
|
+
|
|
3
18
|
## 0.152.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var inTabFetch = require('../../dist/inTabFetch-
|
|
5
|
+
var inTabFetch = require('../../dist/inTabFetch-6d54acd8.cjs.dev.js');
|
|
6
6
|
require('@valbuild/core');
|
|
7
|
-
require('../../dist/ValRouterCore-
|
|
7
|
+
require('../../dist/ValRouterCore-bd3e9b6c.cjs.dev.js');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('@valbuild/shared/internal');
|
|
10
10
|
require('zod-validation-error');
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var inTabFetch = require('../../dist/inTabFetch-
|
|
5
|
+
var inTabFetch = require('../../dist/inTabFetch-5caf8250.cjs.prod.js');
|
|
6
6
|
require('@valbuild/core');
|
|
7
|
-
require('../../dist/ValRouterCore-
|
|
7
|
+
require('../../dist/ValRouterCore-0c0359fe.cjs.prod.js');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('@valbuild/shared/internal');
|
|
10
10
|
require('zod-validation-error');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { c as createInTabValFetch } from '../../dist/inTabFetch-
|
|
1
|
+
export { c as createInTabValFetch } from '../../dist/inTabFetch-de7cf596.esm.js';
|
|
2
2
|
import '@valbuild/core';
|
|
3
|
-
import '../../dist/ValRouterCore-
|
|
3
|
+
import '../../dist/ValRouterCore-eea19e82.esm.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '@valbuild/shared/internal';
|
|
6
6
|
import 'zod-validation-error';
|
|
@@ -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-4e2b0014.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-4e2b0014.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,
|
|
@@ -5430,13 +5290,6 @@ const PlanRefusedBody = z.z.object({
|
|
|
5430
5290
|
error: internal.PlanRefusalError
|
|
5431
5291
|
});
|
|
5432
5292
|
|
|
5433
|
-
/** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
|
|
5434
|
-
const PatchFileBody = z.z.object({
|
|
5435
|
-
moduleFilePath: z.z.string().regex(/^\/.+\.val\.(ts|js)$/),
|
|
5436
|
-
patch: internal.Patch,
|
|
5437
|
-
message: z.z.string().max(500).optional()
|
|
5438
|
-
});
|
|
5439
|
-
|
|
5440
5293
|
/** A staging's body, as `write_files` sends it. */
|
|
5441
5294
|
const StageFilesBody = z.z.object({
|
|
5442
5295
|
files: z.z.record(z.z.string(), z.z.string().nullable())
|
|
@@ -5465,11 +5318,6 @@ async function withStagedModuleSources(body) {
|
|
|
5465
5318
|
modules
|
|
5466
5319
|
});
|
|
5467
5320
|
}
|
|
5468
|
-
|
|
5469
|
-
/** What `patchFileInProposal` reads of content's answer for a proposal's files. */
|
|
5470
|
-
const ProposalFilesRead = z.z.object({
|
|
5471
|
-
files: z.z.record(z.z.string(), z.z.string().nullable())
|
|
5472
|
-
});
|
|
5473
5321
|
const PatchId = z.z.string().refine(s => !!s); // TODO: validate
|
|
5474
5322
|
const CommitSha = z.z.string().refine(s => !!s); // TODO: validate
|
|
5475
5323
|
z.z.string().refine(s => !!s); // TODO: validate
|
|
@@ -6395,38 +6243,15 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6395
6243
|
};
|
|
6396
6244
|
}
|
|
6397
6245
|
|
|
6398
|
-
/**
|
|
6399
|
-
* The writes the SITE's server may make to a proposal's files: what the
|
|
6400
|
-
* design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
|
|
6401
|
-
* code, build it, and report its typecheck. The tab is served by the site's
|
|
6402
|
-
* build so that a build the assistant breaks in the proposal cannot take
|
|
6403
|
-
* down the tools it would fix it with; at the proposal's address those
|
|
6404
|
-
* tools run on the proposal's own code.
|
|
6405
|
-
*
|
|
6406
|
-
* The typecheck too, though it blocks the proposal's Publish (adept.md,
|
|
6407
|
-
* decision 20): it is the proposal's staged files checked against the
|
|
6408
|
-
* site's, the same program from either address, and the content service
|
|
6409
|
-
* keeps it only for the inputs it was made from. Without it the tab's
|
|
6410
|
-
* Types check, and the assistant's `typecheck`, had nothing to show.
|
|
6411
|
-
*
|
|
6412
|
-
* And a quick preview: the browser half of a build of the staged files,
|
|
6413
|
-
* which Val Build makes and nothing serves.
|
|
6414
|
-
*
|
|
6415
|
-
* The rest stay the proposal's own: Update from the site and the lockfile
|
|
6416
|
-
* are answered from the proposal's build and schemas, and bringing back a
|
|
6417
|
-
* point's code is the Studio at its address finishing a restore.
|
|
6418
|
-
*/
|
|
6419
|
-
static SITE_MAY_WRITE = new Set(["files", "build", "quick-preview", "typecheck"]);
|
|
6420
|
-
|
|
6421
6246
|
/**
|
|
6422
6247
|
* Whether this server may make a write to a proposal's files: the
|
|
6423
|
-
* proposal's own server,
|
|
6424
|
-
*
|
|
6425
|
-
*
|
|
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.
|
|
6426
6252
|
*/
|
|
6427
6253
|
mayWriteFiles(write) {
|
|
6428
|
-
|
|
6429
|
-
return ValOpsHttp.SITE_MAY_WRITE.has(write.write);
|
|
6254
|
+
return this.proposal !== null && write.name === this.proposal.name;
|
|
6430
6255
|
}
|
|
6431
6256
|
|
|
6432
6257
|
/**
|
|
@@ -6453,17 +6278,13 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6453
6278
|
return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
|
|
6454
6279
|
}
|
|
6455
6280
|
async proposalsApi(path, init, profileId) {
|
|
6456
|
-
var _exec, _exec2, _exec3, _exec4
|
|
6281
|
+
var _exec, _exec2, _exec3, _exec4;
|
|
6457
6282
|
const json = "application/json";
|
|
6458
6283
|
const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
|
|
6459
6284
|
if (updating !== undefined && init.method === "POST") {
|
|
6460
6285
|
return this.updateContentFromSite(updating, init.body, profileId);
|
|
6461
6286
|
}
|
|
6462
|
-
const
|
|
6463
|
-
if (patching !== undefined && init.method === "POST") {
|
|
6464
|
-
return this.patchFileInProposal(patching, init.body, profileId);
|
|
6465
|
-
}
|
|
6466
|
-
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];
|
|
6467
6288
|
if (withCode !== undefined && init.method === "POST") {
|
|
6468
6289
|
return this.updateCodeFromSite(withCode, init.body, profileId);
|
|
6469
6290
|
}
|
|
@@ -6473,11 +6294,11 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6473
6294
|
* build's schemas (step 8.2). Anywhere else they go to content as they
|
|
6474
6295
|
* are, and the site's pending changes block as they always did.
|
|
6475
6296
|
*/
|
|
6476
|
-
const checking = (
|
|
6297
|
+
const checking = (_exec3 = /^\/([0-9a-f]{20})\/merge-checks$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
|
|
6477
6298
|
if (checking !== undefined && init.method === "GET" && (await this.answersMovesFor(checking, profileId))) {
|
|
6478
6299
|
return this.mergeChecksWithMoves(checking, profileId);
|
|
6479
6300
|
}
|
|
6480
|
-
const pressing = (
|
|
6301
|
+
const pressing = (_exec4 = /^\/([0-9a-f]{20})\/merge$/.exec(path)) === null || _exec4 === void 0 ? void 0 : _exec4[1];
|
|
6481
6302
|
if (pressing !== undefined && init.method === "POST" && (await this.answersMovesFor(pressing, profileId))) {
|
|
6482
6303
|
return this.pressMergeWithMoves(pressing, init.body, profileId);
|
|
6483
6304
|
}
|
|
@@ -6529,147 +6350,6 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6529
6350
|
};
|
|
6530
6351
|
}
|
|
6531
6352
|
|
|
6532
|
-
/**
|
|
6533
|
-
* A patch written into a module's FILE in a proposal, and staged there as
|
|
6534
|
-
* code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
|
|
6535
|
-
* The assistant there changes the proposal's code, so content it writes goes
|
|
6536
|
-
* with that code -- a field it just added is filled in the same change, and
|
|
6537
|
-
* built and rendered with it -- rather than into the proposal's saves, which
|
|
6538
|
-
* the site's server does not write.
|
|
6539
|
-
*
|
|
6540
|
-
* Answered here, at `POST /<name>/patch-file`: the file is the proposal's
|
|
6541
|
-
* copy if it has one, otherwise the one this build was made from, and the
|
|
6542
|
-
* patch is written into it as a save writes one (`patchModuleText`). Who may
|
|
6543
|
-
* is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
|
|
6544
|
-
*/
|
|
6545
|
-
async patchFileInProposal(name, body, profileId) {
|
|
6546
|
-
var _this$projectSource, _this$options2;
|
|
6547
|
-
const json = "application/json";
|
|
6548
|
-
const answer = (status, value) => ({
|
|
6549
|
-
status,
|
|
6550
|
-
contentType: json,
|
|
6551
|
-
body: JSON.stringify(value)
|
|
6552
|
-
});
|
|
6553
|
-
if (!this.mayWriteFiles({
|
|
6554
|
-
name,
|
|
6555
|
-
write: "files"
|
|
6556
|
-
})) {
|
|
6557
|
-
return answer(403, {
|
|
6558
|
-
message: "Files are changed in the proposal this Studio is open in, not in another."
|
|
6559
|
-
});
|
|
6560
|
-
}
|
|
6561
|
-
let parsedBody;
|
|
6562
|
-
try {
|
|
6563
|
-
parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
|
|
6564
|
-
} catch {
|
|
6565
|
-
return answer(400, {
|
|
6566
|
-
message: "The patch's body is not JSON."
|
|
6567
|
-
});
|
|
6568
|
-
}
|
|
6569
|
-
const request = PatchFileBody.safeParse(parsedBody);
|
|
6570
|
-
if (!request.success) {
|
|
6571
|
-
return answer(400, {
|
|
6572
|
-
message: `Invalid patch: ${zodValidationError.fromError(request.error).toString()}`
|
|
6573
|
-
});
|
|
6574
|
-
}
|
|
6575
|
-
const {
|
|
6576
|
-
moduleFilePath,
|
|
6577
|
-
patch,
|
|
6578
|
-
message
|
|
6579
|
-
} = request.data;
|
|
6580
|
-
const content = this.proposalContent(name, profileId);
|
|
6581
|
-
const read = await content("/files");
|
|
6582
|
-
if (!read.ok) {
|
|
6583
|
-
return {
|
|
6584
|
-
status: read.status,
|
|
6585
|
-
contentType: json,
|
|
6586
|
-
body: await read.text()
|
|
6587
|
-
};
|
|
6588
|
-
}
|
|
6589
|
-
const files = ProposalFilesRead.safeParse(await read.json());
|
|
6590
|
-
if (!files.success) {
|
|
6591
|
-
return answer(502, {
|
|
6592
|
-
message: `Content answered the proposal's files in a shape this Val does not read: ${zodValidationError.fromError(files.error).toString()}`
|
|
6593
|
-
});
|
|
6594
|
-
}
|
|
6595
|
-
const filePath = moduleFilePath.replace(/^\/+/, "");
|
|
6596
|
-
const own = files.data.files[filePath];
|
|
6597
|
-
if (own === null) {
|
|
6598
|
-
return answer(409, {
|
|
6599
|
-
message: `${moduleFilePath} is deleted in this proposal.`
|
|
6600
|
-
});
|
|
6601
|
-
}
|
|
6602
|
-
if (own === undefined && this.projectSource === null) {
|
|
6603
|
-
return answer(409, {
|
|
6604
|
-
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.`
|
|
6605
|
-
});
|
|
6606
|
-
}
|
|
6607
|
-
const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
|
|
6608
|
-
if (text === undefined) {
|
|
6609
|
-
return answer(404, {
|
|
6610
|
-
message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
|
|
6611
|
-
});
|
|
6612
|
-
}
|
|
6613
|
-
const patched = await patchModuleFiles(moduleFilePath, text, path => {
|
|
6614
|
-
var _this$projectSource2;
|
|
6615
|
-
const proposalCopy = files.data.files[path];
|
|
6616
|
-
return proposalCopy !== undefined ? proposalCopy : (_this$projectSource2 = this.projectSource) === null || _this$projectSource2 === void 0 ? void 0 : _this$projectSource2[path];
|
|
6617
|
-
}, patch);
|
|
6618
|
-
if (fp.result.isErr(patched)) {
|
|
6619
|
-
return answer(422, {
|
|
6620
|
-
message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
|
|
6621
|
-
});
|
|
6622
|
-
}
|
|
6623
|
-
const formatter = (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.formatter;
|
|
6624
|
-
const format = async (written, path) => {
|
|
6625
|
-
if (!formatter) return fp.result.ok(written);
|
|
6626
|
-
try {
|
|
6627
|
-
return fp.result.ok(await formatter(written, path));
|
|
6628
|
-
} catch (error) {
|
|
6629
|
-
return fp.result.err(`The patched ${path} could not be formatted: ${error instanceof Error ? error.message : String(error)}`);
|
|
6630
|
-
}
|
|
6631
|
-
};
|
|
6632
|
-
const staging = {};
|
|
6633
|
-
if (patched.value.moduleText !== null) {
|
|
6634
|
-
const formatted = await format(patched.value.moduleText, moduleFilePath);
|
|
6635
|
-
if (fp.result.isErr(formatted)) {
|
|
6636
|
-
return answer(422, {
|
|
6637
|
-
message: formatted.error
|
|
6638
|
-
});
|
|
6639
|
-
}
|
|
6640
|
-
staging[filePath] = formatted.value;
|
|
6641
|
-
}
|
|
6642
|
-
// An entry's file as a save writes it: see `ValOps.prepare`.
|
|
6643
|
-
for (const [entryFile, content] of Object.entries(patched.value.entries)) {
|
|
6644
|
-
const formatted = await format(JSON.stringify(content, null, 2), `/${entryFile}`);
|
|
6645
|
-
if (fp.result.isErr(formatted)) {
|
|
6646
|
-
return answer(422, {
|
|
6647
|
-
message: formatted.error
|
|
6648
|
-
});
|
|
6649
|
-
}
|
|
6650
|
-
staging[entryFile] = formatted.value;
|
|
6651
|
-
}
|
|
6652
|
-
const modules = await stagedModuleSources(staging);
|
|
6653
|
-
const staged = await content("/files", {
|
|
6654
|
-
method: "POST",
|
|
6655
|
-
body: JSON.stringify({
|
|
6656
|
-
files: staging,
|
|
6657
|
-
// The Source the patched text declares: see `stagedModuleSources`.
|
|
6658
|
-
...(Object.keys(modules).length > 0 ? {
|
|
6659
|
-
modules
|
|
6660
|
-
} : {}),
|
|
6661
|
-
...(message !== undefined ? {
|
|
6662
|
-
message
|
|
6663
|
-
} : {})
|
|
6664
|
-
})
|
|
6665
|
-
});
|
|
6666
|
-
return {
|
|
6667
|
-
status: staged.status,
|
|
6668
|
-
contentType: staged.headers.get("Content-Type") ?? json,
|
|
6669
|
-
body: await staged.text()
|
|
6670
|
-
};
|
|
6671
|
-
}
|
|
6672
|
-
|
|
6673
6353
|
/**
|
|
6674
6354
|
* Update from the site, for a proposal that changes only content
|
|
6675
6355
|
* (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
|