From f07ff0eb7527034cf852ffbdc1936ea73b2472e2 Mon Sep 17 00:00:00 2001 From: "Gabriel R. Antunes" Date: Wed, 1 May 2024 17:31:25 -0400 Subject: [PATCH] feat: OperationDeclaration: enhanced typings --- .../EntityDeclaration/EntityDeclaration.ts | 1 + .../OperationDeclaration.ts | 58 +++++++++++-------- .../sisgea/base/arquivo/arquivo.operations.ts | 7 ++- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/javascript/sisgea-spec/src/helpers/EntityDeclaration/EntityDeclaration.ts b/javascript/sisgea-spec/src/helpers/EntityDeclaration/EntityDeclaration.ts index e9fb679f..8a4fae0c 100644 --- a/javascript/sisgea-spec/src/helpers/EntityDeclaration/EntityDeclaration.ts +++ b/javascript/sisgea-spec/src/helpers/EntityDeclaration/EntityDeclaration.ts @@ -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 | IDeclarator; required?: boolean; diff --git a/javascript/sisgea-spec/src/helpers/OperationDeclaration/OperationDeclaration.ts b/javascript/sisgea-spec/src/helpers/OperationDeclaration/OperationDeclaration.ts index 72da1f30..87c740a0 100644 --- a/javascript/sisgea-spec/src/helpers/OperationDeclaration/OperationDeclaration.ts +++ b/javascript/sisgea-spec/src/helpers/OperationDeclaration/OperationDeclaration.ts @@ -1,30 +1,42 @@ import { IDeclarationProperty, IDeclarator } from '../EntityDeclaration/EntityDeclaration'; +export type IOperationInputFile = { + strategy: 'file'; + mimeTypes: string[]; +}; + +export type IOperationInputDto = { + strategy: 'dto'; + body?: Record | null; + query?: Record | null; + params?: Record | null; + combineInputs?: (inputs: { body: Record; query: Record; params?: unknown }) => unknown; +}; + +export type IOperationOutputFile = { + strategy: 'file'; + mimeTypes: string[]; + description: string; +}; + +export type IOperationOutputDto = { + description: string; + dto: IDeclarator; +}; + +export type IOperationOutputDtos = { + strategy: 'dto'; + success: IOperationOutputDto; +}; + export type IOperation = { name: string; description: string; - input?: - | { - strategy: 'file'; - } - | { - strategy: 'dto'; - - body?: Record | null; - query?: Record | null; - params?: Record | null; - - combineInputs?: (inputs: { body: Record; query: Record; params?: unknown }) => unknown; - } - | null; - - output: - | { - strategy: 'file'; - } - | { - strategy: 'dto'; - dto: IDeclarator; - }; + kind?: 'query' | 'mutation'; + + input?: IOperationInputFile | IOperationInputDto | null; + output: IOperationOutputFile | IOperationOutputDtos; }; + +export type IOperator = () => IOperation; diff --git a/javascript/sisgea-spec/src/sisgea/base/arquivo/arquivo.operations.ts b/javascript/sisgea-spec/src/sisgea/base/arquivo/arquivo.operations.ts index b3bf41e2..d647ae49 100644 --- a/javascript/sisgea-spec/src/sisgea/base/arquivo/arquivo.operations.ts +++ b/javascript/sisgea-spec/src/sisgea/base/arquivo/arquivo.operations.ts @@ -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']: { @@ -30,6 +31,8 @@ export const ArquivoGetFileOperator = () => { output: { strategy: 'file', + description: 'Binário do arquivo consultado.', + mimeTypes: ['application/octet-stream'], }, } satisfies IOperation; };