@prodforcode/event-forge-mongoose 1.0.0 → 1.0.2

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.
@@ -0,0 +1,3 @@
1
+ export * from './schemas';
2
+ export * from './repositories';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schemas"), exports);
18
+ __exportStar(require("./repositories"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,iDAA+B"}
@@ -0,0 +1,3 @@
1
+ export * from './mongoose-outbox.repository';
2
+ export * from './mongoose-inbox.repository';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mongoose-outbox.repository"), exports);
18
+ __exportStar(require("./mongoose-inbox.repository"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,8DAA4C"}
@@ -0,0 +1,15 @@
1
+ import { CreateInboxMessageDto, IInboxRepository, RecordInboxMessageResult } from '@prodforcode/event-forge-core';
2
+ import { Model } from 'mongoose';
3
+ import { InboxMessageDocument } from '../schemas/inbox-message.schema';
4
+ export declare class MongooseInboxRepository implements IInboxRepository {
5
+ private readonly model;
6
+ constructor(model: Model<InboxMessageDocument>);
7
+ record(dto: CreateInboxMessageDto): Promise<RecordInboxMessageResult>;
8
+ exists(messageId: string, source: string): Promise<boolean>;
9
+ markProcessing(id: string): Promise<void>;
10
+ markProcessed(id: string): Promise<void>;
11
+ markFailed(id: string, error: string): Promise<void>;
12
+ deleteOlderThan(date: Date): Promise<number>;
13
+ private toInboxMessage;
14
+ }
15
+ //# sourceMappingURL=mongoose-inbox.repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-inbox.repository.d.ts","sourceRoot":"","sources":["../../src/repositories/mongoose-inbox.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAGhB,wBAAwB,EACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAMvE,qBAAa,uBAAwB,YAAW,gBAAgB;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC;IAEzD,MAAM,CAAC,GAAG,EAAE,qBAAqB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA8DrE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS3D,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYpD,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAYlD,OAAO,CAAC,cAAc;CAYvB"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseInboxRepository = void 0;
4
+ const event_forge_core_1 = require("@prodforcode/event-forge-core");
5
+ class MongooseInboxRepository {
6
+ model;
7
+ constructor(model) {
8
+ this.model = model;
9
+ }
10
+ async record(dto) {
11
+ const existing = await this.model.findOne({
12
+ messageId: dto.messageId,
13
+ source: dto.source,
14
+ });
15
+ if (existing) {
16
+ const message = this.toInboxMessage(existing);
17
+ return {
18
+ message,
19
+ isDuplicate: true,
20
+ };
21
+ }
22
+ const document = new this.model({
23
+ messageId: dto.messageId,
24
+ source: dto.source,
25
+ eventType: dto.eventType,
26
+ payload: dto.payload,
27
+ status: event_forge_core_1.InboxMessageStatus.RECEIVED,
28
+ });
29
+ try {
30
+ const saved = await document.save();
31
+ const message = this.toInboxMessage(saved);
32
+ return {
33
+ message,
34
+ isDuplicate: false,
35
+ };
36
+ }
37
+ catch (error) {
38
+ if (error.code === 11000) {
39
+ const existing = await this.model.findOne({
40
+ messageId: dto.messageId,
41
+ source: dto.source,
42
+ });
43
+ if (!existing) {
44
+ throw new Error(`Race condition: Duplicate key error but message not found for messageId=${dto.messageId}, source=${dto.source}`);
45
+ }
46
+ const message = this.toInboxMessage(existing);
47
+ return {
48
+ message,
49
+ isDuplicate: true,
50
+ };
51
+ }
52
+ throw error;
53
+ }
54
+ }
55
+ async exists(messageId, source) {
56
+ const count = await this.model.countDocuments({
57
+ messageId,
58
+ source,
59
+ });
60
+ return count > 0;
61
+ }
62
+ async markProcessing(id) {
63
+ await this.model.updateOne({ _id: id }, {
64
+ $set: {
65
+ status: event_forge_core_1.InboxMessageStatus.PROCESSING,
66
+ },
67
+ });
68
+ }
69
+ async markProcessed(id) {
70
+ await this.model.updateOne({ _id: id }, {
71
+ $set: {
72
+ status: event_forge_core_1.InboxMessageStatus.PROCESSED,
73
+ processedAt: new Date(),
74
+ },
75
+ });
76
+ }
77
+ async markFailed(id, error) {
78
+ await this.model.updateOne({ _id: id }, {
79
+ $set: {
80
+ status: event_forge_core_1.InboxMessageStatus.FAILED,
81
+ errorMessage: error,
82
+ },
83
+ });
84
+ }
85
+ async deleteOlderThan(date) {
86
+ const result = await this.model.deleteMany({
87
+ status: event_forge_core_1.InboxMessageStatus.PROCESSED,
88
+ createdAt: { $lt: date },
89
+ });
90
+ return result.deletedCount;
91
+ }
92
+ toInboxMessage(doc) {
93
+ return {
94
+ id: doc._id.toString(),
95
+ messageId: doc.messageId,
96
+ source: doc.source,
97
+ eventType: doc.eventType,
98
+ payload: doc.payload,
99
+ status: doc.status,
100
+ errorMessage: doc.errorMessage ?? undefined,
101
+ createdAt: doc.createdAt,
102
+ };
103
+ }
104
+ }
105
+ exports.MongooseInboxRepository = MongooseInboxRepository;
106
+ //# sourceMappingURL=mongoose-inbox.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-inbox.repository.js","sourceRoot":"","sources":["../../src/repositories/mongoose-inbox.repository.ts"],"names":[],"mappings":";;;AAAA,oEAMuC;AASvC,MAAa,uBAAuB;IACL;IAA7B,YAA6B,KAAkC;QAAlC,UAAK,GAAL,KAAK,CAA6B;IAAG,CAAC;IAEnE,KAAK,CAAC,MAAM,CAAC,GAA0B;QAErC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YACxC,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,MAAM,EAAE,GAAG,CAAC,MAAM;SACnB,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YAEb,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,QAAgC,CAAC,CAAC;YACtE,OAAO;gBAEL,OAAO;gBACP,WAAW,EAAE,IAAI;aAClB,CAAC;QACJ,CAAC;QAGD,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;YAC9B,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,qCAAkB,CAAC,QAAQ;SACpC,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,KAA6B,CAAC,CAA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qCAAkB,CAAC,SAAS;gBACpC,WAAW,EAAE,IAAI,IAAI,EAAE;aACxB;SACF,CACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU,EAAE,KAAa;QACxC,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CACxB,EAAE,GAAG,EAAE,EAAE,EAAE,EACX;YACE,IAAI,EAAE;gBACJ,MAAM,EAAE,qCAAkB,CAAC,MAAM;gBACjC,YAAY,EAAE,KAAK;aACpB;SACF,CACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,IAAU;QAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;YACzC,MAAM,EAAE,qCAAkB,CAAC,SAAS;YACpC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;SACzB,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC;IAKO,cAAc,CAAC,GAAyB;QAC9C,OAAO;YACL,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,SAAS;YAC3C,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC;CACF;AArID,0DAqIC"}
@@ -0,0 +1,18 @@
1
+ import { CreateOutboxMessageDto, IOutboxRepository, OutboxMessage } from '@prodforcode/event-forge-core';
2
+ import { Connection, Model } from 'mongoose';
3
+ import { OutboxMessageDocument } from '../schemas/outbox-message.schema';
4
+ export declare class MongooseOutboxRepository implements IOutboxRepository {
5
+ private readonly connection;
6
+ private readonly model;
7
+ constructor(connection: Connection, model: Model<OutboxMessageDocument>);
8
+ create(dto: CreateOutboxMessageDto, transactionContext?: unknown): Promise<OutboxMessage>;
9
+ fetchAndLockPending(limit: number, lockerId: string): Promise<OutboxMessage[]>;
10
+ markPublished(id: string): Promise<void>;
11
+ markFailed(id: string, error: string, permanent?: boolean): Promise<void>;
12
+ releaseLock(id: string): Promise<void>;
13
+ releaseStaleLocks(olderThan: Date): Promise<number>;
14
+ deleteOlderThan(date: Date): Promise<number>;
15
+ withTransaction<T>(operation: (context: unknown) => Promise<T>): Promise<T>;
16
+ private toOutboxMessage;
17
+ }
18
+ //# sourceMappingURL=mongoose-outbox.repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-outbox.repository.d.ts","sourceRoot":"","sources":["../../src/repositories/mongoose-outbox.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EAEd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAiB,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAMzE,qBAAa,wBAAyB,YAAW,iBAAiB;IAE9D,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,CAAC,qBAAqB,CAAC;IAGhD,MAAM,CACV,GAAG,EAAE,sBAAsB,EAC3B,kBAAkB,CAAC,EAAE,OAAO,GAC3B,OAAO,CAAC,aAAa,CAAC;IAmBnB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAwC9E,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BvE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAatC,iBAAiB,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBnD,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAS5C,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAmBjF,OAAO,CAAC,eAAe;CAmBxB"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseOutboxRepository = void 0;
4
+ const event_forge_core_1 = require("@prodforcode/event-forge-core");
5
+ class MongooseOutboxRepository {
6
+ connection;
7
+ model;
8
+ constructor(connection, model) {
9
+ this.connection = connection;
10
+ this.model = model;
11
+ }
12
+ async create(dto, transactionContext) {
13
+ const session = transactionContext;
14
+ const document = new this.model({
15
+ aggregateType: dto.aggregateType,
16
+ aggregateId: dto.aggregateId,
17
+ eventType: dto.eventType,
18
+ payload: dto.payload,
19
+ metadata: dto.metadata,
20
+ scheduledAt: dto.scheduledAt,
21
+ maxRetries: dto.maxRetries ?? 3,
22
+ status: event_forge_core_1.OutboxMessageStatus.PENDING,
23
+ retryCount: 0,
24
+ });
25
+ const saved = await document.save({ session });
26
+ return this.toOutboxMessage(saved);
27
+ }
28
+ async fetchAndLockPending(limit, lockerId) {
29
+ const now = new Date();
30
+ const lockTimeout = new Date(Date.now() - 5 * 60 * 1000);
31
+ const messages = [];
32
+ for (let i = 0; i < limit; i++) {
33
+ const message = await this.model.findOneAndUpdate({
34
+ status: { $in: [event_forge_core_1.OutboxMessageStatus.PENDING, event_forge_core_1.OutboxMessageStatus.FAILED] },
35
+ $and: [
36
+ { $or: [{ scheduledAt: null }, { scheduledAt: { $lte: now } }] },
37
+ { $or: [{ lockedAt: null }, { lockedAt: { $lt: lockTimeout } }] },
38
+ ],
39
+ }, {
40
+ $set: {
41
+ status: event_forge_core_1.OutboxMessageStatus.PROCESSING,
42
+ lockedBy: lockerId,
43
+ lockedAt: new Date(),
44
+ },
45
+ }, {
46
+ new: true,
47
+ sort: { createdAt: 1 },
48
+ });
49
+ if (!message) {
50
+ break;
51
+ }
52
+ messages.push(message);
53
+ }
54
+ return messages.map((doc) => this.toOutboxMessage(doc));
55
+ }
56
+ async markPublished(id) {
57
+ await this.model.updateOne({ _id: id }, {
58
+ $set: {
59
+ status: event_forge_core_1.OutboxMessageStatus.PUBLISHED,
60
+ lockedBy: null,
61
+ lockedAt: null,
62
+ },
63
+ });
64
+ }
65
+ async markFailed(id, error, permanent = false) {
66
+ const message = await this.model.findById(id);
67
+ if (!message) {
68
+ return;
69
+ }
70
+ const status = permanent
71
+ ? event_forge_core_1.OutboxMessageStatus.PERMANENTLY_FAILED
72
+ : event_forge_core_1.OutboxMessageStatus.FAILED;
73
+ await this.model.updateOne({ _id: id }, {
74
+ $set: {
75
+ status,
76
+ errorMessage: error,
77
+ lockedBy: null,
78
+ lockedAt: null,
79
+ },
80
+ $inc: {
81
+ retryCount: 1,
82
+ },
83
+ });
84
+ }
85
+ async releaseLock(id) {
86
+ await this.model.updateOne({ _id: id }, {
87
+ $set: {
88
+ status: event_forge_core_1.OutboxMessageStatus.PENDING,
89
+ lockedBy: null,
90
+ lockedAt: null,
91
+ },
92
+ });
93
+ }
94
+ async releaseStaleLocks(olderThan) {
95
+ const result = await this.model.updateMany({
96
+ status: event_forge_core_1.OutboxMessageStatus.PROCESSING,
97
+ lockedAt: { $lt: olderThan },
98
+ }, {
99
+ $set: {
100
+ status: event_forge_core_1.OutboxMessageStatus.PENDING,
101
+ lockedBy: null,
102
+ lockedAt: null,
103
+ },
104
+ });
105
+ return result.modifiedCount;
106
+ }
107
+ async deleteOlderThan(date) {
108
+ const result = await this.model.deleteMany({
109
+ status: event_forge_core_1.OutboxMessageStatus.PUBLISHED,
110
+ createdAt: { $lt: date },
111
+ });
112
+ return result.deletedCount;
113
+ }
114
+ async withTransaction(operation) {
115
+ const session = await this.connection.startSession();
116
+ session.startTransaction();
117
+ try {
118
+ const result = await operation(session);
119
+ await session.commitTransaction();
120
+ return result;
121
+ }
122
+ catch (error) {
123
+ await session.abortTransaction();
124
+ throw error;
125
+ }
126
+ finally {
127
+ await session.endSession();
128
+ }
129
+ }
130
+ toOutboxMessage(doc) {
131
+ return {
132
+ id: doc._id.toString(),
133
+ aggregateType: doc.aggregateType,
134
+ aggregateId: doc.aggregateId,
135
+ eventType: doc.eventType,
136
+ payload: doc.payload,
137
+ metadata: doc.metadata ?? {},
138
+ status: doc.status,
139
+ retryCount: doc.retryCount,
140
+ maxRetries: doc.maxRetries,
141
+ errorMessage: doc.errorMessage ?? undefined,
142
+ scheduledAt: doc.scheduledAt ?? undefined,
143
+ lockedBy: doc.lockedBy ?? undefined,
144
+ lockedAt: doc.lockedAt ?? undefined,
145
+ createdAt: doc.createdAt,
146
+ updatedAt: doc.updatedAt,
147
+ };
148
+ }
149
+ }
150
+ exports.MongooseOutboxRepository = MongooseOutboxRepository;
151
+ //# sourceMappingURL=mongoose-outbox.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoose-outbox.repository.js","sourceRoot":"","sources":["../../src/repositories/mongoose-outbox.repository.ts"],"names":[],"mappings":";;;AAAA,oEAKuC;AASvC,MAAa,wBAAwB;IAEhB;IACA;IAFnB,YACmB,UAAsB,EACtB,KAAmC;QADnC,eAAU,GAAV,UAAU,CAAY;QACtB,UAAK,GAAL,KAAK,CAA8B;IACnD,CAAC;IAEJ,KAAK,CAAC,MAAM,CACV,GAA2B,EAC3B,kBAA4B;QAE5B,MAAM,OAAO,GAAG,kBAA+C,CAAC;QAEhE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;YAC9B,aAAa,EAAE,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AAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAClC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACjC,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAKO,eAAe,CAAC,GAA0B;QAChD,OAAO;YACL,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtB,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE;YAC5B,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,SAAS;YAC3C,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,SAAS;YACzC,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,SAAS;YACnC,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,SAAS;YACnC,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC;CACF;AA1LD,4DA0LC"}
@@ -0,0 +1,18 @@
1
+ import { InboxMessage } from '@prodforcode/event-forge-core';
2
+ import { Schema, Document, Model, Types } from 'mongoose';
3
+ export interface InboxMessageDocument extends Omit<Document, 'id'>, Omit<InboxMessage, 'id'> {
4
+ _id: Types.ObjectId;
5
+ createdAt: Date;
6
+ updatedAt: Date;
7
+ }
8
+ export declare const InboxMessageSchema: Schema<InboxMessageDocument, Model<InboxMessageDocument, any, any, any, Document<unknown, any, InboxMessageDocument, any, {}> & InboxMessageDocument & Required<{
9
+ _id: Types.ObjectId;
10
+ }> & {
11
+ __v: number;
12
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, InboxMessageDocument, Document<unknown, {}, import("mongoose").FlatRecord<InboxMessageDocument>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<InboxMessageDocument> & Required<{
13
+ _id: Types.ObjectId;
14
+ }> & {
15
+ __v: number;
16
+ }>;
17
+ export type InboxMessageModel = Model<InboxMessageDocument>;
18
+ //# sourceMappingURL=inbox-message.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-message.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/inbox-message.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsB,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;IAC1F,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAKD,eAAO,MAAM,kBAAkB;;;;;;;;EAuC9B,CAAC;AA6CF,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InboxMessageSchema = void 0;
4
+ const event_forge_core_1 = require("@prodforcode/event-forge-core");
5
+ const mongoose_1 = require("mongoose");
6
+ exports.InboxMessageSchema = new mongoose_1.Schema({
7
+ messageId: {
8
+ type: String,
9
+ required: true,
10
+ },
11
+ source: {
12
+ type: String,
13
+ required: true,
14
+ },
15
+ eventType: {
16
+ type: String,
17
+ required: true,
18
+ index: true,
19
+ },
20
+ payload: {
21
+ type: mongoose_1.Schema.Types.Mixed,
22
+ required: true,
23
+ },
24
+ status: {
25
+ type: String,
26
+ enum: Object.values(event_forge_core_1.InboxMessageStatus),
27
+ default: event_forge_core_1.InboxMessageStatus.RECEIVED,
28
+ index: true,
29
+ },
30
+ errorMessage: {
31
+ type: String,
32
+ default: null,
33
+ },
34
+ processedAt: {
35
+ type: Date,
36
+ default: null,
37
+ index: true,
38
+ },
39
+ }, {
40
+ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' },
41
+ collection: 'inbox_messages',
42
+ });
43
+ exports.InboxMessageSchema.index({
44
+ messageId: 1,
45
+ source: 1,
46
+ }, {
47
+ unique: true,
48
+ name: 'idx_inbox_message_source_unique',
49
+ });
50
+ exports.InboxMessageSchema.index({
51
+ eventType: 1,
52
+ createdAt: 1,
53
+ }, {
54
+ name: 'idx_inbox_event_type',
55
+ });
56
+ exports.InboxMessageSchema.index({
57
+ status: 1,
58
+ createdAt: 1,
59
+ }, {
60
+ name: 'idx_inbox_cleanup',
61
+ });
62
+ //# sourceMappingURL=inbox-message.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-message.schema.js","sourceRoot":"","sources":["../../src/schemas/inbox-message.schema.ts"],"names":[],"mappings":";;;AAAA,oEAAiF;AACjF,uCAA0D;AAc7C,QAAA,kBAAkB,GAAG,IAAI,iBAAM,CAC1C;IACE,SAAS,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;KACZ;IACD,OAAO,EAAE;QACP,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,KAAK;QACxB,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,qCAAkB,CAAC;QACvC,OAAO,EAAE,qCAAkB,CAAC,QAAQ;QACpC,KAAK,EAAE,IAAI;KACZ;IACD,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;KACd;IACD,WAAW,EAAE;QACX,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,IAAI;KACZ;CACF,EACD;IACE,UAAU,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE;IAC9D,UAAU,EAAE,gBAAgB;CAC7B,CACF,CAAC;AAKF,0BAAkB,CAAC,KAAK,CACtB;IACE,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;CACV,EACD;IACE,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,iCAAiC;CACxC,CACF,CAAC;AAKF,0BAAkB,CAAC,KAAK,CACtB;IACE,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;CACb,EACD;IACE,IAAI,EAAE,sBAAsB;CAC7B,CACF,CAAC;AAKF,0BAAkB,CAAC,KAAK,CACtB;IACE,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;CACb,EACD;IACE,IAAI,EAAE,mBAAmB;CAC1B,CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './outbox-message.schema';
2
+ export * from './inbox-message.schema';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./outbox-message.schema"), exports);
18
+ __exportStar(require("./inbox-message.schema"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,yDAAuC"}
@@ -0,0 +1,18 @@
1
+ import { OutboxMessage } from '@prodforcode/event-forge-core';
2
+ import { Schema, Document, Model, Types } from 'mongoose';
3
+ export interface OutboxMessageDocument extends Omit<Document, 'id'>, Omit<OutboxMessage, 'id'> {
4
+ _id: Types.ObjectId;
5
+ createdAt: Date;
6
+ updatedAt: Date;
7
+ }
8
+ export declare const OutboxMessageSchema: Schema<OutboxMessageDocument, Model<OutboxMessageDocument, any, any, any, Document<unknown, any, OutboxMessageDocument, any, {}> & OutboxMessageDocument & Required<{
9
+ _id: Types.ObjectId;
10
+ }> & {
11
+ __v: number;
12
+ }, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, OutboxMessageDocument, Document<unknown, {}, import("mongoose").FlatRecord<OutboxMessageDocument>, {}, import("mongoose").ResolveSchemaOptions<import("mongoose").DefaultSchemaOptions>> & import("mongoose").FlatRecord<OutboxMessageDocument> & Required<{
13
+ _id: Types.ObjectId;
14
+ }> & {
15
+ __v: number;
16
+ }>;
17
+ export type OutboxMessageModel = Model<OutboxMessageDocument>;
18
+ //# sourceMappingURL=outbox-message.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox-message.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/outbox-message.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuB,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;IAC5F,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAMD,eAAO,MAAM,mBAAmB;;;;;;;;EA8D/B,CAAC;AA6EF,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutboxMessageSchema = void 0;
4
+ const event_forge_core_1 = require("@prodforcode/event-forge-core");
5
+ const mongoose_1 = require("mongoose");
6
+ exports.OutboxMessageSchema = new mongoose_1.Schema({
7
+ aggregateType: {
8
+ type: String,
9
+ required: true,
10
+ index: true,
11
+ },
12
+ aggregateId: {
13
+ type: String,
14
+ required: true,
15
+ index: true,
16
+ },
17
+ eventType: {
18
+ type: String,
19
+ required: true,
20
+ index: true,
21
+ },
22
+ payload: {
23
+ type: mongoose_1.Schema.Types.Mixed,
24
+ required: true,
25
+ },
26
+ metadata: {
27
+ type: mongoose_1.Schema.Types.Mixed,
28
+ default: {},
29
+ },
30
+ status: {
31
+ type: String,
32
+ enum: Object.values(event_forge_core_1.OutboxMessageStatus),
33
+ default: event_forge_core_1.OutboxMessageStatus.PENDING,
34
+ index: true,
35
+ },
36
+ retryCount: {
37
+ type: Number,
38
+ default: 0,
39
+ },
40
+ maxRetries: {
41
+ type: Number,
42
+ default: 3,
43
+ },
44
+ errorMessage: {
45
+ type: String,
46
+ default: null,
47
+ },
48
+ scheduledAt: {
49
+ type: Date,
50
+ default: null,
51
+ index: true,
52
+ },
53
+ lockedBy: {
54
+ type: String,
55
+ default: null,
56
+ },
57
+ lockedAt: {
58
+ type: Date,
59
+ default: null,
60
+ index: true,
61
+ },
62
+ }, {
63
+ timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' },
64
+ collection: 'outbox_messages',
65
+ });
66
+ exports.OutboxMessageSchema.index({
67
+ status: 1,
68
+ scheduledAt: 1,
69
+ createdAt: 1,
70
+ }, {
71
+ name: 'idx_outbox_pending_processing',
72
+ });
73
+ exports.OutboxMessageSchema.index({
74
+ status: 1,
75
+ createdAt: 1,
76
+ }, {
77
+ name: 'idx_outbox_cleanup',
78
+ });
79
+ exports.OutboxMessageSchema.index({
80
+ status: 1,
81
+ lockedAt: 1,
82
+ }, {
83
+ name: 'idx_outbox_stale_locks',
84
+ });
85
+ exports.OutboxMessageSchema.set('toJSON', {
86
+ virtuals: true,
87
+ versionKey: false,
88
+ transform: (_doc, ret) => {
89
+ ret.id = ret._id.toString();
90
+ delete ret._id;
91
+ return ret;
92
+ },
93
+ });
94
+ exports.OutboxMessageSchema.set('toObject', {
95
+ virtuals: true,
96
+ versionKey: false,
97
+ transform: (_doc, ret) => {
98
+ ret.id = ret._id.toString();
99
+ delete ret._id;
100
+ return ret;
101
+ },
102
+ });
103
+ //# sourceMappingURL=outbox-message.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox-message.schema.js","sourceRoot":"","sources":["../../src/schemas/outbox-message.schema.ts"],"names":[],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",
4
4
  "description": "Mongoose adapter for Universal Inbox-Outbox Pattern (MongoDB)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "mongoose": "^8.0.0",
20
- "@prodforcode/event-forge-core": "1.0.0"
20
+ "@prodforcode/event-forge-core": "1.0.2"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/jest": "^29.5.11",