@rvoh/dream 2.5.7 → 2.6.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 (250) hide show
  1. package/dist/cjs/src/Dream.js +37 -66
  2. package/dist/cjs/src/decorators/class/STI.js +2 -2
  3. package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +16 -10
  4. package/dist/cjs/src/dream/LoadBuilder.js +70 -9
  5. package/dist/cjs/src/dream/Query.js +5 -6
  6. package/dist/cjs/src/dream/constants.js +2 -0
  7. package/dist/cjs/src/dream/internal/buildAssociationPaths.js +33 -0
  8. package/dist/cjs/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
  9. package/dist/cjs/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
  10. package/dist/cjs/src/dream/internal/destroyAssociatedRecords.js +14 -6
  11. package/dist/cjs/src/dream/internal/destroyDream.js +7 -1
  12. package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +35 -0
  13. package/dist/cjs/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
  14. package/dist/cjs/src/serializer/SerializerRenderer.js +1 -1
  15. package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +114 -52
  16. package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
  17. package/dist/cjs/src/types/recursiveSerialization.js +1 -0
  18. package/dist/esm/src/Dream.js +37 -66
  19. package/dist/esm/src/decorators/class/STI.js +2 -2
  20. package/dist/esm/src/dream/LeftJoinLoadBuilder.js +16 -10
  21. package/dist/esm/src/dream/LoadBuilder.js +70 -9
  22. package/dist/esm/src/dream/Query.js +5 -6
  23. package/dist/esm/src/dream/constants.js +2 -0
  24. package/dist/esm/src/dream/internal/buildAssociationPaths.js +33 -0
  25. package/dist/esm/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
  26. package/dist/esm/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
  27. package/dist/esm/src/dream/internal/destroyAssociatedRecords.js +14 -6
  28. package/dist/esm/src/dream/internal/destroyDream.js +7 -1
  29. package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +35 -0
  30. package/dist/esm/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
  31. package/dist/esm/src/serializer/SerializerRenderer.js +1 -1
  32. package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +114 -52
  33. package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
  34. package/dist/esm/src/types/recursiveSerialization.js +1 -0
  35. package/dist/types/src/Dream.d.ts +25 -10
  36. package/dist/types/src/decorators/Decorators.d.ts +8 -0
  37. package/dist/types/src/decorators/class/STI.d.ts +1 -3
  38. package/dist/types/src/decorators/field/sortable/Sortable.d.ts +9 -0
  39. package/dist/types/src/decorators/field/validation/Validates.d.ts +4 -0
  40. package/dist/types/src/decorators/static-method/Scope.d.ts +4 -0
  41. package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +16 -10
  42. package/dist/types/src/dream/LoadBuilder.d.ts +63 -10
  43. package/dist/types/src/dream/Query.d.ts +1 -1
  44. package/dist/types/src/dream/constants.d.ts +2 -0
  45. package/dist/types/src/dream/internal/buildAssociationPaths.d.ts +12 -0
  46. package/dist/types/src/dream/internal/buildDependentDestroyPreloadPaths.d.ts +17 -0
  47. package/dist/types/src/dream/internal/buildSerializerPreloadPaths.d.ts +3 -0
  48. package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +1 -1
  49. package/dist/types/src/dream/internal/destroyAssociatedRecords.d.ts +5 -1
  50. package/dist/types/src/dream/internal/loadDependentDestroyTree.d.ts +17 -0
  51. package/dist/types/src/dream/internal/resolveSerializerAssociationEdges.d.ts +13 -0
  52. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +164 -63
  53. package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +126 -43
  54. package/dist/types/src/types/associations/belongsTo.d.ts +34 -0
  55. package/dist/types/src/types/associations/belongsTo.ts +41 -0
  56. package/dist/types/src/types/associations/hasMany.d.ts +18 -0
  57. package/dist/types/src/types/associations/hasMany.ts +18 -0
  58. package/dist/types/src/types/associations/shared.d.ts +71 -0
  59. package/dist/types/src/types/associations/shared.ts +74 -0
  60. package/dist/types/src/types/dream.d.ts +16 -0
  61. package/dist/types/src/types/dream.ts +18 -0
  62. package/dist/types/src/types/lifecycle.d.ts +18 -0
  63. package/dist/types/src/types/lifecycle.ts +18 -0
  64. package/dist/types/src/types/query.d.ts +3 -0
  65. package/dist/types/src/types/query.ts +3 -0
  66. package/dist/types/src/types/recursiveSerialization.d.ts +8 -0
  67. package/dist/types/src/types/recursiveSerialization.ts +10 -0
  68. package/dist/types/src/types/serializer.d.ts +8 -1
  69. package/dist/types/src/types/serializer.ts +8 -1
  70. package/docs/classes/db.DreamMigrationHelpers.html +9 -9
  71. package/docs/classes/db.KyselyQueryDriver.html +32 -32
  72. package/docs/classes/db.PostgresQueryDriver.html +33 -33
  73. package/docs/classes/db.QueryDriverBase.html +31 -31
  74. package/docs/classes/errors.CheckConstraintViolation.html +3 -3
  75. package/docs/classes/errors.ColumnOverflow.html +3 -3
  76. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  77. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
  78. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
  79. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  80. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  81. package/docs/classes/errors.InvalidClockTime.html +2 -2
  82. package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
  83. package/docs/classes/errors.InvalidDateTime.html +2 -2
  84. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  85. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  86. package/docs/classes/errors.NotNullViolation.html +3 -3
  87. package/docs/classes/errors.RecordNotFound.html +3 -3
  88. package/docs/classes/errors.ValidationError.html +3 -3
  89. package/docs/classes/index.CalendarDate.html +33 -33
  90. package/docs/classes/index.ClockTime.html +32 -32
  91. package/docs/classes/index.ClockTimeTz.html +35 -35
  92. package/docs/classes/index.DateTime.html +86 -86
  93. package/docs/classes/index.Decorators.html +21 -20
  94. package/docs/classes/index.Dream.html +133 -126
  95. package/docs/classes/index.DreamApp.html +5 -5
  96. package/docs/classes/index.DreamTransaction.html +2 -2
  97. package/docs/classes/index.Env.html +2 -2
  98. package/docs/classes/index.Query.html +57 -57
  99. package/docs/classes/system.CliFileWriter.html +4 -4
  100. package/docs/classes/system.DreamBin.html +2 -2
  101. package/docs/classes/system.DreamCLI.html +6 -6
  102. package/docs/classes/system.DreamImporter.html +2 -2
  103. package/docs/classes/system.DreamLogos.html +2 -2
  104. package/docs/classes/system.DreamSerializerBuilder.html +177 -59
  105. package/docs/classes/system.ObjectSerializerBuilder.html +110 -34
  106. package/docs/classes/system.PathHelpers.html +3 -3
  107. package/docs/classes/utils.Encrypt.html +2 -2
  108. package/docs/classes/utils.Range.html +2 -2
  109. package/docs/functions/db.closeAllDbConnections.html +1 -1
  110. package/docs/functions/db.dreamDbConnections.html +1 -1
  111. package/docs/functions/db.untypedDb.html +1 -1
  112. package/docs/functions/db.validateColumn.html +1 -1
  113. package/docs/functions/db.validateTable.html +1 -1
  114. package/docs/functions/errors.pgErrorType.html +1 -1
  115. package/docs/functions/index.DreamSerializer.html +1 -1
  116. package/docs/functions/index.ObjectSerializer.html +1 -1
  117. package/docs/functions/index.ReplicaSafe.html +1 -1
  118. package/docs/functions/index.STI.html +1 -1
  119. package/docs/functions/index.SoftDelete.html +1 -1
  120. package/docs/functions/utils.camelize.html +1 -1
  121. package/docs/functions/utils.capitalize.html +1 -1
  122. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  123. package/docs/functions/utils.compact.html +1 -1
  124. package/docs/functions/utils.groupBy.html +1 -1
  125. package/docs/functions/utils.hyphenize.html +1 -1
  126. package/docs/functions/utils.intersection.html +1 -1
  127. package/docs/functions/utils.isEmpty.html +1 -1
  128. package/docs/functions/utils.normalizeUnicode.html +1 -1
  129. package/docs/functions/utils.pascalize.html +1 -1
  130. package/docs/functions/utils.percent.html +1 -1
  131. package/docs/functions/utils.range.html +1 -1
  132. package/docs/functions/utils.round.html +1 -1
  133. package/docs/functions/utils.sanitizeString.html +1 -1
  134. package/docs/functions/utils.snakeify.html +1 -1
  135. package/docs/functions/utils.sort.html +1 -1
  136. package/docs/functions/utils.sortBy.html +1 -1
  137. package/docs/functions/utils.sortObjectByKey.html +1 -1
  138. package/docs/functions/utils.sortObjectByValue.html +1 -1
  139. package/docs/functions/utils.uncapitalize.html +1 -1
  140. package/docs/functions/utils.uniq.html +1 -1
  141. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  142. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  143. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  144. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  145. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  146. package/docs/interfaces/types.DecoratorContext.html +2 -2
  147. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  148. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  149. package/docs/interfaces/types.DurationObject.html +2 -2
  150. package/docs/interfaces/types.EncryptOptions.html +2 -2
  151. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  152. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  153. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  154. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  155. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  156. package/docs/types/openapi.OpenapiFormats.html +1 -1
  157. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  158. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  159. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  160. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  161. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  163. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  164. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  165. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  166. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  167. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  168. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  169. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  170. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  171. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  172. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  173. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  174. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  175. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  176. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  177. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  178. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  179. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  180. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  181. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  182. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  183. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  184. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  185. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  186. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  187. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  188. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  189. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  190. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  191. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  192. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  193. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  194. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  195. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  196. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  197. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  198. package/docs/types/types.CalendarDateObject.html +1 -1
  199. package/docs/types/types.Camelized.html +1 -1
  200. package/docs/types/types.ClockTimeObject.html +1 -1
  201. package/docs/types/types.DbConnectionType.html +1 -1
  202. package/docs/types/types.DbTypes.html +1 -1
  203. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  204. package/docs/types/types.DreamAttributes.html +1 -1
  205. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  206. package/docs/types/types.DreamClassColumn.html +1 -1
  207. package/docs/types/types.DreamColumn.html +1 -1
  208. package/docs/types/types.DreamColumnNames.html +1 -1
  209. package/docs/types/types.DreamLogLevel.html +1 -1
  210. package/docs/types/types.DreamLogger.html +2 -2
  211. package/docs/types/types.DreamModelSerializerType.html +1 -1
  212. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  213. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  214. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  215. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  216. package/docs/types/types.DreamSerializable.html +1 -1
  217. package/docs/types/types.DreamSerializableArray.html +1 -1
  218. package/docs/types/types.DreamSerializerKey.html +1 -1
  219. package/docs/types/types.DreamSerializers.html +1 -1
  220. package/docs/types/types.DreamVirtualColumns.html +1 -1
  221. package/docs/types/types.DurationUnit.html +1 -1
  222. package/docs/types/types.EncryptAlgorithm.html +1 -1
  223. package/docs/types/types.HasManyStatement.html +1 -1
  224. package/docs/types/types.HasOneStatement.html +1 -1
  225. package/docs/types/types.Hyphenized.html +1 -1
  226. package/docs/types/types.Pascalized.html +1 -1
  227. package/docs/types/types.PrimaryKeyType.html +1 -1
  228. package/docs/types/types.RoundingPrecision.html +1 -1
  229. package/docs/types/types.SerializerCasing.html +1 -1
  230. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  231. package/docs/types/types.Snakeified.html +1 -1
  232. package/docs/types/types.StrictInterface.html +1 -1
  233. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  234. package/docs/types/types.UpdateableProperties.html +1 -1
  235. package/docs/types/types.ValidationType.html +1 -1
  236. package/docs/types/types.ViewModel.html +2 -2
  237. package/docs/types/types.ViewModelClass.html +1 -1
  238. package/docs/types/types.WeekdayName.html +1 -1
  239. package/docs/types/types.WhereStatementForDream.html +1 -1
  240. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  241. package/docs/variables/index.DreamConst.html +1 -1
  242. package/docs/variables/index.ops.html +1 -1
  243. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  244. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  245. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  246. package/docs/variables/system.primaryKeyTypes.html +1 -1
  247. package/package.json +1 -1
  248. package/dist/cjs/src/dream/internal/extractNestedPaths.js +0 -34
  249. package/dist/esm/src/dream/internal/extractNestedPaths.js +0 -34
  250. package/dist/types/src/dream/internal/extractNestedPaths.d.ts +0 -21
