@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.
Files changed (128) hide show
  1. package/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml +42 -2
  2. package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +6 -1
  3. package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/lock-threads.yml +19 -0
  4. package/node_modules/@fastify/fast-json-stringify-compiler/LICENSE +1 -1
  5. package/node_modules/@fastify/fast-json-stringify-compiler/README.md +1 -1
  6. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.gitattributes +2 -0
  7. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/dependabot.yml +13 -0
  8. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/ci.yml +33 -0
  9. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/lock-threads.yml +19 -0
  10. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/LICENSE +22 -0
  11. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/README.md +742 -0
  12. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-branch.js +116 -0
  13. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-lib.js +339 -0
  14. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-thread.js +33 -0
  15. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench.js +391 -0
  16. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/build/build-schema-validator.js +26 -0
  17. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/eslint.config.js +9 -0
  18. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/example.js +81 -0
  19. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/server.js +42 -0
  20. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/index.js +1308 -0
  21. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/location.js +24 -0
  22. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/merge-schemas.js +9 -0
  23. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/schema-validator.js +1134 -0
  24. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/serializer.js +141 -0
  25. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/standalone.js +34 -0
  26. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/validator.js +96 -0
  27. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/package.json +89 -0
  28. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/additionalProperties.test.js +332 -0
  29. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/allof.test.js +751 -0
  30. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/any.test.js +231 -0
  31. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/anyof.test.js +812 -0
  32. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/array.test.js +688 -0
  33. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/asNumber.test.js +13 -0
  34. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/basic.test.js +400 -0
  35. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/bigint.test.js +76 -0
  36. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/clean-cache.test.js +47 -0
  37. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/const.test.js +314 -0
  38. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/date.test.js +639 -0
  39. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/debug-mode.test.js +130 -0
  40. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/defaults.test.js +376 -0
  41. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/enum.test.js +37 -0
  42. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fix-604.test.js +25 -0
  43. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fixtures/.keep +0 -0
  44. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/if-then-else.test.js +540 -0
  45. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/inferType.test.js +92 -0
  46. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/infinity.test.js +55 -0
  47. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/integer.test.js +194 -0
  48. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/invalidSchema.test.js +38 -0
  49. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-479.test.js +57 -0
  50. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-793.test.js +107 -0
  51. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-794.test.js +177 -0
  52. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-836.test.js +183 -0
  53. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-add-comma.test.js +57 -0
  54. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/README.md +10 -0
  55. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4/required.json +54 -0
  56. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4.test.js +12 -0
  57. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6/required.json +70 -0
  58. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6.test.js +12 -0
  59. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7/required.json +70 -0
  60. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7.test.js +12 -0
  61. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/util.js +31 -0
  62. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/missing-values.test.js +88 -0
  63. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/multi-type-serializer.test.js +19 -0
  64. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nestedObjects.test.js +63 -0
  65. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nullable.test.js +543 -0
  66. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/oneof.test.js +510 -0
  67. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/patternProperties.test.js +168 -0
  68. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/recursion.test.js +245 -0
  69. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.json +12 -0
  70. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.test.js +2077 -0
  71. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/regex.test.js +32 -0
  72. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/required.test.js +204 -0
  73. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/requiresAjv.test.js +50 -0
  74. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize.test.js +141 -0
  75. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize2.test.js +18 -0
  76. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize3.test.js +17 -0
  77. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize4.test.js +16 -0
  78. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize5.test.js +16 -0
  79. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize6.test.js +22 -0
  80. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize7.test.js +68 -0
  81. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/side-effect.test.js +196 -0
  82. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/standalone-mode.test.js +219 -0
  83. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/string.test.js +84 -0
  84. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/surrogate.test.js +67 -0
  85. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/toJSON.test.js +203 -0
  86. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typebox.test.js +36 -0
  87. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typesArray.test.js +550 -0
  88. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/unknownFormats.test.js +27 -0
  89. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/webpack.test.js +50 -0
  90. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.d.ts +219 -0
  91. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.tst.ts +259 -0
  92. package/node_modules/@fastify/fast-json-stringify-compiler/package.json +6 -11
  93. package/node_modules/@fastify/fast-json-stringify-compiler/types/{index.test-d.ts → index.tst.ts} +34 -32
  94. package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
  95. package/node_modules/@protobufjs/utf8/index.js +29 -18
  96. package/node_modules/@protobufjs/utf8/package.json +2 -2
  97. package/node_modules/@protobufjs/utf8/tests/index.js +5 -0
  98. package/node_modules/@zuplo/core/package.json +1 -1
  99. package/node_modules/@zuplo/graphql/package.json +1 -1
  100. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  101. package/node_modules/@zuplo/otel/package.json +1 -1
  102. package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js → chunk-D3O7C43P.js} +98 -97
  103. package/node_modules/@zuplo/runtime/out/esm/chunk-D3O7C43P.js.map +1 -0
  104. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  105. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  106. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  107. package/node_modules/@zuplo/runtime/out/types/index.d.ts +172 -0
  108. package/node_modules/@zuplo/runtime/package.json +1 -1
  109. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -1
  110. package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
  111. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -1
  112. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
  113. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
  114. package/node_modules/hono/dist/cjs/utils/body.js +12 -4
  115. package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
  116. package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
  117. package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
  118. package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
  120. package/node_modules/hono/dist/utils/body.js +12 -4
  121. package/node_modules/hono/dist/utils/buffer.js +2 -1
  122. package/node_modules/hono/dist/validator/validator.js +3 -3
  123. package/node_modules/hono/package.json +8 -7
  124. package/package.json +6 -6
  125. package/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +0 -1
  126. package/node_modules/@zuplo/runtime/out/esm/chunk-5CYWMN74.js.map +0 -1
  127. package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
  128. /package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js.LEGAL.txt → chunk-D3O7C43P.js.LEGAL.txt} +0 -0
