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

feat: return function when registering #22

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

KATT
Copy link
Contributor

@KATT KATT commented Mar 14, 2024

Closes #24

Why

When testing RPC function it's useful to be able to call them directly with the implementation

Example

// retool.ts

// [...]

const rpc = new RetoolRPC({
  // [...]
});

export const helloWorld = rpc.register({
  name: 'helloWorld',
  arguments: {
    name: { type: 'string', description: 'Your name', required: true },
  },
  implementation: async (args, context) => {
    return {
      message: `Hello ${args.name}`,
      context,
    };
  },
});
// retool.test.ts
import { helloWorld } from './retool';

test('helloWorld', async () => {
  const result = await helloWorld(
    {
      name: 'world',
    },
    {
      // ... context
    },
  );
  expect(result.message).toBe(`Hello world`);
});

What this does

  • Adds the ability to infer the return type of the registered function
  • Returns the function so it can be called directly

Alternatives / workarounds

It's possible to work around, but it's a bit annoying, it's nicer if the SDK could just return the function implementation

@huytool157 huytool157 merged commit b772151 into tryretool:main Mar 16, 2024
2 checks passed
@huytool157
Copy link
Collaborator

Change is live on 0.1.5

@KATT KATT deleted the feat/return-fn branch March 16, 2024 22:07
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.

Return implementation when registering function to make tests easier
2 participants