pwi-plata-type 0.4.201 → 0.4.202

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.
Files changed (94) hide show
  1. package/README.md +2 -2
  2. package/package.json +58 -58
  3. package/src/@types/build.d.ts +26 -26
  4. package/src/@types/cluster.actions.d.ts +27 -27
  5. package/src/@types/cluster.d.ts +55 -55
  6. package/src/@types/create-cli.d.ts +8 -8
  7. package/src/@types/exported.d.ts +34 -31
  8. package/src/@types/fs.d.ts +6 -6
  9. package/src/@types/global.d.ts +131 -131
  10. package/src/@types/knex.d.ts +13 -13
  11. package/src/@types/model.d.ts +143 -143
  12. package/src/@types/router.d.ts +107 -107
  13. package/src/@types/sql.d.ts +120 -120
  14. package/src/@types/swagger.d.ts +22 -22
  15. package/src/bin/extras/create-api-cli.ts +218 -218
  16. package/src/bin/extras/create-cluster-cli.ts +160 -160
  17. package/src/bin/extras/create-lib-cli.ts +84 -84
  18. package/src/bin/extras/plata-create-tools.ts +97 -97
  19. package/src/bin/plata-api.ts +189 -189
  20. package/src/bin/plata-build.ts +19 -19
  21. package/src/bin/plata-cluster.ts +42 -42
  22. package/src/bin/plata-cmd.ts +19 -19
  23. package/src/bin/plata-create.ts +50 -50
  24. package/src/bin/plata-runtime.ts +110 -110
  25. package/src/bin/plata-swagger.ts +104 -104
  26. package/src/index.ts +20 -20
  27. package/src/libs/axios.ts +32 -32
  28. package/src/libs/build.ts +234 -234
  29. package/src/libs/build_wasm.ts +169 -169
  30. package/src/libs/cluster/cluster-controller.ts +93 -93
  31. package/src/libs/cluster.ts +319 -319
  32. package/src/libs/custom.ts +21 -21
  33. package/src/libs/env.ts +10 -10
  34. package/src/libs/fs.ts +399 -399
  35. package/src/libs/hot-reload.ts +63 -63
  36. package/src/libs/job.ts +32 -32
  37. package/src/libs/models/index.ts +4 -4
  38. package/src/libs/models/model-template-combine.ts +93 -93
  39. package/src/libs/models/model-template-env.ts +58 -58
  40. package/src/libs/models/model-template-union.ts +87 -87
  41. package/src/libs/models/model-template.ts +111 -111
  42. package/src/libs/models/model-validations.ts +453 -453
  43. package/src/libs/models/tools.ts +196 -196
  44. package/src/libs/router.ts +184 -184
  45. package/src/libs/runtime.ts +328 -328
  46. package/src/libs/sql.ts +931 -931
  47. package/src/libs/swagger.ts +81 -81
  48. package/src/libs/tools.ts +236 -236
  49. package/src/misc/golang/wasm_exec.js +574 -574
  50. package/src/scripts/post-install/api.ts +32 -32
  51. package/src/scripts/post-install/cluster.ts +28 -28
  52. package/src/scripts/post-install/lib.ts +25 -25
  53. package/src/scripts/post-install.ts +64 -64
  54. package/src/scripts/pre-test.ts +33 -33
  55. package/src/tests/1-config.test.ts +12 -12
  56. package/src/tests/2-effect.test.ts +107 -107
  57. package/src/tests/3-model.env.test.ts +66 -66
  58. package/src/tests/4-model.test.ts +150 -150
  59. package/src/tests/5-model.union.test.ts +160 -160
  60. package/src/tests/6-router.test.ts +44 -44
  61. package/src/tests/7-switch.test.ts +75 -75
  62. package/src/tests/8-brands.test.ts +52 -52
  63. package/src/tests/9-sql.test.ts +639 -639
  64. package/src/tests/assets/sql/example.sql +94 -94
  65. package/templates/create-cli/class.ts +13 -13
  66. package/templates/create-cli/cluster.ts +14 -14
  67. package/templates/create-cli/cmd.ts +3 -3
  68. package/templates/create-cli/config.ts +2 -2
  69. package/templates/create-cli/lib.ts +3 -3
  70. package/templates/create-cli/model.ts +14 -14
  71. package/templates/create-cli/route.ts +8 -8
  72. package/templates/create-cli/task.ts +13 -13
  73. package/templates/postinstall/api/.vscode/launch.json +20 -20
  74. package/templates/postinstall/api/Dockerfile +22 -22
  75. package/templates/postinstall/api/configs/env.ts +2 -2
  76. package/templates/postinstall/api/envs/debug.env +15 -15
  77. package/templates/postinstall/api/envs/homolog.env +15 -15
  78. package/templates/postinstall/api/envs/prod.env +15 -15
  79. package/templates/postinstall/api/tsconfig.json +24 -24
  80. package/templates/postinstall/cluster/.vscode/launch.json +20 -20
  81. package/templates/postinstall/cluster/Dockerfile +24 -24
  82. package/templates/postinstall/cluster/configs/env.ts +2 -2
  83. package/templates/postinstall/cluster/envs/debug.env +10 -10
  84. package/templates/postinstall/cluster/envs/homolog.env +10 -10
  85. package/templates/postinstall/cluster/envs/prod.env +10 -10
  86. package/templates/postinstall/cluster/tsconfig.json +24 -24
  87. package/templates/postinstall/lib/postinstall-tools.mjs +111 -111
  88. package/templates/postinstall/lib/postinstall.js +33 -33
  89. package/templates/postinstall/lib/tsconfig.json +22 -22
  90. package/templates/swagger-cli/header.json +21 -21
  91. package/templates/swagger-cli/route/body.json +14 -14
  92. package/templates/swagger-cli/route/header.json +18 -18
  93. package/templates/swagger-cli/route/response.json +53 -53
  94. package/tsconfig.json +28 -28
