@cratis/chronicle 3.0.0 → 3.1.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 (319) hide show
  1. package/EventStore.ts +17 -1
  2. package/IEventStore.ts +16 -0
  3. package/auditing/CausationType.ts +10 -0
  4. package/compliance/ComplianceContracts.ts +84 -0
  5. package/compliance/IPIIManager.ts +17 -0
  6. package/compliance/PIIManager.ts +31 -0
  7. package/compliance/index.ts +2 -0
  8. package/connection/ChronicleConnection.ts +7 -1
  9. package/connection/ChronicleServices.ts +2 -0
  10. package/connection/Guid.ts +18 -0
  11. package/dist/EventStore.d.ts +8 -0
  12. package/dist/EventStore.d.ts.map +1 -1
  13. package/dist/EventStore.js +13 -1
  14. package/dist/EventStore.js.map +1 -1
  15. package/dist/IEventStore.d.ts +12 -0
  16. package/dist/IEventStore.d.ts.map +1 -1
  17. package/dist/auditing/CausationType.d.ts +8 -0
  18. package/dist/auditing/CausationType.d.ts.map +1 -1
  19. package/dist/auditing/CausationType.js +8 -0
  20. package/dist/auditing/CausationType.js.map +1 -1
  21. package/dist/compliance/ComplianceContracts.d.ts +40 -0
  22. package/dist/compliance/ComplianceContracts.d.ts.map +1 -1
  23. package/dist/compliance/ComplianceContracts.js +71 -0
  24. package/dist/compliance/ComplianceContracts.js.map +1 -1
  25. package/dist/compliance/IPIIManager.d.ts +15 -0
  26. package/dist/compliance/IPIIManager.d.ts.map +1 -0
  27. package/dist/compliance/IPIIManager.js +4 -0
  28. package/dist/compliance/IPIIManager.js.map +1 -0
  29. package/dist/compliance/PIIManager.d.ts +20 -0
  30. package/dist/compliance/PIIManager.d.ts.map +1 -0
  31. package/dist/compliance/PIIManager.js +30 -0
  32. package/dist/compliance/PIIManager.js.map +1 -0
  33. package/dist/compliance/index.d.ts +2 -0
  34. package/dist/compliance/index.d.ts.map +1 -1
  35. package/dist/compliance/index.js +1 -0
  36. package/dist/compliance/index.js.map +1 -1
  37. package/dist/connection/ChronicleConnection.d.ts +1 -0
  38. package/dist/connection/ChronicleConnection.d.ts.map +1 -1
  39. package/dist/connection/ChronicleConnection.js +6 -1
  40. package/dist/connection/ChronicleConnection.js.map +1 -1
  41. package/dist/connection/ChronicleServices.d.ts +2 -0
  42. package/dist/connection/ChronicleServices.d.ts.map +1 -1
  43. package/dist/connection/Guid.d.ts +5 -0
  44. package/dist/connection/Guid.d.ts.map +1 -1
  45. package/dist/connection/Guid.js +15 -0
  46. package/dist/connection/Guid.js.map +1 -1
  47. package/dist/eventSequences/AppendOperationsBroadcaster.d.ts +16 -0
  48. package/dist/eventSequences/AppendOperationsBroadcaster.d.ts.map +1 -0
  49. package/dist/eventSequences/AppendOperationsBroadcaster.js +77 -0
  50. package/dist/eventSequences/AppendOperationsBroadcaster.js.map +1 -0
  51. package/dist/eventSequences/AppendOptions.d.ts +7 -0
  52. package/dist/eventSequences/AppendOptions.d.ts.map +1 -1
  53. package/dist/eventSequences/AppendResult.d.ts +14 -0
  54. package/dist/eventSequences/AppendResult.d.ts.map +1 -1
  55. package/dist/eventSequences/AppendedEventWithResult.d.ts +13 -0
  56. package/dist/eventSequences/AppendedEventWithResult.d.ts.map +1 -0
  57. package/dist/eventSequences/AppendedEventWithResult.js +4 -0
  58. package/dist/eventSequences/AppendedEventWithResult.js.map +1 -0
  59. package/dist/eventSequences/CompleteStreamError.d.ts +17 -0
  60. package/dist/eventSequences/CompleteStreamError.d.ts.map +1 -0
  61. package/dist/eventSequences/CompleteStreamError.js +20 -0
  62. package/dist/eventSequences/CompleteStreamError.js.map +1 -0
  63. package/dist/eventSequences/CompleteStreamResult.d.ts +14 -0
  64. package/dist/eventSequences/CompleteStreamResult.d.ts.map +1 -0
  65. package/dist/eventSequences/CompleteStreamResult.js +4 -0
  66. package/dist/eventSequences/CompleteStreamResult.js.map +1 -0
  67. package/dist/eventSequences/ConcurrencyViolation.d.ts +13 -0
  68. package/dist/eventSequences/ConcurrencyViolation.d.ts.map +1 -0
  69. package/dist/eventSequences/ConcurrencyViolation.js +4 -0
  70. package/dist/eventSequences/ConcurrencyViolation.js.map +1 -0
  71. package/dist/eventSequences/EventForEventSourceId.d.ts +8 -0
  72. package/dist/eventSequences/EventForEventSourceId.d.ts.map +1 -1
  73. package/dist/eventSequences/EventSequence.d.ts +35 -1
  74. package/dist/eventSequences/EventSequence.d.ts.map +1 -1
  75. package/dist/eventSequences/EventSequence.js +350 -19
  76. package/dist/eventSequences/EventSequence.js.map +1 -1
  77. package/dist/eventSequences/IEventSequence.d.ts +85 -1
  78. package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
  79. package/dist/eventSequences/WaitForCompletionResult.d.ts +11 -0
  80. package/dist/eventSequences/WaitForCompletionResult.d.ts.map +1 -0
  81. package/dist/eventSequences/WaitForCompletionResult.js +4 -0
  82. package/dist/eventSequences/WaitForCompletionResult.js.map +1 -0
  83. package/dist/eventSequences/index.d.ts +5 -0
  84. package/dist/eventSequences/index.d.ts.map +1 -1
  85. package/dist/eventSequences/index.js +1 -0
  86. package/dist/eventSequences/index.js.map +1 -1
  87. package/dist/eventStoreSubscriptions/EventStoreSubscriptions.d.ts +3 -0
  88. package/dist/eventStoreSubscriptions/EventStoreSubscriptions.d.ts.map +1 -1
  89. package/dist/eventStoreSubscriptions/EventStoreSubscriptions.js +9 -0
  90. package/dist/eventStoreSubscriptions/EventStoreSubscriptions.js.map +1 -1
  91. package/dist/eventStoreSubscriptions/IEventStoreSubscriptions.d.ts +6 -0
  92. package/dist/eventStoreSubscriptions/IEventStoreSubscriptions.d.ts.map +1 -1
  93. package/dist/eventStoreSubscriptions/contracts.d.ts +18 -0
  94. package/dist/eventStoreSubscriptions/contracts.d.ts.map +1 -1
  95. package/dist/eventStoreSubscriptions/contracts.js +106 -0
  96. package/dist/eventStoreSubscriptions/contracts.js.map +1 -1
  97. package/dist/events/constraints/Constraints.js +1 -1
  98. package/dist/events/constraints/Constraints.js.map +1 -1
  99. package/dist/externalServices/ExternalServiceBuilder.d.ts +42 -0
  100. package/dist/externalServices/ExternalServiceBuilder.d.ts.map +1 -0
  101. package/dist/externalServices/ExternalServiceBuilder.js +110 -0
  102. package/dist/externalServices/ExternalServiceBuilder.js.map +1 -0
  103. package/dist/externalServices/ExternalServices.d.ts +19 -0
  104. package/dist/externalServices/ExternalServices.d.ts.map +1 -0
  105. package/dist/externalServices/ExternalServices.js +30 -0
  106. package/dist/externalServices/ExternalServices.js.map +1 -0
  107. package/dist/externalServices/ExternalServicesContracts.d.ts +137 -0
  108. package/dist/externalServices/ExternalServicesContracts.d.ts.map +1 -0
  109. package/dist/externalServices/ExternalServicesContracts.js +654 -0
  110. package/dist/externalServices/ExternalServicesContracts.js.map +1 -0
  111. package/dist/externalServices/IExternalServiceBuilder.d.ts +67 -0
  112. package/dist/externalServices/IExternalServiceBuilder.d.ts.map +1 -0
  113. package/dist/externalServices/IExternalServiceBuilder.js +4 -0
  114. package/dist/externalServices/IExternalServiceBuilder.js.map +1 -0
  115. package/dist/externalServices/IExternalServices.d.ts +13 -0
  116. package/dist/externalServices/IExternalServices.d.ts.map +1 -0
  117. package/dist/externalServices/IExternalServices.js +4 -0
  118. package/dist/externalServices/IExternalServices.js.map +1 -0
  119. package/dist/externalServices/index.d.ts +5 -0
  120. package/dist/externalServices/index.d.ts.map +1 -0
  121. package/dist/externalServices/index.js +5 -0
  122. package/dist/externalServices/index.js.map +1 -0
  123. package/dist/identities/IIdentityManager.d.ts +17 -0
  124. package/dist/identities/IIdentityManager.d.ts.map +1 -0
  125. package/dist/identities/IIdentityManager.js +4 -0
  126. package/dist/identities/IIdentityManager.js.map +1 -0
  127. package/dist/identities/IdentityManager.d.ts +20 -0
  128. package/dist/identities/IdentityManager.d.ts.map +1 -0
  129. package/dist/identities/IdentityManager.js +31 -0
  130. package/dist/identities/IdentityManager.js.map +1 -0
  131. package/dist/identities/index.d.ts +3 -0
  132. package/dist/identities/index.d.ts.map +1 -0
  133. package/dist/identities/index.js +4 -0
  134. package/dist/identities/index.js.map +1 -0
  135. package/dist/index.d.ts +5 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +5 -1
  138. package/dist/index.js.map +1 -1
  139. package/dist/observation/FailedPartition.d.ts +15 -0
  140. package/dist/observation/FailedPartition.d.ts.map +1 -0
  141. package/dist/observation/FailedPartition.js +4 -0
  142. package/dist/observation/FailedPartition.js.map +1 -0
  143. package/dist/observation/FailedPartitionAttempt.d.ts +15 -0
  144. package/dist/observation/FailedPartitionAttempt.d.ts.map +1 -0
  145. package/dist/observation/FailedPartitionAttempt.js +4 -0
  146. package/dist/observation/FailedPartitionAttempt.js.map +1 -0
  147. package/dist/observation/FailedPartitions.d.ts +24 -0
  148. package/dist/observation/FailedPartitions.d.ts.map +1 -0
  149. package/dist/observation/FailedPartitions.js +39 -0
  150. package/dist/observation/FailedPartitions.js.map +1 -0
  151. package/dist/observation/ICanBeNotifiedWhenPartitionReplayed.d.ts +19 -0
  152. package/dist/observation/ICanBeNotifiedWhenPartitionReplayed.d.ts.map +1 -0
  153. package/dist/observation/ICanBeNotifiedWhenPartitionReplayed.js +4 -0
  154. package/dist/observation/ICanBeNotifiedWhenPartitionReplayed.js.map +1 -0
  155. package/dist/observation/ICanBeNotifiedWhenReplay.d.ts +17 -0
  156. package/dist/observation/ICanBeNotifiedWhenReplay.d.ts.map +1 -0
  157. package/dist/observation/ICanBeNotifiedWhenReplay.js +4 -0
  158. package/dist/observation/ICanBeNotifiedWhenReplay.js.map +1 -0
  159. package/dist/observation/IFailedPartitions.d.ts +18 -0
  160. package/dist/observation/IFailedPartitions.d.ts.map +1 -0
  161. package/dist/observation/IFailedPartitions.js +4 -0
  162. package/dist/observation/IFailedPartitions.js.map +1 -0
  163. package/dist/observation/index.d.ts +6 -0
  164. package/dist/observation/index.d.ts.map +1 -1
  165. package/dist/observation/index.js +1 -0
  166. package/dist/observation/index.js.map +1 -1
  167. package/dist/observation/notifyReplayLifecycle.d.ts +13 -0
  168. package/dist/observation/notifyReplayLifecycle.d.ts.map +1 -0
  169. package/dist/observation/notifyReplayLifecycle.js +54 -0
  170. package/dist/observation/notifyReplayLifecycle.js.map +1 -0
  171. package/dist/observation/toClientFailedPartition.d.ts +9 -0
  172. package/dist/observation/toClientFailedPartition.d.ts.map +1 -0
  173. package/dist/observation/toClientFailedPartition.js +23 -0
  174. package/dist/observation/toClientFailedPartition.js.map +1 -0
  175. package/dist/projections/Projections.d.ts +0 -4
  176. package/dist/projections/Projections.d.ts.map +1 -1
  177. package/dist/projections/Projections.js +25 -103
  178. package/dist/projections/Projections.js.map +1 -1
  179. package/dist/projections/declarative/AddBuilder.d.ts +17 -0
  180. package/dist/projections/declarative/AddBuilder.d.ts.map +1 -0
  181. package/dist/projections/declarative/AddBuilder.js +28 -0
  182. package/dist/projections/declarative/AddBuilder.js.map +1 -0
  183. package/dist/projections/declarative/AddChildBuilder.d.ts +56 -0
  184. package/dist/projections/declarative/AddChildBuilder.d.ts.map +1 -0
  185. package/dist/projections/declarative/AddChildBuilder.js +72 -0
  186. package/dist/projections/declarative/AddChildBuilder.js.map +1 -0
  187. package/dist/projections/declarative/ChildrenBuilder.d.ts +28 -0
  188. package/dist/projections/declarative/ChildrenBuilder.d.ts.map +1 -0
  189. package/dist/projections/declarative/ChildrenBuilder.js +72 -0
  190. package/dist/projections/declarative/ChildrenBuilder.js.map +1 -0
  191. package/dist/projections/declarative/CompositeKeyBuilder.d.ts +16 -0
  192. package/dist/projections/declarative/CompositeKeyBuilder.d.ts.map +1 -0
  193. package/dist/projections/declarative/CompositeKeyBuilder.js +29 -0
  194. package/dist/projections/declarative/CompositeKeyBuilder.js.map +1 -0
  195. package/dist/projections/declarative/FromBuilder.d.ts +8 -6
  196. package/dist/projections/declarative/FromBuilder.d.ts.map +1 -1
  197. package/dist/projections/declarative/FromBuilder.js +44 -14
  198. package/dist/projections/declarative/FromBuilder.js.map +1 -1
  199. package/dist/projections/declarative/ICompositeKeyBuilder.d.ts +5 -0
  200. package/dist/projections/declarative/ICompositeKeyBuilder.d.ts.map +1 -1
  201. package/dist/projections/declarative/JoinBuilder.d.ts +7 -5
  202. package/dist/projections/declarative/JoinBuilder.d.ts.map +1 -1
  203. package/dist/projections/declarative/JoinBuilder.js +50 -16
  204. package/dist/projections/declarative/JoinBuilder.js.map +1 -1
  205. package/dist/projections/declarative/NestedBuilder.d.ts +24 -0
  206. package/dist/projections/declarative/NestedBuilder.d.ts.map +1 -0
  207. package/dist/projections/declarative/NestedBuilder.js +60 -0
  208. package/dist/projections/declarative/NestedBuilder.js.map +1 -0
  209. package/dist/projections/declarative/ProjectionBuilderCore.d.ts +127 -0
  210. package/dist/projections/declarative/ProjectionBuilderCore.d.ts.map +1 -0
  211. package/dist/projections/declarative/ProjectionBuilderCore.js +180 -0
  212. package/dist/projections/declarative/ProjectionBuilderCore.js.map +1 -0
  213. package/dist/projections/declarative/ProjectionBuilderFor.d.ts +6 -32
  214. package/dist/projections/declarative/ProjectionBuilderFor.d.ts.map +1 -1
  215. package/dist/projections/declarative/ProjectionBuilderFor.js +24 -118
  216. package/dist/projections/declarative/ProjectionBuilderFor.js.map +1 -1
  217. package/dist/projections/declarative/SubtractBuilder.d.ts +17 -0
  218. package/dist/projections/declarative/SubtractBuilder.d.ts.map +1 -0
  219. package/dist/projections/declarative/SubtractBuilder.js +28 -0
  220. package/dist/projections/declarative/SubtractBuilder.js.map +1 -0
  221. package/dist/projections/declarative/index.d.ts +9 -0
  222. package/dist/projections/declarative/index.d.ts.map +1 -1
  223. package/dist/projections/declarative/index.js +8 -0
  224. package/dist/projections/declarative/index.js.map +1 -1
  225. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +90 -0
  226. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -0
  227. package/dist/projections/modelBound/childrenAndNestedBuilder.js +290 -0
  228. package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -0
  229. package/dist/reactors/ReactorSideEffects.d.ts +29 -0
  230. package/dist/reactors/ReactorSideEffects.d.ts.map +1 -0
  231. package/dist/reactors/ReactorSideEffects.js +70 -0
  232. package/dist/reactors/ReactorSideEffects.js.map +1 -0
  233. package/dist/reactors/Reactors.d.ts +4 -1
  234. package/dist/reactors/Reactors.d.ts.map +1 -1
  235. package/dist/reactors/Reactors.js +23 -4
  236. package/dist/reactors/Reactors.js.map +1 -1
  237. package/dist/reducers/Reducers.d.ts.map +1 -1
  238. package/dist/reducers/Reducers.js +15 -3
  239. package/dist/reducers/Reducers.js.map +1 -1
  240. package/dist/reducers/reducer.d.ts +9 -1
  241. package/dist/reducers/reducer.d.ts.map +1 -1
  242. package/dist/reducers/reducer.js +4 -2
  243. package/dist/reducers/reducer.js.map +1 -1
  244. package/dist/transactions/IUnitOfWork.d.ts +18 -0
  245. package/dist/transactions/IUnitOfWork.d.ts.map +1 -1
  246. package/dist/transactions/UnitOfWork.d.ts +9 -0
  247. package/dist/transactions/UnitOfWork.d.ts.map +1 -1
  248. package/dist/transactions/UnitOfWork.js +14 -0
  249. package/dist/transactions/UnitOfWork.js.map +1 -1
  250. package/dist/tsconfig.tsbuildinfo +1 -1
  251. package/eventSequences/AppendOperationsBroadcaster.ts +83 -0
  252. package/eventSequences/AppendOptions.ts +8 -0
  253. package/eventSequences/AppendResult.ts +16 -0
  254. package/eventSequences/AppendedEventWithResult.ts +17 -0
  255. package/eventSequences/CompleteStreamError.ts +20 -0
  256. package/eventSequences/CompleteStreamResult.ts +13 -0
  257. package/eventSequences/ConcurrencyViolation.ts +18 -0
  258. package/eventSequences/EventForEventSourceId.ts +12 -0
  259. package/eventSequences/EventSequence.spec.ts +588 -0
  260. package/eventSequences/EventSequence.ts +406 -20
  261. package/eventSequences/IEventSequence.ts +109 -1
  262. package/eventSequences/WaitForCompletionResult.ts +15 -0
  263. package/eventSequences/index.ts +5 -0
  264. package/eventStoreSubscriptions/EventStoreSubscriptions.spec.ts +52 -0
  265. package/eventStoreSubscriptions/EventStoreSubscriptions.ts +19 -1
  266. package/eventStoreSubscriptions/IEventStoreSubscriptions.ts +7 -0
  267. package/eventStoreSubscriptions/contracts.ts +126 -0
  268. package/events/constraints/Constraints.ts +1 -1
  269. package/externalServices/ExternalServiceBuilder.ts +128 -0
  270. package/externalServices/ExternalServices.ts +34 -0
  271. package/externalServices/ExternalServicesContracts.ts +709 -0
  272. package/externalServices/IExternalServiceBuilder.ts +76 -0
  273. package/externalServices/IExternalServices.ts +16 -0
  274. package/externalServices/index.ts +7 -0
  275. package/identities/IIdentityManager.ts +19 -0
  276. package/identities/IdentityManager.ts +32 -0
  277. package/identities/index.ts +5 -0
  278. package/index.ts +6 -0
  279. package/observation/FailedPartition.ts +21 -0
  280. package/observation/FailedPartitionAttempt.ts +21 -0
  281. package/observation/FailedPartitions.spec.ts +75 -0
  282. package/observation/FailedPartitions.ts +44 -0
  283. package/observation/ICanBeNotifiedWhenPartitionReplayed.ts +22 -0
  284. package/observation/ICanBeNotifiedWhenReplay.ts +20 -0
  285. package/observation/IFailedPartitions.ts +22 -0
  286. package/observation/index.ts +6 -0
  287. package/observation/notifyReplayLifecycle.spec.ts +98 -0
  288. package/observation/notifyReplayLifecycle.ts +61 -0
  289. package/observation/toClientFailedPartition.ts +26 -0
  290. package/package.json +12 -2
  291. package/projections/Projections.childrenAndNested.spec.ts +188 -0
  292. package/projections/Projections.spec.ts +131 -0
  293. package/projections/Projections.ts +37 -119
  294. package/projections/declarative/AddBuilder.ts +28 -0
  295. package/projections/declarative/AddChildBuilder.ts +97 -0
  296. package/projections/declarative/ChildrenBuilder.spec.ts +157 -0
  297. package/projections/declarative/ChildrenBuilder.ts +90 -0
  298. package/projections/declarative/CompositeKeyBuilder.spec.ts +117 -0
  299. package/projections/declarative/CompositeKeyBuilder.ts +38 -0
  300. package/projections/declarative/FromBuilder.ts +60 -15
  301. package/projections/declarative/ICompositeKeyBuilder.ts +6 -0
  302. package/projections/declarative/JoinBuilder.ts +66 -17
  303. package/projections/declarative/NestedBuilder.ts +76 -0
  304. package/projections/declarative/ProjectionBuilderCore.ts +257 -0
  305. package/projections/declarative/ProjectionBuilderFor.spec.ts +115 -0
  306. package/projections/declarative/ProjectionBuilderFor.ts +29 -168
  307. package/projections/declarative/SubtractBuilder.ts +28 -0
  308. package/projections/declarative/index.ts +9 -0
  309. package/projections/modelBound/childrenAndNestedBuilder.ts +354 -0
  310. package/reactors/ReactorSideEffects.spec.ts +182 -0
  311. package/reactors/ReactorSideEffects.ts +97 -0
  312. package/reactors/Reactors.ts +29 -4
  313. package/reducers/Reducers.spec.ts +87 -0
  314. package/reducers/Reducers.ts +15 -3
  315. package/reducers/reducer.spec.ts +40 -0
  316. package/reducers/reducer.ts +11 -2
  317. package/transactions/IUnitOfWork.ts +21 -0
  318. package/transactions/UnitOfWork.spec.ts +82 -0
  319. package/transactions/UnitOfWork.ts +20 -0
