@adonix.org/cloud-spark 0.0.162 → 0.0.164

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ⚡️ Cloud Spark
1
+ # ⚡️Cloud Spark
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@adonix.org/cloud-spark.svg?color=blue)](https://www.npmjs.com/package/@adonix.org/cloud-spark)
4
4
  [![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/adonix-org/cloud-spark/blob/main/LICENSE)
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import CacheLib from 'cache-control-parser';
2
- import { MatchFunction } from 'path-to-regexp';
3
1
  import { StatusCodes } from 'http-status-codes';
4
2
  export { StatusCodes } from 'http-status-codes';
3
+ import CacheLib from 'cache-control-parser';
4
+ import { MatchFunction } from 'path-to-regexp';
5
5
 
6
6
  /**
7
7
  * @see {@link https://github.com/etienne-martin/cache-control-parser | cache-control-parser}
@@ -19,38 +19,6 @@ declare const CacheControl: {
19
19
  }>;
20
20
  };
21
21
 
22
- /**
23
- * https://github.com/prettymuchbryce/http-status-codes
24
- */
25
-
26
- /**
27
- * Standard HTTP header names and common values.
28
- */
29
- declare namespace HttpHeader {
30
- const ALLOW = "Allow";
31
- const ACCEPT_ENCODING = "Accept-Encoding";
32
- const ORIGIN = "Origin";
33
- const CONTENT_TYPE = "Content-Type";
34
- const CACHE_CONTROL = "Cache-Control";
35
- const USER_AGENT = "User-Agent";
36
- const VARY = "Vary";
37
- const CONTENT_SECURITY_POLICY = "Content-Security-Policy";
38
- const PERMISSIONS_POLICY = "Permissions-Policy";
39
- const STRICT_TRANSPORT_SECURITY = "Strict-Transport-Security";
40
- const REFERRER_POLICY = "Referrer-Policy";
41
- const X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options";
42
- const X_FRAME_OPTIONS = "X-Frame-Options";
43
- const ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
44
- const ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
45
- const ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
46
- const ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
47
- const ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
48
- const ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
49
- const ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
50
- const SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
51
- const CONNECTION = "Connection";
52
- const UPGRADE = "Upgrade";
53
- }
54
22
  /**
55
23
  * Standard HTTP request methods.
56
24
  */
@@ -77,55 +45,6 @@ declare const PATCH: Method;
77
45
  declare const DELETE: Method;
78
46
  declare const OPTIONS: Method;
79
47
 
80
- /**
81
- * Common media types used for HTTP headers.
82
- */
83
- declare enum MediaType {
84
- PLAIN_TEXT = "text/plain",
85
- HTML = "text/html",
86
- CSS = "text/css",
87
- CSV = "text/csv",
88
- XML = "text/xml",
89
- MARKDOWN = "text/markdown",
90
- RICH_TEXT = "text/richtext",
91
- JSON = "application/json",
92
- XML_APP = "application/xml",
93
- YAML = "application/x-yaml",
94
- FORM_URLENCODED = "application/x-www-form-urlencoded",
95
- NDJSON = "application/x-ndjson",
96
- MSGPACK = "application/x-msgpack",
97
- PROTOBUF = "application/x-protobuf",
98
- MULTIPART_FORM_DATA = "multipart/form-data",
99
- MULTIPART_MIXED = "multipart/mixed",
100
- MULTIPART_ALTERNATIVE = "multipart/alternative",
101
- MULTIPART_DIGEST = "multipart/digest",
102
- MULTIPART_RELATED = "multipart/related",
103
- MULTIPART_SIGNED = "multipart/signed",
104
- MULTIPART_ENCRYPTED = "multipart/encrypted",
105
- OCTET_STREAM = "application/octet-stream",
106
- PDF = "application/pdf",
107
- ZIP = "application/zip",
108
- GZIP = "application/gzip",
109
- MSWORD = "application/msword",
110
- DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
111
- EXCEL = "application/vnd.ms-excel",
112
- XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
113
- POWERPOINT = "application/vnd.ms-powerpoint",
114
- PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
115
- ICO = "image/x-icon",
116
- ICO_MS = "image/vnd.microsoft.icon",
117
- GIF = "image/gif",
118
- PNG = "image/png",
119
- JPEG = "image/jpeg",
120
- WEBP = "image/webp",
121
- SVG = "image/svg+xml",
122
- HEIF = "image/heif",
123
- AVIF = "image/avif",
124
- EVENT_STREAM = "text/event-stream",
125
- TAR = "application/x-tar",
126
- BZIP2 = "application/x-bzip2"
127
- }
128
-
129
48
  /**
130
49
  * Time constants in seconds. Month is approximated as 30 days.
131
50
  */
@@ -139,65 +58,8 @@ declare const Time: {
139
58
  readonly Year: 31536000;
140
59
  };
141
60
 
142
- /** WebSocket upgrade header value */
143
- declare const WS_UPGRADE = "upgrade";
144
- /** WebSocket protocol header value */
145
- declare const WS_WEBSOCKET = "websocket";
146
- /** WebSocket protocol version */
147
- declare const WS_VERSION = "13";
148
- /** Max close code a user can send */
149
- declare const WS_MAX_CLOSE_CODE = 4999;
150
- /** Max number of reason chars a user can send */
151
- declare const WS_MAX_REASON_CHARS = 123;
152
- /** WebSocket close codes */
153
- declare const CloseCode: {
154
- readonly NORMAL: 1000;
155
- readonly GOING_AWAY: 1001;
156
- readonly PROTOCOL_ERROR: 1002;
157
- readonly UNSUPPORTED_DATA: 1003;
158
- readonly NO_STATUS: 1005;
159
- readonly ABNORMAL: 1006;
160
- readonly INVALID_PAYLOAD: 1007;
161
- readonly POLICY_VIOLATION: 1008;
162
- readonly MESSAGE_TOO_BIG: 1009;
163
- readonly MISSING_EXTENSION: 1010;
164
- readonly INTERNAL_ERROR: 1011;
165
- readonly TLS_HANDSHAKE: 1015;
166
- };
167
- /** WebSocket RESERVED close codes */
168
- declare const WS_RESERVED_CODES: Set<number>;
169
-
170
- /**
171
- * Type guard that checks if a string is a valid HTTP method.
172
- *
173
- * @param value - The string to test.
174
- * @returns True if `value` is a recognized HTTP method.
175
- */
176
- declare function isMethod(value: unknown): value is Method;
177
61
  /**
178
- * Checks if a value is an array of valid HTTP methods.
179
- *
180
- * Each element is verified using the `isMethod` type guard.
181
- *
182
- * @param value - The value to check.
183
- * @returns `true` if `value` is an array and every element is a valid `Method`, otherwise `false`.
184
- */
185
- declare function isMethodArray(value: unknown): value is Method[];
186
- /**
187
- * Asserts that a value is an array of valid HTTP methods.
188
- *
189
- * This function uses {@link isMethodArray} to validate the input. If the
190
- * value is not an array of `Method` elements, it throws a `TypeError`.
191
- * Otherwise, TypeScript will narrow the type of `value` to `Method[]`
192
- * within the calling scope.
193
- *
194
- * @param value - The value to check.
195
- * @throws TypeError If `value` is not a valid method array.
196
- */
197
- declare function assertMethods(value: unknown): asserts value is Method[];
198
-
199
- /**
200
- * User-supplied options for configuring CORS behavior.
62
+ * User-supplied options for configuring`CORS`behavior.
201
63
  *
202
64
  * This is a partial form of {@link CorsConfig}, meaning you only need
203
65
  * to provide the options you want to override. Any missing values will
@@ -213,9 +75,9 @@ declare function assertMethods(value: unknown): asserts value is Method[];
213
75
  */
214
76
  type CorsInit = Partial<CorsConfig>;
215
77
  /**
216
- * Configuration options for Cross-Origin Resource Sharing (CORS).
78
+ * Configuration options for Cross-Origin Resource Sharing `CORS`.
217
79
  *
218
- * Implementations of CORS middleware use this interface to determine
80
+ * Implementations of `CORS` middleware use this interface to determine
219
81
  * how cross-origin requests are validated and which headers are sent
220
82
  * in the response.
221
83
  *
@@ -232,7 +94,7 @@ type CorsInit = Partial<CorsConfig>;
232
94
  */
233
95
  interface CorsConfig {
234
96
  /**
235
- * Origins allowed for CORS requests.
97
+ * Origins allowed for `CORS` requests.
236
98
  *
237
99
  * Use `["*"]` to allow all origins, or provide a list of specific origins.
238
100
  * Example: `["https://example.com", "https://api.example.com"]`
@@ -241,9 +103,9 @@ interface CorsConfig {
241
103
  */
242
104
  allowedOrigins: string[];
243
105
  /**
244
- * HTTP headers allowed in CORS requests.
106
+ * HTTP headers allowed in `CORS` requests.
245
107
  *
246
- * Browsers always allow *CORS-safelisted request headers* without preflight:
108
+ * Browsers always allow `CORS`-safelisted request headers* without preflight:
247
109
  * - `Accept`
248
110
  * - `Accept-Language`
249
111
  * - `Content-Language`
@@ -280,7 +142,7 @@ interface CorsConfig {
280
142
  * can be cached by the client.
281
143
  *
282
144
  * Increase for production use to reduce preflights, or lower for development
283
- * if you frequently adjust CORS rules.
145
+ * if you frequently adjust `CORS` rules.
284
146
  *
285
147
  * @default 300 (5 minutes)
286
148
  */
@@ -317,6 +179,19 @@ interface ErrorJson {
317
179
  details: string;
318
180
  }
319
181
 
182
+ /**
183
+ * Initialization options for an OctetStream response.
184
+ *
185
+ * @property size - Total size of the data (required).
186
+ * @property offset - Start of the byte range (optional, defaults to 0).
187
+ * @property length - Length of the byte range (optional, defaults to size).
188
+ */
189
+ interface OctetStreamInit {
190
+ size: number;
191
+ offset?: number;
192
+ length?: number;
193
+ }
194
+
320
195
  /**
321
196
  * Represents the constructor of a Worker subclass.
322
197
  *
@@ -402,7 +277,7 @@ type RouteHandler = RouteCallback | WorkerClass;
402
277
  * pass to the registered handler.
403
278
  */
404
279
  interface Route {
405
- /** HTTP method for the route (e.g., GET, POST, etc.) */
280
+ /** HTTP method for the route (e.g., `GET`, `POST`, etc.) */
406
281
  method: Method;
407
282
  /** Path-to-regexp matcher function for this route */
408
283
  matcher: MatchFunction<PathParams>;
@@ -423,7 +298,7 @@ interface MatchedRoute {
423
298
  /**
424
299
  * A route tuple. Each tuple consists of:
425
300
  *
426
- * 1. HTTP method (e.g., "GET", "POST")
301
+ * 1. HTTP method (e.g., `GET`, `POST`)
427
302
  * 2. Path string (supports parameters, e.g., "/users/:id")
428
303
  * 3. Callback function or Worker class to handle matched requests
429
304
  * */
@@ -475,7 +350,7 @@ declare abstract class Middleware {
475
350
  * Creates a Vary-aware caching middleware for Workers.
476
351
  *
477
352
  * This middleware:
478
- * - Caches **GET requests** only.
353
+ * - Caches `GET` requests **only**.
479
354
  * - Respects the `Vary` header of responses, ensuring that requests
480
355
  * with different headers (e.g., `Origin`) receive the correct cached response.
481
356
  * - Skips caching for non-cacheable responses (e.g., error responses or
@@ -487,90 +362,10 @@ declare abstract class Middleware {
487
362
  * @returns A `Middleware` instance that can be used in a Worker pipeline.
488
363
  */
489
364
  declare function cache(cacheName?: string, getKey?: (request: Request) => URL): Middleware;
490
-
491
- /**
492
- * Creates a CORS middleware instance.
493
- *
494
- * This middleware automatically handles Cross-Origin Resource Sharing (CORS)
495
- * for incoming requests, including preflight OPTIONS requests, and adds
496
- * appropriate headers to responses.
497
- *
498
- * @param init - Optional configuration for CORS behavior. See {@link CorsConfig}.
499
- * @returns A {@link Middleware} instance that can be used in your middleware chain.
500
- */
501
- declare function cors(init?: CorsInit): Middleware;
502
-
503
- declare function websocket(path?: string): Middleware;
504
-
505
- /**
506
- * Lexicographically compares two strings.
507
- *
508
- * This comparator can be used in `Array.prototype.sort()` to produce a
509
- * consistent, stable ordering of string arrays.
510
- *
511
- * @param a - The first string to compare.
512
- * @param b - The second string to compare.
513
- * @returns A number indicating the relative order of `a` and `b`.
514
- */
515
- declare function lexCompare(a: string, b: string): number;
516
-
517
- /**
518
- * Sets a header on the given Headers object.
519
- *
520
- * - If `value` is an array, any duplicates and empty strings are removed.
521
- * - If the resulting value is empty, the header is deleted.
522
- * - Otherwise, values are joined with `", "` and set as the header value.
523
- *
524
- * @param headers - The Headers object to modify.
525
- * @param key - The header name to set.
526
- * @param value - The header value(s) to set. Can be a string or array of strings.
527
- */
528
- declare function setHeader(headers: Headers, key: string, value: string | string[]): void;
529
- /**
530
- * Merges new value(s) into an existing header on the given Headers object.
531
- *
532
- * - Preserves any existing values and adds new ones.
533
- * - Removes duplicates and trims all values.
534
- * - If the header does not exist, it is created.
535
- * - If the resulting value array is empty, the header is deleted.
536
- *
537
- * @param headers - The Headers object to modify.
538
- * @param key - The header name to merge into.
539
- * @param value - The new header value(s) to add. Can be a string or array of strings.
540
- */
541
- declare function mergeHeader(headers: Headers, key: string, value: string | string[]): void;
542
- /**
543
- * Returns the values of an HTTP header as an array of strings.
544
- *
545
- * This helper:
546
- * - Retrieves the header value by `key`.
547
- * - Splits the value on commas.
548
- * - Trims surrounding whitespace from each entry.
549
- * - Filters out any empty tokens.
550
- * - Removes duplicate values (case-sensitive)
551
- *
552
- * If the header is not present, an empty array is returned.
553
- *
554
- */
555
- declare function getHeaderValues(headers: Headers, key: string): string[];
556
-
557
- /**
558
- * Extracts and normalizes the `Origin` header from a request.
559
- *
560
- * Returns the origin (scheme + host + port) as a string if present and valid.
561
- * Returns `null` if:
562
- * - The `Origin` header is missing
563
- * - The `Origin` header is `"null"` (opaque origin)
564
- * - The `Origin` header is malformed
565
- *
566
- * @param request - The incoming {@link Request} object.
567
- * @returns The normalized origin string, or `null` if not present or invalid.
568
- */
569
- declare function getOrigin(request: Request): string | null;
570
365
  /**
571
366
  * Returns a new URL with its query parameters sorted into a stable order.
572
367
  *
573
- * This is useful for cache key generation: URLs that differ only in the
368
+ * This is used for cache key generation: URLs that differ only in the
574
369
  * order of their query parameters will normalize to the same key.
575
370
  *
576
371
  * @param request - The incoming Request whose URL will be normalized.
@@ -580,7 +375,7 @@ declare function sortSearchParams(request: Request): URL;
580
375
  /**
581
376
  * Returns a new URL with all query parameters removed.
582
377
  *
583
- * This is useful when query parameters are not relevant to cache lookups,
378
+ * This is used when query parameters are not relevant to cache lookups,
584
379
  * ensuring that variants of the same resource share a single cache entry.
585
380
  *
586
381
  * @param request - The incoming Request whose URL will be normalized.
@@ -589,13 +384,18 @@ declare function sortSearchParams(request: Request): URL;
589
384
  declare function stripSearchParams(request: Request): URL;
590
385
 
591
386
  /**
592
- * Returns the proper Content-Type string for a given media type.
593
- * Appends `charset=utf-8` for text-based types that require it.
387
+ * Creates a`CORS`middleware instance.
388
+ *
389
+ * This middleware automatically handles Cross-Origin Resource Sharing (CORS)
390
+ * for incoming requests, including preflight `OPTIONS` requests, and adds
391
+ * appropriate headers to responses.
594
392
  *
595
- * @param type - The media type.
596
- * @returns A string suitable for the `Content-Type` header.
393
+ * @param init - Optional configuration for `CORS` behavior. See {@link CorsConfig}.
394
+ * @returns A {@link Middleware} instance that can be used in your middleware chain.
597
395
  */
598
- declare function getContentType(type: MediaType): string;
396
+ declare function cors(init?: CorsInit): Middleware;
397
+
398
+ declare function websocket(path?: string): Middleware;
599
399
 
600
400
  type WarnEvent = {
601
401
  type: "warn";
@@ -627,7 +427,7 @@ interface WebSocketConnection<A extends WSAttachment> {
627
427
 
628
428
  declare class WebSocketSessions<A extends WSAttachment = WSAttachment> {
629
429
  private readonly map;
630
- create(attachment?: A): WebSocketConnection<A>;
430
+ create(attachment?: Partial<A>): WebSocketConnection<A>;
631
431
  restore(ws: WebSocket): WebSocketConnection<A>;
632
432
  restoreAll(all: WebSocket[]): ReadonlyArray<WebSocketConnection<A>>;
633
433
  get(ws: WebSocket): WebSocketConnection<A> | undefined;
@@ -641,20 +441,13 @@ declare class WebSocketSessions<A extends WSAttachment = WSAttachment> {
641
441
 
642
442
  /**
643
443
  * A type-safe Cloudflare Worker handler with a guaranteed `fetch` method.
644
- *
645
- * Extends `ExportedHandler` but ensures that `fetch` exists and has the
646
- * correct signature for Cloudflare Worker invocation.
647
- *
648
- * `Env` is a placeholder type for the environment bindings provided by
649
- * the user (e.g., KV namespaces, secrets, Durable Objects). This interface
650
- * does not constrain the actual type; it only ensures `fetch` is present.
651
444
  */
652
- interface FetchHandler extends ExportedHandler<Env> {
445
+ interface FetchHandler {
653
446
  /**
654
447
  * Handles an incoming request and produces a response.
655
448
  *
656
449
  * @param request - The incoming `Request` object.
657
- * @param env - User-provided environment bindings (placeholder type).
450
+ * @param env - User-provided environment bindings.
658
451
  * @param ctx - Execution context for background tasks (`waitUntil`).
659
452
  * @returns A `Promise` that resolves to a `Response`.
660
453
  */
@@ -778,31 +571,31 @@ declare abstract class BasicWorker extends MiddlewareWorker {
778
571
  * Dispatches the request to the method-specific handler.
779
572
  */
780
573
  protected dispatch(): Promise<Response>;
781
- /** Override and implement this method for GET requests. */
574
+ /** Override and implement this method for `GET` requests. */
782
575
  protected get(): Promise<Response>;
783
- /** Override and implement this method for PUT requests. */
576
+ /** Override and implement this method for `PUT` requests. */
784
577
  protected put(): Promise<Response>;
785
- /** Override and implement this method for POST requests. */
578
+ /** Override and implement this method for `POST` requests. */
786
579
  protected post(): Promise<Response>;
787
- /** Override and implement this method for PATCH requests. */
580
+ /** Override and implement this method for `PATCH` requests. */
788
581
  protected patch(): Promise<Response>;
789
- /** Override and implement this method for DELETE requests. */
582
+ /** Override and implement this method for `DELETE` requests. */
790
583
  protected delete(): Promise<Response>;
791
- /** Returns a default empty OPTIONS response. */
584
+ /** Returns a default empty `OPTIONS` response. */
792
585
  protected options(): Promise<Response>;
793
586
  /**
794
- * Default handler for HEAD requests.
795
- * Performs a GET request and removes the body for HEAD semantics.
587
+ * Default handler for `HEAD` requests.
588
+ * Performs a `GET` request and removes the body for `HEAD` semantics.
796
589
  *
797
590
  * Usually does not need to be overridden as this behavior covers
798
- * standard HEAD requirements.
591
+ * standard `HEAD` requirements.
799
592
  */
800
593
  protected head(): Promise<Response>;
801
594
  /**
802
- * DEFAULT allowed HTTP methods for subclasses.
595
+ * The DEFAULT allowed HTTP methods for subclasses are `GET`, `HEAD`, `OPTIONS`.
803
596
  *
804
- * These defaults were selected for getting started quickly and should be
805
- * overridden for each specific worker.
597
+ * These defaults were selected for getting started quickly and can be
598
+ * overridden for each worker subclass.
806
599
  */
807
600
  getAllowedMethods(): Method[];
808
601
  }
@@ -825,7 +618,7 @@ declare abstract class RouteWorker extends BasicWorker {
825
618
  * - A function that receives URL parameters, or
826
619
  * - A Worker subclass that will handle the request.
827
620
  *
828
- * @param method - HTTP method for the route (GET, POST, etc.).
621
+ * @param method - HTTP method for the route (`GET`, `POST`, etc.).
829
622
  * @param path - URL path pattern (Express-style, e.g., "/users/:id").
830
623
  * @param handler - The function or Worker class to run when the route matches.
831
624
  * @returns The current worker instance, allowing method chaining.
@@ -835,7 +628,7 @@ declare abstract class RouteWorker extends BasicWorker {
835
628
  * Registers multiple routes at once in the worker.
836
629
  *
837
630
  * Each route should be a tuple `[method, path, handler]` where:
838
- * - `method` - HTTP method for the route (GET, POST, etc.).
631
+ * - `method` - HTTP method for the route (`GET`, `POST`, etc.).
839
632
  * - `path` - URL path pattern (Express-style, e.g., "/users/:id").
840
633
  * - `handler` - A function that receives URL parameters or a Worker subclass
841
634
  * that will handle the request.
@@ -886,7 +679,7 @@ declare abstract class BaseResponse {
886
679
  /** Enable websocket responses. */
887
680
  webSocket: WebSocket | null;
888
681
  /** Default media type of the response body. */
889
- mediaType: MediaType;
682
+ mediaType: string;
890
683
  /** Converts current state to ResponseInit for constructing a Response. */
891
684
  protected get responseInit(): ResponseInit;
892
685
  /** Sets a header, overwriting any existing value. */
@@ -936,13 +729,62 @@ declare class JsonResponse extends SuccessResponse {
936
729
  * HTML response. Automatically sets Content-Type to text/html.
937
730
  */
938
731
  declare class HtmlResponse extends SuccessResponse {
939
- constructor(body: string, cache?: CacheControl, status?: StatusCodes);
732
+ constructor(body: string, cache?: CacheControl, status?: StatusCodes, charset?: string);
940
733
  }
941
734
  /**
942
735
  * Plain text response. Automatically sets Content-Type to text/plain.
943
736
  */
944
737
  declare class TextResponse extends SuccessResponse {
945
- constructor(content: string, cache?: CacheControl, status?: StatusCodes);
738
+ constructor(body: string, cache?: CacheControl, status?: StatusCodes, charset?: string);
739
+ }
740
+ /**
741
+ * A response class for streaming binary data.
742
+ *
743
+ * Automatically sets headers for:
744
+ * - Accept-Ranges: bytes
745
+ * - Content-Length
746
+ * - Content-Range (for partial content)
747
+ *
748
+ * The status code is handled internally:
749
+ * - 200 OK for full content
750
+ * - 206 Partial Content for range responses
751
+ *
752
+ * @param stream - The ReadableStream containing the data to send.
753
+ * @param init - Options for the response:
754
+ * - size: Total size of the data (required)
755
+ * - offset: Start of the byte range (defaults to 0)
756
+ * - length: Length of the byte range (defaults to size)
757
+ * @param cache: Optional caching information
758
+ */
759
+ declare class OctetStream extends WorkerResponse {
760
+ constructor(stream: ReadableStream, init: OctetStreamInit, cache?: CacheControl);
761
+ }
762
+ /**
763
+ * A streaming response for Cloudflare R2 objects.
764
+ *
765
+ * @param source - The R2 object to stream.
766
+ * @param cache - Optional caching information.
767
+ */
768
+ declare class R2ObjectStream extends OctetStream {
769
+ constructor(source: R2ObjectBody, cache?: CacheControl);
770
+ /**
771
+ * Computes the byte range for an R2 object, returning all values needed
772
+ * to construct a proper streaming response.
773
+ *
774
+ * Handles three cases:
775
+ * 1. **No range specified** — returns the full object.
776
+ * 2. **Suffix range** (e.g., last N bytes) — calculates offset and length
777
+ * so that only the requested suffix is returned.
778
+ * 3. **Standard offset/length range** — returns the requested range,
779
+ * applying defaults if offset or length are missing.
780
+ *
781
+ * @param source - The R2 object containing optional range information.
782
+ * @returns An object containing:
783
+ * - `size` — total size of the object in bytes
784
+ * - `offset` — starting byte of the range
785
+ * - `length` — number of bytes in the range
786
+ */
787
+ private static computeRange;
946
788
  }
947
789
  /**
948
790
  * Response for WebSocket upgrade requests.
@@ -952,16 +794,16 @@ declare class WebSocketUpgrade extends WorkerResponse {
952
794
  constructor(client: WebSocket);
953
795
  }
954
796
  /**
955
- * Response for HEAD requests. Copy headers and status from a GET response
797
+ * Response for `HEAD` requests. Copy headers and status from a `GET` response
956
798
  * without the body.
957
799
  */
958
800
  declare class Head extends WorkerResponse {
959
801
  constructor(get: Response);
960
802
  }
961
803
  /**
962
- * Response for OPTIONS preflight requests.
804
+ * Response for `OPTIONS` preflight requests.
963
805
  */
964
- declare class Options extends SuccessResponse {
806
+ declare class Options extends WorkerResponse {
965
807
  constructor();
966
808
  }
967
809
 
@@ -1019,4 +861,4 @@ declare class ServiceUnavailable extends HttpError {
1019
861
  constructor(details?: string);
1020
862
  }
1021
863
 
1022
- export { BadRequest, BasicWorker, CacheControl, ClonedResponse, CloseCode, type CorsConfig, type CorsInit, DELETE, type ErrorJson, Forbidden, GET, HEAD, Head, HtmlResponse, HttpError, HttpHeader, InternalServerError, JsonResponse, type MatchedRoute, MediaType, Method, MethodNotAllowed, MethodNotImplemented, NotFound, NotImplemented, OPTIONS, Options, PATCH, POST, PUT, type PathParams, type Route, type RouteCallback, type RouteHandler, type RouteTable, type RouteTuple, RouteWorker, ServiceUnavailable, SuccessResponse, TextResponse, Time, Unauthorized, UpgradeRequired, WS_MAX_CLOSE_CODE, WS_MAX_REASON_CHARS, WS_RESERVED_CODES, WS_UPGRADE, WS_VERSION, WS_WEBSOCKET, WebSocketSessions, WebSocketUpgrade, type Worker, type WorkerClass, WorkerResponse, assertMethods, cache, cors, getContentType, getHeaderValues, getOrigin, isMethod, isMethodArray, lexCompare, mergeHeader, setHeader, sortSearchParams, stripSearchParams, websocket };
864
+ export { BadRequest, BasicWorker, CacheControl, ClonedResponse, type CorsConfig, type CorsInit, DELETE, type ErrorJson, Forbidden, GET, HEAD, Head, HtmlResponse, HttpError, InternalServerError, JsonResponse, type MatchedRoute, Method, MethodNotAllowed, MethodNotImplemented, NotFound, NotImplemented, OPTIONS, OctetStream, type OctetStreamInit, Options, PATCH, POST, PUT, type PathParams, R2ObjectStream, type Route, type RouteCallback, type RouteHandler, type RouteTable, type RouteTuple, RouteWorker, ServiceUnavailable, SuccessResponse, TextResponse, Time, Unauthorized, UpgradeRequired, WebSocketSessions, WebSocketUpgrade, type Worker, type WorkerClass, WorkerResponse, cache, cors, sortSearchParams, stripSearchParams, websocket };