@rvoh/dream 0.34.0 → 0.35.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 (219) hide show
  1. package/dist/cjs/src/Dream.js +25 -10
  2. package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +14 -0
  3. package/dist/cjs/src/dream/internal/destroyDream.js +1 -2
  4. package/dist/cjs/src/dream/internal/runHooksFor.js +66 -28
  5. package/dist/cjs/src/dream/internal/saveDream.js +2 -4
  6. package/dist/cjs/src/dream/internal/undestroyDream.js +1 -2
  7. package/dist/cjs/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.js +18 -0
  8. package/dist/cjs/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.js +18 -0
  9. package/dist/cjs/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.js +18 -0
  10. package/dist/cjs/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.js +18 -0
  11. package/dist/cjs/src/helpers/DreamLogos/DreamLogos.js +12 -0
  12. package/dist/cjs/src/helpers/{DreamGlam/howyadoins/whaaaaaaaaaaok.js → DreamLogos/logos.js} +2 -2
  13. package/dist/cjs/src/helpers/areEqual.js +29 -0
  14. package/dist/cjs/src/helpers/cli/autoGeneratedFileDisclaimer.js +2 -2
  15. package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -2
  16. package/dist/cjs/src/helpers/cli/generateSerializerContent.js +14 -6
  17. package/dist/cjs/src/helpers/notEqual.js +7 -0
  18. package/dist/cjs/src/helpers/uniq.js +3 -4
  19. package/dist/cjs/src/index.js +3 -3
  20. package/dist/esm/src/Dream.js +25 -10
  21. package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +14 -0
  22. package/dist/esm/src/dream/internal/destroyDream.js +1 -2
  23. package/dist/esm/src/dream/internal/runHooksFor.js +66 -28
  24. package/dist/esm/src/dream/internal/saveDream.js +2 -4
  25. package/dist/esm/src/dream/internal/undestroyDream.js +1 -2
  26. package/dist/esm/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.js +15 -0
  27. package/dist/esm/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.js +15 -0
  28. package/dist/esm/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.js +15 -0
  29. package/dist/esm/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.js +15 -0
  30. package/dist/esm/src/helpers/DreamLogos/DreamLogos.js +9 -0
  31. package/dist/esm/src/helpers/{DreamGlam/howyadoins/whaaaaaaaaaaok.js → DreamLogos/logos.js} +1 -1
  32. package/dist/esm/src/helpers/areEqual.js +26 -0
  33. package/dist/esm/src/helpers/cli/autoGeneratedFileDisclaimer.js +2 -2
  34. package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -2
  35. package/dist/esm/src/helpers/cli/generateSerializerContent.js +14 -6
  36. package/dist/esm/src/helpers/notEqual.js +4 -0
  37. package/dist/esm/src/helpers/uniq.js +3 -4
  38. package/dist/esm/src/index.js +1 -1
  39. package/dist/types/src/Dream.d.ts +1 -0
  40. package/dist/types/src/decorators/Decorators.d.ts +27 -27
  41. package/dist/types/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.d.ts +7 -0
  42. package/dist/types/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.d.ts +7 -0
  43. package/dist/types/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.d.ts +7 -0
  44. package/dist/types/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.d.ts +7 -0
  45. package/dist/types/src/helpers/DreamLogos/DreamLogos.d.ts +4 -0
  46. package/dist/types/src/helpers/DreamLogos/logos.d.ts +2 -0
  47. package/dist/types/src/helpers/areEqual.d.ts +1 -0
  48. package/dist/types/src/helpers/notEqual.d.ts +1 -0
  49. package/dist/types/src/index.d.ts +1 -1
  50. package/docs/assets/icons.js +1 -1
  51. package/docs/assets/icons.svg +1 -1
  52. package/docs/assets/main.js +1 -1
  53. package/docs/assets/navigation.js +1 -1
  54. package/docs/assets/search.js +1 -1
  55. package/docs/assets/style.css +21 -66
  56. package/docs/classes/Benchmark.html +2 -2
  57. package/docs/classes/CalendarDate.html +2 -2
  58. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +5 -6
  59. package/docs/classes/Decorators.html +38 -38
  60. package/docs/classes/Dream.html +131 -130
  61. package/docs/classes/DreamApplication.html +4 -4
  62. package/docs/classes/DreamBin.html +2 -2
  63. package/docs/classes/DreamCLI.html +4 -4
  64. package/docs/classes/DreamImporter.html +2 -2
  65. package/docs/classes/DreamLogos.html +4 -0
  66. package/docs/classes/DreamMigrationHelpers.html +7 -7
  67. package/docs/classes/DreamSerializer.html +2 -2
  68. package/docs/classes/DreamTransaction.html +2 -2
  69. package/docs/classes/Encrypt.html +2 -2
  70. package/docs/classes/Env.html +2 -2
  71. package/docs/classes/GlobalNameNotSet.html +5 -6
  72. package/docs/classes/NonLoadedAssociation.html +5 -6
  73. package/docs/classes/Query.html +50 -50
  74. package/docs/classes/Range.html +2 -2
  75. package/docs/classes/RecordNotFound.html +5 -6
  76. package/docs/classes/ValidationError.html +5 -6
  77. package/docs/functions/Attribute.html +1 -1
  78. package/docs/functions/RendersMany.html +1 -1
  79. package/docs/functions/RendersOne.html +1 -1
  80. package/docs/functions/ReplicaSafe.html +1 -1
  81. package/docs/functions/STI.html +1 -1
  82. package/docs/functions/SoftDelete.html +1 -1
  83. package/docs/functions/camelize.html +1 -1
  84. package/docs/functions/capitalize.html +1 -1
  85. package/docs/functions/closeAllDbConnections.html +1 -1
  86. package/docs/functions/compact.html +1 -1
  87. package/docs/functions/debug.html +1 -1
  88. package/docs/functions/dreamDbConnections.html +1 -1
  89. package/docs/functions/dreamPath.html +1 -1
  90. package/docs/functions/generateDream.html +1 -1
  91. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  92. package/docs/functions/hyphenize.html +1 -1
  93. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
  94. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  95. package/docs/functions/isEmpty.html +1 -1
  96. package/docs/functions/loadRepl.html +1 -1
  97. package/docs/functions/lookupClassByGlobalName.html +1 -1
  98. package/docs/functions/pascalize.html +1 -1
  99. package/docs/functions/pgErrorType.html +1 -1
  100. package/docs/functions/range-1.html +1 -1
  101. package/docs/functions/relativeDreamPath.html +1 -1
  102. package/docs/functions/round.html +1 -1
  103. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  104. package/docs/functions/sharedPathPrefix.html +1 -1
  105. package/docs/functions/snakeify.html +1 -1
  106. package/docs/functions/sort.html +1 -1
  107. package/docs/functions/sortBy.html +1 -1
  108. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  109. package/docs/functions/uncapitalize.html +1 -1
  110. package/docs/functions/uniq.html +1 -1
  111. package/docs/functions/untypedDb.html +1 -1
  112. package/docs/functions/validateColumn.html +1 -1
  113. package/docs/functions/validateTable.html +1 -1
  114. package/docs/index.html +7 -7
  115. package/docs/interfaces/AttributeStatement.html +2 -2
  116. package/docs/interfaces/DecoratorContext.html +2 -2
  117. package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
  118. package/docs/interfaces/DreamApplicationOpts.html +2 -2
  119. package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
  120. package/docs/interfaces/EncryptOptions.html +2 -2
  121. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  122. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  123. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  124. package/docs/modules.html +9 -9
  125. package/docs/types/Camelized.html +1 -1
  126. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  127. package/docs/types/DateTime.html +1 -1
  128. package/docs/types/DbConnectionType.html +1 -1
  129. package/docs/types/DreamAssociationMetadata.html +1 -1
  130. package/docs/types/DreamAttributes.html +1 -1
  131. package/docs/types/DreamClassColumn.html +1 -1
  132. package/docs/types/DreamColumn.html +1 -1
  133. package/docs/types/DreamColumnNames.html +1 -1
  134. package/docs/types/DreamLogLevel.html +1 -1
  135. package/docs/types/DreamLogger.html +1 -1
  136. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  137. package/docs/types/DreamParamSafeAttributes.html +1 -1
  138. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  139. package/docs/types/DreamSerializerKey.html +1 -1
  140. package/docs/types/DreamSerializers.html +1 -1
  141. package/docs/types/DreamTableSchema.html +1 -1
  142. package/docs/types/DreamVirtualColumns.html +1 -1
  143. package/docs/types/EncryptAlgorithm.html +1 -1
  144. package/docs/types/Hyphenized.html +1 -1
  145. package/docs/types/IdType.html +1 -1
  146. package/docs/types/OpenapiAllTypes.html +1 -1
  147. package/docs/types/OpenapiFormats.html +1 -1
  148. package/docs/types/OpenapiNumberFormats.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/OpenapiSchemaPartialSegment.html +1 -1
  175. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  176. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  177. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  178. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  179. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  180. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  181. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  182. package/docs/types/OpenapiSchemaString.html +1 -1
  183. package/docs/types/OpenapiShorthandAllTypes.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/SerializableClassOrSerializerCallback.html +1 -1
  190. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
  191. package/docs/types/SerializableDreamOrViewModel.html +1 -1
  192. package/docs/types/SerializableTypes.html +1 -1
  193. package/docs/types/Snakeified.html +1 -1
  194. package/docs/types/Timestamp.html +1 -1
  195. package/docs/types/UpdateableAssociationProperties.html +1 -1
  196. package/docs/types/UpdateableProperties.html +1 -1
  197. package/docs/types/ValidationType.html +1 -1
  198. package/docs/types/ViewModelSerializerKey.html +1 -1
  199. package/docs/types/WhereStatementForDream.html +1 -1
  200. package/docs/types/WhereStatementForDreamClass.html +1 -1
  201. package/docs/variables/DateTime-1.html +1 -1
  202. package/docs/variables/DreamConst.html +1 -1
  203. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  204. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  205. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  206. package/docs/variables/ops.html +1 -1
  207. package/docs/variables/primaryKeyTypes.html +1 -1
  208. package/package.json +4 -4
  209. package/dist/cjs/src/dream/internal/safelyRunCommitHooks.js +0 -15
  210. package/dist/cjs/src/helpers/DreamGlam/DreamGlam.js +0 -16
  211. package/dist/cjs/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.js +0 -42
  212. package/dist/esm/src/dream/internal/safelyRunCommitHooks.js +0 -12
  213. package/dist/esm/src/helpers/DreamGlam/DreamGlam.js +0 -13
  214. package/dist/esm/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.js +0 -39
  215. package/dist/types/src/dream/internal/safelyRunCommitHooks.d.ts +0 -7
  216. package/dist/types/src/helpers/DreamGlam/DreamGlam.d.ts +0 -5
  217. package/dist/types/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.d.ts +0 -1
  218. package/dist/types/src/helpers/DreamGlam/howyadoins/whaaaaaaaaaaok.d.ts +0 -2
  219. package/docs/classes/DreamGlam.html +0 -5
