directus 9.6.0 → 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.
- package/dist/app.js +3 -1
- package/dist/auth/drivers/oauth2.js +3 -0
- package/dist/auth/drivers/openid.js +3 -0
- package/dist/cache.d.ts +4 -1
- package/dist/cache.js +29 -7
- package/dist/cli/commands/schema/apply.d.ts +1 -0
- package/dist/cli/commands/schema/apply.js +9 -5
- package/dist/cli/index.js +1 -0
- package/dist/controllers/assets.js +9 -1
- package/dist/controllers/utils.js +18 -1
- package/dist/database/helpers/date/dialects/default.d.ts +3 -0
- package/dist/database/helpers/date/dialects/default.js +7 -0
- package/dist/database/helpers/date/dialects/sqlite.d.ts +0 -9
- package/dist/database/helpers/date/dialects/sqlite.js +0 -24
- package/dist/database/helpers/date/index.d.ts +6 -6
- package/dist/database/helpers/date/index.js +13 -13
- package/dist/database/helpers/date/types.d.ts +0 -9
- package/dist/database/helpers/{date → fn}/dialects/mssql.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/mssql.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/mysql.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/mysql.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/oracle.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/oracle.js +14 -3
- package/dist/database/helpers/{date → fn}/dialects/postgres.d.ts +3 -2
- package/dist/database/helpers/{date → fn}/dialects/postgres.js +14 -3
- package/dist/database/helpers/fn/dialects/sqlite.d.ts +13 -0
- package/dist/database/helpers/fn/dialects/sqlite.js +42 -0
- package/dist/database/helpers/fn/index.d.ts +7 -0
- package/dist/database/helpers/fn/index.js +17 -0
- package/dist/database/helpers/fn/types.d.ts +18 -0
- package/dist/database/helpers/fn/types.js +27 -0
- package/dist/database/helpers/index.d.ts +4 -1
- package/dist/database/helpers/index.js +7 -1
- package/dist/database/index.js +0 -3
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +3 -0
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.js +17 -0
- package/dist/database/migrations/20220314A-add-translation-strings.d.ts +3 -0
- package/dist/database/migrations/20220314A-add-translation-strings.js +15 -0
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +3 -0
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.js +77 -0
- package/dist/database/migrations/20220323A-add-field-validation.d.ts +3 -0
- package/dist/database/migrations/20220323A-add-field-validation.js +17 -0
- package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +3 -0
- package/dist/database/migrations/20220325A-fix-typecast-flags.js +49 -0
- package/dist/database/migrations/20220325B-add-default-language.d.ts +3 -0
- package/dist/database/migrations/20220325B-add-default-language.js +28 -0
- package/dist/database/migrations/run.js +1 -1
- package/dist/database/run-ast.js +11 -3
- package/dist/database/system-data/fields/activity.yaml +4 -4
- package/dist/database/system-data/fields/collections.yaml +4 -4
- package/dist/database/system-data/fields/fields.yaml +17 -8
- package/dist/database/system-data/fields/files.yaml +2 -2
- package/dist/database/system-data/fields/panels.yaml +2 -2
- package/dist/database/system-data/fields/permissions.yaml +4 -4
- package/dist/database/system-data/fields/presets.yaml +17 -3
- package/dist/database/system-data/fields/relations.yaml +1 -1
- package/dist/database/system-data/fields/revisions.yaml +2 -2
- package/dist/database/system-data/fields/roles.yaml +4 -4
- package/dist/database/system-data/fields/settings.yaml +19 -4
- package/dist/database/system-data/fields/users.yaml +2 -2
- package/dist/database/system-data/fields/webhooks.yaml +4 -4
- package/dist/env.js +6 -2
- package/dist/exceptions/database/dialects/mysql.js +23 -17
- package/dist/logger.js +2 -1
- package/dist/middleware/respond.js +7 -28
- package/dist/services/activity.js +4 -1
- package/dist/services/authorization.d.ts +1 -1
- package/dist/services/authorization.js +156 -14
- package/dist/services/collections.js +222 -198
- package/dist/services/fields.js +184 -173
- package/dist/services/files.js +69 -3
- package/dist/services/graphql.js +2 -2
- package/dist/services/import-export.d.ts +34 -0
- package/dist/services/import-export.js +270 -0
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -1
- package/dist/services/items.js +1 -0
- package/dist/services/payload.js +11 -9
- package/dist/services/permissions.js +10 -10
- package/dist/services/relations.js +93 -78
- package/dist/services/server.js +1 -0
- package/dist/services/shares.js +2 -1
- package/dist/services/users.js +3 -1
- package/dist/utils/apply-query.js +21 -3
- package/dist/utils/get-column.d.ts +6 -5
- package/dist/utils/get-column.js +16 -8
- package/dist/utils/get-date-formatted.d.ts +1 -0
- package/dist/utils/get-date-formatted.js +14 -0
- package/dist/utils/get-local-type.js +2 -2
- package/dist/utils/get-permissions.js +1 -1
- package/dist/utils/get-schema.d.ts +1 -1
- package/dist/utils/get-schema.js +16 -11
- package/dist/utils/track.js +3 -2
- package/dist/utils/url.d.ts +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/validate-storage.js +3 -1
- package/package.json +13 -12
- package/dist/services/import.d.ts +0 -13
- package/dist/services/import.js +0 -118
|
@@ -55,105 +55,113 @@ class CollectionsService {
|
|
|
55
55
|
if (payload.collection.startsWith('directus_')) {
|
|
56
56
|
throw new exceptions_1.InvalidPayloadException(`Collections can't start with "directus_"`);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
payload.fields
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
58
|
+
try {
|
|
59
|
+
const existingCollections = [
|
|
60
|
+
...((_b = (_a = (await this.knex.select('collection').from('directus_collections'))) === null || _a === void 0 ? void 0 : _a.map(({ collection }) => collection)) !== null && _b !== void 0 ? _b : []),
|
|
61
|
+
...Object.keys(this.schema.collections),
|
|
62
|
+
];
|
|
63
|
+
if (existingCollections.includes(payload.collection)) {
|
|
64
|
+
throw new exceptions_1.InvalidPayloadException(`Collection "${payload.collection}" already exists.`);
|
|
65
|
+
}
|
|
66
|
+
// Create the collection/fields in a transaction so it'll be reverted in case of errors or
|
|
67
|
+
// permission problems. This might not work reliably in MySQL, as it doesn't support DDL in
|
|
68
|
+
// transactions.
|
|
69
|
+
await this.knex.transaction(async (trx) => {
|
|
70
|
+
if (payload.schema) {
|
|
71
|
+
// Directus heavily relies on the primary key of a collection, so we have to make sure that
|
|
72
|
+
// every collection that is created has a primary key. If no primary key field is created
|
|
73
|
+
// while making the collection, we default to an auto incremented id named `id`
|
|
74
|
+
if (!payload.fields)
|
|
75
|
+
payload.fields = [
|
|
76
|
+
{
|
|
77
|
+
field: 'id',
|
|
78
|
+
type: 'integer',
|
|
79
|
+
meta: {
|
|
80
|
+
hidden: true,
|
|
81
|
+
interface: 'numeric',
|
|
82
|
+
readonly: true,
|
|
83
|
+
},
|
|
84
|
+
schema: {
|
|
85
|
+
is_primary_key: true,
|
|
86
|
+
has_auto_increment: true,
|
|
87
|
+
},
|
|
86
88
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return field;
|
|
99
|
-
});
|
|
100
|
-
const fieldsService = new fields_1.FieldsService({ knex: trx, schema: this.schema });
|
|
101
|
-
await trx.schema.createTable(payload.collection, (table) => {
|
|
102
|
-
for (const field of payload.fields) {
|
|
103
|
-
if (field.type && constants_1.ALIAS_TYPES.includes(field.type) === false) {
|
|
104
|
-
fieldsService.addColumnToTable(table, field);
|
|
89
|
+
];
|
|
90
|
+
// Ensure that every field meta has the field/collection fields filled correctly
|
|
91
|
+
payload.fields = payload.fields.map((field) => {
|
|
92
|
+
if (field.meta) {
|
|
93
|
+
field.meta = {
|
|
94
|
+
...field.meta,
|
|
95
|
+
field: field.field,
|
|
96
|
+
collection: payload.collection,
|
|
97
|
+
};
|
|
105
98
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
99
|
+
return field;
|
|
100
|
+
});
|
|
101
|
+
const fieldsService = new fields_1.FieldsService({ knex: trx, schema: this.schema });
|
|
102
|
+
await trx.schema.createTable(payload.collection, (table) => {
|
|
103
|
+
for (const field of payload.fields) {
|
|
104
|
+
if (field.type && constants_1.ALIAS_TYPES.includes(field.type) === false) {
|
|
105
|
+
fieldsService.addColumnToTable(table, field);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
const fieldItemsService = new items_1.ItemsService('directus_fields', {
|
|
110
|
+
knex: trx,
|
|
111
|
+
accountability: this.accountability,
|
|
112
|
+
schema: this.schema,
|
|
113
|
+
});
|
|
114
|
+
const fieldPayloads = payload.fields.filter((field) => field.meta).map((field) => field.meta);
|
|
115
|
+
await fieldItemsService.createMany(fieldPayloads);
|
|
116
|
+
}
|
|
117
|
+
if (payload.meta) {
|
|
118
|
+
const collectionItemsService = new items_1.ItemsService('directus_collections', {
|
|
119
|
+
knex: trx,
|
|
120
|
+
accountability: this.accountability,
|
|
121
|
+
schema: this.schema,
|
|
122
|
+
});
|
|
123
|
+
await collectionItemsService.createOne({
|
|
124
|
+
...payload.meta,
|
|
125
|
+
collection: payload.collection,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return payload.collection;
|
|
129
|
+
});
|
|
127
130
|
return payload.collection;
|
|
128
|
-
});
|
|
129
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
130
|
-
await this.cache.clear();
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
finally {
|
|
133
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
134
|
+
await this.cache.clear();
|
|
135
|
+
}
|
|
136
|
+
await (0, cache_1.clearSystemCache)();
|
|
137
|
+
}
|
|
134
138
|
}
|
|
135
139
|
/**
|
|
136
140
|
* Create multiple new collections
|
|
137
141
|
*/
|
|
138
142
|
async createMany(payloads, opts) {
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
try {
|
|
144
|
+
const collections = await this.knex.transaction(async (trx) => {
|
|
145
|
+
const service = new CollectionsService({
|
|
146
|
+
schema: this.schema,
|
|
147
|
+
accountability: this.accountability,
|
|
148
|
+
knex: trx,
|
|
149
|
+
});
|
|
150
|
+
const collectionNames = [];
|
|
151
|
+
for (const payload of payloads) {
|
|
152
|
+
const name = await service.createOne(payload, { autoPurgeCache: false });
|
|
153
|
+
collectionNames.push(name);
|
|
154
|
+
}
|
|
155
|
+
return collectionNames;
|
|
144
156
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
return collections;
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
161
|
+
await this.cache.clear();
|
|
149
162
|
}
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
153
|
-
await this.cache.clear();
|
|
163
|
+
await (0, cache_1.clearSystemCache)();
|
|
154
164
|
}
|
|
155
|
-
await this.systemCache.clear();
|
|
156
|
-
return collections;
|
|
157
165
|
}
|
|
158
166
|
/**
|
|
159
167
|
* Read all collections. Currently doesn't support any query.
|
|
@@ -252,31 +260,35 @@ class CollectionsService {
|
|
|
252
260
|
if (this.accountability && this.accountability.admin !== true) {
|
|
253
261
|
throw new exceptions_1.ForbiddenException();
|
|
254
262
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
try {
|
|
264
|
+
const collectionItemsService = new items_1.ItemsService('directus_collections', {
|
|
265
|
+
knex: this.knex,
|
|
266
|
+
accountability: this.accountability,
|
|
267
|
+
schema: this.schema,
|
|
268
|
+
});
|
|
269
|
+
const payload = data;
|
|
270
|
+
if (!payload.meta) {
|
|
271
|
+
return collectionKey;
|
|
272
|
+
}
|
|
273
|
+
const exists = !!(await this.knex
|
|
274
|
+
.select('collection')
|
|
275
|
+
.from('directus_collections')
|
|
276
|
+
.where({ collection: collectionKey })
|
|
277
|
+
.first());
|
|
278
|
+
if (exists) {
|
|
279
|
+
await collectionItemsService.updateOne(collectionKey, payload.meta, opts);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
await collectionItemsService.createOne({ ...payload.meta, collection: collectionKey }, opts);
|
|
283
|
+
}
|
|
262
284
|
return collectionKey;
|
|
263
285
|
}
|
|
264
|
-
|
|
265
|
-
.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
.
|
|
269
|
-
if (exists) {
|
|
270
|
-
await collectionItemsService.updateOne(collectionKey, payload.meta, opts);
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
await collectionItemsService.createOne({ ...payload.meta, collection: collectionKey }, opts);
|
|
274
|
-
}
|
|
275
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
276
|
-
await this.cache.clear();
|
|
286
|
+
finally {
|
|
287
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
288
|
+
await this.cache.clear();
|
|
289
|
+
}
|
|
290
|
+
await (0, cache_1.clearSystemCache)();
|
|
277
291
|
}
|
|
278
|
-
await this.systemCache.clear();
|
|
279
|
-
return collectionKey;
|
|
280
292
|
}
|
|
281
293
|
/**
|
|
282
294
|
* Update multiple collections by name
|
|
@@ -285,21 +297,25 @@ class CollectionsService {
|
|
|
285
297
|
if (this.accountability && this.accountability.admin !== true) {
|
|
286
298
|
throw new exceptions_1.ForbiddenException();
|
|
287
299
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
try {
|
|
301
|
+
await this.knex.transaction(async (trx) => {
|
|
302
|
+
const service = new CollectionsService({
|
|
303
|
+
schema: this.schema,
|
|
304
|
+
accountability: this.accountability,
|
|
305
|
+
knex: trx,
|
|
306
|
+
});
|
|
307
|
+
for (const collectionKey of collectionKeys) {
|
|
308
|
+
await service.updateOne(collectionKey, data, { autoPurgeCache: false });
|
|
309
|
+
}
|
|
293
310
|
});
|
|
294
|
-
|
|
295
|
-
|
|
311
|
+
return collectionKeys;
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
315
|
+
await this.cache.clear();
|
|
296
316
|
}
|
|
297
|
-
|
|
298
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
299
|
-
await this.cache.clear();
|
|
317
|
+
await (0, cache_1.clearSystemCache)();
|
|
300
318
|
}
|
|
301
|
-
await this.systemCache.clear();
|
|
302
|
-
return collectionKeys;
|
|
303
319
|
}
|
|
304
320
|
/**
|
|
305
321
|
* Delete a single collection This will delete the table and all records within. It'll also
|
|
@@ -309,78 +325,82 @@ class CollectionsService {
|
|
|
309
325
|
if (this.accountability && this.accountability.admin !== true) {
|
|
310
326
|
throw new exceptions_1.ForbiddenException();
|
|
311
327
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
await this.knex.transaction(async (trx) => {
|
|
318
|
-
var _a;
|
|
319
|
-
if (collectionToBeDeleted.schema) {
|
|
320
|
-
await trx.schema.dropTable(collectionKey);
|
|
328
|
+
try {
|
|
329
|
+
const collections = await this.readByQuery();
|
|
330
|
+
const collectionToBeDeleted = collections.find((collection) => collection.collection === collectionKey);
|
|
331
|
+
if (!!collectionToBeDeleted === false) {
|
|
332
|
+
throw new exceptions_1.ForbiddenException();
|
|
321
333
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
knex: trx,
|
|
327
|
-
accountability: this.accountability,
|
|
328
|
-
schema: this.schema,
|
|
329
|
-
});
|
|
330
|
-
await collectionItemsService.deleteOne(collectionKey);
|
|
331
|
-
}
|
|
332
|
-
if (collectionToBeDeleted.schema) {
|
|
333
|
-
const fieldsService = new fields_1.FieldsService({
|
|
334
|
-
knex: trx,
|
|
335
|
-
accountability: this.accountability,
|
|
336
|
-
schema: this.schema,
|
|
337
|
-
});
|
|
338
|
-
await trx('directus_fields').delete().where('collection', '=', collectionKey);
|
|
339
|
-
await trx('directus_presets').delete().where('collection', '=', collectionKey);
|
|
340
|
-
const revisionsToDelete = await trx
|
|
341
|
-
.select('id')
|
|
342
|
-
.from('directus_revisions')
|
|
343
|
-
.where({ collection: collectionKey });
|
|
344
|
-
if (revisionsToDelete.length > 0) {
|
|
345
|
-
const keys = revisionsToDelete.map((record) => record.id);
|
|
346
|
-
await trx('directus_revisions').update({ parent: null }).whereIn('parent', keys);
|
|
334
|
+
await this.knex.transaction(async (trx) => {
|
|
335
|
+
var _a;
|
|
336
|
+
if (collectionToBeDeleted.schema) {
|
|
337
|
+
await trx.schema.dropTable(collectionKey);
|
|
347
338
|
}
|
|
348
|
-
|
|
349
|
-
await trx('
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
339
|
+
// Make sure this collection isn't used as a group in any other collections
|
|
340
|
+
await trx('directus_collections').update({ group: null }).where({ group: collectionKey });
|
|
341
|
+
if (collectionToBeDeleted.meta) {
|
|
342
|
+
const collectionItemsService = new items_1.ItemsService('directus_collections', {
|
|
343
|
+
knex: trx,
|
|
344
|
+
accountability: this.accountability,
|
|
345
|
+
schema: this.schema,
|
|
346
|
+
});
|
|
347
|
+
await collectionItemsService.deleteOne(collectionKey);
|
|
348
|
+
}
|
|
349
|
+
if (collectionToBeDeleted.schema) {
|
|
350
|
+
const fieldsService = new fields_1.FieldsService({
|
|
351
|
+
knex: trx,
|
|
352
|
+
accountability: this.accountability,
|
|
353
|
+
schema: this.schema,
|
|
354
|
+
});
|
|
355
|
+
await trx('directus_fields').delete().where('collection', '=', collectionKey);
|
|
356
|
+
await trx('directus_presets').delete().where('collection', '=', collectionKey);
|
|
357
|
+
const revisionsToDelete = await trx
|
|
358
|
+
.select('id')
|
|
359
|
+
.from('directus_revisions')
|
|
360
|
+
.where({ collection: collectionKey });
|
|
361
|
+
if (revisionsToDelete.length > 0) {
|
|
362
|
+
const keys = revisionsToDelete.map((record) => record.id);
|
|
363
|
+
await trx('directus_revisions').update({ parent: null }).whereIn('parent', keys);
|
|
364
|
+
}
|
|
365
|
+
await trx('directus_revisions').delete().where('collection', '=', collectionKey);
|
|
366
|
+
await trx('directus_activity').delete().where('collection', '=', collectionKey);
|
|
367
|
+
await trx('directus_permissions').delete().where('collection', '=', collectionKey);
|
|
368
|
+
await trx('directus_relations').delete().where({ many_collection: collectionKey });
|
|
369
|
+
const relations = this.schema.relations.filter((relation) => {
|
|
370
|
+
return relation.collection === collectionKey || relation.related_collection === collectionKey;
|
|
371
|
+
});
|
|
372
|
+
for (const relation of relations) {
|
|
373
|
+
// Delete related o2m fields that point to current collection
|
|
374
|
+
if (relation.related_collection && ((_a = relation.meta) === null || _a === void 0 ? void 0 : _a.one_field)) {
|
|
375
|
+
await fieldsService.deleteField(relation.related_collection, relation.meta.one_field);
|
|
376
|
+
}
|
|
377
|
+
// Delete related m2o fields that point to current collection
|
|
378
|
+
if (relation.related_collection === collectionKey) {
|
|
379
|
+
await fieldsService.deleteField(relation.collection, relation.field);
|
|
380
|
+
}
|
|
359
381
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
382
|
+
const a2oRelationsThatIncludeThisCollection = this.schema.relations.filter((relation) => {
|
|
383
|
+
var _a, _b;
|
|
384
|
+
return (_b = (_a = relation.meta) === null || _a === void 0 ? void 0 : _a.one_allowed_collections) === null || _b === void 0 ? void 0 : _b.includes(collectionKey);
|
|
385
|
+
});
|
|
386
|
+
for (const relation of a2oRelationsThatIncludeThisCollection) {
|
|
387
|
+
const newAllowedCollections = relation
|
|
388
|
+
.meta.one_allowed_collections.filter((collection) => collectionKey !== collection)
|
|
389
|
+
.join(',');
|
|
390
|
+
await trx('directus_relations')
|
|
391
|
+
.update({ one_allowed_collections: newAllowedCollections })
|
|
392
|
+
.where({ id: relation.meta.id });
|
|
363
393
|
}
|
|
364
394
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
.meta.one_allowed_collections.filter((collection) => collectionKey !== collection)
|
|
372
|
-
.join(',');
|
|
373
|
-
await trx('directus_relations')
|
|
374
|
-
.update({ one_allowed_collections: newAllowedCollections })
|
|
375
|
-
.where({ id: relation.meta.id });
|
|
376
|
-
}
|
|
395
|
+
});
|
|
396
|
+
return collectionKey;
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
400
|
+
await this.cache.clear();
|
|
377
401
|
}
|
|
378
|
-
|
|
379
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
380
|
-
await this.cache.clear();
|
|
402
|
+
await (0, cache_1.clearSystemCache)();
|
|
381
403
|
}
|
|
382
|
-
await this.systemCache.clear();
|
|
383
|
-
return collectionKey;
|
|
384
404
|
}
|
|
385
405
|
/**
|
|
386
406
|
* Delete multiple collections by key
|
|
@@ -389,21 +409,25 @@ class CollectionsService {
|
|
|
389
409
|
if (this.accountability && this.accountability.admin !== true) {
|
|
390
410
|
throw new exceptions_1.ForbiddenException();
|
|
391
411
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
412
|
+
try {
|
|
413
|
+
await this.knex.transaction(async (trx) => {
|
|
414
|
+
const service = new CollectionsService({
|
|
415
|
+
schema: this.schema,
|
|
416
|
+
accountability: this.accountability,
|
|
417
|
+
knex: trx,
|
|
418
|
+
});
|
|
419
|
+
for (const collectionKey of collectionKeys) {
|
|
420
|
+
await service.deleteOne(collectionKey, { autoPurgeCache: false });
|
|
421
|
+
}
|
|
397
422
|
});
|
|
398
|
-
|
|
399
|
-
|
|
423
|
+
return collectionKeys;
|
|
424
|
+
}
|
|
425
|
+
finally {
|
|
426
|
+
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
427
|
+
await this.cache.clear();
|
|
400
428
|
}
|
|
401
|
-
|
|
402
|
-
if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
|
|
403
|
-
await this.cache.clear();
|
|
429
|
+
await (0, cache_1.clearSystemCache)();
|
|
404
430
|
}
|
|
405
|
-
await this.systemCache.clear();
|
|
406
|
-
return collectionKeys;
|
|
407
431
|
}
|
|
408
432
|
}
|
|
409
433
|
exports.CollectionsService = CollectionsService;
|