@tinycloud/sdk-services 3.3.0-beta.7 → 3.3.0

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-Cc6Ueicm.d.cts → BaseService-BhfKzKke.d.cts} +5 -1
  2. package/dist/{BaseService-DOdXd7sr.d.ts → BaseService-x4AFZiEa.d.ts} +5 -1
  3. package/dist/encryption/index.cjs +18 -5
  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 +18 -5
  8. package/dist/encryption/index.js.map +1 -1
  9. package/dist/index.cjs +911 -797
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +95 -11
  12. package/dist/index.d.ts +95 -11
  13. package/dist/index.js +911 -797
  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 +72 -80
  18. package/dist/kv/index.cjs.map +1 -1
  19. package/dist/kv/index.d.cts +4 -5
  20. package/dist/kv/index.d.ts +4 -5
  21. package/dist/kv/index.js +72 -80
  22. package/dist/kv/index.js.map +1 -1
  23. package/dist/kv/replication/index.cjs +6 -5
  24. package/dist/kv/replication/index.cjs.map +1 -1
  25. package/dist/kv/replication/index.d.cts +3 -3
  26. package/dist/kv/replication/index.d.ts +3 -3
  27. package/dist/kv/replication/index.js +6 -5
  28. package/dist/kv/replication/index.js.map +1 -1
  29. package/dist/{scope-B-m6cKH-.d.ts → scope-BHTkk5Yk.d.ts} +13 -2
  30. package/dist/{scope-B7oeKdLM.d.cts → scope-DMhalRFn.d.cts} +13 -2
  31. package/dist/sql/index.cjs +30 -16
  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 +30 -16
  36. package/dist/sql/index.js.map +1 -1
  37. package/dist/{types-BjH0ZtGy.d.cts → types-eVS1Whuf.d.cts} +24 -4
  38. package/dist/{types-BjH0ZtGy.d.ts → types-eVS1Whuf.d.ts} +24 -4
  39. package/package.json +2 -2
