@zlooks.cn/event-server 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.
Files changed (65) hide show
  1. package/dist/command/index.d.ts +3 -0
  2. package/dist/command/index.d.ts.map +1 -0
  3. package/dist/command/index.js +20 -0
  4. package/dist/command/index.js.map +1 -0
  5. package/dist/config/schema.d.ts +8 -0
  6. package/dist/config/schema.d.ts.map +1 -0
  7. package/dist/config/schema.js +5 -0
  8. package/dist/config/schema.js.map +1 -0
  9. package/dist/event-center-store.d.ts +56 -0
  10. package/dist/event-center-store.d.ts.map +1 -0
  11. package/dist/event-center-store.js +230 -0
  12. package/dist/event-center-store.js.map +1 -0
  13. package/dist/messages/deliveries/ack.msg.d.ts +3 -0
  14. package/dist/messages/deliveries/ack.msg.d.ts.map +1 -0
  15. package/dist/messages/deliveries/ack.msg.js +10 -0
  16. package/dist/messages/deliveries/ack.msg.js.map +1 -0
  17. package/dist/messages/deliveries/claim.msg.d.ts +3 -0
  18. package/dist/messages/deliveries/claim.msg.d.ts.map +1 -0
  19. package/dist/messages/deliveries/claim.msg.js +10 -0
  20. package/dist/messages/deliveries/claim.msg.js.map +1 -0
  21. package/dist/messages/deliveries/fail.msg.d.ts +3 -0
  22. package/dist/messages/deliveries/fail.msg.d.ts.map +1 -0
  23. package/dist/messages/deliveries/fail.msg.js +10 -0
  24. package/dist/messages/deliveries/fail.msg.js.map +1 -0
  25. package/dist/messages/deliveries/renew.msg.d.ts +3 -0
  26. package/dist/messages/deliveries/renew.msg.d.ts.map +1 -0
  27. package/dist/messages/deliveries/renew.msg.js +10 -0
  28. package/dist/messages/deliveries/renew.msg.js.map +1 -0
  29. package/dist/messages/events/publish.msg.d.ts +3 -0
  30. package/dist/messages/events/publish.msg.d.ts.map +1 -0
  31. package/dist/messages/events/publish.msg.js +10 -0
  32. package/dist/messages/events/publish.msg.js.map +1 -0
  33. package/dist/messages/subscriptions/ensure.msg.d.ts +3 -0
  34. package/dist/messages/subscriptions/ensure.msg.d.ts.map +1 -0
  35. package/dist/messages/subscriptions/ensure.msg.js +10 -0
  36. package/dist/messages/subscriptions/ensure.msg.js.map +1 -0
  37. package/dist/migrations/index.d.ts +3 -0
  38. package/dist/migrations/index.d.ts.map +1 -0
  39. package/dist/migrations/index.js +2 -0
  40. package/dist/migrations/index.js.map +1 -0
  41. package/dist/persistence/entities.d.ts +40 -0
  42. package/dist/persistence/entities.d.ts.map +1 -0
  43. package/dist/persistence/entities.js +60 -0
  44. package/dist/persistence/entities.js.map +1 -0
  45. package/dist/services/application.service.d.ts +4 -0
  46. package/dist/services/application.service.d.ts.map +1 -0
  47. package/dist/services/application.service.js +15 -0
  48. package/dist/services/application.service.js.map +1 -0
  49. package/dist/services/config.service.d.ts +3 -0
  50. package/dist/services/config.service.d.ts.map +1 -0
  51. package/dist/services/config.service.js +14 -0
  52. package/dist/services/config.service.js.map +1 -0
  53. package/dist/services/database.service.d.ts +3 -0
  54. package/dist/services/database.service.d.ts.map +1 -0
  55. package/dist/services/database.service.js +15 -0
  56. package/dist/services/database.service.js.map +1 -0
  57. package/dist/services/event-runtime.service.d.ts +4 -0
  58. package/dist/services/event-runtime.service.d.ts.map +1 -0
  59. package/dist/services/event-runtime.service.js +5 -0
  60. package/dist/services/event-runtime.service.js.map +1 -0
  61. package/dist/services/event.boot.d.ts +3 -0
  62. package/dist/services/event.boot.d.ts.map +1 -0
  63. package/dist/services/event.boot.js +8 -0
  64. package/dist/services/event.boot.js.map +1 -0
  65. package/package.json +58 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'node:url';
