@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 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<TState extends JsonValue = JsonValue> {
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<TState>;
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
- export interface CommandCommitted<TState extends JsonValue = JsonValue> {
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<TState extends JsonValue = JsonValue> {
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<TState extends JsonValue = JsonValue> = CommandDone<TState> | Omit<CommandNoop, "events"> | Omit<CommandRejected, "events">;
156
- export type CommandOutcome<TState extends JsonValue = JsonValue> = CommandCommitted<TState> | CommandNoop | CommandRejected;
157
- export declare const done: <TState extends JsonValue = JsonValue>(value?: JsonValue, state?: TState) => CommandDone<TState>;
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, TState extends JsonValue = JsonValue> = (input: TInput, context: CommandContext<TState>) => CommandHandlerOutcome<TState>;
162
- export interface CommandDefinition<TInput = unknown, TState extends JsonValue = JsonValue> {
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<TState>;
169
- readonly handle: CommandDefinition<TInput, TState>["execute"];
167
+ }) => CommandOutcome;
168
+ readonly handle: CommandDefinition<TInput>["execute"];
170
169
  }
171
- export type CommandDefinitionOptions<TInput, TState extends JsonValue = JsonValue> = {
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, TState>;
176
+ readonly handler: CommandHandler<TInput>;
178
177
  };
179
- export declare function defineCommand<TInput, TState extends JsonValue = JsonValue>(options: CommandDefinitionOptions<TInput, TState>): CommandDefinition<TInput, TState>;
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, state) => Object.freeze({ kind: "committed", value, state });
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") return Object.freeze({ ...outcome, events: Object.freeze([...appended]) });
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;
@@ -1,4 +1,4 @@
1
- import { assertJsonValue } from "./index";
1
+ import { assertJsonValue } from "./index.js";
2
2
  function nonEmpty(value, code, message) {
3
3
  if (typeof value !== "string" || value.length === 0)
4
4
  throw new Error(`${code}: ${message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sekiban/dcb-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "Cloudflare-independent Serialized DCB definitions and domain algebra.",
6
6
  "license": "Elastic-2.0",