@tinycloud/sdk-services 3.2.0-beta.2 → 3.2.0-beta.3

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/dist/{BaseService-DWbPbov7.d.cts → BaseService-BDQXjWMx.d.cts} +1 -1
  2. package/dist/{BaseService-B_UKhVht.d.ts → BaseService-Di_hVfUV.d.ts} +1 -1
  3. package/dist/encryption/index.cjs +7 -1
  4. package/dist/encryption/index.cjs.map +1 -1
  5. package/dist/encryption/index.d.cts +2 -2
  6. package/dist/encryption/index.d.ts +2 -2
  7. package/dist/encryption/index.js +7 -1
  8. package/dist/encryption/index.js.map +1 -1
  9. package/dist/index.cjs +595 -353
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +36 -26
  12. package/dist/index.d.ts +36 -26
  13. package/dist/index.js +590 -353
  14. package/dist/index.js.map +1 -1
  15. package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
  16. package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
  17. package/dist/kv/index.cjs +530 -334
  18. package/dist/kv/index.cjs.map +1 -1
  19. package/dist/kv/index.d.cts +17 -468
  20. package/dist/kv/index.d.ts +17 -468
  21. package/dist/kv/index.js +524 -333
  22. package/dist/kv/index.js.map +1 -1
  23. package/dist/kv/replication/index.cjs +1375 -0
  24. package/dist/kv/replication/index.cjs.map +1 -0
  25. package/dist/kv/replication/index.d.cts +9 -0
  26. package/dist/kv/replication/index.d.ts +9 -0
  27. package/dist/kv/replication/index.js +1342 -0
  28. package/dist/kv/replication/index.js.map +1 -0
  29. package/dist/scope-BmLxwyl-.d.ts +957 -0
  30. package/dist/scope-D855kRDx.d.cts +957 -0
  31. package/dist/sql/index.cjs +12 -6
  32. package/dist/sql/index.cjs.map +1 -1
  33. package/dist/sql/index.d.cts +2 -2
  34. package/dist/sql/index.d.ts +2 -2
  35. package/dist/sql/index.js +12 -6
  36. package/dist/sql/index.js.map +1 -1
  37. package/dist/{types-CVwwxqXF.d.cts → types-7A5rHWRY.d.cts} +10 -1
  38. package/dist/{types-CVwwxqXF.d.ts → types-7A5rHWRY.d.ts} +10 -1
  39. package/package.json +18 -1
