@rvoh/dream 2.33.0 → 2.35.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 (218) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/src/Dream.js +14 -3
  3. package/dist/cjs/src/decorators/Decorators.js +20 -0
  4. package/dist/cjs/src/decorators/field/lifecycle/AfterCreateCommit.js +4 -0
  5. package/dist/cjs/src/decorators/field/lifecycle/AfterDestroyCommit.js +4 -0
  6. package/dist/cjs/src/decorators/field/lifecycle/AfterSaveCommit.js +4 -0
  7. package/dist/cjs/src/decorators/field/lifecycle/AfterUpdateCommit.js +4 -0
  8. package/dist/cjs/src/dream/DreamTransaction.js +14 -3
  9. package/dist/cjs/src/dream/QueryDriver/Kysely.js +1 -1
  10. package/dist/cjs/src/dream/internal/runHooksFor.js +16 -5
  11. package/dist/cjs/src/dream/internal/withConcurrentWriterRetry.js +6 -1
  12. package/dist/esm/src/Dream.js +14 -3
  13. package/dist/esm/src/decorators/Decorators.js +20 -0
  14. package/dist/esm/src/decorators/field/lifecycle/AfterCreateCommit.js +4 -0
  15. package/dist/esm/src/decorators/field/lifecycle/AfterDestroyCommit.js +4 -0
  16. package/dist/esm/src/decorators/field/lifecycle/AfterSaveCommit.js +4 -0
  17. package/dist/esm/src/decorators/field/lifecycle/AfterUpdateCommit.js +4 -0
  18. package/dist/esm/src/dream/DreamTransaction.js +14 -3
  19. package/dist/esm/src/dream/QueryDriver/Kysely.js +1 -1
  20. package/dist/esm/src/dream/internal/runHooksFor.js +16 -5
  21. package/dist/esm/src/dream/internal/withConcurrentWriterRetry.js +6 -1
  22. package/dist/types/src/Dream.d.ts +13 -2
  23. package/dist/types/src/decorators/Decorators.d.ts +24 -4
  24. package/dist/types/src/decorators/field/lifecycle/AfterCreateCommit.d.ts +6 -2
  25. package/dist/types/src/decorators/field/lifecycle/AfterDestroyCommit.d.ts +6 -1
  26. package/dist/types/src/decorators/field/lifecycle/AfterSaveCommit.d.ts +6 -2
  27. package/dist/types/src/decorators/field/lifecycle/AfterUpdateCommit.d.ts +6 -2
  28. package/dist/types/src/dream/DreamTransaction.d.ts +8 -1
  29. package/dist/types/src/dream/internal/runHooksFor.d.ts +5 -0
  30. package/dist/types/src/dream/internal/withConcurrentWriterRetry.d.ts +2 -1
  31. package/dist/types/src/types/lifecycle.d.ts +29 -0
  32. package/dist/types/src/types/types/lifecycle.ts +46 -0
  33. package/docs/classes/db.DreamMigrationHelpers.html +11 -11
  34. package/docs/classes/db.KyselyQueryDriver.html +46 -46
  35. package/docs/classes/db.PostgresQueryDriver.html +47 -47
  36. package/docs/classes/db.QueryDriverBase.html +45 -45
  37. package/docs/classes/errors.CannotSaveMissingDream.html +5 -5
  38. package/docs/classes/errors.CheckConstraintViolation.html +5 -5
  39. package/docs/classes/errors.ColumnOverflow.html +5 -5
  40. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +5 -5
  41. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +5 -5
  42. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +5 -5
  43. package/docs/classes/errors.DecryptionError.html +4 -4
  44. package/docs/classes/errors.DecryptionParseError.html +4 -4
  45. package/docs/classes/errors.DecryptionRotationError.html +5 -5
  46. package/docs/classes/errors.GlobalNameNotSet.html +5 -5
  47. package/docs/classes/errors.InvalidCalendarDate.html +5 -5
  48. package/docs/classes/errors.InvalidClockTime.html +5 -5
  49. package/docs/classes/errors.InvalidClockTimeTz.html +5 -5
  50. package/docs/classes/errors.InvalidDateTime.html +5 -5
  51. package/docs/classes/errors.MissingSerializersDefinition.html +5 -5
  52. package/docs/classes/errors.NonLoadedAssociation.html +5 -5
  53. package/docs/classes/errors.NotNullViolation.html +5 -5
  54. package/docs/classes/errors.RecordNotFound.html +5 -5
  55. package/docs/classes/errors.SortableScopeDidNotStabilize.html +5 -5
  56. package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +5 -5
  57. package/docs/classes/errors.ValidationError.html +5 -5
  58. package/docs/classes/index.CalendarDate.html +33 -33
  59. package/docs/classes/index.ClockTime.html +32 -32
  60. package/docs/classes/index.ClockTimeTz.html +35 -35
  61. package/docs/classes/index.DateTime.html +86 -86
  62. package/docs/classes/index.Decorators.html +39 -23
  63. package/docs/classes/index.Dream.html +134 -126
  64. package/docs/classes/index.DreamApp.html +10 -10
  65. package/docs/classes/index.DreamTransaction.html +6 -2
  66. package/docs/classes/index.Env.html +2 -2
  67. package/docs/classes/index.Query.html +65 -65
  68. package/docs/classes/system.CliFileWriter.html +4 -4
  69. package/docs/classes/system.DreamBin.html +2 -2
  70. package/docs/classes/system.DreamCLI.html +7 -7
  71. package/docs/classes/system.DreamImporter.html +2 -2
  72. package/docs/classes/system.DreamLogos.html +2 -2
  73. package/docs/classes/system.DreamSerializerBuilder.html +11 -11
  74. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  75. package/docs/classes/system.PathHelpers.html +3 -3
  76. package/docs/classes/utils.Encrypt.html +3 -3
  77. package/docs/classes/utils.Range.html +2 -2
  78. package/docs/functions/db.closeAllDbConnections.html +1 -1
  79. package/docs/functions/db.dreamDbConnections.html +1 -1
  80. package/docs/functions/db.untypedDb.html +1 -1
  81. package/docs/functions/db.validateColumn.html +1 -1
  82. package/docs/functions/db.validateTable.html +1 -1
  83. package/docs/functions/errors.pgErrorType.html +1 -1
  84. package/docs/functions/index.DreamSerializer.html +1 -1
  85. package/docs/functions/index.ObjectSerializer.html +1 -1
  86. package/docs/functions/index.ReplicaSafe.html +1 -1
  87. package/docs/functions/index.STI.html +1 -1
  88. package/docs/functions/index.SoftDelete.html +1 -1
  89. package/docs/functions/utils.camelize.html +1 -1
  90. package/docs/functions/utils.capitalize.html +1 -1
  91. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  92. package/docs/functions/utils.compact.html +1 -1
  93. package/docs/functions/utils.groupBy.html +1 -1
  94. package/docs/functions/utils.hyphenize.html +1 -1
  95. package/docs/functions/utils.intersection.html +1 -1
  96. package/docs/functions/utils.isEmpty.html +3 -3
  97. package/docs/functions/utils.normalizeUnicode.html +1 -1
  98. package/docs/functions/utils.pascalize.html +1 -1
  99. package/docs/functions/utils.percent.html +1 -1
  100. package/docs/functions/utils.range.html +1 -1
  101. package/docs/functions/utils.round.html +1 -1
  102. package/docs/functions/utils.sanitizeString.html +1 -1
  103. package/docs/functions/utils.snakeify.html +1 -1
  104. package/docs/functions/utils.sort.html +1 -1
  105. package/docs/functions/utils.sortBy.html +1 -1
  106. package/docs/functions/utils.sortObjectByKey.html +1 -1
  107. package/docs/functions/utils.sortObjectByValue.html +1 -1
  108. package/docs/functions/utils.uncapitalize.html +1 -1
  109. package/docs/functions/utils.uniq.html +1 -1
  110. package/docs/index.html +1 -1
  111. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  112. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  113. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  114. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  115. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  116. package/docs/interfaces/types.DecoratorContext.html +2 -2
  117. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  118. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  119. package/docs/interfaces/types.DreamDbConfig.html +6 -6
  120. package/docs/interfaces/types.DurationObject.html +2 -2
  121. package/docs/interfaces/types.EncryptOptions.html +2 -2
  122. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  123. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  124. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  125. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  126. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  127. package/docs/types/openapi.OpenapiFormats.html +1 -1
  128. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  129. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  130. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  131. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  132. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  133. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  134. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  135. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  136. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  137. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  138. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  139. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  140. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  141. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  142. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  143. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  144. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  145. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  146. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  147. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  148. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  149. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  150. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  151. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  152. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  153. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  154. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  155. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  156. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  157. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  158. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  159. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  160. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  161. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  162. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  163. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  164. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  165. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  166. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  167. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  168. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  169. package/docs/types/types.CalendarDateObject.html +1 -1
  170. package/docs/types/types.Camelized.html +1 -1
  171. package/docs/types/types.ClockTimeObject.html +1 -1
  172. package/docs/types/types.DbConnectionType.html +1 -1
  173. package/docs/types/types.DbTypes.html +1 -1
  174. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  175. package/docs/types/types.DreamAttributes.html +1 -1
  176. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  177. package/docs/types/types.DreamClassColumn.html +1 -1
  178. package/docs/types/types.DreamColumn.html +1 -1
  179. package/docs/types/types.DreamColumnNames.html +1 -1
  180. package/docs/types/types.DreamLogLevel.html +1 -1
  181. package/docs/types/types.DreamLogger.html +2 -2
  182. package/docs/types/types.DreamModelSerializerType.html +1 -1
  183. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  184. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  185. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  186. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  187. package/docs/types/types.DreamSerializable.html +1 -1
  188. package/docs/types/types.DreamSerializableArray.html +1 -1
  189. package/docs/types/types.DreamSerializerKey.html +1 -1
  190. package/docs/types/types.DreamSerializers.html +1 -1
  191. package/docs/types/types.DreamVirtualColumns.html +1 -1
  192. package/docs/types/types.DurationUnit.html +1 -1
  193. package/docs/types/types.EncryptAlgorithm.html +1 -1
  194. package/docs/types/types.HasManyStatement.html +1 -1
  195. package/docs/types/types.HasOneStatement.html +1 -1
  196. package/docs/types/types.Hyphenized.html +1 -1
  197. package/docs/types/types.Pascalized.html +1 -1
  198. package/docs/types/types.PrimaryKeyType.html +1 -1
  199. package/docs/types/types.RoundingPrecision.html +1 -1
  200. package/docs/types/types.SerializerCasing.html +1 -1
  201. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  202. package/docs/types/types.Snakeified.html +1 -1
  203. package/docs/types/types.StrictInterface.html +1 -1
  204. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  205. package/docs/types/types.UpdateableProperties.html +1 -1
  206. package/docs/types/types.ValidationType.html +1 -1
  207. package/docs/types/types.ViewModel.html +2 -2
  208. package/docs/types/types.ViewModelClass.html +1 -1
  209. package/docs/types/types.WeekdayName.html +1 -1
  210. package/docs/types/types.WhereStatementForDream.html +1 -1
  211. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  212. package/docs/variables/index.DreamConst.html +1 -1
  213. package/docs/variables/index.ops.html +1 -1
  214. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  215. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  216. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  217. package/docs/variables/system.primaryKeyTypes.html +1 -1
  218. package/package.json +5 -2
