UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

63 lines 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuitesPersistenceVolatile = void 0; const SuiteNotFoundException_1 = require("../../exceptions/SuiteNotFoundException"); function deepCopy(suite) { return JSON.parse(JSON.stringify(suite)); } /** * A volatile (in-memory) implementation of SuitesPersistence. */ class SuitesPersistenceVolatile { constructor(suites = new Map()) { this.suites = suites; } async createSuite(suiteMetadata) { this.suites.set(suiteMetadata.id, deepCopy(suiteMetadata)); } async updateSuite(suiteMetadata) { if (!this.suites.has(suiteMetadata.id)) { throw SuiteNotFoundException_1.SuiteNotFoundException.forId(suiteMetadata.id); } this.suites.set(suiteMetadata.id, deepCopy(suiteMetadata)); } async getSuiteById(suiteId) { const metadata = this.suites.get(suiteId); if (!metadata) { throw SuiteNotFoundException_1.SuiteNotFoundException.forId(suiteId); } return deepCopy(metadata); } async getSuites(query) { const validLimit = Math.min(Math.max(1, query.limit ?? 100), 100); let filtered = Array.from(this.suites.values()); // partialName takes precedence over name if both are provided. if (query.partialName) { const lower = query.partialName.toLowerCase(); filtered = filtered.filter((s) => s.name?.toLowerCase().includes(lower)); } else if (query.name) { filtered = filtered.filter((s) => s.name === query.name); } const sortCol = query.sortBy ?? 'created_at'; const sortAsc = query.sortOrder === 'asc'; filtered.sort((a, b) => { const aVal = String(a[sortCol] ?? ''); const bVal = String(b[sortCol] ?? ''); const cmp = aVal < bVal ? -1 : aVal > bVal ? 1 : 0; return sortAsc ? cmp : -cmp; }); const offset = query.pageToken ? parseInt(query.pageToken, 10) : 0; const paged = filtered.slice(offset, offset + validLimit); const hasMore = offset + validLimit < filtered.length; return { items: paged.map(deepCopy), nextPageToken: hasMore ? (offset + validLimit).toString() : undefined, }; } async deleteSuite(suiteId) { this.suites.delete(suiteId); } } exports.SuitesPersistenceVolatile = SuitesPersistenceVolatile; //# sourceMappingURL=SuitesPersistenceVolatile.js.map