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,114 +1,114 @@
1
- interface RequiredInterface<T> {
2
- filePath: string,
3
- name: string,
4
- exports: T
5
- }
6
-
7
- type RequireAsyncReturn<T> = PlataPromise<RequiredInterface<T>>
8
- type RequireFolderReturn<T> = PlataPromise<RequiredInterface<T>[]>
9
- type RequiredFolder<T> = Awaited<RequireFolderReturn<T>>
10
-
11
- type StringKeyOfObject<T extends Object> = Exclude<{
12
- [name in keyof T]:
13
- name extends string ? name
14
- : name extends number ? `${name}`
15
- : undefined
16
- }[keyof T], undefined>;
17
-
18
- type AnyRecord<T> = {
19
- [P in string]: T;
20
- }
21
- type LooseAutocomplete<T extends string> = T | Omit<string, T>
22
-
23
- type Replace<T, O, U> = T extends O ? Exclude<T, O> | U : T
24
-
25
- type PlataEnvDefaults = "prod" | "homolog" | "debug"
26
- type PlataEnv = LooseAutocomplete<PlataEnvDefaults>
27
-
28
- type PlataFunctionWrapperReturn<F extends (...a: any) => any, T> = (...a: Parameters<F>) => T
29
-
30
- type RemovePlataResult<T> = T extends PlataResult<infer U> ? Exclude<U, PlataError> : T
31
-
32
- type RemovePlataResultOnArray<T> =
33
- T extends [ infer U ] ? [ RemovePlataResult<Awaited<U>> ]
34
- : T extends [ infer U, ...infer V ] ? [ RemovePlataResult<Awaited<U>>, ...RemovePlataResultOnArray<V> ]
35
- : []
36
- //: T extends Promise<infer U>[] ? RemovePlataResult<U>[]
37
- //: never
38
-
39
- ;
40
-
41
- type RemovePlataResultOnPromiseAll<T> =
42
- RemovePlataResultOnArray<T>
43
- // extends [ infer U ] ? RemovePlataResultOnArray<T>
44
- // : T extends Promise<infer U>[] ? 'RemovePlataResult<U>'
45
- // : 'never'
46
- ;
47
-
48
- interface PlataRuntime {}
49
-
50
- interface PlataProcess {
51
-
52
- }
53
-
54
- interface Plata extends PlataRuntime {
55
- cluster: {
56
- isPrimary: true,
57
- clusters: Cluster.ClusterConfig[]
58
- } | { isPrimary: false, clusters?: undefined }
59
- config: NodeJS.ProcessEnv & {
60
- ENV?: PlataEnv
61
- PORT?: string
62
- _PLATA_API_ROOT?: string
63
- _PLATA_API_SSL_KEY?: string
64
- _PLATA_API_SSL_CERT?: string
65
- _PLATA_API_SSL_PASS?: string
66
- _PLATA_API_JSON_SIZE?: string
67
- _PLATA_WORKER_NAME?: string
68
- _PLATA_WORKER_TYPE?: 'WORKER' | 'CONTROLLER'
69
- _PLATA_SQL_CACHETABLE?: string
70
- _PLATA_SQL_CACHETABLETIME?: string
71
- }
72
- }
73
-
74
- declare const Plata: Plata
75
-
76
- declare const process: NodeJS.Process & PlataProcess
77
-
78
- interface EnvConfig {
79
- env: PlataEnv
80
- }
81
-
82
- interface PlataError {
83
- errorID: string
84
- msg: string,
85
- error?: any
86
- }
87
-
88
- type MaybePlataError = null | PlataError
89
-
90
- type PlataResult<T> = (T & { errorID?: undefined }) | PlataError
91
-
92
- type PlataPromise<T> = Promise<PlataResult<T>>
93
-
94
- type Dictionary<T> = {
95
- [key: string]: T
96
- }
97
-
98
- type DictionaryRecord<K extends string | number, T> = {
99
- [key in K]: T
100
- }
101
-
102
- interface PlataEnvConfig {
103
- env: PlataEnv
104
- }
105
-
106
- type DeepWritable<T extends {}> = {
107
- -readonly [K in keyof T]: T[K] extends Dictionary<any> ? DeepWritable<T[K]> : T[K]
108
- }
109
-
110
- type ArrayCombine<T extends readonly any[]> =
111
- T extends readonly [ infer U extends T[number] ] ? U
112
- : T extends readonly [ infer U extends T[number], ...infer R] ? U & ArrayCombine<R>
113
- : never
1
+ interface RequiredInterface<T> {
2
+ filePath: string,
3
+ name: string,
4
+ exports: T
5
+ }
6
+
7
+ type RequireAsyncReturn<T> = PlataPromise<RequiredInterface<T>>
8
+ type RequireFolderReturn<T> = PlataPromise<RequiredInterface<T>[]>
9
+ type RequiredFolder<T> = Awaited<RequireFolderReturn<T>>
10
+
11
+ type StringKeyOfObject<T extends Object> = Exclude<{
12
+ [name in keyof T]:
13
+ name extends string ? name
14
+ : name extends number ? `${name}`
15
+ : undefined
16
+ }[keyof T], undefined>;
17
+
18
+ type AnyRecord<T> = {
19
+ [P in string]: T;
20
+ }
21
+ type LooseAutocomplete<T extends string> = T | Omit<string, T>
22
+
23
+ type Replace<T, O, U> = T extends O ? Exclude<T, O> | U : T
24
+
25
+ type PlataEnvDefaults = "prod" | "homolog" | "debug"
26
+ type PlataEnv = LooseAutocomplete<PlataEnvDefaults>
27
+
28
+ type PlataFunctionWrapperReturn<F extends (...a: any) => any, T> = (...a: Parameters<F>) => T
29
+
30
+ type RemovePlataResult<T> = T extends PlataResult<infer U> ? Exclude<U, PlataError> : T
31
+
32
+ type RemovePlataResultOnArray<T> =
33
+ T extends [ infer U ] ? [ RemovePlataResult<Awaited<U>> ]
34
+ : T extends [ infer U, ...infer V ] ? [ RemovePlataResult<Awaited<U>>, ...RemovePlataResultOnArray<V> ]
35
+ : []
36
+ //: T extends Promise<infer U>[] ? RemovePlataResult<U>[]
37
+ //: never
38
+
39
+ ;
40
+
41
+ type RemovePlataResultOnPromiseAll<T> =
42
+ RemovePlataResultOnArray<T>
43
+ // extends [ infer U ] ? RemovePlataResultOnArray<T>
44
+ // : T extends Promise<infer U>[] ? 'RemovePlataResult<U>'
45
+ // : 'never'
46
+ ;
47
+
48
+ interface PlataRuntime {}
49
+
50
+ interface PlataProcess {
51
+
52
+ }
53
+
54
+ interface Plata extends PlataRuntime {
55
+ cluster: {
56
+ isPrimary: true,
57
+ clusters: Cluster.ClusterConfig[]
58
+ } | { isPrimary: false, clusters?: undefined }
59
+ config: NodeJS.ProcessEnv & {
60
+ ENV?: PlataEnv
61
+ PORT?: string
62
+ _PLATA_API_ROOT?: string
63
+ _PLATA_API_SSL_KEY?: string
64
+ _PLATA_API_SSL_CERT?: string
65
+ _PLATA_API_SSL_PASS?: string
66
+ _PLATA_API_JSON_SIZE?: string
67
+ _PLATA_WORKER_NAME?: string
68
+ _PLATA_WORKER_TYPE?: 'WORKER' | 'CONTROLLER'
69
+ _PLATA_SQL_CACHETABLE?: string
70
+ _PLATA_SQL_CACHETABLETIME?: string
71
+ }
72
+ }
73
+
74
+ declare const Plata: Plata
75
+
76
+ declare const process: NodeJS.Process & PlataProcess
77
+
78
+ interface EnvConfig {
79
+ env: PlataEnv
80
+ }
81
+
82
+ interface PlataError {
83
+ errorID: string
84
+ msg: string,
85
+ error?: any
86
+ }
87
+
88
+ type MaybePlataError = null | PlataError
89
+
90
+ type PlataResult<T> = (T & { errorID?: undefined }) | PlataError
91
+
92
+ type PlataPromise<T> = Promise<PlataResult<T>>
93
+
94
+ type Dictionary<T> = {
95
+ [key: string]: T
96
+ }
97
+
98
+ type DictionaryRecord<K extends string | number, T> = {
99
+ [key in K]: T
100
+ }
101
+
102
+ interface PlataEnvConfig {
103
+ env: PlataEnv
104
+ }
105
+
106
+ type DeepWritable<T extends {}> = {
107
+ -readonly [K in keyof T]: T[K] extends Dictionary<any> ? DeepWritable<T[K]> : T[K]
108
+ }
109
+
110
+ type ArrayCombine<T extends readonly any[]> =
111
+ T extends readonly [ infer U extends T[number] ] ? U
112
+ : T extends readonly [ infer U extends T[number], ...infer R] ? U & ArrayCombine<R>
113
+ : never
114
114
  ;