@@ -399,9 +399,14 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
399
399
  * }
400
400
  * ```
401
401
  *
402
+ * The decorated method is called with no argument, once the
403
+ * transaction has committed, so declaring a parameter on it is a
404
+ * compile error. A subclass override of the method that is not itself
405
+ * decorated is not checked; it is still called with no argument.
406
+ *
402
407
  * @returns The AfterCreateCommit decorator
403
408
  */
404
- AfterCreateCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): any;
409
+ AfterCreateCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): import("../types/lifecycle.js").CommitHookDecorator;
405
410
  /**
406
411
  * AfterSave decorator
407
412
  *
@@ -430,10 +435,15 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
430
435
  * }
431
436
  * ```
432
437
  *
438
+ * The decorated method is called with no argument, once the
439
+ * transaction has committed, so declaring a parameter on it is a
440
+ * compile error. A subclass override of the method that is not itself
441
+ * decorated is not checked; it is still called with no argument.
442
+ *
433
443
  * @returns The AfterSaveCommit decorator
434
444
  *
435
445
  */
436
- AfterSaveCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): any;
446
+ AfterSaveCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): import("../types/lifecycle.js").CommitHookDecorator;
437
447
  /**
438
448
  * AfterUpdate decorator
439
449
  *
@@ -462,10 +472,15 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
462
472
  * }
463
473
  * ```
464
474
  *
475
+ * The decorated method is called with no argument, once the
476
+ * transaction has committed, so declaring a parameter on it is a
477
+ * compile error. A subclass override of the method that is not itself
478
+ * decorated is not checked; it is still called with no argument.
479
+ *
465
480
  * @returns The AfterUpdateCommit decorator
466
481
  *
467
482
  */
