mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-22 10:32:40 +08:00
feat(ql3): establish 3.0 incubation baseline
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
BoundedRunListProjectionUnavailableError,
|
||||
InvalidBoundedRunListProjectionError,
|
||||
executeBoundedRunListProjection,
|
||||
type BoundedRunListInput,
|
||||
} from '@qinglong/runtime-core/bounded-run-list-projection';
|
||||
import type { ProjectRunListReader } from '@qinglong/runtime-core/project-run-list';
|
||||
|
||||
import type { LocalApiResponse } from '../transport/contract';
|
||||
|
||||
export interface LocalApiRunListRequest {
|
||||
readonly projectId: string;
|
||||
readonly input: Readonly<BoundedRunListInput>;
|
||||
}
|
||||
|
||||
export interface LocalApiRunListRoute {
|
||||
handle(request: Readonly<LocalApiRunListRequest>): Promise<LocalApiResponse>;
|
||||
}
|
||||
|
||||
function unavailable(): LocalApiResponse {
|
||||
return Object.freeze({
|
||||
statusCode: 503,
|
||||
body: Object.freeze({ code: 'run_list_unavailable' }),
|
||||
});
|
||||
}
|
||||
|
||||
export function createLocalApiRunListRoute(
|
||||
runs: ProjectRunListReader,
|
||||
): Readonly<LocalApiRunListRoute> {
|
||||
if (!runs || typeof runs.listRunsByProject !== 'function') {
|
||||
throw new TypeError('Local API Run list repository is invalid');
|
||||
}
|
||||
return Object.freeze({
|
||||
async handle(request: Readonly<LocalApiRunListRequest>) {
|
||||
try {
|
||||
const result = await executeBoundedRunListProjection(
|
||||
runs,
|
||||
request.projectId,
|
||||
request.input,
|
||||
);
|
||||
return Object.freeze({
|
||||
statusCode: 200,
|
||||
body: Object.freeze({ ...result }),
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof InvalidBoundedRunListProjectionError ||
|
||||
error instanceof BoundedRunListProjectionUnavailableError
|
||||
) {
|
||||
return unavailable();
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user