tspace-spear 1.2.3 → 1.2.5
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 +268 -19
- package/dist/lib/core/const/index.d.ts +153 -0
- package/dist/lib/core/const/index.js +105 -0
- package/dist/lib/core/const/index.js.map +1 -0
- package/dist/lib/core/decorators/context.d.ts +16 -9
- package/dist/lib/core/decorators/context.js +85 -59
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/headers.d.ts +2 -2
- package/dist/lib/core/decorators/headers.js +1 -1
- package/dist/lib/core/decorators/headers.js.map +1 -1
- package/dist/lib/core/decorators/methods.d.ts +7 -7
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +3 -3
- package/dist/lib/core/decorators/middleware.js +2 -2
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.d.ts +1 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.d.ts +1 -1
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/server/fast-router.d.ts +133 -0
- package/dist/lib/core/server/fast-router.js +277 -0
- package/dist/lib/core/server/fast-router.js.map +1 -0
- package/dist/lib/core/server/index.d.ts +34 -37
- package/dist/lib/core/server/index.js +192 -501
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/net/index.d.ts +20 -0
- package/dist/lib/core/server/net/index.js +393 -0
- package/dist/lib/core/server/net/index.js.map +1 -0
- package/dist/lib/core/server/parser-factory.d.ts +10 -11
- package/dist/lib/core/server/parser-factory.js +259 -437
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/response.d.ts +6 -0
- package/dist/lib/core/server/response.js +168 -0
- package/dist/lib/core/server/response.js.map +1 -0
- package/dist/lib/core/server/router.d.ts +2 -12
- package/dist/lib/core/server/router.js +2 -13
- package/dist/lib/core/server/router.js.map +1 -1
- package/dist/lib/core/server/uWS/index.d.ts +30 -0
- package/dist/lib/core/server/uWS/index.js +357 -0
- package/dist/lib/core/server/uWS/index.js.map +1 -0
- package/dist/lib/core/types/index.d.ts +144 -43
- package/dist/lib/core/utils/index.d.ts +12 -0
- package/dist/lib/core/utils/index.js +137 -0
- package/dist/lib/core/utils/index.js.map +1 -0
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/package.json +19 -14
package/README.md
CHANGED
|
@@ -16,6 +16,11 @@ Install with [npm](https://www.npmjs.com/):
|
|
|
16
16
|
npm install tspace-spear --save
|
|
17
17
|
|
|
18
18
|
```
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
See the [`docs`](https://thanathip41.github.io/tspace-spear) directory for full documentation.
|
|
23
|
+
|
|
19
24
|
## Basic Usage
|
|
20
25
|
- [Start Server](#start-server)
|
|
21
26
|
- [Adapter](#adapter)
|
|
@@ -32,6 +37,7 @@ npm install tspace-spear --save
|
|
|
32
37
|
- [Cookie](#cookie)
|
|
33
38
|
- [Middleware](#middleware)
|
|
34
39
|
- [Controller](#controller)
|
|
40
|
+
- [Dto](#dto)
|
|
35
41
|
- [Router](#router)
|
|
36
42
|
- [Swagger](#swagger)
|
|
37
43
|
- [WebSocket](#websocket)
|
|
@@ -82,6 +88,7 @@ new Spear({ adapter: uWS })
|
|
|
82
88
|
```
|
|
83
89
|
|
|
84
90
|
## Cluster
|
|
91
|
+
Cluster mode allows tspace-spear to run multiple worker processes to fully utilize multi-core CPU performance.
|
|
85
92
|
```js
|
|
86
93
|
import { Spear } from "tspace-spear";
|
|
87
94
|
new Spear({
|
|
@@ -98,6 +105,9 @@ new Spear({
|
|
|
98
105
|
```
|
|
99
106
|
|
|
100
107
|
## Global Prefix
|
|
108
|
+
Global Prefix allows you to define a base path for all routes in your application.
|
|
109
|
+
|
|
110
|
+
It helps keep your API structured and consistent (e.g. /api, /v1, /app).
|
|
101
111
|
```js
|
|
102
112
|
const app = new Spear({
|
|
103
113
|
globalPrefix : '/api' // prefix all routes
|
|
@@ -109,6 +119,16 @@ const app = new Spear({
|
|
|
109
119
|
```
|
|
110
120
|
|
|
111
121
|
## Logger
|
|
122
|
+
The built-in Logger provides request logging for incoming HTTP requests.
|
|
123
|
+
|
|
124
|
+
It helps you monitor:
|
|
125
|
+
|
|
126
|
+
Request method
|
|
127
|
+
Request path
|
|
128
|
+
Performance tracking
|
|
129
|
+
Debugging and observability
|
|
130
|
+
|
|
131
|
+
You can enable a simple logger or configure advanced logging behavior.
|
|
112
132
|
```js
|
|
113
133
|
const app = new Spear({
|
|
114
134
|
logger : true
|
|
@@ -124,8 +144,17 @@ const app = new Spear({
|
|
|
124
144
|
```
|
|
125
145
|
|
|
126
146
|
## Format Response
|
|
147
|
+
Provides a consistent response structure system to standardize how responses are handled across your application.
|
|
148
|
+
|
|
149
|
+
It ensures that:
|
|
150
|
+
|
|
151
|
+
* All responses are predictable
|
|
152
|
+
* Errors are properly structured
|
|
153
|
+
* Missing routes are handled cleanly
|
|
154
|
+
* Global error catching is supported
|
|
127
155
|
|
|
128
156
|
### Notfound
|
|
157
|
+
The NotFound handler is triggered when no route matches the incoming request.
|
|
129
158
|
```js
|
|
130
159
|
const app = new Spear()
|
|
131
160
|
.get('/' , () => {
|
|
@@ -142,6 +171,13 @@ const app = new Spear()
|
|
|
142
171
|
```
|
|
143
172
|
|
|
144
173
|
### Response
|
|
174
|
+
The response system ensures that all returned values are automatically formatted and sent to the client.
|
|
175
|
+
|
|
176
|
+
You can return:
|
|
177
|
+
|
|
178
|
+
* String
|
|
179
|
+
* Object (JSON)
|
|
180
|
+
* Custom response via ctx.res
|
|
145
181
|
```js
|
|
146
182
|
import { Spear } from "tspace-spear";
|
|
147
183
|
|
|
@@ -183,6 +219,10 @@ const app = new Spear()
|
|
|
183
219
|
```
|
|
184
220
|
|
|
185
221
|
### Catch
|
|
222
|
+
The Catch handler is used to handle unexpected runtime errors globally.
|
|
223
|
+
|
|
224
|
+
It acts as a safety layer to prevent server crashes and standardize error responses.
|
|
225
|
+
|
|
186
226
|
```js
|
|
187
227
|
import { Spear } from "tspace-spear";
|
|
188
228
|
import { z } from "zod";
|
|
@@ -217,7 +257,9 @@ const app = new Spear()
|
|
|
217
257
|
```
|
|
218
258
|
|
|
219
259
|
## Cors
|
|
260
|
+
CORS (Cross-Origin Resource Sharing) controls which origins are allowed to access your API.
|
|
220
261
|
|
|
262
|
+
It helps secure your server by restricting or allowing cross-domain requests.
|
|
221
263
|
```js
|
|
222
264
|
const app = new Spear()
|
|
223
265
|
.cors({
|
|
@@ -232,6 +274,9 @@ const app = new Spear()
|
|
|
232
274
|
```
|
|
233
275
|
|
|
234
276
|
## Body
|
|
277
|
+
Body parsing allows your server to read incoming request payloads (JSON) and access them via ctx.body.
|
|
278
|
+
|
|
279
|
+
It enables handling requests with structured data.
|
|
235
280
|
```js
|
|
236
281
|
|
|
237
282
|
new Spear()
|
|
@@ -247,7 +292,14 @@ new Spear()
|
|
|
247
292
|
```
|
|
248
293
|
|
|
249
294
|
## File Upload
|
|
295
|
+
File upload support allows handling multipart/form-data requests and working with uploaded files via ctx.files.
|
|
296
|
+
|
|
297
|
+
It provides:
|
|
250
298
|
|
|
299
|
+
* Temporary file handling
|
|
300
|
+
* File size limits
|
|
301
|
+
* Manual file movement
|
|
302
|
+
* Auto cleanup option
|
|
251
303
|
```js
|
|
252
304
|
|
|
253
305
|
import { Spear, type T } from 'tspace-spear';
|
|
@@ -284,6 +336,14 @@ new Spear()
|
|
|
284
336
|
```
|
|
285
337
|
|
|
286
338
|
## Cookie
|
|
339
|
+
Cookie support allows you to read and manage HTTP cookies from incoming requests via ctx.cookies.
|
|
340
|
+
|
|
341
|
+
It is useful for:
|
|
342
|
+
|
|
343
|
+
* Session handling
|
|
344
|
+
* Authentication
|
|
345
|
+
* User preferences
|
|
346
|
+
* Stateful requests
|
|
287
347
|
```js
|
|
288
348
|
|
|
289
349
|
new Spear()
|
|
@@ -297,6 +357,12 @@ new Spear()
|
|
|
297
357
|
```
|
|
298
358
|
|
|
299
359
|
## Middleware
|
|
360
|
+
Middleware is a function that runs before the controller handler and is used to:
|
|
361
|
+
|
|
362
|
+
* Intercept requests
|
|
363
|
+
* Modify ctx
|
|
364
|
+
* Validate or block execution
|
|
365
|
+
* Handle authentication / logging / transformations
|
|
300
366
|
```js
|
|
301
367
|
import { type T } from "tspace-spear"
|
|
302
368
|
// file cat-middleware.ts
|
|
@@ -348,6 +414,9 @@ import CatMiddleware from './cat-middleware.ts'
|
|
|
348
414
|
```
|
|
349
415
|
|
|
350
416
|
## Controller
|
|
417
|
+
A Controller is used to group related routes and define request handlers in a structured way.
|
|
418
|
+
|
|
419
|
+
It helps organize your application into modules (similar to NestJS / Express routers), while keeping a clean and readable API design.
|
|
351
420
|
```js
|
|
352
421
|
import {
|
|
353
422
|
Controller ,
|
|
@@ -462,8 +531,131 @@ import CatController from './cat-controller.ts'
|
|
|
462
531
|
})()
|
|
463
532
|
```
|
|
464
533
|
|
|
534
|
+
|
|
535
|
+
## Dto
|
|
536
|
+
DTO (Data Transfer Object) is used to validate and transform incoming request data before it reaches your controller logic.
|
|
537
|
+
```js
|
|
538
|
+
import {
|
|
539
|
+
Controller ,
|
|
540
|
+
Post,
|
|
541
|
+
createDtoDecorator
|
|
542
|
+
type T
|
|
543
|
+
} from 'tspace-spear';
|
|
544
|
+
|
|
545
|
+
import z from "zod";
|
|
546
|
+
|
|
547
|
+
const ValidateDtoBody = (keys: string[]) => {
|
|
548
|
+
return createDtoDecorator((ctx) => {
|
|
549
|
+
const body = ctx.body ?? {};
|
|
550
|
+
const issues: Array<{ path: string; message: string }> = [];
|
|
551
|
+
|
|
552
|
+
for (let i = 0; i < keys.length; i++) {
|
|
553
|
+
const key = keys[i];
|
|
554
|
+
|
|
555
|
+
if (body[key] == null) {
|
|
556
|
+
issues.push({
|
|
557
|
+
path: key,
|
|
558
|
+
message: "Missing field",
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (issues.length > 0) {
|
|
564
|
+
throw {
|
|
565
|
+
message : "Validation failed",
|
|
566
|
+
issues
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const ValidateDtoZodBody = (schema: z.ZodTypeAny) => {
|
|
573
|
+
return createDtoDecorator((ctx) => {
|
|
574
|
+
const result = schema.parse(ctx.body);
|
|
575
|
+
ctx.body = result as T.Body;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const ValidateDtoPromiseBody = (keys: string[]) => {
|
|
580
|
+
return createDtoDecorator(async (ctx) => {
|
|
581
|
+
await new Promise(resolve => setTimeout(resolve,500));
|
|
582
|
+
// check in DB or other async operation
|
|
583
|
+
throw new Error('Validation failed in promise!');
|
|
584
|
+
}, (ctx, error) => {
|
|
585
|
+
// you implement your custom error handling for async validation here
|
|
586
|
+
return ctx.res.status(400).json({
|
|
587
|
+
message: error.message || "Validation failed",
|
|
588
|
+
issues: error.issues || [],
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const catSchema = z.object({
|
|
594
|
+
name: z.string(),
|
|
595
|
+
age: z.number(),
|
|
596
|
+
})
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
// file cat-controller.ts
|
|
600
|
+
@Controller('/cats')
|
|
601
|
+
export class CatController {
|
|
602
|
+
@Post('/')
|
|
603
|
+
@ValidateDtoBody(["name", "age"])
|
|
604
|
+
public async basic(ctx : T.Context) {
|
|
605
|
+
const body = ctx.body;
|
|
606
|
+
return {
|
|
607
|
+
body
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
@Post('/zod')
|
|
612
|
+
@ValidateDtoZodBody(catSchema)
|
|
613
|
+
public async zod(ctx : T.Context) {
|
|
614
|
+
const body = ctx.body as z.infer<typeof catSchema>;
|
|
615
|
+
return {
|
|
616
|
+
body
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
@Post('/promise')
|
|
621
|
+
@ValidateDtoPromiseBody(['name', 'age'])
|
|
622
|
+
public async promise(ctx : T.Context) {
|
|
623
|
+
const body = ctx.body;
|
|
624
|
+
|
|
625
|
+
return {
|
|
626
|
+
body
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
import { Spear } , { Router, type T } from "tspace-spear";
|
|
632
|
+
|
|
633
|
+
import CatController from './cat-controller.ts'
|
|
634
|
+
|
|
635
|
+
(async () => {
|
|
636
|
+
|
|
637
|
+
new Spear({
|
|
638
|
+
controllers: [ CatController ]
|
|
639
|
+
})
|
|
640
|
+
.useBodyParser()
|
|
641
|
+
.listen(3000 , () => console.log(`Server is now listening http://localhost:3000`))
|
|
642
|
+
|
|
643
|
+
// localhost:3000/cats // basic implete
|
|
644
|
+
// localhost:3000/cats/zod // zod implete
|
|
645
|
+
// localhost:3000/cats/promise // promise implete
|
|
646
|
+
|
|
647
|
+
})()
|
|
648
|
+
```
|
|
649
|
+
|
|
465
650
|
## Router
|
|
651
|
+
The Router allows you to organize routes into modular groups, making your application more scalable and maintainable.
|
|
652
|
+
|
|
653
|
+
It supports:
|
|
466
654
|
|
|
655
|
+
* Grouped routes
|
|
656
|
+
* Nested route prefixes
|
|
657
|
+
* Reusable router modules
|
|
658
|
+
* Separation of concerns
|
|
467
659
|
```js
|
|
468
660
|
import { Spear, Router, type T } from "tspace-spear";
|
|
469
661
|
|
|
@@ -507,6 +699,14 @@ app.listen(port , () => console.log(`Server is now listening http://localhost:30
|
|
|
507
699
|
```
|
|
508
700
|
|
|
509
701
|
## Swagger
|
|
702
|
+
Provides built-in Swagger support to document your API endpoints.
|
|
703
|
+
|
|
704
|
+
It allows you to:
|
|
705
|
+
|
|
706
|
+
* Describe request parameters (query, body, params)
|
|
707
|
+
* Generate API documentation
|
|
708
|
+
* Improve developer experience
|
|
709
|
+
* Standardize API contracts
|
|
510
710
|
```js
|
|
511
711
|
|
|
512
712
|
// file cat-controller.ts
|
|
@@ -574,7 +774,22 @@ class CatController {
|
|
|
574
774
|
name : {
|
|
575
775
|
type : 'string',
|
|
576
776
|
example : "xxxxx"
|
|
577
|
-
}
|
|
777
|
+
},
|
|
778
|
+
status : {
|
|
779
|
+
type : 'string',
|
|
780
|
+
example: "active",
|
|
781
|
+
enum: ['active', 'inactive'],
|
|
782
|
+
description: "User status (active = enabled, inactive = disabled)",
|
|
783
|
+
required : true
|
|
784
|
+
},
|
|
785
|
+
roles: {
|
|
786
|
+
type: 'array',
|
|
787
|
+
items : {
|
|
788
|
+
type: 'string',
|
|
789
|
+
example: "roleA",
|
|
790
|
+
enum: ['roleA', 'roleB']
|
|
791
|
+
}
|
|
792
|
+
},
|
|
578
793
|
}
|
|
579
794
|
}
|
|
580
795
|
})
|
|
@@ -699,44 +914,78 @@ class CatController {
|
|
|
699
914
|
```
|
|
700
915
|
|
|
701
916
|
## WebSocket
|
|
917
|
+
Provides built-in WebSocket support for real-time communication.
|
|
918
|
+
|
|
919
|
+
It allows you to:
|
|
920
|
+
|
|
921
|
+
* Handle client connections
|
|
922
|
+
* Send/receive messages
|
|
923
|
+
* Build chat systems
|
|
924
|
+
* Manage real-time events
|
|
702
925
|
```js
|
|
703
926
|
import { Spear } from "tspace-spear";
|
|
927
|
+
import fs from 'fs';
|
|
928
|
+
import path from 'path';
|
|
704
929
|
|
|
705
930
|
new Spear()
|
|
706
|
-
.get('/',
|
|
707
|
-
|
|
708
|
-
|
|
931
|
+
.get('/',(ctx) => {
|
|
932
|
+
// you can serve a HTML file for testing WebSocket connection
|
|
933
|
+
const htmlWs = fs.readFileSync(path.join(path.resolve(), 'public', 'ws.html'), 'utf-8');
|
|
934
|
+
return ctx.res.html(htmlWs);
|
|
709
935
|
})
|
|
710
936
|
.ws(() => {
|
|
937
|
+
const clients = new Map<string, any>();
|
|
711
938
|
return {
|
|
712
939
|
connection: (ws) => {
|
|
713
|
-
|
|
940
|
+
console.log("connected");
|
|
714
941
|
},
|
|
942
|
+
|
|
715
943
|
message: (ws, msg) => {
|
|
716
944
|
const data = JSON.parse(msg.toString());
|
|
717
945
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
946
|
+
if (data.type === "register") {
|
|
947
|
+
ws.userId = data.userId;
|
|
948
|
+
clients.set(data.userId, ws);
|
|
949
|
+
|
|
950
|
+
ws.send(JSON.stringify({
|
|
951
|
+
type: "system",
|
|
952
|
+
message: `registered as ${data.userId}`
|
|
953
|
+
}));
|
|
954
|
+
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
if (data.type === "chat") {
|
|
959
|
+
const targetWs = clients.get(data.to);
|
|
723
960
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
961
|
+
if (!targetWs) {
|
|
962
|
+
ws.send(JSON.stringify({
|
|
963
|
+
type: "error",
|
|
964
|
+
message: "User not online"
|
|
965
|
+
}));
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
targetWs.send(JSON.stringify({
|
|
970
|
+
type: "chat",
|
|
971
|
+
from: ws.userId,
|
|
972
|
+
text: data.text
|
|
973
|
+
}));
|
|
728
974
|
|
|
729
|
-
|
|
730
|
-
ws.send(JSON.stringify({ type: 'error', message: 'Unknown message type' }));
|
|
975
|
+
return;
|
|
731
976
|
}
|
|
732
977
|
},
|
|
733
|
-
|
|
734
|
-
|
|
978
|
+
|
|
979
|
+
close: (ws) => {
|
|
980
|
+
if (ws.userId) {
|
|
981
|
+
clients.delete(ws.userId);
|
|
982
|
+
}
|
|
735
983
|
},
|
|
984
|
+
|
|
736
985
|
error: (ws, error) => {
|
|
737
986
|
console.error('WebSocket error:', error);
|
|
738
987
|
}
|
|
739
|
-
}
|
|
988
|
+
};
|
|
740
989
|
})
|
|
741
990
|
.listen(3000 , ({ port , server }) => {
|
|
742
991
|
console.log(`server listening on : http://localhost:${port}`)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export declare const HTTP_STATUS_MESSAGES: {
|
|
2
|
+
readonly 100: "Continue";
|
|
3
|
+
readonly 101: "Switching Protocols";
|
|
4
|
+
readonly 102: "Processing";
|
|
5
|
+
readonly 200: "OK";
|
|
6
|
+
readonly 201: "Created";
|
|
7
|
+
readonly 202: "Accepted";
|
|
8
|
+
readonly 203: "Non-Authoritative Information";
|
|
9
|
+
readonly 204: "No Content";
|
|
10
|
+
readonly 205: "Reset Content";
|
|
11
|
+
readonly 206: "Partial Content";
|
|
12
|
+
readonly 207: "Multi-Status";
|
|
13
|
+
readonly 208: "Already Reported";
|
|
14
|
+
readonly 226: "IM Used";
|
|
15
|
+
readonly 300: "Multiple Choices";
|
|
16
|
+
readonly 301: "Moved Permanently";
|
|
17
|
+
readonly 302: "Found";
|
|
18
|
+
readonly 303: "See Other";
|
|
19
|
+
readonly 304: "Not Modified";
|
|
20
|
+
readonly 305: "Use Proxy";
|
|
21
|
+
readonly 306: "(Unused)";
|
|
22
|
+
readonly 307: "Temporary Redirect";
|
|
23
|
+
readonly 308: "Permanent Redirect";
|
|
24
|
+
readonly 400: "Bad Request";
|
|
25
|
+
readonly 401: "Unauthorized";
|
|
26
|
+
readonly 402: "Payment Required";
|
|
27
|
+
readonly 403: "Forbidden";
|
|
28
|
+
readonly 404: "Not Found";
|
|
29
|
+
readonly 405: "Method Not Allowed";
|
|
30
|
+
readonly 406: "Not Acceptable";
|
|
31
|
+
readonly 407: "Proxy Authentication Required";
|
|
32
|
+
readonly 408: "Request Timeout";
|
|
33
|
+
readonly 409: "Conflict";
|
|
34
|
+
readonly 410: "Gone";
|
|
35
|
+
readonly 411: "Length Required";
|
|
36
|
+
readonly 412: "Precondition Failed";
|
|
37
|
+
readonly 413: "Payload Too Large";
|
|
38
|
+
readonly 414: "URI Too Long";
|
|
39
|
+
readonly 415: "Unsupported Media Type";
|
|
40
|
+
readonly 416: "Range Not Satisfiable";
|
|
41
|
+
readonly 417: "Expectation Failed";
|
|
42
|
+
readonly 418: "I'm a teapot";
|
|
43
|
+
readonly 421: "Misdirected Request";
|
|
44
|
+
readonly 422: "Unprocessable Entity";
|
|
45
|
+
readonly 423: "Locked";
|
|
46
|
+
readonly 424: "Failed Dependency";
|
|
47
|
+
readonly 425: "Too Early";
|
|
48
|
+
readonly 426: "Upgrade Required";
|
|
49
|
+
readonly 428: "Precondition Required";
|
|
50
|
+
readonly 429: "Too Many Requests";
|
|
51
|
+
readonly 431: "Request Header Fields Too Large";
|
|
52
|
+
readonly 451: "Unavailable For Legal Reasons";
|
|
53
|
+
readonly 500: "Internal Server Error";
|
|
54
|
+
readonly 501: "Not Implemented";
|
|
55
|
+
readonly 502: "Bad Gateway";
|
|
56
|
+
readonly 503: "Service Unavailable";
|
|
57
|
+
readonly 504: "Gateway Timeout";
|
|
58
|
+
readonly 505: "HTTP Version Not Supported";
|
|
59
|
+
readonly 506: "Variant Also Negotiates";
|
|
60
|
+
readonly 507: "Insufficient Storage";
|
|
61
|
+
readonly 508: "Loop Detected";
|
|
62
|
+
readonly 510: "Not Extended";
|
|
63
|
+
readonly 511: "Network Authentication Required";
|
|
64
|
+
};
|
|
65
|
+
export declare const HEADER_CONTENT_TYPES: {
|
|
66
|
+
readonly text: {
|
|
67
|
+
readonly 'Content-Type': "text/plain";
|
|
68
|
+
};
|
|
69
|
+
readonly html: {
|
|
70
|
+
readonly 'Content-Type': "text/html";
|
|
71
|
+
};
|
|
72
|
+
readonly css: {
|
|
73
|
+
readonly 'Content-Type': "text/css";
|
|
74
|
+
};
|
|
75
|
+
readonly js: {
|
|
76
|
+
readonly 'Content-Type': "application/javascript";
|
|
77
|
+
};
|
|
78
|
+
readonly json: {
|
|
79
|
+
readonly 'Content-Type': "application/json";
|
|
80
|
+
};
|
|
81
|
+
readonly form: {
|
|
82
|
+
readonly 'Content-Type': "application/x-www-form-urlencoded";
|
|
83
|
+
};
|
|
84
|
+
readonly multipart: {
|
|
85
|
+
readonly 'Content-Type': "multipart/form-data";
|
|
86
|
+
};
|
|
87
|
+
readonly png: {
|
|
88
|
+
readonly 'Content-Type': "image/png";
|
|
89
|
+
};
|
|
90
|
+
readonly jpg: {
|
|
91
|
+
readonly 'Content-Type': "image/jpeg";
|
|
92
|
+
};
|
|
93
|
+
readonly jpeg: {
|
|
94
|
+
readonly 'Content-Type': "image/jpeg";
|
|
95
|
+
};
|
|
96
|
+
readonly gif: {
|
|
97
|
+
readonly 'Content-Type': "image/gif";
|
|
98
|
+
};
|
|
99
|
+
readonly webp: {
|
|
100
|
+
readonly 'Content-Type': "image/webp";
|
|
101
|
+
};
|
|
102
|
+
readonly svg: {
|
|
103
|
+
readonly 'Content-Type': "image/svg+xml";
|
|
104
|
+
};
|
|
105
|
+
readonly ico: {
|
|
106
|
+
readonly 'Content-Type': "image/x-icon";
|
|
107
|
+
};
|
|
108
|
+
readonly pdf: {
|
|
109
|
+
readonly 'Content-Type': "application/pdf";
|
|
110
|
+
};
|
|
111
|
+
readonly zip: {
|
|
112
|
+
readonly 'Content-Type': "application/zip";
|
|
113
|
+
};
|
|
114
|
+
readonly gzip: {
|
|
115
|
+
readonly 'Content-Type': "application/gzip";
|
|
116
|
+
};
|
|
117
|
+
readonly mp4: {
|
|
118
|
+
readonly 'Content-Type': "video/mp4";
|
|
119
|
+
};
|
|
120
|
+
readonly webm: {
|
|
121
|
+
readonly 'Content-Type': "video/webm";
|
|
122
|
+
};
|
|
123
|
+
readonly ogg: {
|
|
124
|
+
readonly 'Content-Type': "video/ogg";
|
|
125
|
+
};
|
|
126
|
+
readonly mp3: {
|
|
127
|
+
readonly 'Content-Type': "audio/mpeg";
|
|
128
|
+
};
|
|
129
|
+
readonly wav: {
|
|
130
|
+
readonly 'Content-Type': "audio/wav";
|
|
131
|
+
};
|
|
132
|
+
readonly aac: {
|
|
133
|
+
readonly 'Content-Type': "audio/aac";
|
|
134
|
+
};
|
|
135
|
+
readonly oga: {
|
|
136
|
+
readonly 'Content-Type': "audio/ogg";
|
|
137
|
+
};
|
|
138
|
+
readonly woff: {
|
|
139
|
+
readonly 'Content-Type': "font/woff";
|
|
140
|
+
};
|
|
141
|
+
readonly woff2: {
|
|
142
|
+
readonly 'Content-Type': "font/woff2";
|
|
143
|
+
};
|
|
144
|
+
readonly ttf: {
|
|
145
|
+
readonly 'Content-Type': "font/ttf";
|
|
146
|
+
};
|
|
147
|
+
readonly otf: {
|
|
148
|
+
readonly 'Content-Type': "font/otf";
|
|
149
|
+
};
|
|
150
|
+
readonly octet: {
|
|
151
|
+
readonly 'Content-Type': "application/octet-stream";
|
|
152
|
+
};
|
|
153
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HEADER_CONTENT_TYPES = exports.HTTP_STATUS_MESSAGES = void 0;
|
|
4
|
+
exports.HTTP_STATUS_MESSAGES = {
|
|
5
|
+
100: 'Continue',
|
|
6
|
+
101: 'Switching Protocols',
|
|
7
|
+
102: 'Processing',
|
|
8
|
+
200: 'OK',
|
|
9
|
+
201: 'Created',
|
|
10
|
+
202: 'Accepted',
|
|
11
|
+
203: 'Non-Authoritative Information',
|
|
12
|
+
204: 'No Content',
|
|
13
|
+
205: 'Reset Content',
|
|
14
|
+
206: 'Partial Content',
|
|
15
|
+
207: 'Multi-Status',
|
|
16
|
+
208: 'Already Reported',
|
|
17
|
+
226: 'IM Used',
|
|
18
|
+
300: 'Multiple Choices',
|
|
19
|
+
301: 'Moved Permanently',
|
|
20
|
+
302: 'Found',
|
|
21
|
+
303: 'See Other',
|
|
22
|
+
304: 'Not Modified',
|
|
23
|
+
305: 'Use Proxy',
|
|
24
|
+
306: '(Unused)',
|
|
25
|
+
307: 'Temporary Redirect',
|
|
26
|
+
308: 'Permanent Redirect',
|
|
27
|
+
400: 'Bad Request',
|
|
28
|
+
401: 'Unauthorized',
|
|
29
|
+
402: 'Payment Required',
|
|
30
|
+
403: 'Forbidden',
|
|
31
|
+
404: 'Not Found',
|
|
32
|
+
405: 'Method Not Allowed',
|
|
33
|
+
406: 'Not Acceptable',
|
|
34
|
+
407: 'Proxy Authentication Required',
|
|
35
|
+
408: 'Request Timeout',
|
|
36
|
+
409: 'Conflict',
|
|
37
|
+
410: 'Gone',
|
|
38
|
+
411: 'Length Required',
|
|
39
|
+
412: 'Precondition Failed',
|
|
40
|
+
413: 'Payload Too Large',
|
|
41
|
+
414: 'URI Too Long',
|
|
42
|
+
415: 'Unsupported Media Type',
|
|
43
|
+
416: 'Range Not Satisfiable',
|
|
44
|
+
417: 'Expectation Failed',
|
|
45
|
+
418: 'I\'m a teapot',
|
|
46
|
+
421: 'Misdirected Request',
|
|
47
|
+
422: 'Unprocessable Entity',
|
|
48
|
+
423: 'Locked',
|
|
49
|
+
424: 'Failed Dependency',
|
|
50
|
+
425: 'Too Early',
|
|
51
|
+
426: 'Upgrade Required',
|
|
52
|
+
428: 'Precondition Required',
|
|
53
|
+
429: 'Too Many Requests',
|
|
54
|
+
431: 'Request Header Fields Too Large',
|
|
55
|
+
451: 'Unavailable For Legal Reasons',
|
|
56
|
+
500: 'Internal Server Error',
|
|
57
|
+
501: 'Not Implemented',
|
|
58
|
+
502: 'Bad Gateway',
|
|
59
|
+
503: 'Service Unavailable',
|
|
60
|
+
504: 'Gateway Timeout',
|
|
61
|
+
505: 'HTTP Version Not Supported',
|
|
62
|
+
506: 'Variant Also Negotiates',
|
|
63
|
+
507: 'Insufficient Storage',
|
|
64
|
+
508: 'Loop Detected',
|
|
65
|
+
510: 'Not Extended',
|
|
66
|
+
511: 'Network Authentication Required'
|
|
67
|
+
};
|
|
68
|
+
exports.HEADER_CONTENT_TYPES = {
|
|
69
|
+
text: { 'Content-Type': 'text/plain' },
|
|
70
|
+
html: { 'Content-Type': 'text/html' },
|
|
71
|
+
css: { 'Content-Type': 'text/css' },
|
|
72
|
+
js: { 'Content-Type': 'application/javascript' },
|
|
73
|
+
json: { 'Content-Type': 'application/json' },
|
|
74
|
+
form: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
75
|
+
multipart: { 'Content-Type': 'multipart/form-data' },
|
|
76
|
+
// images
|
|
77
|
+
png: { 'Content-Type': 'image/png' },
|
|
78
|
+
jpg: { 'Content-Type': 'image/jpeg' },
|
|
79
|
+
jpeg: { 'Content-Type': 'image/jpeg' },
|
|
80
|
+
gif: { 'Content-Type': 'image/gif' },
|
|
81
|
+
webp: { 'Content-Type': 'image/webp' },
|
|
82
|
+
svg: { 'Content-Type': 'image/svg+xml' },
|
|
83
|
+
ico: { 'Content-Type': 'image/x-icon' },
|
|
84
|
+
// documents
|
|
85
|
+
pdf: { 'Content-Type': 'application/pdf' },
|
|
86
|
+
zip: { 'Content-Type': 'application/zip' },
|
|
87
|
+
gzip: { 'Content-Type': 'application/gzip' },
|
|
88
|
+
// video
|
|
89
|
+
mp4: { 'Content-Type': 'video/mp4' },
|
|
90
|
+
webm: { 'Content-Type': 'video/webm' },
|
|
91
|
+
ogg: { 'Content-Type': 'video/ogg' },
|
|
92
|
+
// audio
|
|
93
|
+
mp3: { 'Content-Type': 'audio/mpeg' },
|
|
94
|
+
wav: { 'Content-Type': 'audio/wav' },
|
|
95
|
+
aac: { 'Content-Type': 'audio/aac' },
|
|
96
|
+
oga: { 'Content-Type': 'audio/ogg' },
|
|
97
|
+
// fonts
|
|
98
|
+
woff: { 'Content-Type': 'font/woff' },
|
|
99
|
+
woff2: { 'Content-Type': 'font/woff2' },
|
|
100
|
+
ttf: { 'Content-Type': 'font/ttf' },
|
|
101
|
+
otf: { 'Content-Type': 'font/otf' },
|
|
102
|
+
// binary
|
|
103
|
+
octet: { 'Content-Type': 'application/octet-stream' }
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/const/index.ts"],"names":[],"mappings":"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"}
|