Skip to content

Commit

Permalink
extract DD
Browse files Browse the repository at this point in the history
  • Loading branch information
BBB committed Sep 21, 2023
1 parent 490b905 commit d795a89
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 1 addition & 17 deletions packages/builder/src/effect-schema/EffectBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,13 @@ import {
} from "@ollierelph/openapi-visitor";
import { printAst } from "~/src/lib/printAst";
import { match, P } from "ts-pattern";
import { DefaultDict } from "~/src/lib/DefaultDict";

type PathResponses = {
path: string;
responses: ResponsesObject;
};

class DefaultDict<T, Q> extends Map<T, Q> {
defaultFactory: () => Q;
constructor(defaultFactory: () => Q) {
super();
this.defaultFactory = defaultFactory;
}
get(name: T): Q {
if (this.has(name)) {
return super.get(name)!;
} else {
const value = this.defaultFactory();
this.set(name, value);
return value;
}
}
}

class MethodPaths {
constructor(private resolveReference: ReturnType<typeof getReference>) {}

Expand Down
18 changes: 18 additions & 0 deletions packages/builder/src/lib/DefaultDict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export class DefaultDict<T, Q> extends Map<T, Q> {
defaultFactory: () => Q;

constructor(defaultFactory: () => Q) {
super();
this.defaultFactory = defaultFactory;
}

get(name: T): Q {
if (this.has(name)) {
return super.get(name)!;
} else {
const value = this.defaultFactory();
this.set(name, value);
return value;
}
}
}

0 comments on commit d795a89

Please sign in to comment.