Skip to content

Commit d8bb550

Browse files
committed
fix: changes to
1 parent d76f5f7 commit d8bb550

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/endpoint/src/schemas/Collection.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import PolymorphicSchema from './Polymorphic.js';
22
import { filterEmpty, getValues } from './utils.js';
3-
import { Schema } from '../interface.js';
3+
import { SchemaSimple } from '../interface.js';
44
import {
55
Entity as EntitySchema,
66
SchemaClass,
77
Values,
88
Array as ArraySchema,
9+
SchemaSimpleNew,
910
} from '../schema.js';
1011

1112
const pushMerge = (existing: any, incoming: any) => {
@@ -25,7 +26,9 @@ const createValue = (value: any) => (value ? { ...value } : undefined);
2526
* @see https://resthooks.io/rest/api/Collection
2627
*/
2728
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>,
2932
Parent extends any[] = [
3033
urlParams: Record<string, any>,
3134
body?: Record<string, any>,
@@ -40,7 +43,9 @@ export default class CollectionSchema<
4043
...args: Parent
4144
) => (collectionKey: Record<string, any>) => boolean;
4245

43-
declare readonly schema: S;
46+
declare readonly schema: S extends SchemaSimpleNew[]
47+
? ArraySchema<S[number]>
48+
: S;
4449

4550
declare push: S extends ArraySchema<any>
4651
? CollectionSchema<S, Parent>
@@ -59,7 +64,9 @@ export default class CollectionSchema<
5964
...args: Parent
6065
) => (collectionKey: Record<string, any>) => boolean,
6166
) {
62-
this.schema = schema;
67+
this.schema = Array.isArray(schema)
68+
? (new ArraySchema(schema[0]) as any)
69+
: schema;
6370
this.instanceKey = instanceKey;
6471
this.createCollectionFilter =
6572
createCollectionFilter ?? (defaultFilter as any);

0 commit comments

Comments
 (0)