@valbuild/server 0.150.3 → 0.150.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +1 -1
- package/browser/dist/valbuild-server-browser.cjs.prod.js +1 -1
- package/browser/dist/valbuild-server-browser.esm.js +1 -1
- package/dist/{ValRouterCore-b3c6a562.esm.js → ValRouterCore-2f7ad9b9.esm.js} +9 -3
- package/dist/{ValRouterCore-f9016ae0.cjs.dev.js → ValRouterCore-946e45df.cjs.dev.js} +9 -3
- package/dist/{ValRouterCore-2e82ae18.cjs.prod.js → ValRouterCore-97c47cec.cjs.prod.js} +9 -3
- package/dist/declarations/src/ValOpsHttp.d.ts +44 -5
- package/dist/{getJsonEntryAtCommit-b8469ec5.cjs.dev.js → getJsonEntryAtCommit-757fec21.cjs.dev.js} +1 -1
- package/dist/{getJsonEntryAtCommit-ad6deabd.esm.js → getJsonEntryAtCommit-8a6adc22.esm.js} +1 -1
- package/dist/{getJsonEntryAtCommit-5552ac46.cjs.prod.js → getJsonEntryAtCommit-e519549a.cjs.prod.js} +1 -1
- package/dist/valbuild-server.cjs.dev.js +224 -20
- package/dist/valbuild-server.cjs.prod.js +224 -20
- package/dist/valbuild-server.esm.js +225 -21
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @valbuild/server
|
|
2
2
|
|
|
3
|
+
## 0.150.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#968](https://github.com/valbuild/val/pull/968) [`2a16ffa`](https://github.com/valbuild/val/commit/2a16ffacd1c77bccaa6ccf5f8754b1f9c574d4f2) Thanks [@freekh](https://github.com/freekh)! - The assistant can search, format and typecheck a proposal's code, and change content in the design tab.
|
|
8
|
+
|
|
9
|
+
- **`search_code`** finds every line of the project that matches some text or a regular expression, with its file and line number, so the assistant finds where something is rendered before reading whole files.
|
|
10
|
+
- **`format_files`** formats the proposal's files with Prettier and the project's own config (`.prettierrc`, `.prettierrc.json` or `package.json`'s `prettier`), and stages the ones that change. It runs in the browser, loaded the first time it is used, because the platform's server cannot run Prettier. A config it cannot read — JavaScript, YAML, plugins or per-file overrides — is reported rather than guessed at.
|
|
11
|
+
- **`typecheck`** checks the proposal's code with TypeScript and answers the type errors the proposal adds — not the ones the site already has. The assistant runs it after changing code and before building. In the design tab its result is the Types check.
|
|
12
|
+
- **`create_patch` in the design tab** writes content into the module's file in the proposal and stages it with the code, so a field the assistant adds to a schema is filled in the same change and built with it.
|
|
13
|
+
|
|
14
|
+
- [#963](https://github.com/valbuild/val/pull/963) [`f7d56ec`](https://github.com/valbuild/val/commit/f7d56ecaed8567c0ea2889bbf1ba64844356cb1a) Thanks [@freekh](https://github.com/freekh)! - The assistant's chats in a proposal are shared with everyone on the project. A chat started while you are in a proposal belongs to it: anyone on the project who opens the proposal sees it in the chat list, with who is in it, and can read it and keep asking. Messages are named once more than one person has written, and the chat header has a link to the chat. One question runs at a time: if someone else's question is running, what you write is sent when its answer is done. Chats started on the site stay your own.
|
|
15
|
+
|
|
16
|
+
It needs the content server that knows about proposal chats; with an older one, chats work as before.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`5960071`](https://github.com/valbuild/val/commit/59600711af792f489b050ab47bcdc103d7d8c028), [`2a16ffa`](https://github.com/valbuild/val/commit/2a16ffacd1c77bccaa6ccf5f8754b1f9c574d4f2), [`f7d56ec`](https://github.com/valbuild/val/commit/f7d56ecaed8567c0ea2889bbf1ba64844356cb1a)]:
|
|
19
|
+
- @valbuild/shared@0.150.8
|
|
20
|
+
- @valbuild/ui@0.150.8
|
|
21
|
+
|
|
22
|
+
## 0.150.5
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [#956](https://github.com/valbuild/val/pull/956) [`47a31cc`](https://github.com/valbuild/val/commit/47a31cc3574841acf4f3207d5053f8bc728d25cd) Thanks [@freekh](https://github.com/freekh)! - The design tab: a proposal's code, changed with the assistant, in a tab of its own. Open it from a proposal's menu in the switcher ("Open design tab"). It opens at `/val/design/<proposal>` on the site's address, beside the proposal's, and shows the files the proposal changes against the site, each one's diff, the proposal's history, Build, and the proposal's address in a frame at desktop, tablet and phone widths. The assistant there changes the proposal's code (and only reads content).
|
|
27
|
+
|
|
28
|
+
The tab is served by the site's build, not the proposal's. So a change the assistant breaks the proposal with takes away the preview, never the tab or the tools that fix it. For that, the site's Val server now stages files in, and builds, a proposal it names; a proposal's address still writes only its own.
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`47a31cc`](https://github.com/valbuild/val/commit/47a31cc3574841acf4f3207d5053f8bc728d25cd)]:
|
|
31
|
+
- @valbuild/ui@0.150.5
|
|
32
|
+
|
|
3
33
|
## 0.150.3
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@valbuild/core');
|
|
6
|
-
var ValRouterCore = require('../../dist/ValRouterCore-
|
|
6
|
+
var ValRouterCore = require('../../dist/ValRouterCore-946e45df.cjs.dev.js');
|
|
7
7
|
require('@valbuild/shared/internal');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('zod-validation-error');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@valbuild/core');
|
|
6
|
-
var ValRouterCore = require('../../dist/ValRouterCore-
|
|
6
|
+
var ValRouterCore = require('../../dist/ValRouterCore-97c47cec.cjs.prod.js');
|
|
7
7
|
require('@valbuild/shared/internal');
|
|
8
8
|
require('zod');
|
|
9
9
|
require('zod-validation-error');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_CONTENT_HOST } from '@valbuild/core';
|
|
2
|
-
import { j as ValOpsMemory, E as bytesToBase64, y as ValServer, z as createValRequestHandler } from '../../dist/ValRouterCore-
|
|
2
|
+
import { j as ValOpsMemory, E as bytesToBase64, y as ValServer, z as createValRequestHandler } from '../../dist/ValRouterCore-2f7ad9b9.esm.js';
|
|
3
3
|
import '@valbuild/shared/internal';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'zod-validation-error';
|
|
@@ -8439,7 +8439,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8439
8439
|
id: z.string(),
|
|
8440
8440
|
name: z.string().nullable(),
|
|
8441
8441
|
createdAt: z.string(),
|
|
8442
|
-
updatedAt: z.string()
|
|
8442
|
+
updatedAt: z.string(),
|
|
8443
|
+
// A proposal's chats say who is in each (Flow H).
|
|
8444
|
+
authorIds: z.array(z.string()).optional()
|
|
8443
8445
|
})),
|
|
8444
8446
|
nextCursor: z.object({
|
|
8445
8447
|
updatedAt: z.string(),
|
|
@@ -8448,6 +8450,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8448
8450
|
});
|
|
8449
8451
|
const params = new URLSearchParams();
|
|
8450
8452
|
if (req.query.limit) params.set("limit", req.query.limit);
|
|
8453
|
+
// In a proposal, its chats, everyone's (Flow H).
|
|
8454
|
+
if (req.query.proposal) params.set("proposal", req.query.proposal);
|
|
8451
8455
|
if (req.query.cursor_updatedAt) {
|
|
8452
8456
|
params.set("cursor_updatedAt", req.query.cursor_updatedAt);
|
|
8453
8457
|
}
|
|
@@ -8637,7 +8641,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8637
8641
|
const SessionMessagesResponse = z.object({
|
|
8638
8642
|
messages: z.array(z.object({
|
|
8639
8643
|
role: z.string(),
|
|
8640
|
-
content: AIMessageContent
|
|
8644
|
+
content: AIMessageContent,
|
|
8645
|
+
// Who asked, on a user message (Flow H).
|
|
8646
|
+
authorId: z.string().nullable().optional()
|
|
8641
8647
|
})),
|
|
8642
8648
|
nextCursor: z.object({
|
|
8643
8649
|
updatedAt: z.string(),
|
|
@@ -9110,7 +9116,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
9110
9116
|
// TypeScript compiler. See `patch/ts/publishKit.ts`.
|
|
9111
9117
|
const {
|
|
9112
9118
|
getJsonEntryAtCommit
|
|
9113
|
-
} = await import('./getJsonEntryAtCommit-
|
|
9119
|
+
} = await import('./getJsonEntryAtCommit-8a6adc22.esm.js');
|
|
9114
9120
|
const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
|
|
9115
9121
|
if (result.isErr(res)) {
|
|
9116
9122
|
return historyErrorResponse(res.error);
|
|
@@ -8445,7 +8445,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8445
8445
|
id: z.z.string(),
|
|
8446
8446
|
name: z.z.string().nullable(),
|
|
8447
8447
|
createdAt: z.z.string(),
|
|
8448
|
-
updatedAt: z.z.string()
|
|
8448
|
+
updatedAt: z.z.string(),
|
|
8449
|
+
// A proposal's chats say who is in each (Flow H).
|
|
8450
|
+
authorIds: z.z.array(z.z.string()).optional()
|
|
8449
8451
|
})),
|
|
8450
8452
|
nextCursor: z.z.object({
|
|
8451
8453
|
updatedAt: z.z.string(),
|
|
@@ -8454,6 +8456,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8454
8456
|
});
|
|
8455
8457
|
const params = new URLSearchParams();
|
|
8456
8458
|
if (req.query.limit) params.set("limit", req.query.limit);
|
|
8459
|
+
// In a proposal, its chats, everyone's (Flow H).
|
|
8460
|
+
if (req.query.proposal) params.set("proposal", req.query.proposal);
|
|
8457
8461
|
if (req.query.cursor_updatedAt) {
|
|
8458
8462
|
params.set("cursor_updatedAt", req.query.cursor_updatedAt);
|
|
8459
8463
|
}
|
|
@@ -8643,7 +8647,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8643
8647
|
const SessionMessagesResponse = z.z.object({
|
|
8644
8648
|
messages: z.z.array(z.z.object({
|
|
8645
8649
|
role: z.z.string(),
|
|
8646
|
-
content: AIMessageContent
|
|
8650
|
+
content: AIMessageContent,
|
|
8651
|
+
// Who asked, on a user message (Flow H).
|
|
8652
|
+
authorId: z.z.string().nullable().optional()
|
|
8647
8653
|
})),
|
|
8648
8654
|
nextCursor: z.z.object({
|
|
8649
8655
|
updatedAt: z.z.string(),
|
|
@@ -9116,7 +9122,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
9116
9122
|
// TypeScript compiler. See `patch/ts/publishKit.ts`.
|
|
9117
9123
|
const {
|
|
9118
9124
|
getJsonEntryAtCommit
|
|
9119
|
-
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-
|
|
9125
|
+
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-757fec21.cjs.dev.js'); });
|
|
9120
9126
|
const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
|
|
9121
9127
|
if (fp.result.isErr(res)) {
|
|
9122
9128
|
return historyErrorResponse(res.error);
|
|
@@ -8445,7 +8445,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8445
8445
|
id: z.z.string(),
|
|
8446
8446
|
name: z.z.string().nullable(),
|
|
8447
8447
|
createdAt: z.z.string(),
|
|
8448
|
-
updatedAt: z.z.string()
|
|
8448
|
+
updatedAt: z.z.string(),
|
|
8449
|
+
// A proposal's chats say who is in each (Flow H).
|
|
8450
|
+
authorIds: z.z.array(z.z.string()).optional()
|
|
8449
8451
|
})),
|
|
8450
8452
|
nextCursor: z.z.object({
|
|
8451
8453
|
updatedAt: z.z.string(),
|
|
@@ -8454,6 +8456,8 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8454
8456
|
});
|
|
8455
8457
|
const params = new URLSearchParams();
|
|
8456
8458
|
if (req.query.limit) params.set("limit", req.query.limit);
|
|
8459
|
+
// In a proposal, its chats, everyone's (Flow H).
|
|
8460
|
+
if (req.query.proposal) params.set("proposal", req.query.proposal);
|
|
8457
8461
|
if (req.query.cursor_updatedAt) {
|
|
8458
8462
|
params.set("cursor_updatedAt", req.query.cursor_updatedAt);
|
|
8459
8463
|
}
|
|
@@ -8643,7 +8647,9 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
8643
8647
|
const SessionMessagesResponse = z.z.object({
|
|
8644
8648
|
messages: z.z.array(z.z.object({
|
|
8645
8649
|
role: z.z.string(),
|
|
8646
|
-
content: AIMessageContent
|
|
8650
|
+
content: AIMessageContent,
|
|
8651
|
+
// Who asked, on a user message (Flow H).
|
|
8652
|
+
authorId: z.z.string().nullable().optional()
|
|
8647
8653
|
})),
|
|
8648
8654
|
nextCursor: z.z.object({
|
|
8649
8655
|
updatedAt: z.z.string(),
|
|
@@ -9116,7 +9122,7 @@ const ValServer = (valModules, options, callbacks, platform) => {
|
|
|
9116
9122
|
// TypeScript compiler. See `patch/ts/publishKit.ts`.
|
|
9117
9123
|
const {
|
|
9118
9124
|
getJsonEntryAtCommit
|
|
9119
|
-
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-
|
|
9125
|
+
} = await Promise.resolve().then(function () { return require('./getJsonEntryAtCommit-e519549a.cjs.prod.js'); });
|
|
9120
9126
|
const res = await getJsonEntryAtCommit(serverOps, req.query.commit_sha, req.query.path, req.query.key);
|
|
9121
9127
|
if (fp.result.isErr(res)) {
|
|
9122
9128
|
return historyErrorResponse(res.error);
|
|
@@ -302,13 +302,38 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
302
302
|
* (valbuild/home `docs/adept.md`, step 6), reporting the typecheck of
|
|
303
303
|
* them (step 7, decision 20), serving a build of it
|
|
304
304
|
* (valbuild/home `docs/hosted-publishing.md`, step 7), or moving it onto the
|
|
305
|
-
* site's code (step 8, "Update from the site")
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* path is not such a write.
|
|
305
|
+
* site's code (step 8, "Update from the site"). The proposal it names and
|
|
306
|
+
* what it does, or `null` when this path is not such a write.
|
|
307
|
+
*
|
|
308
|
+
* Who may make one is {@link ValOpsHttp.mayWriteFiles}.
|
|
310
309
|
*/
|
|
311
310
|
private static proposalFilesWrite;
|
|
311
|
+
/**
|
|
312
|
+
* The writes the SITE's server may make to a proposal's files: what the
|
|
313
|
+
* design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
|
|
314
|
+
* code, build it, and report its typecheck. The tab is served by the site's
|
|
315
|
+
* build so that a build the assistant breaks in the proposal cannot take
|
|
316
|
+
* down the tools it would fix it with; at the proposal's address those
|
|
317
|
+
* tools run on the proposal's own code.
|
|
318
|
+
*
|
|
319
|
+
* The typecheck too, though it blocks the proposal's Publish (adept.md,
|
|
320
|
+
* decision 20): it is the proposal's staged files checked against the
|
|
321
|
+
* site's, the same program from either address, and the content service
|
|
322
|
+
* keeps it only for the inputs it was made from. Without it the tab's
|
|
323
|
+
* Types check, and the assistant's `typecheck`, had nothing to show.
|
|
324
|
+
*
|
|
325
|
+
* The rest stay the proposal's own: Update from the site and the lockfile
|
|
326
|
+
* are answered from the proposal's build and schemas, and bringing back a
|
|
327
|
+
* point's code is the Studio at its address finishing a restore.
|
|
328
|
+
*/
|
|
329
|
+
private static readonly SITE_MAY_WRITE;
|
|
330
|
+
/**
|
|
331
|
+
* Whether this server may make a write to a proposal's files: the
|
|
332
|
+
* proposal's own server, any of them; the site's, the design tab's; and a
|
|
333
|
+
* proposal's address, none to another proposal. Either way the site's own
|
|
334
|
+
* files change only when a proposal is merged.
|
|
335
|
+
*/
|
|
336
|
+
private mayWriteFiles;
|
|
312
337
|
/**
|
|
313
338
|
* What a proposal's address may reach of the publish API: building ITS OWN
|
|
314
339
|
* merge, and nothing that publishes the site's changes. The merge's prepare
|
|
@@ -326,6 +351,20 @@ export declare class ValOpsHttp extends ValOps {
|
|
|
326
351
|
body: string;
|
|
327
352
|
contentType: string;
|
|
328
353
|
}>;
|
|
354
|
+
/**
|
|
355
|
+
* A patch written into a module's FILE in a proposal, and staged there as
|
|
356
|
+
* code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
|
|
357
|
+
* The assistant there changes the proposal's code, so content it writes goes
|
|
358
|
+
* with that code -- a field it just added is filled in the same change, and
|
|
359
|
+
* built and rendered with it -- rather than into the proposal's saves, which
|
|
360
|
+
* the site's server does not write.
|
|
361
|
+
*
|
|
362
|
+
* Answered here, at `POST /<name>/patch-file`: the file is the proposal's
|
|
363
|
+
* copy if it has one, otherwise the one this build was made from, and the
|
|
364
|
+
* patch is written into it as a save writes one (`patchModuleText`). Who may
|
|
365
|
+
* is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
|
|
366
|
+
*/
|
|
367
|
+
private patchFileInProposal;
|
|
329
368
|
/**
|
|
330
369
|
* Update from the site, for a proposal that changes only content
|
|
331
370
|
* (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
|
package/dist/{getJsonEntryAtCommit-b8469ec5.cjs.dev.js → getJsonEntryAtCommit-757fec21.cjs.dev.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
4
|
+
var ValRouterCore = require('./ValRouterCore-946e45df.cjs.dev.js');
|
|
5
5
|
var fp = require('@valbuild/core/fp');
|
|
6
6
|
var jsonValuesModule = require('./jsonValuesModule-8ae503a8.cjs.dev.js');
|
|
7
7
|
require('@valbuild/core');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { F as bytesToUtf8, G as posixPath } from './ValRouterCore-
|
|
2
|
+
import { F as bytesToUtf8, G as posixPath } from './ValRouterCore-2f7ad9b9.esm.js';
|
|
3
3
|
import { result } from '@valbuild/core/fp';
|
|
4
4
|
import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-427d68c8.esm.js';
|
|
5
5
|
import '@valbuild/core';
|
package/dist/{getJsonEntryAtCommit-5552ac46.cjs.prod.js → getJsonEntryAtCommit-e519549a.cjs.prod.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
4
|
+
var ValRouterCore = require('./ValRouterCore-97c47cec.cjs.prod.js');
|
|
5
5
|
var fp = require('@valbuild/core/fp');
|
|
6
6
|
var jsonValuesModule = require('./jsonValuesModule-d1bb8d8f.cjs.prod.js');
|
|
7
7
|
require('@valbuild/core');
|
|
@@ -12,7 +12,7 @@ var path = require('path');
|
|
|
12
12
|
var fs = require('fs');
|
|
13
13
|
var vm = require('node:vm');
|
|
14
14
|
var node_module = require('node:module');
|
|
15
|
-
var ValRouterCore = require('./ValRouterCore-
|
|
15
|
+
var ValRouterCore = require('./ValRouterCore-946e45df.cjs.dev.js');
|
|
16
16
|
var server = require('@valbuild/ui/server');
|
|
17
17
|
var z = require('zod');
|
|
18
18
|
var zodValidationError = require('zod-validation-error');
|
|
@@ -4978,6 +4978,46 @@ function sameJson(a, b) {
|
|
|
4978
4978
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
4979
4979
|
}
|
|
4980
4980
|
|
|
4981
|
+
/**
|
|
4982
|
+
* A module's file with a patch written into it: what a save does to a
|
|
4983
|
+
* `.val.ts`, for one file and one patch, with nothing pending around it.
|
|
4984
|
+
*
|
|
4985
|
+
* The design tab's `create_patch` (valbuild/home `docs/design-tab.md`): there
|
|
4986
|
+
* the assistant changes a proposal's code, and content it writes goes into the
|
|
4987
|
+
* module's file and is staged with the code -- so a field it just added can
|
|
4988
|
+
* be filled in the same change, and is built and rendered with it.
|
|
4989
|
+
*
|
|
4990
|
+
* Only the module's own file. A `.jsonValues()` entry lives in a `*.val.json`
|
|
4991
|
+
* of its own, which a save routes to op by op (`ValOps.prepare`); a patch that
|
|
4992
|
+
* reaches into one fails here, and the message says to write that file.
|
|
4993
|
+
*/
|
|
4994
|
+
async function patchModuleText(text, patch$1) {
|
|
4995
|
+
// The TypeScript compiler, loaded when a patch asks for it, as a save loads
|
|
4996
|
+
// it: see `publishKit.ts`.
|
|
4997
|
+
const {
|
|
4998
|
+
tsOps,
|
|
4999
|
+
parseValFile
|
|
5000
|
+
} = await Promise.resolve().then(function () { return require('./publishKit-5865095c.cjs.dev.js'); });
|
|
5001
|
+
const applied = patch.applyPatch(parseValFile(text), tsOps, patch$1);
|
|
5002
|
+
if (fp.result.isErr(applied)) {
|
|
5003
|
+
const reason = messagesOf(applied.error).join(" ");
|
|
5004
|
+
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);
|
|
5005
|
+
}
|
|
5006
|
+
const sourceFile = applied.value;
|
|
5007
|
+
// As a save writes it: https://github.com/microsoft/TypeScript/issues/36174
|
|
5008
|
+
return fp.result.ok(unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u")));
|
|
5009
|
+
}
|
|
5010
|
+
|
|
5011
|
+
/**
|
|
5012
|
+
* A patch error, or a tree of syntax errors, as sentences. Walked here rather
|
|
5013
|
+
* than with `syntax.ts`'s `flattenErrors`, which would bring the compiler in
|
|
5014
|
+
* with this module.
|
|
5015
|
+
*/
|
|
5016
|
+
|
|
5017
|
+
function messagesOf(error) {
|
|
5018
|
+
return Array.isArray(error) ? error.flatMap(messagesOf) : [error.message];
|
|
5019
|
+
}
|
|
5020
|
+
|
|
4981
5021
|
/**
|
|
4982
5022
|
* Which of the site's pending changes a merge of a proposal moves into
|
|
4983
5023
|
* proposals of their own (valbuild/home `docs/hosted-publishing.md`, step 8.2,
|
|
@@ -5083,6 +5123,18 @@ const textEncoder$2 = new TextEncoder();
|
|
|
5083
5123
|
const PlanRefusedBody = z.z.object({
|
|
5084
5124
|
error: internal.PlanRefusalError
|
|
5085
5125
|
});
|
|
5126
|
+
|
|
5127
|
+
/** `POST /proposals-api/<name>/patch-file`: see `patchFileInProposal`. */
|
|
5128
|
+
const PatchFileBody = z.z.object({
|
|
5129
|
+
moduleFilePath: z.z.string().regex(/^\/.+\.val\.(ts|js)$/),
|
|
5130
|
+
patch: internal.Patch,
|
|
5131
|
+
message: z.z.string().max(500).optional()
|
|
5132
|
+
});
|
|
5133
|
+
|
|
5134
|
+
/** What `patchFileInProposal` reads of content's answer for a proposal's files. */
|
|
5135
|
+
const ProposalFilesRead = z.z.object({
|
|
5136
|
+
files: z.z.record(z.z.string(), z.z.string().nullable())
|
|
5137
|
+
});
|
|
5086
5138
|
const PatchId = z.z.string().refine(s => !!s); // TODO: validate
|
|
5087
5139
|
const CommitSha = z.z.string().refine(s => !!s); // TODO: validate
|
|
5088
5140
|
z.z.string().refine(s => !!s); // TODO: validate
|
|
@@ -5842,16 +5894,49 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5842
5894
|
* (valbuild/home `docs/adept.md`, step 6), reporting the typecheck of
|
|
5843
5895
|
* them (step 7, decision 20), serving a build of it
|
|
5844
5896
|
* (valbuild/home `docs/hosted-publishing.md`, step 7), or moving it onto the
|
|
5845
|
-
* site's code (step 8, "Update from the site")
|
|
5846
|
-
*
|
|
5847
|
-
*
|
|
5848
|
-
*
|
|
5849
|
-
* path is not such a write.
|
|
5897
|
+
* site's code (step 8, "Update from the site"). The proposal it names and
|
|
5898
|
+
* what it does, or `null` when this path is not such a write.
|
|
5899
|
+
*
|
|
5900
|
+
* Who may make one is {@link ValOpsHttp.mayWriteFiles}.
|
|
5850
5901
|
*/
|
|
5851
5902
|
static proposalFilesWrite(method, path) {
|
|
5852
|
-
var _exec;
|
|
5853
5903
|
if (method !== "POST") return null;
|
|
5854
|
-
|
|
5904
|
+
const match = /^\/([0-9a-f]{20})\/(files|lockfile|typecheck|build|update-from-site|restore-code)$/.exec(path);
|
|
5905
|
+
return match === null ? null : {
|
|
5906
|
+
name: match[1],
|
|
5907
|
+
write: match[2]
|
|
5908
|
+
};
|
|
5909
|
+
}
|
|
5910
|
+
|
|
5911
|
+
/**
|
|
5912
|
+
* The writes the SITE's server may make to a proposal's files: what the
|
|
5913
|
+
* design tab does (valbuild/home `docs/design-tab.md`, step 2) -- stage
|
|
5914
|
+
* code, build it, and report its typecheck. The tab is served by the site's
|
|
5915
|
+
* build so that a build the assistant breaks in the proposal cannot take
|
|
5916
|
+
* down the tools it would fix it with; at the proposal's address those
|
|
5917
|
+
* tools run on the proposal's own code.
|
|
5918
|
+
*
|
|
5919
|
+
* The typecheck too, though it blocks the proposal's Publish (adept.md,
|
|
5920
|
+
* decision 20): it is the proposal's staged files checked against the
|
|
5921
|
+
* site's, the same program from either address, and the content service
|
|
5922
|
+
* keeps it only for the inputs it was made from. Without it the tab's
|
|
5923
|
+
* Types check, and the assistant's `typecheck`, had nothing to show.
|
|
5924
|
+
*
|
|
5925
|
+
* The rest stay the proposal's own: Update from the site and the lockfile
|
|
5926
|
+
* are answered from the proposal's build and schemas, and bringing back a
|
|
5927
|
+
* point's code is the Studio at its address finishing a restore.
|
|
5928
|
+
*/
|
|
5929
|
+
static SITE_MAY_WRITE = new Set(["files", "build", "typecheck"]);
|
|
5930
|
+
|
|
5931
|
+
/**
|
|
5932
|
+
* Whether this server may make a write to a proposal's files: the
|
|
5933
|
+
* proposal's own server, any of them; the site's, the design tab's; and a
|
|
5934
|
+
* proposal's address, none to another proposal. Either way the site's own
|
|
5935
|
+
* files change only when a proposal is merged.
|
|
5936
|
+
*/
|
|
5937
|
+
mayWriteFiles(write) {
|
|
5938
|
+
if (this.proposal !== null) return write.name === this.proposal.name;
|
|
5939
|
+
return ValOpsHttp.SITE_MAY_WRITE.has(write.write);
|
|
5855
5940
|
}
|
|
5856
5941
|
|
|
5857
5942
|
/**
|
|
@@ -5878,12 +5963,16 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5878
5963
|
return /^\/publish-jobs\/[A-Za-z0-9_-]{1,100}\/(merge-prepare|steps|renew|cancel)$/.test(path);
|
|
5879
5964
|
}
|
|
5880
5965
|
async proposalsApi(path, init, profileId) {
|
|
5881
|
-
var _exec2, _exec3, _exec4, _exec5
|
|
5966
|
+
var _exec, _exec2, _exec3, _exec4, _exec5;
|
|
5882
5967
|
const json = "application/json";
|
|
5883
|
-
const updating = (
|
|
5968
|
+
const updating = (_exec = /^\/([0-9a-f]{20})\/update-content$/.exec(path)) === null || _exec === void 0 ? void 0 : _exec[1];
|
|
5884
5969
|
if (updating !== undefined && init.method === "POST") {
|
|
5885
5970
|
return this.updateContentFromSite(updating, init.body, profileId);
|
|
5886
5971
|
}
|
|
5972
|
+
const patching = (_exec2 = /^\/([0-9a-f]{20})\/patch-file$/.exec(path)) === null || _exec2 === void 0 ? void 0 : _exec2[1];
|
|
5973
|
+
if (patching !== undefined && init.method === "POST") {
|
|
5974
|
+
return this.patchFileInProposal(patching, init.body, profileId);
|
|
5975
|
+
}
|
|
5887
5976
|
const withCode = (_exec3 = /^\/([0-9a-f]{20})\/update-code$/.exec(path)) === null || _exec3 === void 0 ? void 0 : _exec3[1];
|
|
5888
5977
|
if (withCode !== undefined && init.method === "POST") {
|
|
5889
5978
|
return this.updateCodeFromSite(withCode, init.body, profileId);
|
|
@@ -5912,12 +6001,12 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5912
6001
|
};
|
|
5913
6002
|
}
|
|
5914
6003
|
const writes = ValOpsHttp.proposalFilesWrite(init.method, path);
|
|
5915
|
-
if (writes !== null &&
|
|
6004
|
+
if (writes !== null && !this.mayWriteFiles(writes)) {
|
|
5916
6005
|
return {
|
|
5917
6006
|
status: 403,
|
|
5918
6007
|
contentType: json,
|
|
5919
6008
|
body: JSON.stringify({
|
|
5920
|
-
message: this.proposal === null ? "
|
|
6009
|
+
message: this.proposal === null ? "Only the proposal's own Studio does this: open the proposal, and do it there." : "Files are changed in the proposal this Studio is open in, not in another."
|
|
5921
6010
|
})
|
|
5922
6011
|
};
|
|
5923
6012
|
}
|
|
@@ -5948,6 +6037,121 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5948
6037
|
};
|
|
5949
6038
|
}
|
|
5950
6039
|
|
|
6040
|
+
/**
|
|
6041
|
+
* A patch written into a module's FILE in a proposal, and staged there as
|
|
6042
|
+
* code: the design tab's `create_patch` (valbuild/home `docs/design-tab.md`).
|
|
6043
|
+
* The assistant there changes the proposal's code, so content it writes goes
|
|
6044
|
+
* with that code -- a field it just added is filled in the same change, and
|
|
6045
|
+
* built and rendered with it -- rather than into the proposal's saves, which
|
|
6046
|
+
* the site's server does not write.
|
|
6047
|
+
*
|
|
6048
|
+
* Answered here, at `POST /<name>/patch-file`: the file is the proposal's
|
|
6049
|
+
* copy if it has one, otherwise the one this build was made from, and the
|
|
6050
|
+
* patch is written into it as a save writes one (`patchModuleText`). Who may
|
|
6051
|
+
* is who may stage files: {@link ValOpsHttp.mayWriteFiles}.
|
|
6052
|
+
*/
|
|
6053
|
+
async patchFileInProposal(name, body, profileId) {
|
|
6054
|
+
var _this$projectSource, _this$options;
|
|
6055
|
+
const json = "application/json";
|
|
6056
|
+
const answer = (status, value) => ({
|
|
6057
|
+
status,
|
|
6058
|
+
contentType: json,
|
|
6059
|
+
body: JSON.stringify(value)
|
|
6060
|
+
});
|
|
6061
|
+
if (!this.mayWriteFiles({
|
|
6062
|
+
name,
|
|
6063
|
+
write: "files"
|
|
6064
|
+
})) {
|
|
6065
|
+
return answer(403, {
|
|
6066
|
+
message: "Files are changed in the proposal this Studio is open in, not in another."
|
|
6067
|
+
});
|
|
6068
|
+
}
|
|
6069
|
+
let parsedBody;
|
|
6070
|
+
try {
|
|
6071
|
+
parsedBody = body === undefined || body === "" ? {} : JSON.parse(body);
|
|
6072
|
+
} catch {
|
|
6073
|
+
return answer(400, {
|
|
6074
|
+
message: "The patch's body is not JSON."
|
|
6075
|
+
});
|
|
6076
|
+
}
|
|
6077
|
+
const request = PatchFileBody.safeParse(parsedBody);
|
|
6078
|
+
if (!request.success) {
|
|
6079
|
+
return answer(400, {
|
|
6080
|
+
message: `Invalid patch: ${zodValidationError.fromError(request.error).toString()}`
|
|
6081
|
+
});
|
|
6082
|
+
}
|
|
6083
|
+
const {
|
|
6084
|
+
moduleFilePath,
|
|
6085
|
+
patch,
|
|
6086
|
+
message
|
|
6087
|
+
} = request.data;
|
|
6088
|
+
const content = this.proposalContent(name, profileId);
|
|
6089
|
+
const read = await content("/files");
|
|
6090
|
+
if (!read.ok) {
|
|
6091
|
+
return {
|
|
6092
|
+
status: read.status,
|
|
6093
|
+
contentType: json,
|
|
6094
|
+
body: await read.text()
|
|
6095
|
+
};
|
|
6096
|
+
}
|
|
6097
|
+
const files = ProposalFilesRead.safeParse(await read.json());
|
|
6098
|
+
if (!files.success) {
|
|
6099
|
+
return answer(502, {
|
|
6100
|
+
message: `Content answered the proposal's files in a shape this Val does not read: ${zodValidationError.fromError(files.error).toString()}`
|
|
6101
|
+
});
|
|
6102
|
+
}
|
|
6103
|
+
const filePath = moduleFilePath.replace(/^\/+/, "");
|
|
6104
|
+
const own = files.data.files[filePath];
|
|
6105
|
+
if (own === null) {
|
|
6106
|
+
return answer(409, {
|
|
6107
|
+
message: `${moduleFilePath} is deleted in this proposal.`
|
|
6108
|
+
});
|
|
6109
|
+
}
|
|
6110
|
+
if (own === undefined && this.projectSource === null) {
|
|
6111
|
+
return answer(409, {
|
|
6112
|
+
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.`
|
|
6113
|
+
});
|
|
6114
|
+
}
|
|
6115
|
+
const text = own ?? ((_this$projectSource = this.projectSource) === null || _this$projectSource === void 0 ? void 0 : _this$projectSource[filePath]);
|
|
6116
|
+
if (text === undefined) {
|
|
6117
|
+
return answer(404, {
|
|
6118
|
+
message: `There is no module file ${moduleFilePath} in this proposal or on the site.`
|
|
6119
|
+
});
|
|
6120
|
+
}
|
|
6121
|
+
const patched = await patchModuleText(text, patch);
|
|
6122
|
+
if (fp.result.isErr(patched)) {
|
|
6123
|
+
return answer(422, {
|
|
6124
|
+
message: `The patch does not apply to ${moduleFilePath}: ${patched.error}`
|
|
6125
|
+
});
|
|
6126
|
+
}
|
|
6127
|
+
let formatted = patched.value;
|
|
6128
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.formatter) {
|
|
6129
|
+
try {
|
|
6130
|
+
formatted = await this.options.formatter(patched.value, moduleFilePath);
|
|
6131
|
+
} catch (error) {
|
|
6132
|
+
return answer(422, {
|
|
6133
|
+
message: `The patched ${moduleFilePath} could not be formatted: ${error instanceof Error ? error.message : String(error)}`
|
|
6134
|
+
});
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
const staged = await content("/files", {
|
|
6138
|
+
method: "POST",
|
|
6139
|
+
body: JSON.stringify({
|
|
6140
|
+
files: {
|
|
6141
|
+
[filePath]: formatted
|
|
6142
|
+
},
|
|
6143
|
+
...(message !== undefined ? {
|
|
6144
|
+
message
|
|
6145
|
+
} : {})
|
|
6146
|
+
})
|
|
6147
|
+
});
|
|
6148
|
+
return {
|
|
6149
|
+
status: staged.status,
|
|
6150
|
+
contentType: staged.headers.get("Content-Type") ?? json,
|
|
6151
|
+
body: await staged.text()
|
|
6152
|
+
};
|
|
6153
|
+
}
|
|
6154
|
+
|
|
5951
6155
|
/**
|
|
5952
6156
|
* Update from the site, for a proposal that changes only content
|
|
5953
6157
|
* (valbuild/home `docs/hosted-publishing.md`, step 8.2, slice 1a): content
|
|
@@ -5962,14 +6166,14 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
5962
6166
|
* with their `resolutions` merges.
|
|
5963
6167
|
*/
|
|
5964
6168
|
async updateContentFromSite(name, body, profileId) {
|
|
5965
|
-
var _this$
|
|
6169
|
+
var _this$proposal;
|
|
5966
6170
|
const json = "application/json";
|
|
5967
6171
|
const answer = (status, value) => ({
|
|
5968
6172
|
status,
|
|
5969
6173
|
contentType: json,
|
|
5970
6174
|
body: JSON.stringify(value)
|
|
5971
6175
|
});
|
|
5972
|
-
if (((_this$
|
|
6176
|
+
if (((_this$proposal = this.proposal) === null || _this$proposal === void 0 ? void 0 : _this$proposal.name) !== name) {
|
|
5973
6177
|
return answer(403, {
|
|
5974
6178
|
message: "A proposal is updated from the site at its own address, where its build is."
|
|
5975
6179
|
});
|
|
@@ -6239,14 +6443,14 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6239
6443
|
* Only at the proposal's own address, as every write to its files is.
|
|
6240
6444
|
*/
|
|
6241
6445
|
async updateCodeFromSite(name, body, profileId) {
|
|
6242
|
-
var _this$
|
|
6446
|
+
var _this$proposal2;
|
|
6243
6447
|
const json = "application/json";
|
|
6244
6448
|
const answer = (status, value) => ({
|
|
6245
6449
|
status,
|
|
6246
6450
|
contentType: json,
|
|
6247
6451
|
body: JSON.stringify(value)
|
|
6248
6452
|
});
|
|
6249
|
-
if (((_this$
|
|
6453
|
+
if (((_this$proposal2 = this.proposal) === null || _this$proposal2 === void 0 ? void 0 : _this$proposal2.name) !== name) {
|
|
6250
6454
|
return answer(403, {
|
|
6251
6455
|
message: "A proposal is updated from the site at its own address, where its files are written."
|
|
6252
6456
|
});
|
|
@@ -6692,8 +6896,8 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
6692
6896
|
|
|
6693
6897
|
/** The branch this server's patches are on, where it knows it. */
|
|
6694
6898
|
ownBranch() {
|
|
6695
|
-
var _this$
|
|
6696
|
-
return ((_this$
|
|
6899
|
+
var _this$proposal3, _this$git;
|
|
6900
|
+
return ((_this$proposal3 = this.proposal) === null || _this$proposal3 === void 0 ? void 0 : _this$proposal3.branch) ?? ((_this$git = this.git) === null || _this$git === void 0 ? void 0 : _this$git.branch);
|
|
6697
6901
|
}
|
|
6698
6902
|
async getWebSocketNonce(profileId) {
|
|
6699
6903
|
return fetch(`${this.contentUrl}/v1/${this.project}/websocket/nonces`, {
|
|
@@ -7458,13 +7662,13 @@ class ValOpsHttp extends ValRouterCore.ValOps {
|
|
|
7458
7662
|
*/
|
|
7459
7663
|
intoProposal) {
|
|
7460
7664
|
try {
|
|
7461
|
-
var _this$
|
|
7665
|
+
var _this$proposal4, _res$headers$get3;
|
|
7462
7666
|
/*
|
|
7463
7667
|
* A save in a proposal is a commit on the proposal's branch, at its own
|
|
7464
7668
|
* route: the site's `/commit` refuses a proposal's patches, which is
|
|
7465
7669
|
* the line that keeps them off the site until a merge.
|
|
7466
7670
|
*/
|
|
7467
|
-
const proposalName = intoProposal ?? ((_this$
|
|
7671
|
+
const proposalName = intoProposal ?? ((_this$proposal4 = this.proposal) === null || _this$proposal4 === void 0 ? void 0 : _this$proposal4.name);
|
|
7468
7672
|
const commitUrl = proposalName !== undefined ? `${this.contentUrl}/v1/${this.project}/proposals/${proposalName}/save` : `${this.contentUrl}/v1/${this.project}/commit`;
|
|
7469
7673
|
const res = await fetch(commitUrl, {
|
|
7470
7674
|
method: "POST",
|