@@ -56,6 +56,10 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
56
56
  * @returns A Scope decorator
57
57
  */
58
58
  Scope(this: Decorators<TD>, opts?: {
59
+ /**
60
+ * If `true`, this scope will be applied automatically to all queries involving this model.
61
+ * Defaults to `false`.
62
+ */
59
63
  default?: boolean;
60
64
  }): any;
61
65
  /**
@@ -116,10 +120,14 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
116
120
  * @returns A Validates decorator
117
121
  */
118
122
  Validates<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
123
+ /** The minimum allowed value (inclusive). */
119
124
  min?: number;
125
+ /** The maximum allowed value (inclusive). */
120
126
  max?: number;
121
127
  } : VT extends 'length' ? {
128
+ /** The minimum allowed length (inclusive). */
122
129
  min: number;
130
+ /** The maximum allowed length (inclusive). */
123
131
  max?: number;
124
132
  } : VT extends 'contains' ? string | RegExp : never>(this: Decorators<TD>, type: VT, args?: VTArgs): any;
125
133
  /**
@@ -1,5 +1,3 @@
1
1
  import Dream from '../../Dream.js';
2
2
  export declare const STI_SCOPE_NAME = "dream:STI";
3
- export default function STI(dreamClass: typeof Dream, { value }?: {
4
- value?: string;
5
- }): ClassDecorator;
3
+ export default function STI(dreamClass: typeof Dream): ClassDecorator;
@@ -1,5 +1,14 @@
1
1
  export default function Sortable(opts?: SortableOpts): any;
2
2
  interface SortableOpts {
3
+ /**
4
+ * A column name or array of column names that define the scope within which
5
+ * position values are unique. Records are sorted independently within each scope.
6
+ *
7
+ * ```ts
8
+ * @deco.Sortable({ scope: 'species' })
9
+ * public positionWithinSpecies: number
10
+ * ```
11
+ */
3
12
  scope?: string | string[];
