Skip to content

Commit

Permalink
refactor: anyware pipeline namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Nov 4, 2024
1 parent 24c38cf commit 3ffea92
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/lib/anyware/Interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Deferred, MaybePromise } from '../prelude.js'
import type { Private } from '../private.js'
import type { InferPublicHooks, SomePublicHookEnvelope } from './hook/public.js'
import type { Pipeline } from './Pipeline.js'
import type { Pipeline } from './Pipeline/Pipeline.js'

export type InterceptorOptions = {
retrying: boolean
Expand Down
46 changes: 0 additions & 46 deletions src/lib/anyware/Pipeline.ts

This file was deleted.

38 changes: 38 additions & 0 deletions src/lib/anyware/Pipeline/Pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { FindValueAfter, IsLastValue } from '../../prelude.js'
import type { Private } from '../../private.js'
import type { HookDefinitionMap, HookSequence } from '../hook/definition.js'
import type { HookPrivateInput, HookResultError, PrivateHook } from '../hook/private.js'
export * as Pipeline from './builder.js'

// dprint-ignore
export type Pipeline<
$HookSequence extends HookSequence = HookSequence,
$HookMap extends HookDefinitionMap<$HookSequence> = HookDefinitionMap<$HookSequence>,
$Result = unknown,
> =
// todo what is the point of private here? Its usually for hiding fields on a user facing interface. But is this type actually user facing?
Private.Add<
{
hookSequence: $HookSequence
hookMap: $HookMap
result: $Result
},
{
hookNamesOrderedBySequence: $HookSequence
hooks: {
[$HookName in $HookSequence[number]]:
PrivateHook<
$HookMap[$HookName]['slots'],
HookPrivateInput<
$HookMap[$HookName]['input'],
$HookMap[$HookName]['slots']
>,
IsLastValue<$HookName, $HookSequence> extends true
? $Result
: $HookMap[FindValueAfter<$HookName, $HookSequence>]
>
}
passthroughErrorInstanceOf?: Function[]
passthroughErrorWith?: (signal: HookResultError) => boolean
}
>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type FindValueAfter, type IsLastValue, type MaybePromise } from '../prelude.js'
import type { HookDefinitionMap, HookSequence } from './hook/definition.js'
import type { HookResultError, InferPrivateHookInput } from './hook/private.js'
import { type FindValueAfter, type IsLastValue, type MaybePromise } from '../../prelude.js'
import type { HookDefinitionMap, HookSequence } from '../hook/definition.js'
import type { HookResultError, InferPrivateHookInput } from '../hook/private.js'
import { createRunner, type Runner } from '../run/runner.js'
import type { Pipeline } from './Pipeline.js'
import { createRunner, type Runner } from './run/runner.js'

export { type HookDefinitionMap } from './hook/definition.js'
export { type HookDefinitionMap } from '../hook/definition.js'

export type PipelineInput<
$HookSequence extends HookSequence = HookSequence,
Expand Down Expand Up @@ -79,7 +79,5 @@ export const create = <

export type Builder<$Pipeline extends Pipeline> = {
pipeline: $Pipeline
// todo
// use:
run: Runner<$Pipeline>
}
4 changes: 2 additions & 2 deletions src/lib/anyware/_.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './builder.js'
export * from './Interceptor.js'
export * from './Pipeline.js'
export * from './Pipeline/builder.js'
export * from './Pipeline/Pipeline.js'
export * from './run/runner.js'
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/anyware/run/runHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { casesExhausted, createDeferred, debugSub, errorFromMaybeError } from '.
import type { HookResult, HookResultErrorAsync, Slots } from '../hook/private.js'
import { createPublicHook, type SomePublicHookEnvelope } from '../hook/public.js'
import type { InterceptorGeneric } from '../Interceptor.js'
import type { Pipeline } from '../Pipeline.js'
import type { Pipeline } from '../Pipeline/Pipeline.js'
import type { ResultEnvelop } from './resultEnvelope.js'

type HookDoneResolver = (input: HookResult) => void
Expand Down
2 changes: 1 addition & 1 deletion src/lib/anyware/run/runPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContextualError } from '../../errors/ContextualError.js'
import { casesExhausted, createDeferred, debug } from '../../prelude.js'
import type { HookResult, HookResultErrorAsync } from '../hook/private.js'
import type { InterceptorGeneric } from '../Interceptor.js'
import type { Pipeline } from '../Pipeline.js'
import type { Pipeline } from '../Pipeline/Pipeline.js'
import { createResultEnvelope } from './resultEnvelope.js'
import type { ResultEnvelop } from './resultEnvelope.js'
import { runHook } from './runHook.js'
Expand Down
2 changes: 1 addition & 1 deletion src/lib/anyware/run/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { HookName } from '../hook/definition.js'
import type { HookResultErrorExtension } from '../hook/private.js'
import type { SomePublicHookEnvelope } from '../hook/public.js'
import { createRetryingInterceptor, type Interceptor, type InterceptorInput } from '../Interceptor.js'
import type { Pipeline } from '../Pipeline.js'
import type { Pipeline } from '../Pipeline/Pipeline.js'
import { getEntrypoint } from './getEntrypoint.js'
import { runPipeline } from './runPipeline.js'

