pwi-plata-type 0.4.166 → 0.4.167

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 (101) hide show
  1. package/README.md +2 -2
  2. package/__BUILD__/libs/sql.js +4 -1
  3. package/__BUILD__/libs/sql.js.map +1 -1
  4. package/package.json +53 -53
  5. package/src/@types/build.d.ts +26 -26
  6. package/src/@types/cluster.actions.d.ts +27 -27
  7. package/src/@types/cluster.d.ts +55 -55
  8. package/src/@types/create-cli.d.ts +8 -8
  9. package/src/@types/exported.d.ts +31 -31
  10. package/src/@types/fs.d.ts +6 -6
  11. package/src/@types/global.d.ts +113 -113
  12. package/src/@types/knex.d.ts +13 -13
  13. package/src/@types/model.d.ts +143 -143
  14. package/src/@types/router.d.ts +107 -107
  15. package/src/@types/sql.d.ts +75 -75
  16. package/src/@types/swagger.d.ts +22 -22
  17. package/src/bin/extras/create-api-cli.ts +218 -218
  18. package/src/bin/extras/create-cluster-cli.ts +160 -160
  19. package/src/bin/extras/create-lib-cli.ts +84 -84
  20. package/src/bin/extras/plata-create-tools.ts +97 -97
  21. package/src/bin/plata-api.ts +189 -189
  22. package/src/bin/plata-build.ts +17 -17
  23. package/src/bin/plata-cluster.ts +42 -42
  24. package/src/bin/plata-cmd.ts +18 -18
  25. package/src/bin/plata-create.ts +49 -49
  26. package/src/bin/plata-runtime.ts +131 -131
  27. package/src/bin/plata-swagger.ts +99 -99
  28. package/src/bin/runtime/_setupRuntime.ts +48 -48
  29. package/src/bin/runtime/_types.d.ts +7 -7
  30. package/src/bin/runtime/class.ts +20 -20
  31. package/src/bin/runtime/dirs.ts +25 -25
  32. package/src/bin/runtime/effect.ts +60 -60
  33. package/src/bin/runtime/fs.ts +10 -10
  34. package/src/bin/runtime/promises.ts +18 -18
  35. package/src/bin/runtime/require.ts +113 -113
  36. package/src/bin/runtime/sql.ts +12 -12
  37. package/src/bin/runtime/switch.ts +60 -60
  38. package/src/index.ts +19 -19
  39. package/src/libs/axios.ts +51 -51
  40. package/src/libs/build.ts +162 -162
  41. package/src/libs/cluster/cluster-controller.ts +93 -93
  42. package/src/libs/cluster.ts +330 -330
  43. package/src/libs/custom.ts +15 -15
  44. package/src/libs/env.ts +10 -10
  45. package/src/libs/fs.ts +399 -399
  46. package/src/libs/hot-reload.ts +63 -63
  47. package/src/libs/models/index.ts +4 -4
  48. package/src/libs/models/model-template-combine.ts +93 -93
  49. package/src/libs/models/model-template-env.ts +58 -58
  50. package/src/libs/models/model-template-union.ts +83 -83
  51. package/src/libs/models/model-template.ts +107 -107
  52. package/src/libs/models/model-validations.ts +443 -443
  53. package/src/libs/models/tools.ts +194 -194
  54. package/src/libs/router.ts +185 -185
  55. package/src/libs/sql.ts +792 -788
  56. package/src/libs/swagger.ts +81 -81
  57. package/src/libs/tools.ts +240 -240
  58. package/src/scripts/post-install/api.ts +32 -32
  59. package/src/scripts/post-install/cluster.ts +28 -28
  60. package/src/scripts/post-install/lib.ts +25 -25
  61. package/src/scripts/post-install.ts +64 -64
  62. package/src/scripts/pre-test.ts +33 -33
  63. package/src/tests/assets/sql/example.sql +76 -76
  64. package/src/tests/config.test.ts +12 -12
  65. package/src/tests/effect.test.ts +62 -62
  66. package/src/tests/model.env.test.ts +66 -66
  67. package/src/tests/model.test.ts +141 -141
  68. package/src/tests/model.union.test.ts +160 -160
  69. package/src/tests/router.test.ts +44 -44
  70. package/src/tests/sql.test.ts +502 -502
  71. package/src/tests/switch.test.ts +76 -76
  72. package/templates/create-cli/class.ts +13 -13
  73. package/templates/create-cli/cluster.ts +14 -14
  74. package/templates/create-cli/cmd.ts +3 -3
  75. package/templates/create-cli/config.ts +2 -2
  76. package/templates/create-cli/lib.ts +3 -3
  77. package/templates/create-cli/model.ts +14 -14
  78. package/templates/create-cli/route.ts +8 -8
  79. package/templates/create-cli/task.ts +13 -13
  80. package/templates/postinstall/api/.vscode/launch.json +20 -20
  81. package/templates/postinstall/api/Dockerfile +24 -24
  82. package/templates/postinstall/api/configs/env.ts +2 -2
  83. package/templates/postinstall/api/envs/debug.env +15 -15
  84. package/templates/postinstall/api/envs/homolog.env +15 -15
  85. package/templates/postinstall/api/envs/prod.env +15 -15
  86. package/templates/postinstall/api/tsconfig.json +24 -24
  87. package/templates/postinstall/cluster/.vscode/launch.json +20 -20
  88. package/templates/postinstall/cluster/Dockerfile +24 -24
  89. package/templates/postinstall/cluster/configs/env.ts +2 -2
  90. package/templates/postinstall/cluster/envs/debug.env +10 -10
  91. package/templates/postinstall/cluster/envs/homolog.env +10 -10
  92. package/templates/postinstall/cluster/envs/prod.env +10 -10
  93. package/templates/postinstall/cluster/tsconfig.json +24 -24
  94. package/templates/postinstall/lib/postinstall-tools.mjs +111 -111
  95. package/templates/postinstall/lib/postinstall.js +33 -33
  96. package/templates/postinstall/lib/tsconfig.json +22 -22
  97. package/templates/swagger-cli/header.json +21 -21
  98. package/templates/swagger-cli/route/body.json +14 -14
  99. package/templates/swagger-cli/route/header.json +18 -18
  100. package/templates/swagger-cli/route/response.json +53 -53
  101. 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