ziex 0.1.0-dev.1360 → 0.1.0-dev.1377

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.
Files changed (39) hide show
  1. package/aws-lambda/index.js +20 -29
  2. package/build.zig +118 -2
  3. package/build.zig.zon +13 -2
  4. package/cloudflare/index.js +1768 -1954
  5. package/index.js +190 -218
  6. package/{pkg/ziex/src/react → jsx}/dom.d.ts +5 -9
  7. package/{pkg/ziex/src/react → jsx}/index.d.ts +1 -1
  8. package/{react → jsx}/index.js +19 -25
  9. package/{pkg/ziex/src/react → jsx}/types.d.ts +14 -9
  10. package/package.json +6 -14
  11. package/vercel/index.js +0 -15
  12. package/wasm/index.js +259 -239
  13. package/wasm/init.dev.js +249 -191
  14. package/wasm/init.js +3 -3
  15. package/pkg/ziex/src/zx.d.ts +0 -1
  16. package/vendor/jsz/js/src/index.d.ts +0 -1
  17. package/vendor/jsz/js/src/zigjs.d.ts +0 -107
  18. /package/{pkg/ziex/src/app.d.ts → app.d.ts} +0 -0
  19. /package/{pkg/ziex/src/aws-lambda → aws-lambda}/index.d.ts +0 -0
  20. /package/{pkg/ziex/src/browser → browser}/kv.d.ts +0 -0
  21. /package/{pkg/ziex/src/cloudflare → cloudflare}/app.d.ts +0 -0
  22. /package/{pkg/ziex/src/cloudflare → cloudflare}/db.d.ts +0 -0
  23. /package/{pkg/ziex/src/cloudflare → cloudflare}/do.d.ts +0 -0
  24. /package/{pkg/ziex/src/cloudflare → cloudflare}/index.d.ts +0 -0
  25. /package/{pkg/ziex/src/cloudflare → cloudflare}/kv.d.ts +0 -0
  26. /package/{pkg/ziex/src/cloudflare → cloudflare}/worker.d.ts +0 -0
  27. /package/{pkg/ziex/src/db.d.ts → db.d.ts} +0 -0
  28. /package/{pkg/ziex/src/fetch.d.ts → fetch.d.ts} +0 -0
  29. /package/{pkg/ziex/src/index.d.ts → index.d.ts} +0 -0
  30. /package/{pkg/ziex/src/kv.d.ts → kv.d.ts} +0 -0
  31. /package/{pkg/ziex/src/runtime.d.ts → runtime.d.ts} +0 -0
  32. /package/{pkg/ziex/src/vercel → vercel}/index.d.ts +0 -0
  33. /package/{pkg/ziex/src/wasi.d.ts → wasi.d.ts} +0 -0
  34. /package/{pkg/ziex/src/wasm → wasm}/core.d.ts +0 -0
  35. /package/{pkg/ziex/src/wasm → wasm}/dom.d.ts +0 -0
  36. /package/{pkg/ziex/src/wasm → wasm}/index.d.ts +0 -0
  37. /package/{pkg/ziex/src/wasm → wasm}/init.d.ts +0 -0
  38. /package/{pkg/ziex/src/wasm → wasm}/types.d.ts +0 -0
  39. /package/{pkg/ziex/src/wasm → wasm}/wasi.d.ts +0 -0
@@ -1,25 +1,9 @@
1
- var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true,
11
- configurable: true,
12
- set: __exportSetter.bind(all, name)
13
- });
14
- };
15
-
16
1
  // src/aws-lambda/index.ts
17
2
  function isV2(event) {
18
3
  return "requestContext" in event && event.requestContext !== null && "http" in event.requestContext;
19
4
  }
20
5
  function getMethod(event) {
21
- if (isV2(event))
22
- return event.requestContext.http.method;
6
+ if (isV2(event)) return event.requestContext.http.method;
23
7
  return event.httpMethod;
24
8
  }
