@adonix.org/cloud-spark 0.0.26
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/LICENSE +201 -0
- package/README.md +2 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +439 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { StatusCodes } from 'http-status-codes';
|
|
2
|
+
export { StatusCodes } from 'http-status-codes';
|
|
3
|
+
|
|
4
|
+
declare const Time: {
|
|
5
|
+
readonly Second: 1;
|
|
6
|
+
readonly Minute: 60;
|
|
7
|
+
readonly Hour: number;
|
|
8
|
+
readonly Day: number;
|
|
9
|
+
readonly Week: number;
|
|
10
|
+
};
|
|
11
|
+
declare enum Method {
|
|
12
|
+
GET = "GET",
|
|
13
|
+
PUT = "PUT",
|
|
14
|
+
POST = "POST",
|
|
15
|
+
PATCH = "PATCH",
|
|
16
|
+
DELETE = "DELETE",
|
|
17
|
+
HEAD = "HEAD",
|
|
18
|
+
OPTIONS = "OPTIONS"
|
|
19
|
+
}
|
|
20
|
+
declare function isMethod(value: string): value is Method;
|
|
21
|
+
declare function getContentType(type: MimeType): string;
|
|
22
|
+
declare enum MimeType {
|
|
23
|
+
PLAIN_TEXT = "text/plain",
|
|
24
|
+
HTML = "text/html",
|
|
25
|
+
CSS = "text/css",
|
|
26
|
+
CSV = "text/csv",
|
|
27
|
+
XML = "text/xml",
|
|
28
|
+
MARKDOWN = "text/markdown",
|
|
29
|
+
RICH_TEXT = "text/richtext",
|
|
30
|
+
JSON = "application/json",
|
|
31
|
+
XML_APP = "application/xml",
|
|
32
|
+
YAML = "application/x-yaml",
|
|
33
|
+
FORM_URLENCODED = "application/x-www-form-urlencoded",
|
|
34
|
+
NDJSON = "application/x-ndjson",
|
|
35
|
+
MSGPACK = "application/x-msgpack",
|
|
36
|
+
PROTOBUF = "application/x-protobuf",
|
|
37
|
+
MULTIPART_FORM_DATA = "multipart/form-data",
|
|
38
|
+
MULTIPART_MIXED = "multipart/mixed",
|
|
39
|
+
MULTIPART_ALTERNATIVE = "multipart/alternative",
|
|
40
|
+
MULTIPART_DIGEST = "multipart/digest",
|
|
41
|
+
MULTIPART_RELATED = "multipart/related",
|
|
42
|
+
MULTIPART_SIGNED = "multipart/signed",
|
|
43
|
+
MULTIPART_ENCRYPTED = "multipart/encrypted",
|
|
44
|
+
OCTET_STREAM = "application/octet-stream",
|
|
45
|
+
PDF = "application/pdf",
|
|
46
|
+
ZIP = "application/zip",
|
|
47
|
+
GZIP = "application/gzip",
|
|
48
|
+
MSWORD = "application/msword",
|
|
49
|
+
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
50
|
+
EXCEL = "application/vnd.ms-excel",
|
|
51
|
+
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
52
|
+
POWERPOINT = "application/vnd.ms-powerpoint",
|
|
53
|
+
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
54
|
+
ICO = "image/x-icon",
|
|
55
|
+
ICO_MS = "image/vnd.microsoft.icon",
|
|
56
|
+
GIF = "image/gif",
|
|
57
|
+
PNG = "image/png",
|
|
58
|
+
JPEG = "image/jpeg",
|
|
59
|
+
WEBP = "image/webp",
|
|
60
|
+
SVG = "image/svg+xml",
|
|
61
|
+
HEIF = "image/heif",
|
|
62
|
+
AVIF = "image/avif",
|
|
63
|
+
EVENT_STREAM = "text/event-stream",
|
|
64
|
+
TAR = "application/x-tar",
|
|
65
|
+
BZIP2 = "application/x-bzip2"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface CorsProvider {
|
|
69
|
+
getOrigin(): string | null;
|
|
70
|
+
getAllowOrigins(): string[];
|
|
71
|
+
getAllowMethods(): Method[];
|
|
72
|
+
getAllowHeaders(): string[];
|
|
73
|
+
getMaxAge(): number;
|
|
74
|
+
}
|
|
75
|
+
interface ErrorJson {
|
|
76
|
+
code: number;
|
|
77
|
+
error: string;
|
|
78
|
+
details: string;
|
|
79
|
+
}
|
|
80
|
+
declare class WorkerResponse {
|
|
81
|
+
protected readonly cors: CorsProvider;
|
|
82
|
+
protected readonly code: StatusCodes;
|
|
83
|
+
protected readonly mimeType: MimeType;
|
|
84
|
+
private _headers;
|
|
85
|
+
private _body;
|
|
86
|
+
constructor(cors: CorsProvider, content?: string | null, code?: StatusCodes, mimeType?: MimeType);
|
|
87
|
+
createResponse(): Response;
|
|
88
|
+
protected get responseInit(): ResponseInit;
|
|
89
|
+
protected get body(): string | null;
|
|
90
|
+
protected set body(body: string | null);
|
|
91
|
+
protected get headers(): Headers;
|
|
92
|
+
protected set headers(headers: Headers);
|
|
93
|
+
protected addCorsHeaders(): void;
|
|
94
|
+
protected getAllowMethods(): string;
|
|
95
|
+
protected getAllowHeaders(): string;
|
|
96
|
+
protected getAllowOrigins(): string[];
|
|
97
|
+
protected getMaxAge(): string;
|
|
98
|
+
}
|
|
99
|
+
declare class JsonResponse extends WorkerResponse {
|
|
100
|
+
private _json;
|
|
101
|
+
constructor(cors: CorsProvider, content?: object, code?: StatusCodes);
|
|
102
|
+
get json(): object;
|
|
103
|
+
set json(json: object);
|
|
104
|
+
createResponse(): Response;
|
|
105
|
+
}
|
|
106
|
+
declare class HtmlResponse extends WorkerResponse {
|
|
107
|
+
constructor(cors: CorsProvider, content: string, code?: StatusCodes, type?: MimeType);
|
|
108
|
+
}
|
|
109
|
+
declare class TextResponse extends WorkerResponse {
|
|
110
|
+
constructor(cors: CorsProvider, content: string, code?: StatusCodes, type?: MimeType);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Remove the body from a GET response.
|
|
114
|
+
*/
|
|
115
|
+
declare class Head extends WorkerResponse {
|
|
116
|
+
constructor(cors: CorsProvider, response: Response);
|
|
117
|
+
}
|
|
118
|
+
declare class Options extends WorkerResponse {
|
|
119
|
+
constructor(cors: CorsProvider);
|
|
120
|
+
}
|
|
121
|
+
declare class ErrorResponse extends JsonResponse {
|
|
122
|
+
protected details?: string | undefined;
|
|
123
|
+
constructor(cors: CorsProvider, code: StatusCodes, details?: string | undefined);
|
|
124
|
+
get json(): ErrorJson;
|
|
125
|
+
}
|
|
126
|
+
declare class BadRequest extends ErrorResponse {
|
|
127
|
+
constructor(cors: CorsProvider, detail?: string);
|
|
128
|
+
}
|
|
129
|
+
declare class Unauthorized extends ErrorResponse {
|
|
130
|
+
constructor(cors: CorsProvider, detail?: string);
|
|
131
|
+
}
|
|
132
|
+
declare class Forbidden extends ErrorResponse {
|
|
133
|
+
constructor(cors: CorsProvider, detail?: string);
|
|
134
|
+
}
|
|
135
|
+
declare class NotFound extends ErrorResponse {
|
|
136
|
+
constructor(cors: CorsProvider, detail?: string);
|
|
137
|
+
}
|
|
138
|
+
declare class MethodNotAllowed extends ErrorResponse {
|
|
139
|
+
constructor(cors: CorsProvider, method: string);
|
|
140
|
+
get json(): ErrorJson & {
|
|
141
|
+
allowed: Method[];
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
declare class InternalServerError extends ErrorResponse {
|
|
145
|
+
constructor(cors: CorsProvider, detail?: string);
|
|
146
|
+
}
|
|
147
|
+
declare class NotImplemented extends ErrorResponse {
|
|
148
|
+
constructor(cors: CorsProvider);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
declare abstract class BasicWorker implements CorsProvider {
|
|
152
|
+
private readonly _request;
|
|
153
|
+
private readonly _env;
|
|
154
|
+
private readonly _ctx?;
|
|
155
|
+
constructor(_request: Request, _env?: Env, _ctx?: ExecutionContext | undefined);
|
|
156
|
+
protected get request(): Request;
|
|
157
|
+
protected get env(): Env;
|
|
158
|
+
protected get ctx(): ExecutionContext | undefined;
|
|
159
|
+
fetch(): Promise<Response>;
|
|
160
|
+
protected get(): Response | Promise<Response>;
|
|
161
|
+
protected put(): Response | Promise<Response>;
|
|
162
|
+
protected post(): Response | Promise<Response>;
|
|
163
|
+
protected patch(): Response | Promise<Response>;
|
|
164
|
+
protected delete(): Response | Promise<Response>;
|
|
165
|
+
private options;
|
|
166
|
+
private head;
|
|
167
|
+
protected getResponse<T extends WorkerResponse, Ctor extends new (cors: CorsProvider, ...args: any[]) => T>(ResponseClass: Ctor, ...args: ConstructorParameters<Ctor> extends [any, ...infer R] ? R : never): Response;
|
|
168
|
+
getAllowOrigins(): string[];
|
|
169
|
+
getAllowMethods(): Method[];
|
|
170
|
+
isAllowed(method: string): boolean;
|
|
171
|
+
getAllowHeaders(): string[];
|
|
172
|
+
getMaxAge(): number;
|
|
173
|
+
getOrigin(): string | null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare abstract class RoutedWorker extends BasicWorker {
|
|
177
|
+
private routes;
|
|
178
|
+
constructor(request: Request, env?: Env, ctx?: ExecutionContext);
|
|
179
|
+
protected abstract addRoutes(): void;
|
|
180
|
+
protected addRoute(route: string | RegExp, callback: () => Response | Promise<Response>, method?: Method): void;
|
|
181
|
+
fetch(): Promise<Response>;
|
|
182
|
+
protected get(): Response | Promise<Response>;
|
|
183
|
+
protected put(): Response | Promise<Response>;
|
|
184
|
+
protected post(): Response | Promise<Response>;
|
|
185
|
+
protected patch(): Response | Promise<Response>;
|
|
186
|
+
protected delete(): Response | Promise<Response>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { BadRequest, BasicWorker, type CorsProvider, type ErrorJson, ErrorResponse, Forbidden, Head, HtmlResponse, InternalServerError, JsonResponse, Method, MethodNotAllowed, MimeType, NotFound, NotImplemented, Options, RoutedWorker, TextResponse, Time, Unauthorized, WorkerResponse, getContentType, isMethod };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { StatusCodes as StatusCodes2 } from "http-status-codes";
|
|
3
|
+
|
|
4
|
+
// src/common.ts
|
|
5
|
+
var Time = {
|
|
6
|
+
Second: 1,
|
|
7
|
+
Minute: 60,
|
|
8
|
+
Hour: 60 * 60,
|
|
9
|
+
Day: 60 * 60 * 24,
|
|
10
|
+
Week: 60 * 60 * 24 * 7
|
|
11
|
+
};
|
|
12
|
+
var Method = /* @__PURE__ */ ((Method3) => {
|
|
13
|
+
Method3["GET"] = "GET";
|
|
14
|
+
Method3["PUT"] = "PUT";
|
|
15
|
+
Method3["POST"] = "POST";
|
|
16
|
+
Method3["PATCH"] = "PATCH";
|
|
17
|
+
Method3["DELETE"] = "DELETE";
|
|
18
|
+
Method3["HEAD"] = "HEAD";
|
|
19
|
+
Method3["OPTIONS"] = "OPTIONS";
|
|
20
|
+
return Method3;
|
|
21
|
+
})(Method || {});
|
|
22
|
+
var METHOD_SET = new Set(Object.values(Method));
|
|
23
|
+
function isMethod(value) {
|
|
24
|
+
return METHOD_SET.has(value);
|
|
25
|
+
}
|
|
26
|
+
function getContentType(type) {
|
|
27
|
+
if (ADD_CHARSET.has(type)) {
|
|
28
|
+
return `${type}; charset=utf-8`;
|
|
29
|
+
}
|
|
30
|
+
return type;
|
|
31
|
+
}
|
|
32
|
+
var MimeType = /* @__PURE__ */ ((MimeType2) => {
|
|
33
|
+
MimeType2["PLAIN_TEXT"] = "text/plain";
|
|
34
|
+
MimeType2["HTML"] = "text/html";
|
|
35
|
+
MimeType2["CSS"] = "text/css";
|
|
36
|
+
MimeType2["CSV"] = "text/csv";
|
|
37
|
+
MimeType2["XML"] = "text/xml";
|
|
38
|
+
MimeType2["MARKDOWN"] = "text/markdown";
|
|
39
|
+
MimeType2["RICH_TEXT"] = "text/richtext";
|
|
40
|
+
MimeType2["JSON"] = "application/json";
|
|
41
|
+
MimeType2["XML_APP"] = "application/xml";
|
|
42
|
+
MimeType2["YAML"] = "application/x-yaml";
|
|
43
|
+
MimeType2["FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
44
|
+
MimeType2["NDJSON"] = "application/x-ndjson";
|
|
45
|
+
MimeType2["MSGPACK"] = "application/x-msgpack";
|
|
46
|
+
MimeType2["PROTOBUF"] = "application/x-protobuf";
|
|
47
|
+
MimeType2["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
48
|
+
MimeType2["MULTIPART_MIXED"] = "multipart/mixed";
|
|
49
|
+
MimeType2["MULTIPART_ALTERNATIVE"] = "multipart/alternative";
|
|
50
|
+
MimeType2["MULTIPART_DIGEST"] = "multipart/digest";
|
|
51
|
+
MimeType2["MULTIPART_RELATED"] = "multipart/related";
|
|
52
|
+
MimeType2["MULTIPART_SIGNED"] = "multipart/signed";
|
|
53
|
+
MimeType2["MULTIPART_ENCRYPTED"] = "multipart/encrypted";
|
|
54
|
+
MimeType2["OCTET_STREAM"] = "application/octet-stream";
|
|
55
|
+
MimeType2["PDF"] = "application/pdf";
|
|
56
|
+
MimeType2["ZIP"] = "application/zip";
|
|
57
|
+
MimeType2["GZIP"] = "application/gzip";
|
|
58
|
+
MimeType2["MSWORD"] = "application/msword";
|
|
59
|
+
MimeType2["DOCX"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
60
|
+
MimeType2["EXCEL"] = "application/vnd.ms-excel";
|
|
61
|
+
MimeType2["XLSX"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
62
|
+
MimeType2["POWERPOINT"] = "application/vnd.ms-powerpoint";
|
|
63
|
+
MimeType2["PPTX"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
64
|
+
MimeType2["ICO"] = "image/x-icon";
|
|
65
|
+
MimeType2["ICO_MS"] = "image/vnd.microsoft.icon";
|
|
66
|
+
MimeType2["GIF"] = "image/gif";
|
|
67
|
+
MimeType2["PNG"] = "image/png";
|
|
68
|
+
MimeType2["JPEG"] = "image/jpeg";
|
|
69
|
+
MimeType2["WEBP"] = "image/webp";
|
|
70
|
+
MimeType2["SVG"] = "image/svg+xml";
|
|
71
|
+
MimeType2["HEIF"] = "image/heif";
|
|
72
|
+
MimeType2["AVIF"] = "image/avif";
|
|
73
|
+
MimeType2["EVENT_STREAM"] = "text/event-stream";
|
|
74
|
+
MimeType2["TAR"] = "application/x-tar";
|
|
75
|
+
MimeType2["BZIP2"] = "application/x-bzip2";
|
|
76
|
+
return MimeType2;
|
|
77
|
+
})(MimeType || {});
|
|
78
|
+
var ADD_CHARSET = /* @__PURE__ */ new Set([
|
|
79
|
+
"text/plain" /* PLAIN_TEXT */,
|
|
80
|
+
"text/html" /* HTML */,
|
|
81
|
+
"text/css" /* CSS */,
|
|
82
|
+
"text/csv" /* CSV */,
|
|
83
|
+
"text/markdown" /* MARKDOWN */,
|
|
84
|
+
"text/xml" /* XML */,
|
|
85
|
+
"application/json" /* JSON */,
|
|
86
|
+
"application/xml" /* XML_APP */,
|
|
87
|
+
"application/x-www-form-urlencoded" /* FORM_URLENCODED */,
|
|
88
|
+
"application/x-ndjson" /* NDJSON */,
|
|
89
|
+
"text/richtext" /* RICH_TEXT */,
|
|
90
|
+
"image/svg+xml" /* SVG */
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// src/response.ts
|
|
94
|
+
import { getReasonPhrase, StatusCodes } from "http-status-codes";
|
|
95
|
+
var WorkerResponse = class {
|
|
96
|
+
constructor(cors, content = null, code = StatusCodes.OK, mimeType = "application/json" /* JSON */) {
|
|
97
|
+
this.cors = cors;
|
|
98
|
+
this.code = code;
|
|
99
|
+
this.mimeType = mimeType;
|
|
100
|
+
this._body = this.code === StatusCodes.NO_CONTENT ? null : content;
|
|
101
|
+
}
|
|
102
|
+
_headers = new Headers();
|
|
103
|
+
_body;
|
|
104
|
+
createResponse() {
|
|
105
|
+
this.addCorsHeaders();
|
|
106
|
+
if (this.body) {
|
|
107
|
+
this.headers.set("Content-Type", getContentType(this.mimeType));
|
|
108
|
+
}
|
|
109
|
+
return new Response(this.body, this.responseInit);
|
|
110
|
+
}
|
|
111
|
+
get responseInit() {
|
|
112
|
+
return {
|
|
113
|
+
headers: this.headers,
|
|
114
|
+
status: this.code,
|
|
115
|
+
statusText: getReasonPhrase(this.code)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
get body() {
|
|
119
|
+
return this._body;
|
|
120
|
+
}
|
|
121
|
+
set body(body) {
|
|
122
|
+
this._body = body;
|
|
123
|
+
}
|
|
124
|
+
get headers() {
|
|
125
|
+
return this._headers;
|
|
126
|
+
}
|
|
127
|
+
set headers(headers) {
|
|
128
|
+
this._headers = headers;
|
|
129
|
+
}
|
|
130
|
+
addCorsHeaders() {
|
|
131
|
+
const origin = this.cors.getOrigin();
|
|
132
|
+
if (!origin) return;
|
|
133
|
+
if (this.getAllowOrigins().includes("*")) {
|
|
134
|
+
this.headers.set("Access-Control-Allow-Origin", "*");
|
|
135
|
+
} else if (this.getAllowOrigins().includes(origin)) {
|
|
136
|
+
this.headers.set("Access-Control-Allow-Origin", origin);
|
|
137
|
+
}
|
|
138
|
+
this.headers.set(
|
|
139
|
+
"Access-Control-Allow-Headers",
|
|
140
|
+
this.getAllowHeaders()
|
|
141
|
+
);
|
|
142
|
+
this.headers.set(
|
|
143
|
+
"Access-Control-Allow-Methods",
|
|
144
|
+
this.getAllowMethods()
|
|
145
|
+
);
|
|
146
|
+
this.headers.set("Access-Control-Max-Age", this.getMaxAge());
|
|
147
|
+
this.headers.set("X-Content-Type-Options", "nosniff");
|
|
148
|
+
}
|
|
149
|
+
getAllowMethods() {
|
|
150
|
+
return this.cors.getAllowMethods().join(", ");
|
|
151
|
+
}
|
|
152
|
+
getAllowHeaders() {
|
|
153
|
+
return this.cors.getAllowHeaders().join(", ");
|
|
154
|
+
}
|
|
155
|
+
getAllowOrigins() {
|
|
156
|
+
return this.cors.getAllowOrigins();
|
|
157
|
+
}
|
|
158
|
+
getMaxAge() {
|
|
159
|
+
return String(this.cors.getMaxAge());
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var JsonResponse = class extends WorkerResponse {
|
|
163
|
+
_json;
|
|
164
|
+
constructor(cors, content = {}, code = StatusCodes.OK) {
|
|
165
|
+
super(cors, null, code, "application/json" /* JSON */);
|
|
166
|
+
this._json = content;
|
|
167
|
+
}
|
|
168
|
+
get json() {
|
|
169
|
+
return this._json;
|
|
170
|
+
}
|
|
171
|
+
set json(json) {
|
|
172
|
+
this._json = json;
|
|
173
|
+
}
|
|
174
|
+
createResponse() {
|
|
175
|
+
this.body = JSON.stringify(this.json);
|
|
176
|
+
return super.createResponse();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var HtmlResponse = class extends WorkerResponse {
|
|
180
|
+
constructor(cors, content, code = StatusCodes.OK, type = "text/html" /* HTML */) {
|
|
181
|
+
super(cors, content, code, type);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var TextResponse = class extends WorkerResponse {
|
|
185
|
+
constructor(cors, content, code = StatusCodes.OK, type = "text/plain" /* PLAIN_TEXT */) {
|
|
186
|
+
super(cors, content, code, type);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var Head = class extends WorkerResponse {
|
|
190
|
+
constructor(cors, response) {
|
|
191
|
+
super(cors, null, response.status);
|
|
192
|
+
this.headers = new Headers(response.headers);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var Options = class extends WorkerResponse {
|
|
196
|
+
constructor(cors) {
|
|
197
|
+
super(cors, null, StatusCodes.NO_CONTENT);
|
|
198
|
+
this.headers.set("Allow", this.getAllowMethods());
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var ErrorResponse = class extends JsonResponse {
|
|
202
|
+
constructor(cors, code, details) {
|
|
203
|
+
super(cors, {}, code);
|
|
204
|
+
this.details = details;
|
|
205
|
+
}
|
|
206
|
+
get json() {
|
|
207
|
+
return {
|
|
208
|
+
code: this.code,
|
|
209
|
+
error: getReasonPhrase(this.code),
|
|
210
|
+
details: this.details ?? getReasonPhrase(this.code)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var BadRequest = class extends ErrorResponse {
|
|
215
|
+
constructor(cors, detail) {
|
|
216
|
+
super(cors, StatusCodes.BAD_REQUEST, detail);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
var Unauthorized = class extends ErrorResponse {
|
|
220
|
+
constructor(cors, detail) {
|
|
221
|
+
super(cors, StatusCodes.UNAUTHORIZED, detail);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var Forbidden = class extends ErrorResponse {
|
|
225
|
+
constructor(cors, detail) {
|
|
226
|
+
super(cors, StatusCodes.FORBIDDEN, detail);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var NotFound = class extends ErrorResponse {
|
|
230
|
+
constructor(cors, detail) {
|
|
231
|
+
super(cors, StatusCodes.NOT_FOUND, detail);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var MethodNotAllowed = class extends ErrorResponse {
|
|
235
|
+
constructor(cors, method) {
|
|
236
|
+
super(
|
|
237
|
+
cors,
|
|
238
|
+
StatusCodes.METHOD_NOT_ALLOWED,
|
|
239
|
+
`${method} method not allowed.`
|
|
240
|
+
);
|
|
241
|
+
this.headers.set("Allow", this.getAllowMethods());
|
|
242
|
+
}
|
|
243
|
+
get json() {
|
|
244
|
+
return {
|
|
245
|
+
...super.json,
|
|
246
|
+
allowed: this.cors.getAllowMethods()
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var InternalServerError = class extends ErrorResponse {
|
|
251
|
+
constructor(cors, detail) {
|
|
252
|
+
super(cors, StatusCodes.INTERNAL_SERVER_ERROR, detail);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var NotImplemented = class extends ErrorResponse {
|
|
256
|
+
constructor(cors) {
|
|
257
|
+
super(cors, StatusCodes.NOT_IMPLEMENTED);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/basic-worker.ts
|
|
262
|
+
var BasicWorker = class {
|
|
263
|
+
constructor(_request, _env = {}, _ctx) {
|
|
264
|
+
this._request = _request;
|
|
265
|
+
this._env = _env;
|
|
266
|
+
this._ctx = _ctx;
|
|
267
|
+
}
|
|
268
|
+
get request() {
|
|
269
|
+
return this._request;
|
|
270
|
+
}
|
|
271
|
+
get env() {
|
|
272
|
+
return this._env;
|
|
273
|
+
}
|
|
274
|
+
get ctx() {
|
|
275
|
+
return this._ctx;
|
|
276
|
+
}
|
|
277
|
+
async fetch() {
|
|
278
|
+
if (!this.isAllowed(this.request.method)) {
|
|
279
|
+
return this.getResponse(MethodNotAllowed, this.request.method);
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
switch (this.request.method) {
|
|
283
|
+
case "GET" /* GET */:
|
|
284
|
+
return await this.get();
|
|
285
|
+
case "PUT" /* PUT */:
|
|
286
|
+
return await this.put();
|
|
287
|
+
case "POST" /* POST */:
|
|
288
|
+
return await this.post();
|
|
289
|
+
case "PATCH" /* PATCH */:
|
|
290
|
+
return await this.patch();
|
|
291
|
+
case "DELETE" /* DELETE */:
|
|
292
|
+
return await this.delete();
|
|
293
|
+
case "HEAD" /* HEAD */:
|
|
294
|
+
return await this.head();
|
|
295
|
+
case "OPTIONS" /* OPTIONS */:
|
|
296
|
+
return await this.options();
|
|
297
|
+
default:
|
|
298
|
+
return this.getResponse(
|
|
299
|
+
MethodNotAllowed,
|
|
300
|
+
this.request.method
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
} catch (error) {
|
|
304
|
+
return this.getResponse(InternalServerError, String(error));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
get() {
|
|
308
|
+
return this.getResponse(NotImplemented);
|
|
309
|
+
}
|
|
310
|
+
put() {
|
|
311
|
+
return this.getResponse(NotImplemented);
|
|
312
|
+
}
|
|
313
|
+
post() {
|
|
314
|
+
return this.getResponse(NotImplemented);
|
|
315
|
+
}
|
|
316
|
+
patch() {
|
|
317
|
+
return this.getResponse(NotImplemented);
|
|
318
|
+
}
|
|
319
|
+
delete() {
|
|
320
|
+
return this.getResponse(NotImplemented);
|
|
321
|
+
}
|
|
322
|
+
options() {
|
|
323
|
+
return this.getResponse(Options);
|
|
324
|
+
}
|
|
325
|
+
async head() {
|
|
326
|
+
return this.getResponse(Head, await this.get());
|
|
327
|
+
}
|
|
328
|
+
getResponse(ResponseClass, ...args) {
|
|
329
|
+
return new ResponseClass(this, ...args).createResponse();
|
|
330
|
+
}
|
|
331
|
+
getAllowOrigins() {
|
|
332
|
+
return ["*"];
|
|
333
|
+
}
|
|
334
|
+
getAllowMethods() {
|
|
335
|
+
return ["GET" /* GET */, "OPTIONS" /* OPTIONS */, "HEAD" /* HEAD */];
|
|
336
|
+
}
|
|
337
|
+
isAllowed(method) {
|
|
338
|
+
return isMethod(method) && this.getAllowMethods().includes(method);
|
|
339
|
+
}
|
|
340
|
+
getAllowHeaders() {
|
|
341
|
+
return ["Content-Type"];
|
|
342
|
+
}
|
|
343
|
+
getMaxAge() {
|
|
344
|
+
return Time.Day;
|
|
345
|
+
}
|
|
346
|
+
getOrigin() {
|
|
347
|
+
return this.request.headers.get("Origin");
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// src/routed-worker.ts
|
|
352
|
+
var RoutedWorker = class extends BasicWorker {
|
|
353
|
+
routes = /* @__PURE__ */ new Map();
|
|
354
|
+
constructor(request, env = {}, ctx) {
|
|
355
|
+
super(request, env, ctx);
|
|
356
|
+
this.addRoutes();
|
|
357
|
+
}
|
|
358
|
+
addRoute(route, callback, method = "GET" /* GET */) {
|
|
359
|
+
if (!isMethod(method)) {
|
|
360
|
+
throw new Error(`Unknown method ${method}`);
|
|
361
|
+
}
|
|
362
|
+
if (!this.getAllowMethods().includes(method)) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`${method} is not currently allowed. Update or override getAllowedMethods()`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const boundCallback = callback.bind(this);
|
|
368
|
+
const handlers = this.routes.get(method) ?? [];
|
|
369
|
+
handlers.push({ route, callback: boundCallback });
|
|
370
|
+
this.routes.set(method, handlers);
|
|
371
|
+
}
|
|
372
|
+
async fetch() {
|
|
373
|
+
const method = this.request.method;
|
|
374
|
+
if (!isMethod(method)) {
|
|
375
|
+
throw new Error(`Unsupported method ${method}`);
|
|
376
|
+
}
|
|
377
|
+
if (!this.isAllowed(this.request.method)) {
|
|
378
|
+
return this.getResponse(MethodNotAllowed, this.request.method);
|
|
379
|
+
}
|
|
380
|
+
let url;
|
|
381
|
+
try {
|
|
382
|
+
url = new URL(this.request.url);
|
|
383
|
+
} catch {
|
|
384
|
+
return this.getResponse(BadRequest, "Malformed URL");
|
|
385
|
+
}
|
|
386
|
+
const handlers = this.routes.get(method) ?? [];
|
|
387
|
+
const match = handlers.find(
|
|
388
|
+
({ route }) => route instanceof RegExp ? route.test(url.pathname) : route === url.pathname
|
|
389
|
+
);
|
|
390
|
+
if (match) {
|
|
391
|
+
try {
|
|
392
|
+
return await match.callback();
|
|
393
|
+
} catch (err) {
|
|
394
|
+
return this.getResponse(InternalServerError, String(err));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return await super.fetch();
|
|
398
|
+
}
|
|
399
|
+
get() {
|
|
400
|
+
return this.getResponse(NotFound);
|
|
401
|
+
}
|
|
402
|
+
put() {
|
|
403
|
+
return this.getResponse(NotFound);
|
|
404
|
+
}
|
|
405
|
+
post() {
|
|
406
|
+
return this.getResponse(NotFound);
|
|
407
|
+
}
|
|
408
|
+
patch() {
|
|
409
|
+
return this.getResponse(NotFound);
|
|
410
|
+
}
|
|
411
|
+
delete() {
|
|
412
|
+
return this.getResponse(NotFound);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
export {
|
|
416
|
+
BadRequest,
|
|
417
|
+
BasicWorker,
|
|
418
|
+
ErrorResponse,
|
|
419
|
+
Forbidden,
|
|
420
|
+
Head,
|
|
421
|
+
HtmlResponse,
|
|
422
|
+
InternalServerError,
|
|
423
|
+
JsonResponse,
|
|
424
|
+
Method,
|
|
425
|
+
MethodNotAllowed,
|
|
426
|
+
MimeType,
|
|
427
|
+
NotFound,
|
|
428
|
+
NotImplemented,
|
|
429
|
+
Options,
|
|
430
|
+
RoutedWorker,
|
|
431
|
+
StatusCodes2 as StatusCodes,
|
|
432
|
+
TextResponse,
|
|
433
|
+
Time,
|
|
434
|
+
Unauthorized,
|
|
435
|
+
WorkerResponse,
|
|
436
|
+
getContentType,
|
|
437
|
+
isMethod
|
|
438
|
+
};
|
|
439
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/common.ts","../src/response.ts","../src/basic-worker.ts","../src/routed-worker.ts"],"sourcesContent":["/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { StatusCodes } from \"http-status-codes\";\n\nexport * from \"./common\";\nexport * from \"./response\";\nexport * from \"./basic-worker\";\nexport * from \"./routed-worker\";\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Time = {\n Second: 1,\n Minute: 60,\n Hour: 60 * 60,\n Day: 60 * 60 * 24,\n Week: 60 * 60 * 24 * 7,\n} as const;\n\nexport enum Method {\n GET = \"GET\",\n PUT = \"PUT\",\n POST = \"POST\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n}\n\nconst METHOD_SET: Set<string> = new Set(Object.values(Method));\n\nexport function isMethod(value: string): value is Method {\n return METHOD_SET.has(value);\n}\n\nexport function getContentType(type: MimeType): string {\n if (ADD_CHARSET.has(type)) {\n return `${type}; charset=utf-8`;\n }\n return type;\n}\n\nexport enum MimeType {\n PLAIN_TEXT = \"text/plain\",\n HTML = \"text/html\",\n CSS = \"text/css\",\n CSV = \"text/csv\",\n XML = \"text/xml\",\n MARKDOWN = \"text/markdown\",\n RICH_TEXT = \"text/richtext\",\n JSON = \"application/json\",\n XML_APP = \"application/xml\",\n YAML = \"application/x-yaml\",\n FORM_URLENCODED = \"application/x-www-form-urlencoded\",\n NDJSON = \"application/x-ndjson\",\n MSGPACK = \"application/x-msgpack\",\n PROTOBUF = \"application/x-protobuf\",\n MULTIPART_FORM_DATA = \"multipart/form-data\",\n MULTIPART_MIXED = \"multipart/mixed\",\n MULTIPART_ALTERNATIVE = \"multipart/alternative\",\n MULTIPART_DIGEST = \"multipart/digest\",\n MULTIPART_RELATED = \"multipart/related\",\n MULTIPART_SIGNED = \"multipart/signed\",\n MULTIPART_ENCRYPTED = \"multipart/encrypted\",\n OCTET_STREAM = \"application/octet-stream\",\n PDF = \"application/pdf\",\n ZIP = \"application/zip\",\n GZIP = \"application/gzip\",\n MSWORD = \"application/msword\",\n DOCX = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n EXCEL = \"application/vnd.ms-excel\",\n XLSX = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n POWERPOINT = \"application/vnd.ms-powerpoint\",\n PPTX = \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n ICO = \"image/x-icon\",\n ICO_MS = \"image/vnd.microsoft.icon\",\n GIF = \"image/gif\",\n PNG = \"image/png\",\n JPEG = \"image/jpeg\",\n WEBP = \"image/webp\",\n SVG = \"image/svg+xml\",\n HEIF = \"image/heif\",\n AVIF = \"image/avif\",\n EVENT_STREAM = \"text/event-stream\",\n TAR = \"application/x-tar\",\n BZIP2 = \"application/x-bzip2\",\n}\n\nconst ADD_CHARSET: Set<MimeType> = new Set([\n MimeType.PLAIN_TEXT,\n MimeType.HTML,\n MimeType.CSS,\n MimeType.CSV,\n MimeType.MARKDOWN,\n MimeType.XML,\n MimeType.JSON,\n MimeType.XML_APP,\n MimeType.FORM_URLENCODED,\n MimeType.NDJSON,\n MimeType.RICH_TEXT,\n MimeType.SVG,\n]);\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getReasonPhrase, StatusCodes } from \"http-status-codes\";\nimport { getContentType, Method, MimeType } from \"./common\";\n\nexport interface CorsProvider {\n getOrigin(): string | null;\n getAllowOrigins(): string[];\n getAllowMethods(): Method[];\n getAllowHeaders(): string[];\n getMaxAge(): number;\n}\n\nexport interface ErrorJson {\n code: number;\n error: string;\n details: string;\n}\n\nexport class WorkerResponse {\n private _headers: Headers = new Headers();\n private _body: string | null;\n\n constructor(\n protected readonly cors: CorsProvider,\n content: string | null = null,\n protected readonly code: StatusCodes = StatusCodes.OK,\n protected readonly mimeType: MimeType = MimeType.JSON\n ) {\n this._body = this.code === StatusCodes.NO_CONTENT ? null : content;\n }\n\n public createResponse(): Response {\n this.addCorsHeaders();\n if (this.body) {\n this.headers.set(\"Content-Type\", getContentType(this.mimeType));\n }\n return new Response(this.body, this.responseInit);\n }\n\n protected get responseInit(): ResponseInit {\n return {\n headers: this.headers,\n status: this.code,\n statusText: getReasonPhrase(this.code),\n };\n }\n\n protected get body(): string | null {\n return this._body;\n }\n\n protected set body(body: string | null) {\n this._body = body;\n }\n\n protected get headers(): Headers {\n return this._headers;\n }\n\n protected set headers(headers: Headers) {\n this._headers = headers;\n }\n\n protected addCorsHeaders(): void {\n const origin = this.cors.getOrigin();\n if (!origin) return; // no Origin, skip CORS\n\n if (this.getAllowOrigins().includes(\"*\")) {\n this.headers.set(\"Access-Control-Allow-Origin\", \"*\");\n } else if (this.getAllowOrigins().includes(origin)) {\n this.headers.set(\"Access-Control-Allow-Origin\", origin);\n }\n this.headers.set(\n \"Access-Control-Allow-Headers\",\n this.getAllowHeaders()\n );\n this.headers.set(\n \"Access-Control-Allow-Methods\",\n this.getAllowMethods()\n );\n this.headers.set(\"Access-Control-Max-Age\", this.getMaxAge());\n this.headers.set(\"X-Content-Type-Options\", \"nosniff\");\n }\n\n protected getAllowMethods(): string {\n return this.cors.getAllowMethods().join(\", \");\n }\n\n protected getAllowHeaders(): string {\n return this.cors.getAllowHeaders().join(\", \");\n }\n\n protected getAllowOrigins(): string[] {\n return this.cors.getAllowOrigins();\n }\n\n protected getMaxAge(): string {\n return String(this.cors.getMaxAge());\n }\n}\n\nexport class JsonResponse extends WorkerResponse {\n private _json: object;\n constructor(\n cors: CorsProvider,\n content: object = {},\n code: StatusCodes = StatusCodes.OK\n ) {\n super(cors, null, code, MimeType.JSON);\n this._json = content;\n }\n\n public get json(): object {\n return this._json;\n }\n\n public set json(json: object) {\n this._json = json;\n }\n\n public override createResponse(): Response {\n this.body = JSON.stringify(this.json);\n return super.createResponse();\n }\n}\n\nexport class HtmlResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.HTML\n ) {\n super(cors, content, code, type);\n }\n}\n\nexport class TextResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.PLAIN_TEXT\n ) {\n super(cors, content, code, type);\n }\n}\n\n/**\n * Remove the body from a GET response.\n */\nexport class Head extends WorkerResponse {\n constructor(cors: CorsProvider, response: Response) {\n super(cors, null, response.status);\n this.headers = new Headers(response.headers);\n }\n}\n\nexport class Options extends WorkerResponse {\n constructor(cors: CorsProvider) {\n super(cors, null, StatusCodes.NO_CONTENT);\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n}\n\nexport class ErrorResponse extends JsonResponse {\n constructor(\n cors: CorsProvider,\n code: StatusCodes,\n protected details?: string\n ) {\n super(cors, {}, code);\n }\n\n public override get json(): ErrorJson {\n return {\n code: this.code,\n error: getReasonPhrase(this.code),\n details: this.details ?? getReasonPhrase(this.code),\n };\n }\n}\n\nexport class BadRequest extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.BAD_REQUEST, detail);\n }\n}\n\nexport class Unauthorized extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.UNAUTHORIZED, detail);\n }\n}\n\nexport class Forbidden extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.FORBIDDEN, detail);\n }\n}\n\nexport class NotFound extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.NOT_FOUND, detail);\n }\n}\n\nexport class MethodNotAllowed extends ErrorResponse {\n constructor(cors: CorsProvider, method: string) {\n super(\n cors,\n StatusCodes.METHOD_NOT_ALLOWED,\n `${method} method not allowed.`\n );\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n\n public override get json(): ErrorJson & { allowed: Method[] } {\n return {\n ...super.json,\n allowed: this.cors.getAllowMethods(),\n };\n }\n}\n\nexport class InternalServerError extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.INTERNAL_SERVER_ERROR, detail);\n }\n}\n\nexport class NotImplemented extends ErrorResponse {\n constructor(cors: CorsProvider) {\n super(cors, StatusCodes.NOT_IMPLEMENTED);\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isMethod, Method, Time } from \"./common\";\nimport {\n CorsProvider,\n Head,\n InternalServerError,\n MethodNotAllowed,\n NotImplemented,\n Options,\n WorkerResponse,\n} from \"./response\";\n\nexport abstract class BasicWorker implements CorsProvider {\n constructor(\n private readonly _request: Request,\n private readonly _env: Env = {},\n private readonly _ctx?: ExecutionContext\n ) {}\n\n protected get request(): Request {\n return this._request;\n }\n\n protected get env(): Env {\n return this._env;\n }\n\n protected get ctx(): ExecutionContext | undefined {\n return this._ctx;\n }\n\n public async fetch(): Promise<Response> {\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n try {\n switch (this.request.method) {\n case Method.GET:\n return await this.get();\n case Method.PUT:\n return await this.put();\n case Method.POST:\n return await this.post();\n case Method.PATCH:\n return await this.patch();\n case Method.DELETE:\n return await this.delete();\n case Method.HEAD:\n return await this.head();\n case Method.OPTIONS:\n return await this.options();\n default:\n return this.getResponse(\n MethodNotAllowed,\n this.request.method\n );\n }\n } catch (error) {\n return this.getResponse(InternalServerError, String(error));\n }\n }\n\n protected get(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected put(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected post(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected patch(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected delete(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n private options(): Response | Promise<Response> {\n return this.getResponse(Options);\n }\n\n private async head(): Promise<Response> {\n return this.getResponse(Head, await this.get());\n }\n\n protected getResponse<\n T extends WorkerResponse,\n Ctor extends new (cors: CorsProvider, ...args: any[]) => T\n >(\n ResponseClass: Ctor,\n ...args: ConstructorParameters<Ctor> extends [any, ...infer R]\n ? R\n : never\n ): Response {\n return new ResponseClass(this, ...args).createResponse();\n }\n\n public getAllowOrigins(): string[] {\n return [\"*\"];\n }\n\n public getAllowMethods(): Method[] {\n return [Method.GET, Method.OPTIONS, Method.HEAD];\n }\n\n public isAllowed(method: string): boolean {\n return isMethod(method) && this.getAllowMethods().includes(method);\n }\n\n public getAllowHeaders(): string[] {\n return [\"Content-Type\"];\n }\n\n public getMaxAge(): number {\n return Time.Day;\n }\n\n public getOrigin(): string | null {\n return this.request.headers.get(\"Origin\");\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BasicWorker } from \"./basic-worker\";\nimport { isMethod, Method } from \"./common\";\nimport {\n BadRequest,\n InternalServerError,\n MethodNotAllowed,\n NotFound,\n} from \"./response\";\n\ninterface RouteHandler {\n route: string | RegExp;\n callback: () => Response | Promise<Response>;\n}\n\nexport abstract class RoutedWorker extends BasicWorker {\n private routes: Map<Method, RouteHandler[]> = new Map();\n\n constructor(request: Request, env: Env = {}, ctx?: ExecutionContext) {\n super(request, env, ctx);\n this.addRoutes();\n }\n\n protected abstract addRoutes(): void;\n\n protected addRoute(\n route: string | RegExp,\n callback: () => Response | Promise<Response>,\n method: Method = Method.GET\n ): void {\n if (!isMethod(method)) {\n throw new Error(`Unknown method ${method}`);\n }\n if (!this.getAllowMethods().includes(method)) {\n throw new Error(\n `${method} is not currently allowed. Update or override getAllowedMethods()`\n );\n }\n\n const boundCallback = callback.bind(this);\n const handlers = this.routes.get(method) ?? [];\n handlers.push({ route, callback: boundCallback });\n this.routes.set(method, handlers);\n }\n\n public override async fetch(): Promise<Response> {\n const method = this.request.method;\n if (!isMethod(method)) {\n throw new Error(`Unsupported method ${method}`);\n }\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n let url: URL;\n try {\n url = new URL(this.request.url);\n } catch {\n return this.getResponse(BadRequest, \"Malformed URL\");\n }\n\n const handlers = this.routes.get(method) ?? [];\n const match = handlers.find(({ route }) =>\n route instanceof RegExp\n ? route.test(url.pathname)\n : route === url.pathname\n );\n\n if (match) {\n try {\n return await match.callback();\n } catch (err) {\n return this.getResponse(InternalServerError, String(err));\n }\n }\n return await super.fetch();\n }\n\n protected override get(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override put(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override post(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override patch(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override delete(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n}\n"],"mappings":";AAgBA,SAAS,eAAAA,oBAAmB;;;ACArB,IAAM,OAAO;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ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AY,kBAAkB,KAAK,QAAQ,MAAM;AAAA,IACjE;AAEA,QAAI;AACJ,QAAI;AACA,YAAM,IAAI,IAAI,KAAK,QAAQ,GAAG;AAAA,IAClC,QAAQ;AACJ,aAAO,KAAK,YAAY,YAAY,eAAe;AAAA,IACvD;AAEA,UAAM,WAAW,KAAK,OAAO,IAAI,MAAM,KAAK,CAAC;AAC7C,UAAM,QAAQ,SAAS;AAAA,MAAK,CAAC,EAAE,MAAM,MACjC,iBAAiB,SACX,MAAM,KAAK,IAAI,QAAQ,IACvB,UAAU,IAAI;AAAA,IACxB;AAEA,QAAI,OAAO;AACP,UAAI;AACA,eAAO,MAAM,MAAM,SAAS;AAAA,MAChC,SAAS,KAAK;AACV,eAAO,KAAK,YAAY,qBAAqB,OAAO,GAAG,CAAC;AAAA,MAC5D;AAAA,IACJ;AACA,WAAO,MAAM,MAAM,MAAM;AAAA,EAC7B;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,OAAqC;AACpD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,QAAsC;AACrD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,SAAuC;AACtD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AACJ;","names":["StatusCodes","Method","MimeType"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adonix.org/cloud-spark",
|
|
3
|
+
"version": "0.0.26",
|
|
4
|
+
"description": "Ignite your Cloudflare Workers with a type-safe library for rapid development.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"dev": "tsup --watch",
|
|
21
|
+
"prepare-pack": "node -e \"require('fs').mkdirSync('artifacts', { recursive: true })\"",
|
|
22
|
+
"pack": "npm run prepare-pack && npm pack --pack-destination ./artifacts",
|
|
23
|
+
"test": "vitest",
|
|
24
|
+
"debug": "tsx ./src/debug.ts"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@cloudflare/workers-types": "^4.20250813.0",
|
|
28
|
+
"tsup": "^8.5.0",
|
|
29
|
+
"tsx": "^4.20.4",
|
|
30
|
+
"typescript": "^5.9.2",
|
|
31
|
+
"vitest": "~3.2.4"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"http-status-codes": "^2.3.0"
|
|
35
|
+
}
|
|
36
|
+
}
|