@directus/api 10.0.0 → 10.1.0

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.
Files changed (104) hide show
  1. package/dist/__mocks__/cache.d.mts +5 -0
  2. package/dist/__mocks__/cache.mjs +7 -0
  3. package/dist/__utils__/items-utils.d.ts +2 -0
  4. package/dist/__utils__/items-utils.js +31 -0
  5. package/dist/__utils__/schemas.d.ts +13 -0
  6. package/dist/__utils__/schemas.js +301 -0
  7. package/dist/__utils__/snapshots.d.ts +5 -0
  8. package/dist/__utils__/snapshots.js +894 -0
  9. package/dist/app.js +17 -0
  10. package/dist/auth/drivers/oauth2.js +1 -1
  11. package/dist/auth/drivers/openid.js +1 -1
  12. package/dist/cli/commands/bootstrap/index.js +1 -0
  13. package/dist/controllers/flows.js +4 -1
  14. package/dist/controllers/schema.js +20 -16
  15. package/dist/controllers/utils.js +4 -2
  16. package/dist/database/migrations/run.js +3 -2
  17. package/dist/env.js +7 -0
  18. package/dist/extensions.js +4 -5
  19. package/dist/flows.d.ts +4 -1
  20. package/dist/flows.js +12 -10
  21. package/dist/services/collections.js +2 -1
  22. package/dist/services/graphql/index.js +4 -2
  23. package/dist/services/items.js +1 -1
  24. package/dist/services/permissions.js +18 -0
  25. package/dist/utils/apply-query.js +12 -2
  26. package/dist/utils/sanitize-error.d.ts +1 -0
  27. package/dist/utils/sanitize-error.js +7 -0
  28. package/dist/utils/sanitize-query.js +1 -1
  29. package/dist/utils/transformations.js +5 -3
  30. package/package.json +19 -20
  31. package/dist/app.test.d.ts +0 -1
  32. package/dist/controllers/files.test.d.ts +0 -1
  33. package/dist/database/migrations/run.test.d.ts +0 -1
  34. package/dist/env.test.d.ts +0 -1
  35. package/dist/logger.test.d.ts +0 -1
  36. package/dist/middleware/authenticate.test.d.ts +0 -1
  37. package/dist/middleware/extract-token.test.d.ts +0 -1
  38. package/dist/middleware/validate-batch.test.d.ts +0 -1
  39. package/dist/operations/condition/index.test.d.ts +0 -1
  40. package/dist/operations/exec/index.test.d.ts +0 -1
  41. package/dist/operations/item-create/index.test.d.ts +0 -1
  42. package/dist/operations/item-delete/index.test.d.ts +0 -1
  43. package/dist/operations/item-read/index.test.d.ts +0 -1
  44. package/dist/operations/item-update/index.test.d.ts +0 -1
  45. package/dist/operations/log/index.test.d.ts +0 -1
  46. package/dist/operations/mail/index.test.d.ts +0 -1
  47. package/dist/operations/notification/index.test.d.ts +0 -1
  48. package/dist/operations/request/index.test.d.ts +0 -1
  49. package/dist/operations/sleep/index.test.d.ts +0 -1
  50. package/dist/operations/transform/index.test.d.ts +0 -1
  51. package/dist/operations/trigger/index.test.d.ts +0 -1
  52. package/dist/request/index.test.d.ts +0 -1
  53. package/dist/request/request-interceptor.test.d.ts +0 -1
  54. package/dist/request/response-interceptor.test.d.ts +0 -1
  55. package/dist/request/validate-ip.test.d.ts +0 -1
  56. package/dist/services/files.test.d.ts +0 -1
  57. package/dist/services/graphql/utils/process-error.test.d.ts +0 -1
  58. package/dist/services/items.test.d.ts +0 -1
  59. package/dist/services/payload.test.d.ts +0 -1
  60. package/dist/services/roles.test.d.ts +0 -1
  61. package/dist/services/schema.test.d.ts +0 -1
  62. package/dist/services/specifications.test.d.ts +0 -1
  63. package/dist/services/users.test.d.ts +0 -1
  64. package/dist/services/webhooks.test.d.ts +0 -1
  65. package/dist/storage/get-storage-driver.test.d.ts +0 -1
  66. package/dist/storage/index.test.d.ts +0 -1
  67. package/dist/storage/register-drivers.test.d.ts +0 -1
  68. package/dist/storage/register-locations.test.d.ts +0 -1
  69. package/dist/utils/apply-diff.test.d.ts +0 -1
  70. package/dist/utils/apply-function-to-column-name.test.d.ts +0 -1
  71. package/dist/utils/apply-snapshot.test.d.ts +0 -1
  72. package/dist/utils/async-handler.test.d.ts +0 -1
  73. package/dist/utils/calculate-field-depth.test.d.ts +0 -1
  74. package/dist/utils/filter-items.test.d.ts +0 -1
  75. package/dist/utils/get-auth-providers.test.d.ts +0 -1
  76. package/dist/utils/get-cache-headers.test.d.ts +0 -1
  77. package/dist/utils/get-cache-key.test.d.ts +0 -1
  78. package/dist/utils/get-collection-from-alias.test.d.ts +0 -1
  79. package/dist/utils/get-column-path.test.d.ts +0 -1
  80. package/dist/utils/get-config-from-env.test.d.ts +0 -1
  81. package/dist/utils/get-date-formatted.test.d.ts +0 -1
  82. package/dist/utils/get-graphql-query-and-variables.test.d.ts +0 -1
  83. package/dist/utils/get-milliseconds.test.d.ts +0 -1
  84. package/dist/utils/get-relation-info.test.d.ts +0 -1
  85. package/dist/utils/get-relation-type.test.d.ts +0 -1
  86. package/dist/utils/get-string-byte-size.test.d.ts +0 -1
  87. package/dist/utils/get-versioned-hash.test.d.ts +0 -1
  88. package/dist/utils/is-directus-jwt.test.d.ts +0 -1
  89. package/dist/utils/jwt.test.d.ts +0 -1
  90. package/dist/utils/map-values-deep.test.d.ts +0 -1
  91. package/dist/utils/md.test.d.ts +0 -1
  92. package/dist/utils/merge-permissions.test.d.ts +0 -1
  93. package/dist/utils/sanitize-query.test.d.ts +0 -1
  94. package/dist/utils/sanitize-schema.test.d.ts +0 -1
  95. package/dist/utils/should-skip-cache.test.d.ts +0 -1
  96. package/dist/utils/stall.test.d.ts +0 -1
  97. package/dist/utils/strip-function.test.d.ts +0 -1
  98. package/dist/utils/url.test.d.ts +0 -1
  99. package/dist/utils/user-name.test.d.ts +0 -1
  100. package/dist/utils/validate-diff.test.d.ts +0 -1
  101. package/dist/utils/validate-env.test.d.ts +0 -1
  102. package/dist/utils/validate-keys.test.d.ts +0 -1
  103. package/dist/utils/validate-query.test.d.ts +0 -1
  104. package/dist/utils/validate-snapshot.test.d.ts +0 -1
