@bluelibs/runner 4.7.0-alpha → 4.7.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.md +16 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,32 +139,29 @@ Runner auto-detects the platform and adapts behavior at runtime. The only featur
|
|
|
139
139
|
|
|
140
140
|
### Serialization (EJSON)
|
|
141
141
|
|
|
142
|
-
Runner uses EJSON by default. Think of it as JSON with superpowers: it safely round‑trips values like Date, RegExp, and even your own custom types across HTTP and between Node and the browser.
|
|
142
|
+
Runner uses [EJSON](https://www.npmjs.com/package/@bluelibs/ejson) by default. Think of it as JSON with superpowers: it safely round‑trips values like Date, RegExp, and even your own custom types across HTTP and between Node and the browser.
|
|
143
143
|
|
|
144
144
|
- By default, Runner’s HTTP clients and exposures use the EJSON serializer
|
|
145
145
|
- You can call `getDefaultSerializer()` for the shared serializer instance
|
|
146
146
|
- A global serializer is also exposed as a resource: `globals.resources.serializer`
|
|
147
147
|
|
|
148
148
|
```ts
|
|
149
|
-
import {
|
|
150
|
-
|
|
151
|
-
// 1) Quick use
|
|
152
|
-
const s = getDefaultSerializer();
|
|
153
|
-
const text = s.stringify({ when: new Date() });
|
|
154
|
-
const obj = s.parse<{ when: Date }>(text);
|
|
149
|
+
import { r, globals } from "@bluelibs/runner";
|
|
155
150
|
|
|
156
151
|
// 2) Register custom EJSON types centrally via the global serializer resource
|
|
157
152
|
const ejsonSetup = r
|
|
158
153
|
.resource("app.serialization.setup")
|
|
159
154
|
.dependencies({ serializer: globals.resources.serializer })
|
|
160
155
|
.init(async (_config, { serializer }) => {
|
|
156
|
+
const text = s.stringify({ when: new Date() });
|
|
157
|
+
const obj = s.parse<{ when: Date }>(text);
|
|
161
158
|
class Distance {
|
|
162
159
|
constructor(public value: number, public unit: string) {}
|
|
163
160
|
toJSONValue() {
|
|
164
161
|
return { value: this.value, unit: this.unit } as const;
|
|
165
162
|
}
|
|
166
163
|
typeName() {
|
|
167
|
-
return "Distance"
|
|
164
|
+
return "Distance";
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
|
|
@@ -186,10 +183,11 @@ Here's a sneak peek of how you can expose your application and configure a clien
|
|
|
186
183
|
import { r, globals } from "@bluelibs/runner";
|
|
187
184
|
import { nodeExposure } from "@bluelibs/runner/node";
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.
|
|
186
|
+
let app = r.resource("app");
|
|
187
|
+
|
|
188
|
+
if (process.env.SERVER) {
|
|
189
|
+
// 1. Expose your local tasks and events over HTTP, only when server mode is active.
|
|
190
|
+
app.register([
|
|
193
191
|
// ... your tasks and events
|
|
194
192
|
nodeExposure.with({
|
|
195
193
|
http: {
|
|
@@ -197,16 +195,17 @@ const app = r
|
|
|
197
195
|
listen: { port: 7070 },
|
|
198
196
|
},
|
|
199
197
|
}),
|
|
200
|
-
])
|
|
201
|
-
|
|
198
|
+
]);
|
|
199
|
+
}
|
|
200
|
+
app = app.build();
|
|
202
201
|
|
|
203
202
|
// 2. In another app, define a tunnel resource to call a remote Runner
|
|
204
|
-
const
|
|
203
|
+
const remoteTasksTunnel = r
|
|
205
204
|
.resource("app.tunnels.http")
|
|
206
205
|
.tags([globals.tags.tunnel])
|
|
207
206
|
.init(async () => ({
|
|
208
|
-
mode: "client"
|
|
209
|
-
transport: "http"
|
|
207
|
+
mode: "client", // or "server", or "none", or "both" for emulating network infrastructure
|
|
208
|
+
transport: "http", // the only one supported for now
|
|
210
209
|
// Selectively forward tasks starting with "remote.tasks."
|
|
211
210
|
tasks: (t) => t.id.startsWith("remote.tasks."),
|
|
212
211
|
client: globals.tunnels.http.createClient({
|