fast-json-stringify 5.0.6 → 5.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/.github/workflows/benchmark.yml +12 -12
- package/.github/workflows/ci.yml +2 -0
- package/benchmark/bench.js +54 -0
- package/{build-schema-validator.js → build/build-schema-validator.js} +1 -1
- package/{example.js → examples/example.js} +1 -1
- package/{server.js → examples/server.js} +1 -1
- package/index.d.ts +9 -8
- package/index.js +232 -270
- package/lib/ref-resolver.js +84 -0
- package/{schema-validator.js → lib/schema-validator.js} +0 -0
- package/{serializer.js → lib/serializer.js} +19 -46
- package/{standalone.js → lib/standalone.js} +8 -8
- package/lib/validator.js +75 -0
- package/package.json +11 -6
- package/test/array.test.js +25 -0
- package/test/basic.test.js +13 -0
- package/test/const.test.js +235 -8
- package/test/date.test.js +119 -4
- package/test/debug-mode.test.js +23 -4
- package/test/nullable.test.js +97 -0
- package/test/ref.test.js +28 -0
- package/test/types/schema-inference.test-d.ts +48 -0
- package/test/typesArray.test.js +29 -0
- package/ajv.js +0 -37
|
@@ -11,15 +11,15 @@ jobs:
|
|
|
11
11
|
permissions:
|
|
12
12
|
contents: read
|
|
13
13
|
outputs:
|
|
14
|
-
PR-BENCH-12: ${{ steps.benchmark-pr.outputs.BENCH_RESULT12 }}
|
|
15
14
|
PR-BENCH-14: ${{ steps.benchmark-pr.outputs.BENCH_RESULT14 }}
|
|
16
15
|
PR-BENCH-16: ${{ steps.benchmark-pr.outputs.BENCH_RESULT16 }}
|
|
17
|
-
|
|
16
|
+
PR-BENCH-18: ${{ steps.benchmark-pr.outputs.BENCH_RESULT18 }}
|
|
18
17
|
MAIN-BENCH-14: ${{ steps.benchmark-main.outputs.BENCH_RESULT14 }}
|
|
19
18
|
MAIN-BENCH-16: ${{ steps.benchmark-main.outputs.BENCH_RESULT16 }}
|
|
19
|
+
MAIN-BENCH-18: ${{ steps.benchmark-main.outputs.BENCH_RESULT18 }}
|
|
20
20
|
strategy:
|
|
21
21
|
matrix:
|
|
22
|
-
node-version: [
|
|
22
|
+
node-version: [14, 16, 18]
|
|
23
23
|
steps:
|
|
24
24
|
- uses: actions/checkout@v3
|
|
25
25
|
with:
|
|
@@ -75,38 +75,38 @@ jobs:
|
|
|
75
75
|
with:
|
|
76
76
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
77
77
|
message: |
|
|
78
|
-
**Node**:
|
|
78
|
+
**Node**: 14
|
|
79
79
|
**PR**:
|
|
80
80
|
```
|
|
81
|
-
${{ needs.benchmark.outputs.PR-BENCH-
|
|
81
|
+
${{ needs.benchmark.outputs.PR-BENCH-14 }}
|
|
82
82
|
```
|
|
83
83
|
**MAIN**:
|
|
84
84
|
```
|
|
85
|
-
${{ needs.benchmark.outputs.MAIN-BENCH-
|
|
85
|
+
${{ needs.benchmark.outputs.MAIN-BENCH-14 }}
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
---
|
|
89
89
|
|
|
90
|
-
**Node**:
|
|
90
|
+
**Node**: 16
|
|
91
91
|
**PR**:
|
|
92
92
|
```
|
|
93
|
-
${{ needs.benchmark.outputs.PR-BENCH-
|
|
93
|
+
${{ needs.benchmark.outputs.PR-BENCH-16 }}
|
|
94
94
|
```
|
|
95
95
|
**MAIN**:
|
|
96
96
|
```
|
|
97
|
-
${{ needs.benchmark.outputs.MAIN-BENCH-
|
|
97
|
+
${{ needs.benchmark.outputs.MAIN-BENCH-16 }}
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
---
|
|
101
101
|
|
|
102
|
-
**Node**:
|
|
102
|
+
**Node**: 18
|
|
103
103
|
**PR**:
|
|
104
104
|
```
|
|
105
|
-
${{ needs.benchmark.outputs.PR-BENCH-
|
|
105
|
+
${{ needs.benchmark.outputs.PR-BENCH-18 }}
|
|
106
106
|
```
|
|
107
107
|
**MAIN**:
|
|
108
108
|
```
|
|
109
|
-
${{ needs.benchmark.outputs.MAIN-BENCH-
|
|
109
|
+
${{ needs.benchmark.outputs.MAIN-BENCH-18 }}
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
- uses: actions-ecosystem/action-remove-labels@v1
|
package/.github/workflows/ci.yml
CHANGED
package/benchmark/bench.js
CHANGED
|
@@ -213,6 +213,60 @@ const benchmarks = [
|
|
|
213
213
|
n5: 42,
|
|
214
214
|
b5: true
|
|
215
215
|
}
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'object with const string property',
|
|
219
|
+
schema: {
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
a: { const: 'const string' }
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
input: { a: 'const string' }
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'object with const number property',
|
|
229
|
+
schema: {
|
|
230
|
+
type: 'object',
|
|
231
|
+
properties: {
|
|
232
|
+
a: { const: 1 }
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
input: { a: 1 }
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: 'object with const bool property',
|
|
239
|
+
schema: {
|
|
240
|
+
type: 'object',
|
|
241
|
+
properties: {
|
|
242
|
+
a: { const: true }
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
input: { a: true }
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: 'object with const object property',
|
|
249
|
+
schema: {
|
|
250
|
+
type: 'object',
|
|
251
|
+
properties: {
|
|
252
|
+
foo: { const: { bar: 'baz' } }
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
input: {
|
|
256
|
+
foo: { bar: 'baz' }
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'object with const null property',
|
|
261
|
+
schema: {
|
|
262
|
+
type: 'object',
|
|
263
|
+
properties: {
|
|
264
|
+
foo: { const: null }
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
input: {
|
|
268
|
+
foo: null
|
|
269
|
+
}
|
|
216
270
|
}
|
|
217
271
|
]
|
|
218
272
|
|
|
@@ -23,4 +23,4 @@ const validationCode = standaloneCode(ajv, validate)
|
|
|
23
23
|
|
|
24
24
|
const moduleCode = `/* CODE GENERATED BY '${path.basename(__filename)}' DO NOT EDIT! */\n${validationCode}`
|
|
25
25
|
|
|
26
|
-
fs.writeFileSync(path.join(__dirname, 'schema-validator.js'), moduleCode)
|
|
26
|
+
fs.writeFileSync(path.join(__dirname, '../lib/schema-validator.js'), moduleCode)
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Ajv, { Options as AjvOptions } from "ajv"
|
|
2
|
+
|
|
2
3
|
declare namespace build {
|
|
3
4
|
interface BaseSchema {
|
|
4
5
|
/**
|
|
@@ -189,13 +190,13 @@ interface StandaloneOption extends build.Options {
|
|
|
189
190
|
declare function build(schema: build.AnySchema, options: DebugOption): { code: string, ajv: Ajv };
|
|
190
191
|
declare function build(schema: build.AnySchema, options: DeprecateDebugOption): { code: string, ajv: Ajv };
|
|
191
192
|
declare function build(schema: build.AnySchema, options: StandaloneOption): string;
|
|
192
|
-
declare function build(schema: build.AnySchema, options?: build.Options): (doc:
|
|
193
|
-
declare function build(schema: build.StringSchema, options?: build.Options): (doc:
|
|
194
|
-
declare function build(schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): (doc:
|
|
195
|
-
declare function build(schema: build.NullSchema, options?: build.Options): (doc:
|
|
196
|
-
declare function build(schema: build.BooleanSchema, options?: build.Options): (doc:
|
|
197
|
-
declare function build(schema: build.ArraySchema | build.TupleSchema, options?: build.Options): (doc:
|
|
198
|
-
declare function build(schema: build.ObjectSchema, options?: build.Options): (doc:
|
|
199
|
-
declare function build(schema: build.Schema, options?: build.Options):
|
|
193
|
+
declare function build(schema: build.AnySchema, options?: build.Options): <TDoc = any>(doc: TDoc) => any;
|
|
194
|
+
declare function build(schema: build.StringSchema, options?: build.Options): <TDoc extends string = string>(doc: TDoc) => string;
|
|
195
|
+
declare function build(schema: build.IntegerSchema | build.NumberSchema, options?: build.Options): <TDoc extends number = number>(doc: TDoc) => string;
|
|
196
|
+
declare function build(schema: build.NullSchema, options?: build.Options): <TDoc extends null = null>(doc: TDoc) => "null";
|
|
197
|
+
declare function build(schema: build.BooleanSchema, options?: build.Options): <TDoc extends boolean = boolean>(doc: TDoc) => string;
|
|
198
|
+
declare function build(schema: build.ArraySchema | build.TupleSchema, options?: build.Options): <TDoc extends any[]= any[]>(doc: TDoc) => string;
|
|
199
|
+
declare function build(schema: build.ObjectSchema, options?: build.Options): <TDoc extends object = object>(doc: TDoc) => string;
|
|
200
|
+
declare function build(schema: build.Schema, options?: build.Options): <TDoc = object | any[] | string | number | boolean | null> (doc: TDoc) => string;
|
|
200
201
|
|
|
201
202
|
export = build;
|