@based/errors 1.3.0 → 1.3.1-alpha.1
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 +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index_original.d.ts +21 -0
- package/package.json +13 -7
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var f=(e,r)=>{for(var a in r)l(e,a,{get:r[a],enumerable:!0})},h=(e,r,a,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of y(r))!b.call(e,n)&&n!==a&&l(e,n,{get:()=>r[n],enumerable:!(s=P(r,n))||s.enumerable});return e};var v=e=>h(l({},"__esModule",{value:!0}),e);var M={};f(M,{BasedError:()=>i,BasedErrorCode:()=>u,EMPTY_ROUTE:()=>c,convertDataToBasedError:()=>F,createErrorData:()=>I,errorTypeHandlers:()=>p});module.exports=v(M);function g(e){return e&&typeof e=="object"&&(e.type==="channel"||e.type==="query"||e.type==="function"||e.type==="http"||e.type==="stream")&&typeof e.name=="string"}var u=(t=>(t[t.incorrectFieldType=1e3]="incorrectFieldType",t[t.incorrectNodeType=1001]="incorrectNodeType",t[t.exceedsMaximum=1002]="exceedsMaximum",t[t.subceedsMinimum=1003]="subceedsMinimum",t[t.fieldDoesNotExist=1004]="fieldDoesNotExist",t[t.incorrectFormat=1005]="incorrectFormat",t[t.referenceIsIncorrectType=1006]="referenceIsIncorrectType",t[t.valueAndDefault=1007]="valueAndDefault",t[t.defaultNotSupported=1008]="defaultNotSupported",t[t.multipleOperationsNotAllowed=1009]="multipleOperationsNotAllowed",t[t.requiredFieldNotDefined=1010]="requiredFieldNotDefined",t[t.languageNotSupported=1011]="languageNotSupported",t[t.invalidJSON=1012]="invalidJSON",t[t.noLanguageFound=1013]="noLanguageFound",t[t.cannotDeleteNodeFromModify=1014]="cannotDeleteNodeFromModify",t[t.nestedModifyObjectNotAllowed=1015]="nestedModifyObjectNotAllowed",t[t.infinityNotSupported=1016]="infinityNotSupported",t[t.invalidSchemaFormat=1017]="invalidSchemaFormat",t[t.invalidProperty=1018]="invalidProperty",t[t.FunctionError=50001]="FunctionError",t[t.AuthorizeFunctionError=50002]="AuthorizeFunctionError",t[t.NoOservableCacheAvailable=50003]="NoOservableCacheAvailable",t[t.ObservableFunctionError=50004]="ObservableFunctionError",t[t.ObserveCallbackError=50005]="ObserveCallbackError",t[t.FunctionNotFound=40401]="FunctionNotFound",t[t.FunctionIsNotObservable=40402]="FunctionIsNotObservable",t[t.FunctionIsObservable=40403]="FunctionIsObservable",t[t.FunctionIsStream=40404]="FunctionIsStream",t[t.CannotStreamToObservableFunction=40405]="CannotStreamToObservableFunction",t[t.FunctionIsWrongType=40406]="FunctionIsWrongType",t[t.AuthorizeRejectedError=40301]="AuthorizeRejectedError",t[t.InvalidPayload=40001]="InvalidPayload",t[t.PayloadTooLarge=40002]="PayloadTooLarge",t[t.ChunkTooLarge=40003]="ChunkTooLarge",t[t.UnsupportedContentEncoding=40004]="UnsupportedContentEncoding",t[t.NoBinaryProtocol=40005]="NoBinaryProtocol",t[t.LengthRequired=41101]="LengthRequired",t[t.MethodNotAllowed=40501]="MethodNotAllowed",t[t.RateLimit=40029]="RateLimit",t[t.MissingAuthStateProtocolHeader=40030]="MissingAuthStateProtocolHeader",t[t.IncorrectAccessKey=40031]="IncorrectAccessKey",t[t.Block=90001]="Block",t[t.PrefixAlreadyInUse=2e3]="PrefixAlreadyInUse",t[t.CannotChangeFieldInStrictMode=2001]="CannotChangeFieldInStrictMode",t[t.CannotRemoveFieldInStrictMode=2002]="CannotRemoveFieldInStrictMode",t[t.CannotMutateWithExistingData=2003]="CannotMutateWithExistingData",t[t.CannotDeleteRoot=2004]="CannotDeleteRoot",t[t.CannotChangeDefaultField=2005]="CannotChangeDefaultField",t[t.CannotRemoveLastProperty=2006]="CannotRemoveLastProperty",t))(u||{});var i=class extends Error{statusMessage;code};var F=(e,r)=>{if(!e||typeof e!="object"){let m=new i(`Payload: ${e}`);return m.name="Invalid returned payload",m}let{message:a,code:s}=e,n=a?a[0]==="["?a:`[${u[s]}] `+a:s?"Cannot read error msg":JSON.stringify(e,null,2),d=new i(n);return d.stack=r?n+" "+r:n,d.name=u[s],d.code=s,d};var o=e=>e.name?`[${e.name}] `:"",p={1e3:{message:e=>`[${e.path.join(".")}] Incorrect field type.`},1001:{message:e=>`[${e.path.join(".")}] Incorrect node type.`},1002:{message:e=>`[${e.path.join(".")}] Exceeds maximum property.`},1003:{message:e=>`[${e.path.join(".")}] Subceeds minimum property.`},1004:{message:e=>`[${e.path.join(".")}] Field does not exist.`},1005:{message:e=>`[${e.path.join(".")}] Incorrect format.`},1006:{message:e=>`[${e.path.join(".")}] Reference is from incorrect type.`},1007:{message:e=>`[${e.path.join(".")}] Value and $default are being used at the same time.`},1008:{message:e=>`[${e.path.join(".")}] $default is not suported.`},1009:{message:e=>`[${e.path.join(".")}] Multiple operations are not allowed here.`},1010:{message:e=>`[${e.path.join(".")}] Required field is not defined.`},1011:{message:e=>`[${e.path.join(".")}] Language not supported.`},1012:{message:e=>`[${e.path.join(".")}] Invalid JSON.`},1013:{message:e=>`[${e.path.join(".")}] No language found.`},1014:{message:e=>`[${e.path.join(".")}] Cannot delete node from modify.`},1015:{message:e=>`[${e.path.join(".")}] Nested modify object not allowed.`},1016:{message:e=>`[${e.path.join(".")}] Infinity not supported.`},1017:{message:e=>`[${e.path.join(".")}] Invalid schema format.`},1018:{message:e=>`[${e.path.join(".")}] Invalid property.`},50001:{statusCode:500,statusMessage:"Internal Server Error",message:e=>typeof e.err=="string"||!e.err.message?`[${e.route.name}] ${JSON.stringify(e.err)}`:o(e.route)+`${e.err.name&&e.err.name!=="Error"?`[${e.err.name}] `:""}${e.err.message||""}.`},50002:{statusCode:403,statusMessage:"Forbidden",message:e=>typeof e.err=="string"||!e.err.message?`[${e.route.name}] ${JSON.stringify(e.err)}`:o(e.route)+`${e.err.name&&e.err.name!=="Error"?`[${e.err.name}] `:""}${e.err.message||""}.`},50003:{statusCode:500,statusMessage:"Internal Server Error",message:e=>o(e.route)+`No observable cache available${e.route.name} - ${e.observableId}.`},50004:{statusCode:500,statusMessage:"Internal Server Error",message:e=>typeof e.err=="string"||!e.err.message?`[${e.route.name} (observable)] ${JSON.stringify(e.err)}.`:o(e.route)+`${e.err.name&&e.err.name!=="Error"?`[${e.err.name}] `:""}${e.err.message||""}.`},50005:{statusCode:500,statusMessage:"Internal Server Error",message:()=>"Error in server side observer."},40401:{statusCode:404,statusMessage:"Not Found",message:e=>o(e.route)+`Function not found${e.route.path?` path '${e.route.path}'`:""}.`},40402:{statusCode:400,statusMessage:"Incorrect Protocol",message:e=>o(e.route)+"Target function is not observable."},40403:{statusCode:400,statusMessage:"Incorrect Protocol",message:e=>o(e.route)+"Target function is observable."},40404:{statusCode:400,statusMessage:"Incorrect Protocol",message:e=>o(e.route)+"Target function is stream."},40405:{statusCode:400,statusMessage:"Incorrect Protocol",message:e=>o(e.route)+"Cannot stream to observable function."},40406:{statusCode:400,statusMessage:"Incorrect Protocol",message:e=>o(e.route)+"Target function is of wrong type."},40301:{statusCode:403,statusMessage:"Forbidden",message:e=>o(e.route)+"Authorize rejected access."},40001:{statusCode:400,statusMessage:"Bad Request",message:e=>o(e.route)+"Invalid payload."},40002:{statusCode:413,statusMessage:"Payload Too Large",message:e=>o(e.route)+" PayloadTooLarge."},40003:{statusCode:413,statusMessage:"Payload Too Large",message:e=>o(e)+"ChunkTooLarge "+e.name+"."},40004:{statusCode:400,statusMessage:"Incorrect content encoding",message:e=>o(e)+"Incorrect content encoding."},40005:{statusCode:400,statusMessage:"Protocol mismatch",message:()=>"Please upgrade to the latest based client."},41101:{statusCode:411,statusMessage:"Length Required",message:e=>o(e)+"Length Required."},40501:{statusCode:405,statusMessage:"Method Not Allowed",message:e=>o(e)+"Method Not Allowed."},40029:{statusCode:429,statusMessage:"Rate limit",message:()=>"Rate limit."},40030:{statusCode:500,statusMessage:"Internal Server Error",message:()=>""},40031:{statusCode:429,statusMessage:"Rate limit",message:()=>"Rate limit."},90001:{statusCode:429,statusMessage:"Blocked ip",message:()=>"Blocked ip."},2e3:{message:e=>`[${e.path.join(".")}] Prefix already in use.`},2001:{message:e=>`[${e.path.join(".")}] Cannot change field in strict mode.`},2002:{message:e=>`[${e.path.join(".")}] Cannot remove field in strict mode.`},2003:{message:e=>`[${e.path.join(".")}] Cannot mutate with existing data.`},2004:{message:e=>`[${e.path.join(".")}] Cannot delete root.`},2005:{message:e=>`[${e.path.join(".")}] Cannot change default field.`},2006:{message:e=>`[${e.path.join(".")}] Cannot remove last property.`}},c={name:"no-route",path:"",type:"function"};function E(e){return e.route!==void 0}function I(e,r){let a=p[e],s=r?g(r)?r:"route"in r?r.route:c:c;return{code:e,message:a.message(r),...E(r)?{statusCode:a.statusCode,statusMessage:a.statusMessage,route:{name:s.name,path:s.path,type:s.type}}:null}}0&&(module.exports={BasedError,BasedErrorCode,EMPTY_ROUTE,convertDataToBasedError,createErrorData,errorTypeHandlers});
|
package/dist/src/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function createErrorData<T extends BasedErrorCode>(code: T, paylo
|
|
|
11
11
|
route: {
|
|
12
12
|
name: string;
|
|
13
13
|
path: string;
|
|
14
|
-
type: "function" | "channel" | "query" | "stream" | "app" | "job";
|
|
14
|
+
type: "function" | "channel" | "query" | "stream" | "app" | "job" | "http";
|
|
15
15
|
};
|
|
16
16
|
code: T;
|
|
17
17
|
message: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BasedRoute } from '@based/functions';
|
|
2
|
+
import { BasedErrorCode, ErrorHandler, ErrorPayload } from './types.js';
|
|
3
|
+
type ErrorType = {
|
|
4
|
+
[K in BasedErrorCode]: ErrorHandler<K>;
|
|
5
|
+
};
|
|
6
|
+
export declare const errorTypeHandlers: ErrorType;
|
|
7
|
+
export declare const EMPTY_ROUTE: BasedRoute;
|
|
8
|
+
export declare function createErrorData<T extends BasedErrorCode>(code: T, payload: ErrorPayload[T]): {
|
|
9
|
+
statusCode: number;
|
|
10
|
+
statusMessage: string;
|
|
11
|
+
route: {
|
|
12
|
+
name: string;
|
|
13
|
+
path: string;
|
|
14
|
+
type: "function" | "channel" | "query" | "stream" | "app" | "job" | "http";
|
|
15
|
+
};
|
|
16
|
+
code: T;
|
|
17
|
+
message: string;
|
|
18
|
+
};
|
|
19
|
+
export * from './types.js';
|
|
20
|
+
export * from './BasedError.js';
|
|
21
|
+
export * from './convertDataToBasedError.js';
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/errors",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./client": "./dist/src/client.js",
|
|
9
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"node": {
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"default": "./dist/src/index.js"
|
|
14
|
+
}
|
|
10
15
|
},
|
|
11
16
|
"scripts": {
|
|
12
|
-
"
|
|
17
|
+
"buildCjs": "npx esbuild ./src/index.ts --bundle --platform=node --minify --outfile=./dist/index.cjs",
|
|
18
|
+
"build": "npx tsc && cp ./dist/src/index.d.ts ./dist/src/index_original.d.ts && npm run buildCjs",
|
|
13
19
|
"watch": "npx tsc --watch",
|
|
14
20
|
"test": "npx ava",
|
|
15
|
-
"clean": "
|
|
21
|
+
"clean": "rm -rf ./dist ./node_modules"
|
|
16
22
|
},
|
|
17
23
|
"sideEffects": false,
|
|
18
24
|
"ava": {
|
|
@@ -24,16 +30,16 @@
|
|
|
24
30
|
},
|
|
25
31
|
"files": [
|
|
26
32
|
"dist/src",
|
|
33
|
+
"dist/index.cjs",
|
|
27
34
|
"README.md",
|
|
28
35
|
"package.json"
|
|
29
36
|
],
|
|
30
37
|
"dependencies": {
|
|
31
|
-
"@based/functions": "
|
|
38
|
+
"@based/functions": "3.3.2-alpha.1"
|
|
32
39
|
},
|
|
33
40
|
"devDependencies": {
|
|
34
41
|
"ts-node": "10.9.1",
|
|
35
42
|
"ava": "5.3.1",
|
|
36
|
-
"typescript": "^4.3.5"
|
|
37
|
-
"rimraf": "^3.0.2"
|
|
43
|
+
"typescript": "^4.3.5"
|
|
38
44
|
}
|
|
39
45
|
}
|