@valbuild/server 0.154.4 → 0.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
  3. package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
  4. package/browser/dist/valbuild-server-browser.esm.js +2 -2
  5. package/dist/{ValOpsMemory-a1a58597.cjs.prod.js → ValOpsMemory-073f9526.cjs.prod.js} +1 -1
  6. package/dist/{ValOpsMemory-88633e0f.cjs.dev.js → ValOpsMemory-3ce3e9e8.cjs.dev.js} +1 -1
  7. package/dist/{ValOpsMemory-82af54c9.esm.js → ValOpsMemory-ecc15827.esm.js} +1 -1
  8. package/dist/{createPrettierFormatter-5d830bdf.cjs.dev.js → createPrettierFormatter-8e60f596.cjs.prod.js} +1 -1
  9. package/dist/{createPrettierFormatter-b31bfbe5.cjs.prod.js → createPrettierFormatter-a9109288.cjs.dev.js} +1 -1
  10. package/dist/{createPrettierFormatter-ce478de1.esm.js → createPrettierFormatter-fb68e363.esm.js} +1 -1
  11. package/dist/{createValRuntime-d34c69e8.esm.js → createValRuntime-02197b93.esm.js} +6 -4
  12. package/dist/{createValRuntime-07bf43dd.cjs.prod.js → createValRuntime-42622f8f.cjs.prod.js} +6 -4
  13. package/dist/{createValRuntime-858474b4.cjs.dev.js → createValRuntime-b55d14f0.cjs.dev.js} +6 -4
  14. package/dist/declarations/src/internal/index.d.ts +14 -0
  15. package/dist/declarations/src/proposalMerge/foldContent.d.ts +45 -0
  16. package/dist/declarations/src/proposalMerge/project.d.ts +124 -0
  17. package/dist/declarations/src/proposalMerge/threeWay.d.ts +51 -0
  18. package/dist/declarations/src/proposalMerge/validate.d.ts +16 -0
  19. package/dist/foldContent-2c218a30.cjs.dev.js +216 -0
  20. package/dist/foldContent-54f2c87c.cjs.prod.js +216 -0
  21. package/dist/foldContent-f065c19f.esm.js +214 -0
  22. package/dist/{inTabFetch-e9a48fac.cjs.prod.js → inTabFetch-46ad6b87.cjs.prod.js} +1 -1
  23. package/dist/{inTabFetch-54c1cb83.esm.js → inTabFetch-6dacc8a1.esm.js} +1 -1
  24. package/dist/{inTabFetch-fb9cf5e0.cjs.dev.js → inTabFetch-85b1aef4.cjs.dev.js} +1 -1
  25. package/dist/{proposalJsonEntries-2cd6f6fe.esm.js → jsonValuesModule-12fc4bb0.esm.js} +2 -128
  26. package/dist/{proposalJsonEntries-d21900d4.cjs.dev.js → jsonValuesModule-6cf73937.cjs.prod.js} +2 -130
  27. package/dist/{proposalJsonEntries-d4623810.cjs.prod.js → jsonValuesModule-ed68a9de.cjs.dev.js} +2 -130
  28. package/dist/merge-5a8fc685.cjs.prod.js +1596 -0
  29. package/dist/merge-a21a9c78.cjs.dev.js +1596 -0
  30. package/dist/merge-eca8ec38.esm.js +1566 -0
  31. package/dist/proposalJsonEntries-4fcfab08.cjs.prod.js +135 -0
  32. package/dist/proposalJsonEntries-878ad5b6.cjs.dev.js +135 -0
  33. package/dist/proposalJsonEntries-e1b07915.esm.js +128 -0
  34. package/dist/{publishKit-cf3858a0.cjs.prod.js → publishKit-70276aed.cjs.prod.js} +19 -22
  35. package/dist/{publishKit-4e7a1516.esm.js → publishKit-a732e3c3.esm.js} +11 -14
  36. package/dist/{publishKit-6b88a02e.cjs.dev.js → publishKit-f7a77be5.cjs.dev.js} +19 -22
  37. package/dist/{valRuntime-ca9958fc.esm.js → valRuntime-407399c1.esm.js} +11 -982
  38. package/dist/{valRuntime-5cadce34.cjs.dev.js → valRuntime-7a4bbb5d.cjs.dev.js} +21 -995
  39. package/dist/{valRuntime-ae69b225.cjs.prod.js → valRuntime-8585d3ce.cjs.prod.js} +21 -995
  40. package/dist/valbuild-server.cjs.dev.js +45 -462
  41. package/dist/valbuild-server.cjs.prod.js +45 -462
  42. package/dist/valbuild-server.esm.js +15 -431
  43. package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
  44. package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
  45. package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
  46. package/internal/dist/valbuild-server-internal.cjs.dev.js +20 -2
  47. package/internal/dist/valbuild-server-internal.cjs.prod.js +20 -2
  48. package/internal/dist/valbuild-server-internal.esm.js +20 -3
  49. package/package.json +4 -4
