@nice-code/error 0.8.0 → 0.10.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/build/index.d.ts +913 -0
- package/build/index.js +1004 -933
- package/build/index.js.map +1 -0
- package/package.json +5 -4
- package/build/types/NiceError/NiceError.d.ts +0 -148
- package/build/types/NiceError/NiceError.enums.d.ts +0 -5
- package/build/types/NiceError/NiceError.types.d.ts +0 -204
- package/build/types/NiceError/NiceErrorHydrated.d.ts +0 -51
- package/build/types/NiceError/nice_error.static.d.ts +0 -2
- package/build/types/NiceErrorDefined/NiceErrorDefined.d.ts +0 -135
- package/build/types/NiceErrorDefined/defineNiceError.d.ts +0 -7
- package/build/types/NiceErrorDefined/err.d.ts +0 -59
- package/build/types/NiceErrorHandler/NiceErrorHandler.d.ts +0 -23
- package/build/types/NiceErrorHandler/NiceErrorHandler.types.d.ts +0 -82
- package/build/types/NiceErrorHandler/handleWith.d.ts +0 -8
- package/build/types/example/error_usage_example.d.ts +0 -41
- package/build/types/index.d.ts +0 -18
- package/build/types/internal/index.d.ts +0 -1
- package/build/types/internal/nice_core_errors.d.ts +0 -49
- package/build/types/test/helpers/nice_error_testing.static.d.ts +0 -3
- package/build/types/test/helpers/test_utils.d.ts +0 -1
- package/build/types/utils/castAndHydrate.d.ts +0 -35
- package/build/types/utils/castNiceError.d.ts +0 -15
- package/build/types/utils/inspectPotentialError/inspectPotentialError.d.ts +0 -2
- package/build/types/utils/inspectPotentialError/inspectPotentialError.enums.d.ts +0 -9
- package/build/types/utils/inspectPotentialError/inspectPotentialError.types.d.ts +0 -51
- package/build/types/utils/isNiceErrorObject.d.ts +0 -12
- package/build/types/utils/isRegularErrorObject.d.ts +0 -2
- package/build/types/utils/jsErrorOrCastJsError.d.ts +0 -1
- package/build/types/utils/logger.d.ts +0 -3
- package/build/types/utils/matchFirst.d.ts +0 -35
- package/build/types/utils/packError/causePack.d.ts +0 -2
- package/build/types/utils/packError/msgPack.d.ts +0 -2
- package/build/types/utils/packError/packError.d.ts +0 -3
- package/build/types/utils/packError/packError.enums.d.ts +0 -5
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { NiceError } from "../NiceError/NiceError";
|
|
2
|
-
import type { INiceErrorDomainProps, TExtractContextType } from "../NiceError/NiceError.types";
|
|
3
|
-
/**
|
|
4
|
-
* Handler map for `matchFirst`. Each key is an error id (from `ACTIVE_IDS`) and
|
|
5
|
-
* the value is a function that receives the typed context for that id.
|
|
6
|
-
*
|
|
7
|
-
* The `_` key is an optional fallback that runs when no id-specific handler matched.
|
|
8
|
-
*/
|
|
9
|
-
export type TMatchFirstHandlers<ERR_DEF extends INiceErrorDomainProps, ACTIVE_IDS extends keyof ERR_DEF["schema"] & string, RESULT> = {
|
|
10
|
-
[K in ACTIVE_IDS]?: (context: TExtractContextType<ERR_DEF["schema"][K]>) => RESULT;
|
|
11
|
-
} & {
|
|
12
|
-
_?: () => RESULT;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Pattern-matches an error against a map of id → handler functions, returning the
|
|
16
|
-
* result of the first handler whose id is active on the error.
|
|
17
|
-
*
|
|
18
|
-
* - Ids are tested in the order returned by `error.getIds()`.
|
|
19
|
-
* - If no id-specific handler matched and `_` is provided, the fallback is called.
|
|
20
|
-
* - Returns `undefined` when neither any id handler nor the fallback fires.
|
|
21
|
-
*
|
|
22
|
-
* **Requires hydrated context.** If any matched id is in the `"unhydrated"` state,
|
|
23
|
-
* `getContext` will throw. Call `niceErrorDefined.hydrate(error)` beforehand when
|
|
24
|
-
* working with errors deserialized from a JSON payload.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const result = matchFirst(error, {
|
|
29
|
-
* invalid_credentials: ({ username }) => `Wrong password for ${username}`,
|
|
30
|
-
* account_locked: () => "Account is locked",
|
|
31
|
-
* _: () => "Unknown auth error",
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare function matchFirst<ERR_DEF extends INiceErrorDomainProps, ACTIVE_IDS extends keyof ERR_DEF["schema"] & string, RESULT>(error: NiceError<ERR_DEF, ACTIVE_IDS>, handlers: TMatchFirstHandlers<ERR_DEF, ACTIVE_IDS, RESULT>): RESULT | undefined;
|