Skip to content

Commit

Permalink
improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
samu committed Nov 24, 2024
1 parent 7528a8a commit 114814b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/createClient/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { doFetch } from "./helpers/doFetch/doFetch";
import { parseBodyFromResponse } from "./helpers/parseBodyFromResponse/parseBodyFromResponse";
import type { Client } from "./helpers/types";

export type ClientOptions = {
export type ClientParams = {
baseUrl: string | null;
};

Expand All @@ -40,7 +40,7 @@ export function createClient<
>,
params: {
acceptHeader: MimeType;
globalOptions: ClientOptions;
clientParams: ClientParams;
}
): Client<
EndpointDeclaration,
Expand All @@ -59,7 +59,7 @@ export function createClient<
const pathString = buildPathString(props.params, path);
const queryString = buildQueryString(props.query);

const url = `${params.globalOptions.baseUrl}${pathString}${queryString}`;
const url = `${params.clientParams.baseUrl}${pathString}${queryString}`;

const fetchResult = await doFetch(
url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { z } from "zod";
import { ClientOptions, createClient } from "../createClient/createClient";
import { ClientParams, createClient } from "../createClient/createClient";
import { createPipeline } from "../createPipeline/createPipeline";
import type {
BasePipelineContext,
Expand Down Expand Up @@ -31,7 +31,7 @@ export function createValidatedEndpointFactory<
Pipeline<PrePipelineOut, PostPipelineOut>
]
) {
const globalOptions: ClientOptions = {
const clientParams: ClientParams = {
baseUrl: null,
};

Expand Down Expand Up @@ -102,7 +102,7 @@ export function createValidatedEndpointFactory<

const endpoint = createClient(routeDefinition, {
acceptHeader,
globalOptions,
clientParams,
}) as Endpoint<
PrePipelineIn,
PostPipelineOut,
Expand All @@ -119,8 +119,8 @@ export function createValidatedEndpointFactory<

return endpoint;
},
setGlobalClientOptions: (options: Partial<ClientOptions>) => {
Object.assign(globalOptions, options);
setGlobalClientParams: (partialClientParams: Partial<ClientParams>) => {
Object.assign(clientParams, partialClientParams);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ export const testPipeline = createValidatedEndpointFactory(
)
);

testPipeline.setGlobalClientOptions({ baseUrl: "https://some-test-domain.ch" });
testPipeline.setGlobalClientParams({ baseUrl: "https://some-test-domain.ch" });
7 changes: 3 additions & 4 deletions src/helpers/testHelpers/mockEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export function mockEndpoint<
ResB,
ResC
>,
// TODO params vs options
options?: { dontServe?: true; serveNotFound?: true }
params?: { dontServe?: true; serveNotFound?: true }
): Endpoint<
PipelineIn,
PipelineOut,
Expand All @@ -75,8 +74,8 @@ export function mockEndpoint<
} as Record<string, string>;

const handleRequest = createRequestHandler([
...(options?.dontServe ? [] : [endpoint]),
...(options?.serveNotFound ? [notFoundEndpoint] : []),
...(params?.dontServe ? [] : [endpoint]),
...(params?.serveNotFound ? [notFoundEndpoint] : []),
]);

const url = new URL(fullUrl as string);
Expand Down
6 changes: 3 additions & 3 deletions src/middlewares/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { getDefaultLogStatement } from "../helpers/getDefaultLogStatement";
import { Logger } from "../helpers/types";
import { FinalizeContext } from "./finalize/helpers/types";

export const logger = <PipelineContext extends FinalizeContext>(options?: {
export const logger = <PipelineContext extends FinalizeContext>(params?: {
logger?: Logger;
getLogStatement?: (context: FinalizeContext) => Promise<string>;
}): Middleware<PipelineContext, PipelineContext> => {
const logger = options?.logger ?? consoleLogger;
const getLogStatement = options?.getLogStatement ?? getDefaultLogStatement;
const logger = params?.logger ?? consoleLogger;
const getLogStatement = params?.getLogStatement ?? getDefaultLogStatement;

const middleware: Middleware<PipelineContext, PipelineContext> = async (
context
Expand Down

0 comments on commit 114814b

Please sign in to comment.