@meteorwallet/errors
Advanced tools
@@ -6,2 +6,3 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs'); | ||
| __meteorwallet_utils_javascript_type_utils_string_utils = require_rolldown_runtime.__toESM(__meteorwallet_utils_javascript_type_utils_string_utils); | ||
| require("@meteorwallet/utils/typescript/typescript_utility.types"); | ||
@@ -8,0 +9,0 @@ //#region src/MeteorError.ts |
| import { zMeteorErrorObject } from "./MeteorError.zod.js"; | ||
| import { jsErrorOrCastJsError } from "./utils/jsErrorOrCastJsError.js"; | ||
| import { nullEmpty } from "@meteorwallet/utils/javascript_type_utils/string.utils"; | ||
| import { PartialBy, StringKeyOf } from "@meteorwallet/utils/typescript/typescript_utility.types"; | ||
@@ -5,0 +6,0 @@ //#region src/MeteorError.ts |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"MeteorError.js","names":[],"sources":["../src/MeteorError.ts"],"sourcesContent":["import { nullEmpty } from \"@meteorwallet/utils/javascript_type_utils/string.utils\";\r\nimport { PartialBy, StringKeyOf } from \"@meteorwallet/utils/typescript/typescript_utility.types\";\r\nimport { IMeteorErrorObject, TErrorContextData, TErrorContextDataCheck } from \"./MeteorError.types\";\r\nimport { zMeteorErrorObject } from \"./MeteorError.zod\";\r\nimport { jsErrorOrCastJsError } from \"./utils/jsErrorOrCastJsError\";\r\n\r\nexport class MeteorError<\r\n N extends string = string,\r\n E extends string = string,\r\n C extends TErrorContextData<E> = any,\r\n >\r\n extends Error\r\n implements IMeteorErrorObject<N, E, C>\r\n{\r\n isUnknownError = false;\r\n public errorIds: E[] = [];\r\n public context: Partial<C> = {};\r\n public message: string;\r\n private setMessage: boolean = false;\r\n public name = \"MeteorError\" as const;\r\n public originError?: Error;\r\n public extendsSubtypes: string[] = [];\r\n public subtype: N;\r\n public castFromSubtype?: N;\r\n private contextCheck?: (id: E | string) => boolean;\r\n\r\n constructor(\r\n message: string,\r\n {\r\n ids,\r\n context,\r\n subtype,\r\n castFromSubtype,\r\n extendsSubtypes,\r\n }: {\r\n ids: E[];\r\n context?: Partial<C>;\r\n subtype?: N;\r\n castFromSubtype?: N;\r\n extendsSubtypes?: string[];\r\n originError: Error | undefined;\r\n },\r\n ) {\r\n super(message ?? \"\");\r\n\r\n this.subtype = subtype ?? (\"Unset\" as N);\r\n this.extendsSubtypes = extendsSubtypes ?? [];\r\n this.castFromSubtype = castFromSubtype;\r\n\r\n if (subtype === \"Unknown\") {\r\n this.isUnknownError = true;\r\n }\r\n\r\n this.message = message;\r\n this.errorIds = ids;\r\n this.context = context ?? {};\r\n\r\n if (nullEmpty(this.message)) {\r\n this.message = `[${this.errorIds.join(\"] , [\")}]`;\r\n }\r\n }\r\n\r\n static isMeteorErrorObj(\r\n err: any,\r\n ): err is PartialBy<IMeteorErrorObject<string, string, any>, \"subtype\"> {\r\n if (err != null && (typeof err === \"object\" || typeof err === \"function\")) {\r\n const parsed = zMeteorErrorObject.safeParse(err);\r\n return parsed.success;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n static isMeteorError(err: any): err is MeteorError {\r\n return MeteorError.isMeteorErrorObj(err) && err instanceof MeteorError;\r\n }\r\n\r\n static cast(err: any): MeteorError {\r\n if (MeteorError.isMeteorErrorObj(err)) {\r\n return new MeteorError(err.message, {\r\n ids: err.errorIds,\r\n context: err.context,\r\n subtype: err.subtype ?? \"Unset\",\r\n castFromSubtype: err.castFromSubtype,\r\n extendsSubtypes: err.extendsSubtypes ?? [],\r\n originError: err.originError,\r\n });\r\n }\r\n\r\n throw new MeteorInternalError(\r\n \"MeteorError: Tried to cast an object or class which does not match a MeteorError object\",\r\n );\r\n }\r\n\r\n static castOrNull(err: any): MeteorError | null {\r\n try {\r\n return MeteorError.cast(err);\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n static fromId<ID extends string>(id: ID, idContext?: any): MeteorError {\r\n const context = { [id]: idContext };\r\n return new MeteorError(\"\", {\r\n ids: [id],\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n static fromIds<ID extends string>(ids: ID[], context?: any): MeteorError {\r\n return new MeteorError(\"\", {\r\n ids,\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n static fromContext(context: Record<string, any>): MeteorError {\r\n const ids = Object.keys(context);\r\n return new MeteorError(\"\", {\r\n ids,\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n setContentCheck(contextCheck: TErrorContextDataCheck<StringKeyOf<C>>): void {\r\n this.contextCheck = (id: E | string) => contextCheck[id as unknown as StringKeyOf<C>] === true;\r\n }\r\n\r\n get idsText(): string {\r\n return `[${this.errorIds.join(\", \")}]`;\r\n }\r\n\r\n toJsonObject(): IMeteorErrorObject<N, E, C> {\r\n return {\r\n isUnknownError: this.isUnknownError,\r\n errorIds: this.errorIds,\r\n context: this.context,\r\n message: this.message,\r\n name: this.name,\r\n subtype: this.subtype,\r\n originError: this.originError,\r\n castFromSubtype: this.castFromSubtype,\r\n extendsSubtypes: this.extendsSubtypes,\r\n };\r\n }\r\n\r\n hasId(errorId: E): boolean {\r\n return this.errorIds.includes(errorId as E);\r\n }\r\n\r\n hasOneOfIds(incomingErrorIds: E[]): boolean {\r\n return incomingErrorIds.some((id) => this.hasId(id));\r\n }\r\n\r\n get hasMultiple(): boolean {\r\n return this.errorIds.length > 1;\r\n }\r\n\r\n getIds(): E[] {\r\n return this.errorIds as E[];\r\n }\r\n\r\n getContextForId<K extends StringKeyOf<C> extends undefined ? never : StringKeyOf<C>>(\r\n id: K,\r\n ): C[K] {\r\n const context = this.context[id];\r\n\r\n if (context == null) {\r\n throw new MeteorInternalError(\r\n `MeteorError[${this.subtype}]: Error ID \"${id as string}\" context was never set. Use MeteorError.withContext() when creating the Error, or use MeteorError.fromId(id, context)`,\r\n );\r\n }\r\n\r\n return context;\r\n }\r\n\r\n addId<K extends E>(\r\n errorId: K,\r\n context?: K extends StringKeyOf<C> ? C[K] : never,\r\n ): MeteorError<N, E, C> {\r\n if (this.contextCheck?.(errorId) && context == null) {\r\n throw new MeteorInternalError(\r\n `MeteorError[${this.subtype}]: Error ID \"${errorId}\" requires context data. Provide context as second argument, or use MeteorError.withContext()`,\r\n );\r\n }\r\n\r\n this.errorIds = [...new Set([...this.errorIds, errorId])];\r\n\r\n if (context != null) {\r\n this.context = {\r\n ...this.context,\r\n ...context,\r\n };\r\n }\r\n\r\n return this;\r\n }\r\n\r\n withMessage(message: string): MeteorError<N, E, C> {\r\n this.message = message;\r\n this.setMessage = true;\r\n return this;\r\n }\r\n\r\n withOriginError(error: unknown): MeteorError<N, E, C> {\r\n this.originError = jsErrorOrCastJsError(error);\r\n\r\n if (!this.setMessage) {\r\n this.message = this.originError.message ?? this.message;\r\n }\r\n\r\n return this;\r\n }\r\n}\r\n\r\nexport class MeteorInternalError extends Error {}\r\n\r\nexport type TAnyMeteorError = MeteorError<string, string, any>;\r\n\r\nexport type TMeteorErrorObject<ERR extends MeteorError> = ERR extends MeteorError<\r\n infer N,\r\n infer E,\r\n infer D\r\n>\r\n ? IMeteorErrorObject<N, E, D>\r\n : never;\r\n\r\nexport type TMeteorErrorInterpreter<T extends MeteorError> = (e: any) => T | undefined;\r\n\r\nexport type TMeteorErrorSubtype<O extends { _errRef: any }> = O[\"_errRef\"] extends MeteorError<\r\n infer N,\r\n infer E,\r\n infer D\r\n>\r\n ? MeteorError<string | N, E, D>\r\n : never;\r\n\r\nexport type TMeteorErrorSubtypeObject<O extends { _errRef: any }> =\r\n O[\"_errRef\"] extends MeteorError<infer N, infer E, infer D>\r\n ? IMeteorErrorObject<string | N, E, D>\r\n : never;\r\n\r\nexport type TMeteorResult<R, E extends MeteorError = TAnyMeteorError> =\r\n | {\r\n ok: false;\r\n error: E;\r\n result?: undefined;\r\n }\r\n | {\r\n ok: true;\r\n error?: undefined;\r\n result: R;\r\n };\r\n"],"mappings":";;;;;AAMA,IAAa,cAAb,MAAa,oBAKH,MAEV;CACE,iBA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AAGH,SAAO;;CAGT,YAAY,SAAuC;AACjD,OAAK,UAAU;AACf,OAAK,aAAa;AAClB,SAAO;;CAGT,gBAAgB,OAAsC;AACpD,OAAK,cAAc,qBAAqB,MAAM;AAE9C,MAAI,CAAC,KAAK,WACR,MAAK,UAAU,KAAK,YAAY,WAAW,KAAK;AAGlD,SAAO;;;AAIX,IAAa,sBAAb,cAAyC,MAAM"} | ||
| {"version":3,"file":"MeteorError.js","names":[],"sources":["../src/MeteorError.ts"],"sourcesContent":["import { nullEmpty } from \"@meteorwallet/utils/javascript_type_utils/string.utils\";\r\nimport { PartialBy, StringKeyOf } from \"@meteorwallet/utils/typescript/typescript_utility.types\";\r\nimport { IMeteorErrorObject, TErrorContextData, TErrorContextDataCheck } from \"./MeteorError.types\";\r\nimport { zMeteorErrorObject } from \"./MeteorError.zod\";\r\nimport { jsErrorOrCastJsError } from \"./utils/jsErrorOrCastJsError\";\r\n\r\nexport class MeteorError<\r\n N extends string = string,\r\n E extends string = string,\r\n C extends TErrorContextData<E> = any,\r\n >\r\n extends Error\r\n implements IMeteorErrorObject<N, E, C>\r\n{\r\n isUnknownError = false;\r\n public errorIds: E[] = [];\r\n public context: Partial<C> = {};\r\n public message: string;\r\n private setMessage: boolean = false;\r\n public name = \"MeteorError\" as const;\r\n public originError?: Error;\r\n public extendsSubtypes: string[] = [];\r\n public subtype: N;\r\n public castFromSubtype?: N;\r\n private contextCheck?: (id: E | string) => boolean;\r\n\r\n constructor(\r\n message: string,\r\n {\r\n ids,\r\n context,\r\n subtype,\r\n castFromSubtype,\r\n extendsSubtypes,\r\n }: {\r\n ids: E[];\r\n context?: Partial<C>;\r\n subtype?: N;\r\n castFromSubtype?: N;\r\n extendsSubtypes?: string[];\r\n originError: Error | undefined;\r\n },\r\n ) {\r\n super(message ?? \"\");\r\n\r\n this.subtype = subtype ?? (\"Unset\" as N);\r\n this.extendsSubtypes = extendsSubtypes ?? [];\r\n this.castFromSubtype = castFromSubtype;\r\n\r\n if (subtype === \"Unknown\") {\r\n this.isUnknownError = true;\r\n }\r\n\r\n this.message = message;\r\n this.errorIds = ids;\r\n this.context = context ?? {};\r\n\r\n if (nullEmpty(this.message)) {\r\n this.message = `[${this.errorIds.join(\"] , [\")}]`;\r\n }\r\n }\r\n\r\n static isMeteorErrorObj(\r\n err: any,\r\n ): err is PartialBy<IMeteorErrorObject<string, string, any>, \"subtype\"> {\r\n if (err != null && (typeof err === \"object\" || typeof err === \"function\")) {\r\n const parsed = zMeteorErrorObject.safeParse(err);\r\n return parsed.success;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n static isMeteorError(err: any): err is MeteorError {\r\n return MeteorError.isMeteorErrorObj(err) && err instanceof MeteorError;\r\n }\r\n\r\n static cast(err: any): MeteorError {\r\n if (MeteorError.isMeteorErrorObj(err)) {\r\n return new MeteorError(err.message, {\r\n ids: err.errorIds,\r\n context: err.context,\r\n subtype: err.subtype ?? \"Unset\",\r\n castFromSubtype: err.castFromSubtype,\r\n extendsSubtypes: err.extendsSubtypes ?? [],\r\n originError: err.originError,\r\n });\r\n }\r\n\r\n throw new MeteorInternalError(\r\n \"MeteorError: Tried to cast an object or class which does not match a MeteorError object\",\r\n );\r\n }\r\n\r\n static castOrNull(err: any): MeteorError | null {\r\n try {\r\n return MeteorError.cast(err);\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n static fromId<ID extends string>(id: ID, idContext?: any): MeteorError {\r\n const context = { [id]: idContext };\r\n return new MeteorError(\"\", {\r\n ids: [id],\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n static fromIds<ID extends string>(ids: ID[], context?: any): MeteorError {\r\n return new MeteorError(\"\", {\r\n ids,\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n static fromContext(context: Record<string, any>): MeteorError {\r\n const ids = Object.keys(context);\r\n return new MeteorError(\"\", {\r\n ids,\r\n context: context as any,\r\n subtype: \"Unset\",\r\n originError: undefined,\r\n });\r\n }\r\n\r\n setContentCheck(contextCheck: TErrorContextDataCheck<StringKeyOf<C>>): void {\r\n this.contextCheck = (id: E | string) => contextCheck[id as unknown as StringKeyOf<C>] === true;\r\n }\r\n\r\n get idsText(): string {\r\n return `[${this.errorIds.join(\", \")}]`;\r\n }\r\n\r\n toJsonObject(): IMeteorErrorObject<N, E, C> {\r\n return {\r\n isUnknownError: this.isUnknownError,\r\n errorIds: this.errorIds,\r\n context: this.context,\r\n message: this.message,\r\n name: this.name,\r\n subtype: this.subtype,\r\n originError: this.originError,\r\n castFromSubtype: this.castFromSubtype,\r\n extendsSubtypes: this.extendsSubtypes,\r\n };\r\n }\r\n\r\n hasId(errorId: E): boolean {\r\n return this.errorIds.includes(errorId as E);\r\n }\r\n\r\n hasOneOfIds(incomingErrorIds: E[]): boolean {\r\n return incomingErrorIds.some((id) => this.hasId(id));\r\n }\r\n\r\n get hasMultiple(): boolean {\r\n return this.errorIds.length > 1;\r\n }\r\n\r\n getIds(): E[] {\r\n return this.errorIds as E[];\r\n }\r\n\r\n getContextForId<K extends StringKeyOf<C> extends undefined ? never : StringKeyOf<C>>(\r\n id: K,\r\n ): C[K] {\r\n const context = this.context[id];\r\n\r\n if (context == null) {\r\n throw new MeteorInternalError(\r\n `MeteorError[${this.subtype}]: Error ID \"${id as string}\" context was never set. Use MeteorError.withContext() when creating the Error, or use MeteorError.fromId(id, context)`,\r\n );\r\n }\r\n\r\n return context;\r\n }\r\n\r\n addId<K extends E>(\r\n errorId: K,\r\n context?: K extends StringKeyOf<C> ? C[K] : never,\r\n ): MeteorError<N, E, C> {\r\n if (this.contextCheck?.(errorId) && context == null) {\r\n throw new MeteorInternalError(\r\n `MeteorError[${this.subtype}]: Error ID \"${errorId}\" requires context data. Provide context as second argument, or use MeteorError.withContext()`,\r\n );\r\n }\r\n\r\n this.errorIds = [...new Set([...this.errorIds, errorId])];\r\n\r\n if (context != null) {\r\n this.context = {\r\n ...this.context,\r\n ...context,\r\n };\r\n }\r\n\r\n return this;\r\n }\r\n\r\n withMessage(message: string): MeteorError<N, E, C> {\r\n this.message = message;\r\n this.setMessage = true;\r\n return this;\r\n }\r\n\r\n withOriginError(error: unknown): MeteorError<N, E, C> {\r\n this.originError = jsErrorOrCastJsError(error);\r\n\r\n if (!this.setMessage) {\r\n this.message = this.originError.message ?? this.message;\r\n }\r\n\r\n return this;\r\n }\r\n}\r\n\r\nexport class MeteorInternalError extends Error {}\r\n\r\nexport type TAnyMeteorError = MeteorError<string, string, any>;\r\n\r\nexport type TMeteorErrorObject<ERR extends MeteorError> = ERR extends MeteorError<\r\n infer N,\r\n infer E,\r\n infer D\r\n>\r\n ? IMeteorErrorObject<N, E, D>\r\n : never;\r\n\r\nexport type TMeteorErrorInterpreter<T extends MeteorError> = (e: any) => T | undefined;\r\n\r\nexport type TMeteorErrorSubtype<O extends { _errRef: any }> = O[\"_errRef\"] extends MeteorError<\r\n infer N,\r\n infer E,\r\n infer D\r\n>\r\n ? MeteorError<string | N, E, D>\r\n : never;\r\n\r\nexport type TMeteorErrorSubtypeObject<O extends { _errRef: any }> =\r\n O[\"_errRef\"] extends MeteorError<infer N, infer E, infer D>\r\n ? IMeteorErrorObject<string | N, E, D>\r\n : never;\r\n\r\nexport type TMeteorResult<R, E extends MeteorError = TAnyMeteorError> =\r\n | {\r\n ok: false;\r\n error: E;\r\n result?: undefined;\r\n }\r\n | {\r\n ok: true;\r\n error?: undefined;\r\n result: R;\r\n };\r\n"],"mappings":";;;;;;AAMA,IAAa,cAAb,MAAa,oBAKH,MAEV;CACE,iBAAiB;CACjB,AAAO,WAAgB,EAAE;CACzB,AAAO,UAAsB,EAAE;CAC/B,AAAO;CACP,AAAQ,aAAsB;CAC9B,AAAO,OAAO;CACd,AAAO;CACP,AAAO,kBAA4B,EAAE;CACrC,AAAO;CACP,AAAO;CACP,AAAQ;CAER,YACE,SACA,EACE,KACA,SACA,SACA,iBACA,mBASF;AACA,QAAM,WAAW,GAAG;AAEp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
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"MeteorError.zod.js","names":[],"sources":["../src/MeteorError.zod.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const zMeteorErrorObject = z.object({\n isUnknownError: z.boolean(),\n errorIds: z.array(z.string()),\n context: z.record(z.unknown()),\n message: z.string(),\n name: z.literal(\"MeteorError\"),\n subtype: z.string().optional(),\n});\n"],"mappings":";;;AAEA,MAAa,qBAAqB,EAAE,OAAO;CACzC,gBAAgB,EAAE,SAAS;CAC3B,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC;CAC7B,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC;CAC9B,SAAS,EAAE,QAAQ;CACnB,MAAM,EAAE,QAAQ,cAAc;CAC9B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC/B,CAAC"} | ||
| {"version":3,"file":"MeteorError.zod.js","names":[],"sources":["../src/MeteorError.zod.ts"],"sourcesContent":["import { z } from \"zod\";\r\n\r\nexport const zMeteorErrorObject = z.object({\r\n isUnknownError: z.boolean(),\r\n errorIds: z.array(z.string()),\r\n context: z.record(z.unknown()),\r\n message: z.string(),\r\n name: z.literal(\"MeteorError\"),\r\n subtype: z.string().optional(),\r\n});\r\n"],"mappings":";;;AAEA,MAAa,qBAAqB,EAAE,OAAO;CACzC,gBAAgB,EAAE,SAAS;CAC3B,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC;CAC7B,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC;CAC9B,SAAS,EAAE,QAAQ;CACnB,MAAM,EAAE,QAAQ,cAAc;CAC9B,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC/B,CAAC"} |
@@ -0,3 +1,5 @@ | ||
| const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs'); | ||
| const require_MeteorError = require('../MeteorError.cjs'); | ||
| const require_getAllMeteorErrorSubtypes = require('../utils/getAllMeteorErrorSubtypes.cjs'); | ||
| require("@meteorwallet/utils/typescript/typescript_utility.types"); | ||
@@ -4,0 +6,0 @@ //#region src/subtype/createMeteorErrorSubtype.ts |
| import { MeteorError, MeteorInternalError } from "../MeteorError.js"; | ||
| import { getAllMeteorErrorSubtypes } from "../utils/getAllMeteorErrorSubtypes.js"; | ||
| import { StringKeyOf } from "@meteorwallet/utils/typescript/typescript_utility.types"; | ||
@@ -4,0 +5,0 @@ //#region src/subtype/createMeteorErrorSubtype.ts |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"createMeteorErrorSubtype.js","names":[],"sources":["../../src/subtype/createMeteorErrorSubtype.ts"],"sourcesContent":["import { StringKeyOf } from \"@meteorwallet/utils/typescript/typescript_utility.types\";\r\nimport { MeteorError, MeteorInternalError } from \"../MeteorError\";\r\nimport {\r\n IMeteorErrorDescriptor,\r\n IMeteorErrorObject,\r\n TErrorContextData,\r\n TErrorContextDataCheck,\r\n} from \"../MeteorError.types\";\r\nimport { getAllMeteorErrorSubtypes } from \"../utils/getAllMeteorErrorSubtypes\";\r\n\r\nexport function createMeteorErrorSubtype<\r\n N extends string,\r\n E extends string = never,\r\n C extends TErrorContextData<E> = {},\r\n>(subtype: N, contextCheck?: TErrorContextDataCheck<StringKeyOf<C>>, extendsSubtypes?: string[]) {\r\n const errorBaseData = {\r\n contextCheck,\r\n subtype,\r\n extendsSubtypes: extendsSubtypes ?? [],\r\n };\r\n\r\n const contextCheckThrow = (\r\n ids: E[],\r\n context?: Partial<TErrorContextDataCheck<StringKeyOf<C>>>,\r\n ) => {\r\n if (errorBaseData.contextCheck != null) {\r\n for (const id of ids as unknown as StringKeyOf<C>[]) {\r\n if (errorBaseData.contextCheck[id] && (context == null || context[id] == null)) {\r\n throw new MeteorInternalError(\r\n `MeteorError [subtype: ${subtype}]: Error ID \"${id}\" requires context data. Provide context with the IDs when creating the Error, or use MeteorError.withContext()`,\r\n );\r\n }\r\n }\r\n }\r\n };\r\n\r\n const wrapWithContextCheck = (error: MeteorError<N, E, C>): MeteorError<N, E, C> => {\r\n if (errorBaseData.contextCheck != null) {\r\n error.setContentCheck(errorBaseData.contextCheck);\r\n }\r\n return error;\r\n };\r\n\r\n const isObj = (inspectErr: unknown): inspectErr is IMeteorErrorObject<N, E, C> => {\r\n if (!MeteorError.isMeteorErrorObj(inspectErr)) {\r\n return false;\r\n }\r\n\r\n if (inspectErr.subtype == null) {\r\n return false;\r\n }\r\n\r\n return inspectErr.subtype === subtype || (extendsSubtypes ?? []).includes(inspectErr.subtype);\r\n };\r\n\r\n const isExactSubtypeObj = (err: unknown): err is IMeteorErrorObject<N, E, C> => {\r\n return MeteorError.isMeteorErrorObj(err) && err.subtype === subtype;\r\n };\r\n\r\n const is = (err: any): err is MeteorError<N, E, C> => {\r\n return isObj(err) && err instanceof MeteorError;\r\n };\r\n\r\n const isExactSubtype = (err: any): err is MeteorError<N, E, C> => {\r\n return isExactSubtypeObj(err) && err instanceof MeteorError;\r\n };\r\n\r\n const cast = (inspectError?: any): MeteorError<N, E, C> => {\r\n // console.log(\"Trying to cast error object\", inspectError);\r\n\r\n if (isObj(inspectError)) {\r\n // console.log(`casting from error ${inspectError.subtype}`, inspectError);\r\n\r\n return new MeteorError(inspectError.message, {\r\n ids: inspectError.errorIds,\r\n context: inspectError.context,\r\n subtype,\r\n castFromSubtype: inspectError.subtype,\r\n extendsSubtypes,\r\n originError: inspectError.originError,\r\n });\r\n }\r\n\r\n throw new MeteorInternalError(\r\n `MeteorError [subtypes: \"${getAllMeteorErrorSubtypes(errorBaseData).join(`\", \"`)}\"]: Tried to cast an object or class which does not match a MeteorError object or this subtype [incoming error subtypes: \"${getAllMeteorErrorSubtypes(inspectError).join(`\", \"`)}\"]`,\r\n );\r\n };\r\n\r\n const castOrNull = (err: any): MeteorError<N, E, C> | null => {\r\n try {\r\n return cast(err);\r\n } catch (e) {\r\n if (e instanceof Error) {\r\n console.warn(e.message);\r\n }\r\n return null;\r\n }\r\n };\r\n\r\n const fromId = <ID extends E>(id: ID, idContext?: ID extends keyof C ? C[ID] : never) => {\r\n const context = { [id]: idContext };\r\n contextCheckThrow([id], context as any);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids: [id],\r\n context: context as any,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromIds = <ID extends E>(ids: ID[], context?: Partial<C>) => {\r\n contextCheckThrow(ids, context);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids,\r\n context,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromContext = (context: Partial<C>) => {\r\n const ids = Object.keys(context) as E[];\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids,\r\n context,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromDescriptor = (descriptor: IMeteorErrorDescriptor<E, C>) => {\r\n contextCheckThrow([descriptor.id], {\r\n [descriptor.id]: descriptor.context,\r\n } as any);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(descriptor.message, {\r\n ids: [descriptor.id],\r\n context: {\r\n [descriptor.id]: descriptor.context,\r\n } as Partial<C>,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const extendMeteorErrorSubtype = <\r\n SN extends string,\r\n SE extends string,\r\n SC extends TErrorContextData<SE> = C,\r\n >(\r\n sName: SN,\r\n sContextCheck?: TErrorContextDataCheck<StringKeyOf<SC>>,\r\n ) => {\r\n return createMeteorErrorSubtype<SN, SE | E, SC & C>(\r\n sName,\r\n {\r\n ...(sContextCheck ?? {}),\r\n ...(contextCheck ?? {}),\r\n } as any,\r\n [...(extendsSubtypes ?? []), subtype],\r\n );\r\n };\r\n\r\n const _empty = () => {\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids: [],\r\n context: {},\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const _errRef = _empty();\r\n\r\n return {\r\n is,\r\n isExactSubtype,\r\n isObj,\r\n isExactSubtypeObj,\r\n fromId,\r\n fromIds,\r\n fromContext,\r\n fromDescriptor,\r\n cast,\r\n castOrNull,\r\n extendMeteorErrorSubtype,\r\n _errRef,\r\n };\r\n}\r\n"],"mappings":";;;;AAUA,SAAgB,yBAId,SAAY,cAAuD,iBAA4B;CAC/F,MAAM,gBAAgB;EACpB;EACA;EACA,iBAAiB,mBAAmB,EAAE;EACvC;CAED,MAAM,qBACJ,KACA,YACG;AACH,MAAI,cAAc,gBAAgB,MAChC;QAAK,MAAM,MAAM,IACf,KAAI,cAAc,aAAa,QAAQ,WAAW,QAAQ,QAAQ,OAAO,MACvE,OAAM,IAAI,oBACR,yBAAyB,QAAQ,eAAe,GAAG,iHACpD;;;CAMT,MAAM,wBAAwB,UAAsD;AAClF,MAAI,cAAc,gBAAgB,KAChC,OAAM,gBAAgB,cAAc,aAAa;AAEnD,SAAO;;CAGT,MAAM,SAAS,eAAmE;AAChF,MAAI,CAAC,YAAY,iBAAiB,WAAW,CAC3C,QAAO;AAGT,MAAI,WAAW,WAAW,KACxB,QAAO;AAGT,SAAO,WAAW,YAAY,YAAY,mBAAmB,EAAE,EAAE,SAAS,WAAW,QAAQ;;CAG/F,MAAM,qBAAqB,QAAqD;AAC9E,SAAO,YAAY,iBAAiB,IAAI,IAAI,IAAI,YAAY;;CAG9D,MAAM,MAAM,QAA0C;AACpD,SAAO,MAAM,IAAI,IAAI,eAAe;;CAGtC,MAAM,kBAAkB,QAA0C;AAChE,SAAO,kBAAkB,IAAI,IAAI,eAAe;;CAGlD,MAAM,QAAQ,iBAA6C;AAGzD,MAAI,MAAM,aAAa,CAGrB,QAAO,IAAI,YAAY,aAAa,SAAS;GAC3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AE;GACvB,EACD,CAAC,GAAI,mBAAmB,EAAE,EAAG,QAAQ,CACtC;;CAGH,MAAM,eAAe;AACnB,SAAO,qBACL,IAAI,YAAqB,IAAI;GAC3B,KAAK,EAAE;GACP,SAAS,EAAE;GACF;GACQ;GACjB,aAAa;GACd,CAAC,CACH;;CAGH,MAAM,UAAU,QAAQ;AAExB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"} | ||
| {"version":3,"file":"createMeteorErrorSubtype.js","names":[],"sources":["../../src/subtype/createMeteorErrorSubtype.ts"],"sourcesContent":["import { StringKeyOf } from \"@meteorwallet/utils/typescript/typescript_utility.types\";\r\nimport { MeteorError, MeteorInternalError } from \"../MeteorError\";\r\nimport {\r\n IMeteorErrorDescriptor,\r\n IMeteorErrorObject,\r\n TErrorContextData,\r\n TErrorContextDataCheck,\r\n} from \"../MeteorError.types\";\r\nimport { getAllMeteorErrorSubtypes } from \"../utils/getAllMeteorErrorSubtypes\";\r\n\r\nexport function createMeteorErrorSubtype<\r\n N extends string,\r\n E extends string = never,\r\n C extends TErrorContextData<E> = {},\r\n>(subtype: N, contextCheck?: TErrorContextDataCheck<StringKeyOf<C>>, extendsSubtypes?: string[]) {\r\n const errorBaseData = {\r\n contextCheck,\r\n subtype,\r\n extendsSubtypes: extendsSubtypes ?? [],\r\n };\r\n\r\n const contextCheckThrow = (\r\n ids: E[],\r\n context?: Partial<TErrorContextDataCheck<StringKeyOf<C>>>,\r\n ) => {\r\n if (errorBaseData.contextCheck != null) {\r\n for (const id of ids as unknown as StringKeyOf<C>[]) {\r\n if (errorBaseData.contextCheck[id] && (context == null || context[id] == null)) {\r\n throw new MeteorInternalError(\r\n `MeteorError [subtype: ${subtype}]: Error ID \"${id}\" requires context data. Provide context with the IDs when creating the Error, or use MeteorError.withContext()`,\r\n );\r\n }\r\n }\r\n }\r\n };\r\n\r\n const wrapWithContextCheck = (error: MeteorError<N, E, C>): MeteorError<N, E, C> => {\r\n if (errorBaseData.contextCheck != null) {\r\n error.setContentCheck(errorBaseData.contextCheck);\r\n }\r\n return error;\r\n };\r\n\r\n const isObj = (inspectErr: unknown): inspectErr is IMeteorErrorObject<N, E, C> => {\r\n if (!MeteorError.isMeteorErrorObj(inspectErr)) {\r\n return false;\r\n }\r\n\r\n if (inspectErr.subtype == null) {\r\n return false;\r\n }\r\n\r\n return inspectErr.subtype === subtype || (extendsSubtypes ?? []).includes(inspectErr.subtype);\r\n };\r\n\r\n const isExactSubtypeObj = (err: unknown): err is IMeteorErrorObject<N, E, C> => {\r\n return MeteorError.isMeteorErrorObj(err) && err.subtype === subtype;\r\n };\r\n\r\n const is = (err: any): err is MeteorError<N, E, C> => {\r\n return isObj(err) && err instanceof MeteorError;\r\n };\r\n\r\n const isExactSubtype = (err: any): err is MeteorError<N, E, C> => {\r\n return isExactSubtypeObj(err) && err instanceof MeteorError;\r\n };\r\n\r\n const cast = (inspectError?: any): MeteorError<N, E, C> => {\r\n // console.log(\"Trying to cast error object\", inspectError);\r\n\r\n if (isObj(inspectError)) {\r\n // console.log(`casting from error ${inspectError.subtype}`, inspectError);\r\n\r\n return new MeteorError(inspectError.message, {\r\n ids: inspectError.errorIds,\r\n context: inspectError.context,\r\n subtype,\r\n castFromSubtype: inspectError.subtype,\r\n extendsSubtypes,\r\n originError: inspectError.originError,\r\n });\r\n }\r\n\r\n throw new MeteorInternalError(\r\n `MeteorError [subtypes: \"${getAllMeteorErrorSubtypes(errorBaseData).join(`\", \"`)}\"]: Tried to cast an object or class which does not match a MeteorError object or this subtype [incoming error subtypes: \"${getAllMeteorErrorSubtypes(inspectError).join(`\", \"`)}\"]`,\r\n );\r\n };\r\n\r\n const castOrNull = (err: any): MeteorError<N, E, C> | null => {\r\n try {\r\n return cast(err);\r\n } catch (e) {\r\n if (e instanceof Error) {\r\n console.warn(e.message);\r\n }\r\n return null;\r\n }\r\n };\r\n\r\n const fromId = <ID extends E>(id: ID, idContext?: ID extends keyof C ? C[ID] : never) => {\r\n const context = { [id]: idContext };\r\n contextCheckThrow([id], context as any);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids: [id],\r\n context: context as any,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromIds = <ID extends E>(ids: ID[], context?: Partial<C>) => {\r\n contextCheckThrow(ids, context);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids,\r\n context,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromContext = (context: Partial<C>) => {\r\n const ids = Object.keys(context) as E[];\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids,\r\n context,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const fromDescriptor = (descriptor: IMeteorErrorDescriptor<E, C>) => {\r\n contextCheckThrow([descriptor.id], {\r\n [descriptor.id]: descriptor.context,\r\n } as any);\r\n\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(descriptor.message, {\r\n ids: [descriptor.id],\r\n context: {\r\n [descriptor.id]: descriptor.context,\r\n } as Partial<C>,\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const extendMeteorErrorSubtype = <\r\n SN extends string,\r\n SE extends string,\r\n SC extends TErrorContextData<SE> = C,\r\n >(\r\n sName: SN,\r\n sContextCheck?: TErrorContextDataCheck<StringKeyOf<SC>>,\r\n ) => {\r\n return createMeteorErrorSubtype<SN, SE | E, SC & C>(\r\n sName,\r\n {\r\n ...(sContextCheck ?? {}),\r\n ...(contextCheck ?? {}),\r\n } as any,\r\n [...(extendsSubtypes ?? []), subtype],\r\n );\r\n };\r\n\r\n const _empty = () => {\r\n return wrapWithContextCheck(\r\n new MeteorError<N, E, C>(\"\", {\r\n ids: [],\r\n context: {},\r\n subtype: subtype,\r\n extendsSubtypes: extendsSubtypes,\r\n originError: undefined,\r\n }),\r\n );\r\n };\r\n\r\n const _errRef = _empty();\r\n\r\n return {\r\n is,\r\n isExactSubtype,\r\n isObj,\r\n isExactSubtypeObj,\r\n fromId,\r\n fromIds,\r\n fromContext,\r\n fromDescriptor,\r\n cast,\r\n castOrNull,\r\n extendMeteorErrorSubtype,\r\n _errRef,\r\n };\r\n}\r\n"],"mappings":";;;;;AAUA,SAAgB,yBAId,SAAY,cAAuD,iBAA4B;CAC/F,MAAM,gBAAgB;EACpB;EACA;EACA,iBAAiB,mBAAmB,EAAE;EACvC;CAED,MAAM,qBACJ,KACA,YACG;AACH,MAAI,cAAc,gBAAgB,MAChC;QAAK,MAAM,MAAM,IACf,KAAI,cAAc,aAAa,QAAQ,WAAW,QAAQ,QAAQ,OAAO,MACvE,OAAM,IAAI,oBACR,yBAAyB,QAAQ,eAAe,GAAG,iHACpD;;;CAMT,MAAM,wBAAwB,UAAsD;AAClF,MAAI,cAAc,gBAAgB,KAChC,OAAM,gBAAgB,cAAc,aAAa;AAEnD,SAAO;;CAGT,MAAM,SAAS,eAAmE;AAChF,MAAI,CAAC,YAAY,iBAAiB,WAAW,CAC3C,QAAO;AAGT,MAAI,WAAW,WAAW,KACxB,QAAO;AAGT,SAAO,WAAW,YAAY,YAAY,mBAAmB,EAAE,EAAE,SAAS,WAAW,QAAQ;;CAG/F,MAAM,qBAAqB,QAAqD;AAC9E,SAAO,YAAY,iBAAiB,IAAI,IAAI,IAAI,YAAY;;CAG9D,MAAM,MAAM,QAA0C;AACpD,SAAO,MAAM,IAAI,IAAI,eAAe;;CAGtC,MAAM,kBAAkB,QAA0C;AAChE,SAAO,kBAAkB,IAAI,IAAI,eAAe;;CAGlD,MAAM,QAAQ,iBAA6C;AAGzD,MAAI,MAAM,aAAa,CAGrB,QAAO,IAAI,YAAY,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GAAI,gBAAgB,EAAE;GACvB,EACD,CAAC,GAAI,mBAAmB,EAAE,EAAG,QAAQ,CACtC;;CAGH,MAAM,eAAe;AACnB,SAAO,qBACL,IAAI,YAAqB,IAAI;GAC3B,KAAK,EAAE;GACP,SAAS,EAAE;GACF;GACQ;GACjB,aAAa;GACd,CAAC,CACH;;CAGH,MAAM,UAAU,QAAQ;AAExB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"} |
@@ -0,1 +1,2 @@ | ||
| require('../MeteorError.cjs'); | ||
| const require_createMeteorErrorSubtype = require('./createMeteorErrorSubtype.cjs'); | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
| import "../MeteorError.js"; | ||
| import { createMeteorErrorSubtype } from "./createMeteorErrorSubtype.js"; | ||
@@ -2,0 +3,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"merr_unknown.js","names":[],"sources":["../../src/subtype/merr_unknown.ts"],"sourcesContent":["import { TMeteorErrorSubtype } from \"../MeteorError\";\r\nimport { createMeteorErrorSubtype } from \"./createMeteorErrorSubtype\";\r\n\r\nexport enum EErrIdUnknown {\r\n unhandled_error = \"unhandled_error\",\r\n}\r\n\r\nexport interface IMeteorErrorUnknownContext {\r\n [EErrIdUnknown.unhandled_error]: Error;\r\n}\r\n\r\nexport const baseMeteorErrorContext = {\r\n [EErrIdUnknown.unhandled_error]: true,\r\n} as const;\r\n\r\nexport const merr_unknown = createMeteorErrorSubtype<\r\n \"merr_unknown\",\r\n EErrIdUnknown,\r\n IMeteorErrorUnknownContext\r\n>(\"merr_unknown\", baseMeteorErrorContext);\r\n\r\nexport type TMeteorErrorUnknown = TMeteorErrorSubtype<typeof merr_unknown>;\r\n"],"mappings":";;;AAGA,IAAY,0DAAL;AACL;;;AAOF,MAAa,yBAAyB,GACnC,cAAc,kBAAkB,MAClC;AAED,MAAa,eAAe,yBAI1B,gBAAgB,uBAAuB"} | ||
| {"version":3,"file":"merr_unknown.js","names":[],"sources":["../../src/subtype/merr_unknown.ts"],"sourcesContent":["import { TMeteorErrorSubtype } from \"../MeteorError\";\r\nimport { createMeteorErrorSubtype } from \"./createMeteorErrorSubtype\";\r\n\r\nexport enum EErrIdUnknown {\r\n unhandled_error = \"unhandled_error\",\r\n}\r\n\r\nexport interface IMeteorErrorUnknownContext {\r\n [EErrIdUnknown.unhandled_error]: Error;\r\n}\r\n\r\nexport const baseMeteorErrorContext = {\r\n [EErrIdUnknown.unhandled_error]: true,\r\n} as const;\r\n\r\nexport const merr_unknown = createMeteorErrorSubtype<\r\n \"merr_unknown\",\r\n EErrIdUnknown,\r\n IMeteorErrorUnknownContext\r\n>(\"merr_unknown\", baseMeteorErrorContext);\r\n\r\nexport type TMeteorErrorUnknown = TMeteorErrorSubtype<typeof merr_unknown>;\r\n"],"mappings":";;;;AAGA,IAAY,0DAAL;AACL;;;AAOF,MAAa,yBAAyB,GACnC,cAAc,kBAAkB,MAClC;AAED,MAAa,eAAe,yBAI1B,gBAAgB,uBAAuB"} |
+2
-2
| { | ||
| "name": "@meteorwallet/errors", | ||
| "version": "1.28.0-0", | ||
| "version": "1.29.0-0", | ||
| "description": "Error handling for Meteor Wallet", | ||
@@ -38,3 +38,3 @@ "files": [ | ||
| "dependencies": { | ||
| "@meteorwallet/utils": "1.28.0-0", | ||
| "@meteorwallet/utils": "1.29.0-0", | ||
| "zod": "3.24.4" | ||
@@ -41,0 +41,0 @@ }, |
282387
0.17%1893
0.37%+ Added
- Removed
Updated