@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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.validateYupSchemaSync = exports.validateYupSchema = exports.handleYupError = exports.StrapiIDSchema = exports.yup = void 0;
|
|
30
|
+
/* eslint-disable no-template-curly-in-string */
|
|
31
|
+
const yup = __importStar(require("yup"));
|
|
32
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
33
|
+
const fp_1 = require("lodash/fp");
|
|
34
|
+
const utils = __importStar(require("./string-formatting"));
|
|
35
|
+
const errors_1 = require("./errors");
|
|
36
|
+
const print_value_1 = __importDefault(require("./print-value"));
|
|
37
|
+
const MixedSchemaType = yup.MixedSchema;
|
|
38
|
+
const isNotNilTest = (value) => !lodash_1.default.isNil(value);
|
|
39
|
+
const isNotNullTest = (value) => !lodash_1.default.isNull(value);
|
|
40
|
+
yup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {
|
|
41
|
+
return this.test('defined', msg, isNotNilTest);
|
|
42
|
+
});
|
|
43
|
+
yup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {
|
|
44
|
+
return this.test('defined', msg, isNotNullTest);
|
|
45
|
+
});
|
|
46
|
+
yup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {
|
|
47
|
+
return this.test('is a function', message, (value) => lodash_1.default.isUndefined(value) || lodash_1.default.isFunction(value));
|
|
48
|
+
});
|
|
49
|
+
yup.addMethod(yup.string, 'isCamelCase', function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {
|
|
50
|
+
return this.test('is in camelCase', message, (value) => value ? utils.isCamelCase(value) : true);
|
|
51
|
+
});
|
|
52
|
+
yup.addMethod(yup.string, 'isKebabCase', function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {
|
|
53
|
+
return this.test('is in kebab-case', message, (value) => value ? utils.isKebabCase(value) : true);
|
|
54
|
+
});
|
|
55
|
+
yup.addMethod(yup.object, 'onlyContainsFunctions', function onlyContainsFunctions(message = '${path} contains values that are not functions') {
|
|
56
|
+
return this.test('only contains functions', message, (value) => lodash_1.default.isUndefined(value) || (value && Object.values(value).every(lodash_1.default.isFunction)));
|
|
57
|
+
});
|
|
58
|
+
class StrapiIDSchema extends MixedSchemaType {
|
|
59
|
+
constructor() {
|
|
60
|
+
super({ type: 'strapiID' });
|
|
61
|
+
}
|
|
62
|
+
_typeCheck(value) {
|
|
63
|
+
return typeof value === 'string' || ((0, fp_1.isNumber)(value) && (0, fp_1.isInteger)(value) && value >= 0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.StrapiIDSchema = StrapiIDSchema;
|
|
67
|
+
const handleYupError = (error, errorMessage) => {
|
|
68
|
+
throw new errors_1.YupValidationError(error, errorMessage);
|
|
69
|
+
};
|
|
70
|
+
exports.handleYupError = handleYupError;
|
|
71
|
+
const defaultValidationParam = { strict: true, abortEarly: false };
|
|
72
|
+
const validateYupSchema = (schema, options = {}) => async (body, errorMessage) => {
|
|
73
|
+
try {
|
|
74
|
+
const optionsWithDefaults = (0, fp_1.defaults)(defaultValidationParam, options);
|
|
75
|
+
const result = await schema.validate(body, optionsWithDefaults);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
if (e instanceof yup.ValidationError) {
|
|
80
|
+
handleYupError(e, errorMessage);
|
|
81
|
+
}
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.validateYupSchema = validateYupSchema;
|
|
86
|
+
const validateYupSchemaSync = (schema, options = {}) => (body, errorMessage) => {
|
|
87
|
+
try {
|
|
88
|
+
const optionsWithDefaults = (0, fp_1.defaults)(defaultValidationParam, options);
|
|
89
|
+
return schema.validateSync(body, optionsWithDefaults);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
if (e instanceof yup.ValidationError) {
|
|
93
|
+
handleYupError(e, errorMessage);
|
|
94
|
+
}
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.validateYupSchemaSync = validateYupSchemaSync;
|
|
99
|
+
// Temporary fix of this issue : https://github.com/jquense/yup/issues/616
|
|
100
|
+
yup.setLocale({
|
|
101
|
+
mixed: {
|
|
102
|
+
notType(options) {
|
|
103
|
+
const { path, type, value, originalValue } = options;
|
|
104
|
+
const isCast = originalValue != null && originalValue !== value;
|
|
105
|
+
const msg = `${path} must be a \`${type}\` type, ` +
|
|
106
|
+
`but the final value was: \`${(0, print_value_1.default)(value, true)}\`${isCast ? ` (cast from the value \`${(0, print_value_1.default)(originalValue, true)}\`).` : '.'}`;
|
|
107
|
+
/* Remove comment that is not supposed to be seen by the enduser
|
|
108
|
+
if (value === null) {
|
|
109
|
+
msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``;
|
|
110
|
+
}
|
|
111
|
+
*/
|
|
112
|
+
return msg;
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const customYup = Object.assign(yup, {
|
|
117
|
+
strapiID: () => new StrapiIDSchema(),
|
|
118
|
+
});
|
|
119
|
+
exports.yup = customYup;
|
|
120
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAgD;AAChD,yCAA2B;AAC3B,oDAAuB;AACvB,kCAA0D;AAC1D,2DAA6C;AAC7C,qCAA8C;AAC9C,gEAAuC;AAEvC,MAAM,eAAe,GAAG,GAAG,CAAC,WAAW,CAAC;AAExC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,gBAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAEzD,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,gBAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE3D,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,SAAS,CAAC,GAAG,GAAG,0BAA0B;IACpF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,SAAS,CAAC,GAAG,GAAG,yBAAyB;IACpF,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,CA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Property(exports, "__esModule", { value: true });
|
|
3
|
+
const webhookEvents = {
|
|
4
|
+
ENTRY_CREATE: 'entry.create',
|
|
5
|
+
ENTRY_UPDATE: 'entry.update',
|
|
6
|
+
ENTRY_DELETE: 'entry.delete',
|
|
7
|
+
ENTRY_PUBLISH: 'entry.publish',
|
|
8
|
+
ENTRY_UNPUBLISH: 'entry.unpublish',
|
|
9
|
+
MEDIA_CREATE: 'media.create',
|
|
10
|
+
MEDIA_UPDATE: 'media.update',
|
|
11
|
+
MEDIA_DELETE: 'media.delete',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* TODO V5: remove this file
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
const deprecatedWebhookEvents = new Proxy(webhookEvents, {
|
|
18
|
+
get(target, prop) {
|
|
19
|
+
console.warn('[deprecated] @strapi/utils/webhook will no longer exist in the next major release of Strapi. ' +
|
|
20
|
+
'Instead, the webhookEvents object can be retrieved from strapi.webhookStore.allowedEvents');
|
|
21
|
+
return target[prop];
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
exports.default = {
|
|
25
|
+
webhookEvents: deprecatedWebhookEvents,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":";;AAAA,MAAM,aAAa,GAAG;IACpB,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;CAC7B,CAAC;AAIF;;;GAGG;AACH,MAAM,uBAAuB,GAAG,IAAI,KAAK,CAAgB,aAAa,EAAE;IACtE,GAAG,CAAC,MAAM,EAAE,IAAY;QACtB,OAAO,CAAC,IAAI,CACV,+FAA+F;YAC7F,2FAA2F,CAC9F,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF,CAAC,CAAC;AAEH,kBAAe;IACb,aAAa,EAAE,uBAAuB;CACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.0-beta.0",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -27,12 +27,20 @@
|
|
|
27
27
|
"url": "https://strapi.io"
|
|
28
28
|
}
|
|
29
29
|
],
|
|
30
|
-
"main": "./
|
|
31
|
-
"types": "./index.d.ts",
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"./dist"
|
|
34
|
+
],
|
|
32
35
|
"directories": {
|
|
33
36
|
"lib": "./lib"
|
|
34
37
|
},
|
|
35
38
|
"scripts": {
|
|
39
|
+
"build": "run -T tsc",
|
|
40
|
+
"build:ts": "run build",
|
|
41
|
+
"watch": "run -T tsc -w --preserveWatchOutput",
|
|
42
|
+
"clean": "run -T rimraf ./dist",
|
|
43
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
36
44
|
"test:unit": "run -T jest",
|
|
37
45
|
"test:unit:watch": "run -T jest --watch",
|
|
38
46
|
"lint": "run -T eslint ."
|
|
@@ -45,9 +53,16 @@
|
|
|
45
53
|
"p-map": "4.0.0",
|
|
46
54
|
"yup": "0.32.9"
|
|
47
55
|
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/koa": "2.13.4",
|
|
58
|
+
"eslint-config-custom": "4.12.0-beta.0",
|
|
59
|
+
"koa": "2.13.4",
|
|
60
|
+
"koa-body": "4.2.0",
|
|
61
|
+
"tsconfig": "4.12.0-beta.0"
|
|
62
|
+
},
|
|
48
63
|
"engines": {
|
|
49
64
|
"node": ">=14.19.1 <=18.x.x",
|
|
50
65
|
"npm": ">=6.0.0"
|
|
51
66
|
},
|
|
52
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "b965b428a445bdbc81fb4b70120237f2d48e7647"
|
|
53
68
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
package/index.d.ts
DELETED
package/lib/async.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CurriedFunction3 } from 'lodash';
|
|
2
|
-
|
|
3
|
-
export type MapAsync<T = any, R = any> = CurriedFunction3<
|
|
4
|
-
T[],
|
|
5
|
-
(element: T, index: number) => R | Promise<R>,
|
|
6
|
-
{ concurrency?: number },
|
|
7
|
-
Promise<R[]>
|
|
8
|
-
>;
|
|
9
|
-
|
|
10
|
-
export type ForEachAsync<T = any, R = any> = (
|
|
11
|
-
array: T[],
|
|
12
|
-
func: (element: T, index: number) => R | Promise<R>,
|
|
13
|
-
options?: { concurrency?: number }
|
|
14
|
-
) => Promise<R[]>;
|
|
15
|
-
|
|
16
|
-
export type ReduceAsync<T = any, V = T, R = V> = CurriedFunction3<
|
|
17
|
-
T[],
|
|
18
|
-
(accumulator: V | R, current: Awaited<T>, index: number) => R | Promise<R>,
|
|
19
|
-
V,
|
|
20
|
-
Promise<R>
|
|
21
|
-
>;
|
package/lib/async.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const pMap = require('p-map');
|
|
4
|
-
const { curry, curryN } = require('lodash/fp');
|
|
5
|
-
|
|
6
|
-
function pipeAsync(...methods) {
|
|
7
|
-
return async (data) => {
|
|
8
|
-
let res = data;
|
|
9
|
-
for (let i = 0; i < methods.length; i += 1) {
|
|
10
|
-
res = await methods[i](res);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return res;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @type { import('./async').MapAsync }
|
|
19
|
-
*/
|
|
20
|
-
const mapAsync = curry(pMap);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @type { import('./async').ReduceAsync }
|
|
24
|
-
*/
|
|
25
|
-
const reduceAsync = curryN(2, async (mixedArray, iteratee, initialValue) => {
|
|
26
|
-
let acc = initialValue;
|
|
27
|
-
for (let i = 0; i < mixedArray.length; i += 1) {
|
|
28
|
-
acc = await iteratee(acc, await mixedArray[i], i);
|
|
29
|
-
}
|
|
30
|
-
return acc;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @type { import('./async').ForEachAsync }
|
|
35
|
-
*/
|
|
36
|
-
const forEachAsync = curry(async (array, func, options) => {
|
|
37
|
-
await mapAsync(array, func, options);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
mapAsync,
|
|
42
|
-
reduceAsync,
|
|
43
|
-
forEachAsync,
|
|
44
|
-
pipeAsync,
|
|
45
|
-
};
|
package/lib/build-query.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// TODO: move to dbal
|
|
4
|
-
|
|
5
|
-
const _ = require('lodash');
|
|
6
|
-
const parseType = require('./parse-type');
|
|
7
|
-
|
|
8
|
-
const isAttribute = (model, field) =>
|
|
9
|
-
_.has(model.allAttributes, field) || model.primaryKey === field || field === 'id';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns the model, attribute name and association from a path of relation
|
|
13
|
-
* @param {Object} options - Options
|
|
14
|
-
* @param {Object} options.model - Strapi model
|
|
15
|
-
* @param {string} options.field - path of relation / attribute
|
|
16
|
-
*/
|
|
17
|
-
const getAssociationFromFieldKey = ({ model, field }) => {
|
|
18
|
-
const fieldParts = field.split('.');
|
|
19
|
-
|
|
20
|
-
let tmpModel = model;
|
|
21
|
-
let association;
|
|
22
|
-
let attribute;
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < fieldParts.length; i += 1) {
|
|
25
|
-
const part = fieldParts[i];
|
|
26
|
-
attribute = part;
|
|
27
|
-
|
|
28
|
-
const assoc = tmpModel.associations.find((ast) => ast.alias === part);
|
|
29
|
-
|
|
30
|
-
if (assoc) {
|
|
31
|
-
association = assoc;
|
|
32
|
-
tmpModel = strapi.db.getModelByAssoc(assoc);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!assoc && (!isAttribute(tmpModel, part) || i !== fieldParts.length - 1)) {
|
|
37
|
-
const err = new Error(
|
|
38
|
-
`Your filters contain a field '${field}' that doesn't appear on your model definition nor its relations`
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
err.status = 400;
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
association,
|
|
48
|
-
model: tmpModel,
|
|
49
|
-
attribute,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Cast an input value
|
|
55
|
-
* @param {Object} options - Options
|
|
56
|
-
* @param {string} options.type - type of the atribute
|
|
57
|
-
* @param {*} options.value - value tu cast
|
|
58
|
-
* @param {string} options.operator - name of operator
|
|
59
|
-
*/
|
|
60
|
-
const castInput = ({ type, value, operator }) => {
|
|
61
|
-
return Array.isArray(value)
|
|
62
|
-
? value.map((val) => castValue({ type, operator, value: val }))
|
|
63
|
-
: castValue({ type, operator, value });
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Cast basic values based on attribute type
|
|
68
|
-
* @param {Object} options - Options
|
|
69
|
-
* @param {string} options.type - type of the atribute
|
|
70
|
-
* @param {*} options.value - value tu cast
|
|
71
|
-
* @param {string} options.operator - name of operator
|
|
72
|
-
*/
|
|
73
|
-
const castValue = ({ type, value, operator }) => {
|
|
74
|
-
if (operator === 'null') return parseType({ type: 'boolean', value });
|
|
75
|
-
return parseType({ type, value });
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {Object} options - Options
|
|
81
|
-
* @param {string} options.model - The model
|
|
82
|
-
* @param {string} options.field - path of relation / attribute
|
|
83
|
-
*/
|
|
84
|
-
const normalizeFieldName = ({ model, field }) => {
|
|
85
|
-
const fieldPath = field.split('.');
|
|
86
|
-
return _.last(fieldPath) === 'id'
|
|
87
|
-
? _.initial(fieldPath).concat(model.primaryKey).join('.')
|
|
88
|
-
: fieldPath.join('.');
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const BOOLEAN_OPERATORS = ['or', 'and'];
|
|
92
|
-
|
|
93
|
-
const hasDeepFilters = ({ where = [], sort = [] }, { minDepth = 1 } = {}) => {
|
|
94
|
-
// A query uses deep filtering if some of the clauses contains a sort or a match expression on a field of a relation
|
|
95
|
-
|
|
96
|
-
// We don't use minDepth here because deep sorting is limited to depth 1
|
|
97
|
-
const hasDeepSortClauses = sort.some(({ field }) => field.includes('.'));
|
|
98
|
-
|
|
99
|
-
const hasDeepWhereClauses = where.some(({ field, operator, value }) => {
|
|
100
|
-
if (BOOLEAN_OPERATORS.includes(operator)) {
|
|
101
|
-
return value.some((clauses) => hasDeepFilters({ where: clauses }));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return field.split('.').length > minDepth;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return hasDeepSortClauses || hasDeepWhereClauses;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const normalizeWhereClauses = (whereClauses, { model }) => {
|
|
111
|
-
return whereClauses
|
|
112
|
-
.filter(({ field, value }) => {
|
|
113
|
-
if (_.isNull(value)) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
if (_.isUndefined(value)) {
|
|
117
|
-
strapi.log.warn(`The value of field: '${field}', in your where filter, is undefined.`);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
})
|
|
122
|
-
.map(({ field, operator, value }) => {
|
|
123
|
-
if (BOOLEAN_OPERATORS.includes(operator)) {
|
|
124
|
-
return {
|
|
125
|
-
field,
|
|
126
|
-
operator,
|
|
127
|
-
value: value.map((clauses) => normalizeWhereClauses(clauses, { model })),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const { model: assocModel, attribute } = getAssociationFromFieldKey({
|
|
132
|
-
model,
|
|
133
|
-
field,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const { type } = _.get(assocModel, ['allAttributes', attribute], {});
|
|
137
|
-
|
|
138
|
-
// cast value or array of values
|
|
139
|
-
const castedValue = castInput({ type, operator, value });
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
field: normalizeFieldName({ model, field }),
|
|
143
|
-
operator,
|
|
144
|
-
value: castedValue,
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const normalizeSortClauses = (clauses, { model }) => {
|
|
150
|
-
const normalizedClauses = clauses.map(({ field, order }) => ({
|
|
151
|
-
field: normalizeFieldName({ model, field }),
|
|
152
|
-
order,
|
|
153
|
-
}));
|
|
154
|
-
|
|
155
|
-
normalizedClauses.forEach(({ field }) => {
|
|
156
|
-
const fieldDepth = field.split('.').length - 1;
|
|
157
|
-
if (fieldDepth === 1) {
|
|
158
|
-
// Check if the relational field exists
|
|
159
|
-
getAssociationFromFieldKey({ model, field });
|
|
160
|
-
} else if (fieldDepth > 1) {
|
|
161
|
-
const err = new Error(
|
|
162
|
-
`Sorting on ${field} is not possible: you cannot sort at a depth greater than 1`
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
err.status = 400;
|
|
166
|
-
throw err;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
return normalizedClauses;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
*
|
|
175
|
-
* @param {Object} options - Options
|
|
176
|
-
* @param {Object} options.model - The model for which the query will be built
|
|
177
|
-
* @param {Object} options.filters - The filters for the query (start, sort, limit, and where clauses)
|
|
178
|
-
* @param {Object} options.rest - In case the database layer requires any other params pass them
|
|
179
|
-
*/
|
|
180
|
-
const buildQuery = ({ model, filters = {}, ...rest }) => {
|
|
181
|
-
const { where, sort } = filters;
|
|
182
|
-
|
|
183
|
-
// Validate query clauses
|
|
184
|
-
if ([where, sort].some(Array.isArray)) {
|
|
185
|
-
if (hasDeepFilters({ where, sort }, { minDepth: 2 })) {
|
|
186
|
-
strapi.log.warn(
|
|
187
|
-
'Deep filtering queries should be used carefully (e.g Can cause performance issues).\nWhen possible build custom routes which will in most case be more optimised.'
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (sort) {
|
|
192
|
-
filters.sort = normalizeSortClauses(sort, { model });
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (where) {
|
|
196
|
-
// Cast where clauses to match the inner types
|
|
197
|
-
filters.where = normalizeWhereClauses(where, { model });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// call the ORM's buildQuery implementation
|
|
202
|
-
return strapi.db.connectors.get(model.orm).buildQuery({ model, filters, ...rest });
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
module.exports = {
|
|
206
|
-
buildQuery,
|
|
207
|
-
hasDeepFilters,
|
|
208
|
-
};
|
package/lib/code-generator.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Using timestamp (milliseconds) to be sure it is unique
|
|
4
|
-
// + converting timestamp to base 36 for better readibility
|
|
5
|
-
const generateTimestampCode = (date) => {
|
|
6
|
-
const referDate = date || new Date();
|
|
7
|
-
|
|
8
|
-
return referDate.getTime().toString(36);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
generateTimestampCode,
|
|
13
|
-
};
|
package/lib/config.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const { getCommonPath } = require('./string-formatting');
|
|
5
|
-
|
|
6
|
-
const getConfigUrls = (config, forAdminBuild = false) => {
|
|
7
|
-
const serverConfig = config.get('server');
|
|
8
|
-
const adminConfig = config.get('admin');
|
|
9
|
-
|
|
10
|
-
// Defines serverUrl value
|
|
11
|
-
let serverUrl = _.get(serverConfig, 'url', '');
|
|
12
|
-
serverUrl = _.trim(serverUrl, '/ ');
|
|
13
|
-
if (typeof serverUrl !== 'string') {
|
|
14
|
-
throw new Error('Invalid server url config. Make sure the url is a string.');
|
|
15
|
-
}
|
|
16
|
-
if (serverUrl.startsWith('http')) {
|
|
17
|
-
try {
|
|
18
|
-
serverUrl = _.trim(new URL(serverConfig.url).toString(), '/');
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
'Invalid server url config. Make sure the url defined in server.js is valid.'
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
} else if (serverUrl !== '') {
|
|
25
|
-
serverUrl = `/${serverUrl}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Defines adminUrl value
|
|
29
|
-
let adminUrl = _.get(adminConfig, 'url', '/admin');
|
|
30
|
-
adminUrl = _.trim(adminUrl, '/ ');
|
|
31
|
-
if (typeof adminUrl !== 'string') {
|
|
32
|
-
throw new Error('Invalid admin url config. Make sure the url is a non-empty string.');
|
|
33
|
-
}
|
|
34
|
-
if (adminUrl.startsWith('http')) {
|
|
35
|
-
try {
|
|
36
|
-
adminUrl = _.trim(new URL(adminUrl).toString(), '/');
|
|
37
|
-
} catch (e) {
|
|
38
|
-
throw new Error('Invalid admin url config. Make sure the url defined in server.js is valid.');
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
adminUrl = `${serverUrl}/${adminUrl}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Defines adminPath value
|
|
45
|
-
let adminPath = adminUrl;
|
|
46
|
-
if (
|
|
47
|
-
serverUrl.startsWith('http') &&
|
|
48
|
-
adminUrl.startsWith('http') &&
|
|
49
|
-
new URL(adminUrl).origin === new URL(serverUrl).origin &&
|
|
50
|
-
!forAdminBuild
|
|
51
|
-
) {
|
|
52
|
-
adminPath = adminUrl.replace(getCommonPath(serverUrl, adminUrl), '');
|
|
53
|
-
adminPath = `/${_.trim(adminPath, '/')}`;
|
|
54
|
-
} else if (adminUrl.startsWith('http')) {
|
|
55
|
-
adminPath = new URL(adminUrl).pathname;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
serverUrl,
|
|
60
|
-
adminUrl,
|
|
61
|
-
adminPath,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getAbsoluteUrl =
|
|
66
|
-
(adminOrServer) =>
|
|
67
|
-
(config, forAdminBuild = false) => {
|
|
68
|
-
const { serverUrl, adminUrl } = getConfigUrls(config, forAdminBuild);
|
|
69
|
-
const url = adminOrServer === 'server' ? serverUrl : adminUrl;
|
|
70
|
-
|
|
71
|
-
if (url.startsWith('http')) {
|
|
72
|
-
return url;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const hostname =
|
|
76
|
-
config.get('environment') === 'development' &&
|
|
77
|
-
['127.0.0.1', '0.0.0.0'].includes(config.get('server.host'))
|
|
78
|
-
? 'localhost'
|
|
79
|
-
: config.get('server.host');
|
|
80
|
-
|
|
81
|
-
return `http://${hostname}:${config.get('server.port')}${url}`;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
module.exports = {
|
|
85
|
-
getConfigUrls,
|
|
86
|
-
getAbsoluteAdminUrl: getAbsoluteUrl('admin'),
|
|
87
|
-
getAbsoluteServerUrl: getAbsoluteUrl('server'),
|
|
88
|
-
};
|