@palmares/schemas 0.0.1 → 0.1.0

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 (174) hide show
  1. package/.turbo/turbo-build$colon$watch.log +12 -410
  2. package/CHANGELOG.md +17 -0
  3. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
  4. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
  5. package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
  6. package/__tests__/.drizzle/schema.ts +35 -0
  7. package/__tests__/drizzle.config.ts +11 -0
  8. package/__tests__/eslint.config.js +10 -0
  9. package/__tests__/manage.ts +5 -0
  10. package/__tests__/node_modules/.bin/drizzle-kit +17 -0
  11. package/__tests__/node_modules/.bin/esbuild +14 -0
  12. package/__tests__/node_modules/.bin/tsc +17 -0
  13. package/__tests__/node_modules/.bin/tsserver +17 -0
  14. package/__tests__/node_modules/.bin/tsx +17 -0
  15. package/__tests__/package.json +36 -0
  16. package/__tests__/sqlite.db +0 -0
  17. package/__tests__/src/core/array.test.ts +130 -0
  18. package/__tests__/src/core/boolean.test.ts +66 -0
  19. package/__tests__/src/core/datetime.test.ts +102 -0
  20. package/__tests__/src/core/index.ts +35 -0
  21. package/__tests__/src/core/model.test.ts +260 -0
  22. package/__tests__/src/core/models.ts +50 -0
  23. package/__tests__/src/core/numbers.test.ts +177 -0
  24. package/__tests__/src/core/object.test.ts +198 -0
  25. package/__tests__/src/core/string.test.ts +222 -0
  26. package/__tests__/src/core/test.test.ts +59 -0
  27. package/__tests__/src/core/types.test.ts +97 -0
  28. package/__tests__/src/core/union.test.ts +99 -0
  29. package/__tests__/src/settings.ts +71 -0
  30. package/__tests__/tsconfig.json +11 -0
  31. package/dist/cjs/src/adapter/fields/index.js +2 -2
  32. package/dist/cjs/src/adapter/fields/object.js +9 -0
  33. package/dist/cjs/src/adapter/index.js +1 -0
  34. package/dist/cjs/src/constants.js +1 -7
  35. package/dist/cjs/src/domain.js +146 -1
  36. package/dist/cjs/src/index.js +69 -74
  37. package/dist/cjs/src/model.js +206 -206
  38. package/dist/cjs/src/schema/array.js +185 -58
  39. package/dist/cjs/src/schema/boolean.js +105 -44
  40. package/dist/cjs/src/schema/datetime.js +104 -38
  41. package/dist/cjs/src/schema/number.js +134 -114
  42. package/dist/cjs/src/schema/object.js +106 -43
  43. package/dist/cjs/src/schema/schema.js +123 -75
  44. package/dist/cjs/src/schema/string.js +152 -58
  45. package/dist/cjs/src/schema/union.js +412 -290
  46. package/dist/cjs/src/utils.js +42 -15
  47. package/dist/cjs/src/validators/array.js +6 -1
  48. package/dist/cjs/src/validators/boolean.js +2 -0
  49. package/dist/cjs/src/validators/datetime.js +4 -0
  50. package/dist/cjs/src/validators/number.js +12 -40
  51. package/dist/cjs/src/validators/object.js +1 -0
  52. package/dist/cjs/src/validators/schema.js +5 -1
  53. package/dist/cjs/src/validators/string.js +30 -2
  54. package/dist/cjs/src/validators/union.js +5 -4
  55. package/dist/cjs/src/validators/utils.js +99 -27
  56. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
  57. package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
  58. package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
  59. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
  60. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
  61. package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
  62. package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
  63. package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
  64. package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
  65. package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
  66. package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
  67. package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
  68. package/dist/cjs/types/adapter/index.d.ts +1 -0
  69. package/dist/cjs/types/adapter/index.d.ts.map +1 -1
  70. package/dist/cjs/types/adapter/types.d.ts +28 -18
  71. package/dist/cjs/types/adapter/types.d.ts.map +1 -1
  72. package/dist/cjs/types/constants.d.ts +0 -1
  73. package/dist/cjs/types/constants.d.ts.map +1 -1
  74. package/dist/cjs/types/domain.d.ts +5 -4
  75. package/dist/cjs/types/domain.d.ts.map +1 -1
  76. package/dist/cjs/types/index.d.ts +78 -55
  77. package/dist/cjs/types/index.d.ts.map +1 -1
  78. package/dist/cjs/types/model.d.ts +17 -17
  79. package/dist/cjs/types/model.d.ts.map +1 -1
  80. package/dist/cjs/types/schema/array.d.ts +168 -47
  81. package/dist/cjs/types/schema/array.d.ts.map +1 -1
  82. package/dist/cjs/types/schema/boolean.d.ts +103 -44
  83. package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
  84. package/dist/cjs/types/schema/datetime.d.ts +90 -30
  85. package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
  86. package/dist/cjs/types/schema/number.d.ts +133 -125
  87. package/dist/cjs/types/schema/number.d.ts.map +1 -1
  88. package/dist/cjs/types/schema/object.d.ts +104 -35
  89. package/dist/cjs/types/schema/object.d.ts.map +1 -1
  90. package/dist/cjs/types/schema/schema.d.ts +62 -44
  91. package/dist/cjs/types/schema/schema.d.ts.map +1 -1
  92. package/dist/cjs/types/schema/string.d.ts +152 -65
  93. package/dist/cjs/types/schema/string.d.ts.map +1 -1
  94. package/dist/cjs/types/schema/types.d.ts +11 -2
  95. package/dist/cjs/types/schema/types.d.ts.map +1 -1
  96. package/dist/cjs/types/schema/union.d.ts +133 -40
  97. package/dist/cjs/types/schema/union.d.ts.map +1 -1
  98. package/dist/cjs/types/types.d.ts +35 -0
  99. package/dist/cjs/types/types.d.ts.map +1 -1
  100. package/dist/cjs/types/utils.d.ts +41 -27
  101. package/dist/cjs/types/utils.d.ts.map +1 -1
  102. package/dist/cjs/types/validators/array.d.ts.map +1 -1
  103. package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
  104. package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
  105. package/dist/cjs/types/validators/number.d.ts +5 -6
  106. package/dist/cjs/types/validators/number.d.ts.map +1 -1
  107. package/dist/cjs/types/validators/object.d.ts.map +1 -1
  108. package/dist/cjs/types/validators/schema.d.ts +2 -2
  109. package/dist/cjs/types/validators/schema.d.ts.map +1 -1
  110. package/dist/cjs/types/validators/string.d.ts +9 -9
  111. package/dist/cjs/types/validators/string.d.ts.map +1 -1
  112. package/dist/cjs/types/validators/utils.d.ts +44 -27
  113. package/dist/cjs/types/validators/utils.d.ts.map +1 -1
  114. package/dist/esm/src/adapter/fields/index.js +2 -2
  115. package/dist/esm/src/adapter/fields/object.js +6 -0
  116. package/dist/esm/src/adapter/index.js +1 -0
  117. package/dist/esm/src/constants.js +1 -2
  118. package/dist/esm/src/domain.js +11 -1
  119. package/dist/esm/src/index.js +38 -73
  120. package/dist/esm/src/model.js +83 -78
  121. package/dist/esm/src/schema/array.js +136 -54
  122. package/dist/esm/src/schema/boolean.js +98 -44
  123. package/dist/esm/src/schema/datetime.js +91 -38
  124. package/dist/esm/src/schema/number.js +127 -110
  125. package/dist/esm/src/schema/object.js +98 -43
  126. package/dist/esm/src/schema/schema.js +102 -67
  127. package/dist/esm/src/schema/string.js +147 -59
  128. package/dist/esm/src/schema/union.js +119 -40
  129. package/dist/esm/src/types.js +14 -1
  130. package/dist/esm/src/utils.js +56 -27
  131. package/dist/esm/src/validators/array.js +6 -1
  132. package/dist/esm/src/validators/boolean.js +2 -0
  133. package/dist/esm/src/validators/datetime.js +4 -0
  134. package/dist/esm/src/validators/number.js +9 -23
  135. package/dist/esm/src/validators/object.js +1 -0
  136. package/dist/esm/src/validators/schema.js +5 -1
  137. package/dist/esm/src/validators/string.js +30 -2
  138. package/dist/esm/src/validators/union.js +5 -4
  139. package/dist/esm/src/validators/utils.js +62 -36
  140. package/package.json +3 -3
  141. package/src/adapter/fields/array.ts +2 -2
  142. package/src/adapter/fields/boolean.ts +3 -8
  143. package/src/adapter/fields/datetime.ts +3 -9
  144. package/src/adapter/fields/index.ts +11 -11
  145. package/src/adapter/fields/number.ts +3 -9
  146. package/src/adapter/fields/object.ts +13 -10
  147. package/src/adapter/fields/string.ts +3 -9
  148. package/src/adapter/fields/union.ts +3 -9
  149. package/src/adapter/index.ts +1 -0
  150. package/src/adapter/types.ts +60 -45
  151. package/src/constants.ts +1 -3
  152. package/src/domain.ts +15 -1
  153. package/src/index.ts +189 -211
  154. package/src/model.ts +119 -115
  155. package/src/schema/array.ts +274 -90
  156. package/src/schema/boolean.ts +145 -60
  157. package/src/schema/datetime.ts +133 -49
  158. package/src/schema/number.ts +210 -173
  159. package/src/schema/object.ts +167 -74
  160. package/src/schema/schema.ts +205 -126
  161. package/src/schema/string.ts +221 -94
  162. package/src/schema/types.ts +44 -16
  163. package/src/schema/union.ts +193 -68
  164. package/src/types.ts +53 -0
  165. package/src/utils.ts +115 -57
  166. package/src/validators/array.ts +46 -27
  167. package/src/validators/boolean.ts +13 -7
  168. package/src/validators/datetime.ts +24 -16
  169. package/src/validators/number.ts +53 -63
  170. package/src/validators/object.ts +6 -5
  171. package/src/validators/schema.ts +33 -25
  172. package/src/validators/string.ts +122 -59
  173. package/src/validators/union.ts +8 -8
  174. package/src/validators/utils.ts +67 -42
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import SchemaAdapter from './adapter';
2
+ import SchemaDomain from './domain';
2
3
  import { modelSchema } from './model';
