@lunora/bindings 1.0.0-alpha.7 → 1.0.0-alpha.9
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/dist/analytics/index.d.mts +70 -70
- package/dist/analytics/index.d.ts +70 -70
- package/dist/images/index.d.mts +147 -147
- package/dist/images/index.d.ts +147 -147
- package/dist/kv/index.d.mts +89 -89
- package/dist/kv/index.d.ts +89 -89
- package/dist/pipelines/index.d.mts +24 -24
- package/dist/pipelines/index.d.ts +24 -24
- package/dist/r2sql/index.d.mts +120 -120
- package/dist/r2sql/index.d.ts +120 -120
- package/dist/vectors/index.d.mts +83 -83
- package/dist/vectors/index.d.ts +83 -83
- package/package.json +2 -2
package/dist/kv/index.d.mts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The value types Workers KV can store / return. Mirrors Cloudflare's
|
|
3
|
-
* `KVNamespace` `get`/`put` body unions; declared here so the package stays
|
|
4
|
-
* runtime-agnostic and the `*Like` interfaces don't pull in
|
|
5
|
-
* `@cloudflare/workers-types` at runtime.
|
|
6
|
-
*/
|
|
2
|
+
* The value types Workers KV can store / return. Mirrors Cloudflare's
|
|
3
|
+
* `KVNamespace` `get`/`put` body unions; declared here so the package stays
|
|
4
|
+
* runtime-agnostic and the `*Like` interfaces don't pull in
|
|
5
|
+
* `@cloudflare/workers-types` at runtime.
|
|
6
|
+
*/
|
|
7
7
|
type KvValue = ReadableStream | ArrayBuffer | ArrayBufferView | string;
|
|
8
8
|
/** How a raw KV read should decode the stored value. Mirrors KV's `type` option. */
|
|
9
9
|
type KvValueType = "text" | "json" | "arrayBuffer" | "stream";
|
|
10
10
|
/**
|
|
11
|
-
* Per-read options forwarded to the binding. `cacheTtl` is KV's edge-cache TTL
|
|
12
|
-
* (seconds, min 60); `type` selects the decode mode for {@link Kv.getRaw}.
|
|
13
|
-
*/
|
|
11
|
+
* Per-read options forwarded to the binding. `cacheTtl` is KV's edge-cache TTL
|
|
12
|
+
* (seconds, min 60); `type` selects the decode mode for {@link Kv.getRaw}.
|
|
13
|
+
*/
|
|
14
14
|
interface KvGetOptions {
|
|
15
15
|
/** KV edge-cache TTL in seconds (minimum 60). Forwarded verbatim. */
|
|
16
16
|
cacheTtl?: number;
|
|
@@ -18,23 +18,23 @@ interface KvGetOptions {
|
|
|
18
18
|
type?: KvValueType;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Minimal projection of Cloudflare's `KVNamespace`. Declared structurally so
|
|
22
|
-
* unit tests can pass a plain `Map`-backed double; the real binding satisfies
|
|
23
|
-
* the same shape. Mirrors `R2BucketLike` in `@lunora/storage`.
|
|
24
|
-
*/
|
|
21
|
+
* Minimal projection of Cloudflare's `KVNamespace`. Declared structurally so
|
|
22
|
+
* unit tests can pass a plain `Map`-backed double; the real binding satisfies
|
|
23
|
+
* the same shape. Mirrors `R2BucketLike` in `@lunora/storage`.
|
|
24
|
+
*/
|
|
25
25
|
interface KVNamespaceLike {
|
|
26
26
|
/** Delete a key. No-op if the key is absent. */
|
|
27
27
|
delete: (key: string) => Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* Read a value. The real binding overloads on `options.type`; declared here
|
|
30
|
+
* as the broad union so a structural double need only return the value (or
|
|
31
|
+
* `null` when absent).
|
|
32
|
+
*/
|
|
33
33
|
get: (key: string, options?: KvGetOptions | KvValueType) => Promise<unknown>;
|
|
34
34
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
* Read a value together with its associated metadata. Returns
|
|
36
|
+
* `{ value: null, metadata: null }` when the key is absent.
|
|
37
|
+
*/
|
|
38
38
|
getWithMetadata: (key: string, options?: KvGetOptions | KvValueType) => Promise<{
|
|
39
39
|
metadata: unknown;
|
|
40
40
|
value: unknown;
|
|
@@ -80,11 +80,11 @@ type KvNamespaceListResult<Metadata = unknown> = {
|
|
|
80
80
|
/** Construction options for the `createKv` factory. */
|
|
81
81
|
interface LunoraKvOptions {
|
|
82
82
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
* Optional per-instance key prefix applied to every operation (get/put/
|
|
84
|
+
* delete/list). Use for multi-tenant key namespacing — equivalent to
|
|
85
|
+
* calling the `scopeKey` helper on every key. Combined via `scopeKey`, so a
|
|
86
|
+
* `..` or NUL in the prefix is rejected.
|
|
87
|
+
*/
|
|
88
88
|
keyPrefix?: string;
|
|
89
89
|
/** The bound KV namespace (`env.<BINDING>`). */
|
|
90
90
|
namespace: KVNamespaceLike;
|
|
@@ -98,9 +98,9 @@ interface KvPutOptions {
|
|
|
98
98
|
/** Arbitrary metadata stored alongside the value (returned by `getWithMetadata`/`list`). */
|
|
99
99
|
metadata?: unknown;
|
|
100
100
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
* When true, write `value` to KV verbatim (no `JSON.stringify`). `value`
|
|
102
|
+
* must already be a KV-writable type (string/ArrayBuffer/stream).
|
|
103
|
+
*/
|
|
104
104
|
raw?: boolean;
|
|
105
105
|
}
|
|
106
106
|
/** Options for {@link Kv.list}. */
|
|
@@ -117,9 +117,9 @@ interface KvListResult<Metadata = unknown> {
|
|
|
117
117
|
/** Cursor for the next page; `undefined` when the listing is complete. */
|
|
118
118
|
cursor?: string;
|
|
119
119
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
* The key names, with any instance `keyPrefix` stripped back off so callers
|
|
121
|
+
* see the same keys they wrote.
|
|
122
|
+
*/
|
|
123
123
|
keys: KvListKey<Metadata>[];
|
|
124
124
|
/** True when this is the final page (no further `cursor`). */
|
|
125
125
|
listComplete: boolean;
|
|
@@ -132,46 +132,46 @@ interface KvValueWithMetadata<Value, Metadata> {
|
|
|
132
132
|
value: Value | null;
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
|
-
* The typed Workers KV client bound to `ctx.kv`. JSON-decodes/encodes by
|
|
136
|
-
* default; a raw escape hatch ({@link Kv.getRaw} / `put(..., { raw: true })`)
|
|
137
|
-
* handles text/binary/stream values.
|
|
138
|
-
*/
|
|
135
|
+
* The typed Workers KV client bound to `ctx.kv`. JSON-decodes/encodes by
|
|
136
|
+
* default; a raw escape hatch ({@link Kv.getRaw} / `put(..., { raw: true })`)
|
|
137
|
+
* handles text/binary/stream values.
|
|
138
|
+
*/
|
|
139
139
|
interface Kv {
|
|
140
140
|
/** Delete a key. No-op if absent. */
|
|
141
141
|
delete: (key: string) => Promise<void>;
|
|
142
142
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
* Read a key and `JSON.parse` it into `T`. Returns `null` when the key is
|
|
144
|
+
* absent. Throws if the stored value isn't valid JSON — use
|
|
145
|
+
* {@link Kv.getRaw} for non-JSON values.
|
|
146
|
+
*/
|
|
147
147
|
get: <T = unknown>(key: string, options?: {
|
|
148
148
|
cacheTtl?: number;
|
|
149
149
|
}) => Promise<T | null>;
|
|
150
150
|
/** Read a raw value with an explicit decode `type` (default `"text"`). Returns `null` when absent. */
|
|
151
151
|
getRaw: <T = string>(key: string, options?: KvGetOptions) => Promise<T | null>;
|
|
152
152
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
* Read a key's JSON value together with its metadata. Returns
|
|
154
|
+
* `{ value: null, metadata: null }` when the key is absent.
|
|
155
|
+
*/
|
|
156
156
|
getWithMetadata: <T = unknown, M = unknown>(key: string, options?: {
|
|
157
157
|
cacheTtl?: number;
|
|
158
158
|
}) => Promise<KvValueWithMetadata<T, M>>;
|
|
159
159
|
/** List keys (optionally `prefix`-filtered, paginated via `cursor`). */
|
|
160
160
|
list: <M = unknown>(options?: KvListOptions) => Promise<KvListResult<M>>;
|
|
161
161
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
* Write `value` to `key`. JSON-stringifies `value` unless `options.raw` is
|
|
163
|
+
* set (in which case `value` must be a KV-writable type). Forwards
|
|
164
|
+
* `expirationTtl`/`expiration`/`metadata` to the binding.
|
|
165
|
+
*/
|
|
166
166
|
put: <T = unknown>(key: string, value: T, options?: KvPutOptions) => Promise<void>;
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
-
* Compose a per-tenant key from a scope prefix and a caller-supplied key. Both
|
|
170
|
-
* halves are validated — the prefix may not contain `..` or NUL either, and the
|
|
171
|
-
* resulting key must stay under KV's length ceiling. Recommended for any
|
|
172
|
-
* multi-tenant deployment so client-supplied keys can't address peer data.
|
|
173
|
-
* Mirrors `scopeKey` from `@lunora/storage`.
|
|
174
|
-
*/
|
|
169
|
+
* Compose a per-tenant key from a scope prefix and a caller-supplied key. Both
|
|
170
|
+
* halves are validated — the prefix may not contain `..` or NUL either, and the
|
|
171
|
+
* resulting key must stay under KV's length ceiling. Recommended for any
|
|
172
|
+
* multi-tenant deployment so client-supplied keys can't address peer data.
|
|
173
|
+
* Mirrors `scopeKey` from `@lunora/storage`.
|
|
174
|
+
*/
|
|
175
175
|
declare const scopeKey: (prefix: string, key: string) => string;
|
|
176
176
|
declare const createKv: (options: LunoraKvOptions) => Kv;
|
|
177
177
|
/** One KV namespace as the studio's KV browser surfaces it (mirrors the runtime's KvNamespaceSummary). */
|
|
@@ -196,9 +196,9 @@ interface KvValueResultLike {
|
|
|
196
196
|
value: null | string;
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
|
-
* The structural shape of a KV introspector — mirrors `KvIntrospector` from
|
|
200
|
-
* `@lunora/runtime` without importing it, keeping the dependency graph clean.
|
|
201
|
-
*/
|
|
199
|
+
* The structural shape of a KV introspector — mirrors `KvIntrospector` from
|
|
200
|
+
* `@lunora/runtime` without importing it, keeping the dependency graph clean.
|
|
201
|
+
*/
|
|
202
202
|
interface KvIntrospectorLike {
|
|
203
203
|
deleteKey: (options: {
|
|
204
204
|
key: string;
|
|
@@ -227,45 +227,45 @@ interface KvIntrospectorLike {
|
|
|
227
227
|
/** Construction options for {@link createKvIntrospector}. */
|
|
228
228
|
interface CreateKvIntrospectorOptions {
|
|
229
229
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
* Map of binding name → bound KV namespace. Each entry becomes one
|
|
231
|
+
* namespace the studio can browse. Example:
|
|
232
|
+
* ```ts
|
|
233
|
+
* createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
236
|
namespaces: Record<string, KVNamespaceLike>;
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
239
|
-
* Build a `KvIntrospector`-compatible object from a map of bound KV namespaces.
|
|
240
|
-
* Pass the result as `kvIntrospector` on `WorkerOptions` to enable the studio's
|
|
241
|
-
* KV browser (`/_lunora/admin/kv/*` endpoints).
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* createWorker({
|
|
245
|
-
* // …
|
|
246
|
-
* kvIntrospector: createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } }),
|
|
247
|
-
* });
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
239
|
+
* Build a `KvIntrospector`-compatible object from a map of bound KV namespaces.
|
|
240
|
+
* Pass the result as `kvIntrospector` on `WorkerOptions` to enable the studio's
|
|
241
|
+
* KV browser (`/_lunora/admin/kv/*` endpoints).
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* createWorker({
|
|
245
|
+
* // …
|
|
246
|
+
* kvIntrospector: createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } }),
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
250
|
declare const createKvIntrospector: (options: CreateKvIntrospectorOptions) => KvIntrospectorLike;
|
|
251
251
|
/**
|
|
252
|
-
* Zero-config KV introspector: scan a worker `env` for every bound Workers KV
|
|
253
|
-
* namespace and register each under its binding name. Every `kv_namespaces` entry
|
|
254
|
-
* in `wrangler.jsonc` then appears in the studio's KV browser automatically — no
|
|
255
|
-
* hand-written `createKvIntrospector({ namespaces: … })` call, and any binding
|
|
256
|
-
* name (not just `KV`) and any number of namespaces light up. Non-KV bindings
|
|
257
|
-
* (R2, Durable Objects, queues, secrets, …) are skipped via {@link isKvNamespace}.
|
|
258
|
-
*
|
|
259
|
-
* Returns an introspector even when `env` holds no KV namespaces — its
|
|
260
|
-
* `listNamespaces()` resolves to `[]`, so the studio renders an empty state
|
|
261
|
-
* rather than a "not configured" error.
|
|
262
|
-
* @example
|
|
263
|
-
* ```ts
|
|
264
|
-
* createWorker({
|
|
265
|
-
* // …
|
|
266
|
-
* kvIntrospector: createKvIntrospectorFromEnv(env),
|
|
267
|
-
* });
|
|
268
|
-
* ```
|
|
269
|
-
*/
|
|
252
|
+
* Zero-config KV introspector: scan a worker `env` for every bound Workers KV
|
|
253
|
+
* namespace and register each under its binding name. Every `kv_namespaces` entry
|
|
254
|
+
* in `wrangler.jsonc` then appears in the studio's KV browser automatically — no
|
|
255
|
+
* hand-written `createKvIntrospector({ namespaces: … })` call, and any binding
|
|
256
|
+
* name (not just `KV`) and any number of namespaces light up. Non-KV bindings
|
|
257
|
+
* (R2, Durable Objects, queues, secrets, …) are skipped via {@link isKvNamespace}.
|
|
258
|
+
*
|
|
259
|
+
* Returns an introspector even when `env` holds no KV namespaces — its
|
|
260
|
+
* `listNamespaces()` resolves to `[]`, so the studio renders an empty state
|
|
261
|
+
* rather than a "not configured" error.
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* createWorker({
|
|
265
|
+
* // …
|
|
266
|
+
* kvIntrospector: createKvIntrospectorFromEnv(env),
|
|
267
|
+
* });
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
270
|
declare const createKvIntrospectorFromEnv: (env: unknown) => KvIntrospectorLike;
|
|
271
271
|
export { type CreateKvIntrospectorOptions, type KVNamespaceLike, type Kv, type KvGetOptions, type KvIntrospectorLike, type KvListKey, type KvListOptions, type KvListResult, type KvNamespaceListResult, type KvNamespacePutOptions, type KvPutOptions, type KvValue, type KvValueType, type KvValueWithMetadata, type LunoraKvOptions, createKv, createKvIntrospector, createKvIntrospectorFromEnv, scopeKey };
|
package/dist/kv/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The value types Workers KV can store / return. Mirrors Cloudflare's
|
|
3
|
-
* `KVNamespace` `get`/`put` body unions; declared here so the package stays
|
|
4
|
-
* runtime-agnostic and the `*Like` interfaces don't pull in
|
|
5
|
-
* `@cloudflare/workers-types` at runtime.
|
|
6
|
-
*/
|
|
2
|
+
* The value types Workers KV can store / return. Mirrors Cloudflare's
|
|
3
|
+
* `KVNamespace` `get`/`put` body unions; declared here so the package stays
|
|
4
|
+
* runtime-agnostic and the `*Like` interfaces don't pull in
|
|
5
|
+
* `@cloudflare/workers-types` at runtime.
|
|
6
|
+
*/
|
|
7
7
|
type KvValue = ReadableStream | ArrayBuffer | ArrayBufferView | string;
|
|
8
8
|
/** How a raw KV read should decode the stored value. Mirrors KV's `type` option. */
|
|
9
9
|
type KvValueType = "text" | "json" | "arrayBuffer" | "stream";
|
|
10
10
|
/**
|
|
11
|
-
* Per-read options forwarded to the binding. `cacheTtl` is KV's edge-cache TTL
|
|
12
|
-
* (seconds, min 60); `type` selects the decode mode for {@link Kv.getRaw}.
|
|
13
|
-
*/
|
|
11
|
+
* Per-read options forwarded to the binding. `cacheTtl` is KV's edge-cache TTL
|
|
12
|
+
* (seconds, min 60); `type` selects the decode mode for {@link Kv.getRaw}.
|
|
13
|
+
*/
|
|
14
14
|
interface KvGetOptions {
|
|
15
15
|
/** KV edge-cache TTL in seconds (minimum 60). Forwarded verbatim. */
|
|
16
16
|
cacheTtl?: number;
|
|
@@ -18,23 +18,23 @@ interface KvGetOptions {
|
|
|
18
18
|
type?: KvValueType;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Minimal projection of Cloudflare's `KVNamespace`. Declared structurally so
|
|
22
|
-
* unit tests can pass a plain `Map`-backed double; the real binding satisfies
|
|
23
|
-
* the same shape. Mirrors `R2BucketLike` in `@lunora/storage`.
|
|
24
|
-
*/
|
|
21
|
+
* Minimal projection of Cloudflare's `KVNamespace`. Declared structurally so
|
|
22
|
+
* unit tests can pass a plain `Map`-backed double; the real binding satisfies
|
|
23
|
+
* the same shape. Mirrors `R2BucketLike` in `@lunora/storage`.
|
|
24
|
+
*/
|
|
25
25
|
interface KVNamespaceLike {
|
|
26
26
|
/** Delete a key. No-op if the key is absent. */
|
|
27
27
|
delete: (key: string) => Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
* Read a value. The real binding overloads on `options.type`; declared here
|
|
30
|
+
* as the broad union so a structural double need only return the value (or
|
|
31
|
+
* `null` when absent).
|
|
32
|
+
*/
|
|
33
33
|
get: (key: string, options?: KvGetOptions | KvValueType) => Promise<unknown>;
|
|
34
34
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
* Read a value together with its associated metadata. Returns
|
|
36
|
+
* `{ value: null, metadata: null }` when the key is absent.
|
|
37
|
+
*/
|
|
38
38
|
getWithMetadata: (key: string, options?: KvGetOptions | KvValueType) => Promise<{
|
|
39
39
|
metadata: unknown;
|
|
40
40
|
value: unknown;
|
|
@@ -80,11 +80,11 @@ type KvNamespaceListResult<Metadata = unknown> = {
|
|
|
80
80
|
/** Construction options for the `createKv` factory. */
|
|
81
81
|
interface LunoraKvOptions {
|
|
82
82
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
* Optional per-instance key prefix applied to every operation (get/put/
|
|
84
|
+
* delete/list). Use for multi-tenant key namespacing — equivalent to
|
|
85
|
+
* calling the `scopeKey` helper on every key. Combined via `scopeKey`, so a
|
|
86
|
+
* `..` or NUL in the prefix is rejected.
|
|
87
|
+
*/
|
|
88
88
|
keyPrefix?: string;
|
|
89
89
|
/** The bound KV namespace (`env.<BINDING>`). */
|
|
90
90
|
namespace: KVNamespaceLike;
|
|
@@ -98,9 +98,9 @@ interface KvPutOptions {
|
|
|
98
98
|
/** Arbitrary metadata stored alongside the value (returned by `getWithMetadata`/`list`). */
|
|
99
99
|
metadata?: unknown;
|
|
100
100
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
* When true, write `value` to KV verbatim (no `JSON.stringify`). `value`
|
|
102
|
+
* must already be a KV-writable type (string/ArrayBuffer/stream).
|
|
103
|
+
*/
|
|
104
104
|
raw?: boolean;
|
|
105
105
|
}
|
|
106
106
|
/** Options for {@link Kv.list}. */
|
|
@@ -117,9 +117,9 @@ interface KvListResult<Metadata = unknown> {
|
|
|
117
117
|
/** Cursor for the next page; `undefined` when the listing is complete. */
|
|
118
118
|
cursor?: string;
|
|
119
119
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
* The key names, with any instance `keyPrefix` stripped back off so callers
|
|
121
|
+
* see the same keys they wrote.
|
|
122
|
+
*/
|
|
123
123
|
keys: KvListKey<Metadata>[];
|
|
124
124
|
/** True when this is the final page (no further `cursor`). */
|
|
125
125
|
listComplete: boolean;
|
|
@@ -132,46 +132,46 @@ interface KvValueWithMetadata<Value, Metadata> {
|
|
|
132
132
|
value: Value | null;
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
|
-
* The typed Workers KV client bound to `ctx.kv`. JSON-decodes/encodes by
|
|
136
|
-
* default; a raw escape hatch ({@link Kv.getRaw} / `put(..., { raw: true })`)
|
|
137
|
-
* handles text/binary/stream values.
|
|
138
|
-
*/
|
|
135
|
+
* The typed Workers KV client bound to `ctx.kv`. JSON-decodes/encodes by
|
|
136
|
+
* default; a raw escape hatch ({@link Kv.getRaw} / `put(..., { raw: true })`)
|
|
137
|
+
* handles text/binary/stream values.
|
|
138
|
+
*/
|
|
139
139
|
interface Kv {
|
|
140
140
|
/** Delete a key. No-op if absent. */
|
|
141
141
|
delete: (key: string) => Promise<void>;
|
|
142
142
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
* Read a key and `JSON.parse` it into `T`. Returns `null` when the key is
|
|
144
|
+
* absent. Throws if the stored value isn't valid JSON — use
|
|
145
|
+
* {@link Kv.getRaw} for non-JSON values.
|
|
146
|
+
*/
|
|
147
147
|
get: <T = unknown>(key: string, options?: {
|
|
148
148
|
cacheTtl?: number;
|
|
149
149
|
}) => Promise<T | null>;
|
|
150
150
|
/** Read a raw value with an explicit decode `type` (default `"text"`). Returns `null` when absent. */
|
|
151
151
|
getRaw: <T = string>(key: string, options?: KvGetOptions) => Promise<T | null>;
|
|
152
152
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
* Read a key's JSON value together with its metadata. Returns
|
|
154
|
+
* `{ value: null, metadata: null }` when the key is absent.
|
|
155
|
+
*/
|
|
156
156
|
getWithMetadata: <T = unknown, M = unknown>(key: string, options?: {
|
|
157
157
|
cacheTtl?: number;
|
|
158
158
|
}) => Promise<KvValueWithMetadata<T, M>>;
|
|
159
159
|
/** List keys (optionally `prefix`-filtered, paginated via `cursor`). */
|
|
160
160
|
list: <M = unknown>(options?: KvListOptions) => Promise<KvListResult<M>>;
|
|
161
161
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
* Write `value` to `key`. JSON-stringifies `value` unless `options.raw` is
|
|
163
|
+
* set (in which case `value` must be a KV-writable type). Forwards
|
|
164
|
+
* `expirationTtl`/`expiration`/`metadata` to the binding.
|
|
165
|
+
*/
|
|
166
166
|
put: <T = unknown>(key: string, value: T, options?: KvPutOptions) => Promise<void>;
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
|
-
* Compose a per-tenant key from a scope prefix and a caller-supplied key. Both
|
|
170
|
-
* halves are validated — the prefix may not contain `..` or NUL either, and the
|
|
171
|
-
* resulting key must stay under KV's length ceiling. Recommended for any
|
|
172
|
-
* multi-tenant deployment so client-supplied keys can't address peer data.
|
|
173
|
-
* Mirrors `scopeKey` from `@lunora/storage`.
|
|
174
|
-
*/
|
|
169
|
+
* Compose a per-tenant key from a scope prefix and a caller-supplied key. Both
|
|
170
|
+
* halves are validated — the prefix may not contain `..` or NUL either, and the
|
|
171
|
+
* resulting key must stay under KV's length ceiling. Recommended for any
|
|
172
|
+
* multi-tenant deployment so client-supplied keys can't address peer data.
|
|
173
|
+
* Mirrors `scopeKey` from `@lunora/storage`.
|
|
174
|
+
*/
|
|
175
175
|
declare const scopeKey: (prefix: string, key: string) => string;
|
|
176
176
|
declare const createKv: (options: LunoraKvOptions) => Kv;
|
|
177
177
|
/** One KV namespace as the studio's KV browser surfaces it (mirrors the runtime's KvNamespaceSummary). */
|
|
@@ -196,9 +196,9 @@ interface KvValueResultLike {
|
|
|
196
196
|
value: null | string;
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
199
|
-
* The structural shape of a KV introspector — mirrors `KvIntrospector` from
|
|
200
|
-
* `@lunora/runtime` without importing it, keeping the dependency graph clean.
|
|
201
|
-
*/
|
|
199
|
+
* The structural shape of a KV introspector — mirrors `KvIntrospector` from
|
|
200
|
+
* `@lunora/runtime` without importing it, keeping the dependency graph clean.
|
|
201
|
+
*/
|
|
202
202
|
interface KvIntrospectorLike {
|
|
203
203
|
deleteKey: (options: {
|
|
204
204
|
key: string;
|
|
@@ -227,45 +227,45 @@ interface KvIntrospectorLike {
|
|
|
227
227
|
/** Construction options for {@link createKvIntrospector}. */
|
|
228
228
|
interface CreateKvIntrospectorOptions {
|
|
229
229
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
* Map of binding name → bound KV namespace. Each entry becomes one
|
|
231
|
+
* namespace the studio can browse. Example:
|
|
232
|
+
* ```ts
|
|
233
|
+
* createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
236
|
namespaces: Record<string, KVNamespaceLike>;
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
239
|
-
* Build a `KvIntrospector`-compatible object from a map of bound KV namespaces.
|
|
240
|
-
* Pass the result as `kvIntrospector` on `WorkerOptions` to enable the studio's
|
|
241
|
-
* KV browser (`/_lunora/admin/kv/*` endpoints).
|
|
242
|
-
* @example
|
|
243
|
-
* ```ts
|
|
244
|
-
* createWorker({
|
|
245
|
-
* // …
|
|
246
|
-
* kvIntrospector: createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } }),
|
|
247
|
-
* });
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
239
|
+
* Build a `KvIntrospector`-compatible object from a map of bound KV namespaces.
|
|
240
|
+
* Pass the result as `kvIntrospector` on `WorkerOptions` to enable the studio's
|
|
241
|
+
* KV browser (`/_lunora/admin/kv/*` endpoints).
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* createWorker({
|
|
245
|
+
* // …
|
|
246
|
+
* kvIntrospector: createKvIntrospector({ namespaces: { MY_KV: env.MY_KV } }),
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
250
|
declare const createKvIntrospector: (options: CreateKvIntrospectorOptions) => KvIntrospectorLike;
|
|
251
251
|
/**
|
|
252
|
-
* Zero-config KV introspector: scan a worker `env` for every bound Workers KV
|
|
253
|
-
* namespace and register each under its binding name. Every `kv_namespaces` entry
|
|
254
|
-
* in `wrangler.jsonc` then appears in the studio's KV browser automatically — no
|
|
255
|
-
* hand-written `createKvIntrospector({ namespaces: … })` call, and any binding
|
|
256
|
-
* name (not just `KV`) and any number of namespaces light up. Non-KV bindings
|
|
257
|
-
* (R2, Durable Objects, queues, secrets, …) are skipped via {@link isKvNamespace}.
|
|
258
|
-
*
|
|
259
|
-
* Returns an introspector even when `env` holds no KV namespaces — its
|
|
260
|
-
* `listNamespaces()` resolves to `[]`, so the studio renders an empty state
|
|
261
|
-
* rather than a "not configured" error.
|
|
262
|
-
* @example
|
|
263
|
-
* ```ts
|
|
264
|
-
* createWorker({
|
|
265
|
-
* // …
|
|
266
|
-
* kvIntrospector: createKvIntrospectorFromEnv(env),
|
|
267
|
-
* });
|
|
268
|
-
* ```
|
|
269
|
-
*/
|
|
252
|
+
* Zero-config KV introspector: scan a worker `env` for every bound Workers KV
|
|
253
|
+
* namespace and register each under its binding name. Every `kv_namespaces` entry
|
|
254
|
+
* in `wrangler.jsonc` then appears in the studio's KV browser automatically — no
|
|
255
|
+
* hand-written `createKvIntrospector({ namespaces: … })` call, and any binding
|
|
256
|
+
* name (not just `KV`) and any number of namespaces light up. Non-KV bindings
|
|
257
|
+
* (R2, Durable Objects, queues, secrets, …) are skipped via {@link isKvNamespace}.
|
|
258
|
+
*
|
|
259
|
+
* Returns an introspector even when `env` holds no KV namespaces — its
|
|
260
|
+
* `listNamespaces()` resolves to `[]`, so the studio renders an empty state
|
|
261
|
+
* rather than a "not configured" error.
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* createWorker({
|
|
265
|
+
* // …
|
|
266
|
+
* kvIntrospector: createKvIntrospectorFromEnv(env),
|
|
267
|
+
* });
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
270
|
declare const createKvIntrospectorFromEnv: (env: unknown) => KvIntrospectorLike;
|
|
271
271
|
export { type CreateKvIntrospectorOptions, type KVNamespaceLike, type Kv, type KvGetOptions, type KvIntrospectorLike, type KvListKey, type KvListOptions, type KvListResult, type KvNamespaceListResult, type KvNamespacePutOptions, type KvPutOptions, type KvValue, type KvValueType, type KvValueWithMetadata, type LunoraKvOptions, createKv, createKvIntrospector, createKvIntrospectorFromEnv, scopeKey };
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Structural types for the Cloudflare Pipelines write path (R2-backed streaming
|
|
3
|
-
* ingestion). Pipelines is the other "emit data to a sink" surface alongside
|
|
4
|
-
* Analytics Engine — telemetry/events out, no in-handler read-back. The binding
|
|
5
|
-
* is mirrored structurally (`*Like`) so a plain-object fake satisfies it in unit
|
|
6
|
-
* tests, like `@lunora/bindings/analytics`'s `AnalyticsEngineDatasetLike`.
|
|
7
|
-
*/
|
|
2
|
+
* Structural types for the Cloudflare Pipelines write path (R2-backed streaming
|
|
3
|
+
* ingestion). Pipelines is the other "emit data to a sink" surface alongside
|
|
4
|
+
* Analytics Engine — telemetry/events out, no in-handler read-back. The binding
|
|
5
|
+
* is mirrored structurally (`*Like`) so a plain-object fake satisfies it in unit
|
|
6
|
+
* tests, like `@lunora/bindings/analytics`'s `AnalyticsEngineDatasetLike`.
|
|
7
|
+
*/
|
|
8
8
|
/** One Pipelines record — a JSON object matching the stream's schema. */
|
|
9
9
|
type PipelineRecord = Record<string, unknown>;
|
|
10
10
|
/**
|
|
11
|
-
* Minimal structural projection of workers-types' `Pipeline<T>` binding. The
|
|
12
|
-
* real binding's `send` takes an array of records and resolves once accepted.
|
|
13
|
-
*/
|
|
11
|
+
* Minimal structural projection of workers-types' `Pipeline<T>` binding. The
|
|
12
|
+
* real binding's `send` takes an array of records and resolves once accepted.
|
|
13
|
+
*/
|
|
14
14
|
interface PipelineBindingLike<T extends PipelineRecord = PipelineRecord> {
|
|
15
15
|
send: (records: T[]) => Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* The write-side client bound to `ctx.pipelines` (the generated context imports
|
|
19
|
-
* this exact type as `import("@lunora/bindings/pipelines").PipelineClient`).
|
|
20
|
-
* Ingestion is durable, batched, and fire-and-forget — never read a record back
|
|
21
|
-
* in-handler.
|
|
22
|
-
*/
|
|
18
|
+
* The write-side client bound to `ctx.pipelines` (the generated context imports
|
|
19
|
+
* this exact type as `import("@lunora/bindings/pipelines").PipelineClient`).
|
|
20
|
+
* Ingestion is durable, batched, and fire-and-forget — never read a record back
|
|
21
|
+
* in-handler.
|
|
22
|
+
*/
|
|
23
23
|
interface PipelineClient<T extends PipelineRecord = PipelineRecord> {
|
|
24
24
|
/** Ingest one record or an array of records into the R2-backed sink. */
|
|
25
25
|
send: (records: T | T[]) => Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Wrap a Cloudflare Pipelines binding in the write-side {@link PipelineClient}
|
|
29
|
-
* bound to `ctx.pipelines`. The binding is `env.PIPELINES` (the `pipelines`
|
|
30
|
-
* binding the config layer recognizes; the remote pipeline name is minted with
|
|
31
|
-
* `wrangler pipelines create`).
|
|
32
|
-
*
|
|
33
|
-
* Ingestion is durable and batched: `send` accepts one record or an array and
|
|
34
|
-
* resolves once Cloudflare has accepted them for delivery to the R2-backed sink.
|
|
35
|
-
* There is no in-handler read-back — this is a fire-and-forget egress path, so
|
|
36
|
-
* it belongs on ActionCtx only (external I/O), mirroring `ctx.images`.
|
|
37
|
-
*/
|
|
28
|
+
* Wrap a Cloudflare Pipelines binding in the write-side {@link PipelineClient}
|
|
29
|
+
* bound to `ctx.pipelines`. The binding is `env.PIPELINES` (the `pipelines`
|
|
30
|
+
* binding the config layer recognizes; the remote pipeline name is minted with
|
|
31
|
+
* `wrangler pipelines create`).
|
|
32
|
+
*
|
|
33
|
+
* Ingestion is durable and batched: `send` accepts one record or an array and
|
|
34
|
+
* resolves once Cloudflare has accepted them for delivery to the R2-backed sink.
|
|
35
|
+
* There is no in-handler read-back — this is a fire-and-forget egress path, so
|
|
36
|
+
* it belongs on ActionCtx only (external I/O), mirroring `ctx.images`.
|
|
37
|
+
*/
|
|
38
38
|
declare const createPipelines: <T extends PipelineRecord = PipelineRecord>(options: {
|
|
39
39
|
binding: PipelineBindingLike<T>;
|
|
40
40
|
}) => PipelineClient<T>;
|