-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
28 lines (25 loc) · 802 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { CollectionMeta } from "./types.ts";
export const omit = <T, K extends string>(
keys: readonly K[],
obj: T,
): Omit<T, K> =>
// @ts-ignore ?
Object.entries(obj).reduce((keep: Partial<T>, [k, v]) => {
// @ts-ignore ?
if (!keys.includes(k)) keep[k] = v;
return keep;
}, {});
export const getSubCollectionNames = (collection: CollectionMeta) =>
Object.entries(collection.schema.properties || {})
.reduce((all: string[], [name, d]) => {
if (d.type === "array" && d.items && d.items?.type === "object") {
all.push(name);
}
return all;
}, []);
export const getSubSchema = (
collection: CollectionMeta,
key: string,
): Record<string, unknown> | undefined =>
// @ts-ignore ?
((collection.schema?.properties || {})[key] || {}).items;