@zuplo/cli 6.71.23 → 6.71.26
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/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml +42 -2
- package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +6 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/LICENSE +1 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/README.md +1 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.gitattributes +2 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/dependabot.yml +13 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/ci.yml +33 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/LICENSE +22 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/README.md +742 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-branch.js +116 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-lib.js +339 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-thread.js +33 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench.js +391 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/build/build-schema-validator.js +26 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/eslint.config.js +9 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/example.js +81 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/server.js +42 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/index.js +1308 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/location.js +24 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/merge-schemas.js +9 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/schema-validator.js +1134 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/serializer.js +141 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/standalone.js +34 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/validator.js +96 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/package.json +89 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/additionalProperties.test.js +332 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/allof.test.js +751 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/any.test.js +231 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/anyof.test.js +812 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/array.test.js +688 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/asNumber.test.js +13 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/basic.test.js +400 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/bigint.test.js +76 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/clean-cache.test.js +47 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/const.test.js +314 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/date.test.js +639 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/debug-mode.test.js +130 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/defaults.test.js +376 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/enum.test.js +37 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fix-604.test.js +25 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fixtures/.keep +0 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/if-then-else.test.js +540 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/inferType.test.js +92 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/infinity.test.js +55 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/integer.test.js +194 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/invalidSchema.test.js +38 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-479.test.js +57 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-793.test.js +107 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-794.test.js +177 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-836.test.js +183 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-add-comma.test.js +57 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/README.md +10 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4/required.json +54 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6/required.json +70 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7/required.json +70 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/util.js +31 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/missing-values.test.js +88 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/multi-type-serializer.test.js +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nestedObjects.test.js +63 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nullable.test.js +543 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/oneof.test.js +510 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/patternProperties.test.js +168 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/recursion.test.js +245 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.json +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.test.js +2077 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/regex.test.js +32 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/required.test.js +204 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/requiresAjv.test.js +50 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize.test.js +141 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize2.test.js +18 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize3.test.js +17 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize4.test.js +16 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize5.test.js +16 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize6.test.js +22 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize7.test.js +68 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/side-effect.test.js +196 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/standalone-mode.test.js +219 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/string.test.js +84 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/surrogate.test.js +67 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/toJSON.test.js +203 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typebox.test.js +36 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typesArray.test.js +550 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/unknownFormats.test.js +27 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/webpack.test.js +50 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.d.ts +219 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.tst.ts +259 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/package.json +6 -11
- package/node_modules/@fastify/fast-json-stringify-compiler/types/{index.test-d.ts → index.tst.ts} +34 -32
- package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
- package/node_modules/@protobufjs/utf8/index.js +29 -18
- package/node_modules/@protobufjs/utf8/package.json +2 -2
- package/node_modules/@protobufjs/utf8/tests/index.js +5 -0
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js → chunk-D3O7C43P.js} +98 -97
- package/node_modules/@zuplo/runtime/out/esm/chunk-D3O7C43P.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +172 -0
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -1
- package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -1
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/cjs/utils/body.js +12 -4
- package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
- package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
- package/node_modules/hono/dist/utils/body.js +12 -4
- package/node_modules/hono/dist/utils/buffer.js +2 -1
- package/node_modules/hono/dist/validator/validator.js +3 -3
- package/node_modules/hono/package.json +8 -7
- package/package.json +6 -6
- package/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-5CYWMN74.js.map +0 -1
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js.LEGAL.txt → chunk-D3O7C43P.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const clone = require('rfdc/default')
|
|
5
|
+
const build = require('..')
|
|
6
|
+
|
|
7
|
+
test('oneOf with $ref should not change the input schema', t => {
|
|
8
|
+
t.plan(2)
|
|
9
|
+
|
|
10
|
+
const referenceSchema = {
|
|
11
|
+
$id: 'externalId',
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
name: { type: 'string' }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const schema = {
|
|
19
|
+
$id: 'mainSchema',
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
people: {
|
|
23
|
+
oneOf: [{ $ref: 'externalId' }]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const clonedSchema = clone(schema)
|
|
28
|
+
const stringify = build(schema, {
|
|
29
|
+
schema: {
|
|
30
|
+
[referenceSchema.$id]: referenceSchema
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const value = stringify({ people: { name: 'hello', foo: 'bar' } })
|
|
35
|
+
t.assert.equal(value, '{"people":{"name":"hello"}}')
|
|
36
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('oneOf and anyOf with $ref should not change the input schema', t => {
|
|
40
|
+
t.plan(3)
|
|
41
|
+
|
|
42
|
+
const referenceSchema = {
|
|
43
|
+
$id: 'externalSchema',
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
name: { type: 'string' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const schema = {
|
|
51
|
+
$id: 'rootSchema',
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
people: {
|
|
55
|
+
oneOf: [{ $ref: 'externalSchema' }]
|
|
56
|
+
},
|
|
57
|
+
love: {
|
|
58
|
+
anyOf: [
|
|
59
|
+
{ $ref: '#/definitions/foo' },
|
|
60
|
+
{ type: 'boolean' }
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
definitions: {
|
|
65
|
+
foo: { type: 'string' }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const clonedSchema = clone(schema)
|
|
69
|
+
const stringify = build(schema, {
|
|
70
|
+
schema: {
|
|
71
|
+
[referenceSchema.$id]: referenceSchema
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const valueAny1 = stringify({ people: { name: 'hello', foo: 'bar' }, love: 'music' })
|
|
76
|
+
const valueAny2 = stringify({ people: { name: 'hello', foo: 'bar' }, love: true })
|
|
77
|
+
|
|
78
|
+
t.assert.equal(valueAny1, '{"people":{"name":"hello"},"love":"music"}')
|
|
79
|
+
t.assert.equal(valueAny2, '{"people":{"name":"hello"},"love":true}')
|
|
80
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('multiple $ref tree', t => {
|
|
84
|
+
t.plan(2)
|
|
85
|
+
|
|
86
|
+
const referenceDeepSchema = {
|
|
87
|
+
$id: 'deepId',
|
|
88
|
+
type: 'number'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const referenceSchema = {
|
|
92
|
+
$id: 'externalId',
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
name: { $ref: '#/definitions/foo' },
|
|
96
|
+
age: { $ref: 'deepId' }
|
|
97
|
+
},
|
|
98
|
+
definitions: {
|
|
99
|
+
foo: { type: 'string' }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const schema = {
|
|
104
|
+
$id: 'mainSchema',
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {
|
|
107
|
+
people: {
|
|
108
|
+
oneOf: [{ $ref: 'externalId' }]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const clonedSchema = clone(schema)
|
|
113
|
+
const stringify = build(schema, {
|
|
114
|
+
schema: {
|
|
115
|
+
[referenceDeepSchema.$id]: referenceDeepSchema,
|
|
116
|
+
[referenceSchema.$id]: referenceSchema
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const value = stringify({ people: { name: 'hello', foo: 'bar', age: 42 } })
|
|
121
|
+
t.assert.equal(value, '{"people":{"name":"hello","age":42}}')
|
|
122
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('must not mutate items $ref', t => {
|
|
126
|
+
t.plan(2)
|
|
127
|
+
|
|
128
|
+
const referenceSchema = {
|
|
129
|
+
$id: 'ShowSchema',
|
|
130
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
name: {
|
|
134
|
+
type: 'string'
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const schema = {
|
|
140
|
+
$id: 'ListSchema',
|
|
141
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
142
|
+
type: 'array',
|
|
143
|
+
items: {
|
|
144
|
+
$ref: 'ShowSchema#'
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const clonedSchema = clone(schema)
|
|
148
|
+
const stringify = build(schema, {
|
|
149
|
+
schema: {
|
|
150
|
+
[referenceSchema.$id]: referenceSchema
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const value = stringify([{ name: 'foo' }])
|
|
155
|
+
t.assert.equal(value, '[{"name":"foo"}]')
|
|
156
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('must not mutate items referred by $ref', t => {
|
|
160
|
+
t.plan(2)
|
|
161
|
+
|
|
162
|
+
const firstSchema = {
|
|
163
|
+
$id: 'example1',
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {
|
|
166
|
+
name: {
|
|
167
|
+
type: 'string'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const reusedSchema = {
|
|
173
|
+
$id: 'example2',
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
name: {
|
|
177
|
+
oneOf: [
|
|
178
|
+
{
|
|
179
|
+
$ref: 'example1'
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const clonedSchema = clone(firstSchema)
|
|
187
|
+
const stringify = build(reusedSchema, {
|
|
188
|
+
schema: {
|
|
189
|
+
[firstSchema.$id]: firstSchema
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const value = stringify({ name: { name: 'foo' } })
|
|
194
|
+
t.assert.equal(value, '{"name":{"name":"foo"}}')
|
|
195
|
+
t.assert.deepStrictEqual(firstSchema, clonedSchema)
|
|
196
|
+
})
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test, after } = require('node:test')
|
|
4
|
+
const fjs = require('..')
|
|
5
|
+
const fs = require('fs')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
|
|
8
|
+
function build (opts, schema) {
|
|
9
|
+
return fjs(schema || {
|
|
10
|
+
title: 'default string',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
firstName: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
required: ['firstName']
|
|
18
|
+
}, opts)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const tmpDir = 'test/fixtures'
|
|
22
|
+
|
|
23
|
+
test('activate standalone mode', async (t) => {
|
|
24
|
+
t.plan(3)
|
|
25
|
+
|
|
26
|
+
after(async () => {
|
|
27
|
+
await fs.promises.rm(destination, { force: true })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const code = build({ mode: 'standalone' })
|
|
31
|
+
t.assert.ok(typeof code === 'string')
|
|
32
|
+
t.assert.equal(code.indexOf('ajv'), -1)
|
|
33
|
+
|
|
34
|
+
const destination = path.resolve(tmpDir, 'standalone.js')
|
|
35
|
+
|
|
36
|
+
await fs.promises.writeFile(destination, code)
|
|
37
|
+
const standalone = require(destination)
|
|
38
|
+
t.assert.equal(standalone({ firstName: 'Foo', surname: 'bar' }), JSON.stringify({ firstName: 'Foo' }), 'surname evicted')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('test ajv schema', async (t) => {
|
|
42
|
+
t.plan(3)
|
|
43
|
+
|
|
44
|
+
after(async () => {
|
|
45
|
+
await fs.promises.rm(destination, { force: true })
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const code = build({ mode: 'standalone' }, {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
},
|
|
52
|
+
if: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
kind: { type: 'string', enum: ['foobar'] }
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
then: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
kind: { type: 'string', enum: ['foobar'] },
|
|
62
|
+
foo: { type: 'string' },
|
|
63
|
+
bar: { type: 'number' },
|
|
64
|
+
list: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
name: { type: 'string' },
|
|
70
|
+
value: { type: 'string' }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
else: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
kind: { type: 'string', enum: ['greeting'] },
|
|
80
|
+
hi: { type: 'string' },
|
|
81
|
+
hello: { type: 'number' },
|
|
82
|
+
list: {
|
|
83
|
+
type: 'array',
|
|
84
|
+
items: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: {
|
|
87
|
+
name: { type: 'string' },
|
|
88
|
+
value: { type: 'string' }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
t.assert.ok(typeof code === 'string')
|
|
96
|
+
t.assert.equal(code.indexOf('ajv') > 0, true)
|
|
97
|
+
|
|
98
|
+
const destination = path.resolve(tmpDir, 'standalone2.js')
|
|
99
|
+
|
|
100
|
+
await fs.promises.writeFile(destination, code)
|
|
101
|
+
const standalone = require(destination)
|
|
102
|
+
t.assert.equal(standalone({
|
|
103
|
+
kind: 'foobar',
|
|
104
|
+
foo: 'FOO',
|
|
105
|
+
list: [{
|
|
106
|
+
name: 'name',
|
|
107
|
+
value: 'foo'
|
|
108
|
+
}],
|
|
109
|
+
bar: 42,
|
|
110
|
+
hi: 'HI',
|
|
111
|
+
hello: 45,
|
|
112
|
+
a: 'A',
|
|
113
|
+
b: 35
|
|
114
|
+
}), JSON.stringify({
|
|
115
|
+
kind: 'foobar',
|
|
116
|
+
foo: 'FOO',
|
|
117
|
+
bar: 42,
|
|
118
|
+
list: [{
|
|
119
|
+
name: 'name',
|
|
120
|
+
value: 'foo'
|
|
121
|
+
}]
|
|
122
|
+
}))
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('no need to keep external schemas once compiled', async (t) => {
|
|
126
|
+
t.plan(1)
|
|
127
|
+
|
|
128
|
+
after(async () => {
|
|
129
|
+
await fs.promises.rm(destination, { force: true })
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const externalSchema = {
|
|
133
|
+
first: {
|
|
134
|
+
definitions: {
|
|
135
|
+
id1: {
|
|
136
|
+
type: 'object',
|
|
137
|
+
properties: {
|
|
138
|
+
id1: {
|
|
139
|
+
type: 'integer'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const code = fjs({
|
|
147
|
+
$ref: 'first#/definitions/id1'
|
|
148
|
+
}, {
|
|
149
|
+
mode: 'standalone',
|
|
150
|
+
schema: externalSchema
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const destination = path.resolve(tmpDir, 'standalone3.js')
|
|
154
|
+
|
|
155
|
+
await fs.promises.writeFile(destination, code)
|
|
156
|
+
const standalone = require(destination)
|
|
157
|
+
|
|
158
|
+
t.assert.equal(standalone({ id1: 5 }), JSON.stringify({ id1: 5 }), 'serialization works with external schemas')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('no need to keep external schemas once compiled - with oneOf validator', async (t) => {
|
|
162
|
+
t.plan(2)
|
|
163
|
+
|
|
164
|
+
after(async () => {
|
|
165
|
+
await fs.promises.rm(destination, { force: true })
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
const externalSchema = {
|
|
169
|
+
ext: {
|
|
170
|
+
definitions: {
|
|
171
|
+
oBaz: {
|
|
172
|
+
type: 'object',
|
|
173
|
+
properties: {
|
|
174
|
+
baz: { type: 'number' }
|
|
175
|
+
},
|
|
176
|
+
required: ['baz']
|
|
177
|
+
},
|
|
178
|
+
oBar: {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: {
|
|
181
|
+
bar: { type: 'string' }
|
|
182
|
+
},
|
|
183
|
+
required: ['bar']
|
|
184
|
+
},
|
|
185
|
+
other: {
|
|
186
|
+
type: 'string',
|
|
187
|
+
const: 'other'
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const schema = {
|
|
194
|
+
title: 'object with oneOf property value containing refs to external schema',
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: {
|
|
197
|
+
oneOfSchema: {
|
|
198
|
+
oneOf: [
|
|
199
|
+
{ $ref: 'ext#/definitions/oBaz' },
|
|
200
|
+
{ $ref: 'ext#/definitions/oBar' }
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
required: ['oneOfSchema']
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const code = fjs(schema, {
|
|
208
|
+
mode: 'standalone',
|
|
209
|
+
schema: externalSchema
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
const destination = path.resolve(tmpDir, 'standalone-oneOf-ref.js')
|
|
213
|
+
|
|
214
|
+
await fs.promises.writeFile(destination, code)
|
|
215
|
+
const stringify = require(destination)
|
|
216
|
+
|
|
217
|
+
t.assert.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
|
|
218
|
+
t.assert.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
|
|
219
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
|
|
5
|
+
const build = require('..')
|
|
6
|
+
|
|
7
|
+
test('serialize short string', (t) => {
|
|
8
|
+
t.plan(2)
|
|
9
|
+
|
|
10
|
+
const schema = {
|
|
11
|
+
type: 'string'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const input = 'abcd'
|
|
15
|
+
const stringify = build(schema)
|
|
16
|
+
const output = stringify(input)
|
|
17
|
+
|
|
18
|
+
t.assert.equal(output, '"abcd"')
|
|
19
|
+
t.assert.equal(JSON.parse(output), input)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('serialize short string', (t) => {
|
|
23
|
+
t.plan(2)
|
|
24
|
+
|
|
25
|
+
const schema = {
|
|
26
|
+
type: 'string'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const input = '\x00'
|
|
30
|
+
const stringify = build(schema)
|
|
31
|
+
const output = stringify(input)
|
|
32
|
+
|
|
33
|
+
t.assert.equal(output, '"\\u0000"')
|
|
34
|
+
t.assert.equal(JSON.parse(output), input)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('serialize long string', (t) => {
|
|
38
|
+
t.plan(2)
|
|
39
|
+
|
|
40
|
+
const schema = {
|
|
41
|
+
type: 'string'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const input = new Array(2e4).fill('\x00').join('')
|
|
45
|
+
const stringify = build(schema)
|
|
46
|
+
const output = stringify(input)
|
|
47
|
+
|
|
48
|
+
t.assert.equal(output, `"${new Array(2e4).fill('\\u0000').join('')}"`)
|
|
49
|
+
t.assert.equal(JSON.parse(output), input)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('unsafe string', (t) => {
|
|
53
|
+
t.plan(2)
|
|
54
|
+
|
|
55
|
+
const schema = {
|
|
56
|
+
type: 'string',
|
|
57
|
+
format: 'unsafe'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const input = 'abcd'
|
|
61
|
+
const stringify = build(schema)
|
|
62
|
+
const output = stringify(input)
|
|
63
|
+
|
|
64
|
+
t.assert.equal(output, `"${input}"`)
|
|
65
|
+
t.assert.equal(JSON.parse(output), input)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('unsafe unescaped string', (t) => {
|
|
69
|
+
t.plan(2)
|
|
70
|
+
|
|
71
|
+
const schema = {
|
|
72
|
+
type: 'string',
|
|
73
|
+
format: 'unsafe'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const input = 'abcd "abcd"'
|
|
77
|
+
const stringify = build(schema)
|
|
78
|
+
const output = stringify(input)
|
|
79
|
+
|
|
80
|
+
t.assert.equal(output, `"${input}"`)
|
|
81
|
+
t.assert.throws(function () {
|
|
82
|
+
JSON.parse(output)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const validator = require('is-my-json-valid')
|
|
5
|
+
const build = require('..')
|
|
6
|
+
|
|
7
|
+
test('render a string with surrogate pairs as JSON:test 1', (t) => {
|
|
8
|
+
t.plan(2)
|
|
9
|
+
|
|
10
|
+
const schema = {
|
|
11
|
+
title: 'surrogate',
|
|
12
|
+
type: 'string'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const validate = validator(schema)
|
|
16
|
+
const stringify = build(schema)
|
|
17
|
+
const output = stringify('𝌆')
|
|
18
|
+
|
|
19
|
+
t.assert.equal(output, '"𝌆"')
|
|
20
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('render a string with surrogate pairs as JSON: test 2', (t) => {
|
|
24
|
+
t.plan(2)
|
|
25
|
+
|
|
26
|
+
const schema = {
|
|
27
|
+
title: 'long',
|
|
28
|
+
type: 'string'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const validate = validator(schema)
|
|
32
|
+
const stringify = build(schema)
|
|
33
|
+
const output = stringify('\uD834\uDF06')
|
|
34
|
+
|
|
35
|
+
t.assert.equal(output, '"𝌆"')
|
|
36
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('render a string with Unpaired surrogate code as JSON', (t) => {
|
|
40
|
+
t.plan(2)
|
|
41
|
+
|
|
42
|
+
const schema = {
|
|
43
|
+
title: 'surrogate',
|
|
44
|
+
type: 'string'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const validate = validator(schema)
|
|
48
|
+
const stringify = build(schema)
|
|
49
|
+
const output = stringify('\uDF06\uD834')
|
|
50
|
+
t.assert.equal(output, JSON.stringify('\uDF06\uD834'))
|
|
51
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('render a string with lone surrogate code as JSON', (t) => {
|
|
55
|
+
t.plan(2)
|
|
56
|
+
|
|
57
|
+
const schema = {
|
|
58
|
+
title: 'surrogate',
|
|
59
|
+
type: 'string'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const validate = validator(schema)
|
|
63
|
+
const stringify = build(schema)
|
|
64
|
+
const output = stringify('\uDEAD')
|
|
65
|
+
t.assert.equal(output, JSON.stringify('\uDEAD'))
|
|
66
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
67
|
+
})
|