Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/adapters/REST/endpoints/component-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ export const getMany: RestEndpoint<'ComponentType', 'getMany'> = (

export const get: RestEndpoint<'ComponentType', 'get'> = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams & { componentId: string },
params: GetSpaceEnvironmentParams & { componentTypeId: string },
headers?: RawAxiosRequestHeaders,
) => {
return raw.get<ComponentTypeProps>(http, getBaseUrl(params) + `/${params.componentId}`, {
return raw.get<ComponentTypeProps>(http, getBaseUrl(params) + `/${params.componentTypeId}`, {
headers,
})
}

export const del: RestEndpoint<'ComponentType', 'delete'> = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams & { componentTypeId: string },
) => {
return raw.del(http, getBaseUrl(params) + `/${params.componentTypeId}`)
}
4 changes: 3 additions & 1 deletion lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
select?: string
links_to_entry?: string

[key: string]: any

Check warning on line 270 in lib/common-types.ts

View workflow job for this annotation

GitHub Actions / check / lint

Unexpected any. Specify a different type
}

export interface SpaceQueryOptions extends PaginationQueryOptions {
Expand Down Expand Up @@ -576,6 +576,7 @@

(opts: MROpts<'ComponentType', 'getMany', UA>): MRReturn<'ComponentType', 'getMany'>
(opts: MROpts<'ComponentType', 'get', UA>): MRReturn<'ComponentType', 'get'>
(opts: MROpts<'ComponentType', 'delete', UA>): MRReturn<'ComponentType', 'delete'>

(opts: MROpts<'Concept', 'get', UA>): MRReturn<'Concept', 'get'>
(opts: MROpts<'Concept', 'getMany', UA>): MRReturn<'Concept', 'getMany'>
Expand Down Expand Up @@ -1475,9 +1476,10 @@
return: CollectionProp<ComponentTypeProps>
}
get: {
params: GetSpaceEnvironmentParams & { componentId: string }
params: GetSpaceEnvironmentParams & { componentTypeId: string }
return: ComponentTypeProps
}
delete: { params: GetSpaceEnvironmentParams & { componentTypeId: string }; return: void }
}
Concept: {
create: {
Expand Down
23 changes: 20 additions & 3 deletions lib/plain/entities/component-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export type ComponentTypePlainClientAPI = {
/**
* Fetches a single component type by ID
* @param params the space, environment, and component type IDs
* @param params.componentId the component type ID
* @returns the component type
* @throws if the request fails, or the space, environment, or component type is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
Expand All @@ -41,11 +40,29 @@ export type ComponentTypePlainClientAPI = {
* const componentType = await client.componentType.get({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* componentId: '<component_id>',
* componentTypeId: '<component_id>',
* });
* ```
*/
get(
params: OptionalDefaults<GetSpaceEnvironmentParams & { componentId: string }>,
params: OptionalDefaults<GetSpaceEnvironmentParams & { componentTypeId: string }>,
): Promise<ComponentTypeProps>

/**
* Deletes a single component type
* @param params the space, environment, and component type IDs
* @throws if the request fails, or the component type is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* await client.componentType.delete({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* componentTypeId: '<component_id>',
* });
* ```
*/
delete(
params: OptionalDefaults<GetSpaceEnvironmentParams & { componentTypeId: string }>,
): Promise<void>
}
1 change: 1 addition & 0 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const createPlainClient = (
componentType: {
getMany: wrap(wrapParams, 'ComponentType', 'getMany'),
get: wrap(wrapParams, 'ComponentType', 'get'),
delete: wrap(wrapParams, 'ComponentType', 'delete'),
},
contentType: {
get: wrap(wrapParams, 'ContentType', 'get'),
Expand Down
23 changes: 22 additions & 1 deletion test/unit/adapters/REST/endpoints/component-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Rest ComponentType', { concurrent: true }, () => {
params: {
spaceId: 'space123',
environmentId: 'master',
componentId: 'component123',
componentTypeId: 'component123',
},
})
.then((r) => {
Expand All @@ -102,4 +102,25 @@ describe('Rest ComponentType', { concurrent: true }, () => {
)
})
})

test('delete calls correct URL', async () => {
const { httpMock, adapterMock } = setupRestAdapter(Promise.resolve({ data: '' }))

return adapterMock
.makeRequest({
entityType: 'ComponentType',
action: 'delete',
userAgent: 'mocked',
params: {
spaceId: 'space123',
environmentId: 'master',
componentTypeId: 'component123',
},
})
.then(() => {
expect(httpMock.delete.mock.calls[0][0]).to.eql(
'/spaces/space123/environments/master/component_types/component123',
)
})
})
})
Loading