3
+ import { createRegistryDatabaseDataSource, registerDatabaseCommands } from '@zlooks.cn/database-command';
4
+ import { runServiceCommand } from '@zlooks.cn/service-command';
5
+ import { eventMigrations } from '../migrations/index.js';
6
+ import { eventEntities } from '../persistence/entities.js';
7
+ await runServiceCommand({
8
+ packageRoot: fileURLToPath(new URL('../../', import.meta.url)), requiresReactServer: false,
9
+ configure(program) {
10
+ registerDatabaseCommands(program, {
11
+ createDataSource: (envFile) => createRegistryDatabaseDataSource(envFile, {
12
+ commandNamespace: 'cn.zlooks.event.db.command', entities: [...eventEntities],
13
+ }), migrations: eventMigrations,
14
+ });
15
+ },
16
+ }).catch((error) => {
17
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
18
+ process.exitCode = 1;
19
+ });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACzG,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,iBAAiB,CAAC;IACtB,WAAW,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK;IAC1F,SAAS,CAAC,OAAO;QACf,wBAAwB,CAAC,OAAO,EAAE;YAChC,gBAAgB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,gCAAgC,CAAC,OAAO,EAAE;gBACvE,gBAAgB,EAAE,4BAA4B,EAAE,QAAQ,EAAE,CAAC,GAAG,aAAa,CAAC;aAC7E,CAAC,EAAE,UAAU,EAAE,eAAe;SAChC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type PostgresConfig } from '@zlooks.cn/infrastructure';
2
+ export interface EventServerConfig {
3
+ readonly postgres: PostgresConfig;
4
+ }
5
+ export declare function parseEventServerConfig(input: {
6
+ readonly postgres: unknown;
7
+ }): EventServerConfig;
8
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAAG,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAA;CAAE;AACxE,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,iBAAiB,CAE/F"}
@@ -0,0 +1,5 @@
1
+ import { parsePostgresConfig } from '@zlooks.cn/infrastructure';
2
+ export function parseEventServerConfig(input) {
3
+ return Object.freeze({ postgres: parsePostgresConfig(input.postgres) });
4
+ }
5
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAuB,MAAM,2BAA2B,CAAC;AAGrF,MAAM,UAAU,sBAAsB,CAAC,KAAqC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { AckRequest, ClaimRequest, FailRequest, RenewRequest } from '@zlooks.cn/event-client';
2
+ import { type DataSource } from 'typeorm';
3
+ export declare class EventCenterStore {
4
+ #private;
5
+ private readonly dataSource;
6
+ constructor(dataSource: DataSource, options?: {
7
+ maxAttempts?: number;
8
+ baseRetryMs?: number;
9
+ backfillBatchSize?: number;
10
+ serializable?: boolean;
11
+ clock?: () => Date;
12
+ });
13
+ publish(input: unknown, contextInput: unknown): Promise<{
14
+ eventId: string;
15
+ inserted: boolean;
16
+ }>;
17
+ ensureSubscription(subscriptionId: string, eventType: string): Promise<{
18
+ subscriptionId: string;
19
+ eventType: string;
20
+ created: boolean;
21
+ }>;
22
+ claim(input: ClaimRequest, now?: Date): Promise<Readonly<{
23
+ deliveryId: string;
24
+ leaseToken: string;
25
+ attempts: number;
26
+ event: Readonly<{
27
+ protocol: 'zlooks.event';
28
+ protocolVersion: 1;
29
+ eventId: string;
30
+ type: string;
31
+ producer: string;
32
+ aggregate: Readonly<{
33
+ type: string;
34
+ id: string;
35
+ }>;
36
+ occurredAt: string;
37
+ data: unknown;
38
+ }>;
39
+ context: Readonly<{
40
+ version: 1;
41
+ values: Readonly<Readonly<Record<string, import("@hile/context").ContextJsonValue>>>;
42
+ }>;
43
+ }>[]>;
44
+ ack(input: AckRequest, now?: Date): Promise<boolean>;
45
+ renew(input: RenewRequest, now?: Date): Promise<boolean>;
46
+ fail(input: FailRequest, now?: Date): Promise<boolean>;
47
+ countEvents(): Promise<number>;
48
+ countDeliveries(): Promise<number>;
49
+ countDeadLetters(): Promise<number>;
50
+ private retryDelay;
51
+ private backfill;
52
+ private insertDelivery;
53
+ private deliveryRow;
54
+ private serializable;
55
+ }
56
+ //# sourceMappingURL=event-center-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-center-store.d.ts","sourceRoot":"","sources":["../src/event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AAY;CAY3B"}
@@ -0,0 +1,230 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { parseExecutionContext } from '@hile/context';
3
+ import { parseDomainEvent } from '@zlooks.cn/event-bus';
4
+ import { Equal, In, LessThan, LessThanOrEqual, MoreThan } from 'typeorm';
5
+ import { EventDeliveryEntity, EventRecordEntity, EventSubscriptionEntity } from './persistence/entities.js';
6
+ export class EventCenterStore {
7
+ dataSource;
8
+ #maxAttempts;
9
+ #baseRetryMs;
10
+ #backfillBatchSize;
11
+ #serializable;
12
+ #clock;
13
+ constructor(dataSource, options = {}) {
14
+ this.dataSource = dataSource;
15
+ this.#maxAttempts = options.maxAttempts ?? 10;
16
+ this.#baseRetryMs = options.baseRetryMs ?? 1_000;
17
+ this.#backfillBatchSize = options.backfillBatchSize ?? 256;
18
+ this.#serializable = options.serializable ?? true;
19
+ this.#clock = options.clock ?? (() => new Date());
20
+ }
21
+ async publish(input, contextInput) {
22
+ const event = parseDomainEvent(input);
23
+ const context = parseExecutionContext(contextInput);
24
+ const fingerprint = hash(event);
25
+ return this.serializable(async (manager) => {
26
+ const repository = manager.getRepository(EventRecordEntity);
27
+ const existing = await repository.findOneBy({ id: event.eventId });
28
+ if (existing && existing.fingerprint !== fingerprint) {
29
+ throw new Error(`Event ID ${event.eventId} was reused with different content`);
30
+ }
31
+ if (!existing)
32
+ await repository.save({
33
+ id: event.eventId, eventType: event.type, producer: event.producer,
34
+ aggregateType: event.aggregate.type, aggregateId: event.aggregate.id,
35
+ payload: event,
36
+ context: context, fingerprint,
37
+ occurredAt: new Date(event.occurredAt), createdAt: this.#clock(),
38
+ });
39
+ const stored = await repository.findOneByOrFail({ id: event.eventId });
40
+ if (stored.fingerprint !== fingerprint)
41
+ throw new Error(`Event ID ${event.eventId} was reused with different content`);
42
+ const subscriptions = await manager.getRepository(EventSubscriptionEntity).findBy({ eventType: event.type });
43
+ for (const { id } of subscriptions)
44
+ await this.insertDelivery(manager, id, event);
45
+ return { eventId: event.eventId, inserted: existing === null };
46
+ });
47
+ }
48
+ async ensureSubscription(subscriptionId, eventType) {
49
+ return this.serializable(async (manager) => {
50
+ const subscriptions = manager.getRepository(EventSubscriptionEntity);
51
+ const existing = await subscriptions.findOneBy({ id: subscriptionId });
52
+ if (existing && existing.eventType !== eventType)
53
+ throw new Error(`Subscription ${subscriptionId} is already bound to ${existing.eventType}`);
54
+ if (!existing)
55
+ await subscriptions.save({
56
+ id: subscriptionId, eventType, backfillComplete: false, createdAt: this.#clock(),
57
+ });
58
+ const stored = await subscriptions.findOneByOrFail({ id: subscriptionId });
59
+ if (stored.eventType !== eventType)
60
+ throw new Error(`Subscription ${subscriptionId} is already bound to ${stored.eventType}`);
61
+ return { subscriptionId, eventType, created: existing === null };
62
+ });
63
+ }
64
+ async claim(input, now = new Date()) {
65
+ const subscription = await this.dataSource.getRepository(EventSubscriptionEntity).findOneBy({ id: input.subscriptionId });
66
+ if (!subscription || subscription.eventType !== input.eventType) {
67
+ throw new Error(`Subscription ${input.subscriptionId} is not bound to ${input.eventType}`);
68
+ }
69
+ if (!subscription.backfillComplete)
70
+ await this.backfill(subscription.id, subscription.eventType);
71
+ const repository = this.dataSource.getRepository(EventDeliveryEntity);
72
+ const candidateIds = await this.dataSource.query(`
73
+ SELECT "id" FROM (
74
+ SELECT DISTINCT ON ("ordering_key")
75
+ "id", "status", "next_attempt_at", "lease_until", "created_at"
76
+ FROM "event_deliveries"
77
+ WHERE "subscription_id" = $1 AND "status" IN ('pending', 'leased')
78
+ ORDER BY "ordering_key", "created_at", "id"
79
+ ) "head"
80
+ WHERE ("status" = 'pending' AND "next_attempt_at" <= $2)
81
+ OR ("status" = 'leased' AND "lease_until" <= $2)
82
+ ORDER BY "created_at", "id"
83
+ LIMIT $3
84
+ `, [input.subscriptionId, now, Math.min(256, input.limit * 4)]);
85
+ const rows = candidateIds.length === 0
86
+ ? []
87
+ : await repository.findBy({ id: In(candidateIds.map(({ id }) => id)) });
88
+ const rowsById = new Map(rows.map((row) => [row.id, row]));
89
+ const candidates = candidateIds.flatMap(({ id }) => {
90
+ const row = rowsById.get(id);
91
+ return row ? [row] : [];
92
+ });
93
+ const claimed = [];
94
+ for (const candidate of candidates) {
95
+ if (claimed.length >= input.limit)
96
+ break;
97
+ const predecessor = await repository.findOne({ where: [
98
+ { subscriptionId: input.subscriptionId, orderingKey: candidate.orderingKey, status: In(['pending', 'leased']), createdAt: LessThan(candidate.createdAt) },
99
+ { subscriptionId: input.subscriptionId, orderingKey: candidate.orderingKey, status: In(['pending', 'leased']), createdAt: Equal(candidate.createdAt), id: LessThan(candidate.id) },
100
+ ] });
101
+ if (predecessor)
102
+ continue;
103
+ const leaseToken = randomUUID();
104
+ const leaseUntil = new Date(now.getTime() + input.leaseMs);
105
+ const where = candidate.status === 'pending'
106
+ ? { id: candidate.id, status: 'pending', attempts: candidate.attempts, nextAttemptAt: LessThanOrEqual(now) }
107
+ : { id: candidate.id, status: 'leased', attempts: candidate.attempts, leaseUntil: LessThanOrEqual(now) };
108
+ const result = await repository.update(where, {
109
+ status: 'leased', attempts: candidate.attempts + 1, leaseOwner: input.instanceId, leaseToken, leaseUntil,
110
+ });
111
+ if (result.affected === 1)
112
+ claimed.push({ ...candidate, status: 'leased', attempts: candidate.attempts + 1, leaseOwner: input.instanceId, leaseToken, leaseUntil });
113
+ }
114
+ const eventRepository = this.dataSource.getRepository(EventRecordEntity);
115
+ return Promise.all(claimed.map(async (delivery) => {
116
+ const record = await eventRepository.findOneByOrFail({ id: delivery.eventId });
117
+ return Object.freeze({
118
+ deliveryId: delivery.id, leaseToken: delivery.leaseToken, attempts: delivery.attempts,
119
+ event: parseDomainEvent(record.payload), context: parseExecutionContext(record.context),
120
+ });
121
+ }));
122
+ }
123
+ async ack(input, now = new Date()) {
124
+ const result = await this.dataSource.getRepository(EventDeliveryEntity).update({
125
+ id: input.deliveryId, subscriptionId: input.subscriptionId, status: 'leased',
126
+ leaseOwner: input.instanceId, leaseToken: input.leaseToken, leaseUntil: MoreThan(now),
127
+ }, { status: 'delivered', deliveredAt: now, leaseOwner: null, leaseToken: null, leaseUntil: null });
128
+ return result.affected === 1;
129
+ }
130
+ async renew(input, now = new Date()) {
131
+ const result = await this.dataSource.getRepository(EventDeliveryEntity).update({
132
+ id: input.deliveryId, subscriptionId: input.subscriptionId, status: 'leased',
133
+ leaseOwner: input.instanceId, leaseToken: input.leaseToken, leaseUntil: MoreThan(now),
134
+ }, { leaseUntil: new Date(now.getTime() + input.leaseMs) });
135
+ return result.affected === 1;
136
+ }
137
+ async fail(input, now = new Date()) {
138
+ const repository = this.dataSource.getRepository(EventDeliveryEntity);
139
+ const current = await repository.findOneBy({ id: input.deliveryId, subscriptionId: input.subscriptionId });
140
+ if (!current || current.status !== 'leased' || current.leaseOwner !== input.instanceId
141
+ || current.leaseToken !== input.leaseToken || !current.leaseUntil || current.leaseUntil <= now)
142
+ return false;
143
+ const dead = current.attempts >= this.#maxAttempts;
144
+ const result = await repository.update({
145
+ id: current.id, status: 'leased', attempts: current.attempts,
146
+ leaseOwner: input.instanceId, leaseToken: input.leaseToken, leaseUntil: MoreThan(now),
147
+ }, {
148
+ status: dead ? 'dead' : 'pending',
149
+ nextAttemptAt: dead ? current.nextAttemptAt : new Date(now.getTime() + this.retryDelay(current.attempts)),
150
+ leaseOwner: null, leaseToken: null, leaseUntil: null,
151
+ firstFailureReason: current.firstFailureReason ?? input.reason, lastFailureReason: input.reason,
152
+ });
153
+ return result.affected === 1;
154
+ }
155
+ countEvents() { return this.dataSource.getRepository(EventRecordEntity).count(); }
156
+ countDeliveries() { return this.dataSource.getRepository(EventDeliveryEntity).count(); }
157
+ countDeadLetters() { return this.dataSource.getRepository(EventDeliveryEntity).countBy({ status: 'dead' }); }
158
+ retryDelay(attempts) { return Math.min(60_000, this.#baseRetryMs * (2 ** Math.min(attempts - 1, 6))); }
159
+ async backfill(subscriptionId, eventType) {
160
+ await this.serializable(async (manager) => {
161
+ const subscriptions = manager.getRepository(EventSubscriptionEntity);
162
+ const subscription = await subscriptions.findOneByOrFail({ id: subscriptionId });
163
+ if (subscription.backfillComplete)
164
+ return;
165
+ const events = await manager.getRepository(EventRecordEntity)
166
+ .createQueryBuilder('event')
167
+ .leftJoin(EventDeliveryEntity.options.name, 'delivery', 'delivery.subscriptionId = :subscriptionId AND delivery.eventId = event.id', { subscriptionId })
168
+ .where('event.eventType = :eventType', { eventType })
169
+ .andWhere('delivery.id IS NULL')
170
+ .orderBy('event.occurredAt', 'ASC')
171
+ .addOrderBy('event.id', 'ASC')
172
+ .take(this.#backfillBatchSize)
173
+ .getMany();
174
+ if (events.length > 0) {
175
+ await manager.getRepository(EventDeliveryEntity).createQueryBuilder()
176
+ .insert()
177
+ .values(events.map((event) => this.deliveryRow(subscriptionId, parseDomainEvent(event.payload))))
178
+ .orIgnore()
179
+ .execute();
180
+ }
181
+ if (events.length < this.#backfillBatchSize) {
182
+ await subscriptions.update({ id: subscriptionId, backfillComplete: false }, { backfillComplete: true });
183
+ }
184
+ });
185
+ }
186
+ async insertDelivery(manager, subscriptionId, event) {
187
+ await manager.getRepository(EventDeliveryEntity).createQueryBuilder()
188
+ .insert()
189
+ .values(this.deliveryRow(subscriptionId, event))
190
+ .orIgnore()
191
+ .execute();
192
+ }
193
+ deliveryRow(subscriptionId, event) {
194
+ return {
195
+ id: randomUUID(), subscriptionId, eventId: event.eventId,
196
+ orderingKey: `${event.producer}/${event.aggregate.type}/${event.aggregate.id}`,
197
+ status: 'pending', attempts: 0,
198
+ nextAttemptAt: this.#clock(), leaseOwner: null, leaseToken: null, leaseUntil: null,
199
+ firstFailureReason: null, lastFailureReason: null, deliveredAt: null, createdAt: new Date(event.occurredAt),
200
+ };
201
+ }
202
+ async serializable(work) {
203
+ for (let attempt = 0;; attempt += 1) {
204
+ try {
205
+ return await (this.#serializable
206
+ ? this.dataSource.transaction('SERIALIZABLE', work)
207
+ : this.dataSource.transaction(work));
208
+ }
209
+ catch (error) {
210
+ if (attempt >= 2 || !isTransactionRetry(error))
211
+ throw error;
212
+ }
213
+ }
214
+ }
215
+ }
216
+ function hash(value) {
217
+ return createHash('sha256').update(stableStringify(value)).digest('hex');
218
+ }
219
+ function stableStringify(value) {
220
+ if (Array.isArray(value))
221
+ return `[${value.map(stableStringify).join(',')}]`;
222
+ if (value && typeof value === 'object')
223
+ return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${JSON.stringify(key)}:${stableStringify(item)}`).join(',')}}`;
224
+ return JSON.stringify(value);
225
+ }
226
+ function isTransactionRetry(error) {
227
+ return Boolean(error && typeof error === 'object' && 'code' in error
228
+ && (error.code === '40001' || error.code === '23505'));
229
+ }
230
+ //# sourceMappingURL=event-center-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-center-store.js","sourceRoot":"","sources":["../src/event-center-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAyB,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAoB,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAuC,MAAM,SAAS,CAAC;AAC9G,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,uBAAuB,EAAyB,MAAM,2BAA2B,CAAC;AAEnI,MAAM,OAAO,gBAAgB;IAMS,UAAU;IALrC,YAAY,CAAS;IACrB,YAAY,CAAS;IACrB,kBAAkB,CAAS;IAC3B,aAAa,CAAU;IACvB,MAAM,CAAa;IAC5B,YAAoC,UAAsB,EAAE,OAAO,GAE/D,EAAE;0BAF8B,UAAU;QAG5C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;QACjD,IAAI,CAAC,kBAAkB,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,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AACD,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK;WAC/D,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=ack.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ack.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/deliveries/ack.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { ackRequestSchema, deliveryMutationResponseSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = ackRequestSchema.parse(data);
8
+ return deliveryMutationResponseSchema.parse({ accepted: await (await loadService(eventRuntimeService)).ack(request) });
9
+ });
10
+ //# sourceMappingURL=ack.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ack.msg.js","sourceRoot":"","sources":["../../../src/messages/deliveries/ack.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,8BAA8B,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACzH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=claim.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/deliveries/claim.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { claimRequestSchema, claimResponseSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = claimRequestSchema.parse(data);
8
+ return claimResponseSchema.parse({ deliveries: await (await loadService(eventRuntimeService)).claim(request) });
9
+ });
10
+ //# sourceMappingURL=claim.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim.msg.js","sourceRoot":"","sources":["../../../src/messages/deliveries/claim.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,mBAAmB,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAClH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=fail.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fail.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/deliveries/fail.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { deliveryMutationResponseSchema, failRequestSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = failRequestSchema.parse(data);
8
+ return deliveryMutationResponseSchema.parse({ accepted: await (await loadService(eventRuntimeService)).fail(request) });
9
+ });
10
+ //# sourceMappingURL=fail.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fail.msg.js","sourceRoot":"","sources":["../../../src/messages/deliveries/fail.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9C,OAAO,8BAA8B,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC1H,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=renew.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renew.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/deliveries/renew.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { deliveryMutationResponseSchema, renewRequestSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = renewRequestSchema.parse(data);
8
+ return deliveryMutationResponseSchema.parse({ accepted: await (await loadService(eventRuntimeService)).renew(request) });
9
+ });
10
+ //# sourceMappingURL=renew.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renew.msg.js","sourceRoot":"","sources":["../../../src/messages/deliveries/renew.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7F,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,8BAA8B,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC3H,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=publish.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/events/publish.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { publishRequestSchema, publishResponseSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = publishRequestSchema.parse(data);
8
+ return publishResponseSchema.parse(await (await loadService(eventRuntimeService)).publish(request.event, invocation.context));
9
+ });
10
+ //# sourceMappingURL=publish.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.msg.js","sourceRoot":"","sources":["../../../src/messages/events/publish.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAChI,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/message-loader").MessageRegisterProps<unknown, import("@hile/micro").MicroMessageHandlerExtras>;
2
+ export default _default;
3
+ //# sourceMappingURL=ensure.msg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure.msg.d.ts","sourceRoot":"","sources":["../../../src/messages/subscriptions/ensure.msg.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { loadService } from '@hile/core';
2
+ import { defineMicroMessage } from '@hile/micro';
3
+ import { ensureSubscriptionRequestSchema, ensureSubscriptionResponseSchema } from '@zlooks.cn/event-client';
4
+ import eventRuntimeService from '../../services/event-runtime.service.js';
5
+ export default defineMicroMessage(async ({ data, invocation }) => {
6
+ invocation.signal.throwIfAborted();
7
+ const request = ensureSubscriptionRequestSchema.parse(data);
8
+ return ensureSubscriptionResponseSchema.parse(await (await loadService(eventRuntimeService)).ensureSubscription(request.subscriptionId, request.eventType));
9
+ });
10
+ //# sourceMappingURL=ensure.msg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensure.msg.js","sourceRoot":"","sources":["../../../src/messages/subscriptions/ensure.msg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,+BAA+B,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAC5G,OAAO,mBAAmB,MAAM,yCAAyC,CAAC;AAE1E,eAAe,kBAAkB,CAAU,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;IACxE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5D,OAAO,gCAAgC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9J,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DatabaseMigration } from '@zlooks.cn/database-command';
2
+ export declare const eventMigrations: readonly DatabaseMigration[];
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,eAAO,MAAM,eAAe,EAAE,SAAS,iBAAiB,EAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const eventMigrations = [];
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,eAAe,GAAiC,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { EntitySchema } from 'typeorm';
2
+ export interface EventRecordRow {
3
+ id: string;
4
+ eventType: string;
5
+ producer: string;
6
+ aggregateType: string;
7
+ aggregateId: string;
8
+ payload: Record<string, unknown>;
9
+ context: Record<string, unknown>;
10
+ fingerprint: string;
11
+ occurredAt: Date;
12
+ createdAt: Date;
13
+ }
14
+ export interface EventSubscriptionRow {
15
+ id: string;
16
+ eventType: string;
17
+ backfillComplete: boolean;
18
+ createdAt: Date;
19
+ }
20
+ export interface EventDeliveryRow {
21
+ id: string;
22
+ subscriptionId: string;
23
+ eventId: string;
24
+ status: 'pending' | 'leased' | 'delivered' | 'dead';
25
+ orderingKey: string;
26
+ attempts: number;
27
+ nextAttemptAt: Date;
28
+ leaseOwner: string | null;
29
+ leaseToken: string | null;
30
+ leaseUntil: Date | null;
31
+ firstFailureReason: string | null;
32
+ lastFailureReason: string | null;
33
+ deliveredAt: Date | null;
34
+ createdAt: Date;
35
+ }
36
+ export declare const EventRecordEntity: EntitySchema<EventRecordRow>;
37
+ export declare const EventSubscriptionEntity: EntitySchema<EventSubscriptionRow>;
38
+ export declare const EventDeliveryEntity: EntitySchema<EventDeliveryRow>;
39
+ export declare const eventEntities: readonly [EntitySchema<EventRecordRow>, EntitySchema<EventSubscriptionRow>, EntitySchema<EventDeliveryRow>];
40
+ //# sourceMappingURL=entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/persistence/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAC5F,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IACxF,UAAU,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC;CACnC;AACD,MAAM,WAAW,oBAAoB;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE;AACnH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;IACzG,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5F,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7F,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,iBAAiB,8BAQ5B,CAAC;AAEH,eAAO,MAAM,uBAAuB,oCAMlC,CAAC;AAEH,eAAO,MAAM,mBAAmB,gCAwC9B,CAAC;AAEH,eAAO,MAAM,aAAa,6GAA6E,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { EntitySchema } from 'typeorm';
2
+ export const EventRecordEntity = new EntitySchema({
3
+ name: 'EventRecord', tableName: 'event_records', columns: {
4
+ id: { type: 'uuid', primary: true }, eventType: { name: 'event_type', type: 'varchar', length: 256 },
5
+ producer: { type: 'varchar', length: 256 }, aggregateType: { name: 'aggregate_type', type: 'varchar', length: 64 },
6
+ aggregateId: { name: 'aggregate_id', type: 'varchar', length: 256 }, payload: { type: 'jsonb' }, context: { type: 'jsonb' },
7
+ fingerprint: { type: 'varchar', length: 64 }, occurredAt: { name: 'occurred_at', type: 'timestamptz' },
8
+ createdAt: { name: 'created_at', type: 'timestamptz' },
9
+ }, indices: [{ columns: ['eventType', 'occurredAt', 'id'] }, { columns: ['aggregateType', 'aggregateId', 'occurredAt', 'id'] }],
10
+ });
11
+ export const EventSubscriptionEntity = new EntitySchema({
12
+ name: 'EventSubscription', tableName: 'event_subscriptions', columns: {
13
+ id: { type: 'varchar', length: 256, primary: true }, eventType: { name: 'event_type', type: 'varchar', length: 256 },
14
+ backfillComplete: { name: 'backfill_complete', type: 'boolean', default: false },
15
+ createdAt: { name: 'created_at', type: 'timestamptz' },
16
+ }, indices: [{ columns: ['eventType'] }],
17
+ });
18
+ export const EventDeliveryEntity = new EntitySchema({
19
+ name: 'EventDelivery', tableName: 'event_deliveries', columns: {
20
+ id: { type: 'uuid', primary: true }, subscriptionId: { name: 'subscription_id', type: 'varchar', length: 256 },
21
+ eventId: { name: 'event_id', type: 'uuid' }, status: { type: 'varchar', length: 16 }, attempts: { type: 'integer', default: 0 },
22
+ orderingKey: { name: 'ordering_key', type: 'varchar', length: 600 },
23
+ nextAttemptAt: { name: 'next_attempt_at', type: 'timestamptz' }, leaseOwner: { name: 'lease_owner', type: 'varchar', length: 256, nullable: true },
24
+ leaseToken: { name: 'lease_token', type: 'uuid', nullable: true }, leaseUntil: { name: 'lease_until', type: 'timestamptz', nullable: true },
25
+ firstFailureReason: { name: 'first_failure_reason', type: 'varchar', length: 2000, nullable: true },
26
+ lastFailureReason: { name: 'last_failure_reason', type: 'varchar', length: 2000, nullable: true },
27
+ deliveredAt: { name: 'delivered_at', type: 'timestamptz', nullable: true }, createdAt: { name: 'created_at', type: 'timestamptz' },
28
+ },
29
+ foreignKeys: [
30
+ {
31
+ name: 'fk_event_deliveries_subscription', target: EventSubscriptionEntity,
32
+ columnNames: ['subscriptionId'], referencedColumnNames: ['id'],
33
+ },
34
+ {
35
+ name: 'fk_event_deliveries_event', target: EventRecordEntity,
36
+ columnNames: ['eventId'], referencedColumnNames: ['id'],
37
+ },
38
+ ],
39
+ checks: [
40
+ { name: 'chk_event_deliveries_status', expression: `"status" IN ('pending', 'leased', 'delivered', 'dead')` },
41
+ { name: 'chk_event_deliveries_attempts', expression: `"attempts" >= 0` },
42
+ {
43
+ name: 'chk_event_deliveries_state',
44
+ expression: `
45
+ ("status" = 'pending' AND "lease_owner" IS NULL AND "lease_token" IS NULL AND "lease_until" IS NULL AND "delivered_at" IS NULL)
46
+ OR ("status" = 'leased' AND "lease_owner" IS NOT NULL AND "lease_token" IS NOT NULL AND "lease_until" IS NOT NULL AND "delivered_at" IS NULL)
47
+ OR ("status" = 'delivered' AND "lease_owner" IS NULL AND "lease_token" IS NULL AND "lease_until" IS NULL AND "delivered_at" IS NOT NULL)
48
+ OR ("status" = 'dead' AND "lease_owner" IS NULL AND "lease_token" IS NULL AND "lease_until" IS NULL AND "delivered_at" IS NULL)
49
+ `,
50
+ },
51
+ ],
52
+ indices: [
53
+ { name: 'uq_event_delivery_subscription_event', columns: ['subscriptionId', 'eventId'], unique: true },
54
+ { name: 'idx_event_delivery_due', columns: ['subscriptionId', 'status', 'nextAttemptAt', 'createdAt'] },
55
+ { name: 'idx_event_delivery_lease', columns: ['subscriptionId', 'status', 'leaseUntil'] },
56
+ { name: 'idx_event_delivery_ordering', columns: ['subscriptionId', 'orderingKey', 'status', 'createdAt', 'id'] },
57
+ ],
58
+ });
59
+ export const eventEntities = [EventRecordEntity, EventSubscriptionEntity, EventDeliveryEntity];
60
+ //# sourceMappingURL=entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/persistence/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAgBvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,YAAY,CAAiB;IAChE,I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AAE,IAAI,EAAE,wBAAwB,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,CAAC,EAAE;QACvG,EAAE,IAAI,EAAE,0BAA0B,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE;QACzF,EAAE,IAAI,EAAE,6BAA6B,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE;KACjH;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,iBAAiB,EAAE,uBAAuB,EAAE,mBAAmB,CAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Application } from '@hile/micro';
2
+ declare const _default: import("@hile/core").ServiceRegisterProps<Application>;
3
+ export default _default;
4
+ //# sourceMappingURL=application.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.service.d.ts","sourceRoot":"","sources":["../../src/services/application.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { defineService } from '@hile/core';
3
+ import { Application } from '@hile/micro';
4
+ import { EVENT_SERVICE_NAMESPACE } from '@zlooks.cn/event-client';
5
+ import { parseAdvertiseHost, parseRegistryBootstrap } from '@zlooks.cn/registry-config';
6
+ import { detect } from 'detect-port';
7
+ export default defineService('zlooks.event.application', async (shutdown) => {
8
+ const registry = parseRegistryBootstrap({ REGISTRY_HOST: process.env.REGISTRY_HOST, REGISTRY_PORT: process.env.REGISTRY_PORT });
9
+ const advertiseHost = parseAdvertiseHost(process.env.HILE_ADVERTISE_HOST);
10
+ const application = new Application({ namespace: EVENT_SERVICE_NAMESPACE, registry, ...(advertiseHost ? { advertiseHost } : {}) });
11
+ await application.load(fileURLToPath(new URL('../messages', import.meta.url)));
12
+ shutdown(await application.listen(await detect()));
13
+ return application;
14
+ });
15
+ //# sourceMappingURL=application.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.service.js","sourceRoot":"","sources":["../../src/services/application.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAe,aAAa,CAAC,0BAA0B,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAC1E,MAAM,QAAQ,GAAG,sBAAsB,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;IAChI,MAAM,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC1E,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACnI,MAAM,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/E,QAAQ,CAAC,MAAM,WAAW,CAAC,MAAM,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC;IACnD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/core").ServiceRegisterProps<import("@zlooks.cn/registry-config").RegistryConfigSubscription<import("../config/schema.js").EventServerConfig>>;
2
+ export default _default;
3
+ //# sourceMappingURL=config.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../../src/services/config.service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { defineService, loadService } from '@hile/core';
2
+ import { parsePostgresConfig } from '@zlooks.cn/infrastructure';
3
+ import { registryConfigTopic, subscribeRegistryConfig } from '@zlooks.cn/registry-config';
4
+ import { parseEventServerConfig } from '../config/schema.js';
5
+ import applicationService from './application.service.js';
6
+ export default defineService('zlooks.event.config', async (shutdown) => {
7
+ const subscriber = await subscribeRegistryConfig(await loadService(applicationService), {
8
+ sources: { postgres: { topic: registryConfigTopic('postgres'), parse: parsePostgresConfig } },
9
+ compose: parseEventServerConfig,
10
+ });
11
+ shutdown(() => subscriber.close());
12
+ return subscriber;
13
+ });
14
+ //# sourceMappingURL=config.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.service.js","sourceRoot":"","sources":["../../src/services/config.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAE1D,eAAe,aAAa,CAAC,qBAAqB,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IACrE,MAAM,UAAU,GAAG,MAAM,uBAAuB,CAAC,MAAM,WAAW,CAAC,kBAAkB,CAAC,EAAE;QACtF,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE;QAC7F,OAAO,EAAE,sBAAsB;KAChC,CAAC,CAAC;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;IACnC,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/core").ServiceRegisterProps<import("typeorm").DataSource>;
2
+ export default _default;
3
+ //# sourceMappingURL=database.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.service.d.ts","sourceRoot":"","sources":["../../src/services/database.service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { defineService, loadService } from '@hile/core';
2
+ import { createDataSource } from '@hile/typeorm';
3
+ import { eventEntities } from '../persistence/entities.js';
4
+ import configService from './config.service.js';
5
+ export default defineService('zlooks.event.database', async (shutdown) => {
6
+ const config = (await loadService(configService)).snapshot().postgres;
7
+ const database = await createDataSource({
8
+ type: 'postgres', host: config.host, port: config.port, username: config.username,
9
+ password: config.password, database: config.database, ssl: config.ssl, poolSize: config.poolSize,
10
+ synchronize: true, migrationsRun: false, entities: [...eventEntities],
11
+ });
12
+ shutdown(() => database.destroy());
13
+ return database;
14
+ });
15
+ //# sourceMappingURL=database.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.service.js","sourceRoot":"","sources":["../../src/services/database.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAEhD,eAAe,aAAa,CAAC,uBAAuB,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IACvE,MAAM,MAAM,GAAG,CAAC,MAAM,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC;QACtC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACjF,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ;QAChG,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,GAAG,aAAa,CAAC;KACtE,CAAC,CAAC;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { EventCenterStore } from '../event-center-store.js';
2
+ declare const _default: import("@hile/core").ServiceRegisterProps<EventCenterStore>;
3
+ export default _default;
4
+ //# sourceMappingURL=event-runtime.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-runtime.service.d.ts","sourceRoot":"","sources":["../../src/services/event-runtime.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { defineService, loadService } from '@hile/core';
2
+ import { EventCenterStore } from '../event-center-store.js';
3
+ import databaseService from './database.service.js';
4
+ export default defineService('zlooks.event.runtime', async () => new EventCenterStore(await loadService(databaseService)));
5
+ //# sourceMappingURL=event-runtime.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-runtime.service.js","sourceRoot":"","sources":["../../src/services/event-runtime.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,eAAe,aAAa,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,gBAAgB,CAAC,MAAM,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@hile/core").ServiceRegisterProps<import("@hile/micro").Application>;
2
+ export default _default;
3
+ //# sourceMappingURL=event.boot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.boot.d.ts","sourceRoot":"","sources":["../../src/services/event.boot.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { defineService, loadService } from '@hile/core';
2
+ import applicationService from './application.service.js';
3
+ import databaseService from './database.service.js';
4
+ export default defineService('zlooks.event.boot', async () => {
5
+ await loadService(databaseService);
6
+ return loadService(applicationService);
7
+ });
8
+ //# sourceMappingURL=event.boot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.boot.js","sourceRoot":"","sources":["../../src/services/event.boot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,eAAe,aAAa,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;IAC3D,MAAM,WAAW,CAAC,eAAe,CAAC,CAAC;IACnC,OAAO,WAAW,CAAC,kBAAkB,CAAC,CAAC;AACzC,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@zlooks.cn/event-server",
3
+ "version": "1.0.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=24.0.0"
8
+ },
9
+ "bin": {
10
+ "zlooks-event-server": "dist/command/index.js"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "zlooks": {
16
+ "kind": "service",
17
+ "description": "中心领域事件投递服务",
18
+ "dependsOn": [],
19
+ "commands": {
20
+ "db": [
21
+ "migrate"
22
+ ]
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "pnpm run clean && tsc -p tsconfig.json && fix-esm-import-path --preserve-import-type ./dist",
27
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
28
+ "dev": "hile start --dev --env-file ~/.zlooks.cn/.env",
29
+ "start": "hile start --env-file ~/.zlooks.cn/.env",
30
+ "test": "vitest run",
31
+ "typecheck": "tsc -p tsconfig.json --noEmit"
32
+ },
33
+ "dependencies": {
34
+ "@hile/context": "4.0.2",
35
+ "@hile/core": "4.0.1",
36
+ "@hile/message-loader": "4.0.4",
37
+ "@hile/micro": "4.0.4",
38
+ "@hile/typeorm": "4.0.1",
39
+ "@zlooks.cn/database-command": "1.0.2",
40
+ "@zlooks.cn/event-bus": "1.0.1",
41
+ "@zlooks.cn/event-client": "1.0.1",
42
+ "@zlooks.cn/infrastructure": "1.0.0",
43
+ "@zlooks.cn/registry-config": "1.0.0",
44
+ "@zlooks.cn/service-command": "1.0.0",
45
+ "detect-port": "2.1.0",
46
+ "pg": "8.23.0",
47
+ "typeorm": "1.1.0"
48
+ },
49
+ "devDependencies": {
50
+ "@hile/cli": "4.0.5",
51
+ "@types/node": "26.2.0",
52
+ "fix-esm-import-path": "1.10.3",
53
+ "pg-mem": "3.0.14",
54
+ "typescript": "7.0.2",
55
+ "vitest": "4.1.11"
56
+ },
57
+ "gitHead": "b118899f7646d3cb4e82563f0d32f68238bb38d0"
58
+ }