@ts-awesome/orm 1.7.1 → 1.8.0-rc.0
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/dist/branded.d.ts +6 -0
- package/dist/branded.js +3 -0
- package/dist/branded.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/operators.d.ts +19 -1
- package/dist/operators.js +33 -1
- package/dist/operators.js.map +1 -1
- package/package.json +1 -1
- package/tests/builder.spec.ts +20 -5
- package/tests/models.ts +17 -8
- package/tests/reader.spec.ts +13 -13
package/dist/branded.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branded.js","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export * from './operators';
|
|
|
6
6
|
export { Select, Update, Upsert, Insert, Delete, IExpr, TableRef } from './builder';
|
|
7
7
|
export * from './reader';
|
|
8
8
|
export * from './intermediate';
|
|
9
|
+
export * from './wrappers';
|
|
10
|
+
export * from './branded';
|
|
9
11
|
import Symbols from './symbols';
|
|
10
12
|
export default Symbols;
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,8 @@ Object.defineProperty(exports, "Delete", { enumerable: true, get: function () {
|
|
|
32
32
|
Object.defineProperty(exports, "TableRef", { enumerable: true, get: function () { return builder_1.TableRef; } });
|
|
33
33
|
__exportStar(require("./reader"), exports);
|
|
34
34
|
__exportStar(require("./intermediate"), exports);
|
|
35
|
+
__exportStar(require("./wrappers"), exports);
|
|
36
|
+
__exportStar(require("./branded"), exports);
|
|
35
37
|
const symbols_1 = __importDefault(require("./symbols"));
|
|
36
38
|
exports.default = symbols_1.default;
|
|
37
39
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,+CAA6B;AAC7B,8CAA4B;AAC5B,qCAAkF;AAA1E,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAS,mGAAA,QAAQ,OAAA;AAC/D,2CAAyB;AACzB,iDAA+B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,+CAA6B;AAC7B,8CAA4B;AAC5B,qCAAkF;AAA1E,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAS,mGAAA,QAAQ,OAAA;AAC/D,2CAAyB;AACzB,iDAA+B;AAC/B,6CAA2B;AAC3B,4CAA0B;AAE1B,wDAAgC;AAChC,kBAAe,iBAAO,CAAC"}
|
package/dist/operators.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Column, IOperandable, Order, TableMetaProvider, ITableRef, IBuildableSubSelectQuery } from "./interfaces";
|
|
1
|
+
import { Column, IOperandable, Order, TableMetaProvider, ITableRef, IBuildableSubSelectQuery, Queryable, DbValueType } from "./interfaces";
|
|
2
|
+
import { FunctionCall } from "./wrappers";
|
|
2
3
|
import { Window } from "./builder";
|
|
3
4
|
export declare function and(...operands: (boolean | IOperandable<boolean>)[]): IOperandable<boolean>;
|
|
4
5
|
export declare function or(...operands: (boolean | IOperandable<boolean>)[]): IOperandable<boolean>;
|
|
@@ -36,3 +37,20 @@ export declare function last_value<T>(value: Column<T> | IOperandable<T>, over:
|
|
|
36
37
|
export declare function nth_value<T>(value: Column<T> | IOperandable<T>, n: number, over: Window<any>, filter?: IOperandable<boolean> | boolean): IOperandable<unknown>;
|
|
37
38
|
export declare function lag<T>(value: Column<T> | IOperandable<T>, offset: number, def: T | null, over: Window<any>, filter?: IOperandable<boolean> | boolean): IOperandable<T>;
|
|
38
39
|
export declare function lead<T>(value: Column<T> | IOperandable<T>, offset: number, def: T | null, over: Window<any>, filter?: IOperandable<boolean> | boolean): IOperandable<T>;
|
|
40
|
+
/**
|
|
41
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL
|
|
42
|
+
*/
|
|
43
|
+
export declare function coalesce(...args: (Queryable<any> | DbValueType)[]): FunctionCall<unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-NULLIF
|
|
46
|
+
*/
|
|
47
|
+
export declare function nullif(value1: Queryable<any> | DbValueType, value2: Queryable<any> | DbValueType): FunctionCall<unknown>;
|
|
48
|
+
/**
|
|
49
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
|
|
50
|
+
*/
|
|
51
|
+
export declare function greatest(...args: (Queryable<any> | DbValueType)[]): FunctionCall<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
|
|
54
|
+
*/
|
|
55
|
+
export declare function least(...args: (Queryable<any> | DbValueType)[]): FunctionCall<unknown>;
|
|
56
|
+
export declare function date_trunc(granularity: string, date: Queryable<Date> | Date | string): FunctionCall<unknown>;
|
package/dist/operators.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lead = exports.lag = exports.nth_value = exports.last_value = exports.first_value = exports.cume_dist = exports.percent_rank = exports.dense_rank = exports.rank = exports.row_number = exports.case_ = exports.cast = exports.alias = exports.of = exports.desc = exports.asc = exports.min = exports.max = exports.count = exports.sum = exports.avg = exports.exists = exports.any = exports.all = exports.not = exports.or = exports.and = void 0;
|
|
3
|
+
exports.date_trunc = exports.least = exports.greatest = exports.nullif = exports.coalesce = exports.lead = exports.lag = exports.nth_value = exports.last_value = exports.first_value = exports.cume_dist = exports.percent_rank = exports.dense_rank = exports.rank = exports.row_number = exports.case_ = exports.cast = exports.alias = exports.of = exports.desc = exports.asc = exports.min = exports.max = exports.count = exports.sum = exports.avg = exports.exists = exports.any = exports.all = exports.not = exports.or = exports.and = void 0;
|
|
4
4
|
const wrappers_1 = require("./wrappers");
|
|
5
5
|
const symbols_1 = require("./symbols");
|
|
6
6
|
function and(...operands) {
|
|
@@ -130,4 +130,36 @@ function lead(value, offset, def, over, filter) {
|
|
|
130
130
|
return new wrappers_1.FunctionWindowCall('lead', filter !== null && filter !== void 0 ? filter : null, over, [value, offset !== null && offset !== void 0 ? offset : 1, def !== null && def !== void 0 ? def : null]);
|
|
131
131
|
}
|
|
132
132
|
exports.lead = lead;
|
|
133
|
+
/**
|
|
134
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL
|
|
135
|
+
*/
|
|
136
|
+
function coalesce(...args) {
|
|
137
|
+
return new wrappers_1.FunctionCall('COALESCE', args);
|
|
138
|
+
}
|
|
139
|
+
exports.coalesce = coalesce;
|
|
140
|
+
/**
|
|
141
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-NULLIF
|
|
142
|
+
*/
|
|
143
|
+
function nullif(value1, value2) {
|
|
144
|
+
return new wrappers_1.FunctionCall('NULLIF', [value1, value2]);
|
|
145
|
+
}
|
|
146
|
+
exports.nullif = nullif;
|
|
147
|
+
/**
|
|
148
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
|
|
149
|
+
*/
|
|
150
|
+
function greatest(...args) {
|
|
151
|
+
return new wrappers_1.FunctionCall('GREATEST', args);
|
|
152
|
+
}
|
|
153
|
+
exports.greatest = greatest;
|
|
154
|
+
/**
|
|
155
|
+
* https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
|
|
156
|
+
*/
|
|
157
|
+
function least(...args) {
|
|
158
|
+
return new wrappers_1.FunctionCall('LEAST', args);
|
|
159
|
+
}
|
|
160
|
+
exports.least = least;
|
|
161
|
+
function date_trunc(granularity, date) {
|
|
162
|
+
return new wrappers_1.FunctionCall('DATE_TRUNC', [granularity, date]);
|
|
163
|
+
}
|
|
164
|
+
exports.date_trunc = date_trunc;
|
|
133
165
|
//# sourceMappingURL=operators.js.map
|
package/dist/operators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":";;;AAWA,yCAAwF;AACxF,uCAA8C;AAG9C,SAAgB,GAAG,CAAC,GAAG,QAA6C;IAClE,OAAO,IAAI,sBAAW,CAAC,KAAK,EAAE,QAAQ,CAA0B,CAAA;AAClE,CAAC;AAFD,kBAEC;AAED,SAAgB,EAAE,CAAC,GAAG,QAA6C;IACjE,OAAO,IAAI,sBAAW,CAAC,IAAI,EAAE,QAAQ,CAA0B,CAAA;AACjE,CAAC;AAFD,gBAEC;AAED,SAAgB,GAAG,CAAC,SAA0C;IAC5D,OAAO,IAAI,sBAAW,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,CAA0B,CAAA;AACrE,CAAC;AAFD,kBAEC;AAED,SAAgB,GAAG,CAAQ,QAAkC;IAC3D,OAAO,IAAI,sBAAW,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAoB,CAAA;AAC9D,CAAC;AAFD,kBAEC;AAED,SAAgB,GAAG,CAAQ,QAAkC;IAC3D,OAAO,IAAI,sBAAW,C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
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
alias,
|
|
3
|
+
and,
|
|
4
|
+
asc,
|
|
5
|
+
Delete,
|
|
6
|
+
desc,
|
|
7
|
+
Insert,
|
|
8
|
+
max,
|
|
9
|
+
Select,
|
|
10
|
+
sum,
|
|
11
|
+
TableMetadataSymbol,
|
|
12
|
+
Update,
|
|
13
|
+
Upsert,
|
|
14
|
+
of,
|
|
15
|
+
dbFilterField
|
|
16
|
+
} from '../src';
|
|
17
|
+
import {Employee, MailingList, Person, PersonId, Tag, TagPerson} from './models';
|
|
18
|
+
import {TableRef, readModelMeta, Window} from '../src/builder';
|
|
19
|
+
import {count, dbField, dbTable, exists, case_, cast, first_value, IOperandable} from "../src";
|
|
5
20
|
import {FunctionCall} from "../src/wrappers";
|
|
6
21
|
|
|
7
22
|
|
|
8
23
|
const tableInfo = readModelMeta(Person);
|
|
9
24
|
const tableName = tableInfo.tableName;
|
|
10
|
-
const person: InstanceType<typeof Person> = {id: 1, name: 'Name', age: 18, city: 'City', profiles: ["profile-a"]};
|
|
25
|
+
const person: InstanceType<typeof Person> = {id: 1 as PersonId, name: 'Name', age: 18, city: 'City', profiles: ["profile-a"]};
|
|
11
26
|
|
|
12
27
|
describe('Select', () => {
|
|
13
28
|
|
package/tests/models.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {dbField, dbTable, IDbField, dbFilterField, and, Select, DbValueType,
|
|
1
|
+
import {dbField, dbTable, IDbField, dbFilterField, and, Select, DbValueType,
|
|
2
|
+
IOperandable, cast, FunctionCall, Branded} from '../src';
|
|
2
3
|
|
|
3
4
|
const UUID: IDbField = {}
|
|
4
5
|
|
|
6
|
+
export type PersonId = Branded<number, 'PersonId'>;
|
|
7
|
+
export type PersonUid = Branded<string, 'PersonUid'>;
|
|
8
|
+
|
|
5
9
|
@dbTable('Person', [{name: 'idx', fields: ['id']}])
|
|
6
10
|
export class Person {
|
|
7
11
|
@dbField({
|
|
8
12
|
primaryKey: true,
|
|
9
13
|
autoIncrement: true
|
|
10
14
|
})
|
|
11
|
-
id!:
|
|
15
|
+
id!: PersonId;
|
|
12
16
|
|
|
13
17
|
@dbField({
|
|
14
18
|
kind: UUID
|
|
15
19
|
})
|
|
16
|
-
uid?:
|
|
20
|
+
uid?: PersonUid;
|
|
17
21
|
|
|
18
22
|
@dbField name!: string;
|
|
19
23
|
@dbField age!: number;
|
|
@@ -36,13 +40,16 @@ export class Person {
|
|
|
36
40
|
tags?: string[];
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
export type TagId = Branded<number, 'TagId'>;
|
|
44
|
+
|
|
39
45
|
@dbTable('Tag')
|
|
40
46
|
export class Tag {
|
|
41
47
|
@dbField({
|
|
42
48
|
primaryKey: true,
|
|
43
49
|
autoIncrement: true
|
|
44
50
|
})
|
|
45
|
-
public id!:
|
|
51
|
+
public id!: TagId;
|
|
52
|
+
|
|
46
53
|
@dbField public name!: string;
|
|
47
54
|
}
|
|
48
55
|
|
|
@@ -51,16 +58,16 @@ export class TagPerson {
|
|
|
51
58
|
@dbField({
|
|
52
59
|
primaryKey: true,
|
|
53
60
|
})
|
|
54
|
-
public person!:
|
|
61
|
+
public person!: PersonId;
|
|
55
62
|
@dbField({
|
|
56
63
|
primaryKey: true,
|
|
57
64
|
})
|
|
58
|
-
public tag!:
|
|
65
|
+
public tag!: TagId;
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
@dbTable('Employee')
|
|
62
69
|
export class Employee {
|
|
63
|
-
@dbField personId!:
|
|
70
|
+
@dbField personId!: PersonId;
|
|
64
71
|
@dbField company!: string;
|
|
65
72
|
@dbField salary!: number;
|
|
66
73
|
}
|
|
@@ -80,12 +87,14 @@ export const EMAIL: IDbField = {
|
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
export type MailingListId = Branded<number, 'MailingListId'>;
|
|
91
|
+
|
|
83
92
|
export class MailingList {
|
|
84
93
|
@dbField({
|
|
85
94
|
primaryKey: true,
|
|
86
95
|
autoIncrement: true
|
|
87
96
|
})
|
|
88
|
-
public id!:
|
|
97
|
+
public id!: MailingListId;
|
|
89
98
|
@dbField public name!: string;
|
|
90
99
|
@dbField({kind: EMAIL}) email!: string;
|
|
91
100
|
}
|
package/tests/reader.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reader, IQueryData, dbTable, IDbField, dbField, DbValueType } from '../dist';
|
|
2
|
-
import { Person } from './models';
|
|
2
|
+
import { Person, PersonId, PersonUid} from './models';
|
|
3
3
|
|
|
4
4
|
const DB_JSON: IDbField = {
|
|
5
5
|
reader(raw: DbValueType): any {
|
|
@@ -14,11 +14,11 @@ function generatePersons(quantity: number): IQueryData[] {
|
|
|
14
14
|
const res = [];
|
|
15
15
|
for (let i = 1; i <= quantity; i++) {
|
|
16
16
|
const person = new Person();
|
|
17
|
-
person['id'] = i;
|
|
17
|
+
person['id'] = i as PersonId;
|
|
18
18
|
person['city'] = `TestCity${i}`;
|
|
19
19
|
person['age'] = 18;
|
|
20
20
|
person['name'] = `TestName${i}`;
|
|
21
|
-
person['uid'] = `uid${i}
|
|
21
|
+
person['uid'] = `uid${i}` as PersonUid;
|
|
22
22
|
// person['profiles'] = ['profile-a'];
|
|
23
23
|
res.push(person);
|
|
24
24
|
}
|
|
@@ -41,12 +41,12 @@ describe('DbReader', () => {
|
|
|
41
41
|
it('read Model', () => {
|
|
42
42
|
@dbTable
|
|
43
43
|
class Model {
|
|
44
|
-
@dbField public readonly id!:
|
|
44
|
+
@dbField public readonly id!: PersonId;
|
|
45
45
|
@dbField('raw') public readonly value!: string;
|
|
46
46
|
@dbField({sensitive: true, nullable: true}) public readonly password?: string;
|
|
47
47
|
@dbField({kind: DB_JSON, model: [Person]}) public readonly personal!: Person[];
|
|
48
48
|
|
|
49
|
-
constructor(id, raw, personal) {
|
|
49
|
+
constructor(id: PersonId, raw, personal) {
|
|
50
50
|
this.id = id;
|
|
51
51
|
this.value = raw;
|
|
52
52
|
this.personal = personal
|
|
@@ -59,7 +59,7 @@ describe('DbReader', () => {
|
|
|
59
59
|
personal: JSON.stringify(persons),
|
|
60
60
|
password: 'test'
|
|
61
61
|
}
|
|
62
|
-
const expected = new Model(5, 'false', persons);
|
|
62
|
+
const expected = new Model(5 as PersonId, 'false', persons);
|
|
63
63
|
|
|
64
64
|
const results = reader([model], Model);
|
|
65
65
|
expect(results.length).toBe(1);
|
|
@@ -71,12 +71,12 @@ describe('DbReader', () => {
|
|
|
71
71
|
it('read Model incl sensitive', () => {
|
|
72
72
|
@dbTable
|
|
73
73
|
class Model {
|
|
74
|
-
@dbField public readonly id!:
|
|
74
|
+
@dbField public readonly id!: PersonId;
|
|
75
75
|
@dbField('raw') public readonly value!: string;
|
|
76
76
|
@dbField({sensitive: true, nullable: true}) public readonly password?: string;
|
|
77
77
|
@dbField({kind: DB_JSON, model: [Person]}) public readonly personal!: Person[];
|
|
78
78
|
|
|
79
|
-
constructor(id, raw, personal, password) {
|
|
79
|
+
constructor(id: PersonId, raw, personal, password) {
|
|
80
80
|
this.id = id;
|
|
81
81
|
this.value = raw;
|
|
82
82
|
this.personal = personal
|
|
@@ -90,7 +90,7 @@ describe('DbReader', () => {
|
|
|
90
90
|
personal: JSON.stringify(persons),
|
|
91
91
|
password: 'test'
|
|
92
92
|
}
|
|
93
|
-
const expected = new Model(5, 'false', persons, 'test');
|
|
93
|
+
const expected = new Model(5 as PersonId, 'false', persons, 'test');
|
|
94
94
|
|
|
95
95
|
const results = reader([model], Model, true);
|
|
96
96
|
expect(results.length).toBe(1);
|
|
@@ -102,11 +102,11 @@ describe('DbReader', () => {
|
|
|
102
102
|
it('read Model from no data', () => {
|
|
103
103
|
@dbTable
|
|
104
104
|
class Model {
|
|
105
|
-
@dbField public readonly id!:
|
|
105
|
+
@dbField public readonly id!: PersonId;
|
|
106
106
|
@dbField('raw') public readonly value!: string;
|
|
107
107
|
@dbField({kind: DB_JSON, model: [Person]}) public readonly personal!: Person[];
|
|
108
108
|
|
|
109
|
-
constructor(id, raw, personal) {
|
|
109
|
+
constructor(id: PersonId, raw, personal) {
|
|
110
110
|
this.id = id;
|
|
111
111
|
this.value = raw;
|
|
112
112
|
this.personal = personal
|
|
@@ -120,11 +120,11 @@ describe('DbReader', () => {
|
|
|
120
120
|
it('read Object from no json', () => {
|
|
121
121
|
@dbTable
|
|
122
122
|
class Model {
|
|
123
|
-
@dbField public readonly id!:
|
|
123
|
+
@dbField public readonly id!: PersonId;
|
|
124
124
|
@dbField('raw') public readonly value!: string;
|
|
125
125
|
@dbField({kind: DB_JSON, model: Object, nullable: true}) public readonly some_other!: object | null;
|
|
126
126
|
|
|
127
|
-
constructor(id, raw, some_other) {
|
|
127
|
+
constructor(id: PersonId, raw, some_other) {
|
|
128
128
|
this.id = id;
|
|
129
129
|
this.value = raw;
|
|
130
130
|
this.some_other = some_other
|