@@ -1,7 +1,11 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
+ import type { Constructor } from '@cratis/fundamentals';
5
+ import type { AppendedEvent } from '../events/AppendedEvent';
6
+ import { AppendedEventWithResult } from './AppendedEventWithResult';
4
7
  import { AppendOptions } from './AppendOptions';
8
+ import { CompleteStreamResult } from './CompleteStreamResult';
5
9
  import { EventForEventSourceId } from './EventForEventSourceId';
6
10
  import { AppendResult } from './AppendResult';
7
11
  import { EventSequenceId } from './EventSequenceId';
@@ -18,6 +22,18 @@ export interface IEventSequence {
18
22
  /** Transactional append operations for this event sequence. */
19
23
  readonly transactional: ITransactionalEventSequence;
20
24
 
25
+ /**
26
+ * A hot, multicast async iterable that yields the events appended through this specific
27
+ * {@link IEventSequence} instance, together with their result, after each {@link append} or
28
+ * {@link appendMany} call completes (whether it succeeded or failed). A single-event append
29
+ * yields an array of one element; a batch append yields the full batch.
30
+ * @remarks
31
+ * This does not fire for transactional appends through `transactional`. Values are only
32
+ * published while at least one consumer is iterating — there is no replay buffer, so a
33
+ * consumer that starts iterating after an append misses it.
34
+ */
35
+ readonly appendOperations: AsyncIterable<AppendedEventWithResult[]>;
36
+
21
37
  /**
22
38
  * Appends a single event to the event sequence.
23
39
  * @param eventSourceId - The identifier of the event source.
@@ -44,12 +60,36 @@ export interface IEventSequence {
44
60
  */
45
61
  appendMany(events: EventForEventSourceId[], options?: AppendOptions): Promise<AppendResult[]>;
46
62
 
63
+ /**
64
+ * Gets the next sequence number that will be assigned to the next appended event.
65
+ * @returns The next sequence number.
66
+ */
67
+ getNextSequenceNumber(): Promise<EventSequenceNumber>;
68
+
47
69
  /**
48
70
  * Gets the tail sequence number (the number of the most recently appended event).
49
71
  * @param eventSourceId - Optional event source identifier to filter by.
72
+ * @param eventSourceType - Optional event source type to filter by.
73
+ * @param eventStreamType - Optional event stream type to filter by.
74
+ * @param eventStreamId - Optional event stream identifier to filter by.
75
+ * @param filterEventTypes - Optional collection of event type constructors to filter by.
50
76
  * @returns The tail sequence number.
51
77
  */
52
- getTailSequenceNumber(eventSourceId?: string): Promise<EventSequenceNumber>;
78
+ getTailSequenceNumber(
79
+ eventSourceId?: string,
80
+ eventSourceType?: string,
81
+ eventStreamType?: string,
82
+ eventStreamId?: string,
83
+ filterEventTypes?: Constructor[]
84
+ ): Promise<EventSequenceNumber>;
85
+
86
+ /**
87
+ * Gets the tail sequence number for a specific observer (reactor/reducer) type, based on the
88
+ * tail of the event types the observer handles.
89
+ * @param observerType - The observer (reactor/reducer) type to get the tail sequence number for.
90
+ * @returns The tail sequence number.
91
+ */
92
+ getTailSequenceNumberForObserver(observerType: Constructor): Promise<EventSequenceNumber>;
53
93
 
54
94
  /**
55
95
  * Determines whether there are events for a given event source identifier.
@@ -57,4 +97,72 @@ export interface IEventSequence {
57
97
  * @returns True if there are events for the given event source.
58
98
  */
59
99
  hasEventsFor(eventSourceId: string): Promise<boolean>;
100
+
101
+ /**
102
+ * Gets all events for a specific event source, optionally filtered to specific event types.
103
+ * @param eventSourceId - The event source identifier to get events for.
104
+ * @param eventTypes - Collection of event type constructors to filter by.
105
+ * @param eventStreamType - Optional event stream type. Defaults to the default stream type.
106
+ * @param eventStreamId - Optional event stream identifier. Defaults to the default stream.
107
+ * @param eventSourceType - Optional event source type. Defaults to the default source type.
108
+ * @returns A collection of appended events.
109
+ */
110
+ getForEventSourceIdAndEventTypes(
111
+ eventSourceId: string,
112
+ eventTypes: Constructor[],
113
+ eventStreamType?: string,
114
+ eventStreamId?: string,
115
+ eventSourceType?: string
116
+ ): Promise<AppendedEvent[]>;
117
+
118
+ /**
119
+ * Gets all events after and including a given sequence number, optionally filtered by event
120
+ * source identifier and event types.
121
+ * @param sequenceNumber - The sequence number of the first event to get from.
122
+ * @param eventSourceId - Optional event source identifier to filter by.
123
+ * @param filterEventTypes - Optional collection of event type constructors to filter by.
124
+ * @returns A collection of appended events.
125
+ */
126
+ getFromSequenceNumber(
127
+ sequenceNumber: EventSequenceNumber,
128
+ eventSourceId?: string,
129
+ filterEventTypes?: Constructor[]
130
+ ): Promise<AppendedEvent[]>;
131
+
132
+ /**
133
+ * Redacts a single event at a specific sequence number.
134
+ * @param sequenceNumber - The sequence number of the event to redact.
135
+ * @param reason - The reason for redacting the event.
136
+ * @returns A promise that resolves when the redaction has completed.
137
+ * @remarks
138
+ * This is a permanent, destructive rewrite of the event's content — typically used to satisfy GDPR
139
+ * or other compliance erasure requirements. It is not a field-level mask.
140
+ */
141
+ redact(sequenceNumber: EventSequenceNumber, reason: string): Promise<void>;
142
+
143
+ /**
144
+ * Redacts all events for a specific event source, optionally filtered to specific event types.
145
+ * @param eventSourceId - The event source identifier to redact events for.
146
+ * @param reason - The reason for redacting the events.
147
+ * @param eventTypes - Optional collection of event type constructors to limit the redaction to.
148
+ * @returns A promise that resolves when the redaction has completed.
149
+ * @remarks
150
+ * This is a permanent, destructive rewrite of the events' content — typically used to satisfy GDPR
151
+ * or other compliance erasure requirements. It is not a field-level mask.
152
+ */
153
+ redactForEventSource(eventSourceId: string, reason: string, eventTypes?: Constructor[]): Promise<void>;
154
+
155
+ /**
156
+ * Completes a stream so that no further events can be appended to it.
157
+ * @param eventStreamType - The event stream type identifying the stream's type.
158
+ * @param eventStreamId - The event stream identifier identifying the stream within the type.
159
+ * @returns The tail sequence number at the moment of completion on success, or a typed error
160
+ * describing why the operation was rejected.
161
+ * @remarks
162
+ * The default stream can never be completed and will return `DefaultStreamCannotBeCompleted`.
163
+ * Completing an already-completed stream returns `AlreadyCompleted` and leaves the stream in its
164
+ * completed state. After a successful completion any subsequent append targeting the same stream
165
+ * results in a constraint violation of type `StreamClosed`.
166
+ */
167
+ completeStream(eventStreamType: string, eventStreamId: string): Promise<CompleteStreamResult>;
60
168
  }
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { FailedPartition } from '../observation/FailedPartition';
5
+
6
+ /**
7
+ * Represents the result of waiting for the observers affected by an append operation to catch up.
8
+ */
9
+ export interface WaitForCompletionResult {
10
+ /** Whether all affected observers completed successfully. */
11
+ readonly isSuccess: boolean;
12
+
13
+ /** The failed partitions discovered while waiting, across all affected observers. */
14
+ readonly failedPartitions: ReadonlyArray<FailedPartition>;
15
+ }
@@ -4,11 +4,16 @@
4
4
  export { EventSequenceId } from './EventSequenceId';
