@rvoh/dream 0.44.8 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/Dream.js +246 -23
- package/dist/cjs/src/cli/index.js +16 -0
- package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
- package/dist/cjs/src/decorators/Decorators.js +2 -1
- package/dist/cjs/src/dream/Query.js +162 -24
- package/dist/cjs/src/dream/internal/extractNestedPaths.js +37 -0
- package/dist/cjs/src/helpers/indent.js +18 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +3 -18
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +139 -3
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
- package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +20 -0
- package/dist/esm/src/Dream.js +246 -23
- package/dist/esm/src/cli/index.js +16 -0
- package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
- package/dist/esm/src/decorators/Decorators.js +2 -1
- package/dist/esm/src/dream/Query.js +162 -24
- package/dist/esm/src/dream/internal/extractNestedPaths.js +34 -0
- package/dist/esm/src/helpers/indent.js +15 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +3 -18
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +139 -3
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +17 -0
- package/dist/types/src/Dream.d.ts +218 -24
- package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +18 -14
- package/dist/types/src/decorators/Decorators.d.ts +2 -1
- package/dist/types/src/dream/Query.d.ts +154 -25
- package/dist/types/src/dream/internal/extractNestedPaths.d.ts +21 -0
- package/dist/types/src/helpers/indent.d.ts +3 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +176 -5
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +176 -3
- package/dist/types/src/serializer/helpers/serializerForAssociatedClass.d.ts +9 -0
- package/dist/types/src/types/dream.d.ts +2 -1
- package/dist/types/src/types/dream.ts +26 -1
- package/docs/assets/highlight.css +7 -0
- package/docs/assets/navigation.js +1 -1
- 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 +21 -20
- package/docs/classes/Dream.html +288 -209
- 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 +21 -8
- package/docs/classes/DreamSerializerBuilder.html +66 -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/ObjectSerializerBuilder.html +66 -2
- package/docs/classes/Query.html +118 -78
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.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/cloneDeepSafe.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/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.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/normalizeUnicode.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/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.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/BelongsToStatement.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/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.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/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/modules.html +1 -0
- 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/DbTypes.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -0
- 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/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.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/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.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/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.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/OpenapiPrimitiveBaseTypes.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/OpenapiShorthandPrimitiveBaseTypes.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/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.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/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.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
|
@@ -10,6 +10,38 @@ export default class ObjectSerializerBuilder {
|
|
|
10
10
|
this.data = data;
|
|
11
11
|
this.passthroughData = passthroughData;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Includes an attribute from the data object in the serialized output.
|
|
15
|
+
*
|
|
16
|
+
* For ObjectSerializer, the `openapi` option is always required since type
|
|
17
|
+
* inference is not available for plain objects or ViewModels.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The attribute name from the data object
|
|
20
|
+
* @param options - Configuration options including required OpenAPI schema, default value, and output customization
|
|
21
|
+
* @returns The serializer builder for method chaining
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Required OpenAPI schema
|
|
26
|
+
* .attribute('email', {
|
|
27
|
+
* openapi: { type: 'string', format: 'email' }
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* // With default value
|
|
31
|
+
* .attribute('status', {
|
|
32
|
+
* openapi: { type: 'string' },
|
|
33
|
+
* default: 'active'
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* // Rename output key
|
|
37
|
+
* .attribute('email', {
|
|
38
|
+
* openapi: { type: 'string' },
|
|
39
|
+
* as: 'userEmail'
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
|
|
44
|
+
*/
|
|
13
45
|
attribute(name, options) {
|
|
14
46
|
this.attributes.push({
|
|
15
47
|
type: 'attribute',
|
|
@@ -18,15 +50,74 @@ export default class ObjectSerializerBuilder {
|
|
|
18
50
|
});
|
|
19
51
|
return this;
|
|
20
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Includes an attribute from a nested object in the serialized output.
|
|
55
|
+
*
|
|
56
|
+
* Pulls up an attribute from a target object property. The `openapi` option
|
|
57
|
+
* is always required. If the target object or the delegated attribute
|
|
58
|
+
* is null/undefined, the `default` option value will be used if provided.
|
|
59
|
+
*
|
|
60
|
+
* @param targetName - The property name containing the target object
|
|
61
|
+
* @param name - The attribute name within the target object
|
|
62
|
+
* @param options - Configuration options including required OpenAPI schema, default value, and output customization
|
|
63
|
+
* @returns The serializer builder for method chaining
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Delegate to user.email
|
|
68
|
+
* .delegatedAttribute('user', 'email', {
|
|
69
|
+
* openapi: { type: 'string', format: 'email' }
|
|
70
|
+
* })
|
|
71
|
+
*
|
|
72
|
+
* // With default value for null target or attribute
|
|
73
|
+
* .delegatedAttribute('profile', 'displayName', {
|
|
74
|
+
* openapi: { type: 'string' },
|
|
75
|
+
* default: 'Anonymous User'
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
|
|
80
|
+
*/
|
|
21
81
|
delegatedAttribute(targetName, name, options) {
|
|
22
82
|
this.attributes.push({
|
|
23
83
|
type: 'delegatedAttribute',
|
|
24
|
-
targetName,
|
|
84
|
+
targetName: targetName,
|
|
25
85
|
name: name,
|
|
26
86
|
options: options ?? {},
|
|
27
87
|
});
|
|
28
88
|
return this;
|
|
29
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Includes a computed value in the serialized output.
|
|
92
|
+
*
|
|
93
|
+
* Executes a callback function to generate a custom attribute value.
|
|
94
|
+
* The `openapi` option is always required since the return type cannot be inferred.
|
|
95
|
+
*
|
|
96
|
+
* @param name - The attribute name for the computed value
|
|
97
|
+
* @param fn - Callback function that returns the computed value
|
|
98
|
+
* @param options - Configuration options including required OpenAPI schema and optional flattening
|
|
99
|
+
* @returns The serializer builder for method chaining
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Simple computed value
|
|
104
|
+
* .customAttribute('fullName', () =>
|
|
105
|
+
* `${user.firstName} ${user.lastName}`,
|
|
106
|
+
* { openapi: { type: 'string' } }
|
|
107
|
+
* )
|
|
108
|
+
*
|
|
109
|
+
* // Flattened object properties
|
|
110
|
+
* .customAttribute('coordinates', () => ({ lat: 40.7, lng: -74.0 }), {
|
|
111
|
+
* flatten: true,
|
|
112
|
+
* openapi: {
|
|
113
|
+
* lat: { type: 'number' },
|
|
114
|
+
* lng: { type: 'number' }
|
|
115
|
+
* }
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
|
|
120
|
+
*/
|
|
30
121
|
customAttribute(name, fn, options) {
|
|
31
122
|
this.attributes.push({
|
|
32
123
|
type: 'customAttribute',
|
|
@@ -36,22 +127,104 @@ export default class ObjectSerializerBuilder {
|
|
|
36
127
|
});
|
|
37
128
|
return this;
|
|
38
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Includes a single associated object in the serialized output.
|
|
132
|
+
*
|
|
133
|
+
* For ObjectSerializer, explicit serializer configuration is always required
|
|
134
|
+
* since association schemas cannot be inferred from plain objects.
|
|
135
|
+
*
|
|
136
|
+
* @param name - The association property name
|
|
137
|
+
* @param options - Configuration options including required serializer and OpenAPI schema
|
|
138
|
+
* @returns The serializer builder for method chaining
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // With explicit serializer function
|
|
143
|
+
* .rendersOne('owner', UserSerializer, {
|
|
144
|
+
* openapi: { $ref: '#/components/schemas/User' }
|
|
145
|
+
* })
|
|
146
|
+
*
|
|
147
|
+
* // With Dream class reference
|
|
148
|
+
* .rendersOne('creator', {
|
|
149
|
+
* dreamClass: User,
|
|
150
|
+
* serializerKey: 'summary',
|
|
151
|
+
* openapi: { $ref: '#/components/schemas/UserSummary' }
|
|
152
|
+
* })
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
|
|
156
|
+
*/
|
|
39
157
|
rendersOne(name, options) {
|
|
40
158
|
this.attributes.push({
|
|
41
159
|
type: 'rendersOne',
|
|
42
|
-
name,
|
|
160
|
+
name: name,
|
|
43
161
|
options: options ?? {},
|
|
44
162
|
});
|
|
45
163
|
return this;
|
|
46
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Includes an array of associated objects in the serialized output.
|
|
167
|
+
*
|
|
168
|
+
* For ObjectSerializer, explicit serializer configuration is always required
|
|
169
|
+
* since association schemas cannot be inferred from plain objects.
|
|
170
|
+
*
|
|
171
|
+
* @param name - The association property name (should be an array)
|
|
172
|
+
* @param options - Configuration options including required serializer and OpenAPI schema
|
|
173
|
+
* @returns The serializer builder for method chaining
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // With explicit serializer function
|
|
178
|
+
* .rendersMany('articles', ArticleSerializer, {
|
|
179
|
+
* openapi: {
|
|
180
|
+
* type: 'array',
|
|
181
|
+
* items: { $ref: '#/components/schemas/Article' }
|
|
182
|
+
* }
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* // With ViewModel class reference
|
|
186
|
+
* .rendersMany('comments', {
|
|
187
|
+
* viewModelClass: CommentViewModel,
|
|
188
|
+
* serializer: CommentViewModelSerializer,
|
|
189
|
+
* openapi: {
|
|
190
|
+
* type: 'array',
|
|
191
|
+
* items: { $ref: '#/components/schemas/Comment' }
|
|
192
|
+
* }
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* See: {@link https://your-docs-url.com/docs/serializers/associations | Serializer Associations Documentation}
|
|
197
|
+
*/
|
|
47
198
|
rendersMany(name, options) {
|
|
48
199
|
this.attributes.push({
|
|
49
200
|
type: 'rendersMany',
|
|
50
|
-
name,
|
|
201
|
+
name: name,
|
|
51
202
|
options: options ?? {},
|
|
52
203
|
});
|
|
53
204
|
return this;
|
|
54
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Executes the serializer and returns the serialized output.
|
|
208
|
+
*
|
|
209
|
+
* This method processes all defined attributes, custom attributes, delegated attributes,
|
|
210
|
+
* and associations to produce the final serialized object. The result is suitable for
|
|
211
|
+
* JSON.stringify() and API responses.
|
|
212
|
+
*
|
|
213
|
+
* @param passthrough - Additional data to pass through to nested serializers
|
|
214
|
+
* @param opts - Rendering options for customizing the serialization process
|
|
215
|
+
* @returns The serialized object
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const result = UserViewModelSerializer(userVm).render()
|
|
220
|
+
* // Returns: { id: '123', email: 'user@example.com', ... }
|
|
221
|
+
*
|
|
222
|
+
* // With passthrough data for nested serializers
|
|
223
|
+
* const result = UserViewModelSerializer(userVm).render({ currentUserId: '456' })
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* See: {@link https://your-docs-url.com/docs/serializers/render | Serializer Rendering Documentation}
|
|
227
|
+
*/
|
|
55
228
|
render(passthrough = {}, opts = {}) {
|
|
56
229
|
return new SerializerRenderer(this, passthrough, opts).render();
|
|
57
230
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inferSerializersFromDreamClassOrViewModelClass } from './inferSerializerFromDreamOrViewModel.js';
|
|
2
|
+
/**
|
|
3
|
+
* Only used when flatten: true, and the associated model is null, in which case,
|
|
4
|
+
* we need something to determine the keys that will be flattened into the
|
|
5
|
+
* rendering serializer
|
|
6
|
+
*/
|
|
7
|
+
export function serializerForAssociatedClass(object, associationName, options) {
|
|
8
|
+
if (options.serializer)
|
|
9
|
+
return options.serializer;
|
|
10
|
+
if (!object.isDreamInstance)
|
|
11
|
+
return null;
|
|
12
|
+
const dream = object;
|
|
13
|
+
const association = dream['getAssociationMetadata'](associationName);
|
|
14
|
+
const associatedClasses = association.modelCB();
|
|
15
|
+
const associatedClass = Array.isArray(associatedClasses) ? associatedClasses[0] : associatedClasses;
|
|
16
|
+
return inferSerializersFromDreamClassOrViewModelClass(associatedClass, options.serializerKey)[0] ?? null;
|
|
17
|
+
}
|
|
@@ -6,14 +6,16 @@ import DreamClassTransactionBuilder from './dream/DreamClassTransactionBuilder.j
|
|
|
6
6
|
import DreamInstanceTransactionBuilder from './dream/DreamInstanceTransactionBuilder.js';
|
|
7
7
|
import DreamTransaction from './dream/DreamTransaction.js';
|
|
8
8
|
import { DestroyOptions } from './dream/internal/destroyOptions.js';
|
|
9
|
+
import { RecursiveSerializerInfo } from './dream/internal/extractNestedPaths.js';
|
|
9
10
|
import LeftJoinLoadBuilder from './dream/LeftJoinLoadBuilder.js';
|
|
10
11
|
import LoadBuilder from './dream/LoadBuilder.js';
|
|
11
12
|
import Query from './dream/Query.js';
|
|
12
13
|
import { AssociationStatementsMap, PassthroughOnClause, WhereStatement } from './types/associations/shared.js';
|
|
13
14
|
import { AssociationTableNames, DbConnectionType } from './types/db.js';
|
|
14
|
-
import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, CreateOrFindByExtraOpts, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, DreamColumnNames, DreamParamSafeColumnNames, IdType, JoinAndStatements, NextPreloadArgumentType, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from './types/dream.js';
|
|
15
|
+
import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, CreateOrFindByExtraOpts, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, DreamColumnNames, DreamParamSafeColumnNames, DreamSerializerKey, IdType, JoinAndStatements, NextPreloadArgumentType, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from './types/dream.js';
|
|
15
16
|
import { HookStatement, HookStatementMap } from './types/lifecycle.js';
|
|
16
17
|
import { BaseModelColumnTypes, DefaultQueryTypeOptions, FindEachOpts, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from './types/query.js';
|
|
18
|
+
import { DreamModelSerializerType, SimpleObjectSerializerType } from './types/serializer.js';
|
|
17
19
|
import { ValidationStatement, ValidationType } from './types/validation.js';
|
|
18
20
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, RequiredOnClauseKeys, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from './types/variadic.js';
|
|
19
21
|
export default class Dream {
|
|
@@ -54,6 +56,44 @@ export default class Dream {
|
|
|
54
56
|
private static globallyInitializingDecorators;
|
|
55
57
|
get schema(): any;
|
|
56
58
|
get globalSchema(): any;
|
|
59
|
+
/**
|
|
60
|
+
* Determines if the provided Dream class is the same as or a subclass of this Dream class.
|
|
61
|
+
* This method is particularly useful for runtime type checking and works with STI (Single Table Inheritance) classes.
|
|
62
|
+
*
|
|
63
|
+
* For regular Dream classes, this checks if the provided class is exactly the same class.
|
|
64
|
+
* For STI classes, this checks inheritance relationships - a child STI class will return true
|
|
65
|
+
* when compared against its parent class.
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Regular class comparison
|
|
69
|
+
* User.typeof(User) // true
|
|
70
|
+
* User.typeof(Pet) // false
|
|
71
|
+
*
|
|
72
|
+
* // STI inheritance checking
|
|
73
|
+
* class Balloon extends ApplicationModel {
|
|
74
|
+
* // base STI class
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* class Mylar extends Balloon {
|
|
78
|
+
* // STI child class
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* Balloon.typeof(Balloon) // true
|
|
82
|
+
* Balloon.typeof(Mylar) // false
|
|
83
|
+
* Mylar.typeof(Balloon) // true (child recognizes parent)
|
|
84
|
+
* Mylar.typeof(Mylar) // true
|
|
85
|
+
*
|
|
86
|
+
* // Runtime type checking with variables
|
|
87
|
+
* const dreamClass: typeof Dream = getRandomDreamClass()
|
|
88
|
+
* if (dreamClass.typeof(Pet)) {
|
|
89
|
+
* // dreamClass is Pet or a subclass of Pet
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param dreamClass - The Dream class to compare against this class
|
|
94
|
+
* @returns `true` if the provided class is the same as this class or if this class is a subclass of the provided class (STI inheritance), `false` otherwise
|
|
95
|
+
*/
|
|
96
|
+
static typeof(dreamClass: typeof Dream): boolean;
|
|
57
97
|
/**
|
|
58
98
|
* Shadows #primaryKey, a getter which can be overwritten to customize the id field
|
|
59
99
|
* for a given model.
|
|
@@ -332,6 +372,12 @@ export default class Dream {
|
|
|
332
372
|
* name of that model.
|
|
333
373
|
*/
|
|
334
374
|
private static setGlobalName;
|
|
375
|
+
protected static serializationMap<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, serializerKey?: SerializerKey): RecursiveSerializerInfo;
|
|
376
|
+
protected static displaySerialization<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, serializerKey?: SerializerKey): RecursiveSerializerInfo;
|
|
377
|
+
protected static recursiveSerializationMap(serializer: DreamModelSerializerType | SimpleObjectSerializerType, { forDisplay, forDisplayDepth, }?: {
|
|
378
|
+
forDisplay?: boolean;
|
|
379
|
+
forDisplayDepth?: number;
|
|
380
|
+
}): RecursiveSerializerInfo;
|
|
335
381
|
/**
|
|
336
382
|
* Returns the column names for the given model
|
|
337
383
|
*
|
|
@@ -463,12 +509,14 @@ export default class Dream {
|
|
|
463
509
|
* // 2
|
|
464
510
|
* ```
|
|
465
511
|
*
|
|
512
|
+
* @param opts - Pagination options
|
|
466
513
|
* @param opts.page - the page number that you want to fetch results for
|
|
467
514
|
* @param opts.pageSize - the number of results per page (optional)
|
|
468
|
-
* @returns
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
515
|
+
* @returns A paginated result object containing:
|
|
516
|
+
* - `recordCount` - A number representing the total number of records matching your query
|
|
517
|
+
* - `pageCount` - The number of pages needed to encapsulate all the matching records
|
|
518
|
+
* - `currentPage` - The current page (same as what is provided in the paginate args)
|
|
519
|
+
* - `results` - An array of records matching the current record
|
|
472
520
|
*/
|
|
473
521
|
static paginate<T extends typeof Dream>(this: T, opts: PaginatedDreamQueryOptions): Promise<PaginatedDreamQueryResult<InstanceType<T>>>;
|
|
474
522
|
/**
|
|
@@ -524,7 +572,8 @@ export default class Dream {
|
|
|
524
572
|
* ```
|
|
525
573
|
*
|
|
526
574
|
* @param attributes - attributes or belongs to associations you wish to set on this model before persisting
|
|
527
|
-
* @param
|
|
575
|
+
* @param __namedParameters - optional parameters
|
|
576
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
528
577
|
* @returns A newly persisted dream instance
|
|
529
578
|
*/
|
|
530
579
|
static create<T extends typeof Dream>(this: T, attributes?: UpdateablePropertiesForClass<T>, { skipHooks }?: {
|
|
@@ -546,6 +595,7 @@ export default class Dream {
|
|
|
546
595
|
* ```
|
|
547
596
|
*
|
|
548
597
|
* @param attributes - The base attributes to persist, but also the attributes to use to find when create fails
|
|
598
|
+
* @param extraOpts - Additional options
|
|
549
599
|
* @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
|
|
550
600
|
* @returns A dream instance
|
|
551
601
|
*/
|
|
@@ -560,6 +610,7 @@ export default class Dream {
|
|
|
560
610
|
* ```
|
|
561
611
|
*
|
|
562
612
|
* @param attributes - The base attributes for finding which record to update, also used when creating
|
|
613
|
+
* @param extraOpts - Additional options
|
|
563
614
|
* @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
|
|
564
615
|
* @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
565
616
|
* @returns A dream instance
|
|
@@ -578,6 +629,7 @@ export default class Dream {
|
|
|
578
629
|
* at least one of the provided attributes
|
|
579
630
|
*
|
|
580
631
|
* @param attributes - The base attributes for finding which record to update, also used when creating
|
|
632
|
+
* @param extraOpts - Additional options
|
|
581
633
|
* @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
|
|
582
634
|
* @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
583
635
|
* @returns A dream instance
|
|
@@ -649,6 +701,7 @@ export default class Dream {
|
|
|
649
701
|
* ```
|
|
650
702
|
*
|
|
651
703
|
* @param cb - The callback to call for each found record
|
|
704
|
+
* @param opts - Optional parameters for batch processing
|
|
652
705
|
* @param opts.batchSize - the batch size you wish to collect records in. If not provided, it will default to 1000
|
|
653
706
|
* @returns void
|
|
654
707
|
*/
|
|
@@ -722,6 +775,7 @@ export default class Dream {
|
|
|
722
775
|
* ```
|
|
723
776
|
*
|
|
724
777
|
* @param attributes - The base attributes for finding, but also the attributes to use when creating
|
|
778
|
+
* @param extraOpts - Additional options
|
|
725
779
|
* @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
|
|
726
780
|
* @returns A dream instance
|
|
727
781
|
*/
|
|
@@ -745,10 +799,10 @@ export default class Dream {
|
|
|
745
799
|
static exists<T extends typeof Dream>(this: T): Promise<boolean>;
|
|
746
800
|
/**
|
|
747
801
|
* Load each specified association using a single SQL query.
|
|
748
|
-
* See {@link
|
|
802
|
+
* See {@link Dream.preload} for preloading in separate queries.
|
|
749
803
|
*
|
|
750
804
|
* Note: since leftJoinPreload loads via single query, it has
|
|
751
|
-
* some downsides and that may be avoided using {@link
|
|
805
|
+
* some downsides and that may be avoided using {@link Dream.preload}:
|
|
752
806
|
* 1. `limit` and `offset` will be automatically removed
|
|
753
807
|
* 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
|
|
754
808
|
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.preload('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
|
|
@@ -797,6 +851,144 @@ export default class Dream {
|
|
|
797
851
|
allowOffset: true;
|
|
798
852
|
allowPaginate: true;
|
|
799
853
|
}>>;
|
|
854
|
+
/**
|
|
855
|
+
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
856
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
857
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
858
|
+
* manually remember which associations to preload for serialization.
|
|
859
|
+
*
|
|
860
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
861
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
862
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
863
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
864
|
+
* corresponding modifications to preload statements.
|
|
865
|
+
*
|
|
866
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
867
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
868
|
+
*
|
|
869
|
+
* ```ts
|
|
870
|
+
* // Instead of manually specifying all associations:
|
|
871
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
872
|
+
*
|
|
873
|
+
* // Automatically preload everything needed for serialization:
|
|
874
|
+
* await User.preloadForSerialization({ serializerKey: 'summary' }).all()
|
|
875
|
+
*
|
|
876
|
+
* // Add where conditions to specific associations during preloading:
|
|
877
|
+
* await User.preloadForSerialization({
|
|
878
|
+
* serializerKey: 'detailed',
|
|
879
|
+
* modifierFn: (dreamClass, associationName) => {
|
|
880
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
881
|
+
* return { and: { published: true } }
|
|
882
|
+
* }
|
|
883
|
+
* }
|
|
884
|
+
* }).all()
|
|
885
|
+
*
|
|
886
|
+
* // Skip preloading specific associations to handle them manually:
|
|
887
|
+
* await User.preloadForSerialization({
|
|
888
|
+
* serializerKey: 'summary',
|
|
889
|
+
* modifierFn: (dreamClass, associationName) => {
|
|
890
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
891
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
892
|
+
* }
|
|
893
|
+
* }
|
|
894
|
+
* })
|
|
895
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading
|
|
896
|
+
* .all()
|
|
897
|
+
* ```
|
|
898
|
+
*
|
|
899
|
+
* @param opts - Configuration options for serialization preloading
|
|
900
|
+
* @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
|
|
901
|
+
* @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
902
|
+
* @returns A Query with all serialization associations preloaded
|
|
903
|
+
*/
|
|
904
|
+
static preloadForSerialization<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, opts?: {
|
|
905
|
+
serializerKey?: SerializerKey;
|
|
906
|
+
modifierFn?: <DreamClass extends typeof Dream, const AssociationName extends DreamAssociationNames<InstanceType<DreamClass>>>(dreamClass: DreamClass, associationName: AssociationName) => {
|
|
907
|
+
and?: object;
|
|
908
|
+
andAny?: object;
|
|
909
|
+
andNot?: object;
|
|
910
|
+
} | 'omit' | undefined;
|
|
911
|
+
}): Query<InstanceType<T>, Readonly<{
|
|
912
|
+
joinedAssociations: readonly [];
|
|
913
|
+
rootTableName: InstanceType<T>["table"];
|
|
914
|
+
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
915
|
+
allowPreload: true;
|
|
916
|
+
allowLeftJoinPreload: false;
|
|
917
|
+
allowLimit: true;
|
|
918
|
+
allowOffset: true;
|
|
919
|
+
allowPaginate: true;
|
|
920
|
+
}>>;
|
|
921
|
+
/**
|
|
922
|
+
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
923
|
+
* in a DreamSerializer using left join preloading. This traverses the entire content tree
|
|
924
|
+
* of serializers to automatically load all necessary associations in a single query,
|
|
925
|
+
* eliminating N+1 query problems and removing the need to manually remember which
|
|
926
|
+
* associations to preload for serialization.
|
|
927
|
+
*
|
|
928
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
929
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
930
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
931
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
932
|
+
* corresponding modifications to left join preload statements.
|
|
933
|
+
*
|
|
934
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
935
|
+
* automatically left join preloads all associations that will be needed during serialization.
|
|
936
|
+
*
|
|
937
|
+
* Note: Left join preloading loads all data in a single SQL query but has trade-offs compared
|
|
938
|
+
* to regular preloading. See {@link Dream.leftJoinPreload} for details about limitations.
|
|
939
|
+
*
|
|
940
|
+
* ```ts
|
|
941
|
+
* // Instead of manually specifying all associations:
|
|
942
|
+
* await User.leftJoinPreload('posts', 'comments', 'replies').all()
|
|
943
|
+
*
|
|
944
|
+
* // Automatically left join preload everything needed for serialization:
|
|
945
|
+
* await User.leftJoinPreloadForSerialization({ serializerKey: 'summary' }).all()
|
|
946
|
+
*
|
|
947
|
+
* // Add where conditions to specific associations during left join preloading:
|
|
948
|
+
* await User.leftJoinPreloadForSerialization({
|
|
949
|
+
* serializerKey: 'detailed',
|
|
950
|
+
* modifierFn: (dreamClass, associationName) => {
|
|
951
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
952
|
+
* return { and: { published: true } }
|
|
953
|
+
* }
|
|
954
|
+
* }
|
|
955
|
+
* }).all()
|
|
956
|
+
*
|
|
957
|
+
* // Skip left join preloading specific associations to handle them manually:
|
|
958
|
+
* await User.leftJoinPreloadForSerialization({
|
|
959
|
+
* serializerKey: 'summary',
|
|
960
|
+
* modifierFn: (dreamClass, associationName) => {
|
|
961
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
962
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
963
|
+
* }
|
|
964
|
+
* }
|
|
965
|
+
* })
|
|
966
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading instead
|
|
967
|
+
* .all()
|
|
968
|
+
* ```
|
|
969
|
+
*
|
|
970
|
+
* @param opts - Configuration options for serialization preloading
|
|
971
|
+
* @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
|
|
972
|
+
* @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
973
|
+
* @returns A Query with all serialization associations left join preloaded
|
|
974
|
+
*/
|
|
975
|
+
static leftJoinPreloadForSerialization<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, opts?: {
|
|
976
|
+
serializerKey?: SerializerKey;
|
|
977
|
+
modifierFn?: <DreamClass extends typeof Dream, const AssociationName extends DreamAssociationNames<InstanceType<DreamClass>>>(dreamClass: DreamClass, associationName: AssociationName) => {
|
|
978
|
+
and?: object;
|
|
979
|
+
andAny?: object;
|
|
980
|
+
andNot?: object;
|
|
981
|
+
} | 'omit' | undefined;
|
|
982
|
+
}): Query<InstanceType<T>, Readonly<{
|
|
983
|
+
joinedAssociations: readonly [];
|
|
984
|
+
rootTableName: InstanceType<T>["table"];
|
|
985
|
+
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
986
|
+
allowPreload: false;
|
|
987
|
+
allowLeftJoinPreload: true;
|
|
988
|
+
allowLimit: false;
|
|
989
|
+
allowOffset: false;
|
|
990
|
+
allowPaginate: false;
|
|
991
|
+
}>>;
|
|
800
992
|
/**
|
|
801
993
|
* Returns a new Query instance with the provided
|
|
802
994
|
* inner join statement attached
|
|
@@ -999,7 +1191,7 @@ export default class Dream {
|
|
|
999
1191
|
* // 3
|
|
1000
1192
|
* ```
|
|
1001
1193
|
*
|
|
1002
|
-
* @param
|
|
1194
|
+
* @param args - a list of fields to pluck, followed by a callback function to call for each set of found fields
|
|
1003
1195
|
* @returns void
|
|
1004
1196
|
*/
|
|
1005
1197
|
static pluckEach<T extends typeof Dream, I extends InstanceType<T>, ColumnNames extends TableColumnNames<I['DB'], I['table']>[], CbArgTypes extends BaseModelColumnTypes<ColumnNames, I>>(this: T, ...args: PluckEachArgs<ColumnNames, CbArgTypes>): Promise<void>;
|
|
@@ -1176,7 +1368,7 @@ export default class Dream {
|
|
|
1176
1368
|
* // [User{email: 'how@yadoin'}, User{name: 'fred'}, User{name: 'fred'}]
|
|
1177
1369
|
* ```
|
|
1178
1370
|
*
|
|
1179
|
-
* @param
|
|
1371
|
+
* @param statements - a list of where statements to `OR` together
|
|
1180
1372
|
* @returns A Query for this model with the whereAny clause applied
|
|
1181
1373
|
*/
|
|
1182
1374
|
static whereAny<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = InstanceType<T>['table']>(this: T, statements: WhereStatement<DB, Schema, TableName>[]): Query<InstanceType<T>>;
|
|
@@ -1189,7 +1381,7 @@ export default class Dream {
|
|
|
1189
1381
|
* // User{email: 'hello@world'}
|
|
1190
1382
|
* ```
|
|
1191
1383
|
*
|
|
1192
|
-
* @param
|
|
1384
|
+
* @param attributes - A where statement to negate and apply to the Query
|
|
1193
1385
|
* @returns A Query for this model with the whereNot clause applied
|
|
1194
1386
|
*/
|
|
1195
1387
|
static whereNot<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = InstanceType<T>['table']>(this: T, attributes: WhereStatement<DB, Schema, TableName>): Query<InstanceType<T>>;
|
|
@@ -1850,7 +2042,7 @@ export default class Dream {
|
|
|
1850
2042
|
* // 'dog'
|
|
1851
2043
|
* ```
|
|
1852
2044
|
*
|
|
1853
|
-
* @param
|
|
2045
|
+
* @param columnName - The column name you want the previous value for
|
|
1854
2046
|
* @returns Returns the previous value for an attribute
|
|
1855
2047
|
*/
|
|
1856
2048
|
previousValueForAttribute<I extends Dream, DB extends I['DB'], TableName extends I['table'], Table extends DB[TableName], ColumnName extends DreamColumnNames<I>>(this: I, columnName: ColumnName): Updateable<Table>[ColumnName];
|
|
@@ -1867,7 +2059,7 @@ export default class Dream {
|
|
|
1867
2059
|
* Returns true if the columnName provided has
|
|
1868
2060
|
* changes that have not yet been persisted.
|
|
1869
2061
|
*
|
|
1870
|
-
* @param
|
|
2062
|
+
* @param attribute - the column name to check
|
|
1871
2063
|
* @returns A boolean
|
|
1872
2064
|
*/
|
|
1873
2065
|
willSaveChangeToAttribute<I extends Dream>(this: I, attribute: DreamColumnNames<I>): boolean;
|
|
@@ -2068,7 +2260,7 @@ export default class Dream {
|
|
|
2068
2260
|
/**
|
|
2069
2261
|
* Loads the requested associations upon execution
|
|
2070
2262
|
*
|
|
2071
|
-
* NOTE: {@link
|
|
2263
|
+
* NOTE: {@link Dream.preload} is often a preferrable way of achieving the
|
|
2072
2264
|
* same goal.
|
|
2073
2265
|
*
|
|
2074
2266
|
* ```ts
|
|
@@ -2090,18 +2282,17 @@ export default class Dream {
|
|
|
2090
2282
|
load<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLoadArgs<DB, Schema, TableName, Arr>]): LoadBuilder<I>;
|
|
2091
2283
|
/**
|
|
2092
2284
|
* Load each specified association using a single SQL query.
|
|
2093
|
-
* See {@link
|
|
2285
|
+
* See {@link Dream.load} for loading in separate queries.
|
|
2094
2286
|
*
|
|
2095
|
-
* Note: since
|
|
2096
|
-
* some downsides and that may be avoided using {@link
|
|
2287
|
+
* Note: since leftJoinLoad loads via single query, it has
|
|
2288
|
+
* some downsides and that may be avoided using {@link Dream.load}:
|
|
2097
2289
|
* 1. `limit` and `offset` will be automatically removed
|
|
2098
2290
|
* 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
|
|
2099
|
-
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.
|
|
2291
|
+
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinLoad('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
|
|
2100
2292
|
* 4. the individual query becomes more complex the more associations are included
|
|
2101
2293
|
* 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.load(...).findEach(...)` avoids instantiating massive amounts of data at once
|
|
2102
|
-
* Loads the requested associations upon execution
|
|
2103
2294
|
*
|
|
2104
|
-
* NOTE: {@link
|
|
2295
|
+
* NOTE: {@link Dream.leftJoinPreload} is often a preferrable way of achieving the
|
|
2105
2296
|
* same goal.
|
|
2106
2297
|
*
|
|
2107
2298
|
* ```ts
|
|
@@ -2220,7 +2411,8 @@ export default class Dream {
|
|
|
2220
2411
|
* user.type // 'User'
|
|
2221
2412
|
* ```
|
|
2222
2413
|
*
|
|
2223
|
-
* @param
|
|
2414
|
+
* @param __namedParameters - optional parameters
|
|
2415
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
2224
2416
|
* @returns void
|
|
2225
2417
|
*/
|
|
2226
2418
|
save<I extends Dream>(this: I, { skipHooks }?: {
|
|
@@ -2258,7 +2450,8 @@ export default class Dream {
|
|
|
2258
2450
|
* ```
|
|
2259
2451
|
*
|
|
2260
2452
|
* @param attributes - the attributes to set on the model
|
|
2261
|
-
* @param
|
|
2453
|
+
* @param __namedParameters - optional parameters
|
|
2454
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
2262
2455
|
* @returns void
|
|
2263
2456
|
*/
|
|
2264
2457
|
update<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: {
|
|
@@ -2283,7 +2476,8 @@ export default class Dream {
|
|
|
2283
2476
|
* ```
|
|
2284
2477
|
*
|
|
2285
2478
|
* @param attributes - The attributes to update on this instance
|
|
2286
|
-
* @param
|
|
2479
|
+
* @param __namedParameters - optional parameters
|
|
2480
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
2287
2481
|
* @returns - void
|
|
2288
2482
|
*/
|
|
2289
2483
|
updateAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: {
|
|
@@ -2312,7 +2506,7 @@ export default class Dream {
|
|
|
2312
2506
|
* Flags a dream model so that it allows
|
|
2313
2507
|
* deletion once again.
|
|
2314
2508
|
*
|
|
2315
|
-
* Undoes {@link Dream.
|
|
2509
|
+
* Undoes {@link Dream.preventDeletion}
|
|
2316
2510
|
*
|
|
2317
2511
|
* ```ts
|
|
2318
2512
|
* class User extends ApplicationModel {
|