@resultsafe/core-fp-result 0.1.7 → 0.1.8
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 +73 -44
- package/README.ru.md +111 -87
- package/cjs/constructors/Err.js.map +1 -1
- package/cjs/constructors/Ok.js.map +1 -1
- package/cjs/guards/isErr.js.map +1 -1
- package/cjs/guards/isErrAnd.js.map +1 -1
- package/cjs/guards/isOk.js.map +1 -1
- package/cjs/guards/isOkAnd.js.map +1 -1
- package/cjs/methods/andThen.js.map +1 -1
- package/cjs/methods/err.js.map +1 -1
- package/cjs/methods/expect.js.map +1 -1
- package/cjs/methods/expectErr.js.map +1 -1
- package/cjs/methods/flatten.js.map +1 -1
- package/cjs/methods/inspect.js.map +1 -1
- package/cjs/methods/inspectErr.js.map +1 -1
- package/cjs/methods/map.js.map +1 -1
- package/cjs/methods/mapErr.js.map +1 -1
- package/cjs/methods/match.js.map +1 -1
- package/cjs/methods/ok.js.map +1 -1
- package/cjs/methods/orElse.js.map +1 -1
- package/cjs/methods/tap.js.map +1 -1
- package/cjs/methods/tapErr.js.map +1 -1
- package/cjs/methods/transpose.js.map +1 -1
- package/cjs/methods/unwrap.js.map +1 -1
- package/cjs/methods/unwrapErr.js.map +1 -1
- package/cjs/methods/unwrapOr.js.map +1 -1
- package/cjs/methods/unwrapOrElse.js.map +1 -1
- package/cjs/refiners/refineAsyncResult.js.map +1 -1
- package/cjs/refiners/refineAsyncResultU.js.map +1 -1
- package/cjs/refiners/refineResult.js.map +1 -1
- package/cjs/refiners/refineResultU.js.map +1 -1
- package/cjs/refiners/refineVariantMap.js.map +1 -1
- package/cjs/refiners/utils/getPayloadKeys.js.map +1 -1
- package/docs/_category_.json +3 -3
- package/docs/assets/logo.svg +0 -0
- package/docs/examples/_category_.json +1 -1
- package/docs/examples/auth/_category_.json +1 -1
- package/docs/examples/auth/index.md +1 -1
- package/docs/examples/connection/_category_.json +1 -1
- package/docs/examples/connection/connect.md +1 -1
- package/docs/examples/connection/index.md +1 -1
- package/docs/examples/connection/reconnect.md +1 -1
- package/docs/examples/errors/_category_.json +1 -1
- package/docs/examples/errors/index.md +1 -1
- package/docs/examples/errors/retry.md +1 -1
- package/docs/examples/index.md +1 -1
- package/docs/examples/streaming/_category_.json +1 -1
- package/docs/examples/streaming/index.md +1 -1
- package/docs/examples/streaming/text.md +1 -1
- package/docs/meta/AI-AGENT-RULES.md +265 -0
- package/docs/meta/CONTEXT.md +70 -0
- package/docs/meta/MANIFEST.md +58 -0
- package/docs/meta/registry/COUNTERS.md +29 -0
- package/docs/meta/registry/ENTITIES.md +30 -0
- package/esm/constructors/Err.js.map +1 -1
- package/esm/constructors/Ok.js.map +1 -1
- package/esm/guards/isErr.js.map +1 -1
- package/esm/guards/isErrAnd.js.map +1 -1
- package/esm/guards/isOk.js.map +1 -1
- package/esm/guards/isOkAnd.js.map +1 -1
- package/esm/methods/andThen.js.map +1 -1
- package/esm/methods/err.js.map +1 -1
- package/esm/methods/expect.js.map +1 -1
- package/esm/methods/expectErr.js.map +1 -1
- package/esm/methods/flatten.js.map +1 -1
- package/esm/methods/inspect.js.map +1 -1
- package/esm/methods/inspectErr.js.map +1 -1
- package/esm/methods/map.js.map +1 -1
- package/esm/methods/mapErr.js.map +1 -1
- package/esm/methods/match.js.map +1 -1
- package/esm/methods/ok.js.map +1 -1
- package/esm/methods/orElse.js.map +1 -1
- package/esm/methods/tap.js.map +1 -1
- package/esm/methods/tapErr.js.map +1 -1
- package/esm/methods/transpose.js.map +1 -1
- package/esm/methods/unwrap.js.map +1 -1
- package/esm/methods/unwrapErr.js.map +1 -1
- package/esm/methods/unwrapOr.js.map +1 -1
- package/esm/methods/unwrapOrElse.js.map +1 -1
- package/esm/refiners/refineAsyncResult.js.map +1 -1
- package/esm/refiners/refineAsyncResultU.js.map +1 -1
- package/esm/refiners/refineResult.js.map +1 -1
- package/esm/refiners/refineResultU.js.map +1 -1
- package/esm/refiners/refineVariantMap.js.map +1 -1
- package/esm/refiners/utils/getPayloadKeys.js.map +1 -1
- package/package.json +1 -1
- package/types/guards/isErrAnd.d.ts.map +1 -1
- package/types/guards/isOkAnd.d.ts.map +1 -1
- package/types/methods/andThen.d.ts.map +1 -1
- package/types/methods/err.d.ts.map +1 -1
- package/types/methods/expect.d.ts.map +1 -1
- package/types/methods/expectErr.d.ts.map +1 -1
- package/types/methods/inspect.d.ts.map +1 -1
- package/types/methods/inspectErr.d.ts.map +1 -1
- package/types/methods/map.d.ts.map +1 -1
- package/types/methods/mapErr.d.ts.map +1 -1
- package/types/methods/ok.d.ts.map +1 -1
- package/types/methods/orElse.d.ts.map +1 -1
- package/types/methods/tapErr.d.ts.map +1 -1
- package/types/methods/transpose.d.ts.map +1 -1
- package/types/methods/unwrap.d.ts.map +1 -1
- package/types/methods/unwrapErr.d.ts.map +1 -1
- package/types/methods/unwrapOr.d.ts.map +1 -1
- package/types/refiners/refineAsyncResult.d.ts.map +1 -1
- package/types/refiners/refineAsyncResultU.d.ts.map +1 -1
- package/types/refiners/refineResult.d.ts.map +1 -1
- package/types/refiners/refineResultU.d.ts.map +1 -1
- package/types/refiners/refineVariantMap.d.ts.map +1 -1
- package/types/refiners/types/SyncRefinedResultUnion.d.ts.map +1 -1
- package/types/refiners/utils/getPayloadKeys.d.ts.map +1 -1
- package/types/types/core/Option.d.ts +43 -0
- package/types/types/core/Option.d.ts.map +1 -0
- package/types/types/core/Result.d.ts +58 -0
- package/types/types/core/Result.d.ts.map +1 -0
- package/types/types/index.d.ts +7 -0
- package/types/types/index.d.ts.map +1 -0
- package/types/types/refiners/AsyncValidatorFn.d.ts +21 -0
- package/types/types/refiners/AsyncValidatorFn.d.ts.map +1 -0
- package/types/types/refiners/PayloadKeys.d.ts +20 -0
- package/types/types/refiners/PayloadKeys.d.ts.map +1 -0
- package/types/types/refiners/ValidatorFn.d.ts +23 -0
- package/types/types/refiners/ValidatorFn.d.ts.map +1 -0
- package/types/types/refiners/VariantConfig.d.ts +27 -0
- package/types/types/refiners/VariantConfig.d.ts.map +1 -0
- package/umd/resultsafe-monorepo-core-fp-result.umd.js.map +1 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# AI-Agent Rules for @resultsafe/core-fp-result
|
|
2
|
+
|
|
3
|
+
> Quick reference for AI agents and developers working on this package.
|
|
4
|
+
> Read this before modifying any code in `src/`.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Quick Reference
|
|
9
|
+
|
|
10
|
+
| Task | Command |
|
|
11
|
+
|------|---------|
|
|
12
|
+
| Run tests | `pnpm test` |
|
|
13
|
+
| Run lint | `pnpm lint` |
|
|
14
|
+
| Auto-fix lint | `pnpm lint:fix` |
|
|
15
|
+
| TypeDoc check | `pnpm docs:api:check` |
|
|
16
|
+
| Build all | `pnpm build:all` |
|
|
17
|
+
| Verify release | `pnpm verify:release` |
|
|
18
|
+
| Add changeset | `pnpm changeset:add:result` (from root) |
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## @since Rules
|
|
23
|
+
|
|
24
|
+
**ALL exported symbols MUST have `@since` tag.**
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
/**
|
|
28
|
+
* Represents the result of an operation.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam T - The success type.
|
|
31
|
+
* @typeParam E - The error type.
|
|
32
|
+
* @since 0.1.8
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export type Result<T, E> = ...
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**ESLint auto-adds `@since`** with current version from `package.json` (currently `0.1.8`).
|
|
39
|
+
|
|
40
|
+
**Workflow:**
|
|
41
|
+
```bash
|
|
42
|
+
# 1. Write export with JSDoc
|
|
43
|
+
export const myFn = () => {};
|
|
44
|
+
|
|
45
|
+
# 2. Run auto-fix
|
|
46
|
+
pnpm lint:fix
|
|
47
|
+
|
|
48
|
+
# 3. Verify @since was added
|
|
49
|
+
pnpm lint # should pass
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## File Structure
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
src/
|
|
58
|
+
├── types/ ← Type definitions
|
|
59
|
+
│ ├── core/
|
|
60
|
+
│ │ ├── Result.ts # Main Result type
|
|
61
|
+
│ │ └── Option.ts # Option type
|
|
62
|
+
│ └── refiners/
|
|
63
|
+
│ ├── VariantConfig.ts
|
|
64
|
+
│ ├── PayloadKeys.ts
|
|
65
|
+
│ ├── ValidatorFn.ts
|
|
66
|
+
│ └── AsyncValidatorFn.ts
|
|
67
|
+
├── constructors/
|
|
68
|
+
│ ├── Ok.ts # Success constructor
|
|
69
|
+
│ └── Err.ts # Error constructor
|
|
70
|
+
├── guards/
|
|
71
|
+
│ ├── isOk.ts # Success type guard
|
|
72
|
+
│ ├── isErr.ts # Error type guard
|
|
73
|
+
│ ├── isOkAnd.ts # Success + predicate
|
|
74
|
+
│ └── isErrAnd.ts # Error + predicate
|
|
75
|
+
├── methods/
|
|
76
|
+
│ ├── map.ts # Transform success
|
|
77
|
+
│ ├── mapErr.ts # Transform error
|
|
78
|
+
│ ├── andThen.ts # Chain computations
|
|
79
|
+
│ ├── orElse.ts # Recover from error
|
|
80
|
+
│ ├── match.ts # Pattern matching
|
|
81
|
+
│ ├── tap.ts # Side effect (success)
|
|
82
|
+
│ ├── tapErr.ts # Side effect (error)
|
|
83
|
+
│ ├── flatten.ts # Flatten nested Result
|
|
84
|
+
│ ├── inspect.ts # Debug (success)
|
|
85
|
+
│ ├── inspectErr.ts # Debug (error)
|
|
86
|
+
│ ├── unwrap.ts # Extract or throw
|
|
87
|
+
│ ├── unwrapOr.ts # Extract or default
|
|
88
|
+
│ ├── unwrapOrElse.ts # Extract or compute
|
|
89
|
+
│ ├── unwrapErr.ts # Extract error or throw
|
|
90
|
+
│ ├── expect.ts # Extract or custom message
|
|
91
|
+
│ ├── expectErr.ts # Extract error or message
|
|
92
|
+
│ ├── ok.ts # To Option (success)
|
|
93
|
+
│ ├── err.ts # To Option (error)
|
|
94
|
+
│ └── transpose.ts # Result<Option> → Option<Result>
|
|
95
|
+
└── refiners/
|
|
96
|
+
├── refineResult.ts # Synchronous refiner
|
|
97
|
+
├── refineAsyncResult.ts # Asynchronous refiner
|
|
98
|
+
├── refineVariantMap.ts # Variant refinement
|
|
99
|
+
└── types/ # Refiner type definitions
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Type Safety
|
|
105
|
+
|
|
106
|
+
### Local Type Definitions
|
|
107
|
+
|
|
108
|
+
`Result` and `Option` are defined **locally** in `src/types/core/`:
|
|
109
|
+
|
|
110
|
+
- `src/types/core/Result.ts` — main type definition
|
|
111
|
+
- `src/types/core/Option.ts` — option type definition
|
|
112
|
+
|
|
113
|
+
These are **not re-exports** — they are full definitions with complete JSDoc.
|
|
114
|
+
This ensures:
|
|
115
|
+
- Type safety for guard functions
|
|
116
|
+
- Complete documentation in TypeDoc output
|
|
117
|
+
- AI agents see full context without cross-package navigation
|
|
118
|
+
|
|
119
|
+
### Guard Functions
|
|
120
|
+
|
|
121
|
+
Guard functions must preserve TypeScript type narrowing:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// ✅ Correct
|
|
125
|
+
export const isOk = <T, E>(
|
|
126
|
+
result: Result<T, E>,
|
|
127
|
+
): result is { ok: true; value: T } => result.ok === true;
|
|
128
|
+
|
|
129
|
+
// ❌ Wrong — loses type narrowing
|
|
130
|
+
export const isOk = <T, E>(result: Result<T, E>): boolean => result.ok === true;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## JSDoc Requirements
|
|
136
|
+
|
|
137
|
+
Per [SPEC-003](../../../../docs/specs/SPEC-003-typedoc-documentation-standard.md):
|
|
138
|
+
|
|
139
|
+
| Element | Required |
|
|
140
|
+
|---------|----------|
|
|
141
|
+
| Summary (1-3 sentences) | ✅ |
|
|
142
|
+
| @typeParam (for generics) | ✅ |
|
|
143
|
+
| @param (for functions) | ✅ |
|
|
144
|
+
| @returns (for functions) | ✅ |
|
|
145
|
+
| @throws (if applicable) | ✅ |
|
|
146
|
+
| @since | ✅ (auto-added) |
|
|
147
|
+
| @example | ✅ |
|
|
148
|
+
| @public | ✅ |
|
|
149
|
+
|
|
150
|
+
**Language:** English only. No Russian, Chinese, or other languages.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Testing Requirements
|
|
155
|
+
|
|
156
|
+
Per [SPEC-001](../../../../docs/specs/SPEC-001-tdd-development-standard.md):
|
|
157
|
+
|
|
158
|
+
- **TDD mandatory**: Write failing test first
|
|
159
|
+
- **Both branches**: Test Ok AND Err cases
|
|
160
|
+
- **Type-level tests**: For generic functions and guards
|
|
161
|
+
- **Contract compliance**: Reference SPEC-NNN in test comments
|
|
162
|
+
|
|
163
|
+
**Test structure:**
|
|
164
|
+
```
|
|
165
|
+
__tests__/
|
|
166
|
+
├── unit/
|
|
167
|
+
│ ├── constructors/
|
|
168
|
+
│ ├── guards/
|
|
169
|
+
│ ├── methods/
|
|
170
|
+
│ └── types/
|
|
171
|
+
└── integration/
|
|
172
|
+
└── types/
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Signal Markers
|
|
178
|
+
|
|
179
|
+
Use these markers when human review is needed:
|
|
180
|
+
|
|
181
|
+
```markdown
|
|
182
|
+
<!-- @since-MISSING: export 'transform' has no @since tag -->
|
|
183
|
+
Use when: ESLint rule is disabled or auto-fix failed
|
|
184
|
+
|
|
185
|
+
<!-- @since-OUTDATED: @since 0.1.0 but package is 0.1.8 -->
|
|
186
|
+
Use when: Existing @since is older (DO NOT FIX — historical record)
|
|
187
|
+
|
|
188
|
+
<!-- TDD-VIOLATION: wrote implementation before test -->
|
|
189
|
+
Use when: TDD sequence was broken
|
|
190
|
+
|
|
191
|
+
<!-- CONTRACT-MISSING: no SPEC for symbol X -->
|
|
192
|
+
Use when: Implementing but no language-neutral contract exists
|
|
193
|
+
|
|
194
|
+
<!-- PARITY-VIOLATION: impl deviates from SPEC-NNN -->
|
|
195
|
+
Use when: Implementation doesn't match contract
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Common Tasks
|
|
201
|
+
|
|
202
|
+
### Add new method
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# 1. Create test file
|
|
206
|
+
touch __tests__/unit/methods/myMethod.test.ts
|
|
207
|
+
|
|
208
|
+
# 2. Write failing test (RED)
|
|
209
|
+
# 3. Write implementation (GREEN)
|
|
210
|
+
# 4. Run lint:fix (adds @since)
|
|
211
|
+
# 5. Run tests
|
|
212
|
+
pnpm test
|
|
213
|
+
|
|
214
|
+
# 6. Create changeset
|
|
215
|
+
cd ../../../../ # to monorepo root
|
|
216
|
+
pnpm changeset:add:result
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Update existing method
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# 1. Update test
|
|
223
|
+
# 2. Update implementation
|
|
224
|
+
# 3. Update JSDoc (if signature changed)
|
|
225
|
+
# 4. Run all checks
|
|
226
|
+
pnpm test && pnpm lint && pnpm docs:api:check
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Debug type issues
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Check TypeDoc validation
|
|
233
|
+
pnpm docs:api:check
|
|
234
|
+
|
|
235
|
+
# Check TypeScript types
|
|
236
|
+
pnpm build:types
|
|
237
|
+
|
|
238
|
+
# Check exports
|
|
239
|
+
pnpm test __tests__/unit/exports/
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Related Documents
|
|
245
|
+
|
|
246
|
+
| Document | Purpose |
|
|
247
|
+
|----------|---------|
|
|
248
|
+
| [SPEC-001](../../../../docs/specs/SPEC-001-tdd-development-standard.md) | TDD development standard |
|
|
249
|
+
| [SPEC-003](../../../../docs/specs/SPEC-003-typedoc-documentation-standard.md) | TypeDoc documentation rules |
|
|
250
|
+
| [AI_DOC_FRAMEWORK.md](../../../../AI_DOC_FRAMEWORK.md) | Monorepo documentation system |
|
|
251
|
+
| [DOMAIN.md](../../../../docs/core/DOMAIN.md) | Domain terminology |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Package Context
|
|
256
|
+
|
|
257
|
+
**Purpose:** Functional programming Result type for error handling without exceptions.
|
|
258
|
+
|
|
259
|
+
**Core concept:** `Result<T, E>` is a discriminated union:
|
|
260
|
+
- `{ ok: true, value: T }` — success case
|
|
261
|
+
- `{ ok: false, error: E }` — error case
|
|
262
|
+
|
|
263
|
+
**Design principle:** Explicit error handling — caller MUST handle both cases.
|
|
264
|
+
|
|
265
|
+
**Inspired by:** Rust's `std::result::Result`
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: CONTEXT
|
|
3
|
+
uuid: 3143ad43-830e-4a51-9795-c484204e0e00
|
|
4
|
+
title: "@resultsafe/core-fp-result — Package Context"
|
|
5
|
+
status: canonical
|
|
6
|
+
layer: authored
|
|
7
|
+
lang: en
|
|
8
|
+
scope: package
|
|
9
|
+
package: "@resultsafe/core-fp-result"
|
|
10
|
+
owner: Denis
|
|
11
|
+
created: 2026-03-26
|
|
12
|
+
updated: 2026-03-26
|
|
13
|
+
links: []
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# @resultsafe/core-fp-result — Package Context
|
|
17
|
+
|
|
18
|
+
<!-- AGENT: update only when this package's purpose or scope changes -->
|
|
19
|
+
|
|
20
|
+
## What this package does
|
|
21
|
+
|
|
22
|
+
Provides the Result type implementation for handling operations that can succeed or fail.
|
|
23
|
+
The Result type represents either a success value (Ok) or an error value (Err),
|
|
24
|
+
offering a type-safe alternative to exception-based error handling.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Why it exists as a separate package
|
|
29
|
+
|
|
30
|
+
This package isolates the Result type implementation, allowing other packages
|
|
31
|
+
to depend on it without requiring the entire resultsafe runtime.
|
|
32
|
+
It is the core error handling primitive for the functional programming ecosystem.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Public API surface
|
|
37
|
+
|
|
38
|
+
[Key exported symbols — derive from `src/index.ts`]
|
|
39
|
+
|
|
40
|
+
| Symbol | Category | Description |
|
|
41
|
+
|--------|----------|-------------|
|
|
42
|
+
| `Result` | type | The Result type union |
|
|
43
|
+
| `Ok` | constructor | Constructs an Ok variant |
|
|
44
|
+
| `Err` | constructor | Constructs an Err variant |
|
|
45
|
+
| `isOk` | guard | Type guard for Ok |
|
|
46
|
+
| `isErr` | guard | Type guard for Err |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Dependencies on other resultsafe packages
|
|
51
|
+
|
|
52
|
+
| Package | Why |
|
|
53
|
+
|---------|-----|
|
|
54
|
+
| `@resultsafe/core-fp-result-shared` | Shared utilities |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Contracts implemented
|
|
59
|
+
|
|
60
|
+
| Contract | Symbol | Impl SPEC |
|
|
61
|
+
|----------|--------|-----------|
|
|
62
|
+
| [SPEC-010](../../../../docs/specs/contracts/SPEC-010-result-type-contract.md) | `Result` | [SPEC-001](specs/SPEC-001-result-implementation.md) |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Related root docs
|
|
67
|
+
|
|
68
|
+
- [Monorepo context](../../../../docs/core/CONTEXT.md)
|
|
69
|
+
- [Architecture](../../../../docs/core/ARCHITECTURE.md)
|
|
70
|
+
- [Domain glossary](../../../../docs/core/DOMAIN.md)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: MANIFEST
|
|
3
|
+
uuid: 971ffb6b-68db-4465-b286-21659fca5c17
|
|
4
|
+
title: "@resultsafe/core-fp-result — Documentation Map"
|
|
5
|
+
status: canonical
|
|
6
|
+
layer: authored
|
|
7
|
+
lang: en
|
|
8
|
+
scope: package
|
|
9
|
+
package: "@resultsafe/core-fp-result"
|
|
10
|
+
owner: Denis
|
|
11
|
+
created: 2026-03-26
|
|
12
|
+
updated: 2026-03-26
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# @resultsafe/core-fp-result — Documentation Map
|
|
16
|
+
|
|
17
|
+
> Package: `packages/core/fp/result`
|
|
18
|
+
> Monorepo map: [docs/MANIFEST.md](../../../../docs/MANIFEST.md)
|
|
19
|
+
|
|
20
|
+
## What this package does
|
|
21
|
+
|
|
22
|
+
Provides the Result type implementation for functional error handling in the resultsafe monorepo.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Agent reading chain
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Package task → this MANIFEST → CONTEXT.md → targeted files
|
|
30
|
+
For cross-cutting context → ../../../../docs/MANIFEST.md
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Package documents
|
|
36
|
+
|
|
37
|
+
| File | Role | Status | Updated |
|
|
38
|
+
|------|------|--------|---------|
|
|
39
|
+
| [CONTEXT.md](CONTEXT.md) | Why this package exists | canonical | 2026-03-26 |
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Generated (not committed)
|
|
44
|
+
|
|
45
|
+
| Folder | What | Command |
|
|
46
|
+
|--------|------|---------|
|
|
47
|
+
| `../api/` | TypeDoc API docs | `pnpm docs:api` |
|
|
48
|
+
| `../examples/` | Example docs | `pnpm docs:examples` |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Related root docs
|
|
53
|
+
|
|
54
|
+
- [Monorepo context](../../../../docs/core/CONTEXT.md)
|
|
55
|
+
- [Architecture](../../../../docs/core/ARCHITECTURE.md)
|
|
56
|
+
- [Domain glossary](../../../../docs/core/DOMAIN.md)
|
|
57
|
+
- [This package in registry](../../../../docs/registry/PACKAGES.md)
|
|
58
|
+
- [Contracts](../../../../docs/specs/contracts/)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: COUNTERS
|
|
3
|
+
uuid: 95199988-2bae-4ad9-8040-8a1aa86b803a
|
|
4
|
+
title: "@resultsafe/core-fp-result — Local ID Counters"
|
|
5
|
+
status: canonical
|
|
6
|
+
layer: authored
|
|
7
|
+
lang: en
|
|
8
|
+
scope: package
|
|
9
|
+
package: "@resultsafe/core-fp-result"
|
|
10
|
+
owner: Denis
|
|
11
|
+
created: 2026-03-26
|
|
12
|
+
updated: 2026-03-26
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# @resultsafe/core-fp-result — Local ID Counters
|
|
16
|
+
|
|
17
|
+
> Package-local counters. Independent from root and from other packages.
|
|
18
|
+
> SPEC-001 here is a different document from SPEC-001 in another package.
|
|
19
|
+
> Update in the same commit as the new file.
|
|
20
|
+
> Next ID = value in the table. After creation — increment.
|
|
21
|
+
|
|
22
|
+
| Prefix | Next number | Last created |
|
|
23
|
+
|--------|-------------|--------------|
|
|
24
|
+
| SPEC | 001 | — |
|
|
25
|
+
| ADR | 001 | — |
|
|
26
|
+
| TASK | 001 | — |
|
|
27
|
+
| CONCEPT | 001 | — |
|
|
28
|
+
| RB | 001 | — |
|
|
29
|
+
| NOTE | 001 | — |
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: ENTITIES
|
|
3
|
+
uuid: a02a4468-3a62-442e-827a-c9a40fbeaaa2
|
|
4
|
+
title: "@resultsafe/core-fp-result — Package Entities"
|
|
5
|
+
status: canonical
|
|
6
|
+
layer: authored
|
|
7
|
+
lang: en
|
|
8
|
+
scope: package
|
|
9
|
+
package: "@resultsafe/core-fp-result"
|
|
10
|
+
owner: Denis
|
|
11
|
+
created: 2026-03-26
|
|
12
|
+
updated: 2026-03-26
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# @resultsafe/core-fp-result — Package Entities
|
|
16
|
+
|
|
17
|
+
> Cross-cutting entities that involve this package.
|
|
18
|
+
> Links to root `docs/registry/ENTITIES.md` for shared entities.
|
|
19
|
+
|
|
20
|
+
## Entities
|
|
21
|
+
|
|
22
|
+
| Entity | Description | Related Specs |
|
|
23
|
+
|--------|-------------|---------------|
|
|
24
|
+
| — | — | — |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Related root entities
|
|
29
|
+
|
|
30
|
+
- [Root Entities](../../../../docs/registry/ENTITIES.md)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Err.js","sources":["../../../src/constructors/Err.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Создает ошибочное значение `Result` из переданного payload ошибки.\n *\n * @typeParam E - Тип значения ошибки.\n * @typeParam T - The success type for the resulting `Result`.\n * @param error - Payload ошибки для обёртки.\n * @returns A `Result` with `ok: false` and the provided `error`.\n * @since 0.1.0\n * @see {@link Ok} - Creates a successful `Result`.\n * @example\n * ```ts\n * import { Err } from '@resultsafe/core-fp-result';\n *\n * const result = Err<string, number>('boom');\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const Err = <E, T = never>(error: E): Result<T, E> =>\n ({ ok: false, error }) as const;\n
|
|
1
|
+
{"version":3,"file":"Err.js","sources":["../../../src/constructors/Err.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Создает ошибочное значение `Result` из переданного payload ошибки.\n *\n * @typeParam E - Тип значения ошибки.\n * @typeParam T - The success type for the resulting `Result`.\n * @param error - Payload ошибки для обёртки.\n * @returns A `Result` with `ok: false` and the provided `error`.\n * @since 0.1.0\n * @see {@link Ok} - Creates a successful `Result`.\n * @example\n * ```ts\n * import { Err } from '@resultsafe/core-fp-result';\n *\n * const result = Err<string, number>('boom');\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const Err = <E, T = never>(error: E): Result<T, E> =>\n ({ ok: false, error }) as const;\n"],"names":[],"mappings":";;AAoBO,MAAM,MAAM,wBAAe,WAC/B,EAAE,IAAI,OAAO,MAAA,IADG;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ok.js","sources":["../../../src/constructors/Ok.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Создает успешное значение `Result` из переданного payload.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - The error type for the resulting `Result`.\n * @param value - Payload успеха для обёртки.\n * @returns A `Result` with `ok: true` and the provided `value`.\n * @since 0.1.0\n * @see {@link Err} - Creates an error `Result`.\n * @example\n * ```ts\n * import { Ok } from '@resultsafe/core-fp-result';\n *\n * const result = Ok<number, string>(42);\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const Ok = <T, E = never>(value: T): Result<T, E> =>\n ({ ok: true, value }) as const;\n
|
|
1
|
+
{"version":3,"file":"Ok.js","sources":["../../../src/constructors/Ok.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Создает успешное значение `Result` из переданного payload.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - The error type for the resulting `Result`.\n * @param value - Payload успеха для обёртки.\n * @returns A `Result` with `ok: true` and the provided `value`.\n * @since 0.1.0\n * @see {@link Err} - Creates an error `Result`.\n * @example\n * ```ts\n * import { Ok } from '@resultsafe/core-fp-result';\n *\n * const result = Ok<number, string>(42);\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const Ok = <T, E = never>(value: T): Result<T, E> =>\n ({ ok: true, value }) as const;\n"],"names":[],"mappings":";;AAoBO,MAAM,KAAK,wBAAe,WAC9B,EAAE,IAAI,MAAM,MAAA,IADG;"}
|
package/esm/guards/isErr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErr.js","sources":["../../../src/guards/isErr.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Проверяет, находится ли `Result` в ветке ошибки.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @returns `true` when `result.ok` equals `false`.\n * @since 0.1.0\n * @see {@link isOk} - Checks the success branch.\n * @example\n * ```ts\n * import { Err, isErr } from '@resultsafe/core-fp-result';\n *\n * const result = Err('boom');\n * console.log(isErr(result)); // true\n * ```\n * @public\n */\nexport const isErr = <T, E>(\n result: Result<T, E>,\n): result is { ok: false; error: E } => result.ok === false;\n
|
|
1
|
+
{"version":3,"file":"isErr.js","sources":["../../../src/guards/isErr.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Проверяет, находится ли `Result` в ветке ошибки.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @returns `true` when `result.ok` equals `false`.\n * @since 0.1.0\n * @see {@link isOk} - Checks the success branch.\n * @example\n * ```ts\n * import { Err, isErr } from '@resultsafe/core-fp-result';\n *\n * const result = Err('boom');\n * console.log(isErr(result)); // true\n * ```\n * @public\n */\nexport const isErr = <T, E>(\n result: Result<T, E>,\n): result is { ok: false; error: E } => result.ok === false;\n"],"names":[],"mappings":";;AAoBO,MAAM,QAAQ,wBACnB,WACsC,OAAO,OAAO,OAFjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErrAnd.js","sources":["../../../src/guards/isErrAnd.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\
|
|
1
|
+
{"version":3,"file":"isErrAnd.js","sources":["../../../src/guards/isErrAnd.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\nimport { isErr } from './isErr.js';\n\n/**\n * Проверяет, что `Result` завершился ошибкой и удовлетворяет предикату.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @param predicate - Предикат, применяемый к значению ошибки.\n * @returns `true` when the value is `Err` and the predicate returns `true`.\n * @since 0.1.0\n * @see {@link isErr} - Performs the base error check.\n * @example\n * ```ts\n * import { Err, isErrAnd } from '@resultsafe/core-fp-result';\n *\n * const result = Err({ code: 503 });\n * console.log(isErrAnd(result, (error) => error.code >= 500)); // true\n * ```\n * @public\n */\nexport const isErrAnd = <T, E>(\n result: Result<T, E>,\n predicate: (error: E) => boolean,\n): boolean => isErr(result) && predicate(result.error);\n"],"names":[],"mappings":";;;AAsBO,MAAM,WAAW,wBACtB,QACA,cACY,MAAM,MAAM,KAAK,UAAU,OAAO,KAAK,GAH7B;"}
|
package/esm/guards/isOk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOk.js","sources":["../../../src/guards/isOk.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Проверяет, находится ли `Result` в ветке успеха.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @returns `true` when `result.ok` equals `true`.\n * @since 0.1.0\n * @see {@link isErr} - Checks the error branch.\n * @example\n * ```ts\n * import { Ok, isOk } from '@resultsafe/core-fp-result';\n *\n * const result = Ok(10);\n * console.log(isOk(result)); // true\n * ```\n * @public\n */\nexport const isOk = <T, E>(\n result: Result<T, E>,\n): result is { ok: true; value: T } => result.ok === true;\n
|
|
1
|
+
{"version":3,"file":"isOk.js","sources":["../../../src/guards/isOk.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Проверяет, находится ли `Result` в ветке успеха.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @returns `true` when `result.ok` equals `true`.\n * @since 0.1.0\n * @see {@link isErr} - Checks the error branch.\n * @example\n * ```ts\n * import { Ok, isOk } from '@resultsafe/core-fp-result';\n *\n * const result = Ok(10);\n * console.log(isOk(result)); // true\n * ```\n * @public\n */\nexport const isOk = <T, E>(\n result: Result<T, E>,\n): result is { ok: true; value: T } => result.ok === true;\n"],"names":[],"mappings":";;AAoBO,MAAM,OAAO,wBAClB,WACqC,OAAO,OAAO,MAFjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOkAnd.js","sources":["../../../src/guards/isOkAnd.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\
|
|
1
|
+
{"version":3,"file":"isOkAnd.js","sources":["../../../src/guards/isOkAnd.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\nimport { isOk } from './isOk.js';\n\n/**\n * Проверяет, что `Result` успешен и удовлетворяет предикату.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - `Result` для проверки.\n * @param predicate - Предикат, применяемый к успешному значению.\n * @returns `true` when the value is `Ok` and the predicate returns `true`.\n * @since 0.1.0\n * @see {@link isOk} - Performs the base success check.\n * @example\n * ```ts\n * import { Ok, isOkAnd } from '@resultsafe/core-fp-result';\n *\n * const result = Ok(8);\n * console.log(isOkAnd(result, (value) => value % 2 === 0)); // true\n * ```\n * @public\n */\nexport const isOkAnd = <T, E>(\n result: Result<T, E>,\n predicate: (value: T) => boolean,\n): boolean => isOk(result) && predicate(result.value);\n"],"names":[],"mappings":";;;AAsBO,MAAM,UAAU,wBACrB,QACA,cACY,KAAK,MAAM,KAAK,UAAU,OAAO,KAAK,GAH7B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"andThen.js","sources":["../../../src/methods/andThen.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"andThen.js","sources":["../../../src/methods/andThen.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Цепляет вычисление, которое возвращает другой `Result`.\n *\n * @typeParam T - The input success type.\n * @typeParam U - The output success type.\n * @typeParam E - Общий тип ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция, применяемая, когда `result` имеет `Ok`.\n * @returns Преобразованный `Result` или исходный `Err`.\n * @since 0.1.0\n * @see {@link map} - Преобразует только успешное значение.\n * @example\n * ```ts\n * import { Ok, Err, andThen } from '@resultsafe/core-fp-result';\n *\n * const parsed = andThen(Ok('12'), (value) => {\n * const n = Number(value);\n * return Number.isNaN(n) ? Err('invalid') : Ok(n);\n * });\n * console.log(parsed.ok); // true\n * ```\n * @public\n */\nexport const andThen = <T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => Result<U, E>,\n): Result<U, E> => (isOk(result) ? fn(result.value) : (result as Result<U, E>));\n"],"names":[],"mappings":";;;AA0BO,MAAM,UAAU,wBACrB,QACA,OACkB,KAAK,MAAM,IAAI,GAAG,OAAO,KAAK,IAAK,QAHhC;"}
|
package/esm/methods/err.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"err.js","sources":["../../../src/methods/err.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"err.js","sources":["../../../src/methods/err.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option } from '../shared-types.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Извлекает ветку ошибки в виде `Option`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @returns `Some(error)` для `Err`, иначе `None`.\n * @since 0.1.0\n * @see {@link ok} - Извлекает ветку успеха.\n * @example\n * ```ts\n * import { Err, err } from '@resultsafe/core-fp-result';\n *\n * const value = err(Err('boom'));\n * console.log(value.some); // true\n * ```\n * @public\n */\nexport const err = <T, E>(result: Result<T, E>): Option<E> =>\n isErr(result) ? Some(result.error) : None;\n"],"names":[],"mappings":";;;;AAuBO,MAAM,MAAM,wBAAO,WACxB,MAAM,MAAM,IAAI,KAAK,OAAO,KAAK,IAAI,MADpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sources":["../../../src/methods/expect.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"expect.js","sources":["../../../src/methods/expect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Возвращает успешное значение или выбрасывает исключение с пользовательским сообщением.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param msg - Сообщение об ошибке, используемое когда `result` имеет `Err`.\n * @returns Распакованное успешное значение.\n * @throws Error - Выбрасывает исключение, когда `result` имеет `Err`.\n * @since 0.1.0\n * @see {@link expectErr} - Симметричный helper для ветки ошибки.\n * @example\n * ```ts\n * import { Ok, expect } from '@resultsafe/core-fp-result';\n *\n * const value = expect(Ok(5), 'must be ok');\n * console.log(value); // 5\n * ```\n * @public\n */\nexport const expect = <T, E>(result: Result<T, E>, msg: string): T => {\n if (isOk(result)) {\n return result.value;\n }\n throw new Error(msg);\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBAAO,QAAsB,QAAmB;AACpE,MAAI,KAAK,MAAM,GAAG;AAChB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,GAAG;AACrB,GALsB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expectErr.js","sources":["../../../src/methods/expectErr.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"expectErr.js","sources":["../../../src/methods/expectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Возвращает значение ошибки или выбрасывает исключение с пользовательским сообщением.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param msg - Сообщение об ошибке, используемое когда `result` имеет `Ok`.\n * @returns Распакованное значение ошибки.\n * @throws Error - Выбрасывает исключение, когда `result` имеет `Ok`.\n * @since 0.1.0\n * @see {@link expect} - Симметричный helper для ветки успеха.\n * @example\n * ```ts\n * import { Err, expectErr } from '@resultsafe/core-fp-result';\n *\n * const error = expectErr(Err('boom'), 'must be err');\n * console.log(error); // boom\n * ```\n * @public\n */\nexport const expectErr = <T, E>(result: Result<T, E>, msg: string): E => {\n if (isErr(result)) {\n return result.error;\n }\n throw new Error(msg);\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,YAAY,wBAAO,QAAsB,QAAmB;AACvE,MAAI,MAAM,MAAM,GAAG;AACjB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,IAAI,MAAM,GAAG;AACrB,GALyB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","sources":["../../../src/methods/flatten.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\n\n/**\n * Схлопывает вложенный `Result<Result<T, E>, E>` на один уровень.\n *\n * @typeParam T - The inner success value type.\n * @typeParam E - The shared error value type.\n * @param result - Вложенный `Result` для схлопывания.\n * @returns A single-layer `Result<T, E>`.\n * @since 0.1.0\n * @see {@link andThen} - Chains computations that already return `Result`.\n * @example\n * ```ts\n * import { Ok, flatten } from '@resultsafe/core-fp-result';\n *\n * const value = flatten(Ok(Ok(3)));\n * console.log(value.ok); // true\n * ```\n * @public\n */\nexport const flatten = <T, E>(result: Result<Result<T, E>, E>): Result<T, E> =>\n result.ok ? result.value : { ok: false, error: result.error };\n
|
|
1
|
+
{"version":3,"file":"flatten.js","sources":["../../../src/methods/flatten.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\n\n/**\n * Схлопывает вложенный `Result<Result<T, E>, E>` на один уровень.\n *\n * @typeParam T - The inner success value type.\n * @typeParam E - The shared error value type.\n * @param result - Вложенный `Result` для схлопывания.\n * @returns A single-layer `Result<T, E>`.\n * @since 0.1.0\n * @see {@link andThen} - Chains computations that already return `Result`.\n * @example\n * ```ts\n * import { Ok, flatten } from '@resultsafe/core-fp-result';\n *\n * const value = flatten(Ok(Ok(3)));\n * console.log(value.ok); // true\n * ```\n * @public\n */\nexport const flatten = <T, E>(result: Result<Result<T, E>, E>): Result<T, E> =>\n result.ok ? result.value : { ok: false, error: result.error };\n"],"names":[],"mappings":";;AAoBO,MAAM,UAAU,wBAAO,WAC5B,OAAO,KAAK,OAAO,QAAQ,EAAE,IAAI,OAAO,OAAO,OAAO,MAAA,GADjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspect.js","sources":["../../../src/methods/inspect.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"inspect.js","sources":["../../../src/methods/inspect.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Выполняет побочный эффект для успешного значения и возвращает исходный `Result`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция побочного эффекта для ветки успеха.\n * @returns Тот же экземпляр `Result`.\n * @since 0.1.0\n * @see {@link tap} - Эквивалентный helper для ветки успеха.\n * @example\n * ```ts\n * import { Ok, inspect } from '@resultsafe/core-fp-result';\n *\n * const result = inspect(Ok(1), (value) => console.log(value)); // 1\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const inspect = <T, E>(\n result: Result<T, E>,\n fn: (value: T) => void,\n): Result<T, E> => {\n if (isOk(result)) {\n fn(result.value);\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,UAAU,wBACrB,QACA,OACiB;AACjB,MAAI,KAAK,MAAM,GAAG;AAChB,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GARuB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inspectErr.js","sources":["../../../src/methods/inspectErr.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"inspectErr.js","sources":["../../../src/methods/inspectErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Выполняет побочный эффект для значения ошибки и возвращает исходный `Result`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция побочного эффекта для ветки ошибки.\n * @returns Тот же экземпляр `Result`.\n * @since 0.1.0\n * @see {@link tapErr} - Эквивалентный helper для ветки ошибки.\n * @example\n * ```ts\n * import { Err, inspectErr } from '@resultsafe/core-fp-result';\n *\n * const result = inspectErr(Err('boom'), (error) => console.log(error)); // boom\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const inspectErr = <T, E>(\n result: Result<T, E>,\n fn: (error: E) => void,\n): Result<T, E> => {\n if (isErr(result)) {\n fn(result.error);\n }\n return result;\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,aAAa,wBACxB,QACA,OACiB;AACjB,MAAI,MAAM,MAAM,GAAG;AACjB,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GAR0B;"}
|
package/esm/methods/map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sources":["../../../src/methods/map.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"map.js","sources":["../../../src/methods/map.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Преобразует успешное значение, сохраняя ветку ошибки.\n *\n * @typeParam T - Тип входного успешного значения.\n * @typeParam U - Тип выходного успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция преобразования успешного значения.\n * @returns Преобразованный `Ok` или исходный `Err`.\n * @since 0.1.0\n * @see {@link mapErr} - Преобразует ветку ошибки.\n * @example\n * ```ts\n * import { Ok, map } from '@resultsafe/core-fp-result';\n *\n * const result = map(Ok(2), (value) => value * 10);\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const map = <T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => U,\n): Result<U, E> =>\n isOk(result)\n ? { ok: true, value: fn(result.value) }\n : (result as Result<U, E>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,MAAM,wBACjB,QACA,OAEA,KAAK,MAAM,IACP,EAAE,IAAI,MAAM,OAAO,GAAG,OAAO,KAAK,MACjC,QANY;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapErr.js","sources":["../../../src/methods/mapErr.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"mapErr.js","sources":["../../../src/methods/mapErr.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Преобразует значение ошибки, сохраняя ветку успеха.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип входного значения ошибки.\n * @typeParam F - Тип выходного значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция преобразования значения ошибки.\n * @returns Преобразованный `Err` или исходный `Ok`.\n * @since 0.1.0\n * @see {@link map} - Transforms the success branch.\n * @example\n * ```ts\n * import { Err, mapErr } from '@resultsafe/core-fp-result';\n *\n * const result = mapErr(Err('e1'), (error) => `mapped:${error}`);\n * console.log(result.ok); // false\n * ```\n * @public\n */\nexport const mapErr = <T, E, F>(\n result: Result<T, E>,\n fn: (error: E) => F,\n): Result<T, F> =>\n isErr(result)\n ? { ok: false, error: fn(result.error) }\n : (result as Result<T, F>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBACpB,QACA,OAEA,MAAM,MAAM,IACR,EAAE,IAAI,OAAO,OAAO,GAAG,OAAO,KAAK,MAClC,QANe;"}
|
package/esm/methods/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sources":["../../../src/methods/match.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\n\n/**\n * Выполняет сопоставление `Result` в единое выходное значение.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @typeParam U - The output type returned by both handlers.\n * @param result - Исходный `Result`.\n * @param okFn - Обработчик для ветки успеха.\n * @param errFn - Обработчик для ветки ошибки.\n * @returns Выходное значение, полученное от выбранного обработчика.\n * @since 0.1.0\n * @see {@link unwrapOrElse} - Similar shape with default fallback semantics.\n * @example\n * ```ts\n * import { Ok, match } from '@resultsafe/core-fp-result';\n *\n * const value = match(Ok(3), (x) => `ok:${x}`, (e) => `err:${e}`);\n * console.log(value); // ok:3\n * ```\n * @public\n */\nexport const match = <T, E, U>(\n result: Result<T, E>,\n okFn: (value: T) => U,\n errFn: (error: E) => U,\n): U => {\n if (result.ok) {\n return okFn(result.value);\n } else {\n const { error } = result;\n return errFn(error);\n }\n};\n
|
|
1
|
+
{"version":3,"file":"match.js","sources":["../../../src/methods/match.ts"],"sourcesContent":["import { type Result } from '../shared-types.js';\n\n/**\n * Выполняет сопоставление `Result` в единое выходное значение.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @typeParam U - The output type returned by both handlers.\n * @param result - Исходный `Result`.\n * @param okFn - Обработчик для ветки успеха.\n * @param errFn - Обработчик для ветки ошибки.\n * @returns Выходное значение, полученное от выбранного обработчика.\n * @since 0.1.0\n * @see {@link unwrapOrElse} - Similar shape with default fallback semantics.\n * @example\n * ```ts\n * import { Ok, match } from '@resultsafe/core-fp-result';\n *\n * const value = match(Ok(3), (x) => `ok:${x}`, (e) => `err:${e}`);\n * console.log(value); // ok:3\n * ```\n * @public\n */\nexport const match = <T, E, U>(\n result: Result<T, E>,\n okFn: (value: T) => U,\n errFn: (error: E) => U,\n): U => {\n if (result.ok) {\n return okFn(result.value);\n } else {\n const { error } = result;\n return errFn(error);\n }\n};\n"],"names":[],"mappings":";;AAuBO,MAAM,QAAQ,wBACnB,QACA,MACA,UACM;AACN,MAAI,OAAO,IAAI;AACb,WAAO,KAAK,OAAO,KAAK;AAAA,EAC1B,OAAO;AACL,UAAM,EAAE,UAAU;AAClB,WAAO,MAAM,KAAK;AAAA,EACpB;AACF,GAXqB;"}
|
package/esm/methods/ok.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ok.js","sources":["../../../src/methods/ok.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ok.js","sources":["../../../src/methods/ok.ts"],"sourcesContent":["import { isOk } from '../guards/isOk.js';\nimport { None, Some } from '../internal/option.js';\nimport { type Option } from '../shared-types.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Извлекает успешную ветку в виде `Option`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @returns `Some(value)` для `Ok`, иначе `None`.\n * @since 0.1.0\n * @see {@link err} - Извлекает ветку ошибки.\n * @example\n * ```ts\n * import { Ok, ok } from '@resultsafe/core-fp-result';\n *\n * const value = ok(Ok(10));\n * console.log(value.some); // true\n * ```\n * @public\n */\nexport const ok = <T, E>(result: Result<T, E>): Option<T> =>\n isOk(result) ? Some(result.value) : None;\n"],"names":[],"mappings":";;;;AAuBO,MAAM,KAAK,wBAAO,WACvB,KAAK,MAAM,IAAI,KAAK,OAAO,KAAK,IAAI,MADpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orElse.js","sources":["../../../src/methods/orElse.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"orElse.js","sources":["../../../src/methods/orElse.ts"],"sourcesContent":["import { isErr } from '../guards/isErr.js';\nimport { type Result } from '../shared-types.js';\n\n/**\n * Восстанавливается из ошибки, преобразуя `Err` в другой `Result`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип входного значения ошибки.\n * @typeParam F - Тип выходного значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Функция восстановления, применяемая для `Err`.\n * @returns Восстановленный `Result` или исходный `Ok`.\n * @since 0.1.0\n * @see {@link andThen} - Цепляет ветку успеха.\n * @example\n * ```ts\n * import { Err, Ok, orElse } from '@resultsafe/core-fp-result';\n *\n * const result = orElse(Err('network'), () => Ok('cached'));\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const orElse = <T, E, F>(\n result: Result<T, E>,\n fn: (error: E) => Result<T, F>,\n): Result<T, F> =>\n isErr(result) ? fn(result.error) : (result as Result<T, F>);\n"],"names":[],"mappings":";;;AAuBO,MAAM,SAAS,wBACpB,QACA,OAEA,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,IAAK,QAJhB;"}
|
package/esm/methods/tap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tap.js","sources":["../../../src/methods/tap.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Выполняет побочный эффект для значения `Ok` и возвращает входной `Result`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Колбэк побочного эффекта для ветки успеха.\n * @returns Неизмененный `Result`.\n * @since 0.1.0\n * @see {@link tapErr} - Executes a side effect for the error branch.\n * @example\n * ```ts\n * import { Ok, tap } from '@resultsafe/core-fp-result';\n *\n * const result = tap(Ok(1), (value) => console.log(value)); // 1\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const tap = <T, E>(\n result: Result<T, E>,\n fn: (value: T) => void,\n): Result<T, E> => {\n if (result.ok) {\n fn(result.value);\n }\n return result;\n};\n
|
|
1
|
+
{"version":3,"file":"tap.js","sources":["../../../src/methods/tap.ts"],"sourcesContent":["import type { Result } from '../shared-types.js';\n\n/**\n * Выполняет побочный эффект для значения `Ok` и возвращает входной `Result`.\n *\n * @typeParam T - Тип успешного значения.\n * @typeParam E - Тип значения ошибки.\n * @param result - Исходный `Result`.\n * @param fn - Колбэк побочного эффекта для ветки успеха.\n * @returns Неизмененный `Result`.\n * @since 0.1.0\n * @see {@link tapErr} - Executes a side effect for the error branch.\n * @example\n * ```ts\n * import { Ok, tap } from '@resultsafe/core-fp-result';\n *\n * const result = tap(Ok(1), (value) => console.log(value)); // 1\n * console.log(result.ok); // true\n * ```\n * @public\n */\nexport const tap = <T, E>(\n result: Result<T, E>,\n fn: (value: T) => void,\n): Result<T, E> => {\n if (result.ok) {\n fn(result.value);\n }\n return result;\n};\n"],"names":[],"mappings":";;AAqBO,MAAM,MAAM,wBACjB,QACA,OACiB;AACjB,MAAI,OAAO,IAAI;AACb,OAAG,OAAO,KAAK;AAAA,EACjB;AACA,SAAO;AACT,GARmB;"}
|