massaman 0.5.1 → 0.5.2

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.
@@ -1,3 +1,3 @@
1
- import { n as Ok, r as Result, t as Err } from "../types-BsimcHZS.mjs";
2
- import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "../index-D5q3I26j.mjs";
1
+ import { n as Ok, r as Result, t as Err } from "../types-D8DevyLz.mjs";
2
+ import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "../index-CmmSFDY_.mjs";
3
3
  export { type Err, type Ok, type Result, assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
@@ -1,2 +1,2 @@
1
- import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "../control-DCdm8IH6.mjs";
1
+ import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "../control-DMCSi-hj.mjs";
2
2
  export { assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
@@ -2,13 +2,21 @@ import { isNil } from "es-toolkit/predicate";
2
2
  import { assert, invariant } from "es-toolkit/util";
3
3
  //#region src/control/result.ts
4
4
  /**
5
+ * Checks whether a value exposes the required structural `Error` fields.
6
+ * @param value - The value to inspect
7
+ * @returns Whether the value has string `name` and `message` fields
8
+ * @private
9
+ */
10
+ function isErrorLike(value) {
11
+ return typeof value === "object" && !isNil(value) && "name" in value && typeof value.name === "string" && "message" in value && typeof value.message === "string";
12
+ }
13
+ /**
5
14
  * Minimal error coercion used internally by `err()`. Kept local to avoid
6
15
  * pulling the full conversion module into the `massaman/control` bundle.
7
- * For richer stringification (Maps, Sets, Errors with own props, circular
8
- * refs), import `toError` from `massaman/conversion`.
9
16
  */
10
17
  function coerceError(thrown) {
11
18
  if (thrown instanceof Error) return thrown;
19
+ if (isErrorLike(thrown)) return Object.defineProperties(new Error(thrown.message, { cause: thrown }), Object.getOwnPropertyDescriptors(thrown));
12
20
  if (typeof thrown === "string") return new Error(thrown);
13
21
  try {
14
22
  const message = JSON.stringify(thrown) ?? String(thrown);
@@ -36,18 +44,6 @@ function ok(value) {
36
44
  error: null
37
45
  };
38
46
  }
39
- /**
40
- * Creates a failure result wrapping the given error.
41
- *
42
- * @param error - The error value
43
- * @returns An `Err` result containing the error
44
- *
45
- * @example
46
- * ```ts
47
- * const result = err(new Error('fail'))
48
- * // { ok: false, error: Error('fail') }
49
- * ```
50
- */
51
47
  function err(error) {
52
48
  return {
53
49
  ok: false,
@@ -240,4 +236,4 @@ function unreachable(message) {
240
236
  //#endregion
241
237
  export { todo as a, err as c, ok as d, unwrap as f, unimplemented as i, isErr as l, invariant as n, attempt as o, unreachable as r, attemptAsync as s, assert as t, isOk as u };
242
238
 
243
- //# sourceMappingURL=control-DCdm8IH6.mjs.map
239
+ //# sourceMappingURL=control-DMCSi-hj.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-DMCSi-hj.mjs","names":[],"sources":["../src/control/result.ts","../src/control/attempt.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"sourcesContent":["import { isNil } from 'es-toolkit/predicate'\n\nimport type { Err, Ok, Result } from './types.js'\n\n/**\n * Checks whether a value exposes the required structural `Error` fields.\n * @param value - The value to inspect\n * @returns Whether the value has string `name` and `message` fields\n * @private\n */\nfunction isErrorLike(value: unknown): value is Error {\n return (\n typeof value === 'object' &&\n !isNil(value) &&\n 'name' in value &&\n typeof value.name === 'string' &&\n 'message' in value &&\n typeof value.message === 'string'\n )\n}\n\n/**\n * Minimal error coercion used internally by `err()`. Kept local to avoid\n * pulling the full conversion module into the `massaman/control` bundle.\n */\nfunction coerceError(thrown: unknown): Error {\n if (thrown instanceof Error) {\n return thrown\n }\n if (isErrorLike(thrown)) {\n return Object.defineProperties(\n new Error(thrown.message, { cause: thrown }),\n Object.getOwnPropertyDescriptors(thrown)\n )\n }\n if (typeof thrown === 'string') {\n return new Error(thrown)\n }\n try {\n const message = JSON.stringify(thrown) ?? String(thrown)\n return new Error(message, { cause: thrown })\n } catch {\n return new Error(String(thrown), { cause: thrown })\n }\n}\n\n/**\n * Creates a success result wrapping the given value.\n *\n * @param value - The success value\n * @returns An `Ok` result containing the value\n *\n * @example\n * ```ts\n * const result = ok(42)\n * // { ok: true, value: 42 }\n * ```\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: null }\n}\n\n/**\n * Creates a failure result wrapping the given error.\n *\n * @param error - The error value\n * @returns An `Err` result containing the error\n *\n * @example\n * ```ts\n * const result = err(new Error('fail'))\n * // { ok: false, error: Error('fail') }\n * ```\n */\nexport function err<E extends Error>(error: E): Err<E>\nexport function err(error: unknown): Err\nexport function err(error: unknown): Err {\n return { ok: false, value: null, error: coerceError(error) }\n}\n\n/**\n * Type guard that narrows a `Result` to `Ok`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Ok`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{}'))\n * if (isOk(result)) {\n * console.log(result.value)\n * }\n * ```\n */\nexport function isOk<T, E extends Error>(result: Result<T, E>): result is Ok<T> {\n return result.ok === true\n}\n\n/**\n * Type guard that narrows a `Result` to `Err`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Err`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('bad'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport function isErr<T, E extends Error>(result: Result<T, E>): result is Err<E> {\n return result.ok === false\n}\n\n/**\n * Extract the value from an `Ok` result, or throw on `Err`.\n *\n * When called without a message, throws the original error.\n * When called with a message, throws a new Error with that message\n * and the original error as `cause` (like Rust's `expect`).\n *\n * @param result - The result to unwrap\n * @param message - Optional custom error message (Rust `expect` behavior)\n * @returns The unwrapped value\n *\n * @example\n * ```ts\n * const value = unwrap(ok(42)) // 42\n * unwrap(err('fail')) // throws Error('fail')\n * unwrap(err('fail'), 'config required') // throws Error('config required', { cause: Error('fail') })\n * ```\n */\nexport function unwrap<T, E extends Error>(result: Result<T, E>, message?: string): T {\n if (result.ok) {\n return result.value\n }\n if (!isNil(message)) {\n throw new Error(message, { cause: result.error })\n }\n throw result.error\n}\n","import { err, ok } from './result.js'\nimport type { Result } from './types.js'\n\n/**\n * Executes a synchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the return value on success, `Err` with the thrown value on failure.\n *\n * @param fn - The function to execute\n * @returns A `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{\"a\":1}'))\n * if (isOk(result)) {\n * console.log(result.value) // { a: 1 }\n * }\n * ```\n */\nexport function attempt<T>(fn: () => T): Result<T> {\n try {\n return ok(fn())\n } catch (error) {\n return err(error)\n }\n}\n\n/**\n * Executes an asynchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the resolved value on success, `Err` with the rejection reason on failure.\n *\n * @param fn - The async function to execute\n * @returns A promise resolving to a `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = await attemptAsync(() => fetch('/api/data'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport async function attemptAsync<T>(fn: () => Promise<T>): Promise<Result<T>> {\n try {\n return ok(await fn())\n } catch (error) {\n return err(error)\n }\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Stub for a code path you intend to write but haven't. Throws at runtime,\n * returns `never` so it typechecks in any position.\n *\n * For paths you intentionally don't support, see `unimplemented`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseConfig(raw: string): Config {\n * return todo('waiting on schema decision')\n * }\n * ```\n */\nexport function todo(message?: string): never {\n if (isNil(message)) {\n throw new Error('not yet implemented')\n }\n throw new Error(`not yet implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as intentionally unsupported. Throws at runtime, returns\n * `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * type Driver = 'postgres' | 'sqlite' | 'mysql'\n *\n * function migrate(driver: Driver): void {\n * return match(driver)\n * .with('postgres', runPgMigration)\n * .with('sqlite', runSqliteMigration)\n * .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))\n * .exhaustive()\n * }\n * ```\n */\nexport function unimplemented(message?: string): never {\n if (isNil(message)) {\n throw new Error('not implemented')\n }\n throw new Error(`not implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as logically impossible. Throws at runtime if execution\n * gets there. Returns `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths you intentionally don't support, see `unimplemented`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseDigit(input: string): number {\n * const parsed = Number.parseInt(input, 10)\n * if (Number.isNaN(parsed)) {\n * return unreachable('caller pre-validated')\n * }\n * return parsed\n * }\n * ```\n */\nexport function unreachable(message?: string): never {\n if (isNil(message)) {\n throw new Error('entered unreachable code')\n }\n throw new Error(`entered unreachable code: ${message}`)\n}\n"],"mappings":";;;;;;;;;AAUA,SAAS,YAAY,OAAgC;CACnD,OACE,OAAO,UAAU,YACjB,CAAC,MAAM,KAAK,KACZ,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,aAAa,SACb,OAAO,MAAM,YAAY;AAE7B;;;;;AAMA,SAAS,YAAY,QAAwB;CAC3C,IAAI,kBAAkB,OACpB,OAAO;CAET,IAAI,YAAY,MAAM,GACpB,OAAO,OAAO,iBACZ,IAAI,MAAM,OAAO,SAAS,EAAE,OAAO,OAAO,CAAC,GAC3C,OAAO,0BAA0B,MAAM,CACzC;CAEF,IAAI,OAAO,WAAW,UACpB,OAAO,IAAI,MAAM,MAAM;CAEzB,IAAI;EACF,MAAM,UAAU,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM;EACvD,OAAO,IAAI,MAAM,SAAS,EAAE,OAAO,OAAO,CAAC;CAC7C,QAAQ;EACN,OAAO,IAAI,MAAM,OAAO,MAAM,GAAG,EAAE,OAAO,OAAO,CAAC;CACpD;AACF;;;;;;;;;;;;;AAcA,SAAgB,GAAM,OAAiB;CACrC,OAAO;EAAE,IAAI;EAAM;EAAO,OAAO;CAAK;AACxC;AAgBA,SAAgB,IAAI,OAAqB;CACvC,OAAO;EAAE,IAAI;EAAO,OAAO;EAAM,OAAO,YAAY,KAAK;CAAE;AAC7D;;;;;;;;;;;;;;;AAgBA,SAAgB,KAAyB,QAAuC;CAC9E,OAAO,OAAO,OAAO;AACvB;;;;;;;;;;;;;;;AAgBA,SAAgB,MAA0B,QAAwC;CAChF,OAAO,OAAO,OAAO;AACvB;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,OAA2B,QAAsB,SAAqB;CACpF,IAAI,OAAO,IACT,OAAO,OAAO;CAEhB,IAAI,CAAC,MAAM,OAAO,GAChB,MAAM,IAAI,MAAM,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;CAElD,MAAM,OAAO;AACf;;;;;;;;;;;;;;;;;;AC5HA,SAAgB,QAAW,IAAwB;CACjD,IAAI;EACF,OAAO,GAAG,GAAG,CAAC;CAChB,SAAS,OAAO;EACd,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;AAiBA,eAAsB,aAAgB,IAA0C;CAC9E,IAAI;EACF,OAAO,GAAG,MAAM,GAAG,CAAC;CACtB,SAAS,OAAO;EACd,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;;;;;AC5BA,SAAgB,KAAK,SAAyB;CAC5C,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,qBAAqB;CAEvC,MAAM,IAAI,MAAM,wBAAwB,SAAS;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;ACCA,SAAgB,cAAc,SAAyB;CACrD,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,iBAAiB;CAEnC,MAAM,IAAI,MAAM,oBAAoB,SAAS;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;ACPA,SAAgB,YAAY,SAAyB;CACnD,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,0BAA0B;CAE5C,MAAM,IAAI,MAAM,6BAA6B,SAAS;AACxD"}
@@ -1,4 +1,4 @@
1
- import { n as Ok$1, t as Err$1 } from "./types-BsimcHZS.mjs";
1
+ import { n as Ok$1, t as Err$1 } from "./types-D8DevyLz.mjs";
2
2
  import { NonExhaustiveError, P, Pattern, isMatching, match as match$1 } from "ts-pattern";
3
3
  //#region src/match/match.d.ts
4
4
  declare function okPattern(): {
@@ -37,7 +37,7 @@ type Ok<T> = Ok$1<T>;
37
37
  /**
38
38
  * The `Err` variant of a `Result<T>`. See {@link Ok} for the co-location note.
39
39
  */
40
- type Err = Err$1;
40
+ type Err<E extends Error = Error> = Err$1<E>;
41
41
  //#endregion
42
42
  export { Err as a, match$1 as i, Pattern as n, Ok as o, isMatching as r, P$1 as s, NonExhaustiveError as t };
43
- //# sourceMappingURL=index-DcVpX2Bb.d.mts.map
43
+ //# sourceMappingURL=index-BupTTOMT.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-DcVpX2Bb.d.mts","names":[],"sources":["../src/match/match.ts"],"mappings":";;;iBAuBS;EAAe;;iBACf,gBAAgB,gBAAgB,EAAI,kBAC3C,SAAS;EACN;EAAU,OAAO;;iBASb;EAAgB;;iBAChB,iBAAiB,gBAAgB,EAAI,kBAC5C,SAAS;EACN;EAAW,OAAO;;;;;;;;;;cAiBV,YAAU;EAAQ,WAAW;EAAW,YAAY;;;;;;;;KAYrD,GAAG,KAAK,KAAO;;;;KAKf,MAAM"}
1
+ {"version":3,"file":"index-BupTTOMT.d.mts","names":[],"sources":["../src/match/match.ts"],"mappings":";;;iBAuBS;EAAe;;iBACf,gBAAgB,gBAAgB,EAAI,kBAC3C,SAAS;EACN;EAAU,OAAO;;iBASb;EAAgB;;iBAChB,iBAAiB,gBAAgB,EAAI,kBAC5C,SAAS;EACN;EAAW,OAAO;;;;;;;;;;cAiBV,YAAU;EAAQ,WAAW;EAAW,YAAY;;;;;;;;KAYrD,GAAG,KAAK,KAAO;;;;KAKf,IAAI,UAAU,QAAQ,SAAS,MAAQ"}
@@ -1,4 +1,4 @@
1
- import { n as Ok, r as Result, t as Err } from "./types-BsimcHZS.mjs";
1
+ import { n as Ok, r as Result, t as Err } from "./types-D8DevyLz.mjs";
2
2
  import { assert, invariant } from "es-toolkit/util";
3
3
  //#region src/control/attempt.d.ts
4
4
  /**
@@ -60,6 +60,7 @@ declare function ok<T>(value: T): Ok<T>;
60
60
  * // { ok: false, error: Error('fail') }
61
61
  * ```
62
62
  */
63
+ declare function err<E extends Error>(error: E): Err<E>;
63
64
  declare function err(error: unknown): Err;
64
65
  /**
65
66
  * Type guard that narrows a `Result` to `Ok`.
@@ -75,7 +76,7 @@ declare function err(error: unknown): Err;
75
76
  * }
76
77
  * ```
77
78
  */
78
- declare function isOk<T>(result: Result<T>): result is Ok<T>;
79
+ declare function isOk<T, E extends Error>(result: Result<T, E>): result is Ok<T>;
79
80
  /**
80
81
  * Type guard that narrows a `Result` to `Err`.
81
82
  *
@@ -90,7 +91,7 @@ declare function isOk<T>(result: Result<T>): result is Ok<T>;
90
91
  * }
91
92
  * ```
92
93
  */
93
- declare function isErr<T>(result: Result<T>): result is Err;
94
+ declare function isErr<T, E extends Error>(result: Result<T, E>): result is Err<E>;
94
95
  /**
95
96
  * Extract the value from an `Ok` result, or throw on `Err`.
96
97
  *
@@ -109,7 +110,7 @@ declare function isErr<T>(result: Result<T>): result is Err;
109
110
  * unwrap(err('fail'), 'config required') // throws Error('config required', { cause: Error('fail') })
110
111
  * ```
111
112
  */
112
- declare function unwrap<T>(result: Result<T>, message?: string): T;
113
+ declare function unwrap<T, E extends Error>(result: Result<T, E>, message?: string): T;
113
114
  //#endregion
114
115
  //#region src/control/todo.d.ts
115
116
  /**
@@ -182,4 +183,4 @@ declare function unimplemented(message?: string): never;
182
183
  declare function unreachable(message?: string): never;
183
184
  //#endregion
184
185
  export { todo as a, isOk as c, attempt as d, attemptAsync as f, unimplemented as i, ok as l, invariant as n, err as o, unreachable as r, isErr as s, assert as t, unwrap as u };
185
- //# sourceMappingURL=index-D5q3I26j.d.mts.map
186
+ //# sourceMappingURL=index-CmmSFDY_.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CmmSFDY_.d.mts","names":[],"sources":["../src/control/attempt.ts","../src/control/result.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"mappings":";;;;;;;;;;;;;;;;;;iBAkBgB,QAAQ,GAAG,UAAU,IAAI,OAAO;;;;;;;;;;;;;;;;iBAuB1B,aAAa,GAAG,UAAU,QAAQ,KAAK,QAAQ,OAAO;;;;;;;;;;;;;;;iBCiB5D,GAAG,GAAG,OAAO,IAAI,GAAG;;;;;;;;;;;;;iBAgBpB,IAAI,UAAU,OAAO,OAAO,IAAI,IAAI;iBACpC,IAAI,iBAAiB;;;;;;;;;;;;;;;iBAmBrB,KAAK,GAAG,UAAU,OAAO,QAAQ,OAAO,GAAG,KAAK,UAAU,GAAG;;;;;;;;;;;;;;;iBAkB7D,MAAM,GAAG,UAAU,OAAO,QAAQ,OAAO,GAAG,KAAK,UAAU,IAAI;;;;;;;;;;;;;;;;;;;iBAsB/D,OAAO,GAAG,UAAU,OAAO,QAAQ,OAAO,GAAG,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;iBCnHpE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;iBCML,cAAc;;;;;;;;;;;;;;;;;;;;;;;;iBCFd,YAAY"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { $ as union, A as isSubset, B as pullAt, C as forEachRight, D as intersection, E as initial, F as maxBy, G as shuffle, H as remove, I as minBy, J as take, K as sortBy, L as orderBy, M as keyBy, N as last, O as intersectionBy, P as mapAsync, Q as toFilled, R as partition, S as forEachAsync, St as adjust, T as head, U as sample, V as reduceAsync, W as sampleSize, X as takeRightWhile, Y as takeRight, Z as takeWhile, _ as flatMap, _t as descend, a as combinations, at as unzip, b as flatten, bt as reduceWhile, c as difference, ct as without, d as drop, dt as xorWith, et as unionBy, f as dropRight, ft as zip, g as filterAsync, gt as ascend, h as fill, ht as unfold, i as chunkBy, it as uniqWith, j as isSubsetWith, k as intersectionWith, l as differenceBy, lt as xor, m as dropWhile, mt as zipWith, n as cartesianProduct, nt as uniq, o as compact, ot as unzipWith, p as dropRightWhile, pt as zipObject, q as tail, r as chunk, rt as uniqBy, s as countBy, st as windowed, t as at, tt as unionWith, u as differenceWith, ut as xorBy, v as flatMapAsync, vt as sortWith, w as groupBy, x as flattenDeep, xt as dropRepeats, y as flatMapDeep, yt as scan, z as pull } from "./index-BPYJOreI.mjs";
2
- import { r as Result } from "./types-BsimcHZS.mjs";
3
- import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "./index-D5q3I26j.mjs";
2
+ import { r as Result } from "./types-D8DevyLz.mjs";
3
+ import { a as todo, c as isOk, d as attempt, f as attemptAsync, i as unimplemented, l as ok, n as invariant, o as err, r as unreachable, s as isErr, t as assert, u as unwrap } from "./index-CmmSFDY_.mjs";
4
4
  import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./index-C7dxY5U-.mjs";
5
5
  import { AbortError, TimeoutError } from "./error/index.mjs";
6
6
  import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "./index-DlZyDxI_.mjs";
@@ -9,5 +9,5 @@ import { A as evolve, C as sortKeys, D as toMerged, E as toKebabCaseKeys, O as t
9
9
  import { A as isString, B as isNaN, C as isNull, D as isPromise, E as isPrimitive, F as isWeakSet, G as both, H as isObject, I as isArray, K as either, L as isEmpty, M as isTypedArray, N as isUndefined, O as isRegExp, P as isWeakMap, R as isFiniteNumber, S as isNotNil, T as isPlainObject, U as allPass, V as isNotEmpty, W as anyPass, _ as isJSONValue, a as isBuffer, b as isNil, c as isEqual, d as isFile, f as isFunction, g as isJSONObject, h as isJSONArray, i as isBrowser, j as isSymbol, k as isSet, l as isEqualWith, m as isJSON, n as isBlob, o as isDate, p as isIterable, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isLength, w as isNumber, x as isNode, y as isMap, z as isInteger } from "./index-D7DGVrkN.mjs";
10
10
  import { Mutex, Semaphore, allKeyed, delay, limitAsync, timeout, withTimeout } from "./promise/index.mjs";
11
11
  import { camelCase, capitalize, constantCase, deburr, dedent, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
12
- import { a as Err, i as match, n as Pattern, o as Ok, r as isMatching, s as P, t as NonExhaustiveError } from "./index-DcVpX2Bb.mjs";
12
+ import { a as Err, i as match, n as Pattern, o as Ok, r as isMatching, s as P, t as NonExhaustiveError } from "./index-BupTTOMT.mjs";
13
13
  export { AbortError, type DebounceOptions, type DebouncedFunction, type Err, type MemoizeCache, Mutex, NonExhaustiveError, type Ok, P, Pattern, type Result, Semaphore, type ThrottleOptions, type ThrottledFunction, TimeoutError, type ToCamelCaseKeys, type ToConstantCaseKeys, type ToKebabCaseKeys, type ToPascalCaseKeys, type ToSnakeCaseKeys, adjust, after, allKeyed, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, dedent, deepFreeze, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapKeysAsync, mapValues, mapValuesAsync, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortKeys, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toConstantCaseKeys, toError, toFilled, toFinite, toInteger, toKebabCaseKeys, toMerged, toNumber, toPascalCaseKeys, toSnakeCaseKeys, toString, todo, trim, trimEnd, trimStart, unary, unescape, unfold, unimplemented, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unreachable, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
package/dist/index.mjs CHANGED
@@ -7,6 +7,6 @@ import { A as isString, B as isNaN, C as isNull, D as isPromise, E as isPrimitiv
7
7
  import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./conversion-BB912-15.mjs";
8
8
  import { Mutex, Semaphore, allKeyed, delay, limitAsync, timeout, withTimeout } from "./promise/index.mjs";
9
9
  import { camelCase, capitalize, constantCase, deburr, dedent, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
10
- import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "./control-DCdm8IH6.mjs";
10
+ import { a as todo, c as err, d as ok, f as unwrap, i as unimplemented, l as isErr, n as invariant, o as attempt, r as unreachable, s as attemptAsync, t as assert, u as isOk } from "./control-DMCSi-hj.mjs";
11
11
  import { a as P, i as match, n as Pattern, r as isMatching, t as NonExhaustiveError } from "./match-fBetfaIa.mjs";
12
12
  export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allKeyed, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, dedent, deepFreeze, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapKeysAsync, mapValues, mapValuesAsync, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortKeys, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toConstantCaseKeys, toError, toFilled, toFinite, toInteger, toKebabCaseKeys, toMerged, toNumber, toPascalCaseKeys, toSnakeCaseKeys, toString, todo, trim, trimEnd, trimStart, unary, unescape, unfold, unimplemented, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unreachable, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
@@ -1,2 +1,2 @@
1
- import { a as Err, i as match, n as Pattern, o as Ok, r as isMatching, s as P, t as NonExhaustiveError } from "../index-DcVpX2Bb.mjs";
1
+ import { a as Err, i as match, n as Pattern, o as Ok, r as isMatching, s as P, t as NonExhaustiveError } from "../index-BupTTOMT.mjs";
2
2
  export { type Err, NonExhaustiveError, type Ok, P, Pattern, isMatching, match };
@@ -1 +1 @@
1
- {"version":3,"file":"match-fBetfaIa.mjs","names":["matchValue","P","TsP"],"sources":["../src/match/match.ts"],"sourcesContent":["/**\n * Extends ts-pattern's `P` namespace with `P.ok()` and `P.err()` — pattern\n * factories for matching a `Result` and its contained value or error.\n *\n * Mirrors Rust's `Ok(value)` / `Err(error)` match arms, but uses the\n * namespace-method form (`P.ok()` / `P.err()`) so it doesn't collide with\n * the lowercase `ok()` / `err()` constructors from `massaman/control`.\n *\n * @example\n * ```ts\n * import { match, P, attempt } from 'massaman'\n *\n * match(attempt(() => JSON.parse(raw)))\n * .with(P.ok(), ({ value }) => use(value))\n * .with(P.err(), ({ error }) => log(error))\n * .exhaustive()\n * ```\n */\n\nimport { match as matchValue, P as TsP } from 'ts-pattern'\n\nimport type { Err as ErrType, Ok as OkType } from '../control/types.js'\n\nfunction okPattern(): { ok: true }\nfunction okPattern<const pattern extends TsP.Pattern<unknown>>(\n pattern: pattern\n): { ok: true; value: pattern }\nfunction okPattern(\n ...patterns: readonly [] | readonly [TsP.Pattern<unknown>]\n): { ok: true } | { ok: true; value: TsP.Pattern<unknown> } {\n return matchValue(patterns)\n .with([], () => ({ ok: true as const }))\n .otherwise(([pattern]) => ({ ok: true as const, value: pattern }))\n}\n\nfunction errPattern(): { ok: false }\nfunction errPattern<const pattern extends TsP.Pattern<unknown>>(\n pattern: pattern\n): { ok: false; error: pattern }\nfunction errPattern(\n ...patterns: readonly [] | readonly [TsP.Pattern<unknown>]\n): { ok: false } | { ok: false; error: TsP.Pattern<unknown> } {\n return matchValue(patterns)\n .with([], () => ({ ok: false as const }))\n .otherwise(([pattern]) => ({ ok: false as const, error: pattern }))\n}\n\n/**\n * Extended ts-pattern `P` namespace. Carries everything ts-pattern exports\n * (`P.string`, `P.number`, `P.array`, `P.when`, …) plus `P.ok()` / `P.err()`\n * for matching `Result` values and their contents.\n *\n * For the `P.Pattern<T>` type shorthand, import `Pattern` standalone from\n * `massaman/match` — it's the form ts-pattern's own docs recommend.\n */\nexport const P: typeof TsP & { ok: typeof okPattern; err: typeof errPattern } = {\n ...TsP,\n ok: okPattern,\n err: errPattern,\n}\n\n/**\n * The `Ok` variant of a `Result<T>`. Re-exported here so the value-side\n * patterns and the type-side `Ok<T>` live in one module — any consumer\n * import gets both type and value namespaces without cross-module merge\n * issues (TS2300).\n */\nexport type Ok<T> = OkType<T>\n\n/**\n * The `Err` variant of a `Result<T>`. See {@link Ok} for the co-location note.\n */\nexport type Err = ErrType\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,UACP,GAAG,UACuD;CAC1D,OAAOA,MAAW,QAAQ,CAAC,CACxB,KAAK,CAAC,UAAU,EAAE,IAAI,KAAc,EAAE,CAAC,CACvC,WAAW,CAAC,cAAc;EAAE,IAAI;EAAe,OAAO;CAAQ,EAAE;AACrE;AAMA,SAAS,WACP,GAAG,UACyD;CAC5D,OAAOA,MAAW,QAAQ,CAAC,CACxB,KAAK,CAAC,UAAU,EAAE,IAAI,MAAe,EAAE,CAAC,CACxC,WAAW,CAAC,cAAc;EAAE,IAAI;EAAgB,OAAO;CAAQ,EAAE;AACtE;;;;;;;;;AAUA,MAAaC,MAAmE;CAC9E,GAAGC;CACH,IAAI;CACJ,KAAK;AACP"}
1
+ {"version":3,"file":"match-fBetfaIa.mjs","names":["matchValue","P","TsP"],"sources":["../src/match/match.ts"],"sourcesContent":["/**\n * Extends ts-pattern's `P` namespace with `P.ok()` and `P.err()` — pattern\n * factories for matching a `Result` and its contained value or error.\n *\n * Mirrors Rust's `Ok(value)` / `Err(error)` match arms, but uses the\n * namespace-method form (`P.ok()` / `P.err()`) so it doesn't collide with\n * the lowercase `ok()` / `err()` constructors from `massaman/control`.\n *\n * @example\n * ```ts\n * import { match, P, attempt } from 'massaman'\n *\n * match(attempt(() => JSON.parse(raw)))\n * .with(P.ok(), ({ value }) => use(value))\n * .with(P.err(), ({ error }) => log(error))\n * .exhaustive()\n * ```\n */\n\nimport { match as matchValue, P as TsP } from 'ts-pattern'\n\nimport type { Err as ErrType, Ok as OkType } from '../control/types.js'\n\nfunction okPattern(): { ok: true }\nfunction okPattern<const pattern extends TsP.Pattern<unknown>>(\n pattern: pattern\n): { ok: true; value: pattern }\nfunction okPattern(\n ...patterns: readonly [] | readonly [TsP.Pattern<unknown>]\n): { ok: true } | { ok: true; value: TsP.Pattern<unknown> } {\n return matchValue(patterns)\n .with([], () => ({ ok: true as const }))\n .otherwise(([pattern]) => ({ ok: true as const, value: pattern }))\n}\n\nfunction errPattern(): { ok: false }\nfunction errPattern<const pattern extends TsP.Pattern<unknown>>(\n pattern: pattern\n): { ok: false; error: pattern }\nfunction errPattern(\n ...patterns: readonly [] | readonly [TsP.Pattern<unknown>]\n): { ok: false } | { ok: false; error: TsP.Pattern<unknown> } {\n return matchValue(patterns)\n .with([], () => ({ ok: false as const }))\n .otherwise(([pattern]) => ({ ok: false as const, error: pattern }))\n}\n\n/**\n * Extended ts-pattern `P` namespace. Carries everything ts-pattern exports\n * (`P.string`, `P.number`, `P.array`, `P.when`, …) plus `P.ok()` / `P.err()`\n * for matching `Result` values and their contents.\n *\n * For the `P.Pattern<T>` type shorthand, import `Pattern` standalone from\n * `massaman/match` — it's the form ts-pattern's own docs recommend.\n */\nexport const P: typeof TsP & { ok: typeof okPattern; err: typeof errPattern } = {\n ...TsP,\n ok: okPattern,\n err: errPattern,\n}\n\n/**\n * The `Ok` variant of a `Result<T>`. Re-exported here so the value-side\n * patterns and the type-side `Ok<T>` live in one module — any consumer\n * import gets both type and value namespaces without cross-module merge\n * issues (TS2300).\n */\nexport type Ok<T> = OkType<T>\n\n/**\n * The `Err` variant of a `Result<T>`. See {@link Ok} for the co-location note.\n */\nexport type Err<E extends Error = Error> = ErrType<E>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,SAAS,UACP,GAAG,UACuD;CAC1D,OAAOA,MAAW,QAAQ,CAAC,CACxB,KAAK,CAAC,UAAU,EAAE,IAAI,KAAc,EAAE,CAAC,CACvC,WAAW,CAAC,cAAc;EAAE,IAAI;EAAe,OAAO;CAAQ,EAAE;AACrE;AAMA,SAAS,WACP,GAAG,UACyD;CAC5D,OAAOA,MAAW,QAAQ,CAAC,CACxB,KAAK,CAAC,UAAU,EAAE,IAAI,MAAe,EAAE,CAAC,CACxC,WAAW,CAAC,cAAc;EAAE,IAAI;EAAgB,OAAO;CAAQ,EAAE;AACtE;;;;;;;;;AAUA,MAAaC,MAAmE;CAC9E,GAAGC;CACH,IAAI;CACJ,KAAK;AACP"}
@@ -17,17 +17,21 @@ interface Ok<T> {
17
17
  *
18
18
  * @example
19
19
  * ```ts
20
- * const result: Err = { ok: false, error: new Error('fail') }
20
+ * const result: Err<TypeError> = {
21
+ * ok: false,
22
+ * value: null,
23
+ * error: new TypeError('fail'),
24
+ * }
21
25
  * ```
22
26
  */
23
- interface Err {
27
+ interface Err<E extends Error = Error> {
24
28
  readonly ok: false;
25
29
  readonly value: null;
26
- readonly error: Error;
30
+ readonly error: E;
27
31
  }
28
32
  /**
29
33
  * Discriminated union representing either success (`Ok`) or failure (`Err`).
30
- * Inspired by Rust's `Result<T, E>`, but errors are always `Error`.
34
+ * Inspired by Rust's `Result<T, E>`.
31
35
  *
32
36
  * @example
33
37
  * ```ts
@@ -36,7 +40,7 @@ interface Err {
36
40
  * }
37
41
  * ```
38
42
  */
39
- type Result<T> = Ok<T> | Err;
43
+ type Result<T, E extends Error = Error> = Ok<T> | Err<E>;
40
44
  //#endregion
41
45
  export { Ok as n, Result as r, Err as t };
42
- //# sourceMappingURL=types-BsimcHZS.d.mts.map
46
+ //# sourceMappingURL=types-D8DevyLz.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-D8DevyLz.d.mts","names":[],"sources":["../src/control/types.ts"],"mappings":";;;;;;;;;UAQiB,GAAG;WACT;WACA,OAAO;WACP;;;;;;;;;;;;;;UAeM,IAAI,UAAU,QAAQ;WAC5B;WACA;WACA,OAAO;;;;;;;;;;;;;KAcN,OAAO,GAAG,UAAU,QAAQ,SAAS,GAAG,KAAK,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "massaman",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "A comprehensive functional programming library and utilities for TypeScript",
5
5
  "keywords": [
6
6
  "es-toolkit",
@@ -1 +0,0 @@
1
- {"version":3,"file":"control-DCdm8IH6.mjs","names":[],"sources":["../src/control/result.ts","../src/control/attempt.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"sourcesContent":["import { isNil } from 'es-toolkit/predicate'\n\nimport type { Err, Ok, Result } from './types.js'\n\n/**\n * Minimal error coercion used internally by `err()`. Kept local to avoid\n * pulling the full conversion module into the `massaman/control` bundle.\n * For richer stringification (Maps, Sets, Errors with own props, circular\n * refs), import `toError` from `massaman/conversion`.\n */\nfunction coerceError(thrown: unknown): Error {\n if (thrown instanceof Error) {\n return thrown\n }\n if (typeof thrown === 'string') {\n return new Error(thrown)\n }\n try {\n const message = JSON.stringify(thrown) ?? String(thrown)\n return new Error(message, { cause: thrown })\n } catch {\n return new Error(String(thrown), { cause: thrown })\n }\n}\n\n/**\n * Creates a success result wrapping the given value.\n *\n * @param value - The success value\n * @returns An `Ok` result containing the value\n *\n * @example\n * ```ts\n * const result = ok(42)\n * // { ok: true, value: 42 }\n * ```\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value, error: null }\n}\n\n/**\n * Creates a failure result wrapping the given error.\n *\n * @param error - The error value\n * @returns An `Err` result containing the error\n *\n * @example\n * ```ts\n * const result = err(new Error('fail'))\n * // { ok: false, error: Error('fail') }\n * ```\n */\nexport function err(error: unknown): Err {\n return { ok: false, value: null, error: coerceError(error) }\n}\n\n/**\n * Type guard that narrows a `Result` to `Ok`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Ok`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{}'))\n * if (isOk(result)) {\n * console.log(result.value)\n * }\n * ```\n */\nexport function isOk<T>(result: Result<T>): result is Ok<T> {\n return result.ok === true\n}\n\n/**\n * Type guard that narrows a `Result` to `Err`.\n *\n * @param result - The result to check\n * @returns `true` if the result is `Err`\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('bad'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport function isErr<T>(result: Result<T>): result is Err {\n return result.ok === false\n}\n\n/**\n * Extract the value from an `Ok` result, or throw on `Err`.\n *\n * When called without a message, throws the original error.\n * When called with a message, throws a new Error with that message\n * and the original error as `cause` (like Rust's `expect`).\n *\n * @param result - The result to unwrap\n * @param message - Optional custom error message (Rust `expect` behavior)\n * @returns The unwrapped value\n *\n * @example\n * ```ts\n * const value = unwrap(ok(42)) // 42\n * unwrap(err('fail')) // throws Error('fail')\n * unwrap(err('fail'), 'config required') // throws Error('config required', { cause: Error('fail') })\n * ```\n */\nexport function unwrap<T>(result: Result<T>, message?: string): T {\n if (result.ok) {\n return result.value\n }\n if (!isNil(message)) {\n throw new Error(message, { cause: result.error })\n }\n throw result.error\n}\n","import { err, ok } from './result.js'\nimport type { Result } from './types.js'\n\n/**\n * Executes a synchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the return value on success, `Err` with the thrown value on failure.\n *\n * @param fn - The function to execute\n * @returns A `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = attempt(() => JSON.parse('{\"a\":1}'))\n * if (isOk(result)) {\n * console.log(result.value) // { a: 1 }\n * }\n * ```\n */\nexport function attempt<T>(fn: () => T): Result<T> {\n try {\n return ok(fn())\n } catch (error) {\n return err(error)\n }\n}\n\n/**\n * Executes an asynchronous function and wraps the outcome in a `Result`.\n * Returns `Ok` with the resolved value on success, `Err` with the rejection reason on failure.\n *\n * @param fn - The async function to execute\n * @returns A promise resolving to a `Result` containing either the value or the error\n *\n * @example\n * ```ts\n * const result = await attemptAsync(() => fetch('/api/data'))\n * if (isErr(result)) {\n * console.error(result.error)\n * }\n * ```\n */\nexport async function attemptAsync<T>(fn: () => Promise<T>): Promise<Result<T>> {\n try {\n return ok(await fn())\n } catch (error) {\n return err(error)\n }\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Stub for a code path you intend to write but haven't. Throws at runtime,\n * returns `never` so it typechecks in any position.\n *\n * For paths you intentionally don't support, see `unimplemented`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseConfig(raw: string): Config {\n * return todo('waiting on schema decision')\n * }\n * ```\n */\nexport function todo(message?: string): never {\n if (isNil(message)) {\n throw new Error('not yet implemented')\n }\n throw new Error(`not yet implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as intentionally unsupported. Throws at runtime, returns\n * `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths that should be impossible, see `unreachable`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * type Driver = 'postgres' | 'sqlite' | 'mysql'\n *\n * function migrate(driver: Driver): void {\n * return match(driver)\n * .with('postgres', runPgMigration)\n * .with('sqlite', runSqliteMigration)\n * .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))\n * .exhaustive()\n * }\n * ```\n */\nexport function unimplemented(message?: string): never {\n if (isNil(message)) {\n throw new Error('not implemented')\n }\n throw new Error(`not implemented: ${message}`)\n}\n","import { isNil } from 'es-toolkit/predicate'\n\n/**\n * Marks a code path as logically impossible. Throws at runtime if execution\n * gets there. Returns `never` so it typechecks in any position.\n *\n * For work you plan to finish later, see `todo`.\n * For paths you intentionally don't support, see `unimplemented`.\n *\n * @param message - Optional context appended to the thrown error\n * @returns Never returns — always throws\n *\n * @example\n * ```ts\n * function parseDigit(input: string): number {\n * const parsed = Number.parseInt(input, 10)\n * if (Number.isNaN(parsed)) {\n * return unreachable('caller pre-validated')\n * }\n * return parsed\n * }\n * ```\n */\nexport function unreachable(message?: string): never {\n if (isNil(message)) {\n throw new Error('entered unreachable code')\n }\n throw new Error(`entered unreachable code: ${message}`)\n}\n"],"mappings":";;;;;;;;;AAUA,SAAS,YAAY,QAAwB;CAC3C,IAAI,kBAAkB,OACpB,OAAO;CAET,IAAI,OAAO,WAAW,UACpB,OAAO,IAAI,MAAM,MAAM;CAEzB,IAAI;EACF,MAAM,UAAU,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM;EACvD,OAAO,IAAI,MAAM,SAAS,EAAE,OAAO,OAAO,CAAC;CAC7C,QAAQ;EACN,OAAO,IAAI,MAAM,OAAO,MAAM,GAAG,EAAE,OAAO,OAAO,CAAC;CACpD;AACF;;;;;;;;;;;;;AAcA,SAAgB,GAAM,OAAiB;CACrC,OAAO;EAAE,IAAI;EAAM;EAAO,OAAO;CAAK;AACxC;;;;;;;;;;;;;AAcA,SAAgB,IAAI,OAAqB;CACvC,OAAO;EAAE,IAAI;EAAO,OAAO;EAAM,OAAO,YAAY,KAAK;CAAE;AAC7D;;;;;;;;;;;;;;;AAgBA,SAAgB,KAAQ,QAAoC;CAC1D,OAAO,OAAO,OAAO;AACvB;;;;;;;;;;;;;;;AAgBA,SAAgB,MAAS,QAAkC;CACzD,OAAO,OAAO,OAAO;AACvB;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,OAAU,QAAmB,SAAqB;CAChE,IAAI,OAAO,IACT,OAAO,OAAO;CAEhB,IAAI,CAAC,MAAM,OAAO,GAChB,MAAM,IAAI,MAAM,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;CAElD,MAAM,OAAO;AACf;;;;;;;;;;;;;;;;;;ACrGA,SAAgB,QAAW,IAAwB;CACjD,IAAI;EACF,OAAO,GAAG,GAAG,CAAC;CAChB,SAAS,OAAO;EACd,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;AAiBA,eAAsB,aAAgB,IAA0C;CAC9E,IAAI;EACF,OAAO,GAAG,MAAM,GAAG,CAAC;CACtB,SAAS,OAAO;EACd,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;;;;;AC5BA,SAAgB,KAAK,SAAyB;CAC5C,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,qBAAqB;CAEvC,MAAM,IAAI,MAAM,wBAAwB,SAAS;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;ACCA,SAAgB,cAAc,SAAyB;CACrD,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,iBAAiB;CAEnC,MAAM,IAAI,MAAM,oBAAoB,SAAS;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;ACPA,SAAgB,YAAY,SAAyB;CACnD,IAAI,MAAM,OAAO,GACf,MAAM,IAAI,MAAM,0BAA0B;CAE5C,MAAM,IAAI,MAAM,6BAA6B,SAAS;AACxD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-D5q3I26j.d.mts","names":[],"sources":["../src/control/attempt.ts","../src/control/result.ts","../src/control/todo.ts","../src/control/unimplemented.ts","../src/control/unreachable.ts"],"mappings":";;;;;;;;;;;;;;;;;;iBAkBgB,QAAQ,GAAG,UAAU,IAAI,OAAO;;;;;;;;;;;;;;;;iBAuB1B,aAAa,GAAG,UAAU,QAAQ,KAAK,QAAQ,OAAO;;;;;;;;;;;;;;;iBCJ5D,GAAG,GAAG,OAAO,IAAI,GAAG;;;;;;;;;;;;;iBAgBpB,IAAI,iBAAiB;;;;;;;;;;;;;;;iBAkBrB,KAAK,GAAG,QAAQ,OAAO,KAAK,UAAU,GAAG;;;;;;;;;;;;;;;iBAkBzC,MAAM,GAAG,QAAQ,OAAO,KAAK,UAAU;;;;;;;;;;;;;;;;;;;iBAsBvC,OAAO,GAAG,QAAQ,OAAO,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;iBC5FhD,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;iBCML,cAAc;;;;;;;;;;;;;;;;;;;;;;;;iBCFd,YAAY"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-BsimcHZS.d.mts","names":[],"sources":["../src/control/types.ts"],"mappings":";;;;;;;;;UAQiB,GAAG;WACT;WACA,OAAO;WACP;;;;;;;;;;UAWM;WACN;WACA;WACA,OAAO;;;;;;;;;;;;;KAcN,OAAO,KAAK,GAAG,KAAK"}