From e5e503fe874ec68858235f83c7ec4a7f928b46c4 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 13 Feb 2023 09:57:03 +0800 Subject: [PATCH] feat: add namespace and duplicator parameters for collection options (#1449) * feat: add namespace and duplicator parameters for collection options * fix: duplicator:getDict --- packages/core/database/src/collection.ts | 3 +- packages/core/database/src/database.ts | 7 +- packages/core/server/src/application.ts | 2 + .../src/plugin-manager/options/collection.ts | 2 + .../acl/src/collections/roles-users.ts | 2 + packages/plugins/acl/src/collections/roles.ts | 2 + .../acl/src/collections/rolesResources.ts | 2 + .../src/collections/rolesResourcesActions.ts | 2 + .../src/collections/rolesResourcesScopes.ts | 2 + packages/plugins/acl/src/server.ts | 5 ++ .../src/server/collections/auditChanges.ts | 2 + .../src/server/collections/auditLogs.ts | 2 + .../src/server/collections/chinaRegions.ts | 2 + .../src/collections/collectionCategories.ts | 2 + .../src/collections/collections.ts | 2 + .../src/collections/fields.ts | 2 + .../plugins/collection-manager/src/server.ts | 6 ++ .../src/server/collection-group-manager.ts | 5 +- .../plugins/duplicator/src/server/server.ts | 44 ++++++++++ .../src/server/collections/attachments.ts | 2 + .../src/server/collections/storages.ts | 2 + .../src/server/collections/graphPositions.ts | 2 + .../src/server/collections/iframe-html.ts | 2 + .../server/collections/mapConfiguration.ts | 2 + .../src/collections/applications.ts | 2 + .../src/server/collections/oidcProviders.ts | 2 + .../src/server/collections/samlProviders.ts | 2 + .../src/server/collections/sequences.ts | 2 + .../server/collections/collectionsHistory.ts | 2 + .../src/server/collections/fieldsHistory.ts | 2 + .../src/collections/systemSettings.ts | 2 + .../src/collections/uiRoutes.ts | 2 + .../src/collections/uiSchemaServerHooks.ts | 2 + .../src/collections/uiSchemaTemplates.ts | 2 + .../src/collections/uiSchemaTreePath.ts | 2 + .../src/collections/uiSchemas.ts | 2 + .../plugins/users/src/collections/users.ts | 2 + .../src/server/collections/verifications.ts | 2 + .../collections/verifications_providers.ts | 2 + .../plugins/workflow/src/server/Plugin.ts | 82 +++++++++++-------- .../src/server/collections/executions.ts | 2 + .../src/server/collections/flow_nodes.ts | 2 + .../workflow/src/server/collections/jobs.ts | 2 + .../src/server/collections/workflows.ts | 2 + .../assignees/collections/users_jobs.ts | 2 + 45 files changed, 186 insertions(+), 42 deletions(-) diff --git a/packages/core/database/src/collection.ts b/packages/core/database/src/collection.ts index c9ca36bf2..86479b2c2 100644 --- a/packages/core/database/src/collection.ts +++ b/packages/core/database/src/collection.ts @@ -7,7 +7,7 @@ import { QueryInterfaceDropTableOptions, SyncOptions, Transactionable, - Utils, + Utils } from 'sequelize'; import { Database } from './database'; import { Field, FieldOptions } from './fields'; @@ -307,6 +307,7 @@ export class Collection< updateOptions(options: CollectionOptions, mergeOptions?: any) { let newOptions = lodash.cloneDeep(options); newOptions = merge(this.options, newOptions, mergeOptions); + this.options = newOptions; this.context.database.emit('beforeUpdateCollection', this, newOptions); diff --git a/packages/core/database/src/database.ts b/packages/core/database/src/database.ts index 8aa902c1d..be04dc2c7 100644 --- a/packages/core/database/src/database.ts +++ b/packages/core/database/src/database.ts @@ -15,7 +15,7 @@ import { Sequelize, SyncOptions, Transactionable, - Utils, + Utils } from 'sequelize'; import { SequelizeStorage, Umzug } from 'umzug'; import { Collection, CollectionOptions, RepositoryType } from './collection'; @@ -58,7 +58,7 @@ import { SyncListener, UpdateListener, UpdateWithAssociationsListener, - ValidateListener, + ValidateListener } from './types'; export interface MergeOptions extends merge.Options {} @@ -250,6 +250,8 @@ export class Database extends EventEmitter implements AsyncEmitter { name: 'migrations', autoGenId: false, timestamps: false, + namespace: 'core', + duplicator: 'required', fields: [{ type: 'string', name: 'name' }], }); @@ -612,6 +614,7 @@ export class Database extends EventEmitter implements AsyncEmitter { } extendCollection(collectionOptions: CollectionOptions, mergeOptions?: MergeOptions) { + collectionOptions = lodash.cloneDeep(collectionOptions); const collectionName = collectionOptions.name; const existCollection = this.getCollection(collectionName); if (existCollection) { diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index 33c1fa21b..80ac85902 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -101,6 +101,8 @@ export class ApplicationVersion { if (!app.db.hasCollection('applicationVersion')) { app.db.collection({ name: 'applicationVersion', + namespace: 'core', + duplicator: 'required', timestamps: false, fields: [{ name: 'value', type: 'string' }], }); diff --git a/packages/core/server/src/plugin-manager/options/collection.ts b/packages/core/server/src/plugin-manager/options/collection.ts index 3b9cffb93..0cc02c537 100644 --- a/packages/core/server/src/plugin-manager/options/collection.ts +++ b/packages/core/server/src/plugin-manager/options/collection.ts @@ -1,5 +1,7 @@ export default { name: 'applicationPlugins', + namespace: 'core', + duplicator: 'required', repository: 'PluginManagerRepository', fields: [ { type: 'string', name: 'name', unique: true }, diff --git a/packages/plugins/acl/src/collections/roles-users.ts b/packages/plugins/acl/src/collections/roles-users.ts index c59a4564c..abe0fe97d 100644 --- a/packages/plugins/acl/src/collections/roles-users.ts +++ b/packages/plugins/acl/src/collections/roles-users.ts @@ -2,5 +2,7 @@ import { CollectionOptions } from '@nocobase/database'; export default { name: 'rolesUsers', + duplicator: 'optional', + namespace: 'acl', fields: [{ type: 'boolean', name: 'default' }], } as CollectionOptions; diff --git a/packages/plugins/acl/src/collections/roles.ts b/packages/plugins/acl/src/collections/roles.ts index 8a58a3086..ef28e72c2 100644 --- a/packages/plugins/acl/src/collections/roles.ts +++ b/packages/plugins/acl/src/collections/roles.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'acl', + duplicator: 'required', name: 'roles', title: '{{t("Roles")}}', autoGenId: false, diff --git a/packages/plugins/acl/src/collections/rolesResources.ts b/packages/plugins/acl/src/collections/rolesResources.ts index 8a59485ef..a43b8c5ed 100644 --- a/packages/plugins/acl/src/collections/rolesResources.ts +++ b/packages/plugins/acl/src/collections/rolesResources.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'acl', + duplicator: 'required', name: 'rolesResources', model: 'RoleResourceModel', indexes: [ diff --git a/packages/plugins/acl/src/collections/rolesResourcesActions.ts b/packages/plugins/acl/src/collections/rolesResourcesActions.ts index 18dcd8631..a18c5e1c1 100644 --- a/packages/plugins/acl/src/collections/rolesResourcesActions.ts +++ b/packages/plugins/acl/src/collections/rolesResourcesActions.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'acl', + duplicator: 'required', name: 'rolesResourcesActions', model: 'RoleResourceActionModel', fields: [ diff --git a/packages/plugins/acl/src/collections/rolesResourcesScopes.ts b/packages/plugins/acl/src/collections/rolesResourcesScopes.ts index 3281d4e78..f3a759d60 100644 --- a/packages/plugins/acl/src/collections/rolesResourcesScopes.ts +++ b/packages/plugins/acl/src/collections/rolesResourcesScopes.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'acl', + duplicator: 'required', name: 'rolesResourcesScopes', fields: [ { diff --git a/packages/plugins/acl/src/server.ts b/packages/plugins/acl/src/server.ts index bce65fbc5..470588f42 100644 --- a/packages/plugins/acl/src/server.ts +++ b/packages/plugins/acl/src/server.ts @@ -772,6 +772,11 @@ export class PluginACL extends Plugin { async load() { await this.importCollections(resolve(__dirname, 'collections')); + this.db.extendCollection({ + name: 'rolesUischemas', + namespace: 'acl', + duplicator: 'required', + }); } } diff --git a/packages/plugins/audit-logs/src/server/collections/auditChanges.ts b/packages/plugins/audit-logs/src/server/collections/auditChanges.ts index cae4c356f..261207a75 100644 --- a/packages/plugins/audit-logs/src/server/collections/auditChanges.ts +++ b/packages/plugins/audit-logs/src/server/collections/auditChanges.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'audit-logs', + duplicator: 'optional', name: 'auditChanges', title: '变动值', createdBy: false, diff --git a/packages/plugins/audit-logs/src/server/collections/auditLogs.ts b/packages/plugins/audit-logs/src/server/collections/auditLogs.ts index df90dd076..932d4e6e7 100644 --- a/packages/plugins/audit-logs/src/server/collections/auditLogs.ts +++ b/packages/plugins/audit-logs/src/server/collections/auditLogs.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'audit-logs', + duplicator: 'optional', name: 'auditLogs', createdBy: false, updatedBy: false, diff --git a/packages/plugins/china-region/src/server/collections/chinaRegions.ts b/packages/plugins/china-region/src/server/collections/chinaRegions.ts index 14c40cbe7..fa431b142 100644 --- a/packages/plugins/china-region/src/server/collections/chinaRegions.ts +++ b/packages/plugins/china-region/src/server/collections/chinaRegions.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'china-region', + duplicator: 'skip', name: 'chinaRegions', title: '中国行政区划', autoGenId: false, diff --git a/packages/plugins/collection-manager/src/collections/collectionCategories.ts b/packages/plugins/collection-manager/src/collections/collectionCategories.ts index 7e6205e08..10ccfedee 100644 --- a/packages/plugins/collection-manager/src/collections/collectionCategories.ts +++ b/packages/plugins/collection-manager/src/collections/collectionCategories.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'collection-manager', + duplicator: 'required', name: 'collectionCategories', autoGenId: true, sortable: true, diff --git a/packages/plugins/collection-manager/src/collections/collections.ts b/packages/plugins/collection-manager/src/collections/collections.ts index 4e5485c5c..b3d52dc87 100644 --- a/packages/plugins/collection-manager/src/collections/collections.ts +++ b/packages/plugins/collection-manager/src/collections/collections.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'collection-manager', + duplicator: 'required', name: 'collections', title: '数据表配置', sortable: 'sort', diff --git a/packages/plugins/collection-manager/src/collections/fields.ts b/packages/plugins/collection-manager/src/collections/fields.ts index 66010a0bb..b6b219c70 100644 --- a/packages/plugins/collection-manager/src/collections/fields.ts +++ b/packages/plugins/collection-manager/src/collections/fields.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'collection-manager', + duplicator: 'required', name: 'fields', autoGenId: false, model: 'FieldModel', diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index fd0796918..4e7bc518b 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -245,6 +245,12 @@ export class CollectionManagerPlugin extends Plugin { } await next(); }); + + this.app.db.extendCollection({ + name: 'collectionCategory', + namespace: 'collection-manager', + duplicator: 'required', + }); } } diff --git a/packages/plugins/duplicator/src/server/collection-group-manager.ts b/packages/plugins/duplicator/src/server/collection-group-manager.ts index a693adb80..8c02ac591 100644 --- a/packages/plugins/duplicator/src/server/collection-group-manager.ts +++ b/packages/plugins/duplicator/src/server/collection-group-manager.ts @@ -1,4 +1,3 @@ -import { Application } from '@nocobase/server'; import lodash from 'lodash'; import { Restorer } from './restorer'; @@ -70,7 +69,7 @@ CollectionGroupManager.registerCollectionGroup({ CollectionGroupManager.registerCollectionGroup({ pluginName: 'collection-manager', function: 'collections', - collections: ['collections', 'fields'], + collections: ['collections', 'fields', 'collectionCategories', 'collectionCategory'], dumpable: 'required', }); @@ -252,5 +251,5 @@ CollectionGroupManager.registerCollectionGroup({ pluginName: 'iframe-block', function: 'iframe html storage', collections: ['iframeHtml'], - dumpable: 'optional', + dumpable: 'required', }); diff --git a/packages/plugins/duplicator/src/server/server.ts b/packages/plugins/duplicator/src/server/server.ts index 8bf96652a..bd5ebf9e2 100644 --- a/packages/plugins/duplicator/src/server/server.ts +++ b/packages/plugins/duplicator/src/server/server.ts @@ -11,4 +11,48 @@ export default class Duplicator extends Plugin { addDumpCommand(this.app); addRestoreCommand(this.app); } + + async load() { + this.app.resourcer.define({ + name: 'duplicator', + actions: { + getDict: async (ctx, next) => { + ctx.withoutDataWrapping = true; + let collectionNames = await this.db.getRepository('collections').find(); + collectionNames = collectionNames.map((item) => item.get('name')); + const collections: any[] = []; + for (const [name, collection] of this.db.collections) { + const columns: any[] = []; + for (const key in collection.model.rawAttributes) { + if (Object.prototype.hasOwnProperty.call(collection.model.rawAttributes, key)) { + const attribute = collection.model.rawAttributes[key]; + columns.push({ + realName: attribute.field, + name: key, + }); + } + } + const item = { + name, + title: collection.options.title, + namespace: collection.options.namespace, + duplicator: collection.options.duplicator, + // columns, + }; + if (!item.namespace && collectionNames.includes(name)) { + item.namespace = 'collection-manager'; + if (!item.duplicator) { + item.duplicator = 'optional'; + } + } + collections.push(item); + } + ctx.body = collections; + await next(); + }, + }, + }); + + this.app.acl.allow('duplicator', 'getDict'); + } } diff --git a/packages/plugins/file-manager/src/server/collections/attachments.ts b/packages/plugins/file-manager/src/server/collections/attachments.ts index b3d570068..aa2f461eb 100644 --- a/packages/plugins/file-manager/src/server/collections/attachments.ts +++ b/packages/plugins/file-manager/src/server/collections/attachments.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'file-manager', + duplicator: 'optional', name: 'attachments', title: '文件管理器', createdBy: true, diff --git a/packages/plugins/file-manager/src/server/collections/storages.ts b/packages/plugins/file-manager/src/server/collections/storages.ts index 979c8a242..029cb3dd8 100644 --- a/packages/plugins/file-manager/src/server/collections/storages.ts +++ b/packages/plugins/file-manager/src/server/collections/storages.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'file-manager', + duplicator: 'optional', name: 'storages', title: '存储引擎', fields: [ diff --git a/packages/plugins/graph-collection-manager/src/server/collections/graphPositions.ts b/packages/plugins/graph-collection-manager/src/server/collections/graphPositions.ts index 1b7ad4116..3ca8ba30c 100644 --- a/packages/plugins/graph-collection-manager/src/server/collections/graphPositions.ts +++ b/packages/plugins/graph-collection-manager/src/server/collections/graphPositions.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'graph-collection-manager', + duplicator: 'required', name: 'graphPositions', fields: [ { diff --git a/packages/plugins/iframe-block/src/server/collections/iframe-html.ts b/packages/plugins/iframe-block/src/server/collections/iframe-html.ts index 0fca8db1a..6d5772449 100644 --- a/packages/plugins/iframe-block/src/server/collections/iframe-html.ts +++ b/packages/plugins/iframe-block/src/server/collections/iframe-html.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'iframe-block', + duplicator: 'required', name: 'iframeHtml', createdBy: true, updatedBy: true, diff --git a/packages/plugins/map/src/server/collections/mapConfiguration.ts b/packages/plugins/map/src/server/collections/mapConfiguration.ts index 7089ec622..b0ff4a584 100644 --- a/packages/plugins/map/src/server/collections/mapConfiguration.ts +++ b/packages/plugins/map/src/server/collections/mapConfiguration.ts @@ -2,6 +2,8 @@ import { CollectionOptions } from "@nocobase/client"; import { MapConfigurationCollectionName } from "../constants"; export default { + namespace: 'map', + duplicator: 'optional', name: MapConfigurationCollectionName, title: '{{t("Map Manager")}}', fields: [ diff --git a/packages/plugins/multi-app-manager/src/collections/applications.ts b/packages/plugins/multi-app-manager/src/collections/applications.ts index e98ac6e17..338879828 100644 --- a/packages/plugins/multi-app-manager/src/collections/applications.ts +++ b/packages/plugins/multi-app-manager/src/collections/applications.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'multi-app-manager', + duplicator: 'optional', name: 'applications', model: 'ApplicationModel', autoGenId: false, diff --git a/packages/plugins/oidc/src/server/collections/oidcProviders.ts b/packages/plugins/oidc/src/server/collections/oidcProviders.ts index bf51755ca..b0091ec83 100644 --- a/packages/plugins/oidc/src/server/collections/oidcProviders.ts +++ b/packages/plugins/oidc/src/server/collections/oidcProviders.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'oidc', + duplicator: 'optional', name: 'oidcProviders', title: '{{t("OIDC Providers")}}', fields: [ diff --git a/packages/plugins/saml/src/server/collections/samlProviders.ts b/packages/plugins/saml/src/server/collections/samlProviders.ts index 9545689f2..29730c495 100644 --- a/packages/plugins/saml/src/server/collections/samlProviders.ts +++ b/packages/plugins/saml/src/server/collections/samlProviders.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'saml', + duplicator: 'optional', name: 'samlProviders', title: '{{t("SAML Providers")}}', fields: [ diff --git a/packages/plugins/sequence-field/src/server/collections/sequences.ts b/packages/plugins/sequence-field/src/server/collections/sequences.ts index 38bb15b55..e49f3978d 100644 --- a/packages/plugins/sequence-field/src/server/collections/sequences.ts +++ b/packages/plugins/sequence-field/src/server/collections/sequences.ts @@ -1,4 +1,6 @@ export default { + namespace: 'sequence-field', + duplicator: 'required', name: 'sequences', fields: [ { diff --git a/packages/plugins/snapshot-field/src/server/collections/collectionsHistory.ts b/packages/plugins/snapshot-field/src/server/collections/collectionsHistory.ts index 9d812e5b5..94f555627 100644 --- a/packages/plugins/snapshot-field/src/server/collections/collectionsHistory.ts +++ b/packages/plugins/snapshot-field/src/server/collections/collectionsHistory.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'snapshot-field', + duplicator: 'required', name: 'collectionsHistory', title: '数据表历史', sortable: 'sort', diff --git a/packages/plugins/snapshot-field/src/server/collections/fieldsHistory.ts b/packages/plugins/snapshot-field/src/server/collections/fieldsHistory.ts index bbfc78385..78c74ddf8 100644 --- a/packages/plugins/snapshot-field/src/server/collections/fieldsHistory.ts +++ b/packages/plugins/snapshot-field/src/server/collections/fieldsHistory.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'snapshot-field', + duplicator: 'required', name: 'fieldsHistory', title: '{{t("Fields history")}}', autoGenId: false, diff --git a/packages/plugins/system-settings/src/collections/systemSettings.ts b/packages/plugins/system-settings/src/collections/systemSettings.ts index 7c1a7f180..8ec65e116 100644 --- a/packages/plugins/system-settings/src/collections/systemSettings.ts +++ b/packages/plugins/system-settings/src/collections/systemSettings.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'system-settings', + duplicator: 'optional', name: 'systemSettings', fields: [ { diff --git a/packages/plugins/ui-routes-storage/src/collections/uiRoutes.ts b/packages/plugins/ui-routes-storage/src/collections/uiRoutes.ts index de2e2cb6d..380d565f1 100644 --- a/packages/plugins/ui-routes-storage/src/collections/uiRoutes.ts +++ b/packages/plugins/ui-routes-storage/src/collections/uiRoutes.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'ui-routes-storage', + duplicator: 'required', name: 'uiRoutes', title: '前端路由表', model: 'MagicAttributeModel', diff --git a/packages/plugins/ui-schema-storage/src/collections/uiSchemaServerHooks.ts b/packages/plugins/ui-schema-storage/src/collections/uiSchemaServerHooks.ts index 2d124c396..214fa2937 100644 --- a/packages/plugins/ui-schema-storage/src/collections/uiSchemaServerHooks.ts +++ b/packages/plugins/ui-schema-storage/src/collections/uiSchemaServerHooks.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'ui-schema-storage', + duplicator: 'required', name: 'uiSchemaServerHooks', model: 'ServerHookModel', // autoGenId: false, diff --git a/packages/plugins/ui-schema-storage/src/collections/uiSchemaTemplates.ts b/packages/plugins/ui-schema-storage/src/collections/uiSchemaTemplates.ts index 06adf7630..4d905b5cd 100644 --- a/packages/plugins/ui-schema-storage/src/collections/uiSchemaTemplates.ts +++ b/packages/plugins/ui-schema-storage/src/collections/uiSchemaTemplates.ts @@ -1,6 +1,8 @@ import { defineCollection } from '@nocobase/database'; export default defineCollection({ + namespace: 'ui-schema-storage', + duplicator: 'required', name: 'uiSchemaTemplates', autoGenId: false, fields: [ diff --git a/packages/plugins/ui-schema-storage/src/collections/uiSchemaTreePath.ts b/packages/plugins/ui-schema-storage/src/collections/uiSchemaTreePath.ts index c83b84fdd..e5055369c 100644 --- a/packages/plugins/ui-schema-storage/src/collections/uiSchemaTreePath.ts +++ b/packages/plugins/ui-schema-storage/src/collections/uiSchemaTreePath.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'ui-schema-storage', + duplicator: 'required', name: 'uiSchemaTreePath', autoGenId: false, timestamps: false, diff --git a/packages/plugins/ui-schema-storage/src/collections/uiSchemas.ts b/packages/plugins/ui-schema-storage/src/collections/uiSchemas.ts index 0da5e2303..d00ad9e09 100644 --- a/packages/plugins/ui-schema-storage/src/collections/uiSchemas.ts +++ b/packages/plugins/ui-schema-storage/src/collections/uiSchemas.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'ui-schema-storage', + duplicator: 'required', name: 'uiSchemas', title: '字段配置', autoGenId: false, diff --git a/packages/plugins/users/src/collections/users.ts b/packages/plugins/users/src/collections/users.ts index 17efb0557..8463e703e 100644 --- a/packages/plugins/users/src/collections/users.ts +++ b/packages/plugins/users/src/collections/users.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'users', + duplicator: 'optional', name: 'users', title: '{{t("Users")}}', sortable: 'sort', diff --git a/packages/plugins/verification/src/server/collections/verifications.ts b/packages/plugins/verification/src/server/collections/verifications.ts index ef23c8afe..3a37ba128 100644 --- a/packages/plugins/verification/src/server/collections/verifications.ts +++ b/packages/plugins/verification/src/server/collections/verifications.ts @@ -1,4 +1,6 @@ export default { + namespace: 'verification', + duplicator: 'optional', name: 'verifications', fields: [ { diff --git a/packages/plugins/verification/src/server/collections/verifications_providers.ts b/packages/plugins/verification/src/server/collections/verifications_providers.ts index fa4c4b075..699273c4d 100644 --- a/packages/plugins/verification/src/server/collections/verifications_providers.ts +++ b/packages/plugins/verification/src/server/collections/verifications_providers.ts @@ -1,4 +1,6 @@ export default { + namespace: 'verification', + duplicator: 'optional', name: 'verifications_providers', fields: [ { diff --git a/packages/plugins/workflow/src/server/Plugin.ts b/packages/plugins/workflow/src/server/Plugin.ts index 0364126cc..4f982d1c2 100644 --- a/packages/plugins/workflow/src/server/Plugin.ts +++ b/packages/plugins/workflow/src/server/Plugin.ts @@ -15,7 +15,6 @@ import WorkflowModel from './models/Workflow'; import Processor from './Processor'; import initTriggers, { Trigger } from './triggers'; - type Pending = [ExecutionModel, JobModel?]; export default class WorkflowPlugin extends Plugin { instructions: Registry = new Registry(); @@ -34,9 +33,9 @@ export default class WorkflowPlugin extends Plugin { } else if (!instance.current) { const count = await Model.count({ where: { - key: instance.key + key: instance.key, }, - transaction: options.transaction + transaction: options.transaction, }); if (!count) { instance.set('current', true); @@ -52,18 +51,21 @@ export default class WorkflowPlugin extends Plugin { key: instance.key, current: true, id: { - [Op.ne]: instance.id - } + [Op.ne]: instance.id, + }, }, - transaction: options.transaction + transaction: options.transaction, }); if (previous) { // NOTE: set to `null` but not `false` will not violate the unique index - await previous.update({ enabled: false, current: null }, { - transaction: options.transaction, - hooks: false - }); + await previous.update( + { enabled: false, current: null }, + { + transaction: options.transaction, + hooks: false, + }, + ); this.toggle(previous, false); } @@ -185,24 +187,29 @@ export default class WorkflowPlugin extends Plugin { // NOTE: no transaction here for read-uncommitted execution const existed = await workflow.countExecutions({ where: { - id: options.context.executionId - } + id: options.context.executionId, + }, }); if (existed) { - this.app.logger.warn(`[Workflow] workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`); + this.app.logger.warn( + `[Workflow] workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`, + ); valid = false; } } if (valid) { - const execution = await this.db.sequelize.transaction(async transaction => { - const execution = await workflow.createExecution({ - context, - key: workflow.key, - status: EXECUTION_STATUS.CREATED, - useTransaction: workflow.useTransaction, - }, { transaction }); + const execution = await this.db.sequelize.transaction(async (transaction) => { + const execution = await workflow.createExecution( + { + context, + key: workflow.key, + status: EXECUTION_STATUS.CREATED, + useTransaction: workflow.useTransaction, + }, + { transaction }, + ); const executed = await workflow.countExecutions({ transaction }); @@ -211,19 +218,22 @@ export default class WorkflowPlugin extends Plugin { const allExecuted = await (execution.constructor).count({ where: { - key: workflow.key + key: workflow.key, }, - transaction + transaction, }); - await (workflow.constructor).update({ - allExecuted - }, { - where: { - key: workflow.key + await (workflow.constructor).update( + { + allExecuted, }, - individualHooks: true, - transaction - }); + { + where: { + key: workflow.key, + }, + individualHooks: true, + transaction, + }, + ); execution.workflow = workflow; @@ -243,7 +253,7 @@ export default class WorkflowPlugin extends Plugin { } else { this.dispatch(); } - } + }; public async resume(job) { if (!job.execution) { @@ -264,16 +274,16 @@ export default class WorkflowPlugin extends Plugin { if (this.pending.length) { next = this.pending.shift() as Pending; } else { - const execution = await this.db.getRepository('executions').findOne({ + const execution = (await this.db.getRepository('executions').findOne({ filter: { - status: EXECUTION_STATUS.CREATED + status: EXECUTION_STATUS.CREATED, }, - sort: 'createdAt' - }) as ExecutionModel; + sort: 'createdAt', + })) as ExecutionModel; if (execution) { next = [execution]; } - }; + } if (next) { this.process(...next); } diff --git a/packages/plugins/workflow/src/server/collections/executions.ts b/packages/plugins/workflow/src/server/collections/executions.ts index 1f6a7eca5..8bc0d45f1 100644 --- a/packages/plugins/workflow/src/server/collections/executions.ts +++ b/packages/plugins/workflow/src/server/collections/executions.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'workflow', + duplicator: 'optional', name: 'executions', fields: [ { diff --git a/packages/plugins/workflow/src/server/collections/flow_nodes.ts b/packages/plugins/workflow/src/server/collections/flow_nodes.ts index 75c7151a6..fce168cf0 100644 --- a/packages/plugins/workflow/src/server/collections/flow_nodes.ts +++ b/packages/plugins/workflow/src/server/collections/flow_nodes.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'workflow', + duplicator: 'required', name: 'flow_nodes', // model: 'FlowNodeModel', title: 'Workflow Nodes', diff --git a/packages/plugins/workflow/src/server/collections/jobs.ts b/packages/plugins/workflow/src/server/collections/jobs.ts index 70966e977..024545da5 100644 --- a/packages/plugins/workflow/src/server/collections/jobs.ts +++ b/packages/plugins/workflow/src/server/collections/jobs.ts @@ -1,6 +1,8 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'workflow', + duplicator: 'optional', name: 'jobs', fields: [ { diff --git a/packages/plugins/workflow/src/server/collections/workflows.ts b/packages/plugins/workflow/src/server/collections/workflows.ts index 033fa2f0c..64531413e 100644 --- a/packages/plugins/workflow/src/server/collections/workflows.ts +++ b/packages/plugins/workflow/src/server/collections/workflows.ts @@ -2,6 +2,8 @@ import { CollectionOptions } from '@nocobase/database'; export default function () { return { + namespace: 'workflow', + duplicator: 'required', name: 'workflows', fields: [ { diff --git a/packages/plugins/workflow/src/server/extensions/assignees/collections/users_jobs.ts b/packages/plugins/workflow/src/server/extensions/assignees/collections/users_jobs.ts index 5839dda6b..7d0549fab 100644 --- a/packages/plugins/workflow/src/server/extensions/assignees/collections/users_jobs.ts +++ b/packages/plugins/workflow/src/server/extensions/assignees/collections/users_jobs.ts @@ -1,7 +1,9 @@ import { CollectionOptions } from '@nocobase/database'; export default { + namespace: 'workflow', name: 'users_jobs', + duplicator: 'optional', fields: [ { type: 'bigInt',