@nudojs/service 5.0.0-beta.0 → 5.0.0-beta.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 +7 -12
- package/dist/{analysis-CSXrOVlg.d.ts → analysis-_DlXLC-L.d.ts} +17 -3
- package/dist/analysis.d.ts +3 -2
- package/dist/analysis.js +9 -5
- package/dist/{analyzer-types-JyJiCt8w.d.ts → analyzer-types-CfBrPK9L.d.ts} +1 -1
- package/dist/{chunk-LFZRUXGK.js → chunk-EG6FYQLI.js} +1 -1
- package/dist/chunk-J2PUE4NV.js +235 -0
- package/dist/{chunk-QAFMPM2E.js → chunk-NQXAF4LJ.js} +2277 -2225
- package/dist/{chunk-YLALZXTZ.js → chunk-ZXVAX7DE.js} +255 -11
- package/dist/{interface-BGlP7aIk.d.ts → emit/index.d.ts} +258 -18
- package/dist/{chunk-HEU4WON5.js → emit/index.js} +1627 -299
- package/dist/evaluator/evaluator-api.d.ts +1 -1
- package/dist/evaluator/evaluator-api.js +5 -5
- package/dist/index.d.ts +17 -19
- package/dist/index.js +188 -197
- package/dist/what-if-mIo7I5Ii.d.ts +21 -0
- package/package.json +9 -25
- package/dist/case.d.ts +0 -124
- package/dist/case.js +0 -18
- package/dist/chunk-6IZR4ZYJ.js +0 -1107
- package/dist/chunk-E4N4A4JV.js +0 -651
- package/dist/chunk-K3ZPOTP2.js +0 -199
- package/dist/chunk-PVJIMQRI.js +0 -246
- package/dist/chunk-QYRH7Z2Q.js +0 -89
- package/dist/chunk-U7JYTRIB.js +0 -888
- package/dist/chunk-YLVZMHWC.js +0 -364
- package/dist/dts.d.ts +0 -142
- package/dist/dts.js +0 -30
- package/dist/harvest.d.ts +0 -254
- package/dist/harvest.js +0 -75
- package/dist/interface.d.ts +0 -3
- package/dist/interface.js +0 -43
- package/dist/lsp.d.ts +0 -103
- package/dist/lsp.js +0 -36
package/dist/chunk-YLVZMHWC.js
DELETED
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
// src/case-emitter.ts
|
|
2
|
-
import { parse, extractDirectives } from "@nudojs/parser";
|
|
3
|
-
var GENERATED_PREFIX = "call@";
|
|
4
|
-
var GENERATED_CASE_LINE_REGEX = /^\s*\*?\s*@nudo:case\s+"(call@[^"]*)"/;
|
|
5
|
-
var IDENT_KEY_REGEX = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
6
|
-
var NUMBER_LITERAL_REGEX = /^-?\d+(\.\d+)?$/;
|
|
7
|
-
var UNSAFE_STRING_CHARS = /[,()[\]{}]/;
|
|
8
|
-
var UNSAFE_KEY_CHARS = /[,()[\]{}:]/;
|
|
9
|
-
var CONTROL_CHARS = /[\x00-\x1f\x7f]/;
|
|
10
|
-
function serializeStringLiteral(value) {
|
|
11
|
-
if (CONTROL_CHARS.test(value)) return null;
|
|
12
|
-
if (value.includes("*/")) return null;
|
|
13
|
-
if (UNSAFE_STRING_CHARS.test(value)) return null;
|
|
14
|
-
const hasDbl = value.includes('"');
|
|
15
|
-
const hasSgl = value.includes("'");
|
|
16
|
-
if (hasDbl && hasSgl) return null;
|
|
17
|
-
return hasDbl ? `'${value}'` : `"${value}"`;
|
|
18
|
-
}
|
|
19
|
-
function serializeObjectKey(key) {
|
|
20
|
-
if (IDENT_KEY_REGEX.test(key)) return key;
|
|
21
|
-
if (CONTROL_CHARS.test(key)) return null;
|
|
22
|
-
if (key.includes('"')) return null;
|
|
23
|
-
if (UNSAFE_KEY_CHARS.test(key) || key.includes("*/")) return null;
|
|
24
|
-
if (/^['"]|['"]$/.test(key)) return null;
|
|
25
|
-
return `"${key}"`;
|
|
26
|
-
}
|
|
27
|
-
function serializeCaseArg(a) {
|
|
28
|
-
const s = a.shape;
|
|
29
|
-
if (a.term?.op === "lit") {
|
|
30
|
-
const v = a.term.value;
|
|
31
|
-
if (typeof v === "number") {
|
|
32
|
-
if (!Number.isFinite(v)) return null;
|
|
33
|
-
const n = String(v);
|
|
34
|
-
return NUMBER_LITERAL_REGEX.test(n) ? n : null;
|
|
35
|
-
}
|
|
36
|
-
if (typeof v === "boolean") return v ? "true" : "false";
|
|
37
|
-
if (v === null) return "null";
|
|
38
|
-
if (v === void 0) return "undefined";
|
|
39
|
-
if (typeof v === "bigint") return null;
|
|
40
|
-
if (typeof v === "string") return serializeStringLiteral(v);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
switch (s.k) {
|
|
44
|
-
case "prim":
|
|
45
|
-
if (s.type === "number") return "number()";
|
|
46
|
-
if (s.type === "string") return "string()";
|
|
47
|
-
if (s.type === "boolean") return "boolean()";
|
|
48
|
-
return null;
|
|
49
|
-
case "unknown":
|
|
50
|
-
case "any":
|
|
51
|
-
return "any()";
|
|
52
|
-
case "never":
|
|
53
|
-
return "never";
|
|
54
|
-
case "sum": {
|
|
55
|
-
const parts = [];
|
|
56
|
-
for (const member of s.members) {
|
|
57
|
-
const ser = serializeCaseArg(member);
|
|
58
|
-
if (ser === null) return null;
|
|
59
|
-
parts.push(ser);
|
|
60
|
-
}
|
|
61
|
-
return `union(${parts.join(", ")})`;
|
|
62
|
-
}
|
|
63
|
-
case "arr": {
|
|
64
|
-
const el = serializeCaseArg(s.element);
|
|
65
|
-
return el === null ? null : `array(${el})`;
|
|
66
|
-
}
|
|
67
|
-
case "tuple": {
|
|
68
|
-
const parts = [];
|
|
69
|
-
for (const el of s.elements) {
|
|
70
|
-
const ser = serializeCaseArg(el);
|
|
71
|
-
if (ser === null) return null;
|
|
72
|
-
parts.push(ser);
|
|
73
|
-
}
|
|
74
|
-
return `[${parts.join(", ")}]`;
|
|
75
|
-
}
|
|
76
|
-
case "obj": {
|
|
77
|
-
const parts = [];
|
|
78
|
-
for (const [key, slot] of Object.entries(s.slots)) {
|
|
79
|
-
const vs = serializeCaseArg(slot.value);
|
|
80
|
-
if (vs === null) return null;
|
|
81
|
-
const ks = serializeObjectKey(key);
|
|
82
|
-
if (ks === null) return null;
|
|
83
|
-
parts.push(`${ks}: ${vs}`);
|
|
84
|
-
}
|
|
85
|
-
return parts.length === 0 ? "{}" : `{ ${parts.join(", ")} }`;
|
|
86
|
-
}
|
|
87
|
-
default:
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function buildCaseDirective(name, argsAbs) {
|
|
92
|
-
if (name.includes('"') || /[\r\n]/.test(name)) return null;
|
|
93
|
-
const parts = [];
|
|
94
|
-
for (const arg of argsAbs) {
|
|
95
|
-
const s = serializeCaseArg(arg);
|
|
96
|
-
if (s === null) return null;
|
|
97
|
-
parts.push(s);
|
|
98
|
-
}
|
|
99
|
-
return ` * @nudo:case "${name}" (${parts.join(", ")})`;
|
|
100
|
-
}
|
|
101
|
-
function stripGeneratedCaseDirectives(source) {
|
|
102
|
-
const lines = source.split("\n");
|
|
103
|
-
const removed = [];
|
|
104
|
-
const drop = new Array(lines.length).fill(false);
|
|
105
|
-
for (let i = 0; i < lines.length; i++) {
|
|
106
|
-
const m = lines[i].match(GENERATED_CASE_LINE_REGEX);
|
|
107
|
-
if (m) {
|
|
108
|
-
drop[i] = true;
|
|
109
|
-
removed.push(m[1]);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
for (let i = 0; i < lines.length; i++) {
|
|
113
|
-
if (!/^\s*\/\*\*\s*$/.test(lines[i])) continue;
|
|
114
|
-
let j = i + 1;
|
|
115
|
-
let clean = true;
|
|
116
|
-
while (j < lines.length) {
|
|
117
|
-
if (/\*\//.test(lines[j])) break;
|
|
118
|
-
if (/\/\*/.test(lines[j])) {
|
|
119
|
-
clean = false;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
j++;
|
|
123
|
-
}
|
|
124
|
-
if (!clean || j >= lines.length) continue;
|
|
125
|
-
if (!/^\s*\*\/\s*$/.test(lines[j])) continue;
|
|
126
|
-
let onlyFiller = true;
|
|
127
|
-
for (let k = i + 1; k < j; k++) {
|
|
128
|
-
if (drop[k]) continue;
|
|
129
|
-
const t = lines[k].trim();
|
|
130
|
-
if (t !== "" && !/^\*{1,2}$/.test(t)) {
|
|
131
|
-
onlyFiller = false;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (onlyFiller) {
|
|
136
|
-
for (let k = i; k <= j; k++) drop[k] = true;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
source: lines.filter((_, i) => !drop[i]).join("\n"),
|
|
141
|
-
removed
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
function collectExistingCases(source) {
|
|
145
|
-
const byName = /* @__PURE__ */ new Map();
|
|
146
|
-
let ast;
|
|
147
|
-
try {
|
|
148
|
-
ast = parse(source, { errorRecovery: true });
|
|
149
|
-
} catch {
|
|
150
|
-
return byName;
|
|
151
|
-
}
|
|
152
|
-
for (const { name, directives } of extractDirectives(ast)) {
|
|
153
|
-
for (const d of directives) {
|
|
154
|
-
if (d.kind !== "case") continue;
|
|
155
|
-
const list = byName.get(name);
|
|
156
|
-
if (list) list.push(d);
|
|
157
|
-
else byName.set(name, [d]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return byName;
|
|
161
|
-
}
|
|
162
|
-
function insertGeneratedCaseDirectives(source, analysis) {
|
|
163
|
-
const written = [];
|
|
164
|
-
const skipped = [];
|
|
165
|
-
const existing = collectExistingCases(source);
|
|
166
|
-
const edits = [];
|
|
167
|
-
for (const fn of analysis.functions) {
|
|
168
|
-
const existingCases = existing.get(fn.name) ?? [];
|
|
169
|
-
if (existingCases.some((c) => !c.name.startsWith(GENERATED_PREFIX))) {
|
|
170
|
-
skipped.push({ fn: fn.name, reason: "hand-written" });
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (existingCases.length > 0) {
|
|
174
|
-
skipped.push({ fn: fn.name, reason: "already-generated" });
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
if (fn.skipped) {
|
|
178
|
-
skipped.push({ fn: fn.name, reason: "skipped" });
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (fn.noDeclaration) {
|
|
182
|
-
skipped.push({ fn: fn.name, reason: "no-declaration" });
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (fn.entryOnly) {
|
|
186
|
-
skipped.push({ fn: fn.name, reason: "entry-only" });
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
const callsiteCases = fn.cases.filter((c) => c.source === "callsite");
|
|
190
|
-
if (callsiteCases.length === 0) {
|
|
191
|
-
skipped.push({ fn: fn.name, reason: "no-serializable-cases", detail: "no callsite cases" });
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
const built = [];
|
|
195
|
-
const names = [];
|
|
196
|
-
for (const c of callsiteCases) {
|
|
197
|
-
const directive = buildCaseDirective(c.name, c.argAbs ?? []);
|
|
198
|
-
if (directive === null) {
|
|
199
|
-
skipped.push({ fn: fn.name, reason: "no-serializable-cases", detail: `case ${c.name} not serializable` });
|
|
200
|
-
} else {
|
|
201
|
-
built.push(directive);
|
|
202
|
-
names.push(c.name);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (built.length === 0) continue;
|
|
206
|
-
edits.push({ line: fn.loc.start.line, column: fn.loc.start.column, directives: built, fn: fn.name });
|
|
207
|
-
written.push({ fn: fn.name, cases: names });
|
|
208
|
-
}
|
|
209
|
-
edits.sort((a, b) => b.line - a.line);
|
|
210
|
-
const lines = source.split("\n");
|
|
211
|
-
for (const edit of edits) {
|
|
212
|
-
const declIdx = edit.line - 1;
|
|
213
|
-
const indent = " ".repeat(edit.column);
|
|
214
|
-
let insertIdx = -1;
|
|
215
|
-
let blockIndent = "";
|
|
216
|
-
const aboveIdx = declIdx - 1;
|
|
217
|
-
if (aboveIdx >= 0 && /^\s*\*\/\s*$/.test(lines[aboveIdx])) {
|
|
218
|
-
let s = aboveIdx - 1;
|
|
219
|
-
while (s >= 0) {
|
|
220
|
-
const t = lines[s];
|
|
221
|
-
if (/^\s*\/\*\*/.test(t)) {
|
|
222
|
-
insertIdx = s + 1;
|
|
223
|
-
blockIndent = t.match(/^\s*/)?.[0] ?? "";
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
if (/^\s*\*/.test(t) || t.trim() === "") {
|
|
227
|
-
s--;
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (insertIdx >= 0) {
|
|
234
|
-
lines.splice(insertIdx, 0, ...edit.directives.map((d) => blockIndent + d));
|
|
235
|
-
} else {
|
|
236
|
-
lines.splice(declIdx, 0, `${indent}/**`, ...edit.directives.map((d) => indent + d), `${indent} */`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
source: lines.join("\n"),
|
|
241
|
-
changed: written.length > 0,
|
|
242
|
-
written,
|
|
243
|
-
skipped
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
function diffOps(a, b) {
|
|
247
|
-
let start = 0;
|
|
248
|
-
while (start < a.length && start < b.length && a[start] === b[start]) start++;
|
|
249
|
-
let endA = a.length;
|
|
250
|
-
let endB = b.length;
|
|
251
|
-
while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
|
|
252
|
-
endA--;
|
|
253
|
-
endB--;
|
|
254
|
-
}
|
|
255
|
-
const midA = a.slice(start, endA);
|
|
256
|
-
const midB = b.slice(start, endB);
|
|
257
|
-
const n = midA.length;
|
|
258
|
-
const m = midB.length;
|
|
259
|
-
const dp = new Int32Array((n + 1) * (m + 1));
|
|
260
|
-
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
261
|
-
for (let j2 = m - 1; j2 >= 0; j2--) {
|
|
262
|
-
dp[i2 * (m + 1) + j2] = midA[i2] === midB[j2] ? dp[(i2 + 1) * (m + 1) + (j2 + 1)] + 1 : Math.max(dp[(i2 + 1) * (m + 1) + j2], dp[i2 * (m + 1) + (j2 + 1)]);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const ops = [];
|
|
266
|
-
for (let k = 0; k < start; k++) ops.push({ type: "equal", text: a[k] });
|
|
267
|
-
let i = 0;
|
|
268
|
-
let j = 0;
|
|
269
|
-
while (i < n && j < m) {
|
|
270
|
-
if (midA[i] === midB[j]) {
|
|
271
|
-
ops.push({ type: "equal", text: midA[i] });
|
|
272
|
-
i++;
|
|
273
|
-
j++;
|
|
274
|
-
} else if (dp[(i + 1) * (m + 1) + j] >= dp[i * (m + 1) + (j + 1)]) {
|
|
275
|
-
ops.push({ type: "delete", text: midA[i] });
|
|
276
|
-
i++;
|
|
277
|
-
} else {
|
|
278
|
-
ops.push({ type: "insert", text: midB[j] });
|
|
279
|
-
j++;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
while (i < n) ops.push({ type: "delete", text: midA[i++] });
|
|
283
|
-
while (j < m) ops.push({ type: "insert", text: midB[j++] });
|
|
284
|
-
for (let k = endA; k < a.length; k++) ops.push({ type: "equal", text: a[k] });
|
|
285
|
-
return ops;
|
|
286
|
-
}
|
|
287
|
-
var DIFF_CONTEXT = 3;
|
|
288
|
-
function formatRange(start, count) {
|
|
289
|
-
const s = count === 0 ? start - 1 : start;
|
|
290
|
-
return count === 1 ? `${s}` : `${s},${count}`;
|
|
291
|
-
}
|
|
292
|
-
function unifiedDiff(a, b, path) {
|
|
293
|
-
if (a === b) return "";
|
|
294
|
-
const ops = diffOps(a.split("\n"), b.split("\n"));
|
|
295
|
-
const hunks = [];
|
|
296
|
-
let idx = 0;
|
|
297
|
-
while (idx < ops.length) {
|
|
298
|
-
if (ops[idx].type === "equal") {
|
|
299
|
-
idx++;
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
let start = idx;
|
|
303
|
-
let ctx = 0;
|
|
304
|
-
while (start > 0 && ops[start - 1].type === "equal" && ctx < DIFF_CONTEXT) {
|
|
305
|
-
start--;
|
|
306
|
-
ctx++;
|
|
307
|
-
}
|
|
308
|
-
let j = idx;
|
|
309
|
-
let equalRun = 0;
|
|
310
|
-
let lastChange = idx;
|
|
311
|
-
while (j < ops.length) {
|
|
312
|
-
if (ops[j].type === "equal") {
|
|
313
|
-
equalRun++;
|
|
314
|
-
if (equalRun > DIFF_CONTEXT * 2) break;
|
|
315
|
-
} else {
|
|
316
|
-
equalRun = 0;
|
|
317
|
-
lastChange = j;
|
|
318
|
-
}
|
|
319
|
-
j++;
|
|
320
|
-
}
|
|
321
|
-
let end = lastChange + 1;
|
|
322
|
-
ctx = 0;
|
|
323
|
-
while (end < ops.length && ops[end].type === "equal" && ctx < DIFF_CONTEXT) {
|
|
324
|
-
end++;
|
|
325
|
-
ctx++;
|
|
326
|
-
}
|
|
327
|
-
hunks.push({ start, ops: ops.slice(start, end) });
|
|
328
|
-
idx = end;
|
|
329
|
-
}
|
|
330
|
-
const out = [`--- a/${path}`, `+++ b/${path}`];
|
|
331
|
-
for (let h = 0; h < hunks.length; h++) {
|
|
332
|
-
const { start, ops: hunkOps } = hunks[h];
|
|
333
|
-
let oldCount = 0;
|
|
334
|
-
let newCount = 0;
|
|
335
|
-
for (let k = 0; k < start; k++) {
|
|
336
|
-
if (ops[k].type !== "insert") oldCount++;
|
|
337
|
-
if (ops[k].type !== "delete") newCount++;
|
|
338
|
-
}
|
|
339
|
-
let dels = 0;
|
|
340
|
-
let ins = 0;
|
|
341
|
-
for (const op of hunkOps) {
|
|
342
|
-
if (op.type === "delete") dels++;
|
|
343
|
-
else if (op.type === "insert") ins++;
|
|
344
|
-
else {
|
|
345
|
-
dels++;
|
|
346
|
-
ins++;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
out.push(`@@ -${formatRange(oldCount + 1, dels)} +${formatRange(newCount + 1, ins)} @@`);
|
|
350
|
-
for (const op of hunkOps) {
|
|
351
|
-
const prefix = op.type === "equal" ? " " : op.type === "delete" ? "-" : "+";
|
|
352
|
-
out.push(prefix + op.text);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return out.join("\n") + "\n";
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export {
|
|
359
|
-
serializeCaseArg,
|
|
360
|
-
buildCaseDirective,
|
|
361
|
-
stripGeneratedCaseDirectives,
|
|
362
|
-
insertGeneratedCaseDirectives,
|
|
363
|
-
unifiedDiff
|
|
364
|
-
};
|
package/dist/dts.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { Abs, NudoConstraint } from '@nudojs/core';
|
|
2
|
-
import { a as AnalysisResult, F as FunctionAnalysis } from './analyzer-types-JyJiCt8w.js';
|
|
3
|
-
import '@babel/types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Abs → TS 类型串。有损:pred / 非 lit term 落到 shape 基类型。
|
|
7
|
-
* `typeVars`:term var id → TS 类型参数名(HOF 泛型投影时传入;
|
|
8
|
-
* `any`+var 在此映射下渲染为该参数名,否则 `unknown`)。
|
|
9
|
-
*/
|
|
10
|
-
declare function absToTSType(a: Abs, typeVars?: Map<string, string>): string;
|
|
11
|
-
/**
|
|
12
|
-
* 为单个函数生成 .d.ts 声明行(JSDoc + 单一 widen 主签名)。
|
|
13
|
-
* 有 hof 关系时优先泛型投影(C3.3);否则 case-widen。
|
|
14
|
-
* service 的 generateDts 与 CLI `--dts`(infer/watch)共用本函数,
|
|
15
|
-
* 两条路径输出保持一致。
|
|
16
|
-
*/
|
|
17
|
-
declare function generateFunctionDtsLines(fn: FunctionAnalysis): string[];
|
|
18
|
-
declare function generateDts(result: AnalysisResult): string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Abs → 生态 schema 投影(单向有损)。
|
|
22
|
-
*
|
|
23
|
-
* 优先走 core `absToConstraint`(与 interface/check 同一投影语义),
|
|
24
|
-
* 再转成中间层 SchemaNode;投影失败时退回 shape 尽力提取并记 dropped。
|
|
25
|
-
* Dialect 只负责 Node → 源码字符串;Abs 才是真理源。
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
type SchemaDialect = "zod";
|
|
29
|
-
type SchemaRefinement = {
|
|
30
|
-
kind: "numBound";
|
|
31
|
-
op: "gt" | "ge" | "lt" | "le";
|
|
32
|
-
n: number;
|
|
33
|
-
} | {
|
|
34
|
-
kind: "int";
|
|
35
|
-
} | {
|
|
36
|
-
kind: "strMin";
|
|
37
|
-
n: number;
|
|
38
|
-
} | {
|
|
39
|
-
kind: "strMax";
|
|
40
|
-
n: number;
|
|
41
|
-
};
|
|
42
|
-
type SchemaNode = {
|
|
43
|
-
k: "lit";
|
|
44
|
-
value: string | number | boolean | null | undefined;
|
|
45
|
-
} | {
|
|
46
|
-
k: "prim";
|
|
47
|
-
type: "number" | "string" | "boolean" | "bigint" | "symbol";
|
|
48
|
-
refinements: SchemaRefinement[];
|
|
49
|
-
} | {
|
|
50
|
-
k: "obj";
|
|
51
|
-
slots: Array<{
|
|
52
|
-
key: string;
|
|
53
|
-
node: SchemaNode;
|
|
54
|
-
optional?: boolean;
|
|
55
|
-
}>;
|
|
56
|
-
} | {
|
|
57
|
-
k: "arr";
|
|
58
|
-
element: SchemaNode;
|
|
59
|
-
} | {
|
|
60
|
-
k: "tuple";
|
|
61
|
-
elements: SchemaNode[];
|
|
62
|
-
} | {
|
|
63
|
-
k: "union";
|
|
64
|
-
members: SchemaNode[];
|
|
65
|
-
} | {
|
|
66
|
-
k: "fn";
|
|
67
|
-
} | {
|
|
68
|
-
k: "promise";
|
|
69
|
-
inner: SchemaNode;
|
|
70
|
-
} | {
|
|
71
|
-
k: "brand";
|
|
72
|
-
name: string;
|
|
73
|
-
} | {
|
|
74
|
-
k: "never";
|
|
75
|
-
} | {
|
|
76
|
-
k: "unknown";
|
|
77
|
-
};
|
|
78
|
-
type SchemaProjection = {
|
|
79
|
-
source: string;
|
|
80
|
-
dialect: SchemaDialect;
|
|
81
|
-
dropped: string[];
|
|
82
|
-
};
|
|
83
|
-
/** NudoConstraint → SchemaNode(与 absToConstraint 投影语义对齐) */
|
|
84
|
-
declare function constraintToSchemaNode(c: NudoConstraint): SchemaNode;
|
|
85
|
-
/** Abs → SchemaNode + dropped(优先 core absToConstraint;失败则 shape 尽力) */
|
|
86
|
-
declare function absToSchemaNode(a: Abs): {
|
|
87
|
-
node: SchemaNode;
|
|
88
|
-
dropped: string[];
|
|
89
|
-
};
|
|
90
|
-
declare function schemaNodeToZod(node: SchemaNode): string;
|
|
91
|
-
declare function projectAbsToSchema(a: Abs, opts?: {
|
|
92
|
-
dialect?: SchemaDialect;
|
|
93
|
-
}): SchemaProjection;
|
|
94
|
-
declare function absToSchemaSource(a: Abs, opts?: {
|
|
95
|
-
dialect?: SchemaDialect;
|
|
96
|
-
}): string;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Abs / SchemaNode → Standard Schema v1 运行时模块(单向有损投影)。
|
|
100
|
-
*
|
|
101
|
-
* 产物是零第三方依赖的 TS/JS 模块:每个导出实现 `~standard` Props
|
|
102
|
-
* (version=1, vendor="nudo", validate)。validate 对 SchemaNode 做
|
|
103
|
-
* 结构 + 可表达 refinement 执法;落不了的 pred 不在此假装精确。
|
|
104
|
-
*
|
|
105
|
-
* 协议:https://standardschema.dev —— 运行时互操作出口,不替代 nudo check。
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
type StandardSchemaIssue = {
|
|
109
|
-
message: string;
|
|
110
|
-
path?: ReadonlyArray<PropertyKey>;
|
|
111
|
-
};
|
|
112
|
-
type StandardSchemaResult = {
|
|
113
|
-
value: unknown;
|
|
114
|
-
issues?: undefined;
|
|
115
|
-
} | {
|
|
116
|
-
issues: ReadonlyArray<StandardSchemaIssue>;
|
|
117
|
-
value?: undefined;
|
|
118
|
-
};
|
|
119
|
-
/** SchemaNode 同步校验(生成模块与测试共用语义)。 */
|
|
120
|
-
declare function validateSchemaNode(node: SchemaNode, value: unknown): StandardSchemaResult;
|
|
121
|
-
type StandardSchemaModuleProjection = {
|
|
122
|
-
source: string;
|
|
123
|
-
dropped: string[];
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Abs → Standard Schema v1 模块源码。
|
|
127
|
-
* `exports`:导出名 → Abs(通常是 output / 各参数)。
|
|
128
|
-
*/
|
|
129
|
-
declare function absToStandardSchemaModule(exports: Record<string, Abs>, opts?: {
|
|
130
|
-
banner?: string;
|
|
131
|
-
}): StandardSchemaModuleProjection;
|
|
132
|
-
/** 便捷:单个 Abs → 单导出模块(默认导出名 `schema`)。 */
|
|
133
|
-
declare function absToStandardSchema(a: Abs, opts?: {
|
|
134
|
-
name?: string;
|
|
135
|
-
}): StandardSchemaModuleProjection;
|
|
136
|
-
|
|
137
|
-
/** Abs 指称守卫(设计 §2.7):保留 pred */
|
|
138
|
-
declare function generateGuardFunctionFromAbs(name: string, abs: Abs): string;
|
|
139
|
-
/** 兼容别名:Abs 路径唯一 */
|
|
140
|
-
declare function generateGuardFunction(name: string, abs: Abs): string;
|
|
141
|
-
|
|
142
|
-
export { type SchemaDialect, type SchemaNode, type SchemaProjection, type SchemaRefinement, type StandardSchemaIssue, type StandardSchemaModuleProjection, type StandardSchemaResult, absToSchemaNode, absToSchemaSource, absToStandardSchema, absToStandardSchemaModule, absToTSType, constraintToSchemaNode, generateDts, generateFunctionDtsLines, generateGuardFunction, generateGuardFunctionFromAbs, projectAbsToSchema, schemaNodeToZod, validateSchemaNode };
|
package/dist/dts.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
absToSchemaNode,
|
|
3
|
-
absToSchemaSource,
|
|
4
|
-
absToStandardSchema,
|
|
5
|
-
absToStandardSchemaModule,
|
|
6
|
-
absToTSType,
|
|
7
|
-
constraintToSchemaNode,
|
|
8
|
-
generateDts,
|
|
9
|
-
generateFunctionDtsLines,
|
|
10
|
-
generateGuardFunction,
|
|
11
|
-
generateGuardFunctionFromAbs,
|
|
12
|
-
projectAbsToSchema,
|
|
13
|
-
schemaNodeToZod,
|
|
14
|
-
validateSchemaNode
|
|
15
|
-
} from "./chunk-6IZR4ZYJ.js";
|
|
16
|
-
export {
|
|
17
|
-
absToSchemaNode,
|
|
18
|
-
absToSchemaSource,
|
|
19
|
-
absToStandardSchema,
|
|
20
|
-
absToStandardSchemaModule,
|
|
21
|
-
absToTSType,
|
|
22
|
-
constraintToSchemaNode,
|
|
23
|
-
generateDts,
|
|
24
|
-
generateFunctionDtsLines,
|
|
25
|
-
generateGuardFunction,
|
|
26
|
-
generateGuardFunctionFromAbs,
|
|
27
|
-
projectAbsToSchema,
|
|
28
|
-
schemaNodeToZod,
|
|
29
|
-
validateSchemaNode
|
|
30
|
-
};
|