leoric 2.4.0 → 2.4.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/History.md +9 -0
- package/package.json +1 -1
- package/src/bone.js +2 -2
- package/src/data_types.js +32 -32
- package/src/drivers/abstract/attribute.js +1 -1
- package/src/drivers/postgres/data_types.js +2 -2
- package/src/drivers/sqlite/data_types.js +9 -9
- package/src/utils/invokable.js +3 -0
- package/types/data_types.d.ts +35 -32
- package/types/index.d.ts +7 -1
package/History.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
2.4.1 / 2022-04-27
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: realm.Bone.DataTypes should be invokable, Invokable.TYPE.toSqlString() get wrong default length(1), DataType definitions by @JimmyDaddy in https://github.com/cyjake/leoric/pull/307
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.4.0...v2.4.1
|
|
9
|
+
|
|
1
10
|
2.4.0 / 2022-04-24
|
|
2
11
|
==================
|
|
3
12
|
|
package/package.json
CHANGED
package/src/bone.js
CHANGED
|
@@ -138,6 +138,8 @@ function valuesValidate(values, attributes, ctx) {
|
|
|
138
138
|
*/
|
|
139
139
|
class Bone {
|
|
140
140
|
|
|
141
|
+
static DataTypes = DataTypes.invokable;
|
|
142
|
+
|
|
141
143
|
// private variables
|
|
142
144
|
#raw = {};
|
|
143
145
|
#rawSaved = {};
|
|
@@ -1712,6 +1714,4 @@ for (const getter of Spell_getters) {
|
|
|
1712
1714
|
});
|
|
1713
1715
|
}
|
|
1714
1716
|
|
|
1715
|
-
Object.assign(Bone, { DataTypes });
|
|
1716
|
-
|
|
1717
1717
|
module.exports = Bone;
|
package/src/data_types.js
CHANGED
|
@@ -110,20 +110,20 @@ class DataType {
|
|
|
110
110
|
* STRING
|
|
111
111
|
* STRING(127)
|
|
112
112
|
* STRING.BINARY
|
|
113
|
-
* @param {number}
|
|
113
|
+
* @param {number} dataLength
|
|
114
114
|
*/
|
|
115
115
|
class STRING extends DataType {
|
|
116
|
-
constructor(
|
|
116
|
+
constructor(dataLength = 255) {
|
|
117
117
|
super();
|
|
118
118
|
this.dataType = 'varchar';
|
|
119
|
-
this.
|
|
119
|
+
this.dataLength = dataLength;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
toSqlString() {
|
|
123
|
-
const {
|
|
123
|
+
const { dataLength } = this;
|
|
124
124
|
const dataType = this.dataType.toUpperCase();
|
|
125
125
|
const chunks = [];
|
|
126
|
-
chunks.push(
|
|
126
|
+
chunks.push(dataLength > 0 ? `${dataType}(${dataLength})` : dataType);
|
|
127
127
|
return chunks.join(' ');
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -134,17 +134,17 @@ class STRING extends DataType {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
class BINARY extends DataType {
|
|
137
|
-
constructor(
|
|
137
|
+
constructor(dataLength = 255) {
|
|
138
138
|
super();
|
|
139
|
-
this.
|
|
139
|
+
this.dataLength = dataLength;
|
|
140
140
|
this.dataType = 'binary';
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
toSqlString() {
|
|
144
|
-
const {
|
|
144
|
+
const { dataLength } = this;
|
|
145
145
|
const dataType = this.dataType.toUpperCase();
|
|
146
146
|
const chunks = [];
|
|
147
|
-
chunks.push(
|
|
147
|
+
chunks.push(dataLength > 0 ? `${dataType}(${dataLength})` : dataType);
|
|
148
148
|
return chunks.join(' ');
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -156,8 +156,8 @@ class BINARY extends DataType {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
class VARBINARY extends BINARY {
|
|
159
|
-
constructor(
|
|
160
|
-
super(
|
|
159
|
+
constructor(dataLength) {
|
|
160
|
+
super(dataLength);
|
|
161
161
|
this.dataType = 'varbinary';
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -170,12 +170,12 @@ class VARBINARY extends BINARY {
|
|
|
170
170
|
* INTEGER.UNSIGNED
|
|
171
171
|
* INTEGER.UNSIGNED.ZEROFILL
|
|
172
172
|
* INTEGER(10)
|
|
173
|
-
* @param {number}
|
|
173
|
+
* @param {number} dataLength
|
|
174
174
|
*/
|
|
175
175
|
class INTEGER extends DataType {
|
|
176
|
-
constructor(
|
|
176
|
+
constructor(dataLength) {
|
|
177
177
|
super();
|
|
178
|
-
this.
|
|
178
|
+
this.dataLength = dataLength;
|
|
179
179
|
this.dataType = 'integer';
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -190,10 +190,10 @@ class INTEGER extends DataType {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
toSqlString() {
|
|
193
|
-
const {
|
|
193
|
+
const { dataLength, unsigned, zerofill } = this;
|
|
194
194
|
const dataType = this.dataType.toUpperCase();
|
|
195
195
|
const chunks = [];
|
|
196
|
-
chunks.push(
|
|
196
|
+
chunks.push(dataLength > 0 ? `${dataType}(${dataLength})` : dataType);
|
|
197
197
|
if (unsigned) chunks.push('UNSIGNED');
|
|
198
198
|
if (zerofill) chunks.push('ZEROFILL');
|
|
199
199
|
return chunks.join(' ');
|
|
@@ -222,11 +222,11 @@ class INTEGER extends DataType {
|
|
|
222
222
|
* TINYINT
|
|
223
223
|
* TINYINT.UNSIGNED
|
|
224
224
|
* TINYINT(1)
|
|
225
|
-
* @param {number}
|
|
225
|
+
* @param {number} dataLength
|
|
226
226
|
*/
|
|
227
227
|
class TINYINT extends INTEGER {
|
|
228
|
-
constructor(
|
|
229
|
-
super(
|
|
228
|
+
constructor(dataLength) {
|
|
229
|
+
super(dataLength);
|
|
230
230
|
this.dataType = 'tinyint';
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -237,11 +237,11 @@ class TINYINT extends INTEGER {
|
|
|
237
237
|
* SMALLINT
|
|
238
238
|
* SMALLINT.UNSIGNED
|
|
239
239
|
* SMALLINT(2)
|
|
240
|
-
* @param {number}
|
|
240
|
+
* @param {number} dataLength
|
|
241
241
|
*/
|
|
242
242
|
class SMALLINT extends INTEGER {
|
|
243
|
-
constructor(
|
|
244
|
-
super(
|
|
243
|
+
constructor(dataLength) {
|
|
244
|
+
super(dataLength);
|
|
245
245
|
this.dataType = 'smallint';
|
|
246
246
|
}
|
|
247
247
|
}
|
|
@@ -252,11 +252,11 @@ class SMALLINT extends INTEGER {
|
|
|
252
252
|
* MEDIUMINT
|
|
253
253
|
* MEDIUMINT.UNSIGNED
|
|
254
254
|
* MEDIUMINT(3)
|
|
255
|
-
* @param {number}
|
|
255
|
+
* @param {number} dataLength
|
|
256
256
|
*/
|
|
257
257
|
class MEDIUMINT extends INTEGER {
|
|
258
|
-
constructor(
|
|
259
|
-
super(
|
|
258
|
+
constructor(dataLength) {
|
|
259
|
+
super(dataLength);
|
|
260
260
|
this.dataType = 'mediumint';
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -268,11 +268,11 @@ class MEDIUMINT extends INTEGER {
|
|
|
268
268
|
* BIGINT
|
|
269
269
|
* BIGINT.UNSIGNED
|
|
270
270
|
* BIGINT(8)
|
|
271
|
-
* @param {number}
|
|
271
|
+
* @param {number} dataLength
|
|
272
272
|
*/
|
|
273
273
|
class BIGINT extends INTEGER {
|
|
274
|
-
constructor(
|
|
275
|
-
super(
|
|
274
|
+
constructor(dataLength) {
|
|
275
|
+
super(dataLength);
|
|
276
276
|
this.dataType = 'bigint';
|
|
277
277
|
}
|
|
278
278
|
}
|
|
@@ -442,11 +442,11 @@ class TEXT extends DataType {
|
|
|
442
442
|
}
|
|
443
443
|
super();
|
|
444
444
|
this.dataType = 'text';
|
|
445
|
-
this.
|
|
445
|
+
this.dataLength = length;
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
toSqlString() {
|
|
449
|
-
return [ this.
|
|
449
|
+
return [ this.dataLength, this.dataType ].join('').toUpperCase();
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
|
|
@@ -457,11 +457,11 @@ class BLOB extends DataType {
|
|
|
457
457
|
}
|
|
458
458
|
super();
|
|
459
459
|
this.dataType = 'blob';
|
|
460
|
-
this.
|
|
460
|
+
this.dataLength = length;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
toSqlString() {
|
|
464
|
-
return [ this.
|
|
464
|
+
return [ this.dataLength, this.dataType ].join('').toUpperCase();
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
cast(value) {
|
|
@@ -34,8 +34,8 @@ class Sqlite_DATEONLY extends DataTypes.DATEONLY {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
class Sqlite_INTEGER extends DataTypes.INTEGER {
|
|
37
|
-
constructor(
|
|
38
|
-
super(
|
|
37
|
+
constructor(dataLength) {
|
|
38
|
+
super(dataLength);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
uncast(value) {
|
|
@@ -54,24 +54,24 @@ class Sqlite_BIGINT extends DataTypes.BIGINT {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
class Sqlite_BINARY extends DataTypes {
|
|
57
|
-
constructor(
|
|
58
|
-
super(
|
|
59
|
-
this.
|
|
57
|
+
constructor(dataLength = 255) {
|
|
58
|
+
super(dataLength);
|
|
59
|
+
this.dataLength = dataLength;
|
|
60
60
|
this.dataType = 'binary';
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
toSqlString() {
|
|
64
|
-
const {
|
|
64
|
+
const { dataLength } = this;
|
|
65
65
|
const dataType = this.dataType.toUpperCase();
|
|
66
66
|
const chunks = [];
|
|
67
67
|
chunks.push('VARCHAR');
|
|
68
|
-
chunks.push(
|
|
68
|
+
chunks.push(dataLength > 0 ? `${dataType}(${dataLength})` : dataType);
|
|
69
69
|
return chunks.join(' ');
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
class Sqlite_VARBINARY extends Sqlite_BINARY {
|
|
73
|
-
constructor(
|
|
74
|
-
super(
|
|
73
|
+
constructor(dataLength) {
|
|
74
|
+
super(dataLength);
|
|
75
75
|
this.dataType = 'varbinary';
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/utils/invokable.js
CHANGED
|
@@ -18,6 +18,9 @@ function invokable(DataType) {
|
|
|
18
18
|
|
|
19
19
|
// INTEGER.UNSIGNED
|
|
20
20
|
get(target, p) {
|
|
21
|
+
// ref: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/length
|
|
22
|
+
// The length property indicates the number of parameters expected by the function.
|
|
23
|
+
// invokable INTEGER.toSqlString() will default to return "INTEGER(1)"
|
|
21
24
|
return target.hasOwnProperty(p) ? target[p] : new target()[p];
|
|
22
25
|
}
|
|
23
26
|
});
|
package/types/data_types.d.ts
CHANGED
|
@@ -1,65 +1,68 @@
|
|
|
1
1
|
type LENGTH_VARIANTS = 'tiny' | '' | 'medium' | 'long';
|
|
2
2
|
|
|
3
|
-
interface INVOKABLE<T> {
|
|
4
|
-
(
|
|
5
|
-
(
|
|
3
|
+
interface INVOKABLE<T> extends DataType {
|
|
4
|
+
(dataLength?: LENGTH_VARIANTS): T;
|
|
5
|
+
(dataLength?: number): T;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export default class DataType {
|
|
9
9
|
toSqlString(): string;
|
|
10
10
|
|
|
11
|
-
static STRING:
|
|
12
|
-
static INTEGER:
|
|
13
|
-
static BIGINT:
|
|
14
|
-
static DECIMAL:
|
|
15
|
-
static TEXT:
|
|
16
|
-
static BLOB:
|
|
17
|
-
static JSON:
|
|
18
|
-
static JSONB:
|
|
19
|
-
static BINARY:
|
|
20
|
-
static VARBINARY:
|
|
21
|
-
static DATE:
|
|
22
|
-
static DATEONLY:
|
|
23
|
-
static BOOLEAN:
|
|
24
|
-
static VIRTUAL:
|
|
11
|
+
static STRING: INVOKABLE<STRING>;
|
|
12
|
+
static INTEGER: INTEGER & INVOKABLE<INTEGER>;
|
|
13
|
+
static BIGINT: BIGINT & INVOKABLE<BIGINT>;
|
|
14
|
+
static DECIMAL: DECIMAL & INVOKABLE<DECIMAL>;
|
|
15
|
+
static TEXT: INVOKABLE<TEXT>;
|
|
16
|
+
static BLOB: INVOKABLE<BLOB>;
|
|
17
|
+
static JSON: JSON;
|
|
18
|
+
static JSONB: JSONB;
|
|
19
|
+
static BINARY: BINARY & INVOKABLE<BINARY>;
|
|
20
|
+
static VARBINARY: VARBINARY & INVOKABLE<VARBINARY>;
|
|
21
|
+
static DATE: DATE & INVOKABLE<DATE>;
|
|
22
|
+
static DATEONLY: DATEONLY;
|
|
23
|
+
static BOOLEAN: BOOLEAN;
|
|
24
|
+
static VIRTUAL: VIRTUAL;
|
|
25
25
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
declare class STRING extends DataType {
|
|
29
29
|
dataType: 'varchar';
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
30
|
+
dataLength: number;
|
|
31
|
+
constructor(dataLength: number);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare class INTEGER extends DataType {
|
|
35
35
|
dataType: 'integer' | 'bigint' | 'decimal';
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
|
|
39
|
-
get
|
|
36
|
+
dataLength: number;
|
|
37
|
+
constructor(dataLength: number);
|
|
38
|
+
// avoid INTEGER.UNSIGNED.ZEROFILL.UNSIGNED.UNSIGNED
|
|
39
|
+
get UNSIGNED(): Omit<this, 'UNSIGNED' | 'ZEROFILL'>;
|
|
40
|
+
get ZEROFILL(): Omit<this, 'UNSIGNED' | 'ZEROFILL'>;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
declare class BIGINT extends INTEGER {
|
|
43
44
|
dataType: 'bigint';
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
declare class
|
|
47
|
+
declare class DECIMAL_INNER extends INTEGER {
|
|
47
48
|
dataType: 'decimal';
|
|
48
49
|
precision: number;
|
|
49
50
|
scale: number;
|
|
50
51
|
constructor(precision: number, scale: number);
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
declare type DECIMAL = Omit<DECIMAL_INNER, 'dataLength'>;
|
|
55
|
+
|
|
53
56
|
declare class TEXT extends DataType {
|
|
54
57
|
dataType: 'text';
|
|
55
|
-
|
|
56
|
-
constructor(
|
|
58
|
+
dataLength: LENGTH_VARIANTS;
|
|
59
|
+
constructor(dataLength: LENGTH_VARIANTS);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
declare class BLOB extends DataType {
|
|
60
63
|
dataType: 'blob';
|
|
61
|
-
|
|
62
|
-
constructor(
|
|
64
|
+
dataLength: LENGTH_VARIANTS;
|
|
65
|
+
constructor(dataLength: LENGTH_VARIANTS)
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
declare class JSON extends DataType {
|
|
@@ -72,14 +75,14 @@ declare class JSONB extends JSON {
|
|
|
72
75
|
|
|
73
76
|
declare class BINARY extends DataType {
|
|
74
77
|
dataType: 'binary';
|
|
75
|
-
|
|
76
|
-
constructor(
|
|
78
|
+
dataLength: number;
|
|
79
|
+
constructor(dataLength: number);
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
declare class VARBINARY extends DataType {
|
|
80
83
|
dataType: 'varbinary';
|
|
81
|
-
|
|
82
|
-
constructor(
|
|
84
|
+
dataLength: number;
|
|
85
|
+
constructor(dataLength: number);
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
declare class DATE extends DataType {
|
package/types/index.d.ts
CHANGED
|
@@ -179,11 +179,17 @@ export interface ColumnMeta {
|
|
|
179
179
|
comment?: string;
|
|
180
180
|
datetimePrecision?: string;
|
|
181
181
|
}
|
|
182
|
+
|
|
183
|
+
declare type validator = Literal | Function | Array<Literal | Literal[]>;
|
|
184
|
+
|
|
182
185
|
export interface AttributeMeta extends ColumnMeta {
|
|
183
186
|
jsType?: Literal;
|
|
184
187
|
type: DataType;
|
|
185
188
|
virtual?: boolean,
|
|
186
189
|
toSqlString: () => string;
|
|
190
|
+
validate: {
|
|
191
|
+
[key: string]: validator;
|
|
192
|
+
}
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
interface RelateOptions {
|
|
@@ -442,7 +448,7 @@ export class Collection<T extends Bone> extends Array<T> {
|
|
|
442
448
|
}
|
|
443
449
|
|
|
444
450
|
export class Bone {
|
|
445
|
-
static DataTypes: DataType;
|
|
451
|
+
static DataTypes: typeof DataType;
|
|
446
452
|
|
|
447
453
|
/**
|
|
448
454
|
* get the connection pool of the driver
|