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
@@ -99,6 +99,7 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
99
99
  code_challenge_method: 'S256',
100
100
  // Some providers require state even with PKCE
101
101
  state: codeChallenge,
102
+ nonce: codeChallenge,
102
103
  });
103
104
  }
104
105
  catch (e) {
@@ -122,7 +123,8 @@ class OpenIDAuthDriver extends local_1.LocalAuthDriver {
122
123
  let userInfo;
123
124
  try {
124
125
  const client = await this.client;
125
- tokenSet = await client.callback(this.redirectUrl, { code: payload.code, state: payload.state }, { code_verifier: payload.codeVerifier, state: openid_client_1.generators.codeChallenge(payload.codeVerifier) });
126
+ const codeChallenge = openid_client_1.generators.codeChallenge(payload.codeVerifier);
127
+ tokenSet = await client.callback(this.redirectUrl, { code: payload.code, state: payload.state }, { code_verifier: payload.codeVerifier, state: codeChallenge, nonce: codeChallenge });
126
128
  userInfo = tokenSet.claims();
127
129
  if (client.issuer.metadata.userinfo_endpoint) {
128
130
  userInfo = {
@@ -33,7 +33,6 @@ const fs_1 = require("fs");
33
33
  const inquirer_1 = __importDefault(require("inquirer"));
34
34
  const js_yaml_1 = require("js-yaml");
35
35
  const path_1 = __importDefault(require("path"));
36
- const cache_1 = require("../../../cache");
37
36
  const database_1 = __importStar(require("../../../database"));
38
37
  const logger_1 = __importDefault(require("../../../logger"));
39
38
  const apply_snapshot_1 = require("../../../utils/apply-snapshot");
@@ -44,7 +43,6 @@ async function apply(snapshotPath, options) {
44
43
  const filename = path_1.default.resolve(process.cwd(), snapshotPath);
45
44
  const database = (0, database_1.default)();
46
45
  await (0, database_1.validateDatabaseConnection)(database);
47
- await (0, cache_1.flushCaches)();
48
46
  if ((await (0, database_1.isInstalled)()) === false) {
49
47
  logger_1.default.error(`Directus isn't installed on this database. Please run "directus bootstrap" first.`);
50
48
  database.destroy();
@@ -11,9 +11,7 @@ const fs_1 = require("fs");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const inquirer_1 = __importDefault(require("inquirer"));
13
13
  const js_yaml_1 = require("js-yaml");
14
- const cache_1 = require("../../../cache");
15
14
  async function snapshot(snapshotPath, options) {
16
- await (0, cache_1.flushCaches)();
17
15
  const database = (0, database_1.default)();
18
16
  try {
19
17
  const snapshot = await (0, get_snapshot_1.getSnapshot)({ database });
@@ -1,5 +1,5 @@
1
1
  import { Knex } from 'knex';
2
- export declare type Credentials = {
2
+ export type Credentials = {
3
3
  filename?: string;
4
4
  host?: string;
5
5
  port?: number;
@@ -26,23 +26,14 @@ router.get('/:type', (0, async_handler_1.default)(async (req, res, next) => {
26
26
  };
27
27
  return next();
28
28
  }), respond_1.respond);
29
- router.get('/:type/index.js', (0, async_handler_1.default)(async (req, res) => {
30
- const type = (0, utils_1.depluralize)(req.params.type);
31
- if (!(0, utils_1.isIn)(type, constants_1.APP_OR_HYBRID_EXTENSION_TYPES)) {
32
- throw new exceptions_1.RouteNotFoundException(req.path);
33
- }
29
+ router.get('/sources/index.js', (0, async_handler_1.default)(async (req, res) => {
34
30
  const extensionManager = (0, extensions_1.getExtensionManager)();
35
- const extensionSource = extensionManager.getAppExtensions(type);
36
- if (extensionSource === undefined) {
31
+ const extensionSource = extensionManager.getAppExtensions();
32
+ if (extensionSource === null) {
37
33
  throw new exceptions_1.RouteNotFoundException(req.path);
38
34
  }
39
35
  res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
40
- if (env_1.default.EXTENSIONS_CACHE_TTL) {
41
- res.setHeader('Cache-Control', (0, get_cache_headers_1.getCacheControlHeader)(req, (0, ms_1.default)(env_1.default.EXTENSIONS_CACHE_TTL)));
42
- }
43
- else {
44
- res.setHeader('Cache-Control', 'no-store');
45
- }
36
+ res.setHeader('Cache-Control', env_1.default.EXTENSIONS_CACHE_TTL ? (0, get_cache_headers_1.getCacheControlHeader)(req, (0, ms_1.default)(env_1.default.EXTENSIONS_CACHE_TTL)) : 'no-store');
46
37
  res.setHeader('Vary', 'Origin, Cache-Control');
47
38
  res.end(extensionSource);
48
39
  }));
@@ -1,5 +1,5 @@
1
1
  import { DateHelper } from '../types';
2
2
  export declare class DateHelperSQLite extends DateHelper {
3
- parse(date: string): string;
3
+ parse(date: string | Date): string;
4
4
  fieldFlagForField(fieldType: string): string;
5
5
  }
@@ -7,6 +7,10 @@ class DateHelperSQLite extends types_1.DateHelper {
7
7
  if (!date) {
8
8
  return date;
9
9
  }
10
+ // Date generated from NOW()
11
+ if (date instanceof Date) {
12
+ return String(date.getTime());
13
+ }
10
14
  // Return the time as string
11
15
  if (date.length <= 8 && date.includes(':')) {
12
16
  return date;
@@ -1,6 +1,6 @@
1
1
  import { DatabaseHelper } from '../types';
2
2
  export declare abstract class DateHelper extends DatabaseHelper {
3
- parse(date: string): string;
3
+ parse(date: string | Date): string;
4
4
  readTimestampString(date: string): string;
5
5
  writeTimestamp(date: string): Date;
6
6
  fieldFlagForField(_fieldType: string): string;
@@ -5,6 +5,10 @@ const types_1 = require("../types");
5
5
  const date_fns_1 = require("date-fns");
6
6
  class DateHelper extends types_1.DatabaseHelper {
7
7
  parse(date) {
8
+ // Date generated from NOW()
9
+ if (date instanceof Date) {
10
+ return date.toISOString();
11
+ }
8
12
  return date;
9
13
  }
10
14
  readTimestampString(date) {
@@ -1,13 +1,13 @@
1
1
  import { FnHelper, FnHelperOptions } from '../types';
2
2
  import { Knex } from 'knex';
3
3
  export declare class FnHelperMSSQL extends FnHelper {
4
- year(table: string, column: string): Knex.Raw;
5
- month(table: string, column: string): Knex.Raw;
6
- week(table: string, column: string): Knex.Raw;
7
- day(table: string, column: string): Knex.Raw;
8
- weekday(table: string, column: string): Knex.Raw;
9
- hour(table: string, column: string): Knex.Raw;
10
- minute(table: string, column: string): Knex.Raw;
11
- second(table: string, column: string): Knex.Raw;
4
+ year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
5
+ month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
6
+ week(table: string, column: string, options: FnHelperOptions): Knex.Raw;
7
+ day(table: string, column: string, options: FnHelperOptions): Knex.Raw;
8
+ weekday(table: string, column: string, options: FnHelperOptions): Knex.Raw;
9
+ hour(table: string, column: string, options: FnHelperOptions): Knex.Raw;
10
+ minute(table: string, column: string, options: FnHelperOptions): Knex.Raw;
11
+ second(table: string, column: string, options: FnHelperOptions): Knex.Raw;
12
12
  count(table: string, column: string, options?: FnHelperOptions): Knex.Raw<any>;
13
13
  }
@@ -2,30 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FnHelperMSSQL = void 0;
4
4
  const types_1 = require("../types");
5
+ const parseLocaltime = (columnType) => {
6
+ if (columnType === 'timestamp') {
7
+ return ` AT TIME ZONE 'UTC'`;
8
+ }
9
+ return '';
10
+ };
5
11
  class FnHelperMSSQL extends types_1.FnHelper {
6
- year(table, column) {
7
- return this.knex.raw('DATEPART(year, ??.??)', [table, column]);
12
+ year(table, column, options) {
13
+ return this.knex.raw(`DATEPART(year, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
8
14
  }
9
- month(table, column) {
10
- return this.knex.raw('DATEPART(month, ??.??)', [table, column]);
15
+ month(table, column, options) {
16
+ return this.knex.raw(`DATEPART(month, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
11
17
  }
12
- week(table, column) {
13
- return this.knex.raw('DATEPART(week, ??.??)', [table, column]);
18
+ week(table, column, options) {
19
+ return this.knex.raw(`DATEPART(week, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
14
20
  }
15
- day(table, column) {
16
- return this.knex.raw('DATEPART(day, ??.??)', [table, column]);
21
+ day(table, column, options) {
22
+ return this.knex.raw(`DATEPART(day, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
17
23
  }
18
- weekday(table, column) {
19
- return this.knex.raw('DATEPART(weekday, ??.??)', [table, column]);
24
+ weekday(table, column, options) {
25
+ return this.knex.raw(`DATEPART(weekday, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
20
26
  }
21
- hour(table, column) {
22
- return this.knex.raw('DATEPART(hour, ??.??)', [table, column]);
27
+ hour(table, column, options) {
28
+ return this.knex.raw(`DATEPART(hour, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
23
29
  }
24
- minute(table, column) {
25
- return this.knex.raw('DATEPART(minute, ??.??)', [table, column]);
30
+ minute(table, column, options) {
31
+ return this.knex.raw(`DATEPART(minute, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
26
32
  }
27
- second(table, column) {
28
- return this.knex.raw('DATEPART(second, ??.??)', [table, column]);
33
+ second(table, column, options) {
34
+ return this.knex.raw(`DATEPART(second, ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
29
35
  }
30
36
  count(table, column, options) {
31
37
  var _a, _b, _c, _d, _e;
@@ -1,13 +1,13 @@
1
1
  import { FnHelper, FnHelperOptions } from '../types';
2
2
  import { Knex } from 'knex';
3
3
  export declare class FnHelperMySQL extends FnHelper {
4
- year(table: string, column: string): Knex.Raw;
5
- month(table: string, column: string): Knex.Raw;
6
- week(table: string, column: string): Knex.Raw;
7
- day(table: string, column: string): Knex.Raw;
8
- weekday(table: string, column: string): Knex.Raw;
9
- hour(table: string, column: string): Knex.Raw;
10
- minute(table: string, column: string): Knex.Raw;
11
- second(table: string, column: string): Knex.Raw;
4
+ year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
5
+ month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
6
+ week(table: string, column: string, options: FnHelperOptions): Knex.Raw;
7
+ day(table: string, column: string, options: FnHelperOptions): Knex.Raw;
8
+ weekday(table: string, column: string, options: FnHelperOptions): Knex.Raw;
9
+ hour(table: string, column: string, options: FnHelperOptions): Knex.Raw;
10
+ minute(table: string, column: string, options: FnHelperOptions): Knex.Raw;
11
+ second(table: string, column: string, options: FnHelperOptions): Knex.Raw;
12
12
  count(table: string, column: string, options?: FnHelperOptions): Knex.Raw;
13
13
  }
@@ -2,30 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FnHelperMySQL = void 0;
4
4
  const types_1 = require("../types");
5
+ const parseLocaltime = (columnType) => {
6
+ if (columnType === 'timestamp') {
7
+ return `CONVERT_TZ(??.??, @@GLOBAL.time_zone, '+00:00')`;
8
+ }
9
+ return '??.??';
10
+ };
5
11
  class FnHelperMySQL extends types_1.FnHelper {
6
- year(table, column) {
7
- return this.knex.raw('YEAR(??.??)', [table, column]);
12
+ year(table, column, options) {
13
+ return this.knex.raw(`YEAR(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
8
14
  }
9
- month(table, column) {
10
- return this.knex.raw('MONTH(??.??)', [table, column]);
15
+ month(table, column, options) {
16
+ return this.knex.raw(`MONTH(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
11
17
  }
12
- week(table, column) {
13
- return this.knex.raw('WEEK(??.??)', [table, column]);
18
+ week(table, column, options) {
19
+ return this.knex.raw(`WEEK(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
14
20
  }
15
- day(table, column) {
16
- return this.knex.raw('DAYOFMONTH(??.??)', [table, column]);
21
+ day(table, column, options) {
22
+ return this.knex.raw(`DAYOFMONTH(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
17
23
  }
18
- weekday(table, column) {
19
- return this.knex.raw('DAYOFWEEK(??.??)', [table, column]);
24
+ weekday(table, column, options) {
25
+ return this.knex.raw(`DAYOFWEEK(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
20
26
  }
21
- hour(table, column) {
22
- return this.knex.raw('HOUR(??.??)', [table, column]);
27
+ hour(table, column, options) {
28
+ return this.knex.raw(`HOUR(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
23
29
  }
24
- minute(table, column) {
25
- return this.knex.raw('MINUTE(??.??)', [table, column]);
30
+ minute(table, column, options) {
31
+ return this.knex.raw(`MINUTE(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
26
32
  }
27
- second(table, column) {
28
- return this.knex.raw('SECOND(??.??)', [table, column]);
33
+ second(table, column, options) {
34
+ return this.knex.raw(`SECOND(${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
29
35
  }
30
36
  count(table, column, options) {
31
37
  var _a, _b, _c, _d, _e;
@@ -1,13 +1,13 @@
1
1
  import { FnHelper, FnHelperOptions } from '../types';
2
2
  import { Knex } from 'knex';
3
3
  export declare class FnHelperPostgres extends FnHelper {
4
- year(table: string, column: string): Knex.Raw;
5
- month(table: string, column: string): Knex.Raw;
6
- week(table: string, column: string): Knex.Raw;
7
- day(table: string, column: string): Knex.Raw;
8
- weekday(table: string, column: string): Knex.Raw;
9
- hour(table: string, column: string): Knex.Raw;
10
- minute(table: string, column: string): Knex.Raw;
11
- second(table: string, column: string): Knex.Raw;
4
+ year(table: string, column: string, options: FnHelperOptions): Knex.Raw;
5
+ month(table: string, column: string, options: FnHelperOptions): Knex.Raw;
6
+ week(table: string, column: string, options: FnHelperOptions): Knex.Raw;
7
+ day(table: string, column: string, options: FnHelperOptions): Knex.Raw;
8
+ weekday(table: string, column: string, options: FnHelperOptions): Knex.Raw;
9
+ hour(table: string, column: string, options: FnHelperOptions): Knex.Raw;
10
+ minute(table: string, column: string, options: FnHelperOptions): Knex.Raw;
11
+ second(table: string, column: string, options: FnHelperOptions): Knex.Raw;
12
12
  count(table: string, column: string, options?: FnHelperOptions): Knex.Raw;
13
13
  }
@@ -2,30 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FnHelperPostgres = void 0;
4
4
  const types_1 = require("../types");
5
+ const parseLocaltime = (columnType) => {
6
+ if (columnType === 'timestamp') {
7
+ return ` AT TIME ZONE 'UTC'`;
8
+ }
9
+ return '';
10
+ };
5
11
  class FnHelperPostgres extends types_1.FnHelper {
6
- year(table, column) {
7
- return this.knex.raw('EXTRACT(YEAR FROM ??.??)', [table, column]);
12
+ year(table, column, options) {
13
+ return this.knex.raw(`EXTRACT(YEAR FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
8
14
  }
9
- month(table, column) {
10
- return this.knex.raw('EXTRACT(MONTH FROM ??.??)', [table, column]);
15
+ month(table, column, options) {
16
+ return this.knex.raw(`EXTRACT(MONTH FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
11
17
  }
12
- week(table, column) {
13
- return this.knex.raw('EXTRACT(WEEK FROM ??.??)', [table, column]);
18
+ week(table, column, options) {
19
+ return this.knex.raw(`EXTRACT(WEEK FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
14
20
  }
15
- day(table, column) {
16
- return this.knex.raw('EXTRACT(DAY FROM ??.??)', [table, column]);
21
+ day(table, column, options) {
22
+ return this.knex.raw(`EXTRACT(DAY FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
17
23
  }
18
- weekday(table, column) {
19
- return this.knex.raw('EXTRACT(DOW FROM ??.??)', [table, column]);
24
+ weekday(table, column, options) {
25
+ return this.knex.raw(`EXTRACT(DOW FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
20
26
  }
21
- hour(table, column) {
22
- return this.knex.raw('EXTRACT(HOUR FROM ??.??)', [table, column]);
27
+ hour(table, column, options) {
28
+ return this.knex.raw(`EXTRACT(HOUR FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
23
29
  }
24
- minute(table, column) {
25
- return this.knex.raw('EXTRACT(MINUTE FROM ??.??)', [table, column]);
30
+ minute(table, column, options) {
31
+ return this.knex.raw(`EXTRACT(MINUTE FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
26
32
  }
27
- second(table, column) {
28
- return this.knex.raw('EXTRACT(SECOND FROM ??.??)', [table, column]);
33
+ second(table, column, options) {
34
+ return this.knex.raw(`EXTRACT(SECOND FROM ??.??${parseLocaltime(options === null || options === void 0 ? void 0 : options.type)})`, [table, column]);
29
35
  }
30
36
  count(table, column, options) {
31
37
  var _a, _b, _c, _d, _e;
@@ -1,7 +1,7 @@
1
1
  import { Query, SchemaOverview } from '@directus/shared/types';
2
2
  import { Knex } from 'knex';
3
3
  import { DatabaseHelper } from '../types';
4
- export declare type FnHelperOptions = {
4
+ export type FnHelperOptions = {
5
5
  type?: string;
6
6
  query?: Query;
7
7
  };
@@ -10,4 +10,4 @@ export declare function getHelpers(database: Knex): {
10
10
  schema: schemaHelpers.sqlite | schemaHelpers.postgres | schemaHelpers.cockroachdb | schemaHelpers.oracle;
11
11
  };
12
12
  export declare function getFunctions(database: Knex, schema: SchemaOverview): fnHelpers.sqlite | fnHelpers.postgres | fnHelpers.mysql | fnHelpers.oracle | fnHelpers.mssql;
13
- export declare type Helpers = ReturnType<typeof getHelpers>;
13
+ export type Helpers = ReturnType<typeof getHelpers>;
@@ -2,4 +2,5 @@ import { KNEX_TYPES } from '@directus/shared/constants';
2
2
  import { Options, SchemaHelper } from '../types';
3
3
  export declare class SchemaHelperCockroachDb extends SchemaHelper {
4
4
  changeToType(table: string, column: string, type: typeof KNEX_TYPES[number], options?: Options): Promise<void>;
5
+ constraintName(existingName: string): string;
5
6
  }
@@ -6,5 +6,16 @@ class SchemaHelperCockroachDb extends types_1.SchemaHelper {
6
6
  async changeToType(table, column, type, options = {}) {
7
7
  await this.changeToTypeByCopy(table, column, type, options);
8
8
  }
9
+ constraintName(existingName) {
10
+ const suffix = '_replaced';
11
+ // CockroachDB does not allow for dropping/creating constraints with the same
12
+ // name in a single transaction. reference issue #14873
13
+ if (existingName.endsWith(suffix)) {
14
+ return existingName.substring(0, existingName.length - suffix.length);
15
+ }
16
+ else {
17
+ return existingName + suffix;
18
+ }
19
+ }
9
20
  }
10
21
  exports.SchemaHelperCockroachDb = SchemaHelperCockroachDb;
@@ -1,7 +1,7 @@
1
1
  import { DatabaseHelper } from '../types';
2
2
  import { KNEX_TYPES } from '@directus/shared/constants';
3
- declare type Clients = 'mysql' | 'postgres' | 'cockroachdb' | 'sqlite' | 'oracle' | 'mssql' | 'redshift';
4
- export declare type Options = {
3
+ type Clients = 'mysql' | 'postgres' | 'cockroachdb' | 'sqlite' | 'oracle' | 'mssql' | 'redshift';
4
+ export type Options = {
5
5
  nullable?: boolean;
6
6
  default?: any;
7
7
  length?: number;
@@ -13,5 +13,6 @@ export declare abstract class SchemaHelper extends DatabaseHelper {
13
13
  protected changeToTypeByCopy(table: string, column: string, type: typeof KNEX_TYPES[number], options: Options): Promise<void>;
14
14
  preColumnChange(): Promise<boolean>;
15
15
  postColumnChange(): Promise<void>;
16
+ constraintName(existingName: string): string;
16
17
  }
17
18
  export {};
@@ -62,5 +62,10 @@ class SchemaHelper extends types_1.DatabaseHelper {
62
62
  async postColumnChange() {
63
63
  return;
64
64
  }
65
+ constraintName(existingName) {
66
+ // most vendors allow for dropping/creating constraints with the same name
67
+ // reference issue #14873
68
+ return existingName;
69
+ }
65
70
  }
66
71
  exports.SchemaHelper = SchemaHelper;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -42,6 +65,7 @@ async function run(database, direction, log = true) {
42
65
  if (direction === 'latest')
43
66
  await latest();
44
67
  async function up() {
68
+ var _a;
45
69
  const currentVersion = completedMigrations[completedMigrations.length - 1];
46
70
  let nextVersion;
47
71
  if (!currentVersion) {
@@ -55,7 +79,7 @@ async function run(database, direction, log = true) {
55
79
  if (!nextVersion) {
56
80
  throw Error('Nothing to upgrade');
57
81
  }
58
- const { up } = require(nextVersion.file);
82
+ const { up } = await (_a = nextVersion.file, Promise.resolve().then(() => __importStar(require(_a))));
59
83
  if (log) {
60
84
  logger_1.default.info(`Applying ${nextVersion.name}...`);
61
85
  }
@@ -63,6 +87,7 @@ async function run(database, direction, log = true) {
63
87
  await database.insert({ version: nextVersion.version, name: nextVersion.name }).into('directus_migrations');
64
88
  }
65
89
  async function down() {
90
+ var _a;
66
91
  const lastAppliedMigration = (0, lodash_1.orderBy)(completedMigrations, ['timestamp', 'version'], ['desc', 'desc'])[0];
67
92
  if (!lastAppliedMigration) {
68
93
  throw Error('Nothing to downgrade');
@@ -71,7 +96,7 @@ async function run(database, direction, log = true) {
71
96
  if (!migration) {
72
97
  throw new Error("Couldn't find migration");
73
98
  }
74
- const { down } = require(migration.file);
99
+ const { down } = await (_a = migration.file, Promise.resolve().then(() => __importStar(require(_a))));
75
100
  if (log) {
76
101
  logger_1.default.info(`Undoing ${migration.name}...`);
77
102
  }
@@ -79,9 +104,10 @@ async function run(database, direction, log = true) {
79
104
  await database('directus_migrations').delete().where({ version: migration.version });
80
105
  }
81
106
  async function latest() {
107
+ var _a;
82
108
  for (const migration of migrations) {
83
109
  if (migration.completed === false) {
84
- const { up } = require(migration.file);
110
+ const { up } = await (_a = migration.file, Promise.resolve().then(() => __importStar(require(_a))));
85
111
  if (log) {
86
112
  logger_1.default.info(`Applying ${migration.name}...`);
87
113
  }
@@ -1,7 +1,7 @@
1
1
  import { Item, SchemaOverview } from '@directus/shared/types';
2
2
  import { Knex } from 'knex';
3
3
  import { AST, NestedCollectionNode } from '../types/ast';
4
- declare type RunASTOptions = {
4
+ type RunASTOptions = {
5
5
  /**
6
6
  * Query override for the current level
7
7
  */
@@ -209,7 +209,7 @@ function applyParentFilters(schema, nestedCollectionNodes, parentItem) {
209
209
  const foreignField = nestedNode.relatedKey[relatedCollection];
210
210
  const foreignIds = (0, lodash_1.uniq)(keysPerCollection[relatedCollection]);
211
211
  (0, lodash_1.merge)(nestedNode, {
212
- query: { [relatedCollection]: { filter: { [foreignField]: { _in: foreignIds } } } },
212
+ query: { [relatedCollection]: { filter: { [foreignField]: { _in: foreignIds } }, limit: foreignIds.length } },
213
213
  });
214
214
  }
215
215
  }
package/dist/env.d.ts CHANGED
@@ -4,6 +4,10 @@
4
4
  */
5
5
  declare let env: Record<string, any>;
6
6
  export default env;
7
+ /**
8
+ * Small wrapper function that makes it easier to write unit tests against changing environments
9
+ */
10
+ export declare const getEnv: () => Record<string, any>;
7
11
  /**
8
12
  * When changes have been made during runtime, like in the CLI, we can refresh the env object with
9
13
  * the newly created variables
package/dist/env.js CHANGED
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.refreshEnv = void 0;
10
+ exports.refreshEnv = exports.getEnv = void 0;
11
11
  const dotenv_1 = __importDefault(require("dotenv"));
12
12
  const fs_1 = __importDefault(require("fs"));
13
13
  const lodash_1 = require("lodash");
@@ -265,11 +265,16 @@ const typeMap = {
265
265
  let env = {
266
266
  ...defaults,
267
267
  ...process.env,
268
- ...getEnv(),
268
+ ...processConfiguration(),
269
269
  };
270
270
  process.env = env;
271
271
  env = processValues(env);
272
272
  exports.default = env;
273
+ /**
274
+ * Small wrapper function that makes it easier to write unit tests against changing environments
275
+ */
276
+ const getEnv = () => env;
277
+ exports.getEnv = getEnv;
273
278
  /**
274
279
  * When changes have been made during runtime, like in the CLI, we can refresh the env object with
275
280
  * the newly created variables
@@ -278,13 +283,13 @@ function refreshEnv() {
278
283
  env = {
279
284
  ...defaults,
280
285
  ...process.env,
281
- ...getEnv(),
286
+ ...processConfiguration(),
282
287
  };
283
288
  process.env = env;
284
289
  env = processValues(env);
285
290
  }
286
291
  exports.refreshEnv = refreshEnv;
287
- function getEnv() {
292
+ function processConfiguration() {
288
293
  const configPath = path_1.default.resolve(process.env.CONFIG_PATH || defaults.CONFIG_PATH);
289
294
  if (fs_1.default.existsSync(configPath) === false)
290
295
  return {};
@@ -1,8 +1 @@
1
- declare const testEnv: {
2
- NUMBER: string;
3
- NUMBER_CAST_AS_STRING: string;
4
- REGEX: string;
5
- CSV: string;
6
- CSV_CAST_AS_STRING: string;
7
- MULTIPLE: string;
8
- };
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { BaseException } from '@directus/shared/exceptions';
2
- declare type Exceptions = {
2
+ type Exceptions = {
3
3
  collection: string;
4
4
  field: string;
5
5
  };
@@ -1,4 +1,4 @@
1
- export declare type MSSQLError = {
1
+ export type MSSQLError = {
2
2
  message: string;
3
3
  code: 'EREQUEST';
4
4
  number: number;
@@ -8,7 +8,7 @@ export declare type MSSQLError = {
8
8
  procName: string;
9
9
  lineNumber: number;
10
10
  };
11
- export declare type MySQLError = {
11
+ export type MySQLError = {
12
12
  message: string;
13
13
  code: string;
14
14
  errno: number;
@@ -17,7 +17,7 @@ export declare type MySQLError = {
17
17
  index: number;
18
18
  sql: string;
19
19
  };
20
- export declare type PostgresError = {
20
+ export type PostgresError = {
21
21
  message: string;
22
22
  length: number;
23
23
  code: string;
@@ -28,14 +28,14 @@ export declare type PostgresError = {
28
28
  dataType?: string;
29
29
  constraint?: string;
30
30
  };
31
- export declare type OracleError = {
31
+ export type OracleError = {
32
32
  message: string;
33
33
  errorNum: number;
34
34
  offset: number;
35
35
  };
36
- export declare type SQLiteError = {
36
+ export type SQLiteError = {
37
37
  message: string;
38
38
  errno: number;
39
39
  code: string;
40
40
  };
41
- export declare type SQLError = MSSQLError & MySQLError & PostgresError & SQLiteError & OracleError & Error;
41
+ export type SQLError = MSSQLError & MySQLError & PostgresError & SQLiteError & OracleError & Error;