pwi-plata-type 0.2.4 → 0.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.
@@ -8,7 +8,7 @@ export async function h() {
8
8
 
9
9
  switch (command) {
10
10
  case 'lib':
11
- const nameLib = args.shift()
11
+ const nameLib = `${args.shift()}`
12
12
  promises.push(tools.files.deployFileToProject(
13
13
  'configs',
14
14
  'config',
@@ -24,7 +24,7 @@ export async function h() {
24
24
  ).finally(() => console.log(`Lib ${nameLib.toLowerCase()} criada`)))
25
25
  break;
26
26
  case 'config':
27
- const nameConfig = args.shift()
27
+ const nameConfig = `${args.shift()}`
28
28
  promises.push(tools.files.deployFileToProject(
29
29
  'configs',
30
30
  'config',
@@ -45,14 +45,14 @@ export async function h() {
45
45
  routeFilePath,
46
46
  'route',
47
47
  `${routeFileName}.ts`,
48
- {}
48
+ { PlataName: `${PlataDirs.ProjectJson.plata_name}` }
49
49
  ).finally(() => console.log(
50
50
  `Rota ${routeFilePath}/${routeFileName === 'index' ? '' : routeFileName} criada`
51
51
  )))
52
52
 
53
53
  break;
54
54
  case 'model':
55
- const modelName = args.shift()
55
+ const modelName = `${args.shift()}`
56
56
  const plataName = PlataDirs.ProjectJson.plata_name
57
57
 
58
58
  promises.push(tools.files.deployFileToProject(
package/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as PlataCluster from './libs/cluster.js'
2
2
  import * as PlataEnv from './libs/env.js'
3
3
  import * as PlataRoutes from './libs/routes.js'
4
+ import { PlataRoute } from './libs/routes.js'
4
5
  import * as PlataTools from './libs/tools.js'
5
6
  import * as PlataModels from './libs/model.js'
6
7
 
@@ -10,4 +11,5 @@ export {
10
11
  PlataRoutes,
11
12
  PlataTools,
12
13
  PlataModels,
14
+ PlataRoute,
13
15
  }
package/libs/routes.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PlataDirs, PlataRequire } from "./tools.js";
2
- import express, { Express, Router } from "express";
2
+ import express, { Router } from "express";
3
3
 
4
4
  export type PlataRouter = () => Router
5
5
 
@@ -31,4 +31,24 @@ export async function loadExpressRoutes(): Promise<Router> {
31
31
  }
32
32
 
33
33
  return router
34
+ }
35
+
36
+ export type PlataRequest = express.Request & { user: any, extras: any }
37
+
38
+ export type PlataRequestHandler = (req: PlataRequest, res: express.Response, next: express.NextFunction) => Promise<any>
39
+
40
+ export function PlataRoute(r: PlataRequestHandler): express.RequestHandler {
41
+ return async (req, res, next) => {
42
+ const aReq = req as any
43
+
44
+ if (aReq.user === undefined) {
45
+ aReq.user = new Object(null)
46
+ }
47
+
48
+ if (aReq.extras === undefined) {
49
+ aReq.extras = new Object(null)
50
+ }
51
+
52
+ return r(aReq, res, next)
53
+ }
34
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwi-plata-type",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "bin": {
@@ -1,11 +1,13 @@
1
+ //@ts-nocheck
1
2
  import { Router } from 'express'
3
+ import { PlataRoute } from 'ç__PlataName__ç'
2
4
 
3
5
  export default (): Router => {
4
6
  const router = Router()
5
7
 
6
- router.get('/', (req, res) => {
8
+ router.get('/', PlataRoute(async (req, res) => {
7
9
  return res.status(200).json({})
8
- })
10
+ }))
9
11
 
10
12
  return router
11
13
  }