Skip to content

Commit

Permalink
some schemas created
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-appinventiv committed Feb 15, 2019
1 parent df8496b commit 35de0c6
Show file tree
Hide file tree
Showing 25 changed files with 454 additions and 39 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"private": false,
"scripts": {
"start": "webpack-dev-server",
"build": "webpack"
"build": "webpack",
"lint": "tslint -p tsconfig.json"
},
"devDependencies": {
"html-webpack-plugin": "^3.2.0",
"ts-loader": "^5.3.3",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@


export * from './lib/index';
export * from './lib/index';
3 changes: 1 addition & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@


export class MyLibrary {}
export class MyLibrary {}
5 changes: 3 additions & 2 deletions src/lib/parse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@


export function parse() {}
export function parse() {
//
}
3 changes: 0 additions & 3 deletions src/lib/schema/any.schema.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/lib/schema/base.schema.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/lib/schema/body.schema.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/lib/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// 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();
12 changes: 12 additions & 0 deletions src/lib/schema/locations/body.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AnySchema } from '../types/any.schema';
import { StringSchema } from '../types/string.schema';
import { NumberSchema } from '../types/number.schema';

export class BodySchema extends AnySchema {
string(): StringSchema {
return new StringSchema();
}
number(): NumberSchema {
return new NumberSchema();
}
}
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions src/lib/schema/locations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export * from './body.schema';
Empty file.
Empty file.
3 changes: 0 additions & 3 deletions src/lib/schema/number.schema.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib/schema/string.schema.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/lib/schema/types/any.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { BaseSchema } from './base.schema';

export class AnySchema extends BaseSchema<any> {}
Empty file.
76 changes: 76 additions & 0 deletions src/lib/schema/types/base.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

export abstract class BaseSchema<T> {
protected abstract location: string;
protected abstract fieldName: string;
protected abstract metaData: any;
/**
* @type Filter
* @description This allow the given argument values to be truthy for filter.
* @param values Argument values which are allowed to be truthy for filter.
*/
allow(...values: T[]): this {
// TO DO
return this;
}
/**
* @type Filter
* @description This disallow the given argument values to be truthy for filter.
* @param values Argument values which are disallowed to be truthy for filter.
*/
disallow(...values: T[]): this {
// TO DO
return this;
}
/**
* @type Filter
* @description This function will set the required flag to true.
*/
required(): this {
// TO DO
return this;
}
/**
* @type MetaData
* @description This function will set the label metadata to given value.
*/
label(name: string): this {
// TO DO
return this;
}
/**
* @type MetaData
* @description This function will set the unit metadata to given value.
*/
unit(): this {
// TO DO
return this;
}
/**
* @type Modifier
* @description This function will set the default value of the field.
*/
default(value: T): this {
// TO DO
return this;
}
/**
* @type MetaData
* @description This function will set the example metadata to given value.
*/
example(value: T): this {
// TO DO
return this;
}
description(): this {
// TO DO
return this;
}
custom(cb: (value: T) => void): this {
// TO DO
return this;
}
equalTo(value: T): this {
// TO DO
return this;
}
}
5 changes: 5 additions & 0 deletions src/lib/schema/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export * from './base.schema';
export * from './any.schema';
export * from './string.schema';
export * from './number.schema';
52 changes: 52 additions & 0 deletions src/lib/schema/types/number.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @name NumberSchema
* @type Number
* @description NumberSchema
*/

import { BaseSchema } from './base.schema';

export class NumberSchema extends BaseSchema<number> {
protected location: string;
protected metaData: any;
protected schema: string[];
constructor(protected fieldName: string) {
super();
}
integer(convert: boolean = false): NumberSchema {
// TO DO
return this;
}
float(convert: boolean = false): NumberSchema {
// TO DO
return this;
}
unsafe(): NumberSchema {
// TO DO
return this;
}
negative(): NumberSchema {
// TO DO
return this;
}
position(): NumberSchema {
// TO DO
return this;
}
precision(): NumberSchema {
// TO DO
return this;
}
min(num: number): NumberSchema {
// TO DO
return this;
}
max(num: number): NumberSchema {
// TO DO
return this;
}
port(): NumberSchema {
// TO DO
return this;
}
}
Empty file.
146 changes: 146 additions & 0 deletions src/lib/schema/types/string.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { BaseSchema } from './base.schema';

export class StringSchema extends BaseSchema<string> {
protected location: string;
protected metaData: any;
protected schema: string[];
constructor(protected fieldName: string) {
super();
}
/**
* @type Filter
*/
alphanum(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
regex(): StringSchema {
// check for regex
return this;
}
/**
* @type Modifier, Filter
* @description Lowercase value or filter lowercase value
*/
lowercase(convert: boolean = true): StringSchema {
// TO DO
return this;
}
/**
* @type Modifier, Filter
* @description Upercase value or filter upercase value
*/
uppercase(convert: boolean = true): StringSchema {
// TO DO
return this;
}
/**
* @type Modifier, Filter
* @description Trim value or filter trimmed value
*/
trim(convert: boolean = true): StringSchema {
// trim value or check if value trim
return this;
}
/**
* @type Modifier, Filter
*/
trimEnd(convert: boolean = true): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Modifier, Filter
*/
trimStart(convert: boolean = true): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
replace(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
truncate(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
email(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
isoDate(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
jwt(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
uri(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
dataUri(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
ip(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
creditCard(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Filter
*/
hostname(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Modifier
*/
normalize(): StringSchema {
// check for alphanum value
return this;
}
/**
* @type Modifier
*/
split(): StringSchema {
// check for alphanum value
return this;
}
}
Loading

0 comments on commit 35de0c6

Please sign in to comment.