Skip to content

Commit

Permalink
fix(extension/throws): return client type
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Nov 20, 2024
1 parent 3e72e0a commit 65dfe4e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/extensions/Throws/Throws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 10 additions & 3 deletions src/extensions/Throws/Throws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ interface BuilderExtension_<$Args extends Builder.Extension.Parameters<BuilderEx
/**
* TODO
*/
// @ts-expect-error fixme
throws: () => 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' }
Expand Down
4 changes: 2 additions & 2 deletions src/lib/anyware/Overload/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Builder<
*/
extendInput: <$InputExtension extends object>() => Builder<
$RootContext,
ConfigManager.UpdateOneKey<$Context, 'input', $InputExtension>
ConfigManager.UpdateAtKey<$Context, 'input', $InputExtension>
>
/**
* TODO
Expand Down Expand Up @@ -53,7 +53,7 @@ interface BuilderStep<
},
): Builder<
$RootContext,
ConfigManager.UpdateOneKey<
ConfigManager.UpdateAtKey<
$Context,
'steps',
& $Context['steps']
Expand Down
6 changes: 3 additions & 3 deletions src/lib/anyware/Pipeline/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface Builder<$Context extends Context = Context> {
run?: $Runner
},
) => Builder<
ConfigManager.UpdateOneKey<
ConfigManager.UpdateAtKey<
$Context,
'steps',
[
Expand Down Expand Up @@ -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',
[
Expand Down Expand Up @@ -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',
[
Expand Down
18 changes: 9 additions & 9 deletions src/lib/config-manager/ConfigManager.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ assertEqual<

// dprint-ignore
{
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, [], { a2: 2 }> , { a: { b: 2 }; a2: 2 }>()
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, ['a'], { b: 3 }> , { a: { b: 3 } }>()
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, ['a', 'b'], 3> , { a: { b: 3 } }>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, [], { a2: 2 }> , { a: { b: 2 }; a2: 2 }>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, ['a'], { b: 3 }> , { a: { b: 3 } }>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, ['a', 'b'], 3> , { a: { b: 3 } }>()
// never
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, [], 1> , never>()
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, ['x'], 1> , never>()
assertEqual<ConfigManager.SetOne<{ a: { b: 2 } }, ['a', 'b', 'c'], 3> , { a: { b: never } }>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, [], 1> , never>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, ['x'], 1> , never>()
assertEqual<ConfigManager.SetAtKeyPath<{ a: { b: 2 } }, ['a', 'b', 'c'], 3> , { a: { b: never } }>()

assertEqual<ConfigManager.UpdateOneKey<a1, 'a', { b: 2 }> , { a: { b: 2 }; b: string }>()
assertEqual<ConfigManager.UpdateOneKey<{ a?: number }, 'a', 1> , { a: 1 }>()
assertEqual<ConfigManager.UpdateOneKey<{ a?: number; b?: number }, 'a', 1> , { a: 1; b?: number }>()
assertEqual<ConfigManager.UpdateAtKey<a1, 'a', { b: 2 }> , { a: { b: 2 }; b: string }>()
assertEqual<ConfigManager.UpdateAtKey<{ a?: number }, 'a', 1> , { a: 1 }>()
assertEqual<ConfigManager.UpdateAtKey<{ a?: number; b?: number }, 'a', 1> , { a: 1; b?: number }>()

assertEqual<ConfigManager.SetAtPath<a1, [], 9> , a1>()
assertEqual<ConfigManager.SetAtPath<a1, ['a'], { b: 2 }> , { a: { b: 2 }; b: string }>()
Expand Down
10 changes: 5 additions & 5 deletions src/lib/config-manager/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[_]
}
Expand All @@ -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
Expand Down

0 comments on commit 65dfe4e

Please sign in to comment.