Skip to content

Commit 552f346

Browse files
committed
refactor: only track name on ctx
1 parent 8bf07bf commit 552f346

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

src/layers/6_client/Settings/Config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { GraphQLSchema } from 'graphql'
22
import type { RequireProperties } from '../../../lib/prelude.js'
33
import type { TransportHttp, TransportMemory } from '../../../requestPipeline/Transport.js'
4-
import type { GlobalRegistry } from '../../../types/GlobalRegistry/GlobalRegistry.js'
54
import type { SchemaDrivenDataMap } from '../../../types/SchemaDrivenDataMap/__.js'
65
import type { TransportHttpInput } from '../transportHttp/request.js'
76

@@ -106,7 +105,6 @@ export interface TransportConfigMemory {
106105
}
107106

108107
export type Config = {
109-
name: GlobalRegistry.ClientNames // todo remove? it is in context
110108
output: OutputConfig
111109
schemaMap: SchemaDrivenDataMap | null
112110
transport: TransportConfigHttp | TransportConfigMemory

src/layers/6_client/Settings/InputToConfig.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { InputOutputEnvelopeLonghand, InputStatic, URLInput } from './Input
88

99
// dprint-ignore
1010
export type NormalizeInput<$Input extends InputStatic> = {
11-
name: HandleName<$Input>
1211
schemaMap: ConfigManager.OrDefault<$Input['schemaMap'], null>
1312
transport: HandleTransport<$Input>
1413
output: {
@@ -49,10 +48,6 @@ export const inputToConfig = <$Input extends InputStatic>(
4948
const transport = handleTransport(input)
5049

5150
return {
52-
// todo fixme: passes before generation
53-
// eslint-disable-next-line
54-
// @ts-ignore
55-
name: input.name ?? defaultSchemaName,
5651
transport,
5752
schemaMap: input.schemaMap ?? null as any,
5853
output: {
@@ -86,9 +81,6 @@ export const inputToConfig = <$Input extends InputStatic>(
8681
}
8782
}
8883

89-
type HandleName<$Input extends InputStatic> = $Input['name'] extends string ? $Input['name']
90-
: GlobalRegistry.DefaultClientName
91-
9284
// dprint-ignore
9385
type HandleTransport<$Input extends InputStatic> =
9486
$Input['schema'] extends URLInput ? TransportConfigHttp :

src/layers/6_client/Settings/inputIncrementable/inputIncrementable.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Transport, TransportMemory } from '../../../../requestPipeline/Transport.js'
2-
import type { GlobalRegistry } from '../../../../types/GlobalRegistry/GlobalRegistry.js'
32
import type { TransportHttpInput } from '../../transportHttp/request.js'
43
import type { OutputInput } from './output.js'
54

@@ -18,7 +17,6 @@ export type WithInput<$Context extends IncrementableInputContext = Incrementable
1817
)
1918

2019
export type IncrementableInputContext = {
21-
name: GlobalRegistry.ClientNames
2220
transport: {
2321
type: Transport
2422
}

src/layers/6_client/client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { defaultName } from '../../generator/config/defaults.js'
12
import type { Chain } from '../../lib/chain/__.js'
23
import { proxyGet } from '../../lib/prelude.js'
4+
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
35
import { Schema } from '../../types/Schema/__.js'
46
import { type Anyware_, AnywareExtension } from './chainExtensions/anyware.js'
57
import type { Internal_ } from './chainExtensions/internal.js'
@@ -34,7 +36,7 @@ type Create = <$Input extends InputStatic>(input: $Input) =>
3436
// eslint-disable-next-line
3537
// @ts-ignore
3638
Client<{
37-
name: $Input['name']
39+
name: HandleName<$Input>
3840
input: $Input
3941
config: NormalizeInput<$Input>
4042
retry: null
@@ -45,7 +47,7 @@ type Create = <$Input extends InputStatic>(input: $Input) =>
4547

4648
export const create: Create = (input) => {
4749
const initialContext = createContext({
48-
name: input.name ?? `default`, // todo import from shared constants
50+
name: input.name ?? defaultName,
4951
extensions: [],
5052
scalars: Schema.Scalar.Registry.empty,
5153
// retry: null,
@@ -93,3 +95,6 @@ export const createWithContext = (
9395

9496
return clientProxy
9597
}
98+
99+
type HandleName<$Input extends InputStatic> = $Input['name'] extends string ? $Input['name']
100+
: GlobalRegistry.DefaultClientName

src/layers/6_client/clientPrefilled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type CreatePrefilled = <
5656
// @ts-ignore passes after generation
5757
Client<{
5858
name: $Name
59-
input: $Input & { name: $Name; schemaMap: SchemaDrivenDataMap }
59+
input: $Input & { schemaMap: SchemaDrivenDataMap }
6060
retry: null
6161
scalars: $Scalars
6262
extensions: []

src/layers/6_client/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface Context {
1616
// retry: Anyware.Extension2<RequestPipeline.Core, { retrying: true }> | null
1717
extensions: Extension[]
1818
scalars: Schema.Scalar.Registry
19+
/**
20+
* Type level augmentations.
21+
*
22+
* @remarks Typically added by extensions. Added here upon use for optimized type-level reads later on.
23+
*/
1924
typeHooks: {
2025
onRequestResult: Extension.Hooks.OnRequestResult[]
2126
onRequestDocumentRootType: Extension.Hooks.OnRequestDocumentRootType[]

src/layers/6_client/handleOutput.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ type HandleOutput_Extensions<$Context extends Context, $Envelope extends Graffle
140140
// @ts-ignore fixme
141141
RunTypeHookOnRequestResult<$Context, {
142142
result: $Envelope
143-
registeredSchema: GlobalRegistry.GetOrDefault<$Context['config']['name']>
143+
// eslint-disable-next-line
144+
// @ts-ignore fixme
145+
registeredSchema: GlobalRegistry.GetOrDefault<$Context['name']>
144146
}>['result']
145147
>
146148

src/layers/6_client/requestMethods/requestMethods.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ export type RequestMethods<$Arguments extends Chain.Extension.Parameters<Request
2727
// GlobalRegistry.Has<$Context['name']> extends false
2828
// eslint-disable-next-line
2929
// @ts-ignore passes after generation
30-
GlobalRegistry.Has<$Arguments['context']['config']['name']> extends false
30+
GlobalRegistry.Has<$Arguments['context']['name']> extends false
3131
? {}
3232
:
3333
(
3434
// eslint-disable-next-line
3535
// @ts-ignore Passes after generation
36-
& TypeFunction.Call<GlobalRegistry.GetOrDefault<$Arguments['context']['config']['name']>['interfaces']['Root'], $Arguments['context']>
36+
& TypeFunction.Call<GlobalRegistry.GetOrDefault<$Arguments['context']['name']>['interfaces']['Root'], $Arguments['context']>
3737
& {
3838
// eslint-disable-next-line
3939
// @ts-ignore Passes after generation
40-
document: TypeFunction.Call<GlobalRegistry.GetOrDefault<$Arguments['context']['config']['name']>['interfaces']['Document'], $Arguments['context']>
40+
document: TypeFunction.Call<GlobalRegistry.GetOrDefault<$Arguments['context']['name']>['interfaces']['Document'], $Arguments['context']>
4141
}
4242
)
4343
)

src/requestPipeline/CustomScalars/decode.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const withBatch: TestCaseWith = [
2626
{},
2727
async ([_, query, responseData, expectedData], { fetch, kitchenSinkHttp: kitchenSink }) => {
2828
fetch.mockResolvedValueOnce(createResponse({ data: responseData }))
29+
kitchenSink._.name
2930
expect(await kitchenSink.scalar(DateScalar).query.$batch(query)).toEqual(expectedData)
3031
},
3132
]

tests/_/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ interface Fixtures {
3737
fetch: Mock<(request: Request) => Promise<Response>>
3838
pokemonService: SchemaService
3939
graffle: Client<Context>
40-
kitchenSink: Client<ConfigManager.SetAtPath<Context, ['config', 'name'], 'default'>>
41-
kitchenSinkHttp: Client<ConfigManager.SetAtPath<Context, ['config', 'name'], 'default'>>
40+
kitchenSink: Client<ConfigManager.SetAtPath<Context, ['name'], 'default'>>
41+
kitchenSinkHttp: Client<ConfigManager.SetAtPath<Context, ['name'], 'default'>>
4242
kitchenSinkData: typeof db
4343
project: Project
4444
}

0 commit comments

Comments
 (0)