@oliversalzburg/js-utils 0.0.2 → 0.0.4
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/README.md +1 -48
- package/output/array.d.ts +28 -1
- package/output/array.js +27 -0
- package/output/array.js.map +1 -1
- package/output/core.d.ts +4 -0
- package/output/core.js +2 -0
- package/output/core.js.map +1 -0
- package/output/error-serializer.d.ts +37 -0
- package/output/error-serializer.js +63 -0
- package/output/error-serializer.js.map +1 -0
- package/output/errors/AbstractError.d.ts +34 -0
- package/output/errors/AbstractError.js +62 -0
- package/output/errors/AbstractError.js.map +1 -0
- package/output/errors/InternalError.d.ts +14 -0
- package/output/errors/InternalError.js +33 -0
- package/output/errors/InternalError.js.map +1 -0
- package/output/errors/InvalidArgumentError.d.ts +13 -0
- package/output/errors/InvalidArgumentError.js +20 -0
- package/output/errors/InvalidArgumentError.js.map +1 -0
- package/output/errors/InvalidOperationError.d.ts +13 -0
- package/output/errors/InvalidOperationError.js +20 -0
- package/output/errors/InvalidOperationError.js.map +1 -0
- package/output/errors/NotImplementedError.d.ts +12 -0
- package/output/errors/NotImplementedError.js +19 -0
- package/output/errors/NotImplementedError.js.map +1 -0
- package/output/errors/PermissionViolationError.d.ts +13 -0
- package/output/errors/PermissionViolationError.js +20 -0
- package/output/errors/PermissionViolationError.js.map +1 -0
- package/output/errors/ResourceConflictError.d.ts +12 -0
- package/output/errors/ResourceConflictError.js +19 -0
- package/output/errors/ResourceConflictError.js.map +1 -0
- package/output/errors/UnknownError.d.ts +16 -0
- package/output/errors/UnknownError.js +23 -0
- package/output/errors/UnknownError.js.map +1 -0
- package/output/errors/index.d.ts +8 -0
- package/output/errors/index.js +9 -0
- package/output/errors/index.js.map +1 -0
- package/output/index.d.ts +3 -0
- package/output/index.js +3 -0
- package/output/index.js.map +1 -1
- package/output/nil.d.ts +16 -7
- package/output/nil.js +9 -4
- package/output/nil.js.map +1 -1
- package/output/sleep.d.ts +2 -2
- package/output/sleep.js +3 -3
- package/output/sleep.js.map +1 -1
- package/output/string-formatter.d.ts +20 -0
- package/output/string-formatter.js +26 -0
- package/output/string-formatter.js.map +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,48 +1 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
## Does
|
|
4
|
-
|
|
5
|
-
- [Yarn 3](https://yarnpkg.com/)
|
|
6
|
-
- Uses [TypeScript](https://www.typescriptlang.org/)
|
|
7
|
-
- Target application runs in [Node.js](https://nodejs.org/)
|
|
8
|
-
- [esbuild](https://esbuild.github.io/)
|
|
9
|
-
- [EditorConfig](https://editorconfig.org/) + [ESLint](https://eslint.org/) + [Prettier](https://prettier.io/) + [lint-staged](https://github.com/okonet/lint-staged)
|
|
10
|
-
- QA with [GitHub Actions](https://github.com/features/actions)
|
|
11
|
-
- [MkDocs](https://www.mkdocs.org/)-oriented Markdown in mind
|
|
12
|
-
|
|
13
|
-
## Doesn't
|
|
14
|
-
|
|
15
|
-
- [Yarn PnP](https://yarnpkg.com/features/pnp)
|
|
16
|
-
- [Yarn telemetry](https://yarnpkg.com/advanced/telemetry)
|
|
17
|
-
- [Yarn Zero-Installs](https://yarnpkg.com/features/zero-installs)
|
|
18
|
-
- [Husky](https://github.com/typicode/husky)
|
|
19
|
-
|
|
20
|
-
## Why
|
|
21
|
-
|
|
22
|
-
1. Why modern Yarn?
|
|
23
|
-
|
|
24
|
-
Among other things, Yarn is robust, performant and extremely versatile when it comes to repository management. The given configuration provides a very solid first-time experience. Some of the things that make modern Yarn great can be seen in this project template.
|
|
25
|
-
|
|
26
|
-
1. Why esbuild?
|
|
27
|
-
|
|
28
|
-
We want fast builds. The code is still checked for correctness in the editor and in CI.
|
|
29
|
-
|
|
30
|
-
1. Why the MkDocs Markdown?
|
|
31
|
-
|
|
32
|
-
If you're going to want to build any documentation site, you will appreciate having auto-formatted to this style from the start. Using mkdocs-material for documentation sites is highly recommended. The Python Markdown ecosystem is much more versatile and performant than the JS/TS space.
|
|
33
|
-
|
|
34
|
-
1. Why is PnP disabled?
|
|
35
|
-
|
|
36
|
-
While PnP is generally preferred for its strictness, using it still incurs a lot of friction. Because PnP is enabled by default in modern Yarn, this deters many users from adopting modern Yarn. Thus, this project uses Yarn's `node-modules` linker, the behavior of which should be very familiar to most adopters.
|
|
37
|
-
|
|
38
|
-
1. Why is telemetry disabled?
|
|
39
|
-
|
|
40
|
-
Whenever possible, the disclosure of _any_ data should be opt-in. Please refer to the document linked above, and enable telemetry after carefully reading it.
|
|
41
|
-
|
|
42
|
-
1. Why not Zero-Installs?
|
|
43
|
-
|
|
44
|
-
Zero-Installs are purely a `.gitignore`-controlled feature. Most new adopters do not expect the behavior of the default configuration and some adopters have raised concerns over long-term effects. Enable it after carefully reading the article linked above.
|
|
45
|
-
|
|
46
|
-
1. Why not use Husky for the hook?
|
|
47
|
-
|
|
48
|
-
Husky is more complex than what is required to install the hook in a modern Yarn repository. We also do not want to hand over control over repository behavior to a dependency.
|
|
1
|
+
# JS Utils
|
package/output/array.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
|
-
import { ConstructorOf } from "./
|
|
1
|
+
import { ConstructorOf } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* Places the items in the array in random order.
|
|
4
|
+
* @param array The array to shuffle.
|
|
5
|
+
* @returns The passed array in random order.
|
|
6
|
+
*/
|
|
2
7
|
export declare const shuffleArray: <T>(array: T[]) => T[];
|
|
8
|
+
/**
|
|
9
|
+
* Returns an array that holds all items that appear in both
|
|
10
|
+
* passed arrays.
|
|
11
|
+
* @param a The first array.
|
|
12
|
+
* @param b The second array.
|
|
13
|
+
* @returns A new array which holds the items that appear in
|
|
14
|
+
* both passed arrays.
|
|
15
|
+
*/
|
|
3
16
|
export declare const intersect: <T>(a: T[], b: T[]) => T[];
|
|
17
|
+
/**
|
|
18
|
+
* Returns an array that holds all items that only appear in `a`.
|
|
19
|
+
* @param a The first array.
|
|
20
|
+
* @param b The second array.
|
|
21
|
+
* @returns A new array which holds the items that ony appear
|
|
22
|
+
* in `a`.
|
|
23
|
+
*/
|
|
4
24
|
export declare const difference: <T>(a: T[], b: T[]) => T[];
|
|
25
|
+
/**
|
|
26
|
+
* From an array with unknown contents, retrieve all the elements
|
|
27
|
+
* that are of a certain type and return them as a new array.
|
|
28
|
+
* @param array The array to filter.
|
|
29
|
+
* @param InstanceType The type to search for.
|
|
30
|
+
* @returns A new array with the filtered items.
|
|
31
|
+
*/
|
|
5
32
|
export declare const filterType: <T>(array: Array<unknown>, InstanceType: ConstructorOf<T>) => T[];
|
package/output/array.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { is } from "./nil.js";
|
|
2
|
+
/**
|
|
3
|
+
* Places the items in the array in random order.
|
|
4
|
+
* @param array The array to shuffle.
|
|
5
|
+
* @returns The passed array in random order.
|
|
6
|
+
*/
|
|
2
7
|
export const shuffleArray = (array) => {
|
|
3
8
|
for (let index = array.length - 1; index > 0; index--) {
|
|
4
9
|
const targetIndex = Math.floor(Math.random() * (index + 1));
|
|
@@ -8,11 +13,33 @@ export const shuffleArray = (array) => {
|
|
|
8
13
|
}
|
|
9
14
|
return array;
|
|
10
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Returns an array that holds all items that appear in both
|
|
18
|
+
* passed arrays.
|
|
19
|
+
* @param a The first array.
|
|
20
|
+
* @param b The second array.
|
|
21
|
+
* @returns A new array which holds the items that appear in
|
|
22
|
+
* both passed arrays.
|
|
23
|
+
*/
|
|
11
24
|
export const intersect = (a, b) => {
|
|
12
25
|
return a.filter(x => b.includes(x));
|
|
13
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns an array that holds all items that only appear in `a`.
|
|
29
|
+
* @param a The first array.
|
|
30
|
+
* @param b The second array.
|
|
31
|
+
* @returns A new array which holds the items that ony appear
|
|
32
|
+
* in `a`.
|
|
33
|
+
*/
|
|
14
34
|
export const difference = (a, b) => {
|
|
15
35
|
return a.filter(x => !b.includes(x));
|
|
16
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* From an array with unknown contents, retrieve all the elements
|
|
39
|
+
* that are of a certain type and return them as a new array.
|
|
40
|
+
* @param array The array to filter.
|
|
41
|
+
* @param InstanceType The type to search for.
|
|
42
|
+
* @returns A new array with the filtered items.
|
|
43
|
+
*/
|
|
17
44
|
export const filterType = (array, InstanceType) => array.filter(element => is(element, InstanceType));
|
|
18
45
|
//# sourceMappingURL=array.js.map
|
package/output/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../source/array.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../source/array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAI,KAAe,EAAE,EAAE;IACjD,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE;QACrD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;QAClC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;KAC3B;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,CAAW,EAAE,CAAW,EAAE,EAAE;IACvD,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAI,CAAW,EAAE,CAAW,EAAE,EAAE;IACxD,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAI,KAAqB,EAAE,YAA8B,EAAE,EAAE,CACrF,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAa,CAAC"}
|
package/output/core.d.ts
ADDED
package/output/core.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AbstractError } from "./errors/AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* The shape of an `Error` instance, after it has been serialized into a simple hash.
|
|
4
|
+
*/
|
|
5
|
+
export type SerializedError = Record<string, Record<string, string> | string | undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* Determine if the given unknown subject is an `Error` instance.
|
|
8
|
+
* @param subject The object to inspect.
|
|
9
|
+
* @returns `true` if the subject is an `Error`, `false´ otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isError: (subject: unknown) => subject is Error;
|
|
12
|
+
/**
|
|
13
|
+
* Returns an `AbstractError` that best represents the passed subject.
|
|
14
|
+
* If the passed subject is already an `AbstractError`, it is returned as-is.
|
|
15
|
+
* Otherwise, it will be converted into an appropriate error type.
|
|
16
|
+
* @param subject The subject to inspect
|
|
17
|
+
* @returns An `AbstractError` instance.
|
|
18
|
+
*/
|
|
19
|
+
export declare const unknownToError: (subject: unknown) => AbstractError;
|
|
20
|
+
/**
|
|
21
|
+
* Serializes an error into a JSON string.
|
|
22
|
+
* @param error The error to stringify.
|
|
23
|
+
* @returns A JSON string representing the error.
|
|
24
|
+
*/
|
|
25
|
+
export declare const errorToJSON: (error: Error) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Converts an error into a regular hash.
|
|
28
|
+
* @param error The error to convert.
|
|
29
|
+
* @returns A new object that contains all the properties of the error.
|
|
30
|
+
*/
|
|
31
|
+
export declare const errorToRecord: (error: Error) => Record<string, unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Serializes an error into a simpler shape.
|
|
34
|
+
* @param error The error to serialize.
|
|
35
|
+
* @returns A simple representation of the error.
|
|
36
|
+
*/
|
|
37
|
+
export declare const errorToSimpleSerializable: <TError extends AbstractError = AbstractError>(error: TError) => SerializedError;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { AbstractError } from "./errors/AbstractError.js";
|
|
3
|
+
import { InternalError } from "./errors/InternalError.js";
|
|
4
|
+
import { UnknownError } from "./errors/UnknownError.js";
|
|
5
|
+
/**
|
|
6
|
+
* Determine if the given unknown subject is an `Error` instance.
|
|
7
|
+
* @param subject The object to inspect.
|
|
8
|
+
* @returns `true` if the subject is an `Error`, `false´ otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export const isError = (subject) => {
|
|
11
|
+
return subject instanceof Error || types.isNativeError(subject);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns an `AbstractError` that best represents the passed subject.
|
|
15
|
+
* If the passed subject is already an `AbstractError`, it is returned as-is.
|
|
16
|
+
* Otherwise, it will be converted into an appropriate error type.
|
|
17
|
+
* @param subject The subject to inspect
|
|
18
|
+
* @returns An `AbstractError` instance.
|
|
19
|
+
*/
|
|
20
|
+
export const unknownToError = (subject) => {
|
|
21
|
+
if (AbstractError.isAbstractError(subject)) {
|
|
22
|
+
return subject;
|
|
23
|
+
}
|
|
24
|
+
if (isError(subject)) {
|
|
25
|
+
return InternalError.fromError(subject);
|
|
26
|
+
}
|
|
27
|
+
return new UnknownError(String(subject));
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Serializes an error into a JSON string.
|
|
31
|
+
* @param error The error to stringify.
|
|
32
|
+
* @returns A JSON string representing the error.
|
|
33
|
+
*/
|
|
34
|
+
export const errorToJSON = (error) => {
|
|
35
|
+
return JSON.stringify(error, Object.getOwnPropertyNames(error));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Converts an error into a regular hash.
|
|
39
|
+
* @param error The error to convert.
|
|
40
|
+
* @returns A new object that contains all the properties of the error.
|
|
41
|
+
*/
|
|
42
|
+
export const errorToRecord = (error) => {
|
|
43
|
+
const record = {};
|
|
44
|
+
for (const propertyName of Object.getOwnPropertyNames(error)) {
|
|
45
|
+
record[propertyName] = error[propertyName];
|
|
46
|
+
}
|
|
47
|
+
return record;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Serializes an error into a simpler shape.
|
|
51
|
+
* @param error The error to serialize.
|
|
52
|
+
* @returns A simple representation of the error.
|
|
53
|
+
*/
|
|
54
|
+
export const errorToSimpleSerializable = (error) => {
|
|
55
|
+
const serialized = {
|
|
56
|
+
code: error.code,
|
|
57
|
+
message: error.message,
|
|
58
|
+
name: error.name,
|
|
59
|
+
stack: error.stack,
|
|
60
|
+
};
|
|
61
|
+
return serialized;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=error-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-serializer.js","sourceRoot":"","sources":["../source/error-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAOxD;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAoB,EAAE;IAC5D,OAAO,OAAO,YAAY,KAAK,IAAI,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAiB,EAAE;IAChE,IAAI,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE;QAC1C,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;KACzC;IAED,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IAClD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAY,EAA2B,EAAE;IACrE,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;QAC5D,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,YAAkC,CAAC,CAAC;KAClE;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAa,EACI,EAAE;IACnB,MAAM,UAAU,GAAoB;QAClC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Maybe } from "../nil.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AbstractError extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP status code to associate with this error.
|
|
8
|
+
* @deprecated We no longer respond to HTTP requests with error-specifc
|
|
9
|
+
* status codes.
|
|
10
|
+
*/
|
|
11
|
+
status: number;
|
|
12
|
+
/**
|
|
13
|
+
* Another error that should be transported with this error.
|
|
14
|
+
* @deprecated We don't make use of this or interpret nested errors at all.
|
|
15
|
+
*/
|
|
16
|
+
inner: Maybe<Error>;
|
|
17
|
+
/**
|
|
18
|
+
* A user-friendly error message that may be transported to the client.
|
|
19
|
+
* @deprecated User-friendly errors should be read from `extensions`.
|
|
20
|
+
*/
|
|
21
|
+
info: Maybe<string>;
|
|
22
|
+
/**
|
|
23
|
+
* An application-unique, readable error code.
|
|
24
|
+
*/
|
|
25
|
+
code: string;
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new AbstractError.
|
|
28
|
+
* @param code The main identification code for the error.
|
|
29
|
+
* @param message The main error message.
|
|
30
|
+
* @param status The HTTP status code to return.
|
|
31
|
+
*/
|
|
32
|
+
constructor(code: string, message: string, status: number);
|
|
33
|
+
static isAbstractError(error: unknown, allowForeignModule?: boolean): error is AbstractError;
|
|
34
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all errors.
|
|
3
|
+
*/
|
|
4
|
+
export class AbstractError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* The HTTP status code to associate with this error.
|
|
7
|
+
* @deprecated We no longer respond to HTTP requests with error-specifc
|
|
8
|
+
* status codes.
|
|
9
|
+
*/
|
|
10
|
+
status;
|
|
11
|
+
/**
|
|
12
|
+
* Another error that should be transported with this error.
|
|
13
|
+
* @deprecated We don't make use of this or interpret nested errors at all.
|
|
14
|
+
*/
|
|
15
|
+
inner;
|
|
16
|
+
/**
|
|
17
|
+
* A user-friendly error message that may be transported to the client.
|
|
18
|
+
* @deprecated User-friendly errors should be read from `extensions`.
|
|
19
|
+
*/
|
|
20
|
+
info;
|
|
21
|
+
/**
|
|
22
|
+
* An application-unique, readable error code.
|
|
23
|
+
*/
|
|
24
|
+
code;
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new AbstractError.
|
|
27
|
+
* @param code The main identification code for the error.
|
|
28
|
+
* @param message The main error message.
|
|
29
|
+
* @param status The HTTP status code to return.
|
|
30
|
+
*/
|
|
31
|
+
constructor(code, message, status) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.name = "AbstractError";
|
|
35
|
+
this.status = status;
|
|
36
|
+
this.inner = null;
|
|
37
|
+
// Capture a new stacktrace, otherwise it will include our base-class constructor instead of the code
|
|
38
|
+
// location we're actually interested in.
|
|
39
|
+
Error.captureStackTrace(this, AbstractError);
|
|
40
|
+
}
|
|
41
|
+
static isAbstractError(error, allowForeignModule = true) {
|
|
42
|
+
if (error instanceof AbstractError) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
// When multiple versions of core-models3 are loaded at runtime, the
|
|
46
|
+
// prototypes of errors don't align. In that case, we just analyze the
|
|
47
|
+
// error code.
|
|
48
|
+
if (allowForeignModule) {
|
|
49
|
+
const errorRecord = error;
|
|
50
|
+
if (Object(error) === error &&
|
|
51
|
+
"code" in errorRecord &&
|
|
52
|
+
typeof errorRecord.code === "string") {
|
|
53
|
+
const codedError = error;
|
|
54
|
+
if (codedError.code.match(/^ERR_OS_/)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=AbstractError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractError.js","sourceRoot":"","sources":["../../source/errors/AbstractError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC;;;;OAIG;IACH,MAAM,CAAS;IAEf;;;OAGG;IACH,KAAK,CAAe;IAEpB;;;OAGG;IACH,IAAI,CAAgB;IAEpB;;OAEG;IACH,IAAI,CAAS;IAEb;;;;;OAKG;IACH,YAAY,IAAY,EAAE,OAAe,EAAE,MAAc;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB,qGAAqG;QACrG,yCAAyC;QACzC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,KAAc,EAAE,kBAAkB,GAAG,IAAI;QAC9D,IAAI,KAAK,YAAY,aAAa,EAAE;YAClC,OAAO,IAAI,CAAC;SACb;QAED,oEAAoE;QACpE,sEAAsE;QACtE,cAAc;QACd,IAAI,kBAAkB,EAAE;YACtB,MAAM,WAAW,GAAG,KAAgC,CAAC;YACrD,IACE,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK;gBACvB,MAAM,IAAI,WAAW;gBACrB,OAAO,WAAW,CAAC,IAAI,KAAK,QAAQ,EACpC;gBACA,MAAM,UAAU,GAAG,KAAyB,CAAC;gBAC7C,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;oBACrC,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an `Error`-like object was caught and converted into an
|
|
4
|
+
* implementation of `AbstractError` for further processing.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InternalError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InternalError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message: string, status?: number);
|
|
13
|
+
static fromError(error: Error): InternalError;
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an `Error`-like object was caught and converted into an
|
|
4
|
+
* implementation of `AbstractError` for further processing.
|
|
5
|
+
*/
|
|
6
|
+
export class InternalError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InternalError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message, status = 500) {
|
|
13
|
+
super("ERR_OS_INTERNAL", message, status);
|
|
14
|
+
this.name = "InternalError";
|
|
15
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
16
|
+
// constructor instead of the code location we're actually interested in.
|
|
17
|
+
Error.captureStackTrace(this, InternalError);
|
|
18
|
+
}
|
|
19
|
+
static fromError(error) {
|
|
20
|
+
// Create a _real_ `InternalError` instance, which we will return later.
|
|
21
|
+
const internalError = new InternalError(error.message);
|
|
22
|
+
// Assign the error to it, to inherit all the fields in the error.
|
|
23
|
+
// Then assign another `InternalError` to replace key fields, like:
|
|
24
|
+
// name, code, status, ...
|
|
25
|
+
Object.assign(internalError, error, new InternalError(error.message));
|
|
26
|
+
// Set the inner error.
|
|
27
|
+
internalError.inner = error;
|
|
28
|
+
// Inherit the original error stack again.
|
|
29
|
+
internalError.stack = error.stack;
|
|
30
|
+
return internalError;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=InternalError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalError.js","sourceRoot":"","sources":["../../source/errors/InternalError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,iBAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE1C,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAY;QAC3B,wEAAwE;QACxE,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvD,kEAAkE;QAClE,mEAAmE;QACnE,0BAA0B;QAC1B,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,KAAK,EAAE,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,uBAAuB;QACvB,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5B,0CAA0C;QAC1C,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAElC,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when the user supplied an argument that is not valid in the current
|
|
4
|
+
* context.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InvalidArgumentError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InvalidArgumentError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message: string, status?: number);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when the user supplied an argument that is not valid in the current
|
|
4
|
+
* context.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidArgumentError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InvalidArgumentError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message, status = 400) {
|
|
13
|
+
super("ERR_OS_INVALID_ARGUMENT", message, status);
|
|
14
|
+
this.name = "InvalidArgumentError";
|
|
15
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
16
|
+
// constructor instead of the code location we're actually interested in.
|
|
17
|
+
Error.captureStackTrace(this, InvalidArgumentError);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=InvalidArgumentError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidArgumentError.js","sourceRoot":"","sources":["../../source/errors/InvalidArgumentError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACrD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAElD,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QAEnC,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an operation was attempted that can not be completed in the current
|
|
4
|
+
* context.
|
|
5
|
+
*/
|
|
6
|
+
export declare class InvalidOperationError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InvalidOperationError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message: string, status?: number);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an operation was attempted that can not be completed in the current
|
|
4
|
+
* context.
|
|
5
|
+
*/
|
|
6
|
+
export class InvalidOperationError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `InvalidOperationError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message, status = 400) {
|
|
13
|
+
super("ERR_OS_INVALID_OPERATION", message, status);
|
|
14
|
+
this.name = "InvalidOperationError";
|
|
15
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
16
|
+
// constructor instead of the code location we're actually interested in.
|
|
17
|
+
Error.captureStackTrace(this, InvalidOperationError);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=InvalidOperationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidOperationError.js","sourceRoot":"","sources":["../../source/errors/InvalidOperationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QAEpC,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when a called method actually hasn't been implemented yet (whoops).
|
|
4
|
+
*/
|
|
5
|
+
export declare class NotImplementedError extends AbstractError {
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new `NotImplementedError`.
|
|
8
|
+
* @param message The main error message.
|
|
9
|
+
* @param status The HTTP status code to return.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message: string, status?: number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when a called method actually hasn't been implemented yet (whoops).
|
|
4
|
+
*/
|
|
5
|
+
export class NotImplementedError extends AbstractError {
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new `NotImplementedError`.
|
|
8
|
+
* @param message The main error message.
|
|
9
|
+
* @param status The HTTP status code to return.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message, status = 501) {
|
|
12
|
+
super("ERR_OS_NOT_IMPLEMENTED", message, status);
|
|
13
|
+
this.name = "NotImplementedError";
|
|
14
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
15
|
+
// constructor instead of the code location we're actually interested in.
|
|
16
|
+
Error.captureStackTrace(this, NotImplementedError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=NotImplementedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotImplementedError.js","sourceRoot":"","sources":["../../source/errors/NotImplementedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACpD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEjD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAElC,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* An error used when access to a resource was requested, but the required
|
|
4
|
+
* permissions were not available.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PermissionViolationError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `PermissionViolationError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message: string, status?: number);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* An error used when access to a resource was requested, but the required
|
|
4
|
+
* permissions were not available.
|
|
5
|
+
*/
|
|
6
|
+
export class PermissionViolationError extends AbstractError {
|
|
7
|
+
/**
|
|
8
|
+
* Constructs a new `PermissionViolationError`.
|
|
9
|
+
* @param message The main error message.
|
|
10
|
+
* @param status The HTTP status code to return.
|
|
11
|
+
*/
|
|
12
|
+
constructor(message, status = 403) {
|
|
13
|
+
super("ERR_OS_PERMISSION_VIOLATION", message, status);
|
|
14
|
+
this.name = "PermissionViolationError";
|
|
15
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
16
|
+
// constructor instead of the code location we're actually interested in.
|
|
17
|
+
Error.captureStackTrace(this, PermissionViolationError);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=PermissionViolationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PermissionViolationError.js","sourceRoot":"","sources":["../../source/errors/PermissionViolationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,aAAa;IACzD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,6BAA6B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QAEvC,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when a resource conflict was detected.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ResourceConflictError extends AbstractError {
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new `ResourceConflictError`.
|
|
8
|
+
* @param message The main error message.
|
|
9
|
+
* @param status The HTTP status code to return.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message: string, status?: number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when a resource conflict was detected.
|
|
4
|
+
*/
|
|
5
|
+
export class ResourceConflictError extends AbstractError {
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new `ResourceConflictError`.
|
|
8
|
+
* @param message The main error message.
|
|
9
|
+
* @param status The HTTP status code to return.
|
|
10
|
+
*/
|
|
11
|
+
constructor(message, status = 409) {
|
|
12
|
+
super("ERR_OS_RESOURCE_CONFLICT", message, status);
|
|
13
|
+
this.name = "ResourceConflictError";
|
|
14
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
15
|
+
// constructor instead of the code location we're actually interested in.
|
|
16
|
+
Error.captureStackTrace(this, ResourceConflictError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ResourceConflictError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceConflictError.js","sourceRoot":"","sources":["../../source/errors/ResourceConflictError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QAEpC,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an unknown, non-`Error`-like object was caught and converted into a
|
|
4
|
+
* real `Error` instance.
|
|
5
|
+
* Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
|
|
6
|
+
* into an `UnknownError`.
|
|
7
|
+
* To enrich an `Error`-like object that was caught, use the `InternalError`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UnknownError extends AbstractError {
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new `UnknownError`.
|
|
12
|
+
* @param message The main error message.
|
|
13
|
+
* @param status The HTTP status code to return.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message: string, status?: number);
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractError } from "./AbstractError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used when an unknown, non-`Error`-like object was caught and converted into a
|
|
4
|
+
* real `Error` instance.
|
|
5
|
+
* Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
|
|
6
|
+
* into an `UnknownError`.
|
|
7
|
+
* To enrich an `Error`-like object that was caught, use the `InternalError`.
|
|
8
|
+
*/
|
|
9
|
+
export class UnknownError extends AbstractError {
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new `UnknownError`.
|
|
12
|
+
* @param message The main error message.
|
|
13
|
+
* @param status The HTTP status code to return.
|
|
14
|
+
*/
|
|
15
|
+
constructor(message, status = 500) {
|
|
16
|
+
super("ERR_OS_UNKNOWN", message, status);
|
|
17
|
+
this.name = "UnknownError";
|
|
18
|
+
// Capture a new stacktrace, otherwise it will include our base-class
|
|
19
|
+
// constructor instead of the code location we're actually interested in.
|
|
20
|
+
Error.captureStackTrace(this, UnknownError);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=UnknownError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnknownError.js","sourceRoot":"","sources":["../../source/errors/UnknownError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC7C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACvC,KAAK,CAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEzC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAE3B,qEAAqE;QACrE,yEAAyE;QACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./AbstractError.js";
|
|
2
|
+
export * from "./InternalError.js";
|
|
3
|
+
export * from "./InvalidArgumentError.js";
|
|
4
|
+
export * from "./InvalidOperationError.js";
|
|
5
|
+
export * from "./NotImplementedError.js";
|
|
6
|
+
export * from "./PermissionViolationError.js";
|
|
7
|
+
export * from "./ResourceConflictError.js";
|
|
8
|
+
export * from "./UnknownError.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./AbstractError.js";
|
|
2
|
+
export * from "./InternalError.js";
|
|
3
|
+
export * from "./InvalidArgumentError.js";
|
|
4
|
+
export * from "./InvalidOperationError.js";
|
|
5
|
+
export * from "./NotImplementedError.js";
|
|
6
|
+
export * from "./PermissionViolationError.js";
|
|
7
|
+
export * from "./ResourceConflictError.js";
|
|
8
|
+
export * from "./UnknownError.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
|
package/output/index.d.ts
CHANGED
package/output/index.js
CHANGED
package/output/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
|
package/output/nil.d.ts
CHANGED
|
@@ -1,30 +1,39 @@
|
|
|
1
|
+
import { ConstructorOf } from "./core.js";
|
|
2
|
+
/**
|
|
3
|
+
* When you want to normalize away `null` | `undefined`, or deal
|
|
4
|
+
* with either type through a consistent interface.
|
|
5
|
+
*/
|
|
1
6
|
export type Nil = null | undefined;
|
|
2
|
-
export type Maybe<T> = T | Nil;
|
|
3
7
|
/**
|
|
4
|
-
*
|
|
8
|
+
* A type that could be either what you want, or `Nil`.
|
|
5
9
|
*/
|
|
6
|
-
export type
|
|
10
|
+
export type Maybe<T> = T | Nil;
|
|
7
11
|
/**
|
|
8
12
|
* Check if something is a concrete value of the given type.
|
|
9
13
|
* Can be used as a typeguard.
|
|
10
|
-
*
|
|
11
14
|
* @param nilable The subject that could be nil.
|
|
12
15
|
* @param InstanceType The type to check against.
|
|
16
|
+
* @returns `true` if the input element matches the given type,
|
|
17
|
+
* `false` otherwise.
|
|
13
18
|
*/
|
|
14
19
|
export declare function is<T>(nilable: Maybe<T>, InstanceType: ConstructorOf<T>): nilable is T;
|
|
15
20
|
/**
|
|
16
|
-
* Check if something is
|
|
21
|
+
* Check if something is nil.
|
|
17
22
|
* Can be used as a typeguard.
|
|
18
|
-
*
|
|
19
23
|
* @param subject The subject that could be nil.
|
|
24
|
+
* @returns `true` if the subject is nil, `false` otherwise.
|
|
20
25
|
*/
|
|
21
26
|
export declare function isNil<T>(subject: Maybe<T>): subject is Nil;
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when an unexpected nil value was encountered.
|
|
29
|
+
*/
|
|
22
30
|
export declare class UnexpectedNilError extends Error {
|
|
23
31
|
constructor(message?: string);
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* Ensure that the passed subject is not nil; throw otherwise.
|
|
27
|
-
*
|
|
28
35
|
* @param subject A subject that is possible nil.
|
|
36
|
+
* @returns The subject, if it isn't nil.
|
|
37
|
+
* @throws {UnexpectedNilError} When the subject is nil.
|
|
29
38
|
*/
|
|
30
39
|
export declare function mustExist<T>(subject: Maybe<T>): T;
|
package/output/nil.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check if something is a concrete value of the given type.
|
|
3
3
|
* Can be used as a typeguard.
|
|
4
|
-
*
|
|
5
4
|
* @param nilable The subject that could be nil.
|
|
6
5
|
* @param InstanceType The type to check against.
|
|
6
|
+
* @returns `true` if the input element matches the given type,
|
|
7
|
+
* `false` otherwise.
|
|
7
8
|
*/
|
|
8
9
|
export function is(nilable, InstanceType) {
|
|
9
10
|
return !isNil(nilable) && nilable instanceof InstanceType;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
|
-
* Check if something is
|
|
13
|
+
* Check if something is nil.
|
|
13
14
|
* Can be used as a typeguard.
|
|
14
|
-
*
|
|
15
15
|
* @param subject The subject that could be nil.
|
|
16
|
+
* @returns `true` if the subject is nil, `false` otherwise.
|
|
16
17
|
*/
|
|
17
18
|
export function isNil(subject) {
|
|
18
19
|
return subject === null || subject === undefined;
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown when an unexpected nil value was encountered.
|
|
23
|
+
*/
|
|
20
24
|
export class UnexpectedNilError extends Error {
|
|
21
25
|
constructor(message = "unexpected nil value") {
|
|
22
26
|
super(message);
|
|
@@ -24,8 +28,9 @@ export class UnexpectedNilError extends Error {
|
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
30
|
* Ensure that the passed subject is not nil; throw otherwise.
|
|
27
|
-
*
|
|
28
31
|
* @param subject A subject that is possible nil.
|
|
32
|
+
* @returns The subject, if it isn't nil.
|
|
33
|
+
* @throws {UnexpectedNilError} When the subject is nil.
|
|
29
34
|
*/
|
|
30
35
|
export function mustExist(subject) {
|
|
31
36
|
if (isNil(subject)) {
|
package/output/nil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nil.js","sourceRoot":"","sources":["../source/nil.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,MAAM,UAAU,EAAE,CAAI,OAAiB,EAAE,YAA8B;IACrE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,YAAY,YAAY,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAI,OAAiB;IACxC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,GAAG,sBAAsB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAI,OAAiB;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;QAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/output/sleep.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wait a given period before continuing execution.
|
|
3
|
-
*
|
|
4
3
|
* @param duration How many milliseconds to wait.
|
|
4
|
+
* @returns Nothing
|
|
5
5
|
*/
|
|
6
|
-
export declare
|
|
6
|
+
export declare const sleep: (duration: number) => Promise<void>;
|
package/output/sleep.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wait a given period before continuing execution.
|
|
3
|
-
*
|
|
4
3
|
* @param duration How many milliseconds to wait.
|
|
4
|
+
* @returns Nothing
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export const sleep = (duration) => {
|
|
7
7
|
return new Promise(resolve => setTimeout(resolve, duration));
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
9
|
//# sourceMappingURL=sleep.js.map
|
package/output/sleep.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../source/sleep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"sleep.js","sourceRoot":"","sources":["../source/sleep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAiB,EAAE;IACvD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a given input string with numeric placeholders.
|
|
3
|
+
* @example
|
|
4
|
+
* // returns "Hello World"
|
|
5
|
+
* formatString("{0} {1}", ["Hello", "World"]);
|
|
6
|
+
* @param string The input string with placeholders.
|
|
7
|
+
* @param formatArguments An array of strings to place into the placeholders.
|
|
8
|
+
* @returns The formatted string.
|
|
9
|
+
*/
|
|
10
|
+
export declare const formatString: (string: string, ...formatArguments: Array<string>) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Formats a given input string with alphanumeric placeholders.
|
|
13
|
+
* @example
|
|
14
|
+
* // returns "Hello World"
|
|
15
|
+
* formatString("{first} {second}", {first:"Hello", second:"World"});
|
|
16
|
+
* @param string The input string with placeholders.
|
|
17
|
+
* @param parameters A hash of parameters to place in the placeholders.
|
|
18
|
+
* @returns The formatted string.
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatStringTemplate: (string: string, parameters: Record<string, string | undefined>) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a given input string with numeric placeholders.
|
|
3
|
+
* @example
|
|
4
|
+
* // returns "Hello World"
|
|
5
|
+
* formatString("{0} {1}", ["Hello", "World"]);
|
|
6
|
+
* @param string The input string with placeholders.
|
|
7
|
+
* @param formatArguments An array of strings to place into the placeholders.
|
|
8
|
+
* @returns The formatted string.
|
|
9
|
+
*/
|
|
10
|
+
export const formatString = (string, ...formatArguments) => {
|
|
11
|
+
return string.replace(/{(\d+)}/g, (match, matchedDigits) => typeof formatArguments[matchedDigits] !== "undefined" ? formatArguments[matchedDigits] : match);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Formats a given input string with alphanumeric placeholders.
|
|
15
|
+
* @example
|
|
16
|
+
* // returns "Hello World"
|
|
17
|
+
* formatString("{first} {second}", {first:"Hello", second:"World"});
|
|
18
|
+
* @param string The input string with placeholders.
|
|
19
|
+
* @param parameters A hash of parameters to place in the placeholders.
|
|
20
|
+
* @returns The formatted string.
|
|
21
|
+
*/
|
|
22
|
+
export const formatStringTemplate = (string, parameters) => {
|
|
23
|
+
string = string.replace(/#{[\w.]+}/g, query => parameters[query.slice(2, query.length - 1)] ?? "<missing parameter>");
|
|
24
|
+
return string;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=string-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-formatter.js","sourceRoot":"","sources":["../source/string-formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,eAA8B,EAAU,EAAE;IACxF,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,aAAqB,EAAU,EAAE,CACzE,OAAO,eAAe,CAAC,aAAa,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAC/F,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,UAA8C,EACtC,EAAE;IACV,MAAM,GAAG,MAAM,CAAC,OAAO,CACrB,YAAY,EACZ,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,qBAAqB,CAC/E,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@oliversalzburg/js-utils",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"build": "yarn run build:tsc",
|
|
18
18
|
"build:esbuild": "node build.js",
|
|
19
19
|
"build:tsc": "tsc",
|
|
20
|
-
"lint
|
|
20
|
+
"lint": "yarn run lint:eslint && yarn run lint:tsc",
|
|
21
|
+
"lint:eslint": "eslint source ./*js",
|
|
21
22
|
"lint:tsc": "tsc --noEmit",
|
|
22
23
|
"npm:publish": "npm publish",
|
|
23
24
|
"npm:publish:major": "npm version major && npm publish",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
"@typescript-eslint/parser": "6.9.0",
|
|
34
35
|
"esbuild": "0.19.5",
|
|
35
36
|
"eslint": "8.52.0",
|
|
37
|
+
"eslint-plugin-jsdoc": "46.8.2",
|
|
36
38
|
"lint-staged": "15.0.2",
|
|
37
39
|
"prettier": "3.0.3",
|
|
38
40
|
"prettier-package-json": "2.8.0",
|