5
5
  export { EventSequenceNumber } from './EventSequenceNumber';
6
6
  export type { AppendError } from './AppendError';
7
+ export type { ConcurrencyViolation } from './ConcurrencyViolation';
7
8
  export type { ConstraintViolation } from './ConstraintViolation';
8
9
  export type { AppendResult } from './AppendResult';
10
+ export type { AppendedEventWithResult } from './AppendedEventWithResult';
9
11
  export type { AppendOptions } from './AppendOptions';
12
+ export { CompleteStreamError } from './CompleteStreamError';
13
+ export type { CompleteStreamResult } from './CompleteStreamResult';
10
14
  export type { ConcurrencyScope } from './ConcurrencyScope';
11
15
  export type { EventForEventSourceId } from './EventForEventSourceId';
16
+ export type { WaitForCompletionResult } from './WaitForCompletionResult';
12
17
  export type { IEventSequence } from './IEventSequence';
13
18
  export type { IEventLog } from './IEventLog';
14
19
  export type { ITransactionalEventSequence } from './ITransactionalEventSequence';
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { describe, expect, it, vi } from 'vitest';
5
+ import type { ChronicleConnection } from '../connection';
6
+ import type { IEventTypes } from '../events';
7
+ import { EventStoreSubscriptions } from './EventStoreSubscriptions';
8
+
9
+ function createEventStoreSubscriptions(getSubscriptionsResult?: unknown) {
10
+ const getSubscriptions = vi.fn().mockResolvedValue(getSubscriptionsResult ?? { items: [] });
11
+ const connection = { eventStoreSubscriptions: { getSubscriptions } } as unknown as ChronicleConnection;
12
+ const eventTypes = {} as IEventTypes;
13
+ const subscriptions = new EventStoreSubscriptions(eventTypes, 'my-event-store', connection);
14
+ return { subscriptions, getSubscriptions };
15
+ }
16
+
17
+ describe('EventStoreSubscriptions', () => {
18
+ describe('when getting all subscriptions', () => {
19
+ const { subscriptions, getSubscriptions } = createEventStoreSubscriptions({
20
+ items: [{
21
+ Identifier: 'my-subscription',
22
+ SourceEventStore: 'source-event-store',
23
+ EventTypes: [{ Id: 'a3f6a2f0-6f2f-4a3c-9d3f-6f2f4a3c9d3f', Generation: 1, Tombstone: false }]
24
+ }]
25
+ });
26
+
27
+ it('should call the RPC with the target event store and map the response', async () => {
28
+ const result = await subscriptions.getAll();
29
+
30
+ expect(getSubscriptions).toHaveBeenCalledTimes(1);
31
+ const request = getSubscriptions.mock.calls[0][0];
32
+ expect(request.TargetEventStore).toEqual('my-event-store');
33
+
34
+ expect(result).toHaveLength(1);
35
+ expect(result[0].id.value).toEqual('my-subscription');
36
+ expect(result[0].sourceEventStore).toEqual('source-event-store');
37
+ expect(result[0].eventTypes).toHaveLength(1);
38
+ expect(result[0].eventTypes[0].id.value).toEqual('a3f6a2f0-6f2f-4a3c-9d3f-6f2f4a3c9d3f');
39
+ expect(result[0].eventTypes[0].generation.value).toEqual(1);
40
+ });
41
+ });
42
+
43
+ describe('when there are no subscriptions', () => {
44
+ const { subscriptions } = createEventStoreSubscriptions({ items: [] });
45
+
46
+ it('should return an empty array', async () => {
47
+ const result = await subscriptions.getAll();
48
+
49
+ expect(result).toEqual([]);
50
+ });
51
+ });
52
+ });
@@ -4,8 +4,9 @@
4
4
  import { diag } from '@opentelemetry/api';