Expand Down
26 changes: 13 additions & 13 deletions src/lib/builder/Definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export type AddExtension<$Chain_ extends Definition_, $Extension_ extends Extens
export type MaterializeGeneric<$Chain_ extends Definition_> =
Simplify<
Private.Add<
mergeArrayOfObjects<
MaterializeExtensionsGeneric<$Chain_, $Chain_['extensions']>
>,
{
chain: $Chain_,
context: mergeArrayOfObjects<
MaterializeExtensionsGenericContext<$Chain_['extensions']>
>
}
},
mergeArrayOfObjects<
MaterializeExtensionsGeneric<$Chain_, $Chain_['extensions']>
>
>
>

Expand All @@ -81,15 +81,15 @@ type MaterializeExtensionsGenericContext<$Extensions extends [...Extension[]]> =
export type MaterializeSpecific<$Chain_ extends Definition_> =
Simplify<
Private.Add<
mergeArrayOfObjects<
MaterializeExtensionsInitial<$Chain_, $Chain_['extensions']>
>,
{
chain: $Chain_,
context: mergeArrayOfObjects<
MaterializeExtensionsInitialContext<$Chain_['extensions']>
>
}
},
mergeArrayOfObjects<
MaterializeExtensionsInitial<$Chain_, $Chain_['extensions']>
>
>
>

Expand All @@ -109,17 +109,17 @@ type MaterializeExtensionsInitialContext<$Extensions extends [...Extension[]]> =
export type MaterializeWithNewContext<$Chain_ extends Definition_, $Context extends Context> =
// Simplify<
Private.Add<
{
chain: $Chain_,
context: $Context
},
mergeArrayOfObjects<
MaterializeExtensionsWithNewState<
$Chain_,
$Context,
$Chain_['extensions']
>
>,
{
chain: $Chain_,
context: $Context
}
>
>
// >

Expand Down
6 changes: 3 additions & 3 deletions src/lib/builder/__.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Builder } from './__.js'
type B = Builder.Definition.AddExtension<Builder.Definition.Empty, ex1_>
assertEqual<B['extensions'], [ex1_]>()
type b = Builder.Definition.MaterializeSpecific<B>
assertEqual<b, Private.Add<{ a: 1 }, { chain: B; context: {} }>>()
assertEqual<b, Private.Add<{ chain: B; context: {} }, { a: 1 }>>()
}
// ---------------------------------------------------------------------------------------------------------------------
{
Expand All @@ -24,7 +24,7 @@ import type { Builder } from './__.js'
type B = Builder.Definition.AddExtensions<Builder.Definition.Empty, [ex1_]>
assertEqual<B['extensions'], [ex1_]>()
type b = Builder.Definition.MaterializeSpecific<B>
assertEqual<b, Private.Add<{ a: 1 }, { chain: B; context: {} }>>()
assertEqual<b, Private.Add<{ chain: B; context: {} }, { a: 1 }>>()
}
// ---------------------------------------------------------------------------------------------------------------------
{
Expand All @@ -37,7 +37,7 @@ import type { Builder } from './__.js'
}
type B = Builder.Definition.AddExtension<Builder.Definition.Empty, Reflect_>
type b = Builder.Definition.MaterializeSpecific<B>
assertEqual<b, Private.Add<{ reflect: 'context' | 'chain' }, { chain: B; context: {} }>>()
assertEqual<b, Private.Add<{ chain: B; context: {} }, { reflect: 'context' | 'chain' }>>()
}
// ---------------------------------------------------------------------------------------------------------------------
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export namespace Private {
*
* The given data will be added to the type under a symbol that is private to this library.
*/
export type Add<$Type extends object, $PrivateData extends Data> =
& $Type
export type Add<$PrivateData extends Data, $Type extends object> =
& {
[privateSymbol]: $PrivateData
}
& $Type

/**
* Get the private data from a type.
Expand Down
4 changes: 2 additions & 2 deletions src/requestPipeline/RequestPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type RequestPipeline<$Config extends Config = Config> = Anyware.Pipeline<
GraffleExecutionResultVar<$Config>
>

export const RequestPipeline = Anyware.create<HookSequence, HookMap, Grafaid.FormattedExecutionResult>({
export const RequestPipeline = Anyware.Pipeline.create<HookSequence, HookMap, Grafaid.FormattedExecutionResult>({
// If core errors caused by an abort error then raise it as a direct error.
// This is an expected possible error. Possible when user cancels a request.
passthroughErrorWith: (signal) => {
Expand Down Expand Up @@ -86,7 +86,7 @@ export const RequestPipeline = Anyware.create<HookSequence, HookMap, Grafaid.For
const methodMode = input.state.config.transport.config.methodMode
const requestMethod = methodMode === MethodMode.post
? `post`
: methodMode === MethodMode.getReads // eslint-disable-line
: methodMode === MethodMode.getReads
? OperationTypeToAccessKind[operationType] === `read` ? `get` : `post`
: casesExhausted(methodMode)

Expand Down

0 comments on commit 3ffea92

Please sign in to comment.