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,43 +1,43 @@
1
- import { PlataClusterManager } from "++/libs/cluster"
2
-
3
- export async function main() {
4
- const cluster = new PlataClusterManager()
5
-
6
- if (cluster.isPrimary()) {
7
- const clustersPromise: RequireFolderReturn<{ default: Cluster.WorkerConfig }> = require("@@/clusters/*.*")
8
- const clusters = await clustersPromise
9
-
10
- if (clusters.errorID !== undefined) {
11
- console.log(clusters)
12
- process.exit(0)
13
- }
14
-
15
- const promises: Promise<void>[] = []
16
-
17
- clusters.forEach(c => {
18
- const config = c.exports.default
19
- promises.push(cluster._startCluster(config).then(r => {
20
- if (r !== null) {
21
- console.log(r)
22
- process.exit(0)
23
- }
24
- }))
25
- })
26
-
27
- await Promise.all(promises)
28
- } else {
29
- if (Plata.config._PLATA_WORKER_NAME === undefined) {
30
- await cluster.send({
31
- action: 'KILL',
32
- msg: 'tried to start a Worker without _PLATA_WORKER_NAME'
33
- })
34
-
35
- return
36
- }
37
-
38
- await cluster._onStartCluster(
39
- Plata.config._PLATA_WORKER_NAME,
40
- Plata.config._PLATA_WORKER_TYPE,
41
- )
42
- }
1
+ import { PlataClusterManager } from "++/libs/cluster"
2
+
3
+ export async function main() {
4
+ const cluster = new PlataClusterManager()
5
+
6
+ if (cluster.isPrimary()) {
7
+ const clustersPromise: RequireFolderReturn<{ default: Cluster.WorkerConfig }> = require("@@/clusters/*.*")
8
+ const clusters = await clustersPromise
9
+
10
+ if (clusters.errorID !== undefined) {
11
+ console.log(clusters)
12
+ process.exit(0)
13
+ }
14
+
15
+ const promises: Promise<void>[] = []
16
+
17
+ clusters.forEach(c => {
18
+ const config = c.exports.default
19
+ promises.push(cluster._startCluster(config).then(r => {
20
+ if (r !== null) {
21
+ console.log(r)
22
+ process.exit(0)
23
+ }
24
+ }))
25
+ })
26
+
27
+ await Promise.all(promises)
28
+ } else {
29
+ if (Plata.config._PLATA_WORKER_NAME === undefined) {
30
+ await cluster.send({
31
+ action: 'KILL',
32
+ msg: 'tried to start a Worker without _PLATA_WORKER_NAME'
33
+ })
34
+
35
+ return
36
+ }
37
+
38
+ await cluster._onStartCluster(
39
+ Plata.config._PLATA_WORKER_NAME,
40
+ Plata.config._PLATA_WORKER_TYPE,
41
+ )
42
+ }
43
43
  }
@@ -1,19 +1,19 @@
1
- export async function main() {
2
- const args = process.argv.slice(
3
- process.argv.indexOf('+')
4
- )
5
-
6
- const run = args.slice(
7
- args.indexOf('plata-cmd') + 1
8
- )[0]?.toLowerCase()
9
-
10
- if (!run) {
11
- console.log('Comando inválido')
12
- console.log(process.argv.join(' '))
13
- process.exit(0)
14
- }
15
-
16
- const cmd: { main: () => Promise<void> } = require(`@@/cmds/${run}`)
17
-
18
- return cmd.main()
1
+ export async function main() {
2
+ const args = process.argv.slice(
3
+ process.argv.indexOf('+')
4
+ )
5
+
6
+ const run = args.slice(
7
+ args.indexOf('plata-cmd') + 1
8
+ )[0]?.toLowerCase()
9
+
10
+ if (!run) {
11
+ console.log('Comando inválido')
12
+ console.log(process.argv.join(' '))
13
+ process.exit(0)
14
+ }
15
+
16
+ const cmd: { main: () => Promise<void> } = require(`@@/cmds/${run}`)
17
+
18
+ return cmd.main()
19
19
  }
@@ -1,50 +1,50 @@
1
- import { PlataBuild } from "++/libs/build"
2
- import type { Command } from "commander"
3
-
4
- export const main = async () => {
5
- if (Plata.ProjectJson.plata_no_setup !== undefined) {
6
- console.log('Plata não configurada remova o plata_no_setup do package.json')
7
- process.exit(0)
8
- }
9
-
10
- const args = process.argv.slice(process.argv.indexOf('+'))
11
- let cli: Command | null = null
12
-
13
- switch (Plata.ProjectJson.plata_type ?? 'api') {
14
- case 'api':
15
- cli = await (require('++/bin/extras/create-api-cli') as CreateCli.ImportedCreateCli).cli
16
- break
17
- case 'lib':
18
- cli = await (require('++/bin/extras/create-lib-cli') as CreateCli.ImportedCreateCli).cli
19
- break
20
- case 'cluster':
21
- cli = await (require('++/bin/extras/create-cluster-cli') as CreateCli.ImportedCreateCli).cli
22
- break
23
- default:
24
- console.log(`${Plata.ProjectJson.plata_type} not supported`)
25
- process.exit(0)
26
- break
27
- }
28
-
29
- const config = await PlataBuild.getBuildConfig()
30
-
31
- if (config.errorID !== undefined) {
32
- console.log(`⚠️ - Não foi possivel carregar a config - ${config.errorID}`)
33
-
34
- return cli.parseAsync(args)
35
- }
36
-
37
- if (config.plugins?.length) {
38
- for (let i = 0; i < config.plugins.length; i++) {
39
- const plugin = config.plugins[i];
40
-
41
- if (plugin.cliCreate !== undefined) {
42
- cli = await plugin.cliCreate(cli)
43
- }
44
- }
45
-
46
- console.log(`✅ - Plugins carregados`)
47
- }
48
-
49
- return cli.parseAsync(args)
1
+ import { PlataBuild } from "++/libs/build"
2
+ import type { Command } from "commander"
3
+
4
+ export const main = async () => {
5
+ if (Plata.ProjectJson.plata_no_setup !== undefined) {
6
+ console.log('Plata não configurada remova o plata_no_setup do package.json')
7
+ process.exit(0)
8
+ }
9
+
10
+ const args = process.argv.slice(process.argv.indexOf('+'))
11
+ let cli: Command | null = null
12
+
13
+ switch (Plata.ProjectJson.plata_type ?? 'api') {
14
+ case 'api':
15
+ cli = await (require('++/bin/extras/create-api-cli') as CreateCli.ImportedCreateCli).cli
16
+ break
17
+ case 'lib':
18
+ cli = await (require('++/bin/extras/create-lib-cli') as CreateCli.ImportedCreateCli).cli
19
+ break
20
+ case 'cluster':
21
+ cli = await (require('++/bin/extras/create-cluster-cli') as CreateCli.ImportedCreateCli).cli
22
+ break
23
+ default:
24
+ console.log(`${Plata.ProjectJson.plata_type} not supported`)
25
+ process.exit(0)
26
+ break
27
+ }
28
+
29
+ const config = await PlataBuild.getBuildConfig()
30
+
31
+ if (config.errorID !== undefined) {
32
+ console.log(`⚠️ - Não foi possivel carregar a config - ${config.errorID}`)
33
+
34
+ return cli.parseAsync(args)
35
+ }
36
+
37
+ if (config.plugins?.length) {
38
+ for (let i = 0; i < config.plugins.length; i++) {
39
+ const plugin = config.plugins[i];
40
+
41
+ if (plugin.cliCreate !== undefined) {
42
+ cli = await plugin.cliCreate(cli)
43
+ }
44
+ }
45
+
46
+ console.log(`✅ - Plugins carregados`)
47
+ }
48
+
49
+ return cli.parseAsync(args)
50
50
  }
@@ -1,132 +1,132 @@
1
- #!/usr/bin/env node
2
-
3
- import path from 'node:path'
4
- import { ok } from 'node:assert'
5
- import cluster from 'node:cluster'
6
- import { loadRuntimeLibs } from './runtime/_setupRuntime'
7
- import { PlataFs } from '../libs/fs'
8
- import { PlataEnvLoader } from '../libs/env'
9
- import { PlataBuild } from '../libs/build'
10
-
11
- export async function compile() {
12
- if (!cluster.isPrimary) return
13
-
14
- await PlataBuild.compile({
15
- basePath: Plata.ProjectDir,
16
- mapFiles: true,
17
- packageJsonSetup: false,
18
- otimizar: false,
19
- })
20
- // build({
21
- // basePath: Plata.ProjectDir,
22
- // configFilePath: 'tsconfig.json',
23
- // compilerOptions: {
24
- // newLine: 'LF',
25
- // rootDir: '.'
26
- // },
27
- // include: [
28
- // './**/*'
29
- // ],
30
- // exclude: [
31
- // './__BUILD__',
32
- // './__RELEASE__',
33
- // './node_modules',
34
- // './.vscode',
35
- // './.git',
36
- // '.gitignore'
37
- // ],
38
- // copyOtherToOutDir: true,
39
- // clean: {
40
- // outDir: true,
41
- // declarationDir: true,
42
- // outFile: true
43
- // },
44
- // })
45
- }
46
-
47
- const shouldCompile = async () => { // TODO Colocar a compilição e essa função em um arquivo separado
48
- if (process.argv.findIndex(p => p === '--skip-recompile') !== -1 || Plata.ProjectJson['plata_skip_recompile'] !== undefined)
49
- return Plata.files.access(path.join(Plata.ProjectDir, '__BUILD__')).then(r => !r)
50
- ;
51
-
52
- return true
53
- }
54
-
55
- const main = async () => {
56
- const g = global as any
57
-
58
- g.Plata = await loadRuntimeLibs()
59
-
60
- g.Plata.files = PlataFs
61
-
62
- if (await shouldCompile())
63
- await compile()
64
- ;
65
-
66
- module.constructor.prototype.require = function (pathRequire) {
67
- const self = this;
68
- ok(typeof pathRequire === 'string', 'path must be a string');
69
- ok(pathRequire, 'missing path');
70
-
71
- try {
72
- switch (pathRequire.slice(0,2)) {
73
- case '@@':
74
- pathRequire = pathRequire.replace('@@', `${Plata.ProjectDir}/__BUILD__`)
75
- break
76
- case '++':
77
- pathRequire = pathRequire.replace('++', `${Plata.PlataDir}/__BUILD__`)
78
- break
79
- }
80
-
81
- pathRequire = pathRequire.replace(/\\/g, '/')
82
-
83
- switch (path.extname(pathRequire)) {
84
- case '.env':
85
- return Plata.FastPromise(() => Plata.ReadEnvFileToPromise(pathRequire))
86
- break
87
- case '.*':
88
- return Plata.FastPromise(() => Plata.RequireFolder(path.dirname(pathRequire)))
89
- break
90
- default:
91
- return self.constructor._load(pathRequire, self)
92
- break
93
- }
94
-
95
-
96
- } catch (err) {
97
- // if module not found, we have nothing to do, simply throw it back.
98
- if (err.code === 'MODULE_NOT_FOUND') {
99
- throw err;
100
- }
101
- // resolve the path to get absolute path
102
- pathRequire = path.resolve(__dirname, pathRequire)
103
-
104
- // Write to log or whatever
105
- console.log('Error in file: ' + pathRequire);
106
- }
107
- }
108
-
109
- // inicializa a config da plata
110
- g.Plata.config = process.env
111
-
112
- const envFile = await PlataEnvLoader.load()
113
-
114
- if (envFile.errorID !== undefined) {
115
- console.log(envFile)
116
- process.exit(1)
117
- }
118
-
119
- for (const key in envFile) {
120
- g.Plata.config[key] = envFile[key]
121
- }
122
-
123
- // roda o sript solicitado
124
- const run = process.argv[process.argv.indexOf('+') + 1]
125
-
126
- const app: { main: () => Promise<void> } = require(`++/bin/${run}`)
127
-
128
- await app.main()
129
-
130
- }
131
-
1
+ #!/usr/bin/env node
2
+
3
+ import path from 'node:path'
4
+ import { ok } from 'node:assert'
5
+ import cluster from 'node:cluster'
6
+ import { loadRuntimeLibs } from './runtime/_setupRuntime'
7
+ import { PlataFs } from '../libs/fs'
8
+ import { PlataEnvLoader } from '../libs/env'
9
+ import { PlataBuild } from '../libs/build'
10
+
11
+ export async function compile() {
12
+ if (!cluster.isPrimary) return
13
+
14
+ await PlataBuild.compile({
15
+ basePath: Plata.ProjectDir,
16
+ mapFiles: true,
17
+ packageJsonSetup: false,
18
+ otimizar: false,
19
+ })
20
+ // build({
21
+ // basePath: Plata.ProjectDir,
22
+ // configFilePath: 'tsconfig.json',
23
+ // compilerOptions: {
24
+ // newLine: 'LF',
25
+ // rootDir: '.'
26
+ // },
27
+ // include: [
28
+ // './**/*'
29
+ // ],
30
+ // exclude: [
31
+ // './__BUILD__',
32
+ // './__RELEASE__',
33
+ // './node_modules',
34
+ // './.vscode',
35
+ // './.git',
36
+ // '.gitignore'
37
+ // ],
38
+ // copyOtherToOutDir: true,
39
+ // clean: {
40
+ // outDir: true,
41
+ // declarationDir: true,
42
+ // outFile: true
43
+ // },
44
+ // })
45
+ }
46
+
47
+ const shouldCompile = async () => { // TODO Colocar a compilição e essa função em um arquivo separado
48
+ if (process.argv.findIndex(p => p === '--skip-recompile') !== -1 || Plata.ProjectJson['plata_skip_recompile'] !== undefined)
49
+ return Plata.files.access(path.join(Plata.ProjectDir, '__BUILD__')).then(r => !r)
50
+ ;
51
+
52
+ return true
53
+ }
54
+
55
+ const main = async () => {
56
+ const g = global as any
57
+
58
+ g.Plata = await loadRuntimeLibs()
59
+
60
+ g.Plata.files = PlataFs
61
+
62
+ if (await shouldCompile())
63
+ await compile()
64
+ ;
65
+
66
+ module.constructor.prototype.require = function (pathRequire) {
67
+ const self = this;
68
+ ok(typeof pathRequire === 'string', 'path must be a string');
69
+ ok(pathRequire, 'missing path');
70
+
71
+ try {
72
+ switch (pathRequire.slice(0,2)) {
73
+ case '@@':
74
+ pathRequire = pathRequire.replace('@@', `${Plata.ProjectDir}/__BUILD__`)
75
+ break
76
+ case '++':
77
+ pathRequire = pathRequire.replace('++', `${Plata.PlataDir}/__BUILD__`)
78
+ break
79
+ }
80
+
81
+ pathRequire = pathRequire.replace(/\\/g, '/')
82
+
83
+ switch (path.extname(pathRequire)) {
84
+ case '.env':
85
+ return Plata.FastPromise(() => Plata.ReadEnvFileToPromise(pathRequire))
86
+ break
87
+ case '.*':
88
+ return Plata.FastPromise(() => Plata.RequireFolder(path.dirname(pathRequire)))
89
+ break
90
+ default:
91
+ return self.constructor._load(pathRequire, self)
92
+ break
93
+ }
94
+
95
+
96
+ } catch (err) {
97
+ // if module not found, we have nothing to do, simply throw it back.
98
+ if (err.code === 'MODULE_NOT_FOUND') {
99
+ throw err;
100
+ }
101
+ // resolve the path to get absolute path
102
+ pathRequire = path.resolve(__dirname, pathRequire)
103
+
104
+ // Write to log or whatever
105
+ console.log('Error in file: ' + pathRequire);
106
+ }
107
+ }
108
+
109
+ // inicializa a config da plata
110
+ g.Plata.config = process.env
111
+
112
+ const envFile = await PlataEnvLoader.load()
113
+
114
+ if (envFile.errorID !== undefined) {
115
+ console.log(envFile)
116
+ process.exit(1)
117
+ }
118
+
119
+ for (const key in envFile) {
120
+ g.Plata.config[key] = envFile[key]
121
+ }
122
+
123
+ // roda o sript solicitado
124
+ const run = process.argv[process.argv.indexOf('+') + 1]
125
+
126
+ const app: { main: () => Promise<void> } = require(`++/bin/${run}`)
127
+
128
+ await app.main()
129
+
130
+ }
131
+
132
132
  main()