Skip to content

Commit

Permalink
refactor: track input on context
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Oct 31, 2024
1 parent 82e0090 commit 8bf07bf
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
5 changes: 0 additions & 5 deletions src/layers/6_client/Settings/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { TransportHttp, TransportMemory } from '../../../requestPipeline/Tr
import type { GlobalRegistry } from '../../../types/GlobalRegistry/GlobalRegistry.js'
import type { SchemaDrivenDataMap } from '../../../types/SchemaDrivenDataMap/__.js'
import type { TransportHttpInput } from '../transportHttp/request.js'
import type { InputStatic } from './Input.js'

export type OutputChannel = 'throw' | 'return'

Expand Down Expand Up @@ -107,10 +106,6 @@ export interface TransportConfigMemory {
}

export type Config = {
/**
* The initial input that was given to derive this config.
*/
initialInput: InputStatic
name: GlobalRegistry.ClientNames // todo remove? it is in context
output: OutputConfig
schemaMap: SchemaDrivenDataMap | null
Expand Down
2 changes: 0 additions & 2 deletions src/layers/6_client/Settings/InputToConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { InputOutputEnvelopeLonghand, InputStatic, URLInput } from './Input

// dprint-ignore
export type NormalizeInput<$Input extends InputStatic> = {
initialInput: $Input
name: HandleName<$Input>
schemaMap: ConfigManager.OrDefault<$Input['schemaMap'], null>
transport: HandleTransport<$Input>
Expand Down Expand Up @@ -50,7 +49,6 @@ export const inputToConfig = <$Input extends InputStatic>(
const transport = handleTransport(input)

return {
initialInput: input,
// todo fixme: passes before generation
// eslint-disable-next-line
// @ts-ignore
Expand Down
8 changes: 5 additions & 3 deletions src/layers/6_client/chainExtensions/with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export interface With<$Args extends Chain.Extension.Parameters<With_>> {
// @ts-ignore Passes after generation
) => Chain.Definition.MaterializeWithNewContext<
$Args['chain'],
ConfigManager.SetAtPath<
ConfigManager.SetProperties<
$Args['context'],
['config'],
NormalizeInput<$Args['context']['config']['initialInput'] & $Input>
{
input: $Args['context']['input'] & $Input
config: NormalizeInput<$Args['context']['input'] & $Input>
}
>
>
}
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const create: Create = (input) => {
name: input.name ?? `default`, // todo import from shared constants
extensions: [],
scalars: Schema.Scalar.Registry.empty,
retry: null,
// retry: null,
input,
})
return createWithContext(initialContext)
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/clientPrefilled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createPrefilled: CreatePrefilled = (name, schemaMap, scalars, schem
name,
extensions: [],
scalars,
retry: null,
// retry: null,
input: {
schema: schemaUrl,
// eslint-disable-next-line
Expand Down
9 changes: 6 additions & 3 deletions src/layers/6_client/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Anyware } from '../../lib/anyware/__.js'
import type { RequestPipeline } from '../../requestPipeline/__.js'
// import type { Anyware } from '../../lib/anyware/__.js'
// import type { RequestPipeline } from '../../requestPipeline/__.js'
import type { Schema } from '../../types/Schema/__.js'
import type { Extension } from './extension/extension.js'
import type { Config } from './Settings/Config.js'
Expand All @@ -8,9 +8,12 @@ import { inputToConfig } from './Settings/InputToConfig.js'

export interface Context {
name: string
/**
* The initial input that was given to derive the config.
*/
input: InputStatic
config: Config
retry: Anyware.Extension2<RequestPipeline.Core, { retrying: true }> | null
// retry: Anyware.Extension2<RequestPipeline.Core, { retrying: true }> | null
extensions: Extension[]
scalars: Schema.Scalar.Registry
typeHooks: {
Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const gqlProperties = Chain.Extension.create<Gql_>((_, context) => {

const result = await RequestPipeline.anyware.run({
initialInput,
retryingExtension: context.retry as any,
// retryingExtension: context.retry as any,
extensions: context.extensions.filter(_ => _.onRequest !== undefined).map(_ => _.onRequest!) as any,
})

Expand Down
2 changes: 1 addition & 1 deletion src/layers/6_client/requestMethods/requestMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const executeDocument = async (

const result = await RequestPipeline.anyware.run({
initialInput,
retryingExtension: state.retry as any,
// retryingExtension: state.retry as any,
extensions: state.extensions.filter(_ => _.onRequest !== undefined).map(_ => _.onRequest!) as any,
})

Expand Down

0 comments on commit 8bf07bf

Please sign in to comment.