25
9
  function getPath(event) {
@@ -38,29 +22,36 @@ function getPath(event) {
38
22
  return e.path + (queryString ? `?${queryString}` : "");
39
23
  }
40
24
  function getHeaders(event) {
41
- const headers = new Headers;
25
+ const headers = new Headers();
42
26
  if (event.headers) {
43
27
  for (const [k, v] of Object.entries(event.headers)) {
44
- if (v != null)
45
- headers.set(k, v);
28
+ if (v != null) headers.set(k, v);
46
29
  }
47
30
  }
48
31
  if ("multiValueHeaders" in event && event.multiValueHeaders) {
49
32
  for (const [k, vs] of Object.entries(event.multiValueHeaders)) {
50
- if (!vs?.length)
51
- continue;
33
+ if (!vs?.length) continue;
52
34
  headers.delete(k);
53
- for (const v of vs)
54
- headers.append(k, v);
35
+ for (const v of vs) headers.append(k, v);
55
36
  }
56
37
  }
57
38
  return headers;
58
39
  }
40
+ function decodeBase64(base64) {
41
+ const binary = atob(base64);
42
+ const bytes = new Uint8Array(binary.length);
43
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
44
+ return bytes;
45
+ }
46
+ function encodeBase64(buffer) {
47
+ const bytes = new Uint8Array(buffer);
48
+ let binary = "";
49
+ for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
50
+ return btoa(binary);
51
+ }
59
52
  function getBody(event) {
60
- if (!event.body)
61
- return null;
62
- if (event.isBase64Encoded)
63
- return Buffer.from(event.body, "base64");
53
+ if (!event.body) return null;
54
+ if (event.isBase64Encoded) return decodeBase64(event.body);
64
55
  return event.body;
65
56
  }
66
57
  function toRequest(event, headers) {
@@ -103,7 +94,7 @@ async function toLambdaResult(res, binaryMediaTypes) {
103
94
  let body;
104
95
  let isBase64Encoded = false;
105
96
  if (binary) {
106
- body = Buffer.from(await res.arrayBuffer()).toString("base64");
97
+ body = encodeBase64(await res.arrayBuffer());
107
98
  isBase64Encoded = true;
108
99
  } else {
109
100
  body = await res.text();
package/build.zig CHANGED
@@ -1,5 +1,121 @@
1
1
  const std = @import("std");
2
+ const esbuild = @import("esbuild");
2
3
 
3
- pub fn build(b: *std.Build) void {
4
- _ = b; // stub
4
+ pub fn build(b: *std.Build) !void {
5
+ const optimize = b.standardOptimizeOption(.{});
6
+ const target = b.standardTargetOptions(.{});
7
+ _ = target;
8
+ const type_decl = b.option(bool, "type-decl", "Generate type declarations") orelse true;
9
+ const is_release = optimize != .Debug;
10
+
11
+ // --- JS bundles (esbuild) --- //
12
+ const packages = esbuild.addBuild(b, .{
13
+ .name = "ziex",
14
+ .config = .{
15
+ .entrypoints = &.{
16
+ b.path("src/index.ts"),
17
+ b.path("src/jsx/index.ts"),
18
+ b.path("src/wasm/index.ts"),
19
+ b.path("src/cloudflare/index.ts"),
20
+ b.path("src/aws-lambda/index.ts"),
21
+ b.path("src/vercel/index.ts"),
22
+ },
23
+ .format = .esm,
24
+ .platform = .neutral,
25
+ .minify = is_release,
26
+ .define = &.{
27
+ .{ .key = "__DEV__", .value = if (is_release) "false" else "true" },
28
+ },
29
+ },
30
+ });
31
+
32
+ const wasm_init = esbuild.addBuild(b, .{
33
+ .name = "wasm_init",
34
+ .config = .{
35
+ .entrypoints = &.{b.path("src/wasm/init.ts")},
36
+ .format = .esm,
37
+ .platform = .browser,
38
+ .minify = true,
39
+ .define = &.{
40
+ .{ .key = "__DEV__", .value = "false" },
41
+ },
42
+ },
43
+ });
44
+
45
+ const wasm_init_dev = esbuild.addBuild(b, .{
46
+ .name = "wasm_init_dev",
47
+ .config = .{
48
+ .entrypoints = &.{b.path("src/wasm/init.ts")},
49
+ .format = .esm,
50
+ .platform = .browser,
51
+ .minify = false,
52
+ .define = &.{
53
+ .{ .key = "__DEV__", .value = "true" },
54
+ },
55
+ },
56
+ });
57
+
58
+ const dist_files = b.addNamedWriteFiles("ziex_js");
59
+
60
+ // --- App init files --- //
61
+ {
62
+ _ = dist_files.addCopyFile(wasm_init.dir.path(b, "init.js"), "wasm/init.js");
63
+ _ = dist_files.addCopyFile(wasm_init_dev.dir.path(b, "init.js"), "wasm/init.dev.js");
64
+ }
65
+
66
+ // --- Static package files --- //
67
+ {
68
+ _ = dist_files.addCopyFile(try makePublishPackageJson(b), "package.json");
69
+ _ = dist_files.addCopyFile(b.path("../../README.md"), "README.md");
70
+ _ = dist_files.addCopyFile(b.path("bin/ziex"), "bin/ziex");
71
+ _ = dist_files.addCopyFile(b.path("build.zig"), "build.zig");
72
+ _ = dist_files.addCopyFile(b.path("build.zig.zon"), "build.zig.zon");
73
+
74
+ // --- Other bindings --- //
75
+ _ = dist_files.addCopyDirectory(packages.dir, "", .{});
76
+ }
77
+
78
+ // --- TypeScript declarations --- //
79
+ if (type_decl) {
80
+ const typescript = @import("typescript");
81
+ const dts = typescript.addBuild(b, .{
82
+ .name = "ziex.d.ts",
83
+ .config = .{
84
+ .project = b.path("tsconfig.json"),
85
+ },
86
+ });
87
+ _ = dist_files.addCopyDirectory(dts.dir.path(b, "pkg/ziex/src"), "", .{});
88
+ }
89
+
90
+ b.getInstallStep().dependOn(&b.addInstallDirectory(.{
91
+ .source_dir = dist_files.getDirectory(),
92
+ .install_dir = .prefix,
93
+ .install_subdir = "",
94
+ }).step);
95
+ }
96
+
97
+ fn makePublishPackageJson(b: *std.Build) !std.Build.LazyPath {
98
+ const src = try b.root.root_dir.handle.readFileAlloc(b.graph.io, "package.json", b.allocator, .unlimited);
99
+ defer b.allocator.free(src);
100
+
101
+ var parsed = try std.json.parseFromSlice(std.json.Value, b.allocator, src, .{});
102
+ defer parsed.deinit();
103
+
104
+ const obj = &parsed.value.object;
105
+ try obj.put(b.allocator, "main", .{ .string = "index.js" });
106
+ try obj.put(b.allocator, "module", .{ .string = "index.js" });
107
+ try obj.put(b.allocator, "types", .{ .string = "index.d.ts" });
108
+ try obj.put(b.allocator, "scripts", .{ .object = .empty });
109
+ _ = obj.swapRemove("private");
110
+ _ = obj.swapRemove("devDependencies");
111
+ _ = obj.swapRemove("peerDependencies");
112
+ _ = obj.swapRemove("release");
113
+ _ = obj.swapRemove("prettier");
114
+
115
+ const json = try std.json.Stringify.valueAlloc(b.allocator, parsed.value, .{ .whitespace = .indent_2 });
116
+ defer b.allocator.free(json);
117
+ const out = try std.mem.concat(b.allocator, u8, &.{ json, "\n" });
118
+ defer b.allocator.free(out);
119
+
120
+ return b.addWriteFiles().add("package.json", out);
5
121
  }
package/build.zig.zon CHANGED
@@ -2,6 +2,17 @@
2
2
  .name = .ziex_js,
3
3
  .fingerprint = 0x3428b4e119b455bf,
4
4
  .version = "0.1.0-dev",
5
- .minimum_zig_version = "0.16.0",
6
- .paths = .{""},
5
+ .minimum_zig_version = "0.17.0-dev.1158+1d1193aa7",
6
+ .dependencies = .{
7
+ .esbuild = .{ .path = "../plugin-esbuild" },
8
+ .typescript = .{ .path = "../plugin-typescript", .lazy = true },
9
+ },
10
+ .paths = .{
11
+ "build.zig",
12
+ "build.zig.zon",
13
+ "src",
14
+ "bin",
15
+ "package.json",
16
+ "tsconfig.json",
17
+ },
7
18
  }