-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added full support for new api-core module that allows separate inp…
…ut/output schema definitions for endpoints - Added support for new Endpoint format from api-core
- Loading branch information
1 parent
c75898b
commit bc4ac60
Showing
11 changed files
with
437 additions
and
171 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
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,74 @@ | ||
import { CoreController, EndpointMount, ObjectSchema } from "@plattar/api-core"; | ||
|
||
export interface EndpointMapping { | ||
readonly controller: CoreController; | ||
readonly mount: EndpointMount; | ||
} | ||
|
||
/** | ||
* Contains a collection of Schema to Endpoint lists used for generating query functions | ||
*/ | ||
export class SchemaCollection { | ||
private readonly _map: Map<typeof ObjectSchema, Array<EndpointMapping>>; | ||
|
||
public constructor() { | ||
this._map = new Map<typeof ObjectSchema, Array<EndpointMapping>>(); | ||
} | ||
|
||
public push(controller: CoreController): SchemaCollection { | ||
const mounts: Array<EndpointMount> = controller.mount(); | ||
const schema: typeof ObjectSchema = controller.getSchema(); | ||
|
||
// we insert as part of the input, if the input is undefined we use the | ||
// original schema | ||
mounts.forEach((mount: EndpointMount) => { | ||
this._insert(controller, mount.meta.input || schema, mount); | ||
|
||
if (mount.meta.output) { | ||
this._insert(controller, mount.meta.output, null); | ||
} | ||
}); | ||
|
||
return this; | ||
} | ||
|
||
private _insert(controller: CoreController, schema: typeof ObjectSchema, mount: EndpointMount | null): SchemaCollection { | ||
const data: Array<EndpointMapping> | undefined = this._map.get(schema); | ||
|
||
if (data) { | ||
if (mount) { | ||
data.push({ | ||
controller: controller, | ||
mount: mount | ||
}); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
const newData: Array<EndpointMapping> = new Array<EndpointMapping>(); | ||
|
||
if (mount) { | ||
newData.push({ | ||
controller: controller, | ||
mount: mount | ||
}); | ||
} | ||
|
||
this._map.set(schema, newData); | ||
|
||
return this; | ||
} | ||
|
||
public get(key: typeof ObjectSchema): Array<EndpointMapping> | null { | ||
const data = this._map.get(key); | ||
|
||
return data ? data : null; | ||
} | ||
|
||
public forEach(fn: (schema: typeof ObjectSchema, endpoints: Array<EndpointMapping>) => void) { | ||
this._map.forEach((value: Array<EndpointMapping>, key: typeof ObjectSchema) => { | ||
fn(key, value); | ||
}); | ||
} | ||
} |
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,30 @@ | ||
import { Schema } from "./schema"; | ||
|
||
/** | ||
* Keeps track of all generated Schema objects ready to be written out into files | ||
*/ | ||
export class SchemaList { | ||
private readonly _map: Map<string, Schema>; | ||
|
||
public constructor() { | ||
this._map = new Map<string, Schema>(); | ||
} | ||
|
||
public push(schema: Schema): SchemaList { | ||
this._map.set(schema.key, schema); | ||
|
||
return this; | ||
} | ||
|
||
public get(key: string): Schema | null { | ||
const data = this._map.get(key); | ||
|
||
return data ? data : null; | ||
} | ||
|
||
public forEach(fn: (schema: Schema) => void) { | ||
this._map.forEach((value: Schema, key: string) => { | ||
fn(value); | ||
}); | ||
} | ||
} |
Oops, something went wrong.