-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartitionByMethod.ts
More file actions
26 lines (21 loc) · 874 Bytes
/
partitionByMethod.ts
File metadata and controls
26 lines (21 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { CanonicalSpec, HTTPMethod } from "@patchlogr/types";
import type { Partition, PartitionedSpec } from "./partition";
import { createSHA256Hash } from "../utils/createHash";
import { stableStringify } from "../utils/stableStringify";
export function partitionByMethod(spec: CanonicalSpec): PartitionedSpec {
const partitions = new Map<HTTPMethod, Partition[]>();
Object.entries(spec.operations).forEach(([key, operation]) => {
const hash = createSHA256Hash(stableStringify(operation));
if (!partitions.has(operation.method))
partitions.set(operation.method, [{ hash, operationKey: key }]);
else
partitions.get(operation.method)?.push({ hash, operationKey: key });
});
return {
metadata: {
...spec.info,
...spec.security,
},
partitions,
};
}