@@ -1,219 +1,219 @@
1
- import { tools } from "./plata-create-tools";
2
- import { Command } from 'commander'
3
- import path from 'node:path'
4
-
5
- const program = new Command()
6
-
7
- program.name('Plata Create cli')
8
- program.description('CLI usada para criar rotas, libs, models e muito mais na plata')
9
- program.version(Plata.PlataJson.version)
10
-
11
- program.command('route <routes...>')
12
- .description('Cria uma rota utilizando o templete da plata')
13
- .action(async routes => {
14
- if (!Array.isArray(routes)) {
15
- return
16
- }
17
-
18
- const promises: any[] = []
19
- const plataName = Plata.ProjectJson.plata_name
20
-
21
- for (const route of routes) {
22
- const r = `${route}/`.replace(/:(.*?)(?:\/|$)/g, (_, parm) => {
23
- return parm[parm.length - 1] !== '?' ? `{${parm}}/` : `[${parm.slice(0, -1)}]/`
24
- })
25
-
26
- const routeArg = r.slice(0, -1).split('/')
27
-
28
- const routeFileName = routeArg[routeArg.length - 1] === '' ? 'index' : routeArg.pop()
29
- const routeFilePath = path.join('routes', ...routeArg.filter(v => v !== ''))
30
-
31
- promises.push(tools.files.deployFileToProject(
32
- routeFilePath,
33
- 'route',
34
- `${routeFileName}.ts`,
35
- { PlataName: `${plataName}` }
36
- ).finally(() => console.log(
37
- `Rota ${routeFilePath}/${routeFileName === 'index' ? '' : routeFileName} criada`
38
- )))
39
- }
40
-
41
- await Promise.all(promises)
42
- })
43
- ;
44
-
45
- program.command('lib <libs...>')
46
- .description('Cria uma lib utilizando o templete da plata')
47
- .action(async libs => {
48
- if (!Array.isArray(libs)) {
49
- return
50
- }
51
-
52
- const promises: any[] = []
53
-
54
- for (const lib of libs) {
55
- promises.push(tools.files.deployFileToProject(
56
- 'libs',
57
- 'lib',
58
- `${lib}.ts`.toLowerCase(),
59
- { Name: `${lib}`, name: `${lib}`.toLowerCase() }
60
- ).finally(() => console.log(`Config ${lib} criada`)))
61
- }
62
-
63
- await Promise.all(promises)
64
-
65
- })
66
- ;
67
-
68
-
69
- program.command('class <classes...>')
70
- .description('Cria uma config com e uma clase utilizando o templete da plata')
71
- .action(async clazzs => {
72
- if (!Array.isArray(clazzs)) {
73
- return
74
- }
75
-
76
- const promises: any[] = []
77
-
78
- for (const lib of clazzs) {
79
- promises.push(tools.files.deployFileToProject(
80
- 'configs',
81
- 'config',
82
- `${lib}.ts`.toLowerCase(),
83
- { Name: `${lib}`, name: `${lib}`.toLowerCase() }
84
- ).finally(() => console.log(`Config ${lib} criada`)))
85
-
86
- promises.push(tools.files.deployFileToProject(
87
- 'libs',
88
- 'class',
89
- `${lib}.ts`.toLowerCase(),
90
- { Name: `${lib}`, name: `${lib}`.toLowerCase() }
91
- ).finally(() => console.log(`Classe ${lib} criada`)))
92
- }
93
-
94
- await Promise.all(promises)
95
- })
96
- ;
97
-
98
- program.command('config <configs...>')
99
- .description('Cria uma config utilizando o templete da plata')
100
- .action(async configs => {
101
- if (!Array.isArray(configs)) {
102
- return
103
- }
104
-
105
- const promises: any[] = []
106
-
107
- for (const config of configs) {
108
- promises.push(tools.files.deployFileToProject(
109
- 'configs',
110
- 'config',
111
- `${config}.ts`.toLowerCase(),
112
- { Name: `${config}`, name: `${config}`.toLowerCase() }
113
- ).finally(() => console.log(`Config ${config} criada`)))
114
- }
115
-
116
- await Promise.all(promises)
117
-
118
- })
119
- ;
120
-
121
- program.command('model <models...>')
122
- .description('Cria um model utilizando o templete da plata')
123
- .action(async models => {
124
- if (!Array.isArray(models)) {
125
- return
126
- }
127
-
128
- const promises: any[] = []
129
- const plataName = Plata.ProjectJson.plata_name
130
-
131
- for (const model of models) {
132
- promises.push(tools.files.deployFileToProject(
133
- 'models',
134
- 'model',
135
- `${model}.ts`.toLowerCase(),
136
- { Name: `${model}`, PlataName: `${plataName}` }
137
- ).finally(() => console.log(`Model ${model} criada`)))
138
- }
139
-
140
- await Promise.all(promises)
141
- })
142
- ;
143
-
144
- program.command('task <tasks...>')
145
- .description('Cria uma task utilizando o templete da plata')
146
- .action(async tasks => {
147
- if (!Array.isArray(tasks)) {
148
- return
149
- }
150
-
151
- const promises: any[] = []
152
- const plataName = Plata.ProjectJson.plata_name
153
-
154
- for (const task of tasks) {
155
- promises.push(tools.files.deployFileToProject(
156
- 'tasks',
157
- 'task',
158
- `${task}.ts`.toLowerCase(),
159
- { Name: `${task}`, PlataName: `${plataName}` }
160
- ).finally(() => console.log(`Task ${tasks} criada`)))
161
- }
162
-
163
- await Promise.all(promises)
164
- })
165
- ;
166
-
167
- program.command('cluster <clusters...>')
168
- .description('Cria o arquivo do worker utilizando o templete da plata')
169
- .action(async clusters => {
170
- if (!Array.isArray(clusters)) return
171
-
172
- const promises: any[] = []
173
- const plataName = Plata.ProjectJson.plata_name
174
-
175
- for (const cluster of clusters) {
176
- promises.push(tools.files.deployFileToProject(
177
- 'clusters',
178
- 'cluster',
179
- `${cluster}.ts`.toLowerCase(),
180
- { Name: `${cluster}`, name: `${cluster}`.toLowerCase(), PlataName: `${plataName}` }
181
- ).finally(() => console.log(`Worker ${cluster} criada`)))
182
- }
183
- })
184
- ;
185
-
186
- program.command('cmd <cmds...>')
187
- .description('Cria o arquivo de um comando cmd')
188
- .action(async cmds => {
189
- if (!Array.isArray(cmds)) return
190
-
191
- for (const cmd of cmds) {
192
- await tools.files.deployFileToProject(
193
- 'cmds',
194
- 'cmd',
195
- `${cmd}.ts`.toLowerCase(),
196
- {}
197
- ).finally(() => console.log(`Cmd ${cmd} criado`))
198
-
199
- Plata.ProjectJson['my-scripts'] = Plata.ProjectJson['my-scripts'] ?? Object.create(null)
200
-
201
- if (Plata.ProjectJson['my-scripts'][`cmd:${cmd}`] === undefined) {
202
- Plata.ProjectJson['my-scripts'][`cmd:${cmd}`] = `plata-runtime + plata-cmd ${cmd}`
203
- }
204
-
205
- Plata.ProjectJson.scripts = JSON.parse(JSON.stringify({
206
- ...Plata.ProjectJson['my-scripts'],
207
- ...Plata.ProjectJson.scripts,
208
- }))
209
-
210
- await Plata.files.fs
211
- .writeFile(
212
- path.join(Plata.ProjectDir, 'package.json'),
213
- JSON.stringify(Plata.ProjectJson, null, 4)
214
- )
215
- ;
216
- }
217
- })
218
-
1
+ import { tools } from "./plata-create-tools";
2
+ import { Command } from 'commander'
3
+ import path from 'node:path'
4
+
5
+ const program = new Command()
6
+
7
+ program.name('Plata Create cli')
8
+ program.description('CLI usada para criar rotas, libs, models e muito mais na plata')
9
+ program.version(Plata.PlataJson.version)
10
+
11
+ program.command('route <routes...>')
12
+ .description('Cria uma rota utilizando o templete da plata')
13
+ .action(async routes => {
14
+ if (!Array.isArray(routes)) {
15
+ return
16
+ }
17
+
18
+ const promises: any[] = []
19
+ const plataName = Plata.ProjectJson.plata_name
20
+
21
+ for (const route of routes) {
22
+ const r = `${route}/`.replace(/:(.*?)(?:\/|$)/g, (_, parm) => {
23
+ return parm[parm.length - 1] !== '?' ? `{${parm}}/` : `[${parm.slice(0, -1)}]/`
24
+ })
25
+
26
+ const routeArg = r.slice(0, -1).split('/')
27
+
28
+ const routeFileName = routeArg[routeArg.length - 1] === '' ? 'index' : routeArg.pop()
29
+ const routeFilePath = path.join('routes', ...routeArg.filter(v => v !== ''))
30
+
31
+ promises.push(tools.files.deployFileToProject(
32
+ routeFilePath,
33
+ 'route',
34
+ `${routeFileName}.ts`,
35
+ { PlataName: `${plataName}` }
36
+ ).finally(() => console.log(
37
+ `Rota ${routeFilePath}/${routeFileName === 'index' ? '' : routeFileName} criada`
38
+ )))
39
+ }
40
+
41
+ await Promise.all(promises)
42
+ })
43
+ ;
44
+
45
+ program.command('lib <libs...>')
46
+ .description('Cria uma lib utilizando o templete da plata')
47
+ .action(async libs => {
48
+ if (!Array.isArray(libs)) {
49
+ return
50
+ }
51
+
52
+ const promises: any[] = []
53
+
54
+ for (const lib of libs) {
55
+ promises.push(tools.files.deployFileToProject(
56
+ 'libs',
57
+ 'lib',
58
+ `${lib}.ts`.toLowerCase(),
59
+ { Name: `${lib}`, name: `${lib}`.toLowerCase() }
60
+ ).finally(() => console.log(`Config ${lib} criada`)))
61
+ }
62
+
63
+ await Promise.all(promises)
64
+
65
+ })
66
+ ;
67
+
68
+
69
+ program.command('class <classes...>')
70
+ .description('Cria uma config com e uma clase utilizando o templete da plata')
71
+ .action(async clazzs => {
72
+ if (!Array.isArray(clazzs)) {
73
+ return
74
+ }
75
+
76
+ const promises: any[] = []
77
+
78
+ for (const lib of clazzs) {
79
+ promises.push(tools.files.deployFileToProject(
80
+ 'configs',
81
+ 'config',
82
+ `${lib}.ts`.toLowerCase(),
83
+ { Name: `${lib}`, name: `${lib}`.toLowerCase() }
84
+ ).finally(() => console.log(`Config ${lib} criada`)))
85
+
86
+ promises.push(tools.files.deployFileToProject(
87
+ 'libs',
88
+ 'class',
89
+ `${lib}.ts`.toLowerCase(),
90
+ { Name: `${lib}`, name: `${lib}`.toLowerCase() }
91
+ ).finally(() => console.log(`Classe ${lib} criada`)))
92
+ }
93
+
94
+ await Promise.all(promises)
95
+ })
96
+ ;
97
+
98
+ program.command('config <configs...>')
99
+ .description('Cria uma config utilizando o templete da plata')
100
+ .action(async configs => {
101
+ if (!Array.isArray(configs)) {
102
+ return
103
+ }
104
+
105
+ const promises: any[] = []
106
+
107
+ for (const config of configs) {
108
+ promises.push(tools.files.deployFileToProject(
109
+ 'configs',
110
+ 'config',
111
+ `${config}.ts`.toLowerCase(),
112
+ { Name: `${config}`, name: `${config}`.toLowerCase() }
113
+ ).finally(() => console.log(`Config ${config} criada`)))
114
+ }
115
+
116
+ await Promise.all(promises)
117
+
118
+ })
119
+ ;
120
+
121
+ program.command('model <models...>')
122
+ .description('Cria um model utilizando o templete da plata')
123
+ .action(async models => {
124
+ if (!Array.isArray(models)) {
125
+ return
126
+ }
127
+
128
+ const promises: any[] = []
129
+ const plataName = Plata.ProjectJson.plata_name
130
+
131
+ for (const model of models) {
132
+ promises.push(tools.files.deployFileToProject(
133
+ 'models',
134
+ 'model',
135
+ `${model}.ts`.toLowerCase(),
136
+ { Name: `${model}`, PlataName: `${plataName}` }
137
+ ).finally(() => console.log(`Model ${model} criada`)))
138
+ }
139
+
140
+ await Promise.all(promises)
141
+ })
142
+ ;
143
+
144
+ program.command('task <tasks...>')
145
+ .description('Cria uma task utilizando o templete da plata')
146
+ .action(async tasks => {
147
+ if (!Array.isArray(tasks)) {
148
+ return
149
+ }
150
+
151
+ const promises: any[] = []
152
+ const plataName = Plata.ProjectJson.plata_name
153
+
154
+ for (const task of tasks) {
155
+ promises.push(tools.files.deployFileToProject(
156
+ 'tasks',
157
+ 'task',
158
+ `${task}.ts`.toLowerCase(),
159
+ { Name: `${task}`, PlataName: `${plataName}` }
160
+ ).finally(() => console.log(`Task ${tasks} criada`)))
161
+ }
162
+
163
+ await Promise.all(promises)
164
+ })
165
+ ;
166
+
167
+ program.command('cluster <clusters...>')
168
+ .description('Cria o arquivo do worker utilizando o templete da plata')
169
+ .action(async clusters => {
170
+ if (!Array.isArray(clusters)) return
171
+
172
+ const promises: any[] = []
173
+ const plataName = Plata.ProjectJson.plata_name
174
+
175
+ for (const cluster of clusters) {
176
+ promises.push(tools.files.deployFileToProject(
177
+ 'clusters',
178
+ 'cluster',
179
+ `${cluster}.ts`.toLowerCase(),
180
+ { Name: `${cluster}`, name: `${cluster}`.toLowerCase(), PlataName: `${plataName}` }
181
+ ).finally(() => console.log(`Worker ${cluster} criada`)))
182
+ }
183
+ })
184
+ ;
185
+
186
+ program.command('cmd <cmds...>')
187
+ .description('Cria o arquivo de um comando cmd')
188
+ .action(async cmds => {
189
+ if (!Array.isArray(cmds)) return
190
+
191
+ for (const cmd of cmds) {
192
+ await tools.files.deployFileToProject(
193
+ 'cmds',
194
+ 'cmd',
195
+ `${cmd}.ts`.toLowerCase(),
196
+ {}
197
+ ).finally(() => console.log(`Cmd ${cmd} criado`))
198
+
199
+ Plata.ProjectJson['my-scripts'] = Plata.ProjectJson['my-scripts'] ?? Object.create(null)
200
+
201
+ if (Plata.ProjectJson['my-scripts'][`cmd:${cmd}`] === undefined) {
202
+ Plata.ProjectJson['my-scripts'][`cmd:${cmd}`] = `plata-runtime + plata-cmd ${cmd}`
203
+ }
204
+
205
+ Plata.ProjectJson.scripts = JSON.parse(JSON.stringify({
206
+ ...Plata.ProjectJson['my-scripts'],
207
+ ...Plata.ProjectJson.scripts,
208
+ }))
209
+
210
+ await Plata.files.fs
211
+ .writeFile(
212
+ path.join(Plata.ProjectDir, 'package.json'),
213
+ JSON.stringify(Plata.ProjectJson, null, 4)
214
+ )
215
+ ;
216
+ }
217
+ })
218
+
219
219
  export const cli = program