@feathersjs/schema 5.0.0-pre.34 → 5.0.0-pre.36
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/CHANGELOG.md +17 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/default-schemas.d.ts +297 -9
- package/lib/default-schemas.js +22 -1
- package/lib/default-schemas.js.map +1 -1
- package/lib/hooks/resolve.d.ts +18 -7
- package/lib/hooks/resolve.js +40 -15
- package/lib/hooks/resolve.js.map +1 -1
- package/lib/json-schema.d.ts +35 -10
- package/lib/json-schema.js +35 -19
- package/lib/json-schema.js.map +1 -1
- package/package.json +13 -13
- package/src/default-schemas.ts +22 -1
- package/src/hooks/resolve.ts +52 -26
- package/src/json-schema.ts +52 -26
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.36](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.35...v5.0.0-pre.36) (2023-01-29)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **configuration:** Add pool and connection object to SQL database default configuration ([#3023](https://github.com/feathersjs/feathers/issues/3023)) ([092c749](https://github.com/feathersjs/feathers/commit/092c749d43f7da4d019576d1210fe7d3719a44a2))
|
|
11
|
+
- **databases:** Ensure that query sanitization is not necessary when using query schemas ([#3022](https://github.com/feathersjs/feathers/issues/3022)) ([dbf514e](https://github.com/feathersjs/feathers/commit/dbf514e85d1508b95c007462a39b3cadd4ff391d))
|
|
12
|
+
- **schema:** Allow any type in resolver hooks ([#3006](https://github.com/feathersjs/feathers/issues/3006)) ([f01281f](https://github.com/feathersjs/feathers/commit/f01281f7d83262738459585fc3f53f56c0a0deb8))
|
|
13
|
+
- **schema:** Ensure all types of nested data are securely dispatched ([#3005](https://github.com/feathersjs/feathers/issues/3005)) ([e4a9da5](https://github.com/feathersjs/feathers/commit/e4a9da5f3288e8e9f02087754473c7a9dfda6cb1))
|
|
14
|
+
- Update all dependencies ([#3024](https://github.com/feathersjs/feathers/issues/3024)) ([283dc47](https://github.com/feathersjs/feathers/commit/283dc4798d85584bc031e6e54b83b4ea77d1edd0))
|
|
15
|
+
|
|
16
|
+
# [5.0.0-pre.35](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.34...v5.0.0-pre.35) (2023-01-12)
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- **generators:** Move core code generators to shared generators package ([#2982](https://github.com/feathersjs/feathers/issues/2982)) ([0328d22](https://github.com/feathersjs/feathers/commit/0328d2292153870bc43958f73d2c6f288a8cec17))
|
|
21
|
+
- **schema:** Allow to add additional operators to the query syntax ([#2941](https://github.com/feathersjs/feathers/issues/2941)) ([f324940](https://github.com/feathersjs/feathers/commit/f324940d5795b41e8c6fc113defb0beb7ab03a0a))
|
|
22
|
+
|
|
6
23
|
# [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
|
|
7
24
|
|
|
8
25
|
### Bug Fixes
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -18,6 +18,6 @@ Refer to the [Feathers documentation](https://docs.feathersjs.com) for more deta
|
|
|
18
18
|
|
|
19
19
|
## License
|
|
20
20
|
|
|
21
|
-
Copyright (c)
|
|
21
|
+
Copyright (c) 2023 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
22
22
|
|
|
23
23
|
Licensed under the [MIT license](LICENSE).
|
package/lib/default-schemas.d.ts
CHANGED
|
@@ -122,8 +122,40 @@ export declare const sqlSettingsSchema: {
|
|
|
122
122
|
readonly client: {
|
|
123
123
|
readonly type: "string";
|
|
124
124
|
};
|
|
125
|
+
readonly pool: {
|
|
126
|
+
readonly type: "object";
|
|
127
|
+
readonly properties: {
|
|
128
|
+
readonly min: {
|
|
129
|
+
readonly type: "number";
|
|
130
|
+
};
|
|
131
|
+
readonly max: {
|
|
132
|
+
readonly type: "number";
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
125
136
|
readonly connection: {
|
|
126
|
-
readonly
|
|
137
|
+
readonly oneOf: readonly [{
|
|
138
|
+
readonly type: "string";
|
|
139
|
+
}, {
|
|
140
|
+
readonly type: "object";
|
|
141
|
+
readonly properties: {
|
|
142
|
+
readonly host: {
|
|
143
|
+
readonly type: "string";
|
|
144
|
+
};
|
|
145
|
+
readonly port: {
|
|
146
|
+
readonly type: "number";
|
|
147
|
+
};
|
|
148
|
+
readonly user: {
|
|
149
|
+
readonly type: "string";
|
|
150
|
+
};
|
|
151
|
+
readonly password: {
|
|
152
|
+
readonly type: "string";
|
|
153
|
+
};
|
|
154
|
+
readonly database: {
|
|
155
|
+
readonly type: "string";
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
}];
|
|
127
159
|
};
|
|
128
160
|
};
|
|
129
161
|
};
|
|
@@ -275,8 +307,40 @@ export declare const defaultAppSettings: {
|
|
|
275
307
|
readonly client: {
|
|
276
308
|
readonly type: "string";
|
|
277
309
|
};
|
|
310
|
+
readonly pool: {
|
|
311
|
+
readonly type: "object";
|
|
312
|
+
readonly properties: {
|
|
313
|
+
readonly min: {
|
|
314
|
+
readonly type: "number";
|
|
315
|
+
};
|
|
316
|
+
readonly max: {
|
|
317
|
+
readonly type: "number";
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
};
|
|
278
321
|
readonly connection: {
|
|
279
|
-
readonly
|
|
322
|
+
readonly oneOf: readonly [{
|
|
323
|
+
readonly type: "string";
|
|
324
|
+
}, {
|
|
325
|
+
readonly type: "object";
|
|
326
|
+
readonly properties: {
|
|
327
|
+
readonly host: {
|
|
328
|
+
readonly type: "string";
|
|
329
|
+
};
|
|
330
|
+
readonly port: {
|
|
331
|
+
readonly type: "number";
|
|
332
|
+
};
|
|
333
|
+
readonly user: {
|
|
334
|
+
readonly type: "string";
|
|
335
|
+
};
|
|
336
|
+
readonly password: {
|
|
337
|
+
readonly type: "string";
|
|
338
|
+
};
|
|
339
|
+
readonly database: {
|
|
340
|
+
readonly type: "string";
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
}];
|
|
280
344
|
};
|
|
281
345
|
};
|
|
282
346
|
};
|
|
@@ -286,8 +350,40 @@ export declare const defaultAppSettings: {
|
|
|
286
350
|
readonly client: {
|
|
287
351
|
readonly type: "string";
|
|
288
352
|
};
|
|
353
|
+
readonly pool: {
|
|
354
|
+
readonly type: "object";
|
|
355
|
+
readonly properties: {
|
|
356
|
+
readonly min: {
|
|
357
|
+
readonly type: "number";
|
|
358
|
+
};
|
|
359
|
+
readonly max: {
|
|
360
|
+
readonly type: "number";
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
};
|
|
289
364
|
readonly connection: {
|
|
290
|
-
readonly
|
|
365
|
+
readonly oneOf: readonly [{
|
|
366
|
+
readonly type: "string";
|
|
367
|
+
}, {
|
|
368
|
+
readonly type: "object";
|
|
369
|
+
readonly properties: {
|
|
370
|
+
readonly host: {
|
|
371
|
+
readonly type: "string";
|
|
372
|
+
};
|
|
373
|
+
readonly port: {
|
|
374
|
+
readonly type: "number";
|
|
375
|
+
};
|
|
376
|
+
readonly user: {
|
|
377
|
+
readonly type: "string";
|
|
378
|
+
};
|
|
379
|
+
readonly password: {
|
|
380
|
+
readonly type: "string";
|
|
381
|
+
};
|
|
382
|
+
readonly database: {
|
|
383
|
+
readonly type: "string";
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
}];
|
|
291
387
|
};
|
|
292
388
|
};
|
|
293
389
|
};
|
|
@@ -297,8 +393,40 @@ export declare const defaultAppSettings: {
|
|
|
297
393
|
readonly client: {
|
|
298
394
|
readonly type: "string";
|
|
299
395
|
};
|
|
396
|
+
readonly pool: {
|
|
397
|
+
readonly type: "object";
|
|
398
|
+
readonly properties: {
|
|
399
|
+
readonly min: {
|
|
400
|
+
readonly type: "number";
|
|
401
|
+
};
|
|
402
|
+
readonly max: {
|
|
403
|
+
readonly type: "number";
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
};
|
|
300
407
|
readonly connection: {
|
|
301
|
-
readonly
|
|
408
|
+
readonly oneOf: readonly [{
|
|
409
|
+
readonly type: "string";
|
|
410
|
+
}, {
|
|
411
|
+
readonly type: "object";
|
|
412
|
+
readonly properties: {
|
|
413
|
+
readonly host: {
|
|
414
|
+
readonly type: "string";
|
|
415
|
+
};
|
|
416
|
+
readonly port: {
|
|
417
|
+
readonly type: "number";
|
|
418
|
+
};
|
|
419
|
+
readonly user: {
|
|
420
|
+
readonly type: "string";
|
|
421
|
+
};
|
|
422
|
+
readonly password: {
|
|
423
|
+
readonly type: "string";
|
|
424
|
+
};
|
|
425
|
+
readonly database: {
|
|
426
|
+
readonly type: "string";
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
}];
|
|
302
430
|
};
|
|
303
431
|
};
|
|
304
432
|
};
|
|
@@ -308,8 +436,40 @@ export declare const defaultAppSettings: {
|
|
|
308
436
|
readonly client: {
|
|
309
437
|
readonly type: "string";
|
|
310
438
|
};
|
|
439
|
+
readonly pool: {
|
|
440
|
+
readonly type: "object";
|
|
441
|
+
readonly properties: {
|
|
442
|
+
readonly min: {
|
|
443
|
+
readonly type: "number";
|
|
444
|
+
};
|
|
445
|
+
readonly max: {
|
|
446
|
+
readonly type: "number";
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
};
|
|
311
450
|
readonly connection: {
|
|
312
|
-
readonly
|
|
451
|
+
readonly oneOf: readonly [{
|
|
452
|
+
readonly type: "string";
|
|
453
|
+
}, {
|
|
454
|
+
readonly type: "object";
|
|
455
|
+
readonly properties: {
|
|
456
|
+
readonly host: {
|
|
457
|
+
readonly type: "string";
|
|
458
|
+
};
|
|
459
|
+
readonly port: {
|
|
460
|
+
readonly type: "number";
|
|
461
|
+
};
|
|
462
|
+
readonly user: {
|
|
463
|
+
readonly type: "string";
|
|
464
|
+
};
|
|
465
|
+
readonly password: {
|
|
466
|
+
readonly type: "string";
|
|
467
|
+
};
|
|
468
|
+
readonly database: {
|
|
469
|
+
readonly type: "string";
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
}];
|
|
313
473
|
};
|
|
314
474
|
};
|
|
315
475
|
};
|
|
@@ -462,8 +622,40 @@ export declare const defaultAppConfiguration: {
|
|
|
462
622
|
readonly client: {
|
|
463
623
|
readonly type: "string";
|
|
464
624
|
};
|
|
625
|
+
readonly pool: {
|
|
626
|
+
readonly type: "object";
|
|
627
|
+
readonly properties: {
|
|
628
|
+
readonly min: {
|
|
629
|
+
readonly type: "number";
|
|
630
|
+
};
|
|
631
|
+
readonly max: {
|
|
632
|
+
readonly type: "number";
|
|
633
|
+
};
|
|
634
|
+
};
|
|
635
|
+
};
|
|
465
636
|
readonly connection: {
|
|
466
|
-
readonly
|
|
637
|
+
readonly oneOf: readonly [{
|
|
638
|
+
readonly type: "string";
|
|
639
|
+
}, {
|
|
640
|
+
readonly type: "object";
|
|
641
|
+
readonly properties: {
|
|
642
|
+
readonly host: {
|
|
643
|
+
readonly type: "string";
|
|
644
|
+
};
|
|
645
|
+
readonly port: {
|
|
646
|
+
readonly type: "number";
|
|
647
|
+
};
|
|
648
|
+
readonly user: {
|
|
649
|
+
readonly type: "string";
|
|
650
|
+
};
|
|
651
|
+
readonly password: {
|
|
652
|
+
readonly type: "string";
|
|
653
|
+
};
|
|
654
|
+
readonly database: {
|
|
655
|
+
readonly type: "string";
|
|
656
|
+
};
|
|
657
|
+
};
|
|
658
|
+
}];
|
|
467
659
|
};
|
|
468
660
|
};
|
|
469
661
|
};
|
|
@@ -473,8 +665,40 @@ export declare const defaultAppConfiguration: {
|
|
|
473
665
|
readonly client: {
|
|
474
666
|
readonly type: "string";
|
|
475
667
|
};
|
|
668
|
+
readonly pool: {
|
|
669
|
+
readonly type: "object";
|
|
670
|
+
readonly properties: {
|
|
671
|
+
readonly min: {
|
|
672
|
+
readonly type: "number";
|
|
673
|
+
};
|
|
674
|
+
readonly max: {
|
|
675
|
+
readonly type: "number";
|
|
676
|
+
};
|
|
677
|
+
};
|
|
678
|
+
};
|
|
476
679
|
readonly connection: {
|
|
477
|
-
readonly
|
|
680
|
+
readonly oneOf: readonly [{
|
|
681
|
+
readonly type: "string";
|
|
682
|
+
}, {
|
|
683
|
+
readonly type: "object";
|
|
684
|
+
readonly properties: {
|
|
685
|
+
readonly host: {
|
|
686
|
+
readonly type: "string";
|
|
687
|
+
};
|
|
688
|
+
readonly port: {
|
|
689
|
+
readonly type: "number";
|
|
690
|
+
};
|
|
691
|
+
readonly user: {
|
|
692
|
+
readonly type: "string";
|
|
693
|
+
};
|
|
694
|
+
readonly password: {
|
|
695
|
+
readonly type: "string";
|
|
696
|
+
};
|
|
697
|
+
readonly database: {
|
|
698
|
+
readonly type: "string";
|
|
699
|
+
};
|
|
700
|
+
};
|
|
701
|
+
}];
|
|
478
702
|
};
|
|
479
703
|
};
|
|
480
704
|
};
|
|
@@ -484,8 +708,40 @@ export declare const defaultAppConfiguration: {
|
|
|
484
708
|
readonly client: {
|
|
485
709
|
readonly type: "string";
|
|
486
710
|
};
|
|
711
|
+
readonly pool: {
|
|
712
|
+
readonly type: "object";
|
|
713
|
+
readonly properties: {
|
|
714
|
+
readonly min: {
|
|
715
|
+
readonly type: "number";
|
|
716
|
+
};
|
|
717
|
+
readonly max: {
|
|
718
|
+
readonly type: "number";
|
|
719
|
+
};
|
|
720
|
+
};
|
|
721
|
+
};
|
|
487
722
|
readonly connection: {
|
|
488
|
-
readonly
|
|
723
|
+
readonly oneOf: readonly [{
|
|
724
|
+
readonly type: "string";
|
|
725
|
+
}, {
|
|
726
|
+
readonly type: "object";
|
|
727
|
+
readonly properties: {
|
|
728
|
+
readonly host: {
|
|
729
|
+
readonly type: "string";
|
|
730
|
+
};
|
|
731
|
+
readonly port: {
|
|
732
|
+
readonly type: "number";
|
|
733
|
+
};
|
|
734
|
+
readonly user: {
|
|
735
|
+
readonly type: "string";
|
|
736
|
+
};
|
|
737
|
+
readonly password: {
|
|
738
|
+
readonly type: "string";
|
|
739
|
+
};
|
|
740
|
+
readonly database: {
|
|
741
|
+
readonly type: "string";
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
}];
|
|
489
745
|
};
|
|
490
746
|
};
|
|
491
747
|
};
|
|
@@ -495,8 +751,40 @@ export declare const defaultAppConfiguration: {
|
|
|
495
751
|
readonly client: {
|
|
496
752
|
readonly type: "string";
|
|
497
753
|
};
|
|
754
|
+
readonly pool: {
|
|
755
|
+
readonly type: "object";
|
|
756
|
+
readonly properties: {
|
|
757
|
+
readonly min: {
|
|
758
|
+
readonly type: "number";
|
|
759
|
+
};
|
|
760
|
+
readonly max: {
|
|
761
|
+
readonly type: "number";
|
|
762
|
+
};
|
|
763
|
+
};
|
|
764
|
+
};
|
|
498
765
|
readonly connection: {
|
|
499
|
-
readonly
|
|
766
|
+
readonly oneOf: readonly [{
|
|
767
|
+
readonly type: "string";
|
|
768
|
+
}, {
|
|
769
|
+
readonly type: "object";
|
|
770
|
+
readonly properties: {
|
|
771
|
+
readonly host: {
|
|
772
|
+
readonly type: "string";
|
|
773
|
+
};
|
|
774
|
+
readonly port: {
|
|
775
|
+
readonly type: "number";
|
|
776
|
+
};
|
|
777
|
+
readonly user: {
|
|
778
|
+
readonly type: "string";
|
|
779
|
+
};
|
|
780
|
+
readonly password: {
|
|
781
|
+
readonly type: "string";
|
|
782
|
+
};
|
|
783
|
+
readonly database: {
|
|
784
|
+
readonly type: "string";
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
}];
|
|
500
788
|
};
|
|
501
789
|
};
|
|
502
790
|
};
|
package/lib/default-schemas.js
CHANGED
|
@@ -112,7 +112,28 @@ exports.sqlSettingsSchema = {
|
|
|
112
112
|
type: 'object',
|
|
113
113
|
properties: {
|
|
114
114
|
client: { type: 'string' },
|
|
115
|
-
|
|
115
|
+
pool: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
min: { type: 'number' },
|
|
119
|
+
max: { type: 'number' }
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
connection: {
|
|
123
|
+
oneOf: [
|
|
124
|
+
{ type: 'string' },
|
|
125
|
+
{
|
|
126
|
+
type: 'object',
|
|
127
|
+
properties: {
|
|
128
|
+
host: { type: 'string' },
|
|
129
|
+
port: { type: 'number' },
|
|
130
|
+
user: { type: 'string' },
|
|
131
|
+
password: { type: 'string' },
|
|
132
|
+
database: { type: 'string' }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
116
137
|
}
|
|
117
138
|
};
|
|
118
139
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-schemas.js","sourceRoot":"","sources":["../src/default-schemas.ts"],"names":[],"mappings":";;;AAEa,QAAA,4BAA4B,GAAG;IAC1C,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,CAAC;IAChD,UAAU,EAAE;QACV,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,wBAAwB;SACtC;QACD,MAAM,EAAE;YACN,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,MAAM;iBACb;gBACD;oBACE,IAAI,EAAE,QAAQ;iBACf;aACF;YACD,WAAW,EAAE,mDAAmD;SACjE;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,mDAAmD;SACjE;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gCAAgC;SAC9C;QACD,cAAc,EAAE;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzB,WAAW,EAAE,sFAAsF;SAC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E,QAAQ,EAAE;SACxB;KACF;IACD,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC3B,KAAK,EAAE,yBAAiB;IACxB,UAAU,EAAE,yBAAiB;IAC7B,MAAM,EAAE,yBAAiB;IACzB,KAAK,EAAE,yBAAiB;CAChB,CAAA;AAEG,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE,0BAAkB;CACtB,CAAA"}
|
package/lib/hooks/resolve.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { HookContext, NextFunction } from '@feathersjs/feathers';
|
|
2
2
|
import { Resolver } from '../resolver';
|
|
3
3
|
export type ResolverSetting<H extends HookContext> = Resolver<any, H> | Resolver<any, H>[];
|
|
4
|
-
export declare const resolveQuery: <
|
|
5
|
-
export declare const resolveData: <
|
|
6
|
-
export declare const resolveResult: <
|
|
4
|
+
export declare const resolveQuery: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<any>;
|
|
5
|
+
export declare const resolveData: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<any>;
|
|
6
|
+
export declare const resolveResult: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>;
|
|
7
7
|
export declare const DISPATCH: unique symbol;
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export
|
|
8
|
+
export declare const getDispatchValue: (value: any) => any;
|
|
9
|
+
export declare const getDispatch: (value: any) => any;
|
|
10
|
+
export declare const setDispatch: (current: any, dispatch: any) => any;
|
|
11
|
+
export declare const resolveDispatch: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>;
|
|
12
|
+
export declare const resolveExternal: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(...resolvers: Resolver<any, H>[]) => (context: H, next?: NextFunction) => Promise<void>;
|
|
13
|
+
type ResolveAllSettings<H extends HookContext> = {
|
|
12
14
|
data?: {
|
|
13
15
|
create: Resolver<any, H>;
|
|
14
16
|
patch: Resolver<any, H>;
|
|
@@ -18,4 +20,13 @@ export type ResolveAllSettings<H extends HookContext> = {
|
|
|
18
20
|
result?: Resolver<any, H>;
|
|
19
21
|
dispatch?: Resolver<any, H>;
|
|
20
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Resolve all resolvers at once.
|
|
25
|
+
*
|
|
26
|
+
* @param map The individual resolvers
|
|
27
|
+
* @returns A combined resolver middleware
|
|
28
|
+
* @deprecated Use individual data, query and external resolvers and hooks instead.
|
|
29
|
+
* @see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
30
|
+
*/
|
|
21
31
|
export declare const resolveAll: <H extends HookContext<import("@feathersjs/feathers").Application<any, any>, any>>(map: ResolveAllSettings<H>) => (this: any, context: H, next?: import("@feathersjs/hooks").AsyncMiddleware<H>) => Promise<any>;
|
|
32
|
+
export {};
|
package/lib/hooks/resolve.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveAll = exports.resolveExternal = exports.resolveDispatch = exports.getDispatch = exports.DISPATCH = exports.resolveResult = exports.resolveData = exports.resolveQuery = void 0;
|
|
3
|
+
exports.resolveAll = exports.resolveExternal = exports.resolveDispatch = exports.setDispatch = exports.getDispatch = exports.getDispatchValue = exports.DISPATCH = exports.resolveResult = exports.resolveData = exports.resolveQuery = void 0;
|
|
4
4
|
const hooks_1 = require("@feathersjs/hooks");
|
|
5
5
|
const getContext = (context) => {
|
|
6
6
|
return Object.freeze({
|
|
@@ -11,7 +11,7 @@ const getContext = (context) => {
|
|
|
11
11
|
})
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
|
-
const
|
|
14
|
+
const getResult = (context) => {
|
|
15
15
|
const isPaginated = context.method === 'find' && context.result.data;
|
|
16
16
|
const data = isPaginated ? context.result.data : context.result;
|
|
17
17
|
return { isPaginated, data };
|
|
@@ -75,14 +75,14 @@ const resolveResult = (...resolvers) => {
|
|
|
75
75
|
resolve,
|
|
76
76
|
query: {
|
|
77
77
|
...query,
|
|
78
|
-
$select
|
|
78
|
+
...($select ? { $select } : {})
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
await next();
|
|
82
82
|
}
|
|
83
83
|
const ctx = getContext(context);
|
|
84
84
|
const status = context.params.resolve;
|
|
85
|
-
const { isPaginated, data } =
|
|
85
|
+
const { isPaginated, data } = getResult(context);
|
|
86
86
|
const result = Array.isArray(data)
|
|
87
87
|
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, ctx, status)))
|
|
88
88
|
: await runResolvers(resolvers, data, ctx, status);
|
|
@@ -96,26 +96,48 @@ const resolveResult = (...resolvers) => {
|
|
|
96
96
|
};
|
|
97
97
|
exports.resolveResult = resolveResult;
|
|
98
98
|
exports.DISPATCH = Symbol('@feathersjs/schema/dispatch');
|
|
99
|
-
const
|
|
99
|
+
const getDispatchValue = (value) => {
|
|
100
|
+
if (typeof value === 'object' && value !== null) {
|
|
101
|
+
if (value[exports.DISPATCH] !== undefined) {
|
|
102
|
+
return value[exports.DISPATCH];
|
|
103
|
+
}
|
|
104
|
+
if (Array.isArray(value)) {
|
|
105
|
+
return value.map((item) => (0, exports.getDispatchValue)(item));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
};
|
|
110
|
+
exports.getDispatchValue = getDispatchValue;
|
|
111
|
+
const getDispatch = (value) => typeof value === 'object' && value !== null && value[exports.DISPATCH] ? value[exports.DISPATCH] : null;
|
|
100
112
|
exports.getDispatch = getDispatch;
|
|
113
|
+
const setDispatch = (current, dispatch) => {
|
|
114
|
+
Object.defineProperty(current, exports.DISPATCH, {
|
|
115
|
+
value: dispatch,
|
|
116
|
+
enumerable: false,
|
|
117
|
+
configurable: false
|
|
118
|
+
});
|
|
119
|
+
return dispatch;
|
|
120
|
+
};
|
|
121
|
+
exports.setDispatch = setDispatch;
|
|
101
122
|
const resolveDispatch = (...resolvers) => async (context, next) => {
|
|
102
123
|
if (typeof next === 'function') {
|
|
103
124
|
await next();
|
|
104
125
|
}
|
|
105
126
|
const ctx = getContext(context);
|
|
106
|
-
const existingDispatch = (0, exports.getDispatch)(context.result
|
|
127
|
+
const existingDispatch = (0, exports.getDispatch)(context.result);
|
|
107
128
|
if (existingDispatch !== null) {
|
|
108
129
|
context.dispatch = existingDispatch;
|
|
109
130
|
}
|
|
110
131
|
else {
|
|
111
132
|
const status = context.params.resolve;
|
|
112
|
-
const { isPaginated, data } =
|
|
133
|
+
const { isPaginated, data } = getResult(context);
|
|
113
134
|
const resolveAndGetDispatch = async (current) => {
|
|
114
135
|
const resolved = await runResolvers(resolvers, current, ctx, status);
|
|
115
|
-
|
|
116
|
-
res[key] = (0, exports.
|
|
136
|
+
const currentDispatch = Object.keys(resolved).reduce((res, key) => {
|
|
137
|
+
res[key] = (0, exports.getDispatchValue)(resolved[key]);
|
|
117
138
|
return res;
|
|
118
139
|
}, {});
|
|
140
|
+
return (0, exports.setDispatch)(current, currentDispatch);
|
|
119
141
|
};
|
|
120
142
|
const result = await (Array.isArray(data)
|
|
121
143
|
? Promise.all(data.map(resolveAndGetDispatch))
|
|
@@ -126,17 +148,20 @@ const resolveDispatch = (...resolvers) => async (context, next) => {
|
|
|
126
148
|
data: result
|
|
127
149
|
}
|
|
128
150
|
: result;
|
|
129
|
-
context.dispatch = dispatch;
|
|
130
|
-
Object.defineProperty(context.result, exports.DISPATCH, {
|
|
131
|
-
value: dispatch,
|
|
132
|
-
enumerable: false,
|
|
133
|
-
configurable: false
|
|
134
|
-
});
|
|
151
|
+
context.dispatch = (0, exports.setDispatch)(context.result, dispatch);
|
|
135
152
|
}
|
|
136
153
|
};
|
|
137
154
|
exports.resolveDispatch = resolveDispatch;
|
|
138
155
|
exports.resolveExternal = exports.resolveDispatch;
|
|
139
156
|
const dataMethods = ['create', 'update', 'patch'];
|
|
157
|
+
/**
|
|
158
|
+
* Resolve all resolvers at once.
|
|
159
|
+
*
|
|
160
|
+
* @param map The individual resolvers
|
|
161
|
+
* @returns A combined resolver middleware
|
|
162
|
+
* @deprecated Use individual data, query and external resolvers and hooks instead.
|
|
163
|
+
* @see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
164
|
+
*/
|
|
140
165
|
const resolveAll = (map) => {
|
|
141
166
|
const middleware = [];
|
|
142
167
|
middleware.push((0, exports.resolveDispatch)(map.dispatch));
|
package/lib/hooks/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/hooks/resolve.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAG3C,MAAM,UAAU,GAAG,CAAwB,OAAU,EAAE,EAAE;IACvD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,OAAO;QACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACpB,GAAG,OAAO,CAAC,MAAM;YACjB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;SACzB,CAAC;KACH,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/hooks/resolve.ts"],"names":[],"mappings":";;;AACA,6CAA2C;AAG3C,MAAM,UAAU,GAAG,CAAwB,OAAU,EAAE,EAAE;IACvD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,OAAO;QACV,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACpB,GAAG,OAAO,CAAC,MAAM;YACjB,KAAK,EAAE,MAAM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E5C,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAU,EAAE,IAAkB,EAAE,EAAE,CACvD,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAC3D,CAAA;aACF;QACH,CAAC,CAAC,CAAA;KACH;IAED,OAAO,IAAA,eAAO,EAAC,UAAU,CAAC,CAAA;AAC5B,CAAC,CAAA;AA1BY,QAAA,UAAU,cA0BtB"}
|
package/lib/json-schema.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare const getValidator: <T = any, R = T>(schema: JSONSchemaDefinition
|
|
|
29
29
|
* @returns A map of validator functions
|
|
30
30
|
*/
|
|
31
31
|
export declare const getDataValidator: (def: JSONSchemaDefinition | DataSchemaMap, validator: Ajv) => DataValidatorMap;
|
|
32
|
-
export type PropertyQuery<D extends JSONSchema> = {
|
|
32
|
+
export type PropertyQuery<D extends JSONSchema, X> = {
|
|
33
33
|
anyOf: [
|
|
34
34
|
D,
|
|
35
35
|
{
|
|
@@ -49,7 +49,7 @@ export type PropertyQuery<D extends JSONSchema> = {
|
|
|
49
49
|
type: 'array';
|
|
50
50
|
items: D;
|
|
51
51
|
};
|
|
52
|
-
};
|
|
52
|
+
} & X;
|
|
53
53
|
}
|
|
54
54
|
];
|
|
55
55
|
};
|
|
@@ -57,9 +57,12 @@ export type PropertyQuery<D extends JSONSchema> = {
|
|
|
57
57
|
* Create a Feathers query syntax compatible JSON schema definition for a property definition.
|
|
58
58
|
*
|
|
59
59
|
* @param def The property definition (e.g. `{ type: 'string' }`)
|
|
60
|
+
* @param extensions Additional properties to add to the query property schema
|
|
60
61
|
* @returns A JSON schema definition for the Feathers query syntax for this property.
|
|
61
62
|
*/
|
|
62
|
-
export declare const queryProperty: <T extends import("json-schema-to-ts").JSONSchema7
|
|
63
|
+
export declare const queryProperty: <T extends import("json-schema-to-ts").JSONSchema7, X extends {
|
|
64
|
+
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
65
|
+
}>(def: T, extensions?: X) => {
|
|
63
66
|
readonly anyOf: readonly [any, {
|
|
64
67
|
readonly type: "object";
|
|
65
68
|
readonly additionalProperties: false;
|
|
@@ -77,29 +80,34 @@ export declare const queryProperty: <T extends import("json-schema-to-ts").JSONS
|
|
|
77
80
|
readonly type: "array";
|
|
78
81
|
readonly items: any;
|
|
79
82
|
};
|
|
80
|
-
};
|
|
83
|
+
} & X;
|
|
81
84
|
}];
|
|
82
85
|
};
|
|
83
|
-
export declare const SUPPORTED_TYPES: string[];
|
|
84
86
|
/**
|
|
85
87
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
86
88
|
*
|
|
87
89
|
* @param definitions A map of property definitions
|
|
90
|
+
* @param extensions Additional properties to add to the query property schema
|
|
88
91
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
89
92
|
*/
|
|
90
93
|
export declare const queryProperties: <T extends {
|
|
91
94
|
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
92
|
-
}
|
|
95
|
+
}, X extends { [K in keyof T]?: {
|
|
96
|
+
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
97
|
+
}; }>(definitions: T, extensions?: X) => { [K_1 in keyof T]: PropertyQuery<T[K_1], X[K_1]>; };
|
|
93
98
|
/**
|
|
94
99
|
* Creates a JSON schema for the complete Feathers query syntax including `$limit`, $skip`
|
|
95
100
|
* and `$sort` and `$select` for the allowed properties.
|
|
96
101
|
*
|
|
97
102
|
* @param definition The property definitions to create the query syntax schema for
|
|
103
|
+
* @param extensions Additional properties to add to the query property schema
|
|
98
104
|
* @returns A JSON schema for the complete query syntax
|
|
99
105
|
*/
|
|
100
106
|
export declare const querySyntax: <T extends {
|
|
101
107
|
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
102
|
-
}
|
|
108
|
+
}, X extends { [K in keyof T]?: {
|
|
109
|
+
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
110
|
+
}; }>(definition: T, extensions?: X) => {
|
|
103
111
|
readonly $limit: {
|
|
104
112
|
readonly type: "number";
|
|
105
113
|
readonly minimum: 0;
|
|
@@ -110,7 +118,7 @@ export declare const querySyntax: <T extends {
|
|
|
110
118
|
};
|
|
111
119
|
readonly $sort: {
|
|
112
120
|
readonly type: "object";
|
|
113
|
-
readonly properties: { [
|
|
121
|
+
readonly properties: { [K_1 in keyof T]: {
|
|
114
122
|
readonly type: 'number';
|
|
115
123
|
readonly enum: [1, -1];
|
|
116
124
|
}; };
|
|
@@ -128,7 +136,24 @@ export declare const querySyntax: <T extends {
|
|
|
128
136
|
readonly items: {
|
|
129
137
|
readonly type: "object";
|
|
130
138
|
readonly additionalProperties: false;
|
|
131
|
-
readonly properties: { [
|
|
139
|
+
readonly properties: { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; };
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
readonly $and: {
|
|
143
|
+
readonly type: "array";
|
|
144
|
+
readonly items: {
|
|
145
|
+
readonly type: "object";
|
|
146
|
+
readonly additionalProperties: false;
|
|
147
|
+
readonly properties: { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; } & {
|
|
148
|
+
readonly $or: {
|
|
149
|
+
readonly type: "array";
|
|
150
|
+
readonly items: {
|
|
151
|
+
readonly type: "object";
|
|
152
|
+
readonly additionalProperties: false;
|
|
153
|
+
readonly properties: { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; };
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
};
|
|
132
157
|
};
|
|
133
158
|
};
|
|
134
|
-
} & { [
|
|
159
|
+
} & { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; };
|
package/lib/json-schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.querySyntax = exports.queryProperties = exports.
|
|
3
|
+
exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.getDataValidator = exports.getValidator = void 0;
|
|
4
4
|
const commons_1 = require("@feathersjs/commons");
|
|
5
5
|
/**
|
|
6
6
|
* Returns a compiled validation function for a schema and AJV validator instance.
|
|
@@ -44,9 +44,10 @@ exports.getDataValidator = getDataValidator;
|
|
|
44
44
|
* Create a Feathers query syntax compatible JSON schema definition for a property definition.
|
|
45
45
|
*
|
|
46
46
|
* @param def The property definition (e.g. `{ type: 'string' }`)
|
|
47
|
+
* @param extensions Additional properties to add to the query property schema
|
|
47
48
|
* @returns A JSON schema definition for the Feathers query syntax for this property.
|
|
48
49
|
*/
|
|
49
|
-
const queryProperty = (def) => {
|
|
50
|
+
const queryProperty = (def, extensions = {}) => {
|
|
50
51
|
const definition = commons_1._.omit(def, 'default');
|
|
51
52
|
return {
|
|
52
53
|
anyOf: [
|
|
@@ -67,28 +68,29 @@ const queryProperty = (def) => {
|
|
|
67
68
|
$nin: {
|
|
68
69
|
type: 'array',
|
|
69
70
|
items: definition
|
|
70
|
-
}
|
|
71
|
+
},
|
|
72
|
+
...extensions
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
]
|
|
74
76
|
};
|
|
75
77
|
};
|
|
76
78
|
exports.queryProperty = queryProperty;
|
|
77
|
-
exports.SUPPORTED_TYPES = ['string', 'number', 'integer', 'boolean', 'null'];
|
|
78
79
|
/**
|
|
79
80
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
80
81
|
*
|
|
81
82
|
* @param definitions A map of property definitions
|
|
83
|
+
* @param extensions Additional properties to add to the query property schema
|
|
82
84
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
83
85
|
*/
|
|
84
|
-
const queryProperties = (definitions) => Object.keys(definitions).reduce((res, key) => {
|
|
86
|
+
const queryProperties = (definitions, extensions = {}) => Object.keys(definitions).reduce((res, key) => {
|
|
85
87
|
const result = res;
|
|
86
88
|
const definition = definitions[key];
|
|
87
|
-
const {
|
|
88
|
-
if ($ref
|
|
89
|
-
throw new Error(`Can not create query syntax schema for property '${key}'
|
|
89
|
+
const { $ref } = definition;
|
|
90
|
+
if ($ref) {
|
|
91
|
+
throw new Error(`Can not create query syntax schema for reference property '${key}'`);
|
|
90
92
|
}
|
|
91
|
-
result[key] = (0, exports.queryProperty)(definition);
|
|
93
|
+
result[key] = (0, exports.queryProperty)(definition, extensions[key]);
|
|
92
94
|
return result;
|
|
93
95
|
}, {});
|
|
94
96
|
exports.queryProperties = queryProperties;
|
|
@@ -97,11 +99,31 @@ exports.queryProperties = queryProperties;
|
|
|
97
99
|
* and `$sort` and `$select` for the allowed properties.
|
|
98
100
|
*
|
|
99
101
|
* @param definition The property definitions to create the query syntax schema for
|
|
102
|
+
* @param extensions Additional properties to add to the query property schema
|
|
100
103
|
* @returns A JSON schema for the complete query syntax
|
|
101
104
|
*/
|
|
102
|
-
const querySyntax = (definition) => {
|
|
105
|
+
const querySyntax = (definition, extensions = {}) => {
|
|
103
106
|
const keys = Object.keys(definition);
|
|
104
|
-
const props = (0, exports.queryProperties)(definition);
|
|
107
|
+
const props = (0, exports.queryProperties)(definition, extensions);
|
|
108
|
+
const $or = {
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
additionalProperties: false,
|
|
113
|
+
properties: props
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const $and = {
|
|
117
|
+
type: 'array',
|
|
118
|
+
items: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
additionalProperties: false,
|
|
121
|
+
properties: {
|
|
122
|
+
...props,
|
|
123
|
+
$or
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
105
127
|
return {
|
|
106
128
|
$limit: {
|
|
107
129
|
type: 'number',
|
|
@@ -130,14 +152,8 @@ const querySyntax = (definition) => {
|
|
|
130
152
|
...(keys.length > 0 ? { enum: keys } : {})
|
|
131
153
|
}
|
|
132
154
|
},
|
|
133
|
-
$or
|
|
134
|
-
|
|
135
|
-
items: {
|
|
136
|
-
type: 'object',
|
|
137
|
-
additionalProperties: false,
|
|
138
|
-
properties: props
|
|
139
|
-
}
|
|
140
|
-
},
|
|
155
|
+
$or,
|
|
156
|
+
$and,
|
|
141
157
|
...props
|
|
142
158
|
};
|
|
143
159
|
};
|
package/lib/json-schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":";;;AAAA,iDAAuC;AAgBvC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAiB,MAA4B,EAAE,SAAc,EAAmB,EAAE,CAC5G,SAAS,CAAC,OAAO,CAAC;IAChB,MAAM,EAAE,IAAI;IACZ,GAAI,MAAc;CACnB,CAA2B,CAAA;AAJjB,QAAA,YAAY,gBAIK;AAE9B;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAAG,CAC9B,GAAyC,EACzC,SAAc,EACI,EAAE;IACpB,MAAM,MAAM,GAAG,CAAE,GAAW,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAkB,CAAA;IAE7E,OAAO;QACL,MAAM,EAAE,IAAA,oBAAY,EAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;QAC9C,MAAM,EAAE,IAAA,oBAAY,EAClB,MAAM,CAAC,MAAM,IAAI;YACf,GAAI,MAAM,CAAC,MAAc;YACzB,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ;SAClC,EACD,SAAS,CACV;QACD,KAAK,EAAE,IAAA,oBAAY,EACjB,MAAM,CAAC,KAAK,IAAI;YACd,GAAI,MAAM,CAAC,MAAc;YACzB,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO;YAChC,QAAQ,EAAE,EAAE;SACb,EACD,SA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,KAAK;KACA,CAAA;AACZ,CAAC,CAAA;AA/DY,QAAA,WAAW,eA+DvB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/schema",
|
|
3
3
|
"description": "A common data schema definition format",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.36",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
44
|
"prepublish": "npm run compile",
|
|
45
|
-
"pack": "npm pack --pack-destination ../
|
|
45
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
46
46
|
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
47
47
|
"mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
|
|
48
48
|
"test": "npm run compile && npm run mocha"
|
|
@@ -54,24 +54,24 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@feathersjs/adapter-commons": "^5.0.0-pre.
|
|
58
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
59
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
60
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
57
|
+
"@feathersjs/adapter-commons": "^5.0.0-pre.36",
|
|
58
|
+
"@feathersjs/commons": "^5.0.0-pre.36",
|
|
59
|
+
"@feathersjs/errors": "^5.0.0-pre.36",
|
|
60
|
+
"@feathersjs/feathers": "^5.0.0-pre.36",
|
|
61
61
|
"@feathersjs/hooks": "^0.7.6",
|
|
62
62
|
"@types/json-schema": "^7.0.11",
|
|
63
|
-
"ajv": "^8.
|
|
63
|
+
"ajv": "^8.12.0",
|
|
64
64
|
"ajv-formats": "^2.1.1",
|
|
65
|
-
"json-schema-to-ts": "^2.6.
|
|
65
|
+
"json-schema-to-ts": "^2.6.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@feathersjs/memory": "^5.0.0-pre.
|
|
68
|
+
"@feathersjs/memory": "^5.0.0-pre.36",
|
|
69
69
|
"@types/mocha": "^10.0.1",
|
|
70
|
-
"@types/node": "^18.11.
|
|
70
|
+
"@types/node": "^18.11.18",
|
|
71
71
|
"ajv-formats": "^2.1.1",
|
|
72
|
-
"mocha": "^10.
|
|
72
|
+
"mocha": "^10.2.0",
|
|
73
73
|
"shx": "^0.3.4",
|
|
74
|
-
"typescript": "^4.9.
|
|
74
|
+
"typescript": "^4.9.4"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "9a107b463cc80d7f3c28553c908987e05b0b634a"
|
|
77
77
|
}
|
package/src/default-schemas.ts
CHANGED
|
@@ -117,7 +117,28 @@ export const sqlSettingsSchema = {
|
|
|
117
117
|
type: 'object',
|
|
118
118
|
properties: {
|
|
119
119
|
client: { type: 'string' },
|
|
120
|
-
|
|
120
|
+
pool: {
|
|
121
|
+
type: 'object',
|
|
122
|
+
properties: {
|
|
123
|
+
min: { type: 'number' },
|
|
124
|
+
max: { type: 'number' }
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
connection: {
|
|
128
|
+
oneOf: [
|
|
129
|
+
{ type: 'string' },
|
|
130
|
+
{
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
host: { type: 'string' },
|
|
134
|
+
port: { type: 'number' },
|
|
135
|
+
user: { type: 'string' },
|
|
136
|
+
password: { type: 'string' },
|
|
137
|
+
database: { type: 'string' }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
121
142
|
}
|
|
122
143
|
} as const
|
|
123
144
|
|
package/src/hooks/resolve.ts
CHANGED
|
@@ -12,7 +12,7 @@ const getContext = <H extends HookContext>(context: H) => {
|
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const getResult = <H extends HookContext>(context: H) => {
|
|
16
16
|
const isPaginated = context.method === 'find' && context.result.data
|
|
17
17
|
const data = isPaginated ? context.result.data : context.result
|
|
18
18
|
|
|
@@ -39,7 +39,7 @@ const runResolvers = async <T, H extends HookContext>(
|
|
|
39
39
|
export type ResolverSetting<H extends HookContext> = Resolver<any, H> | Resolver<any, H>[]
|
|
40
40
|
|
|
41
41
|
export const resolveQuery =
|
|
42
|
-
<
|
|
42
|
+
<H extends HookContext>(...resolvers: Resolver<any, H>[]) =>
|
|
43
43
|
async (context: H, next?: NextFunction) => {
|
|
44
44
|
const ctx = getContext(context)
|
|
45
45
|
const data = context?.params?.query || {}
|
|
@@ -56,7 +56,7 @@ export const resolveQuery =
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export const resolveData =
|
|
59
|
-
<
|
|
59
|
+
<H extends HookContext>(...resolvers: Resolver<any, H>[]) =>
|
|
60
60
|
async (context: H, next?: NextFunction) => {
|
|
61
61
|
if (context.data !== undefined) {
|
|
62
62
|
const ctx = getContext(context)
|
|
@@ -78,10 +78,8 @@ export const resolveData =
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export const resolveResult = <
|
|
82
|
-
const virtualProperties = new Set(
|
|
83
|
-
resolvers.reduce((acc, current) => acc.concat(current.virtualNames), [] as (keyof T)[])
|
|
84
|
-
)
|
|
81
|
+
export const resolveResult = <H extends HookContext>(...resolvers: Resolver<any, H>[]) => {
|
|
82
|
+
const virtualProperties = new Set(resolvers.reduce((acc, current) => acc.concat(current.virtualNames), []))
|
|
85
83
|
|
|
86
84
|
return async (context: H, next?: NextFunction) => {
|
|
87
85
|
if (typeof next === 'function') {
|
|
@@ -98,7 +96,7 @@ export const resolveResult = <T, H extends HookContext>(...resolvers: Resolver<T
|
|
|
98
96
|
resolve,
|
|
99
97
|
query: {
|
|
100
98
|
...query,
|
|
101
|
-
$select
|
|
99
|
+
...($select ? { $select } : {})
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
102
|
|
|
@@ -107,7 +105,7 @@ export const resolveResult = <T, H extends HookContext>(...resolvers: Resolver<T
|
|
|
107
105
|
|
|
108
106
|
const ctx = getContext(context)
|
|
109
107
|
const status = context.params.resolve
|
|
110
|
-
const { isPaginated, data } =
|
|
108
|
+
const { isPaginated, data } = getResult(context)
|
|
111
109
|
|
|
112
110
|
const result = Array.isArray(data)
|
|
113
111
|
? await Promise.all(data.map(async (current) => runResolvers(resolvers, current, ctx, status)))
|
|
@@ -123,32 +121,57 @@ export const resolveResult = <T, H extends HookContext>(...resolvers: Resolver<T
|
|
|
123
121
|
|
|
124
122
|
export const DISPATCH = Symbol('@feathersjs/schema/dispatch')
|
|
125
123
|
|
|
126
|
-
export const
|
|
127
|
-
typeof value === 'object' && value !== null
|
|
124
|
+
export const getDispatchValue = (value: any): any => {
|
|
125
|
+
if (typeof value === 'object' && value !== null) {
|
|
126
|
+
if (value[DISPATCH] !== undefined) {
|
|
127
|
+
return value[DISPATCH]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
return value.map((item) => getDispatchValue(item))
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return value
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const getDispatch = (value: any): any =>
|
|
139
|
+
typeof value === 'object' && value !== null && value[DISPATCH] ? value[DISPATCH] : null
|
|
140
|
+
|
|
141
|
+
export const setDispatch = (current: any, dispatch: any) => {
|
|
142
|
+
Object.defineProperty(current, DISPATCH, {
|
|
143
|
+
value: dispatch,
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: false
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
return dispatch
|
|
149
|
+
}
|
|
128
150
|
|
|
129
151
|
export const resolveDispatch =
|
|
130
|
-
<
|
|
152
|
+
<H extends HookContext>(...resolvers: Resolver<any, H>[]) =>
|
|
131
153
|
async (context: H, next?: NextFunction) => {
|
|
132
154
|
if (typeof next === 'function') {
|
|
133
155
|
await next()
|
|
134
156
|
}
|
|
135
157
|
|
|
136
158
|
const ctx = getContext(context)
|
|
137
|
-
const existingDispatch = getDispatch(context.result
|
|
159
|
+
const existingDispatch = getDispatch(context.result)
|
|
138
160
|
|
|
139
161
|
if (existingDispatch !== null) {
|
|
140
162
|
context.dispatch = existingDispatch
|
|
141
163
|
} else {
|
|
142
164
|
const status = context.params.resolve
|
|
143
|
-
const { isPaginated, data } =
|
|
165
|
+
const { isPaginated, data } = getResult(context)
|
|
144
166
|
const resolveAndGetDispatch = async (current: any) => {
|
|
145
|
-
const resolved
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
res[key] = getDispatch(resolved[key])
|
|
167
|
+
const resolved = await runResolvers(resolvers, current, ctx, status)
|
|
168
|
+
const currentDispatch = Object.keys(resolved).reduce((res, key) => {
|
|
169
|
+
res[key] = getDispatchValue(resolved[key])
|
|
149
170
|
|
|
150
171
|
return res
|
|
151
|
-
}, {} as any)
|
|
172
|
+
}, {} as Record<string, any>)
|
|
173
|
+
|
|
174
|
+
return setDispatch(current, currentDispatch)
|
|
152
175
|
}
|
|
153
176
|
|
|
154
177
|
const result = await (Array.isArray(data)
|
|
@@ -161,18 +184,13 @@ export const resolveDispatch =
|
|
|
161
184
|
}
|
|
162
185
|
: result
|
|
163
186
|
|
|
164
|
-
context.dispatch = dispatch
|
|
165
|
-
Object.defineProperty(context.result, DISPATCH, {
|
|
166
|
-
value: dispatch,
|
|
167
|
-
enumerable: false,
|
|
168
|
-
configurable: false
|
|
169
|
-
})
|
|
187
|
+
context.dispatch = setDispatch(context.result, dispatch)
|
|
170
188
|
}
|
|
171
189
|
}
|
|
172
190
|
|
|
173
191
|
export const resolveExternal = resolveDispatch
|
|
174
192
|
|
|
175
|
-
|
|
193
|
+
type ResolveAllSettings<H extends HookContext> = {
|
|
176
194
|
data?: {
|
|
177
195
|
create: Resolver<any, H>
|
|
178
196
|
patch: Resolver<any, H>
|
|
@@ -185,6 +203,14 @@ export type ResolveAllSettings<H extends HookContext> = {
|
|
|
185
203
|
|
|
186
204
|
const dataMethods = ['create', 'update', 'patch'] as const
|
|
187
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Resolve all resolvers at once.
|
|
208
|
+
*
|
|
209
|
+
* @param map The individual resolvers
|
|
210
|
+
* @returns A combined resolver middleware
|
|
211
|
+
* @deprecated Use individual data, query and external resolvers and hooks instead.
|
|
212
|
+
* @see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
213
|
+
*/
|
|
188
214
|
export const resolveAll = <H extends HookContext>(map: ResolveAllSettings<H>) => {
|
|
189
215
|
const middleware = []
|
|
190
216
|
|
package/src/json-schema.ts
CHANGED
|
@@ -63,7 +63,7 @@ export const getDataValidator = (
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export type PropertyQuery<D extends JSONSchema> = {
|
|
66
|
+
export type PropertyQuery<D extends JSONSchema, X> = {
|
|
67
67
|
anyOf: [
|
|
68
68
|
D,
|
|
69
69
|
{
|
|
@@ -83,7 +83,7 @@ export type PropertyQuery<D extends JSONSchema> = {
|
|
|
83
83
|
type: 'array'
|
|
84
84
|
items: D
|
|
85
85
|
}
|
|
86
|
-
}
|
|
86
|
+
} & X
|
|
87
87
|
}
|
|
88
88
|
]
|
|
89
89
|
}
|
|
@@ -92,9 +92,13 @@ export type PropertyQuery<D extends JSONSchema> = {
|
|
|
92
92
|
* Create a Feathers query syntax compatible JSON schema definition for a property definition.
|
|
93
93
|
*
|
|
94
94
|
* @param def The property definition (e.g. `{ type: 'string' }`)
|
|
95
|
+
* @param extensions Additional properties to add to the query property schema
|
|
95
96
|
* @returns A JSON schema definition for the Feathers query syntax for this property.
|
|
96
97
|
*/
|
|
97
|
-
export const queryProperty = <T extends JSONSchema
|
|
98
|
+
export const queryProperty = <T extends JSONSchema, X extends { [key: string]: JSONSchema }>(
|
|
99
|
+
def: T,
|
|
100
|
+
extensions: X = {} as X
|
|
101
|
+
) => {
|
|
98
102
|
const definition = _.omit(def, 'default')
|
|
99
103
|
return {
|
|
100
104
|
anyOf: [
|
|
@@ -115,50 +119,78 @@ export const queryProperty = <T extends JSONSchema>(def: T) => {
|
|
|
115
119
|
$nin: {
|
|
116
120
|
type: 'array',
|
|
117
121
|
items: definition
|
|
118
|
-
}
|
|
122
|
+
},
|
|
123
|
+
...extensions
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
]
|
|
122
127
|
} as const
|
|
123
128
|
}
|
|
124
129
|
|
|
125
|
-
export const SUPPORTED_TYPES = ['string', 'number', 'integer', 'boolean', 'null']
|
|
126
|
-
|
|
127
130
|
/**
|
|
128
131
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
129
132
|
*
|
|
130
133
|
* @param definitions A map of property definitions
|
|
134
|
+
* @param extensions Additional properties to add to the query property schema
|
|
131
135
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
132
136
|
*/
|
|
133
|
-
export const queryProperties = <
|
|
137
|
+
export const queryProperties = <
|
|
138
|
+
T extends { [key: string]: JSONSchema },
|
|
139
|
+
X extends { [K in keyof T]?: { [key: string]: JSONSchema } }
|
|
140
|
+
>(
|
|
141
|
+
definitions: T,
|
|
142
|
+
extensions: X = {} as X
|
|
143
|
+
) =>
|
|
134
144
|
Object.keys(definitions).reduce((res, key) => {
|
|
135
145
|
const result = res as any
|
|
136
146
|
const definition = definitions[key]
|
|
137
|
-
const {
|
|
147
|
+
const { $ref } = definition as any
|
|
138
148
|
|
|
139
|
-
if ($ref
|
|
140
|
-
throw new Error(
|
|
141
|
-
`Can not create query syntax schema for property '${key}'. Only types ${SUPPORTED_TYPES.join(
|
|
142
|
-
', '
|
|
143
|
-
)} are allowed.`
|
|
144
|
-
)
|
|
149
|
+
if ($ref) {
|
|
150
|
+
throw new Error(`Can not create query syntax schema for reference property '${key}'`)
|
|
145
151
|
}
|
|
146
152
|
|
|
147
|
-
result[key] = queryProperty(definition)
|
|
153
|
+
result[key] = queryProperty(definition as JSONSchemaDefinition, extensions[key as keyof T])
|
|
148
154
|
|
|
149
155
|
return result
|
|
150
|
-
}, {} as { [K in keyof T]: PropertyQuery<T[K]> })
|
|
156
|
+
}, {} as { [K in keyof T]: PropertyQuery<T[K], X[K]> })
|
|
151
157
|
|
|
152
158
|
/**
|
|
153
159
|
* Creates a JSON schema for the complete Feathers query syntax including `$limit`, $skip`
|
|
154
160
|
* and `$sort` and `$select` for the allowed properties.
|
|
155
161
|
*
|
|
156
162
|
* @param definition The property definitions to create the query syntax schema for
|
|
163
|
+
* @param extensions Additional properties to add to the query property schema
|
|
157
164
|
* @returns A JSON schema for the complete query syntax
|
|
158
165
|
*/
|
|
159
|
-
export const querySyntax = <
|
|
166
|
+
export const querySyntax = <
|
|
167
|
+
T extends { [key: string]: JSONSchema },
|
|
168
|
+
X extends { [K in keyof T]?: { [key: string]: JSONSchema } }
|
|
169
|
+
>(
|
|
170
|
+
definition: T,
|
|
171
|
+
extensions: X = {} as X
|
|
172
|
+
) => {
|
|
160
173
|
const keys = Object.keys(definition)
|
|
161
|
-
const props = queryProperties(definition)
|
|
174
|
+
const props = queryProperties(definition, extensions)
|
|
175
|
+
const $or = {
|
|
176
|
+
type: 'array',
|
|
177
|
+
items: {
|
|
178
|
+
type: 'object',
|
|
179
|
+
additionalProperties: false,
|
|
180
|
+
properties: props
|
|
181
|
+
}
|
|
182
|
+
} as const
|
|
183
|
+
const $and = {
|
|
184
|
+
type: 'array',
|
|
185
|
+
items: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
additionalProperties: false,
|
|
188
|
+
properties: {
|
|
189
|
+
...props,
|
|
190
|
+
$or
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} as const
|
|
162
194
|
|
|
163
195
|
return {
|
|
164
196
|
$limit: {
|
|
@@ -190,14 +222,8 @@ export const querySyntax = <T extends { [key: string]: JSONSchema }>(definition:
|
|
|
190
222
|
...(keys.length > 0 ? { enum: keys as any as (keyof T)[] } : {})
|
|
191
223
|
}
|
|
192
224
|
},
|
|
193
|
-
$or
|
|
194
|
-
|
|
195
|
-
items: {
|
|
196
|
-
type: 'object',
|
|
197
|
-
additionalProperties: false,
|
|
198
|
-
properties: props
|
|
199
|
-
}
|
|
200
|
-
},
|
|
225
|
+
$or,
|
|
226
|
+
$and,
|
|
201
227
|
...props
|
|
202
228
|
} as const
|
|
203
229
|
}
|