@nestbridge/runtime 0.1.0 → 0.1.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 +66 -0
- package/build/nestbridge.runtime.js +1 -1
- package/package.json +6 -1
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @nestbridge/runtime
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MDReal32/nestbridge/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/@nestbridge/runtime)
|
|
5
|
+
|
|
6
|
+
The browser-side `fetch()` client that NestBridge's generated controller
|
|
7
|
+
modules call into. Zero dependencies, and no knowledge of NestJS or Vite —
|
|
8
|
+
see the [repository README](../../README.md) for how this fits into the rest
|
|
9
|
+
of NestBridge.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add @nestbridge/runtime
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configure once
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { configureNestBridge } from '@nestbridge/runtime';
|
|
21
|
+
|
|
22
|
+
configureNestBridge({
|
|
23
|
+
baseURL: '/api',
|
|
24
|
+
async headers() {
|
|
25
|
+
return { authorization: `Bearer ${getToken()}` };
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Call this once, before your first request — typically at the top of your
|
|
31
|
+
app's entry point. `configureNestBridge` replaces the whole config rather
|
|
32
|
+
than merging, so pass everything you need in one call.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
interface NestBridgeConfig {
|
|
36
|
+
baseURL?: string;
|
|
37
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
38
|
+
fetch?: typeof globalThis.fetch;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## `request()`
|
|
43
|
+
|
|
44
|
+
Generated controller modules call `request()` directly; you won't normally
|
|
45
|
+
call it yourself. Non-2xx responses reject with a `NestBridgeError`:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
class NestBridgeError<T = unknown> extends Error {
|
|
49
|
+
readonly status: number;
|
|
50
|
+
readonly body: T;
|
|
51
|
+
readonly response: Response;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Types
|
|
56
|
+
|
|
57
|
+
- `NestBridgeConfig` — the shape passed to `configureNestBridge`.
|
|
58
|
+
- `NestBridgeRequest` — the shape of a single generated request.
|
|
59
|
+
- `RemoteMethod<T>` / `RemoteResult<T>` — the type-level helpers that project
|
|
60
|
+
a real controller method's parameters and return type onto its generated
|
|
61
|
+
client method. Useful outside code generation too — a manual SDK wrapper, a
|
|
62
|
+
mock, a test double.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestbridge/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/MDReal32/nestbridge.git",
|
|
9
|
+
"directory": "packages/runtime"
|
|
10
|
+
},
|
|
6
11
|
"main": "./build/nestbridge.runtime.js",
|
|
7
12
|
"types": "./build/nestbridge.runtime.d.ts",
|
|
8
13
|
"exports": {
|