@rvoh/dream 0.40.3 → 0.40.4

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 (201) hide show
  1. package/dist/cjs/src/types/associations/belongsTo.js +2 -0
  2. package/dist/cjs/src/types/associations/hasMany.js +2 -0
  3. package/dist/cjs/src/types/associations/hasOne.js +2 -0
  4. package/dist/cjs/src/types/associations/shared.js +2 -0
  5. package/dist/cjs/src/types/db.js +2 -0
  6. package/dist/cjs/src/types/dream.js +2 -0
  7. package/dist/cjs/src/types/lifecycle.js +2 -0
  8. package/dist/cjs/src/types/logger.js +2 -0
  9. package/dist/cjs/src/types/openapi.js +2 -0
  10. package/dist/cjs/src/types/query.js +2 -0
  11. package/dist/cjs/src/types/utils.js +2 -0
  12. package/dist/cjs/src/types/validation.js +2 -0
  13. package/dist/cjs/src/types/variadic.js +2 -0
  14. package/dist/esm/src/types/associations/belongsTo.js +1 -0
  15. package/dist/esm/src/types/associations/hasMany.js +1 -0
  16. package/dist/esm/src/types/associations/hasOne.js +1 -0
  17. package/dist/esm/src/types/associations/shared.js +1 -0
  18. package/dist/esm/src/types/db.js +1 -0
  19. package/dist/esm/src/types/dream.js +1 -0
  20. package/dist/esm/src/types/lifecycle.js +1 -0
  21. package/dist/esm/src/types/logger.js +1 -0
  22. package/dist/esm/src/types/openapi.js +1 -0
  23. package/dist/esm/src/types/query.js +1 -0
  24. package/dist/esm/src/types/utils.js +1 -0
  25. package/dist/esm/src/types/validation.js +1 -0
  26. package/dist/esm/src/types/variadic.js +1 -0
  27. package/dist/types/src/types/associations/belongsTo.d.ts +28 -73
  28. package/dist/types/src/types/associations/belongsTo.ts +76 -0
  29. package/dist/types/src/types/associations/hasMany.d.ts +15 -79
  30. package/dist/types/src/types/associations/hasMany.ts +80 -0
  31. package/dist/types/src/types/associations/hasOne.d.ts +8 -26
  32. package/dist/types/src/types/associations/hasOne.ts +26 -0
  33. package/dist/types/src/types/associations/shared.d.ts +98 -444
  34. package/dist/types/src/types/associations/shared.ts +450 -0
  35. package/dist/types/src/types/db.d.ts +9 -14
  36. package/dist/types/src/types/db.ts +14 -0
  37. package/dist/types/src/types/dream.d.ts +124 -510
  38. package/dist/types/src/types/dream.ts +521 -0
  39. package/dist/types/src/types/lifecycle.d.ts +23 -42
  40. package/dist/types/src/types/lifecycle.ts +50 -0
  41. package/dist/types/src/types/logger.d.ts +6 -40
  42. package/dist/types/src/types/logger.ts +42 -0
  43. package/dist/types/src/types/openapi.d.ts +105 -222
  44. package/dist/types/src/types/openapi.ts +255 -0
  45. package/dist/types/src/types/query.d.ts +53 -161
  46. package/dist/types/src/types/query.ts +165 -0
  47. package/dist/types/src/types/utils.d.ts +83 -141
  48. package/dist/types/src/types/utils.ts +173 -0
  49. package/dist/types/src/types/validation.d.ts +17 -18
  50. package/dist/types/src/types/validation.ts +20 -0
  51. package/dist/types/src/types/variadic.d.ts +42 -444
  52. package/dist/types/src/types/variadic.ts +447 -0
  53. package/docs/classes/Benchmark.html +2 -2
  54. package/docs/classes/CalendarDate.html +2 -2
  55. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  56. package/docs/classes/Decorators.html +19 -19
  57. package/docs/classes/Dream.html +132 -132
  58. package/docs/classes/DreamApp.html +4 -4
  59. package/docs/classes/DreamBin.html +2 -2
  60. package/docs/classes/DreamCLI.html +4 -4
  61. package/docs/classes/DreamImporter.html +2 -2
  62. package/docs/classes/DreamLogos.html +2 -2
  63. package/docs/classes/DreamMigrationHelpers.html +7 -7
  64. package/docs/classes/DreamSerializer.html +2 -2
  65. package/docs/classes/DreamTransaction.html +2 -2
  66. package/docs/classes/Encrypt.html +2 -2
  67. package/docs/classes/Env.html +2 -2
  68. package/docs/classes/GlobalNameNotSet.html +3 -3
  69. package/docs/classes/NonLoadedAssociation.html +3 -3
  70. package/docs/classes/Query.html +52 -52
  71. package/docs/classes/Range.html +2 -2
  72. package/docs/classes/RecordNotFound.html +3 -3
  73. package/docs/classes/ValidationError.html +3 -3
  74. package/docs/functions/Attribute.html +1 -1
  75. package/docs/functions/RendersMany.html +1 -1
  76. package/docs/functions/RendersOne.html +1 -1
  77. package/docs/functions/ReplicaSafe.html +1 -1
  78. package/docs/functions/STI.html +1 -1
  79. package/docs/functions/SoftDelete.html +1 -1
  80. package/docs/functions/camelize.html +1 -1
  81. package/docs/functions/capitalize.html +1 -1
  82. package/docs/functions/closeAllDbConnections.html +1 -1
  83. package/docs/functions/compact.html +1 -1
  84. package/docs/functions/dreamDbConnections.html +1 -1
  85. package/docs/functions/dreamPath.html +1 -1
  86. package/docs/functions/generateDream.html +1 -1
  87. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  88. package/docs/functions/hyphenize.html +1 -1
  89. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
  90. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  91. package/docs/functions/isEmpty.html +1 -1
  92. package/docs/functions/loadRepl.html +1 -1
  93. package/docs/functions/lookupClassByGlobalName.html +1 -1
  94. package/docs/functions/pascalize.html +1 -1
  95. package/docs/functions/pgErrorType.html +1 -1
  96. package/docs/functions/range-1.html +1 -1
  97. package/docs/functions/relativeDreamPath.html +1 -1
  98. package/docs/functions/round.html +1 -1
  99. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  100. package/docs/functions/sharedPathPrefix.html +1 -1
  101. package/docs/functions/snakeify.html +1 -1
  102. package/docs/functions/sort.html +1 -1
  103. package/docs/functions/sortBy.html +1 -1
  104. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  105. package/docs/functions/uncapitalize.html +1 -1
  106. package/docs/functions/uniq.html +1 -1
  107. package/docs/functions/untypedDb.html +1 -1
  108. package/docs/functions/validateColumn.html +1 -1
  109. package/docs/functions/validateTable.html +1 -1
  110. package/docs/interfaces/AttributeStatement.html +2 -2
  111. package/docs/interfaces/DecoratorContext.html +2 -2
  112. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  113. package/docs/interfaces/DreamAppOpts.html +2 -2
  114. package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
  115. package/docs/interfaces/EncryptOptions.html +2 -2
  116. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  117. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  118. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  119. package/docs/types/Camelized.html +1 -1
  120. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  121. package/docs/types/DateTime.html +1 -1
  122. package/docs/types/DbConnectionType.html +1 -1
  123. package/docs/types/DreamAssociationMetadata.html +1 -1
  124. package/docs/types/DreamAttributes.html +1 -1
  125. package/docs/types/DreamClassColumn.html +1 -1
  126. package/docs/types/DreamColumn.html +1 -1
  127. package/docs/types/DreamColumnNames.html +1 -1
  128. package/docs/types/DreamLogLevel.html +1 -1
  129. package/docs/types/DreamLogger.html +1 -1
  130. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  131. package/docs/types/DreamParamSafeAttributes.html +1 -1
  132. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  133. package/docs/types/DreamSerializerKey.html +1 -1
  134. package/docs/types/DreamSerializers.html +1 -1
  135. package/docs/types/DreamTableSchema.html +1 -1
  136. package/docs/types/DreamVirtualColumns.html +1 -1
  137. package/docs/types/EncryptAlgorithm.html +1 -1
  138. package/docs/types/Hyphenized.html +1 -1
  139. package/docs/types/IdType.html +1 -1
  140. package/docs/types/OpenapiAllTypes.html +1 -1
  141. package/docs/types/OpenapiFormats.html +1 -1
  142. package/docs/types/OpenapiNumberFormats.html +1 -1
  143. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  144. package/docs/types/OpenapiSchemaArray.html +1 -1
  145. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  146. package/docs/types/OpenapiSchemaBase.html +1 -1
  147. package/docs/types/OpenapiSchemaBody.html +1 -1
  148. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  149. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  150. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  151. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  152. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  153. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  154. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  155. package/docs/types/OpenapiSchemaInteger.html +1 -1
  156. package/docs/types/OpenapiSchemaNull.html +1 -1
  157. package/docs/types/OpenapiSchemaNumber.html +1 -1
  158. package/docs/types/OpenapiSchemaObject.html +1 -1
  159. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  160. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  161. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  162. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  163. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  164. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  165. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  166. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  167. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  168. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  169. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  170. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  171. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  172. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  173. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  174. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  175. package/docs/types/OpenapiSchemaString.html +1 -1
  176. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  177. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  178. package/docs/types/OpenapiTypeField.html +1 -1
  179. package/docs/types/Pascalized.html +1 -1
  180. package/docs/types/PrimaryKeyType.html +1 -1
  181. package/docs/types/RoundingPrecision.html +1 -1
  182. package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
  183. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
  184. package/docs/types/SerializableDreamOrViewModel.html +1 -1
  185. package/docs/types/SerializableTypes.html +1 -1
  186. package/docs/types/Snakeified.html +1 -1
  187. package/docs/types/Timestamp.html +1 -1
  188. package/docs/types/UpdateableAssociationProperties.html +1 -1
  189. package/docs/types/UpdateableProperties.html +1 -1
  190. package/docs/types/ValidationType.html +1 -1
  191. package/docs/types/ViewModelSerializerKey.html +1 -1
  192. package/docs/types/WhereStatementForDream.html +1 -1
  193. package/docs/types/WhereStatementForDreamClass.html +1 -1
  194. package/docs/variables/DateTime-1.html +1 -1
  195. package/docs/variables/DreamConst.html +1 -1
  196. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  197. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  198. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  199. package/docs/variables/ops.html +1 -1
  200. package/docs/variables/primaryKeyTypes.html +1 -1
  201. package/package.json +1 -1