@@ -26,7 +26,11 @@ const undestroyDream_js_1 = require("./dream/internal/undestroyDream.js");
26
26
  const LeftJoinLoadBuilder_js_1 = require("./dream/LeftJoinLoadBuilder.js");
27
27
  const LoadBuilder_js_1 = require("./dream/LoadBuilder.js");
28
28
  const Query_js_1 = require("./dream/Query.js");
29
+ const CannotAssociationQueryOnUnpersistedDream_js_1 = require("./errors/associations/CannotAssociationQueryOnUnpersistedDream.js");
30
+ const CannotCreateAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotCreateAssociationOnUnpersistedDream.js");
31
+ const CannotDestroyAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotDestroyAssociationOnUnpersistedDream.js");
29
32
  const CannotPassNullOrUndefinedToRequiredBelongsTo_js_1 = require("./errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js");
33
+ const CannotUpdateAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotUpdateAssociationOnUnpersistedDream.js");
30
34
  const CanOnlyPassBelongsToModelParam_js_1 = require("./errors/associations/CanOnlyPassBelongsToModelParam.js");
31
35
  const NonLoadedAssociation_js_1 = require("./errors/associations/NonLoadedAssociation.js");
32
36
  const CannotCallUndestroyOnANonSoftDeleteModel_js_1 = require("./errors/CannotCallUndestroyOnANonSoftDeleteModel.js");
