-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
presets.ts
47 lines (43 loc) · 1.49 KB
/
presets.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
import type { DirectusPreset } from '../../../schema/preset.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import { throwIfEmpty } from '../../utils/index.js';
import type { RestCommand } from '../../types.js';
export type ReadPresetOutput<
Schema extends object,
TQuery extends Query<Schema, Item>,
Item extends object = DirectusPreset<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;
/**
* List all Presets that exist in Directus.
* @param query The query parameters
* @returns An array of up to limit Preset objects. If no items are available, data will be an empty array.
*/
export const readPresets =
<Schema extends object, const TQuery extends Query<Schema, DirectusPreset<Schema>>>(
query?: TQuery,
): RestCommand<ReadPresetOutput<Schema, TQuery>[], Schema> =>
() => ({
path: `/presets`,
params: query ?? {},
method: 'GET',
});
/**
* List an existing preset by primary key.
* @param key The primary key of the dashboard
* @param query The query parameters
* @returns Returns a Preset object if a valid primary key was provided.
* @throws Will throw if key is empty
*/
export const readPreset =
<Schema extends object, const TQuery extends Query<Schema, DirectusPreset<Schema>>>(
key: DirectusPreset<Schema>['id'],
query?: TQuery,
): RestCommand<ReadPresetOutput<Schema, TQuery>, Schema> =>
() => {
throwIfEmpty(String(key), 'Key cannot be empty');
return {
path: `/presets/${key}`,
params: query ?? {},
method: 'GET',
};
};