@valbuild/server 0.155.0 → 0.156.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -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-f000531b.cjs.prod.js → ValOpsMemory-6155aa9b.cjs.prod.js} +36 -4
- package/dist/{ValOpsMemory-1a0bc2dc.esm.js → ValOpsMemory-a00c3187.esm.js} +36 -4
- package/dist/{ValOpsMemory-6e829758.cjs.dev.js → ValOpsMemory-c1453e6a.cjs.dev.js} +36 -4
- 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-f55300a0.esm.js → createValRuntime-4371c69b.esm.js} +6 -4
- package/dist/{createValRuntime-a519939b.cjs.prod.js → createValRuntime-5eb0336d.cjs.prod.js} +6 -4
- package/dist/{createValRuntime-1c7d891e.cjs.dev.js → createValRuntime-82f38747.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-dae5dd87.esm.js → inTabFetch-22fc6815.esm.js} +1 -1
- package/dist/{inTabFetch-3d8ceb84.cjs.prod.js → inTabFetch-4efbd411.cjs.prod.js} +1 -1
- package/dist/{inTabFetch-75753a09.cjs.dev.js → inTabFetch-f5eedbd0.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-395b92e5.cjs.prod.js → publishKit-0ec427f3.cjs.prod.js} +19 -22
- package/dist/{publishKit-04b6d255.esm.js → publishKit-a40062cd.esm.js} +11 -14
- package/dist/{publishKit-de4baed6.cjs.dev.js → publishKit-ffcaf2af.cjs.dev.js} +19 -22
- package/dist/{valRuntime-e922e372.cjs.prod.js → valRuntime-175e2032.cjs.prod.js} +21 -995
- package/dist/{valRuntime-7fd12e16.esm.js → valRuntime-18d4c693.esm.js} +11 -982
- package/dist/{valRuntime-d3cc6e0d.cjs.dev.js → valRuntime-c4b2e906.cjs.dev.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 +3 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fp = require('@valbuild/core/fp');
|
|
4
|
+
var ts = require('typescript');
|
|
5
|
+
var jsonValuesModule = require('./jsonValuesModule-6cf73937.cjs.prod.js');
|
|
6
|
+
var jsonValuesPatch = require('./jsonValuesPatch-92798812.cjs.prod.js');
|
|
7
|
+
var createPrettierFormatter = require('./createPrettierFormatter-8e60f596.cjs.prod.js');
|
|
8
|
+
require('@valbuild/shared/internal');
|
|
9
|
+
require('@valbuild/core');
|
|
10
|
+
require('path');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* The half of a proposal's snapshot that needs the compiler: which
|
|
18
|
+
* `*.val.json` a saved entry is, read from its module's `.val.ts`. Apart from
|
|
19
|
+
* `./proposal` so that a reader serving published content -- which never has
|
|
20
|
+
* a saved entry -- does not evaluate TypeScript to start
|
|
21
|
+
* (`readerSnapshot` loads this only when there is one).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The `.jsonValues()` entries the proposal saved, by module and key.
|
|
26
|
+
*
|
|
27
|
+
* An entry's content is not in its module's Source -- that holds a marker per
|
|
28
|
+
* entry -- but in the entry's own `*.val.json`, and a save writes that file:
|
|
29
|
+
* it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
|
|
30
|
+
* not as Source. So the snapshot alone shows the build's entries. This is the
|
|
31
|
+
* other half: each saved `*.val.json`, read as the entry its module names.
|
|
32
|
+
*
|
|
33
|
+
* Which entry a file is comes from the module's `.val.ts`, whose
|
|
34
|
+
* `c.json(() => import("..."))` thunks name the files -- the saved text if
|
|
35
|
+
* the save rewrote it, else the build's own (`projectSource`). An entry whose
|
|
36
|
+
* module cannot be read that way is left to the build, as before: this adds
|
|
37
|
+
* what it can find and never fails the address.
|
|
38
|
+
*/
|
|
39
|
+
function proposalJsonEntries(proposal, projectSource) {
|
|
40
|
+
const found = new Map();
|
|
41
|
+
const savedJson = Object.keys(proposal.files).filter(path => path.endsWith(".val.json"));
|
|
42
|
+
if (savedJson.length === 0) return found;
|
|
43
|
+
const savedJsonPaths = new Set(savedJson);
|
|
44
|
+
for (const [moduleFilePath, source] of Object.entries(proposal.modules)) {
|
|
45
|
+
if (!holdsJsonMarkers(source)) continue;
|
|
46
|
+
const relative = moduleFilePath.replace(/^\//, "");
|
|
47
|
+
const text = proposal.files[relative] ?? (projectSource === null || projectSource === void 0 ? void 0 : projectSource[relative]);
|
|
48
|
+
if (text === undefined) continue;
|
|
49
|
+
const entries = jsonEntryPaths(relative, text);
|
|
50
|
+
if (entries === null) continue;
|
|
51
|
+
const byKey = new Map();
|
|
52
|
+
for (const [key, importPath] of entries) {
|
|
53
|
+
const jsonPath = jsonValuesPatch.resolveExistingJsonPath(moduleFilePath, importPath).replace(/^\//, "");
|
|
54
|
+
if (!savedJsonPaths.has(jsonPath)) continue;
|
|
55
|
+
const content = parseJson(proposal.files[jsonPath]);
|
|
56
|
+
if (content !== undefined) byKey.set(key, content);
|
|
57
|
+
}
|
|
58
|
+
if (byKey.size > 0) found.set(moduleFilePath, byKey);
|
|
59
|
+
}
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
|
|
65
|
+
* `.jsonValues()` entry's content in place of its marker -- the shape a draft
|
|
66
|
+
* already has, where the entries it edits hold content and the rest are
|
|
67
|
+
* markers the readers resolve from the build. See {@link proposalJsonEntries}.
|
|
68
|
+
*
|
|
69
|
+
* For the readers only. Val's own server keeps the markers
|
|
70
|
+
* ({@link proposalSnapshot}): its patching works on them, and it takes the
|
|
71
|
+
* saved entries separately.
|
|
72
|
+
*/
|
|
73
|
+
function proposalSnapshotForReaders(proposal, projectSource) {
|
|
74
|
+
const snapshot = createPrettierFormatter.proposalSnapshot(proposal);
|
|
75
|
+
for (const [moduleFilePath, entries] of proposalJsonEntries(proposal, projectSource)) {
|
|
76
|
+
const source = snapshot[moduleFilePath];
|
|
77
|
+
if (!createPrettierFormatter.isObject(source)) continue;
|
|
78
|
+
const filled = {};
|
|
79
|
+
for (const [key, value] of Object.entries(source)) {
|
|
80
|
+
if (createPrettierFormatter.isJsonValue(value)) filled[key] = value;
|
|
81
|
+
}
|
|
82
|
+
for (const [key, content] of entries) {
|
|
83
|
+
// Own keys only: an entry may be named `toString`.
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(filled, key)) {
|
|
85
|
+
filled[key] = content;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
snapshot[moduleFilePath] = filled;
|
|
89
|
+
}
|
|
90
|
+
return snapshot;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A record of `.jsonValues()` markers (`{ _type: "json" }`), at least one. */
|
|
94
|
+
function holdsJsonMarkers(source) {
|
|
95
|
+
return createPrettierFormatter.isObject(source) && Object.values(source).some(value => createPrettierFormatter.isObject(value) && value["_type"] === "json");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Each entry key's import path, from a `.jsonValues()` module's text. */
|
|
99
|
+
function jsonEntryPaths(fileName, text) {
|
|
100
|
+
try {
|
|
101
|
+
const analysis = jsonValuesModule.analyzeValModule(ts__default["default"].createSourceFile(fileName, text, ts__default["default"].ScriptTarget.ES2015, true));
|
|
102
|
+
if (fp.result.isErr(analysis)) return null;
|
|
103
|
+
const paths = new Map();
|
|
104
|
+
for (const [key, entry] of jsonValuesModule.analyzeJsonValuesEntries(analysis.value.source)) {
|
|
105
|
+
paths.set(key, entry.importPath);
|
|
106
|
+
}
|
|
107
|
+
return paths;
|
|
108
|
+
} catch {
|
|
109
|
+
// Not a module this can read: its entries stay the build's.
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseJson(text) {
|
|
114
|
+
if (text === undefined) return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const value = JSON.parse(text);
|
|
117
|
+
return isMutableJsonValue(value) ? value : undefined;
|
|
118
|
+
} catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** {@link isJsonValue}, for the mutable JSON a server patches. */
|
|
124
|
+
function isMutableJsonValue(value) {
|
|
125
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
return value.every(isMutableJsonValue);
|
|
130
|
+
}
|
|
131
|
+
return createPrettierFormatter.isObject(value) && Object.values(value).every(isMutableJsonValue);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
exports.proposalJsonEntries = proposalJsonEntries;
|
|
135
|
+
exports.proposalSnapshotForReaders = proposalSnapshotForReaders;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fp = require('@valbuild/core/fp');
|
|
4
|
+
var ts = require('typescript');
|
|
5
|
+
var jsonValuesModule = require('./jsonValuesModule-ed68a9de.cjs.dev.js');
|
|
6
|
+
var jsonValuesPatch = require('./jsonValuesPatch-88bc661d.cjs.dev.js');
|
|
7
|
+
var createPrettierFormatter = require('./createPrettierFormatter-a9109288.cjs.dev.js');
|
|
8
|
+
require('@valbuild/shared/internal');
|
|
9
|
+
require('@valbuild/core');
|
|
10
|
+
require('path');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* The half of a proposal's snapshot that needs the compiler: which
|
|
18
|
+
* `*.val.json` a saved entry is, read from its module's `.val.ts`. Apart from
|
|
19
|
+
* `./proposal` so that a reader serving published content -- which never has
|
|
20
|
+
* a saved entry -- does not evaluate TypeScript to start
|
|
21
|
+
* (`readerSnapshot` loads this only when there is one).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The `.jsonValues()` entries the proposal saved, by module and key.
|
|
26
|
+
*
|
|
27
|
+
* An entry's content is not in its module's Source -- that holds a marker per
|
|
28
|
+
* entry -- but in the entry's own `*.val.json`, and a save writes that file:
|
|
29
|
+
* it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
|
|
30
|
+
* not as Source. So the snapshot alone shows the build's entries. This is the
|
|
31
|
+
* other half: each saved `*.val.json`, read as the entry its module names.
|
|
32
|
+
*
|
|
33
|
+
* Which entry a file is comes from the module's `.val.ts`, whose
|
|
34
|
+
* `c.json(() => import("..."))` thunks name the files -- the saved text if
|
|
35
|
+
* the save rewrote it, else the build's own (`projectSource`). An entry whose
|
|
36
|
+
* module cannot be read that way is left to the build, as before: this adds
|
|
37
|
+
* what it can find and never fails the address.
|
|
38
|
+
*/
|
|
39
|
+
function proposalJsonEntries(proposal, projectSource) {
|
|
40
|
+
const found = new Map();
|
|
41
|
+
const savedJson = Object.keys(proposal.files).filter(path => path.endsWith(".val.json"));
|
|
42
|
+
if (savedJson.length === 0) return found;
|
|
43
|
+
const savedJsonPaths = new Set(savedJson);
|
|
44
|
+
for (const [moduleFilePath, source] of Object.entries(proposal.modules)) {
|
|
45
|
+
if (!holdsJsonMarkers(source)) continue;
|
|
46
|
+
const relative = moduleFilePath.replace(/^\//, "");
|
|
47
|
+
const text = proposal.files[relative] ?? (projectSource === null || projectSource === void 0 ? void 0 : projectSource[relative]);
|
|
48
|
+
if (text === undefined) continue;
|
|
49
|
+
const entries = jsonEntryPaths(relative, text);
|
|
50
|
+
if (entries === null) continue;
|
|
51
|
+
const byKey = new Map();
|
|
52
|
+
for (const [key, importPath] of entries) {
|
|
53
|
+
const jsonPath = jsonValuesPatch.resolveExistingJsonPath(moduleFilePath, importPath).replace(/^\//, "");
|
|
54
|
+
if (!savedJsonPaths.has(jsonPath)) continue;
|
|
55
|
+
const content = parseJson(proposal.files[jsonPath]);
|
|
56
|
+
if (content !== undefined) byKey.set(key, content);
|
|
57
|
+
}
|
|
58
|
+
if (byKey.size > 0) found.set(moduleFilePath, byKey);
|
|
59
|
+
}
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
|
|
65
|
+
* `.jsonValues()` entry's content in place of its marker -- the shape a draft
|
|
66
|
+
* already has, where the entries it edits hold content and the rest are
|
|
67
|
+
* markers the readers resolve from the build. See {@link proposalJsonEntries}.
|
|
68
|
+
*
|
|
69
|
+
* For the readers only. Val's own server keeps the markers
|
|
70
|
+
* ({@link proposalSnapshot}): its patching works on them, and it takes the
|
|
71
|
+
* saved entries separately.
|
|
72
|
+
*/
|
|
73
|
+
function proposalSnapshotForReaders(proposal, projectSource) {
|
|
74
|
+
const snapshot = createPrettierFormatter.proposalSnapshot(proposal);
|
|
75
|
+
for (const [moduleFilePath, entries] of proposalJsonEntries(proposal, projectSource)) {
|
|
76
|
+
const source = snapshot[moduleFilePath];
|
|
77
|
+
if (!createPrettierFormatter.isObject(source)) continue;
|
|
78
|
+
const filled = {};
|
|
79
|
+
for (const [key, value] of Object.entries(source)) {
|
|
80
|
+
if (createPrettierFormatter.isJsonValue(value)) filled[key] = value;
|
|
81
|
+
}
|
|
82
|
+
for (const [key, content] of entries) {
|
|
83
|
+
// Own keys only: an entry may be named `toString`.
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(filled, key)) {
|
|
85
|
+
filled[key] = content;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
snapshot[moduleFilePath] = filled;
|
|
89
|
+
}
|
|
90
|
+
return snapshot;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A record of `.jsonValues()` markers (`{ _type: "json" }`), at least one. */
|
|
94
|
+
function holdsJsonMarkers(source) {
|
|
95
|
+
return createPrettierFormatter.isObject(source) && Object.values(source).some(value => createPrettierFormatter.isObject(value) && value["_type"] === "json");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Each entry key's import path, from a `.jsonValues()` module's text. */
|
|
99
|
+
function jsonEntryPaths(fileName, text) {
|
|
100
|
+
try {
|
|
101
|
+
const analysis = jsonValuesModule.analyzeValModule(ts__default["default"].createSourceFile(fileName, text, ts__default["default"].ScriptTarget.ES2015, true));
|
|
102
|
+
if (fp.result.isErr(analysis)) return null;
|
|
103
|
+
const paths = new Map();
|
|
104
|
+
for (const [key, entry] of jsonValuesModule.analyzeJsonValuesEntries(analysis.value.source)) {
|
|
105
|
+
paths.set(key, entry.importPath);
|
|
106
|
+
}
|
|
107
|
+
return paths;
|
|
108
|
+
} catch {
|
|
109
|
+
// Not a module this can read: its entries stay the build's.
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseJson(text) {
|
|
114
|
+
if (text === undefined) return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const value = JSON.parse(text);
|
|
117
|
+
return isMutableJsonValue(value) ? value : undefined;
|
|
118
|
+
} catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** {@link isJsonValue}, for the mutable JSON a server patches. */
|
|
124
|
+
function isMutableJsonValue(value) {
|
|
125
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
return value.every(isMutableJsonValue);
|
|
130
|
+
}
|
|
131
|
+
return createPrettierFormatter.isObject(value) && Object.values(value).every(isMutableJsonValue);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
exports.proposalJsonEntries = proposalJsonEntries;
|
|
135
|
+
exports.proposalSnapshotForReaders = proposalSnapshotForReaders;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { result } from '@valbuild/core/fp';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-12fc4bb0.esm.js';
|
|
4
|
+
import { r as resolveExistingJsonPath } from './jsonValuesPatch-13acc674.esm.js';
|
|
5
|
+
import { a as proposalSnapshot, i as isObject, d as isJsonValue } from './createPrettierFormatter-fb68e363.esm.js';
|
|
6
|
+
import '@valbuild/shared/internal';
|
|
7
|
+
import '@valbuild/core';
|
|
8
|
+
import 'path';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* The half of a proposal's snapshot that needs the compiler: which
|
|
12
|
+
* `*.val.json` a saved entry is, read from its module's `.val.ts`. Apart from
|
|
13
|
+
* `./proposal` so that a reader serving published content -- which never has
|
|
14
|
+
* a saved entry -- does not evaluate TypeScript to start
|
|
15
|
+
* (`readerSnapshot` loads this only when there is one).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `.jsonValues()` entries the proposal saved, by module and key.
|
|
20
|
+
*
|
|
21
|
+
* An entry's content is not in its module's Source -- that holds a marker per
|
|
22
|
+
* entry -- but in the entry's own `*.val.json`, and a save writes that file:
|
|
23
|
+
* it reaches the proposal's address as saved TEXT ({@link ValProposal.files}),
|
|
24
|
+
* not as Source. So the snapshot alone shows the build's entries. This is the
|
|
25
|
+
* other half: each saved `*.val.json`, read as the entry its module names.
|
|
26
|
+
*
|
|
27
|
+
* Which entry a file is comes from the module's `.val.ts`, whose
|
|
28
|
+
* `c.json(() => import("..."))` thunks name the files -- the saved text if
|
|
29
|
+
* the save rewrote it, else the build's own (`projectSource`). An entry whose
|
|
30
|
+
* module cannot be read that way is left to the build, as before: this adds
|
|
31
|
+
* what it can find and never fails the address.
|
|
32
|
+
*/
|
|
33
|
+
function proposalJsonEntries(proposal, projectSource) {
|
|
34
|
+
const found = new Map();
|
|
35
|
+
const savedJson = Object.keys(proposal.files).filter(path => path.endsWith(".val.json"));
|
|
36
|
+
if (savedJson.length === 0) return found;
|
|
37
|
+
const savedJsonPaths = new Set(savedJson);
|
|
38
|
+
for (const [moduleFilePath, source] of Object.entries(proposal.modules)) {
|
|
39
|
+
if (!holdsJsonMarkers(source)) continue;
|
|
40
|
+
const relative = moduleFilePath.replace(/^\//, "");
|
|
41
|
+
const text = proposal.files[relative] ?? (projectSource === null || projectSource === void 0 ? void 0 : projectSource[relative]);
|
|
42
|
+
if (text === undefined) continue;
|
|
43
|
+
const entries = jsonEntryPaths(relative, text);
|
|
44
|
+
if (entries === null) continue;
|
|
45
|
+
const byKey = new Map();
|
|
46
|
+
for (const [key, importPath] of entries) {
|
|
47
|
+
const jsonPath = resolveExistingJsonPath(moduleFilePath, importPath).replace(/^\//, "");
|
|
48
|
+
if (!savedJsonPaths.has(jsonPath)) continue;
|
|
49
|
+
const content = parseJson(proposal.files[jsonPath]);
|
|
50
|
+
if (content !== undefined) byKey.set(key, content);
|
|
51
|
+
}
|
|
52
|
+
if (byKey.size > 0) found.set(moduleFilePath, byKey);
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The snapshot as a page reads it: {@link proposalSnapshot}, with each saved
|
|
59
|
+
* `.jsonValues()` entry's content in place of its marker -- the shape a draft
|
|
60
|
+
* already has, where the entries it edits hold content and the rest are
|
|
61
|
+
* markers the readers resolve from the build. See {@link proposalJsonEntries}.
|
|
62
|
+
*
|
|
63
|
+
* For the readers only. Val's own server keeps the markers
|
|
64
|
+
* ({@link proposalSnapshot}): its patching works on them, and it takes the
|
|
65
|
+
* saved entries separately.
|
|
66
|
+
*/
|
|
67
|
+
function proposalSnapshotForReaders(proposal, projectSource) {
|
|
68
|
+
const snapshot = proposalSnapshot(proposal);
|
|
69
|
+
for (const [moduleFilePath, entries] of proposalJsonEntries(proposal, projectSource)) {
|
|
70
|
+
const source = snapshot[moduleFilePath];
|
|
71
|
+
if (!isObject(source)) continue;
|
|
72
|
+
const filled = {};
|
|
73
|
+
for (const [key, value] of Object.entries(source)) {
|
|
74
|
+
if (isJsonValue(value)) filled[key] = value;
|
|
75
|
+
}
|
|
76
|
+
for (const [key, content] of entries) {
|
|
77
|
+
// Own keys only: an entry may be named `toString`.
|
|
78
|
+
if (Object.prototype.hasOwnProperty.call(filled, key)) {
|
|
79
|
+
filled[key] = content;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
snapshot[moduleFilePath] = filled;
|
|
83
|
+
}
|
|
84
|
+
return snapshot;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A record of `.jsonValues()` markers (`{ _type: "json" }`), at least one. */
|
|
88
|
+
function holdsJsonMarkers(source) {
|
|
89
|
+
return isObject(source) && Object.values(source).some(value => isObject(value) && value["_type"] === "json");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Each entry key's import path, from a `.jsonValues()` module's text. */
|
|
93
|
+
function jsonEntryPaths(fileName, text) {
|
|
94
|
+
try {
|
|
95
|
+
const analysis = analyzeValModule(ts.createSourceFile(fileName, text, ts.ScriptTarget.ES2015, true));
|
|
96
|
+
if (result.isErr(analysis)) return null;
|
|
97
|
+
const paths = new Map();
|
|
98
|
+
for (const [key, entry] of analyzeJsonValuesEntries(analysis.value.source)) {
|
|
99
|
+
paths.set(key, entry.importPath);
|
|
100
|
+
}
|
|
101
|
+
return paths;
|
|
102
|
+
} catch {
|
|
103
|
+
// Not a module this can read: its entries stay the build's.
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function parseJson(text) {
|
|
108
|
+
if (text === undefined) return undefined;
|
|
109
|
+
try {
|
|
110
|
+
const value = JSON.parse(text);
|
|
111
|
+
return isMutableJsonValue(value) ? value : undefined;
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** {@link isJsonValue}, for the mutable JSON a server patches. */
|
|
118
|
+
function isMutableJsonValue(value) {
|
|
119
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
return value.every(isMutableJsonValue);
|
|
124
|
+
}
|
|
125
|
+
return isObject(value) && Object.values(value).every(isMutableJsonValue);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { proposalJsonEntries, proposalSnapshotForReaders };
|
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
4
|
var fp = require('@valbuild/core/fp');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var merge = require('./merge-5a8fc685.cjs.prod.js');
|
|
6
|
+
var jsonValuesModule = require('./jsonValuesModule-6cf73937.cjs.prod.js');
|
|
7
7
|
var jsonValuesPatch = require('./jsonValuesPatch-92798812.cjs.prod.js');
|
|
8
|
-
var ValOpsMemory = require('./ValOpsMemory-
|
|
9
|
-
require('@valbuild/core');
|
|
10
|
-
require('path');
|
|
11
|
-
require('zod');
|
|
12
|
-
require('fs');
|
|
13
|
-
require('zod-validation-error');
|
|
8
|
+
var ValOpsMemory = require('./ValOpsMemory-6155aa9b.cjs.prod.js');
|
|
9
|
+
require('@valbuild/core/patch');
|
|
14
10
|
require('@valbuild/shared/internal');
|
|
15
|
-
require('
|
|
11
|
+
require('path');
|
|
12
|
+
require('@valbuild/core');
|
|
16
13
|
require('crypto');
|
|
17
|
-
require('
|
|
18
|
-
require('./createPrettierFormatter-b31bfbe5.cjs.prod.js');
|
|
19
|
-
require('@valbuild/core/patch');
|
|
14
|
+
require('fs');
|
|
20
15
|
require('node:vm');
|
|
21
16
|
require('node:module');
|
|
17
|
+
require('zod');
|
|
18
|
+
require('zod-validation-error');
|
|
22
19
|
require('./ValPatchStore-457b166f.cjs.prod.js');
|
|
23
20
|
require('image-size');
|
|
24
21
|
|
|
@@ -112,7 +109,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
112
109
|
const sourceFile = ts__default["default"].createSourceFile(moduleFilePath, valTsSource, ts__default["default"].ScriptTarget.ES2015, true);
|
|
113
110
|
let analysis;
|
|
114
111
|
try {
|
|
115
|
-
analysis =
|
|
112
|
+
analysis = jsonValuesModule.analyzeValModule(sourceFile);
|
|
116
113
|
} catch (err) {
|
|
117
114
|
// `file-unavailable` rather than a kind of its own: the module's TEXT is
|
|
118
115
|
// the file we could not use, and adding a wire kind for "unparseable"
|
|
@@ -130,7 +127,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
130
127
|
message: "could not read the module at this commit"
|
|
131
128
|
});
|
|
132
129
|
}
|
|
133
|
-
const entries =
|
|
130
|
+
const entries = jsonValuesModule.analyzeJsonValuesEntries(analysis.value.source);
|
|
134
131
|
const entry = entries.get(key);
|
|
135
132
|
if (entry === undefined) {
|
|
136
133
|
/*
|
|
@@ -167,8 +164,8 @@ moduleGitPath, valTsSource, key) {
|
|
|
167
164
|
* if TypeScript becomes reachable from `@valbuild/server/browser` again.
|
|
168
165
|
*/
|
|
169
166
|
|
|
170
|
-
const tsOps = new
|
|
171
|
-
return fp.pipe(
|
|
167
|
+
const tsOps = new merge.TSOps(document => {
|
|
168
|
+
return fp.pipe(jsonValuesModule.analyzeValModule(document), fp.result.map(({
|
|
172
169
|
source
|
|
173
170
|
}) => source));
|
|
174
171
|
});
|
|
@@ -178,12 +175,12 @@ function parseValFile(text) {
|
|
|
178
175
|
return ts__default["default"].createSourceFile("<val>", text, ts__default["default"].ScriptTarget.ES2015);
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
exports.insertValJsonEntry =
|
|
182
|
-
exports.removeValJsonEntry =
|
|
183
|
-
exports.analyzeJsonValuesEntries =
|
|
184
|
-
exports.analyzeValModule =
|
|
185
|
-
exports.evaluateModuleSource =
|
|
186
|
-
exports.jsonValuesRecordKeys =
|
|
178
|
+
exports.insertValJsonEntry = merge.insertValJsonEntry;
|
|
179
|
+
exports.removeValJsonEntry = merge.removeValJsonEntry;
|
|
180
|
+
exports.analyzeJsonValuesEntries = jsonValuesModule.analyzeJsonValuesEntries;
|
|
181
|
+
exports.analyzeValModule = jsonValuesModule.analyzeValModule;
|
|
182
|
+
exports.evaluateModuleSource = jsonValuesModule.evaluateModuleSource;
|
|
183
|
+
exports.jsonValuesRecordKeys = jsonValuesModule.jsonValuesRecordKeys;
|
|
187
184
|
exports.getJsonEntryAtCommit = getJsonEntryAtCommit;
|
|
188
185
|
exports.parseValFile = parseValFile;
|
|
189
186
|
exports.tsOps = tsOps;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { result, pipe } from '@valbuild/core/fp';
|
|
3
|
-
import { T as TSOps } from './
|
|
4
|
-
export {
|
|
5
|
-
import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './
|
|
6
|
-
export { c as analyzeJsonValuesEntries, a as analyzeValModule,
|
|
3
|
+
import { T as TSOps } from './merge-eca8ec38.esm.js';
|
|
4
|
+
export { i as insertValJsonEntry, r as removeValJsonEntry } from './merge-eca8ec38.esm.js';
|
|
5
|
+
import { a as analyzeValModule, c as analyzeJsonValuesEntries } from './jsonValuesModule-12fc4bb0.esm.js';
|
|
6
|
+
export { c as analyzeJsonValuesEntries, a as analyzeValModule, i as evaluateModuleSource, j as jsonValuesRecordKeys } from './jsonValuesModule-12fc4bb0.esm.js';
|
|
7
7
|
import { p as posixPath } from './jsonValuesPatch-13acc674.esm.js';
|
|
8
|
-
import { N as bytesToUtf8 } from './ValOpsMemory-
|
|
9
|
-
import '@valbuild/core';
|
|
10
|
-
import 'path';
|
|
11
|
-
import 'zod';
|
|
12
|
-
import 'fs';
|
|
13
|
-
import 'zod-validation-error';
|
|
8
|
+
import { N as bytesToUtf8 } from './ValOpsMemory-a00c3187.esm.js';
|
|
9
|
+
import '@valbuild/core/patch';
|
|
14
10
|
import '@valbuild/shared/internal';
|
|
15
|
-
import '
|
|
11
|
+
import 'path';
|
|
12
|
+
import '@valbuild/core';
|
|
16
13
|
import 'crypto';
|
|
17
|
-
import '
|
|
18
|
-
import './createPrettierFormatter-ce478de1.esm.js';
|
|
19
|
-
import '@valbuild/core/patch';
|
|
14
|
+
import 'fs';
|
|
20
15
|
import 'node:vm';
|
|
21
16
|
import 'node:module';
|
|
17
|
+
import 'zod';
|
|
18
|
+
import 'zod-validation-error';
|
|
22
19
|
import './ValPatchStore-9ccc09e7.esm.js';
|
|
23
20
|
import 'image-size';
|
|
24
21
|
|
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var ts = require('typescript');
|
|
4
4
|
var fp = require('@valbuild/core/fp');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var merge = require('./merge-a21a9c78.cjs.dev.js');
|
|
6
|
+
var jsonValuesModule = require('./jsonValuesModule-ed68a9de.cjs.dev.js');
|
|
7
7
|
var jsonValuesPatch = require('./jsonValuesPatch-88bc661d.cjs.dev.js');
|
|
8
|
-
var ValOpsMemory = require('./ValOpsMemory-
|
|
9
|
-
require('@valbuild/core');
|
|
10
|
-
require('path');
|
|
11
|
-
require('zod');
|
|
12
|
-
require('fs');
|
|
13
|
-
require('zod-validation-error');
|
|
8
|
+
var ValOpsMemory = require('./ValOpsMemory-c1453e6a.cjs.dev.js');
|
|
9
|
+
require('@valbuild/core/patch');
|
|
14
10
|
require('@valbuild/shared/internal');
|
|
15
|
-
require('
|
|
11
|
+
require('path');
|
|
12
|
+
require('@valbuild/core');
|
|
16
13
|
require('crypto');
|
|
17
|
-
require('
|
|
18
|
-
require('./createPrettierFormatter-5d830bdf.cjs.dev.js');
|
|
19
|
-
require('@valbuild/core/patch');
|
|
14
|
+
require('fs');
|
|
20
15
|
require('node:vm');
|
|
21
16
|
require('node:module');
|
|
17
|
+
require('zod');
|
|
18
|
+
require('zod-validation-error');
|
|
22
19
|
require('./ValPatchStore-b53db740.cjs.dev.js');
|
|
23
20
|
require('image-size');
|
|
24
21
|
|
|
@@ -112,7 +109,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
112
109
|
const sourceFile = ts__default["default"].createSourceFile(moduleFilePath, valTsSource, ts__default["default"].ScriptTarget.ES2015, true);
|
|
113
110
|
let analysis;
|
|
114
111
|
try {
|
|
115
|
-
analysis =
|
|
112
|
+
analysis = jsonValuesModule.analyzeValModule(sourceFile);
|
|
116
113
|
} catch (err) {
|
|
117
114
|
// `file-unavailable` rather than a kind of its own: the module's TEXT is
|
|
118
115
|
// the file we could not use, and adding a wire kind for "unparseable"
|
|
@@ -130,7 +127,7 @@ moduleGitPath, valTsSource, key) {
|
|
|
130
127
|
message: "could not read the module at this commit"
|
|
131
128
|
});
|
|
132
129
|
}
|
|
133
|
-
const entries =
|
|
130
|
+
const entries = jsonValuesModule.analyzeJsonValuesEntries(analysis.value.source);
|
|
134
131
|
const entry = entries.get(key);
|
|
135
132
|
if (entry === undefined) {
|
|
136
133
|
/*
|
|
@@ -167,8 +164,8 @@ moduleGitPath, valTsSource, key) {
|
|
|
167
164
|
* if TypeScript becomes reachable from `@valbuild/server/browser` again.
|
|
168
165
|
*/
|
|
169
166
|
|
|
170
|
-
const tsOps = new
|
|
171
|
-
return fp.pipe(
|
|
167
|
+
const tsOps = new merge.TSOps(document => {
|
|
168
|
+
return fp.pipe(jsonValuesModule.analyzeValModule(document), fp.result.map(({
|
|
172
169
|
source
|
|
173
170
|
}) => source));
|
|
174
171
|
});
|
|
@@ -178,12 +175,12 @@ function parseValFile(text) {
|
|
|
178
175
|
return ts__default["default"].createSourceFile("<val>", text, ts__default["default"].ScriptTarget.ES2015);
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
exports.insertValJsonEntry =
|
|
182
|
-
exports.removeValJsonEntry =
|
|
183
|
-
exports.analyzeJsonValuesEntries =
|
|
184
|
-
exports.analyzeValModule =
|
|
185
|
-
exports.evaluateModuleSource =
|
|
186
|
-
exports.jsonValuesRecordKeys =
|
|
178
|
+
exports.insertValJsonEntry = merge.insertValJsonEntry;
|
|
179
|
+
exports.removeValJsonEntry = merge.removeValJsonEntry;
|
|
180
|
+
exports.analyzeJsonValuesEntries = jsonValuesModule.analyzeJsonValuesEntries;
|
|
181
|
+
exports.analyzeValModule = jsonValuesModule.analyzeValModule;
|
|
182
|
+
exports.evaluateModuleSource = jsonValuesModule.evaluateModuleSource;
|
|
183
|
+
exports.jsonValuesRecordKeys = jsonValuesModule.jsonValuesRecordKeys;
|
|
187
184
|
exports.getJsonEntryAtCommit = getJsonEntryAtCommit;
|
|
188
185
|
exports.parseValFile = parseValFile;
|
|
189
186
|
exports.tsOps = tsOps;
|