-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified new options, made optional properties of options required …
…during internal usage (to reflect defaults)
- Loading branch information
Showing
15 changed files
with
97 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,61 @@ | ||
// Part of the Prim+RPC project ( https://prim.doseofted.me/ ) | ||
// Copyright 2023 Ted Klingenberg | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { defu } from "defu" | ||
import { destr } from "destr" | ||
import type { UserProvidedServerOptions } from "./provided" | ||
import type { SetRequired } from "type-fest" | ||
|
||
const defaults = { | ||
transformHandler: { | ||
stringify: JSON.stringify, | ||
parse: destr, | ||
binary: false, | ||
mediaType: "application/json", | ||
}, | ||
handleErrors: { enabled: true, stackTrace: false }, | ||
resolverClient: null, | ||
resolverServer: null, | ||
} satisfies UserProvidedServerOptions | ||
|
||
type MergeOptions = Omit<UserProvidedServerOptions, keyof typeof defaults> | ||
|
||
export function createOptions(provided: UserProvidedServerOptions = {}) { | ||
const { | ||
transformHandler = defaults.transformHandler, | ||
handleErrors = defaults.handleErrors, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
resolverClient = defaults.resolverClient, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
resolverServer = defaults.resolverServer, | ||
...providedMerge | ||
} = provided | ||
const merged = defu<MergeOptions, MergeOptions[]>(providedMerge, { | ||
module: null, | ||
allowSchema: {}, | ||
allowedMethodsOnMethod: {}, | ||
batchTime: false, | ||
handleBlobs: true, | ||
handleForms: true, | ||
handlingDepth: 3, | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
return { ...merged, handleErrors, transformHandler, resolverClient, resolverServer } as InitializedOptions | ||
} | ||
|
||
/** Options utilized internally by client/server (some values will be set to defaults) */ | ||
export type InitializedOptions = SetRequired< | ||
UserProvidedServerOptions, | ||
| "transformHandler" | ||
| "handleErrors" | ||
| "module" | ||
| "allowSchema" | ||
| "allowedMethodsOnMethod" | ||
| "batchTime" | ||
| "handleBlobs" | ||
| "handleForms" | ||
| "handlingDepth" | ||
| "resolverClient" | ||
| "resolverServer" | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { send } from "process" | ||
import { UserProvidedClientOptions } from "../options/client/provided" | ||
import { UserProvidedServerOptions } from "../options/provided" | ||
import { ResolverServer } from "../resolver/types" | ||
|
||
export function createRpcServer<GivenOptions extends UserProvidedClientOptions = UserProvidedClientOptions>( | ||
options: GivenOptions | ||
export function createRpcServer<GivenOptions extends UserProvidedServerOptions = UserProvidedServerOptions>( | ||
_options: GivenOptions | ||
): ResolverServer { | ||
return () => null | ||
} |