@kalutskii/foundation 0.1.3 → 0.1.4
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 +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @kalutskii/foundation
|
|
2
2
|
|
|
3
3
|
Shared HTTP contracts and helpers for consistent API communication across esb-market-space services.
|
|
4
4
|
|
|
@@ -13,13 +13,13 @@ Shared HTTP contracts and helpers for consistent API communication across esb-ma
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
bun add @
|
|
16
|
+
bun add @kalutskii/foundation
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
or
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
npm i @
|
|
22
|
+
npm i @kalutskii/foundation
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Core concepts
|
|
@@ -39,8 +39,8 @@ Status code groups are exported as constants and used by types:
|
|
|
39
39
|
### 1. Build typed contracts
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
import { failure, success } from '@
|
|
43
|
-
import type { APIContractResult } from '@
|
|
42
|
+
import { failure, success } from '@kalutskii/foundation';
|
|
43
|
+
import type { APIContractResult } from '@kalutskii/foundation';
|
|
44
44
|
|
|
45
45
|
type User = { id: string; name: string };
|
|
46
46
|
|
|
@@ -53,8 +53,8 @@ const result: APIContractResult<User> = Math.random() > 0.5 ? ok : bad;
|
|
|
53
53
|
### 2. Resolve fetchers safely
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
import { fetchAndThrow, fetchSafely } from '@
|
|
57
|
-
import type { APIContractResult } from '@
|
|
56
|
+
import { fetchAndThrow, fetchSafely } from '@kalutskii/foundation';
|
|
57
|
+
import type { APIContractResult } from '@kalutskii/foundation';
|
|
58
58
|
|
|
59
59
|
type User = { id: string; name: string };
|
|
60
60
|
|
|
@@ -78,7 +78,7 @@ try {
|
|
|
78
78
|
### 3. Use typed Hono JSON responses
|
|
79
79
|
|
|
80
80
|
```ts
|
|
81
|
-
import { respond } from '@
|
|
81
|
+
import { respond } from '@kalutskii/foundation';
|
|
82
82
|
import { Hono } from 'hono';
|
|
83
83
|
|
|
84
84
|
const app = new Hono();
|
|
@@ -96,7 +96,7 @@ app.get('/health', (c) => {
|
|
|
96
96
|
### 4. Parse query params with helpers
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
|
-
import { asQueryBoolean, asQueryNumber } from '@
|
|
99
|
+
import { asQueryBoolean, asQueryNumber } from '@kalutskii/foundation';
|
|
100
100
|
import { z } from 'zod';
|
|
101
101
|
|
|
102
102
|
const pageSchema = asQueryNumber(z.number().int().min(1));
|