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,195 +1,195 @@
1
-
2
- export namespace ModelsInternals {
3
- export function hasValue<T>(value: T | undefined | null): value is T {
4
- if (value === null)
5
- return false
6
- ;
7
-
8
- if (value === undefined)
9
- return false
10
- ;
11
-
12
- return true
13
- }
14
-
15
- export function filterValidation(value: any, validations: Model.PrimitiveValidationType[]) {
16
-
17
- for (let i = 0; i < validations.length; i++) {
18
- const validation = validations[i]
19
-
20
- if (validation.filter !== undefined) {
21
- value = validation.filter(value)
22
- }
23
- }
24
-
25
- return value
26
- }
27
-
28
- export function filterTemplate<Y extends Model.Template>(value: any, template: Y) {
29
- for (const param in template) {
30
- const t = template[param]
31
-
32
- // Objeto => param: { ... }
33
- if (t.length === undefined) {
34
- if (!ModelsInternals.hasValue(value[param])) {
35
- value[param] = Object.create(null)
36
- }
37
-
38
- value[param] = filterTemplate(value[param], t as Model.Template)
39
- continue
40
- }
41
-
42
- // Parametro => param: [ PlataModels.Required() ]
43
- if (typeof t[0] === 'function') {
44
- if (!ModelsInternals.hasValue(value[param])) {
45
- value[param] = null
46
- }
47
-
48
- value[param] = ModelsInternals.filterValidation(value[param], t as Model.PrimitiveValidationType[])
49
-
50
- continue
51
- }
52
-
53
- // Array de valores => param: [[ PlataModels.Required() ]]
54
- if (t[0].length !== undefined) {
55
- if (!ModelsInternals.hasValue(value[param])) {
56
- value[param] = []
57
- }
58
-
59
- if (!Array.isArray(value[param])) {
60
- value[param] = [value[param]]
61
- }
62
-
63
- for (let i = 0; i < value[param].length; i++) {
64
- value[param][i] = ModelsInternals.filterValidation(value[param][i], t[0] as Model.PrimitiveValidationType[])
65
- }
66
-
67
- continue
68
- }
69
-
70
- // Array de Objetos => param: [{ ... }]
71
- if (!ModelsInternals.hasValue(value[param])) {
72
- value[param] = []
73
-
74
- continue
75
- }
76
-
77
- if (!Array.isArray(value[param])) {
78
- if (typeof value[param] !== 'object') {
79
- value[param] = []
80
-
81
- continue
82
- }
83
-
84
- value[param] = [value[param]]
85
- }
86
-
87
- for (let i = 0; i < value[param].length; i++) {
88
- value[param][i] = filterTemplate(value[param][i], t[0])
89
- }
90
- }
91
-
92
- return value as DeepWritable<Model.ExtractTemplateTypeNotValid<typeof template>>
93
- }
94
-
95
- export async function validateTemplateEnv(value: Record<string, string | undefined>, template: Model.TemplateEnv): PlataPromise<PlataError[]> {
96
- const promises: Promise<Model.ValidateReturn>[] = []
97
-
98
- for (const env in template) {
99
- promises.push(Plata.FastPromise(() => validateParameter(
100
- value[env] ?? null,
101
- template[env],
102
- env
103
- )))
104
- }
105
-
106
- return Promise.all(promises).then(
107
- result => result.filter(Boolean).flatMap(r => r) as PlataError[],
108
- err => ({
109
- errorID: 'BPLMINVLTMEN001',
110
- msg: `unexpected error while validating template for env`,
111
- error: err
112
- })
113
- )
114
- }
115
-
116
- export async function validateParameter(value: any, pipeline: readonly Model.PrimitiveValidationType[], name: string): Promise<Model.ValidateReturn> {
117
- for (const validation of pipeline) {
118
- const result = await validation(name, value)
119
-
120
- if (result.error !== undefined) {
121
- return result.error
122
- }
123
-
124
- if (!result.continua) {
125
- break
126
- }
127
- }
128
-
129
- return null
130
- }
131
-
132
- export async function validateTemplate<Y extends Model.Template>(value: any, template: Y, name?: string): PlataPromise<PlataError[]> {
133
- const promises: any[] = []
134
- for (const param in template) {
135
- const t = template[param]
136
-
137
- if (t.length === undefined) {
138
- promises.push(Plata.FastPromise(() => validateTemplate(
139
- value[param],
140
- t as Model.Template,
141
- `${name ?? ''}${param}.`
142
- )))
143
-
144
- continue
145
- }
146
-
147
- if (typeof t[0] === 'function') {
148
- promises.push(
149
- Plata.FastPromise(() => validateParameter(
150
- value[param],
151
- t as Model.PrimitiveValidationType[],
152
- `${name ?? ''}${param}`
153
- ))
154
- )
155
-
156
- continue
157
- }
158
-
159
- if (t[0].length !== undefined) {
160
- for (let i = 0; i < value[param].length; i++) {
161
- promises.push(
162
- Plata.FastPromise(() => validateParameter(
163
- value[param][i],
164
- t[0],
165
- `${name ?? ''}${param}[${i}]`
166
- ))
167
- )
168
- }
169
-
170
- continue
171
- }
172
-
173
- for (let i = 0; i < value[param].length; i++) {
174
- promises.push(
175
- Plata.FastPromise(() => validateTemplate(
176
- value[param][i],
177
- t[0],
178
- `${name ?? ''}${param}[${i}].`
179
- ))
180
- )
181
- }
182
- }
183
-
184
- return Promise.all(promises).then(
185
- result => [].concat(...result).filter(v => v !== null),
186
- err => {
187
- return {
188
- errorID: 'BPLM0001',
189
- msg: `unexpected error while validating template (${name})`,
190
- error: err
191
- }
192
- }
193
- )
194
- }
1
+
2
+ export namespace ModelsInternals {
3
+ export function hasValue<T>(value: T | undefined | null): value is T {
4
+ if (value === null)
5
+ return false
6
+ ;
7
+
8
+ if (value === undefined)
9
+ return false
10
+ ;
11
+
12
+ return true
13
+ }
14
+
15
+ export function filterValidation(value: any, validations: Model.PrimitiveValidationType[]) {
16
+
17
+ for (let i = 0; i < validations.length; i++) {
18
+ const validation = validations[i]
19
+
20
+ if (validation.filter !== undefined) {
21
+ value = validation.filter(value)
22
+ }
23
+ }
24
+
25
+ return value
26
+ }
27
+
28
+ export function filterTemplate<Y extends Model.Template>(value: any, template: Y) {
29
+ for (const param in template) {
30
+ const t = template[param]
31
+
32
+ // Objeto => param: { ... }
33
+ if (t.length === undefined) {
34
+ if (!ModelsInternals.hasValue(value[param])) {
35
+ value[param] = Object.create(null)
36
+ }
37
+
38
+ value[param] = filterTemplate(value[param], t as Model.Template)
39
+ continue
40
+ }
41
+
42
+ // Parametro => param: [ PlataModels.Required() ]
43
+ if (typeof t[0] === 'function') {
44
+ if (!ModelsInternals.hasValue(value[param])) {
45
+ value[param] = null
46
+ }
47
+
48
+ value[param] = ModelsInternals.filterValidation(value[param], t as Model.PrimitiveValidationType[])
49
+
50
+ continue
51
+ }
52
+
53
+ // Array de valores => param: [[ PlataModels.Required() ]]
54
+ if (t[0].length !== undefined) {
55
+ if (!ModelsInternals.hasValue(value[param])) {
56
+ value[param] = []
57
+ }
58
+
59
+ if (!Array.isArray(value[param])) {
60
+ value[param] = [value[param]]
61
+ }
62
+
63
+ for (let i = 0; i < value[param].length; i++) {
64
+ value[param][i] = ModelsInternals.filterValidation(value[param][i], t[0] as Model.PrimitiveValidationType[])
65
+ }
66
+
67
+ continue
68
+ }
69
+
70
+ // Array de Objetos => param: [{ ... }]
71
+ if (!ModelsInternals.hasValue(value[param])) {
72
+ value[param] = []
73
+
74
+ continue
75
+ }
76
+
77
+ if (!Array.isArray(value[param])) {
78
+ if (typeof value[param] !== 'object') {
79
+ value[param] = []
80
+
81
+ continue
82
+ }
83
+
84
+ value[param] = [value[param]]
85
+ }
86
+
87
+ for (let i = 0; i < value[param].length; i++) {
88
+ value[param][i] = filterTemplate(value[param][i], t[0])
89
+ }
90
+ }
91
+
92
+ return value as DeepWritable<Model.ExtractTemplateTypeNotValid<typeof template>>
93
+ }
94
+
95
+ export async function validateTemplateEnv(value: Record<string, string | undefined>, template: Model.TemplateEnv): PlataPromise<PlataError[]> {
96
+ const promises: Promise<Model.ValidateReturn>[] = []
97
+
98
+ for (const env in template) {
99
+ promises.push(Plata.FastPromise(() => validateParameter(
100
+ value[env] ?? null,
101
+ template[env],
102
+ env
103
+ )))
104
+ }
105
+
106
+ return Promise.all(promises).then(
107
+ result => result.filter(Boolean).flatMap(r => r) as PlataError[],
108
+ err => ({
109
+ errorID: 'BPLMINVLTMEN001',
110
+ msg: `unexpected error while validating template for env`,
111
+ error: err
112
+ })
113
+ )
114
+ }
115
+
116
+ export async function validateParameter(value: any, pipeline: readonly Model.PrimitiveValidationType[], name: string): Promise<Model.ValidateReturn> {
117
+ for (const validation of pipeline) {
118
+ const result = await validation(name, value)
119
+
120
+ if (result.error !== undefined) {
121
+ return result.error
122
+ }
123
+
124
+ if (!result.continua) {
125
+ break
126
+ }
127
+ }
128
+
129
+ return null
130
+ }
131
+
132
+ export async function validateTemplate<Y extends Model.Template>(value: any, template: Y, name?: string): PlataPromise<PlataError[]> {
133
+ const promises: any[] = []
134
+ for (const param in template) {
135
+ const t = template[param]
136
+
137
+ if (t.length === undefined) {
138
+ promises.push(Plata.FastPromise(() => validateTemplate(
139
+ value[param],
140
+ t as Model.Template,
141
+ `${name ?? ''}${param}.`
142
+ )))
143
+
144
+ continue
145
+ }
146
+
147
+ if (typeof t[0] === 'function') {
148
+ promises.push(
149
+ Plata.FastPromise(() => validateParameter(
150
+ value[param],
151
+ t as Model.PrimitiveValidationType[],
152
+ `${name ?? ''}${param}`
153
+ ))
154
+ )
155
+
156
+ continue
157
+ }
158
+
159
+ if (t[0].length !== undefined) {
160
+ for (let i = 0; i < value[param].length; i++) {
161
+ promises.push(
162
+ Plata.FastPromise(() => validateParameter(
163
+ value[param][i],
164
+ t[0],
165
+ `${name ?? ''}${param}[${i}]`
166
+ ))
167
+ )
168
+ }
169
+
170
+ continue
171
+ }
172
+
173
+ for (let i = 0; i < value[param].length; i++) {
174
+ promises.push(
175
+ Plata.FastPromise(() => validateTemplate(
176
+ value[param][i],
177
+ t[0],
178
+ `${name ?? ''}${param}[${i}].`
179
+ ))
180
+ )
181
+ }
182
+ }
183
+
184
+ return Promise.all(promises).then(
185
+ result => [].concat(...result).filter(v => v !== null),
186
+ err => {
187
+ return {
188
+ errorID: 'BPLM0001',
189
+ msg: `unexpected error while validating template (${name})`,
190
+ error: err
191
+ }
192
+ }
193
+ )
194
+ }
195
195
  }