@cododel/alto 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/default/default/extensions/filters/comment.ts +9 -0
- package/dist/default/default/extensions/filters/contains.ts +8 -0
- package/dist/default/default/extensions/filters/directus.ts +336 -0
- package/dist/default/default/extensions/filters/drop_first.ts +8 -0
- package/dist/default/default/extensions/filters/entries.ts +13 -0
- package/dist/default/default/extensions/filters/falsey.ts +17 -0
- package/dist/default/default/extensions/filters/indent.ts +6 -0
- package/dist/default/default/extensions/filters/inflections.ts +25 -0
- package/dist/default/default/extensions/filters/json.ts +10 -0
- package/dist/default/default/extensions/filters/log.ts +5 -0
- package/dist/default/default/extensions/filters/object_set.ts +11 -0
- package/dist/default/default/extensions/filters/push.ts +10 -0
- package/dist/default/default/extensions/filters/quote.ts +19 -0
- package/dist/default/default/extensions/filters/regex_replace.ts +10 -0
- package/dist/default/default/extensions/filters/splice.ts +13 -0
- package/dist/default/default/extensions/filters/split.ts +9 -0
- package/dist/default/default/extensions/filters/string_cases.ts +72 -0
- package/dist/default/default/extensions/filters/truthy.ts +17 -0
- package/dist/default/default/extensions/filters/typescript.ts +10 -0
- package/dist/default/default/extensions/filters/unshift.ts +10 -0
- package/dist/default/default/extensions/filters/wrap.ts +10 -0
- package/dist/default/default/extensions/tags/.gitkeep +0 -0
- package/dist/default/default/includes/typescript/get-field-jsdoc.liquid +11 -0
- package/dist/default/default/includes/typescript/get-field-type.liquid +121 -0
- package/dist/default/default/macros/typescript/types.njk +1 -0
- package/dist/default/default/templates/default/client.ts.njk +518 -0
- package/dist/default/default/templates/default/types.ts.njk +134 -0
- package/dist/default/extensions/filters/comment.ts +9 -0
- package/dist/default/extensions/filters/contains.ts +8 -0
- package/dist/default/extensions/filters/directus.ts +336 -0
- package/dist/default/extensions/filters/drop_first.ts +8 -0
- package/dist/default/extensions/filters/entries.ts +13 -0
- package/dist/default/extensions/filters/falsey.ts +17 -0
- package/dist/default/extensions/filters/indent.ts +6 -0
- package/dist/default/extensions/filters/inflections.ts +25 -0
- package/dist/default/extensions/filters/json.ts +10 -0
- package/dist/default/extensions/filters/log.ts +5 -0
- package/dist/default/extensions/filters/object_set.ts +11 -0
- package/dist/default/extensions/filters/push.ts +10 -0
- package/dist/default/extensions/filters/quote.ts +19 -0
- package/dist/default/extensions/filters/regex_replace.ts +10 -0
- package/dist/default/extensions/filters/splice.ts +13 -0
- package/dist/default/extensions/filters/split.ts +9 -0
- package/dist/default/extensions/filters/string_cases.ts +72 -0
- package/dist/default/extensions/filters/truthy.ts +17 -0
- package/dist/default/extensions/filters/typescript.ts +10 -0
- package/dist/default/extensions/filters/unshift.ts +10 -0
- package/dist/default/extensions/filters/wrap.ts +10 -0
- package/dist/default/extensions/tags/.gitkeep +0 -0
- package/dist/default/includes/typescript/get-field-jsdoc.liquid +11 -0
- package/dist/default/includes/typescript/get-field-type.liquid +121 -0
- package/dist/default/macros/typescript/types.njk +1 -0
- package/dist/default/templates/default/client.ts.njk +518 -0
- package/dist/default/templates/default/types.ts.njk +134 -0
- package/dist/index.js +450 -451
- package/package.json +9 -10
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
{% block header %}
|
|
2
|
+
/**
|
|
3
|
+
* This file is automatically generated by the `@indirectus/cli` package.
|
|
4
|
+
* Follow the package's instruction to update this file with the latest schema.
|
|
5
|
+
*/
|
|
6
|
+
{% endblock %}
|
|
7
|
+
|
|
8
|
+
{% block imports %}
|
|
9
|
+
import type * as Directus from "@directus/sdk";
|
|
10
|
+
import type { System, Collections} from "./types";
|
|
11
|
+
|
|
12
|
+
import * as DirectusSDK from "@directus/sdk";
|
|
13
|
+
|
|
14
|
+
type DirectusSDK = typeof DirectusSDK;
|
|
15
|
+
|
|
16
|
+
{% endblock %}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Schema definition.
|
|
20
|
+
*/
|
|
21
|
+
export interface Schema extends System {
|
|
22
|
+
{% for collection in registry.collections -%}
|
|
23
|
+
{% if not collection.is_system %}
|
|
24
|
+
{% set suffix = "" if collection.is_singleton else "[]" %}
|
|
25
|
+
/**
|
|
26
|
+
* The {{ collection.name | to_collection_text }} collection.
|
|
27
|
+
*/
|
|
28
|
+
{{ collection.name | to_ts_identifier }}: Collections.{{ collection.name | pascal_case }}{{ suffix }};
|
|
29
|
+
{% endif %}
|
|
30
|
+
{% endfor %}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TypedCollectionItemsWrapper<Collection extends object>
|
|
34
|
+
{
|
|
35
|
+
/**
|
|
36
|
+
* Creates many items in the collection.
|
|
37
|
+
*/
|
|
38
|
+
create<const Query extends DirectusSDK.Query<Schema, Collection>>(items: Partial<Collection>[], query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']>[]>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Read many items from the collection.
|
|
42
|
+
*/
|
|
43
|
+
query<const Query extends DirectusSDK.Query<Schema, Collection>>(query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']>[]>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Read the first item from the collection matching the query.
|
|
47
|
+
*/
|
|
48
|
+
find<const Query extends DirectusSDK.Query<Schema, Collection>>(query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']> | undefined>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Update many items in the collection.
|
|
52
|
+
*/
|
|
53
|
+
update<const Query extends DirectusSDK.Query<Schema, Collection[]>>(keys: string[] | number[], patch: Partial<Collection>, query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']>[]>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Remove many items in the collection.
|
|
57
|
+
*/
|
|
58
|
+
remove<const Query extends DirectusSDK.Query<Schema, Collection>>(keys: string[] | number[]): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface TypedCollectionItemWrapper<Collection extends object>
|
|
62
|
+
{
|
|
63
|
+
/**
|
|
64
|
+
* Create a single item in the collection.
|
|
65
|
+
*/
|
|
66
|
+
create<const Query extends DirectusSDK.Query<Schema, Collection>>(item: Partial<Collection>, query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']>>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Read a single item from the collection.
|
|
70
|
+
*/
|
|
71
|
+
get<const Query extends DirectusSDK.Query<Schema, Collection>>(key: string | number, query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']> | undefined>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Update a single item from the collection.
|
|
75
|
+
*/
|
|
76
|
+
update<const Query extends DirectusSDK.Query<Schema, Collection>>(key: string | number, patch: Partial<Collection>, query?: Query): Promise<DirectusSDK.ApplyQueryFields<Schema, Collection, Query['fields']> | undefined>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Remove many items in the collection.
|
|
80
|
+
*/
|
|
81
|
+
remove<const Query extends DirectusSDK.Query<Schema, Collection>>(key: string | number): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Helper functions
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
{% for collection in registry.collections -%}
|
|
89
|
+
|
|
90
|
+
{% set collectionName = collection.name | to_collection_name %}
|
|
91
|
+
{% set collectionString = collection.name | to_collection_string %}
|
|
92
|
+
{% set collectionType = ["Collections.", collection.name | to_collection_name] | join %}
|
|
93
|
+
{% set genericQuery = ["const Query extends Directus.Query<Schema, ", collectionType, ">"] | join %}
|
|
94
|
+
{% set genericQueryArray = ["const Query extends Directus.Query<Schema, ", collectionType, "[]>"] | join %}
|
|
95
|
+
{% set applyType = ["DirectusSDK.ApplyQueryFields<Schema, ", collectionType, ", Query['fields']>"] | join %}
|
|
96
|
+
|
|
97
|
+
{% if not collection.is_system %}
|
|
98
|
+
|
|
99
|
+
{% if collection.is_singleton %}
|
|
100
|
+
/**
|
|
101
|
+
* Reads the {{ collection.name | to_collection_text }} singleton.
|
|
102
|
+
*/
|
|
103
|
+
export function read{{ collectionName }}<
|
|
104
|
+
{{ genericQuery }},
|
|
105
|
+
>(query?: Query) {
|
|
106
|
+
return DirectusSDK.readSingleton<Schema, {{ collectionString }}, Query>("{{ collection.name }}", query);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Reads the {{ collection.name | to_collection_text }} singleton.
|
|
111
|
+
*/
|
|
112
|
+
export const get{{ collectionName }} = read{{ collectionName }};
|
|
113
|
+
|
|
114
|
+
{% else %}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create many {{ collection.name | to_collection_text }} items.
|
|
118
|
+
*/
|
|
119
|
+
export function create{{ collectionName }}Items<
|
|
120
|
+
{{ genericQueryArray}}
|
|
121
|
+
>(items: Partial<{{ collectionType }}>[], query?: Query) {
|
|
122
|
+
return DirectusSDK.createItems<Schema, {{ collectionString }}, Query>("{{ collection.name }}", items, query);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Create a single {{ collection.name | to_collection_text }} item.
|
|
127
|
+
*/
|
|
128
|
+
export function create{{ collectionName }}Item<
|
|
129
|
+
const Query extends DirectusSDK.Query<Schema, {{ collectionType }}[]> // Is this a mistake? Why []?
|
|
130
|
+
>(item: Partial<{{ collectionType }}>, query?: Query) {
|
|
131
|
+
return DirectusSDK.createItem<Schema, {{ collectionString }}, Query>("{{ collection.name }}", item, query);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Read many {{ collection.name | to_collection_text }} items.
|
|
136
|
+
*/
|
|
137
|
+
export function read{{ collectionName }}Items<
|
|
138
|
+
{{ genericQuery }},
|
|
139
|
+
>(query?: Query) {
|
|
140
|
+
return DirectusSDK.readItems<Schema, {{ collectionString }}, Query>("{{ collection.name }}", query);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Read many {{ collection.name | to_collection_text }} items.
|
|
145
|
+
*/
|
|
146
|
+
export const list{{ collectionName }} = read{{ collectionName }}Items;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Gets a single known {{ collection.name | to_collection_text }} item by id.
|
|
150
|
+
*/
|
|
151
|
+
export function read{{ collectionName }}Item<
|
|
152
|
+
{{ genericQuery }},
|
|
153
|
+
>(key: string | number, query?: Query) {
|
|
154
|
+
return DirectusSDK.readItem<Schema, {{ collectionString }}, Query>("{{ collection.name }}", key, query);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Gets a single known {{ collection.name | to_collection_text }} item by id.
|
|
159
|
+
*/
|
|
160
|
+
export const read{{ collectionName }} = read{{ collectionName }}Item;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Read many {{ collection.name | to_collection_text }} items.
|
|
164
|
+
*/
|
|
165
|
+
export function update{{ collectionName }}Items<
|
|
166
|
+
{{ genericQueryArray }},
|
|
167
|
+
>(keys: string[] | number[], patch: Partial<{{ collectionType }}>, query?: Query) {
|
|
168
|
+
return DirectusSDK.updateItems<Schema, {{ collectionString }}, Query>("{{ collection.name }}", keys, patch, query);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets a single known {{ collection.name | to_collection_text }} item by id.
|
|
173
|
+
*/
|
|
174
|
+
export function update{{ collectionName }}Item<
|
|
175
|
+
{{ genericQueryArray }},
|
|
176
|
+
>(key: string | number, patch: Partial<{{ collectionType }}>, query?: Query) {
|
|
177
|
+
return DirectusSDK.updateItem<Schema, {{ collectionString }}, Query>("{{ collection.name }}", key, patch, query);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Deletes many {{ collection.name | to_collection_text }} items.
|
|
182
|
+
*/
|
|
183
|
+
export function delete{{ collectionName }}Items<
|
|
184
|
+
{{ genericQueryArray }},
|
|
185
|
+
>(keys: string[] | number[]) {
|
|
186
|
+
return DirectusSDK.deleteItems<Schema, {{ collectionString }}, Query>("{{ collection.name }}", keys);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Deletes a single known {{ collection.name | to_collection_text }} item by id.
|
|
191
|
+
*/
|
|
192
|
+
export function delete{{ collectionName }}Item(key: string | number) {
|
|
193
|
+
return DirectusSDK.deleteItem<Schema, {{ collectionString }}>("{{ collection.name }}", key);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export class {{ collectionName }}Items implements TypedCollectionItemsWrapper<{{ collectionType }}>
|
|
197
|
+
{
|
|
198
|
+
/**
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
constructor(private client: Directus.DirectusClient<Schema> & Directus.RestClient<Schema>)
|
|
202
|
+
{
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Creates many items in the collection.
|
|
207
|
+
*/
|
|
208
|
+
async create<
|
|
209
|
+
const Query extends DirectusSDK.Query<Schema, {{ collectionType }}>
|
|
210
|
+
>(
|
|
211
|
+
items: Partial<{{ collectionType }}>[],
|
|
212
|
+
query?: Query
|
|
213
|
+
): Promise<
|
|
214
|
+
{{ applyType }}[]
|
|
215
|
+
> {
|
|
216
|
+
return await this.client.request(create{{ collectionName }}Items(items, query as any)) as any; // Seems like a bug in the SDK.
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Read many items from the collection.
|
|
221
|
+
*/
|
|
222
|
+
async query<{{ genericQuery }}>(query?: Query): Promise<{{ applyType }}[]>
|
|
223
|
+
{
|
|
224
|
+
return await this.client.request(read{{ collectionName }}Items(query));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Read the first item from the collection matching the query.
|
|
229
|
+
*/
|
|
230
|
+
async find<{{ genericQuery }}>(query?: Query): Promise<{{ applyType }} | undefined>
|
|
231
|
+
{
|
|
232
|
+
const items = await this.client.request(read{{ collectionName }}Items({
|
|
233
|
+
...query,
|
|
234
|
+
limit: 1,
|
|
235
|
+
}));
|
|
236
|
+
return items?.[0] as any; // TODO: fix
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Update many items in the collection.
|
|
241
|
+
*/
|
|
242
|
+
async update<{{ genericQueryArray }}>(keys: string[] | number[], patch: Partial<{{ collectionType }}>, query?: Query): Promise<{{ applyType }}[]>
|
|
243
|
+
{
|
|
244
|
+
return await this.client.request(update{{ collectionName }}Items(keys, patch, query));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Remove many items in the collection.
|
|
249
|
+
*/
|
|
250
|
+
async remove<{{ genericQuery }}>(keys: string[] | number[]): Promise<void>
|
|
251
|
+
{
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export class {{ collectionName }}Item implements TypedCollectionItemWrapper<{{ collectionType }}>
|
|
257
|
+
{
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
*/
|
|
261
|
+
constructor(private client: Directus.DirectusClient<Schema> & Directus.RestClient<Schema>)
|
|
262
|
+
{
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Create a single item in the collection.
|
|
267
|
+
*/
|
|
268
|
+
async create<{{ genericQuery }}>(item: Partial<{{ collectionType }}>, query?: Query): Promise<{{ applyType }}>
|
|
269
|
+
{
|
|
270
|
+
return await this.client.request(create{{ collectionName }}Item(item, query as any)) as any;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Read a single item from the collection.
|
|
275
|
+
*/
|
|
276
|
+
async get<{{ genericQuery }}>(key: string | number, query?: Query): Promise<{{ applyType }} | undefined>
|
|
277
|
+
{
|
|
278
|
+
return await this.client.request(read{{ collectionName }}Item(key, query));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Update a single item from the collection.
|
|
283
|
+
*/
|
|
284
|
+
async update<{{ genericQuery }}>(key: string | number, patch: Partial<{{ collectionType }}>, query?: Query): Promise<{{ applyType }} | undefined>
|
|
285
|
+
{
|
|
286
|
+
return await this.client.request(update{{ collectionName }}Item(key, patch, query as any)) as any;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Remove many items in the collection.
|
|
291
|
+
*/
|
|
292
|
+
async remove<{{ genericQuery }}>(key: string | number): Promise<void>
|
|
293
|
+
{
|
|
294
|
+
return await this.client.request(delete{{ collectionName }}Item(key));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
{% endif %}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
{% endif %}
|
|
302
|
+
{% endfor %}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The Directus Client.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
export type DirectusRestCommands<T extends Record<any, any>> = keyof {
|
|
310
|
+
[K in keyof T as T[K] extends (
|
|
311
|
+
...any: any[]
|
|
312
|
+
) => Directus.RestCommand<any, any>
|
|
313
|
+
? K
|
|
314
|
+
: never]: K;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export type TypedClient = {
|
|
318
|
+
{%- for collection in registry.collections %}
|
|
319
|
+
|
|
320
|
+
{% set collectionType = ["Collections.", collection.name | to_collection_name] | join %}
|
|
321
|
+
{% set genericQuery = ["const Query extends Directus.Query<Schema, ", collectionType, ">"] | join %}
|
|
322
|
+
{% set applyType = ["DirectusSDK.ApplyQueryFields<Schema, ", collectionType, ", Query['fields']>"] | join %}
|
|
323
|
+
|
|
324
|
+
{% if not collection.is_system %}
|
|
325
|
+
|
|
326
|
+
{% if not collection.is_singleton %}
|
|
327
|
+
/**
|
|
328
|
+
* Manages multiple items from the {{ collection.name.raw | to_collection_name }} collection.
|
|
329
|
+
*/
|
|
330
|
+
{{ collection.name.raw | pluralize | to_collection_string }}: TypedCollectionItemsWrapper<Collections.{{ collection.name.raw | to_collection_name }}>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Manages individual items from the {{ collection.name.raw | to_collection_name }} collection.
|
|
334
|
+
*/
|
|
335
|
+
{{ collection.name.raw | singularize | to_collection_string }}: TypedCollectionItemWrapper<Collections.{{ collection.name.raw | to_collection_name }}>;
|
|
336
|
+
{% else %}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Fetches the only {{ collection.name.raw | singularize | to_collection_name }} instance available.
|
|
340
|
+
*/
|
|
341
|
+
[{{ collection.name | to_collection_string }}]<{{ genericQuery }}>(query?: Query): Promise<{{ applyType }}>;
|
|
342
|
+
|
|
343
|
+
{% endif %}
|
|
344
|
+
|
|
345
|
+
{% endif %}
|
|
346
|
+
{%- endfor %}
|
|
347
|
+
} & DirectusCommands;
|
|
348
|
+
|
|
349
|
+
type ExcludedDirectusCommands = "withOptions" | "withToken" | "withSearch";
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* This is almost a sanity check for protecting against breaking changes in the SDK.
|
|
353
|
+
* If this is erroring for you, the SDK probably changed and there's an update needed.
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
const excludedDirectusCommands: {
|
|
357
|
+
[K in keyof Omit<
|
|
358
|
+
DirectusSDK,
|
|
359
|
+
Exclude<keyof DirectusCommands, ExcludedDirectusCommands>
|
|
360
|
+
>]: true;
|
|
361
|
+
} = {
|
|
362
|
+
["auth"]: true,
|
|
363
|
+
["authentication"]: true,
|
|
364
|
+
["createDirectus"]: true,
|
|
365
|
+
["rest"]: true,
|
|
366
|
+
["formatFields"]: true,
|
|
367
|
+
["generateUid"]: true,
|
|
368
|
+
["getAuthEndpoint"]: true,
|
|
369
|
+
["graphql"]: true,
|
|
370
|
+
["isDirectusError"]: true,
|
|
371
|
+
["memoryStorage"]: true,
|
|
372
|
+
["messageCallback"]: true,
|
|
373
|
+
["pong"]: true,
|
|
374
|
+
["queryToParams"]: true,
|
|
375
|
+
["realtime"]: true,
|
|
376
|
+
["sleep"]: true,
|
|
377
|
+
["staticToken"]: true,
|
|
378
|
+
["throwIfCoreCollection"]: true,
|
|
379
|
+
["throwIfEmpty"]: true,
|
|
380
|
+
["withOptions"]: true,
|
|
381
|
+
["withToken"]: true,
|
|
382
|
+
["withSearch"]: true,
|
|
383
|
+
} as const;
|
|
384
|
+
|
|
385
|
+
export type _InjectSchemaSystemTypes<T, Schema>
|
|
386
|
+
= T extends Directus.Query<any, infer C> ? Directus.Query<Schema, C>
|
|
387
|
+
{% for collection in registry.collections | skip_collections(skipCollections) -%}
|
|
388
|
+
{% if collection.is_system %}
|
|
389
|
+
: T extends Directus.{{ collection.name | to_collection_name }}<any> ? Directus.{{ collection.name | to_collection_name }}<Schema>
|
|
390
|
+
{% endif %}
|
|
391
|
+
{% endfor %}
|
|
392
|
+
: T extends Directus.DirectusUser<any> ? Directus.DirectusUser<Schema>
|
|
393
|
+
: T;
|
|
394
|
+
|
|
395
|
+
export type InjectSchemaSystemTypes<T, Schema>
|
|
396
|
+
= T extends Partial<infer Nested> ? Partial<_InjectSchemaSystemTypes<Nested, Schema>>
|
|
397
|
+
: _InjectSchemaSystemTypes<T, Schema>
|
|
398
|
+
;
|
|
399
|
+
|
|
400
|
+
export type InjectSchema<T, Schema>
|
|
401
|
+
= T extends [] ? []
|
|
402
|
+
: T extends [infer Param] ? [InjectSchema<Param, Schema>]
|
|
403
|
+
: T extends [infer Param, ...infer Rest] ? [InjectSchema<Param, Schema>, ...InjectSchema<Rest, Schema>]
|
|
404
|
+
: InjectSchemaSystemTypes<T, Schema>;
|
|
405
|
+
|
|
406
|
+
export type DirectusCommands = {
|
|
407
|
+
[K in DirectusRestCommands<DirectusSDK>]: (
|
|
408
|
+
...args: InjectSchema<Parameters<DirectusSDK[K]>, Schema>
|
|
409
|
+
) => Promise<
|
|
410
|
+
ReturnType<DirectusSDK[K]> extends Directus.RestCommand<infer Output, any>
|
|
411
|
+
? Output
|
|
412
|
+
: unknown
|
|
413
|
+
>;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isDirectusRestCommand(
|
|
417
|
+
pair: [any, any],
|
|
418
|
+
): pair is [string, (...args: any[]) => Directus.RestCommand<any, any>] {
|
|
419
|
+
return (
|
|
420
|
+
!((pair?.[0] as any) in excludedDirectusCommands) &&
|
|
421
|
+
typeof pair?.[1] === "function"
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function isDirectusRestClient<Schema>(
|
|
426
|
+
client: DirectusSDK.DirectusClient<Schema>,
|
|
427
|
+
): client is DirectusSDK.DirectusClient<Schema> &
|
|
428
|
+
DirectusSDK.RestClient<Schema> {
|
|
429
|
+
return client && "request" in client;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export const schema = () => {
|
|
433
|
+
return <Schema>(client: Directus.DirectusClient<Schema>): TypedClient => {
|
|
434
|
+
|
|
435
|
+
if (!isDirectusRestClient(client)) {
|
|
436
|
+
throw new Error("Directus client must have the REST plugin enabled.");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return Object.fromEntries([
|
|
440
|
+
...Object.entries(DirectusSDK)
|
|
441
|
+
.filter(isDirectusRestCommand)
|
|
442
|
+
.map(([key, value]) => {
|
|
443
|
+
return [
|
|
444
|
+
key,
|
|
445
|
+
(...args: any[]): any => {
|
|
446
|
+
return client.request(
|
|
447
|
+
value(...args),
|
|
448
|
+
);
|
|
449
|
+
},
|
|
450
|
+
];
|
|
451
|
+
}),
|
|
452
|
+
|
|
453
|
+
{% for collection in registry.collections %}
|
|
454
|
+
{% if not collection.is_system%}
|
|
455
|
+
{% if not collection.is_singleton %}
|
|
456
|
+
[{{ collection.name.raw | pluralize | to_collection_string }}, new {{ collection.name | to_collection_name }}Items(client as any)],
|
|
457
|
+
[{{ collection.name.raw | singularize | to_collection_string }}, new {{ collection.name | to_collection_name }}Item(client as any)],
|
|
458
|
+
{% else %}
|
|
459
|
+
[{{ collection.name | to_collection_string }}, (query: any) => {
|
|
460
|
+
return client.request(read{{ collection.name | to_collection_name }}(query));
|
|
461
|
+
}],
|
|
462
|
+
{% endif %}
|
|
463
|
+
{% endif %}
|
|
464
|
+
{% endfor %}
|
|
465
|
+
]);
|
|
466
|
+
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export interface BindableClient {
|
|
471
|
+
with: <
|
|
472
|
+
Client extends DirectusSDK.DirectusClient<any>,
|
|
473
|
+
Extension extends object,
|
|
474
|
+
>(
|
|
475
|
+
createExtension: (client: Client) => Extension,
|
|
476
|
+
) => this & Extension;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export const bindings = () => {
|
|
480
|
+
return <Schema, Client extends DirectusSDK.DirectusClient<Schema>>(
|
|
481
|
+
client: Client,
|
|
482
|
+
): BindableClient => {
|
|
483
|
+
return {
|
|
484
|
+
with(createExtension: any) {
|
|
485
|
+
const extension = createExtension(this);
|
|
486
|
+
const extensions = Object.entries(
|
|
487
|
+
extension,
|
|
488
|
+
).reduce<PropertyDescriptorMap>((properties, [name, value]) => {
|
|
489
|
+
return {
|
|
490
|
+
...properties,
|
|
491
|
+
[name]: {
|
|
492
|
+
value,
|
|
493
|
+
configurable: true,
|
|
494
|
+
writable: true,
|
|
495
|
+
enumerable: true,
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
}, {});
|
|
499
|
+
|
|
500
|
+
Object.defineProperties(this, extensions);
|
|
501
|
+
|
|
502
|
+
return this;
|
|
503
|
+
},
|
|
504
|
+
} as any;
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
export function createDirectusWithTypes(
|
|
509
|
+
url: string,
|
|
510
|
+
options?: Directus.ClientOptions
|
|
511
|
+
): Directus.DirectusClient<Schema> & Directus.RestClient<Schema> & TypedClient {
|
|
512
|
+
return DirectusSDK.createDirectus<Schema>(url, options)
|
|
513
|
+
.with(bindings())
|
|
514
|
+
.with(DirectusSDK.rest())
|
|
515
|
+
.with(schema());
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export const createTypedClient = createDirectusWithTypes;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{% block header %}
|
|
2
|
+
/**
|
|
3
|
+
* This file is automatically generated by the `@indirectus/cli` package.
|
|
4
|
+
* Follow the package's instruction to update this file with the latest schema.
|
|
5
|
+
*/
|
|
6
|
+
{% endblock %}
|
|
7
|
+
|
|
8
|
+
{% block imports %}
|
|
9
|
+
import type * as Directus from "@directus/sdk";
|
|
10
|
+
|
|
11
|
+
{% endblock %}
|
|
12
|
+
|
|
13
|
+
export namespace Types {
|
|
14
|
+
{% block types %}
|
|
15
|
+
// Internal
|
|
16
|
+
export type Nullable<T> = T | null;
|
|
17
|
+
export type Optional<T> = Nullable<T>;
|
|
18
|
+
export type UnknownType<T> = T | unknown;
|
|
19
|
+
export type PrimaryKey<T> = T;
|
|
20
|
+
|
|
21
|
+
// Numbers
|
|
22
|
+
export type BigInteger = number;
|
|
23
|
+
export type Decimal = number;
|
|
24
|
+
export type Float = number;
|
|
25
|
+
export type Integer = number;
|
|
26
|
+
export type Number = number;
|
|
27
|
+
|
|
28
|
+
// Buffers
|
|
29
|
+
export type Binary = string;
|
|
30
|
+
export type String = string;
|
|
31
|
+
export type Text = string;
|
|
32
|
+
|
|
33
|
+
// Date & Time
|
|
34
|
+
export type Date = string | globalThis.Date;
|
|
35
|
+
export type DateTime = string | globalThis.Date;
|
|
36
|
+
|
|
37
|
+
// Geometry
|
|
38
|
+
export namespace Geometry {
|
|
39
|
+
export type LineString = any;
|
|
40
|
+
export type MultiLineString = any;
|
|
41
|
+
export type MultiPoint = any;
|
|
42
|
+
export type MultiPolygon = any;
|
|
43
|
+
export type Point = any;
|
|
44
|
+
export type Polygon = any;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Complex
|
|
48
|
+
export type JSON = any;
|
|
49
|
+
export type JSONSchema = any;
|
|
50
|
+
|
|
51
|
+
// Others
|
|
52
|
+
export type UUID = string;
|
|
53
|
+
export type Boolean = boolean;
|
|
54
|
+
export type Enum = string;
|
|
55
|
+
|
|
56
|
+
{% endblock %}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* All collection types.
|
|
61
|
+
*/
|
|
62
|
+
export namespace Collections {
|
|
63
|
+
|
|
64
|
+
{% for collection in registry.collections | skip_collections(skipCollections) -%}
|
|
65
|
+
{% if collection.is_system %}
|
|
66
|
+
|
|
67
|
+
{%- set field_count = collection.fields | only_custom_fields | length -%}
|
|
68
|
+
{% filter comment -%}
|
|
69
|
+
The resolved {{ collection.name | to_collection_text }} collection type.
|
|
70
|
+
{% endfilter %}
|
|
71
|
+
export type {{ collection.name | to_collection_name }} = Directus.{{ collection.name | to_collection_name }}<System>;
|
|
72
|
+
{% endif %}
|
|
73
|
+
{% endfor %}
|
|
74
|
+
|
|
75
|
+
{% for collection in registry.collections -%}
|
|
76
|
+
{% if not collection.is_system %}
|
|
77
|
+
/**
|
|
78
|
+
* The {{ collection.name | space_case | lower_case }} collection.
|
|
79
|
+
*/
|
|
80
|
+
export interface {{ collection.name | pascal_case }} {
|
|
81
|
+
{%- for field in collection.fields %}
|
|
82
|
+
{%- set type = field | to_ts_type -%}
|
|
83
|
+
{%- if type != 'never' %}
|
|
84
|
+
{{ field.name | to_ts_identifier }}: {{ type }};
|
|
85
|
+
{%- endif -%}
|
|
86
|
+
{%- endfor %}
|
|
87
|
+
}
|
|
88
|
+
{% endif %}
|
|
89
|
+
{% endfor %}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* System schema extensions.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export interface System {
|
|
97
|
+
|
|
98
|
+
{% for collection in registry.collections | skip_collections(skipCollections) -%}
|
|
99
|
+
{% if collection.is_system %}
|
|
100
|
+
|
|
101
|
+
{% filter comment -%}
|
|
102
|
+
The definition for the {{ collection.name | to_collection_text }} system collection.
|
|
103
|
+
{% endfilter %}
|
|
104
|
+
{{ collection.name }}: {
|
|
105
|
+
{%- for field in collection.fields | only_custom_fields %}
|
|
106
|
+
{%- set type = field | to_ts_type -%}
|
|
107
|
+
{%- if type != 'never' %}
|
|
108
|
+
{{ field.name | to_ts_identifier }}: {{ type }};
|
|
109
|
+
{%- endif -%}
|
|
110
|
+
{%- endfor %}
|
|
111
|
+
}{{ "" if collection.is_singleton else "[]" }};
|
|
112
|
+
|
|
113
|
+
{% endif %}
|
|
114
|
+
{% endfor %}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Schema definition.
|
|
120
|
+
*/
|
|
121
|
+
export interface Schema extends System {
|
|
122
|
+
{% for collection in registry.collections -%}
|
|
123
|
+
{% if not collection.is_system %}
|
|
124
|
+
{% set suffix = "" if collection.is_singleton else "[]" %}
|
|
125
|
+
/**
|
|
126
|
+
* The {{ collection.name | to_collection_text }} collection.
|
|
127
|
+
*/
|
|
128
|
+
{{ collection.name | to_ts_identifier }}: Collections.{{ collection.name | pascal_case }}{{ suffix }};
|
|
129
|
+
{% endif %}
|
|
130
|
+
{% endfor %}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|