@@ -1,14 +1,14 @@
1
- import { Knex as KnexOriginal } from 'knex';
2
- import { ModelTemplate } from '++/libs/models'
3
-
4
- declare module 'knex' {
5
- namespace Knex {
6
- interface QueryBuilder {
7
- includeOne<TRecord extends {}, TResult>(table: keyof TRecord, type: Sql.Joins,s: KnexOriginal.JoinCallback): KnexOriginal.QueryBuilder<TRecord, TResult>;
8
- context<TRecord extends {}, TResult>(context: any): KnexOriginal.QueryBuilder<TRecord, TResult>;
9
- context<T>(): T;
10
- getConnTable<TRecord extends {}, TResult>(table: string, trxName?: string): KnexOriginal.QueryBuilder<TRecord, TResult>
11
- comment?: <TRecord extends {}, TResult>(comment: string) => KnexOriginal.QueryBuilder<TRecord, TResult>
12
- }
13
- }
1
+ import { Knex as KnexOriginal } from 'knex';
2
+ import { ModelTemplate } from '++/libs/models'
3
+
4
+ declare module 'knex' {
5
+ namespace Knex {
6
+ interface QueryBuilder {
7
+ includeOne<TRecord extends {}, TResult>(table: keyof TRecord, type: Sql.Joins,s: KnexOriginal.JoinCallback): KnexOriginal.QueryBuilder<TRecord, TResult>;
8
+ context<TRecord extends {}, TResult>(context: any): KnexOriginal.QueryBuilder<TRecord, TResult>;
9
+ context<T>(): T;
10
+ getConnTable<TRecord extends {}, TResult>(table: string, trxName?: string): KnexOriginal.QueryBuilder<TRecord, TResult>
11
+ comment?: <TRecord extends {}, TResult>(comment: string) => KnexOriginal.QueryBuilder<TRecord, TResult>
12
+ }
13
+ }
14
14
  }
@@ -1,144 +1,144 @@
1
- declare namespace Model {
2
-
3
- type ValidateReturn = PlataError | null
4
-
5
- interface PrimitiveValidationTypeReturn {
6
- error?: PlataError
7
- continua: boolean
8
- }
9
-
10
- type PrimitiveValidationTypeFunction<T = any, D = undefined> =
11
- (nome: string, valor: T | D) => Promise<PrimitiveValidationTypeReturn>
12
- ;
13
-
14
-
15
- interface PrimitiveValidationType<T = any, D = undefined> extends PrimitiveValidationTypeFunction<T, D>{
16
- filter?: (value: any) => any
17
- }
18
-
19
- interface Template {
20
- readonly [name: string]:
21
- readonly PrimitiveValidationType<unknown, unknown>[] |
22
- readonly Template[] |
23
- Template |
24
- readonly (readonly PrimitiveValidationType[])[]
25
- }
26
-
27
- interface TemplateEnv {
28
- readonly [name: string]: readonly PrimitiveValidationType<unknown, unknown>[]
29
- }
30
-
31
- type GetTemplateParamType<T> =
32
- T extends readonly [ PrimitiveValidationType<infer G, infer H> ] ? G | H :
33
- T extends readonly [ PrimitiveValidationType<any, infer H>, PrimitiveValidationType<infer G, any> ] ? G | H :
34
- T extends readonly [ PrimitiveValidationType<any, infer H>, ...any[], PrimitiveValidationType<infer G, any> ] ? G | H :
35
- never
36
- ;
37
-
38
- type GetTemplateEnvParamType<const T extends PrimitiveValidationType<unknown, unknown>[]> =
39
- T extends readonly [ PrimitiveValidationType<infer G, infer H> ] ? `${G}` | H :
40
- T extends readonly [ PrimitiveValidationType<any, infer H>, PrimitiveValidationType<infer G, any> ] ? `${G}` | H :
41
- T extends readonly [ PrimitiveValidationType<any, infer H>, ...any[], PrimitiveValidationType<infer G, any> ] ? `${G}` | H :
42
- never
43
- ;
44
-
45
- type ExtractTemplateParamType<T> = Exclude<GetTemplateParamType<T>, undefined>
46
-
47
- type ExtractTemplateEnvParamType<const T> = Replace<Exclude<GetTemplateEnvParamType<T>, undefined>, null, undefined>
48
-
49
- type ExtractTemplateType<T extends Template> = {
50
- [P in keyof T]: T[P] extends Template ? ExtractTemplateType<T[P]> :
51
- T[P] extends readonly Template[] ? ExtractTemplateType<T[P][0]>[] :
52
- T[P] extends readonly (readonly PrimitiveValidationType[])[] ? ExtractTemplateParamType<T[P][0]>[] :
53
- T[P] extends readonly PrimitiveValidationType<unknown, unknown>[] ? ExtractTemplateParamType<T[P]> :
54
- number | boolean | string | null
55
- }
56
-
57
-
58
- type ExtractTemplateEnvType<const T extends TemplateEnv> = {
59
- [P in keyof T]: ExtractTemplateEnvParamType<T[P]>
60
- }
61
-
62
- type ExtractTemplateTypeNotValid<T extends Template> = {
63
- [P in keyof T]: T[P] extends Template ? ExtractTemplateTypeNotValid<T[P]> :
64
- T[P] extends readonly Template[] ? ExtractTemplateTypeNotValid<T[P][0]>[] :
65
- T[P] extends readonly (readonly PrimitiveValidationType[])[] ? (number | boolean | string | null)[] :
66
- number | boolean | string | null
67
- }
68
-
69
- type ParcialTemplateType<T extends Template> = Partial<ExtractTemplateType<T>>
70
-
71
- type ModelTemplateValidation<T extends Template> = (value: ExtractTemplateType<T>) => Promise<PlataError | null>
72
-
73
- type ModelTemplateFilter<T extends Template> = (value: DeepWritable<ExtractTemplateTypeNotValid<T>>) => DeepWritable<ExtractTemplateTypeNotValid<T>>
74
-
75
- type ModelTemplateEnvValidation<const T extends TemplateEnv> = (value: ExtractTemplateEnvType<T>) => Promise<PlataError | null>
76
-
77
- type ModelValidateReturn<T extends Template> =
78
- ModelValidateReturnHelper<ExtractTemplateType<T>, ExtractTemplateTypeNotValid<T>>
79
- ;
80
-
81
- type ModelValidateEnvReturn<const T extends TemplateEnv> =
82
- ModelValidateReturnHelper<ExtractTemplateEnvType<T>, undefined>
83
- ;
84
-
85
- type ModelValidateReturnHelper<const OKAY, const ERROR> =
86
- | {
87
- errors: undefined,
88
- value: OKAY
89
- }
90
- | {
91
- errors: PlataError[]
92
- value: ERROR
93
- }
94
- ;
95
-
96
- type ConvertFunction<T extends Template, O> = (x: ExtractTemplateType<T>) => O
97
-
98
- type Converters<T extends Template> = (AnyRecord<Model.ConvertFunction<T, any>>)
99
-
100
- type GetConverterType<T extends Template, F> = F extends ConvertFunction<T, infer G> ? G : never
101
-
102
- type ModelConvertFuntion<T extends Template, C extends Converters<T>> =
103
- <K extends keyof C>(value: ExtractTemplateType<T>, to: K) => PlataResult<GetConverterType<T, C[K]>>
104
- ;
105
-
106
- interface TemplateUnionConfig {
107
- key: string
108
- }
109
-
110
- interface ModelClass {
111
- readonly type: Record<string | number, any>
112
- filter?: (value: any) => any
113
- validate(value: any, skipFilter?: true): Promise<Model.ModelValidateReturnHelper<any, any>>
114
-
115
- }
116
-
117
- type TemplateRecord =
118
- Record<string | `${number}` | `${boolean}` | 'null', ModelClass>
119
- ;
120
-
121
- type ExtractModelUnionType<const C extends TemplateUnionConfig, const R extends TemplateRecord> = {
122
- [K in keyof R]: Record<C['key'], K> & R[K]['type']
123
- }[keyof R]
124
-
125
- type RemoveTypesForFilter<T extends Record<string, any>> = {
126
- -readonly [K in keyof T]:
127
- T[K] extends Record<string, any> ? RemoveTypesForFilter<T[K]>
128
- : number | boolean | string | null
129
-
130
- }
131
-
132
- type ExtractModelUnionTypeFilter<const C extends TemplateUnionConfig, const R extends TemplateRecord> = {
133
- [K in keyof R]: Record<C['key'], K> & RemoveTypesForFilter<R[K]['type']>
134
- }[keyof R]
135
-
136
- type ExtractModelUnionReturn<const C extends TemplateUnionConfig, const R extends TemplateRecord> =
137
- {
138
- [K in keyof R]: {
139
- model: R[K],
140
- value: R[K]['type'] & Record<C['key'], K>
141
- }
142
- }[keyof R]
143
- ;
1
+ declare namespace Model {
2
+
3
+ type ValidateReturn = PlataError | null
4
+
5
+ interface PrimitiveValidationTypeReturn {
6
+ error?: PlataError
7
+ continua: boolean
8
+ }
9
+
10
+ type PrimitiveValidationTypeFunction<T = any, D = undefined> =
11
+ (nome: string, valor: T | D) => Promise<PrimitiveValidationTypeReturn>
12
+ ;
13
+
14
+
15
+ interface PrimitiveValidationType<T = any, D = undefined> extends PrimitiveValidationTypeFunction<T, D>{
16
+ filter?: (value: any) => any
17
+ }
18
+
19
+ interface Template {
20
+ readonly [name: string]:
21
+ readonly PrimitiveValidationType<unknown, unknown>[] |
22
+ readonly Template[] |
23
+ Template |
24
+ readonly (readonly PrimitiveValidationType[])[]
25
+ }
26
+
27
+ interface TemplateEnv {
28
+ readonly [name: string]: readonly PrimitiveValidationType<unknown, unknown>[]
29
+ }
30
+
31
+ type GetTemplateParamType<T> =
32
+ T extends readonly [ PrimitiveValidationType<infer G, infer H> ] ? G | H :
33
+ T extends readonly [ PrimitiveValidationType<any, infer H>, PrimitiveValidationType<infer G, any> ] ? G | H :
34
+ T extends readonly [ PrimitiveValidationType<any, infer H>, ...any[], PrimitiveValidationType<infer G, any> ] ? G | H :
35
+ never
36
+ ;
37
+
38
+ type GetTemplateEnvParamType<const T extends PrimitiveValidationType<unknown, unknown>[]> =
39
+ T extends readonly [ PrimitiveValidationType<infer G, infer H> ] ? `${G}` | H :
40
+ T extends readonly [ PrimitiveValidationType<any, infer H>, PrimitiveValidationType<infer G, any> ] ? `${G}` | H :
41
+ T extends readonly [ PrimitiveValidationType<any, infer H>, ...any[], PrimitiveValidationType<infer G, any> ] ? `${G}` | H :
42
+ never
43
+ ;
44
+
45
+ type ExtractTemplateParamType<T> = Exclude<GetTemplateParamType<T>, undefined>
46
+
47
+ type ExtractTemplateEnvParamType<const T> = Replace<Exclude<GetTemplateEnvParamType<T>, undefined>, null, undefined>
48
+
49
+ type ExtractTemplateType<T extends Template> = {
50
+ [P in keyof T]: T[P] extends Template ? ExtractTemplateType<T[P]> :
51
+ T[P] extends readonly Template[] ? ExtractTemplateType<T[P][0]>[] :
52
+ T[P] extends readonly (readonly PrimitiveValidationType[])[] ? ExtractTemplateParamType<T[P][0]>[] :
53
+ T[P] extends readonly PrimitiveValidationType<unknown, unknown>[] ? ExtractTemplateParamType<T[P]> :
54
+ number | boolean | string | null
55
+ }
56
+
57
+
58
+ type ExtractTemplateEnvType<const T extends TemplateEnv> = {
59
+ [P in keyof T]: ExtractTemplateEnvParamType<T[P]>
60
+ }
61
+
62
+ type ExtractTemplateTypeNotValid<T extends Template> = {
63
+ [P in keyof T]: T[P] extends Template ? ExtractTemplateTypeNotValid<T[P]> :
64
+ T[P] extends readonly Template[] ? ExtractTemplateTypeNotValid<T[P][0]>[] :
65
+ T[P] extends readonly (readonly PrimitiveValidationType[])[] ? (number | boolean | string | null)[] :
66
+ number | boolean | string | null
67
+ }
68
+
69
+ type ParcialTemplateType<T extends Template> = Partial<ExtractTemplateType<T>>
70
+
71
+ type ModelTemplateValidation<T extends Template> = (value: ExtractTemplateType<T>) => Promise<PlataError | null>
72
+
73
+ type ModelTemplateFilter<T extends Template> = (value: DeepWritable<ExtractTemplateTypeNotValid<T>>) => DeepWritable<ExtractTemplateTypeNotValid<T>>
74
+
75
+ type ModelTemplateEnvValidation<const T extends TemplateEnv> = (value: ExtractTemplateEnvType<T>) => Promise<PlataError | null>
76
+
77
+ type ModelValidateReturn<T extends Template> =
78
+ ModelValidateReturnHelper<ExtractTemplateType<T>, ExtractTemplateTypeNotValid<T>>
79
+ ;
80
+
81
+ type ModelValidateEnvReturn<const T extends TemplateEnv> =
82
+ ModelValidateReturnHelper<ExtractTemplateEnvType<T>, undefined>
83
+ ;
84
+
85
+ type ModelValidateReturnHelper<const OKAY, const ERROR> =
86
+ | {
87
+ errors: undefined,
88
+ value: OKAY
89
+ }
90
+ | {
91
+ errors: PlataError[]
92
+ value: ERROR
93
+ }
94
+ ;
95
+
96
+ type ConvertFunction<T extends Template, O> = (x: ExtractTemplateType<T>) => O
97
+
98
+ type Converters<T extends Template> = (AnyRecord<Model.ConvertFunction<T, any>>)
99
+
100
+ type GetConverterType<T extends Template, F> = F extends ConvertFunction<T, infer G> ? G : never
101
+
102
+ type ModelConvertFuntion<T extends Template, C extends Converters<T>> =
103
+ <K extends keyof C>(value: ExtractTemplateType<T>, to: K) => PlataResult<GetConverterType<T, C[K]>>
104
+ ;
105
+
106
+ interface TemplateUnionConfig {
107
+ key: string
108
+ }
109
+
110
+ interface ModelClass {
111
+ readonly type: Record<string | number, any>
112
+ filter?: (value: any) => any
113
+ validate(value: any, skipFilter?: true): Promise<Model.ModelValidateReturnHelper<any, any>>
114
+
115
+ }
116
+
117
+ type TemplateRecord =
118
+ Record<string | `${number}` | `${boolean}` | 'null', ModelClass>
119
+ ;
120
+
121
+ type ExtractModelUnionType<const C extends TemplateUnionConfig, const R extends TemplateRecord> = {
122
+ [K in keyof R]: Record<C['key'], K> & R[K]['type']
123
+ }[keyof R]
124
+
125
+ type RemoveTypesForFilter<T extends Record<string, any>> = {
126
+ -readonly [K in keyof T]:
127
+ T[K] extends Record<string, any> ? RemoveTypesForFilter<T[K]>
128
+ : number | boolean | string | null
129
+
130
+ }
131
+
132
+ type ExtractModelUnionTypeFilter<const C extends TemplateUnionConfig, const R extends TemplateRecord> = {
133
+ [K in keyof R]: Record<C['key'], K> & RemoveTypesForFilter<R[K]['type']>
134
+ }[keyof R]
135
+
136
+ type ExtractModelUnionReturn<const C extends TemplateUnionConfig, const R extends TemplateRecord> =
137
+ {
138
+ [K in keyof R]: {
139
+ model: R[K],
140
+ value: R[K]['type'] & Record<C['key'], K>
141
+ }
142
+ }[keyof R]
143
+ ;
144
144
  }