@nudojs/service 3.0.0 → 5.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ // src/case-json.ts
2
+ import { formatAbs, formatShape } from "@nudojs/core";
3
+ function mapCase(c) {
4
+ const out = {
5
+ name: c.name,
6
+ args: c.argAbs.map((a) => formatShape(a)),
7
+ result: formatShape(c.abs),
8
+ throws: c.throwsAbs.shape.k !== "never" ? formatShape(c.throwsAbs) : null,
9
+ source: c.source ?? null
10
+ };
11
+ if (c.aggregatedFrom !== void 0) out.aggregatedFrom = c.aggregatedFrom;
12
+ if (c.argAbs.length > 0) {
13
+ out.argsAbs = c.argAbs.map((a) => {
14
+ try {
15
+ return formatAbs(a);
16
+ } catch {
17
+ return "unknown";
18
+ }
19
+ });
20
+ }
21
+ try {
22
+ out.resultAbs = formatAbs(c.abs);
23
+ } catch {
24
+ }
25
+ if (c.intension) {
26
+ const i = c.intension;
27
+ out.intension = {
28
+ ...i.display !== void 0 ? { display: i.display } : {},
29
+ ...i.abs !== void 0 ? { abs: i.abs } : {},
30
+ ...i.absMultiline !== void 0 ? { absMultiline: i.absMultiline } : {},
31
+ ...i.term !== void 0 ? { term: i.term } : {},
32
+ ...i.pred !== void 0 ? { pred: i.pred } : {},
33
+ ...i.conf !== void 0 ? { conf: i.conf } : {}
34
+ };
35
+ }
36
+ return out;
37
+ }
38
+ function mapFunction(f) {
39
+ const out = {
40
+ name: f.name,
41
+ loc: f.loc,
42
+ entryOnly: f.entryOnly ?? false,
43
+ cases: f.cases.map(mapCase)
44
+ };
45
+ if (f.noDeclaration) out.noDeclaration = true;
46
+ if (f.combinedAbs) {
47
+ out.combined = formatShape(f.combinedAbs);
48
+ try {
49
+ out.combinedAbs = formatAbs(f.combinedAbs);
50
+ } catch {
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+ function serializeCaseJson(result, file) {
56
+ const functions = result.functions.map(mapFunction);
57
+ const external = result.externalFunctions?.map((f) => ({
58
+ name: f.name,
59
+ fromModule: f.fromModule,
60
+ cases: f.cases.map(mapCase)
61
+ }));
62
+ const caseCount = functions.reduce((n, f) => n + f.cases.length, 0) + (external ?? []).reduce((n, f) => n + f.cases.length, 0);
63
+ const json = {
64
+ version: 1,
65
+ file,
66
+ summary: {
67
+ functions: functions.length,
68
+ externalFunctions: external?.length ?? 0,
69
+ cases: caseCount,
70
+ diagnostics: result.diagnostics.length
71
+ },
72
+ functions,
73
+ diagnostics: result.diagnostics.map((d) => ({
74
+ range: d.range,
75
+ severity: d.severity,
76
+ message: d.message,
77
+ ...d.code !== void 0 ? { code: d.code } : {},
78
+ ...d.suggestions ? { suggestions: d.suggestions } : {},
79
+ ...d.tags ? { tags: d.tags } : {},
80
+ ...d.origin ? { origin: d.origin } : {}
81
+ }))
82
+ };
83
+ if (external) json.externalFunctions = external;
84
+ return json;
85
+ }
86
+
87
+ export {
88
+ serializeCaseJson
89
+ };