ziex 0.1.0-dev.1458 → 0.1.0-dev.1567
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 -9
- package/app.d.ts +37 -22
- package/build.zig.zon +1 -1
- package/index.d.ts +1 -1
- package/index.js +252 -223
- package/package.json +2 -2
- package/platforms/aws-lambda/index.d.ts +1 -1
- package/platforms/cloudflare/app.d.ts +31 -1
- package/platforms/cloudflare/index.d.ts +5 -4
- package/platforms/cloudflare/index.js +1801 -1670
- package/platforms/cloudflare/kv.d.ts +4 -2
- package/platforms/cloudflare/stateful.d.ts +26 -0
- package/platforms/cloudflare/worker.d.ts +1 -2
- package/platforms/vercel/index.d.ts +1 -1
- package/runtime/index.d.ts +20 -10
- package/runtime/kv/indexdb.d.ts +11 -3
- package/runtime/kv/localstorage.d.ts +11 -3
- package/runtime/kv/memory.d.ts +13 -6
- package/runtime/kv.d.ts +17 -18
- package/runtime/kv.js +178 -240
- package/runtime/wasi.d.ts +2 -7
- package/wasm/constants.d.ts +33 -0
- package/wasm/core.d.ts +7 -19
- package/wasm/dom_cmd.d.ts +6 -0
- package/wasm/generated/event_bits.d.ts +2 -0
- package/wasm/generated/events.d.ts +1 -0
- package/wasm/generated/tag_indices.d.ts +2 -0
- package/wasm/generated/tags.d.ts +1 -0
- package/wasm/index.d.ts +3 -2
- package/wasm/index.js +635 -555
- package/wasm/init.dev.js +650 -562
- package/wasm/init.js +3 -3
- package/platforms/cloudflare/do.d.ts +0 -50
package/runtime/kv.js
CHANGED
|
@@ -1,164 +1,3 @@
|
|
|
1
|
-
// src/runtime/kv/memory.ts
|
|
2
|
-
function createMemoryKV() {
|
|
3
|
-
const store = /* @__PURE__ */ new Map();
|
|
4
|
-
function read(key) {
|
|
5
|
-
const entry = store.get(key);
|
|
6
|
-
if (!entry) return null;
|
|
7
|
-
const expiresAt = entry[1];
|
|
8
|
-
if (expiresAt !== void 0 && Date.now() >= expiresAt) {
|
|
9
|
-
store.delete(key);
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return entry[0];
|
|
13
|
-
}
|
|
14
|
-
function write(key, value, options) {
|
|
15
|
-
let expiresAt;
|
|
16
|
-
if (options?.expiration !== void 0) {
|
|
17
|
-
expiresAt = options.expiration * 1e3;
|
|
18
|
-
} else if (options?.expirationTtl !== void 0) {
|
|
19
|
-
expiresAt = Date.now() + options.expirationTtl * 1e3;
|
|
20
|
-
}
|
|
21
|
-
store.set(key, [value, expiresAt]);
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
async get(key) {
|
|
25
|
-
return read(key);
|
|
26
|
-
},
|
|
27
|
-
async put(key, value, options) {
|
|
28
|
-
write(key, value, options);
|
|
29
|
-
},
|
|
30
|
-
async delete(key) {
|
|
31
|
-
store.delete(key);
|
|
32
|
-
},
|
|
33
|
-
async list(options) {
|
|
34
|
-
const keys = [...store.keys()].filter((k) => {
|
|
35
|
-
if (options?.prefix && !k.startsWith(options.prefix)) return false;
|
|
36
|
-
return read(k) !== null;
|
|
37
|
-
}).map((name) => ({ name }));
|
|
38
|
-
return { keys };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/runtime/kv/localstorage.ts
|
|
44
|
-
function getLocalStorage() {
|
|
45
|
-
if (typeof localStorage === "undefined") {
|
|
46
|
-
throw new Error("localStorage is not available in this environment");
|
|
47
|
-
}
|
|
48
|
-
return localStorage;
|
|
49
|
-
}
|
|
50
|
-
function createLocalStorageKV(options = {}) {
|
|
51
|
-
const storage = getLocalStorage();
|
|
52
|
-
const namespace = options.namespace ?? "default";
|
|
53
|
-
const storagePrefix = options.storagePrefix ?? "ziex-kv";
|
|
54
|
-
const scopedKey = (key) => `${storagePrefix}:${namespace}:${key}`;
|
|
55
|
-
const namespacePrefix = scopedKey("");
|
|
56
|
-
return {
|
|
57
|
-
getSync(key) {
|
|
58
|
-
return storage.getItem(scopedKey(key));
|
|
59
|
-
},
|
|
60
|
-
async get(key) {
|
|
61
|
-
return this.getSync(key);
|
|
62
|
-
},
|
|
63
|
-
putSync(key, value) {
|
|
64
|
-
storage.setItem(scopedKey(key), value);
|
|
65
|
-
},
|
|
66
|
-
async put(key, value) {
|
|
67
|
-
this.putSync(key, value);
|
|
68
|
-
},
|
|
69
|
-
deleteSync(key) {
|
|
70
|
-
storage.removeItem(scopedKey(key));
|
|
71
|
-
},
|
|
72
|
-
async delete(key) {
|
|
73
|
-
this.deleteSync(key);
|
|
74
|
-
},
|
|
75
|
-
listSync(options2) {
|
|
76
|
-
const prefix = namespacePrefix + (options2?.prefix ?? "");
|
|
77
|
-
const keys = [];
|
|
78
|
-
for (let i = 0; i < storage.length; i += 1) {
|
|
79
|
-
const key = storage.key(i);
|
|
80
|
-
if (!key || !key.startsWith(prefix)) continue;
|
|
81
|
-
keys.push({ name: key.slice(namespacePrefix.length) });
|
|
82
|
-
}
|
|
83
|
-
return { keys };
|
|
84
|
-
},
|
|
85
|
-
async list(options2) {
|
|
86
|
-
return this.listSync(options2);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/runtime/kv/indexdb.ts
|
|
92
|
-
function getIndexedDb() {
|
|
93
|
-
if (typeof indexedDB === "undefined") {
|
|
94
|
-
throw new Error("IndexedDB is not available in this environment");
|
|
95
|
-
}
|
|
96
|
-
return indexedDB;
|
|
97
|
-
}
|
|
98
|
-
function requestToPromise(request) {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
request.onsuccess = () => resolve(request.result);
|
|
101
|
-
request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function transactionToPromise(transaction) {
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
transaction.oncomplete = () => resolve();
|
|
107
|
-
transaction.onabort = () => reject(transaction.error ?? new Error("IndexedDB transaction aborted"));
|
|
108
|
-
transaction.onerror = () => reject(transaction.error ?? new Error("IndexedDB transaction failed"));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function createIndexedDbKV(options = {}) {
|
|
112
|
-
const databaseName = options.databaseName ?? "ziex-kv";
|
|
113
|
-
const storeName = options.storeName ?? "kv";
|
|
114
|
-
const namespace = options.namespace ?? "default";
|
|
115
|
-
const dbPromise = new Promise((resolve, reject) => {
|
|
116
|
-
const request = getIndexedDb().open(databaseName, 1);
|
|
117
|
-
request.onupgradeneeded = () => {
|
|
118
|
-
const db = request.result;
|
|
119
|
-
if (!db.objectStoreNames.contains(storeName)) {
|
|
120
|
-
db.createObjectStore(storeName);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
request.onsuccess = () => resolve(request.result);
|
|
124
|
-
request.onerror = () => reject(request.error ?? new Error("Failed to open IndexedDB"));
|
|
125
|
-
});
|
|
126
|
-
const scopedKey = (key) => `${namespace}:${key}`;
|
|
127
|
-
return {
|
|
128
|
-
async get(key) {
|
|
129
|
-
const db = await dbPromise;
|
|
130
|
-
const tx = db.transaction(storeName, "readonly");
|
|
131
|
-
const store = tx.objectStore(storeName);
|
|
132
|
-
const value = await requestToPromise(store.get(scopedKey(key)));
|
|
133
|
-
await transactionToPromise(tx);
|
|
134
|
-
return typeof value === "string" ? value : null;
|
|
135
|
-
},
|
|
136
|
-
async put(key, value) {
|
|
137
|
-
const db = await dbPromise;
|
|
138
|
-
const tx = db.transaction(storeName, "readwrite");
|
|
139
|
-
tx.objectStore(storeName).put(value, scopedKey(key));
|
|
140
|
-
await transactionToPromise(tx);
|
|
141
|
-
},
|
|
142
|
-
async delete(key) {
|
|
143
|
-
const db = await dbPromise;
|
|
144
|
-
const tx = db.transaction(storeName, "readwrite");
|
|
145
|
-
tx.objectStore(storeName).delete(scopedKey(key));
|
|
146
|
-
await transactionToPromise(tx);
|
|
147
|
-
},
|
|
148
|
-
async list(options2) {
|
|
149
|
-
const db = await dbPromise;
|
|
150
|
-
const tx = db.transaction(storeName, "readonly");
|
|
151
|
-
const store = tx.objectStore(storeName);
|
|
152
|
-
const keys = await requestToPromise(store.getAllKeys());
|
|
153
|
-
await transactionToPromise(tx);
|
|
154
|
-
const prefix = scopedKey(options2?.prefix ?? "");
|
|
155
|
-
return {
|
|
156
|
-
keys: keys.filter((key) => typeof key === "string" && key.startsWith(prefix)).map((key) => ({ name: key.slice(namespace.length + 1) }))
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
1
|
// ../../vendor/jsz/js/src/zigjs.ts
|
|
163
2
|
var NAN_PREFIX = 2146959360;
|
|
164
3
|
var predefined = {
|
|
@@ -434,109 +273,208 @@ function writeJsonOut(getMemory, allocRef, outPtrAddr, value) {
|
|
|
434
273
|
}
|
|
435
274
|
|
|
436
275
|
// src/runtime/kv/extern.ts
|
|
276
|
+
var Suspending = WebAssembly.Suspending;
|
|
277
|
+
var jspi = typeof Suspending === "function";
|
|
278
|
+
var miss = jspi ? -1 : 0;
|
|
437
279
|
function putOptions(ttlSeconds) {
|
|
438
280
|
if (ttlSeconds < 60) return void 0;
|
|
439
281
|
return { expirationTtl: ttlSeconds };
|
|
440
282
|
}
|
|
283
|
+
function kvDel(binding, key) {
|
|
284
|
+
const b = binding;
|
|
285
|
+
return (b.del ?? b.delete).call(b, key);
|
|
286
|
+
}
|
|
441
287
|
function isSyncKVNamespace(binding) {
|
|
442
|
-
|
|
443
|
-
return typeof candidate.getSync === "function" && typeof candidate.putSync === "function" && typeof candidate.deleteSync === "function" && typeof candidate.listSync === "function";
|
|
288
|
+
return typeof binding.get === "function" && binding.get.constructor.name !== "AsyncFunction";
|
|
444
289
|
}
|
|
445
|
-
function
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
290
|
+
function listOpts(prefix) {
|
|
291
|
+
return prefix.length > 0 ? { prefix } : void 0;
|
|
292
|
+
}
|
|
293
|
+
function maybeThen(r, f) {
|
|
294
|
+
return r instanceof Promise ? r.then(f) : f(r);
|
|
295
|
+
}
|
|
296
|
+
function readStr(getMemory, ptr, len) {
|
|
297
|
+
return textDecoder.decode(new Uint8Array(getMemory().buffer, ptr, len));
|
|
298
|
+
}
|
|
299
|
+
function resolve(bindings, ns) {
|
|
300
|
+
const b = bindings[ns] ?? bindings["default"] ?? null;
|
|
301
|
+
if (!b || jspi) return b;
|
|
302
|
+
return isSyncKVNamespace(b) ? b : null;
|
|
303
|
+
}
|
|
304
|
+
function encodeGet(getMemory, allocRef, value, out_ptr) {
|
|
305
|
+
if (value === null) return -1;
|
|
306
|
+
return writeBytesOut(getMemory, allocRef, out_ptr, textEncoder.encode(value));
|
|
307
|
+
}
|
|
308
|
+
function encodeList(getMemory, allocRef, names, out_ptr) {
|
|
309
|
+
if (names.length === 0) {
|
|
310
|
+
new DataView(getMemory().buffer).setUint32(out_ptr, 0, true);
|
|
311
|
+
return 0;
|
|
453
312
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
b.deleteSync(readStr(key_ptr, key_len));
|
|
479
|
-
return 0;
|
|
480
|
-
},
|
|
481
|
-
kv_list: (ns_ptr, ns_len, pfx_ptr, pfx_len, out_ptr) => {
|
|
482
|
-
const b = syncBinding2(readStr(ns_ptr, ns_len));
|
|
483
|
-
if (!b) return writeJsonOut(getMemory, allocRef, out_ptr, []);
|
|
484
|
-
const prefix = readStr(pfx_ptr, pfx_len);
|
|
485
|
-
const result = b.listSync(prefix.length > 0 ? { prefix } : void 0);
|
|
486
|
-
return writeJsonOut(getMemory, allocRef, out_ptr, result.keys.map((k) => k.name));
|
|
487
|
-
}
|
|
488
|
-
};
|
|
313
|
+
return writeJsonOut(getMemory, allocRef, out_ptr, names);
|
|
314
|
+
}
|
|
315
|
+
function get(b, key, out_ptr, getMemory, allocRef) {
|
|
316
|
+
return maybeThen(b.get(key), (v) => encodeGet(getMemory, allocRef, v, out_ptr));
|
|
317
|
+
}
|
|
318
|
+
function put(b, key, val, ttl) {
|
|
319
|
+
return maybeThen(b.put(key, val, putOptions(ttl)), () => 0);
|
|
320
|
+
}
|
|
321
|
+
function del(b, key) {
|
|
322
|
+
return maybeThen(kvDel(b, key), () => 0);
|
|
323
|
+
}
|
|
324
|
+
function list(b, prefix, out_ptr, getMemory, allocRef) {
|
|
325
|
+
return maybeThen(
|
|
326
|
+
b.list(listOpts(prefix)),
|
|
327
|
+
(result) => encodeList(getMemory, allocRef, result.keys.map((k) => k.name), out_ptr)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
function wrapImport(impl) {
|
|
331
|
+
if (!jspi) {
|
|
332
|
+
return ((...args) => {
|
|
333
|
+
const r = impl(...args);
|
|
334
|
+
if (r instanceof Promise) throw new Error("async kv binding requires JSPI");
|
|
335
|
+
return r;
|
|
336
|
+
});
|
|
489
337
|
}
|
|
338
|
+
return new Suspending(impl);
|
|
339
|
+
}
|
|
340
|
+
function createKVImports(bindings, getMemory, allocRef) {
|
|
490
341
|
return {
|
|
491
|
-
kv_get:
|
|
492
|
-
const b =
|
|
342
|
+
kv_get: wrapImport((ns_ptr, ns_len, key_ptr, key_len, out_ptr) => {
|
|
343
|
+
const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
|
|
493
344
|
if (!b) return -1;
|
|
494
|
-
|
|
495
|
-
if (value === null) return -1;
|
|
496
|
-
return writeBytesOut(getMemory, allocRef, out_ptr, encoder2.encode(value));
|
|
345
|
+
return get(b, readStr(getMemory, key_ptr, key_len), out_ptr, getMemory, allocRef);
|
|
497
346
|
}),
|
|
498
|
-
kv_put:
|
|
499
|
-
const b =
|
|
500
|
-
if (!b) return
|
|
501
|
-
|
|
502
|
-
|
|
347
|
+
kv_put: wrapImport((ns_ptr, ns_len, key_ptr, key_len, val_ptr, val_len, ttl_seconds) => {
|
|
348
|
+
const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
|
|
349
|
+
if (!b) return miss;
|
|
350
|
+
return put(
|
|
351
|
+
b,
|
|
352
|
+
readStr(getMemory, key_ptr, key_len),
|
|
353
|
+
readStr(getMemory, val_ptr, val_len),
|
|
354
|
+
ttl_seconds
|
|
355
|
+
);
|
|
503
356
|
}),
|
|
504
|
-
kv_delete:
|
|
505
|
-
const b =
|
|
506
|
-
if (!b) return
|
|
507
|
-
|
|
508
|
-
return 0;
|
|
357
|
+
kv_delete: wrapImport((ns_ptr, ns_len, key_ptr, key_len) => {
|
|
358
|
+
const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
|
|
359
|
+
if (!b) return miss;
|
|
360
|
+
return del(b, readStr(getMemory, key_ptr, key_len));
|
|
509
361
|
}),
|
|
510
|
-
kv_list:
|
|
511
|
-
const b =
|
|
362
|
+
kv_list: wrapImport((ns_ptr, ns_len, pfx_ptr, pfx_len, out_ptr) => {
|
|
363
|
+
const b = resolve(bindings, readStr(getMemory, ns_ptr, ns_len));
|
|
512
364
|
if (!b) return writeJsonOut(getMemory, allocRef, out_ptr, []);
|
|
513
|
-
|
|
514
|
-
const result = await b.list(prefix.length > 0 ? { prefix } : void 0);
|
|
515
|
-
const names = result.keys.map((k) => k.name);
|
|
516
|
-
if (names.length === 0) {
|
|
517
|
-
new DataView(getMemory().buffer).setUint32(out_ptr, 0, true);
|
|
518
|
-
return 0;
|
|
519
|
-
}
|
|
520
|
-
return writeJsonOut(getMemory, allocRef, out_ptr, names);
|
|
365
|
+
return list(b, readStr(getMemory, pfx_ptr, pfx_len), out_ptr, getMemory, allocRef);
|
|
521
366
|
})
|
|
522
367
|
};
|
|
523
368
|
}
|
|
524
369
|
|
|
525
|
-
// src/runtime/kv.ts
|
|
526
|
-
|
|
527
|
-
|
|
370
|
+
// src/runtime/kv/localstorage.ts
|
|
371
|
+
var namespace = "default";
|
|
372
|
+
var storagePrefix = "ziex-kv";
|
|
373
|
+
var namespacePrefix = `${storagePrefix}:${namespace}:`;
|
|
374
|
+
function storage() {
|
|
375
|
+
if (typeof localStorage === "undefined") {
|
|
376
|
+
throw new Error("localStorage is not available in this environment");
|
|
377
|
+
}
|
|
378
|
+
return localStorage;
|
|
379
|
+
}
|
|
380
|
+
function get2(key) {
|
|
381
|
+
return storage().getItem(`${storagePrefix}:${namespace}:${key}`);
|
|
528
382
|
}
|
|
383
|
+
function put2(key, value) {
|
|
384
|
+
storage().setItem(`${storagePrefix}:${namespace}:${key}`, value);
|
|
385
|
+
}
|
|
386
|
+
function del2(key) {
|
|
387
|
+
storage().removeItem(`${storagePrefix}:${namespace}:${key}`);
|
|
388
|
+
}
|
|
389
|
+
function list2(options) {
|
|
390
|
+
const ls = storage();
|
|
391
|
+
const prefix = namespacePrefix + (options?.prefix ?? "");
|
|
392
|
+
const keys = [];
|
|
393
|
+
for (let i = 0; i < ls.length; i += 1) {
|
|
394
|
+
const key = ls.key(i);
|
|
395
|
+
if (!key || !key.startsWith(prefix)) continue;
|
|
396
|
+
keys.push({ name: key.slice(namespacePrefix.length) });
|
|
397
|
+
}
|
|
398
|
+
return { keys };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/runtime/kv/indexdb.ts
|
|
402
|
+
var databaseName = "ziex-kv";
|
|
403
|
+
var storeName = "kv";
|
|
404
|
+
var namespace2 = "default";
|
|
405
|
+
var dbPromise;
|
|
406
|
+
function openDb() {
|
|
407
|
+
if (!dbPromise) {
|
|
408
|
+
if (typeof indexedDB === "undefined") {
|
|
409
|
+
return Promise.reject(new Error("IndexedDB is not available in this environment"));
|
|
410
|
+
}
|
|
411
|
+
dbPromise = new Promise((resolve2, reject) => {
|
|
412
|
+
const request = indexedDB.open(databaseName, 1);
|
|
413
|
+
request.onupgradeneeded = () => {
|
|
414
|
+
const db = request.result;
|
|
415
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
416
|
+
db.createObjectStore(storeName);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
request.onsuccess = () => resolve2(request.result);
|
|
420
|
+
request.onerror = () => reject(request.error ?? new Error("Failed to open IndexedDB"));
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
return dbPromise;
|
|
424
|
+
}
|
|
425
|
+
function requestToPromise(request) {
|
|
426
|
+
return new Promise((resolve2, reject) => {
|
|
427
|
+
request.onsuccess = () => resolve2(request.result);
|
|
428
|
+
request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
function transactionToPromise(transaction) {
|
|
432
|
+
return new Promise((resolve2, reject) => {
|
|
433
|
+
transaction.oncomplete = () => resolve2();
|
|
434
|
+
transaction.onabort = () => reject(transaction.error ?? new Error("IndexedDB transaction aborted"));
|
|
435
|
+
transaction.onerror = () => reject(transaction.error ?? new Error("IndexedDB transaction failed"));
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async function get3(key) {
|
|
439
|
+
const db = await openDb();
|
|
440
|
+
const tx = db.transaction(storeName, "readonly");
|
|
441
|
+
const value = await requestToPromise(tx.objectStore(storeName).get(`${namespace2}:${key}`));
|
|
442
|
+
await transactionToPromise(tx);
|
|
443
|
+
return typeof value === "string" ? value : null;
|
|
444
|
+
}
|
|
445
|
+
async function put3(key, value) {
|
|
446
|
+
const db = await openDb();
|
|
447
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
448
|
+
tx.objectStore(storeName).put(value, `${namespace2}:${key}`);
|
|
449
|
+
await transactionToPromise(tx);
|
|
450
|
+
}
|
|
451
|
+
async function del3(key) {
|
|
452
|
+
const db = await openDb();
|
|
453
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
454
|
+
tx.objectStore(storeName).delete(`${namespace2}:${key}`);
|
|
455
|
+
await transactionToPromise(tx);
|
|
456
|
+
}
|
|
457
|
+
async function list3(options) {
|
|
458
|
+
const db = await openDb();
|
|
459
|
+
const tx = db.transaction(storeName, "readonly");
|
|
460
|
+
const keys = await requestToPromise(tx.objectStore(storeName).getAllKeys());
|
|
461
|
+
await transactionToPromise(tx);
|
|
462
|
+
const prefix = `${namespace2}:${options?.prefix ?? ""}`;
|
|
463
|
+
return {
|
|
464
|
+
keys: keys.filter((key) => typeof key === "string" && key.startsWith(prefix)).map((key) => ({ name: key.slice(namespace2.length + 1) }))
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// src/runtime/kv.ts
|
|
469
|
+
var hasJspi = typeof WebAssembly.Suspending === "function" && typeof WebAssembly.promising === "function";
|
|
529
470
|
function createBrowserKVBindings(options = {}) {
|
|
530
|
-
const
|
|
471
|
+
const namespace3 = options.namespace ?? "default";
|
|
531
472
|
return {
|
|
532
|
-
[
|
|
473
|
+
[namespace3]: hasJspi && !options.forceLocalStorage ? { get: get3, put: put3, del: del3, list: list3 } : { get: get2, put: put2, del: del2, list: list2 }
|
|
533
474
|
};
|
|
534
475
|
}
|
|
535
476
|
export {
|
|
536
477
|
createBrowserKVBindings,
|
|
537
|
-
createIndexedDbKV,
|
|
538
478
|
createKVImports,
|
|
539
|
-
|
|
540
|
-
createMemoryKV,
|
|
541
|
-
hasJSPI
|
|
479
|
+
hasJspi
|
|
542
480
|
};
|
package/runtime/wasi.d.ts
CHANGED
|
@@ -17,11 +17,10 @@ export type WASI = {
|
|
|
17
17
|
};
|
|
18
18
|
}): void;
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
/** WASI imports for request argv/stdin. Response body uses `__zx_http`, not stdout. */
|
|
21
|
+
export declare function createWasiImports({ request, stdinData, }: {
|
|
21
22
|
request: Request;
|
|
22
23
|
stdinData?: Uint8Array;
|
|
23
|
-
/** Called for each stdout chunk. When provided, chunks are NOT buffered internally. */
|
|
24
|
-
onStdout?: (chunk: Uint8Array) => void;
|
|
25
24
|
}): {
|
|
26
25
|
wasiImport: {
|
|
27
26
|
args_sizes_get(argc_ptr: number, argv_buf_size_ptr: number): number;
|
|
@@ -71,9 +70,5 @@ export declare function createWasiImports({ request, stdinData, onStdout, }: {
|
|
|
71
70
|
poll_oneoff(_in: number, _out: number, _nsubscriptions: number, nevents_ptr: number): number;
|
|
72
71
|
};
|
|
73
72
|
setMemory: (m: WebAssembly.Memory) => void;
|
|
74
|
-
collectOutput: () => {
|
|
75
|
-
stdout: Uint8Array;
|
|
76
|
-
stderrText: string;
|
|
77
|
-
};
|
|
78
73
|
};
|
|
79
74
|
export declare function mergeUint8Arrays(arrays: Uint8Array[]): Uint8Array;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric wire constants for the WASM↔JS ABI.
|
|
3
|
+
*
|
|
4
|
+
* Kept in a path-import-free module so esbuild's const-inlining heuristic can
|
|
5
|
+
* fold these into call sites across the bundle (#1317 / #1981):
|
|
6
|
+
* only `null` / `undefined` / `true` / `false` / integers / short reals, at the
|
|
7
|
+
* top of a scope with no `import`/`export … from "…"`.
|
|
8
|
+
*
|
|
9
|
+
* Must stay in sync with Zig (`dom_cmd.zig`, `host.zig` / `__zx_cb` types).
|
|
10
|
+
*/
|
|
11
|
+
export declare const DOM_CMD_HEADER_SIZE = 8;
|
|
12
|
+
export declare const DOM_CMD_RECORD_SIZE = 24;
|
|
13
|
+
export declare const DomOp_CreateElement = 1;
|
|
14
|
+
export declare const DomOp_CreateText = 2;
|
|
15
|
+
export declare const DomOp_HydrateInsert = 3;
|
|
16
|
+
export declare const DomOp_SetAttr = 4;
|
|
17
|
+
export declare const DomOp_SetProp = 5;
|
|
18
|
+
export declare const DomOp_RemoveAttr = 6;
|
|
19
|
+
export declare const DomOp_SetNodeValue = 7;
|
|
20
|
+
export declare const DomOp_SetInnerHtml = 8;
|
|
21
|
+
export declare const DomOp_AppendChild = 9;
|
|
22
|
+
export declare const DomOp_InsertBefore = 10;
|
|
23
|
+
export declare const DomOp_RemoveChild = 11;
|
|
24
|
+
export declare const DomOp_ReplaceChild = 12;
|
|
25
|
+
export declare const CallbackType_Event = 0;
|
|
26
|
+
export declare const CallbackType_FetchSuccess = 1;
|
|
27
|
+
export declare const CallbackType_FetchError = 2;
|
|
28
|
+
export declare const CallbackType_Timeout = 3;
|
|
29
|
+
export declare const CallbackType_Interval = 4;
|
|
30
|
+
export declare const CallbackType_WebSocketOpen = 5;
|
|
31
|
+
export declare const CallbackType_WebSocketMessage = 6;
|
|
32
|
+
export declare const CallbackType_WebSocketError = 7;
|
|
33
|
+
export declare const CallbackType_WebSocketClose = 8;
|
package/wasm/core.d.ts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { ZigJS } from "../../../../vendor/jsz/js/src";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export declare const CallbackType_Event = 0;
|
|
6
|
-
export declare const CallbackType_FetchSuccess = 1;
|
|
7
|
-
export declare const CallbackType_FetchError = 2;
|
|
8
|
-
export declare const CallbackType_Timeout = 3;
|
|
9
|
-
export declare const CallbackType_Interval = 4;
|
|
10
|
-
export declare const CallbackType_WebSocketOpen = 5;
|
|
11
|
-
export declare const CallbackType_WebSocketMessage = 6;
|
|
12
|
-
export declare const CallbackType_WebSocketError = 7;
|
|
13
|
-
export declare const CallbackType_WebSocketClose = 8;
|
|
2
|
+
import { CallbackType_Event, CallbackType_FetchSuccess, CallbackType_FetchError, CallbackType_Timeout, CallbackType_Interval, CallbackType_WebSocketOpen, CallbackType_WebSocketMessage, CallbackType_WebSocketError, CallbackType_WebSocketClose } from "./constants";
|
|
3
|
+
export { CallbackType_Event, CallbackType_FetchSuccess, CallbackType_FetchError, CallbackType_Timeout, CallbackType_Interval, CallbackType_WebSocketOpen, CallbackType_WebSocketMessage, CallbackType_WebSocketError, CallbackType_WebSocketClose, } from "./constants";
|
|
14
4
|
export type CallbackTypeValue = typeof CallbackType_Event | typeof CallbackType_FetchSuccess | typeof CallbackType_FetchError | typeof CallbackType_Timeout | typeof CallbackType_Interval | typeof CallbackType_WebSocketOpen | typeof CallbackType_WebSocketMessage | typeof CallbackType_WebSocketError | typeof CallbackType_WebSocketClose;
|
|
15
|
-
|
|
16
|
-
export type
|
|
17
|
-
export type WsOnOpenHandler = (wsId: bigint, protocolPtr: number, protocolLen: number) => void;
|
|
18
|
-
export type WsOnMessageHandler = (wsId: bigint, dataPtr: number, dataLen: number, isBinary: number) => void;
|
|
19
|
-
export type WsOnErrorHandler = (wsId: bigint, msgPtr: number, msgLen: number) => void;
|
|
20
|
-
export type WsOnCloseHandler = (wsId: bigint, code: number, reasonPtr: number, reasonLen: number, wasClean: number) => void;
|
|
5
|
+
/** Unified host→guest callback: (type, id, a, b, c). Extra args are msg-specific. */
|
|
6
|
+
export type CallbackHandler = (callbackType: number, id: bigint, a: bigint, b: bigint, c: bigint) => void;
|
|
21
7
|
/**
|
|
22
8
|
* Core WASM bridge - environment-agnostic (browser + edge).
|
|
23
9
|
* No references to browser globals (document, window, WebSocket, HTMLFormElement).
|
|
@@ -49,9 +35,11 @@ export declare class ZxBridgeCore {
|
|
|
49
35
|
#private;
|
|
50
36
|
protected readonly _alloc: (size: number) => number;
|
|
51
37
|
constructor(exports: WebAssembly.Exports);
|
|
38
|
+
/** Invoke the unified callback handler */
|
|
39
|
+
protected _invoke(type: CallbackTypeValue, id: bigint, a?: bigint, b?: bigint, c?: bigint): void;
|
|
52
40
|
/**
|
|
53
41
|
* Async fetch with full options support.
|
|
54
|
-
*
|
|
42
|
+
* Completes via `__zx_cb(fetch_success|fetch_error, ...)`.
|
|
55
43
|
*/
|
|
56
44
|
fetchAsync(urlPtr: number, urlLen: number, methodPtr: number, methodLen: number, headersPtr: number, headersLen: number, bodyPtr: number, bodyLen: number, timeoutMs: number, fetchId: bigint): void;
|
|
57
45
|
/** Notify WASM that a fetch completed. `body` is raw bytes on success, text on error. */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type DomFlushContext = {
|
|
2
|
+
domNodes: Map<number, Node>;
|
|
3
|
+
cleanupDomNodes: (node: Node) => void;
|
|
4
|
+
};
|
|
5
|
+
/** Apply a DomCmd buffer written at `ptr` with byte length `len`. */
|
|
6
|
+
export declare function flushDomCmds(ptr: number, len: number, ctx: DomFlushContext): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DELEGATED_EVENTS: readonly ['click', 'dblclick', 'input', 'change', 'submit', 'focusin', 'focusout', 'keydown', 'keyup', 'keypress', 'mouseenter', 'mouseleave', 'mousedown', 'mouseup', 'mousemove', 'touchstart', 'touchend', 'touchmove', 'scroll', 'wheel', 'pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'pointerenter', 'pointerleave', 'lostpointercapture'];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TAG_NAMES: readonly ['aside', 'fragment', 'iframe', 'slot', 'img', 'html', 'base', 'head', 'link', 'meta', 'script', 'style', 'title', 'address', 'article', 'body', 'h1', 'h6', 'footer', 'header', 'h2', 'h3', 'h4', 'h5', 'hgroup', 'nav', 'section', 'dd', 'dl', 'dt', 'div', 'figcaption', 'figure', 'hr', 'li', 'ol', 'ul', 'menu', 'main', 'p', 'picture', 'pre', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'time', 'dfn', 'em', 'i', 'kbd', 'mark', 'q', 'blockquote', 'rp', 'ruby', 'rt', 'rtc', 'rb', 's', 'del', 'ins', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'u', 'var', 'wbr', 'area', 'map', 'audio', 'source', 'track', 'video', 'embed', 'object', 'param', 'canvas', 'noscript', 'caption', 'table', 'col', 'colgroup', 'tbody', 'tr', 'thead', 'tfoot', 'td', 'th', 'button', 'datalist', 'option', 'fieldset', 'label', 'form', 'input', 'keygen', 'legend', 'meter', 'optgroup', 'select', 'output', 'progress', 'textarea', 'details', 'dialog', 'menuitem', 'summary', 'content', 'element', 'shadow', 'template', 'acronym', 'applet', 'basefont', 'font', 'big', 'blink', 'center', 'command', 'dir', 'frame', 'frameset', 'isindex', 'listing', 'marquee', 'noembed', 'plaintext', 'spacer', 'strike', 'tt', 'xmp', 'animate', 'animateMotion', 'animateTransform', 'circle', 'clipPath', 'defs', 'desc', 'ellipse', 'feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'filter', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'set', 'stop', 'svg', 'switch', 'symbol', 'text', 'textPath', 'tspan', 'use', 'view', 'custom'];
|
package/wasm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { CallbackType_Event, CallbackType_FetchSuccess, CallbackType_FetchError, CallbackType_Timeout, CallbackType_Interval, CallbackType_WebSocketOpen, CallbackType_WebSocketMessage, CallbackType_WebSocketError, CallbackType_WebSocketClose,
|
|
1
|
+
export { CallbackType_Event, CallbackType_FetchSuccess, CallbackType_FetchError, CallbackType_Timeout, CallbackType_Interval, CallbackType_WebSocketOpen, CallbackType_WebSocketMessage, CallbackType_WebSocketError, CallbackType_WebSocketClose, } from "./constants";
|
|
2
|
+
export { jsz, storeValueGetRef, loadValueFromRef, releaseValueRef, textDecoder, textEncoder, getMemoryView, readString, writeBytes, writeBytesOut, writeJsonOut, bindWasmAlloc, ZxBridgeCore, } from "./core";
|
|
2
3
|
export type { CallbackTypeValue, WasmAllocRef } from "./core";
|
|
3
4
|
import { ZxBridgeCore } from "./core";
|
|
4
5
|
import { type KVNamespace } from "../runtime/kv";
|
|
@@ -18,7 +19,7 @@ export declare class ZxBridge extends ZxBridgeCore {
|
|
|
18
19
|
submitFormActionAsync(form: HTMLFormElement, actionId: number, statesJson: string, fetchId: bigint): void;
|
|
19
20
|
/**
|
|
20
21
|
* Create and connect a WebSocket.
|
|
21
|
-
*
|
|
22
|
+
* Completes via `__zx_cb(ws_open|ws_message|ws_error|ws_close, ...)`.
|
|
22
23
|
*/
|
|
23
24
|
wsConnect(wsId: bigint, urlPtr: number, urlLen: number, protocolsPtr: number, protocolsLen: number): void;
|
|
24
25
|
/** Send data over WebSocket */
|