Skip to content

Commit

Permalink
refactor: extract prefilled to own module
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Aug 4, 2024
1 parent 4964979 commit e5fc3f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/entrypoints/alpha/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { create as createSelect, select } from '../../layers/5_select/select.js'
export { type Client, create, createPrefilled } from '../../layers/6_client/client.js'
export { type Input, type InputPrefilled } from '../../layers/6_client/Settings/Input.js'
export { type Client, create } from '../../layers/6_client/client.js'
export { createPrefilled, type InputPrefilled } from '../../layers/6_client/prefilled.js'
export { type Input } from '../../layers/6_client/Settings/Input.js'
4 changes: 1 addition & 3 deletions src/layers/6_client/Settings/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Schema } from '../../1_Schema/__.js'
import type { GlobalRegistry } from '../../2_generator/globalRegistry.js'
import type { TransportHttp, TransportMemory } from '../../5_core/types.js'
import { Transport } from '../../5_core/types.js'
import type { InputPrefilled } from '../prefilled.js'
import { type OutputChannel, type OutputChannelConfig, outputConfigDefault } from './Config.js'

export type InputOutputEnvelopeLonghand = {
Expand Down Expand Up @@ -179,6 +180,3 @@ const inferTransport = <T extends Input<any>>(input: T): InferTransport<T> => {
// @ts-expect-error conditional type
return input.schema instanceof URL || typeof input.schema === `string` ? Transport.http : Transport.memory
}

export type InputPrefilled<$Schema extends GlobalRegistry.SchemaList> = $Schema extends any ? (InputRaw<$Schema>)
: never
26 changes: 1 addition & 25 deletions src/layers/6_client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Anyware } from '../../lib/anyware/__.js'
import { Errors } from '../../lib/errors/__.js'
import type { SomeExecutionResultWithoutErrors } from '../../lib/graphql.js'
import { isOperationTypeName, operationTypeNameToRootTypeName, type RootTypeName } from '../../lib/graphql.js'
import type { Exact } from '../../lib/prelude.js'
import { isPlainObject } from '../../lib/prelude.js'
import type { URLInput } from '../0_functions/request.js'
import type { BaseInput } from '../0_functions/types.js'
Expand All @@ -24,7 +23,7 @@ import {
traditionalGraphqlOutput,
traditionalGraphqlOutputThrowing,
} from './Settings/Config.js'
import { type Input, type InputPrefilled, type InputToConfig, inputToConfig } from './Settings/Input.js'
import { type Input, type InputToConfig, inputToConfig } from './Settings/Input.js'

export type SchemaInput = URLInput | GraphQLSchema

Expand Down Expand Up @@ -105,29 +104,6 @@ export type ClientTyped<$Index extends Schema.Index, $Config extends Config> =
}
& GetRootTypeMethods<$Config, $Index>

// dprint-ignore
export type CreatePrefilled = <$Name extends GlobalRegistry.SchemaNames>(name: $Name, schemaIndex: Schema.Index) => <
// eslint-disable-next-line
// @ts-ignore passes after generation
$Input extends InputPrefilled<GlobalRegistry.Schemas[$Name]>,
>(
// eslint-disable-next-line
// @ts-ignore passes after generation
input: Exact<$Input, InputPrefilled<GlobalRegistry.Schemas[$Name]>>,
) =>
Client<
// eslint-disable-next-line
// @ts-ignore passes after generation
GlobalRegistry.GetSchemaIndexOrDefault<$Name>,
InputToConfig<$Input>
>

export const createPrefilled: CreatePrefilled = (name, schemaIndex) => {
// eslint-disable-next-line
// @ts-ignore passes after generation
return (input) => create({ ...input, name, schemaIndex }) as any
}

// dprint-ignore
type Create = <
$Input extends Input<GlobalRegistry.SchemaList>,
Expand Down

0 comments on commit e5fc3f2

Please # to comment.