@@ -81,7 +81,7 @@ declare const ErrorCodes: {
81
81
  readonly ABORTED: "ABORTED";
82
82
  readonly INVALID_INPUT: "INVALID_INPUT";
83
83
  readonly PERMISSION_DENIED: "PERMISSION_DENIED";
84
- /** HTTP 503 `sql_busy:<stage>` / `unavailable_retryable`: nothing was applied; retry after `meta.retryAfterMs`. */
84
+ /** HTTP 503 `sql_busy:<stage>` / `unavailable_retryable`/`read_audit_busy`: nothing was applied; retry after `meta.retryAfterMs`. */
85
85
  readonly NODE_BUSY: "NODE_BUSY";
86
86
  /** HTTP 503 `request_timeout`: the node's deadline passed before any write began; nothing was applied. */
87
87
  readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
@@ -211,6 +211,17 @@ interface FetchResponse {
211
211
  text(): Promise<string>;
212
212
  arrayBuffer(): Promise<ArrayBuffer>;
213
213
  blob(): Promise<Blob>;
214
+ /** Present on standard Responses; the retry reads a clone so the caller's body stays intact. */
215
+ clone?(): FetchResponse;
216
+ /** Set by `ServiceContext.invokeWithRetry` on the response it returns: how many requests it took. */
217
+ retry?: RetryStats;
218
+ }
219
+ /** What automatic retry cost one request, so latency can be split from backoff. */
220
+ interface RetryStats {
221
+ /** Requests sent, including the first (1 means no retry). */
222
+ attempts: number;
223
+ /** Total milliseconds spent waiting between attempts. */
224
+ backoffMs: number;
214
225
  }
215
226
  /**
216
227
  * Fetch function signature - allows for custom fetch implementations.
@@ -218,7 +229,12 @@ interface FetchResponse {
218
229
  */
219
230
  type FetchFunction = (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
220
231
  /**
221
- * Configuration for automatic retry of failed requests.
232
+ * Automatic retry of node responses that guarantee nothing was applied
233
+ * (`NODE_BUSY`, `REQUEST_TIMEOUT`). Applied once, in the service context's
234
+ * `invokeWithRetry`, which re-mints the signed invocation per attempt. Backoff
235
+ * is full-jitter: each delay is uniform in `[0, step]`, where
236
+ * `step` is the strategy's delay capped at `maxDelayMs`. A node `Retry-After`
237
+ * replaces the delay. Opt out with `{ maxAttempts: 1 }`.
222
238
  */
223
239
  interface RetryPolicy {
224
240
  /** Maximum number of attempts (including initial) */
@@ -229,8 +245,10 @@ interface RetryPolicy {
229
245
  baseDelayMs: number;
230
246
  /** Maximum delay in milliseconds between retries */
231
247
  maxDelayMs: number;
232
- /** Error codes that should trigger a retry */
248
+ /** Node error codes that trigger a retry. `OUTCOME_UNKNOWN` is never retried. */
233
249
  retryableErrors: string[];
250
+ /** Total time budget for all attempts and waits, in milliseconds. Unset: no cap. */
251
+ maxTotalMs?: number;
234
252
  }
235
253
  /**
236
254
  * Default retry policy.
@@ -279,6 +297,8 @@ interface IServiceContext {
279
297
  readonly invokeAny?: InvokeAnyFunction;
280
298
  /** Fetch function (defaults to globalThis.fetch) */
281
299
  readonly fetch: FetchFunction;
300
+ /** Send a signed invocation, retrying a busy node; `build` re-signs per attempt. Absent: sends once. */
301
+ invokeWithRetry?(url: string, build: () => FetchRequestInit | Promise<FetchRequestInit>): Promise<FetchResponse>;
282
302
  /** Available TinyCloud host URLs */
283
303
  readonly hosts: string[];
284
304
  /** Get another registered service by name */
@@ -384,4 +404,4 @@ declare function serviceError(code: string, message: string, service: string, op
384
404
  meta?: Record<string, unknown>;
385
405
  }): ServiceError;
386
406
 
387
- export { type EventHandler as E, type FetchFunction as F, type IService as I, type PermissionHint as P, type Result as R, type ServiceSession as S, type TelemetryConfig as T, type IServiceContext as a, type ServiceError as b, type InvokeFunction as c, type InvokeAnyFunction as d, type RetryPolicy as e, type StorageQuotaInfo as f, type ErrorCode as g, ErrorCodes as h, type FetchRequestInit as i, type FetchResponse as j, type InvocationFact as k, type InvocationFacts as l, type InvokeAnyEntry as m, type ServiceErrorEvent as n, type ServiceHeaders as o, type ServiceRequestEvent as p, type ServiceResponseEvent as q, type ServiceRetryEvent as r, type TelemetryEventHandler as s, TelemetryEvents as t, type TelemetrySpanEvent as u, defaultRetryPolicy as v, err as w, ok as x, serviceError as y };
407
+ export { type EventHandler as E, type FetchRequestInit as F, type IService as I, type PermissionHint as P, type Result as R, type ServiceSession as S, type TelemetryConfig as T, type IServiceContext as a, type ServiceError as b, type ServiceHeaders as c, type FetchResponse as d, type RetryStats as e, type FetchFunction as f, type InvokeFunction as g, type InvokeAnyFunction as h, type RetryPolicy as i, type StorageQuotaInfo as j, type ErrorCode as k, ErrorCodes as l, type InvocationFact as m, type InvocationFacts as n, type InvokeAnyEntry as o, type ServiceErrorEvent as p, type ServiceRequestEvent as q, type ServiceResponseEvent as r, type ServiceRetryEvent as s, type TelemetryEventHandler as t, TelemetryEvents as u, type TelemetrySpanEvent as v, defaultRetryPolicy as w, err as x, ok as y, serviceError as z };
@@ -81,7 +81,7 @@ declare const ErrorCodes: {
81
81
  readonly ABORTED: "ABORTED";
82
82
  readonly INVALID_INPUT: "INVALID_INPUT";
83
83
  readonly PERMISSION_DENIED: "PERMISSION_DENIED";
84
- /** HTTP 503 `sql_busy:<stage>` / `unavailable_retryable`: nothing was applied; retry after `meta.retryAfterMs`. */
84
+ /** HTTP 503 `sql_busy:<stage>` / `unavailable_retryable`/`read_audit_busy`: nothing was applied; retry after `meta.retryAfterMs`. */
85
85
  readonly NODE_BUSY: "NODE_BUSY";
86
86
  /** HTTP 503 `request_timeout`: the node's deadline passed before any write began; nothing was applied. */
87
87
  readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
@@ -211,6 +211,17 @@ interface FetchResponse {
211
211
  text(): Promise<string>;
212
212
  arrayBuffer(): Promise<ArrayBuffer>;
213
213
  blob(): Promise<Blob>;
214
+ /** Present on standard Responses; the retry reads a clone so the caller's body stays intact. */
215
+ clone?(): FetchResponse;
216
+ /** Set by `ServiceContext.invokeWithRetry` on the response it returns: how many requests it took. */
217
+ retry?: RetryStats;
218
+ }
219
+ /** What automatic retry cost one request, so latency can be split from backoff. */
220
+ interface RetryStats {
221
+ /** Requests sent, including the first (1 means no retry). */
222
+ attempts: number;
223
+ /** Total milliseconds spent waiting between attempts. */
224
+ backoffMs: number;
214
225
  }
215
226
  /**
216
227
  * Fetch function signature - allows for custom fetch implementations.
@@ -218,7 +229,12 @@ interface FetchResponse {
218
229
  */
219
230
  type FetchFunction = (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
220
231
  /**
221
- * Configuration for automatic retry of failed requests.
232
+ * Automatic retry of node responses that guarantee nothing was applied
233
+ * (`NODE_BUSY`, `REQUEST_TIMEOUT`). Applied once, in the service context's
234
+ * `invokeWithRetry`, which re-mints the signed invocation per attempt. Backoff
235
+ * is full-jitter: each delay is uniform in `[0, step]`, where
236
+ * `step` is the strategy's delay capped at `maxDelayMs`. A node `Retry-After`
237
+ * replaces the delay. Opt out with `{ maxAttempts: 1 }`.
222
238
  */
223
239
  interface RetryPolicy {
224
240
  /** Maximum number of attempts (including initial) */
@@ -229,8 +245,10 @@ interface RetryPolicy {
229
245
  baseDelayMs: number;
230
246
  /** Maximum delay in milliseconds between retries */
231
247
  maxDelayMs: number;
232
- /** Error codes that should trigger a retry */
248
+ /** Node error codes that trigger a retry. `OUTCOME_UNKNOWN` is never retried. */
233
249
  retryableErrors: string[];
250
+ /** Total time budget for all attempts and waits, in milliseconds. Unset: no cap. */
251
+ maxTotalMs?: number;
234
252
  }
235
253
  /**
236
254
  * Default retry policy.
@@ -279,6 +297,8 @@ interface IServiceContext {
279
297
  readonly invokeAny?: InvokeAnyFunction;
280
298
  /** Fetch function (defaults to globalThis.fetch) */
281
299
  readonly fetch: FetchFunction;
300
+ /** Send a signed invocation, retrying a busy node; `build` re-signs per attempt. Absent: sends once. */
301
+ invokeWithRetry?(url: string, build: () => FetchRequestInit | Promise<FetchRequestInit>): Promise<FetchResponse>;
282
302
  /** Available TinyCloud host URLs */
283
303
  readonly hosts: string[];
284
304
  /** Get another registered service by name */
@@ -384,4 +404,4 @@ declare function serviceError(code: string, message: string, service: string, op
384
404
  meta?: Record<string, unknown>;
385
405
  }): ServiceError;
386
406
 
387
- export { type EventHandler as E, type FetchFunction as F, type IService as I, type PermissionHint as P, type Result as R, type ServiceSession as S, type TelemetryConfig as T, type IServiceContext as a, type ServiceError as b, type InvokeFunction as c, type InvokeAnyFunction as d, type RetryPolicy as e, type StorageQuotaInfo as f, type ErrorCode as g, ErrorCodes as h, type FetchRequestInit as i, type FetchResponse as j, type InvocationFact as k, type InvocationFacts as l, type InvokeAnyEntry as m, type ServiceErrorEvent as n, type ServiceHeaders as o, type ServiceRequestEvent as p, type ServiceResponseEvent as q, type ServiceRetryEvent as r, type TelemetryEventHandler as s, TelemetryEvents as t, type TelemetrySpanEvent as u, defaultRetryPolicy as v, err as w, ok as x, serviceError as y };
407
+ export { type EventHandler as E, type FetchRequestInit as F, type IService as I, type PermissionHint as P, type Result as R, type ServiceSession as S, type TelemetryConfig as T, type IServiceContext as a, type ServiceError as b, type ServiceHeaders as c, type FetchResponse as d, type RetryStats as e, type FetchFunction as f, type InvokeFunction as g, type InvokeAnyFunction as h, type RetryPolicy as i, type StorageQuotaInfo as j, type ErrorCode as k, ErrorCodes as l, type InvocationFact as m, type InvocationFacts as n, type InvokeAnyEntry as o, type ServiceErrorEvent as p, type ServiceRequestEvent as q, type ServiceResponseEvent as r, type ServiceRetryEvent as s, type TelemetryEventHandler as t, TelemetryEvents as u, type TelemetrySpanEvent as v, defaultRetryPolicy as w, err as x, ok as y, serviceError as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinycloud/sdk-services",
3
- "version": "3.3.0-beta.7",
3
+ "version": "3.3.0",
4
4
  "description": "TinyCloud SDK Services - Platform-agnostic service implementations",
5
5
  "author": "TinyCloud, Inc.",
6
6
  "license": "EGPL",
@@ -139,7 +139,7 @@
139
139
  },
140
140
  "devDependencies": {
141
141
  "@types/node": "^20",
142
- "@tinycloud/node-sdk-wasm": "1.7.7",
142
+ "@tinycloud/node-sdk-wasm": "1.7.8",
143
143
  "tsup": "^8.0.0",
144
144
  "typescript": "^5.9.3"
145
145
  },