@@ -1,470 +1,7 @@
1
- import { B as BaseService } from '../BaseService-B_UKhVht.js';
2
- import { R as Result, I as IService } from '../types-CVwwxqXF.js';
3
-
4
- /**
5
- * KV Service Types
6
- *
7
- * Type definitions for the KV (Key-Value) service operations.
8
- */
9
-
10
- /**
11
- * Configuration for KVService.
12
- */
13
- interface KVServiceConfig {
14
- /**
15
- * Default prefix for all keys.
16
- * Useful for namespacing data within a space.
17
- *
18
- * @example
19
- * ```typescript
20
- * const kv = new KVService({ prefix: 'myapp/settings' });
21
- * await kv.put('theme', 'dark'); // Stores at 'myapp/settings/theme'
22
- * ```
23
- */
24
- prefix?: string;
25
- /**
26
- * Default timeout in milliseconds for each KV request, including reading
27
- * the response body. When it elapses the request is aborted and the
28
- * operation returns an `ErrorCodes.TIMEOUT` error. A per-call `timeout`
29
- * option overrides it. Unset (the default), `0`, or `Infinity` means no
30
- * timeout.
31
- */
32
- timeout?: number;
33
- /** Allow additional config properties */
34
- [key: string]: unknown;
35
- }
36
- /**
37
- * Options for KV get operations.
38
- */
39
- interface KVGetOptions {
40
- /**
41
- * Override the default prefix for this operation.
42
- */
43
- prefix?: string;
44
- /**
45
- * Return raw response instead of parsed JSON.
46
- * When true, data will be the raw response text.
47
- */
48
- raw?: boolean;
49
- /**
50
- * Return the raw response bytes as a Uint8Array instead of parsed/text data.
51
- * Use this to read back binary values (e.g. images) byte-identically. Takes
52
- * precedence over {@link raw}.
53
- */
54
- binary?: boolean;
55
- /**
56
- * Ask the node to reject the response when the stored value exceeds this
57
- * number of bytes. This bounds downloads before the response body is read.
58
- */
59
- maxResponseBytes?: number;
60
- /**
61
- * Custom timeout for this operation in milliseconds. Overrides
62
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
63
- */
64
- timeout?: number;
65
- /**
66
- * Custom abort signal for this operation.
67
- */
68
- signal?: AbortSignal;
69
- }
70
- /**
71
- * Options for KV put operations.
72
- */
73
- interface KVPutOptions {
74
- /**
75
- * Override the default prefix for this operation.
76
- */
77
- prefix?: string;
78
- /**
79
- * Content type for the value.
80
- * Defaults to 'application/json' for objects.
81
- */
82
- contentType?: string;
83
- /**
84
- * Custom metadata headers to store with the value.
85
- */
86
- metadata?: Record<string, string>;
87
- /** Only write when the current object has this strong ETag. */
88
- ifMatch?: string;
89
- /** Only write when the key does not exist. */
90
- ifNoneMatch?: "*";
91
- /**
92
- * Custom timeout for this operation in milliseconds. Overrides
93
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
94
- */
95
- timeout?: number;
96
- /**
97
- * Custom abort signal for this operation.
98
- */
99
- signal?: AbortSignal;
100
- }
101
- /**
102
- * One entry in a KV batch put request.
103
- */
104
- interface KVBatchPutItem {
105
- /**
106
- * The key to store under.
107
- */
108
- key: string;
109
- /**
110
- * The value to store.
111
- *
112
- * Objects are JSON stringified. Strings are stored as text. Binary values
113
- * should be supplied as Blob, ArrayBuffer, or Uint8Array.
114
- */
115
- value: unknown;
116
- /**
117
- * Content type for this item. Defaults to application/json for objects and
118
- * application/octet-stream for binary values.
119
- */
120
- contentType?: string;
121
- }
122
- /**
123
- * Options for KV batch put operations.
124
- */
125
- interface KVBatchPutOptions {
126
- /**
127
- * Override the default prefix for all entries in this batch.
128
- */
129
- prefix?: string;
130
- /**
131
- * Custom timeout for this operation in milliseconds. Overrides
132
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
133
- */
134
- timeout?: number;
135
- /**
136
- * Custom abort signal for this operation.
137
- */
138
- signal?: AbortSignal;
139
- }
140
- /**
141
- * Response from KV batch put operations.
142
- */
143
- interface KVBatchPutResponse {
144
- /**
145
- * Keys successfully written by the batch.
146
- */
147
- written: string[];
148
- /**
149
- * Number of written keys.
150
- */
151
- count: number;
152
- }
153
- /**
154
- * Response from a KV batch read. Transport or authorization failures are
155
- * returned by the outer Result; each requested key has its own Result so a
156
- * missing key does not discard successful siblings.
157
- */
158
- interface KVBatchReadResponse<T = unknown> {
159
- results: Array<{
160
- key: string;
161
- result: Result<KVResponse<T>>;
162
- }>;
163
- count: number;
164
- }
165
- /**
166
- * Options for KV list operations.
167
- */
168
- interface KVListOptions {
169
- /**
170
- * Override the default prefix for this operation.
171
- */
172
- prefix?: string;
173
- /**
174
- * Additional path to append to the prefix.
175
- */
176
- path?: string;
177
- /**
178
- * Whether to remove the prefix from returned keys.
179
- * When true, keys are returned relative to the prefix.
180
- */
181
- removePrefix?: boolean;
182
- /**
183
- * Return raw response instead of parsed JSON.
184
- */
185
- raw?: boolean;
186
- /** Maximum number of keys the node may return. */
187
- limit?: number;
188
- /** Opaque scope-bound cursor returned by a previous bounded list. */
189
- cursor?: string;
190
- /**
191
- * Custom timeout for this operation in milliseconds. Overrides
192
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
193
- */
194
- timeout?: number;
195
- /**
196
- * Custom abort signal for this operation.
197
- */
198
- signal?: AbortSignal;
199
- }
200
- /**
201
- * Options for KV delete operations.
202
- */
203
- interface KVDeleteOptions {
204
- /**
205
- * Override the default prefix for this operation.
206
- */
207
- prefix?: string;
208
- /** Only delete when the current object has this strong ETag. */
209
- ifMatch?: string;
210
- /**
211
- * Custom timeout for this operation in milliseconds. Overrides
212
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
213
- */
214
- timeout?: number;
215
- /**
216
- * Custom abort signal for this operation.
217
- */
218
- signal?: AbortSignal;
219
- }
220
- /**
221
- * Options for KV head (metadata) operations.
222
- */
223
- interface KVHeadOptions {
224
- /**
225
- * Override the default prefix for this operation.
226
- */
227
- prefix?: string;
228
- /**
229
- * Custom timeout for this operation in milliseconds. Overrides
230
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
231
- */
232
- timeout?: number;
233
- /**
234
- * Custom abort signal for this operation.
235
- */
236
- signal?: AbortSignal;
237
- }
238
- /**
239
- * Default lifetime for signed KV read URLs when a caller omits expiresInSeconds.
240
- * SDK duration defaults are stored in milliseconds; createSignedReadUrl converts
241
- * this to the node endpoint's ttl_seconds field.
242
- *
243
- * Keep this in sync with EXPIRY.SIGNED_READ_URL_MS in @tinycloud/sdk-core.
244
- * sdk-services cannot import sdk-core because sdk-core depends on sdk-services.
245
- */
246
- declare const DEFAULT_SIGNED_READ_URL_EXPIRY_MS: number;
247
- /**
248
- * Options for creating a signed KV read URL.
249
- */
250
- interface KVCreateSignedReadUrlOptions {
251
- /**
252
- * Override the default prefix for this operation.
253
- */
254
- prefix?: string;
255
- /**
256
- * Requested URL lifetime in seconds.
257
- * Defaults to {@link DEFAULT_SIGNED_READ_URL_EXPIRY_MS} converted to seconds.
258
- * The node may cap this by its configured maximum, the invocation expiry,
259
- * or the parent delegation expiry.
260
- */
261
- expiresInSeconds?: number;
262
- /**
263
- * Optional blake3 content hash to bind the signed URL to a specific object.
264
- */
265
- contentHash?: string;
266
- /**
267
- * Optional ETag to bind the signed URL to a specific object version.
268
- */
269
- etag?: string;
270
- /**
271
- * Custom timeout for this operation in milliseconds. Overrides
272
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
273
- */
274
- timeout?: number;
275
- /**
276
- * Custom abort signal for this operation.
277
- */
278
- signal?: AbortSignal;
279
- }
280
- /**
281
- * Response headers from KV operations.
282
- */
283
- interface KVResponseHeaders {
284
- /**
285
- * ETag for conditional requests.
286
- */
287
- etag?: string;
288
- /**
289
- * Content type of the stored value.
290
- */
291
- contentType?: string;
292
- /**
293
- * Last modification timestamp.
294
- */
295
- lastModified?: string;
296
- /**
297
- * Content length in bytes.
298
- */
299
- contentLength?: number;
300
- /**
301
- * Get a header value by name.
302
- * @param name - Header name (case-insensitive)
303
- */
304
- get(name: string): string | null;
305
- }
306
- /**
307
- * Response from KV get/put operations.
308
- *
309
- * @template T - Type of the data payload
310
- */
311
- interface KVResponse<T = unknown> {
312
- /**
313
- * The data payload.
314
- * For get: the stored value.
315
- * For put: undefined.
316
- */
317
- data: T;
318
- /**
319
- * Response headers with metadata.
320
- */
321
- headers: KVResponseHeaders;
322
- }
323
- /**
324
- * Response from KV list operations.
325
- */
326
- interface KVListResponse {
327
- /**
328
- * Array of keys matching the list criteria.
329
- */
330
- keys: string[];
331
- /** True when more matching keys exist than the requested limit. */
332
- truncated?: boolean;
333
- /** Opaque cursor for the next page, when the node returned one. */
334
- nextCursor?: string;
335
- }
336
- /**
337
- * Options for {@link IKVService.changes}, the `tinycloud.kv/sync` change feed.
338
- */
339
- interface KVChangesOptions {
340
- /**
341
- * The space-relative KV prefix to follow, sent as the invocation path. It
342
- * is not joined with the service's configured prefix, and must be non-empty.
343
- * Prefixes match whole path segments: `notes` covers `notes` and
344
- * `notes/a`, while `notes/` covers everything under `notes/` but not
345
- * `notes` itself. The session must hold `tinycloud.kv/sync` on it by name.
346
- *
347
- * Returned `changes[].key` values are full paths in the space, like this
348
- * prefix. On a service with a configured prefix (for example
349
- * `DelegatedAccess.kv`, whose prefix is the delegation path), `get` joins
350
- * that prefix again, so strip it from the key first, or follow the feed
351
- * with `kv.withPrefix(...).changes()`, which returns relative keys.
352
- */
353
- prefix: string;
354
- /**
355
- * The `cursor` from the previous page. Omit it to bootstrap from the start
356
- * of the prefix. Opaque; never parse or build one.
357
- */
358
- cursor?: string;
359
- /**
360
- * Page size, 1 through 1000 (node default 500). A page never splits one
361
- * invocation's changes, so it can hold more than `limit` changes.
362
- */
363
- limit?: number;
364
- /**
365
- * CID of a never-invoked delegation carrying `tinycloud.kv/retain` on the
366
- * prefix. When valid, the node attests `authority.retainUntil`.
367
- */
368
- retentionGrant?: string;
369
- /**
370
- * Custom timeout for this operation in milliseconds. Overrides
371
- * `KVServiceConfig.timeout`; `0` disables a configured timeout.
372
- */
373
- timeout?: number;
374
- /**
375
- * Custom abort signal for this operation.
376
- */
377
- signal?: AbortSignal;
378
- }
379
- /**
380
- * One key's latest state in a change feed page. Content is not included:
381
- * read it with `get`/`batchGet` and check it against `etag`.
382
- */
383
- type KVChange = {
384
- key: string;
385
- deleted: false;
386
- /** The strong ETag `get` returns for this state. */
387
- etag: string;
388
- metadata: Record<string, string>;
389
- } | {
390
- key: string;
391
- deleted: true;
392
- };
393
- /**
394
- * The node-attested window in which the caller's authority holds. Values are
395
- * RFC 3339 timestamps, or `null` when nothing in the chain sets one.
396
- */
397
- interface KVChangesAuthority {
398
- /** The latest `nbf` across the invocation's whole delegation chain. */
399
- notBefore: string | null;
400
- /** The earliest `exp` across the invocation's whole delegation chain. */
401
- expiresAt: string | null;
402
- /**
403
- * The earliest `exp` across a valid retention grant's own chain. `null`
404
- * means no retention: none was presented, or its chain sets no expiry.
405
- */
406
- retainUntil: string | null;
407
- }
408
- /**
409
- * One page of the `tinycloud.kv/sync` change feed.
410
- */
411
- interface KVChangesResponse {
412
- /** Each changed key's latest state, in commit order. */
413
- changes: KVChange[];
414
- /**
415
- * More changes are available now. A page may be empty with `more: true`;
416
- * keep paging with the returned cursor.
417
- */
418
- more: boolean;
419
- /**
420
- * The cursor for the next request. An empty poll returns the request's
421
- * cursor unchanged.
422
- */
423
- cursor: string;
424
- /** The node, space and prefix that served the page. */
425
- source: {
426
- nodeDid: string;
427
- space: string;
428
- prefix: string;
429
- };
430
- authority: KVChangesAuthority;
431
- }
432
- /**
433
- * Response from signed KV read URL creation.
434
- */
435
- interface KVSignedReadUrlResponse {
436
- /**
437
- * Absolute URL suitable for passing to external readers.
438
- */
439
- url: string;
440
- /**
441
- * Opaque URL returned by tinycloud-node, usually relative to the node host.
442
- */
443
- relativeUrl: string;
444
- /**
445
- * Opaque signed KV ticket identifier.
446
- */
447
- ticketId: string;
448
- /**
449
- * Expiry timestamp as returned by tinycloud-node.
450
- */
451
- expiresAt: string;
452
- }
453
- /**
454
- * KV service action types.
455
- */
456
- declare const KVAction: {
457
- readonly GET: "tinycloud.kv/get";
458
- readonly PUT: "tinycloud.kv/put";
459
- readonly LIST: "tinycloud.kv/list";
460
- readonly DELETE: "tinycloud.kv/del";
461
- readonly HEAD: "tinycloud.kv/metadata";
462
- /** The change feed; never implied by `*` or `tinycloud.kv/*`. */
463
- readonly SYNC: "tinycloud.kv/sync";
464
- /** Retention attestation; presented through `retentionGrant`, never invoked or implied. */
465
- readonly RETAIN: "tinycloud.kv/retain";
466
- };
467
- type KVActionType = (typeof KVAction)[keyof typeof KVAction];
1
+ import { B as BaseService } from '../BaseService-Di_hVfUV.js';
2
+ import { R as Result, I as IService } from '../types-7A5rHWRY.js';
3
+ import { Z as KVGetOptions, a2 as KVResponse, S as KVBatchReadResponse, a1 as KVPutOptions, N as KVBatchPutItem, O as KVBatchPutOptions, Q as KVBatchPutResponse, $ as KVListOptions, a0 as KVListResponse, V as KVChangesOptions, W as KVChangesResponse, Y as KVDeleteOptions, _ as KVHeadOptions, X as KVCreateSignedReadUrlOptions, a5 as KVSignedReadUrlResponse, a4 as KVServiceConfig, c as KVReadThrough } from '../scope-BmLxwyl-.js';
4
+ export { A as AuthorityRefusal, C as CLEAR_PENDING_WARNING, I as DEFAULT_SIGNED_READ_URL_EXPIRY_MS, J as KVAction, M as KVActionType, T as KVChange, U as KVChangesAuthority, b as KVListPage, d as KVReplicaHandle, e as KVReplicaSpec, f as KVReplicaStorage, a as KVReplicationController, K as KVReplicationDeps, a3 as KVResponseHeaders, L as LocalGetResult, g as LocalListResult, h as LocalReadMeta, i as LocalReplicaStatus, j as LocalSyncResult, k as PendingWriteRecord, l as PendingWriteState, P as PendingWriteStore, m as PinnedKey, n as PurgeTarget, o as ReplicaAuthorityState, p as ReplicaCoverage, q as ReplicaDevice, r as ReplicaGrantInfo, s as ReplicaState, t as ReplicaStatusEntry, u as ReplicationAuthority, v as ReplicationControl, w as ReplicationEvent, R as ReplicationIdentity, x as ReplicationOptions, y as ReplicationPurgeReport, z as ReplicationReason, B as ReplicationScheduler, D as ResolvedReplicationOptions, E as canonicalReplicationIdentity, F as kvPrefixCovers, G as replicationIdentityKey, H as requiresSecretsOptIn } from '../scope-BmLxwyl-.js';
468
5
 
