Browse Source

update model.ts

pull/20035/head
masumulu28 2 years ago
parent
commit
60d0ba2cec
  1. 7
      npm/ng-packs/packages/schematics/src/constants/volo.ts
  2. 17
      npm/ng-packs/packages/schematics/src/utils/model.ts

7
npm/ng-packs/packages/schematics/src/constants/volo.ts

@ -4,6 +4,9 @@ export const VOLO_REMOTE_STREAM_CONTENT = [
'Volo.Abp.Content.RemoteStreamContent', 'Volo.Abp.Content.RemoteStreamContent',
]; ];
export const SAAS_NAMESPACE = 'Volo.Saas';
export const TENANT_KEY = 'tenant';
export const VOLO_PACKAGE_PROXY_IMPORTS = new Map<string, string>([ export const VOLO_PACKAGE_PROXY_IMPORTS = new Map<string, string>([
['Volo.Abp.Identity.IdentityUserDto', '@volo/abp.ng.identity/proxy'], ['Volo.Abp.Identity.IdentityUserDto', '@volo/abp.ng.identity/proxy'],
['Volo.Abp.Identity.IdentityRoleDto', '@volo/abp.ng.identity/proxy'], ['Volo.Abp.Identity.IdentityRoleDto', '@volo/abp.ng.identity/proxy'],
@ -18,8 +21,8 @@ export const VOLO_PACKAGE_PROXY_IMPORTS = new Map<string, string>([
['Volo.Chat.ChatConversationDto', '@volo/abp.ng.chat/proxy'], ['Volo.Chat.ChatConversationDto', '@volo/abp.ng.chat/proxy'],
['Volo.Abp.Gdpr.GdprRequestDto', '@volo/abp.ng.gdpr/proxy'], ['Volo.Abp.Gdpr.GdprRequestDto', '@volo/abp.ng.gdpr/proxy'],
['Volo.Saas.Tenants.TenantDto', '@volo/abp.ng.saas/proxy'], ['Volo.Saas.Tenants.TenantDto', '@volo/abp.ng.saas/proxy'],
['Volo.Saas.TenantConnectionStringsDto', '@volo/abp.ng.saas/proxy'], ['Volo.Saas.Tenants.TenantConnectionStringDto', '@volo/abp.ng.saas/proxy'],
['Volo.Saas.EditionDto', '@volo/abp.ng.saas/proxy'], ['Volo.Saas.Tenants.EditionDto', '@volo/abp.ng.saas/proxy'],
[ [
'Volo.Abp.TextTemplateManagement.TextTemplates.TextTemplateContentDto', 'Volo.Abp.TextTemplateManagement.TextTemplates.TextTemplateContentDto',
'@volo/abp.ng.saas/proxy', '@volo/abp.ng.saas/proxy',

17
npm/ng-packs/packages/schematics/src/utils/model.ts

@ -16,7 +16,7 @@ import {
extendsSelf, extendsSelf,
removeTypeModifiers, removeTypeModifiers,
} from './type'; } from './type';
import { VOLO_PACKAGE_PROXY_IMPORTS, VOLO_REGEX } from '../constants'; import { SAAS_NAMESPACE, TENANT_KEY, VOLO_PACKAGE_PROXY_IMPORTS, VOLO_REGEX } from '../constants';
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const shouldQuote = require('should-quote'); const shouldQuote = require('should-quote');
@ -41,7 +41,7 @@ export function createImportRefsToModelReducer(params: ModelGeneratorParams) {
sortInterfaces(interfaces); sortInterfaces(interfaces);
interfaces.forEach(_interface => { 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 (types[_interface.ref]!.isEnum) {
if (!enums.includes(_interface.ref)) enums.push(_interface.ref); if (!enums.includes(_interface.ref)) enums.push(_interface.ref);
@ -203,15 +203,12 @@ export function parseBaseTypeWithGenericTypes(type: string): string[] {
return nodeToText(parsedTypeNode); return nodeToText(parsedTypeNode);
} }
const tenantKey = 'tenant';
const saasNamespace = 'Volo.Saas';
export function resolveAbpPackages(models: Model[]) { export function resolveAbpPackages(models: Model[]) {
for (const model of models) { for (const model of models) {
renamePropForTenant(model.interfaces); renamePropForTenant(model.interfaces);
model.imports.forEach((imp, i) => { model.imports.forEach((imp, i) => {
fixImportName(imp); fixImportNameForTenant(imp);
for (const ref of imp.refs) { for (const ref of imp.refs) {
const path = VOLO_PACKAGE_PROXY_IMPORTS.get(ref); const path = VOLO_PACKAGE_PROXY_IMPORTS.get(ref);
@ -226,8 +223,8 @@ export function resolveAbpPackages(models: Model[]) {
function renamePropForTenant(interfaces: Interface[]) { function renamePropForTenant(interfaces: Interface[]) {
for (const inters of interfaces) { for (const inters of interfaces) {
for (const prop of inters.properties) { for (const prop of inters.properties) {
const isTenant = prop.name.toLocaleLowerCase().includes(tenantKey); const isTenant = prop.name.toLocaleLowerCase().includes(TENANT_KEY);
const isSaasDto = prop.refs.filter(f => f.startsWith(saasNamespace)).length > 0; const isSaasDto = prop.refs.filter(f => f.startsWith(SAAS_NAMESPACE)).length > 0;
if (isTenant && isSaasDto) { if (isTenant && isSaasDto) {
prop.type = 'Saas' + prop.type; prop.type = 'Saas' + prop.type;
@ -236,9 +233,9 @@ function renamePropForTenant(interfaces: Interface[]) {
} }
} }
function fixImportName(imp: Import) { function fixImportNameForTenant(imp: Import) {
imp.specifiers.forEach((spe, index) => { imp.specifiers.forEach((spe, index) => {
const isTenant = spe.toLocaleLowerCase().includes(tenantKey); const isTenant = spe.toLocaleLowerCase().includes(TENANT_KEY);
if (isTenant) { if (isTenant) {
imp.specifiers[index] = 'Saas' + spe; imp.specifiers[index] = 'Saas' + spe;

Loading…
Cancel
Save