Skip to content

Commit

Permalink
feat(ambientes): operations
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed May 2, 2024
1 parent 339e3d8 commit 1ccfe12
Show file tree
Hide file tree
Showing 35 changed files with 1,372 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ export type IObjectUuid = {
id: string;
};

export const ObjectUuidDeclarationFactory = (name: string = 'ObjectUuid') => {
export const ObjectUuid = (description: string | null = null, name: string | null = null) => {
return {
name,
name: name ?? 'ObjectUuid',

properties: {
id: {
nullable: false,
type: PropertyTypes.UUID,
description: 'ID do registro.',
description: description ?? 'ID do registro.',
validator: ({ custom }) => custom.uuid(),
},
},
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions javascript/sisgea-spec/src/core/pagination/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './IPaginatedOptionsInputDto';
export * from './paginated-result.declaration';
export * from './pagination.declaration';
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import * as Spec from '@/helpers';

export type IPaginatedResultDtoMetaSortBy = {
property: string;
export type IPaginatedSortBy = {
mode: string;
property: string;
};

export type IPaginatedFilter = {
property: string;
restrictions: string[];
};

export type IPaginatedResultDtoMeta = {
itemsPerPage: number;
totalItems: number;
currentPage: number;
totalPages: number;
search: string;
//
sortBy: IPaginatedSortBy[];
filter: IPaginatedFilter[];
};

export type IPaginatedResultDtoLinks = {
first: string | null;
previous: string | null;
current: string | null;
next: string | null;
last: string | null;
};

export type IPaginatedResultDto<T> = {
data: T[];
meta: IPaginatedResultDtoMeta;
links: IPaginatedResultDtoLinks;
};

export type IPaginatedInputDto = {
limit?: number;
page?: number;
search?: string;
sortBy?: IPaginatedSortBy[];
filter?: IPaginatedFilter[];
};

export const PaginatedResultDtoMetaSortByDeclaration = () => {
export const PaginatedResultDtoMetaSortBy = () => {
return {
name: 'PaginatedResultDtoMetaSortBy',

Expand All @@ -14,22 +52,24 @@ export const PaginatedResultDtoMetaSortByDeclaration = () => {
type: Spec.PropertyTypes.STRING,
description: '',
nullable: false,
validator: ({ custom }) => custom.string().required().nonNullable(),
},
mode: {
type: Spec.PropertyTypes.STRING,
description: '',
nullable: false,
validator: ({ custom }) =>
custom
.string()
.matches(/^[\D]+:(ASC|DESC)$/)
.required()
.nonNullable(),
},
},
} satisfies Spec.IDeclaration;
};

export type IPaginatedResultDtoMetaFilter = {
property: string;
restrictions: string[];
};

export const PaginatedResultDtoMetaFilterDeclaration = () => {
export const PaginatedResultDtoMetaFilter = () => {
return {
name: 'PaginatedResultDtoMetaFilter',

Expand All @@ -49,17 +89,7 @@ export const PaginatedResultDtoMetaFilterDeclaration = () => {
} satisfies Spec.IDeclaration;
};

export type IPaginatedResultDtoMeta = {
itemsPerPage: number;
totalItems: number;
currentPage: number;
totalPages: number;
search: string;
sortBy: IPaginatedResultDtoMetaSortBy[];
filter: IPaginatedResultDtoMetaFilter[];
};

export const PaginatedResultDtoMetaDeclaration = () => {
export const PaginatedResultDtoMeta = () => {
return {
name: 'PaginatedResultDtoMeta',

Expand Down Expand Up @@ -94,29 +124,21 @@ export const PaginatedResultDtoMetaDeclaration = () => {
sortBy: {
arrayOf: true,
description: '',
type: PaginatedResultDtoMetaSortByDeclaration,
type: PaginatedResultDtoMetaSortBy,
nullable: false,
},

filter: {
arrayOf: true,
description: '',
type: PaginatedResultDtoMetaFilterDeclaration,
type: PaginatedResultDtoMetaFilter,
nullable: false,
},
},
} satisfies Spec.IDeclaration;
};

export type IPaginatedResultDtoLinks = {
first: string | null;
previous: string | null;
current: string | null;
next: string | null;
last: string | null;
};

export const PaginatedResultDtoLinksDeclaration = () => {
export const PaginatedResultDtoLinks = () => {
return {
name: 'PaginatedResultDtoLinks',

Expand Down Expand Up @@ -150,12 +172,6 @@ export const PaginatedResultDtoLinksDeclaration = () => {
} satisfies Spec.IDeclaration;
};

export type IPaginatedResultDto<T> = {
data: T[];
meta: IPaginatedResultDtoMeta;
links: IPaginatedResultDtoLinks;
};

export const PaginatedResultDtoDeclarationFactoryBuilder = (type: Spec.IDeclarator<any>, name: string) => () => {
return {
name: name,
Expand All @@ -164,7 +180,7 @@ export const PaginatedResultDtoDeclarationFactoryBuilder = (type: Spec.IDeclarat
meta: {
nullable: false,
description: '',
type: PaginatedResultDtoMetaDeclaration,
type: PaginatedResultDtoMeta,
},

data: {
Expand All @@ -177,7 +193,50 @@ export const PaginatedResultDtoDeclarationFactoryBuilder = (type: Spec.IDeclarat
links: {
description: '',
nullable: false,
type: PaginatedResultDtoLinksDeclaration,
type: PaginatedResultDtoLinks,
},
},
} satisfies Spec.IDeclaration;
};

export const PaginatedInput = () => {
return {
name: 'PaginatedInput',
properties: {
limit: {
nullable: true,
required: false,
type: Spec.PropertyTypes.INTEGER,
description: 'Limitar a quantidade de resultados por página.',
validator: ({ custom }) => custom.number().integer().positive().nullable().optional(),
},
page: {
nullable: true,
required: false,
type: Spec.PropertyTypes.INTEGER,
description: 'Definir a página de consulta.',
validator: ({ custom }) => custom.number().integer().positive().nullable().optional().default(1),
},
search: {
nullable: true,
required: false,
type: Spec.PropertyTypes.STRING,
description: 'Busca textual.',
validator: ({ custom }) => custom.string().nullable().optional(),
},
sortBy: {
arrayOf: true,
nullable: true,
required: false,
description: 'Ordenação.',
type: PaginatedResultDtoMetaSortBy,
},
filter: {
arrayOf: true,
nullable: true,
required: false,
description: 'Filtros',
type: PaginatedResultDtoMetaFilter,
},
},
} satisfies Spec.IDeclaration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IValidationContractObjectIdOptions {
message?: string;
}

export const objectId = (yup: BaseYup) => () => {
export const objectId = (yup: BaseYup) => {
return (options: IValidationContractObjectIdOptions = {}) => {
const { required = true, message } = options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export type IOperationInputFile = {

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

Expand All @@ -21,7 +21,7 @@ export type IOperationOutputFile = {

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

export type IOperationOutputDtos = {
Expand All @@ -33,7 +33,7 @@ export type IOperation = {
name: string;
description: string;

kind?: 'query' | 'mutation';
gql: 'query' | 'mutation' | false;

input?: IOperationInputFile | IOperationInputDto | null;
output: IOperationOutputFile | IOperationOutputDtos;
Expand Down
Loading

0 comments on commit 1ccfe12

Please sign in to comment.