massaman 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/control/index.d.mts +2 -2
- package/dist/control/index.mjs +2 -2
- package/dist/{control-B8mDJqXw.mjs → control-Dg2fwHB7.mjs} +81 -2
- package/dist/control-Dg2fwHB7.mjs.map +1 -0
- package/dist/{index-BHb3Vge_.d.mts → index-Bp3ol0vr.d.mts} +72 -2
- package/dist/index-Bp3ol0vr.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/control-B8mDJqXw.mjs.map +0 -1
- package/dist/index-BHb3Vge_.d.mts.map +0 -1
package/dist/control/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as Ok, r as Result, t as Err } from "../types-X6LqLWno.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
export { Err, Ok, Result, assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, unwrap };
|
|
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-Bp3ol0vr.mjs";
|
|
3
|
+
export { Err, Ok, Result, assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
|
package/dist/control/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, unwrap };
|
|
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-Dg2fwHB7.mjs";
|
|
2
|
+
export { assert, attempt, attemptAsync, err, invariant, isErr, isOk, ok, todo, unimplemented, unreachable, unwrap };
|
|
@@ -159,6 +159,85 @@ async function attemptAsync(fn) {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
//#endregion
|
|
162
|
-
|
|
162
|
+
//#region src/control/todo.ts
|
|
163
|
+
/**
|
|
164
|
+
* Stub for a code path you intend to write but haven't. Throws at runtime,
|
|
165
|
+
* returns `never` so it typechecks in any position.
|
|
166
|
+
*
|
|
167
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
168
|
+
* For paths that should be impossible, see `unreachable`.
|
|
169
|
+
*
|
|
170
|
+
* @param message - Optional context appended to the thrown error
|
|
171
|
+
* @returns Never returns — always throws
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* function parseConfig(raw: string): Config {
|
|
176
|
+
* return todo('waiting on schema decision')
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
function todo(message) {
|
|
181
|
+
if (isNil(message)) throw new Error("not yet implemented");
|
|
182
|
+
throw new Error(`not yet implemented: ${message}`);
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/control/unimplemented.ts
|
|
186
|
+
/**
|
|
187
|
+
* Marks a code path as intentionally unsupported. Throws at runtime, returns
|
|
188
|
+
* `never` so it typechecks in any position.
|
|
189
|
+
*
|
|
190
|
+
* For work you plan to finish later, see `todo`.
|
|
191
|
+
* For paths that should be impossible, see `unreachable`.
|
|
192
|
+
*
|
|
193
|
+
* @param message - Optional context appended to the thrown error
|
|
194
|
+
* @returns Never returns — always throws
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* type Driver = 'postgres' | 'sqlite' | 'mysql'
|
|
199
|
+
*
|
|
200
|
+
* function migrate(driver: Driver): void {
|
|
201
|
+
* return match(driver)
|
|
202
|
+
* .with('postgres', runPgMigration)
|
|
203
|
+
* .with('sqlite', runSqliteMigration)
|
|
204
|
+
* .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))
|
|
205
|
+
* .exhaustive()
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
function unimplemented(message) {
|
|
210
|
+
if (isNil(message)) throw new Error("not implemented");
|
|
211
|
+
throw new Error(`not implemented: ${message}`);
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/control/unreachable.ts
|
|
215
|
+
/**
|
|
216
|
+
* Marks a code path as logically impossible. Throws at runtime if execution
|
|
217
|
+
* gets there. Returns `never` so it typechecks in any position.
|
|
218
|
+
*
|
|
219
|
+
* For work you plan to finish later, see `todo`.
|
|
220
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
221
|
+
*
|
|
222
|
+
* @param message - Optional context appended to the thrown error
|
|
223
|
+
* @returns Never returns — always throws
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* function parseDigit(input: string): number {
|
|
228
|
+
* const parsed = Number.parseInt(input, 10)
|
|
229
|
+
* if (Number.isNaN(parsed)) {
|
|
230
|
+
* return unreachable('caller pre-validated')
|
|
231
|
+
* }
|
|
232
|
+
* return parsed
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
function unreachable(message) {
|
|
237
|
+
if (isNil(message)) throw new Error("entered unreachable code");
|
|
238
|
+
throw new Error(`entered unreachable code: ${message}`);
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
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 };
|
|
163
242
|
|
|
164
|
-
//# sourceMappingURL=control-
|
|
243
|
+
//# sourceMappingURL=control-Dg2fwHB7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-Dg2fwHB7.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,OAAO;CAE1B,IAAI;EACF,MAAM,UAAU,KAAK,UAAU,OAAO,IAAI,OAAO,OAAO;EACxD,OAAO,IAAI,MAAM,SAAS,EAAE,OAAO,QAAQ,CAAC;SACtC;E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AAyB;CACnD,IAAI,MAAM,QAAQ,EAChB,MAAM,IAAI,MAAM,2BAA2B;CAE7C,MAAM,IAAI,MAAM,6BAA6B,UAAU"}
|
|
@@ -112,5 +112,75 @@ declare function isErr<T>(result: Result<T>): result is Err;
|
|
|
112
112
|
*/
|
|
113
113
|
declare function unwrap<T>(result: Result<T>, message?: string): T;
|
|
114
114
|
//#endregion
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
//#region src/control/todo.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* Stub for a code path you intend to write but haven't. Throws at runtime,
|
|
118
|
+
* returns `never` so it typechecks in any position.
|
|
119
|
+
*
|
|
120
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
121
|
+
* For paths that should be impossible, see `unreachable`.
|
|
122
|
+
*
|
|
123
|
+
* @param message - Optional context appended to the thrown error
|
|
124
|
+
* @returns Never returns — always throws
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* function parseConfig(raw: string): Config {
|
|
129
|
+
* return todo('waiting on schema decision')
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function todo(message?: string): never;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/control/unimplemented.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* Marks a code path as intentionally unsupported. Throws at runtime, returns
|
|
138
|
+
* `never` so it typechecks in any position.
|
|
139
|
+
*
|
|
140
|
+
* For work you plan to finish later, see `todo`.
|
|
141
|
+
* For paths that should be impossible, see `unreachable`.
|
|
142
|
+
*
|
|
143
|
+
* @param message - Optional context appended to the thrown error
|
|
144
|
+
* @returns Never returns — always throws
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* type Driver = 'postgres' | 'sqlite' | 'mysql'
|
|
149
|
+
*
|
|
150
|
+
* function migrate(driver: Driver): void {
|
|
151
|
+
* return match(driver)
|
|
152
|
+
* .with('postgres', runPgMigration)
|
|
153
|
+
* .with('sqlite', runSqliteMigration)
|
|
154
|
+
* .with('mysql', () => unimplemented('mysql driver intentionally unsupported'))
|
|
155
|
+
* .exhaustive()
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function unimplemented(message?: string): never;
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/control/unreachable.d.ts
|
|
162
|
+
/**
|
|
163
|
+
* Marks a code path as logically impossible. Throws at runtime if execution
|
|
164
|
+
* gets there. Returns `never` so it typechecks in any position.
|
|
165
|
+
*
|
|
166
|
+
* For work you plan to finish later, see `todo`.
|
|
167
|
+
* For paths you intentionally don't support, see `unimplemented`.
|
|
168
|
+
*
|
|
169
|
+
* @param message - Optional context appended to the thrown error
|
|
170
|
+
* @returns Never returns — always throws
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* function parseDigit(input: string): number {
|
|
175
|
+
* const parsed = Number.parseInt(input, 10)
|
|
176
|
+
* if (Number.isNaN(parsed)) {
|
|
177
|
+
* return unreachable('caller pre-validated')
|
|
178
|
+
* }
|
|
179
|
+
* return parsed
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function unreachable(message?: string): never;
|
|
184
|
+
//#endregion
|
|
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 };
|
|
186
|
+
//# sourceMappingURL=index-Bp3ol0vr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Bp3ol0vr.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":";;;;;;;AAkBA;;;;;;;;;;;;iBAAgB,OAAA,GAAA,CAAW,EAAA,QAAU,CAAA,GAAI,MAAA,CAAO,CAAA;;;AAuBhD;;;;;;;;;;;;;iBAAsB,YAAA,GAAA,CAAgB,EAAA,QAAU,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,MAAA,CAAO,CAAA;;;;;;AAvB5E;;;;;;;;;iBCmBgB,EAAA,GAAA,CAAM,KAAA,EAAO,CAAA,GAAI,EAAA,CAAG,CAAA;;;;;;ADIpC;;;;;;;iBCYgB,GAAA,CAAI,KAAA,YAAiB,GAAA;;;;;;;;;;;;;;;iBAkBrB,IAAA,GAAA,CAAQ,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,EAAA,CAAG,CAAA;;;;;;;;;;;;;;;iBAkBzC,KAAA,GAAA,CAAS,MAAA,EAAQ,MAAA,CAAO,CAAA,IAAK,MAAA,IAAU,GAAA;;;;;AAlBvD;;;;;;;;;;;;;;iBAwCgB,MAAA,GAAA,CAAU,MAAA,EAAQ,MAAA,CAAO,CAAA,GAAI,OAAA,YAAmB,CAAA;;;;;;;AD7FhE;;;;;;;;;;;;;iBECgB,IAAA,CAAK,OAAA;;;;;;;AFDrB;;;;;;;;;;;;;;;AAuBA;;;;iBGhBgB,aAAA,CAAc,OAAA;;;;;;;AHP9B;;;;;;;;;;;;;;;AAuBA;;iBIlBgB,WAAA,CAAY,OAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "./index-mfIoxwxy.mjs";
|
|
2
2
|
import { r as Result } from "./types-X6LqLWno.mjs";
|
|
3
|
-
import { a as
|
|
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-Bp3ol0vr.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-BjmDP8W9.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-D5l6I7QH.mjs";
|
|
@@ -10,4 +10,4 @@ import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPr
|
|
|
10
10
|
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
11
11
|
import { camelCase, capitalize, constantCase, deburr, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
|
|
12
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-DtnKhaAD.mjs";
|
|
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, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, 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, 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, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
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, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, 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, 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, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, 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 isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPr
|
|
|
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-ByBXBR5i.mjs";
|
|
8
8
|
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
9
9
|
import { camelCase, capitalize, constantCase, deburr, 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
|
|
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-Dg2fwHB7.mjs";
|
|
11
11
|
import { a as P, i as match, n as Pattern, r as isMatching, t as NonExhaustiveError } from "./match-CG_v2C4Q.mjs";
|
|
12
|
-
export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, 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, 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, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
12
|
+
export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, 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, 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, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, 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/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"control-B8mDJqXw.mjs","names":[],"sources":["../src/control/result.ts","../src/control/attempt.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"],"mappings":";;;;;;;;;AAUA,SAAS,YAAY,QAAwB;CAC3C,IAAI,kBAAkB,OACpB,OAAO;CAET,IAAI,OAAO,WAAW,UACpB,OAAO,IAAI,MAAM,OAAO;CAE1B,IAAI;EACF,MAAM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