-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async support for Directory Sync #288
Add async support for Directory Sync #288
Conversation
SyncOrAsyncListResource = Union[ | ||
Awaitable[AsyncWorkOsListResource], | ||
WorkOsListResource, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is FUN. I wanted this to be:
SyncOrAsyncListResource = Union[
Awaitable[AsyncWorkOsListResource[ListableResource, ListAndFilterParams]],
WorkOsListResource[ListableResource, ListAndFilterParams],
]
but Unions cannot be used as generics. This means I had to make the Protocol
return type SyncOrAsyncListResource
for list methods, instead of something like SyncOrAsyncListResource[Directory, DirectoryFilterParams]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to do something similar for events I'm creating a union of all event types and using that as a bounds=
constraint on a type variable.... I don't know if that's helpful at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give that a go.
list_params = { | ||
"limit": limit, | ||
"before": before, | ||
"after": after, | ||
"order": order, | ||
} | ||
|
||
if group is not None: | ||
list_params["group"] = group | ||
if directory is not None: | ||
list_params["directory"] = directory | ||
|
||
response = await self._http_client.request( | ||
"directory_users", | ||
method=REQUEST_METHOD_GET, | ||
params=list_params, | ||
token=workos.api_key, | ||
) | ||
|
||
return AsyncWorkOsListResource( | ||
list_method=self.list_users, | ||
list_args=list_params, | ||
**ListPage[DirectoryUser](**response).model_dump(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR lacks deduplication of code like this. Might be a good thing for me to take a stab at either before or after I work on connections.
@@ -32,8 +33,8 @@ class PreparedRequest(TypedDict): | |||
method: str | |||
url: str | |||
headers: httpx.Headers | |||
params: NotRequired[Union[Dict, None]] | |||
json: NotRequired[Union[Dict, None]] | |||
params: NotRequired[Union[Mapping, None]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I just did the same thing in my PR. That's fine, git diffing should be good about any conflicts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I figured it should be okay. Just wanted to get my tests passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Add async support for DirectorySync.
Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.