468
- AfterUpdateCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): any;
483
+ AfterUpdateCommit(this: Decorators<TD>, opts?: AfterHookOpts<T>): import("../types/lifecycle.js").CommitHookDecorator;
469
484
  /**
470
485
  * AfterDestroy decorator
471
486
  *
@@ -494,8 +509,13 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
494
509
  * }
495
510
  * ```
496
511
  *
512
+ * The decorated method is called with no argument, once the
513
+ * transaction has committed, so declaring a parameter on it is a
514
+ * compile error. A subclass override of the method that is not itself
515
+ * decorated is not checked; it is still called with no argument.
516
+ *
497
517
  * @returns The AfterDestroyCommit decorator
498
518
  *
499
519
  */
500
- AfterDestroyCommit(this: Decorators<TD>): any;
520
+ AfterDestroyCommit(this: Decorators<TD>): import("../types/lifecycle.js").CommitHookDecorator;
501
521
  }
@@ -1,5 +1,5 @@
1
1
  import Dream from '../../../Dream.js';
2
- import { AfterHookOpts } from '../../../types/lifecycle.js';
2
+ import { AfterHookOpts, CommitHookDecorator } from '../../../types/lifecycle.js';
3
3
  /**
4
4
  * Calls the decorated method whenever a dream has finished
5
5
  * being created. If the save takes place within a transaction,
@@ -8,6 +8,10 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
8
8
  * a transaction, the method will be run after the save
9
9
  * is complete.
10
10
  *
11
+ * The method is called with no argument: the transaction has already
12
+ * committed, so there is none to hand it. Decorating a method that
13
+ * declares a parameter is a compile error (see {@link CommitHookDecorator}).
14
+ *
11
15
  * class User extends ApplicationModel {
12
16
  * @deco.AfterCreateCommit()
13
17
  * public doSomething() {
@@ -17,5 +21,5 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
17
21
  *
18
22
  * @param opts.ifChanged - Optional. A list of columns which should must change in order for this function to be called.
19
23
  */