@@ -0,0 +1,5 @@
1
+ import type { Mock } from 'vitest';
2
+ export declare const getCache: Mock;
3
+ export declare const flushCaches: Mock;
4
+ export declare const clearSystemCache: Mock;
5
+ export declare const setSystemCache: Mock;
@@ -0,0 +1,7 @@
1
+ import { vi } from 'vitest';
2
+ export const getCache = vi
3
+ .fn()
4
+ .mockReturnValue({ cache: undefined, systemCache: undefined, lockCache: undefined });
5
+ export const flushCaches = vi.fn();
6
+ export const clearSystemCache = vi.fn();
7
+ export const setSystemCache = vi.fn();
@@ -0,0 +1,2 @@
1
+ export declare const sqlFieldFormatter: (schema: Record<string, any>, table: string) => string;
2
+ export declare const sqlFieldList: (schema: Record<string, any>, table: string) => string;
@@ -0,0 +1,31 @@
1
+ // dynamically adds fields to the sql strings as the schema grows
2
+ export const sqlFieldFormatter = (schema, table) => {
3
+ const fields = [];
4
+ // Exclude alias fields, unable to selected in DB
5
+ for (const field of Object.keys(schema['collections'][table].fields)) {
6
+ if (schema['collections'][table].fields[field].type !== 'alias') {
7
+ fields.push(field);
8
+ }
9
+ }
10
+ let sql = '';
11
+ for (const field of fields.slice(0, fields.length - 1)) {
12
+ sql += `"${table}"."${field}", `;
13
+ }
14
+ sql += `"${table}"."${fields[fields.length - 1]}"`;
15
+ return sql;
16
+ };
17
+ export const sqlFieldList = (schema, table) => {
18
+ const fields = [];
19
+ // Exclude alias fields, unable to selected in DB
20
+ for (const field of Object.keys(schema['collections'][table].fields)) {
21
+ if (schema['collections'][table].fields[field].type !== 'alias') {
22
+ fields.push(field);
23
+ }
24
+ }
25
+ let sql = '';
26
+ for (const field of fields.slice(0, fields.length - 1)) {
27
+ sql += `"${field}", `;
28
+ }
29
+ sql += `"${fields[fields.length - 1]}"`;
30
+ return sql;
31
+ };
@@ -0,0 +1,13 @@
1
+ import type { CollectionsOverview, Relation } from '@directus/types';
2
+ export declare const systemSchema: {
3
+ collections: CollectionsOverview;
4
+ relations: Relation[];
5
+ };
6
+ export declare const userSchema: {
7
+ collections: CollectionsOverview;
8
+ relations: Relation[];
9
+ };
10
+ export declare const snapshotApplyTestSchema: {
11
+ collections: CollectionsOverview;
12
+ relations: Relation[];
13
+ };
@@ -0,0 +1,301 @@
1
+ export const systemSchema = {
2
+ collections: {
3
+ directus_users: {
4
+ collection: 'directus_users',
5
+ primary: 'id',
6
+ singleton: false,
7
+ note: '$t:directus_collection.directus_users',
8
+ sortField: null,
9
+ accountability: null,
10
+ fields: {
11
+ id: {
12
+ field: 'id',
13
+ defaultValue: null,
14
+ nullable: false,
15
+ generated: false,
16
+ type: 'uuid',
17
+ dbType: 'uuid',
18
+ precision: null,
19
+ scale: null,
20
+ special: [],
21
+ note: null,
22
+ alias: false,
23
+ validation: null,
24
+ },
25
+ name: {
26
+ field: 'name',
27
+ defaultValue: "A User's Name",
28
+ nullable: false,
29
+ generated: false,
30
+ type: 'uuid',
31
+ dbType: 'uuid',
32
+ precision: null,
33
+ scale: null,
34
+ special: [],
35
+ note: null,
36
+ alias: false,
37
+ validation: null,
38
+ },
39
+ items: {
40
+ field: 'items',
41
+ defaultValue: null,
42
+ nullable: true,
43
+ generated: false,
44
+ type: 'alias',
45
+ dbType: null,
46
+ precision: null,
47
+ scale: null,
48
+ special: ['o2m'],
49
+ note: null,
50
+ alias: true,
51
+ validation: null,
52
+ },
53
+ },
54
+ },
55
+ directus_files: {
56
+ collection: 'directus_files',
57
+ primary: 'id',
58
+ singleton: false,
59
+ note: '$t:directus_collection.directus_files',
60
+ sortField: null,
61
+ accountability: null,
62
+ fields: {
63
+ id: {
64
+ field: 'id',
65
+ defaultValue: null,
66
+ nullable: false,
67
+ generated: false,
68
+ type: 'uuid',
69
+ dbType: 'uuid',
70
+ precision: null,
71
+ scale: null,
72
+ special: [],
73
+ note: null,
74
+ alias: false,
75
+ validation: null,
76
+ },
77
+ title: {
78
+ field: 'title',
79
+ defaultValue: "A File's Title",
80
+ nullable: false,
81
+ generated: false,
82
+ type: 'string',
83
+ dbType: 'text',
84
+ precision: null,
85
+ scale: null,
86
+ special: [],
87
+ note: null,
88
+ alias: false,
89
+ validation: null,
90
+ },
91
+ uploaded_by: {
92
+ field: 'uploaded_by',
93
+ defaultValue: null,
94
+ nullable: true,
95
+ generated: false,
96
+ type: 'uuid',
97
+ dbType: 'uuid',
98
+ precision: null,
99
+ scale: null,
100
+ special: [],
101
+ note: null,
102
+ alias: false,
103
+ validation: null,
104
+ },
105
+ },
106
+ },
107
+ },
108
+ relations: [
109
+ {
110
+ collection: 'directus_files',
111
+ field: 'uploaded_by',
112
+ related_collection: 'directus_users',
113
+ schema: {
114
+ table: 'directus_files',
115
+ column: 'uploaded_by',
116
+ foreign_key_table: 'directus_users',
117
+ foreign_key_column: 'id',
118
+ on_update: 'NO ACTION',
119
+ on_delete: 'NO ACTION',
120
+ constraint_name: null,
121
+ },
122
+ meta: {
123
+ system: true,
124
+ many_collection: 'directus_files',
125
+ many_field: 'uploaded_by',
126
+ one_collection: 'directus_users',
127
+ one_field: 'items',
128
+ one_allowed_collections: null,
129
+ one_collection_field: null,
130
+ one_deselect_action: 'nullify',
131
+ junction_field: null,
132
+ sort_field: null,
133
+ },
134
+ },
135
+ ],
136
+ };
137
+ export const userSchema = {
138
+ collections: {
139
+ authors: {
140
+ collection: 'authors',
141
+ primary: 'id',
142
+ singleton: false,
143
+ note: 'authors',
144
+ sortField: null,
145
+ accountability: null,
146
+ fields: {
147
+ id: {
148
+ field: 'id',
149
+ defaultValue: null,
150
+ nullable: false,
151
+ generated: false,
152
+ type: 'uuid',
153
+ dbType: 'uuid',
154
+ precision: null,
155
+ scale: null,
156
+ special: [],
157
+ note: null,
158
+ alias: false,
159
+ validation: null,
160
+ },
161
+ name: {
162
+ field: 'name',
163
+ defaultValue: "An Author's Name",
164
+ nullable: false,
165
+ generated: false,
166
+ type: 'uuid',
167
+ dbType: 'uuid',
168
+ precision: null,
169
+ scale: null,
170
+ special: [],
171
+ note: null,
172
+ alias: false,
173
+ validation: null,
174
+ },
175
+ items: {
176
+ field: 'items',
177
+ defaultValue: null,
178
+ nullable: true,
179
+ generated: false,
180
+ type: 'alias',
181
+ dbType: null,
182
+ precision: null,
183
+ scale: null,
184
+ special: ['o2m'],
185
+ note: null,
186
+ alias: true,
187
+ validation: null,
188
+ },
189
+ },
190
+ },
191
+ posts: {
192
+ collection: 'posts',
193
+ primary: 'id',
194
+ singleton: false,
195
+ note: 'posts',
196
+ sortField: null,
197
+ accountability: null,
198
+ fields: {
199
+ id: {
200
+ field: 'id',
201
+ defaultValue: null,
202
+ nullable: false,
203
+ generated: false,
204
+ type: 'uuid',
205
+ dbType: 'uuid',
206
+ precision: null,
207
+ scale: null,
208
+ special: [],
209
+ note: null,
210
+ alias: false,
211
+ validation: null,
212
+ },
213
+ title: {
214
+ field: 'title',
215
+ defaultValue: "A Post's Title",
216
+ nullable: false,
217
+ generated: false,
218
+ type: 'string',
219
+ dbType: 'text',
220
+ precision: null,
221
+ scale: null,
222
+ special: [],
223
+ note: null,
224
+ alias: false,
225
+ validation: null,
226
+ },
227
+ uploaded_by: {
228
+ field: 'uploaded_by',
229
+ defaultValue: null,
230
+ nullable: true,
231
+ generated: false,
232
+ type: 'uuid',
233
+ dbType: 'uuid',
234
+ precision: null,
235
+ scale: null,
236
+ special: [],
237
+ note: null,
238
+ alias: false,
239
+ validation: null,
240
+ },
241
+ },
242
+ },
243
+ },
244
+ relations: [
245
+ {
246
+ collection: 'posts',
247
+ field: 'uploaded_by',
248
+ related_collection: 'authors',
249
+ schema: {
250
+ table: 'posts',
251
+ column: 'uploaded_by',
252
+ foreign_key_table: 'authors',
253
+ foreign_key_column: 'id',
254
+ on_update: 'NO ACTION',
255
+ on_delete: 'SET NULL',
256
+ constraint_name: null,
257
+ },
258
+ meta: {
259
+ id: 11,
260
+ many_collection: 'posts',
261
+ many_field: 'uploaded_by',
262
+ one_collection: 'authors',
263
+ one_field: 'items',
264
+ one_collection_field: null,
265
+ one_allowed_collections: null,
266
+ junction_field: null,
267
+ sort_field: null,
268
+ one_deselect_action: 'nullify',
269
+ },
270
+ },
271
+ ],
272
+ };
273
+ export const snapshotApplyTestSchema = {
274
+ collections: {
275
+ test_table: {
276
+ collection: 'test_table',
277
+ primary: 'id',
278
+ singleton: false,
279
+ note: 'test_table',
280
+ sortField: null,
281
+ accountability: 'all',
282
+ fields: {
283
+ id: {
284
+ field: 'id',
285
+ defaultValue: null,
286
+ nullable: false,
287
+ generated: false,
288
+ type: 'uuid',
289
+ dbType: 'uuid',
290
+ precision: null,
291
+ scale: null,
292
+ special: [],
293
+ note: null,
294
+ alias: false,
295
+ validation: null,
296
+ },
297
+ },
298
+ },
299
+ },
300
+ relations: [],
301
+ };
@@ -0,0 +1,5 @@
1
+ import type { Snapshot } from '../types/index.js';
2
+ export declare const snapshotBeforeCreateCollection: Snapshot;
3
+ export declare const snapshotCreateCollection: Snapshot;
4
+ export declare const snapshotCreateCollectionNotNested: Snapshot;
5
+ export declare const snapshotBeforeDeleteCollection: Snapshot;