@palmares/schemas 0.0.1

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 (219) hide show
  1. package/.turbo/turbo-build$colon$watch.log +424 -0
  2. package/.turbo/turbo-build.log +13 -0
  3. package/.turbo/turbo-build:watch.log +26 -0
  4. package/CHANGELOG.md +11 -0
  5. package/LICENSE +21 -0
  6. package/dist/cjs/src/adapter/fields/array.js +157 -0
  7. package/dist/cjs/src/adapter/fields/boolean.js +167 -0
  8. package/dist/cjs/src/adapter/fields/datetime.js +167 -0
  9. package/dist/cjs/src/adapter/fields/index.js +311 -0
  10. package/dist/cjs/src/adapter/fields/number.js +167 -0
  11. package/dist/cjs/src/adapter/fields/object.js +167 -0
  12. package/dist/cjs/src/adapter/fields/string.js +167 -0
  13. package/dist/cjs/src/adapter/fields/union.js +167 -0
  14. package/dist/cjs/src/adapter/index.js +198 -0
  15. package/dist/cjs/src/adapter/types.js +4 -0
  16. package/dist/cjs/src/compile.js +262 -0
  17. package/dist/cjs/src/conf.js +27 -0
  18. package/dist/cjs/src/constants.js +42 -0
  19. package/dist/cjs/src/domain.js +12 -0
  20. package/dist/cjs/src/exceptions.js +168 -0
  21. package/dist/cjs/src/index.js +365 -0
  22. package/dist/cjs/src/model.js +628 -0
  23. package/dist/cjs/src/parsers/convert-from-number.js +20 -0
  24. package/dist/cjs/src/parsers/convert-from-string.js +24 -0
  25. package/dist/cjs/src/parsers/index.js +25 -0
  26. package/dist/cjs/src/schema/array.js +890 -0
  27. package/dist/cjs/src/schema/boolean.js +826 -0
  28. package/dist/cjs/src/schema/datetime.js +778 -0
  29. package/dist/cjs/src/schema/index.js +17 -0
  30. package/dist/cjs/src/schema/number.js +960 -0
  31. package/dist/cjs/src/schema/object.js +999 -0
  32. package/dist/cjs/src/schema/schema.js +1788 -0
  33. package/dist/cjs/src/schema/string.js +948 -0
  34. package/dist/cjs/src/schema/types.js +4 -0
  35. package/dist/cjs/src/schema/union.js +952 -0
  36. package/dist/cjs/src/types.js +4 -0
  37. package/dist/cjs/src/utils.js +627 -0
  38. package/dist/cjs/src/validators/array.js +457 -0
  39. package/dist/cjs/src/validators/boolean.js +199 -0
  40. package/dist/cjs/src/validators/datetime.js +287 -0
  41. package/dist/cjs/src/validators/number.js +403 -0
  42. package/dist/cjs/src/validators/object.js +290 -0
  43. package/dist/cjs/src/validators/schema.js +318 -0
  44. package/dist/cjs/src/validators/string.js +439 -0
  45. package/dist/cjs/src/validators/types.js +4 -0
  46. package/dist/cjs/src/validators/union.js +232 -0
  47. package/dist/cjs/src/validators/utils.js +426 -0
  48. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -0
  49. package/dist/cjs/types/adapter/fields/array.d.ts +20 -0
  50. package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -0
  51. package/dist/cjs/types/adapter/fields/boolean.d.ts +25 -0
  52. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -0
  53. package/dist/cjs/types/adapter/fields/datetime.d.ts +25 -0
  54. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -0
  55. package/dist/cjs/types/adapter/fields/index.d.ts +31 -0
  56. package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -0
  57. package/dist/cjs/types/adapter/fields/number.d.ts +25 -0
  58. package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -0
  59. package/dist/cjs/types/adapter/fields/object.d.ts +25 -0
  60. package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -0
  61. package/dist/cjs/types/adapter/fields/string.d.ts +25 -0
  62. package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -0
  63. package/dist/cjs/types/adapter/fields/union.d.ts +25 -0
  64. package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -0
  65. package/dist/cjs/types/adapter/index.d.ts +25 -0
  66. package/dist/cjs/types/adapter/index.d.ts.map +1 -0
  67. package/dist/cjs/types/adapter/types.d.ts +144 -0
  68. package/dist/cjs/types/adapter/types.d.ts.map +1 -0
  69. package/dist/cjs/types/compile.d.ts +3 -0
  70. package/dist/cjs/types/compile.d.ts.map +1 -0
  71. package/dist/cjs/types/conf.d.ts +16 -0
  72. package/dist/cjs/types/conf.d.ts.map +1 -0
  73. package/dist/cjs/types/constants.d.ts +6 -0
  74. package/dist/cjs/types/constants.d.ts.map +1 -0
  75. package/dist/cjs/types/domain.d.ts +21 -0
  76. package/dist/cjs/types/domain.d.ts.map +1 -0
  77. package/dist/cjs/types/exceptions.d.ts +13 -0
  78. package/dist/cjs/types/exceptions.d.ts.map +1 -0
  79. package/dist/cjs/types/index.d.ts +240 -0
  80. package/dist/cjs/types/index.d.ts.map +1 -0
  81. package/dist/cjs/types/model.d.ts +136 -0
  82. package/dist/cjs/types/model.d.ts.map +1 -0
  83. package/dist/cjs/types/parsers/convert-from-number.d.ts +15 -0
  84. package/dist/cjs/types/parsers/convert-from-number.d.ts.map +1 -0
  85. package/dist/cjs/types/parsers/convert-from-string.d.ts +9 -0
  86. package/dist/cjs/types/parsers/convert-from-string.d.ts.map +1 -0
  87. package/dist/cjs/types/parsers/index.d.ts +3 -0
  88. package/dist/cjs/types/parsers/index.d.ts.map +1 -0
  89. package/dist/cjs/types/schema/array.d.ts +429 -0
  90. package/dist/cjs/types/schema/array.d.ts.map +1 -0
  91. package/dist/cjs/types/schema/boolean.d.ts +501 -0
  92. package/dist/cjs/types/schema/boolean.d.ts.map +1 -0
  93. package/dist/cjs/types/schema/datetime.d.ts +474 -0
  94. package/dist/cjs/types/schema/datetime.d.ts.map +1 -0
  95. package/dist/cjs/types/schema/index.d.ts +4 -0
  96. package/dist/cjs/types/schema/index.d.ts.map +1 -0
  97. package/dist/cjs/types/schema/number.d.ts +667 -0
  98. package/dist/cjs/types/schema/number.d.ts.map +1 -0
  99. package/dist/cjs/types/schema/object.d.ts +450 -0
  100. package/dist/cjs/types/schema/object.d.ts.map +1 -0
  101. package/dist/cjs/types/schema/schema.d.ts +646 -0
  102. package/dist/cjs/types/schema/schema.d.ts.map +1 -0
  103. package/dist/cjs/types/schema/string.d.ts +606 -0
  104. package/dist/cjs/types/schema/string.d.ts.map +1 -0
  105. package/dist/cjs/types/schema/types.d.ts +70 -0
  106. package/dist/cjs/types/schema/types.d.ts.map +1 -0
  107. package/dist/cjs/types/schema/union.d.ts +388 -0
  108. package/dist/cjs/types/schema/union.d.ts.map +1 -0
  109. package/dist/cjs/types/types.d.ts +11 -0
  110. package/dist/cjs/types/types.d.ts.map +1 -0
  111. package/dist/cjs/types/utils.d.ts +79 -0
  112. package/dist/cjs/types/utils.d.ts.map +1 -0
  113. package/dist/cjs/types/validators/array.d.ts +8 -0
  114. package/dist/cjs/types/validators/array.d.ts.map +1 -0
  115. package/dist/cjs/types/validators/boolean.d.ts +4 -0
  116. package/dist/cjs/types/validators/boolean.d.ts.map +1 -0
  117. package/dist/cjs/types/validators/datetime.d.ts +7 -0
  118. package/dist/cjs/types/validators/datetime.d.ts.map +1 -0
  119. package/dist/cjs/types/validators/number.d.ts +10 -0
  120. package/dist/cjs/types/validators/number.d.ts.map +1 -0
  121. package/dist/cjs/types/validators/object.d.ts +6 -0
  122. package/dist/cjs/types/validators/object.d.ts.map +1 -0
  123. package/dist/cjs/types/validators/schema.d.ts +10 -0
  124. package/dist/cjs/types/validators/schema.d.ts.map +1 -0
  125. package/dist/cjs/types/validators/string.d.ts +12 -0
  126. package/dist/cjs/types/validators/string.d.ts.map +1 -0
  127. package/dist/cjs/types/validators/types.d.ts +2 -0
  128. package/dist/cjs/types/validators/types.d.ts.map +1 -0
  129. package/dist/cjs/types/validators/union.d.ts +4 -0
  130. package/dist/cjs/types/validators/union.d.ts.map +1 -0
  131. package/dist/cjs/types/validators/utils.d.ts +83 -0
  132. package/dist/cjs/types/validators/utils.d.ts.map +1 -0
  133. package/dist/esm/src/adapter/fields/array.js +13 -0
  134. package/dist/esm/src/adapter/fields/boolean.js +20 -0
  135. package/dist/esm/src/adapter/fields/datetime.js +20 -0
  136. package/dist/esm/src/adapter/fields/index.js +37 -0
  137. package/dist/esm/src/adapter/fields/number.js +20 -0
  138. package/dist/esm/src/adapter/fields/object.js +20 -0
  139. package/dist/esm/src/adapter/fields/string.js +20 -0
  140. package/dist/esm/src/adapter/fields/union.js +20 -0
  141. package/dist/esm/src/adapter/index.js +18 -0
  142. package/dist/esm/src/adapter/types.js +1 -0
  143. package/dist/esm/src/compile.js +10 -0
  144. package/dist/esm/src/conf.js +19 -0
  145. package/dist/esm/src/constants.js +5 -0
  146. package/dist/esm/src/domain.js +2 -0
  147. package/dist/esm/src/exceptions.js +15 -0
  148. package/dist/esm/src/index.js +160 -0
  149. package/dist/esm/src/model.js +255 -0
  150. package/dist/esm/src/parsers/convert-from-number.js +8 -0
  151. package/dist/esm/src/parsers/convert-from-string.js +14 -0
  152. package/dist/esm/src/parsers/index.js +2 -0
  153. package/dist/esm/src/schema/array.js +403 -0
  154. package/dist/esm/src/schema/boolean.js +465 -0
  155. package/dist/esm/src/schema/datetime.js +423 -0
  156. package/dist/esm/src/schema/index.js +3 -0
  157. package/dist/esm/src/schema/number.js +592 -0
  158. package/dist/esm/src/schema/object.js +464 -0
  159. package/dist/esm/src/schema/schema.js +728 -0
  160. package/dist/esm/src/schema/string.js +579 -0
  161. package/dist/esm/src/schema/types.js +1 -0
  162. package/dist/esm/src/schema/union.js +388 -0
  163. package/dist/esm/src/types.js +1 -0
  164. package/dist/esm/src/utils.js +175 -0
  165. package/dist/esm/src/validators/array.js +135 -0
  166. package/dist/esm/src/validators/boolean.js +35 -0
  167. package/dist/esm/src/validators/datetime.js +85 -0
  168. package/dist/esm/src/validators/number.js +162 -0
  169. package/dist/esm/src/validators/object.js +38 -0
  170. package/dist/esm/src/validators/schema.js +114 -0
  171. package/dist/esm/src/validators/string.js +174 -0
  172. package/dist/esm/src/validators/types.js +1 -0
  173. package/dist/esm/src/validators/union.js +38 -0
  174. package/dist/esm/src/validators/utils.js +120 -0
  175. package/package.json +48 -0
  176. package/src/adapter/fields/array.ts +31 -0
  177. package/src/adapter/fields/boolean.ts +48 -0
  178. package/src/adapter/fields/datetime.ts +49 -0
  179. package/src/adapter/fields/index.ts +72 -0
  180. package/src/adapter/fields/number.ts +49 -0
  181. package/src/adapter/fields/object.ts +49 -0
  182. package/src/adapter/fields/string.ts +49 -0
  183. package/src/adapter/fields/union.ts +49 -0
  184. package/src/adapter/index.ts +34 -0
  185. package/src/adapter/types.ts +261 -0
  186. package/src/compile.ts +14 -0
  187. package/src/conf.ts +27 -0
  188. package/src/constants.ts +9 -0
  189. package/src/domain.ts +3 -0
  190. package/src/exceptions.ts +17 -0
  191. package/src/index.ts +338 -0
  192. package/src/model.ts +501 -0
  193. package/src/parsers/convert-from-number.ts +13 -0
  194. package/src/parsers/convert-from-string.ts +19 -0
  195. package/src/parsers/index.ts +2 -0
  196. package/src/schema/array.ts +633 -0
  197. package/src/schema/boolean.ts +700 -0
  198. package/src/schema/datetime.ts +613 -0
  199. package/src/schema/index.ts +5 -0
  200. package/src/schema/number.ts +885 -0
  201. package/src/schema/object.ts +699 -0
  202. package/src/schema/schema.ts +1093 -0
  203. package/src/schema/string.ts +807 -0
  204. package/src/schema/types.ts +126 -0
  205. package/src/schema/union.ts +596 -0
  206. package/src/types.ts +13 -0
  207. package/src/utils.ts +322 -0
  208. package/src/validators/array.ts +164 -0
  209. package/src/validators/boolean.ts +46 -0
  210. package/src/validators/datetime.ts +113 -0
  211. package/src/validators/number.ts +188 -0
  212. package/src/validators/object.ts +55 -0
  213. package/src/validators/schema.ts +134 -0
  214. package/src/validators/string.ts +215 -0
  215. package/src/validators/types.ts +1 -0
  216. package/src/validators/union.ts +52 -0
  217. package/src/validators/utils.ts +200 -0
  218. package/tsconfig.json +9 -0
  219. package/tsconfig.types.json +10 -0
