@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.
- package/dist/cjs/src/types/associations/belongsTo.js +2 -0
- package/dist/cjs/src/types/associations/hasMany.js +2 -0
- package/dist/cjs/src/types/associations/hasOne.js +2 -0
- package/dist/cjs/src/types/associations/shared.js +2 -0
- package/dist/cjs/src/types/db.js +2 -0
- package/dist/cjs/src/types/dream.js +2 -0
- package/dist/cjs/src/types/lifecycle.js +2 -0
- package/dist/cjs/src/types/logger.js +2 -0
- package/dist/cjs/src/types/openapi.js +2 -0
- package/dist/cjs/src/types/query.js +2 -0
- package/dist/cjs/src/types/utils.js +2 -0
- package/dist/cjs/src/types/validation.js +2 -0
- package/dist/cjs/src/types/variadic.js +2 -0
- package/dist/esm/src/types/associations/belongsTo.js +1 -0
- package/dist/esm/src/types/associations/hasMany.js +1 -0
- package/dist/esm/src/types/associations/hasOne.js +1 -0
- package/dist/esm/src/types/associations/shared.js +1 -0
- package/dist/esm/src/types/db.js +1 -0
- package/dist/esm/src/types/dream.js +1 -0
- package/dist/esm/src/types/lifecycle.js +1 -0
- package/dist/esm/src/types/logger.js +1 -0
- package/dist/esm/src/types/openapi.js +1 -0
- package/dist/esm/src/types/query.js +1 -0
- package/dist/esm/src/types/utils.js +1 -0
- package/dist/esm/src/types/validation.js +1 -0
- package/dist/esm/src/types/variadic.js +1 -0
- package/dist/types/src/types/associations/belongsTo.d.ts +28 -73
- package/dist/types/src/types/associations/belongsTo.ts +76 -0
- package/dist/types/src/types/associations/hasMany.d.ts +15 -79
- package/dist/types/src/types/associations/hasMany.ts +80 -0
- package/dist/types/src/types/associations/hasOne.d.ts +8 -26
- package/dist/types/src/types/associations/hasOne.ts +26 -0
- package/dist/types/src/types/associations/shared.d.ts +98 -444
- package/dist/types/src/types/associations/shared.ts +450 -0
- package/dist/types/src/types/db.d.ts +9 -14
- package/dist/types/src/types/db.ts +14 -0
- package/dist/types/src/types/dream.d.ts +124 -510
- package/dist/types/src/types/dream.ts +521 -0
- package/dist/types/src/types/lifecycle.d.ts +23 -42
- package/dist/types/src/types/lifecycle.ts +50 -0
- package/dist/types/src/types/logger.d.ts +6 -40
- package/dist/types/src/types/logger.ts +42 -0
- package/dist/types/src/types/openapi.d.ts +105 -222
- package/dist/types/src/types/openapi.ts +255 -0
- package/dist/types/src/types/query.d.ts +53 -161
- package/dist/types/src/types/query.ts +165 -0
- package/dist/types/src/types/utils.d.ts +83 -141
- package/dist/types/src/types/utils.ts +173 -0
- package/dist/types/src/types/validation.d.ts +17 -18
- package/dist/types/src/types/validation.ts +20 -0
- package/dist/types/src/types/variadic.d.ts +42 -444
- package/dist/types/src/types/variadic.ts +447 -0
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +132 -132
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializer.html +2 -2
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/Query.html +52 -52
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/Attribute.html +1 -1
- package/docs/functions/RendersMany.html +1 -1
- package/docs/functions/RendersOne.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/AttributeStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
- package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
- package/docs/types/SerializableDreamOrViewModel.html +1 -1
- package/docs/types/SerializableTypes.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModelSerializerKey.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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'
|