https://project.mdnd-it.cc/work_packages/94
This commit is contained in:
2025-08-23 04:25:28 +02:00
parent 725516ad6c
commit 19cfa031d0
25823 changed files with 1095587 additions and 2801760 deletions
@@ -0,0 +1,3 @@
import { OnoConstructor } from "./types";
declare const constructor: OnoConstructor;
export { constructor as Ono };
+47
View File
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ono = void 0;
const extend_error_1 = require("./extend-error");
const normalize_1 = require("./normalize");
const to_json_1 = require("./to-json");
const constructor = Ono;
exports.Ono = constructor;
/**
* Creates an `Ono` instance for a specifc error type.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function Ono(ErrorConstructor, options) {
options = normalize_1.normalizeOptions(options);
function ono(...args) {
let { originalError, props, message } = normalize_1.normalizeArgs(args, options);
// Create a new error of the specified type
let newError = new ErrorConstructor(message);
// Extend the error with the properties of the original error and the `props` object
return extend_error_1.extendError(newError, originalError, props);
}
ono[Symbol.species] = ErrorConstructor;
return ono;
}
/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
Ono.toJSON = function toJSON(error) {
return to_json_1.toJSON.call(error);
};
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*/
Ono.extend = function extend(error, originalError, props) {
if (props || originalError instanceof Error) {
return extend_error_1.extendError(error, originalError, props);
}
else if (originalError) {
return extend_error_1.extendError(error, undefined, originalError);
}
else {
return extend_error_1.extendError(error);
}
};
//# sourceMappingURL=constructor.js.map
@@ -0,0 +1 @@
{"version":3,"file":"constructor.js","sourceRoot":"","sources":["../src/constructor.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAC7C,2CAA8D;AAC9D,uCAAkD;AAGlD,MAAM,WAAW,GAAG,GAAqB,CAAC;AAClB,0BAAG;AAE3B;;GAEG;AACH,gEAAgE;AAChE,SAAS,GAAG,CAAsB,gBAAyC,EAAE,OAAoB;IAC/F,OAAO,GAAG,4BAAgB,CAAC,OAAO,CAAC,CAAC;IAEpC,SAAS,GAAG,CAAwC,GAAG,IAAe;QACpE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,yBAAa,CAAO,IAAI,EAAE,OAAQ,CAAC,CAAC;QAE5E,2CAA2C;QAC3C,IAAI,QAAQ,GAAG,IAAK,gBAAiD,CAAC,OAAO,CAAC,CAAC;QAE/E,oFAAoF;QACpF,OAAO,0BAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,gBAAgB,CAAC;IACvC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,GAAG,CAAC,MAAM,GAAG,SAAS,MAAM,CAAC,KAAgB;IAC3C,OAAO,gBAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;GAGG;AACH,GAAG,CAAC,MAAM,GAAG,SAAS,MAAM,CAAC,KAAgB,EAAE,aAAyB,EAAE,KAAc;IACtF,IAAI,KAAK,IAAI,aAAa,YAAY,KAAK,EAAE;QAC3C,OAAO,0BAAW,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;KACjD;SACI,IAAI,aAAa,EAAE;QACtB,OAAO,0BAAW,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;KACrD;SACI;QACH,OAAO,0BAAW,CAAC,KAAK,CAAC,CAAC;KAC3B;AACH,CAAC,CAAC"}
@@ -0,0 +1,9 @@
import { ErrorLike, OnoError } from "./types";
/**
* Extends the new error with the properties of the original error and the `props` object.
*
* @param newError - The error object to extend
* @param originalError - The original error object, if any
* @param props - Additional properties to add, if any
*/
export declare function extendError<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
+77
View File
@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendError = void 0;
const isomorphic_node_1 = require("./isomorphic.node");
const stack_1 = require("./stack");
const to_json_1 = require("./to-json");
const protectedProps = ["name", "message", "stack"];
/**
* Extends the new error with the properties of the original error and the `props` object.
*
* @param newError - The error object to extend
* @param originalError - The original error object, if any
* @param props - Additional properties to add, if any
*/
function extendError(error, originalError, props) {
let onoError = error;
extendStack(onoError, originalError);
// Copy properties from the original error
if (originalError && typeof originalError === "object") {
mergeErrors(onoError, originalError);
}
// The default `toJSON` method doesn't output props like `name`, `message`, `stack`, etc.
// So replace it with one that outputs every property of the error.
onoError.toJSON = to_json_1.toJSON;
// On Node.js, add support for the `util.inspect()` method
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (isomorphic_node_1.addInspectMethod) {
isomorphic_node_1.addInspectMethod(onoError);
}
// Finally, copy custom properties that were specified by the user.
// These props OVERWRITE any previous props
if (props && typeof props === "object") {
Object.assign(onoError, props);
}
return onoError;
}
exports.extendError = extendError;
/**
* Extend the error stack to include its cause
*/
function extendStack(newError, originalError) {
let stackProp = Object.getOwnPropertyDescriptor(newError, "stack");
if (stack_1.isLazyStack(stackProp)) {
stack_1.lazyJoinStacks(stackProp, newError, originalError);
}
else if (stack_1.isWritableStack(stackProp)) {
newError.stack = stack_1.joinStacks(newError, originalError);
}
}
/**
* Merges properties of the original error with the new error.
*
* @param newError - The error object to extend
* @param originalError - The original error object, if any
*/
function mergeErrors(newError, originalError) {
// Get the original error's keys
// NOTE: We specifically exclude properties that we have already set on the new error.
// This is _especially_ important for the `stack` property, because this property has
// a lazy getter in some environments
let keys = to_json_1.getDeepKeys(originalError, protectedProps);
// HACK: We have to cast the errors to `any` so we can use symbol indexers.
// see https://github.com/Microsoft/TypeScript/issues/1863
let _newError = newError;
let _originalError = originalError;
for (let key of keys) {
if (_newError[key] === undefined) {
try {
_newError[key] = _originalError[key];
}
catch (e) {
// This property is read-only, so it can't be copied
}
}
}
}
//# sourceMappingURL=extend-error.js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Aa,CAAC,CAAC;KACtD;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,QAAmB,EAAE,aAAwB;IAChE,gCAAgC;IAChC,sFAAsF;IACtF,qFAAqF;IACrF,qCAAqC;IACrC,IAAI,IAAI,GAAG,qBAAW,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAEtD,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAI,SAAS,GAAG,QAAe,CAAC;IAChC,IAAI,cAAc,GAAG,aAAoB,CAAC;IAE1C,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;QACpB,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;YAChC,IAAI;gBACF,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;aACtC;YACD,OAAO,CAAC,EAAE;gBACR,oDAAoD;aACrD;SACF;KACF;AACH,CAAC"}
+5
View File
@@ -0,0 +1,5 @@
import { ono } from "./singleton";
export { Ono } from "./constructor";
export * from "./types";
export { ono };
export default ono;
+25
View File
@@ -0,0 +1,25 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ono = void 0;
/* eslint-env commonjs */
const singleton_1 = require("./singleton");
Object.defineProperty(exports, "ono", { enumerable: true, get: function () { return singleton_1.ono; } });
var constructor_1 = require("./constructor");
Object.defineProperty(exports, "Ono", { enumerable: true, get: function () { return constructor_1.Ono; } });
__exportStar(require("./types"), exports);
exports.default = singleton_1.ono;
// CommonJS default export hack
if (typeof module === "object" && typeof module.exports === "object") {
module.exports = Object.assign(module.exports.default, module.exports);
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yBAAyB;AACzB,2CAAkC;AAIzB,oFAJA,eAAG,OAIA;AAFZ,6CAAoC;AAA3B,kGAAA,GAAG,OAAA;AACZ,0CAAwB;AAGxB,kBAAe,eAAG,CAAC;AAEnB,+BAA+B;AAC/B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE;IACpE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACxE"}
@@ -0,0 +1,15 @@
/**
* Ono supports custom formatters for error messages. In Node.js, it defaults
* to the `util.format()` function. In browsers, it defaults to `Array.join()`.
*
* The Node.js functionality can be used in a web browser via a polyfill,
* such as "format-util".
*
* @see https://github.com/tmpfs/format-util
*/
export declare const format = false;
/**
* The `util.inspect()` functionality only applies to Node.js.
* We return the constant `false` here so that the Node-specific code gets removed by tree-shaking.
*/
export declare const addInspectMethod = false;
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addInspectMethod = exports.format = void 0;
/**
* Ono supports custom formatters for error messages. In Node.js, it defaults
* to the `util.format()` function. In browsers, it defaults to `Array.join()`.
*
* The Node.js functionality can be used in a web browser via a polyfill,
* such as "format-util".
*
* @see https://github.com/tmpfs/format-util
*/
exports.format = false;
/**
* The `util.inspect()` functionality only applies to Node.js.
* We return the constant `false` here so that the Node-specific code gets removed by tree-shaking.
*/
exports.addInspectMethod = false;
//# sourceMappingURL=isomorphic.browser.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isomorphic.browser.js","sourceRoot":"","sources":["../src/isomorphic.browser.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACU,QAAA,MAAM,GAAG,KAAK,CAAC;AAE5B;;;GAGG;AACU,QAAA,gBAAgB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,15 @@
/// <reference types="node" />
import * as util from "util";
import { OnoError } from "./types";
/**
* Ono supports Node's `util.format()` formatting for error messages.
*
* @see https://nodejs.org/api/util.html#util_util_format_format_args
*/
export declare const format: typeof util.format;
/**
* Adds an `inspect()` method to support Node's `util.inspect()` function.
*
* @see https://nodejs.org/api/util.html#util_util_inspect_custom
*/
export declare function addInspectMethod<T>(newError: OnoError<T>): void;
@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addInspectMethod = exports.format = void 0;
const util = require("util");
const to_json_1 = require("./to-json");
// The `inspect()` method is actually a Symbol, not a string key.
// https://nodejs.org/api/util.html#util_util_inspect_custom
const inspectMethod = util.inspect.custom || Symbol.for("nodejs.util.inspect.custom");
/**
* Ono supports Node's `util.format()` formatting for error messages.
*
* @see https://nodejs.org/api/util.html#util_util_format_format_args
*/
exports.format = util.format;
/**
* Adds an `inspect()` method to support Node's `util.inspect()` function.
*
* @see https://nodejs.org/api/util.html#util_util_inspect_custom
*/
function addInspectMethod(newError) {
// @ts-expect-error - TypeScript doesn't support symbol indexers
newError[inspectMethod] = inspect;
}
exports.addInspectMethod = addInspectMethod;
/**
* Returns a representation of the error for Node's `util.inspect()` method.
*
* @see https://nodejs.org/api/util.html#util_custom_inspection_functions_on_objects
*/
function inspect() {
// HACK: We have to cast the objects to `any` so we can use symbol indexers.
// see https://github.com/Microsoft/TypeScript/issues/1863
let pojo = {};
let error = this;
for (let key of to_json_1.getDeepKeys(error)) {
let value = error[key];
pojo[key] = value;
}
// Don't include the `inspect()` method on the output object,
// otherwise it will cause `util.inspect()` to go into an infinite loop
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete pojo[inspectMethod];
return pojo;
}
//# sourceMappingURL=isomorphic.node.js.map
@@ -0,0 +1 @@
{"version":3,"file":"isomorphic.node.js","sourceRoot":"","sources":["../src/isomorphic.node.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,uCAAwC;AAGxC,iEAAiE;AACjE,4DAA4D;AAC5D,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAEtF;;;;GAIG;AACU,QAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AAElC;;;;GAIG;AACH,SAAgB,gBAAgB,CAAI,QAAqB;IACvD,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC;AACpC,CAAC;AAHD,4CAGC;AAED;;;;GAIG;AACH,SAAS,OAAO;IACd,4EAA4E;IAC5E,0DAA0D;IAC1D,IAAI,IAAI,GAAQ,EAAE,CAAC;IACnB,IAAI,KAAK,GAAG,IAAW,CAAC;IAExB,KAAK,IAAI,GAAG,IAAI,qBAAW,CAAC,KAAK,CAAC,EAAE;QAClC,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACnB;IAED,6DAA6D;IAC7D,uEAAuE;IACvE,gEAAgE;IAChE,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;IAE3B,OAAO,IAAqB,CAAC;AAC/B,CAAC"}
+13
View File
@@ -0,0 +1,13 @@
import { ErrorLike, OnoOptions } from "./types";
/**
* Normalizes Ono options, accounting for defaults and optional options.
*/
export declare function normalizeOptions(options?: OnoOptions): OnoOptions;
/**
* Normalizes the Ono arguments, accounting for defaults, options, and optional arguments.
*/
export declare function normalizeArgs<E extends ErrorLike, P extends object>(args: unknown[], options: OnoOptions): {
originalError: E | undefined;
props: P | undefined;
message: string;
};
+59
View File
@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeArgs = exports.normalizeOptions = void 0;
const isomorphic_node_1 = require("./isomorphic.node");
/**
* Normalizes Ono options, accounting for defaults and optional options.
*/
function normalizeOptions(options) {
options = options || {};
return {
concatMessages: options.concatMessages === undefined ? true : Boolean(options.concatMessages),
format: options.format === undefined ? isomorphic_node_1.format
: (typeof options.format === "function" ? options.format : false),
};
}
exports.normalizeOptions = normalizeOptions;
/**
* Normalizes the Ono arguments, accounting for defaults, options, and optional arguments.
*/
function normalizeArgs(args, options) {
let originalError;
let props;
let formatArgs;
let message = "";
// Determine which arguments were actually specified
if (typeof args[0] === "string") {
formatArgs = args;
}
else if (typeof args[1] === "string") {
if (args[0] instanceof Error) {
originalError = args[0];
}
else {
props = args[0];
}
formatArgs = args.slice(1);
}
else {
originalError = args[0];
props = args[1];
formatArgs = args.slice(2);
}
// If there are any format arguments, then format the error message
if (formatArgs.length > 0) {
if (options.format) {
message = options.format.apply(undefined, formatArgs);
}
else {
message = formatArgs.join(" ");
}
}
if (options.concatMessages && originalError && originalError.message) {
// The inner-error's message will be added to the new message
message += (message ? " \n" : "") + originalError.message;
}
return { originalError, props, message };
}
exports.normalizeArgs = normalizeArgs;
//# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":";;;AAAA,uDAA2C;AAG3C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,OAAoB;IACnD,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IACxB,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;QAC7F,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,wBAAM;YAC3C,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAA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CAAC,OAAO,CAAC;KAC3D;IAED,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC;AAzCD,sCAyCC"}
+3
View File
@@ -0,0 +1,3 @@
import { OnoSingleton } from "./types";
declare const singleton: OnoSingleton;
export { singleton as ono };
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ono = void 0;
const constructor_1 = require("./constructor");
const singleton = ono;
exports.ono = singleton;
ono.error = new constructor_1.Ono(Error);
ono.eval = new constructor_1.Ono(EvalError);
ono.range = new constructor_1.Ono(RangeError);
ono.reference = new constructor_1.Ono(ReferenceError);
ono.syntax = new constructor_1.Ono(SyntaxError);
ono.type = new constructor_1.Ono(TypeError);
ono.uri = new constructor_1.Ono(URIError);
const onoMap = ono;
/**
* Creates a new error with the specified message, properties, and/or inner error.
* If an inner error is provided, then the new error will match its type, if possible.
*/
function ono(...args) {
let originalError = args[0];
// Is the first argument an Error-like object?
if (typeof originalError === "object" && typeof originalError.name === "string") {
// Try to find an Ono singleton method that matches this error type
for (let typedOno of Object.values(onoMap)) {
if (typeof typedOno === "function" && typedOno.name === "ono") {
let species = typedOno[Symbol.species];
if (species && species !== Error && (originalError instanceof species || originalError.name === species.name)) {
// Create an error of the same type
return typedOno.apply(undefined, args);
}
}
}
}
// By default, create a base Error object
return ono.error.apply(undefined, args);
}
//# sourceMappingURL=singleton.js.map
@@ -0,0 +1 @@
{"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":";;;AACA,+CAAsD;AAGtD,MAAM,SAAS,GAAG,GAAmB,CAAC;AAChB,wBAAG;AAEzB,GAAG,CAAC,KAAK,GAAG,IAAI,iBAAc,CAAC,KAAK,CAAC,CAAC;AACtC,GAAG,CAAC,IAAI,GAAG,IAAI,iBAAc,CAAC,SAAS,CAAC,CAAC;AACzC,GAAG,CAAC,KAAK,GAAG,IAAI,iBAAc,CAAC,UAAU,CAAC,CAAC;AAC3C,GAAG,CAAC,SAAS,GAAG,IAAI,iBAAc,CAAC,cAAc,CAAC,CAAC;AACnD,GAAG,CAAC,MAAM,GAAG,IAAI,iBAAc,CAAC,WAAW,CAAC,CAAC;AAC7C,GAAG,CAAC,IAAI,GAAG,IAAI,iBAAc,CAAC,SAAS,CAAC,CAAC;AACzC,GAAG,CAAC,GAAG,GAAG,IAAI,iBAAc,CAAC,QAAQ,CAAC,CAAC;AAEvC,MAAM,MAAM,GAAG,GAA4C,CAAC;AAE5D;;;GAGG;AACH,SAAS,GAAG,CAAwC,GAAG,IAAe;IACpE,IAAI,aAAa,GAAG,IAAI,CAAC,CAAC,CAA0B,CAAC;IAErD,8CAA8C;IAC9C,IAAI,OAAO,aAAa,KAAK,QAAQ,IAAI,OAAO,aAAa,CAAC,IAAI,KAAK,QAAQ,EAAE;QAE/E,mEAAmE;QACnE,KAAK,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YAC1C,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE;gBAC7D,IAAI,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAEvC,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,aAAa,YAAY,OAAO,IAAI,aAAa,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE;oBAC7G,mCAAmC;oBACnC,OAAO,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;iBACxC;aACF;SACF;KACF;IAED,yCAAyC;IACzC,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC"}
+28
View File
@@ -0,0 +1,28 @@
import { ErrorLike } from "./types";
/**
* The Property Descriptor of a lazily-computed `stack` property.
*/
interface LazyStack {
configurable: true;
/**
* Lazily computes the error's stack trace.
*/
get(): string | undefined;
}
/**
* Is the property lazily computed?
*/
export declare function isLazyStack(stackProp: PropertyDescriptor | undefined): stackProp is LazyStack;
/**
* Is the stack property writable?
*/
export declare function isWritableStack(stackProp: PropertyDescriptor | undefined): boolean;
/**
* Appends the original `Error.stack` property to the new Error's stack.
*/
export declare function joinStacks(newError: ErrorLike, originalError?: ErrorLike): string | undefined;
/**
* Calls `joinStacks` lazily, when the `Error.stack` property is accessed.
*/
export declare function lazyJoinStacks(lazyStack: LazyStack, newError: ErrorLike, originalError?: ErrorLike): void;
export {};
+102
View File
@@ -0,0 +1,102 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lazyJoinStacks = exports.joinStacks = exports.isWritableStack = exports.isLazyStack = void 0;
const newline = /\r?\n/;
const onoCall = /\bono[ @]/;
/**
* Is the property lazily computed?
*/
function isLazyStack(stackProp) {
return Boolean(stackProp &&
stackProp.configurable &&
typeof stackProp.get === "function");
}
exports.isLazyStack = isLazyStack;
/**
* Is the stack property writable?
*/
function isWritableStack(stackProp) {
return Boolean(
// If there is no stack property, then it's writable, since assigning it will create it
!stackProp ||
stackProp.writable ||
typeof stackProp.set === "function");
}
exports.isWritableStack = isWritableStack;
/**
* Appends the original `Error.stack` property to the new Error's stack.
*/
function joinStacks(newError, originalError) {
let newStack = popStack(newError.stack);
let originalStack = originalError ? originalError.stack : undefined;
if (newStack && originalStack) {
return newStack + "\n\n" + originalStack;
}
else {
return newStack || originalStack;
}
}
exports.joinStacks = joinStacks;
/**
* Calls `joinStacks` lazily, when the `Error.stack` property is accessed.
*/
function lazyJoinStacks(lazyStack, newError, originalError) {
if (originalError) {
Object.defineProperty(newError, "stack", {
get: () => {
let newStack = lazyStack.get.apply(newError);
return joinStacks({ stack: newStack }, originalError);
},
enumerable: false,
configurable: true
});
}
else {
lazyPopStack(newError, lazyStack);
}
}
exports.lazyJoinStacks = lazyJoinStacks;
/**
* Removes Ono from the stack, so that the stack starts at the original error location
*/
function popStack(stack) {
if (stack) {
let lines = stack.split(newline);
// Find the Ono call(s) in the stack, and remove them
let onoStart;
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if (onoCall.test(line)) {
if (onoStart === undefined) {
// We found the first Ono call in the stack trace.
// There may be other subsequent Ono calls as well.
onoStart = i;
}
}
else if (onoStart !== undefined) {
// We found the first non-Ono call after one or more Ono calls.
// So remove the Ono call lines from the stack trace
lines.splice(onoStart, i - onoStart);
break;
}
}
if (lines.length > 0) {
return lines.join("\n");
}
}
// If we get here, then the stack doesn't contain a call to `ono`.
// This may be due to minification or some optimization of the JS engine.
// So just return the stack as-is.
return stack;
}
/**
* Calls `popStack` lazily, when the `Error.stack` property is accessed.
*/
function lazyPopStack(error, lazyStack) {
Object.defineProperty(error, "stack", {
get: () => popStack(lazyStack.get.apply(error)),
enumerable: false,
configurable: true
});
}
//# sourceMappingURL=stack.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../src/stack.ts"],"names":[],"mappings":";;;AAEA,MAAM,OAAO,GAAG,OAAO,CAAC;AACxB,MAAM,OAAO,GAAG,WAAW,CAAC;AAc5B;;GAEG;AACH,SAAgB,WAAW,CAAC,SAAyC;IACnE,OAAO,OAAO,CACZ,SAAS;QACT,SAAS,CAAC,YAAY;QACtB,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC;AAND,kCAMC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,SAAyC;IACvE,OAAO,OAAO;IACZ,uFAAuF;IACvF,CAAC,SAAS;QACV,SAAS,CAAC,QAAQ;QAClB,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,CACpC,CAAC;AACJ,CAAC;AAPD,0CAOC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,QAAmB,EAAE,aAAyB;IACvE,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,aAAa,GA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iBACd;aACF;iBACI,IAAI,QAAQ,KAAK,SAAS,EAAE;gBAC/B,+DAA+D;gBAC/D,oDAAoD;gBACpD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC;gBACrC,MAAM;aACP;SACF;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YACpB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACzB;KACF;IAED,kEAAkE;IAClE,yEAAyE;IACzE,kCAAkC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,KAAgB,EAAE,SAAoB;IAC1D,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE;QACpC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/C,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC"}
+11
View File
@@ -0,0 +1,11 @@
import { ErrorLike, ErrorPOJO } from "./types";
/**
* Custom JSON serializer for Error objects.
* Returns all built-in error properties, as well as extended properties.
*/
export declare function toJSON<E extends ErrorLike>(this: E): ErrorPOJO & E;
/**
* Returns own, inherited, enumerable, non-enumerable, string, and symbol keys of `obj`.
* Does NOT return members of the base Object prototype, or the specified omitted keys.
*/
export declare function getDeepKeys(obj: object, omit?: Array<string | symbol>): Set<string | symbol>;
+48
View File
@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeepKeys = exports.toJSON = void 0;
const nonJsonTypes = ["function", "symbol", "undefined"];
const protectedProps = ["constructor", "prototype", "__proto__"];
const objectPrototype = Object.getPrototypeOf({});
/**
* Custom JSON serializer for Error objects.
* Returns all built-in error properties, as well as extended properties.
*/
function toJSON() {
// HACK: We have to cast the objects to `any` so we can use symbol indexers.
// see https://github.com/Microsoft/TypeScript/issues/1863
let pojo = {};
let error = this;
for (let key of getDeepKeys(error)) {
if (typeof key === "string") {
let value = error[key];
let type = typeof value;
if (!nonJsonTypes.includes(type)) {
pojo[key] = value;
}
}
}
return pojo;
}
exports.toJSON = toJSON;
/**
* Returns own, inherited, enumerable, non-enumerable, string, and symbol keys of `obj`.
* Does NOT return members of the base Object prototype, or the specified omitted keys.
*/
function getDeepKeys(obj, omit = []) {
let keys = [];
// Crawl the prototype chain, finding all the string and symbol keys
while (obj && obj !== objectPrototype) {
keys = keys.concat(Object.getOwnPropertyNames(obj), Object.getOwnPropertySymbols(obj));
obj = Object.getPrototypeOf(obj);
}
// De-duplicate the list of keys
let uniqueKeys = new Set(keys);
// Remove any omitted keys
for (let key of omit.concat(protectedProps)) {
uniqueKeys.delete(key);
}
return uniqueKeys;
}
exports.getDeepKeys = getDeepKeys;
//# sourceMappingURL=to-json.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"to-json.js","sourceRoot":"","sources":["../src/to-json.ts"],"names":[],"mappings":";;;AAEA,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AACzD,MAAM,cAAc,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACjE,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAElD;;;GAGG;AACH,SAAgB,MAAM;IACpB,4EAA4E;IAC5E,0DAA0D;IAC1D,IAAI,IAAI,GAAQ,EAAE,CAAC;IACnB,IAAI,KAAK,GAAG,IAAW,CAAC;IAExB,KAAK,IAAI,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QAClC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,IAAI,GAAG,OAAO,KAAK,CAAC;YAExB,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBAChC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aACnB;SACF;KACF;IAED,OAAO,IAAqB,CAAC;AAC/B,CAAC;AAlBD,wBAkBC;AAGD;;;GAGG;AACH,SAAgB,WAAW,CAAC,GAAW,EAAE,OAA+B,EAAE;IACxE,IAAI,IAAI,GAA2B,EAAE,CAAC;IAEtC,oEAAoE;IACpE,OAAO,GAAG,IAAI,GAAG,KAAK,eAAe,EAAE;QACrC,IAAI,GAAG,IAAI,CAAC,MAAM,CAChB,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAC/B,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAClC,CAAC;QACF,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAW,CAAC;KAC5C;IAED,gCAAgC;IAChC,IAAI,UAAU,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAE/B,0BAA0B;IAC1B,KAAK,IAAI,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;QAC3C,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;KACxB;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AArBD,kCAqBC"}
+201
View File
@@ -0,0 +1,201 @@
/// <reference types="node" />
import { inspect } from "util";
/**
* The default export of the "ono" module.
*/
export interface OnoSingleton extends Ono<Error> {
error: Ono<Error>;
eval: Ono<EvalError>;
range: Ono<RangeError>;
reference: Ono<ReferenceError>;
syntax: Ono<SyntaxError>;
type: Ono<TypeError>;
uri: Ono<URIError>;
}
/**
* Creates an `Ono` instance for a specifc error type.
*/
export interface OnoConstructor {
<T extends ErrorLike>(constructor: ErrorLikeConstructor<T>, options?: OnoOptions): Ono<T>;
new <T extends ErrorLike>(constructor: ErrorLikeConstructor<T>, options?: OnoOptions): Ono<T>;
/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
toJSON<E extends ErrorLike>(error: E): ErrorPOJO & E;
/**
* Extends the given Error object with enhanced Ono functionality, such as improved support for
* `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
*/
extend<T extends ErrorLike>(error: T): T & OnoError<T>;
/**
* Extends the given Error object with enhanced Ono functionality, such as additional properties
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, P extends object>(error: T, props?: P): T & P & OnoError<T & P>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
*/
extend<T extends ErrorLike, E extends ErrorLike>(error: T, originalError?: E): T & E & OnoError<T & E>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
}
/**
* An `Ono` is a function that creates errors of a specific type.
*/
export interface Ono<T extends ErrorLike> {
/**
* The type of Error that this `Ono` function produces.
*/
readonly [Symbol.species]: ErrorLikeConstructor<T>;
/**
* Creates a new error with the message, stack trace, and properties of another error.
*
* @param error - The original error
*/
<E extends ErrorLike>(error: E): T & E & OnoError<T & E>;
/**
* Creates a new error with the message, stack trace, and properties of another error,
* as well as aditional properties.
*
* @param error - The original error
* @param props - An object whose properties will be added to the returned error
*/
<E extends ErrorLike, P extends object>(error: E, props: P): T & E & P & OnoError<T & E & P>;
/**
* Creates a new error with a formatted message and the stack trace and properties of another error.
*
* @param error - The original error
* @param message - The new error message, possibly including argument placeholders
* @param params - Optional arguments to replace the corresponding placeholders in the message
*/
<E extends ErrorLike>(error: E, message: string, ...params: unknown[]): T & E & OnoError<T & E>;
/**
* Creates a new error with a formatted message and the stack trace and properties of another error,
* as well as additional properties.
*
* @param error - The original error
* @param props - An object whose properties will be added to the returned error
* @param message - The new error message, possibly including argument placeholders
* @param params - Optional arguments to replace the corresponding placeholders in the message
*/
<E extends ErrorLike, P extends object>(error: E, props: P, message: string, ...params: unknown[]): T & E & P & OnoError<T & E & P>;
/**
* Creates an error with a formatted message.
*
* @param message - The new error message, possibly including argument placeholders
* @param params - Optional arguments to replace the corresponding placeholders in the message
*/
(message: string, ...params: unknown[]): T & OnoError<T>;
/**
* Creates an error with additional properties.
*
* @param props - An object whose properties will be added to the returned error
*/
<P extends object>(props: P): T & P & OnoError<T & P>;
/**
* Creates an error with a formatted message and additional properties.
*
* @param props - An object whose properties will be added to the returned error
* @param message - The new error message, possibly including argument placeholders
* @param params - Optional arguments to replace the corresponding placeholders in the message
*/
<P extends object>(props: P, message: string, ...params: unknown[]): T & P & OnoError<T & P>;
}
/**
* All error objects returned by Ono have these properties.
*/
export interface OnoError<T> extends ErrorPOJO {
/**
* Returns a JSON representation of the error, including all built-in error properties,
* as well as properties that were dynamically added.
*/
toJSON(): ErrorPOJO & T;
/**
* Returns a representation of the error for Node's `util.inspect()` method.
*
* @see https://nodejs.org/api/util.html#util_custom_inspection_functions_on_objects
*/
[inspect.custom](): ErrorPOJO & T;
}
/**
* An error object that doesn't inherit from the `Error` class, such as `DOMError`, `DOMException`,
* and some third-party error types.
*/
export interface ErrorPOJO {
message?: string;
stack?: string;
name?: string;
}
/**
* Any object that "looks like" an `Error` object.
*/
export declare type ErrorLike = Error | ErrorPOJO;
/**
* A constructor for `ErrorLike` objects.
*/
export declare type ErrorLikeConstructor<T extends ErrorLike> = ErrorLikeConstructorFunction<T> | ErrorLikeConstructorClass<T>;
/**
* A constructor function for `ErrorLike` objects.
* Constructor functions can be called without the `new` keyword.
*
* @example
* throw TypeError();
*/
export interface ErrorLikeConstructorFunction<T extends ErrorLike> {
readonly prototype: T;
(): T;
}
/**
* A constructor class for `ErrorLike` objects.
* Constructor classes must be called with the `new` keyword.
*
* @example
* throw new TypeError();
*/
export interface ErrorLikeConstructorClass<T extends ErrorLike> {
readonly prototype: T;
new (...args: unknown[]): T;
}
/**
* Options that determine the behavior of an `Ono` instance.
*/
export interface OnoOptions {
/**
* When `Ono` is used to wrap an error, this setting determines whether the inner error's message
* is appended to the new error message.
*
* Defaults to `true`.
*/
concatMessages?: boolean;
/**
* A function that replaces placeholders like "%s" or "%d" in error messages with values.
* If set to `false`, then error messages will be treated as literals and no placeholder replacement will occur.
*
* Defaults to `utils.inspect()` in Node.js. Defaults to `Array.join()` in browsers.
*/
format?: MessageFormatter | false;
}
/**
* A function that accepts a message template and arguments to replace template parameters.
*
* @example
* format("Hello, %s! You have %d unread messages.", "John", 5);
*/
export declare type MessageFormatter = (message: string, ...args: unknown[]) => string;
+4
View File
@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAAA,+BAA+B"}