@zipbul/result 0.1.7 → 1.0.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.ko.md +0 -19
- package/README.md +0 -19
- package/dist/index.js +1 -1
- package/dist/src/err.d.ts +2 -5
- package/dist/src/types.d.ts +4 -6
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -112,12 +112,10 @@ import { err } from '@zipbul/result';
|
|
|
112
112
|
// 데이터 없음 — 단순 신호
|
|
113
113
|
const e1 = err();
|
|
114
114
|
// e1.data → never (접근 불가)
|
|
115
|
-
// e1.stack → 캡처된 스택 트레이스
|
|
116
115
|
|
|
117
116
|
// 데이터 포함 — 에러 상세 정보 전달
|
|
118
117
|
const e2 = err('not found');
|
|
119
118
|
// e2.data → 'not found'
|
|
120
|
-
// e2.stack → 캡처된 스택 트레이스
|
|
121
119
|
|
|
122
120
|
// 풍부한 에러 객체
|
|
123
121
|
const e3 = err({ code: 'TIMEOUT', retryAfter: 3000 });
|
|
@@ -129,7 +127,6 @@ const e3 = err({ code: 'TIMEOUT', retryAfter: 3000 });
|
|
|
129
127
|
| 프로퍼티 | 타입 | 설명 |
|
|
130
128
|
|:---------|:-----|:-----|
|
|
131
129
|
| `data` | `E` | 첨부된 에러 데이터 |
|
|
132
|
-
| `stack` | `string` | `err()` 호출 지점에서 캡처된 스택 트레이스 |
|
|
133
130
|
|
|
134
131
|
> **불변성** — 모든 `Err`는 `Object.freeze()`됩니다. strict mode에서 프로퍼티를 수정하면 `TypeError`가 발생합니다.
|
|
135
132
|
|
|
@@ -198,7 +195,6 @@ type ApiResult = Result<User, { code: string; message: string }>;
|
|
|
198
195
|
|
|
199
196
|
```typescript
|
|
200
197
|
type Err<E = never> = {
|
|
201
|
-
stack: string;
|
|
202
198
|
data: E;
|
|
203
199
|
};
|
|
204
200
|
```
|
|
@@ -374,21 +370,6 @@ async function fetchUser(id: number): Promise<Result<User, ApiError>> {
|
|
|
374
370
|
}
|
|
375
371
|
```
|
|
376
372
|
|
|
377
|
-
### 스택 트레이스
|
|
378
|
-
|
|
379
|
-
모든 `Err`는 생성 시점에 스택 트레이스를 캡처하여, `throw` 없이 디버깅이 가능합니다:
|
|
380
|
-
|
|
381
|
-
```typescript
|
|
382
|
-
const e = err('something went wrong');
|
|
383
|
-
console.log(e.stack);
|
|
384
|
-
// Error
|
|
385
|
-
// at err (/.../err.ts:22:18)
|
|
386
|
-
// at validate (/.../validate.ts:15:12)
|
|
387
|
-
// at handleRequest (/.../server.ts:8:20)
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
<br>
|
|
391
|
-
|
|
392
373
|
## 🔌 프레임워크 연동 예시
|
|
393
374
|
|
|
394
375
|
<details>
|
package/README.md
CHANGED
|
@@ -112,12 +112,10 @@ import { err } from '@zipbul/result';
|
|
|
112
112
|
// No data — simple signal
|
|
113
113
|
const e1 = err();
|
|
114
114
|
// e1.data → never (cannot access)
|
|
115
|
-
// e1.stack → captured stack trace
|
|
116
115
|
|
|
117
116
|
// With data — carry error details
|
|
118
117
|
const e2 = err('not found');
|
|
119
118
|
// e2.data → 'not found'
|
|
120
|
-
// e2.stack → captured stack trace
|
|
121
119
|
|
|
122
120
|
// Rich error objects
|
|
123
121
|
const e3 = err({ code: 'TIMEOUT', retryAfter: 3000 });
|
|
@@ -129,7 +127,6 @@ Properties of the returned `Err`:
|
|
|
129
127
|
| Property | Type | Description |
|
|
130
128
|
|:---------|:-----|:------------|
|
|
131
129
|
| `data` | `E` | The attached error data |
|
|
132
|
-
| `stack` | `string` | Stack trace captured at `err()` call site |
|
|
133
130
|
|
|
134
131
|
> **Immutability** — every `Err` is `Object.freeze()`d. Attempting to modify properties in strict mode throws a `TypeError`.
|
|
135
132
|
|
|
@@ -198,7 +195,6 @@ The error type returned by `err()`.
|
|
|
198
195
|
|
|
199
196
|
```typescript
|
|
200
197
|
type Err<E = never> = {
|
|
201
|
-
stack: string;
|
|
202
198
|
data: E;
|
|
203
199
|
};
|
|
204
200
|
```
|
|
@@ -374,21 +370,6 @@ async function fetchUser(id: number): Promise<Result<User, ApiError>> {
|
|
|
374
370
|
}
|
|
375
371
|
```
|
|
376
372
|
|
|
377
|
-
### Stack traces
|
|
378
|
-
|
|
379
|
-
Every `Err` captures a stack trace at creation time, enabling debugging without `throw`:
|
|
380
|
-
|
|
381
|
-
```typescript
|
|
382
|
-
const e = err('something went wrong');
|
|
383
|
-
console.log(e.stack);
|
|
384
|
-
// Error
|
|
385
|
-
// at err (/.../err.ts:22:18)
|
|
386
|
-
// at validate (/.../validate.ts:15:12)
|
|
387
|
-
// at handleRequest (/.../server.ts:8:20)
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
<br>
|
|
391
|
-
|
|
392
373
|
## 🔌 Framework Integration Examples
|
|
393
374
|
|
|
394
375
|
<details>
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var G="__$$e_9f4a1c7b__",B="__$$e_9f4a1c7b__";function q(){return B}function H(D){if(D.trim().length===0)throw TypeError("Marker key must be a non-empty string");B=D}function Y(D){let L
|
|
2
|
+
var G="__$$e_9f4a1c7b__",B="__$$e_9f4a1c7b__";function q(){return B}function H(D){if(D.trim().length===0)throw TypeError("Marker key must be a non-empty string");B=D}function Y(D){let L={[q()]:!0,data:D};return Object.freeze(L)}function J(D){try{return D!==null&&D!==void 0&&typeof D==="object"&&D[q()]===!0}catch{return!1}}function Q(D,L){if(D instanceof Promise)return D.then((F)=>F,(F)=>L?Y(L(F)):Y(F));try{return D()}catch(F){return L?Y(L(F)):Y(F)}}export{H as setMarkerKey,Q as safe,J as isErr,q as getMarkerKey,Y as err,G as DEFAULT_MARKER_KEY};
|
package/dist/src/err.d.ts
CHANGED
|
@@ -2,23 +2,20 @@ import type { Err } from './types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates an immutable {@link Err} value with no attached data.
|
|
4
4
|
*
|
|
5
|
-
* The returned object is `Object.freeze()`-d
|
|
6
|
-
* captured at the call site. This function **never throws**.
|
|
5
|
+
* The returned object is `Object.freeze()`-d. This function **never throws**.
|
|
7
6
|
*
|
|
8
7
|
* @returns A frozen `Err` with `data` typed as `never`.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```ts
|
|
12
11
|
* const e = err();
|
|
13
|
-
* console.log(e.stack); // stack trace
|
|
14
12
|
* ```
|
|
15
13
|
*/
|
|
16
14
|
export declare function err(): Err;
|
|
17
15
|
/**
|
|
18
16
|
* Creates an immutable {@link Err} value carrying the given data.
|
|
19
17
|
*
|
|
20
|
-
* The returned object is `Object.freeze()`-d
|
|
21
|
-
* captured at the call site. This function **never throws**.
|
|
18
|
+
* The returned object is `Object.freeze()`-d. This function **never throws**.
|
|
22
19
|
*
|
|
23
20
|
* @param data - Any value describing the error (string, object, number, etc.).
|
|
24
21
|
* @returns A frozen `Err<E>` with `data` set to the provided value.
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The error type returned by {@link err}.
|
|
3
3
|
*
|
|
4
|
-
* Every `Err` carries
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Every `Err` carries an optional `data` payload describing what went wrong.
|
|
5
|
+
* The hidden marker property used for detection is intentionally excluded
|
|
6
|
+
* from the type — it is managed internally by `err()` and checked only
|
|
7
|
+
* through `isErr()`.
|
|
8
8
|
*
|
|
9
9
|
* @template E - The type of the attached error data. Defaults to `never`.
|
|
10
10
|
*
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
* ```ts
|
|
13
13
|
* const e: Err<string> = err('not found');
|
|
14
14
|
* console.log(e.data); // 'not found'
|
|
15
|
-
* console.log(e.stack); // stack trace string
|
|
16
15
|
* ```
|
|
17
16
|
*/
|
|
18
17
|
export type Err<E = never> = {
|
|
19
|
-
stack: string;
|
|
20
18
|
data: E;
|
|
21
19
|
};
|
|
22
20
|
/**
|