@oliversalzburg/js-utils 0.0.3 → 0.0.5

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.
Files changed (104) hide show
  1. package/coverage/base.css +224 -0
  2. package/coverage/block-navigation.js +87 -0
  3. package/coverage/bundle.js +30 -0
  4. package/coverage/favicon.png +0 -0
  5. package/coverage/index.html +16 -0
  6. package/coverage/prettify.css +1 -0
  7. package/coverage/prettify.js +2 -0
  8. package/coverage/sort-arrow-sprite.png +0 -0
  9. package/coverage/sorter.js +196 -0
  10. package/coverage/spa.css +298 -0
  11. package/coverage/string-formatter.ts.html +187 -0
  12. package/coverage/tmp/coverage-4186-1699218521999-0.json +1 -0
  13. package/coverage/tmp/coverage-4196-1699218521967-0.json +1 -0
  14. package/docs/README.md +3 -0
  15. package/docs/classes/AbstractError.md +271 -0
  16. package/docs/classes/Canvas.md +177 -0
  17. package/docs/classes/InternalError.md +301 -0
  18. package/docs/classes/InvalidArgumentError.md +277 -0
  19. package/docs/classes/InvalidOperationError.md +277 -0
  20. package/docs/classes/NotImplementedError.md +276 -0
  21. package/docs/classes/PermissionViolationError.md +277 -0
  22. package/docs/classes/Random.md +109 -0
  23. package/docs/classes/RenderLoop.md +49 -0
  24. package/docs/classes/ResourceConflictError.md +276 -0
  25. package/docs/classes/UnexpectedNilError.md +169 -0
  26. package/docs/classes/UnknownError.md +280 -0
  27. package/docs/classes/Vector2.md +79 -0
  28. package/docs/classes/Vector3.md +106 -0
  29. package/docs/modules.md +1313 -0
  30. package/mkdocs.yml +52 -0
  31. package/output/core.d.ts +18 -1
  32. package/output/core.js +1 -0
  33. package/output/core.js.map +1 -1
  34. package/output/error-serializer.d.ts +37 -0
  35. package/output/error-serializer.js +63 -0
  36. package/output/error-serializer.js.map +1 -0
  37. package/output/errors/AbstractError.d.ts +42 -0
  38. package/output/errors/AbstractError.js +70 -0
  39. package/output/errors/AbstractError.js.map +1 -0
  40. package/output/errors/InternalError.d.ts +19 -0
  41. package/output/errors/InternalError.js +38 -0
  42. package/output/errors/InternalError.js.map +1 -0
  43. package/output/errors/InvalidArgumentError.d.ts +13 -0
  44. package/output/errors/InvalidArgumentError.js +20 -0
  45. package/output/errors/InvalidArgumentError.js.map +1 -0
  46. package/output/errors/InvalidOperationError.d.ts +13 -0
  47. package/output/errors/InvalidOperationError.js +20 -0
  48. package/output/errors/InvalidOperationError.js.map +1 -0
  49. package/output/errors/NotImplementedError.d.ts +12 -0
  50. package/output/errors/NotImplementedError.js +19 -0
  51. package/output/errors/NotImplementedError.js.map +1 -0
  52. package/output/errors/PermissionViolationError.d.ts +13 -0
  53. package/output/errors/PermissionViolationError.js +20 -0
  54. package/output/errors/PermissionViolationError.js.map +1 -0
  55. package/output/errors/ResourceConflictError.d.ts +12 -0
  56. package/output/errors/ResourceConflictError.js +19 -0
  57. package/output/errors/ResourceConflictError.js.map +1 -0
  58. package/output/errors/UnknownError.d.ts +16 -0
  59. package/output/errors/UnknownError.js +23 -0
  60. package/output/errors/UnknownError.js.map +1 -0
  61. package/output/errors/index.d.ts +8 -0
  62. package/output/errors/index.js +9 -0
  63. package/output/errors/index.js.map +1 -0
  64. package/output/graphics/canvas.d.ts +80 -0
  65. package/output/graphics/canvas.js +164 -0
  66. package/output/graphics/canvas.js.map +1 -0
  67. package/output/graphics/core.d.ts +94 -0
  68. package/output/graphics/core.js +479 -0
  69. package/output/graphics/core.js.map +1 -0
  70. package/output/graphics/index.d.ts +3 -0
  71. package/output/graphics/index.js +4 -0
  72. package/output/graphics/index.js.map +1 -0
  73. package/output/graphics/render-loop.d.ts +20 -0
  74. package/output/graphics/render-loop.js +51 -0
  75. package/output/graphics/render-loop.js.map +1 -0
  76. package/output/index.d.ts +7 -0
  77. package/output/index.js +7 -0
  78. package/output/index.js.map +1 -1
  79. package/output/math/core.d.ts +46 -0
  80. package/output/math/core.js +72 -0
  81. package/output/math/core.js.map +1 -0
  82. package/output/math/index.d.ts +2 -0
  83. package/output/math/index.js +3 -0
  84. package/output/math/index.js.map +1 -0
  85. package/output/math/vector.d.ts +33 -0
  86. package/output/math/vector.js +42 -0
  87. package/output/math/vector.js.map +1 -0
  88. package/output/nil.d.ts +13 -8
  89. package/output/nil.js +16 -11
  90. package/output/nil.js.map +1 -1
  91. package/output/random.d.ts +56 -0
  92. package/output/random.js +184 -0
  93. package/output/random.js.map +1 -0
  94. package/output/string-formatter.d.ts +20 -0
  95. package/output/string-formatter.js +26 -0
  96. package/output/string-formatter.js.map +1 -0
  97. package/output/string-formatter.test.d.ts +1 -0
  98. package/output/string-formatter.test.js +17 -0
  99. package/output/string-formatter.test.js.map +1 -0
  100. package/output/vector.d.ts +10 -0
  101. package/output/vector.js +19 -0
  102. package/output/vector.js.map +1 -0
  103. package/package.json +23 -7
  104. package/typedoc.json +8 -0
