Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzarbn committed Mar 24, 2021
1 parent 1892921 commit e74ebd5
Show file tree
Hide file tree
Showing 55 changed files with 590 additions and 504 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-inferrable-types": "off"
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"jest": "^26.6.3",
"lodash.camelcase": "^4.3.0",
"miragejs": "^0.1.41",
"prettier": "2.2.1",
"rimraf": "^2.6.2",
"ts-jest": "^26.5",
"typescript": "^4.2"
Expand Down
24 changes: 13 additions & 11 deletions src/builders/urlBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {Model} from '../model';
import {Orion} from '../orion';
import {ModelConstructor} from '../contracts/modelConstructor';
import {ExtractModelAttributesType} from '../types/extractModelAttributesType';
import {ExtractModelPersistedAttributesType} from '../types/extractModelPersistedAttributesType';
import {ExtractModelRelationsType} from '../types/extractModelRelationsType';
import {ExtractModelKeyType} from "../types/extractModelKeyType";
import { Model } from '../model';
import { Orion } from '../orion';
import { ModelConstructor } from '../contracts/modelConstructor';
import { ExtractModelAttributesType } from '../types/extractModelAttributesType';
import { ExtractModelPersistedAttributesType } from '../types/extractModelPersistedAttributesType';
import { ExtractModelRelationsType } from '../types/extractModelRelationsType';
import { ExtractModelKeyType } from '../types/extractModelKeyType';

