@rvoh/dream 2.28.2 → 2.29.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 +15 -11
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +7 -3
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +8 -8
- package/dist/cjs/src/dream/LoadBuilder.js +7 -4
- package/dist/cjs/src/dream/Query.js +25 -10
- package/dist/cjs/src/dream/QueryDriver/Base.js +12 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +11 -2
- package/dist/cjs/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
- package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +1 -1
- package/dist/cjs/src/dream/internal/reload.js +3 -1
- package/dist/cjs/src/dream/internal/shouldBypassDefaultScope.js +3 -4
- package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +4 -1
- package/dist/cjs/src/errors/NoUpdateOnAssociationQuery.js +1 -1
- package/dist/cjs/src/errors/sti/STIChildTypeMismatch.js +28 -0
- package/dist/esm/src/Dream.js +15 -11
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +7 -3
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +8 -8
- package/dist/esm/src/dream/LoadBuilder.js +7 -4
- package/dist/esm/src/dream/Query.js +25 -10
- package/dist/esm/src/dream/QueryDriver/Base.js +12 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +11 -2
- package/dist/esm/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
- package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +1 -1
- package/dist/esm/src/dream/internal/reload.js +3 -1
- package/dist/esm/src/dream/internal/shouldBypassDefaultScope.js +3 -4
- package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +4 -1
- package/dist/esm/src/errors/NoUpdateOnAssociationQuery.js +1 -1
- package/dist/esm/src/errors/sti/STIChildTypeMismatch.js +28 -0
- package/dist/types/src/Dream.d.ts +10 -6
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +8 -4
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +4 -4
- package/dist/types/src/dream/LoadBuilder.d.ts +6 -3
- package/dist/types/src/dream/Query.d.ts +18 -8
- package/dist/types/src/dream/QueryDriver/Base.d.ts +6 -0
- package/dist/types/src/dream/internal/destroyOptions.d.ts +3 -2
- package/dist/types/src/errors/sti/STIChildTypeMismatch.d.ts +11 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +11 -11
- package/docs/classes/db.KyselyQueryDriver.html +44 -42
- package/docs/classes/db.PostgresQueryDriver.html +45 -43
- package/docs/classes/db.QueryDriverBase.html +43 -41
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.SortableBatchRequiresTooManyScopeLocks.html +3 -3
- package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +134 -131
- package/docs/classes/index.DreamApp.html +10 -10
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +72 -69
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +11 -11
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +3 -3
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +5 -5
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
|
@@ -190,7 +190,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
190
190
|
* @param options - Options for destroying the instance
|
|
191
191
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
192
192
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
193
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
193
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
194
194
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
195
195
|
* @returns The instance that was destroyed
|
|
196
196
|
*/
|
|
@@ -212,7 +212,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
212
212
|
* @param options - Options for destroying the instance
|
|
213
213
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
214
214
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
215
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
215
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
216
216
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
217
217
|
* @returns The instance that was destroyed
|
|
218
218
|
*/
|
|
@@ -227,14 +227,14 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
227
227
|
* this will raise an exception.
|
|
228
228
|
*
|
|
229
229
|
* ```ts
|
|
230
|
-
* const user = await User.
|
|
230
|
+
* const user = await User.removeDefaultScope('dream:SoftDelete').last()
|
|
231
231
|
* await user.txn(txn).undestroy()
|
|
232
232
|
* ```
|
|
233
233
|
*
|
|
234
234
|
* @param options - Options for undestroying the instance
|
|
235
235
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
236
236
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
237
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
237
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade undestroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
238
238
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
239
239
|
* @returns The undestroyed instance
|
|
240
240
|
*/
|
|
@@ -403,7 +403,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
403
403
|
* @param attributes - The attributes to update on the association
|
|
404
404
|
* @param updateAssociationOptions - Options for updating the association
|
|
405
405
|
* @param updateAssociationOptions.where - Optional where statement to apply to query before updating
|
|
406
|
-
* @param updateAssociationOptions.bypassAllDefaultScopes - If true, bypasses
|
|
406
|
+
* @param updateAssociationOptions.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when updating the association; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
407
407
|
* @param updateAssociationOptions.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
|
|
408
408
|
* @param updateAssociationOptions.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
|
|
409
409
|
* @returns The number of updated records
|
|
@@ -460,7 +460,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
460
460
|
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
461
461
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
462
462
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
463
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
463
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when destroying the association; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
464
464
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
|
|
465
465
|
* @returns The number of records deleted
|
|
466
466
|
*/
|
|
@@ -498,7 +498,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
498
498
|
* @param options.andAny - Optional andAny statement to apply to query before destroying
|
|
499
499
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
500
500
|
* @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
|
|
501
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
501
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when destroying the association; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
502
502
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
|
|
503
503
|
* @returns The number of records deleted
|
|
504
504
|
*/
|
|
@@ -531,7 +531,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
531
531
|
* @param options.andAny - Optional andAny statement to apply to query before undestroying
|
|
532
532
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
533
533
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
534
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
534
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when undestroying the association; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
535
535
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when undestroying the association. Defaults to an empty array
|
|
536
536
|
* @returns The number of records undestroyed
|
|
537
537
|
*/
|
|
@@ -44,21 +44,24 @@ export default class LoadBuilder {
|
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
47
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
48
|
+
*
|
|
49
|
+
* Prevents user-removable default scopes from applying when loading
|
|
50
|
+
* associations. An associated STI child's reserved type discriminator remains
|
|
51
|
+
* enforced; loading through its STI base still spans registered children.
|
|
49
52
|
*
|
|
50
53
|
* ```ts
|
|
51
54
|
* const user = await User.firstOrFail()
|
|
52
55
|
* const loaded = await user
|
|
53
56
|
* .load('posts')
|
|
54
|
-
* .
|
|
57
|
+
* .removeDefaultScope('dream:SoftDelete')
|
|
55
58
|
* .execute()
|
|
56
59
|
* ```
|
|
57
60
|
*
|
|
58
61
|
* @returns The LoadBuilder instance for chaining
|
|
59
62
|
*/
|
|
60
63
|
removeAllDefaultScopes() {
|
|
61
|
-
this.query = this.query
|
|
64
|
+
this.query = this.query['removeAllDefaultScopes']();
|
|
62
65
|
return this;
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
@@ -177,13 +177,13 @@ export default class Query {
|
|
|
177
177
|
/**
|
|
178
178
|
* @internal
|
|
179
179
|
*
|
|
180
|
-
* Whether or not to bypass all default scopes for this Query
|
|
180
|
+
* Whether or not to bypass all user-removable default scopes for this Query
|
|
181
181
|
*/
|
|
182
182
|
bypassAllDefaultScopes = false;
|
|
183
183
|
/**
|
|
184
184
|
* @internal
|
|
185
185
|
*
|
|
186
|
-
* Whether or not to bypass all default scopes for this Query, but not associations
|
|
186
|
+
* Whether or not to bypass all user-removable default scopes for this Query, but not associations
|
|
187
187
|
*/
|
|
188
188
|
bypassAllDefaultScopesExceptOnAssociations = false;
|
|
189
189
|
/**
|
|
@@ -778,10 +778,14 @@ export default class Query {
|
|
|
778
778
|
});
|
|
779
779
|
}
|
|
780
780
|
/**
|
|
781
|
-
*
|
|
782
|
-
*
|
|
781
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
782
|
+
*
|
|
783
|
+
* Prevents user-removable default scopes from applying when the Query is
|
|
784
|
+
* executed, including when associations are loaded. An STI child's reserved
|
|
785
|
+
* type discriminator remains enforced; query the STI base model to span its
|
|
786
|
+
* registered children.
|
|
783
787
|
*
|
|
784
|
-
* @returns A new Query which
|
|
788
|
+
* @returns A new Query which bypasses user-removable default scopes
|
|
785
789
|
*/
|
|
786
790
|
removeAllDefaultScopes() {
|
|
787
791
|
return this.clone({
|
|
@@ -1044,8 +1048,19 @@ export default class Query {
|
|
|
1044
1048
|
* @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
|
|
1045
1049
|
*/
|
|
1046
1050
|
toKysely(type) {
|
|
1051
|
+
if (type !== 'select')
|
|
1052
|
+
this.assertMutationPreservesAssociationQuery();
|
|
1047
1053
|
return this.dbDriverInstance().toKysely(type);
|
|
1048
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* @internal
|
|
1057
|
+
*
|
|
1058
|
+
* Prevents mutation paths that discard an association query's ownership constraint.
|
|
1059
|
+
*/
|
|
1060
|
+
assertMutationPreservesAssociationQuery() {
|
|
1061
|
+
if (this.baseSelectQuery)
|
|
1062
|
+
throw new NoUpdateOnAssociationQuery();
|
|
1063
|
+
}
|
|
1049
1064
|
/**
|
|
1050
1065
|
* Applies transaction to the Query instance
|
|
1051
1066
|
*
|
|
@@ -1904,7 +1919,7 @@ export default class Query {
|
|
|
1904
1919
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
1905
1920
|
* @param options.lock - If true, each batch is re-selected with an exclusive row lock inside its own transaction before being destroyed, making the destroy a compare-and-set. Defaults to false
|
|
1906
1921
|
* @param options.batchSize - The number of records to process per batch. Must be a positive integer. Defaults to 10 when `lock` is true, and to 1000 otherwise
|
|
1907
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
1922
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
1908
1923
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
1909
1924
|
* @returns The number of records that were removed
|
|
1910
1925
|
* @throws InvalidBatchSize if `batchSize` is not a positive integer
|
|
@@ -2126,7 +2141,7 @@ export default class Query {
|
|
|
2126
2141
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2127
2142
|
* @param options.lock - If true, each batch is re-selected with an exclusive row lock inside its own transaction before being destroyed, making the destroy a compare-and-set. See {@link Query.destroy} for the full semantics. Defaults to false
|
|
2128
2143
|
* @param options.batchSize - The number of records to process per batch. Must be a positive integer. Defaults to 10 when `lock` is true, and to 1000 otherwise
|
|
2129
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
2144
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
2130
2145
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
2131
2146
|
* @returns The number of records that were removed
|
|
2132
2147
|
* @throws InvalidBatchSize if `batchSize` is not a positive integer
|
|
@@ -2156,7 +2171,7 @@ export default class Query {
|
|
|
2156
2171
|
* @param options - Options for undestroying the instance
|
|
2157
2172
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
2158
2173
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2159
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
2174
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade undestroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
2160
2175
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
2161
2176
|
* @returns The number of records that were removed
|
|
2162
2177
|
* @throws BatchingIncompatibleWithLimitOrOffset if the query carries a `limit` or `offset`
|
|
@@ -2196,11 +2211,11 @@ export default class Query {
|
|
|
2196
2211
|
* @returns The number of records that were removed
|
|
2197
2212
|
*/
|
|
2198
2213
|
async delete() {
|
|
2214
|
+
this.assertMutationPreservesAssociationQuery();
|
|
2199
2215
|
return await this.dbDriverInstance().delete();
|
|
2200
2216
|
}
|
|
2201
2217
|
async update(attributesOrCb, { skipHooks, lock, batchSize } = {}) {
|
|
2202
|
-
|
|
2203
|
-
throw new NoUpdateOnAssociationQuery();
|
|
2218
|
+
this.assertMutationPreservesAssociationQuery();
|
|
2204
2219
|
if (Object.keys(this.innerJoinStatements).length)
|
|
2205
2220
|
throw new NoUpdateAllOnJoins();
|
|
2206
2221
|
if (Object.keys(this.leftJoinStatements).length)
|
|
@@ -18,6 +18,14 @@ export default class QueryDriverBase {
|
|
|
18
18
|
this.connectionOverride = query['originalOpts'].connection;
|
|
19
19
|
this.innerJoinDreamClasses = Object.freeze(query['originalOpts'].innerJoinDreamClasses || []);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*
|
|
24
|
+
* Prevents mutation paths that discard an association query's ownership constraint.
|
|
25
|
+
*/
|
|
26
|
+
assertMutationPreservesAssociationQuery() {
|
|
27
|
+
this.query['assertMutationPreservesAssociationQuery']();
|
|
28
|
+
}
|
|
21
29
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
22
30
|
static async ensureAllMigrationsHaveBeenRun(
|
|
23
31
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -110,6 +118,8 @@ export default class QueryDriverBase {
|
|
|
110
118
|
* @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
|
|
111
119
|
*/
|
|
112
120
|
toKysely(type) {
|
|
121
|
+
if (type !== 'select')
|
|
122
|
+
this.assertMutationPreservesAssociationQuery();
|
|
113
123
|
throw new Error('implement toKysely in child class (if it makes sense)');
|
|
114
124
|
}
|
|
115
125
|
/**
|
|
@@ -543,6 +553,7 @@ export default class QueryDriverBase {
|
|
|
543
553
|
*/
|
|
544
554
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
545
555
|
async delete() {
|
|
556
|
+
this.assertMutationPreservesAssociationQuery();
|
|
546
557
|
throw new Error('implement delete in child class');
|
|
547
558
|
}
|
|
548
559
|
/**
|
|
@@ -551,6 +562,7 @@ export default class QueryDriverBase {
|
|
|
551
562
|
*/
|
|
552
563
|
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
|
|
553
564
|
async update(attributes) {
|
|
565
|
+
this.assertMutationPreservesAssociationQuery();
|
|
554
566
|
throw new Error('implement update in child class');
|
|
555
567
|
}
|
|
556
568
|
/**
|
|
@@ -301,6 +301,8 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
301
301
|
* @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
|
|
302
302
|
*/
|
|
303
303
|
toKysely(type) {
|
|
304
|
+
if (type !== 'select')
|
|
305
|
+
this.assertMutationPreservesAssociationQuery();
|
|
304
306
|
switch (type) {
|
|
305
307
|
case 'select':
|
|
306
308
|
return this.buildSelect();
|
|
@@ -740,6 +742,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
740
742
|
* @returns the number of deleted rows
|
|
741
743
|
*/
|
|
742
744
|
async delete() {
|
|
745
|
+
this.assertMutationPreservesAssociationQuery();
|
|
743
746
|
const deletionResult = await executeDatabaseQuery(this.buildDelete(), 'executeTakeFirst');
|
|
744
747
|
return Number(deletionResult?.numDeletedRows || 0);
|
|
745
748
|
}
|
|
@@ -748,6 +751,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
748
751
|
* @returns the number of updated rows
|
|
749
752
|
*/
|
|
750
753
|
async update(attributes) {
|
|
754
|
+
this.assertMutationPreservesAssociationQuery();
|
|
751
755
|
const kyselyQuery = this.buildUpdate(attributes);
|
|
752
756
|
const res = await executeDatabaseQuery(kyselyQuery, 'execute');
|
|
753
757
|
const resultData = Array.from(res.entries())?.[0]?.[1];
|
|
@@ -1014,7 +1018,11 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
1014
1018
|
return { kyselyQuery, clone: this.query };
|
|
1015
1019
|
}
|
|
1016
1020
|
columnsWithRequiredLoadColumns(columns) {
|
|
1017
|
-
return uniq(compact([
|
|
1021
|
+
return uniq(compact([
|
|
1022
|
+
this.dreamClass.primaryKey,
|
|
1023
|
+
this.dreamClass['isSTIBase'] || this.dreamClass['isSTIChild'] ? 'type' : null,
|
|
1024
|
+
...columns,
|
|
1025
|
+
]));
|
|
1018
1026
|
}
|
|
1019
1027
|
/**
|
|
1020
1028
|
* @internal
|
|
@@ -1784,12 +1792,13 @@ export default class KyselyQueryDriver extends QueryDriverBase {
|
|
|
1784
1792
|
}, {});
|
|
1785
1793
|
}
|
|
1786
1794
|
conditionallyApplyDefaultScopes() {
|
|
1787
|
-
if (this.query['
|
|
1795
|
+
if (this.query['bypassAllDefaultScopesExceptOnAssociations'])
|
|
1788
1796
|
return this.query;
|
|
1789
1797
|
const thisScopes = this.dreamClass['scopes'].default;
|
|
1790
1798
|
let query = this.query;
|
|
1791
1799
|
for (const scope of thisScopes) {
|
|
1792
1800
|
if (!shouldBypassDefaultScope(scope.method, {
|
|
1801
|
+
bypassAllDefaultScopes: this.query['bypassAllDefaultScopes'],
|
|
1793
1802
|
defaultScopesToBypass: [
|
|
1794
1803
|
...this.query['defaultScopesToBypass'],
|
|
1795
1804
|
...this.query['defaultScopesToBypassExceptOnAssociations'],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function applyScopeBypassingSettingsToQuery(query, { bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
2
2
|
if (bypassAllDefaultScopes)
|
|
3
|
-
query = query
|
|
3
|
+
query = query['removeAllDefaultScopes']();
|
|
4
4
|
defaultScopesToBypass.forEach(defaultScopeToBypass => {
|
|
5
5
|
query = query.removeDefaultScope(defaultScopeToBypass);
|
|
6
6
|
});
|
|
@@ -21,7 +21,7 @@ export default async function loadDependentDestroyTree(dream, txn, { reallyDestr
|
|
|
21
21
|
loadBuilder = loadBuilder.load(...args);
|
|
22
22
|
}
|
|
23
23
|
if (bypassAllDefaultScopes) {
|
|
24
|
-
loadBuilder = loadBuilder
|
|
24
|
+
loadBuilder = loadBuilder['removeAllDefaultScopes']();
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
for (const scopeName of defaultScopesToBypass) {
|
|
@@ -10,7 +10,9 @@ export default async function reload(dream, txn = null) {
|
|
|
10
10
|
// we have persisted are not yet propagated
|
|
11
11
|
else
|
|
12
12
|
query = query.connection('primary');
|
|
13
|
-
query = query
|
|
13
|
+
query = query['removeAllDefaultScopes']().where({
|
|
14
|
+
[dream['_primaryKey']]: dream.primaryKeyValue(),
|
|
15
|
+
});
|
|
14
16
|
const reloadedRecord = await query.firstOrFail();
|
|
15
17
|
dream.setAttributes(reloadedRecord.getAttributes());
|
|
16
18
|
dream['freezeAttributes']();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { STI_SCOPE_NAME } from '../../decorators/class/STI.js';
|
|
1
2
|
export default function shouldBypassDefaultScope(scopeName, { bypassAllDefaultScopes = false, defaultScopesToBypass, }) {
|
|
2
|
-
if (bypassAllDefaultScopes)
|
|
3
|
-
return true;
|
|
4
|
-
if (!defaultScopesToBypass.length)
|
|
5
|
-
return false;
|
|
6
3
|
if (defaultScopesToBypass.includes(scopeName))
|
|
7
4
|
return true;
|
|
5
|
+
if (bypassAllDefaultScopes)
|
|
6
|
+
return scopeName !== STI_SCOPE_NAME;
|
|
8
7
|
return false;
|
|
9
8
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import STIChildMissing from '../../errors/sti/STIChildMissing.js';
|
|
2
|
+
import STIChildTypeMismatch from '../../errors/sti/STIChildTypeMismatch.js';
|
|
2
3
|
import filterRowToKnownColumns from './filterRowToKnownColumns.js';
|
|
3
4
|
export default function sqlResultToDreamInstance(dreamClass, sqlResult) {
|
|
5
|
+
if (dreamClass['isSTIChild'] && sqlResult.type !== dreamClass['sti'].value)
|
|
6
|
+
throw new STIChildTypeMismatch(dreamClass, sqlResult.type, sqlResult[dreamClass.primaryKey]);
|
|
4
7
|
// base-model reads select `*`, so under schema/image skew (or with a
|
|
5
8
|
// column declared in ignoredColumns but not yet dropped) the row can
|
|
6
9
|
// contain columns the compiled schema doesn't know about. Passing such
|
|
@@ -32,7 +35,7 @@ export default function sqlResultToDreamInstance(dreamClass, sqlResult) {
|
|
|
32
35
|
export function findExtendingDreamClass(dreamClass, type) {
|
|
33
36
|
if (!dreamClass['extendedBy'])
|
|
34
37
|
return undefined;
|
|
35
|
-
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass.
|
|
38
|
+
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass['sti'].value === type);
|
|
36
39
|
if (extendingDreamClass)
|
|
37
40
|
return extendingDreamClass;
|
|
38
41
|
return dreamClass['extendedBy']
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default class NoUpdateOnAssociationQuery extends Error {
|
|
2
2
|
get message() {
|
|
3
3
|
return `
|
|
4
|
-
|
|
4
|
+
Mutations may not be called on an associationQuery because its ownership constraint cannot be preserved. Use an association-specific mutation method or query the associated model with explicit conditions.
|
|
5
5
|
`;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default class STIChildTypeMismatch extends Error {
|
|
2
|
+
expectedDreamClass;
|
|
3
|
+
expectedType;
|
|
4
|
+
actualType;
|
|
5
|
+
baseDreamClass;
|
|
6
|
+
table;
|
|
7
|
+
primaryKeyValue;
|
|
8
|
+
constructor(expectedDreamClass, actualType, primaryKeyValue) {
|
|
9
|
+
super();
|
|
10
|
+
this.expectedDreamClass = expectedDreamClass;
|
|
11
|
+
this.expectedType = expectedDreamClass['sti'].value;
|
|
12
|
+
this.actualType = actualType;
|
|
13
|
+
this.baseDreamClass = expectedDreamClass['sti'].baseClass;
|
|
14
|
+
this.table = this.baseDreamClass.table;
|
|
15
|
+
this.primaryKeyValue = primaryKeyValue;
|
|
16
|
+
}
|
|
17
|
+
get message() {
|
|
18
|
+
return `
|
|
19
|
+
Cannot hydrate STI child from a row with a different discriminator.
|
|
20
|
+
Expected Dream class: ${this.expectedDreamClass.sanitizedName}
|
|
21
|
+
Expected type: ${this.expectedType}
|
|
22
|
+
Type specified in DB record: ${String(this.actualType)}
|
|
23
|
+
STI base Dream class: ${this.baseDreamClass.sanitizedName}
|
|
24
|
+
Table: ${this.table}
|
|
25
|
+
Primary key value: ${String(this.primaryKeyValue)}
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -594,9 +594,13 @@ export default class Dream {
|
|
|
594
594
|
*/
|
|
595
595
|
static get associationNames(): string[];
|
|
596
596
|
/**
|
|
597
|
-
*
|
|
597
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
598
598
|
*
|
|
599
|
-
*
|
|
599
|
+
* Returns a query which bypasses user-removable default scopes, including on
|
|
600
|
+
* association loads. An STI child's reserved type discriminator remains
|
|
601
|
+
* enforced; query the STI base model to span its registered children.
|
|
602
|
+
*
|
|
603
|
+
* @returns A query which bypasses user-removable default scopes
|
|
600
604
|
*/
|
|
601
605
|
static removeAllDefaultScopes<T extends typeof Dream>(this: T): Query<InstanceType<T>>;
|
|
602
606
|
/**
|
|
@@ -2470,7 +2474,7 @@ export default class Dream {
|
|
|
2470
2474
|
* @param options - Options for destroying the instance
|
|
2471
2475
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2472
2476
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2473
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
2477
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
2474
2478
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
2475
2479
|
* @returns The instance that was destroyed
|
|
2476
2480
|
*/
|
|
@@ -2493,7 +2497,7 @@ export default class Dream {
|
|
|
2493
2497
|
* @param options - Options for destroying the instance
|
|
2494
2498
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
2495
2499
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2496
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
2500
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
2497
2501
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
2498
2502
|
* @returns The instance that was destroyed
|
|
2499
2503
|
*/
|
|
@@ -2506,14 +2510,14 @@ export default class Dream {
|
|
|
2506
2510
|
* this will raise an exception.
|
|
2507
2511
|
*
|
|
2508
2512
|
* ```ts
|
|
2509
|
-
* const user = await User.
|
|
2513
|
+
* const user = await User.removeDefaultScope('dream:SoftDelete').last()
|
|
2510
2514
|
* await user.undestroy()
|
|
2511
2515
|
* ```
|
|
2512
2516
|
*
|
|
2513
2517
|
* @param options - Options for undestroying the instance
|
|
2514
2518
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
2515
2519
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
2516
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
2520
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade undestroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
2517
2521
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
2518
2522
|
* @returns The undestroyed record
|
|
2519
2523
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SelectArg, SelectExpression } from 'kysely';
|
|
2
2
|
import Dream from '../Dream.js';
|
|
3
3
|
import { PassthroughOnClause, WhereStatement } from '../types/associations/shared.js';
|
|
4
|
-
import {
|
|
4
|
+
import { AllDefaultScopeNames, CreateOrFindByExtraOpts, DreamColumnNames, DreamSerializerKey, FindablePropertiesForClass, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateOrCreateByExtraOpts, ValidatedPluckEachColumnNames } from '../types/dream.js';
|
|
5
5
|
import { BaseModelColumnTypes, FindEachOpts, LoadForModifierFn, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from '../types/query.js';
|
|
6
6
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
|
|
7
7
|
import DreamTransaction from './DreamTransaction.js';
|
|
@@ -599,9 +599,13 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
599
599
|
*/
|
|
600
600
|
queryInstance<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I): Query<DreamInstance>;
|
|
601
601
|
/**
|
|
602
|
-
*
|
|
602
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
603
603
|
*
|
|
604
|
-
*
|
|
604
|
+
* Returns a query which bypasses user-removable default scopes, including on
|
|
605
|
+
* association loads. An STI child's reserved type discriminator remains
|
|
606
|
+
* enforced; query the STI base model to span its registered children.
|
|
607
|
+
*
|
|
608
|
+
* @returns A query which bypasses user-removable default scopes
|
|
605
609
|
*/
|
|
606
610
|
removeAllDefaultScopes<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I): Query<DreamInstance>;
|
|
607
611
|
/**
|
|
@@ -610,7 +614,7 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
610
614
|
*
|
|
611
615
|
* @returns A new Query which will prevent a specific default scope from applying
|
|
612
616
|
*/
|
|
613
|
-
removeDefaultScope<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I, scopeName:
|
|
617
|
+
removeDefaultScope<I extends DreamClassTransactionBuilder<DreamClass, DreamInstance>>(this: I, scopeName: AllDefaultScopeNames<DreamInstance>): Query<DreamInstance>;
|
|
614
618
|
/**
|
|
615
619
|
* Returns the last record corresponding to the
|
|
616
620
|
* model, ordered by primary key.
|
|
@@ -174,7 +174,7 @@ export default class DreamInstanceTransactionBuilder<DreamInstance extends Dream
|
|
|
174
174
|
* @param options - Options for destroying the instance
|
|
175
175
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
176
176
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
177
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
177
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
178
178
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
179
179
|
* @returns The instance that was destroyed
|
|
180
180
|
*/
|
|
@@ -194,7 +194,7 @@ export default class DreamInstanceTransactionBuilder<DreamInstance extends Dream
|
|
|
194
194
|
* @param options - Options for destroying the instance
|
|
195
195
|
* @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
|
|
196
196
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
197
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
197
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
198
198
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
199
199
|
* @returns The instance that was destroyed
|
|
200
200
|
*/
|
|
@@ -207,14 +207,14 @@ export default class DreamInstanceTransactionBuilder<DreamInstance extends Dream
|
|
|
207
207
|
* this will raise an exception.
|
|
208
208
|
*
|
|
209
209
|
* ```ts
|
|
210
|
-
* const user = await User.
|
|
210
|
+
* const user = await User.removeDefaultScope('dream:SoftDelete').last()
|
|
211
211
|
* await user.txn(txn).undestroy()
|
|
212
212
|
* ```
|
|
213
213
|
*
|
|
214
214
|
* @param options - Options for undestroying the instance
|
|
215
215
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
216
216
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
217
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
217
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade undestroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
218
218
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
219
219
|
* @returns The undestroyed instance
|
|
220
220
|
*/
|
|
@@ -41,14 +41,17 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
41
41
|
*/
|
|
42
42
|
removeDefaultScope<I extends LoadBuilder<DreamInstance>>(this: I, scopeName: AllDefaultScopeNames<DreamInstance>): I;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
44
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
45
|
+
*
|
|
46
|
+
* Prevents user-removable default scopes from applying when loading
|
|
47
|
+
* associations. An associated STI child's reserved type discriminator remains
|
|
48
|
+
* enforced; loading through its STI base still spans registered children.
|
|
46
49
|
*
|
|
47
50
|
* ```ts
|
|
48
51
|
* const user = await User.firstOrFail()
|
|
49
52
|
* const loaded = await user
|
|
50
53
|
* .load('posts')
|
|
51
|
-
* .
|
|
54
|
+
* .removeDefaultScope('dream:SoftDelete')
|
|
52
55
|
* .execute()
|
|
53
56
|
* ```
|
|
54
57
|
*
|
|
@@ -143,13 +143,13 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
143
143
|
/**
|
|
144
144
|
* @internal
|
|
145
145
|
*
|
|
146
|
-
* Whether or not to bypass all default scopes for this Query
|
|
146
|
+
* Whether or not to bypass all user-removable default scopes for this Query
|
|
147
147
|
*/
|
|
148
148
|
private readonly bypassAllDefaultScopes;
|
|
149
149
|
/**
|
|
150
150
|
* @internal
|
|
151
151
|
*
|
|
152
|
-
* Whether or not to bypass all default scopes for this Query, but not associations
|
|
152
|
+
* Whether or not to bypass all user-removable default scopes for this Query, but not associations
|
|
153
153
|
*/
|
|
154
154
|
private readonly bypassAllDefaultScopesExceptOnAssociations;
|
|
155
155
|
/**
|
|
@@ -511,10 +511,14 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
511
511
|
*/
|
|
512
512
|
private setAssociationQueryBase;
|
|
513
513
|
/**
|
|
514
|
-
*
|
|
515
|
-
* the Query is executed
|
|
514
|
+
* @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
|
|
516
515
|
*
|
|
517
|
-
*
|
|
516
|
+
* Prevents user-removable default scopes from applying when the Query is
|
|
517
|
+
* executed, including when associations are loaded. An STI child's reserved
|
|
518
|
+
* type discriminator remains enforced; query the STI base model to span its
|
|
519
|
+
* registered children.
|
|
520
|
+
*
|
|
521
|
+
* @returns A new Query which bypasses user-removable default scopes
|
|
518
522
|
*/
|
|
519
523
|
removeAllDefaultScopes(): Query<DreamInstance, QueryTypeOpts>;
|
|
520
524
|
/**
|
|
@@ -727,6 +731,12 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
727
731
|
* @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, or an UpdateQueryBuilder
|
|
728
732
|
*/
|
|
729
733
|
toKysely<QueryType extends 'select' | 'delete' | 'update', DbType = QueryToKyselyDBType<typeof this>, TableNames = QueryToKyselyTableNamesType<typeof this>, ToKyselyReturnType = QueryType extends 'select' ? SelectQueryBuilder<DbType, TableNames & keyof DbType, unknown> : QueryType extends 'delete' ? DeleteQueryBuilder<DbType, TableNames & keyof DbType, unknown> : QueryType extends 'update' ? UpdateQueryBuilder<DbType, TableNames & keyof DbType, TableNames & keyof DbType, unknown> : never>(type: QueryType): ToKyselyReturnType;
|
|
734
|
+
/**
|
|
735
|
+
* @internal
|
|
736
|
+
*
|
|
737
|
+
* Prevents mutation paths that discard an association query's ownership constraint.
|
|
738
|
+
*/
|
|
739
|
+
private assertMutationPreservesAssociationQuery;
|
|
730
740
|
/**
|
|
731
741
|
* Applies transaction to the Query instance
|
|
732
742
|
*
|
|
@@ -1351,7 +1361,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
1351
1361
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
1352
1362
|
* @param options.lock - If true, each batch is re-selected with an exclusive row lock inside its own transaction before being destroyed, making the destroy a compare-and-set. Defaults to false
|
|
1353
1363
|
* @param options.batchSize - The number of records to process per batch. Must be a positive integer. Defaults to 10 when `lock` is true, and to 1000 otherwise
|
|
1354
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
1364
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
1355
1365
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
1356
1366
|
* @returns The number of records that were removed
|
|
1357
1367
|
* @throws InvalidBatchSize if `batchSize` is not a positive integer
|
|
@@ -1469,7 +1479,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
1469
1479
|
* @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
1470
1480
|
* @param options.lock - If true, each batch is re-selected with an exclusive row lock inside its own transaction before being destroyed, making the destroy a compare-and-set. See {@link Query.destroy} for the full semantics. Defaults to false
|
|
1471
1481
|
* @param options.batchSize - The number of records to process per batch. Must be a positive integer. Defaults to 10 when `lock` is true, and to 1000 otherwise
|
|
1472
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
1482
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade destroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
1473
1483
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
|
|
1474
1484
|
* @returns The number of records that were removed
|
|
1475
1485
|
* @throws InvalidBatchSize if `batchSize` is not a positive integer
|
|
@@ -1502,7 +1512,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
1502
1512
|
* @param options - Options for undestroying the instance
|
|
1503
1513
|
* @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
|
|
1504
1514
|
* @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
|
|
1505
|
-
* @param options.bypassAllDefaultScopes - If true, bypasses
|
|
1515
|
+
* @param options.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when cascade undestroying; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
1506
1516
|
* @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
|
|
1507
1517
|
* @returns The number of records that were removed
|
|
1508
1518
|
* @throws BatchingIncompatibleWithLimitOrOffset if the query carries a `limit` or `offset`
|
|
@@ -20,6 +20,12 @@ export default class QueryDriverBase<DreamInstance extends Dream> {
|
|
|
20
20
|
*/
|
|
21
21
|
protected readonly innerJoinDreamClasses: readonly (typeof Dream)[];
|
|
22
22
|
constructor(query: Query<DreamInstance, any>);
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*
|
|
26
|
+
* Prevents mutation paths that discard an association query's ownership constraint.
|
|
27
|
+
*/
|
|
28
|
+
protected assertMutationPreservesAssociationQuery(): void;
|
|
23
29
|
static ensureAllMigrationsHaveBeenRun(connectionName: string): Promise<void>;
|
|
24
30
|
/**
|
|
25
31
|
* migrate the database. Must respond to the NODE_ENV value.
|