@sekiban/dcb-client 0.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.
- package/LICENSE +90 -0
- package/README.md +14 -0
- package/dist/executor.d.ts +75 -0
- package/dist/executor.js +515 -0
- package/dist/index.d.ts +209 -0
- package/dist/index.js +15618 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { AppendedEvent, CommandDefinition, CommandOutcome, EventDefinition, JsonValue, TagDefinition, TagInput } from "@sekiban/dcb-core";
|
|
2
|
+
export interface ReadonlyTagStateResponse {
|
|
3
|
+
readonly payload: JsonValue;
|
|
4
|
+
readonly version: number;
|
|
5
|
+
readonly lastSortedUniqueId: string;
|
|
6
|
+
readonly tagGroup: string;
|
|
7
|
+
readonly tagContent: string;
|
|
8
|
+
readonly tagProjector: string;
|
|
9
|
+
readonly tagPayloadName?: string;
|
|
10
|
+
/** Runtime tag-state responses serialize projectorVersion as a string. */
|
|
11
|
+
readonly projectorVersion?: string;
|
|
12
|
+
}
|
|
13
|
+
export type TagStateSnapshot = ReadonlyTagStateResponse & {
|
|
14
|
+
readonly tag: string;
|
|
15
|
+
readonly tagStateId: string;
|
|
16
|
+
};
|
|
17
|
+
export interface CommitCandidate {
|
|
18
|
+
readonly eventId: string;
|
|
19
|
+
readonly eventPayloadName: string;
|
|
20
|
+
readonly payload: JsonValue;
|
|
21
|
+
readonly tags: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
export interface ConsistencyEntry {
|
|
24
|
+
readonly tag: string;
|
|
25
|
+
/** §3.1 commit-envelope spelling; §5.3 tag-state keeps lastSortedUniqueId. */
|
|
26
|
+
readonly lastSortableUniqueId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface CommitEnvelope {
|
|
29
|
+
readonly candidates: readonly CommitCandidate[];
|
|
30
|
+
readonly consistency: readonly ConsistencyEntry[];
|
|
31
|
+
readonly [key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface CommitHttpResult {
|
|
34
|
+
readonly status: number;
|
|
35
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
36
|
+
readonly body?: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface TagLatestSortableResponse {
|
|
39
|
+
readonly exists: boolean;
|
|
40
|
+
readonly lastSortableUniqueId: string;
|
|
41
|
+
}
|
|
42
|
+
export interface QueryRequest {
|
|
43
|
+
readonly queryType: string;
|
|
44
|
+
readonly queryParamsJson: string;
|
|
45
|
+
readonly waitForSortableUniqueId?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface QueryResponse {
|
|
48
|
+
readonly resultJson: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ListQueryRequest extends QueryRequest {
|
|
51
|
+
readonly queryParamsJson: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ListQueryResponse {
|
|
54
|
+
readonly itemsJson: string;
|
|
55
|
+
readonly totalCount: number;
|
|
56
|
+
readonly totalPages: number;
|
|
57
|
+
readonly currentPage: number;
|
|
58
|
+
readonly pageSize: number;
|
|
59
|
+
}
|
|
60
|
+
export interface SerializedDcbTransport {
|
|
61
|
+
readonly readTagState: (request: {
|
|
62
|
+
readonly tagStateId: string;
|
|
63
|
+
}, signal?: AbortSignal) => Promise<ReadonlyTagStateResponse | CommitHttpResult>;
|
|
64
|
+
readonly readTagLatestSortable?: (request: {
|
|
65
|
+
readonly tag: string;
|
|
66
|
+
}, signal?: AbortSignal) => Promise<TagLatestSortableResponse | CommitHttpResult>;
|
|
67
|
+
readonly commit: (request: CommitEnvelope, signal?: AbortSignal) => Promise<unknown | CommitHttpResult>;
|
|
68
|
+
/** G57 makes the two read-only query endpoints part of every transport. */
|
|
69
|
+
readonly query: (request: QueryRequest, signal?: AbortSignal) => Promise<QueryResponse | CommitHttpResult>;
|
|
70
|
+
readonly listQuery: (request: ListQueryRequest, signal?: AbortSignal) => Promise<ListQueryResponse | CommitHttpResult>;
|
|
71
|
+
/** Optional identity supplied by a transport that is already scoped. */
|
|
72
|
+
readonly serviceId?: string;
|
|
73
|
+
}
|
|
74
|
+
export declare class ClientError extends Error {
|
|
75
|
+
readonly code: string;
|
|
76
|
+
readonly status?: number;
|
|
77
|
+
readonly partial?: unknown;
|
|
78
|
+
constructor(code: string, message: string, options?: {
|
|
79
|
+
readonly status?: number;
|
|
80
|
+
readonly partial?: unknown;
|
|
81
|
+
readonly cause?: unknown;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export declare class SerializedDcbClient implements SerializedDcbTransport {
|
|
85
|
+
readonly baseUrl: string;
|
|
86
|
+
private readonly fetchImpl;
|
|
87
|
+
constructor(baseUrl: string, fetchImpl?: typeof fetch);
|
|
88
|
+
readTagState(request: {
|
|
89
|
+
readonly tagStateId: string;
|
|
90
|
+
}, signal?: AbortSignal): Promise<ReadonlyTagStateResponse>;
|
|
91
|
+
readTagLatestSortable(request: {
|
|
92
|
+
readonly tag: string;
|
|
93
|
+
}, signal?: AbortSignal): Promise<TagLatestSortableResponse>;
|
|
94
|
+
query(request: QueryRequest, signal?: AbortSignal): Promise<QueryResponse>;
|
|
95
|
+
listQuery(request: ListQueryRequest, signal?: AbortSignal): Promise<ListQueryResponse>;
|
|
96
|
+
readonly tagLatestSortable: (request: {
|
|
97
|
+
readonly tag: string;
|
|
98
|
+
}, signal?: AbortSignal) => Promise<TagLatestSortableResponse>;
|
|
99
|
+
readonly tagState: (request: {
|
|
100
|
+
readonly tagStateId: string;
|
|
101
|
+
}, signal?: AbortSignal) => Promise<ReadonlyTagStateResponse>;
|
|
102
|
+
commit(request: CommitEnvelope, signal?: AbortSignal): Promise<unknown>;
|
|
103
|
+
private readResponse;
|
|
104
|
+
}
|
|
105
|
+
export declare class ClaimLedger {
|
|
106
|
+
private readonly snapshotsByStateId;
|
|
107
|
+
private readonly snapshotsByTag;
|
|
108
|
+
private readonly transport;
|
|
109
|
+
constructor(transport: SerializedDcbTransport);
|
|
110
|
+
readTagState(tagStateId: string, signal?: AbortSignal): Promise<TagStateSnapshot>;
|
|
111
|
+
readTagState(tag: TagInput, projector: string, signal?: AbortSignal): Promise<TagStateSnapshot>;
|
|
112
|
+
read(tagStateId: string, signal?: AbortSignal): Promise<TagStateSnapshot>;
|
|
113
|
+
get snapshots(): readonly TagStateSnapshot[];
|
|
114
|
+
clear(): void;
|
|
115
|
+
}
|
|
116
|
+
export interface PreflightInput {
|
|
117
|
+
readonly candidates: readonly Pick<CommitCandidate, "tags">[];
|
|
118
|
+
readonly consistency: readonly ConsistencyEntry[];
|
|
119
|
+
readonly claims: readonly Pick<TagStateSnapshot, "tag" | "lastSortedUniqueId">[];
|
|
120
|
+
}
|
|
121
|
+
/** Validate the commit envelope before any transport call. */
|
|
122
|
+
export declare function preflightCommit(input: PreflightInput): void;
|
|
123
|
+
export interface ClientCommandContext {
|
|
124
|
+
readonly readTagState: (tagStateId: string, signal?: AbortSignal) => Promise<TagStateSnapshot>;
|
|
125
|
+
readonly state: (tagStateId: string, signal?: AbortSignal) => Promise<JsonValue | undefined>;
|
|
126
|
+
readonly assertEmpty: (tagStateId: string, signal?: AbortSignal) => Promise<void>;
|
|
127
|
+
readonly append: (event: EventDefinition | string, payload: unknown, tags: readonly TagInput[]) => CommitCandidate;
|
|
128
|
+
readonly claims: readonly TagStateSnapshot[];
|
|
129
|
+
readonly candidates: readonly CommitCandidate[];
|
|
130
|
+
}
|
|
131
|
+
export type ClientCommandDecision = {
|
|
132
|
+
readonly kind: "committed" | "done";
|
|
133
|
+
readonly value?: JsonValue;
|
|
134
|
+
readonly envelope?: Partial<CommitEnvelope>;
|
|
135
|
+
} | {
|
|
136
|
+
readonly kind: "noop";
|
|
137
|
+
readonly reason?: string;
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "rejected";
|
|
140
|
+
readonly error: string;
|
|
141
|
+
readonly code?: string;
|
|
142
|
+
} | {
|
|
143
|
+
readonly kind: "invalid";
|
|
144
|
+
readonly error: string;
|
|
145
|
+
readonly code?: string;
|
|
146
|
+
};
|
|
147
|
+
export interface ExecuteOptions {
|
|
148
|
+
readonly input?: unknown;
|
|
149
|
+
readonly maxConflictRetries?: number;
|
|
150
|
+
readonly signal?: AbortSignal;
|
|
151
|
+
readonly totalBudgetMs?: number;
|
|
152
|
+
}
|
|
153
|
+
export interface ExecuteCommon {
|
|
154
|
+
readonly attempts: number;
|
|
155
|
+
readonly status?: number;
|
|
156
|
+
readonly code?: string;
|
|
157
|
+
readonly error?: string;
|
|
158
|
+
readonly cause?: unknown;
|
|
159
|
+
}
|
|
160
|
+
export interface ExecuteCommitted extends ExecuteCommon {
|
|
161
|
+
readonly kind: "committed";
|
|
162
|
+
readonly response: unknown;
|
|
163
|
+
}
|
|
164
|
+
export interface ExecuteNoop extends ExecuteCommon {
|
|
165
|
+
readonly kind: "noop";
|
|
166
|
+
readonly reason?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface ExecuteRejected extends ExecuteCommon {
|
|
169
|
+
readonly kind: "rejected";
|
|
170
|
+
readonly error: string;
|
|
171
|
+
}
|
|
172
|
+
export interface ExecuteConflict extends ExecuteCommon {
|
|
173
|
+
readonly kind: "conflict";
|
|
174
|
+
readonly response?: unknown;
|
|
175
|
+
}
|
|
176
|
+
export interface ExecutePartial extends ExecuteCommon {
|
|
177
|
+
readonly kind: "partial";
|
|
178
|
+
readonly partial: unknown;
|
|
179
|
+
}
|
|
180
|
+
export interface ExecuteTimeout extends ExecuteCommon {
|
|
181
|
+
readonly kind: "timeout";
|
|
182
|
+
}
|
|
183
|
+
export interface ExecuteUnavailable extends ExecuteCommon {
|
|
184
|
+
readonly kind: "unavailable";
|
|
185
|
+
}
|
|
186
|
+
export interface ExecuteTransport extends ExecuteCommon {
|
|
187
|
+
readonly kind: "transport";
|
|
188
|
+
}
|
|
189
|
+
export interface ExecuteInvalid extends ExecuteCommon {
|
|
190
|
+
readonly kind: "invalid";
|
|
191
|
+
}
|
|
192
|
+
export type ExecuteResult = ExecuteCommitted | ExecuteNoop | ExecuteRejected | ExecuteConflict | ExecutePartial | ExecuteTimeout | ExecuteUnavailable | ExecuteTransport | ExecuteInvalid;
|
|
193
|
+
export interface ClaimLedgerExecutorOptions {
|
|
194
|
+
readonly transport: SerializedDcbTransport;
|
|
195
|
+
readonly maxConflictRetries?: number;
|
|
196
|
+
readonly totalBudgetMs?: number;
|
|
197
|
+
}
|
|
198
|
+
type CommandLike = ((context: ClientCommandContext, input?: unknown) => ClientCommandDecision | Promise<ClientCommandDecision>) | CommandDefinition;
|
|
199
|
+
export declare class ClaimLedgerExecutor {
|
|
200
|
+
private readonly transport;
|
|
201
|
+
private readonly defaultRetries;
|
|
202
|
+
private readonly defaultBudget?;
|
|
203
|
+
constructor(options: ClaimLedgerExecutorOptions);
|
|
204
|
+
execute(command: CommandLike, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
205
|
+
}
|
|
206
|
+
export declare const createClaimLedgerExecutor: (options: ClaimLedgerExecutorOptions) => ClaimLedgerExecutor;
|
|
207
|
+
export declare const createSerializedDcbClient: (baseUrl: string, fetchImpl?: typeof fetch) => SerializedDcbClient;
|
|
208
|
+
export type { AppendedEvent, CommandDefinition, CommandOutcome, EventDefinition, JsonValue, TagDefinition, TagInput };
|
|
209
|
+
export * from "./executor.js";
|