@zlooks.cn/event-client 1.0.1
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 +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +195 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +113 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +32 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +33 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ExecutionContext, type InvocationContext } from '@hile/context';
|
|
2
|
+
import type { DomainEvent, EventDefinition } from '@zlooks.cn/event-bus';
|
|
3
|
+
export * from './protocol.js';
|
|
4
|
+
export interface EventMicroCaller {
|
|
5
|
+
call(namespace: string, operation: string, data: unknown, options: Readonly<{
|
|
6
|
+
context: ExecutionContext;
|
|
7
|
+
timeout: number;
|
|
8
|
+
retries: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}>): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface EventSubscription {
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface DomainEventPublisher {
|
|
16
|
+
publish(event: DomainEvent<string, unknown>, signal?: AbortSignal): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface EventConsumeOptions<TEvent> {
|
|
19
|
+
readonly subscriptionId: string;
|
|
20
|
+
readonly handle: (event: TEvent, invocation: InvocationContext) => void | Promise<void>;
|
|
21
|
+
readonly concurrency?: number;
|
|
22
|
+
readonly leaseMs?: number;
|
|
23
|
+
readonly pollIntervalMs?: number;
|
|
24
|
+
readonly onError?: (error: unknown) => void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface EventConsumer {
|
|
27
|
+
consume<TType extends string, TData>(definition: EventDefinition<TType, TData>, options: EventConsumeOptions<DomainEvent<TType, TData>>): EventSubscription;
|
|
28
|
+
}
|
|
29
|
+
export declare class EventClient implements EventConsumer {
|
|
30
|
+
#private;
|
|
31
|
+
private readonly application;
|
|
32
|
+
constructor(application: EventMicroCaller, options?: {
|
|
33
|
+
readonly instanceId?: string;
|
|
34
|
+
});
|
|
35
|
+
publish<TType extends string, TData>(definition: EventDefinition<TType, TData>, input: unknown, context: ExecutionContext, signal?: AbortSignal): Promise<DomainEvent<TType, TData>>;
|
|
36
|
+
publishEvent(eventInput: unknown, context: ExecutionContext, signal?: AbortSignal): Promise<DomainEvent<string, unknown>>;
|
|
37
|
+
consume<TType extends string, TData>(definition: EventDefinition<TType, TData>, options: EventConsumeOptions<DomainEvent<TType, TData>>): EventSubscription;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export declare class ContextualEventPublisher implements DomainEventPublisher {
|
|
41
|
+
private readonly client;
|
|
42
|
+
private readonly context;
|
|
43
|
+
constructor(client: EventClient, context: () => ExecutionContext);
|
|
44
|
+
publish(event: DomainEvent<string, unknown>, signal?: AbortSignal): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAkD,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC9H,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AASzE,cAAc,eAAe,CAAC;AAE9B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC1E,OAAO,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,C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AAE,KAAK,EAC9C,UAAU,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,WAAW,GACzG,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAOpC;IAEY,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAMrI;IAEM,OAAO,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,EACxC,UAAU,EAAE,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,mBAAmB,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,GACjG,iBAAiB,CAOnB;IAEY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAElC;CACF;AAED,qBAAa,wBAAyB,YAAW,oBAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAe,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAjF,YAAoC,MAAM,EAAE,WAAW,EAAmB,OAAO,EAAE,MAAM,gBAAgB,EAAI;IAChG,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7F;CACF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createInvocationContext, parseExecutionContext } from '@hile/context';
|
|
3
|
+
import { ackRequestSchema, claimRequestSchema, claimResponseSchema, deliveryMutationResponseSchema, ensureSubscriptionRequestSchema, ensureSubscriptionResponseSchema, EVENT_ACK_OPERATION, EVENT_CLAIM_OPERATION, EVENT_FAIL_OPERATION, EVENT_PUBLISH_OPERATION, EVENT_RENEW_OPERATION, EVENT_SERVICE_NAMESPACE, EVENT_SUBSCRIBE_OPERATION, failRequestSchema, publishRequestSchema, publishResponseSchema, renewRequestSchema, } from './protocol.js';
|
|
4
|
+
export * from './protocol.js';
|
|
5
|
+
export class EventClient {
|
|
6
|
+
application;
|
|
7
|
+
#instanceId;
|
|
8
|
+
#subscriptions = new Set();
|
|
9
|
+
constructor(application, options = {}) {
|
|
10
|
+
this.application = application;
|
|
11
|
+
this.#instanceId = options.instanceId ?? `event-client-${randomUUID()}`;
|
|
12
|
+
}
|
|
13
|
+
async publish(definition, input, context, signal) {
|
|
14
|
+
const event = definition.parse(input);
|
|
15
|
+
const request = publishRequestSchema.parse({ event });
|
|
16
|
+
publishResponseSchema.parse(await this.application.call(EVENT_SERVICE_NAMESPACE, EVENT_PUBLISH_OPERATION, request, {
|
|
17
|
+
context: parseExecutionContext(context), timeout: 5_000, retries: 2, ...(signal ? { signal } : {}),
|
|
18
|
+
}));
|
|
19
|
+
return event;
|
|
20
|
+
}
|
|
21
|
+
async publishEvent(eventInput, context, signal) {
|
|
22
|
+
const { event } = publishRequestSchema.parse({ event: eventInput });
|
|
23
|
+
publishResponseSchema.parse(await this.application.call(EVENT_SERVICE_NAMESPACE, EVENT_PUBLISH_OPERATION, { event }, {
|
|
24
|
+
context: parseExecutionContext(context), timeout: 5_000, retries: 2, ...(signal ? { signal } : {}),
|
|
25
|
+
}));
|
|
26
|
+
return event;
|
|
27
|
+
}
|
|
28
|
+
consume(definition, options) {
|
|
29
|
+
const subscription = new ClientSubscription(this.application, this.#instanceId, definition, options, () => {
|
|
30
|
+
this.#subscriptions.delete(subscription);
|
|
31
|
+
});
|
|
32
|
+
this.#subscriptions.add(subscription);
|
|
33
|
+
subscription.start();
|
|
34
|
+
return subscription;
|
|
35
|
+
}
|
|
36
|
+
async close() {
|
|
37
|
+
await Promise.all([...this.#subscriptions].map((subscription) => subscription.close()));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class ContextualEventPublisher {
|
|
41
|
+
client;
|
|
42
|
+
context;
|
|
43
|
+
constructor(client, context) {
|
|
44
|
+
this.client = client;
|
|
45
|
+
this.context = context;
|
|
46
|
+
}
|
|
47
|
+
async publish(event, signal) {
|
|
48
|
+
await this.client.publishEvent(event, this.context(), signal);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class ClientSubscription {
|
|
52
|
+
application;
|
|
53
|
+
instanceId;
|
|
54
|
+
definition;
|
|
55
|
+
options;
|
|
56
|
+
onClose;
|
|
57
|
+
#controller = new AbortController();
|
|
58
|
+
#done;
|
|
59
|
+
constructor(application, instanceId, definition, options, onClose) {
|
|
60
|
+
this.application = application;
|
|
61
|
+
this.instanceId = instanceId;
|
|
62
|
+
this.definition = definition;
|
|
63
|
+
this.options = options;
|
|
64
|
+
this.onClose = onClose;
|
|
65
|
+
this.#done = this.run();
|
|
66
|
+
}
|
|
67
|
+
start() { void this.#done.catch((error) => this.reportError(error)); }
|
|
68
|
+
async close() { this.#controller.abort(); await this.#done.catch(() => undefined); this.onClose(); }
|
|
69
|
+
async run() {
|
|
70
|
+
const context = parseExecutionContext({ version: 1, values: {} });
|
|
71
|
+
const subscription = ensureSubscriptionRequestSchema.parse({ subscriptionId: this.options.subscriptionId, eventType: this.definition.type });
|
|
72
|
+
const claim = claimRequestSchema.parse({
|
|
73
|
+
...subscription, instanceId: this.instanceId,
|
|
74
|
+
limit: this.options.concurrency ?? 8, leaseMs: this.options.leaseMs ?? 30_000,
|
|
75
|
+
});
|
|
76
|
+
let registered = false;
|
|
77
|
+
while (!this.#controller.signal.aborted) {
|
|
78
|
+
try {
|
|
79
|
+
if (!registered) {
|
|
80
|
+
ensureSubscriptionResponseSchema.parse(await this.call(EVENT_SUBSCRIBE_OPERATION, subscription, context));
|
|
81
|
+
registered = true;
|
|
82
|
+
}
|
|
83
|
+
let claimResponse;
|
|
84
|
+
try {
|
|
85
|
+
claimResponse = await this.call(EVENT_CLAIM_OPERATION, claim, context, 0);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (this.#controller.signal.aborted)
|
|
89
|
+
break;
|
|
90
|
+
await this.reportError(error);
|
|
91
|
+
await delay(claim.leaseMs, this.#controller.signal);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const { deliveries } = claimResponseSchema.parse(claimResponse);
|
|
95
|
+
if (deliveries.length === 0) {
|
|
96
|
+
await delay(this.options.pollIntervalMs ?? 500, this.#controller.signal);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
await Promise.all(deliveries.map((delivery) => this.handleDelivery(delivery, subscription.subscriptionId, claim.leaseMs, context)));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (this.#controller.signal.aborted)
|
|
103
|
+
break;
|
|
104
|
+
await this.reportError(error);
|
|
105
|
+
await delay(this.options.pollIntervalMs ?? 500, this.#controller.signal);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async handleDelivery(delivery, subscriptionId, leaseMs, context) {
|
|
110
|
+
const renewal = new AbortController();
|
|
111
|
+
const handler = new AbortController();
|
|
112
|
+
const renewalSignal = AbortSignal.any([this.#controller.signal, renewal.signal]);
|
|
113
|
+
const handlerSignal = AbortSignal.any([this.#controller.signal, handler.signal]);
|
|
114
|
+
let renewalFailed = false;
|
|
115
|
+
let renewalError;
|
|
116
|
+
const renewing = this.renewWhileHandling(delivery, subscriptionId, leaseMs, context, renewalSignal)
|
|
117
|
+
.catch((error) => { renewalFailed = true; renewalError = error; handler.abort(error); });
|
|
118
|
+
let handlingFailed = false;
|
|
119
|
+
let handlingError;
|
|
120
|
+
try {
|
|
121
|
+
const event = this.definition.parse(delivery.event);
|
|
122
|
+
await this.options.handle(event, createInvocationContext(delivery.context, handlerSignal, subscriptionId));
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
handlingFailed = true;
|
|
126
|
+
handlingError = error;
|
|
127
|
+
}
|
|
128
|
+
renewal.abort();
|
|
129
|
+
await renewing;
|
|
130
|
+
if (handlingFailed || renewalFailed) {
|
|
131
|
+
const error = handlingFailed ? handlingError : renewalError;
|
|
132
|
+
const failure = failRequestSchema.parse({
|
|
133
|
+
deliveryId: delivery.deliveryId, leaseToken: delivery.leaseToken,
|
|
134
|
+
subscriptionId, instanceId: this.instanceId, reason: failureReason(error),
|
|
135
|
+
});
|
|
136
|
+
deliveryMutationResponseSchema.parse(await this.call(EVENT_FAIL_OPERATION, failure, context));
|
|
137
|
+
await this.reportError(error);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const ack = ackRequestSchema.parse({
|
|
141
|
+
deliveryId: delivery.deliveryId, leaseToken: delivery.leaseToken,
|
|
142
|
+
subscriptionId, instanceId: this.instanceId,
|
|
143
|
+
});
|
|
144
|
+
const result = deliveryMutationResponseSchema.parse(await this.call(EVENT_ACK_OPERATION, ack, context));
|
|
145
|
+
if (!result.accepted)
|
|
146
|
+
await this.reportError(new Error(`Event delivery ${delivery.deliveryId} lease was lost before acknowledgement`));
|
|
147
|
+
}
|
|
148
|
+
async renewWhileHandling(delivery, subscriptionId, leaseMs, context, signal) {
|
|
149
|
+
const interval = Math.max(250, Math.floor(leaseMs / 4));
|
|
150
|
+
while (!signal.aborted) {
|
|
151
|
+
await delay(interval, signal);
|
|
152
|
+
if (signal.aborted)
|
|
153
|
+
return;
|
|
154
|
+
const request = renewRequestSchema.parse({
|
|
155
|
+
deliveryId: delivery.deliveryId, leaseToken: delivery.leaseToken,
|
|
156
|
+
subscriptionId, instanceId: this.instanceId, leaseMs,
|
|
157
|
+
});
|
|
158
|
+
let response;
|
|
159
|
+
try {
|
|
160
|
+
response = await this.call(EVENT_RENEW_OPERATION, request, context, 1, signal, Math.min(5_000, interval));
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (signal.aborted)
|
|
164
|
+
return;
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
if (!deliveryMutationResponseSchema.parse(response).accepted) {
|
|
168
|
+
throw new Error(`Event delivery ${delivery.deliveryId} lease was lost during handling`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async reportError(error) {
|
|
173
|
+
try {
|
|
174
|
+
await this.options.onError?.(error);
|
|
175
|
+
}
|
|
176
|
+
catch { /* Diagnostics must not stop delivery. */ }
|
|
177
|
+
}
|
|
178
|
+
call(operation, data, context, retries = 1, signal = this.#controller.signal, timeout = 5_000) {
|
|
179
|
+
return this.application.call(EVENT_SERVICE_NAMESPACE, operation, data, {
|
|
180
|
+
context, timeout, retries, signal,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function failureReason(error) {
|
|
185
|
+
return (error instanceof Error ? error.message : String(error)).slice(0, 2_000) || 'Unknown consumer failure';
|
|
186
|
+
}
|
|
187
|
+
function delay(milliseconds, signal) {
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
if (signal.aborted)
|
|
190
|
+
return resolve();
|
|
191
|
+
const timer = setTimeout(resolve, milliseconds);
|
|
192
|
+
signal.addEventListener('abort', () => { clearTimeout(timer); resolve(); }, { once: true });
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAiD,MAAM,eAAe,CAAC;AAE9H,OAAO,EACL,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,8BAA8B,EACzF,+BAA+B,EAAE,gCAAgC,EAAE,mBAAmB,EACtF,qBAAqB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,qBAAqB,EAC3F,uBAAuB,EAAE,yB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_NAMESPACE = "cn.zlooks.event";
|
|
3
|
+
export declare const EVENT_PUBLISH_OPERATION = "/events/publish";
|
|
4
|
+
export declare const EVENT_SUBSCRIBE_OPERATION = "/subscriptions/ensure";
|
|
5
|
+
export declare const EVENT_CLAIM_OPERATION = "/deliveries/claim";
|
|
6
|
+
export declare const EVENT_RENEW_OPERATION = "/deliveries/renew";
|
|
7
|
+
export declare const EVENT_ACK_OPERATION = "/deliveries/ack";
|
|
8
|
+
export declare const EVENT_FAIL_OPERATION = "/deliveries/fail";
|
|
9
|
+
export declare const publishRequestSchema: z.ZodPipe<z.ZodObject<{
|
|
10
|
+
event: z.ZodUnknown;
|
|
11
|
+
}, z.core.$strict>, z.ZodTransform<{
|
|
12
|
+
event: Readonly<{
|
|
13
|
+
protocol: 'zlooks.event';
|
|
14
|
+
protocolVersion: 1;
|
|
15
|
+
eventId: string;
|
|
16
|
+
type: string;
|
|
17
|
+
producer: string;
|
|
18
|
+
aggregate: Readonly<{
|
|
19
|
+
type: string;
|
|
20
|
+
id: string;
|
|
21
|
+
}>;
|
|
22
|
+
occurredAt: string;
|
|
23
|
+
data: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
}, {
|
|
26
|
+
event: unknown;
|
|
27
|
+
}>>;
|
|
28
|
+
export declare const publishResponseSchema: z.ZodReadonly<z.ZodObject<{
|
|
29
|
+
eventId: z.ZodUUID;
|
|
30
|
+
inserted: z.ZodBoolean;
|
|
31
|
+
}, z.core.$strict>>;
|
|
32
|
+
export declare const ensureSubscriptionRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
33
|
+
subscriptionId: z.ZodString;
|
|
34
|
+
eventType: z.ZodString;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
export declare const ensureSubscriptionResponseSchema: z.ZodReadonly<z.ZodObject<{
|
|
37
|
+
subscriptionId: z.ZodString;
|
|
38
|
+
eventType: z.ZodString;
|
|
39
|
+
created: z.ZodBoolean;
|
|
40
|
+
}, z.core.$strict>>;
|
|
41
|
+
export declare const claimRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
42
|
+
subscriptionId: z.ZodString;
|
|
43
|
+
eventType: z.ZodString;
|
|
44
|
+
instanceId: z.ZodString;
|
|
45
|
+
limit: z.ZodNumber;
|
|
46
|
+
leaseMs: z.ZodNumber;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
export declare const claimResponseSchema: z.ZodReadonly<z.ZodObject<{
|
|
49
|
+
deliveries: z.ZodArray<z.ZodPipe<z.ZodObject<{
|
|
50
|
+
deliveryId: z.ZodUUID;
|
|
51
|
+
leaseToken: z.ZodUUID;
|
|
52
|
+
attempts: z.ZodNumber;
|
|
53
|
+
event: z.ZodUnknown;
|
|
54
|
+
context: z.ZodUnknown;
|
|
55
|
+
}, z.core.$strict>, z.ZodTransform<{
|
|
56
|
+
deliveryId: string;
|
|
57
|
+
leaseToken: string;
|
|
58
|
+
attempts: number;
|
|
59
|
+
event: Readonly<{
|
|
60
|
+
protocol: 'zlooks.event';
|
|
61
|
+
protocolVersion: 1;
|
|
62
|
+
eventId: string;
|
|
63
|
+
type: string;
|
|
64
|
+
producer: string;
|
|
65
|
+
aggregate: Readonly<{
|
|
66
|
+
type: string;
|
|
67
|
+
id: string;
|
|
68
|
+
}>;
|
|
69
|
+
occurredAt: string;
|
|
70
|
+
data: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
context: Readonly<{
|
|
73
|
+
version: 1;
|
|
74
|
+
values: Readonly<Readonly<Record<string, import("@hile/context").ContextJsonValue>>>;
|
|
75
|
+
}>;
|
|
76
|
+
}, {
|
|
77
|
+
deliveryId: string;
|
|
78
|
+
leaseToken: string;
|
|
79
|
+
attempts: number;
|
|
80
|
+
event: unknown;
|
|
81
|
+
context: unknown;
|
|
82
|
+
}>>>;
|
|
83
|
+
}, z.core.$strict>>;
|
|
84
|
+
export declare const renewRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
85
|
+
deliveryId: z.ZodUUID;
|
|
86
|
+
subscriptionId: z.ZodString;
|
|
87
|
+
instanceId: z.ZodString;
|
|
88
|
+
leaseToken: z.ZodUUID;
|
|
89
|
+
leaseMs: z.ZodNumber;
|
|
90
|
+
}, z.core.$strict>>;
|
|
91
|
+
export declare const ackRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
92
|
+
deliveryId: z.ZodUUID;
|
|
93
|
+
subscriptionId: z.ZodString;
|
|
94
|
+
instanceId: z.ZodString;
|
|
95
|
+
leaseToken: z.ZodUUID;
|
|
96
|
+
}, z.core.$strict>>;
|
|
97
|
+
export declare const failRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
98
|
+
deliveryId: z.ZodUUID;
|
|
99
|
+
subscriptionId: z.ZodString;
|
|
100
|
+
instanceId: z.ZodString;
|
|
101
|
+
leaseToken: z.ZodUUID;
|
|
102
|
+
reason: z.ZodString;
|
|
103
|
+
}, z.core.$strict>>;
|
|
104
|
+
export declare const deliveryMutationResponseSchema: z.ZodReadonly<z.ZodObject<{
|
|
105
|
+
accepted: z.ZodBoolean;
|
|
106
|
+
}, z.core.$strict>>;
|
|
107
|
+
export type PublishRequest = z.input<typeof publishRequestSchema>;
|
|
108
|
+
export type EnsureSubscriptionRequest = z.infer<typeof ensureSubscriptionRequestSchema>;
|
|
109
|
+
export type ClaimRequest = z.infer<typeof claimRequestSchema>;
|
|
110
|
+
export type RenewRequest = z.infer<typeof renewRequestSchema>;
|
|
111
|
+
export type AckRequest = z.infer<typeof ackRequestSchema>;
|
|
112
|
+
export type FailRequest = z.infer<typeof failRequestSchema>;
|
|
113
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,uBAAuB,oBAAoB,CAAC;AACzD,eAAO,MAAM,uBAAuB,oBAAoB,CAAC;A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-0,0 +1,32 @@
|
|
|
1
|
+
import { parseExecutionContext } from '@hile/context';
|
|
2
|
+
import { parseDomainEvent } from '@zlooks.cn/event-bus';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const EVENT_SERVICE_NAMESPACE = 'cn.zlooks.event';
|
|
5
|
+
export const EVENT_PUBLISH_OPERATION = '/events/publish';
|
|
6
|
+
export const EVENT_SUBSCRIBE_OPERATION = '/subscriptions/ensure';
|
|
7
|
+
export const EVENT_CLAIM_OPERATION = '/deliveries/claim';
|
|
8
|
+
export const EVENT_RENEW_OPERATION = '/deliveries/renew';
|
|
9
|
+
export const EVENT_ACK_OPERATION = '/deliveries/ack';
|
|
10
|
+
export const EVENT_FAIL_OPERATION = '/deliveries/fail';
|
|
11
|
+
const subscriptionId = z.string().min(3).max(256).regex(/^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9-]*)+\.v[1-9][0-9]*$/);
|
|
12
|
+
const instanceId = z.string().min(1).max(256).regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/);
|
|
13
|
+
const leaseToken = z.uuid();
|
|
14
|
+
const leaseMs = z.number().int().min(1_000).max(300_000);
|
|
15
|
+
export const publishRequestSchema = z.strictObject({ event: z.unknown() }).transform(({ event }) => ({ event: parseDomainEvent(event) }));
|
|
16
|
+
export const publishResponseSchema = z.strictObject({ eventId: z.uuid(), inserted: z.boolean() }).readonly();
|
|
17
|
+
export const ensureSubscriptionRequestSchema = z.strictObject({ subscriptionId, eventType: z.string().min(1).max(256) }).readonly();
|
|
18
|
+
export const ensureSubscriptionResponseSchema = z.strictObject({ subscriptionId, eventType: z.string(), created: z.boolean() }).readonly();
|
|
19
|
+
export const claimRequestSchema = z.strictObject({
|
|
20
|
+
subscriptionId, eventType: z.string().min(1).max(256), instanceId,
|
|
21
|
+
limit: z.number().int().min(1).max(64), leaseMs,
|
|
22
|
+
}).readonly();
|
|
23
|
+
const claimedDeliverySchema = z.strictObject({
|
|
24
|
+
deliveryId: z.uuid(), leaseToken, attempts: z.number().int().positive(), event: z.unknown(), context: z.unknown(),
|
|
25
|
+
}).transform((value) => ({ ...value, event: parseDomainEvent(value.event), context: parseExecutionContext(value.context) }));
|
|
26
|
+
export const claimResponseSchema = z.strictObject({ deliveries: z.array(claimedDeliverySchema).max(64) }).readonly();
|
|
27
|
+
const deliveryMutationRequestSchema = z.strictObject({ deliveryId: z.uuid(), subscriptionId, instanceId, leaseToken });
|
|
28
|
+
export const renewRequestSchema = deliveryMutationRequestSchema.extend({ leaseMs }).readonly();
|
|
29
|
+
export const ackRequestSchema = deliveryMutationRequestSchema.readonly();
|
|
30
|
+
export const failRequestSchema = deliveryMutationRequestSchema.extend({ reason: z.string().min(1).max(2_000) }).readonly();
|
|
31
|
+
export const deliveryMutationResponseSchema = z.strictObject({ accepted: z.boolean() }).readonly();
|
|
32
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;AACzD,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AACjE,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AACzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEvD,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CA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AM,CAAC,MAAM,kBAAkB,GAAG,6BAA6B,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC/F,MAAM,CAAC,MAAM,gBAAgB,GAAG,6BAA6B,CAAC,QAAQ,EAAE,CAAC;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC3H,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zlooks.cn/event-client",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "pnpm run clean && tsc -p tsconfig.json && fix-esm-import-path --preserve-import-type ./dist",
|
|
17
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@hile/context": "4.0.2",
|
|
23
|
+
"@zlooks.cn/event-bus": "1.0.1",
|
|
24
|
+
"zod": "4.4.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "26.2.0",
|
|
28
|
+
"fix-esm-import-path": "1.10.3",
|
|
29
|
+
"typescript": "7.0.2",
|
|
30
|
+
"vitest": "4.1.11"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "b118899f7646d3cb4e82563f0d32f68238bb38d0"
|
|
33
|
+
}
|