20
- export default function AfterCreateCommit<T extends Dream>(opts?: AfterHookOpts<T>): any;
24
+ export default function AfterCreateCommit<T extends Dream>(opts?: AfterHookOpts<T>): CommitHookDecorator;
21
25
  export declare function afterCreateCommitImplementation<T extends Dream>(target: T, key: string, opts?: AfterHookOpts<T>): void;
@@ -1,4 +1,5 @@
1
1
  import Dream from '../../../Dream.js';
2
+ import { CommitHookDecorator } from '../../../types/lifecycle.js';
2
3
  /**
3
4
  * Calls the decorated method whenever a dream has finished
4
5
  * being destroyed. If the destroy takes place within a transaction,
@@ -7,6 +8,10 @@ import Dream from '../../../Dream.js';
7
8
  * a transaction, the method will be run after the save
8
9
  * is complete.
9
10
  *
11
+ * The method is called with no argument: the transaction has already
12
+ * committed, so there is none to hand it. Decorating a method that
13
+ * declares a parameter is a compile error (see {@link CommitHookDecorator}).
14
+ *
10
15
  * class User extends ApplicationModel {
11
16
  * @deco.AfterDestroyCommit()
12
17
  * public doSomething() {
@@ -14,5 +19,5 @@ import Dream from '../../../Dream.js';
14
19
  * }
15
20
  * }
16
21
  */
