@ditojs/server 2.0.5 → 2.1.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/package.json +11 -13
- package/src/app/Application.js +226 -179
- package/src/app/Validator.js +53 -43
- package/src/cli/console.js +6 -4
- package/src/cli/db/createMigration.js +59 -30
- package/src/cli/db/migrate.js +6 -4
- package/src/cli/db/reset.js +8 -5
- package/src/cli/db/rollback.js +6 -4
- package/src/cli/db/seed.js +2 -1
- package/src/cli/index.js +1 -1
- package/src/controllers/AdminController.js +98 -84
- package/src/controllers/CollectionController.js +37 -30
- package/src/controllers/Controller.js +83 -43
- package/src/controllers/ControllerAction.js +27 -15
- package/src/controllers/ModelController.js +4 -1
- package/src/controllers/RelationController.js +19 -21
- package/src/controllers/UsersController.js +3 -4
- package/src/decorators/parameters.js +3 -1
- package/src/decorators/scope.js +1 -1
- package/src/errors/ControllerError.js +2 -1
- package/src/errors/DatabaseError.js +20 -11
- package/src/graph/DitoGraphProcessor.js +48 -40
- package/src/graph/expression.js +6 -8
- package/src/graph/graph.js +20 -11
- package/src/lib/EventEmitter.js +12 -12
- package/src/middleware/handleConnectMiddleware.js +16 -10
- package/src/middleware/handleError.js +6 -5
- package/src/middleware/handleSession.js +33 -29
- package/src/middleware/handleUser.js +2 -2
- package/src/middleware/index.js +1 -0
- package/src/middleware/logRequests.js +3 -3
- package/src/middleware/setupRequestStorage.js +14 -0
- package/src/mixins/AssetMixin.js +62 -58
- package/src/mixins/SessionMixin.js +13 -10
- package/src/mixins/TimeStampedMixin.js +33 -29
- package/src/mixins/UserMixin.js +130 -116
- package/src/models/Model.js +245 -194
- package/src/models/definitions/filters.js +14 -13
- package/src/query/QueryBuilder.js +252 -195
- package/src/query/QueryFilters.js +3 -3
- package/src/query/QueryParameters.js +2 -2
- package/src/query/Registry.js +8 -10
- package/src/schema/keywords/_validate.js +10 -8
- package/src/schema/properties.test.js +247 -206
- package/src/schema/relations.js +42 -20
- package/src/schema/relations.test.js +36 -19
- package/src/services/Service.js +8 -14
- package/src/storage/S3Storage.js +5 -3
- package/src/storage/Storage.js +16 -14
- package/src/utils/function.js +7 -4
- package/src/utils/function.test.js +30 -6
- package/src/utils/object.test.js +5 -1
- package/types/index.d.ts +244 -257
|
@@ -22,10 +22,12 @@ describe('convertSchema()', () => {
|
|
|
22
22
|
type: 'array'
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
expect(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
expect(
|
|
26
|
+
convertSchema({
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties
|
|
29
|
+
})
|
|
30
|
+
).toEqual({
|
|
29
31
|
type: 'object',
|
|
30
32
|
properties,
|
|
31
33
|
additionalProperties: false
|
|
@@ -59,10 +61,12 @@ describe('convertSchema()', () => {
|
|
|
59
61
|
default: null
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
expect(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
expect(
|
|
65
|
+
convertSchema({
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties
|
|
68
|
+
})
|
|
69
|
+
).toEqual({
|
|
66
70
|
type: 'object',
|
|
67
71
|
properties,
|
|
68
72
|
additionalProperties: false
|
|
@@ -70,14 +74,16 @@ describe('convertSchema()', () => {
|
|
|
70
74
|
})
|
|
71
75
|
|
|
72
76
|
it(`expands 'text' types to 'string' JSON schema types`, () => {
|
|
73
|
-
expect(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
expect(
|
|
78
|
+
convertSchema({
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
myText: {
|
|
82
|
+
type: 'text'
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
85
|
+
})
|
|
86
|
+
).toEqual({
|
|
81
87
|
type: 'object',
|
|
82
88
|
properties: {
|
|
83
89
|
myText: {
|
|
@@ -89,19 +95,21 @@ describe('convertSchema()', () => {
|
|
|
89
95
|
})
|
|
90
96
|
|
|
91
97
|
it('adds `required` arrays and formats for required properties', () => {
|
|
92
|
-
expect(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
expect(
|
|
99
|
+
convertSchema({
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: {
|
|
102
|
+
myString: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
required: true
|
|
105
|
+
},
|
|
106
|
+
myNumber: {
|
|
107
|
+
type: 'number',
|
|
108
|
+
required: true
|
|
109
|
+
}
|
|
102
110
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
111
|
+
})
|
|
112
|
+
).toEqual({
|
|
105
113
|
type: 'object',
|
|
106
114
|
properties: {
|
|
107
115
|
myString: {
|
|
@@ -119,14 +127,16 @@ describe('convertSchema()', () => {
|
|
|
119
127
|
})
|
|
120
128
|
|
|
121
129
|
it('preserves JSON schema-style `required` arrays', () => {
|
|
122
|
-
expect(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
expect(
|
|
131
|
+
convertSchema({
|
|
132
|
+
type: 'object',
|
|
133
|
+
required: ['myString', 'myNumber'],
|
|
134
|
+
properties: {
|
|
135
|
+
myString: { type: 'string' },
|
|
136
|
+
myNumber: { type: 'number' }
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
).toEqual({
|
|
130
140
|
type: 'object',
|
|
131
141
|
properties: {
|
|
132
142
|
myString: { type: 'string' },
|
|
@@ -138,15 +148,17 @@ describe('convertSchema()', () => {
|
|
|
138
148
|
})
|
|
139
149
|
|
|
140
150
|
it(`expands 'object' schemas with properties to JSON schemas allowing no additional properties`, () => {
|
|
141
|
-
expect(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
expect(
|
|
152
|
+
convertSchema({
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
myText: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
properties: {}
|
|
158
|
+
}
|
|
147
159
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
160
|
+
})
|
|
161
|
+
).toEqual({
|
|
150
162
|
type: 'object',
|
|
151
163
|
properties: {
|
|
152
164
|
myText: {
|
|
@@ -160,16 +172,18 @@ describe('convertSchema()', () => {
|
|
|
160
172
|
})
|
|
161
173
|
|
|
162
174
|
it('preserves pre-existing settings for no additional properties', () => {
|
|
163
|
-
expect(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
expect(
|
|
176
|
+
convertSchema({
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
myText: {
|
|
180
|
+
type: 'object',
|
|
181
|
+
additionalProperties: true,
|
|
182
|
+
properties: {}
|
|
183
|
+
}
|
|
170
184
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
185
|
+
})
|
|
186
|
+
).toEqual({
|
|
173
187
|
type: 'object',
|
|
174
188
|
properties: {
|
|
175
189
|
myText: {
|
|
@@ -183,20 +197,22 @@ describe('convertSchema()', () => {
|
|
|
183
197
|
})
|
|
184
198
|
|
|
185
199
|
it('expands nested object schemas with required properties', () => {
|
|
186
|
-
expect(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
expect(
|
|
201
|
+
convertSchema({
|
|
202
|
+
type: 'object',
|
|
203
|
+
properties: {
|
|
204
|
+
myText: {
|
|
205
|
+
type: 'object',
|
|
206
|
+
properties: {
|
|
207
|
+
myProperty: {
|
|
208
|
+
type: 'text',
|
|
209
|
+
required: true
|
|
210
|
+
}
|
|
195
211
|
}
|
|
196
212
|
}
|
|
197
213
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
214
|
+
})
|
|
215
|
+
).toEqual({
|
|
200
216
|
type: 'object',
|
|
201
217
|
properties: {
|
|
202
218
|
myText: {
|
|
@@ -216,19 +232,21 @@ describe('convertSchema()', () => {
|
|
|
216
232
|
})
|
|
217
233
|
|
|
218
234
|
it(`expands 'object' schemas with patternProperties`, () => {
|
|
219
|
-
expect(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
235
|
+
expect(
|
|
236
|
+
convertSchema({
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
myText: {
|
|
240
|
+
type: 'object',
|
|
241
|
+
patternProperties: {
|
|
242
|
+
'^.*$': {
|
|
243
|
+
type: 'text'
|
|
244
|
+
}
|
|
227
245
|
}
|
|
228
246
|
}
|
|
229
247
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
248
|
+
})
|
|
249
|
+
).toEqual({
|
|
232
250
|
type: 'object',
|
|
233
251
|
properties: {
|
|
234
252
|
myText: {
|
|
@@ -246,20 +264,22 @@ describe('convertSchema()', () => {
|
|
|
246
264
|
})
|
|
247
265
|
|
|
248
266
|
it('expands datetime types to their JSON schema representation', () => {
|
|
249
|
-
expect(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
267
|
+
expect(
|
|
268
|
+
convertSchema({
|
|
269
|
+
type: 'object',
|
|
270
|
+
properties: {
|
|
271
|
+
myDate: {
|
|
272
|
+
type: 'date'
|
|
273
|
+
},
|
|
274
|
+
myDateTime: {
|
|
275
|
+
type: 'datetime'
|
|
276
|
+
},
|
|
277
|
+
myTimeStamp: {
|
|
278
|
+
type: 'timestamp'
|
|
279
|
+
}
|
|
260
280
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
281
|
+
})
|
|
282
|
+
).toEqual({
|
|
263
283
|
type: 'object',
|
|
264
284
|
properties: {
|
|
265
285
|
myDate: {
|
|
@@ -280,14 +300,16 @@ describe('convertSchema()', () => {
|
|
|
280
300
|
})
|
|
281
301
|
|
|
282
302
|
it('expands unrecognized types to `$ref` references', () => {
|
|
283
|
-
expect(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
303
|
+
expect(
|
|
304
|
+
convertSchema({
|
|
305
|
+
type: 'object',
|
|
306
|
+
properties: {
|
|
307
|
+
myModel: {
|
|
308
|
+
type: 'MyModel'
|
|
309
|
+
}
|
|
288
310
|
}
|
|
289
|
-
}
|
|
290
|
-
|
|
311
|
+
})
|
|
312
|
+
).toEqual({
|
|
291
313
|
type: 'object',
|
|
292
314
|
properties: {
|
|
293
315
|
myModel: {
|
|
@@ -299,16 +321,21 @@ describe('convertSchema()', () => {
|
|
|
299
321
|
})
|
|
300
322
|
|
|
301
323
|
it(`expands unrecognized types to \`instanceof\` keywords when the \`useInstanceOf\` option is provided`, () => {
|
|
302
|
-
expect(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
324
|
+
expect(
|
|
325
|
+
convertSchema(
|
|
326
|
+
{
|
|
327
|
+
type: 'object',
|
|
328
|
+
properties: {
|
|
329
|
+
myModel: {
|
|
330
|
+
type: 'MyModel'
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
useInstanceOf: true
|
|
307
336
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
useInstanceOf: true
|
|
311
|
-
})).toEqual({
|
|
337
|
+
)
|
|
338
|
+
).toEqual({
|
|
312
339
|
type: 'object',
|
|
313
340
|
properties: {
|
|
314
341
|
myModel: {
|
|
@@ -321,15 +348,17 @@ describe('convertSchema()', () => {
|
|
|
321
348
|
})
|
|
322
349
|
|
|
323
350
|
it('handles `nullable: true` correctly (now natively supported)', () => {
|
|
324
|
-
expect(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
351
|
+
expect(
|
|
352
|
+
convertSchema({
|
|
353
|
+
type: 'object',
|
|
354
|
+
properties: {
|
|
355
|
+
myString: {
|
|
356
|
+
type: 'string',
|
|
357
|
+
nullable: true
|
|
358
|
+
}
|
|
330
359
|
}
|
|
331
|
-
}
|
|
332
|
-
|
|
360
|
+
})
|
|
361
|
+
).toEqual({
|
|
333
362
|
type: 'object',
|
|
334
363
|
properties: {
|
|
335
364
|
myString: {
|
|
@@ -342,15 +371,17 @@ describe('convertSchema()', () => {
|
|
|
342
371
|
})
|
|
343
372
|
|
|
344
373
|
it(`handles \`nullable: true\` references correctly`, () => {
|
|
345
|
-
expect(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
374
|
+
expect(
|
|
375
|
+
convertSchema({
|
|
376
|
+
type: 'object',
|
|
377
|
+
properties: {
|
|
378
|
+
myModel: {
|
|
379
|
+
type: 'MyModel',
|
|
380
|
+
nullable: true
|
|
381
|
+
}
|
|
351
382
|
}
|
|
352
|
-
}
|
|
353
|
-
|
|
383
|
+
})
|
|
384
|
+
).toEqual({
|
|
354
385
|
type: 'object',
|
|
355
386
|
properties: {
|
|
356
387
|
myModel: {
|
|
@@ -365,15 +396,17 @@ describe('convertSchema()', () => {
|
|
|
365
396
|
})
|
|
366
397
|
|
|
367
398
|
it(`handles \`nullable: true\` dates correctly (now natively supported)`, () => {
|
|
368
|
-
expect(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
399
|
+
expect(
|
|
400
|
+
convertSchema({
|
|
401
|
+
type: 'object',
|
|
402
|
+
properties: {
|
|
403
|
+
myDate: {
|
|
404
|
+
type: 'date',
|
|
405
|
+
nullable: true
|
|
406
|
+
}
|
|
374
407
|
}
|
|
375
|
-
}
|
|
376
|
-
|
|
408
|
+
})
|
|
409
|
+
).toEqual({
|
|
377
410
|
type: 'object',
|
|
378
411
|
properties: {
|
|
379
412
|
myDate: {
|
|
@@ -387,16 +420,18 @@ describe('convertSchema()', () => {
|
|
|
387
420
|
})
|
|
388
421
|
|
|
389
422
|
it(`handles \`nullable: true\` enums correctly`, () => {
|
|
390
|
-
expect(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
423
|
+
expect(
|
|
424
|
+
convertSchema({
|
|
425
|
+
type: 'object',
|
|
426
|
+
properties: {
|
|
427
|
+
myEnum: {
|
|
428
|
+
type: 'string',
|
|
429
|
+
enum: ['one', 'two', 'three'],
|
|
430
|
+
nullable: true
|
|
431
|
+
}
|
|
397
432
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
433
|
+
})
|
|
434
|
+
).toEqual({
|
|
400
435
|
type: 'object',
|
|
401
436
|
properties: {
|
|
402
437
|
myEnum: {
|
|
@@ -410,44 +445,46 @@ describe('convertSchema()', () => {
|
|
|
410
445
|
})
|
|
411
446
|
|
|
412
447
|
it('converts schemas within oneOf properties', () => {
|
|
413
|
-
expect(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
448
|
+
expect(
|
|
449
|
+
convertSchema({
|
|
450
|
+
type: 'object',
|
|
451
|
+
properties: {
|
|
452
|
+
myList: {
|
|
453
|
+
type: 'array',
|
|
454
|
+
items: {
|
|
455
|
+
oneOf: [
|
|
456
|
+
{
|
|
457
|
+
type: 'object',
|
|
458
|
+
properties: {
|
|
459
|
+
prop1: {
|
|
460
|
+
type: 'string',
|
|
461
|
+
required: true
|
|
462
|
+
},
|
|
463
|
+
prop2: {
|
|
464
|
+
type: 'number',
|
|
465
|
+
required: true
|
|
466
|
+
}
|
|
430
467
|
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
type: 'object',
|
|
471
|
+
properties: {
|
|
472
|
+
prop3: {
|
|
473
|
+
type: 'string',
|
|
474
|
+
required: true
|
|
475
|
+
},
|
|
476
|
+
prop4: {
|
|
477
|
+
type: 'number',
|
|
478
|
+
required: true
|
|
479
|
+
}
|
|
443
480
|
}
|
|
444
481
|
}
|
|
445
|
-
|
|
446
|
-
|
|
482
|
+
]
|
|
483
|
+
}
|
|
447
484
|
}
|
|
448
485
|
}
|
|
449
|
-
}
|
|
450
|
-
|
|
486
|
+
})
|
|
487
|
+
).toEqual({
|
|
451
488
|
type: 'object',
|
|
452
489
|
properties: {
|
|
453
490
|
myList: {
|
|
@@ -493,25 +530,27 @@ describe('convertSchema()', () => {
|
|
|
493
530
|
})
|
|
494
531
|
|
|
495
532
|
it('supports `required: true` on object', () => {
|
|
496
|
-
expect(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
533
|
+
expect(
|
|
534
|
+
convertSchema({
|
|
535
|
+
type: 'object',
|
|
536
|
+
properties: {
|
|
537
|
+
myObject: {
|
|
538
|
+
type: 'object',
|
|
539
|
+
required: true,
|
|
540
|
+
properties: {
|
|
541
|
+
prop1: {
|
|
542
|
+
type: 'string',
|
|
543
|
+
required: true
|
|
544
|
+
},
|
|
545
|
+
prop2: {
|
|
546
|
+
type: 'number',
|
|
547
|
+
required: true
|
|
548
|
+
}
|
|
510
549
|
}
|
|
511
550
|
}
|
|
512
551
|
}
|
|
513
|
-
}
|
|
514
|
-
|
|
552
|
+
})
|
|
553
|
+
).toEqual({
|
|
515
554
|
type: 'object',
|
|
516
555
|
properties: {
|
|
517
556
|
myObject: {
|
|
@@ -537,31 +576,33 @@ describe('convertSchema()', () => {
|
|
|
537
576
|
})
|
|
538
577
|
|
|
539
578
|
it('processes discriminator schemas correctly', () => {
|
|
540
|
-
expect(
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
579
|
+
expect(
|
|
580
|
+
convertSchema({
|
|
581
|
+
type: 'object',
|
|
582
|
+
discriminator: { propertyName: 'foo' },
|
|
583
|
+
required: ['foo'],
|
|
584
|
+
oneOf: [
|
|
585
|
+
{
|
|
586
|
+
properties: {
|
|
587
|
+
foo: { const: 'x' },
|
|
588
|
+
a: {
|
|
589
|
+
type: 'string',
|
|
590
|
+
required: true
|
|
591
|
+
}
|
|
551
592
|
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
properties: {
|
|
596
|
+
foo: { enum: ['y', 'z'] },
|
|
597
|
+
b: {
|
|
598
|
+
type: 'string',
|
|
599
|
+
required: true
|
|
600
|
+
}
|
|
560
601
|
}
|
|
561
602
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
603
|
+
]
|
|
604
|
+
})
|
|
605
|
+
).toEqual({
|
|
565
606
|
type: 'object',
|
|
566
607
|
discriminator: { propertyName: 'foo' },
|
|
567
608
|
required: ['foo'],
|