@tinycloud/sdk-services 3.2.6-beta.4 → 3.3.0-beta.25

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 (45) hide show
  1. package/dist/{BaseService-1Ug6y7DC.d.cts → BaseService-BhfKzKke.d.cts} +5 -1
  2. package/dist/{BaseService-Bn07Vudy.d.ts → BaseService-x4AFZiEa.d.ts} +5 -1
  3. package/dist/encryption/index.cjs +25 -4
  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 +25 -4
  8. package/dist/encryption/index.js.map +1 -1
  9. package/dist/index.cjs +959 -808
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +114 -7
  12. package/dist/index.d.ts +114 -7
  13. package/dist/index.js +958 -808
  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 +136 -99
  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 +136 -99
  22. package/dist/kv/index.js.map +1 -1
  23. package/dist/kv/replication/grantPolicy.cjs +82 -0
  24. package/dist/kv/replication/grantPolicy.cjs.map +1 -0
  25. package/dist/kv/replication/grantPolicy.d.cts +19 -0
  26. package/dist/kv/replication/grantPolicy.d.ts +19 -0
  27. package/dist/kv/replication/grantPolicy.js +50 -0
  28. package/dist/kv/replication/grantPolicy.js.map +1 -0
  29. package/dist/kv/replication/index.cjs +576 -132
  30. package/dist/kv/replication/index.cjs.map +1 -1
  31. package/dist/kv/replication/index.d.cts +3 -3
  32. package/dist/kv/replication/index.d.ts +3 -3
  33. package/dist/kv/replication/index.js +576 -132
  34. package/dist/kv/replication/index.js.map +1 -1
  35. package/dist/{scope-BnyVPZ5E.d.ts → scope-9U4gVNFN.d.ts} +312 -7
  36. package/dist/{scope-CQ5kmHlt.d.cts → scope-BzdcrOZG.d.cts} +312 -7
  37. package/dist/sql/index.cjs +98 -50
  38. package/dist/sql/index.cjs.map +1 -1
  39. package/dist/sql/index.d.cts +2 -2
  40. package/dist/sql/index.d.ts +2 -2
  41. package/dist/sql/index.js +98 -50
  42. package/dist/sql/index.js.map +1 -1
  43. package/dist/{types-gmdUiorz.d.cts → types-eVS1Whuf.d.cts} +29 -3
  44. package/dist/{types-gmdUiorz.d.ts → types-eVS1Whuf.d.ts} +29 -3
  45. package/package.json +16 -2
@@ -1,4 +1,4 @@
1
- import { I as IService, a as IServiceContext, S as ServiceSession, b as ServiceError, R as Result } from './types-gmdUiorz.cjs';
1
+ import { I as IService, a as IServiceContext, S as ServiceSession, b as ServiceError, c as ServiceHeaders, F as FetchRequestInit, d as FetchResponse, R as Result } from './types-eVS1Whuf.cjs';
2
2
 
3
3
  /**
4
4
  * Base Service Types
@@ -195,6 +195,10 @@ declare abstract class BaseService implements IService {
195
195
  * @returns A combined abort signal
196
196
  */
197
197
  protected combineSignals(...signals: (AbortSignal | undefined)[]): AbortSignal;
198
+ /** POST a signed invocation with retry; `mint` re-signs per attempt, `init.headers` add to the signed ones. */
199
+ protected invokeWithRetry(url: string, mint: () => ServiceHeaders, { headers: extra, ...init }?: Omit<FetchRequestInit, "headers"> & {
200
+ headers?: Record<string, string>;
201
+ }): Promise<FetchResponse>;
198
202
  /**
199
203
  * Create the abort signal for one request, bounded by the request timeout.
200
204
  *
@@ -1,4 +1,4 @@
1
- import { I as IService, a as IServiceContext, S as ServiceSession, b as ServiceError, R as Result } from './types-gmdUiorz.js';
1
+ import { I as IService, a as IServiceContext, S as ServiceSession, b as ServiceError, c as ServiceHeaders, F as FetchRequestInit, d as FetchResponse, R as Result } from './types-eVS1Whuf.js';
2
2
 
3
3
  /**
4
4
  * Base Service Types
@@ -195,6 +195,10 @@ declare abstract class BaseService implements IService {
195
195
  * @returns A combined abort signal
196
196
  */
