directus 9.1.2 → 9.2.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 (78) hide show
  1. package/dist/auth.js +5 -3
  2. package/dist/cli/commands/database/install.js +2 -4
  3. package/dist/cli/commands/schema/apply.js +26 -10
  4. package/dist/controllers/assets.js +0 -27
  5. package/dist/controllers/auth.js +7 -2
  6. package/dist/controllers/extensions.js +1 -1
  7. package/dist/database/{functions/types.d.ts → helpers/date/dialects/mssql.d.ts} +2 -1
  8. package/dist/database/{functions → helpers/date}/dialects/mssql.js +4 -6
  9. package/dist/database/{functions → helpers/date}/dialects/mysql.d.ts +2 -4
  10. package/dist/database/{functions → helpers/date}/dialects/mysql.js +4 -6
  11. package/dist/database/{functions/dialects/mssql.d.ts → helpers/date/dialects/oracle.d.ts} +2 -4
  12. package/dist/database/{functions → helpers/date}/dialects/oracle.js +4 -6
  13. package/dist/database/helpers/date/dialects/postgres.d.ts +12 -0
  14. package/dist/database/{functions → helpers/date}/dialects/postgres.js +4 -6
  15. package/dist/database/{functions → helpers/date}/dialects/sqlite.d.ts +3 -4
  16. package/dist/database/helpers/date/dialects/sqlite.js +35 -0
  17. package/dist/database/helpers/date/index.d.ts +6 -0
  18. package/dist/database/helpers/date/index.js +15 -0
  19. package/dist/database/helpers/date/types.d.ts +13 -0
  20. package/dist/database/helpers/date/types.js +10 -0
  21. package/dist/database/helpers/geometry/dialects/mssql.d.ts +14 -0
  22. package/dist/database/helpers/geometry/dialects/mssql.js +36 -0
  23. package/dist/database/helpers/geometry/dialects/mysql.d.ts +7 -0
  24. package/dist/database/helpers/geometry/dialects/mysql.js +16 -0
  25. package/dist/database/helpers/geometry/dialects/oracle.d.ts +15 -0
  26. package/dist/database/helpers/geometry/dialects/oracle.js +39 -0
  27. package/dist/database/helpers/geometry/dialects/postgres.d.ts +10 -0
  28. package/dist/database/helpers/geometry/dialects/postgres.js +23 -0
  29. package/dist/database/helpers/geometry/dialects/redshift.d.ts +7 -0
  30. package/dist/database/helpers/geometry/dialects/redshift.js +16 -0
  31. package/dist/database/helpers/geometry/dialects/sqlite.d.ts +6 -0
  32. package/dist/database/helpers/geometry/dialects/sqlite.js +14 -0
  33. package/dist/database/helpers/geometry/index.d.ts +6 -0
  34. package/dist/database/helpers/geometry/index.js +15 -0
  35. package/dist/database/helpers/{geometry.d.ts → geometry/types.d.ts} +3 -7
  36. package/dist/database/helpers/geometry/types.js +54 -0
  37. package/dist/database/helpers/index.d.ts +8 -0
  38. package/dist/database/helpers/index.js +33 -0
  39. package/dist/database/helpers/types.d.ts +5 -0
  40. package/dist/database/helpers/types.js +9 -0
  41. package/dist/database/index.js +6 -6
  42. package/dist/database/run-ast.js +5 -5
  43. package/dist/database/seeds/run.js +3 -3
  44. package/dist/database/system-data/fields/notifications.yaml +1 -0
  45. package/dist/env.js +1 -0
  46. package/dist/extensions.js +17 -2
  47. package/dist/middleware/sanitize-query.js +1 -1
  48. package/dist/services/activity.js +7 -2
  49. package/dist/services/assets.js +14 -0
  50. package/dist/services/fields.d.ts +2 -0
  51. package/dist/services/fields.js +57 -26
  52. package/dist/services/files.d.ts +1 -1
  53. package/dist/services/files.js +13 -11
  54. package/dist/services/graphql.js +3 -0
  55. package/dist/services/items.js +18 -29
  56. package/dist/services/payload.d.ts +2 -0
  57. package/dist/services/payload.js +3 -3
  58. package/dist/utils/apply-query.js +9 -11
  59. package/dist/utils/apply-snapshot.js +27 -28
  60. package/dist/utils/get-column.js +2 -2
  61. package/dist/utils/get-default-index-name.js +2 -2
  62. package/dist/utils/get-local-type.js +1 -12
  63. package/dist/utils/merge-permissions.js +2 -2
  64. package/dist/utils/sanitize-query.js +1 -12
  65. package/dist/utils/validate-query.js +1 -1
  66. package/dist/webhooks.js +16 -24
  67. package/package.json +13 -13
  68. package/dist/database/functions/dialects/oracle.d.ts +0 -14
  69. package/dist/database/functions/dialects/postgres.d.ts +0 -14
  70. package/dist/database/functions/dialects/sqlite.js +0 -33
  71. package/dist/database/functions/index.d.ts +0 -3
  72. package/dist/database/functions/index.js +0 -26
  73. package/dist/database/functions/types.js +0 -2
  74. package/dist/database/helpers/date.d.ts +0 -8
  75. package/dist/database/helpers/date.js +0 -44
  76. package/dist/database/helpers/geometry.js +0 -189
  77. package/dist/utils/get-simple-hash.d.ts +0 -5
  78. package/dist/utils/get-simple-hash.js +0 -15