5
5
  import { ChronicleConnection } from '../connection';
6
6
  import { EventStoreName } from '../EventStoreName';
7
- import { IEventTypes } from '../events';
7
+ import { EventType, EventTypeGeneration, EventTypeId, IEventTypes } from '../events';
8
8
  import { EventStoreSubscriptionBuilder } from './EventStoreSubscriptionBuilder';
9
+ import { EventStoreSubscriptionDefinition } from './EventStoreSubscriptionDefinition';
9
10
  import { EventStoreSubscriptionId } from './EventStoreSubscriptionId';
10
11
  import { IEventStoreSubscriptionBuilder } from './IEventStoreSubscriptionBuilder';
11
12
  import { IEventStoreSubscriptions } from './IEventStoreSubscriptions';
@@ -71,4 +72,21 @@ export class EventStoreSubscriptions implements IEventStoreSubscriptions {
71
72
  SubscriptionIds: [id]
72
73
  });
73
74
  }
75
+
76
+ /** @inheritdoc */
77
+ async getAll(): Promise<EventStoreSubscriptionDefinition[]> {
78
+ const response = await this._connection.eventStoreSubscriptions.getSubscriptions({
79
+ TargetEventStore: this._targetEventStore
80
+ });
81
+
82
+ return (response.items ?? []).map(definition => new EventStoreSubscriptionDefinition(
83
+ new EventStoreSubscriptionId(definition.Identifier),
84
+ definition.SourceEventStore,
85
+ (definition.EventTypes ?? []).map(eventType => new EventType(
86
+ new EventTypeId(eventType.Id),
87
+ new EventTypeGeneration(eventType.Generation),
88
+ eventType.Tombstone
89
+ ))
90
+ ));
91
+ }
74
92
  }
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { EventStoreName } from '../EventStoreName';
5
+ import { EventStoreSubscriptionDefinition } from './EventStoreSubscriptionDefinition';
5
6
  import { EventStoreSubscriptionId } from './EventStoreSubscriptionId';
