@beff/aula-cli 0.0.1 → 0.1.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/README.md +11 -1
- package/dist/licenses/aula-g2p-NOTICE.txt +13 -0
- package/dist/licenses/espeak-ng-COPYING.txt +674 -0
- package/dist/licenses/fonts-OFL-JetBrainsMono.txt +93 -0
- package/dist/licenses/fonts-OFL-NunitoSans.txt +93 -0
- package/dist/src/aula-render.core.wasm +0 -0
- package/dist/src/aula-voice-tts-ZXQ7XXHJ.js +14 -0
- package/dist/src/chunk-2XGNOG2U.js +28 -0
- package/dist/src/chunk-46KT47TH.js +21 -0
- package/dist/src/chunk-7KT36JRP.js +1282 -0
- package/dist/src/chunk-GFCJYE75.js +42 -0
- package/dist/src/chunk-IAQZ6DTC.js +271 -0
- package/dist/src/chunk-QWNBVWUQ.js +1105 -0
- package/dist/src/chunk-XUBCUJW5.js +104 -0
- package/dist/src/chunk-YX73KJQ6.js +577 -0
- package/dist/src/cli.js +334 -0
- package/dist/src/commands-M246OWYJ.js +27 -0
- package/dist/src/problems-Y67BY7WB.js +12 -0
- package/dist/src/project-NWT5MDQI.js +11 -0
- package/dist/src/render-child.js +3771 -0
- package/dist/src/run-CTVGU7EK.js +127 -0
- package/dist/src/server-5OGXX6BF.js +220 -0
- package/dist/web/app/assets/__vite-browser-external-BN30sEqc.js +1 -0
- package/dist/web/app/assets/__vite-browser-external-BtQTJ51O.js +1 -0
- package/dist/web/app/assets/aula-method.js +1 -0
- package/dist/web/app/assets/aula-voice-worker-DymX5vwM.js +52 -0
- package/dist/web/app/assets/aula.core-BtiPQSZi.wasm +0 -0
- package/dist/web/app/assets/aula.core5-YhDIb7Me.wasm +0 -0
- package/dist/web/app/assets/aula.js +1 -0
- package/dist/web/app/assets/build-worker.js +696 -0
- package/dist/web/app/assets/esbuild-BaXVPFT2.wasm +0 -0
- package/dist/web/app/assets/index-B8_aMtuI.js +53 -0
- package/dist/web/app/assets/index-cL-Dm_aw.css +2 -0
- package/dist/web/app/assets/protocol-CnlzsyRt.js +15 -0
- package/dist/web/app/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
- package/dist/web/app/assets/src-CmWmmzpF.js +25 -0
- package/dist/web/app/index.html +15 -0
- package/package.json +27 -5
|
@@ -0,0 +1,1282 @@
|
|
|
1
|
+
// ../aula-project/src/diagnostics.ts
|
|
2
|
+
import { diagnosticOf } from "@beff/aula/run";
|
|
3
|
+
function error(message, more = {}) {
|
|
4
|
+
return { severity: "error", message, ...more, stack: [], related: [] };
|
|
5
|
+
}
|
|
6
|
+
var isError = (d) => d.severity === "error";
|
|
7
|
+
var Problems = class extends Error {
|
|
8
|
+
diagnostics;
|
|
9
|
+
constructor(diagnostics) {
|
|
10
|
+
super(diagnostics.map((d) => d.message).join("\n"));
|
|
11
|
+
this.diagnostics = diagnostics;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function wrongArgument(message, hint) {
|
|
15
|
+
return new Problems([error(message, hint === void 0 ? {} : { hint })]);
|
|
16
|
+
}
|
|
17
|
+
function diagnosticsOf(e, host2) {
|
|
18
|
+
return e instanceof Problems ? e.diagnostics : [diagnosticOf(e, "", host2)];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ../aula-project/src/node.ts
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { pathToFileURL } from "node:url";
|
|
24
|
+
import { isProjectDefinition } from "@beff/aula";
|
|
25
|
+
import { definedAt, loadEngine, v8Frames } from "@beff/aula/run";
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/@beff+client@1.0.1/node_modules/@beff/client/dist/esm/openapi-pp.js
|
|
28
|
+
var removeNullUnionBranch = (definition) => {
|
|
29
|
+
if (typeof definition === "boolean") {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const variantsKey = definition.anyOf != null ? "anyOf" : definition.oneOf != null ? "oneOf" : null;
|
|
33
|
+
if (variantsKey == null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const variants = definition[variantsKey];
|
|
37
|
+
if (variants == null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const nonNull = variants.filter((variant) => !isNullDefinition(variant));
|
|
41
|
+
if (nonNull.length === variants.length || nonNull.length === 0) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const normalizedNonNull = nonNull.map((variant) => removeNullUnionBranch(variant) ?? variant);
|
|
45
|
+
if (normalizedNonNull.length === 1) {
|
|
46
|
+
return normalizedNonNull[0];
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...definition,
|
|
50
|
+
[variantsKey]: normalizedNonNull
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var isNullDefinition = (definition) => {
|
|
54
|
+
return typeof definition !== "boolean" && definition.type === "null";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/@beff+client@1.0.1/node_modules/@beff/client/dist/esm/err.js
|
|
58
|
+
var prettyPrintValue = (it) => {
|
|
59
|
+
if (typeof it === "string") {
|
|
60
|
+
return `"${it}"`;
|
|
61
|
+
}
|
|
62
|
+
if (typeof it === "number") {
|
|
63
|
+
return `${it}`;
|
|
64
|
+
}
|
|
65
|
+
if (typeof it === "boolean") {
|
|
66
|
+
return `${it}`;
|
|
67
|
+
}
|
|
68
|
+
if (typeof it === "bigint") {
|
|
69
|
+
return `${it}n`;
|
|
70
|
+
}
|
|
71
|
+
if (it === null) {
|
|
72
|
+
return "null";
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(it)) {
|
|
75
|
+
return `Array`;
|
|
76
|
+
}
|
|
77
|
+
if (typeof it === "object") {
|
|
78
|
+
return `Object`;
|
|
79
|
+
}
|
|
80
|
+
return JSON.stringify(it);
|
|
81
|
+
};
|
|
82
|
+
var joinWithDot = (it) => {
|
|
83
|
+
if (it.length === 0) {
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
let acc = it[0];
|
|
87
|
+
for (const item of it.slice(1)) {
|
|
88
|
+
if (item.startsWith("[")) {
|
|
89
|
+
acc += item;
|
|
90
|
+
} else {
|
|
91
|
+
acc += "." + item;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return acc;
|
|
95
|
+
};
|
|
96
|
+
var printPath = (parentPath, path2) => {
|
|
97
|
+
const mergedPath = [...parentPath, ...path2];
|
|
98
|
+
return mergedPath.length > 0 ? `(${joinWithDot(mergedPath)})` : "";
|
|
99
|
+
};
|
|
100
|
+
var joinFilteredStrings = (it) => {
|
|
101
|
+
return it.filter((it2) => it2.length > 0).join(" ");
|
|
102
|
+
};
|
|
103
|
+
var printRegularError = (err, parentPath, showReceived) => {
|
|
104
|
+
const path2 = printPath(parentPath, err.path);
|
|
105
|
+
const msg = [err.message, showReceived ? `received: ${prettyPrintValue(err.received)}` : ""].filter((it) => it.length > 0).join(", ");
|
|
106
|
+
return joinFilteredStrings([path2, msg]);
|
|
107
|
+
};
|
|
108
|
+
var printUnionError = (err, parentPath) => {
|
|
109
|
+
const path2 = printPath(parentPath, err.path);
|
|
110
|
+
const printedErrors = printErrorsPart(err.errors, [], false);
|
|
111
|
+
const innerMessages = printedErrors.length > 5 ? printedErrors.slice(0, 5).join(" OR ") + " and more..." : printedErrors.join(" | ");
|
|
112
|
+
const msg = [`Failed to decode one of (${innerMessages})`, `received: ${prettyPrintValue(err.received)}`].filter((it) => it.length > 0).join(", ");
|
|
113
|
+
return joinFilteredStrings([path2, msg]);
|
|
114
|
+
};
|
|
115
|
+
var printErrorsPart = (it, parentPath, showReceived) => {
|
|
116
|
+
return it.map((err) => {
|
|
117
|
+
if ("isUnionError" in err) {
|
|
118
|
+
return printUnionError(err, parentPath);
|
|
119
|
+
}
|
|
120
|
+
return printRegularError(err, parentPath, showReceived);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var printErrors = (it, parentPath = []) => {
|
|
124
|
+
return printErrorsPart(it, parentPath, true).map((msg, idx, all) => all.length == 1 ? joinFilteredStrings([msg]) : joinFilteredStrings([`#${idx}`, msg])).join(" | ");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ../../node_modules/.pnpm/@beff+client@1.0.1/node_modules/@beff/client/dist/esm/runtime.js
|
|
128
|
+
var JSON_PROTO = Object.getPrototypeOf({});
|
|
129
|
+
function deepmergeConstructor(options) {
|
|
130
|
+
function setKey(result, key, value) {
|
|
131
|
+
if (key === "__proto__") {
|
|
132
|
+
Object.defineProperty(result, key, { value, enumerable: true, writable: true, configurable: true });
|
|
133
|
+
} else {
|
|
134
|
+
result[key] = value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function cloneArray(value) {
|
|
138
|
+
let i = 0;
|
|
139
|
+
const il = value.length;
|
|
140
|
+
const result = new Array(il);
|
|
141
|
+
for (i; i < il; ++i) {
|
|
142
|
+
result[i] = clone(value[i]);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function cloneObject(target) {
|
|
147
|
+
const result = {};
|
|
148
|
+
if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) {
|
|
149
|
+
return cloneProtoObject(target);
|
|
150
|
+
}
|
|
151
|
+
const targetKeys = getKeys(target);
|
|
152
|
+
let i, il, key;
|
|
153
|
+
for (i = 0, il = targetKeys.length; i < il; ++i) {
|
|
154
|
+
key = targetKeys[i];
|
|
155
|
+
setKey(result, key, clone(target[key]));
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
function concatArrays(target, source) {
|
|
160
|
+
const tl = target.length;
|
|
161
|
+
const sl = source.length;
|
|
162
|
+
let i = 0;
|
|
163
|
+
const result = new Array(tl + sl);
|
|
164
|
+
for (i; i < tl; ++i) {
|
|
165
|
+
result[i] = clone(target[i]);
|
|
166
|
+
}
|
|
167
|
+
for (i = 0; i < sl; ++i) {
|
|
168
|
+
result[i + tl] = clone(source[i]);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
173
|
+
function getSymbolsAndKeys(value) {
|
|
174
|
+
const result = Object.keys(value);
|
|
175
|
+
const keys = Object.getOwnPropertySymbols(value);
|
|
176
|
+
for (let i = 0, il = keys.length; i < il; ++i) {
|
|
177
|
+
propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;
|
|
182
|
+
const cloneProtoObject = typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : void 0;
|
|
183
|
+
function isMergeableObject(value) {
|
|
184
|
+
return typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value);
|
|
185
|
+
}
|
|
186
|
+
function isPrimitive(value) {
|
|
187
|
+
return typeof value !== "object" || value === null;
|
|
188
|
+
}
|
|
189
|
+
const isPrimitiveOrBuiltIn = (
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
typeof Buffer !== "undefined" ? (value) => typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date || ArrayBuffer.isView(value) || // @ts-ignore
|
|
192
|
+
value instanceof Buffer : (value) => typeof value !== "object" || value === null || value instanceof RegExp || value instanceof Date || ArrayBuffer.isView(value)
|
|
193
|
+
);
|
|
194
|
+
const mergeArray = options && typeof options.mergeArray === "function" ? options.mergeArray({ clone, deepmerge: _deepmerge, getKeys, isMergeableObject }) : concatArrays;
|
|
195
|
+
function clone(entry) {
|
|
196
|
+
return isMergeableObject(entry) ? Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry) : entry;
|
|
197
|
+
}
|
|
198
|
+
function mergeObject(target, source) {
|
|
199
|
+
const result = {};
|
|
200
|
+
const targetKeys = getKeys(target);
|
|
201
|
+
const sourceKeys = getKeys(source);
|
|
202
|
+
let i, il, key;
|
|
203
|
+
for (i = 0, il = targetKeys.length; i < il; ++i) {
|
|
204
|
+
key = targetKeys[i];
|
|
205
|
+
sourceKeys.indexOf(key) === -1 && setKey(result, key, clone(target[key]));
|
|
206
|
+
}
|
|
207
|
+
for (i = 0, il = sourceKeys.length; i < il; ++i) {
|
|
208
|
+
key = sourceKeys[i];
|
|
209
|
+
if (targetKeys.indexOf(key) !== -1) {
|
|
210
|
+
if (cloneProtoObject && isMergeableObject(source[key]) && Object.getPrototypeOf(source[key]) !== JSON_PROTO) {
|
|
211
|
+
setKey(result, key, cloneProtoObject(source[key]));
|
|
212
|
+
} else {
|
|
213
|
+
setKey(result, key, _deepmerge(target[key], source[key]));
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
setKey(result, key, clone(source[key]));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
function _deepmerge(target, source) {
|
|
222
|
+
const sourceIsArray = Array.isArray(source);
|
|
223
|
+
const targetIsArray = Array.isArray(target);
|
|
224
|
+
if (isPrimitive(source) || source instanceof Map || source instanceof Set) {
|
|
225
|
+
return source;
|
|
226
|
+
} else if (isPrimitiveOrBuiltIn(target)) {
|
|
227
|
+
return clone(source);
|
|
228
|
+
} else if (sourceIsArray && targetIsArray) {
|
|
229
|
+
return mergeArray(target, source);
|
|
230
|
+
} else if (sourceIsArray !== targetIsArray) {
|
|
231
|
+
return clone(source);
|
|
232
|
+
} else {
|
|
233
|
+
return mergeObject(target, source);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function _deepmergeAll() {
|
|
237
|
+
switch (arguments.length) {
|
|
238
|
+
case 0:
|
|
239
|
+
return {};
|
|
240
|
+
case 1:
|
|
241
|
+
return clone(arguments[0]);
|
|
242
|
+
case 2:
|
|
243
|
+
return _deepmerge(arguments[0], arguments[1]);
|
|
244
|
+
}
|
|
245
|
+
let result;
|
|
246
|
+
for (let i = 0, il = arguments.length; i < il; ++i) {
|
|
247
|
+
result = _deepmerge(result, arguments[i]);
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
return _deepmergeAll;
|
|
252
|
+
}
|
|
253
|
+
function deepmergeArray(options) {
|
|
254
|
+
const deepmerge2 = options.deepmerge;
|
|
255
|
+
const clone = options.clone;
|
|
256
|
+
return function(target, source) {
|
|
257
|
+
let i = 0;
|
|
258
|
+
const sl = source.length;
|
|
259
|
+
const il = Math.max(target.length, source.length);
|
|
260
|
+
const result = new Array(il);
|
|
261
|
+
for (i = 0; i < il; ++i) {
|
|
262
|
+
if (i < sl) {
|
|
263
|
+
result[i] = deepmerge2(target[i], source[i]);
|
|
264
|
+
} else {
|
|
265
|
+
result[i] = clone(target[i]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
var deepmerge = deepmergeConstructor({ mergeArray: deepmergeArray });
|
|
272
|
+
function buildError(ctx, message, received) {
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
message,
|
|
276
|
+
path: [...ctx.path],
|
|
277
|
+
received
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
function editDistance(a, b) {
|
|
282
|
+
const d = [];
|
|
283
|
+
for (let i = 0; i <= a.length; i++) {
|
|
284
|
+
d.push([i]);
|
|
285
|
+
for (let j = 1; j <= b.length; j++) {
|
|
286
|
+
d[i][j] = i === 0 ? j : Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
287
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
288
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return d[a.length][b.length];
|
|
293
|
+
}
|
|
294
|
+
function extraPropertyError(ctx, key, allowed, received) {
|
|
295
|
+
if (allowed == null) {
|
|
296
|
+
pushPath(ctx, key);
|
|
297
|
+
const err2 = buildError(ctx, "extra property", received);
|
|
298
|
+
popPath(ctx);
|
|
299
|
+
return err2;
|
|
300
|
+
}
|
|
301
|
+
let nearest = null;
|
|
302
|
+
let best = Math.max(1, Math.floor(key.length / 3));
|
|
303
|
+
for (const k of allowed) {
|
|
304
|
+
const distance = editDistance(key, k);
|
|
305
|
+
if (distance <= best && distance < key.length && (nearest == null || distance < best)) {
|
|
306
|
+
nearest = k;
|
|
307
|
+
best = distance;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const suggestion = nearest == null ? "" : ` Did you mean ${JSON.stringify(nearest)}?`;
|
|
311
|
+
const list = allowed.length === 0 ? "none" : allowed.map((k) => JSON.stringify(k)).join(", ");
|
|
312
|
+
pushPath(ctx, key);
|
|
313
|
+
const err = buildError(ctx, `extra property.${suggestion} Allowed: ${list}`, received);
|
|
314
|
+
popPath(ctx);
|
|
315
|
+
return err;
|
|
316
|
+
}
|
|
317
|
+
function reportAtPath(ctx, acc, key, runtype, input) {
|
|
318
|
+
if (!runtype.validate(ctx, input)) {
|
|
319
|
+
pushPath(ctx, key);
|
|
320
|
+
acc.push(...runtype.reportDecodeError(ctx, input));
|
|
321
|
+
popPath(ctx);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function pushPath(ctx, key) {
|
|
325
|
+
ctx.path.push(key);
|
|
326
|
+
}
|
|
327
|
+
function popPath(ctx) {
|
|
328
|
+
ctx.path.pop();
|
|
329
|
+
}
|
|
330
|
+
function registerStringFormatter(stringFormatters2, name, value) {
|
|
331
|
+
if (typeof value === "function") {
|
|
332
|
+
stringFormatters2[name] = {
|
|
333
|
+
validator: value
|
|
334
|
+
};
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
stringFormatters2[name] = value;
|
|
338
|
+
}
|
|
339
|
+
function registerNumberFormatter(numberFormatters2, name, value) {
|
|
340
|
+
if (typeof value === "function") {
|
|
341
|
+
numberFormatters2[name] = {
|
|
342
|
+
validator: value
|
|
343
|
+
};
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
numberFormatters2[name] = value;
|
|
347
|
+
}
|
|
348
|
+
function annotateSchema(metadata, schema) {
|
|
349
|
+
if (metadata?.description == null) {
|
|
350
|
+
return schema;
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
...schema,
|
|
354
|
+
description: metadata.description
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function jsdocDescription(description) {
|
|
358
|
+
const sanitized = description.replace(/\*\//g, "* /");
|
|
359
|
+
const lines = sanitized.split("\n");
|
|
360
|
+
if (lines.length === 1) {
|
|
361
|
+
return `/** ${lines[0]} */`;
|
|
362
|
+
}
|
|
363
|
+
return ["/**", ...lines.map((line) => ` * ${line}`), " */"].join("\n");
|
|
364
|
+
}
|
|
365
|
+
function typeDescription(typeExpr, docText) {
|
|
366
|
+
if (docText == null) {
|
|
367
|
+
return { typeExpr };
|
|
368
|
+
}
|
|
369
|
+
return { typeExpr, docText };
|
|
370
|
+
}
|
|
371
|
+
var BaseRuntype = class {
|
|
372
|
+
metadata;
|
|
373
|
+
constructor(metadata) {
|
|
374
|
+
this.metadata = metadata;
|
|
375
|
+
}
|
|
376
|
+
describe(ctx) {
|
|
377
|
+
return typeDescription(this.describeTypeExpr(ctx), this.metadata?.description);
|
|
378
|
+
}
|
|
379
|
+
describeChildren() {
|
|
380
|
+
return [];
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
function describeTypeExpr(ctx, runtype) {
|
|
384
|
+
return runtype.describe(ctx).typeExpr;
|
|
385
|
+
}
|
|
386
|
+
function renderTypeDescription(description) {
|
|
387
|
+
return description.docText == null ? description.typeExpr : `${jsdocDescription(description.docText)}
|
|
388
|
+
${description.typeExpr}`;
|
|
389
|
+
}
|
|
390
|
+
function renderTypeAlias(name, description) {
|
|
391
|
+
const declaration = `type ${name} = ${description.typeExpr};`;
|
|
392
|
+
return description.docText == null ? declaration : `${jsdocDescription(description.docText)}
|
|
393
|
+
${declaration}`;
|
|
394
|
+
}
|
|
395
|
+
function describePropertyKey(key) {
|
|
396
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) || /^(0|[1-9][0-9]*)$/.test(key)) {
|
|
397
|
+
return key;
|
|
398
|
+
}
|
|
399
|
+
return JSON.stringify(key);
|
|
400
|
+
}
|
|
401
|
+
function describeObjectMember(ctx, key, value) {
|
|
402
|
+
const optionalMark = value instanceof OptionalFieldRuntype ? "?" : "";
|
|
403
|
+
const description = value.describe(ctx);
|
|
404
|
+
return {
|
|
405
|
+
docText: description.docText,
|
|
406
|
+
member: `${key}${optionalMark}: ${description.typeExpr}`
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function describeIndexObjectMember(ctx, key, value) {
|
|
410
|
+
return describeObjectMember(ctx, `[K in ${describeTypeExpr(ctx, key)}]`, value);
|
|
411
|
+
}
|
|
412
|
+
function renderObjectMember(member) {
|
|
413
|
+
const renderedMember = `${member.member};`;
|
|
414
|
+
return member.docText == null ? renderedMember : `${jsdocDescription(member.docText)}
|
|
415
|
+
${renderedMember}`;
|
|
416
|
+
}
|
|
417
|
+
function collectDescribeRefs(runtype, ctx) {
|
|
418
|
+
if (runtype instanceof RefRuntype) {
|
|
419
|
+
runtype.collectDescribeRefs(ctx);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
for (const child of runtype.describeChildren()) {
|
|
423
|
+
collectDescribeRefs(child, ctx);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
var TypeofRuntype = class extends BaseRuntype {
|
|
427
|
+
typeName;
|
|
428
|
+
constructor(metadata, typeName) {
|
|
429
|
+
super(metadata);
|
|
430
|
+
this.typeName = typeName;
|
|
431
|
+
}
|
|
432
|
+
describeTypeExpr(_ctx) {
|
|
433
|
+
return this.typeName;
|
|
434
|
+
}
|
|
435
|
+
schema(_ctx) {
|
|
436
|
+
return annotateSchema(this.metadata, { type: this.typeName });
|
|
437
|
+
}
|
|
438
|
+
validate(_ctx, input) {
|
|
439
|
+
return typeof input === this.typeName;
|
|
440
|
+
}
|
|
441
|
+
parseAfterValidation(_ctx, input) {
|
|
442
|
+
return input;
|
|
443
|
+
}
|
|
444
|
+
reportDecodeError(ctx, input) {
|
|
445
|
+
return buildError(ctx, "expected " + this.typeName, input);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
var NUMBER_KEY_PATTERN = "^-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?$";
|
|
449
|
+
var NUMBER_KEY_REGEX = new RegExp(NUMBER_KEY_PATTERN);
|
|
450
|
+
var AnyRuntype = class extends BaseRuntype {
|
|
451
|
+
constructor(metadata) {
|
|
452
|
+
super(metadata);
|
|
453
|
+
}
|
|
454
|
+
describeTypeExpr(_ctx) {
|
|
455
|
+
return "any";
|
|
456
|
+
}
|
|
457
|
+
schema(_ctx) {
|
|
458
|
+
return annotateSchema(this.metadata, {});
|
|
459
|
+
}
|
|
460
|
+
validate(_ctx, _input) {
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
parseAfterValidation(_ctx, input) {
|
|
464
|
+
return input;
|
|
465
|
+
}
|
|
466
|
+
reportDecodeError(ctx, input) {
|
|
467
|
+
return buildError(ctx, "expected any", input);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var NeverRuntype = class extends BaseRuntype {
|
|
471
|
+
constructor(metadata) {
|
|
472
|
+
super(metadata);
|
|
473
|
+
}
|
|
474
|
+
describeTypeExpr(_ctx) {
|
|
475
|
+
return "never";
|
|
476
|
+
}
|
|
477
|
+
schema(_ctx) {
|
|
478
|
+
return annotateSchema(this.metadata, { anyOf: [] });
|
|
479
|
+
}
|
|
480
|
+
validate(_ctx, _input) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
parseAfterValidation(_ctx, _input) {
|
|
484
|
+
throw new Error("unreachable");
|
|
485
|
+
}
|
|
486
|
+
reportDecodeError(ctx, input) {
|
|
487
|
+
return buildError(ctx, "expected never", input);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
var ArrayRuntype = class extends BaseRuntype {
|
|
491
|
+
itemParser;
|
|
492
|
+
constructor(metadata, itemParser) {
|
|
493
|
+
super(metadata);
|
|
494
|
+
this.itemParser = itemParser;
|
|
495
|
+
}
|
|
496
|
+
schema(ctx) {
|
|
497
|
+
pushPath(ctx, "[]");
|
|
498
|
+
const items = this.itemParser.schema(ctx);
|
|
499
|
+
popPath(ctx);
|
|
500
|
+
return annotateSchema(this.metadata, {
|
|
501
|
+
type: "array",
|
|
502
|
+
items
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
validate(ctx, input) {
|
|
506
|
+
if (Array.isArray(input)) {
|
|
507
|
+
for (let i = 0; i < input.length; i++) {
|
|
508
|
+
const v = input[i];
|
|
509
|
+
const ok = this.itemParser.validate(ctx, v);
|
|
510
|
+
if (!ok) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
parseAfterValidation(ctx, input) {
|
|
519
|
+
return input.map((v) => this.itemParser.parseAfterValidation(ctx, v));
|
|
520
|
+
}
|
|
521
|
+
reportDecodeError(ctx, input) {
|
|
522
|
+
if (!Array.isArray(input)) {
|
|
523
|
+
return buildError(ctx, "expected array", input);
|
|
524
|
+
}
|
|
525
|
+
let acc = [];
|
|
526
|
+
for (let i = 0; i < input.length; i++) {
|
|
527
|
+
reportAtPath(ctx, acc, `[${i}]`, this.itemParser, input[i]);
|
|
528
|
+
}
|
|
529
|
+
return acc;
|
|
530
|
+
}
|
|
531
|
+
describeTypeExpr(ctx) {
|
|
532
|
+
return `Array<${describeTypeExpr(ctx, this.itemParser)}>`;
|
|
533
|
+
}
|
|
534
|
+
describeChildren() {
|
|
535
|
+
return [this.itemParser];
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
var OptionalFieldRuntype = class {
|
|
539
|
+
t;
|
|
540
|
+
constructor(t) {
|
|
541
|
+
this.t = t;
|
|
542
|
+
}
|
|
543
|
+
schema(ctx) {
|
|
544
|
+
const inner = this.t.schema(ctx);
|
|
545
|
+
return {
|
|
546
|
+
anyOf: [inner, { type: "null" }]
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
validate(ctx, input) {
|
|
550
|
+
if (input == null) {
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
return this.t.validate(ctx, input);
|
|
554
|
+
}
|
|
555
|
+
parseAfterValidation(ctx, input) {
|
|
556
|
+
if (input == null) {
|
|
557
|
+
return input;
|
|
558
|
+
}
|
|
559
|
+
return this.t.parseAfterValidation(ctx, input);
|
|
560
|
+
}
|
|
561
|
+
// validate() returns true for null/undefined, so reportDecodeError is only
|
|
562
|
+
// called when input is non-null. Reporting "expected nullish value" here
|
|
563
|
+
// would be noise — only the inner type's errors are relevant.
|
|
564
|
+
reportDecodeError(ctx, input) {
|
|
565
|
+
return this.t.reportDecodeError(ctx, input);
|
|
566
|
+
}
|
|
567
|
+
describe(ctx) {
|
|
568
|
+
return this.t.describe(ctx);
|
|
569
|
+
}
|
|
570
|
+
describeChildren() {
|
|
571
|
+
return [this.t];
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
575
|
+
function setOwnProperty(target, key, value) {
|
|
576
|
+
if (key === "__proto__") {
|
|
577
|
+
Object.defineProperty(target, key, { value, enumerable: true, writable: true, configurable: true });
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
target[key] = value;
|
|
581
|
+
}
|
|
582
|
+
var ObjectRuntype = class extends BaseRuntype {
|
|
583
|
+
properties;
|
|
584
|
+
indexedPropertiesParser;
|
|
585
|
+
constructor(metadata, properties, indexedPropertiesParser) {
|
|
586
|
+
super(metadata);
|
|
587
|
+
this.properties = properties;
|
|
588
|
+
this.indexedPropertiesParser = indexedPropertiesParser;
|
|
589
|
+
}
|
|
590
|
+
describeTypeExpr(ctx) {
|
|
591
|
+
const sortedKeys = Object.keys(this.properties).sort();
|
|
592
|
+
const props = sortedKeys.map((k) => {
|
|
593
|
+
const it = this.properties[k];
|
|
594
|
+
return describeObjectMember(ctx, describePropertyKey(k), it);
|
|
595
|
+
});
|
|
596
|
+
const indexProps = this.indexedPropertiesParser.map(({ key, value }) => describeIndexObjectMember(ctx, key, value));
|
|
597
|
+
const members = [...props, ...indexProps];
|
|
598
|
+
const hasMemberDescriptions = members.some((it) => it.docText != null);
|
|
599
|
+
if (hasMemberDescriptions) {
|
|
600
|
+
if (members.length === 0) {
|
|
601
|
+
return "{}";
|
|
602
|
+
}
|
|
603
|
+
const content2 = members.map(renderObjectMember).join("\n");
|
|
604
|
+
return `{
|
|
605
|
+
${content2}
|
|
606
|
+
}`;
|
|
607
|
+
}
|
|
608
|
+
const content = members.map((it) => it.member).join(", ");
|
|
609
|
+
return `{ ${content} }`;
|
|
610
|
+
}
|
|
611
|
+
describeChildren() {
|
|
612
|
+
return [
|
|
613
|
+
...Object.values(this.properties),
|
|
614
|
+
...this.indexedPropertiesParser.flatMap(({ key, value }) => [key, value])
|
|
615
|
+
];
|
|
616
|
+
}
|
|
617
|
+
schema(ctx) {
|
|
618
|
+
const properties = {};
|
|
619
|
+
const optionalized = /* @__PURE__ */ new Set();
|
|
620
|
+
for (const k in this.properties) {
|
|
621
|
+
pushPath(ctx, k);
|
|
622
|
+
const item = this.properties[k];
|
|
623
|
+
const raw = item.schema(ctx);
|
|
624
|
+
const rewrite = removeNullUnionBranch(raw);
|
|
625
|
+
if (rewrite != null) {
|
|
626
|
+
properties[k] = rewrite;
|
|
627
|
+
optionalized.add(k);
|
|
628
|
+
} else {
|
|
629
|
+
properties[k] = raw;
|
|
630
|
+
}
|
|
631
|
+
popPath(ctx);
|
|
632
|
+
}
|
|
633
|
+
const required = Object.keys(this.properties).filter((k) => !optionalized.has(k));
|
|
634
|
+
const base = {
|
|
635
|
+
type: "object",
|
|
636
|
+
properties,
|
|
637
|
+
...required.length > 0 ? { required } : {}
|
|
638
|
+
};
|
|
639
|
+
const indexSchemas = this.indexedPropertiesParser.map(({ key, value }) => {
|
|
640
|
+
pushPath(ctx, "[key]");
|
|
641
|
+
const keySchema = key.schema(ctx);
|
|
642
|
+
popPath(ctx);
|
|
643
|
+
pushPath(ctx, "[value]");
|
|
644
|
+
const valueSchema = value.schema(ctx);
|
|
645
|
+
popPath(ctx);
|
|
646
|
+
return {
|
|
647
|
+
type: "object",
|
|
648
|
+
additionalProperties: valueSchema,
|
|
649
|
+
propertyNames: keySchema
|
|
650
|
+
};
|
|
651
|
+
});
|
|
652
|
+
if (indexSchemas.length === 0) {
|
|
653
|
+
return annotateSchema(this.metadata, { ...base, additionalProperties: false });
|
|
654
|
+
}
|
|
655
|
+
if (Object.keys(properties).length === 0 && indexSchemas.length === 1) {
|
|
656
|
+
const valueRuntype = this.indexedPropertiesParser[0].value;
|
|
657
|
+
if (valueRuntype instanceof NeverRuntype) {
|
|
658
|
+
return annotateSchema(this.metadata, { type: "object", additionalProperties: false });
|
|
659
|
+
}
|
|
660
|
+
if (valueRuntype instanceof AnyRuntype) {
|
|
661
|
+
return annotateSchema(this.metadata, { ...indexSchemas[0], additionalProperties: true });
|
|
662
|
+
}
|
|
663
|
+
return annotateSchema(this.metadata, indexSchemas[0]);
|
|
664
|
+
}
|
|
665
|
+
return annotateSchema(this.metadata, {
|
|
666
|
+
allOf: [base, ...indexSchemas]
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
validate(ctx, input) {
|
|
670
|
+
if (typeof input === "object" && !Array.isArray(input) && input !== null) {
|
|
671
|
+
const configKeys = Object.keys(this.properties);
|
|
672
|
+
for (const k of configKeys) {
|
|
673
|
+
const validator = this.properties[k];
|
|
674
|
+
if (!validator.validate(ctx, input[k])) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (this.indexedPropertiesParser.length > 0) {
|
|
679
|
+
const inputKeys = Object.keys(input);
|
|
680
|
+
const extraKeys = inputKeys.filter((k) => !hasOwn.call(this.properties, k));
|
|
681
|
+
for (const k of extraKeys) {
|
|
682
|
+
let isValid = false;
|
|
683
|
+
for (const p of this.indexedPropertiesParser) {
|
|
684
|
+
if (!p.key.validate(ctx, k)) {
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const v = input[k];
|
|
688
|
+
if (!p.value.validate(ctx, v)) {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
isValid = true;
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
if (!isValid && !this.leavesKeyToIntersection(ctx, input, k)) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
if (ctx.disallowExtraProperties && ctx.intersectionInput !== input) {
|
|
700
|
+
const inputKeys = Object.keys(input);
|
|
701
|
+
const extraKeys = inputKeys.filter((k) => !hasOwn.call(this.properties, k));
|
|
702
|
+
if (extraKeys.length > 0) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return true;
|
|
708
|
+
}
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
parseAfterValidation(ctx, input) {
|
|
712
|
+
let acc = {};
|
|
713
|
+
const inputKeys = Object.keys(input);
|
|
714
|
+
if (ctx.objectKeyOrder === "input") {
|
|
715
|
+
for (const k of inputKeys) {
|
|
716
|
+
if (hasOwn.call(this.properties, k)) {
|
|
717
|
+
setOwnProperty(acc, k, this.properties[k].parseAfterValidation(ctx, input[k]));
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
for (const p of this.indexedPropertiesParser) {
|
|
721
|
+
const v = input[k];
|
|
722
|
+
const isValid = p.key.validate(ctx, k) && p.value.validate(ctx, v);
|
|
723
|
+
if (isValid) {
|
|
724
|
+
const itemParsed = p.value.parseAfterValidation(ctx, v);
|
|
725
|
+
const keyParsed = p.key.parseAfterValidation(ctx, k);
|
|
726
|
+
setOwnProperty(acc, keyParsed, itemParsed);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
} else {
|
|
731
|
+
const configKeys = Object.keys(this.properties).sort();
|
|
732
|
+
for (const k of configKeys) {
|
|
733
|
+
if (!hasOwn.call(input, k)) {
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
const v = input[k];
|
|
737
|
+
const itemParsed = this.properties[k].parseAfterValidation(ctx, v);
|
|
738
|
+
setOwnProperty(acc, k, itemParsed);
|
|
739
|
+
}
|
|
740
|
+
if (this.indexedPropertiesParser.length > 0) {
|
|
741
|
+
const extraKeys = inputKeys.filter((k) => !hasOwn.call(this.properties, k)).sort();
|
|
742
|
+
for (const k of extraKeys) {
|
|
743
|
+
const v = input[k];
|
|
744
|
+
for (const p of this.indexedPropertiesParser) {
|
|
745
|
+
const isValid = p.key.validate(ctx, k) && p.value.validate(ctx, v);
|
|
746
|
+
if (isValid) {
|
|
747
|
+
const itemParsed = p.value.parseAfterValidation(ctx, v);
|
|
748
|
+
const keyParsed = p.key.parseAfterValidation(ctx, k);
|
|
749
|
+
setOwnProperty(acc, keyParsed, itemParsed);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return acc;
|
|
756
|
+
}
|
|
757
|
+
reportDecodeError(ctx, input) {
|
|
758
|
+
if (typeof input !== "object" || Array.isArray(input) || input === null) {
|
|
759
|
+
return buildError(ctx, "expected object", input);
|
|
760
|
+
}
|
|
761
|
+
let acc = [];
|
|
762
|
+
const configKeys = Object.keys(this.properties);
|
|
763
|
+
for (const k of configKeys) {
|
|
764
|
+
reportAtPath(ctx, acc, k, this.properties[k], input[k]);
|
|
765
|
+
}
|
|
766
|
+
if (this.indexedPropertiesParser.length > 0) {
|
|
767
|
+
const inputKeys = Object.keys(input);
|
|
768
|
+
const extraKeys = inputKeys.filter((k) => !hasOwn.call(this.properties, k));
|
|
769
|
+
for (const k of extraKeys) {
|
|
770
|
+
if (this.leavesKeyToIntersection(ctx, input, k)) {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
for (const p of this.indexedPropertiesParser) {
|
|
774
|
+
const keyOk = p.key.validate(ctx, k);
|
|
775
|
+
const valueOk = p.value.validate(ctx, input[k]);
|
|
776
|
+
const ok = keyOk && valueOk;
|
|
777
|
+
if (!ok) {
|
|
778
|
+
pushPath(ctx, k);
|
|
779
|
+
if (!keyOk) {
|
|
780
|
+
const keyReported = p.key.reportDecodeError(ctx, k);
|
|
781
|
+
acc.push(...keyReported);
|
|
782
|
+
}
|
|
783
|
+
if (!valueOk) {
|
|
784
|
+
const valueReported = p.value.reportDecodeError(ctx, input[k]);
|
|
785
|
+
acc.push(...valueReported);
|
|
786
|
+
}
|
|
787
|
+
popPath(ctx);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
} else {
|
|
792
|
+
if (ctx.disallowExtraProperties && ctx.intersectionInput !== input) {
|
|
793
|
+
const inputKeys = Object.keys(input);
|
|
794
|
+
const extraKeys = inputKeys.filter((k) => !hasOwn.call(this.properties, k));
|
|
795
|
+
if (extraKeys.length > 0) {
|
|
796
|
+
return extraKeys.flatMap((k) => extraPropertyError(ctx, k, configKeys, input[k]));
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return acc;
|
|
801
|
+
}
|
|
802
|
+
allowedKeys() {
|
|
803
|
+
return this.indexedPropertiesParser.length > 0 ? null : Object.keys(this.properties);
|
|
804
|
+
}
|
|
805
|
+
// In an intersection, an index signature only constrains the keys it matches: another member may know the rest.
|
|
806
|
+
leavesKeyToIntersection(ctx, input, k) {
|
|
807
|
+
return ctx.intersectionInput === input && !this.indexedPropertiesParser.some((p) => p.key.validate(ctx, k));
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var RefRuntype = class extends BaseRuntype {
|
|
811
|
+
refName;
|
|
812
|
+
namedRuntypes;
|
|
813
|
+
constructor(metadata, refName, namedRuntypes2) {
|
|
814
|
+
super(metadata);
|
|
815
|
+
this.refName = refName;
|
|
816
|
+
this.namedRuntypes = namedRuntypes2;
|
|
817
|
+
}
|
|
818
|
+
getNamedRuntypes() {
|
|
819
|
+
return this.namedRuntypes;
|
|
820
|
+
}
|
|
821
|
+
describeTypeExpr(_ctx) {
|
|
822
|
+
return this.refName;
|
|
823
|
+
}
|
|
824
|
+
collectDescribeRefs(ctx) {
|
|
825
|
+
const name = this.refName;
|
|
826
|
+
ctx.refCounts[name] = (ctx.refCounts[name] || 0) + 1;
|
|
827
|
+
if (ctx.activeRefs.has(name)) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (ctx.visitedRefs.has(name)) {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
ctx.visitedRefs.add(name);
|
|
834
|
+
ctx.activeRefs.add(name);
|
|
835
|
+
collectDescribeRefs(this.getNamedRuntypes()[name], ctx);
|
|
836
|
+
ctx.activeRefs.delete(name);
|
|
837
|
+
}
|
|
838
|
+
describe(ctx) {
|
|
839
|
+
const name = this.refName;
|
|
840
|
+
const to = this.getNamedRuntypes()[this.refName];
|
|
841
|
+
const refDescription = () => typeDescription(name, this.metadata?.description);
|
|
842
|
+
if (ctx.refCounts[name] > 1) {
|
|
843
|
+
if (ctx.activeRefs.has(name)) {
|
|
844
|
+
return refDescription();
|
|
845
|
+
}
|
|
846
|
+
if (ctx.definitions[name] == null) {
|
|
847
|
+
ctx.activeRefs.add(name);
|
|
848
|
+
ctx.definitions[name] = to.describe(ctx);
|
|
849
|
+
ctx.activeRefs.delete(name);
|
|
850
|
+
}
|
|
851
|
+
return refDescription();
|
|
852
|
+
}
|
|
853
|
+
const target = to.describe(ctx);
|
|
854
|
+
return this.metadata?.description == null ? target : typeDescription(target.typeExpr, this.metadata.description);
|
|
855
|
+
}
|
|
856
|
+
schema(ctx) {
|
|
857
|
+
const name = this.refName;
|
|
858
|
+
const to = this.getNamedRuntypes()[this.refName];
|
|
859
|
+
if (ctx.mode === "contextual") {
|
|
860
|
+
const printingContext = ctx.printingContext;
|
|
861
|
+
if (printingContext == null) {
|
|
862
|
+
throw new Error("INTERNAL ERROR: Missing SchemaPrintingContext");
|
|
863
|
+
}
|
|
864
|
+
if (!printingContext.hasDefinition(name) && !printingContext.isDefinitionInProgress(name)) {
|
|
865
|
+
printingContext.markDefinitionInProgress(name);
|
|
866
|
+
const schemaTarget = printingContext.getNamedTypeSchemaOverride(name) ?? to;
|
|
867
|
+
const body = schemaTarget.schema(ctx);
|
|
868
|
+
printingContext.storeDefinition(name, body);
|
|
869
|
+
}
|
|
870
|
+
return annotateSchema(this.metadata, { $ref: printingContext.getRef(name) });
|
|
871
|
+
}
|
|
872
|
+
if (ctx.seen[name]) {
|
|
873
|
+
return annotateSchema(this.metadata, {});
|
|
874
|
+
}
|
|
875
|
+
ctx.seen[name] = true;
|
|
876
|
+
var tmp = to.schema(ctx);
|
|
877
|
+
delete ctx.seen[name];
|
|
878
|
+
return annotateSchema(this.metadata, tmp);
|
|
879
|
+
}
|
|
880
|
+
validate(ctx, input) {
|
|
881
|
+
const to = this.getNamedRuntypes()[this.refName];
|
|
882
|
+
return to.validate(ctx, input);
|
|
883
|
+
}
|
|
884
|
+
parseAfterValidation(ctx, input) {
|
|
885
|
+
const to = this.getNamedRuntypes()[this.refName];
|
|
886
|
+
return to.parseAfterValidation(ctx, input);
|
|
887
|
+
}
|
|
888
|
+
reportDecodeError(ctx, input) {
|
|
889
|
+
const to = this.getNamedRuntypes()[this.refName];
|
|
890
|
+
return to.reportDecodeError(ctx, input);
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
var ParserFromRuntype = class {
|
|
894
|
+
_runtype;
|
|
895
|
+
name;
|
|
896
|
+
hideTypeNameInDescribe;
|
|
897
|
+
constructor(runtype, name, hideTypeNameInDescribe) {
|
|
898
|
+
this._runtype = runtype;
|
|
899
|
+
this.name = name;
|
|
900
|
+
this.hideTypeNameInDescribe = hideTypeNameInDescribe;
|
|
901
|
+
}
|
|
902
|
+
parse(input, options) {
|
|
903
|
+
const safe = this.safeParse(input, options);
|
|
904
|
+
if (safe.success) {
|
|
905
|
+
return safe.data;
|
|
906
|
+
}
|
|
907
|
+
const explained = printErrors(safe.errors, []);
|
|
908
|
+
throw new Error(`Failed to parse ${this.name} - ${explained}`);
|
|
909
|
+
}
|
|
910
|
+
safeParse(input, options) {
|
|
911
|
+
const disallowExtraProperties = options?.disallowExtraProperties ?? false;
|
|
912
|
+
const objectKeyOrder = options?.objectKeyOrder ?? "input";
|
|
913
|
+
const ok = this.validate(input, options);
|
|
914
|
+
if (ok) {
|
|
915
|
+
let ctx2 = { disallowExtraProperties, objectKeyOrder };
|
|
916
|
+
const parsed = this._runtype.parseAfterValidation(ctx2, input);
|
|
917
|
+
return { success: true, data: parsed };
|
|
918
|
+
}
|
|
919
|
+
let ctx = { path: [], disallowExtraProperties };
|
|
920
|
+
return {
|
|
921
|
+
success: false,
|
|
922
|
+
errors: this._runtype.reportDecodeError(ctx, input).slice(0, 10)
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
validate(input, options) {
|
|
926
|
+
const disallowExtraProperties = options?.disallowExtraProperties ?? false;
|
|
927
|
+
const ctx = { disallowExtraProperties };
|
|
928
|
+
const ok = this._runtype.validate(ctx, input);
|
|
929
|
+
if (typeof ok !== "boolean") {
|
|
930
|
+
throw new Error("INTERNAL ERROR: Expected boolean");
|
|
931
|
+
}
|
|
932
|
+
return ok;
|
|
933
|
+
}
|
|
934
|
+
schema() {
|
|
935
|
+
const ctx = {
|
|
936
|
+
path: [],
|
|
937
|
+
seen: {},
|
|
938
|
+
mode: "flat"
|
|
939
|
+
};
|
|
940
|
+
return this._runtype.schema(ctx);
|
|
941
|
+
}
|
|
942
|
+
schemaWithContext(schemaPrintingContext) {
|
|
943
|
+
const ctx = {
|
|
944
|
+
path: [],
|
|
945
|
+
seen: {},
|
|
946
|
+
mode: "contextual",
|
|
947
|
+
printingContext: schemaPrintingContext
|
|
948
|
+
};
|
|
949
|
+
return this._runtype.schema(ctx);
|
|
950
|
+
}
|
|
951
|
+
describe() {
|
|
952
|
+
const ctx = {
|
|
953
|
+
activeRefs: /* @__PURE__ */ new Set(),
|
|
954
|
+
definitions: {},
|
|
955
|
+
refCounts: {},
|
|
956
|
+
visitedRefs: /* @__PURE__ */ new Set()
|
|
957
|
+
};
|
|
958
|
+
collectDescribeRefs(this._runtype, ctx);
|
|
959
|
+
const out = this._runtype.describe(ctx);
|
|
960
|
+
let sortedDepsKeys = Object.keys(ctx.definitions).sort();
|
|
961
|
+
const depsPart = sortedDepsKeys.map((key) => [key, ctx.definitions[key]]).map(([key, description]) => renderTypeAlias(key, description)).join("\n\n");
|
|
962
|
+
if (this.hideTypeNameInDescribe) {
|
|
963
|
+
return [depsPart, renderTypeDescription(out)].filter((it) => it != null && it.length > 0).join("\n\n");
|
|
964
|
+
}
|
|
965
|
+
const outPart = renderTypeAlias(`Codec${this.name}`, out);
|
|
966
|
+
return [depsPart, outPart].filter((it) => it != null && it.length > 0).join("\n\n");
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
var buildParserFromRuntype = (runtype, name, hideTypeNameInDescribe) => new ParserFromRuntype(runtype, name, hideTypeNameInDescribe);
|
|
970
|
+
var buildParsers = (generated, args) => {
|
|
971
|
+
const stringFormats = args?.stringFormats ?? {};
|
|
972
|
+
for (const k of generated.requiredStringFormats) {
|
|
973
|
+
if (stringFormats[k] == null) {
|
|
974
|
+
throw new Error(`Missing custom format ${k}`);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
Object.keys(stringFormats).forEach((k) => {
|
|
978
|
+
const v = stringFormats[k];
|
|
979
|
+
registerStringFormatter(generated.stringFormatters, k, v);
|
|
980
|
+
});
|
|
981
|
+
const numberFormats = args?.numberFormats ?? {};
|
|
982
|
+
for (const k of generated.requiredNumberFormats) {
|
|
983
|
+
if (numberFormats[k] == null) {
|
|
984
|
+
throw new Error(`Missing custom format ${k}`);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
Object.keys(numberFormats).forEach((k) => {
|
|
988
|
+
const v = numberFormats[k];
|
|
989
|
+
registerNumberFormatter(generated.numberFormatters, k, v);
|
|
990
|
+
});
|
|
991
|
+
let acc = {};
|
|
992
|
+
for (const k of Object.keys(generated.parsers)) {
|
|
993
|
+
const it = buildParserFromRuntype(generated.parsers[k], k, false);
|
|
994
|
+
acc[k] = it;
|
|
995
|
+
}
|
|
996
|
+
return acc;
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
// ../aula-bundle/generated/parser.js
|
|
1000
|
+
var RequiredStringFormats = [];
|
|
1001
|
+
var RequiredNumberFormats = [];
|
|
1002
|
+
var namedRuntypes = {};
|
|
1003
|
+
var stringFormatters = {};
|
|
1004
|
+
var numberFormatters = {};
|
|
1005
|
+
var direct_hoist_0 = new RefRuntype(void 0, "PackageJson", namedRuntypes);
|
|
1006
|
+
var direct_hoist_1 = new AnyRuntype(void 0);
|
|
1007
|
+
var direct_hoist_2 = new TypeofRuntype(void 0, "string");
|
|
1008
|
+
var direct_hoist_3 = new ArrayRuntype(void 0, direct_hoist_2);
|
|
1009
|
+
var direct_hoist_4 = new ObjectRuntype({
|
|
1010
|
+
"description": "The part of a package.json that aula reads: how a package names its module and its\nworkspace packages."
|
|
1011
|
+
}, {
|
|
1012
|
+
"exports": new OptionalFieldRuntype(direct_hoist_1),
|
|
1013
|
+
"main": new OptionalFieldRuntype(direct_hoist_2),
|
|
1014
|
+
"module": new OptionalFieldRuntype(direct_hoist_2),
|
|
1015
|
+
"name": new OptionalFieldRuntype(direct_hoist_2),
|
|
1016
|
+
"workspaces": new OptionalFieldRuntype(direct_hoist_3)
|
|
1017
|
+
}, []);
|
|
1018
|
+
Object.assign(namedRuntypes, {
|
|
1019
|
+
"PackageJson": direct_hoist_4
|
|
1020
|
+
});
|
|
1021
|
+
var buildParsersInput = {
|
|
1022
|
+
"PackageJson": direct_hoist_0
|
|
1023
|
+
};
|
|
1024
|
+
var parser_default = {
|
|
1025
|
+
buildParsers: (args) => buildParsers(
|
|
1026
|
+
{
|
|
1027
|
+
parsers: buildParsersInput,
|
|
1028
|
+
stringFormatters,
|
|
1029
|
+
numberFormatters,
|
|
1030
|
+
requiredStringFormats: RequiredStringFormats,
|
|
1031
|
+
requiredNumberFormats: RequiredNumberFormats
|
|
1032
|
+
},
|
|
1033
|
+
args
|
|
1034
|
+
)
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
// ../aula-bundle/src/parsers.ts
|
|
1038
|
+
var Parsers = parser_default.buildParsers();
|
|
1039
|
+
|
|
1040
|
+
// ../aula-bundle/src/index.ts
|
|
1041
|
+
var SOURCE_PREFIX = "tree:";
|
|
1042
|
+
function dirname(path2) {
|
|
1043
|
+
const at = path2.lastIndexOf("/");
|
|
1044
|
+
return at < 0 ? "" : path2.slice(0, at);
|
|
1045
|
+
}
|
|
1046
|
+
function join(from, relative) {
|
|
1047
|
+
const parts = from === "" ? [] : from.split("/");
|
|
1048
|
+
for (const part of relative.split("/")) {
|
|
1049
|
+
if (part === "" || part === ".") continue;
|
|
1050
|
+
if (part === "..") {
|
|
1051
|
+
if (!parts.length) return null;
|
|
1052
|
+
parts.pop();
|
|
1053
|
+
} else parts.push(part);
|
|
1054
|
+
}
|
|
1055
|
+
return parts.join("/");
|
|
1056
|
+
}
|
|
1057
|
+
var LOADERS = /* @__PURE__ */ new Map([
|
|
1058
|
+
["ts", "ts"],
|
|
1059
|
+
["mts", "ts"],
|
|
1060
|
+
["js", "js"],
|
|
1061
|
+
["mjs", "js"],
|
|
1062
|
+
["json", "json"]
|
|
1063
|
+
]);
|
|
1064
|
+
var loaderOf = (path2) => LOADERS.get(path2.slice(path2.lastIndexOf(".") + 1)) ?? "ts";
|
|
1065
|
+
function treePlugin(tree, imports) {
|
|
1066
|
+
return {
|
|
1067
|
+
name: "aula-tree",
|
|
1068
|
+
setup(build) {
|
|
1069
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
1070
|
+
const url = imports[args.path];
|
|
1071
|
+
if (url !== void 0) return { path: url, external: true };
|
|
1072
|
+
if (args.kind === "entry-point") return { path: join("", args.path) ?? args.path, namespace: "tree" };
|
|
1073
|
+
if (!args.path.startsWith("./") && !args.path.startsWith("../")) {
|
|
1074
|
+
const found = await resolvePackage(tree, args.path, args.importer);
|
|
1075
|
+
if (found !== null) return { path: found, namespace: "tree" };
|
|
1076
|
+
return {
|
|
1077
|
+
errors: [{ text: `cannot find the package "${args.path}" in node_modules or the workspace packages` }]
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
const path2 = join(dirname(args.importer), args.path);
|
|
1081
|
+
if (path2 === null) return { errors: [{ text: `"${args.path}" is outside the folder you opened` }] };
|
|
1082
|
+
for (const candidate of [path2, `${path2}.ts`, `${path2}/index.ts`]) {
|
|
1083
|
+
if (await tree.read(candidate) !== null) return { path: candidate, namespace: "tree" };
|
|
1084
|
+
}
|
|
1085
|
+
return { errors: [{ text: `cannot find "${args.path}" (${path2})` }] };
|
|
1086
|
+
});
|
|
1087
|
+
build.onLoad({ filter: /.*/, namespace: "tree" }, async (args) => {
|
|
1088
|
+
const contents = await tree.read(args.path);
|
|
1089
|
+
if (contents === null) return { errors: [{ text: `cannot read ${args.path}` }] };
|
|
1090
|
+
return { contents, loader: loaderOf(args.path) };
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function isMessage(value) {
|
|
1096
|
+
return typeof value === "object" && value !== null && typeof Reflect.get(value, "text") === "string";
|
|
1097
|
+
}
|
|
1098
|
+
var diagnostic = ({ text, location: at }) => ({
|
|
1099
|
+
severity: "error",
|
|
1100
|
+
message: text,
|
|
1101
|
+
...at ? { location: { file: at.file.replace(SOURCE_PREFIX, ""), line: at.line, col: at.column + 1 } } : {},
|
|
1102
|
+
stack: [],
|
|
1103
|
+
related: []
|
|
1104
|
+
});
|
|
1105
|
+
async function bundle(esbuild, tree, entry, imports) {
|
|
1106
|
+
let result;
|
|
1107
|
+
try {
|
|
1108
|
+
result = await esbuild.build({
|
|
1109
|
+
entryPoints: [entry],
|
|
1110
|
+
bundle: true,
|
|
1111
|
+
write: false,
|
|
1112
|
+
format: "esm",
|
|
1113
|
+
platform: "browser",
|
|
1114
|
+
target: "es2024",
|
|
1115
|
+
outfile: "bundle.js",
|
|
1116
|
+
sourcemap: "both",
|
|
1117
|
+
sourcesContent: false,
|
|
1118
|
+
metafile: true,
|
|
1119
|
+
logLevel: "silent",
|
|
1120
|
+
plugins: [treePlugin(tree, imports)]
|
|
1121
|
+
});
|
|
1122
|
+
} catch (error2) {
|
|
1123
|
+
const errors = typeof error2 === "object" && error2 !== null ? Reflect.get(error2, "errors") : void 0;
|
|
1124
|
+
if (Array.isArray(errors) && errors.every(isMessage)) return { _tag: "Left", left: errors.map(diagnostic) };
|
|
1125
|
+
throw error2;
|
|
1126
|
+
}
|
|
1127
|
+
const code = result.outputFiles.find((f) => f.path.endsWith(".js"))?.text;
|
|
1128
|
+
const map = result.outputFiles.find((f) => f.path.endsWith(".js.map"))?.text;
|
|
1129
|
+
if (code === void 0 || map === void 0) throw new Error("esbuild wrote no bundle");
|
|
1130
|
+
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((input) => input.startsWith(SOURCE_PREFIX)).map((input) => input.slice(SOURCE_PREFIX.length));
|
|
1131
|
+
return { _tag: "Right", right: { code, map, inputs } };
|
|
1132
|
+
}
|
|
1133
|
+
function exportTarget(exports, subpath) {
|
|
1134
|
+
if (typeof exports === "string") return subpath === "." ? exports : null;
|
|
1135
|
+
if (typeof exports !== "object" || exports === null) return null;
|
|
1136
|
+
const keys = Object.keys(exports);
|
|
1137
|
+
if (keys.some((key) => key.startsWith("."))) {
|
|
1138
|
+
return subpath in exports ? exportTarget(Reflect.get(exports, subpath), ".") : null;
|
|
1139
|
+
}
|
|
1140
|
+
for (const key of ["browser", "import", "default"]) {
|
|
1141
|
+
if (key in exports) return exportTarget(Reflect.get(exports, key), ".");
|
|
1142
|
+
}
|
|
1143
|
+
return null;
|
|
1144
|
+
}
|
|
1145
|
+
function packageOf(specifier) {
|
|
1146
|
+
const parts = specifier.split("/");
|
|
1147
|
+
const size = specifier.startsWith("@") ? 2 : 1;
|
|
1148
|
+
const rest = parts.slice(size).join("/");
|
|
1149
|
+
return { name: parts.slice(0, size).join("/"), subpath: rest === "" ? "." : `./${rest}` };
|
|
1150
|
+
}
|
|
1151
|
+
async function packageModule(tree, folder, subpath) {
|
|
1152
|
+
const found = manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`));
|
|
1153
|
+
if (!found) return null;
|
|
1154
|
+
const target = exportTarget(found.exports, subpath) ?? (subpath === "." ? found.module ?? found.main ?? "index.js" : subpath);
|
|
1155
|
+
return join(folder, target);
|
|
1156
|
+
}
|
|
1157
|
+
async function resolveBare(tree, specifier, importer) {
|
|
1158
|
+
const { name, subpath } = packageOf(specifier);
|
|
1159
|
+
for (let dir = dirname(importer); ; dir = dirname(dir)) {
|
|
1160
|
+
const found = await packageModule(
|
|
1161
|
+
tree,
|
|
1162
|
+
dir === "" ? `node_modules/${name}` : `${dir}/node_modules/${name}`,
|
|
1163
|
+
subpath
|
|
1164
|
+
);
|
|
1165
|
+
if (found !== null) return found;
|
|
1166
|
+
if (dir === "") return null;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function manifest(file, text) {
|
|
1170
|
+
if (text === null) return null;
|
|
1171
|
+
const parsed = Parsers.PackageJson.safeParse(JSON.parse(text));
|
|
1172
|
+
return parsed.success ? parsed.data : null;
|
|
1173
|
+
}
|
|
1174
|
+
async function workspaceFolders(tree) {
|
|
1175
|
+
const patterns = [];
|
|
1176
|
+
const pnpm = await tree.read("pnpm-workspace.yaml");
|
|
1177
|
+
if (pnpm !== null) {
|
|
1178
|
+
let inside = false;
|
|
1179
|
+
for (const line of pnpm.split("\n")) {
|
|
1180
|
+
if (/^packages:\s*$/.test(line)) inside = true;
|
|
1181
|
+
else if (/^\S/.test(line)) inside = false;
|
|
1182
|
+
else if (inside) {
|
|
1183
|
+
const item = /^\s*-\s*["']?([^"'#]+?)["']?\s*(#.*)?$/.exec(line)?.[1];
|
|
1184
|
+
if (item !== void 0) patterns.push(item);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
patterns.push(...manifest("package.json", await tree.read("package.json"))?.workspaces ?? []);
|
|
1189
|
+
const folders = [];
|
|
1190
|
+
for (const pattern of patterns) {
|
|
1191
|
+
const clean = pattern.replace(/^\.\//, "").replace(/\/$/, "");
|
|
1192
|
+
if (clean.endsWith("/*")) {
|
|
1193
|
+
const parent = clean.slice(0, -2);
|
|
1194
|
+
folders.push(...(await tree.list(parent)).map((name) => `${parent}/${name}`));
|
|
1195
|
+
} else if (!clean.includes("*")) folders.push(clean);
|
|
1196
|
+
}
|
|
1197
|
+
return folders;
|
|
1198
|
+
}
|
|
1199
|
+
async function resolvePackage(tree, specifier, importer) {
|
|
1200
|
+
const installed = await resolveBare(tree, specifier, importer);
|
|
1201
|
+
if (installed !== null) return installed;
|
|
1202
|
+
const { name, subpath } = packageOf(specifier);
|
|
1203
|
+
for (const folder of await workspaceFolders(tree)) {
|
|
1204
|
+
if (manifest(`${folder}/package.json`, await tree.read(`${folder}/package.json`))?.name !== name) continue;
|
|
1205
|
+
return packageModule(tree, folder, subpath);
|
|
1206
|
+
}
|
|
1207
|
+
return null;
|
|
1208
|
+
}
|
|
1209
|
+
var ORDER = /^(\d+)-/;
|
|
1210
|
+
var projectName = (folder) => folder.replace(ORDER, "");
|
|
1211
|
+
|
|
1212
|
+
// ../aula-project/src/node.ts
|
|
1213
|
+
var PROJECT_MODULE = "index.ts";
|
|
1214
|
+
var GLUE = [
|
|
1215
|
+
`${path.dirname(new URL(import.meta.resolve("@beff/aula")).pathname)}/`,
|
|
1216
|
+
new URL(import.meta.url).pathname
|
|
1217
|
+
];
|
|
1218
|
+
function host(capabilities, root, glue = []) {
|
|
1219
|
+
const all = [...GLUE, ...glue];
|
|
1220
|
+
return {
|
|
1221
|
+
frames: v8Frames,
|
|
1222
|
+
name: (file) => file.startsWith("/") && !file.includes("/node_modules/") && !all.some((g) => file.startsWith(g)) ? path.relative(root, file) : void 0,
|
|
1223
|
+
exists: (file) => capabilities.fs.existsSync(path.resolve(root, file))
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
function propertyOf(e, key) {
|
|
1227
|
+
return typeof e === "object" && e !== null ? Reflect.get(e, key) : void 0;
|
|
1228
|
+
}
|
|
1229
|
+
async function loadProject(capabilities, load, root, folder) {
|
|
1230
|
+
const file = path.join(folder, PROJECT_MODULE);
|
|
1231
|
+
if (!capabilities.fs.existsSync(file)) {
|
|
1232
|
+
throw wrongArgument(
|
|
1233
|
+
`${path.relative(root, folder) || "."} has no ${PROJECT_MODULE}`,
|
|
1234
|
+
`give the project folder: the folder with ${PROJECT_MODULE}`
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
await loadEngine();
|
|
1238
|
+
const module = await load(pathToFileURL(file).href);
|
|
1239
|
+
const exported = propertyOf(module, "default");
|
|
1240
|
+
if (!isProjectDefinition(exported)) {
|
|
1241
|
+
const rel = path.relative(root, file);
|
|
1242
|
+
throw new Problems([
|
|
1243
|
+
error(`the default export of ${rel} is not made by defineProject`, {
|
|
1244
|
+
location: { file: rel, line: 1, col: 0 },
|
|
1245
|
+
hint: "write `export default defineProject({ title, theme, chapters: [ \u2026 ] })`"
|
|
1246
|
+
})
|
|
1247
|
+
]);
|
|
1248
|
+
}
|
|
1249
|
+
return exported;
|
|
1250
|
+
}
|
|
1251
|
+
var folderOf = (project) => path.dirname(definedAt(project).file);
|
|
1252
|
+
var nameOf = (project) => projectName(path.basename(folderOf(project)));
|
|
1253
|
+
async function withSource(capabilities, root, d) {
|
|
1254
|
+
if (d.source !== void 0 || d.location === void 0) return d;
|
|
1255
|
+
const file = path.resolve(root, d.location.file);
|
|
1256
|
+
if (!capabilities.fs.existsSync(file)) return d;
|
|
1257
|
+
const text = await capabilities.fs.readFile(file, "utf8");
|
|
1258
|
+
const lines = text.split("\n");
|
|
1259
|
+
if (lines.at(-1) === "") lines.pop();
|
|
1260
|
+
const line = lines[d.location.line - 1];
|
|
1261
|
+
return line === void 0 || d.location.line < 1 ? d : { ...d, source: line.replace(/\r$/, "") };
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export {
|
|
1265
|
+
TypeofRuntype,
|
|
1266
|
+
OptionalFieldRuntype,
|
|
1267
|
+
ObjectRuntype,
|
|
1268
|
+
RefRuntype,
|
|
1269
|
+
buildParsers,
|
|
1270
|
+
Parsers,
|
|
1271
|
+
bundle,
|
|
1272
|
+
error,
|
|
1273
|
+
isError,
|
|
1274
|
+
Problems,
|
|
1275
|
+
wrongArgument,
|
|
1276
|
+
diagnosticsOf,
|
|
1277
|
+
host,
|
|
1278
|
+
loadProject,
|
|
1279
|
+
folderOf,
|
|
1280
|
+
nameOf,
|
|
1281
|
+
withSource
|
|
1282
|
+
};
|