@bett3r-dev/pv3-types 1.0.0 → 1.4.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 (137) hide show
  1. package/CHANGELOG.md +305 -0
  2. package/build/adminPlugin.d.ts +24 -0
  3. package/build/adminPlugin.d.ts.map +1 -0
  4. package/build/{eventsourcing/utils.js → adminPlugin.js} +1 -1
  5. package/build/adminPlugin.js.map +1 -0
  6. package/build/aggregateSchema.d.ts +94 -0
  7. package/build/aggregateSchema.d.ts.map +1 -0
  8. package/build/aggregateSchema.js +287 -0
  9. package/build/aggregateSchema.js.map +1 -0
  10. package/build/authentication.d.ts +179 -78
  11. package/build/authentication.d.ts.map +1 -1
  12. package/build/authentication.js +62 -19
  13. package/build/authentication.js.map +1 -1
  14. package/build/cache.d.ts +50 -4
  15. package/build/cache.d.ts.map +1 -1
  16. package/build/clusterAdministration.d.ts +712 -225
  17. package/build/clusterAdministration.d.ts.map +1 -1
  18. package/build/clusterAdministration.js +175 -52
  19. package/build/clusterAdministration.js.map +1 -1
  20. package/build/configuration.d.ts +26 -5
  21. package/build/configuration.d.ts.map +1 -1
  22. package/build/database.d.ts +240 -56
  23. package/build/database.d.ts.map +1 -1
  24. package/build/database.js +102 -20
  25. package/build/database.js.map +1 -1
  26. package/build/endpoints.d.ts +141 -41
  27. package/build/endpoints.d.ts.map +1 -1
  28. package/build/endpoints.js +50 -26
  29. package/build/endpoints.js.map +1 -1
  30. package/build/errors.d.ts +166 -0
  31. package/build/errors.d.ts.map +1 -0
  32. package/build/errors.js +276 -0
  33. package/build/errors.js.map +1 -0
  34. package/build/evenstore.d.ts +47 -7
  35. package/build/evenstore.d.ts.map +1 -1
  36. package/build/eventsourcing/aggregateBuilder.d.ts +17 -8
  37. package/build/eventsourcing/aggregateBuilder.d.ts.map +1 -1
  38. package/build/eventsourcing/commandBuilder.d.ts +20 -13
  39. package/build/eventsourcing/commandBuilder.d.ts.map +1 -1
  40. package/build/eventsourcing/commandHandlers.d.ts +155 -33
  41. package/build/eventsourcing/commandHandlers.d.ts.map +1 -1
  42. package/build/eventsourcing/commandHandlers.js +62 -14
  43. package/build/eventsourcing/commandHandlers.js.map +1 -1
  44. package/build/eventsourcing/eventHandlers.d.ts +173 -44
  45. package/build/eventsourcing/eventHandlers.d.ts.map +1 -1
  46. package/build/eventsourcing/eventHandlers.js +29 -21
  47. package/build/eventsourcing/eventHandlers.js.map +1 -1
  48. package/build/eventsourcing/eventHandlersBuilder.d.ts +18 -12
  49. package/build/eventsourcing/eventHandlersBuilder.d.ts.map +1 -1
  50. package/build/eventsourcing/eventHandlersBuilder.js.map +1 -1
  51. package/build/eventsourcing/eventsourcing.types.d.ts +322 -0
  52. package/build/eventsourcing/eventsourcing.types.d.ts.map +1 -0
  53. package/build/eventsourcing/eventsourcing.types.js +26 -0
  54. package/build/eventsourcing/eventsourcing.types.js.map +1 -0
  55. package/build/eventsourcing/externalSystemBuilder.d.ts +8 -7
  56. package/build/eventsourcing/externalSystemBuilder.d.ts.map +1 -1
  57. package/build/eventsourcing/index.d.ts +2 -378
  58. package/build/eventsourcing/index.d.ts.map +1 -1
  59. package/build/eventsourcing/index.js +2 -23
  60. package/build/eventsourcing/index.js.map +1 -1
  61. package/build/eventsourcing/invariants.d.ts +34 -10
  62. package/build/eventsourcing/invariants.d.ts.map +1 -1
  63. package/build/eventsourcing/shapeChangeForSubscriber.d.ts +33 -0
  64. package/build/eventsourcing/shapeChangeForSubscriber.d.ts.map +1 -0
  65. package/build/eventsourcing/shapeChangeForSubscriber.js +47 -0
  66. package/build/eventsourcing/shapeChangeForSubscriber.js.map +1 -0
  67. package/build/index.d.ts +6 -1
  68. package/build/index.d.ts.map +1 -1
  69. package/build/index.js +6 -1
  70. package/build/index.js.map +1 -1
  71. package/build/infrastructure.d.ts +9 -1
  72. package/build/infrastructure.d.ts.map +1 -1
  73. package/build/infrastructure.js +33 -1
  74. package/build/infrastructure.js.map +1 -1
  75. package/build/livenessWatchdog.d.ts +28 -0
  76. package/build/livenessWatchdog.d.ts.map +1 -0
  77. package/build/livenessWatchdog.js +43 -0
  78. package/build/livenessWatchdog.js.map +1 -0
  79. package/build/logger.d.ts +8 -9
  80. package/build/logger.d.ts.map +1 -1
  81. package/build/logger.js +18 -6
  82. package/build/logger.js.map +1 -1
  83. package/build/outboxManager.d.ts +858 -14
  84. package/build/outboxManager.d.ts.map +1 -1
  85. package/build/outboxManager.js +173 -15
  86. package/build/outboxManager.js.map +1 -1
  87. package/build/permissions.d.ts +47 -0
  88. package/build/permissions.d.ts.map +1 -0
  89. package/build/permissions.js +3 -0
  90. package/build/permissions.js.map +1 -0
  91. package/build/ports.d.ts +10 -10
  92. package/build/ports.d.ts.map +1 -1
  93. package/build/routesAuth.d.ts +17 -25
  94. package/build/routesAuth.d.ts.map +1 -1
  95. package/build/routesAuth.js +4 -14
  96. package/build/routesAuth.js.map +1 -1
  97. package/build/typedEventEmitter.d.ts +7 -13
  98. package/build/typedEventEmitter.d.ts.map +1 -1
  99. package/build/typedEventEmitter.js +2 -2
  100. package/build/typedEventEmitter.js.map +1 -1
  101. package/build/userSession.d.ts +8 -0
  102. package/build/userSession.d.ts.map +1 -0
  103. package/build/userSession.js +3 -0
  104. package/build/userSession.js.map +1 -0
  105. package/package.json +22 -7
  106. package/build/eventsourcing/utils.d.ts +0 -4
  107. package/build/eventsourcing/utils.d.ts.map +0 -1
  108. package/build/eventsourcing/utils.js.map +0 -1
  109. package/build/validation.d.ts +0 -64
  110. package/build/validation.d.ts.map +0 -1
  111. package/build/validation.js +0 -57
  112. package/build/validation.js.map +0 -1
  113. package/src/authentication.ts +0 -273
  114. package/src/cache.ts +0 -109
  115. package/src/clusterAdministration.ts +0 -216
  116. package/src/configuration.ts +0 -71
  117. package/src/database.ts +0 -157
  118. package/src/endpoints.ts +0 -198
  119. package/src/evenstore.ts +0 -27
  120. package/src/eventsourcing/aggregateBuilder.ts +0 -11
  121. package/src/eventsourcing/commandBuilder.ts +0 -64
  122. package/src/eventsourcing/commandHandlers.ts +0 -137
  123. package/src/eventsourcing/eventHandlers.ts +0 -118
  124. package/src/eventsourcing/eventHandlersBuilder.ts +0 -42
  125. package/src/eventsourcing/externalSystemBuilder.ts +0 -20
  126. package/src/eventsourcing/index.ts +0 -111
  127. package/src/eventsourcing/invariants.ts +0 -27
  128. package/src/eventsourcing/utils.ts +0 -4
  129. package/src/index.ts +0 -15
  130. package/src/infrastructure.ts +0 -41
  131. package/src/logger.ts +0 -45
  132. package/src/outboxManager.ts +0 -36
  133. package/src/ports.ts +0 -42
  134. package/src/routesAuth.ts +0 -58
  135. package/src/typedEventEmitter.ts +0 -73
  136. package/src/validation.ts +0 -89
  137. package/tsconfig.json +0 -15