6
7
  import { IEventStoreSubscriptionBuilder } from './IEventStoreSubscriptionBuilder';
7
8
 
@@ -26,4 +27,10 @@ export interface IEventStoreSubscriptions {
26
27
  * @param subscriptionId - The subscription identifier to remove.
27
28
  */
28
29
  unsubscribe(subscriptionId: EventStoreSubscriptionId | string): Promise<void>;
30
+
31
+ /**
32
+ * Gets all subscriptions registered for this event store.
33
+ * @returns A collection of {@link EventStoreSubscriptionDefinition}.
34
+ */
35
+ getAll(): Promise<EventStoreSubscriptionDefinition[]>;
29
36
  }
@@ -28,6 +28,14 @@ export interface RemoveEventStoreSubscriptions {
28
28
  SubscriptionIds: string[];
29
29
  }
30
30
 
31
+ export interface GetEventStoreSubscriptions {
32
+ TargetEventStore: string;
33
+ }
34
+
35
+ export interface IEnumerableEventStoreSubscriptionDefinitionContract {
36
+ items: EventStoreSubscriptionDefinitionContract[];
37
+ }
38
+
31
39
  function createBaseEmpty(): Empty {
32
40
  return {};
33
41
  }
@@ -48,6 +56,14 @@ function createBaseRemoveEventStoreSubscriptions(): RemoveEventStoreSubscription
48
56
  return { TargetEventStore: '', SubscriptionIds: [] };
