directus 9.20.4 → 9.21.2

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 (143) hide show
  1. package/dist/auth/drivers/openid.js +3 -1
  2. package/dist/cli/commands/schema/apply.js +0 -2
  3. package/dist/cli/commands/schema/snapshot.js +0 -2
  4. package/dist/cli/utils/create-db-connection.d.ts +1 -1
  5. package/dist/controllers/extensions.js +4 -13
  6. package/dist/database/helpers/date/dialects/sqlite.d.ts +1 -1
  7. package/dist/database/helpers/date/dialects/sqlite.js +4 -0
  8. package/dist/database/helpers/date/types.d.ts +1 -1
  9. package/dist/database/helpers/date/types.js +4 -0
  10. package/dist/database/helpers/fn/dialects/mssql.d.ts +8 -8
  11. package/dist/database/helpers/fn/dialects/mssql.js +22 -16
  12. package/dist/database/helpers/fn/dialects/mysql.d.ts +8 -8
  13. package/dist/database/helpers/fn/dialects/mysql.js +22 -16
  14. package/dist/database/helpers/fn/dialects/postgres.d.ts +8 -8
  15. package/dist/database/helpers/fn/dialects/postgres.js +22 -16
  16. package/dist/database/helpers/fn/types.d.ts +1 -1
  17. package/dist/database/helpers/index.d.ts +1 -1
  18. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -0
  19. package/dist/database/helpers/schema/dialects/cockroachdb.js +11 -0
  20. package/dist/database/helpers/schema/types.d.ts +3 -2
  21. package/dist/database/helpers/schema/types.js +5 -0
  22. package/dist/database/migrations/run.js +29 -3
  23. package/dist/database/run-ast.d.ts +1 -1
  24. package/dist/database/run-ast.js +1 -1
  25. package/dist/env.d.ts +4 -0
  26. package/dist/env.js +9 -4
  27. package/dist/env.test.d.ts +1 -8
  28. package/dist/exceptions/database/contains-null-values.d.ts +1 -1
  29. package/dist/exceptions/database/dialects/types.d.ts +6 -6
  30. package/dist/exceptions/database/invalid-foreign-key.d.ts +1 -1
  31. package/dist/exceptions/database/not-null-violation.d.ts +1 -1
  32. package/dist/exceptions/database/record-not-unique.d.ts +1 -1
  33. package/dist/exceptions/database/value-out-of-range.d.ts +1 -1
  34. package/dist/exceptions/database/value-too-long.d.ts +1 -1
  35. package/dist/exceptions/hit-rate-limit.d.ts +1 -1
  36. package/dist/exceptions/method-not-allowed.d.ts +1 -1
  37. package/dist/exceptions/service-unavailable.d.ts +1 -1
  38. package/dist/extensions.d.ts +7 -7
  39. package/dist/extensions.js +92 -89
  40. package/dist/logger.d.ts +1 -0
  41. package/dist/messenger.d.ts +1 -1
  42. package/dist/middleware/authenticate.d.ts +1 -0
  43. package/dist/middleware/schema.js +1 -1
  44. package/dist/middleware/validate-batch.d.ts +2 -0
  45. package/dist/operations/condition/index.d.ts +1 -1
  46. package/dist/operations/condition/index.js +1 -1
  47. package/dist/operations/condition/index.test.d.ts +1 -0
  48. package/dist/operations/exec/index.d.ts +1 -1
  49. package/dist/operations/item-create/index.d.ts +1 -1
  50. package/dist/operations/item-delete/index.d.ts +1 -1
  51. package/dist/operations/item-read/index.d.ts +1 -1
  52. package/dist/operations/item-update/index.d.ts +1 -1
  53. package/dist/operations/log/index.d.ts +1 -1
  54. package/dist/operations/mail/index.d.ts +1 -1
  55. package/dist/operations/notification/index.d.ts +1 -1
  56. package/dist/operations/request/index.d.ts +1 -1
  57. package/dist/operations/sleep/index.d.ts +1 -1
  58. package/dist/operations/transform/index.d.ts +1 -1
  59. package/dist/operations/trigger/index.d.ts +1 -1
  60. package/dist/operations/trigger/index.js +5 -2
  61. package/dist/rate-limiter.d.ts +1 -1
  62. package/dist/services/authorization.js +7 -3
  63. package/dist/services/collections.d.ts +1 -1
  64. package/dist/services/collections.js +112 -13
  65. package/dist/services/fields.d.ts +5 -4
  66. package/dist/services/fields.js +118 -50
  67. package/dist/services/fields.test.d.ts +1 -0
  68. package/dist/services/graphql/index.js +4 -1
  69. package/dist/services/graphql/utils/process-error.d.ts +4 -0
  70. package/dist/services/graphql/utils/process-error.js +26 -0
  71. package/dist/services/graphql/utils/process-error.test.d.ts +1 -0
  72. package/dist/services/items.d.ts +1 -1
  73. package/dist/services/items.js +39 -13
  74. package/dist/services/mail/index.d.ts +2 -2
  75. package/dist/services/mail/index.js +2 -1
  76. package/dist/services/mail/templates/base.liquid +4 -4
  77. package/dist/services/notifications.js +9 -4
  78. package/dist/services/notifications.test.d.ts +1 -0
  79. package/dist/services/payload.d.ts +2 -2
  80. package/dist/services/payload.js +14 -12
  81. package/dist/services/relations.d.ts +4 -4
  82. package/dist/services/relations.js +66 -8
  83. package/dist/services/users.js +8 -2
  84. package/dist/services/users.test.d.ts +1 -0
  85. package/dist/types/assets.d.ts +7 -7
  86. package/dist/types/ast.d.ts +7 -7
  87. package/dist/types/auth.d.ts +4 -4
  88. package/dist/types/collection.d.ts +2 -2
  89. package/dist/types/events.d.ts +1 -1
  90. package/dist/types/files.d.ts +2 -2
  91. package/dist/types/items.d.ts +5 -5
  92. package/dist/types/migration.d.ts +1 -1
  93. package/dist/types/revision.d.ts +1 -1
  94. package/dist/types/services.d.ts +1 -1
  95. package/dist/types/snapshot.d.ts +4 -4
  96. package/dist/types/webhooks.d.ts +2 -2
  97. package/dist/utils/apply-snapshot.js +32 -13
  98. package/dist/utils/get-ast-from-query.d.ts +1 -1
  99. package/dist/utils/get-column-path.d.ts +2 -2
  100. package/dist/utils/get-module-default.d.ts +1 -1
  101. package/dist/utils/get-relation-info.d.ts +1 -1
  102. package/dist/utils/get-schema.d.ts +6 -2
  103. package/dist/utils/get-schema.js +1 -1
  104. package/dist/utils/get-snapshot.js +1 -1
  105. package/dist/utils/job-queue.d.ts +1 -1
  106. package/dist/utils/merge-permissions.d.ts +1 -0
  107. package/dist/utils/reduce-schema.js +3 -1
  108. package/package.json +69 -80
  109. package/dist/__mocks__/cache.d.ts +0 -5
  110. package/dist/__mocks__/cache.js +0 -7
  111. package/dist/__utils__/items-utils.d.ts +0 -2
  112. package/dist/__utils__/items-utils.js +0 -36
  113. package/dist/__utils__/schemas.d.ts +0 -13
  114. package/dist/__utils__/schemas.js +0 -304
  115. package/dist/__utils__/snapshots.d.ts +0 -5
  116. package/dist/__utils__/snapshots.js +0 -897
  117. package/dist/cli/index.test.js +0 -63
  118. package/dist/controllers/files.test.js +0 -49
  119. package/dist/database/migrations/run.test.js +0 -92
  120. package/dist/env.test.js +0 -40
  121. package/dist/middleware/authenticate.test.js +0 -214
  122. package/dist/middleware/extract-token.test.js +0 -60
  123. package/dist/middleware/validate-batch.test.js +0 -82
  124. package/dist/operations/exec/index.test.js +0 -95
  125. package/dist/services/files.test.js +0 -89
  126. package/dist/services/items.test.js +0 -765
  127. package/dist/services/payload.test.js +0 -196
  128. package/dist/services/specifications.test.js +0 -96
  129. package/dist/utils/apply-snapshot.test.js +0 -305
  130. package/dist/utils/async-handler.test.js +0 -18
  131. package/dist/utils/calculate-field-depth.test.js +0 -76
  132. package/dist/utils/filter-items.test.js +0 -60
  133. package/dist/utils/get-auth-providers.test.js +0 -72
  134. package/dist/utils/get-cache-key.test.js +0 -74
  135. package/dist/utils/get-column-path.test.js +0 -136
  136. package/dist/utils/get-config-from-env.test.js +0 -19
  137. package/dist/utils/get-relation-info.test.js +0 -88
  138. package/dist/utils/get-relation-type.test.js +0 -69
  139. package/dist/utils/get-string-byte-size.test.js +0 -8
  140. package/dist/utils/is-directus-jwt.test.js +0 -26
  141. package/dist/utils/jwt.test.js +0 -36
  142. package/dist/utils/merge-permissions.test.js +0 -80
  143. package/dist/utils/validate-keys.test.js +0 -97
