oxidejs 0.2.4 → 0.3.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 +24 -6
- package/dist/client-C-s6XXpS.mjs +148 -0
- package/dist/context-C1UFQ0Zc.d.mts +64 -0
- package/dist/context-zrTZyYpF.mjs +42 -0
- package/dist/index.d.mts +2 -29
- package/dist/index.mjs +103 -44
- package/dist/plugin-HZKRDuCS.mjs +602 -0
- package/dist/plugin.mjs +1 -1
- package/dist/rpc/client.d.mts +13 -0
- package/dist/rpc/client.mjs +2 -0
- package/dist/rpc-DzUkWWgQ.mjs +915 -0
- package/dist/rpc.d.mts +75 -0
- package/dist/rpc.mjs +3 -0
- package/dist/rsbuild.mjs +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/worker-dom/install.d.mts +1 -0
- package/dist/worker-dom/install.mjs +6 -0
- package/dist/worker-dom.d.mts +5 -0
- package/dist/worker-dom.mjs +16 -0
- package/package.json +19 -8
- package/virtual.d.ts +7 -4
- package/dist/plugin-nO0yjtk0.mjs +0 -954
package/dist/rpc.d.mts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { t as ActionContext } from "./context-C1UFQ0Zc.mjs";
|
|
2
|
+
import { RpcClientOptions, createClient } from "./rpc/client.mjs";
|
|
3
|
+
import { Layer, Stream } from "effect";
|
|
4
|
+
import { Rpc, RpcGroup } from "effect/unstable/rpc";
|
|
5
|
+
//#region src/rpc/server.d.ts
|
|
6
|
+
type ActionHandlerOptions = {
|
|
7
|
+
path?: string;
|
|
8
|
+
sameOrigin?: boolean;
|
|
9
|
+
transport?: "http" | "ws";
|
|
10
|
+
createContext?: (req: Request) => ActionContext | Promise<ActionContext>;
|
|
11
|
+
};
|
|
12
|
+
type ActionGroup = RpcGroup.RpcGroup<Rpc.Any>;
|
|
13
|
+
declare function createActionHandler(group: ActionGroup, handlers: Layer.Layer<unknown, unknown, unknown>, options?: ActionHandlerOptions): (request: Request) => Promise<Response>;
|
|
14
|
+
declare function disposeActionHandler(group: ActionGroup, path?: string, transport?: "http" | "ws"): Promise<void>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/rpc/ws.d.ts
|
|
17
|
+
type WsPeer = {
|
|
18
|
+
request?: Request;
|
|
19
|
+
context: Record<string, unknown>;
|
|
20
|
+
send: (data: unknown) => unknown;
|
|
21
|
+
/** Optional: register a listener when the peer disconnects. */
|
|
22
|
+
onClose?: (fn: () => void) => void;
|
|
23
|
+
};
|
|
24
|
+
type WsMessage = {
|
|
25
|
+
text: () => string;
|
|
26
|
+
};
|
|
27
|
+
type WsHooksOptions = {
|
|
28
|
+
path?: string;
|
|
29
|
+
sameOrigin?: boolean;
|
|
30
|
+
maxMessageSize?: number;
|
|
31
|
+
createContext?: (peer: WsPeer) => ActionContext | Promise<ActionContext>;
|
|
32
|
+
};
|
|
33
|
+
declare function createWsHooks(group: RpcGroup.RpcGroup<Rpc.Any>, handlers: Layer.Layer<unknown, unknown, unknown>, options?: WsHooksOptions): {
|
|
34
|
+
upgrade(req: Request): Response | undefined;
|
|
35
|
+
message(peer: WsPeer, message: WsMessage): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/rpc/stream.d.ts
|
|
39
|
+
declare function asyncGenToStream<T>(gen: AsyncGenerator<T, unknown, unknown>): Stream.Stream<T, Error, never>;
|
|
40
|
+
/**
|
|
41
|
+
* Re-enter `run` for every generator pull so AsyncLocalStorage request context
|
|
42
|
+
* stays available across yields (Effect may drain the stream after the outer ALS scope ends).
|
|
43
|
+
*/
|
|
44
|
+
declare function bindAsyncGenContext<T>(gen: AsyncGenerator<T, unknown, unknown>, run: <R>(fn: () => R) => R): AsyncGenerator<T, unknown, unknown>;
|
|
45
|
+
/** Create a generator inside `run`, then keep every subsequent pull inside `run`. */
|
|
46
|
+
declare function asyncGenToStreamInContext<T>(create: () => AsyncGenerator<T, unknown, unknown>, run: <R>(fn: () => R) => R): Stream.Stream<T, Error, never>;
|
|
47
|
+
declare function streamToAsyncGen<T>(stream: Stream.Stream<T>): AsyncIterable<T>;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/rpc/scrub.d.ts
|
|
50
|
+
/** Mutable repair state so each Defect can claim a distinct originating request id. */
|
|
51
|
+
type IdRepairState = {
|
|
52
|
+
/** Request ids not yet claimed by a terminal (non-chunk) response. */
|
|
53
|
+
remaining: Set<unknown>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Scrub one JSON-RPC response object.
|
|
57
|
+
* Effect encodes Defects with `id: -32603`; reclaim the originating request id from `state.remaining`.
|
|
58
|
+
*/
|
|
59
|
+
declare function scrubRpcMessage(msg: unknown, requestIds?: readonly unknown[], state?: IdRepairState): unknown;
|
|
60
|
+
/**
|
|
61
|
+
* Rewrite a JSON / NDJSON body so clients never see Effect `_tag` / `data` trees.
|
|
62
|
+
* Accepts a single object, a JSON array, or newline-delimited frames.
|
|
63
|
+
*/
|
|
64
|
+
declare function scrubRpcJson(body: string, requestIds?: readonly unknown[]): string;
|
|
65
|
+
/** Collect JSON-RPC request ids from a unary object or batch array body. */
|
|
66
|
+
declare function extractJsonRpcRequestIds(body: ArrayBuffer | Uint8Array | string): unknown[];
|
|
67
|
+
/** Ensure a body is a valid NDJSON frame (Effect's ndJsonRpc decode requires a trailing newline). */
|
|
68
|
+
declare function ensureNdjsonBody(buf: ArrayBuffer): Uint8Array<ArrayBuffer>;
|
|
69
|
+
/**
|
|
70
|
+
* TransformStream that scrubs Effect defect payloads one NDJSON line at a time,
|
|
71
|
+
* so long-running stream actions stay incremental.
|
|
72
|
+
*/
|
|
73
|
+
declare function scrubNdjsonTransform(requestIds?: readonly unknown[]): TransformStream<Uint8Array, Uint8Array>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type ActionHandlerOptions, type RpcClientOptions, type WsHooksOptions, asyncGenToStream, asyncGenToStreamInContext, bindAsyncGenContext, createActionHandler, createClient, createWsHooks, disposeActionHandler, ensureNdjsonBody, extractJsonRpcRequestIds, scrubNdjsonTransform, scrubRpcJson, scrubRpcMessage, streamToAsyncGen };
|
package/dist/rpc.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as extractJsonRpcRequestIds, c as scrubRpcMessage, i as ensureNdjsonBody, n as createActionHandler, o as scrubNdjsonTransform, r as disposeActionHandler, s as scrubRpcJson, t as createWsHooks } from "./rpc-DzUkWWgQ.mjs";
|
|
2
|
+
import { a as streamToAsyncGen, i as bindAsyncGenContext, n as asyncGenToStream, r as asyncGenToStreamInContext, t as createClient } from "./client-C-s6XXpS.mjs";
|
|
3
|
+
export { asyncGenToStream, asyncGenToStreamInContext, bindAsyncGenContext, createActionHandler, createClient, createWsHooks, disposeActionHandler, ensureNdjsonBody, extractJsonRpcRequestIds, scrubNdjsonTransform, scrubRpcJson, scrubRpcMessage, streamToAsyncGen };
|
package/dist/rsbuild.mjs
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as linkedom from "linkedom";
|
|
2
|
+
//#region src/worker-dom.ts
|
|
3
|
+
/** Install a minimal DOM on `globalThis` for Ilha `renderToString` in Workers. */
|
|
4
|
+
function ensureWorkerDom() {
|
|
5
|
+
if (typeof globalThis.document !== "undefined") return;
|
|
6
|
+
const window = linkedom.parseHTML("<!DOCTYPE html><html><body></body></html>");
|
|
7
|
+
const g = globalThis;
|
|
8
|
+
g.document = window.document;
|
|
9
|
+
g.window = window;
|
|
10
|
+
for (const [key, value] of Object.entries(linkedom)) {
|
|
11
|
+
if (key === "parseHTML" || key === "parseJSON" || key === "toJSON" || key === "Document") continue;
|
|
12
|
+
if (typeof value === "function" && /^[A-Z]/.test(key)) g[key] = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ensureWorkerDom };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxidejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vite/Rsbuild plugin. One build → dist/server.js + optional client. Server actions via *.server.ts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -45,6 +45,22 @@
|
|
|
45
45
|
"./client": {
|
|
46
46
|
"types": "./client.d.ts"
|
|
47
47
|
},
|
|
48
|
+
"./rpc": {
|
|
49
|
+
"types": "./dist/rpc.d.mts",
|
|
50
|
+
"import": "./dist/rpc.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./rpc/client": {
|
|
53
|
+
"types": "./dist/rpc/client.d.mts",
|
|
54
|
+
"import": "./dist/rpc/client.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./worker-dom": {
|
|
57
|
+
"types": "./dist/worker-dom.d.mts",
|
|
58
|
+
"import": "./dist/worker-dom.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./worker-dom/install": {
|
|
61
|
+
"types": "./dist/worker-dom/install.d.mts",
|
|
62
|
+
"import": "./dist/worker-dom/install.mjs"
|
|
63
|
+
},
|
|
48
64
|
"./tsconfig": "./tsconfig.app.json"
|
|
49
65
|
},
|
|
50
66
|
"scripts": {
|
|
@@ -56,15 +72,13 @@
|
|
|
56
72
|
"prepublishOnly": "bun run build"
|
|
57
73
|
},
|
|
58
74
|
"dependencies": {
|
|
75
|
+
"effect": "~4.0.0-rc.112",
|
|
76
|
+
"linkedom": "^0.18.13",
|
|
59
77
|
"unplugin": "^3.3.0"
|
|
60
78
|
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"tacho": "^0.6.1"
|
|
63
|
-
},
|
|
64
79
|
"peerDependencies": {
|
|
65
80
|
"@rsbuild/core": "*",
|
|
66
81
|
"crossws": "*",
|
|
67
|
-
"tacho": "*",
|
|
68
82
|
"vite": "*"
|
|
69
83
|
},
|
|
70
84
|
"peerDependenciesMeta": {
|
|
@@ -76,9 +90,6 @@
|
|
|
76
90
|
},
|
|
77
91
|
"vite": {
|
|
78
92
|
"optional": true
|
|
79
|
-
},
|
|
80
|
-
"tacho": {
|
|
81
|
-
"optional": true
|
|
82
93
|
}
|
|
83
94
|
},
|
|
84
95
|
"engines": {
|
package/virtual.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
declare module "virtual:oxide/actions" {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { Rpc, RpcGroup } from "effect/unstable/rpc";
|
|
3
|
+
import type { Layer } from "effect";
|
|
4
|
+
|
|
5
|
+
const actionsGroup: RpcGroup.RpcGroup<Rpc.Any>;
|
|
6
|
+
export const actionsHandlers: Layer.Layer<unknown, unknown, unknown>;
|
|
7
|
+
export default actionsGroup;
|
|
8
|
+
export { actionsGroup as actions };
|
|
6
9
|
}
|
|
7
10
|
|
|
8
11
|
declare module "virtual:oxide/client" {
|