package/mkdocs.yml ADDED
@@ -0,0 +1,52 @@
1
+ copyright: Oliver Salzburg
2
+ dev_addr: 0.0.0.0:8000
3
+ docs_dir: docs
4
+ extra:
5
+ social:
6
+ - icon: fontawesome/brands/github
7
+ link: https://github.com/oliversalzburg/
8
+ markdown_extensions:
9
+ - abbr
10
+ - admonition
11
+ - pymdownx.details
12
+ - pymdownx.highlight:
13
+ anchor_linenums: true
14
+ - pymdownx.inlinehilite
15
+ - pymdownx.snippets
16
+ - pymdownx.superfences:
17
+ - pymdownx.tabbed:
18
+ alternate_style: true
19
+ - pymdownx.tilde
20
+ - toc:
21
+ permalink: true
22
+ plugins:
23
+ - search
24
+ repo_name: oliversalzburg/js-utils
25
+ repo_url: https://github.com/oliversalzburg/js-utils
26
+ site_name: JS Utils
27
+ theme:
28
+ favicon: assets/images/favicon.ico
29
+ features:
30
+ - content.code.copy
31
+ - navigation.instant
32
+ - navigation.sections
33
+ - navigation.tabs
34
+ - navigation.tabs.sticky
35
+ icon:
36
+ repo: fontawesome/brands/github
37
+ name: material
38
+ palette:
39
+ - media: "(prefers-color-scheme: light)"
40
+ scheme: default
41
+ accent: amber
42
+ primary: indigo
43
+ toggle:
44
+ icon: material/toggle-switch-off-outline
45
+ name: Switch to dark mode
46
+ - media: "(prefers-color-scheme: dark)"
47
+ scheme: slate
48
+ accent: indigo
49
+ primary: amber
50
+ toggle:
51
+ icon: material/toggle-switch
52
+ name: Switch to light mode
package/output/core.d.ts CHANGED
@@ -1,4 +1,21 @@
1
1
  /**
2
2
  * Describes a function that is a constructor for T.
3
3
  */
