@nhtio/swarm 1.20251110.0 → 1.20260111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ class SwarmError extends Error {
6
+ /**
7
+ * Creates a new SwarmError instance.
8
+ * @param message The error message.
9
+ * @param options The error options.
10
+ */
11
+ constructor(message, options) {
12
+ const superOptions = options ? { cause: options.cause } : {};
13
+ super(message, superOptions);
14
+ /** @private */
15
+ __publicField(this, "$__name");
16
+ /** @private */
17
+ __publicField(this, "$__message");
18
+ const ErrorConstructor = this.constructor;
19
+ Object.setPrototypeOf(this, ErrorConstructor);
20
+ this.$__name = ErrorConstructor.name;
21
+ this.$__message = message;
22
+ if ("function" === typeof Error.captureStackTrace) {
23
+ Error.captureStackTrace(this, ErrorConstructor);
24
+ }
25
+ if (this.stack && options && options.trim && options.trim > 0) {
26
+ const stackLines = this.stack.split("\n");
27
+ stackLines.splice(0, options.trim);
28
+ this.stack = stackLines.join("\n");
29
+ }
30
+ }
31
+ get name() {
32
+ return this.$__name;
33
+ }
34
+ get message() {
35
+ return this.$__message;
36
+ }
37
+ get [Symbol.toStringTag]() {
38
+ return this.constructor.name;
39
+ }
40
+ toString() {
41
+ return `${this.name}: ${this.message}`;
42
+ }
43
+ [Symbol.toPrimitive](hint) {
44
+ switch (hint) {
45
+ case "string":
46
+ return this.toString();
47
+ default:
48
+ return true;
49
+ }
50
+ }
51
+ static [Symbol.hasInstance](instance) {
52
+ if (typeof instance === "object" && instance !== null || typeof instance === "function") {
53
+ const proto = Object.getPrototypeOf(instance);
54
+ return proto.name === this.name || proto === this;
55
+ }
56
+ return false;
57
+ }
58
+ }
59
+ class UnsupportedEnvironmentError extends SwarmError {
60
+ constructor() {
61
+ super("Unable to setup instance because Service Workers are not supported in this environment");
62
+ }
63
+ }
64
+ class AlreadyInitializedInContextError extends SwarmError {
65
+ constructor() {
66
+ super(
67
+ "Unable to setup instance because another instance is already initialized in this context"
68
+ );
69
+ }
70
+ }
71
+ class RequestTimeoutError extends SwarmError {
72
+ constructor(event) {
73
+ super(`Request timed out while waiting for event "${String(event)}".`);
74
+ }
75
+ }
76
+ class MissingEncryptionKey extends SwarmError {
77
+ constructor() {
78
+ super(`An encryption key has not been provided at any point in the runtime.`);
79
+ }
80
+ }
81
+ const errors = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
82
+ __proto__: null,
83
+ AlreadyInitializedInContextError,
84
+ MissingEncryptionKey,
85
+ RequestTimeoutError,
86
+ UnsupportedEnvironmentError
87
+ }, Symbol.toStringTag, { value: "Module" }));
88
+ exports.AlreadyInitializedInContextError = AlreadyInitializedInContextError;
89
+ exports.MissingEncryptionKey = MissingEncryptionKey;
90
+ exports.RequestTimeoutError = RequestTimeoutError;
91
+ exports.UnsupportedEnvironmentError = UnsupportedEnvironmentError;
92
+ exports.errors = errors;
93
+ //# sourceMappingURL=errors-B7SDj7bo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-j8BTGk4y.js","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Easily accessible error classes for Swarm\n * @module @nhtio/swarm/errors\n */\n\n/**\n * Describes the options for the SwarmError class.\n */\nexport interface SwarmErrorOptions {\n /**\n * The cause data property of an Error instance indicates the specific original cause of the error.\n */\n cause?: Error\n /**\n * How many rows to trim from the stack trace.\n * This is useful for removing the stack trace of the current function from the error.\n */\n trim?: number\n}\n\n/**\n * Base class for all Swarm errors.\n * @extends Error\n */\nclass SwarmError extends Error {\n /** @private */\n readonly $__name: string\n /** @private */\n readonly $__message: string\n\n /**\n * Creates a new SwarmError instance.\n * @param message The error message.\n * @param options The error options.\n */\n constructor(message: string, options?: SwarmErrorOptions) {\n const superOptions = options ? { cause: options.cause } : {}\n super(message, superOptions)\n const ErrorConstructor = this.constructor\n Object.setPrototypeOf(this, ErrorConstructor)\n this.$__name = ErrorConstructor.name\n this.$__message = message\n if ('function' === typeof Error.captureStackTrace) {\n Error.captureStackTrace(this, ErrorConstructor)\n }\n if (this.stack && options && options.trim && options.trim > 0) {\n const stackLines = this.stack.split('\\n')\n stackLines.splice(0, options.trim)\n this.stack = stackLines.join('\\n')\n }\n }\n\n get name() {\n return this.$__name\n }\n\n get message() {\n return this.$__message\n }\n\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default') {\n switch (hint) {\n case 'string':\n return this.toString()\n default:\n return true\n }\n }\n\n static [Symbol.hasInstance](instance: unknown) {\n if ((typeof instance === 'object' && instance !== null) || typeof instance === 'function') {\n const proto = Object.getPrototypeOf(instance)\n return proto.name === this.name || proto === this\n }\n return false\n }\n}\n\nexport type { SwarmError }\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.\n */\nexport class UnsupportedEnvironmentError extends SwarmError {\n constructor() {\n super('Unable to setup instance because Service Workers are not supported in this environment')\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.\n */\nexport class AlreadyInitializedInContextError extends SwarmError {\n constructor() {\n super(\n 'Unable to setup instance because another instance is already initialized in this context'\n )\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.\n */\nexport class RequestTimeoutError extends SwarmError {\n constructor(event: string | number | symbol) {\n super(`Request timed out while waiting for event \"${String(event)}\".`)\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.\n */\nexport class MissingEncryptionKey extends SwarmError {\n constructor() {\n super(`An encryption key has not been provided at any point in the runtime.`)\n }\n}\n"],"names":["SwarmError","message","options","superOptions","__publicField","ErrorConstructor","stackLines","hint","instance","proto","UnsupportedEnvironmentError","AlreadyInitializedInContextError","RequestTimeoutError","event","MissingEncryptionKey"],"mappings":"iLAwBA,MAAMA,UAAmB,KAAM,CAW7B,YAAYC,EAAiBC,EAA6B,CACxD,MAAMC,EAAeD,EAAU,CAAE,MAAOA,EAAQ,OAAU,GAC1D,MAAMD,EAASE,CAAY,EAXpBC,EAAA,gBAEAA,EAAA,mBAUP,MAAMC,EAAmB,KAAK,YAO9B,GANO,OAAA,eAAe,KAAMA,CAAgB,EAC5C,KAAK,QAAUA,EAAiB,KAChC,KAAK,WAAaJ,EACC,OAAO,MAAM,mBAA5B,YACI,MAAA,kBAAkB,KAAMI,CAAgB,EAE5C,KAAK,OAASH,GAAWA,EAAQ,MAAQA,EAAQ,KAAO,EAAG,CAC7D,MAAMI,EAAa,KAAK,MAAM,MAAM;AAAA,CAAI,EAC7BA,EAAA,OAAO,EAAGJ,EAAQ,IAAI,EAC5B,KAAA,MAAQI,EAAW,KAAK;AAAA,CAAI,CACnC,CACF,CAEA,IAAI,MAAO,CACT,OAAO,KAAK,OACd,CAEA,IAAI,SAAU,CACZ,OAAO,KAAK,UACd,CAEA,IAAK,OAAO,WAAW,GAAI,CACzB,OAAO,KAAK,YAAY,IAC1B,CAEA,UAAW,CACT,MAAO,GAAG,KAAK,IAAI,KAAK,KAAK,OAAO,EACtC,CAEA,CAAC,OAAO,WAAW,EAAEC,EAAuC,CAC1D,OAAQA,EAAM,CACZ,IAAK,SACH,OAAO,KAAK,WACd,QACS,MAAA,EACX,CACF,CAEA,OAAQ,OAAO,WAAW,EAAEC,EAAmB,CAC7C,GAAK,OAAOA,GAAa,UAAYA,IAAa,MAAS,OAAOA,GAAa,WAAY,CACnF,MAAAC,EAAQ,OAAO,eAAeD,CAAQ,EAC5C,OAAOC,EAAM,OAAS,KAAK,MAAQA,IAAU,IAC/C,CACO,MAAA,EACT,CACF,CAOO,MAAMC,UAAoCV,CAAW,CAC1D,aAAc,CACZ,MAAM,wFAAwF,CAChG,CACF,CAKO,MAAMW,UAAyCX,CAAW,CAC/D,aAAc,CACZ,MACE,0FAAA,CAEJ,CACF,CAKO,MAAMY,UAA4BZ,CAAW,CAClD,YAAYa,EAAiC,CAC3C,MAAM,8CAA8C,OAAOA,CAAK,CAAC,IAAI,CACvE,CACF,CAKO,MAAMC,UAA6Bd,CAAW,CACnD,aAAc,CACZ,MAAM,sEAAsE,CAC9E,CACF"}
1
+ {"version":3,"file":"errors-B7SDj7bo.js","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Easily accessible error classes for Swarm\n * @module @nhtio/swarm/errors\n */\n\n/**\n * Describes the options for the SwarmError class.\n */\nexport interface SwarmErrorOptions {\n /**\n * The cause data property of an Error instance indicates the specific original cause of the error.\n */\n cause?: Error\n /**\n * How many rows to trim from the stack trace.\n * This is useful for removing the stack trace of the current function from the error.\n */\n trim?: number\n}\n\n/**\n * Base class for all Swarm errors.\n * @extends Error\n */\nclass SwarmError extends Error {\n /** @private */\n readonly $__name: string\n /** @private */\n readonly $__message: string\n\n /**\n * Creates a new SwarmError instance.\n * @param message The error message.\n * @param options The error options.\n */\n constructor(message: string, options?: SwarmErrorOptions) {\n const superOptions = options ? { cause: options.cause } : {}\n super(message, superOptions)\n const ErrorConstructor = this.constructor\n Object.setPrototypeOf(this, ErrorConstructor)\n this.$__name = ErrorConstructor.name\n this.$__message = message\n if ('function' === typeof Error.captureStackTrace) {\n Error.captureStackTrace(this, ErrorConstructor)\n }\n if (this.stack && options && options.trim && options.trim > 0) {\n const stackLines = this.stack.split('\\n')\n stackLines.splice(0, options.trim)\n this.stack = stackLines.join('\\n')\n }\n }\n\n get name() {\n return this.$__name\n }\n\n get message() {\n return this.$__message\n }\n\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default') {\n switch (hint) {\n case 'string':\n return this.toString()\n default:\n return true\n }\n }\n\n static [Symbol.hasInstance](instance: unknown) {\n if ((typeof instance === 'object' && instance !== null) || typeof instance === 'function') {\n const proto = Object.getPrototypeOf(instance)\n return proto.name === this.name || proto === this\n }\n return false\n }\n}\n\nexport type { SwarmError }\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.\n */\nexport class UnsupportedEnvironmentError extends SwarmError {\n constructor() {\n super('Unable to setup instance because Service Workers are not supported in this environment')\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.\n */\nexport class AlreadyInitializedInContextError extends SwarmError {\n constructor() {\n super(\n 'Unable to setup instance because another instance is already initialized in this context'\n )\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.\n */\nexport class RequestTimeoutError extends SwarmError {\n constructor(event: string | number | symbol) {\n super(`Request timed out while waiting for event \"${String(event)}\".`)\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.\n */\nexport class MissingEncryptionKey extends SwarmError {\n constructor() {\n super(`An encryption key has not been provided at any point in the runtime.`)\n }\n}\n"],"names":[],"mappings":";;;;AAwBA,MAAM,mBAAmB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW7B,YAAY,SAAiB,SAA6B;AACxD,UAAM,eAAe,UAAU,EAAE,OAAO,QAAQ,UAAU;AAC1D,UAAM,SAAS,YAAY;AAXpB;AAAA;AAEA;AAAA;AAUP,UAAM,mBAAmB,KAAK;AACvB,WAAA,eAAe,MAAM,gBAAgB;AAC5C,SAAK,UAAU,iBAAiB;AAChC,SAAK,aAAa;AACd,QAAA,eAAe,OAAO,MAAM,mBAAmB;AAC3C,YAAA,kBAAk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;;;;;;;;;"}
@@ -0,0 +1,94 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ class SwarmError extends Error {
5
+ /**
6
+ * Creates a new SwarmError instance.
7
+ * @param message The error message.
8
+ * @param options The error options.
9
+ */
10
+ constructor(message, options) {
11
+ const superOptions = options ? { cause: options.cause } : {};
12
+ super(message, superOptions);
13
+ /** @private */
14
+ __publicField(this, "$__name");
15
+ /** @private */
16
+ __publicField(this, "$__message");
17
+ const ErrorConstructor = this.constructor;
18
+ Object.setPrototypeOf(this, ErrorConstructor);
19
+ this.$__name = ErrorConstructor.name;
20
+ this.$__message = message;
21
+ if ("function" === typeof Error.captureStackTrace) {
22
+ Error.captureStackTrace(this, ErrorConstructor);
23
+ }
24
+ if (this.stack && options && options.trim && options.trim > 0) {
25
+ const stackLines = this.stack.split("\n");
26
+ stackLines.splice(0, options.trim);
27
+ this.stack = stackLines.join("\n");
28
+ }
29
+ }
30
+ get name() {
31
+ return this.$__name;
32
+ }
33
+ get message() {
34
+ return this.$__message;
35
+ }
36
+ get [Symbol.toStringTag]() {
37
+ return this.constructor.name;
38
+ }
39
+ toString() {
40
+ return `${this.name}: ${this.message}`;
41
+ }
42
+ [Symbol.toPrimitive](hint) {
43
+ switch (hint) {
44
+ case "string":
45
+ return this.toString();
46
+ default:
47
+ return true;
48
+ }
49
+ }
50
+ static [Symbol.hasInstance](instance) {
51
+ if (typeof instance === "object" && instance !== null || typeof instance === "function") {
52
+ const proto = Object.getPrototypeOf(instance);
53
+ return proto.name === this.name || proto === this;
54
+ }
55
+ return false;
56
+ }
57
+ }
58
+ class UnsupportedEnvironmentError extends SwarmError {
59
+ constructor() {
60
+ super("Unable to setup instance because Service Workers are not supported in this environment");
61
+ }
62
+ }
63
+ class AlreadyInitializedInContextError extends SwarmError {
64
+ constructor() {
65
+ super(
66
+ "Unable to setup instance because another instance is already initialized in this context"
67
+ );
68
+ }
69
+ }
70
+ class RequestTimeoutError extends SwarmError {
71
+ constructor(event) {
72
+ super(`Request timed out while waiting for event "${String(event)}".`);
73
+ }
74
+ }
75
+ class MissingEncryptionKey extends SwarmError {
76
+ constructor() {
77
+ super(`An encryption key has not been provided at any point in the runtime.`);
78
+ }
79
+ }
80
+ const errors = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
81
+ __proto__: null,
82
+ AlreadyInitializedInContextError,
83
+ MissingEncryptionKey,
84
+ RequestTimeoutError,
85
+ UnsupportedEnvironmentError
86
+ }, Symbol.toStringTag, { value: "Module" }));
87
+ export {
88
+ AlreadyInitializedInContextError as A,
89
+ MissingEncryptionKey as M,
90
+ RequestTimeoutError as R,
91
+ UnsupportedEnvironmentError as U,
92
+ errors as e
93
+ };
94
+ //# sourceMappingURL=errors-Bgn2zMF7.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-Cqo3rABf.mjs","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Easily accessible error classes for Swarm\n * @module @nhtio/swarm/errors\n */\n\n/**\n * Describes the options for the SwarmError class.\n */\nexport interface SwarmErrorOptions {\n /**\n * The cause data property of an Error instance indicates the specific original cause of the error.\n */\n cause?: Error\n /**\n * How many rows to trim from the stack trace.\n * This is useful for removing the stack trace of the current function from the error.\n */\n trim?: number\n}\n\n/**\n * Base class for all Swarm errors.\n * @extends Error\n */\nclass SwarmError extends Error {\n /** @private */\n readonly $__name: string\n /** @private */\n readonly $__message: string\n\n /**\n * Creates a new SwarmError instance.\n * @param message The error message.\n * @param options The error options.\n */\n constructor(message: string, options?: SwarmErrorOptions) {\n const superOptions = options ? { cause: options.cause } : {}\n super(message, superOptions)\n const ErrorConstructor = this.constructor\n Object.setPrototypeOf(this, ErrorConstructor)\n this.$__name = ErrorConstructor.name\n this.$__message = message\n if ('function' === typeof Error.captureStackTrace) {\n Error.captureStackTrace(this, ErrorConstructor)\n }\n if (this.stack && options && options.trim && options.trim > 0) {\n const stackLines = this.stack.split('\\n')\n stackLines.splice(0, options.trim)\n this.stack = stackLines.join('\\n')\n }\n }\n\n get name() {\n return this.$__name\n }\n\n get message() {\n return this.$__message\n }\n\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default') {\n switch (hint) {\n case 'string':\n return this.toString()\n default:\n return true\n }\n }\n\n static [Symbol.hasInstance](instance: unknown) {\n if ((typeof instance === 'object' && instance !== null) || typeof instance === 'function') {\n const proto = Object.getPrototypeOf(instance)\n return proto.name === this.name || proto === this\n }\n return false\n }\n}\n\nexport type { SwarmError }\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.\n */\nexport class UnsupportedEnvironmentError extends SwarmError {\n constructor() {\n super('Unable to setup instance because Service Workers are not supported in this environment')\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.\n */\nexport class AlreadyInitializedInContextError extends SwarmError {\n constructor() {\n super(\n 'Unable to setup instance because another instance is already initialized in this context'\n )\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.\n */\nexport class RequestTimeoutError extends SwarmError {\n constructor(event: string | number | symbol) {\n super(`Request timed out while waiting for event \"${String(event)}\".`)\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.\n */\nexport class MissingEncryptionKey extends SwarmError {\n constructor() {\n super(`An encryption key has not been provided at any point in the runtime.`)\n }\n}\n"],"names":["SwarmError","message","options","superOptions","__publicField","ErrorConstructor","stackLines","hint","instance","proto","UnsupportedEnvironmentError","AlreadyInitializedInContextError","RequestTimeoutError","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,MAAU;AAAA,IAC/C;AACO,WAAA;AAAA,EACT;AACF;AAOO,MAAMC,UAAoCV,EAAW;AAAA,EAC1D,cAAc;AACZ,UAAM,wFAAwF;AAAA,EAChG;AACF;AAKO,MAAMW,UAAyCX,EAAW;AAAA,EAC/D,cAAc;AACZ;AAAA,MACE;AAAA,IAAA;AAAA,EAEJ;AACF;AAKO,MAAMY,UAA4BZ,EAAW;AAAA,EAClD,YAAYa,GAAiC;AAC3C,UAAM,8CAA8C,OAAOA,CAAK,CAAC,IAAI;AAAA,EACvE;AACF;AAKO,MAAMC,UAA6Bd,EAAW;AAAA,EACnD,cAAc;AACZ,UAAM,sEAAsE;AAAA,EAC9E;AACF;;;;;;;;"}
1
+ {"version":3,"file":"errors-Bgn2zMF7.mjs","sources":["../src/errors.ts"],"sourcesContent":["/**\n * Easily accessible error classes for Swarm\n * @module @nhtio/swarm/errors\n */\n\n/**\n * Describes the options for the SwarmError class.\n */\nexport interface SwarmErrorOptions {\n /**\n * The cause data property of an Error instance indicates the specific original cause of the error.\n */\n cause?: Error\n /**\n * How many rows to trim from the stack trace.\n * This is useful for removing the stack trace of the current function from the error.\n */\n trim?: number\n}\n\n/**\n * Base class for all Swarm errors.\n * @extends Error\n */\nclass SwarmError extends Error {\n /** @private */\n readonly $__name: string\n /** @private */\n readonly $__message: string\n\n /**\n * Creates a new SwarmError instance.\n * @param message The error message.\n * @param options The error options.\n */\n constructor(message: string, options?: SwarmErrorOptions) {\n const superOptions = options ? { cause: options.cause } : {}\n super(message, superOptions)\n const ErrorConstructor = this.constructor\n Object.setPrototypeOf(this, ErrorConstructor)\n this.$__name = ErrorConstructor.name\n this.$__message = message\n if ('function' === typeof Error.captureStackTrace) {\n Error.captureStackTrace(this, ErrorConstructor)\n }\n if (this.stack && options && options.trim && options.trim > 0) {\n const stackLines = this.stack.split('\\n')\n stackLines.splice(0, options.trim)\n this.stack = stackLines.join('\\n')\n }\n }\n\n get name() {\n return this.$__name\n }\n\n get message() {\n return this.$__message\n }\n\n get [Symbol.toStringTag]() {\n return this.constructor.name\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default') {\n switch (hint) {\n case 'string':\n return this.toString()\n default:\n return true\n }\n }\n\n static [Symbol.hasInstance](instance: unknown) {\n if ((typeof instance === 'object' && instance !== null) || typeof instance === 'function') {\n const proto = Object.getPrototypeOf(instance)\n return proto.name === this.name || proto === this\n }\n return false\n }\n}\n\nexport type { SwarmError }\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.\n */\nexport class UnsupportedEnvironmentError extends SwarmError {\n constructor() {\n super('Unable to setup instance because Service Workers are not supported in this environment')\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.\n */\nexport class AlreadyInitializedInContextError extends SwarmError {\n constructor() {\n super(\n 'Unable to setup instance because another instance is already initialized in this context'\n )\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.\n */\nexport class RequestTimeoutError extends SwarmError {\n constructor(event: string | number | symbol) {\n super(`Request timed out while waiting for event \"${String(event)}\".`)\n }\n}\n\n/**\n * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.\n */\nexport class MissingEncryptionKey extends SwarmError {\n constructor() {\n super(`An encryption key has not been provided at any point in the runtime.`)\n }\n}\n"],"names":[],"mappings":";;;AAwBA,MAAM,mBAAmB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW7B,YAAY,SAAiB,SAA6B;AACxD,UAAM,eAAe,UAAU,EAAE,OAAO,QAAQ,UAAU;AAC1D,UAAM,SAAS,YAAY;AAXpB;AAAA;AAEA;AAAA;AAUP,UAAM,mBAAmB,KAAK;AACvB,WAAA,eAAe,MAAM,gBAAgB;AAC5C,SAAK,UAAU,iBAAiB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,6BAA6B,WAAW;AAAA,EACnD,cAAc;AACZ,UAAM,sEAAsE;AAAA,EAC9E;AACF;;;;;;;;"}
package/errors.cjs CHANGED
@@ -1,2 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./errors-j8BTGk4y.js");exports.AlreadyInitializedInContextError=r.AlreadyInitializedInContextError;exports.MissingEncryptionKey=r.MissingEncryptionKey;exports.RequestTimeoutError=r.RequestTimeoutError;exports.UnsupportedEnvironmentError=r.UnsupportedEnvironmentError;
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const errors = require("./errors-B7SDj7bo.js");
4
+ exports.AlreadyInitializedInContextError = errors.AlreadyInitializedInContextError;
5
+ exports.MissingEncryptionKey = errors.MissingEncryptionKey;
6
+ exports.RequestTimeoutError = errors.RequestTimeoutError;
7
+ exports.UnsupportedEnvironmentError = errors.UnsupportedEnvironmentError;
2
8
  //# sourceMappingURL=errors.cjs.map
