diff --git a/npm/ng-packs/packages/schematics/src/commands/api/index.ts b/npm/ng-packs/packages/schematics/src/commands/api/index.ts index 249f80cd65..15dfb8ab2d 100644 --- a/npm/ng-packs/packages/schematics/src/commands/api/index.ts +++ b/npm/ng-packs/packages/schematics/src/commands/api/index.ts @@ -29,6 +29,7 @@ import { sanitizeTypeNames, sanitizeControllerTypeNames, serializeParameters, + resolveAbpPackages, resolveSelfGenericProps, } from '../../utils'; import * as cases from '../../utils/text'; @@ -160,6 +161,8 @@ function createModelGenerator(params: ModelGeneratorParams) { ), ); + resolveAbpPackages(models); + return chain( models.map(model => applyWithOverwrite(url('./files-model'), [ diff --git a/npm/ng-packs/packages/schematics/src/constants/volo.ts b/npm/ng-packs/packages/schematics/src/constants/volo.ts index f42f4ed196..7a65902732 100644 --- a/npm/ng-packs/packages/schematics/src/constants/volo.ts +++ b/npm/ng-packs/packages/schematics/src/constants/volo.ts @@ -3,3 +3,33 @@ export const VOLO_REMOTE_STREAM_CONTENT = [ 'Volo.Abp.Content.IRemoteStreamContent', 'Volo.Abp.Content.RemoteStreamContent', ]; + +export const SAAS_NAMESPACE = 'Volo.Saas'; +export const TENANT_KEY = 'tenant'; + +export const VOLO_PACKAGE_PROXY_IMPORTS = new Map([ + ['Volo.Abp.Identity.IdentityUserDto', '@volo/abp.ng.identity/proxy'], + ['Volo.Abp.Identity.IdentityRoleDto', '@volo/abp.ng.identity/proxy'], + ['Volo.Abp.FileManagement.FileDescriptorDto', '@volo/abp.ng.file-management/proxy'], + ['Volo.Abp.FileManagement.DirectoryContentDto', '@volo/abp.ng.file-management/proxy'], + ['Volo.Abp.AuditLogging.AuditLogDto', '@volo/abp.ng.audit-logging/proxy'], + ['Volo.Abp.AuditLogging.AuditLogActionDto', '@volo/abp.ng.audit-logging/proxy'], + ['Volo.Abp.AuditLogging.EntityChangeDto', '@volo/abp.ng.audit-logging/proxy'], + ['Volo.Abp.AuditLogging.EntityPropertyChangeDto', '@volo/abp.ng.audit-logging/proxy'], + ['Volo.Chat.Messages', '@volo/abp.ng.chat/proxy'], + ['Volo.Chat.ChatMessageDto', '@volo/abp.ng.chat/proxy'], + ['Volo.Chat.ChatConversationDto', '@volo/abp.ng.chat/proxy'], + ['Volo.Abp.Gdpr.GdprRequestDto', '@volo/abp.ng.gdpr/proxy'], + ['Volo.Saas.Tenants.TenantDto', '@volo/abp.ng.saas/proxy'], + //TenantConnectionStringDto it must end with Strings. + ['Volo.Saas.Tenants.TenantConnectionStringDto', '@volo/abp.ng.saas/proxy'], + ['Volo.Saas.Editions.EditionDto', '@volo/abp.ng.saas/proxy'], + [ + 'Volo.Abp.TextTemplateManagement.TextTemplates.TextTemplateContentDto', + '@volo/abp.ng.saas/proxy', + ], + [ + 'Volo.Abp.TextTemplateManagement.TextTemplates.TemplateDefinitionDto', + '@volo/abp.ng.saas/proxy', + ], +]); diff --git a/npm/ng-packs/packages/schematics/src/utils/model.ts b/npm/ng-packs/packages/schematics/src/utils/model.ts index 720a76b1b3..35e29a39f1 100644 --- a/npm/ng-packs/packages/schematics/src/utils/model.ts +++ b/npm/ng-packs/packages/schematics/src/utils/model.ts @@ -1,5 +1,4 @@ -import { VOLO_REGEX } from '../constants'; -import { Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models'; +import { Import, Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models'; import { extractGenerics, generateRefWithPlaceholders, @@ -17,6 +16,8 @@ import { extendsSelf, removeTypeModifiers, } from './type'; +import { SAAS_NAMESPACE, TENANT_KEY, VOLO_PACKAGE_PROXY_IMPORTS, VOLO_REGEX } from '../constants'; + // eslint-disable-next-line @typescript-eslint/no-var-requires const shouldQuote = require('should-quote'); @@ -40,7 +41,7 @@ export function createImportRefsToModelReducer(params: ModelGeneratorParams) { sortInterfaces(interfaces); interfaces.forEach(_interface => { - if (VOLO_REGEX.test(_interface.ref)) return; + if (VOLO_REGEX.test(_interface.ref) || VOLO_PACKAGE_PROXY_IMPORTS.has(_interface.ref)) return; if (types[_interface.ref]!.isEnum) { if (!enums.includes(_interface.ref)) enums.push(_interface.ref); @@ -202,6 +203,46 @@ export function parseBaseTypeWithGenericTypes(type: string): string[] { return nodeToText(parsedTypeNode); } +export function resolveAbpPackages(models: Model[]) { + for (const model of models) { + renamePropForTenant(model.interfaces); + + model.imports.forEach((imp, i) => { + fixImportNameForTenant(imp); + + for (const ref of imp.refs) { + const path = VOLO_PACKAGE_PROXY_IMPORTS.get(ref); + if (path) { + model.imports[i] = new Import({ ...imp, path }); + } + } + }); + } +} + +function renamePropForTenant(interfaces: Interface[]) { + for (const inters of interfaces) { + for (const prop of inters.properties) { + const isTenant = prop.name.toLocaleLowerCase().includes(TENANT_KEY); + const isSaasDto = prop.refs.filter(f => f.startsWith(SAAS_NAMESPACE)).length > 0; + + if (isTenant && isSaasDto) { + prop.type = 'Saas' + prop.type; + } + } + } +} + +function fixImportNameForTenant(imp: Import) { + imp.specifiers.forEach((spe, index) => { + const isTenant = spe.toLocaleLowerCase().includes(TENANT_KEY); + + if (isTenant) { + imp.specifiers[index] = 'Saas' + spe; + } + }); +} + export function resolveSelfGenericProps(params: Partial) { const { types, solution } = params; if (!types || !solution) {