Skip to content

Commit

Permalink
fix: prettier formatting, removed query params, stronger typing for f…
Browse files Browse the repository at this point in the history
…unc. params.
  • Loading branch information
michaelpineirocontentful committed Jan 16, 2025
1 parent c8582f4 commit 8d1e35e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
11 changes: 6 additions & 5 deletions lib/adapters/REST/endpoints/function.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { AxiosInstance } from 'contentful-sdk-core'
import * as raw from './raw'
import { normalizeSelect } from './utils'
import type {
CollectionProp,
GetFunctionForEnvParams,
GetFunctionParams,
GetManyFunctionParams,
} from '../../../common-types'
import type { RestEndpoint } from '../types'
import type { FunctionProps } from '../../../entities/function'

const getBaseUrl = (params: GetFunctionParams) =>
// Base URL
const getManyUrl = (params: GetManyFunctionParams) =>
`/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/functions`

const getFunctionUrl = (params: GetFunctionParams) => `${getBaseUrl(params)}/${params.functionId}`
const getFunctionUrl = (params: GetFunctionParams) => `${getManyUrl(params)}/${params.functionId}`

const getFunctionsEnvURL = (params: GetFunctionForEnvParams) => {
return `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appInstallationId}/functions`
Expand All @@ -27,9 +28,9 @@ export const get: RestEndpoint<'Function', 'get'> = (

export const getMany: RestEndpoint<'Function', 'getMany'> = (
http: AxiosInstance,
params: GetFunctionParams
params: GetManyFunctionParams
) => {
return raw.get<CollectionProp<FunctionProps>>(http, getBaseUrl(params))
return raw.get<CollectionProp<FunctionProps>>(http, getManyUrl(params))
}

export const getManyForEnvironment: RestEndpoint<'Function', 'getManyForEnvironment'> = (
Expand Down
5 changes: 3 additions & 2 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ export type MRActions = {
}
Function: {
get: { params: GetFunctionParams; return: FunctionProps }
getMany: { params: GetFunctionParams; return: CollectionProp<FunctionProps> }
getMany: { params: GetManyFunctionParams; return: CollectionProp<FunctionProps> }
getManyForEnvironment: {
params: GetFunctionForEnvParams
return: CollectionProp<FunctionProps>
Expand Down Expand Up @@ -2148,7 +2148,8 @@ export type GetEditorInterfaceParams = GetSpaceEnvironmentParams & { contentType
export type GetEntryParams = GetSpaceEnvironmentParams & { entryId: string }
export type GetExtensionParams = GetSpaceEnvironmentParams & { extensionId: string }
export type GetEnvironmentTemplateParams = GetOrganizationParams & { environmentTemplateId: string }
export type GetFunctionParams = GetAppDefinitionParams & { functionId?: string }
export type GetFunctionParams = GetAppDefinitionParams & { functionId: string }
export type GetManyFunctionParams = GetAppDefinitionParams
export type GetFunctionForEnvParams = GetSpaceParams & { environmentId: string } & {
appInstallationId: string
}
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/bulk-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export enum BulkActionStatus {
}

const STATUSES = Object.values(BulkActionStatus)
type BulkActionStatuses = typeof STATUSES[number]
type BulkActionStatuses = (typeof STATUSES)[number]

interface BulkActionFailedError {
sys: { type: 'Error'; id: 'BulkActionFailed' }
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/resource-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type OptionalSysFields =

export type SpaceEnvResourceTypeProps = Pick<
ResourceTypeProps,
typeof publicResourceTypeFields[number]
(typeof publicResourceTypeFields)[number]
> & {
// we mark timestamps and users as optional to include system types like `Contentful:Entry` into the public response
sys: Partial<Pick<ResourceTypeProps['sys'], OptionalSysFields>> &
Expand Down
1 change: 0 additions & 1 deletion lib/plain/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import type {
EnvironmentTemplateValidationProps,
ValidateEnvironmentTemplateInstallationProps,
} from '../entities/environment-template-installation'
import type { FunctionProps } from '../entities/function'
import type {
CreateOrganizationInvitationProps,
OrganizationInvitationProps,
Expand Down
8 changes: 3 additions & 5 deletions lib/plain/entities/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
CollectionProp,
GetFunctionParams,
GetFunctionForEnvParams,
QueryParams,
GetManyFunctionParams,
} from '../../common-types'
import type { FunctionProps } from '../../entities/function'
import type { OptionalDefaults } from '../wrappers/wrap'
Expand Down Expand Up @@ -37,9 +37,7 @@ export type FunctionPlainClientAPI = {
* });
* ```
*/
getMany(
params: OptionalDefaults<GetFunctionParams & QueryParams>
): Promise<CollectionProp<FunctionProps>>
getMany(params: OptionalDefaults<GetManyFunctionParams>): Promise<CollectionProp<FunctionProps>>

/**
* Fetches all functions for the given environment
Expand All @@ -56,6 +54,6 @@ export type FunctionPlainClientAPI = {
* ```
*/
getManyForEnvironment(
params: OptionalDefaults<GetFunctionForEnvParams & QueryParams>
params: OptionalDefaults<GetFunctionForEnvParams>
): Promise<CollectionProp<FunctionProps>>
}
2 changes: 1 addition & 1 deletion test/unit/mocks/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ const mocks = {
workflowsChangelogEntry: workflowsChangelogEntryMock,
}

function cloneMock<T extends keyof typeof mocks>(name: T): typeof mocks[T] {
function cloneMock<T extends keyof typeof mocks>(name: T): (typeof mocks)[T] {
return cloneDeep(mocks[name])
}

Expand Down

0 comments on commit 8d1e35e

Please sign in to comment.