@@ -1,368 +1,20 @@
1
- import { Internal, deserializeSchema, DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
- import { q as summaryOf, t as matchesFilter, w as byUpdatedAt, x as newSketchpad, y as isSketchpadId, z as applySketchpadChange, A as ValOps, h as VAL_CLIENT_HEADERS, B as isSafePatchId, C as isMediaFilePath, M as MEDIA_FILE_PATH_ACCEPTS, D as bufferFromDataUrl, d as getFieldsForType, u as uploadRemoteFile, g as getFileExt, E as isPublicFilePath, F as guessMimeTypeFromPath, G as createMetadataFromBuffer, H as fetchFresh, I as DEFAULT_ANALYTICS_INGEST_URL, o as ValOpsMemory, J as sessionAuth, K as isHttpOps } from './ValOpsMemory-82af54c9.esm.js';
1
+ import { Internal, DEFAULT_CONTENT_HOST } from '@valbuild/core';
2
+ import { q as summaryOf, t as matchesFilter, w as byUpdatedAt, x as newSketchpad, y as isSketchpadId, z as applySketchpadChange, A as ValOps, h as VAL_CLIENT_HEADERS, B as isSafePatchId, C as isMediaFilePath, M as MEDIA_FILE_PATH_ACCEPTS, D as bufferFromDataUrl, d as getFieldsForType, u as uploadRemoteFile, g as getFileExt, E as isPublicFilePath, F as guessMimeTypeFromPath, G as createMetadataFromBuffer, H as fetchFresh, I as DEFAULT_ANALYTICS_INGEST_URL, o as ValOpsMemory, J as sessionAuth, K as isHttpOps } from './ValOpsMemory-ecc15827.esm.js';
3
3
  import path from 'path';
4
4
  import ts from 'typescript';
5
5
  import { z } from 'zod';
6
6
  import fs from 'fs';
7
7
  import { fromError } from 'zod-validation-error';
8
- import { pipe, result } from '@valbuild/core/fp';
9
- import { a as analyzeValModule, e as findObjectPropertyAssignment, g as findObjectPropertyAssignmentToRemove, h as evaluateExpression, s as shallowValidateExpression, v as validateInitializers, c as analyzeJsonValuesEntries, i as proposalJsonEntries } from './proposalJsonEntries-2cd6f6fe.esm.js';
8
+ import { result } from '@valbuild/core/fp';
9
+ import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-12fc4bb0.esm.js';
10
10
  import { r as resolveExistingJsonPath } from './jsonValuesPatch-13acc674.esm.js';
11
- import { Patch, Sketchpad, schemaErrorsOf, PatchSets, joinSharedChanges, schemaTypesOfPath, sideFiles, sideSource, JSONValue, SketchpadSummary, getErrorMessageFromUnknownJson, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, valModulesEntryPath, newestCommitSha, isCrossRequestError } from '@valbuild/shared/internal';
11
+ import { Patch, Sketchpad, sideFiles, sideSource, JSONValue, SketchpadSummary, getErrorMessageFromUnknownJson, PlanRefusalError, PatchId as PatchId$1, SerializedSchema, valModulesEntryPath, newestCommitSha, isCrossRequestError } from '@valbuild/shared/internal';
12
12
  import os from 'os';
13
13
  import crypto$1, { randomBytes, createHash } from 'crypto';
14
14
  import { Buffer as Buffer$1 } from 'buffer';
15
- import { l as layeredSnapshot, s as stagedAfterBuild, e as servingBuildOf, a as proposalSnapshot, n as namedMode, f as selectsHttpMode } from './createPrettierFormatter-ce478de1.esm.js';
16
- import { PatchError, deepEqual, isNotRoot, parseAndValidateArrayIndex, applyPatch, deepClone, JSONOps } from '@valbuild/core/patch';
17
- import 'node:vm';
18
- import 'node:module';
19
-
20
- function isValidIdentifier(text) {
21
- if (text.length === 0) {
22
- return false;
23
- }
24
- if (!ts.isIdentifierStart(text.charCodeAt(0), ts.ScriptTarget.ES2020)) {
25
- return false;
26
- }
27
- for (let i = 1; i < text.length; ++i) {
28
- if (!ts.isIdentifierPart(text.charCodeAt(i), ts.ScriptTarget.ES2020)) {
29
- return false;
30
- }
31
- }
32
- return true;
33
- }
34
- function createPropertyAssignment(key, value) {
35
- return ts.factory.createPropertyAssignment(isValidIdentifier(key) ? ts.factory.createIdentifier(key) : ts.factory.createStringLiteral(key), toExpression(value));
36
- }
37
-
38
- /**
39
- * Builds the expression `c.json(() => import("<importPath>"))` used to reference
40
- * a lazily-loaded `*.val.json` entry of a `.jsonValues()` record.
41
- */
42
- function createValJsonReference(importPath) {
43
- // () => import("<importPath>")
44
- // NOTE: an `import` identifier prints as the dynamic-import keyword call,
45
- // which avoids casting the ImportKeyword token (not typed as an Expression).
46
- const importCall = ts.factory.createCallExpression(ts.factory.createIdentifier("import"), undefined, [ts.factory.createStringLiteral(importPath)]);
47
- const thunk = ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), importCall);
48
- // c.json(<thunk>)
49
- return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("c"), ts.factory.createIdentifier("json")), undefined, [thunk]);
50
- }
51
-
52
- /**
53
- * Inserts a new `.jsonValues()` entry `"<key>": c.json(() => import("<importPath>"))`
54
- * into the record's object literal in a `.val.ts` module. `recordPath` is the
55
- * path from the module source to the record (empty for a root record/router).
56
- * Fails if the entry key already exists.
57
- */
58
- function insertValJsonEntry(document, recordPath, key, importPath) {
59
- return pipe(analyzeValModule(document), result.flatMap(({
60
- source
61
- }) => getAtPath(source, recordPath)), result.flatMap(recordNode => {
62
- if (!ts.isObjectLiteralExpression(recordNode)) {
63
- return result.err(new PatchError("Cannot add jsonValues entry: record source is not an object literal"));
64
- }
65
- return pipe(findObjectPropertyAssignment(recordNode, key), result.flatMap(assignment => {
66
- if (assignment) {
67
- return result.err(new PatchError(`Cannot add jsonValues entry '${key}': it already exists`));
68
- }
69
- const property = ts.factory.createPropertyAssignment(isValidIdentifier(key) ? ts.factory.createIdentifier(key) : ts.factory.createStringLiteral(key), createValJsonReference(importPath));
70
- return result.ok(insertAt(document, recordNode.properties, recordNode.properties.length, property));
71
- }));
72
- }));
73
- }
74
-
75
- /**
76
- * Removes the `.jsonValues()` entry `"<key>"` from the record's object literal
77
- * in a `.val.ts` module. `recordPath` is the path from the module source to the
78
- * record (empty for a root record/router). Fails if the entry key is missing.
79
- */
80
- function removeValJsonEntry(document, recordPath, key) {
81
- return pipe(analyzeValModule(document), result.flatMap(({
82
- source
83
- }) => getAtPath(source, recordPath)), result.flatMap(recordNode => {
84
- if (!ts.isObjectLiteralExpression(recordNode)) {
85
- return result.err(new PatchError("Cannot remove jsonValues entry: record source is not an object literal"));
86
- }
87
- return pipe(findObjectPropertyAssignmentToRemove(recordNode, key), result.flatMap(assignment => {
88
- if (!assignment) {
89
- return result.err(new PatchError(`Cannot remove jsonValues entry '${key}': it does not exist`));
90
- }
91
- const [doc] = removeAt(document, recordNode.properties, recordNode.properties.indexOf(assignment));
92
- return result.ok(doc);
93
- }));
94
- }));
95
- }
96
- function toExpression(value) {
97
- if (typeof value === "string") {
98
- // TODO: Use configuration/heuristics to determine use of single quote or double quote
99
- return ts.factory.createStringLiteral(value);
100
- } else if (typeof value === "number") {
101
- // TODO: do we want to do something like this for very large numbers?
102
- // if (value > Number.MAX_SAFE_INTEGER) {
103
- // return ts.factory.createBigIntLiteral(`${value}n`);
104
- // }
105
- // if (value < Number.MIN_SAFE_INTEGER) {
106
- // return ts.factory.createPrefixUnaryExpression(
107
- // ts.SyntaxKind.MinusToken,
108
- // ts.factory.createBigIntLiteral(`${value}n`),
109
- // );
110
- // }
111
- if (value < 0) {
112
- return ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(Math.abs(value)));
113
- }
114
- return ts.factory.createNumericLiteral(value);
115
- } else if (typeof value === "boolean") {
116
- return value ? ts.factory.createTrue() : ts.factory.createFalse();
117
- } else if (value === null) {
118
- return ts.factory.createNull();
119
- } else if (Array.isArray(value)) {
120
- return ts.factory.createArrayLiteralExpression(value.map(toExpression));
121
- } else if (typeof value === "object") {
122
- return ts.factory.createObjectLiteralExpression(Object.entries(value)
123
- // `patch_id` is injected server-side onto a media source whose bytes are
124
- // not committed yet. It describes the draft, not the content, and a
125
- // whole-object write built from the client's optimistic view would
126
- // otherwise print it into the user's file.
127
- .filter(([key]) => key !== "patch_id").map(([key, value]) => createPropertyAssignment(key, value)));
128
- } else {
129
- return ts.factory.createStringLiteral(value);
130
- }
131
- }
132
-
133
- // TODO: Choose newline based on project settings/heuristics/system default?
134
- const newLine = ts.NewLineKind.LineFeed;
135
- // TODO: Handle indentation of printed code
136
- const printer = ts.createPrinter({
137
- newLine: newLine
138
- // neverAsciiEscape: true,
139
- });
140
- function replaceNodeValue(document, node, value) {
141
- const replacementText = printer.printNode(ts.EmitHint.Unspecified, toExpression(value), document);
142
- const span = ts.createTextSpanFromBounds(node.getStart(document, false), node.end);
143
- const newText = `${document.text.substring(0, span.start)}${replacementText}${document.text.substring(ts.textSpanEnd(span))}`;
144
- return [document.update(newText, ts.createTextChangeRange(span, replacementText.length)), node];
145
- }
146
- function isIndentation(s) {
147
- for (let i = 0; i < s.length; ++i) {
148
- const c = s.charAt(i);
149
- if (c !== " " && c !== "\t") {
150
- return false;
151
- }
152
- }
153
- return true;
154
- }
155
- function newLineStr(kind) {
156
- if (kind === ts.NewLineKind.CarriageReturnLineFeed) {
157
- return "\r\n";
158
- } else {
159
- return "\n";
160
- }
161
- }
162
- function getSeparator(document, neighbor) {
163
- const startPos = neighbor.getStart(document, true);
164
- const basis = document.getLineAndCharacterOfPosition(startPos);
165
- const lineStartPos = document.getPositionOfLineAndCharacter(basis.line, 0);
166
- const maybeIndentation = document.getText().substring(lineStartPos, startPos);
167
- if (isIndentation(maybeIndentation)) {
168
- return `,${newLineStr(newLine)}${maybeIndentation}`;
169
- } else {
170
- return `, `;
171
- }
172
- }
173
- function insertAt(document, nodes, index, node) {
174
- let span;
175
- let replacementText;
176
- if (nodes.length === 0) {
177
- // Replace entire range of nodes
178
- replacementText = printer.printNode(ts.EmitHint.Unspecified, node, document);
179
- span = ts.createTextSpanFromBounds(nodes.pos, nodes.end);
180
- } else if (index === nodes.length) {
181
- // Insert after last node
182
- const neighbor = nodes[nodes.length - 1];
183
- replacementText = `${getSeparator(document, neighbor)}${printer.printNode(ts.EmitHint.Unspecified, node, document)}`;
184
- span = ts.createTextSpan(neighbor.end, 0);
185
- } else {
186
- // Insert before node
187
- const neighbor = nodes[index];
188
- replacementText = `${printer.printNode(ts.EmitHint.Unspecified, node, document)}${getSeparator(document, neighbor)}`;
189
- span = ts.createTextSpan(neighbor.getStart(document, true), 0);
190
- }
191
- const newText = `${document.text.substring(0, span.start)}${replacementText}${document.text.substring(ts.textSpanEnd(span))}`;
192
- return document.update(newText, ts.createTextChangeRange(span, replacementText.length));
193
- }
194
- function removeAt(document, nodes, index) {
195
- const node = nodes[index];
196
- let span;
197
- if (nodes.length === 1) {
198
- span = ts.createTextSpanFromBounds(nodes.pos, nodes.end);
199
- } else if (index === nodes.length - 1) {
200
- // Remove until previous node
201
- const neighbor = nodes[index - 1];
202
- span = ts.createTextSpanFromBounds(neighbor.end, node.end);
203
- } else {
204
- // Remove before next node
205
- const neighbor = nodes[index + 1];
206
- span = ts.createTextSpanFromBounds(node.getStart(document, true), neighbor.getStart(document, true));
207
- }
208
- const newText = `${document.text.substring(0, span.start)}${document.text.substring(ts.textSpanEnd(span))}`;
209
- return [document.update(newText, ts.createTextChangeRange(span, 0)), node];
210
- }
211
- function parseAndValidateArrayInsertIndex(key, nodes) {
212
- if (key === "-") {
213
- // For insertion, all nodes up until the insertion index must be valid
214
- // initializers
215
- const err = validateInitializers(nodes);
216
- if (err) {
217
- return result.err(err);
218
- }
219
- return result.ok(nodes.length);
220
- }
221
- return pipe(parseAndValidateArrayIndex(key), result.flatMap(index => {
222
- // For insertion, all nodes up until the insertion index must be valid
223
- // initializers
224
- const err = validateInitializers(nodes.slice(0, index));
225
- if (err) {
226
- return result.err(err);
227
- }
228
- if (index > nodes.length) {
229
- return result.err(new PatchError("Array index out of bounds"));
230
- } else {
231
- return result.ok(index);
232
- }
233
- }));
234
- }
235
- function parseAndValidateArrayInboundsIndex(key, nodes) {
236
- return pipe(parseAndValidateArrayIndex(key), result.flatMap(index => {
237
- // For in-bounds operations, all nodes up until and including the index
238
- // must be valid initializers
239
- const err = validateInitializers(nodes.slice(0, index + 1));
240
- if (err) {
241
- return result.err(err);
242
- }
243
- if (index >= nodes.length) {
244
- return result.err(new PatchError("Array index out of bounds"));
245
- } else {
246
- return result.ok(index);
247
- }
248
- }));
249
- }
250
- function replaceInNode(document, node, key, value) {
251
- if (ts.isArrayLiteralExpression(node)) {
252
- return pipe(parseAndValidateArrayInboundsIndex(key, node.elements), result.map(index => replaceNodeValue(document, node.elements[index], value)));
253
- } else if (ts.isObjectLiteralExpression(node)) {
254
- return pipe(findObjectPropertyAssignment(node, key), result.flatMap(assignment => {
255
- if (!assignment) {
256
- return result.err(new PatchError("Cannot replace object element which does not exist"));
257
- }
258
- return result.ok(assignment);
259
- }), result.map(assignment => replaceNodeValue(document, assignment.initializer, value)));
260
- } else {
261
- return result.err(shallowValidateExpression(node) ?? new PatchError("Cannot replace in non-object/array"));
262
- }
263
- }
264
- function replaceAtPath(document, rootNode, path, value) {
265
- if (isNotRoot(path)) {
266
- return pipe(getPointerFromPath(rootNode, path), result.flatMap(([node, key]) => replaceInNode(document, node, key, value)));
267
- } else {
268
- return result.ok(replaceNodeValue(document, rootNode, value));
269
- }
270
- }
271
- function getFromNode(node, key) {
272
- if (ts.isArrayLiteralExpression(node)) {
273
- return pipe(parseAndValidateArrayInboundsIndex(key, node.elements), result.map(index => node.elements[index]));
274
- } else if (ts.isObjectLiteralExpression(node)) {
275
- return pipe(findObjectPropertyAssignment(node, key), result.map(assignment => assignment === null || assignment === void 0 ? void 0 : assignment.initializer));
276
- } else {
277
- return result.err(shallowValidateExpression(node) ?? new PatchError("Cannot access non-object/array"));
278
- }
279
- }
280
- function getPointerFromPath(node, path) {
281
- let targetNode = node;
282
- let key = path[0];
283
- for (let i = 0; i < path.length - 1; ++i, key = path[i]) {
284
- const childNode = getFromNode(targetNode, key);
285
- if (result.isErr(childNode)) {
286
- return childNode;
287
- }
288
- if (childNode.value === undefined) {
289
- return result.err(new PatchError(`Path refers to non-existing object/array: ${path.join("/")}`));
290
- }
291
- targetNode = childNode.value;
292
- }
293
- return result.ok([targetNode, key]);
294
- }
295
- function getAtPath(rootNode, path) {
296
- return pipe(path, result.flatMapReduce((node, key) => pipe(getFromNode(node, key), result.filterOrElse(childNode => childNode !== undefined, () => new PatchError("Path refers to non-existing object/array"))), rootNode));
297
- }
298
- function removeFromNode(document, node, key) {
299
- if (ts.isArrayLiteralExpression(node)) {
300
- return pipe(parseAndValidateArrayInboundsIndex(key, node.elements), result.map(index => removeAt(document, node.elements, index)));
301
- } else if (ts.isObjectLiteralExpression(node)) {
302
- return pipe(findObjectPropertyAssignmentToRemove(node, key), result.flatMap(assignment => {
303
- if (!assignment) {
304
- return result.err(new PatchError("Cannot remove object element which does not exist"));
305
- }
306
- return result.ok(assignment);
307
- }), result.map(assignment => [removeAt(document, node.properties, node.properties.indexOf(assignment))[0], assignment.initializer]));
308
- } else {
309
- return result.err(shallowValidateExpression(node) ?? new PatchError("Cannot remove from non-object/array"));
310
- }
311
- }
312
- function removeAtPath(document, rootNode, path) {
313
- return pipe(getPointerFromPath(rootNode, path), result.flatMap(([node, key]) => removeFromNode(document, node, key)));
314
- }
315
- function addToNode(document, node, key, value) {
316
- if (ts.isArrayLiteralExpression(node)) {
317
- return pipe(parseAndValidateArrayInsertIndex(key, node.elements), result.map(index => [insertAt(document, node.elements, index, toExpression(value))]));
318
- } else if (ts.isObjectLiteralExpression(node)) {
319
- return pipe(findObjectPropertyAssignment(node, key), result.map(assignment => {
320
- if (!assignment) {
321
- return [insertAt(document, node.properties, node.properties.length, createPropertyAssignment(key, value))];
322
- } else {
323
- return replaceNodeValue(document, assignment.initializer, value);
324
- }
325
- }));
326
- } else {
327
- return result.err(shallowValidateExpression(node) ?? new PatchError("Cannot add to non-object/array"));
328
- }
329
- }
330
- function addAtPath(document, rootNode, path, value) {
331
- if (isNotRoot(path)) {
332
- return pipe(getPointerFromPath(rootNode, path), result.flatMap(([node, key]) => addToNode(document, node, key, value)));
333
- } else {
334
- return result.ok(replaceNodeValue(document, rootNode, value));
335
- }
336
- }
337
- function pickDocument([document]) {
338
- return document;
339
- }
340
- class TSOps {
341
- constructor(findRoot) {
342
- this.findRoot = findRoot;
343
- }
344
- get(document, path) {
345
- return pipe(document, this.findRoot, result.flatMap(rootNode => getAtPath(rootNode, path)), result.flatMap(evaluateExpression));
346
- }
347
- add(document, path, value) {
348
- return pipe(document, this.findRoot, result.flatMap(rootNode => addAtPath(document, rootNode, path, value)), result.map(pickDocument));
349
- }
350
- remove(document, path) {
351
- return pipe(document, this.findRoot, result.flatMap(rootNode => removeAtPath(document, rootNode, path)), result.map(pickDocument));
352
- }
353
- replace(document, path, value) {
354
- return pipe(document, this.findRoot, result.flatMap(rootNode => replaceAtPath(document, rootNode, path, value)), result.map(pickDocument));
355
- }
356
- move(document, from, path) {
357
- return pipe(document, this.findRoot, result.flatMap(rootNode => removeAtPath(document, rootNode, from)), result.flatMap(([document, removedNode]) => pipe(evaluateExpression(removedNode), result.map(removedValue => [document, removedValue]))), result.flatMap(([document, removedValue]) => pipe(document, this.findRoot, result.flatMap(root => addAtPath(document, root, path, removedValue)))), result.map(pickDocument));
358
- }
359
- copy(document, from, path) {
360
- return pipe(document, this.findRoot, result.flatMap(rootNode => pipe(getAtPath(rootNode, from), result.flatMap(evaluateExpression), result.flatMap(value => addAtPath(document, rootNode, path, value)))), result.map(pickDocument));
361
- }
362
- test(document, path, value) {
363
- return pipe(document, this.findRoot, result.flatMap(rootNode => getAtPath(rootNode, path)), result.flatMap(evaluateExpression), result.map(documentValue => deepEqual(value, documentValue)));
364
- }
365
- }
15
+ import { proposalJsonEntries } from './proposalJsonEntries-e1b07915.esm.js';
16
+ import { l as layeredSnapshot, s as stagedAfterBuild, e as servingBuildOf, a as proposalSnapshot, n as namedMode, f as selectsHttpMode } from './createPrettierFormatter-fb68e363.esm.js';
17
+ import { m as mergeValues, d as diffOps, b as resolveContent, v as validateWith, e as valueAt, w as writeContent, h as atomicFor, j as mergeFromSite, s as schemaCheck, k as entryFilesOf, n as changesToMove } from './merge-eca8ec38.esm.js';
366
18
 
