@rvoh/dream 0.45.0 → 0.45.1

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 (196) hide show
  1. package/dist/cjs/src/Dream.js +118 -36
  2. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +92 -0
  3. package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +98 -0
  4. package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +52 -1
  5. package/dist/cjs/src/dream/LoadBuilder.js +49 -0
  6. package/dist/cjs/src/dream/Query.js +31 -57
  7. package/dist/cjs/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +18 -0
  8. package/dist/cjs/src/dream/internal/unaliasTableName.js +7 -0
  9. package/dist/esm/src/Dream.js +118 -36
  10. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +92 -0
  11. package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +98 -0
  12. package/dist/esm/src/dream/LeftJoinLoadBuilder.js +52 -1
  13. package/dist/esm/src/dream/LoadBuilder.js +49 -0
  14. package/dist/esm/src/dream/Query.js +31 -57
  15. package/dist/esm/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +15 -0
  16. package/dist/esm/src/dream/internal/unaliasTableName.js +4 -0
  17. package/dist/types/src/Dream.d.ts +113 -49
  18. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +108 -2
  19. package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +96 -2
  20. package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +48 -1
  21. package/dist/types/src/dream/LoadBuilder.d.ts +48 -1
  22. package/dist/types/src/dream/Query.d.ts +32 -59
  23. package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +9 -0
  24. package/dist/types/src/dream/internal/unaliasTableName.d.ts +1 -0
  25. package/dist/types/src/types/query.d.ts +5 -0
  26. package/dist/types/src/types/query.ts +5 -0
  27. package/docs/assets/search.js +1 -1
  28. package/docs/classes/Benchmark.html +2 -2
  29. package/docs/classes/CalendarDate.html +2 -2
  30. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  31. package/docs/classes/Decorators.html +19 -19
  32. package/docs/classes/Dream.html +220 -186
  33. package/docs/classes/DreamApp.html +4 -4
  34. package/docs/classes/DreamBin.html +2 -2
  35. package/docs/classes/DreamCLI.html +4 -4
  36. package/docs/classes/DreamImporter.html +2 -2
  37. package/docs/classes/DreamLogos.html +2 -2
  38. package/docs/classes/DreamMigrationHelpers.html +7 -7
  39. package/docs/classes/DreamSerializerBuilder.html +8 -8
  40. package/docs/classes/DreamTransaction.html +2 -2
  41. package/docs/classes/Encrypt.html +2 -2
  42. package/docs/classes/Env.html +2 -2
  43. package/docs/classes/GlobalNameNotSet.html +3 -3
  44. package/docs/classes/NonLoadedAssociation.html +3 -3
  45. package/docs/classes/ObjectSerializerBuilder.html +8 -8
  46. package/docs/classes/Query.html +70 -66
  47. package/docs/classes/Range.html +2 -2
  48. package/docs/classes/RecordNotFound.html +3 -3
  49. package/docs/classes/ValidationError.html +3 -3
  50. package/docs/functions/DreamSerializer.html +1 -1
  51. package/docs/functions/ObjectSerializer.html +1 -1
  52. package/docs/functions/ReplicaSafe.html +1 -1
  53. package/docs/functions/STI.html +1 -1
  54. package/docs/functions/SoftDelete.html +1 -1
  55. package/docs/functions/camelize.html +1 -1
  56. package/docs/functions/capitalize.html +1 -1
  57. package/docs/functions/cloneDeepSafe.html +1 -1
  58. package/docs/functions/closeAllDbConnections.html +1 -1
  59. package/docs/functions/compact.html +1 -1
  60. package/docs/functions/dreamDbConnections.html +1 -1
  61. package/docs/functions/dreamPath.html +1 -1
  62. package/docs/functions/expandStiClasses.html +1 -1
  63. package/docs/functions/generateDream.html +1 -1
  64. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  65. package/docs/functions/groupBy.html +1 -1
  66. package/docs/functions/hyphenize.html +1 -1
  67. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  68. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
  69. package/docs/functions/intersection.html +1 -1
  70. package/docs/functions/isDreamSerializer.html +1 -1
  71. package/docs/functions/isEmpty.html +1 -1
  72. package/docs/functions/loadRepl.html +1 -1
  73. package/docs/functions/lookupClassByGlobalName.html +1 -1
  74. package/docs/functions/normalizeUnicode.html +1 -1
  75. package/docs/functions/pascalize.html +1 -1
  76. package/docs/functions/pgErrorType.html +1 -1
  77. package/docs/functions/range-1.html +1 -1
  78. package/docs/functions/relativeDreamPath.html +1 -1
  79. package/docs/functions/round.html +1 -1
  80. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  81. package/docs/functions/sharedPathPrefix.html +1 -1
  82. package/docs/functions/snakeify.html +1 -1
  83. package/docs/functions/sort.html +1 -1
  84. package/docs/functions/sortBy.html +1 -1
  85. package/docs/functions/sortObjectByKey.html +1 -1
  86. package/docs/functions/sortObjectByValue.html +1 -1
  87. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  88. package/docs/functions/uncapitalize.html +1 -1
  89. package/docs/functions/uniq.html +1 -1
  90. package/docs/functions/untypedDb.html +1 -1
  91. package/docs/functions/validateColumn.html +1 -1
  92. package/docs/functions/validateTable.html +1 -1
  93. package/docs/interfaces/BelongsToStatement.html +2 -2
  94. package/docs/interfaces/DecoratorContext.html +2 -2
  95. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  96. package/docs/interfaces/DreamAppOpts.html +2 -2
  97. package/docs/interfaces/EncryptOptions.html +2 -2
  98. package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
  99. package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
  100. package/docs/interfaces/OpenapiDescription.html +2 -2
  101. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  102. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  103. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  104. package/docs/interfaces/SerializerRendererOpts.html +2 -2
  105. package/docs/types/Camelized.html +1 -1
  106. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  107. package/docs/types/DateTime.html +1 -1
  108. package/docs/types/DbConnectionType.html +1 -1
  109. package/docs/types/DbTypes.html +1 -1
  110. package/docs/types/DreamAssociationMetadata.html +1 -1
  111. package/docs/types/DreamAttributes.html +1 -1
  112. package/docs/types/DreamClassAssociationAndStatement.html +1 -1
  113. package/docs/types/DreamClassColumn.html +1 -1
  114. package/docs/types/DreamColumn.html +1 -1
  115. package/docs/types/DreamColumnNames.html +1 -1
  116. package/docs/types/DreamLogLevel.html +1 -1
  117. package/docs/types/DreamLogger.html +1 -1
  118. package/docs/types/DreamModelSerializerType.html +1 -1
  119. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  120. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  121. package/docs/types/DreamParamSafeAttributes.html +1 -1
  122. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  123. package/docs/types/DreamSerializable.html +1 -1
  124. package/docs/types/DreamSerializableArray.html +1 -1
  125. package/docs/types/DreamSerializerKey.html +1 -1
  126. package/docs/types/DreamSerializers.html +1 -1
  127. package/docs/types/DreamTableSchema.html +1 -1
  128. package/docs/types/DreamVirtualColumns.html +1 -1
  129. package/docs/types/EncryptAlgorithm.html +1 -1
  130. package/docs/types/HasManyStatement.html +1 -1
  131. package/docs/types/HasOneStatement.html +1 -1
  132. package/docs/types/Hyphenized.html +1 -1
  133. package/docs/types/IdType.html +1 -1
  134. package/docs/types/OpenapiAllTypes.html +1 -1
  135. package/docs/types/OpenapiFormats.html +1 -1
  136. package/docs/types/OpenapiNumberFormats.html +1 -1
  137. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
  138. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  139. package/docs/types/OpenapiSchemaArray.html +1 -1
  140. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  141. package/docs/types/OpenapiSchemaBase.html +1 -1
  142. package/docs/types/OpenapiSchemaBody.html +1 -1
  143. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  144. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  145. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  146. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  147. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  148. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  149. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  150. package/docs/types/OpenapiSchemaInteger.html +1 -1
  151. package/docs/types/OpenapiSchemaNull.html +1 -1
  152. package/docs/types/OpenapiSchemaNumber.html +1 -1
  153. package/docs/types/OpenapiSchemaObject.html +1 -1
  154. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  155. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  156. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  157. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  158. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  159. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  160. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  161. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  162. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  163. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  164. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  165. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  166. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  167. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  168. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  169. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  170. package/docs/types/OpenapiSchemaString.html +1 -1
  171. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  172. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  173. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  174. package/docs/types/OpenapiTypeField.html +1 -1
  175. package/docs/types/Pascalized.html +1 -1
  176. package/docs/types/PrimaryKeyType.html +1 -1
  177. package/docs/types/RoundingPrecision.html +1 -1
  178. package/docs/types/SerializerCasing.html +1 -1
  179. package/docs/types/SimpleObjectSerializerType.html +1 -1
  180. package/docs/types/Snakeified.html +1 -1
  181. package/docs/types/Timestamp.html +1 -1
  182. package/docs/types/UpdateableAssociationProperties.html +1 -1
  183. package/docs/types/UpdateableProperties.html +1 -1
  184. package/docs/types/ValidationType.html +1 -1
  185. package/docs/types/ViewModel.html +1 -1
  186. package/docs/types/ViewModelClass.html +1 -1
  187. package/docs/types/WhereStatementForDream.html +1 -1
  188. package/docs/types/WhereStatementForDreamClass.html +1 -1
  189. package/docs/variables/DateTime-1.html +1 -1
  190. package/docs/variables/DreamConst.html +1 -1
  191. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  192. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  193. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  194. package/docs/variables/ops.html +1 -1
  195. package/docs/variables/primaryKeyTypes.html +1 -1
  196. package/package.json +1 -1
