@strapi/utils 4.11.3 → 4.12.0-beta.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/async.d.ts +10 -0
- package/dist/async.js +33 -0
- package/dist/async.js.map +1 -0
- package/dist/code-generator.d.ts +2 -0
- package/dist/code-generator.js +11 -0
- package/dist/code-generator.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +79 -0
- package/dist/config.js.map +1 -0
- package/dist/content-types.d.ts +60 -0
- package/dist/content-types.js +151 -0
- package/dist/content-types.js.map +1 -0
- package/dist/convert-query-params.d.ts +75 -0
- package/dist/convert-query-params.js +476 -0
- package/dist/convert-query-params.js.map +1 -0
- package/dist/env-helper.d.ts +18 -0
- package/dist/env-helper.js +84 -0
- package/dist/env-helper.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/file.d.ts +16 -0
- package/dist/file.js +54 -0
- package/dist/file.js.map +1 -0
- package/dist/format-yup-error.d.ts +10 -0
- package/dist/format-yup-error.js +17 -0
- package/dist/format-yup-error.js.map +1 -0
- package/dist/hooks.d.ts +63 -0
- package/dist/hooks.js +89 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import-default.d.ts +1 -0
- package/dist/import-default.js +9 -0
- package/dist/import-default.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/object-formatting.d.ts +3 -0
- package/dist/object-formatting.js +14 -0
- package/dist/object-formatting.js.map +1 -0
- package/dist/operators.d.ts +2 -0
- package/dist/operators.js +70 -0
- package/dist/operators.js.map +1 -0
- package/dist/pagination.d.ts +14 -0
- package/dist/pagination.js +80 -0
- package/dist/pagination.js.map +1 -0
- package/dist/parse-multipart.d.ts +8 -0
- package/dist/parse-multipart.js +36 -0
- package/dist/parse-multipart.js.map +1 -0
- package/dist/parse-type.d.ts +21 -0
- package/dist/parse-type.js +108 -0
- package/dist/parse-type.js.map +1 -0
- package/dist/policy.d.ts +41 -0
- package/dist/policy.js +109 -0
- package/dist/policy.js.map +1 -0
- package/dist/print-value.d.ts +2 -0
- package/dist/print-value.js +50 -0
- package/dist/print-value.js.map +1 -0
- package/dist/provider-factory.d.ts +29 -0
- package/dist/provider-factory.js +80 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/relations.d.ts +10 -0
- package/dist/relations.js +23 -0
- package/dist/relations.js.map +1 -0
- package/dist/sanitize/index.d.ts +23 -0
- package/dist/sanitize/index.js +135 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitizers.d.ts +10 -0
- package/dist/sanitize/sanitizers.js +114 -0
- package/dist/sanitize/sanitizers.js.map +1 -0
- package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
- package/{lib → dist}/sanitize/visitors/allowed-fields.js +17 -32
- package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
- package/dist/sanitize/visitors/index.d.ts +7 -0
- package/dist/sanitize/visitors/index.js +21 -0
- package/dist/sanitize/visitors/index.js.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-password.d.ts +3 -0
- package/dist/sanitize/visitors/remove-password.js +9 -0
- package/dist/sanitize/visitors/remove-password.js.map +1 -0
- package/dist/sanitize/visitors/remove-private.d.ts +3 -0
- package/dist/sanitize/visitors/remove-private.js +14 -0
- package/dist/sanitize/visitors/remove-private.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
- package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
- package/dist/sanitize/visitors/restricted-fields.js +25 -0
- package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
- package/dist/set-creator-fields.d.ts +9 -0
- package/dist/set-creator-fields.js +39 -0
- package/dist/set-creator-fields.js.map +1 -0
- package/dist/string-formatting.d.ts +15 -0
- package/dist/string-formatting.js +85 -0
- package/dist/string-formatting.js.map +1 -0
- package/dist/template-configuration.d.ts +5 -0
- package/dist/template-configuration.js +30 -0
- package/dist/template-configuration.js.map +1 -0
- package/dist/template.d.ts +9 -0
- package/dist/template.js +20 -0
- package/dist/template.js.map +1 -0
- package/dist/traverse/factory.d.ts +78 -0
- package/dist/traverse/factory.js +127 -0
- package/dist/traverse/factory.js.map +1 -0
- package/dist/traverse/index.d.ts +5 -0
- package/dist/traverse/index.js +17 -0
- package/dist/traverse/index.js.map +1 -0
- package/dist/traverse/query-fields.d.ts +3 -0
- package/dist/traverse/query-fields.js +35 -0
- package/dist/traverse/query-fields.js.map +1 -0
- package/dist/traverse/query-filters.d.ts +3 -0
- package/dist/traverse/query-filters.js +75 -0
- package/dist/traverse/query-filters.js.map +1 -0
- package/dist/traverse/query-populate.d.ts +3 -0
- package/dist/traverse/query-populate.js +144 -0
- package/dist/traverse/query-populate.js.map +1 -0
- package/dist/traverse/query-sort.d.ts +3 -0
- package/dist/traverse/query-sort.js +116 -0
- package/dist/traverse/query-sort.js.map +1 -0
- package/dist/traverse-entity.d.ts +31 -0
- package/dist/traverse-entity.js +134 -0
- package/dist/traverse-entity.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +13 -0
- package/dist/validators.js +120 -0
- package/dist/validators.js.map +1 -0
- package/dist/webhook.d.ts +5 -0
- package/dist/webhook.js +27 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +19 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -4
- package/index.d.ts +0 -5
- package/lib/async.d.ts +0 -21
- package/lib/async.js +0 -45
- package/lib/build-query.js +0 -208
- package/lib/code-generator.js +0 -13
- package/lib/config.js +0 -88
- package/lib/content-types.js +0 -196
- package/lib/convert-query-params.js +0 -586
- package/lib/env-helper.js +0 -98
- package/lib/errors.js +0 -113
- package/lib/file.js +0 -60
- package/lib/format-yup-error.js +0 -20
- package/lib/hooks.js +0 -110
- package/lib/import-default.js +0 -10
- package/lib/index.js +0 -99
- package/lib/object-formatting.js +0 -15
- package/lib/operators.js +0 -74
- package/lib/pagination.js +0 -99
- package/lib/parse-multipart.js +0 -44
- package/lib/parse-type.js +0 -100
- package/lib/policy.js +0 -129
- package/lib/print-value.js +0 -52
- package/lib/provider-factory.js +0 -116
- package/lib/relations.js +0 -31
- package/lib/sanitize/index.js +0 -143
- package/lib/sanitize/sanitizers.js +0 -163
- package/lib/sanitize/visitors/index.js +0 -11
- package/lib/sanitize/visitors/remove-dynamic-zones.js +0 -9
- package/lib/sanitize/visitors/remove-morph-to-relations.js +0 -9
- package/lib/sanitize/visitors/remove-password.js +0 -7
- package/lib/sanitize/visitors/remove-private.js +0 -15
- package/lib/sanitize/visitors/remove-restricted-relations.js +0 -81
- package/lib/sanitize/visitors/restricted-fields.js +0 -32
- package/lib/set-creator-fields.js +0 -17
- package/lib/string-formatting.js +0 -79
- package/lib/template-configuration.js +0 -32
- package/lib/template.js +0 -28
- package/lib/traverse/factory.js +0 -157
- package/lib/traverse/index.js +0 -16
- package/lib/traverse/query-fields.js +0 -39
- package/lib/traverse/query-filters.js +0 -97
- package/lib/traverse/query-populate.js +0 -191
- package/lib/traverse/query-sort.js +0 -171
- package/lib/traverse-entity.js +0 -166
- package/lib/validators.js +0 -120
- package/lib/webhook.js +0 -30
package/lib/errors.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const { HttpError } = require('http-errors');
|
|
6
|
-
const { formatYupErrors } = require('./format-yup-error');
|
|
7
|
-
|
|
8
|
-
/* ApplicationError */
|
|
9
|
-
class ApplicationError extends Error {
|
|
10
|
-
constructor(message, details = {}) {
|
|
11
|
-
super();
|
|
12
|
-
this.name = 'ApplicationError';
|
|
13
|
-
this.message = message || 'An application error occured';
|
|
14
|
-
this.details = details;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class ValidationError extends ApplicationError {
|
|
19
|
-
constructor(message, details) {
|
|
20
|
-
super(message, details);
|
|
21
|
-
this.name = 'ValidationError';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
class YupValidationError extends ValidationError {
|
|
26
|
-
constructor(yupError, message) {
|
|
27
|
-
super();
|
|
28
|
-
const { errors, message: yupMessage } = formatYupErrors(yupError);
|
|
29
|
-
this.message = message || yupMessage;
|
|
30
|
-
this.details = { errors };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class PaginationError extends ApplicationError {
|
|
35
|
-
constructor(message, details) {
|
|
36
|
-
super(message, details);
|
|
37
|
-
this.name = 'PaginationError';
|
|
38
|
-
this.message = message || 'Invalid pagination';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class NotFoundError extends ApplicationError {
|
|
43
|
-
constructor(message, details) {
|
|
44
|
-
super(message, details);
|
|
45
|
-
this.name = 'NotFoundError';
|
|
46
|
-
this.message = message || 'Entity not found';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class ForbiddenError extends ApplicationError {
|
|
51
|
-
constructor(message, details) {
|
|
52
|
-
super(message, details);
|
|
53
|
-
this.name = 'ForbiddenError';
|
|
54
|
-
this.message = message || 'Forbidden access';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
class UnauthorizedError extends ApplicationError {
|
|
59
|
-
constructor(message, details) {
|
|
60
|
-
super(message, details);
|
|
61
|
-
this.name = 'UnauthorizedError';
|
|
62
|
-
this.message = message || 'Unauthorized';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class RateLimitError extends ApplicationError {
|
|
67
|
-
constructor(message, details) {
|
|
68
|
-
super(message, details);
|
|
69
|
-
this.name = 'RateLimitError';
|
|
70
|
-
this.message = message || 'Too many requests, please try again later.';
|
|
71
|
-
this.details = details || {};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
class PayloadTooLargeError extends ApplicationError {
|
|
76
|
-
constructor(message, details) {
|
|
77
|
-
super(message, details);
|
|
78
|
-
this.name = 'PayloadTooLargeError';
|
|
79
|
-
this.message = message || 'Entity too large';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
class PolicyError extends ForbiddenError {
|
|
84
|
-
constructor(message, details) {
|
|
85
|
-
super(message, details);
|
|
86
|
-
this.name = 'PolicyError';
|
|
87
|
-
this.message = message || 'Policy Failed';
|
|
88
|
-
this.details = details || {};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
class NotImplementedError extends ApplicationError {
|
|
93
|
-
constructor(message, details) {
|
|
94
|
-
super(message, details);
|
|
95
|
-
this.name = 'NotImplementedError';
|
|
96
|
-
this.message = message || 'This feature is not implemented yet';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = {
|
|
101
|
-
HttpError,
|
|
102
|
-
ApplicationError,
|
|
103
|
-
ValidationError,
|
|
104
|
-
YupValidationError,
|
|
105
|
-
PaginationError,
|
|
106
|
-
NotFoundError,
|
|
107
|
-
ForbiddenError,
|
|
108
|
-
UnauthorizedError,
|
|
109
|
-
RateLimitError,
|
|
110
|
-
PayloadTooLargeError,
|
|
111
|
-
PolicyError,
|
|
112
|
-
NotImplementedError,
|
|
113
|
-
};
|
package/lib/file.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Utils file containing file treatment utils
|
|
5
|
-
*/
|
|
6
|
-
const { Writable } = require('stream');
|
|
7
|
-
|
|
8
|
-
const kbytesToBytes = (kbytes) => kbytes * 1000;
|
|
9
|
-
const bytesToKbytes = (bytes) => Math.round((bytes / 1000) * 100) / 100;
|
|
10
|
-
const bytesToHumanReadable = (bytes) => {
|
|
11
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
12
|
-
if (bytes === 0) return '0 Bytes';
|
|
13
|
-
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1000)), 10);
|
|
14
|
-
return `${Math.round(bytes / 1000 ** i, 2)} ${sizes[i]}`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const streamToBuffer = (stream) =>
|
|
18
|
-
new Promise((resolve, reject) => {
|
|
19
|
-
const chunks = [];
|
|
20
|
-
stream.on('data', (chunk) => {
|
|
21
|
-
chunks.push(chunk);
|
|
22
|
-
});
|
|
23
|
-
stream.on('end', () => {
|
|
24
|
-
resolve(Buffer.concat(chunks));
|
|
25
|
-
});
|
|
26
|
-
stream.on('error', reject);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const getStreamSize = (stream) =>
|
|
30
|
-
new Promise((resolve, reject) => {
|
|
31
|
-
let size = 0;
|
|
32
|
-
stream.on('data', (chunk) => {
|
|
33
|
-
size += Buffer.byteLength(chunk);
|
|
34
|
-
});
|
|
35
|
-
stream.on('close', () => resolve(size));
|
|
36
|
-
stream.on('error', reject);
|
|
37
|
-
stream.resume();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create a writeable Node.js stream that discards received data.
|
|
42
|
-
* Useful for testing, draining a stream of data, etc.
|
|
43
|
-
*/
|
|
44
|
-
function writableDiscardStream(options) {
|
|
45
|
-
return new Writable({
|
|
46
|
-
...options,
|
|
47
|
-
write(chunk, encding, callback) {
|
|
48
|
-
setImmediate(callback);
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = {
|
|
54
|
-
streamToBuffer,
|
|
55
|
-
bytesToHumanReadable,
|
|
56
|
-
bytesToKbytes,
|
|
57
|
-
kbytesToBytes,
|
|
58
|
-
getStreamSize,
|
|
59
|
-
writableDiscardStream,
|
|
60
|
-
};
|
package/lib/format-yup-error.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { isEmpty, toPath } = require('lodash/fp');
|
|
4
|
-
|
|
5
|
-
const formatYupInnerError = (yupError) => ({
|
|
6
|
-
path: toPath(yupError.path),
|
|
7
|
-
message: yupError.message,
|
|
8
|
-
name: yupError.name,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const formatYupErrors = (yupError) => ({
|
|
12
|
-
errors: isEmpty(yupError.inner)
|
|
13
|
-
? [formatYupInnerError(yupError)]
|
|
14
|
-
: yupError.inner.map(formatYupInnerError),
|
|
15
|
-
message: yupError.message,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
module.exports = {
|
|
19
|
-
formatYupErrors,
|
|
20
|
-
};
|
package/lib/hooks.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { eq, remove, cloneDeep } = require('lodash/fp');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a default Strapi hook
|
|
7
|
-
*/
|
|
8
|
-
const createHook = () => {
|
|
9
|
-
const state = {
|
|
10
|
-
handlers: [],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
getHandlers() {
|
|
15
|
-
return state.handlers;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
register(handler) {
|
|
19
|
-
state.handlers.push(handler);
|
|
20
|
-
|
|
21
|
-
return this;
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
delete(handler) {
|
|
25
|
-
state.handlers = remove(eq(handler), state.handlers);
|
|
26
|
-
|
|
27
|
-
return this;
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
call() {
|
|
31
|
-
throw new Error('Method not implemented');
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Create an async series hook.
|
|
38
|
-
* Upon execution, it will execute every handler in order with the same context
|
|
39
|
-
*/
|
|
40
|
-
const createAsyncSeriesHook = () => ({
|
|
41
|
-
...createHook(),
|
|
42
|
-
|
|
43
|
-
async call(context) {
|
|
44
|
-
for (const handler of this.getHandlers()) {
|
|
45
|
-
await handler(context);
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Create an async series waterfall hook.
|
|
52
|
-
* Upon execution, it will execute every handler in order and pass the return value of the last handler to the next one
|
|
53
|
-
*/
|
|
54
|
-
const createAsyncSeriesWaterfallHook = () => ({
|
|
55
|
-
...createHook(),
|
|
56
|
-
|
|
57
|
-
async call(param) {
|
|
58
|
-
let res = param;
|
|
59
|
-
|
|
60
|
-
for (const handler of this.getHandlers()) {
|
|
61
|
-
res = await handler(res);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return res;
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Create an async parallel hook.
|
|
70
|
-
* Upon execution, it will execute every registered handler in band.
|
|
71
|
-
*/
|
|
72
|
-
const createAsyncParallelHook = () => ({
|
|
73
|
-
...createHook(),
|
|
74
|
-
|
|
75
|
-
async call(context) {
|
|
76
|
-
const promises = this.getHandlers().map((handler) => handler(cloneDeep(context)));
|
|
77
|
-
|
|
78
|
-
return Promise.all(promises);
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Create an async parallel hook.
|
|
84
|
-
* Upon execution, it will execute every registered handler in serie and return the first result found.
|
|
85
|
-
*/
|
|
86
|
-
const createAsyncBailHook = () => ({
|
|
87
|
-
...createHook(),
|
|
88
|
-
|
|
89
|
-
async call(context) {
|
|
90
|
-
for (const handler of this.getHandlers()) {
|
|
91
|
-
const result = await handler(context);
|
|
92
|
-
|
|
93
|
-
if (result !== undefined) {
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
module.exports = {
|
|
101
|
-
// Internal utils
|
|
102
|
-
internals: {
|
|
103
|
-
createHook,
|
|
104
|
-
},
|
|
105
|
-
// Hooks
|
|
106
|
-
createAsyncSeriesHook,
|
|
107
|
-
createAsyncSeriesWaterfallHook,
|
|
108
|
-
createAsyncParallelHook,
|
|
109
|
-
createAsyncBailHook,
|
|
110
|
-
};
|
package/lib/import-default.js
DELETED
package/lib/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Export shared utilities
|
|
5
|
-
*/
|
|
6
|
-
const { buildQuery, hasDeepFilters } = require('./build-query');
|
|
7
|
-
const parseMultipartData = require('./parse-multipart');
|
|
8
|
-
const parseType = require('./parse-type');
|
|
9
|
-
const policy = require('./policy');
|
|
10
|
-
const templateConfiguration = require('./template-configuration');
|
|
11
|
-
const { yup, handleYupError, validateYupSchema, validateYupSchemaSync } = require('./validators');
|
|
12
|
-
const errors = require('./errors');
|
|
13
|
-
const {
|
|
14
|
-
nameToSlug,
|
|
15
|
-
nameToCollectionName,
|
|
16
|
-
getCommonBeginning,
|
|
17
|
-
escapeQuery,
|
|
18
|
-
stringIncludes,
|
|
19
|
-
stringEquals,
|
|
20
|
-
isKebabCase,
|
|
21
|
-
isCamelCase,
|
|
22
|
-
toRegressedEnumValue,
|
|
23
|
-
startsWithANumber,
|
|
24
|
-
joinBy,
|
|
25
|
-
toKebabCase,
|
|
26
|
-
} = require('./string-formatting');
|
|
27
|
-
const { removeUndefined, keysDeep } = require('./object-formatting');
|
|
28
|
-
const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
|
|
29
|
-
const { generateTimestampCode } = require('./code-generator');
|
|
30
|
-
const contentTypes = require('./content-types');
|
|
31
|
-
const env = require('./env-helper');
|
|
32
|
-
const webhook = require('./webhook');
|
|
33
|
-
const relations = require('./relations');
|
|
34
|
-
const setCreatorFields = require('./set-creator-fields');
|
|
35
|
-
const hooks = require('./hooks');
|
|
36
|
-
const providerFactory = require('./provider-factory');
|
|
37
|
-
const pagination = require('./pagination');
|
|
38
|
-
const sanitize = require('./sanitize');
|
|
39
|
-
const traverseEntity = require('./traverse-entity');
|
|
40
|
-
const { pipeAsync, mapAsync, reduceAsync, forEachAsync } = require('./async');
|
|
41
|
-
const convertQueryParams = require('./convert-query-params');
|
|
42
|
-
const importDefault = require('./import-default');
|
|
43
|
-
const template = require('./template');
|
|
44
|
-
const file = require('./file');
|
|
45
|
-
const traverse = require('./traverse');
|
|
46
|
-
const { isOperator, isOperatorOfType } = require('./operators');
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
yup,
|
|
50
|
-
handleYupError,
|
|
51
|
-
policy,
|
|
52
|
-
templateConfiguration,
|
|
53
|
-
buildQuery,
|
|
54
|
-
hasDeepFilters,
|
|
55
|
-
parseMultipartData,
|
|
56
|
-
sanitize,
|
|
57
|
-
traverseEntity,
|
|
58
|
-
parseType,
|
|
59
|
-
nameToSlug,
|
|
60
|
-
toRegressedEnumValue,
|
|
61
|
-
startsWithANumber,
|
|
62
|
-
joinBy,
|
|
63
|
-
nameToCollectionName,
|
|
64
|
-
getCommonBeginning,
|
|
65
|
-
getConfigUrls,
|
|
66
|
-
escapeQuery,
|
|
67
|
-
removeUndefined,
|
|
68
|
-
keysDeep,
|
|
69
|
-
getAbsoluteAdminUrl,
|
|
70
|
-
getAbsoluteServerUrl,
|
|
71
|
-
generateTimestampCode,
|
|
72
|
-
stringIncludes,
|
|
73
|
-
stringEquals,
|
|
74
|
-
template,
|
|
75
|
-
isKebabCase,
|
|
76
|
-
isCamelCase,
|
|
77
|
-
toKebabCase,
|
|
78
|
-
webhook,
|
|
79
|
-
contentTypes,
|
|
80
|
-
env,
|
|
81
|
-
relations,
|
|
82
|
-
setCreatorFields,
|
|
83
|
-
hooks,
|
|
84
|
-
providerFactory,
|
|
85
|
-
pagination,
|
|
86
|
-
pipeAsync,
|
|
87
|
-
mapAsync,
|
|
88
|
-
reduceAsync,
|
|
89
|
-
forEachAsync,
|
|
90
|
-
errors,
|
|
91
|
-
validateYupSchema,
|
|
92
|
-
validateYupSchemaSync,
|
|
93
|
-
convertQueryParams,
|
|
94
|
-
importDefault,
|
|
95
|
-
file,
|
|
96
|
-
traverse,
|
|
97
|
-
isOperator,
|
|
98
|
-
isOperatorOfType,
|
|
99
|
-
};
|
package/lib/object-formatting.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
const removeUndefined = (obj) => _.pickBy(obj, (value) => typeof value !== 'undefined');
|
|
6
|
-
|
|
7
|
-
const keysDeep = (obj, path = []) =>
|
|
8
|
-
!_.isObject(obj)
|
|
9
|
-
? path.join('.')
|
|
10
|
-
: _.reduce(obj, (acc, next, key) => _.concat(acc, keysDeep(next, [...path, key])), []);
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
removeUndefined,
|
|
14
|
-
keysDeep,
|
|
15
|
-
};
|
package/lib/operators.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const GROUP_OPERATORS = ['$and', '$or'];
|
|
4
|
-
|
|
5
|
-
const WHERE_OPERATORS = [
|
|
6
|
-
'$not',
|
|
7
|
-
'$in',
|
|
8
|
-
'$notIn',
|
|
9
|
-
'$eq',
|
|
10
|
-
'$eqi',
|
|
11
|
-
'$ne',
|
|
12
|
-
'$gt',
|
|
13
|
-
'$gte',
|
|
14
|
-
'$lt',
|
|
15
|
-
'$lte',
|
|
16
|
-
'$null',
|
|
17
|
-
'$notNull',
|
|
18
|
-
'$between',
|
|
19
|
-
'$startsWith',
|
|
20
|
-
'$endsWith',
|
|
21
|
-
'$startsWithi',
|
|
22
|
-
'$endsWithi',
|
|
23
|
-
'$contains',
|
|
24
|
-
'$notContains',
|
|
25
|
-
'$containsi',
|
|
26
|
-
'$notContainsi',
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const CAST_OPERATORS = [
|
|
30
|
-
'$not',
|
|
31
|
-
'$in',
|
|
32
|
-
'$notIn',
|
|
33
|
-
'$eq',
|
|
34
|
-
'$ne',
|
|
35
|
-
'$gt',
|
|
36
|
-
'$gte',
|
|
37
|
-
'$lt',
|
|
38
|
-
'$lte',
|
|
39
|
-
'$between',
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const ARRAY_OPERATORS = ['$in', '$notIn', '$between'];
|
|
43
|
-
|
|
44
|
-
const OPERATORS = {
|
|
45
|
-
where: WHERE_OPERATORS,
|
|
46
|
-
cast: CAST_OPERATORS,
|
|
47
|
-
group: GROUP_OPERATORS,
|
|
48
|
-
array: ARRAY_OPERATORS,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// for performance, cache all operators in lowercase
|
|
52
|
-
const OPERATORS_LOWERCASE = Object.fromEntries(
|
|
53
|
-
Object.entries(OPERATORS).map(([key, values]) => [
|
|
54
|
-
key,
|
|
55
|
-
values.map((value) => value.toLowerCase()),
|
|
56
|
-
])
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const isOperatorOfType = (type, key, ignoreCase = false) => {
|
|
60
|
-
if (ignoreCase) {
|
|
61
|
-
return OPERATORS_LOWERCASE[type]?.includes(key.toLowerCase()) ?? false;
|
|
62
|
-
}
|
|
63
|
-
return OPERATORS[type]?.includes(key) ?? false;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const isOperator = (key, ignoreCase = false) => {
|
|
67
|
-
return Object.keys(OPERATORS).some((type) => isOperatorOfType(type, key, ignoreCase));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
isOperator,
|
|
72
|
-
isOperatorOfType,
|
|
73
|
-
OPERATORS,
|
|
74
|
-
};
|
package/lib/pagination.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { merge, pipe, omit, isNil } = require('lodash/fp');
|
|
4
|
-
const { PaginationError } = require('./errors');
|
|
5
|
-
|
|
6
|
-
const STRAPI_DEFAULTS = {
|
|
7
|
-
offset: {
|
|
8
|
-
start: 0,
|
|
9
|
-
limit: 10,
|
|
10
|
-
},
|
|
11
|
-
page: {
|
|
12
|
-
page: 1,
|
|
13
|
-
pageSize: 10,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const paginationAttributes = ['start', 'limit', 'page', 'pageSize'];
|
|
18
|
-
|
|
19
|
-
const withMaxLimit = (limit, maxLimit = -1) => {
|
|
20
|
-
if (maxLimit === -1 || limit < maxLimit) {
|
|
21
|
-
return limit;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return maxLimit;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Ensure minimum page & pageSize values (page >= 1, pageSize >= 0, start >= 0, limit >= 0)
|
|
28
|
-
const ensureMinValues = ({ start, limit }) => ({
|
|
29
|
-
start: Math.max(start, 0),
|
|
30
|
-
limit: limit === -1 ? limit : Math.max(limit, 1),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const ensureMaxValues =
|
|
34
|
-
(maxLimit = -1) =>
|
|
35
|
-
({ start, limit }) => ({
|
|
36
|
-
start,
|
|
37
|
-
limit: withMaxLimit(limit, maxLimit),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Apply maxLimit as the limit when limit is -1
|
|
41
|
-
const withNoLimit = (pagination, maxLimit = -1) => ({
|
|
42
|
-
...pagination,
|
|
43
|
-
limit: pagination.limit === -1 ? maxLimit : pagination.limit,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
|
|
47
|
-
const defaultValues = merge(STRAPI_DEFAULTS, defaults);
|
|
48
|
-
|
|
49
|
-
const usePagePagination = !isNil(args.page) || !isNil(args.pageSize);
|
|
50
|
-
const useOffsetPagination = !isNil(args.start) || !isNil(args.limit);
|
|
51
|
-
|
|
52
|
-
const ensureValidValues = pipe(ensureMinValues, ensureMaxValues(maxLimit));
|
|
53
|
-
|
|
54
|
-
// If there is no pagination attribute, don't modify the payload
|
|
55
|
-
if (!usePagePagination && !useOffsetPagination) {
|
|
56
|
-
return merge(args, ensureValidValues(defaultValues.offset));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// If there is page & offset pagination attributes, throw an error
|
|
60
|
-
if (usePagePagination && useOffsetPagination) {
|
|
61
|
-
throw new PaginationError('Cannot use both page & offset pagination in the same query');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const pagination = {};
|
|
65
|
-
|
|
66
|
-
// Start / Limit
|
|
67
|
-
if (useOffsetPagination) {
|
|
68
|
-
const { start, limit } = merge(defaultValues.offset, args);
|
|
69
|
-
|
|
70
|
-
Object.assign(pagination, { start, limit });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Page / PageSize
|
|
74
|
-
if (usePagePagination) {
|
|
75
|
-
const { page, pageSize } = merge(defaultValues.page, {
|
|
76
|
-
...args,
|
|
77
|
-
pageSize: Math.max(1, args.pageSize),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
Object.assign(pagination, {
|
|
81
|
-
start: (page - 1) * pageSize,
|
|
82
|
-
limit: pageSize,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Handle -1 limit
|
|
87
|
-
Object.assign(pagination, withNoLimit(pagination, maxLimit));
|
|
88
|
-
|
|
89
|
-
const replacePaginationAttributes = pipe(
|
|
90
|
-
// Remove pagination attributes
|
|
91
|
-
omit(paginationAttributes),
|
|
92
|
-
// Merge the object with the new pagination + ensure minimum & maximum values
|
|
93
|
-
merge(ensureValidValues(pagination))
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
return replacePaginationAttributes(args);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
module.exports = { withDefaultPagination };
|
package/lib/parse-multipart.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
module.exports = (ctx) => {
|
|
6
|
-
if (!ctx.is('multipart')) {
|
|
7
|
-
return { data: ctx.request.body, files: {} };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const { body = {}, files = {} } = ctx.request;
|
|
11
|
-
|
|
12
|
-
if (!body.data) {
|
|
13
|
-
return ctx.badRequest(
|
|
14
|
-
`When using multipart/form-data you need to provide your data in a JSON 'data' field.`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let data;
|
|
19
|
-
try {
|
|
20
|
-
data = JSON.parse(body.data);
|
|
21
|
-
} catch (error) {
|
|
22
|
-
return ctx.badRequest(`Invalid 'data' field. 'data' should be a valid JSON.`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const filesToUpload = Object.keys(files).reduce((acc, key) => {
|
|
26
|
-
const fullPath = _.toPath(key);
|
|
27
|
-
|
|
28
|
-
if (fullPath.length <= 1 || fullPath[0] !== 'files') {
|
|
29
|
-
return ctx.badRequest(
|
|
30
|
-
`When using multipart/form-data you need to provide your files by prefixing them with the 'files'.
|
|
31
|
-
For example, when a media file is named "avatar", make sure the form key name is "files.avatar"`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const path = _.tail(fullPath);
|
|
36
|
-
acc[path.join('.')] = files[key];
|
|
37
|
-
return acc;
|
|
38
|
-
}, {});
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
data,
|
|
42
|
-
files: filesToUpload,
|
|
43
|
-
};
|
|
44
|
-
};
|