49
57
  }
50
58
 
59
+ function createBaseGetEventStoreSubscriptions(): GetEventStoreSubscriptions {
60
+ return { TargetEventStore: '' };
61
+ }
62
+
63
+ function createBaseIEnumerableEventStoreSubscriptionDefinition(): IEnumerableEventStoreSubscriptionDefinitionContract {
64
+ return { items: [] };
65
+ }
66
+
51
67
  export const EmptyMessage: MessageFns<Empty> = {
52
68
  encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
53
69
  return writer;
@@ -322,6 +338,100 @@ export const RemoveEventStoreSubscriptionsMessage: MessageFns<RemoveEventStoreSu
322
338
  }
323
339
  };
324
340
 
341
+ export const GetEventStoreSubscriptionsMessage: MessageFns<GetEventStoreSubscriptions> = {
342
+ encode(message: GetEventStoreSubscriptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
343
+ if (message.TargetEventStore !== '') {
344
+ writer.uint32(10).string(message.TargetEventStore);
345
+ }
346
+ return writer;
347
+ },
348
+ decode(input: BinaryReader | Uint8Array, length?: number): GetEventStoreSubscriptions {
349
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
350
+ const end = length === undefined ? reader.len : reader.pos + length;
351
+ const message = createBaseGetEventStoreSubscriptions();
352
+ while (reader.pos < end) {
353
+ const tag = reader.uint32();
354
+ switch (tag >>> 3) {
355
+ case 1:
356
+ message.TargetEventStore = reader.string();
357
+ continue;
358
+ }
359
+ if ((tag & 7) === 4 || tag === 0) {
360
+ break;
361
+ }
362
+ reader.skip(tag & 7);
363
+ }
364
+ return message;
365
+ },
366
+ fromJSON(object: unknown): GetEventStoreSubscriptions {
367
+ const value = object as { TargetEventStore?: unknown };
368
+ return {
369
+ TargetEventStore: typeof value.TargetEventStore === 'string' ? value.TargetEventStore : ''
370
+ };
371
+ },
372
+ toJSON(message: GetEventStoreSubscriptions): unknown {
373
+ return {
374
+ TargetEventStore: message.TargetEventStore
375
+ };
376
+ },
377
+ create(base?: DeepPartial<GetEventStoreSubscriptions>): GetEventStoreSubscriptions {
378
+ return GetEventStoreSubscriptionsMessage.fromPartial(base ?? {});
379
+ },
380
+ fromPartial(object: DeepPartial<GetEventStoreSubscriptions>): GetEventStoreSubscriptions {
381
+ return {
382
+ TargetEventStore: object.TargetEventStore ?? ''
383
+ };
384
+ }
385
+ };
386
+
387
+ export const IEnumerableEventStoreSubscriptionDefinitionMessage: MessageFns<IEnumerableEventStoreSubscriptionDefinitionContract> = {
388
+ encode(message: IEnumerableEventStoreSubscriptionDefinitionContract, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
389
+ for (const item of message.items) {
390
+ EventStoreSubscriptionDefinitionMessage.encode(item, writer.uint32(10).fork()).join();
391
+ }
392
+ return writer;
393
+ },
394
+ decode(input: BinaryReader | Uint8Array, length?: number): IEnumerableEventStoreSubscriptionDefinitionContract {
395
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
396
+ const end = length === undefined ? reader.len : reader.pos + length;
397
+ const message = createBaseIEnumerableEventStoreSubscriptionDefinition();
398
+ while (reader.pos < end) {
399
+ const tag = reader.uint32();
400
+ switch (tag >>> 3) {
401
+ case 1:
402
+ message.items.push(EventStoreSubscriptionDefinitionMessage.decode(reader, reader.uint32()));
403
+ continue;
404
+ }
405
+ if ((tag & 7) === 4 || tag === 0) {
406
+ break;
407
+ }
408
+ reader.skip(tag & 7);
409
+ }
410
+ return message;
411
+ },
412
+ fromJSON(object: unknown): IEnumerableEventStoreSubscriptionDefinitionContract {
413
+ const value = object as { items?: unknown[] };
414
+ return {
415
+ items: Array.isArray(value.items)
416
+ ? value.items.map(_ => EventStoreSubscriptionDefinitionMessage.fromJSON(_))
417
+ : []
418
+ };
419
+ },
420
+ toJSON(message: IEnumerableEventStoreSubscriptionDefinitionContract): unknown {
421
+ return {
422
+ items: message.items.map(_ => EventStoreSubscriptionDefinitionMessage.toJSON(_))
423
+ };
424
+ },
425
+ create(base?: DeepPartial<IEnumerableEventStoreSubscriptionDefinitionContract>): IEnumerableEventStoreSubscriptionDefinitionContract {
426
+ return IEnumerableEventStoreSubscriptionDefinitionMessage.fromPartial(base ?? {});
427
+ },
428
+ fromPartial(object: DeepPartial<IEnumerableEventStoreSubscriptionDefinitionContract>): IEnumerableEventStoreSubscriptionDefinitionContract {
429
+ return {
430
+ items: object.items?.map(_ => EventStoreSubscriptionDefinitionMessage.fromPartial(_)) ?? []
431
+ };
432
+ }
433
+ };
434
+
325
435
  export const EventStoreSubscriptionsDefinition = {
326
436
  name: 'EventStoreSubscriptions',
327
437
  fullName: 'Cratis.Chronicle.Contracts.Observation.EventStoreSubscriptions.EventStoreSubscriptions',
@@ -334,6 +444,14 @@ export const EventStoreSubscriptionsDefinition = {
334
444
  responseStream: false,
335
445
  options: {}
336
446
  },
447
+ getSubscriptions: {
448
+ name: 'GetSubscriptions',
449
+ requestType: GetEventStoreSubscriptionsMessage,
450
+ requestStream: false,
451
+ responseType: IEnumerableEventStoreSubscriptionDefinitionMessage,
452
+ responseStream: false,
453
+ options: {}
454
+ },
337
455
  remove: {
338
456
  name: 'Remove',
339
457
  requestType: RemoveEventStoreSubscriptionsMessage,
@@ -347,11 +465,19 @@ export const EventStoreSubscriptionsDefinition = {
347
465
 
348
466
  export interface EventStoreSubscriptionsClient<CallOptionsExt = {}> {
349
467
  add(request: DeepPartial<AddEventStoreSubscriptions>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
468
+ getSubscriptions(
469
+ request: DeepPartial<GetEventStoreSubscriptions>,
470
+ options?: CallOptions & CallOptionsExt
471
+ ): Promise<IEnumerableEventStoreSubscriptionDefinitionContract>;
350
472
  remove(request: DeepPartial<RemoveEventStoreSubscriptions>, options?: CallOptions & CallOptionsExt): Promise<Empty>;
351
473
  }
352
474
 
353
475
  export interface EventStoreSubscriptionsServiceImplementation<CallContextExt = {}> {
354
476
  add(request: AddEventStoreSubscriptions, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
477
+ getSubscriptions(
478
+ request: GetEventStoreSubscriptions,
479
+ context: CallContext & CallContextExt
480
+ ): Promise<DeepPartial<IEnumerableEventStoreSubscriptionDefinitionContract>>;
355
481
  remove(request: RemoveEventStoreSubscriptions, context: CallContext & CallContextExt): Promise<DeepPartial<Empty>>;
356
482
  }
357
483
 
@@ -84,7 +84,7 @@ export class Constraints implements IConstraints {
84
84
  Definition: {
85
85
  Value0: undefined,
86
86
  Value1: {
87
- EventTypeId: uet.eventTypeId
87
+ EventTypeIds: [uet.eventTypeId]
88
88
  }
89
89
  },
90
90
  Scope: scope
@@ -0,0 +1,128 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import {
5
+ ExternalServiceDefinition,
6
+ ExternalServiceEndpoint,
7
+ ExternalServiceEndpointType,
8
+ OneOfBasicAuthorizationBearerTokenAuthorizationOAuthAuthorization
9
+ } from './ExternalServicesContracts';
10
+ import { IExternalServiceBuilder } from './IExternalServiceBuilder';
11
+
12
+ /**
13
+ * Implements {@link IExternalServiceBuilder}.
14
+ */
15
+ export class ExternalServiceBuilder implements IExternalServiceBuilder {
16
+ private readonly _headers = new Map<string, string>();
17
+ private readonly _options = new Map<string, string>();
18
+ private _type = ExternalServiceEndpointType.Http;
19
+ private _url = '';
20
+ private _authorization: OneOfBasicAuthorizationBearerTokenAuthorizationOAuthAuthorization | undefined;
21
+ private _host = '';
22
+ private _port = 0;
23
+ private _database = '';
24
+ private _username = '';
25
+ private _password = '';
26
+
27
+ /** @inheritdoc */
28
+ http(url: string): IExternalServiceBuilder {
29
+ this._type = ExternalServiceEndpointType.Http;
30
+ this._url = url;
31
+ return this;
32
+ }
33
+
34
+ /** @inheritdoc */
35
+ withBasicAuth(username: string, password: string): IExternalServiceBuilder {
36
+ this._authorization = {
37
+ Value0: { Username: username, Password: password },
38
+ Value1: undefined,
39
+ Value2: undefined
40
+ };
41
+ return this;
42
+ }
43
+
44
+ /** @inheritdoc */
45
+ withBearerToken(token: string): IExternalServiceBuilder {
46
+ this._authorization = {
47
+ Value0: undefined,
48
+ Value1: { Token: token },
49
+ Value2: undefined
50
+ };
51
+ return this;
52
+ }
53
+
54
+ /** @inheritdoc */
55
+ withOAuth(authority: string, clientId: string, clientSecret: string): IExternalServiceBuilder {
56
+ this._authorization = {
57
+ Value0: undefined,
58
+ Value1: undefined,
59
+ Value2: { Authority: authority, ClientId: clientId, ClientSecret: clientSecret }
60
+ };
61
+ return this;
62
+ }
63
+
64
+ /** @inheritdoc */
65
+ withHeader(key: string, value: string): IExternalServiceBuilder {
66
+ this._headers.set(key, value);
67
+ return this;
68
+ }
69
+
70
+ /** @inheritdoc */
71
+ msSql(host: string, database: string, username: string, password: string, port = 0): IExternalServiceBuilder {
72
+ return this.configureDatabase(ExternalServiceEndpointType.MsSql, host, database, username, password, port);
73
+ }
74
+
75
+ /** @inheritdoc */
76
+ postgreSql(host: string, database: string, username: string, password: string, port = 0): IExternalServiceBuilder {
77
+ return this.configureDatabase(ExternalServiceEndpointType.PostgreSql, host, database, username, password, port);
78
+ }
79
+
80
+ /** @inheritdoc */
81
+ withOption(key: string, value: string): IExternalServiceBuilder {
82
+ this._options.set(key, value);
83
+ return this;
84
+ }
85
+
86
+ /**
87
+ * Builds the external service definition.
88
+ * @param id - The identifier of the external service.
89
+ * @param name - The human-readable name of the external service.
90
+ * @returns The built external service definition.
91
+ */
92
+ build(id: string, name: string): ExternalServiceDefinition {
93
+ const endpoint: ExternalServiceEndpoint = { Type: this._type, Http: undefined, Database: undefined };
94
+
95
+ if (this._type === ExternalServiceEndpointType.Http) {
96
+ endpoint.Http = {
97
+ Url: this._url,
98
+ Authorization: this._authorization,
99
+ Headers: Object.fromEntries(this._headers)
100
+ };
101
+ } else {
102
+ endpoint.Database = {
103
+ Host: this._host,
104
+ Port: this._port,
105
+ Database: this._database,
106
+ Username: this._username,
107
+ Password: this._password,
108
+ Options: Object.fromEntries(this._options)
109
+ };
110
+ }
111
+
112
+ return {
113
+ Id: id,
114
+ Name: name,
115
+ Endpoint: endpoint
116
+ };
117
+ }
118
+
119
+ private configureDatabase(type: ExternalServiceEndpointType, host: string, database: string, username: string, password: string, port: number): IExternalServiceBuilder {
120
+ this._type = type;
121
+ this._host = host;
122
+ this._database = database;
123
+ this._username = username;
124
+ this._password = password;
125
+ this._port = port;
126
+ return this;
127
+ }
128
+ }
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ChronicleConnection } from '../connection';
5
+ import { ExternalServiceBuilder } from './ExternalServiceBuilder';
6
+ import { IExternalServiceBuilder } from './IExternalServiceBuilder';
7
+ import { IExternalServices } from './IExternalServices';
8
+
9
+ /**
10
+ * Implements {@link IExternalServices}.
11
+ */
12
+ export class ExternalServices implements IExternalServices {
13
+ /**
14
+ * Creates a new {@link ExternalServices} instance.
15
+ * @param _eventStore - Event store name.
16
+ * @param _connection - Chronicle connection.
17
+ */
18
+ constructor(
19
+ private readonly _eventStore: string,
20
+ private readonly _connection: ChronicleConnection
21
+ ) {}
22
+
23
+ /** @inheritdoc */
24
+ async register(name: string, configure: (builder: IExternalServiceBuilder) => void): Promise<void> {
25
+ const builder = new ExternalServiceBuilder();
26
+ configure(builder);
27
+ const definition = builder.build(name, name);
28
+
29
+ await this._connection.externalServices.add({
30
+ EventStore: this._eventStore,
31
+ ExternalServices: [definition]
32
+ });
33
+ }
34
+ }