Debian Codegraph @

debian/tests/test_modules/@tufjs/repo-mock/dist/handler.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.tufHandlers = tufHandlers;
4 function tufHandlers(tufRepo, opts) {
5 const metadataPrefix = opts.metadataPathPrefix ?? '/metadata';
6 const targetPrefix = opts.targetPathPrefix ?? '/targets';
7 const handlers = [
8 {
9 path: `${metadataPrefix}/1.root.json`,
10 fn: respondWithMetadata(tufRepo.rootMeta),
11 },
12 {
13 path: `${metadataPrefix}/timestamp.json`,
14 fn: respondWithMetadata(tufRepo.timestampMeta),
15 },
16 {
17 path: `${metadataPrefix}/snapshot.json`,
18 fn: respondWithMetadata(tufRepo.snapshotMeta),
19 },
20 {
21 path: `${metadataPrefix}/targets.json`,
22 fn: respondWithMetadata(tufRepo.targetsMeta),
23 },
24 {
25 path: `${metadataPrefix}/2.root.json`,
26 fn: () => ({ statusCode: 404, response: '' }),
27 },
28 ];
29 tufRepo.targets.forEach((target) => {
30 handlers.push({
31 path: `${targetPrefix}/${target.name}`,
32 fn: () => ({ statusCode: 200, response: target.content }),
33 });
34 });
35 return handlers;
36 }
37 /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
38 function respondWithMetadata(meta) {
39 return () => ({
40 statusCode: 200,
41 response: JSON.stringify(meta.toJSON()),
42 contentType: 'application/json',
43 });
44 }