@@ -0,0 +1,540 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const build = require('..')
5
+
6
+ process.env.TZ = 'UTC'
7
+
8
+ const schema = {
9
+ type: 'object',
10
+ properties: {
11
+ },
12
+ if: {
13
+ type: 'object',
14
+ properties: {
15
+ kind: { type: 'string', enum: ['foobar'] }
16
+ }
17
+ },
18
+ then: {
19
+ type: 'object',
20
+ properties: {
21
+ kind: { type: 'string', enum: ['foobar'] },
22
+ foo: { type: 'string' },
23
+ bar: { type: 'number' },
24
+ list: {
25
+ type: 'array',
26
+ items: {
27
+ type: 'object',
28
+ properties: {
29
+ name: { type: 'string' },
30
+ value: { type: 'string' }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ },
36
+ else: {
37
+ type: 'object',
38
+ properties: {
39
+ kind: { type: 'string', enum: ['greeting'] },
40
+ hi: { type: 'string' },
41
+ hello: { type: 'number' },
42
+ list: {
43
+ type: 'array',
44
+ items: {
45
+ type: 'object',
46
+ properties: {
47
+ name: { type: 'string' },
48
+ value: { type: 'string' }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ const nestedIfSchema = {
57
+ type: 'object',
58
+ properties: { },
59
+ if: {
60
+ type: 'object',
61
+ properties: {
62
+ kind: { type: 'string', enum: ['foobar', 'greeting'] }
63
+ }
64
+ },
65
+ then: {
66
+ if: {
67
+ type: 'object',
68
+ properties: {
69
+ kind: { type: 'string', enum: ['foobar'] }
70
+ }
71
+ },
72
+ then: {
73
+ type: 'object',
74
+ properties: {
75
+ kind: { type: 'string', enum: ['foobar'] },
76
+ foo: { type: 'string' },
77
+ bar: { type: 'number' },
78
+ list: {
79
+ type: 'array',
80
+ items: {
81
+ type: 'object',
82
+ properties: {
83
+ name: { type: 'string' },
84
+ value: { type: 'string' }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ },
90
+ else: {
91
+ type: 'object',
92
+ properties: {
93
+ kind: { type: 'string', enum: ['greeting'] },
94
+ hi: { type: 'string' },
95
+ hello: { type: 'number' }
96
+ }
97
+ }
98
+ },
99
+ else: {
100
+ type: 'object',
101
+ properties: {
102
+ kind: { type: 'string', enum: ['alphabet'] },
103
+ a: { type: 'string' },
104
+ b: { type: 'number' }
105
+ }
106
+ }
107
+ }
108
+
109
+ const nestedElseSchema = {
110
+ type: 'object',
111
+ properties: { },
112
+ if: {
113
+ type: 'object',
114
+ properties: {
115
+ kind: { type: 'string', enum: ['foobar'] }
116
+ }
117
+ },
118
+ then: {
119
+ type: 'object',
120
+ properties: {
121
+ kind: { type: 'string', enum: ['foobar'] },
122
+ foo: { type: 'string' },
123
+ bar: { type: 'number' },
124
+ list: {
125
+ type: 'array',
126
+ items: {
127
+ type: 'object',
128
+ properties: {
129
+ name: { type: 'string' },
130
+ value: { type: 'string' }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ },
136
+ else: {
137
+ if: {
138
+ type: 'object',
139
+ properties: {
140
+ kind: { type: 'string', enum: ['greeting'] }
141
+ }
142
+ },
143
+ then: {
144
+ type: 'object',
145
+ properties: {
146
+ kind: { type: 'string', enum: ['greeting'] },
147
+ hi: { type: 'string' },
148
+ hello: { type: 'number' }
149
+ }
150
+ },
151
+ else: {
152
+ type: 'object',
153
+ properties: {
154
+ kind: { type: 'string', enum: ['alphabet'] },
155
+ a: { type: 'string' },
156
+ b: { type: 'number' }
157
+ }
158
+ }
159
+ }
160
+ }
161
+
162
+ const nestedDeepElseSchema = {
163
+ type: 'object',
164
+ additionalProperties: schema
165
+ }
166
+
167
+ const noElseSchema = {
168
+ type: 'object',
169
+ properties: {
170
+ },
171
+ if: {
172
+ type: 'object',
173
+ properties: {
174
+ kind: { type: 'string', enum: ['foobar'] }
175
+ }
176
+ },
177
+ then: {
178
+ type: 'object',
179
+ properties: {
180
+ kind: { type: 'string', enum: ['foobar'] },
181
+ foo: { type: 'string' },
182
+ bar: { type: 'number' },
183
+ list: {
184
+ type: 'array',
185
+ items: {
186
+ type: 'object',
187
+ properties: {
188
+ name: { type: 'string' },
189
+ value: { type: 'string' }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ const fooBarInput = {
197
+ kind: 'foobar',
198
+ foo: 'FOO',
199
+ list: [{
200
+ name: 'name',
201
+ value: 'foo'
202
+ }],
203
+ bar: 42,
204
+ hi: 'HI',
205
+ hello: 45,
206
+ a: 'A',
207
+ b: 35
208
+ }
209
+ const greetingInput = {
210
+ kind: 'greeting',
211
+ foo: 'FOO',
212
+ bar: 42,
213
+ hi: 'HI',
214
+ hello: 45,
215
+ a: 'A',
216
+ b: 35
217
+ }
218
+ const alphabetInput = {
219
+ kind: 'alphabet',
220
+ foo: 'FOO',
221
+ bar: 42,
222
+ hi: 'HI',
223
+ hello: 45,
224
+ a: 'A',
225
+ b: 35
226
+ }
227
+ const deepFoobarInput = {
228
+ foobar: fooBarInput
229
+ }
230
+ const foobarOutput = JSON.stringify({
231
+ kind: 'foobar',
232
+ foo: 'FOO',
233
+ bar: 42,
234
+ list: [{
235
+ name: 'name',
236
+ value: 'foo'
237
+ }]
238
+ })
239
+ const greetingOutput = JSON.stringify({
240
+ kind: 'greeting',
241
+ hi: 'HI',
242
+ hello: 45
243
+ })
244
+ const alphabetOutput = JSON.stringify({
245
+ kind: 'alphabet',
246
+ a: 'A',
247
+ b: 35
248
+ })
249
+ const deepFoobarOutput = JSON.stringify({
250
+ foobar: JSON.parse(foobarOutput)
251
+ })
252
+ const noElseGreetingOutput = JSON.stringify({})
253
+
254
+ test('if-then-else', async t => {
255
+ const tests = [
256
+ {
257
+ name: 'foobar',
258
+ schema,
259
+ input: fooBarInput,
260
+ expected: foobarOutput
261
+ },
262
+ {
263
+ name: 'greeting',
264
+ schema,
265
+ input: greetingInput,
266
+ expected: greetingOutput
267
+ },
268
+ {
269
+ name: 'if nested - then then',
270
+ schema: nestedIfSchema,
271
+ input: fooBarInput,
272
+ expected: foobarOutput
273
+ },
274
+ {
275
+ name: 'if nested - then else',
276
+ schema: nestedIfSchema,
277
+ input: greetingInput,
278
+ expected: greetingOutput
279
+ },
280
+ {
281
+ name: 'if nested - else',
282
+ schema: nestedIfSchema,
283
+ input: alphabetInput,
284
+ expected: alphabetOutput
285
+ },
286
+ {
287
+ name: 'else nested - then',
288
+ schema: nestedElseSchema,
289
+ input: fooBarInput,
290
+ expected: foobarOutput
291
+ },
292
+ {
293
+ name: 'else nested - else then',
294
+ schema: nestedElseSchema,
295
+ input: greetingInput,
296
+ expected: greetingOutput
297
+ },
298
+ {
299
+ name: 'else nested - else else',
300
+ schema: nestedElseSchema,
301
+ input: alphabetInput,
302
+ expected: alphabetOutput
303
+ },
304
+ {
305
+ name: 'deep then - else',
306
+ schema: nestedDeepElseSchema,
307
+ input: deepFoobarInput,
308
+ expected: deepFoobarOutput
309
+ },
310
+ {
311
+ name: 'no else',
312
+ schema: noElseSchema,
313
+ input: greetingInput,
314
+ expected: noElseGreetingOutput
315
+ }
316
+ ]
317
+
318
+ for (const { name, schema, input, expected } of tests) {
319
+ await t.test(name + ' - normal', async t => {
320
+ t.plan(1)
321
+
322
+ const stringify = build(JSON.parse(JSON.stringify(schema)), { ajv: { strictTypes: false } })
323
+ const serialized = stringify(input)
324
+ t.assert.equal(serialized, expected)
325
+ })
326
+ }
327
+ })
328
+
329
+ test('nested if/then', t => {
330
+ t.plan(2)
331
+
332
+ const schema = {
333
+ type: 'object',
334
+ properties: { a: { type: 'string' } },
335
+ if: {
336
+ type: 'object',
337
+ properties: { foo: { type: 'string' } }
338
+ },
339
+ then: {
340
+ properties: { bar: { type: 'string' } },
341
+ if: {
342
+ type: 'object',
343
+ properties: { foo1: { type: 'string' } }
344
+ },
345
+ then: {
346
+ properties: { bar1: { type: 'string' } }
347
+ }
348
+ }
349
+ }
350
+
351
+ const stringify = build(schema)
352
+
353
+ t.assert.equal(
354
+ stringify({ a: 'A', foo: 'foo', bar: 'bar' }),
355
+ JSON.stringify({ a: 'A', bar: 'bar' })
356
+ )
357
+
358
+ t.assert.equal(
359
+ stringify({ a: 'A', foo: 'foo', bar: 'bar', foo1: 'foo1', bar1: 'bar1' }),
360
+ JSON.stringify({ a: 'A', bar: 'bar', bar1: 'bar1' })
361
+ )
362
+ })
363
+
364
+ test('if/else with string format', (t) => {
365
+ t.plan(2)
366
+
367
+ const schema = {
368
+ if: { type: 'string' },
369
+ then: { type: 'string', format: 'date' },
370
+ else: { const: 'Invalid' }
371
+ }
372
+
373
+ const stringify = build(schema)
374
+
375
+ const date = new Date(1674263005800)
376
+
377
+ t.assert.equal(stringify(date), '"2023-01-21"')
378
+ t.assert.equal(stringify('Invalid'), '"Invalid"')
379
+ })
380
+
381
+ test('if/else with const integers', (t) => {
382
+ t.plan(2)
383
+
384
+ const schema = {
385
+ type: 'number',
386
+ if: { type: 'number', minimum: 42 },
387
+ then: { const: 66 },
388
+ else: { const: 33 }
389
+ }
390
+
391
+ const stringify = build(schema)
392
+
393
+ t.assert.equal(stringify(100.32), '66')
394
+ t.assert.equal(stringify(10.12), '33')
395
+ })
396
+
397
+ test('if/else with array', (t) => {
398
+ t.plan(2)
399
+
400
+ const schema = {
401
+ type: 'array',
402
+ if: { type: 'array', maxItems: 1 },
403
+ then: { items: { type: 'string' } },
404
+ else: { items: { type: 'number' } }
405
+ }
406
+
407
+ const stringify = build(schema)
408
+
409
+ t.assert.equal(stringify(['1']), JSON.stringify(['1']))
410
+ t.assert.equal(stringify(['1', '2']), JSON.stringify([1, 2]))
411
+ })
412
+
413
+ test('external recursive if/then/else', (t) => {
414
+ t.plan(1)
415
+
416
+ const externalSchema = {
417
+ type: 'object',
418
+ properties: {
419
+ base: { type: 'string' },
420
+ self: { $ref: 'externalSchema#' }
421
+ },
422
+ if: {
423
+ type: 'object',
424
+ properties: {
425
+ foo: { type: 'string', const: '41' }
426
+ }
427
+ },
428
+ then: {
429
+ type: 'object',
430
+ properties: {
431
+ bar: { type: 'string', const: '42' }
432
+ }
433
+ },
434
+ else: {
435
+ type: 'object',
436
+ properties: {
437
+ baz: { type: 'string', const: '43' }
438
+ }
439
+ }
440
+ }
441
+
442
+ const schema = {
443
+ type: 'object',
444
+ properties: {
445
+ a: { $ref: 'externalSchema#/properties/self' },
446
+ b: { $ref: 'externalSchema#/properties/self' }
447
+ }
448
+ }
449
+
450
+ const data = {
451
+ a: {
452
+ base: 'a',
453
+ foo: '41',
454
+ bar: '42',
455
+ baz: '43',
456
+ ignore: 'ignored'
457
+ },
458
+ b: {
459
+ base: 'b',
460
+ foo: 'not-41',
461
+ bar: '42',
462
+ baz: '43',
463
+ ignore: 'ignored'
464
+ }
465
+ }
466
+ const stringify = build(schema, { schema: { externalSchema } })
467
+ t.assert.equal(stringify(data), '{"a":{"base":"a","bar":"42"},"b":{"base":"b","baz":"43"}}')
468
+ })
469
+
470
+ test('invalid if-then-else schema', (t) => {
471
+ t.plan(1)
472
+
473
+ const schema = {
474
+ type: 'object',
475
+ if: {
476
+ type: 'object',
477
+ properties: {
478
+ kind: { type: 'string', enum: ['foobar'] }
479
+ }
480
+ },
481
+ then: {
482
+ type: 'object',
483
+ properties: {
484
+ foo: { type: 'string' }
485
+ }
486
+ },
487
+ else: {
488
+ type: 'object',
489
+ properties: 'invalid' // properties must be object
490
+ }
491
+ }
492
+
493
+ try {
494
+ build(schema)
495
+ t.assert.fail('Should throw')
496
+ } catch (err) {
497
+ t.assert.ok(err.message.includes('schema is invalid'))
498
+ }
499
+ })
500
+
501
+ test('if-then-else with allOf', (t) => {
502
+ t.plan(2)
503
+
504
+ const schema = {
505
+ type: 'object',
506
+ allOf: [
507
+ {
508
+ type: 'object',
509
+ properties: {
510
+ base: { type: 'string' }
511
+ }
512
+ }
513
+ ],
514
+ if: {
515
+ type: 'object',
516
+ properties: {
517
+ kind: { type: 'string', enum: ['foobar'] }
518
+ }
519
+ },
520
+ then: {
521
+ type: 'object',
522
+ properties: {
523
+ foo: { type: 'string' }
524
+ }
525
+ },
526
+ else: {
527
+ type: 'object',
528
+ properties: {
529
+ bar: { type: 'string' }
530
+ }
531
+ }
532
+ }
533
+
534
+ const stringify = build(schema)
535
+ const data = { base: 'test', kind: 'foobar', foo: 'value' }
536
+ const output = stringify(data)
537
+
538
+ t.assert.doesNotThrow(() => JSON.parse(output))
539
+ t.assert.equal(output, '{"base":"test","foo":"value"}')
540
+ })
@@ -0,0 +1,92 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const validator = require('is-my-json-valid')
5
+ const build = require('..')
6
+
7
+ function buildTest (schema, toStringify) {
8
+ test(`render a ${schema.title} as JSON`, (t) => {
9
+ t.plan(3)
10
+
11
+ const validate = validator(schema)
12
+ const stringify = build(schema)
13
+ const output = stringify(toStringify)
14
+
15
+ t.assert.deepStrictEqual(JSON.parse(output), toStringify)
16
+ t.assert.equal(output, JSON.stringify(toStringify))
17
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
18
+ })
19
+ }
20
+
21
+ buildTest({
22
+ title: 'infer type object by keyword',
23
+ // 'type': 'object',
24
+ properties: {
25
+ name: {
26
+ type: 'string'
27
+ }
28
+ }
29
+ }, {
30
+ name: 'foo'
31
+ })
32
+
33
+ buildTest({
34
+ title: 'infer type of nested object by keyword',
35
+ // 'type': 'object',
36
+ properties: {
37
+ more: {
38
+ description: 'more properties',
39
+ // 'type': 'object',
40
+ properties: {
41
+ something: {
42
+ type: 'string'
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }, {
48
+ more: {
49
+ something: 'else'
50
+ }
51
+ })
52
+
53
+ buildTest({
54
+ title: 'infer type array by keyword',
55
+ type: 'object',
56
+ properties: {
57
+ ids: {
58
+ // 'type': 'array',
59
+ items: {
60
+ type: 'string'
61
+ }
62
+ }
63
+ }
64
+ }, {
65
+ ids: ['test']
66
+ })
67
+
68
+ buildTest({
69
+ title: 'infer type string by keyword',
70
+ type: 'object',
71
+ properties: {
72
+ name: {
73
+ // 'type': 'string',
74
+ maxLength: 3
75
+ }
76
+ }
77
+ }, {
78
+ name: 'foo'
79
+ })
80
+
81
+ buildTest({
82
+ title: 'infer type number by keyword',
83
+ type: 'object',
84
+ properties: {
85
+ age: {
86
+ // 'type': 'number',
87
+ maximum: 18
88
+ }
89
+ }
90
+ }, {
91
+ age: 18
92
+ })
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const build = require('..')
5
+
6
+ test('Finite numbers', t => {
7
+ const values = [-5, 0, -0, 1.33, 99, 100.0,
8
+ Math.E, Number.EPSILON,
9
+ Number.MAX_SAFE_INTEGER, Number.MAX_VALUE,
10
+ Number.MIN_SAFE_INTEGER, Number.MIN_VALUE]
11
+
12
+ t.plan(values.length)
13
+
14
+ const schema = {
15
+ type: 'number'
16
+ }
17
+
18
+ const stringify = build(schema)
19
+
20
+ values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
21
+ })
22
+
23
+ test('Infinite integers', t => {
24
+ const values = [Infinity, -Infinity]
25
+
26
+ t.plan(values.length)
27
+
28
+ const schema = {
29
+ type: 'integer'
30
+ }
31
+
32
+ const stringify = build(schema)
33
+
34
+ values.forEach(v => {
35
+ try {
36
+ stringify(v)
37
+ } catch (err) {
38
+ t.assert.equal(err.message, `The value "${v}" cannot be converted to an integer.`)
39
+ }
40
+ })
41
+ })
42
+
43
+ test('Infinite numbers', t => {
44
+ const values = [Infinity, -Infinity]
45
+
46
+ t.plan(values.length)
47
+
48
+ const schema = {
49
+ type: 'number'
50
+ }
51
+
52
+ const stringify = build(schema)
53
+
54
+ values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
55
+ })