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

[Types] Expose Transaction types #1223

Closed
marlonmarcello opened this issue Oct 12, 2023 · 3 comments · Fixed by #1224
Closed

[Types] Expose Transaction types #1223

marlonmarcello opened this issue Oct 12, 2023 · 3 comments · Fixed by #1224

Comments

@marlonmarcello
Copy link

Is your feature request related to a problem? Please describe.

I am trying to create a dynamic transaction entry generator. Bear with me please.
A third party tool my company uses exports data in a JSON format.
I am trying to go through this JSON and create an array of transaction operations.

Something like:

function generateTransactions(jsonData) {
  const transactions = jsonData.map((entry) => {
    const table = entry.identityName;
    const record = sanitizeData(entry)

    return {
      insert: {
        table,
        record
      }
    }
  })
}

This example is simplified, I will have to make updates as well in case the ID already exists in the DB.

There is another use case in the project as well where I have a debouncer on a set of form inputs that process a dynamic set of transaction operations after the timer runs out to avoid constantly updating the DB as the user types.

Describe the solution you'd like

I'd like to be able to have proper types for my dynamic function based on the types that Xata already has on the client package.
Is it possible to expose the following types?

  1. TransactionOperation
  2. InsertTransactionOperation
  3. UpdateTransactionOperation
  4. DeleteTransactionOperation

Describe alternatives you've considered

In some parts of the project I am pretty much duplicating those and using specific record types:

type UpdateTransactionOperation<O extends XataRecord> = {
  id: string;
  fields: Partial<EditableData<O>>;
};

type TaskUpdateTransaction = UpdateTransactionOperation<TaskRecord>;

And in another instance I did infer from the parameter, which isn't very nice:

import { getXataClient } from "@/xata";

import type { CreateProjectResponse, ProjectWithEmployees } from "../types";

const xata = getXataClient();

type TransactionParameter = Parameters<typeof xata.transactions.run>[0][0];

Additional context

@SferaDev
Copy link
Member

Something like this would help, right?

9077d96

@SferaDev
Copy link
Member

Going to tag a release now with the change (release might take a few minutes).

Please update and let me know if we can help you with anything else 😉

@marlonmarcello
Copy link
Author

Yess! Thanks @SferaDev 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants