@sekiban/dcb-core 0.1.0 → 0.2.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.
- package/dist/index.d.ts +15 -16
- package/dist/index.js +4 -2
- package/dist/materializedView.d.ts +1 -1
- package/dist/materializedView.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -121,25 +121,24 @@ export interface AppendedEvent {
|
|
|
121
121
|
readonly payload: JsonValue;
|
|
122
122
|
readonly tags: readonly TagDefinition[];
|
|
123
123
|
}
|
|
124
|
-
export interface CommandContext
|
|
124
|
+
export interface CommandContext {
|
|
125
125
|
readonly state: <T extends JsonValue = JsonValue>(tag: TagInput) => T | undefined;
|
|
126
126
|
readonly assertEmpty: (tag: TagInput) => void;
|
|
127
127
|
readonly append: (event: EventDefinition, payload: unknown, tags?: readonly TagInput[]) => AppendedEvent;
|
|
128
|
-
readonly done: (value?: JsonValue) => CommandDone
|
|
128
|
+
readonly done: (value?: JsonValue) => CommandDone;
|
|
129
129
|
readonly noop: (reason?: string) => Omit<CommandNoop, "events">;
|
|
130
130
|
readonly reject: (reason: string, code?: string) => Omit<CommandRejected, "events">;
|
|
131
131
|
readonly appendedEvents: readonly AppendedEvent[];
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
/** `done` commits the appended candidates with an optional value; it carries no state. */
|
|
134
|
+
export interface CommandCommitted {
|
|
134
135
|
readonly kind: "committed";
|
|
135
136
|
readonly value?: JsonValue;
|
|
136
|
-
readonly state?: TState;
|
|
137
137
|
readonly events: readonly AppendedEvent[];
|
|
138
138
|
}
|
|
139
|
-
export interface CommandDone
|
|
139
|
+
export interface CommandDone {
|
|
140
140
|
readonly kind: "committed";
|
|
141
141
|
readonly value?: JsonValue;
|
|
142
|
-
readonly state?: TState;
|
|
143
142
|
}
|
|
144
143
|
export interface CommandNoop {
|
|
145
144
|
readonly kind: "noop";
|
|
@@ -152,31 +151,31 @@ export interface CommandRejected {
|
|
|
152
151
|
readonly code: string;
|
|
153
152
|
readonly events: readonly [];
|
|
154
153
|
}
|
|
155
|
-
export type CommandHandlerOutcome
|
|
156
|
-
export type CommandOutcome
|
|
157
|
-
export declare const done:
|
|
154
|
+
export type CommandHandlerOutcome = CommandDone | Omit<CommandNoop, "events"> | Omit<CommandRejected, "events">;
|
|
155
|
+
export type CommandOutcome = CommandCommitted | CommandNoop | CommandRejected;
|
|
156
|
+
export declare const done: (value?: JsonValue) => CommandDone;
|
|
158
157
|
export declare const noop: (reason?: string) => CommandNoop;
|
|
159
158
|
export declare const reject: (reason: string, code?: string) => CommandRejected;
|
|
160
159
|
export type CommandInputParser<TInput> = (input: unknown) => TInput;
|
|
161
|
-
export type CommandHandler<TInput
|
|
162
|
-
export interface CommandDefinition<TInput = unknown
|
|
160
|
+
export type CommandHandler<TInput> = (input: TInput, context: CommandContext) => CommandHandlerOutcome;
|
|
161
|
+
export interface CommandDefinition<TInput = unknown> {
|
|
163
162
|
readonly id: string;
|
|
164
163
|
readonly name: string;
|
|
165
164
|
readonly parseInput: (input: unknown) => TInput;
|
|
166
165
|
readonly execute: (input: unknown, options?: {
|
|
167
166
|
readonly state?: Readonly<Record<string, JsonValue>>;
|
|
168
|
-
}) => CommandOutcome
|
|
169
|
-
readonly handle: CommandDefinition<TInput
|
|
167
|
+
}) => CommandOutcome;
|
|
168
|
+
readonly handle: CommandDefinition<TInput>["execute"];
|
|
170
169
|
}
|
|
171
|
-
export type CommandDefinitionOptions<TInput
|
|
170
|
+
export type CommandDefinitionOptions<TInput> = {
|
|
172
171
|
readonly id?: string;
|
|
173
172
|
readonly name?: string;
|
|
174
173
|
readonly parseInput?: CommandInputParser<TInput>;
|
|
175
174
|
readonly inputParser?: CommandInputParser<TInput>;
|
|
176
175
|
readonly input?: CommandInputParser<TInput>;
|
|
177
|
-
readonly handler: CommandHandler<TInput
|
|
176
|
+
readonly handler: CommandHandler<TInput>;
|
|
178
177
|
};
|
|
179
|
-
export declare function defineCommand<TInput
|
|
178
|
+
export declare function defineCommand<TInput>(options: CommandDefinitionOptions<TInput>): CommandDefinition<TInput>;
|
|
180
179
|
export interface DomainComponentDefinition {
|
|
181
180
|
readonly id?: string;
|
|
182
181
|
readonly name?: string;
|
package/dist/index.js
CHANGED
|
@@ -355,7 +355,7 @@ function defineProjector(options) {
|
|
|
355
355
|
deserializeState
|
|
356
356
|
});
|
|
357
357
|
}
|
|
358
|
-
var done = (value
|
|
358
|
+
var done = (value) => Object.freeze({ kind: "committed", value });
|
|
359
359
|
var noop = (reason) => Object.freeze({ kind: "noop", reason, events: [] });
|
|
360
360
|
var reject = (reason, code = "command_rejected") => Object.freeze({ kind: "rejected", reason, code, events: [] });
|
|
361
361
|
function defineCommand(options) {
|
|
@@ -395,7 +395,9 @@ function defineCommand(options) {
|
|
|
395
395
|
if (!outcome || typeof outcome !== "object" || !["committed", "noop", "rejected"].includes(outcome.kind)) {
|
|
396
396
|
throw new DcbDefinitionError("COMMAND_OUTCOME_INVALID", `Command ${id} must return done, noop, or reject`);
|
|
397
397
|
}
|
|
398
|
-
if (outcome.kind === "committed")
|
|
398
|
+
if (outcome.kind === "committed") {
|
|
399
|
+
return Object.freeze({ kind: "committed", value: outcome.value, events: Object.freeze([...appended]) });
|
|
400
|
+
}
|
|
399
401
|
if (appended.length > 0) throw new DcbDefinitionError("COMMAND_EVENTS_WITHOUT_COMMIT", `Command ${id} appended events but did not return done`);
|
|
400
402
|
return outcome.kind === "noop" ? Object.freeze({ ...outcome, events: [] }) : Object.freeze({ ...outcome, events: [] });
|
|
401
403
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type JsonValue } from "./index";
|
|
1
|
+
import { type JsonValue } from "./index.js";
|
|
2
2
|
/** The only scalar representations that may be persisted in an MV index. */
|
|
3
3
|
export type MaterializedViewIndexValueType = "text" | "integer" | "real";
|
|
4
4
|
export type MaterializedViewIndexValue = string | number;
|
package/dist/materializedView.js
CHANGED