-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
692b77f
commit 41a1b7a
Showing
7 changed files
with
84 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = class ProjectionsApi { | ||
|
||
#apis = new Map(); | ||
|
||
update({ projection, index, method, path }) { | ||
if (method !== 'GET' || !projection) return; | ||
this.#upsertApiEntry(projection, index, path); | ||
} | ||
|
||
get(projection) { | ||
return this.#apis.get(projection.key); | ||
} | ||
|
||
#upsertApiEntry(projection, index, path) { | ||
const entry = this.#ensureApiEntry(projection); | ||
if (index) entry.index = path; | ||
entry.routes.push(path); | ||
} | ||
|
||
#ensureApiEntry(projection) { | ||
return this.#apis.get(projection.key) || this.#createApiEntry(projection.key); | ||
} | ||
|
||
#createApiEntry(key) { | ||
const entry = { routes: [], index: '' }; | ||
this.#apis.set(key, entry); | ||
return entry; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Projection } from '../../..'; | ||
|
||
export type ProjectionApiEntry = { | ||
routes: string[]; | ||
index: string; | ||
} | ||
|
||
export default class ProjectionsApi { | ||
|
||
#apis = new Map<string, ProjectionApiEntry>(); | ||
|
||
update({ projection, index, method, path }: { projection: Projection, index: boolean; method: string, path: string }) { | ||
if (method !== 'GET' || !projection) return; | ||
this.#upsertApiEntry(projection, index, path); | ||
} | ||
|
||
get(projection: Projection) { | ||
return this.#apis.get(projection.key); | ||
} | ||
|
||
#upsertApiEntry(projection: Projection, index: boolean, path: string) { | ||
const entry = this.#ensureApiEntry(projection); | ||
if (index) entry.index = path; | ||
entry.routes.push(path); | ||
} | ||
|
||
#ensureApiEntry(projection: Projection): ProjectionApiEntry { | ||
return this.#apis.get(projection.key) || this.#createApiEntry(projection.key); | ||
} | ||
|
||
#createApiEntry(key: string): ProjectionApiEntry { | ||
const entry = { routes: [], index: '' }; | ||
this.#apis.set(key, entry); | ||
return entry; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters