This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Context, Effect, Effectable, ExecutionStrategy, Function, Predicate, Runtime, Scope, String, Tracer, type Types } from "effect"
|
import { Context, Effect, Effectable, ExecutionStrategy, Function, Predicate, Runtime, Scope, String, Tracer, type Types, type Utils } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { Hooks } from "./hooks/index.js"
|
import { Hooks } from "./hooks/index.js"
|
||||||
import * as Memoized from "./Memoized.js"
|
import * as Memoized from "./Memoized.js"
|
||||||
@@ -97,15 +97,275 @@ const nonReactiveTags = [Tracer.ParentSpan] as const
|
|||||||
|
|
||||||
export const isComponent = (u: unknown): u is Component<unknown, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, TypeId)
|
export const isComponent = (u: unknown): u is Component<unknown, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, TypeId)
|
||||||
|
|
||||||
export const make = <Args extends readonly any[], A extends React.ReactNode, E, R>(
|
export namespace make {
|
||||||
body: (...args: Args) => Effect.Effect<A, E, R>
|
export type Gen = {
|
||||||
): Component<(...args: Args) => A, E, R> => Object.setPrototypeOf(
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A extends React.ReactNode, P = never>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>
|
||||||
|
): Component<
|
||||||
|
P, A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B
|
||||||
|
): Component<P, Effect.Effect.Error<B>, Effect.Effect.Context<B>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
): Component<P, Effect.Effect.Error<C>, Effect.Effect.Context<C>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
): Component<P, Effect.Effect.Error<D>, Effect.Effect.Context<D>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
): Component<P, Effect.Effect.Error<E>, Effect.Effect.Context<E>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
): Component<P, Effect.Effect.Error<F>, Effect.Effect.Context<F>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
): Component<P, Effect.Effect.Error<G>, Effect.Effect.Context<G>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => H,
|
||||||
|
): Component<P, Effect.Effect.Error<H>, Effect.Effect.Context<H>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => H,
|
||||||
|
h: (_: H, props: NoInfer<P>) => I,
|
||||||
|
): Component<P, Effect.Effect.Error<I>, Effect.Effect.Context<I>>
|
||||||
|
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I, J extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Generator<Eff, A, never>,
|
||||||
|
a: (
|
||||||
|
_: Effect.Effect<
|
||||||
|
A,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
||||||
|
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
||||||
|
>,
|
||||||
|
props: NoInfer<P>,
|
||||||
|
) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => H,
|
||||||
|
h: (_: H, props: NoInfer<P>) => I,
|
||||||
|
i: (_: I, props: NoInfer<P>) => J,
|
||||||
|
): Component<P, Effect.Effect.Error<J>, Effect.Effect.Context<J>>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NonGen = {
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
|
||||||
|
body: (props: P) => Eff
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => H,
|
||||||
|
h: (_: H, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, I, P extends {} = {}>(
|
||||||
|
body: (props: P) => A,
|
||||||
|
a: (_: A, props: NoInfer<P>) => B,
|
||||||
|
b: (_: B, props: NoInfer<P>) => C,
|
||||||
|
c: (_: C, props: NoInfer<P>) => D,
|
||||||
|
d: (_: D, props: NoInfer<P>) => E,
|
||||||
|
e: (_: E, props: NoInfer<P>) => F,
|
||||||
|
f: (_: F, props: NoInfer<P>) => G,
|
||||||
|
g: (_: G, props: NoInfer<P>) => H,
|
||||||
|
h: (_: H, props: NoInfer<P>) => I,
|
||||||
|
i: (_: I, props: NoInfer<P>) => Eff,
|
||||||
|
): Component<P, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const make: (
|
||||||
|
& make.Gen
|
||||||
|
& make.NonGen
|
||||||
|
& ((
|
||||||
|
spanName: string,
|
||||||
|
spanOptions?: Tracer.SpanOptions,
|
||||||
|
) => make.Gen & make.NonGen)
|
||||||
|
) = (spanNameOrBody: Function | string, ...pipeables: any[]): any => {
|
||||||
|
if (typeof spanNameOrBody !== "string") {
|
||||||
|
const displayName = displayNameFromBody(spanNameOrBody)
|
||||||
|
return Object.setPrototypeOf(
|
||||||
Object.assign(function() {}, defaultOptions, {
|
Object.assign(function() {}, defaultOptions, {
|
||||||
body,
|
body: displayName
|
||||||
displayName: !String.isEmpty(body.name) ? body.name : undefined,
|
? Effect.fn(displayName)(spanNameOrBody as any, ...pipeables as [])
|
||||||
|
: Effect.fn(spanNameOrBody as any, ...pipeables),
|
||||||
|
displayName,
|
||||||
}),
|
}),
|
||||||
ComponentProto,
|
ComponentProto,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const spanOptions = pipeables[0]
|
||||||
|
return (body: any, ...pipeables: any[]) => Object.setPrototypeOf(
|
||||||
|
Object.assign(function() {}, defaultOptions, {
|
||||||
|
body: Effect.fn(spanNameOrBody, spanOptions)(body, ...pipeables as []),
|
||||||
|
displayName: displayNameFromBody(body) ?? spanNameOrBody,
|
||||||
|
}),
|
||||||
|
ComponentProto,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const makeUntraced: make.Gen & make.NonGen = (
|
||||||
|
body: Function,
|
||||||
|
...pipeables: any[]
|
||||||
|
) => Object.setPrototypeOf(
|
||||||
|
Object.assign(function() {}, defaultOptions, {
|
||||||
|
body: Effect.fnUntraced(body as any, ...pipeables as []),
|
||||||
|
displayName: displayNameFromBody(body),
|
||||||
|
}),
|
||||||
|
ComponentProto,
|
||||||
|
)
|
||||||
|
|
||||||
|
const displayNameFromBody = (body: Function) => !String.isEmpty(body.name) ? body.name : undefined
|
||||||
|
|
||||||
export const withOptions: {
|
export const withOptions: {
|
||||||
<T extends Component<any, any, any, any>>(
|
<T extends Component<any, any, any, any>>(
|
||||||
|
|||||||
Reference in New Issue
Block a user