367
19
  /**
368
20
  * The `*.val.json` files backing a `.jsonValues()` module's entries, as paths
@@ -1861,7 +1513,7 @@ function createFsSketchpadStore(rootDir, now = () => new Date()) {
1861
1513
  * as a bundler does.
1862
1514
  */
1863
1515
  function loadTypeScriptKit() {
1864
- return import('./publishKit-4e7a1516.esm.js');
1516
+ return import('./publishKit-a732e3c3.esm.js');
1865
1517
  }
1866
1518
 
1867
1519
  /** Serializes a schema, or gives up quietly — serialization errors are reported elsewhere. */
@@ -3280,629 +2932,6 @@ class FSOpsHost {
3280
2932
  }
3281
2933
  }
3282
2934
 
3283
- /** What a schema reports about this content: see `schemaErrorsOf`. */
3284
- const validateWith = (schema, moduleFilePath, source) => schemaErrorsOf(schema, moduleFilePath, source);
3285
-
3286
- /**
3287
- * A module's errors for this content: its own `validate` where the schema was
3288
- * evaluated, custom rules and all; otherwise what its serialized schema says,
3289
- * which is every rule but a custom `.validate(...)` (a closure does not
3290
- * serialize).
3291
- */
3292
- function validateModule(moduleFilePath, module, source) {
3293
- if (module.validate) return module.validate(source);
3294
- return validateWith(deserializeSchema(module.schema), moduleFilePath, source);
3295
- }
3296
-
3297
- /** The errors of a module's own Source: as evaluated where they were, else found here. */
3298
- function errorsOfSource(moduleFilePath, module) {
3299
- return module.errors ?? validateModule(moduleFilePath, module, module.source);
3300
- }
3301
-
3302
- /**
3303
- * A `.jsonValues()` record's entry files, by key, read out of its `.val.ts`
3304
- * (the loaded marker does not carry the path). `null` when it has none.
3305
- */
3306
- function entryFilesOf(moduleFilePath, text) {
3307
- const analysis = valModuleOf(moduleFilePath, text);
3308
- if (analysis === null) return null;
3309
- const entries = analyzeJsonValuesEntries(analysis.source);
3310
- if (entries.size === 0) return null;
3311
- const dir = path.posix.dirname(moduleFilePath.slice(1));
3312
- return Object.fromEntries([...entries].map(([key, {
3313
- importPath
3314
- }]) => [key, path.posix.join(dir, importPath)]));
3315
- }
3316
-
3317
- // --- code and content ------------------------------------------------------------
3318
-
3319
- /**
3320
- * A file's code: for a `.val.ts`, everything but `c.define`'s content
3321
- * argument, which Val reads at request time (step 2) and so is no part of a
3322
- * build; a `.val.json` entry is no code at all. Every other file is code
3323
- * whole.
3324
- */
3325
- function codeOf(file, text) {
3326
- // A `.jsonValues()` entry is content, read at request time like the rest.
3327
- if (file.endsWith(".val.json")) return "";
3328
- if (!file.endsWith(".val.ts")) return text;
3329
- const analysis = valModuleOf(file, text);
3330
- if (analysis === null) return text;
3331
- const {
3332
- source
3333
- } = analysis;
3334
- return text.slice(0, source.getStart()) + "/* content */" + text.slice(source.end);
3335
- }
3336
-
3337
- /**
3338
- * A `.val.ts`'s `c.define(...)`, or `null` when it has none: a file of schemas
3339
- * that pages share (`export const heroSchema = s.object(...)`) is named like a
3340
- * module and is code. `analyzeValModule` throws for one; this does not.
3341
- */
3342
- function valModuleOf(file, text) {
3343
- const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.ES2015, true);
3344
- if (!sourceFile.statements.some(node => ts.isExportAssignment(node))) {
3345
- return null;
3346
- }
3347
- const analysis = analyzeValModule(sourceFile);
3348
- return result.isErr(analysis) ? null : analysis.value;
3349
- }
3350
-
3351
- /**
3352
- * The three-way merge of a module's content: where both sides started
3353
- * (`base`), and each side's version. Pure JSON -- the schema decides nothing
3354
- * here, and is checked afterwards (the schema check in `merge.ts`).
3355
- *
3356
- * The rules (valbuild/home `docs/hosted-publishing.md` step 8.2):
3357
- *
3358
- * - Changed on one side: that side's.
3359
- * - Changed on both: a conflict -- even to the same value, which is an easy
3360
- * conflict to resolve but still one somebody decides.
3361
- * - An object (a page, a record) merges key by key, so two keys changed on
3362
- * two sides combine.
3363
- * - A list merges item by item only when neither side changed its shape: no
3364
- * item added, removed or moved. Otherwise positions mean different items on
3365
- * the two sides, and the whole list is the conflict.
3366
- */
3367
-
3368
- function isObject(value) {
3369
- return typeof value === "object" && value !== null && !Array.isArray(value);
3370
- }
3371
- function same(a, b) {
3372
- if (a === undefined || b === undefined) return a === b;
3373
- return deepEqual(a, b);
3374
- }
3375
-
3376
- /**
3377
- * Did this side add, remove or move an item? Lengths differ, or an item now
3378
- * sits where it was not, while it is still what used to be somewhere else.
3379
- */
3380
- function reshaped(base, side) {
3381
- if (base.length !== side.length) return true;
3382
- return side.some((item, at) => !same(item, base[at]) && base.some((was, from) => from !== at && same(item, was)));
3383
- }
3384
-
3385
- /**
3386
- * Where a value is one value, though it is an object: a media value (its path
3387
- * and what describes that file) or rich text. The schema says; see `merge.ts`.
3388
- */
3389
-
3390
- function mergeValues(base, site, proposal, atomic = () => false, path = []) {
3391
- if (same(site, base)) return {
3392
- value: proposal,
3393
- conflicts: []
3394
- };
3395
- if (same(proposal, base)) return {
3396
- value: site,
3397
- conflicts: []
3398
- };
3399
- if (atomic(path)) {
3400
- return {
3401
- value: site,
3402
- conflicts: [{
3403
- path,
3404
- base,
3405
- site,
3406
- proposal
3407
- }]
3408
- };
3409
- }
3410
- if (isObject(base) && isObject(site) && isObject(proposal)) {
3411
- const keys = [...new Set([...Object.keys(site), ...Object.keys(proposal), ...Object.keys(base)])];
3412
- const value = {};
3413
- const conflicts = [];
3414
- for (const key of keys) {
3415
- const merged = mergeValues(base[key], site[key], proposal[key], atomic, [...path, key]);
3416
- if (merged.value !== undefined) value[key] = merged.value;
3417
- conflicts.push(...merged.conflicts);
3418
- }
3419
- return {
3420
- value,
3421
- conflicts
3422
- };
3423
- }
3424
- if (Array.isArray(base) && Array.isArray(site) && Array.isArray(proposal) && !reshaped(base, site) && !reshaped(base, proposal)) {
3425
- const value = [];
3426
- const conflicts = [];
3427
- base.forEach((item, at) => {
3428
- const merged = mergeValues(item, site[at], proposal[at], atomic, [...path, String(at)]);
3429
- // Neither side removed an item, so every position holds one.
3430
- value.push(merged.value ?? null);
3431
- conflicts.push(...merged.conflicts);
3432
- });
3433
- return {
3434
- value,
3435
- conflicts
3436
- };
3437
- }
3438
- return {
3439
- value: site,
3440
- conflicts: [{
3441
- path,
3442
- base,
3443
- site,
3444
- proposal
3445
- }]
3446
- };
3447
- }
3448
-
3449
- /** `doc` with `value` at `path`; `undefined` removes it. `doc` is not changed. */
3450
- function setAt(doc, path, value) {
3451
- if (path.length === 0) return value;
3452
- const [head, ...rest] = path;
3453
- if (Array.isArray(doc)) {
3454
- const copy = [...doc];
3455
- const at = Number(head);
3456
- const next = setAt(copy[at], rest, value);
3457
- if (next === undefined) copy.splice(at, 1);else copy[at] = next;
3458
- return copy;
3459
- }
3460
- const copy = isObject(doc) ? {
3461
- ...doc
3462
- } : {};
3463
- const next = setAt(copy[head], rest, value);
3464
- if (next === undefined) delete copy[head];else copy[head] = next;
3465
- return copy;
3466
- }
3467
- function valueAt(doc, path) {
3468
- let current = doc;
3469
- for (const key of path) {
3470
- if (Array.isArray(current)) current = current[Number(key)];else if (isObject(current)) current = current[key];else return undefined;
3471
- }
3472
- return current;
3473
- }
3474
-
3475
- /**
3476
- * The Val patch that turns `from` into `to`, as small as it can be: what
3477
- * writes a merge into a `.val.ts` without rewriting what did not change.
3478
- */
3479
- function diffOps(from, to, path = []) {
3480
- if (same(from, to)) return [];
3481
- if (isObject(from) && isObject(to)) {
3482
- const ops = [];
3483
- for (const key of Object.keys(from)) {
3484
- if (!(key in to)) ops.push({
3485
- op: "remove",
3486
- path: below(path, key)
3487
- });
3488
- }
3489
- for (const [key, value] of Object.entries(to)) {
3490
- ops.push(...(key in from ? diffOps(from[key], value, [...path, key]) : [add([...path, key], value)]));
3491
- }
3492
- return ops;
3493
- }
3494
- if (Array.isArray(from) && Array.isArray(to) && from.length === to.length) {
3495
- return from.flatMap((item, at) => diffOps(item, to[at], [...path, String(at)]));
3496
- }
3497
- return [{
3498
- op: "replace",
3499
- path,
3500
- value: to ?? null
3501
- }];
3502
- }
3503
- function add(path, value) {
3504
- return {
3505
- op: "add",
3506
- path,
3507
- value
3508
- };
3509
- }
3510
- function below(path, key) {
3511
- return path.length === 0 ? [key] : [path[0], ...path.slice(1), key];
3512
- }
3513
-
3514
- /**
3515
- * Publishing a proposal as a pull request is merged: valbuild/home
3516
- * `docs/hosted-publishing.md`, step 8.2.
3517
- *
3518
- * Val's half: the two answers that need a schema. Content gets them as files
3519
- * and change ids and carries them out, never looking at a field, a list or a
3520
- * patch set.
3521
- *
3522
- * - {@link mergeFromSite} -- Update from the site: the merge commit `M`.
3523
- * - {@link changesToMove} -- which of the site's pending changes leave the
3524
- * site when a proposal is merged.
3525
- *
3526
- * `mergeScenarios.test.ts` is their specification.
3527
- */
3528
-
3529
- /** A field both sides changed since the proposal started. */
3530
-
3531
- /**
3532
- * Code both sides changed: a component, `val.modules.ts`, or the schema of a
3533
- * `.val.ts` (its code -- everything but `c.define`'s content argument, whose
3534
- * fields merge on their own).
3535
- */
3536
-
3537
- /**
3538
- * The schema check: content that merged cleanly and is not valid under the
3539
- * schema the merge ends with -- an entry the site added, say, under a field
3540
- * whose type the proposal changed.
3541
- */
3542
-
3543
- /** How a conflict is resolved: keep one side, or write it -- as AI or a developer does. */
3544
-
3545
- /**
3546
- * Update from the site: a three-way merge of where the proposal started
3547
- * (`base`), the site's head and the proposal's last save, written whole.
3548
- * Every conflict needs a resolution, or nothing is merged.
3549
- *
3550
- * File by file. A file that is not a `.val.ts` is code, and merges as a
3551
- * file: changed on one side, that side's; on both, a conflict. A `.val.ts`
3552
- * is code (everything but `c.define`'s content argument) and content, and the
3553
- * two merge apart: the code as a file, the content field by field
3554
- * (`mergeValues`). So a schema the proposal changed and a field the site
3555
- * published in the same file do not conflict. A code conflict in a `.val.ts`
3556
- * is resolved by keeping a side's code -- the content still merges -- or by
3557
- * writing the whole file.
3558
- *
3559
- * Not here: the schema check ({@link schemaCheck}). It needs the merged
3560
- * files' schemas, so whoever can evaluate them -- Val's loader, the builder
3561
- * tab -- runs it on `files` before the merge is committed.
3562
- */
3563
- function mergeFromSite(input) {
3564
- const {
3565
- base,
3566
- site,
3567
- proposal,
3568
- resolutions
3569
- } = input;
3570
- const files = {};
3571
- const modules = {};
3572
- const conflicts = [];
3573
- const paths = [...new Set([...Object.keys(base.files), ...Object.keys(site.files), ...Object.keys(proposal.files)])].sort();
3574
- // A `.jsonValues()` entry is written with its module, never on its own.
3575
- const entryFiles = new Set([base, site, proposal].flatMap(side => Object.values(side.modules).flatMap(module => Object.values(module.entries ?? {}))));
3576
- for (const file of paths) {
3577
- var _moduleOf3, _moduleOf4, _moduleOf5, _moduleOf6;
3578
- if (entryFiles.has(file)) continue;
3579
- const b = base.files[file] ?? null;
3580
- const s = site.files[file] ?? null;
3581
- const p = proposal.files[file] ?? null;
3582
- const resolution = fileResolution(resolutions, file);
3583
- const codeConflict = () => ({
3584
- kind: "code",
3585
- file,
3586
- base: b,
3587
- site: s,
3588
- proposal: p
3589
- });
3590
-
3591
- // A file named like a module that no side defines as one -- schemas the
3592
- // pages share -- is code.
3593
- const moduleFilePath = `/${file}`;
3594
- const isModule = [base, site, proposal].some(side => side.modules[moduleFilePath] !== undefined);
3595
- if (!file.endsWith(".val.ts") || !isModule) {
3596
- if (s === b) files[file] = p;else if (p === b) files[file] = s;else if (resolution) files[file] = resolvedText(resolution, s, p);else {
3597
- conflicts.push(codeConflict());
3598
- files[file] = s;
3599
- }
3600
- continue;
3601
- }
3602
-
3603
- // A .val.ts: whose code, then the content under it.
3604
- const code = text => text === null ? null : codeOf(file, text);
3605
- let side;
3606
- if (code(s) === code(b)) side = "proposal";else if (code(p) === code(b)) side = "site";else if (resolution && "text" in resolution) {
3607
- files[file] = resolution.text;
3608
- continue;
3609
- } else if (resolution) side = resolution.keep;else {
3610
- conflicts.push(codeConflict());
3611
- files[file] = s;
3612
- continue;
3613
- }
3614
- const moduleOf = project => project.modules[moduleFilePath];
3615
- const sourceOf = project => {
3616
- var _moduleOf;
3617
- return (_moduleOf = moduleOf(project)) === null || _moduleOf === void 0 ? void 0 : _moduleOf.source;
3618
- };
3619
- const chosen = side === "site" ? site : proposal;
3620
- const text = side === "site" ? s : p;
3621
- if (text === null) {
3622
- // That side deleted the file. Content the other side changed would go
3623
- // with it: that is for a person to decide -- unless they have.
3624
- const other = side === "site" ? p : s;
3625
- if (!resolution && other !== b) {
3626
- conflicts.push(codeConflict());
3627
- }
3628
- files[file] = null;
3629
- for (const project of [base, site, proposal]) {
3630
- for (const entry of Object.values(((_moduleOf2 = moduleOf(project)) === null || _moduleOf2 === void 0 ? void 0 : _moduleOf2.entries) ?? {})) {
3631
- var _moduleOf2;
3632
- files[entry] = null;
3633
- }
3634
- }
3635
- continue;
3636
- }
3637
- // What the chosen text holds, which the merge is written over.
3638
- const from = ((_moduleOf3 = moduleOf(chosen)) === null || _moduleOf3 === void 0 ? void 0 : _moduleOf3.written) ?? ((_moduleOf4 = moduleOf(chosen)) === null || _moduleOf4 === void 0 ? void 0 : _moduleOf4.source);
3639
- const merged = mergeValues(sourceOf(base), sourceOf(site), sourceOf(proposal), atomicFor((_moduleOf5 = moduleOf(chosen)) === null || _moduleOf5 === void 0 ? void 0 : _moduleOf5.schema));
3640
- const resolved = resolveContent(moduleFilePath, merged, resolutions);
3641
- conflicts.push(...resolved.unresolved);
3642
- const content = resolved.content;
3643
- modules[moduleFilePath] = content;
3644
- const entries = (_moduleOf6 = moduleOf(chosen)) === null || _moduleOf6 === void 0 ? void 0 : _moduleOf6.entries;
3645
- if (entries) {
3646
- var _moduleOf7, _moduleOf8;
3647
- Object.assign(files, writeEntries(file, text, chosen.files, entries, from, content, [(_moduleOf7 = moduleOf(site)) === null || _moduleOf7 === void 0 ? void 0 : _moduleOf7.entries, (_moduleOf8 = moduleOf(proposal)) === null || _moduleOf8 === void 0 ? void 0 : _moduleOf8.entries]));
3648
- } else {
3649
- files[file] = writeContent(file, text, from, content);
3650
- }
3651
- }
3652
- if (conflicts.length > 0) return {
3653
- status: "conflicts",
3654
- conflicts
3655
- };
3656
- return {
3657
- status: "merged",
3658
- files,
3659
- modules,
3660
- code: Object.keys(files).filter(file => {
3661
- const text = files[file];
3662
- const before = site.files[file] ?? null;
3663
- if (text === null || before === null) return text !== before;
3664
- return codeOf(file, text) !== codeOf(file, before);
3665
- })
3666
- };
3667
- }
3668
-
3669
- /** A change pending on the site, in chain order. */
3670
-
3671
- /**
3672
- * The site's pending changes that conflict with going from `site` to
3673
- * `merged`, as whole patch sets: each inner list moves together, into a
3674
- * proposal of its own. Everything else stays pending.
3675
- *
3676
- * Patch sets are the Studio's own (`PatchSets`), from the schema the changes
3677
- * were written against; sets that share a change are one, because a change
3678
- * cannot be split. A set moves when, taken as the site's side of a three-way
3679
- * merge with the merged commit as the other, it conflicts (`mergeValues`, so
3680
- * the same value on both sides moves too); or when it no longer applies to
3681
- * the merged commit, or leaves it invalid under the merged schema.
3682
- */
3683
- function changesToMove(input) {
3684
- const {
3685
- site,
3686
- merged,
3687
- pending
3688
- } = input;
3689
- const sets = new PatchSets();
3690
- for (const change of pending) {
3691
- var _site$modules$change$;
3692
- sets.insert(change.moduleFilePath, (_site$modules$change$ = site.modules[change.moduleFilePath]) === null || _site$modules$change$ === void 0 ? void 0 : _site$modules$change$.schema, change.patch, change.patchId, "", null);
3693
- }
3694
- const groups = joinSharedChanges(sets.serialize().map(set => set.patches.map(p => p.patchId)));
3695
- const moves = [];
3696
- for (const group of groups) {
3697
- const changes = pending.filter(change => group.has(change.patchId));
3698
- if (conflictsWithMerge(changes, site, merged)) {
3699
- moves.push(changes.map(change => change.patchId));
3700
- }
3701
- }
3702
- // In chain order, so the moved proposals are opened in the order the
3703
- // changes were written.
3704
- const order = ids => pending.findIndex(change => change.patchId === ids[0]);
3705
- return moves.sort((a, b) => order(a) - order(b));
3706
- }
3707
-
3708
- // --- the pieces --------------------------------------------------------------
3709
-
3710
- /**
3711
- * A module's merged content with the resolutions written in: each field
3712
- * conflict that has one, and any value written for the schema check (or
3713
- * anywhere else) as given. What is left is what still needs a person.
3714
- */
3715
- function resolveContent(moduleFilePath, merged, resolutions) {
3716
- let content = merged.value;
3717
- const unresolved = [];
3718
- for (const conflict of merged.conflicts) {
3719
- const resolved = fieldResolution(resolutions, moduleFilePath, conflict);
3720
- if (resolved === null) {
3721
- unresolved.push({
3722
- kind: "field",
3723
- moduleFilePath,
3724
- ...conflict
3725
- });
3726
- } else {
3727
- content = setAt(content, conflict.path, resolved.value);
3728
- }
3729
- }
3730
- for (const resolution of resolutions) {
3731
- if ("moduleFilePath" in resolution && resolution.moduleFilePath === moduleFilePath && "value" in resolution && !merged.conflicts.some(c => samePath(c.path, resolution.path))) {
3732
- content = setAt(content, resolution.path, resolution.value);
3733
- }
3734
- }
3735
- return {
3736
- content,
3737
- unresolved
3738
- };
3739
- }
3740
- function conflictsWithMerge(changes, site, merged) {
3741
- const modules = [...new Set(changes.map(change => change.moduleFilePath))];
3742
- for (const moduleFilePath of modules) {
3743
- var _site$modules$moduleF;
3744
- const ops = changes.filter(change => change.moduleFilePath === moduleFilePath).flatMap(change => change.patch).filter(op => op.op !== "file");
3745
- const before = (_site$modules$moduleF = site.modules[moduleFilePath]) === null || _site$modules$moduleF === void 0 ? void 0 : _site$modules$moduleF.source;
3746
- const after = merged.modules[moduleFilePath];
3747
- if (before === undefined || after === undefined) return true;
3748
- const written = apply(before, ops);
3749
- if (written === undefined) return true;
3750
- const mergedSource = after.source;
3751
- const atomic = atomicFor(after.schema);
3752
- if (mergeValues(before, written, mergedSource, atomic).conflicts.length) {
3753
- return true;
3754
- }
3755
- // Over the merged commit: it applies, and is as valid as it was.
3756
- const over = apply(mergedSource, ops);
3757
- if (over === undefined) return true;
3758
- const known = new Set(errorPaths(moduleFilePath, after, mergedSource));
3759
- if (errorPaths(moduleFilePath, after, over).some(path => !known.has(path))) {
3760
- return true;
3761
- }
3762
- }
3763
- return false;
3764
- }
3765
- function apply(source, ops) {
3766
- if (source === undefined) return undefined;
3767
- const applied = applyPatch(deepClone(source), new JSONOps(), ops);
3768
- return result.isOk(applied) ? applied.value : undefined;
3769
- }
3770
- function errorPaths(moduleFilePath, module, source) {
3771
- return validateModule(moduleFilePath, module, source).map(error => error.path.join("/"));
3772
- }
3773
-
3774
- /**
3775
- * The schema check of a merge: content in `merged` -- the project
3776
- * {@link mergeFromSite} wrote, with its schemas evaluated -- that is invalid
3777
- * under the schema it ends with, leaving out what was already invalid on a
3778
- * side. A conflict, each; a resolution with a value for one is written into
3779
- * the content by the merge, and so is checked here.
3780
- */
3781
- function schemaCheck(merged, sides) {
3782
- const conflicts = [];
3783
- for (const [path, module] of Object.entries(merged.modules)) {
3784
- const moduleFilePath = path;
3785
- const known = new Set(sides.flatMap(side => {
3786
- const there = side.modules[moduleFilePath];
3787
- return there ? errorsOfSource(moduleFilePath, there).map(e => e.path.join("/")) : [];
3788
- }));
3789
- for (const error of errorsOfSource(moduleFilePath, module)) {
3790
- if (known.has(error.path.join("/"))) continue;
3791
- conflicts.push({
3792
- kind: "invalid",
3793
- moduleFilePath,
3794
- path: error.path,
3795
- value: valueAt(module.source, error.path),
3796
- message: error.message
3797
- });
3798
- }
3799
- }
3800
- return conflicts;
3801
- }
3802
-
3803
- /**
3804
- * The values that merge whole, though they are objects: media (an image's
3805
- * alt text describes that image, not another) and rich text.
3806
- */
3807
- const ATOMIC = new Set(["image", "file", "video", "font", "richtext"]);
3808
-
3809
- /** See {@link ATOMIC}: where this schema holds a value that merges whole. */
3810
- function atomicFor(schema) {
3811
- if (!schema) return () => false;
3812
- return path => {
3813
- const types = schemaTypesOfPath(schema, path);
3814
- return [...types].some(type => ATOMIC.has(type));
3815
- };
3816
- }
3817
- const tsOps = new TSOps(document => pipe(analyzeValModule(document), result.map(({
3818
- source
3819
- }) => source)));
3820
-
3821
- /**
3822
- * `content` written into the `.val.ts` `text`, whose content is `from`: as
3823
- * the smallest patch, through the same AST operations a save uses, so what
3824
- * did not change is left exactly as it was.
3825
- */
3826
- function writeContent(file, text, from, content) {
3827
- const ops = diffOps(from, content);
3828
- if (ops.length === 0) return text;
3829
- const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.ES2015, true);
3830
- return printed(unwrap(file, applyPatch(sourceFile, tsOps, ops)));
3831
- }
3832
-
3833
- /**
3834
- * A `.jsonValues()` module, written as its files: the `.val.ts` names the
3835
- * entries -- one added gets a `c.json(...)` line, as a save writes it, one
3836
- * removed loses its line -- and each entry is its own `.val.json`. An entry
3837
- * whose content did not change keeps its file's text exactly.
3838
- */
3839
- function writeEntries(file, text, chosenFiles, entries, from, content, others) {
3840
- const written = {};
3841
- const before = isRecord(from) ? from : {};
3842
- const after = isRecord(content) ? content : {};
3843
- const moduleDir = path.posix.dirname(file);
3844
- let sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.ES2015, true);
3845
- for (const key of Object.keys(before)) {
3846
- if (key in after) continue;
3847
- sourceFile = unwrap(file, removeValJsonEntry(sourceFile, [], key));
3848
- written[entries[key]] = null;
3849
- }
3850
- for (const [key, value] of Object.entries(after)) {
3851
- const entryFile = entries[key] ?? others.map(other => other === null || other === void 0 ? void 0 : other[key]).find(f => f !== undefined) ?? path.posix.join(moduleDir, path.posix.basename(file, ".val.ts"), `${key}.val.json`);
3852
- if (!(key in before)) {
3853
- const importPath = `./${path.posix.relative(moduleDir, entryFile)}`;
3854
- sourceFile = unwrap(file, insertValJsonEntry(sourceFile, [], key, importPath));
3855
- }
3856
- const kept = chosenFiles[entryFile];
3857
- written[entryFile] = key in before && diffOps(before[key], value).length === 0 && kept ? kept : JSON.stringify(value, null, 2);
3858
- }
3859
- written[file] = printed(sourceFile);
3860
- return written;
3861
- }
3862
- function isRecord(value) {
3863
- return typeof value === "object" && value !== null && !Array.isArray(value);
3864
- }
3865
- function unwrap(file, written) {
3866
- if (result.isErr(written)) {
3867
- throw new Error(`could not write the merge into ${file}: ${String(written.error)}`);
3868
- }
3869
- return written.value;
3870
- }
3871
-
3872
- /** As `prepare` prints: TypeScript escapes non-ASCII as \\u sequences. */
3873
- function printed(sourceFile) {
3874
- return unescape(sourceFile.getText(sourceFile).replace(/\\u/g, "%u"));
3875
- }
3876
- function fileResolution(resolutions, file) {
3877
- for (const resolution of resolutions) {
3878
- if ("file" in resolution && resolution.file === file) return resolution;
3879
- }
3880
- return null;
3881
- }
3882
- function resolvedText(resolution, site, proposal) {
3883
- if ("text" in resolution) return resolution.text;
3884
- return resolution.keep === "site" ? site : proposal;
3885
- }
3886
-
3887
- /** A field conflict's resolution, as the value it leaves; `null` when it has none. */
3888
- function fieldResolution(resolutions, moduleFilePath, conflict) {
3889
- for (const resolution of resolutions) {
3890
- if (!("moduleFilePath" in resolution) || resolution.moduleFilePath !== moduleFilePath || !samePath(resolution.path, conflict.path)) {
3891
- continue;
3892
- }
3893
- if ("value" in resolution) return {
3894
- value: resolution.value
3895
- };
3896
- return {
3897
- value: resolution.keep === "site" ? conflict.site : conflict.proposal
3898
- };
3899
- }
3900
- return null;
3901
- }
3902
- function samePath(a, b) {
3903
- return a.length === b.length && a.every((key, at) => key === b[at]);
3904
- }
3905
-
3906
2935
  /**
3907
2936
  * Update from the site when only content changed (valbuild/home
3908
2937
  * `docs/hosted-publishing.md` step 8.2, slice 1a): the proposal staged no code
@@ -4164,7 +3193,7 @@ async function stagedModuleSources(files) {
4164
3193
  parseValFile,
4165
3194
  analyzeValModule,
4166
3195
  evaluateModuleSource
4167
- } = await import('./publishKit-4e7a1516.esm.js');
3196
+ } = await import('./publishKit-a732e3c3.esm.js');
4168
3197
  const sources = {};
4169
3198
  for (const {
4170
3199
  path,
@@ -8684,4 +7713,4 @@ function sameValue(a, b) {
8684
7713
  return JSON.stringify(a) === JSON.stringify(b);
8685
7714
  }
8686
7715
 
8687
- export { APP_MODE_REQUIRES_REMOTE_FILES as A, TSOps as T, ValOpsFS as V, verifyJwt as a, getExpire as b, resolveRemoteFileAuth as c, decodeJwtWithoutVerifying as d, encodeJwt as e, removeValJsonEntry as f, getPersonalAccessTokenPath as g, insertValJsonEntry as h, initHandlerOptions as i, createValOps as j, ValOpsHttp as k, loadTypeScriptKit as l, readPatchStore as m, describePatchStoreProblems as n, parsePersonalAccessTokenFile as p, readValLoginToken as r, valRuntime as v };
7716
+ export { APP_MODE_REQUIRES_REMOTE_FILES as A, ValOpsFS as V, verifyJwt as a, getExpire as b, resolveRemoteFileAuth as c, decodeJwtWithoutVerifying as d, encodeJwt as e, createValOps as f, getPersonalAccessTokenPath as g, ValOpsHttp as h, initHandlerOptions as i, readPatchStore as j, describePatchStoreProblems as k, loadTypeScriptKit as l, parsePersonalAccessTokenFile as p, readValLoginToken as r, valRuntime as v };