17
- export default function AfterDestroyCommit(): any;
22
+ export default function AfterDestroyCommit(): CommitHookDecorator;
18
23
  export declare function afterDestroyCommitImplementation<T extends Dream>(target: T, key: string): void;
@@ -1,5 +1,5 @@
1
1
  import Dream from '../../../Dream.js';
2
- import { AfterHookOpts } from '../../../types/lifecycle.js';
2
+ import { AfterHookOpts, CommitHookDecorator } from '../../../types/lifecycle.js';
3
3
  /**
4
4
  * Calls the decorated method whenever a dream has finished
5
5
  * being saved. If the save takes place within a transaction,
@@ -8,6 +8,10 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
8
8
  * a transaction, the method will be run after the save
9
9
  * is complete.
10
10
  *
11
+ * The method is called with no argument: the transaction has already
12
+ * committed, so there is none to hand it. Decorating a method that
13
+ * declares a parameter is a compile error (see {@link CommitHookDecorator}).
14
+ *
11
15
  * class User extends ApplicationModel {
12
16
  * @deco.AfterSaveCommit()
13
17
  * public doSomething() {
@@ -17,5 +21,5 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
17
21
  *
18
22
  * @param opts.ifChanged - Optional. A list of columns which should must change in order for this function to be called.
19
23
  */
20
- export default function AfterSaveCommit<T extends Dream>(opts?: AfterHookOpts<T>): any;
24
+ export default function AfterSaveCommit<T extends Dream>(opts?: AfterHookOpts<T>): CommitHookDecorator;
21
25
  export declare function afterSaveCommitImplementation<T extends Dream>(target: T, key: string, opts?: AfterHookOpts<T>): void;
@@ -1,5 +1,5 @@
1
1
  import Dream from '../../../Dream.js';
2
- import { AfterHookOpts } from '../../../types/lifecycle.js';
2
+ import { AfterHookOpts, CommitHookDecorator } from '../../../types/lifecycle.js';
3
3
  /**
4
4
  * Calls the decorated method whenever a dream has finished
5
5
  * being updated. If the save takes place within a transaction,
@@ -8,6 +8,10 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
8
8
  * a transaction, the method will be run after the save
9
9
  * is complete.
10
10
  *
11
+ * The method is called with no argument: the transaction has already
12
+ * committed, so there is none to hand it. Decorating a method that
13
+ * declares a parameter is a compile error (see {@link CommitHookDecorator}).
14
+ *
11
15
  * class User extends ApplicationModel {
12
16
  * @deco.AfterUpdateCommit()
13
17
  * public doSomething() {
@@ -17,5 +21,5 @@ import { AfterHookOpts } from '../../../types/lifecycle.js';
17
21
  *
18
22
  * @param opts.ifChanged - Optional. A list of columns which should must change in order for this function to be called.
19
23
  */
