pwi-plata-type 0.2.15 → 0.2.18
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/Dockerfile +10 -5
- package/libs/model.ts +20 -1
- package/libs/swagger.ts +2 -1
- package/package.json +2 -2
- package/templates/postinstall/api/Dockerfile +9 -4
package/Dockerfile
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
FROM node:16-alpine
|
|
1
|
+
FROM node:16-alpine AS build
|
|
2
2
|
|
|
3
3
|
WORKDIR /usr/src/app
|
|
4
4
|
|
|
5
|
-
COPY
|
|
5
|
+
COPY . ./
|
|
6
|
+
|
|
7
|
+
RUN npm ci --only=production && \
|
|
8
|
+
npm run build
|
|
9
|
+
|
|
10
|
+
FROM node:16-alpine AS bin
|
|
6
11
|
|
|
7
12
|
EXPOSE 3050
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
WORKDIR /usr/src/app
|
|
10
15
|
|
|
11
|
-
COPY .
|
|
16
|
+
COPY --from=build /usr/src/app/build .
|
|
12
17
|
|
|
13
|
-
CMD [ "
|
|
18
|
+
CMD [ "npm", "start" ]
|
package/libs/model.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface RetornoValicadaoModel {
|
|
|
12
12
|
|
|
13
13
|
export type ModelValicacao = (value: any) => Promise<PlataError | null>
|
|
14
14
|
|
|
15
|
+
export type ModelTratamento<T> = (value: T) => T
|
|
16
|
+
|
|
15
17
|
export type ModelValicacaoPrimitivo = (nome: string, valor: any) => Promise<RetornoValidacaoPrimitivo>
|
|
16
18
|
|
|
17
19
|
export interface ModelType {
|
|
@@ -21,6 +23,7 @@ export interface ModelType {
|
|
|
21
23
|
export class Model {
|
|
22
24
|
public readonly template: ModelType
|
|
23
25
|
public readonly validacoes: Map<string, ModelValicacao>
|
|
26
|
+
public readonly tratamentos: Map<string, ModelTratamento<any>>
|
|
24
27
|
|
|
25
28
|
constructor(template: ModelType) {
|
|
26
29
|
this.template = template
|
|
@@ -30,6 +33,10 @@ export class Model {
|
|
|
30
33
|
public addValidacao(nome: string, callback: ModelValicacao) {
|
|
31
34
|
this.validacoes.set(nome, callback)
|
|
32
35
|
}
|
|
36
|
+
|
|
37
|
+
public addTratamento<T>(nome: string, callback: ModelTratamento<T>) {
|
|
38
|
+
this.tratamentos.set(nome, callback)
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export async function _validaCampo(value: any, pipelines: ModelValicacaoPrimitivo[], name: string): Promise<PlataError | null> {
|
|
@@ -48,6 +55,14 @@ export async function _validaCampo(value: any, pipelines: ModelValicacaoPrimitiv
|
|
|
48
55
|
return null
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
export function _trataModel<T>(value: T, model: Model): T {
|
|
59
|
+
model.tratamentos.forEach(tratamento => {
|
|
60
|
+
value = tratamento(value)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return value
|
|
64
|
+
}
|
|
65
|
+
|
|
51
66
|
export function _filtraModel(value: any, model: Model): any {
|
|
52
67
|
for (const campo in model.template) {
|
|
53
68
|
const t = model.template[campo]
|
|
@@ -169,6 +184,8 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
|
|
|
169
184
|
export async function valida(value: any, model: Model): Promise<RetornoValicadaoModel> {
|
|
170
185
|
value = _filtraModel(value, model)
|
|
171
186
|
|
|
187
|
+
value = _trataModel(value, model)
|
|
188
|
+
|
|
172
189
|
return {
|
|
173
190
|
value,
|
|
174
191
|
errors: await _validaModel(value, model),
|
|
@@ -279,7 +296,9 @@ export function Int(): ModelValicacaoPrimitivo {
|
|
|
279
296
|
}
|
|
280
297
|
}
|
|
281
298
|
|
|
282
|
-
|
|
299
|
+
const v = +valor
|
|
300
|
+
|
|
301
|
+
if (Math.round(v) !== v) {
|
|
283
302
|
return {
|
|
284
303
|
error: {
|
|
285
304
|
errorID: "BPMVINT002",
|
package/libs/swagger.ts
CHANGED
|
@@ -45,7 +45,8 @@ export namespace PlataSwagger {
|
|
|
45
45
|
|
|
46
46
|
obj.paths[httpPath][metodo] = { ...header, responses: response }
|
|
47
47
|
|
|
48
|
-
if
|
|
48
|
+
//https://bobbyhadz.com/blog/javascript-check-if-object-is-empty
|
|
49
|
+
if (Object.keys(body).length !== 0) {
|
|
49
50
|
if (!Array.isArray(obj.paths[httpPath][metodo].parameters)) {
|
|
50
51
|
obj.paths[httpPath][metodo].parameters = []
|
|
51
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwi-plata-type",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"jest": "^28.1.1",
|
|
24
24
|
"swagger-ui-express": "^4.4.0",
|
|
25
25
|
"ts-jest": "^28.0.4",
|
|
26
|
-
"ts-node": "
|
|
26
|
+
"ts-node": "10.8.2"
|
|
27
27
|
},
|
|
28
28
|
"description": "",
|
|
29
29
|
"devDependencies": {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
FROM node:16-alpine
|
|
1
|
+
FROM node:16-alpine AS build
|
|
2
2
|
|
|
3
3
|
WORKDIR /usr/src/app
|
|
4
4
|
|
|
5
|
-
COPY
|
|
5
|
+
COPY . ./
|
|
6
|
+
|
|
7
|
+
RUN npm ci --only=production && \
|
|
8
|
+
npm run build
|
|
9
|
+
|
|
10
|
+
FROM node:16-alpine AS bin
|
|
6
11
|
|
|
7
12
|
EXPOSE 3050
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
WORKDIR /usr/src/app
|
|
10
15
|
|
|
11
|
-
COPY .
|
|
16
|
+
COPY --from=build /usr/src/app/build .
|
|
12
17
|
|
|
13
18
|
CMD [ "npm", "start" ]
|