@nhtio/swarm 1.20250424.0 → 1.20250425.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{errors-BsRN4TW4.mjs → errors-Cqo3rABf.mjs} +26 -19
- package/{errors-BsRN4TW4.mjs.map → errors-Cqo3rABf.mjs.map} +1 -1
- package/errors-j8BTGk4y.js +4 -0
- package/{errors-DTZFdRbq.js.map → errors-j8BTGk4y.js.map} +1 -1
- package/errors.cjs +1 -1
- package/errors.d.ts +6 -0
- package/errors.mjs +4 -3
- package/index.cjs +47 -2
- package/index.cjs.map +1 -1
- package/index.d.ts +2 -0
- package/index.mjs +27553 -907
- package/index.mjs.map +1 -1
- package/lib/class_swarm.d.ts +5 -4
- package/lib/encryption.d.ts +9 -0
- package/lib/logger.d.ts +1 -1
- package/lib/symbols.d.ts +1 -0
- package/package.json +1 -1
- package/types.d.ts +1 -0
- package/errors-DTZFdRbq.js +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
|
-
var m = (
|
|
3
|
-
var
|
|
4
|
-
class
|
|
2
|
+
var m = (e, r, t) => r in e ? u(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var i = (e, r, t) => m(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
class n extends Error {
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new SwarmError instance.
|
|
7
7
|
* @param message The error message.
|
|
@@ -11,11 +11,11 @@ class i extends Error {
|
|
|
11
11
|
const c = s ? { cause: s.cause } : {};
|
|
12
12
|
super(t, c);
|
|
13
13
|
/** @private */
|
|
14
|
-
|
|
14
|
+
i(this, "$__name");
|
|
15
15
|
/** @private */
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
if (Object.setPrototypeOf(this,
|
|
16
|
+
i(this, "$__message");
|
|
17
|
+
const o = this.constructor;
|
|
18
|
+
if (Object.setPrototypeOf(this, o), this.$__name = o.name, this.$__message = t, typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, o), this.stack && s && s.trim && s.trim > 0) {
|
|
19
19
|
const a = this.stack.split(`
|
|
20
20
|
`);
|
|
21
21
|
a.splice(0, s.trim), this.stack = a.join(`
|
|
@@ -50,33 +50,40 @@ class i extends Error {
|
|
|
50
50
|
return !1;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
class l extends
|
|
53
|
+
class l extends n {
|
|
54
54
|
constructor() {
|
|
55
55
|
super("Unable to setup instance because Service Workers are not supported in this environment");
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
class
|
|
58
|
+
class p extends n {
|
|
59
59
|
constructor() {
|
|
60
60
|
super(
|
|
61
61
|
"Unable to setup instance because another instance is already initialized in this context"
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
class
|
|
66
|
-
constructor(
|
|
67
|
-
super(`Request timed out while waiting for event "${String(
|
|
65
|
+
class h extends n {
|
|
66
|
+
constructor(r) {
|
|
67
|
+
super(`Request timed out while waiting for event "${String(r)}".`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
class g extends n {
|
|
71
|
+
constructor() {
|
|
72
|
+
super("An encryption key has not been provided at any point in the runtime.");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
71
76
|
__proto__: null,
|
|
72
|
-
AlreadyInitializedInContextError:
|
|
73
|
-
|
|
77
|
+
AlreadyInitializedInContextError: p,
|
|
78
|
+
MissingEncryptionKey: g,
|
|
79
|
+
RequestTimeoutError: h,
|
|
74
80
|
UnsupportedEnvironmentError: l
|
|
75
81
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
76
82
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
p as A,
|
|
84
|
+
g as M,
|
|
85
|
+
h as R,
|
|
79
86
|
l as U,
|
|
80
|
-
|
|
87
|
+
y as e
|
|
81
88
|
};
|
|
82
|
-
//# sourceMappingURL=errors-
|
|
89
|
+
//# sourceMappingURL=errors-Cqo3rABf.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
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","event","MissingEncryptionKey"],"mappings":";;;AAwBA,MAAMA,UAAmB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW7B,YAAYC,GAAiBC,GAA6B;AACxD,UAAMC,IAAeD,IAAU,EAAE,OAAOA,EAAQ,UAAU;AAC1D,UAAMD,GAASE,CAAY;AAXpB;AAAA,IAAAC,EAAA;AAEA;AAAA,IAAAA,EAAA;AAUP,UAAMC,IAAmB,KAAK;AAO9B,QANO,OAAA,eAAe,MAAMA,CAAgB,GAC5C,KAAK,UAAUA,EAAiB,MAChC,KAAK,aAAaJ,GACC,OAAO,MAAM,qBAA5B,cACI,MAAA,kBAAkB,MAAMI,CAAgB,GAE5C,KAAK,SAASH,KAAW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@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var h=Object.defineProperty;var d=(e,r,t)=>r in e?h(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var i=(e,r,t)=>d(e,typeof r!="symbol"?r+"":r,t);class n extends Error{constructor(t,s){const p=s?{cause:s.cause}:{};super(t,p);i(this,"$__name");i(this,"$__message");const o=this.constructor;if(Object.setPrototypeOf(this,o),this.$__name=o.name,this.$__message=t,typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,o),this.stack&&s&&s.trim&&s.trim>0){const a=this.stack.split(`
|
|
2
|
+
`);a.splice(0,s.trim),this.stack=a.join(`
|
|
3
|
+
`)}}get name(){return this.$__name}get message(){return this.$__message}get[Symbol.toStringTag](){return this.constructor.name}toString(){return`${this.name}: ${this.message}`}[Symbol.toPrimitive](t){switch(t){case"string":return this.toString();default:return!0}}static[Symbol.hasInstance](t){if(typeof t=="object"&&t!==null||typeof t=="function"){const s=Object.getPrototypeOf(t);return s.name===this.name||s===this}return!1}}class c extends n{constructor(){super("Unable to setup instance because Service Workers are not supported in this environment")}}class u extends n{constructor(){super("Unable to setup instance because another instance is already initialized in this context")}}class m extends n{constructor(r){super(`Request timed out while waiting for event "${String(r)}".`)}}class l extends n{constructor(){super("An encryption key has not been provided at any point in the runtime.")}}const y=Object.freeze(Object.defineProperty({__proto__:null,AlreadyInitializedInContextError:u,MissingEncryptionKey:l,RequestTimeoutError:m,UnsupportedEnvironmentError:c},Symbol.toStringTag,{value:"Module"}));exports.AlreadyInitializedInContextError=u;exports.MissingEncryptionKey=l;exports.RequestTimeoutError=m;exports.UnsupportedEnvironmentError=c;exports.errors=y;
|
|
4
|
+
//# sourceMappingURL=errors-j8BTGk4y.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
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"}
|
package/errors.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./errors-
|
|
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;
|
|
2
2
|
//# sourceMappingURL=errors.cjs.map
|
package/errors.d.ts
CHANGED
|
@@ -57,3 +57,9 @@ export declare class AlreadyInitializedInContextError extends SwarmError {
|
|
|
57
57
|
export declare class RequestTimeoutError extends SwarmError {
|
|
58
58
|
constructor(event: string | number | symbol);
|
|
59
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
|
+
}
|
package/errors.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { A as o, R as t, U as
|
|
1
|
+
import { A as n, M as o, R as t, U as i } from "./errors-Cqo3rABf.mjs";
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
n as AlreadyInitializedInContextError,
|
|
4
|
+
o as MissingEncryptionKey,
|
|
4
5
|
t as RequestTimeoutError,
|
|
5
|
-
|
|
6
|
+
i as UnsupportedEnvironmentError
|
|
6
7
|
};
|
|
7
8
|
//# sourceMappingURL=errors.mjs.map
|