ziex 0.1.0-dev.1466 → 0.1.0-dev.1568

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.
@@ -1,5 +1,7 @@
1
1
  /**
2
- * Cloudflare KV implements the generic {@link KVNamespace} binding.
2
+ * Cloudflare KV can be used as a {@link KVNamespace} binding
3
+ * (`delete` is accepted as `del` by the host imports).
3
4
  */
4
- export { createMemoryKV, createKVImports } from "../../runtime/kv";
5
+ export { createKVImports } from "../../runtime/kv";
5
6
  export type { KVNamespace } from "../../runtime/kv";
7
+ export { get, put, del, list } from "../../runtime/kv/memory";
@@ -0,0 +1,26 @@
1
+ import type { WsState } from "../../runtime";
2
+ import type { KVNamespace } from "../../runtime/kv";
3
+ import type { Database } from "../../runtime/db";
4
+ type ConnState = WsState & {
5
+ topics: Set<string>;
6
+ };
7
+ /**
8
+ * Build a sticky long-lived fetch class for the host runtime.
9
+ *
10
+ * Prefer {@link stateful} so the handler reuses the app's module/kv/db.
11
+ *
12
+ * @internal
13
+ */
14
+ export declare function createStatefulFetch(module: WebAssembly.Module, options?: {
15
+ kv?: (env: any) => Record<string, KVNamespace>;
16
+ db?: (env: any) => Record<string, Database>;
17
+ imports?: (mem: () => WebAssembly.Memory) => WebAssembly.Imports;
18
+ }): {
19
+ new (state: any, env: any): {
20
+ readonly state: any;
21
+ readonly env: any;
22
+ readonly connections: Map<WebSocket, ConnState>;
23
+ fetch(request: Request): Promise<Response>;
24
+ };
25
+ };
26
+ export {};
@@ -1,3 +1,2 @@
1
1
  export { run, buildWsImports, attachWebSocket } from "../../runtime";
2
- export type { DurableObjectNamespace, WsState } from "../../runtime";
3
- export { createWebSocketDO } from "./do";
2
+ export type { StickyNamespace, WsState } from "../../runtime";
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @example
5
5
  * ```ts
6
- * import { Ziex } from "ziex/cloudflare";
6
+ * import { Ziex } from "ziex";
7
7
  * import { handle } from "ziex/vercel";
8
8
  * import module from "./app.wasm"; // or fetch at runtime
9
9
  *
@@ -1,11 +1,11 @@
1
1
  import type { WASI } from "./wasi";
2
- import { type KVNamespace } from "./kv";
2
+ import type { KVNamespace } from "./kv";
3
3
  import type { Database } from "./db";
4
- /** Minimal Durable Object namespace shape needed for WebSocket routing. */
5
- export type DurableObjectNamespace = {
4
+ /** Minimal sticky long-lived fetch namespace shape (e.g. Cloudflare Durable Object binding). */
5
+ export type StickyNamespace = {
6
6
  idFromName(name: string): unknown;
7
- get(id: unknown): {
8
- fetch(req: Request): Promise<Response>;
7
+ get(id: any): {
8
+ fetch(request: Request): Promise<Response>;
9
9
  };
10
10
  };
11
11
  export type WsState = {
@@ -21,6 +21,16 @@ export type WsState = {
21
21
  publish?: (topic: string, data: Uint8Array) => number;
22
22
  isSubscribed?: (topic: string) => boolean;
23
23
  };
24
+ type HttpState = {
25
+ committed: boolean;
26
+ ended: boolean;
27
+ status: number;
28
+ streaming: boolean;
29
+ headers: Headers;
30
+ bodyChunks: Uint8Array[];
31
+ streamWriter: WritableStreamDefaultWriter<Uint8Array> | null;
32
+ };
33
+ export declare function buildHttpImports(mem: () => WebAssembly.Memory, http: HttpState): WebAssembly.ModuleImports;
24
34
  /** Build the __zx_ws import object for a given connection state. */
25
35
  export declare function buildWsImports(Suspending: any, mem: () => WebAssembly.Memory, decoder: TextDecoder, ws: WsState): WebAssembly.ModuleImports;
26
36
  /** Create WebSocketPair, wire message/close listeners, flush pending writes. */
@@ -42,7 +52,7 @@ export declare function attachWebSocket(ws: WsState): {
42
52
  * });
43
53
  * ```
44
54
  */
