@tinycloud/sdk-services 3.1.0-beta.6 → 3.1.0-beta.7

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/index.cjs CHANGED
@@ -1205,11 +1205,31 @@ function networkError(service, message, cause) {
1205
1205
  cause
1206
1206
  };
1207
1207
  }
1208
- function timeoutError(service) {
1208
+ var RequestTimeoutError = class extends Error {
1209
+ constructor(timeoutMs) {
1210
+ super(`Request timed out after ${timeoutMs}ms.`);
1211
+ this.name = "TimeoutError";
1212
+ this.timeoutMs = timeoutMs;
1213
+ }
1214
+ };
1215
+ function isRequestTimeoutError(error) {
1216
+ return error instanceof RequestTimeoutError || error instanceof Error && error.name === "TimeoutError" && typeof error.timeoutMs === "number";
1217
+ }
1218
+ function timeoutError(service, timeoutMs, cause) {
1219
+ if (timeoutMs === void 0) {
1220
+ return {
1221
+ code: ErrorCodes.TIMEOUT,
1222
+ message: "Request timed out.",
1223
+ service,
1224
+ ...cause === void 0 ? {} : { cause }
1225
+ };
1226
+ }
1209
1227
  return {
1210
1228
  code: ErrorCodes.TIMEOUT,
1211
- message: "Request timed out.",
1212
- service
1229
+ message: `Request timed out after ${timeoutMs}ms.`,
1230
+ service,
1231
+ ...cause === void 0 ? {} : { cause },
1232
+ meta: { timeoutMs }
1213
1233
  };
1214
1234
  }
1215
1235
  function abortedError(service) {
@@ -1373,6 +1393,9 @@ function isStorageFullError(error) {
1373
1393
  }
1374
1394
  function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
1375
1395
  if (error instanceof Error) {
1396
+ if (isRequestTimeoutError(error)) {
1397
+ return timeoutError(service, error.timeoutMs, error);
1398
+ }
1376
1399
  if (error.name === "AbortError") {
1377
1400
  return abortedError(service);
1378
1401
  }
@@ -1397,6 +1420,7 @@ function errorResult(error) {
1397
1420
  }
1398
1421
 
1399
1422
  // src/base/BaseService.ts
1423
+ var MAX_TIMER_DELAY_MS = 2147483647;
1400
1424
  var BaseService = class {
1401
1425
  constructor() {
1402
1426
  /**
@@ -1577,6 +1601,64 @@ var BaseService = class {
1577
1601
  }
1578
1602
  return controller.signal;
1579
1603
  }
1604
+ /**
1605
+ * Create the abort signal for one request, bounded by the request timeout.
1606
+ *
1607
+ * The signal aborts when the service signs out, the context aborts, the
1608
+ * caller's `signal` aborts, or the timeout elapses, whichever comes first.
1609
+ * A timeout aborts with a {@link RequestTimeoutError} (`TimeoutError`), which
1610
+ * `wrapError` maps to `ErrorCodes.TIMEOUT`; the other sources keep their own
1611
+ * reason (normally `AbortError`, mapped to `ErrorCodes.ABORTED`).
1612
+ *
1613
+ * The timeout is `timeoutMs` when given, otherwise `config.timeout`. Only a
1614
+ * positive, finite value (at most 2^31-1 ms) applies; `undefined`, `0`, and
1615
+ * `Infinity` mean no timeout, so a per-call `0` opts out of a configured one.
1616
+ *
1617
+ * Callers must call `dispose()` once the response body has been consumed,
1618
+ * which clears the timer and removes the listeners this adds to the
1619
+ * long-lived service and context signals.
1620
+ *
1621
+ * @param signal - The caller's abort signal for this request
1622
+ * @param timeoutMs - Per-request timeout override in milliseconds
1623
+ */
1624
+ createRequestSignal(signal, timeoutMs) {
1625
+ const controller = new AbortController();
1626
+ const detachers = [];
1627
+ let timer;
1628
+ const dispose = () => {
1629
+ if (timer !== void 0) {
1630
+ clearTimeout(timer);
1631
+ timer = void 0;
1632
+ }
1633
+ for (const detach of detachers.splice(0)) {
1634
+ detach();
1635
+ }
1636
+ };
1637
+ const abort = (reason) => {
1638
+ dispose();
1639
+ controller.abort(reason);
1640
+ };
1641
+ const requestSignal = { signal: controller.signal, dispose };
1642
+ const parents = [
1643
+ this.abortController.signal,
1644
+ this.context?.abortSignal,
1645
+ signal
1646
+ ].filter((parent) => parent !== void 0);
1647
+ for (const parent of parents) {
1648
+ if (parent.aborted) {
1649
+ abort(parent.reason);
1650
+ return requestSignal;
1651
+ }
1652
+ const onAbort = () => abort(parent.reason);
1653
+ parent.addEventListener("abort", onAbort, { once: true });
1654
+ detachers.push(() => parent.removeEventListener("abort", onAbort));
1655
+ }
1656
+ const timeout = timeoutMs ?? this._config.timeout;
1657
+ if (typeof timeout === "number" && timeout > 0 && timeout <= MAX_TIMER_DELAY_MS) {
1658
+ timer = setTimeout(() => abort(new RequestTimeoutError(timeout)), timeout);
1659
+ }
1660
+ return requestSignal;
1661
+ }
1580
1662
  /**
1581
1663
  * Wrap an operation with error handling and telemetry.
1582
1664
  *
@@ -1837,7 +1919,7 @@ var KVService = class extends BaseService {
1837
1919
  * @param path - Resource path
1838
1920
  * @param action - KV action
1839
1921
  * @param body - Optional request body
1840
- * @param signal - Optional abort signal
1922
+ * @param signal - Request signal from createRequestSignal()
1841
1923
  * @returns Fetch response
1842
1924
  */
1843
1925
  async invokeOperation(path, action, body, signal, extraHeaders) {
@@ -1853,7 +1935,7 @@ var KVService = class extends BaseService {
1853
1935
  method: "POST",
1854
1936
  headers: requestHeaders,
1855
1937
  body,
1856
- signal: this.combineSignals(signal)
1938
+ signal
1857
1939
  });
1858
1940
  }
1859
1941
  /**
@@ -2030,6 +2112,7 @@ var KVService = class extends BaseService {
2030
2112
  "kv"
2031
2113
  ));
2032
2114
  }
2115
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2033
2116
  try {
2034
2117
  const session = this.context.session;
2035
2118
  const invocationHeaders = this.context.invokeAny(
@@ -2051,7 +2134,7 @@ var KVService = class extends BaseService {
2051
2134
  const response = await this.context.fetch(`${this.host}/invoke`, {
2052
2135
  method: "POST",
2053
2136
  headers,
2054
- signal: this.combineSignals(options?.signal)
2137
+ signal: request.signal
2055
2138
  });
2056
2139
  if (!response.ok) {
2057
2140
  const errorText = response.status === 401 || response.status === 403 ? await this.readAuthorizationText(response) : await response.text();
@@ -2116,6 +2199,8 @@ var KVService = class extends BaseService {
2116
2199
  return ok({ results, count: results.length });
2117
2200
  } catch (error) {
2118
2201
  return err(wrapError("kv", error));
2202
+ } finally {
2203
+ request.dispose();
2119
2204
  }
2120
2205
  }
2121
2206
  /**
@@ -2248,12 +2333,13 @@ var KVService = class extends BaseService {
2248
2333
  ));
2249
2334
  }
2250
2335
  const path = this.getFullPath(key, options?.prefix);
2336
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2251
2337
  try {
2252
2338
  const response = await this.invokeOperation(
2253
2339
  path,
2254
2340
  KVAction.GET,
2255
2341
  void 0,
2256
- options?.signal,
2342
+ request.signal,
2257
2343
  options?.maxResponseBytes === void 0 ? void 0 : { "x-tinycloud-max-response-bytes": String(options.maxResponseBytes) }
2258
2344
  );
2259
2345
  if (!response.ok) {
@@ -2310,6 +2396,8 @@ var KVService = class extends BaseService {
2310
2396
  });
2311
2397
  } catch (error) {
2312
2398
  return err(wrapError("kv", error));
2399
+ } finally {
2400
+ request.dispose();
2313
2401
  }
2314
2402
  });
2315
2403
  }
@@ -2337,12 +2425,13 @@ var KVService = class extends BaseService {
2337
2425
  }
2338
2426
  const path = this.getFullPath(key, options?.prefix);
2339
2427
  const body = this.serializePutValue(value, options?.contentType);
2428
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2340
2429
  try {
2341
2430
  const response = await this.invokeOperation(
2342
2431
  path,
2343
2432
  KVAction.PUT,
2344
2433
  body,
2345
- options?.signal,
2434
+ request.signal,
2346
2435
  {
2347
2436
  ...options?.ifMatch === void 0 ? {} : { "if-match": options.ifMatch },
2348
2437
  ...options?.ifNoneMatch === void 0 ? {} : { "if-none-match": options.ifNoneMatch }
@@ -2398,6 +2487,8 @@ var KVService = class extends BaseService {
2398
2487
  });
2399
2488
  } catch (error) {
2400
2489
  return err(wrapError("kv", error));
2490
+ } finally {
2491
+ request.dispose();
2401
2492
  }
2402
2493
  });
2403
2494
  }
@@ -2437,6 +2528,7 @@ var KVService = class extends BaseService {
2437
2528
  seen.add(path);
2438
2529
  }
2439
2530
  let requestMayHaveDispatched = false;
2531
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2440
2532
  try {
2441
2533
  const body = new FormData();
2442
2534
  for (let index = 0; index < items.length; index++) {
@@ -2459,7 +2551,7 @@ var KVService = class extends BaseService {
2459
2551
  method: "POST",
2460
2552
  headers,
2461
2553
  body,
2462
- signal: this.combineSignals(options?.signal)
2554
+ signal: request.signal
2463
2555
  };
2464
2556
  const fetchFn = this.context.fetch;
2465
2557
  requestMayHaveDispatched = true;
@@ -2510,14 +2602,16 @@ var KVService = class extends BaseService {
2510
2602
  rawBody = await response.json();
2511
2603
  } catch (jsonError) {
2512
2604
  const cause = jsonError instanceof Error ? jsonError : new Error(String(jsonError));
2605
+ const timedOut = isRequestTimeoutError(cause);
2513
2606
  return err(
2514
2607
  serviceError(
2515
- ErrorCodes.NETWORK_ERROR,
2516
- `KV batchPut response was not valid JSON: ${cause.message}`,
2608
+ timedOut ? ErrorCodes.TIMEOUT : ErrorCodes.NETWORK_ERROR,
2609
+ timedOut ? `KV batchPut response body did not arrive in time: ${cause.message}` : `KV batchPut response was not valid JSON: ${cause.message}`,
2517
2610
  "kv",
2518
2611
  {
2519
2612
  cause,
2520
2613
  meta: {
2614
+ ...timedOut ? { timeoutMs: cause.timeoutMs } : {},
2521
2615
  requestMayHaveDispatched: true,
2522
2616
  responseReceived: true,
2523
2617
  status: response.status,
@@ -2572,6 +2666,8 @@ var KVService = class extends BaseService {
2572
2666
  ...wrapped,
2573
2667
  meta: { ...wrapped.meta, requestMayHaveDispatched }
2574
2668
  });
2669
+ } finally {
2670
+ request.dispose();
2575
2671
  }
2576
2672
  });
2577
2673
  }
@@ -2594,12 +2690,13 @@ var KVService = class extends BaseService {
2594
2690
  if (options?.path) {
2595
2691
  listPath = listPath ? `${listPath}/${options.path}` : options.path;
2596
2692
  }
2693
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2597
2694
  try {
2598
2695
  const response = await this.invokeOperation(
2599
2696
  listPath,
2600
2697
  KVAction.LIST,
2601
2698
  void 0,
2602
- options?.signal,
2699
+ request.signal,
2603
2700
  options?.limit === void 0 && options?.cursor === void 0 ? void 0 : {
2604
2701
  ...options?.limit === void 0 ? {} : { "x-tinycloud-limit": String(options.limit) },
2605
2702
  ...options?.cursor === void 0 ? {} : { "x-tinycloud-cursor": options.cursor }
@@ -2640,6 +2737,8 @@ var KVService = class extends BaseService {
2640
2737
  });
2641
2738
  } catch (error) {
2642
2739
  return err(wrapError("kv", error));
2740
+ } finally {
2741
+ request.dispose();
2643
2742
  }
2644
2743
  });
2645
2744
  }
@@ -2652,12 +2751,13 @@ var KVService = class extends BaseService {
2652
2751
  return err(authRequiredError("kv"));
2653
2752
  }
2654
2753
  const path = this.getFullPath(key, options?.prefix);
2754
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2655
2755
  try {
2656
2756
  const response = await this.invokeOperation(
2657
2757
  path,
2658
2758
  KVAction.DELETE,
2659
2759
  void 0,
2660
- options?.signal,
2760
+ request.signal,
2661
2761
  options?.ifMatch === void 0 ? void 0 : { "if-match": options.ifMatch }
2662
2762
  );
2663
2763
  if (!response.ok) {
@@ -2705,6 +2805,8 @@ var KVService = class extends BaseService {
2705
2805
  });
2706
2806
  } catch (error) {
2707
2807
  return err(wrapError("kv", error));
2808
+ } finally {
2809
+ request.dispose();
2708
2810
  }
2709
2811
  });
2710
2812
  }
@@ -2717,12 +2819,13 @@ var KVService = class extends BaseService {
2717
2819
  return err(authRequiredError("kv"));
2718
2820
  }
2719
2821
  const path = this.getFullPath(key, options?.prefix);
2822
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2720
2823
  try {
2721
2824
  const response = await this.invokeOperation(
2722
2825
  path,
2723
2826
  KVAction.HEAD,
2724
2827
  void 0,
2725
- options?.signal
2828
+ request.signal
2726
2829
  );
2727
2830
  if (!response.ok) {
2728
2831
  if (response.status === 401 || response.status === 403) {
@@ -2753,6 +2856,8 @@ var KVService = class extends BaseService {
2753
2856
  });
2754
2857
  } catch (error) {
2755
2858
  return err(wrapError("kv", error));
2859
+ } finally {
2860
+ request.dispose();
2756
2861
  }
2757
2862
  });
2758
2863
  }
@@ -2790,12 +2895,13 @@ var KVService = class extends BaseService {
2790
2895
  if (options?.etag !== void 0) {
2791
2896
  body.etag = options.etag;
2792
2897
  }
2898
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2793
2899
  try {
2794
2900
  const response = await this.context.fetch(`${this.host}/signed/kv`, {
2795
2901
  method: "POST",
2796
2902
  headers: this.withJsonContentType(headers),
2797
2903
  body: JSON.stringify(body),
2798
- signal: this.combineSignals(options?.signal)
2904
+ signal: request.signal
2799
2905
  });
2800
2906
  if (!response.ok) {
2801
2907
  return this.createSignedReadUrlError(response, key, path);
@@ -2815,6 +2921,8 @@ var KVService = class extends BaseService {
2815
2921
  return ok(signedUrl);
2816
2922
  } catch (error) {
2817
2923
  return err(wrapError("kv", error));
2924
+ } finally {
2925
+ request.dispose();
2818
2926
  }
2819
2927
  });
2820
2928
  }
@@ -3028,6 +3136,7 @@ var SQLService = class extends BaseService {
3028
3136
  if (!this.requireAuth()) {
3029
3137
  return err(authRequiredError("sql"));
3030
3138
  }
3139
+ const request = this.createRequestSignal(options?.signal);
3031
3140
  try {
3032
3141
  const body = {
3033
3142
  action: "query",
@@ -3041,7 +3150,7 @@ var SQLService = class extends BaseService {
3041
3150
  dbName,
3042
3151
  action,
3043
3152
  body,
3044
- options?.signal
3153
+ request.signal
3045
3154
  );
3046
3155
  if (!response.ok) {
3047
3156
  return this.handleErrorResponse(response, "query", dbName, [action]);
@@ -3050,6 +3159,8 @@ var SQLService = class extends BaseService {
3050
3159
  return ok(data);
3051
3160
  } catch (error) {
3052
3161
  return err(wrapError("sql", error));
3162
+ } finally {
3163
+ request.dispose();
3053
3164
  }
3054
3165
  });
3055
3166
  }
@@ -3058,6 +3169,7 @@ var SQLService = class extends BaseService {
3058
3169
  if (!this.requireAuth()) {
3059
3170
  return err(authRequiredError("sql"));
3060
3171
  }
3172
+ const request = this.createRequestSignal(options?.signal);
3061
3173
  try {
3062
3174
  const body = {
3063
3175
  action: "execute",
@@ -3078,7 +3190,7 @@ var SQLService = class extends BaseService {
3078
3190
  dbName,
3079
3191
  requestedActions,
3080
3192
  body,
3081
- options?.signal
3193
+ request.signal
3082
3194
  );
3083
3195
  if (!response.ok) {
3084
3196
  return this.handleErrorResponse(response, "execute", dbName, requestedActions);
@@ -3087,6 +3199,8 @@ var SQLService = class extends BaseService {
3087
3199
  return ok(data);
3088
3200
  } catch (error) {
3089
3201
  return err(wrapError("sql", error));
3202
+ } finally {
3203
+ request.dispose();
3090
3204
  }
3091
3205
  });
3092
3206
  }
@@ -3095,13 +3209,14 @@ var SQLService = class extends BaseService {
3095
3209
  if (!this.requireAuth()) {
3096
3210
  return err(authRequiredError("sql"));
3097
3211
  }
3212
+ const request = this.createRequestSignal(options?.signal);
3098
3213
  try {
3099
3214
  const requestedActions = this.actionsForSqlBatch(statements);
3100
3215
  const response = await this.invokeSQL(
3101
3216
  dbName,
3102
3217
  requestedActions,
3103
3218
  { action: "batch", statements },
3104
- options?.signal
3219
+ request.signal
3105
3220
  );
3106
3221
  if (!response.ok) {
3107
3222
  return this.handleErrorResponse(response, "batch", dbName, requestedActions);
@@ -3110,6 +3225,8 @@ var SQLService = class extends BaseService {
3110
3225
  return ok(data);
3111
3226
  } catch (error) {
3112
3227
  return err(wrapError("sql", error));
3228
+ } finally {
3229
+ request.dispose();
3113
3230
  }
3114
3231
  });
3115
3232
  }
@@ -3118,12 +3235,13 @@ var SQLService = class extends BaseService {
3118
3235
  if (!this.requireAuth()) {
3119
3236
  return err(authRequiredError("sql"));
3120
3237
  }
3238
+ const request = this.createRequestSignal(options?.signal);
3121
3239
  try {
3122
3240
  const response = await this.invokeSQL(
3123
3241
  dbName,
3124
3242
  SQLAction.WRITE,
3125
3243
  { action: "execute_statement", name, params: params ?? [] },
3126
- options?.signal
3244
+ request.signal
3127
3245
  );
3128
3246
  if (!response.ok) {
3129
3247
  return this.handleErrorResponse(response, "executeStatement", dbName, [SQLAction.WRITE]);
@@ -3132,6 +3250,8 @@ var SQLService = class extends BaseService {
3132
3250
  return ok(data);
3133
3251
  } catch (error) {
3134
3252
  return err(wrapError("sql", error));
3253
+ } finally {
3254
+ request.dispose();
3135
3255
  }
3136
3256
  });
3137
3257
  }
@@ -3140,12 +3260,13 @@ var SQLService = class extends BaseService {
3140
3260
  if (!this.requireAuth()) {
3141
3261
  return err(authRequiredError("sql"));
3142
3262
  }
3263
+ const request = this.createRequestSignal(options?.signal);
3143
3264
  try {
3144
3265
  const response = await this.invokeSQL(
3145
3266
  dbName,
3146
3267
  SQLAction.READ,
3147
3268
  { action: "export" },
3148
- options?.signal
3269
+ request.signal
3149
3270
  );
3150
3271
  if (!response.ok) {
3151
3272
  return this.handleErrorResponse(response, "export", dbName, [SQLAction.READ]);
@@ -3159,6 +3280,8 @@ var SQLService = class extends BaseService {
3159
3280
  return ok(text);
3160
3281
  } catch (error) {
3161
3282
  return err(wrapError("sql", error));
3283
+ } finally {
3284
+ request.dispose();
3162
3285
  }
3163
3286
  });
3164
3287
  }
@@ -3249,7 +3372,7 @@ var SQLService = class extends BaseService {
3249
3372
  "Content-Type": "application/json"
3250
3373
  },
3251
3374
  body: JSON.stringify(body),
3252
- signal: this.combineSignals(signal)
3375
+ signal
3253
3376
  });
3254
3377
  }
3255
3378
  actionForSql(sql, fallback) {
@@ -3513,12 +3636,13 @@ var DuckDbService = class extends BaseService {
3513
3636
  if (!this.requireAuth()) {
3514
3637
  return err(authRequiredError("duckdb"));
3515
3638
  }
3639
+ const request = this.createRequestSignal(options?.signal);
3516
3640
  try {
3517
3641
  const response = await this.invokeDuckDb(
3518
3642
  dbName,
3519
3643
  DuckDbAction.READ,
3520
3644
  { action: "query", sql, params: params ?? [] },
3521
- options?.signal
3645
+ request.signal
3522
3646
  );
3523
3647
  if (!response.ok) {
3524
3648
  return this.handleErrorResponse(response, "query");
@@ -3527,6 +3651,8 @@ var DuckDbService = class extends BaseService {
3527
3651
  return ok(data);
3528
3652
  } catch (error) {
3529
3653
  return err(wrapError("duckdb", error));
3654
+ } finally {
3655
+ request.dispose();
3530
3656
  }
3531
3657
  });
3532
3658
  }
@@ -3535,12 +3661,13 @@ var DuckDbService = class extends BaseService {
3535
3661
  if (!this.requireAuth()) {
3536
3662
  return err(authRequiredError("duckdb"));
3537
3663
  }
3664
+ const request = this.createRequestSignal(options?.signal);
3538
3665
  try {
3539
3666
  const response = await this.invokeDuckDb(
3540
3667
  dbName,
3541
3668
  DuckDbAction.READ,
3542
3669
  { action: "query", sql, params: params ?? [] },
3543
- options?.signal,
3670
+ request.signal,
3544
3671
  { Accept: "application/vnd.apache.arrow.stream" }
3545
3672
  );
3546
3673
  if (!response.ok) {
@@ -3550,6 +3677,8 @@ var DuckDbService = class extends BaseService {
3550
3677
  return ok(buffer);
3551
3678
  } catch (error) {
3552
3679
  return err(wrapError("duckdb", error));
3680
+ } finally {
3681
+ request.dispose();
3553
3682
  }
3554
3683
  });
3555
3684
  }
@@ -3558,6 +3687,7 @@ var DuckDbService = class extends BaseService {
3558
3687
  if (!this.requireAuth()) {
3559
3688
  return err(authRequiredError("duckdb"));
3560
3689
  }
3690
+ const request = this.createRequestSignal(options?.signal);
3561
3691
  try {
3562
3692
  const body = {
3563
3693
  action: "execute",
@@ -3571,7 +3701,7 @@ var DuckDbService = class extends BaseService {
3571
3701
  dbName,
3572
3702
  DuckDbAction.WRITE,
3573
3703
  body,
3574
- options?.signal
3704
+ request.signal
3575
3705
  );
3576
3706
  if (!response.ok) {
3577
3707
  return this.handleErrorResponse(response, "execute");
@@ -3580,6 +3710,8 @@ var DuckDbService = class extends BaseService {
3580
3710
  return ok(data);
3581
3711
  } catch (error) {
3582
3712
  return err(wrapError("duckdb", error));
3713
+ } finally {
3714
+ request.dispose();
3583
3715
  }
3584
3716
  });
3585
3717
  }
@@ -3588,6 +3720,7 @@ var DuckDbService = class extends BaseService {
3588
3720
  if (!this.requireAuth()) {
3589
3721
  return err(authRequiredError("duckdb"));
3590
3722
  }
3723
+ const request = this.createRequestSignal(options?.signal);
3591
3724
  try {
3592
3725
  const body = {
3593
3726
  action: "batch",
@@ -3600,7 +3733,7 @@ var DuckDbService = class extends BaseService {
3600
3733
  dbName,
3601
3734
  DuckDbAction.WRITE,
3602
3735
  body,
3603
- options?.signal
3736
+ request.signal
3604
3737
  );
3605
3738
  if (!response.ok) {
3606
3739
  return this.handleErrorResponse(response, "batch");
@@ -3609,6 +3742,8 @@ var DuckDbService = class extends BaseService {
3609
3742
  return ok(data);
3610
3743
  } catch (error) {
3611
3744
  return err(wrapError("duckdb", error));
3745
+ } finally {
3746
+ request.dispose();
3612
3747
  }
3613
3748
  });
3614
3749
  }
@@ -3617,12 +3752,13 @@ var DuckDbService = class extends BaseService {
3617
3752
  if (!this.requireAuth()) {
3618
3753
  return err(authRequiredError("duckdb"));
3619
3754
  }
3755
+ const request = this.createRequestSignal(options?.signal);
3620
3756
  try {
3621
3757
  const response = await this.invokeDuckDb(
3622
3758
  dbName,
3623
3759
  DuckDbAction.WRITE,
3624
3760
  { action: "executeStatement", name, params: params ?? [] },
3625
- options?.signal
3761
+ request.signal
3626
3762
  );
3627
3763
  if (!response.ok) {
3628
3764
  return this.handleErrorResponse(response, "executeStatement");
@@ -3631,6 +3767,8 @@ var DuckDbService = class extends BaseService {
3631
3767
  return ok(data);
3632
3768
  } catch (error) {
3633
3769
  return err(wrapError("duckdb", error));
3770
+ } finally {
3771
+ request.dispose();
3634
3772
  }
3635
3773
  });
3636
3774
  }
@@ -3639,12 +3777,13 @@ var DuckDbService = class extends BaseService {
3639
3777
  if (!this.requireAuth()) {
3640
3778
  return err(authRequiredError("duckdb"));
3641
3779
  }
3780
+ const request = this.createRequestSignal(options?.signal);
3642
3781
  try {
3643
3782
  const response = await this.invokeDuckDb(
3644
3783
  dbName,
3645
3784
  DuckDbAction.READ,
3646
3785
  { action: "describe" },
3647
- options?.signal
3786
+ request.signal
3648
3787
  );
3649
3788
  if (!response.ok) {
3650
3789
  return this.handleErrorResponse(response, "describe");
@@ -3653,6 +3792,8 @@ var DuckDbService = class extends BaseService {
3653
3792
  return ok(data);
3654
3793
  } catch (error) {
3655
3794
  return err(wrapError("duckdb", error));
3795
+ } finally {
3796
+ request.dispose();
3656
3797
  }
3657
3798
  });
3658
3799
  }
@@ -3661,12 +3802,13 @@ var DuckDbService = class extends BaseService {
3661
3802
  if (!this.requireAuth()) {
3662
3803
  return err(authRequiredError("duckdb"));
3663
3804
  }
3805
+ const request = this.createRequestSignal(options?.signal);
3664
3806
  try {
3665
3807
  const response = await this.invokeDuckDb(
3666
3808
  dbName,
3667
3809
  DuckDbAction.EXPORT,
3668
3810
  { action: "export" },
3669
- options?.signal
3811
+ request.signal
3670
3812
  );
3671
3813
  if (!response.ok) {
3672
3814
  return this.handleErrorResponse(response, "export");
@@ -3675,6 +3817,8 @@ var DuckDbService = class extends BaseService {
3675
3817
  return ok(blob);
3676
3818
  } catch (error) {
3677
3819
  return err(wrapError("duckdb", error));
3820
+ } finally {
3821
+ request.dispose();
3678
3822
  }
3679
3823
  });
3680
3824
  }
@@ -3683,6 +3827,7 @@ var DuckDbService = class extends BaseService {
3683
3827
  if (!this.requireAuth()) {
3684
3828
  return err(authRequiredError("duckdb"));
3685
3829
  }
3830
+ const request = this.createRequestSignal(options?.signal);
3686
3831
  try {
3687
3832
  const session = this.context.session;
3688
3833
  const headers = this.context.invoke(
@@ -3698,7 +3843,7 @@ var DuckDbService = class extends BaseService {
3698
3843
  "Content-Type": "application/x-duckdb"
3699
3844
  },
3700
3845
  body: new Blob([data]),
3701
- signal: this.combineSignals(options?.signal)
3846
+ signal: request.signal
3702
3847
  });
3703
3848
  if (!response.ok) {
3704
3849
  return this.handleErrorResponse(response, "import");
@@ -3706,6 +3851,8 @@ var DuckDbService = class extends BaseService {
3706
3851
  return ok(void 0);
3707
3852
  } catch (error) {
3708
3853
  return err(wrapError("duckdb", error));
3854
+ } finally {
3855
+ request.dispose();
3709
3856
  }
3710
3857
  });
3711
3858
  }
@@ -3721,7 +3868,7 @@ var DuckDbService = class extends BaseService {
3721
3868
  ...extraHeaders
3722
3869
  },
3723
3870
  body: JSON.stringify(body),
3724
- signal: this.combineSignals(signal)
3871
+ signal
3725
3872
  });
3726
3873
  }
3727
3874
  async handleErrorResponse(response, operation) {