@@ -18,13 +18,13 @@ export interface User {
18
18
  app_access: boolean;
19
19
  admin_access: boolean;
20
20
  }
21
- export declare type AuthData = Record<string, any> | null;
21
+ export type AuthData = Record<string, any> | null;
22
22
  export interface Session {
23
23
  token: string;
24
24
  expires: Date;
25
25
  share: string;
26
26
  }
27
- export declare type DirectusTokenPayload = {
27
+ export type DirectusTokenPayload = {
28
28
  id?: string;
29
29
  role: string | null;
30
30
  app_access: boolean | number;
@@ -35,7 +35,7 @@ export declare type DirectusTokenPayload = {
35
35
  item: string;
36
36
  };
37
37
  };
38
- export declare type ShareData = {
38
+ export type ShareData = {
39
39
  share_id: string;
40
40
  share_role: string;
41
41
  share_item: string;
@@ -46,7 +46,7 @@ export declare type ShareData = {
46
46
  share_max_uses?: number;
47
47
  share_password?: string;
48
48
  };
49
- export declare type LoginResult = {
49
+ export type LoginResult = {
50
50
  accessToken: any;
51
51
  refreshToken: any;
52
52
  expires: any;
@@ -1,6 +1,6 @@
1
1
  import { Table } from 'knex-schema-inspector/dist/types/table';
2
2
  import { Field } from '@directus/shared/types';
3
- export declare type CollectionMeta = {
3
+ export type CollectionMeta = {
4
4
  collection: string;
5
5
  note: string | null;
6
6
  hidden: boolean;
@@ -11,7 +11,7 @@ export declare type CollectionMeta = {
11
11
  accountability: 'all' | 'accountability' | null;
12
12
  group: string | null;
13
13
  };
14
- export declare type Collection = {
14
+ export type Collection = {
15
15
  collection: string;
16
16
  fields?: Field[];
17
17
  meta: CollectionMeta | null;
@@ -1,6 +1,6 @@
1
1
  import { ActionHandler, FilterHandler, InitHandler } from '@directus/shared/types';
2
2
  import { ScheduledTask } from 'node-cron';
3
- export declare type EventHandler = {
3
+ export type EventHandler = {
4
4
  type: 'filter';
5
5
  name: string;
6
6
  handler: FilterHandler;
@@ -1,4 +1,4 @@
1
- export declare type File = {
1
+ export type File = {
2
2
  id: string;
3
3
  storage: string;
4
4
  filename_disk: string;
@@ -19,7 +19,7 @@ export declare type File = {
19
19
  tags: string | null;
20
20
  metadata: Record<string, any> | null;
21
21
  };
22
- export declare type Metadata = {
22
+ export type Metadata = {
23
23
  height?: number | undefined;
24
24
  width?: number | undefined;
25
25
  description?: string | undefined;
@@ -3,9 +3,9 @@
3
3
  * expecting an item vs any other generic object.
4
4
  */
5
5
  import { EventContext } from '@directus/shared/types';
6
- export declare type Item = Record<string, any>;
7
- export declare type PrimaryKey = string | number;
8
- export declare type Alterations = {
6
+ export type Item = Record<string, any>;
7
+ export type PrimaryKey = string | number;
8
+ export type Alterations = {
9
9
  create: {
10
10
  [key: string]: any;
11
11
  }[];
@@ -14,7 +14,7 @@ export declare type Alterations = {
14
14
  }[];
15
15
  delete: (number | string)[];
16
16
  };
17
- export declare type MutationOptions = {
17
+ export type MutationOptions = {
18
18
  /**
19
19
  * Callback function that's fired whenever a revision is made in the mutation
20
20
  */
@@ -37,7 +37,7 @@ export declare type MutationOptions = {
37
37
  */
38
38
  bypassEmitAction?: (params: ActionEventParams) => void;
39
39
  };
40
- export declare type ActionEventParams = {
40
+ export type ActionEventParams = {
41
41
  event: string | string[];
42
42
  meta: Record<string, any>;
43
43
  context: EventContext;
@@ -1,4 +1,4 @@
1
- export declare type Migration = {
1
+ export type Migration = {
2
2
  version: string;
3
3
  name: string;
4
4
  timestamp: Date;
@@ -1,4 +1,4 @@
1
- export declare type Revision = {
1
+ export type Revision = {
2
2
  activity: number;
3
3
  collection: string;
4
4
  item: string | number;
@@ -1,7 +1,7 @@
1
1
  import { Knex } from 'knex';
2
2
  import { Accountability, Query, SchemaOverview } from '@directus/shared/types';
3
3
  import { Item, PrimaryKey } from './items';
4
- export declare type AbstractServiceOptions = {
4
+ export type AbstractServiceOptions = {
5
5
  knex?: Knex;
6
6
  accountability?: Accountability | null;
7
7
  schema: SchemaOverview;
@@ -1,20 +1,20 @@
1
1
  import { Collection } from './collection';
2
2
  import { Relation, RelationMeta, Field, FieldMeta } from '@directus/shared/types';
3
3
  import { Diff } from 'deep-diff';
4
- export declare type Snapshot = {
4
+ export type Snapshot = {
5
5
  version: number;
6
6
  directus: string;
7
7
  collections: Collection[];
8
8
  fields: SnapshotField[];
9
9
  relations: SnapshotRelation[];
10
10
  };
11
- export declare type SnapshotField = Field & {
11
+ export type SnapshotField = Field & {
12
12
  meta: Omit<FieldMeta, 'id'>;
13
13
  };
14
- export declare type SnapshotRelation = Relation & {
14
+ export type SnapshotRelation = Relation & {
15
15
  meta: Omit<RelationMeta, 'id'>;
16
16
  };
17
- export declare type SnapshotDiff = {
17
+ export type SnapshotDiff = {
18
18
  collections: {
19
19
  collection: string;
20
20
  diff: Diff<Collection | undefined>[];
@@ -1,4 +1,4 @@
1
- export declare type Webhook = {
1
+ export type Webhook = {
2
2
  id: number;
3
3
  name: string;
4
4
  method: 'GET' | 'POST';
@@ -9,7 +9,7 @@ export declare type Webhook = {
9
9
  collections: string[];
10
10
  headers: WebhookHeader[];
11
11
  };
12
- export declare type WebhookHeader = {
12
+ export type WebhookHeader = {
13
13
  header: string;
14
14
  value: string;
15
15
  };
@@ -12,13 +12,19 @@ const get_schema_1 = require("./get-schema");
12
12
  const get_snapshot_1 = require("./get-snapshot");
13
13
  const get_snapshot_diff_1 = require("./get-snapshot-diff");
14
14
  const cache_1 = require("../cache");
15
+ const emitter_1 = __importDefault(require("../emitter"));
15
16
  async function applySnapshot(snapshot, options) {
16
17
  var _a, _b, _c, _d;
17
18
  const database = (_a = options === null || options === void 0 ? void 0 : options.database) !== null && _a !== void 0 ? _a : (0, database_1.default)();
18
- const schema = (_b = options === null || options === void 0 ? void 0 : options.schema) !== null && _b !== void 0 ? _b : (await (0, get_schema_1.getSchema)({ database }));
19
+ const schema = (_b = options === null || options === void 0 ? void 0 : options.schema) !== null && _b !== void 0 ? _b : (await (0, get_schema_1.getSchema)({ database, bypassCache: true }));
19
20
  const { systemCache } = (0, cache_1.getCache)();
20
21
  const current = (_c = options === null || options === void 0 ? void 0 : options.current) !== null && _c !== void 0 ? _c : (await (0, get_snapshot_1.getSnapshot)({ database, schema }));
21
22
  const snapshotDiff = (_d = options === null || options === void 0 ? void 0 : options.diff) !== null && _d !== void 0 ? _d : (0, get_snapshot_diff_1.getSnapshotDiff)(current, snapshot);
23
+ const nestedActionEvents = [];
24
+ const mutationOptions = {
25
+ autoPurgeSystemCache: false,
26
+ bypassEmitAction: (params) => nestedActionEvents.push(params),
27
+ };
22
28
  await database.transaction(async (trx) => {
23
29
  const collectionsService = new services_1.CollectionsService({ knex: trx, schema });
24
30
  const getNestedCollectionsToCreate = (currentLevelCollection) => snapshotDiff.collections.filter(({ diff }) => { var _a, _b; return ((_b = (_a = diff[0].rhs) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.group) === currentLevelCollection; });
@@ -49,7 +55,7 @@ async function applySnapshot(snapshot, options) {
49
55
  await collectionsService.createOne({
50
56
  ...diff[0].rhs,
51
57
  fields,
52
- });
58
+ }, mutationOptions);
53
59
  }
54
60
  catch (err) {
55
61
  logger_1.default.error(`Failed to create collection "${collection}"`);
@@ -69,7 +75,7 @@ async function applySnapshot(snapshot, options) {
69
75
  const relationsService = new services_1.RelationsService({ knex: trx, schema });
70
76
  for (const relation of relations) {
71
77
  try {
72
- await relationsService.deleteOne(relation.collection, relation.field);
78
+ await relationsService.deleteOne(relation.collection, relation.field, mutationOptions);
73
79
  }
74
80
  catch (err) {
75
81
  logger_1.default.error(`Failed to delete collection "${collection}" due to relation "${relation.collection}.${relation.field}"`);
@@ -81,7 +87,7 @@ async function applySnapshot(snapshot, options) {
81
87
  }
82
88
  await deleteCollections(getNestedCollectionsToDelete(collection));
83
89
  try {
84
- await collectionsService.deleteOne(collection);
90
+ await collectionsService.deleteOne(collection, mutationOptions);
85
91
  }
86
92
  catch (err) {
87
93
  logger_1.default.error(`Failed to delete collection "${collection}"`);
@@ -130,7 +136,7 @@ async function applySnapshot(snapshot, options) {
130
136
  });
131
137
  if (newValues) {
132
138
  try {
133
- await collectionsService.updateOne(collection, newValues);
139
+ await collectionsService.updateOne(collection, newValues, mutationOptions);
134
140
  }
135
141
  catch (err) {
136
142
  logger_1.default.error(`Failed to update collection "${collection}"`);
@@ -139,11 +145,14 @@ async function applySnapshot(snapshot, options) {
139
145
  }
140
146
  }
141
147
  }
142
- const fieldsService = new services_1.FieldsService({ knex: trx, schema: await (0, get_schema_1.getSchema)({ database: trx }) });
148
+ const fieldsService = new services_1.FieldsService({
149
+ knex: trx,
150
+ schema: await (0, get_schema_1.getSchema)({ database: trx, bypassCache: true }),
151
+ });
143
152
  for (const { collection, field, diff } of snapshotDiff.fields) {
144
153
  if ((diff === null || diff === void 0 ? void 0 : diff[0].kind) === 'N' && !isNestedMetaUpdate(diff === null || diff === void 0 ? void 0 : diff[0])) {
145
154
  try {
146
- await fieldsService.createField(collection, diff[0].rhs);
155
+ await fieldsService.createField(collection, diff[0].rhs, undefined, mutationOptions);
147
156
  }
148
157
  catch (err) {
149
158
  logger_1.default.error(`Failed to create field "${collection}.${field}"`);
@@ -158,7 +167,7 @@ async function applySnapshot(snapshot, options) {
158
167
  try {
159
168
  await fieldsService.updateField(collection, {
160
169
  ...newValues,
161
- });
170
+ }, mutationOptions);
162
171
  }
163
172
  catch (err) {
164
173
  logger_1.default.error(`Failed to update field "${collection}.${field}"`);
@@ -168,7 +177,7 @@ async function applySnapshot(snapshot, options) {
168
177
  }
169
178
  if ((diff === null || diff === void 0 ? void 0 : diff[0].kind) === 'D' && !isNestedMetaUpdate(diff === null || diff === void 0 ? void 0 : diff[0])) {
170
179
  try {
171
- await fieldsService.deleteField(collection, field);
180
+ await fieldsService.deleteField(collection, field, mutationOptions);
172
181
  }
173
182
  catch (err) {
174
183
  logger_1.default.error(`Failed to delete field "${collection}.${field}"`);
@@ -179,7 +188,10 @@ async function applySnapshot(snapshot, options) {
179
188
  snapshotDiff.relations = snapshotDiff.relations.filter((relation) => (relation.collection === collection && relation.field === field) === false);
180
189
  }
181
190
  }
182
- const relationsService = new services_1.RelationsService({ knex: trx, schema: await (0, get_schema_1.getSchema)({ database: trx }) });
191
+ const relationsService = new services_1.RelationsService({
192
+ knex: trx,
193
+ schema: await (0, get_schema_1.getSchema)({ database: trx, bypassCache: true }),
194
+ });
183
195
  for (const { collection, field, diff } of snapshotDiff.relations) {
184
196
  const structure = {};
185
197
  for (const diffEdit of diff) {
@@ -187,7 +199,7 @@ async function applySnapshot(snapshot, options) {
187
199
  }
188
200
  if ((diff === null || diff === void 0 ? void 0 : diff[0].kind) === 'N') {
189
201
  try {
190
- await relationsService.createOne(diff[0].rhs);
202
+ await relationsService.createOne(diff[0].rhs, mutationOptions);
191
203
  }
192
204
  catch (err) {
193
205
  logger_1.default.error(`Failed to create relation "${collection}.${field}"`);
@@ -200,7 +212,7 @@ async function applySnapshot(snapshot, options) {
200
212
  });
201
213
  if (newValues) {
202
214
  try {
203
- await relationsService.updateOne(collection, field, newValues);
215
+ await relationsService.updateOne(collection, field, newValues, mutationOptions);
204
216
  }
205
217
  catch (err) {
206
218
  logger_1.default.error(`Failed to update relation "${collection}.${field}"`);
@@ -210,7 +222,7 @@ async function applySnapshot(snapshot, options) {
210
222
  }
211
223
  if ((diff === null || diff === void 0 ? void 0 : diff[0].kind) === 'D') {
212
224
  try {
213
- await relationsService.deleteOne(collection, field);
225
+ await relationsService.deleteOne(collection, field, mutationOptions);
214
226
  }
215
227
  catch (err) {
216
228
  logger_1.default.error(`Failed to delete relation "${collection}.${field}"`);
@@ -220,6 +232,13 @@ async function applySnapshot(snapshot, options) {
220
232
  }
221
233
  });
222
234
  await (systemCache === null || systemCache === void 0 ? void 0 : systemCache.clear());
235
+ if (nestedActionEvents.length > 0) {
236
+ const updatedSchema = await (0, get_schema_1.getSchema)({ database, bypassCache: true });
237
+ for (const nestedActionEvent of nestedActionEvents) {
238
+ nestedActionEvent.context.schema = updatedSchema;
239
+ emitter_1.default.emitAction(nestedActionEvent.event, nestedActionEvent.meta, nestedActionEvent.context);
240
+ }
241
+ }
223
242
  }
224
243
  exports.applySnapshot = applySnapshot;
225
244
  function isNestedMetaUpdate(diff) {
@@ -4,7 +4,7 @@
4
4
  import { Knex } from 'knex';
5
5
  import { AST } from '../types';
6
6
  import { Query, PermissionsAction, Accountability, SchemaOverview } from '@directus/shared/types';
7
- declare type GetASTOptions = {
7
+ type GetASTOptions = {
8
8
  accountability?: Accountability | null;
9
9
  action?: PermissionsAction;
10
10
  knex?: Knex;
@@ -1,8 +1,8 @@
1
1
  import { Relation } from '@directus/shared/types';
2
- declare type AliasMap = string | {
2
+ type AliasMap = string | {
3
3
  [key: string]: AliasMap;
4
4
  };
5
- export declare type ColPathProps = {
5
+ export type ColPathProps = {
6
6
  path: string[];
7
7
  collection: string;
8
8
  aliasMap: AliasMap;
@@ -1,3 +1,3 @@
1
- export default function getModuleDefault<T>(mod: T | {
1
+ export default function getModuleDefault<T extends object>(mod: T | {
2
2
  default: T;
3
3
  }): T;
@@ -1,5 +1,5 @@
1
1
  import { Relation } from '@directus/shared/types';
2
- declare type RelationInfo = {
2
+ type RelationInfo = {
3
3
  relation: Relation | null;
4
4
  relationType: string | null;
5
5
  };
@@ -1,6 +1,10 @@
1
- import { Accountability, SchemaOverview } from '@directus/shared/types';
1
+ import { SchemaOverview } from '@directus/shared/types';
2
2
  import { Knex } from 'knex';
3
3
  export declare function getSchema(options?: {
4
- accountability?: Accountability;
5
4
  database?: Knex;
5
+ /**
6
+ * To bypass any cached schema if bypassCache is enabled.
7
+ * Used to ensure schema snapshot/apply is not using outdated schema
8
+ */
9
+ bypassCache?: boolean;
6
10
  }): Promise<SchemaOverview>;
@@ -21,7 +21,7 @@ async function getSchema(options) {
21
21
  const database = (options === null || options === void 0 ? void 0 : options.database) || (0, database_1.default)();
22
22
  const schemaInspector = (0, schema_1.default)(database);
23
23
  let result;
24
- if (env_1.default.CACHE_SCHEMA !== false) {
24
+ if (!(options === null || options === void 0 ? void 0 : options.bypassCache) && env_1.default.CACHE_SCHEMA !== false) {
25
25
  let cachedSchema;
26
26
  try {
27
27
  cachedSchema = (await (0, cache_1.getSystemCache)('schema'));
@@ -12,7 +12,7 @@ const lodash_1 = require("lodash");
12
12
  async function getSnapshot(options) {
13
13
  var _a, _b;
14
14
  const database = (_a = options === null || options === void 0 ? void 0 : options.database) !== null && _a !== void 0 ? _a : (0, database_1.default)();
15
- const schema = (_b = options === null || options === void 0 ? void 0 : options.schema) !== null && _b !== void 0 ? _b : (await (0, get_schema_1.getSchema)({ database }));
15
+ const schema = (_b = options === null || options === void 0 ? void 0 : options.schema) !== null && _b !== void 0 ? _b : (await (0, get_schema_1.getSchema)({ database, bypassCache: true }));
16
16
  const collectionsService = new services_1.CollectionsService({ knex: database, schema });
17
17
  const fieldsService = new services_1.FieldsService({ knex: database, schema });
18
18
  const relationsService = new services_1.RelationsService({ knex: database, schema });
@@ -1,4 +1,4 @@
1
- declare type Job = () => Promise<void> | void;
1
+ type Job = () => Promise<void> | void;
2
2
  export declare class JobQueue {
3
3
  private running;
4
4
  private jobs;
@@ -1,3 +1,4 @@
1
+ /// <reference types="lodash" />
1
2
  import { Permission } from '@directus/shared/types';
2
3
  export declare function mergePermissions(strategy: 'and' | 'or', ...permissions: Permission[][]): Permission[];
3
4
  export declare function mergePermission(strategy: 'and' | 'or', currentPerm: Permission, newPerm: Permission): import("lodash").Omit<{
@@ -54,7 +54,9 @@ function reduceSchema(schema, permissions, actions = ['create', 'read', 'update'
54
54
  collectionsAllowed = false;
55
55
  }
56
56
  if (relation.related_collection &&
57
- Object.keys(allowedFieldsInCollection).includes(relation.related_collection) === false) {
57
+ (Object.keys(allowedFieldsInCollection).includes(relation.related_collection) === false ||
58
+ // Ignore legacy permissions with an empty fields array
59
+ allowedFieldsInCollection[relation.related_collection].length === 0)) {
58
60
  collectionsAllowed = false;
59
61
  }
60
62
  if (((_a = relation.meta) === null || _a === void 0 ? void 0 : _a.one_allowed_collections) &&