@dxos/errors 0.8.4-main.5ea62a8 → 0.8.4-main.60689f5b1c

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -1,133 +1,88 @@
1
1
  // src/base.ts
2
- function _check_private_redeclaration(obj, privateCollection) {
3
- if (privateCollection.has(obj)) {
4
- throw new TypeError("Cannot initialize the same private elements twice on an object");
5
- }
6
- }
7
- function _class_apply_descriptor_get(receiver, descriptor) {
8
- if (descriptor.get) {
9
- return descriptor.get.call(receiver);
10
- }
11
- return descriptor.value;
12
- }
13
- function _class_apply_descriptor_set(receiver, descriptor, value) {
14
- if (descriptor.set) {
15
- descriptor.set.call(receiver, value);
16
- } else {
17
- if (!descriptor.writable) {
18
- throw new TypeError("attempted to set read only private field");
19
- }
20
- descriptor.value = value;
21
- }
22
- }
23
- function _class_extract_field_descriptor(receiver, privateMap, action) {
24
- if (!privateMap.has(receiver)) {
25
- throw new TypeError("attempted to " + action + " private field on non-instance");
26
- }
27
- return privateMap.get(receiver);
28
- }
29
- function _class_private_field_get(receiver, privateMap) {
30
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
31
- return _class_apply_descriptor_get(receiver, descriptor);
32
- }
33
- function _class_private_field_init(obj, privateMap, value) {
34
- _check_private_redeclaration(obj, privateMap);
35
- privateMap.set(obj, value);
36
- }
37
- function _class_private_field_set(receiver, privateMap, value) {
38
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
39
- _class_apply_descriptor_set(receiver, descriptor, value);
40
- return value;
41
- }
42
- function _define_property(obj, key, value) {
43
- if (key in obj) {
44
- Object.defineProperty(obj, key, {
45
- value,
46
- enumerable: true,
47
- configurable: true,
48
- writable: true
49
- });
50
- } else {
51
- obj[key] = value;
52
- }
53
- return obj;
54
- }
55
- var _code = /* @__PURE__ */ new WeakMap();
56
- var _context = /* @__PURE__ */ new WeakMap();
57
2
  var BaseError = class _BaseError extends Error {
58
3
  /**
59
4
  * Primary way of defining new error classes.
60
- *
61
- * Expample:
62
- *
63
- * ```ts
64
- * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
65
- * ```
5
+ * Extended class may specialize constructor for required context params.
6
+ * @param name - Error name.
7
+ * @param message - Default error message.
66
8
  */
67
- static extend(code) {
68
- var _class;
69
- return _class = class extends _BaseError {
9
+ static extend(name, message) {
10
+ return class ExtendedError extends _BaseError {
11
+ static name = name;
70
12
  static is(error) {
71
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
13
+ return typeof error === "object" && error !== null && "name" in error && error.name === name;
72
14
  }
73
- static wrap(message, options) {
74
- return (error) => new this(message, {
75
- ...options,
76
- cause: error
77
- });
15
+ static wrap(options) {
16
+ const wrapFn = (error) => {
17
+ if (options?.ifTypeDiffers === true && this.is(error)) {
18
+ return error;
19
+ }
20
+ const newError = new this({
21
+ message,
22
+ ...options,
23
+ cause: error
24
+ });
25
+ Error.captureStackTrace(newError, wrapFn);
26
+ return newError;
27
+ };
28
+ return wrapFn;
78
29
  }
79
- constructor(message, options) {
80
- super(code, message, options);
30
+ constructor(options) {
31
+ super(name, {
32
+ message: options?.message ?? message,
33
+ ...options
34
+ });
81
35
  }
82
- }, _define_property(_class, "code", code), _class;
36
+ };
83
37
  }
84
- get name() {
85
- return _class_private_field_get(this, _code);
38
+ // NOTE: Errors go through odd transformations and the private fields seem to break.
39
+ name;
40
+ context;
41
+ constructor(name, options) {
42
+ let message = options?.message;
43
+ if (message && options?.context && Object.keys(options.context).length > 0) {
44
+ message += `: ${JSON.stringify(options?.context)}`;
45
+ }
46
+ super(message, {
47
+ cause: options?.cause
48
+ });
49
+ this.name = name;
50
+ this.context = options?.context ?? {};
51
+ Object.setPrototypeOf(this, new.target.prototype);
86
52
  }
87
- get code() {
88
- return _class_private_field_get(this, _code);
53
+ /** Fallback message. */
54
+ get message() {
55
+ return this.constructor.name;
89
56
  }
90
57
  // For effect error matching.
91
58
  get _tag() {
92
- return _class_private_field_get(this, _code);
93
- }
94
- get context() {
95
- return _class_private_field_get(this, _context);
96
- }
97
- constructor(code, message, options) {
98
- super(message, options), _class_private_field_init(this, _code, {
99
- writable: true,
100
- value: void 0
101
- }), _class_private_field_init(this, _context, {
102
- writable: true,
103
- value: void 0
104
- });
105
- _class_private_field_set(this, _code, code);
106
- _class_private_field_set(this, _context, options?.context ?? {});
107
- Object.setPrototypeOf(this, new.target.prototype);
59
+ return this.name;
108
60
  }
109
61
  };
110
62
 
111
63
  // src/errors.ts
112
- var TimeoutError = class extends BaseError.extend("TIMEOUT") {
64
+ var ApiError = class extends BaseError.extend("ApiError", "API error") {
65
+ };
66
+ var SystemError = class extends BaseError.extend("SystemError", "System error") {
113
67
  };
114
- var AbortedError = class extends BaseError.extend("ABORTED") {
68
+ var InternalError = class extends BaseError.extend("InternalError", "Internal error") {
115
69
  };
116
- var UnimplementedError = class extends BaseError.extend("UNIMPLEMENTED") {
70
+ var TimeoutError = class extends BaseError.extend("TimeoutError", "Timeout") {
117
71
  };
118
- var ApiError = class extends BaseError.extend("API_ERROR") {
72
+ var AbortedError = class extends BaseError.extend("AbortedError", "Aborted") {
119
73
  };
120
- var SystemError = class extends BaseError.extend("SYSTEM_ERROR") {
74
+ var NotImplementedError = class extends BaseError.extend("NotImplementedError", "Not implemented") {
121
75
  };
122
- var InternalError = class extends BaseError.extend("INTERNAL_ERROR") {
76
+ var RuntimeServiceError = class extends BaseError.extend("RuntimeServiceError", "Runtime service error") {
123
77
  };
124
78
  export {
125
79
  AbortedError,
126
80
  ApiError,
127
81
  BaseError,
128
82
  InternalError,
83
+ NotImplementedError,
84
+ RuntimeServiceError,
129
85
  SystemError,
130
- TimeoutError,
131
- UnimplementedError
86
+ TimeoutError
132
87
  };
133
88
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/base.ts", "../../../src/errors.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport type BaseErrorOptions = {\n /**\n * The cause of the error.\n * An instance of Error.\n */\n cause?: unknown;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n *\n * Expample:\n *\n * ```ts\n * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}\n * ```\n */\n static extend<Code extends string>(code: Code) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(message: string, options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this(message, { ...options, cause: error });\n }\n\n constructor(message: string, options?: BaseErrorOptions) {\n super(code, message, options);\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, message: string, options?: BaseErrorOptions) {\n super(message, options);\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED') {}\n\nexport class UnimplementedError extends BaseError.extend('UNIMPLEMENTED') {}\n\nexport class ApiError extends BaseError.extend('API_ERROR') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM_ERROR') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL_ERROR') {}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDE,QAAA,oBAAA,QAAA;IACA,WAAA,oBAAA,QAAA;AA7BK,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;;;;EAU3D,OAAOC,OAA4BC,MAAY;;AAC7C,WAAA,SAAO,cAAcH,WAAAA;MAGnB,OAAOI,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMF,SAASA;MAC1F;MAEA,OAAOG,KAAKC,SAAiBC,SAA2C;AACtE,eAAO,CAACH,UAAmB,IAAI,KAAKE,SAAS;UAAE,GAAGC;UAASC,OAAOJ;QAAM,CAAA;MAC1E;MAEA,YAAYE,SAAiBC,SAA4B;AACvD,cAAML,MAAMI,SAASC,OAAAA;MACvB;IACF,GAbE,iBAAA,QAAOL,QAAOA,IAAAA,GAAAA;EAclB;EAaA,IAAaO,OAAO;AAClB,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIP,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;;EAGA,IAAIQ,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIC,UAAU;AACZ,WAAA,yBAAO,MAAK,QAAA;EACd;EAvBA,YAAYT,MAAYI,SAAiBC,SAA4B;AACnE,UAAMD,SAASC,OAAAA,GAJjB,0BAAA,MAAA,OAAA;;aAAA;QACA,0BAAA,MAAA,UAAA;;aAAA;;mCAKO,OAAQL,IAAAA;mCACR,UAAWK,SAASI,WAAW,CAAC,CAAA;AACrCC,WAAOC,eAAe,MAAM,WAAWC,SAAS;EAClD;AAkBF;;;ACrEO,IAAMC,eAAN,cAA2BC,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAMC,eAAN,cAA2BF,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAME,qBAAN,cAAiCH,UAAUC,OAAO,eAAA,EAAA;AAAkB;AAEpE,IAAMG,WAAN,cAAuBJ,UAAUC,OAAO,WAAA,EAAA;AAAc;AAEtD,IAAMI,cAAN,cAA0BL,UAAUC,OAAO,cAAA,EAAA;AAAiB;AAE5D,IAAMK,gBAAN,cAA4BN,UAAUC,OAAO,gBAAA,EAAA;AAAmB;",
6
- "names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "message", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "TimeoutError", "BaseError", "extend", "AbortedError", "UnimplementedError", "ApiError", "SystemError", "InternalError"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Options for creating a BaseError.\n */\nexport type BaseErrorOptions = ErrorOptions & {\n /**\n * Override base message.\n */\n message?: string;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Name extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n * Extended class may specialize constructor for required context params.\n * @param name - Error name.\n * @param message - Default error message.\n */\n static extend<Name extends string = string>(name: Name, message?: string) {\n return class ExtendedError extends BaseError<Name> {\n static override name: Name = name;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'name' in error && error.name === name;\n }\n\n static wrap(\n options?: Omit<BaseErrorOptions, 'cause'> & { ifTypeDiffers?: boolean },\n ): (error: unknown) => ExtendedError {\n const wrapFn = (error: unknown) => {\n if (options?.ifTypeDiffers === true && this.is(error)) {\n return error as ExtendedError;\n }\n const newError: ExtendedError = new this({ message, ...options, cause: error });\n Error.captureStackTrace(newError, wrapFn); // Position stack-trace to start from the caller of `wrap`.\n return newError;\n };\n return wrapFn;\n }\n\n constructor(options?: BaseErrorOptions) {\n super(name, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\n override name: Name;\n context: Record<string, unknown>;\n\n constructor(name: Name, options?: BaseErrorOptions) {\n let message = options?.message;\n if (message && options?.context && Object.keys(options.context).length > 0) {\n message += `: ${JSON.stringify(options?.context)}`;\n }\n\n super(message, { cause: options?.cause });\n\n this.name = name;\n this.context = options?.context ?? {};\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n // For effect error matching.\n get _tag(): Name {\n return this.name;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('ApiError', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SystemError', 'System error') {}\n\nexport class InternalError extends BaseError.extend('InternalError', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TimeoutError', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('AbortedError', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NotImplementedError', 'Not implemented') {}\n\nexport class RuntimeServiceError extends BaseError.extend('RuntimeServiceError', 'Runtime service error') {}\n"],
5
+ "mappings": ";AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAgBG,OAAaA;MAE7B,OAAOG,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMJ,SAASA;MAC1F;MAEA,OAAOK,KACLC,SACmC;AACnC,cAAMC,SAAS,CAACH,UAAAA;AACd,cAAIE,SAASE,kBAAkB,QAAQ,KAAKL,GAAGC,KAAAA,GAAQ;AACrD,mBAAOA;UACT;AACA,g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["BaseError", "Error", "extend", "name", "message", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "keys", "length", "JSON", "stringify", "setPrototypeOf", "prototype", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError", "RuntimeServiceError"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/base.ts":{"bytes":7660,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2000,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3885},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","SystemError","TimeoutError","UnimplementedError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3300},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":418}},"bytes":3908}}}
1
+ {"inputs":{"src/base.ts":{"bytes":7641,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2574,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":450,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5162},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","RuntimeServiceError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1726},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":630}},"bytes":2570}}}
@@ -1,135 +1,90 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/base.ts
4
- function _check_private_redeclaration(obj, privateCollection) {
5
- if (privateCollection.has(obj)) {
6
- throw new TypeError("Cannot initialize the same private elements twice on an object");
7
- }
8
- }
9
- function _class_apply_descriptor_get(receiver, descriptor) {
10
- if (descriptor.get) {
11
- return descriptor.get.call(receiver);
12
- }
13
- return descriptor.value;
14
- }
15
- function _class_apply_descriptor_set(receiver, descriptor, value) {
16
- if (descriptor.set) {
17
- descriptor.set.call(receiver, value);
18
- } else {
19
- if (!descriptor.writable) {
20
- throw new TypeError("attempted to set read only private field");
21
- }
22
- descriptor.value = value;
23
- }
24
- }
25
- function _class_extract_field_descriptor(receiver, privateMap, action) {
26
- if (!privateMap.has(receiver)) {
27
- throw new TypeError("attempted to " + action + " private field on non-instance");
28
- }
29
- return privateMap.get(receiver);
30
- }
31
- function _class_private_field_get(receiver, privateMap) {
32
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
33
- return _class_apply_descriptor_get(receiver, descriptor);
34
- }
35
- function _class_private_field_init(obj, privateMap, value) {
36
- _check_private_redeclaration(obj, privateMap);
37
- privateMap.set(obj, value);
38
- }
39
- function _class_private_field_set(receiver, privateMap, value) {
40
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
41
- _class_apply_descriptor_set(receiver, descriptor, value);
42
- return value;
43
- }
44
- function _define_property(obj, key, value) {
45
- if (key in obj) {
46
- Object.defineProperty(obj, key, {
47
- value,
48
- enumerable: true,
49
- configurable: true,
50
- writable: true
51
- });
52
- } else {
53
- obj[key] = value;
54
- }
55
- return obj;
56
- }
57
- var _code = /* @__PURE__ */ new WeakMap();
58
- var _context = /* @__PURE__ */ new WeakMap();
59
4
  var BaseError = class _BaseError extends Error {
60
5
  /**
61
6
  * Primary way of defining new error classes.
62
- *
63
- * Expample:
64
- *
65
- * ```ts
66
- * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
67
- * ```
7
+ * Extended class may specialize constructor for required context params.
8
+ * @param name - Error name.
9
+ * @param message - Default error message.
68
10
  */
69
- static extend(code) {
70
- var _class;
71
- return _class = class extends _BaseError {
11
+ static extend(name, message) {
12
+ return class ExtendedError extends _BaseError {
13
+ static name = name;
72
14
  static is(error) {
73
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
15
+ return typeof error === "object" && error !== null && "name" in error && error.name === name;
74
16
  }
75
- static wrap(message, options) {
76
- return (error) => new this(message, {
77
- ...options,
78
- cause: error
79
- });
17
+ static wrap(options) {
18
+ const wrapFn = (error) => {
19
+ if (options?.ifTypeDiffers === true && this.is(error)) {
20
+ return error;
21
+ }
22
+ const newError = new this({
23
+ message,
24
+ ...options,
25
+ cause: error
26
+ });
27
+ Error.captureStackTrace(newError, wrapFn);
28
+ return newError;
29
+ };
30
+ return wrapFn;
80
31
  }
81
- constructor(message, options) {
82
- super(code, message, options);
32
+ constructor(options) {
33
+ super(name, {
34
+ message: options?.message ?? message,
35
+ ...options
36
+ });
83
37
  }
84
- }, _define_property(_class, "code", code), _class;
38
+ };
85
39
  }
86
- get name() {
87
- return _class_private_field_get(this, _code);
40
+ // NOTE: Errors go through odd transformations and the private fields seem to break.
41
+ name;
42
+ context;
43
+ constructor(name, options) {
44
+ let message = options?.message;
45
+ if (message && options?.context && Object.keys(options.context).length > 0) {
46
+ message += `: ${JSON.stringify(options?.context)}`;
47
+ }
48
+ super(message, {
49
+ cause: options?.cause
50
+ });
51
+ this.name = name;
52
+ this.context = options?.context ?? {};
53
+ Object.setPrototypeOf(this, new.target.prototype);
88
54
  }
89
- get code() {
90
- return _class_private_field_get(this, _code);
55
+ /** Fallback message. */
56
+ get message() {
57
+ return this.constructor.name;
91
58
  }
92
59
  // For effect error matching.
93
60
  get _tag() {
94
- return _class_private_field_get(this, _code);
95
- }
96
- get context() {
97
- return _class_private_field_get(this, _context);
98
- }
99
- constructor(code, message, options) {
100
- super(message, options), _class_private_field_init(this, _code, {
101
- writable: true,
102
- value: void 0
103
- }), _class_private_field_init(this, _context, {
104
- writable: true,
105
- value: void 0
106
- });
107
- _class_private_field_set(this, _code, code);
108
- _class_private_field_set(this, _context, options?.context ?? {});
109
- Object.setPrototypeOf(this, new.target.prototype);
61
+ return this.name;
110
62
  }
111
63
  };
112
64
 
113
65
  // src/errors.ts
114
- var TimeoutError = class extends BaseError.extend("TIMEOUT") {
66
+ var ApiError = class extends BaseError.extend("ApiError", "API error") {
67
+ };
68
+ var SystemError = class extends BaseError.extend("SystemError", "System error") {
115
69
  };
116
- var AbortedError = class extends BaseError.extend("ABORTED") {
70
+ var InternalError = class extends BaseError.extend("InternalError", "Internal error") {
117
71
  };
118
- var UnimplementedError = class extends BaseError.extend("UNIMPLEMENTED") {
72
+ var TimeoutError = class extends BaseError.extend("TimeoutError", "Timeout") {
119
73
  };
120
- var ApiError = class extends BaseError.extend("API_ERROR") {
74
+ var AbortedError = class extends BaseError.extend("AbortedError", "Aborted") {
121
75
  };
122
- var SystemError = class extends BaseError.extend("SYSTEM_ERROR") {
76
+ var NotImplementedError = class extends BaseError.extend("NotImplementedError", "Not implemented") {
123
77
  };
124
- var InternalError = class extends BaseError.extend("INTERNAL_ERROR") {
78
+ var RuntimeServiceError = class extends BaseError.extend("RuntimeServiceError", "Runtime service error") {
125
79
  };
126
80
  export {
127
81
  AbortedError,
128
82
  ApiError,
129
83
  BaseError,
130
84
  InternalError,
85
+ NotImplementedError,
86
+ RuntimeServiceError,
131
87
  SystemError,
132
- TimeoutError,
133
- UnimplementedError
88
+ TimeoutError
134
89
  };
135
90
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/base.ts", "../../../src/errors.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport type BaseErrorOptions = {\n /**\n * The cause of the error.\n * An instance of Error.\n */\n cause?: unknown;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n *\n * Expample:\n *\n * ```ts\n * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}\n * ```\n */\n static extend<Code extends string>(code: Code) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(message: string, options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this(message, { ...options, cause: error });\n }\n\n constructor(message: string, options?: BaseErrorOptions) {\n super(code, message, options);\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, message: string, options?: BaseErrorOptions) {\n super(message, options);\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED') {}\n\nexport class UnimplementedError extends BaseError.extend('UNIMPLEMENTED') {}\n\nexport class ApiError extends BaseError.extend('API_ERROR') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM_ERROR') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL_ERROR') {}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDE,QAAA,oBAAA,QAAA;IACA,WAAA,oBAAA,QAAA;AA7BK,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;;;;EAU3D,OAAOC,OAA4BC,MAAY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names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "message", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "TimeoutError", "BaseError", "extend", "AbortedError", "UnimplementedError", "ApiError", "SystemError", "InternalError"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Options for creating a BaseError.\n */\nexport type BaseErrorOptions = ErrorOptions & {\n /**\n * Override base message.\n */\n message?: string;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Name extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n * Extended class may specialize constructor for required context params.\n * @param name - Error name.\n * @param message - Default error message.\n */\n static extend<Name extends string = string>(name: Name, message?: string) {\n return class ExtendedError extends BaseError<Name> {\n static override name: Name = name;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'name' in error && error.name === name;\n }\n\n static wrap(\n options?: Omit<BaseErrorOptions, 'cause'> & { ifTypeDiffers?: boolean },\n ): (error: unknown) => ExtendedError {\n const wrapFn = (error: unknown) => {\n if (options?.ifTypeDiffers === true && this.is(error)) {\n return error as ExtendedError;\n }\n const newError: ExtendedError = new this({ message, ...options, cause: error });\n Error.captureStackTrace(newError, wrapFn); // Position stack-trace to start from the caller of `wrap`.\n return newError;\n };\n return wrapFn;\n }\n\n constructor(options?: BaseErrorOptions) {\n super(name, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\n override name: Name;\n context: Record<string, unknown>;\n\n constructor(name: Name, options?: BaseErrorOptions) {\n let message = options?.message;\n if (message && options?.context && Object.keys(options.context).length > 0) {\n message += `: ${JSON.stringify(options?.context)}`;\n }\n\n super(message, { cause: options?.cause });\n\n this.name = name;\n this.context = options?.context ?? {};\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n // For effect error matching.\n get _tag(): Name {\n return this.name;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('ApiError', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SystemError', 'System error') {}\n\nexport class InternalError extends BaseError.extend('InternalError', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TimeoutError', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('AbortedError', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NotImplementedError', 'Not implemented') {}\n\nexport class RuntimeServiceError extends BaseError.extend('RuntimeServiceError', 'Runtime service error') {}\n"],
5
+ "mappings": ";;;AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAgBG,OAAaA;MAE7B,OAAOG,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMJ,SAASA;MAC1F;MAEA,OAAOK,KACLC,SACmC;AACnC,cAAMC,SAAS,CAACH,UAAAA;AACd,cAAIE,SAASE,kBAAkB,QAAQ,KAAKL,GAAGC,KAAAA,GAAQ;AACrD,mBAAOA;UACT;AACA,gBAAMK,WAA0B,IAAI,KAAK;YAAER;YAAS,GAAGK;YAASI,OAAON;UAAM,CAAA;AAC7EN,gBAAMa,kBAAkBF,UAAUF,MAAAA;AAClC,iBAAOE;QACT;AACA,eAAOF;MACT;MAEA,YAAYD,SAA4B;AACtC,cAAMN,MAAM;UAAEC,SAASK,SAASL,WAAWA;UAAS,GAAGK;QAAQ,CAAA;MACjE;IACF;EACF;;EAGSN;EACTY;EAEA,YAAYZ,MAAYM,SAA4B;AAClD,QAAIL,UAAUK,SAASL;AACvB,QAAIA,WAAWK,SAASM,WAAWC,OAAOC,KAAKR,QAAQM,OAAO,EAAEG,SAAS,GAAG;AAC1Ed,iBAAW,KAAKe,KAAKC,UAAUX,SAASM,OAAAA,CAAAA;IAC1C;AAEA,UAAMX,SAAS;MAAES,OAAOJ,SAASI;IAAM,CAAA;AAEvC,SAAKV,OAAOA;AACZ,SAAKY,UAAUN,SAASM,WAAW,CAAC;AAEpCC,WAAOK,eAAe,MAAM,WAAWC,SAAS;EAClD;;EAGA,IAAalB,UAAU;AACrB,WAAO,KAAK,YAAYD;EAC1B;;EAGA,IAAIoB,OAAa;AACf,WAAO,KAAKpB;EACd;AACF;;;AC9EO,IAAMqB,WAAN,cAAuBC,UAAUC,OAAO,YAAY,WAAA,EAAA;AAAc;AAElE,IAAMC,cAAN,cAA0BF,UAAUC,OAAO,eAAe,cAAA,EAAA;AAAiB;AAE3E,IAAME,gBAAN,cAA4BH,UAAUC,OAAO,iBAAiB,gBAAA,EAAA;AAAmB;AAEjF,IAAMG,eAAN,cAA2BJ,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMI,eAAN,cAA2BL,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMK,sBAAN,cAAkCN,UAAUC,OAAO,uBAAuB,iBAAA,EAAA;AAAoB;AAE9F,IAAMM,sBAAN,cAAkCP,UAAUC,OAAO,uBAAuB,uBAAA,EAAA;AAA0B;",
6
+ "names": ["BaseError", "Error", "extend", "name", "message", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "keys", "length", "JSON", "stringify", "setPrototypeOf", "prototype", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError", "RuntimeServiceError"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/base.ts":{"bytes":7660,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2000,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3887},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","SystemError","TimeoutError","UnimplementedError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3300},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":418}},"bytes":4001}}}
1
+ {"inputs":{"src/base.ts":{"bytes":7641,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2574,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":450,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5164},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","RuntimeServiceError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1726},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":630}},"bytes":2663}}}