feat: init
This commit is contained in:
9
node_modules/@poppinss/exception/LICENSE.md
generated
vendored
Normal file
9
node_modules/@poppinss/exception/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# The MIT License
|
||||
|
||||
Copyright (c) 2023
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
64
node_modules/@poppinss/exception/README.md
generated
vendored
Normal file
64
node_modules/@poppinss/exception/README.md
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
# @poppinss/exception
|
||||
|
||||
> Create custom exceptions with error code, status, and the help description.
|
||||
|
||||
<br />
|
||||
|
||||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
|
||||
|
||||
## Introduction
|
||||
|
||||
The `@poppinss/exception` package provides with a base `Exception` class that can be used to create custom errors with support for defining the **error status**, **error code**, and **help description**.
|
||||
|
||||
```ts
|
||||
import { Exception } from '@poppinss/exception'
|
||||
|
||||
class ResourceNotFound extends Exception {
|
||||
static code = 'E_RESOURCE_NOT_FOUND'
|
||||
static status = 404
|
||||
static message = 'Unable to find resource'
|
||||
}
|
||||
|
||||
throw new ResourceNotFound()
|
||||
```
|
||||
|
||||
### Anonymous error classes
|
||||
|
||||
You can also create an anonymous exception class using the `createError` method. The return value is a class constructor that accepts an array of values to use for message interpolation.
|
||||
|
||||
The interpolation of error message is performed using the [`util.format`](https://nodejs.org/api/util.html#utilformatformat-args) method.
|
||||
|
||||
```ts
|
||||
import { createError } from '@poppinss/exception'
|
||||
|
||||
const E_RESOURCE_NOT_FOUND = createError<[number]>(
|
||||
'Unable to find resource with id %d',
|
||||
'E_RESOURCE_NOT_FOUND'
|
||||
)
|
||||
|
||||
const id = 1
|
||||
throw new E_RESOURCE_NOT_FOUND([id])
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
One of the primary goals of poppinss is to have a vibrant community of users and contributors who believes in the principles of the framework.
|
||||
|
||||
We encourage you to read the [contribution guide](https://github.com/poppinss/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
In order to ensure that the poppinss community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/poppinss/.github/blob/main/docs/CODE_OF_CONDUCT.md).
|
||||
|
||||
## License
|
||||
|
||||
Poppinss exception is open-sourced software licensed under the [MIT license](LICENSE.md).
|
||||
|
||||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/poppinss/exception/checks.yml?style=for-the-badge
|
||||
[gh-workflow-url]: https://github.com/poppinss/exception/actions/workflows/checks.yml 'Github action'
|
||||
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
||||
[typescript-url]: "typescript"
|
||||
[npm-image]: https://img.shields.io/npm/v/@poppinss/exception.svg?style=for-the-badge&logo=npm
|
||||
[npm-url]: https://npmjs.org/package/@poppinss/exception 'npm'
|
||||
[license-image]: https://img.shields.io/npm/l/@poppinss/exception?color=blueviolet&style=for-the-badge
|
||||
[license-url]: LICENSE.md 'license'
|
||||
1
node_modules/@poppinss/exception/build/index.d.ts
generated
vendored
Normal file
1
node_modules/@poppinss/exception/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './src/exception.ts';
|
||||
44
node_modules/@poppinss/exception/build/index.js
generated
vendored
Normal file
44
node_modules/@poppinss/exception/build/index.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { format } from "node:util";
|
||||
var Exception = class extends Error {
|
||||
name;
|
||||
status;
|
||||
constructor(message, options) {
|
||||
super(message, options);
|
||||
const ErrorConstructor = this.constructor;
|
||||
this.name = ErrorConstructor.name;
|
||||
this.message = message || ErrorConstructor.message || "";
|
||||
this.status = options?.status || ErrorConstructor.status || 500;
|
||||
const code = options?.code || ErrorConstructor.code;
|
||||
if (code !== void 0) this.code = code;
|
||||
const help = ErrorConstructor.help;
|
||||
if (help !== void 0) this.help = help;
|
||||
Error.captureStackTrace(this, ErrorConstructor);
|
||||
}
|
||||
get [Symbol.toStringTag]() {
|
||||
return this.constructor.name;
|
||||
}
|
||||
toString() {
|
||||
if (this.code) return `${this.name} [${this.code}]: ${this.message}`;
|
||||
return `${this.name}: ${this.message}`;
|
||||
}
|
||||
};
|
||||
var InvalidArgumentsException = class extends Exception {
|
||||
static code = "E_INVALID_ARGUMENTS_EXCEPTION";
|
||||
static status = 500;
|
||||
};
|
||||
var RuntimeException = class extends Exception {
|
||||
static code = "E_RUNTIME_EXCEPTION";
|
||||
static status = 500;
|
||||
};
|
||||
function createError(message, code, status) {
|
||||
return class extends Exception {
|
||||
static message = message;
|
||||
static code = code;
|
||||
static status = status;
|
||||
constructor(args, options) {
|
||||
super(format(message, ...args || []), options);
|
||||
this.name = "Exception";
|
||||
}
|
||||
};
|
||||
}
|
||||
export { Exception, InvalidArgumentsException, RuntimeException, createError };
|
||||
76
node_modules/@poppinss/exception/build/src/exception.d.ts
generated
vendored
Normal file
76
node_modules/@poppinss/exception/build/src/exception.d.ts
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Create a custom error class with the ability to define the error
|
||||
* code, status, and the help text.
|
||||
*
|
||||
* ```js
|
||||
* export class FileNotFoundException extends Exception {
|
||||
* static status = 500
|
||||
* static code = 'E_FILE_NOT_FOUND'
|
||||
* }
|
||||
*
|
||||
* throw new FileNotFoundException(
|
||||
* `Unable to find file from ${filePath} location`
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
export declare class Exception extends Error {
|
||||
/**
|
||||
* Define the error metadata as static properties to avoid
|
||||
* setting them repeatedly on the error instance
|
||||
*/
|
||||
static help?: string;
|
||||
static code?: string;
|
||||
static status?: number;
|
||||
static message?: string;
|
||||
/**
|
||||
* Name of the class that raised the exception.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Optional help description for the error. You can use it to define additional
|
||||
* human readable information for the error.
|
||||
*/
|
||||
help?: string;
|
||||
/**
|
||||
* A machine readable error code. This will allow the error handling logic
|
||||
* to narrow down exceptions based upon the error code.
|
||||
*/
|
||||
code?: string;
|
||||
/**
|
||||
* A status code for the error. Usually helpful when converting errors
|
||||
* to HTTP responses.
|
||||
*/
|
||||
status: number;
|
||||
constructor(message?: string, options?: ErrorOptions & {
|
||||
code?: string;
|
||||
status?: number;
|
||||
});
|
||||
get [Symbol.toStringTag](): string;
|
||||
toString(): string;
|
||||
}
|
||||
export declare class InvalidArgumentsException extends Exception {
|
||||
static code: string;
|
||||
static status: number;
|
||||
}
|
||||
export declare class RuntimeException extends Exception {
|
||||
static code: string;
|
||||
static status: number;
|
||||
}
|
||||
/**
|
||||
* Helper to create an anonymous error class.
|
||||
*
|
||||
* ```ts
|
||||
*
|
||||
* const E_RESOURCE_NOT_FOUND = createError<[number]>(
|
||||
* 'Unable to find resource with id %d',
|
||||
* 'E_RESOURCE_NOT_FOUND'
|
||||
* )
|
||||
* const id = 1
|
||||
* throw new E_RESOURCE_NOT_FOUND([id])
|
||||
*```
|
||||
*/
|
||||
export declare function createError<T extends any[] = never>(message: string, code: string, status?: number): typeof Exception & T extends never ? {
|
||||
new (args?: any, options?: ErrorOptions): Exception;
|
||||
} : {
|
||||
new (args: T, options?: ErrorOptions): Exception;
|
||||
};
|
||||
109
node_modules/@poppinss/exception/package.json
generated
vendored
Normal file
109
node_modules/@poppinss/exception/package.json
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"name": "@poppinss/exception",
|
||||
"description": "Utility to create custom exceptions",
|
||||
"version": "1.2.3",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"build",
|
||||
"!build/bin",
|
||||
"!build/tests"
|
||||
],
|
||||
"main": "build/index.js",
|
||||
"exports": {
|
||||
".": "./build/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "npm run lint",
|
||||
"test": "c8 npm run quick:test",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write .",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"precompile": "npm run lint",
|
||||
"compile": "tsdown && tsc --emitDeclarationOnly --declaration",
|
||||
"build": "npm run compile",
|
||||
"version": "npm run build",
|
||||
"prepublishOnly": "npm run build",
|
||||
"release": "release-it",
|
||||
"quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@adonisjs/eslint-config": "^3.0.0-next.5",
|
||||
"@adonisjs/prettier-config": "^1.4.5",
|
||||
"@adonisjs/tsconfig": "^2.0.0-next.3",
|
||||
"@japa/expect": "^3.0.6",
|
||||
"@japa/expect-type": "^2.0.3",
|
||||
"@japa/runner": "^4.4.0",
|
||||
"@poppinss/ts-exec": "^1.4.1",
|
||||
"@release-it/conventional-changelog": "^10.0.3",
|
||||
"@types/node": "^25.0.1",
|
||||
"c8": "^10.1.3",
|
||||
"eslint": "^9.39.1",
|
||||
"prettier": "^3.7.4",
|
||||
"release-it": "^19.1.0",
|
||||
"tsdown": "^0.17.3",
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"homepage": "https://github.com/poppinss/exception#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/poppinss/exception.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/poppinss/exception/issues"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Harminder Virk <virk@adonisjs.com>",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"tsdown": {
|
||||
"entry": [
|
||||
"index.ts"
|
||||
],
|
||||
"outDir": "./build",
|
||||
"clean": true,
|
||||
"format": "esm",
|
||||
"minify": "dce-only",
|
||||
"fixedExtension": false,
|
||||
"dts": false,
|
||||
"treeshake": false,
|
||||
"sourcemaps": false,
|
||||
"target": "esnext"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"requireCleanWorkingDir": true,
|
||||
"requireUpstream": true,
|
||||
"commitMessage": "chore(release): ${version}",
|
||||
"tagAnnotation": "v${version}",
|
||||
"push": true,
|
||||
"tagName": "v${version}"
|
||||
},
|
||||
"github": {
|
||||
"release": true
|
||||
},
|
||||
"npm": {
|
||||
"publish": true,
|
||||
"skipChecks": true
|
||||
},
|
||||
"plugins": {
|
||||
"@release-it/conventional-changelog": {
|
||||
"preset": {
|
||||
"name": "angular"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"c8": {
|
||||
"reporter": [
|
||||
"text",
|
||||
"html"
|
||||
],
|
||||
"exclude": [
|
||||
"tests/**"
|
||||
]
|
||||
},
|
||||
"prettier": "@adonisjs/prettier-config"
|
||||
}
|
||||
Reference in New Issue
Block a user