package/src/index.ts ADDED
@@ -0,0 +1,338 @@
1
+ import SchemaAdapter from './adapter';
2
+ import { modelSchema } from './model';
3
+ import ArraySchema, { array } from './schema/array';
4
+ import BooleanSchema, { boolean } from './schema/boolean';
5
+ import DatetimeSchema, { datetime } from './schema/datetime';
6
+ import NumberSchema, { number } from './schema/number';
7
+ import ObjectSchema, { object } from './schema/object';
8
+ import Schema, { schema } from './schema/schema';
9
+ import StringSchema, { string } from './schema/string';
10
+ import UnionSchema, { union } from './schema/union';
11
+
12
+ import type { DefinitionsOfSchemaType, ExtractTypeFromObjectOfSchemas } from "./schema/types";
13
+ import type { Narrow } from '@palmares/core';
14
+ import type {
15
+ Model,
16
+ ModelFields} from "@palmares/databases";
17
+
18
+ export { default as default } from './domain';
19
+ export { default as FieldAdapter } from './adapter/fields';
20
+ export { default as NumberAdapter } from './adapter/fields/number';
21
+ export { default as ObjectFieldAdapter } from './adapter/fields/object';
22
+ export { default as UnionFieldAdapter } from './adapter/fields/union';
23
+ export { default as StringFieldAdapter } from './adapter/fields/string';
24
+ export { default as ArrayFieldAdapter } from './adapter/fields/array';
25
+ export { default as BooleanFieldAdapter } from './adapter/fields/boolean';
26
+ export { default as DatetimeFieldAdapter } from './adapter/fields/datetime';
27
+
28
+ export { setDefaultAdapter } from './conf';
29
+ export * from './adapter/types';
30
+ export * from './schema';
31
+ export {
32
+ SchemaAdapter,
33
+ NumberSchema,
34
+ ObjectSchema,
35
+ UnionSchema,
36
+ StringSchema,
37
+ ArraySchema,
38
+ BooleanSchema,
39
+ DatetimeSchema,
40
+ Schema,
41
+ };
42
+ export { schema, number, object, union, string, array, datetime, boolean };
43
+ export { default as compile } from './compile';
44
+
45
+ export { modelSchema };
46
+
47
+ export function getSchemasWithDefaultAdapter<TAdapter extends SchemaAdapter>() {
48
+ return {
49
+ number: () => NumberSchema.new<{ schemaAdapter: TAdapter; schemaType: 'number'; hasSave: false }>(),
50
+ string: () => StringSchema.new<{ schemaAdapter: TAdapter; schemaType: 'string'; hasSave: false }>(),
51
+ array: <TSchemas extends readonly [Schema, ...Schema[]] | [Schema[]]>(...schemas: TSchemas) =>
52
+ array<TSchemas, { schemaAdapter: TAdapter; schemaType: 'array'; hasSave: false }>(...schemas),
53
+ boolean: () => BooleanSchema.new<{ schemaAdapter: TAdapter; schemaType: 'boolean'; hasSave: false }>(),
54
+ object: <TData extends Record<any, Schema<any, any>>>(data: TData) =>
55
+ ObjectSchema.new<TData, { schemaAdapter: TAdapter; schemaType: 'object'; hasSave: false }>(data),
56
+ union: <TSchemas extends readonly [Schema<any, any>, Schema<any, any>, ...Schema<any, any>[]]>(
57
+ ...schemas: Narrow<TSchemas>
58
+ ) => UnionSchema.new<TSchemas, { schemaAdapter: TAdapter; schemaType: 'union'; hasSave: false }>(schemas),
59
+ datetime: () => DatetimeSchema.new<{ schemaAdapter: TAdapter; schemaType: 'datetime'; hasSave: false }>(),
60
+ /**
61
+ * Different from other models, this function is a factory function that returns either an ObjectSchema or an ArraySchema.
62
+ * The idea is to build the schema of a model dynamically based on its fields.
63
+ *
64
+ * Another feature is that it can automatically add the foreign key relation to the schema, but for that you need to define
65
+ * the fields of the related model in the fields object.
66
+ *
67
+ * For example: A User model have a field `companyId` that is a ForeignKeyField to the Company model. The `relationName`
68
+ * is the direct relation from the User model to the Company model, and the `relatedName` is the reverse relation from the
69
+ * Company model to the User model. If you define the fieldName as either the relatedName or the relationName it will fetch
70
+ * the data automatically.
71
+ *
72
+ * **Important**: We build the schema dynamically but also lazily, if you don't try to parse or validate the schema, it won't be built.
73
+ * After the first time it's built, it's cached and never built again.
74
+ *
75
+ * **Important 2**: If you want to use the automatic relation feature, you need to define guarantee that the foreignKey field fieldName
76
+ * exists on `show` array, or that it doesn't exist on `omit` array.
77
+ *
78
+ * Like: `{ options: { show: ['id', 'name', 'companyId'] }}` or `{ options: { omit: ['id'] }}` it **will work**.
79
+ *
80
+ * If you do `{ options: { show: ['id', 'name'] }}` or `{ options: { omit: ['companyId']} }` it **won't work**.
81
+ *
82
+ * **Important 3**: If you want to return an array instead of an object, you need to pass the `many` option as true.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { auto, choice, foreignKey, Model, define } from '@palmares/databases';
87
+ * import * as p from '@palmares/schemas';
88
+ *
89
+ * const Company = define('Company', {
90
+ * fields: {
91
+ * id: auto(),
92
+ * name: text(),
93
+ * },
94
+ * options: {
95
+ * tableName: 'company',
96
+ * }
97
+ * });
98
+ *
99
+ * class User extends Model<User>() {
100
+ * fields = {
101
+ * id: auto(),
102
+ * type: choice({ choices: ['user', 'admin'] }),
103
+ * companyId: foreignKey({
104
+ * relatedTo: Company,
105
+ * relationName: 'company',
106
+ * relatedName: 'usersOfCompany',
107
+ * toField: 'id',
108
+ * onDelete: 'CASCADE',
109
+ * }),
110
+ * }
111
+ *
112
+ * options = {
113
+ * tableName: 'user',
114
+ * }
115
+ * }
116
+ *
117
+ * const userSchema = p.modelSchema(User, {
118
+ * fields: {
119
+ * company: p.modelSchema(Company).optional({ outputOnly: true });
120
+ * },
121
+ * show: ['type', 'companyId']
122
+ * });
123
+ *
124
+ * const companySchema = p.modelSchema(Company, {
125
+ * fields: {
126
+ * usersOfCompany: p.modelSchema(User, { many: true }).optional({ outputOnly: true });
127
+ * },
128
+ * show: ['id', 'type']
129
+ * });
130
+ *```
131
+ * @param model - The model that you want to build the schema from.
132
+ * @param options - The options to build the schema.
133
+ * @param options.ignoreExtraneousFields - If you want to ignore extraneous fields set this to true.
134
+ * @param options.engineInstance - What engine instance you want to use to fetch the data. Defaults to the first one.
135
+ * @param options.fields - Extra fields that you want to add to the schema. If it has the same name as the model field,
136
+ * We will not create a schema for that field and use the one you have defined here.
137
+ * @param options.omit - Fields that you want to omit from the schema. If that is defined, we ignore `show` option.
138
+ * @param options.show - Fields that you want to show on the schema. If that is defined, we ignore `omit` option.
139
+ * @param options.many - If you want to return an array instead of an object, set this to true. With that we create
140
+ * an ArraySchema instead of an ObjectSchema.
141
+ *
142
+ * @returns - If you pass the `many` option as true, we return an ArraySchema, otherwise we return an ObjectSchema.
143
+ */
144
+ modelSchema: <
145
+ TModel extends ReturnType<typeof Model>,
146
+ const TOmit extends readonly (keyof ModelFields<InstanceType<TModel>>)[] | undefined[] = undefined[],
147
+ const TShow extends readonly (keyof ModelFields<InstanceType<TModel>>)[] | undefined[] = undefined[],
148
+ TMany extends boolean = false,
149
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> | undefined = undefined,
150
+ TAllModelFields = ModelFields<InstanceType<TModel>>,
151
+ TFieldsOnModel = TOmit extends undefined[]
152
+ ? TShow extends undefined[]
153
+ ? TAllModelFields
154
+ : Pick<
155
+ TAllModelFields,
156
+ TShow[number] extends keyof TAllModelFields ? TShow[number] : never
157
+ >
158
+ : Omit<
159
+ TAllModelFields,
160
+ TOmit[number] extends keyof TAllModelFields ? TOmit[number] : never
161
+ >,
162
+ TReturnType extends {
163
+ input: any;
164
+ output: any;
165
+ validate: any,
166
+ internal: any;
167
+ representation: any;
168
+ } = {
169
+ input: TFields extends undefined ? TFieldsOnModel :
170
+ Omit<
171
+ TFieldsOnModel,
172
+ keyof ExtractTypeFromObjectOfSchemas<
173
+ // eslint-disable-next-line ts/ban-types
174
+ TFields extends undefined ? {} : TFields,
175
+ 'input'
176
+ >
177
+ > &
178
+ ExtractTypeFromObjectOfSchemas<
179
+ // eslint-disable-next-line ts/ban-types
180
+ TFields extends undefined ? {} : TFields,
181
+ 'input'
182
+ >
183
+ output: TFields extends undefined ? TFieldsOnModel :
184
+ (Omit<
185
+ TFieldsOnModel,
186
+ keyof ExtractTypeFromObjectOfSchemas<
187
+ // eslint-disable-next-line ts/ban-types
188
+ TFields extends undefined ? {} : TFields,
189
+ 'output'
190
+ >
191
+ > &
192
+ ExtractTypeFromObjectOfSchemas<
193
+ // eslint-disable-next-line ts/ban-types
194
+ TFields extends undefined ? {} : TFields,
195
+ 'output'
196
+ >);
197
+ internal: TFields extends undefined ? TFieldsOnModel :
198
+ (Omit<
199
+ TFieldsOnModel,
200
+ keyof ExtractTypeFromObjectOfSchemas<
201
+ // eslint-disable-next-line ts/ban-types
202
+ TFields extends undefined ? {} : TFields,
203
+ 'internal'
204
+ >
205
+ > &
206
+ ExtractTypeFromObjectOfSchemas<
207
+ // eslint-disable-next-line ts/ban-types
208
+ TFields extends undefined ? {} : TFields,
209
+ 'internal'
210
+ >);
211
+ representation: TFields extends undefined ? TFieldsOnModel :
212
+ (Omit<
213
+ TFieldsOnModel,
214
+ keyof ExtractTypeFromObjectOfSchemas<
215
+ // eslint-disable-next-line ts/ban-types
216
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
217
+ 'representation'
218
+ >
219
+ > &
220
+ ExtractTypeFromObjectOfSchemas<
221
+ // eslint-disable-next-line ts/ban-types
222
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
223
+ 'representation'
224
+ >);
225
+ validate: TFields extends undefined ? TFieldsOnModel :
226
+ Omit<
227
+ TFieldsOnModel,
228
+ keyof ExtractTypeFromObjectOfSchemas<
229
+ // eslint-disable-next-line ts/ban-types
230
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
231
+ 'validate'
232
+ >
233
+ > &
234
+ ExtractTypeFromObjectOfSchemas<
235
+ // eslint-disable-next-line ts/ban-types
236
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
237
+ 'validate'
238
+ >;
239
+ }
240
+ >(
241
+ model: TModel,
242
+ options?: {
243
+ ignoreExtraneousFields?: boolean;
244
+ engineInstance?: string;
245
+ fields?: TFields;
246
+ omit?: TOmit;
247
+ omitRelation?: readonly (keyof TFields)[];
248
+ show?: TShow;
249
+ many?: TMany
250
+ }): TMany extends true ? ArraySchema<{
251
+ input: TReturnType['input'][];
252
+ output: TReturnType['output'][];
253
+ internal: TReturnType['internal'][];
254
+ representation: TReturnType['representation'][];
255
+ validate: TReturnType['validate'][];
256
+ }, {
257
+ schemaAdapter: TAdapter;
258
+ schemaType: 'object';
259
+ hasSave: false
260
+ }, [
261
+ ObjectSchema<{
262
+ input: TReturnType['input'];
263
+ output: TReturnType['output'];
264
+ internal: TReturnType['internal'];
265
+ representation: TReturnType['representation'];
266
+ validate: TReturnType['validate'];
267
+ }, {
268
+ schemaAdapter: TAdapter;
269
+ schemaType: 'object';
270
+ hasSave: false
271
+ }, Record<any, any>>[]
272
+ ]> : ObjectSchema<{
273
+ input: TReturnType['input'];
274
+ output: TReturnType['output'];
275
+ internal: TReturnType['internal'];
276
+ representation: TReturnType['representation'];
277
+ validate: TReturnType['validate'];
278
+ }, {
279
+ schemaAdapter: TAdapter;
280
+ schemaType: 'object';
281
+ hasSave: false
282
+ }, Record<any, any>> => modelSchema<
283
+ TModel,
284
+ TOmit,
285
+ TShow,
286
+ TMany,
287
+ TFields,
288
+ TAllModelFields,
289
+ {
290
+ schemaAdapter: TAdapter;
291
+ schemaType: 'object';
292
+ hasSave: false
293
+ },
294
+ TFieldsOnModel,
295
+ TReturnType
296
+ >(model, options)
297
+ };
298
+ }
299
+ /*
300
+ export class User extends Model<User>() {
301
+ fields = {
302
+ id: AutoField.new(),
303
+ uuid: UuidField.new({
304
+ autoGenerate: true
305
+ }),
306
+ name: CharField.new({ maxLength: 255, dbIndex: true, allowNull: true }),
307
+ age: IntegerField.new({ dbIndex: true }),
308
+ userType: EnumField.new({ choices: ['admin', 'user'], defaultValue: 'admin' }),
309
+ price: DecimalField.new({ maxDigits: 5, decimalPlaces: 2, allowNull: true }),
310
+ isActive: BooleanField.new({ defaultValue: true }),
311
+ companyId: ForeignKeyField.new({
312
+ onDelete: ON_DELETE.CASCADE,
313
+ relatedName: 'usersOfCompany',
314
+ relationName: 'company',
315
+ toField: 'id',
316
+ relatedTo: Company
317
+ }),
318
+ updatedAt: DateField.new({ autoNow: true }),
319
+ createdAt: DateField.new({ autoNowAdd: true }),
320
+ }
321
+
322
+ options: ModelOptionsType<User> = {
323
+ tableName: 'users',
324
+ }
325
+ }
326
+
327
+ export class Company extends Model<Company>() {
328
+ fields = {
329
+ id: AutoField.new(),
330
+ name: CharField.new({ maxLength: 255 }),
331
+ address: CharField.new({ maxLength: 255, allowNull: true }),
332
+ }
333
+
334
+ options: ModelOptionsType<Company> = {
335
+ tableName: 'companies',
336
+ }
337
+ }
338
+ */