package/dist/auth.js CHANGED
@@ -24,9 +24,11 @@ function getAuthProvider(provider) {
24
24
  exports.getAuthProvider = getAuthProvider;
25
25
  async function registerAuthProviders() {
26
26
  const options = { knex: (0, database_1.default)(), schema: await (0, get_schema_1.getSchema)() };
27
- const defaultProvider = getProviderInstance('local', options);
28
- // Register default provider
29
- providers.set(constants_1.DEFAULT_AUTH_PROVIDER, defaultProvider);
27
+ // Register default provider if not disabled
28
+ if (!env_1.default.AUTH_DISABLE_DEFAULT) {
29
+ const defaultProvider = getProviderInstance('local', options);
30
+ providers.set(constants_1.DEFAULT_AUTH_PROVIDER, defaultProvider);
31
+ }
30
32
  if (!env_1.default.AUTH_PROVIDERS) {
31
33
  return;
32
34
  }
@@ -3,15 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const run_1 = __importDefault(require("../../../database/migrations/run"));
7
- const run_2 = __importDefault(require("../../../database/seeds/run"));
6
+ const run_1 = __importDefault(require("../../../database/seeds/run"));
8
7
  const database_1 = __importDefault(require("../../../database"));
9
8
  const logger_1 = __importDefault(require("../../../logger"));
10
9
  async function start() {
11
10
  const database = (0, database_1.default)();
12
11
  try {
13
- await (0, run_2.default)(database);
14
- await (0, run_1.default)(database, 'latest');
12
+ await (0, run_1.default)(database);
15
13
  database.destroy();
16
14
  process.exit(0);
17
15
  }
@@ -35,7 +35,7 @@ const get_snapshot_diff_1 = require("../../../utils/get-snapshot-diff");
35
35
  const apply_snapshot_1 = require("../../../utils/apply-snapshot");
36
36
  const cache_1 = require("../../../cache");
37
37
  async function apply(snapshotPath, options) {
38
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
39
39
  const filename = path_1.default.resolve(process.cwd(), snapshotPath);
40
40
  const database = (0, database_1.default)();
41
41
  await (0, database_1.validateDatabaseConnection)(database);
@@ -83,12 +83,15 @@ async function apply(snapshotPath, options) {
83
83
  else if (((_c = diff[0]) === null || _c === void 0 ? void 0 : _c.kind) === 'N') {
84
84
  message += `\n - ${chalk_1.default.green('Create')} ${collection}`;
85
85
  }
86
+ else if (((_d = diff[0]) === null || _d === void 0 ? void 0 : _d.kind) === 'A') {
87
+ message += `\n - ${chalk_1.default.blue('Update')} ${collection}`;
88
+ }
86
89
  }
87
90
  }
88
91
  if (snapshotDiff.fields.length > 0) {
89
92
  message += '\n\n' + chalk_1.default.black.underline.bold('Fields:');
90
93
  for (const { collection, field, diff } of snapshotDiff.fields) {
91
- if (((_d = diff[0]) === null || _d === void 0 ? void 0 : _d.kind) === 'E') {
94
+ if (((_e = diff[0]) === null || _e === void 0 ? void 0 : _e.kind) === 'E') {
92
95
  message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
93
96
  for (const change of diff) {
94
97
  if (change.kind === 'E') {
@@ -97,19 +100,22 @@ async function apply(snapshotPath, options) {
97
100
  }
98
101
  }
99
102
  }
100
- else if (((_e = diff[0]) === null || _e === void 0 ? void 0 : _e.kind) === 'D') {
103
+ else if (((_f = diff[0]) === null || _f === void 0 ? void 0 : _f.kind) === 'D') {
101
104
  message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field}`;
102
105
  }
103
- else if (((_f = diff[0]) === null || _f === void 0 ? void 0 : _f.kind) === 'N') {
106
+ else if (((_g = diff[0]) === null || _g === void 0 ? void 0 : _g.kind) === 'N') {
104
107
  message += `\n - ${chalk_1.default.green('Create')} ${collection}.${field}`;
105
108
  }
109
+ else if (((_h = diff[0]) === null || _h === void 0 ? void 0 : _h.kind) === 'A') {
110
+ message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
111
+ }
106
112
  }
107
113
  }
108
114
  if (snapshotDiff.relations.length > 0) {
109
115
  message += '\n\n' + chalk_1.default.black.underline.bold('Relations:');
110
116
  for (const { collection, field, related_collection, diff } of snapshotDiff.relations) {
111
- if (((_g = diff[0]) === null || _g === void 0 ? void 0 : _g.kind) === 'E') {
112
- message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field} -> ${related_collection}`;
117
+ if (((_j = diff[0]) === null || _j === void 0 ? void 0 : _j.kind) === 'E') {
118
+ message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
113
119
  for (const change of diff) {
114
120
  if (change.kind === 'E') {
115
121
  const path = change.path.slice(1).join('.');
@@ -117,11 +123,21 @@ async function apply(snapshotPath, options) {
117
123
  }
118
124
  }
119
125
  }
120
- else if (((_h = diff[0]) === null || _h === void 0 ? void 0 : _h.kind) === 'D') {
121
- message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field} -> ${related_collection}`;
126
+ else if (((_k = diff[0]) === null || _k === void 0 ? void 0 : _k.kind) === 'D') {
127
+ message += `\n - ${chalk_1.default.red('Delete')} ${collection}.${field}`;
128
+ }
129
+ else if (((_l = diff[0]) === null || _l === void 0 ? void 0 : _l.kind) === 'N') {
130
+ message += `\n - ${chalk_1.default.green('Create')} ${collection}.${field}`;
131
+ }
132
+ else if (((_m = diff[0]) === null || _m === void 0 ? void 0 : _m.kind) === 'A') {
133
+ message += `\n - ${chalk_1.default.blue('Update')} ${collection}.${field}`;
134
+ }
135
+ else {
136
+ continue;
122
137
  }
123
- else if (((_j = diff[0]) === null || _j === void 0 ? void 0 : _j.kind) === 'N') {
124
- message += `\n - ${chalk_1.default.green('Create')} ${collection}.${field} -> ${related_collection}`;
138
+ // Related collection doesn't exist for m2a relationship types
139
+ if (related_collection) {
140
+ message += `-> ${related_collection}`;
125
141
  }
126
142
  }
127
143
  }
@@ -6,44 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const express_1 = require("express");
7
7
  const lodash_1 = require("lodash");
8
8
  const ms_1 = __importDefault(require("ms"));
9
- const uuid_validate_1 = __importDefault(require("uuid-validate"));
10
9
  const constants_1 = require("../constants");
11
10
  const database_1 = __importDefault(require("../database"));
12
11
  const env_1 = __importDefault(require("../env"));
13
12
  const exceptions_1 = require("../exceptions");
14
13
  const use_collection_1 = __importDefault(require("../middleware/use-collection"));
15
14
  const services_1 = require("../services");
16
- const storage_1 = __importDefault(require("../storage"));
17
15
  const assets_1 = require("../types/assets");
18
16
  const async_handler_1 = __importDefault(require("../utils/async-handler"));
19
17
  const router = (0, express_1.Router)();
20
18
  router.use((0, use_collection_1.default)('directus_files'));
21
19
  router.get('/:pk',
22
- // Check if file exists and if you have permission to read it
23
- (0, async_handler_1.default)(async (req, res, next) => {
24
- var _a;
25
- /**
26
- * We ignore everything in the id after the first 36 characters (uuid length). This allows the
27
- * user to add an optional extension, or other identifier for use in external software (#4067)
28
- */
29
- const id = (_a = req.params.pk) === null || _a === void 0 ? void 0 : _a.substring(0, 36);
30
- /**
31
- * This is a little annoying. Postgres will error out if you're trying to search in `where`
32
- * with a wrong type. In case of directus_files where id is a uuid, we'll have to verify the
33
- * validity of the uuid ahead of time.
34
- */
35
- const isValidUUID = (0, uuid_validate_1.default)(id, 4);
36
- if (isValidUUID === false)
37
- throw new exceptions_1.ForbiddenException();
38
- const database = (0, database_1.default)();
39
- const file = await database.select('id', 'storage', 'filename_disk').from('directus_files').where({ id }).first();
40
- if (!file)
41
- throw new exceptions_1.ForbiddenException();
42
- const { exists } = await storage_1.default.disk(file.storage).exists(file.filename_disk);
43
- if (!exists)
44
- throw new exceptions_1.ForbiddenException();
45
- return next();
46
- }),
47
20
  // Validate query params
48
21
  (0, async_handler_1.default)(async (req, res, next) => {
49
22
  const payloadService = new services_1.PayloadService('directus_settings', { schema: req.schema });
@@ -38,7 +38,9 @@ for (const authProvider of authProviders) {
38
38
  }
39
39
  router.use(`/login/${authProvider.name}`, authRouter);
40
40
  }
41
- router.use('/login', (0, drivers_1.createLocalAuthRouter)(constants_1.DEFAULT_AUTH_PROVIDER));
41
+ if (!env_1.default.AUTH_DISABLE_DEFAULT) {
42
+ router.use('/login', (0, drivers_1.createLocalAuthRouter)(constants_1.DEFAULT_AUTH_PROVIDER));
43
+ }
42
44
  router.post('/refresh', (0, async_handler_1.default)(async (req, res, next) => {
43
45
  var _a;
44
46
  const accountability = {
@@ -141,7 +143,10 @@ router.post('/password/reset', (0, async_handler_1.default)(async (req, res, nex
141
143
  return next();
142
144
  }), respond_1.respond);
143
145
  router.get('/', (0, async_handler_1.default)(async (req, res, next) => {
144
- res.locals.payload = { data: (0, get_auth_providers_1.getAuthProviders)() };
146
+ res.locals.payload = {
147
+ data: (0, get_auth_providers_1.getAuthProviders)(),
148
+ disableDefault: env_1.default.AUTH_DISABLE_DEFAULT,
149
+ };
145
150
  return next();
146
151
  }), respond_1.respond);
147
152
  exports.default = router;
@@ -33,7 +33,7 @@ router.get('/:type/index.js', (0, async_handler_1.default)(async (req, res) => {
33
33
  throw new exceptions_1.RouteNotFoundException(req.path);
34
34
  }
35
35
  res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
36
- res.setHeader('Cache-Control', 'no-cache');
36
+ res.setHeader('Cache-Control', 'no-store');
37
37
  res.setHeader('Vary', 'Origin, Cache-Control');
38
38
  res.end(extensionSource);
39
39
  }));
@@ -1,5 +1,6 @@
1
+ import { DateHelper } from '../types';
1
2
  import { Knex } from 'knex';
2
- export interface HelperFn {
3
+ export declare class DateHelperMSSQL extends DateHelper {
3
4
  year(table: string, column: string): Knex.Raw;
4
5
  month(table: string, column: string): Knex.Raw;
5
6
  week(table: string, column: string): Knex.Raw;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelperMSSQL = void 0;
4
- class HelperMSSQL {
5
- constructor(knex) {
6
- this.knex = knex;
7
- }
3
+ exports.DateHelperMSSQL = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelperMSSQL extends types_1.DateHelper {
8
6
  year(table, column) {
9
7
  return this.knex.raw('DATEPART(year, ??.??)', [table, column]);
10
8
  }
@@ -30,4 +28,4 @@ class HelperMSSQL {
30
28
  return this.knex.raw('DATEPART(second, ??.??)', [table, column]);
31
29
  }
32
30
  }
33
- exports.HelperMSSQL = HelperMSSQL;
31
+ exports.DateHelperMSSQL = DateHelperMSSQL;
@@ -1,8 +1,6 @@
1
+ import { DateHelper } from '../types';
1
2
  import { Knex } from 'knex';
2
- import { HelperFn } from '../types';
3
- export declare class HelperMySQL implements HelperFn {
4
- private knex;
5
- constructor(knex: Knex);
3
+ export declare class DateHelperMySQL extends DateHelper {
6
4
  year(table: string, column: string): Knex.Raw;
7
5
  month(table: string, column: string): Knex.Raw;
8
6
  week(table: string, column: string): Knex.Raw;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelperMySQL = void 0;
4
- class HelperMySQL {
5
- constructor(knex) {
6
- this.knex = knex;
7
- }
3
+ exports.DateHelperMySQL = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelperMySQL extends types_1.DateHelper {
8
6
  year(table, column) {
9
7
  return this.knex.raw('YEAR(??.??)', [table, column]);
10
8
  }
@@ -30,4 +28,4 @@ class HelperMySQL {
30
28
  return this.knex.raw('SECOND(??.??)', [table, column]);
31
29
  }
32
30
  }
33
- exports.HelperMySQL = HelperMySQL;
31
+ exports.DateHelperMySQL = DateHelperMySQL;
@@ -1,8 +1,6 @@
1
+ import { DateHelper } from '../types';
1
2
  import { Knex } from 'knex';
2
- import { HelperFn } from '../types';
3
- export declare class HelperMSSQL implements HelperFn {
4
- private knex;
5
- constructor(knex: Knex);
3
+ export declare class DateHelperOracle extends DateHelper {
6
4
  year(table: string, column: string): Knex.Raw;
7
5
  month(table: string, column: string): Knex.Raw;
8
6
  week(table: string, column: string): Knex.Raw;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelperOracle = void 0;
4
- class HelperOracle {
5
- constructor(knex) {
6
- this.knex = knex;
7
- }
3
+ exports.DateHelperOracle = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelperOracle extends types_1.DateHelper {
8
6
  year(table, column) {
9
7
  return this.knex.raw("TO_CHAR(??.??, 'IYYY')", [table, column]);
10
8
  }
@@ -30,4 +28,4 @@ class HelperOracle {
30
28
  return this.knex.raw("TO_CHAR(??.??, 'SS')", [table, column]);
31
29
  }
32
30
  }
33
- exports.HelperOracle = HelperOracle;
31
+ exports.DateHelperOracle = DateHelperOracle;
@@ -0,0 +1,12 @@
1
+ import { DateHelper } from '../types';
2
+ import { Knex } from 'knex';
3
+ export declare class DateHelperPostgres 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
+ }
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelperPostgres = void 0;
4
- class HelperPostgres {
5
- constructor(knex) {
6
- this.knex = knex;
7
- }
3
+ exports.DateHelperPostgres = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelperPostgres extends types_1.DateHelper {
8
6
  year(table, column) {
9
7
  return this.knex.raw('EXTRACT(YEAR FROM ??.??)', [table, column]);
10
8
  }
@@ -30,4 +28,4 @@ class HelperPostgres {
30
28
  return this.knex.raw('EXTRACT(SECOND FROM ??.??)', [table, column]);
31
29
  }
32
30
  }
33
- exports.HelperPostgres = HelperPostgres;
31
+ exports.DateHelperPostgres = DateHelperPostgres;
@@ -1,8 +1,6 @@
1
+ import { DateHelper } from '../types';
1
2
  import { Knex } from 'knex';
2
- import { HelperFn } from '../types';
3
- export declare class HelperSQLite implements HelperFn {
4
- private knex;
5
- constructor(knex: Knex);
3
+ export declare class DateHelperSQLite extends DateHelper {
6
4
  year(table: string, column: string): Knex.Raw;
7
5
  month(table: string, column: string): Knex.Raw;
8
6
  week(table: string, column: string): Knex.Raw;
@@ -11,4 +9,5 @@ export declare class HelperSQLite implements HelperFn {
11
9
  hour(table: string, column: string): Knex.Raw;
12
10
  minute(table: string, column: string): Knex.Raw;
13
11
  second(table: string, column: string): Knex.Raw;
12
+ parse(date: string): string;
14
13
  }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateHelperSQLite = void 0;
4
+ const types_1 = require("../types");
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
+ parse(date) {
31
+ const newDate = new Date(date);
32
+ return (newDate.getTime() - newDate.getTimezoneOffset() * 60 * 1000).toString();
33
+ }
34
+ }
35
+ exports.DateHelperSQLite = DateHelperSQLite;
@@ -0,0 +1,6 @@
1
+ export { DateHelperPostgres as postgres } from './dialects/postgres';
2
+ export { DateHelperPostgres as redshift } from './dialects/postgres';
3
+ export { DateHelperOracle as oracle } from './dialects/oracle';
4
+ export { DateHelperSQLite as sqlite } from './dialects/sqlite';
5
+ export { DateHelperMySQL as mysql } from './dialects/mysql';
6
+ export { DateHelperMSSQL as mssql } from './dialects/mssql';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mssql = exports.mysql = exports.sqlite = exports.oracle = 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 oracle_1 = require("./dialects/oracle");
9
+ Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return oracle_1.DateHelperOracle; } });
10
+ var sqlite_1 = require("./dialects/sqlite");
11
+ Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.DateHelperSQLite; } });
12
+ var mysql_1 = require("./dialects/mysql");
13
+ Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.DateHelperMySQL; } });
14
+ var mssql_1 = require("./dialects/mssql");
15
+ Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.DateHelperMSSQL; } });
@@ -0,0 +1,13 @@
1
+ import { DatabaseHelper } from '../types';
2
+ import { Knex } from 'knex';
3
+ 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
+ parse(date: string): string;
13
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateHelper = void 0;
4
+ const types_1 = require("../types");
5
+ class DateHelper extends types_1.DatabaseHelper {
6
+ parse(date) {
7
+ return date;
8
+ }
9
+ }
10
+ exports.DateHelper = DateHelper;
@@ -0,0 +1,14 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Field, RawField } from '@directus/shared/types';
3
+ import { GeoJSONGeometry } from 'wellknown';
4
+ import { Knex } from 'knex';
5
+ export declare class GeometryHelperMSSQL extends GeometryHelper {
6
+ isTrue(expression: Knex.Raw): Knex.Raw<any>;
7
+ isFalse(expression: Knex.Raw): Knex.Raw<any>;
8
+ createColumn(table: Knex.CreateTableBuilder, field: RawField | Field): Knex.ColumnBuilder;
9
+ asText(table: string, column: string): Knex.Raw;
10
+ fromText(text: string): Knex.Raw;
11
+ _intersects(key: string, geojson: GeoJSONGeometry): Knex.Raw;
12
+ _intersects_bbox(key: string, geojson: GeoJSONGeometry): Knex.Raw;
13
+ collect(table: string, column: string): Knex.Raw;
14
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperMSSQL = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperMSSQL extends types_1.GeometryHelper {
6
+ isTrue(expression) {
7
+ return expression.wrap(``, ` = 1`);
8
+ }
9
+ isFalse(expression) {
10
+ return expression.wrap(``, ` = 0`);
11
+ }
12
+ createColumn(table, field) {
13
+ if (field.type.split('.')[1]) {
14
+ field.meta.special = [field.type];
15
+ }
16
+ return table.specificType(field.field, 'geometry');
17
+ }
18
+ asText(table, column) {
19
+ return this.knex.raw('??.??.STAsText() as ??', [table, column, column]);
20
+ }
21
+ fromText(text) {
22
+ return this.knex.raw('geometry::STGeomFromText(?, 4326)', text);
23
+ }
24
+ _intersects(key, geojson) {
25
+ const geometry = this.fromGeoJSON(geojson);
26
+ return this.knex.raw('??.STIntersects(?)', [key, geometry]);
27
+ }
28
+ _intersects_bbox(key, geojson) {
29
+ const geometry = this.fromGeoJSON(geojson);
30
+ return this.knex.raw('??.STEnvelope().STIntersects(?.STEnvelope())', [key, geometry]);
31
+ }
32
+ collect(table, column) {
33
+ return this.knex.raw('geometry::CollectionAggregate(??.??).STAsText()', [table, column]);
34
+ }
35
+ }
36
+ exports.GeometryHelperMSSQL = GeometryHelperMSSQL;
@@ -0,0 +1,7 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Knex } from 'knex';
3
+ export declare class GeometryHelperMySQL extends GeometryHelper {
4
+ collect(table: string, column: string): Knex.Raw;
5
+ fromText(text: string): Knex.Raw;
6
+ asGeoJSON(table: string, column: string): Knex.Raw;
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperMySQL = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperMySQL extends types_1.GeometryHelper {
6
+ collect(table, column) {
7
+ return this.knex.raw(`concat('geometrycollection(', group_concat(? separator ', '), ')'`, this.asText(table, column));
8
+ }
9
+ fromText(text) {
10
+ return this.knex.raw('st_geomfromtext(?)', text);
11
+ }
12
+ asGeoJSON(table, column) {
13
+ return this.knex.raw('st_asgeojson(??.??) as ??', [table, column, column]);
14
+ }
15
+ }
16
+ exports.GeometryHelperMySQL = GeometryHelperMySQL;
@@ -0,0 +1,15 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Field, RawField } from '@directus/shared/types';
3
+ import { GeoJSONGeometry } from 'wellknown';
4
+ import { Knex } from 'knex';
5
+ export declare class GeometryHelperOracle extends GeometryHelper {
6
+ isTrue(expression: Knex.Raw): Knex.Raw<any>;
7
+ isFalse(expression: Knex.Raw): Knex.Raw<any>;
8
+ createColumn(table: Knex.CreateTableBuilder, field: RawField | Field): Knex.ColumnBuilder;
9
+ asText(table: string, column: string): Knex.Raw;
10
+ asGeoJSON(table: string, column: string): Knex.Raw;
11
+ fromText(text: string): Knex.Raw;
12
+ _intersects(key: string, geojson: GeoJSONGeometry): Knex.Raw;
13
+ _intersects_bbox(key: string, geojson: GeoJSONGeometry): Knex.Raw;
14
+ collect(table: string, column: string): Knex.Raw;
15
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperOracle = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperOracle extends types_1.GeometryHelper {
6
+ isTrue(expression) {
7
+ return expression.wrap(``, ` = 'TRUE'`);
8
+ }
9
+ isFalse(expression) {
10
+ return expression.wrap(``, ` = 'FALSE'`);
11
+ }
12
+ createColumn(table, field) {
13
+ if (field.type.split('.')[1]) {
14
+ field.meta.special = [field.type];
15
+ }
16
+ return table.specificType(field.field, 'sdo_geometry');
17
+ }
18
+ asText(table, column) {
19
+ return this.knex.raw('sdo_util.to_wktgeometry(??.??) as ??', [table, column, column]);
20
+ }
21
+ asGeoJSON(table, column) {
22
+ return this.knex.raw('sdo_util.to_geojson(??.??) as ??', [table, column, column]);
23
+ }
24
+ fromText(text) {
25
+ return this.knex.raw('sdo_geometry(?, 4326)', text);
26
+ }
27
+ _intersects(key, geojson) {
28
+ const geometry = this.fromGeoJSON(geojson);
29
+ return this.knex.raw(`sdo_overlapbdyintersect(??, ?)`, [key, geometry]);
30
+ }
31
+ _intersects_bbox(key, geojson) {
32
+ const geometry = this.fromGeoJSON(geojson);
33
+ return this.knex.raw(`sdo_overlapbdyintersect(sdo_geom.sdo_mbr(??), sdo_geom.sdo_mbr(?))`, [key, geometry]);
34
+ }
35
+ collect(table, column) {
36
+ return this.knex.raw(`concat('geometrycollection(', listagg(?, ', '), ')'`, this.asText(table, column));
37
+ }
38
+ }
39
+ exports.GeometryHelperOracle = GeometryHelperOracle;
@@ -0,0 +1,10 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Field, RawField } from '@directus/shared/types';
3
+ import { GeoJSONGeometry } from 'wellknown';
4
+ import { Knex } from 'knex';
5
+ export declare class GeometryHelperPostgres extends GeometryHelper {
6
+ supported(): Promise<boolean>;
7
+ createColumn(table: Knex.CreateTableBuilder, field: RawField | Field): Knex.ColumnBuilder;
8
+ _intersects_bbox(key: string, geojson: GeoJSONGeometry): Knex.Raw;
9
+ asGeoJSON(table: string, column: string): Knex.Raw;
10
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperPostgres = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperPostgres extends types_1.GeometryHelper {
6
+ async supported() {
7
+ const res = await this.knex.select('oid').from('pg_proc').where({ proname: 'postgis_version' });
8
+ return res.length > 0;
9
+ }
10
+ createColumn(table, field) {
11
+ var _a;
12
+ const type = (_a = field.type.split('.')[1]) !== null && _a !== void 0 ? _a : 'geometry';
13
+ return table.specificType(field.field, `geometry(${type}, 4326)`);
14
+ }
15
+ _intersects_bbox(key, geojson) {
16
+ const geometry = this.fromGeoJSON(geojson);
17
+ return this.knex.raw('?? && ?', [key, geometry]);
18
+ }
19
+ asGeoJSON(table, column) {
20
+ return this.knex.raw('st_asgeojson(??.??) as ??', [table, column, column]);
21
+ }
22
+ }
23
+ exports.GeometryHelperPostgres = GeometryHelperPostgres;
@@ -0,0 +1,7 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Field, RawField } from '@directus/shared/types';
3
+ import { Knex } from 'knex';
4
+ export declare class GeometryHelperRedshift extends GeometryHelper {
5
+ createColumn(table: Knex.CreateTableBuilder, field: RawField | Field): Knex.ColumnBuilder;
6
+ asGeoJSON(table: string, column: string): Knex.Raw;
7
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperRedshift = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperRedshift extends types_1.GeometryHelper {
6
+ createColumn(table, field) {
7
+ if (field.type.split('.')[1]) {
8
+ field.meta.special = [field.type];
9
+ }
10
+ return table.specificType(field.field, 'geometry');
11
+ }
12
+ asGeoJSON(table, column) {
13
+ return this.knex.raw('st_asgeojson(??.??) as ??', [table, column, column]);
14
+ }
15
+ }
16
+ exports.GeometryHelperRedshift = GeometryHelperRedshift;
@@ -0,0 +1,6 @@
1
+ import { GeometryHelper } from '../types';
2
+ import { Knex } from 'knex';
3
+ export declare class GeometryHelperSQLite extends GeometryHelper {
4
+ supported(): Promise<boolean>;
5
+ asGeoJSON(table: string, column: string): Knex.Raw;
6
+ }