query-core 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/map.ts CHANGED
@@ -1,67 +1,67 @@
1
- import {Attribute, StringMap} from './metadata';
1
+ import { Attribute, StringMap } from "./metadata"
2
2
 
3
3
  export function mapArray<T>(results: T[], m?: StringMap): T[] {
4
4
  if (!m) {
5
- return results;
5
+ return results
6
6
  }
7
- const mkeys = Object.keys(m);
7
+ const mkeys = Object.keys(m)
8
8
  if (mkeys.length === 0) {
9
- return results;
9
+ return results
10
10
  }
11
- const objs = [];
12
- const length = results.length;
11
+ const objs = []
12
+ const length = results.length
13
13
  for (let i = 0; i < length; i++) {
14
- const obj = results[i];
15
- const obj2: any = {};
16
- const keys = Object.keys(obj as any);
14
+ const obj = results[i]
15
+ const obj2: any = {}
16
+ const keys = Object.keys(obj as any)
17
17
  for (const key of keys) {
18
- let k0 = m[key];
18
+ let k0 = m[key]
19
19
  if (!k0) {
20
- k0 = key;
20
+ k0 = key
21
21
  }
22
- obj2[k0] = (obj as any)[key];
22
+ obj2[k0] = (obj as any)[key]
23
23
  }
24
- objs.push(obj2);
24
+ objs.push(obj2)
25
25
  }
26
- return objs;
26
+ return objs
27
27
  }
28
28
  export function handleResults<T>(r: T[], m?: StringMap, bools?: Attribute[]): T[] {
29
29
  if (m) {
30
- const res = mapArray(r, m);
30
+ const res = mapArray(r, m)
31
31
  if (bools && bools.length > 0) {
32
- return handleBool(res, bools);
32
+ return handleBool(res, bools)
33
33
  } else {
34
- return res;
34
+ return res
35
35
  }
36
36
  } else {
37
37
  if (bools && bools.length > 0) {
38
- return handleBool(r, bools);
38
+ return handleBool(r, bools)
39
39
  } else {
40
- return r;
40
+ return r
41
41
  }
42
42
  }
43
43
  }
