imodel 0.17.2 → 0.18.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/index.d.mts +5 -5
- package/index.mjs +18 -18
- package/migrate.d.mts +1 -1
- package/migrate.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.
|
|
2
|
+
* imodel v0.18.0
|
|
3
3
|
* (c) 2019-2026 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
@@ -469,19 +469,19 @@ declare function deleting(size?: number): FieldDecorator<Date | null>;
|
|
|
469
469
|
|
|
470
470
|
/**
|
|
471
471
|
* @overload
|
|
472
|
-
* @param {Hooks} hook
|
|
472
|
+
* @param {Partial<Hooks>} hook
|
|
473
473
|
* @param {boolean} [approach] 插入位置是否为更靠近执行的位置
|
|
474
474
|
* @returns {ClassDecorator}
|
|
475
475
|
*/
|
|
476
|
-
declare function hooks(hook: Hooks
|
|
476
|
+
declare function hooks(hook: Partial<Hooks>, approach?: boolean | undefined): ClassDecorator;
|
|
477
477
|
/**
|
|
478
478
|
* @overload
|
|
479
479
|
* @param {Function} Model
|
|
480
|
-
* @param {Hooks} hook
|
|
480
|
+
* @param {Partial<Hooks>} hook
|
|
481
481
|
* @param {boolean} [approach] 插入位置是否为更靠近执行的位置
|
|
482
482
|
* @returns {void}
|
|
483
483
|
*/
|
|
484
|
-
declare function hooks(Model: Function, hook: Hooks
|
|
484
|
+
declare function hooks(Model: Function, hook: Partial<Hooks>, approach?: boolean | undefined): void;
|
|
485
485
|
/** @type {Hook<Hooks['where']>} */
|
|
486
486
|
declare const where: Hook<Hooks["where"]>;
|
|
487
487
|
/** @type {Hook<Hooks['beforeCreateMany']>} */
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.
|
|
2
|
+
* imodel v0.18.0
|
|
3
3
|
* (c) 2019-2026 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
@@ -3963,14 +3963,14 @@ function buildHooks(Model) {
|
|
|
3963
3963
|
const isBeforeList = [['where', true], ['beforeCreateMany', true], ['afterCreateMany', false], ['beforeCreate', true], ['afterCreate', false], ['beforeUpdate', true], ['afterUpdate', false], ['beforeDelete', true], ['afterDelete', false]];
|
|
3964
3964
|
/**
|
|
3965
3965
|
* @overload
|
|
3966
|
-
* @param {Hooks} hook
|
|
3966
|
+
* @param {Partial<Hooks>} hook
|
|
3967
3967
|
* @param {boolean} [approach] 插入位置是否为更靠近执行的位置
|
|
3968
3968
|
* @returns {ClassDecorator}
|
|
3969
3969
|
*/
|
|
3970
3970
|
/**
|
|
3971
3971
|
* @overload
|
|
3972
3972
|
* @param {Function} Model
|
|
3973
|
-
* @param {Hooks} hook
|
|
3973
|
+
* @param {Partial<Hooks>} hook
|
|
3974
3974
|
* @param {boolean} [approach] 插入位置是否为更靠近执行的位置
|
|
3975
3975
|
* @returns {void}
|
|
3976
3976
|
*/
|
|
@@ -5416,8 +5416,8 @@ function toPrimaries(model, documents) {
|
|
|
5416
5416
|
* @returns {Hooks['where'] | undefined}
|
|
5417
5417
|
*/
|
|
5418
5418
|
function mergeWhere(hooks) {
|
|
5419
|
-
if (
|
|
5420
|
-
return;
|
|
5419
|
+
if (hooks.length <= 1) {
|
|
5420
|
+
return hooks[0];
|
|
5421
5421
|
}
|
|
5422
5422
|
return async function (conn, model) {
|
|
5423
5423
|
let that;
|
|
@@ -5437,8 +5437,8 @@ function mergeWhere(hooks) {
|
|
|
5437
5437
|
* @returns {Hooks['beforeCreateMany'] | undefined}
|
|
5438
5438
|
*/
|
|
5439
5439
|
function mergeBeforeCreateMany(hooks) {
|
|
5440
|
-
if (
|
|
5441
|
-
return;
|
|
5440
|
+
if (hooks.length <= 1) {
|
|
5441
|
+
return hooks[0];
|
|
5442
5442
|
}
|
|
5443
5443
|
return async function (conn, model, record) {
|
|
5444
5444
|
let data = record;
|
|
@@ -5454,8 +5454,8 @@ function mergeBeforeCreateMany(hooks) {
|
|
|
5454
5454
|
* @returns {Hooks['beforeCreate'] | undefined}
|
|
5455
5455
|
*/
|
|
5456
5456
|
function mergeBeforeCreate(hooks) {
|
|
5457
|
-
if (
|
|
5458
|
-
return;
|
|
5457
|
+
if (hooks.length <= 1) {
|
|
5458
|
+
return hooks[0];
|
|
5459
5459
|
}
|
|
5460
5460
|
return async function (conn, model, record) {
|
|
5461
5461
|
let data = record;
|
|
@@ -5471,8 +5471,8 @@ function mergeBeforeCreate(hooks) {
|
|
|
5471
5471
|
* @returns {Hooks['beforeUpdate'] | undefined}
|
|
5472
5472
|
*/
|
|
5473
5473
|
function mergeBeforeUpdate(hooks) {
|
|
5474
|
-
if (
|
|
5475
|
-
return;
|
|
5474
|
+
if (hooks.length <= 1) {
|
|
5475
|
+
return hooks[0];
|
|
5476
5476
|
}
|
|
5477
5477
|
return async function (conn, model, record, set) {
|
|
5478
5478
|
let data = set;
|
|
@@ -5488,8 +5488,8 @@ function mergeBeforeUpdate(hooks) {
|
|
|
5488
5488
|
* @returns {((this: any, ...argv: T) => MaybePromise<void>) | undefined}
|
|
5489
5489
|
*/
|
|
5490
5490
|
function mergeRun(hooks) {
|
|
5491
|
-
if (
|
|
5492
|
-
return;
|
|
5491
|
+
if (hooks.length <= 1) {
|
|
5492
|
+
return hooks[0];
|
|
5493
5493
|
}
|
|
5494
5494
|
return async function (...p) {
|
|
5495
5495
|
for (const hook of hooks) {
|
|
@@ -5513,14 +5513,14 @@ function filterFunction(v) {
|
|
|
5513
5513
|
function mergeHooks(...hooks) {
|
|
5514
5514
|
const allHooks = hooks.flat();
|
|
5515
5515
|
return {
|
|
5516
|
-
where: mergeWhere(allHooks.map(v => v.where).filter(filterFunction)),
|
|
5517
|
-
beforeCreateMany: mergeBeforeCreateMany(allHooks.map(v => v.beforeCreateMany).filter(filterFunction)),
|
|
5516
|
+
where: mergeWhere(allHooks.map(v => v.where).filter(filterFunction).reverse()),
|
|
5517
|
+
beforeCreateMany: mergeBeforeCreateMany(allHooks.map(v => v.beforeCreateMany).filter(filterFunction).reverse()),
|
|
5518
5518
|
afterCreateMany: mergeRun(allHooks.map(v => v.afterCreateMany).filter(filterFunction)),
|
|
5519
|
-
beforeCreate: mergeBeforeCreate(allHooks.map(v => v.beforeCreate).filter(filterFunction)),
|
|
5519
|
+
beforeCreate: mergeBeforeCreate(allHooks.map(v => v.beforeCreate).filter(filterFunction).reverse()),
|
|
5520
5520
|
afterCreate: mergeRun(allHooks.map(v => v.afterCreate).filter(filterFunction)),
|
|
5521
|
-
beforeUpdate: mergeBeforeUpdate(allHooks.map(v => v.beforeUpdate).filter(filterFunction)),
|
|
5521
|
+
beforeUpdate: mergeBeforeUpdate(allHooks.map(v => v.beforeUpdate).filter(filterFunction).reverse()),
|
|
5522
5522
|
afterUpdate: mergeRun(allHooks.map(v => v.afterUpdate).filter(filterFunction)),
|
|
5523
|
-
beforeDelete: mergeRun(allHooks.map(v => v.beforeDelete).filter(filterFunction)),
|
|
5523
|
+
beforeDelete: mergeRun(allHooks.map(v => v.beforeDelete).filter(filterFunction).reverse()),
|
|
5524
5524
|
afterDelete: mergeRun(allHooks.map(v => v.afterDelete).filter(filterFunction))
|
|
5525
5525
|
};
|
|
5526
5526
|
}
|
package/migrate.d.mts
CHANGED
package/migrate.mjs
CHANGED