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
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelperSQLite = void 0;
4
+ const types_1 = require("../types");
5
+ class GeometryHelperSQLite extends types_1.GeometryHelper {
6
+ async supported() {
7
+ const res = await this.knex.select('name').from('pragma_function_list').where({ name: 'spatialite_version' });
8
+ return res.length > 0;
9
+ }
10
+ asGeoJSON(table, column) {
11
+ return this.knex.raw('asgeojson(??.??) as ??', [table, column, column]);
12
+ }
13
+ }
14
+ exports.GeometryHelperSQLite = GeometryHelperSQLite;
@@ -0,0 +1,6 @@
1
+ export { GeometryHelperPostgres as postgres } from './dialects/postgres';
2
+ export { GeometryHelperRedshift as redshift } from './dialects/redshift';
3
+ export { GeometryHelperOracle as oracle } from './dialects/oracle';
4
+ export { GeometryHelperSQLite as sqlite } from './dialects/sqlite';
5
+ export { GeometryHelperMySQL as mysql } from './dialects/mysql';
6
+ export { GeometryHelperMSSQL 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.GeometryHelperPostgres; } });
6
+ var redshift_1 = require("./dialects/redshift");
7
+ Object.defineProperty(exports, "redshift", { enumerable: true, get: function () { return redshift_1.GeometryHelperRedshift; } });
8
+ var oracle_1 = require("./dialects/oracle");
9
+ Object.defineProperty(exports, "oracle", { enumerable: true, get: function () { return oracle_1.GeometryHelperOracle; } });
10
+ var sqlite_1 = require("./dialects/sqlite");
11
+ Object.defineProperty(exports, "sqlite", { enumerable: true, get: function () { return sqlite_1.GeometryHelperSQLite; } });
12
+ var mysql_1 = require("./dialects/mysql");
13
+ Object.defineProperty(exports, "mysql", { enumerable: true, get: function () { return mysql_1.GeometryHelperMySQL; } });
14
+ var mssql_1 = require("./dialects/mssql");
15
+ Object.defineProperty(exports, "mssql", { enumerable: true, get: function () { return mssql_1.GeometryHelperMSSQL; } });
@@ -1,16 +1,13 @@
1
+ import { GeoJSONGeometry } from 'wellknown';
1
2
  import { Field, RawField } from '@directus/shared/types';
3
+ import { DatabaseHelper } from '../types';
2
4
  import { Knex } from 'knex';