export class UrlBuilder {
public static getResourceBaseUrl<M extends Model,
public static getResourceBaseUrl<
M extends Model,
Attributes = ExtractModelAttributesType<M>,
PersistedAttributes = ExtractModelPersistedAttributesType<M>,
Relations = ExtractModelRelationsType<M>,
Key = ExtractModelKeyType<M>
>(model: ModelConstructor<M, Attributes, PersistedAttributes, Relations, Key>): string {
>(model: ModelConstructor<M, Attributes, PersistedAttributes, Relations, Key>): string {
return Orion.getApiUrl() + '/' + (model.prototype as M).$getResourceName();
}

Expand All @@ -23,12 +24,13 @@ export class UrlBuilder {
);
}

public static getRelationResourceUrl<R extends Model,
public static getRelationResourceUrl<
R extends Model,
Attributes = ExtractModelAttributesType<R>,
PersistedAttributes = ExtractModelPersistedAttributesType<R>,
Relations = ExtractModelRelationsType<R>,
Key = ExtractModelKeyType<R>
>(
>(
parent: Model,
relationConstructor: ModelConstructor<R, Attributes, PersistedAttributes, Relations, Key>
): string {
Expand Down
19 changes: 10 additions & 9 deletions src/contracts/modelConstructor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {Model} from '../model';
import {ExtractModelAttributesType} from '../types/extractModelAttributesType';
import {ExtractModelPersistedAttributesType} from '../types/extractModelPersistedAttributesType';
import {ExtractModelRelationsType} from '../types/extractModelRelationsType';
import {ExtractModelKeyType} from "../types/extractModelKeyType";
import { Model } from '../model';
import { ExtractModelAttributesType } from '../types/extractModelAttributesType';
import { ExtractModelPersistedAttributesType } from '../types/extractModelPersistedAttributesType';
import { ExtractModelRelationsType } from '../types/extractModelRelationsType';
import { ExtractModelKeyType } from '../types/extractModelKeyType';

export interface ModelConstructor<M extends Model,
export interface ModelConstructor<
M extends Model,
Attributes = ExtractModelAttributesType<M>,
PersistedAttributes = ExtractModelPersistedAttributesType<M>,
Relations = ExtractModelRelationsType<M>,
Key = ExtractModelKeyType<M>,
AllAttributes = Attributes & PersistedAttributes,
> {
new(attributes?: AllAttributes, relations?: Relations): M;
AllAttributes = Attributes & PersistedAttributes
> {
new (attributes?: AllAttributes, relations?: Relations): M;
}
53 changes: 27 additions & 26 deletions src/drivers/default/builders/queryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import {HttpMethod} from '../enums/httpMethod';
import {Model} from '../../../model';
import {ModelConstructor} from '../../../contracts/modelConstructor';
import {Scope} from '../scope';
import {Filter} from '../filter';
import {FilterOperator} from '../enums/filterOperator';
import {FilterType} from '../enums/filterType';
import {Sorter} from '../sorter';
import {SortDirection} from '../enums/sortDirection';
import {UrlBuilder} from '../../../builders/urlBuilder';
import {ExtractModelAttributesType} from '../../../types/extractModelAttributesType';
import {ExtractModelPersistedAttributesType} from '../../../types/extractModelPersistedAttributesType';
import {ExtractModelRelationsType} from '../../../types/extractModelRelationsType';
import {HttpClient} from '../../../httpClient';
import {AxiosResponse} from 'axios';
import {Orion} from '../../../orion';
import {ExtractModelKeyType} from "../../../types/extractModelKeyType";

export class QueryBuilder<M extends Model,
import { HttpMethod } from '../enums/httpMethod';
import { Model } from '../../../model';
import { ModelConstructor } from '../../../contracts/modelConstructor';
import { Scope } from '../scope';
import { Filter } from '../filter';
import { FilterOperator } from '../enums/filterOperator';
import { FilterType } from '../enums/filterType';
import { Sorter } from '../sorter';
import { SortDirection } from '../enums/sortDirection';
import { UrlBuilder } from '../../../builders/urlBuilder';
import { ExtractModelAttributesType } from '../../../types/extractModelAttributesType';
import { ExtractModelPersistedAttributesType } from '../../../types/extractModelPersistedAttributesType';
import { ExtractModelRelationsType } from '../../../types/extractModelRelationsType';
import { HttpClient } from '../../../httpClient';
import { AxiosResponse } from 'axios';
import { Orion } from '../../../orion';
import { ExtractModelKeyType } from '../../../types/extractModelKeyType';

export class QueryBuilder<
M extends Model,
Attributes = ExtractModelAttributesType<M>,
PersistedAttributes = ExtractModelPersistedAttributesType<M>,
Relations = ExtractModelRelationsType<M>,
Key = ExtractModelKeyType<M>,
AllAttributes = Attributes & PersistedAttributes,
> {
AllAttributes = Attributes & PersistedAttributes
> {
protected baseUrl: string;
protected modelConstructor: ModelConstructor<M, Attributes, PersistedAttributes, Relations, Key>;
protected httpClient: HttpClient;
Expand Down Expand Up @@ -54,7 +55,7 @@ export class QueryBuilder<M extends Model,
const response = await this.httpClient.request(
'/',
HttpMethod.GET,
this.prepareQueryParams({limit, page})
this.prepareQueryParams({ limit, page })
);

return response.data.data.map((attributes: AllAttributes & Relations) => {
Expand All @@ -66,12 +67,12 @@ export class QueryBuilder<M extends Model,
const response = await this.httpClient.request(
'/search',
HttpMethod.POST,
this.prepareQueryParams({limit, page}),
this.prepareQueryParams({ limit, page }),
{
scopes: this.scopes,
filters: this.filters,
search: {value: this.searchValue},
sort: this.sorters
search: { value: this.searchValue },
sort: this.sorters,
}
);

Expand Down Expand Up @@ -116,7 +117,7 @@ export class QueryBuilder<M extends Model,
const response = await this.httpClient.request(
`/${key}`,
HttpMethod.DELETE,
this.prepareQueryParams({force})
this.prepareQueryParams({ force })
);

return this.hydrate(response.data.data, response);
Expand Down
31 changes: 19 additions & 12 deletions src/drivers/default/builders/relationQueryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import {Model} from '../../../model';
import {QueryBuilder} from './queryBuilder';
import {ModelConstructor} from '../../../contracts/modelConstructor';
import {UrlBuilder} from '../../../builders/urlBuilder';
import {ExtractModelAttributesType} from '../../../types/extractModelAttributesType';
import {ExtractModelPersistedAttributesType} from '../../../types/extractModelPersistedAttributesType';
import {ExtractModelRelationsType} from '../../../types/extractModelRelationsType';
import {Orion} from '../../../orion';
import {ExtractModelKeyType} from "../../../types/extractModelKeyType";
import { Model } from '../../../model';
import { QueryBuilder } from './queryBuilder';
import { ModelConstructor } from '../../../contracts/modelConstructor';
import { UrlBuilder } from '../../../builders/urlBuilder';
import { ExtractModelAttributesType } from '../../../types/extractModelAttributesType';
import { ExtractModelPersistedAttributesType } from '../../../types/extractModelPersistedAttributesType';
import { ExtractModelRelationsType } from '../../../types/extractModelRelationsType';
import { Orion } from '../../../orion';
import { ExtractModelKeyType } from '../../../types/extractModelKeyType';

export class RelationQueryBuilder<Relation extends Model,
export class RelationQueryBuilder<
Relation extends Model,
Attributes = ExtractModelAttributesType<Relation>,
PersistedAttributes = ExtractModelPersistedAttributesType<Attributes>,
Relations = ExtractModelRelationsType<Relation>,
Key = ExtractModelKeyType<Relation>
> extends QueryBuilder<Relation, Attributes, PersistedAttributes, Relations, Key> {
> extends QueryBuilder<Relation, Attributes, PersistedAttributes, Relations, Key> {
constructor(
relationConstructor: ModelConstructor<Relation, Attributes, PersistedAttributes, Relations, Key>,
relationConstructor: ModelConstructor<
Relation,
Attributes,
PersistedAttributes,
Relations,
Key
>,
parent: Model<any>
) {
super(relationConstructor);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/default/enums/authDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum AuthDriver {
Default = 'default',
Passport = 'passport',
Sanctum = 'sanctum'
Sanctum = 'sanctum',
}
2 changes: 1 addition & 1 deletion src/drivers/default/enums/filterOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export enum FilterOperator {
Like = 'like',
NotLike = 'not like',
In = 'in',
NotIn = 'not in'
NotIn = 'not in',
}
2 changes: 1 addition & 1 deletion src/drivers/default/enums/filterType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum FilterType {
And = 'and',
Or = 'or'
Or = 'or',
}
2 changes: 1 addition & 1 deletion src/drivers/default/enums/httpMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export enum HttpMethod {
POST = 'post',
PATCH = 'patch',
PUT = 'put',
DELETE = 'delete'
DELETE = 'delete',
}
2 changes: 1 addition & 1 deletion src/drivers/default/enums/sortDirection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum SortDirection {
Asc = 'asc',
Desc = 'desc'
Desc = 'desc',
}
7 changes: 3 additions & 4 deletions src/drivers/default/filter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {FilterOperator} from './enums/filterOperator';
import {FilterType} from './enums/filterType';
import { FilterOperator } from './enums/filterOperator';
import { FilterType } from './enums/filterType';

export class Filter {
constructor(
protected field: string,
protected operator: FilterOperator,
protected value: any,
protected type?: FilterType
) {
}
) {}

public getField(): string {
return this.field;
Expand Down
16 changes: 8 additions & 8 deletions src/drivers/default/relations/belongsTo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Model} from '../../../model';
import {RelationQueryBuilder} from '../builders/relationQueryBuilder';
import {ExtractModelAttributesType} from '../../../types/extractModelAttributesType';
import {ExtractModelPersistedAttributesType} from '../../../types/extractModelPersistedAttributesType';
import {ExtractModelRelationsType} from '../../../types/extractModelRelationsType';
import { Model } from '../../../model';
import { RelationQueryBuilder } from '../builders/relationQueryBuilder';
import { ExtractModelAttributesType } from '../../../types/extractModelAttributesType';
import { ExtractModelPersistedAttributesType } from '../../../types/extractModelPersistedAttributesType';
import { ExtractModelRelationsType } from '../../../types/extractModelRelationsType';

export class BelongsTo<Relation extends Model,
export class BelongsTo<
Relation extends Model,
Attributes = ExtractModelAttributesType<Relation>,
PersistedAttributes = ExtractModelPersistedAttributesType<Attributes>,
Relations = ExtractModelRelationsType<Relation>
> extends RelationQueryBuilder<Relation, Attributes, PersistedAttributes, Relations> {
}
> extends RelationQueryBuilder<Relation, Attributes, PersistedAttributes, Relations> {}
Loading

0 comments on commit e74ebd5

Please sign in to comment.