Browse Source

Merge pull request #20035 from abpframework/masum/ng-schematics

Add volo packages map and check during resolve import
pull/20084/head
oykuermann 2 years ago
committed by GitHub
parent
commit
9d1f2c9e2f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      npm/ng-packs/packages/schematics/src/commands/api/index.ts
  2. 30
      npm/ng-packs/packages/schematics/src/constants/volo.ts
  3. 47
      npm/ng-packs/packages/schematics/src/utils/model.ts

3
npm/ng-packs/packages/schematics/src/commands/api/index.ts

@ -29,6 +29,7 @@ import {
sanitizeTypeNames, sanitizeTypeNames,
sanitizeControllerTypeNames, sanitizeControllerTypeNames,
serializeParameters, serializeParameters,
resolveAbpPackages,
resolveSelfGenericProps, resolveSelfGenericProps,
} from '../../utils'; } from '../../utils';
import * as cases from '../../utils/text'; import * as cases from '../../utils/text';
@ -160,6 +161,8 @@ function createModelGenerator(params: ModelGeneratorParams) {
), ),
); );
resolveAbpPackages(models);
return chain( return chain(
models.map(model => models.map(model =>
applyWithOverwrite(url('./files-model'), [ applyWithOverwrite(url('./files-model'), [

30
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.IRemoteStreamContent',
'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>([
['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',
],
]);

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

@ -1,5 +1,4 @@
import { VOLO_REGEX } from '../constants'; import { Import, Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models';
import { Interface, Model, Property, PropertyDef, Type, TypeWithEnum } from '../models';
import { import {
extractGenerics, extractGenerics,
generateRefWithPlaceholders, generateRefWithPlaceholders,
@ -17,6 +16,8 @@ import {
extendsSelf, extendsSelf,
removeTypeModifiers, removeTypeModifiers,
} from './type'; } from './type';
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');
@ -40,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);
@ -202,6 +203,46 @@ export function parseBaseTypeWithGenericTypes(type: string): string[] {
return nodeToText(parsedTypeNode); 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<ModelGeneratorParams>) { export function resolveSelfGenericProps(params: Partial<ModelGeneratorParams>) {
const { types, solution } = params; const { types, solution } = params;
if (!types || !solution) { if (!types || !solution) {

Loading…
Cancel
Save