@directus/api 21.0.0-rc.0 → 21.0.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 (285) hide show
  1. package/dist/app.js +5 -5
  2. package/dist/auth/drivers/ldap.js +4 -4
  3. package/dist/auth/drivers/local.js +4 -4
  4. package/dist/auth/drivers/oauth2.js +4 -4
  5. package/dist/auth/drivers/openid.js +4 -2
  6. package/dist/cache.d.ts +0 -1
  7. package/dist/cache.js +7 -25
  8. package/dist/cli/commands/bootstrap/index.js +2 -8
  9. package/dist/cli/commands/init/index.js +10 -9
  10. package/dist/cli/utils/defaults.d.ts +11 -4
  11. package/dist/cli/utils/defaults.js +1 -7
  12. package/dist/constants.d.ts +1 -1
  13. package/dist/controllers/auth.js +16 -5
  14. package/dist/controllers/permissions.js +2 -14
  15. package/dist/controllers/roles.js +1 -22
  16. package/dist/controllers/tus.js +27 -13
  17. package/dist/controllers/users.js +55 -0
  18. package/dist/database/helpers/fn/types.d.ts +1 -2
  19. package/dist/database/helpers/fn/types.js +1 -1
  20. package/dist/database/helpers/geometry/dialects/mssql.d.ts +1 -1
  21. package/dist/database/helpers/geometry/dialects/mssql.js +2 -4
  22. package/dist/database/helpers/geometry/dialects/mysql.js +1 -1
  23. package/dist/database/helpers/geometry/dialects/oracle.d.ts +1 -1
  24. package/dist/database/helpers/geometry/dialects/oracle.js +3 -5
  25. package/dist/database/helpers/geometry/types.d.ts +1 -1
  26. package/dist/database/helpers/geometry/types.js +2 -4
  27. package/dist/database/index.js +11 -8
  28. package/dist/database/migrations/20240305A-change-useragent-type.js +1 -1
  29. package/dist/database/migrations/20240716A-update-files-date-fields.js +33 -0
  30. package/dist/database/{run-ast/types.d.ts → run-ast.d.ts} +9 -3
  31. package/dist/database/run-ast.js +458 -0
  32. package/dist/flows.js +4 -3
  33. package/dist/logger/index.js +1 -1
  34. package/dist/middleware/authenticate.js +7 -2
  35. package/dist/middleware/cache.js +1 -1
  36. package/dist/middleware/check-ip.d.ts +2 -0
  37. package/dist/middleware/check-ip.js +37 -0
  38. package/dist/middleware/error-handler.d.ts +2 -2
  39. package/dist/middleware/error-handler.js +54 -51
  40. package/dist/middleware/get-permissions.d.ts +3 -0
  41. package/dist/middleware/get-permissions.js +10 -0
  42. package/dist/middleware/respond.js +1 -1
  43. package/dist/services/activity.js +10 -22
  44. package/dist/services/assets.d.ts +3 -2
  45. package/dist/services/assets.js +7 -15
  46. package/dist/services/authentication.js +18 -18
  47. package/dist/services/authorization.d.ts +17 -0
  48. package/dist/services/authorization.js +456 -0
  49. package/dist/services/collections.js +17 -18
  50. package/dist/services/fields.d.ts +4 -0
  51. package/dist/services/fields.js +53 -58
  52. package/dist/services/files/lib/get-sharp-instance.d.ts +2 -0
  53. package/dist/services/files/lib/get-sharp-instance.js +10 -0
  54. package/dist/services/files/utils/get-metadata.js +7 -6
  55. package/dist/services/files.js +8 -10
  56. package/dist/services/graphql/index.d.ts +3 -3
  57. package/dist/services/graphql/index.js +22 -126
  58. package/dist/services/graphql/subscription.js +4 -2
  59. package/dist/services/import-export.js +4 -18
  60. package/dist/services/index.d.ts +2 -3
  61. package/dist/services/index.js +2 -3
  62. package/dist/services/items.js +44 -115
  63. package/dist/services/mail/index.d.ts +1 -1
  64. package/dist/services/mail/index.js +9 -1
  65. package/dist/services/meta.js +23 -60
  66. package/dist/services/notifications.js +6 -14
  67. package/dist/services/payload.d.ts +10 -9
  68. package/dist/services/payload.js +3 -18
  69. package/dist/services/{permissions.d.ts → permissions/index.d.ts} +7 -5
  70. package/dist/services/{permissions.js → permissions/index.js} +54 -30
  71. package/dist/{permissions → services/permissions}/lib/with-app-minimal-permissions.d.ts +1 -1
  72. package/dist/services/permissions/lib/with-app-minimal-permissions.js +13 -0
  73. package/dist/services/relations.d.ts +9 -1
  74. package/dist/services/relations.js +56 -31
  75. package/dist/services/roles.d.ts +12 -4
  76. package/dist/services/roles.js +424 -57
  77. package/dist/services/shares.d.ts +2 -0
  78. package/dist/services/shares.js +8 -12
  79. package/dist/services/specifications.d.ts +2 -2
  80. package/dist/services/specifications.js +27 -39
  81. package/dist/services/tus/data-store.js +4 -5
  82. package/dist/services/tus/server.d.ts +1 -1
  83. package/dist/services/tus/server.js +9 -2
  84. package/dist/services/users.d.ts +5 -1
  85. package/dist/services/users.js +161 -78
  86. package/dist/services/utils.js +7 -11
  87. package/dist/services/versions.d.ts +2 -0
  88. package/dist/services/versions.js +10 -34
  89. package/dist/telemetry/lib/get-report.js +2 -2
  90. package/dist/telemetry/utils/check-increased-user-limits.d.ts +7 -0
  91. package/dist/telemetry/utils/check-increased-user-limits.js +25 -0
  92. package/dist/telemetry/utils/get-role-counts-by-roles.d.ts +6 -0
  93. package/dist/telemetry/utils/get-role-counts-by-roles.js +27 -0
  94. package/dist/telemetry/utils/get-role-counts-by-users.d.ts +11 -0
  95. package/dist/telemetry/utils/get-role-counts-by-users.js +34 -0
  96. package/dist/telemetry/utils/get-user-count.d.ts +8 -0
  97. package/dist/telemetry/utils/get-user-count.js +33 -0
  98. package/dist/telemetry/utils/get-user-counts-by-roles.d.ts +7 -0
  99. package/dist/telemetry/utils/get-user-counts-by-roles.js +35 -0
  100. package/dist/types/ast.d.ts +1 -43
  101. package/dist/types/items.d.ts +0 -11
  102. package/dist/utils/apply-query.d.ts +3 -4
  103. package/dist/utils/apply-query.js +16 -39
  104. package/dist/utils/get-accountability-for-role.js +25 -16
  105. package/dist/utils/get-accountability-for-token.js +16 -17
  106. package/dist/utils/get-ast-from-query.d.ts +13 -0
  107. package/dist/utils/get-ast-from-query.js +297 -0
  108. package/dist/utils/get-cache-key.d.ts +1 -1
  109. package/dist/utils/get-cache-key.js +1 -12
  110. package/dist/utils/get-column.d.ts +1 -2
  111. package/dist/utils/get-column.js +0 -1
  112. package/dist/utils/get-permissions.d.ts +2 -0
  113. package/dist/utils/get-permissions.js +150 -0
  114. package/dist/utils/get-schema.js +3 -3
  115. package/dist/utils/get-service.js +1 -5
  116. package/dist/utils/merge-permissions-for-share.d.ts +4 -0
  117. package/dist/utils/merge-permissions-for-share.js +109 -0
  118. package/dist/utils/merge-permissions.d.ts +3 -0
  119. package/dist/utils/merge-permissions.js +95 -0
  120. package/dist/utils/reduce-schema.d.ts +6 -4
  121. package/dist/utils/reduce-schema.js +32 -16
  122. package/dist/websocket/authenticate.d.ts +2 -0
  123. package/dist/websocket/authenticate.js +12 -0
  124. package/dist/websocket/controllers/graphql.js +4 -1
  125. package/dist/websocket/controllers/hooks.js +0 -4
  126. package/dist/websocket/controllers/rest.js +2 -0
  127. package/dist/websocket/handlers/subscribe.js +2 -0
  128. package/dist/websocket/utils/items.d.ts +1 -1
  129. package/package.json +36 -37
  130. package/dist/controllers/access.d.ts +0 -2
  131. package/dist/controllers/access.js +0 -148
  132. package/dist/controllers/policies.d.ts +0 -2
  133. package/dist/controllers/policies.js +0 -169
  134. package/dist/database/get-ast-from-query/get-ast-from-query.d.ts +0 -16
  135. package/dist/database/get-ast-from-query/get-ast-from-query.js +0 -82
  136. package/dist/database/get-ast-from-query/lib/convert-wildcards.d.ts +0 -13
  137. package/dist/database/get-ast-from-query/lib/convert-wildcards.js +0 -69
  138. package/dist/database/get-ast-from-query/lib/parse-fields.d.ts +0 -15
  139. package/dist/database/get-ast-from-query/lib/parse-fields.js +0 -190
  140. package/dist/database/get-ast-from-query/utils/get-deep-query.d.ts +0 -14
  141. package/dist/database/get-ast-from-query/utils/get-deep-query.js +0 -17
  142. package/dist/database/get-ast-from-query/utils/get-related-collection.d.ts +0 -2
  143. package/dist/database/get-ast-from-query/utils/get-related-collection.js +0 -13
  144. package/dist/database/get-ast-from-query/utils/get-relation.d.ts +0 -2
  145. package/dist/database/get-ast-from-query/utils/get-relation.js +0 -7
  146. package/dist/database/migrations/20240710A-permissions-policies.js +0 -169
  147. package/dist/database/run-ast/lib/get-db-query.d.ts +0 -4
  148. package/dist/database/run-ast/lib/get-db-query.js +0 -208
  149. package/dist/database/run-ast/lib/parse-current-level.d.ts +0 -7
  150. package/dist/database/run-ast/lib/parse-current-level.js +0 -41
  151. package/dist/database/run-ast/run-ast.d.ts +0 -7
  152. package/dist/database/run-ast/run-ast.js +0 -107
  153. package/dist/database/run-ast/types.js +0 -1
  154. package/dist/database/run-ast/utils/apply-case-when.d.ts +0 -16
  155. package/dist/database/run-ast/utils/apply-case-when.js +0 -26
  156. package/dist/database/run-ast/utils/apply-parent-filters.d.ts +0 -3
  157. package/dist/database/run-ast/utils/apply-parent-filters.js +0 -55
  158. package/dist/database/run-ast/utils/get-column-pre-processor.d.ts +0 -10
  159. package/dist/database/run-ast/utils/get-column-pre-processor.js +0 -57
  160. package/dist/database/run-ast/utils/get-field-alias.d.ts +0 -2
  161. package/dist/database/run-ast/utils/get-field-alias.js +0 -4
  162. package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.d.ts +0 -5
  163. package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.js +0 -23
  164. package/dist/database/run-ast/utils/merge-with-parent-items.d.ts +0 -3
  165. package/dist/database/run-ast/utils/merge-with-parent-items.js +0 -87
  166. package/dist/database/run-ast/utils/remove-temporary-fields.d.ts +0 -3
  167. package/dist/database/run-ast/utils/remove-temporary-fields.js +0 -73
  168. package/dist/permissions/cache.d.ts +0 -2
  169. package/dist/permissions/cache.js +0 -23
  170. package/dist/permissions/lib/fetch-permissions.d.ts +0 -10
  171. package/dist/permissions/lib/fetch-permissions.js +0 -55
  172. package/dist/permissions/lib/fetch-policies.d.ts +0 -7
  173. package/dist/permissions/lib/fetch-policies.js +0 -28
  174. package/dist/permissions/lib/fetch-roles-tree.d.ts +0 -3
  175. package/dist/permissions/lib/fetch-roles-tree.js +0 -28
  176. package/dist/permissions/lib/with-app-minimal-permissions.js +0 -10
  177. package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.d.ts +0 -7
  178. package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.js +0 -56
  179. package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.d.ts +0 -3
  180. package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.js +0 -16
  181. package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.d.ts +0 -8
  182. package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.js +0 -24
  183. package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.d.ts +0 -9
  184. package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js +0 -31
  185. package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.d.ts +0 -16
  186. package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.js +0 -27
  187. package/dist/permissions/modules/fetch-global-access/fetch-global-access.d.ts +0 -10
  188. package/dist/permissions/modules/fetch-global-access/fetch-global-access.js +0 -23
  189. package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.d.ts +0 -5
  190. package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.js +0 -7
  191. package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.d.ts +0 -5
  192. package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.js +0 -10
  193. package/dist/permissions/modules/fetch-global-access/types.d.ts +0 -4
  194. package/dist/permissions/modules/fetch-global-access/types.js +0 -1
  195. package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.d.ts +0 -4
  196. package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.js +0 -27
  197. package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.d.ts +0 -12
  198. package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.js +0 -32
  199. package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.d.ts +0 -4
  200. package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js +0 -29
  201. package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.d.ts +0 -4
  202. package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.js +0 -49
  203. package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.d.ts +0 -3
  204. package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.js +0 -56
  205. package/dist/permissions/modules/process-ast/lib/field-map-from-ast.d.ts +0 -4
  206. package/dist/permissions/modules/process-ast/lib/field-map-from-ast.js +0 -8
  207. package/dist/permissions/modules/process-ast/lib/inject-cases.d.ts +0 -9
  208. package/dist/permissions/modules/process-ast/lib/inject-cases.js +0 -93
  209. package/dist/permissions/modules/process-ast/process-ast.d.ts +0 -9
  210. package/dist/permissions/modules/process-ast/process-ast.js +0 -39
  211. package/dist/permissions/modules/process-ast/types.d.ts +0 -24
  212. package/dist/permissions/modules/process-ast/types.js +0 -1
  213. package/dist/permissions/modules/process-ast/utils/collections-in-field-map.d.ts +0 -2
  214. package/dist/permissions/modules/process-ast/utils/collections-in-field-map.js +0 -7
  215. package/dist/permissions/modules/process-ast/utils/dedupe-access.d.ts +0 -12
  216. package/dist/permissions/modules/process-ast/utils/dedupe-access.js +0 -30
  217. package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.d.ts +0 -15
  218. package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.js +0 -50
  219. package/dist/permissions/modules/process-ast/utils/find-related-collection.d.ts +0 -3
  220. package/dist/permissions/modules/process-ast/utils/find-related-collection.js +0 -9
  221. package/dist/permissions/modules/process-ast/utils/flatten-filter.d.ts +0 -3
  222. package/dist/permissions/modules/process-ast/utils/flatten-filter.js +0 -34
  223. package/dist/permissions/modules/process-ast/utils/format-a2o-key.d.ts +0 -1
  224. package/dist/permissions/modules/process-ast/utils/format-a2o-key.js +0 -3
  225. package/dist/permissions/modules/process-ast/utils/get-info-for-path.d.ts +0 -5
  226. package/dist/permissions/modules/process-ast/utils/get-info-for-path.js +0 -7
  227. package/dist/permissions/modules/process-ast/utils/has-item-permissions.d.ts +0 -2
  228. package/dist/permissions/modules/process-ast/utils/has-item-permissions.js +0 -3
  229. package/dist/permissions/modules/process-ast/utils/stringify-query-path.d.ts +0 -2
  230. package/dist/permissions/modules/process-ast/utils/stringify-query-path.js +0 -3
  231. package/dist/permissions/modules/process-ast/utils/validate-path/create-error.d.ts +0 -3
  232. package/dist/permissions/modules/process-ast/utils/validate-path/create-error.js +0 -16
  233. package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.d.ts +0 -2
  234. package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.js +0 -12
  235. package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.d.ts +0 -2
  236. package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.js +0 -28
  237. package/dist/permissions/modules/process-payload/lib/is-field-nullable.d.ts +0 -5
  238. package/dist/permissions/modules/process-payload/lib/is-field-nullable.js +0 -12
  239. package/dist/permissions/modules/process-payload/process-payload.d.ts +0 -13
  240. package/dist/permissions/modules/process-payload/process-payload.js +0 -77
  241. package/dist/permissions/modules/validate-access/lib/validate-collection-access.d.ts +0 -12
  242. package/dist/permissions/modules/validate-access/lib/validate-collection-access.js +0 -11
  243. package/dist/permissions/modules/validate-access/lib/validate-item-access.d.ts +0 -9
  244. package/dist/permissions/modules/validate-access/lib/validate-item-access.js +0 -33
  245. package/dist/permissions/modules/validate-access/validate-access.d.ts +0 -14
  246. package/dist/permissions/modules/validate-access/validate-access.js +0 -28
  247. package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.d.ts +0 -1
  248. package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js +0 -8
  249. package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.d.ts +0 -5
  250. package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.js +0 -10
  251. package/dist/permissions/types.d.ts +0 -6
  252. package/dist/permissions/types.js +0 -1
  253. package/dist/permissions/utils/create-default-accountability.d.ts +0 -2
  254. package/dist/permissions/utils/create-default-accountability.js +0 -11
  255. package/dist/permissions/utils/extract-required-dynamic-variable-context.d.ts +0 -8
  256. package/dist/permissions/utils/extract-required-dynamic-variable-context.js +0 -27
  257. package/dist/permissions/utils/fetch-dynamic-variable-context.d.ts +0 -9
  258. package/dist/permissions/utils/fetch-dynamic-variable-context.js +0 -43
  259. package/dist/permissions/utils/filter-policies-by-ip.d.ts +0 -2
  260. package/dist/permissions/utils/filter-policies-by-ip.js +0 -15
  261. package/dist/permissions/utils/get-unaliased-field-key.d.ts +0 -5
  262. package/dist/permissions/utils/get-unaliased-field-key.js +0 -17
  263. package/dist/permissions/utils/process-permissions.d.ts +0 -7
  264. package/dist/permissions/utils/process-permissions.js +0 -9
  265. package/dist/permissions/utils/with-cache.d.ts +0 -10
  266. package/dist/permissions/utils/with-cache.js +0 -25
  267. package/dist/services/access.d.ts +0 -10
  268. package/dist/services/access.js +0 -43
  269. package/dist/services/policies.d.ts +0 -12
  270. package/dist/services/policies.js +0 -87
  271. package/dist/telemetry/utils/check-user-limits.d.ts +0 -5
  272. package/dist/telemetry/utils/check-user-limits.js +0 -19
  273. package/dist/utils/fetch-user-count/fetch-access-lookup.d.ts +0 -17
  274. package/dist/utils/fetch-user-count/fetch-access-lookup.js +0 -22
  275. package/dist/utils/fetch-user-count/fetch-access-roles.d.ts +0 -16
  276. package/dist/utils/fetch-user-count/fetch-access-roles.js +0 -37
  277. package/dist/utils/fetch-user-count/fetch-active-users.d.ts +0 -6
  278. package/dist/utils/fetch-user-count/fetch-active-users.js +0 -3
  279. package/dist/utils/fetch-user-count/fetch-user-count.d.ts +0 -12
  280. package/dist/utils/fetch-user-count/fetch-user-count.js +0 -57
  281. package/dist/utils/fetch-user-count/get-user-count-query.d.ts +0 -20
  282. package/dist/utils/fetch-user-count/get-user-count-query.js +0 -17
  283. package/dist/utils/validate-user-count-integrity.d.ts +0 -13
  284. package/dist/utils/validate-user-count-integrity.js +0 -29
  285. /package/dist/database/migrations/{20240710A-permissions-policies.d.ts → 20240716A-update-files-date-fields.d.ts} +0 -0
