directus 9.7.1 → 9.8.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 (59) hide show
  1. package/dist/cache.js +2 -2
  2. package/dist/database/helpers/date/dialects/default.d.ts +3 -0
  3. package/dist/database/helpers/date/dialects/default.js +7 -0
  4. package/dist/database/helpers/date/dialects/sqlite.d.ts +0 -9
  5. package/dist/database/helpers/date/dialects/sqlite.js +0 -24
  6. package/dist/database/helpers/date/index.d.ts +6 -6
  7. package/dist/database/helpers/date/index.js +13 -13
  8. package/dist/database/helpers/date/types.d.ts +0 -9
  9. package/dist/database/helpers/{date → fn}/dialects/mssql.d.ts +3 -2
  10. package/dist/database/helpers/{date → fn}/dialects/mssql.js +14 -3
  11. package/dist/database/helpers/{date → fn}/dialects/mysql.d.ts +3 -2
  12. package/dist/database/helpers/{date → fn}/dialects/mysql.js +14 -3
  13. package/dist/database/helpers/{date → fn}/dialects/oracle.d.ts +3 -2
  14. package/dist/database/helpers/{date → fn}/dialects/oracle.js +14 -3
  15. package/dist/database/helpers/{date → fn}/dialects/postgres.d.ts +3 -2
  16. package/dist/database/helpers/{date → fn}/dialects/postgres.js +14 -3
  17. package/dist/database/helpers/fn/dialects/sqlite.d.ts +13 -0
  18. package/dist/database/helpers/fn/dialects/sqlite.js +42 -0
  19. package/dist/database/helpers/fn/index.d.ts +7 -0
  20. package/dist/database/helpers/fn/index.js +17 -0
  21. package/dist/database/helpers/fn/types.d.ts +18 -0
  22. package/dist/database/helpers/fn/types.js +27 -0
  23. package/dist/database/helpers/index.d.ts +4 -1
  24. package/dist/database/helpers/index.js +7 -1
  25. package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +3 -0
  26. package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.js +17 -0
  27. package/dist/database/migrations/20220322A-rename-field-typecast-flags.js +6 -2
  28. package/dist/database/migrations/20220323A-add-field-validation.d.ts +3 -0
  29. package/dist/database/migrations/20220323A-add-field-validation.js +17 -0
  30. package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +3 -0
  31. package/dist/database/migrations/20220325A-fix-typecast-flags.js +49 -0
  32. package/dist/database/migrations/20220325B-add-default-language.d.ts +3 -0
  33. package/dist/database/migrations/20220325B-add-default-language.js +28 -0
  34. package/dist/database/run-ast.js +4 -2
  35. package/dist/database/system-data/fields/activity.yaml +4 -4
  36. package/dist/database/system-data/fields/fields.yaml +9 -0
  37. package/dist/database/system-data/fields/presets.yaml +14 -0
  38. package/dist/database/system-data/fields/settings.yaml +13 -1
  39. package/dist/logger.js +2 -1
  40. package/dist/services/activity.js +4 -1
  41. package/dist/services/authorization.d.ts +1 -1
  42. package/dist/services/authorization.js +128 -44
  43. package/dist/services/collections.js +222 -198
  44. package/dist/services/fields.js +184 -173
  45. package/dist/services/payload.js +8 -6
  46. package/dist/services/relations.js +93 -81
  47. package/dist/services/server.js +1 -0
  48. package/dist/services/shares.js +2 -1
  49. package/dist/services/users.js +3 -1
  50. package/dist/utils/apply-query.js +21 -3
  51. package/dist/utils/get-column.d.ts +6 -5
  52. package/dist/utils/get-column.js +16 -8
  53. package/dist/utils/get-schema.d.ts +1 -1
  54. package/dist/utils/get-schema.js +15 -10
  55. package/dist/utils/track.js +3 -2
  56. package/dist/utils/url.d.ts +1 -1
  57. package/dist/utils/url.js +1 -1
  58. package/dist/utils/validate-storage.js +3 -1
  59. package/package.json +12 -12
