@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../src/validators/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAwC,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE1G,wBAAgB,gBAAgB,CAAC,cAAc,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,4BAA4B,CAmDxG"}
@@ -0,0 +1,10 @@
1
+ import type BooleanSchema from '../schema/boolean';
2
+ import type NumberSchema from '../schema/number';
3
+ import type Schema from '../schema/schema';
4
+ import type StringSchema from '../schema/string';
5
+ import type { ValidationFallbackReturnType } from '../schema/types';
6
+ export declare function optional(args: Schema['__optional']): ValidationFallbackReturnType;
7
+ export declare function nullable(args: Schema['__nullable']): ValidationFallbackReturnType;
8
+ export declare function checkType(args: Schema['__type']): ValidationFallbackReturnType;
9
+ export declare function is(args: BooleanSchema['__is'] | NumberSchema['__is'] | StringSchema['__is']): ValidationFallbackReturnType;
10
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/validators/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEpE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,4BAA4B,CAkCjF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,4BAA4B,CAkCjF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,4BAA4B,CA2B9E;AAED,wBAAgB,EAAE,CAChB,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GACxE,4BAA4B,CAuB9B"}
@@ -0,0 +1,12 @@
1
+ import type StringSchema from '../schema/string';
2
+ import { type ValidationFallbackReturnType } from '../schema/types';
3
+ export declare function stringValidation(): ValidationFallbackReturnType;
4
+ export declare function maxLength(args: StringSchema['__maxLength']): ValidationFallbackReturnType;
5
+ export declare function minLength(args: StringSchema['__maxLength']): ValidationFallbackReturnType;
6
+ export declare function endsWith(args: StringSchema['__endsWith']): ValidationFallbackReturnType;
7
+ export declare function startsWith(args: StringSchema['__startsWith']): ValidationFallbackReturnType;
8
+ export declare function includes(args: StringSchema['__includes']): ValidationFallbackReturnType;
9
+ export declare function regex(args: StringSchema['__regex']): ValidationFallbackReturnType;
10
+ export declare function uuid(args: StringSchema['__uuid']): ValidationFallbackReturnType;
11
+ export declare function email(args: StringSchema['__email']): ValidationFallbackReturnType;
12
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../../src/validators/string.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEpE,wBAAgB,gBAAgB,IAAI,4BAA4B,CAoB/D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,4BAA4B,CAqBzF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,GAAG,4BAA4B,CAqBzF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,4BAA4B,CAqBvF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,4BAA4B,CAqB3F;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG,4BAA4B,CAqBvF;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,4BAA4B,CAqBjF;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,4BAA4B,CAyB/E;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,4BAA4B,CAsBjF"}
@@ -0,0 +1,2 @@
1
+ export type ValidatorTypes = 'low' | 'medium' | 'high';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/validators/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type Schema from '../schema/schema';
2
+ import type { ValidationFallbackReturnType } from '../schema/types';
3
+ export declare function unionValidation(schemas: readonly [Schema<any, any>, Schema<any, any>, ...Schema<any, any>[]]): ValidationFallbackReturnType;
4
+ //# sourceMappingURL=union.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../../../src/validators/union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEpE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAC5E,4BAA4B,CA8C9B"}
@@ -0,0 +1,83 @@
1
+ import type { ValidatorTypes } from './types';
2
+ import type { ErrorCodes } from '../adapter/types';
3
+ import type Schema from '../schema/schema';
4
+ import type { ValidationFallbackCallbackReturnType, ValidationFallbackCallbackType, ValidationFallbackReturnType } from '../schema/types';
5
+ /**
6
+ * Okay, so what is this? This is a validator class, it represents a Node on a linked list. The linked list has lower priority validators on the end of the list and higher
7
+ * priority validators on the start of the list. Maybe in the future we can change that to a binary tree, but for now this is enough.
8
+ *
9
+ * Why did we choose this approach? Because what i was doing was that i saw myself repeating the same code 3 times on the schema in order to make the validation work. Each validator had
10
+ * a different return type, i didn't like that. I wanted to add more power and control on the validator, not on the schema. So i created this class. So pretty much, over here and
11
+ * on each validator we can define the type it is. It can actually be three: `low`, `medium` and `high`. The `low` validators are the ones that are going to be executed last, the `high` validators
12
+ * are the ones that are going to be executed first. High validators validate if the value is null or undefined, if it allows that. It can stop the execution of the other validators if it wants to.
13
+ *
14
+ * Example: Let's say that the value is null, if the value is null, is there a reason to check if it's a number? No, right? So the high validator can stop the execution of the other validators.
15
+ * Same as before, if the value is not a number, is there a reason to check if it's value is greater than the `max` allowed 10? No, right? So the medium validator can stop the execution of
16
+ * the other validators.
17
+ *
18
+ * That's what this solve, it's a better approach than repeating the same code 3 times on the schema. It's also more powerful, because if we need to add any extra priorities we can do that easily
19
+ * without changing the schema.
20
+ */
21
+ export default class Validator {
22
+ child?: Validator;
23
+ parent?: Validator;
24
+ priority: number;
25
+ fallbacks: ((value: any, path: (string | number)[], options: Parameters<Schema['__transformToAdapter']>[0]) => Promise<{
26
+ parsed: any;
27
+ errors: {
28
+ isValid: boolean;
29
+ code: ErrorCodes;
30
+ message: string;
31
+ path: (string | number)[];
32
+ }[];
33
+ preventChildValidation?: boolean;
34
+ }>)[];
35
+ constructor(type: ValidatorTypes);
36
+ /**
37
+ * We create all of the validators on the schema in order, i actually didn't want to go on that route but i found it easier to do so.
38
+ *
39
+ * The logic here is simple, if it's not the same priority we will walk on the linked list until we find a validator that matches the priority we are expecting. If we can't walk anymore, we create
40
+ * the next priority validator and append it to the linked list. Be aware that it's a double linked list, so we can walk both ways, from the end to the start and from the start to the end.
41
+ * So you don't really need to start from the root, the linked list can start from anywhere and it will find it's way through.
42
+ *
43
+ * I know there are better ways to do this instead of walking through the linked list, but like i explained before, this is enough for now.
44
+ *
45
+ * If the priority is higher than the current priority saved on the schema, we should substitute the rootValidator on the schema with the new one.
46
+ *
47
+ * @param schema - The schema that we are working on right now, all fallbacks are tied to that specific schema.
48
+ * @param type - The type of the fallback that we are adding.
49
+ * @param fallback - The fallback function that we are adding.
50
+ * @param childOrParent - If we are adding a fallback to the child or to the parent.
51
+ * @param options - The options that we are passing to the fallback.
52
+ */
53
+ private checkAppendOrCreate;
54
+ addFallback(schema: Schema, type: ValidatorTypes, fallback: ValidationFallbackCallbackType, options?: Parameters<(typeof Validator)['createAndAppendFallback']>[2]): void;
55
+ /**
56
+ * Validates the value against all of the fallbacks, the fallbacks are executed in order, from the highest priority to the lowest priority.
57
+ * A validator can stop the execution of the other validators if it feels like so. Like on the example of a value being null or undefined.
58
+ *
59
+ * @param errorsAsHashedSet - This is a set that contains all of the errors that we already found, this is used to avoid duplicated errors.
60
+ * @param path - The path that we are validating right now.
61
+ * @param parseResult - The result of the parsing, it contains the parsed value and the errors that we found.
62
+ * @param options - The options that we are passing to the fallback.
63
+ */
64
+ validate(errorsAsHashedSet: Set<string>, path: ValidationFallbackCallbackReturnType['errors'][number]['path'], parseResult: {
65
+ errors: undefined | ValidationFallbackCallbackReturnType['errors'];
66
+ parsed: any;
67
+ }, options: Parameters<Schema['__transformToAdapter']>[0]): Promise<ValidationFallbackCallbackReturnType>;
68
+ /**
69
+ * This static method takes care of everything for you. This means that you should only call this method for appending new fallbacks, it takes care of creating the root validator
70
+ * and making sure that the rootValidator on the schema is the highest priority one.
71
+ *
72
+ * @param schema - The schema that we are working on right now, all fallbacks are tied to that specific schema. We automatically define the rootValidator on the schema
73
+ * so you don't need to worry about that.
74
+ * @param fallback - The fallback that we are adding. This is an object that contains the type of the fallback and the callback that we are adding.
75
+ * @param options - The options that we are passing to the fallback. Options like `at` and `removeCurrent` are passed to the `addFallback` method.
76
+ */
77
+ static createAndAppendFallback(schema: Schema<any, any>, fallback: ValidationFallbackReturnType, options?: {
78
+ at?: number;
79
+ removeCurrent?: boolean;
80
+ }): Validator;
81
+ toString(ident?: number): string;
82
+ }
83
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/validators/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EACV,oCAAoC,EACpC,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AAgBzB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,CAAC,CACV,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACzB,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,KACnD,OAAO,CAAC;QACX,MAAM,EAAE,GAAG,CAAC;QACZ,MAAM,EAAE;YACN,OAAO,EAAE,OAAO,CAAC;YACjB,IAAI,EAAE,UAAU,CAAC;YACjB,OAAO,EAAE,MAAM,CAAC;YAChB,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;SAC3B,EAAE,CAAC;QACJ,sBAAsB,CAAC,EAAE,OAAO,CAAC;KAClC,CAAC,CAAC,EAAE,CAAM;gBAEC,IAAI,EAAE,cAAc;IAIhC;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,mBAAmB;IA0B3B,WAAW,CACT,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,8BAA8B,EACxC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,CAAC;IAWxE;;;;;;;;OAQG;IACG,QAAQ,CACZ,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,IAAI,EAAE,oCAAoC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EACpE,WAAW,EAAE;QACX,MAAM,EAAE,SAAS,GAAG,oCAAoC,CAAC,QAAQ,CAAC,CAAC;QACnE,MAAM,EAAE,GAAG,CAAC;KACb,EACD,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,GACrD,OAAO,CAAC,oCAAoC,CAAC;IA4BhD;;;;;;;;OAQG;IACH,MAAM,CAAC,uBAAuB,CAC5B,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACxB,QAAQ,EAAE,4BAA4B,EACtC,OAAO,CAAC,EAAE;QACR,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB;IAcH,QAAQ,CAAC,KAAK,SAAI,GAAG,MAAM;CAK5B"}
@@ -0,0 +1,13 @@
1
+ import FieldAdapter from '.';
2
+ export function arrayFieldAdapter(args) {
3
+ class CustomArrayFieldAdapter extends ArrayFieldAdapter {
4
+ translate = args.translate;
5
+ toString = args.toString;
6
+ formatError = args.formatError;
7
+ parse = args.parse;
8
+ }
9
+ return CustomArrayFieldAdapter;
10
+ }
11
+ export default class ArrayFieldAdapter extends FieldAdapter {
12
+ translate(_fieldAdapter, _args) {}
13
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function booleanFieldAdapter(args) {
4
+ class CustomBooleanFieldAdapter extends BooleanFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomBooleanFieldAdapter;
11
+ }
12
+ export default class BooleanFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function datetimeFieldAdapter(args) {
4
+ class CustomDatetimeFieldAdapter extends DatetimeFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomDatetimeFieldAdapter;
11
+ }
12
+ export default class DatetimeFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,37 @@
1
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
2
+ export function fieldAdapter(args) {
3
+ class CustomFieldAdapter extends FieldAdapter {
4
+ translate = args.translate;
5
+ toString = args.toString;
6
+ formatError = args.formatError;
7
+ parse = args.parse;
8
+ }
9
+ return CustomFieldAdapter;
10
+ }
11
+ export default class FieldAdapter {
12
+ translate(_fieldAdapter, _args, _base) {
13
+ throw new SchemaAdapterNotImplementedError({
14
+ className: this.constructor.name,
15
+ functionName: 'translate'
16
+ });
17
+ }
18
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
19
+ throw new SchemaAdapterNotImplementedError({
20
+ className: this.constructor.name,
21
+ functionName: 'parse'
22
+ });
23
+ }
24
+ toString(_adapter, _fieldAdapter, _args, _base) {
25
+ throw new SchemaAdapterNotImplementedError({
26
+ className: this.constructor.name,
27
+ functionName: 'toString'
28
+ });
29
+ }
30
+ // eslint-disable-next-line ts/require-await
31
+ async formatError(_adapter, _fieldAdapter, _error, _metadata) {
32
+ throw new SchemaAdapterNotImplementedError({
33
+ className: this.constructor.name,
34
+ functionName: 'formatError'
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function numberFieldAdapter(args) {
4
+ class CustomNumberFieldAdapter extends NumberFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomNumberFieldAdapter;
11
+ }
12
+ export default class NumberFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function objectFieldAdapter(args) {
4
+ class CustomObjectFieldAdapter extends ObjectFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomObjectFieldAdapter;
11
+ }
12
+ export default class ObjectFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function stringFieldAdapter(args) {
4
+ class CustomStringFieldAdapter extends StringFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomStringFieldAdapter;
11
+ }
12
+ export default class StringFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import FieldAdapter from '.';
2
+ import { SchemaAdapterNotImplementedError } from '../../exceptions';
3
+ export function unionFieldAdapter(args) {
4
+ class CustomUnionFieldAdapter extends UnionFieldAdapter {
5
+ translate = args.translate;
6
+ toString = args.toString;
7
+ formatError = args.formatError;
8
+ parse = args.parse;
9
+ }
10
+ return CustomUnionFieldAdapter;
11
+ }
12
+ export default class UnionFieldAdapter extends FieldAdapter {
13
+ translate(_fieldAdapter, _args) {}
14
+ parse(_adapter, _fieldAdapter, _result, _value, _args) {
15
+ throw new SchemaAdapterNotImplementedError({
16
+ className: this.constructor.name,
17
+ functionName: 'parse'
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,18 @@
1
+ import { SchemaAdapterNotImplementedError } from '../exceptions';
2
+ export default class SchemaAdapter {
3
+ field;
4
+ number;
5
+ object;
6
+ union;
7
+ string;
8
+ array;
9
+ boolean;
10
+ datetime;
11
+ // eslint-disable-next-line ts/require-await
12
+ async formatError(_error, _metadata) {
13
+ throw new SchemaAdapterNotImplementedError({
14
+ className: 'SchemaAdapter',
15
+ functionName: 'formatError'
16
+ });
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ import { getDefaultStd } from '@palmares/core';
2
+ import { getDefaultAdapter } from './conf';
3
+ export default async function compile(schemas) {
4
+ const schemasAsEntries = Object.entries(schemas);
5
+ const adapter = getDefaultAdapter();
6
+ const std = getDefaultStd();
7
+ for (const [keyName, schema] of schemasAsEntries){
8
+ console.log(await schema.compile(adapter));
9
+ }
10
+ }
@@ -0,0 +1,19 @@
1
+ import { NoAdapterFoundError } from './exceptions';
2
+ let cachedAdapter = null;
3
+ /**
4
+ * Sets the default adapter to be used by all of your schemas.
5
+ *
6
+ * @param adapter - The adapter to use when you define schemas.
7
+ */ export function setDefaultAdapter(adapter) {
8
+ cachedAdapter = adapter;
9
+ }
10
+ /**
11
+ * Gets the default adapter to be used by all of your schemas.
12
+ *
13
+ * @throws {NoAdapterFoundError} - If no adapter has been set.
14
+ *
15
+ * @returns The default adapter.
16
+ */ export function getDefaultAdapter() {
17
+ if (!cachedAdapter) throw new NoAdapterFoundError();
18
+ return cachedAdapter;
19
+ }
@@ -0,0 +1,5 @@
1
+ export const DEFAULT_NUMBER_MAX_EXCEPTION = (max, inclusive)=>`The number is greater than the allowed ${max}.${inclusive ? ` The value ${max} is accepted as well.` : ''}`;
2
+ export const DEFAULT_NUMBER_MIN_EXCEPTION = (min, inclusive)=>`The number is less than the allowed ${min}.${inclusive ? ` The value ${min} is accepted as well.` : ''}`;
3
+ export const DEFAULT_NUMBER_NEGATIVE_EXCEPTION = (allowZero)=>`The number should be negative.${allowZero ? ` The value 0 is accepted as well.` : ''}`;
4
+ export const DEFAULT_NUMBER_POSITIVE_EXCEPTION = (allowZero)=>`The number should be positive.${allowZero ? ` The value 0 is accepted as well.` : ''}`;
5
+ export const DEFAULT_NUMBER_INTEGER_EXCEPTION = ()=>`THe number should be an integer.`;
@@ -0,0 +1,2 @@
1
+ import { domain } from '@palmares/core';
2
+ export default domain('@palmares/schemas', __dirname, {});
@@ -0,0 +1,15 @@
1
+ export class SchemaAdapterNotImplementedError extends Error {
2
+ constructor(args){
3
+ super(`Schema adapter did not implement ${args.functionName} in ${args.className}`);
4
+ }
5
+ }
6
+ export class NoAdapterFoundError extends Error {
7
+ constructor(){
8
+ super('No adapter found, please define an adapter using setDefaultAdapter() before using any schema.');
9
+ }
10
+ }
11
+ export class TranslatableFieldNotImplementedError extends Error {
12
+ constructor(fieldName){
13
+ super(`TranslatableField '${fieldName}' did not implement the 'schema' key on 'customAttributes'`);
14
+ }
15
+ }
@@ -0,0 +1,160 @@
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
+ export { default as default } from './domain';
12
+ export { default as FieldAdapter } from './adapter/fields';
13
+ export { default as NumberAdapter } from './adapter/fields/number';
14
+ export { default as ObjectFieldAdapter } from './adapter/fields/object';
15
+ export { default as UnionFieldAdapter } from './adapter/fields/union';
16
+ export { default as StringFieldAdapter } from './adapter/fields/string';
17
+ export { default as ArrayFieldAdapter } from './adapter/fields/array';
18
+ export { default as BooleanFieldAdapter } from './adapter/fields/boolean';
19
+ export { default as DatetimeFieldAdapter } from './adapter/fields/datetime';
20
+ export { setDefaultAdapter } from './conf';
21
+ export * from './adapter/types';
22
+ export * from './schema';
23
+ export { SchemaAdapter, NumberSchema, ObjectSchema, UnionSchema, StringSchema, ArraySchema, BooleanSchema, DatetimeSchema, Schema };
24
+ export { schema, number, object, union, string, array, datetime, boolean };
25
+ export { default as compile } from './compile';
26
+ export { modelSchema };
27
+ export function getSchemasWithDefaultAdapter() {
28
+ return {
29
+ number: ()=>NumberSchema.new(),
30
+ string: ()=>StringSchema.new(),
31
+ array: (...schemas)=>array(...schemas),
32
+ boolean: ()=>BooleanSchema.new(),
33
+ object: (data)=>ObjectSchema.new(data),
34
+ union: (...schemas)=>UnionSchema.new(schemas),
35
+ datetime: ()=>DatetimeSchema.new(),
36
+ /**
37
+ * Different from other models, this function is a factory function that returns either an ObjectSchema or an ArraySchema.
38
+ * The idea is to build the schema of a model dynamically based on its fields.
39
+ *
40
+ * Another feature is that it can automatically add the foreign key relation to the schema, but for that you need to define
41
+ * the fields of the related model in the fields object.
42
+ *
43
+ * For example: A User model have a field `companyId` that is a ForeignKeyField to the Company model. The `relationName`
44
+ * is the direct relation from the User model to the Company model, and the `relatedName` is the reverse relation from the
45
+ * Company model to the User model. If you define the fieldName as either the relatedName or the relationName it will fetch
46
+ * the data automatically.
47
+ *
48
+ * **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.
49
+ * After the first time it's built, it's cached and never built again.
50
+ *
51
+ * **Important 2**: If you want to use the automatic relation feature, you need to define guarantee that the foreignKey field fieldName
52
+ * exists on `show` array, or that it doesn't exist on `omit` array.
53
+ *
54
+ * Like: `{ options: { show: ['id', 'name', 'companyId'] }}` or `{ options: { omit: ['id'] }}` it **will work**.
55
+ *
56
+ * If you do `{ options: { show: ['id', 'name'] }}` or `{ options: { omit: ['companyId']} }` it **won't work**.
57
+ *
58
+ * **Important 3**: If you want to return an array instead of an object, you need to pass the `many` option as true.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { auto, choice, foreignKey, Model, define } from '@palmares/databases';
63
+ * import * as p from '@palmares/schemas';
64
+ *
65
+ * const Company = define('Company', {
66
+ * fields: {
67
+ * id: auto(),
68
+ * name: text(),
69
+ * },
70
+ * options: {
71
+ * tableName: 'company',
72
+ * }
73
+ * });
74
+ *
75
+ * class User extends Model<User>() {
76
+ * fields = {
77
+ * id: auto(),
78
+ * type: choice({ choices: ['user', 'admin'] }),
79
+ * companyId: foreignKey({
80
+ * relatedTo: Company,
81
+ * relationName: 'company',
82
+ * relatedName: 'usersOfCompany',
83
+ * toField: 'id',
84
+ * onDelete: 'CASCADE',
85
+ * }),
86
+ * }
87
+ *
88
+ * options = {
89
+ * tableName: 'user',
90
+ * }
91
+ * }
92
+ *
93
+ * const userSchema = p.modelSchema(User, {
94
+ * fields: {
95
+ * company: p.modelSchema(Company).optional({ outputOnly: true });
96
+ * },
97
+ * show: ['type', 'companyId']
98
+ * });
99
+ *
100
+ * const companySchema = p.modelSchema(Company, {
101
+ * fields: {
102
+ * usersOfCompany: p.modelSchema(User, { many: true }).optional({ outputOnly: true });
103
+ * },
104
+ * show: ['id', 'type']
105
+ * });
106
+ *```
107
+ * @param model - The model that you want to build the schema from.
108
+ * @param options - The options to build the schema.
109
+ * @param options.ignoreExtraneousFields - If you want to ignore extraneous fields set this to true.
110
+ * @param options.engineInstance - What engine instance you want to use to fetch the data. Defaults to the first one.
111
+ * @param options.fields - Extra fields that you want to add to the schema. If it has the same name as the model field,
112
+ * We will not create a schema for that field and use the one you have defined here.
113
+ * @param options.omit - Fields that you want to omit from the schema. If that is defined, we ignore `show` option.
114
+ * @param options.show - Fields that you want to show on the schema. If that is defined, we ignore `omit` option.
115
+ * @param options.many - If you want to return an array instead of an object, set this to true. With that we create
116
+ * an ArraySchema instead of an ObjectSchema.
117
+ *
118
+ * @returns - If you pass the `many` option as true, we return an ArraySchema, otherwise we return an ObjectSchema.
119
+ */ modelSchema: (model, options)=>modelSchema(model, options)
120
+ };
121
+ } /*
122
+ export class User extends Model<User>() {
123
+ fields = {
124
+ id: AutoField.new(),
125
+ uuid: UuidField.new({
126
+ autoGenerate: true
127
+ }),
128
+ name: CharField.new({ maxLength: 255, dbIndex: true, allowNull: true }),
129
+ age: IntegerField.new({ dbIndex: true }),
130
+ userType: EnumField.new({ choices: ['admin', 'user'], defaultValue: 'admin' }),
131
+ price: DecimalField.new({ maxDigits: 5, decimalPlaces: 2, allowNull: true }),
132
+ isActive: BooleanField.new({ defaultValue: true }),
133
+ companyId: ForeignKeyField.new({
134
+ onDelete: ON_DELETE.CASCADE,
135
+ relatedName: 'usersOfCompany',
136
+ relationName: 'company',
137
+ toField: 'id',
138
+ relatedTo: Company
139
+ }),
140
+ updatedAt: DateField.new({ autoNow: true }),
141
+ createdAt: DateField.new({ autoNowAdd: true }),
142
+ }
143
+
144
+ options: ModelOptionsType<User> = {
145
+ tableName: 'users',
146
+ }
147
+ }
148
+
149
+ export class Company extends Model<Company>() {
150
+ fields = {
151
+ id: AutoField.new(),
152
+ name: CharField.new({ maxLength: 255 }),
153
+ address: CharField.new({ maxLength: 255, allowNull: true }),
154
+ }
155
+
156
+ options: ModelOptionsType<Company> = {
157
+ tableName: 'companies',
158
+ }
159
+ }
160
+ */