ziex 0.1.0-dev.787 → 0.1.0-dev.805
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 +3 -1
- package/app.d.ts +112 -0
- package/build.zig +5 -0
- package/build.zig.zon +7 -0
- package/cloudflare/app.d.ts +2 -95
- package/cloudflare/do.d.ts +48 -0
- package/cloudflare/index.d.ts +4 -4
- package/cloudflare/index.js +470 -276
- package/cloudflare/kv.d.ts +2 -27
- package/cloudflare/worker.d.ts +3 -148
- package/index.d.ts +2 -1
- package/index.js +257 -1028
- package/kv.d.ts +27 -0
- package/package.json +1 -5
- package/runtime.d.ts +70 -0
- package/wasi.d.ts +61 -0
- package/wasm/core.d.ts +78 -0
- package/wasm/index.d.ts +9 -35
- package/wasm/index.js +103 -59
- package/wasm/init.js +97 -59
- package/wasm/wasi.d.ts +28 -0
- package/hono/index.d.ts +0 -92
- package/hono/index.js +0 -1515
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/ziex-dev/branding/main/banner.svg" alt="Ziex banner" width="100%" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
5
|
A full-stack web framework for Zig. Write declarative UI components using familiar JSX patterns, transpiled to efficient Zig code.
|
|
4
6
|
|
package/app.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DurableObjectNamespace } from "./runtime";
|
|
2
|
+
import type { KVNamespace } from "./kv";
|
|
3
|
+
import type { WASI } from "./wasi";
|
|
4
|
+
/**
|
|
5
|
+
* Anything that can be resolved to a `WebAssembly.Module`:
|
|
6
|
+
* - `WebAssembly.Module` — already compiled (Cloudflare Workers, wrangler)
|
|
7
|
+
* - `ArrayBuffer` / `ArrayBufferView` — raw WASM bytes
|
|
8
|
+
* - `Response` — a fetch() response whose body is the WASM binary
|
|
9
|
+
* - `string` — an HTTP(S) URL or an absolute file path (Bun)
|
|
10
|
+
* - `URL` — a URL object
|
|
11
|
+
*/
|
|
12
|
+
export type WasmInput = WebAssembly.Module | ArrayBuffer | ArrayBufferView | Response | string | URL;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve any supported WASM input to a compiled `WebAssembly.Module`.
|
|
15
|
+
* The result is NOT cached here — cache it at the call site if needed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveModule(input: WasmInput): Promise<WebAssembly.Module>;
|
|
18
|
+
/** Keys of `Env` whose value extends {@link KVNamespace}. */
|
|
19
|
+
type KVKey<Env> = {
|
|
20
|
+
[K in keyof Env]: Env[K] extends KVNamespace ? K : never;
|
|
21
|
+
}[keyof Env];
|
|
22
|
+
/** Keys of `Env` whose value extends {@link DurableObjectNamespace}. */
|
|
23
|
+
type DOKey<Env> = {
|
|
24
|
+
[K in keyof Env]: Env[K] extends DurableObjectNamespace ? K : never;
|
|
25
|
+
}[keyof Env];
|
|
26
|
+
type ZiexOptions<Env> = {
|
|
27
|
+
/** WASM module — accepts any {@link WasmInput}. Resolved and cached on first request. */
|
|
28
|
+
module: WasmInput;
|
|
29
|
+
/** Optional pre-configured WASI instance. */
|
|
30
|
+
wasi?: WASI;
|
|
31
|
+
/** Extra WASM import namespaces. */
|
|
32
|
+
imports?: (mem: () => WebAssembly.Memory) => Record<string, Record<string, unknown>>;
|
|
33
|
+
/**
|
|
34
|
+
* KV namespace bindings. Two forms are supported:
|
|
35
|
+
*
|
|
36
|
+
* - **Env key**: a single key from `Env` whose value is a `KVNamespace` — used as the `"default"` binding.
|
|
37
|
+
* - **Name map**: `{ [bindingName]: envKey }` — map namespace names to env keys.
|
|
38
|
+
*
|
|
39
|
+
* @example Single env key (becomes the "default" binding)
|
|
40
|
+
* ```ts
|
|
41
|
+
* kv: "MY_KV"
|
|
42
|
+
* ```
|
|
43
|
+
* @example Name map
|
|
44
|
+
* ```ts
|
|
45
|
+
* kv: { default: "MY_KV", users: "USERS_KV" }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
kv?: KVKey<Env> | Record<string, KVKey<Env>>;
|
|
49
|
+
/**
|
|
50
|
+
* Env key whose value is a `DurableObjectNamespace` for WebSocket pub/sub.
|
|
51
|
+
* Requires `createWebSocketDO` export on the worker.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* websocket: "ChatRoom"
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
websocket?: DOKey<Env>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Main Ziex application class. Mirrors the Hono API style — construct once,
|
|
62
|
+
* export as default, and the runtime calls `fetch` for you.
|
|
63
|
+
*
|
|
64
|
+
* Works on Cloudflare Workers, Bun, and Vercel Edge out of the box.
|
|
65
|
+
*
|
|
66
|
+
* @example Cloudflare Workers / wrangler
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { Ziex } from "ziex";
|
|
69
|
+
* import module from "./app.wasm";
|
|
70
|
+
*
|
|
71
|
+
* const app = new Ziex<Env>({
|
|
72
|
+
* module,
|
|
73
|
+
* kv: (env) => ({ default: env.KV }),
|
|
74
|
+
* });
|
|
75
|
+
* export default app;
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Bun
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { Ziex } from "ziex";
|
|
81
|
+
* import wasmPath from "./app.wasm" with { type: "wasm" };
|
|
82
|
+
*
|
|
83
|
+
* const app = new Ziex({ module: wasmPath });
|
|
84
|
+
* export default app;
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example Vercel Edge
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { Ziex } from "ziex";
|
|
90
|
+
* import { handle } from "ziex/vercel";
|
|
91
|
+
*
|
|
92
|
+
* const app = new Ziex({ module: "https://example.com/app.wasm" });
|
|
93
|
+
* export default handle(app);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare class Ziex<Env = Record<string, unknown>> {
|
|
97
|
+
private readonly options;
|
|
98
|
+
private resolved;
|
|
99
|
+
constructor(options: ZiexOptions<Env>);
|
|
100
|
+
private getModule;
|
|
101
|
+
private resolveKV;
|
|
102
|
+
/**
|
|
103
|
+
* Fetch handler called by the runtime on every request.
|
|
104
|
+
*
|
|
105
|
+
* Arrow function so `this` is always the class instance, even when the
|
|
106
|
+
* runtime extracts `fetch` from the exported object (e.g. Bun).
|
|
107
|
+
*/
|
|
108
|
+
fetch: (request: Request, env: Env, ctx?: {
|
|
109
|
+
waitUntil(p: Promise<unknown>): void;
|
|
110
|
+
}) => Promise<Response>;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
package/build.zig
ADDED
package/build.zig.zon
ADDED
package/cloudflare/app.d.ts
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
type
|
|
3
|
-
idFromName(name: string): unknown;
|
|
4
|
-
get(id: unknown): {
|
|
5
|
-
fetch(req: Request): Promise<Response>;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
type WASI = {
|
|
9
|
-
wasiImport: Record<string, (...args: any[]) => unknown>;
|
|
10
|
-
start(instance: {
|
|
11
|
-
exports: {
|
|
12
|
-
memory: WebAssembly.Memory;
|
|
13
|
-
_start: () => unknown;
|
|
14
|
-
};
|
|
15
|
-
}): number;
|
|
16
|
-
initialize?(instance: {
|
|
17
|
-
exports: {
|
|
18
|
-
memory: WebAssembly.Memory;
|
|
19
|
-
_initialize?: () => unknown;
|
|
20
|
-
};
|
|
21
|
-
}): void;
|
|
22
|
-
};
|
|
23
|
-
type ZiexOptions<Env> = {
|
|
24
|
-
/** Compiled WASM module for the Ziex app. */
|
|
25
|
-
module: WebAssembly.Module;
|
|
26
|
-
/** Optional pre-configured WASI instance. */
|
|
27
|
-
wasi?: WASI;
|
|
28
|
-
/** Extra WASM import namespaces. */
|
|
29
|
-
imports?: (mem: () => WebAssembly.Memory) => Record<string, Record<string, unknown>>;
|
|
30
|
-
/**
|
|
31
|
-
* Factory that maps platform env bindings to Ziex KV namespaces.
|
|
32
|
-
* Called per-request so bindings are resolved from the live env.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* kv: (env) => ({ default: env.MY_KV })
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
kv?: (env: Env) => Record<string, KVNamespace>;
|
|
40
|
-
/**
|
|
41
|
-
* Factory that maps platform env bindings to a Durable Object namespace
|
|
42
|
-
* for WebSocket pub/sub. Requires `createWebSocketDO` export on the worker.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* websocket: (env) => env.ChatRoom
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
websocket?: (env: Env) => DurableObjectNamespace;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Main Ziex application class. Mirrors the Hono API style — construct once,
|
|
53
|
-
* export as default, and the runtime calls `fetch` for you.
|
|
54
|
-
*
|
|
55
|
-
* Works on Cloudflare Workers out of the box. For other platforms use the
|
|
56
|
-
* adapter methods (e.g. `app.vercel()`).
|
|
57
|
-
*
|
|
58
|
-
* @example Cloudflare Workers
|
|
59
|
-
* ```ts
|
|
60
|
-
* import { Ziex } from "ziex/cloudflare";
|
|
61
|
-
* import module from "./app.wasm";
|
|
62
|
-
*
|
|
63
|
-
* const app = new Ziex<Env>({
|
|
64
|
-
* module,
|
|
65
|
-
* kv: (env) => ({ default: env.KV }),
|
|
66
|
-
* websocket: (env) => env.ChatRoom,
|
|
67
|
-
* });
|
|
68
|
-
*
|
|
69
|
-
* export const ChatRoom = createWebSocketDO(module);
|
|
70
|
-
* export default app;
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example Vercel Edge
|
|
74
|
-
* ```ts
|
|
75
|
-
* import { Ziex } from "ziex/cloudflare";
|
|
76
|
-
* import module from "./app.wasm"; // fetch at runtime on Vercel, see vercel adapter
|
|
77
|
-
*
|
|
78
|
-
* const app = new Ziex({ module });
|
|
79
|
-
* export default app.vercel();
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare class Ziex<Env = Record<string, unknown>> {
|
|
83
|
-
private readonly options;
|
|
84
|
-
constructor(options: ZiexOptions<Env>);
|
|
85
|
-
/**
|
|
86
|
-
* Cloudflare Workers fetch handler.
|
|
87
|
-
*
|
|
88
|
-
* `env` and `ctx` are injected by the CF runtime — you never call this
|
|
89
|
-
* directly. Just `export default app` and Cloudflare handles the rest.
|
|
90
|
-
*/
|
|
91
|
-
fetch(request: Request, env: Env, ctx?: {
|
|
92
|
-
waitUntil(p: Promise<unknown>): void;
|
|
93
|
-
}): Promise<Response>;
|
|
94
|
-
}
|
|
95
|
-
export {};
|
|
1
|
+
export { Ziex, resolveModule } from "../app";
|
|
2
|
+
export type { WasmInput } from "../app";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { WsState } from "../runtime";
|
|
2
|
+
import type { KVNamespace } from "../kv";
|
|
3
|
+
type ConnState = WsState & {
|
|
4
|
+
topics: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Create a Durable Object class that handles WebSocket connections for a ZX app.
|
|
8
|
+
*
|
|
9
|
+
* Each DO instance corresponds to one "room" (keyed by pathname). All clients
|
|
10
|
+
* connecting to the same route share a DO instance, enabling pub/sub via
|
|
11
|
+
* `ctx.socket.subscribe()` / `ctx.socket.publish()`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // worker.ts
|
|
16
|
+
* import { Ziex } from "ziex";
|
|
17
|
+
* import { createWebSocketDO } from "ziex/cloudflare";
|
|
18
|
+
* import module from "./app.wasm";
|
|
19
|
+
*
|
|
20
|
+
* export const ZxWS = createWebSocketDO(module);
|
|
21
|
+
*
|
|
22
|
+
* export default new Ziex({
|
|
23
|
+
* module,
|
|
24
|
+
* websocket: (env) => env.ZxWS,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createWebSocketDO(module: WebAssembly.Module, options?: {
|
|
29
|
+
/**
|
|
30
|
+
* KV namespace bindings for the DO. Pass a factory that receives the DO's
|
|
31
|
+
* `env` so bindings are resolved at runtime:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* createWebSocketDO(module, { kv: (env) => ({ default: env.KV }) })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
kv?: (env: any) => Record<string, KVNamespace>;
|
|
38
|
+
imports?: (mem: () => WebAssembly.Memory) => Record<string, Record<string, unknown>>;
|
|
39
|
+
}): {
|
|
40
|
+
new (state: any, env: any): {
|
|
41
|
+
readonly doState: any;
|
|
42
|
+
readonly env: any;
|
|
43
|
+
/** All active connections in this room, keyed by their server-side WebSocket. */
|
|
44
|
+
readonly connections: Map<WebSocket, ConnState>;
|
|
45
|
+
fetch(request: Request): Promise<Response>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export {};
|
package/cloudflare/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * as worker from "
|
|
2
|
-
export * as kv from "
|
|
3
|
-
export { Ziex } from "
|
|
4
|
-
export { createWebSocketDO } from "./
|
|
1
|
+
export * as worker from "../runtime";
|
|
2
|
+
export * as kv from "../kv";
|
|
3
|
+
export { Ziex } from "../app";
|
|
4
|
+
export { createWebSocketDO } from "./do";
|