-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
shares.ts
49 lines (46 loc) · 1.39 KB
/
shares.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { DirectusShare } from '../../../schema/share.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import type { RestCommand } from '../../types.js';
export type CreateShareOutput<
Schema extends object,
TQuery extends Query<Schema, Item>,
Item extends object = DirectusShare<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;
/**
* Create multiple new shares.
*
* @param items The shares to create
* @param query Optional return data query
*
* @returns Returns the share objects for the created shares.
*/
export const createShares =
<Schema extends object, const TQuery extends Query<Schema, DirectusShare<Schema>>>(
items: Partial<DirectusShare<Schema>>[],
query?: TQuery,
): RestCommand<CreateShareOutput<Schema, TQuery>[], Schema> =>
() => ({
path: `/shares`,
params: query ?? {},
body: JSON.stringify(items),
method: 'POST',
});
/**
* Create a new share.
*
* @param item The share to create
* @param query Optional return data query
*
* @returns Returns the share object for the created share.
*/
export const createShare =
<Schema extends object, const TQuery extends Query<Schema, DirectusShare<Schema>>>(
item: Partial<DirectusShare<Schema>>,
query?: TQuery,
): RestCommand<CreateShareOutput<Schema, TQuery>, Schema> =>
() => ({
path: `/shares`,
params: query ?? {},
body: JSON.stringify(item),
method: 'POST',
});