@valbuild/server 0.154.1 → 0.154.2
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 +35 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +6 -3
- package/browser/dist/valbuild-server-browser.cjs.prod.js +6 -3
- package/browser/dist/valbuild-server-browser.esm.js +6 -3
- package/dist/{ValRouterCore-be314bc7.esm.js → ValOpsMemory-611f33d2.esm.js} +14 -1992
- package/dist/{ValRouterCore-cfb35067.cjs.prod.js → ValOpsMemory-6ebbb3ba.cjs.prod.js} +23 -2013
- package/dist/{ValRouterCore-361673dc.cjs.dev.js → ValOpsMemory-d8bf9f5d.cjs.dev.js} +23 -2013
- package/dist/ValPatchStore-2f92eced.cjs.prod.js +1128 -0
- package/dist/ValPatchStore-df8cdbe7.cjs.dev.js +1128 -0
- package/dist/ValPatchStore-e23070df.esm.js +1119 -0
- package/dist/ValRouterCore-5b747abb.cjs.prod.js +612 -0
- package/dist/ValRouterCore-73eb843d.esm.js +608 -0
- package/dist/ValRouterCore-86757d56.cjs.dev.js +612 -0
- package/dist/createPrettierFormatter-05ad7480.cjs.prod.js +692 -0
- package/dist/createPrettierFormatter-1edca494.esm.js +673 -0
- package/dist/createPrettierFormatter-851fcf99.cjs.dev.js +692 -0
- package/dist/createValRuntime-2dc83070.cjs.prod.js +47 -0
- package/dist/createValRuntime-62836dbe.esm.js +45 -0
- package/dist/createValRuntime-fd9b673d.cjs.dev.js +47 -0
- package/dist/declarations/src/ValOpsMemory.d.ts +3 -73
- package/dist/declarations/src/ValPatchStore.d.ts +92 -0
- package/dist/declarations/src/ValRouter.d.ts +1 -11
- package/dist/declarations/src/createPrettierFormatter.d.ts +18 -3
- package/dist/declarations/src/createValRuntime.d.ts +12 -0
- package/dist/declarations/src/draftReads.d.ts +11 -3
- package/dist/declarations/src/index.d.ts +4 -2
- package/dist/declarations/src/internal/index.d.ts +28 -6
- package/dist/declarations/src/proposal.d.ts +13 -25
- package/dist/declarations/src/proposalJsonEntries.d.ts +30 -0
- package/dist/declarations/src/serverMode.d.ts +31 -0
- package/dist/{draftReads-0dcddf72.cjs.prod.js → draftReads-3f7dcda5.cjs.prod.js} +10 -2
- package/dist/{draftReads-df44e629.cjs.dev.js → draftReads-a300a02f.cjs.dev.js} +10 -2
- package/dist/{draftReads-1f29aedd.esm.js → draftReads-bca0d49c.esm.js} +10 -2
- package/dist/{inTabFetch-56226d62.cjs.prod.js → inTabFetch-0124da2e.cjs.prod.js} +5 -4
- package/dist/{inTabFetch-5d0314a3.cjs.dev.js → inTabFetch-d0c9c58a.cjs.dev.js} +5 -4
- package/dist/{inTabFetch-7c8a5628.esm.js → inTabFetch-e48a801e.esm.js} +2 -1
- package/dist/jsonValuesPatch-13acc674.esm.js +276 -0
- package/dist/jsonValuesPatch-88bc661d.cjs.dev.js +281 -0
- package/dist/jsonValuesPatch-92798812.cjs.prod.js +281 -0
- package/dist/proposalJsonEntries-0669f027.esm.js +480 -0
- package/dist/proposalJsonEntries-26f397bd.cjs.dev.js +500 -0
- package/dist/proposalJsonEntries-9e537244.cjs.prod.js +500 -0
- package/dist/{publishKit-5a8c9a0d.cjs.dev.js → publishKit-96522d5a.cjs.prod.js} +20 -22
- package/dist/{publishKit-707230bc.cjs.prod.js → publishKit-b06031dc.cjs.dev.js} +20 -22
- package/dist/{publishKit-b850045b.esm.js → publishKit-b8929fe8.esm.js} +8 -9
- package/dist/{ValRouter-9505c550.cjs.dev.js → valRuntime-ba8ff718.cjs.prod.js} +158 -6038
- package/dist/{ValRouter-31f89baf.cjs.prod.js → valRuntime-c8c82b24.cjs.dev.js} +158 -6038
- package/dist/{ValRouter-b7dc784d.esm.js → valRuntime-ccbbbfad.esm.js} +107 -5937
- package/dist/valbuild-server.cjs.dev.js +5146 -352
- package/dist/valbuild-server.cjs.prod.js +5146 -352
- package/dist/valbuild-server.esm.js +4902 -132
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +7 -4
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +7 -4
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +7 -4
- package/internal/dist/valbuild-server-internal.cjs.dev.js +47 -31
- package/internal/dist/valbuild-server-internal.cjs.prod.js +47 -31
- package/internal/dist/valbuild-server-internal.esm.js +38 -22
- package/package.json +4 -4
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fp = require('@valbuild/core/fp');
|
|
4
|
+
var ts = require('typescript');
|
|
5
|
+
var jsonValuesPatch = require('./jsonValuesPatch-92798812.cjs.prod.js');
|
|
6
|
+
var createPrettierFormatter = require('./createPrettierFormatter-05ad7480.cjs.prod.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
11
|
+
|
|
12
|
+
class ValSyntaxError {
|
|
13
|
+
constructor(message, node) {
|
|
14
|
+
this.message = message;
|
|
15
|
+
this.node = node;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function forEachError(tree, callback) {
|
|
19
|
+
if (Array.isArray(tree)) {
|
|
20
|
+
for (const subtree of tree) {
|
|
21
|
+
forEachError(subtree, callback);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
callback(tree);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function flatMapErrors(tree, cb) {
|
|
28
|
+
const result = [];
|
|
29
|
+
forEachError(tree, error => result.push(cb(error)));
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function formatSyntaxError(error, sourceFile) {
|
|
33
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(error.node.pos);
|
|
34
|
+
return `${pos.line}:${pos.character} ${error.message}`;
|
|
35
|
+
}
|
|
36
|
+
function formatSyntaxErrorTree(tree, sourceFile) {
|
|
37
|
+
return flatMapErrors(tree, error => formatSyntaxError(error, sourceFile));
|
|
38
|
+
}
|
|
39
|
+
function isLiteralPropertyName(name) {
|
|
40
|
+
return ts__default["default"].isIdentifier(name) || ts__default["default"].isStringLiteral(name) || ts__default["default"].isNumericLiteral(name);
|
|
41
|
+
}
|
|
42
|
+
function validateObjectProperties(nodes) {
|
|
43
|
+
const errors = [];
|
|
44
|
+
for (const node of nodes) {
|
|
45
|
+
if (!ts__default["default"].isPropertyAssignment(node)) {
|
|
46
|
+
errors.push(new ValSyntaxError("Object literal element must be property assignment", node));
|
|
47
|
+
} else if (!isLiteralPropertyName(node.name)) {
|
|
48
|
+
errors.push(new ValSyntaxError("Object literal element key must be an identifier or a literal", node));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (errors.length > 0) {
|
|
52
|
+
return fp.result.err(errors);
|
|
53
|
+
}
|
|
54
|
+
return fp.result.ok(nodes);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Validates that the expression is a JSON compatible type of expression without
|
|
59
|
+
* validating its children.
|
|
60
|
+
*/
|
|
61
|
+
function shallowValidateExpression(value) {
|
|
62
|
+
return ts__default["default"].isStringLiteralLike(value) || ts__default["default"].isNumericLiteral(value) || value.kind === ts__default["default"].SyntaxKind.TrueKeyword || value.kind === ts__default["default"].SyntaxKind.FalseKeyword || value.kind === ts__default["default"].SyntaxKind.NullKeyword || ts__default["default"].isArrayLiteralExpression(value) || ts__default["default"].isObjectLiteralExpression(value) ? undefined : new ValSyntaxError("Expression must be a literal", value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Evaluates the expression as a JSON value
|
|
67
|
+
*/
|
|
68
|
+
function evaluateExpression(value) {
|
|
69
|
+
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
|
|
70
|
+
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters.
|
|
71
|
+
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1".
|
|
72
|
+
// https://github.com/microsoft/TypeScript/blob/4b794fe1dd0d184d3f8f17e94d8187eace57c91e/src/compiler/types.ts#L2127-L2131
|
|
73
|
+
|
|
74
|
+
if (ts__default["default"].isStringLiteralLike(value)) {
|
|
75
|
+
return fp.result.ok(value.text);
|
|
76
|
+
} else if (ts__default["default"].isNumericLiteral(value)) {
|
|
77
|
+
return fp.result.ok(Number(value.text));
|
|
78
|
+
} else if (value.kind === ts__default["default"].SyntaxKind.TrueKeyword) {
|
|
79
|
+
return fp.result.ok(true);
|
|
80
|
+
} else if (value.kind === ts__default["default"].SyntaxKind.FalseKeyword) {
|
|
81
|
+
return fp.result.ok(false);
|
|
82
|
+
} else if (value.kind === ts__default["default"].SyntaxKind.NullKeyword) {
|
|
83
|
+
return fp.result.ok(null);
|
|
84
|
+
} else if (ts__default["default"].isArrayLiteralExpression(value)) {
|
|
85
|
+
return fp.result.all(value.elements.map(evaluateExpression));
|
|
86
|
+
} else if (ts__default["default"].isObjectLiteralExpression(value)) {
|
|
87
|
+
return fp.pipe(validateObjectProperties(value.properties), fp.result.flatMap(assignments => fp.pipe(assignments.map(assignment => fp.pipe(evaluateExpression(assignment.initializer), fp.result.map(value => [assignment.name.text, value]))), fp.result.all)), fp.result.map(Object.fromEntries));
|
|
88
|
+
} else {
|
|
89
|
+
return fp.result.err(new ValSyntaxError("Expression must be a literal", value));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Finds the property `key` is written as in an object literal, for an edit to
|
|
95
|
+
* write into.
|
|
96
|
+
*
|
|
97
|
+
* An object may spread another into itself (`{ ...noMedia, code: null }`): the
|
|
98
|
+
* module evaluates it, so the value reads fine, and an edit to a key written
|
|
99
|
+
* out AFTER every spread can go ahead - that property is the one that wins.
|
|
100
|
+
* What cannot is an edit to a key a spread might supply or override, since we
|
|
101
|
+
* would be writing a value the module does not end up with. Those are
|
|
102
|
+
* refused, naming the spread, so the author knows which line to write out.
|
|
103
|
+
*/
|
|
104
|
+
function findObjectPropertyAssignment(value, key) {
|
|
105
|
+
const spreads = value.properties.filter(ts__default["default"].isSpreadAssignment);
|
|
106
|
+
return fp.pipe(validateObjectProperties(value.properties.filter(property => !ts__default["default"].isSpreadAssignment(property))), fp.result.flatMap(assignments => {
|
|
107
|
+
const matchingAssignments = assignments.filter(assignment => assignment.name.text === key);
|
|
108
|
+
if (matchingAssignments.length > 1) {
|
|
109
|
+
return fp.result.err(new ValSyntaxError(`Object key "${key}" is ambiguous`, value));
|
|
110
|
+
}
|
|
111
|
+
const [assignment] = matchingAssignments;
|
|
112
|
+
if (assignment === undefined) {
|
|
113
|
+
if (spreads.length > 0) {
|
|
114
|
+
return fp.result.err(new ValSyntaxError(`Cannot edit "${key}": it is not written out in this object, so it may come from ${spreadNames(spreads)}. Write "${key}" out after the spread to make it editable`, spreads[spreads.length - 1]));
|
|
115
|
+
}
|
|
116
|
+
return fp.result.ok(undefined);
|
|
117
|
+
}
|
|
118
|
+
const overriding = spreads.filter(spread => spread.pos > assignment.pos);
|
|
119
|
+
if (overriding.length > 0) {
|
|
120
|
+
return fp.result.err(new ValSyntaxError(`Cannot edit "${key}": ${spreadNames(overriding)} comes after it and may override it. Move "${key}" after the spread to make it editable`, assignment));
|
|
121
|
+
}
|
|
122
|
+
return fp.result.ok(assignment);
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Finds the property `key` is written as, for a REMOVE: stricter than
|
|
128
|
+
* {@link findObjectPropertyAssignment}, because removing a key from an object
|
|
129
|
+
* that spreads another into it is refused outright. The key's own property may
|
|
130
|
+
* be all that hides a value the spread supplies, and removing it would bring
|
|
131
|
+
* that value back - and for a `.jsonValues()` entry, delete its file as well.
|
|
132
|
+
*
|
|
133
|
+
* Every remove goes through this, so the two that exist (a value, and a
|
|
134
|
+
* `.jsonValues()` entry) cannot disagree about it.
|
|
135
|
+
*/
|
|
136
|
+
function findObjectPropertyAssignmentToRemove(value, key) {
|
|
137
|
+
const spreads = value.properties.filter(ts__default["default"].isSpreadAssignment);
|
|
138
|
+
if (spreads.length > 0) {
|
|
139
|
+
return fp.result.err(new ValSyntaxError(`Cannot remove "${key}" from an object that spreads another into it: ${spreadNames(spreads)} may have a "${key}" of its own, and removing this one would bring it back`, value));
|
|
140
|
+
}
|
|
141
|
+
return findObjectPropertyAssignment(value, key);
|
|
142
|
+
}
|
|
143
|
+
function spreadNames(spreads) {
|
|
144
|
+
// Not `getText()`: it needs parent pointers, and the parsers here do not set them.
|
|
145
|
+
return spreads.map(spread => ts__default["default"].isIdentifier(spread.expression) ? `"...${spread.expression.text}"` : "a spread").join(", ");
|
|
146
|
+
}
|
|
147
|
+
function validateInitializers(nodes) {
|
|
148
|
+
for (const node of nodes) {
|
|
149
|
+
if (ts__default["default"].isSpreadElement(node)) {
|
|
150
|
+
return new ValSyntaxError("Unexpected spread element", node);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isPath(node, path) {
|
|
157
|
+
let currentNode = node;
|
|
158
|
+
for (let i = path.length - 1; i > 0; --i) {
|
|
159
|
+
const name = path[i];
|
|
160
|
+
if (!ts__default["default"].isPropertyAccessExpression(currentNode)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if (!ts__default["default"].isIdentifier(currentNode.name) || currentNode.name.text !== name) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
currentNode = currentNode.expression;
|
|
167
|
+
}
|
|
168
|
+
return ts__default["default"].isIdentifier(currentNode) && currentNode.text === path[0];
|
|
169
|
+
}
|
|
170
|
+
function validateArguments(node, validators) {
|
|
171
|
+
return fp.result.allV([node.arguments.length === validators.length ? fp.result.voidOk : fp.result.err(new ValSyntaxError(`Expected ${validators.length} arguments`, node)), ...node.arguments.slice(0, validators.length).map((argument, index) => validators[index](argument))]);
|
|
172
|
+
}
|
|
173
|
+
function analyzeDefaultExport(node) {
|
|
174
|
+
const cDefine = node.expression;
|
|
175
|
+
if (!ts__default["default"].isCallExpression(cDefine)) {
|
|
176
|
+
return fp.result.err(new ValSyntaxError("Expected default expression to be a call expression", cDefine));
|
|
177
|
+
}
|
|
178
|
+
if (!isPath(cDefine.expression, ["c", "define"])) {
|
|
179
|
+
return fp.result.err(new ValSyntaxError("Expected default expression to be calling c.define", cDefine.expression));
|
|
180
|
+
}
|
|
181
|
+
return fp.pipe(validateArguments(cDefine, [id => {
|
|
182
|
+
// TODO: validate ID value here?
|
|
183
|
+
if (!ts__default["default"].isStringLiteralLike(id)) {
|
|
184
|
+
return fp.result.err(new ValSyntaxError("Expected first argument to c.define to be a string literal", id));
|
|
185
|
+
}
|
|
186
|
+
return fp.result.voidOk;
|
|
187
|
+
}, () => {
|
|
188
|
+
return fp.result.voidOk;
|
|
189
|
+
}, () => {
|
|
190
|
+
return fp.result.voidOk;
|
|
191
|
+
}]), fp.result.map(() => {
|
|
192
|
+
const [, schema, source] = cDefine.arguments;
|
|
193
|
+
return {
|
|
194
|
+
schema,
|
|
195
|
+
source
|
|
196
|
+
};
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
function analyzeValModule(sourceFile) {
|
|
200
|
+
const analysis = sourceFile.forEachChild(node => {
|
|
201
|
+
if (ts__default["default"].isExportAssignment(node)) {
|
|
202
|
+
return analyzeDefaultExport(node);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (!analysis) {
|
|
206
|
+
throw Error("Failed to find fixed content node in val module");
|
|
207
|
+
}
|
|
208
|
+
return analysis;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Given the `source` object-literal expression of a `.jsonValues()` record /
|
|
213
|
+
* router (the 3rd argument to `c.define`, via {@link analyzeValModule}),
|
|
214
|
+
* extracts each entry's `c.json(() => import("..."))` import path, keyed by
|
|
215
|
+
* entry key. Entries whose value is not a `c.json(...)` call are skipped.
|
|
216
|
+
*/
|
|
217
|
+
function analyzeJsonValuesEntries(source) {
|
|
218
|
+
const entries = new Map();
|
|
219
|
+
if (!ts__default["default"].isObjectLiteralExpression(source)) {
|
|
220
|
+
return entries;
|
|
221
|
+
}
|
|
222
|
+
for (const prop of source.properties) {
|
|
223
|
+
if (!ts__default["default"].isPropertyAssignment(prop)) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const key = getPropertyKey(prop.name);
|
|
227
|
+
if (key === null) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const entry = analyzeCJsonCall(prop.initializer);
|
|
231
|
+
if (entry) {
|
|
232
|
+
entries.set(key, entry);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return entries;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Every key of a `.jsonValues()` record's source literal, thunked or not.
|
|
240
|
+
*
|
|
241
|
+
* {@link analyzeJsonValuesEntries} answers "which entries have a file behind
|
|
242
|
+
* them", which is the question for resolving a path. This is the other one:
|
|
243
|
+
* which keys the record HAS. They differ on a value that is not a
|
|
244
|
+
* `c.json(...)` call - written inline, or mid-edit - and telling an existing
|
|
245
|
+
* key from a new one is what decides whether a whole-record write adds a
|
|
246
|
+
* `c.json(...)` thunk or replaces one. Using the thunk set for that would
|
|
247
|
+
* insert a second property with a key the literal already has.
|
|
248
|
+
*/
|
|
249
|
+
function jsonValuesRecordKeys(source) {
|
|
250
|
+
const keys = [];
|
|
251
|
+
if (!ts__default["default"].isObjectLiteralExpression(source)) {
|
|
252
|
+
return keys;
|
|
253
|
+
}
|
|
254
|
+
for (const prop of source.properties) {
|
|
255
|
+
if (!ts__default["default"].isPropertyAssignment(prop)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const key = getPropertyKey(prop.name);
|
|
259
|
+
if (key !== null) {
|
|
260
|
+
keys.push(key);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return keys;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The Source a `c.define(...)` literal declares, as a module's Source is
|
|
268
|
+
* stored: each `.jsonValues()` entry's `c.json(() => import("..."))` as the
|
|
269
|
+
* marker `{ _type: "json" }` its content stands behind, and every other value
|
|
270
|
+
* as written. An error for anything that is not a literal.
|
|
271
|
+
*
|
|
272
|
+
* What a staging records for a module (`stagedModuleSources`): without the
|
|
273
|
+
* markers, an entry the assistant added to a record was in the module's code
|
|
274
|
+
* and not in its Source, and an edit into it was undone.
|
|
275
|
+
*/
|
|
276
|
+
function evaluateModuleSource(source) {
|
|
277
|
+
const entries = analyzeJsonValuesEntries(source);
|
|
278
|
+
if (entries.size === 0 || !ts__default["default"].isObjectLiteralExpression(source)) {
|
|
279
|
+
return evaluateExpression(source);
|
|
280
|
+
}
|
|
281
|
+
const value = {};
|
|
282
|
+
for (const prop of source.properties) {
|
|
283
|
+
if (!ts__default["default"].isPropertyAssignment(prop)) {
|
|
284
|
+
return fp.result.err(new ValSyntaxError("Expected a property assignment", prop));
|
|
285
|
+
}
|
|
286
|
+
const key = getPropertyKey(prop.name);
|
|
287
|
+
if (key === null) {
|
|
288
|
+
return fp.result.err(new ValSyntaxError("Expected a literal key", prop.name));
|
|
289
|
+
}
|
|
290
|
+
if (entries.has(key)) {
|
|
291
|
+
value[key] = {
|
|
292
|
+
_type: "json"
|
|
293
|
+
};
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const evaluated = evaluateExpression(prop.initializer);
|
|
297
|
+
if (fp.result.isErr(evaluated)) return evaluated;
|
|
298
|
+
value[key] = evaluated.value;
|
|
299
|
+
}
|
|
300
|
+
return fp.result.ok(value);
|
|
301
|
+
}
|
|
302
|
+
function getPropertyKey(name) {
|
|
303
|
+
if (ts__default["default"].isStringLiteralLike(name)) {
|
|
304
|
+
return name.text;
|
|
305
|
+
}
|
|
306
|
+
if (ts__default["default"].isIdentifier(name)) {
|
|
307
|
+
return name.text;
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
function analyzeCJsonCall(node) {
|
|
312
|
+
// c.json(() => import("path"))
|
|
313
|
+
if (!ts__default["default"].isCallExpression(node) || !isCJson(node.expression)) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
const [thunk] = node.arguments;
|
|
317
|
+
if (!thunk) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
const importPath = getImportPathFromThunk(thunk);
|
|
321
|
+
if (importPath === null) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
importPath
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function isCJson(expr) {
|
|
329
|
+
// c.json
|
|
330
|
+
return ts__default["default"].isPropertyAccessExpression(expr) && ts__default["default"].isIdentifier(expr.expression) && expr.expression.text === "c" && ts__default["default"].isIdentifier(expr.name) && expr.name.text === "json";
|
|
331
|
+
}
|
|
332
|
+
function getImportPathFromThunk(thunk) {
|
|
333
|
+
// () => import("path") (concise body) OR () => { return import("path"); }
|
|
334
|
+
if (!ts__default["default"].isArrowFunction(thunk)) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
let importCall;
|
|
338
|
+
if (ts__default["default"].isCallExpression(thunk.body)) {
|
|
339
|
+
importCall = thunk.body;
|
|
340
|
+
} else if (ts__default["default"].isBlock(thunk.body)) {
|
|
341
|
+
for (const stmt of thunk.body.statements) {
|
|
342
|
+
if (ts__default["default"].isReturnStatement(stmt) && stmt.expression && ts__default["default"].isCallExpression(stmt.expression)) {
|
|
343
|
+
importCall = stmt.expression;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (!importCall || !ts__default["default"].isCallExpression(importCall)) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
const isImport = importCall.expression.kind === ts__default["default"].SyntaxKind.ImportKeyword || ts__default["default"].isIdentifier(importCall.expression) && importCall.expression.text === "import";
|
|
352
|
+
if (!isImport) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
const arg = importCall.arguments[0];
|
|
356
|
+
if (arg && ts__default["default"].isStringLiteralLike(arg)) {
|
|
357
|
+
return arg.text;
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/*
|
|
363
|
+
* The half of a proposal's snapshot that needs the compiler: which
|
|
364
|
+
* `*.val.json` a saved entry is, read from its module's `.val.ts`. Apart from
|
|
365
|
+
* `./proposal` so that a reader serving published content -- which never has
|
|
366
|
+
* a saved entry -- does not evaluate TypeScript to start
|
|
367
|
+
* (`readerSnapshot` loads this only when there is one).
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* The `.jsonValues()` entries the proposal saved, by module and key.
|
|
372
|
+
*
|
|
373
|
+
* An entry's content is not in its module's Source -- that holds a marker per
|
|
374
|
+
* entry -- but in the entry's own `*.val.json`, and a save writes that file:
|
|
375
|
+
* it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
|
|
376
|
+
* not as Source. So the snapshot alone shows the build's entries. This is the
|
|
377
|
+
* other half: each saved `*.val.json`, read as the entry its module names.
|
|
378
|
+
*
|
|
379
|
+
* Which entry a file is comes from the module's `.val.ts`, whose
|
|
380
|
+
* `c.json(() => import("..."))` thunks name the files -- the saved text if
|
|
381
|
+
* the save rewrote it, else the build's own (`projectSource`). An entry whose
|
|
382
|
+
* module cannot be read that way is left to the build, as before: this adds
|
|
383
|
+
* what it can find and never fails the address.
|
|
384
|
+
*/
|
|
385
|
+
function proposalJsonEntries(proposal, projectSource) {
|
|
386
|
+
const found = new Map();
|
|
387
|
+
const savedJson = Object.keys(proposal.files).filter(path => path.endsWith(".val.json"));
|
|
388
|
+
if (savedJson.length === 0) return found;
|
|
389
|
+
const savedJsonPaths = new Set(savedJson);
|
|
390
|
+
for (const [moduleFilePath, source] of Object.entries(proposal.modules)) {
|
|
391
|
+
if (!holdsJsonMarkers(source)) continue;
|
|
392
|
+
const relative = moduleFilePath.replace(/^\//, "");
|
|
393
|
+
const text = proposal.files[relative] ?? (projectSource === null || projectSource === void 0 ? void 0 : projectSource[relative]);
|
|
394
|
+
if (text === undefined) continue;
|
|
395
|
+
const entries = jsonEntryPaths(relative, text);
|
|
396
|
+
if (entries === null) continue;
|
|
397
|
+
const byKey = new Map();
|
|
398
|
+
for (const [key, importPath] of entries) {
|
|
399
|
+
const jsonPath = jsonValuesPatch.resolveExistingJsonPath(moduleFilePath, importPath).replace(/^\//, "");
|
|
400
|
+
if (!savedJsonPaths.has(jsonPath)) continue;
|
|
401
|
+
const content = parseJson(proposal.files[jsonPath]);
|
|
402
|
+
if (content !== undefined) byKey.set(key, content);
|
|
403
|
+
}
|
|
404
|
+
if (byKey.size > 0) found.set(moduleFilePath, byKey);
|
|
405
|
+
}
|
|
406
|
+
return found;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
|
|
411
|
+
* `.jsonValues()` entry's content in place of its marker -- the shape a draft
|
|
412
|
+
* already has, where the entries it edits hold content and the rest are
|
|
413
|
+
* markers the readers resolve from the build. See {@link proposalJsonEntries}.
|
|
414
|
+
*
|
|
415
|
+
* For the readers only. Val's own server keeps the markers
|
|
416
|
+
* ({@link proposalSnapshot}): its patching works on them, and it takes the
|
|
417
|
+
* saved entries separately.
|
|
418
|
+
*/
|
|
419
|
+
function proposalSnapshotForReaders(proposal, projectSource) {
|
|
420
|
+
const snapshot = createPrettierFormatter.proposalSnapshot(proposal);
|
|
421
|
+
for (const [moduleFilePath, entries] of proposalJsonEntries(proposal, projectSource)) {
|
|
422
|
+
const source = snapshot[moduleFilePath];
|
|
423
|
+
if (!createPrettierFormatter.isObject(source)) continue;
|
|
424
|
+
const filled = {};
|
|
425
|
+
for (const [key, value] of Object.entries(source)) {
|
|
426
|
+
if (createPrettierFormatter.isJsonValue(value)) filled[key] = value;
|
|
427
|
+
}
|
|
428
|
+
for (const [key, content] of entries) {
|
|
429
|
+
// Own keys only: an entry may be named `toString`.
|
|
430
|
+
if (Object.prototype.hasOwnProperty.call(filled, key)) {
|
|
431
|
+
filled[key] = content;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
snapshot[moduleFilePath] = filled;
|
|
435
|
+
}
|
|
436
|
+
return snapshot;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** A record of `.jsonValues()` markers (`{ _type: "json" }`), at least one. */
|
|
440
|
+
function holdsJsonMarkers(source) {
|
|
441
|
+
return createPrettierFormatter.isObject(source) && Object.values(source).some(value => createPrettierFormatter.isObject(value) && value["_type"] === "json");
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** Each entry key's import path, from a `.jsonValues()` module's text. */
|
|
445
|
+
function jsonEntryPaths(fileName, text) {
|
|
446
|
+
try {
|
|
447
|
+
const analysis = analyzeValModule(ts__default["default"].createSourceFile(fileName, text, ts__default["default"].ScriptTarget.ES2015, true));
|
|
448
|
+
if (fp.result.isErr(analysis)) return null;
|
|
449
|
+
const paths = new Map();
|
|
450
|
+
for (const [key, entry] of analyzeJsonValuesEntries(analysis.value.source)) {
|
|
451
|
+
paths.set(key, entry.importPath);
|
|
452
|
+
}
|
|
453
|
+
return paths;
|
|
454
|
+
} catch {
|
|
455
|
+
// Not a module this can read: its entries stay the build's.
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function parseJson(text) {
|
|
460
|
+
if (text === undefined) return undefined;
|
|
461
|
+
try {
|
|
462
|
+
const value = JSON.parse(text);
|
|
463
|
+
return isMutableJsonValue(value) ? value : undefined;
|
|
464
|
+
} catch {
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** {@link isJsonValue}, for the mutable JSON a server patches. */
|
|
470
|
+
function isMutableJsonValue(value) {
|
|
471
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
if (Array.isArray(value)) {
|
|
475
|
+
return value.every(isMutableJsonValue);
|
|
476
|
+
}
|
|
477
|
+
return createPrettierFormatter.isObject(value) && Object.values(value).every(isMutableJsonValue);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
var proposalJsonEntries$1 = /*#__PURE__*/Object.freeze({
|
|
481
|
+
__proto__: null,
|
|
482
|
+
proposalJsonEntries: proposalJsonEntries,
|
|
483
|
+
proposalSnapshotForReaders: proposalSnapshotForReaders
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
exports.analyzeJsonValuesEntries = analyzeJsonValuesEntries;
|
|
487
|
+
exports.analyzeValModule = analyzeValModule;
|
|
488
|
+
exports.evaluateExpression = evaluateExpression;
|
|
489
|
+
exports.evaluateModuleSource = evaluateModuleSource;
|
|
490
|
+
exports.findObjectPropertyAssignment = findObjectPropertyAssignment;
|
|
491
|
+
exports.findObjectPropertyAssignmentToRemove = findObjectPropertyAssignmentToRemove;
|
|
492
|
+
exports.flatMapErrors = flatMapErrors;
|
|
493
|
+
exports.formatSyntaxError = formatSyntaxError;
|
|
494
|
+
exports.formatSyntaxErrorTree = formatSyntaxErrorTree;
|
|
495
|
+
exports.jsonValuesRecordKeys = jsonValuesRecordKeys;
|
|
496
|
+
exports.proposalJsonEntries = proposalJsonEntries;
|
|
497
|
+
exports.proposalJsonEntries$1 = proposalJsonEntries$1;
|
|
498
|
+
exports.proposalSnapshotForReaders = proposalSnapshotForReaders;
|
|
499
|
+
exports.shallowValidateExpression = shallowValidateExpression;
|
|
500
|
+
exports.validateInitializers = validateInitializers;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
4
|
var fp = require('@valbuild/core/fp');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var valRuntime = require('./valRuntime-ba8ff718.cjs.prod.js');
|
|
6
|
+
var proposalJsonEntries = require('./proposalJsonEntries-9e537244.cjs.prod.js');
|
|
7
|
+
var jsonValuesPatch = require('./jsonValuesPatch-92798812.cjs.prod.js');
|
|
8
|
+
var ValOpsMemory = require('./ValOpsMemory-6ebbb3ba.cjs.prod.js');
|
|
7
9
|
require('@valbuild/core');
|
|
8
|
-
require('@valbuild/ui/server');
|
|
9
10
|
require('path');
|
|
10
11
|
require('zod');
|
|
11
12
|
require('fs');
|
|
@@ -14,15 +15,12 @@ require('@valbuild/shared/internal');
|
|
|
14
15
|
require('os');
|
|
15
16
|
require('crypto');
|
|
16
17
|
require('buffer');
|
|
18
|
+
require('./createPrettierFormatter-05ad7480.cjs.prod.js');
|
|
17
19
|
require('@valbuild/core/patch');
|
|
18
20
|
require('node:vm');
|
|
19
21
|
require('node:module');
|
|
20
|
-
require('
|
|
21
|
-
require('node:https');
|
|
22
|
-
require('node:net');
|
|
22
|
+
require('./ValPatchStore-2f92eced.cjs.prod.js');
|
|
23
23
|
require('image-size');
|
|
24
|
-
require('http');
|
|
25
|
-
require('https');
|
|
26
24
|
|
|
27
25
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
28
26
|
|
|
@@ -67,7 +65,7 @@ async function getJsonEntryAtCommit(ops, commitSha, moduleFilePath, key) {
|
|
|
67
65
|
if (fp.result.isErr(moduleRes)) {
|
|
68
66
|
return moduleRes;
|
|
69
67
|
}
|
|
70
|
-
const entryPath = findEntryImportPath(moduleFilePath, moduleGitPath.value,
|
|
68
|
+
const entryPath = findEntryImportPath(moduleFilePath, moduleGitPath.value, ValOpsMemory.bytesToUtf8(moduleRes.value), key);
|
|
71
69
|
if (fp.result.isErr(entryPath)) {
|
|
72
70
|
return entryPath;
|
|
73
71
|
}
|
|
@@ -85,7 +83,7 @@ async function getJsonEntryAtCommit(ops, commitSha, moduleFilePath, key) {
|
|
|
85
83
|
return entryRes;
|
|
86
84
|
}
|
|
87
85
|
try {
|
|
88
|
-
return fp.result.ok(JSON.parse(
|
|
86
|
+
return fp.result.ok(JSON.parse(ValOpsMemory.bytesToUtf8(entryRes.value)));
|
|
89
87
|
} catch (err) {
|
|
90
88
|
return fp.result.err({
|
|
91
89
|
kind: "file-unavailable",
|
|
@@ -114,7 +112,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
114
112
|
const sourceFile = ts__default["default"].createSourceFile(moduleFilePath, valTsSource, ts__default["default"].ScriptTarget.ES2015, true);
|
|
115
113
|
let analysis;
|
|
116
114
|
try {
|
|
117
|
-
analysis =
|
|
115
|
+
analysis = proposalJsonEntries.analyzeValModule(sourceFile);
|
|
118
116
|
} catch (err) {
|
|
119
117
|
// `file-unavailable` rather than a kind of its own: the module's TEXT is
|
|
120
118
|
// the file we could not use, and adding a wire kind for "unparseable"
|
|
@@ -132,7 +130,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
132
130
|
message: "could not read the module at this commit"
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
|
-
const entries =
|
|
133
|
+
const entries = proposalJsonEntries.analyzeJsonValuesEntries(analysis.value.source);
|
|
136
134
|
const entry = entries.get(key);
|
|
137
135
|
if (entry === undefined) {
|
|
138
136
|
/*
|
|
@@ -147,8 +145,8 @@ moduleGitPath, valTsSource, key) {
|
|
|
147
145
|
message: `'${key}' had no entry at this commit`
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
|
-
const moduleDir =
|
|
151
|
-
return fp.result.ok(
|
|
148
|
+
const moduleDir = jsonValuesPatch.posixPath.dirname(moduleFilePath);
|
|
149
|
+
return fp.result.ok(jsonValuesPatch.posixPath.join(moduleDir, entry.importPath));
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
/**
|
|
@@ -169,8 +167,8 @@ moduleGitPath, valTsSource, key) {
|
|
|
169
167
|
* if TypeScript becomes reachable from `@valbuild/server/browser` again.
|
|
170
168
|
*/
|
|
171
169
|
|
|
172
|
-
const tsOps = new
|
|
173
|
-
return fp.pipe(
|
|
170
|
+
const tsOps = new valRuntime.TSOps(document => {
|
|
171
|
+
return fp.pipe(proposalJsonEntries.analyzeValModule(document), fp.result.map(({
|
|
174
172
|
source
|
|
175
173
|
}) => source));
|
|
176
174
|
});
|
|
@@ -180,12 +178,12 @@ function parseValFile(text) {
|
|
|
180
178
|
return ts__default["default"].createSourceFile("<val>", text, ts__default["default"].ScriptTarget.ES2015);
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
exports.
|
|
184
|
-
exports.
|
|
185
|
-
exports.
|
|
186
|
-
exports.
|
|
187
|
-
exports.
|
|
188
|
-
exports.
|
|
181
|
+
exports.insertValJsonEntry = valRuntime.insertValJsonEntry;
|
|
182
|
+
exports.removeValJsonEntry = valRuntime.removeValJsonEntry;
|
|
183
|
+
exports.analyzeJsonValuesEntries = proposalJsonEntries.analyzeJsonValuesEntries;
|
|
184
|
+
exports.analyzeValModule = proposalJsonEntries.analyzeValModule;
|
|
185
|
+
exports.evaluateModuleSource = proposalJsonEntries.evaluateModuleSource;
|
|
186
|
+
exports.jsonValuesRecordKeys = proposalJsonEntries.jsonValuesRecordKeys;
|
|
189
187
|
exports.getJsonEntryAtCommit = getJsonEntryAtCommit;
|
|
190
188
|
exports.parseValFile = parseValFile;
|
|
191
189
|
exports.tsOps = tsOps;
|