@zireal/result-kit 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zireal/result-kit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Type-safe result and structured error utilities for TypeScript, with optional NestJS adapters.",
5
5
  "license": "MIT",
6
6
  "author": "Ali Farooq <alifarooq122@gmail.com>",
@@ -16,17 +16,6 @@
16
16
  "result-type",
17
17
  "result monad"
18
18
  ],
19
- "scripts": {
20
- "build": "tsdown",
21
- "clean": "rm -rf dist coverage",
22
- "changeset": "changeset",
23
- "changeset:version": "changeset version",
24
- "changeset:publish": "changeset publish",
25
- "test": "vitest run",
26
- "test:watch": "vitest watch",
27
- "test:cov": "vitest run --coverage",
28
- "check": "tsc --noEmit"
29
- },
30
19
  "peerDependencies": {
31
20
  "@nestjs/common": "^11.0.0"
32
21
  },
@@ -65,5 +54,16 @@
65
54
  "require": "./dist/nest/index.cjs"
66
55
  },
67
56
  "./package.json": "./package.json"
57
+ },
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "clean": "rm -rf dist coverage",
61
+ "changeset": "changeset",
62
+ "changeset:version": "changeset version",
63
+ "changeset:publish": "changeset publish",
64
+ "test": "vitest run",
65
+ "test:watch": "vitest watch",
66
+ "test:cov": "vitest run --coverage",
67
+ "check": "tsc --noEmit"
68
68
  }
