@metaobjectsdev/render 0.8.1 → 0.9.0-rc.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/dist/email-document.d.ts +7 -0
- package/dist/email-document.d.ts.map +1 -0
- package/dist/email-document.js +2 -0
- package/dist/email-document.js.map +1 -0
- package/dist/extract/coerce.d.ts +15 -0
- package/dist/extract/coerce.d.ts.map +1 -0
- package/dist/{recover → extract}/coerce.js +87 -13
- package/dist/extract/coerce.js.map +1 -0
- package/dist/{recover/recover-map.d.ts → extract/extract-map.d.ts} +1 -1
- package/dist/{recover/recover-map.d.ts.map → extract/extract-map.d.ts.map} +1 -1
- package/dist/{recover/recover-map.js → extract/extract-map.js} +3 -3
- package/dist/{recover/recover-map.js.map → extract/extract-map.js.map} +1 -1
- package/dist/extract/extract.d.ts +4 -0
- package/dist/extract/extract.d.ts.map +1 -0
- package/dist/extract/extract.js +157 -0
- package/dist/extract/extract.js.map +1 -0
- package/dist/{recover → extract}/json-forgiving-reader.d.ts.map +1 -1
- package/dist/{recover → extract}/json-forgiving-reader.js +1 -1
- package/dist/{recover → extract}/json-forgiving-reader.js.map +1 -1
- package/dist/{recover → extract}/locate.d.ts.map +1 -1
- package/dist/{recover → extract}/locate.js.map +1 -1
- package/dist/extract/normalize.d.ts +4 -0
- package/dist/extract/normalize.d.ts.map +1 -0
- package/dist/extract/normalize.js +22 -0
- package/dist/extract/normalize.js.map +1 -0
- package/dist/extract/strip.d.ts.map +1 -0
- package/dist/{recover → extract}/strip.js.map +1 -1
- package/dist/extract/types.d.ts +160 -0
- package/dist/extract/types.d.ts.map +1 -0
- package/dist/extract/types.js +221 -0
- package/dist/extract/types.js.map +1 -0
- package/dist/{recover → extract}/xml-forgiving-reader.d.ts.map +1 -1
- package/dist/{recover → extract}/xml-forgiving-reader.js +1 -1
- package/dist/{recover → extract}/xml-forgiving-reader.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/prompt/output-format-renderer.d.ts.map +1 -1
- package/dist/prompt/output-format-renderer.js +113 -59
- package/dist/prompt/output-format-renderer.js.map +1 -1
- package/dist/prompt/output-format-spec.d.ts +1 -1
- package/dist/prompt/prompt-field.d.ts +1 -1
- package/package.json +1 -1
- package/src/email-document.ts +6 -0
- package/src/extract/KNOWN_GAPS.md +59 -0
- package/src/extract/coerce.ts +224 -0
- package/src/{recover/recover-map.ts → extract/extract-map.ts} +2 -2
- package/src/extract/extract.ts +187 -0
- package/src/{recover → extract}/json-forgiving-reader.ts +1 -1
- package/src/extract/normalize.ts +23 -0
- package/src/extract/types.ts +346 -0
- package/src/{recover → extract}/xml-forgiving-reader.ts +1 -1
- package/src/index.ts +17 -11
- package/src/prompt/output-format-renderer.ts +140 -61
- package/src/prompt/output-format-spec.ts +1 -1
- package/src/prompt/prompt-field.ts +1 -1
- package/dist/recover/coerce.d.ts +0 -5
- package/dist/recover/coerce.d.ts.map +0 -1
- package/dist/recover/coerce.js.map +0 -1
- package/dist/recover/recover.d.ts +0 -4
- package/dist/recover/recover.d.ts.map +0 -1
- package/dist/recover/recover.js +0 -115
- package/dist/recover/recover.js.map +0 -1
- package/dist/recover/strip.d.ts.map +0 -1
- package/dist/recover/types.d.ts +0 -117
- package/dist/recover/types.d.ts.map +0 -1
- package/dist/recover/types.js +0 -124
- package/dist/recover/types.js.map +0 -1
- package/src/recover/KNOWN_GAPS.md +0 -35
- package/src/recover/coerce.ts +0 -141
- package/src/recover/recover.ts +0 -146
- package/src/recover/types.ts +0 -217
- /package/dist/{recover → extract}/json-forgiving-reader.d.ts +0 -0
- /package/dist/{recover → extract}/locate.d.ts +0 -0
- /package/dist/{recover → extract}/locate.js +0 -0
- /package/dist/{recover → extract}/strip.d.ts +0 -0
- /package/dist/{recover → extract}/strip.js +0 -0
- /package/dist/{recover → extract}/xml-forgiving-reader.d.ts +0 -0
- /package/src/{recover → extract}/locate.ts +0 -0
- /package/src/{recover → extract}/strip.ts +0 -0
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// the verbatim prose, skeleton shapes, or numeric-vs-quoted decision.
|
|
11
11
|
|
|
12
12
|
import { ESCAPERS } from "../escapers.js";
|
|
13
|
-
import { FieldKind, Format } from "../
|
|
13
|
+
import { FieldKind, Format } from "../extract/types.js";
|
|
14
14
|
import type { OutputFormatSpec } from "./output-format-spec.js";
|
|
15
15
|
import type { PromptField } from "./prompt-field.js";
|
|
16
16
|
import type { PromptOverrides } from "./prompt-overrides.js";
|
|
@@ -23,6 +23,11 @@ const NUMERIC_KINDS: ReadonlySet<FieldKind> = new Set<FieldKind>([
|
|
|
23
23
|
FieldKind.BOOLEAN,
|
|
24
24
|
]);
|
|
25
25
|
|
|
26
|
+
const INDENT = " ";
|
|
27
|
+
const MAX_NEST_DEPTH = 8;
|
|
28
|
+
|
|
29
|
+
type SkelMode = "example" | "inline";
|
|
30
|
+
|
|
26
31
|
// The render engine OWNS format-keyed escaping; Format ("JSON"/"XML") maps to the
|
|
27
32
|
// lowercase ESCAPERS keys.
|
|
28
33
|
const escapeXml = (s: string): string => ESCAPERS.xml(s);
|
|
@@ -48,24 +53,8 @@ export function renderOutputFormat(spec: OutputFormatSpec, overrides: PromptOver
|
|
|
48
53
|
|
|
49
54
|
function renderInline(spec: OutputFormatSpec, overrides: PromptOverrides): string {
|
|
50
55
|
return spec.format === Format.XML
|
|
51
|
-
?
|
|
52
|
-
:
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function renderXmlInline(spec: OutputFormatSpec, overrides: PromptOverrides): string {
|
|
56
|
-
const lines = spec.fields.map((field) => {
|
|
57
|
-
const escaped = escapeXml(inlineContent(field, overrides));
|
|
58
|
-
return ` <${field.name}>${escaped}</${field.name}>\n`;
|
|
59
|
-
});
|
|
60
|
-
return `<${spec.rootName}>\n${lines.join("")}</${spec.rootName}>`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function renderJsonInline(spec: OutputFormatSpec, overrides: PromptOverrides): string {
|
|
64
|
-
const lines = spec.fields.map(
|
|
65
|
-
(field) => ` "${field.name}": "${escapeJson(inlineContent(field, overrides))}"`,
|
|
66
|
-
);
|
|
67
|
-
// Empty object is `{\n}` (Java/C# parity), not `{\n\n}` from join("") on no lines.
|
|
68
|
-
return spec.fields.length === 0 ? "{\n}" : `{\n${lines.join(",\n")}\n}`;
|
|
56
|
+
? renderXmlSkeleton(spec, overrides, "inline")
|
|
57
|
+
: renderJsonSkeleton(spec, overrides, "inline");
|
|
69
58
|
}
|
|
70
59
|
|
|
71
60
|
function inlineContent(field: PromptField, overrides: PromptOverrides): string {
|
|
@@ -90,33 +79,49 @@ function resolveInstruction(field: PromptField, overrides: PromptOverrides): str
|
|
|
90
79
|
|
|
91
80
|
function renderGuide(spec: OutputFormatSpec, overrides: PromptOverrides): string {
|
|
92
81
|
let sb = "Fill in each field as described below:\n";
|
|
82
|
+
sb += guideFields(spec, overrides, "", new Set<OutputFormatSpec>([spec]), 0);
|
|
83
|
+
sb += "\nRespond exactly like this:\n";
|
|
84
|
+
sb += renderExampleOnly(spec, overrides);
|
|
85
|
+
return sb;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function guideFields(
|
|
89
|
+
spec: OutputFormatSpec, overrides: PromptOverrides, prefix: string,
|
|
90
|
+
path: Set<OutputFormatSpec>, depth: number,
|
|
91
|
+
): string {
|
|
92
|
+
let sb = "";
|
|
93
93
|
for (const field of spec.fields) {
|
|
94
|
-
const
|
|
95
|
-
sb +=
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
const displayName = prefix + field.name;
|
|
95
|
+
sb += guideEntry(field, overrides, displayName);
|
|
96
|
+
if (canExpand(field, path, depth)) {
|
|
97
|
+
const nested = field.nested!;
|
|
98
|
+
const childPrefix = field.array ? `${displayName}[].` : `${displayName}.`;
|
|
99
|
+
path.add(nested);
|
|
100
|
+
sb += guideFields(nested, overrides, childPrefix, path, depth + 1);
|
|
101
|
+
path.delete(nested);
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
}
|
|
104
|
+
return sb;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function guideEntry(field: PromptField, overrides: PromptOverrides, displayName: string): string {
|
|
108
|
+
const req = field.required ? "required" : "optional";
|
|
109
|
+
let sb = `- ${displayName} (${req})`;
|
|
110
|
+
const instruction = resolveInstruction(field, overrides);
|
|
111
|
+
if (instruction != null) sb += `: ${instruction}`;
|
|
112
|
+
sb += "\n";
|
|
113
|
+
if (field.kind === FieldKind.ENUM && field.enumValues != null && field.enumValues.length > 0) {
|
|
114
|
+
sb += ` one of ${field.enumValues.join(", ")}\n`;
|
|
115
|
+
const enumDoc = field.enumDoc;
|
|
116
|
+
if (enumDoc != null) {
|
|
117
|
+
for (const val of field.enumValues) {
|
|
118
|
+
const doc = enumDoc[val];
|
|
119
|
+
if (doc != null) sb += ` ${val} = ${doc}\n`;
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
|
-
const eg = exampleValueIfDeclared(field, overrides);
|
|
114
|
-
if (eg != null) {
|
|
115
|
-
sb += ` e.g. ${eg}\n`;
|
|
116
|
-
}
|
|
117
122
|
}
|
|
118
|
-
|
|
119
|
-
sb +=
|
|
123
|
+
const eg = exampleValueIfDeclared(field, overrides);
|
|
124
|
+
if (eg != null) sb += ` e.g. ${eg}\n`;
|
|
120
125
|
return sb;
|
|
121
126
|
}
|
|
122
127
|
|
|
@@ -124,29 +129,103 @@ function renderGuide(spec: OutputFormatSpec, overrides: PromptOverrides): string
|
|
|
124
129
|
|
|
125
130
|
function renderExampleOnly(spec: OutputFormatSpec, overrides: PromptOverrides): string {
|
|
126
131
|
return spec.format === Format.XML
|
|
127
|
-
? renderXmlSkeleton(spec, overrides)
|
|
128
|
-
: renderJsonSkeleton(spec, overrides);
|
|
132
|
+
? renderXmlSkeleton(spec, overrides, "example")
|
|
133
|
+
: renderJsonSkeleton(spec, overrides, "example");
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
// ---- JSON skeleton (recursive) ---------------------------------------------
|
|
137
|
+
|
|
138
|
+
function renderJsonSkeleton(spec: OutputFormatSpec, overrides: PromptOverrides, mode: SkelMode): string {
|
|
139
|
+
return jsonObject(spec, overrides, "", mode, new Set<OutputFormatSpec>([spec]), 0);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function jsonObject(
|
|
143
|
+
spec: OutputFormatSpec, overrides: PromptOverrides, braceIndent: string,
|
|
144
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
145
|
+
): string {
|
|
146
|
+
if (spec.fields.length === 0) return `{\n${braceIndent}}`;
|
|
147
|
+
const fieldIndent = braceIndent + INDENT;
|
|
148
|
+
const lines = spec.fields.map(
|
|
149
|
+
(field) => `${fieldIndent}"${field.name}": ${jsonValue(field, overrides, fieldIndent, mode, path, depth)}`,
|
|
150
|
+
);
|
|
151
|
+
return `{\n${lines.join(",\n")}\n${braceIndent}}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function jsonValue(
|
|
155
|
+
field: PromptField, overrides: PromptOverrides, indent: string,
|
|
156
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
157
|
+
): string {
|
|
158
|
+
if (field.array) return jsonArray(field, overrides, indent, mode, path, depth);
|
|
159
|
+
if (field.kind === FieldKind.OBJECT) return jsonObjectField(field, overrides, indent, mode, path, depth);
|
|
160
|
+
return jsonLeaf(field, overrides, mode);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function jsonLeaf(field: PromptField, overrides: PromptOverrides, mode: SkelMode): string {
|
|
164
|
+
if (mode === "inline") return `"${escapeJson(inlineContent(field, overrides))}"`;
|
|
165
|
+
const value = exampleValue(field, overrides);
|
|
166
|
+
return isNumericOrBoolean(field.kind, value) ? value : `"${escapeJson(value)}"`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function canExpand(field: PromptField, path: Set<OutputFormatSpec>, depth: number): boolean {
|
|
170
|
+
return field.kind === FieldKind.OBJECT && field.nested != null
|
|
171
|
+
&& depth < MAX_NEST_DEPTH && !path.has(field.nested);
|
|
137
172
|
}
|
|
138
173
|
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
174
|
+
function jsonObjectField(
|
|
175
|
+
field: PromptField, overrides: PromptOverrides, indent: string,
|
|
176
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
177
|
+
): string {
|
|
178
|
+
if (!canExpand(field, path, depth)) return jsonLeaf(field, overrides, mode);
|
|
179
|
+
const nested = field.nested!;
|
|
180
|
+
path.add(nested);
|
|
181
|
+
const out = jsonObject(nested, overrides, indent, mode, path, depth + 1);
|
|
182
|
+
path.delete(nested);
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function jsonArray(
|
|
187
|
+
field: PromptField, overrides: PromptOverrides, indent: string,
|
|
188
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
189
|
+
): string {
|
|
190
|
+
const elemIndent = indent + INDENT;
|
|
191
|
+
let elem: string;
|
|
192
|
+
if (canExpand(field, path, depth)) {
|
|
193
|
+
const nested = field.nested!;
|
|
194
|
+
path.add(nested);
|
|
195
|
+
elem = jsonObject(nested, overrides, elemIndent, mode, path, depth + 1);
|
|
196
|
+
path.delete(nested);
|
|
197
|
+
} else {
|
|
198
|
+
elem = jsonLeaf(field, overrides, mode);
|
|
199
|
+
}
|
|
200
|
+
return `[\n${elemIndent}${elem}\n${indent}]`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---- XML skeleton (recursive) ----------------------------------------------
|
|
204
|
+
|
|
205
|
+
function renderXmlSkeleton(spec: OutputFormatSpec, overrides: PromptOverrides, mode: SkelMode): string {
|
|
206
|
+
return `<${spec.rootName}>\n${xmlBody(spec, overrides, INDENT, mode, new Set<OutputFormatSpec>([spec]), 0)}</${spec.rootName}>`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function xmlBody(
|
|
210
|
+
spec: OutputFormatSpec, overrides: PromptOverrides, indent: string,
|
|
211
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
212
|
+
): string {
|
|
213
|
+
return spec.fields.map((field) => xmlField(field, overrides, indent, mode, path, depth)).join("");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function xmlField(
|
|
217
|
+
field: PromptField, overrides: PromptOverrides, indent: string,
|
|
218
|
+
mode: SkelMode, path: Set<OutputFormatSpec>, depth: number,
|
|
219
|
+
): string {
|
|
220
|
+
if (canExpand(field, path, depth)) {
|
|
221
|
+
const nested = field.nested!;
|
|
222
|
+
path.add(nested);
|
|
223
|
+
const body = xmlBody(nested, overrides, indent + INDENT, mode, path, depth + 1);
|
|
224
|
+
path.delete(nested);
|
|
225
|
+
return `${indent}<${field.name}>\n${body}${indent}</${field.name}>\n`;
|
|
226
|
+
}
|
|
227
|
+
const content = mode === "inline" ? inlineContent(field, overrides) : exampleValue(field, overrides);
|
|
228
|
+
return `${indent}<${field.name}>${escapeXml(content)}</${field.name}>\n`;
|
|
150
229
|
}
|
|
151
230
|
|
|
152
231
|
function exampleValueIfDeclared(field: PromptField, overrides: PromptOverrides): string | null {
|
|
@@ -172,7 +251,7 @@ function isNumericOrBoolean(kind: FieldKind, value: string): boolean {
|
|
|
172
251
|
// Finite-only: NaN/Infinity fall through to a quoted string so the emitted JSON
|
|
173
252
|
// stays valid. Number("") is 0, so guard the empty/blank case explicitly. Reject
|
|
174
253
|
// JS-only radix literals (0x../0b../0o..) that Number() accepts but Java/C# don't —
|
|
175
|
-
// same guard as the
|
|
254
|
+
// same guard as the extract engine's parseFiniteNumber (keeps the JSON valid + parity).
|
|
176
255
|
const t = value.trim();
|
|
177
256
|
if (t === "" || /^[+-]?0[xXbBoO]/.test(t)) return false;
|
|
178
257
|
return Number.isFinite(Number(t));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// FR-010 artifact 1 — a complete output-format descriptor.
|
|
2
2
|
|
|
3
|
-
import type { Format } from "../
|
|
3
|
+
import type { Format } from "../extract/types.js";
|
|
4
4
|
import type { PromptField } from "./prompt-field.js";
|
|
5
5
|
import type { PromptStyle } from "./prompt-style.js";
|
|
6
6
|
|
package/dist/recover/coerce.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { FieldSpec, RecoverOptions, RecoveryReport } from "./types.js";
|
|
2
|
-
/** Sentinel: the value was present but could not be coerced to the declared kind/vocabulary. */
|
|
3
|
-
export declare const MALFORMED: unique symbol;
|
|
4
|
-
export declare function coerceValue(raw: string | null, spec: FieldSpec, opts: RecoverOptions, fieldPath: string, report: RecoveryReport): unknown | typeof MALFORMED;
|
|
5
|
-
//# sourceMappingURL=coerce.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../src/recover/coerce.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E,gGAAgG;AAChG,eAAO,MAAM,SAAS,EAAE,OAAO,MAA2C,CAAC;AAE3E,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,cAAc,EACpB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,cAAc,GACrB,OAAO,GAAG,OAAO,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E,OAAO,EAAE,CAAC,CAAC;IAC1G,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,UAAU,CAAC,GAAW,EAAE,EAAW;IAC1C,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,MAAM,CAAC;QACZ,KAAK,KAAK,CAAC;QACX,KAAK,GAAG;YACN,OAAO,IAAI,CAAC;QACd,KAAK,OAAO,CAAC;QACb,KAAK,IAAI,CAAC;QACV,KAAK,GAAG;YACN,OAAO,KAAK,CAAC;QACf;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,SAAS,CAAC,CAAU;IAC3B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RecoverOptions, RecoverOutcome, RecoverSchema } from "./types.js";
|
|
2
|
-
/** The forgiving entry point: recover dirty `text` against `schema`. Never throws. */
|
|
3
|
-
export declare function recover(text: string | null | undefined, schema: RecoverSchema, opts?: Partial<RecoverOptions> | null): RecoverOutcome;
|
|
4
|
-
//# sourceMappingURL=recover.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/recover/recover.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAa,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQ3F,sFAAsF;AACtF,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,MAAM,EAAE,aAAa,EACrB,IAAI,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,GACpC,cAAc,CA0BhB"}
|
package/dist/recover/recover.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Public entry point. Runs the staged pipeline; NEVER throws. Mirrors Java Recover.
|
|
2
|
-
import { Format, FieldKind, FieldRecovery, Tolerance, normalizeOptions, } from "./types.js";
|
|
3
|
-
import { RecoveryReport } from "./types.js";
|
|
4
|
-
import { strip } from "./strip.js";
|
|
5
|
-
import { locateJson, locateXml } from "./locate.js";
|
|
6
|
-
import { readJson, TRUNCATED } from "./json-forgiving-reader.js";
|
|
7
|
-
import { readXml } from "./xml-forgiving-reader.js";
|
|
8
|
-
import { coerceValue, MALFORMED } from "./coerce.js";
|
|
9
|
-
/** The forgiving entry point: recover dirty `text` against `schema`. Never throws. */
|
|
10
|
-
export function recover(text, schema, opts) {
|
|
11
|
-
const o = normalizeOptions(opts);
|
|
12
|
-
const report = new RecoveryReport();
|
|
13
|
-
const data = {};
|
|
14
|
-
const stripped = strip(text);
|
|
15
|
-
const ci = o.tolerance !== Tolerance.STRICT;
|
|
16
|
-
const span = schema.format === Format.JSON ? locateJson(stripped) : locateXml(stripped, schema.rootName, ci);
|
|
17
|
-
let raw;
|
|
18
|
-
if (span == null) {
|
|
19
|
-
raw = {};
|
|
20
|
-
}
|
|
21
|
-
else if (schema.format === Format.JSON) {
|
|
22
|
-
raw = readJson(span);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
raw = readXml(span, ci);
|
|
26
|
-
}
|
|
27
|
-
if (isEmptyRecord(raw) && (stripped.length === 0 || span == null)) {
|
|
28
|
-
report.markEmpty();
|
|
29
|
-
}
|
|
30
|
-
extract(schema.fields, raw, "", data, report, o, ci);
|
|
31
|
-
return { data, report };
|
|
32
|
-
}
|
|
33
|
-
function extract(fields, raw, prefix, data, report, o, ci) {
|
|
34
|
-
for (const f of fields) {
|
|
35
|
-
const path = prefix.length === 0 ? f.name : `${prefix}.${f.name}`;
|
|
36
|
-
const present = lookup(raw, f.name, ci);
|
|
37
|
-
if (present === undefined) {
|
|
38
|
-
report.set(path, f.required ? FieldRecovery.LOST_REQUIRED : FieldRecovery.LOST_OPTIONAL);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (present === TRUNCATED) {
|
|
42
|
-
// present-but-garbled (empty/cut-off value)
|
|
43
|
-
report.set(path, FieldRecovery.MALFORMED);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (f.array) {
|
|
47
|
-
// An array field: a single non-list value is treated as a one-element array
|
|
48
|
-
// (e.g. a single repeated-XML tag). Each element is coerced/recursed independently.
|
|
49
|
-
const elements = Array.isArray(present) ? present : [present];
|
|
50
|
-
const out = [];
|
|
51
|
-
let anyMalformed = false;
|
|
52
|
-
for (let idx = 0; idx < elements.length; idx++) {
|
|
53
|
-
const v = extractValue(f, elements[idx], `${path}[${idx}]`, report, o, ci);
|
|
54
|
-
if (v === MALFORMED)
|
|
55
|
-
anyMalformed = true;
|
|
56
|
-
else
|
|
57
|
-
out.push(v);
|
|
58
|
-
}
|
|
59
|
-
// Cross-port contract: a MALFORMED array still places its successfully-coerced
|
|
60
|
-
// elements into data (partial recovery), UNLIKE a MALFORMED scalar which is absent.
|
|
61
|
-
data[f.name] = out;
|
|
62
|
-
report.set(path, anyMalformed ? FieldRecovery.MALFORMED : FieldRecovery.RECOVERED);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(present)) {
|
|
66
|
-
// a list where a singular value was expected
|
|
67
|
-
report.set(path, FieldRecovery.MALFORMED);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const v = extractValue(f, present, path, report, o, ci);
|
|
71
|
-
if (v === MALFORMED) {
|
|
72
|
-
report.set(path, FieldRecovery.MALFORMED);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
data[f.name] = v;
|
|
76
|
-
report.set(path, FieldRecovery.RECOVERED);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/** Coerce one (non-array) element: nested-object recursion or scalar coercion. Returns MALFORMED on failure. */
|
|
81
|
-
function extractValue(f, present, path, report, o, ci) {
|
|
82
|
-
if (f.kind === FieldKind.OBJECT) {
|
|
83
|
-
if (f.nested != null && isPlainObject(present)) {
|
|
84
|
-
const nestedData = {};
|
|
85
|
-
extract(f.nested.fields, present, path, nestedData, report, o, ci);
|
|
86
|
-
return nestedData;
|
|
87
|
-
}
|
|
88
|
-
return MALFORMED; // object expected but scalar/non-map present
|
|
89
|
-
}
|
|
90
|
-
const rawStr = typeof present === "string" ? present : stringifyScalar(present);
|
|
91
|
-
return coerceValue(rawStr, f, o, path, report);
|
|
92
|
-
}
|
|
93
|
-
/** Case-folding lookup honoring tolerance. Returns `undefined` for absent (mirrors Java null). */
|
|
94
|
-
function lookup(raw, name, ci) {
|
|
95
|
-
if (Object.prototype.hasOwnProperty.call(raw, name))
|
|
96
|
-
return raw[name];
|
|
97
|
-
if (ci) {
|
|
98
|
-
const lower = name.toLowerCase();
|
|
99
|
-
for (const k of Object.keys(raw))
|
|
100
|
-
if (k.toLowerCase() === lower)
|
|
101
|
-
return raw[k];
|
|
102
|
-
}
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
function isPlainObject(o) {
|
|
106
|
-
return typeof o === "object" && o !== null && !Array.isArray(o);
|
|
107
|
-
}
|
|
108
|
-
function isEmptyRecord(o) {
|
|
109
|
-
return Object.keys(o).length === 0;
|
|
110
|
-
}
|
|
111
|
-
/** Mirror Java String.valueOf for non-string forgiving-reader scalars. */
|
|
112
|
-
function stringifyScalar(v) {
|
|
113
|
-
return String(v);
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=recover.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recover.js","sourceRoot":"","sources":["../../src/recover/recover.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,OAAO,EACL,MAAM,EACN,SAAS,EACT,aAAa,EACb,SAAS,EACT,gBAAgB,GACjB,MAAM,Y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CAAC,WAAW,EAAE,KAAK,KAAK;gBAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,CAA0B;IAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,0EAA0E;AAC1E,SAAS,eAAe,CAAC,CAAU;IACjC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../../src/recover/strip.ts"],"names":[],"mappings":"AAMA,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAU5D"}
|
package/dist/recover/types.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/** Output format the dirty text claims to be. Corpus schema.json uses "JSON"/"XML". */
|
|
2
|
-
export declare const Format: {
|
|
3
|
-
readonly JSON: "JSON";
|
|
4
|
-
readonly XML: "XML";
|
|
5
|
-
};
|
|
6
|
-
export type Format = (typeof Format)[keyof typeof Format];
|
|
7
|
-
/** The coercion target kinds the engine understands. OBJECT = nested RecoverSchema. */
|
|
8
|
-
export declare const FieldKind: {
|
|
9
|
-
readonly STRING: "STRING";
|
|
10
|
-
readonly INT: "INT";
|
|
11
|
-
readonly LONG: "LONG";
|
|
12
|
-
readonly DOUBLE: "DOUBLE";
|
|
13
|
-
readonly BOOLEAN: "BOOLEAN";
|
|
14
|
-
readonly ENUM: "ENUM";
|
|
15
|
-
readonly OBJECT: "OBJECT";
|
|
16
|
-
};
|
|
17
|
-
export type FieldKind = (typeof FieldKind)[keyof typeof FieldKind];
|
|
18
|
-
/**
|
|
19
|
-
* FROZEN cross-port per-field recovery classification. Do not reorder or add
|
|
20
|
-
* without an ADR. These string values are SERIALIZED in the conformance corpus.
|
|
21
|
-
*/
|
|
22
|
-
export declare const FieldRecovery: {
|
|
23
|
-
readonly RECOVERED: "RECOVERED";
|
|
24
|
-
readonly DEFAULTED: "DEFAULTED";
|
|
25
|
-
readonly LOST_OPTIONAL: "LOST_OPTIONAL";
|
|
26
|
-
readonly LOST_REQUIRED: "LOST_REQUIRED";
|
|
27
|
-
readonly MALFORMED: "MALFORMED";
|
|
28
|
-
};
|
|
29
|
-
export type FieldRecovery = (typeof FieldRecovery)[keyof typeof FieldRecovery];
|
|
30
|
-
/**
|
|
31
|
-
* STRICT: case-sensitive, minimal repair. NORMAL: case-insensitive keys/tags
|
|
32
|
-
* (default). LOOSE: maximal repair (currently identical to NORMAL — reserved).
|
|
33
|
-
*/
|
|
34
|
-
export declare const Tolerance: {
|
|
35
|
-
readonly STRICT: "STRICT";
|
|
36
|
-
readonly NORMAL: "NORMAL";
|
|
37
|
-
readonly LOOSE: "LOOSE";
|
|
38
|
-
};
|
|
39
|
-
export type Tolerance = (typeof Tolerance)[keyof typeof Tolerance];
|
|
40
|
-
/** A recorded normalization/coercion. kind e.g. "alias", "clamp", "case", "runtime-alias-override". */
|
|
41
|
-
export interface Coercion {
|
|
42
|
-
readonly fieldPath: string;
|
|
43
|
-
readonly from: string;
|
|
44
|
-
readonly to: string;
|
|
45
|
-
readonly kind: string;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* One field's recover descriptor. enumValues/enumAlias non-null only for ENUM;
|
|
49
|
-
* min/max non-null only for numeric range constraints; nested non-null only for OBJECT.
|
|
50
|
-
*/
|
|
51
|
-
export interface FieldSpec {
|
|
52
|
-
readonly name: string;
|
|
53
|
-
readonly kind: FieldKind;
|
|
54
|
-
readonly required: boolean;
|
|
55
|
-
readonly array: boolean;
|
|
56
|
-
readonly enumValues: readonly string[] | null;
|
|
57
|
-
readonly enumAlias: Readonly<Record<string, string>> | null;
|
|
58
|
-
readonly min: number | null;
|
|
59
|
-
readonly max: number | null;
|
|
60
|
-
readonly nested: RecoverSchema | null;
|
|
61
|
-
}
|
|
62
|
-
export declare function scalar(name: string, kind: FieldKind, required: boolean): FieldSpec;
|
|
63
|
-
export declare function enumField(name: string, required: boolean, values: readonly string[] | null, aliases: Readonly<Record<string, string>> | null): FieldSpec;
|
|
64
|
-
export declare function range(name: string, kind: FieldKind, required: boolean, min: number | null, max: number | null): FieldSpec;
|
|
65
|
-
export declare function object(name: string, required: boolean, array: boolean, nested: RecoverSchema | null): FieldSpec;
|
|
66
|
-
/** Top-level recover descriptor. rootName = the XML root tag / logical JSON root name. */
|
|
67
|
-
export interface RecoverSchema {
|
|
68
|
-
readonly format: Format;
|
|
69
|
-
readonly rootName: string;
|
|
70
|
-
readonly fields: readonly FieldSpec[];
|
|
71
|
-
}
|
|
72
|
-
export declare function recoverSchema(format: Format, rootName: string, fields: readonly FieldSpec[] | null): RecoverSchema;
|
|
73
|
-
/**
|
|
74
|
-
* ctx carries the field path and the FieldSpec; return null to fall through to
|
|
75
|
-
* default coercion. The single bespoke-coercion hook (the bounded "20%").
|
|
76
|
-
*/
|
|
77
|
-
export type OnField = (fieldPath: string, rawValue: string, spec: FieldSpec) => unknown | null;
|
|
78
|
-
/**
|
|
79
|
-
* Bounded runtime override surface. aliases/normalizers are MERGED with the
|
|
80
|
-
* schema's, runtime winning on key conflict. onField is the single hook.
|
|
81
|
-
*/
|
|
82
|
-
export interface RecoverOptions {
|
|
83
|
-
readonly tolerance: Tolerance;
|
|
84
|
-
readonly aliases: Readonly<Record<string, string>>;
|
|
85
|
-
readonly normalizers: Readonly<Record<string, (raw: string) => unknown | null>>;
|
|
86
|
-
readonly onField: OnField | null;
|
|
87
|
-
}
|
|
88
|
-
export declare function defaults(): RecoverOptions;
|
|
89
|
-
/** Normalize a partial / undefined options bag into a complete RecoverOptions. */
|
|
90
|
-
export declare function normalizeOptions(opts?: Partial<RecoverOptions> | null): RecoverOptions;
|
|
91
|
-
/** Engine return. data is a forgiving record; Phase-2 codegen wraps it into a typed RecoveryResult<T>. */
|
|
92
|
-
export interface RecoverOutcome {
|
|
93
|
-
readonly data: Record<string, unknown>;
|
|
94
|
-
readonly report: RecoveryReport;
|
|
95
|
-
}
|
|
96
|
-
/** Typed result of a generated recover(...): best-effort value (null where lost/malformed) + report. */
|
|
97
|
-
export interface RecoveryResult<T> {
|
|
98
|
-
readonly data: T | null;
|
|
99
|
-
readonly report: RecoveryReport;
|
|
100
|
-
}
|
|
101
|
-
/** Mutable accumulator of per-field recovery classification, the degenerate-response flag, and coercion notes. */
|
|
102
|
-
export declare class RecoveryReport {
|
|
103
|
-
private readonly _states;
|
|
104
|
-
private readonly _coercions;
|
|
105
|
-
private _empty;
|
|
106
|
-
set(fieldPath: string, state: FieldRecovery): void;
|
|
107
|
-
addCoercion(c: Coercion): void;
|
|
108
|
-
markEmpty(): void;
|
|
109
|
-
isEmpty(): boolean;
|
|
110
|
-
states(): ReadonlyMap<string, FieldRecovery>;
|
|
111
|
-
coercions(): readonly Coercion[];
|
|
112
|
-
lostRequired(): string[];
|
|
113
|
-
malformed(): string[];
|
|
114
|
-
hasLostRequired(): boolean;
|
|
115
|
-
private byState;
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/recover/types.ts"],"names":[],"mappings":"AAQA,uFAAuF;AACvF,eAAO,MAAM,MAAM;;;CAGT,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAE1D,uFAAuF;AACvF,eAAO,MAAM,SAAS;;;;;;;;CAQZ,CAAC;AACX,MAAM,MA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