@ziex/cli 0.1.0-dev.865 → 0.1.0-test.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/package.json +10 -29
- package/README.md +0 -195
- package/app.d.ts +0 -112
- package/aws-lambda/index.d.ts +0 -96
- package/aws-lambda/index.js +0 -126
- package/build.zig +0 -5
- package/build.zig.zon +0 -7
- package/cloudflare/app.d.ts +0 -2
- package/cloudflare/do.d.ts +0 -48
- package/cloudflare/index.d.ts +0 -4
- package/cloudflare/index.js +0 -1707
- package/cloudflare/kv.d.ts +0 -2
- package/cloudflare/worker.d.ts +0 -3
- package/index.d.ts +0 -2
- package/index.js +0 -739
- package/kv.d.ts +0 -27
- package/react/dom.d.ts +0 -21
- package/react/index.d.ts +0 -2
- package/react/index.js +0 -144
- package/react/types.d.ts +0 -190
- package/runtime.d.ts +0 -70
- package/vercel/index.d.ts +0 -26
- package/vercel/index.js +0 -18
- package/wasi.d.ts +0 -61
- package/wasm/core.d.ts +0 -78
- package/wasm/dom.d.ts +0 -4
- package/wasm/index.d.ts +0 -46
- package/wasm/index.js +0 -895
- package/wasm/init.d.ts +0 -1
- package/wasm/init.js +0 -873
- package/wasm/types.d.ts +0 -1
- package/wasm/wasi.d.ts +0 -28
- package/zx.d.ts +0 -1
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
package/react/index.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, {
|
|
5
|
-
get: all[name],
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
set: (newValue) => all[name] = () => newValue
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/react/dom.ts
|
|
13
|
-
function findCommentMarker(id) {
|
|
14
|
-
const startPrefix = `$${id} `;
|
|
15
|
-
const endMarker = `/$${id}`;
|
|
16
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_COMMENT, null);
|
|
17
|
-
let startComment = null;
|
|
18
|
-
let endComment = null;
|
|
19
|
-
let name = "";
|
|
20
|
-
let props = {};
|
|
21
|
-
let node;
|
|
22
|
-
while (node = walker.nextNode()) {
|
|
23
|
-
const text = node.textContent?.trim() || "";
|
|
24
|
-
if (text.startsWith(startPrefix)) {
|
|
25
|
-
startComment = node;
|
|
26
|
-
const content = text.slice(startPrefix.length);
|
|
27
|
-
const jsonStart = content.indexOf("{");
|
|
28
|
-
if (jsonStart !== -1) {
|
|
29
|
-
name = content.slice(0, jsonStart).trim();
|
|
30
|
-
const jsonStr = content.slice(jsonStart);
|
|
31
|
-
try {
|
|
32
|
-
props = JSON.parse(jsonStr);
|
|
33
|
-
} catch {}
|
|
34
|
-
} else {
|
|
35
|
-
name = content.trim();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (text === endMarker) {
|
|
39
|
-
endComment = node;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (startComment && endComment) {
|
|
44
|
-
return { startComment, endComment, name, props };
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function createContainerBetweenMarkers(startComment, endComment) {
|
|
49
|
-
const container = document.createElement("div");
|
|
50
|
-
container.style.display = "contents";
|
|
51
|
-
let current = startComment.nextSibling;
|
|
52
|
-
while (current && current !== endComment) {
|
|
53
|
-
const next = current.nextSibling;
|
|
54
|
-
container.appendChild(current);
|
|
55
|
-
current = next;
|
|
56
|
-
}
|
|
57
|
-
endComment.parentNode?.insertBefore(container, endComment);
|
|
58
|
-
return container;
|
|
59
|
-
}
|
|
60
|
-
async function prepareComponent(component) {
|
|
61
|
-
const marker = findCommentMarker(component.id);
|
|
62
|
-
if (!marker) {
|
|
63
|
-
throw new Error(`Comment marker for ${component.id} not found`, { cause: component });
|
|
64
|
-
}
|
|
65
|
-
const props = marker.props;
|
|
66
|
-
const domNode = createContainerBetweenMarkers(marker.startComment, marker.endComment);
|
|
67
|
-
const Component = await component.import();
|
|
68
|
-
return { domNode, props, Component };
|
|
69
|
-
}
|
|
70
|
-
function filterComponents(components) {
|
|
71
|
-
const currentPath = window.location.pathname;
|
|
72
|
-
return components.filter((component) => component.route === currentPath || !component.route);
|
|
73
|
-
}
|
|
74
|
-
function discoverComponents() {
|
|
75
|
-
const components = [];
|
|
76
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_COMMENT, null);
|
|
77
|
-
const markers = [];
|
|
78
|
-
let node;
|
|
79
|
-
while (node = walker.nextNode()) {
|
|
80
|
-
const text = node.textContent?.trim() || "";
|
|
81
|
-
if (text.startsWith("$") && !text.startsWith("/$")) {
|
|
82
|
-
const spaceIdx = text.indexOf(" ");
|
|
83
|
-
if (spaceIdx !== -1) {
|
|
84
|
-
const id = text.slice(1, spaceIdx);
|
|
85
|
-
const content = text.slice(spaceIdx + 1);
|
|
86
|
-
if (content.startsWith("[")) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
const jsonStart = content.indexOf("{");
|
|
90
|
-
let name = "";
|
|
91
|
-
let props = {};
|
|
92
|
-
if (jsonStart !== -1) {
|
|
93
|
-
name = content.slice(0, jsonStart).trim();
|
|
94
|
-
try {
|
|
95
|
-
props = JSON.parse(content.slice(jsonStart));
|
|
96
|
-
} catch {}
|
|
97
|
-
} else {
|
|
98
|
-
name = content.trim();
|
|
99
|
-
}
|
|
100
|
-
markers.push({ id, name, props, startComment: node, endComment: null });
|
|
101
|
-
}
|
|
102
|
-
} else if (text.startsWith("/$")) {
|
|
103
|
-
const id = text.slice(2);
|
|
104
|
-
const marker = markers.find((m) => m.id === id && !m.endComment);
|
|
105
|
-
if (marker) {
|
|
106
|
-
marker.endComment = node;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (const marker of markers) {
|
|
111
|
-
if (!marker.endComment)
|
|
112
|
-
continue;
|
|
113
|
-
const container = createContainerBetweenMarkers(marker.startComment, marker.endComment);
|
|
114
|
-
components.push({
|
|
115
|
-
id: marker.id,
|
|
116
|
-
name: marker.name,
|
|
117
|
-
props: marker.props,
|
|
118
|
-
container
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return components;
|
|
122
|
-
}
|
|
123
|
-
async function hydrateAll(registry, render) {
|
|
124
|
-
const components = discoverComponents();
|
|
125
|
-
await Promise.all(components.map(async ({ name, props, container }) => {
|
|
126
|
-
const importer = registry[name];
|
|
127
|
-
if (!importer) {
|
|
128
|
-
console.warn(`Component "${name}" not found in registry`);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
const Component = await importer();
|
|
133
|
-
render(container, Component, props);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.error(`Failed to hydrate "${name}":`, error);
|
|
136
|
-
}
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
prepareComponent,
|
|
141
|
-
hydrateAll,
|
|
142
|
-
filterComponents,
|
|
143
|
-
discoverComponents
|
|
144
|
-
};
|
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/vercel/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, {
|
|
5
|
-
get: all[name],
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
set: (newValue) => all[name] = () => newValue
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/vercel/index.ts
|
|
13
|
-
function handle(app) {
|
|
14
|
-
return (req) => app.fetch(req);
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
handle
|
|
18
|
-
};
|
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[];
|