@resultsafe/core-fp-result 0.1.10 → 0.2.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/README.md CHANGED
@@ -1,305 +1,317 @@
1
- # @resultsafe/core-fp-result
2
-
3
- <a id="top"></a>
4
-
5
- > ✅ **Version 0.1.9** | UTF-8 encoded documentation | AI-optimized for developer collaboration
6
-
7
- ![ResultSafe Logo](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/docs/assets/logo.svg)
8
-
9
- [![npm version](https://img.shields.io/npm/v/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
10
- [![npm downloads](https://img.shields.io/npm/dm/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
11
- [![license](https://img.shields.io/npm/l/@resultsafe/core-fp-result.svg)](./LICENSE)
12
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6.svg)](https://www.typescriptlang.org/)
13
- [![docs](https://img.shields.io/badge/docs-api-informational.svg)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
14
- [![build status](https://img.shields.io/badge/build-local%20verified-success.svg)](./package.json)
15
- [![monorepo](https://img.shields.io/badge/monorepo-resultsafe%2Fmonorepo-0A0A0A.svg)](https://github.com/Livooon/resultsafe)
16
-
17
- A Rust-inspired Result package for explicit, composable, and type-friendly APIs in TypeScript and JavaScript.
18
-
19
- **Language:** English | [Русский](https://github.com/resultsafe/monorepo/blob/main/packages/core/fp/result/README.ru.md)
20
-
21
- **Documentation:** [API index](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md) · [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
22
-
23
- ---
24
- ## Contents
25
-
26
- - [Why this package](#why-this-package)
27
- - [Monorepo context](#monorepo-context)
28
- - [Key features](#key-features)
29
- - [Package](#package)
30
- - [Installation](#installation)
31
- - [Quick start](#quick-start)
32
- - [Core API overview](#core-api-overview)
33
- - [Build and distribution formats](#build-and-distribution-formats)
34
- - [Monorepo and package structure](#monorepo-and-package-structure)
35
- - [When to use this project](#when-to-use-this-project)
36
- - [Documentation links](#documentation-links)
37
- - [License](#license)
38
-
39
- ---
40
-
41
- ## Why this package
42
-
43
- `@resultsafe/core-fp-result` provides explicit success/error flows instead of hidden control paths and exception-first branching.
44
-
45
- Its core package, [`@resultsafe/core-fp-result`](https://www.npmjs.com/package/@resultsafe/core-fp-result), provides a Rust-inspired `Result` API for TypeScript and JavaScript with:
46
-
47
- - explicit `Ok` / `Err`
48
- - predictable functional composition
49
- - safe branching through guards and matching
50
- - disciplined extraction APIs
51
- - advanced refinement utilities for typed variants and strict matching
52
-
53
- The goal is not to imitate Rust mechanically, but to bring the same clarity of intent to Node.js libraries: explicit values, predictable branching, and APIs organized for long-term maintenance.
54
-
55
- ---
56
-
57
- ## Monorepo context
58
-
59
- `@resultsafe/core-fp-result` is the TypeScript/JavaScript package inside the multilingual `resultsafe/monorepo`.
60
-
61
- The monorepo applies shared Rust-inspired design concepts across language-specific packages. TypeScript/JavaScript is the current production package track, while Python is planned as a separate package track with the same conceptual model.
62
-
63
- ---
64
-
65
- ## Key features
66
-
67
- - Rust-inspired `Result` model for TypeScript and JavaScript.
68
- - Explicit constructors via `Ok` and `Err`.
69
- - Composable transformations with APIs such as `map`, `mapErr`, `andThen`, and `orElse`.
70
- - Safe branching through guards like `isOk`, `isErr`, `isOkAnd`, `isErrAnd`, and matching helpers.
71
- - Controlled extraction with `unwrap`, `unwrapOr`, `unwrapErr`, `expect`, and `expectErr`.
72
- - Advanced refinement layer for typed variants, strict matching, and result narrowing.
73
- - Coherent module structure instead of a flat utility dump.
74
- - Type output for TypeScript users for better DX and safer integrations.
75
- - Flexible distribution formats with Types, ESM, CJS, and UMD builds.
76
-
77
- ---
78
-
79
- ## Package
80
-
81
- ### `@resultsafe/core-fp-result`
82
-
83
- A focused Result library for explicit error handling and FP-style composition.
84
-
85
- It is designed for developers who want:
86
-
87
- - clear success/error modeling
88
- - predictable transformations
89
- - explicit branching and extraction
90
- - better readability in error-heavy flows
91
- - a structured Rust-inspired API surface in TypeScript/JavaScript
92
-
93
- ---
94
-
95
- ## Installation
96
-
97
- ### Package
98
-
99
- ```bash
100
- pnpm add @resultsafe/core-fp-result
101
-
102
- # Alternative
103
- npm install @resultsafe/core-fp-result
104
- ```
105
-
106
- ### Monorepo
107
-
108
- ```bash
109
- pnpm install
110
- ```
111
-
112
- ---
113
-
114
- ## Quick start
115
-
116
- A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
117
-
118
- ```ts
119
- import {
120
- Ok,
121
- map,
122
- unwrapOr,
123
- } from "@resultsafe/core-fp-result";
124
-
125
- const initial = Ok(21);
126
- const doubled = map(initial, (value) => value * 2);
127
- const finalValue = unwrapOr(doubled, 0);
128
-
129
- console.log(finalValue); // 42
130
- ```
131
-
132
- ### Basic `Ok` / `Err` example
133
-
134
- ```ts
135
- import { Ok, Err, match } from "@resultsafe/core-fp-result";
136
-
137
- const parsePort = (input: string) => {
138
- const port = Number(input);
139
- return Number.isInteger(port) && port > 0
140
- ? Ok(port)
141
- : Err("Invalid port");
142
- };
143
-
144
- const result = parsePort("3000");
145
- const message = match(result, (value) => `Port: ${value}`, (error) => `Error: ${error}`);
146
-
147
- console.log(message);
148
- ```
149
-
150
- ---
151
-
152
- <!-- AI-AGENT: Each function has 3 links: Source (GitHub UI), Raw (direct code), Code (new UI) -->
153
- <!-- Raw links are best for automated code analysis and parsing -->
154
-
155
- ## Core API overview
156
-
157
- ### Core Types
158
-
159
- - [`Result<T, E>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts) — Success/failure container [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts "View raw code")
160
- - [`Option<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts) — Optional value container [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts "View raw code")
161
-
162
- ### Type Helpers
163
-
164
- - [`VariantConfig`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) — Variant configuration [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts "View raw code")
165
- - [`PayloadKeys<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts) — Extract payload keys [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/PayloadKeys.ts "View raw code")
166
- - [`ValidatorFn<T>`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) — Sync validator function [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts "View raw code")
167
- - [`AsyncValidatorFn`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) — Async validator function [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts "View raw code")
168
-
169
- ### Constructors
170
-
171
- - [`Ok`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts) — Create success result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts "View raw code")
172
- - [`Err`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts) — Create error result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts "View raw code")
173
-
174
- ### Guards
175
-
176
- - [`isOk`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts) — Check if success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts "View raw code")
177
- - [`isErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts) Check if error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts "View raw code")
178
- - [`isOkAnd`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOkAnd.ts) — Check success with predicate [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOkAnd.ts "View raw code")
179
- - [`isErrAnd`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErrAnd.ts) — Check error with predicate [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErrAnd.ts "View raw code")
180
-
181
- ### Methods
182
-
183
- #### Transformation
184
-
185
- - [`map`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts) — Transform success value [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts "View raw code")
186
- - [`mapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts) Transform error value [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts "View raw code")
187
-
188
- #### Chaining
189
-
190
- - [`andThen`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts) — Chain computations returning Result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts "View raw code")
191
- - [`orElse`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts) — Recover from error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts "View raw code")
192
-
193
- #### Extraction
194
-
195
- - [`unwrap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts) — Extract value or throw [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts "View raw code")
196
- - [`unwrapOr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts) — Extract value or default [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts "View raw code")
197
- - [`unwrapOrElse`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOrElse.ts) — Extract value or compute default [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOrElse.ts "View raw code")
198
- - [`unwrapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapErr.ts) Extract error or throw [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapErr.ts "View raw code")
199
- - [`expect`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts) — Extract value or throw with message [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts "View raw code")
200
- - [`expectErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expectErr.ts) Extract error or throw with message [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expectErr.ts "View raw code")
201
-
202
- #### Side Effects
203
-
204
- - [`tap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts) — Side effect on success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts "View raw code")
205
- - [`tapErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts) — Side effect on error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts "View raw code")
206
- - [`inspect`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspect.ts) Debug on success [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspect.ts "View raw code")
207
- - [`inspectErr`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspectErr.ts) — Debug on error [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/inspectErr.ts "View raw code")
208
-
209
- #### Advanced
210
-
211
- - [`match`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts) Pattern matching [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts "View raw code")
212
- - [`flatten`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts) — Flatten nested Result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts "View raw code")
213
- - [`transpose`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts) — Result<Option> → Option<Result> [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts "View raw code")
214
- - [`ok`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/ok.ts) Convert to Option (success) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/ok.ts "View raw code")
215
- - [`err`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/err.ts) Convert to Option (error) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/err.ts "View raw code")
216
-
217
- ### Refiners
218
-
219
- - [`isTypedVariant`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) Type guard for variant [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts "View raw code")
220
- - [`isTypedVariantOf`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts) — Type guard with variant map [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariantOf.ts "View raw code")
221
- - [`matchVariant`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts) — Match variant with handlers [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts "View raw code")
222
- - [`matchVariantStrict`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) Strict variant matching [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts "View raw code")
223
- - [`refineAsyncResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) — Async result refinement [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts "View raw code")
224
- - [`refineAsyncResultU`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts) Async refinement (uncurried) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResultU.ts "View raw code")
225
- - [`refineResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts) Synchronous result refinement [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts "View raw code")
226
- - [`refineResultU`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResultU.ts) — Synchronous refinement (uncurried) [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResultU.ts "View raw code")
227
- - [`refineVariantMap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineVariantMap.ts) Refine variant map [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineVariantMap.ts "View raw code")
228
-
229
- ### Type aliases
230
-
231
- - [`Handler`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Handler.ts) Match handler type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Handler.ts "View raw code")
232
- - [`MatchBuilder`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts) — Match builder type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/MatchBuilder.ts "View raw code")
233
- - [`Matcher`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Matcher.ts) — Matcher function type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/Matcher.ts "View raw code")
234
- - [`SyncRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts) Synchronous refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResult.ts "View raw code")
235
- - [`SyncRefinedResultUnion`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts) — Union of refined results [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncRefinedResultUnion.ts "View raw code")
236
- - [`SyncValidatorMap`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts) Validator map type [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/SyncValidatorMap.ts "View raw code")
237
- - [`UniversalAsyncRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts) Async refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalAsyncRefinedResult.ts "View raw code")
238
- - [`UniversalRefinedResult`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts) Universal refined result [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/UniversalRefinedResult.ts "View raw code")
239
- - [`VariantOf`](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/VariantOf.ts) — Variant type helper [🔗](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/types/VariantOf.ts "View raw code")
240
-
241
- ---
242
-
243
- ## Build and distribution formats
244
-
245
- - Types: `build:types`
246
- - ESM: `build:esm`
247
- - CJS: `build:cjs`
248
- - UMD: `build:umd`
249
-
250
- This package ships typed declarations and multiple runtime module formats for broad compatibility.
251
-
252
- ---
253
-
254
- ## Monorepo and package structure
255
-
256
- ```txt
257
- src/
258
- constructors/
259
- guards/
260
- methods/
261
- refiners/
262
- types/
263
- utils/
264
- internal/
265
- index.ts
266
- ```
267
-
268
- ---
269
-
270
- ## When to use this project
271
-
272
- Use this project when you want:
273
-
274
- - explicit success/error modeling
275
- - predictable FP-style composition
276
- - visible control flow
277
- - stronger type-guided result handling in TypeScript
278
- - advanced refinement tools for typed variants and strict result matching
279
-
280
- ---
281
-
282
- ## Documentation links
283
-
284
- - [API entry (README)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
285
- - [API entry (index)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/index.md)
286
- - [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
287
- - [Constructors module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md)
288
- - [Guards module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md)
289
- - [Methods module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md)
290
- - [Refiners module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
291
- - [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
292
-
293
- ---
294
- Back to top: [@resultsafe/core-fp-result](#top)
295
-
296
- ---
297
- ## Author
298
-
299
- Denis Savasteev
300
-
301
- ---
302
-
303
- ## License
304
-
305
- [MIT](./LICENSE)
1
+ # @resultsafe/core-fp-result
2
+
3
+ <a id="top"></a>
4
+
5
+ ![ResultSafe Logo](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/docs/assets/logo.svg)
6
+
7
+ ## 🤖 AI Context
8
+
9
+ This package implements the `Result<T, E>` pattern for explicit error handling without `try/catch`.
10
+
11
+ - **Rust analogue:** `std::result::Result`
12
+ - **Scala analogue:** `Either`
13
+ - **Core principle:** Error is a value, not an exception.
14
+
15
+ [![npm version](https://img.shields.io/npm/v/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
16
+ [![npm downloads](https://img.shields.io/npm/dm/@resultsafe/core-fp-result.svg)](https://www.npmjs.com/package/@resultsafe/core-fp-result)
17
+ [![license](https://img.shields.io/npm/l/@resultsafe/core-fp-result.svg)](./LICENSE)
18
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6.svg)](https://www.typescriptlang.org/)
19
+ [![docs](https://img.shields.io/badge/docs-api-informational.svg)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
20
+ [![build status](https://img.shields.io/badge/build-local%20verified-success.svg)](./package.json)
21
+ [![monorepo](https://img.shields.io/badge/monorepo-resultsafe%2Fmonorepo-0A0A0A.svg)](https://github.com/Livooon/resultsafe)
22
+
23
+ A Rust-inspired Result package for explicit, composable, and type-friendly APIs in TypeScript and JavaScript.
24
+
25
+ **Language:** English | [Русский](https://github.com/resultsafe/monorepo/blob/main/packages/core/fp/result/README.ru.md)
26
+
27
+ **Documentation:** [API index](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md) · [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
28
+
29
+ ---
30
+
31
+ ## Contents
32
+
33
+ - [Why this package](#why-this-package)
34
+ - [Monorepo context](#monorepo-context)
35
+ - [Key features](#key-features)
36
+ - [Package](#package)
37
+ - [Installation](#installation)
38
+ - [Quick start](#quick-start)
39
+ - [Core API overview](#core-api-overview)
40
+ - [Build and distribution formats](#build-and-distribution-formats)
41
+ - [Monorepo and package structure](#monorepo-and-package-structure)
42
+ - [When to use this project](#when-to-use-this-project)
43
+ - [Documentation links](#documentation-links)
44
+ - [License](#license)
45
+
46
+ ---
47
+
48
+ ## Why this package
49
+
50
+ `@resultsafe/core-fp-result` provides explicit success/error flows instead of hidden control paths and exception-first branching.
51
+
52
+ Its core package, [`@resultsafe/core-fp-result`](https://www.npmjs.com/package/@resultsafe/core-fp-result), provides a Rust-inspired `Result` API for TypeScript and JavaScript with:
53
+
54
+ - explicit `Ok` / `Err`
55
+ - predictable functional composition
56
+ - safe branching through guards and matching
57
+ - disciplined extraction APIs
58
+ - advanced refinement utilities for typed variants and strict matching
59
+
60
+ The goal is not to imitate Rust mechanically, but to bring the same clarity of intent to Node.js libraries: explicit values, predictable branching, and APIs organized for long-term maintenance.
61
+
62
+ ---
63
+
64
+ ## Monorepo context
65
+
66
+ `@resultsafe/core-fp-result` is the TypeScript/JavaScript package inside the multilingual `resultsafe/monorepo`.
67
+
68
+ The monorepo applies shared Rust-inspired design concepts across language-specific packages. TypeScript/JavaScript is the current production package track, while Python is planned as a separate package track with the same conceptual model.
69
+
70
+ ---
71
+
72
+ ## Key features
73
+
74
+ - Rust-inspired `Result` model for TypeScript and JavaScript.
75
+ - Explicit constructors via `Ok` and `Err`.
76
+ - Composable transformations with APIs such as `map`, `mapErr`, `andThen`, and `orElse`.
77
+ - Safe branching through guards like `isOk`, `isErr`, `isOkAnd`, `isErrAnd`, and matching helpers.
78
+ - Controlled extraction with `unwrap`, `unwrapOr`, `unwrapErr`, `expect`, and `expectErr`.
79
+ - Advanced refinement layer for typed variants, strict matching, and result narrowing.
80
+ - Coherent module structure instead of a flat utility dump.
81
+ - Type output for TypeScript users for better DX and safer integrations.
82
+ - Flexible distribution formats with Types, ESM, CJS, and UMD builds.
83
+
84
+ ---
85
+
86
+ ## Package
87
+
88
+ ### `@resultsafe/core-fp-result`
89
+
90
+ A focused Result library for explicit error handling and FP-style composition.
91
+
92
+ It is designed for developers who want:
93
+
94
+ - clear success/error modeling
95
+ - predictable transformations
96
+ - explicit branching and extraction
97
+ - better readability in error-heavy flows
98
+ - a structured Rust-inspired API surface in TypeScript/JavaScript
99
+
100
+ ---
101
+
102
+ ## Installation
103
+
104
+ ### Package
105
+
106
+ ```bash
107
+ pnpm add @resultsafe/core-fp-result
108
+
109
+ # Alternative
110
+ npm install @resultsafe/core-fp-result
111
+ ```
112
+
113
+ ### Monorepo
114
+
115
+ ```bash
116
+ pnpm install
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Quick start
122
+
123
+ A typical Result flow starts with explicit constructors and then composes through functions rather than implicit exception paths.
124
+
125
+ ```ts
126
+ import { Ok, map, unwrapOr } from '@resultsafe/core-fp-result';
127
+
128
+ const initial = Ok(21);
129
+ const doubled = map(initial, (value) => value * 2);
130
+ const finalValue = unwrapOr(doubled, 0);
131
+
132
+ console.log(finalValue); // 42
133
+ ```
134
+
135
+ ### Basic `Ok` / `Err` example
136
+
137
+ ```ts
138
+ import { Ok, Err, match } from '@resultsafe/core-fp-result';
139
+
140
+ const parsePort = (input: string) => {
141
+ const port = Number(input);
142
+ return Number.isInteger(port) && port > 0 ? Ok(port) : Err('Invalid port');
143
+ };
144
+
145
+ const result = parsePort('3000');
146
+ const message = match(
147
+ result,
148
+ (value) => `Port: ${value}`,
149
+ (error) => `Error: ${error}`,
150
+ );
151
+
152
+ console.log(message);
153
+ ```
154
+
155
+ ---
156
+
157
+ ## API Reference
158
+
159
+ ### Core Functions
160
+
161
+ | Function | Signature | Description | GitHub | Raw |
162
+ | ----------- | ----------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
163
+ | `Ok` | `(value: T) => Result<T, E>` | Success constructor | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Ok.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Ok.ts) |
164
+ | `Err` | `(error: E) => Result<T, E>` | Error constructor | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/constructors/Err.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/constructors/Err.ts) |
165
+ | `match` | `(r, onOk, onErr) => U` | Branch on result | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/match.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/match.ts) |
166
+ | `andThen` | `(r, fn) => Result<U, E>` | Chain (flatMap) | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/andThen.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/andThen.ts) |
167
+ | `map` | `(r, fn) => Result<U, E>` | Transform success value | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/map.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/map.ts) |
168
+ | `mapErr` | `(r, fn) => Result<T, U>` | Transform error value | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/mapErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/mapErr.ts) |
169
+ | `orElse` | `(r, fn) => Result<T, U>` | Recover from error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/orElse.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/orElse.ts) |
170
+ | `unwrap` | `(r) => T` | Extract value or throw | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrap.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrap.ts) |
171
+ | `unwrapOr` | `(r, fallback: T) => T` | Extract value or default | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/unwrapOr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/unwrapOr.ts) |
172
+ | `expect` | `(r, msg: string) => T` | Extract value or throw with message | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/expect.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/expect.ts) |
173
+ | `isOk` | `(r) => boolean` | Check if success | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isOk.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isOk.ts) |
174
+ | `isErr` | `(r) => boolean` | Check if error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/guards/isErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/guards/isErr.ts) |
175
+ | `tap` | `(r, fn) => Result<T, E>` | Side effect on success | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tap.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tap.ts) |
176
+ | `tapErr` | `(r, fn) => Result<T, E>` | Side effect on error | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/tapErr.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/tapErr.ts) |
177
+ | `transpose` | `(r) => Option<Result<T, E>>` | Result<Option> to Option<Result> | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/transpose.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/transpose.ts) |
178
+ | `flatten` | `(r) => Result<T, E>` | Flatten nested Result | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/methods/flatten.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/methods/flatten.ts) |
179
+
180
+ ### Advanced: Refiners
181
+
182
+ | Function | Description | GitHub | Raw |
183
+ | -------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
184
+ | `isTypedVariant` | Type guard for variant | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/isTypedVariant.ts) |
185
+ | `matchVariant` | Match variant with handlers | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariant.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariant.ts) |
186
+ | `matchVariantStrict` | Strict variant matching | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/matchVariantStrict.ts) |
187
+ | `refineResult` | Sync result refinement | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineResult.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineResult.ts) |
188
+ | `refineAsyncResult` | Async result refinement | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/refiners/refineAsyncResult.ts) |
189
+
190
+ ### Type Aliases
191
+
192
+ | Type | Description | GitHub | Raw |
193
+ | ------------------ | ----------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
194
+ | `Result<T, E>` | Base success/error type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Result.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Result.ts) |
195
+ | `Option<T>` | Optional value type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/core/Option.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/core/Option.ts) |
196
+ | `VariantConfig` | Variant configuration type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/VariantConfig.ts) |
197
+ | `ValidatorFn<T>` | Sync validator function type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/ValidatorFn.ts) |
198
+ | `AsyncValidatorFn` | Async validator function type | [🔗](https://github.com/Livooon/resultsafe/blob/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) | [📄](https://raw.githubusercontent.com/Livooon/resultsafe/main/packages/core/fp/result/src/types/refiners/AsyncValidatorFn.ts) |
199
+
200
+ > **Full API:** [All modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md) · [Constructors](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md) · [Guards](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md) · [Methods](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md) · [Refiners](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
201
+
202
+ ---
203
+
204
+ ## Examples
205
+
206
+ ### Example 1: Basic Usage
207
+
208
+ ```typescript
209
+ import { Ok, Err, match } from '@resultsafe/core-fp-result';
210
+
211
+ const result = Ok(42);
212
+ match(
213
+ result,
214
+ (value) => console.log(value),
215
+ (error) => console.error(error),
216
+ );
217
+ ```
218
+
219
+ ### Example 2: Error Handling
220
+
221
+ ```typescript
222
+ import { Ok, Err } from '@resultsafe/core-fp-result';
223
+
224
+ const divide = (a: number, b: number) =>
225
+ b === 0 ? Err('Division by zero') : Ok(a / b);
226
+
227
+ const result = divide(10, 0);
228
+ // Err("Division by zero")
229
+ ```
230
+
231
+ ### Example 3: Chaining Operations
232
+
233
+ ```typescript
234
+ import { Ok, andThen, map } from '@resultsafe/core-fp-result';
235
+
236
+ const result = Ok(5);
237
+ const doubled = andThen(result, (x) => Ok(x * 2));
238
+ const squared = map(doubled, (x) => x ** 2);
239
+ ```
240
+
241
+ ---
242
+
243
+ ## Ecosystem
244
+
245
+ - `@resultsafe/core-fp-option` — Option/Maybe type
246
+ - `@resultsafe/core-fp-either` — Either type
247
+ - `@resultsafe/core-fp-result` — This package (Result type)
248
+
249
+ All packages follow the same API design pattern.
250
+
251
+ ---
252
+
253
+ ## Build and distribution formats
254
+
255
+ - Types: `build:types`
256
+ - ESM: `build:esm`
257
+ - CJS: `build:cjs`
258
+ - UMD: `build:umd`
259
+
260
+ This package ships typed declarations and multiple runtime module formats for broad compatibility.
261
+
262
+ ---
263
+
264
+ ## Monorepo and package structure
265
+
266
+ ```txt
267
+ src/
268
+ constructors/
269
+ guards/
270
+ methods/
271
+ refiners/
272
+ types/
273
+ utils/
274
+ internal/
275
+ index.ts
276
+ ```
277
+
278
+ ---
279
+
280
+ ## When to use this project
281
+
282
+ Use this project when you want:
283
+
284
+ - explicit success/error modeling
285
+ - predictable FP-style composition
286
+ - visible control flow
287
+ - stronger type-guided result handling in TypeScript
288
+ - advanced refinement tools for typed variants and strict result matching
289
+
290
+ ---
291
+
292
+ ## Documentation links
293
+
294
+ - [API entry (README)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/README.md)
295
+ - [API entry (index)](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/index.md)
296
+ - [Modules](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/modules.md)
297
+ - [Constructors module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/constructors/index.md)
298
+ - [Guards module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/guards/index.md)
299
+ - [Methods module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/methods/index.md)
300
+ - [Refiners module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/refiners/index.md)
301
+ - [Type aliases module](https://unpkg.com/@resultsafe/core-fp-result@latest/docs/api/type-aliases/index.md)
302
+
303
+ ---
304
+
305
+ Back to top: [@resultsafe/core-fp-result](#top)
306
+
307
+ ---
308
+
309
+ ## Author
310
+
311
+ Denis Savasteev
312
+
313
+ ---
314
+
315
+ ## License
316
+
317
+ [MIT](./LICENSE)
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resultsafe/core-fp-result",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./cjs/index.js",
package/types/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './constructors/index.js';
2
2
  export * from './guards/index.js';
3
3
  export * from './methods/index.js';
4
4
  export * from './refiners/index.js';
5
+ export * from './shared-types.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -1,5 +1,13 @@
1
1
  import type { VariantOf } from './VariantOf.js';
2
- /** Описывает запись обработчика варианта во внутренних механизмах matcher. @internal */
2
+ /**
3
+ * Describes a handler entry for variant matching in internal matcher mechanisms.
4
+ *
5
+ * @typeParam K - The variant key type.
6
+ * @typeParam T - The variant union type.
7
+ * @typeParam R - The return type of the handler function.
8
+ *
9
+ * @internal
10
+ */
3
11
  export type Handler<K extends string, T extends VariantOf<K>, R> = {
4
12
  readonly variant: K;
5
13
  readonly fn: (value: Extract<T, {
@@ -1 +1 @@
1
- {"version":3,"file":"Handler.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/Handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,wFAAwF;AACxF,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,CAAC;CACpD,CAAC"}
1
+ {"version":3,"file":"Handler.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/Handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,CAAC;CACpD,CAAC"}
@@ -1,5 +1,24 @@
1
1
  import type { VariantOf } from './VariantOf.js';
2
- /** Описывает форму строгого builder для matcher. */
2
+ /**
3
+ * Describes the shape of a strict builder for variant matching.
4
+ *
5
+ * @typeParam T - The variant union type.
6
+ * @typeParam R - The return type of the match operation.
7
+ * @typeParam Handled - The union of already handled variant types.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { MatchBuilder } from '@resultsafe/core-fp-result';
12
+ *
13
+ * const builder: MatchBuilder<MyVariant, string> = {
14
+ * with: (variant, fn) => builder,
15
+ * run: () => 'result'
16
+ * };
17
+ * ```
18
+ *
19
+ * @since 0.1.8
20
+ * @public
21
+ */
3
22
  export type MatchBuilder<T extends VariantOf, R, Handled extends T['type'] = never> = {
4
23
  readonly with: <K extends Exclude<T['type'], Handled>>(variant: K, fn: (value: Extract<T, {
5
24
  type: K;
@@ -1 +1 @@
1
- {"version":3,"file":"MatchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/MatchBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,oDAAoD;AACpD,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,SAAS,EACnB,CAAC,EACD,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,IAC/B;IACF,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EACnD,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,KACtC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;CAC3D,CAAC"}
1
+ {"version":3,"file":"MatchBuilder.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/MatchBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,YAAY,CACtB,CAAC,SAAS,SAAS,EACnB,CAAC,EACD,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,IAC/B;IACF,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EACnD,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,KACtC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;CAC3D,CAAC"}
@@ -1,5 +1,27 @@
1
1
  import type { VariantOf } from './VariantOf.js';
2
- /** Описывает форму нестрогого builder для matcher. */
2
+ /**
3
+ * Describes the shape of a non-strict builder for variant matching.
4
+ *
5
+ * @typeParam T - The variant union type.
6
+ * @typeParam R - The return type of the match operation.
7
+ *
8
+ * @remarks
9
+ * Unlike {@link MatchBuilder}, this builder allows matching any variant
10
+ * and provides an `otherwise` fallback handler for unmatched cases.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Matcher } from '@resultsafe/core-fp-result';
15
+ *
16
+ * const matcher: Matcher<MyVariant, string> = {
17
+ * with: (variant, fn) => matcher,
18
+ * otherwise: (fn) => ({ run: () => 'default' })
19
+ * };
20
+ * ```
21
+ *
22
+ * @since 0.1.8
23
+ * @public
24
+ */
3
25
  export type Matcher<T extends VariantOf, R> = {
4
26
  readonly with: <K extends T['type']>(variant: K, fn: (value: Extract<T, {
5
27
  type: K;
@@ -1 +1 @@
1
- {"version":3,"file":"Matcher.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/Matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,sDAAsD;AACtD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,IAAI;IAC5C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EACjC,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,KACtC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CACxE,CAAC"}
1
+ {"version":3,"file":"Matcher.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/Matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,IAAI;IAC5C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EACjC,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KAAK,CAAC,KACtC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CACxE,CAAC"}
@@ -1,5 +1,27 @@
1
1
  import type { PayloadKeys, ValidatorFn, VariantConfig } from '../../shared-types.js';
2
- /** Описывает синхронно уточненное конкретное значение варианта. */
2
+ /**
3
+ * Describes a synchronously refined specific variant value.
4
+ *
5
+ * @typeParam K - The variant key type.
6
+ * @typeParam TMap - The variant configuration map.
7
+ * @typeParam _TValidators - The validator map for the variant.
8
+ *
9
+ * @remarks
10
+ * This type represents a refined variant with its payload fields
11
+ * validated synchronously. The `type` field discriminates the variant,
12
+ * and the remaining fields are the validated payload.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { SyncRefinedResult, VariantConfig } from '@resultsafe/core-fp-result';
17
+ *
18
+ * type MyVariant = SyncRefinedResult<'user', { user: { payload: 'name' } }, {}>;
19
+ * // { type: 'user'; name: unknown }
20
+ * ```
21
+ *
22
+ * @since 0.1.8
23
+ * @public
24
+ */
3
25
  export type SyncRefinedResult<K extends keyof TMap & string, TMap extends Record<string, VariantConfig>, _TValidators extends Partial<Record<PayloadKeys<TMap[K]>, ValidatorFn>>> = {
4
26
  type: K;
5
27
  } & Record<PayloadKeys<TMap[K]>, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"SyncRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,mEAAmE;AACnE,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IACrE;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"SyncRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,IACrE;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC"}
@@ -1,7 +1,30 @@
1
1
  import type { VariantConfig } from '../../shared-types.js';
2
2
  import type { SyncRefinedResult } from './SyncRefinedResult.js';
3
3
  import type { SyncValidatorMap } from './SyncValidatorMap.js';
4
- /** Описывает объединение синхронно уточненных вариантов. */
4
+ /**
5
+ * Describes a union of synchronously refined variants.
6
+ *
7
+ * @typeParam TMap - The variant configuration map.
8
+ * @typeParam TValidators - The validator map for all variants.
9
+ *
10
+ * @remarks
11
+ * This type represents the union of all refined variants in the map.
12
+ * Each variant is refined using {@link SyncRefinedResult}.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { SyncRefinedResultUnion, VariantConfig } from '@resultsafe/core-fp-result';
17
+ *
18
+ * type Variants = SyncRefinedResultUnion<
19
+ * { user: { payload: 'name' }; error: { payload: 'code' } },
20
+ * {}
21
+ * >;
22
+ * // { type: 'user'; name: unknown } | { type: 'error'; code: unknown }
23
+ * ```
24
+ *
25
+ * @since 0.1.8
26
+ * @public
27
+ */
5
28
  export type SyncRefinedResultUnion<TMap extends Record<string, VariantConfig>, TValidators extends SyncValidatorMap<TMap>> = {
6
29
  [K in keyof TMap & string]: SyncRefinedResult<K, TMap, NonNullable<TValidators[K]>>;
7
30
  }[keyof TMap & string];
@@ -1 +1 @@
1
- {"version":3,"file":"SyncRefinedResultUnion.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncRefinedResultUnion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,4DAA4D;AAC5D,MAAM,MAAM,sBAAsB,CAChC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,WAAW,SAAS,gBAAgB,CAAC,IAAI,CAAC,IACxC;KACD,CAAC,IAAI,MAAM,IAAI,GAAG,MAAM,GAAG,iBAAiB,CAC3C,CAAC,EACD,IAAI,EACJ,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAC5B;CACF,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"SyncRefinedResultUnion.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncRefinedResultUnion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,sBAAsB,CAChC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,WAAW,SAAS,gBAAgB,CAAC,IAAI,CAAC,IACxC;KACD,CAAC,IAAI,MAAM,IAAI,GAAG,MAAM,GAAG,iBAAiB,CAC3C,CAAC,EACD,IAAI,EACJ,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAC5B;CACF,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC"}
@@ -1,5 +1,27 @@
1
1
  import type { PayloadKeys, ValidatorFn, VariantConfig } from '../../shared-types.js';
2
- /** Описывает наборы валидаторов, сгруппированные по ключу варианта. */
2
+ /**
3
+ * Describes validator sets grouped by variant key.
4
+ *
5
+ * @typeParam TMap - The variant configuration map.
6
+ *
7
+ * @remarks
8
+ * This type maps each variant to its optional validators for payload fields.
9
+ * Validators are used to refine and check variant data at runtime.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { SyncValidatorMap, VariantConfig } from '@resultsafe/core-fp-result';
14
+ *
15
+ * type Validators = SyncValidatorMap<{
16
+ * user: { payload: 'name' | 'age' };
17
+ * error: { payload: 'code' };
18
+ * }>;
19
+ * // { user?: { name?: ValidatorFn; age?: ValidatorFn }; error?: { code?: ValidatorFn } }
20
+ * ```
21
+ *
22
+ * @since 0.1.8
23
+ * @public
24
+ */
3
25
  export type SyncValidatorMap<TMap extends Record<string, VariantConfig>> = {
4
26
  [K in keyof TMap]?: Partial<Record<PayloadKeys<TMap[K]>, ValidatorFn>>;
5
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SyncValidatorMap.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncValidatorMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,uEAAuE;AACvE,MAAM,MAAM,gBAAgB,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI;KACxE,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;CACvE,CAAC"}
1
+ {"version":3,"file":"SyncValidatorMap.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/SyncValidatorMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,gBAAgB,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI;KACxE,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;CACvE,CAAC"}
@@ -1,5 +1,31 @@
1
1
  import type { VariantConfig } from '../../shared-types.js';
2
- /** Описывает обобщенное асинхронно уточненное значение варианта. */
2
+ /**
3
+ * Describes a generalized asynchronously refined variant value.
4
+ *
5
+ * @typeParam K - The variant key type.
6
+ * @typeParam TMap - The variant configuration map.
7
+ * @typeParam _TValidators - The validator map for the variant.
8
+ *
9
+ * @remarks
10
+ * This type represents a variant refined through async validation.
11
+ * The `type` field discriminates the variant, and additional fields
12
+ * are validated asynchronously.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { UniversalAsyncRefinedResult, VariantConfig } from '@resultsafe/core-fp-result';
17
+ *
18
+ * type AsyncVariant = UniversalAsyncRefinedResult<
19
+ * 'user',
20
+ * { user: { payload: 'name' } },
21
+ * {}
22
+ * >;
23
+ * // { type: 'user'; [key: string]: unknown }
24
+ * ```
25
+ *
26
+ * @since 0.1.8
27
+ * @public
28
+ */
3
29
  export type UniversalAsyncRefinedResult<K extends keyof TMap & string, TMap extends Record<string, VariantConfig>, _TValidators extends Record<string, unknown>> = {
4
30
  type: K;
5
31
  } & Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"UniversalAsyncRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/UniversalAsyncRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,oEAAoE;AACpE,MAAM,MAAM,2BAA2B,CACrC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC1C;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"UniversalAsyncRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/UniversalAsyncRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,2BAA2B,CACrC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC1C;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -1,5 +1,31 @@
1
1
  import type { VariantConfig } from '../../shared-types.js';
2
- /** Описывает обобщенное синхронно уточненное значение варианта. */
2
+ /**
3
+ * Describes a generalized synchronously refined variant value.
4
+ *
5
+ * @typeParam K - The variant key type.
6
+ * @typeParam TMap - The variant configuration map.
7
+ * @typeParam _TValidators - The validator map for the variant.
8
+ *
9
+ * @remarks
10
+ * This type represents a variant refined through sync validation.
11
+ * The `type` field discriminates the variant, and additional fields
12
+ * are validated synchronously.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { UniversalRefinedResult, VariantConfig } from '@resultsafe/core-fp-result';
17
+ *
18
+ * type SyncVariant = UniversalRefinedResult<
19
+ * 'user',
20
+ * { user: { payload: 'name' } },
21
+ * {}
22
+ * >;
23
+ * // { type: 'user'; [key: string]: unknown }
24
+ * ```
25
+ *
26
+ * @since 0.1.8
27
+ * @public
28
+ */
3
29
  export type UniversalRefinedResult<K extends keyof TMap & string, TMap extends Record<string, VariantConfig>, _TValidators extends Record<string, unknown>> = {
4
30
  type: K;
5
31
  } & Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"UniversalRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/UniversalRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,mEAAmE;AACnE,MAAM,MAAM,sBAAsB,CAChC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC1C;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"UniversalRefinedResult.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/UniversalRefinedResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,sBAAsB,CAChC,CAAC,SAAS,MAAM,IAAI,GAAG,MAAM,EAC7B,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC1C,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC1C;IACF,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -1,4 +1,23 @@
1
- /** Описывает минимальный контракт дискриминированного объединения. */
1
+ /**
2
+ * Describes the minimal contract for a discriminated union variant.
3
+ *
4
+ * @typeParam K - The variant key type. Defaults to `string`.
5
+ *
6
+ * @remarks
7
+ * This type is used as a constraint for variant unions. Each variant
8
+ * must have a `type` field that serves as the discriminator.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { VariantOf } from '@resultsafe/core-fp-result';
13
+ *
14
+ * type MyVariant = VariantOf<'user' | 'error'>;
15
+ * // { type: 'user' } | { type: 'error' }
16
+ * ```
17
+ *
18
+ * @since 0.1.8
19
+ * @public
20
+ */
2
21
  export type VariantOf<K extends string = string> = {
3
22
  type: K;
4
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"VariantOf.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/VariantOf.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"VariantOf.d.ts","sourceRoot":"","sources":["../../../../src/refiners/types/VariantOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC"}
@@ -1,3 +1,42 @@
1
+ /**
2
+ * Represents the result of an operation that can either succeed with a
3
+ * value of type `T` or fail with an error of type `E`.
4
+ *
5
+ * @summary
6
+ * Represents the result of an operation that can either succeed with a
7
+ * value of type `T` or fail with an error of type `E`.
8
+ *
9
+ * @remarks
10
+ * `Result` is the core type of this library. Pattern match on the `ok`
11
+ * field to narrow the union, then access `value` or `error` safely.
12
+ *
13
+ * Unlike exceptions, `Result` makes the failure path explicit in the
14
+ * type signature, forcing the caller to handle both outcomes.
15
+ *
16
+ * @typeParam T - The type of the success value.
17
+ * @typeParam E - The type of the error.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { Result, Ok, Err } from '@resultsafe/core-fp-result';
22
+ *
23
+ * function divide(a: number, b: number): Result<number, string> {
24
+ * if (b === 0) return Err("Division by zero");
25
+ * return Ok(a / b);
26
+ * }
27
+ *
28
+ * const result = divide(10, 2);
29
+ *
30
+ * if (result.ok) {
31
+ * console.log(result.value); // 5
32
+ * } else {
33
+ * console.error(result.error);
34
+ * }
35
+ * ```
36
+ *
37
+ * @since 0.1.8
38
+ * @public
39
+ */
1
40
  export type Result<T, E> = {
2
41
  readonly ok: true;
3
42
  readonly value: T;
@@ -5,18 +44,121 @@ export type Result<T, E> = {
5
44
  readonly ok: false;
6
45
  readonly error: E;
7
46
  };
47
+ /**
48
+ * Represents an optional value that can either contain a value of type `T`
49
+ * or be empty.
50
+ *
51
+ * @summary
52
+ * Represents an optional value that can either contain a value of type `T`
53
+ * or be empty.
54
+ *
55
+ * @remarks
56
+ * `Option` is used to represent the presence or absence of a value. It is
57
+ * an alternative to `null` or `undefined` that is type-safe and explicit.
58
+ *
59
+ * @typeParam T - The type of the contained value.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { Option } from '@resultsafe/core-fp-result';
64
+ *
65
+ * const someValue: Option<number> = { some: true, value: 42 };
66
+ * const noValue: Option<number> = { some: false };
67
+ * ```
68
+ *
69
+ * @since 0.1.8
70
+ * @public
71
+ */
8
72
  export type Option<T> = {
9
73
  readonly some: true;
10
74
  readonly value: T;
11
75
  } | {
12
76
  readonly some: false;
13
77
  };
78
+ /**
79
+ * Configuration options for variant validation.
80
+ *
81
+ * @remarks
82
+ * Used to configure how variants are validated, including payload keys
83
+ * and field strictness.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { VariantConfig } from '@resultsafe/core-fp-result';
88
+ *
89
+ * const config: VariantConfig = {
90
+ * payload: ['name', 'age'],
91
+ * forbidden: 'id',
92
+ * strictFields: true
93
+ * };
94
+ * ```
95
+ *
96
+ * @since 0.1.8
97
+ * @public
98
+ */
14
99
  export interface VariantConfig {
15
100
  readonly payload: 'never' | string | readonly string[];
16
101
  readonly forbidden?: string | undefined;
17
102
  readonly strictFields?: boolean | undefined;
18
103
  }
104
+ /**
105
+ * Extracts the payload keys from a `VariantConfig`.
106
+ *
107
+ * @typeParam T - The `VariantConfig` type to extract keys from.
108
+ * @returns The union of payload keys, or `never` if payload is `'never'`.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import { PayloadKeys, VariantConfig } from '@resultsafe/core-fp-result';
113
+ *
114
+ * type Config = { payload: 'name' | 'age'; forbidden?: string };
115
+ * type Keys = PayloadKeys<Config>; // 'name' | 'age'
116
+ * ```
117
+ *
118
+ * @since 0.1.8
119
+ * @public
120
+ */
19
121
  export type PayloadKeys<T extends VariantConfig> = T['payload'] extends 'never' ? never : T['payload'] extends string ? T['payload'] : T['payload'] extends readonly string[] ? T['payload'][number] : never;
122
+ /**
123
+ * A synchronous validator function that checks if a value is of a specific type.
124
+ *
125
+ * @typeParam T - The type the validator checks for.
126
+ * @param x - The value to validate.
127
+ * @returns `true` if `x` is of type `T`, `false` otherwise.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { ValidatorFn } from '@resultsafe/core-fp-result';
132
+ *
133
+ * const isNumber: ValidatorFn<number> = (x): x is number =>
134
+ * typeof x === 'number';
135
+ *
136
+ * console.log(isNumber(42)); // true
137
+ * console.log(isNumber('42')); // false
138
+ * ```
139
+ *
140
+ * @since 0.1.8
141
+ * @public
142
+ */
20
143
  export type ValidatorFn<T = unknown> = (x: unknown) => x is T;
144
+ /**
145
+ * An asynchronous validator function that checks if a value is valid.
146
+ *
147
+ * @param value - The value to validate.
148
+ * @returns A promise that resolves to `true` if valid, `false` otherwise.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { AsyncValidatorFn } from '@resultsafe/core-fp-result';
153
+ *
154
+ * const isValidId: AsyncValidatorFn = async (value) => {
155
+ * // Simulate async database check
156
+ * return typeof value === 'string' && value.length > 0;
157
+ * };
158
+ * ```
159
+ *
160
+ * @since 0.1.8
161
+ * @public
162
+ */
21
163
  export type AsyncValidatorFn = (value: unknown) => Promise<boolean>;
22
164
  //# sourceMappingURL=shared-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/shared-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,MAAM,CAAC,CAAC,IAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7B,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,aAAa,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,OAAO,GAC3E,KAAK,GACL,CAAC,CAAC,SAAS,CAAC,SAAS,MAAM,GACzB,CAAC,CAAC,SAAS,CAAC,GACZ,CAAC,CAAC,SAAS,CAAC,SAAS,SAAS,MAAM,EAAE,GACpC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GACpB,KAAK,CAAC;AAEd,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;AAE9D,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"shared-types.d.ts","sourceRoot":"","sources":["../../src/shared-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAChB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC1C;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,aAAa,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,OAAO,GAC3E,KAAK,GACL,CAAC,CAAC,SAAS,CAAC,SAAS,MAAM,GACzB,CAAC,CAAC,SAAS,CAAC,GACZ,CAAC,CAAC,SAAS,CAAC,SAAS,SAAS,MAAM,EAAE,GACpC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GACpB,KAAK,CAAC;AAEd;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC"}