leoric 2.6.2 → 2.7.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 +783 -0
- package/index.js +4 -1
- package/package.json +2 -1
- package/src/adapters/sequelize.js +6 -6
- package/src/bone.js +9 -7
- package/src/collection.js +0 -8
- package/src/constants.js +3 -0
- package/src/data_types.js +438 -428
- package/src/data_types.js.map +1 -0
- package/src/data_types.ts +600 -0
- package/src/decorators.js +29 -5
- package/src/decorators.js.map +1 -1
- package/src/decorators.ts +20 -9
- package/src/drivers/abstract/index.js +8 -8
- package/src/drivers/abstract/spellbook.js +10 -8
- package/src/drivers/mysql/data_types.js +1 -1
- package/src/drivers/mysql/index.js +4 -2
- package/src/drivers/postgres/data_types.js +2 -2
- package/src/drivers/postgres/index.js +6 -2
- package/src/drivers/postgres/type_parser.js +7 -0
- package/src/drivers/sqlite/data_types.js +2 -2
- package/src/realm.js +11 -7
- package/src/spell.js +2 -2
- package/src/utils/index.js +8 -0
- package/types/index.d.ts +16 -16
- package/types/data_types.d.ts +0 -105
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const Logger = require('./src/drivers/abstract/logger');
|
|
|
5
5
|
const Spell = require('./src/spell');
|
|
6
6
|
const Bone = require('./src/bone');
|
|
7
7
|
const Collection = require('./src/collection');
|
|
8
|
-
const { invokable: DataTypes } = require('./src/data_types');
|
|
8
|
+
const { invokable: DataTypes, LENGTH_VARIANTS } = require('./src/data_types');
|
|
9
9
|
const migrations = require('./src/migrations');
|
|
10
10
|
const sequelize = require('./src/adapters/sequelize');
|
|
11
11
|
const { heresql } = require('./src/utils/string');
|
|
@@ -14,6 +14,7 @@ const Realm = require('./src/realm');
|
|
|
14
14
|
const Decorators = require('./src/decorators');
|
|
15
15
|
const Raw = require('./src/raw');
|
|
16
16
|
const { MysqlDriver, PostgresDriver, SqliteDriver, AbstractDriver } = require('./src/drivers');
|
|
17
|
+
const { isBone } = require('./src/utils');
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {Object} RawSql
|
|
@@ -64,6 +65,8 @@ Object.assign(Realm, {
|
|
|
64
65
|
SqliteDriver,
|
|
65
66
|
AbstractDriver,
|
|
66
67
|
Raw,
|
|
68
|
+
LENGTH_VARIANTS,
|
|
69
|
+
isBone,
|
|
67
70
|
});
|
|
68
71
|
|
|
69
72
|
module.exports = Realm;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leoric",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "JavaScript Object-relational mapping alchemy",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@types/node": "^16.10.1",
|
|
68
68
|
"dayjs": "^1.10.3",
|
|
69
69
|
"eslint": "^7.20.0",
|
|
70
|
+
"eslint-plugin-no-only-tests": "^3.0.0",
|
|
70
71
|
"expect.js": "^0.3.1",
|
|
71
72
|
"jsdoc": "^3.6.3",
|
|
72
73
|
"mocha": "^8.2.1",
|
|
@@ -65,7 +65,7 @@ const setScopeToSpell = (scope) => (spell) => {
|
|
|
65
65
|
* @returns {Object}
|
|
66
66
|
*/
|
|
67
67
|
function mergeScope(scopes) {
|
|
68
|
-
|
|
68
|
+
const merged = {};
|
|
69
69
|
for (const scope of scopes) {
|
|
70
70
|
if (scope.where) {
|
|
71
71
|
merged.where = Object.assign({}, merged.where, scope.where);
|
|
@@ -227,7 +227,7 @@ module.exports = Bone => {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
const { where } = options;
|
|
230
|
-
|
|
230
|
+
const spell = this._find(where, options)[`$${func}`](name);
|
|
231
231
|
if (options.paranoid === false) return spell.unparanoid;
|
|
232
232
|
return spell;
|
|
233
233
|
}
|
|
@@ -262,9 +262,9 @@ module.exports = Bone => {
|
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
264
|
* see https://github.com/sequelize/sequelize/blob/a729c4df41fa3a58fbecaf879265d2fb73d80e5f/src/model.js#L2299
|
|
265
|
-
* @param {Array<Object>} valueSets
|
|
266
|
-
* @param {Object} options
|
|
267
|
-
* @returns
|
|
265
|
+
* @param {Array<Object>} valueSets
|
|
266
|
+
* @param {Object} options
|
|
267
|
+
* @returns
|
|
268
268
|
*/
|
|
269
269
|
static bulkBuild(valueSets, options = {}) {
|
|
270
270
|
if (!valueSets.length) return [];
|
|
@@ -333,7 +333,7 @@ module.exports = Bone => {
|
|
|
333
333
|
// static drop() {}
|
|
334
334
|
|
|
335
335
|
static findAll(options = {}) {
|
|
336
|
-
|
|
336
|
+
const spell = this._find({}, filterOptions(options));
|
|
337
337
|
translateOptions(spell, options);
|
|
338
338
|
if (options.paranoid === false) return spell.unparanoid;
|
|
339
339
|
return spell;
|
package/src/bone.js
CHANGED
|
@@ -10,7 +10,7 @@ const pluralize = require('pluralize');
|
|
|
10
10
|
const { executeValidator, LeoricValidateError } = require('./validator');
|
|
11
11
|
require('reflect-metadata');
|
|
12
12
|
|
|
13
|
-
const DataTypes = require('./data_types');
|
|
13
|
+
const { default: DataTypes } = require('./data_types');
|
|
14
14
|
const Collection = require('./collection');
|
|
15
15
|
const Spell = require('./spell');
|
|
16
16
|
const Raw = require('./raw');
|
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
LEGACY_TIMESTAMP_COLUMN_MAP,
|
|
22
22
|
ASSOCIATE_METADATA_MAP,
|
|
23
23
|
TIMESTAMP_ATTRIBUTE_NAMES,
|
|
24
|
+
IS_LEORIC_BONE,
|
|
24
25
|
} = require('./constants');
|
|
25
26
|
|
|
26
27
|
const columnAttributesKey = Symbol('leoric#columns');
|
|
@@ -101,7 +102,7 @@ function valuesValidate(values, attributes, ctx) {
|
|
|
101
102
|
const value = values[valueKey];
|
|
102
103
|
if (value == null && defaultValue == null) {
|
|
103
104
|
if (allowNull === false) throw new LeoricValidateError('notNull', name);
|
|
104
|
-
if ((allowNull === true || allowNull === undefined) && validate.notNull === undefined
|
|
105
|
+
if ((allowNull === true || allowNull === undefined) && validate.notNull === undefined) continue;
|
|
105
106
|
}
|
|
106
107
|
if (!validate) continue;
|
|
107
108
|
for (const key in validate) {
|
|
@@ -699,7 +700,7 @@ class Bone {
|
|
|
699
700
|
async _update(values, options = {}) {
|
|
700
701
|
const Model = this.constructor;
|
|
701
702
|
const { attributes, primaryKey, shardingKey } = Model;
|
|
702
|
-
|
|
703
|
+
const changes = {};
|
|
703
704
|
if (values == null) {
|
|
704
705
|
for (const name in attributes) {
|
|
705
706
|
if (this.changed(name)) changes[name] = this.attribute(name);
|
|
@@ -727,7 +728,7 @@ class Bone {
|
|
|
727
728
|
if (attributes[updatedAt] && !changes[updatedAt] && !changes[deletedAt] && !options.silent) {
|
|
728
729
|
changes[updatedAt] = new Date();
|
|
729
730
|
}
|
|
730
|
-
if (options.validate !== false
|
|
731
|
+
if (options.validate !== false) {
|
|
731
732
|
this._validateAttributes(changes);
|
|
732
733
|
}
|
|
733
734
|
const spell = new Spell(Model, options).$where(where).$update(changes);
|
|
@@ -910,10 +911,9 @@ class Bone {
|
|
|
910
911
|
const { attributes } = Model;
|
|
911
912
|
for (const key in attributes) {
|
|
912
913
|
const attribute = attributes[key];
|
|
913
|
-
if (attribute.primaryKey) continue;
|
|
914
914
|
if (values[key] == null && attribute.defaultValue != null) {
|
|
915
915
|
data[key] = attribute.defaultValue;
|
|
916
|
-
} else if (values[key] !== undefined){
|
|
916
|
+
} else if (values[key] !== undefined) {
|
|
917
917
|
data[key] = values[key];
|
|
918
918
|
}
|
|
919
919
|
}
|
|
@@ -1667,7 +1667,7 @@ class Bone {
|
|
|
1667
1667
|
if (force) {
|
|
1668
1668
|
await driver.dropTable(table);
|
|
1669
1669
|
await driver.createTable(table, attributes);
|
|
1670
|
-
} else if (alter){
|
|
1670
|
+
} else if (alter) {
|
|
1671
1671
|
await driver.alterTable(table, compare(attributes, columnMap));
|
|
1672
1672
|
} else {
|
|
1673
1673
|
console.warn('[synchronize_fail] %s couldn\'t be synchronized, please use force or alter to specify execution', this.name);
|
|
@@ -1715,4 +1715,6 @@ for (const getter of Spell_getters) {
|
|
|
1715
1715
|
});
|
|
1716
1716
|
}
|
|
1717
1717
|
|
|
1718
|
+
Reflect.defineMetadata(IS_LEORIC_BONE, true, Bone);
|
|
1719
|
+
|
|
1718
1720
|
module.exports = Bone;
|
package/src/collection.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { AGGREGATOR_MAP } = require('./constants');
|
|
4
|
-
|
|
5
|
-
const AGGREGATORS = Object.values(AGGREGATOR_MAP);
|
|
6
3
|
/**
|
|
7
4
|
* An extended Array to represent collections of models.
|
|
8
5
|
*/
|
|
@@ -92,11 +89,6 @@ function dispatch(spell, rows, fields) {
|
|
|
92
89
|
const row = rows[0];
|
|
93
90
|
const record = row && (row[''] || row[table]);
|
|
94
91
|
const result = record && record[value];
|
|
95
|
-
// see https://www.w3schools.com/mysql/mysql_ref_functions.asp
|
|
96
|
-
if (AGGREGATORS.includes(args[0].name)) {
|
|
97
|
-
const num = Number(result);
|
|
98
|
-
return isNaN(num) ? result : num;
|
|
99
|
-
}
|
|
100
92
|
return result;
|
|
101
93
|
}
|
|
102
94
|
}
|
package/src/constants.js
CHANGED
|
@@ -36,6 +36,8 @@ const ASSOCIATE_METADATA_MAP = {
|
|
|
36
36
|
belongsTo: Symbol('belongsTo'),
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const IS_LEORIC_BONE = Symbol('leoric#bone');
|
|
40
|
+
|
|
39
41
|
module.exports = {
|
|
40
42
|
AGGREGATOR_MAP,
|
|
41
43
|
LEGACY_TIMESTAMP_MAP,
|
|
@@ -44,4 +46,5 @@ module.exports = {
|
|
|
44
46
|
ASSOCIATE_METADATA_MAP,
|
|
45
47
|
TIMESTAMP_ATTRIBUTE_NAMES,
|
|
46
48
|
AGGREGATORS,
|
|
49
|
+
IS_LEORIC_BONE,
|
|
47
50
|
};
|