69
- }
69
+ }
@@ -1,4 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_result_kit = require("../result-kit-Ck1xAp-J.cjs");
3
- exports.ResultKit = require_result_kit.ResultKit;
4
- exports.isTypedError = require_result_kit.isTypedError;
@@ -1,3 +0,0 @@
1
- import { a as isTypedError, i as TypedErrorUnion, n as TypedError, r as TypedErrorOf, t as ResultKit } from "../index-EJ_Ol5Fu.cjs";
2
- import { n as Result, r as Success, t as Failure } from "../result-DbQ8o1Cs.cjs";
3
- export { Failure, Result, ResultKit, Success, TypedError, TypedErrorOf, TypedErrorUnion, isTypedError };
@@ -1,3 +0,0 @@
1
- import { a as isTypedError, i as TypedErrorUnion, n as TypedError, r as TypedErrorOf, t as ResultKit } from "../index-Ch6k0lVU.mjs";
2
- import { n as Result, r as Success, t as Failure } from "../result-CI_HBDHK.mjs";
3
- export { Failure, Result, ResultKit, Success, TypedError, TypedErrorOf, TypedErrorUnion, isTypedError };
@@ -1,2 +0,0 @@
1
- import { n as isTypedError, t as ResultKit } from "../result-kit-C5ZY61pO.mjs";
2
- export { ResultKit, isTypedError };
@@ -1,70 +0,0 @@
1
- import { n as Result, r as Success, t as Failure } from "./result-CI_HBDHK.mjs";
2
-
3
- //#region src/core/error.d.ts
4
- interface TypedError<TType extends string = string> {
5
- readonly type: TType;
6
- readonly message: string;
7
- readonly details?: Record<string, unknown>;
8
- readonly cause?: unknown;
9
- }
10
- type TypedErrorOf<TType extends string> = TypedError<TType>;
11
- type TypedErrorUnion<TType extends string> = TType extends string ? TypedError<TType> : never;
12
- declare const isTypedError: (error: unknown) => error is TypedError<string>;
13
- //#endregion
14
- //#region src/core/result-kit.d.ts
15
- declare abstract class ResultKit {
16
- static isSuccess<T, E>(result: Result<T, E>): result is Success<T>;
17
- static isFailure<T, E>(result: Result<T, E>): result is Failure<E>;
18
- static success<T>(value: T): Success<T>;
19
- static failure<E>(error: E): Failure<E>;
20
- static fail<T extends string>(error: TypedError<T>): Failure<TypedError<T>>;
21
- static isTypedError(error: unknown): error is TypedError<string>;
22
- static map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
23
- static bimap<T, U, E, F>(result: Result<T, E>, onSuccess: (value: T) => U, onFailure: (error: E) => F): Result<U, F>;
24
- static mapAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<U>): Promise<Result<U, E>>;
25
- static mapError<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
26
- static mapErrorAsync<T, E, F>(result: Result<T, E>, fn: (error: E) => Promise<F>): Promise<Result<T, F>>;
27
- static andThen<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
28
- static andThenAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<Result<U, E>>): Promise<Result<U, E>>;
29
- static orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
30
- static orElseAsync<T, E, F>(result: Result<T, E>, fn: (error: E) => Promise<Result<T, F>>): Promise<Result<T, F>>;
31
- static unwrap<T, E>(result: Result<T, E>): T | undefined;
32
- static unwrapSuccess<T>(result: Success<T>): T;
33
- static unwrapFailure<E>(result: Failure<E>): E;
34
- static unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
35
- static unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
36
- static unwrapOrElseAsync<T, E>(result: Result<T, E>, fn: (error: E) => Promise<T>): Promise<T>;
37
- static match<T, E, U>(result: Result<T, E>, handlers: {
38
- onSuccess: (value: T) => U;
39
- onFailure: (error: E) => U;
40
- }): U;
41
- static matchAsync<T, E, U>(result: Result<T, E>, handlers: {
42
- onSuccess: (value: T) => Promise<U>;
43
- onFailure: (error: E) => Promise<U>;
44
- }): Promise<U>;
45
- static tap<T, E>(result: Result<T, E>, handlers: {
46
- onSuccess?: (value: T) => void;
47
- onFailure?: (error: E) => void;
48
- }): Result<T, E>;
49
- static tapAsync<T, E>(result: Result<T, E>, handlers: {
50
- onSuccess?: (value: T) => Promise<void>;
51
- onFailure?: (error: E) => Promise<void>;
52
- }): Promise<Result<T, E>>;
53
- static combine<T, E>(results: Result<T, E>[]): Result<T[], E>;
54
- static combineAsync<T, E>(results: Promise<Result<T, E>>[]): Promise<Result<T[], E>>;
55
- static combineWithAllErrors<T, E>(results: Result<T, E>[]): Result<T[], E[]>;
56
- static combineWithAllErrorsAsync<T, E>(results: Promise<Result<T, E>>[]): Promise<Result<T[], E[]>>;
57
- static flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E>;
58
- static fromPromise<T, E>(promise: Promise<T>, errorFn: (error: unknown) => E): Promise<Result<T, E>>;
59
- static fromThrowable<Args extends unknown[], T, E>(fn: (...args: Args) => T, errorFn: (error: unknown) => E): (...args: Args) => Result<T, E>;
60
- static fromThrowableAsync<Args extends unknown[], T, E>(fn: (...args: Args) => Promise<T>, errorFn: (error: unknown) => E): (...args: Args) => Promise<Result<T, E>>;
61
- static fromNullable<T, E>(value: T | null | undefined, error: E): Result<NonNullable<T>, E>;
62
- static fromPredicate<T, E>(value: T, predicate: (value: T) => boolean, error: E): Result<T, E>;
63
- static toNullable<T, E>(result: Result<T, E>): T | null;
64
- static partition<T, E>(results: Result<T, E>[]): [T[], E[]];
65
- static filterSuccesses<T, E>(results: Result<T, E>[]): T[];
66
- static filterFailures<T, E>(results: Result<T, E>[]): E[];
67
- }
68
- //#endregion
69
- export { isTypedError as a, TypedErrorUnion as i, TypedError as n, TypedErrorOf as r, ResultKit as t };
70
- //# sourceMappingURL=index-Ch6k0lVU.d.mts.map
@@ -1,70 +0,0 @@
1
- import { n as Result, r as Success, t as Failure } from "./result-DbQ8o1Cs.cjs";
2
-
3
- //#region src/core/error.d.ts
4
- interface TypedError<TType extends string = string> {
5
- readonly type: TType;
6
- readonly message: string;
7
- readonly details?: Record<string, unknown>;
8
- readonly cause?: unknown;
9
- }
10
- type TypedErrorOf<TType extends string> = TypedError<TType>;
11
- type TypedErrorUnion<TType extends string> = TType extends string ? TypedError<TType> : never;
12
- declare const isTypedError: (error: unknown) => error is TypedError<string>;
13
- //#endregion
14
- //#region src/core/result-kit.d.ts
15
- declare abstract class ResultKit {
16
- static isSuccess<T, E>(result: Result<T, E>): result is Success<T>;
17
- static isFailure<T, E>(result: Result<T, E>): result is Failure<E>;
18
- static success<T>(value: T): Success<T>;
19
- static failure<E>(error: E): Failure<E>;
20
- static fail<T extends string>(error: TypedError<T>): Failure<TypedError<T>>;
21
- static isTypedError(error: unknown): error is TypedError<string>;
22
- static map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
23
- static bimap<T, U, E, F>(result: Result<T, E>, onSuccess: (value: T) => U, onFailure: (error: E) => F): Result<U, F>;
24
- static mapAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<U>): Promise<Result<U, E>>;
25
- static mapError<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
26
- static mapErrorAsync<T, E, F>(result: Result<T, E>, fn: (error: E) => Promise<F>): Promise<Result<T, F>>;
27
- static andThen<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
28
- static andThenAsync<T, U, E>(result: Result<T, E>, fn: (value: T) => Promise<Result<U, E>>): Promise<Result<U, E>>;
29
- static orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
30
- static orElseAsync<T, E, F>(result: Result<T, E>, fn: (error: E) => Promise<Result<T, F>>): Promise<Result<T, F>>;
31
- static unwrap<T, E>(result: Result<T, E>): T | undefined;
32
- static unwrapSuccess<T>(result: Success<T>): T;
33
- static unwrapFailure<E>(result: Failure<E>): E;
34
- static unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
35
- static unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
36
- static unwrapOrElseAsync<T, E>(result: Result<T, E>, fn: (error: E) => Promise<T>): Promise<T>;
37
- static match<T, E, U>(result: Result<T, E>, handlers: {
38
- onSuccess: (value: T) => U;
39
- onFailure: (error: E) => U;
40
- }): U;
41
- static matchAsync<T, E, U>(result: Result<T, E>, handlers: {
42
- onSuccess: (value: T) => Promise<U>;
43
- onFailure: (error: E) => Promise<U>;
44
- }): Promise<U>;
45
- static tap<T, E>(result: Result<T, E>, handlers: {
46
- onSuccess?: (value: T) => void;
47
- onFailure?: (error: E) => void;
48
- }): Result<T, E>;
49
- static tapAsync<T, E>(result: Result<T, E>, handlers: {
50
- onSuccess?: (value: T) => Promise<void>;
51
- onFailure?: (error: E) => Promise<void>;
52
- }): Promise<Result<T, E>>;
53
- static combine<T, E>(results: Result<T, E>[]): Result<T[], E>;
54
- static combineAsync<T, E>(results: Promise<Result<T, E>>[]): Promise<Result<T[], E>>;
55
- static combineWithAllErrors<T, E>(results: Result<T, E>[]): Result<T[], E[]>;
56
- static combineWithAllErrorsAsync<T, E>(results: Promise<Result<T, E>>[]): Promise<Result<T[], E[]>>;
57
- static flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E>;
58
- static fromPromise<T, E>(promise: Promise<T>, errorFn: (error: unknown) => E): Promise<Result<T, E>>;
59
- static fromThrowable<Args extends unknown[], T, E>(fn: (...args: Args) => T, errorFn: (error: unknown) => E): (...args: Args) => Result<T, E>;
60
- static fromThrowableAsync<Args extends unknown[], T, E>(fn: (...args: Args) => Promise<T>, errorFn: (error: unknown) => E): (...args: Args) => Promise<Result<T, E>>;
61
- static fromNullable<T, E>(value: T | null | undefined, error: E): Result<NonNullable<T>, E>;
62
- static fromPredicate<T, E>(value: T, predicate: (value: T) => boolean, error: E): Result<T, E>;
63
- static toNullable<T, E>(result: Result<T, E>): T | null;
64
- static partition<T, E>(results: Result<T, E>[]): [T[], E[]];
65
- static filterSuccesses<T, E>(results: Result<T, E>[]): T[];
66
- static filterFailures<T, E>(results: Result<T, E>[]): E[];
67
- }
68
- //#endregion
69
- export { isTypedError as a, TypedErrorUnion as i, TypedError as n, TypedErrorOf as r, ResultKit as t };
70
- //# sourceMappingURL=index-EJ_Ol5Fu.d.cts.map
package/dist/index.cjs DELETED
@@ -1,5 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_result_kit = require("./result-kit-Ck1xAp-J.cjs");
3
- require("./core/index.cjs");
4
- exports.ResultKit = require_result_kit.ResultKit;
5
- exports.isTypedError = require_result_kit.isTypedError;
package/dist/index.d.cts DELETED
@@ -1,3 +0,0 @@
1
- import { a as isTypedError, i as TypedErrorUnion, n as TypedError, r as TypedErrorOf, t as ResultKit } from "./index-EJ_Ol5Fu.cjs";
2
- import { n as Result, r as Success, t as Failure } from "./result-DbQ8o1Cs.cjs";
3
- export { Failure, Result, ResultKit, Success, TypedError, TypedErrorOf, TypedErrorUnion, isTypedError };
package/dist/index.d.mts DELETED
@@ -1,3 +0,0 @@
1
- import { a as isTypedError, i as TypedErrorUnion, n as TypedError, r as TypedErrorOf, t as ResultKit } from "./index-Ch6k0lVU.mjs";
2
- import { n as Result, r as Success, t as Failure } from "./result-CI_HBDHK.mjs";
3
- export { Failure, Result, ResultKit, Success, TypedError, TypedErrorOf, TypedErrorUnion, isTypedError };
package/dist/index.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { n as isTypedError, t as ResultKit } from "./result-kit-C5ZY61pO.mjs";
2
- import "./core/index.mjs";
3
- export { ResultKit, isTypedError };
@@ -1,46 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_result_kit = require("../result-kit-Ck1xAp-J.cjs");
3
- let _nestjs_common = require("@nestjs/common");
4
- //#region src/nest/http.ts
5
- const DEFAULT_UNKNOWN_MESSAGE = "An unknown error occurred";
6
- const DEFAULT_ERROR_CODE = "INTERNAL_SERVER_ERROR";
7
- const normalizeErrorCode = (value) => value.trim().replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase() || DEFAULT_ERROR_CODE;
8
- const toHttpExceptionFromDescriptor = (descriptor) => {
9
- const status = descriptor.status ?? _nestjs_common.HttpStatus.INTERNAL_SERVER_ERROR;
10
- return new _nestjs_common.HttpException({
11
- code: descriptor.code ?? (status === _nestjs_common.HttpStatus.INTERNAL_SERVER_ERROR ? DEFAULT_ERROR_CODE : String(status)),
12
- message: descriptor.message ?? DEFAULT_UNKNOWN_MESSAGE,
13
- ...descriptor.details ? { details: descriptor.details } : {},
14
- ...descriptor.error ? { error: descriptor.error } : {}
15
- }, status);
16
- };
17
- const toHttpException = (error, options) => {
18
- const mapped = options?.mapError?.(error);
19
- if (mapped instanceof _nestjs_common.HttpException) return mapped;
20
- if (mapped) return toHttpExceptionFromDescriptor(mapped);
21
- if (error instanceof _nestjs_common.HttpException) return error;
22
- if (require_result_kit.isTypedError(error)) return new _nestjs_common.InternalServerErrorException({
23
- code: normalizeErrorCode(error.type),
24
- message: error.message,
25
- ...error.details ? { details: error.details } : {}
26
- });
27
- if (error instanceof Error) return new _nestjs_common.InternalServerErrorException({
28
- code: DEFAULT_ERROR_CODE,
29
- message: error.message || options?.fallbackMessage || DEFAULT_UNKNOWN_MESSAGE
30
- });
31
- return new _nestjs_common.InternalServerErrorException({
32
- code: DEFAULT_ERROR_CODE,
33
- message: options?.fallbackMessage || DEFAULT_UNKNOWN_MESSAGE
34
- });
35
- };
36
- const unwrapOrThrow = (result, options) => {
37
- if (require_result_kit.ResultKit.isSuccess(result)) return result.value;
38
- throw toHttpException(result.error, options);
39
- };
40
- const unwrapPromise = async (promise, options) => unwrapOrThrow(await promise, options);
41
- //#endregion
42
- exports.toHttpException = toHttpException;
43
- exports.unwrapOrThrow = unwrapOrThrow;
44
- exports.unwrapPromise = unwrapPromise;
45
-
46
- //# sourceMappingURL=index.cjs.map
@@ -1,21 +0,0 @@
1
- import { n as Result } from "../result-DbQ8o1Cs.cjs";
2
- import { HttpException } from "@nestjs/common";
3
-
4
- //#region src/nest/http.d.ts
5
- interface HttpExceptionDescriptor {
6
- readonly status?: number;
7
- readonly code?: string | number;
8
- readonly message?: string;
9
- readonly details?: Record<string, unknown>;
10
- readonly error?: string;
11
- }
12
- interface NestErrorOptions<E> {
13
- readonly mapError?: (error: E) => HttpException | HttpExceptionDescriptor | undefined;
14
- readonly fallbackMessage?: string;
15
- }
16
- declare const toHttpException: <E>(error: E, options?: NestErrorOptions<E>) => HttpException;
17
- declare const unwrapOrThrow: <T, E>(result: Result<T, E>, options?: NestErrorOptions<E>) => T;
18
- declare const unwrapPromise: <T, E>(promise: Promise<Result<T, E>>, options?: NestErrorOptions<E>) => Promise<T>;
19
- //#endregion
20
- export { type HttpExceptionDescriptor, type NestErrorOptions, toHttpException, unwrapOrThrow, unwrapPromise };
21
- //# sourceMappingURL=index.d.cts.map
@@ -1,21 +0,0 @@
1
- import { n as Result } from "../result-CI_HBDHK.mjs";
2
- import { HttpException } from "@nestjs/common";
3
-
4
- //#region src/nest/http.d.ts
5
- interface HttpExceptionDescriptor {
6
- readonly status?: number;
7
- readonly code?: string | number;
8
- readonly message?: string;
9
- readonly details?: Record<string, unknown>;
10
- readonly error?: string;
11
- }
12
- interface NestErrorOptions<E> {
13
- readonly mapError?: (error: E) => HttpException | HttpExceptionDescriptor | undefined;
14
- readonly fallbackMessage?: string;
15
- }
16
- declare const toHttpException: <E>(error: E, options?: NestErrorOptions<E>) => HttpException;
17
- declare const unwrapOrThrow: <T, E>(result: Result<T, E>, options?: NestErrorOptions<E>) => T;
18
- declare const unwrapPromise: <T, E>(promise: Promise<Result<T, E>>, options?: NestErrorOptions<E>) => Promise<T>;
19
- //#endregion
20
- export { type HttpExceptionDescriptor, type NestErrorOptions, toHttpException, unwrapOrThrow, unwrapPromise };
21
- //# sourceMappingURL=index.d.mts.map
@@ -1,43 +0,0 @@
1
- import { n as isTypedError, t as ResultKit } from "../result-kit-C5ZY61pO.mjs";
2
- import { HttpException, HttpStatus, InternalServerErrorException } from "@nestjs/common";
3
- //#region src/nest/http.ts
4
- const DEFAULT_UNKNOWN_MESSAGE = "An unknown error occurred";
5
- const DEFAULT_ERROR_CODE = "INTERNAL_SERVER_ERROR";
6
- const normalizeErrorCode = (value) => value.trim().replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase() || DEFAULT_ERROR_CODE;
7
- const toHttpExceptionFromDescriptor = (descriptor) => {
8
- const status = descriptor.status ?? HttpStatus.INTERNAL_SERVER_ERROR;
9
- return new HttpException({
10
- code: descriptor.code ?? (status === HttpStatus.INTERNAL_SERVER_ERROR ? DEFAULT_ERROR_CODE : String(status)),
11
- message: descriptor.message ?? DEFAULT_UNKNOWN_MESSAGE,
12
- ...descriptor.details ? { details: descriptor.details } : {},
13
- ...descriptor.error ? { error: descriptor.error } : {}
14
- }, status);
15
- };
16
- const toHttpException = (error, options) => {
17
- const mapped = options?.mapError?.(error);
18
- if (mapped instanceof HttpException) return mapped;
19
- if (mapped) return toHttpExceptionFromDescriptor(mapped);
20
- if (error instanceof HttpException) return error;
21
- if (isTypedError(error)) return new InternalServerErrorException({
22
- code: normalizeErrorCode(error.type),
23
- message: error.message,
24
- ...error.details ? { details: error.details } : {}
25
- });
26
- if (error instanceof Error) return new InternalServerErrorException({
27
- code: DEFAULT_ERROR_CODE,
28
- message: error.message || options?.fallbackMessage || DEFAULT_UNKNOWN_MESSAGE
29
- });
30
- return new InternalServerErrorException({
31
- code: DEFAULT_ERROR_CODE,
32
- message: options?.fallbackMessage || DEFAULT_UNKNOWN_MESSAGE
33
- });
34
- };
35
- const unwrapOrThrow = (result, options) => {
36
- if (ResultKit.isSuccess(result)) return result.value;
37
- throw toHttpException(result.error, options);
38
- };
39
- const unwrapPromise = async (promise, options) => unwrapOrThrow(await promise, options);
40
- //#endregion
41
- export { toHttpException, unwrapOrThrow, unwrapPromise };
42
-
43
- //# sourceMappingURL=index.mjs.map
@@ -1,13 +0,0 @@
1
- //#region src/core/result.d.ts
2
- interface Success<T> {
3
- readonly ok: true;
4
- readonly value: T;
5
- }
6
- interface Failure<E> {
7
- readonly ok: false;
8
- readonly error: E;
9
- }
10
- type Result<T, E> = Success<T> | Failure<E>;
11
- //#endregion
12
- export { Result as n, Success as r, Failure as t };
13
- //# sourceMappingURL=result-CI_HBDHK.d.mts.map
@@ -1,13 +0,0 @@
1
- //#region src/core/result.d.ts
2
- interface Success<T> {
3
- readonly ok: true;
4
- readonly value: T;
5
- }
6
- interface Failure<E> {
7
- readonly ok: false;
8
- readonly error: E;
9
- }
10
- type Result<T, E> = Success<T> | Failure<E>;
11
- //#endregion
12
- export { Result as n, Success as r, Failure as t };
13
- //# sourceMappingURL=result-DbQ8o1Cs.d.cts.map
@@ -1,172 +0,0 @@
1
- //#region src/core/error.ts
2
- const isTypedError = (error) => {
3
- if (!error || typeof error !== "object") return false;
4
- const candidate = error;
5
- if (typeof candidate.type !== "string" || typeof candidate.message !== "string") return false;
6
- if ("details" in candidate && candidate.details !== void 0 && (candidate.details === null || typeof candidate.details !== "object" || Array.isArray(candidate.details))) return false;
7
- return true;
8
- };
9
- //#endregion
10
- //#region src/core/result-kit.ts
11
- var ResultKit = class {
12
- static isSuccess(result) {
13
- return result.ok === true;
14
- }
15
- static isFailure(result) {
16
- return result.ok === false;
17
- }
18
- static success(value) {
19
- return {
20
- ok: true,
21
- value
22
- };
23
- }
24
- static failure(error) {
25
- return {
26
- ok: false,
27
- error
28
- };
29
- }
30
- static fail(error) {
31
- return this.failure(error);
32
- }
33
- static isTypedError(error) {
34
- return isTypedError(error);
35
- }
36
- static map(result, fn) {
37
- return this.isSuccess(result) ? this.success(fn(result.value)) : result;
38
- }
39
- static bimap(result, onSuccess, onFailure) {
40
- return this.isSuccess(result) ? this.success(onSuccess(result.value)) : this.failure(onFailure(result.error));
41
- }
42
- static async mapAsync(result, fn) {
43
- return this.isSuccess(result) ? this.success(await fn(result.value)) : result;
44
- }
45
- static mapError(result, fn) {
46
- return this.isFailure(result) ? this.failure(fn(result.error)) : result;
47
- }
48
- static async mapErrorAsync(result, fn) {
49
- return this.isFailure(result) ? this.failure(await fn(result.error)) : result;
50
- }
51
- static andThen(result, fn) {
52
- return this.isSuccess(result) ? fn(result.value) : result;
53
- }
54
- static async andThenAsync(result, fn) {
55
- return this.isSuccess(result) ? fn(result.value) : result;
56
- }
57
- static orElse(result, fn) {
58
- return this.isFailure(result) ? fn(result.error) : result;
59
- }
60
- static async orElseAsync(result, fn) {
61
- return this.isFailure(result) ? fn(result.error) : result;
62
- }
63
- static unwrap(result) {
64
- return this.isSuccess(result) ? result.value : void 0;
65
- }
66
- static unwrapSuccess(result) {
67
- return result.value;
68
- }
69
- static unwrapFailure(result) {
70
- return result.error;
71
- }
72
- static unwrapOr(result, defaultValue) {
73
- return this.isSuccess(result) ? result.value : defaultValue;
74
- }
75
- static unwrapOrElse(result, fn) {
76
- return this.isSuccess(result) ? result.value : fn(result.error);
77
- }
78
- static async unwrapOrElseAsync(result, fn) {
79
- return this.isSuccess(result) ? result.value : fn(result.error);
80
- }
81
- static match(result, handlers) {
82
- return this.isSuccess(result) ? handlers.onSuccess(result.value) : handlers.onFailure(result.error);
83
- }
84
- static async matchAsync(result, handlers) {
85
- return this.isSuccess(result) ? handlers.onSuccess(result.value) : handlers.onFailure(result.error);
86
- }
87
- static tap(result, handlers) {
88
- if (this.isSuccess(result)) handlers.onSuccess?.(result.value);
89
- else handlers.onFailure?.(result.error);
90
- return result;
91
- }
92
- static async tapAsync(result, handlers) {
93
- if (this.isSuccess(result)) await handlers.onSuccess?.(result.value);
94
- else await handlers.onFailure?.(result.error);
95
- return result;
96
- }
97
- static combine(results) {
98
- const values = [];
99
- for (const result of results) {
100
- if (this.isFailure(result)) return result;
101
- values.push(result.value);
102
- }
103
- return this.success(values);
104
- }
105
- static async combineAsync(results) {
106
- return this.combine(await Promise.all(results));
107
- }
108
- static combineWithAllErrors(results) {
109
- const values = [];
110
- const errors = [];
111
- for (const result of results) if (this.isSuccess(result)) values.push(result.value);
112
- else errors.push(result.error);
113
- return errors.length > 0 ? this.failure(errors) : this.success(values);
114
- }
115
- static async combineWithAllErrorsAsync(results) {
116
- return this.combineWithAllErrors(await Promise.all(results));
117
- }
118
- static flatten(result) {
119
- return this.isSuccess(result) ? result.value : result;
120
- }
121
- static async fromPromise(promise, errorFn) {
122
- try {
123
- return this.success(await promise);
124
- } catch (error) {
125
- return this.failure(errorFn(error));
126
- }
127
- }
128
- static fromThrowable(fn, errorFn) {
129
- return (...args) => {
130
- try {
131
- return this.success(fn(...args));
132
- } catch (error) {
133
- return this.failure(errorFn(error));
134
- }
135
- };
136
- }
137
- static fromThrowableAsync(fn, errorFn) {
138
- return async (...args) => {
139
- try {
140
- return this.success(await fn(...args));
141
- } catch (error) {
142
- return this.failure(errorFn(error));
143
- }
144
- };
145
- }
146
- static fromNullable(value, error) {
147
- return value == null ? this.failure(error) : this.success(value);
148
- }
149
- static fromPredicate(value, predicate, error) {
150
- return predicate(value) ? this.success(value) : this.failure(error);
151
- }
152
- static toNullable(result) {
153
- return this.isSuccess(result) ? result.value : null;
154
- }
155
- static partition(results) {
156
- const values = [];
157
- const errors = [];
158
- for (const result of results) if (this.isSuccess(result)) values.push(result.value);
159
- else errors.push(result.error);
160
- return [values, errors];
161
- }
162
- static filterSuccesses(results) {
163
- return results.filter((result) => this.isSuccess(result)).map((result) => result.value);
164
- }
165
- static filterFailures(results) {
166
- return results.filter((result) => this.isFailure(result)).map((result) => result.error);
167
- }
168
- };
169
- //#endregion
170
- export { isTypedError as n, ResultKit as t };
171
-
172
- //# sourceMappingURL=result-kit-C5ZY61pO.mjs.map
@@ -1,183 +0,0 @@
1
- //#region src/core/error.ts
2
- const isTypedError = (error) => {
3
- if (!error || typeof error !== "object") return false;
4
- const candidate = error;
5
- if (typeof candidate.type !== "string" || typeof candidate.message !== "string") return false;
6
- if ("details" in candidate && candidate.details !== void 0 && (candidate.details === null || typeof candidate.details !== "object" || Array.isArray(candidate.details))) return false;
7
- return true;
8
- };
9
- //#endregion
10
- //#region src/core/result-kit.ts
11
- var ResultKit = class {
12
- static isSuccess(result) {
13
- return result.ok === true;
14
- }
15
- static isFailure(result) {
16
- return result.ok === false;
17
- }
18
- static success(value) {
19
- return {
20
- ok: true,
21
- value
22
- };
23
- }
24
- static failure(error) {
25
- return {
26
- ok: false,
27
- error
28
- };
29
- }
30
- static fail(error) {
31
- return this.failure(error);
32
- }
33
- static isTypedError(error) {
34
- return isTypedError(error);
35
- }
36
- static map(result, fn) {
37
- return this.isSuccess(result) ? this.success(fn(result.value)) : result;
38
- }
39
- static bimap(result, onSuccess, onFailure) {
40
- return this.isSuccess(result) ? this.success(onSuccess(result.value)) : this.failure(onFailure(result.error));
41
- }
42
- static async mapAsync(result, fn) {
43
- return this.isSuccess(result) ? this.success(await fn(result.value)) : result;
44
- }
45
- static mapError(result, fn) {
46
- return this.isFailure(result) ? this.failure(fn(result.error)) : result;
47
- }
48
- static async mapErrorAsync(result, fn) {
49
- return this.isFailure(result) ? this.failure(await fn(result.error)) : result;
50
- }
51
- static andThen(result, fn) {
52
- return this.isSuccess(result) ? fn(result.value) : result;
53
- }
54
- static async andThenAsync(result, fn) {
55
- return this.isSuccess(result) ? fn(result.value) : result;
56
- }
57
- static orElse(result, fn) {
58
- return this.isFailure(result) ? fn(result.error) : result;
59
- }
60
- static async orElseAsync(result, fn) {
61
- return this.isFailure(result) ? fn(result.error) : result;
62
- }
63
- static unwrap(result) {
64
- return this.isSuccess(result) ? result.value : void 0;
65
- }
66
- static unwrapSuccess(result) {
67
- return result.value;
68
- }
69
- static unwrapFailure(result) {
70
- return result.error;
71
- }
72
- static unwrapOr(result, defaultValue) {
73
- return this.isSuccess(result) ? result.value : defaultValue;
74
- }
75
- static unwrapOrElse(result, fn) {
76
- return this.isSuccess(result) ? result.value : fn(result.error);
77
- }
78
- static async unwrapOrElseAsync(result, fn) {
79
- return this.isSuccess(result) ? result.value : fn(result.error);
80
- }
81
- static match(result, handlers) {
82
- return this.isSuccess(result) ? handlers.onSuccess(result.value) : handlers.onFailure(result.error);
83
- }
84
- static async matchAsync(result, handlers) {
85
- return this.isSuccess(result) ? handlers.onSuccess(result.value) : handlers.onFailure(result.error);
86
- }
87
- static tap(result, handlers) {
88
- if (this.isSuccess(result)) handlers.onSuccess?.(result.value);
89
- else handlers.onFailure?.(result.error);
90
- return result;
91
- }
92
- static async tapAsync(result, handlers) {
93
- if (this.isSuccess(result)) await handlers.onSuccess?.(result.value);
94
- else await handlers.onFailure?.(result.error);
95
- return result;
96
- }
97
- static combine(results) {
98
- const values = [];
99
- for (const result of results) {
100
- if (this.isFailure(result)) return result;
101
- values.push(result.value);
102
- }
103
- return this.success(values);
104
- }
105
- static async combineAsync(results) {
106
- return this.combine(await Promise.all(results));
107
- }
108
- static combineWithAllErrors(results) {
109
- const values = [];
110
- const errors = [];
111
- for (const result of results) if (this.isSuccess(result)) values.push(result.value);
112
- else errors.push(result.error);
113
- return errors.length > 0 ? this.failure(errors) : this.success(values);
114
- }
115
- static async combineWithAllErrorsAsync(results) {
116
- return this.combineWithAllErrors(await Promise.all(results));
117
- }
118
- static flatten(result) {
119
- return this.isSuccess(result) ? result.value : result;
120
- }
121
- static async fromPromise(promise, errorFn) {
122
- try {
123
- return this.success(await promise);
124
- } catch (error) {
125
- return this.failure(errorFn(error));
126
- }
127
- }
128
- static fromThrowable(fn, errorFn) {
129
- return (...args) => {
130
- try {
131
- return this.success(fn(...args));
132
- } catch (error) {
133
- return this.failure(errorFn(error));
134
- }
135
- };
136
- }
137
- static fromThrowableAsync(fn, errorFn) {
138
- return async (...args) => {
139
- try {
140
- return this.success(await fn(...args));
141
- } catch (error) {
142
- return this.failure(errorFn(error));
143
- }
144
- };
145
- }
146
- static fromNullable(value, error) {
147
- return value == null ? this.failure(error) : this.success(value);
148
- }
149
- static fromPredicate(value, predicate, error) {
150
- return predicate(value) ? this.success(value) : this.failure(error);
151
- }
152
- static toNullable(result) {
153
- return this.isSuccess(result) ? result.value : null;
154
- }
155
- static partition(results) {
156
- const values = [];
157
- const errors = [];
158
- for (const result of results) if (this.isSuccess(result)) values.push(result.value);
159
- else errors.push(result.error);
160
- return [values, errors];
161
- }
162
- static filterSuccesses(results) {
163
- return results.filter((result) => this.isSuccess(result)).map((result) => result.value);
164
- }
165
- static filterFailures(results) {
166
- return results.filter((result) => this.isFailure(result)).map((result) => result.error);
167
- }
168
- };
169
- //#endregion
170
- Object.defineProperty(exports, "ResultKit", {
171
- enumerable: true,
172
- get: function() {
173
- return ResultKit;
174
- }
175
- });
176
- Object.defineProperty(exports, "isTypedError", {
177
- enumerable: true,
178
- get: function() {
179
- return isTypedError;
180
- }
181
- });
182
-
183
- //# sourceMappingURL=result-kit-Ck1xAp-J.cjs.map