@@ -42,6 +46,7 @@ const DateTime_js_1 = require("./helpers/DateTime.js");
42
46
  const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
43
47
  const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
44
48
  const inferSerializerFromDreamOrViewModel_js_1 = require("./helpers/inferSerializerFromDreamOrViewModel.js");
49
+ const notEqual_js_1 = require("./helpers/notEqual.js");
45
50
  const typechecks_js_1 = require("./helpers/typechecks.js");
46
51
  class Dream {
47
52
  DB;
@@ -2245,13 +2250,8 @@ class Dream {
2245
2250
  this.constructor.columns().forEach(column => {
2246
2251
  const was = this.previousValueForAttribute(column);
2247
2252
  const now = this[column];
2248
- if (was !== now) {
2249
- ;
2250
- obj[column] = {
2251
- was,
2252
- now,
2253
- };
2254
- }
2253
+ if ((0, notEqual_js_1.default)(was, now))
2254
+ obj[column] = { was, now };
2255
2255
  });
2256
2256
  return obj;
2257
2257
  }
@@ -2285,7 +2285,7 @@ class Dream {
2285
2285
  * @returns Returns the previous value for an attribute
2286
2286
  */
2287
2287
  previousValueForAttribute(columnName) {
2288
- if (this.frozenAttributes[columnName] !== this[columnName])
2288
+ if ((0, notEqual_js_1.default)(this.frozenAttributes[columnName], this[columnName]))
2289
2289
  return this.frozenAttributes[columnName];
2290
2290
  return this.attributesFromBeforeLastSave[columnName];
2291
2291
  }
@@ -2301,7 +2301,7 @@ class Dream {
2301
2301
  const changes = this.changes();
2302
2302
  const now = changes?.[columnName]?.now;
2303
2303
  const was = changes?.[columnName]?.was;
2304
- return this.isPersisted && now !== was;
2304
+ return this.isPersisted && (0, notEqual_js_1.default)(now, was);
2305
2305
  }
2306
2306
  /**
2307
2307
  * Returns true if the columnName provided has
@@ -2484,7 +2484,12 @@ class Dream {
2484
2484
  * @returns A boolean
2485
2485
  */
2486
2486
  equals(other) {
2487
- return other?.constructor === this.constructor && other.primaryKeyValue === this.primaryKeyValue;
2487
+ if (!other?.isDreamInstance)
2488
+ return false;
2489
+ return this.comparisonKey === other.comparisonKey;
2490
+ }
2491
+ get comparisonKey() {
2492
+ return `${this.constructor.globalName}:${this.primaryKeyValue}`;
2488
2493
  }
2489
2494
  /**
2490
2495
  * @internal
@@ -2547,6 +2552,8 @@ class Dream {
2547
2552
  * @returns The created association
2548
2553
  */
2549
2554
  async createAssociation(associationName, attributes = {}) {
2555
+ if (this.isNewRecord)
2556
+ throw new CannotCreateAssociationOnUnpersistedDream_js_1.default(this, associationName);
2550
2557
  return (0, createAssociation_js_1.default)(this, null, associationName, attributes);
2551
2558
  }
2552
2559
  /**
@@ -2567,6 +2574,8 @@ class Dream {
2567
2574
  * @returns The number of records deleted
2568
2575
  */
2569
2576
  async destroyAssociation(associationName, options) {
2577
+ if (this.isNewRecord)
2578
+ throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
2570
2579
  return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
2571
2580
  ...(0, destroyOptions_js_1.destroyOptions)(options),
2572
2581
  joinOnStatements: {
@@ -2599,6 +2608,8 @@ class Dream {
2599
2608
  * @returns The number of records deleted
2600
2609
  */
2601
2610
  async reallyDestroyAssociation(associationName, options) {
2611
+ if (this.isNewRecord)
2612
+ throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
2602
2613
  return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
2603
2614
  ...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
2604
2615
  joinOnStatements: {
@@ -2650,6 +2661,8 @@ class Dream {
2650
2661
  *
2651
2662
  */
2652
2663
  associationQuery(associationName, joinOnStatements) {
2664
+ if (this.isNewRecord)
2665
+ throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this, associationName);
2653
2666
  return (0, associationQuery_js_1.default)(this, null, associationName, {
2654
2667
  joinOnStatements: joinOnStatements,
2655
2668
  bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
@@ -2679,6 +2692,8 @@ class Dream {
2679
2692
  * @returns The number of updated records
2680
2693
  */
2681
2694
  async updateAssociation(associationName, attributes, updateAssociationOptions) {
2695
+ if (this.isNewRecord)
2696
+ throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this, associationName);
2682
2697
  return (0, associationUpdateQuery_js_1.default)(this, null, associationName, {
2683
2698
  joinOnStatements: {
2684
2699
  on: updateAssociationOptions?.on,
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CannotAssociationQueryOnUnpersistedDream_js_1 = require("../errors/associations/CannotAssociationQueryOnUnpersistedDream.js");
4
+ const CannotCreateAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotCreateAssociationOnUnpersistedDream.js");
5
+ const CannotDestroyAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotDestroyAssociationOnUnpersistedDream.js");
6
+ const CannotUpdateAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotUpdateAssociationOnUnpersistedDream.js");
3
7
  const associationQuery_js_1 = require("./internal/associations/associationQuery.js");
4
8
  const associationUpdateQuery_js_1 = require("./internal/associations/associationUpdateQuery.js");
5
9
  const createAssociation_js_1 = require("./internal/associations/createAssociation.js");
@@ -310,6 +314,8 @@ class DreamInstanceTransactionBuilder {
310
314
  * @returns A Query scoped to the specified association on the current instance
311
315
  */
312
316
  associationQuery(associationName, joinOnStatements) {
317
+ if (this.dreamInstance.isNewRecord)
318
+ throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
313
319
  return (0, associationQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
314
320
  joinOnStatements: joinOnStatements,
315
321
  bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
@@ -341,6 +347,8 @@ class DreamInstanceTransactionBuilder {
341
347
  * @returns The number of updated records
342
348
  */
343
349
  async updateAssociation(associationName, attributes, updateAssociationOptions) {
350
+ if (this.dreamInstance.isNewRecord)
351
+ throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
344
352
  return await (0, associationUpdateQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
345
353
  joinOnStatements: {
346
354
  on: updateAssociationOptions?.on,
@@ -367,6 +375,8 @@ class DreamInstanceTransactionBuilder {
367
375
  * @returns The created association
368
376
  */
369
377
  async createAssociation(associationName, opts = {}) {
378
+ if (this.dreamInstance.isNewRecord)
379
+ throw new CannotCreateAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
370
380
  return await (0, createAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, opts);
371
381
  }
372
382
  /**
@@ -389,6 +399,8 @@ class DreamInstanceTransactionBuilder {
389
399
  * @returns The number of records deleted
390
400
  */
391
401
  async destroyAssociation(associationName, options) {
402
+ if (this.dreamInstance.isNewRecord)
403
+ throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
392
404
  return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
393
405
  ...(0, destroyOptions_js_1.destroyOptions)(options),
394
406
  joinOnStatements: {
@@ -423,6 +435,8 @@ class DreamInstanceTransactionBuilder {
423
435
  * @returns The number of records deleted
424
436
  */
425
437
  async reallyDestroyAssociation(associationName, options) {
438
+ if (this.dreamInstance.isNewRecord)
439
+ throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
426
440
  return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
427
441
  ...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
428
442
  joinOnStatements: {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = destroyDream;
4
4
  const destroyAssociatedRecords_js_1 = require("./destroyAssociatedRecords.js");
5
5
  const runHooksFor_js_1 = require("./runHooksFor.js");
6
- const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
7
6
  const softDeleteDream_js_1 = require("./softDeleteDream.js");
8
7
  /**
9
8
  * @internal
@@ -42,7 +41,7 @@ async function destroyDreamWithTransaction(dream, txn, options) {
42
41
  await maybeDestroyDream(dream, txn, reallyDestroy);
43
42
  if (!skipHooks) {
44
43
  await (0, runHooksFor_js_1.default)('afterDestroy', dream, true, null, txn || undefined);
45
- await (0, safelyRunCommitHooks_js_1.default)(dream, 'afterDestroyCommit', true, null, txn);
44
+ await (0, runHooksFor_js_1.default)('afterDestroyCommit', dream, true, null, txn);
46
45
  }
47
46
  if (shouldSoftDelete(dream, reallyDestroy)) {
48
47
  await dream.txn(txn).reload();
@@ -4,48 +4,90 @@ exports.default = runHooksFor;
4
4
  exports.runHook = runHook;
5
5
  async function runHooksFor(key, dream, alreadyPersisted, beforeSaveChanges, txn) {
6
6
  const Base = dream.constructor;
7
- for (const statement of Base['hooks'][key]) {
8
- if (statement.ifChanging?.length) {
7
+ for (const hook of Base['hooks'][key]) {
8
+ if (hook.ifChanging?.length) {
9
9
  switch (key) {
10
10
  case 'beforeCreate':
11
- await runConditionalBeforeHooksForCreate(dream, statement, txn);
11
+ if (shouldRunBeforeCreateHook(dream, hook)) {
12
+ await runHook(hook, dream, txn);
13
+ }
12
14
  break;
13
15
  case 'beforeSave':
14
- if (alreadyPersisted)
15
- await runConditionalBeforeHooksForUpdate(dream, statement, txn);
16
- else
17
- await runConditionalBeforeHooksForCreate(dream, statement, txn);
16
+ if ((alreadyPersisted && shouldRunBeforeUpdateHook(dream, hook)) ||
17
+ (!alreadyPersisted && shouldRunBeforeCreateHook(dream, hook))) {
18
+ await runHook(hook, dream, txn);
19
+ }
18
20
  break;
19
21
  case 'beforeUpdate':
20
- await runConditionalBeforeHooksForUpdate(dream, statement, txn);
22
+ if (shouldRunBeforeUpdateHook(dream, hook)) {
23
+ await runHook(hook, dream, txn);
24
+ }
21
25
  break;
22
26
  default:
23
27
  throw new Error(`Unexpected statement key detected with ifChanging clause: ${key}`);
24
28
  }
25
29
  }
26
- else if (statement.ifChanged?.length) {
30
+ else if (hook.ifChanged?.length) {
27
31
  switch (key) {
28
32
  case 'afterCreate':
33
+ if (shouldRunAfterCreateHook(dream, hook, beforeSaveChanges)) {
34
+ await runHook(hook, dream, txn);
35
+ }
36
+ break;
29
37
  case 'afterCreateCommit':
30
- await runConditionalAfterHooksForCreate(dream, statement, beforeSaveChanges, txn);
38
+ if (shouldRunAfterCreateHook(dream, hook, beforeSaveChanges)) {
39
+ if (txn)
40
+ txn.addCommitHook(hook, dream);
41
+ else
42
+ await runHook(hook, dream);
43
+ }
31
44
  break;
32
45
  case 'afterSave':
46
+ if ((alreadyPersisted && shouldRunAfterUpdateHook(dream, hook)) ||
47
+ (!alreadyPersisted && shouldRunAfterCreateHook(dream, hook, beforeSaveChanges))) {
48
+ await runHook(hook, dream, txn);
49
+ }
50
+ break;
33
51
  case 'afterSaveCommit':
34
- if (alreadyPersisted)
35
- await runConditionalAfterHooksForUpdate(dream, statement, txn);
36
- else
37
- await runConditionalAfterHooksForCreate(dream, statement, beforeSaveChanges, txn);
52
+ if ((alreadyPersisted && shouldRunAfterUpdateHook(dream, hook)) ||
53
+ (!alreadyPersisted && shouldRunAfterCreateHook(dream, hook, beforeSaveChanges))) {
54
+ if (txn)
55
+ txn.addCommitHook(hook, dream);
56
+ else
57
+ await runHook(hook, dream);
58
+ }
38
59
  break;
39
60
  case 'afterUpdate':
61
+ if (shouldRunAfterUpdateHook(dream, hook)) {
62
+ await runHook(hook, dream, txn);
63
+ }
64
+ break;
40
65
  case 'afterUpdateCommit':
41
- await runConditionalAfterHooksForUpdate(dream, statement, txn);
66
+ if (shouldRunAfterUpdateHook(dream, hook)) {
67
+ if (txn)
68
+ txn.addCommitHook(hook, dream);
69
+ else
70
+ await runHook(hook, dream);
71
+ }
42
72
  break;
43
73
  default:
44
74
  throw new Error(`Unexpected statement key detected with ifChanged clause: ${key}`);
45
75
  }
46
76
  }
47
77
  else {
48
- await runHook(statement, dream, txn);
78
+ switch (key) {
79
+ case 'afterCreateCommit':
80
+ case 'afterSaveCommit':
81
+ case 'afterUpdateCommit':
82
+ case 'afterDestroyCommit':
83
+ if (txn)
84
+ txn.addCommitHook(hook, dream);
85
+ else
86
+ await runHook(hook, dream);
87
+ break;
88
+ default:
89
+ await runHook(hook, dream, txn);
90
+ }
49
91
  }
50
92
  }
51
93
  }
@@ -60,40 +102,36 @@ Please make sure "${statement.method}" is defined on ${dream['sanitizedConstruct
60
102
  }
61
103
  await dream[statement.method](txn);
62
104
  }
63
- async function runConditionalBeforeHooksForCreate(dream, statement, txn) {
105
+ function shouldRunBeforeCreateHook(dream, statement) {
64
106
  let shouldRun = false;
65
107
  for (const attribute of statement.ifChanging) {
66
108
  if (dream[attribute] !== undefined)
67
109
  shouldRun = true;
68
110
  }
69
- if (shouldRun)
70
- await runHook(statement, dream, txn);
111
+ return shouldRun;
71
112
  }
72
- async function runConditionalAfterHooksForCreate(dream, statement, beforeSaveChanges, txn) {
113
+ function shouldRunAfterCreateHook(dream, statement, beforeSaveChanges) {
73
114
  let shouldRun = false;
74
115
  for (const attribute of statement.ifChanged) {
75
116
  if (beforeSaveChanges?.[attribute] &&
76
117
  beforeSaveChanges[attribute].was !== beforeSaveChanges[attribute].now)
77
118
  shouldRun = true;
78
119
  }
79
- if (shouldRun)
80
- await runHook(statement, dream, txn);
120
+ return shouldRun;
81
121
  }
82
- async function runConditionalBeforeHooksForUpdate(dream, statement, txn) {
122
+ function shouldRunBeforeUpdateHook(dream, statement) {
83
123
  let shouldRun = false;
84
124
  for (const attribute of statement.ifChanging) {
85
125
  if (dream.willSaveChangeToAttribute(attribute))
86
126
  shouldRun = true;
87
127
  }
88
- if (shouldRun)
89
- await runHook(statement, dream, txn);
128
+ return shouldRun;
90
129
  }
91
- async function runConditionalAfterHooksForUpdate(dream, statement, txn) {
130
+ function shouldRunAfterUpdateHook(dream, statement) {
92
131
  let shouldRun = false;
93
132
  for (const attribute of statement.ifChanged) {
94
133
  if (dream.savedChangeToAttribute(attribute))
95
134
  shouldRun = true;
96
135
  }
97
- if (shouldRun)
98
- await runHook(statement, dream, txn);
136
+ return shouldRun;
99
137
  }
@@ -8,7 +8,6 @@ const namespaceColumn_js_1 = require("../../helpers/namespaceColumn.js");
8
8
  const sqlAttributes_js_1 = require("../../helpers/sqlAttributes.js");
9
9
  const executeDatabaseQuery_js_1 = require("./executeDatabaseQuery.js");
10
10
  const runHooksFor_js_1 = require("./runHooksFor.js");
11
- const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
12
11
  async function saveDream(dream, txn = null, { skipHooks = false } = {}) {
13
12
  const db = txn?.kyselyTransaction || (0, index_js_1.default)('primary');
14
13
  const alreadyPersisted = dream.isPersisted;
@@ -59,9 +58,8 @@ async function saveDream(dream, txn = null, { skipHooks = false } = {}) {
59
58
  await (0, runHooksFor_js_1.default)('afterUpdate', dream, alreadyPersisted, beforeSaveChanges, txn);
60
59
  else
61
60
  await (0, runHooksFor_js_1.default)('afterCreate', dream, alreadyPersisted, beforeSaveChanges, txn);
62
- const commitHookType = alreadyPersisted ? 'afterUpdateCommit' : 'afterCreateCommit';
63
- await (0, safelyRunCommitHooks_js_1.default)(dream, commitHookType, alreadyPersisted, beforeSaveChanges, txn);
64
- await (0, safelyRunCommitHooks_js_1.default)(dream, 'afterSaveCommit', alreadyPersisted, beforeSaveChanges, txn);
61
+ await (0, runHooksFor_js_1.default)(alreadyPersisted ? 'afterUpdateCommit' : 'afterCreateCommit', dream, alreadyPersisted, beforeSaveChanges, txn);
62
+ await (0, runHooksFor_js_1.default)('afterSaveCommit', dream, alreadyPersisted, beforeSaveChanges, txn);
65
63
  }
66
64
  return dream;
67
65
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = undestroyDream;
4
4
  const setPosition_js_1 = require("../../decorators/field/sortable/helpers/setPosition.js");
5
5
  const runHooksFor_js_1 = require("./runHooksFor.js");
6
- const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
7
6
  /**
8
7
  * @internal
9
8
  *
@@ -41,7 +40,7 @@ async function undestroyDreamWithTransaction(dream, txn, options) {
41
40
  }
42
41
  if (!skipHooks) {
43
42
  await (0, runHooksFor_js_1.default)('afterUpdate', dream, true, null, txn);
44
- await (0, safelyRunCommitHooks_js_1.default)(dream, 'afterUpdateCommit', true, null, txn);
43
+ await (0, runHooksFor_js_1.default)('afterUpdateCommit', dream, true, null, txn);
45
44
  }
46
45
  await dream.txn(txn).reload();
47
46
  return dream;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CannotAssociationQueryOnUnpersistedDream extends Error {
4
+ dream;
5
+ associationName;
6
+ constructor(dream, associationName) {
7
+ super();
8
+ this.dream = dream;
9
+ this.associationName = associationName;
10
+ }
11
+ get message() {
12
+ return `Cannot perform associationQuery on an unpersisted Dream.
13
+ Dream class: ${this.dream.sanitizedConstructorName}
14
+ Association: ${this.associationName.toString()}
15
+ `;
16
+ }
17
+ }
18
+ exports.default = CannotAssociationQueryOnUnpersistedDream;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CannotCreateAssociationOnUnpersistedDream extends Error {
4
+ dream;
5
+ associationName;
6
+ constructor(dream, associationName) {
7
+ super();
8
+ this.dream = dream;
9
+ this.associationName = associationName;
10
+ }
11
+ get message() {
12
+ return `Cannot perform createAssociation on an unpersisted Dream.
13
+ Dream class: ${this.dream.sanitizedConstructorName}
14
+ Association: ${this.associationName.toString()}
15
+ `;
16
+ }
17
+ }
18
+ exports.default = CannotCreateAssociationOnUnpersistedDream;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CannotDestroyAssociationOnUnpersistedDream extends Error {
4
+ dream;
5
+ associationName;
6
+ constructor(dream, associationName) {
7
+ super();
8
+ this.dream = dream;
9
+ this.associationName = associationName;
10
+ }
11
+ get message() {
12
+ return `Cannot perform destroyAssociation on an unpersisted Dream.
13
+ Dream class: ${this.dream.sanitizedConstructorName}
14
+ Association: ${this.associationName.toString()}
15
+ `;
16
+ }
17
+ }
18
+ exports.default = CannotDestroyAssociationOnUnpersistedDream;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CannotUpdateAssociationOnUnpersistedDream extends Error {
4
+ dream;
5
+ associationName;
6
+ constructor(dream, associationName) {
7
+ super();
8
+ this.dream = dream;
9
+ this.associationName = associationName;
10
+ }
11
+ get message() {
12
+ return `Cannot perform updateAssociation on an unpersisted Dream.
13
+ Dream class: ${this.dream.sanitizedConstructorName}
14
+ Association: ${this.associationName.toString()}
15
+ `;
16
+ }
17
+ }
18
+ exports.default = CannotUpdateAssociationOnUnpersistedDream;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const logos_js_1 = require("./logos.js");
4
+ class DreamLogos {
5
+ static colorful() {
6
+ return (0, logos_js_1.default)();
7
+ }
8
+ static monochrome() {
9
+ return (0, logos_js_1.monochromeLogo)();
10
+ }
11
+ }
12
+ exports.default = DreamLogos;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = whaaaaaaaaaaok;
4
- exports.whaaaaaaaaaaokBasic = whaaaaaaaaaaokBasic;
4
+ exports.monochromeLogo = monochromeLogo;
5
5
  const yoctocolors_1 = require("yoctocolors");
6
6
  function whaaaaaaaaaaok() {
7
7
  return (yoctocolors_1.default.bgMagentaBright(yoctocolors_1.default.black(`
@@ -45,7 +45,7 @@ function whaaaaaaaaaaok() {
45
45
 
46
46
  `)));
47
47
  }
48
- function whaaaaaaaaaaokBasic() {
48
+ function monochromeLogo() {
49
49
  return `
50
50
  ,▄█▄
51
51
  ]█▄▄ ╓█████▌
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = areEqual;
4
+ const CalendarDate_js_1 = require("./CalendarDate.js");
5
+ const DateTime_js_1 = require("./DateTime.js");
6
+ function areEqual(a, b) {
7
+ return areEqualOrUndefined(a, b) ?? areEqualOrUndefined(b, a) ?? JSON.stringify(a) === JSON.stringify(b);
8
+ }
9
+ function areEqualOrUndefined(a, b) {
10
+ if (a === null)
11
+ return b === null;
12
+ if (a === undefined)
13
+ return b === undefined;
14
+ if (typeof a === 'boolean')
15
+ return a === b;
16
+ if (typeof a === 'number')
17
+ return a === b;
18
+ if (typeof a === 'string')
19
+ return a === b;
20
+ if (a instanceof DateTime_js_1.DateTime)
21
+ return b instanceof DateTime_js_1.DateTime && a.equals(b);
22
+ if (a instanceof CalendarDate_js_1.default)
23
+ return b instanceof CalendarDate_js_1.default && a.equals(b);
24
+ if (Array.isArray(a))
25
+ return Array.isArray(b) && a.length === b.length && !a.find((value, index) => !areEqual(value, b[index]));
26
+ if (a?.isDreamInstance)
27
+ return a.equals(b);
28
+ return undefined;
29
+ }
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = autogeneratedFileDisclaimer;
4
- const DreamGlam_js_1 = require("../DreamGlam/DreamGlam.js");
4
+ const DreamLogos_js_1 = require("../DreamLogos/DreamLogos.js");
5
5
  function autogeneratedFileDisclaimer(startComment = '\n/*', endComment = '\n*/') {
6
6
  return `\
7
7
  ${startComment}
8
- ${DreamGlam_js_1.default.whaaaaaaaaaaokBasic()}
8
+ ${DreamLogos_js_1.default.monochrome()}
9
9
 
10
10
  This file was automatically generated by my cat, Aster.
11
11
  He does not want you mucking about with his files,
@@ -78,7 +78,7 @@ public ${(0, camelize_js_1.default)(attributeName)}: ${getAttributeType(attribut
78
78
  return `\
79
79
  import { ${(0, uniq_js_1.default)(dreamImports).join(', ')} } from '@rvoh/dream'${(0, uniq_js_1.default)(modelImportStatements).join('')}
80
80
 
81
- const deco = new Decorators<InstanceType<typeof ${modelClassName}>>()
81
+ const deco = new Decorators<typeof ${modelClassName}>()
82
82
 
83
83
  ${isSTI ? `\n@STI(${parentModelClassName})` : ''}
84
84
  export default class ${modelClassName} extends ${isSTI ? parentModelClassName : 'ApplicationModel'} {
@@ -89,7 +89,7 @@ ${isSTI
89
89
  }
90
90
 
91
91
  `}${serializer
92
- ? ` public get serializers(): DreamSerializers<${modelClassName}> {
92
+ ? ` public ${isSTI ? 'override ' : ''}get serializers(): DreamSerializers<${modelClassName}> {
93
93
  return {
94
94
  default: '${(0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName)}',
95
95
  summary: '${(0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName, 'summary')}',
@@ -32,13 +32,13 @@ function generateSerializerContent({ fullyQualifiedModelName, columnsWithTypes =
32
32
  Passthrough extends object,
33
33
  >`;
34
34
  dreamSerializerTypeArgs = `<DataType, Passthrough>`;
35
- const defaultSerialzerClassName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName));
36
- const summarySerialzerClassName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName, 'summary'));
35
+ const defaultSerialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName));
36
+ const summarySerialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName), 'summary');
37
37
  const defaultSerialzerExtends = isSTI
38
- ? (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedParentName))
38
+ ? (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedParentName))
39
39
  : summarySerialzerClassName;
40
40
  const summarySerialzerExtends = isSTI
41
- ? (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedParentName, 'summary'))
41
+ ? (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedParentName), 'summary')
42
42
  : 'DreamSerializer';
43
43
  const additionalModelImports = [];
44
44
  columnsWithTypes.forEach(attr => {
@@ -101,8 +101,16 @@ function attributeOptionsSpecifier(type, attr) {
101
101
  }
102
102
  }
103
103
  function importStatementForSerializer(originModelName, destinationModelName) {
104
- return `\nimport ${(0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(destinationModelName))}, { ${(0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(destinationModelName, 'summary'))} } from '${(0, relativeDreamPath_js_1.default)('serializers', 'serializers', originModelName, destinationModelName)}'`;
104
+ const defaultSerializer = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(destinationModelName)));
105
+ const summarySerializer = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(destinationModelName), 'summary'));
106
+ const importFrom = (0, relativeDreamPath_js_1.default)('serializers', 'serializers', originModelName, destinationModelName);
107
+ return `\nimport ${defaultSerializer}, { ${summarySerializer} } from '${importFrom}'`;
105
108
  }
106
109
  function importStatementForModel(originModelName, destinationModelName = originModelName) {
107
- return `\nimport ${(0, globalClassNameFromFullyQualifiedModelName_js_1.default)(destinationModelName)} from '${(0, relativeDreamPath_js_1.default)('serializers', 'models', originModelName, destinationModelName)}'`;
110
+ const modelName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)(destinationModelName);
111
+ const importFrom = (0, relativeDreamPath_js_1.default)('serializers', 'models', originModelName, destinationModelName);
112
+ return `\nimport ${modelName} from '${importFrom}'`;
113
+ }
114
+ function fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName) {
115
+ return fullyQualifiedModelName.split('/').pop() ?? '';
108
116
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const areEqual_js_1 = require("./areEqual.js");
5
+ function default_1(a, b) {
6
+ return !(0, areEqual_js_1.default)(a, b);
7
+ }
@@ -6,15 +6,14 @@ function uniq(arr, toKey = undefined) {
6
6
  return uniqWith(arr, toKey);
7
7
  return uniqWith(arr, a => String(a));
8
8
  }
9
- function dreamKey(dream) {
10
- return `${dream.constructor.globalName}:${dream.primaryKeyValue}`;
11
- }
12
9
  function uniqWith(arr, toKey) {
13
10
  const map = arr.reduce((acc, val) => {
14
11
  // Prefix with underscore to ensure that the values cannot be interpreted as integers.
15
12
  // If they can be interpreted as integers, then the keys are ordered not by the
16
13
  // order in which they were added, but in ascending numerical order.
17
- const key = val?.isDreamInstance ? dreamKey(val) : `_${toKey(val)}`;
14
+ const key = val?.isDreamInstance
15
+ ? val.comparisonKey
16
+ : `_${toKey(val)}`;
18
17
  acc[key] ||= val;
19
18
  return acc;
20
19
  }, {});
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = exports.dreamPath = exports.pascalize = exports.loadRepl = exports.isEmpty = exports.inferSerializerFromDreamOrViewModel = exports.inferSerializerFromDreamClassOrViewModelClass = exports.hyphenize = exports.globalClassNameFromFullyQualifiedModelName = exports.Env = exports.DreamGlam = exports.debug = exports.DateTime = exports.compact = exports.generateDream = exports.capitalize = exports.camelize = exports.CalendarDate = exports.Benchmark = exports.ValidationError = exports.RecordNotFound = exports.GlobalNameNotSet = exports.CreateOrFindByFailedToCreateAndFind = exports.NonLoadedAssociation = exports.Encrypt = exports.Query = exports.DreamTransaction = exports.openapiShorthandPrimitiveTypes = exports.openapiPrimitiveTypes = exports.DreamConst = exports.Dream = exports.DreamApplication = exports.lookupClassByGlobalName = exports.DreamImporter = exports.Decorators = exports.STI = exports.SoftDelete = exports.ReplicaSafe = exports.validateTable = exports.validateColumn = exports.DreamMigrationHelpers = exports.untypedDb = exports.pgErrorType = exports.dreamDbConnections = exports.closeAllDbConnections = exports.DreamCLI = exports.DreamBin = void 0;
3
+ exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = exports.dreamPath = exports.pascalize = exports.loadRepl = exports.isEmpty = exports.inferSerializerFromDreamOrViewModel = exports.inferSerializerFromDreamClassOrViewModelClass = exports.hyphenize = exports.globalClassNameFromFullyQualifiedModelName = exports.Env = exports.DreamLogos = exports.debug = exports.DateTime = exports.compact = exports.generateDream = exports.capitalize = exports.camelize = exports.CalendarDate = exports.Benchmark = exports.ValidationError = exports.RecordNotFound = exports.GlobalNameNotSet = exports.CreateOrFindByFailedToCreateAndFind = exports.NonLoadedAssociation = exports.Encrypt = exports.Query = exports.DreamTransaction = exports.openapiShorthandPrimitiveTypes = exports.openapiPrimitiveTypes = exports.DreamConst = exports.Dream = exports.DreamApplication = exports.lookupClassByGlobalName = exports.DreamImporter = exports.Decorators = exports.STI = exports.SoftDelete = exports.ReplicaSafe = exports.validateTable = exports.validateColumn = exports.DreamMigrationHelpers = exports.untypedDb = exports.pgErrorType = exports.dreamDbConnections = exports.closeAllDbConnections = exports.DreamCLI = exports.DreamBin = void 0;
4
4
  exports.DreamSerializer = exports.Attribute = exports.RendersOne = exports.RendersMany = exports.ops = exports.uniq = exports.uncapitalize = exports.standardizeFullyQualifiedModelName = exports.sortBy = exports.sort = exports.snakeify = exports.serializerNameFromFullyQualifiedModelName = exports.round = void 0;
5
5
  var index_js_1 = require("./bin/index.js");
6
6
  Object.defineProperty(exports, "DreamBin", { enumerable: true, get: function () { return index_js_1.default; } });
@@ -71,8 +71,8 @@ var DateTime_js_1 = require("./helpers/DateTime.js");
71
71
  Object.defineProperty(exports, "DateTime", { enumerable: true, get: function () { return DateTime_js_1.DateTime; } });
72
72
  var debug_js_1 = require("./helpers/debug.js");
73
73
  Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_js_1.default; } });
74
- var DreamGlam_js_1 = require("./helpers/DreamGlam/DreamGlam.js");
75
- Object.defineProperty(exports, "DreamGlam", { enumerable: true, get: function () { return DreamGlam_js_1.default; } });
74
+ var DreamLogos_js_1 = require("./helpers/DreamLogos/DreamLogos.js");
75
+ Object.defineProperty(exports, "DreamLogos", { enumerable: true, get: function () { return DreamLogos_js_1.default; } });
76
76
  var Env_js_1 = require("./helpers/Env.js");
77
77
  Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return Env_js_1.default; } });
78
78
  var globalClassNameFromFullyQualifiedModelName_js_1 = require("./helpers/globalClassNameFromFullyQualifiedModelName.js");