Skip to content

Commit

Permalink
feat: OperationDeclaration: enhanced typings
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed May 1, 2024
1 parent 54b8650 commit f07ff0e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type IOutputDeclarationModes = typeof OutputDeclarationModes;
export type IOutputDeclarationMode = IOutputDeclarationModes[keyof IOutputDeclarationModes];

export type IDeclarationPropertySimple = {
name?: string | void;
arrayOf?: boolean;
type: Omit<IPropertyType, IPropertyTypes['MIXED']> | IDeclarator<any>;
required?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { IDeclarationProperty, IDeclarator } from '../EntityDeclaration/EntityDeclaration';

export type IOperationInputFile = {
strategy: 'file';
mimeTypes: string[];
};

export type IOperationInputDto = {
strategy: 'dto';
body?: Record<string, IDeclarationProperty> | null;
query?: Record<string, IDeclarationProperty> | null;
params?: Record<string, IDeclarationProperty> | null;
combineInputs?: (inputs: { body: Record<string, unknown>; query: Record<string, unknown>; params?: unknown }) => unknown;
};

export type IOperationOutputFile = {
strategy: 'file';
mimeTypes: string[];
description: string;
};

export type IOperationOutputDto = {
description: string;
dto: IDeclarator<any>;
};

export type IOperationOutputDtos = {
strategy: 'dto';
success: IOperationOutputDto;
};

export type IOperation = {
name: string;
description: string;

input?:
| {
strategy: 'file';
}
| {
strategy: 'dto';

body?: Record<string, IDeclarationProperty> | null;
query?: Record<string, IDeclarationProperty> | null;
params?: Record<string, IDeclarationProperty> | null;

combineInputs?: (inputs: { body: Record<string, unknown>; query: Record<string, unknown>; params?: unknown }) => unknown;
}
| null;

output:
| {
strategy: 'file';
}
| {
strategy: 'dto';
dto: IDeclarator<any>;
};
kind?: 'query' | 'mutation';

input?: IOperationInputFile | IOperationInputDto | null;
output: IOperationOutputFile | IOperationOutputDtos;
};

export type IOperator = () => IOperation;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { IOperation, PropertyTypes } from '@/helpers';
export const ArquivoGetFileOperator = () => {
return {
name: 'ArquivoGetFile',

description: 'Obtêm o conteúdo de um arquivo.',

input: {
strategy: 'dto',
params: {
...ObjectUuidDeclarationFactory().properties,
id: {
...ObjectUuidDeclarationFactory().properties.id,
},
},
query: {
['acesso.recurso.nome']: {
Expand All @@ -30,6 +31,8 @@ export const ArquivoGetFileOperator = () => {

output: {
strategy: 'file',
description: 'Binário do arquivo consultado.',
mimeTypes: ['application/octet-stream'],
},
} satisfies IOperation;
};

0 comments on commit f07ff0e

Please sign in to comment.