Update dependency typescript to v7 - autoclosed #54

Closed
renovate-bot wants to merge 61 commits from renovate/typescript-7.x into master
2 changed files with 160 additions and 158 deletions
Showing only changes of commit feced4732f - Show all commits
+23 -23
View File
@@ -10,14 +10,14 @@ import * as View from "./View.js"
export const SubmittableFormTypeId: unique symbol = Symbol.for("@effect-fc/Form/SubmittableForm") export const SubmittableFormTypeId: unique symbol = Symbol.for("@effect-fc/Form/SubmittableForm")
export type SubmittableFormTypeId = typeof SubmittableFormTypeId export type SubmittableFormTypeId = typeof SubmittableFormTypeId
export interface SubmittableForm<in out A, in out I = A, in out R = never, in out MA = void, out ME = never, in out MR = never> export interface SubmittableForm<in out A, in out I = A, in out RD = never, in out RE = never, in out MA = void, out ME = never, in out MR = never>
extends Form.Form<readonly [], A, I, never, never> { extends Form.Form<readonly [], A, I, never, never> {
readonly [SubmittableFormTypeId]: SubmittableFormTypeId readonly [SubmittableFormTypeId]: SubmittableFormTypeId
readonly schema: Schema.ConstraintCodec<A, I, R, unknown> readonly schema: Schema.ConstraintCodec<A, I, RD, RE>
readonly context: Context.Context<Scope.Scope | R> readonly context: Context.Context<Scope.Scope | RD | RE>
readonly mutation: Mutation.Mutation< readonly mutation: Mutation.Mutation<
readonly [value: A, form: SubmittableForm<A, I, R, unknown, unknown, unknown>], readonly [value: A, form: SubmittableForm<A, I, RD, RE, unknown, unknown, unknown>],
MA, ME, MR MA, ME, MR
> >
readonly validationFiber: View.View<Option.Option<Fiber.Fiber<A, Schema.SchemaError>>, never, never> readonly validationFiber: View.View<Option.Option<Fiber.Fiber<A, Schema.SchemaError>>, never, never>
@@ -26,8 +26,8 @@ extends Form.Form<readonly [], A, I, never, never> {
readonly submit: Effect.Effect<Option.Option<AsyncResult.Success<MA, ME> | AsyncResult.Failure<MA, ME>>, Cause.NoSuchElementError> readonly submit: Effect.Effect<Option.Option<AsyncResult.Success<MA, ME> | AsyncResult.Failure<MA, ME>>, Cause.NoSuchElementError>
} }
export class SubmittableFormImpl<in out A, in out I = A, in out R = never, in out MA = void, in out ME = never, in out MR = never> export class SubmittableFormImpl<in out A, in out I = A, in out RD = never, in out RE = never, in out MA = void, out ME = never, in out MR = never>
extends Pipeable.Class implements SubmittableForm<A, I, R, MA, ME, MR> { extends Pipeable.Class implements SubmittableForm<A, I, RD, RE, MA, ME, MR> {
readonly [Form.FormTypeId]: Form.FormTypeId = Form.FormTypeId readonly [Form.FormTypeId]: Form.FormTypeId = Form.FormTypeId
readonly [SubmittableFormTypeId]: SubmittableFormTypeId = SubmittableFormTypeId readonly [SubmittableFormTypeId]: SubmittableFormTypeId = SubmittableFormTypeId
@@ -39,10 +39,10 @@ extends Pipeable.Class implements SubmittableForm<A, I, R, MA, ME, MR> {
readonly isCommitting: View.View<boolean, never, never> readonly isCommitting: View.View<boolean, never, never>
constructor( constructor(
readonly schema: Schema.ConstraintCodec<A, I, R, unknown>, readonly schema: Schema.ConstraintCodec<A, I, RD, RE>,
readonly context: Context.Context<Scope.Scope | R>, readonly context: Context.Context<Scope.Scope | RD | RE>,
readonly mutation: Mutation.Mutation< readonly mutation: Mutation.Mutation<
readonly [value: A, form: SubmittableForm<A, I, R, unknown, unknown, unknown>], readonly [value: A, form: SubmittableForm<A, I, RD, RE, unknown, unknown, unknown>],
MA, ME, MR MA, ME, MR
>, >,
readonly value: Lens.Lens<Option.Option<A>, never, never, never, never>, readonly value: Lens.Lens<Option.Option<A>, never, never, never, never>,
@@ -165,26 +165,26 @@ export const isSubmittableForm = (u: unknown): u is SubmittableForm<unknown, unk
export declare namespace make { export declare namespace make {
export interface Options<in out A, in out I = A, in out R = never, in out MA = void, in out ME = never, in out MR = never> export interface Options<in out A, in out I = A, in out RD = never, in out RE = never, in out MA = void, out ME = never, in out MR = never>
extends Mutation.make.Options< extends Mutation.make.Options<
readonly [value: NoInfer<A>, form: SubmittableForm<NoInfer<A>, NoInfer<I>, NoInfer<R>, unknown, unknown, unknown>], readonly [value: NoInfer<A>, form: SubmittableForm<NoInfer<A>, NoInfer<I>, NoInfer<RD>, NoInfer<RE>, unknown, unknown, unknown>],
MA, ME, MR MA, ME, MR
> { > {
readonly schema: Schema.ConstraintCodec<A, I, R, unknown> readonly schema: Schema.ConstraintCodec<A, I, RD, RE>
readonly initialEncodedValue: NoInfer<I> readonly initialEncodedValue: NoInfer<I>
} }
} }
export const make = Effect.fnUntraced(function* <A, I = A, R = never, MA = void, ME = never, MR = never>( export const make = Effect.fnUntraced(function* <A, I = A, RD = never, RE = never, MA = void, ME = never, MR = never>(
options: make.Options<A, I, R, MA, ME, MR> options: make.Options<A, I, RD, RE, MA, ME, MR>
): Effect.fn.Return< ): Effect.fn.Return<
SubmittableForm<A, I, R, MA, ME, MR>, SubmittableForm<A, I, RD, RE, MA, ME, MR>,
never, never,
Scope.Scope | R | MR Scope.Scope | RD | RE | MR
> { > {
return new SubmittableFormImpl( return new SubmittableFormImpl(
options.schema, options.schema,
yield* Effect.context<Scope.Scope | R | MR>(), yield* Effect.context<Scope.Scope | RD | RE | MR>(),
yield* Mutation.make(options), yield* Mutation.make(options),
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<A>())), Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<A>())),
@@ -197,16 +197,16 @@ export const make = Effect.fnUntraced(function* <A, I = A, R = never, MA = void,
}) })
export declare namespace service { export declare namespace service {
export interface Options<in out A, in out I = A, in out R = never, in out MA = void, in out ME = never, in out MR = never> export interface Options<in out A, in out I = A, in out RD = never, in out RE = never, in out MA = void, out ME = never, in out MR = never>
extends make.Options<A, I, R, MA, ME, MR> {} extends make.Options<A, I, RD, RE, MA, ME, MR> {}
} }
export const service = <A, I = A, R = never, MA = void, ME = never, MR = never, MP = never>( export const service = <A, I = A, RD = never, RE = never, MA = void, ME = never, MR = never>(
options: service.Options<A, I, R, MA, ME, MR> options: service.Options<A, I, RD, RE, MA, ME, MR>
): Effect.Effect< ): Effect.Effect<
SubmittableForm<A, I, R, MA, ME, MR>, SubmittableForm<A, I, RD, RE, MA, ME, MR>,
never, never,
Scope.Scope | R | MR Scope.Scope | RD | RE | MR
> => Effect.tap( > => Effect.tap(
make(options), make(options),
form => Effect.forkScoped(form.run), form => Effect.forkScoped(form.run),
+137 -135
View File
@@ -1,204 +1,206 @@
import { import type { StandardSchemaV1 } from "@standard-schema/spec"
Array, import { Array, type Context, Effect, Equal, Fiber, Option, Pipeable, Predicate, Schema, SchemaIssue, type Scope, Semaphore, Stream, SubscriptionRef } from "effect"
type Context,
Effect,
Equal,
Fiber,
Option,
Pipeable,
Predicate,
Schema,
SchemaIssue,
SchemaParser,
type Scope,
Semaphore,
Stream,
SubscriptionRef,
} from "effect"
import * as Form from "./Form.js" import * as Form from "./Form.js"
import * as Lens from "./Lens.js" import * as Lens from "./Lens.js"
import * as View from "./View.js" import * as View from "./View.js"
type FormSchema<A, I, R> = Schema.Top & {
readonly Type: A
readonly Encoded: I
readonly DecodingServices: R
readonly EncodingServices: R
}
export const SynchronizedFormTypeId: unique symbol = Symbol.for("@effect-fc/Form/SynchronizedForm") export const SynchronizedFormTypeId: unique symbol = Symbol.for("@effect-fc/Form/SynchronizedForm")
export type SynchronizedFormTypeId = typeof SynchronizedFormTypeId export type SynchronizedFormTypeId = typeof SynchronizedFormTypeId
export interface SynchronizedForm< export interface SynchronizedForm<in out A, in out I = A, in out RD = never, in out RE = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never>
in out A, extends Form.Form<readonly [], A, I, TER, TER | TEW> {
in out I = A,
in out R = never,
in out TER = never,
in out TEW = never,
in out TRR = never,
in out TRW = never,
> extends Form.Form<readonly [], A, I, TER, TER | TEW> {
readonly [SynchronizedFormTypeId]: SynchronizedFormTypeId readonly [SynchronizedFormTypeId]: SynchronizedFormTypeId
readonly schema: FormSchema<A, I, R>
readonly context: Context.Context<Scope.Scope | R | TRR | TRW> readonly schema: Schema.ConstraintCodec<A, I, RD, RE>
readonly context: Context.Context<Scope.Scope | RD | RE | TRR | TRW>
readonly target: Lens.Lens<A, TER, TEW, TRR, TRW> readonly target: Lens.Lens<A, TER, TEW, TRR, TRW>
readonly validationFiber: View.View<Option.Option<Fiber.Fiber<A, SchemaIssue.Issue>>, never, never> readonly validationFiber: View.View<Option.Option<Fiber.Fiber<A, Schema.SchemaError>>, never, never>
readonly run: Effect.Effect<void, TER> readonly run: Effect.Effect<void, TER>
} }
export class SynchronizedFormImpl< export class SynchronizedFormImpl<in out A, in out I = A, in out RD = never, in out RE = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never>
in out A, extends Pipeable.Class implements SynchronizedForm<A, I, RD, RE, TER, TEW, TRR, TRW> {
in out I = A,
in out R = never,
in out TER = never,
in out TEW = never,
in out TRR = never,
in out TRW = never,
> extends Pipeable.Class implements SynchronizedForm<A, I, R, TER, TEW, TRR, TRW> {
readonly [Form.FormTypeId]: Form.FormTypeId = Form.FormTypeId readonly [Form.FormTypeId]: Form.FormTypeId = Form.FormTypeId
readonly [SynchronizedFormTypeId]: SynchronizedFormTypeId = SynchronizedFormTypeId readonly [SynchronizedFormTypeId]: SynchronizedFormTypeId = SynchronizedFormTypeId
readonly path = [] as const readonly path = [] as const
readonly value: View.View<Option.Option<A>, TER, never>
readonly value: View.View<Option.Option<A>, never, never>
readonly encodedValue: Lens.Lens<I, TER, TER | TEW, never, never> readonly encodedValue: Lens.Lens<I, TER, TER | TEW, never, never>
readonly isValidating: View.View<boolean, never, never> readonly isValidating: View.View<boolean, never, never>
readonly canCommit: View.View<boolean, never, never> readonly canCommit: View.View<boolean, never, never>
constructor( constructor(
readonly schema: FormSchema<A, I, R>, readonly schema: Schema.ConstraintCodec<A, I, RD, RE>,
readonly context: Context.Context<Scope.Scope | R | TRR | TRW>, readonly context: Context.Context<Scope.Scope | RD | RE | TRR | TRW>,
readonly target: Lens.Lens<A, TER, TEW, TRR, TRW>, readonly target: Lens.Lens<A, TER, TEW, TRR, TRW>,
readonly internalEncodedValue: Lens.Lens<I, never, never, never, never>, readonly internalEncodedValue: Lens.Lens<I, never, never, never, never>,
readonly issues: Lens.Lens<readonly Form.FormIssue[], never, never, never, never>, readonly issues: Lens.Lens<readonly StandardSchemaV1.Issue[], never, never, never, never>,
readonly validationFiber: Lens.Lens<Option.Option<Fiber.Fiber<A, SchemaIssue.Issue>>, never, never, never, never>, readonly validationFiber: Lens.Lens<Option.Option<Fiber.Fiber<A, Schema.SchemaError>>, never, never, never, never>,
readonly isCommitting: Lens.Lens<boolean, never, never, never, never>, readonly isCommitting: Lens.Lens<boolean, never, never>,
readonly runSemaphore: Semaphore.Semaphore, readonly runSemaphore: Semaphore.Semaphore,
) { ) {
super() super()
this.value = View.make({
get: Effect.provide(Effect.map(target.get, Option.some), context), this.value = Effect.succeed(this).pipe(
changes: Stream.provideContext( Effect.map(self => View.make({
target.changes.pipe( get: Effect.provide(Effect.option(self.target.get), self.context),
Stream.map(Option.some), get changes() {
Stream.catchCause(() => Stream.make(Option.none<A>())), return Stream.provideContext(
self.target.changes.pipe(
Stream.map(Option.some),
Stream.catch(() => Stream.make(Option.none())),
),
self.context,
)
},
})),
View.unwrap,
)
this.encodedValue = Effect.all([
Effect.succeed(this),
Effect.succeed(Lens.asLensImpl(this.internalEncodedValue)),
]).pipe(
Effect.map(([self, parent]) => Lens.make({
get: parent.get,
get changes() { return parent.changes },
commit: a => Effect.andThen(
Effect.flatMap(
parent.resolve,
resolved => resolved.commit(Effect.succeed(a)),
),
self.synchronizeEncodedValue(a),
), ),
context, lock: parent.lock,
), })),
}) Lens.unwrap,
this.encodedValue = Lens.make({ )
get: Lens.get(internalEncodedValue), this.isValidating = Effect.succeed(this).pipe(
changes: internalEncodedValue.changes, Effect.map(self => View.map(self.validationFiber, Option.isSome)),
commit: encoded => Effect.andThen( View.unwrap,
Lens.set(internalEncodedValue, encoded), )
this.synchronizeEncodedValue(encoded), this.canCommit = Effect.succeed(this).pipe(
), Effect.map(self => View.map(
lock: Lens.asLensImpl(internalEncodedValue).lock, View.zipLatestAll(self.issues, self.validationFiber, self.isCommitting),
}) as unknown as Lens.Lens<I, TER, TER | TEW, never, never> ([issues, validationFiber, isCommitting]) => (
this.isValidating = View.map(validationFiber, Option.isSome) Array.isReadonlyArrayEmpty(issues) &&
const commitState = View.zipLatestAll(issues as any, validationFiber as any, isCommitting as any) as unknown as View.View<readonly [ Option.isNone(validationFiber) &&
readonly Form.FormIssue[], !isCommitting
Option.Option<Fiber.Fiber<A, SchemaIssue.Issue>>, ),
boolean, )),
]> View.unwrap,
this.canCommit = View.map(
commitState,
([currentIssues, fiber, committing]) => currentIssues.length === 0 && Option.isNone(fiber) && !committing,
) )
} }
synchronizeEncodedValue(encodedValue: I): Effect.Effect<void, TER | TEW> { synchronizeEncodedValue(encodedValue: I): Effect.Effect<void, TER | TEW, never> {
const self = this return Lens.get(this.validationFiber).pipe(
return Effect.gen(function*() { Effect.andThen(Option.match({
const current = yield* Lens.get(self.validationFiber) onSome: Fiber.interrupt,
if (Option.isSome(current)) yield* Fiber.interrupt(current.value) onNone: () => Effect.void,
const fiber = yield* Effect.forkScoped( })),
Effect.andThen(Effect.forkScoped(
Effect.ensuring( Effect.ensuring(
SchemaParser.decodeEffect(self.schema)(encodedValue), Schema.decodeEffect(this.schema, { errors: "all" })(encodedValue),
Lens.set(self.validationFiber, Option.none()), Lens.set(this.validationFiber, Option.none()),
)
)),
Effect.tap(fiber => Lens.set(this.validationFiber, Option.some(fiber))),
Effect.flatMap(Fiber.join),
Effect.flatMap(value => Effect.ensuring(
Lens.set(this.isCommitting, true).pipe(
Effect.andThen(Lens.set(this.issues, Array.empty())),
Effect.andThen(Lens.set(this.target, value)),
), ),
) Lens.set(this.isCommitting, false),
yield* Lens.set(self.validationFiber, Option.some(fiber)) )),
yield* Fiber.join(fiber).pipe( Effect.catchIf(
Effect.flatMap(value => Effect.ensuring( Schema.isSchemaError,
Effect.andThen( error => Lens.set(this.issues, SchemaIssue.makeFormatterStandardSchemaV1()(error.issue).issues),
Lens.set(self.isCommitting, true), ),
Effect.andThen(Lens.set(self.issues, Array.empty()), Lens.set(self.target, value)),
), Effect.provide(this.context),
Lens.set(self.isCommitting, false), )
)),
Effect.catchIf(SchemaIssue.isIssue, issue => Lens.set(self.issues, formatIssue(issue))),
)
}).pipe(Effect.provide(this.context)) as Effect.Effect<void, TER | TEW>
} }
get run(): Effect.Effect<void, TER> { get run(): Effect.Effect<void, TER, never> {
return this.runSemaphore.withPermits(1)(Effect.provide( return this.runSemaphore.withPermits(1)(Effect.provide(
Stream.runForEach(Stream.drop(this.target.changes, 1), targetValue => Effect.ignore( Stream.runForEach(
Effect.flatMap(SchemaParser.encodeEffect(this.schema)(targetValue), encodedValue => Effect.flatMap( Stream.drop(Lens.changes(this.target), 1),
Lens.get(this.internalEncodedValue), targetValue => Schema.encodeEffect(this.schema, { errors: "all" })(targetValue).pipe(
current => Equal.equals(encodedValue, current) Effect.flatMap(encodedValue => Effect.when(
? Effect.succeed(undefined) Effect.andThen(
: Effect.andThen(
Lens.set(this.issues, Array.empty()), Lens.set(this.issues, Array.empty()),
Lens.set(this.internalEncodedValue, encodedValue), Lens.set(this.internalEncodedValue, encodedValue),
), ),
)), Effect.map(
)), Lens.get(this.internalEncodedValue),
currentEncodedValue => !Equal.equals(encodedValue, currentEncodedValue),
),
)),
Effect.ignore,
),
),
this.context, this.context,
)) ))
} }
} }
const formatIssue = (issue: SchemaIssue.Issue): readonly Form.FormIssue[] => {
const formatted = SchemaIssue.makeFormatterStandardSchemaV1()(issue)
return formatted.issues.map(item => ({
path: (item.path ?? []) as readonly PropertyKey[],
message: item.message,
}))
}
export const isSynchronizedForm = (u: unknown): u is SynchronizedForm<unknown, unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, SynchronizedFormTypeId) export const isSynchronizedForm = (u: unknown): u is SynchronizedForm<unknown, unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, SynchronizedFormTypeId)
export declare namespace make { export declare namespace make {
export interface Options<in out A, in out I = A, in out R = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never> { export interface Options<in out A, in out I = A, in out RD = never, in out RE = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never> {
readonly schema: FormSchema<A, I, R> readonly schema: Schema.ConstraintCodec<A, I, RD, RE>
readonly target: Lens.Lens<A, TER, TEW, TRR, TRW> readonly target: Lens.Lens<A, TER, TEW, TRR, TRW>
readonly initialEncodedValue?: NoInfer<I> readonly initialEncodedValue?: NoInfer<I>
} }
} }
export const make = Effect.fnUntraced(function* <A, I = A, R = never, TER = never, TEW = never, TRR = never, TRW = never>( export const make = Effect.fnUntraced(function* <A, I = A, RD = never, RE = never, TER = never, TEW = never, TRR = never, TRW = never>(
options: make.Options<A, I, R, TER, TEW, TRR, TRW>, options: make.Options<A, I, RD, RE, TER, TEW, TRR, TRW>
): Effect.fn.Return< ): Effect.fn.Return<
SynchronizedForm<A, I, R, TER, TEW, TRR, TRW>, SynchronizedForm<A, I, RD, RE, TER, TEW, TRR, TRW>,
SchemaIssue.Issue | TER, Schema.SchemaError | TER,
Scope.Scope | R | TRR | TRW Scope.Scope | RD | RE | TRR | TRW
> { > {
const initialEncodedValue = options.initialEncodedValue !== undefined const initialEncodedValue = options.initialEncodedValue !== undefined
? options.initialEncodedValue ? options.initialEncodedValue
: yield* Effect.flatMap(Lens.get(options.target), SchemaParser.encodeEffect(options.schema)) : yield* Effect.flatMap(
Lens.get(options.target),
Schema.encodeEffect(options.schema),
)
return new SynchronizedFormImpl( return new SynchronizedFormImpl(
options.schema, options.schema,
yield* Effect.context<Scope.Scope | R | TRR | TRW>(), yield* Effect.context<Scope.Scope | RD | RE | TRR | TRW>(),
options.target, options.target,
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(initialEncodedValue)), Lens.fromSubscriptionRef(yield* SubscriptionRef.make(initialEncodedValue)),
Lens.fromSubscriptionRef(yield* SubscriptionRef.make<readonly Form.FormIssue[]>(Array.empty())), Lens.fromSubscriptionRef(yield* SubscriptionRef.make<readonly StandardSchemaV1.Issue[]>(Array.empty())),
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, SchemaIssue.Issue>>())), Lens.fromSubscriptionRef(yield* SubscriptionRef.make(Option.none<Fiber.Fiber<A, Schema.SchemaError>>())),
Lens.fromSubscriptionRef(yield* SubscriptionRef.make(false)), Lens.fromSubscriptionRef(yield* SubscriptionRef.make(false)),
yield* Semaphore.make(1), yield* Semaphore.make(1),
) )
}) })
export declare namespace service { export declare namespace service {
export interface Options<in out A, in out I = A, in out R = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never> export interface Options<in out A, in out I = A, in out RD = never, in out RE = never, in out TER = never, in out TEW = never, in out TRR = never, in out TRW = never>
extends make.Options<A, I, R, TER, TEW, TRR, TRW> {} extends make.Options<A, I, RD, RE, TER, TEW, TRR, TRW> {}
} }
export const service = <A, I = A, R = never, TER = never, TEW = never, TRR = never, TRW = never>( export const service = <A, I = A, RD = never, RE = never, TER = never, TEW = never, TRR = never, TRW = never>(
options: service.Options<A, I, R, TER, TEW, TRR, TRW>, options: service.Options<A, I, RD, RE, TER, TEW, TRR, TRW>
): Effect.Effect< ): Effect.Effect<
SynchronizedForm<A, I, R, TER, TEW, TRR, TRW>, SynchronizedForm<A, I, RD, RE, TER, TEW, TRR, TRW>,
SchemaIssue.Issue | TER, Schema.SchemaError | TER,
Scope.Scope | R | TRR | TRW Scope.Scope | RD | RE | TRR | TRW
> => Effect.tap(make(options), form => Effect.asVoid(Effect.forkScoped(form.run))) > => Effect.tap(
make(options),
form => Effect.forkScoped(form.run),
)