ziex 0.1.0-dev.805 → 0.1.0-dev.852

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.
@@ -377,7 +377,7 @@ class ZxBridge extends ZxBridgeCore {
377
377
  }
378
378
  submitFormActionAsync(form, statesJson, fetchId) {
379
379
  const formData = new FormData(form);
380
- formData.append("__zx_states", statesJson);
380
+ formData.append("__$states", statesJson);
381
381
  fetch(window.location.href, {
382
382
  method: "POST",
383
383
  headers: { "X-ZX-Action": "1" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziex",
3
- "version": "0.1.0-dev.805",
3
+ "version": "0.1.0-dev.852",
4
4
  "description": "ZX is a framework for building web applications with Zig.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/wasm/index.js CHANGED
@@ -377,7 +377,7 @@ class ZxBridge extends ZxBridgeCore {
377
377
  }
378
378
  submitFormActionAsync(form, statesJson, fetchId) {
379
379
  const formData = new FormData(form);
380
- formData.append("__zx_states", statesJson);
380
+ formData.append("__$states", statesJson);
381
381
  fetch(window.location.href, {
382
382
  method: "POST",
383
383
  headers: { "X-ZX-Action": "1" },
package/wasm/init.js CHANGED
@@ -366,7 +366,7 @@ class ZxBridge extends ZxBridgeCore {
366
366
  }
367
367
  submitFormActionAsync(form, statesJson, fetchId) {
368
368
  const formData = new FormData(form);
369
- formData.append("__zx_states", statesJson);
369
+ formData.append("__$states", statesJson);
370
370
  fetch(window.location.href, {
371
371
  method: "POST",
372
372
  headers: { "X-ZX-Action": "1" },
package/app.d.ts DELETED
@@ -1,112 +0,0 @@
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 {};
@@ -1,96 +0,0 @@
1
- /**
2
- * Ziex adapter for AWS Lambda (API Gateway v1, v2, and ALB).
3
- *
4
- * Based on Hono's AWS Lambda adapter implementation.
5
- *
6
- * @example API Gateway v2 (HTTP API)
7
- * ```ts
8
- * import { Ziex } from "ziex/cloudflare";
9
- * import { handle } from "ziex/aws-lambda";
10
- * import module from "./app.wasm";
11
- *
12
- * const app = new Ziex({ module });
13
- * export const handler = handle(app);
14
- * ```
15
- */
16
- type ApiGwV1Event = {
17
- version?: "1.0";
18
- httpMethod: string;
19
- path: string;
20
- headers: Record<string, string> | null;
21
- multiValueHeaders: Record<string, string[]> | null;
22
- queryStringParameters: Record<string, string> | null;
23
- multiValueQueryStringParameters: Record<string, string[]> | null;
24
- body: string | null;
25
- isBase64Encoded: boolean;
26
- requestContext: {
27
- elb?: unknown;
28
- };
29
- };
30
- type ApiGwV2Event = {
31
- version: "2.0";
32
- requestContext: {
33
- http: {
34
- method: string;
35
- };
36
- };
37
- rawPath: string;
38
- rawQueryString: string;
39
- headers: Record<string, string>;
40
- body?: string;
41
- isBase64Encoded: boolean;
42
- };
43
- type AlbEvent = {
44
- httpMethod: string;
45
- path: string;
46
- headers: Record<string, string> | null;
47
- multiValueHeaders: Record<string, string[]> | null;
48
- queryStringParameters: Record<string, string> | null;
49
- multiValueQueryStringParameters: Record<string, string[]> | null;
50
- body: string | null;
51
- isBase64Encoded: boolean;
52
- requestContext: {
53
- elb: unknown;
54
- };
55
- };
56
- export type LambdaEvent = ApiGwV1Event | ApiGwV2Event | AlbEvent;
57
- export type LambdaContext = {
58
- functionName: string;
59
- functionVersion: string;
60
- invokedFunctionArn: string;
61
- memoryLimitInMB: string;
62
- awsRequestId: string;
63
- logGroupName: string;
64
- logStreamName: string;
65
- callbackWaitsForEmptyEventLoop: boolean;
66
- getRemainingTimeInMillis(): number;
67
- };
68
- export type LambdaResult = {
69
- statusCode: number;
70
- headers: Record<string, string>;
71
- multiValueHeaders: Record<string, string[]>;
72
- body: string;
73
- isBase64Encoded: boolean;
74
- cookies?: string[];
75
- };
76
- type FetchApp = {
77
- fetch(req: Request, env?: unknown, ctx?: unknown): Promise<Response>;
78
- };
79
- export type HandleOptions = {
80
- /**
81
- * Content types to encode as base64 in the Lambda response.
82
- * By default, non-text content types are base64 encoded automatically.
83
- */
84
- binaryMediaTypes?: string[];
85
- };
86
- /**
87
- * Wrap a Ziex app as an AWS Lambda handler.
88
- *
89
- * @example
90
- * ```ts
91
- * import { handle } from "ziex/aws-lambda";
92
- * export const handler = handle(app);
93
- * ```
94
- */
95
- export declare function handle(app: FetchApp, options?: HandleOptions): (event: LambdaEvent, _context?: LambdaContext) => Promise<LambdaResult>;
96
- export {};
@@ -1,2 +0,0 @@
1
- export { Ziex, resolveModule } from "../app";
2
- export type { WasmInput } from "../app";
@@ -1,48 +0,0 @@
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 {};
@@ -1,4 +0,0 @@
1
- export * as worker from "../runtime";
2
- export * as kv from "../kv";
3
- export { Ziex } from "../app";
4
- export { createWebSocketDO } from "./do";
@@ -1,2 +0,0 @@
1
- export { createMemoryKV, createKVImports } from "../kv";
2
- export type { KVNamespace } from "../kv";
@@ -1,3 +0,0 @@
1
- export { run, buildWsImports, attachWebSocket } from "../runtime";
2
- export type { DurableObjectNamespace, WsState } from "../runtime";
3
- export { createWebSocketDO } from "./do";
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { Ziex } from "./app";
2
- export type { WasmInput } from "./app";
package/kv.d.ts DELETED
@@ -1,27 +0,0 @@
1
- export interface KVNamespace {
2
- get(key: string): Promise<string | null>;
3
- put(key: string, value: string, options?: {
4
- expiration?: number;
5
- expirationTtl?: number;
6
- }): Promise<void>;
7
- delete(key: string): Promise<void>;
8
- list(options?: {
9
- prefix?: string;
10
- }): Promise<{
11
- keys: {
12
- name: string;
13
- }[];
14
- }>;
15
- }
16
- /**
17
- * In-memory KV namespace. Used as the default shim on platforms that don't
18
- * provide a real KV binding (e.g. Vercel). Data lives only for the lifetime
19
- * of the isolate instance.
20
- */
21
- export declare function createMemoryKV(): KVNamespace;
22
- /**
23
- * Create a `__zx_kv` import object for use with `run({ kv: ... })`.
24
- * Always returns a valid import object. When JSPI is unavailable all KV
25
- * operations are stubbed (get → not-found, put/delete → success, list → []).
26
- */
27
- export declare function createKVImports(bindings: Record<string, KVNamespace>, getMemory: () => WebAssembly.Memory): Record<string, unknown>;
package/react/dom.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { ComponentMetadata } from "./types";
2
- export type PreparedComponent = {
3
- domNode: HTMLElement;
4
- props: Record<string, any> & {
5
- dangerouslySetInnerHTML?: {
6
- __html: string;
7
- };
8
- };
9
- Component: (props: any) => React.ReactElement;
10
- };
11
- export declare function prepareComponent(component: ComponentMetadata): Promise<PreparedComponent>;
12
- export declare function filterComponents(components: ComponentMetadata[]): ComponentMetadata[];
13
- export type DiscoveredComponent = {
14
- id: string;
15
- name: string;
16
- props: Record<string, any>;
17
- container: HTMLElement;
18
- };
19
- export declare function discoverComponents(): DiscoveredComponent[];
20
- export type ComponentRegistry = Record<string, () => Promise<(props: any) => React.ReactElement>>;
21
- export declare function hydrateAll(registry: ComponentRegistry, render: (container: HTMLElement, Component: (props: any) => React.ReactElement, props: Record<string, any>) => void): Promise<void>;
package/react/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { prepareComponent, filterComponents, discoverComponents, hydrateAll, type PreparedComponent, type DiscoveredComponent, type ComponentRegistry, } from "./dom";
2
- export type { ComponentMetadata } from "./types";
package/react/types.d.ts DELETED
@@ -1,190 +0,0 @@
1
- /**
2
- * Metadata for a client-side component used within a ZX file.
3
- *
4
- * This type represents the metadata for components that are marked with the `@rendering` attribute
5
- * in ZX files. When a component is declared with `@rendering={.react}` or `@rendering={.client}` in a
6
- * `.zx` file, the ZX transpiler generates a `ComponentMetadata` entry that is included in the
7
- * generated `components` array.
8
- *
9
- * @example
10
- * ```tsx
11
- * // In a ZX file (page.zx):
12
- * <CounterComponent @rendering={.react} max_count={10} />
13
- *
14
- * // Generated components array (components.ts):
15
- * export const components: ComponentMetadata[] = [
16
- * {
17
- * name: "CounterComponent",
18
- * path: "./components/CounterComponent.tsx",
19
- * id: "zx-dcde04c415da9d1b15ca2690d8b497ae",
20
- * type: "react",
21
- * import: () => import('./components/CounterComponent.tsx')
22
- * }
23
- * ];
24
- * ```
25
- *
26
- * @example
27
- * ```tsx
28
- * // Using ComponentMetadata with prepareComponent:
29
- * import { prepareComponent, type ComponentMetadata } from "ziex";
30
- *
31
- * for (const component of components) {
32
- * const { domNode, props, Component } = await prepareComponent(component);
33
- * // Render component to DOM node
34
- * }
35
- * ```
36
- */
37
- export type ComponentMetadata = {
38
- /**
39
- * The name of the component as declared in the ZX file.
40
- *
41
- * This is the tag name used in JSX syntax within `.zx` files. It corresponds to the component
42
- * identifier used in the component declaration (e.g., `<CounterComponent />`).
43
- *
44
- * @example
45
- * ```tsx
46
- * // In ZX file:
47
- * <CounterComponent @rendering={.react} />
48
- *
49
- * // name will be: "CounterComponent"
50
- * ```
51
- */
52
- name: string;
53
- /**
54
- * The file path to the component module.
55
- *
56
- * This is the relative or absolute path to the component file that will be dynamically imported
57
- * at runtime. For CSR components, this typically points to a `.tsx` or `.jsx` file. For Client
58
- * components, this points to a Zig component file.
59
- *
60
- * The path is determined from the `@jsImport` directive in the ZX file, or defaults to
61
- * `./{componentName}.tsx` if not explicitly specified.
62
- *
63
- * @example
64
- * ```tsx
65
- * // In ZX file:
66
- * const CounterComponent = @jsImport("components/Counter.tsx");
67
- * <CounterComponent @rendering={.react} />
68
- *
69
- * // path will be: "components/Counter.tsx"
70
- * ```
71
- *
72
- * @example
73
- * ```tsx
74
- * // Without explicit @jsImport:
75
- * <MyComponent @rendering={.react} />
76
- *
77
- * // path will default to: "./MyComponent.tsx"
78
- * ```
79
- */
80
- path: string;
81
- /**
82
- * The route of of the component in which page the component was used,
83
- * null in case the component was used in other non-page/layout context.
84
- * ```
85
- */
86
- route: string | null;
87
- /**
88
- * A unique identifier for the component's hydration boundary.
89
- *
90
- * This ID is generated by hashing the component's path and name using MD5, then formatting it
91
- * as a hex string with the "zx-" prefix and a counter suffix. The ID is used to locate the
92
- * component's comment markers in the DOM during client-side hydration.
93
- *
94
- * The ID format is: `zx-{32 hex characters}-{counter}` (e.g., `zx-dcde04c415da9d1b15ca2690d8b497ae-0`)
95
- *
96
- * The ZX runtime renders components with comment markers in the format:
97
- * `<!--$id name props-->...<!--/$id-->`
98
- *
99
- * @example
100
- * ```tsx
101
- * // Component metadata:
102
- * {
103
- * name: "CounterComponent",
104
- * path: "./components/Counter.tsx",
105
- * id: "zx-dcde04c415da9d1b15ca2690d8b497ae-0"
106
- * }
107
- *
108
- * // Generated HTML with comment markers:
109
- * <!--$zx-dcde04c415da9d1b15ca2690d8b497ae-0 CounterComponent {"max_count":10}-->
110
- * <button>0</button>
111
- * <!--/$zx-dcde04c415da9d1b15ca2690d8b497ae-0-->
112
- * ```
113
- */
114
- id: string;
115
- /**
116
- * The rendering type of the component, determining how it will be rendered on the client.
117
- *
118
- * - **"react"** (Client Side React): The component is a React component that will be rendered
119
- * using React's client-side rendering. The component file should export a default React
120
- * component function. This is the most common type for interactive UI components.
121
- *
122
- * - **"client"** (Client Side Zig): The component is a Zig component that will be compiled to
123
- * WebAssembly and rendered on the client side. This allows you to use Zig's performance
124
- * and type safety for client-side components.
125
- *
126
- * The type is determined by the `@rendering` attribute value in the ZX file (`.react` or `.client`).
127
- *
128
- * @example
129
- * ```tsx
130
- * // CSR component (React):
131
- * <CounterComponent @rendering={.react} max_count={10} />
132
- * // type: "react"
133
- *
134
- * // Component file (CounterComponent.tsx):
135
- * export default function CounterComponent({ max_count }: { max_count: number }) {
136
- * return <div>Count: {max_count}</div>;
137
- * }
138
- * ```
139
- *
140
- * @example
141
- * ```tsx
142
- * // Client component (Zig/WASM):
143
- * <CounterComponent @rendering={.client} />
144
- * // type: "client"
145
- *
146
- * // Component file (CounterComponent.zig):
147
- * pub fn CounterComponent(allocator: zx.Allocator) zx.Component {
148
- * return (<div @allocator={allocator}>Counter</div>);
149
- * }
150
- * ```
151
- */
152
- type: "react" | "client";
153
- /**
154
- * A lazy-loading function that dynamically imports the component module.
155
- *
156
- * This function returns a Promise that resolves to the component function. It enables
157
- * code-splitting and lazy loading of components, improving initial page load performance
158
- * by only loading components when they are needed.
159
- *
160
- * For CSR components, the imported module should export a default React component.
161
- * For Client components, the import mechanism depends on the WASM module structure.
162
- *
163
- * The function is called during client-side hydration to load and render the component
164
- * into its corresponding DOM container element.
165
- *
166
- * @returns A Promise that resolves to a component function that accepts props and returns a React element.
167
- *
168
- * @example
169
- * ```tsx
170
- * // Component metadata:
171
- * {
172
- * import: () => import('./components/CounterComponent.tsx')
173
- * }
174
- *
175
- * // Usage:
176
- * const Component = await component.import();
177
- * // Component is now the default export from CounterComponent.tsx
178
- * ```
179
- *
180
- * @example
181
- * ```tsx
182
- * // With prepareComponent helper:
183
- * import { prepareComponent } from "ziex";
184
- *
185
- * const { Component, props, domNode } = await prepareComponent(component);
186
- * // Component is loaded and ready to render with props
187
- * ```
188
- */
189
- import: () => Promise<(props: any) => React.ReactElement>;
190
- };
package/runtime.d.ts DELETED
@@ -1,70 +0,0 @@
1
- import type { WASI } from "./wasi";
2
- import type { KVNamespace } from "./kv";
3
- /** Minimal Durable Object namespace shape needed for WebSocket routing. */
4
- export type DurableObjectNamespace = {
5
- idFromName(name: string): unknown;
6
- get(id: unknown): {
7
- fetch(req: Request): Promise<Response>;
8
- };
9
- };
10
- export type WsState = {
11
- upgraded: boolean;
12
- server: WebSocket | null;
13
- pendingWrites: Uint8Array[];
14
- messageQueue: Uint8Array[];
15
- recvResolve: ((bytes: Uint8Array | null) => void) | null;
16
- /** Resolved when ws_recv is called for the first time (WASM has entered the message loop). */
17
- _resolveFirstSuspend?: () => void;
18
- subscribe?: (topic: string) => void;
19
- unsubscribe?: (topic: string) => void;
20
- publish?: (topic: string, data: Uint8Array) => number;
21
- isSubscribed?: (topic: string) => boolean;
22
- };
23
- /** Build the __zx_ws import object for a given connection state. */
24
- export declare function buildWsImports(Suspending: any, mem: () => WebAssembly.Memory, decoder: TextDecoder, ws: WsState): {
25
- ws_upgrade: () => void;
26
- ws_write: (ptr: number, len: number) => void;
27
- ws_close: (code: number, reason_ptr: number, reason_len: number) => void;
28
- ws_recv: any;
29
- ws_subscribe: (ptr: number, len: number) => void;
30
- ws_unsubscribe: (ptr: number, len: number) => void;
31
- ws_publish: (topic_ptr: number, topic_len: number, data_ptr: number, data_len: number) => number;
32
- ws_is_subscribed: (ptr: number, len: number) => number;
33
- };
34
- /** Create WebSocketPair, wire message/close listeners, flush pending writes. */
35
- export declare function attachWebSocket(ws: WsState): {
36
- client: WebSocket;
37
- };
38
- /**
39
- * Run a WASM module for a single request using JSPI.
40
- *
41
- * Pass `kv` as a map of binding names → KV namespaces. The Zig side selects
42
- * a binding via `zx.kv.scope("name")`; the top-level `zx.kv.*` functions use
43
- * `"default"`.
44
- *
45
- * @example
46
- * ```ts
47
- * return run({
48
- * request, env, ctx, module,
49
- * kv: { default: env.KV, users: env.USERS_KV },
50
- * });
51
- * ```
52
- */
53
- export declare function run({ request, env, ctx, module, kv: kvBindings, imports, wasi, websocket: doNamespace, }: {
54
- request: Request;
55
- env?: unknown;
56
- ctx?: {
57
- waitUntil(promise: Promise<unknown>): void;
58
- };
59
- module: WebAssembly.Module;
60
- /** KV namespace bindings — `{ default: env.KV, otherName: env.OTHER_KV }` */
61
- kv?: Record<string, KVNamespace>;
62
- imports?: (mem: () => WebAssembly.Memory) => Record<string, Record<string, unknown>>;
63
- wasi?: WASI;
64
- /**
65
- * Durable Object namespace to use for WebSocket connections.
66
- * When provided, WebSocket upgrade requests are automatically forwarded to
67
- * the DO so that pub/sub works across multiple connected clients.
68
- */
69
- websocket?: DurableObjectNamespace;
70
- }): Promise<Response>;
package/vercel/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Ziex adapter for Vercel Edge Functions.
3
- *
4
- * @example
5
- * ```ts
6
- * import { Ziex } from "ziex/cloudflare";
7
- * import { handle } from "ziex/vercel";
8
- * import module from "./app.wasm"; // or fetch at runtime
9
- *
10
- * const app = new Ziex({ module });
11
- *
12
- * export const config = { runtime: "edge" };
13
- * export default handle(app);
14
- * ```
15
- */
16
- type FetchApp = {
17
- fetch(req: Request, env?: unknown, ctx?: unknown): Promise<Response>;
18
- };
19
- /**
20
- * Wrap a Ziex app as a Vercel Edge Function handler.
21
- *
22
- * Returns a standard `(req: Request) => Promise<Response>` function.
23
- * Vercel's edge runtime calls it directly — just export it as default.
24
- */
25
- export declare function handle(app: FetchApp): (req: Request) => Promise<Response>;
26
- export {};
package/wasi.d.ts DELETED
@@ -1,61 +0,0 @@
1
- export declare class ProcExit extends Error {
2
- readonly code: number;
3
- constructor(code: number);
4
- }
5
- export type WASI = {
6
- wasiImport: Record<string, (...args: any[]) => unknown>;
7
- start(instance: {
8
- exports: {
9
- memory: WebAssembly.Memory;
10
- _start: () => unknown;
11
- };
12
- }): number;
13
- initialize?(instance: {
14
- exports: {
15
- memory: WebAssembly.Memory;
16
- _initialize?: () => unknown;
17
- };
18
- }): void;
19
- };
20
- export declare function createWasiImports({ request, stdinData, onStdout, }: {
21
- request: Request;
22
- stdinData?: Uint8Array;
23
- /** Called for each stdout chunk. When provided, chunks are NOT buffered internally. */
24
- onStdout?: (chunk: Uint8Array) => void;
25
- }): {
26
- wasiImport: {
27
- args_sizes_get(argc_ptr: number, argv_buf_size_ptr: number): number;
28
- args_get(argv_ptr: number, argv_buf_ptr: number): number;
29
- environ_sizes_get(count_ptr: number, buf_size_ptr: number): number;
30
- environ_get(_environ_ptr: number, _environ_buf_ptr: number): number;
31
- fd_write(fd: number, iovs_ptr: number, iovs_len: number, nwritten_ptr: number): number;
32
- fd_read(fd: number, iovs_ptr: number, iovs_len: number, nread_ptr: number): number;
33
- fd_fdstat_get(_fd: number, fdstat_ptr: number): number;
34
- fd_prestat_get(_fd: number, _bufptr: number): number;
35
- fd_prestat_dir_name(_fd: number, _path: number, _path_len: number): number;
36
- fd_close(_fd: number): number;
37
- fd_pread(_fd: number, _iovs: number, _iovs_len: number, _offset: bigint, nread_ptr: number): number;
38
- fd_pwrite(_fd: number, _iovs: number, _iovs_len: number, _offset: bigint, nwritten_ptr: number): number;
39
- fd_filestat_get(_fd: number, filestat_ptr: number): number;
40
- fd_seek(_fd: number, _offset: bigint, _whence: number, newoffset_ptr: number): number;
41
- proc_exit(code: number): never;
42
- sched_yield(): number;
43
- clock_time_get(_id: number, _precision: bigint, time_ptr: number): number;
44
- random_get(buf_ptr: number, buf_len: number): number;
45
- path_open(_fd: number, _dirflags: number, _path: number, _path_len: number, _oflags: number, _rights_base: bigint, _rights_inheriting: bigint, _fdflags: number, opened_fd_ptr: number): number;
46
- path_create_directory(_fd: number, _path: number, _path_len: number): number;
47
- path_unlink_file(_fd: number, _path: number, _path_len: number): number;
48
- path_remove_directory(_fd: number, _path: number, _path_len: number): number;
49
- path_rename(_fd: number, _old_path: number, _old_path_len: number, _new_fd: number, _new_path: number, _new_path_len: number): number;
50
- path_filestat_get(_fd: number, _flags: number, _path: number, _path_len: number, filestat_ptr: number): number;
51
- path_readlink(_fd: number, _path: number, _path_len: number, _buf: number, _buf_len: number, nread_ptr: number): number;
52
- fd_readdir(_fd: number, _buf: number, _buf_len: number, _cookie: bigint, bufused_ptr: number): number;
53
- poll_oneoff(_in: number, _out: number, _nsubscriptions: number, nevents_ptr: number): number;
54
- };
55
- setMemory: (m: WebAssembly.Memory) => void;
56
- collectOutput: () => {
57
- stdout: Uint8Array;
58
- stderrText: string;
59
- };
60
- };
61
- export declare function mergeUint8Arrays(arrays: Uint8Array[]): Uint8Array;
package/wasm/core.d.ts DELETED
@@ -1,78 +0,0 @@
1
- import { ZigJS } from "../../../../vendor/jsz/js/src";
2
- /**
3
- * Core WASM bridge — environment-agnostic (browser + edge).
4
- * Contains no references to browser globals (document, window, WebSocket, HTMLFormElement).
5
- */
6
- export declare const CallbackType: {
7
- readonly Event: 0;
8
- readonly FetchSuccess: 1;
9
- readonly FetchError: 2;
10
- readonly Timeout: 3;
11
- readonly Interval: 4;
12
- readonly WebSocketOpen: 5;
13
- readonly WebSocketMessage: 6;
14
- readonly WebSocketError: 7;
15
- readonly WebSocketClose: 8;
16
- };
17
- export type CallbackTypeValue = typeof CallbackType[keyof typeof CallbackType];
18
- export type CallbackHandler = (callbackType: number, id: bigint, dataRef: bigint) => void;
19
- export type FetchCompleteHandler = (fetchId: bigint, statusCode: number, bodyPtr: number, bodyLen: number, isError: number) => void;
20
- export type WsOnOpenHandler = (wsId: bigint, protocolPtr: number, protocolLen: number) => void;
21
- export type WsOnMessageHandler = (wsId: bigint, dataPtr: number, dataLen: number, isBinary: number) => void;
22
- export type WsOnErrorHandler = (wsId: bigint, msgPtr: number, msgLen: number) => void;
23
- export type WsOnCloseHandler = (wsId: bigint, code: number, reasonPtr: number, reasonLen: number, wasClean: number) => void;
24
- export declare const jsz: ZigJS;
25
- /** Store a value using jsz.storeValue and get the 64-bit reference. */
26
- export declare function storeValueGetRef(val: any): bigint;
27
- /** Shared encoder/decoder — avoids allocating new instances on every call. */
28
- export declare const textDecoder: TextDecoder;
29
- export declare const textEncoder: TextEncoder;
30
- export declare function getMemoryView(): Uint8Array;
31
- /** Read a string from WASM memory */
32
- export declare function readString(ptr: number, len: number): string;
33
- /** Write bytes to WASM memory at a specific location */
34
- export declare function writeBytes(ptr: number, data: Uint8Array): void;
35
- /**
36
- * Core ZX Bridge — works in both browser and edge runtimes.
37
- * Contains fetch, timers, and logging. No DOM or browser-WebSocket references.
38
- *
39
- * Extend this class in browser environments to add DOM and WebSocket support.
40
- */
41
- export declare class ZxBridgeCore {
42
- #private;
43
- protected readonly _alloc: (size: number) => number;
44
- constructor(exports: WebAssembly.Exports);
45
- /**
46
- * Async fetch with full options support.
47
- * Calls __zx_fetch_complete when done.
48
- */
49
- fetchAsync(urlPtr: number, urlLen: number, methodPtr: number, methodLen: number, headersPtr: number, headersLen: number, bodyPtr: number, bodyLen: number, timeoutMs: number, fetchId: bigint): void;
50
- /** Notify WASM that a fetch completed */
51
- protected _notifyFetchComplete(fetchId: bigint, statusCode: number, body: string, isError: boolean): void;
52
- /** Set a timeout and callback when it fires */
53
- setTimeout(callbackId: bigint, delayMs: number): void;
54
- /** Set an interval and callback each time it fires */
55
- setInterval(callbackId: bigint, intervalMs: number): void;
56
- /** Clear an interval */
57
- clearInterval(callbackId: bigint): void;
58
- /** Write a string to WASM memory, returning pointer and length */
59
- protected _writeStringToWasm(str: string): {
60
- ptr: number;
61
- len: number;
62
- };
63
- protected _writeBytesToWasm(data: Uint8Array): {
64
- ptr: number;
65
- len: number;
66
- };
67
- /** Log a message from WASM at the given level (0=error, 1=warn, 2=info, 3=debug) */
68
- static log(level: number, ptr: number, len: number): void;
69
- /**
70
- * Create the core import object for WASM instantiation.
71
- * Includes only environment-agnostic bindings: log, fetch, and timers.
72
- * Use ZxBridge.createImportObject (from wasm/index.ts) in browser contexts
73
- * to additionally include DOM and WebSocket bindings.
74
- */
75
- static createImportObject(bridgeRef: {
76
- current: ZxBridgeCore | null;
77
- }): WebAssembly.Imports;
78
- }
package/wasm/dom.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { ComponentMetadata } from "./types";
2
- export type PreparedComponent = {};
3
- export declare function prepareComponent(component: ComponentMetadata): Promise<PreparedComponent>;
4
- export declare function filterComponents(components: ComponentMetadata[]): ComponentMetadata[];
package/wasm/index.d.ts DELETED
@@ -1,46 +0,0 @@
1
- export { CallbackType, jsz, storeValueGetRef, textDecoder, textEncoder, getMemoryView, readString, writeBytes, ZxBridgeCore, } from "./core";
2
- export type { CallbackTypeValue } from "./core";
3
- import { ZxBridgeCore } from "./core";
4
- /**
5
- * Browser ZX Bridge — extends ZxBridgeCore with DOM, WebSocket, and form-action support.
6
- * Import this from environments that have access to browser globals.
7
- * For edge runtimes, import ZxBridgeCore from ./core instead.
8
- */
9
- export declare class ZxBridge extends ZxBridgeCore {
10
- #private;
11
- constructor(exports: WebAssembly.Exports);
12
- /** Submit a form action with bound-state round-trip. */
13
- submitFormActionAsync(form: HTMLFormElement, statesJson: string, fetchId: bigint): void;
14
- /**
15
- * Create and connect a WebSocket.
16
- * Calls __zx_ws_onopen, __zx_ws_onmessage, __zx_ws_onerror, __zx_ws_onclose.
17
- */
18
- wsConnect(wsId: bigint, urlPtr: number, urlLen: number, protocolsPtr: number, protocolsLen: number): void;
19
- /** Send data over WebSocket */
20
- wsSend(wsId: bigint, dataPtr: number, dataLen: number, isBinary: number): void;
21
- /** Close WebSocket connection */
22
- wsClose(wsId: bigint, code: number, reasonPtr: number, reasonLen: number): void;
23
- /** Handle a DOM event (called by event delegation) */
24
- eventbridge(velementId: bigint, eventTypeId: number, event: Event): void;
25
- /** Create the full browser import object for WASM instantiation (includes DOM + WebSocket). */
26
- static createImportObject(bridgeRef: {
27
- current: ZxBridge | null;
28
- }): WebAssembly.Imports;
29
- }
30
- /** Initialize event delegation */
31
- export declare function initEventDelegation(bridge: ZxBridge, rootSelector?: string): void;
32
- export type InitOptions = {
33
- url?: string;
34
- eventDelegationRoot?: string;
35
- importObject?: WebAssembly.Imports;
36
- };
37
- /** Initialize WASM with the ZX Bridge */
38
- export declare function init(options?: InitOptions): Promise<{
39
- source: WebAssembly.WebAssemblyInstantiatedSource;
40
- bridge: ZxBridge;
41
- }>;
42
- declare global {
43
- interface HTMLElement {
44
- __zx_ref?: number;
45
- }
46
- }
package/wasm/init.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/wasm/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export type ComponentMetadata = {};
package/wasm/wasi.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * WASI/edge WASM bridge — zero dependencies on ZigJS (jsz) or browser globals.
3
- *
4
- * Import this (and only this) from edge/server runtimes. It provides the
5
- * minimal __zx import namespace needed by server-side WASM: log, fetch, and
6
- * timers. The jsz importObject is intentionally omitted — the server binary
7
- * does not use jsz value-passing.
8
- */
9
- export declare class ZxWasiBridge {
10
- #private;
11
- constructor(exports: WebAssembly.Exports);
12
- log(level: number, ptr: number, len: number): void;
13
- fetchAsync(urlPtr: number, urlLen: number, methodPtr: number, methodLen: number, headersPtr: number, headersLen: number, bodyPtr: number, bodyLen: number, timeoutMs: number, fetchId: bigint): void;
14
- setTimeout(callbackId: bigint, delayMs: number): void;
15
- setInterval(callbackId: bigint, intervalMs: number): void;
16
- clearInterval(callbackId: bigint): void;
17
- /**
18
- * Create the WASI import object for WASM instantiation.
19
- *
20
- * Returns only the `__zx` namespace (log, fetch, timers).
21
- * Does NOT include jsz.importObject() — the server binary does not use jsz.
22
- */
23
- static createImportObject(bridgeRef: {
24
- current: ZxWasiBridge | null;
25
- }): {
26
- __zx: Record<string, unknown>;
27
- };
28
- }
package/zx.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function getZxInfo(): any;