@isdk/json-repair 0.2.0 → 0.3.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.
- package/CHANGELOG.md +90 -0
- package/README.cn.md +24 -9
- package/README.md +40 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +269 -49
- package/dist/index.d.ts +269 -49
- package/dist/index.js +1 -1
- package/package.json +6 -5
- package/docs/README.md +0 -387
- package/docs/_media/README.cn.md +0 -333
- package/docs/classes/RepairParser.md +0 -130
- package/docs/classes/SchemaWalker.md +0 -241
- package/docs/functions/compareScores.md +0 -32
- package/docs/functions/discardedText.md +0 -42
- package/docs/functions/expectsArrayRoot.md +0 -23
- package/docs/functions/findImplicitRecordRegion.md +0 -32
- package/docs/functions/jsonRepair.md +0 -49
- package/docs/functions/jsonRepairResult.md +0 -50
- package/docs/functions/locateJsonCandidates.md +0 -33
- package/docs/functions/looksLikeSchemaEcho.md +0 -29
- package/docs/functions/renderValidatorErrors.md +0 -32
- package/docs/functions/scoreCandidate.md +0 -45
- package/docs/functions/validateValue.md +0 -38
- package/docs/globals.md +0 -43
- package/docs/interfaces/CandidateScore.md +0 -63
- package/docs/interfaces/JsonCandidate.md +0 -71
- package/docs/interfaces/LocatedJson.md +0 -48
- package/docs/interfaces/RepairOptions.md +0 -301
- package/docs/interfaces/RepairResult.md +0 -58
- package/docs/interfaces/ValidationError.md +0 -27
- package/docs/type-aliases/CommentStyle.md +0 -13
- package/docs/type-aliases/EscapeMode.md +0 -13
- package/docs/type-aliases/JSONPath.md +0 -14
- package/docs/type-aliases/LiteralDialect.md +0 -13
- package/docs/type-aliases/RepairFlag.md +0 -11
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / SchemaWalker
|
|
6
|
-
|
|
7
|
-
# Class: SchemaWalker
|
|
8
|
-
|
|
9
|
-
Defined in: [walker/schema-walker.ts:9](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L9)
|
|
10
|
-
|
|
11
|
-
Navigates through a JSON Schema based on a JSON Path.
|
|
12
|
-
Handles $ref resolution and provides type information for specific paths.
|
|
13
|
-
|
|
14
|
-
## Methods
|
|
15
|
-
|
|
16
|
-
### declaredPropertyNames()
|
|
17
|
-
|
|
18
|
-
> **declaredPropertyNames**(`path`): `string`[]
|
|
19
|
-
|
|
20
|
-
Defined in: [walker/schema-walker.ts:129](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L129)
|
|
21
|
-
|
|
22
|
-
The property names the Schema declares at `path` (empty when the level is free-form).
|
|
23
|
-
|
|
24
|
-
#### Parameters
|
|
25
|
-
|
|
26
|
-
##### path
|
|
27
|
-
|
|
28
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
29
|
-
|
|
30
|
-
#### Returns
|
|
31
|
-
|
|
32
|
-
`string`[]
|
|
33
|
-
|
|
34
|
-
***
|
|
35
|
-
|
|
36
|
-
### getExpectedTypes()
|
|
37
|
-
|
|
38
|
-
> **getExpectedTypes**(`path`, `key`): `string`[]
|
|
39
|
-
|
|
40
|
-
Defined in: [walker/schema-walker.ts:175](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L175)
|
|
41
|
-
|
|
42
|
-
Gets the expected types for a specific property at a given path.
|
|
43
|
-
|
|
44
|
-
#### Parameters
|
|
45
|
-
|
|
46
|
-
##### path
|
|
47
|
-
|
|
48
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
49
|
-
|
|
50
|
-
The current parent path.
|
|
51
|
-
|
|
52
|
-
##### key
|
|
53
|
-
|
|
54
|
-
`string`
|
|
55
|
-
|
|
56
|
-
The property key.
|
|
57
|
-
|
|
58
|
-
#### Returns
|
|
59
|
-
|
|
60
|
-
`string`[]
|
|
61
|
-
|
|
62
|
-
An array of expected type strings (e.g., ["string", "number"]).
|
|
63
|
-
|
|
64
|
-
***
|
|
65
|
-
|
|
66
|
-
### getSchemaForPath()
|
|
67
|
-
|
|
68
|
-
> **getSchemaForPath**(`path`): `any`
|
|
69
|
-
|
|
70
|
-
Defined in: [walker/schema-walker.ts:47](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L47)
|
|
71
|
-
|
|
72
|
-
Retrieves the sub-schema for a given JSON path.
|
|
73
|
-
|
|
74
|
-
#### Parameters
|
|
75
|
-
|
|
76
|
-
##### path
|
|
77
|
-
|
|
78
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
79
|
-
|
|
80
|
-
The path to navigate to.
|
|
81
|
-
|
|
82
|
-
#### Returns
|
|
83
|
-
|
|
84
|
-
`any`
|
|
85
|
-
|
|
86
|
-
The sub-schema at the specified path, or undefined if not found.
|
|
87
|
-
|
|
88
|
-
***
|
|
89
|
-
|
|
90
|
-
### hasDeclaredProperties()
|
|
91
|
-
|
|
92
|
-
> **hasDeclaredProperties**(`path`): `boolean`
|
|
93
|
-
|
|
94
|
-
Defined in: [walker/schema-walker.ts:163](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L163)
|
|
95
|
-
|
|
96
|
-
Whether the Schema at the given path declares any property names at all.
|
|
97
|
-
Used to decide whether key matching can be strict or has to stay lenient.
|
|
98
|
-
|
|
99
|
-
#### Parameters
|
|
100
|
-
|
|
101
|
-
##### path
|
|
102
|
-
|
|
103
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
104
|
-
|
|
105
|
-
The current parent path.
|
|
106
|
-
|
|
107
|
-
#### Returns
|
|
108
|
-
|
|
109
|
-
`boolean`
|
|
110
|
-
|
|
111
|
-
***
|
|
112
|
-
|
|
113
|
-
### isDeclaredProperty()
|
|
114
|
-
|
|
115
|
-
> **isDeclaredProperty**(`path`, `key`): `boolean`
|
|
116
|
-
|
|
117
|
-
Defined in: [walker/schema-walker.ts:149](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L149)
|
|
118
|
-
|
|
119
|
-
Whether a property name is explicitly declared in the Schema at the given path.
|
|
120
|
-
|
|
121
|
-
#### Parameters
|
|
122
|
-
|
|
123
|
-
##### path
|
|
124
|
-
|
|
125
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
126
|
-
|
|
127
|
-
The current parent path.
|
|
128
|
-
|
|
129
|
-
##### key
|
|
130
|
-
|
|
131
|
-
`string`
|
|
132
|
-
|
|
133
|
-
The property key to check.
|
|
134
|
-
|
|
135
|
-
#### Returns
|
|
136
|
-
|
|
137
|
-
`boolean`
|
|
138
|
-
|
|
139
|
-
True only when `key` appears in the Schema `properties` of that path.
|
|
140
|
-
|
|
141
|
-
***
|
|
142
|
-
|
|
143
|
-
### isValidProperty()
|
|
144
|
-
|
|
145
|
-
> **isValidProperty**(`path`, `key`): `boolean`
|
|
146
|
-
|
|
147
|
-
Defined in: [walker/schema-walker.ts:74](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L74)
|
|
148
|
-
|
|
149
|
-
Determines if a property key is valid for the given path according to the Schema.
|
|
150
|
-
|
|
151
|
-
#### Parameters
|
|
152
|
-
|
|
153
|
-
##### path
|
|
154
|
-
|
|
155
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
156
|
-
|
|
157
|
-
The current parent path.
|
|
158
|
-
|
|
159
|
-
##### key
|
|
160
|
-
|
|
161
|
-
`string`
|
|
162
|
-
|
|
163
|
-
The property key to check.
|
|
164
|
-
|
|
165
|
-
#### Returns
|
|
166
|
-
|
|
167
|
-
`boolean`
|
|
168
|
-
|
|
169
|
-
True if the property is defined in the Schema or allowed by additionalProperties.
|
|
170
|
-
|
|
171
|
-
***
|
|
172
|
-
|
|
173
|
-
### matchProperty()
|
|
174
|
-
|
|
175
|
-
> **matchProperty**(`path`, `key`): `string` \| `null`
|
|
176
|
-
|
|
177
|
-
Defined in: [walker/schema-walker.ts:107](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L107)
|
|
178
|
-
|
|
179
|
-
Resolves an incoming property name to the name declared by the Schema at `path`.
|
|
180
|
-
|
|
181
|
-
Without `keyMatching` this only accepts an exact declaration. With `keyMatching: true`
|
|
182
|
-
the comparison ignores case and the separators used by the two common naming styles
|
|
183
|
-
(`user_name` / `userName` / `USER NAME`). A function matcher decides itself and may
|
|
184
|
-
return a name the Schema does not declare.
|
|
185
|
-
|
|
186
|
-
Besides renaming, the result is what makes a key a breakpoint for greedy string capture:
|
|
187
|
-
the parser calls this while deciding whether an upcoming `key:` ends the value in front of it.
|
|
188
|
-
|
|
189
|
-
#### Parameters
|
|
190
|
-
|
|
191
|
-
##### path
|
|
192
|
-
|
|
193
|
-
[`JSONPath`](../type-aliases/JSONPath.md)
|
|
194
|
-
|
|
195
|
-
The current parent path.
|
|
196
|
-
|
|
197
|
-
##### key
|
|
198
|
-
|
|
199
|
-
`string`
|
|
200
|
-
|
|
201
|
-
The property key found in the broken document.
|
|
202
|
-
|
|
203
|
-
#### Returns
|
|
204
|
-
|
|
205
|
-
`string` \| `null`
|
|
206
|
-
|
|
207
|
-
The canonical Schema property name, or `null` when nothing matches.
|
|
208
|
-
|
|
209
|
-
***
|
|
210
|
-
|
|
211
|
-
### create()
|
|
212
|
-
|
|
213
|
-
> `static` **create**(`schema`, `options?`): `Promise`\<`SchemaWalker`\>
|
|
214
|
-
|
|
215
|
-
Defined in: [walker/schema-walker.ts:30](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/walker/schema-walker.ts#L30)
|
|
216
|
-
|
|
217
|
-
Static factory method to create a SchemaWalker instance.
|
|
218
|
-
Asynchronously dereferences the provided JSON Schema.
|
|
219
|
-
|
|
220
|
-
The Schema is dereferenced on a deep copy: `$RefParser.dereference()` replaces every
|
|
221
|
-
`$ref` in place, which would otherwise rewrite the object the caller passed in.
|
|
222
|
-
|
|
223
|
-
#### Parameters
|
|
224
|
-
|
|
225
|
-
##### schema
|
|
226
|
-
|
|
227
|
-
`any`
|
|
228
|
-
|
|
229
|
-
The JSON Schema object to walk.
|
|
230
|
-
|
|
231
|
-
##### options?
|
|
232
|
-
|
|
233
|
-
[`RepairOptions`](../interfaces/RepairOptions.md) = `{}`
|
|
234
|
-
|
|
235
|
-
Repair options that concern the Schema itself (`keyMatching`).
|
|
236
|
-
|
|
237
|
-
#### Returns
|
|
238
|
-
|
|
239
|
-
`Promise`\<`SchemaWalker`\>
|
|
240
|
-
|
|
241
|
-
A promise that resolves to a SchemaWalker instance.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / compareScores
|
|
6
|
-
|
|
7
|
-
# Function: compareScores()
|
|
8
|
-
|
|
9
|
-
> **compareScores**(`a`, `b`): `number`
|
|
10
|
-
|
|
11
|
-
Defined in: [score.ts:147](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/score.ts#L147)
|
|
12
|
-
|
|
13
|
-
Compare two scores the way [RepairOptions.onMultiple](../interfaces/RepairOptions.md#onmultiple) promises: fewer errors first, then
|
|
14
|
-
more `required` fields with real values, then more declared fields, then fewer keys that are
|
|
15
|
-
JSON Schema keywords - the signature of an answer built out of the Schema itself. An undeclared
|
|
16
|
-
key that is not a keyword is reported but not held against a fragment.
|
|
17
|
-
|
|
18
|
-
## Parameters
|
|
19
|
-
|
|
20
|
-
### a
|
|
21
|
-
|
|
22
|
-
[`CandidateScore`](../interfaces/CandidateScore.md)
|
|
23
|
-
|
|
24
|
-
### b
|
|
25
|
-
|
|
26
|
-
[`CandidateScore`](../interfaces/CandidateScore.md)
|
|
27
|
-
|
|
28
|
-
## Returns
|
|
29
|
-
|
|
30
|
-
`number`
|
|
31
|
-
|
|
32
|
-
a negative number when `a` should win, positive when `b` should.
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / discardedText
|
|
6
|
-
|
|
7
|
-
# Function: discardedText()
|
|
8
|
-
|
|
9
|
-
> **discardedText**(`text`, `chosen`, `others`): `object`
|
|
10
|
-
|
|
11
|
-
Defined in: [locate.ts:230](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/locate.ts#L230)
|
|
12
|
-
|
|
13
|
-
What the repair threw away around a chosen region: the prose between and around the JSON
|
|
14
|
-
regions (with offsets, so the caller can tell prefix from trailing chatter), and the
|
|
15
|
-
regions it did not pick. Reported separately from the flags because a caller that cannot
|
|
16
|
-
afford to lose content needs the text itself, not just a hint that something went.
|
|
17
|
-
|
|
18
|
-
## Parameters
|
|
19
|
-
|
|
20
|
-
### text
|
|
21
|
-
|
|
22
|
-
`string`
|
|
23
|
-
|
|
24
|
-
### chosen
|
|
25
|
-
|
|
26
|
-
[`LocatedJson`](../interfaces/LocatedJson.md)
|
|
27
|
-
|
|
28
|
-
### others
|
|
29
|
-
|
|
30
|
-
[`LocatedJson`](../interfaces/LocatedJson.md)[]
|
|
31
|
-
|
|
32
|
-
## Returns
|
|
33
|
-
|
|
34
|
-
`object`
|
|
35
|
-
|
|
36
|
-
### fragments
|
|
37
|
-
|
|
38
|
-
> **fragments**: `string`[]
|
|
39
|
-
|
|
40
|
-
### prose
|
|
41
|
-
|
|
42
|
-
> **prose**: `object`[]
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / expectsArrayRoot
|
|
6
|
-
|
|
7
|
-
# Function: expectsArrayRoot()
|
|
8
|
-
|
|
9
|
-
> **expectsArrayRoot**(`walker`): `boolean`
|
|
10
|
-
|
|
11
|
-
Defined in: [locate.ts:38](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/locate.ts#L38)
|
|
12
|
-
|
|
13
|
-
Whether the Schema expects an array at the root of the document.
|
|
14
|
-
|
|
15
|
-
## Parameters
|
|
16
|
-
|
|
17
|
-
### walker
|
|
18
|
-
|
|
19
|
-
[`SchemaWalker`](../classes/SchemaWalker.md)
|
|
20
|
-
|
|
21
|
-
## Returns
|
|
22
|
-
|
|
23
|
-
`boolean`
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / findImplicitRecordRegion
|
|
6
|
-
|
|
7
|
-
# Function: findImplicitRecordRegion()
|
|
8
|
-
|
|
9
|
-
> **findImplicitRecordRegion**(`text`, `walker`): [`LocatedJson`](../interfaces/LocatedJson.md) \| `undefined`
|
|
10
|
-
|
|
11
|
-
Defined in: [locate.ts:85](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/locate.ts#L85)
|
|
12
|
-
|
|
13
|
-
Where a record that has no braces at all starts, when prose sits in front of it:
|
|
14
|
-
`Here you go:\nname: Noah, age: 30`. The only thing that can tell `name` is a key rather
|
|
15
|
-
than part of a sentence is the Schema declaring it, so the Schema supplies the offset.
|
|
16
|
-
|
|
17
|
-
## Parameters
|
|
18
|
-
|
|
19
|
-
### text
|
|
20
|
-
|
|
21
|
-
`string`
|
|
22
|
-
|
|
23
|
-
### walker
|
|
24
|
-
|
|
25
|
-
[`SchemaWalker`](../classes/SchemaWalker.md)
|
|
26
|
-
|
|
27
|
-
## Returns
|
|
28
|
-
|
|
29
|
-
[`LocatedJson`](../interfaces/LocatedJson.md) \| `undefined`
|
|
30
|
-
|
|
31
|
-
A region running from the first declared key to the end of the text, or
|
|
32
|
-
`undefined` when the text names none of them.
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / jsonRepair
|
|
6
|
-
|
|
7
|
-
# Function: jsonRepair()
|
|
8
|
-
|
|
9
|
-
> **jsonRepair**(`input`, `schema?`, `options?`): `Promise`\<`any`\>
|
|
10
|
-
|
|
11
|
-
Defined in: [repair.ts:56](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/repair.ts#L56)
|
|
12
|
-
|
|
13
|
-
Repairs and parses a string generated by an LLM, guided by a JSON Schema.
|
|
14
|
-
This is the main entry point for the library.
|
|
15
|
-
|
|
16
|
-
## Parameters
|
|
17
|
-
|
|
18
|
-
### input
|
|
19
|
-
|
|
20
|
-
`string`
|
|
21
|
-
|
|
22
|
-
The text the model returned: broken JSON, or JSON wrapped in a Markdown
|
|
23
|
-
fence and prose. See [RepairOptions.locate](../interfaces/RepairOptions.md#locate).
|
|
24
|
-
|
|
25
|
-
### schema?
|
|
26
|
-
|
|
27
|
-
`any`
|
|
28
|
-
|
|
29
|
-
Either a plain JSON Schema object or a pre-initialized SchemaWalker instance for better performance in batch processing.
|
|
30
|
-
|
|
31
|
-
### options?
|
|
32
|
-
|
|
33
|
-
[`RepairOptions`](../interfaces/RepairOptions.md) = `{}`
|
|
34
|
-
|
|
35
|
-
Optional configuration to tune the repair process.
|
|
36
|
-
|
|
37
|
-
## Returns
|
|
38
|
-
|
|
39
|
-
`Promise`\<`any`\>
|
|
40
|
-
|
|
41
|
-
A promise that resolves to the repaired and parsed JavaScript object.
|
|
42
|
-
|
|
43
|
-
## Example
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
const schema = { type: 'object', properties: { name: { type: 'string' } } };
|
|
47
|
-
const result = await jsonRepair('{ name: John }', schema);
|
|
48
|
-
console.log(result); // { name: 'John' }
|
|
49
|
-
```
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / jsonRepairResult
|
|
6
|
-
|
|
7
|
-
# Function: jsonRepairResult()
|
|
8
|
-
|
|
9
|
-
> **jsonRepairResult**\<`T`\>(`input`, `schema?`, `options?`): `Promise`\<[`RepairResult`](../interfaces/RepairResult.md)\<`T`\>\>
|
|
10
|
-
|
|
11
|
-
Defined in: [repair.ts:79](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/repair.ts#L79)
|
|
12
|
-
|
|
13
|
-
The same repair, plus what it noticed and what it had to give up.
|
|
14
|
-
|
|
15
|
-
A repaired value that validates can still be the wrong answer, and a repair that had to
|
|
16
|
-
choose between fragments or throw prose away has made decisions the caller should be able
|
|
17
|
-
to see. `flags`, `errors`, `candidates` and `discarded` are what a caller needs to decide
|
|
18
|
-
whether to accept the value, hand the `errors` back to the model for another try, or give
|
|
19
|
-
up and ask a bigger model.
|
|
20
|
-
|
|
21
|
-
## Type Parameters
|
|
22
|
-
|
|
23
|
-
### T
|
|
24
|
-
|
|
25
|
-
`T` = `any`
|
|
26
|
-
|
|
27
|
-
## Parameters
|
|
28
|
-
|
|
29
|
-
### input
|
|
30
|
-
|
|
31
|
-
`string`
|
|
32
|
-
|
|
33
|
-
### schema?
|
|
34
|
-
|
|
35
|
-
`any`
|
|
36
|
-
|
|
37
|
-
### options?
|
|
38
|
-
|
|
39
|
-
[`RepairOptions`](../interfaces/RepairOptions.md) = `{}`
|
|
40
|
-
|
|
41
|
-
## Returns
|
|
42
|
-
|
|
43
|
-
`Promise`\<[`RepairResult`](../interfaces/RepairResult.md)\<`T`\>\>
|
|
44
|
-
|
|
45
|
-
## Example
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
const { value, errors, flags } = await jsonRepairResult('```json\n{ name: Ada }\n```', schema)
|
|
49
|
-
if (errors.length) await retryWith(renderValidatorErrors(errors))
|
|
50
|
-
```
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / locateJsonCandidates
|
|
6
|
-
|
|
7
|
-
# Function: locateJsonCandidates()
|
|
8
|
-
|
|
9
|
-
> **locateJsonCandidates**(`text`, `walker?`): [`LocatedJson`](../interfaces/LocatedJson.md)[]
|
|
10
|
-
|
|
11
|
-
Defined in: [locate.ts:52](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/locate.ts#L52)
|
|
12
|
-
|
|
13
|
-
## Parameters
|
|
14
|
-
|
|
15
|
-
### text
|
|
16
|
-
|
|
17
|
-
`string`
|
|
18
|
-
|
|
19
|
-
The text to scan, normally already trimmed by the caller.
|
|
20
|
-
|
|
21
|
-
### walker?
|
|
22
|
-
|
|
23
|
-
[`SchemaWalker`](../classes/SchemaWalker.md)
|
|
24
|
-
|
|
25
|
-
The Schema in play. It decides three things: whether adjacent sibling
|
|
26
|
-
records may be read as one array, where a record written without braces starts (a key only
|
|
27
|
-
the Schema can name), and nothing at all when no Schema is given.
|
|
28
|
-
|
|
29
|
-
## Returns
|
|
30
|
-
|
|
31
|
-
[`LocatedJson`](../interfaces/LocatedJson.md)[]
|
|
32
|
-
|
|
33
|
-
The regions in document order.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / looksLikeSchemaEcho
|
|
6
|
-
|
|
7
|
-
# Function: looksLikeSchemaEcho()
|
|
8
|
-
|
|
9
|
-
> **looksLikeSchemaEcho**(`fragment`): `boolean`
|
|
10
|
-
|
|
11
|
-
Defined in: [score.ts:100](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/score.ts#L100)
|
|
12
|
-
|
|
13
|
-
Whether the model reproduced the Schema instead of filling it in.
|
|
14
|
-
|
|
15
|
-
Given the fragment's text, Schema keywords are counted where they are written - the usual
|
|
16
|
-
place to look, because an echo is often swallowed by greedy capture on the way to the real
|
|
17
|
-
keys. Given a repaired value, its own keys are counted: a weaker signal (a document with
|
|
18
|
-
one real `items` field is not an echo), which is why one keyword is never enough here
|
|
19
|
-
either way. Anything else - a number, a string that is not text - is not an echo.
|
|
20
|
-
|
|
21
|
-
## Parameters
|
|
22
|
-
|
|
23
|
-
### fragment
|
|
24
|
-
|
|
25
|
-
`unknown`
|
|
26
|
-
|
|
27
|
-
## Returns
|
|
28
|
-
|
|
29
|
-
`boolean`
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / renderValidatorErrors
|
|
6
|
-
|
|
7
|
-
# Function: renderValidatorErrors()
|
|
8
|
-
|
|
9
|
-
> **renderValidatorErrors**(`errors`, `limit?`): `string`
|
|
10
|
-
|
|
11
|
-
Defined in: [validate.ts:35](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/validate.ts#L35)
|
|
12
|
-
|
|
13
|
-
Renders validation errors the way a repair prompt needs them: one `path: message` line
|
|
14
|
-
each, short enough that a 360M-parameter model still follows it. Paths point at the field,
|
|
15
|
-
so the model has something concrete to fix rather than a document to re-read.
|
|
16
|
-
|
|
17
|
-
## Parameters
|
|
18
|
-
|
|
19
|
-
### errors
|
|
20
|
-
|
|
21
|
-
[`ValidationError`](../interfaces/ValidationError.md)[]
|
|
22
|
-
|
|
23
|
-
### limit?
|
|
24
|
-
|
|
25
|
-
`number` = `6`
|
|
26
|
-
|
|
27
|
-
How many lines to emit. More than a handful of simultaneous complaints is
|
|
28
|
-
wasted on a small model; it fixes the first few and breaks the rest.
|
|
29
|
-
|
|
30
|
-
## Returns
|
|
31
|
-
|
|
32
|
-
`string`
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / scoreCandidate
|
|
6
|
-
|
|
7
|
-
# Function: scoreCandidate()
|
|
8
|
-
|
|
9
|
-
> **scoreCandidate**(`value`, `walker`): `object`
|
|
10
|
-
|
|
11
|
-
Defined in: [score.ts:17](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/score.ts#L17)
|
|
12
|
-
|
|
13
|
-
How well a value fits the Schema, measured rather than felt.
|
|
14
|
-
|
|
15
|
-
Counting declared keys is not the same as counting keys a model happened to write. Two
|
|
16
|
-
real failure modes make that difference decisive:
|
|
17
|
-
|
|
18
|
-
- A model that copies the Schema into its answer (`type`, `properties`, `required`, ...)
|
|
19
|
-
produces the fragment with the *most* keys and the least data.
|
|
20
|
-
- A model that answers with `"name": ""` satisfies `type: string` exactly and says nothing.
|
|
21
|
-
|
|
22
|
-
So coverage counts only fields carrying a usable value, and keys the Schema never declared
|
|
23
|
-
are counted against the fragment.
|
|
24
|
-
|
|
25
|
-
## Parameters
|
|
26
|
-
|
|
27
|
-
### value
|
|
28
|
-
|
|
29
|
-
`any`
|
|
30
|
-
|
|
31
|
-
### walker
|
|
32
|
-
|
|
33
|
-
[`SchemaWalker`](../classes/SchemaWalker.md)
|
|
34
|
-
|
|
35
|
-
## Returns
|
|
36
|
-
|
|
37
|
-
`object`
|
|
38
|
-
|
|
39
|
-
### flags
|
|
40
|
-
|
|
41
|
-
> **flags**: [`RepairFlag`](../type-aliases/RepairFlag.md)[]
|
|
42
|
-
|
|
43
|
-
### score
|
|
44
|
-
|
|
45
|
-
> **score**: [`CandidateScore`](../interfaces/CandidateScore.md)
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](../README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
[@isdk/json-repair](../globals.md) / validateValue
|
|
6
|
-
|
|
7
|
-
# Function: validateValue()
|
|
8
|
-
|
|
9
|
-
> **validateValue**(`value`, `walker`): [`ValidationError`](../interfaces/ValidationError.md)[]
|
|
10
|
-
|
|
11
|
-
Defined in: [validate.ts:18](https://github.com/isdk/json-repair.js/blob/5dd9e8689f96f00064dc6c6f8343ca1fd8216d98/src/validate.ts#L18)
|
|
12
|
-
|
|
13
|
-
A small JSON Schema validator, kept inside this package on purpose: the repair already
|
|
14
|
-
knows the Schema through `SchemaWalker`, and the two things a caller needs after a repair
|
|
15
|
-
are "does this still fail?" (to decide whether another model call is worth it) and "where
|
|
16
|
-
does it fail?" (to tell the model). Pulling in a full validator would duplicate the
|
|
17
|
-
walking this library already does.
|
|
18
|
-
|
|
19
|
-
The keywords covered are the ones that describe a shape an LLM can get wrong: `type`
|
|
20
|
-
(including `integer` and unions), `required`, `properties`, `additionalProperties: false`,
|
|
21
|
-
`items`, `enum`, `const`, `pattern`, `format` for dates and times, numeric bounds, string
|
|
22
|
-
length and array length. Unknown keywords are ignored, and so is everything below a Schema
|
|
23
|
-
that says nothing - notably `anyOf` / `oneOf` / `allOf` are not evaluated, so a Schema built
|
|
24
|
-
out of them reports no errors and the fragment ranking falls back to coverage alone.
|
|
25
|
-
|
|
26
|
-
## Parameters
|
|
27
|
-
|
|
28
|
-
### value
|
|
29
|
-
|
|
30
|
-
`any`
|
|
31
|
-
|
|
32
|
-
### walker
|
|
33
|
-
|
|
34
|
-
[`SchemaWalker`](../classes/SchemaWalker.md)
|
|
35
|
-
|
|
36
|
-
## Returns
|
|
37
|
-
|
|
38
|
-
[`ValidationError`](../interfaces/ValidationError.md)[]
|
package/docs/globals.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
[**@isdk/json-repair**](README.md)
|
|
2
|
-
|
|
3
|
-
***
|
|
4
|
-
|
|
5
|
-
# @isdk/json-repair
|
|
6
|
-
|
|
7
|
-
A schema-guided JSON repair library specifically designed for LLM-generated outputs.
|
|
8
|
-
|
|
9
|
-
## Classes
|
|
10
|
-
|
|
11
|
-
- [RepairParser](classes/RepairParser.md)
|
|
12
|
-
- [SchemaWalker](classes/SchemaWalker.md)
|
|
13
|
-
|
|
14
|
-
## Interfaces
|
|
15
|
-
|
|
16
|
-
- [CandidateScore](interfaces/CandidateScore.md)
|
|
17
|
-
- [JsonCandidate](interfaces/JsonCandidate.md)
|
|
18
|
-
- [LocatedJson](interfaces/LocatedJson.md)
|
|
19
|
-
- [RepairOptions](interfaces/RepairOptions.md)
|
|
20
|
-
- [RepairResult](interfaces/RepairResult.md)
|
|
21
|
-
- [ValidationError](interfaces/ValidationError.md)
|
|
22
|
-
|
|
23
|
-
## Type Aliases
|
|
24
|
-
|
|
25
|
-
- [CommentStyle](type-aliases/CommentStyle.md)
|
|
26
|
-
- [EscapeMode](type-aliases/EscapeMode.md)
|
|
27
|
-
- [JSONPath](type-aliases/JSONPath.md)
|
|
28
|
-
- [LiteralDialect](type-aliases/LiteralDialect.md)
|
|
29
|
-
- [RepairFlag](type-aliases/RepairFlag.md)
|
|
30
|
-
|
|
31
|
-
## Functions
|
|
32
|
-
|
|
33
|
-
- [compareScores](functions/compareScores.md)
|
|
34
|
-
- [discardedText](functions/discardedText.md)
|
|
35
|
-
- [expectsArrayRoot](functions/expectsArrayRoot.md)
|
|
36
|
-
- [findImplicitRecordRegion](functions/findImplicitRecordRegion.md)
|
|
37
|
-
- [jsonRepair](functions/jsonRepair.md)
|
|
38
|
-
- [jsonRepairResult](functions/jsonRepairResult.md)
|
|
39
|
-
- [locateJsonCandidates](functions/locateJsonCandidates.md)
|
|
40
|
-
- [looksLikeSchemaEcho](functions/looksLikeSchemaEcho.md)
|
|
41
|
-
- [renderValidatorErrors](functions/renderValidatorErrors.md)
|
|
42
|
-
- [scoreCandidate](functions/scoreCandidate.md)
|
|
43
|
-
- [validateValue](functions/validateValue.md)
|