Skip to content

Commit 0d9eaed

Browse files
authored
Merge pull request #188 from StatelessStudio/v3.1.0
[3.1.0] Aug-06-2019
2 parents 28cb62d + e57af0d commit 0d9eaed

14 files changed

Lines changed: 159 additions & 101 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# PointyApi Changelog
22

3+
## [3.1.0] Aug-06-2019
4+
5+
### Additions
6+
- [Issue #187] Add HttpClient::request for proxy
7+
- [Issue #183] Move getValidationConstraints() to exported module
8+
9+
### Fixes
10+
- npm update
11+
- Cleaned up query-tools
12+
- Move imports to query-tools
13+
314
## [3.0.3] Jul-23-2019
415

516
### Fixes

package-lock.json

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pointyapi",
3-
"version": "3.0.3",
3+
"version": "3.1.0",
44
"author": "stateless-studio",
55
"license": "MIT",
66
"scripts": {
@@ -26,7 +26,7 @@
2626
"@types/btoa": "^1.2.3",
2727
"@types/express": "^4.17.0",
2828
"@types/jsonwebtoken": "^7.2.8",
29-
"@types/node": "^10.14.13",
29+
"@types/node": "^10.14.14",
3030
"@types/request": "^2.48.2",
3131
"atob": "^2.1.2",
3232
"bcryptjs": "^2.4.3",
@@ -35,11 +35,11 @@
3535
"express": "^4.17.1",
3636
"jsonwebtoken": "^8.5.1",
3737
"mock-req-res": "^1.1.1",
38-
"pg": "^7.11.0",
38+
"pg": "^7.12.0",
3939
"pg-connection-string": "^2.1.0",
4040
"reflect-metadata": "^0.1.13",
4141
"request": "^2.88.0",
42-
"sinon": "^7.3.2",
42+
"sinon": "^7.4.1",
4343
"typeorm": "^0.2.18",
4444
"validator": "^10.11.0"
4545
},
@@ -51,7 +51,7 @@
5151
"coveralls": "^3.0.5",
5252
"jasmine": "^3.4.0",
5353
"nyc": "^14.1.1",
54-
"source-map-support": "^0.5.12",
54+
"source-map-support": "^0.5.13",
5555
"ts-node": "^7.0.1",
5656
"tslint": "^5.18.0",
5757
"tslint-eslint-rules": "^5.4.0",

src/http/http-client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import * as request from 'request';
1616
import { HttpClientResponse } from './http-client-response';
1717

1818
export class HttpClient {
19+
public request = request;
20+
1921
// Server URL
2022
public url = 'http://localhost';
2123

@@ -48,7 +50,7 @@ export class HttpClient {
4850
}
4951

5052
return new Promise<HttpClientResponse>((accept, reject) => {
51-
request(options, (error, response, body) => {
53+
this.request(options, (error, response, body) => {
5254
if (error) {
5355
reject(new HttpClientResponse(response, error));
5456
}
@@ -93,7 +95,7 @@ export class HttpClient {
9395
options['auth'] = { bearer: `${bearer}` };
9496
}
9597

96-
request(options, (error, response, body) => {
98+
this.request(options, (error, response, body) => {
9799
if (error) {
98100
reject(new HttpClientResponse(response, error));
99101
}
@@ -138,7 +140,7 @@ export class HttpClient {
138140
}
139141

140142
return new Promise<HttpClientResponse>((accept, reject) => {
141-
request(options, (error, response, body) => {
143+
this.request(options, (error, response, body) => {
142144
if (error) {
143145
reject(new HttpClientResponse(response, error));
144146
}
@@ -180,7 +182,7 @@ export class HttpClient {
180182
options['auth'] = { bearer: `${bearer}` };
181183
}
182184

183-
request(options, (error, response, body) => {
185+
this.request(options, (error, response, body) => {
184186
if (error) {
185187
reject(new HttpClientResponse(response, error));
186188
}

src/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* Middleware
99
*/
10+
// TODO: Remove in v4 vvv
1011
export { getQuery } from './query-tools/get-query';
1112
export { loadEntity } from './middleware/load-entity';
1213
export { loadUser } from './middleware/load-user';

src/query-tools.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* # Query Tools
3+
*
4+
* Query tools assist in processing incoming requests and querying the database
5+
*/
6+
7+
/**
8+
* Query Tools
9+
*/
10+
export { createSearchQuery } from './query-tools/create-search-query';
11+
export { getQuery } from './query-tools/get-query';
12+
export {
13+
getValidationConstraints
14+
} from './query-tools/get-validation-constraints';
15+
export { queryTypes } from './query-tools/query-types';
16+
export { queryValidator } from './query-tools/query-validator';

src/query-tools/get-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Request, Response } from 'express';
22
import { getReadableFields, getBodyguardKeys } from '../bodyguard';
3-
import { UserRole } from '../enums/user-role';
43

54
import { createSearchQuery } from '../utils';
5+
66
/**
77
* Get the objects represented by the request query
88
* @param request Request to query by
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { MetadataStorage, getFromContainer } from 'class-validator';
2+
3+
/**
4+
* Get class-validator constraints for a class
5+
* @param someClass BaseModel class(e.g `request.payloadType`)
6+
* @param key (Optional) Key to get constraints for. If unset, constraints for
7+
* all keys will be returned.
8+
*/
9+
export function getValidationConstraints(someClass: Function, key?: string) {
10+
const container = <MetadataStorage>getFromContainer(MetadataStorage);
11+
const metadata = container.getTargetValidationMetadatas(
12+
someClass,
13+
JSON.stringify(someClass)
14+
);
15+
const properties = container.groupByPropertyName(metadata);
16+
17+
const validators = Object.keys(properties).reduce((schema, property) => {
18+
schema[property] = properties[
19+
property
20+
].reduce((propertySchema, { type, constraints }) => {
21+
if (Array.isArray(constraints) && constraints.length === 1) {
22+
constraints = constraints[0];
23+
}
24+
25+
if (typeof constraints === 'undefined') {
26+
propertySchema[type] = true;
27+
}
28+
else {
29+
propertySchema[type] = constraints;
30+
}
31+
32+
return propertySchema;
33+
}, {});
34+
35+
return schema;
36+
}, {});
37+
38+
if (key) {
39+
if (key in validators) {
40+
return validators[key];
41+
}
42+
else {
43+
return false;
44+
}
45+
}
46+
else {
47+
return validators;
48+
}
49+
}

src/query-tools/query-validator.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,8 @@ import { Request, Response } from 'express';
22
import { isKeyInModel } from '../utils';
33
import { queryTypes, queryTypeKeys } from './query-types';
44
import { getReadableFields, getReadableRelations } from '../bodyguard';
5-
import {
6-
validateSync,
7-
MetadataStorage,
8-
getFromContainer
9-
} from 'class-validator';
10-
11-
/**
12-
* Get class-validator constraints for a class
13-
* @param someClass BaseModel class(e.g `request.payloadType`)
14-
* @param key (Optional) Key to get constraints for. If unset, constraints for
15-
* all keys will be returned.
16-
*/
17-
function getValidationConstraints(someClass: Function, key?: string) {
18-
const container = <MetadataStorage>getFromContainer(MetadataStorage);
19-
const metadata = container.getTargetValidationMetadatas(
20-
someClass,
21-
JSON.stringify(someClass)
22-
);
23-
const properties = container.groupByPropertyName(metadata);
24-
25-
const validators = Object.keys(properties).reduce((schema, property) => {
26-
schema[property] = properties[
27-
property
28-
].reduce((propertySchema, { type, constraints }) => {
29-
if (Array.isArray(constraints) && constraints.length === 1) {
30-
constraints = constraints[0];
31-
}
32-
33-
if (typeof constraints === 'undefined') {
34-
propertySchema[type] = true;
35-
}
36-
else {
37-
propertySchema[type] = constraints;
38-
}
39-
40-
return propertySchema;
41-
}, {});
42-
43-
return schema;
44-
}, {});
45-
46-
if (key) {
47-
if (key in validators) {
48-
return validators[key];
49-
}
50-
else {
51-
return false;
52-
}
53-
}
54-
else {
55-
return validators;
56-
}
57-
}
5+
import { validateSync } from 'class-validator';
6+
import { getValidationConstraints } from './get-validation-constraints';
587

598
/**
609
* Validate a GET query type

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { addResource } from './utils/add-resource';
22
export { bindResponders } from './utils/bind-responders';
3+
// TODO: Remove in v4 vvv
34
export { createSearchQuery } from './query-tools/create-search-query';
45
export { createTimestamp } from './utils/create-timestamp';
56
export { deleteUndefinedMembers } from './utils/delete-undefined-members';

0 commit comments

Comments
 (0)