@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.js CHANGED
@@ -1055,11 +1055,31 @@ function networkError(service, message, cause) {
1055
1055
  cause
1056
1056
  };
1057
1057
  }
1058
- function timeoutError(service) {
1058
+ var RequestTimeoutError = class extends Error {
1059
+ constructor(timeoutMs) {
1060
+ super(`Request timed out after ${timeoutMs}ms.`);
1061
+ this.name = "TimeoutError";
1062
+ this.timeoutMs = timeoutMs;
1063
+ }
1064
+ };
1065
+ function isRequestTimeoutError(error) {
1066
+ return error instanceof RequestTimeoutError || error instanceof Error && error.name === "TimeoutError" && typeof error.timeoutMs === "number";
1067
+ }
1068
+ function timeoutError(service, timeoutMs, cause) {
1069
+ if (timeoutMs === void 0) {
1070
+ return {
1071
+ code: ErrorCodes.TIMEOUT,
1072
+ message: "Request timed out.",
1073
+ service,
1074
+ ...cause === void 0 ? {} : { cause }
1075
+ };
1076
+ }
1059
1077
  return {
1060
1078
  code: ErrorCodes.TIMEOUT,
1061
- message: "Request timed out.",
1062
- service
1079
+ message: `Request timed out after ${timeoutMs}ms.`,
1080
+ service,
1081
+ ...cause === void 0 ? {} : { cause },
1082
+ meta: { timeoutMs }
1063
1083
  };
1064
1084
  }
1065
1085
  function abortedError(service) {
@@ -1223,6 +1243,9 @@ function isStorageFullError(error) {
1223
1243
  }
1224
1244
  function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
1225
1245
  if (error instanceof Error) {
1246
+ if (isRequestTimeoutError(error)) {
1247
+ return timeoutError(service, error.timeoutMs, error);
1248
+ }
1226
1249
  if (error.name === "AbortError") {
1227
1250
  return abortedError(service);
1228
1251
  }
@@ -1247,6 +1270,7 @@ function errorResult(error) {
1247
1270
  }
1248
1271
 
1249
1272
  // src/base/BaseService.ts
1273
+ var MAX_TIMER_DELAY_MS = 2147483647;
1250
1274
  var BaseService = class {
1251
1275
  constructor() {
1252
1276
  /**
@@ -1427,6 +1451,64 @@ var BaseService = class {
1427
1451
  }
1428
1452
  return controller.signal;
1429
1453
  }
1454
+ /**
1455
+ * Create the abort signal for one request, bounded by the request timeout.
1456
+ *
1457
+ * The signal aborts when the service signs out, the context aborts, the
1458
+ * caller's `signal` aborts, or the timeout elapses, whichever comes first.
1459
+ * A timeout aborts with a {@link RequestTimeoutError} (`TimeoutError`), which
1460
+ * `wrapError` maps to `ErrorCodes.TIMEOUT`; the other sources keep their own
1461
+ * reason (normally `AbortError`, mapped to `ErrorCodes.ABORTED`).
1462
+ *
1463
+ * The timeout is `timeoutMs` when given, otherwise `config.timeout`. Only a
1464
+ * positive, finite value (at most 2^31-1 ms) applies; `undefined`, `0`, and
1465
+ * `Infinity` mean no timeout, so a per-call `0` opts out of a configured one.
1466
+ *
1467
+ * Callers must call `dispose()` once the response body has been consumed,
1468
+ * which clears the timer and removes the listeners this adds to the
1469
+ * long-lived service and context signals.
1470
+ *
1471
+ * @param signal - The caller's abort signal for this request
1472
+ * @param timeoutMs - Per-request timeout override in milliseconds
1473
+ */
1474
+ createRequestSignal(signal, timeoutMs) {
1475
+ const controller = new AbortController();
1476
+ const detachers = [];
1477
+ let timer;
1478
+ const dispose = () => {
1479
+ if (timer !== void 0) {
1480
+ clearTimeout(timer);
1481
+ timer = void 0;
1482
+ }
1483
+ for (const detach of detachers.splice(0)) {
1484
+ detach();
1485
+ }
1486
+ };
1487
+ const abort = (reason) => {
1488
+ dispose();
1489
+ controller.abort(reason);
1490
+ };
1491
+ const requestSignal = { signal: controller.signal, dispose };
1492
+ const parents = [
1493
+ this.abortController.signal,
1494
+ this.context?.abortSignal,
1495
+ signal
1496
+ ].filter((parent) => parent !== void 0);
1497
+ for (const parent of parents) {
1498
+ if (parent.aborted) {
1499
+ abort(parent.reason);
1500
+ return requestSignal;
1501
+ }
1502
+ const onAbort = () => abort(parent.reason);
1503
+ parent.addEventListener("abort", onAbort, { once: true });
1504
+ detachers.push(() => parent.removeEventListener("abort", onAbort));
1505
+ }
1506
+ const timeout = timeoutMs ?? this._config.timeout;
1507
+ if (typeof timeout === "number" && timeout > 0 && timeout <= MAX_TIMER_DELAY_MS) {
1508
+ timer = setTimeout(() => abort(new RequestTimeoutError(timeout)), timeout);
1509
+ }
1510
+ return requestSignal;
1511
+ }
1430
1512
  /**
1431
1513
  * Wrap an operation with error handling and telemetry.
1432
1514
  *
@@ -1687,7 +1769,7 @@ var KVService = class extends BaseService {
1687
1769
  * @param path - Resource path
1688
1770
  * @param action - KV action
1689
1771
  * @param body - Optional request body
1690
- * @param signal - Optional abort signal
1772
+ * @param signal - Request signal from createRequestSignal()
1691
1773
  * @returns Fetch response
1692
1774
  */
1693
1775
  async invokeOperation(path, action, body, signal, extraHeaders) {
@@ -1703,7 +1785,7 @@ var KVService = class extends BaseService {
1703
1785
  method: "POST",
1704
1786
  headers: requestHeaders,
1705
1787
  body,
1706
- signal: this.combineSignals(signal)
1788
+ signal
1707
1789
  });
1708
1790
  }
1709
1791
  /**
@@ -1880,6 +1962,7 @@ var KVService = class extends BaseService {
1880
1962
  "kv"
1881
1963
  ));
1882
1964
  }
1965
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
1883
1966
  try {
1884
1967
  const session = this.context.session;
1885
1968
  const invocationHeaders = this.context.invokeAny(
@@ -1901,7 +1984,7 @@ var KVService = class extends BaseService {
1901
1984
  const response = await this.context.fetch(`${this.host}/invoke`, {
1902
1985
  method: "POST",
1903
1986
  headers,
1904
- signal: this.combineSignals(options?.signal)
1987
+ signal: request.signal
1905
1988
  });
1906
1989
  if (!response.ok) {
1907
1990
  const errorText = response.status === 401 || response.status === 403 ? await this.readAuthorizationText(response) : await response.text();
@@ -1966,6 +2049,8 @@ var KVService = class extends BaseService {
1966
2049
  return ok({ results, count: results.length });
1967
2050
  } catch (error) {
1968
2051
  return err(wrapError("kv", error));
2052
+ } finally {
2053
+ request.dispose();
1969
2054
  }
1970
2055
  }
1971
2056
  /**
@@ -2098,12 +2183,13 @@ var KVService = class extends BaseService {
2098
2183
  ));
2099
2184
  }
2100
2185
  const path = this.getFullPath(key, options?.prefix);
2186
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2101
2187
  try {
2102
2188
  const response = await this.invokeOperation(
2103
2189
  path,
2104
2190
  KVAction.GET,
2105
2191
  void 0,
2106
- options?.signal,
2192
+ request.signal,
2107
2193
  options?.maxResponseBytes === void 0 ? void 0 : { "x-tinycloud-max-response-bytes": String(options.maxResponseBytes) }
2108
2194
  );
2109
2195
  if (!response.ok) {
@@ -2160,6 +2246,8 @@ var KVService = class extends BaseService {
2160
2246
  });
2161
2247
  } catch (error) {
2162
2248
  return err(wrapError("kv", error));
2249
+ } finally {
2250
+ request.dispose();
2163
2251
  }
2164
2252
  });
2165
2253
  }
@@ -2187,12 +2275,13 @@ var KVService = class extends BaseService {
2187
2275
  }
2188
2276
  const path = this.getFullPath(key, options?.prefix);
2189
2277
  const body = this.serializePutValue(value, options?.contentType);
2278
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2190
2279
  try {
2191
2280
  const response = await this.invokeOperation(
2192
2281
  path,
2193
2282
  KVAction.PUT,
2194
2283
  body,
2195
- options?.signal,
2284
+ request.signal,
2196
2285
  {
2197
2286
  ...options?.ifMatch === void 0 ? {} : { "if-match": options.ifMatch },
2198
2287
  ...options?.ifNoneMatch === void 0 ? {} : { "if-none-match": options.ifNoneMatch }
@@ -2248,6 +2337,8 @@ var KVService = class extends BaseService {
2248
2337
  });
2249
2338
  } catch (error) {
2250
2339
  return err(wrapError("kv", error));
2340
+ } finally {
2341
+ request.dispose();
2251
2342
  }
2252
2343
  });
2253
2344
  }
@@ -2287,6 +2378,7 @@ var KVService = class extends BaseService {
2287
2378
  seen.add(path);
2288
2379
  }
2289
2380
  let requestMayHaveDispatched = false;
2381
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2290
2382
  try {
2291
2383
  const body = new FormData();
2292
2384
  for (let index = 0; index < items.length; index++) {
@@ -2309,7 +2401,7 @@ var KVService = class extends BaseService {
2309
2401
  method: "POST",
2310
2402
  headers,
2311
2403
  body,
2312
- signal: this.combineSignals(options?.signal)
2404
+ signal: request.signal
2313
2405
  };
2314
2406
  const fetchFn = this.context.fetch;
2315
2407
  requestMayHaveDispatched = true;
@@ -2360,14 +2452,16 @@ var KVService = class extends BaseService {
2360
2452
  rawBody = await response.json();
2361
2453
  } catch (jsonError) {
2362
2454
  const cause = jsonError instanceof Error ? jsonError : new Error(String(jsonError));
2455
+ const timedOut = isRequestTimeoutError(cause);
2363
2456
  return err(
2364
2457
  serviceError(
2365
- ErrorCodes.NETWORK_ERROR,
2366
- `KV batchPut response was not valid JSON: ${cause.message}`,
2458
+ timedOut ? ErrorCodes.TIMEOUT : ErrorCodes.NETWORK_ERROR,
2459
+ timedOut ? `KV batchPut response body did not arrive in time: ${cause.message}` : `KV batchPut response was not valid JSON: ${cause.message}`,
2367
2460
  "kv",
2368
2461
  {
2369
2462
  cause,
2370
2463
  meta: {
2464
+ ...timedOut ? { timeoutMs: cause.timeoutMs } : {},
2371
2465
  requestMayHaveDispatched: true,
2372
2466
  responseReceived: true,
2373
2467
  status: response.status,
@@ -2422,6 +2516,8 @@ var KVService = class extends BaseService {
2422
2516
  ...wrapped,
2423
2517
  meta: { ...wrapped.meta, requestMayHaveDispatched }
2424
2518
  });
2519
+ } finally {
2520
+ request.dispose();
2425
2521
  }
2426
2522
  });
2427
2523
  }
@@ -2444,12 +2540,13 @@ var KVService = class extends BaseService {
2444
2540
  if (options?.path) {
2445
2541
  listPath = listPath ? `${listPath}/${options.path}` : options.path;
2446
2542
  }
2543
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2447
2544
  try {
2448
2545
  const response = await this.invokeOperation(
2449
2546
  listPath,
2450
2547
  KVAction.LIST,
2451
2548
  void 0,
2452
- options?.signal,
2549
+ request.signal,
2453
2550
  options?.limit === void 0 && options?.cursor === void 0 ? void 0 : {
2454
2551
  ...options?.limit === void 0 ? {} : { "x-tinycloud-limit": String(options.limit) },
2455
2552
  ...options?.cursor === void 0 ? {} : { "x-tinycloud-cursor": options.cursor }
@@ -2490,6 +2587,8 @@ var KVService = class extends BaseService {
2490
2587
  });
2491
2588
  } catch (error) {
2492
2589
  return err(wrapError("kv", error));
2590
+ } finally {
2591
+ request.dispose();
2493
2592
  }
2494
2593
  });
2495
2594
  }
@@ -2502,12 +2601,13 @@ var KVService = class extends BaseService {
2502
2601
  return err(authRequiredError("kv"));
2503
2602
  }
2504
2603
  const path = this.getFullPath(key, options?.prefix);
2604
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2505
2605
  try {
2506
2606
  const response = await this.invokeOperation(
2507
2607
  path,
2508
2608
  KVAction.DELETE,
2509
2609
  void 0,
2510
- options?.signal,
2610
+ request.signal,
2511
2611
  options?.ifMatch === void 0 ? void 0 : { "if-match": options.ifMatch }
2512
2612
  );
2513
2613
  if (!response.ok) {
@@ -2555,6 +2655,8 @@ var KVService = class extends BaseService {
2555
2655
  });
2556
2656
  } catch (error) {
2557
2657
  return err(wrapError("kv", error));
2658
+ } finally {
2659
+ request.dispose();
2558
2660
  }
2559
2661
  });
2560
2662
  }
@@ -2567,12 +2669,13 @@ var KVService = class extends BaseService {
2567
2669
  return err(authRequiredError("kv"));
2568
2670
  }
2569
2671
  const path = this.getFullPath(key, options?.prefix);
2672
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2570
2673
  try {
2571
2674
  const response = await this.invokeOperation(
2572
2675
  path,
2573
2676
  KVAction.HEAD,
2574
2677
  void 0,
2575
- options?.signal
2678
+ request.signal
2576
2679
  );
2577
2680
  if (!response.ok) {
2578
2681
  if (response.status === 401 || response.status === 403) {
@@ -2603,6 +2706,8 @@ var KVService = class extends BaseService {
2603
2706
  });
2604
2707
  } catch (error) {
2605
2708
  return err(wrapError("kv", error));
2709
+ } finally {
2710
+ request.dispose();
2606
2711
  }
2607
2712
  });
2608
2713
  }
@@ -2640,12 +2745,13 @@ var KVService = class extends BaseService {
2640
2745
  if (options?.etag !== void 0) {
2641
2746
  body.etag = options.etag;
2642
2747
  }
2748
+ const request = this.createRequestSignal(options?.signal, options?.timeout);
2643
2749
  try {
2644
2750
  const response = await this.context.fetch(`${this.host}/signed/kv`, {
2645
2751
  method: "POST",
2646
2752
  headers: this.withJsonContentType(headers),
2647
2753
  body: JSON.stringify(body),
2648
- signal: this.combineSignals(options?.signal)
2754
+ signal: request.signal
2649
2755
  });
2650
2756
  if (!response.ok) {
2651
2757
  return this.createSignedReadUrlError(response, key, path);
@@ -2665,6 +2771,8 @@ var KVService = class extends BaseService {
2665
2771
  return ok(signedUrl);
2666
2772
  } catch (error) {
2667
2773
  return err(wrapError("kv", error));
2774
+ } finally {
2775
+ request.dispose();
2668
2776
  }
2669
2777
  });
2670
2778
  }
@@ -2878,6 +2986,7 @@ var SQLService = class extends BaseService {
2878
2986
  if (!this.requireAuth()) {
2879
2987
  return err(authRequiredError("sql"));
2880
2988
  }
2989
+ const request = this.createRequestSignal(options?.signal);
2881
2990
  try {
2882
2991
  const body = {
2883
2992
  action: "query",
@@ -2891,7 +3000,7 @@ var SQLService = class extends BaseService {
2891
3000
  dbName,
2892
3001
  action,
2893
3002
  body,
2894
- options?.signal
3003
+ request.signal
2895
3004
  );
2896
3005
  if (!response.ok) {
2897
3006
  return this.handleErrorResponse(response, "query", dbName, [action]);
@@ -2900,6 +3009,8 @@ var SQLService = class extends BaseService {
2900
3009
  return ok(data);
2901
3010
  } catch (error) {
2902
3011
  return err(wrapError("sql", error));
3012
+ } finally {
3013
+ request.dispose();
2903
3014
  }
2904
3015
  });
2905
3016
  }
@@ -2908,6 +3019,7 @@ var SQLService = class extends BaseService {
2908
3019
  if (!this.requireAuth()) {
2909
3020
  return err(authRequiredError("sql"));
2910
3021
  }
3022
+ const request = this.createRequestSignal(options?.signal);
2911
3023
  try {
2912
3024
  const body = {
2913
3025
  action: "execute",
@@ -2928,7 +3040,7 @@ var SQLService = class extends BaseService {
2928
3040
  dbName,
2929
3041
  requestedActions,
2930
3042
  body,
2931
- options?.signal
3043
+ request.signal
2932
3044
  );
2933
3045
  if (!response.ok) {
2934
3046
  return this.handleErrorResponse(response, "execute", dbName, requestedActions);
@@ -2937,6 +3049,8 @@ var SQLService = class extends BaseService {
2937
3049
  return ok(data);
2938
3050
  } catch (error) {
2939
3051
  return err(wrapError("sql", error));
3052
+ } finally {
3053
+ request.dispose();
2940
3054
  }
2941
3055
  });
2942
3056
  }
@@ -2945,13 +3059,14 @@ var SQLService = class extends BaseService {
2945
3059
  if (!this.requireAuth()) {
2946
3060
  return err(authRequiredError("sql"));
2947
3061
  }
3062
+ const request = this.createRequestSignal(options?.signal);
2948
3063
  try {
2949
3064
  const requestedActions = this.actionsForSqlBatch(statements);
2950
3065
  const response = await this.invokeSQL(
2951
3066
  dbName,
2952
3067
  requestedActions,
2953
3068
  { action: "batch", statements },
2954
- options?.signal
3069
+ request.signal
2955
3070
  );
2956
3071
  if (!response.ok) {
2957
3072
  return this.handleErrorResponse(response, "batch", dbName, requestedActions);
@@ -2960,6 +3075,8 @@ var SQLService = class extends BaseService {
2960
3075
  return ok(data);
2961
3076
  } catch (error) {
2962
3077
  return err(wrapError("sql", error));
3078
+ } finally {
3079
+ request.dispose();
2963
3080
  }
2964
3081
  });
2965
3082
  }
@@ -2968,12 +3085,13 @@ var SQLService = class extends BaseService {
2968
3085
  if (!this.requireAuth()) {
2969
3086
  return err(authRequiredError("sql"));
2970
3087
  }
3088
+ const request = this.createRequestSignal(options?.signal);
2971
3089
  try {
2972
3090
  const response = await this.invokeSQL(
2973
3091
  dbName,
2974
3092
  SQLAction.WRITE,
2975
3093
  { action: "execute_statement", name, params: params ?? [] },
2976
- options?.signal
3094
+ request.signal
2977
3095
  );
2978
3096
  if (!response.ok) {
2979
3097
  return this.handleErrorResponse(response, "executeStatement", dbName, [SQLAction.WRITE]);
@@ -2982,6 +3100,8 @@ var SQLService = class extends BaseService {
2982
3100
  return ok(data);
2983
3101
  } catch (error) {
2984
3102
  return err(wrapError("sql", error));
3103
+ } finally {
3104
+ request.dispose();
2985
3105
  }
2986
3106
  });
2987
3107
  }
@@ -2990,12 +3110,13 @@ var SQLService = class extends BaseService {
2990
3110
  if (!this.requireAuth()) {
2991
3111
  return err(authRequiredError("sql"));
2992
3112
  }
3113
+ const request = this.createRequestSignal(options?.signal);
2993
3114
  try {
2994
3115
  const response = await this.invokeSQL(
2995
3116
  dbName,
2996
3117
  SQLAction.READ,
2997
3118
  { action: "export" },
2998
- options?.signal
3119
+ request.signal
2999
3120
  );
3000
3121
  if (!response.ok) {
3001
3122
  return this.handleErrorResponse(response, "export", dbName, [SQLAction.READ]);
@@ -3009,6 +3130,8 @@ var SQLService = class extends BaseService {
3009
3130
  return ok(text);
3010
3131
  } catch (error) {
3011
3132
  return err(wrapError("sql", error));
3133
+ } finally {
3134
+ request.dispose();
3012
3135
  }
3013
3136
  });
3014
3137
  }
@@ -3099,7 +3222,7 @@ var SQLService = class extends BaseService {
3099
3222
  "Content-Type": "application/json"
3100
3223
  },
3101
3224
  body: JSON.stringify(body),
3102
- signal: this.combineSignals(signal)
3225
+ signal
3103
3226
  });
3104
3227
  }
3105
3228
  actionForSql(sql, fallback) {
@@ -3363,12 +3486,13 @@ var DuckDbService = class extends BaseService {
3363
3486
  if (!this.requireAuth()) {
3364
3487
  return err(authRequiredError("duckdb"));
3365
3488
  }
3489
+ const request = this.createRequestSignal(options?.signal);
3366
3490
  try {
3367
3491
  const response = await this.invokeDuckDb(
3368
3492
  dbName,
3369
3493
  DuckDbAction.READ,
3370
3494
  { action: "query", sql, params: params ?? [] },
3371
- options?.signal
3495
+ request.signal
3372
3496
  );
3373
3497
  if (!response.ok) {
3374
3498
  return this.handleErrorResponse(response, "query");
@@ -3377,6 +3501,8 @@ var DuckDbService = class extends BaseService {
3377
3501
  return ok(data);
3378
3502
  } catch (error) {
3379
3503
  return err(wrapError("duckdb", error));
3504
+ } finally {
3505
+ request.dispose();
3380
3506
  }
3381
3507
  });
3382
3508
  }
@@ -3385,12 +3511,13 @@ var DuckDbService = class extends BaseService {
3385
3511
  if (!this.requireAuth()) {
3386
3512
  return err(authRequiredError("duckdb"));
3387
3513
  }
3514
+ const request = this.createRequestSignal(options?.signal);
3388
3515
  try {
3389
3516
  const response = await this.invokeDuckDb(
3390
3517
  dbName,
3391
3518
  DuckDbAction.READ,
3392
3519
  { action: "query", sql, params: params ?? [] },
3393
- options?.signal,
3520
+ request.signal,
3394
3521
  { Accept: "application/vnd.apache.arrow.stream" }
3395
3522
  );
3396
3523
  if (!response.ok) {
@@ -3400,6 +3527,8 @@ var DuckDbService = class extends BaseService {
3400
3527
  return ok(buffer);
3401
3528
  } catch (error) {
3402
3529
  return err(wrapError("duckdb", error));
3530
+ } finally {
3531
+ request.dispose();
3403
3532
  }
3404
3533
  });
3405
3534
  }
@@ -3408,6 +3537,7 @@ var DuckDbService = class extends BaseService {
3408
3537
  if (!this.requireAuth()) {
3409
3538
  return err(authRequiredError("duckdb"));
3410
3539
  }
3540
+ const request = this.createRequestSignal(options?.signal);
3411
3541
  try {
3412
3542
  const body = {
3413
3543
  action: "execute",
@@ -3421,7 +3551,7 @@ var DuckDbService = class extends BaseService {
3421
3551
  dbName,
3422
3552
  DuckDbAction.WRITE,
3423
3553
  body,
3424
- options?.signal
3554
+ request.signal
3425
3555
  );
3426
3556
  if (!response.ok) {
3427
3557
  return this.handleErrorResponse(response, "execute");
@@ -3430,6 +3560,8 @@ var DuckDbService = class extends BaseService {
3430
3560
  return ok(data);
3431
3561
  } catch (error) {
3432
3562
  return err(wrapError("duckdb", error));
3563
+ } finally {
3564
+ request.dispose();
3433
3565
  }
3434
3566
  });
3435
3567
  }
@@ -3438,6 +3570,7 @@ var DuckDbService = class extends BaseService {
3438
3570
  if (!this.requireAuth()) {
3439
3571
  return err(authRequiredError("duckdb"));
3440
3572
  }
3573
+ const request = this.createRequestSignal(options?.signal);
3441
3574
  try {
3442
3575
  const body = {
3443
3576
  action: "batch",
@@ -3450,7 +3583,7 @@ var DuckDbService = class extends BaseService {
3450
3583
  dbName,
3451
3584
  DuckDbAction.WRITE,
3452
3585
  body,
3453
- options?.signal
3586
+ request.signal
3454
3587
  );
3455
3588
  if (!response.ok) {
3456
3589
  return this.handleErrorResponse(response, "batch");
@@ -3459,6 +3592,8 @@ var DuckDbService = class extends BaseService {
3459
3592
  return ok(data);
3460
3593
  } catch (error) {
3461
3594
  return err(wrapError("duckdb", error));
3595
+ } finally {
3596
+ request.dispose();
3462
3597
  }
3463
3598
  });
3464
3599
  }
@@ -3467,12 +3602,13 @@ var DuckDbService = class extends BaseService {
3467
3602
  if (!this.requireAuth()) {
3468
3603
  return err(authRequiredError("duckdb"));
3469
3604
  }
3605
+ const request = this.createRequestSignal(options?.signal);
3470
3606
  try {
3471
3607
  const response = await this.invokeDuckDb(
3472
3608
  dbName,
3473
3609
  DuckDbAction.WRITE,
3474
3610
  { action: "executeStatement", name, params: params ?? [] },
3475
- options?.signal
3611
+ request.signal
3476
3612
  );
3477
3613
  if (!response.ok) {
3478
3614
  return this.handleErrorResponse(response, "executeStatement");
@@ -3481,6 +3617,8 @@ var DuckDbService = class extends BaseService {
3481
3617
  return ok(data);
3482
3618
  } catch (error) {
3483
3619
  return err(wrapError("duckdb", error));
3620
+ } finally {
3621
+ request.dispose();
3484
3622
  }
3485
3623
  });
3486
3624
  }
@@ -3489,12 +3627,13 @@ var DuckDbService = class extends BaseService {
3489
3627
  if (!this.requireAuth()) {
3490
3628
  return err(authRequiredError("duckdb"));
3491
3629
  }
3630
+ const request = this.createRequestSignal(options?.signal);
3492
3631
  try {
3493
3632
  const response = await this.invokeDuckDb(
3494
3633
  dbName,
3495
3634
  DuckDbAction.READ,
3496
3635
  { action: "describe" },
3497
- options?.signal
3636
+ request.signal
3498
3637
  );
3499
3638
  if (!response.ok) {
3500
3639
  return this.handleErrorResponse(response, "describe");
@@ -3503,6 +3642,8 @@ var DuckDbService = class extends BaseService {
3503
3642
  return ok(data);
3504
3643
  } catch (error) {
3505
3644
  return err(wrapError("duckdb", error));
3645
+ } finally {
3646
+ request.dispose();
3506
3647
  }
3507
3648
  });
3508
3649
  }
@@ -3511,12 +3652,13 @@ var DuckDbService = class extends BaseService {
3511
3652
  if (!this.requireAuth()) {
3512
3653
  return err(authRequiredError("duckdb"));
3513
3654
  }
3655
+ const request = this.createRequestSignal(options?.signal);
3514
3656
  try {
3515
3657
  const response = await this.invokeDuckDb(
3516
3658
  dbName,
3517
3659
  DuckDbAction.EXPORT,
3518
3660
  { action: "export" },
3519
- options?.signal
3661
+ request.signal
3520
3662
  );
3521
3663
  if (!response.ok) {
3522
3664
  return this.handleErrorResponse(response, "export");
@@ -3525,6 +3667,8 @@ var DuckDbService = class extends BaseService {
3525
3667
  return ok(blob);
3526
3668
  } catch (error) {
3527
3669
  return err(wrapError("duckdb", error));
3670
+ } finally {
3671
+ request.dispose();
3528
3672
  }
3529
3673
  });
3530
3674
  }
@@ -3533,6 +3677,7 @@ var DuckDbService = class extends BaseService {
3533
3677
  if (!this.requireAuth()) {
3534
3678
  return err(authRequiredError("duckdb"));
3535
3679
  }
3680
+ const request = this.createRequestSignal(options?.signal);
3536
3681
  try {
3537
3682
  const session = this.context.session;
3538
3683
  const headers = this.context.invoke(
@@ -3548,7 +3693,7 @@ var DuckDbService = class extends BaseService {
3548
3693
  "Content-Type": "application/x-duckdb"
3549
3694
  },
3550
3695
  body: new Blob([data]),
3551
- signal: this.combineSignals(options?.signal)
3696
+ signal: request.signal
3552
3697
  });
3553
3698
  if (!response.ok) {
3554
3699
  return this.handleErrorResponse(response, "import");
@@ -3556,6 +3701,8 @@ var DuckDbService = class extends BaseService {
3556
3701
  return ok(void 0);
3557
3702
  } catch (error) {
3558
3703
  return err(wrapError("duckdb", error));
3704
+ } finally {
3705
+ request.dispose();
3559
3706
  }
3560
3707
  });
3561
3708
  }
@@ -3571,7 +3718,7 @@ var DuckDbService = class extends BaseService {
3571
3718
  ...extraHeaders
3572
3719
  },
3573
3720
  body: JSON.stringify(body),
3574
- signal: this.combineSignals(signal)
3721
+ signal
3575
3722
  });
3576
3723
  }
3577
3724
  async handleErrorResponse(response, operation) {