brass-runtime 1.11.0 β 1.11.1
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 +75 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# π οΈ brass-runtime β Mini ZIO-like runtime in TypeScript
|
|
2
2
|
|
|
3
|
-
A small experimental runtime inspired by **ZIO 2**, implemented in vanilla TypeScript and intentionally built without using `Promise` / `async`/`await` as the primary semantic primitive
|
|
3
|
+
A small experimental runtime inspired by **ZIO 2**, implemented in vanilla TypeScript and intentionally built without using `Promise` / `async`/`await` as the **primary semantic primitive**.
|
|
4
4
|
|
|
5
|
-
`brass-runtime` is the
|
|
6
|
-
Higher-level modules (HTTP, streaming utilities, integrations) are built **on top of
|
|
5
|
+
`brass-runtime` is the foundation: it provides an effect system, fibers, scheduler, scopes, and streams.
|
|
6
|
+
Higher-level modules (HTTP, streaming utilities, integrations) are built **on top of the runtime**, not baked into it.
|
|
7
|
+
|
|
8
|
+
> You can still interop with the outside world (timers, fetch, Node APIs) via explicit, cancellable bridges such as `fromPromiseAbortable`.
|
|
7
9
|
|
|
8
10
|
---
|
|
9
11
|
|
|
@@ -19,44 +21,87 @@ If you like ZIOβs separation between `zio-core`, `zio-streams`, and `zio-http`
|
|
|
19
21
|
|
|
20
22
|
---
|
|
21
23
|
|
|
22
|
-
## Core concepts
|
|
24
|
+
## Core concepts
|
|
23
25
|
|
|
24
|
-
-
|
|
26
|
+
- Sync core effect: `Effect<R, E, A>` and `Exit<E, A>`
|
|
25
27
|
- Algebraic async representation: `Async<R, E, A>`
|
|
26
|
-
- Cooperative `Scheduler`
|
|
27
|
-
- Lightweight `Fiber`s with interruption
|
|
28
|
+
- Cooperative `Scheduler` (observable / testable)
|
|
29
|
+
- Lightweight `Fiber`s with interruption & finalizers
|
|
28
30
|
- Structured `Scope`s for resource safety
|
|
29
31
|
- ZStream-style streams with backpressure
|
|
30
32
|
|
|
31
33
|
---
|
|
32
34
|
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i brass-runtime
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
### Run an effect
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { succeed } from "brass-runtime";
|
|
49
|
+
import { Runtime, toPromise } from "brass-runtime/runtime";
|
|
50
|
+
|
|
51
|
+
const runtime = new Runtime({ env: {} });
|
|
52
|
+
|
|
53
|
+
const value = await toPromise(succeed(123), runtime.env);
|
|
54
|
+
console.log(value); // 123
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Structured concurrency with Scope
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { withScope } from "brass-runtime/scope";
|
|
61
|
+
import { Runtime } from "brass-runtime/runtime";
|
|
62
|
+
|
|
63
|
+
const runtime = new Runtime({ env: {} });
|
|
64
|
+
|
|
65
|
+
withScope(runtime, (scope) => {
|
|
66
|
+
const f = scope.fork(/* Async effect */);
|
|
67
|
+
// later...
|
|
68
|
+
scope.close(); // interrupts child fibers + runs finalizers
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> `toPromise` is just a convenience bridge for examples/DX. The runtime semantics remain explicit.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
33
76
|
## Modules built on top of brass-runtime
|
|
34
77
|
|
|
35
|
-
These are
|
|
78
|
+
These are optional layers, implemented using the runtime primitives.
|
|
36
79
|
|
|
37
|
-
### π brass-http
|
|
80
|
+
### π HTTP client (brass-http layer)
|
|
38
81
|
|
|
39
82
|
A ZIO-style HTTP client built on top of fibers and `Async`.
|
|
40
83
|
|
|
41
84
|
- Lazy & cancelable HTTP requests
|
|
42
|
-
-
|
|
43
|
-
- Explicit wire / content / metadata separation
|
|
85
|
+
- Explicit wire/content separation
|
|
44
86
|
- Middleware-friendly (logging, retry, timeout, etc.)
|
|
45
87
|
- Integrated with fiber interruption via `AbortController`
|
|
46
88
|
|
|
47
|
-
|
|
48
|
-
π [**Read the HTTP module docs:** ](./docs/http.md)
|
|
89
|
+
π **Docs:** [HTTP module](./docs/http.md)
|
|
49
90
|
|
|
50
91
|
Example:
|
|
92
|
+
|
|
51
93
|
```ts
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
94
|
+
import { httpClientStream } from "brass-runtime/http";
|
|
95
|
+
import { toPromise, Runtime } from "brass-runtime/runtime";
|
|
96
|
+
|
|
97
|
+
type Post = { id: number; title: string; body: string };
|
|
98
|
+
|
|
99
|
+
const runtime = new Runtime({ env: {} });
|
|
100
|
+
|
|
101
|
+
const client = httpClientStream({ baseUrl: "https://jsonplaceholder.typicode.com" });
|
|
55
102
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
{}
|
|
59
|
-
);
|
|
103
|
+
const res = await toPromise(client.getJson<Post>("/posts/1"), runtime.env);
|
|
104
|
+
console.log(res.status, res.value.title);
|
|
60
105
|
```
|
|
61
106
|
|
|
62
107
|
---
|
|
@@ -76,10 +121,14 @@ Examples:
|
|
|
76
121
|
|
|
77
122
|
---
|
|
78
123
|
|
|
79
|
-
##
|
|
124
|
+
## Docs
|
|
80
125
|
|
|
81
|
-
|
|
82
|
-
|
|
126
|
+
- [Getting Started](./docs/getting-started.md)
|
|
127
|
+
- [Architecture](./docs/ARCHITECTURE.md)
|
|
128
|
+
- [Cancellation & Interruption](./docs/cancellation.md)
|
|
129
|
+
- [Observability: Hooks & Tracing](./docs/observability.md)
|
|
130
|
+
- [HTTP module](./docs/http.md)
|
|
131
|
+
- [Modules overview](./docs/modules.md)
|
|
83
132
|
|
|
84
133
|
---
|
|
85
134
|
|
|
@@ -88,7 +137,7 @@ Examples:
|
|
|
88
137
|
- Stream buffering with backpressure (`buffer`)
|
|
89
138
|
- Abortable async integration (`fromPromiseAbortable`)
|
|
90
139
|
- Fiber-safe `toPromise` for examples & DX
|
|
91
|
-
-
|
|
140
|
+
- HTTP client module built on top of the runtime
|
|
92
141
|
|
|
93
142
|
---
|
|
94
143
|
|
|
@@ -111,7 +160,7 @@ Examples:
|
|
|
111
160
|
- [x] Pipelines (`ZPipeline`-style)
|
|
112
161
|
|
|
113
162
|
### Libraries
|
|
114
|
-
- [x] HTTP client
|
|
163
|
+
- [x] HTTP client
|
|
115
164
|
- [ ] Retry / timeout middleware
|
|
116
165
|
- [ ] Logging / metrics layers
|
|
117
166
|
|
|
@@ -130,7 +179,7 @@ Examples:
|
|
|
130
179
|
|
|
131
180
|
- Runtime invariants matter β avoid sneaking Promises into semantics
|
|
132
181
|
- Prefer libraries on top of the runtime over changes in the core
|
|
133
|
-
- Small, focused PRs are welcome
|
|
182
|
+
- Small, focused PRs are welcome (your repo may enforce PR-only changes)
|
|
134
183
|
|
|
135
184
|
---
|
|
136
185
|
|