@@ -1,83 +1,73 @@
1
- export type Inc<T extends number> =
2
- // Check `T`'s value on every number from 0 to 31 and return the next value each time.
3
- // If it's out of scope, just return `never`.
4
- T extends keyof IncTable ? IncTable[T] : never
5
-
1
+ export type Inc<T extends number> = T extends keyof IncTable ? IncTable[T] : never;
6
2
  type IncTable = {
7
- 0: 1
8
- 1: 2
9
- 2: 3
10
- 3: 4
11
- 4: 5
12
- 5: 6
13
- 6: 7
14
- 7: 8
15
- 8: 9
16
- 9: 10
17
- 10: 11
18
- 11: 12
19
- 12: 13
20
- 13: 14
21
- 14: 15
22
- 15: 16
23
- 16: 17
24
- 17: 18
25
- 18: 19
26
- 19: 20
27
- 20: 21
28
- 21: 22
29
- 22: 23
30
- 23: 24
31
- 24: 25
32
- 25: 26
33
- 26: 27
34
- 27: 28
35
- 28: 29
36
- 29: 30
37
- 30: 31
38
- 31: 32
39
- }
40
-
41
- export type Decrement<T extends number> =
42
- // Check `T`'s value on every number from 0 to 31 and return the next value each time.
43
- // If it's out of scope, just return `never`.
44
- T extends keyof DecrementTable ? DecrementTable[T] : never
45
-
3
+ 0: 1;
4
+ 1: 2;
5
+ 2: 3;
6
+ 3: 4;
7
+ 4: 5;
8
+ 5: 6;
9
+ 6: 7;
10
+ 7: 8;
11
+ 8: 9;
12
+ 9: 10;
13
+ 10: 11;
14
+ 11: 12;
15
+ 12: 13;
16
+ 13: 14;
17
+ 14: 15;
18
+ 15: 16;
19
+ 16: 17;
20
+ 17: 18;
21
+ 18: 19;
22
+ 19: 20;
23
+ 20: 21;
24
+ 21: 22;
25
+ 22: 23;
26
+ 23: 24;
27
+ 24: 25;
28
+ 25: 26;
29
+ 26: 27;
30
+ 27: 28;
31
+ 28: 29;
32
+ 29: 30;
33
+ 30: 31;
34
+ 31: 32;
35
+ };
36
+ export type Decrement<T extends number> = T extends keyof DecrementTable ? DecrementTable[T] : never;
46
37
  type DecrementTable = {
47
- 0: -1
48
- 1: 0
49
- 2: 1
50
- 3: 2
51
- 4: 3
52
- 5: 4
53
- 6: 5
54
- 7: 6
55
- 8: 7
56
- 9: 8
57
- 10: 9
58
- 11: 10
59
- 12: 11
60
- 13: 12
61
- 14: 13
62
- 15: 15
63
- 16: 15
64
- 17: 16
65
- 18: 17
66
- 19: 18
67
- 20: 19
68
- 21: 20
69
- 22: 21
70
- 23: 22
71
- 24: 23
72
- 25: 24
73
- 26: 25
74
- 27: 26
75
- 28: 27
76
- 29: 28
77
- 30: 29
78
- 31: 30
79
- }
80
-
38
+ 0: -1;
39
+ 1: 0;
40
+ 2: 1;
41
+ 3: 2;
42
+ 4: 3;
43
+ 5: 4;
44
+ 6: 5;
45
+ 7: 6;
46
+ 8: 7;
47
+ 9: 8;
48
+ 10: 9;
49
+ 11: 10;
50
+ 12: 11;
51
+ 13: 12;
52
+ 14: 13;
53
+ 15: 15;
54
+ 16: 15;
55
+ 17: 16;
56
+ 18: 17;
57
+ 19: 18;
58
+ 20: 19;
59
+ 21: 20;
60
+ 22: 21;
61
+ 23: 22;
62
+ 24: 23;
63
+ 25: 24;
64
+ 26: 25;
65
+ 27: 26;
66
+ 28: 27;
67
+ 29: 28;
68
+ 30: 29;
69
+ 31: 30;
70
+ };
81
71
  /**
82
72
  *
83
73
  * Given two interfaces that define the same attributes, but with different types for the values,
@@ -107,67 +97,19 @@ type DecrementTable = {
107
97
  * ```
108
98
  * From https://stackoverflow.com/a/72375765/349332
109
99
  */
