@rvoh/dream 0.44.8 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/cjs/src/Dream.js +246 -23
  2. package/dist/cjs/src/cli/index.js +16 -0
  3. package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
  4. package/dist/cjs/src/decorators/Decorators.js +2 -1
  5. package/dist/cjs/src/dream/Query.js +162 -24
  6. package/dist/cjs/src/dream/internal/extractNestedPaths.js +37 -0
  7. package/dist/cjs/src/helpers/indent.js +18 -0
  8. package/dist/cjs/src/serializer/SerializerRenderer.js +3 -18
  9. package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +139 -3
  10. package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
  11. package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +20 -0
  12. package/dist/esm/src/Dream.js +246 -23
  13. package/dist/esm/src/cli/index.js +16 -0
  14. package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
  15. package/dist/esm/src/decorators/Decorators.js +2 -1
  16. package/dist/esm/src/dream/Query.js +162 -24
  17. package/dist/esm/src/dream/internal/extractNestedPaths.js +34 -0
  18. package/dist/esm/src/helpers/indent.js +15 -0
  19. package/dist/esm/src/serializer/SerializerRenderer.js +3 -18
  20. package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +139 -3
  21. package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
  22. package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +17 -0
  23. package/dist/types/src/Dream.d.ts +218 -24
  24. package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +18 -14
  25. package/dist/types/src/decorators/Decorators.d.ts +2 -1
  26. package/dist/types/src/dream/Query.d.ts +154 -25
  27. package/dist/types/src/dream/internal/extractNestedPaths.d.ts +21 -0
  28. package/dist/types/src/helpers/indent.d.ts +3 -0
  29. package/dist/types/src/index.d.ts +1 -1
  30. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +176 -5
  31. package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +176 -3
  32. package/dist/types/src/serializer/helpers/serializerForAssociatedClass.d.ts +9 -0
  33. package/dist/types/src/types/dream.d.ts +2 -1
  34. package/dist/types/src/types/dream.ts +26 -1
  35. package/docs/assets/highlight.css +7 -0
  36. package/docs/assets/navigation.js +1 -1
  37. package/docs/assets/search.js +1 -1
  38. package/docs/classes/Benchmark.html +2 -2
  39. package/docs/classes/CalendarDate.html +2 -2
  40. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  41. package/docs/classes/Decorators.html +21 -20
  42. package/docs/classes/Dream.html +288 -209
  43. package/docs/classes/DreamApp.html +4 -4
  44. package/docs/classes/DreamBin.html +2 -2
  45. package/docs/classes/DreamCLI.html +4 -4
  46. package/docs/classes/DreamImporter.html +2 -2
  47. package/docs/classes/DreamLogos.html +2 -2
  48. package/docs/classes/DreamMigrationHelpers.html +21 -8
  49. package/docs/classes/DreamSerializerBuilder.html +66 -2
  50. package/docs/classes/DreamTransaction.html +2 -2
  51. package/docs/classes/Encrypt.html +2 -2
  52. package/docs/classes/Env.html +2 -2
  53. package/docs/classes/GlobalNameNotSet.html +3 -3
  54. package/docs/classes/NonLoadedAssociation.html +3 -3
  55. package/docs/classes/ObjectSerializerBuilder.html +66 -2
  56. package/docs/classes/Query.html +118 -78
  57. package/docs/classes/Range.html +2 -2
  58. package/docs/classes/RecordNotFound.html +3 -3
  59. package/docs/classes/ValidationError.html +3 -3
  60. package/docs/functions/DreamSerializer.html +1 -1
  61. package/docs/functions/ObjectSerializer.html +1 -1
  62. package/docs/functions/ReplicaSafe.html +1 -1
  63. package/docs/functions/STI.html +1 -1
  64. package/docs/functions/SoftDelete.html +1 -1
  65. package/docs/functions/camelize.html +1 -1
  66. package/docs/functions/capitalize.html +1 -1
  67. package/docs/functions/cloneDeepSafe.html +1 -1
  68. package/docs/functions/closeAllDbConnections.html +1 -1
  69. package/docs/functions/compact.html +1 -1
  70. package/docs/functions/dreamDbConnections.html +1 -1
  71. package/docs/functions/dreamPath.html +1 -1
  72. package/docs/functions/expandStiClasses.html +1 -1
  73. package/docs/functions/generateDream.html +1 -1
  74. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  75. package/docs/functions/groupBy.html +1 -1
  76. package/docs/functions/hyphenize.html +1 -1
  77. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  78. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
  79. package/docs/functions/intersection.html +1 -1
  80. package/docs/functions/isDreamSerializer.html +1 -1
  81. package/docs/functions/isEmpty.html +1 -1
  82. package/docs/functions/loadRepl.html +1 -1
  83. package/docs/functions/lookupClassByGlobalName.html +1 -1
  84. package/docs/functions/normalizeUnicode.html +1 -1
  85. package/docs/functions/pascalize.html +1 -1
  86. package/docs/functions/pgErrorType.html +1 -1
  87. package/docs/functions/range-1.html +1 -1
  88. package/docs/functions/relativeDreamPath.html +1 -1
  89. package/docs/functions/round.html +1 -1
  90. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  91. package/docs/functions/sharedPathPrefix.html +1 -1
  92. package/docs/functions/snakeify.html +1 -1
  93. package/docs/functions/sort.html +1 -1
  94. package/docs/functions/sortBy.html +1 -1
  95. package/docs/functions/sortObjectByKey.html +1 -1
  96. package/docs/functions/sortObjectByValue.html +1 -1
  97. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  98. package/docs/functions/uncapitalize.html +1 -1
  99. package/docs/functions/uniq.html +1 -1
  100. package/docs/functions/untypedDb.html +1 -1
  101. package/docs/functions/validateColumn.html +1 -1
  102. package/docs/functions/validateTable.html +1 -1
  103. package/docs/interfaces/BelongsToStatement.html +2 -2
  104. package/docs/interfaces/DecoratorContext.html +2 -2
  105. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  106. package/docs/interfaces/DreamAppOpts.html +2 -2
  107. package/docs/interfaces/EncryptOptions.html +2 -2
  108. package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
  109. package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
  110. package/docs/interfaces/OpenapiDescription.html +2 -2
  111. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  112. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  113. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  114. package/docs/interfaces/SerializerRendererOpts.html +2 -2
  115. package/docs/modules.html +1 -0
  116. package/docs/types/Camelized.html +1 -1
  117. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  118. package/docs/types/DateTime.html +1 -1
  119. package/docs/types/DbConnectionType.html +1 -1
  120. package/docs/types/DbTypes.html +1 -1
  121. package/docs/types/DreamAssociationMetadata.html +1 -1
  122. package/docs/types/DreamAttributes.html +1 -1
  123. package/docs/types/DreamClassAssociationAndStatement.html +1 -0
  124. package/docs/types/DreamClassColumn.html +1 -1
  125. package/docs/types/DreamColumn.html +1 -1
  126. package/docs/types/DreamColumnNames.html +1 -1
  127. package/docs/types/DreamLogLevel.html +1 -1
  128. package/docs/types/DreamLogger.html +1 -1
  129. package/docs/types/DreamModelSerializerType.html +1 -1
  130. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  131. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  132. package/docs/types/DreamParamSafeAttributes.html +1 -1
  133. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  134. package/docs/types/DreamSerializable.html +1 -1
  135. package/docs/types/DreamSerializableArray.html +1 -1
  136. package/docs/types/DreamSerializerKey.html +1 -1
  137. package/docs/types/DreamSerializers.html +1 -1
  138. package/docs/types/DreamTableSchema.html +1 -1
  139. package/docs/types/DreamVirtualColumns.html +1 -1
  140. package/docs/types/EncryptAlgorithm.html +1 -1
  141. package/docs/types/HasManyStatement.html +1 -1
  142. package/docs/types/HasOneStatement.html +1 -1
  143. package/docs/types/Hyphenized.html +1 -1
  144. package/docs/types/IdType.html +1 -1
  145. package/docs/types/OpenapiAllTypes.html +1 -1
  146. package/docs/types/OpenapiFormats.html +1 -1
  147. package/docs/types/OpenapiNumberFormats.html +1 -1
  148. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
  149. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  150. package/docs/types/OpenapiSchemaArray.html +1 -1
  151. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  152. package/docs/types/OpenapiSchemaBase.html +1 -1
  153. package/docs/types/OpenapiSchemaBody.html +1 -1
  154. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  155. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  156. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  157. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  158. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  159. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  160. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  161. package/docs/types/OpenapiSchemaInteger.html +1 -1
  162. package/docs/types/OpenapiSchemaNull.html +1 -1
  163. package/docs/types/OpenapiSchemaNumber.html +1 -1
  164. package/docs/types/OpenapiSchemaObject.html +1 -1
  165. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  166. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  167. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  168. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  169. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  170. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  171. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  172. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  173. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  174. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  175. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  176. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  177. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  178. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  179. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  180. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  181. package/docs/types/OpenapiSchemaString.html +1 -1
  182. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  183. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  184. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  185. package/docs/types/OpenapiTypeField.html +1 -1
  186. package/docs/types/Pascalized.html +1 -1
  187. package/docs/types/PrimaryKeyType.html +1 -1
  188. package/docs/types/RoundingPrecision.html +1 -1
  189. package/docs/types/SerializerCasing.html +1 -1
  190. package/docs/types/SimpleObjectSerializerType.html +1 -1
  191. package/docs/types/Snakeified.html +1 -1
  192. package/docs/types/Timestamp.html +1 -1
  193. package/docs/types/UpdateableAssociationProperties.html +1 -1
  194. package/docs/types/UpdateableProperties.html +1 -1
  195. package/docs/types/ValidationType.html +1 -1
  196. package/docs/types/ViewModel.html +1 -1
  197. package/docs/types/ViewModelClass.html +1 -1
  198. package/docs/types/WhereStatementForDream.html +1 -1
  199. package/docs/types/WhereStatementForDreamClass.html +1 -1
  200. package/docs/variables/DateTime-1.html +1 -1
  201. package/docs/variables/DreamConst.html +1 -1
  202. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  203. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  204. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  205. package/docs/variables/ops.html +1 -1
  206. package/docs/variables/primaryKeyTypes.html +1 -1
  207. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const yoctocolors_1 = require("yoctocolors");
