Skip to content

Commit a8d842b

Browse files
Move all types into a index.d.ts
1 parent 4ef2b39 commit a8d842b

File tree

10 files changed

+154
-95
lines changed

10 files changed

+154
-95
lines changed

ApiBlueprint.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Router from './Router';
2+
import express from 'express';
3+
import IMountableItem from './IMountableItem';
4+
5+
export default class ApiBlueprint implements IMountableItem {
6+
public path: string = '/docs/blueprint';
7+
public httpMethod: string = 'get';
8+
protected router: Router;
9+
10+
constructor() {
11+
throw new Error('not yet implemented');
12+
}
13+
14+
onMount(router: Router): this {
15+
this.router = router;
16+
17+
return this;
18+
}
19+
20+
at(path: string): this {
21+
this.path = path;
22+
23+
return this;
24+
}
25+
26+
withOptions(options: {}): this {
27+
return this;
28+
}
29+
30+
asExpressRoute(): (req: express.Request, res: express.Response) => void {
31+
throw new Error('Not yet implemented');
32+
}
33+
34+
asKoaRoute() {
35+
throw new Error('not yet implemented');
36+
}
37+
38+
asMetal() {
39+
throw new Error('not yet implemented');
40+
}
41+
}

ICacheEngine.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

IMountableItem.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

InMemoryCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ICacheEngine from './ICacheEngine';
1+
import { ICacheEngine } from '.';
22

33
const STORE_EXPIRATION_CHECK_IN_MS = 10;
44
const DEFAULT_CACHE_TIME_IN_MS = 10;

OpenApi.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import IMountableItem from './IMountableItem';
1+
import { IMountableItem, IOperationVariable, IOpenApiOptions, } from '.';
22
import describeRouteVariables from './describeRouteVariables';
33
import Router from './Router';
4-
import Route, { IOperationVariable } from './Route'; import express from 'express';
5-
6-
interface IOpenApiOptions {
7-
title: string;
8-
version: string;
9-
termsOfService?: string;
10-
license?: string;
11-
basePath?: string;
12-
host?: string;
13-
}
4+
import Route from './Route';
5+
import express from 'express';
146

