@adonix.org/cloud-spark 0.0.161 → 0.0.163
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 +3 -3
- package/dist/index.d.ts +103 -45
- package/dist/index.js +1 -1453
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ⚡️
|
|
1
|
+
# ⚡️Cloud Spark
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@adonix.org/cloud-spark)
|
|
4
4
|
[](https://github.com/adonix-org/cloud-spark/blob/main/LICENSE)
|
|
@@ -21,7 +21,7 @@ npm install @adonix.org/cloud-spark
|
|
|
21
21
|
|
|
22
22
|
<br>
|
|
23
23
|
|
|
24
|
-
## :
|
|
24
|
+
## :rocket: Quickstart
|
|
25
25
|
|
|
26
26
|
:page_facing_up: hello-world.ts
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ npm install @adonix.org/cloud-spark
|
|
|
29
29
|
import { BasicWorker, TextResponse } from "@adonix.org/cloud-spark";
|
|
30
30
|
|
|
31
31
|
export class HelloWorld extends BasicWorker {
|
|
32
|
-
|
|
32
|
+
get() {
|
|
33
33
|
return this.response(TextResponse, "Hi from Cloud Spark!");
|
|
34
34
|
}
|
|
35
35
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,11 +27,14 @@ declare const CacheControl: {
|
|
|
27
27
|
* Standard HTTP header names and common values.
|
|
28
28
|
*/
|
|
29
29
|
declare namespace HttpHeader {
|
|
30
|
-
const ALLOW = "Allow";
|
|
31
30
|
const ACCEPT_ENCODING = "Accept-Encoding";
|
|
32
|
-
const
|
|
31
|
+
const ACCEPT_RANGES = "Accept-Ranges";
|
|
32
|
+
const ALLOW = "Allow";
|
|
33
|
+
const CONTENT_LENGTH = "Content-Length";
|
|
34
|
+
const CONTENT_RANGE = "Content-Range";
|
|
33
35
|
const CONTENT_TYPE = "Content-Type";
|
|
34
36
|
const CACHE_CONTROL = "Cache-Control";
|
|
37
|
+
const ORIGIN = "Origin";
|
|
35
38
|
const USER_AGENT = "User-Agent";
|
|
36
39
|
const VARY = "Vary";
|
|
37
40
|
const CONTENT_SECURITY_POLICY = "Content-Security-Policy";
|
|
@@ -197,7 +200,7 @@ declare function isMethodArray(value: unknown): value is Method[];
|
|
|
197
200
|
declare function assertMethods(value: unknown): asserts value is Method[];
|
|
198
201
|
|
|
199
202
|
/**
|
|
200
|
-
* User-supplied options for configuring
|
|
203
|
+
* User-supplied options for configuring`CORS`behavior.
|
|
201
204
|
*
|
|
202
205
|
* This is a partial form of {@link CorsConfig}, meaning you only need
|
|
203
206
|
* to provide the options you want to override. Any missing values will
|
|
@@ -213,9 +216,9 @@ declare function assertMethods(value: unknown): asserts value is Method[];
|
|
|
213
216
|
*/
|
|
214
217
|
type CorsInit = Partial<CorsConfig>;
|
|
215
218
|
/**
|
|
216
|
-
* Configuration options for Cross-Origin Resource Sharing
|
|
219
|
+
* Configuration options for Cross-Origin Resource Sharing `CORS`.
|
|
217
220
|
*
|
|
218
|
-
* Implementations of CORS middleware use this interface to determine
|
|
221
|
+
* Implementations of `CORS` middleware use this interface to determine
|
|
219
222
|
* how cross-origin requests are validated and which headers are sent
|
|
220
223
|
* in the response.
|
|
221
224
|
*
|
|
@@ -232,7 +235,7 @@ type CorsInit = Partial<CorsConfig>;
|
|
|
232
235
|
*/
|
|
233
236
|
interface CorsConfig {
|
|
234
237
|
/**
|
|
235
|
-
* Origins allowed for CORS requests.
|
|
238
|
+
* Origins allowed for `CORS` requests.
|
|
236
239
|
*
|
|
237
240
|
* Use `["*"]` to allow all origins, or provide a list of specific origins.
|
|
238
241
|
* Example: `["https://example.com", "https://api.example.com"]`
|
|
@@ -241,9 +244,9 @@ interface CorsConfig {
|
|
|
241
244
|
*/
|
|
242
245
|
allowedOrigins: string[];
|
|
243
246
|
/**
|
|
244
|
-
* HTTP headers allowed in CORS requests.
|
|
247
|
+
* HTTP headers allowed in `CORS` requests.
|
|
245
248
|
*
|
|
246
|
-
* Browsers always allow
|
|
249
|
+
* Browsers always allow `CORS`-safelisted request headers* without preflight:
|
|
247
250
|
* - `Accept`
|
|
248
251
|
* - `Accept-Language`
|
|
249
252
|
* - `Content-Language`
|
|
@@ -280,7 +283,7 @@ interface CorsConfig {
|
|
|
280
283
|
* can be cached by the client.
|
|
281
284
|
*
|
|
282
285
|
* Increase for production use to reduce preflights, or lower for development
|
|
283
|
-
* if you frequently adjust CORS rules.
|
|
286
|
+
* if you frequently adjust `CORS` rules.
|
|
284
287
|
*
|
|
285
288
|
* @default 300 (5 minutes)
|
|
286
289
|
*/
|
|
@@ -317,6 +320,19 @@ interface ErrorJson {
|
|
|
317
320
|
details: string;
|
|
318
321
|
}
|
|
319
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Initialization options for an OctetStream response.
|
|
325
|
+
*
|
|
326
|
+
* @property size - Total size of the data (required).
|
|
327
|
+
* @property offset - Start of the byte range (optional, defaults to 0).
|
|
328
|
+
* @property length - Length of the byte range (optional, defaults to size).
|
|
329
|
+
*/
|
|
330
|
+
interface OctetStreamInit {
|
|
331
|
+
size: number;
|
|
332
|
+
offset?: number;
|
|
333
|
+
length?: number;
|
|
334
|
+
}
|
|
335
|
+
|
|
320
336
|
/**
|
|
321
337
|
* Represents the constructor of a Worker subclass.
|
|
322
338
|
*
|
|
@@ -402,7 +418,7 @@ type RouteHandler = RouteCallback | WorkerClass;
|
|
|
402
418
|
* pass to the registered handler.
|
|
403
419
|
*/
|
|
404
420
|
interface Route {
|
|
405
|
-
/** HTTP method for the route (e.g., GET
|
|
421
|
+
/** HTTP method for the route (e.g., `GET`, `POST`, etc.) */
|
|
406
422
|
method: Method;
|
|
407
423
|
/** Path-to-regexp matcher function for this route */
|
|
408
424
|
matcher: MatchFunction<PathParams>;
|
|
@@ -423,7 +439,7 @@ interface MatchedRoute {
|
|
|
423
439
|
/**
|
|
424
440
|
* A route tuple. Each tuple consists of:
|
|
425
441
|
*
|
|
426
|
-
* 1. HTTP method (e.g.,
|
|
442
|
+
* 1. HTTP method (e.g., `GET`, `POST`)
|
|
427
443
|
* 2. Path string (supports parameters, e.g., "/users/:id")
|
|
428
444
|
* 3. Callback function or Worker class to handle matched requests
|
|
429
445
|
* */
|
|
@@ -475,7 +491,7 @@ declare abstract class Middleware {
|
|
|
475
491
|
* Creates a Vary-aware caching middleware for Workers.
|
|
476
492
|
*
|
|
477
493
|
* This middleware:
|
|
478
|
-
* - Caches
|
|
494
|
+
* - Caches `GET` requests **only**.
|
|
479
495
|
* - Respects the `Vary` header of responses, ensuring that requests
|
|
480
496
|
* with different headers (e.g., `Origin`) receive the correct cached response.
|
|
481
497
|
* - Skips caching for non-cacheable responses (e.g., error responses or
|
|
@@ -489,13 +505,13 @@ declare abstract class Middleware {
|
|
|
489
505
|
declare function cache(cacheName?: string, getKey?: (request: Request) => URL): Middleware;
|
|
490
506
|
|
|
491
507
|
/**
|
|
492
|
-
* Creates a
|
|
508
|
+
* Creates a`CORS`middleware instance.
|
|
493
509
|
*
|
|
494
510
|
* This middleware automatically handles Cross-Origin Resource Sharing (CORS)
|
|
495
|
-
* for incoming requests, including preflight OPTIONS requests, and adds
|
|
511
|
+
* for incoming requests, including preflight `OPTIONS` requests, and adds
|
|
496
512
|
* appropriate headers to responses.
|
|
497
513
|
*
|
|
498
|
-
* @param init - Optional configuration for CORS behavior. See {@link CorsConfig}.
|
|
514
|
+
* @param init - Optional configuration for `CORS` behavior. See {@link CorsConfig}.
|
|
499
515
|
* @returns A {@link Middleware} instance that can be used in your middleware chain.
|
|
500
516
|
*/
|
|
501
517
|
declare function cors(init?: CorsInit): Middleware;
|
|
@@ -595,7 +611,7 @@ declare function stripSearchParams(request: Request): URL;
|
|
|
595
611
|
* @param type - The media type.
|
|
596
612
|
* @returns A string suitable for the `Content-Type` header.
|
|
597
613
|
*/
|
|
598
|
-
declare function getContentType(type: MediaType): string;
|
|
614
|
+
declare function getContentType(type: MediaType | string): string;
|
|
599
615
|
|
|
600
616
|
type WarnEvent = {
|
|
601
617
|
type: "warn";
|
|
@@ -627,7 +643,7 @@ interface WebSocketConnection<A extends WSAttachment> {
|
|
|
627
643
|
|
|
628
644
|
declare class WebSocketSessions<A extends WSAttachment = WSAttachment> {
|
|
629
645
|
private readonly map;
|
|
630
|
-
create(attachment?: A): WebSocketConnection<A>;
|
|
646
|
+
create(attachment?: Partial<A>): WebSocketConnection<A>;
|
|
631
647
|
restore(ws: WebSocket): WebSocketConnection<A>;
|
|
632
648
|
restoreAll(all: WebSocket[]): ReadonlyArray<WebSocketConnection<A>>;
|
|
633
649
|
get(ws: WebSocket): WebSocketConnection<A> | undefined;
|
|
@@ -641,20 +657,13 @@ declare class WebSocketSessions<A extends WSAttachment = WSAttachment> {
|
|
|
641
657
|
|
|
642
658
|
/**
|
|
643
659
|
* 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
660
|
*/
|
|
652
|
-
interface FetchHandler
|
|
661
|
+
interface FetchHandler {
|
|
653
662
|
/**
|
|
654
663
|
* Handles an incoming request and produces a response.
|
|
655
664
|
*
|
|
656
665
|
* @param request - The incoming `Request` object.
|
|
657
|
-
* @param env - User-provided environment bindings
|
|
666
|
+
* @param env - User-provided environment bindings.
|
|
658
667
|
* @param ctx - Execution context for background tasks (`waitUntil`).
|
|
659
668
|
* @returns A `Promise` that resolves to a `Response`.
|
|
660
669
|
*/
|
|
@@ -778,31 +787,31 @@ declare abstract class BasicWorker extends MiddlewareWorker {
|
|
|
778
787
|
* Dispatches the request to the method-specific handler.
|
|
779
788
|
*/
|
|
780
789
|
protected dispatch(): Promise<Response>;
|
|
781
|
-
/** Override and implement this method for GET requests. */
|
|
790
|
+
/** Override and implement this method for `GET` requests. */
|
|
782
791
|
protected get(): Promise<Response>;
|
|
783
|
-
/** Override and implement this method for PUT requests. */
|
|
792
|
+
/** Override and implement this method for `PUT` requests. */
|
|
784
793
|
protected put(): Promise<Response>;
|
|
785
|
-
/** Override and implement this method for POST requests. */
|
|
794
|
+
/** Override and implement this method for `POST` requests. */
|
|
786
795
|
protected post(): Promise<Response>;
|
|
787
|
-
/** Override and implement this method for PATCH requests. */
|
|
796
|
+
/** Override and implement this method for `PATCH` requests. */
|
|
788
797
|
protected patch(): Promise<Response>;
|
|
789
|
-
/** Override and implement this method for DELETE requests. */
|
|
798
|
+
/** Override and implement this method for `DELETE` requests. */
|
|
790
799
|
protected delete(): Promise<Response>;
|
|
791
|
-
/** Returns a default empty OPTIONS response. */
|
|
800
|
+
/** Returns a default empty `OPTIONS` response. */
|
|
792
801
|
protected options(): Promise<Response>;
|
|
793
802
|
/**
|
|
794
|
-
* Default handler for HEAD requests.
|
|
795
|
-
* Performs a GET request and removes the body for HEAD semantics.
|
|
803
|
+
* Default handler for `HEAD` requests.
|
|
804
|
+
* Performs a `GET` request and removes the body for `HEAD` semantics.
|
|
796
805
|
*
|
|
797
806
|
* Usually does not need to be overridden as this behavior covers
|
|
798
|
-
* standard HEAD requirements.
|
|
807
|
+
* standard `HEAD` requirements.
|
|
799
808
|
*/
|
|
800
809
|
protected head(): Promise<Response>;
|
|
801
810
|
/**
|
|
802
|
-
* DEFAULT allowed HTTP methods for subclasses
|
|
811
|
+
* The DEFAULT allowed HTTP methods for subclasses are `GET`, `HEAD`, `OPTIONS`.
|
|
803
812
|
*
|
|
804
|
-
* These defaults were selected for getting started quickly and
|
|
805
|
-
* overridden for each
|
|
813
|
+
* These defaults were selected for getting started quickly and can be
|
|
814
|
+
* overridden for each worker subclass.
|
|
806
815
|
*/
|
|
807
816
|
getAllowedMethods(): Method[];
|
|
808
817
|
}
|
|
@@ -825,7 +834,7 @@ declare abstract class RouteWorker extends BasicWorker {
|
|
|
825
834
|
* - A function that receives URL parameters, or
|
|
826
835
|
* - A Worker subclass that will handle the request.
|
|
827
836
|
*
|
|
828
|
-
* @param method - HTTP method for the route (GET
|
|
837
|
+
* @param method - HTTP method for the route (`GET`, `POST`, etc.).
|
|
829
838
|
* @param path - URL path pattern (Express-style, e.g., "/users/:id").
|
|
830
839
|
* @param handler - The function or Worker class to run when the route matches.
|
|
831
840
|
* @returns The current worker instance, allowing method chaining.
|
|
@@ -835,7 +844,7 @@ declare abstract class RouteWorker extends BasicWorker {
|
|
|
835
844
|
* Registers multiple routes at once in the worker.
|
|
836
845
|
*
|
|
837
846
|
* Each route should be a tuple `[method, path, handler]` where:
|
|
838
|
-
* - `method` - HTTP method for the route (GET
|
|
847
|
+
* - `method` - HTTP method for the route (`GET`, `POST`, etc.).
|
|
839
848
|
* - `path` - URL path pattern (Express-style, e.g., "/users/:id").
|
|
840
849
|
* - `handler` - A function that receives URL parameters or a Worker subclass
|
|
841
850
|
* that will handle the request.
|
|
@@ -886,7 +895,7 @@ declare abstract class BaseResponse {
|
|
|
886
895
|
/** Enable websocket responses. */
|
|
887
896
|
webSocket: WebSocket | null;
|
|
888
897
|
/** Default media type of the response body. */
|
|
889
|
-
mediaType: MediaType;
|
|
898
|
+
mediaType: MediaType | string;
|
|
890
899
|
/** Converts current state to ResponseInit for constructing a Response. */
|
|
891
900
|
protected get responseInit(): ResponseInit;
|
|
892
901
|
/** Sets a header, overwriting any existing value. */
|
|
@@ -944,6 +953,55 @@ declare class HtmlResponse extends SuccessResponse {
|
|
|
944
953
|
declare class TextResponse extends SuccessResponse {
|
|
945
954
|
constructor(content: string, cache?: CacheControl, status?: StatusCodes);
|
|
946
955
|
}
|
|
956
|
+
/**
|
|
957
|
+
* A response class for streaming binary data.
|
|
958
|
+
*
|
|
959
|
+
* Automatically sets headers for:
|
|
960
|
+
* - Accept-Ranges: bytes
|
|
961
|
+
* - Content-Length
|
|
962
|
+
* - Content-Range (for partial content)
|
|
963
|
+
*
|
|
964
|
+
* The status code is handled internally:
|
|
965
|
+
* - 200 OK for full content
|
|
966
|
+
* - 206 Partial Content for range responses
|
|
967
|
+
*
|
|
968
|
+
* @param stream - The ReadableStream containing the data to send.
|
|
969
|
+
* @param init - Options for the response:
|
|
970
|
+
* - size: Total size of the data (required)
|
|
971
|
+
* - offset: Start of the byte range (defaults to 0)
|
|
972
|
+
* - length: Length of the byte range (defaults to size)
|
|
973
|
+
* @param cache: Optional caching information
|
|
974
|
+
*/
|
|
975
|
+
declare class OctetStream extends WorkerResponse {
|
|
976
|
+
constructor(stream: ReadableStream, init: OctetStreamInit, cache?: CacheControl);
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* A streaming response for Cloudflare R2 objects.
|
|
980
|
+
*
|
|
981
|
+
* @param object - The R2 object to stream.
|
|
982
|
+
* @param cache - Optional caching information.
|
|
983
|
+
*/
|
|
984
|
+
declare class R2ObjectStream extends OctetStream {
|
|
985
|
+
constructor(object: R2ObjectBody, cache?: CacheControl);
|
|
986
|
+
/**
|
|
987
|
+
* Computes the byte range for an R2 object, returning all values needed
|
|
988
|
+
* to construct a proper streaming response.
|
|
989
|
+
*
|
|
990
|
+
* Handles three cases:
|
|
991
|
+
* 1. **No range specified** — returns the full object.
|
|
992
|
+
* 2. **Suffix range** (e.g., last N bytes) — calculates offset and length
|
|
993
|
+
* so that only the requested suffix is returned.
|
|
994
|
+
* 3. **Standard offset/length range** — returns the requested range,
|
|
995
|
+
* applying defaults if offset or length are missing.
|
|
996
|
+
*
|
|
997
|
+
* @param object - The R2 object containing optional range information.
|
|
998
|
+
* @returns An object containing:
|
|
999
|
+
* - `size` — total size of the object in bytes
|
|
1000
|
+
* - `offset` — starting byte of the range
|
|
1001
|
+
* - `length` — number of bytes in the range
|
|
1002
|
+
*/
|
|
1003
|
+
private static computeRange;
|
|
1004
|
+
}
|
|
947
1005
|
/**
|
|
948
1006
|
* Response for WebSocket upgrade requests.
|
|
949
1007
|
* Automatically sets status to 101 and attaches the client socket.
|
|
@@ -952,16 +1010,16 @@ declare class WebSocketUpgrade extends WorkerResponse {
|
|
|
952
1010
|
constructor(client: WebSocket);
|
|
953
1011
|
}
|
|
954
1012
|
/**
|
|
955
|
-
* Response for HEAD requests. Copy headers and status from a GET response
|
|
1013
|
+
* Response for `HEAD` requests. Copy headers and status from a `GET` response
|
|
956
1014
|
* without the body.
|
|
957
1015
|
*/
|
|
958
1016
|
declare class Head extends WorkerResponse {
|
|
959
1017
|
constructor(get: Response);
|
|
960
1018
|
}
|
|
961
1019
|
/**
|
|
962
|
-
* Response for OPTIONS preflight requests.
|
|
1020
|
+
* Response for `OPTIONS` preflight requests.
|
|
963
1021
|
*/
|
|
964
|
-
declare class Options extends
|
|
1022
|
+
declare class Options extends WorkerResponse {
|
|
965
1023
|
constructor();
|
|
966
1024
|
}
|
|
967
1025
|
|
|
@@ -1019,4 +1077,4 @@ declare class ServiceUnavailable extends HttpError {
|
|
|
1019
1077
|
constructor(details?: string);
|
|
1020
1078
|
}
|
|
1021
1079
|
|
|
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 };
|
|
1080
|
+
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, 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, 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 };
|