1
1
import PolymorphicSchema from './Polymorphic.js' ;
2
2
import { filterEmpty , getValues } from './utils.js' ;
3
- import { Schema } from '../interface.js' ;
3
+ import { SchemaSimple } from '../interface.js' ;
4
4
import {
5
5
Entity as EntitySchema ,
6
6
SchemaClass ,
7
7
Values ,
8
8
Array as ArraySchema ,
9
+ SchemaSimpleNew ,
9
10
} from '../schema.js' ;
10
11
11
12
const pushMerge = ( existing : any , incoming : any ) => {
@@ -25,7 +26,9 @@ const createValue = (value: any) => (value ? { ...value } : undefined);
25
26
* @see https://resthooks.io/rest/api/Collection
26
27
*/
27
28
export default class CollectionSchema <
28
- S extends ArraySchema < any > | Values < any > = ArraySchema < any > | Values < any > ,
29
+ S extends ArraySchema < any > | Values < any > | SchemaSimpleNew [ ] =
30
+ | ArraySchema < any >
31
+ | Values < any > ,
29
32
Parent extends any [ ] = [
30
33
urlParams : Record < string , any > ,
31
34
body ?: Record < string , any > ,
@@ -40,7 +43,9 @@ export default class CollectionSchema<
40
43
...args : Parent
41
44
) => ( collectionKey : Record < string , any > ) => boolean ;
42
45
43
- declare readonly schema : S ;
46
+ declare readonly schema : S extends SchemaSimpleNew [ ]
47
+ ? ArraySchema < S [ number ] >
48
+ : S ;
44
49
45
50
declare push : S extends ArraySchema < any >
46
51
? CollectionSchema < S , Parent >
@@ -59,7 +64,9 @@ export default class CollectionSchema<
59
64
...args : Parent
60
65
) => ( collectionKey : Record < string , any > ) => boolean ,
61
66
) {
62
- this . schema = schema ;
67
+ this . schema = Array . isArray ( schema )
68
+ ? ( new ArraySchema ( schema [ 0 ] ) as any )
69
+ : schema ;
63
70
this . instanceKey = instanceKey ;
64
71
this . createCollectionFilter =
65
72
createCollectionFilter ?? ( defaultFilter as any ) ;
0 commit comments