157
interface IParameter {
168
name: string;
@@ -145,10 +137,12 @@ function buildParametersArray({ variableDefinitions, variableLocation, refLocati
145137
}
146138

147139
class MountableDocument implements IMountableItem {
148-
public path: string = '/docs/openapi/v2';
140+
public path: string = '/docs/openapi';
149141
public httpMethod: string = 'get';
150142

151-
constructor(protected options: IOpenApiOptions, protected router?: Router) {
143+
protected router?: Router;
144+
145+
constructor(protected options: IOpenApiOptions) {
152146
}
153147

154148
onMount(router: Router): this {
@@ -207,6 +201,8 @@ class MountableDocument implements IMountableItem {
207201
}
208202

209203
export class V2 extends MountableDocument {
204+
public path: string = '/docs/swagger';
205+
210206
protected async generateDocumentation(): Promise<any> {
211207
const router = this.getRouter();
212208

Route.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
1-
import IMountableItem from './IMountableItem';
1+
import {
2+
IMountableItem, IConstructorRouteOptions, IRouteOptions,
3+
IOperationVariable, IResponse,
4+
} from '.';
5+
26
import { IncomingHttpHeaders } from 'http';
37
import { DocumentNode, parse, print, getOperationAST } from 'graphql';
48
import { AxiosTransformer, AxiosInstance, AxiosRequestConfig } from 'axios';
59
import * as express from 'express';
610

711
const PATH_VARIABLES_REGEX = /:([A-Za-z]+)/g
812

9-
export interface IConstructorRouteOptions {
10-
schema: DocumentNode | string; // GraphQL Document Type
11-
operationName: string;
12-
axios: AxiosInstance;
13-
path?: string;
14-
cacheTimeInMs?: number;
15-
method?: string;
16-
17-
passThroughHeaders?: string[];
18-
19-
staticVariables?: {};
20-
defaultVariables?: {};
21-
}
22-
23-
export interface IRouteOptions {
24-
path?: string;
25-
cacheTimeInMs?: number;
26-
method?: string;
27-
passThroughHeaders?: string[];
28-
29-
staticVariables?: {};
30-
defaultVariables?: {};
31-
}
32-
33-
export interface IOperationVariable {
34-
name: string;
35-
required: boolean;
36-
type: string;
37-
array: boolean;
38-
defaultValue?: string | boolean | number;
39-
}
40-
41-
export interface IResponse {
42-
statusCode: number;
43-
body: {};
44-
}
45-
4613
/*
4714
enum EHTTPMethod {
4815
GET = 'get',

Router.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import IMountableItem from './IMountableItem';
2-
import ICacheEngine from './ICacheEngine';
3-
import Route, { IConstructorRouteOptions } from './Route';
1+
import {
2+
IGlobalConfiguration,
3+
IMountableItem,
4+
ICacheEngine,
5+
IConstructorRouteOptions,
6+
} from '.';
7+
import Route from './Route';
48
import express from 'express';
5-
import axios, { AxiosBasicCredentials, AxiosProxyConfig, AxiosInstance, AxiosRequestConfig } from 'axios';
9+
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
610
import { parse, DocumentNode, getOperationAST } from 'graphql';
711
import { version } from './package.json';
812

9-
interface IGlobalConfiguration {
10-
cacheEngine?: ICacheEngine;
11-
defaultTimeoutInMs?: number;
12-
defaultCacheTimeInMs?: number;
13-
autoDiscoverEndpoints?: boolean;
14-
optimizeQueryRequest?: boolean;
15-
headers?: {};
16-
passThroughHeaders?: string[];
17-
auth?: AxiosBasicCredentials;
18-
proxy?: AxiosProxyConfig;
19-
}
20-
2113
const DEFAULT_CONFIGURATION: IGlobalConfiguration = {
2214
cacheEngine: undefined,
2315
auth: undefined,

index.d.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import express from 'express';
2+
import Router from './Router';
3+
import { DocumentNode } from 'graphql';
4+
import axios, {
5+
AxiosBasicCredentials, AxiosProxyConfig, AxiosInstance
6+
} from 'axios';
7+
8+
export interface IGlobalConfiguration {
9+
cacheEngine?: ICacheEngine;
10+
defaultTimeoutInMs?: number;
11+
defaultCacheTimeInMs?: number;
12+
autoDiscoverEndpoints?: boolean;
13+
optimizeQueryRequest?: boolean;
14+
headers?: {};
15+
passThroughHeaders?: string[];
16+
auth?: AxiosBasicCredentials;
17+
proxy?: AxiosProxyConfig;
18+
}
19+
20+
export interface IConstructorRouteOptions {
21+
schema: DocumentNode | string; // GraphQL Document Type
22+
operationName: string;
23+
axios: AxiosInstance;
24+
path?: string;
25+
cacheTimeInMs?: number;
26+
method?: string;
27+
28+
passThroughHeaders?: string[];
29+
30+
staticVariables?: {};
31+
defaultVariables?: {};
32+
}
33+
34+
export interface IRouteOptions {
35+
path?: string;
36+
cacheTimeInMs?: number;
37+
method?: string;
38+
passThroughHeaders?: string[];
39+
40+
staticVariables?: {};
41+
defaultVariables?: {};
42+
}
43+
44+
export interface IOperationVariable {
45+
name: string;
46+
required: boolean;
47+
type: string;
48+
array: boolean;
49+
defaultValue?: string | boolean | number;
50+
}
51+
52+
export interface IResponse {
53+
statusCode: number;
54+
body: {};
55+
}
56+
57+
export interface IOpenApiOptions {
58+
title: string;
59+
version: string;
60+
termsOfService?: string;
61+
license?: string;
62+
basePath?: string;
63+
host?: string;
64+
}
65+
66+
export interface IMountableItem {
67+
path: string;
68+
httpMethod: string;
69+
70+
at: (path: string) => this;
71+
72+
asExpressRoute: () => (req: express.Request, res: express.Response) => void;
73+
asKoaRoute: () => void;
74+
asMetal: () => void;
75+
76+
withOptions: (options: any) => this;
77+
78+
onMount?: (router: Router) => this
79+
}
80+
81+
export interface ICacheEngine {
82+
get: (key: string, setFn?: () => string|number|boolean) => string|number|boolean;
83+
set: (key: string, value: string|number|boolean) => void;
84+
}

index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Router from './Router';
22
import Route from './Route';
33

4+
import * as OpenApi from './OpenApi';
5+
import ApiBlueprint from './ApiBlueprint';
6+
47
export default Router;
5-
export { Route };
8+
export { Route, OpenApi, ApiBlueprint };

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0-alpha.10",
44
"description": "",
55
"main": "index.js",
6-
"files": ["*.js"],
6+
"types": "./index.d.ts",
7+
"files": ["*.js", "index.d.ts"],
78
"scripts": {
89
"build": "tsc -p .",
910
"prepare": "npm run build",

0 commit comments

Comments
 (0)