@@ -13,12 +13,12 @@ const CannotPaginateWithLimit_js_1 = require("../errors/pagination/CannotPaginat
13
13
  const CannotPaginateWithOffset_js_1 = require("../errors/pagination/CannotPaginateWithOffset.js");
14
14
  const RecordNotFound_js_1 = require("../errors/RecordNotFound.js");
15
15
  const cloneDeepSafe_js_1 = require("../helpers/cloneDeepSafe.js");
16
- const compact_js_1 = require("../helpers/compact.js");
17
16
  const isObject_js_1 = require("../helpers/isObject.js");
18
17
  const namespaceColumn_js_1 = require("../helpers/namespaceColumn.js");
19
18
  const protectAgainstPollutingAssignment_js_1 = require("../helpers/protectAgainstPollutingAssignment.js");
20
19
  const index_js_2 = require("../ops/index.js");
21
20
  const computedPaginatePage_js_1 = require("./internal/computedPaginatePage.js");
21
+ const convertDreamClassAndAssociationNameTupleArrayToPreloadArgs_js_1 = require("./internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js");
22
22
  const extractNestedPaths_js_1 = require("./internal/extractNestedPaths.js");
23
23
  const Postgres_js_1 = require("./QueryDriver/Postgres.js");
24
24
  class Query {
@@ -493,41 +493,35 @@ class Query {
493
493
  * await User.preload('posts', 'comments', 'replies').all()
494
494
  *
495
495
  * // Automatically preload everything needed for serialization:
496
- * await User.preloadForSerialization({ serializerKey: 'summary' }).all()
496
+ * await User.preloadFor('summary').all()
497
497
  *
498
498
  * // Add where conditions to specific associations during preloading:
499
- * await User.preloadForSerialization({
500
- * serializerKey: 'detailed',
501
- * modifierFn: (dreamClass, associationName) => {
502
- * if (dreamClass.typeof(Post) && associationName === 'comments') {
503
- * return { and: { published: true } }
504
- * }
499
+ * await User.preloadFor('detailed', (dreamClass, associationName) => {
500
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
501
+ * return { and: { published: true } }
505
502
  * }
506
- * }).all()
503
+ * })
504
+ * .all()
507
505
  *
508
506
  * // Skip preloading specific associations to handle them manually:
509
- * await User.preloadForSerialization({
510
- * serializerKey: 'summary',
511
- * modifierFn: (dreamClass, associationName) => {
512
- * if (dreamClass.typeof(User) && associationName === 'posts') {
513
- * return 'omit' // Handle posts preloading separately with custom logic
514
- * }
507
+ * await User.preloadFor('summary', (dreamClass, associationName) => {
508
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
509
+ * return 'omit' // Handle posts preloading separately with custom logic
515
510
  * }
516
511
  * })
517
- * .preload('posts', { and: { featured: true } }) // Custom preloading
518
- * .all()
512
+ * .preload('posts', { and: { featured: true } }) // Custom preloading
513
+ * .all()
519
514
  * ```
520
515
  *
521
- * @param opts - Configuration options for serialization preloading
522
- * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
523
- * @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
516
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
517
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
524
518
  * @returns A Query with all serialization associations preloaded
525
519
  */
526
- preloadForSerialization({ serializerKey, modifierFn, } = {}) {
520
+ preloadFor(serializerKey, modifierFn) {
527
521
  const preloadArgs = (0, extractNestedPaths_js_1.default)(this.dreamClass['serializationMap'](serializerKey));
528
522
  let query = this;
529
523
  preloadArgs.forEach(dreamClassAndAssociationNameTupleArray => {
530
- query = query.preload(...this.convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray, modifierFn));
524
+ query = query.preload(...(0, convertDreamClassAndAssociationNameTupleArrayToPreloadArgs_js_1.default)(dreamClassAndAssociationNameTupleArray, modifierFn));
531
525
  });
532
526
  return query;
533
527
  }
@@ -555,59 +549,39 @@ class Query {
555
549
  * await User.leftJoinPreload('posts', 'comments', 'replies').all()
556
550
  *
557
551
  * // Automatically left join preload everything needed for serialization:
558
- * await User.leftJoinPreloadForSerialization({ serializerKey: 'summary' }).all()
552
+ * await User.leftJoinPreloadFor('summary').all()
559
553
  *
560
554
  * // Add where conditions to specific associations during left join preloading:
561
- * await User.leftJoinPreloadForSerialization({
562
- * serializerKey: 'detailed',
563
- * modifierFn: (dreamClass, associationName) => {
564
- * if (dreamClass.typeof(Post) && associationName === 'comments') {
565
- * return { and: { published: true } }
566
- * }
555
+ * await User.leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
556
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
557
+ * return { and: { published: true } }
567
558
  * }
568
- * }).all()
559
+ * })
560
+ * .all()
569
561
  *
570
562
  * // Skip left join preloading specific associations to handle them manually:
571
- * await User.leftJoinPreloadForSerialization({
572
- * serializerKey: 'summary',
573
- * modifierFn: (dreamClass, associationName) => {
574
- * if (dreamClass.typeof(User) && associationName === 'posts') {
575
- * return 'omit' // Handle posts preloading separately with custom logic
576
- * }
563
+ * await User.leftJoinPreloadFor('summary', (dreamClass, associationName) => {
564
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
565
+ * return 'omit' // Handle posts preloading separately with custom logic
577
566
  * }
578
567
  * })
579
- * .preload('posts', { and: { featured: true } }) // Custom preloading instead
580
- * .all()
568
+ * .preload('posts', { and: { featured: true } }) // Custom preloading instead
569
+ * .all()
581
570
  * ```
582
571
  *
583
- * @param opts - Configuration options for serialization preloading
584
- * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
585
- * @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
572
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
573
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
586
574
  * @returns A Query with all serialization associations left join preloaded
587
575
  */
588
- leftJoinPreloadForSerialization({ serializerKey, modifierFn, } = {}) {
576
+ leftJoinPreloadFor(serializerKey, modifierFn) {
589
577
  const preloadArgs = (0, extractNestedPaths_js_1.default)(this.dreamClass['serializationMap'](serializerKey));
590
578
  let query = this;
591
579
  const counter = { count: 0 };
592
580
  preloadArgs.forEach(dreamClassAndAssociationNameTupleArray => {
593
- query = query.leftJoinPreload(...this.convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray, modifierFn, counter));
581
+ query = query.leftJoinPreload(...(0, convertDreamClassAndAssociationNameTupleArrayToPreloadArgs_js_1.default)(dreamClassAndAssociationNameTupleArray, modifierFn, counter));
594
582
  });
595
583
  return query;
596
584
  }
597
- convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray, modifierFn, counter) {
598
- return (0, compact_js_1.default)(dreamClassAndAssociationNameTupleArray.flatMap(dreamClassAndAssociationNameTuple => {
599
- const associationName = dreamClassAndAssociationNameTuple[1];
600
- const aliasedAssociationName = counter
601
- ? `${dreamClassAndAssociationNameTuple[1]} as drsz${counter.count++}`
602
- : dreamClassAndAssociationNameTuple[1];
603
- if (!modifierFn)
604
- return aliasedAssociationName;
605
- const modifier = modifierFn(dreamClassAndAssociationNameTuple[0], associationName);
606
- if (modifier === 'omit')
607
- return undefined;
608
- return [aliasedAssociationName, modifier];
609
- }));
610
- }
611
585
  /**
612
586
  * Returns a new Query instance, with the provided
613
587
  * joins statement attached
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = convertDreamClassAndAssociationNameTupleArrayToPreloadArgs;
4
+ const compact_js_1 = require("../../helpers/compact.js");
5
+ function convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray, modifierFn, counter) {
6
+ return (0, compact_js_1.default)(dreamClassAndAssociationNameTupleArray.flatMap(dreamClassAndAssociationNameTuple => {
7
+ const associationName = dreamClassAndAssociationNameTuple[1];
8
+ const aliasedAssociationName = counter
9
+ ? `${dreamClassAndAssociationNameTuple[1]} as drsz${counter.count++}`
10
+ : dreamClassAndAssociationNameTuple[1];
11
+ if (!modifierFn)
12
+ return aliasedAssociationName;
13
+ const modifier = modifierFn(dreamClassAndAssociationNameTuple[0], associationName);
14
+ if (modifier === 'omit')
15
+ return undefined;
16
+ return [aliasedAssociationName, modifier];
17
+ }));
18
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = unaliasTableName;
4
+ const extractAssociationMetadataFromAssociationName_js_1 = require("./extractAssociationMetadataFromAssociationName.js");
5
+ function unaliasTableName(tableName) {
6
+ return (0, extractAssociationMetadataFromAssociationName_js_1.default)(tableName).name;
7
+ }
@@ -1146,38 +1146,31 @@ export default class Dream {
1146
1146
  * await User.preload('posts', 'comments', 'replies').all()
1147
1147
  *
1148
1148
  * // Automatically preload everything needed for serialization:
1149
- * await User.preloadForSerialization({ serializerKey: 'summary' }).all()
1149
+ * await User.preloadFor('summary').all()
1150
1150
  *
1151
1151
  * // Add where conditions to specific associations during preloading:
1152
- * await User.preloadForSerialization({
1153
- * serializerKey: 'detailed',
1154
- * modifierFn: (dreamClass, associationName) => {
1155
- * if (dreamClass.typeof(Post) && associationName === 'comments') {
1156
- * return { and: { published: true } }
1157
- * }
1152
+ * await User.preloadFor('default', (dreamClass, associationName) => {
1153
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
1154
+ * return { and: { published: true } }
1158
1155
  * }
1159
1156
  * }).all()
1160
1157
  *
1161
1158
  * // Skip preloading specific associations to handle them manually:
1162
- * await User.preloadForSerialization({
1163
- * serializerKey: 'summary',
1164
- * modifierFn: (dreamClass, associationName) => {
1165
- * if (dreamClass.typeof(User) && associationName === 'posts') {
1166
- * return 'omit' // Handle posts preloading separately with custom logic
1167
- * }
1159
+ * await User.preloadFor('summary', (dreamClass, associationName) => {
1160
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
1161
+ * return 'omit' // Handle posts preloading separately with custom logic
1168
1162
  * }
1169
1163
  * })
1170
1164
  * .preload('posts', { and: { featured: true } }) // Custom preloading
1171
1165
  * .all()
1172
1166
  * ```
1173
1167
  *
1174
- * @param opts - Configuration options for serialization preloading
1175
- * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
1176
- * @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
1168
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
1169
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
1177
1170
  * @returns A Query with all serialization associations preloaded
1178
1171
  */
1179
- static preloadForSerialization(opts = {}) {
1180
- return this.query().preloadForSerialization(opts);
1172
+ static preloadFor(serializerKey, modifierFn) {
1173
+ return this.query().preloadFor(serializerKey, modifierFn);
1181
1174
  }
1182
1175
  /**
1183
1176
  * Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
@@ -1203,38 +1196,31 @@ export default class Dream {
1203
1196
  * await User.leftJoinPreload('posts', 'comments', 'replies').all()
1204
1197
  *
1205
1198
  * // Automatically left join preload everything needed for serialization:
1206
- * await User.leftJoinPreloadForSerialization({ serializerKey: 'summary' }).all()
1199
+ * await User.leftJoinPreloadFor('summary').all()
1207
1200
  *
1208
1201
  * // Add where conditions to specific associations during left join preloading:
1209
- * await User.leftJoinPreloadForSerialization({
1210
- * serializerKey: 'detailed',
1211
- * modifierFn: (dreamClass, associationName) => {
1212
- * if (dreamClass.typeof(Post) && associationName === 'comments') {
1213
- * return { and: { published: true } }
1214
- * }
1202
+ * await User.leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
1203
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
1204
+ * return { and: { published: true } }
1215
1205
  * }
1216
1206
  * }).all()
1217
1207
  *
1218
1208
  * // Skip left join preloading specific associations to handle them manually:
1219
- * await User.leftJoinPreloadForSerialization({
1220
- * serializerKey: 'summary',
1221
- * modifierFn: (dreamClass, associationName) => {
1222
- * if (dreamClass.typeof(User) && associationName === 'posts') {
1223
- * return 'omit' // Handle posts preloading separately with custom logic
1224
- * }
1209
+ * await User.leftJoinPreloadFor('summary', (dreamClass, associationName) => {
1210
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
1211
+ * return 'omit' // Handle posts preloading separately with custom logic
1225
1212
  * }
1226
1213
  * })
1227
1214
  * .preload('posts', { and: { featured: true } }) // Custom preloading instead
1228
1215
  * .all()
1229
1216
  * ```
1230
1217
  *
1231
- * @param opts - Configuration options for serialization preloading
1232
- * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
1233
- * @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
1218
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
1219
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
1234
1220
  * @returns A Query with all serialization associations left join preloaded
1235
1221
  */
1236
- static leftJoinPreloadForSerialization(opts = {}) {
1237
- return this.query().leftJoinPreloadForSerialization(opts);
1222
+ static leftJoinPreloadFor(serializerKey, modifierFn) {
1223
+ return this.query().leftJoinPreloadFor(serializerKey, modifierFn);
1238
1224
  }
1239
1225
  /**
1240
1226
  * Returns a new Query instance with the provided
@@ -3081,6 +3067,54 @@ export default class Dream {
3081
3067
  load(...args) {
3082
3068
  return new LoadBuilder(this).load(...args);
3083
3069
  }
3070
+ /**
3071
+ * Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
3072
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
3073
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
3074
+ * manually remember which associations to preload for serialization.
3075
+ *
3076
+ * This method decouples data loading code from data rendering code by having the serializer
3077
+ * (rendering code) inform the query (loading code) about which associations are needed.
3078
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
3079
+ * modifying existing ones - the loading code automatically adapts without requiring
3080
+ * corresponding modifications to preload statements.
3081
+ *
3082
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
3083
+ * automatically preloads all associations that will be needed during serialization.
3084
+ *
3085
+ * ```ts
3086
+ * // Instead of manually specifying all associations:
3087
+ * await User.preload('posts', 'comments', 'replies').all()
3088
+ *
3089
+ * // Automatically preload everything needed for serialization:
3090
+ * await user.loadFor('summary').execute()
3091
+ *
3092
+ * // Add where conditions to specific associations during preloading:
3093
+ * await user.loadFor('detailed', (dreamClass, associationName) => {
3094
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
3095
+ * return { and: { published: true } }
3096
+ * }
3097
+ * })
3098
+ * .execute()
3099
+ *
3100
+ * // Skip preloading specific associations to handle them manually:
3101
+ * await user
3102
+ * .loadFor('summary', (dreamClass, associationName) => {
3103
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
3104
+ * return 'omit' // Handle posts preloading separately with custom logic
3105
+ * }
3106
+ * })
3107
+ * .load('posts', { and: { featured: true } }) // Custom preloading
3108
+ * .execute()
3109
+ * ```
3110
+ *
3111
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
3112
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
3113
+ * @returns A Query with all serialization associations preloaded
3114
+ */
3115
+ loadFor(serializerKey, modifierFn) {
3116
+ return new LoadBuilder(this)['loadFor'](serializerKey, modifierFn);
3117
+ }
3084
3118
  /**
3085
3119
  * Load each specified association using a single SQL query.
3086
3120
  * See {@link Dream.load} for loading in separate queries.
@@ -3115,6 +3149,54 @@ export default class Dream {
3115
3149
  leftJoinLoad(...args) {
3116
3150
  return new LeftJoinLoadBuilder(this).leftJoinLoad(...args);
3117
3151
  }
3152
+ /**
3153
+ * Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
3154
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
3155
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
3156
+ * manually remember which associations to preload for serialization.
3157
+ *
3158
+ * This method decouples data loading code from data rendering code by having the serializer
3159
+ * (rendering code) inform the query (loading code) about which associations are needed.
3160
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
3161
+ * modifying existing ones - the loading code automatically adapts without requiring
3162
+ * corresponding modifications to preload statements.
3163
+ *
3164
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
3165
+ * automatically preloads all associations that will be needed during serialization.
3166
+ *
3167
+ * ```ts
3168
+ * // Instead of manually specifying all associations:
3169
+ * await User.preload('posts', 'comments', 'replies').all()
3170
+ *
3171
+ * // Automatically preload everything needed for serialization:
3172
+ * await user.leftJoinLoadFor('summary').execute()
3173
+ *
3174
+ * // Add where conditions to specific associations during preloading:
3175
+ * await user.leftJoinLoadFor('detailed', (dreamClass, associationName) => {
3176
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
3177
+ * return { and: { published: true } }
3178
+ * }
3179
+ * })
3180
+ * .execute()
3181
+ *
3182
+ * // Skip preloading specific associations to handle them manually:
3183
+ * await user
3184
+ * .loadFor('summary', (dreamClass, associationName) => {
3185
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
3186
+ * return 'omit' // Handle posts preloading separately with custom logic
3187
+ * }
3188
+ * })
3189
+ * .load('posts', { and: { featured: true } }) // Custom preloading
3190
+ * .execute()
3191
+ * ```
3192
+ *
3193
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
3194
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
3195
+ * @returns A Query with all serialization associations preloaded
3196
+ */
3197
+ leftJoinLoadFor(serializerKey, modifierFn) {
3198
+ return new LeftJoinLoadBuilder(this)['leftJoinLoadFor'](serializerKey, modifierFn);
3199
+ }
3118
3200
  /**
3119
3201
  * Returns true if the association specified has
3120
3202
  * been loaded on this instance
@@ -368,6 +368,52 @@ export default class DreamClassTransactionBuilder {
368
368
  leftJoinPreload(...args) {
369
369
  return this.queryInstance().leftJoinPreload(...args);
370
370
  }
371
+ /**
372
+ * Recursively left-join-preloads all Dream associations referenced by `rendersOne` and `rendersMany`
373
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
374
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
375
+ * manually remember which associations to preload for serialization.
376
+ *
377
+ * This method decouples data loading code from data rendering code by having the serializer
378
+ * (rendering code) inform the query (loading code) about which associations are needed.
379
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
380
+ * modifying existing ones - the loading code automatically adapts without requiring
381
+ * corresponding modifications to preload statements.
382
+ *
383
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
384
+ * automatically preloads all associations that will be needed during serialization.
385
+ *
386
+ * ```ts
387
+ * // Instead of manually specifying all associations:
388
+ * await User.preload('posts', 'comments', 'replies').all()
389
+ *
390
+ * // Automatically preload everything needed for serialization:
391
+ * await User.preloadFor('summary').all()
392
+ *
393
+ * // Add where conditions to specific associations during preloading:
394
+ * await User.txn(txn).leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
395
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
396
+ * return { and: { published: true } }
397
+ * }
398
+ * }).all()
399
+ *
400
+ * // Skip preloading specific associations to handle them manually:
401
+ * await User.txn(txn).leftJoinPreloadFor('summary', (dreamClass, associationName) => {
402
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
403
+ * return 'omit' // Handle posts preloading separately with custom logic
404
+ * }
405
+ * })
406
+ * .preload('posts', { and: { featured: true } }) // Custom preloading
407
+ * .all()
408
+ * ```
409
+ *
410
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
411
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
412
+ * @returns A Query with all serialization associations preloaded
413
+ */
414
+ leftJoinPreloadFor(serializerKey, modifierFn) {
415
+ return this.queryInstance().leftJoinPreloadFor(serializerKey, modifierFn);
416
+ }
371
417
  /**
372
418
  * Applies preload statement to a Query scoped to this model.
373
419
  * Upon instantiating records of this model type,
@@ -392,6 +438,52 @@ export default class DreamClassTransactionBuilder {
392
438
  preload(...args) {
393
439
  return this.queryInstance().preload(...args);
394
440
  }
441
+ /**
442
+ * Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
443
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
444
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
445
+ * manually remember which associations to preload for serialization.
446
+ *
447
+ * This method decouples data loading code from data rendering code by having the serializer
448
+ * (rendering code) inform the query (loading code) about which associations are needed.
449
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
450
+ * modifying existing ones - the loading code automatically adapts without requiring
451
+ * corresponding modifications to preload statements.
452
+ *
453
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
454
+ * automatically preloads all associations that will be needed during serialization.
455
+ *
456
+ * ```ts
457
+ * // Instead of manually specifying all associations:
458
+ * await User.preload('posts', 'comments', 'replies').all()
459
+ *
460
+ * // Automatically preload everything needed for serialization:
461
+ * await User.preloadFor('summary').all()
462
+ *
463
+ * // Add where conditions to specific associations during preloading:
464
+ * await User.txn(txn).preloadFor('detailed', (dreamClass, associationName) => {
465
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
466
+ * return { and: { published: true } }
467
+ * }
468
+ * }).all()
469
+ *
470
+ * // Skip preloading specific associations to handle them manually:
471
+ * await User.txn(txn).preloadFor('summary', (dreamClass, associationName) => {
472
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
473
+ * return 'omit' // Handle posts preloading separately with custom logic
474
+ * }
475
+ * })
476
+ * .preload('posts', { and: { featured: true } }) // Custom preloading
477
+ * .all()
478
+ * ```
479
+ *
480
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
481
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
482
+ * @returns A Query with all serialization associations preloaded
483
+ */
484
+ preloadFor(serializerKey, modifierFn) {
485
+ return this.queryInstance().preloadFor(serializerKey, modifierFn);
486
+ }
395
487
  /**
396
488
  * Returns a new Query instance with the provided
397
489
  * inner join statement attached
@@ -53,6 +53,55 @@ export default class DreamInstanceTransactionBuilder {
53
53
  load(...args) {
54
54
  return new LoadBuilder(this.dreamInstance, this.dreamTransaction).load(...args);
55
55
  }
56
+ /**
57
+ * Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
58
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
59
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
60
+ * manually remember which associations to preload for serialization.
61
+ *
62
+ * This method decouples data loading code from data rendering code by having the serializer
63
+ * (rendering code) inform the query (loading code) about which associations are needed.
64
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
65
+ * modifying existing ones - the loading code automatically adapts without requiring
66
+ * corresponding modifications to preload statements.
67
+ *
68
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
69
+ * automatically preloads all associations that will be needed during serialization.
70
+ *
71
+ * ```ts
72
+ * // Instead of manually specifying all associations:
73
+ * await User.preload('posts', 'comments', 'replies').all()
74
+ *
75
+ * // Automatically preload everything needed for serialization:
76
+ * await user.loadFor('summary').execute()
77
+ *
78
+ * // Add where conditions to specific associations during preloading:
79
+ * await user.txn(txn).loadFor('detailed', (dreamClass, associationName) => {
80
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
81
+ * return { and: { published: true } }
82
+ * }
83
+ * })
84
+ * .execute()
85
+ *
86
+ * // Skip preloading specific associations to handle them manually:
87
+ * await user
88
+ * .txn(txn)
89
+ * .loadFor('summary', (dreamClass, associationName) => {
90
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
91
+ * return 'omit' // Handle posts preloading separately with custom logic
92
+ * }
93
+ * })
94
+ * .load('posts', { and: { featured: true } }) // Custom preloading
95
+ * .execute()
96
+ * ```
97
+ *
98
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
99
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
100
+ * @returns A Query with all serialization associations preloaded
101
+ */
102
+ loadFor(serializerKey, modifierFn) {
103
+ return new LoadBuilder(this.dreamInstance, this.dreamTransaction)['loadFor'](serializerKey, modifierFn);
104
+ }
56
105
  /**
57
106
  * Load each specified association using a single SQL query.
58
107
  * See {@link #load} for loading in separate queries.
@@ -88,6 +137,55 @@ export default class DreamInstanceTransactionBuilder {
88
137
  leftJoinLoad(...args) {
89
138
  return new LeftJoinLoadBuilder(this.dreamInstance, this.dreamTransaction).leftJoinLoad(...args);
90
139
  }
140
+ /**
141
+ * Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
142
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
143
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
144
+ * manually remember which associations to preload for serialization.
145
+ *
146
+ * This method decouples data loading code from data rendering code by having the serializer
147
+ * (rendering code) inform the query (loading code) about which associations are needed.
148
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
149
+ * modifying existing ones - the loading code automatically adapts without requiring
150
+ * corresponding modifications to preload statements.
151
+ *
152
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
153
+ * automatically preloads all associations that will be needed during serialization.
154
+ *
155
+ * ```ts
156
+ * // Instead of manually specifying all associations:
157
+ * await User.preload('posts', 'comments', 'replies').all()
158
+ *
159
+ * // Automatically preload everything needed for serialization:
160
+ * await user.leftJoinLoadFor('summary').execute()
161
+ *
162
+ * // Add where conditions to specific associations during preloading:
163
+ * await user.txn(txn).leftJoinLoadFor('detailed', (dreamClass, associationName) => {
164
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
165
+ * return { and: { published: true } }
166
+ * }
167
+ * })
168
+ * .execute()
169
+ *
170
+ * // Skip preloading specific associations to handle them manually:
171
+ * await user
172
+ * .txn(txn)
173
+ * .leftJoinLoadFor('summary', (dreamClass, associationName) => {
174
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
175
+ * return 'omit' // Handle posts preloading separately with custom logic
176
+ * }
177
+ * })
178
+ * .load('posts', { and: { featured: true } }) // Custom preloading
179
+ * .execute()
180
+ * ```
181
+ *
182
+ * @param serializerKey - The serializer key to use for determining which associations to preload.
183
+ * @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
184
+ * @returns A Query with all serialization associations preloaded
185
+ */
186
+ leftJoinLoadFor(serializerKey, modifierFn) {
187
+ return new LeftJoinLoadBuilder(this.dreamInstance, this.dreamTransaction)['leftJoinLoadFor'](serializerKey, modifierFn);
188
+ }
91
189
  /**
92
190
  * Returns a new Query instance with the provided
93
191
  * inner join statement attached