@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.
Files changed (224) hide show
  1. package/dist/cjs/src/Dream.js +15 -11
  2. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +7 -3
  3. package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +8 -8
  4. package/dist/cjs/src/dream/LoadBuilder.js +7 -4
  5. package/dist/cjs/src/dream/Query.js +25 -10
  6. package/dist/cjs/src/dream/QueryDriver/Base.js +12 -0
  7. package/dist/cjs/src/dream/QueryDriver/Kysely.js +11 -2
  8. package/dist/cjs/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
  9. package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +1 -1
  10. package/dist/cjs/src/dream/internal/reload.js +3 -1
  11. package/dist/cjs/src/dream/internal/shouldBypassDefaultScope.js +3 -4
  12. package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +4 -1
  13. package/dist/cjs/src/errors/NoUpdateOnAssociationQuery.js +1 -1
  14. package/dist/cjs/src/errors/sti/STIChildTypeMismatch.js +28 -0
  15. package/dist/esm/src/Dream.js +15 -11
  16. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +7 -3
  17. package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +8 -8
  18. package/dist/esm/src/dream/LoadBuilder.js +7 -4
  19. package/dist/esm/src/dream/Query.js +25 -10
  20. package/dist/esm/src/dream/QueryDriver/Base.js +12 -0
  21. package/dist/esm/src/dream/QueryDriver/Kysely.js +11 -2
  22. package/dist/esm/src/dream/internal/applyScopeBypassingSettingsToQuery.js +1 -1
  23. package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +1 -1
  24. package/dist/esm/src/dream/internal/reload.js +3 -1
  25. package/dist/esm/src/dream/internal/shouldBypassDefaultScope.js +3 -4
  26. package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +4 -1
  27. package/dist/esm/src/errors/NoUpdateOnAssociationQuery.js +1 -1
  28. package/dist/esm/src/errors/sti/STIChildTypeMismatch.js +28 -0
  29. package/dist/types/src/Dream.d.ts +10 -6
  30. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +8 -4
  31. package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +4 -4
  32. package/dist/types/src/dream/LoadBuilder.d.ts +6 -3
  33. package/dist/types/src/dream/Query.d.ts +18 -8
  34. package/dist/types/src/dream/QueryDriver/Base.d.ts +6 -0
  35. package/dist/types/src/dream/internal/destroyOptions.d.ts +3 -2
  36. package/dist/types/src/errors/sti/STIChildTypeMismatch.d.ts +11 -0
  37. package/docs/assets/hierarchy.js +1 -1
  38. package/docs/assets/search.js +1 -1
  39. package/docs/classes/db.DreamMigrationHelpers.html +11 -11
  40. package/docs/classes/db.KyselyQueryDriver.html +44 -42
  41. package/docs/classes/db.PostgresQueryDriver.html +45 -43
  42. package/docs/classes/db.QueryDriverBase.html +43 -41
  43. package/docs/classes/errors.CheckConstraintViolation.html +3 -3
  44. package/docs/classes/errors.ColumnOverflow.html +3 -3
  45. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  46. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
  47. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
  48. package/docs/classes/errors.DecryptionError.html +2 -2
  49. package/docs/classes/errors.DecryptionParseError.html +2 -2
  50. package/docs/classes/errors.DecryptionRotationError.html +3 -3
  51. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  52. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  53. package/docs/classes/errors.InvalidClockTime.html +2 -2
  54. package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
  55. package/docs/classes/errors.InvalidDateTime.html +2 -2
  56. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  57. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  58. package/docs/classes/errors.NotNullViolation.html +3 -3
  59. package/docs/classes/errors.RecordNotFound.html +3 -3
  60. package/docs/classes/errors.SortableBatchRequiresTooManyScopeLocks.html +3 -3
  61. package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
  62. package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
  63. package/docs/classes/errors.ValidationError.html +3 -3
  64. package/docs/classes/index.CalendarDate.html +33 -33
  65. package/docs/classes/index.ClockTime.html +32 -32
  66. package/docs/classes/index.ClockTimeTz.html +35 -35
  67. package/docs/classes/index.DateTime.html +86 -86
  68. package/docs/classes/index.Decorators.html +19 -19
  69. package/docs/classes/index.Dream.html +134 -131
  70. package/docs/classes/index.DreamApp.html +10 -10
  71. package/docs/classes/index.DreamTransaction.html +2 -2
  72. package/docs/classes/index.Env.html +2 -2
  73. package/docs/classes/index.Query.html +72 -69
  74. package/docs/classes/system.CliFileWriter.html +4 -4
  75. package/docs/classes/system.DreamBin.html +2 -2
  76. package/docs/classes/system.DreamCLI.html +7 -7
  77. package/docs/classes/system.DreamImporter.html +2 -2
  78. package/docs/classes/system.DreamLogos.html +2 -2
  79. package/docs/classes/system.DreamSerializerBuilder.html +11 -11
  80. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  81. package/docs/classes/system.PathHelpers.html +3 -3
  82. package/docs/classes/utils.Encrypt.html +3 -3
  83. package/docs/classes/utils.Range.html +2 -2
  84. package/docs/functions/db.closeAllDbConnections.html +1 -1
  85. package/docs/functions/db.dreamDbConnections.html +1 -1
  86. package/docs/functions/db.untypedDb.html +1 -1
  87. package/docs/functions/db.validateColumn.html +1 -1
  88. package/docs/functions/db.validateTable.html +1 -1
  89. package/docs/functions/errors.pgErrorType.html +1 -1
  90. package/docs/functions/index.DreamSerializer.html +1 -1
  91. package/docs/functions/index.ObjectSerializer.html +1 -1
  92. package/docs/functions/index.ReplicaSafe.html +1 -1
  93. package/docs/functions/index.STI.html +1 -1
  94. package/docs/functions/index.SoftDelete.html +1 -1
  95. package/docs/functions/utils.camelize.html +1 -1
  96. package/docs/functions/utils.capitalize.html +1 -1
  97. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  98. package/docs/functions/utils.compact.html +1 -1
  99. package/docs/functions/utils.groupBy.html +1 -1
  100. package/docs/functions/utils.hyphenize.html +1 -1
  101. package/docs/functions/utils.intersection.html +1 -1
  102. package/docs/functions/utils.isEmpty.html +1 -1
  103. package/docs/functions/utils.normalizeUnicode.html +1 -1
  104. package/docs/functions/utils.pascalize.html +1 -1
  105. package/docs/functions/utils.percent.html +1 -1
  106. package/docs/functions/utils.range.html +1 -1
  107. package/docs/functions/utils.round.html +1 -1
  108. package/docs/functions/utils.sanitizeString.html +1 -1
  109. package/docs/functions/utils.snakeify.html +1 -1
  110. package/docs/functions/utils.sort.html +1 -1
  111. package/docs/functions/utils.sortBy.html +1 -1
  112. package/docs/functions/utils.sortObjectByKey.html +1 -1
  113. package/docs/functions/utils.sortObjectByValue.html +1 -1
  114. package/docs/functions/utils.uncapitalize.html +1 -1
  115. package/docs/functions/utils.uniq.html +1 -1
  116. package/docs/hierarchy.html +1 -1
  117. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  118. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  119. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  120. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  121. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  122. package/docs/interfaces/types.DecoratorContext.html +2 -2
  123. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  124. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  125. package/docs/interfaces/types.DreamDbConfig.html +5 -5
  126. package/docs/interfaces/types.DurationObject.html +2 -2
  127. package/docs/interfaces/types.EncryptOptions.html +2 -2
  128. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  129. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  130. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  131. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  132. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  133. package/docs/types/openapi.OpenapiFormats.html +1 -1
  134. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  135. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  136. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  137. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  138. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  139. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  140. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  141. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  142. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  143. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  144. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  145. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  146. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  147. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  148. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  149. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  150. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  151. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  152. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  153. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  154. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  155. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  156. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  157. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  158. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  159. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  160. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  161. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  163. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  164. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  165. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  166. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  167. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  168. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  169. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  170. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  171. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  172. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  173. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  174. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  175. package/docs/types/types.CalendarDateObject.html +1 -1
  176. package/docs/types/types.Camelized.html +1 -1
  177. package/docs/types/types.ClockTimeObject.html +1 -1
  178. package/docs/types/types.DbConnectionType.html +1 -1
  179. package/docs/types/types.DbTypes.html +1 -1
  180. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  181. package/docs/types/types.DreamAttributes.html +1 -1
  182. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  183. package/docs/types/types.DreamClassColumn.html +1 -1
  184. package/docs/types/types.DreamColumn.html +1 -1
  185. package/docs/types/types.DreamColumnNames.html +1 -1
  186. package/docs/types/types.DreamLogLevel.html +1 -1
  187. package/docs/types/types.DreamLogger.html +2 -2
  188. package/docs/types/types.DreamModelSerializerType.html +1 -1
  189. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  190. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  191. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  192. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  193. package/docs/types/types.DreamSerializable.html +1 -1
  194. package/docs/types/types.DreamSerializableArray.html +1 -1
  195. package/docs/types/types.DreamSerializerKey.html +1 -1
  196. package/docs/types/types.DreamSerializers.html +1 -1
  197. package/docs/types/types.DreamVirtualColumns.html +1 -1
  198. package/docs/types/types.DurationUnit.html +1 -1
  199. package/docs/types/types.EncryptAlgorithm.html +1 -1
  200. package/docs/types/types.HasManyStatement.html +1 -1
  201. package/docs/types/types.HasOneStatement.html +1 -1
  202. package/docs/types/types.Hyphenized.html +1 -1
  203. package/docs/types/types.Pascalized.html +1 -1
  204. package/docs/types/types.PrimaryKeyType.html +1 -1
  205. package/docs/types/types.RoundingPrecision.html +1 -1
  206. package/docs/types/types.SerializerCasing.html +1 -1
  207. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  208. package/docs/types/types.Snakeified.html +1 -1
  209. package/docs/types/types.StrictInterface.html +1 -1
  210. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  211. package/docs/types/types.UpdateableProperties.html +1 -1
  212. package/docs/types/types.ValidationType.html +1 -1
  213. package/docs/types/types.ViewModel.html +2 -2
  214. package/docs/types/types.ViewModelClass.html +1 -1
  215. package/docs/types/types.WeekdayName.html +1 -1
  216. package/docs/types/types.WhereStatementForDream.html +1 -1
  217. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  218. package/docs/variables/index.DreamConst.html +1 -1
  219. package/docs/variables/index.ops.html +1 -1
  220. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  221. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  222. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  223. package/docs/variables/system.primaryKeyTypes.html +1 -1
  224. package/package.json +1 -1
