@based/errors 1.2.0 → 1.4.0

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 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==="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});
@@ -0,0 +1,5 @@
1
+ import { BasedErrorCode } from './types.js';
2
+ export declare class BasedError extends Error {
3
+ statusMessage?: string;
4
+ code?: BasedErrorCode;
5
+ }
@@ -0,0 +1,5 @@
1
+ export class BasedError extends Error {
2
+ statusMessage;
3
+ code;
4
+ }
5
+ //# sourceMappingURL=BasedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BasedError.js","sourceRoot":"","sources":["../../src/BasedError.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC5B,aAAa,CAAS;IACtB,IAAI,CAAiB;CAC7B"}
@@ -0,0 +1,3 @@
1
+ export * from './BasedError.js';
2
+ export * from './convertDataToBasedError.js';
3
+ export * from './types.js';
@@ -0,0 +1,4 @@
1
+ export * from './BasedError.js';
2
+ export * from './convertDataToBasedError.js';
3
+ export * from './types.js';
4
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { BasedErrorData } from './types.js';
2
+ import { BasedError } from './BasedError.js';
3
+ export declare const convertDataToBasedError: (payload: BasedErrorData, stack?: string) => BasedError;
@@ -0,0 +1,24 @@
1
+ import { BasedErrorCode } from './types.js';
2
+ import { BasedError } from './BasedError.js';
3
+ export const convertDataToBasedError = (payload, stack) => {
4
+ if (!payload || typeof payload !== 'object') {
5
+ const err = new BasedError(`Payload: ${payload}`);
6
+ // err.code = BasedErrorCode.FunctionError
7
+ err.name = 'Invalid returned payload';
8
+ return err;
9
+ }
10
+ const { message, code } = payload;
11
+ const msg = message
12
+ ? message[0] === '['
13
+ ? message
14
+ : `[${BasedErrorCode[code]}] ` + message
15
+ : !code
16
+ ? JSON.stringify(payload, null, 2)
17
+ : 'Cannot read error msg';
18
+ const error = new BasedError(msg);
19
+ error.stack = stack ? msg + ' ' + stack : msg;
20
+ error.name = BasedErrorCode[code];
21
+ error.code = code;
22
+ return error;
23
+ };
24
+ //# sourceMappingURL=convertDataToBasedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertDataToBasedError.js","sourceRoot":"","sources":["../../src/convertDataToBasedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,OAAuB,EACvB,KAAc,EACF,EAAE;IACd,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,YAAY,OAAO,EAAE,CAAC,CAAA;QACjD,0CAA0C;QAC1C,GAAG,CAAC,IAAI,GAAG,0BAA0B,CAAA;QACrC,OAAO,GAAG,CAAA;IACZ,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IACjC,MAAM,GAAG,GAAG,OAAO;QACjB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;YAClB,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG,OAAO;QAC1C,CAAC,CAAC,CAAC,IAAI;YACL,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAClC,CAAC,CAAC,uBAAuB,CAAA;IAC7B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACjC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAA;IAC7C,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACjC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACjB,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
@@ -1,166 +1,5 @@
1
- import { BasedRoute } from "@based/functions";
2
- export declare enum BasedErrorCode {
3
- incorrectFieldType = 1000,
4
- incorrectNodeType = 1001,
5
- exceedsMaximum = 1002,
6
- subceedsMinimum = 1003,
7
- fieldDoesNotExist = 1004,
8
- incorrectFormat = 1005,
9
- referenceIsIncorrectType = 1006,
10
- valueAndDefault = 1007,
11
- defaultNotSupported = 1008,
12
- multipleOperationsNotAllowed = 1009,
13
- requiredFieldNotDefined = 1010,
14
- languageNotSupported = 1011,
15
- invalidJSON = 1012,
16
- noLanguageFound = 1013,
17
- cannotDeleteNodeFromModify = 1014,
18
- nestedModifyObjectNotAllowed = 1015,
19
- infinityNotSupported = 1016,
20
- invalidSchemaFormat = 1017,
21
- invalidProperty = 1018,
22
- FunctionError = 50001,
23
- AuthorizeFunctionError = 50002,
24
- NoOservableCacheAvailable = 50003,
25
- ObservableFunctionError = 50004,
26
- ObserveCallbackError = 50005,
27
- FunctionNotFound = 40401,
28
- FunctionIsNotObservable = 40402,
29
- FunctionIsObservable = 40403,
30
- FunctionIsStream = 40404,
31
- CannotStreamToObservableFunction = 40405,
32
- FunctionIsWrongType = 40406,
33
- AuthorizeRejectedError = 40301,
34
- InvalidPayload = 40001,
35
- PayloadTooLarge = 40002,
36
- ChunkTooLarge = 40003,
37
- UnsupportedContentEncoding = 40004,
38
- NoBinaryProtocol = 40005,
39
- LengthRequired = 41101,
40
- MethodNotAllowed = 40501,
41
- RateLimit = 40029,
42
- MissingAuthStateProtocolHeader = 40030,
43
- IncorrectAccessKey = 40031,
44
- Block = 90001,
45
- PrefixAlreadyInUse = 2000,
46
- CannotChangeFieldInStrictMode = 2001,
47
- CannotRemoveFieldInStrictMode = 2002,
48
- CannotMutateWithExistingData = 2003,
49
- CannotDeleteRoot = 2004,
50
- CannotChangeDefaultField = 2005,
51
- CannotRemoveLastProperty = 2006
52
- }
53
- type BasedParseErrorPayload = {
54
- path: string[];
55
- };
56
- type FunctionErrorProps = {
57
- err: Error | string;
58
- requestId?: number;
59
- streamRequestId?: number;
60
- route: BasedRoute;
61
- };
62
- type ObservableFunctionErrorProps = {
63
- observableId: number;
64
- err: Error | string;
65
- route: BasedRoute;
66
- };
67
- type ChannelFunctionErrorProps = {
68
- channelId: number;
69
- err: Error | string;
70
- route: BasedRoute;
71
- };
72
- export type BasedErrorPayload = {
73
- observableId: number;
74
- route: BasedRoute;
75
- } | {
76
- requestId: number;
77
- route: BasedRoute;
78
- } | {
79
- channelId: number;
80
- route: BasedRoute;
81
- } | {
82
- streamRequestId: number;
83
- route: BasedRoute;
84
- } | {
85
- route: BasedRoute;
86
- };
87
- type BasedFunctionError = FunctionErrorProps | ObservableFunctionErrorProps | ChannelFunctionErrorProps;
88
- export type ErrorPayload = {
89
- [BasedErrorCode.incorrectFieldType]: BasedParseErrorPayload;
90
- [BasedErrorCode.incorrectNodeType]: BasedParseErrorPayload;
91
- [BasedErrorCode.exceedsMaximum]: BasedParseErrorPayload;
92
- [BasedErrorCode.subceedsMinimum]: BasedParseErrorPayload;
93
- [BasedErrorCode.fieldDoesNotExist]: BasedParseErrorPayload;
94
- [BasedErrorCode.incorrectFormat]: BasedParseErrorPayload;
95
- [BasedErrorCode.referenceIsIncorrectType]: BasedParseErrorPayload;
96
- [BasedErrorCode.valueAndDefault]: BasedParseErrorPayload;
97
- [BasedErrorCode.defaultNotSupported]: BasedParseErrorPayload;
98
- [BasedErrorCode.multipleOperationsNotAllowed]: BasedParseErrorPayload;
99
- [BasedErrorCode.requiredFieldNotDefined]: BasedParseErrorPayload;
100
- [BasedErrorCode.languageNotSupported]: BasedParseErrorPayload;
101
- [BasedErrorCode.invalidJSON]: BasedParseErrorPayload;
102
- [BasedErrorCode.noLanguageFound]: BasedParseErrorPayload;
103
- [BasedErrorCode.cannotDeleteNodeFromModify]: BasedParseErrorPayload;
104
- [BasedErrorCode.nestedModifyObjectNotAllowed]: BasedParseErrorPayload;
105
- [BasedErrorCode.infinityNotSupported]: BasedParseErrorPayload;
106
- [BasedErrorCode.invalidSchemaFormat]: BasedParseErrorPayload;
107
- [BasedErrorCode.invalidProperty]: BasedParseErrorPayload;
108
- [BasedErrorCode.FunctionError]: BasedFunctionError;
109
- [BasedErrorCode.AuthorizeFunctionError]: BasedFunctionError;
110
- [BasedErrorCode.NoOservableCacheAvailable]: {
111
- observableId: number;
112
- route: BasedRoute;
113
- };
114
- [BasedErrorCode.ObservableFunctionError]: BasedFunctionError;
115
- [BasedErrorCode.ObserveCallbackError]: {
116
- err: Error;
117
- observableId: number;
118
- route: BasedRoute;
119
- };
120
- [BasedErrorCode.FunctionNotFound]: BasedErrorPayload;
121
- [BasedErrorCode.FunctionIsNotObservable]: BasedErrorPayload;
122
- [BasedErrorCode.FunctionIsObservable]: BasedErrorPayload;
123
- [BasedErrorCode.FunctionIsStream]: BasedErrorPayload;
124
- [BasedErrorCode.CannotStreamToObservableFunction]: BasedErrorPayload;
125
- [BasedErrorCode.FunctionIsWrongType]: BasedErrorPayload;
126
- [BasedErrorCode.AuthorizeRejectedError]: BasedErrorPayload;
127
- [BasedErrorCode.InvalidPayload]: BasedErrorPayload;
128
- [BasedErrorCode.PayloadTooLarge]: BasedErrorPayload;
129
- [BasedErrorCode.ChunkTooLarge]: BasedRoute;
130
- [BasedErrorCode.UnsupportedContentEncoding]: BasedRoute;
131
- [BasedErrorCode.NoBinaryProtocol]: {
132
- buffer: ArrayBuffer;
133
- };
134
- [BasedErrorCode.LengthRequired]: BasedRoute;
135
- [BasedErrorCode.MethodNotAllowed]: BasedRoute;
136
- [BasedErrorCode.RateLimit]: {};
137
- [BasedErrorCode.MissingAuthStateProtocolHeader]: {};
138
- [BasedErrorCode.IncorrectAccessKey]: {};
139
- [BasedErrorCode.Block]: {};
140
- [BasedErrorCode.PrefixAlreadyInUse]: BasedParseErrorPayload;
141
- [BasedErrorCode.CannotChangeFieldInStrictMode]: BasedParseErrorPayload;
142
- [BasedErrorCode.CannotRemoveFieldInStrictMode]: BasedParseErrorPayload;
143
- [BasedErrorCode.CannotMutateWithExistingData]: BasedParseErrorPayload;
144
- [BasedErrorCode.CannotDeleteRoot]: BasedParseErrorPayload;
145
- [BasedErrorCode.CannotChangeDefaultField]: BasedParseErrorPayload;
146
- [BasedErrorCode.CannotRemoveLastProperty]: BasedParseErrorPayload;
147
- };
148
- export type ErrorHandler<T extends BasedErrorCode> = {
149
- statusCode?: number;
150
- statusMessage?: string;
151
- message: (payload: ErrorPayload[T]) => string;
152
- };
153
- export type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> = {
154
- route?: BasedRoute;
155
- message: string;
156
- code: T;
157
- statusCode?: number;
158
- statusMessage?: string;
159
- requestId?: number;
160
- observableId?: number;
161
- channelId?: number;
162
- streamRequestId?: number;
163
- };
1
+ import { BasedRoute } from '@based/functions';
2
+ import { BasedErrorCode, ErrorHandler, ErrorPayload } from './types.js';
164
3
  type ErrorType = {
165
4
  [K in BasedErrorCode]: ErrorHandler<K>;
166
5
  };
