diff --git a/src/extensions/Throws/Throws.test.ts b/src/extensions/Throws/Throws.test.ts index 272e1959..be01474c 100644 --- a/src/extensions/Throws/Throws.test.ts +++ b/src/extensions/Throws/Throws.test.ts @@ -4,7 +4,8 @@ import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js' import { schema } from '../../../tests/_/schemas/kitchen-sink/schema.js' import { Throws } from './Throws.js' -const graffle = Graffle.create({ schema }).use(Throws()).throws() +const graffle = Graffle.create({ schema }).use(Throws()).with({ output: { errors: { execution: `return` } } }).throws() + .throws() test(`.gql() throws if errors array non-empty`, async () => { await expect(graffle.gql`query { foo }`.send()).rejects.toMatchInlineSnapshot( diff --git a/src/extensions/Throws/Throws.ts b/src/extensions/Throws/Throws.ts index 3b76cdba..6473ff0d 100644 --- a/src/extensions/Throws/Throws.ts +++ b/src/extensions/Throws/Throws.ts @@ -38,11 +38,18 @@ interface BuilderExtension_<$Args extends Builder.Extension.Parameters IncrementWthNewConfig<$Args, ThrowsifyConfig<$Args['context']['config']>> + throws: () => Builder.Definition.MaterializeWithNewContext< + $Args['chain'], + ConfigManager.UpdateAtKey< + $Args['context'], + 'config', + // @ts-expect-error fixme + ThrowsifyConfig<$Args['context']['config']> + > + > } -type ThrowsifyConfig<$BuilderConfig extends BuilderConfig> = ConfigManager.SetOne< +type ThrowsifyConfig<$BuilderConfig extends BuilderConfig> = ConfigManager.SetAtKeyPath< $BuilderConfig, ['output', 'errors'], { other: 'throw'; execution: 'throw' } diff --git a/src/lib/anyware/Overload/Builder.ts b/src/lib/anyware/Overload/Builder.ts index e4628494..ae1d465b 100644 --- a/src/lib/anyware/Overload/Builder.ts +++ b/src/lib/anyware/Overload/Builder.ts @@ -17,7 +17,7 @@ export interface Builder< */ extendInput: <$InputExtension extends object>() => Builder< $RootContext, - ConfigManager.UpdateOneKey<$Context, 'input', $InputExtension> + ConfigManager.UpdateAtKey<$Context, 'input', $InputExtension> > /** * TODO @@ -53,7 +53,7 @@ interface BuilderStep< }, ): Builder< $RootContext, - ConfigManager.UpdateOneKey< + ConfigManager.UpdateAtKey< $Context, 'steps', & $Context['steps'] diff --git a/src/lib/anyware/Pipeline/builder.ts b/src/lib/anyware/Pipeline/builder.ts index 81caf469..c9c8cf25 100644 --- a/src/lib/anyware/Pipeline/builder.ts +++ b/src/lib/anyware/Pipeline/builder.ts @@ -73,7 +73,7 @@ export interface Builder<$Context extends Context = Context> { run?: $Runner }, ) => Builder< - ConfigManager.UpdateOneKey< + ConfigManager.UpdateAtKey< $Context, 'steps', [ @@ -134,7 +134,7 @@ interface BuilderStep<$Context extends Context> { run?: (input: $Input, slots: $Slots, previous: GetNextStepParameterPrevious<$Context>) => $Output }, ): Builder< - ConfigManager.UpdateOneKey< + ConfigManager.UpdateAtKey< $Context, 'steps', [ @@ -162,7 +162,7 @@ interface BuilderStep<$Context extends Context> { run?: (input: $Input, slots: $Slots, previous: GetNextStepParameterPrevious<$Context>) => $Output }, ): Builder< - ConfigManager.UpdateOneKey< + ConfigManager.UpdateAtKey< $Context, 'steps', [ diff --git a/src/lib/config-manager/ConfigManager.test-d.ts b/src/lib/config-manager/ConfigManager.test-d.ts index 56a3460a..b975f6f3 100644 --- a/src/lib/config-manager/ConfigManager.test-d.ts +++ b/src/lib/config-manager/ConfigManager.test-d.ts @@ -24,17 +24,17 @@ assertEqual< // dprint-ignore { -assertEqual , { a: { b: 2 }; a2: 2 }>() -assertEqual , { a: { b: 3 } }>() -assertEqual , { a: { b: 3 } }>() +assertEqual , { a: { b: 2 }; a2: 2 }>() +assertEqual , { a: { b: 3 } }>() +assertEqual , { a: { b: 3 } }>() // never -assertEqual , never>() -assertEqual , never>() -assertEqual , { a: { b: never } }>() +assertEqual , never>() +assertEqual , never>() +assertEqual , { a: { b: never } }>() -assertEqual , { a: { b: 2 }; b: string }>() -assertEqual , { a: 1 }>() -assertEqual , { a: 1; b?: number }>() +assertEqual , { a: { b: 2 }; b: string }>() +assertEqual , { a: 1 }>() +assertEqual , { a: 1; b?: number }>() assertEqual , a1>() assertEqual , { a: { b: 2 }; b: string }>() diff --git a/src/lib/config-manager/ConfigManager.ts b/src/lib/config-manager/ConfigManager.ts index 88c6bead..3640077b 100644 --- a/src/lib/config-manager/ConfigManager.ts +++ b/src/lib/config-manager/ConfigManager.ts @@ -150,20 +150,20 @@ export type SetProperties<$Object1 extends object, $Object2 extends object> = export type SetMany<$Obj extends object, $Sets extends [Path, any][]> = $Sets extends [] ? $Obj : $Sets extends [infer $Set extends [Path, any], ...infer $SetRest extends [Path, any][]] ? SetMany< - SetOne<$Obj, $Set[0], $Set[1]>, + SetAtKeyPath<$Obj, $Set[0], $Set[1]>, $SetRest > : never export type AppendAtKey<$Obj extends object, $Prop extends keyof $Obj, $Type> = // @ts-expect-error - UpdateOneKey<$Obj, $Prop, [...$Obj[$Prop], $Type]> + UpdateAtKey<$Obj, $Prop, [...$Obj[$Prop], $Type]> export type AppendManyAtKey<$Obj extends object, $Prop extends keyof $Obj, $Type extends any[]> = // @ts-expect-error - UpdateOneKey<$Obj, $Prop, [...$Obj[$Prop], ...$Type]> + UpdateAtKey<$Obj, $Prop, [...$Obj[$Prop], ...$Type]> -export type UpdateOneKey<$Obj extends object, $Prop extends keyof $Obj, $Type extends $Obj[$Prop]> = +export type UpdateAtKey<$Obj extends object, $Prop extends keyof $Obj, $Type extends $Obj[$Prop]> = & { [_ in keyof $Obj as _ extends $Prop ? never : _]: $Obj[_] } @@ -172,7 +172,7 @@ export type UpdateOneKey<$Obj extends object, $Prop extends keyof $Obj, $Type ex } // dprint-ignore -export type SetOne<$Obj extends object, $Path extends Path, $Value> = +export type SetAtKeyPath<$Obj extends object, $Path extends Path, $Value> = Simplify< $Path extends [] ? $Value extends object