Skip to content

Commit

Permalink
feat: rename options constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
dextertanyj committed Aug 21, 2023
1 parent 7e24451 commit 0dc47a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const client = createClient<AppRouter>("http://localhost:3000/api/trpc/", superj
Both `query` and `mutate` accept an optional argument to provide request parameters such as custom headers or cookies.

```typescript
import { options as createOptions } from "k6-trpc";
import { createOptions } from "k6-trpc";

const response = client.healthcheck.query(
createOptions({
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ require("https://jslib.k6.io/url/1.0.0/index.js");
const NONE = Symbol();
const OPTION = Symbol();

export function options(options: Omit<Params, "responseCallback">) {
export const createOptions = (options: Omit<Params, "responseCallback">) => {
return { [OPTION]: "OPTION", ...options };
}
};

type RouterKeys<T extends AnyRouter> = Exclude<keyof T, keyof AnyRouter>;

Expand All @@ -36,14 +36,14 @@ type Handler<R extends AnyRouter, K extends keyof R> = R[K] extends AnyRouter
? T extends "query"
? {
query: I extends typeof NONE
? (opts?: ReturnType<typeof options>) => ReturnType<typeof get>
: (input: I, opts?: ReturnType<typeof options>) => ReturnType<typeof get>;
? (opts?: ReturnType<typeof createOptions>) => ReturnType<typeof get>
: (input: I, opts?: ReturnType<typeof createOptions>) => ReturnType<typeof get>;
}
: T extends "mutation"
? {
mutate: I extends typeof NONE
? (opts?: ReturnType<typeof options>) => ReturnType<typeof post>
: (input: I, opts?: ReturnType<typeof options>) => ReturnType<typeof post>;
? (opts?: ReturnType<typeof createOptions>) => ReturnType<typeof post>
: (input: I, opts?: ReturnType<typeof createOptions>) => ReturnType<typeof post>;
}
: never
: never
Expand All @@ -60,7 +60,7 @@ const isCombinedDataTransformer = (
return Object.prototype.hasOwnProperty.call(transformer, "input");
};

const isOptions = (opts: unknown): opts is ReturnType<typeof options> => {
const isOptions = (opts: unknown): opts is ReturnType<typeof createOptions> => {
return (
typeof opts === "object" && opts !== null && Object.prototype.hasOwnProperty.call(opts, OPTION)
);
Expand All @@ -72,7 +72,7 @@ const createFunctionHandler = (
transformer: CombinedDataTransformer | DataTransformer,
) => {
return (...args: unknown[]) => {
let opts: ReturnType<typeof options> | undefined;
let opts: ReturnType<typeof createOptions> | undefined;
let input: unknown = NONE;

if (args.length === 2) {
Expand Down

0 comments on commit 0dc47a8

Please sign in to comment.