package/errors.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"errors.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/errors.d.ts CHANGED
@@ -1,65 +1,71 @@
1
- /**
2
- * Easily accessible error classes for Swarm
3
- * @module @nhtio/swarm/errors
4
- */
5
- /**
6
- * Describes the options for the SwarmError class.
7
- */
8
- export interface SwarmErrorOptions {
9
- /**
10
- * The cause data property of an Error instance indicates the specific original cause of the error.
11
- */
12
- cause?: Error;
13
- /**
14
- * How many rows to trim from the stack trace.
15
- * This is useful for removing the stack trace of the current function from the error.
16
- */
17
- trim?: number;
18
- }
19
- /**
20
- * Base class for all Swarm errors.
21
- * @extends Error
22
- */
23
- declare class SwarmError extends Error {
24
- /** @private */
25
- readonly $__name: string;
26
- /** @private */
27
- readonly $__message: string;
28
- /**
29
- * Creates a new SwarmError instance.
30
- * @param message The error message.
31
- * @param options The error options.
32
- */
33
- constructor(message: string, options?: SwarmErrorOptions);
34
- get name(): string;
35
- get message(): string;
36
- get [Symbol.toStringTag](): string;
37
- toString(): string;
38
- [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): string | true;
39
- static [Symbol.hasInstance](instance: unknown): boolean;
40
- }
41
- export type { SwarmError };
42
- /**
43
- * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.
44
- */
45
- export declare class UnsupportedEnvironmentError extends SwarmError {
46
- constructor();
47
- }
48
- /**
49
- * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.
50
- */
51
- export declare class AlreadyInitializedInContextError extends SwarmError {
52
- constructor();
53
- }
54
- /**
55
- * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.
56
- */
57
- export declare class RequestTimeoutError extends SwarmError {
58
- constructor(event: string | number | symbol);
59
- }
60
- /**
61
- * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.
62
- */
63
- export declare class MissingEncryptionKey extends SwarmError {
64
- constructor();
65
- }
1
+ /**
2
+ * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialize more than one instance within the same context.
3
+ */
4
+ export declare class AlreadyInitializedInContextError extends SwarmError {
5
+ constructor();
6
+ }
7
+
8
+ /**
9
+ * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class trying to retrieve an instance without having previously or currently provided an encryption key.
10
+ */
11
+ export declare class MissingEncryptionKey extends SwarmError {
12
+ constructor();
13
+ }
14
+
15
+ /**
16
+ * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when a request to the leader is not answered.
17
+ */
18
+ export declare class RequestTimeoutError extends SwarmError {
19
+ constructor(event: string | number | symbol);
20
+ }
21
+
22
+ /**
23
+ * Base class for all Swarm errors.
24
+ * @extends Error
25
+ */
26
+ export declare class SwarmError extends Error {
27
+ /** @private */
28
+ readonly $__name: string;
29
+ /** @private */
30
+ readonly $__message: string;
31
+ /**
32
+ * Creates a new SwarmError instance.
33
+ * @param message The error message.
34
+ * @param options The error options.
35
+ */
36
+ constructor(message: string, options?: SwarmErrorOptions);
37
+ get name(): string;
38
+ get message(): string;
39
+ get [Symbol.toStringTag](): string;
40
+ toString(): string;
41
+ [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): string | true;
42
+ static [Symbol.hasInstance](instance: unknown): boolean;
43
+ }
44
+
45
+ /**
46
+ * Easily accessible error classes for Swarm
47
+ * @module @nhtio/swarm/errors
48
+ */
49
+ /**
50
+ * Describes the options for the SwarmError class.
51
+ */
52
+ export declare interface SwarmErrorOptions {
53
+ /**
54
+ * The cause data property of an Error instance indicates the specific original cause of the error.
55
+ */
56
+ cause?: Error;
57
+ /**
58
+ * How many rows to trim from the stack trace.
59
+ * This is useful for removing the stack trace of the current function from the error.
60
+ */
61
+ trim?: number;
62
+ }
63
+
64
+ /**
65
+ * Thrown by the {@link @nhtio/swarm!Swarm | Swarm} class when trying to be initialized in an environment that does not support Service Workers.
66
+ */
67
+ export declare class UnsupportedEnvironmentError extends SwarmError {
68
+ constructor();
69
+ }
70
+
71
+ export { }
package/errors.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { A as n, M as o, R as t, U as i } from "./errors-Cqo3rABf.mjs";
1
+ import { A, M, R, U } from "./errors-Bgn2zMF7.mjs";
2
2
  export {
3
- n as AlreadyInitializedInContextError,
4
- o as MissingEncryptionKey,
5
- t as RequestTimeoutError,
6
- i as UnsupportedEnvironmentError
3
+ A as AlreadyInitializedInContextError,
4
+ M as MissingEncryptionKey,
5
+ R as RequestTimeoutError,
6
+ U as UnsupportedEnvironmentError
7
7
  };
8
8
  //# sourceMappingURL=errors.mjs.map