45
- export declare function run({ request, env, ctx, module, kv: kvBindings, db: dbBindings, imports, wasi, websocket: doNamespace, }: {
55
+ export declare function run({ request, env, ctx, module, kv: kvBindings, db: dbBindings, imports, wasi, sticky, }: {
46
56
  request: Request;
47
57
  env?: unknown;
48
58
  ctx?: {
@@ -56,9 +66,9 @@ export declare function run({ request, env, ctx, module, kv: kvBindings, db: dbB
56
66
  imports?: (mem: () => WebAssembly.Memory) => WebAssembly.Imports;
57
67
  wasi?: WASI;
58
68
  /**
59
- * Durable Object namespace to use for WebSocket connections.
60
- * When provided, WebSocket upgrade requests are automatically forwarded to
61
- * the DO so that pub/sub works across multiple connected clients.
69
+ * Sticky namespace for long-lived fetch (WebSocket upgrades).
70
+ * When provided, upgrade requests are forwarded so pub/sub works across clients.
62
71
  */
63
- websocket?: DurableObjectNamespace;
72
+ sticky?: StickyNamespace;
64
73
  }): Promise<Response>;
74
+ export {};
@@ -1,7 +1,15 @@
1
- import type { KVNamespace } from "../kv";
2
- export type IndexedDbKVOptions = {
1
+ export type Options = {
3
2
  databaseName?: string;
4
3
  storeName?: string;
5
4
  namespace?: string;
6
5
  };
7
- export declare function createIndexedDbKV(options?: IndexedDbKVOptions): KVNamespace;
6
+ export declare function get(key: string): Promise<string | null>;
7
+ export declare function put(key: string, value: string): Promise<void>;
8
+ export declare function del(key: string): Promise<void>;
9
+ export declare function list(options?: {
10
+ prefix?: string;
11
+ }): Promise<{
12
+ keys: {
13
+ name: string;
14
+ }[];
15
+ }>;
@@ -1,6 +1,14 @@
1
- import type { SyncKVNamespace } from "../kv";
2
- export type LocalStorageKVOptions = {
1
+ export type Options = {
3
2
  namespace?: string;
4
3
  storagePrefix?: string;
5
4
  };
6
- export declare function createLocalStorageKV(options?: LocalStorageKVOptions): SyncKVNamespace;
5
+ export declare function get(key: string): string | null;
6
+ export declare function put(key: string, value: string): void;
7
+ export declare function del(key: string): void;
8
+ export declare function list(options?: {
9
+ prefix?: string;
10
+ }): {
11
+ keys: {
12
+ name: string;
13
+ }[];
14
+ };
@@ -1,6 +1,13 @@
1
- import type { KVNamespace } from "../kv";
2
- /**
3
- * In-memory KV. Used as the default shim on platforms that don't provide a
4
- * real KV binding (e.g. Vercel). Data lives only for the lifetime of the isolate.
5
- */
6
- export declare function createMemoryKV(): KVNamespace;
1
+ export declare function get(key: string): Promise<string | null>;
2
+ export declare function put(key: string, value: string, options?: {
3
+ expiration?: number;
4
+ expirationTtl?: number;
5
+ }): Promise<void>;
6
+ export declare function del(key: string): Promise<void>;
7
+ export declare function list(options?: {
8
+ prefix?: string;
9
+ }): Promise<{
10
+ keys: {
11
+ name: string;
12
+ }[];
13
+ }>;
package/runtime/kv.d.ts CHANGED
@@ -1,29 +1,32 @@
1
1
  export type { WasmAllocRef } from "../wasm/core";
2
- /** Key/value namespace binding. Cloudflare KV–shaped so CF bindings work as-is; other backends adapt to the same interface. */
2
+ export { createKVImports } from "./kv/extern";
3
+ import { type Options as IndexedDbOptions } from "./kv/indexdb";
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ /** Key/value namespace binding (get/put/del/list). */
3
6
  export interface KVNamespace {
4
- get(key: string): Promise<string | null>;
7
+ get(key: string): MaybePromise<string | null>;
5
8
  put(key: string, value: string, options?: {
6
9
  expiration?: number;
7
10
  expirationTtl?: number;
8
- }): Promise<void>;
9
- delete(key: string): Promise<void>;
11
+ }): MaybePromise<void>;
12
+ del(key: string): MaybePromise<void>;
10
13
  list(options?: {
11
14
  prefix?: string;
12
- }): Promise<{
15
+ }): MaybePromise<{
13
16
  keys: {
14
17
  name: string;
15
18
  }[];
16
19
  }>;
17
20
  }
18
- /** Synchronous KV used when JSPI is unavailable (e.g. localStorage). */
19
- export interface SyncKVNamespace extends KVNamespace {
20
- getSync(key: string): string | null;
21
- putSync(key: string, value: string, options?: {
21
+ /** Synchronous KV used when JSPI is unavailable (e.g. localStorage). Same method names, sync returns. */
22
+ export interface SyncKVNamespace {
23
+ get(key: string): string | null;
24
+ put(key: string, value: string, options?: {
22
25
  expiration?: number;
23
26
  expirationTtl?: number;
24
27
  }): void;
25
- deleteSync(key: string): void;
26
- listSync(options?: {
28
+ del(key: string): void;
29
+ list(options?: {
27
30
  prefix?: string;
28
31
  }): {
29
32
  keys: {
@@ -31,15 +34,10 @@ export interface SyncKVNamespace extends KVNamespace {
31
34
  }[];
32
35
  };
33
36
  }
34
- export { createMemoryKV } from "./kv/memory";
35
- export { createLocalStorageKV, type LocalStorageKVOptions } from "./kv/localstorage";
36
- export { createIndexedDbKV, type IndexedDbKVOptions } from "./kv/indexdb";
37
- export { createKVImports } from "./kv/extern";
38
- import { type IndexedDbKVOptions } from "./kv/indexdb";
39
- export type BrowserKVOptions = IndexedDbKVOptions & {
37
+ export type BrowserKVOptions = IndexedDbOptions & {
40
38
  storagePrefix?: string;
41
39
  forceLocalStorage?: boolean;
42
40
  };
43
- export declare function hasJSPI(): boolean;
41
+ export declare const hasJspi: boolean;
44
42
  /** Prefer IndexedDB when JSPI is available, otherwise localStorage. */
45
43
  export declare function createBrowserKVBindings(options?: BrowserKVOptions): Record<string, KVNamespace>;