ziex 0.1.0-dev.786 → 0.1.0-dev.787
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/aws-lambda/index.d.ts +96 -0
- package/aws-lambda/index.js +126 -0
- package/cloudflare/app.d.ts +95 -0
- package/cloudflare/index.d.ts +2 -0
- package/cloudflare/index.js +1160 -58
- package/cloudflare/kv.d.ts +8 -0
- package/cloudflare/worker.d.ts +111 -2
- package/hono/index.d.ts +92 -0
- package/hono/index.js +1515 -0
- package/index.d.ts +1 -9
- package/index.js +1496 -46
- package/package.json +16 -2
- package/vercel/index.d.ts +26 -0
- package/vercel/index.js +18 -0
- package/wasm/index.d.ts +4 -0
- package/wasm/index.js +50 -0
- package/wasm/init.js +50 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziex",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.787",
|
|
4
4
|
"description": "ZX is a framework for building web applications with Zig.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"./react": "./react/index.js",
|
|
10
10
|
"./wasm": "./wasm/index.js",
|
|
11
11
|
"./wasm/init": "./wasm/init.js",
|
|
12
|
-
"./cloudflare": "./cloudflare/index.js"
|
|
12
|
+
"./cloudflare": "./cloudflare/index.js",
|
|
13
|
+
"./hono": "./hono/index.js",
|
|
14
|
+
"./aws-lambda": "./aws-lambda/index.js",
|
|
15
|
+
"./vercel": "./vercel/index.js"
|
|
13
16
|
},
|
|
14
17
|
"homepage": "https://ziex.dev",
|
|
15
18
|
"repository": {
|
|
@@ -30,6 +33,17 @@
|
|
|
30
33
|
],
|
|
31
34
|
"author": "Nurul Huda (Apon) <me@nurulhudaapon.com>",
|
|
32
35
|
"license": "MIT",
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"react": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"react-dom": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"hono": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
33
47
|
"module": "index.js",
|
|
34
48
|
"types": "index.d.ts"
|
|
35
49
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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/wasm/index.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export declare class ZxBridge {
|
|
|
27
27
|
* Calls __zx_fetch_complete when done.
|
|
28
28
|
*/
|
|
29
29
|
fetchAsync(urlPtr: number, urlLen: number, methodPtr: number, methodLen: number, headersPtr: number, headersLen: number, bodyPtr: number, bodyLen: number, timeoutMs: number, fetchId: bigint): void;
|
|
30
|
+
/** Submit a form action with bound-state round-trip.
|
|
31
|
+
* Sends the form as multipart/form-data + __zx_states field,
|
|
32
|
+
* then calls __zx_fetch_complete so WASM can apply state updates. */
|
|
33
|
+
submitFormActionAsync(form: HTMLFormElement, statesJson: string, fetchId: bigint): void;
|
|
30
34
|
/** Set a timeout and callback when it fires */
|
|
31
35
|
setTimeout(callbackId: bigint, delayMs: number): void;
|
|
32
36
|
/** Set an interval and callback each time it fires */
|
package/wasm/index.js
CHANGED
|
@@ -303,6 +303,21 @@ class ZxBridge {
|
|
|
303
303
|
writeBytes(ptr, encoded);
|
|
304
304
|
handler(fetchId, statusCode, ptr, encoded.length, isError ? 1 : 0);
|
|
305
305
|
}
|
|
306
|
+
submitFormActionAsync(form, statesJson, fetchId) {
|
|
307
|
+
const formData = new FormData(form);
|
|
308
|
+
formData.append("__zx_states", statesJson);
|
|
309
|
+
fetch(window.location.href, {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: { "X-ZX-Action": "1" },
|
|
312
|
+
body: formData
|
|
313
|
+
}).then(async (response) => {
|
|
314
|
+
const text = await response.text();
|
|
315
|
+
this.#notifyFetchComplete(fetchId, response.status, text, false);
|
|
316
|
+
}).catch((error) => {
|
|
317
|
+
const msg = error instanceof Error ? error.message : "Fetch failed";
|
|
318
|
+
this.#notifyFetchComplete(fetchId, 0, msg, true);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
306
321
|
setTimeout(callbackId, delayMs) {
|
|
307
322
|
setTimeout(() => {
|
|
308
323
|
this.#invoke(CallbackType.Timeout, callbackId, null);
|
|
@@ -498,6 +513,41 @@ class ZxBridge {
|
|
|
498
513
|
parent.replaceChild(newChild, oldChild);
|
|
499
514
|
cleanupDomNodes(oldChild);
|
|
500
515
|
}
|
|
516
|
+
},
|
|
517
|
+
_getLocationHref: (bufPtr, bufLen) => {
|
|
518
|
+
const bytes = textEncoder.encode(window.location.href);
|
|
519
|
+
const len = Math.min(bytes.length, bufLen);
|
|
520
|
+
writeBytes(bufPtr, bytes.subarray(0, len));
|
|
521
|
+
return len;
|
|
522
|
+
},
|
|
523
|
+
_getFormData: (vnodeId, bufPtr, bufLen) => {
|
|
524
|
+
const form = domNodes.get(vnodeId);
|
|
525
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
526
|
+
return 0;
|
|
527
|
+
const formData = new FormData(form);
|
|
528
|
+
const urlEncoded = new URLSearchParams(formData).toString();
|
|
529
|
+
const bytes = textEncoder.encode(urlEncoded);
|
|
530
|
+
const len = Math.min(bytes.length, bufLen);
|
|
531
|
+
writeBytes(bufPtr, bytes.subarray(0, len));
|
|
532
|
+
return len;
|
|
533
|
+
},
|
|
534
|
+
_submitFormAction: (vnodeId) => {
|
|
535
|
+
const form = domNodes.get(vnodeId);
|
|
536
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
537
|
+
return;
|
|
538
|
+
const formData = new FormData(form);
|
|
539
|
+
fetch(window.location.href, {
|
|
540
|
+
method: "POST",
|
|
541
|
+
headers: { "X-ZX-Action": "1" },
|
|
542
|
+
body: formData
|
|
543
|
+
}).catch(() => {});
|
|
544
|
+
},
|
|
545
|
+
_submitFormActionAsync: (vnodeId, statesPtr, statesLen, fetchId) => {
|
|
546
|
+
const form = domNodes.get(vnodeId);
|
|
547
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
548
|
+
return;
|
|
549
|
+
const statesJson = statesLen > 0 ? readString(statesPtr, statesLen) : "[]";
|
|
550
|
+
bridgeRef.current?.submitFormActionAsync(form, statesJson, fetchId);
|
|
501
551
|
}
|
|
502
552
|
}
|
|
503
553
|
};
|
package/wasm/init.js
CHANGED
|
@@ -292,6 +292,21 @@ class ZxBridge {
|
|
|
292
292
|
writeBytes(ptr, encoded);
|
|
293
293
|
handler(fetchId, statusCode, ptr, encoded.length, isError ? 1 : 0);
|
|
294
294
|
}
|
|
295
|
+
submitFormActionAsync(form, statesJson, fetchId) {
|
|
296
|
+
const formData = new FormData(form);
|
|
297
|
+
formData.append("__zx_states", statesJson);
|
|
298
|
+
fetch(window.location.href, {
|
|
299
|
+
method: "POST",
|
|
300
|
+
headers: { "X-ZX-Action": "1" },
|
|
301
|
+
body: formData
|
|
302
|
+
}).then(async (response) => {
|
|
303
|
+
const text = await response.text();
|
|
304
|
+
this.#notifyFetchComplete(fetchId, response.status, text, false);
|
|
305
|
+
}).catch((error) => {
|
|
306
|
+
const msg = error instanceof Error ? error.message : "Fetch failed";
|
|
307
|
+
this.#notifyFetchComplete(fetchId, 0, msg, true);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
295
310
|
setTimeout(callbackId, delayMs) {
|
|
296
311
|
setTimeout(() => {
|
|
297
312
|
this.#invoke(CallbackType.Timeout, callbackId, null);
|
|
@@ -487,6 +502,41 @@ class ZxBridge {
|
|
|
487
502
|
parent.replaceChild(newChild, oldChild);
|
|
488
503
|
cleanupDomNodes(oldChild);
|
|
489
504
|
}
|
|
505
|
+
},
|
|
506
|
+
_getLocationHref: (bufPtr, bufLen) => {
|
|
507
|
+
const bytes = textEncoder.encode(window.location.href);
|
|
508
|
+
const len = Math.min(bytes.length, bufLen);
|
|
509
|
+
writeBytes(bufPtr, bytes.subarray(0, len));
|
|
510
|
+
return len;
|
|
511
|
+
},
|
|
512
|
+
_getFormData: (vnodeId, bufPtr, bufLen) => {
|
|
513
|
+
const form = domNodes.get(vnodeId);
|
|
514
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
515
|
+
return 0;
|
|
516
|
+
const formData = new FormData(form);
|
|
517
|
+
const urlEncoded = new URLSearchParams(formData).toString();
|
|
518
|
+
const bytes = textEncoder.encode(urlEncoded);
|
|
519
|
+
const len = Math.min(bytes.length, bufLen);
|
|
520
|
+
writeBytes(bufPtr, bytes.subarray(0, len));
|
|
521
|
+
return len;
|
|
522
|
+
},
|
|
523
|
+
_submitFormAction: (vnodeId) => {
|
|
524
|
+
const form = domNodes.get(vnodeId);
|
|
525
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
526
|
+
return;
|
|
527
|
+
const formData = new FormData(form);
|
|
528
|
+
fetch(window.location.href, {
|
|
529
|
+
method: "POST",
|
|
530
|
+
headers: { "X-ZX-Action": "1" },
|
|
531
|
+
body: formData
|
|
532
|
+
}).catch(() => {});
|
|
533
|
+
},
|
|
534
|
+
_submitFormActionAsync: (vnodeId, statesPtr, statesLen, fetchId) => {
|
|
535
|
+
const form = domNodes.get(vnodeId);
|
|
536
|
+
if (!form || !(form instanceof HTMLFormElement))
|
|
537
|
+
return;
|
|
538
|
+
const statesJson = statesLen > 0 ? readString(statesPtr, statesLen) : "[]";
|
|
539
|
+
bridgeRef.current?.submitFormActionAsync(form, statesJson, fetchId);
|
|
490
540
|
}
|
|
491
541
|
}
|
|
492
542
|
};
|