package/dist/cache.js CHANGED
@@ -16,11 +16,11 @@ let lockCache = null;
16
16
  function getCache() {
17
17
  if (env_1.default.CACHE_ENABLED === true && cache === null) {
18
18
  (0, validate_env_1.validateEnv)(['CACHE_NAMESPACE', 'CACHE_TTL', 'CACHE_STORE']);
19
- cache = getKeyvInstance((0, ms_1.default)(env_1.default.CACHE_TTL));
19
+ cache = getKeyvInstance(env_1.default.CACHE_TTL ? (0, ms_1.default)(env_1.default.CACHE_TTL) : undefined);
20
20
  cache.on('error', (err) => logger_1.default.warn(err, `[cache] ${err}`));
21
21
  }
22
22
  if (systemCache === null) {
23
- systemCache = getKeyvInstance(undefined, '_system');
23
+ systemCache = getKeyvInstance(env_1.default.CACHE_SYSTEM_TTL ? (0, ms_1.default)(env_1.default.CACHE_SYSTEM_TTL) : undefined, '_system');
24
24
  systemCache.on('error', (err) => logger_1.default.warn(err, `[cache] ${err}`));
25
25
  }
26
26
  if (lockCache === null) {
@@ -0,0 +1,3 @@
1
+ import { DateHelper } from '../types';
2
+ export declare class DateHelperDefault extends DateHelper {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateHelperDefault = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelperDefault extends types_1.DateHelper {
6
+ }
7
+ exports.DateHelperDefault = DateHelperDefault;
@@ -1,13 +1,4 @@
1
1
  import { DateHelper } from '../types';
2
- import { Knex } from 'knex';
3
2
  export declare class DateHelperSQLite extends DateHelper {
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;
12
3
  parse(date: string): string;
13
4
  }
@@ -3,30 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DateHelperSQLite = void 0;
4
4
  const types_1 = require("../types");
5
5
  class DateHelperSQLite extends types_1.DateHelper {
6
- year(table, column) {
7
- return this.knex.raw("strftime('%Y', ??.?? / 1000, 'unixepoch')", [table, column]);
8
- }
9
- month(table, column) {
10
- return this.knex.raw("strftime('%m', ??.?? / 1000, 'unixepoch')", [table, column]);
11
- }
12
- week(table, column) {
13
- return this.knex.raw("strftime('%W', ??.?? / 1000, 'unixepoch')", [table, column]);
14
- }
15
- day(table, column) {
16
- return this.knex.raw("strftime('%d', ??.?? / 1000, 'unixepoch')", [table, column]);
17
- }
18
- weekday(table, column) {
19
- return this.knex.raw("strftime('%w', ??.?? / 1000, 'unixepoch')", [table, column]);
20
- }
21
- hour(table, column) {
22
- return this.knex.raw("strftime('%H', ??.?? / 1000, 'unixepoch')", [table, column]);
23
- }
24
- minute(table, column) {
25
- return this.knex.raw("strftime('%M', ??.?? / 1000, 'unixepoch')", [table, column]);
26
- }
27
- second(table, column) {
28
- return this.knex.raw("strftime('%S', ??.?? / 1000, 'unixepoch')", [table, column]);
29
- }
30
6
  parse(date) {
31
7
  const newDate = new Date(date);
32
8
  return (newDate.getTime() - newDate.getTimezoneOffset() * 60 * 1000).toString();
@@ -1,7 +1,7 @@
1
- export { DateHelperPostgres as postgres } from './dialects/postgres';
2
- export { DateHelperPostgres as redshift } from './dialects/postgres';
3
- export { DateHelperPostgres as cockroachdb } from './dialects/postgres';
4
- export { DateHelperOracle as oracle } from './dialects/oracle';
1
+ export { DateHelperDefault as postgres } from './dialects/default';
2
+ export { DateHelperDefault as redshift } from './dialects/default';
3
+ export { DateHelperDefault as cockroachdb } from './dialects/default';
4
+ export { DateHelperDefault as oracle } from './dialects/default';
5
+ export { DateHelperDefault as mysql } from './dialects/default';
6
+ export { DateHelperDefault as mssql } from './dialects/default';
5
7
  export { DateHelperSQLite as sqlite } from './dialects/sqlite';
6
- export { DateHelperMySQL as mysql } from './dialects/mysql';
7
- export { DateHelperMSSQL as mssql } from './dialects/mssql';
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mssql = exports.mysql = exports.sqlite = exports.oracle = exports.cockroachdb = exports.redshift = exports.postgres = void 0;
4
- var postgres_1 = require("./dialects/postgres");
5
- Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return postgres_1.DateHelperPostgres; } });
6
- var postgres_2 = require("./dialects/postgres");
7
- Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return postgres_2.DateHelperPostgres; } });
8
- var postgres_3 = require("./dialects/postgres");
9
- Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return postgres_3.DateHelperPostgres; } });
10
- var oracle_1 = require("./dialects/oracle");
11
- Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return oracle_1.DateHelperOracle; } });
3
+ exports.sqlite = exports.mssql = exports.mysql = exports.oracle = exports.cockroachdb = exports.redshift = exports.postgres = void 0;
4
+ var default_1 = require("./dialects/default");
5
+ Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return default_1.DateHelperDefault; } });
6
+ var default_2 = require("./dialects/default");
7
+ Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return default_2.DateHelperDefault; } });
8
+ var default_3 = require("./dialects/default");
9
+ Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return default_3.DateHelperDefault; } });
10
+ var default_4 = require("./dialects/default");
11
+ Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return default_4.DateHelperDefault; } });
12
+ var default_5 = require("./dialects/default");
13
+ Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return default_5.DateHelperDefault; } });
14
+ var default_6 = require("./dialects/default");
15
+ Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return default_6.DateHelperDefault; } });
12
16
  var sqlite_1 = require("./dialects/sqlite");
