@orion-js/helpers 3.11.15 → 4.0.0-alpha.3
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/dist/index.cjs +1018 -0
- package/dist/index.d.ts +362 -0
- package/dist/index.js +992 -0
- package/package.json +21 -15
- package/LICENSE +0 -21
- package/jest.config.js +0 -8
- package/lib/Errors/OrionError.d.ts +0 -39
- package/lib/Errors/OrionError.js +0 -23
- package/lib/Errors/OrionError.test.d.ts +0 -1
- package/lib/Errors/OrionError.test.js +0 -52
- package/lib/Errors/PermissionsError.d.ts +0 -37
- package/lib/Errors/PermissionsError.js +0 -57
- package/lib/Errors/PermissionsError.test.d.ts +0 -1
- package/lib/Errors/PermissionsError.test.js +0 -62
- package/lib/Errors/UserError.d.ts +0 -33
- package/lib/Errors/UserError.js +0 -54
- package/lib/Errors/UserError.test.d.ts +0 -1
- package/lib/Errors/UserError.test.js +0 -49
- package/lib/Errors/index.d.ts +0 -43
- package/lib/Errors/index.js +0 -57
- package/lib/Errors/index.test.d.ts +0 -1
- package/lib/Errors/index.test.js +0 -56
- package/lib/composeMiddlewares.d.ts +0 -6
- package/lib/composeMiddlewares.js +0 -44
- package/lib/createMap.d.ts +0 -17
- package/lib/createMap.js +0 -26
- package/lib/createMap.test.d.ts +0 -1
- package/lib/createMap.test.js +0 -74
- package/lib/createMapArray.d.ts +0 -22
- package/lib/createMapArray.js +0 -32
- package/lib/createMapArray.test.d.ts +0 -1
- package/lib/createMapArray.test.js +0 -101
- package/lib/generateId.d.ts +0 -6
- package/lib/generateId.js +0 -54
- package/lib/generateId.test.d.ts +0 -1
- package/lib/generateId.test.js +0 -11
- package/lib/generateUUID.d.ts +0 -2
- package/lib/generateUUID.js +0 -12
- package/lib/generateUUID.test.d.ts +0 -1
- package/lib/generateUUID.test.js +0 -15
- package/lib/hashObject.d.ts +0 -1
- package/lib/hashObject.js +0 -10
- package/lib/hashObject.test.d.ts +0 -1
- package/lib/hashObject.test.js +0 -30
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -40
- package/lib/normalize.d.ts +0 -70
- package/lib/normalize.js +0 -111
- package/lib/normalize.test.d.ts +0 -1
- package/lib/normalize.test.js +0 -101
- package/lib/retries.d.ts +0 -23
- package/lib/retries.js +0 -45
- package/lib/retries.test.d.ts +0 -1
- package/lib/retries.test.js +0 -47
- package/lib/searchTokens.d.ts +0 -61
- package/lib/searchTokens.js +0 -78
- package/lib/searchTokens.test.d.ts +0 -1
- package/lib/searchTokens.test.js +0 -101
- package/lib/shortenMongoId.d.ts +0 -1
- package/lib/shortenMongoId.js +0 -10
- package/lib/sleep.d.ts +0 -5
- package/lib/sleep.js +0 -8
- package/tsconfig.json +0 -16
- package/yarn-error.log +0 -710
package/package.json
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/helpers",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "4.0.0-alpha.3",
|
|
4
|
+
"main": "./dist/index.cjs",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
5
15
|
"author": "nicolaslopezj",
|
|
6
16
|
"license": "MIT",
|
|
7
17
|
"scripts": {
|
|
8
|
-
"test": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"watch": "tsc -w",
|
|
13
|
-
"upgrade-interactive": "yarn upgrade-interactive"
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"build": "bun run build.ts",
|
|
20
|
+
"dev": "bun --watch src/index.ts",
|
|
21
|
+
"clean": "rm -rf ./dist"
|
|
14
22
|
},
|
|
15
23
|
"dependencies": {
|
|
16
24
|
"object-hash": "^2.2.0"
|
|
17
25
|
},
|
|
18
26
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"ts-jest": "^29.0.5",
|
|
23
|
-
"typescript": "^4.4.4"
|
|
27
|
+
"@types/bun": "^1.2.4",
|
|
28
|
+
"typescript": "^4.4.4",
|
|
29
|
+
"vitest": "^0.34.6"
|
|
24
30
|
},
|
|
25
31
|
"publishConfig": {
|
|
26
32
|
"access": "public"
|
|
27
33
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
-
}
|
|
34
|
+
"gitHead": "a485b1fe6a1840ee6cb58fd69d6de62585f1ed10"
|
|
35
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Orionjs Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/jest.config.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface representing the standardized error information structure for Orion errors.
|
|
3
|
-
* This is used by the getInfo method to provide consistent error reporting.
|
|
4
|
-
*/
|
|
5
|
-
export interface OrionErrorInformation {
|
|
6
|
-
/** The error code or identifier */
|
|
7
|
-
error: string;
|
|
8
|
-
/** Human-readable error message */
|
|
9
|
-
message: string;
|
|
10
|
-
/** Additional error metadata or context */
|
|
11
|
-
extra: any;
|
|
12
|
-
/** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */
|
|
13
|
-
type?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Base error class for all Orion-specific errors.
|
|
17
|
-
*
|
|
18
|
-
* This abstract class provides common properties and methods for all error types
|
|
19
|
-
* used in the Orion framework. It's extended by more specific error classes
|
|
20
|
-
* like UserError and PermissionsError.
|
|
21
|
-
*
|
|
22
|
-
* @property isOrionError - Flag indicating this is an Orion error (always true)
|
|
23
|
-
* @property isUserError - Flag indicating if this is a user-facing error
|
|
24
|
-
* @property isPermissionsError - Flag indicating if this is a permissions-related error
|
|
25
|
-
* @property code - Error code for identifying the error type
|
|
26
|
-
* @property extra - Additional error context or metadata
|
|
27
|
-
*/
|
|
28
|
-
export declare class OrionError extends Error {
|
|
29
|
-
isOrionError: boolean;
|
|
30
|
-
isUserError: boolean;
|
|
31
|
-
isPermissionsError: boolean;
|
|
32
|
-
code: string;
|
|
33
|
-
extra: any;
|
|
34
|
-
/**
|
|
35
|
-
* Returns a standardized representation of the error information.
|
|
36
|
-
* @returns An object containing error details in a consistent format
|
|
37
|
-
*/
|
|
38
|
-
getInfo: () => OrionErrorInformation;
|
|
39
|
-
}
|
package/lib/Errors/OrionError.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrionError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Base error class for all Orion-specific errors.
|
|
6
|
-
*
|
|
7
|
-
* This abstract class provides common properties and methods for all error types
|
|
8
|
-
* used in the Orion framework. It's extended by more specific error classes
|
|
9
|
-
* like UserError and PermissionsError.
|
|
10
|
-
*
|
|
11
|
-
* @property isOrionError - Flag indicating this is an Orion error (always true)
|
|
12
|
-
* @property isUserError - Flag indicating if this is a user-facing error
|
|
13
|
-
* @property isPermissionsError - Flag indicating if this is a permissions-related error
|
|
14
|
-
* @property code - Error code for identifying the error type
|
|
15
|
-
* @property extra - Additional error context or metadata
|
|
16
|
-
*/
|
|
17
|
-
class OrionError extends Error {
|
|
18
|
-
constructor() {
|
|
19
|
-
super(...arguments);
|
|
20
|
-
this.isOrionError = true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.OrionError = OrionError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const OrionError_1 = require("./OrionError");
|
|
4
|
-
// Since OrionError is an abstract class with unimplemented methods,
|
|
5
|
-
// we'll create a concrete implementation for testing
|
|
6
|
-
class TestOrionError extends OrionError_1.OrionError {
|
|
7
|
-
constructor(message, code = 'test_error', extra = {}) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.extra = extra;
|
|
11
|
-
this.isUserError = false;
|
|
12
|
-
this.isPermissionsError = false;
|
|
13
|
-
this.getInfo = () => {
|
|
14
|
-
return {
|
|
15
|
-
error: this.code,
|
|
16
|
-
message: this.message,
|
|
17
|
-
extra: this.extra
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
describe('OrionError', () => {
|
|
23
|
-
it('should be an instance of Error', () => {
|
|
24
|
-
const error = new TestOrionError('Test error message');
|
|
25
|
-
expect(error).toBeInstanceOf(Error);
|
|
26
|
-
});
|
|
27
|
-
it('should have OrionError properties', () => {
|
|
28
|
-
const error = new TestOrionError('Test error message');
|
|
29
|
-
expect(error.isOrionError).toBe(true);
|
|
30
|
-
expect(error.isUserError).toBe(false);
|
|
31
|
-
expect(error.isPermissionsError).toBe(false);
|
|
32
|
-
expect(error.code).toBe('test_error');
|
|
33
|
-
expect(error.message).toBe('Test error message');
|
|
34
|
-
});
|
|
35
|
-
it('should have a getInfo method that returns the correct structure', () => {
|
|
36
|
-
const extraData = { userId: '123', context: 'testing' };
|
|
37
|
-
const error = new TestOrionError('Test error message', 'custom_code', extraData);
|
|
38
|
-
const info = error.getInfo();
|
|
39
|
-
expect(info).toEqual({
|
|
40
|
-
error: 'custom_code',
|
|
41
|
-
message: 'Test error message',
|
|
42
|
-
extra: extraData
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it('should be extendable with custom properties', () => {
|
|
46
|
-
const error = new TestOrionError('Test error message');
|
|
47
|
-
error.customProp = 'custom value';
|
|
48
|
-
expect(error.customProp).toBe('custom value');
|
|
49
|
-
expect(error.message).toBe('Test error message');
|
|
50
|
-
expect(error.isOrionError).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { OrionError } from './OrionError';
|
|
2
|
-
/**
|
|
3
|
-
* Error class for permission-related errors in the Orion framework.
|
|
4
|
-
*
|
|
5
|
-
* PermissionsError represents authorization failures where a user or client
|
|
6
|
-
* attempts to perform an action they don't have permission to execute.
|
|
7
|
-
* This is used to distinguish security/permissions errors from other types
|
|
8
|
-
* of errors for proper error handling and user feedback.
|
|
9
|
-
*
|
|
10
|
-
* @extends OrionError
|
|
11
|
-
*/
|
|
12
|
-
export default class PermissionsError extends OrionError {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new PermissionsError instance.
|
|
15
|
-
*
|
|
16
|
-
* @param permissionErrorType - Identifies the specific permission that was violated
|
|
17
|
-
* (e.g., 'read', 'write', 'admin')
|
|
18
|
-
* @param extra - Additional error context or metadata. Can include a custom message
|
|
19
|
-
* via the message property.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* // Basic usage
|
|
23
|
-
* throw new PermissionsError('delete_document')
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // With custom message
|
|
27
|
-
* throw new PermissionsError('access_admin', { message: 'Admin access required' })
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* // With additional context
|
|
31
|
-
* throw new PermissionsError('edit_user', {
|
|
32
|
-
* userId: 'user123',
|
|
33
|
-
* requiredRole: 'admin'
|
|
34
|
-
* })
|
|
35
|
-
*/
|
|
36
|
-
constructor(permissionErrorType: any, extra?: any);
|
|
37
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const OrionError_1 = require("./OrionError");
|
|
4
|
-
/**
|
|
5
|
-
* Error class for permission-related errors in the Orion framework.
|
|
6
|
-
*
|
|
7
|
-
* PermissionsError represents authorization failures where a user or client
|
|
8
|
-
* attempts to perform an action they don't have permission to execute.
|
|
9
|
-
* This is used to distinguish security/permissions errors from other types
|
|
10
|
-
* of errors for proper error handling and user feedback.
|
|
11
|
-
*
|
|
12
|
-
* @extends OrionError
|
|
13
|
-
*/
|
|
14
|
-
class PermissionsError extends OrionError_1.OrionError {
|
|
15
|
-
/**
|
|
16
|
-
* Creates a new PermissionsError instance.
|
|
17
|
-
*
|
|
18
|
-
* @param permissionErrorType - Identifies the specific permission that was violated
|
|
19
|
-
* (e.g., 'read', 'write', 'admin')
|
|
20
|
-
* @param extra - Additional error context or metadata. Can include a custom message
|
|
21
|
-
* via the message property.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // Basic usage
|
|
25
|
-
* throw new PermissionsError('delete_document')
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* // With custom message
|
|
29
|
-
* throw new PermissionsError('access_admin', { message: 'Admin access required' })
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* // With additional context
|
|
33
|
-
* throw new PermissionsError('edit_user', {
|
|
34
|
-
* userId: 'user123',
|
|
35
|
-
* requiredRole: 'admin'
|
|
36
|
-
* })
|
|
37
|
-
*/
|
|
38
|
-
constructor(permissionErrorType, extra = {}) {
|
|
39
|
-
// Calling parent constructor of base Error class.
|
|
40
|
-
const message = extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`;
|
|
41
|
-
super(message);
|
|
42
|
-
Error.captureStackTrace(this, this.constructor);
|
|
43
|
-
this.isOrionError = true;
|
|
44
|
-
this.isPermissionsError = true;
|
|
45
|
-
this.code = 'PermissionsError';
|
|
46
|
-
this.extra = extra;
|
|
47
|
-
this.getInfo = () => {
|
|
48
|
-
return {
|
|
49
|
-
...extra,
|
|
50
|
-
error: 'PermissionsError',
|
|
51
|
-
message,
|
|
52
|
-
type: permissionErrorType
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.default = PermissionsError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const PermissionsError_1 = __importDefault(require("./PermissionsError"));
|
|
7
|
-
const OrionError_1 = require("./OrionError");
|
|
8
|
-
describe('PermissionsError', () => {
|
|
9
|
-
it('should extend OrionError', () => {
|
|
10
|
-
const error = new PermissionsError_1.default('read_document');
|
|
11
|
-
expect(error).toBeInstanceOf(OrionError_1.OrionError);
|
|
12
|
-
});
|
|
13
|
-
it('should set isPermissionsError to true', () => {
|
|
14
|
-
const error = new PermissionsError_1.default('read_document');
|
|
15
|
-
expect(error.isPermissionsError).toBe(true);
|
|
16
|
-
expect(error.isOrionError).toBe(true);
|
|
17
|
-
expect(error.isUserError).toBeUndefined();
|
|
18
|
-
});
|
|
19
|
-
it('should set code to "PermissionsError"', () => {
|
|
20
|
-
const error = new PermissionsError_1.default('read_document');
|
|
21
|
-
expect(error.code).toBe('PermissionsError');
|
|
22
|
-
});
|
|
23
|
-
it('should generate a default message with permissionErrorType', () => {
|
|
24
|
-
const error = new PermissionsError_1.default('update_user');
|
|
25
|
-
expect(error.message).toBe('Client is not allowed to perform this action [update_user]');
|
|
26
|
-
});
|
|
27
|
-
it('should support custom message in extra', () => {
|
|
28
|
-
const error = new PermissionsError_1.default('delete_document', {
|
|
29
|
-
message: 'You need admin rights to delete this document'
|
|
30
|
-
});
|
|
31
|
-
expect(error.message).toBe('You need admin rights to delete this document');
|
|
32
|
-
});
|
|
33
|
-
it('should store extra data', () => {
|
|
34
|
-
const extraData = {
|
|
35
|
-
documentId: '123',
|
|
36
|
-
requiredRole: 'admin'
|
|
37
|
-
};
|
|
38
|
-
const error = new PermissionsError_1.default('read_document', extraData);
|
|
39
|
-
expect(error.extra).toEqual(extraData);
|
|
40
|
-
});
|
|
41
|
-
it('should have a getInfo method that returns the correct structure', () => {
|
|
42
|
-
const extraData = { documentId: '123', requiredRole: 'admin' };
|
|
43
|
-
const error = new PermissionsError_1.default('read_document', extraData);
|
|
44
|
-
const info = error.getInfo();
|
|
45
|
-
expect(info).toEqual({
|
|
46
|
-
...extraData,
|
|
47
|
-
error: 'PermissionsError',
|
|
48
|
-
message: 'Client is not allowed to perform this action [read_document]',
|
|
49
|
-
type: 'read_document'
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
it('should include the permission type in getInfo', () => {
|
|
53
|
-
const error = new PermissionsError_1.default('admin_action');
|
|
54
|
-
const info = error.getInfo();
|
|
55
|
-
expect(info.type).toBe('admin_action');
|
|
56
|
-
});
|
|
57
|
-
it('should have proper stack trace', () => {
|
|
58
|
-
const error = new PermissionsError_1.default('read_document');
|
|
59
|
-
expect(error.stack).toBeDefined();
|
|
60
|
-
expect(error.stack.includes('PermissionsError.test.ts')).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { OrionError } from './OrionError';
|
|
2
|
-
/**
|
|
3
|
-
* Error class for user-facing errors in the Orion framework.
|
|
4
|
-
*
|
|
5
|
-
* UserError is designed to represent errors that should be displayed to end users,
|
|
6
|
-
* as opposed to system errors or unexpected failures. These errors typically represent
|
|
7
|
-
* validation issues, business rule violations, or other expected error conditions.
|
|
8
|
-
*
|
|
9
|
-
* @extends OrionError
|
|
10
|
-
*/
|
|
11
|
-
export default class UserError extends OrionError {
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new UserError instance.
|
|
14
|
-
*
|
|
15
|
-
* @param code - Error code identifier. If only one parameter is provided,
|
|
16
|
-
* this will be used as the message and code will default to 'error'.
|
|
17
|
-
* @param message - Human-readable error message. Optional if code is provided.
|
|
18
|
-
* @param extra - Additional error context or metadata.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Basic usage
|
|
22
|
-
* throw new UserError('invalid_input', 'The provided email is invalid')
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* // Using only a message (code will be 'error')
|
|
26
|
-
* throw new UserError('Input validation failed')
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* // With extra metadata
|
|
30
|
-
* throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
|
|
31
|
-
*/
|
|
32
|
-
constructor(code: string, message?: string, extra?: any);
|
|
33
|
-
}
|
package/lib/Errors/UserError.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const OrionError_1 = require("./OrionError");
|
|
4
|
-
/**
|
|
5
|
-
* Error class for user-facing errors in the Orion framework.
|
|
6
|
-
*
|
|
7
|
-
* UserError is designed to represent errors that should be displayed to end users,
|
|
8
|
-
* as opposed to system errors or unexpected failures. These errors typically represent
|
|
9
|
-
* validation issues, business rule violations, or other expected error conditions.
|
|
10
|
-
*
|
|
11
|
-
* @extends OrionError
|
|
12
|
-
*/
|
|
13
|
-
class UserError extends OrionError_1.OrionError {
|
|
14
|
-
/**
|
|
15
|
-
* Creates a new UserError instance.
|
|
16
|
-
*
|
|
17
|
-
* @param code - Error code identifier. If only one parameter is provided,
|
|
18
|
-
* this will be used as the message and code will default to 'error'.
|
|
19
|
-
* @param message - Human-readable error message. Optional if code is provided.
|
|
20
|
-
* @param extra - Additional error context or metadata.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* // Basic usage
|
|
24
|
-
* throw new UserError('invalid_input', 'The provided email is invalid')
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* // Using only a message (code will be 'error')
|
|
28
|
-
* throw new UserError('Input validation failed')
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* // With extra metadata
|
|
32
|
-
* throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
|
|
33
|
-
*/
|
|
34
|
-
constructor(code, message, extra) {
|
|
35
|
-
if (!message && code) {
|
|
36
|
-
message = code;
|
|
37
|
-
code = 'error';
|
|
38
|
-
}
|
|
39
|
-
super(message);
|
|
40
|
-
Error.captureStackTrace(this, this.constructor);
|
|
41
|
-
this.isOrionError = true;
|
|
42
|
-
this.isUserError = true;
|
|
43
|
-
this.code = code;
|
|
44
|
-
this.extra = extra;
|
|
45
|
-
this.getInfo = () => {
|
|
46
|
-
return {
|
|
47
|
-
error: code,
|
|
48
|
-
message,
|
|
49
|
-
extra
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.default = UserError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const UserError_1 = __importDefault(require("./UserError"));
|
|
7
|
-
const OrionError_1 = require("./OrionError");
|
|
8
|
-
describe('UserError', () => {
|
|
9
|
-
it('should extend OrionError', () => {
|
|
10
|
-
const error = new UserError_1.default('test_code', 'Test error message');
|
|
11
|
-
expect(error).toBeInstanceOf(OrionError_1.OrionError);
|
|
12
|
-
});
|
|
13
|
-
it('should set isUserError to true', () => {
|
|
14
|
-
const error = new UserError_1.default('test_code', 'Test error message');
|
|
15
|
-
expect(error.isUserError).toBe(true);
|
|
16
|
-
expect(error.isOrionError).toBe(true);
|
|
17
|
-
expect(error.isPermissionsError).toBeUndefined();
|
|
18
|
-
});
|
|
19
|
-
it('should set code and message correctly', () => {
|
|
20
|
-
const error = new UserError_1.default('test_code', 'Test error message');
|
|
21
|
-
expect(error.code).toBe('test_code');
|
|
22
|
-
expect(error.message).toBe('Test error message');
|
|
23
|
-
});
|
|
24
|
-
it('should support providing only a message (code defaults to "error")', () => {
|
|
25
|
-
const error = new UserError_1.default('Test error message');
|
|
26
|
-
expect(error.code).toBe('error');
|
|
27
|
-
expect(error.message).toBe('Test error message');
|
|
28
|
-
});
|
|
29
|
-
it('should support extra data', () => {
|
|
30
|
-
const extraData = { field: 'username', constraint: 'required' };
|
|
31
|
-
const error = new UserError_1.default('validation_error', 'Validation failed', extraData);
|
|
32
|
-
expect(error.extra).toEqual(extraData);
|
|
33
|
-
});
|
|
34
|
-
it('should have a getInfo method that returns the correct structure', () => {
|
|
35
|
-
const extraData = { field: 'email', constraint: 'format' };
|
|
36
|
-
const error = new UserError_1.default('invalid_email', 'Invalid email format', extraData);
|
|
37
|
-
const info = error.getInfo();
|
|
38
|
-
expect(info).toEqual({
|
|
39
|
-
error: 'invalid_email',
|
|
40
|
-
message: 'Invalid email format',
|
|
41
|
-
extra: extraData
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it('should have proper stack trace', () => {
|
|
45
|
-
const error = new UserError_1.default('test_code', 'Test error message');
|
|
46
|
-
expect(error.stack).toBeDefined();
|
|
47
|
-
expect(error.stack.includes('UserError.test.ts')).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
});
|
package/lib/Errors/index.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Exports all error classes used in the Orion framework
|
|
3
|
-
*/
|
|
4
|
-
import { OrionError, OrionErrorInformation } from './OrionError';
|
|
5
|
-
import PermissionsError from './PermissionsError';
|
|
6
|
-
import UserError from './UserError';
|
|
7
|
-
/**
|
|
8
|
-
* Re-export all error types for convenient importing
|
|
9
|
-
*/
|
|
10
|
-
export { OrionError, OrionErrorInformation, PermissionsError, UserError };
|
|
11
|
-
/**
|
|
12
|
-
* Type guard to check if an error is an OrionError
|
|
13
|
-
*
|
|
14
|
-
* @param error - Any error object to test
|
|
15
|
-
* @returns True if the error is an OrionError instance
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* try {
|
|
19
|
-
* // some code that might throw
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* if (isOrionError(error)) {
|
|
22
|
-
* // Handle Orion-specific error
|
|
23
|
-
* console.log(error.code, error.getInfo())
|
|
24
|
-
* } else {
|
|
25
|
-
* // Handle general error
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*/
|
|
29
|
-
export declare function isOrionError(error: any): error is OrionError;
|
|
30
|
-
/**
|
|
31
|
-
* Type guard to check if an error is a UserError
|
|
32
|
-
*
|
|
33
|
-
* @param error - Any error object to test
|
|
34
|
-
* @returns True if the error is a UserError instance
|
|
35
|
-
*/
|
|
36
|
-
export declare function isUserError(error: any): error is UserError;
|
|
37
|
-
/**
|
|
38
|
-
* Type guard to check if an error is a PermissionsError
|
|
39
|
-
*
|
|
40
|
-
* @param error - Any error object to test
|
|
41
|
-
* @returns True if the error is a PermissionsError instance
|
|
42
|
-
*/
|
|
43
|
-
export declare function isPermissionsError(error: any): error is PermissionsError;
|
package/lib/Errors/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file Exports all error classes used in the Orion framework
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.isPermissionsError = exports.isUserError = exports.isOrionError = exports.UserError = exports.PermissionsError = exports.OrionError = void 0;
|
|
10
|
-
const OrionError_1 = require("./OrionError");
|
|
11
|
-
Object.defineProperty(exports, "OrionError", { enumerable: true, get: function () { return OrionError_1.OrionError; } });
|
|
12
|
-
const PermissionsError_1 = __importDefault(require("./PermissionsError"));
|
|
13
|
-
exports.PermissionsError = PermissionsError_1.default;
|
|
14
|
-
const UserError_1 = __importDefault(require("./UserError"));
|
|
15
|
-
exports.UserError = UserError_1.default;
|
|
16
|
-
/**
|
|
17
|
-
* Type guard to check if an error is an OrionError
|
|
18
|
-
*
|
|
19
|
-
* @param error - Any error object to test
|
|
20
|
-
* @returns True if the error is an OrionError instance
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* try {
|
|
24
|
-
* // some code that might throw
|
|
25
|
-
* } catch (error) {
|
|
26
|
-
* if (isOrionError(error)) {
|
|
27
|
-
* // Handle Orion-specific error
|
|
28
|
-
* console.log(error.code, error.getInfo())
|
|
29
|
-
* } else {
|
|
30
|
-
* // Handle general error
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
*/
|
|
34
|
-
function isOrionError(error) {
|
|
35
|
-
return Boolean(error && typeof error === 'object' && error.isOrionError === true);
|
|
36
|
-
}
|
|
37
|
-
exports.isOrionError = isOrionError;
|
|
38
|
-
/**
|
|
39
|
-
* Type guard to check if an error is a UserError
|
|
40
|
-
*
|
|
41
|
-
* @param error - Any error object to test
|
|
42
|
-
* @returns True if the error is a UserError instance
|
|
43
|
-
*/
|
|
44
|
-
function isUserError(error) {
|
|
45
|
-
return Boolean(error && typeof error === 'object' && error.isOrionError === true && error.isUserError === true);
|
|
46
|
-
}
|
|
47
|
-
exports.isUserError = isUserError;
|
|
48
|
-
/**
|
|
49
|
-
* Type guard to check if an error is a PermissionsError
|
|
50
|
-
*
|
|
51
|
-
* @param error - Any error object to test
|
|
52
|
-
* @returns True if the error is a PermissionsError instance
|
|
53
|
-
*/
|
|
54
|
-
function isPermissionsError(error) {
|
|
55
|
-
return Boolean(error && typeof error === 'object' && error.isOrionError === true && error.isPermissionsError === true);
|
|
56
|
-
}
|
|
57
|
-
exports.isPermissionsError = isPermissionsError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/Errors/index.test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("./index");
|
|
4
|
-
describe('Error type guards', () => {
|
|
5
|
-
// Mock concrete implementation of OrionError for testing
|
|
6
|
-
class TestOrionError extends index_1.OrionError {
|
|
7
|
-
constructor() {
|
|
8
|
-
super('Test error');
|
|
9
|
-
this.code = 'test_error';
|
|
10
|
-
this.extra = {};
|
|
11
|
-
this.isOrionError = true;
|
|
12
|
-
this.isUserError = false;
|
|
13
|
-
this.isPermissionsError = false;
|
|
14
|
-
this.getInfo = () => ({
|
|
15
|
-
error: this.code,
|
|
16
|
-
message: this.message,
|
|
17
|
-
extra: this.extra
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
describe('isOrionError', () => {
|
|
22
|
-
it('should return true for OrionError instances', () => {
|
|
23
|
-
expect((0, index_1.isOrionError)(new TestOrionError())).toBe(true);
|
|
24
|
-
expect((0, index_1.isOrionError)(new index_1.UserError('test'))).toBe(true);
|
|
25
|
-
expect((0, index_1.isOrionError)(new index_1.PermissionsError('test'))).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
it('should return false for non-OrionError objects', () => {
|
|
28
|
-
expect((0, index_1.isOrionError)(new Error('Regular error'))).toBe(false);
|
|
29
|
-
expect((0, index_1.isOrionError)({ message: 'Not an error' })).toBe(false);
|
|
30
|
-
expect((0, index_1.isOrionError)(null)).toBe(false);
|
|
31
|
-
expect((0, index_1.isOrionError)(undefined)).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('isUserError', () => {
|
|
35
|
-
it('should return true for UserError instances', () => {
|
|
36
|
-
expect((0, index_1.isUserError)(new index_1.UserError('test'))).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
it('should return false for other error types', () => {
|
|
39
|
-
expect((0, index_1.isUserError)(new TestOrionError())).toBe(false);
|
|
40
|
-
expect((0, index_1.isUserError)(new index_1.PermissionsError('test'))).toBe(false);
|
|
41
|
-
expect((0, index_1.isUserError)(new Error('Regular error'))).toBe(false);
|
|
42
|
-
expect((0, index_1.isUserError)(null)).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('isPermissionsError', () => {
|
|
46
|
-
it('should return true for PermissionsError instances', () => {
|
|
47
|
-
expect((0, index_1.isPermissionsError)(new index_1.PermissionsError('test'))).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
it('should return false for other error types', () => {
|
|
50
|
-
expect((0, index_1.isPermissionsError)(new TestOrionError())).toBe(false);
|
|
51
|
-
expect((0, index_1.isPermissionsError)(new index_1.UserError('test'))).toBe(false);
|
|
52
|
-
expect((0, index_1.isPermissionsError)(new Error('Regular error'))).toBe(false);
|
|
53
|
-
expect((0, index_1.isPermissionsError)(null)).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|