tspace-spear 1.0.0-rc-2 → 1.0.1

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 Thanathip Srisawatpattana
1
+ Copyright (c) 2024 Thanathip Srisawatpattana
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -3,8 +3,7 @@
3
3
  [![NPM version](https://img.shields.io/npm/v/tspace-spear.svg)](https://www.npmjs.com)
4
4
  [![NPM downloads](https://img.shields.io/npm/dm/tspace-spear.svg)](https://www.npmjs.com)
5
5
 
6
- tspace-spear is an api framework for node.js fast and highly focused on providing the best developer experience.
7
- the tspace-spear using native http server
6
+ tspace-spear is a lightweight API framework for Node.js that is fast and highly focused on providing the best developer experience. It utilizes the native HTTP server.
8
7
 
9
8
  ## Install
10
9
 
@@ -16,6 +15,7 @@ npm install tspace-spear --save
16
15
  ```
17
16
  ## Basic Usage
18
17
  - [StartServer](#start-server)
18
+ - [CRUD](#crud)
19
19
  - [Middleware](#middleware)
20
20
  - [Controller](#controller)
21
21
  - [Router](#router)
@@ -39,6 +39,70 @@ new Spear()
39
39
 
40
40
  ```
41
41
 
42
+ ### CRUD
43
+ ```js
44
+ import Spear from "tspace-spear";
45
+
46
+ const spears = [
47
+ {
48
+ id : 1,
49
+ damage : 100
50
+ },
51
+ {
52
+ id : 2,
53
+ damage : 75
54
+ },
55
+ {
56
+ id : 3,
57
+ damage : 50
58
+ }
59
+ ]
60
+
61
+ new Spear()
62
+ .useBodyParser()
63
+ .get('/' , () => spears)
64
+ .get('/:id' , ({ params }) => spears.find(spear => spear.id === Number(params.id ?? 0)))
65
+ .post('/' , ({ body }) => {
66
+ // please validation the your body
67
+ const damage = Number(body.damage ?? (Math.random() * 100).toFixed(0))
68
+
69
+ const id = spears.reduce((max, spear) => spear.id > max ? spear.id : max, 0) + 1
70
+
71
+ spears.push({ id , damage })
72
+
73
+ return spears.find(spear => spear.id === id)
74
+ })
75
+ .patch('/:id' , ({ params , body , res }) => {
76
+
77
+ const damage = Number(body.damage ?? (Math.random() * 100).toFixed(0))
78
+
79
+ const id = Number(params.id)
80
+
81
+ const spear = spears.find(spear => spear.id === id)
82
+
83
+ if (spear == null) return res.status(404).json({ message : 'Spear not found'})
84
+
85
+ spear.damage = damage;
86
+
87
+ return spears.find(spear => spear.id === id)
88
+ })
89
+ .delete('/:id', ({ params , res }) => {
90
+
91
+ const id = Number(params.id)
92
+
93
+ const spear = spears.find(spear => spear.id === id)
94
+
95
+ if (spear == null) return res.status(404).json({ message : 'Spear not found'})
96
+
97
+ spears.splice(spears.findIndex(spear => spear.id === Number(params.id ?? 0)), 1)
98
+
99
+ return res.status(204).json()
100
+ })
101
+ .listen(3000 , ({ server, port }) =>
102
+ console.log(`server listening on : http://localhost:${port}`)
103
+ )
104
+ ```
105
+
42
106
  ## Middleware
43
107
  ```js
44
108
  // file cat-middleware.ts
@@ -96,15 +160,17 @@ import {
96
160
  Params,
97
161
  Cookies,
98
162
  Files,
99
- StatusCode
163
+ StatusCode,
164
+ TCookies,
165
+ TParams,
166
+ TRequest,
167
+ TResponse ,
168
+ TQuery,
169
+ TFiles,
170
+ TContext,
171
+ TNextFunction
100
172
  } from 'tspace-spear';
101
173
 
102
- import type {
103
- TCookies, TParams,
104
- TRequest, TResponse ,
105
- TQuery, TFiles,
106
- TContext, TNextFunction
107
- } from 'tspace-spear';
108
174
  import CatMiddleware from './cat-middleware.ts'
109
175
 
110
176
  // file cat-controller.ts
@@ -128,7 +194,7 @@ class CatController {
128
194
  @Get('/:id')
129
195
  @Middleware(CatMiddleware)
130
196
  @Params('id')
131
- public async show({ params} : TContext) {
197
+ public async show({ params } : TContext) {
132
198
  return {
133
199
  params
134
200
  }
@@ -168,6 +234,7 @@ class CatController {
168
234
  }
169
235
 
170
236
  import Spear , { Router, TContext, TNextFunction } from "tspace-spear";
237
+
171
238
  import CatController from './cat-controller.ts'
172
239
 
173
240
  (async () => {
@@ -181,13 +248,17 @@ import CatController from './cat-controller.ts'
181
248
  // }
182
249
  })
183
250
 
251
+ app.useBodyParser()
252
+ app.useCookiesParser()
253
+ app.useFileUpload()
254
+
184
255
  app.get('/' , ( { res } : TContext) => {
185
256
  return res.json({
186
257
  message : 'hello world!'
187
258
  });
188
259
  })
189
260
 
190
- let port = 3000
261
+ const port = 3000
191
262
 
192
263
  app.listen(port , () => console.log(`Server is now listening http://localhost:${port}`))
193
264
 
@@ -267,15 +338,6 @@ class CatController {
267
338
  name : {
268
339
  type : 'string'
269
340
  }
270
- },
271
- response : {
272
- query : {
273
- type : 'object',
274
- example : {
275
- id : 1,
276
- name : 'catz'
277
- }
278
- }
279
341
  }
280
342
  })
281
343
  public async index({ query } : TContext) {
@@ -287,14 +349,16 @@ class CatController {
287
349
 
288
350
  @Get('/:id')
289
351
  @Swagger({
290
- response : {
291
- params : {
292
- type : 'object',
293
- example : {
294
- id : 1
295
- }
352
+ description : '- message',
353
+ query : {
354
+ id : {
355
+ type : 'integer'
296
356
  }
297
- }
357
+ },
358
+ responses : [
359
+ { status : 200 , description : "OK" , example : { id : 'catz' }},
360
+ { status : 400 , description : "Bad request" , example : { id : 'catz' }}
361
+ ]
298
362
  })
299
363
  public async show({ params } : TContext) {
300
364
  return {
@@ -344,7 +408,7 @@ class CatController {
344
408
  }
345
409
  }
346
410
  })
347
- public async update({ body } : TContext) {
411
+ public async updated({ body } : TContext) {
348
412
  return {
349
413
  body
350
414
  }
@@ -368,7 +432,7 @@ class CatController {
368
432
  }
369
433
  }
370
434
  })
371
- public async updated({ body } : TContext) {
435
+ public async update({ body } : TContext) {
372
436
  return {
373
437
  body
374
438
  }
@@ -391,8 +455,11 @@ class CatController {
391
455
  required : true,
392
456
  properties : {
393
457
  file : {
394
- type : 'string',
395
- format : 'binary'
458
+ type : 'array',
459
+ items: {
460
+ type:"file",
461
+ format:"binary"
462
+ }
396
463
  },
397
464
  name : {
398
465
  type : 'string'
@@ -453,25 +520,32 @@ app.enableCors({
453
520
  })
454
521
 
455
522
  app.useFileUpload({
456
- limits : 1000 * 1000, // limits for file upload 1_000_000 bytes
457
- useTempFiles : true, // whether to use temporary files
458
- tempFileDir : 'tmp', // temporary directory
523
+ limit : 1000 * 1000, // limit for file upload 1_000_000 bytes
524
+ tempFileDir : 'tmp', // folder temporary directory
459
525
  removeTempFile : {
460
526
  remove : true, // remove temporary files
461
527
  ms : 1000 * 60 // remove temporary after 60 seconds
462
528
  }
463
529
  })
464
530
 
465
- app.useBodyParser()
466
-
467
- app.useCookiesParser()
468
-
469
531
  app.get('/' , ({ res } : TContext) => {
470
532
  return res.json({
471
533
  message : 'hello world!'
472
534
  });
473
535
  })
474
536
 
537
+ app.get('/bad-request' , ({ res } : TContext) => {
538
+ return res.status(400).json({
539
+ message : 'hello but bad request'
540
+ });
541
+ })
542
+
543
+ app.get('/not-found' , ({ res } : TContext) => {
544
+ return res.status(404).json({
545
+ message : 'hello but not found the world!'
546
+ });
547
+ })
548
+
475
549
  app.get('/errors', () => {
476
550
  throw new Error('testing Error handler')
477
551
  })
@@ -486,7 +560,7 @@ app.formatResponse((results : unknown , statusCode : number) => {
486
560
  return {
487
561
  success : statusCode < 400,
488
562
  ...results,
489
- code : statusCode
563
+ statusCode
490
564
  }
491
565
  })
492
566
 
@@ -501,13 +575,13 @@ app.errorHandler((err : Error , { res } : TContext) => {
501
575
  return res
502
576
  .status(500)
503
577
  .json({
504
- success : false,
505
- message : err?.message,
506
- code : 500
578
+ success : false,
579
+ message : err?.message,
580
+ statusCode : 500
507
581
  });
508
582
  })
509
583
 
510
- let port = 3000
584
+ const port = 3000
511
585
 
512
586
  app.listen(port , () => console.log(`Server is now listening http://localhost:${port}`))
513
587
 
@@ -14,11 +14,11 @@ const Body = (...bodyParms) => {
14
14
  return function (target, key, descriptor) {
15
15
  const originalMethod = descriptor.value;
16
16
  descriptor.value = function (ctx, next) {
17
- var _a;
18
17
  return __awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
19
  const q = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.body) !== null && _a !== void 0 ? _a : {};
20
20
  const body = bodyParms.reduce((acc, key) => (q[key] != null ? Object.assign(Object.assign({}, acc), { [key]: q[key] }) : acc), {});
21
- ctx.body = Object.keys(body).length ? body : null;
21
+ ctx.body = Object.keys(body).length ? body : {};
22
22
  return yield originalMethod.call(this, ctx, next);
23
23
  });
24
24
  };
@@ -30,11 +30,11 @@ const Files = (...filesParms) => {
30
30
  return function (target, key, descriptor) {
31
31
  const originalMethod = descriptor.value;
32
32
  descriptor.value = function (ctx, next) {
33
- var _a;
34
33
  return __awaiter(this, void 0, void 0, function* () {
34
+ var _a;
35
35
  const q = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.files) !== null && _a !== void 0 ? _a : {};
36
36
  const files = filesParms.reduce((acc, key) => (q[key] != null ? Object.assign(Object.assign({}, acc), { [key]: q[key] }) : acc), {});
37
- ctx.files = Object.keys(files).length ? files : null;
37
+ ctx.files = Object.keys(files).length ? files : {};
38
38
  return yield originalMethod.call(this, ctx, next);
39
39
  });
40
40
  };
@@ -46,11 +46,11 @@ const Params = (...paramsData) => {
46
46
  return function (target, key, descriptor) {
47
47
  const originalMethod = descriptor.value;
48
48
  descriptor.value = function (ctx, next) {
49
- var _a;
50
49
  return __awaiter(this, void 0, void 0, function* () {
50
+ var _a;
51
51
  const q = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) !== null && _a !== void 0 ? _a : {};
52
52
  const params = paramsData.reduce((acc, key) => (q[key] != null ? Object.assign(Object.assign({}, acc), { [key]: q[key] }) : acc), {});
53
- ctx.params = Object.keys(params).length ? params : null;
53
+ ctx.params = Object.keys(params).length ? params : {};
54
54
  return yield originalMethod.call(this, ctx, next);
55
55
  });
56
56
  };
@@ -62,11 +62,11 @@ const Query = (...queryParms) => {
62
62
  return function (target, key, descriptor) {
63
63
  const originalMethod = descriptor.value;
64
64
  descriptor.value = function (ctx, next) {
65
- var _a;
66
65
  return __awaiter(this, void 0, void 0, function* () {
66
+ var _a;
67
67
  const q = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.query) !== null && _a !== void 0 ? _a : {};
68
68
  const query = queryParms.reduce((acc, key) => (q[key] != null ? Object.assign(Object.assign({}, acc), { [key]: q[key] }) : acc), {});
69
- ctx.query = Object.keys(query).length ? query : null;
69
+ ctx.query = Object.keys(query).length ? query : {};
70
70
  return yield originalMethod.call(this, ctx, next);
71
71
  });
72
72
  };
@@ -78,8 +78,8 @@ const Cookies = (...cookiesParms) => {
78
78
  return function (target, key, descriptor) {
79
79
  const originalMethod = descriptor.value;
80
80
  descriptor.value = function (ctx, next) {
81
- var _a;
82
81
  return __awaiter(this, void 0, void 0, function* () {
82
+ var _a;
83
83
  const q = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.cookies) !== null && _a !== void 0 ? _a : {};
84
84
  const cookies = cookiesParms.reduce((acc, key) => (q[key] != null ? Object.assign(Object.assign({}, acc), { [key]: q[key] }) : acc), {});
85
85
  ctx.cookies = Object.keys(cookies).length ? cookies : null;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/context.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEO,MAAM,IAAI,GAAG,CAAC,GAAG,SAAoB,EAAE,EAAE;IAC5C,OAAO,UAAS,MAAW,EAAE,GAAW,EAAE,UAA8B;QACpE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,UAAe,GAAc,EAAG,IAAmB;;;gBAClE,MAAM,CAAC,GAAG,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,mCAAI,EAAE,CAAA;gBACzB,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,C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OAAO,WAcnB"}
@@ -1,2 +1,2 @@
1
- import { TRequestFunction } from '../../types';
1
+ import { TRequestFunction } from '../types';
2
2
  export declare const Middleware: (middleware: TRequestFunction) => (target: any, key: string, descriptor: PropertyDescriptor) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAE,EAAE;IAE1D,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QACxC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAc,EAAG,IAAoB;YAC/D,IAAI;gBAEF,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAG,MAAM,CAAC,CAAA;gBAE1D,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAU,EAAE,EAAE;oBACpC,IAAG,GAAG,IAAI,IAAI,EAAE;wBACd,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;qBACjB;oBACD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAG,IAAI,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAA;aAEH;YAAC,OAAO,KAAW,EAAE;gBAEpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;aACnB;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAA;AAtBY,QAAA,UAAU,cAsBtB"}
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAE,EAAE;IAE1D,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QACxC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAc,EAAG,IAAoB;YAC/D,IAAI,CAAC;gBAEH,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAG,MAAM,CAAC,CAAA;gBAE1D,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAU,EAAE,EAAE;oBACpC,IAAG,GAAG,IAAI,IAAI,EAAE,CAAC;wBACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBAClB,CAAC;oBACD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAG,IAAI,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAA;YAEJ,CAAC;YAAC,OAAO,KAAW,EAAE,CAAC;gBAErB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAA;AAtBY,QAAA,UAAU,cAsBtB"}
@@ -1,2 +1,2 @@
1
- import { TSwagger } from "../../types";
1
+ import { TSwagger } from "../types";
2
2
  export declare const Swagger: (data: TSwagger) => (target: any, propertyKey: any) => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import findMyWayRouter from 'find-my-way';
3
2
  import { Server, ServerResponse } from 'http';
4
3
  import { Router, TContext, TNextFunction, TApplication } from '../..';
@@ -32,6 +31,7 @@ declare class Spear {
32
31
  private _onListeners;
33
32
  private _fileUploadOptions;
34
33
  constructor({ controllers, middlewares, globalPrefix, logger }?: TApplication);
34
+ get instance(): this;
35
35
  get routers(): findMyWayRouter.Instance<findMyWayRouter.HTTPVersion.V1>;
36
36
  /**
37
37
  * The 'enableCors' is used to enable the cors origins on the server.
@@ -54,14 +54,6 @@ declare class Spear {
54
54
  * @returns {this}
55
55
  */
56
56
  use(middleware: (ctx: TContext, next: TNextFunction) => void): this;
57
- /**
58
- * The 'useRouter' method is used to add the router in the request context.
59
- *
60
- * @parms {Function} router
61
- * @property {Function} router - get() , post() , put() , patch() , delete()
62
- * @returns {this}
63
- */
64
- useRouter(router: Router): this;
65
57
  /**
66
58
  * The 'useBodyParser' method is a middleware used to parse the request body of incoming HTTP requests.
67
59
  *
@@ -74,21 +66,27 @@ declare class Spear {
74
66
  * @returns {this}
75
67
  */
76
68
  useCookiesParser(): this;
69
+ /**
70
+ * The 'useRouter' method is used to add the router in the request context.
71
+ *
72
+ * @parms {Function} router
73
+ * @property {Function} router - get() , post() , put() , patch() , delete()
74
+ * @returns {this}
75
+ */
76
+ useRouter(router: Router): this;
77
77
  /**
78
78
  * The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
79
79
  *
80
80
  * @param {?Object}
81
81
  * @property {?number} limits
82
- * @property {?boolean} useTempFiles
83
82
  * @property {?string} tempFileDir
84
83
  * @property {?Object} removeTempFile
85
84
  * @property {boolean} removeTempFile.remove
86
85
  * @property {number} removeTempFile.ms
87
86
  * @returns
88
87
  */
89
- useFileUpload({ limits, useTempFiles, tempFileDir, removeTempFile }?: {
90
- limits?: number;
91
- useTempFiles?: boolean;
88
+ useFileUpload({ limit, tempFileDir, removeTempFile }?: {
89
+ limit?: number;
92
90
  tempFileDir?: string;
93
91
  removeTempFile?: {
94
92
  remove: boolean;
@@ -206,7 +204,7 @@ declare class Spear {
206
204
  * @param {function} cb
207
205
  * @returns
208
206
  */
209
- listen(port: number | (() => ServerResponse) | undefined, cb: (callback: {
207
+ listen(port: (number | (() => ServerResponse)) | undefined, cb: (callback: {
210
208
  server: Server;
211
209
  port: number;
212
210
  }) => void): Promise<void>;