feat(typescript): defaults, literals redesign
Description
Redesigns default request parameter values (enabled with useDefaultRequestParameterValues: true) and inlined literals that are removed for the user's convenience. Both of these are serialized back in to the request just before it's sent to the server by the client code, so we wanted to place the functionality for these in the same place; we elected to put it in the request wrapper file, where its purpose could easily be ascertained by potentially confused customers who might be wondering where their literals went during generation.
I.e., a request file will look something like:
// This file was auto-generated by Fern from our API Definition.
import type * as SeedLiteral from "../../../../index.js";
/**
* @example
* {
* temperature: 10.1,
* context: "You're super wise",
* maybeContext: "You're super wise",
* objectWithLiteral: {
* nestedLiteral: {
* myLiteral: "How super cool"
* }
* },
* query: "What is the weather today"
* }
*/
export interface SendLiteralsInlinedRequest {
context?: "You're super wise";
query: string;
temperature?: number;
maybeContext?: SeedLiteral.SomeAliasedLiteral;
objectWithLiteral: SeedLiteral.ATopLevelLiteral;
defaultDemo?: string;
defaultDemo2?: string;
}
// Not exported
const DEFAULTS = {
defaultDemo: "GOT'EM",
defaultDemo2: "GOT'EM2",
} as const;
type DefaultsKeys = keyof typeof DEFAULTS;
type DefaultsValues = typeof DEFAULTS[DefaultsKeys];
// Not exported
const LITERALS = {
prompt: "You are a helpful assistant",
stream: false,
aliasedContext: "You're super wise",
} as const;
export namespace SendLiteralsInlinedRequest {
export type WithDefaults = SendLiteralsInlinedRequest;
export function withDefaults(request: SendLiteralsInlinedRequest): WithDefaults{
return { ...DEFAULTS, ...LITERALS, request };
}
}
Then in the client, defaults and literals are always applied via SendLiteralsInlinedRequest.withDefaults(request).
Changes Made
More changes than I would have thought to remove the old code, clean up the existing code (useRequestParameterDefaultValues and useBigInt are passed around more liberally in the codebase to allow them to be read easier), and set up the structure for the new request wrapper style in GeneratedRequestWrapperImpl.ts.
Testing
Changed request-parameters:use-default-request-parameter-values fixture slightly to test both DEFAULTS and LITERALS showing up; otherwise, seed regenerating now!
- [X] Unit tests added/updated
- [X] Manual testing completed