@ts-awesome/orm 1.5.2 → 1.5.3

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.
@@ -1,59 +1,167 @@
1
- export namespace SupportedOperations {
2
- export function eq(value: any): Operandable;
3
- export function neq(value: any): Operandable;
4
- export function like(value: any): Operandable;
5
- function _in(value: any): Operandable;
6
- export { _in as in };
7
- export function has(value: any): Operandable;
8
- export function between(lo: any, hi: any): Operandable;
9
- export function gt(value: any): Operandable;
10
- export function gte(value: any): Operandable;
11
- export function lt(value: any): Operandable;
12
- export function lte(value: any): Operandable;
13
- export function add(value: any): Operandable;
14
- export function sub(value: any): Operandable;
15
- export function mul(value: any): Operandable;
16
- export function div(value: any): Operandable;
17
- export function mod(value: any): Operandable;
18
- export function and(value: any): Operandable;
19
- export function or(value: any): Operandable;
20
- export function xor(value: any): Operandable;
1
+ import {ElementType, IOperandable} from './interfaces';
2
+ import {IColumnRef} from "./intermediate";
3
+
4
+ declare class ColumnWrapper<T> implements IOperandable<T> {
5
+ constructor(ref: IColumnRef);
6
+
7
+ eq(value: T | IOperandable<T>): boolean;
8
+ neq(value: T | IOperandable<T>): boolean;
9
+ gt(value: T | IOperandable<T>): boolean;
10
+ gte(value: T | IOperandable<T>): boolean;
11
+ lt(value: T | IOperandable<T>): boolean;
12
+ lte(value: T | IOperandable<T>): boolean;
13
+ between(min: T | IOperandable<T>, max: T | IOperandable<T>): boolean;
14
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
15
+ has(value: (T extends any[] ? T[number] : T) | IOperandable<T extends any[] ? T[number] : T>): boolean;
16
+ like(value: string): boolean;
17
+ add(value: T | IOperandable<T>): IOperandable<T>;
18
+ sub(value: T | IOperandable<T>): IOperandable<T>;
19
+ mul(value: T | IOperandable<T>): IOperandable<T>;
20
+ div(value: T | IOperandable<T>): IOperandable<T>;
21
+ mod(value: T | IOperandable<T>): IOperandable<T>;
22
+ and(value: T | IOperandable<T>): IOperandable<T>;
23
+ or(value: T | IOperandable<T>): IOperandable<T>;
24
+ xor(value: T | IOperandable<T>): IOperandable<T>;
21
25
  }
22
- export function ColumnWrapper(column: any): void;
23
- export class ColumnWrapper {
24
- constructor(column: any);
25
- _column: any;
26
+
27
+ declare class AliasWrapper<T> implements IOperandable<T> {
28
+ constructor(expr: IOperandable<T>, alias: string);
29
+
30
+ eq(value: T | IOperandable<T>): boolean;
31
+ neq(value: T | IOperandable<T>): boolean;
32
+ gt(value: T | IOperandable<T>): boolean;
33
+ gte(value: T | IOperandable<T>): boolean;
34
+ lt(value: T | IOperandable<T>): boolean;
35
+ lte(value: T | IOperandable<T>): boolean;
36
+ between(min: T | IOperandable<T>, max: T | IOperandable<T>): boolean;
37
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
38
+ has(value: (T extends any[] ? T[number] : T) | IOperandable<T extends any[] ? T[number] : T>): boolean;
39
+ like(value: string): boolean;
40
+ add(value: T | IOperandable<T>): IOperandable<T>;
41
+ sub(value: T | IOperandable<T>): IOperandable<T>;
42
+ mul(value: T | IOperandable<T>): IOperandable<T>;
43
+ div(value: T | IOperandable<T>): IOperandable<T>;
44
+ mod(value: T | IOperandable<T>): IOperandable<T>;
45
+ and(value: T | IOperandable<T>): IOperandable<T>;
46
+ or(value: T | IOperandable<T>): IOperandable<T>;
47
+ xor(value: T | IOperandable<T>): IOperandable<T>;
26
48
  }
27
- export function FunctionCall(func: any, args: any): void;
28
- export class FunctionCall {
29
- constructor(func: any, args: any);
30
- _func: any;
31
- _args: any;
49
+
50
+ declare class FunctionCall<T> implements IOperandable<T> {
51
+ constructor(func: string, args: any[]);
52
+
53
+ add(value: IOperandable<T> | T): IOperandable<T>;
54
+ and(value: IOperandable<T> | T): IOperandable<T>;
55
+ between(min: IOperandable<T> | T, max: IOperandable<T> | T): boolean;
56
+ div(value: IOperandable<T> | T): IOperandable<T>;
57
+ eq(value: IOperandable<T> | T): boolean;
58
+ gt(value: IOperandable<T> | T): boolean;
59
+ gte(value: IOperandable<T> | T): boolean;
60
+ has(value: ElementType<T> | IOperandable<ElementType<T>>): boolean;
61
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
62
+ like(value: string): boolean;
63
+ lt(value: IOperandable<T> | T): boolean;
64
+ lte(value: IOperandable<T> | T): boolean;
65
+ mod(value: IOperandable<T> | T): IOperandable<T>;
66
+ mul(value: IOperandable<T> | T): IOperandable<T>;
67
+ neq(value: IOperandable<T> | T): boolean;
68
+ or(value: IOperandable<T> | T): IOperandable<T>;
69
+ sub(value: IOperandable<T> | T): IOperandable<T>;
70
+ xor(value: IOperandable<T> | T): IOperandable<T>;
32
71
  }
33
- export function NamedParameter(name: any): void;
34
- export class NamedParameter {
35
- constructor(name: any);
36
- _named: any;
72
+
73
+ declare class Operandable<T> implements IOperandable<T> {
74
+ constructor(operator: string, operands: any[]);
75
+
76
+ add(value: IOperandable<T> | T): IOperandable<T>;
77
+ and(value: IOperandable<T> | T): IOperandable<T>;
78
+ between(min: IOperandable<T> | T, max: IOperandable<T> | T): boolean;
79
+ div(value: IOperandable<T> | T): IOperandable<T>;
80
+ eq(value: IOperandable<T> | T): boolean;
81
+ gt(value: IOperandable<T> | T): boolean;
82
+ gte(value: IOperandable<T> | T): boolean;
83
+ has(value: ElementType<T> | IOperandable<ElementType<T>>): boolean;
84
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
85
+ like(value: string): boolean;
86
+ lt(value: IOperandable<T> | T): boolean;
87
+ lte(value: IOperandable<T> | T): boolean;
88
+ mod(value: IOperandable<T> | T): IOperandable<T>;
89
+ mul(value: IOperandable<T> | T): IOperandable<T>;
90
+ neq(value: IOperandable<T> | T): boolean;
91
+ or(value: IOperandable<T> | T): IOperandable<T>;
92
+ sub(value: IOperandable<T> | T): IOperandable<T>;
93
+ xor(value: IOperandable<T> | T): IOperandable<T>;
37
94
  }
38
- export function UnnamedParameter(value: any): void;
39
- export class UnnamedParameter {
40
- constructor(value: any);
41
- _value: any;
95
+
96
+ declare class NamedParameter<T> implements IOperandable<T> {
97
+ constructor(name: string);
98
+
99
+ add(value: IOperandable<T> | T): IOperandable<T>;
100
+ and(value: IOperandable<T> | T): IOperandable<T>;
101
+ between(min: IOperandable<T> | T, max: IOperandable<T> | T): boolean;
102
+ div(value: IOperandable<T> | T): IOperandable<T>;
103
+ eq(value: IOperandable<T> | T): boolean;
104
+ gt(value: IOperandable<T> | T): boolean;
105
+ gte(value: IOperandable<T> | T): boolean;
106
+ has(value: ElementType<T> | IOperandable<ElementType<T>>): boolean;
107
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
108
+ like(value: string): boolean;
109
+ lt(value: IOperandable<T> | T): boolean;
110
+ lte(value: IOperandable<T> | T): boolean;
111
+ mod(value: IOperandable<T> | T): IOperandable<T>;
112
+ mul(value: IOperandable<T> | T): IOperandable<T>;
113
+ neq(value: IOperandable<T> | T): boolean;
114
+ or(value: IOperandable<T> | T): IOperandable<T>;
115
+ sub(value: IOperandable<T> | T): IOperandable<T>;
116
+ xor(value: IOperandable<T> | T): IOperandable<T>;
42
117
  }
43
- export function Constant(value: any): void;
44
- export class Constant {
45
- constructor(value: any);
46
- _const: any;
118
+
119
+ declare class UnnamedParameter<T> implements IOperandable<T> {
120
+ constructor(value: T);
121
+
122
+ add(value: IOperandable<T> | T): IOperandable<T>;
123
+ and(value: IOperandable<T> | T): IOperandable<T>;
124
+ between(min: IOperandable<T> | T, max: IOperandable<T> | T): boolean;
125
+ div(value: IOperandable<T> | T): IOperandable<T>;
126
+ eq(value: IOperandable<T> | T): boolean;
127
+ gt(value: IOperandable<T> | T): boolean;
128
+ gte(value: IOperandable<T> | T): boolean;
129
+ has(value: ElementType<T> | IOperandable<ElementType<T>>): boolean;
130
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
131
+ like(value: string): boolean;
132
+ lt(value: IOperandable<T> | T): boolean;
133
+ lte(value: IOperandable<T> | T): boolean;
134
+ mod(value: IOperandable<T> | T): IOperandable<T>;
135
+ mul(value: IOperandable<T> | T): IOperandable<T>;
136
+ neq(value: IOperandable<T> | T): boolean;
137
+ or(value: IOperandable<T> | T): IOperandable<T>;
138
+ sub(value: IOperandable<T> | T): IOperandable<T>;
139
+ xor(value: IOperandable<T> | T): IOperandable<T>;
47
140
  }
48
- export function AliasWrapper(expr: any, alias: any): void;
49
- export class AliasWrapper {
50
- constructor(expr: any, alias: any);
51
- _alias: any;
52
- _operands: any[];
53
- }
54
- export function Operandable(operator: any, operands: any): void;
55
- export class Operandable {
56
- constructor(operator: any, operands: any);
57
- _operator: any;
58
- _operands: any;
141
+
142
+ declare class Constant<T> implements IOperandable<T> {
143
+ constructor(value: T);
144
+
145
+ add(value: IOperandable<T> | T): IOperandable<T>;
146
+ and(value: IOperandable<T> | T): IOperandable<T>;
147
+ between(min: IOperandable<T> | T, max: IOperandable<T> | T): boolean;
148
+ div(value: IOperandable<T> | T): IOperandable<T>;
149
+ eq(value: IOperandable<T> | T): boolean;
150
+ gt(value: IOperandable<T> | T): boolean;
151
+ gte(value: IOperandable<T> | T): boolean;
152
+ has(value: ElementType<T> | IOperandable<ElementType<T>>): boolean;
153
+ in(value: T[] | Iterable<T> | IOperandable<T[]>): boolean;
154
+ like(value: string): boolean;
155
+ lt(value: IOperandable<T> | T): boolean;
156
+ lte(value: IOperandable<T> | T): boolean;
157
+ mod(value: IOperandable<T> | T): IOperandable<T>;
158
+ mul(value: IOperandable<T> | T): IOperandable<T>;
159
+ neq(value: IOperandable<T> | T): boolean;
160
+ or(value: IOperandable<T> | T): IOperandable<T>;
161
+ sub(value: IOperandable<T> | T): IOperandable<T>;
162
+ xor(value: IOperandable<T> | T): IOperandable<T>;
59
163
  }
164
+
165
+ declare const SupportedOperations: any;
166
+
167
+ export {ColumnWrapper, FunctionCall, Operandable, NamedParameter, UnnamedParameter, Constant, SupportedOperations, AliasWrapper}
package/dist/wrappers.js CHANGED
@@ -1,80 +1,99 @@
1
+
1
2
  function skipAliasInOperations(op) {
2
- return typeof op._alias === 'string' && op._operands ? op._operands[0] : op;
3
+ return typeof op._alias === 'string' && op._operands ? op._operands[0] : op
3
4
  }
5
+
4
6
  const SupportedOperations = {
5
- eq(value) { return new Operandable(value === null ? 'IS' : '=', [this, value === null ? 'NULL' : value]); },
6
- neq(value) { return new Operandable(value === null ? 'IS NOT' : '<>', [this, value === null ? 'NULL' : value]); },
7
- like(value) { return new Operandable('LIKE', [this, value]); },
8
- in(value) { return new Operandable('IN', [this, value]); },
9
- has(value) { return new Operandable('IN', [value, this]); },
10
- between(lo, hi) { return new Operandable('BETWEEN', [this, lo, hi]); },
11
- gt(value) { return new Operandable('>', [this, value]); },
12
- gte(value) { return new Operandable('>=', [this, value]); },
13
- lt(value) { return new Operandable('<', [this, value]); },
14
- lte(value) { return new Operandable('<=', [this, value]); },
15
- add(value) { return new Operandable('+', [this, value]); },
16
- sub(value) { return new Operandable('-', [this, value]); },
17
- mul(value) { return new Operandable('*', [this, value]); },
18
- div(value) { return new Operandable('/', [this, value]); },
19
- mod(value) { return new Operandable('%', [this, value]); },
20
- and(value) { return new Operandable('&', [this, value]); },
21
- or(value) { return new Operandable('|', [this, value]); },
22
- xor(value) { return new Operandable('^', [this, value]); },
23
- };
24
- function Operandable(operator, operands) {
25
- this._operator = operator;
26
- this._operands = operands.map(op => skipAliasInOperations(op));
7
+ eq (value) { return new Operandable(value === null ? 'IS' : '=', [this, value === null ? 'NULL' : value])},
8
+ neq (value) { return new Operandable(value === null ? 'IS NOT' : '<>', [this, value === null ? 'NULL' : value])},
9
+ like (value) { return new Operandable('LIKE', [this, value])},
10
+
11
+ in (value) { return new Operandable('IN', [this, value])},
12
+ has (value) { return new Operandable('IN', [value, this])},
13
+
14
+ between(lo,hi) { return new Operandable('BETWEEN', [this, lo,hi])},
15
+ gt (value) { return new Operandable('>', [this, value])},
16
+ gte (value) { return new Operandable('>=', [this, value])},
17
+ lt (value) { return new Operandable('<', [this, value])},
18
+ lte (value) { return new Operandable('<=', [this, value])},
19
+
20
+ add (value) { return new Operandable('+', [this, value])},
21
+ sub (value) { return new Operandable('-', [this, value])},
22
+ mul (value) { return new Operandable('*', [this, value])},
23
+ div (value) { return new Operandable('/', [this, value])},
24
+ mod (value) { return new Operandable('%', [this, value])},
25
+
26
+ and (value) { return new Operandable('&', [this, value])},
27
+ or (value) { return new Operandable('|', [this, value])},
28
+ xor (value) { return new Operandable('^', [this, value])},
29
+ }
30
+
31
+ function Operandable(operator, operands){
32
+ this._operator = operator;
33
+ this._operands = operands.map(op => skipAliasInOperations(op));
27
34
  }
28
35
  Operandable.prototype = SupportedOperations;
36
+
29
37
  function FunctionCall(func, args) {
30
- this._func = func;
31
- this._args = args.map(op => skipAliasInOperations(op));
38
+ this._func = func;
39
+ this._args = args.map(op => skipAliasInOperations(op));
32
40
  }
33
41
  FunctionCall.prototype = SupportedOperations;
42
+
34
43
  function ColumnWrapper(column) {
35
- this._column = column;
44
+ this._column = column;
36
45
  }
37
46
  ColumnWrapper.prototype = SupportedOperations;
47
+
38
48
  function AliasWrapper(expr, alias) {
39
- this._alias = alias;
40
- this._operands = [expr];
49
+ this._alias = alias;
50
+ this._operands = [expr];
41
51
  }
42
52
  AliasWrapper.prototype = SupportedOperations;
53
+
43
54
  function NamedParameter(name) {
44
- if (/^p\d+$/.test(name)) {
45
- throw new Error(`Named parameter ${name} is reserved`);
46
- }
47
- if (!/^[a-zA-Z0-9_]+$/.test(name)) {
48
- throw new Error(`Named parameter should be valid identifier`);
49
- }
50
- this._named = name;
55
+ if (/^p\d+$/.test(name)) {
56
+ throw new Error(`Named parameter ${name} is reserved`);
57
+ }
58
+
59
+ if (!/^[a-zA-Z0-9_]+$/.test(name)) {
60
+ throw new Error(`Named parameter should be valid identifier`);
61
+ }
62
+
63
+ this._named = name;
51
64
  }
52
65
  NamedParameter.prototype = SupportedOperations;
66
+
53
67
  function UnnamedParameter(value) {
54
- this._value = value;
68
+ this._value = value;
55
69
  }
56
70
  UnnamedParameter.prototype = SupportedOperations;
71
+
72
+
57
73
  function Constant(value) {
58
- function check(value) {
59
- if (Array.isArray(value)) {
60
- return value.length > 0 && value.every(check);
61
- }
62
- return value == null || ['string', 'number', 'boolean'].indexOf(typeof value) >= 0;
74
+ function check(value) {
75
+ if (Array.isArray(value)) {
76
+ return value.length > 0 && value.every(check);
63
77
  }
64
- if (!check(value)) {
65
- throw new Error(`Constant expected to be null, number, string, boolean or array of such values. Got ${JSON.stringify(value)}`);
66
- }
67
- this._const = value;
78
+ return value == null || ['string', 'number', 'boolean'].indexOf(typeof value) >= 0;
79
+ }
80
+
81
+ if (!check(value)) {
82
+ throw new Error(`Constant expected to be null, number, string, boolean or array of such values. Got ${JSON.stringify(value)}`);
83
+ }
84
+
85
+ this._const = value;
68
86
  }
69
87
  Constant.prototype = SupportedOperations;
88
+
89
+
70
90
  module.exports = {
71
- SupportedOperations,
72
- ColumnWrapper,
73
- FunctionCall,
74
- NamedParameter,
75
- UnnamedParameter,
76
- Constant,
77
- AliasWrapper,
78
- Operandable,
79
- };
80
- //# sourceMappingURL=wrappers.js.map
91
+ SupportedOperations,
92
+ ColumnWrapper,
93
+ FunctionCall,
94
+ NamedParameter,
95
+ UnnamedParameter,
96
+ Constant,
97
+ AliasWrapper,
98
+ Operandable,
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-awesome/orm",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "TypeScript friendly minimalistic ORM",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "scripts": {
12
12
  "build:dev": "tsc --project tsconfig.json",
13
- "build": "npm run build:dev && cp src/wrappers* dist/",
13
+ "build": "npm run build:dev ; cp src/wrappers* dist/",
14
14
  "lint": "eslint \"src/**/*.ts\"",
15
15
  "test": "jest"
16
16
  },