197
197
  protected combineSignals(...signals: (AbortSignal | undefined)[]): AbortSignal;
198
+ /** POST a signed invocation with retry; `mint` re-signs per attempt, `init.headers` add to the signed ones. */
199
+ protected invokeWithRetry(url: string, mint: () => ServiceHeaders, { headers: extra, ...init }?: Omit<FetchRequestInit, "headers"> & {
200
+ headers?: Record<string, string>;
201
+ }): Promise<FetchResponse>;
198
202
  /**
199
203
  * Create the abort signal for one request, bounded by the request timeout.
200
204
  *
@@ -80,6 +80,14 @@ var ErrorCodes = {
80
80
  ABORTED: "ABORTED",
81
81
  INVALID_INPUT: "INVALID_INPUT",
82
82
  PERMISSION_DENIED: "PERMISSION_DENIED",
83
+ // Node retry signals (tinycloud-node #347). `meta.retryable` says whether a
84
+ // retry is safe; `meta.retryAfterMs` carries the node's Retry-After.
85
+ /** HTTP 503 `sql_busy:<stage>` / `unavailable_retryable`/`read_audit_busy`: nothing was applied; retry after `meta.retryAfterMs`. */
86
+ NODE_BUSY: "NODE_BUSY",
87
+ /** HTTP 503 `request_timeout`: the node's deadline passed before any write began; nothing was applied. */
88
+ REQUEST_TIMEOUT: "REQUEST_TIMEOUT",
89
+ /** HTTP 500 `outcome_unknown`: a write may have been applied; read back before retrying a non-idempotent operation. */
90
+ OUTCOME_UNKNOWN: "OUTCOME_UNKNOWN",
83
91
  // KV-specific errors
84
92
  KV_NOT_FOUND: "KV_NOT_FOUND",
85
93
  KV_WRITE_FAILED: "KV_WRITE_FAILED",
@@ -115,11 +123,12 @@ var ErrorCodes = {
115
123
  DUCKDB_READONLY_VIOLATION: "DUCKDB_READONLY_VIOLATION"
116
124
  };
117
125
  var defaultRetryPolicy = {
118
- maxAttempts: 3,
126
+ maxAttempts: 4,
119
127
  backoff: "exponential",
120
- baseDelayMs: 1e3,
121
- maxDelayMs: 1e4,
122
- retryableErrors: [ErrorCodes.NETWORK_ERROR, ErrorCodes.TIMEOUT]
128
+ baseDelayMs: 250,
129
+ maxDelayMs: 4e3,
130
+ retryableErrors: [ErrorCodes.NODE_BUSY, ErrorCodes.REQUEST_TIMEOUT],
131
+ maxTotalMs: 12e3
123
132
  };
124
133
  var TelemetryEvents = {
125
134
  SPAN: "telemetry.span",
@@ -491,6 +500,18 @@ var BaseService = class {
491
500
  }
492
501
  return controller.signal;
493
502
  }
503
+ /** POST a signed invocation with retry; `mint` re-signs per attempt, `init.headers` add to the signed ones. */
504
+ invokeWithRetry(url, mint, { headers: extra, ...init } = {}) {
505
+ const build = () => {
506
+ const signed = mint();
507
+ return {
508
+ method: "POST",
509
+ ...init,
510
+ headers: Array.isArray(signed) ? [...signed, ...Object.entries(extra ?? {})] : { ...signed, ...extra }
511
+ };
512
+ };
513
+ return this.context.invokeWithRetry ? this.context.invokeWithRetry(url, build) : this.context.fetch(url, build());
514
+ }
494
515
  /**
495
516
  * Create the abort signal for one request, bounded by the request timeout.
496
517
  *