4
13
  }
5
14
  export interface SortableFieldConfig {
@@ -1,10 +1,14 @@
1
1
  import Dream from '../../../Dream.js';
2
2
  import { ValidationType } from '../../../types/validation.js';
3
3
  export default function Validates<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
4
+ /** The minimum allowed value (inclusive). */
4
5
  min?: number;
6
+ /** The maximum allowed value (inclusive). */
5
7
  max?: number;
6
8
  } : VT extends 'length' ? {
9
+ /** The minimum allowed length (inclusive). */
7
10
  min: number;
11
+ /** The maximum allowed length (inclusive). */
8
12
  max?: number;
9
13
  } : VT extends 'contains' ? string | RegExp : never>(type: VT, args?: VTArgs): any;
10
14
  export declare function validatesImplementation<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
@@ -1,5 +1,9 @@
1
1
  import Dream from '../../Dream.js';
2
2
  export default function Scope(opts?: {
3
+ /**
4
+ * If `true`, this scope will be applied automatically to all queries involving this model.
5
+ * Defaults to `false`.
6
+ */
3
7
  default?: boolean;
4
8
  }): any;
5
9
  export declare function scopeImplementation(t: typeof Dream, key: string, opts?: {
@@ -8,13 +8,16 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
8
8
  private dream;
9
9
  private query;
10
10
  /**
11
- * An intermediate class on the way to executing a load
12
- * query. this can be accessed on an instance of a dream
13
- * model by using the `#load` method:
11
+ * An intermediate builder for loading associations onto a Dream model
12
+ * via a single left-join SQL query. Accessed via `#leftJoinLoad`.
13
+ *
14
+ * **Note:** The LeftJoinLoadBuilder works on a clone of the original model.
15
+ * Call `.execute()` to get the clone with associations loaded.
14
16
  *
15
17
  * ```ts
16
18
  * const user = await User.firstOrFail()
17
- * await user.load('settings').execute()
19
+ * const loaded = await user.leftJoinLoad('settings').execute()
20
+ * loaded.settings // association is loaded on the returned clone
18
21
  * ```
19
22
  */
20
23
  constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
@@ -32,17 +35,20 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
32
35
  */
33
36
  leftJoinLoad<I extends LeftJoinLoadBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[], const LastArg extends VariadicLeftJoinLoadArgs<DreamInstance, DB, Schema, TableName, Arr>>(this: I, ...args: [...Arr, LastArg]): I;
34
37
  /**
35
- * executes a load builder query, binding
36
- * all associations to their respective model
37
- * instances.
38
+ * Executes the left-join load query, returning a **clone** of the original model
39
+ * with all requested associations loaded. The original instance is not modified.
38
40
  *
39
41
  * ```ts
40
42
  * const user = await User.firstOrFail()
41
- * await user
42
- * .load('settings')
43
- * .load('posts', 'comments', 'replies', ['image', 'localizedText'])
43
+ * const loaded = await user
44
+ * .leftJoinLoad('settings')
45
+ * .leftJoinLoad('posts', 'comments', 'replies')
44
46
  * .execute()
47
+ *
48
+ * loaded.settings // works — associations are on the returned clone
45
49
  * ```
50
+ *
51
+ * @returns A clone of the Dream instance with all requested associations loaded
46
52
  */
47
53
  execute(): Promise<DreamInstance>;
48
54
  private associationToPreloadedDreamsAndWhatTheyPointTo;
@@ -1,6 +1,7 @@
1
1
  import Dream from '../Dream.js';
2
2
  import { PassthroughOnClause } from '../types/associations/shared.js';
3
- import { DreamSerializerKey, PassthroughColumnNames } from '../types/dream.js';
3
+ import { DbConnectionType } from '../types/db.js';
4
+ import { AllDefaultScopeNames, DreamSerializerKey, PassthroughColumnNames } from '../types/dream.js';
4
5
  import { LoadForModifierFn } from '../types/query.js';
5
6
  import { VariadicLoadArgs } from '../types/variadic.js';
6
7
  import DreamTransaction from './DreamTransaction.js';
@@ -9,17 +10,66 @@ export default class LoadBuilder<DreamInstance extends Dream> {
9
10
  private dream;
10
11
  private query;
11
12
  /**
12
- * An intermediate class on the way to executing a load
13
- * query. this can be accessed on an instance of a dream
14
- * model by using the `#load` method:
13
+ * An intermediate builder for loading associations onto a Dream model.
14
+ * Accessed via the `#load` method on a Dream instance.
15
+ *
16
+ * **Note:** The LoadBuilder works on a clone of the original model.
17
+ * Call `.execute()` to get the clone with associations loaded.
15
18
  *
16
19
  * ```ts
17
20
  * const user = await User.firstOrFail()
18
- * await user.load('settings').execute()
21
+ * const loaded = await user.load('settings').execute()
22
+ * loaded.settings // association is loaded on the returned clone
19
23
  * ```
20
24
  */
21
25
  constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
22
26
  passthrough<I extends LoadBuilder<DreamInstance>, PassthroughColumns extends PassthroughColumnNames<DreamInstance>>(this: I, passthroughWhereStatement: PassthroughOnClause<PassthroughColumns>): I;
27
+ /**
28
+ * Prevents a specific default scope from applying when
29
+ * loading associations
30
+ *
31
+ * ```ts
32
+ * const user = await User.firstOrFail()
33
+ * const loaded = await user
34
+ * .load('posts')
35
+ * .removeDefaultScope('dream:SoftDelete')
36
+ * .execute()
37
+ * ```
38
+ *
39
+ * @param scopeName - The default scope to bypass
40
+ * @returns The LoadBuilder instance for chaining
41
+ */
42
+ removeDefaultScope<I extends LoadBuilder<DreamInstance>>(this: I, scopeName: AllDefaultScopeNames<DreamInstance>): I;
43
+ /**
44
+ * Prevents all default scopes from applying when
45
+ * loading associations
46
+ *
47
+ * ```ts
48
+ * const user = await User.firstOrFail()
49
+ * const loaded = await user
50
+ * .load('posts')
51
+ * .removeAllDefaultScopes()
52
+ * .execute()
53
+ * ```
54
+ *
55
+ * @returns The LoadBuilder instance for chaining
56
+ */
57
+ removeAllDefaultScopes<I extends LoadBuilder<DreamInstance>>(this: I): I;
58
+ /**
59
+ * Sets the database connection to use when loading associations
60
+ *
61
+ * ```ts
62
+ * const user = await User.firstOrFail()
63
+ * const loaded = await user
64
+ * .load('posts')
65
+ * .connection('replica')
66
+ * .execute()
67
+ * ```
68
+ *
69
+ * @param connection - The connection type ('primary' or 'replica')
70
+ * @returns The LoadBuilder instance for chaining
71
+ */
72
+ connection<I extends LoadBuilder<DreamInstance>>(this: I, connection: DbConnectionType): I;
23
73
  /**
24
74
  * Attaches a load statement to the load builder
25
75
  *
@@ -82,19 +132,22 @@ export default class LoadBuilder<DreamInstance extends Dream> {
82
132
  */
83
133
  loadFor<I extends LoadBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): I;
84
134
  /**
85
- * Executes a load builder query, binding
86
- * all associations to their respective model
87
- * instances.
135
+ * Executes the load query, binding all associations to a **clone** of the
136
+ * original model instance. The original instance is not modified.
137
+ *
138
+ * You must use the returned value to access the loaded associations:
88
139
  *
89
140
  * ```ts
90
141
  * const user = await User.firstOrFail()
91
- * await user
142
+ * const loaded = await user
92
143
  * .load('settings')
93
144
  * .load('posts', 'comments', 'replies', ['image', 'localizedText'])
94
145
  * .execute()
146
+ *
147
+ * loaded.settings // works — associations are on the returned clone
95
148
  * ```
96
149
  *
97
- * @returns The Dream instance with all associations loaded
150
+ * @returns A clone of the Dream instance with all requested associations loaded
98
151
  */
99
152
  execute(): Promise<DreamInstance>;
100
153
  }
@@ -1146,7 +1146,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
1146
1146
  * Updates all records matching the Query
1147
1147
  *
1148
1148
  * ```ts
1149
- * await User.where({ email: ops.ilike('%burpcollaborator%') }).updateAll({ email: null })
1149
+ * await User.where({ email: ops.ilike('%burpcollaborator%') }).update({ email: null })
1150
1150
  * // 12
1151
1151
  * ```
1152
1152
  * @param attributes - The attributes used to update the records
@@ -1,5 +1,7 @@
1
1
  export declare const primaryKeyTypes: readonly ["uuid7", "uuid4", "bigserial", "bigint", "integer"];
2
2
  export declare const TRIGRAM_OPERATORS: readonly ["%", "<%", "<<%"];
3
+ export declare const RECURSIVE_SERIALIZATION_MAX_REPEATS = 4;
4
+ export declare const RECURSIVE_DESTROY_PRELOAD_MAX_REPEATS = 4;
3
5
  declare class RequiredAttribute {
4
6
  constructor();
5
7
  }
@@ -0,0 +1,12 @@
1
+ import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
2
+ export interface AssociationPathEdge<NodeType> {
3
+ nextNode: NodeType | null;
4
+ tuple: DreamClassAndAssociationNameTuple;
5
+ }
6
+ export default function buildAssociationPaths<NodeType>(rootNode: NodeType, opts: BuildAssociationPathsOptions<NodeType>): DreamClassAndAssociationNameTuple[][];
7
+ type BuildAssociationPathsOptions<NodeType> = {
8
+ getKey: (node: NodeType) => string;
9
+ getEdges: (node: NodeType) => AssociationPathEdge<NodeType>[];
10
+ maxRepeats: number;
11
+ };
12
+ export {};
@@ -0,0 +1,17 @@
1
+ import Dream from '../../Dream.js';
2
+ import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
3
+ /**
4
+ * @internal
5
+ *
6
+ * Recursively walks `dependent: 'destroy'` associations starting from the given
7
+ * Dream class, producing an array of preload paths. Each path is an array of
8
+ * [DreamClass, associationName] tuples representing a chain from root to leaf.
9
+ *
10
+ * Allows the same Dream class to appear up to MAX_REPEATS times in a single
11
+ * path to support tree structures (e.g. a Category with `dependent: 'destroy'`
12
+ * on its children, which are also Categories).
13
+ *
14
+ * Used to build a preload tree so that all records in the cascade can be loaded
15
+ * upfront, eliminating N+1 queries during destroy.
16
+ */
17
+ export default function buildDependentDestroyPreloadPaths(dreamClass: typeof Dream): DreamClassAndAssociationNameTuple[][];
@@ -0,0 +1,3 @@
1
+ import Dream from '../../Dream.js';
2
+ import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
3
+ export default function buildSerializerPreloadPaths(dreamClass: typeof Dream, serializerKey?: string): DreamClassAndAssociationNameTuple[][];
@@ -1,5 +1,5 @@
1
1
  import { LoadForModifierFn } from '../../types/query.js';
2
- import { DreamClassAndAssociationNameTuple } from './extractNestedPaths.js';
2
+ import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
3
3
  export default function convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray: DreamClassAndAssociationNameTuple[], modifierFn?: LoadForModifierFn, counter?: {
4
4
  count: number;
5
5
  }): (string | {
@@ -5,6 +5,10 @@ import { ReallyDestroyOptions } from './destroyDream.js';
5
5
  * @internal
6
6
  *
7
7
  * Destroys all HasOne/HasMany associations on this
8
- * dream that are marked as `dependent: 'destroy'`
8
+ * dream that are marked as `dependent: 'destroy'`.
9
+ *
10
+ * Expects associations to be preloaded onto the dream instance
11
+ * via `loadDependentDestroyTree`. Iterates loaded associations
12
+ * directly instead of querying the database.
9
13
  */
10
14
  export default function destroyAssociatedRecords<I extends Dream>(dream: I, txn: DreamTransaction<I>, options: ReallyDestroyOptions<I>): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import Dream from '../../Dream.js';
2
+ import { AllDefaultScopeNames } from '../../types/dream.js';
3
+ import DreamTransaction from '../DreamTransaction.js';
4
+ /**
5
+ * @internal
6
+ *
7
+ * Loads all `dependent: 'destroy'` associations onto the dream instance
8
+ * upfront, eliminating N+1 queries during cascade destruction.
9
+ *
10
+ * Returns a clone of the dream with all associations loaded.
11
+ * If there are no dependent-destroy associations, returns the original dream.
12
+ */
13
+ export default function loadDependentDestroyTree<I extends Dream>(dream: I, txn: DreamTransaction<I>, { reallyDestroy, bypassAllDefaultScopes, defaultScopesToBypass, }: {
14
+ reallyDestroy: boolean;
15
+ bypassAllDefaultScopes: boolean;
16
+ defaultScopesToBypass: AllDefaultScopeNames<I>[];
17
+ }): Promise<I>;
@@ -0,0 +1,13 @@
1
+ import Dream from '../../Dream.js';
2
+ import { DreamModelSerializerType, SimpleObjectSerializerType } from '../../types/serializer.js';
3
+ export interface ResolvedSerializerAssociationEdge {
4
+ associationAs: string;
5
+ sourceDreamClass: typeof Dream;
6
+ type: 'rendersOne' | 'rendersMany' | 'delegatedAttribute';
7
+ serializerAssociationName: string;
8
+ targets: {
9
+ dreamClass: typeof Dream;
10
+ serializer: DreamModelSerializerType | SimpleObjectSerializerType;
11
+ }[];
12
+ }
13
+ export default function resolveSerializerAssociationEdges(dreamClass: typeof Dream, serializer: DreamModelSerializerType | SimpleObjectSerializerType): ResolvedSerializerAssociationEdge[];