@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.
- package/CHANGELOG.md +25 -0
- package/browser/dist/valbuild-server-browser.cjs.dev.js +2 -2
- package/browser/dist/valbuild-server-browser.cjs.prod.js +2 -2
- package/browser/dist/valbuild-server-browser.esm.js +2 -2
- package/dist/{ValOpsMemory-a1a58597.cjs.prod.js → ValOpsMemory-073f9526.cjs.prod.js} +1 -1
- package/dist/{ValOpsMemory-88633e0f.cjs.dev.js → ValOpsMemory-3ce3e9e8.cjs.dev.js} +1 -1
- package/dist/{ValOpsMemory-82af54c9.esm.js → ValOpsMemory-ecc15827.esm.js} +1 -1
- package/dist/{createPrettierFormatter-5d830bdf.cjs.dev.js → createPrettierFormatter-8e60f596.cjs.prod.js} +1 -1
- package/dist/{createPrettierFormatter-b31bfbe5.cjs.prod.js → createPrettierFormatter-a9109288.cjs.dev.js} +1 -1
- package/dist/{createPrettierFormatter-ce478de1.esm.js → createPrettierFormatter-fb68e363.esm.js} +1 -1
- package/dist/{createValRuntime-d34c69e8.esm.js → createValRuntime-02197b93.esm.js} +6 -4
- package/dist/{createValRuntime-07bf43dd.cjs.prod.js → createValRuntime-42622f8f.cjs.prod.js} +6 -4
- package/dist/{createValRuntime-858474b4.cjs.dev.js → createValRuntime-b55d14f0.cjs.dev.js} +6 -4
- package/dist/declarations/src/internal/index.d.ts +14 -0
- package/dist/declarations/src/proposalMerge/foldContent.d.ts +45 -0
- package/dist/declarations/src/proposalMerge/project.d.ts +124 -0
- package/dist/declarations/src/proposalMerge/threeWay.d.ts +51 -0
- package/dist/declarations/src/proposalMerge/validate.d.ts +16 -0
- package/dist/foldContent-2c218a30.cjs.dev.js +216 -0
- package/dist/foldContent-54f2c87c.cjs.prod.js +216 -0
- package/dist/foldContent-f065c19f.esm.js +214 -0
- package/dist/{inTabFetch-e9a48fac.cjs.prod.js → inTabFetch-46ad6b87.cjs.prod.js} +1 -1
- package/dist/{inTabFetch-54c1cb83.esm.js → inTabFetch-6dacc8a1.esm.js} +1 -1
- package/dist/{inTabFetch-fb9cf5e0.cjs.dev.js → inTabFetch-85b1aef4.cjs.dev.js} +1 -1
- package/dist/{proposalJsonEntries-2cd6f6fe.esm.js → jsonValuesModule-12fc4bb0.esm.js} +2 -128
- package/dist/{proposalJsonEntries-d21900d4.cjs.dev.js → jsonValuesModule-6cf73937.cjs.prod.js} +2 -130
- package/dist/{proposalJsonEntries-d4623810.cjs.prod.js → jsonValuesModule-ed68a9de.cjs.dev.js} +2 -130
- package/dist/merge-5a8fc685.cjs.prod.js +1596 -0
- package/dist/merge-a21a9c78.cjs.dev.js +1596 -0
- package/dist/merge-eca8ec38.esm.js +1566 -0
- package/dist/proposalJsonEntries-4fcfab08.cjs.prod.js +135 -0
- package/dist/proposalJsonEntries-878ad5b6.cjs.dev.js +135 -0
- package/dist/proposalJsonEntries-e1b07915.esm.js +128 -0
- package/dist/{publishKit-cf3858a0.cjs.prod.js → publishKit-70276aed.cjs.prod.js} +19 -22
- package/dist/{publishKit-4e7a1516.esm.js → publishKit-a732e3c3.esm.js} +11 -14
- package/dist/{publishKit-6b88a02e.cjs.dev.js → publishKit-f7a77be5.cjs.dev.js} +19 -22
- package/dist/{valRuntime-ca9958fc.esm.js → valRuntime-407399c1.esm.js} +11 -982
- package/dist/{valRuntime-5cadce34.cjs.dev.js → valRuntime-7a4bbb5d.cjs.dev.js} +21 -995
- package/dist/{valRuntime-ae69b225.cjs.prod.js → valRuntime-8585d3ce.cjs.prod.js} +21 -995
- package/dist/valbuild-server.cjs.dev.js +45 -462
- package/dist/valbuild-server.cjs.prod.js +45 -462
- package/dist/valbuild-server.esm.js +15 -431
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.dev.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.cjs.prod.js +2 -2
- package/internal/browser/dist/valbuild-server-internal-browser.esm.js +2 -2
- package/internal/dist/valbuild-server-internal.cjs.dev.js +20 -2
- package/internal/dist/valbuild-server-internal.cjs.prod.js +20 -2
- package/internal/dist/valbuild-server-internal.esm.js +20 -3
- package/package.json +4 -4
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { result, pipe } from '@valbuild/core/fp';
|
|
2
1
|
import ts from 'typescript';
|
|
3
|
-
import {
|
|
4
|
-
import { a as proposalSnapshot, i as isObject, d as isJsonValue } from './createPrettierFormatter-ce478de1.esm.js';
|
|
2
|
+
import { result, pipe } from '@valbuild/core/fp';
|
|
5
3
|
|
|
6
4
|
class ValSyntaxError {
|
|
7
5
|
constructor(message, node) {
|
|
@@ -353,128 +351,4 @@ function getImportPathFromThunk(thunk) {
|
|
|
353
351
|
return null;
|
|
354
352
|
}
|
|
355
353
|
|
|
356
|
-
|
|
357
|
-
* The half of a proposal's snapshot that needs the compiler: which
|
|
358
|
-
* `*.val.json` a saved entry is, read from its module's `.val.ts`. Apart from
|
|
359
|
-
* `./proposal` so that a reader serving published content -- which never has
|
|
360
|
-
* a saved entry -- does not evaluate TypeScript to start
|
|
361
|
-
* (`readerSnapshot` loads this only when there is one).
|
|
362
|
-
*/
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* The `.jsonValues()` entries the proposal saved, by module and key.
|
|
366
|
-
*
|
|
367
|
-
* An entry's content is not in its module's Source -- that holds a marker per
|
|
368
|
-
* entry -- but in the entry's own `*.val.json`, and a save writes that file:
|
|
369
|
-
* it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
|
|
370
|
-
* not as Source. So the snapshot alone shows the build's entries. This is the
|
|
371
|
-
* other half: each saved `*.val.json`, read as the entry its module names.
|
|
372
|
-
*
|
|
373
|
-
* Which entry a file is comes from the module's `.val.ts`, whose
|
|
374
|
-
* `c.json(() => import("..."))` thunks name the files -- the saved text if
|
|
375
|
-
* the save rewrote it, else the build's own (`projectSource`). An entry whose
|
|
376
|
-
* module cannot be read that way is left to the build, as before: this adds
|
|
377
|
-
* what it can find and never fails the address.
|
|
378
|
-
*/
|
|
379
|
-
function proposalJsonEntries(proposal, projectSource) {
|
|
380
|
-
const found = new Map();
|
|
381
|
-
const savedJson = Object.keys(proposal.files).filter(path => path.endsWith(".val.json"));
|
|
382
|
-
if (savedJson.length === 0) return found;
|
|
383
|
-
const savedJsonPaths = new Set(savedJson);
|
|
384
|
-
for (const [moduleFilePath, source] of Object.entries(proposal.modules)) {
|
|
385
|
-
if (!holdsJsonMarkers(source)) continue;
|
|
386
|
-
const relative = moduleFilePath.replace(/^\//, "");
|
|
387
|
-
const text = proposal.files[relative] ?? (projectSource === null || projectSource === void 0 ? void 0 : projectSource[relative]);
|
|
388
|
-
if (text === undefined) continue;
|
|
389
|
-
const entries = jsonEntryPaths(relative, text);
|
|
390
|
-
if (entries === null) continue;
|
|
391
|
-
const byKey = new Map();
|
|
392
|
-
for (const [key, importPath] of entries) {
|
|
393
|
-
const jsonPath = resolveExistingJsonPath(moduleFilePath, importPath).replace(/^\//, "");
|
|
394
|
-
if (!savedJsonPaths.has(jsonPath)) continue;
|
|
395
|
-
const content = parseJson(proposal.files[jsonPath]);
|
|
396
|
-
if (content !== undefined) byKey.set(key, content);
|
|
397
|
-
}
|
|
398
|
-
if (byKey.size > 0) found.set(moduleFilePath, byKey);
|
|
399
|
-
}
|
|
400
|
-
return found;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
|
|
405
|
-
* `.jsonValues()` entry's content in place of its marker -- the shape a draft
|
|
406
|
-
* already has, where the entries it edits hold content and the rest are
|
|
407
|
-
* markers the readers resolve from the build. See {@link proposalJsonEntries}.
|
|
408
|
-
*
|
|
409
|
-
* For the readers only. Val's own server keeps the markers
|
|
410
|
-
* ({@link proposalSnapshot}): its patching works on them, and it takes the
|
|
411
|
-
* saved entries separately.
|
|
412
|
-
*/
|
|
413
|
-
function proposalSnapshotForReaders(proposal, projectSource) {
|
|
414
|
-
const snapshot = proposalSnapshot(proposal);
|
|
415
|
-
for (const [moduleFilePath, entries] of proposalJsonEntries(proposal, projectSource)) {
|
|
416
|
-
const source = snapshot[moduleFilePath];
|
|
417
|
-
if (!isObject(source)) continue;
|
|
418
|
-
const filled = {};
|
|
419
|
-
for (const [key, value] of Object.entries(source)) {
|
|
420
|
-
if (isJsonValue(value)) filled[key] = value;
|
|
421
|
-
}
|
|
422
|
-
for (const [key, content] of entries) {
|
|
423
|
-
// Own keys only: an entry may be named `toString`.
|
|
424
|
-
if (Object.prototype.hasOwnProperty.call(filled, key)) {
|
|
425
|
-
filled[key] = content;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
snapshot[moduleFilePath] = filled;
|
|
429
|
-
}
|
|
430
|
-
return snapshot;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/** A record of `.jsonValues()` markers (`{ _type: "json" }`), at least one. */
|
|
434
|
-
function holdsJsonMarkers(source) {
|
|
435
|
-
return isObject(source) && Object.values(source).some(value => isObject(value) && value["_type"] === "json");
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/** Each entry key's import path, from a `.jsonValues()` module's text. */
|
|
439
|
-
function jsonEntryPaths(fileName, text) {
|
|
440
|
-
try {
|
|
441
|
-
const analysis = analyzeValModule(ts.createSourceFile(fileName, text, ts.ScriptTarget.ES2015, true));
|
|
442
|
-
if (result.isErr(analysis)) return null;
|
|
443
|
-
const paths = new Map();
|
|
444
|
-
for (const [key, entry] of analyzeJsonValuesEntries(analysis.value.source)) {
|
|
445
|
-
paths.set(key, entry.importPath);
|
|
446
|
-
}
|
|
447
|
-
return paths;
|
|
448
|
-
} catch {
|
|
449
|
-
// Not a module this can read: its entries stay the build's.
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
function parseJson(text) {
|
|
454
|
-
if (text === undefined) return undefined;
|
|
455
|
-
try {
|
|
456
|
-
const value = JSON.parse(text);
|
|
457
|
-
return isMutableJsonValue(value) ? value : undefined;
|
|
458
|
-
} catch {
|
|
459
|
-
return undefined;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/** {@link isJsonValue}, for the mutable JSON a server patches. */
|
|
464
|
-
function isMutableJsonValue(value) {
|
|
465
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
466
|
-
return true;
|
|
467
|
-
}
|
|
468
|
-
if (Array.isArray(value)) {
|
|
469
|
-
return value.every(isMutableJsonValue);
|
|
470
|
-
}
|
|
471
|
-
return isObject(value) && Object.values(value).every(isMutableJsonValue);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
var proposalJsonEntries$1 = /*#__PURE__*/Object.freeze({
|
|
475
|
-
__proto__: null,
|
|
476
|
-
proposalJsonEntries: proposalJsonEntries,
|
|
477
|
-
proposalSnapshotForReaders: proposalSnapshotForReaders
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
export { analyzeValModule as a, formatSyntaxError as b, analyzeJsonValuesEntries as c, formatSyntaxErrorTree as d, findObjectPropertyAssignment as e, flatMapErrors as f, findObjectPropertyAssignmentToRemove as g, evaluateExpression as h, proposalJsonEntries as i, evaluateModuleSource as j, jsonValuesRecordKeys as k, proposalJsonEntries$1 as l, proposalSnapshotForReaders as p, shallowValidateExpression as s, validateInitializers as v };
|
|
354
|
+
export { ValSyntaxError as V, analyzeValModule as a, formatSyntaxError as b, analyzeJsonValuesEntries as c, formatSyntaxErrorTree as d, findObjectPropertyAssignment as e, flatMapErrors as f, findObjectPropertyAssignmentToRemove as g, evaluateExpression as h, evaluateModuleSource as i, jsonValuesRecordKeys as j, shallowValidateExpression as s, validateInitializers as v };
|
package/dist/{proposalJsonEntries-d21900d4.cjs.dev.js → jsonValuesModule-6cf73937.cjs.prod.js}
RENAMED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fp = require('@valbuild/core/fp');
|
|
4
3
|
var ts = require('typescript');
|
|
5
|
-
var
|
|
6
|
-
var createPrettierFormatter = require('./createPrettierFormatter-5d830bdf.cjs.dev.js');
|
|
4
|
+
var fp = require('@valbuild/core/fp');
|
|
7
5
|
|
|
8
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
9
7
|
|
|
@@ -359,130 +357,7 @@ function getImportPathFromThunk(thunk) {
|
|
|
359
357
|
return null;
|
|
360
358
|
}
|
|
361
359
|
|
|
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
|
-
|
|
360
|
+
exports.ValSyntaxError = ValSyntaxError;
|
|
486
361
|
exports.analyzeJsonValuesEntries = analyzeJsonValuesEntries;
|
|
487
362
|
exports.analyzeValModule = analyzeValModule;
|
|
488
363
|
exports.evaluateExpression = evaluateExpression;
|
|
@@ -493,8 +368,5 @@ exports.flatMapErrors = flatMapErrors;
|
|
|
493
368
|
exports.formatSyntaxError = formatSyntaxError;
|
|
494
369
|
exports.formatSyntaxErrorTree = formatSyntaxErrorTree;
|
|
495
370
|
exports.jsonValuesRecordKeys = jsonValuesRecordKeys;
|
|
496
|
-
exports.proposalJsonEntries = proposalJsonEntries;
|
|
497
|
-
exports.proposalJsonEntries$1 = proposalJsonEntries$1;
|
|
498
|
-
exports.proposalSnapshotForReaders = proposalSnapshotForReaders;
|
|
499
371
|
exports.shallowValidateExpression = shallowValidateExpression;
|
|
500
372
|
exports.validateInitializers = validateInitializers;
|
package/dist/{proposalJsonEntries-d4623810.cjs.prod.js → jsonValuesModule-ed68a9de.cjs.dev.js}
RENAMED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var fp = require('@valbuild/core/fp');
|
|
4
3
|
var ts = require('typescript');
|
|
5
|
-
var
|
|
6
|
-
var createPrettierFormatter = require('./createPrettierFormatter-b31bfbe5.cjs.prod.js');
|
|
4
|
+
var fp = require('@valbuild/core/fp');
|
|
7
5
|
|
|
8
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
9
7
|
|
|
@@ -359,130 +357,7 @@ function getImportPathFromThunk(thunk) {
|
|
|
359
357
|
return null;
|
|
360
358
|
}
|
|
361
359
|
|
|
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
|
-
|
|
360
|
+
exports.ValSyntaxError = ValSyntaxError;
|
|
486
361
|
exports.analyzeJsonValuesEntries = analyzeJsonValuesEntries;
|
|
487
362
|
exports.analyzeValModule = analyzeValModule;
|
|
488
363
|
exports.evaluateExpression = evaluateExpression;
|
|
@@ -493,8 +368,5 @@ exports.flatMapErrors = flatMapErrors;
|
|
|
493
368
|
exports.formatSyntaxError = formatSyntaxError;
|
|
494
369
|
exports.formatSyntaxErrorTree = formatSyntaxErrorTree;
|
|
495
370
|
exports.jsonValuesRecordKeys = jsonValuesRecordKeys;
|
|
496
|
-
exports.proposalJsonEntries = proposalJsonEntries;
|
|
497
|
-
exports.proposalJsonEntries$1 = proposalJsonEntries$1;
|
|
498
|
-
exports.proposalSnapshotForReaders = proposalSnapshotForReaders;
|
|
499
371
|
exports.shallowValidateExpression = shallowValidateExpression;
|
|
500
372
|
exports.validateInitializers = validateInitializers;
|