3
4
  import ArraySchema, { array } from './schema/array';
4
5
  import BooleanSchema, { boolean } from './schema/boolean';
@@ -9,23 +10,21 @@ import Schema, { schema } from './schema/schema';
9
10
  import StringSchema, { string } from './schema/string';
10
11
  import UnionSchema, { union } from './schema/union';
11
12
 
12
- import type { DefinitionsOfSchemaType, ExtractTypeFromObjectOfSchemas } from "./schema/types";
13
+ import type { DefinitionsOfSchemaType, ExtractTypeFromObjectOfSchemas } from './schema/types';
13
14
  import type { Narrow } from '@palmares/core';
14
- import type {
15
- Model,
16
- ModelFields} from "@palmares/databases";
15
+ import type { Model, ModelFields } from '@palmares/databases';
17
16
 
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';
17
+ export { default as FieldAdapter, fieldAdapter } from './adapter/fields';
18
+ export { default as NumberFieldAdapter, numberFieldAdapter } from './adapter/fields/number';
19
+ export { default as ObjectFieldAdapter, objectFieldAdapter } from './adapter/fields/object';
20
+ export { default as UnionFieldAdapter, unionFieldAdapter } from './adapter/fields/union';
21
+ export { default as StringFieldAdapter, stringFieldAdapter } from './adapter/fields/string';
22
+ export { default as ArrayFieldAdapter, arrayFieldAdapter } from './adapter/fields/array';
23
+ export { default as BooleanFieldAdapter, booleanFieldAdapter } from './adapter/fields/boolean';
24
+ export { default as DatetimeFieldAdapter, datetimeFieldAdapter } from './adapter/fields/datetime';
27
25
 
