diff --git a/.vscode/settings.json b/.vscode/settings.json index b3ed285260..7eea164a65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,7 +24,11 @@ "[typescriptreact]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, - "eslint.validate": ["markdown", "javascript", "typescript"], + "eslint.validate": [ + "markdown", + "javascript", + "typescript" + ], "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" }, diff --git a/packages/effect/src/Graph.ts b/packages/effect/src/Graph.ts index d04f9ef2e3..b1a28c925e 100644 --- a/packages/effect/src/Graph.ts +++ b/packages/effect/src/Graph.ts @@ -2770,6 +2770,39 @@ export class Walker implements Iterable<[T, N]> { // @ts-ignore readonly [Symbol.iterator]: () => Iterator<[T, N]> + /** + * Visits each element and maps it to a value using the provided function. + * + * Takes a function that receives the index and data, + * and returns an iterable of the mapped values. Skips elements that + * no longer exist in the graph. + * + * @example + * ```ts + * import { Graph } from "effect" + * + * const graph = Graph.directed((mutable) => { + * const a = Graph.addNode(mutable, "A") + * const b = Graph.addNode(mutable, "B") + * Graph.addEdge(mutable, a, b, 1) + * }) + * + * const dfs = Graph.dfs(graph, { startNodes: [0] }) + * + * // Map to just the node data + * const values = Array.from(dfs.visit((index, data) => data)) + * console.log(values) // ["A", "B"] + * + * // Map to custom objects + * const custom = Array.from(dfs.visit((index, data) => ({ id: index, name: data }))) + * console.log(custom) // [{ id: 0, name: "A" }, { id: 1, name: "B" }] + * ``` + * + * @since 4.0.0 + * @category iterators + */ + readonly visit: (f: (index: T, data: N) => U) => Iterable + constructor( /** * Visits each element and maps it to a value using the provided function. @@ -2802,8 +2835,9 @@ export class Walker implements Iterable<[T, N]> { * @since 4.0.0 * @category iterators */ - readonly visit: (f: (index: T, data: N) => U) => Iterable + visit: (f: (index: T, data: N) => U) => Iterable ) { + this.visit = visit this[Symbol.iterator] = visit((index, data) => [index, data] as [T, N])[Symbol.iterator] } } diff --git a/packages/effect/src/Metric.ts b/packages/effect/src/Metric.ts index 72b890f875..44bc0d02e7 100644 --- a/packages/effect/src/Metric.ts +++ b/packages/effect/src/Metric.ts @@ -1691,11 +1691,19 @@ abstract class Metric$ implements Metric { readonly #metadataCache = new WeakMap>() #metadata: Metric.Metadata | undefined + readonly id: string + readonly description: string | undefined + readonly attributes: Metric.AttributeSet | undefined + constructor( - readonly id: string, - readonly description: string | undefined, - readonly attributes: Metric.AttributeSet | undefined - ) {} + id: string, + description: string | undefined, + attributes: Metric.AttributeSet | undefined + ) { + this.id = id + this.description = description + this.attributes = attributes + } unsafeValue(context: ServiceMap.ServiceMap): State { return this.hook(context).get(context) @@ -2013,13 +2021,22 @@ class SummaryMetric extends Metric$ extends Metric$ { type: Metric.Type + readonly metric: Metric + readonly unsafeValue: (context: ServiceMap.ServiceMap) => State + readonly unsafeUpdate: (input: Input2, context: ServiceMap.ServiceMap) => void + readonly unsafeModify: (input: Input2, context: ServiceMap.ServiceMap) => void + constructor( - readonly metric: Metric, - readonly unsafeValue: (context: ServiceMap.ServiceMap) => State, - readonly unsafeUpdate: (input: Input2, context: ServiceMap.ServiceMap) => void, - readonly unsafeModify: (input: Input2, context: ServiceMap.ServiceMap) => void + metric: Metric, + unsafeValue: (context: ServiceMap.ServiceMap) => State, + unsafeUpdate: (input: Input2, context: ServiceMap.ServiceMap) => void, + unsafeModify: (input: Input2, context: ServiceMap.ServiceMap) => void ) { super(metric.id, metric.description, metric.attributes) + this.metric = metric + this.unsafeValue = unsafeValue + this.unsafeUpdate = unsafeUpdate + this.unsafeModify = unsafeModify this.type = metric.type } createHooks(): Metric.Hooks { diff --git a/packages/effect/src/MutableHashMap.ts b/packages/effect/src/MutableHashMap.ts index 4ab7e16744..07a19fdbfa 100644 --- a/packages/effect/src/MutableHashMap.ts +++ b/packages/effect/src/MutableHashMap.ts @@ -120,8 +120,10 @@ const MutableHashMapProto: Omit, "referential" class MutableHashMapIterator implements IterableIterator<[K, V]> { readonly referentialIterator: Iterator<[K, V]> bucketIterator: Iterator<[K, V]> | undefined + readonly self: MutableHashMap - constructor(readonly self: MutableHashMap) { + constructor(self: MutableHashMap) { + this.self = self this.referentialIterator = self.referential[Symbol.iterator]() } next(): IteratorResult<[K, V]> { @@ -142,8 +144,12 @@ class MutableHashMapIterator implements IterableIterator<[K, V]> { } class BucketIterator implements Iterator<[K, V]> { - constructor(readonly backing: Iterator>) {} + readonly backing: Iterator> currentBucket: Iterator | undefined + + constructor(backing: Iterator>) { + this.backing = backing + } next(): IteratorResult<[K, V]> { if (this.currentBucket === undefined) { const result = this.backing.next() diff --git a/packages/effect/src/PubSub.ts b/packages/effect/src/PubSub.ts index 188d27d1be..6c689eed87 100644 --- a/packages/effect/src/PubSub.ts +++ b/packages/effect/src/PubSub.ts @@ -1538,7 +1538,12 @@ class BoundedPubSubArb implements PubSub.Atomic { subscriberCount = 0 subscribersIndex = 0 - constructor(readonly capacity: number, readonly replayBuffer: ReplayBuffer | undefined) { + readonly capacity: number + readonly replayBuffer: ReplayBuffer | undefined + + constructor(capacity: number, replayBuffer: ReplayBuffer | undefined) { + this.capacity = capacity + this.replayBuffer = replayBuffer this.array = Array.from({ length: capacity }) this.subscribers = Array.from({ length: capacity }) } @@ -1624,11 +1629,18 @@ class BoundedPubSubArb implements PubSub.Atomic { } class BoundedPubSubArbSubscription implements PubSub.BackingSubscription { + private self: BoundedPubSubArb + private subscriberIndex: number + private unsubscribed: boolean + constructor( - private self: BoundedPubSubArb, - private subscriberIndex: number, - private unsubscribed: boolean + self: BoundedPubSubArb, + subscriberIndex: number, + unsubscribed: boolean ) { + this.self = self + this.subscriberIndex = subscriberIndex + this.unsubscribed = unsubscribed } isEmpty(): boolean { @@ -1718,7 +1730,12 @@ class BoundedPubSubPow2 implements PubSub.Atomic { subscriberCount = 0 subscribersIndex = 0 - constructor(readonly capacity: number, readonly replayBuffer: ReplayBuffer | undefined) { + readonly capacity: number + readonly replayBuffer: ReplayBuffer | undefined + + constructor(capacity: number, replayBuffer: ReplayBuffer | undefined) { + this.capacity = capacity + this.replayBuffer = replayBuffer this.array = Array.from({ length: capacity }) this.mask = capacity - 1 this.subscribers = Array.from({ length: capacity }) @@ -1805,11 +1822,18 @@ class BoundedPubSubPow2 implements PubSub.Atomic { } class BoundedPubSubPow2Subscription implements PubSub.BackingSubscription { + private self: BoundedPubSubPow2 + private subscriberIndex: number + private unsubscribed: boolean + constructor( - private self: BoundedPubSubPow2, - private subscriberIndex: number, - private unsubscribed: boolean + self: BoundedPubSubPow2, + subscriberIndex: number, + unsubscribed: boolean ) { + this.self = self + this.subscriberIndex = subscriberIndex + this.unsubscribed = unsubscribed } isEmpty(): boolean { @@ -1897,7 +1921,11 @@ class BoundedPubSubSingle implements PubSub.Atomic { value: A = AbsentValue as unknown as A readonly capacity = 1 - constructor(readonly replayBuffer: ReplayBuffer | undefined) {} + readonly replayBuffer: ReplayBuffer | undefined + + constructor(replayBuffer: ReplayBuffer | undefined) { + this.replayBuffer = replayBuffer + } replayWindow(): PubSub.ReplayWindow { return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow @@ -1969,11 +1997,18 @@ class BoundedPubSubSingle implements PubSub.Atomic { } class BoundedPubSubSingleSubscription implements PubSub.BackingSubscription { + private self: BoundedPubSubSingle + private subscriberIndex: number + private unsubscribed: boolean + constructor( - private self: BoundedPubSubSingle, - private subscriberIndex: number, - private unsubscribed: boolean + self: BoundedPubSubSingle, + subscriberIndex: number, + unsubscribed: boolean ) { + this.self = self + this.subscriberIndex = subscriberIndex + this.unsubscribed = unsubscribed } isEmpty(): boolean { @@ -2045,7 +2080,11 @@ class UnboundedPubSub implements PubSub.Atomic { subscribersIndex = 0 readonly capacity = Number.MAX_SAFE_INTEGER - constructor(readonly replayBuffer: ReplayBuffer | undefined) {} + readonly replayBuffer: ReplayBuffer | undefined + + constructor(replayBuffer: ReplayBuffer | undefined) { + this.replayBuffer = replayBuffer + } replayWindow(): PubSub.ReplayWindow { return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow @@ -2114,12 +2153,21 @@ class UnboundedPubSub implements PubSub.Atomic { } class UnboundedPubSubSubscription implements PubSub.BackingSubscription { + private self: UnboundedPubSub + private subscriberHead: Node + private subscriberIndex: number + private unsubscribed: boolean + constructor( - private self: UnboundedPubSub, - private subscriberHead: Node, - private subscriberIndex: number, - private unsubscribed: boolean + self: UnboundedPubSub, + subscriberHead: Node, + subscriberIndex: number, + unsubscribed: boolean ) { + this.self = self + this.subscriberHead = subscriberHead + this.subscriberIndex = subscriberIndex + this.unsubscribed = unsubscribed } isEmpty(): boolean { @@ -2218,16 +2266,34 @@ class SubscriptionImpl implements Subscription { _A: identity } + readonly pubsub: PubSub.Atomic + readonly subscribers: PubSub.Subscribers + readonly subscription: PubSub.BackingSubscription + readonly pollers: MutableList.MutableList> + readonly shutdownHook: Effect.Latch + readonly shutdownFlag: MutableRef.MutableRef + readonly strategy: PubSub.Strategy + readonly replayWindow: PubSub.ReplayWindow + constructor( - readonly pubsub: PubSub.Atomic, - readonly subscribers: PubSub.Subscribers, - readonly subscription: PubSub.BackingSubscription, - readonly pollers: MutableList.MutableList>, - readonly shutdownHook: Effect.Latch, - readonly shutdownFlag: MutableRef.MutableRef, - readonly strategy: PubSub.Strategy, - readonly replayWindow: PubSub.ReplayWindow - ) {} + pubsub: PubSub.Atomic, + subscribers: PubSub.Subscribers, + subscription: PubSub.BackingSubscription, + pollers: MutableList.MutableList>, + shutdownHook: Effect.Latch, + shutdownFlag: MutableRef.MutableRef, + strategy: PubSub.Strategy, + replayWindow: PubSub.ReplayWindow + ) { + this.pubsub = pubsub + this.subscribers = subscribers + this.subscription = subscription + this.pollers = pollers + this.shutdownHook = shutdownHook + this.shutdownFlag = shutdownFlag + this.strategy = strategy + this.replayWindow = replayWindow + } pipe() { return pipeArguments(this, arguments) @@ -2239,14 +2305,28 @@ class PubSubImpl implements PubSub { _A: identity } + readonly pubsub: PubSub.Atomic + readonly subscribers: PubSub.Subscribers + readonly scope: Scope.Scope.Closeable + readonly shutdownHook: Effect.Latch + readonly shutdownFlag: MutableRef.MutableRef + readonly strategy: PubSub.Strategy + constructor( - readonly pubsub: PubSub.Atomic, - readonly subscribers: PubSub.Subscribers, - readonly scope: Scope.Scope.Closeable, - readonly shutdownHook: Effect.Latch, - readonly shutdownFlag: MutableRef.MutableRef, - readonly strategy: PubSub.Strategy - ) {} + pubsub: PubSub.Atomic, + subscribers: PubSub.Subscribers, + scope: Scope.Scope.Closeable, + shutdownHook: Effect.Latch, + shutdownFlag: MutableRef.MutableRef, + strategy: PubSub.Strategy + ) { + this.pubsub = pubsub + this.subscribers = subscribers + this.scope = scope + this.shutdownHook = shutdownHook + this.shutdownFlag = shutdownFlag + this.strategy = strategy + } pipe() { return pipeArguments(this, arguments) @@ -2592,13 +2672,16 @@ interface ReplayNode { } class ReplayBuffer { - constructor(readonly capacity: number) {} - + readonly capacity: number head: ReplayNode = { value: AbsentValue, next: null } tail: ReplayNode = this.head size = 0 index = 0 + constructor(capacity: number) { + this.capacity = capacity + } + slide() { this.index++ } @@ -2626,7 +2709,10 @@ class ReplayWindowImpl implements PubSub.ReplayWindow { head: ReplayNode index: number remaining: number - constructor(readonly buffer: ReplayBuffer) { + readonly buffer: ReplayBuffer + + constructor(buffer: ReplayBuffer) { + this.buffer = buffer this.index = buffer.index this.remaining = buffer.size this.head = buffer.head diff --git a/packages/effect/src/Pull.ts b/packages/effect/src/Pull.ts index 191ac5919e..81c8897bd3 100644 --- a/packages/effect/src/Pull.ts +++ b/packages/effect/src/Pull.ts @@ -167,7 +167,11 @@ export class Halt { */ readonly [HaltTypeId]: HaltTypeId = HaltTypeId - constructor(readonly leftover: L) {} + readonly leftover: L + + constructor(leftover: L) { + this.leftover = leftover + } } /** diff --git a/packages/effect/src/Record.ts b/packages/effect/src/Record.ts index 7f89212b11..94afcef2e2 100644 --- a/packages/effect/src/Record.ts +++ b/packages/effect/src/Record.ts @@ -692,7 +692,7 @@ export const mapEntries: { self: ReadonlyRecord, f: (a: A, key: K) => [K2, B] ): Record => { - const out = > {} + const out = {} as Record for (const key of keys(self)) { const [k, b] = f(self[key], key) out[k] = b @@ -1402,7 +1402,7 @@ export const difference: { if (isEmptyRecord(that)) { return { ...self } as any } - const out = > {} + const out = {} as Record for (const key of keys(self)) { if (!has(that, key as any)) { out[key] = self[key] diff --git a/packages/effect/src/Scheduler.ts b/packages/effect/src/Scheduler.ts index 88b4708be0..4706c38aaa 100644 --- a/packages/effect/src/Scheduler.ts +++ b/packages/effect/src/Scheduler.ts @@ -132,10 +132,13 @@ const setImmediate = "setImmediate" in globalThis export class MixedScheduler implements Scheduler { private tasks: Array<() => void> = [] private running: ReturnType | undefined = undefined + readonly executionMode: "sync" | "async" constructor( - readonly executionMode: "sync" | "async" = "async" - ) {} + executionMode: "sync" | "async" = "async" + ) { + this.executionMode = executionMode + } /** * @since 2.0.0 diff --git a/packages/effect/src/String.ts b/packages/effect/src/String.ts index f17efe2e4f..9b270b793b 100644 --- a/packages/effect/src/String.ts +++ b/packages/effect/src/String.ts @@ -1083,8 +1083,15 @@ export const kebabToSnake = (self: string): string => self.replace(/-/g, "_") class LinesIterator implements IterableIterator { private index: number private readonly length: number + readonly s: string + readonly stripped: boolean - constructor(readonly s: string, readonly stripped: boolean = false) { + constructor( + s: string, + stripped: boolean = false + ) { + this.s = s + this.stripped = stripped this.index = 0 this.length = s.length } diff --git a/packages/effect/src/Tracer.ts b/packages/effect/src/Tracer.ts index b80b441e81..18568f7424 100644 --- a/packages/effect/src/Tracer.ts +++ b/packages/effect/src/Tracer.ts @@ -414,18 +414,31 @@ export class NativeSpan implements Span { readonly traceId: string = "native" readonly sampled = true + readonly name: string + readonly parent: Option.Option + readonly context: ServiceMap.ServiceMap + readonly links: ReadonlyArray + readonly startTime: bigint + readonly kind: SpanKind + status: SpanStatus attributes: Map events: Array<[name: string, startTime: bigint, attributes: Record]> = [] constructor( - readonly name: string, - readonly parent: Option.Option, - readonly context: ServiceMap.ServiceMap, - readonly links: ReadonlyArray, - readonly startTime: bigint, - readonly kind: SpanKind + name: string, + parent: Option.Option, + context: ServiceMap.ServiceMap, + links: ReadonlyArray, + startTime: bigint, + kind: SpanKind ) { + this.name = name + this.parent = parent + this.context = context + this.links = links + this.startTime = startTime + this.kind = kind this.status = { _tag: "Started", startTime diff --git a/packages/effect/src/Utils.ts b/packages/effect/src/Utils.ts index 0752639851..81fe4c4be7 100644 --- a/packages/effect/src/Utils.ts +++ b/packages/effect/src/Utils.ts @@ -96,12 +96,19 @@ export const isGenKind = (u: unknown): u is GenKind => * @since 2.0.0 */ export class GenKindImpl implements GenKind { + /** + * @since 2.0.0 + */ + readonly value: Kind + constructor( /** * @since 2.0.0 */ - readonly value: Kind - ) {} + value: Kind + ) { + this.value = value + } /** * @since 2.0.0 @@ -150,8 +157,11 @@ export class GenKindImpl implements GenKind implements IterableIterator { private called = false + readonly self: T - constructor(readonly self: T) {} + constructor(self: T) { + this.self = self + } /** * @since 2.0.0 diff --git a/packages/effect/src/internal/core.ts b/packages/effect/src/internal/core.ts index 0e0218befe..58d704766c 100644 --- a/packages/effect/src/internal/core.ts +++ b/packages/effect/src/internal/core.ts @@ -146,12 +146,16 @@ export const isCause = (self: unknown): self is Cause.Cause => hasPrope /** @internal */ export class CauseImpl implements Cause.Cause { readonly [CauseTypeId]: Cause.TypeId + readonly failures: ReadonlyArray< + Cause.Fail | Cause.Die | Cause.Interrupt + > constructor( - readonly failures: ReadonlyArray< + failures: ReadonlyArray< Cause.Fail | Cause.Die | Cause.Interrupt > ) { this[CauseTypeId] = CauseTypeId + this.failures = failures } pipe() { return pipeArguments(this, arguments) @@ -185,12 +189,14 @@ const errorAnnotations = new WeakMap>() /** @internal */ export abstract class FailureBase implements Cause.Cause.FailureProto { readonly annotations: ReadonlyMap + readonly _tag: Tag constructor( - readonly _tag: Tag, + _tag: Tag, annotations: ReadonlyMap, originalError: unknown ) { + this._tag = _tag if (isObject(originalError)) { if (errorAnnotations.has(originalError)) { annotations = new Map([ @@ -224,11 +230,13 @@ export abstract class FailureBase implements Cause.Cause.Fai /** @internal */ export class Fail extends FailureBase<"Fail"> implements Cause.Fail { + readonly error: E constructor( - readonly error: E, + error: E, annotations = new Map() ) { super("Fail", annotations, error) + this.error = error } toJSON(): unknown { return { @@ -275,11 +283,13 @@ export const causeFail = (error: E): Cause.Cause => new CauseImpl([new Fai /** @internal */ export class Die extends FailureBase<"Die"> implements Cause.Die { + readonly defect: unknown constructor( - readonly defect: unknown, + defect: unknown, annotations = new Map() ) { super("Die", annotations, defect) + this.defect = defect } toJSON(): unknown { return { diff --git a/packages/effect/src/internal/effect.ts b/packages/effect/src/internal/effect.ts index 583e500f17..f948e83a9b 100644 --- a/packages/effect/src/internal/effect.ts +++ b/packages/effect/src/internal/effect.ts @@ -80,11 +80,13 @@ import { version } from "./version.ts" /** @internal */ export class Interrupt extends FailureBase<"Interrupt"> implements Cause.Interrupt { + readonly fiberId: Option.Option constructor( - readonly fiberId: Option.Option, + fiberId: Option.Option, annotations = new Map() ) { super("Interrupt", annotations, "Interrupted") + this.fiberId = fiberId } toJSON(): unknown { return { @@ -3864,8 +3866,11 @@ export const runSync: (effect: Effect.Effect) => A = runSyncWith(Ser class Semaphore { public waiters = new Set<() => void>() public taken = 0 + readonly permits: number - constructor(readonly permits: number) {} + constructor(permits: number) { + this.permits = permits + } get free() { return this.permits - this.taken @@ -3940,7 +3945,11 @@ const succeedFalse = succeed(false) class Latch implements Effect.Latch { waiters: Array<(_: Effect.Effect) => void> = [] scheduled = false - constructor(private isOpen: boolean) {} + private isOpen: boolean + + constructor(isOpen: boolean) { + this.isOpen = isOpen + } private unsafeSchedule(fiber: Fiber.Fiber) { if (this.scheduled || this.waiters.length === 0) { diff --git a/packages/effect/src/internal/hashMap.ts b/packages/effect/src/internal/hashMap.ts index 09223b6498..bf7d3c4379 100644 --- a/packages/effect/src/internal/hashMap.ts +++ b/packages/effect/src/internal/hashMap.ts @@ -105,12 +105,18 @@ class EmptyNode extends Node { /** @internal */ class LeafNode extends Node { + readonly hash: number + readonly key: K + readonly value: V constructor( - readonly hash: number, - readonly key: K, - readonly value: V + hash: number, + key: K, + value: V ) { super() + this.hash = hash + this.key = key + this.value = value } get size(): number { @@ -180,12 +186,14 @@ class LeafNode extends Node { /** @internal */ class CollisionNode extends Node { readonly entries: Array<[K, V]> + readonly hash: number constructor( - readonly hash: number, + hash: number, ...entries: Array<[K, V]> ) { super() + this.hash = hash this.entries = entries } @@ -278,12 +286,16 @@ class CollisionNode extends Node { /** @internal */ class IndexedNode extends Node { private _size: number | undefined + readonly bitmap: number + readonly children: ReadonlyArray> constructor( - readonly bitmap: number, - readonly children: ReadonlyArray> + bitmap: number, + children: ReadonlyArray> ) { super() + this.bitmap = bitmap + this.children = children } get size(): number { @@ -424,12 +436,16 @@ class IndexedNode extends Node { /** @internal */ class ArrayNode extends Node { private _size: number | undefined + readonly count: number + readonly children: ReadonlyArray | undefined> constructor( - readonly count: number, - readonly children: ReadonlyArray | undefined> + count: number, + children: ReadonlyArray | undefined> ) { super() + this.count = count + this.children = children } get size(): number { @@ -557,11 +573,16 @@ class ArrayNode extends Node { /** @internal */ class HashMapImpl implements HashMap { readonly [HashMapTypeId]: HashMapTypeId = HashMapTypeId + readonly root: Node + private readonly _size: number constructor( - readonly root: Node, - private readonly _size: number - ) {} + root: Node, + _size: number + ) { + this.root = root + this._size = _size + } get size(): number { return this._size diff --git a/packages/effect/src/internal/rcRef.ts b/packages/effect/src/internal/rcRef.ts index 73597a9289..c850f9bf82 100644 --- a/packages/effect/src/internal/rcRef.ts +++ b/packages/effect/src/internal/rcRef.ts @@ -43,13 +43,22 @@ class RcRefImpl implements RcRef.RcRef { state: State = stateEmpty readonly semaphore = Effect.unsafeMakeSemaphore(1) + readonly acquire: Effect.Effect + readonly services: ServiceMap.ServiceMap + readonly scope: Scope.Scope + readonly idleTimeToLive: Duration.Duration | undefined constructor( - readonly acquire: Effect.Effect, - readonly services: ServiceMap.ServiceMap, - readonly scope: Scope.Scope, - readonly idleTimeToLive: Duration.Duration | undefined - ) {} + acquire: Effect.Effect, + services: ServiceMap.ServiceMap, + scope: Scope.Scope, + idleTimeToLive: Duration.Duration | undefined + ) { + this.acquire = acquire + this.services = services + this.scope = scope + this.idleTimeToLive = idleTimeToLive + } } /** @internal */ diff --git a/packages/effect/src/internal/trie.ts b/packages/effect/src/internal/trie.ts index 21d276479d..583cf0b626 100644 --- a/packages/effect/src/internal/trie.ts +++ b/packages/effect/src/internal/trie.ts @@ -77,12 +77,18 @@ const makeImpl = (root: Node | undefined): TrieImpl => { class TrieIterator implements IterableIterator { stack: Array<[Node, string, boolean]> = [] + readonly trie: TrieImpl + readonly f: TraversalMap + readonly filter: TraversalFilter constructor( - readonly trie: TrieImpl, - readonly f: TraversalMap, - readonly filter: TraversalFilter + trie: TrieImpl, + f: TraversalMap, + filter: TraversalFilter ) { + this.trie = trie + this.f = f + this.filter = filter const root = trie._root !== undefined ? trie._root : undefined if (root !== undefined) { this.stack.push([root, "", false]) diff --git a/packages/effect/src/schema/AST.ts b/packages/effect/src/schema/AST.ts index 0283bf9ba3..4eebe518c8 100644 --- a/packages/effect/src/schema/AST.ts +++ b/packages/effect/src/schema/AST.ts @@ -193,10 +193,16 @@ export type Transformation = Transformation_.Transformation * @since 4.0.0 */ export class Link { + readonly to: AST + readonly transformation: Transformation | Middleware + constructor( - readonly to: AST, - readonly transformation: Transformation | Middleware - ) {} + to: AST, + transformation: Transformation | Middleware + ) { + this.to = to + this.transformation = transformation + } } /** @@ -267,15 +273,29 @@ export interface ParseOptions { * @since 4.0.0 */ export class Context { + readonly isOptional: boolean + readonly isMutable: boolean + /** Used for constructor default values (e.g. `withConstructorDefault` API) */ + readonly defaultValue: Encoding | undefined + /** Used for constructor encoding (e.g. `Class` API) */ + readonly make: Encoding | undefined + readonly annotations: Annotations.Key | undefined + constructor( - readonly isOptional: boolean, - readonly isMutable: boolean, + isOptional: boolean, + isMutable: boolean, /** Used for constructor default values (e.g. `withConstructorDefault` API) */ - readonly defaultValue: Encoding | undefined = undefined, + defaultValue: Encoding | undefined = undefined, /** Used for constructor encoding (e.g. `Class` API) */ - readonly make: Encoding | undefined = undefined, - readonly annotations: Annotations.Key | undefined = undefined - ) {} + make: Encoding | undefined = undefined, + annotations: Annotations.Key | undefined = undefined + ) { + this.isOptional = isOptional + this.isMutable = isMutable + this.defaultValue = defaultValue + this.make = make + this.annotations = annotations + } } /** @@ -289,12 +309,22 @@ export type Checks = readonly [Check.Check, ...ReadonlyArray + readonly run: ( + typeParameters: ReadonlyArray + ) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect constructor( - readonly typeParameters: ReadonlyArray, - readonly run: ( + typeParameters: ReadonlyArray, + run: ( typeParameters: ReadonlyArray ) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect, annotations?: Annotations.Annotations, @@ -335,6 +369,8 @@ export class Declaration extends Base { context?: Context ) { super(annotations, checks, encoding, context) + this.typeParameters = typeParameters + this.run = run } /** @internal */ typeAST(): Declaration { @@ -487,14 +523,17 @@ export class ObjectKeyword extends AbstractParser { */ export class Enums extends AbstractParser { readonly _tag = "Enums" + readonly enums: ReadonlyArray + constructor( - readonly enums: ReadonlyArray, + enums: ReadonlyArray, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.enums = enums } /** @internal */ parser() { @@ -560,16 +599,19 @@ function isASTPart(ast: AST): ast is TemplateLiteral.ASTPart { */ export class TemplateLiteral extends AbstractParser { readonly _tag = "TemplateLiteral" + readonly parts: ReadonlyArray /** @internal */ readonly flippedParts: ReadonlyArray + constructor( - readonly parts: ReadonlyArray, + parts: ReadonlyArray, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.parts = parts const flippedParts: Array = [] for (const part of parts) { if (Predicate.isObject(part)) { @@ -660,14 +702,17 @@ export type Literal = string | number | boolean | bigint */ export class UniqueSymbol extends AbstractParser { readonly _tag = "UniqueSymbol" + readonly symbol: symbol + constructor( - readonly symbol: symbol, + symbol: symbol, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.symbol = symbol } /** @internal */ parser() { @@ -681,14 +726,17 @@ export class UniqueSymbol extends AbstractParser { */ export class LiteralType extends AbstractParser { readonly _tag = "LiteralType" + readonly literal: Literal + constructor( - readonly literal: Literal, + literal: Literal, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.literal = literal if (process.env.NODE_ENV !== "production") { if (Predicate.isNumber(this.literal) && !Number.isFinite(this.literal)) { throw new Error("LiteralType must be a finite number") @@ -791,10 +839,16 @@ export const bigIntKeyword = new BigIntKeyword() * @since 4.0.0 */ export class PropertySignature { + readonly name: PropertyKey + readonly type: AST + constructor( - readonly name: PropertyKey, - readonly type: AST - ) {} + name: PropertyKey, + type: AST + ) { + this.name = name + this.type = type + } } /** @@ -811,10 +865,16 @@ export type Combine = ( * @since 4.0.0 */ export class Merge { + readonly decode: Combine | undefined + readonly encode: Combine | undefined + constructor( - readonly decode: Combine | undefined, - readonly encode: Combine | undefined - ) {} + decode: Combine | undefined, + encode: Combine | undefined + ) { + this.decode = decode + this.encode = encode + } /** @internal */ flip(): Merge { return new Merge(this.encode, this.decode) @@ -826,12 +886,21 @@ export class Merge { * @since 4.0.0 */ export class IndexSignature { + readonly isMutable: boolean + readonly parameter: AST + readonly type: AST + readonly merge: Merge | undefined + constructor( - readonly isMutable: boolean, - readonly parameter: AST, - readonly type: AST, - readonly merge: Merge | undefined + isMutable: boolean, + parameter: AST, + type: AST, + merge: Merge | undefined ) { + this.isMutable = isMutable + this.parameter = parameter + this.type = type + this.merge = merge if (process.env.NODE_ENV !== "production") { if (isOptional(type) && !containsUndefined(type)) { throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.") @@ -846,16 +915,23 @@ export class IndexSignature { */ export class TupleType extends Base { readonly _tag = "TupleType" + readonly isMutable: boolean + readonly elements: ReadonlyArray + readonly rest: ReadonlyArray + constructor( - readonly isMutable: boolean, - readonly elements: ReadonlyArray, - readonly rest: ReadonlyArray, + isMutable: boolean, + elements: ReadonlyArray, + rest: ReadonlyArray, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.isMutable = isMutable + this.elements = elements + this.rest = rest if (process.env.NODE_ENV !== "production") { // A required element cannot follow an optional element. ts(1257) @@ -1052,15 +1128,20 @@ export function getIndexSignatureKeys( */ export class TypeLiteral extends Base { readonly _tag = "TypeLiteral" + readonly propertySignatures: ReadonlyArray + readonly indexSignatures: ReadonlyArray + constructor( - readonly propertySignatures: ReadonlyArray, - readonly indexSignatures: ReadonlyArray, + propertySignatures: ReadonlyArray, + indexSignatures: ReadonlyArray, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.propertySignatures = propertySignatures + this.indexSignatures = indexSignatures if (process.env.NODE_ENV !== "production") { // Duplicate property signatures @@ -1551,15 +1632,20 @@ export function getCandidates(input: any, types: ReadonlyArray): ReadonlyAr */ export class UnionType extends Base { readonly _tag = "UnionType" + readonly types: ReadonlyArray + readonly mode: "anyOf" | "oneOf" + constructor( - readonly types: ReadonlyArray, - readonly mode: "anyOf" | "oneOf", + types: ReadonlyArray, + mode: "anyOf" | "oneOf", annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context ) { super(annotations, checks, encoding, context) + this.types = types + this.mode = mode } /** @internal */ typeAST(): UnionType { @@ -1634,8 +1720,10 @@ export class UnionType extends Base { */ export class Suspend extends Base { readonly _tag = "Suspend" + readonly thunk: () => AST + constructor( - readonly thunk: () => AST, + thunk: () => AST, annotations?: Annotations.Annotations, checks?: Checks, encoding?: Encoding, diff --git a/packages/effect/src/schema/Check.ts b/packages/effect/src/schema/Check.ts index 6be828b75d..6f027e05df 100644 --- a/packages/effect/src/schema/Check.ts +++ b/packages/effect/src/schema/Check.ts @@ -20,15 +20,25 @@ import * as Issue from "./Issue.ts" */ export class Filter extends PipeableClass implements Annotations.Annotated { readonly _tag = "Filter" + readonly run: (input: E, self: AST.AST, options: AST.ParseOptions) => Issue.Issue | undefined + readonly annotations: Annotations.Filter | undefined + /** + * Whether the parsing process should be aborted after this check has failed. + */ + readonly abort: boolean + constructor( - readonly run: (input: E, self: AST.AST, options: AST.ParseOptions) => Issue.Issue | undefined, - readonly annotations: Annotations.Filter | undefined = undefined, + run: (input: E, self: AST.AST, options: AST.ParseOptions) => Issue.Issue | undefined, + annotations: Annotations.Filter | undefined = undefined, /** * Whether the parsing process should be aborted after this check has failed. */ - readonly abort: boolean = false + abort: boolean = false ) { super() + this.run = run + this.annotations = annotations + this.abort = abort } annotate(annotations: Annotations.Filter): Filter { return new Filter(this.run, { ...this.annotations, ...annotations }, this.abort) @@ -46,11 +56,16 @@ export class Filter extends PipeableClass implements Annotations.Annotated */ export class FilterGroup extends PipeableClass implements Annotations.Annotated { readonly _tag = "FilterGroup" + readonly checks: readonly [Check, Check, ...ReadonlyArray>] + readonly annotations: Annotations.Filter | undefined + constructor( - readonly checks: readonly [Check, Check, ...ReadonlyArray>], - readonly annotations: Annotations.Filter | undefined = undefined + checks: readonly [Check, Check, ...ReadonlyArray>], + annotations: Annotations.Filter | undefined = undefined ) { super() + this.checks = checks + this.annotations = annotations } annotate(annotations: Annotations.Filter): FilterGroup { return new FilterGroup(this.checks, { ...this.annotations, ...annotations }) diff --git a/packages/effect/src/schema/Formatter.ts b/packages/effect/src/schema/Formatter.ts index b234304791..6fb27c5290 100644 --- a/packages/effect/src/schema/Formatter.ts +++ b/packages/effect/src/schema/Formatter.ts @@ -97,10 +97,16 @@ function findMessage( interface Forest extends ReadonlyArray {} class Tree { + readonly value: string + readonly forest: Forest + constructor( - readonly value: string, - readonly forest: Forest = [] - ) {} + value: string, + forest: Forest = [] + ) { + this.value = value + this.forest = forest + } draw(): string { return this.value + draw("\n", this.forest) } diff --git a/packages/effect/src/schema/Getter.ts b/packages/effect/src/schema/Getter.ts index 30a04fbfb5..e84fc6cbf2 100644 --- a/packages/effect/src/schema/Getter.ts +++ b/packages/effect/src/schema/Getter.ts @@ -16,13 +16,19 @@ import * as Issue from "./Issue.ts" * @since 4.0.0 */ export class Getter extends PipeableClass { + readonly run: ( + input: Option.Option, + options: AST.ParseOptions + ) => Effect.Effect, Issue.Issue, R> + constructor( - readonly run: ( + run: ( input: Option.Option, options: AST.ParseOptions ) => Effect.Effect, Issue.Issue, R> ) { super() + this.run = run } compose(other: Getter): Getter { if (isPassthrough(this)) { diff --git a/packages/effect/src/schema/Issue.ts b/packages/effect/src/schema/Issue.ts index 1f1b0c5cb7..b67537ba4e 100644 --- a/packages/effect/src/schema/Issue.ts +++ b/packages/effect/src/schema/Issue.ts @@ -57,21 +57,37 @@ class Base { */ export class Filter extends Base { readonly _tag = "Filter" + /** + * The input value that caused the issue. + */ + readonly actual: unknown + /** + * The filter that failed. + */ + readonly filter: Check.Filter + /** + * The issue that occurred. + */ + readonly issue: Issue + constructor( /** * The input value that caused the issue. */ - readonly actual: unknown, + actual: unknown, /** * The filter that failed. */ - readonly filter: Check.Filter, + filter: Check.Filter, /** * The issue that occurred. */ - readonly issue: Issue + issue: Issue ) { super() + this.actual = actual + this.filter = filter + this.issue = issue } } @@ -83,21 +99,37 @@ export class Filter extends Base { */ export class Encoding extends Base { readonly _tag = "Encoding" + /** + * The schema that caused the issue. + */ + readonly ast: AST.AST + /** + * The input value that caused the issue. + */ + readonly actual: Option.Option + /** + * The issue that occurred. + */ + readonly issue: Issue + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.AST, + ast: AST.AST, /** * The input value that caused the issue. */ - readonly actual: Option.Option, + actual: Option.Option, /** * The issue that occurred. */ - readonly issue: Issue + issue: Issue ) { super() + this.ast = ast + this.actual = actual + this.issue = issue } } @@ -109,17 +141,28 @@ export class Encoding extends Base { */ export class Pointer extends Base { readonly _tag = "Pointer" + /** + * The path to the location in the input that caused the issue. + */ + readonly path: ReadonlyArray + /** + * The issue that occurred. + */ + readonly issue: Issue + constructor( /** * The path to the location in the input that caused the issue. */ - readonly path: ReadonlyArray, + path: ReadonlyArray, /** * The issue that occurred. */ - readonly issue: Issue + issue: Issue ) { super() + this.path = path + this.issue = issue } } @@ -131,13 +174,19 @@ export class Pointer extends Base { */ export class MissingKey extends Base { readonly _tag = "MissingKey" + /** + * The metadata for the issue. + */ + readonly annotations: Annotations.Key | undefined + constructor( /** * The metadata for the issue. */ - readonly annotations: Annotations.Key | undefined + annotations: Annotations.Key | undefined ) { super() + this.annotations = annotations } } @@ -149,17 +198,28 @@ export class MissingKey extends Base { */ export class UnexpectedKey extends Base { readonly _tag = "UnexpectedKey" + /** + * The schema that caused the issue. + */ + readonly ast: AST.AST + /** + * The input value that caused the issue. + */ + readonly actual: unknown + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.AST, + ast: AST.AST, /** * The input value that caused the issue. */ - readonly actual: unknown + actual: unknown ) { super() + this.ast = ast + this.actual = actual } } @@ -171,21 +231,37 @@ export class UnexpectedKey extends Base { */ export class Composite extends Base { readonly _tag = "Composite" + /** + * The schema that caused the issue. + */ + readonly ast: AST.AST + /** + * The input value that caused the issue. + */ + readonly actual: Option.Option + /** + * The issues that occurred. + */ + readonly issues: readonly [Issue, ...ReadonlyArray] + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.AST, + ast: AST.AST, /** * The input value that caused the issue. */ - readonly actual: Option.Option, + actual: Option.Option, /** * The issues that occurred. */ - readonly issues: readonly [Issue, ...ReadonlyArray] + issues: readonly [Issue, ...ReadonlyArray] ) { super() + this.ast = ast + this.actual = actual + this.issues = issues } } @@ -198,17 +274,28 @@ export class Composite extends Base { */ export class InvalidType extends Base { readonly _tag = "InvalidType" + /** + * The schema that caused the issue. + */ + readonly ast: AST.AST + /** + * The input value that caused the issue. + */ + readonly actual: Option.Option + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.AST, + ast: AST.AST, /** * The input value that caused the issue. */ - readonly actual: Option.Option + actual: Option.Option ) { super() + this.ast = ast + this.actual = actual } } @@ -220,17 +307,28 @@ export class InvalidType extends Base { */ export class InvalidValue extends Base { readonly _tag = "InvalidValue" + /** + * The value that caused the issue. + */ + readonly actual: Option.Option + /** + * The metadata for the issue. + */ + readonly annotations?: Annotations.Annotations | undefined + constructor( /** * The value that caused the issue. */ - readonly actual: Option.Option, + actual: Option.Option, /** * The metadata for the issue. */ - readonly annotations?: Annotations.Annotations | undefined + annotations?: Annotations.Annotations | undefined ) { super() + this.actual = actual + this.annotations = annotations } } @@ -244,17 +342,28 @@ export class InvalidValue extends Base { */ export class Forbidden extends Base { readonly _tag = "Forbidden" + /** + * The input value that caused the issue. + */ + readonly actual: Option.Option + /** + * The metadata for the issue. + */ + readonly annotations: Annotations.Annotations | undefined + constructor( /** * The input value that caused the issue. */ - readonly actual: Option.Option, + actual: Option.Option, /** * The metadata for the issue. */ - readonly annotations: Annotations.Annotations | undefined + annotations: Annotations.Annotations | undefined ) { super() + this.actual = actual + this.annotations = annotations } } @@ -267,21 +376,37 @@ export class Forbidden extends Base { */ export class AnyOf extends Base { readonly _tag = "AnyOf" + /** + * The schema that caused the issue. + */ + readonly ast: AST.AST + /** + * The input value that caused the issue. + */ + readonly actual: Option.Option + /** + * The issues that occurred. + */ + readonly issues: readonly [Issue, ...ReadonlyArray] + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.AST, + ast: AST.AST, /** * The input value that caused the issue. */ - readonly actual: Option.Option, + actual: Option.Option, /** * The issues that occurred. */ - readonly issues: readonly [Issue, ...ReadonlyArray] + issues: readonly [Issue, ...ReadonlyArray] ) { super() + this.ast = ast + this.actual = actual + this.issues = issues } } @@ -294,21 +419,37 @@ export class AnyOf extends Base { */ export class OneOf extends Base { readonly _tag = "OneOf" + /** + * The schema that caused the issue. + */ + readonly ast: AST.UnionType + /** + * The input value that caused the issue. + */ + readonly actual: unknown + /** + * The schemas that were successful. + */ + readonly successes: ReadonlyArray + constructor( /** * The schema that caused the issue. */ - readonly ast: AST.UnionType, + ast: AST.UnionType, /** * The input value that caused the issue. */ - readonly actual: unknown, + actual: unknown, /** * The schemas that were successful. */ - readonly successes: ReadonlyArray + successes: ReadonlyArray ) { super() + this.ast = ast + this.actual = actual + this.successes = successes } } diff --git a/packages/effect/src/schema/Schema.ts b/packages/effect/src/schema/Schema.ts index e46b1ee249..6e821f53fe 100644 --- a/packages/effect/src/schema/Schema.ts +++ b/packages/effect/src/schema/Schema.ts @@ -246,9 +246,11 @@ export abstract class Bottom$< declare readonly "~encoded.mutability": EncodedMutability declare readonly "~encoded.optionality": EncodedOptionality + readonly ast: Ast readonly makeSync: (input: this["~type.make.in"], options?: MakeOptions) => this["Type"] - constructor(readonly ast: Ast) { + constructor(ast: Ast) { + this.ast = ast this.makeSync = ToParser.makeSync(this) } abstract rebuild(ast: this["ast"]): this["~rebuild.out"] @@ -708,17 +710,23 @@ class make$ extends Bottom$< S["~encoded.mutability"], S["~encoded.optionality"] > { + readonly rebuild: (ast: S["ast"]) => S["~rebuild.out"] + constructor( ast: S["ast"], - readonly rebuild: (ast: S["ast"]) => S["~rebuild.out"] + rebuild: (ast: S["ast"]) => S["~rebuild.out"] ) { super(ast) + this.rebuild = rebuild } } class makeWithSchema$ extends make$ { - constructor(ast: AST.AST, readonly schema: S) { - super(ast, (ast) => new makeWithSchema$(ast, this.schema)) + readonly schema: S + + constructor(ast: AST.AST, schema: S) { + super(ast, (ast) => new makeWithSchema$(ast, schema)) + this.schema = schema } } @@ -1037,8 +1045,11 @@ export interface Literal } class Literal$ extends make$> implements Literal { - constructor(ast: AST.LiteralType, readonly literal: L) { + readonly literal: L + + constructor(ast: AST.LiteralType, literal: L) { super(ast, (ast) => new Literal$(ast, literal)) + this.literal = literal } } @@ -1102,8 +1113,11 @@ export interface TemplateLiteral extends class TemplateLiteral$ extends make$> implements TemplateLiteral { - constructor(ast: AST.TemplateLiteral, readonly parts: Parts) { + readonly parts: Parts + + constructor(ast: AST.TemplateLiteral, parts: Parts) { super(ast, (ast) => new TemplateLiteral$(ast, parts)) + this.parts = parts } } @@ -1157,8 +1171,11 @@ export interface TemplateLiteralParser exte class TemplateLiteralParser$ extends make$> implements TemplateLiteralParser { - constructor(ast: AST.TupleType, readonly parts: Parts) { + readonly parts: Parts + + constructor(ast: AST.TupleType, parts: Parts) { super(ast, (ast) => new TemplateLiteralParser$(ast, parts)) + this.parts = parts } } @@ -1184,8 +1201,11 @@ export interface Enums } class Enums$ extends make$> implements Enums { - constructor(ast: AST.Enums, readonly enums: A) { + readonly enums: A + + constructor(ast: AST.Enums, enums: A) { super(ast, (ast) => new Enums$(ast, enums)) + this.enums = enums } } @@ -1687,8 +1707,13 @@ export interface Record$ extends class Record$$ extends make$> implements Record$ { - constructor(ast: AST.TypeLiteral, readonly key: Key, readonly value: Value) { + readonly key: Key + readonly value: Value + + constructor(ast: AST.TypeLiteral, key: Key, value: Value) { super(ast, (ast) => new Record$$(ast, key, value)) + this.key = key + this.value = value } } @@ -1798,9 +1823,12 @@ class StructWithRest$$> implements StructWithRest { + readonly schema: S readonly records: Records - constructor(ast: AST.TypeLiteral, readonly schema: S, records: Records) { + + constructor(ast: AST.TypeLiteral, schema: S, records: Records) { super(ast, (ast) => new StructWithRest$$(ast, this.schema, this.records)) + this.schema = schema // clone to avoid accidental external mutation this.records = [...records] as any } @@ -2028,9 +2056,12 @@ export interface TupleWithRest< class TupleWithRest$ | mutable>, Rest extends TupleWithRest.Rest> extends make$> { + readonly schema: S readonly rest: Rest - constructor(ast: AST.TupleType, readonly schema: S, rest: Rest) { + + constructor(ast: AST.TupleType, schema: S, rest: Rest) { super(ast, (ast) => new TupleWithRest$(ast, this.schema, this.rest)) + this.schema = schema // clone to avoid accidental external mutation this.rest = [...rest] } @@ -2247,8 +2278,13 @@ export interface Union> extends } class Union$> extends make$> implements Union { - constructor(readonly ast: AST.UnionType, readonly members: Members) { + readonly ast: AST.UnionType + readonly members: Members + + constructor(ast: AST.UnionType, members: Members) { super(ast, (ast) => new Union$(ast, members)) + this.ast = ast + this.members = members } mapMembers>( @@ -2306,12 +2342,17 @@ export interface Literals> extends } class Literals$> extends make$> implements Literals { + readonly literals: L + readonly members: { readonly [K in keyof L]: Literal } + constructor( ast: AST.UnionType, - readonly literals: L, - readonly members: { readonly [K in keyof L]: Literal } + literals: L, + members: { readonly [K in keyof L]: Literal } ) { super(ast, (ast) => new Literals$(ast, literals, members)) + this.literals = literals + this.members = members } mapMembers>(f: (members: this["members"]) => To): Union>> { @@ -2664,12 +2705,19 @@ export interface compose extends decodeTo extends make$> implements decodeTo { + readonly ast: From["ast"] + readonly from: From + readonly to: To + constructor( - readonly ast: From["ast"], - readonly from: From, - readonly to: To + ast: From["ast"], + from: From, + to: To ) { - super(ast, (ast) => new decodeTo$(ast, this.from, this.to)) + super(ast, (ast) => new decodeTo$(ast, from, to)) + this.ast = ast + this.from = from + this.to = to } } @@ -3037,14 +3085,30 @@ export interface TaggedUnion> extends } class TaggedUnion$> extends make$> implements TaggedUnion { + readonly ast: AST.UnionType + readonly cases: Cases + readonly isAnyOf: ( + keys: ReadonlyArray + ) => (value: Cases[keyof Cases]["Type"]) => value is Extract + readonly guards: { [K in keyof Cases]: (u: unknown) => u is Cases[K]["Type"] } + readonly match: { + ( + value: Cases[keyof Cases]["Type"], + cases: { [K in keyof Cases]: (value: Cases[K]["Type"]) => Output } + ): Output + ( + cases: { [K in keyof Cases]: (value: Cases[K]["Type"]) => Output } + ): (value: Cases[keyof Cases]["Type"]) => Output + } + constructor( - readonly ast: AST.UnionType, - readonly cases: Cases, - readonly isAnyOf: ( + ast: AST.UnionType, + cases: Cases, + isAnyOf: ( keys: ReadonlyArray ) => (value: Cases[keyof Cases]["Type"]) => value is Extract, - readonly guards: { [K in keyof Cases]: (u: unknown) => u is Cases[K]["Type"] }, - readonly match: { + guards: { [K in keyof Cases]: (u: unknown) => u is Cases[K]["Type"] }, + match: { ( value: Cases[keyof Cases]["Type"], cases: { [K in keyof Cases]: (value: Cases[K]["Type"]) => Output } @@ -3055,6 +3119,11 @@ class TaggedUnion$> extends make$ new TaggedUnion$(ast, cases, isAnyOf, guards, match)) + this.ast = ast + this.cases = cases + this.isAnyOf = isAnyOf + this.guards = guards + this.match = match } } diff --git a/packages/effect/src/schema/Transformation.ts b/packages/effect/src/schema/Transformation.ts index aa4aa26cf3..2695145d3f 100644 --- a/packages/effect/src/schema/Transformation.ts +++ b/packages/effect/src/schema/Transformation.ts @@ -14,16 +14,28 @@ import type * as Issue from "./Issue.ts" */ export class Middleware { readonly _tag = "Middleware" + readonly decode: ( + sr: Effect.Effect, Issue.Issue, RD1>, + options: AST.ParseOptions + ) => Effect.Effect, Issue.Issue, RD2> + readonly encode: ( + sr: Effect.Effect, Issue.Issue, RE1>, + options: AST.ParseOptions + ) => Effect.Effect, Issue.Issue, RE2> + constructor( - readonly decode: ( + decode: ( sr: Effect.Effect, Issue.Issue, RD1>, options: AST.ParseOptions ) => Effect.Effect, Issue.Issue, RD2>, - readonly encode: ( + encode: ( sr: Effect.Effect, Issue.Issue, RE1>, options: AST.ParseOptions ) => Effect.Effect, Issue.Issue, RE2> - ) {} + ) { + this.decode = decode + this.encode = encode + } flip(): Middleware { return new Middleware(this.encode, this.decode) } @@ -35,10 +47,16 @@ export class Middleware { */ export class Transformation { readonly _tag = "Transformation" + readonly decode: Getter.Getter + readonly encode: Getter.Getter + constructor( - readonly decode: Getter.Getter, - readonly encode: Getter.Getter - ) {} + decode: Getter.Getter, + encode: Getter.Getter + ) { + this.decode = decode + this.encode = encode + } flip(): Transformation { return new Transformation(this.encode, this.decode) } diff --git a/packages/effect/src/unstable/http/HttpBody.ts b/packages/effect/src/unstable/http/HttpBody.ts index 38b65c3137..1dfd829e9d 100644 --- a/packages/effect/src/unstable/http/HttpBody.ts +++ b/packages/effect/src/unstable/http/HttpBody.ts @@ -144,12 +144,19 @@ export const empty: Empty = new Empty() */ export class Raw extends Proto { readonly _tag = "Raw" + readonly body: unknown + readonly contentType: string | undefined + readonly contentLength: number | undefined + constructor( - readonly body: unknown, - readonly contentType: string | undefined, - readonly contentLength: number | undefined + body: unknown, + contentType: string | undefined, + contentLength: number | undefined ) { super() + this.body = body + this.contentType = contentType + this.contentLength = contentLength } toJSON(): unknown { return { @@ -180,12 +187,19 @@ export const raw = ( */ export class Uint8Array extends Proto { readonly _tag = "Uint8Array" + readonly body: globalThis.Uint8Array + readonly contentType: string + readonly contentLength: number + constructor( - readonly body: globalThis.Uint8Array, - readonly contentType: string, - readonly contentLength: number + body: globalThis.Uint8Array, + contentType: string, + contentLength: number ) { super() + this.body = body + this.contentType = contentType + this.contentLength = contentLength } toJSON(): unknown { const toString = this.contentType.startsWith("text/") || this.contentType.endsWith("json") @@ -262,8 +276,13 @@ export class FormData extends Proto { readonly _tag = "FormData" readonly contentType = undefined readonly contentLength = undefined - constructor(readonly formData: globalThis.FormData) { + readonly formData: globalThis.FormData + + constructor( + formData: globalThis.FormData + ) { super() + this.formData = formData } toJSON(): unknown { return { @@ -286,12 +305,19 @@ export const formData = (body: globalThis.FormData): FormData => new FormData(bo */ export class Stream extends Proto { readonly _tag = "Stream" + readonly stream: Stream_.Stream + readonly contentType: string + readonly contentLength: number | undefined + constructor( - readonly stream: Stream_.Stream, - readonly contentType: string, - readonly contentLength: number | undefined + stream: Stream_.Stream, + contentType: string, + contentLength: number | undefined ) { super() + this.stream = stream + this.contentType = contentType + this.contentLength = contentLength } toJSON(): unknown { return { diff --git a/packages/effect/src/unstable/http/HttpClient.ts b/packages/effect/src/unstable/http/HttpClient.ts index 1474f1b3df..f229002739 100644 --- a/packages/effect/src/unstable/http/HttpClient.ts +++ b/packages/effect/src/unstable/http/HttpClient.ts @@ -1030,10 +1030,16 @@ const responseRegistry = (() => { const scopedRequests = new WeakMap() class InterruptibleResponse implements HttpClientResponse.HttpClientResponse { + readonly original: HttpClientResponse.HttpClientResponse + readonly controller: AbortController + constructor( - readonly original: HttpClientResponse.HttpClientResponse, - readonly controller: AbortController - ) {} + original: HttpClientResponse.HttpClientResponse, + controller: AbortController + ) { + this.original = original + this.controller = controller + } readonly [HttpClientResponse.TypeId]: HttpClientResponse.TypeId = HttpClientResponse.TypeId readonly [HttpIncomingMessage.TypeId]: HttpIncomingMessage.TypeId = HttpIncomingMessage.TypeId diff --git a/packages/effect/src/unstable/http/HttpClientResponse.ts b/packages/effect/src/unstable/http/HttpClientResponse.ts index 636839595d..b52091beee 100644 --- a/packages/effect/src/unstable/http/HttpClientResponse.ts +++ b/packages/effect/src/unstable/http/HttpClientResponse.ts @@ -221,11 +221,16 @@ class WebHttpClientResponse extends Inspectable.Class implements HttpClientRespo readonly [HttpIncomingMessage.TypeId]: HttpIncomingMessage.TypeId readonly [TypeId]: TypeId + readonly request: HttpClientRequest.HttpClientRequest + private readonly source: globalThis.Response + constructor( - readonly request: HttpClientRequest.HttpClientRequest, - private readonly source: globalThis.Response + request: HttpClientRequest.HttpClientRequest, + source: globalThis.Response ) { super() + this.request = request + this.source = source this[HttpIncomingMessage.TypeId] = HttpIncomingMessage.TypeId this[TypeId] = TypeId } diff --git a/packages/effect/src/unstable/http/HttpRouter.ts b/packages/effect/src/unstable/http/HttpRouter.ts index e0526bf88f..7f2156c8b0 100644 --- a/packages/effect/src/unstable/http/HttpRouter.ts +++ b/packages/effect/src/unstable/http/HttpRouter.ts @@ -848,10 +848,15 @@ class MiddlewareImpl< > implements Middleware { readonly [MiddlewareTypeId]: Config = {} as any + readonly layerFn: Layer.Layer + readonly dependencies?: Layer.Layer | undefined + constructor( - readonly layerFn: Layer.Layer, - readonly dependencies?: Layer.Layer + layerFn: Layer.Layer, + dependencies?: Layer.Layer ) { + this.layerFn = layerFn + this.dependencies = dependencies const contextKey = `effect/http/HttpRouter/Middleware-${++middlewareId}` as const this.layer = Layer.effectDiscard(Effect.gen(this, function*() { const context = yield* Effect.services() diff --git a/packages/effect/src/unstable/http/HttpServerRequest.ts b/packages/effect/src/unstable/http/HttpServerRequest.ts index 2e6419c321..3c3b11557d 100644 --- a/packages/effect/src/unstable/http/HttpServerRequest.ts +++ b/packages/effect/src/unstable/http/HttpServerRequest.ts @@ -301,15 +301,24 @@ const removeHost = (url: string) => { class ServerRequestImpl extends Inspectable.Class implements HttpServerRequest { readonly [TypeId]: TypeId readonly [HttpIncomingMessage.TypeId]: HttpIncomingMessage.TypeId + readonly source: Request + readonly url: string + public headersOverride?: Headers.Headers | undefined + private remoteAddressOverride?: string | undefined + constructor( - readonly source: Request, - readonly url: string, - public headersOverride?: Headers.Headers, - private remoteAddressOverride?: string + source: Request, + url: string, + headersOverride?: Headers.Headers, + remoteAddressOverride?: string ) { super() this[TypeId] = TypeId this[HttpIncomingMessage.TypeId] = HttpIncomingMessage.TypeId + this.source = source + this.url = url + this.headersOverride = headersOverride + this.remoteAddressOverride = remoteAddressOverride } toJSON(): unknown { return HttpIncomingMessage.inspect(this, { diff --git a/packages/effect/src/unstable/http/Multipart.ts b/packages/effect/src/unstable/http/Multipart.ts index aee1a7ccd2..9a19b3df63 100644 --- a/packages/effect/src/unstable/http/Multipart.ts +++ b/packages/effect/src/unstable/http/Multipart.ts @@ -380,13 +380,19 @@ abstract class PartBase extends Inspectable.Class { class FieldImpl extends PartBase implements Field { readonly _tag = "Field" + readonly key: string + readonly contentType: string + readonly value: string constructor( - readonly key: string, - readonly contentType: string, - readonly value: string + key: string, + contentType: string, + value: string ) { super() + this.key = key + this.contentType = contentType + this.value = value } toJSON(): unknown { @@ -513,14 +519,22 @@ export const toPersisted = ( class PersistedFileImpl extends PartBase implements PersistedFile { readonly _tag = "PersistedFile" + readonly key: string + readonly name: string + readonly contentType: string + readonly path: string constructor( - readonly key: string, - readonly name: string, - readonly contentType: string, - readonly path: string + key: string, + name: string, + contentType: string, + path: string ) { super() + this.key = key + this.name = name + this.contentType = contentType + this.path = path } toJSON(): unknown { diff --git a/packages/effect/src/unstable/socket/Socket.ts b/packages/effect/src/unstable/socket/Socket.ts index 0f4a9051dc..a5c5ea296a 100644 --- a/packages/effect/src/unstable/socket/Socket.ts +++ b/packages/effect/src/unstable/socket/Socket.ts @@ -82,8 +82,13 @@ export class CloseEvent { * @since 4.0.0 */ readonly [CloseEventTypeId]: CloseEventTypeId - constructor(readonly code = 1000, readonly reason?: string) { + readonly code: number + readonly reason?: string | undefined + + constructor(code = 1000, reason?: string) { this[CloseEventTypeId] = CloseEventTypeId + this.code = code + this.reason = reason } /** * @since 4.0.0 diff --git a/packages/effect/src/unstable/tracing/OtlpLogger.ts b/packages/effect/src/unstable/tracing/OtlpLogger.ts index 3d2fd4b05d..777a09baa2 100644 --- a/packages/effect/src/unstable/tracing/OtlpLogger.ts +++ b/packages/effect/src/unstable/tracing/OtlpLogger.ts @@ -217,31 +217,33 @@ const logLevelToSeverityNumber = (logLevel: LogLevel.LogLevel): ESeverityNumber /** * Numerical value of the severity, normalized to values described in Log Data Model. */ -const enum ESeverityNumber { +const ESeverityNumber = { /** Unspecified. Do NOT use as default */ - SEVERITY_NUMBER_UNSPECIFIED = 0, - SEVERITY_NUMBER_TRACE = 1, - SEVERITY_NUMBER_TRACE2 = 2, - SEVERITY_NUMBER_TRACE3 = 3, - SEVERITY_NUMBER_TRACE4 = 4, - SEVERITY_NUMBER_DEBUG = 5, - SEVERITY_NUMBER_DEBUG2 = 6, - SEVERITY_NUMBER_DEBUG3 = 7, - SEVERITY_NUMBER_DEBUG4 = 8, - SEVERITY_NUMBER_INFO = 9, - SEVERITY_NUMBER_INFO2 = 10, - SEVERITY_NUMBER_INFO3 = 11, - SEVERITY_NUMBER_INFO4 = 12, - SEVERITY_NUMBER_WARN = 13, - SEVERITY_NUMBER_WARN2 = 14, - SEVERITY_NUMBER_WARN3 = 15, - SEVERITY_NUMBER_WARN4 = 16, - SEVERITY_NUMBER_ERROR = 17, - SEVERITY_NUMBER_ERROR2 = 18, - SEVERITY_NUMBER_ERROR3 = 19, - SEVERITY_NUMBER_ERROR4 = 20, - SEVERITY_NUMBER_FATAL = 21, - SEVERITY_NUMBER_FATAL2 = 22, - SEVERITY_NUMBER_FATAL3 = 23, - SEVERITY_NUMBER_FATAL4 = 24 -} + SEVERITY_NUMBER_UNSPECIFIED: 0, + SEVERITY_NUMBER_TRACE: 1, + SEVERITY_NUMBER_TRACE2: 2, + SEVERITY_NUMBER_TRACE3: 3, + SEVERITY_NUMBER_TRACE4: 4, + SEVERITY_NUMBER_DEBUG: 5, + SEVERITY_NUMBER_DEBUG2: 6, + SEVERITY_NUMBER_DEBUG3: 7, + SEVERITY_NUMBER_DEBUG4: 8, + SEVERITY_NUMBER_INFO: 9, + SEVERITY_NUMBER_INFO2: 10, + SEVERITY_NUMBER_INFO3: 11, + SEVERITY_NUMBER_INFO4: 12, + SEVERITY_NUMBER_WARN: 13, + SEVERITY_NUMBER_WARN2: 14, + SEVERITY_NUMBER_WARN3: 15, + SEVERITY_NUMBER_WARN4: 16, + SEVERITY_NUMBER_ERROR: 17, + SEVERITY_NUMBER_ERROR2: 18, + SEVERITY_NUMBER_ERROR3: 19, + SEVERITY_NUMBER_ERROR4: 20, + SEVERITY_NUMBER_FATAL: 21, + SEVERITY_NUMBER_FATAL2: 22, + SEVERITY_NUMBER_FATAL3: 23, + SEVERITY_NUMBER_FATAL4: 24 +} as const + +type ESeverityNumber = typeof ESeverityNumber[keyof typeof ESeverityNumber] diff --git a/packages/effect/src/unstable/tracing/OtlpMetrics.ts b/packages/effect/src/unstable/tracing/OtlpMetrics.ts index ae7db4c14b..b040cedce4 100644 --- a/packages/effect/src/unstable/tracing/OtlpMetrics.ts +++ b/packages/effect/src/unstable/tracing/OtlpMetrics.ts @@ -506,8 +506,8 @@ interface IExemplar { * values. It describes how those values relate to the time interval over * which they are aggregated. */ -const enum EAggregationTemporality { - AGGREGATION_TEMPORALITY_UNSPECIFIED = 0, +const EAggregationTemporality = { + AGGREGATION_TEMPORALITY_UNSPECIFIED: 0, /** DELTA is an AggregationTemporality for a metric aggregator which reports changes since last report time. Successive metrics contain aggregation of values from continuous and non-overlapping intervals. @@ -532,7 +532,7 @@ const enum EAggregationTemporality { 8. The 1 second collection cycle ends. A metric is exported for the number of requests received over the interval of time t_0+1 to t_0+2 with a value of 2. */ - AGGREGATION_TEMPORALITY_DELTA = 1, + AGGREGATION_TEMPORALITY_DELTA: 1, /** CUMULATIVE is an AggregationTemporality for a metric aggregator which reports changes since a fixed start time. This means that current values of a CUMULATIVE metric depend on all previous measurements since the @@ -568,5 +568,7 @@ const enum EAggregationTemporality { CUMULATIVE is valid, it is not recommended. This may cause problems for systems that do not use start_time to determine when the aggregation value was reset (e.g. Prometheus). */ - AGGREGATION_TEMPORALITY_CUMULATIVE = 2 -} + AGGREGATION_TEMPORALITY_CUMULATIVE: 2 +} as const + +type EAggregationTemporality = typeof EAggregationTemporality[keyof typeof EAggregationTemporality] diff --git a/packages/effect/src/unstable/tracing/OtlpTracer.ts b/packages/effect/src/unstable/tracing/OtlpTracer.ts index 5a03218ace..5ee639d66e 100644 --- a/packages/effect/src/unstable/tracing/OtlpTracer.ts +++ b/packages/effect/src/unstable/tracing/OtlpTracer.ts @@ -320,20 +320,22 @@ interface Status { message?: string } -const enum StatusCode { - Unset = 0, - Ok = 1, - Error = 2 -} +const StatusCode = { + Unset: 0, + Ok: 1, + Error: 2 +} as const -enum SpanKind { - unspecified = 0, - internal = 1, - server = 2, - client = 3, - producer = 4, - consumer = 5 -} +type StatusCode = typeof StatusCode[keyof typeof StatusCode] + +const SpanKind = { + unspecified: 0, + internal: 1, + server: 2, + client: 3, + producer: 4, + consumer: 5 +} as const const constOtelStatusSuccess: Status = { code: StatusCode.Ok diff --git a/packages/effect/tsconfig.test.json b/packages/effect/tsconfig.test.json index b92c964515..5a172bf2ff 100644 --- a/packages/effect/tsconfig.test.json +++ b/packages/effect/tsconfig.test.json @@ -6,6 +6,7 @@ "compilerOptions": { "tsBuildInfoFile": ".tsbuildinfo/test.tsbuildinfo", "outDir": ".tsbuildinfo/test", - "noEmit": true + "noEmit": true, + "erasableSyntaxOnly": false } } diff --git a/packages/platform-bun/src/BunHttpServer.ts b/packages/platform-bun/src/BunHttpServer.ts index b769f52d32..62008ccc5c 100644 --- a/packages/platform-bun/src/BunHttpServer.ts +++ b/packages/platform-bun/src/BunHttpServer.ts @@ -273,17 +273,30 @@ function wsDefaultRun(this: WebSocketContext, _: Uint8Array | string) { class BunServerRequest extends Inspectable.Class implements ServerRequest.HttpServerRequest { readonly [ServerRequest.TypeId]: ServerRequest.TypeId readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId + readonly source: Request + public resolve: (response: Response) => void + readonly url: string + private bunServer: BunServer + public headersOverride?: Headers.Headers | undefined + private remoteAddressOverride?: string | undefined + constructor( - readonly source: Request, - public resolve: (response: Response) => void, - readonly url: string, - private bunServer: BunServer, - public headersOverride?: Headers.Headers, - private remoteAddressOverride?: string + source: Request, + resolve: (response: Response) => void, + url: string, + bunServer: BunServer, + headersOverride?: Headers.Headers, + remoteAddressOverride?: string ) { super() this[ServerRequest.TypeId] = ServerRequest.TypeId this[IncomingMessage.TypeId] = IncomingMessage.TypeId + this.source = source + this.resolve = resolve + this.url = url + this.bunServer = bunServer + this.headersOverride = headersOverride + this.remoteAddressOverride = remoteAddressOverride } toJSON(): unknown { return IncomingMessage.inspect(this, { diff --git a/packages/platform-node-shared/src/NodeFileSystem.ts b/packages/platform-node-shared/src/NodeFileSystem.ts index 983fdf0e89..a30b2b2c86 100644 --- a/packages/platform-node-shared/src/NodeFileSystem.ts +++ b/packages/platform-node-shared/src/NodeFileSystem.ts @@ -231,14 +231,18 @@ const makeFile = (() => { class FileImpl implements FileSystem.File { readonly [FileSystem.FileTypeId]: FileSystem.FileTypeId + readonly fd: FileSystem.File.Descriptor + private readonly append: boolean private position: bigint = 0n constructor( - readonly fd: FileSystem.File.Descriptor, - private readonly append: boolean + fd: FileSystem.File.Descriptor, + append: boolean ) { this[FileSystem.FileTypeId] = FileSystem.FileTypeId + this.fd = fd + this.append = append } get stat() { diff --git a/packages/platform-node-shared/tsconfig.test.json b/packages/platform-node-shared/tsconfig.test.json index c696818ddf..d6d7ab76d3 100644 --- a/packages/platform-node-shared/tsconfig.test.json +++ b/packages/platform-node-shared/tsconfig.test.json @@ -7,6 +7,7 @@ "tsBuildInfoFile": ".tsbuildinfo/test.tsbuildinfo", "outDir": ".tsbuildinfo/test", "rootDir": "test", - "noEmit": true + "noEmit": true, + "erasableSyntaxOnly": false } } diff --git a/packages/platform-node/src/NodeHttpClient.ts b/packages/platform-node/src/NodeHttpClient.ts index 3c2406c64f..ed2c598f3e 100644 --- a/packages/platform-node/src/NodeHttpClient.ts +++ b/packages/platform-node/src/NodeHttpClient.ts @@ -152,14 +152,18 @@ function noopErrorHandler(_: any) {} class UndiciResponse extends Inspectable.Class implements HttpClientResponse { readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId readonly [Response.TypeId]: Response.TypeId + readonly request: HttpClientRequest + readonly source: Undici.Dispatcher.ResponseData constructor( - readonly request: HttpClientRequest, - readonly source: Undici.Dispatcher.ResponseData + request: HttpClientRequest, + source: Undici.Dispatcher.ResponseData ) { super() this[IncomingMessage.TypeId] = IncomingMessage.TypeId this[Response.TypeId] = Response.TypeId + this.request = request + this.source = source source.body.on("error", noopErrorHandler) } @@ -475,9 +479,10 @@ const waitForFinish = (nodeRequest: Http.ClientRequest, request: HttpClientReque class NodeHttpResponse extends NodeHttpIncomingMessage implements HttpClientResponse { readonly [Response.TypeId]: Response.TypeId + readonly request: HttpClientRequest constructor( - readonly request: HttpClientRequest, + request: HttpClientRequest, source: Http.IncomingMessage ) { super(source, (cause) => @@ -488,6 +493,7 @@ class NodeHttpResponse extends NodeHttpIncomingMessage impl cause })) this[Response.TypeId] = Response.TypeId + this.request = request } get status() { diff --git a/packages/platform-node/src/NodeHttpIncomingMessage.ts b/packages/platform-node/src/NodeHttpIncomingMessage.ts index 74945c0604..1cd8f320c6 100644 --- a/packages/platform-node/src/NodeHttpIncomingMessage.ts +++ b/packages/platform-node/src/NodeHttpIncomingMessage.ts @@ -22,14 +22,20 @@ export abstract class NodeHttpIncomingMessage extends Inspectable.Class * @since 1.0.0 */ readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId + readonly source: Http.IncomingMessage + readonly onError: (error: unknown) => E + readonly remoteAddressOverride?: string | undefined constructor( - readonly source: Http.IncomingMessage, - readonly onError: (error: unknown) => E, - readonly remoteAddressOverride?: string + source: Http.IncomingMessage, + onError: (error: unknown) => E, + remoteAddressOverride?: string ) { super() this[IncomingMessage.TypeId] = IncomingMessage.TypeId + this.source = source + this.onError = onError + this.remoteAddressOverride = remoteAddressOverride } get headers() { diff --git a/packages/platform-node/src/NodeHttpServer.ts b/packages/platform-node/src/NodeHttpServer.ts index 408a607f43..91712a66bb 100644 --- a/packages/platform-node/src/NodeHttpServer.ts +++ b/packages/platform-node/src/NodeHttpServer.ts @@ -232,13 +232,17 @@ export const makeUpgradeHandler = < class ServerRequestImpl extends NodeHttpIncomingMessage implements HttpServerRequest { readonly [Request.TypeId]: Request.TypeId + readonly response: Http.ServerResponse | LazyArg + private upgradeEffect?: Effect.Effect | undefined + readonly url: string + private headersOverride?: Headers.Headers | undefined constructor( - readonly source: Http.IncomingMessage, - readonly response: Http.ServerResponse | LazyArg, - private upgradeEffect?: Effect.Effect, - readonly url = source.url!, - private headersOverride?: Headers.Headers, + source: Http.IncomingMessage, + response: Http.ServerResponse | LazyArg, + upgradeEffect?: Effect.Effect, + url = source.url!, + headersOverride?: Headers.Headers, remoteAddressOverride?: string ) { super(source, (cause) => @@ -248,6 +252,10 @@ class ServerRequestImpl extends NodeHttpIncomingMessage impleme cause }), remoteAddressOverride) this[Request.TypeId] = Request.TypeId + this.response = response + this.upgradeEffect = upgradeEffect + this.url = url + this.headersOverride = headersOverride } private cachedCookies: ReadonlyRecord | undefined diff --git a/packages/platform-node/src/NodeMultipart.ts b/packages/platform-node/src/NodeMultipart.ts index 76cc24727c..793ff12a7f 100644 --- a/packages/platform-node/src/NodeMultipart.ts +++ b/packages/platform-node/src/NodeMultipart.ts @@ -110,9 +110,11 @@ class FileImpl extends PartBase implements Multipart.File { readonly contentType: string readonly content: Stream.Stream readonly contentEffect: Effect.Effect + readonly file: MP.FileStream - constructor(readonly file: MP.FileStream) { + constructor(file: MP.FileStream) { super() + this.file = file this.key = file.info.name this.name = file.filename ?? file.info.name this.contentType = file.info.contentType diff --git a/packages/platform-node/tsconfig.test.json b/packages/platform-node/tsconfig.test.json index c696818ddf..d6d7ab76d3 100644 --- a/packages/platform-node/tsconfig.test.json +++ b/packages/platform-node/tsconfig.test.json @@ -7,6 +7,7 @@ "tsBuildInfoFile": ".tsbuildinfo/test.tsbuildinfo", "outDir": ".tsbuildinfo/test", "rootDir": "test", - "noEmit": true + "noEmit": true, + "erasableSyntaxOnly": false } } diff --git a/tsconfig.base.jsonc b/tsconfig.base.jsonc index b7e66ba814..5c1c54f44c 100644 --- a/tsconfig.base.jsonc +++ b/tsconfig.base.jsonc @@ -13,6 +13,7 @@ "verbatimModuleSyntax": true, // Only transform/eliminate type-only import/export statements. "allowJs": false, // If you touch this, a puppy dies. "rewriteRelativeImportExtensions": true, // Rewrite `.ts` imports to `.js` at build time. + "erasableSyntaxOnly": true, // Allows to run directly with node and type removal // Emit source- & declaration maps. "declarationMap": true,