3
4
  const errors_js_1 = require("./db/errors.js");
4
5
  const index_js_1 = require("./db/index.js");
5
6
  const associationToGetterSetterProp_js_1 = require("./decorators/field/association/associationToGetterSetterProp.js");
@@ -47,7 +48,10 @@ const cloneDeepSafe_js_1 = require("./helpers/cloneDeepSafe.js");
47
48
  const DateTime_js_1 = require("./helpers/DateTime.js");
48
49
  const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
49
50
  const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
51
+ const indent_js_1 = require("./helpers/indent.js");
50
52
  const notEqual_js_1 = require("./helpers/notEqual.js");
53
+ const inferSerializerFromDreamOrViewModel_js_1 = require("./serializer/helpers/inferSerializerFromDreamOrViewModel.js");
54
+ const serializerForAssociatedClass_js_1 = require("./serializer/helpers/serializerForAssociatedClass.js");
51
55
  class Dream {
52
56
  DB;
53
57
  /**
@@ -104,6 +108,46 @@ class Dream {
104
108
  get globalSchema() {
105
109
  throw new DreamMissingRequiredOverride_js_1.default(this.constructor, 'globalSchema');
106
110
  }
111
+ /**
112
+ * Determines if the provided Dream class is the same as or a subclass of this Dream class.
113
+ * This method is particularly useful for runtime type checking and works with STI (Single Table Inheritance) classes.
114
+ *
115
+ * For regular Dream classes, this checks if the provided class is exactly the same class.
116
+ * For STI classes, this checks inheritance relationships - a child STI class will return true
117
+ * when compared against its parent class.
118
+ *
119
+ * ```ts
120
+ * // Regular class comparison
121
+ * User.typeof(User) // true
122
+ * User.typeof(Pet) // false
123
+ *
124
+ * // STI inheritance checking
125
+ * class Balloon extends ApplicationModel {
126
+ * // base STI class
127
+ * }
128
+ *
129
+ * class Mylar extends Balloon {
130
+ * // STI child class
131
+ * }
132
+ *
133
+ * Balloon.typeof(Balloon) // true
134
+ * Balloon.typeof(Mylar) // false
135
+ * Mylar.typeof(Balloon) // true (child recognizes parent)
136
+ * Mylar.typeof(Mylar) // true
137
+ *
138
+ * // Runtime type checking with variables
139
+ * const dreamClass: typeof Dream = getRandomDreamClass()
140
+ * if (dreamClass.typeof(Pet)) {
141
+ * // dreamClass is Pet or a subclass of Pet
142
+ * }
143
+ * ```
144
+ *
145
+ * @param dreamClass - The Dream class to compare against this class
146
+ * @returns `true` if the provided class is the same as this class or if this class is a subclass of the provided class (STI inheritance), `false` otherwise
147
+ */
148
+ static typeof(dreamClass) {
149
+ return this.new() instanceof dreamClass;
150
+ }
107
151
  /**
108
152
  * Shadows #primaryKey, a getter which can be overwritten to customize the id field
109
153
  * for a given model.
@@ -423,6 +467,65 @@ class Dream {
423
467
  static setGlobalName(globalName) {
424
468
  this._globalName = globalName;
425
469
  }
470
+ static serializationMap(serializerKey) {
471
+ const key = serializerKey || 'default';
472
+ const serializer = (0, inferSerializerFromDreamOrViewModel_js_1.inferSerializersFromDreamClassOrViewModelClass)(this, key)[0] ?? null;
473
+ if (!serializer)
474
+ throw new Error(`unable to find serializer with key: ${key}`);
475
+ return this.recursiveSerializationMap(serializer);
476
+ }
477
+ static displaySerialization(serializerKey) {
478
+ const key = serializerKey || 'default';
479
+ const serializer = (0, inferSerializerFromDreamOrViewModel_js_1.inferSerializersFromDreamClassOrViewModelClass)(this, key)[0] ?? null;
480
+ if (!serializer)
481
+ throw new Error(`unable to find serializer with key: ${key}`);
482
+ console.log(yoctocolors_1.default.cyan(this.sanitizedName));
483
+ console.log(yoctocolors_1.default.gray(serializer.globalName));
484
+ return this.recursiveSerializationMap(serializer, {
485
+ forDisplay: true,
486
+ });
487
+ }
488
+ static recursiveSerializationMap(serializer, { forDisplay = false, forDisplayDepth = 0, } = {}) {
489
+ const serializerBuilder = serializer(undefined, undefined);
490
+ const serializerAssociations = serializerBuilder['attributes'].filter(attribute => ['rendersOne', 'rendersMany', 'delegatedAttribute'].includes(attribute.type));
491
+ return serializerAssociations.reduce((acc, serializerAssociation) => {
492
+ const serializerAssociationName = serializerAssociation.targetName ??
493
+ serializerAssociation.name;
494
+ const serializerAssociationType = serializerAssociation.type;
495
+ const association = this['getAssociationMetadata'](serializerAssociationName);
496
+ if (!association)
497
+ return acc;
498
+ const associatedClasses = association.modelCB();
499
+ const associatedClass = Array.isArray(associatedClasses) ? associatedClasses[0] : associatedClasses;
500
+ if (!associatedClass)
501
+ throw new Error(`No class defined on ${serializerAssociationName} association on ${this.sanitizedName}`);
502
+ const associationSerializer = (0, serializerForAssociatedClass_js_1.serializerForAssociatedClass)(this.prototype, serializerAssociationName, serializerAssociation.options);
503
+ if (!associationSerializer)
504
+ throw new Error(`No serializer found to render ${serializerAssociationName} on ${this.sanitizedName}`);
505
+ if (forDisplay && serializerAssociationType !== 'delegatedAttribute') {
506
+ const hierarchyLine = '└───';
507
+ const indentation = (0, indent_js_1.indent)((hierarchyLine.length + 1) * forDisplayDepth, {
508
+ tabWidth: 1,
509
+ });
510
+ const prefix = `${hierarchyLine} `;
511
+ const nestedAssociationDisplay = indentation + `${prefix}${serializerAssociationType} ${yoctocolors_1.default.cyan(serializerAssociationName)}`;
512
+ console.log(nestedAssociationDisplay);
513
+ console.log(yoctocolors_1.default.gray(indentation +
514
+ (0, indent_js_1.indent)(prefix.length, { tabWidth: 1 }) +
515
+ associationSerializer.globalName));
516
+ }
517
+ acc[association.as] = {
518
+ parentDreamClass: this,
519
+ nestedSerializerInfo: serializerAssociation.type === 'delegatedAttribute'
520
+ ? {}
521
+ : associatedClass['recursiveSerializationMap'](associationSerializer, {
522
+ forDisplay,
523
+ forDisplayDepth: forDisplayDepth + 1,
524
+ }),
525
+ };
526
+ return acc;
527
+ }, {});
528
+ }
426
529
  /**
427
530
  * Returns the column names for the given model
428
531
  *
@@ -624,12 +727,14 @@ class Dream {
624
727
  * // 2
625
728
  * ```
626
729
  *
730
+ * @param opts - Pagination options
627
731
  * @param opts.page - the page number that you want to fetch results for
628
732
  * @param opts.pageSize - the number of results per page (optional)
629
- * @returns results.recordCount - A number representing the total number of records matching your query
630
- * @returns results.pageCount - The number of pages needed to encapsulate all the matching records
631
- * @returns results.currentPage - The current page (same as what is provided in the paginate args)
632
- * @returns results.results - An array of records matching the current record
733
+ * @returns A paginated result object containing:
734
+ * - `recordCount` - A number representing the total number of records matching your query
735
+ * - `pageCount` - The number of pages needed to encapsulate all the matching records
736
+ * - `currentPage` - The current page (same as what is provided in the paginate args)
737
+ * - `results` - An array of records matching the current record
633
738
  */
634
739
  static async paginate(opts) {
635
740
  return await this.query().paginate(opts);
@@ -697,7 +802,8 @@ class Dream {
697
802
  * ```
698
803
  *
699
804
  * @param attributes - attributes or belongs to associations you wish to set on this model before persisting
700
- * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
805
+ * @param __namedParameters - optional parameters
806
+ * @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
701
807
  * @returns A newly persisted dream instance
702
808
  */
703
809
  static async create(attributes, { skipHooks } = {}) {
@@ -721,6 +827,7 @@ class Dream {
721
827
  * ```
722
828
  *
723
829
  * @param attributes - The base attributes to persist, but also the attributes to use to find when create fails
830
+ * @param extraOpts - Additional options
724
831
  * @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
725
832
  * @returns A dream instance
726
833
  */
@@ -753,6 +860,7 @@ class Dream {
753
860
  * ```
754
861
  *
755
862
  * @param attributes - The base attributes for finding which record to update, also used when creating
863
+ * @param extraOpts - Additional options
756
864
  * @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
757
865
  * @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
758
866
  * @returns A dream instance
@@ -773,6 +881,7 @@ class Dream {
773
881
  * at least one of the provided attributes
774
882
  *
775
883
  * @param attributes - The base attributes for finding which record to update, also used when creating
884
+ * @param extraOpts - Additional options
776
885
  * @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
777
886
  * @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
778
887
  * @returns A dream instance
@@ -862,6 +971,7 @@ class Dream {
862
971
  * ```
863
972
  *
864
973
  * @param cb - The callback to call for each found record
974
+ * @param opts - Optional parameters for batch processing
865
975
  * @param opts.batchSize - the batch size you wish to collect records in. If not provided, it will default to 1000
866
976
  * @returns void
867
977
  */
@@ -946,6 +1056,7 @@ class Dream {
946
1056
  * ```
947
1057
  *
948
1058
  * @param attributes - The base attributes for finding, but also the attributes to use when creating
1059
+ * @param extraOpts - Additional options
949
1060
  * @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
950
1061
  * @returns A dream instance
951
1062
  */
@@ -973,10 +1084,10 @@ class Dream {
973
1084
  }
974
1085
  /**
975
1086
  * Load each specified association using a single SQL query.
976
- * See {@link #preload} for preloading in separate queries.
1087
+ * See {@link Dream.preload} for preloading in separate queries.
977
1088
  *
978
1089
  * Note: since leftJoinPreload loads via single query, it has
979
- * some downsides and that may be avoided using {@link #preload}:
1090
+ * some downsides and that may be avoided using {@link Dream.preload}:
980
1091
  * 1. `limit` and `offset` will be automatically removed
981
1092
  * 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
982
1093
  * 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.preload('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
@@ -1017,6 +1128,116 @@ class Dream {
1017
1128
  static preload(...args) {
1018
1129
  return this.query().preload(...args);
1019
1130
  }
1131
+ /**
1132
+ * Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
1133
+ * in a DreamSerializer. This traverses the entire content tree of serializers to automatically
1134
+ * load all necessary associations, eliminating N+1 query problems and removing the need to
1135
+ * manually remember which associations to preload for serialization.
1136
+ *
1137
+ * This method decouples data loading code from data rendering code by having the serializer
1138
+ * (rendering code) inform the query (loading code) about which associations are needed.
1139
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
1140
+ * modifying existing ones - the loading code automatically adapts without requiring
1141
+ * corresponding modifications to preload statements.
1142
+ *
1143
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
1144
+ * automatically preloads all associations that will be needed during serialization.
1145
+ *
1146
+ * ```ts
1147
+ * // Instead of manually specifying all associations:
1148
+ * await User.preload('posts', 'comments', 'replies').all()
1149
+ *
1150
+ * // Automatically preload everything needed for serialization:
1151
+ * await User.preloadForSerialization({ serializerKey: 'summary' }).all()
1152
+ *
1153
+ * // Add where conditions to specific associations during preloading:
1154
+ * await User.preloadForSerialization({
1155
+ * serializerKey: 'detailed',
1156
+ * modifierFn: (dreamClass, associationName) => {
1157
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
1158
+ * return { and: { published: true } }
1159
+ * }
1160
+ * }
1161
+ * }).all()
1162
+ *
1163
+ * // Skip preloading specific associations to handle them manually:
1164
+ * await User.preloadForSerialization({
1165
+ * serializerKey: 'summary',
1166
+ * modifierFn: (dreamClass, associationName) => {
1167
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
1168
+ * return 'omit' // Handle posts preloading separately with custom logic
1169
+ * }
1170
+ * }
1171
+ * })
1172
+ * .preload('posts', { and: { featured: true } }) // Custom preloading
1173
+ * .all()
1174
+ * ```
1175
+ *
1176
+ * @param opts - Configuration options for serialization preloading
1177
+ * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
1178
+ * @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
1179
+ * @returns A Query with all serialization associations preloaded
1180
+ */
1181
+ static preloadForSerialization(opts = {}) {
1182
+ return this.query().preloadForSerialization(opts);
1183
+ }
1184
+ /**
1185
+ * Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
1186
+ * in a DreamSerializer using left join preloading. This traverses the entire content tree
1187
+ * of serializers to automatically load all necessary associations in a single query,
1188
+ * eliminating N+1 query problems and removing the need to manually remember which
1189
+ * associations to preload for serialization.
1190
+ *
1191
+ * This method decouples data loading code from data rendering code by having the serializer
1192
+ * (rendering code) inform the query (loading code) about which associations are needed.
1193
+ * As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
1194
+ * modifying existing ones - the loading code automatically adapts without requiring
1195
+ * corresponding modifications to left join preload statements.
1196
+ *
1197
+ * This method analyzes the serializer (specified by `serializerKey` or 'default') and
1198
+ * automatically left join preloads all associations that will be needed during serialization.
1199
+ *
1200
+ * Note: Left join preloading loads all data in a single SQL query but has trade-offs compared
1201
+ * to regular preloading. See {@link Dream.leftJoinPreload} for details about limitations.
1202
+ *
1203
+ * ```ts
1204
+ * // Instead of manually specifying all associations:
1205
+ * await User.leftJoinPreload('posts', 'comments', 'replies').all()
1206
+ *
1207
+ * // Automatically left join preload everything needed for serialization:
1208
+ * await User.leftJoinPreloadForSerialization({ serializerKey: 'summary' }).all()
1209
+ *
1210
+ * // Add where conditions to specific associations during left join preloading:
1211
+ * await User.leftJoinPreloadForSerialization({
1212
+ * serializerKey: 'detailed',
1213
+ * modifierFn: (dreamClass, associationName) => {
1214
+ * if (dreamClass.typeof(Post) && associationName === 'comments') {
1215
+ * return { and: { published: true } }
1216
+ * }
1217
+ * }
1218
+ * }).all()
1219
+ *
1220
+ * // Skip left join preloading specific associations to handle them manually:
1221
+ * await User.leftJoinPreloadForSerialization({
1222
+ * serializerKey: 'summary',
1223
+ * modifierFn: (dreamClass, associationName) => {
1224
+ * if (dreamClass.typeof(User) && associationName === 'posts') {
1225
+ * return 'omit' // Handle posts preloading separately with custom logic
1226
+ * }
1227
+ * }
1228
+ * })
1229
+ * .preload('posts', { and: { featured: true } }) // Custom preloading instead
1230
+ * .all()
1231
+ * ```
1232
+ *
1233
+ * @param opts - Configuration options for serialization preloading
1234
+ * @param opts.serializerKey - The serializer key to use for determining which associations to preload. Defaults to 'default'
1235
+ * @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
1236
+ * @returns A Query with all serialization associations left join preloaded
1237
+ */
1238
+ static leftJoinPreloadForSerialization(opts = {}) {
1239
+ return this.query().leftJoinPreloadForSerialization(opts);
1240
+ }
1020
1241
  /**
1021
1242
  * Returns a new Query instance with the provided
1022
1243
  * inner join statement attached
@@ -1213,7 +1434,7 @@ class Dream {
1213
1434
  * // 3
1214
1435
  * ```
1215
1436
  *
1216
- * @param fields - a list of fields to pluck, followed by a callback function to call for each set of found fields
1437
+ * @param args - a list of fields to pluck, followed by a callback function to call for each set of found fields
1217
1438
  * @returns void
1218
1439
  */
1219
1440
  static async pluckEach(...args) {
@@ -1422,7 +1643,7 @@ class Dream {
1422
1643
  * // [User{email: 'how@yadoin'}, User{name: 'fred'}, User{name: 'fred'}]
1423
1644
  * ```
1424
1645
  *
1425
- * @param whereStatements - a list of where statements to `OR` together
1646
+ * @param statements - a list of where statements to `OR` together
1426
1647
  * @returns A Query for this model with the whereAny clause applied
1427
1648
  */
1428
1649
  static whereAny(statements) {
@@ -1437,7 +1658,7 @@ class Dream {
1437
1658
  * // User{email: 'hello@world'}
1438
1659
  * ```
1439
1660
  *
1440
- * @param whereStatement - A where statement to negate and apply to the Query
1661
+ * @param attributes - A where statement to negate and apply to the Query
1441
1662
  * @returns A Query for this model with the whereNot clause applied
1442
1663
  */
1443
1664
  static whereNot(attributes) {
@@ -2377,7 +2598,7 @@ class Dream {
2377
2598
  * // 'dog'
2378
2599
  * ```
2379
2600
  *
2380
- * @param columName - The column name you want the previous value for
2601
+ * @param columnName - The column name you want the previous value for
2381
2602
  * @returns Returns the previous value for an attribute
2382
2603
  */
2383
2604
  previousValueForAttribute(columnName) {
@@ -2403,7 +2624,7 @@ class Dream {
2403
2624
  * Returns true if the columnName provided has
2404
2625
  * changes that have not yet been persisted.
2405
2626
  *
2406
- * @param columnName - the column name to check
2627
+ * @param attribute - the column name to check
2407
2628
  * @returns A boolean
2408
2629
  */
2409
2630
  willSaveChangeToAttribute(attribute) {
@@ -2840,7 +3061,7 @@ class Dream {
2840
3061
  /**
2841
3062
  * Loads the requested associations upon execution
2842
3063
  *
2843
- * NOTE: {@link #preload} is often a preferrable way of achieving the
3064
+ * NOTE: {@link Dream.preload} is often a preferrable way of achieving the
2844
3065
  * same goal.
2845
3066
  *
2846
3067
  * ```ts
@@ -2864,18 +3085,17 @@ class Dream {
2864
3085
  }
2865
3086
  /**
2866
3087
  * Load each specified association using a single SQL query.
2867
- * See {@link #load} for loading in separate queries.
3088
+ * See {@link Dream.load} for loading in separate queries.
2868
3089
  *
2869
- * Note: since leftJoinPreload loads via single query, it has
2870
- * some downsides and that may be avoided using {@link #load}:
3090
+ * Note: since leftJoinLoad loads via single query, it has
3091
+ * some downsides and that may be avoided using {@link Dream.load}:
2871
3092
  * 1. `limit` and `offset` will be automatically removed
2872
3093
  * 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
2873
- * 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
3094
+ * 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinLoad('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
2874
3095
  * 4. the individual query becomes more complex the more associations are included
2875
3096
  * 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.load(...).findEach(...)` avoids instantiating massive amounts of data at once
2876
- * Loads the requested associations upon execution
2877
3097
  *
2878
- * NOTE: {@link #leftJoinPreload} is often a preferrable way of achieving the
3098
+ * NOTE: {@link Dream.leftJoinPreload} is often a preferrable way of achieving the
2879
3099
  * same goal.
2880
3100
  *
2881
3101
  * ```ts
@@ -3009,7 +3229,8 @@ class Dream {
3009
3229
  * user.type // 'User'
3010
3230
  * ```
3011
3231
  *
3012
- * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
3232
+ * @param __namedParameters - optional parameters
3233
+ * @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
3013
3234
  * @returns void
3014
3235
  */
3015
3236
  async save({ skipHooks } = {}) {
@@ -3049,7 +3270,8 @@ class Dream {
3049
3270
  * ```
3050
3271
  *
3051
3272
  * @param attributes - the attributes to set on the model
3052
- * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
3273
+ * @param __namedParameters - optional parameters
3274
+ * @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
3053
3275
  * @returns void
3054
3276
  */
3055
3277
  async update(attributes, { skipHooks } = {}) {
@@ -3076,7 +3298,8 @@ class Dream {
3076
3298
  * ```
3077
3299
  *
3078
3300
  * @param attributes - The attributes to update on this instance
3079
- * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
3301
+ * @param __namedParameters - optional parameters
3302
+ * @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
3080
3303
  * @returns - void
3081
3304
  */
3082
3305
  async updateAttributes(attributes, { skipHooks } = {}) {
@@ -3109,7 +3332,7 @@ class Dream {
3109
3332
  * Flags a dream model so that it allows
3110
3333
  * deletion once again.
3111
3334
  *
3112
- * Undoes {@link Dream.(preventDeletion:instance) | preventDeletion}
3335
+ * Undoes {@link Dream.preventDeletion}
3113
3336
  *
3114
3337
  * ```ts
3115
3338
  * class User extends ApplicationModel {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const commander_1 = require("commander");
4
4
  const index_js_1 = require("../bin/index.js");
5
+ const index_js_2 = require("../dream-app/index.js");
5
6
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
7
  const sspawn_js_1 = require("../helpers/sspawn.js");
7
8
  const DreamCliLogger_js_1 = require("./logger/DreamCliLogger.js");
@@ -141,6 +142,21 @@ class DreamCLI {
141
142
  await seedDb();
142
143
  process.exit();
143
144
  });
145
+ program
146
+ .command('inspect:serialization')
147
+ .alias('i:serialization')
148
+ .description('displays a serialization map to help understand the rendering logic for a particular model')
149
+ .argument('<globalName>', 'the global name of the model you want to look up')
150
+ .argument('[serializerKey]', 'the serializer key you wish to use')
151
+ .action(async (globalName, serializerKey) => {
152
+ await initializeDreamApp();
153
+ const dreamApp = index_js_2.default.getOrFail();
154
+ const modelClass = dreamApp.models[globalName];
155
+ if (!modelClass)
156
+ throw new Error(`failed to locate model by global name: ${globalName}`);
157
+ modelClass['displaySerialization'](serializerKey);
158
+ process.exit();
159
+ });
144
160
  }
145
161
  /*
146
162
  * the default spawn provided by node:child_process is incompatible
@@ -11,8 +11,9 @@ class DreamMigrationHelpers {
11
11
  *
12
12
  * @param db - The Kysely database object passed into the migration up/down function
13
13
  * @param constraintName - The name of the constraint to create
14
- * @param opts.table - The name of the table
15
- * @param opts.columns[] - The names of the columns to include in the constraint
14
+ * @param options - Configuration options
15
+ * @param options.table - The name of the table
16
+ * @param options.columns - The names of the columns to include in the constraint
16
17
  *
17
18
  */
18
19
  static async addDeferrableUniqueConstraint(db, constraintName, { table, columns, }) {
@@ -30,9 +31,9 @@ class DreamMigrationHelpers {
30
31
  * Note that this always includes "IF NOT EXISTS", so is safe to re-run multiple times.
31
32
  *
32
33
  * @param db - The Kysely database object passed into the migration up/down function
33
- * @param opt.enumName - The name of the enum to modify
34
- * @param opt.value - The name of the value to add to the enum
35
- *
34
+ * @param __namedParameters - The options for adding the enum value
35
+ * @param __namedParameters.enumName - The name of the enum to modify
36
+ * @param __namedParameters.value - The name of the value to add to the enum
36
37
  */
37
38
  static async addEnumValue(db, { enumName, value }) {
38
39
  await (0, kysely_1.sql) `ALTER TYPE ${kysely_1.sql.raw(enumName)} ADD VALUE IF NOT EXISTS '${kysely_1.sql.raw(value)}';`.execute(db);
@@ -50,8 +51,9 @@ class DreamMigrationHelpers {
50
51
  *
51
52
  * @param db - The Kysely database object passed into the migration up/down function
52
53
  * @param extensionName - The name of the database extension to add
53
- * @param opt.ifNotExists - Only add the extension if it doesn't already exist
54
- * @param opt.publicSchema - Create using the public schema
54
+ * @param options - Configuration options
55
+ * @param options.ifNotExists - Only add the extension if it doesn't already exist
56
+ * @param options.publicSchema - Create using the public schema
55
57
  *
56
58
  */
57
59
  static async createExtension(db, extensionName, { ifNotExists = true, publicSchema = true } = {}) {
@@ -66,8 +68,9 @@ class DreamMigrationHelpers {
66
68
  *
67
69
  * @param db - The Kysely database object passed into the migration up/down function
68
70
  * @param indexName - The name of the constraint to create
69
- * @param opts.table - The name of the table
70
- * @param opts.column - The name of the column to index
71
+ * @param options - Configuration options
72
+ * @param options.table - The name of the table
73
+ * @param options.column - The name of the column to index
71
74
  *
72
75
  */
73
76
  static async createGinIndex(db, indexName, { table, column }) {
@@ -82,7 +85,8 @@ class DreamMigrationHelpers {
82
85
  *
83
86
  * @param db - The Kysely database object passed into the migration up/down function
84
87
  * @param constraintName - The name of the constraint to create
85
- * @param opts.table - The name of the table
88
+ * @param options - Configuration options
89
+ * @param options.table - The name of the table
86
90
  *
87
91
  */
88
92
  static async dropConstraint(db, constraintName, { table }) {
@@ -94,10 +98,10 @@ class DreamMigrationHelpers {
94
98
  * Drop a value from an enum and replace it (or optionally remove it from array columns)
95
99
  *
96
100
  * @param db - The Kysely database object passed into the migration up/down function
97
- * @param opt.enumName - The name of the enum to modify
98
- * @param opt.value - The name of the value to drop from the enum
99
- * @param opt.replacements[] - Details about which table and column to change and which value to replace the dropped value with (or remove it if the column is an array)
100
- *
101
+ * @param __namedParameters - The options for dropping the enum value
102
+ * @param __namedParameters.enumName - The name of the enum to modify
103
+ * @param __namedParameters.value - The name of the value to drop from the enum
104
+ * @param __namedParameters.replacements - Details about which table and column to change and which value to replace the dropped value with (or remove it if the column is an array)
101
105
  */
102
106
  static async dropEnumValue(db, { enumName, value, replacements }) {
103
107
  // temporarily set all table columns depending on this enum to an acceptable alternate type
@@ -161,7 +161,8 @@ class Decorators {
161
161
  * }
162
162
  * ```
163
163
  *
164
- * @param scope - The column, association, or combination there-of which you would like to restrict the incrementing logic to
164
+ * @param opts - Configuration options for the sortable decorator
165
+ * @param opts.scope - The column, association, or combination thereof which you would like to restrict the incrementing logic to. Can be a single column name, a single belongs-to association name, or an array of column/association names
165
166
  * @returns A Sortable decorator
166
167
  */
167
168
  Sortable(opts) {