@@ -878,12 +878,16 @@ export default class Dream {
878
878
  });
879
879
  }
880
880
  /**
881
- * Returns a query for this model which disregards default scopes
881
+ * @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
882
882
  *
883
- * @returns A query for this model which disregards default scopes
883
+ * Returns a query which bypasses user-removable default scopes, including on
884
+ * association loads. An STI child's reserved type discriminator remains
885
+ * enforced; query the STI base model to span its registered children.
886
+ *
887
+ * @returns A query which bypasses user-removable default scopes
884
888
  */
885
889
  static removeAllDefaultScopes() {
886
- return this.query().removeAllDefaultScopes();
890
+ return this.query()['removeAllDefaultScopes']();
887
891
  }
888
892
  /**
889
893
  * imports an object from the IOC. This is usually done in rare cases,
@@ -3141,7 +3145,7 @@ export default class Dream {
3141
3145
  * @param options - Options for destroying the instance
3142
3146
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3143
3147
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3144
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
3148
+ * @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
3145
3149
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
3146
3150
  * @returns The instance that was destroyed
3147
3151
  */
@@ -3166,7 +3170,7 @@ export default class Dream {
3166
3170
  * @param options - Options for destroying the instance
3167
3171
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3168
3172
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3169
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
3173
+ * @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
3170
3174
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
3171
3175
  * @returns The instance that was destroyed
3172
3176
  */
@@ -3181,14 +3185,14 @@ export default class Dream {
3181
3185
  * this will raise an exception.
3182
3186
  *
3183
3187
  * ```ts
3184
- * const user = await User.removeAllDefaultScopes().last()
3188
+ * const user = await User.removeDefaultScope('dream:SoftDelete').last()
3185
3189
  * await user.undestroy()
3186
3190
  * ```
3187
3191
  *
3188
3192
  * @param options - Options for undestroying the instance
3189
3193
  * @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
3190
3194
  * @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
3191
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade undestroying. Defaults to false
3195
+ * @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
3192
3196
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
3193
3197
  * @returns The undestroyed record
3194
3198
  */
@@ -3297,7 +3301,7 @@ export default class Dream {
3297
3301
  * @param options.andAny - Optional andAny statement to apply to query before destroying
3298
3302
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3299
3303
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3300
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
3304
+ * @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
3301
3305
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
3302
3306
  * @returns The number of records deleted
3303
3307
  */
@@ -3333,7 +3337,7 @@ export default class Dream {
3333
3337
  * @param options.andAny - Optional andAny statement to apply to query before destroying
3334
3338
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3335
3339
  * @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
3336
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
3340
+ * @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
3337
3341
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
3338
3342
  * @returns The number of records deleted
3339
3343
  */
@@ -3366,7 +3370,7 @@ export default class Dream {
3366
3370
  * @param options.andAny - Optional andAny statement to apply to query before undestroying
3367
3371
  * @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
3368
3372
  * @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
3369
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
3373
+ * @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
3370
3374
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when undestroying the association. Defaults to an empty array
3371
3375
  * @returns The number of records undestroyed
3372
3376
  */
@@ -3419,7 +3423,7 @@ export default class Dream {
3419
3423
  * @param options - Options for updating the association
3420
3424
  * @param options.and - Optional on statement to apply to query before updating
3421
3425
  * @param options.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
3422
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when updating the association. Defaults to false
3426
+ * @param options.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
3423
3427
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
3424
3428
  * @returns The number of updated records
3425
3429
  */
@@ -629,12 +629,16 @@ export default class DreamClassTransactionBuilder {
629
629
  return new Query(this.dreamInstance).txn(this.dreamTransaction);
630
630
  }
631
631
  /**
632
- * Returns a query for this model which disregards default scopes
632
+ * @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
633
633
  *
634
- * @returns A query for this model which disregards default scopes
634
+ * Returns a query which bypasses user-removable default scopes, including on
635
+ * association loads. An STI child's reserved type discriminator remains
636
+ * enforced; query the STI base model to span its registered children.
637
+ *
638
+ * @returns A query which bypasses user-removable default scopes
635
639
  */
636
640
  removeAllDefaultScopes() {
637
- return this.queryInstance().removeAllDefaultScopes();
641
+ return this.queryInstance()['removeAllDefaultScopes']();
638
642
  }
639
643
  /**
640
644
  * Prevents a specific default scope from applying when
@@ -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 all default scopes when cascade destroying. Defaults to false
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 all default scopes when cascade destroying. Defaults to false
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.removeAllDefaultScopes().last()
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 all default scopes when cascade undestroying. Defaults to false
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 all default scopes when updating the association. Defaults to false
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 all default scopes when destroying the association. Defaults to false
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 all default scopes when destroying the association. Defaults to false
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 all default scopes when undestroying the association. Defaults to false
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
- * Prevents all default scopes from applying when
48
- * loading associations
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
- * .removeAllDefaultScopes()
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.removeAllDefaultScopes();
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
- * Prevents default scopes from applying when
782
- * the Query is executed
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 will prevent default scopes from applying
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 all default scopes when cascade destroying. Defaults to false
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 all default scopes when cascade destroying. Defaults to false
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 all default scopes when cascade undestroying. Defaults to false
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
- if (this.baseSelectQuery)
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([this.dreamClass.primaryKey, this.dreamClass['isSTIBase'] ? 'type' : null, ...columns]));
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['bypassAllDefaultScopes'] || this.query['bypassAllDefaultScopesExceptOnAssociations'])
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.removeAllDefaultScopes();
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.removeAllDefaultScopes();
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.removeAllDefaultScopes().where({ [dream['_primaryKey']]: dream.primaryKeyValue() });
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.sanitizedName === type);
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
- udpate may not be called on an associationQuery. Use updateAssociation instead.
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
+ }
@@ -878,12 +878,16 @@ export default class Dream {
878
878
  });
879
879
  }
880
880
  /**
881
- * Returns a query for this model which disregards default scopes
881
+ * @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
882
882
  *
883
- * @returns A query for this model which disregards default scopes
883
+ * Returns a query which bypasses user-removable default scopes, including on
884
+ * association loads. An STI child's reserved type discriminator remains
885
+ * enforced; query the STI base model to span its registered children.
886
+ *
887
+ * @returns A query which bypasses user-removable default scopes
884
888
  */
885
889
  static removeAllDefaultScopes() {
886
- return this.query().removeAllDefaultScopes();
890
+ return this.query()['removeAllDefaultScopes']();
887
891
  }
888
892
  /**
889
893
  * imports an object from the IOC. This is usually done in rare cases,
@@ -3141,7 +3145,7 @@ export default class Dream {
3141
3145
  * @param options - Options for destroying the instance
3142
3146
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3143
3147
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3144
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
3148
+ * @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
3145
3149
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
3146
3150
  * @returns The instance that was destroyed
3147
3151
  */
@@ -3166,7 +3170,7 @@ export default class Dream {
3166
3170
  * @param options - Options for destroying the instance
3167
3171
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3168
3172
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3169
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
3173
+ * @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
3170
3174
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
3171
3175
  * @returns The instance that was destroyed
3172
3176
  */
@@ -3181,14 +3185,14 @@ export default class Dream {
3181
3185
  * this will raise an exception.
3182
3186
  *
3183
3187
  * ```ts
3184
- * const user = await User.removeAllDefaultScopes().last()
3188
+ * const user = await User.removeDefaultScope('dream:SoftDelete').last()
3185
3189
  * await user.undestroy()
3186
3190
  * ```
3187
3191
  *
3188
3192
  * @param options - Options for undestroying the instance
3189
3193
  * @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
3190
3194
  * @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
3191
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade undestroying. Defaults to false
3195
+ * @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
3192
3196
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
3193
3197
  * @returns The undestroyed record
3194
3198
  */
@@ -3297,7 +3301,7 @@ export default class Dream {
3297
3301
  * @param options.andAny - Optional andAny statement to apply to query before destroying
3298
3302
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3299
3303
  * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
3300
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
3304
+ * @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
3301
3305
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
3302
3306
  * @returns The number of records deleted
3303
3307
  */
@@ -3333,7 +3337,7 @@ export default class Dream {
3333
3337
  * @param options.andAny - Optional andAny statement to apply to query before destroying
3334
3338
  * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
3335
3339
  * @param options.cascade - If true, cascades the destroy operation to associations marked with `dependent: 'destroy'`. Defaults to true
3336
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when destroying the association. Defaults to false
3340
+ * @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
3337
3341
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when destroying the association. Defaults to an empty array
3338
3342
  * @returns The number of records deleted
3339
3343
  */
@@ -3366,7 +3370,7 @@ export default class Dream {
3366
3370
  * @param options.andAny - Optional andAny statement to apply to query before undestroying
3367
3371
  * @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
3368
3372
  * @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
3369
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when undestroying the association. Defaults to false
3373
+ * @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
3370
3374
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when undestroying the association. Defaults to an empty array
3371
3375
  * @returns The number of records undestroyed
3372
3376
  */
@@ -3419,7 +3423,7 @@ export default class Dream {
3419
3423
  * @param options - Options for updating the association
3420
3424
  * @param options.and - Optional on statement to apply to query before updating
3421
3425
  * @param options.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
3422
- * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when updating the association. Defaults to false
3426
+ * @param options.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
3423
3427
  * @param options.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
3424
3428
  * @returns The number of updated records
3425
3429
  */
@@ -629,12 +629,16 @@ export default class DreamClassTransactionBuilder {
629
629
  return new Query(this.dreamInstance).txn(this.dreamTransaction);
630
630
  }
631
631
  /**
632
- * Returns a query for this model which disregards default scopes
632
+ * @deprecated Use {@link removeDefaultScope} instead. This method will become private in v3.
633
633
  *
634
- * @returns A query for this model which disregards default scopes
634
+ * Returns a query which bypasses user-removable default scopes, including on
635
+ * association loads. An STI child's reserved type discriminator remains
636
+ * enforced; query the STI base model to span its registered children.
637
+ *
638
+ * @returns A query which bypasses user-removable default scopes
635
639
  */
636
640
  removeAllDefaultScopes() {
637
- return this.queryInstance().removeAllDefaultScopes();
641
+ return this.queryInstance()['removeAllDefaultScopes']();
638
642
  }
639
643
  /**
640
644
  * Prevents a specific default scope from applying when