@strapi/utils 5.61.0 → 5.62.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/email-regex.d.ts +2 -0
- package/dist/email-regex.d.ts.map +1 -0
- package/dist/email-regex.js +17 -0
- package/dist/email-regex.js.map +1 -0
- package/dist/email-regex.mjs +15 -0
- package/dist/email-regex.mjs.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +35 -0
- package/dist/errors.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/pagination.d.ts +9 -5
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +2 -1
- package/dist/pagination.js.map +1 -1
- package/dist/pagination.mjs +2 -1
- package/dist/pagination.mjs.map +1 -1
- package/dist/sanitize/index.d.ts +2 -2
- package/dist/sanitize/index.d.ts.map +1 -1
- package/dist/sanitize/index.js.map +1 -1
- package/dist/sanitize/index.mjs.map +1 -1
- package/dist/sanitize/sanitizers.d.ts +3 -3
- package/dist/sanitize/sanitizers.d.ts.map +1 -1
- package/dist/sanitize/sanitizers.js +13 -11
- package/dist/sanitize/sanitizers.js.map +1 -1
- package/dist/sanitize/sanitizers.mjs +13 -11
- package/dist/sanitize/sanitizers.mjs.map +1 -1
- package/dist/traverse/factory.d.ts +7 -0
- package/dist/traverse/factory.d.ts.map +1 -1
- package/dist/traverse/factory.js +18 -4
- package/dist/traverse/factory.js.map +1 -1
- package/dist/traverse/factory.mjs +18 -4
- package/dist/traverse/factory.mjs.map +1 -1
- package/dist/traverse/query-populate.d.ts.map +1 -1
- package/dist/traverse/query-populate.js +47 -13
- package/dist/traverse/query-populate.js.map +1 -1
- package/dist/traverse/query-populate.mjs +47 -13
- package/dist/traverse/query-populate.mjs.map +1 -1
- package/dist/traverse-entity.d.ts +5 -5
- package/dist/traverse-entity.d.ts.map +1 -1
- package/dist/traverse-entity.js.map +1 -1
- package/dist/traverse-entity.mjs.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validate/index.d.ts +2 -2
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/index.mjs.map +1 -1
- package/dist/validate/validators.d.ts.map +1 -1
- package/dist/validate/validators.js +12 -12
- package/dist/validate/validators.js.map +1 -1
- package/dist/validate/validators.mjs +12 -12
- package/dist/validate/validators.mjs.map +1 -1
- package/dist/yup.d.ts.map +1 -1
- package/dist/yup.js +17 -0
- package/dist/yup.js.map +1 -1
- package/dist/yup.mjs +17 -0
- package/dist/yup.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-regex.d.ts","sourceRoot":"","sources":["../src/email-regex.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,QAEm2B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// yup 0.32.9's email regex backtracks exponentially on some short inputs, so one request can block
|
|
4
|
+
// the event loop. This is the same pattern with two changes:
|
|
5
|
+
// - `.` is no longer allowed inside a domain label, only between labels. Labels are still split on
|
|
6
|
+
// `.`, so the only addresses this now rejects have an empty label, a label that starts or ends
|
|
7
|
+
// with `-`, `_` or `~`, or a top-level label that starts with a digit.
|
|
8
|
+
// - the quoted local part matches its characters with one class instead of overlapping
|
|
9
|
+
// alternatives, which the `i` flag made ambiguous for letters. It accepts exactly the same input.
|
|
10
|
+
//
|
|
11
|
+
// The admin keeps a copy of this pattern for the browser (`admin/src/utils/yupEmail.ts` in
|
|
12
|
+
// `@strapi/admin`); a test there checks the two stay identical.
|
|
13
|
+
const EMAIL_REGEX = // eslint-disable-next-line no-useless-escape, no-control-regex
|
|
14
|
+
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
15
|
+
|
|
16
|
+
exports.EMAIL_REGEX = EMAIL_REGEX;
|
|
17
|
+
//# sourceMappingURL=email-regex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-regex.js","sources":["../src/email-regex.ts"],"sourcesContent":["// yup 0.32.9's email regex backtracks exponentially on some short inputs, so one request can block\n// the event loop. This is the same pattern with two changes:\n// - `.` is no longer allowed inside a domain label, only between labels. Labels are still split on\n// `.`, so the only addresses this now rejects have an empty label, a label that starts or ends\n// with `-`, `_` or `~`, or a top-level label that starts with a digit.\n// - the quoted local part matches its characters with one class instead of overlapping\n// alternatives, which the `i` flag made ambiguous for letters. It accepts exactly the same input.\n//\n// The admin keeps a copy of this pattern for the browser (`admin/src/utils/yupEmail.ts` in\n// `@strapi/admin`); a test there checks the two stay identical.\nexport const EMAIL_REGEX =\n // eslint-disable-next-line no-useless-escape, no-control-regex\n /^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f\\x21\\x23-\\x5b\\x5d-\\x7e\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))$/i;\n"],"names":["EMAIL_REGEX"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA;AAEX;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// yup 0.32.9's email regex backtracks exponentially on some short inputs, so one request can block
|
|
2
|
+
// the event loop. This is the same pattern with two changes:
|
|
3
|
+
// - `.` is no longer allowed inside a domain label, only between labels. Labels are still split on
|
|
4
|
+
// `.`, so the only addresses this now rejects have an empty label, a label that starts or ends
|
|
5
|
+
// with `-`, `_` or `~`, or a top-level label that starts with a digit.
|
|
6
|
+
// - the quoted local part matches its characters with one class instead of overlapping
|
|
7
|
+
// alternatives, which the `i` flag made ambiguous for letters. It accepts exactly the same input.
|
|
8
|
+
//
|
|
9
|
+
// The admin keeps a copy of this pattern for the browser (`admin/src/utils/yupEmail.ts` in
|
|
10
|
+
// `@strapi/admin`); a test there checks the two stay identical.
|
|
11
|
+
const EMAIL_REGEX = // eslint-disable-next-line no-useless-escape, no-control-regex
|
|
12
|
+
/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
13
|
+
|
|
14
|
+
export { EMAIL_REGEX };
|
|
15
|
+
//# sourceMappingURL=email-regex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-regex.mjs","sources":["../src/email-regex.ts"],"sourcesContent":["// yup 0.32.9's email regex backtracks exponentially on some short inputs, so one request can block\n// the event loop. This is the same pattern with two changes:\n// - `.` is no longer allowed inside a domain label, only between labels. Labels are still split on\n// `.`, so the only addresses this now rejects have an empty label, a label that starts or ends\n// with `-`, `_` or `~`, or a top-level label that starts with a digit.\n// - the quoted local part matches its characters with one class instead of overlapping\n// alternatives, which the `i` flag made ambiguous for letters. It accepts exactly the same input.\n//\n// The admin keeps a copy of this pattern for the browser (`admin/src/utils/yupEmail.ts` in\n// `@strapi/admin`); a test there checks the two stay identical.\nexport const EMAIL_REGEX =\n // eslint-disable-next-line no-useless-escape, no-control-regex\n /^((([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+(\\.([a-z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f\\x21\\x23-\\x5b\\x5d-\\x7e\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|\\d|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))\\.)+(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])|(([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])([a-z]|\\d|-|_|~|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])*([a-z]|[\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF])))$/i;\n"],"names":["EMAIL_REGEX"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA;AAEX;;;;"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare class ApplicationError<TName extends string = 'ApplicationError', TMessa
|
|
|
4
4
|
name: TName;
|
|
5
5
|
details: TDetails;
|
|
6
6
|
message: TMessage;
|
|
7
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
7
8
|
constructor(message?: TMessage, details?: TDetails);
|
|
8
9
|
}
|
|
9
10
|
declare class ValidationError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<'ValidationError', TMessage, TDetails> {
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAoBxC,cAAM,gBAAgB,CACpB,KAAK,SAAS,MAAM,GAAG,kBAAkB,EACzC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,QAAQ,GAAG,OAAO,CAClB,SAAQ,KAAK;IACb,IAAI,EAAE,KAAK,CAAC;IAEZ,OAAO,EAAE,QAAQ,CAAC;IAElB,OAAO,EAAE,QAAQ,CAAC;IAMlB,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;gBAgBlD,OAAO,GAAsC,QAAQ,EACrD,OAAO,GAAE,QAAyB;CAOrC;AAED,cAAM,eAAe,CACnB,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,QAAQ,GAAG,OAAO,CAClB,SAAQ,gBAAgB,CAAC,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,CAAC;gBAKnD,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,QAA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,EAAE,OAAO,CAAC,EAAE,QAAQ;CAKrE;AAED,cAAM,cAAc,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CACjG,gBAAgB,EAChB,QAAQ,EACR,QAAQ,CACT;gBAMG,OAAO,GAAmD,QAAQ,EAClE,OAAO,CAAC,EAAE,QAAQ;CAOrB;AAED,cAAM,oBAAoB,CACxB,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,QAAQ,GAAG,OAAO,CAClB,SAAQ,gBAAgB,CAAC,sBAAsB,EAAE,QAAQ,EAAE,QAAQ,CAAC;gBAKxD,OAAO,GAAyB,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ;CAKzE;AAED,cAAM,WAAW,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAE,SAAQ,cAAc,CAC5F,aAAa,EACb,QAAQ,EACR,QAAQ,CACT;gBAKa,OAAO,GAAsB,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ;CAMtE;AAED,cAAM,mBAAmB,CACvB,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,QAAQ,GAAG,OAAO,CAClB,SAAQ,gBAAgB,CAAC,qBAAqB,EAAE,QAAQ,EAAE,QAAQ,CAAC;gBAKvD,OAAO,GAA4C,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ;CAK5F;AAED,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,mBAAmB,GACpB,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -3,7 +3,31 @@
|
|
|
3
3
|
var httpErrors = require('http-errors');
|
|
4
4
|
var formatYupError = require('./format-yup-error.js');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* An app can load two copies of `@strapi/utils` (packages on different
|
|
8
|
+
* versions), and `instanceof` fails between them. Each class brands its
|
|
9
|
+
* prototype with a registry symbol, shared by every copy, so `instanceof` can
|
|
10
|
+
* find the brand through the error's prototype chain instead.
|
|
11
|
+
*/ const BRAND_KEY = Symbol.for('strapi.errors.brandKey');
|
|
12
|
+
// Fixed ids, not `constructor.name`, which a bundler may rename.
|
|
13
|
+
const brand = (ErrorClass, id)=>{
|
|
14
|
+
const key = Symbol.for(`strapi.errors.class:${id}`);
|
|
15
|
+
Object.defineProperty(ErrorClass, BRAND_KEY, {
|
|
16
|
+
value: key
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(ErrorClass.prototype, key, {
|
|
19
|
+
value: true
|
|
20
|
+
});
|
|
21
|
+
};
|
|
6
22
|
/* ApplicationError */ class ApplicationError extends Error {
|
|
23
|
+
static [Symbol.hasInstance](value) {
|
|
24
|
+
// A class declared outside Strapi has no brand of its own.
|
|
25
|
+
if (!Object.hasOwn(this, BRAND_KEY)) {
|
|
26
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
27
|
+
}
|
|
28
|
+
const key = this[BRAND_KEY];
|
|
29
|
+
return typeof value === 'object' && value !== null && value[key] === true;
|
|
30
|
+
}
|
|
7
31
|
constructor(message = 'An application error occurred', details = {}){
|
|
8
32
|
super();
|
|
9
33
|
this.name = 'ApplicationError';
|
|
@@ -11,12 +35,14 @@ var formatYupError = require('./format-yup-error.js');
|
|
|
11
35
|
this.details = details;
|
|
12
36
|
}
|
|
13
37
|
}
|
|
38
|
+
brand(ApplicationError, 'ApplicationError');
|
|
14
39
|
class ValidationError extends ApplicationError {
|
|
15
40
|
constructor(message, details){
|
|
16
41
|
super(message, details);
|
|
17
42
|
this.name = 'ValidationError';
|
|
18
43
|
}
|
|
19
44
|
}
|
|
45
|
+
brand(ValidationError, 'ValidationError');
|
|
20
46
|
class YupValidationError extends ValidationError {
|
|
21
47
|
constructor(yupError, message){
|
|
22
48
|
super('Validation');
|
|
@@ -27,6 +53,7 @@ class YupValidationError extends ValidationError {
|
|
|
27
53
|
};
|
|
28
54
|
}
|
|
29
55
|
}
|
|
56
|
+
brand(YupValidationError, 'YupValidationError');
|
|
30
57
|
class PaginationError extends ApplicationError {
|
|
31
58
|
constructor(message = 'Invalid pagination', details){
|
|
32
59
|
super(message, details);
|
|
@@ -34,6 +61,7 @@ class PaginationError extends ApplicationError {
|
|
|
34
61
|
this.message = message;
|
|
35
62
|
}
|
|
36
63
|
}
|
|
64
|
+
brand(PaginationError, 'PaginationError');
|
|
37
65
|
class NotFoundError extends ApplicationError {
|
|
38
66
|
constructor(message = 'Entity not found', details){
|
|
39
67
|
super(message, details);
|
|
@@ -41,6 +69,7 @@ class NotFoundError extends ApplicationError {
|
|
|
41
69
|
this.message = message;
|
|
42
70
|
}
|
|
43
71
|
}
|
|
72
|
+
brand(NotFoundError, 'NotFoundError');
|
|
44
73
|
class ForbiddenError extends ApplicationError {
|
|
45
74
|
constructor(message = 'Forbidden access', details){
|
|
46
75
|
super(message, details);
|
|
@@ -48,6 +77,7 @@ class ForbiddenError extends ApplicationError {
|
|
|
48
77
|
this.message = message;
|
|
49
78
|
}
|
|
50
79
|
}
|
|
80
|
+
brand(ForbiddenError, 'ForbiddenError');
|
|
51
81
|
class UnauthorizedError extends ApplicationError {
|
|
52
82
|
constructor(message = 'Unauthorized', details){
|
|
53
83
|
super(message, details);
|
|
@@ -55,6 +85,7 @@ class UnauthorizedError extends ApplicationError {
|
|
|
55
85
|
this.message = message;
|
|
56
86
|
}
|
|
57
87
|
}
|
|
88
|
+
brand(UnauthorizedError, 'UnauthorizedError');
|
|
58
89
|
class RateLimitError extends ApplicationError {
|
|
59
90
|
constructor(message = 'Too many requests, please try again later.', details){
|
|
60
91
|
super(message, details);
|
|
@@ -63,6 +94,7 @@ class RateLimitError extends ApplicationError {
|
|
|
63
94
|
this.details = details || {};
|
|
64
95
|
}
|
|
65
96
|
}
|
|
97
|
+
brand(RateLimitError, 'RateLimitError');
|
|
66
98
|
class PayloadTooLargeError extends ApplicationError {
|
|
67
99
|
constructor(message = 'Entity too large', details){
|
|
68
100
|
super(message, details);
|
|
@@ -70,6 +102,7 @@ class PayloadTooLargeError extends ApplicationError {
|
|
|
70
102
|
this.message = message;
|
|
71
103
|
}
|
|
72
104
|
}
|
|
105
|
+
brand(PayloadTooLargeError, 'PayloadTooLargeError');
|
|
73
106
|
class PolicyError extends ForbiddenError {
|
|
74
107
|
constructor(message = 'Policy Failed', details){
|
|
75
108
|
super(message, details);
|
|
@@ -78,6 +111,7 @@ class PolicyError extends ForbiddenError {
|
|
|
78
111
|
this.details = details || {};
|
|
79
112
|
}
|
|
80
113
|
}
|
|
114
|
+
brand(PolicyError, 'PolicyError');
|
|
81
115
|
class NotImplementedError extends ApplicationError {
|
|
82
116
|
constructor(message = 'This feature is not implemented yet', details){
|
|
83
117
|
super(message, details);
|
|
@@ -85,6 +119,7 @@ class NotImplementedError extends ApplicationError {
|
|
|
85
119
|
this.message = message;
|
|
86
120
|
}
|
|
87
121
|
}
|
|
122
|
+
brand(NotImplementedError, 'NotImplementedError');
|
|
88
123
|
|
|
89
124
|
Object.defineProperty(exports, "HttpError", {
|
|
90
125
|
enumerable: true,
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport * as yup from 'yup';\nimport { HttpError } from 'http-errors';\nimport { formatYupErrors } from './format-yup-error';\n\n/* ApplicationError */\nclass ApplicationError<\n TName extends string = 'ApplicationError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends Error {\n name: TName;\n\n details: TDetails;\n\n message: TMessage;\n\n constructor(\n message = 'An application error occurred' as TMessage,\n details: TDetails = {} as TDetails\n ) {\n super();\n this.name = 'ApplicationError' as TName;\n this.message = message;\n this.details = details;\n }\n}\n\nclass ValidationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'ValidationError', TMessage, TDetails> {\n constructor(message: TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ValidationError';\n }\n}\n\ninterface YupFormattedError {\n path: string[];\n message: string;\n name: string;\n value: string;\n}\n\nclass YupValidationError<TMessage extends string = string> extends ValidationError<\n TMessage,\n { errors: YupFormattedError[] }\n> {\n constructor(yupError: yup.ValidationError, message?: TMessage) {\n super('Validation' as TMessage);\n const { errors, message: yupMessage } = formatYupErrors(yupError);\n this.message = message || (yupMessage as TMessage);\n this.details = { errors };\n }\n}\n\nclass PaginationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PaginationError', TMessage, TDetails> {\n constructor(message = 'Invalid pagination' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PaginationError';\n this.message = message;\n }\n}\n\nclass NotFoundError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'NotFoundError',\n TMessage,\n TDetails\n> {\n constructor(message = 'Entity not found' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotFoundError';\n this.message = message;\n }\n}\n\nclass ForbiddenError<\n TName extends string = 'ForbiddenError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<TName, TMessage, TDetails> {\n constructor(message = 'Forbidden access' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ForbiddenError' as TName;\n this.message = message;\n }\n}\n\nclass UnauthorizedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'UnauthorizedError', TMessage, TDetails> {\n constructor(message = 'Unauthorized' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'UnauthorizedError';\n this.message = message;\n }\n}\n\nclass RateLimitError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'RateLimitError',\n TMessage,\n TDetails\n> {\n constructor(\n message = 'Too many requests, please try again later.' as TMessage,\n details?: TDetails\n ) {\n super(message, details);\n this.name = 'RateLimitError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass PayloadTooLargeError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PayloadTooLargeError', TMessage, TDetails> {\n constructor(message = 'Entity too large' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PayloadTooLargeError';\n this.message = message;\n }\n}\n\nclass PolicyError<TMessage extends string = string, TDetails = unknown> extends ForbiddenError<\n 'PolicyError',\n TMessage,\n TDetails\n> {\n constructor(message = 'Policy Failed' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PolicyError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass NotImplementedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'NotImplementedError', TMessage, TDetails> {\n constructor(message = 'This feature is not implemented yet' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotImplementedError';\n this.message = message;\n }\n}\n\nexport {\n HttpError,\n ApplicationError,\n ValidationError,\n YupValidationError,\n PaginationError,\n NotFoundError,\n ForbiddenError,\n UnauthorizedError,\n RateLimitError,\n PayloadTooLargeError,\n PolicyError,\n NotImplementedError,\n};\n"],"names":["ApplicationError","Error","message","details","name","ValidationError","YupValidationError","yupError","errors","yupMessage","formatYupErrors","PaginationError","NotFoundError","ForbiddenError","UnauthorizedError","RateLimitError","PayloadTooLargeError","PolicyError","NotImplementedError"],"mappings":";;;;;AAMA,uBACA,MAAMA,gBAAAA,SAIIC,KAAAA,CAAAA;AAOR,IAAA,WAAA,CACEC,UAAU,+BAA2C,EACrDC,OAAAA,GAAoB,EAAc,CAClC;QACA,KAAK,EAAA;QACL,IAAI,CAACC,IAAI,GAAG,kBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACC,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;AAEA,MAAME,eAAAA,SAGIL,gBAAAA,CAAAA;IACR,WAAA,CAAYE,OAAiB,EAAEC,OAAkB,CAAE;AACjD,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,I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AACC,IAAI,GAAG,qBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport * as yup from 'yup';\nimport { HttpError } from 'http-errors';\nimport { formatYupErrors } from './format-yup-error';\n\n/**\n * An app can load two copies of `@strapi/utils` (packages on different\n * versions), and `instanceof` fails between them. Each class brands its\n * prototype with a registry symbol, shared by every copy, so `instanceof` can\n * find the brand through the error's prototype chain instead.\n */\nconst BRAND_KEY = Symbol.for('strapi.errors.brandKey');\n\n// Fixed ids, not `constructor.name`, which a bundler may rename.\nconst brand = (ErrorClass: { prototype: object }, id: string) => {\n const key = Symbol.for(`strapi.errors.class:${id}`);\n\n Object.defineProperty(ErrorClass, BRAND_KEY, { value: key });\n Object.defineProperty(ErrorClass.prototype, key, { value: true });\n};\n\n/* ApplicationError */\nclass ApplicationError<\n TName extends string = 'ApplicationError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends Error {\n name: TName;\n\n details: TDetails;\n\n message: TMessage;\n\n static {\n brand(this, 'ApplicationError');\n }\n\n static [Symbol.hasInstance](value: unknown): boolean {\n // A class declared outside Strapi has no brand of its own.\n if (!Object.hasOwn(this, BRAND_KEY)) {\n return Function.prototype[Symbol.hasInstance].call(this, value);\n }\n\n const key = (this as unknown as { [BRAND_KEY]: symbol })[BRAND_KEY];\n\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<symbol, unknown>)[key] === true\n );\n }\n\n constructor(\n message = 'An application error occurred' as TMessage,\n details: TDetails = {} as TDetails\n ) {\n super();\n this.name = 'ApplicationError' as TName;\n this.message = message;\n this.details = details;\n }\n}\n\nclass ValidationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'ValidationError', TMessage, TDetails> {\n static {\n brand(this, 'ValidationError');\n }\n\n constructor(message: TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ValidationError';\n }\n}\n\ninterface YupFormattedError {\n path: string[];\n message: string;\n name: string;\n value: string;\n}\n\nclass YupValidationError<TMessage extends string = string> extends ValidationError<\n TMessage,\n { errors: YupFormattedError[] }\n> {\n static {\n brand(this, 'YupValidationError');\n }\n\n constructor(yupError: yup.ValidationError, message?: TMessage) {\n super('Validation' as TMessage);\n const { errors, message: yupMessage } = formatYupErrors(yupError);\n this.message = message || (yupMessage as TMessage);\n this.details = { errors };\n }\n}\n\nclass PaginationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PaginationError', TMessage, TDetails> {\n static {\n brand(this, 'PaginationError');\n }\n\n constructor(message = 'Invalid pagination' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PaginationError';\n this.message = message;\n }\n}\n\nclass NotFoundError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'NotFoundError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'NotFoundError');\n }\n\n constructor(message = 'Entity not found' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotFoundError';\n this.message = message;\n }\n}\n\nclass ForbiddenError<\n TName extends string = 'ForbiddenError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<TName, TMessage, TDetails> {\n static {\n brand(this, 'ForbiddenError');\n }\n\n constructor(message = 'Forbidden access' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ForbiddenError' as TName;\n this.message = message;\n }\n}\n\nclass UnauthorizedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'UnauthorizedError', TMessage, TDetails> {\n static {\n brand(this, 'UnauthorizedError');\n }\n\n constructor(message = 'Unauthorized' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'UnauthorizedError';\n this.message = message;\n }\n}\n\nclass RateLimitError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'RateLimitError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'RateLimitError');\n }\n\n constructor(\n message = 'Too many requests, please try again later.' as TMessage,\n details?: TDetails\n ) {\n super(message, details);\n this.name = 'RateLimitError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass PayloadTooLargeError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PayloadTooLargeError', TMessage, TDetails> {\n static {\n brand(this, 'PayloadTooLargeError');\n }\n\n constructor(message = 'Entity too large' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PayloadTooLargeError';\n this.message = message;\n }\n}\n\nclass PolicyError<TMessage extends string = string, TDetails = unknown> extends ForbiddenError<\n 'PolicyError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'PolicyError');\n }\n\n constructor(message = 'Policy Failed' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PolicyError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass NotImplementedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'NotImplementedError', TMessage, TDetails> {\n static {\n brand(this, 'NotImplementedError');\n }\n\n constructor(message = 'This feature is not implemented yet' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotImplementedError';\n this.message = message;\n }\n}\n\nexport {\n HttpError,\n ApplicationError,\n ValidationError,\n YupValidationError,\n PaginationError,\n NotFoundError,\n ForbiddenError,\n UnauthorizedError,\n RateLimitError,\n PayloadTooLargeError,\n PolicyError,\n NotImplementedError,\n};\n"],"names":["BRAND_KEY","Symbol","for","brand","ErrorClass","id","key","Object","defineProperty","value","prototype","ApplicationError","Error","hasInstance","hasOwn","Function","call","message","details","name","ValidationError","YupValidationError","yupError","errors","yupMessage","formatYupErrors","PaginationError","NotFoundError","ForbiddenError","UnauthorizedError","RateLimitError","PayloadTooLargeError","PolicyError","NotImplementedError"],"mappings":";;;;;AAMA;;;;;AAKC,IACD,MAAMA,SAAAA,GAAYC,MAAAA,CAAOC,GAAG,CAAC,wBAAA,CAAA;AAE7B;AACA,MAAMC,KA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,cAAAA,CAAAA;AAS9E,IAAA,WAAA,CAAYX,OAAAA,GAAU,eAA2B,EAAEC,OAAkB,CAAE;AACrE,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,aAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACf,QAAA,IAAI,CAACC,OAAO,GAAGA,OAAAA,IAAY,EAAC;AAC9B,IAAA;AACF;AATIf,KAAAA,CANE6B,WAAAA,EAMU,aAAA,CAAA;AAWhB,MAAMC,mBAAAA,SAGItB,gBAAAA,CAAAA;AAKR,IAAA,WAAA,CAAYM,OAAAA,GAAU,qCAAiD,EAAEC,OAAkB,CAAE;AAC3F,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,qBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;AARId,KAAAA,CALE8B,mBAAAA,EAKU,qBAAA,CAAA;;;;;;;;;;;;;;;;;;"}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
export { HttpError } from 'http-errors';
|
|
2
2
|
import { formatYupErrors } from './format-yup-error.mjs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* An app can load two copies of `@strapi/utils` (packages on different
|
|
6
|
+
* versions), and `instanceof` fails between them. Each class brands its
|
|
7
|
+
* prototype with a registry symbol, shared by every copy, so `instanceof` can
|
|
8
|
+
* find the brand through the error's prototype chain instead.
|
|
9
|
+
*/ const BRAND_KEY = Symbol.for('strapi.errors.brandKey');
|
|
10
|
+
// Fixed ids, not `constructor.name`, which a bundler may rename.
|
|
11
|
+
const brand = (ErrorClass, id)=>{
|
|
12
|
+
const key = Symbol.for(`strapi.errors.class:${id}`);
|
|
13
|
+
Object.defineProperty(ErrorClass, BRAND_KEY, {
|
|
14
|
+
value: key
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(ErrorClass.prototype, key, {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
};
|
|
4
20
|
/* ApplicationError */ class ApplicationError extends Error {
|
|
21
|
+
static [Symbol.hasInstance](value) {
|
|
22
|
+
// A class declared outside Strapi has no brand of its own.
|
|
23
|
+
if (!Object.hasOwn(this, BRAND_KEY)) {
|
|
24
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
25
|
+
}
|
|
26
|
+
const key = this[BRAND_KEY];
|
|
27
|
+
return typeof value === 'object' && value !== null && value[key] === true;
|
|
28
|
+
}
|
|
5
29
|
constructor(message = 'An application error occurred', details = {}){
|
|
6
30
|
super();
|
|
7
31
|
this.name = 'ApplicationError';
|
|
@@ -9,12 +33,14 @@ import { formatYupErrors } from './format-yup-error.mjs';
|
|
|
9
33
|
this.details = details;
|
|
10
34
|
}
|
|
11
35
|
}
|
|
36
|
+
brand(ApplicationError, 'ApplicationError');
|
|
12
37
|
class ValidationError extends ApplicationError {
|
|
13
38
|
constructor(message, details){
|
|
14
39
|
super(message, details);
|
|
15
40
|
this.name = 'ValidationError';
|
|
16
41
|
}
|
|
17
42
|
}
|
|
43
|
+
brand(ValidationError, 'ValidationError');
|
|
18
44
|
class YupValidationError extends ValidationError {
|
|
19
45
|
constructor(yupError, message){
|
|
20
46
|
super('Validation');
|
|
@@ -25,6 +51,7 @@ class YupValidationError extends ValidationError {
|
|
|
25
51
|
};
|
|
26
52
|
}
|
|
27
53
|
}
|
|
54
|
+
brand(YupValidationError, 'YupValidationError');
|
|
28
55
|
class PaginationError extends ApplicationError {
|
|
29
56
|
constructor(message = 'Invalid pagination', details){
|
|
30
57
|
super(message, details);
|
|
@@ -32,6 +59,7 @@ class PaginationError extends ApplicationError {
|
|
|
32
59
|
this.message = message;
|
|
33
60
|
}
|
|
34
61
|
}
|
|
62
|
+
brand(PaginationError, 'PaginationError');
|
|
35
63
|
class NotFoundError extends ApplicationError {
|
|
36
64
|
constructor(message = 'Entity not found', details){
|
|
37
65
|
super(message, details);
|
|
@@ -39,6 +67,7 @@ class NotFoundError extends ApplicationError {
|
|
|
39
67
|
this.message = message;
|
|
40
68
|
}
|
|
41
69
|
}
|
|
70
|
+
brand(NotFoundError, 'NotFoundError');
|
|
42
71
|
class ForbiddenError extends ApplicationError {
|
|
43
72
|
constructor(message = 'Forbidden access', details){
|
|
44
73
|
super(message, details);
|
|
@@ -46,6 +75,7 @@ class ForbiddenError extends ApplicationError {
|
|
|
46
75
|
this.message = message;
|
|
47
76
|
}
|
|
48
77
|
}
|
|
78
|
+
brand(ForbiddenError, 'ForbiddenError');
|
|
49
79
|
class UnauthorizedError extends ApplicationError {
|
|
50
80
|
constructor(message = 'Unauthorized', details){
|
|
51
81
|
super(message, details);
|
|
@@ -53,6 +83,7 @@ class UnauthorizedError extends ApplicationError {
|
|
|
53
83
|
this.message = message;
|
|
54
84
|
}
|
|
55
85
|
}
|
|
86
|
+
brand(UnauthorizedError, 'UnauthorizedError');
|
|
56
87
|
class RateLimitError extends ApplicationError {
|
|
57
88
|
constructor(message = 'Too many requests, please try again later.', details){
|
|
58
89
|
super(message, details);
|
|
@@ -61,6 +92,7 @@ class RateLimitError extends ApplicationError {
|
|
|
61
92
|
this.details = details || {};
|
|
62
93
|
}
|
|
63
94
|
}
|
|
95
|
+
brand(RateLimitError, 'RateLimitError');
|
|
64
96
|
class PayloadTooLargeError extends ApplicationError {
|
|
65
97
|
constructor(message = 'Entity too large', details){
|
|
66
98
|
super(message, details);
|
|
@@ -68,6 +100,7 @@ class PayloadTooLargeError extends ApplicationError {
|
|
|
68
100
|
this.message = message;
|
|
69
101
|
}
|
|
70
102
|
}
|
|
103
|
+
brand(PayloadTooLargeError, 'PayloadTooLargeError');
|
|
71
104
|
class PolicyError extends ForbiddenError {
|
|
72
105
|
constructor(message = 'Policy Failed', details){
|
|
73
106
|
super(message, details);
|
|
@@ -76,6 +109,7 @@ class PolicyError extends ForbiddenError {
|
|
|
76
109
|
this.details = details || {};
|
|
77
110
|
}
|
|
78
111
|
}
|
|
112
|
+
brand(PolicyError, 'PolicyError');
|
|
79
113
|
class NotImplementedError extends ApplicationError {
|
|
80
114
|
constructor(message = 'This feature is not implemented yet', details){
|
|
81
115
|
super(message, details);
|
|
@@ -83,6 +117,7 @@ class NotImplementedError extends ApplicationError {
|
|
|
83
117
|
this.message = message;
|
|
84
118
|
}
|
|
85
119
|
}
|
|
120
|
+
brand(NotImplementedError, 'NotImplementedError');
|
|
86
121
|
|
|
87
122
|
export { ApplicationError, ForbiddenError, NotFoundError, NotImplementedError, PaginationError, PayloadTooLargeError, PolicyError, RateLimitError, UnauthorizedError, ValidationError, YupValidationError };
|
|
88
123
|
//# sourceMappingURL=errors.mjs.map
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","sources":["../src/errors.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport * as yup from 'yup';\nimport { HttpError } from 'http-errors';\nimport { formatYupErrors } from './format-yup-error';\n\n/* ApplicationError */\nclass ApplicationError<\n TName extends string = 'ApplicationError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends Error {\n name: TName;\n\n details: TDetails;\n\n message: TMessage;\n\n constructor(\n message = 'An application error occurred' as TMessage,\n details: TDetails = {} as TDetails\n ) {\n super();\n this.name = 'ApplicationError' as TName;\n this.message = message;\n this.details = details;\n }\n}\n\nclass ValidationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'ValidationError', TMessage, TDetails> {\n constructor(message: TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ValidationError';\n }\n}\n\ninterface YupFormattedError {\n path: string[];\n message: string;\n name: string;\n value: string;\n}\n\nclass YupValidationError<TMessage extends string = string> extends ValidationError<\n TMessage,\n { errors: YupFormattedError[] }\n> {\n constructor(yupError: yup.ValidationError, message?: TMessage) {\n super('Validation' as TMessage);\n const { errors, message: yupMessage } = formatYupErrors(yupError);\n this.message = message || (yupMessage as TMessage);\n this.details = { errors };\n }\n}\n\nclass PaginationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PaginationError', TMessage, TDetails> {\n constructor(message = 'Invalid pagination' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PaginationError';\n this.message = message;\n }\n}\n\nclass NotFoundError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'NotFoundError',\n TMessage,\n TDetails\n> {\n constructor(message = 'Entity not found' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotFoundError';\n this.message = message;\n }\n}\n\nclass ForbiddenError<\n TName extends string = 'ForbiddenError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<TName, TMessage, TDetails> {\n constructor(message = 'Forbidden access' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ForbiddenError' as TName;\n this.message = message;\n }\n}\n\nclass UnauthorizedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'UnauthorizedError', TMessage, TDetails> {\n constructor(message = 'Unauthorized' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'UnauthorizedError';\n this.message = message;\n }\n}\n\nclass RateLimitError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'RateLimitError',\n TMessage,\n TDetails\n> {\n constructor(\n message = 'Too many requests, please try again later.' as TMessage,\n details?: TDetails\n ) {\n super(message, details);\n this.name = 'RateLimitError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass PayloadTooLargeError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PayloadTooLargeError', TMessage, TDetails> {\n constructor(message = 'Entity too large' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PayloadTooLargeError';\n this.message = message;\n }\n}\n\nclass PolicyError<TMessage extends string = string, TDetails = unknown> extends ForbiddenError<\n 'PolicyError',\n TMessage,\n TDetails\n> {\n constructor(message = 'Policy Failed' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PolicyError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass NotImplementedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'NotImplementedError', TMessage, TDetails> {\n constructor(message = 'This feature is not implemented yet' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotImplementedError';\n this.message = message;\n }\n}\n\nexport {\n HttpError,\n ApplicationError,\n ValidationError,\n YupValidationError,\n PaginationError,\n NotFoundError,\n ForbiddenError,\n UnauthorizedError,\n RateLimitError,\n PayloadTooLargeError,\n PolicyError,\n NotImplementedError,\n};\n"],"names":["ApplicationError","Error","message","details","name","ValidationError","YupValidationError","yupError","errors","yupMessage","formatYupErrors","PaginationError","NotFoundError","ForbiddenError","UnauthorizedError","RateLimitError","PayloadTooLargeError","PolicyError","NotImplementedError"],"mappings":";;;AAMA,uBACA,MAAMA,gBAAAA,SAIIC,KAAAA,CAAAA;AAOR,IAAA,WAAA,CACEC,UAAU,+BAA2C,EACrDC,OAAAA,GAAoB,EAAc,CAClC;QACA,KAAK,EAAA;QACL,IAAI,CAACC,IAAI,GAAG,kBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACC,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;AAEA,MAAME,eAAAA,SAGIL,gBAAAA,CAAAA;IACR,WAAA,CAAYE,OAAiB,EAAEC,OAAkB,CAAE;AACjD,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,iBAAA;AACd,IAAA;AACF;AASA,MAAME,kBAAAA,SAA6DD,eAAAA,CAAAA;IAIjE,WAAA,CAAYE,QAA6B,EAAEL,OAAkB,CAAE;AAC7D,QAAA,KAAK,CAAC,YAAA,CAAA;AACN,QAAA,MAAM,EAAEM,MAAM,EAAEN,SAASO,UAAU,EAAE,GAAGC,eAAAA,CAAgBH,QAAAA,CAAAA;QACxD,IAAI,CAACL,OAAO,GAAGA,OAAA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AAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,gBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACf,QAAA,IAAI,CAACC,OAAO,GAAGA,OAAAA,IAAY,EAAC;AAC9B,IAAA;AACF;AAEA,MAAMa,oBAAAA,SAGIhB,gBAAAA,CAAAA;AACR,IAAA,WAAA,CAAYE,OAAAA,GAAU,kBAA8B,EAAEC,OAAkB,CAAE;AACxE,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,sBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;AAEA,MAAMe,WAAAA,SAA0EJ,cAAAA,CAAAA;AAK9E,IAAA,WAAA,CAAYX,OAAAA,GAAU,eAA2B,EAAEC,OAAkB,CAAE;AACrE,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,aAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACf,QAAA,IAAI,CAACC,OAAO,GAAGA,OAAAA,IAAY,EAAC;AAC9B,IAAA;AACF;AAEA,MAAMe,mBAAAA,SAGIlB,gBAAAA,CAAAA;AACR,IAAA,WAAA,CAAYE,OAAAA,GAAU,qCAAiD,EAAEC,OAAkB,CAAE;AAC3F,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,qBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","sources":["../src/errors.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport * as yup from 'yup';\nimport { HttpError } from 'http-errors';\nimport { formatYupErrors } from './format-yup-error';\n\n/**\n * An app can load two copies of `@strapi/utils` (packages on different\n * versions), and `instanceof` fails between them. Each class brands its\n * prototype with a registry symbol, shared by every copy, so `instanceof` can\n * find the brand through the error's prototype chain instead.\n */\nconst BRAND_KEY = Symbol.for('strapi.errors.brandKey');\n\n// Fixed ids, not `constructor.name`, which a bundler may rename.\nconst brand = (ErrorClass: { prototype: object }, id: string) => {\n const key = Symbol.for(`strapi.errors.class:${id}`);\n\n Object.defineProperty(ErrorClass, BRAND_KEY, { value: key });\n Object.defineProperty(ErrorClass.prototype, key, { value: true });\n};\n\n/* ApplicationError */\nclass ApplicationError<\n TName extends string = 'ApplicationError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends Error {\n name: TName;\n\n details: TDetails;\n\n message: TMessage;\n\n static {\n brand(this, 'ApplicationError');\n }\n\n static [Symbol.hasInstance](value: unknown): boolean {\n // A class declared outside Strapi has no brand of its own.\n if (!Object.hasOwn(this, BRAND_KEY)) {\n return Function.prototype[Symbol.hasInstance].call(this, value);\n }\n\n const key = (this as unknown as { [BRAND_KEY]: symbol })[BRAND_KEY];\n\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as Record<symbol, unknown>)[key] === true\n );\n }\n\n constructor(\n message = 'An application error occurred' as TMessage,\n details: TDetails = {} as TDetails\n ) {\n super();\n this.name = 'ApplicationError' as TName;\n this.message = message;\n this.details = details;\n }\n}\n\nclass ValidationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'ValidationError', TMessage, TDetails> {\n static {\n brand(this, 'ValidationError');\n }\n\n constructor(message: TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ValidationError';\n }\n}\n\ninterface YupFormattedError {\n path: string[];\n message: string;\n name: string;\n value: string;\n}\n\nclass YupValidationError<TMessage extends string = string> extends ValidationError<\n TMessage,\n { errors: YupFormattedError[] }\n> {\n static {\n brand(this, 'YupValidationError');\n }\n\n constructor(yupError: yup.ValidationError, message?: TMessage) {\n super('Validation' as TMessage);\n const { errors, message: yupMessage } = formatYupErrors(yupError);\n this.message = message || (yupMessage as TMessage);\n this.details = { errors };\n }\n}\n\nclass PaginationError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PaginationError', TMessage, TDetails> {\n static {\n brand(this, 'PaginationError');\n }\n\n constructor(message = 'Invalid pagination' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PaginationError';\n this.message = message;\n }\n}\n\nclass NotFoundError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'NotFoundError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'NotFoundError');\n }\n\n constructor(message = 'Entity not found' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotFoundError';\n this.message = message;\n }\n}\n\nclass ForbiddenError<\n TName extends string = 'ForbiddenError',\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<TName, TMessage, TDetails> {\n static {\n brand(this, 'ForbiddenError');\n }\n\n constructor(message = 'Forbidden access' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'ForbiddenError' as TName;\n this.message = message;\n }\n}\n\nclass UnauthorizedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'UnauthorizedError', TMessage, TDetails> {\n static {\n brand(this, 'UnauthorizedError');\n }\n\n constructor(message = 'Unauthorized' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'UnauthorizedError';\n this.message = message;\n }\n}\n\nclass RateLimitError<TMessage extends string = string, TDetails = unknown> extends ApplicationError<\n 'RateLimitError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'RateLimitError');\n }\n\n constructor(\n message = 'Too many requests, please try again later.' as TMessage,\n details?: TDetails\n ) {\n super(message, details);\n this.name = 'RateLimitError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass PayloadTooLargeError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'PayloadTooLargeError', TMessage, TDetails> {\n static {\n brand(this, 'PayloadTooLargeError');\n }\n\n constructor(message = 'Entity too large' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PayloadTooLargeError';\n this.message = message;\n }\n}\n\nclass PolicyError<TMessage extends string = string, TDetails = unknown> extends ForbiddenError<\n 'PolicyError',\n TMessage,\n TDetails\n> {\n static {\n brand(this, 'PolicyError');\n }\n\n constructor(message = 'Policy Failed' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'PolicyError';\n this.message = message;\n this.details = details || ({} as TDetails);\n }\n}\n\nclass NotImplementedError<\n TMessage extends string = string,\n TDetails = unknown,\n> extends ApplicationError<'NotImplementedError', TMessage, TDetails> {\n static {\n brand(this, 'NotImplementedError');\n }\n\n constructor(message = 'This feature is not implemented yet' as TMessage, details?: TDetails) {\n super(message, details);\n this.name = 'NotImplementedError';\n this.message = message;\n }\n}\n\nexport {\n HttpError,\n ApplicationError,\n ValidationError,\n YupValidationError,\n PaginationError,\n NotFoundError,\n ForbiddenError,\n UnauthorizedError,\n RateLimitError,\n PayloadTooLargeError,\n PolicyError,\n NotImplementedError,\n};\n"],"names":["BRAND_KEY","Symbol","for","brand","ErrorClass","id","key","Object","defineProperty","value","prototype","ApplicationError","Error","hasInstance","hasOwn","Function","call","message","details","name","ValidationError","YupValidationError","yupError","errors","yupMessage","formatYupErrors","PaginationError","NotFoundError","ForbiddenError","UnauthorizedError","RateLimitError","PayloadTooLargeError","PolicyError","NotImplementedError"],"mappings":";;;AAMA;;;;;AAKC,IACD,MAAMA,SAAAA,GAAYC,MAAAA,CAAOC,GAAG,CAAC,wBAAA,CAAA;AAE7B;AACA,MAAMC,KAAAA,GAAQ,CAACC,UAAAA,EAAmCC,EAAAA,GAAAA;AAChD,IAAA,MAAMC,MAAML,MAAAA,CAAOC,GAAG,CAAC,CAAC,oBAAoB,EAAEG,EAAAA,CAAAA,CAAI,CAAA;IAElDE,MAAAA,CAAOC,cAAc,CAACJ,UAAAA,EAAYJ,SAAAA,EAAW;QAAES,KAAAA,EAAOH;AAAI,KAAA,CAAA;AAC1DC,IAAAA,MAAAA,CAAOC,cAAc,CAACJ,UAAAA,CAAWM,SAAS,EAAEJ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,CAAA;AAWhB,MAAMC,mBAAAA,SAGItB,gBAAAA,CAAAA;AAKR,IAAA,WAAA,CAAYM,OAAAA,GAAU,qCAAiD,EAAEC,OAAkB,CAAE;AAC3F,QAAA,KAAK,CAACD,OAAAA,EAASC,OAAAA,CAAAA;QACf,IAAI,CAACC,IAAI,GAAG,qBAAA;QACZ,IAAI,CAACF,OAAO,GAAGA,OAAAA;AACjB,IAAA;AACF;AARId,KAAAA,CALE8B,mBAAAA,EAKU,qBAAA,CAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * as file from './file';
|
|
|
22
22
|
export * as async from './async';
|
|
23
23
|
export * as policy from './policy';
|
|
24
24
|
export * as yup from './yup';
|
|
25
|
+
export { EMAIL_REGEX } from './email-regex';
|
|
25
26
|
export * as errors from './errors';
|
|
26
27
|
export * as contentTypes from './content-types';
|
|
27
28
|
export * as relations from './relations';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;A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AAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,GACtB,MAAM,YAAY,CAAC;AAEpB,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var file = require('./file.js');
|
|
|
23
23
|
var async = require('./async.js');
|
|
24
24
|
var policy = require('./policy.js');
|
|
25
25
|
var yup = require('./yup.js');
|
|
26
|
+
var emailRegex = require('./email-regex.js');
|
|
26
27
|
var errors = require('./errors.js');
|
|
27
28
|
var contentTypes = require('./content-types.js');
|
|
28
29
|
var relations = require('./relations.js');
|
|
@@ -95,6 +96,7 @@ exports.file = file;
|
|
|
95
96
|
exports.async = async;
|
|
96
97
|
exports.policy = policy;
|
|
97
98
|
exports.yup = yup;
|
|
99
|
+
exports.EMAIL_REGEX = emailRegex.EMAIL_REGEX;
|
|
98
100
|
exports.errors = errors;
|
|
99
101
|
exports.contentTypes = contentTypes;
|
|
100
102
|
exports.relations = relations;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,7 @@ import * as policy from './policy.mjs';
|
|
|
32
32
|
export { policy };
|
|
33
33
|
import * as yup from './yup.mjs';
|
|
34
34
|
export { yup };
|
|
35
|
+
export { EMAIL_REGEX } from './email-regex.mjs';
|
|
35
36
|
import * as errors from './errors.mjs';
|
|
36
37
|
export { errors };
|
|
37
38
|
import * as contentTypes from './content-types.mjs';
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/pagination.d.ts
CHANGED
|
@@ -19,13 +19,17 @@ export interface OffsetPaginationInformation {
|
|
|
19
19
|
limit: number;
|
|
20
20
|
total: number;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Pagination arguments as they arrive from a query string: values are numbers or numeric strings
|
|
24
|
+
* (e.g. `?pagination[page]=2`). `withDefaultPagination` always returns numbers.
|
|
25
|
+
*/
|
|
26
|
+
type PaginationInput = {
|
|
27
|
+
[K in keyof PaginationArgs]?: PaginationArgs[K] | string;
|
|
28
|
+
};
|
|
29
|
+
declare const withDefaultPagination: <T extends PaginationInput>(args: T, { defaults, maxLimit }?: {
|
|
23
30
|
defaults?: {} | undefined;
|
|
24
31
|
maxLimit?: number | undefined;
|
|
25
|
-
}) =>
|
|
26
|
-
start: number;
|
|
27
|
-
limit: number;
|
|
28
|
-
} & Partial<T>;
|
|
32
|
+
}) => Omit<Partial<T>, keyof PaginationArgs> & Pagination;
|
|
29
33
|
/**
|
|
30
34
|
* Transform pagination information into a paginated response:
|
|
31
35
|
* {
|
package/dist/pagination.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAGA,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,M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A6B,EAAE,CAAC"}
|
package/dist/pagination.js
CHANGED
|
@@ -35,9 +35,10 @@ const ensureMaxValues = (maxLimit = -1)=>({ start, limit })=>({
|
|
|
35
35
|
limit: withMaxLimit(limit, maxLimit)
|
|
36
36
|
});
|
|
37
37
|
// Apply maxLimit as the limit when limit is -1
|
|
38
|
+
// The limit can be the raw query string, e.g. '-1' from `?pagination[limit]=-1`
|
|
38
39
|
const withNoLimit = (pagination, maxLimit = -1)=>({
|
|
39
40
|
...pagination,
|
|
40
|
-
limit: pagination.limit === -1 ? maxLimit : pagination.limit
|
|
41
|
+
limit: Number(pagination.limit) === -1 ? maxLimit : pagination.limit
|
|
41
42
|
});
|
|
42
43
|
const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {})=>{
|
|
43
44
|
const defaultValues = _.merge({}, STRAPI_DEFAULTS, defaults);
|
package/dist/pagination.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","sources":["../src/pagination.ts"],"sourcesContent":["import { merge, flow, omit } from 'lodash';\nimport { PaginationError } from './errors';\n\ninterface PaginationArgs {\n page: number;\n pageSize: number | null;\n start: number;\n limit: number;\n}\n\nexport interface Pagination {\n start: number;\n limit: number;\n}\n\nexport interface PagePatinationInformation {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n}\n\nexport interface OffsetPaginationInformation {\n start: number;\n limit: number;\n total: number;\n}\n\nconst STRAPI_DEFAULTS = {\n offset: {\n start: 0,\n limit: 10,\n },\n page: {\n page: 1,\n pageSize: 10,\n },\n};\n\nconst paginationAttributes = ['start', 'limit', 'page', 'pageSize'];\n\nconst withMaxLimit = (limit: number, maxLimit = -1) => {\n if (maxLimit === -1 || limit < maxLimit) {\n return limit;\n }\n\n return maxLimit;\n};\n\n// Ensure minimum page & pageSize values (page >= 1, pageSize >= 0, start >= 0, limit >= 0)\nconst ensureMinValues = ({ start, limit }: Pagination) => ({\n start: Math.max(start, 0),\n limit: limit === -1 ? limit : Math.max(limit, 1),\n});\n\nconst ensureMaxValues =\n (maxLimit = -1) =>\n ({ start, limit }: { start: number; limit: number }) => ({\n start,\n limit: withMaxLimit(limit, maxLimit),\n });\n\n// Apply maxLimit as the limit when limit is -1\nconst withNoLimit = (pagination: Pagination, maxLimit = -1) => ({\n ...pagination,\n limit: pagination.limit === -1 ? maxLimit : pagination.limit,\n});\n\nconst withDefaultPagination = <T extends Partial<PaginationArgs>>(\n args: T,\n { defaults = {}, maxLimit = -1 } = {}\n) => {\n const defaultValues = merge({}, STRAPI_DEFAULTS, defaults);\n\n const usePagePagination = args.page != null || args.pageSize != null;\n const useOffsetPagination = args.start != null || args.limit != null;\n\n const ensureValidValues = flow(ensureMinValues, ensureMaxValues(maxLimit));\n\n // If there is no pagination attribute, don't modify the payload\n if (!usePagePagination && !useOffsetPagination) {\n return merge({}, args, ensureValidValues(defaultValues.offset));\n }\n\n // If there is page & offset pagination attributes, throw an error\n if (usePagePagination && useOffsetPagination) {\n throw new PaginationError('Cannot use both page & offset pagination in the same query');\n }\n\n const pagination: Pagination = {\n start: 0,\n limit: 0,\n };\n\n // Start / Limit\n if (useOffsetPagination) {\n const { start, limit } = merge({}, defaultValues.offset, args);\n\n Object.assign(pagination, { start, limit });\n }\n\n // Page / PageSize\n if (usePagePagination) {\n const pageArgs =\n args.pageSize == null\n ? omit(args, ['pageSize'])\n : { ...args, pageSize: Math.max(1, args.pageSize) };\n const { page, pageSize } = merge({}, defaultValues.page, pageArgs);\n const pageLimit = ensureValidValues({ start: 0, limit: pageSize }).limit;\n\n Object.assign(pagination, {\n start: (page - 1) * pageLimit,\n limit: pageLimit,\n });\n }\n\n // Handle -1 limit\n Object.assign(pagination, withNoLimit(pagination, maxLimit));\n\n return merge({}, ensureValidValues(pagination), omit(args, paginationAttributes));\n};\n\n/**\n * Transform pagination information into a paginated response:\n * {\n * page: number,\n * pageSize: number,\n * pageCount: number,\n * total: number\n * }\n */\nconst transformPagedPaginationInfo = (\n paginationInfo: Partial<PaginationArgs>,\n total: number\n): PagePatinationInformation => {\n if (paginationInfo.page != null) {\n const page = paginationInfo.page;\n const pageSize = paginationInfo.pageSize ?? total;\n\n return {\n page,\n pageSize,\n pageCount: pageSize > 0 ? Math.ceil(total / pageSize) : 0,\n total,\n };\n }\n\n if (paginationInfo.start != null) {\n const start = paginationInfo.start;\n const limit = paginationInfo.limit ?? total;\n\n // Start limit to page page size\n return {\n page: Math.floor(start / limit) + 1,\n pageSize: limit,\n pageCount: limit > 0 ? Math.ceil(total / limit) : 0,\n total,\n };\n }\n\n // Default pagination\n return {\n ...paginationInfo,\n page: 1,\n pageSize: 10,\n pageCount: 1,\n total,\n };\n};\n\n/**\n * Transform pagination information into a offset response:\n * {\n * start: number,\n * limit: number,\n * total: number\n * }\n */\nconst transformOffsetPaginationInfo = (\n paginationInfo: Partial<PaginationArgs>,\n total: number\n): OffsetPaginationInformation => {\n if (paginationInfo.page != null) {\n const limit = paginationInfo.pageSize ?? total;\n const start = (paginationInfo.page - 1) * limit;\n\n return { start, limit, total };\n }\n\n if (paginationInfo.start != null) {\n const start = paginationInfo.start;\n const limit = paginationInfo.limit ?? total;\n\n // Start limit to page page size\n return { start, limit, total };\n }\n\n // Default pagination\n return {\n ...paginationInfo,\n start: 0,\n limit: 10,\n total,\n };\n};\n\nexport { withDefaultPagination, transformPagedPaginationInfo, transformOffsetPaginationInfo };\n"],"names":["STRAPI_DEFAULTS","offset","start","limit","page","pageSize","paginationAttributes","withMaxLimit","maxLimit","ensureMinValues","Math","max","ensureMaxValues","withNoLimit","pagination","withDefaultPagination","args","defaults","defaultValues","merge","usePagePagination","useOffsetPagination","ensureValidValues","flow","PaginationError","Object","assign","pageArgs","omit","pageLimit","transformPagedPaginationInfo","paginationInfo","total","pageCount","ceil","floor","transformOffsetPaginationInfo"],"mappings":";;;;;AA4BA,MAAMA,eAAAA,GAAkB;IACtBC,MAAAA,EAAQ;QACNC,KAAAA,EAAO,CAAA;QACPC,KAAAA,EAAO;AACT,KA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AACP6B,QAAAA;AACF,KAAA;AACF;;;;;;"}
|
|
1
|
+
{"version":3,"file":"pagination.js","sources":["../src/pagination.ts"],"sourcesContent":["import { merge, flow, omit } from 'lodash';\nimport { PaginationError } from './errors';\n\ninterface PaginationArgs {\n page: number;\n pageSize: number | null;\n start: number;\n limit: number;\n}\n\nexport interface Pagination {\n start: number;\n limit: number;\n}\n\nexport interface PagePatinationInformation {\n page: number;\n pageSize: number;\n pageCount: number;\n total: number;\n}\n\nexport interface OffsetPaginationInformation {\n start: number;\n limit: number;\n total: number;\n}\n\nconst STRAPI_DEFAULTS = {\n offset: {\n start: 0,\n limit: 10,\n },\n page: {\n page: 1,\n pageSize: 10,\n },\n};\n\n/**\n * Pagination arguments as they arrive from a query string: values are numbers or numeric strings\n * (e.g. `?pagination[page]=2`). `withDefaultPagination` always returns numbers.\n */\ntype PaginationInput = {\n [K in keyof PaginationArgs]?: PaginationArgs[K] | string;\n};\n\nconst paginationAttributes = ['start', 'limit', 'page', 'pageSize'];\n\nconst withMaxLimit = (limit: number, maxLimit = -1) => {\n if (maxLimit === -1 || limit < maxLimit) {\n return limit;\n }\n\n return maxLimit;\n};\n\n// Ensure minimum page & pageSize values (page >= 1, pageSize >= 0, start >= 0, limit >= 0)\nconst ensureMinValues = ({ start, limit }: Pagination) => ({\n start: Math.max(start, 0),\n limit: limit === -1 ? limit : Math.max(limit, 1),\n});\n\nconst ensureMaxValues =\n (maxLimit = -1) =>\n ({ start, limit }: { start: number; limit: number }) => ({\n start,\n limit: withMaxLimit(limit, maxLimit),\n });\n\n// Apply maxLimit as the limit when limit is -1\n// The limit can be the raw query string, e.g. '-1' from `?pagination[limit]=-1`\nconst withNoLimit = (pagination: Pagination, maxLimit = -1) => ({\n ...pagination,\n limit: Number(pagination.limit) === -1 ? maxLimit : pagination.limit,\n});\n\nconst withDefaultPagination = <T extends PaginationInput>(\n args: T,\n { defaults = {}, maxLimit = -1 } = {}\n): Omit<Partial<T>, keyof PaginationArgs> & Pagination => {\n const defaultValues = merge({}, STRAPI_DEFAULTS, defaults);\n\n const usePagePagination = args.page != null || args.pageSize != null;\n const useOffsetPagination = args.start != null || args.limit != null;\n\n const ensureValidValues = flow(ensureMinValues, ensureMaxValues(maxLimit));\n\n // If there is no pagination attribute, don't modify the payload\n if (!usePagePagination && !useOffsetPagination) {\n return merge({}, args, ensureValidValues(defaultValues.offset));\n }\n\n // If there is page & offset pagination attributes, throw an error\n if (usePagePagination && useOffsetPagination) {\n throw new PaginationError('Cannot use both page & offset pagination in the same query');\n }\n\n const pagination: Pagination = {\n start: 0,\n limit: 0,\n };\n\n // Start / Limit\n if (useOffsetPagination) {\n const { start, limit } = merge({}, defaultValues.offset, args);\n\n Object.assign(pagination, { start, limit });\n }\n\n // Page / PageSize\n if (usePagePagination) {\n const pageArgs =\n args.pageSize == null\n ? omit(args, ['pageSize'])\n : // Math.max converts a numeric string to a number\n { ...args, pageSize: Math.max(1, args.pageSize as number) };\n const { page, pageSize } = merge({}, defaultValues.page, pageArgs);\n const pageLimit = ensureValidValues({ start: 0, limit: pageSize }).limit;\n\n Object.assign(pagination, {\n start: (page - 1) * pageLimit,\n limit: pageLimit,\n });\n }\n\n // Handle -1 limit\n Object.assign(pagination, withNoLimit(pagination, maxLimit));\n\n return merge({}, ensureValidValues(pagination), omit(args, paginationAttributes));\n};\n\n/**\n * Transform pagination information into a paginated response:\n * {\n * page: number,\n * pageSize: number,\n * pageCount: number,\n * total: number\n * }\n */\nconst transformPagedPaginationInfo = (\n paginationInfo: Partial<PaginationArgs>,\n total: number\n): PagePatinationInformation => {\n if (paginationInfo.page != null) {\n const page = paginationInfo.page;\n const pageSize = paginationInfo.pageSize ?? total;\n\n return {\n page,\n pageSize,\n pageCount: pageSize > 0 ? Math.ceil(total / pageSize) : 0,\n total,\n };\n }\n\n if (paginationInfo.start != null) {\n const start = paginationInfo.start;\n const limit = paginationInfo.limit ?? total;\n\n // Start limit to page page size\n return {\n page: Math.floor(start / limit) + 1,\n pageSize: limit,\n pageCount: limit > 0 ? Math.ceil(total / limit) : 0,\n total,\n };\n }\n\n // Default pagination\n return {\n ...paginationInfo,\n page: 1,\n pageSize: 10,\n pageCount: 1,\n total,\n };\n};\n\n/**\n * Transform pagination information into a offset response:\n * {\n * start: number,\n * limit: number,\n * total: number\n * }\n */\nconst transformOffsetPaginationInfo = (\n paginationInfo: Partial<PaginationArgs>,\n total: number\n): OffsetPaginationInformation => {\n if (paginationInfo.page != null) {\n const limit = paginationInfo.pageSize ?? total;\n const start = (paginationInfo.page - 1) * limit;\n\n return { start, limit, total };\n }\n\n if (paginationInfo.start != null) {\n const start = paginationInfo.start;\n const limit = paginationInfo.limit ?? total;\n\n // Start limit to page page size\n return { start, limit, total };\n }\n\n // Default pagination\n return {\n ...paginationInfo,\n start: 0,\n limit: 10,\n total,\n };\n};\n\nexport { withDefaultPagination, transformPagedPaginationInfo, transformOffsetPaginationInfo };\n"],"names":["STRAPI_DEFAULTS","offset","start","limit","page","pageSize","paginationAttributes","withMaxLimit","maxLimit","ensureMinValues","Math","max","ensureMaxValues","withNoLimit","pagination","Number","withDefaultPagination","args","defaults","defaultValues","merge","usePagePagination","useOffsetPagination","ensureValidValues","flow","PaginationError","Object","assign","pageArgs","omit","pageLimit","transformPagedPaginationInfo","paginationInfo","total","pageCount","ceil","floor","transformOffsetPaginationInfo"],"mappings":";;;;;AA4BA,MAAMA,eAAAA,GAAkB;IACtBC,MAAAA,EAAQ;QACNC,KAAAA,EAAO,CAAA;QACPC,KAAAA,EAAO;AACT,KAAA;IACAC,IAAAA,EAAM;QACJA,IAAAA,EAAM,CAAA;QACNC,QAAAA,EAAU;AACZ;AACF,CAAA;AAUA,MAAMC,oBAAAA,GAAuB;AAAC,IAAA,OAAA;AAAS,IAAA,OAAA;AAAS,IAAA,MAAA;AAAQ,IAAA;AAAW,CAAA;AAEnE,MAAMC,YAAAA,GAAe,CAACJ,KAAAA,EAAeK,QAAAA,GAAW,EAAE,GAAA;AAChD,IAAA,IAAIA,Q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AKyB,IAAI,CAACF,QAAQ9B,KAAAA,CAAAA,GAAS,CAAA;AAClD8B,YAAAA;AACF,SAAA;AACF,IAAA;;IAGA,OAAO;AACL,QAAA,GAAGD,cAAc;QACjB5B,IAAAA,EAAM,CAAA;QACNC,QAAAA,EAAU,EAAA;QACV6B,SAAAA,EAAW,CAAA;AACXD,QAAAA;AACF,KAAA;AACF;AAEA;;;;;;;IAQA,MAAMI,6BAAAA,GAAgC,CACpCL,cAAAA,EACAC,KAAAA,GAAAA;IAEA,IAAID,cAAAA,CAAe5B,IAAI,IAAI,IAAA,EAAM;QAC/B,MAAMD,KAAAA,GAAQ6B,cAAAA,CAAe3B,QAAQ,IAAI4B,KAAAA;AACzC,QAAA,MAAM/B,QAAQ,CAAC8B,eAAe5B,IAAI,GAAG,CAAA,IAAKD,KAAAA;QAE1C,OAAO;AAAED,YAAAA,KAAAA;AAAOC,YAAAA,KAAAA;AAAO8B,YAAAA;AAAM,SAAA;AAC/B,IAAA;IAEA,IAAID,cAAAA,CAAe9B,KAAK,IAAI,IAAA,EAAM;QAChC,MAAMA,KAAAA,GAAQ8B,eAAe9B,KAAK;QAClC,MAAMC,KAAAA,GAAQ6B,cAAAA,CAAe7B,KAAK,IAAI8B,KAAAA;;QAGtC,OAAO;AAAE/B,YAAAA,KAAAA;AAAOC,YAAAA,KAAAA;AAAO8B,YAAAA;AAAM,SAAA;AAC/B,IAAA;;IAGA,OAAO;AACL,QAAA,GAAGD,cAAc;QACjB9B,KAAAA,EAAO,CAAA;QACPC,KAAAA,EAAO,EAAA;AACP8B,QAAAA;AACF,KAAA;AACF;;;;;;"}
|
package/dist/pagination.mjs
CHANGED
|
@@ -33,9 +33,10 @@ const ensureMaxValues = (maxLimit = -1)=>({ start, limit })=>({
|
|
|
33
33
|
limit: withMaxLimit(limit, maxLimit)
|
|
34
34
|
});
|
|
35
35
|
// Apply maxLimit as the limit when limit is -1
|
|
36
|
+
// The limit can be the raw query string, e.g. '-1' from `?pagination[limit]=-1`
|
|
36
37
|
const withNoLimit = (pagination, maxLimit = -1)=>({
|
|
37
38
|
...pagination,
|
|
38
|
-
limit: pagination.limit === -1 ? maxLimit : pagination.limit
|
|
39
|
+
limit: Number(pagination.limit) === -1 ? maxLimit : pagination.limit
|
|
39
40
|
});
|
|
40
41
|
const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {})=>{
|
|
41
42
|
const defaultValues = merge({}, STRAPI_DEFAULTS, defaults);
|