20
- export default function AfterUpdateCommit<T extends Dream>(opts?: AfterHookOpts<T>): any;
24
+ export default function AfterUpdateCommit<T extends Dream>(opts?: AfterHookOpts<T>): CommitHookDecorator;
21
25
  export declare function afterUpdateCommitImplementation<T extends Dream>(target: T, key: string, opts?: AfterHookOpts<T>): void;
@@ -8,8 +8,15 @@ export interface TransactionCommitHookStatement {
8
8
  export default class DreamTransaction<T extends Dream, DB extends T['DB'] = T['DB']> {
9
9
  private _kyselyTransaction;
10
10
  private commitHooks;
11
+ private committed;
11
12
  get kyselyTransaction(): Transaction<DB>;
12
13
  set kyselyTransaction(txn: Transaction<DB>);
13
14
  addCommitHook(hookStatement: HookStatement, dreamInstance: Dream): void;
14
- runAfterCommitHooks(txn: DreamTransaction<any>): Promise<void>;
15
+ /**
16
+ * Runs the commit hooks queued during the transaction, in the order they
17
+ * were queued. A query driver calls this once the transaction has
18
+ * committed. Each hook is called with no argument, since the transaction
19
+ * it would otherwise receive can no longer run queries.
20
+ */
21
+ runAfterCommitHooks(): Promise<void>;
15
22
  }
@@ -6,3 +6,8 @@ export default function runHooksFor<T extends Dream>(key: HookType, dream: T, al
6
6
  now: any;
7
7
  }>> | null, txn: DreamTransaction<any> | null): Promise<void>;
8
8
  export declare function runHook<T extends Dream>(statement: HookStatement, dream: T, txn: DreamTransaction<any> | null): Promise<void>;
9
+ /**
10
+ * Commit hooks run after the transaction has committed, so they are called
11
+ * with no argument.
12
+ */
13
+ export declare function runCommitHook<T extends Dream>(statement: HookStatement, dream: T): Promise<void>;
@@ -23,7 +23,8 @@ export declare const MAX_CONCURRENT_WRITER_ATTEMPTS = 3;
23
23
  * rows mid-statement as well. Either way the database has undone the whole
24
24
  * transaction, nothing has committed and no commit hook has run, so running
25
25
  * the operation again reads the rows as the other writer left them. The last
26
- * attempt's error is the adapter's own.
26
+ * attempt's error is the adapter's own. An error raised after COMMIT, such as a
27
+ * commit hook's, is never retried.
27
28
  *
28
29
  * A unique violation raised by a statement inside the callback is not a
29
30
  * collision but a write that violates a constraint outright, and is not
@@ -2,6 +2,35 @@ import Dream from '../Dream.js';
2
2
  import { DreamColumnNames } from './dream.js';
3
3
  export type HookType = 'beforeCreate' | 'beforeSave' | 'beforeUpdate' | 'beforeDestroy' | 'afterCreate' | 'afterSave' | 'afterUpdate' | 'afterDestroy' | CommitHookType;
4
4
  export type CommitHookType = 'afterCreateCommit' | 'afterSaveCommit' | 'afterUpdateCommit' | 'afterDestroyCommit';
