Skip to content
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

Merged
merged 13 commits into from
Feb 14, 2024
Merged

Adding bulk actions to 1.1 #53

merged 13 commits into from
Feb 14, 2024

Conversation

ssanjay1
Copy link
Contributor

@ssanjay1 ssanjay1 commented Feb 12, 2024

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)

@changelog-app
Copy link

changelog-app bot commented Feb 12, 2024

Generate changelog in packages/generator/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Adding bulk actions to 1.1


Generate changelog in packages/legacy-client/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Adding bulk actions to 1.1


Generate changelog in packages/shared.test/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Adding bulk actions to 1.1


Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor Author

@ssanjay1 ssanjay1 left a 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[] = [];
Copy link
Contributor Author

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)

Copy link
Member

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> {
Copy link
Contributor Author

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

Copy link
Member

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>
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

Copy link
Contributor Author

@ssanjay1 ssanjay1 Feb 12, 2024

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})?

Copy link
Contributor Author

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;
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Contributor

@styu styu left a 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;
Copy link
Contributor

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?

Copy link
Member

@ericanderson ericanderson left a 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);
Copy link
Member

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.

Copy link
Contributor Author

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>
Copy link
Member

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,
>(
Copy link
Member

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>(
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -141,8 +163,8 @@ export const ActionResponse = {
],
};
if (response.edits?.type === "edits") {
const added = [];
const modified = [];
const added: any[] = [];
Copy link
Member

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[] = [];
Copy link
Member

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) {
Copy link
Member

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)
: [],
Copy link
Member

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> {
Copy link
Member

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.

@ssanjay1 ssanjay1 merged commit e2964be into main Feb 14, 2024
6 checks passed
@ssanjay1 ssanjay1 deleted the ssanjay/bulkActions2 branch February 14, 2024 22:05
@ssanjay1 ssanjay1 mentioned this pull request Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants