@pikku/mongodb 0.12.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/CHANGELOG.md +15 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +9 -0
- package/dist/src/mongodb-agent-run-service.d.ts +21 -0
- package/dist/src/mongodb-agent-run-service.js +127 -0
- package/dist/src/mongodb-ai-storage-service.d.ts +41 -0
- package/dist/src/mongodb-ai-storage-service.js +408 -0
- package/dist/src/mongodb-channel-store.d.ts +19 -0
- package/dist/src/mongodb-channel-store.js +52 -0
- package/dist/src/mongodb-deployment-service.d.ts +17 -0
- package/dist/src/mongodb-deployment-service.js +75 -0
- package/dist/src/mongodb-eventhub-store.d.ts +13 -0
- package/dist/src/mongodb-eventhub-store.js +37 -0
- package/dist/src/mongodb-secret-service.d.ts +30 -0
- package/dist/src/mongodb-secret-service.js +110 -0
- package/dist/src/mongodb-workflow-run-service.d.ts +36 -0
- package/dist/src/mongodb-workflow-run-service.js +146 -0
- package/dist/src/mongodb-workflow-service.d.ts +55 -0
- package/dist/src/mongodb-workflow-service.js +351 -0
- package/dist/src/pikku-mongodb.d.ts +12 -0
- package/dist/src/pikku-mongodb.js +37 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -0
- package/run-tests.sh +53 -0
- package/src/index.ts +14 -0
- package/src/mongodb-agent-run-service.ts +206 -0
- package/src/mongodb-ai-storage-service.ts +576 -0
- package/src/mongodb-channel-store.ts +96 -0
- package/src/mongodb-deployment-service.ts +114 -0
- package/src/mongodb-eventhub-store.ts +52 -0
- package/src/mongodb-secret-service.ts +178 -0
- package/src/mongodb-services.test.ts +149 -0
- package/src/mongodb-workflow-run-service.ts +246 -0
- package/src/mongodb-workflow-service.ts +583 -0
- package/src/pikku-mongodb.ts +41 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { PikkuWorkflowService, } from '@pikku/core/workflow';
|
|
2
|
+
import { MongoDBWorkflowRunService } from './mongodb-workflow-run-service.js';
|
|
3
|
+
export class MongoDBWorkflowService extends PikkuWorkflowService {
|
|
4
|
+
initialized = false;
|
|
5
|
+
runService;
|
|
6
|
+
runs;
|
|
7
|
+
steps;
|
|
8
|
+
stepHistory;
|
|
9
|
+
versions;
|
|
10
|
+
constructor(db) {
|
|
11
|
+
super();
|
|
12
|
+
this.runService = new MongoDBWorkflowRunService(db);
|
|
13
|
+
this.runs = db.collection('workflow_runs');
|
|
14
|
+
this.steps = db.collection('workflow_step');
|
|
15
|
+
this.stepHistory = db.collection('workflow_step_history');
|
|
16
|
+
this.versions = db.collection('workflow_versions');
|
|
17
|
+
}
|
|
18
|
+
async init() {
|
|
19
|
+
if (this.initialized)
|
|
20
|
+
return;
|
|
21
|
+
await this.runs.createIndex({ workflow: 1 });
|
|
22
|
+
await this.runs.createIndex({ status: 1 });
|
|
23
|
+
await this.runs.createIndex({ createdAt: -1 });
|
|
24
|
+
await this.steps.createIndex({ workflowRunId: 1, stepName: 1 }, { unique: true });
|
|
25
|
+
await this.steps.createIndex({ workflowRunId: 1 });
|
|
26
|
+
await this.stepHistory.createIndex({ workflowStepId: 1 });
|
|
27
|
+
await this.stepHistory.createIndex({ createdAt: 1 });
|
|
28
|
+
await this.versions.createIndex({ workflowName: 1, graphHash: 1 }, { unique: true });
|
|
29
|
+
this.initialized = true;
|
|
30
|
+
}
|
|
31
|
+
async createRun(workflowName, input, inline, graphHash, wire) {
|
|
32
|
+
const id = crypto.randomUUID();
|
|
33
|
+
const now = new Date();
|
|
34
|
+
await this.runs.insertOne({
|
|
35
|
+
_id: id,
|
|
36
|
+
workflow: workflowName,
|
|
37
|
+
status: 'running',
|
|
38
|
+
input,
|
|
39
|
+
output: null,
|
|
40
|
+
error: null,
|
|
41
|
+
state: {},
|
|
42
|
+
inline,
|
|
43
|
+
graphHash,
|
|
44
|
+
wire,
|
|
45
|
+
createdAt: now,
|
|
46
|
+
updatedAt: now,
|
|
47
|
+
});
|
|
48
|
+
return id;
|
|
49
|
+
}
|
|
50
|
+
async getRun(id) {
|
|
51
|
+
return this.runService.getRun(id);
|
|
52
|
+
}
|
|
53
|
+
async updateRunStatus(id, status, output, error) {
|
|
54
|
+
await this.runs.updateOne({ _id: id }, {
|
|
55
|
+
$set: {
|
|
56
|
+
status,
|
|
57
|
+
output: output ?? null,
|
|
58
|
+
error: error ?? null,
|
|
59
|
+
updatedAt: new Date(),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async insertStepState(runId, stepName, rpcName, data, stepOptions) {
|
|
64
|
+
const stepId = crypto.randomUUID();
|
|
65
|
+
const now = new Date();
|
|
66
|
+
await this.steps.insertOne({
|
|
67
|
+
_id: stepId,
|
|
68
|
+
workflowRunId: runId,
|
|
69
|
+
stepName,
|
|
70
|
+
rpcName,
|
|
71
|
+
data: data ?? null,
|
|
72
|
+
status: 'pending',
|
|
73
|
+
result: null,
|
|
74
|
+
error: null,
|
|
75
|
+
branchTaken: null,
|
|
76
|
+
retries: stepOptions?.retries ?? null,
|
|
77
|
+
retryDelay: stepOptions?.retryDelay?.toString() ?? null,
|
|
78
|
+
createdAt: now,
|
|
79
|
+
updatedAt: now,
|
|
80
|
+
});
|
|
81
|
+
await this.insertHistoryRecord(stepId, 'pending');
|
|
82
|
+
return {
|
|
83
|
+
stepId,
|
|
84
|
+
status: 'pending',
|
|
85
|
+
result: undefined,
|
|
86
|
+
error: undefined,
|
|
87
|
+
attemptCount: 1,
|
|
88
|
+
retries: stepOptions?.retries,
|
|
89
|
+
retryDelay: stepOptions?.retryDelay?.toString(),
|
|
90
|
+
createdAt: now,
|
|
91
|
+
updatedAt: now,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async getStepState(runId, stepName) {
|
|
95
|
+
const row = await this.steps.findOne({
|
|
96
|
+
workflowRunId: runId,
|
|
97
|
+
stepName,
|
|
98
|
+
});
|
|
99
|
+
if (!row) {
|
|
100
|
+
throw new Error(`Step not found: runId=${runId}, stepName=${stepName}. Use insertStepState to create it.`);
|
|
101
|
+
}
|
|
102
|
+
const attemptCount = await this.stepHistory.countDocuments({
|
|
103
|
+
workflowStepId: row._id,
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
stepId: row._id,
|
|
107
|
+
status: row.status,
|
|
108
|
+
result: row.result ?? undefined,
|
|
109
|
+
error: row.error ?? undefined,
|
|
110
|
+
attemptCount,
|
|
111
|
+
retries: row.retries != null ? Number(row.retries) : undefined,
|
|
112
|
+
retryDelay: row.retryDelay ?? undefined,
|
|
113
|
+
createdAt: new Date(row.createdAt),
|
|
114
|
+
updatedAt: new Date(row.updatedAt),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async getRunHistory(runId) {
|
|
118
|
+
return this.runService.getRunHistory(runId);
|
|
119
|
+
}
|
|
120
|
+
async setStepRunning(stepId) {
|
|
121
|
+
await this.steps.updateOne({ _id: stepId }, { $set: { status: 'running', updatedAt: new Date() } });
|
|
122
|
+
const latestHistory = await this.stepHistory
|
|
123
|
+
.find({ workflowStepId: stepId })
|
|
124
|
+
.sort({ createdAt: -1 })
|
|
125
|
+
.limit(1)
|
|
126
|
+
.toArray();
|
|
127
|
+
if (latestHistory.length > 0) {
|
|
128
|
+
await this.stepHistory.updateOne({ _id: latestHistory[0]._id }, { $set: { status: 'running' } });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async setStepScheduled(stepId) {
|
|
132
|
+
await this.steps.updateOne({ _id: stepId }, { $set: { status: 'scheduled', updatedAt: new Date() } });
|
|
133
|
+
}
|
|
134
|
+
async insertHistoryRecord(stepId, status, result, error) {
|
|
135
|
+
const now = new Date();
|
|
136
|
+
const doc = {
|
|
137
|
+
_id: crypto.randomUUID(),
|
|
138
|
+
workflowStepId: stepId,
|
|
139
|
+
status,
|
|
140
|
+
result: result ?? null,
|
|
141
|
+
error: error ?? null,
|
|
142
|
+
createdAt: now,
|
|
143
|
+
runningAt: null,
|
|
144
|
+
scheduledAt: null,
|
|
145
|
+
succeededAt: null,
|
|
146
|
+
failedAt: null,
|
|
147
|
+
};
|
|
148
|
+
const timestampField = this.getTimestampFieldForStatus(status);
|
|
149
|
+
if (timestampField !== 'createdAt') {
|
|
150
|
+
doc[timestampField] = now;
|
|
151
|
+
}
|
|
152
|
+
await this.stepHistory.insertOne(doc);
|
|
153
|
+
}
|
|
154
|
+
getTimestampFieldForStatus(status) {
|
|
155
|
+
switch (status) {
|
|
156
|
+
case 'running':
|
|
157
|
+
return 'runningAt';
|
|
158
|
+
case 'scheduled':
|
|
159
|
+
return 'scheduledAt';
|
|
160
|
+
case 'succeeded':
|
|
161
|
+
return 'succeededAt';
|
|
162
|
+
case 'failed':
|
|
163
|
+
return 'failedAt';
|
|
164
|
+
default:
|
|
165
|
+
return 'createdAt';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async setStepResult(stepId, result) {
|
|
169
|
+
await this.steps.updateOne({ _id: stepId }, {
|
|
170
|
+
$set: {
|
|
171
|
+
status: 'succeeded',
|
|
172
|
+
result,
|
|
173
|
+
error: null,
|
|
174
|
+
updatedAt: new Date(),
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const latestHistory = await this.stepHistory
|
|
178
|
+
.find({ workflowStepId: stepId })
|
|
179
|
+
.sort({ createdAt: -1 })
|
|
180
|
+
.limit(1)
|
|
181
|
+
.toArray();
|
|
182
|
+
if (latestHistory.length > 0) {
|
|
183
|
+
await this.stepHistory.updateOne({ _id: latestHistory[0]._id }, { $set: { status: 'succeeded', result } });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async setStepError(stepId, error) {
|
|
187
|
+
const serializedError = {
|
|
188
|
+
message: error.message,
|
|
189
|
+
stack: error.stack,
|
|
190
|
+
code: error.code,
|
|
191
|
+
};
|
|
192
|
+
await this.steps.updateOne({ _id: stepId }, {
|
|
193
|
+
$set: {
|
|
194
|
+
status: 'failed',
|
|
195
|
+
error: serializedError,
|
|
196
|
+
result: null,
|
|
197
|
+
updatedAt: new Date(),
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const latestHistory = await this.stepHistory
|
|
201
|
+
.find({ workflowStepId: stepId })
|
|
202
|
+
.sort({ createdAt: -1 })
|
|
203
|
+
.limit(1)
|
|
204
|
+
.toArray();
|
|
205
|
+
if (latestHistory.length > 0) {
|
|
206
|
+
await this.stepHistory.updateOne({ _id: latestHistory[0]._id }, { $set: { status: 'failed', error: serializedError } });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async createRetryAttempt(stepId, status) {
|
|
210
|
+
await this.steps.updateOne({ _id: stepId }, {
|
|
211
|
+
$set: {
|
|
212
|
+
status,
|
|
213
|
+
result: null,
|
|
214
|
+
error: null,
|
|
215
|
+
updatedAt: new Date(),
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
await this.insertHistoryRecord(stepId, status);
|
|
219
|
+
const row = await this.steps.findOne({ _id: stepId });
|
|
220
|
+
if (!row)
|
|
221
|
+
throw new Error(`Step not found: ${stepId}`);
|
|
222
|
+
const attemptCount = await this.stepHistory.countDocuments({
|
|
223
|
+
workflowStepId: stepId,
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
stepId: row._id,
|
|
227
|
+
status: row.status,
|
|
228
|
+
result: row.result ?? undefined,
|
|
229
|
+
error: row.error ?? undefined,
|
|
230
|
+
attemptCount,
|
|
231
|
+
retries: row.retries != null ? Number(row.retries) : undefined,
|
|
232
|
+
retryDelay: row.retryDelay ?? undefined,
|
|
233
|
+
createdAt: new Date(row.createdAt),
|
|
234
|
+
updatedAt: new Date(row.updatedAt),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
async withRunLock(id, fn) {
|
|
238
|
+
return fn();
|
|
239
|
+
}
|
|
240
|
+
async withStepLock(_runId, _stepName, fn) {
|
|
241
|
+
return fn();
|
|
242
|
+
}
|
|
243
|
+
async getCompletedGraphState(runId) {
|
|
244
|
+
const results = await this.steps
|
|
245
|
+
.find({
|
|
246
|
+
workflowRunId: runId,
|
|
247
|
+
status: { $in: ['succeeded', 'failed'] },
|
|
248
|
+
})
|
|
249
|
+
.toArray();
|
|
250
|
+
const completedNodeIds = [];
|
|
251
|
+
const failedNodeIds = [];
|
|
252
|
+
const branchKeys = {};
|
|
253
|
+
for (const row of results) {
|
|
254
|
+
const nodeId = row.stepName;
|
|
255
|
+
if (row.status === 'succeeded') {
|
|
256
|
+
completedNodeIds.push(nodeId);
|
|
257
|
+
if (row.branchTaken) {
|
|
258
|
+
branchKeys[nodeId] = row.branchTaken;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (row.status === 'failed') {
|
|
262
|
+
const maxAttempts = (row.retries ?? 0) + 1;
|
|
263
|
+
const attemptCount = await this.stepHistory.countDocuments({
|
|
264
|
+
workflowStepId: row._id,
|
|
265
|
+
});
|
|
266
|
+
if (attemptCount >= maxAttempts) {
|
|
267
|
+
failedNodeIds.push(nodeId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return { completedNodeIds, failedNodeIds, branchKeys };
|
|
272
|
+
}
|
|
273
|
+
async getNodesWithoutSteps(runId, nodeIds) {
|
|
274
|
+
if (nodeIds.length === 0)
|
|
275
|
+
return [];
|
|
276
|
+
const result = await this.steps
|
|
277
|
+
.find({
|
|
278
|
+
workflowRunId: runId,
|
|
279
|
+
stepName: { $in: nodeIds },
|
|
280
|
+
})
|
|
281
|
+
.project({ stepName: 1 })
|
|
282
|
+
.toArray();
|
|
283
|
+
const existingStepNames = new Set(result.map((r) => r.stepName));
|
|
284
|
+
return nodeIds.filter((id) => !existingStepNames.has(id));
|
|
285
|
+
}
|
|
286
|
+
async getNodeResults(runId, nodeIds) {
|
|
287
|
+
if (nodeIds.length === 0)
|
|
288
|
+
return {};
|
|
289
|
+
const result = await this.steps
|
|
290
|
+
.find({
|
|
291
|
+
workflowRunId: runId,
|
|
292
|
+
stepName: { $in: nodeIds },
|
|
293
|
+
status: 'succeeded',
|
|
294
|
+
})
|
|
295
|
+
.toArray();
|
|
296
|
+
const results = {};
|
|
297
|
+
for (const row of result) {
|
|
298
|
+
results[row.stepName] = row.result;
|
|
299
|
+
}
|
|
300
|
+
return results;
|
|
301
|
+
}
|
|
302
|
+
async setBranchTaken(stepId, branchKey) {
|
|
303
|
+
await this.steps.updateOne({ _id: stepId }, { $set: { branchTaken: branchKey, updatedAt: new Date() } });
|
|
304
|
+
}
|
|
305
|
+
async updateRunState(runId, name, value) {
|
|
306
|
+
await this.runs.updateOne({ _id: runId }, {
|
|
307
|
+
$set: {
|
|
308
|
+
[`state.${name}`]: value,
|
|
309
|
+
updatedAt: new Date(),
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async getRunState(runId) {
|
|
314
|
+
const row = await this.runs.findOne({ _id: runId }, { projection: { state: 1 } });
|
|
315
|
+
if (!row)
|
|
316
|
+
return {};
|
|
317
|
+
return row.state ?? {};
|
|
318
|
+
}
|
|
319
|
+
async upsertWorkflowVersion(name, graphHash, graph, source, status) {
|
|
320
|
+
await this.versions.updateOne({ workflowName: name, graphHash }, {
|
|
321
|
+
$setOnInsert: {
|
|
322
|
+
workflowName: name,
|
|
323
|
+
graphHash,
|
|
324
|
+
graph,
|
|
325
|
+
source,
|
|
326
|
+
status: status ?? 'active',
|
|
327
|
+
createdAt: new Date(),
|
|
328
|
+
},
|
|
329
|
+
}, { upsert: true });
|
|
330
|
+
}
|
|
331
|
+
async updateWorkflowVersionStatus(name, graphHash, status) {
|
|
332
|
+
await this.versions.updateOne({ workflowName: name, graphHash }, { $set: { status } });
|
|
333
|
+
}
|
|
334
|
+
async getWorkflowVersion(name, graphHash) {
|
|
335
|
+
return this.runService.getWorkflowVersion(name, graphHash);
|
|
336
|
+
}
|
|
337
|
+
async getAIGeneratedWorkflows(agentName) {
|
|
338
|
+
const filter = { source: 'ai-agent', status: 'active' };
|
|
339
|
+
if (agentName) {
|
|
340
|
+
const escaped = agentName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
341
|
+
filter.workflowName = { $regex: `^ai:${escaped}:` };
|
|
342
|
+
}
|
|
343
|
+
const docs = await this.versions.find(filter).toArray();
|
|
344
|
+
return docs.map((doc) => ({
|
|
345
|
+
workflowName: doc.workflowName,
|
|
346
|
+
graphHash: doc.graphHash,
|
|
347
|
+
graph: doc.graph,
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
async close() { }
|
|
351
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from '@pikku/core/services';
|
|
2
|
+
import { MongoClient, type MongoClientOptions, type Db } from 'mongodb';
|
|
3
|
+
export declare class PikkuMongoDB {
|
|
4
|
+
private logger;
|
|
5
|
+
private dbName;
|
|
6
|
+
db: Db;
|
|
7
|
+
private client;
|
|
8
|
+
private ownsConnection;
|
|
9
|
+
constructor(logger: Logger, clientOrUri: MongoClient | string, dbName: string, options?: MongoClientOptions);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { MongoClient } from 'mongodb';
|
|
2
|
+
export class PikkuMongoDB {
|
|
3
|
+
logger;
|
|
4
|
+
dbName;
|
|
5
|
+
db;
|
|
6
|
+
client;
|
|
7
|
+
ownsConnection;
|
|
8
|
+
constructor(logger, clientOrUri, dbName, options) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.dbName = dbName;
|
|
11
|
+
if (typeof clientOrUri === 'string') {
|
|
12
|
+
this.client = new MongoClient(clientOrUri, options);
|
|
13
|
+
this.ownsConnection = true;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.client = clientOrUri;
|
|
17
|
+
this.ownsConnection = false;
|
|
18
|
+
}
|
|
19
|
+
this.db = this.client.db(dbName);
|
|
20
|
+
}
|
|
21
|
+
async init() {
|
|
22
|
+
this.logger.info(`Connecting to MongoDB database: ${this.dbName}`);
|
|
23
|
+
try {
|
|
24
|
+
await this.client.db('admin').command({ ping: 1 });
|
|
25
|
+
this.logger.info('MongoDB connection successful');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
this.logger.error('Error connecting to MongoDB', error);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async close() {
|
|
33
|
+
if (this.ownsConnection) {
|
|
34
|
+
await this.client.close();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/mongodb-agent-run-service.ts","../src/mongodb-ai-storage-service.ts","../src/mongodb-channel-store.ts","../src/mongodb-deployment-service.ts","../src/mongodb-eventhub-store.ts","../src/mongodb-secret-service.ts","../src/mongodb-workflow-run-service.ts","../src/mongodb-workflow-service.ts","../src/pikku-mongodb.ts"],"version":"5.9.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pikku/mongodb",
|
|
3
|
+
"version": "0.12.1",
|
|
4
|
+
"author": "yasser.fadl@gmail.com",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"module": "dist/src/index.js",
|
|
7
|
+
"main": "dist/src/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"tsc": "tsc",
|
|
11
|
+
"ncu": "npx npm-check-updates",
|
|
12
|
+
"build": "tsc -b",
|
|
13
|
+
"test": "bash run-tests.sh",
|
|
14
|
+
"test:watch": "bash run-tests.sh --watch",
|
|
15
|
+
"test:coverage": "bash run-tests.sh --coverage",
|
|
16
|
+
"release": "npm run build && npm test"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@pikku/core": "^0.12.3"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"mongodb": "^6.12.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"mongodb": "^6.12.0",
|
|
26
|
+
"mongodb-memory-server": "^10.4.0",
|
|
27
|
+
"typescript": "^5.9"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/run-tests.sh
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Enable nullglob to handle cases where no files match the pattern
|
|
4
|
+
shopt -s nullglob
|
|
5
|
+
|
|
6
|
+
# Initialize variables for options
|
|
7
|
+
watch_mode=false
|
|
8
|
+
coverage_mode=false
|
|
9
|
+
|
|
10
|
+
# Parse command-line options
|
|
11
|
+
while [[ $# -gt 0 ]]; do
|
|
12
|
+
case $1 in
|
|
13
|
+
--watch)
|
|
14
|
+
watch_mode=true
|
|
15
|
+
shift
|
|
16
|
+
;;
|
|
17
|
+
--coverage)
|
|
18
|
+
coverage_mode=true
|
|
19
|
+
shift
|
|
20
|
+
;;
|
|
21
|
+
*)
|
|
22
|
+
echo "Unknown option: $1"
|
|
23
|
+
exit 1
|
|
24
|
+
;;
|
|
25
|
+
esac
|
|
26
|
+
done
|
|
27
|
+
|
|
28
|
+
# Define the pattern to match your test files
|
|
29
|
+
pattern="src/*.test.ts"
|
|
30
|
+
|
|
31
|
+
# Expand the pattern into an array of files
|
|
32
|
+
files=($(find src -type f -name "*.test.ts"))
|
|
33
|
+
|
|
34
|
+
# Check if any files matched the pattern
|
|
35
|
+
if [ ${#files[@]} -eq 0 ]; then
|
|
36
|
+
echo "No test files found matching pattern: $pattern"
|
|
37
|
+
exit 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Construct the node command
|
|
41
|
+
node_cmd="node --import tsx --test"
|
|
42
|
+
|
|
43
|
+
# Append options based on flags
|
|
44
|
+
if [ "$watch_mode" = true ]; then
|
|
45
|
+
node_cmd="$node_cmd --watch"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
if [ "$coverage_mode" = true ]; then
|
|
49
|
+
node_cmd="$node_cmd --test-coverage-include=\"src/**/*.{ts,js}\" --test-coverage-exclude=\"**/dist/**\" --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Execute the node command with the expanded list of files
|
|
53
|
+
$node_cmd "${files[@]}"
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { PikkuMongoDB } from './pikku-mongodb.js'
|
|
2
|
+
|
|
3
|
+
export { MongoDBChannelStore } from './mongodb-channel-store.js'
|
|
4
|
+
export { MongoDBEventHubStore } from './mongodb-eventhub-store.js'
|
|
5
|
+
export { MongoDBWorkflowService } from './mongodb-workflow-service.js'
|
|
6
|
+
export { MongoDBWorkflowRunService } from './mongodb-workflow-run-service.js'
|
|
7
|
+
export { MongoDBDeploymentService } from './mongodb-deployment-service.js'
|
|
8
|
+
export { MongoDBAIStorageService } from './mongodb-ai-storage-service.js'
|
|
9
|
+
export { MongoDBAgentRunService } from './mongodb-agent-run-service.js'
|
|
10
|
+
export { MongoDBSecretService } from './mongodb-secret-service.js'
|
|
11
|
+
export type { MongoDBSecretServiceConfig } from './mongodb-secret-service.js'
|
|
12
|
+
|
|
13
|
+
export type { WorkflowRunService } from '@pikku/core/workflow'
|
|
14
|
+
export type { AgentRunService, AgentRunRow } from '@pikku/core/ai-agent'
|