13
17
  Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.DateHelperSQLite; } });
14
- var mysql_1 = require("./dialects/mysql");
15
- Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.DateHelperMySQL; } });
16
- var mssql_1 = require("./dialects/mssql");
17
- Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.DateHelperMSSQL; } });
@@ -1,13 +1,4 @@
1
1
  import { DatabaseHelper } from '../types';
2
- import { Knex } from 'knex';
3
2
  export declare abstract class DateHelper extends DatabaseHelper {
4
- abstract year(table: string, column: string): Knex.Raw;
5
- abstract month(table: string, column: string): Knex.Raw;
6
- abstract week(table: string, column: string): Knex.Raw;
7
- abstract day(table: string, column: string): Knex.Raw;
8
- abstract weekday(table: string, column: string): Knex.Raw;
9
- abstract hour(table: string, column: string): Knex.Raw;
10
- abstract minute(table: string, column: string): Knex.Raw;
11
- abstract second(table: string, column: string): Knex.Raw;
12
3
  parse(date: string): string;
13
4
  }
@@ -1,6 +1,6 @@
1
- import { DateHelper } from '../types';
1
+ import { FnHelper } from '../types';
2
2
  import { Knex } from 'knex';
3
- export declare class DateHelperMSSQL extends DateHelper {
3
+ export declare class FnHelperMSSQL extends FnHelper {
4
4
  year(table: string, column: string): Knex.Raw;
5
5
  month(table: string, column: string): Knex.Raw;
6
6
  week(table: string, column: string): Knex.Raw;
@@ -9,4 +9,5 @@ export declare class DateHelperMSSQL extends DateHelper {
9
9
  hour(table: string, column: string): Knex.Raw;
10
10
  minute(table: string, column: string): Knex.Raw;
11
11
  second(table: string, column: string): Knex.Raw;
12
+ count(table: string, column: string): Knex.Raw<any>;
12
13
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateHelperMSSQL = void 0;
3
+ exports.FnHelperMSSQL = void 0;
4
4
  const types_1 = require("../types");
5
- class DateHelperMSSQL extends types_1.DateHelper {
5
+ class FnHelperMSSQL extends types_1.FnHelper {
6
6
  year(table, column) {
7
7
  return this.knex.raw('DATEPART(year, ??.??)', [table, column]);
8
8
  }
@@ -27,5 +27,16 @@ class DateHelperMSSQL extends types_1.DateHelper {
27
27
  second(table, column) {
28
28
  return this.knex.raw('DATEPART(second, ??.??)', [table, column]);
29
29
  }
30
+ count(table, column) {
31
+ var _a, _b, _c, _d, _e;
32
+ const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
33
+ if (type === 'json') {
34
+ return this.knex.raw(`(SELECT COUNT(*) FROM OPENJSON(??.??, '$'))`, [table, column]);
35
+ }
36
+ if (type === 'alias') {
37
+ return this._relationalCount(table, column);
38
+ }
39
+ throw new Error(`Couldn't extract type from ${table}.${column}`);
40
+ }
30
41
  }
31
- exports.DateHelperMSSQL = DateHelperMSSQL;
42
+ exports.FnHelperMSSQL = FnHelperMSSQL;
@@ -1,6 +1,6 @@
1
- import { DateHelper } from '../types';
1
+ import { FnHelper } from '../types';
2
2
  import { Knex } from 'knex';
3
- export declare class DateHelperMySQL extends DateHelper {
3
+ export declare class FnHelperMySQL extends FnHelper {
4
4
  year(table: string, column: string): Knex.Raw;
5
5
  month(table: string, column: string): Knex.Raw;
6
6
  week(table: string, column: string): Knex.Raw;
@@ -9,4 +9,5 @@ export declare class DateHelperMySQL extends DateHelper {
9
9
  hour(table: string, column: string): Knex.Raw;
10
10
  minute(table: string, column: string): Knex.Raw;
11
11
  second(table: string, column: string): Knex.Raw;
12
+ count(table: string, column: string): Knex.Raw;
12
13
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateHelperMySQL = void 0;
3
+ exports.FnHelperMySQL = void 0;
4
4
  const types_1 = require("../types");
5
- class DateHelperMySQL extends types_1.DateHelper {
5
+ class FnHelperMySQL extends types_1.FnHelper {
6
6
  year(table, column) {
7
7
  return this.knex.raw('YEAR(??.??)', [table, column]);
8
8
  }
@@ -27,5 +27,16 @@ class DateHelperMySQL extends types_1.DateHelper {
27
27
  second(table, column) {
28
28
  return this.knex.raw('SECOND(??.??)', [table, column]);
29
29
  }
30
+ count(table, column) {
31
+ var _a, _b, _c, _d, _e;
32
+ const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
33
+ if (type === 'json') {
34
+ return this.knex.raw('JSON_LENGTH(??.??)', [table, column]);
35
+ }
36
+ if (type === 'alias') {
37
+ return this._relationalCount(table, column);
38
+ }
39
+ throw new Error(`Couldn't extract type from ${table}.${column}`);
40
+ }
30
41
  }
31
- exports.DateHelperMySQL = DateHelperMySQL;
42
+ exports.FnHelperMySQL = FnHelperMySQL;
@@ -1,6 +1,6 @@
1
- import { DateHelper } from '../types';
1
+ import { FnHelper } from '../types';
2
2
  import { Knex } from 'knex';
3
- export declare class DateHelperOracle extends DateHelper {
3
+ export declare class FnHelperOracle extends FnHelper {
4
4
  year(table: string, column: string): Knex.Raw;
5
5
  month(table: string, column: string): Knex.Raw;
6
6
  week(table: string, column: string): Knex.Raw;
@@ -9,4 +9,5 @@ export declare class DateHelperOracle extends DateHelper {
9
9
  hour(table: string, column: string): Knex.Raw;
10
10
  minute(table: string, column: string): Knex.Raw;
11
11
  second(table: string, column: string): Knex.Raw;
12
+ count(table: string, column: string): Knex.Raw<any>;
12
13
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateHelperOracle = void 0;
3
+ exports.FnHelperOracle = void 0;
4
4
  const types_1 = require("../types");
5
- class DateHelperOracle extends types_1.DateHelper {
5
+ class FnHelperOracle extends types_1.FnHelper {
6
6
  year(table, column) {
7
7
  return this.knex.raw("TO_CHAR(??.??, 'IYYY')", [table, column]);
8
8
  }
@@ -27,5 +27,16 @@ class DateHelperOracle extends types_1.DateHelper {
27
27
  second(table, column) {
28
28
  return this.knex.raw("TO_CHAR(??.??, 'SS')", [table, column]);
29
29
  }
30
+ count(table, column) {
31
+ var _a, _b, _c, _d, _e;
32
+ const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
33
+ if (type === 'json') {
34
+ return this.knex.raw("json_value(??.??, '$.size()')", [table, column]);
35
+ }
36
+ if (type === 'alias') {
37
+ return this._relationalCount(table, column);
38
+ }
39
+ throw new Error(`Couldn't extract type from ${table}.${column}`);
40
+ }
30
41
  }
31
- exports.DateHelperOracle = DateHelperOracle;
42
+ exports.FnHelperOracle = FnHelperOracle;
@@ -1,6 +1,6 @@
1
- import { DateHelper } from '../types';
1
+ import { FnHelper } from '../types';
2
2
  import { Knex } from 'knex';
3
- export declare class DateHelperPostgres extends DateHelper {
3
+ export declare class FnHelperPostgres extends FnHelper {
4
4
  year(table: string, column: string): Knex.Raw;
5
5
  month(table: string, column: string): Knex.Raw;
6
6
  week(table: string, column: string): Knex.Raw;
@@ -9,4 +9,5 @@ export declare class DateHelperPostgres extends DateHelper {
9
9
  hour(table: string, column: string): Knex.Raw;
10
10
  minute(table: string, column: string): Knex.Raw;
11
11
  second(table: string, column: string): Knex.Raw;
12
+ count(table: string, column: string): Knex.Raw;
12
13
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateHelperPostgres = void 0;
3
+ exports.FnHelperPostgres = void 0;
4
4
  const types_1 = require("../types");
5
- class DateHelperPostgres extends types_1.DateHelper {
5
+ class FnHelperPostgres extends types_1.FnHelper {
6
6
  year(table, column) {
7
7
  return this.knex.raw('EXTRACT(YEAR FROM ??.??)', [table, column]);
8
8
  }
@@ -27,5 +27,16 @@ class DateHelperPostgres extends types_1.DateHelper {
27
27
  second(table, column) {
28
28
  return this.knex.raw('EXTRACT(SECOND FROM ??.??)', [table, column]);
29
29
  }
30
+ count(table, column) {
31
+ var _a, _b, _c, _d, _e;
32
+ const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
33
+ if (type === 'json') {
34
+ return this.knex.raw('json_array_length(??.??)', [table, column]);
35
+ }
36
+ if (type === 'alias') {
37
+ return this._relationalCount(table, column);
38
+ }
39
+ throw new Error(`Couldn't extract type from ${table}.${column}`);
40
+ }
30
41
  }
31
- exports.DateHelperPostgres = DateHelperPostgres;
42
+ exports.FnHelperPostgres = FnHelperPostgres;
@@ -0,0 +1,13 @@
1
+ import { FnHelper } from '../types';
2
+ import { Knex } from 'knex';
3
+ export declare class FnHelperSQLite 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;
12
+ count(table: string, column: string): Knex.Raw<any>;
13
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FnHelperSQLite = void 0;
4
+ const types_1 = require("../types");
5
+ class FnHelperSQLite extends types_1.FnHelper {
6
+ year(table, column) {
7
+ return this.knex.raw("CAST(strftime('%Y', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
8
+ }
9
+ month(table, column) {
10
+ return this.knex.raw("CAST(strftime('%m', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
11
+ }
12
+ week(table, column) {
13
+ return this.knex.raw("CAST(strftime('%W', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
14
+ }
15
+ day(table, column) {
16
+ return this.knex.raw("CAST(strftime('%d', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
17
+ }
18
+ weekday(table, column) {
19
+ return this.knex.raw("CAST(strftime('%w', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
20
+ }
21
+ hour(table, column) {
22
+ return this.knex.raw("CAST(strftime('%H', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
23
+ }
24
+ minute(table, column) {
25
+ return this.knex.raw("CAST(strftime('%M', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
26
+ }
27
+ second(table, column) {
28
+ return this.knex.raw("CAST(strftime('%S', ??.?? / 1000, 'unixepoch') AS INTEGER)", [table, column]);
29
+ }
30
+ count(table, column) {
31
+ var _a, _b, _c, _d, _e;
32
+ const type = (_e = (_d = (_c = (_b = (_a = this.schema.collections) === null || _a === void 0 ? void 0 : _a[table]) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c[column]) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : 'unknown';
33
+ if (type === 'json') {
34
+ return this.knex.raw(`json_array_length(??.??, '$')`, [table, column]);
35
+ }
36
+ if (type === 'alias') {
37
+ return this._relationalCount(table, column);
38
+ }
39
+ throw new Error(`Couldn't extract type from ${table}.${column}`);
40
+ }
41
+ }
42
+ exports.FnHelperSQLite = FnHelperSQLite;
@@ -0,0 +1,7 @@
1
+ export { FnHelperPostgres as postgres } from './dialects/postgres';
2
+ export { FnHelperPostgres as redshift } from './dialects/postgres';
3
+ export { FnHelperPostgres as cockroachdb } from './dialects/postgres';
4
+ export { FnHelperOracle as oracle } from './dialects/oracle';
5
+ export { FnHelperSQLite as sqlite } from './dialects/sqlite';
6
+ export { FnHelperMySQL as mysql } from './dialects/mysql';
7
+ export { FnHelperMSSQL as mssql } from './dialects/mssql';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mssql = exports.mysql = exports.sqlite = exports.oracle = exports.cockroachdb = exports.redshift = exports.postgres = void 0;
4
+ var postgres_1 = require("./dialects/postgres");
5
+ Object.defineProperty(exports, "postgres", { enumerable: true, get: function () { return postgres_1.FnHelperPostgres; } });
6
+ var postgres_2 = require("./dialects/postgres");
7
+ Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return postgres_2.FnHelperPostgres; } });
8
+ var postgres_3 = require("./dialects/postgres");
9
+ Object.defineProperty(exports, "cockroachdb", { enumerable: true, get: function () { return postgres_3.FnHelperPostgres; } });
10
+ var oracle_1 = require("./dialects/oracle");
11
+ Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return oracle_1.FnHelperOracle; } });
12
+ var sqlite_1 = require("./dialects/sqlite");
13
+ Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.FnHelperSQLite; } });
14
+ var mysql_1 = require("./dialects/mysql");
15
+ Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.FnHelperMySQL; } });
16
+ var mssql_1 = require("./dialects/mssql");
17
+ Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.FnHelperMSSQL; } });
@@ -0,0 +1,18 @@
1
+ import { SchemaOverview } from '@directus/shared/types';
2
+ import { Knex } from 'knex';
3
+ import { DatabaseHelper } from '../types';
4
+ export declare abstract class FnHelper extends DatabaseHelper {
5
+ protected knex: Knex;
6
+ protected schema: SchemaOverview;
7
+ constructor(knex: Knex, schema: SchemaOverview);
8
+ abstract year(table: string, column: string): Knex.Raw;
9
+ abstract month(table: string, column: string): Knex.Raw;
10
+ abstract week(table: string, column: string): Knex.Raw;
11
+ abstract day(table: string, column: string): Knex.Raw;
12
+ abstract weekday(table: string, column: string): Knex.Raw;
13
+ abstract hour(table: string, column: string): Knex.Raw;
14
+ abstract minute(table: string, column: string): Knex.Raw;
15
+ abstract second(table: string, column: string): Knex.Raw;
16
+ abstract count(table: string, column: string): Knex.Raw;
17
+ protected _relationalCount(table: string, column: string): Knex.Raw;
18
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FnHelper = void 0;
4
+ const types_1 = require("../types");
5
+ class FnHelper extends types_1.DatabaseHelper {
6
+ constructor(knex, schema) {
7
+ super(knex);
8
+ this.knex = knex;
9
+ this.schema = schema;
10
+ this.schema = schema;
11
+ }
12
+ _relationalCount(table, column) {
13
+ const relation = this.schema.relations.find((relation) => { var _a; return relation.related_collection === table && ((_a = relation === null || relation === void 0 ? void 0 : relation.meta) === null || _a === void 0 ? void 0 : _a.one_field) === column; });
14
+ const currentPrimary = this.schema.collections[table].primary;
15
+ if (!relation) {
16
+ throw new Error(`Field ${table}.${column} isn't a nested relational collection`);
17
+ }
18
+ return this.knex.raw('(' +
19
+ this.knex
20
+ .count('*')
21
+ .from(relation.collection)
22
+ .where(relation.field, '=', this.knex.raw(`??.??`, [table, currentPrimary]))
23
+ .toQuery() +
24
+ ')');
25
+ }
26
+ }
27
+ exports.FnHelper = FnHelper;
@@ -1,10 +1,13 @@
1
+ import { SchemaOverview } from '@directus/shared/types';
1
2
  import { Knex } from 'knex';
2
3
  import * as dateHelpers from './date';
4
+ import * as fnHelpers from './fn';
3
5
  import * as geometryHelpers from './geometry';
4
6
  import * as schemaHelpers from './schema';
5
7
  export declare function getHelpers(database: Knex): {
6
- date: dateHelpers.postgres | dateHelpers.oracle | dateHelpers.sqlite | dateHelpers.mysql | dateHelpers.mssql;
8
+ date: dateHelpers.postgres | dateHelpers.sqlite;
7
9
  st: geometryHelpers.postgres | geometryHelpers.redshift | geometryHelpers.oracle | geometryHelpers.sqlite | geometryHelpers.mysql | geometryHelpers.mssql;
8
10
  schema: schemaHelpers.postgres | schemaHelpers.cockroachdb | schemaHelpers.oracle;
9
11
  };
12
+ export declare function getFunctions(database: Knex, schema: SchemaOverview): fnHelpers.postgres | fnHelpers.oracle | fnHelpers.sqlite | fnHelpers.mysql | fnHelpers.mssql;
10
13
  export declare type Helpers = ReturnType<typeof getHelpers>;
@@ -19,9 +19,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getHelpers = void 0;
22
+ exports.getFunctions = exports.getHelpers = void 0;
23
23
  const __1 = require("..");
24
24
  const dateHelpers = __importStar(require("./date"));
25
+ const fnHelpers = __importStar(require("./fn"));
25
26
  const geometryHelpers = __importStar(require("./geometry"));
26
27
  const schemaHelpers = __importStar(require("./schema"));
27
28
  function getHelpers(database) {
@@ -33,3 +34,8 @@ function getHelpers(database) {
33
34
  };
34
35
  }
35
36
  exports.getHelpers = getHelpers;
37
+ function getFunctions(database, schema) {
38
+ const client = (0, __1.getDatabaseClient)(database);
39
+ return new fnHelpers[client](database, schema);
40
+ }
41
+ exports.getFunctions = getFunctions;
@@ -0,0 +1,3 @@
1
+ import { Knex } from 'knex';
2
+ export declare function up(knex: Knex): Promise<void>;
3
+ export declare function down(knex: Knex): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ async function up(knex) {
5
+ await knex.schema.alterTable('directus_presets', (table) => {
6
+ table.string('icon', 30).notNullable().defaultTo('bookmark_outline');
7
+ table.string('color').nullable();
8
+ });
9
+ }
10
+ exports.up = up;
11
+ async function down(knex) {
12
+ await knex.schema.alterTable('directus_presets', (table) => {
13
+ table.dropColumn('icon');
14
+ table.dropColumn('color');
15
+ });
16
+ }
17
+ exports.down = down;
@@ -31,7 +31,9 @@ async function up(knex) {
31
31
  }
32
32
  });
33
33
  if (updateRequired) {
34
- await knex('directus_fields').update({ special: parsedSpecial }).where({ id });
34
+ await knex('directus_fields')
35
+ .update({ special: parsedSpecial.join(',') })
36
+ .where({ id });
35
37
  }
36
38
  }
37
39
  }
@@ -65,7 +67,9 @@ async function down(knex) {
65
67
  }
66
68
  });
67
69
  if (updateRequired) {
68
- await knex('directus_fields').update({ special: parsedSpecial }).where({ id });
70
+ await knex('directus_fields')
71
+ .update({ special: parsedSpecial.join(',') })
72
+ .where({ id });
69
73
  }
70
74
  }
71
75
  }
@@ -0,0 +1,3 @@
1
+ import { Knex } from 'knex';
2
+ export declare function up(knex: Knex): Promise<void>;
3
+ export declare function down(knex: Knex): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ async function up(knex) {
5
+ await knex.schema.alterTable('directus_fields', (table) => {
6
+ table.json('validation');
7
+ table.text('validation_message');
8
+ });
9
+ }
10
+ exports.up = up;
11
+ async function down(knex) {
12
+ await knex.schema.alterTable('directus_fields', (table) => {
13
+ table.dropColumn('validation');
14
+ table.dropColumn('validation_message');
15
+ });
16
+ }
17
+ exports.down = down;
@@ -0,0 +1,3 @@
1
+ import { Knex } from 'knex';
2
+ export declare function up(knex: Knex): Promise<void>;
3
+ export declare function down(_knex: Knex): Promise<void>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const utils_1 = require("@directus/shared/utils");
5
+ const lodash_1 = require("lodash");
6
+ async function up(knex) {
7
+ const fields = await knex
8
+ .select('id', 'special')
9
+ .from('directus_fields')
10
+ .whereNotNull('special')
11
+ .orWhere('special', '<>', '');
12
+ for (const { id, special } of fields) {
13
+ let parsedSpecial;
14
+ try {
15
+ if (special.includes('{')) {
16
+ // Fix invalid data in Postgres
17
+ parsedSpecial = (0, utils_1.toArray)(special.replace(/{/g, '').replace(/}/g, '').replace(/"/g, ''));
18
+ }
19
+ else {
20
+ parsedSpecial = (0, utils_1.toArray)(special);
21
+ }
22
+ }
23
+ catch {
24
+ continue;
25
+ }
26
+ if (parsedSpecial && (0, lodash_1.isArray)(parsedSpecial)) {
27
+ // Perform the update again in case it was not performed prior
28
+ parsedSpecial = parsedSpecial.map((special) => {
29
+ switch (special) {
30
+ case 'boolean':
31
+ case 'csv':
32
+ case 'json':
33
+ return 'cast-' + special;
34
+ default:
35
+ return special;
36
+ }
37
+ });
38
+ const parsedSpecialString = parsedSpecial.join(',');
39
+ if (parsedSpecialString !== special) {
40
+ await knex('directus_fields').update({ special: parsedSpecialString }).where({ id });
41
+ }
42
+ }
43
+ }
44
+ }
45
+ exports.up = up;
46
+ async function down(_knex) {
47
+ // Do nothing
48
+ }
49
+ exports.down = down;
@@ -0,0 +1,3 @@
1
+ import { Knex } from 'knex';
2
+ export declare function up(knex: Knex): Promise<void>;
3
+ export declare function down(knex: Knex): Promise<void>;