pwi-plata-type 0.1.2 → 0.1.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.
@@ -1,4 +1,5 @@
1
1
  import { tools } from "./plata-create-tools.js";
2
+ import { PlataDirs } from "../../libs/tools.js"
2
3
  import * as path from 'node:path'
3
4
 
4
5
  export async function h() {
@@ -50,6 +51,17 @@ export async function h() {
50
51
  )))
51
52
 
52
53
  break;
54
+ case 'model':
55
+ const modelName = args.shift()
56
+ const plataName = PlataDirs.ProjectJson.plata_name
57
+
58
+ promises.push(tools.files.deployFileToProject(
59
+ 'models',
60
+ 'model',
61
+ `${modelName.toLowerCase()}.ts`,
62
+ { Name: `${modelName}`, PlataName: `${plataName}` }
63
+ ).finally(() => console.log(`Model ${modelName} criada`)))
64
+ break;
53
65
  }
54
66
 
55
67
  await Promise.all(promises)
package/libs/model.ts CHANGED
@@ -100,7 +100,7 @@ export async function _validaModel(value: any, model: Model, name?: string): Pro
100
100
  if (t.length === undefined) {
101
101
  const m = new Model(t as ModelType)
102
102
 
103
- promises.push(_validaModel(value[campo], m, `${campo}.`))
103
+ promises.push(_validaModel(value[campo], m, `${name ?? ''}${campo}.`))
104
104
  continue
105
105
  }
106
106
 
@@ -306,7 +306,7 @@ export function Int(): ModelValicacaoPrimitivo {
306
306
 
307
307
  export function isArray(tamanhoMaximo?: number): ModelValicacaoPrimitivo {
308
308
  return async (nome: string, valor: any) => {
309
- if (valor === undefined) {
309
+ if (valor === null) {
310
310
  return {
311
311
  error: {
312
312
  errorID: "BPCVARR001",
@@ -354,7 +354,7 @@ export function Optional(): ModelValicacaoPrimitivo {
354
354
 
355
355
  export function Required(): ModelValicacaoPrimitivo {
356
356
  return async (nome: string, valor: any) => {
357
- if (valor === undefined) {
357
+ if (valor === null) {
358
358
  return {
359
359
  error: {
360
360
  errorID: "BPCVREQ001",
@@ -463,7 +463,7 @@ export function VarChar(size: number): ModelValicacaoPrimitivo {
463
463
  return {
464
464
  error: {
465
465
  errorID: "BPVVARC001",
466
- msg: `O campo ${nome} tem que menos de ${nome} caracteres`
466
+ msg: `O campo ${nome} tem que menos de ${size} caracteres`
467
467
  },
468
468
  continua: false
469
469
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pwi-plata-type",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "bin": {
@@ -0,0 +1,26 @@
1
+ //@ts-nocheck
2
+ import { PlataModels } from "ç__PlataName__ç";
3
+
4
+ const ç__Name__ç = new PlataModels.Model({
5
+ campo: [ PlataModels.Required(), PlataModels.Int() ],
6
+ objeto: {
7
+ campo: [ PlataModels.Optional(), PlataModels.DateTime() ]
8
+ },
9
+ arrayItens: [{
10
+ campo: [ PlataModels.Required(), PlataModels.Telefone() ]
11
+ }]
12
+ })
13
+
14
+ ç__Name__ç.addValidacao('Validação Customizada', async (objeto) => {
15
+ if (objeto.campo > 30) {
16
+ return {
17
+ errorID: 'BM0001',
18
+ msg: 'O campo não pode ser maior que 30',
19
+ error: `valor do campo: ${objeto.campo}`
20
+ }
21
+ }
22
+
23
+ return null
24
+ })
25
+
26
+ export const ç__Name__çModel = ç__Name__ç
@@ -7,6 +7,7 @@ export async function install({ dirs, projectPackageJson }) {
7
7
  promises.push(t.createFolderProject('clusters'))
8
8
  promises.push(t.createFolderProject('routes'))
9
9
  promises.push(t.createFolderProject('libs'))
10
+ promises.push(t.createFolderProject('models'))
10
11
 
11
12
  promises.push(t.copyFolderToProject('configs'))
12
13
  promises.push(t.copyFolderToProject('envs'))