Skip to content

Commit

Permalink
add deno support to Inspectable (#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Oct 6, 2024
1 parent fc44692 commit 1febd51
Show file tree
Hide file tree
Showing 36 changed files with 182 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .changeset/early-comics-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect/platform": minor
"effect": minor
"@effect/schema": minor
---

add deno support to Inspectable
5 changes: 4 additions & 1 deletion packages/effect/src/BigDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as Equal from "./Equal.js"
import * as equivalence from "./Equivalence.js"
import { dual, pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import { type Inspectable, NodeInspectSymbol } from "./Inspectable.js"
import { DenoInspectSymbol, type Inspectable, NodeInspectSymbol } from "./Inspectable.js"
import * as Option from "./Option.js"
import * as order from "./Order.js"
import type { Ordering } from "./Ordering.js"
Expand Down Expand Up @@ -74,6 +74,9 @@ const BigDecimalProto: Omit<BigDecimal, "value" | "scale" | "normalized"> = {
scale: this.scale
}
},
[DenoInspectSymbol](this: BigDecimal) {
return this.toJSON()
},
[NodeInspectSymbol](this: BigDecimal) {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as Equivalence from "./Equivalence.js"
import { dual, identity, pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import type { TypeLambda } from "./HKT.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { NonEmptyIterable } from "./NonEmptyIterable.js"
import type { Option } from "./Option.js"
import * as O from "./Option.js"
Expand Down Expand Up @@ -135,6 +135,9 @@ const ChunkProto: Omit<Chunk<unknown>, "backing" | "depth" | "left" | "length" |
values: toReadonlyArray(this).map(toJSON)
}
},
[DenoInspectSymbol]<A>(this: Chunk<A>) {
return this.toJSON()
},
[NodeInspectSymbol]<A>(this: Chunk<A>) {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/Cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Equal from "./Equal.js"
import * as equivalence from "./Equivalence.js"
import { dual, pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import { format, type Inspectable, NodeInspectSymbol } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol } from "./Inspectable.js"
import * as N from "./Number.js"
import { type Pipeable, pipeArguments } from "./Pipeable.js"
import { hasProperty } from "./Predicate.js"
Expand Down Expand Up @@ -67,6 +67,9 @@ const CronProto: Omit<Cron, "minutes" | "hours" | "days" | "months" | "weekdays"
weekdays: Arr.fromIterable(this.weekdays)
}
},
[DenoInspectSymbol](this: Cron) {
return this.toJSON()
},
[NodeInspectSymbol](this: Cron) {
return this.toJSON()
},
Expand Down
6 changes: 6 additions & 0 deletions packages/effect/src/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ const Proto = {
pipe() {
return pipeArguments(this, arguments)
},
[Inspectable.DenoInspectSymbol](this: DateTime) {
return this.toString()
},
[Inspectable.NodeInspectSymbol](this: DateTime) {
return this.toString()
},
Expand Down Expand Up @@ -273,6 +276,9 @@ const ProtoZoned = {

const ProtoTimeZone = {
[TimeZoneTypeId]: TimeZoneTypeId,
[Inspectable.DenoInspectSymbol](this: TimeZone) {
return this.toString()
},
[Inspectable.NodeInspectSymbol](this: TimeZone) {
return this.toString()
}
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/Duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type * as equivalence from "./Equivalence.js"
import { dual } from "./Function.js"
import * as Hash from "./Hash.js"
import type { Inspectable } from "./Inspectable.js"
import { NodeInspectSymbol } from "./Inspectable.js"
import { DenoInspectSymbol, NodeInspectSymbol } from "./Inspectable.js"
import * as Option from "./Option.js"
import * as order from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -160,6 +160,9 @@ const DurationProto: Omit<Duration, "value"> = {
return { _id: "Duration", _tag: "Infinity" }
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
3 changes: 3 additions & 0 deletions packages/effect/src/FiberHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const Proto = {
state: this.state
}
},
[Inspectable.DenoInspectSymbol](this: FiberHandle) {
return this.toJSON()
},
[Inspectable.NodeInspectSymbol](this: FiberHandle) {
return this.toJSON()
},
Expand Down
3 changes: 3 additions & 0 deletions packages/effect/src/FiberMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const Proto = {
state: this.state
}
},
[Inspectable.DenoInspectSymbol](this: FiberMap<unknown>) {
return this.toJSON()
},
[Inspectable.NodeInspectSymbol](this: FiberMap<unknown>) {
return this.toJSON()
},
Expand Down
3 changes: 3 additions & 0 deletions packages/effect/src/FiberSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const Proto = {
state: this.state
}
},
[Inspectable.DenoInspectSymbol](this: FiberSet<unknown, unknown>) {
return this.toJSON()
},
[Inspectable.NodeInspectSymbol](this: FiberSet<unknown, unknown>) {
return this.toJSON()
},
Expand Down
22 changes: 22 additions & 0 deletions packages/effect/src/Inspectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export const NodeInspectSymbol = Symbol.for("nodejs.util.inspect.custom")
*/
export type NodeInspectSymbol = typeof NodeInspectSymbol

/**
* @since 3.9.0
* @category symbols
*/
export const DenoInspectSymbol = Symbol.for("Deno.customInspect")

/**
* @since 3.9.0
* @category symbols
*/
export type DenoInspectSymbol = typeof DenoInspectSymbol

/**
* @since 2.0.0
* @category models
Expand All @@ -24,6 +36,7 @@ export interface Inspectable {
toString(): string
toJSON(): unknown
[NodeInspectSymbol](): unknown
[DenoInspectSymbol](): unknown
}

/**
Expand Down Expand Up @@ -56,6 +69,9 @@ export const BaseProto: Inspectable = {
[NodeInspectSymbol]() {
return this.toJSON()
},
[DenoInspectSymbol]() {
return this.toJSON()
},
toString() {
return format(this.toJSON())
}
Expand All @@ -75,6 +91,12 @@ export abstract class Class {
[NodeInspectSymbol]() {
return this.toJSON()
}
/**
* @since 3.9.0
*/
[DenoInspectSymbol]() {
return this.toJSON()
}
/**
* @since 2.0.0
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/effect/src/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as Equal from "./Equal.js"
import * as Equivalence from "./Equivalence.js"
import { dual, identity, unsafeCoerce } from "./Function.js"
import * as Hash from "./Hash.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { nonEmpty, NonEmptyIterable } from "./NonEmptyIterable.js"
import * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -110,6 +110,9 @@ const ConsProto: Omit<Cons<unknown>, "head" | "tail" | typeof nonEmpty> = {
values: toArray(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down Expand Up @@ -176,6 +179,9 @@ const NilProto: Nil<unknown> = {
_tag: "Nil"
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
8 changes: 7 additions & 1 deletion packages/effect/src/Micro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { constTrue, constVoid, dual, identity, type LazyArg } from "./Function.j
import { globalValue } from "./GlobalValue.js"
import type { TypeLambda } from "./HKT.js"
import type { Inspectable } from "./Inspectable.js"
import { NodeInspectSymbol, toStringUnknown } from "./Inspectable.js"
import { DenoInspectSymbol, NodeInspectSymbol, toStringUnknown } from "./Inspectable.js"
import * as doNotation from "./internal/doNotation.js"
import { StructuralPrototype } from "./internal/effectable.js"
import { SingleShotGen } from "./internal/singleShotGen.js"
Expand Down Expand Up @@ -323,6 +323,9 @@ abstract class MicroCauseImpl<Tag extends string, E> extends globalThis.Error im
toString() {
return this.stack
}
[DenoInspectSymbol]() {
return this.stack
}
[NodeInspectSymbol]() {
return this.stack
}
Expand Down Expand Up @@ -4097,6 +4100,9 @@ const YieldableError: new(message?: string) => YieldableError = (function() {
toJSON() {
return { ...this }
}
[DenoInspectSymbol](): string {
return this[NodeInspectSymbol]()
}
[NodeInspectSymbol](): string {
const stack = this.stack
if (stack) {
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/MutableHashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NonEmptyArray } from "./Array.js"
import * as Equal from "./Equal.js"
import { dual } from "./Function.js"
import * as Hash from "./Hash.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -46,6 +46,9 @@ const MutableHashMapProto: Omit<MutableHashMap<unknown, unknown>, "referential"
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/MutableHashSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @since 2.0.0
*/
import * as Dual from "./Function.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as MutableHashMap from "./MutableHashMap.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -40,6 +40,9 @@ const MutableHashSetProto: Omit<MutableHashSet<unknown>, "keyMap"> = {
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/MutableList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @since 2.0.0
*/
import * as Dual from "./Function.js"
import { format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Inspectable } from "./Inspectable.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -63,6 +63,9 @@ const MutableListProto: Omit<MutableList<unknown>, "head" | "tail"> = {
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/MutableQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as Chunk from "./Chunk.js"
import * as Dual from "./Function.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as MutableList from "./MutableList.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -59,6 +59,9 @@ const MutableQueueProto: Omit<MutableQueue<unknown>, "queue" | "capacity"> = {
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/MutableRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as Equal from "./Equal.js"
import * as Dual from "./Function.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"

Expand Down Expand Up @@ -37,6 +37,9 @@ const MutableRefProto: Omit<MutableRef<unknown>, "current"> = {
current: toJSON(this.current)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/SortedMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Equal from "./Equal.js"
import * as Dual from "./Function.js"
import { pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import * as Option from "./Option.js"
import type { Order } from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
Expand Down Expand Up @@ -62,6 +62,9 @@ const SortedMapProto: Omit<SortedMap<unknown, unknown>, "tree"> = {
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/SortedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Dual from "./Function.js"
import { pipe } from "./Function.js"
import * as Hash from "./Hash.js"
import type { Inspectable } from "./Inspectable.js"
import { format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import { DenoInspectSymbol, format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
import type { Order } from "./Order.js"
import type { Pipeable } from "./Pipeable.js"
import { pipeArguments } from "./Pipeable.js"
Expand Down Expand Up @@ -62,6 +62,9 @@ const SortedSetProto: Omit<SortedSet<unknown>, "keyTree"> = {
values: Array.from(this).map(toJSON)
}
},
[DenoInspectSymbol]() {
return this.toJSON()
},
[NodeInspectSymbol]() {
return this.toJSON()
},
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/internal/cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { constFalse, constTrue, dual, identity, pipe } from "../Function.js"
import { globalValue } from "../GlobalValue.js"
import * as Hash from "../Hash.js"
import * as HashSet from "../HashSet.js"
import { NodeInspectSymbol, toJSON } from "../Inspectable.js"
import { DenoInspectSymbol, NodeInspectSymbol, toJSON } from "../Inspectable.js"
import * as Option from "../Option.js"
import { pipeArguments } from "../Pipeable.js"
import type { Predicate, Refinement } from "../Predicate.js"
Expand Down Expand Up @@ -69,6 +69,9 @@ const proto = {
toString<E>(this: Cause.Cause<E>) {
return pretty(this)
},
[DenoInspectSymbol]<E>(this: Cause.Cause<E>) {
return this.toJSON()
},
[NodeInspectSymbol]<E>(this: Cause.Cause<E>) {
return this.toJSON()
}
Expand Down
Loading

0 comments on commit 1febd51

Please sign in to comment.