4
- export type ConstructorOf<T = Record<string, unknown>> = new (...args: any[]) => T;
4
+ export type ConstructorOf<T = Record<string, unknown>> = new (...args: Array<any>) => T;
5
+ /**
6
+ * Describes literally any function.
7
+ */
8
+ export type AnyFunction = (...args: Array<any>) => any;
9
+ /**
10
+ * Any constructor
11
+ */
12
+ export type AnyConstructor = new (...args: Array<any>) => any;
13
+ /**
14
+ * Describes a function returning an instance of T.
15
+ */
16
+ export type FunctionReturning<T = any> = (...args: Array<any>) => T;
17
+ /**
18
+ * Describes a class "mixin", which is a function that returns a dynamically
19
+ * constructed class, based on the passed parameters.
20
+ */
21
+ export type Mixin<T extends FunctionReturning> = InstanceType<ReturnType<T>>;
package/output/core.js CHANGED
@@ -1,2 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  export {};
2
3
  //# sourceMappingURL=core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":"AAAA,uDAAuD"}
@@ -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,42 @@
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 {@link 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
+ /**
34
+ * Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
35
+ * @param error The object to check.
36
+ * @param allowForeignModule Only check for similar looking error codes.
37
+ * You're going to want to use this if you're dealing with a setup where
38
+ * multiple versions of js-utils are loaded.
39
+ * @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
40
+ */
41
+ static isAbstractError(error: unknown, allowForeignModule?: boolean): error is AbstractError;
42
+ }
@@ -0,0 +1,70 @@
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 {@link 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
+ /**
42
+ * Checks if an object is an instance of {@link AbstractError}, or one of its subclasses.
43
+ * @param error The object to check.
44
+ * @param allowForeignModule Only check for similar looking error codes.
45
+ * You're going to want to use this if you're dealing with a setup where
46
+ * multiple versions of js-utils are loaded.
47
+ * @returns `true` if the object is an {@link AbstractError}, `false` otherwise.
48
+ */
49
+ static isAbstractError(error, allowForeignModule = true) {
50
+ if (error instanceof AbstractError) {
51
+ return true;
52
+ }
53
+ // When multiple versions of js-utils are loaded at runtime, the
54
+ // prototypes of errors don't align. In that case, we just analyze the
55
+ // error code.
56
+ if (allowForeignModule) {
57
+ const errorRecord = error;
58
+ if (Object(error) === error &&
59
+ "code" in errorRecord &&
60
+ typeof errorRecord.code === "string") {
61
+ const codedError = error;
62
+ if (codedError.code.match(/^ERR_OS_/)) {
63
+ return true;
64
+ }
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+ }
70
+ //# 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;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,KAAc,EAAE,kBAAkB,GAAG,IAAI;QAC9D,IAAI,KAAK,YAAY,aAAa,EAAE;YAClC,OAAO,IAAI,CAAC;SACb;QAED,gEAAgE;QAChE,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,19 @@
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 {@link 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
+ /**
14
+ * Converts an error into an {@link InternalError}.
15
+ * @param error The error to convert.
16
+ * @returns An {@link InternalError} that represents the given error.
17
+ */
18
+ static fromError(error: Error): InternalError;
19
+ }
@@ -0,0 +1,38 @@
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 {@link 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
+ /**
20
+ * Converts an error into an {@link InternalError}.
21
+ * @param error The error to convert.
22
+ * @returns An {@link InternalError} that represents the given error.
23
+ */
24
+ static fromError(error) {
25
+ // Create a _real_ `InternalError` instance, which we will return later.
26
+ const internalError = new InternalError(error.message);
27
+ // Assign the error to it, to inherit all the fields in the error.
28
+ // Then assign another `InternalError` to replace key fields, like:
29
+ // name, code, status, ...
30
+ Object.assign(internalError, error, new InternalError(error.message));
31
+ // Set the inner error.
32
+ internalError.inner = error;
33
+ // Inherit the original error stack again.
34
+ internalError.stack = error.stack;
35
+ return internalError;
36
+ }
37
+ }
38
+ //# 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;;;;OAIG;IACH,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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link 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 {@link InternalError}.
8
+ */
9
+ export declare class UnknownError extends AbstractError {
10
+ /**
11
+ * Constructs a new {@link 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 {@link InternalError}.
8
+ */
9
+ export class UnknownError extends AbstractError {
10
+ /**
11
+ * Constructs a new {@link 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"}