@oliversalzburg/js-utils 0.0.3 → 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/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/string-formatter.d.ts +20 -0
- package/output/string-formatter.js +26 -0
- package/output/string-formatter.js.map +1 -0
- package/package.json +2 -1
|
@@ -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"}
|
|
@@ -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,6 +17,7 @@
|
|
|
17
17
|
"build": "yarn run build:tsc",
|
|
18
18
|
"build:esbuild": "node build.js",
|
|
19
19
|
"build:tsc": "tsc",
|
|
20
|
+
"lint": "yarn run lint:eslint && yarn run lint:tsc",
|
|
20
21
|
"lint:eslint": "eslint source ./*js",
|
|
21
22
|
"lint:tsc": "tsc --noEmit",
|
|
22
23
|
"npm:publish": "npm publish",
|