5
+ /**
6
+ * The decorator returned by `deco.AfterCreateCommit()`,
7
+ * `deco.AfterSaveCommit()`, `deco.AfterUpdateCommit()` and
8
+ * `deco.AfterDestroyCommit()`.
9
+ *
10
+ * Dream calls every commit hook with no argument: by the time it runs, the
11
+ * transaction has already committed, so there is no transaction to hand it.
12
+ * Decorating an instance method that declares a parameter — required,
13
+ * optional, defaulted or rest — is therefore a compile error.
14
+ *
15
+ * Other placements of the decorator (an arrow-function field, an `accessor`
16
+ * field, a getter, a static method) are not checked.
17
+ *
18
+ * A subclass that overrides a decorated commit hook without decorating the
19
+ * override is not checked either, so `override hook(txn?: ...)` compiles; at
20
+ * runtime the override is still called with no argument.
21
+ */
22
+ export interface CommitHookDecorator {
23
+ <This, Method extends (...args: any[]) => unknown>(value: This extends abstract new (...args: any[]) => unknown ? Method : CommitHookMethod<Method>, context: ClassMethodDecoratorContext<This, Method>): void;
24
+ (value: any, context: ClassFieldDecoratorContext<any, any> | ClassGetterDecoratorContext<any, any> | ClassSetterDecoratorContext<any, any> | ClassAccessorDecoratorContext<any, any> | ClassDecoratorContext<any>): void;
25
+ }
26
+ /**
27
+ * A method a commit-hook decorator accepts: one that declares no parameter.
28
+ * Any other method resolves to a message naming the problem, which the
29
+ * decorated method is not assignable to. The parameter tuple is compared
30
+ * whole, so a rest parameter typed as a union such as `[] | [X]` is rejected
31
+ * too.
32
+ */
33
+ export type CommitHookMethod<Method> = Method extends (...args: infer Params) => unknown ? [Params] extends [[]] ? Method : 'a commit hook is called with no argument: remove its parameters' : never;
5
34
  export interface HookStatement {
6
35
  type: HookType;
7
36
  className: string;
@@ -18,6 +18,52 @@ export type CommitHookType =
18
18
  | 'afterUpdateCommit'
19
19
  | 'afterDestroyCommit'
20
20
 
21
+ /**
22
+ * The decorator returned by `deco.AfterCreateCommit()`,
23
+ * `deco.AfterSaveCommit()`, `deco.AfterUpdateCommit()` and
24
+ * `deco.AfterDestroyCommit()`.
25
+ *
26
+ * Dream calls every commit hook with no argument: by the time it runs, the
27
+ * transaction has already committed, so there is no transaction to hand it.
28
+ * Decorating an instance method that declares a parameter — required,
29
+ * optional, defaulted or rest — is therefore a compile error.
30
+ *
31
+ * Other placements of the decorator (an arrow-function field, an `accessor`
32
+ * field, a getter, a static method) are not checked.
33
+ *
34
+ * A subclass that overrides a decorated commit hook without decorating the
35
+ * override is not checked either, so `override hook(txn?: ...)` compiles; at
36
+ * runtime the override is still called with no argument.
37
+ */
38
+ export interface CommitHookDecorator {
39
+ <This, Method extends (...args: any[]) => unknown>(
40
+ value: This extends abstract new (...args: any[]) => unknown ? Method : CommitHookMethod<Method>,
41
+ context: ClassMethodDecoratorContext<This, Method>
42
+ ): void
43
+ (
44
+ value: any,
45
+ context:
46
+ | ClassFieldDecoratorContext<any, any>
47
+ | ClassGetterDecoratorContext<any, any>
48
+ | ClassSetterDecoratorContext<any, any>
49
+ | ClassAccessorDecoratorContext<any, any>
50
+ | ClassDecoratorContext<any>
51
+ ): void
52
+ }
53
+
54
+ /**
55
+ * A method a commit-hook decorator accepts: one that declares no parameter.
56
+ * Any other method resolves to a message naming the problem, which the
57
+ * decorated method is not assignable to. The parameter tuple is compared
58
+ * whole, so a rest parameter typed as a union such as `[] | [X]` is rejected
59
+ * too.
60
+ */
61
+ export type CommitHookMethod<Method> = Method extends (...args: infer Params) => unknown
62
+ ? [Params] extends [[]]
63
+ ? Method
64
+ : 'a commit hook is called with no argument: remove its parameters'
65
+ : never
66
+
21
67
  export interface HookStatement {
22
68
  type: HookType
23
69
  className: string