@@ -1,9 +1,10 @@
1
1
  import { BaseSchema } from '@bett3r-dev/jsonschema-definer';
2
- import { Builder, CommittedEvent, EventFactory, EventMetadata, GetMessageType, ReadStreamOptions } from '.';
3
- import { AppErrorInstance, AppErrorType } from '../validation';
4
- import { DatabasePort } from '../database';
5
- import { EndpointActionParams, EndpointActionParamsContext } from '../endpoints';
6
- export type CommandHandlerState<Events = Record<string, EventFactory>, Payload = any, Model = any, USER = any> = {
2
+ import { Artifact, Builder, CommittedEvent, CreateEventType, EventFactory, EventMetadataBaseType, GetMessageType, ReadStreamOptions } from '.';
3
+ import { DatabasePort, DatabaseTransaction } from '../database';
4
+ import { EndpointActionParams, EndpointActionParamsContext, EndpointSchemas } from '../endpoints';
5
+ import { AppError } from '../errors';
6
+ import { PermissionString } from '../permissions';
7
+ export type CommandHandlerState<Events = Record<string, EventFactory>, Payload = any, Model = any, USER = any, METADATA = any> = {
7
8
  commandHandler: Aggregate | System;
8
9
  command: Command;
9
10
  stream: string;
@@ -16,74 +17,186 @@ export type CommandHandlerState<Events = Record<string, EventFactory>, Payload =
16
17
  events: Events[keyof Events][];
17
18
  state: Model;
18
19
  committedEvents?: Array<CommittedEvent>;
19
- metadata?: EventMetadata;
20
- expectedVersion?: number;
20
+ metadata?: METADATA;
21
+ /**
22
+ * Optimistic-concurrency expectation for this command's append.
23
+ *
24
+ * POPULATED BY DEFAULT on an eventsourced aggregate. `defaultEventsourcingLoad` observes
25
+ * the stream's head version BEFORE it reduces the stream and records it here, so the commit
26
+ * asserts the version the handler's decision was actually computed against. When another
27
+ * writer moved the head in between, the append raises a `ConcurrencyError` and the library
28
+ * re-runs the handler against the winner's state instead of silently rebasing a stale
29
+ * decision onto a stream it never saw. Leave it unset to get that.
30
+ *
31
+ * Set it explicitly only to say something the load cannot infer:
32
+ * - a caller-pinned version — "this append is valid only if the stream is still at N";
33
+ * - `null` — "version-free stream": the append writes `version: NULL`, which the partial
34
+ * unique index `(stream, version) WHERE version IS NOT NULL` cannot conflict on. This
35
+ * is what non-aggregate External Systems get, and it is never OCC-checked.
36
+ * Anything supplied — INCLUDING `null` — takes precedence over the derived head; the load
37
+ * checks whether an expectation was given AT ALL, not whether it was non-null.
38
+ *
39
+ * TWO SHAPES, one per commit template, and the type has to admit both because the
40
+ * multi-stream template has always READ the second one (`multiStream.ts` builds each
41
+ * stream's commit config from `expectedVersion?.[stream]`):
42
+ *
43
+ * - single-stream (`defaultCommit`) — `number | null`.
44
+ * - multi-stream (`multiStream.commit`) — a `{ [stream]: number | null }` MAP, so a
45
+ * single command can mix both disciplines: OCC on the streams that carry a real
46
+ * invariant, version-free on the streams whose events are commutative.
47
+ *
48
+ * Declaring only the scalar made the map shape unexpressible in a custom
49
+ * `withLoadFunction`, which is the only place it can be populated — PV3's own
50
+ * `multiStream.load` populates it for nothing. A command with a custom `load` never runs
51
+ * `defaultEventsourcingLoad`, so it derives nothing and keeps exactly what it sets.
52
+ */
53
+ expectedVersion?: number | null | Record<string, number | null>;
54
+ transaction?: DatabaseTransaction;
21
55
  };
22
56
  export type CommandExecutionResponse<Model = unknown> = {
23
57
  state?: Model;
24
58
  events: CommittedEvent[];
25
59
  };
26
- export type ExecuteCommandFunction = <SYSTEM extends System, COMMAND extends keyof SYSTEM['commands']>(commandHandler: SYSTEM, commandName: COMMAND) => (params: Partial<EndpointActionParams>) => Promise<unknown>;
27
- export type CommandLoadFunction<Model = any, Payload = any> = (state: CommandHandlerState<Model, Payload>, options?: ReadStreamOptions, initialState?: Model) => Promise<CommandHandlerState<Model, Payload>>;
28
- export type CommandCommitFunction<Model = any, Payload = any> = (state: CommandHandlerState<Model, Payload>) => Promise<CommandHandlerState<Model, Payload>>;
29
- export type CommandFormatFunction<Model = any, Payload = any> = (handlerState: CommandHandlerState<Model, Payload>) => Promise<CommandExecutionResponse<Model>>;
30
- export type CommandHandlerFunction<Model = any, CommandPayload = unknown, Events extends Record<string, EventFactory<EVENT>> = any, EVENT extends keyof Events = any, USER = any> = (state: Model extends undefined ? null : Model, data: CommandPayload, aggregateState: CommandHandlerState<Events, CommandPayload, any, USER>) => Promise<EventFactory<EVENT, GetMessageType<Events[EVENT]>>[]> | EventFactory<EVENT, GetMessageType<Events[EVENT]>>[];
31
- export type CommandErrorHandlerFunction<CommandPayload = unknown> = (error: AppErrorInstance, data: CommandPayload) => Promise<any>;
32
- export type Command<EVENTS extends Record<string, EventFactory<EVENT>> = any, EVENT extends keyof EVENTS = any, SystemModel = any, CommandPayload = any> = {
60
+ export type GetCommandPayloadType<COMMAND extends Command | Builder<Command>> = COMMAND extends Builder<Command<any, any, any, infer PAYLOAD>> ? PAYLOAD : COMMAND extends Command<any, any, any, infer PAYLOAD> ? PAYLOAD : never;
61
+ export type ExecuteCommandFunction<USER = any> = <SYSTEM extends System, COMMAND extends keyof SYSTEM['commands']>(commandHandler: SYSTEM, commandName: COMMAND, transaction?: DatabaseTransaction, schemas?: EndpointSchemas<any, any, any>) => (params: Partial<EndpointActionParams<GetCommandPayloadType<SYSTEM['commands'][COMMAND]>, any, {
62
+ id: string;
63
+ }, USER>>) => Promise<CommandExecutionResponse | Record<string, CommandExecutionResponse>>;
64
+ export type CommandLoadFunction<USER = any, Model = any, Payload = any, METADATA = any> = (state: CommandHandlerState<any, Payload, Model, USER, METADATA>, options?: ReadStreamOptions, initialState?: Model) => Promise<CommandHandlerState<any, Payload, Model, USER, METADATA>>;
65
+ export type CommandCommitFunction<USER = any, Model = any, Payload = any, METADATA = any> = (state: CommandHandlerState<any, Payload, Model, USER, METADATA>) => Promise<CommandHandlerState<any, Payload, Model, USER, METADATA>>;
66
+ export type CommandFormatFunction<USER = any, Model = any, Payload = any, METADATA = any> = (handlerState: CommandHandlerState<any, Payload, Model, USER, METADATA>) => Promise<CommandExecutionResponse<Model>>;
67
+ export type CommandPreProcessingFunction<USER = any, Model = any, Payload = any, METADATA = any> = (state: CommandHandlerState<any, Payload, Model, USER, METADATA>) => Payload | Promise<Payload>;
68
+ export type CommandHandlerFunction<Model = any, CommandPayload = unknown, Events extends Record<string, EventFactory<EVENT>> = any, EVENT extends Extract<keyof Events, string> = any, USER = any, METADATA = any> = (createEvent: CreateEventType<{
69
+ events: Events;
70
+ name: string;
71
+ }, EVENT>, state: Model extends undefined ? null : Model, data: CommandPayload, aggregateState: CommandHandlerState<Events, CommandPayload, any, USER, METADATA>) => Promise<EventFactory<EVENT, GetMessageType<Events[EVENT]>>[]> | EventFactory<EVENT, GetMessageType<Events[EVENT]>>[];
72
+ export type CommandErrorHandlerFunction<CommandPayload = unknown> = (error: AppError, data: CommandPayload) => Promise<any>;
73
+ /**
74
+ * How a command's stream handles CONCURRENCY. One field, three modes.
75
+ *
76
+ * | mode | asserted at the append | version column | conflicts when | who retries † |
77
+ * |---------------|------------------------|----------------|---------------------------|-------------|
78
+ * | `optimistic` | the LOAD-TIME head | head + 1 | the head moved since load | the library, by re-running the handler |
79
+ * | `rebase` | nothing (`undefined`) | head + 1 | two INSERTs actually collide | the library on the POOLED path; inside a caller-owned transaction, NOBODY — it propagates |
80
+ * | `unversioned` | `null` | `NULL` | never | nobody |
81
+ *
82
+ * † **"the library retries" is not unconditional — it is a property of the POOLED path.** A retry
83
+ * has to resume from a clean state, and inside a transaction the CALLER owns there is nothing to
84
+ * rewind unless a SAVEPOINT was taken first. `executeCommand` takes one only for `optimistic`
85
+ * (that is the only mode whose expectation another writer can invalidate), and only when the
86
+ * transaction implements the savepoint capability at all — MemoryDb and Mongo do not. Anywhere
87
+ * else, a conflict raised inside a caller-owned transaction is PROPAGATED to that transaction's
88
+ * owner, which is the only party that can end it; retrying there would re-execute the command on
89
+ * top of its own uncommitted rows. So a `rebase` command that hits a genuine INSERT collision
90
+ * inside `initTransaction( tx => executeCommand( …, tx )( … ))` surfaces `EVENTSTORE_VERSION_RACE`
91
+ * to its caller rather than being re-run. On the pooled path — no caller transaction — every mode
92
+ * in this table behaves exactly as the cell says.
93
+ *
94
+ * **`optimistic` is the default** and is what an aggregate wants: an aggregate is a consistency
95
+ * boundary, so a decision computed against state read at load time must not be committed onto a
96
+ * stream that moved underneath it.
97
+ *
98
+ * **`rebase` is ORDERING WITHOUT CONFLICT DETECTION — declare it only for provably COMMUTATIVE
99
+ * events.** It is a coherent thing to want ("give me strict per-stream ordering and real version
100
+ * numbers, retry me on a genuine collision, but do not invalidate my decision merely because
101
+ * somebody else wrote") and it is the pre-TV1-2238 behavior of every aggregate. It is therefore
102
+ * also the old lost-update wearing a name: two commands that both read balance 5 and both
103
+ * subtract 3 will both succeed here, and both callers are told they won. Reaching for it to
104
+ * silence a retry storm SILENTLY REINSTATES that. It is not free either — a true INSERT collision
105
+ * still raises a `ConcurrencyError`, and what happens next depends on where the command runs (†
106
+ * above): on the pooled path the library re-runs the handler, but inside a caller-owned
107
+ * transaction NO rewind point is taken for `rebase`, so the conflict propagates and the caller
108
+ * must handle it. Hosts that run commands inside their own transactions — bulk writes, item
109
+ * merge, batch editing — are exactly the ones tempted by `rebase`, and exactly the ones where it
110
+ * does not silently absorb a collision. If a stream is genuinely too hot, the answer is to
111
+ * re-model it (split the stream, or move the invariant off the write path), not to stop checking.
112
+ *
113
+ * **`unversioned` is NOT a choice an aggregate can make** and is refused with
114
+ * `UNVERSIONED_CONCURRENCY_ON_AGGREGATE`. An aggregate REDUCES its stream to state, and a stream
115
+ * whose events carry no version has no deterministic order to reduce in — the same events could
116
+ * fold to a different state on every load. It is what non-aggregate External Systems produce by
117
+ * construction (`version: NULL`, which the partial unique index
118
+ * `(stream, version) WHERE version IS NOT NULL` cannot conflict on), and it stays theirs.
119
+ */
120
+ export type CommandConcurrencyMode = 'optimistic' | 'rebase' | 'unversioned';
121
+ export type Command<EVENTS extends Record<string, EventFactory<EVENT>> = any, EVENT extends Extract<keyof EVENTS, string> = any, SystemModel = any, CommandPayload = any> = {
33
122
  schema: BaseSchema<CommandPayload>;
34
123
  handler: CommandHandlerFunction<SystemModel, CommandPayload, EVENTS, EVENT>;
35
124
  onErrorHandler?: CommandErrorHandlerFunction<CommandPayload>;
125
+ /**
126
+ * How this command's stream handles concurrency — see {@link CommandConcurrencyMode} for what
127
+ * each mode costs and what `rebase` gives up. Defaults to `optimistic`.
128
+ *
129
+ * Declared through the same object either way, because {@link CommandTemplate} is
130
+ * `Omit<Command, 'schema' | 'handler' | 'events'>`: `withCommandTemplate({ concurrency })` sets
131
+ * it for every command of an aggregate or external system, `commandBuilder({ concurrency })`
132
+ * sets or overrides it for one. There is no second, parallel field.
133
+ */
134
+ concurrency?: CommandConcurrencyMode;
36
135
  dataPropertyId?: string;
37
136
  name?: string;
38
137
  actors?: string[];
39
138
  description?: string;
40
- multipartProperties?: string[];
139
+ /** Required permissions for this command. If omitted, defaults to superAdmin-only access (secure by default). */
140
+ permissions?: PermissionString[];
141
+ /** Visibility of the command endpoint. Defaults to 'private' when not set. */
142
+ visibility?: 'public' | 'private' | 'internal';
41
143
  events?: EVENT[];
42
144
  invariants?: InvariantType[];
145
+ idempotencyChecks?: IdempotencyCheckType[];
43
146
  load?: CommandLoadFunction;
44
147
  commit?: CommandCommitFunction;
45
148
  format?: CommandFormatFunction;
149
+ preProcessing?: CommandPreProcessingFunction;
150
+ };
151
+ /**
152
+ * Subset of {@link Command} that the runtime accepts as a "template" — fields
153
+ * merged into every command of an aggregate or external system via
154
+ * `withCommandTemplate`. Excludes `schema`, `handler` and `events`, which are
155
+ * always provided per-command.
156
+ *
157
+ * Mirrors the runtime contract: `CommandBuilder` accepts exactly this shape
158
+ * (`Omit<Command, 'handler' | 'events' | 'schema'>`).
159
+ */
160
+ export type CommandTemplate<EVENTS extends Record<string, EventFactory<EVENT>> = any, EVENT extends Extract<keyof EVENTS, string> = any, SystemModel = any, CommandPayload = any> = Omit<Command<EVENTS, EVENT, SystemModel, CommandPayload>, 'schema' | 'handler' | 'events'>;
161
+ export type IdempotencyCheckType<Model = any, Payload = any, USER = any, METADATA = any> = {
162
+ check: (commandHandlerState: CommandHandlerState<any, Payload, Model, USER, METADATA>) => Promise<CommandHandlerState<any, Payload, Model, USER, METADATA> | void> | void | CommandHandlerState<any, Payload, Model, USER, METADATA>;
46
163
  };
47
- export type InvariantType<Model = any, Payload = any> = {
48
- events?: string[];
49
- rejects: AppErrorType[];
50
- beforeLoad?: (state: CommandHandlerState<any, Payload, Model>) => Promise<CommandHandlerState<any, Payload, Model>>;
51
- check: (commandHandlerState: CommandHandlerState<any, Payload, Model>) => Promise<CommandHandlerState<any, Payload, Model> | void> | void | CommandHandlerState<any, Payload, Model>;
164
+ export type InvariantType<Model = any, Payload = any, USER = any, METADATA = any> = IdempotencyCheckType<Model, Payload, USER, METADATA> & {
165
+ rejects: AppError[];
52
166
  };
53
167
  export declare const SystemGetQuerySchema: import("@bett3r-dev/jsonschema-definer").ObjectSchema<{
168
+ stream?: string | undefined;
169
+ names?: string[] | undefined;
170
+ from?: number | undefined;
54
171
  limit?: number | undefined;
172
+ backward?: boolean | undefined;
55
173
  after?: string | undefined;
56
- from?: number | undefined;
57
174
  before?: string | undefined;
58
- names?: string[] | undefined;
59
- backward?: boolean | undefined;
60
- stream: string;
61
175
  }, true>;
62
176
  export type SystemGetQueryType = typeof SystemGetQuerySchema.type;
63
177
  export declare const SystemEndpointParamsSchema: import("@bett3r-dev/jsonschema-definer").ObjectSchema<{
64
178
  id: string;
65
179
  }, true>;
66
180
  export declare const CommandEndpointQuerySchema: import("@bett3r-dev/jsonschema-definer").ObjectSchema<{
181
+ expectedVersion?: number | null | undefined;
67
182
  causationId?: string | undefined;
68
183
  correlationId?: string | undefined;
69
- expectedVersion?: string | undefined;
70
184
  }, true>;
71
185
  export type OnValidationErrorFunctionType = Function;
72
- export type System<Commands extends Record<string, Command | Builder<Command>> = any, EVENTS extends Record<string, EventFactory> = any> = {
73
- name: string;
186
+ export type System<Commands extends Record<string, Command | Builder<Command>> = any, EVENTS extends Record<string, EventFactory> = any> = Artifact & {
74
187
  events: EVENTS;
75
188
  isStreamable?: boolean;
76
189
  isAggregate?: boolean;
77
190
  isEventsourced?: boolean;
78
191
  commands: Commands;
79
- templateCommand: Command;
192
+ templateCommand: CommandTemplate;
80
193
  };
81
194
  export type AggregateReducedState<Model = any> = {
82
195
  state: Model;
83
- lastEvent?: Partial<Pick<CommittedEvent, 'id' | 'version'>>;
84
196
  };
197
+ export declare const ReducerNOOP: unique symbol;
85
198
  export type EventReducers<EVENTS extends Record<string, EventFactory> = any, Model = any> = {
86
- [Name in keyof EVENTS]: (state: Model, data: GetMessageType<EVENTS[Name]>, metadata: EventMetadata) => Partial<Model>;
199
+ [Name in keyof EVENTS]: ((state: Model, data: GetMessageType<EVENTS[Name]>, metadata: EventMetadataBaseType) => Partial<Model>) | typeof ReducerNOOP;
87
200
  };
88
201
  export type Aggregate<Commands extends Record<string, Command | Builder<Command>> = any, EVENTS extends Record<string, EventFactory> = any, Model = any> = System<Commands, EVENTS> & {
89
202
  schema: BaseSchema<Model>;
@@ -92,10 +205,19 @@ export type Aggregate<Commands extends Record<string, Command | Builder<Command>
92
205
  initialValue: () => Partial<Model> | null | undefined;
93
206
  eventReducers: EventReducers<EVENTS, Model>;
94
207
  };
95
- export type EventSourcingCommandHandlers = {
208
+ export type InstrumentCommandExecution = <T>(info: {
209
+ commandName: string;
210
+ aggregateName: string;
211
+ stream: string;
212
+ isAggregate: boolean;
213
+ correlationId?: string;
214
+ causationId?: string;
215
+ payload: any;
216
+ }, execute: () => Promise<T>) => Promise<T>;
217
+ export type EventSourcingCommandHandlers<USER = any> = {
96
218
  loadStream: (stream: string, options?: ReadStreamOptions) => Promise<CommittedEvent[] | undefined>;
97
- loadAggregateState: (system: System, stream?: string, options?: ReadStreamOptions) => Promise<Record<string, any> | null>;
98
- executeCommand: ExecuteCommandFunction;
219
+ loadAggregateState: <Model>(aggregate: Aggregate<any, any, Model>, stream?: string, options?: ReadStreamOptions) => Promise<AggregateReducedState<Model> | null>;
220
+ executeCommand: ExecuteCommandFunction<USER>;
99
221
  registerCommandHandlerGetEndpoints: (aggregateOrSystem: Aggregate | System, name?: string) => string[];
100
222
  registerCommandHandlerPostEndpoints: (aggregateOrSystem: (Aggregate | System) & {
101
223
  events: Record<string, EventFactory>;
@@ -1 +1 @@
1
- {"version":3,"file":"commandHandlers.d.ts","sourceRoot":"","sources":["../../src/eventsourcing/commandHandlers.ts"],"names":[],"mappings":"AAAA,OAAU,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAC5G,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEjF,MAAM,MAAM,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,GAAC,GAAG,EAAE,KAAK,GAAG,GAAG,EAAE,IAAI,GAAC,GAAG,IAAI;IAC3G,cAAc,EAAE,SAAS,GAAG,MAAM,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CA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,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,GAAG,CAAC;CACd,EACD,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACtB,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,MAAM,4BAA4B,CAAC,IAAI,GAAG,GAAG,IAAI;IACrD,UAAU,EAAE,CACV,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC,cAAc,EAAE,GAAG,SAAS,CAAC,CAAC;IAC3C,kBAAkB,EAAE,CAAC,KAAK,EACxB,SAAS,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EACrC,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IAClD,cAAc,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC7C,kCAAkC,EAAE,CAClC,iBAAiB,EAAE,SAAS,GAAG,MAAM,EACrC,IAAI,CAAC,EAAE,MAAM,KACV,MAAM,EAAE,CAAC;IACd,mCAAmC,EAAE,CACnC,iBAAiB,EAAE,CAAE,SAAS,GAAG,MAAM,CAAE,GAAG;QAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;KACtC,EACD,IAAI,CAAC,EAAE,MAAM,KACV,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B,CAAC"}
@@ -1,28 +1,76 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CommandEndpointQuerySchema = exports.SystemEndpointParamsSchema = exports.SystemGetQuerySchema = void 0;
7
- const jsonschema_definer_1 = __importDefault(require("@bett3r-dev/jsonschema-definer"));
36
+ exports.ReducerNOOP = exports.CommandEndpointQuerySchema = exports.SystemEndpointParamsSchema = exports.SystemGetQuerySchema = void 0;
37
+ const jsonschema_definer_1 = __importStar(require("@bett3r-dev/jsonschema-definer"));
38
+ const eventsourcing_types_1 = require("./eventsourcing.types");
8
39
  //*******************************************
9
40
  // Systems
10
41
  //*******************************************
11
42
  exports.SystemGetQuerySchema = jsonschema_definer_1.default.shape({
12
- stream: jsonschema_definer_1.default.string(),
13
- names: jsonschema_definer_1.default.array().items(jsonschema_definer_1.default.string()).optional(),
43
+ stream: jsonschema_definer_1.default.string().optional(),
44
+ names: jsonschema_definer_1.default.array().items(jsonschema_definer_1.default.string())
45
+ .optional(),
14
46
  from: jsonschema_definer_1.default.number().optional(),
15
47
  limit: jsonschema_definer_1.default.number().optional(),
16
48
  backward: jsonschema_definer_1.default.boolean().optional(),
17
- after: jsonschema_definer_1.default.string().format('date-time').optional(),
18
- before: jsonschema_definer_1.default.string().format('date-time').optional(),
49
+ after: jsonschema_definer_1.default.string().format('date-time')
50
+ .optional(),
51
+ before: jsonschema_definer_1.default.string().format('date-time')
52
+ .optional()
19
53
  });
20
54
  exports.SystemEndpointParamsSchema = jsonschema_definer_1.default.shape({
21
55
  id: jsonschema_definer_1.default.string().description('id for the aggregate')
22
56
  });
23
- exports.CommandEndpointQuerySchema = jsonschema_definer_1.default.shape({
24
- expectedVersion: jsonschema_definer_1.default.string().optional(),
25
- causationId: jsonschema_definer_1.default.string().optional(),
26
- correlationId: jsonschema_definer_1.default.string().optional(),
27
- });
57
+ // Strict by design. mergeSchemas takes EventMetadataBaseSchema (which is
58
+ // additionalProperties:true, to allow arbitrary event metadata) as master, so
59
+ // the merged query schema would inherit `true`. We pin `false` explicitly so an
60
+ // unknown command query param — e.g. the removed `retryOnConcurrencyError`
61
+ // decoy (native OCC retry is now automatic at the eventstore boundary) — is a
62
+ // clean 400, not a silently-ignored 200. correlationId/causationId are stripped
63
+ // as infra params before this schema validates (see validateEndpoint).
64
+ exports.CommandEndpointQuerySchema = (0, jsonschema_definer_1.mergeSchemas)(eventsourcing_types_1.EventMetadataBaseSchema, jsonschema_definer_1.default.shape({
65
+ // Numeric, NOT string: the eventstore compares expectedVersion with `===` to a
66
+ // numeric actualVersion (validateExpectedVersion), so a string would never match
67
+ // ("1" !== 1) — making the OCC "1 winner + N-1 conflicts" path unreachable through
68
+ // executeCommand. Command endpoints validate the query with coerceTypes:true (see
69
+ // validateEndpoint at :498), so the wire query-string `?expectedVersion=1` is
70
+ // coerced to the number 1 here; a non-numeric value is a clean 400. This also
71
+ // matches CommandHandlerState.expectedVersion, already typed `number | null`.
72
+ expectedVersion: jsonschema_definer_1.default.number().nullable()
73
+ .optional()
74
+ })).additionalProperties(false);
75
+ exports.ReducerNOOP = Symbol('ReducerNOOP');
28
76
  //# sourceMappingURL=commandHandlers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commandHandlers.js","sourceRoot":"","sources":["../../src/eventsourcing/commandHandlers.ts"],"names":[],"mappings":";;;;;;AAAA,wFAA+D;AA0D/D,6CAA6C;AAC7C,UAAU;AACV,6CAA6C;AAEhC,QAAA,oBAAoB,GAAG,4BAAC,CAAC,KAAK,CAAC;IAC1C,MAAM,EAAE,4BAAC,CAAC,MAAM,EAAE;IAClB,KAAK,EAAE,4BAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC9C,IAAI,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,KAAK,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,4BAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAChC,KAAK,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAE,WAAW,CAAE,CAAC,QAAQ,EAAE;IAClD,MAAM,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAE,WAAW,CAAE,CAAC,QAAQ,EAAE;CACpD,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,4BAAC,CAAC,KAAK,CAAC;IAChD,EAAE,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,WAAW,CAAE,sBAAsB,CAAE;CACrD,CAAC,CAAC;AACU,QAAA,0BAA0B,GAAG,4BAAC,CAAC,KAAK,CAAC;IAChD,eAAe,EAAE,4BAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACtC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