mirror of
https://github.com/LukeHagar/arbiter.git
synced 2025-12-06 04:19:14 +00:00
formatting pass
This commit is contained in:
@@ -155,18 +155,13 @@ export async function startServers({
|
||||
const persisted = await storage().getAllEndpoints();
|
||||
for (const ep of persisted) {
|
||||
try {
|
||||
openApiStore.recordEndpoint(
|
||||
ep.path,
|
||||
ep.method.toLowerCase(),
|
||||
ep.data.request,
|
||||
{
|
||||
openApiStore.recordEndpoint(ep.path, ep.method.toLowerCase(), ep.data.request, {
|
||||
status: ep.data.response?.status || 200,
|
||||
headers: ep.data.response?.headers || {},
|
||||
contentType: ep.data.response?.contentType || 'application/json',
|
||||
body: '[Raw data stored]',
|
||||
rawData: Buffer.alloc(0),
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch {}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -401,7 +396,8 @@ export async function startServers({
|
||||
// Add the HAR entry to the store and persist if enabled
|
||||
harStore.addEntry(harEntry);
|
||||
if (dbPath) {
|
||||
storage().saveHarEntry({
|
||||
storage()
|
||||
.saveHarEntry({
|
||||
startedDateTime: harEntry.startedDateTime,
|
||||
time: harEntry.time,
|
||||
request: harEntry.request,
|
||||
@@ -409,7 +405,8 @@ export async function startServers({
|
||||
...harEntry.response,
|
||||
// Do not persist raw buffer reference
|
||||
},
|
||||
}).catch(() => {});
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
// Extract security schemes from headers - minimal work
|
||||
@@ -458,7 +455,8 @@ export async function startServers({
|
||||
|
||||
// Persist endpoint minimal info for reconstruction
|
||||
if (dbPath) {
|
||||
storage().upsertEndpoint(path, method.toLowerCase(), {
|
||||
storage()
|
||||
.upsertEndpoint(path, method.toLowerCase(), {
|
||||
path,
|
||||
method: method.toLowerCase(),
|
||||
request: {
|
||||
@@ -473,7 +471,8 @@ export async function startServers({
|
||||
headers: responseHeaders,
|
||||
contentType: responseHeaders['content-type'] || 'application/json',
|
||||
},
|
||||
}).catch(() => {});
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
@@ -514,17 +513,12 @@ export async function startServers({
|
||||
tempStore.setTargetUrl(target);
|
||||
for (const ep of persisted) {
|
||||
try {
|
||||
tempStore.recordEndpoint(
|
||||
ep.path,
|
||||
ep.method.toLowerCase(),
|
||||
ep.data.request,
|
||||
{
|
||||
tempStore.recordEndpoint(ep.path, ep.method.toLowerCase(), ep.data.request, {
|
||||
status: ep.data.response?.status || 200,
|
||||
headers: ep.data.response?.headers || {},
|
||||
contentType: ep.data.response?.contentType || 'application/json',
|
||||
body: '[Raw data stored]'
|
||||
}
|
||||
);
|
||||
body: '[Raw data stored]',
|
||||
});
|
||||
} catch {}
|
||||
}
|
||||
res.send(JSON.stringify(tempStore.getOpenAPISpec()));
|
||||
@@ -543,17 +537,12 @@ export async function startServers({
|
||||
tempStore.setTargetUrl(target);
|
||||
for (const ep of persisted) {
|
||||
try {
|
||||
tempStore.recordEndpoint(
|
||||
ep.path,
|
||||
ep.method.toLowerCase(),
|
||||
ep.data.request,
|
||||
{
|
||||
tempStore.recordEndpoint(ep.path, ep.method.toLowerCase(), ep.data.request, {
|
||||
status: ep.data.response?.status || 200,
|
||||
headers: ep.data.response?.headers || {},
|
||||
contentType: ep.data.response?.contentType || 'application/json',
|
||||
body: '[Raw data stored]'
|
||||
}
|
||||
);
|
||||
body: '[Raw data stored]',
|
||||
});
|
||||
} catch {}
|
||||
}
|
||||
res.send(tempStore.getOpenAPISpecAsYAML());
|
||||
|
||||
@@ -11,5 +11,3 @@ export async function initStorage(dbPath: string): Promise<StorageAdapter> {
|
||||
export function storage(): StorageAdapter {
|
||||
return storageInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,13 +75,21 @@ export class SQLiteStorage implements StorageAdapter {
|
||||
}
|
||||
|
||||
async getHarLog(): Promise<any> {
|
||||
const empty = { log: { version: '1.2', creator: { name: 'Arbiter', version: '1.0.0' }, entries: [] as any[] } };
|
||||
const empty = {
|
||||
log: { version: '1.2', creator: { name: 'Arbiter', version: '1.0.0' }, entries: [] as any[] },
|
||||
};
|
||||
if (!this.db) return empty;
|
||||
try {
|
||||
const rows: Array<{ startedDateTime: string; time: number; request: string; response: string }> = this.db
|
||||
const rows: Array<{
|
||||
startedDateTime: string;
|
||||
time: number;
|
||||
request: string;
|
||||
response: string;
|
||||
}> = this.db
|
||||
.prepare('SELECT startedDateTime, time, request, response FROM har_entries ORDER BY id ASC')
|
||||
.all();
|
||||
const entries = rows.map((r: { startedDateTime: string; time: number; request: string; response: string }) => {
|
||||
const entries = rows.map(
|
||||
(r: { startedDateTime: string; time: number; request: string; response: string }) => {
|
||||
let req: any = {};
|
||||
let res: any = {};
|
||||
try {
|
||||
@@ -96,7 +104,8 @@ export class SQLiteStorage implements StorageAdapter {
|
||||
request: req,
|
||||
response: res,
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
return { log: { ...empty.log, entries } };
|
||||
} catch {
|
||||
return empty;
|
||||
@@ -124,7 +133,9 @@ export class SQLiteStorage implements StorageAdapter {
|
||||
async getAllEndpoints(): Promise<Array<{ path: string; method: string; data: any }>> {
|
||||
if (!this.db) return [];
|
||||
try {
|
||||
const rows: Array<{ path: string; method: string; data: string }> = this.db.prepare('SELECT path, method, data FROM endpoints').all();
|
||||
const rows: Array<{ path: string; method: string; data: string }> = this.db
|
||||
.prepare('SELECT path, method, data FROM endpoints')
|
||||
.all();
|
||||
return rows.map((r: { path: string; method: string; data: string }) => {
|
||||
let data: any = {};
|
||||
try {
|
||||
@@ -139,5 +150,3 @@ export class SQLiteStorage implements StorageAdapter {
|
||||
}
|
||||
|
||||
export const sqliteStorage = new SQLiteStorage();
|
||||
|
||||
|
||||
|
||||
@@ -12,5 +12,3 @@ export interface StorageAdapter {
|
||||
upsertEndpoint(path: string, method: string, data: any): Promise<void>;
|
||||
getAllEndpoints(): Promise<Array<{ path: string; method: string; data: any }>>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user