@multiplayer-app/ai-agent-db 0.1.0-beta.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/README.md +220 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/repositories/AgentChatRepository.d.ts +47 -0
- package/dist/repositories/AgentChatRepository.d.ts.map +1 -0
- package/dist/repositories/AgentChatRepository.js +2 -0
- package/dist/repositories/AgentChatRepository.js.map +1 -0
- package/dist/repositories/AgentMessageRepository.d.ts +41 -0
- package/dist/repositories/AgentMessageRepository.d.ts.map +1 -0
- package/dist/repositories/AgentMessageRepository.js +2 -0
- package/dist/repositories/AgentMessageRepository.js.map +1 -0
- package/dist/repositories/BaseRepository.d.ts +47 -0
- package/dist/repositories/BaseRepository.d.ts.map +1 -0
- package/dist/repositories/BaseRepository.js +2 -0
- package/dist/repositories/BaseRepository.js.map +1 -0
- package/dist/repositories/index.d.ts +4 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +4 -0
- package/dist/repositories/index.js.map +1 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @multiplayer-app/ai-agent-db
|
|
2
|
+
|
|
3
|
+
A database-agnostic repository abstraction layer for Multiplayer AI agent services. This library provides TypeScript interfaces for data access operations, allowing you to implement repository patterns for any database backend (MongoDB, PostgreSQL, MySQL, etc.).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Database-Agnostic Interfaces**: Abstract repository interfaces that work with any database
|
|
8
|
+
- **Type-Safe Operations**: Full TypeScript support with generic types
|
|
9
|
+
- **Repository Pattern**: Clean separation of data access logic from business logic
|
|
10
|
+
- **Specialized Repositories**: Domain-specific interfaces for `AgentChat` and `AgentMessage` entities
|
|
11
|
+
- **Flexible Querying**: Support for filtering, sorting, and pagination
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
- Node.js >= 18
|
|
16
|
+
- TypeScript >= 5.0
|
|
17
|
+
- A database implementation library (e.g., `@multiplayer-app/ai-agent-mongo` for MongoDB)
|
|
18
|
+
|
|
19
|
+
## Architecture
|
|
20
|
+
|
|
21
|
+
This library provides **interfaces only** - no concrete implementations. It follows the Repository pattern to abstract database operations, making your code database-agnostic and easily testable.
|
|
22
|
+
|
|
23
|
+
### Core Interfaces
|
|
24
|
+
|
|
25
|
+
#### `BaseRepository<T, ID>`
|
|
26
|
+
|
|
27
|
+
Generic interface providing standard CRUD operations:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
interface BaseRepository<T, ID = string> {
|
|
31
|
+
findById(id: ID): Promise<T | null>;
|
|
32
|
+
find(filter?: Partial<T>, options?: { sort?: { field: string; order: SortOrder }; limit?: number }): Promise<T[]>;
|
|
33
|
+
findOne(filter: Partial<T>): Promise<T | null>;
|
|
34
|
+
create(entity: Omit<T, 'id' | 'createdAt' | 'updatedAt'>, id?: string): Promise<T>;
|
|
35
|
+
update(id: ID, updates: Partial<Omit<T, 'id' | 'createdAt'>>): Promise<T | null>;
|
|
36
|
+
delete(id: ID): Promise<boolean>;
|
|
37
|
+
exists(id: ID): Promise<boolean>;
|
|
38
|
+
count(filter?: Partial<T>): Promise<number>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### `AgentChatRepository`
|
|
43
|
+
|
|
44
|
+
Extends `BaseRepository<AgentChat>` with chat-specific operations:
|
|
45
|
+
|
|
46
|
+
- `findByUserId(userId: string)`: Find all chats for a user
|
|
47
|
+
- `findByContextKey(contextKey: string)`: Find all chats for a context
|
|
48
|
+
- `findByUserIdAndContextKey(userId: string, contextKey: string)`: Find chats by user and context
|
|
49
|
+
- `findGuestChatsByContextKey(contextKey: string)`: Find guest chats (no userId)
|
|
50
|
+
- `updateTitle(id: string, title: string)`: Update chat title
|
|
51
|
+
- `deleteByUserId(userId: string)`: Delete all chats for a user
|
|
52
|
+
- `deleteByContextKey(contextKey: string)`: Delete all chats for a context
|
|
53
|
+
- `findWithMessages(...)`: Find chats with related messages (aggregation)
|
|
54
|
+
|
|
55
|
+
#### `AgentMessageRepository`
|
|
56
|
+
|
|
57
|
+
Extends `BaseRepository<AgentMessage>` with message-specific operations:
|
|
58
|
+
|
|
59
|
+
- `findByChatId(chatId: string)`: Find all messages for a chat
|
|
60
|
+
- `findByRole(role: MessageRole)`: Find messages by role
|
|
61
|
+
- `findByChatIdAndRole(chatId: string, role?: MessageRole)`: Find messages by chat and role
|
|
62
|
+
- `findWithToolCalls(chatId?: string)`: Find messages with tool calls
|
|
63
|
+
- `findWithAttachments(chatId?: string)`: Find messages with attachments
|
|
64
|
+
- `deleteByChatId(chatId: string)`: Delete all messages for a chat
|
|
65
|
+
- `deleteByRole(role: MessageRole)`: Delete messages by role
|
|
66
|
+
- `deleteByChatIdAndRole(chatId: string, role: MessageRole)`: Delete messages by chat and role
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
### Using with MongoDB Implementation
|
|
71
|
+
|
|
72
|
+
The easiest way to use this library is with the MongoDB implementation:
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MongoAgentChatRepository, MongoAgentMessageRepository } from '@multiplayer-app/ai-agent-mongo';
|
|
77
|
+
|
|
78
|
+
// Initialize repositories
|
|
79
|
+
const chatRepository = new MongoAgentChatRepository();
|
|
80
|
+
const messageRepository = new MongoAgentMessageRepository();
|
|
81
|
+
|
|
82
|
+
// Use the repositories
|
|
83
|
+
const chat = await chatRepository.findById('chat-id');
|
|
84
|
+
const messages = await messageRepository.findByChatId('chat-id');
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Implementing Your Own Repository
|
|
88
|
+
|
|
89
|
+
To implement these interfaces for a different database (e.g., PostgreSQL, MySQL):
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import type { AgentChatRepository } from '@multiplayer-app/ai-agent-db';
|
|
93
|
+
import type { AgentChat } from '@multiplayer-app/ai-agent-types';
|
|
94
|
+
|
|
95
|
+
export class PostgresAgentChatRepository implements AgentChatRepository {
|
|
96
|
+
async findById(id: string): Promise<AgentChat | null> {
|
|
97
|
+
// Your PostgreSQL implementation
|
|
98
|
+
const result = await db.query('SELECT * FROM chats WHERE id = $1', [id]);
|
|
99
|
+
return result.rows[0] || null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async find(
|
|
103
|
+
filter?: Partial<AgentChat>,
|
|
104
|
+
options?: { sort?: { field: string; order: SortOrder }; limit?: number }
|
|
105
|
+
): Promise<AgentChat[]> {
|
|
106
|
+
// Your implementation with filtering, sorting, and pagination
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Implement all other required methods...
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Example: Querying Chats
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import type { AgentChatRepository } from '@multiplayer-app/ai-agent-db';
|
|
117
|
+
|
|
118
|
+
// Find all chats for a user
|
|
119
|
+
const userChats = await chatRepository.findByUserId('user-123');
|
|
120
|
+
|
|
121
|
+
// Find chats with pagination and sorting
|
|
122
|
+
const recentChats = await chatRepository.find(
|
|
123
|
+
{ contextKey: 'my-context' },
|
|
124
|
+
{
|
|
125
|
+
sort: { field: 'updatedAt', order: SortOrder.Desc },
|
|
126
|
+
limit: 10
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Find chats with messages (aggregation)
|
|
131
|
+
const chatsWithMessages = await chatRepository.findWithMessages(
|
|
132
|
+
{ userId: 'user-123' },
|
|
133
|
+
{ sort: { field: 'createdAt', order: SortOrder.Desc } }
|
|
134
|
+
);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Example: Managing Messages
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import type { AgentMessageRepository } from '@multiplayer-app/ai-agent-db';
|
|
141
|
+
|
|
142
|
+
// Find all messages in a chat
|
|
143
|
+
const messages = await messageRepository.findByChatId('chat-id');
|
|
144
|
+
|
|
145
|
+
// Find only assistant messages
|
|
146
|
+
const assistantMessages = await messageRepository.findByChatIdAndRole(
|
|
147
|
+
'chat-id',
|
|
148
|
+
MessageRole.Assistant
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Find messages with tool calls
|
|
152
|
+
const toolCallMessages = await messageRepository.findWithToolCalls('chat-id');
|
|
153
|
+
|
|
154
|
+
// Create a new message
|
|
155
|
+
const newMessage = await messageRepository.create({
|
|
156
|
+
chat: 'chat-id',
|
|
157
|
+
role: MessageRole.User,
|
|
158
|
+
content: 'Hello, AI!'
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Database Access Patterns
|
|
163
|
+
|
|
164
|
+
### Generic Repository Pattern
|
|
165
|
+
|
|
166
|
+
The `BaseRepository` interface provides a consistent API across all entity types:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Works with any entity type
|
|
170
|
+
const repository: BaseRepository<MyEntity> = getRepository();
|
|
171
|
+
|
|
172
|
+
// Standard CRUD operations
|
|
173
|
+
const entity = await repository.findById('id');
|
|
174
|
+
const entities = await repository.find({ status: 'active' });
|
|
175
|
+
const created = await repository.create({ name: 'New Entity' });
|
|
176
|
+
const updated = await repository.update('id', { name: 'Updated' });
|
|
177
|
+
const deleted = await repository.delete('id');
|
|
178
|
+
const exists = await repository.exists('id');
|
|
179
|
+
const count = await repository.count({ status: 'active' });
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### MongoDB Example
|
|
183
|
+
|
|
184
|
+
See `@multiplayer-app/ai-agent-mongo` for a complete MongoDB implementation using Mongoose:
|
|
185
|
+
|
|
186
|
+
- Uses Mongoose schemas and models
|
|
187
|
+
- Handles ObjectId conversion
|
|
188
|
+
- Implements aggregation pipelines for complex queries
|
|
189
|
+
- Provides transaction support
|
|
190
|
+
|
|
191
|
+
## Type Safety
|
|
192
|
+
|
|
193
|
+
All interfaces are fully typed using TypeScript generics and types from `@multiplayer-app/ai-agent-types`:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import type { AgentChat, AgentMessage, SortOrder } from '@multiplayer-app/ai-agent-types';
|
|
197
|
+
import type { AgentChatRepository, AgentMessageRepository } from '@multiplayer-app/ai-agent-db';
|
|
198
|
+
|
|
199
|
+
// TypeScript ensures type safety
|
|
200
|
+
const chat: AgentChat = await chatRepository.findById('id');
|
|
201
|
+
const messages: AgentMessage[] = await messageRepository.findByChatId('chat-id');
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Best Practices
|
|
205
|
+
|
|
206
|
+
1. **Dependency Injection**: Pass repository instances to your services rather than creating them directly
|
|
207
|
+
2. **Error Handling**: Implement proper error handling in your repository implementations
|
|
208
|
+
3. **Transactions**: For databases that support it, implement transaction support in your repositories
|
|
209
|
+
4. **Caching**: Consider adding caching layers above the repository layer for frequently accessed data
|
|
210
|
+
5. **Testing**: Use the interfaces to create mock repositories for unit testing
|
|
211
|
+
|
|
212
|
+
## Related Packages
|
|
213
|
+
|
|
214
|
+
- `@multiplayer-app/ai-agent-types`: Type definitions for AgentChat, AgentMessage, etc.
|
|
215
|
+
- `@multiplayer-app/ai-agent-mongo`: MongoDB implementation of these interfaces
|
|
216
|
+
- `@multiplayer-app/ai-agent-node`: Node.js library that uses these repositories
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AgentChat, AgentChatResponse, SortOrder } from '@multiplayer-app/ai-agent-types';
|
|
2
|
+
import type { BaseRepository } from './BaseRepository';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract repository interface for AgentChat operations.
|
|
5
|
+
* Implement this interface for your specific database (MongoDB, PostgreSQL, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentChatRepository extends BaseRepository<AgentChat> {
|
|
8
|
+
/**
|
|
9
|
+
* Find all chats for a specific user
|
|
10
|
+
*/
|
|
11
|
+
findByUserId(userId: string): Promise<AgentChat[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Find all chats for a specific context key
|
|
14
|
+
*/
|
|
15
|
+
findByContextKey(contextKey: string): Promise<AgentChat[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Find chats by user ID and context key
|
|
18
|
+
*/
|
|
19
|
+
findByUserIdAndContextKey(userId: string, contextKey: string): Promise<AgentChat[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Find guest chats (chats without a userId) for a specific context key
|
|
22
|
+
*/
|
|
23
|
+
findGuestChatsByContextKey(contextKey: string): Promise<AgentChat[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Update chat title
|
|
26
|
+
*/
|
|
27
|
+
updateTitle(id: string, title: string): Promise<AgentChat | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Delete all chats for a specific user
|
|
30
|
+
*/
|
|
31
|
+
deleteByUserId(userId: string): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Delete all chats for a specific context key
|
|
34
|
+
*/
|
|
35
|
+
deleteByContextKey(contextKey: string): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Find chats with related messages using aggregation
|
|
38
|
+
*/
|
|
39
|
+
findWithMessages(filter?: Partial<AgentChat>, options?: {
|
|
40
|
+
sort?: {
|
|
41
|
+
field: string;
|
|
42
|
+
order: SortOrder;
|
|
43
|
+
};
|
|
44
|
+
limit?: number;
|
|
45
|
+
}): Promise<AgentChatResponse[]>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=AgentChatRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/AgentChatRepository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC/F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,cAAc,CAAC,SAAS,CAAC;IACpE;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAEnD;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAE3D;;OAEG;IACH,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAEpF;;OAEG;IACH,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAErE;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAElE;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhD;;OAEG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExD;;OAEG;IACH,gBAAgB,CACd,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAC3B,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,SAAS,CAAA;SAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACvE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatRepository.js","sourceRoot":"","sources":["../../src/repositories/AgentChatRepository.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AgentMessage, MessageRole } from '@multiplayer-app/ai-agent-types';
|
|
2
|
+
import type { BaseRepository } from './BaseRepository';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract repository interface for AgentMessage operations.
|
|
5
|
+
* Implement this interface for your specific database (MongoDB, PostgreSQL, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentMessageRepository extends BaseRepository<AgentMessage> {
|
|
8
|
+
/**
|
|
9
|
+
* Find all messages for a specific chat
|
|
10
|
+
*/
|
|
11
|
+
findByChatId(chatId: string): Promise<AgentMessage[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Find messages by role
|
|
14
|
+
*/
|
|
15
|
+
findByRole(role: MessageRole): Promise<AgentMessage[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Find messages by chat ID and optionally by role
|
|
18
|
+
*/
|
|
19
|
+
findByChatIdAndRole(chatId: string, role?: MessageRole): Promise<AgentMessage[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Find messages that have tool calls
|
|
22
|
+
*/
|
|
23
|
+
findWithToolCalls(chatId?: string): Promise<AgentMessage[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Find messages that have attachments
|
|
26
|
+
*/
|
|
27
|
+
findWithAttachments(chatId?: string): Promise<AgentMessage[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Delete all messages for a specific chat
|
|
30
|
+
*/
|
|
31
|
+
deleteByChatId(chatId: string): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Delete messages by role
|
|
34
|
+
*/
|
|
35
|
+
deleteByRole(role: MessageRole): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Delete messages by chat ID and role
|
|
38
|
+
*/
|
|
39
|
+
deleteByChatIdAndRole(chatId: string, role: MessageRole): Promise<number>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=AgentMessageRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentMessageRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/AgentMessageRepository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc,CAAC,YAAY,CAAC;IAC1E;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAEtD;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAEvD;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAEjF;;OAEG;IACH,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAE5D;;OAEG;IACH,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAE9D;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhD;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentMessageRepository.js","sourceRoot":"","sources":["../../src/repositories/AgentMessageRepository.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SortOrder } from "@multiplayer-app/ai-agent-types";
|
|
2
|
+
/**
|
|
3
|
+
* Base abstract repository interface for database operations.
|
|
4
|
+
* This provides a database-agnostic interface that can be implemented
|
|
5
|
+
* by concrete repositories for specific databases (MongoDB, PostgreSQL, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export interface BaseRepository<T, ID = string> {
|
|
8
|
+
/**
|
|
9
|
+
* Find an entity by its ID
|
|
10
|
+
*/
|
|
11
|
+
findById(id: ID): Promise<T | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Find all entities matching the given filter
|
|
14
|
+
*/
|
|
15
|
+
find(filter?: Partial<T>, options?: {
|
|
16
|
+
sort?: {
|
|
17
|
+
field: string;
|
|
18
|
+
order: SortOrder;
|
|
19
|
+
};
|
|
20
|
+
limit?: number;
|
|
21
|
+
}): Promise<T[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Find a single entity matching the given filter
|
|
24
|
+
*/
|
|
25
|
+
findOne(filter: Partial<T>): Promise<T | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new entity
|
|
28
|
+
*/
|
|
29
|
+
create(entity: Omit<T, 'id' | 'createdAt' | 'updatedAt'>, id?: string): Promise<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Update an entity by ID
|
|
32
|
+
*/
|
|
33
|
+
update(id: ID, updates: Partial<Omit<T, 'id' | 'createdAt'>>): Promise<T | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete an entity by ID
|
|
36
|
+
*/
|
|
37
|
+
delete(id: ID): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Check if an entity exists by ID
|
|
40
|
+
*/
|
|
41
|
+
exists(id: ID): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Count entities matching the given filter
|
|
44
|
+
*/
|
|
45
|
+
count(filter?: Partial<T>): Promise<number>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=BaseRepository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/BaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,MAAM;IAC5C;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAEpC;;OAEG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,SAAS,CAAA;SAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAElH;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAE/C;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEnF;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAEjF;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRepository.js","sourceRoot":"","sources":["../../src/repositories/BaseRepository.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@multiplayer-app/ai-agent-db",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "Shared MongoDB schemas and connection for Multiplayer AI agent services",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["dist", "README.md"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -p tsconfig.json"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@multiplayer-app/ai-agent-types": "0.0.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "5.9.3"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
}
|
|
22
|
+
}
|