469
6
  /**
470
7
  * PrefixedKVService - A prefix-scoped view of KVService.
@@ -1006,6 +543,10 @@ declare class KVService extends BaseService implements IKVService {
1006
543
  * Service configuration.
1007
544
  */
1008
545
  protected _config: KVServiceConfig;
546
+ private readThrough;
547
+ private readThroughReady;
548
+ /** Delay KV routing until an asynchronously loaded read-through is attached. */
549
+ setReadThroughReady(ready: Promise<unknown>): void;
1009
550
  /**
1010
551
  * Create a new KVService instance.
1011
552
  *
@@ -1016,6 +557,8 @@ declare class KVService extends BaseService implements IKVService {
1016
557
  * Get the service configuration.
1017
558
  */
1018
559
  get config(): KVServiceConfig;
560
+ /** Install or remove the optional replication read-through policy. */
561
+ setReadThrough(readThrough: KVReadThrough | null): void;
1019
562
  private handleQuotaErrorResponse;
1020
563
  /**
1021
564
  * Classify a KV 404 by reading the response body once.
@@ -1111,19 +654,24 @@ declare class KVService extends BaseService implements IKVService {
1111
654
  * Get a value by key.
1112
655
  */
1113
656
  get<T = unknown>(key: string, options?: KVGetOptions): Promise<Result<KVResponse<T>>>;
