@rvoh/dream 0.40.3 → 0.40.5
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/Dream.js +64 -12
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +46 -6
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/cjs/src/dream/LoadBuilder.js +3 -3
- package/dist/cjs/src/dream/internal/associations/createAssociation.js +1 -6
- package/dist/cjs/src/dream/internal/findOrCreateBy.js +16 -0
- package/dist/cjs/src/dream/internal/updateOrCreateBy.js +18 -0
- package/dist/cjs/src/errors/CreateOrUpdateByFailedToCreateAndUpdate.js +18 -0
- 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/Dream.js +64 -12
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +46 -6
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/esm/src/dream/LoadBuilder.js +3 -3
- package/dist/esm/src/dream/internal/associations/createAssociation.js +1 -6
- package/dist/esm/src/dream/internal/findOrCreateBy.js +13 -0
- package/dist/esm/src/dream/internal/updateOrCreateBy.js +15 -0
- package/dist/esm/src/errors/CreateOrUpdateByFailedToCreateAndUpdate.js +15 -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/Dream.d.ts +42 -9
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +72 -37
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +3 -3
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +2 -2
- package/dist/types/src/dream/LoadBuilder.d.ts +2 -2
- package/dist/types/src/dream/Query.d.ts +1 -1
- package/dist/types/src/dream/internal/findOrCreateBy.d.ts +4 -0
- package/dist/types/src/dream/internal/updateOrCreateBy.d.ts +4 -0
- package/dist/types/src/errors/CreateOrUpdateByFailedToCreateAndUpdate.d.ts +6 -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 +130 -509
- package/dist/types/src/types/dream.ts +530 -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/assets/search.js +1 -1
- 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 +205 -185
- 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 +53 -53
- 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
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { ColumnType, Updateable } from 'kysely'
|
|
2
|
+
import { STI_SCOPE_NAME } from '../decorators/class/STI.js'
|
|
3
|
+
import Dream from '../Dream.js'
|
|
4
|
+
import { primaryKeyTypes, TRIGRAM_OPERATORS } from '../dream/constants.js'
|
|
5
|
+
import CalendarDate from '../helpers/CalendarDate.js'
|
|
6
|
+
import { DateTime } from '../helpers/DateTime.js'
|
|
7
|
+
import OpsStatement from '../ops/ops-statement.js'
|
|
8
|
+
import DreamSerializer from '../serializer/index.js'
|
|
9
|
+
import {
|
|
10
|
+
AssociatedModelParam,
|
|
11
|
+
AssociationStatement,
|
|
12
|
+
OnStatementForAssociation,
|
|
13
|
+
WhereStatement,
|
|
14
|
+
} from './associations/shared.js'
|
|
15
|
+
import { AssociationTableNames } from './db.js'
|
|
16
|
+
import { FindEachOpts } from './query.js'
|
|
17
|
+
import { FilterInterface, Inc } from './utils.js'
|
|
18
|
+
import { AliasedSchemaAssociation } from './variadic.js'
|
|
19
|
+
|
|
20
|
+
export type PrimaryKeyType = (typeof primaryKeyTypes)[number]
|
|
21
|
+
|
|
22
|
+
export type IdType = string | number | bigint
|
|
23
|
+
export type Timestamp = ColumnType<DateTime | CalendarDate>
|
|
24
|
+
|
|
25
|
+
export type MAX_VARIADIC_DEPTH = 25
|
|
26
|
+
export type TrigramOperator = (typeof TRIGRAM_OPERATORS)[number]
|
|
27
|
+
export type OrderDir = 'asc' | 'desc'
|
|
28
|
+
|
|
29
|
+
export interface SortableOptions<T extends Dream> {
|
|
30
|
+
scope?:
|
|
31
|
+
| keyof DreamBelongsToAssociationMetadata<T>
|
|
32
|
+
| DreamColumnNames<T>
|
|
33
|
+
| (keyof DreamBelongsToAssociationMetadata<T> | DreamColumnNames<T>)[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PrimaryKeyForFind<
|
|
37
|
+
I extends Dream,
|
|
38
|
+
Schema extends I['schema'] = I['schema'],
|
|
39
|
+
TableName extends keyof Schema = I['table'] & keyof Schema,
|
|
40
|
+
> =
|
|
41
|
+
| Schema[TableName]['columns'][I['primaryKey'] & keyof Schema[TableName]['columns']]['coercedType']
|
|
42
|
+
| string
|
|
43
|
+
| null
|
|
44
|
+
| undefined
|
|
45
|
+
|
|
46
|
+
export type DreamColumnNames<
|
|
47
|
+
DreamInstance extends Dream,
|
|
48
|
+
DB = DreamInstance['DB'],
|
|
49
|
+
TableName extends keyof DB = DreamInstance['table'] & keyof DB,
|
|
50
|
+
Table extends DB[keyof DB] = DB[TableName],
|
|
51
|
+
> = keyof Table & string
|
|
52
|
+
|
|
53
|
+
export type DreamParamSafeColumnNames<
|
|
54
|
+
DreamInstance extends Dream,
|
|
55
|
+
BelongsToForeignKeys = DreamBelongsToForeignKeys<DreamInstance>,
|
|
56
|
+
Schema = DreamInstance['schema'],
|
|
57
|
+
TableSchema = Schema[DreamInstance['table'] & keyof Schema],
|
|
58
|
+
> = Exclude<
|
|
59
|
+
DreamColumnNames<DreamInstance>,
|
|
60
|
+
| BelongsToForeignKeys
|
|
61
|
+
| DreamVirtualColumns<DreamInstance>
|
|
62
|
+
| TableSchema['primaryKey' & keyof TableSchema]
|
|
63
|
+
| TableSchema['createdAtField' & keyof TableSchema]
|
|
64
|
+
| TableSchema['updatedAtField' & keyof TableSchema]
|
|
65
|
+
| TableSchema['deletedAtField' & keyof TableSchema]
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
export type DreamBelongsToForeignKeys<
|
|
69
|
+
DreamInstance extends Dream,
|
|
70
|
+
Schema = DreamInstance['schema'],
|
|
71
|
+
TableSchema = Schema[DreamInstance['table'] & keyof Schema],
|
|
72
|
+
AssociationSchema = TableSchema['associations' & keyof TableSchema],
|
|
73
|
+
BelongsToAssociationSchema = AssociationSchema[keyof DreamBelongsToAssociationMetadata<DreamInstance> &
|
|
74
|
+
keyof AssociationSchema],
|
|
75
|
+
BelongsToForeignKeys = Exclude<
|
|
76
|
+
BelongsToAssociationSchema['foreignKey' & keyof BelongsToAssociationSchema],
|
|
77
|
+
null
|
|
78
|
+
>,
|
|
79
|
+
> = BelongsToForeignKeys
|
|
80
|
+
|
|
81
|
+
export type DreamClassColumnNames<
|
|
82
|
+
DreamClass extends typeof Dream,
|
|
83
|
+
DreamInstance extends InstanceType<DreamClass> = InstanceType<DreamClass>,
|
|
84
|
+
DB = DreamInstance['DB'],
|
|
85
|
+
TableName extends keyof DB = DreamInstance['table'] & keyof DB,
|
|
86
|
+
Table extends DB[keyof DB] = DB[TableName],
|
|
87
|
+
> = keyof Table & string
|
|
88
|
+
|
|
89
|
+
export type TableColumnNames<
|
|
90
|
+
DB,
|
|
91
|
+
TableName extends keyof DB,
|
|
92
|
+
Table extends DB[keyof DB] = DB[TableName],
|
|
93
|
+
> = keyof Table & string
|
|
94
|
+
|
|
95
|
+
export type DreamColumn<
|
|
96
|
+
DreamInstance extends Dream,
|
|
97
|
+
Column extends keyof Attrs,
|
|
98
|
+
Attrs = DreamAttributes<DreamInstance>,
|
|
99
|
+
> = Attrs[Column & keyof Attrs]
|
|
100
|
+
|
|
101
|
+
export type DreamClassColumn<
|
|
102
|
+
DreamClass extends typeof Dream,
|
|
103
|
+
Column extends keyof DreamAttributes<DreamInstance>,
|
|
104
|
+
DreamInstance extends InstanceType<DreamClass> = InstanceType<DreamClass>,
|
|
105
|
+
> = DreamColumn<DreamInstance, Column>
|
|
106
|
+
|
|
107
|
+
export type AssociationNameToDream<
|
|
108
|
+
DreamInstance extends Dream,
|
|
109
|
+
AssociationName extends DreamAssociationNames<DreamInstance>,
|
|
110
|
+
PossibleArrayAssociationType = DreamInstance[AssociationName & keyof DreamInstance],
|
|
111
|
+
AssociationType extends Dream = PossibleArrayAssociationType extends (infer ElementType)[]
|
|
112
|
+
? ElementType extends Dream
|
|
113
|
+
? ElementType
|
|
114
|
+
: never
|
|
115
|
+
: PossibleArrayAssociationType extends Dream
|
|
116
|
+
? PossibleArrayAssociationType
|
|
117
|
+
: never,
|
|
118
|
+
> = AssociationType
|
|
119
|
+
|
|
120
|
+
export type DreamAssociationMetadata<
|
|
121
|
+
DreamInstance extends Dream,
|
|
122
|
+
Schema = DreamInstance['schema'],
|
|
123
|
+
AssociationMetadata = Schema[DreamInstance['table'] & keyof Schema]['associations' &
|
|
124
|
+
keyof Schema[DreamInstance['table'] & keyof Schema]],
|
|
125
|
+
> = AssociationMetadata
|
|
126
|
+
|
|
127
|
+
export type DreamAssociationNamesWithoutRequiredOnClauses<
|
|
128
|
+
DreamInstance extends Dream,
|
|
129
|
+
SchemaAssociations = DreamAssociationMetadata<DreamInstance>,
|
|
130
|
+
SchemaTypeInterface = {
|
|
131
|
+
[K in keyof SchemaAssociations]: SchemaAssociations[K]['requiredOnClauses' & keyof SchemaAssociations[K]]
|
|
132
|
+
},
|
|
133
|
+
RequiredOnClauses = keyof FilterInterface<SchemaTypeInterface, null> & string,
|
|
134
|
+
> = RequiredOnClauses
|
|
135
|
+
|
|
136
|
+
export type DreamAssociationNames<
|
|
137
|
+
DreamInstance extends Dream,
|
|
138
|
+
SchemaAssociations = DreamAssociationMetadata<DreamInstance>,
|
|
139
|
+
> = keyof SchemaAssociations
|
|
140
|
+
|
|
141
|
+
type VirtualColumnsForTable<
|
|
142
|
+
Schema,
|
|
143
|
+
TableName extends keyof Schema,
|
|
144
|
+
TableSchema = Schema[TableName],
|
|
145
|
+
> = TableSchema['virtualColumns' & keyof TableSchema]
|
|
146
|
+
|
|
147
|
+
export type DreamVirtualColumns<
|
|
148
|
+
DreamInstance extends Dream,
|
|
149
|
+
Schema = DreamInstance['schema'],
|
|
150
|
+
> = VirtualColumnsForTable<Schema, DreamInstance['table'] & keyof Schema>
|
|
151
|
+
|
|
152
|
+
export type DreamBelongsToAssociationMetadata<
|
|
153
|
+
DreamInstance extends Dream,
|
|
154
|
+
SchemaAssociations = DreamAssociationMetadata<DreamInstance>,
|
|
155
|
+
SchemaTypeInterface = {
|
|
156
|
+
[K in keyof SchemaAssociations]: SchemaAssociations[K]['type' & keyof SchemaAssociations[K]]
|
|
157
|
+
},
|
|
158
|
+
BelongsToKeys = keyof FilterInterface<SchemaTypeInterface, 'BelongsTo'> & string,
|
|
159
|
+
TypeRecord = { [K in BelongsToKeys & string]: SchemaAssociations[K & keyof SchemaAssociations] },
|
|
160
|
+
> = TypeRecord
|
|
161
|
+
|
|
162
|
+
export type DreamAttributes<
|
|
163
|
+
DreamInstance extends Dream,
|
|
164
|
+
Schema = DreamInstance['schema'],
|
|
165
|
+
SchemaColumns = Schema[DreamInstance['table'] & keyof Schema]['columns' &
|
|
166
|
+
keyof Schema[DreamInstance['table'] & keyof Schema]],
|
|
167
|
+
> = {
|
|
168
|
+
-readonly [K in keyof SchemaColumns]: SchemaColumns[K]['coercedType' & keyof SchemaColumns[K]]
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type DreamAttributeDbTypes<
|
|
172
|
+
DreamInstance extends Dream,
|
|
173
|
+
Schema = DreamInstance['schema'],
|
|
174
|
+
SchemaColumns = Schema[DreamInstance['table'] & keyof Schema]['columns' &
|
|
175
|
+
keyof Schema[DreamInstance['table'] & keyof Schema]],
|
|
176
|
+
> = {
|
|
177
|
+
-readonly [K in keyof SchemaColumns]: SchemaColumns[K]['dbType' & keyof SchemaColumns[K]]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type DreamParamSafeAttributes<DreamInstance extends Dream> = {
|
|
181
|
+
[K in keyof DreamAttributes<DreamInstance> &
|
|
182
|
+
DreamParamSafeColumnNames<DreamInstance>]: DreamAttributes<DreamInstance>[K]
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type DreamTableSchema<DreamInstance extends Dream> = Updateable<
|
|
186
|
+
DreamInstance['DB'][DreamInstance['table']]
|
|
187
|
+
>
|
|
188
|
+
|
|
189
|
+
export type TableColumnType<
|
|
190
|
+
Schema,
|
|
191
|
+
TableName,
|
|
192
|
+
Column,
|
|
193
|
+
TableSchema extends Schema[TableName & keyof Schema] = Schema[TableName & keyof Schema],
|
|
194
|
+
TableColumns extends TableSchema['columns' & keyof TableSchema] = TableSchema['columns' &
|
|
195
|
+
keyof TableSchema],
|
|
196
|
+
TableColumnMetadata extends TableColumns[Column & keyof TableColumns] = TableColumns[Column &
|
|
197
|
+
keyof TableColumns],
|
|
198
|
+
ColumnType extends TableColumnMetadata['coercedType' &
|
|
199
|
+
keyof TableColumnMetadata] = TableColumnMetadata['coercedType' & keyof TableColumnMetadata],
|
|
200
|
+
> = ColumnType
|
|
201
|
+
|
|
202
|
+
export type TableColumnEnumTypeArray<
|
|
203
|
+
Schema,
|
|
204
|
+
TableName,
|
|
205
|
+
Column,
|
|
206
|
+
TableSchema extends Schema[TableName & keyof Schema] = Schema[TableName & keyof Schema],
|
|
207
|
+
TableColumns extends TableSchema['columns' & keyof TableSchema] = TableSchema['columns' &
|
|
208
|
+
keyof TableSchema],
|
|
209
|
+
TableColumnMetadata extends TableColumns[Column & keyof TableColumns] = TableColumns[Column &
|
|
210
|
+
keyof TableColumns],
|
|
211
|
+
EnumTypeCandidate = TableColumnMetadata['enumArrayType' & keyof TableColumnMetadata],
|
|
212
|
+
EnumTypeArray extends string[] | null = EnumTypeCandidate extends null
|
|
213
|
+
? null
|
|
214
|
+
: EnumTypeCandidate extends undefined
|
|
215
|
+
? null
|
|
216
|
+
: EnumTypeCandidate extends string[]
|
|
217
|
+
? EnumTypeCandidate
|
|
218
|
+
: never,
|
|
219
|
+
> = EnumTypeArray
|
|
220
|
+
|
|
221
|
+
///////////////////////////
|
|
222
|
+
// Association type helpers
|
|
223
|
+
///////////////////////////
|
|
224
|
+
type AssociationMetadataForTable<Schema, TableName extends keyof Schema> = Schema[TableName]['associations' &
|
|
225
|
+
keyof Schema[TableName]]
|
|
226
|
+
|
|
227
|
+
export type AssociationNamesForTable<Schema, TableName extends keyof Schema> =
|
|
228
|
+
| keyof AssociationMetadataForTable<Schema, TableName>
|
|
229
|
+
| AliasedSchemaAssociation<Schema, TableName>
|
|
230
|
+
|
|
231
|
+
type MetadataForAssociation<
|
|
232
|
+
Schema,
|
|
233
|
+
TableName extends keyof Schema,
|
|
234
|
+
AssociationName,
|
|
235
|
+
AssociationMetadata = AssociationMetadataForTable<Schema, TableName>,
|
|
236
|
+
> = AssociationMetadata[AssociationName & keyof AssociationMetadata]
|
|
237
|
+
|
|
238
|
+
export type AssociationTableName<
|
|
239
|
+
Schema,
|
|
240
|
+
TableName extends keyof Schema,
|
|
241
|
+
AssociationName,
|
|
242
|
+
AssociationData = MetadataForAssociation<Schema, TableName, AssociationName>,
|
|
243
|
+
> = (AssociationData['tables' & keyof AssociationData] & any[])[0] & keyof Schema
|
|
244
|
+
|
|
245
|
+
export type JoinAndStatements<
|
|
246
|
+
DB,
|
|
247
|
+
Schema,
|
|
248
|
+
TableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB,
|
|
249
|
+
RequiredOnClauseKeysForThisAssociation,
|
|
250
|
+
> = RequiredOnClauseKeysForThisAssociation extends null
|
|
251
|
+
? {
|
|
252
|
+
and?: WhereStatement<DB, Schema, TableName>
|
|
253
|
+
andNot?: WhereStatement<DB, Schema, TableName>
|
|
254
|
+
// andNot?: WhereStatementWithoutSimilarityClauses<DB, Schema, TableName>
|
|
255
|
+
andAny?: WhereStatement<DB, Schema, TableName>[]
|
|
256
|
+
// andAny?: WhereStatementWithoutSimilarityClauses<DB, Schema, TableName>[]
|
|
257
|
+
}
|
|
258
|
+
: RequiredOnClauseKeysForThisAssociation extends string[]
|
|
259
|
+
? {
|
|
260
|
+
and: OnStatementForAssociation<DB, Schema, TableName, RequiredOnClauseKeysForThisAssociation>
|
|
261
|
+
andNot?: WhereStatement<DB, Schema, TableName>
|
|
262
|
+
// andNot?: WhereStatementWithoutSimilarityClauses<DB, Schema, TableName>
|
|
263
|
+
andAny?: WhereStatement<DB, Schema, TableName>[]
|
|
264
|
+
// andAny?: WhereStatementWithoutSimilarityClauses<DB, Schema, TableName>[]
|
|
265
|
+
}
|
|
266
|
+
: never
|
|
267
|
+
////////////////////////////////
|
|
268
|
+
// end: Association type helpers
|
|
269
|
+
////////////////////////////////
|
|
270
|
+
|
|
271
|
+
export type UpdateablePropertiesForClass<
|
|
272
|
+
DreamClass extends typeof Dream,
|
|
273
|
+
TableName extends AssociationTableNames<
|
|
274
|
+
InstanceType<DreamClass>['DB'],
|
|
275
|
+
InstanceType<DreamClass>['schema']
|
|
276
|
+
> &
|
|
277
|
+
InstanceType<DreamClass>['table'] = InstanceType<DreamClass>['table'],
|
|
278
|
+
VirtualColumns = DreamVirtualColumns<InstanceType<DreamClass>>,
|
|
279
|
+
> = Partial<
|
|
280
|
+
Updateable<InstanceType<DreamClass>['DB'][TableName]> &
|
|
281
|
+
(VirtualColumns extends readonly any[] ? Record<VirtualColumns[number], any> : object) &
|
|
282
|
+
(AssociatedModelParam<InstanceType<DreamClass>> extends never
|
|
283
|
+
? object
|
|
284
|
+
: AssociatedModelParam<InstanceType<DreamClass>>)
|
|
285
|
+
>
|
|
286
|
+
|
|
287
|
+
export type UpdateableAssociationProperties<
|
|
288
|
+
DreamInstance extends Dream,
|
|
289
|
+
AssociationClass extends Dream,
|
|
290
|
+
Schema = DreamInstance['schema'],
|
|
291
|
+
AssociationTableName extends AssociationTableNames<DreamInstance['DB'], DreamInstance['schema']> &
|
|
292
|
+
keyof DreamInstance['DB'] = AssociationClass['table'],
|
|
293
|
+
VirtualColumns = VirtualColumnsForTable<Schema, AssociationTableName>,
|
|
294
|
+
> = Partial<
|
|
295
|
+
Updateable<DreamInstance['DB'][AssociationTableName]> &
|
|
296
|
+
(VirtualColumns extends readonly any[] ? Record<VirtualColumns[number], any> : object) &
|
|
297
|
+
(AssociatedModelParam<AssociationClass> extends never ? object : AssociatedModelParam<AssociationClass>)
|
|
298
|
+
>
|
|
299
|
+
|
|
300
|
+
export type AttributeKeys<
|
|
301
|
+
I extends Dream,
|
|
302
|
+
TableName extends AssociationTableNames<I['DB'], I['schema']> & I['table'] = I['table'],
|
|
303
|
+
VirtualColumns = DreamVirtualColumns<I>,
|
|
304
|
+
> = keyof (Updateable<I['DB'][TableName]> &
|
|
305
|
+
(VirtualColumns extends readonly any[] ? Record<VirtualColumns[number], any> : object))
|
|
306
|
+
|
|
307
|
+
export type UpdateableProperties<
|
|
308
|
+
I extends Dream,
|
|
309
|
+
TableName extends AssociationTableNames<I['DB'], I['schema']> & I['table'] = I['table'],
|
|
310
|
+
VirtualColumns = DreamVirtualColumns<I>,
|
|
311
|
+
> = Partial<
|
|
312
|
+
Updateable<I['DB'][TableName]> &
|
|
313
|
+
(VirtualColumns extends readonly any[] ? Record<VirtualColumns[number], any> : object) &
|
|
314
|
+
(AssociatedModelParam<I> extends never ? object : AssociatedModelParam<I>)
|
|
315
|
+
>
|
|
316
|
+
|
|
317
|
+
export interface CreateOrFindByExtraOpts<T extends typeof Dream> {
|
|
318
|
+
createWith?: UpdateablePropertiesForClass<T>
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface UpdateOrCreateByExtraOpts<T extends typeof Dream> {
|
|
322
|
+
with?: UpdateablePropertiesForClass<T>
|
|
323
|
+
skipHooks?: boolean
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Model global names and tables
|
|
327
|
+
export type TableNameForGlobalModelName<
|
|
328
|
+
I extends Dream,
|
|
329
|
+
GMN extends keyof GlobalModelNameTableMap<I>,
|
|
330
|
+
> = GlobalModelNameTableMap<I>[GMN]
|
|
331
|
+
|
|
332
|
+
export type GlobalModelNames<I extends Dream> = keyof GlobalModelNameTableMap<I>
|
|
333
|
+
|
|
334
|
+
export type GlobalModelNameTableMap<
|
|
335
|
+
I extends Dream,
|
|
336
|
+
GlobalSchema = I['globalSchema'],
|
|
337
|
+
GlobalNames = GlobalSchema['globalNames' & keyof GlobalSchema],
|
|
338
|
+
> = GlobalNames['models' & keyof GlobalNames]
|
|
339
|
+
// end:Model global names and tables
|
|
340
|
+
|
|
341
|
+
// Serializer global names
|
|
342
|
+
export type GlobalSerializerName<I extends Dream> = GlobalSerializerNames<I>[number]
|
|
343
|
+
|
|
344
|
+
type GlobalSerializerNames<
|
|
345
|
+
I extends Dream,
|
|
346
|
+
GlobalSchema = I['globalSchema'],
|
|
347
|
+
GlobalNames = GlobalSchema['globalNames' & keyof GlobalSchema],
|
|
348
|
+
> = GlobalNames['serializers' & keyof GlobalNames]
|
|
349
|
+
// end:Serializer global names
|
|
350
|
+
|
|
351
|
+
export type DreamSerializers<I extends Dream> = Record<'default', GlobalSerializerName<I>> &
|
|
352
|
+
Record<string, GlobalSerializerName<I>>
|
|
353
|
+
|
|
354
|
+
export type DreamConstructorType<T extends Dream> = (new (...arguments_: any[]) => T) & typeof Dream
|
|
355
|
+
|
|
356
|
+
export type ViewModel = { serializers: Record<string, string> }
|
|
357
|
+
export type ViewModelClass = abstract new (...args: any) => ViewModel
|
|
358
|
+
|
|
359
|
+
export type SerializableDreamOrViewModel = ViewModel
|
|
360
|
+
export type SerializableDreamClassOrViewModelClass = abstract new (
|
|
361
|
+
...args: any
|
|
362
|
+
) => SerializableDreamOrViewModel
|
|
363
|
+
|
|
364
|
+
export type DreamSerializerCallback = () => typeof DreamSerializer
|
|
365
|
+
export type SerializableClassOrSerializerCallback =
|
|
366
|
+
| SerializableDreamClassOrViewModelClass
|
|
367
|
+
| DreamSerializerCallback
|
|
368
|
+
|
|
369
|
+
export type SerializableClassOrClasses =
|
|
370
|
+
| DreamSerializerCallback
|
|
371
|
+
| SerializableDreamClassOrViewModelClass
|
|
372
|
+
| SerializableDreamClassOrViewModelClass[]
|
|
373
|
+
|
|
374
|
+
// preload
|
|
375
|
+
export type NextPreloadArgumentType<
|
|
376
|
+
Schema,
|
|
377
|
+
PreviousTableNames,
|
|
378
|
+
PreviousSchemaAssociations = PreviousTableNames extends undefined
|
|
379
|
+
? undefined
|
|
380
|
+
: Schema[PreviousTableNames & keyof Schema]['associations' &
|
|
381
|
+
keyof Schema[PreviousTableNames & keyof Schema]],
|
|
382
|
+
> = PreviousTableNames extends undefined
|
|
383
|
+
? undefined
|
|
384
|
+
: (keyof PreviousSchemaAssociations & string) | (keyof PreviousSchemaAssociations & string)[]
|
|
385
|
+
|
|
386
|
+
export type PreloadArgumentTypeAssociatedTableNames<
|
|
387
|
+
Schema,
|
|
388
|
+
PreviousTableNames,
|
|
389
|
+
ArgumentType,
|
|
390
|
+
PreviousSchemaAssociations = PreviousTableNames extends undefined
|
|
391
|
+
? undefined
|
|
392
|
+
: Schema[PreviousTableNames & keyof Schema],
|
|
393
|
+
> = ArgumentType extends string[]
|
|
394
|
+
? undefined
|
|
395
|
+
: (PreviousSchemaAssociations[ArgumentType & (keyof PreviousSchemaAssociations & string)] &
|
|
396
|
+
string[])[number]
|
|
397
|
+
// end:preload
|
|
398
|
+
|
|
399
|
+
export type AssociationNameToDreamClassMap = Record<string, typeof Dream>
|
|
400
|
+
export type AssociationNameToAssociationMap = Record<string, AssociationStatement>
|
|
401
|
+
export type AssociationNameToAssociationDataAndDreamClassMap = Record<
|
|
402
|
+
string,
|
|
403
|
+
{
|
|
404
|
+
dreamClass: typeof Dream
|
|
405
|
+
association: AssociationStatement
|
|
406
|
+
}
|
|
407
|
+
>
|
|
408
|
+
|
|
409
|
+
type IdToDreamMap = Map<string | number, Dream>
|
|
410
|
+
export type AliasToDreamIdMap = Record<string, IdToDreamMap>
|
|
411
|
+
|
|
412
|
+
export type RelaxedPreloadStatement<Depth extends number = 0> = RelaxedJoinStatement<Depth>
|
|
413
|
+
|
|
414
|
+
export type RelaxedJoinStatement<Depth extends number = 0> = Depth extends 7
|
|
415
|
+
? object
|
|
416
|
+
: Record<string, RelaxedJoinStatement<Inc<Depth>>>
|
|
417
|
+
|
|
418
|
+
export type RelaxedPreloadOnStatement<DB, Schema, Depth extends number = 0> = Depth extends 7
|
|
419
|
+
? object
|
|
420
|
+
: {
|
|
421
|
+
[key: string]:
|
|
422
|
+
| RelaxedPreloadOnStatement<DB, Schema, Inc<Depth>>
|
|
423
|
+
| JoinAndStatements<any, any, any, any>
|
|
424
|
+
| FakeOnClauseValue
|
|
425
|
+
| object
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export type RelaxedJoinAndStatement<DB, Schema, Depth extends number = 0> = Depth extends 7
|
|
429
|
+
? object
|
|
430
|
+
: {
|
|
431
|
+
[key: string]:
|
|
432
|
+
| RelaxedJoinAndStatement<DB, Schema, Inc<Depth>>
|
|
433
|
+
| JoinAndStatements<any, any, any, any>
|
|
434
|
+
| FakeOnClauseValue
|
|
435
|
+
| object
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Just need something that is not an object, but that could be an array and also null
|
|
439
|
+
type FakeOnClauseValue = string | string[] | number | number[] | null
|
|
440
|
+
|
|
441
|
+
export type TableOrAssociationName<Schema> = (keyof Schema & string) | (keyof Schema[keyof Schema] & string)
|
|
442
|
+
|
|
443
|
+
export type SqlCommandType = 'select' | 'update' | 'delete' | 'insert'
|
|
444
|
+
|
|
445
|
+
export type DreamSerializeOptions<T> = {
|
|
446
|
+
serializerKey?: DreamSerializerKey<T>
|
|
447
|
+
casing?: 'camel' | 'snake' | null
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export type DreamOrViewModelSerializerKey<T> = T extends Dream
|
|
451
|
+
? DreamSerializerKey<T>
|
|
452
|
+
: ViewModelSerializerKey<T>
|
|
453
|
+
|
|
454
|
+
export type DreamSerializerKey<
|
|
455
|
+
T,
|
|
456
|
+
U = T extends (infer R)[] ? R : T,
|
|
457
|
+
Table = U['table' & keyof U] extends string ? U['table' & keyof U] : never,
|
|
458
|
+
Schema = U['schema' & keyof U] extends object ? U['schema' & keyof U] : never,
|
|
459
|
+
TableSchema = Table extends never ? never : Schema extends never ? never : Schema[Table & keyof Schema],
|
|
460
|
+
SerializerKeys = TableSchema extends never
|
|
461
|
+
? never
|
|
462
|
+
: TableSchema['serializerKeys' & keyof TableSchema] & (string[] | Readonly<string[]>),
|
|
463
|
+
SerializerKey = SerializerKeys extends string[] | Readonly<string[]> ? SerializerKeys[number] : never,
|
|
464
|
+
> = SerializerKey
|
|
465
|
+
|
|
466
|
+
export type ViewModelSerializerKey<
|
|
467
|
+
T,
|
|
468
|
+
U = T extends (infer R)[] ? R : T,
|
|
469
|
+
SerializerType = U extends null
|
|
470
|
+
? never
|
|
471
|
+
: U['serializers' & keyof U] extends object
|
|
472
|
+
? keyof U['serializers' & keyof U]
|
|
473
|
+
: never,
|
|
474
|
+
> = SerializerType
|
|
475
|
+
|
|
476
|
+
export interface SimilarityStatement {
|
|
477
|
+
tableName: string
|
|
478
|
+
tableAlias: string
|
|
479
|
+
columnName: string
|
|
480
|
+
opsStatement: OpsStatement<any, any>
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export type PassthroughColumnNames<
|
|
484
|
+
DreamConf,
|
|
485
|
+
GlobalSchema = DreamConf['globalSchema' & keyof DreamConf],
|
|
486
|
+
PassthroughColumns = GlobalSchema['passthroughColumns' & keyof GlobalSchema],
|
|
487
|
+
> = PassthroughColumns
|
|
488
|
+
|
|
489
|
+
export type DefaultScopeName<
|
|
490
|
+
DreamInstance extends Dream,
|
|
491
|
+
Schema = DreamInstance['schema'],
|
|
492
|
+
TableName extends keyof Schema = DreamInstance['table'] & keyof Schema,
|
|
493
|
+
> = DefaultScopeNameForTable<Schema, TableName>
|
|
494
|
+
|
|
495
|
+
export type DefaultScopeNameForTable<
|
|
496
|
+
Schema,
|
|
497
|
+
TableName extends keyof Schema,
|
|
498
|
+
SchemaTable = Schema[TableName],
|
|
499
|
+
SchemaDefaultScopes extends string[] = SchemaTable['scopes' & keyof SchemaTable]['default' &
|
|
500
|
+
keyof SchemaTable['scopes' & keyof SchemaTable]] &
|
|
501
|
+
string[],
|
|
502
|
+
> =
|
|
503
|
+
// it is not valid to remove the STI scope
|
|
504
|
+
Exclude<SchemaDefaultScopes[number], typeof STI_SCOPE_NAME>
|
|
505
|
+
|
|
506
|
+
export type AllDefaultScopeNames<
|
|
507
|
+
DreamConf,
|
|
508
|
+
GlobalSchema = DreamConf['globalSchema' & keyof DreamConf],
|
|
509
|
+
AllNames = GlobalSchema['allDefaultScopeNames' & keyof GlobalSchema],
|
|
510
|
+
> =
|
|
511
|
+
// it is not valid to remove the STI scope
|
|
512
|
+
Exclude<AllNames[number & keyof AllNames], typeof STI_SCOPE_NAME>
|
|
513
|
+
|
|
514
|
+
export type NamedScopeName<
|
|
515
|
+
DreamInstance extends Dream,
|
|
516
|
+
Schema = DreamInstance['schema'],
|
|
517
|
+
SchemaTable = Schema[DreamInstance['table'] & keyof Schema],
|
|
518
|
+
SchemaNamedScopes extends string[] = SchemaTable['scopes' & keyof SchemaTable]['named' &
|
|
519
|
+
keyof SchemaTable['scopes' & keyof SchemaTable]] &
|
|
520
|
+
string[],
|
|
521
|
+
> = SchemaNamedScopes[number]
|
|
522
|
+
|
|
523
|
+
export type DefaultOrNamedScopeName<DreamInstance extends Dream> =
|
|
524
|
+
| DefaultScopeName<DreamInstance>
|
|
525
|
+
| NamedScopeName<DreamInstance>
|
|
526
|
+
|
|
527
|
+
export type PluckEachArgs<ColumnNames extends unknown[], CbArgTypes extends unknown[]> =
|
|
528
|
+
| [...fields: ColumnNames]
|
|
529
|
+
| [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>]
|
|
530
|
+
| [...fields: ColumnNames, callback: (...values: CbArgTypes) => void | Promise<void>, opts: FindEachOpts]
|
|
@@ -1,50 +1,31 @@
|
|
|
1
|
-
import Dream from '../Dream.
|
|
2
|
-
import { DreamColumnNames } from './dream.js'
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
| 'beforeCreate'
|
|
6
|
-
| 'beforeSave'
|
|
7
|
-
| 'beforeUpdate'
|
|
8
|
-
| 'beforeDestroy'
|
|
9
|
-
| 'afterCreate'
|
|
10
|
-
| 'afterSave'
|
|
11
|
-
| 'afterUpdate'
|
|
12
|
-
| 'afterDestroy'
|
|
13
|
-
| CommitHookType
|
|
14
|
-
|
|
15
|
-
export type CommitHookType =
|
|
16
|
-
| 'afterCreateCommit'
|
|
17
|
-
| 'afterSaveCommit'
|
|
18
|
-
| 'afterUpdateCommit'
|
|
19
|
-
| 'afterDestroyCommit'
|
|
20
|
-
|
|
1
|
+
import Dream from '../Dream.js';
|
|
2
|
+
import { DreamColumnNames } from './dream.js';
|
|
3
|
+
export type HookType = 'beforeCreate' | 'beforeSave' | 'beforeUpdate' | 'beforeDestroy' | 'afterCreate' | 'afterSave' | 'afterUpdate' | 'afterDestroy' | CommitHookType;
|
|
4
|
+
export type CommitHookType = 'afterCreateCommit' | 'afterSaveCommit' | 'afterUpdateCommit' | 'afterDestroyCommit';
|
|
21
5
|
export interface HookStatement {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
type: HookType;
|
|
7
|
+
className: string;
|
|
8
|
+
method: string;
|
|
9
|
+
ifChanging?: string[] | undefined;
|
|
10
|
+
ifChanged?: string[] | undefined;
|
|
27
11
|
}
|
|
28
|
-
|
|
29
12
|
export interface BeforeHookOpts<T extends Dream | null = null> {
|
|
30
|
-
|
|
13
|
+
ifChanging?: T extends Dream ? DreamColumnNames<T>[] : string[];
|
|
31
14
|
}
|
|
32
|
-
|
|
33
15
|
export interface AfterHookOpts<T extends Dream | null = null> {
|
|
34
|
-
|
|
16
|
+
ifChanged?: T extends Dream ? DreamColumnNames<T>[] : string[];
|
|
35
17
|
}
|
|
36
|
-
|
|
37
18
|
export interface HookStatementMap {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
19
|
+
beforeCreate: readonly HookStatement[] | HookStatement[];
|
|
20
|
+
beforeUpdate: readonly HookStatement[] | HookStatement[];
|
|
21
|
+
beforeSave: readonly HookStatement[] | HookStatement[];
|
|
22
|
+
beforeDestroy: readonly HookStatement[] | HookStatement[];
|
|
23
|
+
afterCreate: readonly HookStatement[] | HookStatement[];
|
|
24
|
+
afterCreateCommit: readonly HookStatement[] | HookStatement[];
|
|
25
|
+
afterUpdate: readonly HookStatement[] | HookStatement[];
|
|
26
|
+
afterUpdateCommit: readonly HookStatement[] | HookStatement[];
|
|
27
|
+
afterSave: readonly HookStatement[] | HookStatement[];
|
|
28
|
+
afterSaveCommit: readonly HookStatement[] | HookStatement[];
|
|
29
|
+
afterDestroy: readonly HookStatement[] | HookStatement[];
|
|
30
|
+
afterDestroyCommit: readonly HookStatement[] | HookStatement[];
|
|
50
31
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Dream from '../Dream.js'
|
|
2
|
+
import { DreamColumnNames } from './dream.js'
|
|
3
|
+
|
|
4
|
+
export type HookType =
|
|
5
|
+
| 'beforeCreate'
|
|
6
|
+
| 'beforeSave'
|
|
7
|
+
| 'beforeUpdate'
|
|
8
|
+
| 'beforeDestroy'
|
|
9
|
+
| 'afterCreate'
|
|
10
|
+
| 'afterSave'
|
|
11
|
+
| 'afterUpdate'
|
|
12
|
+
| 'afterDestroy'
|
|
13
|
+
| CommitHookType
|
|
14
|
+
|
|
15
|
+
export type CommitHookType =
|
|
16
|
+
| 'afterCreateCommit'
|
|
17
|
+
| 'afterSaveCommit'
|
|
18
|
+
| 'afterUpdateCommit'
|
|
19
|
+
| 'afterDestroyCommit'
|
|
20
|
+
|
|
21
|
+
export interface HookStatement {
|
|
22
|
+
type: HookType
|
|
23
|
+
className: string
|
|
24
|
+
method: string
|
|
25
|
+
ifChanging?: string[] | undefined
|
|
26
|
+
ifChanged?: string[] | undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BeforeHookOpts<T extends Dream | null = null> {
|
|
30
|
+
ifChanging?: T extends Dream ? DreamColumnNames<T>[] : string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AfterHookOpts<T extends Dream | null = null> {
|
|
34
|
+
ifChanged?: T extends Dream ? DreamColumnNames<T>[] : string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface HookStatementMap {
|
|
38
|
+
beforeCreate: readonly HookStatement[] | HookStatement[]
|
|
39
|
+
beforeUpdate: readonly HookStatement[] | HookStatement[]
|
|
40
|
+
beforeSave: readonly HookStatement[] | HookStatement[]
|
|
41
|
+
beforeDestroy: readonly HookStatement[] | HookStatement[]
|
|
42
|
+
afterCreate: readonly HookStatement[] | HookStatement[]
|
|
43
|
+
afterCreateCommit: readonly HookStatement[] | HookStatement[]
|
|
44
|
+
afterUpdate: readonly HookStatement[] | HookStatement[]
|
|
45
|
+
afterUpdateCommit: readonly HookStatement[] | HookStatement[]
|
|
46
|
+
afterSave: readonly HookStatement[] | HookStatement[]
|
|
47
|
+
afterSaveCommit: readonly HookStatement[] | HookStatement[]
|
|
48
|
+
afterDestroy: readonly HookStatement[] | HookStatement[]
|
|
49
|
+
afterDestroyCommit: readonly HookStatement[] | HookStatement[]
|
|
50
|
+
}
|