From c14a6130129786cf8e91cbecad97a7062d1809ac Mon Sep 17 00:00:00 2001 From: Siddharth9890 Date: Wed, 9 Oct 2024 10:44:45 +0530 Subject: [PATCH] fix: data asset naming convention --- api.yml | 35 +++++---- scripts/generate-types.js | 2 +- src/api.d.ts | 32 ++++---- src/common/types.ts | 10 ++- src/modules/data-asset/acl.ts | 11 ++- src/modules/data-asset/data-asset.ts | 14 ++-- src/modules/data-model/data-model.ts | 32 ++++---- src/services/wallet-service.ts | 4 +- test/data-model.test.ts | 108 +++++++++++++-------------- 9 files changed, 132 insertions(+), 116 deletions(-) diff --git a/api.yml b/api.yml index 72fcfde..c313ef4 100644 --- a/api.yml +++ b/api.yml @@ -431,7 +431,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/model.ACLRequest' + $ref: '#/components/schemas/model.DeleteACLRequest' description: Delete Assigned ACL Items Request required: true responses: @@ -537,12 +537,7 @@ paths: - Data models summary: Create data model requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/model.DataModelRequest' - description: Data Model - required: true + $ref: '#/components/requestBodies/model.DataModelRequest' responses: '201': description: Created @@ -620,12 +615,7 @@ paths: schema: type: integer requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/model.DataModel' - description: Data Model - required: true + $ref: '#/components/requestBodies/model.DataModelRequest' responses: '200': description: OK @@ -637,6 +627,14 @@ servers: - url: 'https://localhost:8080' - url: 'http://localhost:8080' components: + requestBodies: + model.DataModelRequest: + content: + application/json: + schema: + $ref: '#/components/schemas/model.DataModelRequest' + description: Data Model + required: true securitySchemes: BearerAuth: description: Type "Bearer" followed by a space and the JWT token. @@ -779,11 +777,13 @@ components: model.DataModel: type: object required: + - created_at - created_by - description - id - schema - title + - updated_at properties: created_at: type: string @@ -822,6 +822,15 @@ components: type: string title: type: string + model.DeleteACLRequest: + type: object + required: + - addresses + properties: + addresses: + type: array + items: + type: string model.MessageResponse: type: object required: diff --git a/scripts/generate-types.js b/scripts/generate-types.js index 176df3b..7ebc60e 100644 --- a/scripts/generate-types.js +++ b/scripts/generate-types.js @@ -78,7 +78,7 @@ import { WalletService } from '../services/wallet-service'; signingKey: string; }\n\n`, `export enum WalletTypeEnum { - Etherum = 'etherum', + Ethereum = 'ethereum', Solana = 'solana', }\n\n`, `export interface JWTData { diff --git a/src/api.d.ts b/src/api.d.ts index 026fe8b..cc73a11 100644 --- a/src/api.d.ts +++ b/src/api.d.ts @@ -696,7 +696,7 @@ export interface paths { /** @description Delete Assigned ACL Items Request */ requestBody: { content: { - 'application/json': components['schemas']['model.ACLRequest'][]; + 'application/json': components['schemas']['model.DeleteACLRequest'][]; }; }; responses: { @@ -852,12 +852,7 @@ export interface paths { path?: never; cookie?: never; }; - /** @description Data Model */ - requestBody: { - content: { - 'application/json': components['schemas']['model.DataModelRequest']; - }; - }; + requestBody: components['requestBodies']['model.DataModelRequest']; responses: { /** @description Created */ 201: { @@ -970,12 +965,7 @@ export interface paths { }; cookie?: never; }; - /** @description Data Model */ - requestBody: { - content: { - 'application/json': components['schemas']['model.DataModel']; - }; - }; + requestBody: components['requestBodies']['model.DataModelRequest']; responses: { /** @description OK */ 200: { @@ -1049,7 +1039,7 @@ export interface components { id: number; }; 'model.DataModel': { - created_at?: string; + created_at: string; created_by: string; deleted_at?: string; description: string; @@ -1057,7 +1047,7 @@ export interface components { schema: Record; tags?: string[]; title: string; - updated_at?: string; + updated_at: string; }; 'model.DataModelRequest': { description: string; @@ -1065,6 +1055,9 @@ export interface components { tags?: string[]; title: string; }; + 'model.DeleteACLRequest': { + addresses: string[]; + }; 'model.MessageResponse': { message: string; }; @@ -1130,7 +1123,14 @@ export interface components { }; responses: never; parameters: never; - requestBodies: never; + requestBodies: { + /** @description Data Model */ + 'model.DataModelRequest': { + content: { + 'application/json': components['schemas']['model.DataModelRequest']; + }; + }; + }; headers: never; pathItems: never; } diff --git a/src/common/types.ts b/src/common/types.ts index 41dde2f..5290c9d 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -11,8 +11,8 @@ export type Environment = 'dev' | 'prod'; export type TokenManagementMode = 'jwt' | 'privateKey'; export interface Config { - environment: Environment; jwt?: string; + environment: Environment; logging?: boolean; wallet?: { privateKey: string; @@ -26,7 +26,7 @@ export interface WalletSignMessageType { } export enum WalletTypeEnum { - Etherum = 'etherum', + Ethereum = 'ethereum', Solana = 'solana', } @@ -131,7 +131,7 @@ export type CreateDataAssetRequest = { export type DataAssetIDRequestAndResponse = { id: number }; export type DataModel = { - created_at?: string; + created_at: string; created_by: string; deleted_at?: string; description: string; @@ -139,7 +139,7 @@ export type DataModel = { schema: {}; tags?: string[]; title: string; - updated_at?: string; + updated_at: string; }; export type DataModelRequest = { @@ -149,6 +149,8 @@ export type DataModelRequest = { title: string; }; +export type DeleteACLRequest = { addresses: string[] }; + export type MessageResponse = { message: string }; export type MyAccountResponse = { diff --git a/src/modules/data-asset/acl.ts b/src/modules/data-asset/acl.ts index 5b34fc3..8db4785 100644 --- a/src/modules/data-asset/acl.ts +++ b/src/modules/data-asset/acl.ts @@ -1,6 +1,11 @@ import { MediaType } from 'openapi-typescript-helpers'; import { paths } from '../../api'; -import { OpenAPIClient, ACLRequest, PublicACL } from '../../common/types'; +import { + OpenAPIClient, + ACLRequest, + PublicACL, + DeleteACLRequest, +} from '../../common/types'; import { GTWError } from '../../helpers/custom-error'; import { ValidationService } from '../../services/validator-service'; @@ -81,12 +86,12 @@ export class ACL { * access control entries should be deleted for the data * @returns the message from the `data` object, which is accessed using `data.message`. */ - public async delete(id: number, aclList: ACLRequest[]) { + public async delete(id: number, aclList: DeleteACLRequest) { const { data, error, response } = await this.client.PATCH( '/data-assets/{id}/acl/delete', { params: { path: { id } }, - body: aclList, + body: [aclList], }, ); diff --git a/src/modules/data-asset/data-asset.ts b/src/modules/data-asset/data-asset.ts index 1d4bd82..ad48f2b 100644 --- a/src/modules/data-asset/data-asset.ts +++ b/src/modules/data-asset/data-asset.ts @@ -135,14 +135,14 @@ export class DataAsset { * This TypeScript function retrieves received data assets with pagination parameters. * @param {number} [page=1] - The `page` parameter is used to specify the page number of the * paginated data that you want to retrieve. It defaults to 1 if not provided. - * @param {number} [page_size=10] - The `page_size` parameter in the `getReceivedToMe` function + * @param {number} [page_size=10] - The `page_size` parameter in the `getReceivedByMe` function * specifies the number of items to be displayed per page when fetching received data assets. By * default, it is set to 10, meaning that the function will return a maximum of 10 data assets per * page unless specified otherwise. - * @returns The `getReceivedToMe` function is returning a `HelperPaginatedResponse` object containing + * @returns The `getReceivedByMe` function is returning a `HelperPaginatedResponse` object containing * an array of `PublicDataAsset` objects. */ - public async getReceivedToMe(page: number = 1, page_size: number = 10) { + public async getReceivedByMe(page: number = 1, page_size: number = 10) { const { data, response, error } = await this.client.GET( '/data-assets/received', { @@ -160,14 +160,14 @@ export class DataAsset { /** * This TypeScript function retrieves detailed information about a public data asset using an API * call. - * @param {number} id - The `id` parameter in the `getDetail` function is a number that represents + * @param {number} id - The `id` parameter in the `get` function is a number that represents * the unique identifier of the data asset you want to retrieve details for. - * @returns The `getDetail` function is returning a Promise that resolves to a `PublicDataAsset` + * @returns The `get` function is returning a Promise that resolves to a `PublicDataAsset` * object. The function makes an asynchronous GET request to fetch details of a data asset with the * specified `id`. If there is an error during the request, a `GTWError` is thrown with the error and * response details. Otherwise, the function returns the fetched data. */ - public async getDetail(id: number): Promise { + public async get(id: number): Promise { const { data, error, response } = await this.client.GET( '/data-assets/{id}', { @@ -308,7 +308,7 @@ export class DataAsset { * representing the name of the file. */ public async download(id: number): Promise<{ file: Blob; fileName: string }> { - const { name } = await this.getDetail(id); + const { name } = await this.get(id); const { data: file, diff --git a/src/modules/data-model/data-model.ts b/src/modules/data-model/data-model.ts index 9d2013c..8f89e38 100644 --- a/src/modules/data-model/data-model.ts +++ b/src/modules/data-model/data-model.ts @@ -80,24 +80,24 @@ export class DataModel { * @returns The `updateDataModel` function is returning the updated data model after making a PUT * request to the server with the provided `dataModelInput` for the specified `dataModelId`. */ - // async updateDataModel( - // dataModelId: number, - // dataModelInput: DataModelRequest, - // ): Promise { - // const { data, error, response } = await this.client.PUT( - // '/data-models/{id}', - // { - // body: {}, - // params: { path: { id: dataModelId } }, - // }, - // ); + async updateDataModel( + dataModelId: number, + dataModelInput: DataModelRequest, + ): Promise { + const { data, error, response } = await this.client.PUT( + '/data-models/{id}', + { + body: dataModelInput, + params: { path: { id: dataModelId } }, + }, + ); - // if (error) { - // throw new GTWError(error, response); - // } + if (error) { + throw new GTWError(error, response); + } - // return data; - // } + return data; + } /** * This TypeScript function asynchronously fetches a data model by its ID using a GET request. diff --git a/src/services/wallet-service.ts b/src/services/wallet-service.ts index 3296081..df327c3 100644 --- a/src/services/wallet-service.ts +++ b/src/services/wallet-service.ts @@ -16,9 +16,9 @@ export class WalletService { walletType?: WalletTypeEnum | undefined; }) { this.walletPrivateKey = walletPrivateKey; - this.walletType = walletType ? walletType : WalletTypeEnum.Etherum; + this.walletType = walletType ? walletType : WalletTypeEnum.Ethereum; this.wallet = - this.walletType === WalletTypeEnum.Etherum + this.walletType === WalletTypeEnum.Ethereum ? new EtherumService(this.walletPrivateKey) : new SolanaService(this.walletPrivateKey); } diff --git a/test/data-model.test.ts b/test/data-model.test.ts index 949db31..545e18a 100644 --- a/test/data-model.test.ts +++ b/test/data-model.test.ts @@ -188,58 +188,58 @@ describe('DataModel', () => { }); }); - // describe('updateDataModel', () => { - // it('should update a data model successfully', async () => { - // const dataModelId = 1; - // const input: DataModelRequest = { - // title: 'Updated Test Model', - // description: 'An updated test data model', - // schema: {}, - // tags: ['test', 'updated'], - // }; - - // const expectedOutput = { - // id: dataModelId, - // ...input, - // created_at: '2023-09-13T12:00:00Z', - // updated_at: '2023-09-13T13:00:00Z', - // created_by: 'user123', - // }; - - // mockPut.mockResolvedValue({ data: expectedOutput, error: null }); - - // const result = await dataModel.updateDataModel(dataModelId, input); - - // expect(result).toEqual(expectedOutput); - // expect(mockClient.PUT).toHaveBeenCalledWith(routes.UpdateDataModel, { - // body: input, - // params: { path: { id: dataModelId } }, - // }); - // }); - - // it('should throw GTWError when API call fails', async () => { - // const dataModelId = 1; - // const input: DataModelRequest = { - // title: 'Updated Test Model', - // description: 'An updated test data model', - // schema: {}, - // tags: ['test', 'updated'], - // }; - - // const mockError = { error: 'API Error' }; - // mockPut.mockResolvedValue({ - // data: null, - // error: mockError, - // response: {}, - // }); - - // await expect( - // dataModel.updateDataModel(dataModelId, input), - // ).rejects.toThrow(GTWError); - // expect(mockClient.PUT).toHaveBeenCalledWith(routes.UpdateDataModel, { - // body: input, - // params: { path: { id: dataModelId } }, - // }); - // }); - // }); + describe('updateDataModel', () => { + it('should update a data model successfully', async () => { + const dataModelId = 1; + const input: DataModelRequest = { + title: 'Updated Test Model', + description: 'An updated test data model', + schema: {}, + tags: ['test', 'updated'], + }; + + const expectedOutput = { + id: dataModelId, + ...input, + created_at: '2023-09-13T12:00:00Z', + updated_at: '2023-09-13T13:00:00Z', + created_by: 'user123', + }; + + mockPut.mockResolvedValue({ data: expectedOutput, error: null }); + + const result = await dataModel.updateDataModel(dataModelId, input); + + expect(result).toEqual(expectedOutput); + expect(mockClient.PUT).toHaveBeenCalledWith(routes.UpdateDataModel, { + body: input, + params: { path: { id: dataModelId } }, + }); + }); + + it('should throw GTWError when API call fails', async () => { + const dataModelId = 1; + const input: DataModelRequest = { + title: 'Updated Test Model', + description: 'An updated test data model', + schema: {}, + tags: ['test', 'updated'], + }; + + const mockError = { error: 'API Error' }; + mockPut.mockResolvedValue({ + data: null, + error: mockError, + response: {}, + }); + + await expect( + dataModel.updateDataModel(dataModelId, input), + ).rejects.toThrow(GTWError); + expect(mockClient.PUT).toHaveBeenCalledWith(routes.UpdateDataModel, { + body: input, + params: { path: { id: dataModelId } }, + }); + }); + }); });