directus 9.6.0 → 9.7.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 +27 -5
- 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/run-ast.js +7 -1
- package/dist/env.js +5 -2
- package/dist/exceptions/database/dialects/mysql.js +23 -17
- package/dist/middleware/respond.js +7 -28
- package/dist/services/collections.js +6 -6
- package/dist/services/fields.js +3 -3
- 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/permissions.js +10 -10
- package/dist/services/relations.js +7 -4
- package/dist/utils/get-date-formatted.d.ts +1 -0
- package/dist/utils/get-date-formatted.js +14 -0
- package/dist/utils/get-permissions.js +1 -1
- package/dist/utils/get-schema.js +1 -1
- package/package.json +13 -12
- package/dist/services/import.d.ts +0 -13
- package/dist/services/import.js +0 -118
package/dist/services/import.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ImportService = void 0;
|
|
7
|
-
const database_1 = __importDefault(require("../database"));
|
|
8
|
-
const exceptions_1 = require("../exceptions");
|
|
9
|
-
const StreamArray_1 = __importDefault(require("stream-json/streamers/StreamArray"));
|
|
10
|
-
const items_1 = require("./items");
|
|
11
|
-
const async_1 = require("async");
|
|
12
|
-
const destroy_1 = __importDefault(require("destroy"));
|
|
13
|
-
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
|
-
class ImportService {
|
|
16
|
-
constructor(options) {
|
|
17
|
-
this.knex = options.knex || (0, database_1.default)();
|
|
18
|
-
this.accountability = options.accountability || null;
|
|
19
|
-
this.schema = options.schema;
|
|
20
|
-
}
|
|
21
|
-
async import(collection, mimetype, stream) {
|
|
22
|
-
var _a, _b, _c, _d, _e;
|
|
23
|
-
if (collection.startsWith('directus_'))
|
|
24
|
-
throw new exceptions_1.ForbiddenException();
|
|
25
|
-
const createPermissions = (_b = (_a = this.accountability) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.find((permission) => permission.collection === collection && permission.action === 'create');
|
|
26
|
-
const updatePermissions = (_d = (_c = this.accountability) === null || _c === void 0 ? void 0 : _c.permissions) === null || _d === void 0 ? void 0 : _d.find((permission) => permission.collection === collection && permission.action === 'update');
|
|
27
|
-
if (((_e = this.accountability) === null || _e === void 0 ? void 0 : _e.admin) !== true && (!createPermissions || !updatePermissions)) {
|
|
28
|
-
throw new exceptions_1.ForbiddenException();
|
|
29
|
-
}
|
|
30
|
-
switch (mimetype) {
|
|
31
|
-
case 'application/json':
|
|
32
|
-
return await this.importJSON(collection, stream);
|
|
33
|
-
case 'text/csv':
|
|
34
|
-
case 'application/vnd.ms-excel':
|
|
35
|
-
return await this.importCSV(collection, stream);
|
|
36
|
-
default:
|
|
37
|
-
throw new exceptions_1.UnsupportedMediaTypeException(`Can't import files of type "${mimetype}"`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
importJSON(collection, stream) {
|
|
41
|
-
const extractJSON = StreamArray_1.default.withParser();
|
|
42
|
-
return this.knex.transaction((trx) => {
|
|
43
|
-
const service = new items_1.ItemsService(collection, {
|
|
44
|
-
knex: trx,
|
|
45
|
-
schema: this.schema,
|
|
46
|
-
accountability: this.accountability,
|
|
47
|
-
});
|
|
48
|
-
const saveQueue = (0, async_1.queue)(async (value) => {
|
|
49
|
-
return await service.upsertOne(value);
|
|
50
|
-
});
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
stream.pipe(extractJSON);
|
|
53
|
-
extractJSON.on('data', ({ value }) => {
|
|
54
|
-
saveQueue.push(value);
|
|
55
|
-
});
|
|
56
|
-
extractJSON.on('error', (err) => {
|
|
57
|
-
(0, destroy_1.default)(stream);
|
|
58
|
-
(0, destroy_1.default)(extractJSON);
|
|
59
|
-
reject(new exceptions_1.InvalidPayloadException(err.message));
|
|
60
|
-
});
|
|
61
|
-
saveQueue.error((err) => {
|
|
62
|
-
reject(err);
|
|
63
|
-
});
|
|
64
|
-
extractJSON.on('end', () => {
|
|
65
|
-
saveQueue.drain(() => {
|
|
66
|
-
return resolve();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
importCSV(collection, stream) {
|
|
73
|
-
return this.knex.transaction((trx) => {
|
|
74
|
-
const service = new items_1.ItemsService(collection, {
|
|
75
|
-
knex: trx,
|
|
76
|
-
schema: this.schema,
|
|
77
|
-
accountability: this.accountability,
|
|
78
|
-
});
|
|
79
|
-
const saveQueue = (0, async_1.queue)(async (value) => {
|
|
80
|
-
return await service.upsertOne(value);
|
|
81
|
-
});
|
|
82
|
-
return new Promise((resolve, reject) => {
|
|
83
|
-
stream
|
|
84
|
-
.pipe((0, csv_parser_1.default)())
|
|
85
|
-
.on('data', (value) => {
|
|
86
|
-
const obj = (0, lodash_1.transform)(value, (result, value, key) => {
|
|
87
|
-
if (value.length === 0) {
|
|
88
|
-
delete result[key];
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
try {
|
|
92
|
-
const parsedJson = JSON.parse(value);
|
|
93
|
-
(0, lodash_1.set)(result, key, parsedJson);
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
(0, lodash_1.set)(result, key, value);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
saveQueue.push(obj);
|
|
101
|
-
})
|
|
102
|
-
.on('error', (err) => {
|
|
103
|
-
(0, destroy_1.default)(stream);
|
|
104
|
-
reject(new exceptions_1.InvalidPayloadException(err.message));
|
|
105
|
-
})
|
|
106
|
-
.on('end', () => {
|
|
107
|
-
saveQueue.drain(() => {
|
|
108
|
-
return resolve();
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
saveQueue.error((err) => {
|
|
112
|
-
reject(err);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.ImportService = ImportService;
|