leoric 2.6.3 → 2.7.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/History.md +11 -0
- package/index.js +2 -1
- package/package.json +2 -1
- package/src/adapters/sequelize.js +6 -6
- package/src/bone.js +6 -7
- package/src/data_types.js +442 -428
- package/src/data_types.js.map +1 -0
- package/src/data_types.ts +608 -0
- package/src/decorators.js +29 -5
- package/src/decorators.js.map +1 -1
- package/src/decorators.ts +16 -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 +2 -2
- package/src/drivers/postgres/data_types.js +1 -1
- package/src/drivers/sqlite/data_types.js +1 -1
- package/src/realm.js +9 -6
- package/types/index.d.ts +12 -16
- package/types/data_types.d.ts +0 -105
package/History.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2.7.0 / 2022-08-24
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: glue code for opts.dialectModulePath by @cyjake in https://github.com/cyjake/leoric/pull/326
|
|
6
|
+
* fix: primaryKey in upsert values should be validate in sqlite and postgres by @JimmyDaddy in https://github.com/cyjake/leoric/pull/328
|
|
7
|
+
* feat: change DataTypes to ts and complete decorators type definitions by @JimmyDaddy in https://github.com/cyjake/leoric/pull/319
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v2.6.3...v2.7.0
|
|
11
|
+
|
|
1
12
|
2.6.3 / 2022-08-04
|
|
2
13
|
==================
|
|
3
14
|
|
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');
|
|
@@ -65,6 +65,7 @@ Object.assign(Realm, {
|
|
|
65
65
|
SqliteDriver,
|
|
66
66
|
AbstractDriver,
|
|
67
67
|
Raw,
|
|
68
|
+
LENGTH_VARIANTS,
|
|
68
69
|
isBone,
|
|
69
70
|
});
|
|
70
71
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leoric",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
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 { DataTypes } = require('./data_types');
|
|
14
14
|
const Collection = require('./collection');
|
|
15
15
|
const Spell = require('./spell');
|
|
16
16
|
const Raw = require('./raw');
|
|
@@ -102,7 +102,7 @@ function valuesValidate(values, attributes, ctx) {
|
|
|
102
102
|
const value = values[valueKey];
|
|
103
103
|
if (value == null && defaultValue == null) {
|
|
104
104
|
if (allowNull === false) throw new LeoricValidateError('notNull', name);
|
|
105
|
-
if ((allowNull === true || allowNull === undefined) && validate.notNull === undefined
|
|
105
|
+
if ((allowNull === true || allowNull === undefined) && validate.notNull === undefined) continue;
|
|
106
106
|
}
|
|
107
107
|
if (!validate) continue;
|
|
108
108
|
for (const key in validate) {
|
|
@@ -700,7 +700,7 @@ class Bone {
|
|
|
700
700
|
async _update(values, options = {}) {
|
|
701
701
|
const Model = this.constructor;
|
|
702
702
|
const { attributes, primaryKey, shardingKey } = Model;
|
|
703
|
-
|
|
703
|
+
const changes = {};
|
|
704
704
|
if (values == null) {
|
|
705
705
|
for (const name in attributes) {
|
|
706
706
|
if (this.changed(name)) changes[name] = this.attribute(name);
|
|
@@ -728,7 +728,7 @@ class Bone {
|
|
|
728
728
|
if (attributes[updatedAt] && !changes[updatedAt] && !changes[deletedAt] && !options.silent) {
|
|
729
729
|
changes[updatedAt] = new Date();
|
|
730
730
|
}
|
|
731
|
-
if (options.validate !== false
|
|
731
|
+
if (options.validate !== false) {
|
|
732
732
|
this._validateAttributes(changes);
|
|
733
733
|
}
|
|
734
734
|
const spell = new Spell(Model, options).$where(where).$update(changes);
|
|
@@ -911,10 +911,9 @@ class Bone {
|
|
|
911
911
|
const { attributes } = Model;
|
|
912
912
|
for (const key in attributes) {
|
|
913
913
|
const attribute = attributes[key];
|
|
914
|
-
if (attribute.primaryKey) continue;
|
|
915
914
|
if (values[key] == null && attribute.defaultValue != null) {
|
|
916
915
|
data[key] = attribute.defaultValue;
|
|
917
|
-
} else if (values[key] !== undefined){
|
|
916
|
+
} else if (values[key] !== undefined) {
|
|
918
917
|
data[key] = values[key];
|
|
919
918
|
}
|
|
920
919
|
}
|
|
@@ -1668,7 +1667,7 @@ class Bone {
|
|
|
1668
1667
|
if (force) {
|
|
1669
1668
|
await driver.dropTable(table);
|
|
1670
1669
|
await driver.createTable(table, attributes);
|
|
1671
|
-
} else if (alter){
|
|
1670
|
+
} else if (alter) {
|
|
1672
1671
|
await driver.alterTable(table, compare(attributes, columnMap));
|
|
1673
1672
|
} else {
|
|
1674
1673
|
console.warn('[synchronize_fail] %s couldn\'t be synchronized, please use force or alter to specify execution', this.name);
|