3
- import { GeoJSONGeometry } from 'wellknown';
4
- export declare function getGeometryHelper(database?: Knex): KnexSpatial;
5
- declare abstract class KnexSpatial {
6
- protected knex: Knex;
7
- constructor(knex: Knex);
5
+ export declare abstract class GeometryHelper extends DatabaseHelper {
8
6
  supported(): boolean | Promise<boolean>;
9
7
  isTrue(expression: Knex.Raw): Knex.Raw<any>;
10
8
  isFalse(expression: Knex.Raw): Knex.Raw<any>;
11
9
  createColumn(table: Knex.CreateTableBuilder, field: RawField | Field): Knex.ColumnBuilder;
12
10
  asText(table: string, column: string): Knex.Raw;
13
- asGeoJSON?(table: string, column: string): Knex.Raw;
14
11
  fromText(text: string): Knex.Raw;
15
12
  fromGeoJSON(geojson: GeoJSONGeometry): Knex.Raw;
16
13
  _intersects(key: string, geojson: GeoJSONGeometry): Knex.Raw;
@@ -21,4 +18,3 @@ declare abstract class KnexSpatial {
21
18
  nintersects_bbox(key: string, geojson: GeoJSONGeometry): Knex.Raw;
22
19
  collect(table: string, column: string): Knex.Raw;
23
20
  }
24
- export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeometryHelper = void 0;
4
+ const wellknown_1 = require("wellknown");
5
+ const types_1 = require("../types");
6
+ class GeometryHelper extends types_1.DatabaseHelper {
7
+ supported() {
8
+ return true;
9
+ }
10
+ isTrue(expression) {
11
+ return expression;
12
+ }
13
+ isFalse(expression) {
14
+ return expression.wrap('NOT ', '');
15
+ }
16
+ createColumn(table, field) {
17
+ var _a;
18
+ const type = (_a = field.type.split('.')[1]) !== null && _a !== void 0 ? _a : 'geometry';
19
+ return table.specificType(field.field, type);
20
+ }
21
+ asText(table, column) {
22
+ return this.knex.raw('st_astext(??.??) as ??', [table, column, column]);
23
+ }
24
+ fromText(text) {
25
+ return this.knex.raw('st_geomfromtext(?, 4326)', text);
26
+ }
27
+ fromGeoJSON(geojson) {
28
+ return this.fromText((0, wellknown_1.stringify)(geojson));
29
+ }
30
+ _intersects(key, geojson) {
31
+ const geometry = this.fromGeoJSON(geojson);
32
+ return this.knex.raw('st_intersects(??, ?)', [key, geometry]);
33
+ }
34
+ intersects(key, geojson) {
35
+ return this.isTrue(this._intersects(key, geojson));
36
+ }
37
+ nintersects(key, geojson) {
38
+ return this.isFalse(this._intersects(key, geojson));
39
+ }
40
+ _intersects_bbox(key, geojson) {
41
+ const geometry = this.fromGeoJSON(geojson);
42
+ return this.knex.raw('st_intersects(??, ?)', [key, geometry]);
43
+ }
44
+ intersects_bbox(key, geojson) {
45
+ return this.isTrue(this._intersects_bbox(key, geojson));
46
+ }
47
+ nintersects_bbox(key, geojson) {
48
+ return this.isFalse(this._intersects_bbox(key, geojson));
49
+ }
50
+ collect(table, column) {
51
+ return this.knex.raw('st_astext(st_collect(??.??))', [table, column]);
52
+ }
53
+ }
54
+ exports.GeometryHelper = GeometryHelper;
@@ -0,0 +1,8 @@
1
+ import { Knex } from 'knex';
2
+ import * as dateHelpers from './date';
3
+ import * as geometryHelpers from './geometry';
4
+ export declare function getHelpers(database: Knex): {
5
+ date: dateHelpers.postgres | dateHelpers.oracle | dateHelpers.sqlite | dateHelpers.mysql | dateHelpers.mssql;
6
+ st: geometryHelpers.postgres | geometryHelpers.redshift | geometryHelpers.oracle | geometryHelpers.sqlite | geometryHelpers.mysql | geometryHelpers.mssql;
7
+ };
8
+ export declare type Helpers = ReturnType<typeof getHelpers>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getHelpers = void 0;
23
+ const __1 = require("..");
24
+ const dateHelpers = __importStar(require("./date"));
25
+ const geometryHelpers = __importStar(require("./geometry"));
26
+ function getHelpers(database) {
27
+ const client = (0, __1.getDatabaseClient)(database);
28
+ return {
29
+ date: new dateHelpers[client](database),
30
+ st: new geometryHelpers[client](database),
31
+ };
32
+ }
33
+ exports.getHelpers = getHelpers;
@@ -0,0 +1,5 @@
1
+ import { Knex } from 'knex';
2
+ export declare abstract class DatabaseHelper {
3
+ protected knex: Knex;
4
+ constructor(knex: Knex);
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseHelper = void 0;
4
+ class DatabaseHelper {
5
+ constructor(knex) {
6
+ this.knex = knex;
7
+ }
8
+ }
9
+ exports.DatabaseHelper = DatabaseHelper;
@@ -15,7 +15,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
15
15
  const path_1 = __importDefault(require("path"));
16
16
  const lodash_1 = require("lodash");
17
17
  const util_1 = require("util");
18
- const geometry_1 = require("./helpers/geometry");
18
+ const helpers_1 = require("./helpers");
19
19
  let database = null;
20
20
  let inspector = null;
21
21
  function getDatabase() {
@@ -197,11 +197,11 @@ exports.validateMigrations = validateMigrations;
197
197
  */
198
198
  async function validateDatabaseExtensions() {
199
199
  const database = getDatabase();
200
- const databaseClient = getDatabaseClient(database);
201
- const geometryHelper = (0, geometry_1.getGeometryHelper)(database);
202
- const geometrySupport = await geometryHelper.supported();
200
+ const client = getDatabaseClient(database);
201
+ const helpers = (0, helpers_1.getHelpers)(database);
202
+ const geometrySupport = await helpers.st.supported();
203
203
  if (!geometrySupport) {
204
- switch (databaseClient) {
204
+ switch (client) {
205
205
  case 'postgres':
206
206
  logger_1.default.warn(`PostGIS isn't installed. Geometry type support will be limited.`);
207
207
  break;
@@ -209,7 +209,7 @@ async function validateDatabaseExtensions() {
209
209
  logger_1.default.warn(`Spatialite isn't installed. Geometry type support will be limited.`);
210
210
  break;
211
211
  default:
212
- logger_1.default.warn(`Geometry type not supported on ${databaseClient}`);
212
+ logger_1.default.warn(`Geometry type not supported on ${client}`);
213
213
  }
214
214
  }
215
215
  }
@@ -10,14 +10,14 @@ const apply_query_1 = __importDefault(require("../utils/apply-query"));
10
10
  const get_column_1 = require("../utils/get-column");
11
11
  const strip_function_1 = require("../utils/strip-function");
12
12
  const utils_1 = require("@directus/shared/utils");
13
- const index_1 = __importDefault(require("./index"));
14
- const geometry_1 = require("../database/helpers/geometry");
13
+ const _1 = __importDefault(require("."));
14
+ const helpers_1 = require("../database/helpers");
15
15
  /**
16
16
  * Execute a given AST using Knex. Returns array of items based on requested AST.
17
17
  */
18
18
  async function runAST(originalAST, schema, options) {
19
19
  const ast = (0, lodash_1.cloneDeep)(originalAST);
20
- const knex = (options === null || options === void 0 ? void 0 : options.knex) || (0, index_1.default)();
20
+ const knex = (options === null || options === void 0 ? void 0 : options.knex) || (0, _1.default)();
21
21
  if (ast.type === 'm2a') {
22
22
  const results = {};
23
23
  for (const collection of ast.names) {
@@ -111,7 +111,7 @@ async function parseCurrentLevel(schema, collection, children, query) {
111
111
  return { fieldNodes, nestedCollectionNodes, primaryKeyField };
112
112
  }
113
113
  function getColumnPreprocessor(knex, schema, table) {
114
- const helper = (0, geometry_1.getGeometryHelper)();
114
+ const helpers = (0, helpers_1.getHelpers)(knex);
115
115
  return function (fieldNode) {
116
116
  let field;
117
117
  if (fieldNode.type === 'field') {
@@ -125,7 +125,7 @@ function getColumnPreprocessor(knex, schema, table) {
125
125
  alias = fieldNode.fieldKey;
126
126
  }
127
127
  if (field.type.startsWith('geometry')) {
128
- return helper.asText(table, field.field);
128
+ return helpers.st.asText(table, field.field);
129
129
  }
130
130
  return (0, get_column_1.getColumn)(knex, table, fieldNode.name, alias);
131
131
  };
@@ -7,8 +7,9 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
7
7
  const js_yaml_1 = __importDefault(require("js-yaml"));
8
8
  const lodash_1 = require("lodash");
9
9
  const path_1 = __importDefault(require("path"));
10
- const geometry_1 = require("../helpers/geometry");
10
+ const helpers_1 = require("../helpers");
11
11
  async function runSeed(database) {
12
+ const helpers = (0, helpers_1.getHelpers)(database);
12
13
  const exists = await database.schema.hasTable('directus_collections');
13
14
  if (exists) {
14
15
  throw new Error('Database is already installed');
@@ -38,8 +39,7 @@ async function runSeed(database) {
38
39
  column = tableBuilder.string(columnName, 255);
39
40
  }
40
41
  else if ((_a = columnInfo.type) === null || _a === void 0 ? void 0 : _a.startsWith('geometry')) {
41
- const helper = (0, geometry_1.getGeometryHelper)();
42
- column = helper.createColumn(tableBuilder, { field: columnName, type: columnInfo.type });
42
+ column = helpers.st.createColumn(tableBuilder, { field: columnName, type: columnInfo.type });
43
43
  }
44
44
  else {
45
45
  // @ts-ignore
@@ -4,6 +4,7 @@ fields:
4
4
  - field: id
5
5
  - field: timestamp
6
6
  special: date-created
7
+ - field: status
7
8
  - field: recipient
8
9
  - field: sender
9
10
  - field: subject
package/dist/env.js CHANGED
@@ -50,6 +50,7 @@ const defaults = {
50
50
  CACHE_SCHEMA: true,
51
51
  CACHE_PERMISSIONS: true,
52
52
  AUTH_PROVIDERS: '',
53
+ AUTH_DISABLE_DEFAULT: false,
53
54
  EXTENSIONS_PATH: './extensions',
54
55
  EMAIL_FROM: 'no-reply@directus.io',
55
56
  EMAIL_TRANSPORT: 'sendmail',
@@ -31,6 +31,7 @@ const database_1 = __importDefault(require("./database"));
31
31
  const emitter_1 = __importDefault(require("./emitter"));
32
32
  const env_1 = __importDefault(require("./env"));
33
33
  const exceptions = __importStar(require("./exceptions"));
34
+ const sharedExceptions = __importStar(require("@directus/shared/exceptions"));
34
35
  const logger_1 = __importDefault(require("./logger"));
35
36
  const fs_extra_1 = __importDefault(require("fs-extra"));
36
37
  const get_schema_1 = require("./utils/get-schema");
@@ -231,7 +232,14 @@ class ExtensionManager {
231
232
  }
232
233
  },
233
234
  };
234
- register(registerFunctions, { services, exceptions, env: env_1.default, database: (0, database_1.default)(), logger: logger_1.default, getSchema: get_schema_1.getSchema });
235
+ register(registerFunctions, {
236
+ services,
237
+ exceptions: { ...exceptions, ...sharedExceptions },
238
+ env: env_1.default,
239
+ database: (0, database_1.default)(),
240
+ logger: logger_1.default,
241
+ getSchema: get_schema_1.getSchema,
242
+ });
235
243
  }
236
244
  registerEndpoint(endpoint, router) {
237
245
  const endpointPath = path_1.default.resolve(endpoint.path, endpoint.entrypoint || '');
@@ -241,7 +249,14 @@ class ExtensionManager {
241
249
  const routeName = typeof mod === 'function' ? endpoint.name : mod.id;
242
250
  const scopedRouter = express_1.default.Router();
243
251
  router.use(`/${routeName}`, scopedRouter);
244
- register(scopedRouter, { services, exceptions, env: env_1.default, database: (0, database_1.default)(), logger: logger_1.default, getSchema: get_schema_1.getSchema });
252
+ register(scopedRouter, {
253
+ services,
254
+ exceptions: { ...exceptions, ...sharedExceptions },
255
+ env: env_1.default,
256
+ database: (0, database_1.default)(),
257
+ logger: logger_1.default,
258
+ getSchema: get_schema_1.getSchema,
259
+ });
245
260
  this.apiEndpoints.push({
246
261
  path: endpointPath,
247
262
  });
@@ -6,7 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const sanitize_query_1 = require("../utils/sanitize-query");
8
8
  const validate_query_1 = require("../utils/validate-query");
9
- const sanitizeQueryMiddleware = (req, res, next) => {
9
+ const sanitizeQueryMiddleware = (req, _res, next) => {
10
10
  req.sanitizedQuery = {};
11
11
  if (!req.query)
12
12
  return;
@@ -15,6 +15,7 @@ const logger_1 = __importDefault(require("../logger"));
15
15
  const user_name_1 = require("../utils/user-name");
16
16
  const lodash_1 = require("lodash");
17
17
  const env_1 = __importDefault(require("../env"));
18
+ const uuid_validate_1 = __importDefault(require("uuid-validate"));
18
19
  class ActivityService extends index_1.ItemsService {
19
20
  constructor(options) {
20
21
  super('directus_activity', options);
@@ -55,9 +56,13 @@ class ActivityService extends index_1.ItemsService {
55
56
  }, {});
56
57
  let comment = data.comment;
57
58
  for (const mention of mentions) {
58
- comment = comment.replace(mention, (_h = userPreviews[mention.substring(1)]) !== null && _h !== void 0 ? _h : '@Unknown User');
59
+ const uuid = mention.substring(1);
60
+ // We only match on UUIDs in the first place. This is just an extra sanity check
61
+ if ((0, uuid_validate_1.default)(uuid) === false)
62
+ continue;
63
+ comment = comment.replace(new RegExp(mention, 'gm'), (_h = userPreviews[uuid]) !== null && _h !== void 0 ? _h : '@Unknown User');
59
64
  }
60
- comment = `> ${comment}`;
65
+ comment = `> ${comment.replace(/\n+/gm, '\n> ')}`;
61
66
  const message = `
62
67
  Hello ${(0, user_name_1.userName)(user)},
63
68
 
@@ -34,6 +34,7 @@ const exceptions_1 = require("../exceptions");
34
34
  const storage_1 = __importDefault(require("../storage"));
35
35
  const authorization_1 = require("./authorization");
36
36
  const TransformationUtils = __importStar(require("../utils/transformations"));
37
+ const uuid_validate_1 = __importDefault(require("uuid-validate"));
37
38
  sharp_1.default.concurrency(1);
38
39
  // Note: don't put this in the service. The service can be initialized in multiple places, but they
39
40
  // should all share the same semaphore instance.
@@ -54,7 +55,20 @@ class AssetsService {
54
55
  if (systemPublicKeys.includes(id) === false && ((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true) {
55
56
  await this.authorizationService.checkAccess('read', 'directus_files', id);
56
57
  }
58
+ /**
59
+ * This is a little annoying. Postgres will error out if you're trying to search in `where`
60
+ * with a wrong type. In case of directus_files where id is a uuid, we'll have to verify the
61
+ * validity of the uuid ahead of time.
62
+ */
63
+ const isValidUUID = (0, uuid_validate_1.default)(id, 4);
64
+ if (isValidUUID === false)
65
+ throw new exceptions_1.ForbiddenException();
57
66
  const file = (await this.knex.select('*').from('directus_files').where({ id }).first());
67
+ if (!file)
68
+ throw new exceptions_1.ForbiddenException();
69
+ const { exists } = await storage_1.default.disk(file.storage).exists(file.filename_disk);
70
+ if (!exists)
71
+ throw new exceptions_1.ForbiddenException();
58
72
  if (range) {
59
73
  if (range.start >= file.filesize || (range.end && range.end >= file.filesize)) {
60
74
  throw new exceptions_1.RangeNotSatisfiableException(range);
@@ -6,9 +6,11 @@ import { PayloadService } from '../services/payload';
6
6
  import { AbstractServiceOptions, SchemaOverview } from '../types';
7
7
  import { Accountability } from '@directus/shared/types';
8
8
  import { Field, RawField, Type } from '@directus/shared/types';
9
+ import { Helpers } from '../database/helpers';
9
10
  import Keyv from 'keyv';
10
11
  export declare class FieldsService {
11
12
  knex: Knex;
13
+ helpers: Helpers;
12
14
  accountability: Accountability | null;
13
15
  itemsService: ItemsService;
14
16
  payloadService: PayloadService;
@@ -39,10 +39,11 @@ const get_local_type_1 = __importDefault(require("../utils/get-local-type"));
39
39
  const utils_1 = require("@directus/shared/utils");
40
40
  const lodash_1 = require("lodash");
41
41
  const relations_1 = require("./relations");
42
- const geometry_1 = require("../database/helpers/geometry");
42
+ const helpers_1 = require("../database/helpers");
43
43
  class FieldsService {
44
44
  constructor(options) {
45
45
  this.knex = options.knex || (0, database_1.default)();
46
+ this.helpers = (0, helpers_1.getHelpers)(this.knex);
46
47
  this.schemaInspector = options.knex ? (0, schema_1.default)(options.knex) : (0, database_1.getSchemaInspector)();
47
48
  this.accountability = options.accountability || null;
48
49
  this.itemsService = new items_1.ItemsService('directus_fields', options);
@@ -211,23 +212,39 @@ class FieldsService {
211
212
  accountability: this.accountability,
212
213
  schema: this.schema,
213
214
  });
214
- if (field.type && constants_1.ALIAS_TYPES.includes(field.type) === false) {
215
+ const hookAdjustedField = await emitter_1.default.emitFilter(`fields.create`, field, {
216
+ collection: collection,
217
+ }, {
218
+ database: trx,
219
+ schema: this.schema,
220
+ accountability: this.accountability,
221
+ });
222
+ if (hookAdjustedField.type && constants_1.ALIAS_TYPES.includes(hookAdjustedField.type) === false) {
215
223
  if (table) {
216
- this.addColumnToTable(table, field);
224
+ this.addColumnToTable(table, hookAdjustedField);
217
225
  }
218
226
  else {
219
227
  await trx.schema.alterTable(collection, (table) => {
220
- this.addColumnToTable(table, field);
228
+ this.addColumnToTable(table, hookAdjustedField);
221
229
  });
222
230
  }
223
231
  }
224
- if (field.meta) {
232
+ if (hookAdjustedField.meta) {
225
233
  await itemsService.createOne({
226
- ...field.meta,
234
+ ...hookAdjustedField.meta,
227
235
  collection: collection,
228
- field: field.field,
229
- });
236
+ field: hookAdjustedField.field,
237
+ }, { emitEvents: false });
230
238
  }
239
+ emitter_1.default.emitAction(`fields.create`, {
240
+ payload: hookAdjustedField,
241
+ key: hookAdjustedField.field,
242
+ collection: collection,
243
+ }, {
244
+ database: (0, database_1.default)(),
245
+ schema: this.schema,
246
+ accountability: this.accountability,
247
+ });
231
248
  });
232
249
  if (this.cache && env_1.default.CACHE_AUTO_PURGE) {
233
250
  await this.cache.clear();
@@ -238,12 +255,23 @@ class FieldsService {
238
255
  if (this.accountability && this.accountability.admin !== true) {
239
256
  throw new exceptions_1.ForbiddenException();
240
257
  }
241
- if (field.schema) {
242
- const existingColumn = await this.schemaInspector.columnInfo(collection, field.field);
243
- if (!(0, lodash_1.isEqual)(existingColumn, field.schema)) {
258
+ const hookAdjustedField = await emitter_1.default.emitFilter(`fields.update`, field, {
259
+ keys: [field.field],
260
+ collection: collection,
261
+ }, {
262
+ database: this.knex,
263
+ schema: this.schema,
264
+ accountability: this.accountability,
265
+ });
266
+ const record = field.meta
267
+ ? await this.knex.select('id').from('directus_fields').where({ collection, field: field.field }).first()
268
+ : null;
269
+ if (hookAdjustedField.schema) {
270
+ const existingColumn = await this.schemaInspector.columnInfo(collection, hookAdjustedField.field);
271
+ if (!(0, lodash_1.isEqual)(existingColumn, hookAdjustedField.schema)) {
244
272
  try {
245
273
  await this.knex.schema.alterTable(collection, (table) => {
246
- if (!field.schema)
274
+ if (!hookAdjustedField.schema)
247
275
  return;
248
276
  this.addColumnToTable(table, field, existingColumn);
249
277
  });
@@ -253,31 +281,35 @@ class FieldsService {
253
281
  }
254
282
  }
255
283
  }
256
- if (field.meta) {
257
- const record = await this.knex
258
- .select('id')
259
- .from('directus_fields')
260
- .where({ collection, field: field.field })
261
- .first();
284
+ if (hookAdjustedField.meta) {
262
285
  if (record) {
263
286
  await this.itemsService.updateOne(record.id, {
264
- ...field.meta,
287
+ ...hookAdjustedField.meta,
265
288
  collection: collection,
266
- field: field.field,
267
- });
289
+ field: hookAdjustedField.field,
290
+ }, { emitEvents: false });
268
291
  }
269
292
  else {
270
293
  await this.itemsService.createOne({
271
- ...field.meta,
294
+ ...hookAdjustedField.meta,
272
295
  collection: collection,
273
- field: field.field,
274
- });
296
+ field: hookAdjustedField.field,
297
+ }, { emitEvents: false });
275
298
  }
276
299
  }
277
300
  if (this.cache && env_1.default.CACHE_AUTO_PURGE) {
278
301
  await this.cache.clear();
279
302
  }
280
303
  await this.systemCache.clear();
304
+ emitter_1.default.emitAction(`fields.update`, {
305
+ payload: hookAdjustedField,
306
+ keys: [hookAdjustedField.field],
307
+ collection: collection,
308
+ }, {
309
+ database: (0, database_1.default)(),
310
+ schema: this.schema,
311
+ accountability: this.accountability,
312
+ });
281
313
  return field.field;
282
314
  }
283
315
  async deleteField(collection, field) {
@@ -402,8 +434,7 @@ class FieldsService {
402
434
  column = table.timestamp(field.field, { useTz: true });
403
435
  }
404
436
  else if (field.type.startsWith('geometry')) {
405
- const helper = (0, geometry_1.getGeometryHelper)();
406
- column = helper.createColumn(table, field);
437
+ column = this.helpers.st.createColumn(table, field);
407
438
  }
408
439
  else {
409
440
  // @ts-ignore
@@ -9,7 +9,7 @@ export declare class FilesService extends ItemsService {
9
9
  uploadOne(stream: NodeJS.ReadableStream, data: Partial<File> & {
10
10
  filename_download: string;
11
11
  storage: string;
12
- }, primaryKey?: PrimaryKey): Promise<PrimaryKey>;
12
+ }, primaryKey?: PrimaryKey, opts?: MutationOptions): Promise<PrimaryKey>;
13
13
  /**
14
14
  * Import a single file from an external URL
15
15
  */
@@ -26,7 +26,7 @@ class FilesService extends items_1.ItemsService {
26
26
  /**
27
27
  * Upload a single new file to the configured storage adapter
28
28
  */
29
- async uploadOne(stream, data, primaryKey) {
29
+ async uploadOne(stream, data, primaryKey, opts) {
30
30
  var _a, _b, _c, _d, _e, _f;
31
31
  const payload = (0, lodash_1.clone)(data);
32
32
  if ('folder' in payload === false) {
@@ -109,15 +109,17 @@ class FilesService extends items_1.ItemsService {
109
109
  if (this.cache && env_1.default.CACHE_AUTO_PURGE) {
110
110
  await this.cache.clear();
111
111
  }
112
- emitter_1.default.emitAction('files.upload', {
113
- payload,
114
- key: primaryKey,
115
- collection: this.collection,
116
- }, {
117
- database: this.knex,
118
- schema: this.schema,
119
- accountability: this.accountability,
120
- });
112
+ if ((opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false) {
113
+ emitter_1.default.emitAction('files.upload', {
114
+ payload,
115
+ key: primaryKey,
116
+ collection: this.collection,
117
+ }, {
118
+ database: this.knex,
119
+ schema: this.schema,
120
+ accountability: this.accountability,
121
+ });
122
+ }
121
123
  return primaryKey;
122
124
  }
123
125
  /**
@@ -126,7 +128,7 @@ class FilesService extends items_1.ItemsService {
126
128
  async importOne(importURL, body) {
127
129
  var _a, _b, _c;
128
130
  const fileCreatePermissions = (_b = (_a = this.accountability) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.find((permission) => permission.collection === 'directus_files' && permission.action === 'create');
129
- if (((_c = this.accountability) === null || _c === void 0 ? void 0 : _c.admin) !== true && !fileCreatePermissions) {
131
+ if (this.accountability && ((_c = this.accountability) === null || _c === void 0 ? void 0 : _c.admin) !== true && !fileCreatePermissions) {
130
132
  throw new exceptions_1.ForbiddenException();
131
133
  }
132
134
  let fileResponse;
@@ -726,6 +726,9 @@ class GraphQLService {
726
726
  args: {
727
727
  groupBy: new graphql_1.GraphQLList(graphql_1.GraphQLString),
728
728
  filter: ReadableCollectionFilterTypes[collection.collection],
729
+ limit: {
730
+ type: graphql_1.GraphQLInt,
731
+ },
729
732
  search: {
730
733
  type: graphql_1.GraphQLString,
731
734
  },