Skip to content

Commit

Permalink
location added
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-appinventiv committed Feb 15, 2019
1 parent 35de0c6 commit 9870229
Show file tree
Hide file tree
Showing 26 changed files with 235 additions and 124 deletions.
19 changes: 3 additions & 16 deletions src/lib/impl/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { BodyLocation } from '../schema/index';



export interface IEmail {
email(): string;
}

export interface IString {
email(): IEmail;
export function body(field: string) {
return new BodyLocation(field);
}

export interface INumber {
number(): string;
}

export interface IBoolean {
boolean(): string;
}
3 changes: 2 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

export class MyLibrary {}
// import { body } from './impl/index';

7 changes: 2 additions & 5 deletions src/lib/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import { BodySchema } from './locations/body.schema';
import { NumberSchema } from './types/number.schema';
import { StringSchema } from './types/string.schema';

// new StringSchema().allow();
// new NumberSchema().min(10).allow();
export * from './types/index';
export * from './locations/index';
19 changes: 19 additions & 0 deletions src/lib/schema/locations/base.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AnyType } from '../types/any.type';
import { StringType } from '../types/string.type';
import { NumberType } from '../types/number.type';

export class BaseLocation {
constructor(
private _location: string,
private _fieldName: string,
) {}
any(): AnyType {
return new AnyType(this._location, this._fieldName);
}
string(): StringType {
return new StringType(this._location, this._fieldName);
}
number(): NumberType {
return new NumberType(this._location, this._fieldName);
}
}
7 changes: 7 additions & 0 deletions src/lib/schema/locations/body.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseLocation } from './base.location';

export class BodyLocation extends BaseLocation {
constructor(fieldName: string) {
super('body', fieldName);
}
}
12 changes: 0 additions & 12 deletions src/lib/schema/locations/body.schema.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/lib/schema/locations/cookie.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseLocation } from './base.location';

export class CookieLocation extends BaseLocation {
constructor(fieldName: string) {
super('cookie', fieldName);
}
}
7 changes: 7 additions & 0 deletions src/lib/schema/locations/header.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseLocation } from './base.location';

export class HeaderLocation extends BaseLocation {
constructor(fieldName: string) {
super('header', fieldName);
}
}
Empty file.
6 changes: 5 additions & 1 deletion src/lib/schema/locations/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@

export * from './body.schema';
export * from './body.location';
export * from './query.location';
export * from './param.location';
export * from './header.location';
export * from './cookie.location';
7 changes: 7 additions & 0 deletions src/lib/schema/locations/param.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseLocation } from './base.location';

export class ParamLocation extends BaseLocation {
constructor(fieldName: string) {
super('param', fieldName);
}
}
Empty file.
7 changes: 7 additions & 0 deletions src/lib/schema/locations/query.location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseLocation } from './base.location';

export class QueryLocation extends BaseLocation {
constructor(fieldName: string) {
super('query', fieldName);
}
}
Empty file.
3 changes: 0 additions & 3 deletions src/lib/schema/types/any.schema.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/lib/schema/types/any.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @name AnyType
* @type Any
* @description AnyType
*/

import { BaseType } from './base.type';

export class AnyType extends BaseType<any> {
protected _metaData: any;
protected _schema: string[];
constructor(
protected _location: string,
protected _fieldName: string,
) {
super();
}
}
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/**
* @name BaseType
* @type Generic
* @description BaseType
*/

export abstract class BaseSchema<T> {
protected abstract location: string;
protected abstract fieldName: string;
protected abstract metaData: any;
export abstract class BaseType<T> {
protected abstract _location: string;
protected abstract _fieldName: string;
protected abstract _metaData: any;
protected abstract _schema: string[];
/**
* @type Filter
* @description This allow the given argument values to be truthy for filter.
Expand Down Expand Up @@ -61,16 +67,46 @@ export abstract class BaseSchema<T> {
// TO DO
return this;
}
/**
* @type MetaData
* @description This function will set the description metadata to given value.
*/
description(): this {
// TO DO
return this;
}
/**
* @type Filter, Modifier
* @description This function will accept a custom validator function.
*/
custom(cb: (value: T) => void): this {
// TO DO
return this;
}
/**
* @type Filter
* @description This function check equal filter to given value.
*/
equalTo(value: T): this {
// TO DO
return this;
}
/**
* @type MetaData
* @description This function set location metdata.
* @param location Location identifier.
*/
location(loc: string): this {
// TO DO
return this;
}
/**
* @type Filter
* @description This function validate.
* @param values Location identifier.
*/
enum(...values: T[]): this {
// TO DO
return this;
}
}
8 changes: 4 additions & 4 deletions src/lib/schema/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export * from './base.schema';
export * from './any.schema';
export * from './string.schema';
export * from './number.schema';
export * from './base.type';
export * from './any.type';
export * from './string.type';
export * from './number.type';
52 changes: 0 additions & 52 deletions src/lib/schema/types/number.schema.ts

This file was deleted.

54 changes: 54 additions & 0 deletions src/lib/schema/types/number.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @name NumberType
* @type Number
* @description NumberType
*/

import { BaseType } from './base.type';

export class NumberType extends BaseType<number> {
protected _metaData: any;
protected _schema: string[];
constructor(
protected _location: string,
protected _fieldName: string,
) {
super();
}
integer(convert: boolean = false): this {
// TO DO
return this;
}
float(convert: boolean = false): this {
// TO DO
return this;
}
unsafe(): this {
// TO DO
return this;
}
negative(): this {
// TO DO
return this;
}
position(): this {
// TO DO
return this;
}
precision(): this {
// TO DO
return this;
}
min(num: number): this {
// TO DO
return this;
}
max(num: number): this {
// TO DO
return this;
}
port(): this {
// TO DO
return this;
}
}
Empty file.
18 changes: 18 additions & 0 deletions src/lib/schema/types/object.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @name ObjectType
* @type Object
* @description ObjectType
*/

import { BaseType } from './base.type';

export class ObjectType extends BaseType<string> {
protected _metaData: any;
protected _schema: string[];
constructor(
protected _location: string,
protected _fieldName: string,
) {
super();
}
}
Loading

0 comments on commit 9870229

Please sign in to comment.