tryretool / retoolrpc

MIT License
6 stars 5 forks source link

feat: return function when registering #22

Closed KATT closed 8 months ago

KATT commented 8 months ago

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

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 commented 8 months ago

Change is live on 0.1.5