-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: Add datastore count API #93
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #93 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 36 36
Lines 1091 1091
Branches 16 16
=========================================
Hits 1091 1091 ☔ View full report in Codecov by Sentry. |
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 looks good to me 💯 left one comment
src/typed-method-types/apps.ts
Outdated
* @description The name of the datastore | ||
*/ | ||
datastore: Schema["name"]; | ||
expression?: string; |
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.
Will the descriptions of these fields be included in the documentation?
Should we add descriptions here?
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.
There are descriptions in the documentation.
Here's the dev API page https://api.dev.slack.com/methods/apps.datastore.count which has short descriptions of the optional fields.
There's a much more in-depth explanation of the expression fields here (which should be re-used for the count explanation as the expression fields work the same way as query): https://api.slack.com/automation/datastores-retrieve#query
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's do as much as we can to provide at least a basic description to specific fields. If there are relevant links for devs to read up on for more info, let's link them to it.
See for example how we do document fields and parameters and link to more information in our Node SDK: https://github.com/slackapi/node-slack-sdk/blob/main/packages/web-api/src/methods.ts#L1229-L1232
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.
Thanks for adding the descriptions 💯
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.
Made a couple of formatting suggestions and also let's DRY up the shared dynamo query expression fields so that each of the API method arguments can extend from a single type.
src/typed-method-types/apps.ts
Outdated
expression?: string; | ||
/** | ||
* @description A map of attributes referenced in expression |
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 A map of attributes referenced in expression | |
* @description A map of attributes referenced in `expression` |
(most IDEs will render markdown-like formatting)
src/typed-method-types/apps.ts
Outdated
"expression_attributes"?: Record<string, string>; | ||
/** | ||
* @description A map of values referenced in expression |
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 A map of values referenced in expression | |
* @description A map of values referenced in `expression` |
Schema extends DatastoreSchema, | ||
> = | ||
& BaseMethodArgs | ||
& { |
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 the arguments to datastore.query
and datastore.count
share a lot of fields, yes? Like datastore
, expression
, attributes and values.
I recommend factoring out these shared fields into its own dedicated type
(doesn't have to be export
ed, can just exist in this file), maybe something like a type DynamoQueryArgs
, and have each of DatastoreQueryArgs
and DatastoreCountArgs
leverage that shared type.
This way, you don't duplicate all the work, and especially with JSDocs now being a part, don't have to duplicate the docs either!
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.
For an example of how to do this, see the Node Slack SDK here: https://github.com/slackapi/node-slack-sdk/blob/main/packages/web-api/src/types/request/conversations.ts#L52-L53
There are a bunch of non-exported interface
s in the above file, and they're mixed and combined together using |
and &
in typescript for different *Arguments
types (like ConversationsAcceptSharedInviteArguments
that I linked to). It is essentially the solution to the same problem we are solving in this PR.
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.
Beautiful! Thanks for addressing my comments 🙇
Summary
Add support for Count API commands for datastores.
testing
Created an app with a datastore, and used the new API to count the number of items in the datastore.
Special notes
The API is behind a toggle which is only enabled for dev right now. The plan is to dial up the toggle with the next SDK/CLI release.
PR for CLI changes: https://github.com/slackapi/slack-cli/pull/1262
Requirements
deno task test
after making the changes.