Skip to content

Commit

Permalink
feat: add conditional operations
Browse files Browse the repository at this point in the history
  • Loading branch information
GenaRazmakhnin committed Nov 6, 2024
1 parent 0b21b1f commit a4f62aa
Showing 1 changed file with 51 additions and 24 deletions.
75 changes: 51 additions & 24 deletions resources/sdk/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,41 @@ export class Client<T extends BasicAuthorization | ResourceOwnerAuthorization> {
.post(buildResourceUrl(''), { json: data })
.json<Bundle>();
},
conditionalUpdate: <T extends keyof ResourceTypeMap>(
resourceName: T,
search: string,
input: PartialResourceBody<T>
) => {
return this.client
.patch(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
.json<BaseResponseResource<T>>();
},
conditionalCreate: <T extends keyof ResourceTypeMap>(
resourceName: T,
search: string,
input: PartialResourceBody<T>
) => {
return this.client
.post(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
.json<BaseResponseResource<T>>();
},
conditionalOverride: <T extends keyof ResourceTypeMap>(
resourceName: T,
search: string,
input: PartialResourceBody<T>
) => {
return this.client
.put(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
.json<BaseResponseResource<T>>();
},
conditionalDelete: <T extends keyof ResourceTypeMap>(
resourceName: T,
search: string
) => {
return this.client
.delete(`${buildResourceUrl(resourceName)}?${search}`)
.json<BaseResponseResource<T>>();
},
search: this.search,
list: this.search,
get: async <T extends keyof ResourceTypeMap>(
Expand All @@ -695,43 +730,35 @@ export class Client<T extends BasicAuthorization | ResourceOwnerAuthorization> {
.get(buildResourceUrl(resourceName, id))
.json<BaseResponseResource<T>>();
},
delete: async <T extends keyof ResourceTypeMap>(
delete: <T extends keyof ResourceTypeMap>(
resourceName: T,
id: string,
): Promise<BaseResponseResource<T>> => {
return new SearchResources<T>((searchParams: URLSearchParams) => {
return this.client
.delete(buildResourceUrl(resourceName, id), { searchParams });
}, resourceName)
) => {
return this.client
.delete(buildResourceUrl(resourceName, id));
},
update: async <T extends keyof ResourceTypeMap>(
update: <T extends keyof ResourceTypeMap>(
resourceName: T,
id: string,
input: PartialResourceBody<T>,
): Promise<BaseResponseResource<T>> => {
return new SearchResources<T>((searchParams: URLSearchParams) => {
return this.client
.patch(buildResourceUrl(resourceName, id), { json: input, searchParams });
}, resourceName)
) => {
return this.client
.patch(buildResourceUrl(resourceName, id), { json: input });
},
create: async <T extends keyof ResourceTypeMap>(
create: <T extends keyof ResourceTypeMap>(
resourceName: T,
input: SetOptional<ResourceTypeMap[T] & { resourceType: string }, 'resourceType'>,
): Promise<BaseResponseResource<T>> => {
return new SearchResources<T>((searchParams: URLSearchParams) => {
return this.client
.post(buildResourceUrl(resourceName), { json: input, searchParams });
}, resourceName)
) => {
return this.client
.post(buildResourceUrl(resourceName), { json: input });
},
override: async <T extends keyof ResourceTypeMap>(
override: <T extends keyof ResourceTypeMap>(
resourceName: T,
id: string,
input: PartialResourceBody<T>,
): Promise<BaseResponseResource<T>> => {
return new SearchResources<T>((searchParams: URLSearchParams) => {
return this.client
.put(buildResourceUrl(resourceName, id), { json: input, searchParams });
}, resourceName)
) => {
return this.client
.put(buildResourceUrl(resourceName, id), { json: input });
},
};

Expand Down

0 comments on commit a4f62aa

Please sign in to comment.