28
- export { setDefaultAdapter } from './conf';
26
+ export { Infer as infer } from './types';
27
+ export { setDefaultAdapter, getDefaultAdapter } from './conf';
29
28
  export * from './adapter/types';
30
29
  export * from './schema';
31
30
  export {
@@ -37,18 +36,20 @@ export {
37
36
  ArraySchema,
38
37
  BooleanSchema,
39
38
  DatetimeSchema,
40
- Schema,
39
+ Schema
41
40
  };
42
41
  export { schema, number, object, union, string, array, datetime, boolean };
43
42
  export { default as compile } from './compile';
44
43
 
45
44
  export { modelSchema };
46
45
 
46
+ export default SchemaDomain;
47
+
47
48
  export function getSchemasWithDefaultAdapter<TAdapter extends SchemaAdapter>() {
48
49
  return {
49
50
  number: () => NumberSchema.new<{ schemaAdapter: TAdapter; schemaType: 'number'; hasSave: false }>(),
50
51
  string: () => StringSchema.new<{ schemaAdapter: TAdapter; schemaType: 'string'; hasSave: false }>(),
51
- array: <TSchemas extends readonly [Schema, ...Schema[]] | [Schema[]]>(...schemas: TSchemas) =>
52
+ array: <TSchemas extends readonly [Schema, ...Schema[]] | [[Schema]]>(...schemas: TSchemas) =>
52
53
  array<TSchemas, { schemaAdapter: TAdapter; schemaType: 'array'; hasSave: false }>(...schemas),
53
54
  boolean: () => BooleanSchema.new<{ schemaAdapter: TAdapter; schemaType: 'boolean'; hasSave: false }>(),
54
55
  object: <TData extends Record<any, Schema<any, any>>>(data: TData) =>
@@ -58,22 +59,23 @@ export function getSchemasWithDefaultAdapter<TAdapter extends SchemaAdapter>() {
58
59
  ) => UnionSchema.new<TSchemas, { schemaAdapter: TAdapter; schemaType: 'union'; hasSave: false }>(schemas),
59
60
  datetime: () => DatetimeSchema.new<{ schemaAdapter: TAdapter; schemaType: 'datetime'; hasSave: false }>(),
60
61
  /**
61
- * Different from other models, this function is a factory function that returns either an ObjectSchema or an ArraySchema.
62
+ * Different from other models, this function is a factory function that returns either an ObjectSchema or
63
+ * an ArraySchema.
62
64
  * The idea is to build the schema of a model dynamically based on its fields.
63
65
  *
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
+ * Another feature is that it can automatically add the foreign key relation to the schema,
67
+ * but for that you need to define the fields of the related model in the fields object.
66
68
  *
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.
69
+ * For example: A User model have a field `companyId` that is a ForeignKeyField to the Company model.
70
+ * The `relationName` is the direct relation from the User model to the Company model, and the `relatedName`
71
+ * is the reverse relation from the Company model to the User model. If you define the fieldName as either
72
+ * the relatedName or the relationName it will fetch the data automatically.
71
73
  *
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
+ * **Important**: We build the schema dynamically but also lazily, if you don't try to parse or validate the
75
+ * schema, it won't be built. After the first time it's built, it's cached and never built again.
74
76
  *
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
+ * **Important 2**: If you want to use the automatic relation feature, you need to define guarantee that the
78
+ * foreignKey field fieldName exists on `show` array, or that it doesn't exist on `omit` array.
77
79
  *
78
80
  * Like: `{ options: { show: ['id', 'name', 'companyId'] }}` or `{ options: { omit: ['id'] }}` it **will work**.
79
81
  *
@@ -128,19 +130,20 @@ export function getSchemasWithDefaultAdapter<TAdapter extends SchemaAdapter>() {
128
130
  * show: ['id', 'type']
129
131
  * });
130
132
  *```
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
- */
133
+ * @param model - The model that you want to build the schema from.
134
+ * @param options - The options to build the schema.
135
+ * @param options.ignoreExtraneousFields - If you want to ignore extraneous fields set this to true.
136
+ * @param options.engineInstance - What engine instance you want to use to fetch the data.
137
+ * Defaults to the first one.
138
+ * @param options.fields - Extra fields that you want to add to the schema. If it has the same name as the
139
+ * model field, We will not create a schema for that field and use the one you have defined here.
140
+ * @param options.omit - Fields that you want to omit from the schema. If that is defined, we ignore `show` option.
141
+ * @param options.show - Fields that you want to show on the schema. If that is defined, we ignore `omit` option.
142
+ * @param options.many - If you want to return an array instead of an object, set this to true. With that we create
143
+ * an ArraySchema instead of an ObjectSchema.
144
+ *
145
+ * @returns - If you pass the `many` option as true, we return an ArraySchema, otherwise we return an ObjectSchema.
146
+ */
144
147
  modelSchema: <
145
148
  TModel extends ReturnType<typeof Model>,
146
149
  const TOmit extends readonly (keyof ModelFields<InstanceType<TModel>>)[] | undefined[] = undefined[],
@@ -151,188 +154,163 @@ export function getSchemasWithDefaultAdapter<TAdapter extends SchemaAdapter>() {
151
154
  TFieldsOnModel = TOmit extends undefined[]
152
155
  ? TShow extends undefined[]
153
156
  ? 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
- >,
157
+ : Pick<TAllModelFields, TShow[number] extends keyof TAllModelFields ? TShow[number] : never>
158
+ : Omit<TAllModelFields, TOmit[number] extends keyof TAllModelFields ? TOmit[number] : never>,
162
159
  TReturnType extends {
163
160
  input: any;
164
161
  output: any;
165
- validate: any,
162
+ validate: any;
166
163
  internal: any;
167
164
  representation: any;
168
165
  } = {
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
- >;
166
+ input: TFields extends undefined
167
+ ? TFieldsOnModel
168
+ : Omit<
169
+ TFieldsOnModel,
170
+ keyof ExtractTypeFromObjectOfSchemas<
171
+ // eslint-disable-next-line ts/ban-types
172
+ TFields extends undefined ? {} : TFields,
173
+ 'input'
174
+ >
175
+ > &
176
+ ExtractTypeFromObjectOfSchemas<
177
+ // eslint-disable-next-line ts/ban-types
178
+ TFields extends undefined ? {} : TFields,
179
+ 'input'
180
+ >;
181
+ output: TFields extends undefined
182
+ ? TFieldsOnModel
183
+ : Omit<
184
+ TFieldsOnModel,
185
+ keyof ExtractTypeFromObjectOfSchemas<
186
+ // eslint-disable-next-line ts/ban-types
187
+ TFields extends undefined ? {} : TFields,
188
+ 'output'
189
+ >
190
+ > &
191
+ ExtractTypeFromObjectOfSchemas<
192
+ // eslint-disable-next-line ts/ban-types
193
+ TFields extends undefined ? {} : TFields,
194
+ 'output'
195
+ >;
196
+ internal: TFields extends undefined
197
+ ? 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
212
+ ? TFieldsOnModel
213
+ : Omit<
214
+ TFieldsOnModel,
215
+ keyof ExtractTypeFromObjectOfSchemas<
216
+ // eslint-disable-next-line ts/ban-types
217
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
218
+ 'representation'
219
+ >
220
+ > &
221
+ ExtractTypeFromObjectOfSchemas<
222
+ // eslint-disable-next-line ts/ban-types
223
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
224
+ 'representation'
225
+ >;
226
+ validate: TFields extends undefined
227
+ ? TFieldsOnModel
228
+ : Omit<
229
+ TFieldsOnModel,
230
+ keyof ExtractTypeFromObjectOfSchemas<
231
+ // eslint-disable-next-line ts/ban-types
232
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
233
+ 'validate'
234
+ >
235
+ > &
236
+ ExtractTypeFromObjectOfSchemas<
237
+ // eslint-disable-next-line ts/ban-types
238
+ TFields extends Record<any, Schema<any, DefinitionsOfSchemaType>> ? TFields : {},
239
+ 'validate'
240
+ >;
239
241
  }
240
242
  >(
241
243
  model: TModel,
242
244
  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
- }, {
245
+ ignoreExtraneousFields?: boolean;
246
+ engineInstance?: string;
247
+ fields?: TFields;
248
+ omit?: TOmit;
249
+ omitRelation?: readonly (keyof TFields)[];
250
+ show?: TShow;
251
+ many?: TMany;
252
+ }
253
+ ): TMany extends true
254
+ ? ArraySchema<
255
+ {
256
+ input: TReturnType['input'][];
257
+ output: TReturnType['output'][];
258
+ internal: TReturnType['internal'][];
259
+ representation: TReturnType['representation'][];
260
+ validate: TReturnType['validate'][];
261
+ },
262
+ {
263
+ schemaAdapter: TAdapter;
264
+ schemaType: 'object';
265
+ hasSave: false;
266
+ },
267
+ [
268
+ ObjectSchema<
269
+ {
270
+ input: TReturnType['input'];
271
+ output: TReturnType['output'];
272
+ internal: TReturnType['internal'];
273
+ representation: TReturnType['representation'];
274
+ validate: TReturnType['validate'];
275
+ },
276
+ {
277
+ schemaAdapter: TAdapter;
278
+ schemaType: 'object';
279
+ hasSave: false;
280
+ },
281
+ Record<any, any>
282
+ >
283
+ ]
284
+ >
285
+ : ObjectSchema<
286
+ {
287
+ input: TReturnType['input'];
288
+ output: TReturnType['output'];
289
+ internal: TReturnType['internal'];
290
+ representation: TReturnType['representation'];
291
+ validate: TReturnType['validate'];
292
+ },
293
+ {
294
+ schemaAdapter: TAdapter;
295
+ schemaType: 'object';
296
+ hasSave: false;
297
+ },
298
+ Record<any, any>
299
+ > =>
300
+ modelSchema<
301
+ TModel,
302
+ TOmit,
303
+ TShow,
304
+ TMany,
305
+ TFields,
306
+ TAllModelFields,
307
+ {
268
308
  schemaAdapter: TAdapter;
269
309
  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)
310
+ hasSave: false;
311
+ },
312
+ TFieldsOnModel,
313
+ TReturnType
314
+ >(model, options)
297
315
  };
298
316
  }
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
- */