Skip to content

Commit a4f62aa

Browse files
feat: add conditional operations
1 parent 0b21b1f commit a4f62aa

File tree

1 file changed

+51
-24
lines changed

1 file changed

+51
-24
lines changed

resources/sdk/typescript/index.ts

+51-24
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,41 @@ export class Client<T extends BasicAuthorization | ResourceOwnerAuthorization> {
685685
.post(buildResourceUrl(''), { json: data })
686686
.json<Bundle>();
687687
},
688+
conditionalUpdate: <T extends keyof ResourceTypeMap>(
689+
resourceName: T,
690+
search: string,
691+
input: PartialResourceBody<T>
692+
) => {
693+
return this.client
694+
.patch(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
695+
.json<BaseResponseResource<T>>();
696+
},
697+
conditionalCreate: <T extends keyof ResourceTypeMap>(
698+
resourceName: T,
699+
search: string,
700+
input: PartialResourceBody<T>
701+
) => {
702+
return this.client
703+
.post(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
704+
.json<BaseResponseResource<T>>();
705+
},
706+
conditionalOverride: <T extends keyof ResourceTypeMap>(
707+
resourceName: T,
708+
search: string,
709+
input: PartialResourceBody<T>
710+
) => {
711+
return this.client
712+
.put(`${buildResourceUrl(resourceName)}?${search}`, { json: input })
713+
.json<BaseResponseResource<T>>();
714+
},
715+
conditionalDelete: <T extends keyof ResourceTypeMap>(
716+
resourceName: T,
717+
search: string
718+
) => {
719+
return this.client
720+
.delete(`${buildResourceUrl(resourceName)}?${search}`)
721+
.json<BaseResponseResource<T>>();
722+
},
688723
search: this.search,
689724
list: this.search,
690725
get: async <T extends keyof ResourceTypeMap>(
@@ -695,43 +730,35 @@ export class Client<T extends BasicAuthorization | ResourceOwnerAuthorization> {
695730
.get(buildResourceUrl(resourceName, id))
696731
.json<BaseResponseResource<T>>();
697732
},
698-
delete: async <T extends keyof ResourceTypeMap>(
733+
delete: <T extends keyof ResourceTypeMap>(
699734
resourceName: T,
700735
id: string,
701-
): Promise<BaseResponseResource<T>> => {
702-
return new SearchResources<T>((searchParams: URLSearchParams) => {
703-
return this.client
704-
.delete(buildResourceUrl(resourceName, id), { searchParams });
705-
}, resourceName)
736+
) => {
737+
return this.client
738+
.delete(buildResourceUrl(resourceName, id));
706739
},
707-
update: async <T extends keyof ResourceTypeMap>(
740+
update: <T extends keyof ResourceTypeMap>(
708741
resourceName: T,
709742
id: string,
710743
input: PartialResourceBody<T>,
711-
): Promise<BaseResponseResource<T>> => {
712-
return new SearchResources<T>((searchParams: URLSearchParams) => {
713-
return this.client
714-
.patch(buildResourceUrl(resourceName, id), { json: input, searchParams });
715-
}, resourceName)
744+
) => {
745+
return this.client
746+
.patch(buildResourceUrl(resourceName, id), { json: input });
716747
},
717-
create: async <T extends keyof ResourceTypeMap>(
748+
create: <T extends keyof ResourceTypeMap>(
718749
resourceName: T,
719750
input: SetOptional<ResourceTypeMap[T] & { resourceType: string }, 'resourceType'>,
720-
): Promise<BaseResponseResource<T>> => {
721-
return new SearchResources<T>((searchParams: URLSearchParams) => {
722-
return this.client
723-
.post(buildResourceUrl(resourceName), { json: input, searchParams });
724-
}, resourceName)
751+
) => {
752+
return this.client
753+
.post(buildResourceUrl(resourceName), { json: input });
725754
},
726-
override: async <T extends keyof ResourceTypeMap>(
755+
override: <T extends keyof ResourceTypeMap>(
727756
resourceName: T,
728757
id: string,
729758
input: PartialResourceBody<T>,
730-
): Promise<BaseResponseResource<T>> => {
731-
return new SearchResources<T>((searchParams: URLSearchParams) => {
732-
return this.client
733-
.put(buildResourceUrl(resourceName, id), { json: input, searchParams });
734-
}, resourceName)
759+
) => {
760+
return this.client
761+
.put(buildResourceUrl(resourceName, id), { json: input });
735762
},
736763
};
737764

0 commit comments

Comments
 (0)