-
Notifications
You must be signed in to change notification settings - Fork 17
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
Adding bulk actions to 1.1 #53
Conversation
Generate changelog in
|
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.
Left some comments as well, also general question, where is the best place to expose some sort of docs to indicate that the bulk actions endpoint only supports up to 20 requests at a time?
@@ -141,8 +163,8 @@ export const ActionResponse = { | |||
], | |||
}; | |||
if (response.edits?.type === "edits") { | |||
const added = []; | |||
const modified = []; | |||
const added: any[] = []; |
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.
Didn't touch this, but for some reason had to add this type, or else checks error out with something along the lines of :
Argument of type '{ apiName: string; primaryKey: any; get: () => Promise<Result<OntologyObject<string, NonNullable<ParameterValue>>, GetObjectError>>; }' is not assignable to parameter of type 'never'.ts(2345)
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.
Hmm. I am a little worried this means we broke something somewhere. If we need to keep a change like this we could at least type it to the real shape we are pushing to prevent future errors.
@@ -38,6 +41,10 @@ export class Ontology<O extends OntologyDefinition<any>> { | |||
return createActionProxy(this.#client); | |||
} | |||
|
|||
get bulkActions(): BulkActions<O> { |
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 only added this here, and not in the actual OntologyDefinition since this seems like we're only adding this for 1.1
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.
That would be correct, since there is no custom definition for actions vs bulk actions. Only the runtime client.ontology.
should be showing bulkActions
.
IsEmptyRecord<O["actions"][A]["parameters"]> extends true | ||
? <Op extends BulkActionExecutionOptions>( | ||
options?: Op, | ||
) => WrappedBulkActionReturnType<O, A, Op> |
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.
Right now I'm just following pattern of how we've handled other actions with no parameters, but the way its setup bulk actions don't really work for actions without parameters. This could be modified so it accepts an array of {}
potentially? And we just use those to tell us how many empty requests we need for the batch endpoint?
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 think {}[]
or undefined[]
is better than nothing, otherwise you arent really calling bulk.
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.
Would undefined[]
be preferable here? Because with {}[]
won't that just let you pass in any sort of object https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcBCBXANgawIIDGMAlhAHYCiIwBGJ5A8mPWQM5wC8cA3gFBxwAthAAmwAPwAuOGQyCARsCgBufnCjAYGKJRHEYrKTLmKocXgF9eYglgCGGuADMMZIqTLOyACghhpmLiELFQ0dB5MLKwAlNIAbhDEIqq8Tj7c5gICAPTZcMRkMMBYWMSswGyorAAWEADu7AAGwmKNltG8vKCQsAjIqIH47uShtCyRHqwATJw8ahpaOhR6BkayCkrmVjb2ji5uLF5TADwACnCgRWQi7IPBHqPhjMyTUwB8vv5wp7FwCUmqNJTbx8LJCUTAaQAVlyMgg8CwwAA5nYsHAwA47IJ8k44IgIBg4AArDCseAQQT6dqdIHHO7DSjUMYRF7kVgfUFZFqQuAwvJkeFwREotEYqBYnF4gnE0nkykwaldcDQeBIFBweTYHDAQTMRCzTkFapKSHcCwAbQAuqorLwCGyEZoyVBEJJNbgdXqDUaTZJzdwAJIEOzXerVOxFOJKSQARgsABoeBZLRYgA
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.
But also feel like it could be weird syntax to do something like client.ontology.bulkActions.noParamaction([undefined, undefined,...], {options})
?
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 wait could we use Record<string,never>[]
?
@@ -30,6 +33,11 @@ export type ActionExecutionOptions = { | |||
returnEdits?: ReturnEditsMode; | |||
}; | |||
|
|||
export type BulkActionExecutionOptions = { | |||
mode?: never; |
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.
Don't want users trying to pass in any sort of execution mode as that isn't supported by the endpoint
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.
The problem with this though is it is suggested in intellisense even though it can only be undefined.
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.
Ah yea you're right, I think I needed this before when we tried the original syntax and I had some conditional types for the options, but yea I think I can just omit now, on it
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.
defer to @ericanderson on the meat of the changes
@@ -58,5 +59,6 @@ export const Ontology: { | |||
export interface Ontology extends ClientOntology<typeof Ontology> { | |||
objects: Objects; | |||
actions: Actions; | |||
bulkActions: BulkActions; |
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.
can you mention rationale in the PR description as to why we add it at the top level vs within actions, for posterity?
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.
Some notes to fix up before merging.
const entries = Object.entries(action.parameters); | ||
|
||
const modifiedEntityTypes = getModifiedEntityTypes(action); | ||
const addedObjects = Array.from(modifiedEntityTypes.addedObjects); |
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 .addedObjects
/.modifiedObjects
is a Set<string>
. So we are converting it to an array so we can forEach
add it to a different set. At the very least you could just forEach
on the returned sets instead of the memory copy.
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.
Ah yea I just pulled this from the generateActions
, it looks like we converted to Array so we could just do a simple join on line 74 when generating the edits return type
IsEmptyRecord<O["actions"][A]["parameters"]> extends true | ||
? <Op extends BulkActionExecutionOptions>( | ||
options?: Op, | ||
) => WrappedBulkActionReturnType<O, A, Op> |
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 think {}[]
or undefined[]
is better than nothing, otherwise you arent really calling bulk.
return async function<Op extends ActionExecutionOptions>( | ||
return async function< | ||
Op extends ActionExecutionOptions, | ||
>( |
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.
nit: unnecessary change
params: ActionArgs<O, typeof p>, | ||
options?: Op, | ||
): Promise<WrappedActionReturnType<O, typeof p, Op>> { | ||
return executeAction<O, typeof p, Op>(client, p, params, options); | ||
return executeAction<O, typeof p, Op>( |
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.
nit: unnecessary change
@@ -30,6 +33,11 @@ export type ActionExecutionOptions = { | |||
returnEdits?: ReturnEditsMode; | |||
}; | |||
|
|||
export type BulkActionExecutionOptions = { | |||
mode?: never; |
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.
The problem with this though is it is suggested in intellisense even though it can only be undefined.
@@ -141,8 +163,8 @@ export const ActionResponse = { | |||
], | |||
}; | |||
if (response.edits?.type === "edits") { | |||
const added = []; | |||
const modified = []; | |||
const added: any[] = []; |
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.
Hmm. I am a little worried this means we broke something somewhere. If we need to keep a change like this we could at least type it to the real shape we are pushing to prevent future errors.
): BulkActionResponse<Edits<TAddedObjects, TModifiedObjects> | undefined> => { | ||
if (response.edits?.type === "edits") { | ||
const added: any[] = []; | ||
const modified: any[] = []; |
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.
same here
if (response.edits?.type === "edits") { | ||
const added: any[] = []; | ||
const modified: any[] = []; | ||
for (const edit of response.edits.edits) { |
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 seems like a copy/paste of the above. Maybe extract function for getting the edits
shape ({type:"edits", added,modified}
)?
{ | ||
requests: params | ||
? remapBulkActionParams<O, A>(params) | ||
: [], |
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.
Given empty array is used here, does this mean that any actions that take zero arguments can never be called in bulk? If thats the intention, should we just exclude them in the type mapping for creating bulk actions?
@@ -38,6 +41,10 @@ export class Ontology<O extends OntologyDefinition<any>> { | |||
return createActionProxy(this.#client); | |||
} | |||
|
|||
get bulkActions(): BulkActions<O> { |
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.
That would be correct, since there is no custom definition for actions vs bulk actions. Only the runtime client.ontology.
should be showing bulkActions
.
We added bulk actions to the top level client ontology due to difficulties wrangling with the types that would conditionally enforce options and return types based on what parameters were passed in (array vs single input)