@@ -1,7 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Context } from '../types.js';
3
- export declare const fetchPolicies: typeof _fetchPolicies;
4
- /**
5
- * Fetch the policies associated with the current user accountability
6
- */
7
- export declare function _fetchPolicies({ roles, user, ip }: Pick<Accountability, 'user' | 'roles' | 'ip'>, context: Context): Promise<string[]>;
@@ -1,28 +0,0 @@
1
- import { filterPoliciesByIp } from '../utils/filter-policies-by-ip.js';
2
- import { withCache } from '../utils/with-cache.js';
3
- export const fetchPolicies = withCache('policies', _fetchPolicies, ({ roles, user, ip }) => ({ roles, user, ip }));
4
- /**
5
- * Fetch the policies associated with the current user accountability
6
- */
7
- export async function _fetchPolicies({ roles, user, ip }, context) {
8
- const { AccessService } = await import('../../services/access.js');
9
- const accessService = new AccessService(context);
10
- let roleFilter;
11
- if (roles.length === 0) {
12
- // Users without role assumes the Public role permissions along with their attached policies
13
- roleFilter = { _and: [{ role: { _null: true } }, { user: { _null: true } }] };
14
- }
15
- else {
16
- roleFilter = { role: { _in: roles } };
17
- }
18
- // If the user is not null, we also want to include the policies attached to the user
19
- const filter = user ? { _or: [{ user: { _eq: user } }, roleFilter] } : roleFilter;
20
- const accessRows = (await accessService.readByQuery({
21
- filter,
22
- fields: ['policy.id', 'policy.ip_access'],
23
- limit: -1,
24
- }));
25
- const filteredAccessRows = filterPoliciesByIp(accessRows, ip);
26
- const ids = filteredAccessRows.map(({ policy }) => policy.id);
27
- return ids;
28
- }
@@ -1,3 +0,0 @@
1
- import type { Knex } from 'knex';
2
- export declare const fetchRolesTree: typeof _fetchRolesTree;
3
- export declare function _fetchRolesTree(start: string | null, knex: Knex): Promise<string[]>;
@@ -1,28 +0,0 @@
1
- import { withCache } from '../utils/with-cache.js';
2
- export const fetchRolesTree = withCache('roles-tree', _fetchRolesTree);
3
- export async function _fetchRolesTree(start, knex) {
4
- if (!start)
5
- return [];
6
- let parent = start;
7
- const roles = [];
8
- while (parent) {
9
- const role = await knex
10
- .select('id', 'parent')
11
- .from('directus_roles')
12
- .where({ id: parent })
13
- .first();
14
- if (!role) {
15
- break;
16
- }
17
- roles.push(role.id);
18
- // Prevent infinite recursion loops
19
- if (role.parent && roles.includes(role.parent) === true) {
20
- roles.reverse();
21
- const rolesStr = roles.map((role) => `"${role}"`).join('->');
22
- throw new Error(`Recursion encountered: role "${role.id}" already exists in tree path ${rolesStr}`);
23
- }
24
- parent = role.parent;
25
- }
26
- roles.reverse();
27
- return roles;
28
- }
@@ -1,10 +0,0 @@
1
- import { appAccessMinimalPermissions } from '@directus/system-data';
2
- import { cloneDeep } from 'lodash-es';
3
- import { filterItems } from '../../utils/filter-items.js';
4
- export function withAppMinimalPermissions(accountability, permissions, filter) {
5
- if (accountability?.app === true) {
6
- const filteredAppMinimalPermissions = cloneDeep(filterItems(appAccessMinimalPermissions, filter));
7
- return [...permissions, ...filteredAppMinimalPermissions];
8
- }
9
- return permissions;
10
- }
@@ -1,7 +0,0 @@
1
- import type { Accountability, CollectionAccess } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- /**
4
- * Get all permissions + minimal app permissions (if applicable) for the user + role in the current accountability.
5
- * The permissions will be filtered by IP access.
6
- */
7
- export declare function fetchAccountabilityCollectionAccess(accountability: Pick<Accountability, 'user' | 'roles' | 'role' | 'ip' | 'admin' | 'app'>, context: Context): Promise<CollectionAccess>;
@@ -1,56 +0,0 @@
1
- import { PERMISSION_ACTIONS } from '@directus/constants';
2
- import { mapValues, uniq } from 'lodash-es';
3
- import { fetchPermissions } from '../../lib/fetch-permissions.js';
4
- import { fetchPolicies } from '../../lib/fetch-policies.js';
5
- /**
6
- * Get all permissions + minimal app permissions (if applicable) for the user + role in the current accountability.
7
- * The permissions will be filtered by IP access.
8
- */
9
- export async function fetchAccountabilityCollectionAccess(accountability, context) {
10
- if (accountability.admin) {
11
- return mapValues(context.schema.collections, () => Object.fromEntries(PERMISSION_ACTIONS.map((action) => [
12
- action,
13
- {
14
- access: 'full',
15
- fields: ['*'],
16
- },
17
- ])));
18
- }
19
- const policies = await fetchPolicies(accountability, context);
20
- const permissions = await fetchPermissions({ policies, accountability }, context);
21
- const infos = {};
22
- for (const perm of permissions) {
23
- // Ensure that collection is in infos
24
- if (!infos[perm.collection]) {
25
- infos[perm.collection] = {
26
- read: { access: 'none' },
27
- create: { access: 'none' },
28
- update: { access: 'none' },
29
- delete: { access: 'none' },
30
- share: { access: 'none' },
31
- };
32
- }
33
- // Ensure that action with default values is in collection infos
34
- if (infos[perm.collection][perm.action]?.access === 'none') {
35
- // If a permissions is iterated over it means that the user has access to it, so set access to 'full'
36
- // Set access to 'full' initially and refine that whenever a permission with filters is encountered
37
- infos[perm.collection][perm.action].access = 'full';
38
- }
39
- const info = infos[perm.collection][perm.action];
40
- // Set access to 'partial' if the permission has filters, which means that the user has conditional access
41
- if (info.access === 'full' && perm.permissions && Object.keys(perm.permissions).length > 0) {
42
- info.access = 'partial';
43
- }
44
- if (perm.fields && info.fields?.[0] !== '*') {
45
- info.fields = uniq([...(info.fields || []), ...(perm.fields || [])]);
46
- if (info.fields.includes('*')) {
47
- info.fields = ['*'];
48
- }
49
- }
50
- if (perm.presets) {
51
- info.presets = { ...(info.presets ?? {}), ...perm.presets };
52
- }
53
- }
54
- // TODO Should fields by null, undefined or and empty array if no access?
55
- return infos;
56
- }
@@ -1,3 +0,0 @@
1
- import type { Accountability, Globals } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- export declare function fetchAccountabilityPolicyGlobals(accountability: Pick<Accountability, 'user' | 'roles' | 'ip' | 'admin' | 'app'>, context: Context): Promise<Globals>;
@@ -1,16 +0,0 @@
1
- import { fetchPolicies } from '../../lib/fetch-policies.js';
2
- export async function fetchAccountabilityPolicyGlobals(accountability, context) {
3
- const policies = await fetchPolicies(accountability, context);
4
- // Policies are already filtered down by the accountability IP, so we don't need to check it again
5
- const result = await context.knex
6
- .select(1)
7
- .from('directus_policies')
8
- .whereIn('id', policies)
9
- .where('enforce_tfa', true)
10
- .first();
11
- return {
12
- app_access: accountability.app,
13
- admin_access: accountability.admin,
14
- enforce_tfa: !!result,
15
- };
16
- }
@@ -1,8 +0,0 @@
1
- import type { Accountability, PermissionsAction } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- export interface FetchAllowedCollectionsOptions {
4
- action: PermissionsAction;
5
- accountability: Pick<Accountability, 'user' | 'role' | 'roles' | 'ip' | 'admin' | 'app'>;
6
- }
7
- export declare const fetchAllowedCollections: typeof _fetchAllowedCollections;
8
- export declare function _fetchAllowedCollections({ action, accountability }: FetchAllowedCollectionsOptions, { knex, schema }: Context): Promise<string[]>;
@@ -1,24 +0,0 @@
1
- import { uniq } from 'lodash-es';
2
- import { fetchPolicies } from '../../lib/fetch-policies.js';
3
- import { withCache } from '../../utils/with-cache.js';
4
- import { fetchPermissions } from '../../lib/fetch-permissions.js';
5
- export const fetchAllowedCollections = withCache('allowed-collections', _fetchAllowedCollections, ({ action, accountability: { user, role, roles, ip, admin, app } }) => ({
6
- action,
7
- accountability: {
8
- user,
9
- role,
10
- roles,
11
- ip,
12
- admin,
13
- app,
14
- },
15
- }));
16
- export async function _fetchAllowedCollections({ action, accountability }, { knex, schema }) {
17
- if (accountability.admin) {
18
- return Object.keys(schema.collections);
19
- }
20
- const policies = await fetchPolicies(accountability, { knex, schema });
21
- const permissions = await fetchPermissions({ action, policies, accountability }, { knex, schema });
22
- const collections = permissions.map(({ collection }) => collection);
23
- return uniq(collections);
24
- }
@@ -1,9 +0,0 @@
1
- import type { Accountability, PermissionsAction } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- export type FieldMap = Record<string, string[]>;
4
- export interface FetchAllowedFieldMapOptions {
5
- accountability: Pick<Accountability, 'user' | 'role' | 'roles' | 'ip' | 'admin' | 'app'>;
6
- action: PermissionsAction;
7
- }
8
- export declare const fetchAllowedFieldMap: typeof _fetchAllowedFieldMap;
9
- export declare function _fetchAllowedFieldMap({ accountability, action }: FetchAllowedFieldMapOptions, { knex, schema }: Context): Promise<FieldMap>;
@@ -1,31 +0,0 @@
1
- import { uniq } from 'lodash-es';
2
- import { fetchPolicies } from '../../lib/fetch-policies.js';
3
- import { withCache } from '../../utils/with-cache.js';
4
- import { fetchPermissions } from '../../lib/fetch-permissions.js';
5
- export const fetchAllowedFieldMap = withCache('allowed-field-map', _fetchAllowedFieldMap, ({ action, accountability: { user, role, roles, ip, admin, app } }) => ({
6
- action,
7
- accountability: { user, role, roles, ip, admin, app },
8
- }));
9
- export async function _fetchAllowedFieldMap({ accountability, action }, { knex, schema }) {
10
- const fieldMap = {};
11
- if (accountability.admin) {
12
- for (const [collection, { fields }] of Object.entries(schema.collections)) {
13
- fieldMap[collection] = Object.keys(fields);
14
- }
15
- return fieldMap;
16
- }
17
- const policies = await fetchPolicies(accountability, { knex, schema });
18
- const permissions = await fetchPermissions({ action, policies, accountability }, { knex, schema });
19
- for (const { collection, fields } of permissions) {
20
- if (!fieldMap[collection]) {
21
- fieldMap[collection] = [];
22
- }
23
- if (fields) {
24
- fieldMap[collection].push(...fields);
25
- }
26
- }
27
- for (const [collection, fields] of Object.entries(fieldMap)) {
28
- fieldMap[collection] = uniq(fields);
29
- }
30
- return fieldMap;
31
- }
@@ -1,16 +0,0 @@
1
- import type { Accountability, PermissionsAction } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- export interface FetchAllowedFieldsOptions {
4
- collection: string;
5
- action: PermissionsAction;
6
- accountability: Pick<Accountability, 'user' | 'role' | 'roles' | 'ip' | 'app'>;
7
- }
8
- export declare const fetchAllowedFields: typeof _fetchAllowedFields;
9
- /**
10
- * Look up all fields that are allowed to be used for the given collection and action for the given
11
- * accountability object
12
- *
13
- * Done by looking up all available policies for the current accountability object, and reading all
14
- * permissions that exist for the collection+action+policy combination
15
- */
16
- export declare function _fetchAllowedFields({ accountability, action, collection }: FetchAllowedFieldsOptions, { knex, schema }: Context): Promise<string[]>;
@@ -1,27 +0,0 @@
1
- import { uniq } from 'lodash-es';
2
- import { fetchPermissions } from '../../lib/fetch-permissions.js';
3
- import { fetchPolicies } from '../../lib/fetch-policies.js';
4
- import { withCache } from '../../utils/with-cache.js';
5
- export const fetchAllowedFields = withCache('allowed-fields', _fetchAllowedFields, ({ action, collection, accountability: { user, role, roles, ip, app } }) => ({
6
- action,
7
- collection,
8
- accountability: { user, role, roles, ip, app },
9
- }));
10
- /**
11
- * Look up all fields that are allowed to be used for the given collection and action for the given
12
- * accountability object
13
- *
14
- * Done by looking up all available policies for the current accountability object, and reading all
15
- * permissions that exist for the collection+action+policy combination
16
- */
17
- export async function _fetchAllowedFields({ accountability, action, collection }, { knex, schema }) {
18
- const policies = await fetchPolicies(accountability, { knex, schema });
19
- const permissions = await fetchPermissions({ action, collections: [collection], policies, accountability }, { knex, schema });
20
- const allowedFields = [];
21
- for (const { fields } of permissions) {
22
- if (!fields)
23
- continue;
24
- allowedFields.push(...fields);
25
- }
26
- return uniq(allowedFields).filter((field) => field === '*' || field in (schema.collections[collection]?.fields ?? {}));
27
- }
@@ -1,10 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Knex } from 'knex';
3
- import type { GlobalAccess } from './types.js';
4
- export declare const fetchGlobalAccess: typeof _fetchGlobalAccess;
5
- /**
6
- * Fetch the global access (eg admin/app access) rules for the given roles, or roles+user combination
7
- *
8
- * Will fetch roles and user info separately so they can be cached and reused individually
9
- */
10
- export declare function _fetchGlobalAccess(accountability: Pick<Accountability, 'user' | 'roles' | 'ip'>, knex: Knex): Promise<GlobalAccess>;
@@ -1,23 +0,0 @@
1
- import { withCache } from '../../utils/with-cache.js';
2
- import { fetchGlobalAccessForRoles } from './lib/fetch-global-access-for-roles.js';
3
- import { fetchGlobalAccessForUser } from './lib/fetch-global-access-for-user.js';
4
- export const fetchGlobalAccess = withCache('global-access', _fetchGlobalAccess, ({ user, roles, ip }) => ({
5
- user,
6
- roles,
7
- ip,
8
- }));
9
- /**
10
- * Fetch the global access (eg admin/app access) rules for the given roles, or roles+user combination
11
- *
12
- * Will fetch roles and user info separately so they can be cached and reused individually
13
- */
14
- export async function _fetchGlobalAccess(accountability, knex) {
15
- const access = await fetchGlobalAccessForRoles(accountability, knex);
16
- if (accountability.user !== undefined) {
17
- const userAccess = await fetchGlobalAccessForUser(accountability, knex);
18
- // If app/admin is already true, keep it true
19
- access.app ||= userAccess.app;
20
- access.admin ||= userAccess.admin;
21
- }
22
- return access;
23
- }
@@ -1,5 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Knex } from 'knex';
3
- import type { GlobalAccess } from '../types.js';
4
- export declare const fetchGlobalAccessForRoles: typeof _fetchGlobalAccessForRoles;
5
- export declare function _fetchGlobalAccessForRoles(accountability: Pick<Accountability, 'roles' | 'ip'>, knex: Knex): Promise<GlobalAccess>;
@@ -1,7 +0,0 @@
1
- import { withCache } from '../../../utils/with-cache.js';
2
- import { fetchGlobalAccessForQuery } from '../utils/fetch-global-access-for-query.js';
3
- export const fetchGlobalAccessForRoles = withCache('global-access-role', _fetchGlobalAccessForRoles, ({ roles, ip }) => ({ roles, ip }));
4
- export async function _fetchGlobalAccessForRoles(accountability, knex) {
5
- const query = knex.where('role', 'in', accountability.roles);
6
- return await fetchGlobalAccessForQuery(query, accountability);
7
- }
@@ -1,5 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Knex } from 'knex';
3
- import type { GlobalAccess } from '../types.js';
4
- export declare const fetchGlobalAccessForUser: typeof _fetchGlobalAccessForUser;
5
- export declare function _fetchGlobalAccessForUser(accountability: Pick<Accountability, 'user' | 'ip'>, knex: Knex): Promise<GlobalAccess>;
@@ -1,10 +0,0 @@
1
- import { withCache } from '../../../utils/with-cache.js';
2
- import { fetchGlobalAccessForQuery } from '../utils/fetch-global-access-for-query.js';
3
- export const fetchGlobalAccessForUser = withCache('global-access-user', _fetchGlobalAccessForUser, ({ user, ip }) => ({
4
- user,
5
- ip,
6
- }));
7
- export async function _fetchGlobalAccessForUser(accountability, knex) {
8
- const query = knex.where('user', '=', accountability.user);
9
- return await fetchGlobalAccessForQuery(query, accountability);
10
- }
@@ -1,4 +0,0 @@
1
- export interface GlobalAccess {
2
- app: boolean;
3
- admin: boolean;
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Knex } from 'knex';
3
- import type { GlobalAccess } from '../types.js';
4
- export declare function fetchGlobalAccessForQuery(query: Knex.QueryBuilder<any, any[]>, accountability: Pick<Accountability, 'ip'>): Promise<GlobalAccess>;
@@ -1,27 +0,0 @@
1
- import { toBoolean, toArray } from '@directus/utils';
2
- import { ipInNetworks } from '../../../../utils/ip-in-networks.js';
3
- export async function fetchGlobalAccessForQuery(query, accountability) {
4
- const globalAccess = {
5
- app: false,
6
- admin: false,
7
- };
8
- const accessRows = await query
9
- .select('directus_policies.admin_access', 'directus_policies.app_access', 'directus_policies.ip_access')
10
- .from('directus_access')
11
- // @NOTE: `where` clause comes from the caller
12
- .leftJoin('directus_policies', 'directus_policies.id', 'directus_access.policy');
13
- // Additively merge access permissions
14
- for (const { admin_access, app_access, ip_access } of accessRows) {
15
- if (accountability.ip && ip_access) {
16
- // Skip row if IP is not in the allowed networks
17
- const networks = toArray(ip_access);
18
- if (!ipInNetworks(accountability.ip, networks))
19
- continue;
20
- }
21
- globalAccess.admin ||= toBoolean(admin_access);
22
- globalAccess.app ||= globalAccess.admin || toBoolean(app_access);
23
- if (globalAccess.admin)
24
- break;
25
- }
26
- return globalAccess;
27
- }
@@ -1,12 +0,0 @@
1
- import type { Accountability, PermissionsAction } from '@directus/types';
2
- import type { Context } from '../../types.js';
3
- export type FieldMap = Record<string, string[]>;
4
- export interface FetchInconsistentFieldMapOptions {
5
- accountability: Pick<Accountability, 'user' | 'role' | 'roles' | 'ip' | 'admin' | 'app'> | null;
6
- action: PermissionsAction;
7
- }
8
- /**
9
- * Fetch a field map for fields that may or may not be null based on item-by-item permissions.
10
- */
11
- export declare const fetchInconsistentFieldMap: typeof _fetchInconsistentFieldMap;
12
- export declare function _fetchInconsistentFieldMap({ accountability, action }: FetchInconsistentFieldMapOptions, { knex, schema }: Context): Promise<FieldMap>;
@@ -1,32 +0,0 @@
1
- import { uniq, intersection, difference, pick } from 'lodash-es';
2
- import { fetchPolicies } from '../../lib/fetch-policies.js';
3
- import { withCache } from '../../utils/with-cache.js';
4
- import { fetchPermissions } from '../../lib/fetch-permissions.js';
5
- /**
6
- * Fetch a field map for fields that may or may not be null based on item-by-item permissions.
7
- */
8
- export const fetchInconsistentFieldMap = withCache('inconsistent-field-map', _fetchInconsistentFieldMap, ({ action, accountability }) => ({
9
- action,
10
- accountability: accountability ? pick(accountability, ['user', 'role', 'roles', 'ip', 'admin', 'app']) : null,
11
- }));
12
- export async function _fetchInconsistentFieldMap({ accountability, action }, { knex, schema }) {
13
- const fieldMap = {};
14
- if (!accountability || accountability.admin) {
15
- for (const collection of Object.keys(schema.collections)) {
16
- fieldMap[collection] = [];
17
- }
18
- return fieldMap;
19
- }
20
- const policies = await fetchPolicies(accountability, { knex, schema });
21
- const permissions = await fetchPermissions({ action, policies, accountability }, { knex, schema });
22
- const collections = uniq(permissions.map(({ collection }) => collection));
23
- for (const collection of collections) {
24
- const fields = permissions
25
- .filter((permission) => permission.collection === collection)
26
- .map((permission) => permission.fields ?? []);
27
- const availableEverywhere = intersection(...fields);
28
- const availableSomewhere = difference(uniq(fields.flat()), availableEverywhere);
29
- fieldMap[collection] = availableSomewhere;
30
- }
31
- return fieldMap;
32
- }
@@ -1,4 +0,0 @@
1
- import type { Accountability } from '@directus/types';
2
- import type { Knex } from 'knex';
3
- export declare const fetchPoliciesIpAccess: typeof _fetchPoliciesIpAccess;
4
- export declare function _fetchPoliciesIpAccess(accountability: Pick<Accountability, 'user' | 'roles'>, knex: Knex): Promise<string[][]>;
@@ -1,29 +0,0 @@
1
- import { toArray } from '@directus/utils';
2
- import { withCache } from '../../utils/with-cache.js';
3
- export const fetchPoliciesIpAccess = withCache('policies-ip-access', _fetchPoliciesIpAccess, ({ user, roles }) => ({
4
- user,
5
- roles,
6
- }));
7
- export async function _fetchPoliciesIpAccess(accountability, knex) {
8
- const query = knex('directus_access')
9
- .select({ ip_access: 'directus_policies.ip_access' })
10
- .leftJoin('directus_policies', 'directus_access.policy', 'directus_policies.id')
11
- .whereNotNull('directus_policies.ip_access');
12
- // No roles and no user means unauthenticated request
13
- if (accountability.roles.length === 0 && !accountability.user) {
14
- query.where({
15
- role: null,
16
- user: null,
17
- });
18
- }
19
- else {
20
- query.where(function () {
21
- if (accountability.user) {
22
- this.orWhere('directus_access.user', accountability.user);
23
- }
24
- this.orWhereIn('directus_access.role', accountability.roles);
25
- });
26
- }
27
- const rows = await query;
28
- return rows.filter(({ ip_access }) => ip_access).map(({ ip_access }) => toArray(ip_access));
29
- }
@@ -1,4 +0,0 @@
1
- import type { SchemaOverview } from '@directus/types';
2
- import type { FieldNode, FunctionFieldNode, NestedCollectionNode } from '../../../../types/ast.js';
3
- import type { FieldMap, QueryPath } from '../types.js';
4
- export declare function extractFieldsFromChildren(collection: string, children: (NestedCollectionNode | FieldNode | FunctionFieldNode)[], fieldMap: FieldMap, schema: SchemaOverview, path?: QueryPath): void;
@@ -1,49 +0,0 @@
1
- import { getUnaliasedFieldKey } from '../../../utils/get-unaliased-field-key.js';
2
- import { formatA2oKey } from '../utils/format-a2o-key.js';
3
- import { getInfoForPath } from '../utils/get-info-for-path.js';
4
- import { extractFieldsFromQuery } from './extract-fields-from-query.js';
5
- export function extractFieldsFromChildren(collection, children, fieldMap, schema, path = []) {
6
- const info = getInfoForPath(fieldMap, 'other', path, collection);
7
- for (const child of children) {
8
- info.fields.add(getUnaliasedFieldKey(child));
9
- if (child.type === 'a2o') {
10
- for (const [collection, children] of Object.entries(child.children)) {
11
- extractFieldsFromChildren(collection, children, fieldMap, schema, [
12
- ...path,
13
- formatA2oKey(child.fieldKey, collection),
14
- ]);
15
- }
16
- if (child.query) {
17
- for (const [collection, query] of Object.entries(child.query)) {
18
- extractFieldsFromQuery(collection, query, fieldMap, schema, [
19
- ...path,
20
- formatA2oKey(child.fieldKey, collection),
21
- ]);
22
- }
23
- }
24
- }
25
- else if (child.type === 'm2o') {
26
- extractFieldsFromChildren(child.relation.related_collection, child.children, fieldMap, schema, [
27
- ...path,
28
- child.fieldKey,
29
- ]);
30
- extractFieldsFromQuery(child.relation.related_collection, child.query, fieldMap, schema, [
31
- ...path,
32
- child.fieldKey,
33
- ]);
34
- }
35
- else if (child.type === 'o2m') {
36
- extractFieldsFromChildren(child.relation.collection, child.children, fieldMap, schema, [
37
- ...path,
38
- child.fieldKey,
39
- ]);
40
- extractFieldsFromQuery(child.relation.collection, child.query, fieldMap, schema, [...path, child.fieldKey]);
41
- }
42
- else if (child.type === 'functionField') {
43
- // functionFields operate on a related o2m collection, we have to make sure we include a
44
- // no-field read check to the related collection
45
- extractFieldsFromChildren(child.relatedCollection, [], fieldMap, schema, [...path, child.fieldKey]);
46
- extractFieldsFromQuery(child.relatedCollection, child.query, fieldMap, schema, [...path, child.fieldKey]);
47
- }
48
- }
49
- }
@@ -1,3 +0,0 @@
1
- import type { Query, SchemaOverview } from '@directus/types';
2
- import type { CollectionKey, FieldKey, FieldMap } from '../types.js';
3
- export declare function extractFieldsFromQuery(collection: CollectionKey, query: Query, fieldMap: FieldMap, schema: SchemaOverview, pathPrefix?: FieldKey[]): void;
@@ -1,56 +0,0 @@
1
- import { parseFilterKey } from '../../../../utils/parse-filter-key.js';
2
- import { extractPathsFromQuery } from '../utils/extract-paths-from-query.js';
3
- import { findRelatedCollection } from '../utils/find-related-collection.js';
4
- import { getInfoForPath } from '../utils/get-info-for-path.js';
5
- export function extractFieldsFromQuery(collection, query, fieldMap, schema, pathPrefix = []) {
6
- if (!query)
7
- return;
8
- const { paths: otherPaths, readOnlyPaths } = extractPathsFromQuery(query);
9
- const groupedPaths = {
10
- other: otherPaths,
11
- read: readOnlyPaths,
12
- };
13
- for (const [group, paths] of Object.entries(groupedPaths)) {
14
- for (const path of paths) {
15
- /**
16
- * Current path stack. For each iteration of the path loop this will be appended with the
17
- * current part we're operating on. So when looping over ['category', 'created_by', 'name']
18
- * the first iteration it'll be `['category']`, and then `['category', 'created_by']` etc.
19
- */
20
- const stack = [];
21
- /**
22
- * Current collection the path part we're operating on lives in. Once we hit a relational
23
- * field, this will be updated to the related collection, so we can follow the relational path
24
- * left to right.
25
- */
26
- let collectionContext = collection;
27
- for (const part of path) {
28
- const info = getInfoForPath(fieldMap, group, [...pathPrefix, ...stack], collectionContext);
29
- // A2o specifier field fetch
30
- if (part.includes(':')) {
31
- const [fieldKey, collection] = part.split(':');
32
- info.fields.add(fieldKey);
33
- collectionContext = collection;
34
- stack.push(part);
35
- continue;
36
- }
37
- if (part.startsWith('$FOLLOW(') && part.endsWith(')')) {
38
- // Don't add this implicit relation field to fields, as it will be accounted for in the reverse direction
39
- }
40
- else {
41
- const { fieldName } = parseFilterKey(part);
42
- info.fields.add(fieldName);
43
- }
44
- /**
45
- * Related collection for the current part. Is null when the current field isn't a
46
- * relational field.
47
- */
48
- const relatedCollection = findRelatedCollection(collectionContext, part, schema);
49
- if (relatedCollection) {
50
- collectionContext = relatedCollection;
51
- stack.push(part);
52
- }
53
- }
54
- }
55
- }
56
- }
@@ -1,4 +0,0 @@
1
- import type { SchemaOverview } from '@directus/types';
2
- import type { AST } from '../../../../types/ast.js';
3
- import type { FieldMap } from '../types.js';
4
- export declare function fieldMapFromAst(ast: AST, schema: SchemaOverview): FieldMap;
@@ -1,8 +0,0 @@
1
- import { extractFieldsFromChildren } from './extract-fields-from-children.js';
2
- import { extractFieldsFromQuery } from './extract-fields-from-query.js';
3
- export function fieldMapFromAst(ast, schema) {
4
- const fieldMap = { read: new Map(), other: new Map() };
5
- extractFieldsFromChildren(ast.name, ast.children, fieldMap, schema);
6
- extractFieldsFromQuery(ast.name, ast.query, fieldMap, schema);
7
- return fieldMap;
8
- }