@@ -177,9 +16,6 @@ export declare function createErrorData<T extends BasedErrorCode>(code: T, paylo
177
16
  code: T;
178
17
  message: string;
179
18
  };
180
- export declare class BasedError extends Error {
181
- statusMessage?: string;
182
- code?: BasedErrorCode;
183
- }
184
- export declare const convertDataToBasedError: (payload: BasedErrorData, stack?: string) => BasedError;
185
- export {};
19
+ export * from './types.js';
20
+ export * from './BasedError.js';
21
+ export * from './convertDataToBasedError.js';
package/dist/src/index.js CHANGED
@@ -1,302 +1,248 @@
1
- import { isAnyBasedRoute } from "@based/functions";
2
- export var BasedErrorCode;
3
- (function (BasedErrorCode) {
4
- // Parse Errors
5
- BasedErrorCode[BasedErrorCode["incorrectFieldType"] = 1000] = "incorrectFieldType";
6
- BasedErrorCode[BasedErrorCode["incorrectNodeType"] = 1001] = "incorrectNodeType";
7
- BasedErrorCode[BasedErrorCode["exceedsMaximum"] = 1002] = "exceedsMaximum";
8
- BasedErrorCode[BasedErrorCode["subceedsMinimum"] = 1003] = "subceedsMinimum";
9
- BasedErrorCode[BasedErrorCode["fieldDoesNotExist"] = 1004] = "fieldDoesNotExist";
10
- BasedErrorCode[BasedErrorCode["incorrectFormat"] = 1005] = "incorrectFormat";
11
- BasedErrorCode[BasedErrorCode["referenceIsIncorrectType"] = 1006] = "referenceIsIncorrectType";
12
- BasedErrorCode[BasedErrorCode["valueAndDefault"] = 1007] = "valueAndDefault";
13
- BasedErrorCode[BasedErrorCode["defaultNotSupported"] = 1008] = "defaultNotSupported";
14
- BasedErrorCode[BasedErrorCode["multipleOperationsNotAllowed"] = 1009] = "multipleOperationsNotAllowed";
15
- BasedErrorCode[BasedErrorCode["requiredFieldNotDefined"] = 1010] = "requiredFieldNotDefined";
16
- BasedErrorCode[BasedErrorCode["languageNotSupported"] = 1011] = "languageNotSupported";
17
- BasedErrorCode[BasedErrorCode["invalidJSON"] = 1012] = "invalidJSON";
18
- BasedErrorCode[BasedErrorCode["noLanguageFound"] = 1013] = "noLanguageFound";
19
- BasedErrorCode[BasedErrorCode["cannotDeleteNodeFromModify"] = 1014] = "cannotDeleteNodeFromModify";
20
- BasedErrorCode[BasedErrorCode["nestedModifyObjectNotAllowed"] = 1015] = "nestedModifyObjectNotAllowed";
21
- BasedErrorCode[BasedErrorCode["infinityNotSupported"] = 1016] = "infinityNotSupported";
22
- BasedErrorCode[BasedErrorCode["invalidSchemaFormat"] = 1017] = "invalidSchemaFormat";
23
- BasedErrorCode[BasedErrorCode["invalidProperty"] = 1018] = "invalidProperty";
24
- // client/server errors
25
- BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
26
- BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
27
- BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
28
- BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
29
- BasedErrorCode[BasedErrorCode["ObserveCallbackError"] = 50005] = "ObserveCallbackError";
30
- BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
31
- BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
32
- BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
33
- BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
34
- BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40405] = "CannotStreamToObservableFunction";
35
- BasedErrorCode[BasedErrorCode["FunctionIsWrongType"] = 40406] = "FunctionIsWrongType";
36
- BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
37
- BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
38
- BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
39
- BasedErrorCode[BasedErrorCode["ChunkTooLarge"] = 40003] = "ChunkTooLarge";
40
- BasedErrorCode[BasedErrorCode["UnsupportedContentEncoding"] = 40004] = "UnsupportedContentEncoding";
41
- BasedErrorCode[BasedErrorCode["NoBinaryProtocol"] = 40005] = "NoBinaryProtocol";
42
- BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
43
- BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
44
- BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
45
- BasedErrorCode[BasedErrorCode["MissingAuthStateProtocolHeader"] = 40030] = "MissingAuthStateProtocolHeader";
46
- BasedErrorCode[BasedErrorCode["IncorrectAccessKey"] = 40031] = "IncorrectAccessKey";
47
- BasedErrorCode[BasedErrorCode["Block"] = 90001] = "Block";
48
- // Mutation error
49
- BasedErrorCode[BasedErrorCode["PrefixAlreadyInUse"] = 2000] = "PrefixAlreadyInUse";
50
- BasedErrorCode[BasedErrorCode["CannotChangeFieldInStrictMode"] = 2001] = "CannotChangeFieldInStrictMode";
51
- BasedErrorCode[BasedErrorCode["CannotRemoveFieldInStrictMode"] = 2002] = "CannotRemoveFieldInStrictMode";
52
- BasedErrorCode[BasedErrorCode["CannotMutateWithExistingData"] = 2003] = "CannotMutateWithExistingData";
53
- BasedErrorCode[BasedErrorCode["CannotDeleteRoot"] = 2004] = "CannotDeleteRoot";
54
- BasedErrorCode[BasedErrorCode["CannotChangeDefaultField"] = 2005] = "CannotChangeDefaultField";
55
- BasedErrorCode[BasedErrorCode["CannotRemoveLastProperty"] = 2006] = "CannotRemoveLastProperty";
56
- })(BasedErrorCode = BasedErrorCode || (BasedErrorCode = {}));
1
+ import { isAnyBasedRoute } from '@based/functions';
2
+ import { BasedErrorCode, } from './types.js';
57
3
  const addName = (payload) => {
58
- return payload.name ? `[${payload.name}] ` : "";
4
+ return payload.name ? `[${payload.name}] ` : '';
59
5
  };
