Skip to content

Commit

Permalink
JNG-4838 re-format templates to support no formatter operation
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Nov 24, 2023
1 parent 020423c commit c4de3a0
Show file tree
Hide file tree
Showing 21 changed files with 978 additions and 1,058 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

import type { JudoStored } from '@judo/data-api-common';
{{# each (getImportTokens application.actor classType) as | token | }}
import { {{ @key }} } from './{{ token }}';
import { {{ @key }} } from './{{ token }}';
{{/ each }}

export interface {{ classDataName classType '' }} {
{{# each classType.attributes as | attribute | }}
{{ attribute.name }}{{# if attribute.isRequired }}: {{ else }}?: null | {{/ if}}{{ typescriptType attribute.dataType }};
{{ attribute.name }}{{# if attribute.isRequired }}: {{ else }}?: null | {{/ if}}{{ typescriptType attribute.dataType }};
{{/ each }}

{{# each classType.relations as | relation | }}
{{ relation.name }}{{# if relation.isOptional }}?: null | {{ else }}:{{/ if}}{{{ getRelationType relation }}};
{{ relation.name }}{{# if relation.isOptional }}?: null | {{ else }}:{{/ if}}{{{ getRelationType relation }}};
{{/ each }}

}

{{# unless classType.attributes.isEmpty }}
export type {{ classDataName classType '' }}Attributes = '{{{ getClassTypeAttributes classType }}}';
export type {{ classDataName classType '' }}Attributes = '{{{ getClassTypeAttributes classType }}}';
{{/ unless }}

{{# unless (classTypeRelationsIsEmpty classType) }}
export type {{ classDataName classType '' }}Relations = '{{{ getClassTypeRelations classType }}}';
export type {{ classDataName classType '' }}Relations = '{{{ getClassTypeRelations classType }}}';
{{/ unless }}

export interface {{ classDataName classType 'Stored' }} extends JudoStored<{{ classDataName classType '' }}>, {{ classDataName classType '' }} {};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{{> fragment.header.hbs }}

export enum {{ restParamName enumerationType }} {

{{# each enumerationType.members as | member | }}
{{ member.name }} = '{{ member.name }}',
{{ member.name }} = '{{ member.name }}',
{{/ each}}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{> fragment.header.hbs }}

{{# each (getEnumerationTypes application) as | fileName | }}
export * from './{{ restParamName fileName }}';
export * from './{{ restParamName fileName }}';
{{/ each }}

{{# each (getClassTypes application) as | fileName | }}
export * from './{{ classDataName fileName '' }}';
export * from './{{ classDataName fileName '' }}';
{{/ each }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{{> fragment.header.hbs }}

{{# each (getOperationTypeFaults operationType) as | fault |}}
import { {{ getFaultTargets fault '' }} } from './{{ getFaultTargets fault '' }}';
import { {{ getFaultTargets fault '' }} } from './{{ getFaultTargets fault '' }}';
{{/ each }}

export interface {{ operationType.FaultContainerName }} {

{{# each operationType.faults as | fault | }}
'{{ fault.target.name.faultKey }}'?: null | {{ getFaultTargets fault '' }};
{{ fault.target.name.faultKey }}?: null | {{ getFaultTargets fault '' }};
{{/each }}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import { {{ joinModelImports dataType }} } from '../model';

export interface {{ restFilterName dataType }} {
value: {{# if (isEnumType dataType) }}{{ restParamName dataType }}{{ else }}{{ typescriptType dataType }}{{/ if }};
operator: {{ typescriptType dataType.operator }};
value: {{# if (isEnumType dataType) }}{{ restParamName dataType }}{{ else }}{{ typescriptType dataType }}{{/ if }};
operator: {{ typescriptType dataType.operator }};
}
17 changes: 8 additions & 9 deletions judo-ui-typescript-rest-api/src/main/resources/rest/mask.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import { MaskBuilder{{# if (isGreaterThan (getAggregatedRelationsSize classType) 0) }}, RelationMaskBuilder{{/ if }} } from './MaskBuilder';
import { {{ joinModelImportTokens ( modelImportTokens classType ) }} } from '../model';

{{# each (getNotClassTypeRelations (getUniqueRelations classType) classType) as | relation | }}
import { {{ getRelationBuilderNames relation }} } from './{{ classDataName relation.target "MaskBuilder" }}';
import { {{ getRelationBuilderNames relation }} } from './{{ classDataName relation.target "MaskBuilder" }}';
{{/ each}}

{{# each (getAggregatedRelations classType) as | relation | }}
export class {{ relationBuilderName relation classType "MaskBuilder" }} extends RelationMaskBuilder {
constructor(protected props: Array<{{ getRelationBuilderNamesWithPipe relation }}>) {
super('{{ relation.name }}', props);
}
export class {{ relationBuilderName relation classType "MaskBuilder" }} extends RelationMaskBuilder {
constructor(protected props: Array<{{ getRelationBuilderNamesWithPipe relation }}>) {
super('{{ relation.name }}', props);
}
}
{{/ each }}

export class {{ classDataName classType "MaskBuilder" }} extends MaskBuilder {
constructor(protected props: Array<{{ generateBuilderProps classType }}>) {
super(props);
}
constructor(protected props: Array<{{ generateBuilderProps classType }}>) {
super(props);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{{> fragment.header.hbs }}

export class MaskBuilder {
constructor(protected props: Array<string | MaskBuilder>) {}
constructor(protected props: Array<string | MaskBuilder>) {}

build(): string {
const distinctStrings = Array.from(new Set(this.props.filter(p => typeof p === 'string')));
const distinctBuilders = Array.from(new Set(this.props.filter(p => p instanceof MaskBuilder).map(p => (p as MaskBuilder).build())));
build(): string {
const distinctStrings = Array.from(new Set(this.props.filter(p => typeof p === 'string')));
const distinctBuilders = Array.from(new Set(this.props.filter(p => p instanceof MaskBuilder).map(p => (p as MaskBuilder).build())));

return `{${[...distinctStrings, ...distinctBuilders].join(',')}}`
}
return `{${[...distinctStrings, ...distinctBuilders].join(',')}}`
}
}

export class RelationMaskBuilder extends MaskBuilder {
constructor(protected name: string, protected props: Array<string | RelationMaskBuilder>) {
super(props);
}
constructor(protected name: string, protected props: Array<string | RelationMaskBuilder>) {
super(props);
}

build(): string {
return `${this.name}${super.build()}`
}
build(): string {
return `${this.name}${super.build()}`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import type { QueryCustomizer } from '@judo/data-api-common';
import { {{ classDataName classType "" }} } from '../model/{{ classDataName classType "" }}';

{{# each (getImportTokensForQueries classType) as | token | }}
import { {{ token }} } from './{{ token }}';
import { {{ token }} } from './{{ token }}';
{{/ each}}

export interface {{ classDataName classType "QueryCustomizer" }} extends QueryCustomizer<{{ classDataName classType "" }}>{
{{# each classType.attributes as |attribute| }}
{{# if attribute.isFilterable }}
{{ attribute.name }}?: Array<{{ restFilterName attribute.dataType }}>;
{{/ if}}
{{# if attribute.isFilterable }}
{{ attribute.name }}?: Array<{{ restFilterName attribute.dataType }}>;
{{/ if}}
{{/ each}}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{{> fragment.header.hbs }}

{{# each (getClassTypes application) as | fileName | }}
export * from './{{ classDataName fileName "QueryCustomizer" }}';
export * from './{{ classDataName fileName "QueryCustomizer" }}';
{{/ each }}

{{# each (getClassTypes application) as | fileName | }}
export * from './{{ classDataName fileName "MaskBuilder" }}';
export * from './{{ classDataName fileName "MaskBuilder" }}';
{{/ each }}

{{# each (getFilterableDataTypes application) as | fileName | }}
export * from './{{ restFilterName fileName }}';
export * from './{{ restFilterName fileName }}';
{{/ each }}
export * from './MaskBuilder';
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,65 @@ import { AccessService } from '../data-service';

export class AccessServiceImpl extends JudoAxiosService implements AccessService {
{{# if application.principal }}
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<{{ classDataName application.principal "" }}>}
*/
async getPrincipal(): Promise<{{ classDataName application.principal "Stored" }}> {
const response = await this.axios.get(this.getPathForActor('{{ rootPathForApp application }}/~principal'));
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<{{ classDataName application.principal "" }}>}
*/
async getPrincipal(): Promise<{{ classDataName application.principal "Stored" }}> {
const response = await this.axios.get(this.getPathForActor('{{ rootPathForApp application }}/~principal'));

return response.data;
}
return response.data;
}
{{/ if }}

/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<JudoMetaData>}
*/
async getMetaData(): Promise<JudoMetaData> {
const response = await this.axios.get(this.getPathForActor('{{ rootPathForApp application }}/~meta'));
return response.data;
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<JudoMetaData>}
*/
async getMetaData(): Promise<JudoMetaData> {
const response = await this.axios.get(this.getPathForActor('{{ rootPathForApp application }}/~meta'));
return response.data;
}

/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 400, 401, 403.
* @return {Promise<string>}
*/
async uploadFile(attributePath: string, file: File): Promise<any> {
const responseToken: any = await this.axios.post(this.getPathForActor(attributePath + '/~upload-token'));

if (!responseToken) {
throw new Error(`Could not upload file, could not obtain Upload Token!`);
}
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 400, 401, 403.
* @return {Promise<string>}
*/
async uploadFile(attributePath: string, file: File): Promise<any> {
const responseToken: any = await this.axios.post(this.getPathForActor(attributePath + '/~upload-token'));
if (!responseToken) {
throw new Error(`Could not upload file, could not obtain Upload Token!`);
}
const formData = new FormData();
formData.append(file.name, file);
const response = await this.axios.post(this.axiosProvider.getFilePath('upload'), formData, {
headers: {
'Content-Type': 'multipart/form-data',
'X-Token': responseToken.data.token,
},
});

if (response.status === 200) {
return response;
} else {
throw new Error(`Unexpected upload response: ${response.status}\n${response}`);
}
}
/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<JudoDownloadFile>}
*/
async downloadFile(downloadToken: string, disposition: 'inline' | 'attachment'): Promise<any> {
const response = await this.axios.get(`${this.axiosProvider.getFilePath('download')}?disposition=${disposition}`, {
responseType: 'blob',
headers: {
'X-Token': downloadToken,
},
});
return response;
const formData = new FormData();
formData.append(file.name, file);

const response = await this.axios.post(this.axiosProvider.getFilePath('upload'), formData, {
headers: {
'Content-Type': 'multipart/form-data',
'X-Token': responseToken.data.token,
},
});

if (response.status === 200) {
return response;
} else {
throw new Error(`Unexpected upload response: ${response.status}\n${response}`);
}
}

/**
* @throws {AxiosError} With data containing {@link Array<FeedbackItem>} for status codes: 401, 403.
* @return {Promise<JudoDownloadFile>}
*/
async downloadFile(downloadToken: string, disposition: 'inline' | 'attachment'): Promise<any> {
const response = await this.axios.get(`${this.axiosProvider.getFilePath('download')}?disposition=${disposition}`, {
responseType: 'blob',
headers: {
'X-Token': downloadToken,
},
});
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import type { AxiosInstance } from 'axios';

export interface JudoAxiosProviderInitData {
axios: AxiosInstance;
basePathFactory?: () => string;
filePathFactory?: () => string;
axios: AxiosInstance;
basePathFactory?: () => string;
filePathFactory?: () => string;
}

export interface AxiosProvider {
init(data: JudoAxiosProviderInitData): void;
getAxios(): AxiosInstance;
getBasePath(suffix?: string): string;
getFilePath(suffix?: string): string;
init(data: JudoAxiosProviderInitData): void;
getAxios(): AxiosInstance;
getBasePath(suffix?: string): string;
getFilePath(suffix?: string): string;
}
Loading

0 comments on commit c4de3a0

Please sign in to comment.