fix(type): use sequelize native Transactionable instead of TransactionAble (#410)
This commit is contained in:
parent
dc05399beb
commit
16f861ad7d
@ -1,5 +1,5 @@
|
||||
import { omit } from 'lodash';
|
||||
import { MultiAssociationAccessors, Op, Sequelize, Transaction } from 'sequelize';
|
||||
import { MultiAssociationAccessors, Op, Sequelize, Transaction, Transactionable } from 'sequelize';
|
||||
import {
|
||||
CommonFindOptions,
|
||||
CountOptions,
|
||||
@ -9,7 +9,6 @@ import {
|
||||
FindOptions,
|
||||
TargetKey,
|
||||
TK,
|
||||
TransactionAble,
|
||||
UpdateOptions
|
||||
} from '../repository';
|
||||
import { updateModelByValues } from '../update-associations';
|
||||
@ -20,7 +19,7 @@ export interface FindAndCountOptions extends CommonFindOptions {}
|
||||
|
||||
export interface FindOneOptions extends CommonFindOptions, FilterByTk {}
|
||||
|
||||
export interface AssociatedOptions extends TransactionAble {
|
||||
export interface AssociatedOptions extends Transactionable {
|
||||
tk?: TK;
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
import lodash from 'lodash';
|
||||
import { SingleAssociationAccessors } from 'sequelize';
|
||||
import { SingleAssociationAccessors, Transactionable } from 'sequelize';
|
||||
import { Model } from '../model';
|
||||
import { Appends, Except, Fields, Filter, TargetKey, TransactionAble, UpdateOptions } from '../repository';
|
||||
import { Appends, Except, Fields, Filter, TargetKey, UpdateOptions } from '../repository';
|
||||
import { updateModelByValues } from '../update-associations';
|
||||
import { RelationRepository, transaction } from './relation-repository';
|
||||
|
||||
export interface SingleRelationFindOption extends TransactionAble {
|
||||
export interface SingleRelationFindOption extends Transactionable {
|
||||
fields?: Fields;
|
||||
except?: Except;
|
||||
appends?: Appends;
|
||||
filter?: Filter;
|
||||
}
|
||||
|
||||
interface SetOption extends TransactionAble {
|
||||
interface SetOption extends Transactionable {
|
||||
tk?: TargetKey;
|
||||
}
|
||||
|
||||
export abstract class SingleRelationRepository extends RelationRepository {
|
||||
@transaction()
|
||||
async remove(options?: TransactionAble): Promise<void> {
|
||||
async remove(options?: Transactionable): Promise<void> {
|
||||
const transaction = await this.getTransaction(options);
|
||||
const sourceModel = await this.getSourceModel(transaction);
|
||||
return await sourceModel[this.accessors().set](null, {
|
||||
@ -63,7 +63,7 @@ export abstract class SingleRelationRepository extends RelationRepository {
|
||||
}
|
||||
|
||||
@transaction()
|
||||
async destroy(options?: TransactionAble): Promise<Boolean> {
|
||||
async destroy(options?: Transactionable): Promise<Boolean> {
|
||||
const transaction = await this.getTransaction(options);
|
||||
|
||||
const target = await this.find({
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
FindOptions as SequelizeFindOptions,
|
||||
ModelCtor,
|
||||
Op,
|
||||
Transaction,
|
||||
Transactionable,
|
||||
UpdateOptions as SequelizeUpdateOptions
|
||||
} from 'sequelize';
|
||||
import { Collection } from './collection';
|
||||
@ -34,9 +34,7 @@ interface CreateManyOptions extends BulkCreateOptions {
|
||||
records: Values[];
|
||||
}
|
||||
|
||||
export interface TransactionAble {
|
||||
transaction?: Transaction;
|
||||
}
|
||||
export { Transactionable } from 'sequelize';
|
||||
|
||||
export interface FilterAble {
|
||||
filter: Filter;
|
||||
@ -57,7 +55,7 @@ export type AssociationKeysToBeUpdate = string[];
|
||||
|
||||
export type Values = any;
|
||||
|
||||
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>, TransactionAble {
|
||||
export interface CountOptions extends Omit<SequelizeCreateOptions, 'distinct' | 'where' | 'include'>, Transactionable {
|
||||
fields?: Fields;
|
||||
filter?: Filter;
|
||||
}
|
||||
@ -68,7 +66,7 @@ export interface FilterByTk {
|
||||
|
||||
export interface FindOptions extends SequelizeFindOptions, CommonFindOptions, FilterByTk {}
|
||||
|
||||
export interface CommonFindOptions extends TransactionAble {
|
||||
export interface CommonFindOptions extends Transactionable {
|
||||
filter?: Filter;
|
||||
fields?: Fields;
|
||||
appends?: Appends;
|
||||
|
@ -9,7 +9,6 @@ import {
|
||||
Transactionable,
|
||||
} from 'sequelize';
|
||||
import { Model } from './model';
|
||||
import { TransactionAble } from './repository';
|
||||
import { UpdateGuard } from './update-guard';
|
||||
|
||||
function isUndefinedOrNull(value: any) {
|
||||
@ -46,7 +45,7 @@ export function modelAssociationByKey(instance: Model, key: string): Association
|
||||
|
||||
type UpdateValue = { [key: string]: any };
|
||||
|
||||
interface UpdateOptions extends TransactionAble {
|
||||
interface UpdateOptions extends Transactionable {
|
||||
filter?: any;
|
||||
filterByTk?: number | string;
|
||||
// 字段白名单
|
||||
|
@ -1,9 +1,9 @@
|
||||
import Database, { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';
|
||||
import Database, { IDatabaseOptions, Model, Transactionable } from '@nocobase/database';
|
||||
import { Application } from '@nocobase/server';
|
||||
import lodash from 'lodash';
|
||||
import * as path from 'path';
|
||||
|
||||
export interface registerAppOptions extends TransactionAble {
|
||||
export interface registerAppOptions extends Transactionable {
|
||||
skipInstall?: boolean;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Repository, TransactionAble } from '@nocobase/database';
|
||||
import { Repository, Transactionable } from '@nocobase/database';
|
||||
import { uid } from '@nocobase/utils';
|
||||
import lodash from 'lodash';
|
||||
import { Transaction } from 'sequelize';
|
||||
@ -13,7 +13,7 @@ type BreakRemoveOnType = {
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export interface removeParentOptions extends TransactionAble {
|
||||
export interface removeParentOptions extends Transactionable {
|
||||
removeParentsIfNoChildren?: boolean;
|
||||
breakRemoveOn?: BreakRemoveOnType;
|
||||
}
|
||||
@ -144,7 +144,7 @@ export class UiSchemaRepository extends Repository {
|
||||
return carry;
|
||||
}
|
||||
|
||||
async getProperties(uid: string, options: TransactionAble = {}) {
|
||||
async getProperties(uid: string, options: Transactionable = {}) {
|
||||
const { transaction } = options;
|
||||
|
||||
const db = this.database;
|
||||
@ -256,7 +256,7 @@ export class UiSchemaRepository extends Repository {
|
||||
}
|
||||
|
||||
@transaction()
|
||||
async clearAncestor(uid: string, options?: TransactionAble) {
|
||||
async clearAncestor(uid: string, options?: Transactionable) {
|
||||
const db = this.database;
|
||||
const treeTable = this.uiSchemaTreePathTableName;
|
||||
|
||||
@ -397,7 +397,7 @@ export class UiSchemaRepository extends Repository {
|
||||
return null;
|
||||
}
|
||||
|
||||
async removeEmptyParents(options: TransactionAble & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {
|
||||
async removeEmptyParents(options: Transactionable & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {
|
||||
const { transaction, uid, breakRemoveOn } = options;
|
||||
|
||||
const removeParent = async (nodeUid: string) => {
|
||||
@ -429,7 +429,7 @@ export class UiSchemaRepository extends Repository {
|
||||
return true;
|
||||
}
|
||||
|
||||
async recursivelyRemoveIfNoChildren(options: TransactionAble & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {
|
||||
async recursivelyRemoveIfNoChildren(options: Transactionable & { uid: string; breakRemoveOn?: BreakRemoveOnType }) {
|
||||
const { uid, transaction, breakRemoveOn } = options;
|
||||
|
||||
const removeLeafNode = async (nodeUid: string) => {
|
||||
@ -456,7 +456,7 @@ export class UiSchemaRepository extends Repository {
|
||||
}
|
||||
|
||||
@transaction()
|
||||
async remove(uid: string, options?: TransactionAble & removeParentOptions) {
|
||||
async remove(uid: string, options?: Transactionable & removeParentOptions) {
|
||||
let { transaction } = options;
|
||||
|
||||
if (options?.removeParentsIfNoChildren) {
|
||||
@ -548,7 +548,7 @@ export class UiSchemaRepository extends Repository {
|
||||
});
|
||||
}
|
||||
|
||||
private async schemaExists(schema: any, options?: TransactionAble): Promise<boolean> {
|
||||
private async schemaExists(schema: any, options?: Transactionable): Promise<boolean> {
|
||||
if (lodash.isObject(schema) && !schema['x-uid']) {
|
||||
return false;
|
||||
}
|
||||
@ -631,7 +631,7 @@ export class UiSchemaRepository extends Repository {
|
||||
}
|
||||
|
||||
@transaction()
|
||||
async insertNodes(nodes: SchemaNode[], options?: TransactionAble) {
|
||||
async insertNodes(nodes: SchemaNode[], options?: Transactionable) {
|
||||
const { transaction } = options;
|
||||
|
||||
const insertedNodes = [];
|
||||
@ -649,7 +649,7 @@ export class UiSchemaRepository extends Repository {
|
||||
}
|
||||
|
||||
@transaction()
|
||||
async insert(schema: any, options?: TransactionAble) {
|
||||
async insert(schema: any, options?: Transactionable) {
|
||||
const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
|
||||
const insertedNodes = await this.insertNodes(nodes, options);
|
||||
return this.getJsonSchema(insertedNodes[0].get('x-uid'), {
|
||||
@ -660,7 +660,7 @@ export class UiSchemaRepository extends Repository {
|
||||
@transaction()
|
||||
async insertNewSchema(
|
||||
schema: any,
|
||||
options?: TransactionAble & {
|
||||
options?: Transactionable & {
|
||||
returnNode?: boolean;
|
||||
},
|
||||
) {
|
||||
@ -760,7 +760,7 @@ export class UiSchemaRepository extends Repository {
|
||||
return { uid, name, async, childOptions };
|
||||
}
|
||||
|
||||
async insertSingleNode(schema: SchemaNode, options: TransactionAble & removeParentOptions) {
|
||||
async insertSingleNode(schema: SchemaNode, options: Transactionable & removeParentOptions) {
|
||||
const { transaction } = options;
|
||||
|
||||
const db = this.database;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database, { Model, TransactionAble } from '@nocobase/database';
|
||||
import Database, { Model, Transactionable } from '@nocobase/database';
|
||||
|
||||
export class UserModel extends Model {
|
||||
async setDefaultRole(roleName: string, options: TransactionAble = {}) {
|
||||
async setDefaultRole(roleName: string, options: Transactionable = {}) {
|
||||
if (roleName == 'anonymous') {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user