From 72cbbf11d19baae6b7140cb6583ddc8ccb5b9ebb Mon Sep 17 00:00:00 2001 From: mccraig mccraig of the clan mccraig Date: Sat, 16 Dec 2023 12:09:09 +0000 Subject: [PATCH] ObjectStepSpecList type --- src/object_chain.ts | 32 ++++++++++++++++---------------- src/object_chain_steps.ts | 30 ++++++++++++++++-------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/object_chain.ts b/src/object_chain.ts index 098db73..3c1b9ad 100644 --- a/src/object_chain.ts +++ b/src/object_chain.ts @@ -6,14 +6,14 @@ import * as ctag from "./chain_tag.ts" import { CastUCObjectStepSpec, UCFxObjectStepSpec, UCPureObjectStepSpec, - ObjectChainSteps, UPObjectStepSpec, + ObjectChainSteps, UPObjectStepSpec, ObjectStepSpecList, ObjectStepsTupleReqsU, ObjectStepsErrorsU, ObjectChainStepsReturn, objectChainStepsProg } from "./object_chain_steps.ts" // an effectful function of Input which build an Object export type ObjectChainProgram> = + Steps extends ObjectStepSpecList> = (i: Input) => Effect.Effect< ObjectStepsTupleReqsU, ObjectStepsErrorsU, @@ -22,18 +22,18 @@ export type ObjectChainProgram> = { + Steps extends ObjectStepSpecList> = { readonly buildObject: ObjectChainProgram } export type ObjectChainServiceContextTag> = + Steps extends ObjectStepSpecList> = Context.Tag, ObjectChainService> // get a Context.Tag for an ObjectChainService export function objectChainServiceContextTag > + Steps extends ObjectStepSpecList> () { return Context.Tag, ObjectChainService>() } @@ -42,7 +42,7 @@ export function objectChainServiceContextTag // Object. it can be built in a single step with objectChain, or iteratively // with addSteps export type ObjectChain, + Steps extends ObjectStepSpecList, // this param is only here so that a chain value's IntelliSense // shows the chain's return type _Return = ObjectChainStepsReturn> = { @@ -63,7 +63,7 @@ export type UPObjectChain = { // deno-lint-ignore no-explicit-any readonly tag: any readonly tagStr: string - readonly steps: cons.NRConsList + readonly steps: ObjectStepSpecList // deno-lint-ignore no-explicit-any readonly program: (i: any) => Effect.Effect // deno-lint-ignore no-explicit-any @@ -102,7 +102,7 @@ export type UPObjectChainProgramValue = // build an ObjectChain from Steps export function objectChain() { - return function > + return function (tag: ChainTag, steps: Steps extends ObjectChainSteps @@ -126,7 +126,7 @@ export function objectChain() { // add a FxStep to an ObjectChain, returning a new ObjectChain export function addStep , + const Steps extends ObjectStepSpecList, NewStep extends UPObjectStepSpec> (chain: ObjectChain, @@ -146,7 +146,7 @@ export function addStep // make an FxStep at the end of an ObjectChain, returning a new ObjectChain export function makeFxStep , + const Steps extends ObjectStepSpecList, K extends string, A extends ObjectChainStepsReturn, D1 extends D2, @@ -168,7 +168,7 @@ export function makeFxStep // make a PureStep at the end of an ObjectChain, returning a new ObjectChain export function makePureStep , + const Steps extends ObjectStepSpecList, K extends string, A extends ObjectChainStepsReturn, V>(chain: ObjectChain, @@ -185,8 +185,8 @@ export function makePureStep // return a new ObjectChain with the addSteps concatenated export function concatSteps , - const AddSteps extends cons.NRConsList> + const ChainSteps extends ObjectStepSpecList, + const AddSteps extends ObjectStepSpecList> (chain: ObjectChain, addSteps: AddSteps extends cons.ConsList ? AddSteps @@ -214,7 +214,7 @@ export function concatSteps export function objectChainServiceImpl > + const Steps extends ObjectStepSpecList> (chain: ObjectChain) { @@ -231,7 +231,7 @@ export function objectChainServiceImpl // to an Effect export function provideObjectChainServiceImpl , + const Steps extends ObjectStepSpecList, InR, InE, InV> (effect: Effect.Effect, @@ -248,7 +248,7 @@ export function provideObjectChainServiceImpl // calls it's buildObject function export function objectChainFxFn > + const Steps extends ObjectStepSpecList> (chain: ObjectChain) { diff --git a/src/object_chain_steps.ts b/src/object_chain_steps.ts index 3fd9280..ccf9f1d 100644 --- a/src/object_chain_steps.ts +++ b/src/object_chain_steps.ts @@ -146,6 +146,8 @@ export function objectStepFn() { } } +export type ObjectStepSpecList = NRConsList + // utility type to get a Union from a Tuple of types // deno-lint-ignore no-explicit-any export type UnionFromTuple = Tuple[number] @@ -163,7 +165,7 @@ export type ExpandTuple = { } & { length: Tuple['length'] } // convert a cons list of UPObjectStepSpecs type to a Tuple type -export type ObjectStepsTuple> = +export type ObjectStepsTuple = ToTuple // get a union of all the Requirements from a list of steps... @@ -174,12 +176,12 @@ export type ObjectStepReqs = ? R : never export type ObjectStepsReqsU< - List extends NRConsList, + List extends ObjectStepSpecList, Acc = never> = List extends None ? Acc : List extends readonly [infer F extends UPObjectStepSpec, - infer R extends NRConsList] + infer R extends ObjectStepSpecList] ? ObjectStepsReqsU> : never type ObjectStepsTupleReqsUImpl< @@ -192,7 +194,7 @@ type ObjectStepsTupleReqsUImpl< // setting up the recursion Service in object_chain.ts ...converting // the list to a tuple before extracting the Requirements union seems // to avoid that -export type ObjectStepsTupleReqsU> = +export type ObjectStepsTupleReqsU = ObjectStepsTupleReqsUImpl> // get a union of all the Errors from a list of steps @@ -202,12 +204,12 @@ export type ObjectStepErrors = ? E : never export type ObjectStepsErrorsU< - List extends NRConsList, + List extends ObjectStepSpecList, Acc = never> = List extends None ? Acc : List extends readonly [infer F extends UPObjectStepSpec, - infer R extends NRConsList] + infer R extends ObjectStepSpecList] ? ObjectStepsErrorsU> : never @@ -218,13 +220,13 @@ export type ObjectStepInput = ? A : never export type ObjectStepsInputTuple< - List extends NRConsList, + List extends ObjectStepSpecList, // deno-lint-ignore no-explicit-any Acc extends readonly any[] = []> = List extends None ? Acc : List extends readonly [infer F extends UPObjectStepSpec, - infer R extends NRConsList] + infer R extends ObjectStepSpecList] ? ObjectStepsInputTuple]> : never @@ -235,13 +237,13 @@ export type ObjectStepValue = ? V : never export type ObjectStepsValueTuple< - List extends NRConsList, + List extends ObjectStepSpecList, // deno-lint-ignore no-explicit-any Acc extends readonly any[] = []> = List extends None ? Acc : List extends readonly [infer F extends UPObjectStepSpec, - infer R extends NRConsList] + infer R extends ObjectStepSpecList] ? ObjectStepsValueTuple]> : never @@ -261,7 +263,7 @@ export type ObjectStepsValueTuple< // 2. it's safe to use never in the else branches. they will not be hit export type ObjectChainSteps< - Specs extends NRConsList, + Specs extends ObjectStepSpecList, ObjAcc> = // case: no more specs @@ -270,7 +272,7 @@ export type ObjectChainSteps< // case: there are more specs - add a property to ObjAcc and recurse : Specs extends readonly [infer First, - infer Rest extends NRConsList] + infer Rest extends ObjectStepSpecList] ? First extends UCFxObjectStepSpec< infer FK, infer _FA, infer _FD1, infer FD2, infer FR, infer FE, infer FV> @@ -285,7 +287,7 @@ export type ObjectChainSteps< // get the final Object result type from a list of ObjectStepSpecs export type ObjectChainStepsReturn< - Specs extends NRConsList, + Specs extends ObjectStepSpecList, ObjAcc> = Specs extends None ? ObjAcc // empty specs returns the input @@ -304,7 +306,7 @@ export type ObjectChainStepsReturn< // other type params export function objectChainStepsProg() { - return function > + return function (objectStepSpecs: Specs extends ObjectChainSteps ? Specs