@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,550 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const build = require('..')
5
+
6
+ test('possibly nullable integer primitive alternative', (t) => {
7
+ t.plan(1)
8
+
9
+ const schema = {
10
+ title: 'simple object with multi-type nullable primitive',
11
+ type: 'object',
12
+ properties: {
13
+ data: {
14
+ type: ['integer']
15
+ }
16
+ }
17
+ }
18
+
19
+ const stringify = build(schema, { ajv: { allowUnionTypes: true } })
20
+
21
+ const value = stringify({
22
+ data: 4
23
+ })
24
+ t.assert.equal(value, '{"data":4}')
25
+ })
26
+
27
+ test('possibly nullable number primitive alternative', (t) => {
28
+ t.plan(1)
29
+
30
+ const schema = {
31
+ title: 'simple object with multi-type nullable primitive',
32
+ type: 'object',
33
+ properties: {
34
+ data: {
35
+ type: ['number']
36
+ }
37
+ }
38
+ }
39
+
40
+ const stringify = build(schema)
41
+
42
+ const value = stringify({
43
+ data: 4
44
+ })
45
+ t.assert.equal(value, '{"data":4}')
46
+ })
47
+
48
+ test('possibly nullable integer primitive alternative with null value', (t) => {
49
+ t.plan(1)
50
+
51
+ const schema = {
52
+ title: 'simple object with multi-type nullable primitive',
53
+ type: 'object',
54
+ properties: {
55
+ data: {
56
+ type: ['integer']
57
+ }
58
+ }
59
+ }
60
+
61
+ const stringify = build(schema)
62
+
63
+ const value = stringify({
64
+ data: null
65
+ })
66
+ t.assert.equal(value, '{"data":0}')
67
+ })
68
+
69
+ test('possibly nullable number primitive alternative with null value', (t) => {
70
+ t.plan(1)
71
+
72
+ const schema = {
73
+ title: 'simple object with multi-type nullable primitive',
74
+ type: 'object',
75
+ properties: {
76
+ data: {
77
+ type: ['number']
78
+ }
79
+ }
80
+ }
81
+
82
+ const stringify = build(schema)
83
+
84
+ const value = stringify({
85
+ data: null
86
+ })
87
+ t.assert.equal(value, '{"data":0}')
88
+ })
89
+
90
+ test('possibly nullable number primitive alternative with null value', (t) => {
91
+ t.plan(1)
92
+
93
+ const schema = {
94
+ title: 'simple object with multi-type nullable primitive',
95
+ type: 'object',
96
+ properties: {
97
+ data: {
98
+ type: ['boolean']
99
+ }
100
+ }
101
+ }
102
+
103
+ const stringify = build(schema)
104
+
105
+ const value = stringify({
106
+ data: null
107
+ })
108
+ t.assert.equal(value, '{"data":false}')
109
+ })
110
+
111
+ test('nullable integer primitive', (t) => {
112
+ t.plan(1)
113
+
114
+ const schema = {
115
+ title: 'simple object with nullable primitive',
116
+ type: 'object',
117
+ properties: {
118
+ data: {
119
+ type: ['integer', 'null']
120
+ }
121
+ }
122
+ }
123
+
124
+ const stringify = build(schema)
125
+
126
+ const value = stringify({
127
+ data: 4
128
+ })
129
+ t.assert.equal(value, '{"data":4}')
130
+ })
131
+
132
+ test('nullable number primitive', (t) => {
133
+ t.plan(1)
134
+
135
+ const schema = {
136
+ title: 'simple object with nullable primitive',
137
+ type: 'object',
138
+ properties: {
139
+ data: {
140
+ type: ['number', 'null']
141
+ }
142
+ }
143
+ }
144
+
145
+ const stringify = build(schema)
146
+
147
+ const value = stringify({
148
+ data: 4
149
+ })
150
+ t.assert.equal(value, '{"data":4}')
151
+ })
152
+
153
+ test('nullable primitive with null value', (t) => {
154
+ t.plan(1)
155
+
156
+ const schema = {
157
+ title: 'simple object with nullable primitive',
158
+ type: 'object',
159
+ properties: {
160
+ data: {
161
+ type: ['integer', 'null']
162
+ }
163
+ }
164
+ }
165
+
166
+ const stringify = build(schema)
167
+
168
+ const value = stringify({
169
+ data: null
170
+ })
171
+ t.assert.equal(value, '{"data":null}')
172
+ })
173
+
174
+ test('nullable number primitive with null value', (t) => {
175
+ t.plan(1)
176
+
177
+ const schema = {
178
+ title: 'simple object with nullable primitive',
179
+ type: 'object',
180
+ properties: {
181
+ data: {
182
+ type: ['number', 'null']
183
+ }
184
+ }
185
+ }
186
+
187
+ const stringify = build(schema)
188
+
189
+ const value = stringify({
190
+ data: null
191
+ })
192
+ t.assert.equal(value, '{"data":null}')
193
+ })
194
+
195
+ test('possibly null object with multi-type property', (t) => {
196
+ t.plan(3)
197
+
198
+ const schema = {
199
+ title: 'simple object with multi-type property',
200
+ type: 'object',
201
+ properties: {
202
+ objectOrNull: {
203
+ type: ['object', 'null'],
204
+ properties: {
205
+ stringOrNumber: {
206
+ type: ['string', 'number']
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ const stringify = build(schema)
213
+
214
+ t.assert.equal(stringify({
215
+ objectOrNull: {
216
+ stringOrNumber: 'string'
217
+ }
218
+ }), '{"objectOrNull":{"stringOrNumber":"string"}}')
219
+
220
+ t.assert.equal(stringify({
221
+ objectOrNull: {
222
+ stringOrNumber: 42
223
+ }
224
+ }), '{"objectOrNull":{"stringOrNumber":42}}')
225
+
226
+ t.assert.equal(stringify({
227
+ objectOrNull: null
228
+ }), '{"objectOrNull":null}')
229
+ })
230
+
231
+ test('object with possibly null array of multiple types', (t) => {
232
+ t.plan(5)
233
+
234
+ const schema = {
235
+ title: 'object with array of multiple types',
236
+ type: 'object',
237
+ properties: {
238
+ arrayOfStringsAndNumbers: {
239
+ type: ['array', 'null'],
240
+ items: {
241
+ type: ['string', 'number', 'null']
242
+ }
243
+ }
244
+ }
245
+ }
246
+ const stringify = build(schema)
247
+
248
+ try {
249
+ const value = stringify({
250
+ arrayOfStringsAndNumbers: null
251
+ })
252
+ t.assert.equal(value, '{"arrayOfStringsAndNumbers":null}')
253
+ } catch (e) {
254
+ console.log(e)
255
+ t.fail()
256
+ }
257
+
258
+ try {
259
+ const value = stringify({
260
+ arrayOfStringsAndNumbers: ['string1', 'string2']
261
+ })
262
+ t.assert.equal(value, '{"arrayOfStringsAndNumbers":["string1","string2"]}')
263
+ } catch (e) {
264
+ console.log(e)
265
+ t.fail()
266
+ }
267
+
268
+ t.assert.equal(stringify({
269
+ arrayOfStringsAndNumbers: [42, 7]
270
+ }), '{"arrayOfStringsAndNumbers":[42,7]}')
271
+
272
+ t.assert.equal(stringify({
273
+ arrayOfStringsAndNumbers: ['string1', 42, 7, 'string2']
274
+ }), '{"arrayOfStringsAndNumbers":["string1",42,7,"string2"]}')
275
+
276
+ t.assert.equal(stringify({
277
+ arrayOfStringsAndNumbers: ['string1', null, 42, 7, 'string2', null]
278
+ }), '{"arrayOfStringsAndNumbers":["string1",null,42,7,"string2",null]}')
279
+ })
280
+
281
+ test('object with tuple of multiple types', (t) => {
282
+ t.plan(2)
283
+
284
+ const schema = {
285
+ title: 'object with array of multiple types',
286
+ type: 'object',
287
+ properties: {
288
+ fixedTupleOfStringsAndNumbers: {
289
+ type: 'array',
290
+ items: [
291
+ {
292
+ type: 'string'
293
+ },
294
+ {
295
+ type: 'number'
296
+ },
297
+ {
298
+ type: ['string', 'number']
299
+ }
300
+ ]
301
+ }
302
+ }
303
+ }
304
+ const stringify = build(schema)
305
+
306
+ try {
307
+ const value = stringify({
308
+ fixedTupleOfStringsAndNumbers: ['string1', 42, 7]
309
+ })
310
+ t.assert.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,7]}')
311
+ } catch (e) {
312
+ console.log(e)
313
+ t.fail()
314
+ }
315
+
316
+ try {
317
+ const value = stringify({
318
+ fixedTupleOfStringsAndNumbers: ['string1', 42, 'string2']
319
+ })
320
+ t.assert.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,"string2"]}')
321
+ } catch (e) {
322
+ console.log(e)
323
+ t.fail()
324
+ }
325
+ })
326
+
327
+ test('object with anyOf and multiple types', (t) => {
328
+ t.plan(3)
329
+
330
+ const schema = {
331
+ title: 'object with anyOf and multiple types',
332
+ type: 'object',
333
+ properties: {
334
+ objectOrBoolean: {
335
+ anyOf: [
336
+ {
337
+ type: 'object',
338
+ properties: {
339
+ stringOrNumber: {
340
+ type: ['string', 'number']
341
+ }
342
+ }
343
+ },
344
+ {
345
+ type: 'boolean'
346
+ }
347
+ ]
348
+ }
349
+ }
350
+ }
351
+ const stringify = build(schema, { ajv: { allowUnionTypes: true } })
352
+
353
+ try {
354
+ const value = stringify({
355
+ objectOrBoolean: { stringOrNumber: 'string' }
356
+ })
357
+ t.assert.equal(value, '{"objectOrBoolean":{"stringOrNumber":"string"}}')
358
+ } catch (e) {
359
+ console.log(e)
360
+ t.fail()
361
+ }
362
+
363
+ t.assert.equal(stringify({
364
+ objectOrBoolean: { stringOrNumber: 42 }
365
+ }), '{"objectOrBoolean":{"stringOrNumber":42}}')
366
+
367
+ t.assert.equal(stringify({
368
+ objectOrBoolean: true
369
+ }), '{"objectOrBoolean":true}')
370
+ })
371
+
372
+ test('string type array can handle dates', (t) => {
373
+ t.plan(1)
374
+ const schema = {
375
+ type: 'object',
376
+ properties: {
377
+ date: { type: ['string'] },
378
+ dateObject: { type: ['string'], format: 'date-time' }
379
+ }
380
+ }
381
+ const stringify = build(schema)
382
+ const value = stringify({
383
+ date: new Date('2018-04-20T07:52:31.017Z'),
384
+ dateObject: new Date('2018-04-21T07:52:31.017Z')
385
+ })
386
+ t.assert.equal(value, '{"date":"2018-04-20T07:52:31.017Z","dateObject":"2018-04-21T07:52:31.017Z"}')
387
+ })
388
+
389
+ test('object that is simultaneously a string and a json', (t) => {
390
+ t.plan(2)
391
+ const schema = {
392
+ type: 'object',
393
+ properties: {
394
+ simultaneously: {
395
+ type: ['string', 'object'],
396
+ properties: {
397
+ foo: { type: 'string' }
398
+ }
399
+ }
400
+ }
401
+ }
402
+
403
+ const likeObjectId = {
404
+ toString () { return 'hello' }
405
+ }
406
+
407
+ const stringify = build(schema)
408
+ const valueStr = stringify({ simultaneously: likeObjectId })
409
+ t.assert.equal(valueStr, '{"simultaneously":"hello"}')
410
+
411
+ const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
412
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
413
+ })
414
+
415
+ test('object that is simultaneously a string and a json switched', (t) => {
416
+ t.plan(2)
417
+ const schema = {
418
+ type: 'object',
419
+ properties: {
420
+ simultaneously: {
421
+ type: ['object', 'string'],
422
+ properties: {
423
+ foo: { type: 'string' }
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ const likeObjectId = {
430
+ toString () { return 'hello' }
431
+ }
432
+
433
+ const stringify = build(schema)
434
+ const valueStr = stringify({ simultaneously: likeObjectId })
435
+ t.assert.equal(valueStr, '{"simultaneously":{}}')
436
+
437
+ const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
438
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
439
+ })
440
+
441
+ test('class instance that is simultaneously a string and a json', (t) => {
442
+ t.plan(2)
443
+
444
+ const schema = {
445
+ type: 'object',
446
+ properties: {
447
+ simultaneously: {
448
+ type: ['string', 'object'],
449
+ properties: {
450
+ foo: { type: 'string' }
451
+ }
452
+ }
453
+ }
454
+ }
455
+
456
+ class Test {
457
+ toString () { return 'hello' }
458
+ }
459
+
460
+ const likeObjectId = new Test()
461
+
462
+ const stringify = build(schema)
463
+ const valueStr = stringify({ simultaneously: likeObjectId })
464
+ t.assert.equal(valueStr, '{"simultaneously":"hello"}')
465
+
466
+ const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
467
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
468
+ })
469
+
470
+ test('should not throw an error when type is array and object is null, it should instead coerce to []', (t) => {
471
+ t.plan(1)
472
+ const schema = {
473
+ type: 'object',
474
+ properties: {
475
+ arr: {
476
+ type: 'array',
477
+ items: {
478
+ type: 'number'
479
+ }
480
+ }
481
+ }
482
+ }
483
+
484
+ const stringify = build(schema)
485
+ const result = stringify({ arr: null })
486
+ t.assert.equal(result, JSON.stringify({ arr: [] }))
487
+ })
488
+
489
+ test('should throw an error when type is array and object is not an array', (t) => {
490
+ t.plan(1)
491
+ const schema = {
492
+ type: 'object',
493
+ properties: {
494
+ arr: {
495
+ type: 'array',
496
+ items: {
497
+ type: 'number'
498
+ }
499
+ }
500
+ }
501
+ }
502
+
503
+ const stringify = build(schema)
504
+ t.assert.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'#/properties/arr\' does not match schema definition.'))
505
+ })
506
+
507
+ test('should throw an error when type is array and object is not an array with external schema', (t) => {
508
+ t.plan(1)
509
+ const schema = {
510
+ type: 'object',
511
+ properties: {
512
+ arr: {
513
+ $ref: 'arrayOfNumbers#/definitions/arr'
514
+ }
515
+ }
516
+ }
517
+
518
+ const externalSchema = {
519
+ arrayOfNumbers: {
520
+ definitions: {
521
+ arr: {
522
+ type: 'array',
523
+ items: {
524
+ type: 'number'
525
+ }
526
+ }
527
+ }
528
+ }
529
+ }
530
+
531
+ const stringify = build(schema, { schema: externalSchema })
532
+ t.assert.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'arrayOfNumbers#/definitions/arr\' does not match schema definition.'))
533
+ })
534
+
535
+ test('throw an error if none of types matches', (t) => {
536
+ t.plan(1)
537
+
538
+ const schema = {
539
+ title: 'simple object with multi-type nullable primitive',
540
+ type: 'object',
541
+ properties: {
542
+ data: {
543
+ type: ['number', 'boolean']
544
+ }
545
+ }
546
+ }
547
+
548
+ const stringify = build(schema)
549
+ t.assert.throws(() => stringify({ data: 'string' }), 'The value "string" does not match schema definition.')
550
+ })
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const build = require('..')
5
+
6
+ test('object with custom format field', (t) => {
7
+ t.plan(1)
8
+
9
+ const schema = {
10
+ title: 'object with custom format field',
11
+ type: 'object',
12
+ properties: {
13
+ str: {
14
+ type: 'string',
15
+ format: 'test-format'
16
+ }
17
+ }
18
+ }
19
+
20
+ const stringify = build(schema)
21
+
22
+ t.assert.doesNotThrow(() => {
23
+ stringify({
24
+ str: 'string'
25
+ })
26
+ })
27
+ })
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const webpack = require('webpack')
5
+ const path = require('path')
6
+
7
+ test('the library should work with webpack', async (t) => {
8
+ t.plan(1)
9
+ const targetdir = path.resolve(__dirname, '..', '.cache')
10
+ const targetname = path.join(targetdir, 'webpacktest.js')
11
+ const wopts = {
12
+ entry: path.resolve(__dirname, '..', 'index.js'),
13
+ mode: 'production',
14
+ target: 'node',
15
+ output: {
16
+ path: targetdir,
17
+ filename: 'webpacktest.js',
18
+ library: {
19
+ name: 'fastJsonStringify',
20
+ type: 'umd'
21
+ }
22
+ }
23
+ }
24
+ await new Promise((resolve, reject) => {
25
+ webpack(wopts, (err, stats) => {
26
+ if (err) { reject(err) } else { resolve(stats) };
27
+ })
28
+ })
29
+ const build = require(targetname)
30
+ const stringify = build({
31
+ title: 'webpack should not rename code to be executed',
32
+ type: 'object',
33
+ properties: {
34
+ foo: {
35
+ type: 'string'
36
+ },
37
+ bar: {
38
+ type: 'boolean'
39
+ }
40
+ },
41
+ patternProperties: {
42
+ foo: {
43
+ type: 'number'
44
+ }
45
+ }
46
+ })
47
+
48
+ const obj = { foo: '42', bar: true }
49
+ t.assert.equal(stringify(obj), '{"foo":"42","bar":true}')
50
+ })