60
6
  export const errorTypeHandlers = {
61
7
  // Parse errors
62
8
  [BasedErrorCode.incorrectFieldType]: {
63
- message: (payload) => `[${payload.path.join(".")}] Incorrect field type.`,
9
+ message: (payload) => `[${payload.path.join('.')}] Incorrect field type.`,
64
10
  },
65
11
  [BasedErrorCode.incorrectNodeType]: {
66
- message: (payload) => `[${payload.path.join(".")}] Incorrect node type.`,
12
+ message: (payload) => `[${payload.path.join('.')}] Incorrect node type.`,
67
13
  },
68
14
  [BasedErrorCode.exceedsMaximum]: {
69
- message: (payload) => `[${payload.path.join(".")}] Exceeds maximum property.`,
15
+ message: (payload) => `[${payload.path.join('.')}] Exceeds maximum property.`,
70
16
  },
71
17
  [BasedErrorCode.subceedsMinimum]: {
72
- message: (payload) => `[${payload.path.join(".")}] Subceeds minimum property.`,
18
+ message: (payload) => `[${payload.path.join('.')}] Subceeds minimum property.`,
73
19
  },
74
20
  [BasedErrorCode.fieldDoesNotExist]: {
75
- message: (payload) => `[${payload.path.join(".")}] Field does not exist.`,
21
+ message: (payload) => `[${payload.path.join('.')}] Field does not exist.`,
76
22
  },
77
23
  [BasedErrorCode.incorrectFormat]: {
78
- message: (payload) => `[${payload.path.join(".")}] Incorrect format.`,
24
+ message: (payload) => `[${payload.path.join('.')}] Incorrect format.`,
79
25
  },
80
26
  [BasedErrorCode.referenceIsIncorrectType]: {
81
- message: (payload) => `[${payload.path.join(".")}] Reference is from incorrect type.`,
27
+ message: (payload) => `[${payload.path.join('.')}] Reference is from incorrect type.`,
82
28
  },
83
29
  [BasedErrorCode.valueAndDefault]: {
84
- message: (payload) => `[${payload.path.join(".")}] Value and $default are being used at the same time.`,
30
+ message: (payload) => `[${payload.path.join('.')}] Value and $default are being used at the same time.`,
85
31
  },
86
32
  [BasedErrorCode.defaultNotSupported]: {
87
- message: (payload) => `[${payload.path.join(".")}] $default is not suported.`,
33
+ message: (payload) => `[${payload.path.join('.')}] $default is not suported.`,
88
34
  },
89
35
  [BasedErrorCode.multipleOperationsNotAllowed]: {
90
- message: (payload) => `[${payload.path.join(".")}] Multiple operations are not allowed here.`,
36
+ message: (payload) => `[${payload.path.join('.')}] Multiple operations are not allowed here.`,
91
37
  },
92
38
  [BasedErrorCode.requiredFieldNotDefined]: {
93
- message: (payload) => `[${payload.path.join(".")}] Required field is not defined.`,
39
+ message: (payload) => `[${payload.path.join('.')}] Required field is not defined.`,
94
40
  },
95
41
  [BasedErrorCode.languageNotSupported]: {
96
- message: (payload) => `[${payload.path.join(".")}] Language not supported.`,
42
+ message: (payload) => `[${payload.path.join('.')}] Language not supported.`,
97
43
  },
98
44
  [BasedErrorCode.invalidJSON]: {
99
- message: (payload) => `[${payload.path.join(".")}] Invalid JSON.`,
45
+ message: (payload) => `[${payload.path.join('.')}] Invalid JSON.`,
100
46
  },
101
47
  [BasedErrorCode.noLanguageFound]: {
102
- message: (payload) => `[${payload.path.join(".")}] No language found.`,
48
+ message: (payload) => `[${payload.path.join('.')}] No language found.`,
103
49
  },
104
50
  [BasedErrorCode.cannotDeleteNodeFromModify]: {
105
- message: (payload) => `[${payload.path.join(".")}] Cannot delete node from modify.`,
51
+ message: (payload) => `[${payload.path.join('.')}] Cannot delete node from modify.`,
106
52
  },
107
53
  [BasedErrorCode.nestedModifyObjectNotAllowed]: {
108
- message: (payload) => `[${payload.path.join(".")}] Nested modify object not allowed.`,
54
+ message: (payload) => `[${payload.path.join('.')}] Nested modify object not allowed.`,
109
55
  },
110
56
  [BasedErrorCode.infinityNotSupported]: {
111
- message: (payload) => `[${payload.path.join(".")}] Infinity not supported.`,
57
+ message: (payload) => `[${payload.path.join('.')}] Infinity not supported.`,
112
58
  },
113
59
  [BasedErrorCode.invalidSchemaFormat]: {
114
- message: (payload) => `[${payload.path.join(".")}] Invalid schema format.`,
60
+ message: (payload) => `[${payload.path.join('.')}] Invalid schema format.`,
115
61
  },
116
62
  [BasedErrorCode.invalidProperty]: {
117
- message: (payload) => `[${payload.path.join(".")}] Invalid property.`,
63
+ message: (payload) => `[${payload.path.join('.')}] Invalid property.`,
118
64
  },
119
65
  [BasedErrorCode.FunctionError]: {
120
66
  statusCode: 500,
121
- statusMessage: "Internal Server Error",
67
+ statusMessage: 'Internal Server Error',
122
68
  message: (payload) => {
123
- if (typeof payload.err === "string" || !payload.err.message) {
69
+ if (typeof payload.err === 'string' || !payload.err.message) {
124
70
  return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
125
71
  }
126
72
  return (addName(payload.route) +
127
- `${payload.err.name && payload.err.name !== "Error"
73
+ `${payload.err.name && payload.err.name !== 'Error'
128
74
  ? `[${payload.err.name}] `
129
- : ""}${payload.err.message || ""}.`);
75
+ : ''}${payload.err.message || ''}.`);
130
76
  },
131
77
  },
132
78
  [BasedErrorCode.AuthorizeFunctionError]: {
133
79
  statusCode: 403,
134
- statusMessage: "Forbidden",
80
+ statusMessage: 'Forbidden',
135
81
  message: (payload) => {
136
- if (typeof payload.err === "string" || !payload.err.message) {
82
+ if (typeof payload.err === 'string' || !payload.err.message) {
137
83
  return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
138
84
  }
139
85
  return (addName(payload.route) +
140
- `${payload.err.name && payload.err.name !== "Error"
86
+ `${payload.err.name && payload.err.name !== 'Error'
141
87
  ? `[${payload.err.name}] `
142
- : ""}${payload.err.message || ""}.`);
88
+ : ''}${payload.err.message || ''}.`);
143
89
  },
144
90
  },
145
91
  [BasedErrorCode.NoOservableCacheAvailable]: {
146
92
  statusCode: 500,
147
- statusMessage: "Internal Server Error",
93
+ statusMessage: 'Internal Server Error',
148
94
  message: (payload) => addName(payload.route) +
149
95
  `No observable cache available${payload.route.name} - ${payload.observableId}.`,
150
96
  },
151
97
  [BasedErrorCode.ObservableFunctionError]: {
152
98
  statusCode: 500,
153
- statusMessage: "Internal Server Error",
99
+ statusMessage: 'Internal Server Error',
154
100
  message: (payload) => {
155
- if (typeof payload.err === "string" || !payload.err.message) {
101
+ if (typeof payload.err === 'string' || !payload.err.message) {
156
102
  return `[${payload.route.name} (observable)] ${JSON.stringify(payload.err)}.`;
157
103
  }
158
104
  return (addName(payload.route) +
159
- `${payload.err.name && payload.err.name !== "Error"
105
+ `${payload.err.name && payload.err.name !== 'Error'
160
106
  ? `[${payload.err.name}] `
161
- : ""}${payload.err.message || ""}.`);
107
+ : ''}${payload.err.message || ''}.`);
162
108
  },
163
109
  },
164
110
  [BasedErrorCode.ObserveCallbackError]: {
165
111
  statusCode: 500,
166
- statusMessage: "Internal Server Error",
112
+ statusMessage: 'Internal Server Error',
167
113
  message: () => {
168
- return "Error in server side observer.";
114
+ return 'Error in server side observer.';
169
115
  },
170
116
  },
171
117
  [BasedErrorCode.FunctionNotFound]: {
172
118
  statusCode: 404,
173
- statusMessage: "Not Found",
119
+ statusMessage: 'Not Found',
174
120
  message: (payload) => {
175
121
  return (addName(payload.route) +
176
- `Function not found${payload.route.path ? ` path '${payload.route.path}'` : ""}.`);
122
+ `Function not found${payload.route.path ? ` path '${payload.route.path}'` : ''}.`);
177
123
  },
178
124
  },
179
125
  [BasedErrorCode.FunctionIsNotObservable]: {
180
126
  statusCode: 400,
181
- statusMessage: "Incorrect Protocol",
127
+ statusMessage: 'Incorrect Protocol',
182
128
  message: (payload) => {
183
- return addName(payload.route) + "Target function is not observable.";
129
+ return addName(payload.route) + 'Target function is not observable.';
184
130
  },
185
131
  },
186
132
  [BasedErrorCode.FunctionIsObservable]: {
187
133
  statusCode: 400,
188
- statusMessage: "Incorrect Protocol",
134
+ statusMessage: 'Incorrect Protocol',
189
135
  message: (payload) => {
190
- return addName(payload.route) + "Target function is observable.";
136
+ return addName(payload.route) + 'Target function is observable.';
191
137
  },
192
138
  },
193
139
  [BasedErrorCode.FunctionIsStream]: {
194
140
  statusCode: 400,
195
- statusMessage: "Incorrect Protocol",
141
+ statusMessage: 'Incorrect Protocol',
196
142
  message: (payload) => {
197
- return addName(payload.route) + "Target function is stream.";
143
+ return addName(payload.route) + 'Target function is stream.';
198
144
  },
199
145
  },
200
146
  [BasedErrorCode.CannotStreamToObservableFunction]: {
201
147
  statusCode: 400,
202
- statusMessage: "Incorrect Protocol",
148
+ statusMessage: 'Incorrect Protocol',
203
149
  message: (payload) => {
204
- return addName(payload.route) + "Cannot stream to observable function.";
150
+ return addName(payload.route) + 'Cannot stream to observable function.';
205
151
  },
206
152
  },
207
153
  [BasedErrorCode.FunctionIsWrongType]: {
208
154
  statusCode: 400,
209
- statusMessage: "Incorrect Protocol",
155
+ statusMessage: 'Incorrect Protocol',
210
156
  message: (payload) => {
211
- return addName(payload.route) + "Target function is of wrong type.";
157
+ return addName(payload.route) + 'Target function is of wrong type.';
212
158
  },
213
159
  },
214
160
  [BasedErrorCode.AuthorizeRejectedError]: {
215
161
  statusCode: 403,
216
- statusMessage: "Forbidden",
162
+ statusMessage: 'Forbidden',
217
163
  message: (payload) => addName(payload.route) + `Authorize rejected access.`,
218
164
  },
219
165
  [BasedErrorCode.InvalidPayload]: {
220
166
  statusCode: 400,
221
- statusMessage: "Bad Request",
222
- message: (payload) => addName(payload.route) + "Invalid payload.",
167
+ statusMessage: 'Bad Request',
168
+ message: (payload) => addName(payload.route) + 'Invalid payload.',
223
169
  },
224
170
  [BasedErrorCode.PayloadTooLarge]: {
225
171
  statusCode: 413,
226
- statusMessage: "Payload Too Large",
227
- message: (payload) => addName(payload.route) + " PayloadTooLarge.",
172
+ statusMessage: 'Payload Too Large',
173
+ message: (payload) => addName(payload.route) + ' PayloadTooLarge.',
228
174
  },
229
175
  [BasedErrorCode.ChunkTooLarge]: {
230
176
  statusCode: 413,
231
- statusMessage: "Payload Too Large",
232
- message: (payload) => addName(payload) + "ChunkTooLarge " + payload.name + ".",
177
+ statusMessage: 'Payload Too Large',
178
+ message: (payload) => addName(payload) + 'ChunkTooLarge ' + payload.name + '.',
233
179
  },
234
180
  [BasedErrorCode.UnsupportedContentEncoding]: {
235
181
  statusCode: 400,
236
- statusMessage: "Incorrect content encoding",
237
- message: (payload) => addName(payload) + "Incorrect content encoding.",
182
+ statusMessage: 'Incorrect content encoding',
183
+ message: (payload) => addName(payload) + 'Incorrect content encoding.',
238
184
  },
239
185
  [BasedErrorCode.NoBinaryProtocol]: {
240
186
  statusCode: 400,
241
- statusMessage: "Protocol mismatch",
242
- message: () => "Please upgrade to the latest based client.",
187
+ statusMessage: 'Protocol mismatch',
188
+ message: () => 'Please upgrade to the latest based client.',
243
189
  },
244
190
  [BasedErrorCode.LengthRequired]: {
245
191
  statusCode: 411,
246
- statusMessage: "Length Required",
247
- message: (payload) => addName(payload) + "Length Required.",
192
+ statusMessage: 'Length Required',
193
+ message: (payload) => addName(payload) + 'Length Required.',
248
194
  },
249
195
  [BasedErrorCode.MethodNotAllowed]: {
250
196
  statusCode: 405,
251
- statusMessage: "Method Not Allowed",
252
- message: (payload) => addName(payload) + "Method Not Allowed.",
197
+ statusMessage: 'Method Not Allowed',
198
+ message: (payload) => addName(payload) + 'Method Not Allowed.',
253
199
  },
254
200
  [BasedErrorCode.RateLimit]: {
255
201
  statusCode: 429,
256
- statusMessage: "Rate limit",
257
- message: () => "Rate limit.",
202
+ statusMessage: 'Rate limit',
203
+ message: () => 'Rate limit.',
258
204
  },
259
205
  [BasedErrorCode.MissingAuthStateProtocolHeader]: {
260
206
  statusCode: 500,
261
- statusMessage: "Internal Server Error",
262
- message: () => "",
207
+ statusMessage: 'Internal Server Error',
208
+ message: () => '',
263
209
  },
264
210
  [BasedErrorCode.IncorrectAccessKey]: {
265
211
  statusCode: 429,
266
- statusMessage: "Rate limit",
267
- message: () => "Rate limit.",
212
+ statusMessage: 'Rate limit',
213
+ message: () => 'Rate limit.',
268
214
  },
269
215
  [BasedErrorCode.Block]: {
270
216
  statusCode: 429,
271
- statusMessage: "Blocked ip",
272
- message: () => "Blocked ip.",
217
+ statusMessage: 'Blocked ip',
218
+ message: () => 'Blocked ip.',
273
219
  },
274
220
  [BasedErrorCode.PrefixAlreadyInUse]: {
275
- message: (payload) => `[${payload.path.join(".")}] Prefix already in use.`,
221
+ message: (payload) => `[${payload.path.join('.')}] Prefix already in use.`,
276
222
  },
277
223
  [BasedErrorCode.CannotChangeFieldInStrictMode]: {
278
- message: (payload) => `[${payload.path.join(".")}] Cannot change field in strict mode.`,
224
+ message: (payload) => `[${payload.path.join('.')}] Cannot change field in strict mode.`,
279
225
  },
280
226
  [BasedErrorCode.CannotRemoveFieldInStrictMode]: {
281
- message: (payload) => `[${payload.path.join(".")}] Cannot remove field in strict mode.`,
227
+ message: (payload) => `[${payload.path.join('.')}] Cannot remove field in strict mode.`,
282
228
  },
283
229
  [BasedErrorCode.CannotMutateWithExistingData]: {
284
- message: (payload) => `[${payload.path.join(".")}] Cannot mutate with existing data.`,
230
+ message: (payload) => `[${payload.path.join('.')}] Cannot mutate with existing data.`,
285
231
  },
286
232
  [BasedErrorCode.CannotDeleteRoot]: {
287
- message: (payload) => `[${payload.path.join(".")}] Cannot delete root.`,
233
+ message: (payload) => `[${payload.path.join('.')}] Cannot delete root.`,
288
234
  },
289
235
  [BasedErrorCode.CannotChangeDefaultField]: {
290
- message: (payload) => `[${payload.path.join(".")}] Cannot change default field.`,
236
+ message: (payload) => `[${payload.path.join('.')}] Cannot change default field.`,
291
237
  },
292
238
  [BasedErrorCode.CannotRemoveLastProperty]: {
293
- message: (payload) => `[${payload.path.join(".")}] Cannot remove last property.`,
239
+ message: (payload) => `[${payload.path.join('.')}] Cannot remove last property.`,
294
240
  },
295
241
  };
296
242
  export const EMPTY_ROUTE = {
297
- name: "no-route",
298
- path: "",
299
- type: "function",
243
+ name: 'no-route',
244
+ path: '',
245
+ type: 'function',
300
246
  };
301
247
  function isServerError(payload) {
302
248
  return payload.route !== undefined;
@@ -307,7 +253,7 @@ export function createErrorData(code, payload) {
307
253
  ? EMPTY_ROUTE
308
254
  : isAnyBasedRoute(payload)
309
255
  ? payload
310
- : "route" in payload
256
+ : 'route' in payload
311
257
  ? payload.route
312
258
  : EMPTY_ROUTE;
313
259
  return {
@@ -326,31 +272,9 @@ export function createErrorData(code, payload) {
326
272
  : null),
327
273
  };
328
274
  }
329
- export class BasedError extends Error {
330
- statusMessage;
331
- code;
332
- }
333
- export const convertDataToBasedError = (payload, stack) => {
334
- if (!payload || typeof payload !== "object") {
335
- const err = new BasedError(`Payload: ${payload}`);
336
- // err.code = BasedErrorCode.FunctionError
337
- err.name = "Invalid returned payload";
338
- return err;
339
- }
340
- const { message, code } = payload;
341
- const msg = message
342
- ? message[0] === "["
343
- ? message
344
- : `[${BasedErrorCode[code]}] ` + message
345
- : !code
346
- ? JSON.stringify(payload, null, 2)
347
- : "Cannot read error msg";
348
- const error = new BasedError(msg);
349
- error.stack = stack ? msg + " " + stack : msg;
350
- error.name = BasedErrorCode[code];
351
- error.code = code;
352
- return error;
353
- };
275
+ export * from './types.js';
276
+ export * from './BasedError.js';
277
+ export * from './convertDataToBasedError.js';
354
278
  // export const errorDescriptions: {
355
279
  // [BasedErrorCode.PrefixAlreadyInUse]: (payload) =>
356
280
  // `Prefix${payload?.prefix ? ` ${payload.prefix}` : ''} is already in use.`,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,CAAN,IAAY,cAuDX;AAvDD,WAAY,cAAc;IACxB,eAAe;IACf,kFAAyB,CAAA;IACzB,gFAAwB,CAAA;IACxB,0EAAqB,CAAA;IACrB,4EAAsB,CAAA;IACtB,gFAAwB,CAAA;IACxB,4EAAsB,CAAA;IACtB,8FAA+B,CAAA;IAC/B,4EAAsB,CAAA;IACtB,oFAA0B,CAAA;IAC1B,sGAAmC,CAAA;IACnC,4FAA8B,CAAA;IAC9B,sFAA2B,CAAA;IAC3B,oEAAkB,CAAA;IAClB,4EAAsB,CAAA;IACtB,kGAAiC,CAAA;IACjC,sGAAmC,CAAA;IACnC,sFAA2B,CAAA;IAC3B,oFAA0B,CAAA;IAC1B,4EAAsB,CAAA;IAEtB,uBAAuB;IACvB,yEAAqB,CAAA;IACr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cAAc,YAAY,CAAA;AAE1B,cAAc,iBAAiB,CAAA;AAE/B,cAAc,8BAA8B,CAAA;AAE5C,oCAAoC;AACpC,sDAAsD;AACtD,iFAAiF;AACjF,IAAI;AACJ,gFAAgF"}
@@ -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";
15
+ };
16
+ code: T;
17
+ message: string;
18
+ };
19
+ export * from './types.js';
20
+ export * from './BasedError.js';
21
+ export * from './convertDataToBasedError.js';
@@ -0,0 +1,163 @@
1
+ import type { BasedRoute } from '@based/functions';
2
+ export declare enum BasedErrorCode {
3
+ incorrectFieldType = 1000,
4
+ incorrectNodeType = 1001,
5
+ exceedsMaximum = 1002,
6
+ subceedsMinimum = 1003,
7
+ fieldDoesNotExist = 1004,
8
+ incorrectFormat = 1005,
9
+ referenceIsIncorrectType = 1006,
10
+ valueAndDefault = 1007,
11
+ defaultNotSupported = 1008,
12
+ multipleOperationsNotAllowed = 1009,
13
+ requiredFieldNotDefined = 1010,
14
+ languageNotSupported = 1011,
15
+ invalidJSON = 1012,
16
+ noLanguageFound = 1013,
17
+ cannotDeleteNodeFromModify = 1014,
18
+ nestedModifyObjectNotAllowed = 1015,
19
+ infinityNotSupported = 1016,
20
+ invalidSchemaFormat = 1017,
21
+ invalidProperty = 1018,
22
+ FunctionError = 50001,
23
+ AuthorizeFunctionError = 50002,
24
+ NoOservableCacheAvailable = 50003,
25
+ ObservableFunctionError = 50004,
26
+ ObserveCallbackError = 50005,
27
+ FunctionNotFound = 40401,
28
+ FunctionIsNotObservable = 40402,
29
+ FunctionIsObservable = 40403,
30
+ FunctionIsStream = 40404,
31
+ CannotStreamToObservableFunction = 40405,
32
+ FunctionIsWrongType = 40406,// was 40402 in server
33
+ AuthorizeRejectedError = 40301,
34
+ InvalidPayload = 40001,
35
+ PayloadTooLarge = 40002,
36
+ ChunkTooLarge = 40003,
37
+ UnsupportedContentEncoding = 40004,
38
+ NoBinaryProtocol = 40005,
39
+ LengthRequired = 41101,
40
+ MethodNotAllowed = 40501,
41
+ RateLimit = 40029,
42
+ MissingAuthStateProtocolHeader = 40030,
43
+ IncorrectAccessKey = 40031,
44
+ Block = 90001,
45
+ PrefixAlreadyInUse = 2000,
46
+ CannotChangeFieldInStrictMode = 2001,
47
+ CannotRemoveFieldInStrictMode = 2002,
48
+ CannotMutateWithExistingData = 2003,
49
+ CannotDeleteRoot = 2004,
50
+ CannotChangeDefaultField = 2005,
51
+ CannotRemoveLastProperty = 2006
52
+ }
53
+ export type BasedParseErrorPayload = {
54
+ path: string[];
55
+ };
56
+ export type FunctionErrorProps = {
57
+ err: Error | string;
58
+ requestId?: number;
59
+ streamRequestId?: number;
60
+ route: BasedRoute;
61
+ };
62
+ export type ObservableFunctionErrorProps = {
63
+ observableId: number;
64
+ err: Error | string;
65
+ route: BasedRoute;
66
+ };
67
+ export type ChannelFunctionErrorProps = {
68
+ channelId: number;
69
+ err: Error | string;
70
+ route: BasedRoute;
71
+ };
72
+ export type BasedErrorPayload = {
73
+ observableId: number;
74
+ route: BasedRoute;
75
+ } | {
76
+ requestId: number;
77
+ route: BasedRoute;
78
+ } | {
79
+ channelId: number;
80
+ route: BasedRoute;
81
+ } | {
82
+ streamRequestId: number;
83
+ route: BasedRoute;
84
+ } | {
85
+ route: BasedRoute;
86
+ };
87
+ export type BasedFunctionError = FunctionErrorProps | ObservableFunctionErrorProps | ChannelFunctionErrorProps;
88
+ export type ErrorPayload = {
89
+ [BasedErrorCode.incorrectFieldType]: BasedParseErrorPayload;
90
+ [BasedErrorCode.incorrectNodeType]: BasedParseErrorPayload;
91
+ [BasedErrorCode.exceedsMaximum]: BasedParseErrorPayload;
92
+ [BasedErrorCode.subceedsMinimum]: BasedParseErrorPayload;
93
+ [BasedErrorCode.fieldDoesNotExist]: BasedParseErrorPayload;
94
+ [BasedErrorCode.incorrectFormat]: BasedParseErrorPayload;
95
+ [BasedErrorCode.referenceIsIncorrectType]: BasedParseErrorPayload;
96
+ [BasedErrorCode.valueAndDefault]: BasedParseErrorPayload;
97
+ [BasedErrorCode.defaultNotSupported]: BasedParseErrorPayload;
98
+ [BasedErrorCode.multipleOperationsNotAllowed]: BasedParseErrorPayload;
99
+ [BasedErrorCode.requiredFieldNotDefined]: BasedParseErrorPayload;
100
+ [BasedErrorCode.languageNotSupported]: BasedParseErrorPayload;
101
+ [BasedErrorCode.invalidJSON]: BasedParseErrorPayload;
102
+ [BasedErrorCode.noLanguageFound]: BasedParseErrorPayload;
103
+ [BasedErrorCode.cannotDeleteNodeFromModify]: BasedParseErrorPayload;
104
+ [BasedErrorCode.nestedModifyObjectNotAllowed]: BasedParseErrorPayload;
105
+ [BasedErrorCode.infinityNotSupported]: BasedParseErrorPayload;
106
+ [BasedErrorCode.invalidSchemaFormat]: BasedParseErrorPayload;
107
+ [BasedErrorCode.invalidProperty]: BasedParseErrorPayload;
108
+ [BasedErrorCode.FunctionError]: BasedFunctionError;
109
+ [BasedErrorCode.AuthorizeFunctionError]: BasedFunctionError;
110
+ [BasedErrorCode.NoOservableCacheAvailable]: {
111
+ observableId: number;
112
+ route: BasedRoute;
113
+ };
114
+ [BasedErrorCode.ObservableFunctionError]: BasedFunctionError;
115
+ [BasedErrorCode.ObserveCallbackError]: {
116
+ err: Error;
117
+ observableId: number;
118
+ route: BasedRoute;
119
+ };
120
+ [BasedErrorCode.FunctionNotFound]: BasedErrorPayload;
121
+ [BasedErrorCode.FunctionIsNotObservable]: BasedErrorPayload;
122
+ [BasedErrorCode.FunctionIsObservable]: BasedErrorPayload;
123
+ [BasedErrorCode.FunctionIsStream]: BasedErrorPayload;
124
+ [BasedErrorCode.CannotStreamToObservableFunction]: BasedErrorPayload;
125
+ [BasedErrorCode.FunctionIsWrongType]: BasedErrorPayload;
126
+ [BasedErrorCode.AuthorizeRejectedError]: BasedErrorPayload;
127
+ [BasedErrorCode.InvalidPayload]: BasedErrorPayload;
128
+ [BasedErrorCode.PayloadTooLarge]: BasedErrorPayload;
129
+ [BasedErrorCode.ChunkTooLarge]: BasedRoute;
130
+ [BasedErrorCode.UnsupportedContentEncoding]: BasedRoute;
131
+ [BasedErrorCode.NoBinaryProtocol]: {
132
+ buffer: ArrayBuffer;
133
+ };
134
+ [BasedErrorCode.LengthRequired]: BasedRoute;
135
+ [BasedErrorCode.MethodNotAllowed]: BasedRoute;
136
+ [BasedErrorCode.RateLimit]: {};
137
+ [BasedErrorCode.MissingAuthStateProtocolHeader]: {};
138
+ [BasedErrorCode.IncorrectAccessKey]: {};
139
+ [BasedErrorCode.Block]: {};
140
+ [BasedErrorCode.PrefixAlreadyInUse]: BasedParseErrorPayload;
141
+ [BasedErrorCode.CannotChangeFieldInStrictMode]: BasedParseErrorPayload;
142
+ [BasedErrorCode.CannotRemoveFieldInStrictMode]: BasedParseErrorPayload;
143
+ [BasedErrorCode.CannotMutateWithExistingData]: BasedParseErrorPayload;
144
+ [BasedErrorCode.CannotDeleteRoot]: BasedParseErrorPayload;
145
+ [BasedErrorCode.CannotChangeDefaultField]: BasedParseErrorPayload;
146
+ [BasedErrorCode.CannotRemoveLastProperty]: BasedParseErrorPayload;
147
+ };
148
+ export type ErrorHandler<T extends BasedErrorCode> = {
149
+ statusCode?: number;
150
+ statusMessage?: string;
151
+ message: (payload: ErrorPayload[T]) => string;
152
+ };
153
+ export type BasedErrorData<T extends BasedErrorCode = BasedErrorCode> = {
154
+ route?: BasedRoute;
155
+ message: string;
156
+ code: T;
157
+ statusCode?: number;
158
+ statusMessage?: string;
159
+ requestId?: number;
160
+ observableId?: number;
161
+ channelId?: number;
162
+ streamRequestId?: number;
163
+ };
@@ -0,0 +1,56 @@
1
+ export var BasedErrorCode;
2
+ (function (BasedErrorCode) {
3
+ // Parse Errors
4
+ BasedErrorCode[BasedErrorCode["incorrectFieldType"] = 1000] = "incorrectFieldType";
5
+ BasedErrorCode[BasedErrorCode["incorrectNodeType"] = 1001] = "incorrectNodeType";
6
+ BasedErrorCode[BasedErrorCode["exceedsMaximum"] = 1002] = "exceedsMaximum";
7
+ BasedErrorCode[BasedErrorCode["subceedsMinimum"] = 1003] = "subceedsMinimum";
8
+ BasedErrorCode[BasedErrorCode["fieldDoesNotExist"] = 1004] = "fieldDoesNotExist";
9
+ BasedErrorCode[BasedErrorCode["incorrectFormat"] = 1005] = "incorrectFormat";
10
+ BasedErrorCode[BasedErrorCode["referenceIsIncorrectType"] = 1006] = "referenceIsIncorrectType";
11
+ BasedErrorCode[BasedErrorCode["valueAndDefault"] = 1007] = "valueAndDefault";
12
+ BasedErrorCode[BasedErrorCode["defaultNotSupported"] = 1008] = "defaultNotSupported";
13
+ BasedErrorCode[BasedErrorCode["multipleOperationsNotAllowed"] = 1009] = "multipleOperationsNotAllowed";
14
+ BasedErrorCode[BasedErrorCode["requiredFieldNotDefined"] = 1010] = "requiredFieldNotDefined";
15
+ BasedErrorCode[BasedErrorCode["languageNotSupported"] = 1011] = "languageNotSupported";
16
+ BasedErrorCode[BasedErrorCode["invalidJSON"] = 1012] = "invalidJSON";
17
+ BasedErrorCode[BasedErrorCode["noLanguageFound"] = 1013] = "noLanguageFound";
18
+ BasedErrorCode[BasedErrorCode["cannotDeleteNodeFromModify"] = 1014] = "cannotDeleteNodeFromModify";
19
+ BasedErrorCode[BasedErrorCode["nestedModifyObjectNotAllowed"] = 1015] = "nestedModifyObjectNotAllowed";
20
+ BasedErrorCode[BasedErrorCode["infinityNotSupported"] = 1016] = "infinityNotSupported";
21
+ BasedErrorCode[BasedErrorCode["invalidSchemaFormat"] = 1017] = "invalidSchemaFormat";
22
+ BasedErrorCode[BasedErrorCode["invalidProperty"] = 1018] = "invalidProperty";
23
+ // client/server errors
24
+ BasedErrorCode[BasedErrorCode["FunctionError"] = 50001] = "FunctionError";
25
+ BasedErrorCode[BasedErrorCode["AuthorizeFunctionError"] = 50002] = "AuthorizeFunctionError";
26
+ BasedErrorCode[BasedErrorCode["NoOservableCacheAvailable"] = 50003] = "NoOservableCacheAvailable";
27
+ BasedErrorCode[BasedErrorCode["ObservableFunctionError"] = 50004] = "ObservableFunctionError";
28
+ BasedErrorCode[BasedErrorCode["ObserveCallbackError"] = 50005] = "ObserveCallbackError";
29
+ BasedErrorCode[BasedErrorCode["FunctionNotFound"] = 40401] = "FunctionNotFound";
30
+ BasedErrorCode[BasedErrorCode["FunctionIsNotObservable"] = 40402] = "FunctionIsNotObservable";
31
+ BasedErrorCode[BasedErrorCode["FunctionIsObservable"] = 40403] = "FunctionIsObservable";
32
+ BasedErrorCode[BasedErrorCode["FunctionIsStream"] = 40404] = "FunctionIsStream";
33
+ BasedErrorCode[BasedErrorCode["CannotStreamToObservableFunction"] = 40405] = "CannotStreamToObservableFunction";
34
+ BasedErrorCode[BasedErrorCode["FunctionIsWrongType"] = 40406] = "FunctionIsWrongType";
35
+ BasedErrorCode[BasedErrorCode["AuthorizeRejectedError"] = 40301] = "AuthorizeRejectedError";
36
+ BasedErrorCode[BasedErrorCode["InvalidPayload"] = 40001] = "InvalidPayload";
37
+ BasedErrorCode[BasedErrorCode["PayloadTooLarge"] = 40002] = "PayloadTooLarge";
38
+ BasedErrorCode[BasedErrorCode["ChunkTooLarge"] = 40003] = "ChunkTooLarge";
39
+ BasedErrorCode[BasedErrorCode["UnsupportedContentEncoding"] = 40004] = "UnsupportedContentEncoding";
40
+ BasedErrorCode[BasedErrorCode["NoBinaryProtocol"] = 40005] = "NoBinaryProtocol";
41
+ BasedErrorCode[BasedErrorCode["LengthRequired"] = 41101] = "LengthRequired";
42
+ BasedErrorCode[BasedErrorCode["MethodNotAllowed"] = 40501] = "MethodNotAllowed";
43
+ BasedErrorCode[BasedErrorCode["RateLimit"] = 40029] = "RateLimit";
44
+ BasedErrorCode[BasedErrorCode["MissingAuthStateProtocolHeader"] = 40030] = "MissingAuthStateProtocolHeader";
45
+ BasedErrorCode[BasedErrorCode["IncorrectAccessKey"] = 40031] = "IncorrectAccessKey";
46
+ BasedErrorCode[BasedErrorCode["Block"] = 90001] = "Block";
47
+ // Mutation error
48
+ BasedErrorCode[BasedErrorCode["PrefixAlreadyInUse"] = 2000] = "PrefixAlreadyInUse";
49
+ BasedErrorCode[BasedErrorCode["CannotChangeFieldInStrictMode"] = 2001] = "CannotChangeFieldInStrictMode";
50
+ BasedErrorCode[BasedErrorCode["CannotRemoveFieldInStrictMode"] = 2002] = "CannotRemoveFieldInStrictMode";
51
+ BasedErrorCode[BasedErrorCode["CannotMutateWithExistingData"] = 2003] = "CannotMutateWithExistingData";
52
+ BasedErrorCode[BasedErrorCode["CannotDeleteRoot"] = 2004] = "CannotDeleteRoot";
53
+ BasedErrorCode[BasedErrorCode["CannotChangeDefaultField"] = 2005] = "CannotChangeDefaultField";
54
+ BasedErrorCode[BasedErrorCode["CannotRemoveLastProperty"] = 2006] = "CannotRemoveLastProperty";
55
+ })(BasedErrorCode || (BasedErrorCode = {}));
56
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,cAuDX;AAvDD,WAAY,cAAc;IACxB,eAAe;IACf,kFAAyB,CAAA;IACzB,gFAAwB,CAAA;IACxB,0EAAqB,CAAA;IACrB,4EAAsB,CAAA;IACtB,gFAAwB,CAAA;IACxB,4EAAsB,CAAA;IACtB,8FAA+B,CAAA;IAC/B,4EAAsB,CAAA;IACtB,oFAA0B,CAAA;IAC1B,sGAAmC,CAAA;IACnC,4FAA8B,CAAA;IAC9B,sFAA2B,CAAA;IAC3B,oEAAkB,CAAA;IAClB,4EAAsB,CAAA;IACtB,kGAAiC,CAAA;IACjC,sGAAmC,CAAA;IACnC,sFAA2B,CAAA;IAC3B,oFAA0B,CAAA;IAC1B,4EAAsB,CAAA;IAEtB,uBAAuB;IACvB,yEAAqB,CAAA;IACrB,2FAA8B,CAAA;IAC9B,iGAAiC,CAAA;IACjC,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,6FAA+B,CAAA;IAC/B,uFAA4B,CAAA;IAC5B,+EAAwB,CAAA;IACxB,+GAAwC,CAAA;IACxC,qFAA2B,CAAA;IAC3B,2FAA8B,CAAA;IAC9B,2EAAsB,CAAA;IACtB,6EAAuB,CAAA;IACvB,yEAAqB,CAAA;IACrB,mGAAkC,CAAA;IAClC,+EAAwB,CAAA;IACxB,2EAAsB,CAAA;IACtB,+EAAwB,CAAA;IACxB,iEAAiB,CAAA;IACjB,2GAAsC,CAAA;IACtC,mFAA0B,CAAA;IAC1B,yDAAa,CAAA;IAEb,iBAAiB;IACjB,kFAAyB,CAAA;IACzB,wGAAoC,CAAA;IACpC,wGAAoC,CAAA;IACpC,sGAAmC,CAAA;IACnC,8EAAuB,CAAA;IACvB,8FAA+B,CAAA;IAC/B,8FAA+B,CAAA;AACjC,CAAC,EAvDW,cAAc,KAAd,cAAc,QAuDzB"}
package/package.json CHANGED
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "name": "@based/errors",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
7
+ "exports": {
8
+ "./client": "./dist/src/client.js",
9
+ ".": {
10
+ "node": {
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "default": "./dist/src/index.js"
14
+ }
15
+ },
7
16
  "scripts": {
8
- "build": "rm -rf ./dist && tsc",
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",
9
19
  "watch": "npx tsc --watch",
10
20
  "test": "npx ava",
11
21
  "clean": "rimraf {.turbo,dist,node_modules}"
@@ -20,10 +30,13 @@
20
30
  },
21
31
  "files": [
22
32
  "dist/src",
33
+ "dist/index.cjs",
23
34
  "README.md",
24
35
  "package.json"
25
36
  ],
26
- "dependencies": {},
37
+ "dependencies": {
38
+ "@based/functions": "^3.0.2"
39
+ },
27
40
  "devDependencies": {
28
41
  "ts-node": "10.9.1",
29
42
  "ava": "5.3.1",