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