@resultsafe/core-fp-result 0.2.0 → 0.2.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/README.md +38 -0
- package/cjs/constructors/Err.js.map +1 -1
- package/cjs/constructors/Ok.js.map +1 -1
- package/cjs/guards/isErr.js.map +1 -1
- package/cjs/guards/isErrAnd.js.map +1 -1
- package/cjs/guards/isOk.js.map +1 -1
- package/cjs/guards/isOkAnd.js.map +1 -1
- package/cjs/methods/andThen.js.map +1 -1
- package/cjs/methods/err.js.map +1 -1
- package/cjs/methods/expect.js.map +1 -1
- package/cjs/methods/expectErr.js.map +1 -1
- package/cjs/methods/flatten.js.map +1 -1
- package/cjs/methods/inspect.js.map +1 -1
- package/cjs/methods/inspectErr.js.map +1 -1
- package/cjs/methods/map.js.map +1 -1
- package/cjs/methods/mapErr.js.map +1 -1
- package/cjs/methods/match.js.map +1 -1
- package/cjs/methods/ok.js.map +1 -1
- package/cjs/methods/orElse.js.map +1 -1
- package/cjs/methods/tap.js.map +1 -1
- package/cjs/methods/tapErr.js.map +1 -1
- package/cjs/methods/transpose.js.map +1 -1
- package/cjs/methods/unwrap.js.map +1 -1
- package/cjs/methods/unwrapErr.js.map +1 -1
- package/cjs/methods/unwrapOr.js.map +1 -1
- package/cjs/methods/unwrapOrElse.js.map +1 -1
- package/cjs/refiners/isTypedVariant.js.map +1 -1
- package/cjs/refiners/isTypedVariantOf.js.map +1 -1
- package/cjs/refiners/matchVariant.js.map +1 -1
- package/cjs/refiners/matchVariantStrict.js.map +1 -1
- package/cjs/refiners/refineAsyncResult.js.map +1 -1
- package/cjs/refiners/refineAsyncResultU.js.map +1 -1
- package/cjs/refiners/refineResult.js.map +1 -1
- package/cjs/refiners/refineResultU.js.map +1 -1
- package/cjs/refiners/refineVariantMap.js.map +1 -1
- package/cjs/refiners/utils/getPayloadKeys.js.map +1 -1
- package/esm/constructors/Err.js.map +1 -1
- package/esm/constructors/Ok.js.map +1 -1
- package/esm/guards/isErr.js.map +1 -1
- package/esm/guards/isErrAnd.js.map +1 -1
- package/esm/guards/isOk.js.map +1 -1
- package/esm/guards/isOkAnd.js.map +1 -1
- package/esm/methods/andThen.js.map +1 -1
- package/esm/methods/err.js.map +1 -1
- package/esm/methods/expect.js.map +1 -1
- package/esm/methods/expectErr.js.map +1 -1
- package/esm/methods/flatten.js.map +1 -1
- package/esm/methods/inspect.js.map +1 -1
- package/esm/methods/inspectErr.js.map +1 -1
- package/esm/methods/map.js.map +1 -1
- package/esm/methods/mapErr.js.map +1 -1
- package/esm/methods/match.js.map +1 -1
- package/esm/methods/ok.js.map +1 -1
- package/esm/methods/orElse.js.map +1 -1
- package/esm/methods/tap.js.map +1 -1
- package/esm/methods/tapErr.js.map +1 -1
- package/esm/methods/transpose.js.map +1 -1
- package/esm/methods/unwrap.js.map +1 -1
- package/esm/methods/unwrapErr.js.map +1 -1
- package/esm/methods/unwrapOr.js.map +1 -1
- package/esm/methods/unwrapOrElse.js.map +1 -1
- package/esm/refiners/isTypedVariant.js.map +1 -1
- package/esm/refiners/isTypedVariantOf.js.map +1 -1
- package/esm/refiners/matchVariant.js.map +1 -1
- package/esm/refiners/matchVariantStrict.js.map +1 -1
- package/esm/refiners/refineAsyncResult.js.map +1 -1
- package/esm/refiners/refineAsyncResultU.js.map +1 -1
- package/esm/refiners/refineResult.js.map +1 -1
- package/esm/refiners/refineResultU.js.map +1 -1
- package/esm/refiners/refineVariantMap.js.map +1 -1
- package/esm/refiners/utils/getPayloadKeys.js.map +1 -1
- package/package.json +1 -1
- package/types/constructors/Err.d.ts +4 -4
- package/types/constructors/Err.d.ts.map +1 -1
- package/types/constructors/Ok.d.ts +4 -4
- package/types/constructors/Ok.d.ts.map +1 -1
- package/types/guards/isErr.d.ts +5 -5
- package/types/guards/isErr.d.ts.map +1 -1
- package/types/guards/isErrAnd.d.ts +6 -6
- package/types/guards/isErrAnd.d.ts.map +1 -1
- package/types/guards/isOk.d.ts +5 -5
- package/types/guards/isOk.d.ts.map +1 -1
- package/types/guards/isOkAnd.d.ts +6 -6
- package/types/guards/isOkAnd.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/methods/andThen.d.ts +7 -7
- package/types/methods/andThen.d.ts.map +1 -1
- package/types/methods/err.d.ts +7 -8
- package/types/methods/err.d.ts.map +1 -1
- package/types/methods/expect.d.ts +9 -9
- package/types/methods/expect.d.ts.map +1 -1
- package/types/methods/expectErr.d.ts +9 -9
- package/types/methods/expectErr.d.ts.map +1 -1
- package/types/methods/flatten.d.ts +3 -3
- package/types/methods/flatten.d.ts.map +1 -1
- package/types/methods/inspect.d.ts +8 -8
- package/types/methods/inspect.d.ts.map +1 -1
- package/types/methods/inspectErr.d.ts +8 -8
- package/types/methods/inspectErr.d.ts.map +1 -1
- package/types/methods/map.d.ts +9 -9
- package/types/methods/map.d.ts.map +1 -1
- package/types/methods/mapErr.d.ts +8 -8
- package/types/methods/mapErr.d.ts.map +1 -1
- package/types/methods/match.d.ts +8 -8
- package/types/methods/match.d.ts.map +1 -1
- package/types/methods/ok.d.ts +7 -8
- package/types/methods/ok.d.ts.map +1 -1
- package/types/methods/orElse.d.ts +9 -9
- package/types/methods/orElse.d.ts.map +1 -1
- package/types/methods/tap.d.ts +7 -7
- package/types/methods/tap.d.ts.map +1 -1
- package/types/methods/tapErr.d.ts +7 -7
- package/types/methods/tapErr.d.ts.map +1 -1
- package/types/methods/transpose.d.ts +5 -6
- package/types/methods/transpose.d.ts.map +1 -1
- package/types/methods/unwrap.d.ts +8 -8
- package/types/methods/unwrap.d.ts.map +1 -1
- package/types/methods/unwrapErr.d.ts +8 -8
- package/types/methods/unwrapErr.d.ts.map +1 -1
- package/types/methods/unwrapOr.d.ts +8 -8
- package/types/methods/unwrapOr.d.ts.map +1 -1
- package/types/methods/unwrapOrElse.d.ts +8 -8
- package/types/methods/unwrapOrElse.d.ts.map +1 -1
- package/types/refiners/isTypedVariant.d.ts +3 -3
- package/types/refiners/isTypedVariantOf.d.ts +3 -3
- package/types/refiners/matchVariant.d.ts +5 -5
- package/types/refiners/matchVariantStrict.d.ts +6 -6
- package/types/refiners/refineAsyncResult.d.ts +17 -15
- package/types/refiners/refineAsyncResult.d.ts.map +1 -1
- package/types/refiners/refineAsyncResultU.d.ts +13 -11
- package/types/refiners/refineAsyncResultU.d.ts.map +1 -1
- package/types/refiners/refineResult.d.ts +18 -16
- package/types/refiners/refineResult.d.ts.map +1 -1
- package/types/refiners/refineResultU.d.ts +13 -11
- package/types/refiners/refineResultU.d.ts.map +1 -1
- package/types/refiners/refineVariantMap.d.ts +8 -8
- package/types/refiners/refineVariantMap.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResult.d.ts +3 -1
- package/types/refiners/types/SyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts +1 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts.map +1 -1
- package/types/refiners/types/SyncValidatorMap.d.ts +3 -1
- package/types/refiners/types/SyncValidatorMap.d.ts.map +1 -1
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts +1 -1
- package/types/refiners/types/UniversalAsyncRefinedResult.d.ts.map +1 -1
- package/types/refiners/types/UniversalRefinedResult.d.ts +1 -1
- package/types/refiners/types/UniversalRefinedResult.d.ts.map +1 -1
- package/types/refiners/utils/getPayloadKeys.d.ts +6 -5
- package/types/refiners/utils/getPayloadKeys.d.ts.map +1 -1
- package/types/types/core/index.d.ts +3 -0
- package/types/types/core/index.d.ts.map +1 -0
- package/types/types/index.d.ts +1 -2
- package/types/types/index.d.ts.map +1 -1
- package/umd/resultsafe-monorepo-core-fp-result.umd.js.map +1 -1
- package/types/shared-types.d.ts +0 -164
- package/types/shared-types.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErrAnd.js","sources":["../../../src/guards/isErrAnd.ts"],"sourcesContent":["import { type Result } from '../
|
|
1
|
+
{"version":3,"file":"isErrAnd.js","sources":["../../../src/guards/isErrAnd.ts"],"sourcesContent":["import { type Result } from '../types/core/index.js';\nimport { isErr } from './isErr.js';\n\n/**\n * Checks that the `Result` resulted in an error and satisfies the predicate.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The `Result` to check.\n * @param predicate - The predicate applied to the error value.\n * @returns `true` when the value is `Err` and the predicate returns `true`.\n * @since 0.1.0\n * @see {@link isErr} - Performs the base error check.\n * @example\n * ```ts\n * import { Err, isErrAnd } from '@resultsafe/core-fp-result';\n *\n * const result = Err({ code: 503 });\n * console.log(isErrAnd(result, (error) => error.code >= 500)); // true\n * ```\n * @public\n */\nexport const isErrAnd = <T, E>(\n result: Result<T, E>,\n predicate: (error: E) => boolean,\n): boolean => isErr(result) && predicate(result.error);\n"],"names":[],"mappings":";;;AAsBO,MAAM,WAAW,wBACtB,QACA,cACY,MAAM,MAAM,KAAK,UAAU,OAAO,KAAK,GAH7B;"}
|
package/esm/guards/isOk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOk.js","sources":["../../../src/guards/isOk.ts"],"sourcesContent":["import type { Result } from '../
|
|
1
|
+
{"version":3,"file":"isOk.js","sources":["../../../src/guards/isOk.ts"],"sourcesContent":["import type { Result } from '../types/core/index.js';\n\n/**\n * Checks whether a `Result` is in the success branch.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The `Result` to check.\n * @returns `true` when `result.ok` equals `true`.\n * @since 0.1.0\n * @see {@link isErr} - Checks the error branch.\n * @example\n * ```ts\n * import { Ok, isOk } from '@resultsafe/core-fp-result';\n *\n * const result = Ok(10);\n * console.log(isOk(result)); // true\n * ```\n * @public\n */\nexport const isOk = <T, E>(\n result: Result<T, E>,\n): result is { ok: true; value: T } => result.ok === true;\n"],"names":[],"mappings":";;AAoBO,MAAM,OAAO,wBAClB,WACqC,OAAO,OAAO,MAFjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOkAnd.js","sources":["../../../src/guards/isOkAnd.ts"],"sourcesContent":["import { type Result } from '../
|
|
1
|
+
{"version":3,"file":"isOkAnd.js","sources":["../../../src/guards/isOkAnd.ts"],"sourcesContent":["import { type Result } from '../types/core/index.js';\nimport { isOk } from './isOk.js';\n\n/**\n * Checks that the `Result` is successful and satisfies the predicate.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The `Result` to check.\n * @param predicate - The predicate applied to the success value.\n * @returns `true` when the value is `Ok` and the predicate returns `true`.\n * @since 0.1.0\n * @see {@link isOk} - Performs the base success check.\n * @example\n * ```ts\n * import { Ok, isOkAnd } from '@resultsafe/core-fp-result';\n *\n * const result = Ok(8);\n * console.log(isOkAnd(result, (value) => value % 2 === 0)); // true\n * ```\n * @public\n */\nexport const isOkAnd = <T, E>(\n result: Result<T, E>,\n predicate: (value: T) => boolean,\n): boolean => isOk(result) && predicate(result.value);\n"],"names":[],"mappings":";;;AAsBO,MAAM,UAAU,wBACrB,QACA,cACY,KAAK,MAAM,KAAK,UAAU,OAAO,KAAK,GAH7B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"andThen.js","sources":["../../../src/methods/andThen.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"andThen.js","sources":["../../../src/methods/andThen.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Chains a computation that returns another `Result`.\n *\n * @typeParam T - The input success type.\n * @typeParam U - The output success type.\n * @typeParam E - The shared error type.\n * @param result - The source `Result`.\n * @param fn - The function applied when `result` is `Ok`.\n * @returns The transformed `Result` or the original `Err`.\n * @since 0.1.0\n * @see {@link map} - Transforms only the success value.\n * @example\n * ```ts\n * import { Ok, Err, andThen } from '@resultsafe/core-fp-result';\n *\n * const parsed = andThen(Ok('12'), (value) => {\n * const n = Number(value);\n * return Number.isNaN(n) ? Err('invalid') : Ok(n);\n * });\n * console.log(parsed.ok); // true\n * ```\n * @public\n */\nexport const andThen = <T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => Result<U, E>,\n): Result<U, E> => (isOk(result) ? fn(result.value) : (result as Result<U, E>));\n"],"names":[],"mappings":";;;AA0BO,MAAM,UAAU,wBACrB,QACA,OACkB,KAAK,MAAM,IAAI,GAAG,OAAO,KAAK,IAAK,QAHhC;"}
|
package/esm/methods/err.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"err.js","sources":["../../../src/methods/err.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option
|
|
1
|
+
{"version":3,"file":"err.js","sources":["../../../src/methods/err.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option, type Result } from '../types/core/index.js';\n\n/**\n * Extracts the error branch as an `Option`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @returns `Some(error)` for `Err`, otherwise `None`.\n * @since 0.1.0\n * @see {@link ok} - Extracts the success branch.\n * @example\n * ```ts\n * import { Err, err } from '@resultsafe/core-fp-result';\n *\n * const value = err(Err('boom'));\n * console.log(value.some); // true\n * ```\n * @public\n */\nexport const err = <T, E>(result: Result<T, E>): Option<E> =>\n isErr(result) ? Some(result.error) : None;\n"],"names":[],"mappings":";;;;AAsBO,MAAM,MAAM,wBAAO,WACxB,MAAM,MAAM,IAAI,KAAK,OAAO,KAAK,IAAI,MADpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sources":["../../../src/methods/expect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"expect.js","sources":["../../../src/methods/expect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Returns the success value or throws an exception with a custom message.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param msg - The error message used when `result` is `Err`.\n * @returns The unwrapped success value.\n * @throws Error - Throws an exception when `result` is `Err`.\n * @since 0.1.0\n * @see {@link expectErr} - Symmetric helper for the error branch.\n * @example\n * ```ts\n * import { Ok, expect } from '@resultsafe/core-fp-result';\n *\n * const value = expect(Ok(5), 'must be ok');\n * console.log(value); // 5\n * ```\n * @public\n */\nexport const expect = <T, E>(result: Result<T, E>, msg: string): T => {\n if (isOk(result)) {\n return result.value;\n }\n throw new Error(msg);\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBAAO,QAAsB,QAAmB;AACpE,MAAI,KAAK,MAAM,GAAG;AAChB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,GAAG;AACrB,GALsB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expectErr.js","sources":["../../../src/methods/expectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"expectErr.js","sources":["../../../src/methods/expectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Returns the error value or throws an exception with a custom message.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param msg - The error message used when `result` is `Ok`.\n * @returns The unwrapped error value.\n * @throws Error - Throws an exception when `result` is `Ok`.\n * @since 0.1.0\n * @see {@link expect} - Symmetric helper for the success branch.\n * @example\n * ```ts\n * import { Err, expectErr } from '@resultsafe/core-fp-result';\n *\n * const error = expectErr(Err('boom'), 'must be err');\n * console.log(error); // boom\n * ```\n * @public\n */\nexport const expectErr = <T, E>(result: Result<T, E>, msg: string): E => {\n if (isErr(result)) {\n return result.error;\n }\n throw new Error(msg);\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,YAAY,wBAAO,QAAsB,QAAmB;AACvE,MAAI,MAAM,MAAM,GAAG;AACjB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,GAAG;AACrB,GALyB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","sources":["../../../src/methods/flatten.ts"],"sourcesContent":["import { type Result } from '../
|
|
1
|
+
{"version":3,"file":"flatten.js","sources":["../../../src/methods/flatten.ts"],"sourcesContent":["import { type Result } from '../types/core/index.js';\n\n/**\n * Collapses a nested `Result<Result<T, E>, E>` one level.\n *\n * @typeParam T - The inner success value type.\n * @typeParam E - The shared error value type.\n * @param result - The nested `Result` to collapse.\n * @returns A single-layer `Result<T, E>`.\n * @since 0.1.0\n * @see {@link andThen} - Chains computations that already return `Result`.\n * @example\n * ```ts\n * import { Ok, flatten } from '@resultsafe/core-fp-result';\n *\n * const value = flatten(Ok(Ok(3)));\n * console.log(value.ok); // true\n * ```\n * @public\n */\nexport const flatten = <T, E>(result: Result<Result<T, E>, E>): Result<T, E> =>\n result.ok ? result.value : { ok: false, error: result.error };\n"],"names":[],"mappings":";;AAoBO,MAAM,UAAU,wBAAO,WAC5B,OAAO,KAAK,OAAO,QAAQ,EAAE,IAAI,OAAO,OAAO,OAAO,MAAA,GADjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","sources":["../../../src/methods/inspect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"inspect.js","sources":["../../../src/methods/inspect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Performs a side effect for the success value and returns the original `Result`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The side effect function for the success branch.\n * @returns The same `Result` instance.\n * @since 0.1.0\n * @see {@link tap} - Equivalent helper for the success branch.\n * @example\n * ```ts\n * import { Ok, inspect } from '@resultsafe/core-fp-result';\n *\n * const result = inspect(Ok(1), (value) => console.log(value)); // 1\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const inspect = <T, E>(\n result: Result<T, E>,\n fn: (value: T) => void,\n): Result<T, E> => {\n if (isOk(result)) {\n fn(result.value);\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,UAAU,wBACrB,QACA,OACiB;AACjB,MAAI,KAAK,MAAM,GAAG;AAChB,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GARuB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspectErr.js","sources":["../../../src/methods/inspectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"inspectErr.js","sources":["../../../src/methods/inspectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Performs a side effect for the error value and returns the original `Result`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The side effect function for the error branch.\n * @returns The same `Result` instance.\n * @since 0.1.0\n * @see {@link tapErr} - Equivalent helper for the error branch.\n * @example\n * ```ts\n * import { Err, inspectErr } from '@resultsafe/core-fp-result';\n *\n * const result = inspectErr(Err('boom'), (error) => console.log(error)); // boom\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const inspectErr = <T, E>(\n result: Result<T, E>,\n fn: (error: E) => void,\n): Result<T, E> => {\n if (isErr(result)) {\n fn(result.error);\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,aAAa,wBACxB,QACA,OACiB;AACjB,MAAI,MAAM,MAAM,GAAG;AACjB,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GAR0B;"}
|
package/esm/methods/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sources":["../../../src/methods/map.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"map.js","sources":["../../../src/methods/map.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Transforms the success value while preserving the error branch.\n *\n * @typeParam T - The input success value type.\n * @typeParam U - The output success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The transformation function for the success value.\n * @returns The transformed `Ok` or the original `Err`.\n * @since 0.1.0\n * @see {@link mapErr} - Transforms the error branch.\n * @example\n * ```ts\n * import { Ok, map } from '@resultsafe/core-fp-result';\n *\n * const result = map(Ok(2), (value) => value * 10);\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const map = <T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => U,\n): Result<U, E> =>\n isOk(result)\n ? { ok: true, value: fn(result.value) }\n : (result as Result<U, E>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,MAAM,wBACjB,QACA,OAEA,KAAK,MAAM,IACP,EAAE,IAAI,MAAM,OAAO,GAAG,OAAO,KAAK,MACjC,QANY;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapErr.js","sources":["../../../src/methods/mapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"mapErr.js","sources":["../../../src/methods/mapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Transforms the error value while preserving the success branch.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The input error value type.\n * @typeParam F - The output error value type.\n * @param result - The source `Result`.\n * @param fn - The transformation function for the error value.\n * @returns The transformed `Err` or the original `Ok`.\n * @since 0.1.0\n * @see {@link map} - Transforms the success branch.\n * @example\n * ```ts\n * import { Err, mapErr } from '@resultsafe/core-fp-result';\n *\n * const result = mapErr(Err('e1'), (error) => `mapped:${error}`);\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const mapErr = <T, E, F>(\n result: Result<T, E>,\n fn: (error: E) => F,\n): Result<T, F> =>\n isErr(result)\n ? { ok: false, error: fn(result.error) }\n : (result as Result<T, F>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBACpB,QACA,OAEA,MAAM,MAAM,IACR,EAAE,IAAI,OAAO,OAAO,GAAG,OAAO,KAAK,MAClC,QANe;"}
|
package/esm/methods/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sources":["../../../src/methods/match.ts"],"sourcesContent":["import { type Result } from '../
|
|
1
|
+
{"version":3,"file":"match.js","sources":["../../../src/methods/match.ts"],"sourcesContent":["import { type Result } from '../types/core/index.js';\n\n/**\n * Pattern matches the `Result` into a single output value.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @typeParam U - The output type returned by both handlers.\n * @param result - The source `Result`.\n * @param okFn - The handler for the success branch.\n * @param errFn - The handler for the error branch.\n * @returns The output value produced by the selected handler.\n * @since 0.1.0\n * @see {@link unwrapOrElse} - Similar shape with default fallback semantics.\n * @example\n * ```ts\n * import { Ok, match } from '@resultsafe/core-fp-result';\n *\n * const value = match(Ok(3), (x) => `ok:${x}`, (e) => `err:${e}`);\n * console.log(value); // ok:3\n * ```\n * @public\n */\nexport const match = <T, E, U>(\n result: Result<T, E>,\n okFn: (value: T) => U,\n errFn: (error: E) => U,\n): U => {\n if (result.ok) {\n return okFn(result.value);\n } else {\n const { error } = result;\n return errFn(error);\n }\n};\n"],"names":[],"mappings":";;AAuBO,MAAM,QAAQ,wBACnB,QACA,MACA,UACM;AACN,MAAI,OAAO,IAAI;AACb,WAAO,KAAK,OAAO,KAAK;AAAA,EAC1B,OAAO;AACL,UAAM,EAAE,UAAU;AAClB,WAAO,MAAM,KAAK;AAAA,EACpB;AACF,GAXqB;"}
|
package/esm/methods/ok.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ok.js","sources":["../../../src/methods/ok.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option
|
|
1
|
+
{"version":3,"file":"ok.js","sources":["../../../src/methods/ok.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option, type Result } from '../types/core/index.js';\n\n/**\n * Extracts the success branch as an `Option`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @returns `Some(value)` for `Ok`, otherwise `None`.\n * @since 0.1.0\n * @see {@link err} - Extracts the error branch.\n * @example\n * ```ts\n * import { Ok, ok } from '@resultsafe/core-fp-result';\n *\n * const value = ok(Ok(10));\n * console.log(value.some); // true\n * ```\n * @public\n */\nexport const ok = <T, E>(result: Result<T, E>): Option<T> =>\n isOk(result) ? Some(result.value) : None;\n"],"names":[],"mappings":";;;;AAsBO,MAAM,KAAK,wBAAO,WACvB,KAAK,MAAM,IAAI,KAAK,OAAO,KAAK,IAAI,MADpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orElse.js","sources":["../../../src/methods/orElse.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"orElse.js","sources":["../../../src/methods/orElse.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Recovers from an error by transforming `Err` into another `Result`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The input error value type.\n * @typeParam F - The output error value type.\n * @param result - The source `Result`.\n * @param fn - The recovery function applied to `Err`.\n * @returns The recovered `Result` or the original `Ok`.\n * @since 0.1.0\n * @see {@link andThen} - Chains the success branch.\n * @example\n * ```ts\n * import { Err, Ok, orElse } from '@resultsafe/core-fp-result';\n *\n * const result = orElse(Err('network'), () => Ok('cached'));\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const orElse = <T, E, F>(\n result: Result<T, E>,\n fn: (error: E) => Result<T, F>,\n): Result<T, F> =>\n isErr(result) ? fn(result.error) : (result as Result<T, F>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBACpB,QACA,OAEA,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,IAAK,QAJhB;"}
|
package/esm/methods/tap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap.js","sources":["../../../src/methods/tap.ts"],"sourcesContent":["import type { Result } from '../
|
|
1
|
+
{"version":3,"file":"tap.js","sources":["../../../src/methods/tap.ts"],"sourcesContent":["import type { Result } from '../types/core/index.js';\n\n/**\n * Performs a side effect for the `Ok` value and returns the input `Result`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The side effect callback for the success branch.\n * @returns The unchanged `Result`.\n * @since 0.1.0\n * @see {@link tapErr} - Executes a side effect for the error branch.\n * @example\n * ```ts\n * import { Ok, tap } from '@resultsafe/core-fp-result';\n *\n * const result = tap(Ok(1), (value) => console.log(value)); // 1\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const tap = <T, E>(\n result: Result<T, E>,\n fn: (value: T) => void,\n): Result<T, E> => {\n if (result.ok) {\n fn(result.value);\n }\n return result;\n};\n"],"names":[],"mappings":";;AAqBO,MAAM,MAAM,wBACjB,QACA,OACiB;AACjB,MAAI,OAAO,IAAI;AACb,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GARmB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tapErr.js","sources":["../../../src/methods/tapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"tapErr.js","sources":["../../../src/methods/tapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Performs a side effect for the `Err` value and returns the input `Result`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The side effect callback for the error branch.\n * @returns The unchanged `Result`.\n * @since 0.1.0\n * @see {@link tap} - Executes a side effect for the success branch.\n * @example\n * ```ts\n * import { Err, tapErr } from '@resultsafe/core-fp-result';\n *\n * const result = tapErr(Err('boom'), (error) => console.log(error)); // boom\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const tapErr = <T, E>(\n result: Result<T, E>,\n fn: (error: E) => void,\n): Result<T, E> => {\n if (isErr(result)) {\n fn(result.error);\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,SAAS,wBACpB,QACA,OACiB;AACjB,MAAI,MAAM,MAAM,GAAG;AACjB,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GARsB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpose.js","sources":["../../../src/methods/transpose.ts"],"sourcesContent":["import { None, Some } from '../internal/option.js';\nimport { type Option
|
|
1
|
+
{"version":3,"file":"transpose.js","sources":["../../../src/methods/transpose.ts"],"sourcesContent":["import { None, Some } from '../internal/option.js';\nimport { type Option, type Result } from '../types/core/index.js';\n\n/**\n * Transforms `Result<Option<T>, E>` into `Option<Result<T, E>>`.\n *\n * @typeParam T - The success value type inside `Option`.\n * @typeParam E - The error value type.\n * @param result - The source `Result` containing an `Option`.\n * @returns The transposed `Option<Result<T, E>>`.\n * @since 0.1.0\n * @see {@link flatten} - Collapses nested `Result` values.\n * @example\n * ```ts\n * import { Ok, transpose } from '@resultsafe/core-fp-result';\n *\n * const value = transpose(Ok({ some: true, value: 2 }));\n * console.log(value.some); // true\n * ```\n * @public\n */\nexport const transpose = <T, E>(\n result: Result<Option<T>, E>,\n): Option<Result<T, E>> => {\n if (result.ok) {\n return result.value.some === true\n ? Some({ ok: true, value: result.value.value })\n : None;\n }\n return Some({ ok: false, error: result.error });\n};\n"],"names":[],"mappings":";;;AAqBO,MAAM,YAAY,wBACvB,WACyB;AACzB,MAAI,OAAO,IAAI;AACb,WAAO,OAAO,MAAM,SAAS,OACzB,KAAK,EAAE,IAAI,MAAM,OAAO,OAAO,MAAM,MAAA,CAAO,IAC5C;AAAA,EACN;AACA,SAAO,KAAK,EAAE,IAAI,OAAO,OAAO,OAAO,OAAO;AAChD,GATyB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrap.js","sources":["../../../src/methods/unwrap.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"unwrap.js","sources":["../../../src/methods/unwrap.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Returns the success value or throws an exception if the result is `Err`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @returns The success payload.\n * @throws Error - Throws an exception when called on `Err`.\n * @since 0.1.0\n * @see {@link unwrapOr} - Returns a fallback instead of throwing.\n * @example\n * ```ts\n * import { Ok, unwrap } from '@resultsafe/core-fp-result';\n *\n * const value = unwrap(Ok(9));\n * console.log(value); // 9\n * ```\n * @public\n */\nexport const unwrap = <T, E>(result: Result<T, E>): T => {\n if (isOk(result)) {\n return result.value;\n }\n throw new Error('Called unwrap on an Err value');\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,SAAS,wBAAO,WAA4B;AACvD,MAAI,KAAK,MAAM,GAAG;AAChB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,+BAA+B;AACjD,GALsB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrapErr.js","sources":["../../../src/methods/unwrapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"unwrapErr.js","sources":["../../../src/methods/unwrapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Returns the error value or throws an exception if the result is `Ok`.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @returns The error payload.\n * @throws Error - Throws an exception when called on `Ok`.\n * @since 0.1.0\n * @see {@link unwrapOrElse} - Returns a success fallback without throwing.\n * @example\n * ```ts\n * import { Err, unwrapErr } from '@resultsafe/core-fp-result';\n *\n * const error = unwrapErr(Err('boom'));\n * console.log(error); // boom\n * ```\n * @public\n */\nexport const unwrapErr = <T, E>(result: Result<T, E>): E => {\n if (isErr(result)) {\n return result.error;\n }\n throw new Error('Called unwrapErr on an Ok value');\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,YAAY,wBAAO,WAA4B;AAC1D,MAAI,MAAM,MAAM,GAAG;AACjB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,iCAAiC;AACnD,GALyB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrapOr.js","sources":["../../../src/methods/unwrapOr.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../
|
|
1
|
+
{"version":3,"file":"unwrapOr.js","sources":["../../../src/methods/unwrapOr.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../types/core/index.js';\n\n/**\n * Returns the success value or the provided default fallback.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param defaultValue - The fallback value for `Err`.\n * @returns The success payload or `defaultValue`.\n * @since 0.1.0\n * @see {@link unwrapOrElse} - Computes the fallback lazily.\n * @example\n * ```ts\n * import { Err, unwrapOr } from '@resultsafe/core-fp-result';\n *\n * const value = unwrapOr(Err('boom'), 0);\n * console.log(value); // 0\n * ```\n * @public\n */\nexport const unwrapOr = <T, E>(result: Result<T, E>, defaultValue: T): T =>\n isOk(result) ? result.value : defaultValue;\n"],"names":[],"mappings":";;;AAsBO,MAAM,WAAW,wBAAO,QAAsB,iBACnD,KAAK,MAAM,IAAI,OAAO,QAAQ,cADR;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unwrapOrElse.js","sources":["../../../src/methods/unwrapOrElse.ts"],"sourcesContent":["import { type Result } from '../
|
|
1
|
+
{"version":3,"file":"unwrapOrElse.js","sources":["../../../src/methods/unwrapOrElse.ts"],"sourcesContent":["import { type Result } from '../types/core/index.js';\n\n/**\n * Returns the success value or computes a fallback from the error.\n *\n * @typeParam T - The success value type.\n * @typeParam E - The error value type.\n * @param result - The source `Result`.\n * @param fn - The fallback provider function for `Err`.\n * @returns The success payload or the computed fallback.\n * @since 0.1.0\n * @see {@link unwrapOr} - Uses an eager fallback value.\n * @example\n * ```ts\n * import { Err, unwrapOrElse } from '@resultsafe/core-fp-result';\n *\n * const value = unwrapOrElse(Err('fatal'), (error) => error.length);\n * console.log(value); // 5\n * ```\n * @public\n */\nexport const unwrapOrElse = <T, E>(\n result: Result<T, E>,\n fn: (error: E) => T,\n): T => {\n if (result.ok) {\n return result.value;\n } else {\n return fn(result.error);\n }\n};\n"],"names":[],"mappings":";;AAqBO,MAAM,eAAe,wBAC1B,QACA,OACM;AACN,MAAI,OAAO,IAAI;AACb,WAAO,OAAO;AAAA,EAChB,OAAO;AACL,WAAO,GAAG,OAAO,KAAK;AAAA,EACxB;AACF,GAT4B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTypedVariant.js","sources":["../../../src/refiners/isTypedVariant.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"isTypedVariant.js","sources":["../../../src/refiners/isTypedVariant.ts"],"sourcesContent":["/**\n * Creates a runtime type guard for a discriminated union variant.\n *\n * @typeParam K - The discriminant literal type.\n * @param variant - The discriminant value to match.\n * @returns A predicate that checks `{ type: K }` shape.\n * @since 0.1.0\n * @see {@link isTypedVariantOf} - Extends check with payload keys.\n * @example\n * ```ts\n * import { isTypedVariant } from '@resultsafe/core-fp-result';\n *\n * const isCreated = isTypedVariant('created');\n * console.log(isCreated({ type: 'created' })); // true\n * ```\n * @public\n */\nexport const isTypedVariant =\n <K extends string>(variant: K) =>\n (value: unknown): value is { type: K } => {\n if (typeof value !== 'object' || value === null) return false;\n if (!('type' in value)) return false;\n\n const obj = value as Record<string, unknown>;\n return obj['type'] === variant;\n };\n"],"names":[],"mappings":";;AAiBO,MAAM,iBACX,wBAAmB,YACnB,CAAC,UAAyC;AACxC,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,MAAI,EAAE,UAAU,OAAQ,QAAO;AAE/B,QAAM,MAAM;AACZ,SAAO,IAAI,MAAM,MAAM;AACzB,GAPA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTypedVariantOf.js","sources":["../../../src/refiners/isTypedVariantOf.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"isTypedVariantOf.js","sources":["../../../src/refiners/isTypedVariantOf.ts"],"sourcesContent":["/**\n * Creates a runtime type guard for a variant with additional payload keys.\n *\n * @typeParam K - The discriminant literal type.\n * @typeParam T - The required payload record shape.\n * @param variant - The discriminant value to match.\n * @returns A predicate that checks variant and payload key presence.\n * @since 0.1.0\n * @see {@link isTypedVariant} - Checks only the discriminant.\n * @example\n * ```ts\n * import { isTypedVariantOf } from '@resultsafe/core-fp-result';\n *\n * const isCreated = isTypedVariantOf<'created', { id: unknown }>('created');\n * console.log(isCreated({ type: 'created', id: 1 })); // true\n * ```\n * @public\n */\nexport const isTypedVariantOf =\n <K extends string, T extends Record<string, unknown>>(variant: K) =>\n (value: unknown): value is { type: K } & T => {\n // Rust-style early returns with Option-like behavior\n if (typeof value !== 'object' || value === null) return false;\n if (!('type' in value)) return false;\n\n const obj = value as Record<string, unknown>;\n if (obj['type'] !== variant) return false;\n\n // Type-safe key checking (like Rust's HashMap.contains_key)\n const requiredKeys = Object.keys({} as T) as Array<keyof T>;\n for (const key of requiredKeys) {\n if (!(key in obj)) return false;\n }\n\n return true;\n };\n"],"names":[],"mappings":";;AAkBO,MAAM,mBACX,wBAAsD,YACtD,CAAC,UAA6C;AAE5C,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,MAAI,EAAE,UAAU,OAAQ,QAAO;AAE/B,QAAM,MAAM;AACZ,MAAI,IAAI,MAAM,MAAM,QAAS,QAAO;AAGpC,QAAM,eAAe,OAAO,KAAK,EAAO;AACxC,aAAW,OAAO,cAAc;AAC9B,QAAI,EAAE,OAAO,KAAM,QAAO;AAAA,EAC5B;AAEA,SAAO;AACT,GAhBA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchVariant.js","sources":["../../../src/refiners/matchVariant.ts"],"sourcesContent":["import type { Handler, Matcher, VariantOf } from './types/index.js';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"matchVariant.js","sources":["../../../src/refiners/matchVariant.ts"],"sourcesContent":["import type { Handler, Matcher, VariantOf } from './types/index.js';\n\n/**\n * Creates a chained matcher for a discriminated union value.\n *\n * @typeParam T - The discriminated union type.\n * @param value - The union value to match.\n * @returns A fluent matcher with `with` and `otherwise` branches.\n * @since 0.1.0\n * @see {@link matchVariantStrict} - Requires exhaustive matching at runtime.\n * @example\n * ```ts\n * import { matchVariant } from '@resultsafe/core-fp-result';\n *\n * const out = matchVariant<{ type: 'ok'; value: number } | { type: 'err'; error: string }>({\n * type: 'ok',\n * value: 1,\n * })\n * .with('ok', (v) => `ok:${v.value}`)\n * .otherwise(() => 'fallback')\n * .run();\n *\n * console.log(out); // ok:1\n * ```\n * @public\n */\nexport const matchVariant = <T extends VariantOf>(\n value: T,\n): Matcher<T, unknown> => {\n const handlers: readonly Handler<T['type'], T, unknown>[] = [];\n\n const withHandler = <K extends T['type']>(\n variant: K,\n fn: (value: Extract<T, { type: K }>) => unknown,\n ): Matcher<T, unknown> => {\n const newHandlers = [...handlers, { variant, fn }] as const;\n\n return {\n with: <K2 extends T['type']>(\n variant2: K2,\n fn2: (value: Extract<T, { type: K2 }>) => unknown,\n ): Matcher<T, unknown> => {\n const newerHandlers = [\n ...newHandlers,\n { variant: variant2, fn: fn2 },\n ] as const;\n\n return {\n with: withHandler,\n otherwise: (fallback: (value: T) => unknown) => ({\n run: (): unknown => {\n for (const h of newerHandlers) {\n if (value.type === h.variant) {\n const fn = h.fn as (input: T) => unknown;\n return fn(value);\n }\n }\n return fallback(value);\n },\n }),\n } as Matcher<T, unknown>;\n },\n otherwise: (fallback: (value: T) => unknown) => ({\n run: (): unknown => {\n for (const h of newHandlers) {\n if (value.type === h.variant) {\n const fn = h.fn as (input: T) => unknown;\n return fn(value);\n }\n }\n return fallback(value);\n },\n }),\n } as Matcher<T, unknown>;\n };\n\n const matcher: Matcher<T, unknown> = {\n with: withHandler,\n otherwise: (fallback: (value: T) => unknown) => ({\n run: (): unknown => {\n /* v8 ignore start -- unreachable with current immutable root handler list */\n for (const h of handlers) {\n if (value.type === h.variant) {\n const fn = h.fn as (input: T) => unknown;\n return fn(value);\n }\n }\n /* v8 ignore stop */\n return fallback(value);\n },\n }),\n };\n\n return matcher;\n};\n"],"names":["fn"],"mappings":";;AA0BO,MAAM,eAAe,wBAC1B,UACwB;AACxB,QAAM,WAAsD,CAAA;AAE5D,QAAM,cAAc,wBAClB,SACA,OACwB;AACxB,UAAM,cAAc,CAAC,GAAG,UAAU,EAAE,SAAS,IAAI;AAEjD,WAAO;AAAA,MACL,MAAM,wBACJ,UACA,QACwB;AACxB,cAAM,gBAAgB;AAAA,UACpB,GAAG;AAAA,UACH,EAAE,SAAS,UAAU,IAAI,IAAA;AAAA,QAAI;AAG/B,eAAO;AAAA,UACL,MAAM;AAAA,UACN,WAAW,wBAAC,cAAqC;AAAA,YAC/C,KAAK,6BAAe;AAClB,yBAAW,KAAK,eAAe;AAC7B,oBAAI,MAAM,SAAS,EAAE,SAAS;AAC5B,wBAAMA,MAAK,EAAE;AACb,yBAAOA,IAAG,KAAK;AAAA,gBACjB;AAAA,cACF;AACA,qBAAO,SAAS,KAAK;AAAA,YACvB,GARK;AAAA,UAQL,IATS;AAAA,QAUX;AAAA,MAEJ,GAvBM;AAAA,MAwBN,WAAW,wBAAC,cAAqC;AAAA,QAC/C,KAAK,6BAAe;AAClB,qBAAW,KAAK,aAAa;AAC3B,gBAAI,MAAM,SAAS,EAAE,SAAS;AAC5B,oBAAMA,MAAK,EAAE;AACb,qBAAOA,IAAG,KAAK;AAAA,YACjB;AAAA,UACF;AACA,iBAAO,SAAS,KAAK;AAAA,QACvB,GARK;AAAA,MAQL,IATS;AAAA,IAUX;AAAA,EAEJ,GA3CoB;AA6CpB,QAAM,UAA+B;AAAA,IACnC,MAAM;AAAA,IACN,WAAW,wBAAC,cAAqC;AAAA,MAC/C,KAAK,6BAAe;AAElB,mBAAW,KAAK,UAAU;AACxB,cAAI,MAAM,SAAS,EAAE,SAAS;AAC5B,kBAAM,KAAK,EAAE;AACb,mBAAO,GAAG,KAAK;AAAA,UACjB;AAAA,QACF;AAEA,eAAO,SAAS,KAAK;AAAA,MACvB,GAVK;AAAA,IAUL,IAXS;AAAA,EAYX;AAGF,SAAO;AACT,GApE4B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchVariantStrict.js","sources":["../../../src/refiners/matchVariantStrict.ts"],"sourcesContent":["import type { Handler, MatchBuilder, VariantOf } from './types/index.js';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"matchVariantStrict.js","sources":["../../../src/refiners/matchVariantStrict.ts"],"sourcesContent":["import type { Handler, MatchBuilder, VariantOf } from './types/index.js';\n\n/**\n * Creates a strict matcher that throws an exception for unhandled variants.\n *\n * @typeParam T - The discriminated union type.\n * @param value - The union value to match.\n * @returns A strict match builder requiring explicit handlers.\n * @throws Error - Throws an exception if no registered handler matches `value.type`.\n * @since 0.1.0\n * @see {@link matchVariant} - Uses a fallback branch instead of throwing.\n * @example\n * ```ts\n * import { matchVariantStrict } from '@resultsafe/core-fp-result';\n *\n * const out = matchVariantStrict<{ type: 'ok'; value: number } | { type: 'err'; error: string }>({\n * type: 'err',\n * error: 'boom',\n * })\n * .with('ok', (v) => `ok:${v.value}`)\n * .with('err', (v) => `err:${v.error}`)\n * .run();\n *\n * console.log(out); // err:boom\n * ```\n * @public\n */\nexport const matchVariantStrict = <T extends VariantOf>(\n value: T,\n): MatchBuilder<T, unknown> => {\n const handlers: readonly Handler<T['type'], T, unknown>[] = [];\n\n const builder = <Handled extends T['type'] = never>(): MatchBuilder<\n T,\n unknown,\n Handled\n > => ({\n with: <K extends Exclude<T['type'], Handled>>(\n variant: K,\n fn: (value: Extract<T, { type: K }>) => unknown,\n ) => {\n const newHandlers = [...handlers, { variant, fn }] as const;\n\n return {\n with: builder<Handled | K>().with,\n run: (() => {\n for (const h of newHandlers) {\n if (value.type === h.variant) {\n const fn = h.fn as (input: T) => unknown;\n return fn(value);\n }\n }\n throw new Error(\n `Unmatched variant: ${String((value as { type: unknown }).type)}`,\n );\n }) as Handled extends T['type'] ? () => unknown : never,\n } as MatchBuilder<T, unknown, Handled | K>;\n },\n\n run: (() => {\n /* v8 ignore start -- unreachable with current immutable root handler list */\n for (const h of handlers) {\n if (value.type === h.variant) {\n const fn = h.fn as (input: T) => unknown;\n return fn(value);\n }\n }\n /* v8 ignore stop */\n throw new Error(\n `Unmatched variant: ${String((value as { type: unknown }).type)}`,\n );\n }) as Handled extends T['type'] ? () => unknown : never,\n });\n\n return builder();\n};\n"],"names":["fn"],"mappings":";;AA2BO,MAAM,qBAAqB,wBAChC,UAC6B;AAC7B,QAAM,WAAsD,CAAA;AAE5D,QAAM,UAAU,8BAIV;AAAA,IACJ,MAAM,wBACJ,SACA,OACG;AACH,YAAM,cAAc,CAAC,GAAG,UAAU,EAAE,SAAS,IAAI;AAEjD,aAAO;AAAA,QACL,MAAM,UAAuB;AAAA,QAC7B,KAAM,8BAAM;AACV,qBAAW,KAAK,aAAa;AAC3B,gBAAI,MAAM,SAAS,EAAE,SAAS;AAC5B,oBAAMA,MAAK,EAAE;AACb,qBAAOA,IAAG,KAAK;AAAA,YACjB;AAAA,UACF;AACA,gBAAM,IAAI;AAAA,YACR,sBAAsB,OAAQ,MAA4B,IAAI,CAAC;AAAA,UAAA;AAAA,QAEnE,IAVM;AAAA,MAUN;AAAA,IAEJ,GApBM;AAAA,IAsBN,KAAM,8BAAM;AAEV,iBAAW,KAAK,UAAU;AACxB,YAAI,MAAM,SAAS,EAAE,SAAS;AAC5B,gBAAM,KAAK,EAAE;AACb,iBAAO,GAAG,KAAK;AAAA,QACjB;AAAA,MACF;AAEA,YAAM,IAAI;AAAA,QACR,sBAAsB,OAAQ,MAA4B,IAAI,CAAC;AAAA,MAAA;AAAA,IAEnE,IAZM;AAAA,EAYN,IAvCc;AA0ChB,SAAO,QAAA;AACT,GAhDkC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refineAsyncResult.js","sources":["../../../src/refiners/refineAsyncResult.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"refineAsyncResult.js","sources":["../../../src/refiners/refineAsyncResult.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type { AsyncValidatorFn } from '../types/refiners/AsyncValidatorFn.js';\nimport type { PayloadKeys } from '../types/refiners/PayloadKeys.js';\nimport type { VariantConfig } from '../types/refiners/VariantConfig.js';\nimport type { UniversalAsyncRefinedResult } from './types/index.js';\n\n/** Resolves payload keys from variant configuration. @internal */\nconst getPayloadKeys = <C extends VariantConfig>(\n config: C,\n): readonly PayloadKeys<C>[] => {\n const p = config.payload;\n if (p === 'never') return [];\n return (Array.isArray(p) ? p : [p]) as readonly PayloadKeys<C>[];\n};\n\n/**\n * Creates an async variant refiner with async payload validators.\n *\n * @typeParam TMap - The variant configuration map type.\n * @param variantMap - The map describing valid variants and payload fields.\n * @returns A curried async refiner factory bound to `variantMap`.\n * @since 0.1.0\n * @see {@link refineAsyncResultU} - Direct (non-curried) helper variant.\n * @example\n * ```ts\n * import { refineAsyncResult } from '@resultsafe/core-fp-result';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const refineOk = refineAsyncResult(map)('ok')({\n * value: async (x: unknown) => typeof x === 'number',\n * });\n *\n * console.log(await refineOk({ type: 'ok', value: 1 })); // { type: 'ok', value: 1 }\n * ```\n * @public\n */\nexport const refineAsyncResult =\n <TMap extends Record<string, VariantConfig>>(variantMap: TMap) =>\n <K extends keyof TMap & string>(variant: K) =>\n <TValidators extends Partial<Record<PayloadKeys<TMap[K]>, AsyncValidatorFn>>>(\n validators: TValidators,\n ) =>\n async (\n value: unknown,\n ): Promise<UniversalAsyncRefinedResult<K, TMap, TValidators> | null> => {\n if (!isObject(value)) return null;\n if (!hasOwn(value, 'type')) return null;\n\n const t = value['type'];\n if (t !== variant) return null;\n\n const config = variantMap[variant];\n if (!config) return null;\n\n const keys = getPayloadKeys(config);\n for (const key of keys) {\n const check = validators?.[key];\n if (!check) continue;\n\n const field = value[key as keyof typeof value];\n const isValid = await check(field); // ✅ Async validation\n if (!isValid) return null;\n }\n\n return value as UniversalAsyncRefinedResult<K, TMap, TValidators>;\n };\n\n/**\n * Refines a value asynchronously in non-curried call style.\n *\n * @typeParam TMap - The variant configuration map type.\n * @typeParam K - The target variant key.\n * @typeParam TValidators - The async validator map for payload fields.\n * @param value - The value to validate and refine.\n * @param variant - The target variant key.\n * @param variantMap - The variant configuration map.\n * @param validators - The async payload validators.\n * @returns A promise resolving to the refined value or `null`.\n * @remarks\n * This export is kept for compatibility. Prefer {@link refineAsyncResultU}\n * from `refineAsyncResultU.ts` as the canonical non-curried entry point.\n * @since 0.1.0\n * @example\n * ```ts\n * import { refineAsyncResultU } from '@resultsafe/core-fp-result/src/refiners/refineAsyncResult.js';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const out = await refineAsyncResultU({ type: 'ok', value: 1 }, 'ok', map, {\n * value: async (x: unknown) => typeof x === 'number',\n * });\n *\n * console.log(out?.type); // ok\n * ```\n * @internal\n */\nexport const refineAsyncResultU = <\n TMap extends Record<string, VariantConfig>,\n K extends keyof TMap & string,\n TValidators extends Partial<Record<PayloadKeys<TMap[K]>, AsyncValidatorFn>>,\n>(\n value: unknown,\n variant: K,\n variantMap: TMap,\n validators: TValidators,\n): Promise<UniversalAsyncRefinedResult<K, TMap, TValidators> | null> =>\n refineAsyncResult(variantMap)(variant)(validators)(value);\n"],"names":[],"mappings":";;;AAOA,MAAM,iBAAiB,wBACrB,WAC8B;AAC9B,QAAM,IAAI,OAAO;AACjB,MAAI,MAAM,QAAS,QAAO,CAAA;AAC1B,SAAQ,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AACnC,GANuB;AA6BhB,MAAM,oBACX,wBAA6C,eAC7C,CAAgC,YAChC,CACE,eAEF,OACE,UACsE;AACtE,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,MAAI,CAAC,OAAO,OAAO,MAAM,EAAG,QAAO;AAEnC,QAAM,IAAI,MAAM,MAAM;AACtB,MAAI,MAAM,QAAS,QAAO;AAE1B,QAAM,SAAS,WAAW,OAAO;AACjC,MAAI,CAAC,OAAQ,QAAO;AAEpB,QAAM,OAAO,eAAe,MAAM;AAClC,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,aAAa,GAAG;AAC9B,QAAI,CAAC,MAAO;AAEZ,UAAM,QAAQ,MAAM,GAAyB;AAC7C,UAAM,UAAU,MAAM,MAAM,KAAK;AACjC,QAAI,CAAC,QAAS,QAAO;AAAA,EACvB;AAEA,SAAO;AACT,GA5BA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refineAsyncResultU.js","sources":["../../../src/refiners/refineAsyncResultU.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"refineAsyncResultU.js","sources":["../../../src/refiners/refineAsyncResultU.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type { AsyncValidatorFn } from '../types/refiners/AsyncValidatorFn.js';\nimport type { PayloadKeys } from '../types/refiners/PayloadKeys.js';\nimport type { VariantConfig } from '../types/refiners/VariantConfig.js';\nimport type { UniversalAsyncRefinedResult } from './types/index.js';\n\n/** Resolves payload keys from variant configuration. @internal */\nconst getPayloadKeys = <C extends VariantConfig>(\n config: C,\n): readonly PayloadKeys<C>[] => {\n const p = config.payload;\n if (p === 'never') return [];\n return (Array.isArray(p) ? p : [p]) as readonly PayloadKeys<C>[];\n};\n\n/**\n * Refines a value asynchronously in non-curried call style.\n *\n * @typeParam TMap - The variant configuration map type.\n * @typeParam K - The target variant key.\n * @typeParam TValidators - The async validator map for payload fields.\n * @param value - The value to validate and refine.\n * @param variant - The target variant key.\n * @param variantMap - The variant configuration map.\n * @param validators - The async payload validators.\n * @returns A promise resolving to the refined value or `null`.\n * @since 0.1.0\n * @see {@link refineAsyncResult} - Curry-style async refiner constructor.\n * @example\n * ```ts\n * import { refineAsyncResultU } from '@resultsafe/core-fp-result';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const out = await refineAsyncResultU({ type: 'ok', value: 1 }, 'ok', map, {\n * value: async (x: unknown) => typeof x === 'number',\n * });\n *\n * console.log(out?.type); // ok\n * ```\n * @public\n */\nexport const refineAsyncResultU = <\n TMap extends Record<string, VariantConfig>,\n K extends keyof TMap & string,\n TValidators extends Partial<Record<PayloadKeys<TMap[K]>, AsyncValidatorFn>>,\n>(\n value: unknown,\n variant: K,\n variantMap: TMap,\n validators: TValidators,\n): Promise<UniversalAsyncRefinedResult<K, TMap, TValidators> | null> => {\n // Imperative style with early returns (Rust-style)\n return (async () => {\n // Rust-style early returns with Option-like behavior\n if (!isObject(value)) return null;\n if (!hasOwn(value, 'type')) return null;\n\n const t = value['type'];\n if (t !== variant) return null;\n\n const config = variantMap[variant];\n if (!config) return null;\n\n // Payload validation with async validators\n const keys = getPayloadKeys(config);\n for (const key of keys) {\n const check = validators[key as keyof TValidators];\n if (!check) continue;\n\n const field = value[key as string];\n // Type-safe async validation\n const isValid = await (check as AsyncValidatorFn)(field);\n if (!isValid) return null;\n }\n\n // Safe cast after all checks\n return value as UniversalAsyncRefinedResult<K, TMap, TValidators>;\n })();\n};\n"],"names":[],"mappings":";;;AAOA,MAAM,iBAAiB,wBACrB,WAC8B;AAC9B,QAAM,IAAI,OAAO;AACjB,MAAI,MAAM,QAAS,QAAO,CAAA;AAC1B,SAAQ,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AACnC,GANuB;AAkChB,MAAM,qBAAqB,wBAKhC,OACA,SACA,YACA,eACsE;AAEtE,UAAQ,YAAY;AAElB,QAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,QAAI,CAAC,OAAO,OAAO,MAAM,EAAG,QAAO;AAEnC,UAAM,IAAI,MAAM,MAAM;AACtB,QAAI,MAAM,QAAS,QAAO;AAE1B,UAAM,SAAS,WAAW,OAAO;AACjC,QAAI,CAAC,OAAQ,QAAO;AAGpB,UAAM,OAAO,eAAe,MAAM;AAClC,eAAW,OAAO,MAAM;AACtB,YAAM,QAAQ,WAAW,GAAwB;AACjD,UAAI,CAAC,MAAO;AAEZ,YAAM,QAAQ,MAAM,GAAa;AAEjC,YAAM,UAAU,MAAO,MAA2B,KAAK;AACvD,UAAI,CAAC,QAAS,QAAO;AAAA,IACvB;AAGA,WAAO;AAAA,EACT,GAAA;AACF,GArCkC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refineResult.js","sources":["../../../src/refiners/refineResult.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"refineResult.js","sources":["../../../src/refiners/refineResult.ts"],"sourcesContent":["import { hasOwn, isObject } from '../internal/object.js';\nimport type { PayloadKeys } from '../types/refiners/PayloadKeys.js';\nimport type { ValidatorFn } from '../types/refiners/ValidatorFn.js';\nimport type { VariantConfig } from '../types/refiners/VariantConfig.js';\nimport type { UniversalRefinedResult } from './types/index.js';\nimport { getPayloadKeys } from './utils/index.js';\n\n/**\n * Creates a sync variant refiner with payload validators.\n *\n * @typeParam TMap - The variant configuration map type.\n * @param variantMap - The map describing valid variants and payload fields.\n * @returns A curried refiner factory bound to `variantMap`.\n * @since 0.1.0\n * @see {@link refineResultU} - Direct (non-curried) helper variant.\n * @example\n * ```ts\n * import { refineResult } from '@resultsafe/core-fp-result';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const refineOk = refineResult(map)('ok')({\n * value: (x: unknown): x is number => typeof x === 'number',\n * });\n *\n * console.log(refineOk({ type: 'ok', value: 1 })); // { type: 'ok', value: 1 }\n * ```\n * @public\n */\nexport const refineResult =\n <TMap extends Record<string, VariantConfig>>(variantMap: TMap) =>\n <K extends keyof TMap & string>(variant: K) =>\n <TValidators extends Partial<Record<PayloadKeys<TMap[K]>, ValidatorFn>>>(\n validators: TValidators,\n ) =>\n (value: unknown): UniversalRefinedResult<K, TMap, TValidators> | null => {\n if (!isObject(value)) return null;\n if (!hasOwn(value, 'type')) return null;\n\n const t = value['type'];\n if (t !== variant) return null;\n\n const config = variantMap[variant];\n if (!config) return null;\n\n const keys = getPayloadKeys(config);\n for (const key of keys) {\n const check = validators?.[key];\n if (!check) continue;\n\n const field = value[key as keyof typeof value];\n if (!check(field)) return null;\n }\n\n return value as UniversalRefinedResult<K, TMap, TValidators>;\n };\n\n/**\n * Refines a value by variant map in non-curried call style.\n *\n * @typeParam TMap - The variant configuration map type.\n * @typeParam K - The target variant key.\n * @typeParam TValidators - The validator map for payload fields.\n * @param value - The value to validate and refine.\n * @param variant - The target variant key.\n * @param variantMap - The variant configuration map.\n * @param validators - The payload validators for the target variant.\n * @returns The refined value or `null`.\n * @remarks\n * This export is kept for compatibility. Prefer {@link refineResultU} from\n * `refineResultU.ts` as the canonical non-curried entry point.\n * @since 0.1.0\n * @example\n * ```ts\n * import { refineResultU } from '@resultsafe/core-fp-result/src/refiners/refineResult.js';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const out = refineResultU({ type: 'ok', value: 1 }, 'ok', map, {\n * value: (x: unknown): x is number => typeof x === 'number',\n * });\n *\n * console.log(out?.type); // ok\n * ```\n * @internal\n */\nexport const refineResultU = <\n TMap extends Record<string, VariantConfig>,\n K extends keyof TMap & string,\n TValidators extends Partial<Record<PayloadKeys<TMap[K]>, ValidatorFn>>,\n>(\n value: unknown,\n variant: K,\n variantMap: TMap,\n validators: TValidators,\n): UniversalRefinedResult<K, TMap, TValidators> | null =>\n refineResult(variantMap)(variant)(validators)(value);\n"],"names":[],"mappings":";;;;AA4BO,MAAM,eACX,wBAA6C,eAC7C,CAAgC,YAChC,CACE,eAEF,CAAC,UAAwE;AACvE,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,MAAI,CAAC,OAAO,OAAO,MAAM,EAAG,QAAO;AAEnC,QAAM,IAAI,MAAM,MAAM;AACtB,MAAI,MAAM,QAAS,QAAO;AAE1B,QAAM,SAAS,WAAW,OAAO;AACjC,MAAI,CAAC,OAAQ,QAAO;AAEpB,QAAM,OAAO,eAAe,MAAM;AAClC,aAAW,OAAO,MAAM;AACtB,UAAM,QAAQ,aAAa,GAAG;AAC9B,QAAI,CAAC,MAAO;AAEZ,UAAM,QAAQ,MAAM,GAAyB;AAC7C,QAAI,CAAC,MAAM,KAAK,EAAG,QAAO;AAAA,EAC5B;AAEA,SAAO;AACT,GAzBA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refineResultU.js","sources":["../../../src/refiners/refineResultU.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"refineResultU.js","sources":["../../../src/refiners/refineResultU.ts"],"sourcesContent":["import type { PayloadKeys } from '../types/refiners/PayloadKeys.js';\nimport type { ValidatorFn } from '../types/refiners/ValidatorFn.js';\nimport type { VariantConfig } from '../types/refiners/VariantConfig.js';\nimport { refineResult } from './refineResult.js';\nimport type { SyncRefinedResult } from './types/index.js';\n\n/**\n * Refines a value by variant map in non-curried call style.\n *\n * @typeParam TMap - The variant configuration map type.\n * @typeParam K - The target variant key.\n * @typeParam TValidators - The validator map for payload fields.\n * @param value - The value to validate and refine.\n * @param variant - The target variant key.\n * @param variantMap - The variant configuration map.\n * @param validators - The payload validators for the target variant.\n * @returns The refined value or `null`.\n * @since 0.1.0\n * @see {@link refineResult} - Curry-style refiner constructor.\n * @example\n * ```ts\n * import { refineResultU } from '@resultsafe/core-fp-result';\n *\n * const map = { ok: { payload: 'value' } } as const;\n * const out = refineResultU({ type: 'ok', value: 1 }, 'ok', map, {\n * value: (x: unknown): x is number => typeof x === 'number',\n * });\n *\n * console.log(out?.type); // ok\n * ```\n * @public\n */\nexport const refineResultU = <\n TMap extends Record<string, VariantConfig>,\n K extends keyof TMap & string,\n TValidators extends Partial<Record<PayloadKeys<TMap[K]>, ValidatorFn>>,\n>(\n value: unknown,\n variant: K,\n variantMap: TMap,\n validators: TValidators,\n): SyncRefinedResult<K, TMap, TValidators> | null =>\n refineResult(variantMap)(variant)(validators)(value);\n"],"names":[],"mappings":";;;AAgCO,MAAM,gBAAgB,wBAK3B,OACA,SACA,YACA,eAEA,aAAa,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,GAVxB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refineVariantMap.js","sources":["../../../src/refiners/refineVariantMap.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"refineVariantMap.js","sources":["../../../src/refiners/refineVariantMap.ts"],"sourcesContent":["import type { PayloadKeys } from '../types/refiners/PayloadKeys.js';\nimport type { ValidatorFn } from '../types/refiners/ValidatorFn.js';\nimport type { VariantConfig } from '../types/refiners/VariantConfig.js';\nimport type { SyncRefinedResultUnion } from './types/SyncRefinedResultUnion.js';\nimport type { SyncValidatorMap } from './types/SyncValidatorMap.js';\n\n/**\n * Refines a discriminated union value by a full variant map.\n *\n * @typeParam TMap - The variant configuration map type.\n * @typeParam TValidators - The validator map type by variant.\n * @param value - The value to validate and refine.\n * @param variantMap - The full variant configuration map.\n * @param validators - The validators grouped by variant key.\n * @returns The refined union member or `null`.\n * @since 0.1.0\n * @see {@link refineResult} - Refines one concrete variant key.\n * @example\n * ```ts\n * import { refineVariantMap } from '@resultsafe/core-fp-result';\n *\n * const map = {\n * created: { payload: 'id' },\n * failed: { payload: 'reason' },\n * } as const;\n *\n * const out = refineVariantMap({ type: 'created', id: '1' }, map, {\n * created: { id: (x: unknown): x is string => typeof x === 'string' },\n * failed: { reason: (x: unknown): x is string => typeof x === 'string' },\n * });\n *\n * console.log(out?.type); // created\n * ```\n * @public\n */\nexport function refineVariantMap<\n TMap extends Record<string, VariantConfig>,\n TValidators extends SyncValidatorMap<TMap>,\n>(\n value: unknown,\n variantMap: TMap,\n validators: TValidators,\n): SyncRefinedResultUnion<TMap, TValidators> | null {\n if (typeof value !== 'object' || value === null || !('type' in value)) {\n return null;\n }\n\n const rawType = (value as { type?: unknown }).type;\n if (typeof rawType !== 'string' || !(rawType in variantMap)) return null;\n\n // fix the specific variant key\n type K = Extract<keyof TMap, string>;\n const k = rawType as K;\n\n const config = variantMap[k];\n if (!config) return null;\n\n // payload keys for the specific K\n const payload = config.payload;\n const keys = (\n payload === 'never' ? [] : Array.isArray(payload) ? payload : [payload]\n ) as readonly PayloadKeys<TMap[typeof k]>[];\n\n // validators aligned with the specific K\n const vvs = validators[k] as\n | Partial<Record<PayloadKeys<TMap[typeof k]>, ValidatorFn>>\n | undefined;\n\n if (vvs) {\n const obj = value as Record<string, unknown>;\n for (const key of keys) {\n const check = vvs[key];\n if (!check) continue;\n if (!check(obj[key as string])) return null;\n }\n }\n\n return value as SyncRefinedResultUnion<TMap, TValidators>;\n}\n"],"names":[],"mappings":";;AAmCO,SAAS,iBAId,OACA,YACA,YACkD;AAClD,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAAQ;AACrE,WAAO;AAAA,EACT;AAEA,QAAM,UAAW,MAA6B;AAC9C,MAAI,OAAO,YAAY,YAAY,EAAE,WAAW,YAAa,QAAO;AAIpE,QAAM,IAAI;AAEV,QAAM,SAAS,WAAW,CAAC;AAC3B,MAAI,CAAC,OAAQ,QAAO;AAGpB,QAAM,UAAU,OAAO;AACvB,QAAM,OACJ,YAAY,UAAU,KAAK,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAIxE,QAAM,MAAM,WAAW,CAAC;AAIxB,MAAI,KAAK;AACP,UAAM,MAAM;AACZ,eAAW,OAAO,MAAM;AACtB,YAAM,QAAQ,IAAI,GAAG;AACrB,UAAI,CAAC,MAAO;AACZ,UAAI,CAAC,MAAM,IAAI,GAAa,CAAC,EAAG,QAAO;AAAA,IACzC;AAAA,EACF;AAEA,SAAO;AACT;AA3CgB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPayloadKeys.js","sources":["../../../../src/refiners/utils/getPayloadKeys.ts"],"sourcesContent":["import type { PayloadKeys
|
|
1
|
+
{"version":3,"file":"getPayloadKeys.js","sources":["../../../../src/refiners/utils/getPayloadKeys.ts"],"sourcesContent":["import type { PayloadKeys } from '../../types/refiners/PayloadKeys.js';\nimport type { VariantConfig } from '../../types/refiners/VariantConfig.js';\n\n/**\n * Normalizes a variant payload configuration into a list of keys.\n *\n * @typeParam C - The variant configuration type.\n * @param config - The variant configuration with payload definition.\n * @returns The payload keys as a readonly array.\n * @since 0.1.0\n * @example\n * ```ts\n * import { getPayloadKeys } from '@resultsafe/core-fp-result/src/refiners/utils/getPayloadKeys.js';\n *\n * const keys = getPayloadKeys({ payload: ['id', 'meta'] } as const);\n * console.log(keys.length); // 2\n * ```\n * @internal\n */\nexport const getPayloadKeys = <C extends VariantConfig>(\n config: C,\n): readonly PayloadKeys<C>[] => {\n const p = config.payload;\n if (p === 'never') return [];\n return (Array.isArray(p) ? p : [p]) as readonly PayloadKeys<C>[];\n};\n"],"names":[],"mappings":";;AAmBO,MAAM,iBAAiB,wBAC5B,WAC8B;AAC9B,QAAM,IAAI,OAAO;AACjB,MAAI,MAAM,QAAS,QAAO,CAAA;AAC1B,SAAQ,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AACnC,GAN8B;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Result } from '../
|
|
1
|
+
import type { Result } from '../types/core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Creates an error `Result` value from the provided error payload.
|
|
4
4
|
*
|
|
5
|
-
* @typeParam E -
|
|
5
|
+
* @typeParam E - The error value type.
|
|
6
6
|
* @typeParam T - The success type for the resulting `Result`.
|
|
7
|
-
* @param error -
|
|
7
|
+
* @param error - The error payload to wrap.
|
|
8
8
|
* @returns A `Result` with `ok: false` and the provided `error`.
|
|
9
9
|
* @since 0.1.0
|
|
10
10
|
* @see {@link Ok} - Creates a successful `Result`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Err.d.ts","sourceRoot":"","sources":["../../../src/constructors/Err.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Err.d.ts","sourceRoot":"","sources":["../../../src/constructors/Err.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CACvB,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Result } from '../
|
|
1
|
+
import type { Result } from '../types/core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Creates a successful `Result` value from the provided payload.
|
|
4
4
|
*
|
|
5
|
-
* @typeParam T -
|
|
5
|
+
* @typeParam T - The success value type.
|
|
6
6
|
* @typeParam E - The error type for the resulting `Result`.
|
|
7
|
-
* @param value -
|
|
7
|
+
* @param value - The success payload to wrap.
|
|
8
8
|
* @returns A `Result` with `ok: true` and the provided `value`.
|
|
9
9
|
* @since 0.1.0
|
|
10
10
|
* @see {@link Err} - Creates an error `Result`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ok.d.ts","sourceRoot":"","sources":["../../../src/constructors/Ok.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Ok.d.ts","sourceRoot":"","sources":["../../../src/constructors/Ok.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CACvB,CAAC"}
|
package/types/guards/isErr.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Result } from '../
|
|
1
|
+
import type { Result } from '../types/core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Checks whether the `Result` is in the error branch.
|
|
4
4
|
*
|
|
5
|
-
* @typeParam T -
|
|
6
|
-
* @typeParam E -
|
|
7
|
-
* @param result - `Result`
|
|
5
|
+
* @typeParam T - The success value type.
|
|
6
|
+
* @typeParam E - The error value type.
|
|
7
|
+
* @param result - The `Result` to check.
|
|
8
8
|
* @returns `true` when `result.ok` equals `false`.
|
|
9
9
|
* @since 0.1.0
|
|
10
10
|
* @see {@link isOk} - Checks the success branch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErr.d.ts","sourceRoot":"","sources":["../../../src/guards/isErr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"isErr.d.ts","sourceRoot":"","sources":["../../../src/guards/isErr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EACxB,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KACnB,MAAM,IAAI;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAyB,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type Result } from '../
|
|
1
|
+
import { type Result } from '../types/core/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Checks that the `Result` resulted in an error and satisfies the predicate.
|
|
4
4
|
*
|
|
5
|
-
* @typeParam T -
|
|
6
|
-
* @typeParam E -
|
|
7
|
-
* @param result - `Result`
|
|
8
|
-
* @param predicate -
|
|
5
|
+
* @typeParam T - The success value type.
|
|
6
|
+
* @typeParam E - The error value type.
|
|
7
|
+
* @param result - The `Result` to check.
|
|
8
|
+
* @param predicate - The predicate applied to the error value.
|
|
9
9
|
* @returns `true` when the value is `Err` and the predicate returns `true`.
|
|
10
10
|
* @since 0.1.0
|
|
11
11
|
* @see {@link isErr} - Performs the base error check.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErrAnd.d.ts","sourceRoot":"","sources":["../../../src/guards/isErrAnd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"isErrAnd.d.ts","sourceRoot":"","sources":["../../../src/guards/isErrAnd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,EAC3B,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,WAAW,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,KAC/B,OAAmD,CAAC"}
|