44
44
  export function handleBool<T>(objs: T[], bools: Attribute[]): T[] {
45
45
  if (!bools || bools.length === 0 || !objs) {
46
- return objs;
46
+ return objs
47
47
  }
48
48
  for (const obj of objs) {
49
- const o: any = obj;
49
+ const o: any = obj
50
50
  for (const field of bools) {
51
51
  if (field.name) {
52
- const v = o[field.name];
53
- if (typeof v !== 'boolean' && v != null && v !== undefined) {
54
- const b = field.true;
52
+ const v = o[field.name]
53
+ if (typeof v !== "boolean" && v != null && v !== undefined) {
54
+ const b = field.true
55
55
  if (b == null || b === undefined) {
56
56
  // tslint:disable-next-line:triple-equals
57
- o[field.name] = ('true' == v || '1' == v || 't' == v || 'y' == v || 'on' == v);
57
+ o[field.name] = "true" == v || "1" == v || "t" == v || "y" == v || "on" == v
58
58
  } else {
59
59
  // tslint:disable-next-line:triple-equals
60
- o[field.name] = (v == b ? true : false);
60
+ o[field.name] = v == b ? true : false
61
61
  }
62
62
  }
63
63
  }
64
64
  }
65
65
  }
66
- return objs;
66
+ return objs
67
67
  }
package/src/metadata.ts CHANGED
@@ -1,73 +1,90 @@
1
1
  export interface Module {
2
- id?: string|number;
3
- path?: string;
4
- route?: string;
2
+ id?: string | number
3
+ path?: string
4
+ route?: string
5
5
  }
6
6
  export interface Config {
7
- host?: string;
8
- port?: number;
9
- user?: string;
10
- password?: string;
11
- database?: string;
7
+ host?: string
8
+ port?: number
9
+ user?: string
10
+ password?: string
11
+ database?: string
12
12
  }
13
13
  export interface StringMap {
14
- [key: string]: string;
14
+ [key: string]: string
15
15
  }
16
16
  export interface Statement {
17
- query: string;
18
- params?: any[];
17
+ query: string
18
+ params?: any[]
19
19
  }
20
20
 
21
- export type DataType = 'ObjectId' | 'date' | 'datetime' | 'time'
22
- | 'boolean' | 'number' | 'integer' | 'string' | 'text'
23
- | 'object' | 'array' | 'binary'
24
- | 'primitives' | 'booleans' | 'numbers' | 'integers' | 'strings' | 'dates' | 'datetimes' | 'times';
25
- export type FormatType = 'currency' | 'percentage' | 'email' | 'url' | 'phone' | 'fax' | 'ipv4' | 'ipv6';
26
- export type MatchType = 'equal' | 'prefix' | 'contain' | 'max' | 'min'; // contain: default for string, min: default for Date, number
21
+ export type DataType =
22
+ | "ObjectId"
23
+ | "date"
24
+ | "datetime"
25
+ | "time"
26
+ | "boolean"
27
+ | "number"
28
+ | "integer"
29
+ | "string"
30
+ | "text"
31
+ | "object"
32
+ | "array"
33
+ | "binary"
34
+ | "primitives"
35
+ | "booleans"
36
+ | "numbers"
37
+ | "integers"
38
+ | "strings"
39
+ | "dates"
40
+ | "datetimes"
41
+ | "times"
42
+ export type FormatType = "currency" | "percentage" | "email" | "url" | "phone" | "fax" | "ipv4" | "ipv6"
43
+ export type MatchType = "equal" | "prefix" | "contain" | "max" | "min" // contain: default for string, min: default for Date, number
27
44
 
28
45
  export interface Model {
29
- name?: string;
30
- attributes: Attributes;
31
- source?: string;
32
- table?: string;
33
- collection?: string;
34
- model?: any;
35
- schema?: any;
46
+ name?: string
47
+ attributes: Attributes
48
+ source?: string
49
+ table?: string
50
+ collection?: string
51
+ model?: any
52
+ schema?: any
36
53
  }
37
54
  export interface Attribute {
38
- name?: string;
39
- field?: string;
40
- column?: string;
41
- type?: DataType;
42
- format?: FormatType;
43
- required?: boolean;
44
- match?: MatchType;
45
- default?: string|number|Date|boolean;
46
- key?: boolean;
47
- unique?: boolean;
48
- enum?: string[] | number[];
49
- q?: boolean;
50
- noinsert?: boolean;
51
- noupdate?: boolean;
52
- nopatch?: boolean;
53
- version?: boolean;
54
- length?: number;
55
- min?: number;
56
- max?: number;
57
- gt?: number;
58
- lt?: number;
59
- precision?: number;
60
- scale?: number;
61
- exp?: RegExp | string;
62
- code?: string;
63
- noformat?: boolean;
64
- ignored?: boolean;
65
- jsonField?: string;
66
- link?: string;
67
- typeof?: Attributes;
68
- true?: string|number;
69
- false?: string|number;
55
+ name?: string
56
+ field?: string
57
+ column?: string
58
+ type?: DataType
59
+ format?: FormatType
60
+ required?: boolean
61
+ match?: MatchType
62
+ default?: string | number | Date | boolean
63
+ key?: boolean
64
+ unique?: boolean
65
+ enum?: string[] | number[]
66
+ q?: boolean
67
+ noinsert?: boolean
68
+ noupdate?: boolean
69
+ nopatch?: boolean
70
+ version?: boolean
71
+ length?: number
72
+ min?: number
73
+ max?: number
74
+ gt?: number
75
+ lt?: number
76
+ precision?: number
77
+ scale?: number
78
+ exp?: RegExp | string
79
+ code?: string
80
+ noformat?: boolean
81
+ ignored?: boolean
82
+ jsonField?: string
83
+ link?: string
84
+ typeof?: Attributes
85
+ true?: string | number
86
+ false?: string | number
70
87
  }
71
88
  export interface Attributes {
72
- [key: string]: Attribute;
89
+ [key: string]: Attribute
73
90
  }