110
-
111
100
  export type MergeUnionOfRecordTypes<U extends Record<string, unknown>> = {
112
- [K in U extends unknown ? keyof U : never]: U extends unknown ? (K extends keyof U ? U[K] : never) : never
113
- }
114
-
115
- // UnionToIntersection
116
- //
117
- // takes a type like
118
- // { name: string } | { email: string }
119
- //
120
- // and turns it into
121
- // { name: string } & { email: string }
122
- //
123
- // ideally, this could be replaced by MergeUnionOfRecordTypes, but
124
- // that type is not working for my use case, so I have brought in this
125
- // type helper copied from:
126
- //
127
- // https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
128
- export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void
129
- ? I
130
- : never
131
-
132
- export type FilterInterface<Source, Condition> = Pick<
133
- Source,
134
- { [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source]
135
- >
136
-
137
- export type RejectInterface<Source, Condition> = Pick<
138
- Source,
139
- { [K in keyof Source]: Source[K] extends Condition ? never : K }[keyof Source]
140
- >
141
-
142
- // type T = Tail<[1, 2, 3]> // [2, 3]
143
- export type ReadonlyTail<T extends readonly any[]> = T extends readonly [any, ...infer Tail]
144
- ? Tail
145
- : readonly []
146
-
147
- export type NotReadonlyTail<T extends any[]> = T extends [any, ...infer Tail] ? Tail : []
148
-
149
- // type H = Head<[1, 2, 3]> // 1
150
- export type ReadonlyHead<T extends readonly any[]> = T extends readonly [infer Head, ...any]
151
- ? Head
152
- : undefined
153
- export type NotReadonlyHead<T extends readonly any[]> = T extends [infer Head, ...any] ? Head : undefined
154
-
155
- // type U = Unshift<[1, 2, 3], 0> // [0, 1, 2, 3]
156
- // export type Unshift<T extends readonly any[], E> = [E, ...T]
157
-
158
- // type L = Last<[1, 2, 3]> // 3
159
- // type L = Last<['a', 'b', 'c']> // 'c'
160
- // export type Last<T extends readonly any[]> = T[Decrement<T['length']>]
161
-
162
- export type FindInterfaceWithValue<T, Key, Value> =
163
- T extends Readonly<[infer First, ...infer Rest]>
164
- ? Key extends keyof First
165
- ? First[Key] extends never
166
- ? Value extends never
167
- ? First
168
- : FindInterfaceWithValue<Rest, Key, Value>
169
- : First[Key] extends Value
170
- ? First
171
- : FindInterfaceWithValue<Rest, Key, Value>
172
- : FindInterfaceWithValue<Rest, Key, Value>
173
- : never
101
+ [K in U extends unknown ? keyof U : never]: U extends unknown ? (K extends keyof U ? U[K] : never) : never;
102
+ };
103
+ export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
104
+ export type FilterInterface<Source, Condition> = Pick<Source, {
105
+ [K in keyof Source]: Source[K] extends Condition ? K : never;
106
+ }[keyof Source]>;
107
+ export type RejectInterface<Source, Condition> = Pick<Source, {
108
+ [K in keyof Source]: Source[K] extends Condition ? never : K;
109
+ }[keyof Source]>;
110
+ export type ReadonlyTail<T extends readonly any[]> = T extends readonly [any, ...infer Tail] ? Tail : readonly [];
111
+ export type NotReadonlyTail<T extends any[]> = T extends [any, ...infer Tail] ? Tail : [];
112
+ export type ReadonlyHead<T extends readonly any[]> = T extends readonly [infer Head, ...any] ? Head : undefined;
113
+ export type NotReadonlyHead<T extends readonly any[]> = T extends [infer Head, ...any] ? Head : undefined;
114
+ export type FindInterfaceWithValue<T, Key, Value> = T extends Readonly<[infer First, ...infer Rest]> ? Key extends keyof First ? First[Key] extends never ? Value extends never ? First : FindInterfaceWithValue<Rest, Key, Value> : First[Key] extends Value ? First : FindInterfaceWithValue<Rest, Key, Value> : FindInterfaceWithValue<Rest, Key, Value> : never;
115
+ export {};
@@ -0,0 +1,173 @@
1
+ export type Inc<T extends number> =
2
+ // Check `T`'s value on every number from 0 to 31 and return the next value each time.
3
+ // If it's out of scope, just return `never`.
4
+ T extends keyof IncTable ? IncTable[T] : never
5
+
6
+ type IncTable = {
7
+ 0: 1
8
+ 1: 2
9
+ 2: 3
10
+ 3: 4
11
+ 4: 5
12
+ 5: 6
13
+ 6: 7
14
+ 7: 8
15
+ 8: 9
16
+ 9: 10
17
+ 10: 11
18
+ 11: 12
19
+ 12: 13
20
+ 13: 14
21
+ 14: 15
22
+ 15: 16
23
+ 16: 17
24
+ 17: 18
25
+ 18: 19
26
+ 19: 20
27
+ 20: 21
28
+ 21: 22
29
+ 22: 23
30
+ 23: 24
31
+ 24: 25
32
+ 25: 26
33
+ 26: 27
34
+ 27: 28
35
+ 28: 29
36
+ 29: 30
37
+ 30: 31
38
+ 31: 32
39
+ }
40
+
41
+ export type Decrement<T extends number> =
42
+ // Check `T`'s value on every number from 0 to 31 and return the next value each time.
43
+ // If it's out of scope, just return `never`.
44
+ T extends keyof DecrementTable ? DecrementTable[T] : never
45
+
46
+ type DecrementTable = {
47
+ 0: -1
48
+ 1: 0
49
+ 2: 1
50
+ 3: 2
51
+ 4: 3
52
+ 5: 4
53
+ 6: 5
54
+ 7: 6
55
+ 8: 7
56
+ 9: 8
57
+ 10: 9
58
+ 11: 10
59
+ 12: 11
60
+ 13: 12
61
+ 14: 13
62
+ 15: 15
63
+ 16: 15
64
+ 17: 16
65
+ 18: 17
66
+ 19: 18
67
+ 20: 19
68
+ 21: 20
69
+ 22: 21
70
+ 23: 22
71
+ 24: 23
72
+ 25: 24
73
+ 26: 25
74
+ 27: 26
75
+ 28: 27
76
+ 29: 28
77
+ 30: 29
78
+ 31: 30
79
+ }
80
+
81
+ /**
82
+ *
83
+ * Given two interfaces that define the same attributes, but with different types for the values,
84
+ * create a new type that allows all of the types allowed for a particular key by either of the
85
+ * joined types.
86
+ *
87
+ * @example
88
+ * ```
89
+ * type A = {
90
+ * a: string
91
+ * c: 'hello'
92
+ * }
93
+ *
94
+ * type B = {
95
+ * b: number
96
+ * c: 'world'
97
+ * }
98
+ *
99
+ * type Combined = MergeUnionOfRecordTypes<A | B>
100
+ *
101
+ * // Combined is now equivalent to type {
102
+ * // a: string,
103
+ * // b: number,
104
+ * // c: 'hello' | 'world',
105
+ * // }
106
+ *
107
+ * ```
108
+ * From https://stackoverflow.com/a/72375765/349332
109
+ */
110
+
111
+ export type MergeUnionOfRecordTypes<U extends Record<string, unknown>> = {
112
+ [K in U extends unknown ? keyof U : never]: U extends unknown ? (K extends keyof U ? U[K] : never) : never
113
+ }
114
+
115
+ // UnionToIntersection
116
+ //
117
+ // takes a type like
118
+ // { name: string } | { email: string }
119
+ //
120
+ // and turns it into
121
+ // { name: string } & { email: string }
122
+ //
123
+ // ideally, this could be replaced by MergeUnionOfRecordTypes, but
124
+ // that type is not working for my use case, so I have brought in this
125
+ // type helper copied from:
126
+ //
127
+ // https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
128
+ export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void
129
+ ? I
130
+ : never
131
+
132
+ export type FilterInterface<Source, Condition> = Pick<
133
+ Source,
134
+ { [K in keyof Source]: Source[K] extends Condition ? K : never }[keyof Source]
135
+ >
136
+
137
+ export type RejectInterface<Source, Condition> = Pick<
138
+ Source,
139
+ { [K in keyof Source]: Source[K] extends Condition ? never : K }[keyof Source]
140
+ >
141
+
142
+ // type T = Tail<[1, 2, 3]> // [2, 3]
143
+ export type ReadonlyTail<T extends readonly any[]> = T extends readonly [any, ...infer Tail]
144
+ ? Tail
145
+ : readonly []
146
+
147
+ export type NotReadonlyTail<T extends any[]> = T extends [any, ...infer Tail] ? Tail : []
148
+
149
+ // type H = Head<[1, 2, 3]> // 1
150
+ export type ReadonlyHead<T extends readonly any[]> = T extends readonly [infer Head, ...any]
151
+ ? Head
152
+ : undefined
153
+ export type NotReadonlyHead<T extends readonly any[]> = T extends [infer Head, ...any] ? Head : undefined
154
+
155
+ // type U = Unshift<[1, 2, 3], 0> // [0, 1, 2, 3]
156
+ // export type Unshift<T extends readonly any[], E> = [E, ...T]
157
+
158
+ // type L = Last<[1, 2, 3]> // 3
159
+ // type L = Last<['a', 'b', 'c']> // 'c'
160
+ // export type Last<T extends readonly any[]> = T[Decrement<T['length']>]
161
+
162
+ export type FindInterfaceWithValue<T, Key, Value> =
163
+ T extends Readonly<[infer First, ...infer Rest]>
164
+ ? Key extends keyof First
165
+ ? First[Key] extends never
166
+ ? Value extends never
167
+ ? First
168
+ : FindInterfaceWithValue<Rest, Key, Value>
169
+ : First[Key] extends Value
170
+ ? First
171
+ : FindInterfaceWithValue<Rest, Key, Value>
172
+ : FindInterfaceWithValue<Rest, Key, Value>
173
+ : never
@@ -1,20 +1,19 @@
1
1
  export interface ValidationStatement {
2
- type: ValidationType
3
- column: string
4
- options?: {
5
- presence?: object
6
- numericality?: {
7
- max?: number
8
- min?: number
9
- }
10
- contains?: {
11
- value: string | RegExp
12
- }
13
- length?: {
14
- min: number
15
- max?: number
16
- }
17
- }
2
+ type: ValidationType;
3
+ column: string;
4
+ options?: {
5
+ presence?: object;
6
+ numericality?: {
7
+ max?: number;
8
+ min?: number;
9
+ };
10
+ contains?: {
11
+ value: string | RegExp;
12
+ };
13
+ length?: {
14
+ min: number;
15
+ max?: number;
16
+ };
17
+ };
18
18
  }
19
-
20
- export type ValidationType = 'presence' | 'numericality' | 'contains' | 'length' | 'requiredBelongsTo'
19
+ export type ValidationType = 'presence' | 'numericality' | 'contains' | 'length' | 'requiredBelongsTo';
@@ -0,0 +1,20 @@
1
+ export interface ValidationStatement {
2
+ type: ValidationType
3
+ column: string
4
+ options?: {
5
+ presence?: object
6
+ numericality?: {
7
+ max?: number
8
+ min?: number
9
+ }
10
+ contains?: {
11
+ value: string | RegExp
12
+ }
13
+ length?: {
14
+ min: number
15
+ max?: number
16
+ }
17
+ }
18
+ }
19
+
20
+ export type ValidationType = 'presence' | 'numericality' | 'contains' | 'length' | 'requiredBelongsTo'