657
+ private getFromNetwork;
1114
658
  batchGet<T = unknown>(keys: string[], options?: KVGetOptions): Promise<Result<KVBatchReadResponse<T>>>;
1115
659
  /**
1116
660
  * Store a value at a key.
1117
661
  */
1118
662
  put(key: string, value: unknown, options?: KVPutOptions): Promise<Result<KVResponse<void>>>;
663
+ private putToNetwork;
1119
664
  /**
1120
665
  * Store multiple values in one TinyCloud KV invocation.
1121
666
  */
1122
667
  batchPut(items: KVBatchPutItem[], options?: KVBatchPutOptions): Promise<Result<KVBatchPutResponse>>;
668
+ private batchPutToNetwork;
1123
669
  /**
1124
670
  * List keys with optional prefix filtering.
1125
671
  */
1126
672
  list(options?: KVListOptions): Promise<Result<KVListResponse>>;
673
+ private listFromNetwork;
674
+ private finishList;
1127
675
  /**
1128
676
  * Read one page of the `tinycloud.kv/sync` change feed for a prefix.
1129
677
  */
@@ -1141,6 +689,7 @@ declare class KVService extends BaseService implements IKVService {
1141
689
  * Delete a key.
1142
690
  */
1143
691
  delete(key: string, options?: KVDeleteOptions): Promise<Result<KVResponse<void>>>;
692
+ private deleteFromNetwork;
1144
693
  /**
1145
694
  * Get metadata for a key without retrieving the value.
1146
695
  */
@@ -1195,4 +744,4 @@ declare class KVService extends BaseService implements IKVService {
1195
744
  withPrefix(prefix: string): IPrefixedKVService;
1196
745
  }
1197
746
 
1198
- export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, type IKVService, type IPrefixedKVService, KVAction, type KVActionType, type KVBatchPutItem, type KVBatchPutOptions, type KVBatchPutResponse, type KVBatchReadResponse, type KVChange, type KVChangesAuthority, type KVChangesOptions, type KVChangesResponse, type KVCreateSignedReadUrlOptions, type KVDeleteOptions, type KVGetOptions, type KVHeadOptions, type KVListOptions, type KVListResponse, type KVPutOptions, type KVResponse, type KVResponseHeaders, KVService, type KVServiceConfig, type KVSignedReadUrlResponse, PrefixedKVService };
747
+ export { type IKVService, type IPrefixedKVService, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVBatchReadResponse, KVChangesOptions, KVChangesResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVReadThrough, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService };