Erster Docker-Stand
This commit is contained in:
1101
_node_modules/effect/src/Arbitrary.ts
generated
Normal file
1101
_node_modules/effect/src/Arbitrary.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
6847
_node_modules/effect/src/Array.ts
generated
Normal file
6847
_node_modules/effect/src/Array.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
2037
_node_modules/effect/src/BigDecimal.ts
generated
Normal file
2037
_node_modules/effect/src/BigDecimal.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
1139
_node_modules/effect/src/BigInt.ts
generated
Normal file
1139
_node_modules/effect/src/BigInt.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
560
_node_modules/effect/src/Boolean.ts
generated
Normal file
560
_node_modules/effect/src/Boolean.ts
generated
Normal file
@@ -0,0 +1,560 @@
|
||||
/**
|
||||
* This module provides utility functions and type class instances for working with the `boolean` type in TypeScript.
|
||||
* It includes functions for basic boolean operations, as well as type class instances for
|
||||
* `Equivalence` and `Order`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as equivalence from "./Equivalence.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import { dual } from "./Function.js"
|
||||
import * as order from "./Order.js"
|
||||
import * as predicate from "./Predicate.js"
|
||||
|
||||
/**
|
||||
* Tests if a value is a `boolean`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { isBoolean } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(isBoolean(true), true)
|
||||
* assert.deepStrictEqual(isBoolean("true"), false)
|
||||
* ```
|
||||
*
|
||||
* @category guards
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const isBoolean: (input: unknown) => input is boolean = predicate.isBoolean
|
||||
|
||||
/**
|
||||
* This function returns the result of either of the given functions depending on the value of the boolean parameter.
|
||||
* It is useful when you have to run one of two functions depending on the boolean value.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Boolean } from "effect"
|
||||
*
|
||||
* assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* This function returns the result of either of the given functions depending on the value of the boolean parameter.
|
||||
* It is useful when you have to run one of two functions depending on the boolean value.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Boolean } from "effect"
|
||||
*
|
||||
* assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B = A>(
|
||||
options: {
|
||||
readonly onFalse: LazyArg<A>
|
||||
readonly onTrue: LazyArg<B>
|
||||
}
|
||||
): (value: boolean) => A | B
|
||||
/**
|
||||
* This function returns the result of either of the given functions depending on the value of the boolean parameter.
|
||||
* It is useful when you have to run one of two functions depending on the boolean value.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Boolean } from "effect"
|
||||
*
|
||||
* assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B>(
|
||||
value: boolean,
|
||||
options: {
|
||||
readonly onFalse: LazyArg<A>
|
||||
readonly onTrue: LazyArg<B>
|
||||
}
|
||||
): A | B
|
||||
} = dual(2, <A, B>(value: boolean, options: {
|
||||
readonly onFalse: LazyArg<A>
|
||||
readonly onTrue: LazyArg<B>
|
||||
}): A | B => value ? options.onTrue() : options.onFalse())
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const Equivalence: equivalence.Equivalence<boolean> = equivalence.boolean
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const Order: order.Order<boolean> = order.boolean
|
||||
|
||||
/**
|
||||
* Negates the given boolean: `!self`
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { not } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(not(true), false)
|
||||
* assert.deepStrictEqual(not(false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const not = (self: boolean): boolean => !self
|
||||
|
||||
/**
|
||||
* Combines two boolean using AND: `self && that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { and } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(and(true, true), true)
|
||||
* assert.deepStrictEqual(and(true, false), false)
|
||||
* assert.deepStrictEqual(and(false, true), false)
|
||||
* assert.deepStrictEqual(and(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const and: {
|
||||
/**
|
||||
* Combines two boolean using AND: `self && that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { and } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(and(true, true), true)
|
||||
* assert.deepStrictEqual(and(true, false), false)
|
||||
* assert.deepStrictEqual(and(false, true), false)
|
||||
* assert.deepStrictEqual(and(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two boolean using AND: `self && that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { and } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(and(true, true), true)
|
||||
* assert.deepStrictEqual(and(true, false), false)
|
||||
* assert.deepStrictEqual(and(false, true), false)
|
||||
* assert.deepStrictEqual(and(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => self && that)
|
||||
|
||||
/**
|
||||
* Combines two boolean using NAND: `!(self && that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nand } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nand(true, true), false)
|
||||
* assert.deepStrictEqual(nand(true, false), true)
|
||||
* assert.deepStrictEqual(nand(false, true), true)
|
||||
* assert.deepStrictEqual(nand(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const nand: {
|
||||
/**
|
||||
* Combines two boolean using NAND: `!(self && that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nand } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nand(true, true), false)
|
||||
* assert.deepStrictEqual(nand(true, false), true)
|
||||
* assert.deepStrictEqual(nand(false, true), true)
|
||||
* assert.deepStrictEqual(nand(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two boolean using NAND: `!(self && that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nand } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nand(true, true), false)
|
||||
* assert.deepStrictEqual(nand(true, false), true)
|
||||
* assert.deepStrictEqual(nand(false, true), true)
|
||||
* assert.deepStrictEqual(nand(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => !(self && that))
|
||||
|
||||
/**
|
||||
* Combines two boolean using OR: `self || that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { or } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(or(true, true), true)
|
||||
* assert.deepStrictEqual(or(true, false), true)
|
||||
* assert.deepStrictEqual(or(false, true), true)
|
||||
* assert.deepStrictEqual(or(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const or: {
|
||||
/**
|
||||
* Combines two boolean using OR: `self || that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { or } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(or(true, true), true)
|
||||
* assert.deepStrictEqual(or(true, false), true)
|
||||
* assert.deepStrictEqual(or(false, true), true)
|
||||
* assert.deepStrictEqual(or(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two boolean using OR: `self || that`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { or } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(or(true, true), true)
|
||||
* assert.deepStrictEqual(or(true, false), true)
|
||||
* assert.deepStrictEqual(or(false, true), true)
|
||||
* assert.deepStrictEqual(or(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => self || that)
|
||||
|
||||
/**
|
||||
* Combines two booleans using NOR: `!(self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nor(true, true), false)
|
||||
* assert.deepStrictEqual(nor(true, false), false)
|
||||
* assert.deepStrictEqual(nor(false, true), false)
|
||||
* assert.deepStrictEqual(nor(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const nor: {
|
||||
/**
|
||||
* Combines two booleans using NOR: `!(self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nor(true, true), false)
|
||||
* assert.deepStrictEqual(nor(true, false), false)
|
||||
* assert.deepStrictEqual(nor(false, true), false)
|
||||
* assert.deepStrictEqual(nor(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two booleans using NOR: `!(self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { nor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(nor(true, true), false)
|
||||
* assert.deepStrictEqual(nor(true, false), false)
|
||||
* assert.deepStrictEqual(nor(false, true), false)
|
||||
* assert.deepStrictEqual(nor(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => !(self || that))
|
||||
|
||||
/**
|
||||
* Combines two booleans using XOR: `(!self && that) || (self && !that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { xor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(xor(true, true), false)
|
||||
* assert.deepStrictEqual(xor(true, false), true)
|
||||
* assert.deepStrictEqual(xor(false, true), true)
|
||||
* assert.deepStrictEqual(xor(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const xor: {
|
||||
/**
|
||||
* Combines two booleans using XOR: `(!self && that) || (self && !that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { xor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(xor(true, true), false)
|
||||
* assert.deepStrictEqual(xor(true, false), true)
|
||||
* assert.deepStrictEqual(xor(false, true), true)
|
||||
* assert.deepStrictEqual(xor(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two booleans using XOR: `(!self && that) || (self && !that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { xor } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(xor(true, true), false)
|
||||
* assert.deepStrictEqual(xor(true, false), true)
|
||||
* assert.deepStrictEqual(xor(false, true), true)
|
||||
* assert.deepStrictEqual(xor(false, false), false)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => (!self && that) || (self && !that))
|
||||
|
||||
/**
|
||||
* Combines two booleans using EQV (aka XNOR): `!xor(self, that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { eqv } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(eqv(true, true), true)
|
||||
* assert.deepStrictEqual(eqv(true, false), false)
|
||||
* assert.deepStrictEqual(eqv(false, true), false)
|
||||
* assert.deepStrictEqual(eqv(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const eqv: {
|
||||
/**
|
||||
* Combines two booleans using EQV (aka XNOR): `!xor(self, that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { eqv } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(eqv(true, true), true)
|
||||
* assert.deepStrictEqual(eqv(true, false), false)
|
||||
* assert.deepStrictEqual(eqv(false, true), false)
|
||||
* assert.deepStrictEqual(eqv(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two booleans using EQV (aka XNOR): `!xor(self, that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { eqv } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(eqv(true, true), true)
|
||||
* assert.deepStrictEqual(eqv(true, false), false)
|
||||
* assert.deepStrictEqual(eqv(false, true), false)
|
||||
* assert.deepStrictEqual(eqv(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self: boolean, that: boolean): boolean => !xor(self, that))
|
||||
|
||||
/**
|
||||
* Combines two booleans using an implication: `(!self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { implies } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(implies(true, true), true)
|
||||
* assert.deepStrictEqual(implies(true, false), false)
|
||||
* assert.deepStrictEqual(implies(false, true), true)
|
||||
* assert.deepStrictEqual(implies(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const implies: {
|
||||
/**
|
||||
* Combines two booleans using an implication: `(!self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { implies } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(implies(true, true), true)
|
||||
* assert.deepStrictEqual(implies(true, false), false)
|
||||
* assert.deepStrictEqual(implies(false, true), true)
|
||||
* assert.deepStrictEqual(implies(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: boolean): (self: boolean) => boolean
|
||||
/**
|
||||
* Combines two booleans using an implication: `(!self || that)`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { implies } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(implies(true, true), true)
|
||||
* assert.deepStrictEqual(implies(true, false), false)
|
||||
* assert.deepStrictEqual(implies(false, true), true)
|
||||
* assert.deepStrictEqual(implies(false, false), true)
|
||||
* ```
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: boolean, that: boolean): boolean
|
||||
} = dual(2, (self, that) => self ? that : true)
|
||||
|
||||
/**
|
||||
* This utility function is used to check if all the elements in a collection of boolean values are `true`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { every } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(every([true, true, true]), true)
|
||||
* assert.deepStrictEqual(every([true, false, true]), false)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const every = (collection: Iterable<boolean>): boolean => {
|
||||
for (const b of collection) {
|
||||
if (!b) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* This utility function is used to check if at least one of the elements in a collection of boolean values is `true`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { some } from "effect/Boolean"
|
||||
*
|
||||
* assert.deepStrictEqual(some([true, false, true]), true)
|
||||
* assert.deepStrictEqual(some([false, false, false]), false)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const some = (collection: Iterable<boolean>): boolean => {
|
||||
for (const b of collection) {
|
||||
if (b) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
360
_node_modules/effect/src/Brand.ts
generated
Normal file
360
_node_modules/effect/src/Brand.ts
generated
Normal file
@@ -0,0 +1,360 @@
|
||||
/**
|
||||
* This module provides types and utility functions to create and work with branded types,
|
||||
* which are TypeScript types with an added type tag to prevent accidental usage of a value in the wrong context.
|
||||
*
|
||||
* The `refined` and `nominal` functions are both used to create branded types in TypeScript.
|
||||
* The main difference between them is that `refined` allows for validation of the data, while `nominal` does not.
|
||||
*
|
||||
* The `nominal` function is used to create a new branded type that has the same underlying type as the input, but with a different name.
|
||||
* This is useful when you want to distinguish between two values of the same type that have different meanings.
|
||||
* The `nominal` function does not perform any validation of the input data.
|
||||
*
|
||||
* On the other hand, the `refined` function is used to create a new branded type that has the same underlying type as the input,
|
||||
* but with a different name, and it also allows for validation of the input data.
|
||||
* The `refined` function takes a predicate that is used to validate the input data.
|
||||
* If the input data fails the validation, a `BrandErrors` is returned, which provides information about the specific validation failure.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Arr from "./Array.js"
|
||||
import * as Either from "./Either.js"
|
||||
import { identity, unsafeCoerce } from "./Function.js"
|
||||
import * as Option from "./Option.js"
|
||||
import type { Predicate } from "./Predicate.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const BrandTypeId: unique symbol = Symbol.for("effect/Brand")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type BrandTypeId = typeof BrandTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const RefinedConstructorsTypeId: unique symbol = Symbol.for("effect/Brand/Refined")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type RefinedConstructorsTypeId = typeof RefinedConstructorsTypeId
|
||||
|
||||
/**
|
||||
* A generic interface that defines a branded type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Brand<in out K extends string | symbol> {
|
||||
readonly [BrandTypeId]: {
|
||||
readonly [k in K]: K
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Brand {
|
||||
/**
|
||||
* Represents a list of refinement errors.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BrandErrors extends Array<RefinementError> {}
|
||||
|
||||
/**
|
||||
* Represents an error that occurs when the provided value of the branded type does not pass the refinement predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface RefinementError {
|
||||
readonly meta: unknown
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Constructor<in out A extends Brand<any>> {
|
||||
readonly [RefinedConstructorsTypeId]: RefinedConstructorsTypeId
|
||||
/**
|
||||
* Constructs a branded type from a value of type `A`, throwing an error if
|
||||
* the provided `A` is not valid.
|
||||
*/
|
||||
(args: Brand.Unbranded<A>): A
|
||||
/**
|
||||
* Constructs a branded type from a value of type `A`, returning `Some<A>`
|
||||
* if the provided `A` is valid, `None` otherwise.
|
||||
*/
|
||||
option(args: Brand.Unbranded<A>): Option.Option<A>
|
||||
/**
|
||||
* Constructs a branded type from a value of type `A`, returning `Right<A>`
|
||||
* if the provided `A` is valid, `Left<BrandError>` otherwise.
|
||||
*/
|
||||
either(args: Brand.Unbranded<A>): Either.Either<A, Brand.BrandErrors>
|
||||
/**
|
||||
* Attempts to refine the provided value of type `A`, returning `true` if
|
||||
* the provided `A` is valid, `false` otherwise.
|
||||
*/
|
||||
is(a: Brand.Unbranded<A>): a is Brand.Unbranded<A> & A
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility type to extract a branded type from a `Brand.Constructor`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type FromConstructor<A> = A extends Brand.Constructor<infer B> ? B : never
|
||||
|
||||
/**
|
||||
* A utility type to extract the value type from a brand.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Unbranded<P> = P extends infer Q & Brands<P> ? Q : P
|
||||
|
||||
/**
|
||||
* A utility type to extract the brands from a branded type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Brands<P> = P extends Brand<any> ? Types.UnionToIntersection<
|
||||
{
|
||||
[k in keyof P[BrandTypeId]]: k extends string | symbol ? Brand<k>
|
||||
: never
|
||||
}[keyof P[BrandTypeId]]
|
||||
>
|
||||
: never
|
||||
|
||||
/**
|
||||
* A utility type that checks that all brands have the same base type.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type EnsureCommonBase<
|
||||
Brands extends readonly [Brand.Constructor<any>, ...Array<Brand.Constructor<any>>]
|
||||
> = {
|
||||
[B in keyof Brands]: Brand.Unbranded<Brand.FromConstructor<Brands[0]>> extends
|
||||
Brand.Unbranded<Brand.FromConstructor<Brands[B]>>
|
||||
? Brand.Unbranded<Brand.FromConstructor<Brands[B]>> extends Brand.Unbranded<Brand.FromConstructor<Brands[0]>>
|
||||
? Brands[B]
|
||||
: Brands[B]
|
||||
: "ERROR: All brands should have the same base type"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category alias
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Branded<A, K extends string | symbol> = A & Brand<K>
|
||||
|
||||
/**
|
||||
* Returns a `BrandErrors` that contains a single `RefinementError`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const error = (message: string, meta?: unknown): Brand.BrandErrors => [{
|
||||
message,
|
||||
meta
|
||||
}]
|
||||
|
||||
/**
|
||||
* Takes a variable number of `BrandErrors` and returns a single `BrandErrors` that contains all refinement errors.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const errors: (...errors: Array<Brand.BrandErrors>) => Brand.BrandErrors = (
|
||||
...errors: Array<Brand.BrandErrors>
|
||||
): Brand.BrandErrors => Arr.flatten(errors)
|
||||
|
||||
/**
|
||||
* Returns a `Brand.Constructor` that can construct a branded type from an unbranded value using the provided `refinement`
|
||||
* predicate as validation of the input data.
|
||||
*
|
||||
* If you don't want to perform any validation but only distinguish between two values of the same type but with different meanings,
|
||||
* see {@link nominal}.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Brand } from "effect"
|
||||
*
|
||||
* type Int = number & Brand.Brand<"Int">
|
||||
*
|
||||
* const Int = Brand.refined<Int>(
|
||||
* (n) => Number.isInteger(n),
|
||||
* (n) => Brand.error(`Expected ${n} to be an integer`)
|
||||
* )
|
||||
*
|
||||
* console.log(Int(1))
|
||||
* // 1
|
||||
*
|
||||
* assert.throws(() => Int(1.1))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export function refined<A extends Brand<any>>(
|
||||
f: (unbranded: Brand.Unbranded<A>) => Option.Option<Brand.BrandErrors>
|
||||
): Brand.Constructor<A>
|
||||
export function refined<A extends Brand<any>>(
|
||||
refinement: Predicate<Brand.Unbranded<A>>,
|
||||
onFailure: (unbranded: Brand.Unbranded<A>) => Brand.BrandErrors
|
||||
): Brand.Constructor<A>
|
||||
export function refined<A extends Brand<any>>(
|
||||
...args: [(unbranded: Brand.Unbranded<A>) => Option.Option<Brand.BrandErrors>] | [
|
||||
Predicate<Brand.Unbranded<A>>,
|
||||
(unbranded: Brand.Unbranded<A>) => Brand.BrandErrors
|
||||
]
|
||||
): Brand.Constructor<A> {
|
||||
const either: (unbranded: Brand.Unbranded<A>) => Either.Either<A, Brand.BrandErrors> = args.length === 2 ?
|
||||
(unbranded) => args[0](unbranded) ? Either.right(unbranded as A) : Either.left(args[1](unbranded)) :
|
||||
(unbranded) => {
|
||||
return Option.match(args[0](unbranded), {
|
||||
onNone: () => Either.right(unbranded as A),
|
||||
onSome: Either.left
|
||||
})
|
||||
}
|
||||
return Object.assign((unbranded: Brand.Unbranded<A>) => Either.getOrThrowWith(either(unbranded), identity), {
|
||||
[RefinedConstructorsTypeId]: RefinedConstructorsTypeId,
|
||||
option: (args: any) => Option.getRight(either(args)),
|
||||
either,
|
||||
is: (args: any): args is Brand.Unbranded<A> & A => Either.isRight(either(args))
|
||||
}) as any
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns a `Brand.Constructor` that **does not apply any runtime checks**, it just returns the provided value.
|
||||
* It can be used to create nominal types that allow distinguishing between two values of the same type but with different meanings.
|
||||
*
|
||||
* If you also want to perform some validation, see {@link refined}.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Brand } from "effect"
|
||||
*
|
||||
* type UserId = number & Brand.Brand<"UserId">
|
||||
*
|
||||
* const UserId = Brand.nominal<UserId>()
|
||||
*
|
||||
* console.log(UserId(1))
|
||||
* // 1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nominal = <A extends Brand<any>>(): Brand.Constructor<
|
||||
A
|
||||
> => {
|
||||
// @ts-expect-error
|
||||
return Object.assign((args) => args, {
|
||||
[RefinedConstructorsTypeId]: RefinedConstructorsTypeId,
|
||||
option: (args: any) => Option.some(args),
|
||||
either: (args: any) => Either.right(args),
|
||||
is: (_args: any): _args is Brand.Unbranded<A> & A => true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines two or more brands together to form a single branded type.
|
||||
* This API is useful when you want to validate that the input data passes multiple brand validators.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Brand } from "effect"
|
||||
*
|
||||
* type Int = number & Brand.Brand<"Int">
|
||||
* const Int = Brand.refined<Int>(
|
||||
* (n) => Number.isInteger(n),
|
||||
* (n) => Brand.error(`Expected ${n} to be an integer`)
|
||||
* )
|
||||
* type Positive = number & Brand.Brand<"Positive">
|
||||
* const Positive = Brand.refined<Positive>(
|
||||
* (n) => n > 0,
|
||||
* (n) => Brand.error(`Expected ${n} to be positive`)
|
||||
* )
|
||||
*
|
||||
* const PositiveInt = Brand.all(Int, Positive)
|
||||
*
|
||||
* console.log(PositiveInt(1))
|
||||
* // 1
|
||||
*
|
||||
* assert.throws(() => PositiveInt(1.1))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combining
|
||||
*/
|
||||
export const all: <Brands extends readonly [Brand.Constructor<any>, ...Array<Brand.Constructor<any>>]>(
|
||||
...brands: Brand.EnsureCommonBase<Brands>
|
||||
) => Brand.Constructor<
|
||||
Types.UnionToIntersection<{ [B in keyof Brands]: Brand.FromConstructor<Brands[B]> }[number]> extends
|
||||
infer X extends Brand<any> ? X : Brand<any>
|
||||
> = <
|
||||
Brands extends readonly [Brand.Constructor<any>, ...Array<Brand.Constructor<any>>]
|
||||
>(...brands: Brand.EnsureCommonBase<Brands>): Brand.Constructor<
|
||||
Types.UnionToIntersection<
|
||||
{
|
||||
[B in keyof Brands]: Brand.FromConstructor<Brands[B]>
|
||||
}[number]
|
||||
> extends infer X extends Brand<any> ? X : Brand<any>
|
||||
> => {
|
||||
const either = (args: any): Either.Either<any, Brand.BrandErrors> => {
|
||||
let result: Either.Either<any, Brand.BrandErrors> = Either.right(args)
|
||||
for (const brand of brands) {
|
||||
const nextResult = brand.either(args)
|
||||
if (Either.isLeft(result) && Either.isLeft(nextResult)) {
|
||||
result = Either.left([...result.left, ...nextResult.left])
|
||||
} else {
|
||||
result = Either.isLeft(result) ? result : nextResult
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
// @ts-expect-error
|
||||
return Object.assign((args) =>
|
||||
Either.match(either(args), {
|
||||
onLeft: (e) => {
|
||||
throw e
|
||||
},
|
||||
onRight: identity
|
||||
}), {
|
||||
[RefinedConstructorsTypeId]: RefinedConstructorsTypeId,
|
||||
option: (args: any) => Option.getRight(either(args)),
|
||||
either,
|
||||
is: (args: any): args is any => Either.isRight(either(args))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the unbranded value from a `Brand` instance.
|
||||
*
|
||||
* @since 3.15.0
|
||||
* @category getters
|
||||
*/
|
||||
export const unbranded: <A extends Brand<any>>(branded: A) => Brand.Unbranded<A> = unsafeCoerce
|
||||
281
_node_modules/effect/src/Cache.ts
generated
Normal file
281
_node_modules/effect/src/Cache.ts
generated
Normal file
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type { Either } from "./Either.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import * as internal from "./internal/cache.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type * as Predicate from "./Predicate.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const CacheTypeId: unique symbol = internal.CacheTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type CacheTypeId = typeof CacheTypeId
|
||||
|
||||
/**
|
||||
* @since 3.6.4
|
||||
* @category symbols
|
||||
*/
|
||||
export const ConsumerCacheTypeId: unique symbol = internal.ConsumerCacheTypeId
|
||||
|
||||
/**
|
||||
* @since 3.6.4
|
||||
* @category symbols
|
||||
*/
|
||||
export type ConsumerCacheTypeId = typeof ConsumerCacheTypeId
|
||||
|
||||
/**
|
||||
* A `Cache` is defined in terms of a lookup function that, given a key of
|
||||
* type `Key`, can either fail with an error of type `Error` or succeed with a
|
||||
* value of type `Value`. Getting a value from the cache will either return
|
||||
* the previous result of the lookup function if it is available or else
|
||||
* compute a new result with the lookup function, put it in the cache, and
|
||||
* return it.
|
||||
*
|
||||
* A cache also has a specified capacity and time to live. When the cache is
|
||||
* at capacity the least recently accessed values in the cache will be
|
||||
* removed to make room for new values. Getting a value with a life older than
|
||||
* the specified time to live will result in a new value being computed with
|
||||
* the lookup function and returned when available.
|
||||
*
|
||||
* The cache is safe for concurrent access. If multiple fibers attempt to get
|
||||
* the same key the lookup function will only be computed once and the result
|
||||
* will be returned to all fibers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Cache<in out Key, in out Value, out Error = never>
|
||||
extends ConsumerCache<Key, Value, Error>, Cache.Variance<Key, Value, Error>
|
||||
{
|
||||
/**
|
||||
* Retrieves the value associated with the specified key if it exists.
|
||||
* Otherwise computes the value with the lookup function, puts it in the
|
||||
* cache, and returns it.
|
||||
*/
|
||||
get(key: Key): Effect.Effect<Value, Error>
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with the specified key if it exists as a left.
|
||||
* Otherwise computes the value with the lookup function, puts it in the
|
||||
* cache, and returns it as a right.
|
||||
*/
|
||||
getEither(key: Key): Effect.Effect<Either<Value, Value>, Error>
|
||||
|
||||
/**
|
||||
* Computes the value associated with the specified key, with the lookup
|
||||
* function, and puts it in the cache. The difference between this and
|
||||
* `get` method is that `refresh` triggers (re)computation of the value
|
||||
* without invalidating it in the cache, so any request to the associated
|
||||
* key can still be served while the value is being re-computed/retrieved
|
||||
* by the lookup function. Additionally, `refresh` always triggers the
|
||||
* lookup function, disregarding the last `Error`.
|
||||
*/
|
||||
refresh(key: Key): Effect.Effect<void, Error>
|
||||
|
||||
/**
|
||||
* Associates the specified value with the specified key in the cache.
|
||||
*/
|
||||
set(key: Key, value: Value): Effect.Effect<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* A ConsumerCache models a portion of a cache which is safe to share without allowing to create new values or access existing ones.
|
||||
*
|
||||
* It can be used safely to give over control for request management without leaking writer side details.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ConsumerCache<in out Key, out Value, out Error = never>
|
||||
extends Cache.ConsumerVariance<Key, Value, Error>
|
||||
{
|
||||
/**
|
||||
* Retrieves the value associated with the specified key if it exists.
|
||||
* Otherwise returns `Option.none`.
|
||||
*/
|
||||
getOption(key: Key): Effect.Effect<Option.Option<Value>, Error>
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with the specified key if it exists and the
|
||||
* lookup function has completed. Otherwise returns `Option.none`.
|
||||
*/
|
||||
getOptionComplete(key: Key): Effect.Effect<Option.Option<Value>>
|
||||
|
||||
/**
|
||||
* Returns statistics for this cache.
|
||||
*/
|
||||
readonly cacheStats: Effect.Effect<CacheStats>
|
||||
|
||||
/**
|
||||
* Returns whether a value associated with the specified key exists in the
|
||||
* cache.
|
||||
*/
|
||||
contains(key: Key): Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Returns statistics for the specified entry.
|
||||
*/
|
||||
entryStats(key: Key): Effect.Effect<Option.Option<EntryStats>>
|
||||
|
||||
/**
|
||||
* Invalidates the value associated with the specified key.
|
||||
*/
|
||||
invalidate(key: Key): Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Invalidates the value associated with the specified key if the predicate holds.
|
||||
*/
|
||||
invalidateWhen(key: Key, predicate: Predicate.Predicate<Value>): Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Invalidates all values in the cache.
|
||||
*/
|
||||
readonly invalidateAll: Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Returns the approximate number of values in the cache.
|
||||
*/
|
||||
readonly size: Effect.Effect<number>
|
||||
|
||||
/**
|
||||
* Returns an approximation of the values in the cache.
|
||||
*/
|
||||
readonly keys: Effect.Effect<Array<Key>>
|
||||
|
||||
/**
|
||||
* Returns an approximation of the values in the cache.
|
||||
*/
|
||||
readonly values: Effect.Effect<Array<Value>>
|
||||
|
||||
/**
|
||||
* Returns an approximation of the values in the cache.
|
||||
*/
|
||||
readonly entries: Effect.Effect<Array<[Key, Value]>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Cache {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in out Key, in out Value, out Error> {
|
||||
readonly [CacheTypeId]: {
|
||||
readonly _Key: Types.Invariant<Key>
|
||||
readonly _Error: Types.Covariant<Error>
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @since 3.6.4
|
||||
* @category models
|
||||
*/
|
||||
export interface ConsumerVariance<in out Key, out Value, out Error> {
|
||||
readonly [ConsumerCacheTypeId]: {
|
||||
readonly _Key: Types.Invariant<Key>
|
||||
readonly _Error: Types.Covariant<Error>
|
||||
readonly _Value: Types.Covariant<Value>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new cache with the specified capacity, time to live, and
|
||||
* lookup function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Key, Value, Error = never, Environment = never>(
|
||||
options: {
|
||||
readonly capacity: number
|
||||
readonly timeToLive: Duration.DurationInput
|
||||
readonly lookup: Lookup<Key, Value, Error, Environment>
|
||||
}
|
||||
) => Effect.Effect<Cache<Key, Value, Error>, never, Environment> = internal.make
|
||||
|
||||
/**
|
||||
* Constructs a new cache with the specified capacity, time to live, and
|
||||
* lookup function, where the time to live can depend on the `Exit` value
|
||||
* returned by the lookup function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWith: <Key, Value, Error = never, Environment = never>(
|
||||
options: {
|
||||
readonly capacity: number
|
||||
readonly lookup: Lookup<Key, Value, Error, Environment>
|
||||
readonly timeToLive: (exit: Exit.Exit<Value, Error>) => Duration.DurationInput
|
||||
}
|
||||
) => Effect.Effect<Cache<Key, Value, Error>, never, Environment> = internal.makeWith
|
||||
|
||||
/**
|
||||
* `CacheStats` represents a snapshot of statistics for the cache as of a
|
||||
* point in time.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface CacheStats {
|
||||
readonly hits: number
|
||||
readonly misses: number
|
||||
readonly size: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new `CacheStats` from the specified values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeCacheStats: (
|
||||
options: {
|
||||
readonly hits: number
|
||||
readonly misses: number
|
||||
readonly size: number
|
||||
}
|
||||
) => CacheStats = internal.makeCacheStats
|
||||
|
||||
/**
|
||||
* Represents a snapshot of statistics for an entry in the cache.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface EntryStats {
|
||||
readonly loadedMillis: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new `EntryStats` from the specified values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeEntryStats: (loadedMillis: number) => EntryStats = internal.makeEntryStats
|
||||
|
||||
/**
|
||||
* A `Lookup` represents a lookup function that, given a key of type `Key`, can
|
||||
* return an effect that will either produce a value of type `Value` or fail
|
||||
* with an error of type `Error` using an environment of type `Environment`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Lookup<Key, Value, Error = never, Environment = never> = (
|
||||
key: Key
|
||||
) => Effect.Effect<Value, Error, Environment>
|
||||
2049
_node_modules/effect/src/Cause.ts
generated
Normal file
2049
_node_modules/effect/src/Cause.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
3051
_node_modules/effect/src/Channel.ts
generated
Normal file
3051
_node_modules/effect/src/Channel.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
158
_node_modules/effect/src/ChildExecutorDecision.ts
generated
Normal file
158
_node_modules/effect/src/ChildExecutorDecision.ts
generated
Normal file
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/channel/childExecutorDecision.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const ChildExecutorDecisionTypeId: unique symbol = internal.ChildExecutorDecisionTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ChildExecutorDecisionTypeId = typeof ChildExecutorDecisionTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type ChildExecutorDecision = Continue | Close | Yield
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace ChildExecutorDecision {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Proto {
|
||||
readonly [ChildExecutorDecisionTypeId]: ChildExecutorDecisionTypeId
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue executing the current substream
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Continue extends ChildExecutorDecision.Proto {
|
||||
readonly _tag: "Continue"
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the current substream with a given value and pass execution to the
|
||||
* next substream
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Close extends ChildExecutorDecision.Proto {
|
||||
readonly _tag: "Close"
|
||||
readonly value: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass execution to the next substream. This either pulls a new element
|
||||
* from upstream, or yields to an already created active substream.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Yield extends ChildExecutorDecision.Proto {
|
||||
readonly _tag: "Yield"
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Continue: (_: void) => ChildExecutorDecision = internal.Continue
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Close: (value: unknown) => ChildExecutorDecision = internal.Close
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Yield: (_: void) => ChildExecutorDecision = internal.Yield
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `ChildExecutorDecision`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isChildExecutorDecision: (u: unknown) => u is ChildExecutorDecision = internal.isChildExecutorDecision
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ChildExecutorDecision` is a `Continue`,
|
||||
* `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isContinue: (self: ChildExecutorDecision) => self is Continue = internal.isContinue
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ChildExecutorDecision` is a `Close`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isClose: (self: ChildExecutorDecision) => self is Close = internal.isClose
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ChildExecutorDecision` is a `Yield`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isYield: (self: ChildExecutorDecision) => self is Yield = internal.isYield
|
||||
|
||||
/**
|
||||
* Folds over a `ChildExecutorDecision` to produce a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* Folds over a `ChildExecutorDecision` to produce a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
options: {
|
||||
readonly onContinue: () => A
|
||||
readonly onClose: (value: unknown) => A
|
||||
readonly onYield: () => A
|
||||
}
|
||||
): (self: ChildExecutorDecision) => A
|
||||
/**
|
||||
* Folds over a `ChildExecutorDecision` to produce a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
self: ChildExecutorDecision,
|
||||
options: {
|
||||
readonly onContinue: () => A
|
||||
readonly onClose: (value: unknown) => A
|
||||
readonly onYield: () => A
|
||||
}
|
||||
): A
|
||||
} = internal.match
|
||||
2350
_node_modules/effect/src/Chunk.ts
generated
Normal file
2350
_node_modules/effect/src/Chunk.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
111
_node_modules/effect/src/Clock.ts
generated
Normal file
111
_node_modules/effect/src/Clock.ts
generated
Normal file
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Context from "./Context.js"
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/clock.js"
|
||||
import * as defaultServices from "./internal/defaultServices.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const ClockTypeId: unique symbol = internal.ClockTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ClockTypeId = typeof ClockTypeId
|
||||
|
||||
/**
|
||||
* Represents a time-based clock which provides functionality related to time
|
||||
* and scheduling.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Clock {
|
||||
readonly [ClockTypeId]: ClockTypeId
|
||||
/**
|
||||
* Unsafely returns the current time in milliseconds.
|
||||
*/
|
||||
unsafeCurrentTimeMillis(): number
|
||||
/**
|
||||
* Returns the current time in milliseconds.
|
||||
*/
|
||||
readonly currentTimeMillis: Effect.Effect<number>
|
||||
/**
|
||||
* Unsafely returns the current time in nanoseconds.
|
||||
*/
|
||||
unsafeCurrentTimeNanos(): bigint
|
||||
/**
|
||||
* Returns the current time in nanoseconds.
|
||||
*/
|
||||
readonly currentTimeNanos: Effect.Effect<bigint>
|
||||
/**
|
||||
* Asynchronously sleeps for the specified duration.
|
||||
*/
|
||||
sleep(duration: Duration.Duration): Effect.Effect<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type CancelToken = () => boolean
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Task = () => void
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ClockScheduler {
|
||||
/**
|
||||
* Unsafely schedules the specified task for the specified duration.
|
||||
*/
|
||||
unsafeSchedule(task: Task, duration: Duration.Duration): CancelToken
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (_: void) => Clock = internal.make
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sleep: (duration: Duration.DurationInput) => Effect.Effect<void> = defaultServices.sleep
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const currentTimeMillis: Effect.Effect<number> = defaultServices.currentTimeMillis
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const currentTimeNanos: Effect.Effect<bigint> = defaultServices.currentTimeNanos
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const clockWith: <A, E, R>(f: (clock: Clock) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> =
|
||||
defaultServices.clockWith
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const Clock: Context.Tag<Clock, Clock> = internal.clockTag
|
||||
743
_node_modules/effect/src/Config.ts
generated
Normal file
743
_node_modules/effect/src/Config.ts
generated
Normal file
@@ -0,0 +1,743 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Brand from "./Brand.js"
|
||||
import type * as Chunk from "./Chunk.js"
|
||||
import type * as ConfigError from "./ConfigError.js"
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Either from "./Either.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import type * as HashMap from "./HashMap.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import * as internal from "./internal/config.js"
|
||||
import type * as LogLevel from "./LogLevel.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Predicate, Refinement } from "./Predicate.js"
|
||||
import type * as Redacted from "./Redacted.js"
|
||||
import type * as Secret from "./Secret.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const ConfigTypeId: unique symbol = internal.ConfigTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ConfigTypeId = typeof ConfigTypeId
|
||||
|
||||
/**
|
||||
* A `Config` describes the structure of some configuration data.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Config<out A> extends Config.Variance<A>, Effect.Effect<A, ConfigError.ConfigError> {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Config {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out A> {
|
||||
readonly [ConfigTypeId]: {
|
||||
readonly _A: Types.Covariant<A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
* @category models
|
||||
*/
|
||||
export type Success<T extends Config<any>> = [T] extends [Config<infer _A>] ? _A : never
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Primitive<out A> extends Config<A> {
|
||||
readonly description: string
|
||||
parse(text: string): Either.Either<A, ConfigError.ConfigError>
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a nested structure, converting all primitives to a `Config`.
|
||||
*
|
||||
* `Config.Wrap<{ key: string }>` becomes `{ key: Config<string> }`
|
||||
*
|
||||
* To create the resulting config, use the `unwrap` constructor.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Wrap<A> = [NonNullable<A>] extends [infer T] ? [IsPlainObject<T>] extends [true] ?
|
||||
| { readonly [K in keyof A]: Wrap<A[K]> }
|
||||
| Config<A>
|
||||
: Config<A>
|
||||
: Config<A>
|
||||
|
||||
type IsPlainObject<A> = [A] extends [Record<string, any>]
|
||||
? [keyof A] extends [never] ? false : [keyof A] extends [string] ? true : false
|
||||
: false
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type LiteralValue = string | number | boolean | null | bigint
|
||||
|
||||
/**
|
||||
* Constructs a config from a tuple / struct / arguments of configs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const all: <const Arg extends Iterable<Config<any>> | Record<string, Config<any>>>(
|
||||
arg: Arg
|
||||
) => Config<
|
||||
[Arg] extends [ReadonlyArray<Config<any>>] ? {
|
||||
-readonly [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never
|
||||
}
|
||||
: [Arg] extends [Iterable<Config<infer A>>] ? Array<A>
|
||||
: [Arg] extends [Record<string, Config<any>>] ? {
|
||||
-readonly [K in keyof Arg]: [Arg[K]] extends [Config<infer A>] ? A : never
|
||||
}
|
||||
: never
|
||||
> = internal.all
|
||||
|
||||
/**
|
||||
* Constructs a config for an array of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const array: <A>(config: Config<A>, name?: string) => Config<Array<A>> = internal.array
|
||||
|
||||
/**
|
||||
* Constructs a config for a boolean value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const boolean: (name?: string) => Config<boolean> = internal.boolean
|
||||
|
||||
/**
|
||||
* Constructs a config for a network port [1, 65535].
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const port: (name?: string) => Config<number> = internal.port
|
||||
|
||||
/**
|
||||
* Constructs a config for an URL value.
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const url: (name?: string) => Config<URL> = internal.url
|
||||
|
||||
/**
|
||||
* Constructs a config for a sequence of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const chunk: <A>(config: Config<A>, name?: string) => Config<Chunk.Chunk<A>> = internal.chunk
|
||||
|
||||
/**
|
||||
* Constructs a config for a date value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const date: (name?: string) => Config<Date> = internal.date
|
||||
|
||||
/**
|
||||
* Constructs a config that fails with the specified message.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fail: (message: string) => Config<never> = internal.fail
|
||||
|
||||
/**
|
||||
* Constructs a config for a float value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const number: (name?: string) => Config<number> = internal.number
|
||||
|
||||
/**
|
||||
* Constructs a config for a integer value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const integer: (name?: string) => Config<number> = internal.integer
|
||||
|
||||
/**
|
||||
* Constructs a config for a literal value.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import { Config } from "effect"
|
||||
*
|
||||
* const config = Config.literal("http", "https")("PROTOCOL")
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const literal: <Literals extends ReadonlyArray<LiteralValue>>(...literals: Literals) => (
|
||||
name?: string
|
||||
) => Config<Literals[number]> = internal.literal
|
||||
|
||||
/**
|
||||
* Constructs a config for a `LogLevel` value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const logLevel: (name?: string) => Config<LogLevel.LogLevel> = internal.logLevel
|
||||
|
||||
/**
|
||||
* Constructs a config for a duration value.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const duration: (name?: string) => Config<Duration.Duration> = internal.duration
|
||||
|
||||
/**
|
||||
* This function returns `true` if the specified value is an `Config` value,
|
||||
* `false` otherwise.
|
||||
*
|
||||
* This function can be useful for checking the type of a value before
|
||||
* attempting to operate on it as an `Config` value. For example, you could
|
||||
* use `isConfig` to check the type of a value before using it as an
|
||||
* argument to a function that expects an `Config` value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isConfig: (u: unknown) => u is Config<unknown> = internal.isConfig
|
||||
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which produces
|
||||
* a different value, constructed using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const map: {
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which produces
|
||||
* a different value, constructed using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, B>(f: (a: A) => B): (self: Config<A>) => Config<B>
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which produces
|
||||
* a different value, constructed using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, B>(self: Config<A>, f: (a: A) => B): Config<B>
|
||||
} = internal.map
|
||||
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which may
|
||||
* produce a different value, constructed using the specified function, which
|
||||
* may throw exceptions that will be translated into validation errors.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const mapAttempt: {
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which may
|
||||
* produce a different value, constructed using the specified function, which
|
||||
* may throw exceptions that will be translated into validation errors.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(f: (a: A) => B): (self: Config<A>) => Config<B>
|
||||
/**
|
||||
* Returns a config whose structure is the same as this one, but which may
|
||||
* produce a different value, constructed using the specified function, which
|
||||
* may throw exceptions that will be translated into validation errors.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(self: Config<A>, f: (a: A) => B): Config<B>
|
||||
} = internal.mapAttempt
|
||||
|
||||
/**
|
||||
* Returns a new config whose structure is the samea as this one, but which
|
||||
* may produce a different value, constructed using the specified fallible
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const mapOrFail: {
|
||||
/**
|
||||
* Returns a new config whose structure is the samea as this one, but which
|
||||
* may produce a different value, constructed using the specified fallible
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(f: (a: A) => Either.Either<B, ConfigError.ConfigError>): (self: Config<A>) => Config<B>
|
||||
/**
|
||||
* Returns a new config whose structure is the samea as this one, but which
|
||||
* may produce a different value, constructed using the specified fallible
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(self: Config<A>, f: (a: A) => Either.Either<B, ConfigError.ConfigError>): Config<B>
|
||||
} = internal.mapOrFail
|
||||
|
||||
/**
|
||||
* Returns a config that has this configuration nested as a property of the
|
||||
* specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const nested: {
|
||||
/**
|
||||
* Returns a config that has this configuration nested as a property of the
|
||||
* specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(name: string): <A>(self: Config<A>) => Config<A>
|
||||
/**
|
||||
* Returns a config that has this configuration nested as a property of the
|
||||
* specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Config<A>, name: string): Config<A>
|
||||
} = internal.nested
|
||||
|
||||
/**
|
||||
* Returns a config whose structure is preferentially described by this
|
||||
* config, but which falls back to the specified config if there is an issue
|
||||
* reading from this config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const orElse: {
|
||||
/**
|
||||
* Returns a config whose structure is preferentially described by this
|
||||
* config, but which falls back to the specified config if there is an issue
|
||||
* reading from this config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A2>(that: LazyArg<Config<A2>>): <A>(self: Config<A>) => Config<A2 | A>
|
||||
/**
|
||||
* Returns a config whose structure is preferentially described by this
|
||||
* config, but which falls back to the specified config if there is an issue
|
||||
* reading from this config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, A2>(self: Config<A>, that: LazyArg<Config<A2>>): Config<A | A2>
|
||||
} = internal.orElse
|
||||
|
||||
/**
|
||||
* Returns configuration which reads from this configuration, but which falls
|
||||
* back to the specified configuration if reading from this configuration
|
||||
* fails with an error satisfying the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const orElseIf: {
|
||||
/**
|
||||
* Returns configuration which reads from this configuration, but which falls
|
||||
* back to the specified configuration if reading from this configuration
|
||||
* fails with an error satisfying the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A2>(
|
||||
options: {
|
||||
readonly if: Predicate<ConfigError.ConfigError>
|
||||
readonly orElse: LazyArg<Config<A2>>
|
||||
}
|
||||
): <A>(self: Config<A>) => Config<A>
|
||||
/**
|
||||
* Returns configuration which reads from this configuration, but which falls
|
||||
* back to the specified configuration if reading from this configuration
|
||||
* fails with an error satisfying the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, A2>(
|
||||
self: Config<A>,
|
||||
options: {
|
||||
readonly if: Predicate<ConfigError.ConfigError>
|
||||
readonly orElse: LazyArg<Config<A2>>
|
||||
}
|
||||
): Config<A>
|
||||
} = internal.orElseIf
|
||||
|
||||
/**
|
||||
* Returns an optional version of this config, which will be `None` if the
|
||||
* data is missing from configuration, and `Some` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const option: <A>(self: Config<A>) => Config<Option.Option<A>> = internal.option
|
||||
|
||||
/**
|
||||
* Constructs a new primitive config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const primitive: <A>(
|
||||
description: string,
|
||||
parse: (text: string) => Either.Either<A, ConfigError.ConfigError>
|
||||
) => Config<A> = internal.primitive
|
||||
|
||||
/**
|
||||
* Returns a config that describes a sequence of values, each of which has the
|
||||
* structure of this config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const repeat: <A>(self: Config<A>) => Config<Array<A>> = internal.repeat
|
||||
|
||||
/**
|
||||
* Constructs a config for a secret value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
* @deprecated
|
||||
*/
|
||||
export const secret: (name?: string) => Config<Secret.Secret> = internal.secret
|
||||
|
||||
/**
|
||||
* Constructs a config for a redacted value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const redacted: {
|
||||
/**
|
||||
* Constructs a config for a redacted value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(name?: string): Config<Redacted.Redacted>
|
||||
/**
|
||||
* Constructs a config for a redacted value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<A>(config: Config<A>): Config<Redacted.Redacted<A>>
|
||||
} = internal.redacted
|
||||
|
||||
/**
|
||||
* Constructs a config for a branded value.
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const branded: {
|
||||
/**
|
||||
* Constructs a config for a branded value.
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category constructors
|
||||
*/
|
||||
<A, B extends Brand.Branded<A, any>>(constructor: Brand.Brand.Constructor<B>): (config: Config<A>) => Config<B>
|
||||
/**
|
||||
* Constructs a config for a branded value.
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category constructors
|
||||
*/
|
||||
<B extends Brand.Branded<string, any>>(name: string | undefined, constructor: Brand.Brand.Constructor<B>): Config<B>
|
||||
/**
|
||||
* Constructs a config for a branded value.
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category constructors
|
||||
*/
|
||||
<A, B extends Brand.Branded<A, any>>(config: Config<A>, constructor: Brand.Brand.Constructor<B>): Config<B>
|
||||
} = internal.branded
|
||||
|
||||
/**
|
||||
* Constructs a config for a sequence of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const hashSet: <A>(config: Config<A>, name?: string) => Config<HashSet.HashSet<A>> = internal.hashSet
|
||||
|
||||
/**
|
||||
* Constructs a config for a string value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const string: (name?: string) => Config<string> = internal.string
|
||||
|
||||
/**
|
||||
* Constructs a config for a non-empty string value.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nonEmptyString: (name?: string) => Config<string> = internal.nonEmptyString
|
||||
|
||||
/**
|
||||
* Constructs a config which contains the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const succeed: <A>(value: A) => Config<A> = internal.succeed
|
||||
|
||||
/**
|
||||
* Lazily constructs a config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const suspend: <A>(config: LazyArg<Config<A>>) => Config<A> = internal.suspend
|
||||
|
||||
/**
|
||||
* Constructs a config which contains the specified lazy value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sync: <A>(value: LazyArg<A>) => Config<A> = internal.sync
|
||||
|
||||
/**
|
||||
* Constructs a config for a sequence of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const hashMap: <A>(config: Config<A>, name?: string) => Config<HashMap.HashMap<string, A>> = internal.hashMap
|
||||
|
||||
/**
|
||||
* Constructs a config from some configuration wrapped with the `Wrap<A>` utility type.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* ```
|
||||
* import { Config, unwrap } from "./Config"
|
||||
*
|
||||
* interface Options { key: string }
|
||||
*
|
||||
* const makeConfig = (config: Config.Wrap<Options>): Config<Options> => unwrap(config)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unwrap: <A>(wrapped: Config.Wrap<A>) => Config<A> = internal.unwrap
|
||||
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but which
|
||||
* performs validation during loading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const validate: {
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but which
|
||||
* performs validation during loading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B extends A>(
|
||||
options: {
|
||||
readonly message: string
|
||||
readonly validation: Refinement<A, B>
|
||||
}
|
||||
): (self: Config<A>) => Config<B>
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but which
|
||||
* performs validation during loading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(
|
||||
options: {
|
||||
readonly message: string
|
||||
readonly validation: Predicate<A>
|
||||
}
|
||||
): (self: Config<A>) => Config<A>
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but which
|
||||
* performs validation during loading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B extends A>(
|
||||
self: Config<A>,
|
||||
options: {
|
||||
readonly message: string
|
||||
readonly validation: Refinement<A, B>
|
||||
}
|
||||
): Config<B>
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but which
|
||||
* performs validation during loading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(
|
||||
self: Config<A>,
|
||||
options: {
|
||||
readonly message: string
|
||||
readonly validation: Predicate<A>
|
||||
}
|
||||
): Config<A>
|
||||
} = internal.validate
|
||||
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but has the
|
||||
* specified default value in case the information cannot be found.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const withDefault: {
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but has the
|
||||
* specified default value in case the information cannot be found.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<const A2>(def: A2): <A>(self: Config<A>) => Config<A2 | A>
|
||||
/**
|
||||
* Returns a config that describes the same structure as this one, but has the
|
||||
* specified default value in case the information cannot be found.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, const A2>(self: Config<A>, def: A2): Config<A | A2>
|
||||
} = internal.withDefault
|
||||
|
||||
/**
|
||||
* Adds a description to this configuration, which is intended for humans.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const withDescription: {
|
||||
/**
|
||||
* Adds a description to this configuration, which is intended for humans.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(description: string): <A>(self: Config<A>) => Config<A>
|
||||
/**
|
||||
* Adds a description to this configuration, which is intended for humans.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Config<A>, description: string): Config<A>
|
||||
} = internal.withDescription
|
||||
|
||||
/**
|
||||
* Returns a config that is the composition of this config and the specified
|
||||
* config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Returns a config that is the composition of this config and the specified
|
||||
* config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<B>(that: Config<B>): <A>(self: Config<A>) => Config<[A, B]>
|
||||
/**
|
||||
* Returns a config that is the composition of this config and the specified
|
||||
* config.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, B>(self: Config<A>, that: Config<B>): Config<[A, B]>
|
||||
} = internal.zip
|
||||
|
||||
/**
|
||||
* Returns a config that is the composes this config and the specified config
|
||||
* using the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipWith: {
|
||||
/**
|
||||
* Returns a config that is the composes this config and the specified config
|
||||
* using the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<B, A, C>(that: Config<B>, f: (a: A, b: B) => C): (self: Config<A>) => Config<C>
|
||||
/**
|
||||
* Returns a config that is the composes this config and the specified config
|
||||
* using the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, B, C>(self: Config<A>, that: Config<B>, f: (a: A, b: B) => C): Config<C>
|
||||
} = internal.zipWith
|
||||
286
_node_modules/effect/src/ConfigError.ts
generated
Normal file
286
_node_modules/effect/src/ConfigError.ts
generated
Normal file
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import * as internal from "./internal/configError.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const ConfigErrorTypeId: unique symbol = internal.ConfigErrorTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ConfigErrorTypeId = typeof ConfigErrorTypeId
|
||||
|
||||
/**
|
||||
* The possible ways that loading configuration data may fail.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type ConfigError =
|
||||
| And
|
||||
| Or
|
||||
| InvalidData
|
||||
| MissingData
|
||||
| SourceUnavailable
|
||||
| Unsupported
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace ConfigError {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Proto {
|
||||
readonly _tag: "ConfigError"
|
||||
readonly [ConfigErrorTypeId]: ConfigErrorTypeId
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Reducer<C, Z> = ConfigErrorReducer<C, Z>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ConfigErrorReducer<in C, in out Z> {
|
||||
andCase(context: C, left: Z, right: Z): Z
|
||||
orCase(context: C, left: Z, right: Z): Z
|
||||
invalidDataCase(context: C, path: Array<string>, message: string): Z
|
||||
missingDataCase(context: C, path: Array<string>, message: string): Z
|
||||
sourceUnavailableCase(
|
||||
context: C,
|
||||
path: Array<string>,
|
||||
message: string,
|
||||
cause: Cause.Cause<unknown>
|
||||
): Z
|
||||
unsupportedCase(context: C, path: Array<string>, message: string): Z
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface And extends ConfigError.Proto {
|
||||
readonly _op: "And"
|
||||
readonly left: ConfigError
|
||||
readonly right: ConfigError
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Or extends ConfigError.Proto {
|
||||
readonly _op: "Or"
|
||||
readonly left: ConfigError
|
||||
readonly right: ConfigError
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface InvalidData extends ConfigError.Proto {
|
||||
readonly _op: "InvalidData"
|
||||
readonly path: Array<string>
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MissingData extends ConfigError.Proto {
|
||||
readonly _op: "MissingData"
|
||||
readonly path: Array<string>
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface SourceUnavailable extends ConfigError.Proto {
|
||||
readonly _op: "SourceUnavailable"
|
||||
readonly path: Array<string>
|
||||
readonly message: string
|
||||
readonly cause: Cause.Cause<unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Unsupported extends ConfigError.Proto {
|
||||
readonly _op: "Unsupported"
|
||||
readonly path: Array<string>
|
||||
readonly message: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Options {
|
||||
readonly pathDelim: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const And: (self: ConfigError, that: ConfigError) => ConfigError = internal.And
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Or: (self: ConfigError, that: ConfigError) => ConfigError = internal.Or
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const MissingData: (path: Array<string>, message: string, options?: Options) => ConfigError =
|
||||
internal.MissingData
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const InvalidData: (path: Array<string>, message: string, options?: Options) => ConfigError =
|
||||
internal.InvalidData
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const SourceUnavailable: (
|
||||
path: Array<string>,
|
||||
message: string,
|
||||
cause: Cause.Cause<unknown>,
|
||||
options?: Options
|
||||
) => ConfigError = internal.SourceUnavailable
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Unsupported: (path: Array<string>, message: string, options?: Options) => ConfigError =
|
||||
internal.Unsupported
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `ConfigError`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isConfigError: (u: unknown) => u is ConfigError = internal.isConfigError
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is an `And`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isAnd: (self: ConfigError) => self is And = internal.isAnd
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is an `Or`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isOr: (self: ConfigError) => self is Or = internal.isOr
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is an `InvalidData`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isInvalidData: (self: ConfigError) => self is InvalidData = internal.isInvalidData
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is an `MissingData`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMissingData: (self: ConfigError) => self is MissingData = internal.isMissingData
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` contains only `MissingData` errors, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categer getters
|
||||
*/
|
||||
export const isMissingDataOnly: (self: ConfigError) => boolean = internal.isMissingDataOnly
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is a `SourceUnavailable`,
|
||||
* `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSourceUnavailable: (self: ConfigError) => self is SourceUnavailable = internal.isSourceUnavailable
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ConfigError` is an `Unsupported`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isUnsupported: (self: ConfigError) => self is Unsupported = internal.isUnsupported
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const prefixed: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(prefix: Array<string>): (self: ConfigError) => ConfigError
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: ConfigError, prefix: Array<string>): ConfigError
|
||||
} = internal.prefixed
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const reduceWithContext: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<C, Z>(context: C, reducer: ConfigErrorReducer<C, Z>): (self: ConfigError) => Z
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<C, Z>(self: ConfigError, context: C, reducer: ConfigErrorReducer<C, Z>): Z
|
||||
} = internal.reduceWithContext
|
||||
421
_node_modules/effect/src/ConfigProvider.ts
generated
Normal file
421
_node_modules/effect/src/ConfigProvider.ts
generated
Normal file
@@ -0,0 +1,421 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Config from "./Config.js"
|
||||
import type * as ConfigError from "./ConfigError.js"
|
||||
import type * as PathPatch from "./ConfigProviderPathPatch.js"
|
||||
import type * as Context from "./Context.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import * as internal from "./internal/configProvider.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const ConfigProviderTypeId: unique symbol = internal.ConfigProviderTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ConfigProviderTypeId = typeof ConfigProviderTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FlatConfigProviderTypeId: unique symbol = internal.FlatConfigProviderTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FlatConfigProviderTypeId = typeof FlatConfigProviderTypeId
|
||||
|
||||
/**
|
||||
* A ConfigProvider is a service that provides configuration given a description
|
||||
* of the structure of that configuration.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ConfigProvider extends ConfigProvider.Proto, Pipeable {
|
||||
/**
|
||||
* Loads the specified configuration, or fails with a config error.
|
||||
*/
|
||||
load<A>(config: Config.Config<A>): Effect.Effect<A, ConfigError.ConfigError>
|
||||
/**
|
||||
* Flattens this config provider into a simplified config provider that knows
|
||||
* only how to deal with flat (key/value) properties.
|
||||
*/
|
||||
readonly flattened: ConfigProvider.Flat
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace ConfigProvider {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Proto {
|
||||
readonly [ConfigProviderTypeId]: ConfigProviderTypeId
|
||||
}
|
||||
|
||||
/**
|
||||
* A simplified config provider that knows only how to deal with flat
|
||||
* (key/value) properties. Because these providers are common, there is
|
||||
* special support for implementing them.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Flat {
|
||||
readonly [FlatConfigProviderTypeId]: FlatConfigProviderTypeId
|
||||
readonly patch: PathPatch.PathPatch
|
||||
load<A>(
|
||||
path: ReadonlyArray<string>,
|
||||
config: Config.Config.Primitive<A>,
|
||||
split?: boolean
|
||||
): Effect.Effect<Array<A>, ConfigError.ConfigError>
|
||||
enumerateChildren(
|
||||
path: ReadonlyArray<string>
|
||||
): Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface FromMapConfig {
|
||||
readonly pathDelim: string
|
||||
readonly seqDelim: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface FromEnvConfig {
|
||||
readonly pathDelim: string
|
||||
readonly seqDelim: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type KeyComponent = KeyName | KeyIndex
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface KeyName {
|
||||
readonly _tag: "KeyName"
|
||||
readonly name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface KeyIndex {
|
||||
readonly _tag: "KeyIndex"
|
||||
readonly index: number
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The service tag for `ConfigProvider`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const ConfigProvider: Context.Tag<ConfigProvider, ConfigProvider> = internal.configProviderTag
|
||||
|
||||
/**
|
||||
* Creates a new config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (
|
||||
options: {
|
||||
readonly load: <A>(config: Config.Config<A>) => Effect.Effect<A, ConfigError.ConfigError>
|
||||
readonly flattened: ConfigProvider.Flat
|
||||
}
|
||||
) => ConfigProvider = internal.make
|
||||
|
||||
/**
|
||||
* Creates a new flat config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeFlat: (options: {
|
||||
readonly load: <A>(
|
||||
path: ReadonlyArray<string>,
|
||||
config: Config.Config.Primitive<A>,
|
||||
split: boolean
|
||||
) => Effect.Effect<Array<A>, ConfigError.ConfigError>
|
||||
readonly enumerateChildren: (
|
||||
path: ReadonlyArray<string>
|
||||
) => Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError>
|
||||
readonly patch: PathPatch.PathPatch
|
||||
}) => ConfigProvider.Flat = internal.makeFlat
|
||||
|
||||
/**
|
||||
* A config provider that loads configuration from context variables
|
||||
*
|
||||
* **Options**:
|
||||
*
|
||||
* - `pathDelim`: The delimiter for the path segments (default: `"_"`).
|
||||
* - `seqDelim`: The delimiter for the sequence of values (default: `","`).
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromEnv: (options?: Partial<ConfigProvider.FromEnvConfig>) => ConfigProvider = internal.fromEnv
|
||||
|
||||
/**
|
||||
* Constructs a new `ConfigProvider` from a key/value (flat) provider, where
|
||||
* nesting is embedded into the string keys.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromFlat: (flat: ConfigProvider.Flat) => ConfigProvider = internal.fromFlat
|
||||
|
||||
/**
|
||||
* Constructs a new `ConfigProvider` from a JSON object.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromJson: (json: unknown) => ConfigProvider = internal.fromJson
|
||||
|
||||
// TODO(4.0): use `_` for nested configs instead of `.` in next major
|
||||
/**
|
||||
* Constructs a ConfigProvider using a map and the specified delimiter string,
|
||||
* which determines how to split the keys in the map into path segments.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromMap: (map: Map<string, string>, config?: Partial<ConfigProvider.FromMapConfig>) => ConfigProvider =
|
||||
internal.fromMap
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically convert all property
|
||||
* names to constant case. This can be utilized to adapt the names of
|
||||
* configuration properties from the default naming convention of camel case
|
||||
* to the naming convention of a config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const constantCase: (self: ConfigProvider) => ConfigProvider = internal.constantCase
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically tranform all path
|
||||
* configuration names with the specified function. This can be utilized to
|
||||
* adapt the names of configuration properties from one naming convention to
|
||||
* another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const mapInputPath: {
|
||||
/**
|
||||
* Returns a new config provider that will automatically tranform all path
|
||||
* configuration names with the specified function. This can be utilized to
|
||||
* adapt the names of configuration properties from one naming convention to
|
||||
* another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(f: (path: string) => string): (self: ConfigProvider) => ConfigProvider
|
||||
/**
|
||||
* Returns a new config provider that will automatically tranform all path
|
||||
* configuration names with the specified function. This can be utilized to
|
||||
* adapt the names of configuration properties from one naming convention to
|
||||
* another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: ConfigProvider, f: (path: string) => string): ConfigProvider
|
||||
} = internal.mapInputPath
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically convert all property
|
||||
* names to kebab case. This can be utilized to adapt the names of
|
||||
* configuration properties from the default naming convention of camel case
|
||||
* to the naming convention of a config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const kebabCase: (self: ConfigProvider) => ConfigProvider = internal.kebabCase
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically convert all property
|
||||
* names to lower case. This can be utilized to adapt the names of
|
||||
* configuration properties from the default naming convention of camel case
|
||||
* to the naming convention of a config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const lowerCase: (self: ConfigProvider) => ConfigProvider = internal.lowerCase
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const nested: {
|
||||
/**
|
||||
* Returns a new config provider that will automatically nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(name: string): (self: ConfigProvider) => ConfigProvider
|
||||
/**
|
||||
* Returns a new config provider that will automatically nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: ConfigProvider, name: string): ConfigProvider
|
||||
} = internal.nested
|
||||
|
||||
/**
|
||||
* Returns a new config provider that preferentially loads configuration data
|
||||
* from this one, but which will fall back to the specified alternate provider
|
||||
* if there are any issues loading the configuration from this provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const orElse: {
|
||||
/**
|
||||
* Returns a new config provider that preferentially loads configuration data
|
||||
* from this one, but which will fall back to the specified alternate provider
|
||||
* if there are any issues loading the configuration from this provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(that: LazyArg<ConfigProvider>): (self: ConfigProvider) => ConfigProvider
|
||||
/**
|
||||
* Returns a new config provider that preferentially loads configuration data
|
||||
* from this one, but which will fall back to the specified alternate provider
|
||||
* if there are any issues loading the configuration from this provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: ConfigProvider, that: LazyArg<ConfigProvider>): ConfigProvider
|
||||
} = internal.orElse
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically un-nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* de-aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const unnested: {
|
||||
/**
|
||||
* Returns a new config provider that will automatically un-nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* de-aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(name: string): (self: ConfigProvider) => ConfigProvider
|
||||
/**
|
||||
* Returns a new config provider that will automatically un-nest all
|
||||
* configuration under the specified property name. This can be utilized to
|
||||
* de-aggregate separate configuration sources that are all required to load a
|
||||
* single configuration value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: ConfigProvider, name: string): ConfigProvider
|
||||
} = internal.unnested
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically convert all property
|
||||
* names to upper case. This can be utilized to adapt the names of
|
||||
* configuration properties from the default naming convention of camel case
|
||||
* to the naming convention of a config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const snakeCase: (self: ConfigProvider) => ConfigProvider = internal.snakeCase
|
||||
|
||||
/**
|
||||
* Returns a new config provider that will automatically convert all property
|
||||
* names to upper case. This can be utilized to adapt the names of
|
||||
* configuration properties from the default naming convention of camel case
|
||||
* to the naming convention of a config provider.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const upperCase: (self: ConfigProvider) => ConfigProvider = internal.upperCase
|
||||
|
||||
/**
|
||||
* Returns a new config provider that transforms the config provider with the
|
||||
* specified function within the specified path.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const within: {
|
||||
/**
|
||||
* Returns a new config provider that transforms the config provider with the
|
||||
* specified function within the specified path.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
(path: ReadonlyArray<string>, f: (self: ConfigProvider) => ConfigProvider): (self: ConfigProvider) => ConfigProvider
|
||||
/**
|
||||
* Returns a new config provider that transforms the config provider with the
|
||||
* specified function within the specified path.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
(
|
||||
self: ConfigProvider,
|
||||
path: ReadonlyArray<string>,
|
||||
f: (self: ConfigProvider) => ConfigProvider
|
||||
): ConfigProvider
|
||||
} = internal.within
|
||||
132
_node_modules/effect/src/ConfigProviderPathPatch.ts
generated
Normal file
132
_node_modules/effect/src/ConfigProviderPathPatch.ts
generated
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/configProvider/pathPatch.js"
|
||||
|
||||
/**
|
||||
* Represents a description of how to modify the path to a configuration
|
||||
* value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type PathPatch = Empty | AndThen | MapName | Nested | Unnested
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Empty {
|
||||
readonly _tag: "Empty"
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface AndThen {
|
||||
readonly _tag: "AndThen"
|
||||
readonly first: PathPatch
|
||||
readonly second: PathPatch
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MapName {
|
||||
readonly _tag: "MapName"
|
||||
f(string: string): string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Nested {
|
||||
readonly _tag: "Nested"
|
||||
readonly name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Unnested {
|
||||
readonly _tag: "Unnested"
|
||||
readonly name: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty: PathPatch = internal.empty
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const andThen: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(that: PathPatch): (self: PathPatch) => PathPatch
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: PathPatch, that: PathPatch): PathPatch
|
||||
} = internal.andThen
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const mapName: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(f: (string: string) => string): (self: PathPatch) => PathPatch
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: PathPatch, f: (string: string) => string): PathPatch
|
||||
} = internal.mapName
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nested: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(name: string): (self: PathPatch) => PathPatch
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: PathPatch, name: string): PathPatch
|
||||
} = internal.nested
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unnested: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(name: string): (self: PathPatch) => PathPatch
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: PathPatch, name: string): PathPatch
|
||||
} = internal.unnested
|
||||
255
_node_modules/effect/src/Console.ts
generated
Normal file
255
_node_modules/effect/src/Console.ts
generated
Normal file
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Context from "./Context.js"
|
||||
import type { Effect } from "./Effect.js"
|
||||
import * as internal from "./internal/console.js"
|
||||
import * as defaultConsole from "./internal/defaultServices/console.js"
|
||||
import type * as Layer from "./Layer.js"
|
||||
import type { Scope } from "./Scope.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export const TypeId: unique symbol = defaultConsole.TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Console {
|
||||
readonly [TypeId]: TypeId
|
||||
assert(condition: boolean, ...args: ReadonlyArray<any>): Effect<void>
|
||||
readonly clear: Effect<void>
|
||||
count(label?: string): Effect<void>
|
||||
countReset(label?: string): Effect<void>
|
||||
debug(...args: ReadonlyArray<any>): Effect<void>
|
||||
dir(item: any, options?: any): Effect<void>
|
||||
dirxml(...args: ReadonlyArray<any>): Effect<void>
|
||||
error(...args: ReadonlyArray<any>): Effect<void>
|
||||
group(options?: {
|
||||
readonly label?: string | undefined
|
||||
readonly collapsed?: boolean | undefined
|
||||
}): Effect<void>
|
||||
readonly groupEnd: Effect<void>
|
||||
info(...args: ReadonlyArray<any>): Effect<void>
|
||||
log(...args: ReadonlyArray<any>): Effect<void>
|
||||
table(tabularData: any, properties?: ReadonlyArray<string>): Effect<void>
|
||||
time(label?: string): Effect<void>
|
||||
timeEnd(label?: string): Effect<void>
|
||||
timeLog(label?: string, ...args: ReadonlyArray<any>): Effect<void>
|
||||
trace(...args: ReadonlyArray<any>): Effect<void>
|
||||
warn(...args: ReadonlyArray<any>): Effect<void>
|
||||
readonly unsafe: UnsafeConsole
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface UnsafeConsole {
|
||||
assert(condition: boolean, ...args: ReadonlyArray<any>): void
|
||||
clear(): void
|
||||
count(label?: string): void
|
||||
countReset(label?: string): void
|
||||
debug(...args: ReadonlyArray<any>): void
|
||||
dir(item: any, options?: any): void
|
||||
dirxml(...args: ReadonlyArray<any>): void
|
||||
error(...args: ReadonlyArray<any>): void
|
||||
group(...args: ReadonlyArray<any>): void
|
||||
groupCollapsed(...args: ReadonlyArray<any>): void
|
||||
groupEnd(): void
|
||||
info(...args: ReadonlyArray<any>): void
|
||||
log(...args: ReadonlyArray<any>): void
|
||||
table(tabularData: any, properties?: ReadonlyArray<string>): void
|
||||
time(label?: string): void
|
||||
timeEnd(label?: string): void
|
||||
timeLog(label?: string, ...args: ReadonlyArray<any>): void
|
||||
trace(...args: ReadonlyArray<any>): void
|
||||
warn(...args: ReadonlyArray<any>): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const Console: Context.Tag<Console, Console> = defaultConsole.consoleTag
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category default services
|
||||
*/
|
||||
export const withConsole: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category default services
|
||||
*/
|
||||
<C extends Console>(console: C): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category default services
|
||||
*/
|
||||
<A, E, R, C extends Console>(effect: Effect<A, E, R>, console: C): Effect<A, E, R>
|
||||
} = internal.withConsole
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category default services
|
||||
*/
|
||||
export const setConsole: <A extends Console>(console: A) => Layer.Layer<never> = internal.setConsole
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const consoleWith: <A, E, R>(f: (console: Console) => Effect<A, E, R>) => Effect<A, E, R> = internal.consoleWith
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const assert: (condition: boolean, ...args: ReadonlyArray<any>) => Effect<void> = internal.assert
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const clear: Effect<void> = internal.clear
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const count: (label?: string) => Effect<void> = internal.count
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const countReset: (label?: string) => Effect<void> = internal.countReset
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const debug: (...args: ReadonlyArray<any>) => Effect<void> = internal.debug
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const dir: (item: any, options?: any) => Effect<void> = internal.dir
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const dirxml: (...args: ReadonlyArray<any>) => Effect<void> = internal.dirxml
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const error: (...args: ReadonlyArray<any>) => Effect<void> = internal.error
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const group: (
|
||||
options?: { label?: string | undefined; collapsed?: boolean | undefined } | undefined
|
||||
) => Effect<void, never, Scope> = internal.group
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const info: (...args: ReadonlyArray<any>) => Effect<void> = internal.info
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const log: (...args: ReadonlyArray<any>) => Effect<void> = internal.log
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const table: (tabularData: any, properties?: ReadonlyArray<string>) => Effect<void> = internal.table
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const time: (label?: string | undefined) => Effect<void, never, Scope> = internal.time
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const timeLog: (label?: string, ...args: ReadonlyArray<any>) => Effect<void> = internal.timeLog
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const trace: (...args: ReadonlyArray<any>) => Effect<void> = internal.trace
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const warn: (...args: ReadonlyArray<any>) => Effect<void> = internal.warn
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const withGroup: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
(
|
||||
options?: {
|
||||
readonly label?: string | undefined
|
||||
readonly collapsed?: boolean | undefined
|
||||
}
|
||||
): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
<A, E, R>(
|
||||
self: Effect<A, E, R>,
|
||||
options?: {
|
||||
readonly label?: string | undefined
|
||||
readonly collapsed?: boolean | undefined
|
||||
}
|
||||
): Effect<A, E, R>
|
||||
} = internal.withGroup
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
export const withTime: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
(label?: string): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessor
|
||||
*/
|
||||
<A, E, R>(self: Effect<A, E, R>, label?: string): Effect<A, E, R>
|
||||
} = internal.withTime
|
||||
867
_node_modules/effect/src/Context.ts
generated
Normal file
867
_node_modules/effect/src/Context.ts
generated
Normal file
@@ -0,0 +1,867 @@
|
||||
/**
|
||||
* This module provides a data structure called `Context` that can be used for dependency injection in effectful
|
||||
* programs. It is essentially a table mapping `Tag`s to their implementations (called `Service`s), and can be used to
|
||||
* manage dependencies in a type-safe way. The `Context` data structure is essentially a way of providing access to a set
|
||||
* of related services that can be passed around as a single unit. This module provides functions to create, modify, and
|
||||
* query the contents of a `Context`, as well as a number of utility types for working with tags and services.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type { Equal } from "./Equal.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import * as internal from "./internal/context.js"
|
||||
import type { Option } from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const TagTypeId: unique symbol = internal.TagTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TagTypeId = typeof TagTypeId
|
||||
|
||||
/**
|
||||
* @since 3.5.9
|
||||
* @category models
|
||||
*/
|
||||
export interface Tag<in out Id, in out Value> extends Pipeable, Inspectable, ReadonlyTag<Id, Value> {
|
||||
readonly _op: "Tag"
|
||||
readonly Service: Value
|
||||
readonly Identifier: Id
|
||||
readonly [TagTypeId]: {
|
||||
readonly _Service: Types.Invariant<Value>
|
||||
readonly _Identifier: Types.Invariant<Id>
|
||||
}
|
||||
of(self: Value): Value
|
||||
context(self: Value): Context<Id>
|
||||
readonly stack?: string | undefined
|
||||
readonly key: string
|
||||
[Unify.typeSymbol]?: unknown
|
||||
[Unify.unifySymbol]?: TagUnify<this>
|
||||
[Unify.ignoreSymbol]?: TagUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.5.9
|
||||
* @category models
|
||||
*/
|
||||
export interface ReadonlyTag<in out Id, out Value> extends Pipeable, Inspectable, Effect.Effect<Value, never, Id> {
|
||||
readonly _op: "Tag"
|
||||
readonly Service: Value
|
||||
readonly Identifier: Id
|
||||
readonly [TagTypeId]: {
|
||||
readonly _Service: Types.Covariant<Value>
|
||||
readonly _Identifier: Types.Invariant<Id>
|
||||
}
|
||||
readonly stack?: string | undefined
|
||||
readonly key: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.11.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const ReferenceTypeId: unique symbol = internal.ReferenceTypeId
|
||||
|
||||
/**
|
||||
* @since 3.11.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type ReferenceTypeId = typeof ReferenceTypeId
|
||||
|
||||
/**
|
||||
* @since 3.11.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Reference<in out Id, in out Value> extends Pipeable, Inspectable {
|
||||
readonly [ReferenceTypeId]: ReferenceTypeId
|
||||
readonly defaultValue: () => Value
|
||||
|
||||
readonly _op: "Tag"
|
||||
readonly Service: Value
|
||||
readonly Identifier: Id
|
||||
readonly [TagTypeId]: {
|
||||
readonly _Service: Types.Invariant<Value>
|
||||
readonly _Identifier: Types.Invariant<Id>
|
||||
}
|
||||
of(self: Value): Value
|
||||
context(self: Value): Context<Id>
|
||||
readonly stack?: string | undefined
|
||||
readonly key: string
|
||||
[Unify.typeSymbol]?: unknown
|
||||
[Unify.unifySymbol]?: TagUnify<this>
|
||||
[Unify.ignoreSymbol]?: TagUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface TagClassShape<Id, Shape> {
|
||||
readonly [TagTypeId]: TagTypeId
|
||||
readonly Type: Shape
|
||||
readonly Id: Id
|
||||
}
|
||||
|
||||
// TODO(4.0): move key narrowing to the Tag interface
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface TagClass<Self, Id extends string, Type> extends Tag<Self, Type> {
|
||||
new(_: never): TagClassShape<Id, Type>
|
||||
readonly key: Id
|
||||
}
|
||||
|
||||
// TODO(4.0): move key narrowing to the Reference interface
|
||||
/**
|
||||
* @since 3.11.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ReferenceClass<Self, Id extends string, Type> extends Reference<Self, Type> {
|
||||
new(_: never): TagClassShape<Id, Type>
|
||||
readonly key: Id
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface TagUnify<A extends { [Unify.typeSymbol]?: any }> {
|
||||
Tag?: () => Extract<A[Unify.typeSymbol], Tag<any, any>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface TagUnifyIgnore {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Tag {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Service<T extends Tag<any, any> | TagClassShape<any, any>> = T extends Tag<any, any> ? T["Service"]
|
||||
: T extends TagClassShape<any, infer A> ? A
|
||||
: never
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Identifier<T extends Tag<any, any> | TagClassShape<any, any>> = T extends Tag<any, any> ? T["Identifier"]
|
||||
: T extends TagClassShape<any, any> ? T
|
||||
: never
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new `Tag` instance with an optional key parameter.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* assert.strictEqual(Context.GenericTag("PORT").key === Context.GenericTag("PORT").key, true)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const GenericTag: <Identifier, Service = Identifier>(key: string) => Tag<Identifier, Service> =
|
||||
internal.makeGenericTag
|
||||
|
||||
const TypeId: unique symbol = internal.TypeId as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type ValidTagsById<R> = R extends infer S ? Tag<S, any> : never
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Context<in Services> extends Equal, Pipeable, Inspectable {
|
||||
readonly [TypeId]: {
|
||||
readonly _Services: Types.Contravariant<Services>
|
||||
}
|
||||
readonly unsafeMap: Map<string, any>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMake: <Services>(unsafeMap: Map<string, any>) => Context<Services> = internal.makeContext
|
||||
|
||||
/**
|
||||
* Checks if the provided argument is a `Context`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* assert.strictEqual(Context.isContext(Context.empty()), true)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isContext: (input: unknown) => input is Context<never> = internal.isContext
|
||||
|
||||
/**
|
||||
* Checks if the provided argument is a `Tag`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* assert.strictEqual(Context.isTag(Context.GenericTag("Tag")), true)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isTag: (input: unknown) => input is Tag<any, any> = internal.isTag
|
||||
|
||||
/**
|
||||
* Checks if the provided argument is a `Reference`.
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @category guards
|
||||
* @experimental
|
||||
*/
|
||||
export const isReference: (u: unknown) => u is Reference<any, any> = internal.isReference
|
||||
|
||||
/**
|
||||
* Returns an empty `Context`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* assert.strictEqual(Context.isContext(Context.empty()), true)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty: () => Context<never> = internal.empty
|
||||
|
||||
/**
|
||||
* Creates a new `Context` with a single service associated to the tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <I, S>(tag: Tag<I, S>, service: Types.NoInfer<S>) => Context<I> = internal.make
|
||||
|
||||
/**
|
||||
* Adds a service to a given `Context`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, pipe } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const someContext = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* const Services = pipe(
|
||||
* someContext,
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const add: {
|
||||
/**
|
||||
* Adds a service to a given `Context`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, pipe } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const someContext = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* const Services = pipe(
|
||||
* someContext,
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<I, S>(tag: Tag<I, S>, service: Types.NoInfer<S>): <Services>(self: Context<Services>) => Context<Services | I>
|
||||
/**
|
||||
* Adds a service to a given `Context`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, pipe } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const someContext = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* const Services = pipe(
|
||||
* someContext,
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Services, I, S>(self: Context<Services>, tag: Tag<I, S>, service: Types.NoInfer<S>): Context<Services | I>
|
||||
} = internal.add
|
||||
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<I, S>(tag: Reference<I, S>): <Services>(self: Context<Services>) => S
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<Services, I extends Services, S>(tag: Tag<I, S>): (self: Context<Services>) => S
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<Services, I, S>(self: Context<Services>, tag: Reference<I, S>): S
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<Services, I extends Services, S>(self: Context<Services>, tag: Tag<I, S>): S
|
||||
} = internal.get
|
||||
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag, or
|
||||
* use the fallback value.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @category getters
|
||||
*/
|
||||
export const getOrElse: {
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag, or
|
||||
* use the fallback value.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @category getters
|
||||
*/
|
||||
<S, I, B>(tag: Tag<I, S>, orElse: LazyArg<B>): <Services>(self: Context<Services>) => S | B
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag, or
|
||||
* use the fallback value.
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @category getters
|
||||
*/
|
||||
<Services, S, I, B>(self: Context<Services>, tag: Tag<I, S>, orElse: LazyArg<B>): S | B
|
||||
} = internal.getOrElse
|
||||
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
* This function is unsafe because if the tag is not present in the context, a runtime error will be thrown.
|
||||
*
|
||||
* For a safer version see {@link getOption}.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.unsafeGet(Services, Port), { PORT: 8080 })
|
||||
* assert.throws(() => Context.unsafeGet(Services, Timeout))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeGet: {
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
* This function is unsafe because if the tag is not present in the context, a runtime error will be thrown.
|
||||
*
|
||||
* For a safer version see {@link getOption}.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.unsafeGet(Services, Port), { PORT: 8080 })
|
||||
* assert.throws(() => Context.unsafeGet(Services, Timeout))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
<S, I>(tag: Tag<I, S>): <Services>(self: Context<Services>) => S
|
||||
/**
|
||||
* Get a service from the context that corresponds to the given tag.
|
||||
* This function is unsafe because if the tag is not present in the context, a runtime error will be thrown.
|
||||
*
|
||||
* For a safer version see {@link getOption}.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.unsafeGet(Services, Port), { PORT: 8080 })
|
||||
* assert.throws(() => Context.unsafeGet(Services, Timeout))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
<Services, S, I>(self: Context<Services>, tag: Tag<I, S>): S
|
||||
} = internal.unsafeGet
|
||||
|
||||
/**
|
||||
* Get the value associated with the specified tag from the context wrapped in an `Option` object. If the tag is not
|
||||
* found, the `Option` object will be `None`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, Option } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 }))
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none())
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const getOption: {
|
||||
/**
|
||||
* Get the value associated with the specified tag from the context wrapped in an `Option` object. If the tag is not
|
||||
* found, the `Option` object will be `None`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, Option } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 }))
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none())
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<S, I>(tag: Tag<I, S>): <Services>(self: Context<Services>) => Option<S>
|
||||
/**
|
||||
* Get the value associated with the specified tag from the context wrapped in an `Option` object. If the tag is not
|
||||
* found, the `Option` object will be `None`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, Option } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const Services = Context.make(Port, { PORT: 8080 })
|
||||
*
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 }))
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none())
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<Services, S, I>(self: Context<Services>, tag: Tag<I, S>): Option<S>
|
||||
} = internal.getOption
|
||||
|
||||
/**
|
||||
* Merges two `Context`s, returning a new `Context` containing the services of both.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const firstContext = Context.make(Port, { PORT: 8080 })
|
||||
* const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
|
||||
*
|
||||
* const Services = Context.merge(firstContext, secondContext)
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const merge: {
|
||||
/**
|
||||
* Merges two `Context`s, returning a new `Context` containing the services of both.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const firstContext = Context.make(Port, { PORT: 8080 })
|
||||
* const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
|
||||
*
|
||||
* const Services = Context.merge(firstContext, secondContext)
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<R1>(that: Context<R1>): <Services>(self: Context<Services>) => Context<R1 | Services>
|
||||
/**
|
||||
* Merges two `Context`s, returning a new `Context` containing the services of both.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const firstContext = Context.make(Port, { PORT: 8080 })
|
||||
* const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
|
||||
*
|
||||
* const Services = Context.merge(firstContext, secondContext)
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Services, R1>(self: Context<Services>, that: Context<R1>): Context<Services | R1>
|
||||
} = internal.merge
|
||||
|
||||
/**
|
||||
* Merges any number of `Context`s, returning a new `Context` containing the services of all.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
* const Host = Context.GenericTag<{ HOST: string }>("Host")
|
||||
*
|
||||
* const firstContext = Context.make(Port, { PORT: 8080 })
|
||||
* const secondContext = Context.make(Timeout, { TIMEOUT: 5000 })
|
||||
* const thirdContext = Context.make(Host, { HOST: "localhost" })
|
||||
*
|
||||
* const Services = Context.mergeAll(firstContext, secondContext, thirdContext)
|
||||
*
|
||||
* assert.deepStrictEqual(Context.get(Services, Port), { PORT: 8080 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Timeout), { TIMEOUT: 5000 })
|
||||
* assert.deepStrictEqual(Context.get(Services, Host), { HOST: "localhost" })
|
||||
* ```
|
||||
*
|
||||
* @since 3.12.0
|
||||
*/
|
||||
export const mergeAll: <T extends Array<unknown>>(
|
||||
...ctxs: [...{ [K in keyof T]: Context<T[K]> }]
|
||||
) => Context<T[number]> = internal.mergeAll
|
||||
|
||||
/**
|
||||
* Returns a new `Context` that contains only the specified services.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { pipe, Context, Option } from "effect"
|
||||
*
|
||||
* const Port = Context.GenericTag<{ PORT: number }>("Port")
|
||||
* const Timeout = Context.GenericTag<{ TIMEOUT: number }>("Timeout")
|
||||
*
|
||||
* const someContext = pipe(
|
||||
* Context.make(Port, { PORT: 8080 }),
|
||||
* Context.add(Timeout, { TIMEOUT: 5000 })
|
||||
* )
|
||||
*
|
||||
* const Services = pipe(someContext, Context.pick(Port))
|
||||
*
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Port), Option.some({ PORT: 8080 }))
|
||||
* assert.deepStrictEqual(Context.getOption(Services, Timeout), Option.none())
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const pick: <Tags extends ReadonlyArray<Tag<any, any>>>(
|
||||
...tags: Tags
|
||||
) => <Services>(self: Context<Services>) => Context<Services & Tag.Identifier<Tags[number]>> = internal.pick
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const omit: <Tags extends ReadonlyArray<Tag<any, any>>>(
|
||||
...tags: Tags
|
||||
) => <Services>(self: Context<Services>) => Context<Exclude<Services, Tag.Identifier<Tags[number]>>> = internal.omit
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, Layer } from "effect"
|
||||
*
|
||||
* class MyTag extends Context.Tag("MyTag")<
|
||||
* MyTag,
|
||||
* { readonly myNum: number }
|
||||
* >() {
|
||||
* static Live = Layer.succeed(this, { myNum: 108 })
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Tag: <const Id extends string>(id: Id) => <Self, Shape>() => TagClass<Self, Id, Shape> = internal.Tag
|
||||
|
||||
/**
|
||||
* Creates a context tag with a default value.
|
||||
*
|
||||
* **Details**
|
||||
*
|
||||
* `Context.Reference` allows you to create a tag that can hold a value. You can
|
||||
* provide a default value for the service, which will automatically be used
|
||||
* when the context is accessed, or override it with a custom implementation
|
||||
* when needed.
|
||||
*
|
||||
* **Example** (Declaring a Tag with a default value)
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Context, Effect } from "effect"
|
||||
*
|
||||
* class SpecialNumber extends Context.Reference<SpecialNumber>()(
|
||||
* "SpecialNumber",
|
||||
* { defaultValue: () => 2048 }
|
||||
* ) {}
|
||||
*
|
||||
* // ┌─── Effect<void, never, never>
|
||||
* // ▼
|
||||
* const program = Effect.gen(function* () {
|
||||
* const specialNumber = yield* SpecialNumber
|
||||
* console.log(`The special number is ${specialNumber}`)
|
||||
* })
|
||||
*
|
||||
* // No need to provide the SpecialNumber implementation
|
||||
* Effect.runPromise(program)
|
||||
* // Output: The special number is 2048
|
||||
* ```
|
||||
*
|
||||
* **Example** (Overriding the default value)
|
||||
*
|
||||
* ```ts
|
||||
* import { Context, Effect } from "effect"
|
||||
*
|
||||
* class SpecialNumber extends Context.Reference<SpecialNumber>()(
|
||||
* "SpecialNumber",
|
||||
* { defaultValue: () => 2048 }
|
||||
* ) {}
|
||||
*
|
||||
* const program = Effect.gen(function* () {
|
||||
* const specialNumber = yield* SpecialNumber
|
||||
* console.log(`The special number is ${specialNumber}`)
|
||||
* })
|
||||
*
|
||||
* Effect.runPromise(program.pipe(Effect.provideService(SpecialNumber, -1)))
|
||||
* // Output: The special number is -1
|
||||
* ```
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @category constructors
|
||||
* @experimental
|
||||
*/
|
||||
export const Reference: <Self>() => <const Id extends string, Service>(
|
||||
id: Id,
|
||||
options: { readonly defaultValue: () => Service }
|
||||
) => ReferenceClass<Self, Id, Service> = internal.Reference
|
||||
718
_node_modules/effect/src/Cron.ts
generated
Normal file
718
_node_modules/effect/src/Cron.ts
generated
Normal file
@@ -0,0 +1,718 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Arr from "./Array.js"
|
||||
import * as Data from "./Data.js"
|
||||
import type * as DateTime from "./DateTime.js"
|
||||
import * as Either from "./Either.js"
|
||||
import * as Equal from "./Equal.js"
|
||||
import * as equivalence from "./Equivalence.js"
|
||||
import { constVoid, dual, identity, pipe } from "./Function.js"
|
||||
import * as Hash from "./Hash.js"
|
||||
import { format, type Inspectable, NodeInspectSymbol } from "./Inspectable.js"
|
||||
import * as dateTime from "./internal/dateTime.js"
|
||||
import * as N from "./Number.js"
|
||||
import * as Option from "./Option.js"
|
||||
import { type Pipeable, pipeArguments } from "./Pipeable.js"
|
||||
import { hasProperty } from "./Predicate.js"
|
||||
import * as String from "./String.js"
|
||||
import type { Mutable } from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const TypeId: unique symbol = Symbol.for("effect/Cron")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Cron extends Pipeable, Equal.Equal, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
readonly tz: Option.Option<DateTime.TimeZone>
|
||||
readonly seconds: ReadonlySet<number>
|
||||
readonly minutes: ReadonlySet<number>
|
||||
readonly hours: ReadonlySet<number>
|
||||
readonly days: ReadonlySet<number>
|
||||
readonly months: ReadonlySet<number>
|
||||
readonly weekdays: ReadonlySet<number>
|
||||
/** @internal */
|
||||
readonly first: {
|
||||
readonly second: number
|
||||
readonly minute: number
|
||||
readonly hour: number
|
||||
readonly day: number
|
||||
readonly month: number
|
||||
readonly weekday: number
|
||||
}
|
||||
/** @internal */
|
||||
readonly next: {
|
||||
readonly second: ReadonlyArray<number | undefined>
|
||||
readonly minute: ReadonlyArray<number | undefined>
|
||||
readonly hour: ReadonlyArray<number | undefined>
|
||||
readonly day: ReadonlyArray<number | undefined>
|
||||
readonly month: ReadonlyArray<number | undefined>
|
||||
readonly weekday: ReadonlyArray<number | undefined>
|
||||
}
|
||||
}
|
||||
|
||||
const CronProto = {
|
||||
[TypeId]: TypeId,
|
||||
[Equal.symbol](this: Cron, that: unknown) {
|
||||
return isCron(that) && equals(this, that)
|
||||
},
|
||||
[Hash.symbol](this: Cron): number {
|
||||
return pipe(
|
||||
Hash.hash(this.tz),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.seconds))),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.minutes))),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.hours))),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.days))),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.months))),
|
||||
Hash.combine(Hash.array(Arr.fromIterable(this.weekdays))),
|
||||
Hash.cached(this)
|
||||
)
|
||||
},
|
||||
toString(this: Cron) {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON(this: Cron) {
|
||||
return {
|
||||
_id: "Cron",
|
||||
tz: this.tz,
|
||||
seconds: Arr.fromIterable(this.seconds),
|
||||
minutes: Arr.fromIterable(this.minutes),
|
||||
hours: Arr.fromIterable(this.hours),
|
||||
days: Arr.fromIterable(this.days),
|
||||
months: Arr.fromIterable(this.months),
|
||||
weekdays: Arr.fromIterable(this.weekdays)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol](this: Cron) {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given value is a `Cron` instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isCron = (u: unknown): u is Cron => hasProperty(u, TypeId)
|
||||
|
||||
/**
|
||||
* Creates a `Cron` instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make = (values: {
|
||||
readonly seconds?: Iterable<number> | undefined
|
||||
readonly minutes: Iterable<number>
|
||||
readonly hours: Iterable<number>
|
||||
readonly days: Iterable<number>
|
||||
readonly months: Iterable<number>
|
||||
readonly weekdays: Iterable<number>
|
||||
readonly tz?: DateTime.TimeZone | undefined
|
||||
}): Cron => {
|
||||
const o: Mutable<Cron> = Object.create(CronProto)
|
||||
o.seconds = new Set(Arr.sort(values.seconds ?? [0], N.Order))
|
||||
o.minutes = new Set(Arr.sort(values.minutes, N.Order))
|
||||
o.hours = new Set(Arr.sort(values.hours, N.Order))
|
||||
o.days = new Set(Arr.sort(values.days, N.Order))
|
||||
o.months = new Set(Arr.sort(values.months, N.Order))
|
||||
o.weekdays = new Set(Arr.sort(values.weekdays, N.Order))
|
||||
o.tz = Option.fromNullable(values.tz)
|
||||
|
||||
const seconds = Array.from(o.seconds)
|
||||
const minutes = Array.from(o.minutes)
|
||||
const hours = Array.from(o.hours)
|
||||
const days = Array.from(o.days)
|
||||
const months = Array.from(o.months)
|
||||
const weekdays = Array.from(o.weekdays)
|
||||
|
||||
o.first = {
|
||||
second: seconds[0] ?? 0,
|
||||
minute: minutes[0] ?? 0,
|
||||
hour: hours[0] ?? 0,
|
||||
day: days[0] ?? 1,
|
||||
month: (months[0] ?? 1) - 1,
|
||||
weekday: weekdays[0] ?? 0
|
||||
}
|
||||
|
||||
o.next = {
|
||||
second: nextLookupTable(seconds, 60),
|
||||
minute: nextLookupTable(minutes, 60),
|
||||
hour: nextLookupTable(hours, 24),
|
||||
day: nextLookupTable(days, 32),
|
||||
month: nextLookupTable(months, 13),
|
||||
weekday: nextLookupTable(weekdays, 7)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
const nextLookupTable = (values: ReadonlyArray<number>, size: number): Array<number | undefined> => {
|
||||
const result = new Array(size).fill(undefined)
|
||||
if (values.length === 0) {
|
||||
return result
|
||||
}
|
||||
|
||||
let current: number | undefined = undefined
|
||||
let index = values.length - 1
|
||||
for (let i = size - 1; i >= 0; i--) {
|
||||
while (index >= 0 && values[index] >= i) {
|
||||
current = values[index--]
|
||||
}
|
||||
result[i] = current
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const ParseErrorTypeId: unique symbol = Symbol.for("effect/Cron/errors/ParseError")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type ParseErrorTypeId = typeof ParseErrorTypeId
|
||||
|
||||
/**
|
||||
* Represents a checked exception which occurs when decoding fails.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export class ParseError extends Data.TaggedError("CronParseError")<{
|
||||
readonly message: string
|
||||
readonly input?: string
|
||||
}> {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
readonly [ParseErrorTypeId] = ParseErrorTypeId
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is an `ParseError`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isParseError = (u: unknown): u is ParseError => hasProperty(u, ParseErrorTypeId)
|
||||
|
||||
/**
|
||||
* Parses a cron expression into a `Cron` instance.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Cron, Either } from "effect"
|
||||
*
|
||||
* // At 04:00 on every day-of-month from 8 through 14.
|
||||
* assert.deepStrictEqual(Cron.parse("0 0 4 8-14 * *"), Either.right(Cron.make({
|
||||
* seconds: [0],
|
||||
* minutes: [0],
|
||||
* hours: [4],
|
||||
* days: [8, 9, 10, 11, 12, 13, 14],
|
||||
* months: [],
|
||||
* weekdays: []
|
||||
* })))
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const parse = (cron: string, tz?: DateTime.TimeZone | string): Either.Either<Cron, ParseError> => {
|
||||
const segments = cron.split(" ").filter(String.isNonEmpty)
|
||||
if (segments.length !== 5 && segments.length !== 6) {
|
||||
return Either.left(
|
||||
new ParseError({
|
||||
message: `Invalid number of segments in cron expression`,
|
||||
input: cron
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (segments.length === 5) {
|
||||
segments.unshift("0")
|
||||
}
|
||||
|
||||
const [seconds, minutes, hours, days, months, weekdays] = segments
|
||||
const zone = tz === undefined || dateTime.isTimeZone(tz) ?
|
||||
Either.right(tz) :
|
||||
Either.fromOption(dateTime.zoneFromString(tz), () =>
|
||||
new ParseError({
|
||||
message: `Invalid time zone in cron expression`,
|
||||
input: tz
|
||||
}))
|
||||
|
||||
return Either.all({
|
||||
tz: zone,
|
||||
seconds: parseSegment(seconds, secondOptions),
|
||||
minutes: parseSegment(minutes, minuteOptions),
|
||||
hours: parseSegment(hours, hourOptions),
|
||||
days: parseSegment(days, dayOptions),
|
||||
months: parseSegment(months, monthOptions),
|
||||
weekdays: parseSegment(weekdays, weekdayOptions)
|
||||
}).pipe(Either.map(make))
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a cron expression into a `Cron` instance.
|
||||
*
|
||||
* **Details**
|
||||
*
|
||||
* This function takes a cron expression as a string and attempts to parse it
|
||||
* into a `Cron` instance. If the expression is valid, the resulting `Cron`
|
||||
* instance will represent the schedule defined by the cron expression.
|
||||
*
|
||||
* If the expression is invalid, the function throws a `ParseError`.
|
||||
*
|
||||
* You can optionally provide a time zone (`tz`) to interpret the cron
|
||||
* expression in a specific time zone. If no time zone is provided, the cron
|
||||
* expression will use the default time zone.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Cron } from "effect"
|
||||
*
|
||||
* // At 04:00 on every day-of-month from 8 through 14.
|
||||
* console.log(Cron.unsafeParse("0 4 8-14 * *"))
|
||||
* // Output:
|
||||
* // {
|
||||
* // _id: 'Cron',
|
||||
* // tz: { _id: 'Option', _tag: 'None' },
|
||||
* // seconds: [ 0 ],
|
||||
* // minutes: [ 0 ],
|
||||
* // hours: [ 4 ],
|
||||
* // days: [
|
||||
* // 8, 9, 10, 11,
|
||||
* // 12, 13, 14
|
||||
* // ],
|
||||
* // months: [],
|
||||
* // weekdays: []
|
||||
* // }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeParse = (cron: string, tz?: DateTime.TimeZone | string): Cron =>
|
||||
Either.getOrThrowWith(parse(cron, tz), identity)
|
||||
|
||||
/**
|
||||
* Checks if a given `Date` falls within an active `Cron` time window.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Cron, Either } from "effect"
|
||||
*
|
||||
* const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *"))
|
||||
* assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 04:00:00")), true)
|
||||
* assert.deepStrictEqual(Cron.match(cron, new Date("2021-01-08 05:00:00")), false)
|
||||
* ```
|
||||
*
|
||||
* @throws `IllegalArgumentException` if the given `DateTime.Input` is invalid.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const match = (cron: Cron, date: DateTime.DateTime.Input): boolean => {
|
||||
const parts = dateTime.unsafeMakeZoned(date, {
|
||||
timeZone: Option.getOrUndefined(cron.tz)
|
||||
}).pipe(dateTime.toParts)
|
||||
|
||||
if (cron.seconds.size !== 0 && !cron.seconds.has(parts.seconds)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (cron.minutes.size !== 0 && !cron.minutes.has(parts.minutes)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (cron.hours.size !== 0 && !cron.hours.has(parts.hours)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (cron.months.size !== 0 && !cron.months.has(parts.month)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (cron.days.size === 0 && cron.weekdays.size === 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (cron.weekdays.size === 0) {
|
||||
return cron.days.has(parts.day)
|
||||
}
|
||||
|
||||
if (cron.days.size === 0) {
|
||||
return cron.weekdays.has(parts.weekDay)
|
||||
}
|
||||
|
||||
return cron.days.has(parts.day) || cron.weekdays.has(parts.weekDay)
|
||||
}
|
||||
|
||||
const daysInMonth = (date: Date): number =>
|
||||
new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)).getUTCDate()
|
||||
|
||||
/**
|
||||
* Returns the next run `Date` for the given `Cron` instance.
|
||||
*
|
||||
* Uses the current time as a starting point if no value is provided for `now`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Cron, Either } from "effect"
|
||||
*
|
||||
* const after = new Date("2021-01-01 00:00:00")
|
||||
* const cron = Either.getOrThrow(Cron.parse("0 4 8-14 * *"))
|
||||
* assert.deepStrictEqual(Cron.next(cron, after), new Date("2021-01-08 04:00:00"))
|
||||
* ```
|
||||
*
|
||||
* @throws `IllegalArgumentException` if the given `DateTime.Input` is invalid.
|
||||
* @throws `Error` if the next run date cannot be found within 10,000 iterations.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const next = (cron: Cron, startFrom?: DateTime.DateTime.Input): Date => {
|
||||
const tz = Option.getOrUndefined(cron.tz)
|
||||
const zoned = dateTime.unsafeMakeZoned(startFrom ?? new Date(), {
|
||||
timeZone: tz
|
||||
})
|
||||
|
||||
const utc = tz !== undefined && dateTime.isTimeZoneNamed(tz) && tz.id === "UTC"
|
||||
const adjustDst = utc ? constVoid : (current: Date) => {
|
||||
const adjusted = dateTime.unsafeMakeZoned(current, {
|
||||
timeZone: zoned.zone,
|
||||
adjustForTimeZone: true
|
||||
}).pipe(dateTime.toDate)
|
||||
|
||||
// TODO: This implementation currently only skips forward when transitioning into daylight savings time.
|
||||
const drift = current.getTime() - adjusted.getTime()
|
||||
if (drift > 0) {
|
||||
current.setTime(current.getTime() + drift)
|
||||
}
|
||||
}
|
||||
|
||||
const result = dateTime.mutate(zoned, (current) => {
|
||||
current.setUTCSeconds(current.getUTCSeconds() + 1, 0)
|
||||
|
||||
for (let i = 0; i < 10_000; i++) {
|
||||
if (cron.seconds.size !== 0) {
|
||||
const currentSecond = current.getUTCSeconds()
|
||||
const nextSecond = cron.next.second[currentSecond]
|
||||
if (nextSecond === undefined) {
|
||||
current.setUTCMinutes(current.getUTCMinutes() + 1, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
if (nextSecond > currentSecond) {
|
||||
current.setUTCSeconds(nextSecond)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (cron.minutes.size !== 0) {
|
||||
const currentMinute = current.getUTCMinutes()
|
||||
const nextMinute = cron.next.minute[currentMinute]
|
||||
if (nextMinute === undefined) {
|
||||
current.setUTCHours(current.getUTCHours() + 1, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
if (nextMinute > currentMinute) {
|
||||
current.setUTCMinutes(nextMinute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (cron.hours.size !== 0) {
|
||||
const currentHour = current.getUTCHours()
|
||||
const nextHour = cron.next.hour[currentHour]
|
||||
if (nextHour === undefined) {
|
||||
current.setUTCDate(current.getUTCDate() + 1)
|
||||
current.setUTCHours(cron.first.hour, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
if (nextHour > currentHour) {
|
||||
current.setUTCHours(nextHour, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (cron.weekdays.size !== 0 || cron.days.size !== 0) {
|
||||
let a: number = Infinity
|
||||
let b: number = Infinity
|
||||
|
||||
if (cron.weekdays.size !== 0) {
|
||||
const currentWeekday = current.getUTCDay()
|
||||
const nextWeekday = cron.next.weekday[currentWeekday]
|
||||
a = nextWeekday === undefined ? 7 - currentWeekday + cron.first.weekday : nextWeekday - currentWeekday
|
||||
}
|
||||
|
||||
if (cron.days.size !== 0 && a !== 0) {
|
||||
const currentDay = current.getUTCDate()
|
||||
const nextDay = cron.next.day[currentDay]
|
||||
b = nextDay === undefined ? daysInMonth(current) - currentDay + cron.first.day : nextDay - currentDay
|
||||
}
|
||||
|
||||
const addDays = Math.min(a, b)
|
||||
if (addDays !== 0) {
|
||||
current.setUTCDate(current.getUTCDate() + addDays)
|
||||
current.setUTCHours(cron.first.hour, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (cron.months.size !== 0) {
|
||||
const currentMonth = current.getUTCMonth() + 1
|
||||
const nextMonth = cron.next.month[currentMonth]
|
||||
if (nextMonth === undefined) {
|
||||
current.setUTCFullYear(current.getUTCFullYear() + 1)
|
||||
current.setUTCMonth(cron.first.month, cron.first.day)
|
||||
current.setUTCHours(cron.first.hour, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
if (nextMonth > currentMonth) {
|
||||
current.setUTCMonth(nextMonth - 1, cron.first.day)
|
||||
current.setUTCHours(cron.first.hour, cron.first.minute, cron.first.second)
|
||||
adjustDst(current)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
throw new Error("Unable to find next cron date")
|
||||
})
|
||||
|
||||
return dateTime.toDateUtc(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an `IterableIterator` which yields the sequence of `Date`s that match the `Cron` instance.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const sequence = function*(cron: Cron, startFrom?: DateTime.DateTime.Input): IterableIterator<Date> {
|
||||
while (true) {
|
||||
yield startFrom = next(cron, startFrom)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const Equivalence: equivalence.Equivalence<Cron> = equivalence.make((self, that) =>
|
||||
restrictionsEquals(self.seconds, that.seconds) &&
|
||||
restrictionsEquals(self.minutes, that.minutes) &&
|
||||
restrictionsEquals(self.hours, that.hours) &&
|
||||
restrictionsEquals(self.days, that.days) &&
|
||||
restrictionsEquals(self.months, that.months) &&
|
||||
restrictionsEquals(self.weekdays, that.weekdays)
|
||||
)
|
||||
|
||||
const restrictionsArrayEquals = equivalence.array(equivalence.number)
|
||||
const restrictionsEquals = (self: ReadonlySet<number>, that: ReadonlySet<number>): boolean =>
|
||||
restrictionsArrayEquals(Arr.fromIterable(self), Arr.fromIterable(that))
|
||||
|
||||
/**
|
||||
* Checks if two `Cron`s are equal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category predicates
|
||||
*/
|
||||
export const equals: {
|
||||
/**
|
||||
* Checks if two `Cron`s are equal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category predicates
|
||||
*/
|
||||
(that: Cron): (self: Cron) => boolean
|
||||
/**
|
||||
* Checks if two `Cron`s are equal.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category predicates
|
||||
*/
|
||||
(self: Cron, that: Cron): boolean
|
||||
} = dual(2, (self: Cron, that: Cron): boolean => Equivalence(self, that))
|
||||
|
||||
interface SegmentOptions {
|
||||
min: number
|
||||
max: number
|
||||
aliases?: Record<string, number> | undefined
|
||||
}
|
||||
|
||||
const secondOptions: SegmentOptions = {
|
||||
min: 0,
|
||||
max: 59
|
||||
}
|
||||
|
||||
const minuteOptions: SegmentOptions = {
|
||||
min: 0,
|
||||
max: 59
|
||||
}
|
||||
|
||||
const hourOptions: SegmentOptions = {
|
||||
min: 0,
|
||||
max: 23
|
||||
}
|
||||
|
||||
const dayOptions: SegmentOptions = {
|
||||
min: 1,
|
||||
max: 31
|
||||
}
|
||||
|
||||
const monthOptions: SegmentOptions = {
|
||||
min: 1,
|
||||
max: 12,
|
||||
aliases: {
|
||||
jan: 1,
|
||||
feb: 2,
|
||||
mar: 3,
|
||||
apr: 4,
|
||||
may: 5,
|
||||
jun: 6,
|
||||
jul: 7,
|
||||
aug: 8,
|
||||
sep: 9,
|
||||
oct: 10,
|
||||
nov: 11,
|
||||
dec: 12
|
||||
}
|
||||
}
|
||||
|
||||
const weekdayOptions: SegmentOptions = {
|
||||
min: 0,
|
||||
max: 6,
|
||||
aliases: {
|
||||
sun: 0,
|
||||
mon: 1,
|
||||
tue: 2,
|
||||
wed: 3,
|
||||
thu: 4,
|
||||
fri: 5,
|
||||
sat: 6
|
||||
}
|
||||
}
|
||||
|
||||
const parseSegment = (
|
||||
input: string,
|
||||
options: SegmentOptions
|
||||
): Either.Either<ReadonlySet<number>, ParseError> => {
|
||||
const capacity = options.max - options.min + 1
|
||||
const values = new Set<number>()
|
||||
const fields = input.split(",")
|
||||
|
||||
for (const field of fields) {
|
||||
const [raw, step] = splitStep(field)
|
||||
if (raw === "*" && step === undefined) {
|
||||
return Either.right(new Set())
|
||||
}
|
||||
|
||||
if (step !== undefined) {
|
||||
if (!Number.isInteger(step)) {
|
||||
return Either.left(new ParseError({ message: `Expected step value to be a positive integer`, input }))
|
||||
}
|
||||
if (step < 1) {
|
||||
return Either.left(new ParseError({ message: `Expected step value to be greater than 0`, input }))
|
||||
}
|
||||
if (step > options.max) {
|
||||
return Either.left(new ParseError({ message: `Expected step value to be less than ${options.max}`, input }))
|
||||
}
|
||||
}
|
||||
|
||||
if (raw === "*") {
|
||||
for (let i = options.min; i <= options.max; i += step ?? 1) {
|
||||
values.add(i)
|
||||
}
|
||||
} else {
|
||||
const [left, right] = splitRange(raw, options.aliases)
|
||||
if (!Number.isInteger(left)) {
|
||||
return Either.left(new ParseError({ message: `Expected a positive integer`, input }))
|
||||
}
|
||||
if (left < options.min || left > options.max) {
|
||||
return Either.left(
|
||||
new ParseError({ message: `Expected a value between ${options.min} and ${options.max}`, input })
|
||||
)
|
||||
}
|
||||
|
||||
if (right === undefined) {
|
||||
values.add(left)
|
||||
} else {
|
||||
if (!Number.isInteger(right)) {
|
||||
return Either.left(new ParseError({ message: `Expected a positive integer`, input }))
|
||||
}
|
||||
if (right < options.min || right > options.max) {
|
||||
return Either.left(
|
||||
new ParseError({ message: `Expected a value between ${options.min} and ${options.max}`, input })
|
||||
)
|
||||
}
|
||||
if (left > right) {
|
||||
return Either.left(new ParseError({ message: `Invalid value range`, input }))
|
||||
}
|
||||
|
||||
for (let i = left; i <= right; i += step ?? 1) {
|
||||
values.add(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (values.size >= capacity) {
|
||||
return Either.right(new Set())
|
||||
}
|
||||
}
|
||||
|
||||
return Either.right(values)
|
||||
}
|
||||
|
||||
const splitStep = (input: string): [string, number | undefined] => {
|
||||
const seperator = input.indexOf("/")
|
||||
if (seperator !== -1) {
|
||||
return [input.slice(0, seperator), Number(input.slice(seperator + 1))]
|
||||
}
|
||||
|
||||
return [input, undefined]
|
||||
}
|
||||
|
||||
const splitRange = (input: string, aliases?: Record<string, number>): [number, number | undefined] => {
|
||||
const seperator = input.indexOf("-")
|
||||
if (seperator !== -1) {
|
||||
return [aliasOrValue(input.slice(0, seperator), aliases), aliasOrValue(input.slice(seperator + 1), aliases)]
|
||||
}
|
||||
|
||||
return [aliasOrValue(input, aliases), undefined]
|
||||
}
|
||||
|
||||
function aliasOrValue(field: string, aliases?: Record<string, number>): number {
|
||||
return aliases?.[field.toLocaleLowerCase()] ?? Number(field)
|
||||
}
|
||||
771
_node_modules/effect/src/Data.ts
generated
Normal file
771
_node_modules/effect/src/Data.ts
generated
Normal file
@@ -0,0 +1,771 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as internal from "./internal/data.js"
|
||||
import { StructuralPrototype } from "./internal/effectable.js"
|
||||
import * as Predicate from "./Predicate.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type { Unify } from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Case {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Constructor<A, Tag extends keyof A = never> {
|
||||
(
|
||||
args: Types.Equals<Omit<A, Tag>, {}> extends true ? void
|
||||
: { readonly [P in keyof A as P extends Tag ? never : P]: A[P] }
|
||||
): A
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* const alice = Data.struct({ name: "Alice", age: 30 })
|
||||
*
|
||||
* const bob = Data.struct({ name: "Bob", age: 40 })
|
||||
*
|
||||
* assert.deepStrictEqual(Equal.equals(alice, alice), true)
|
||||
* assert.deepStrictEqual(Equal.equals(alice, Data.struct({ name: "Alice", age: 30 })), true)
|
||||
*
|
||||
* assert.deepStrictEqual(Equal.equals(alice, { name: "Alice", age: 30 }), false)
|
||||
* assert.deepStrictEqual(Equal.equals(alice, bob), false)
|
||||
* ```
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const struct: <A extends Record<string, any>>(a: A) => { readonly [P in keyof A]: A[P] } = internal.struct
|
||||
|
||||
/**
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const unsafeStruct = <A extends Record<string, any>>(as: A): { readonly [P in keyof A]: A[P] } =>
|
||||
Object.setPrototypeOf(as, StructuralPrototype)
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* const alice = Data.tuple("Alice", 30)
|
||||
*
|
||||
* const bob = Data.tuple("Bob", 40)
|
||||
*
|
||||
* assert.deepStrictEqual(Equal.equals(alice, alice), true)
|
||||
* assert.deepStrictEqual(Equal.equals(alice, Data.tuple("Alice", 30)), true)
|
||||
*
|
||||
* assert.deepStrictEqual(Equal.equals(alice, ["Alice", 30]), false)
|
||||
* assert.deepStrictEqual(Equal.equals(alice, bob), false)
|
||||
* ```
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const tuple = <As extends ReadonlyArray<any>>(...as: As): Readonly<As> => unsafeArray(as)
|
||||
|
||||
/**
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* const alice = Data.struct({ name: "Alice", age: 30 })
|
||||
* const bob = Data.struct({ name: "Bob", age: 40 })
|
||||
*
|
||||
* const persons = Data.array([alice, bob])
|
||||
*
|
||||
* assert.deepStrictEqual(
|
||||
* Equal.equals(
|
||||
* persons,
|
||||
* Data.array([
|
||||
* Data.struct({ name: "Alice", age: 30 }),
|
||||
* Data.struct({ name: "Bob", age: 40 })
|
||||
* ])
|
||||
* ),
|
||||
* true
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const array = <As extends ReadonlyArray<any>>(as: As): Readonly<As> => unsafeArray(as.slice(0) as unknown as As)
|
||||
|
||||
/**
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const unsafeArray = <As extends ReadonlyArray<any>>(as: As): Readonly<As> =>
|
||||
Object.setPrototypeOf(as, internal.ArrayProto)
|
||||
|
||||
const _case = <A>(): Case.Constructor<A> => (args) =>
|
||||
(args === undefined ? Object.create(StructuralPrototype) : struct(args)) as any
|
||||
|
||||
export {
|
||||
/**
|
||||
* Provides a constructor for the specified `Case`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* interface Person {
|
||||
* readonly name: string
|
||||
* }
|
||||
*
|
||||
* // Creating a constructor for the specified Case
|
||||
* const Person = Data.case<Person>()
|
||||
*
|
||||
* // Creating instances of Person
|
||||
* const mike1 = Person({ name: "Mike" })
|
||||
* const mike2 = Person({ name: "Mike" })
|
||||
* const john = Person({ name: "John" })
|
||||
*
|
||||
* // Checking equality
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, mike2), true)
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, john), false)
|
||||
*
|
||||
* ```
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
_case as case
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a tagged constructor for the specified `Case`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* interface Person {
|
||||
* readonly _tag: "Person" // the tag
|
||||
* readonly name: string
|
||||
* }
|
||||
*
|
||||
* const Person = Data.tagged<Person>("Person")
|
||||
*
|
||||
* const mike = Person({ name: "Mike" })
|
||||
*
|
||||
* assert.deepEqual(mike, { _tag: "Person", name: "Mike" })
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const tagged = <A extends { readonly _tag: string }>(
|
||||
tag: A["_tag"]
|
||||
): Case.Constructor<A, "_tag"> =>
|
||||
(args) => {
|
||||
const value = args === undefined ? Object.create(StructuralPrototype) : struct(args)
|
||||
value._tag = tag
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a constructor for a Case Class.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* class Person extends Data.Class<{ readonly name: string }> {}
|
||||
*
|
||||
* // Creating instances of Person
|
||||
* const mike1 = new Person({ name: "Mike" })
|
||||
* const mike2 = new Person({ name: "Mike" })
|
||||
* const john = new Person({ name: "John" })
|
||||
*
|
||||
* // Checking equality
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, mike2), true)
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, john), false)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Class: new<A extends Record<string, any> = {}>(
|
||||
args: Types.Equals<A, {}> extends true ? void
|
||||
: { readonly [P in keyof A]: A[P] }
|
||||
) => Readonly<A> = internal.Structural as any
|
||||
|
||||
/**
|
||||
* Provides a Tagged constructor for a Case Class.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data, Equal } from "effect"
|
||||
*
|
||||
* class Person extends Data.TaggedClass("Person")<{ readonly name: string }> {}
|
||||
*
|
||||
* // Creating instances of Person
|
||||
* const mike1 = new Person({ name: "Mike" })
|
||||
* const mike2 = new Person({ name: "Mike" })
|
||||
* const john = new Person({ name: "John" })
|
||||
*
|
||||
* // Checking equality
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, mike2), true)
|
||||
* assert.deepStrictEqual(Equal.equals(mike1, john), false)
|
||||
*
|
||||
* assert.deepStrictEqual(mike1._tag, "Person")
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const TaggedClass = <Tag extends string>(
|
||||
tag: Tag
|
||||
): new<A extends Record<string, any> = {}>(
|
||||
args: Types.Equals<A, {}> extends true ? void
|
||||
: { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }
|
||||
) => Readonly<A> & { readonly _tag: Tag } => {
|
||||
class Base extends Class<any> {
|
||||
readonly _tag = tag
|
||||
}
|
||||
return Base as any
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Structural: new<A>(
|
||||
args: Types.Equals<A, {}> extends true ? void
|
||||
: { readonly [P in keyof A]: A[P] }
|
||||
) => {} = internal.Structural as any
|
||||
|
||||
/**
|
||||
* Create a tagged enum data type, which is a union of `Data` structs.
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type HttpError = Data.TaggedEnum<{
|
||||
* BadRequest: { readonly status: 400, readonly message: string }
|
||||
* NotFound: { readonly status: 404, readonly message: string }
|
||||
* }>
|
||||
*
|
||||
* // Equivalent to:
|
||||
* type HttpErrorPlain =
|
||||
* | {
|
||||
* readonly _tag: "BadRequest"
|
||||
* readonly status: 400
|
||||
* readonly message: string
|
||||
* }
|
||||
* | {
|
||||
* readonly _tag: "NotFound"
|
||||
* readonly status: 404
|
||||
* readonly message: string
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type TaggedEnum<
|
||||
A extends Record<string, Record<string, any>> & UntaggedChildren<A>
|
||||
> = keyof A extends infer Tag ?
|
||||
Tag extends keyof A ? Types.Simplify<{ readonly _tag: Tag } & { readonly [K in keyof A[Tag]]: A[Tag][K] }>
|
||||
: never
|
||||
: never
|
||||
|
||||
type ChildrenAreTagged<A> = keyof A extends infer K ? K extends keyof A ? "_tag" extends keyof A[K] ? true
|
||||
: false
|
||||
: never
|
||||
: never
|
||||
|
||||
type UntaggedChildren<A> = true extends ChildrenAreTagged<A>
|
||||
? "It looks like you're trying to create a tagged enum, but one or more of its members already has a `_tag` property."
|
||||
: unknown
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace TaggedEnum {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface WithGenerics<Count extends number> {
|
||||
readonly taggedEnum: { readonly _tag: string }
|
||||
readonly numberOfGenerics: Count
|
||||
|
||||
readonly A: unknown
|
||||
readonly B: unknown
|
||||
readonly C: unknown
|
||||
readonly D: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Kind<
|
||||
Z extends WithGenerics<number>,
|
||||
A = unknown,
|
||||
B = unknown,
|
||||
C = unknown,
|
||||
D = unknown
|
||||
> = (Z & {
|
||||
readonly A: A
|
||||
readonly B: B
|
||||
readonly C: C
|
||||
readonly D: D
|
||||
})["taggedEnum"]
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Args<
|
||||
A extends { readonly _tag: string },
|
||||
K extends A["_tag"],
|
||||
E = Extract<A, { readonly _tag: K }>
|
||||
> = { readonly [K in keyof E as K extends "_tag" ? never : K]: E[K] } extends infer T ? {} extends T ? void : T
|
||||
: never
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Value<
|
||||
A extends { readonly _tag: string },
|
||||
K extends A["_tag"]
|
||||
> = Extract<A, { readonly _tag: K }>
|
||||
|
||||
/**
|
||||
* @since 3.1.0
|
||||
*/
|
||||
export type Constructor<A extends { readonly _tag: string }> = Types.Simplify<
|
||||
& {
|
||||
readonly [Tag in A["_tag"]]: Case.Constructor<Extract<A, { readonly _tag: Tag }>, "_tag">
|
||||
}
|
||||
& {
|
||||
readonly $is: <Tag extends A["_tag"]>(tag: Tag) => (u: unknown) => u is Extract<A, { readonly _tag: Tag }>
|
||||
readonly $match: {
|
||||
<
|
||||
const Cases extends {
|
||||
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
||||
}
|
||||
>(
|
||||
cases: Cases & { [K in Exclude<keyof Cases, A["_tag"]>]: never }
|
||||
): (value: A) => Unify<ReturnType<Cases[A["_tag"]]>>
|
||||
<
|
||||
const Cases extends {
|
||||
readonly [Tag in A["_tag"]]: (args: Extract<A, { readonly _tag: Tag }>) => any
|
||||
}
|
||||
>(
|
||||
value: A,
|
||||
cases: Cases & { [K in Exclude<keyof Cases, A["_tag"]>]: never }
|
||||
): Unify<ReturnType<Cases[A["_tag"]]>>
|
||||
}
|
||||
}
|
||||
>
|
||||
|
||||
/**
|
||||
* @since 3.2.0
|
||||
*/
|
||||
export interface GenericMatchers<Z extends WithGenerics<number>> {
|
||||
readonly $is: <Tag extends Z["taggedEnum"]["_tag"]>(
|
||||
tag: Tag
|
||||
) => {
|
||||
<T extends TaggedEnum.Kind<Z, any, any, any, any>>(
|
||||
u: T
|
||||
): u is T & { readonly _tag: Tag }
|
||||
(u: unknown): u is Extract<TaggedEnum.Kind<Z>, { readonly _tag: Tag }>
|
||||
}
|
||||
readonly $match: {
|
||||
<
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
Cases extends {
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: (
|
||||
args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
||||
) => any
|
||||
}
|
||||
>(
|
||||
cases: Cases & { [K in Exclude<keyof Cases, Z["taggedEnum"]["_tag"]>]: never }
|
||||
): (self: TaggedEnum.Kind<Z, A, B, C, D>) => Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
||||
<
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
D,
|
||||
Cases extends {
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: (
|
||||
args: Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
||||
) => any
|
||||
}
|
||||
>(
|
||||
self: TaggedEnum.Kind<Z, A, B, C, D>,
|
||||
cases: Cases & { [K in Exclude<keyof Cases, Z["taggedEnum"]["_tag"]>]: never }
|
||||
): Unify<ReturnType<Cases[Z["taggedEnum"]["_tag"]]>>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const taggedEnum: {
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Z extends TaggedEnum.WithGenerics<1>>(): Types.Simplify<
|
||||
{
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A>(
|
||||
args: TaggedEnum.Args<
|
||||
TaggedEnum.Kind<Z, A>,
|
||||
Tag,
|
||||
Extract<TaggedEnum.Kind<Z, A>, { readonly _tag: Tag }>
|
||||
>
|
||||
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A>, Tag>
|
||||
} & TaggedEnum.GenericMatchers<Z>
|
||||
>
|
||||
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Z extends TaggedEnum.WithGenerics<2>>(): Types.Simplify<
|
||||
{
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B>(
|
||||
args: TaggedEnum.Args<
|
||||
TaggedEnum.Kind<Z, A, B>,
|
||||
Tag,
|
||||
Extract<TaggedEnum.Kind<Z, A, B>, { readonly _tag: Tag }>
|
||||
>
|
||||
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B>, Tag>
|
||||
} & TaggedEnum.GenericMatchers<Z>
|
||||
>
|
||||
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Z extends TaggedEnum.WithGenerics<3>>(): Types.Simplify<
|
||||
{
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C>(
|
||||
args: TaggedEnum.Args<
|
||||
TaggedEnum.Kind<Z, A, B, C>,
|
||||
Tag,
|
||||
Extract<TaggedEnum.Kind<Z, A, B, C>, { readonly _tag: Tag }>
|
||||
>
|
||||
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C>, Tag>
|
||||
} & TaggedEnum.GenericMatchers<Z>
|
||||
>
|
||||
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Z extends TaggedEnum.WithGenerics<4>>(): Types.Simplify<
|
||||
{
|
||||
readonly [Tag in Z["taggedEnum"]["_tag"]]: <A, B, C, D>(
|
||||
args: TaggedEnum.Args<
|
||||
TaggedEnum.Kind<Z, A, B, C, D>,
|
||||
Tag,
|
||||
Extract<TaggedEnum.Kind<Z, A, B, C, D>, { readonly _tag: Tag }>
|
||||
>
|
||||
) => TaggedEnum.Value<TaggedEnum.Kind<Z, A, B, C, D>, Tag>
|
||||
} & TaggedEnum.GenericMatchers<Z>
|
||||
>
|
||||
|
||||
/**
|
||||
* Create a constructor for a tagged union of `Data` structs.
|
||||
*
|
||||
* You can also pass a `TaggedEnum.WithGenerics` if you want to add generics to
|
||||
* the constructor.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* const { BadRequest, NotFound } = Data.taggedEnum<
|
||||
* | { readonly _tag: "BadRequest"; readonly status: 400; readonly message: string }
|
||||
* | { readonly _tag: "NotFound"; readonly status: 404; readonly message: string }
|
||||
* >()
|
||||
*
|
||||
* const notFound = NotFound({ status: 404, message: "Not Found" })
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* import { Data } from "effect"
|
||||
*
|
||||
* type MyResult<E, A> = Data.TaggedEnum<{
|
||||
* Failure: { readonly error: E }
|
||||
* Success: { readonly value: A }
|
||||
* }>
|
||||
* interface MyResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
|
||||
* readonly taggedEnum: MyResult<this["A"], this["B"]>
|
||||
* }
|
||||
* const { Failure, Success } = Data.taggedEnum<MyResultDefinition>()
|
||||
*
|
||||
* const success = Success({ value: 1 })
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A extends { readonly _tag: string }>(): TaggedEnum.Constructor<A>
|
||||
} = () =>
|
||||
new Proxy({}, {
|
||||
get(_target, tag, _receiver) {
|
||||
if (tag === "$is") {
|
||||
return Predicate.isTagged
|
||||
} else if (tag === "$match") {
|
||||
return taggedMatch
|
||||
}
|
||||
return tagged(tag as string)
|
||||
}
|
||||
}) as any
|
||||
|
||||
function taggedMatch<
|
||||
A extends { readonly _tag: string },
|
||||
Cases extends {
|
||||
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
||||
}
|
||||
>(self: A, cases: Cases): ReturnType<Cases[A["_tag"]]>
|
||||
function taggedMatch<
|
||||
A extends { readonly _tag: string },
|
||||
Cases extends {
|
||||
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
||||
}
|
||||
>(cases: Cases): (value: A) => ReturnType<Cases[A["_tag"]]>
|
||||
function taggedMatch<
|
||||
A extends { readonly _tag: string },
|
||||
Cases extends {
|
||||
readonly [K in A["_tag"]]: (args: Extract<A, { readonly _tag: K }>) => any
|
||||
}
|
||||
>(): any {
|
||||
if (arguments.length === 1) {
|
||||
const cases = arguments[0] as Cases
|
||||
return function(value: A): ReturnType<Cases[A["_tag"]]> {
|
||||
return cases[value._tag as A["_tag"]](value as any)
|
||||
}
|
||||
}
|
||||
const value = arguments[0] as A
|
||||
const cases = arguments[1] as Cases
|
||||
return cases[value._tag as A["_tag"]](value as any)
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a constructor for a Case Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Error: new<A extends Record<string, any> = {}>(
|
||||
args: Types.Equals<A, {}> extends true ? void
|
||||
: { readonly [P in keyof A]: A[P] }
|
||||
) => Cause.YieldableError & Readonly<A> = (function() {
|
||||
const plainArgsSymbol = Symbol.for("effect/Data/Error/plainArgs")
|
||||
const O = {
|
||||
BaseEffectError: class extends core.YieldableError {
|
||||
constructor(args: any) {
|
||||
super(args?.message, args?.cause ? { cause: args.cause } : undefined)
|
||||
if (args) {
|
||||
Object.assign(this, args)
|
||||
// @effect-diagnostics-next-line floatingEffect:off
|
||||
Object.defineProperty(this, plainArgsSymbol, { value: args, enumerable: false })
|
||||
}
|
||||
}
|
||||
toJSON() {
|
||||
return { ...(this as any)[plainArgsSymbol], ...this }
|
||||
}
|
||||
} as any
|
||||
}
|
||||
return O.BaseEffectError
|
||||
})()
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const TaggedError = <Tag extends string>(tag: Tag): new<A extends Record<string, any> = {}>(
|
||||
args: Types.Equals<A, {}> extends true ? void
|
||||
: { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }
|
||||
) => Cause.YieldableError & { readonly _tag: Tag } & Readonly<A> => {
|
||||
const O = {
|
||||
BaseEffectError: class extends Error<{}> {
|
||||
readonly _tag = tag
|
||||
}
|
||||
}
|
||||
;(O.BaseEffectError.prototype as any).name = tag
|
||||
return O.BaseEffectError as any
|
||||
}
|
||||
2715
_node_modules/effect/src/DateTime.ts
generated
Normal file
2715
_node_modules/effect/src/DateTime.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
_node_modules/effect/src/DefaultServices.ts
generated
Normal file
34
_node_modules/effect/src/DefaultServices.ts
generated
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Clock from "./Clock.js"
|
||||
import type * as ConfigProvider from "./ConfigProvider.js"
|
||||
import type * as Console from "./Console.js"
|
||||
import type * as Context from "./Context.js"
|
||||
import type * as FiberRef from "./FiberRef.js"
|
||||
import * as internal from "./internal/defaultServices.js"
|
||||
import type * as Random from "./Random.js"
|
||||
import type * as Tracer from "./Tracer.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type DefaultServices =
|
||||
| Clock.Clock
|
||||
| Console.Console
|
||||
| Random.Random
|
||||
| ConfigProvider.ConfigProvider
|
||||
| Tracer.Tracer
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const liveServices: Context.Context<DefaultServices> = internal.liveServices
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentServices: FiberRef.FiberRef<Context.Context<DefaultServices>> = internal.currentServices
|
||||
471
_node_modules/effect/src/Deferred.ts
generated
Normal file
471
_node_modules/effect/src/Deferred.ts
generated
Normal file
@@ -0,0 +1,471 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as internal from "./internal/deferred.js"
|
||||
import type * as MutableRef from "./MutableRef.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const DeferredTypeId: unique symbol = internal.DeferredTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type DeferredTypeId = typeof DeferredTypeId
|
||||
|
||||
/**
|
||||
* A `Deferred` represents an asynchronous variable that can be set exactly
|
||||
* once, with the ability for an arbitrary number of fibers to suspend (by
|
||||
* calling `Deferred.await`) and automatically resume when the variable is set.
|
||||
*
|
||||
* `Deferred` can be used for building primitive actions whose completions
|
||||
* require the coordinated action of multiple fibers, and for building
|
||||
* higher-level concurrent or asynchronous structures.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Deferred<in out A, in out E = never> extends Effect.Effect<A, E>, Deferred.Variance<A, E> {
|
||||
/** @internal */
|
||||
readonly state: MutableRef.MutableRef<internal.State<A, E>>
|
||||
/** @internal */
|
||||
readonly blockingOn: FiberId.FiberId
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: DeferredUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: DeferredUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface DeferredUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
Deferred?: () => Extract<A[Unify.typeSymbol], Deferred<any, any>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface DeferredUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Deferred {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in out A, in out E> {
|
||||
readonly [DeferredTypeId]: {
|
||||
readonly _A: Types.Invariant<A>
|
||||
readonly _E: Types.Invariant<E>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <A, E = never>() => Effect.Effect<Deferred<A, E>> = core.deferredMake
|
||||
|
||||
/**
|
||||
* Creates a new `Deferred` from the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeAs: <A, E = never>(fiberId: FiberId.FiberId) => Effect.Effect<Deferred<A, E>> = core.deferredMakeAs
|
||||
|
||||
const _await: <A, E>(self: Deferred<A, E>) => Effect.Effect<A, E> = core.deferredAwait
|
||||
|
||||
export {
|
||||
/**
|
||||
* Retrieves the value of the `Deferred`, suspending the fiber running the
|
||||
* workflow until the result is available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
_await as await
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* Note that `Deferred.completeWith` will be much faster, so consider using
|
||||
* that if you do not need to memoize the result of the specified effect.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const complete: {
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* Note that `Deferred.completeWith` will be much faster, so consider using
|
||||
* that if you do not need to memoize the result of the specified effect.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(effect: Effect.Effect<A, E>): (self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* Note that `Deferred.completeWith` will be much faster, so consider using
|
||||
* that if you do not need to memoize the result of the specified effect.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean>
|
||||
} = core.deferredComplete
|
||||
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const completeWith: {
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(effect: Effect.Effect<A, E>): (self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Completes the deferred with the result of the specified effect. If the
|
||||
* deferred has already been completed, the method will produce false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean>
|
||||
} = core.deferredCompleteWith
|
||||
|
||||
/**
|
||||
* Exits the `Deferred` with the specified `Exit` value, which will be
|
||||
* propagated to all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const done: {
|
||||
/**
|
||||
* Exits the `Deferred` with the specified `Exit` value, which will be
|
||||
* propagated to all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(exit: Exit.Exit<A, E>): (self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Exits the `Deferred` with the specified `Exit` value, which will be
|
||||
* propagated to all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, exit: Exit.Exit<A, E>): Effect.Effect<boolean>
|
||||
} = core.deferredDone
|
||||
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const fail: {
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<E>(error: E): <A>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, error: E): Effect.Effect<boolean>
|
||||
} = core.deferredFail
|
||||
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const failSync: {
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<E>(evaluate: LazyArg<E>): <A>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Fails the `Deferred` with the specified error, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<E>): Effect.Effect<boolean>
|
||||
} = core.deferredFailSync
|
||||
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const failCause: {
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<E>(cause: Cause.Cause<E>): <A>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, cause: Cause.Cause<E>): Effect.Effect<boolean>
|
||||
} = core.deferredFailCause
|
||||
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const failCauseSync: {
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<E>(evaluate: LazyArg<Cause.Cause<E>>): <A>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Fails the `Deferred` with the specified `Cause`, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<Cause.Cause<E>>): Effect.Effect<boolean>
|
||||
} = core.deferredFailCauseSync
|
||||
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const die: {
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(defect: unknown): <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, defect: unknown): Effect.Effect<boolean>
|
||||
} = core.deferredDie
|
||||
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const dieSync: {
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(evaluate: LazyArg<unknown>): <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Kills the `Deferred` with the specified defect, which will be propagated to
|
||||
* all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<unknown>): Effect.Effect<boolean>
|
||||
} = core.deferredDieSync
|
||||
|
||||
/**
|
||||
* Completes the `Deferred` with interruption. This will interrupt all fibers
|
||||
* waiting on the value of the `Deferred` with the `FiberId` of the fiber
|
||||
* calling this method.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const interrupt: <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean> = core.deferredInterrupt
|
||||
|
||||
/**
|
||||
* Completes the `Deferred` with interruption. This will interrupt all fibers
|
||||
* waiting on the value of the `Deferred` with the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const interruptWith: {
|
||||
/**
|
||||
* Completes the `Deferred` with interruption. This will interrupt all fibers
|
||||
* waiting on the value of the `Deferred` with the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(fiberId: FiberId.FiberId): <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Completes the `Deferred` with interruption. This will interrupt all fibers
|
||||
* waiting on the value of the `Deferred` with the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, fiberId: FiberId.FiberId): Effect.Effect<boolean>
|
||||
} = core.deferredInterruptWith
|
||||
|
||||
/**
|
||||
* Returns `true` if this `Deferred` has already been completed with a value or
|
||||
* an error, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isDone: <A, E>(self: Deferred<A, E>) => Effect.Effect<boolean> = core.deferredIsDone
|
||||
|
||||
/**
|
||||
* Returns a `Some<Effect<A, E, R>>` from the `Deferred` if this `Deferred` has
|
||||
* already been completed, `None` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const poll: <A, E>(
|
||||
self: Deferred<A, E>
|
||||
) => Effect.Effect<Option.Option<Effect.Effect<A, E>>> = core.deferredPoll
|
||||
|
||||
/**
|
||||
* Completes the `Deferred` with the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const succeed: {
|
||||
/**
|
||||
* Completes the `Deferred` with the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): <E>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Completes the `Deferred` with the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, value: A): Effect.Effect<boolean>
|
||||
} = core.deferredSucceed
|
||||
|
||||
/**
|
||||
* Completes the `Deferred` with the specified lazily evaluated value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const sync: {
|
||||
/**
|
||||
* Completes the `Deferred` with the specified lazily evaluated value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(evaluate: LazyArg<A>): <E>(self: Deferred<A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Completes the `Deferred` with the specified lazily evaluated value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E>(self: Deferred<A, E>, evaluate: LazyArg<A>): Effect.Effect<boolean>
|
||||
} = core.deferredSync
|
||||
|
||||
/**
|
||||
* Unsafely creates a new `Deferred` from the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeMake: <A, E = never>(fiberId: FiberId.FiberId) => Deferred<A, E> = core.deferredUnsafeMake
|
||||
|
||||
/**
|
||||
* Unsafely exits the `Deferred` with the specified `Exit` value, which will be
|
||||
* propagated to all fibers waiting on the value of the `Deferred`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeDone: <A, E>(self: Deferred<A, E>, effect: Effect.Effect<A, E>) => void = core.deferredUnsafeDone
|
||||
512
_node_modules/effect/src/Differ.ts
generated
Normal file
512
_node_modules/effect/src/Differ.ts
generated
Normal file
@@ -0,0 +1,512 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { Chunk } from "./Chunk.js"
|
||||
import type { Context } from "./Context.js"
|
||||
import type { Either } from "./Either.js"
|
||||
import type { Equal } from "./Equal.js"
|
||||
import * as Dual from "./Function.js"
|
||||
import type { HashMap } from "./HashMap.js"
|
||||
import type { HashSet } from "./HashSet.js"
|
||||
import * as internal from "./internal/differ.js"
|
||||
import * as ChunkPatch from "./internal/differ/chunkPatch.js"
|
||||
import * as ContextPatch from "./internal/differ/contextPatch.js"
|
||||
import * as HashMapPatch from "./internal/differ/hashMapPatch.js"
|
||||
import * as HashSetPatch from "./internal/differ/hashSetPatch.js"
|
||||
import * as OrPatch from "./internal/differ/orPatch.js"
|
||||
import * as ReadonlyArrayPatch from "./internal/differ/readonlyArrayPatch.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const TypeId: unique symbol = internal.DifferTypeId as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* A `Differ<Value, Patch>` knows how to compare an old value and new value of
|
||||
* type `Value` to produce a patch of type `Patch` that describes the
|
||||
* differences between those values. A `Differ` also knows how to apply a patch
|
||||
* to an old value to produce a new value that represents the old value updated
|
||||
* with the changes described by the patch.
|
||||
*
|
||||
* A `Differ` can be used to construct a `FiberRef` supporting compositional
|
||||
* updates using the `FiberRef.makePatch` constructor.
|
||||
*
|
||||
* The `Differ` companion object contains constructors for `Differ` values for
|
||||
* common data types such as `Chunk`, `HashMap`, and `HashSet``. In addition,
|
||||
* `Differ`values can be transformed using the `transform` operator and combined
|
||||
* using the `orElseEither` and `zip` operators. This allows creating `Differ`
|
||||
* values for arbitrarily complex data types compositionally.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Differ<in out Value, in out Patch> extends Pipeable {
|
||||
readonly [TypeId]: {
|
||||
readonly _V: Types.Invariant<Value>
|
||||
readonly _P: Types.Invariant<Patch>
|
||||
}
|
||||
readonly empty: Patch
|
||||
diff(oldValue: Value, newValue: Value): Patch
|
||||
combine(first: Patch, second: Patch): Patch
|
||||
patch(patch: Patch, oldValue: Value): Value
|
||||
}
|
||||
|
||||
const ChunkPatchTypeId: unique symbol = ChunkPatch.ChunkPatchTypeId as Differ.Chunk.TypeId
|
||||
const ContextPatchTypeId: unique symbol = ContextPatch.ContextPatchTypeId as Differ.Context.TypeId
|
||||
const HashMapPatchTypeId: unique symbol = HashMapPatch.HashMapPatchTypeId as Differ.HashMap.TypeId
|
||||
const HashSetPatchTypeId: unique symbol = HashSetPatch.HashSetPatchTypeId as Differ.HashSet.TypeId
|
||||
const OrPatchTypeId: unique symbol = OrPatch.OrPatchTypeId as Differ.Or.TypeId
|
||||
const ReadonlyArrayPatchTypeId: unique symbol = ReadonlyArrayPatch
|
||||
.ReadonlyArrayPatchTypeId as Differ.ReadonlyArray.TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Differ {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace Context {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof ContextPatchTypeId
|
||||
/**
|
||||
* A `Patch<Input, Output>` describes an update that transforms a `Env<Input>`
|
||||
* to a `Env<Output>` as a data structure. This allows combining updates to
|
||||
* different services in the environment in a compositional way.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in Input, out Output> extends Equal {
|
||||
readonly [ContextPatchTypeId]: {
|
||||
readonly _Input: Types.Contravariant<Input>
|
||||
readonly _Output: Types.Covariant<Output>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace Chunk {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof ChunkPatchTypeId
|
||||
/**
|
||||
* A patch which describes updates to a chunk of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in out Value, in out Patch> extends Equal {
|
||||
readonly [ChunkPatchTypeId]: {
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
readonly _Patch: Types.Invariant<Patch>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace HashMap {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof HashMapPatchTypeId
|
||||
/**
|
||||
* A patch which describes updates to a map of keys and values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in out Key, in out Value, in out Patch> extends Equal {
|
||||
readonly [HashMapPatchTypeId]: {
|
||||
readonly _Key: Types.Invariant<Key>
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
readonly _Patch: Types.Invariant<Patch>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace HashSet {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof HashSetPatchTypeId
|
||||
/**
|
||||
* A patch which describes updates to a set of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in out Value> extends Equal {
|
||||
readonly [HashSetPatchTypeId]: {
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace Or {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof OrPatchTypeId
|
||||
/**
|
||||
* A patch which describes updates to either one value or another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in out Value, in out Value2, in out Patch, in out Patch2> extends Equal {
|
||||
readonly [OrPatchTypeId]: {
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
readonly _Value2: Types.Invariant<Value2>
|
||||
readonly _Patch: Types.Invariant<Patch>
|
||||
readonly _Patch2: Types.Invariant<Patch2>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export namespace ReadonlyArray {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof ReadonlyArrayPatchTypeId
|
||||
/**
|
||||
* A patch which describes updates to a ReadonlyArray of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Patch<in out Value, in out Patch> extends Equal {
|
||||
readonly [ReadonlyArrayPatchTypeId]: {
|
||||
readonly _Value: Types.Invariant<Value>
|
||||
readonly _Patch: Types.Invariant<Patch>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty patch that describes no changes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
export const empty: <Value, Patch>(self: Differ<Value, Patch>) => Patch = (
|
||||
self
|
||||
) => self.empty
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
export const diff: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Value>(oldValue: Value, newValue: Value): <Patch>(
|
||||
self: Differ<Value, Patch>
|
||||
) => Patch
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Value, Patch>(self: Differ<Value, Patch>, oldValue: Value, newValue: Value): Patch
|
||||
} = Dual.dual(
|
||||
3,
|
||||
<Value, Patch>(
|
||||
self: Differ<Value, Patch>,
|
||||
oldValue: Value,
|
||||
newValue: Value
|
||||
): Patch => self.diff(oldValue, newValue)
|
||||
)
|
||||
|
||||
/**
|
||||
* Combines two patches to produce a new patch that describes the updates of
|
||||
* the first patch and then the updates of the second patch. The combine
|
||||
* operation should be associative. In addition, if the combine operation is
|
||||
* commutative then joining multiple fibers concurrently will result in
|
||||
* deterministic `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* Combines two patches to produce a new patch that describes the updates of
|
||||
* the first patch and then the updates of the second patch. The combine
|
||||
* operation should be associative. In addition, if the combine operation is
|
||||
* commutative then joining multiple fibers concurrently will result in
|
||||
* deterministic `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Patch>(first: Patch, second: Patch): <Value>(
|
||||
self: Differ<Value, Patch>
|
||||
) => Patch
|
||||
/**
|
||||
* Combines two patches to produce a new patch that describes the updates of
|
||||
* the first patch and then the updates of the second patch. The combine
|
||||
* operation should be associative. In addition, if the combine operation is
|
||||
* commutative then joining multiple fibers concurrently will result in
|
||||
* deterministic `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Value, Patch>(self: Differ<Value, Patch>, first: Patch, second: Patch): Patch
|
||||
} = Dual.dual(
|
||||
3,
|
||||
<Value, Patch>(
|
||||
self: Differ<Value, Patch>,
|
||||
first: Patch,
|
||||
second: Patch
|
||||
): Patch => self.combine(first, second)
|
||||
)
|
||||
|
||||
/**
|
||||
* Applies a patch to an old value to produce a new value that is equal to the
|
||||
* old value with the updates described by the patch.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
export const patch: {
|
||||
/**
|
||||
* Applies a patch to an old value to produce a new value that is equal to the
|
||||
* old value with the updates described by the patch.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Patch, Value>(patch: Patch, oldValue: Value): (
|
||||
self: Differ<Value, Patch>
|
||||
) => Value
|
||||
/**
|
||||
* Applies a patch to an old value to produce a new value that is equal to the
|
||||
* old value with the updates described by the patch.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category patch
|
||||
*/
|
||||
<Patch, Value>(self: Differ<Value, Patch>, patch: Patch, oldValue: Value): Value
|
||||
} = Dual.dual(
|
||||
3,
|
||||
<Patch, Value>(
|
||||
self: Differ<Value, Patch>,
|
||||
patch: Patch,
|
||||
oldValue: Value
|
||||
): Value => self.patch(patch, oldValue)
|
||||
)
|
||||
|
||||
/**
|
||||
* Constructs a new `Differ`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Value, Patch>(params: {
|
||||
readonly empty: Patch
|
||||
readonly diff: (oldValue: Value, newValue: Value) => Patch
|
||||
readonly combine: (first: Patch, second: Patch) => Patch
|
||||
readonly patch: (patch: Patch, oldValue: Value) => Value
|
||||
}) => Differ<Value, Patch> = internal.make
|
||||
|
||||
/**
|
||||
* Constructs a differ that knows how to diff `Env` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const environment: <A>() => Differ<
|
||||
Context<A>,
|
||||
Differ.Context.Patch<A, A>
|
||||
> = internal.environment
|
||||
|
||||
/**
|
||||
* Constructs a differ that knows how to diff a `Chunk` of values given a
|
||||
* differ that knows how to diff the values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const chunk: <Value, Patch>(
|
||||
differ: Differ<Value, Patch>
|
||||
) => Differ<Chunk<Value>, Differ.Chunk.Patch<Value, Patch>> = internal.chunk
|
||||
|
||||
/**
|
||||
* Constructs a differ that knows how to diff a `HashMap` of keys and values given
|
||||
* a differ that knows how to diff the values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const hashMap: <Key, Value, Patch>(
|
||||
differ: Differ<Value, Patch>
|
||||
) => Differ<HashMap<Key, Value>, Differ.HashMap.Patch<Key, Value, Patch>> = internal.hashMap
|
||||
|
||||
/**
|
||||
* Constructs a differ that knows how to diff a `HashSet` of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const hashSet: <Value>() => Differ<
|
||||
HashSet<Value>,
|
||||
Differ.HashSet.Patch<Value>
|
||||
> = internal.hashSet
|
||||
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a differ that
|
||||
* knows how to diff the sum of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const orElseEither: {
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a differ that
|
||||
* knows how to diff the sum of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value2, Patch2>(that: Differ<Value2, Patch2>): <Value, Patch>(
|
||||
self: Differ<Value, Patch>
|
||||
) => Differ<
|
||||
Either<Value2, Value>,
|
||||
Differ.Or.Patch<Value, Value2, Patch, Patch2>
|
||||
>
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a differ that
|
||||
* knows how to diff the sum of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value, Patch, Value2, Patch2>(self: Differ<Value, Patch>, that: Differ<Value2, Patch2>): Differ<
|
||||
Either<Value2, Value>,
|
||||
Differ.Or.Patch<Value, Value2, Patch, Patch2>
|
||||
>
|
||||
} = internal.orElseEither
|
||||
|
||||
/**
|
||||
* Constructs a differ that knows how to diff a `ReadonlyArray` of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const readonlyArray: <Value, Patch>(
|
||||
differ: Differ<Value, Patch>
|
||||
) => Differ<ReadonlyArray<Value>, Differ.ReadonlyArray.Patch<Value, Patch>> = internal.readonlyArray
|
||||
|
||||
/**
|
||||
* Transforms the type of values that this differ knows how to differ using
|
||||
* the specified functions that map the new and old value types to each other.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const transform: {
|
||||
/**
|
||||
* Transforms the type of values that this differ knows how to differ using
|
||||
* the specified functions that map the new and old value types to each other.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value, Value2>(
|
||||
options: {
|
||||
readonly toNew: (value: Value) => Value2
|
||||
readonly toOld: (value: Value2) => Value
|
||||
}
|
||||
): <Patch>(self: Differ<Value, Patch>) => Differ<Value2, Patch>
|
||||
/**
|
||||
* Transforms the type of values that this differ knows how to differ using
|
||||
* the specified functions that map the new and old value types to each other.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value, Patch, Value2>(
|
||||
self: Differ<Value, Patch>,
|
||||
options: {
|
||||
readonly toNew: (value: Value) => Value2
|
||||
readonly toOld: (value: Value2) => Value
|
||||
}
|
||||
): Differ<Value2, Patch>
|
||||
} = internal.transform
|
||||
|
||||
/**
|
||||
* Constructs a differ that just diffs two values by returning a function that
|
||||
* sets the value to the new value. This differ does not support combining
|
||||
* multiple updates to the value compositionally and should only be used when
|
||||
* there is no compositional way to update them.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const update: <A>() => Differ<A, (a: A) => A> = internal.update
|
||||
|
||||
/**
|
||||
* A variant of `update` that allows specifying the function that will be used
|
||||
* to combine old values with new values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const updateWith: <A>(f: (x: A, y: A) => A) => Differ<A, (a: A) => A> = internal.updateWith
|
||||
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a new differ that
|
||||
* knows how to diff the product of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a new differ that
|
||||
* knows how to diff the product of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value2, Patch2>(that: Differ<Value2, Patch2>): <Value, Patch>(
|
||||
self: Differ<Value, Patch>
|
||||
) => Differ<
|
||||
readonly [Value, Value2], // readonly because invariant
|
||||
readonly [Patch, Patch2] // readonly because invariant
|
||||
>
|
||||
/**
|
||||
* Combines this differ and the specified differ to produce a new differ that
|
||||
* knows how to diff the product of their values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<Value, Patch, Value2, Patch2>(self: Differ<Value, Patch>, that: Differ<Value2, Patch2>): Differ<
|
||||
readonly [Value, Value2], // readonly because invariant
|
||||
readonly [Patch, Patch2] // readonly because invariant
|
||||
>
|
||||
} = internal.zip
|
||||
1140
_node_modules/effect/src/Duration.ts
generated
Normal file
1140
_node_modules/effect/src/Duration.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
29091
_node_modules/effect/src/Effect.ts
generated
Normal file
29091
_node_modules/effect/src/Effect.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
107
_node_modules/effect/src/Effectable.ts
generated
Normal file
107
_node_modules/effect/src/Effectable.ts
generated
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Channel from "./Channel.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/effectable.js"
|
||||
import type * as Sink from "./Sink.js"
|
||||
import type * as Stream from "./Stream.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export const EffectTypeId: Effect.EffectTypeId = internal.EffectTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export type EffectTypeId = Effect.EffectTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export const StreamTypeId: Stream.StreamTypeId = internal.StreamTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export type StreamTypeId = Stream.StreamTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export const SinkTypeId: Sink.SinkTypeId = internal.SinkTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export type SinkTypeId = Sink.SinkTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export const ChannelTypeId: Channel.ChannelTypeId = internal.ChannelTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category type ids
|
||||
*/
|
||||
export type ChannelTypeId = Channel.ChannelTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface CommitPrimitive {
|
||||
new<A, E = never, R = never>(): Effect.Effect<A, E, R>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category prototypes
|
||||
*/
|
||||
export const EffectPrototype: Effect.Effect<never> = internal.EffectPrototype
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category prototypes
|
||||
*/
|
||||
export const CommitPrototype: Effect.Effect<never> = internal.CommitPrototype
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category prototypes
|
||||
*/
|
||||
export const StructuralCommitPrototype: Effect.Effect<never> = internal.StructuralCommitPrototype
|
||||
|
||||
const Base: CommitPrimitive = internal.Base
|
||||
const StructuralBase: CommitPrimitive = internal.StructuralBase
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export abstract class Class<A, E = never, R = never> extends Base<A, E, R> {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
abstract commit(): Effect.Effect<A, E, R>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export abstract class StructuralClass<A, E = never, R = never> extends StructuralBase<A, E, R> {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
abstract commit(): Effect.Effect<A, E, R>
|
||||
}
|
||||
1723
_node_modules/effect/src/Either.ts
generated
Normal file
1723
_node_modules/effect/src/Either.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
195
_node_modules/effect/src/Encoding.ts
generated
Normal file
195
_node_modules/effect/src/Encoding.ts
generated
Normal file
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* This module provides encoding & decoding functionality for:
|
||||
*
|
||||
* - base64 (RFC4648)
|
||||
* - base64 (URL)
|
||||
* - hex
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Either from "./Either.js"
|
||||
import * as Base64 from "./internal/encoding/base64.js"
|
||||
import * as Base64Url from "./internal/encoding/base64Url.js"
|
||||
import * as Common from "./internal/encoding/common.js"
|
||||
import * as Hex from "./internal/encoding/hex.js"
|
||||
|
||||
/**
|
||||
* Encodes the given value into a base64 (RFC4648) `string`.
|
||||
*
|
||||
* @category encoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const encodeBase64: (input: Uint8Array | string) => string = (input) =>
|
||||
typeof input === "string" ? Base64.encode(Common.encoder.encode(input)) : Base64.encode(input)
|
||||
|
||||
/**
|
||||
* Decodes a base64 (RFC4648) encoded `string` into a `Uint8Array`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeBase64 = (str: string): Either.Either<Uint8Array, DecodeException> => Base64.decode(str)
|
||||
|
||||
/**
|
||||
* Decodes a base64 (RFC4648) encoded `string` into a UTF-8 `string`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeBase64String = (str: string) => Either.map(decodeBase64(str), (_) => Common.decoder.decode(_))
|
||||
|
||||
/**
|
||||
* Encodes the given value into a base64 (URL) `string`.
|
||||
*
|
||||
* @category encoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const encodeBase64Url: (input: Uint8Array | string) => string = (input) =>
|
||||
typeof input === "string" ? Base64Url.encode(Common.encoder.encode(input)) : Base64Url.encode(input)
|
||||
|
||||
/**
|
||||
* Decodes a base64 (URL) encoded `string` into a `Uint8Array`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeBase64Url = (str: string): Either.Either<Uint8Array, DecodeException> => Base64Url.decode(str)
|
||||
|
||||
/**
|
||||
* Decodes a base64 (URL) encoded `string` into a UTF-8 `string`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeBase64UrlString = (str: string) => Either.map(decodeBase64Url(str), (_) => Common.decoder.decode(_))
|
||||
|
||||
/**
|
||||
* Encodes the given value into a hex `string`.
|
||||
*
|
||||
* @category encoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const encodeHex: (input: Uint8Array | string) => string = (input) =>
|
||||
typeof input === "string" ? Hex.encode(Common.encoder.encode(input)) : Hex.encode(input)
|
||||
|
||||
/**
|
||||
* Decodes a hex encoded `string` into a `Uint8Array`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeHex = (str: string): Either.Either<Uint8Array, DecodeException> => Hex.decode(str)
|
||||
|
||||
/**
|
||||
* Decodes a hex encoded `string` into a UTF-8 `string`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const decodeHexString = (str: string) => Either.map(decodeHex(str), (_) => Common.decoder.decode(_))
|
||||
|
||||
/**
|
||||
* Encodes a UTF-8 `string` into a URI component `string`.
|
||||
*
|
||||
* @category encoding
|
||||
* @since 3.12.0
|
||||
*/
|
||||
export const encodeUriComponent = (str: string): Either.Either<string, EncodeException> =>
|
||||
Either.try({
|
||||
try: () => encodeURIComponent(str),
|
||||
catch: (e) => EncodeException(str, e instanceof Error ? e.message : "Invalid input")
|
||||
})
|
||||
|
||||
/**
|
||||
* Decodes a URI component `string` into a UTF-8 `string`.
|
||||
*
|
||||
* @category decoding
|
||||
* @since 3.12.0
|
||||
*/
|
||||
export const decodeUriComponent = (str: string): Either.Either<string, DecodeException> =>
|
||||
Either.try({
|
||||
try: () => decodeURIComponent(str),
|
||||
catch: (e) => DecodeException(str, e instanceof Error ? e.message : "Invalid input")
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const DecodeExceptionTypeId: unique symbol = Common.DecodeExceptionTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type DecodeExceptionTypeId = typeof DecodeExceptionTypeId
|
||||
|
||||
/**
|
||||
* Represents a checked exception which occurs when decoding fails.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface DecodeException {
|
||||
readonly _tag: "DecodeException"
|
||||
readonly [DecodeExceptionTypeId]: DecodeExceptionTypeId
|
||||
readonly input: string
|
||||
readonly message?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a checked exception which occurs when decoding fails.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category errors
|
||||
*/
|
||||
export const DecodeException: (input: string, message?: string) => DecodeException = Common.DecodeException
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is an `DecodeException`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isDecodeException: (u: unknown) => u is DecodeException = Common.isDecodeException
|
||||
|
||||
/**
|
||||
* @since 3.12.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const EncodeExceptionTypeId: unique symbol = Common.EncodeExceptionTypeId
|
||||
|
||||
/**
|
||||
* @since 3.12.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type EncodeExceptionTypeId = typeof EncodeExceptionTypeId
|
||||
|
||||
/**
|
||||
* Represents a checked exception which occurs when encoding fails.
|
||||
*
|
||||
* @since 3.12.0
|
||||
* @category models
|
||||
*/
|
||||
export interface EncodeException {
|
||||
readonly _tag: "EncodeException"
|
||||
readonly [EncodeExceptionTypeId]: EncodeExceptionTypeId
|
||||
readonly input: string
|
||||
readonly message?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a checked exception which occurs when encoding fails.
|
||||
*
|
||||
* @since 3.12.0
|
||||
* @category errors
|
||||
*/
|
||||
export const EncodeException: (input: string, message?: string) => EncodeException = Common.EncodeException
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is an `EncodeException`, `false` otherwise.
|
||||
*
|
||||
* @since 3.12.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isEncodeException: (u: unknown) => u is EncodeException = Common.isEncodeException
|
||||
96
_node_modules/effect/src/Equal.ts
generated
Normal file
96
_node_modules/effect/src/Equal.ts
generated
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { Equivalence } from "./Equivalence.js"
|
||||
import * as Hash from "./Hash.js"
|
||||
import { hasProperty } from "./Predicate.js"
|
||||
import { structuralRegionState } from "./Utils.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const symbol: unique symbol = Symbol.for("effect/Equal")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Equal extends Hash.Hash {
|
||||
[symbol](that: Equal): boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category equality
|
||||
*/
|
||||
export function equals<B>(that: B): <A>(self: A) => boolean
|
||||
export function equals<A, B>(self: A, that: B): boolean
|
||||
export function equals(): any {
|
||||
if (arguments.length === 1) {
|
||||
return (self: unknown) => compareBoth(self, arguments[0])
|
||||
}
|
||||
return compareBoth(arguments[0], arguments[1])
|
||||
}
|
||||
|
||||
function compareBoth(self: unknown, that: unknown): boolean {
|
||||
if (self === that) {
|
||||
return true
|
||||
}
|
||||
const selfType = typeof self
|
||||
if (selfType !== typeof that) {
|
||||
return false
|
||||
}
|
||||
if (selfType === "object" || selfType === "function") {
|
||||
if (self !== null && that !== null) {
|
||||
if (isEqual(self) && isEqual(that)) {
|
||||
if (Hash.hash(self) === Hash.hash(that) && self[symbol](that)) {
|
||||
return true
|
||||
} else {
|
||||
return structuralRegionState.enabled && structuralRegionState.tester
|
||||
? structuralRegionState.tester(self, that)
|
||||
: false
|
||||
}
|
||||
} else if (self instanceof Date && that instanceof Date) {
|
||||
return self.toISOString() === that.toISOString()
|
||||
} else if (self instanceof URL && that instanceof URL) {
|
||||
return self.href === that.href
|
||||
}
|
||||
}
|
||||
if (structuralRegionState.enabled) {
|
||||
if (Array.isArray(self) && Array.isArray(that)) {
|
||||
return self.length === that.length && self.every((v, i) => compareBoth(v, that[i]))
|
||||
}
|
||||
if (Object.getPrototypeOf(self) === Object.prototype && Object.getPrototypeOf(self) === Object.prototype) {
|
||||
const keysSelf = Object.keys(self as any)
|
||||
const keysThat = Object.keys(that as any)
|
||||
if (keysSelf.length === keysThat.length) {
|
||||
for (const key of keysSelf) {
|
||||
// @ts-expect-error
|
||||
if (!(key in that && compareBoth(self[key], that[key]))) {
|
||||
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return structuralRegionState.tester ? structuralRegionState.tester(self, that) : false
|
||||
}
|
||||
}
|
||||
|
||||
return structuralRegionState.enabled && structuralRegionState.tester
|
||||
? structuralRegionState.tester(self, that)
|
||||
: false
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isEqual = (u: unknown): u is Equal => hasProperty(u, symbol)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category instances
|
||||
*/
|
||||
export const equivalence: <A>() => Equivalence<A> = () => equals
|
||||
259
_node_modules/effect/src/Equivalence.ts
generated
Normal file
259
_node_modules/effect/src/Equivalence.ts
generated
Normal file
@@ -0,0 +1,259 @@
|
||||
/**
|
||||
* This module provides an implementation of the `Equivalence` type class, which defines a binary relation
|
||||
* that is reflexive, symmetric, and transitive. In other words, it defines a notion of equivalence between values of a certain type.
|
||||
* These properties are also known in mathematics as an "equivalence relation".
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import { dual } from "./Function.js"
|
||||
import type { TypeLambda } from "./HKT.js"
|
||||
|
||||
/**
|
||||
* @category type class
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface Equivalence<in A> {
|
||||
(self: A, that: A): boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @category type lambdas
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface EquivalenceTypeLambda extends TypeLambda {
|
||||
readonly type: Equivalence<this["Target"]>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const make = <A>(isEquivalent: (self: A, that: A) => boolean): Equivalence<A> => (self: A, that: A): boolean =>
|
||||
self === that || isEquivalent(self, that)
|
||||
|
||||
const isStrictEquivalent = (x: unknown, y: unknown) => x === y
|
||||
|
||||
/**
|
||||
* Return an `Equivalence` that uses strict equality (===) to compare values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const strict: <A>() => Equivalence<A> = () => isStrictEquivalent
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const string: Equivalence<string> = strict()
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const number: Equivalence<number> = strict()
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const boolean: Equivalence<boolean> = strict()
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const bigint: Equivalence<bigint> = strict()
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const symbol: Equivalence<symbol> = strict()
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(that: Equivalence<A>): (self: Equivalence<A>) => Equivalence<A>
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A>
|
||||
} = dual(2, <A>(self: Equivalence<A>, that: Equivalence<A>): Equivalence<A> => make((x, y) => self(x, y) && that(x, y)))
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineMany: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(collection: Iterable<Equivalence<A>>): (self: Equivalence<A>) => Equivalence<A>
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A>
|
||||
} = dual(2, <A>(self: Equivalence<A>, collection: Iterable<Equivalence<A>>): Equivalence<A> =>
|
||||
make((x, y) => {
|
||||
if (!self(x, y)) {
|
||||
return false
|
||||
}
|
||||
for (const equivalence of collection) {
|
||||
if (!equivalence(x, y)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}))
|
||||
|
||||
const isAlwaysEquivalent: Equivalence<unknown> = (_x, _y) => true
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineAll = <A>(collection: Iterable<Equivalence<A>>): Equivalence<A> =>
|
||||
combineMany(isAlwaysEquivalent, collection)
|
||||
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const mapInput: {
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<B, A>(f: (b: B) => A): (self: Equivalence<A>) => Equivalence<B>
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B>
|
||||
} = dual(
|
||||
2,
|
||||
<A, B>(self: Equivalence<A>, f: (b: B) => A): Equivalence<B> => make((x, y) => self(f(x), f(y)))
|
||||
)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const Date: Equivalence<Date> = mapInput(number, (date) => date.getTime())
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const product: {
|
||||
<B>(that: Equivalence<B>): <A>(self: Equivalence<A>) => Equivalence<readonly [A, B]> // readonly because invariant
|
||||
<A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> // readonly because invariant
|
||||
} = dual(
|
||||
2,
|
||||
<A, B>(self: Equivalence<A>, that: Equivalence<B>): Equivalence<readonly [A, B]> =>
|
||||
make(([xa, xb], [ya, yb]) => self(xa, ya) && that(xb, yb))
|
||||
)
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const all = <A>(collection: Iterable<Equivalence<A>>): Equivalence<ReadonlyArray<A>> => {
|
||||
return make((x, y) => {
|
||||
const len = Math.min(x.length, y.length)
|
||||
|
||||
let collectionLength = 0
|
||||
for (const equivalence of collection) {
|
||||
if (collectionLength >= len) {
|
||||
break
|
||||
}
|
||||
if (!equivalence(x[collectionLength], y[collectionLength])) {
|
||||
return false
|
||||
}
|
||||
collectionLength++
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const productMany = <A>(
|
||||
self: Equivalence<A>,
|
||||
collection: Iterable<Equivalence<A>>
|
||||
): Equivalence<readonly [A, ...Array<A>]> /* readonly because invariant */ => {
|
||||
const equivalence = all(collection)
|
||||
return make((x, y) => !self(x[0], y[0]) ? false : equivalence(x.slice(1), y.slice(1)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `Promise.all` but operates on `Equivalence`s.
|
||||
*
|
||||
* ```ts skip-type-checking
|
||||
* [Equivalence<A>, Equivalence<B>, ...] -> Equivalence<[A, B, ...]>
|
||||
* ```
|
||||
*
|
||||
* Given a tuple of `Equivalence`s returns a new `Equivalence` that compares values of a tuple
|
||||
* by applying each `Equivalence` to the corresponding element of the tuple.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const tuple = <T extends ReadonlyArray<Equivalence<any>>>(
|
||||
...elements: T
|
||||
): Equivalence<Readonly<{ [I in keyof T]: [T[I]] extends [Equivalence<infer A>] ? A : never }>> => all(elements) as any
|
||||
|
||||
/**
|
||||
* Creates a new `Equivalence` for an array of values based on a given `Equivalence` for the elements of the array.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const array = <A>(item: Equivalence<A>): Equivalence<ReadonlyArray<A>> =>
|
||||
make((self, that) => {
|
||||
if (self.length !== that.length) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (let i = 0; i < self.length; i++) {
|
||||
const isEq = item(self[i], that[i])
|
||||
if (!isEq) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
/**
|
||||
* Given a struct of `Equivalence`s returns a new `Equivalence` that compares values of a struct
|
||||
* by applying each `Equivalence` to the corresponding property of the struct.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const struct = <R extends Record<string, Equivalence<any>>>(
|
||||
fields: R
|
||||
): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> => {
|
||||
const keys = Object.keys(fields)
|
||||
return make((self, that) => {
|
||||
for (const key of keys) {
|
||||
if (!fields[key](self[key], that[key])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
308
_node_modules/effect/src/ExecutionPlan.ts
generated
Normal file
308
_node_modules/effect/src/ExecutionPlan.ts
generated
Normal file
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
import type { NonEmptyReadonlyArray } from "./Array.js"
|
||||
import type * as Context from "./Context.js"
|
||||
import * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/executionPlan.js"
|
||||
import * as Layer from "./Layer.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import { pipeArguments } from "./Pipeable.js"
|
||||
import type * as Schedule from "./Schedule.js"
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @category Symbols
|
||||
* @experimental
|
||||
*/
|
||||
export const TypeId: unique symbol = internal.TypeId
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @category Symbols
|
||||
* @experimental
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @category Guards
|
||||
* @experimental
|
||||
*/
|
||||
export const isExecutionPlan: (u: unknown) => u is ExecutionPlan<any> = internal.isExecutionPlan
|
||||
|
||||
/**
|
||||
* A `ExecutionPlan` can be used with `Effect.withExecutionPlan` or `Stream.withExecutionPlan`, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
|
||||
*
|
||||
* ```ts
|
||||
* import type { LanguageModel } from "@effect/ai"
|
||||
* import type { Layer } from "effect"
|
||||
* import { Effect, ExecutionPlan, Schedule } from "effect"
|
||||
*
|
||||
* declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
|
||||
* declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
|
||||
*
|
||||
* const ThePlan = ExecutionPlan.make(
|
||||
* {
|
||||
* // First try with the bad layer 2 times with a 3 second delay between attempts
|
||||
* provide: layerBad,
|
||||
* attempts: 2,
|
||||
* schedule: Schedule.spaced(3000)
|
||||
* },
|
||||
* // Then try with the bad layer 3 times with a 1 second delay between attempts
|
||||
* {
|
||||
* provide: layerBad,
|
||||
* attempts: 3,
|
||||
* schedule: Schedule.spaced(1000)
|
||||
* },
|
||||
* // Finally try with the good layer.
|
||||
* //
|
||||
* // If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
|
||||
* {
|
||||
* provide: layerGood
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* declare const effect: Effect.Effect<
|
||||
* void,
|
||||
* never,
|
||||
* LanguageModel.LanguageModel
|
||||
* >
|
||||
* const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
|
||||
* ```
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category Models
|
||||
* @experimental
|
||||
*/
|
||||
export interface ExecutionPlan<
|
||||
Types extends {
|
||||
provides: any
|
||||
input: any
|
||||
error: any
|
||||
requirements: any
|
||||
}
|
||||
> extends Pipeable {
|
||||
readonly [TypeId]: TypeId
|
||||
readonly steps: NonEmptyReadonlyArray<{
|
||||
readonly provide:
|
||||
| Context.Context<Types["provides"]>
|
||||
| Layer.Layer<Types["provides"], Types["error"], Types["requirements"]>
|
||||
readonly attempts?: number | undefined
|
||||
readonly while?:
|
||||
| ((input: Types["input"]) => Effect.Effect<boolean, Types["error"], Types["requirements"]>)
|
||||
| undefined
|
||||
readonly schedule?: Schedule.Schedule<any, Types["input"], Types["requirements"]> | undefined
|
||||
}>
|
||||
|
||||
/**
|
||||
* Returns an equivalent `ExecutionPlan` with the requirements satisfied,
|
||||
* using the current context.
|
||||
*/
|
||||
readonly withRequirements: Effect.Effect<
|
||||
ExecutionPlan<{
|
||||
provides: Types["provides"]
|
||||
input: Types["input"]
|
||||
error: Types["error"]
|
||||
requirements: never
|
||||
}>,
|
||||
never,
|
||||
Types["requirements"]
|
||||
>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
export type TypesBase = {
|
||||
provides: any
|
||||
input: any
|
||||
error: any
|
||||
requirements: any
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an `ExecutionPlan`, which can be used with `Effect.withExecutionPlan` or `Stream.withExecutionPlan`, allowing you to provide different resources for each step of execution until the effect succeeds or the plan is exhausted.
|
||||
*
|
||||
* ```ts
|
||||
* import type { LanguageModel } from "@effect/ai"
|
||||
* import type { Layer } from "effect"
|
||||
* import { Effect, ExecutionPlan, Schedule } from "effect"
|
||||
*
|
||||
* declare const layerBad: Layer.Layer<LanguageModel.LanguageModel>
|
||||
* declare const layerGood: Layer.Layer<LanguageModel.LanguageModel>
|
||||
*
|
||||
* const ThePlan = ExecutionPlan.make(
|
||||
* {
|
||||
* // First try with the bad layer 2 times with a 3 second delay between attempts
|
||||
* provide: layerBad,
|
||||
* attempts: 2,
|
||||
* schedule: Schedule.spaced(3000)
|
||||
* },
|
||||
* // Then try with the bad layer 3 times with a 1 second delay between attempts
|
||||
* {
|
||||
* provide: layerBad,
|
||||
* attempts: 3,
|
||||
* schedule: Schedule.spaced(1000)
|
||||
* },
|
||||
* // Finally try with the good layer.
|
||||
* //
|
||||
* // If `attempts` is omitted, the plan will only attempt once, unless a schedule is provided.
|
||||
* {
|
||||
* provide: layerGood
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* declare const effect: Effect.Effect<
|
||||
* void,
|
||||
* never,
|
||||
* LanguageModel.LanguageModel
|
||||
* >
|
||||
* const withPlan: Effect.Effect<void> = Effect.withExecutionPlan(effect, ThePlan)
|
||||
* ```
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category Constructors
|
||||
* @experimental
|
||||
*/
|
||||
export const make = <const Steps extends NonEmptyReadonlyArray<make.Step>>(
|
||||
...steps: Steps & { [K in keyof Steps]: make.Step }
|
||||
): ExecutionPlan<{
|
||||
provides: make.StepProvides<Steps>
|
||||
input: make.StepInput<Steps>
|
||||
error:
|
||||
| (Steps[number]["provide"] extends Context.Context<infer _P> | Layer.Layer<infer _P, infer E, infer _R> ? E
|
||||
: never)
|
||||
| (Steps[number]["while"] extends (input: infer _I) => Effect.Effect<infer _A, infer _E, infer _R> ? _E : never)
|
||||
requirements:
|
||||
| (Steps[number]["provide"] extends Layer.Layer<infer _A, infer _E, infer R> ? R : never)
|
||||
| (Steps[number]["while"] extends (input: infer _I) => Effect.Effect<infer _A, infer _E, infer R> ? R : never)
|
||||
| (Steps[number]["schedule"] extends Schedule.Schedule<infer _O, infer _I, infer R> ? R : never)
|
||||
}> =>
|
||||
makeProto(steps.map((options, i) => {
|
||||
if (options.attempts && options.attempts < 1) {
|
||||
throw new Error(`ExecutionPlan.make: step[${i}].attempts must be greater than 0`)
|
||||
}
|
||||
return {
|
||||
schedule: options.schedule,
|
||||
attempts: options.attempts,
|
||||
while: options.while
|
||||
? (input: any) =>
|
||||
Effect.suspend(() => {
|
||||
const result = options.while!(input)
|
||||
return typeof result === "boolean" ? Effect.succeed(result) : result
|
||||
})
|
||||
: undefined,
|
||||
provide: options.provide
|
||||
}
|
||||
}) as any)
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
export declare namespace make {
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
export type Step = {
|
||||
readonly provide: Context.Context<any> | Context.Context<never> | Layer.Layer.Any
|
||||
readonly attempts?: number | undefined
|
||||
readonly while?: ((input: any) => boolean | Effect.Effect<boolean, any, any>) | undefined
|
||||
readonly schedule?: Schedule.Schedule<any, any, any> | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.1
|
||||
* @experimental
|
||||
*/
|
||||
export type StepProvides<Steps extends ReadonlyArray<any>, Out = unknown> = Steps extends
|
||||
readonly [infer Step, ...infer Rest] ? StepProvides<
|
||||
Rest,
|
||||
& Out
|
||||
& (
|
||||
(Step extends { readonly provide: Context.Context<infer P> | Layer.Layer<infer P, infer _E, infer _R> } ? P
|
||||
: unknown)
|
||||
)
|
||||
> :
|
||||
Out
|
||||
|
||||
/**
|
||||
* @since 3.16.1
|
||||
* @experimental
|
||||
*/
|
||||
export type PlanProvides<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends
|
||||
readonly [infer Plan, ...infer Rest] ?
|
||||
PlanProvides<Rest, Out & (Plan extends ExecutionPlan<infer T> ? T["provides"] : unknown)> :
|
||||
Out
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
export type StepInput<Steps extends ReadonlyArray<any>, Out = unknown> = Steps extends
|
||||
readonly [infer Step, ...infer Rest] ? StepInput<
|
||||
Rest,
|
||||
& Out
|
||||
& (
|
||||
& (Step extends { readonly while: (input: infer I) => infer _ } ? I : unknown)
|
||||
& (Step extends { readonly schedule: Schedule.Schedule<infer _O, infer I, infer _R> } ? I : unknown)
|
||||
)
|
||||
> :
|
||||
Out
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @experimental
|
||||
*/
|
||||
export type PlanInput<Plans extends ReadonlyArray<any>, Out = unknown> = Plans extends
|
||||
readonly [infer Plan, ...infer Rest] ?
|
||||
PlanInput<Rest, Out & (Plan extends ExecutionPlan<infer T> ? T["input"] : unknown)> :
|
||||
Out
|
||||
}
|
||||
|
||||
const Proto: Omit<ExecutionPlan<any>, "steps"> = {
|
||||
[TypeId]: TypeId,
|
||||
get withRequirements() {
|
||||
const self = this as any as ExecutionPlan<any>
|
||||
return Effect.contextWith((context: Context.Context<any>) =>
|
||||
makeProto(self.steps.map((step) => ({
|
||||
...step,
|
||||
provide: Layer.isLayer(step.provide) ? Layer.provide(step.provide, Layer.succeedContext(context)) : step.provide
|
||||
})) as any)
|
||||
)
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const makeProto = <Provides, In, PlanE, PlanR>(
|
||||
steps: ExecutionPlan<{
|
||||
provides: Provides
|
||||
input: In
|
||||
error: PlanE
|
||||
requirements: PlanR
|
||||
}>["steps"]
|
||||
) => {
|
||||
const self = Object.create(Proto)
|
||||
self.steps = steps
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.16.0
|
||||
* @category Combining
|
||||
* @experimental
|
||||
*/
|
||||
export const merge = <const Plans extends NonEmptyReadonlyArray<ExecutionPlan<any>>>(
|
||||
...plans: Plans
|
||||
): ExecutionPlan<{
|
||||
provides: make.PlanProvides<Plans>
|
||||
input: make.PlanInput<Plans>
|
||||
error: Plans[number] extends ExecutionPlan<infer T> ? T["error"] : never
|
||||
requirements: Plans[number] extends ExecutionPlan<infer T> ? T["requirements"] : never
|
||||
}> => makeProto(plans.flatMap((plan) => plan.steps) as any)
|
||||
138
_node_modules/effect/src/ExecutionStrategy.ts
generated
Normal file
138
_node_modules/effect/src/ExecutionStrategy.ts
generated
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import * as internal from "./internal/executionStrategy.js"
|
||||
|
||||
/**
|
||||
* Describes a strategy for evaluating multiple effects, potentially in
|
||||
* parallel.
|
||||
*
|
||||
* There are 3 possible execution strategies: `Sequential`, `Parallel`,
|
||||
* `ParallelN`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type ExecutionStrategy = Sequential | Parallel | ParallelN
|
||||
|
||||
/**
|
||||
* Execute effects sequentially.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Sequential {
|
||||
readonly _tag: "Sequential"
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute effects in parallel.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Parallel {
|
||||
readonly _tag: "Parallel"
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute effects in parallel, up to the specified number of concurrent fibers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ParallelN {
|
||||
readonly _tag: "ParallelN"
|
||||
readonly parallelism: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute effects sequentially.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sequential: ExecutionStrategy = internal.sequential
|
||||
|
||||
/**
|
||||
* Execute effects in parallel.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const parallel: ExecutionStrategy = internal.parallel
|
||||
|
||||
/**
|
||||
* Execute effects in parallel, up to the specified number of concurrent fibers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const parallelN: (parallelism: number) => ExecutionStrategy = internal.parallelN
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ExecutionStrategy` is an instance of
|
||||
* `Sequential`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSequential: (self: ExecutionStrategy) => self is Sequential = internal.isSequential
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ExecutionStrategy` is an instance of
|
||||
* `Sequential`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isParallel: (self: ExecutionStrategy) => self is Parallel = internal.isParallel
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `ExecutionStrategy` is an instance of
|
||||
* `Sequential`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isParallelN: (self: ExecutionStrategy) => self is ParallelN = internal.isParallelN
|
||||
|
||||
/**
|
||||
* Folds over the specified `ExecutionStrategy` using the provided case
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* Folds over the specified `ExecutionStrategy` using the provided case
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
options: {
|
||||
readonly onSequential: LazyArg<A>
|
||||
readonly onParallel: LazyArg<A>
|
||||
readonly onParallelN: (n: number) => A
|
||||
}
|
||||
): (self: ExecutionStrategy) => A
|
||||
/**
|
||||
* Folds over the specified `ExecutionStrategy` using the provided case
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
self: ExecutionStrategy,
|
||||
options: {
|
||||
readonly onSequential: LazyArg<A>
|
||||
readonly onParallel: LazyArg<A>
|
||||
readonly onParallelN: (n: number) => A
|
||||
}
|
||||
): A
|
||||
} = internal.match
|
||||
717
_node_modules/effect/src/Exit.ts
generated
Normal file
717
_node_modules/effect/src/Exit.ts
generated
Normal file
@@ -0,0 +1,717 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Either from "./Either.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type { Predicate, Refinement } from "./Predicate.js"
|
||||
import type { NoInfer } from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* An `Exit<A, E = never>` describes the result of a executing an `Effect` workflow.
|
||||
*
|
||||
* There are two possible values for an `Exit<A, E>`:
|
||||
* - `Exit.Success` contain a success value of type `A`
|
||||
* - `Exit.Failure` contains a failure `Cause` of type `E`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Exit<A, E = never> = Success<A, E> | Failure<A, E>
|
||||
|
||||
/**
|
||||
* Represents a failed `Effect` workflow containing the `Cause` of the failure
|
||||
* of type `E`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Failure<out A, out E> extends Effect.Effect<A, E>, Pipeable, Inspectable {
|
||||
readonly _tag: "Failure"
|
||||
readonly _op: "Failure"
|
||||
readonly cause: Cause.Cause<E>
|
||||
[Unify.typeSymbol]?: unknown
|
||||
[Unify.unifySymbol]?: ExitUnify<this>
|
||||
[Unify.ignoreSymbol]?: ExitUnifyIgnore
|
||||
/** @internal */
|
||||
readonly effect_instruction_i0: Cause.Cause<E>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface ExitUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
Exit?: () => A[Unify.typeSymbol] extends Exit<infer A0, infer E0> | infer _ ? Exit<A0, E0> : never
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface ExitUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a successful `Effect` workflow and containing the returned value
|
||||
* of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Success<out A, out E> extends Effect.Effect<A, E>, Pipeable, Inspectable {
|
||||
readonly _tag: "Success"
|
||||
readonly _op: "Success"
|
||||
readonly value: A
|
||||
[Unify.typeSymbol]?: unknown
|
||||
[Unify.unifySymbol]?: ExitUnify<this>
|
||||
[Unify.ignoreSymbol]?: ExitUnifyIgnore
|
||||
/** @internal */
|
||||
readonly effect_instruction_i0: A
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is an `Exit`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isExit: (u: unknown) => u is Exit<unknown, unknown> = core.exitIsExit
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `Exit` is a `Failure`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFailure: <A, E>(self: Exit<A, E>) => self is Failure<A, E> = core.exitIsFailure
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `Exit` is a `Success`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSuccess: <A, E>(self: Exit<A, E>) => self is Success<A, E> = core.exitIsSuccess
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified exit is a `Failure` **and** the `Cause` of
|
||||
* the failure was due to interruption, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isInterrupted: <A, E>(self: Exit<A, E>) => boolean = core.exitIsInterrupted
|
||||
|
||||
/**
|
||||
* Maps the `Success` value of the specified exit to the provided constant
|
||||
* value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const as: {
|
||||
/**
|
||||
* Maps the `Success` value of the specified exit to the provided constant
|
||||
* value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A2>(value: A2): <A, E>(self: Exit<A, E>) => Exit<A2, E>
|
||||
/**
|
||||
* Maps the `Success` value of the specified exit to the provided constant
|
||||
* value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, A2>(self: Exit<A, E>, value: A2): Exit<A2, E>
|
||||
} = core.exitAs
|
||||
|
||||
/**
|
||||
* Maps the `Success` value of the specified exit to a void.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const asVoid: <A, E>(self: Exit<A, E>) => Exit<void, E> = core.exitAsVoid
|
||||
|
||||
/**
|
||||
* Returns a `Some<Cause<E>>` if the specified exit is a `Failure`, `None`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const causeOption: <A, E>(self: Exit<A, E>) => Option.Option<Cause.Cause<E>> = core.exitCauseOption
|
||||
|
||||
/**
|
||||
* Collects all of the specified exit values into a `Some<Exit<List<A>, E>>`. If
|
||||
* the provided iterable contains no elements, `None` will be returned.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const all: <A, E>(
|
||||
exits: Iterable<Exit<A, E>>,
|
||||
options?: { readonly parallel?: boolean | undefined } | undefined
|
||||
) => Option.Option<Exit<Array<A>, E>> = core.exitCollectAll
|
||||
|
||||
/**
|
||||
* Constructs a new `Exit.Failure` from the specified unrecoverable defect.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const die: (defect: unknown) => Exit<never> = core.exitDie
|
||||
|
||||
/**
|
||||
* Executes the predicate on the value of the specified exit if it is a
|
||||
* `Success`, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const exists: {
|
||||
/**
|
||||
* Executes the predicate on the value of the specified exit if it is a
|
||||
* `Success`, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): <E>(self: Exit<A, E>) => self is Exit<B>
|
||||
/**
|
||||
* Executes the predicate on the value of the specified exit if it is a
|
||||
* `Success`, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<A>(predicate: Predicate<NoInfer<A>>): <E>(self: Exit<A, E>) => boolean
|
||||
/**
|
||||
* Executes the predicate on the value of the specified exit if it is a
|
||||
* `Success`, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<A, E, B extends A>(self: Exit<A, E>, refinement: Refinement<A, B>): self is Exit<B>
|
||||
/**
|
||||
* Executes the predicate on the value of the specified exit if it is a
|
||||
* `Success`, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<A, E>(self: Exit<A, E>, predicate: Predicate<A>): boolean
|
||||
} = core.exitExists
|
||||
|
||||
/**
|
||||
* Constructs a new `Exit.Failure` from the specified recoverable error of type
|
||||
* `E`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fail: <E>(error: E) => Exit<never, E> = core.exitFail
|
||||
|
||||
/**
|
||||
* Constructs a new `Exit.Failure` from the specified `Cause` of type `E`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const failCause: <E>(cause: Cause.Cause<E>) => Exit<never, E> = core.exitFailCause
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
export const flatMap: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<A, A2, E2>(f: (a: A) => Exit<A2, E2>): <E>(self: Exit<A, E>) => Exit<A2, E2 | E>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<A, E, E2, A2>(self: Exit<A, E>, f: (a: A) => Exit<A2, E2>): Exit<A2, E | E2>
|
||||
} = core.exitFlatMap
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
export const flatMapEffect: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<A, E, A2, E2, R>(f: (a: A) => Effect.Effect<Exit<A2, E>, E2, R>): (self: Exit<A, E>) => Effect.Effect<Exit<A2, E>, E2, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<A, E, A2, E2, R>(self: Exit<A, E>, f: (a: A) => Effect.Effect<Exit<A2, E>, E2, R>): Effect.Effect<Exit<A2, E>, E2, R>
|
||||
} = core.exitFlatMapEffect
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
export const flatten: <A, E, E2>(self: Exit<Exit<A, E>, E2>) => Exit<A, E | E2> = core.exitFlatten
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
export const forEachEffect: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<A, B, E2, R>(f: (a: A) => Effect.Effect<B, E2, R>): <E>(self: Exit<A, E>) => Effect.Effect<Exit<B, E2 | E>, never, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<A, E, B, E2, R>(self: Exit<A, E>, f: (a: A) => Effect.Effect<B, E2, R>): Effect.Effect<Exit<B, E | E2>, never, R>
|
||||
} = core.exitForEachEffect
|
||||
|
||||
/**
|
||||
* Converts an `Either<R, L>` into an `Exit<R, L>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category conversions
|
||||
*/
|
||||
export const fromEither: <R, L>(either: Either.Either<R, L>) => Exit<R, L> = core.exitFromEither
|
||||
|
||||
/**
|
||||
* Converts an `Option<A>` into an `Exit<void, A>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category conversions
|
||||
*/
|
||||
export const fromOption: <A>(option: Option.Option<A>) => Exit<A, void> = core.exitFromOption
|
||||
|
||||
/**
|
||||
* Returns the `A` if specified exit is a `Success`, otherwise returns the
|
||||
* alternate `A` value computed from the specified function which receives the
|
||||
* `Cause<E>` of the exit `Failure`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const getOrElse: {
|
||||
/**
|
||||
* Returns the `A` if specified exit is a `Success`, otherwise returns the
|
||||
* alternate `A` value computed from the specified function which receives the
|
||||
* `Cause<E>` of the exit `Failure`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<E, A2>(orElse: (cause: Cause.Cause<E>) => A2): <A>(self: Exit<A, E>) => A2 | A
|
||||
/**
|
||||
* Returns the `A` if specified exit is a `Success`, otherwise returns the
|
||||
* alternate `A` value computed from the specified function which receives the
|
||||
* `Cause<E>` of the exit `Failure`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<A, E, A2>(self: Exit<A, E>, orElse: (cause: Cause.Cause<E>) => A2): A | A2
|
||||
} = core.exitGetOrElse
|
||||
|
||||
/**
|
||||
* Constructs a new `Exit.Failure` from the specified `FiberId` indicating that
|
||||
* the `Fiber` running an `Effect` workflow was terminated due to interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const interrupt: (fiberId: FiberId.FiberId) => Exit<never> = core.exitInterrupt
|
||||
|
||||
/**
|
||||
* Maps over the `Success` value of the specified exit using the provided
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const map: {
|
||||
/**
|
||||
* Maps over the `Success` value of the specified exit using the provided
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, B>(f: (a: A) => B): <E>(self: Exit<A, E>) => Exit<B, E>
|
||||
/**
|
||||
* Maps over the `Success` value of the specified exit using the provided
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, B>(self: Exit<A, E>, f: (a: A) => B): Exit<B, E>
|
||||
} = core.exitMap
|
||||
|
||||
/**
|
||||
* Maps over the `Success` and `Failure` cases of the specified exit using the
|
||||
* provided functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapBoth: {
|
||||
/**
|
||||
* Maps over the `Success` and `Failure` cases of the specified exit using the
|
||||
* provided functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<E, A, E2, A2>(
|
||||
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
||||
): (self: Exit<A, E>) => Exit<A2, E2>
|
||||
/**
|
||||
* Maps over the `Success` and `Failure` cases of the specified exit using the
|
||||
* provided functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, E2, A2>(
|
||||
self: Exit<A, E>,
|
||||
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
||||
): Exit<A2, E2>
|
||||
} = core.exitMapBoth
|
||||
|
||||
/**
|
||||
* Maps over the error contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapError: {
|
||||
/**
|
||||
* Maps over the error contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<E, E2>(f: (e: E) => E2): <A>(self: Exit<A, E>) => Exit<A, E2>
|
||||
/**
|
||||
* Maps over the error contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, E2>(self: Exit<A, E>, f: (e: E) => E2): Exit<A, E2>
|
||||
} = core.exitMapError
|
||||
|
||||
/**
|
||||
* Maps over the `Cause` contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapErrorCause: {
|
||||
/**
|
||||
* Maps over the `Cause` contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<E, E2>(f: (cause: Cause.Cause<E>) => Cause.Cause<E2>): <A>(self: Exit<A, E>) => Exit<A, E2>
|
||||
/**
|
||||
* Maps over the `Cause` contained in the `Failure` of the specified exit using
|
||||
* the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<E, A, E2>(self: Exit<A, E>, f: (cause: Cause.Cause<E>) => Cause.Cause<E2>): Exit<A, E2>
|
||||
} = core.exitMapErrorCause
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<E, A, Z1, Z2>(
|
||||
options: { readonly onFailure: (cause: Cause.Cause<E>) => Z1; readonly onSuccess: (a: A) => Z2 }
|
||||
): (self: Exit<A, E>) => Z1 | Z2
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A, E, Z1, Z2>(
|
||||
self: Exit<A, E>,
|
||||
options: { readonly onFailure: (cause: Cause.Cause<E>) => Z1; readonly onSuccess: (a: A) => Z2 }
|
||||
): Z1 | Z2
|
||||
} = core.exitMatch
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const matchEffect: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<E, A2, E2, R, A, A3, E3, R2>(
|
||||
options: {
|
||||
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>
|
||||
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>
|
||||
}
|
||||
): (self: Exit<A, E>) => Effect.Effect<A2 | A3, E2 | E3, R | R2>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A, E, A2, E2, R, A3, E3, R2>(
|
||||
self: Exit<A, E>,
|
||||
options: {
|
||||
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>
|
||||
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>
|
||||
}
|
||||
): Effect.Effect<A2 | A3, E2 | E3, R | R2>
|
||||
} = core.exitMatchEffect
|
||||
|
||||
/**
|
||||
* Constructs a new `Exit.Success` containing the specified value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const succeed: <A>(value: A) => Exit<A> = core.exitSucceed
|
||||
|
||||
const void_: Exit<void> = core.exitVoid
|
||||
export {
|
||||
/**
|
||||
* Represents an `Exit` which succeeds with `undefined`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
void_ as void
|
||||
}
|
||||
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<[A, A2], E2 | E>
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<[A, A2], E | E2>
|
||||
} = core.exitZip
|
||||
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipLeft: {
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A, E2 | E>
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A, E | E2>
|
||||
} = core.exitZipLeft
|
||||
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipRight: {
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A2, E2 | E>
|
||||
/**
|
||||
* Sequentially zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A2, E | E2>
|
||||
} = core.exitZipRight
|
||||
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipPar: {
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<[A, A2], E2 | E>
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result or else returns
|
||||
* the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<[A, A2], E | E2>
|
||||
} = core.exitZipPar
|
||||
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipParLeft: {
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A, E2 | E>
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* second element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A, E | E2>
|
||||
} = core.exitZipParLeft
|
||||
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipParRight: {
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Exit<A2, E2>): <A, E>(self: Exit<A, E>) => Exit<A2, E2 | E>
|
||||
/**
|
||||
* Parallelly zips the this result with the specified result discarding the
|
||||
* first element of the tuple or else returns the failed `Cause<E | E2>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Exit<A, E>, that: Exit<A2, E2>): Exit<A2, E | E2>
|
||||
} = core.exitZipParRight
|
||||
|
||||
/**
|
||||
* Zips this exit together with that exit using the specified combination
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipWith: {
|
||||
/**
|
||||
* Zips this exit together with that exit using the specified combination
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<B, E2, A, C, E>(
|
||||
that: Exit<B, E2>,
|
||||
options: {
|
||||
readonly onSuccess: (a: A, b: B) => C
|
||||
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<any>
|
||||
}
|
||||
): (self: Exit<A, E>) => Exit<C, any>
|
||||
/**
|
||||
* Zips this exit together with that exit using the specified combination
|
||||
* functions.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, B, E2, C>(
|
||||
self: Exit<A, E>,
|
||||
that: Exit<B, E2>,
|
||||
options: {
|
||||
readonly onSuccess: (a: A, b: B) => C
|
||||
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>
|
||||
}
|
||||
): Exit<C, E | E2>
|
||||
} = core.exitZipWith
|
||||
9
_node_modules/effect/src/FastCheck.ts
generated
Normal file
9
_node_modules/effect/src/FastCheck.ts
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @since 3.10.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category re-exports
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export * from "fast-check"
|
||||
926
_node_modules/effect/src/Fiber.ts
generated
Normal file
926
_node_modules/effect/src/Fiber.ts
generated
Normal file
@@ -0,0 +1,926 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type { Context } from "./Context.js"
|
||||
import type { DefaultServices } from "./DefaultServices.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Either from "./Either.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type { FiberRef } from "./FiberRef.js"
|
||||
import type * as FiberRefs from "./FiberRefs.js"
|
||||
import type * as FiberStatus from "./FiberStatus.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as circular from "./internal/effect/circular.js"
|
||||
import * as internal from "./internal/fiber.js"
|
||||
import * as fiberRuntime from "./internal/fiberRuntime.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type * as order from "./Order.js"
|
||||
import type * as RuntimeFlags from "./RuntimeFlags.js"
|
||||
import type { Scheduler } from "./Scheduler.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
import type { Supervisor } from "./Supervisor.js"
|
||||
import type { AnySpan, Tracer } from "./Tracer.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FiberTypeId: unique symbol = internal.FiberTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FiberTypeId = typeof FiberTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const RuntimeFiberTypeId: unique symbol = internal.RuntimeFiberTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type RuntimeFiberTypeId = typeof RuntimeFiberTypeId
|
||||
|
||||
/**
|
||||
* A fiber is a lightweight thread of execution that never consumes more than a
|
||||
* whole thread (but may consume much less, depending on contention and
|
||||
* asynchronicity). Fibers are spawned by forking effects, which run
|
||||
* concurrently with the parent effect.
|
||||
*
|
||||
* Fibers can be joined, yielding their result to other fibers, or interrupted,
|
||||
* which terminates the fiber, safely releasing all resources.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Fiber<out A, out E = never> extends Effect.Effect<A, E>, Fiber.Variance<A, E> {
|
||||
/**
|
||||
* The identity of the fiber.
|
||||
*/
|
||||
id(): FiberId.FiberId
|
||||
|
||||
/**
|
||||
* Awaits the fiber, which suspends the awaiting fiber until the result of the
|
||||
* fiber has been determined.
|
||||
*/
|
||||
readonly await: Effect.Effect<Exit.Exit<A, E>>
|
||||
|
||||
/**
|
||||
* Retrieves the immediate children of the fiber.
|
||||
*/
|
||||
readonly children: Effect.Effect<Array<Fiber.Runtime<any, any>>>
|
||||
|
||||
/**
|
||||
* Inherits values from all `FiberRef` instances into current fiber. This
|
||||
* will resume immediately.
|
||||
*/
|
||||
readonly inheritAll: Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Tentatively observes the fiber, but returns immediately if it is not
|
||||
* already done.
|
||||
*/
|
||||
readonly poll: Effect.Effect<Option.Option<Exit.Exit<A, E>>>
|
||||
|
||||
/**
|
||||
* In the background, interrupts the fiber as if interrupted from the
|
||||
* specified fiber. If the fiber has already exited, the returned effect will
|
||||
* resume immediately. Otherwise, the effect will resume when the fiber exits.
|
||||
*/
|
||||
interruptAsFork(fiberId: FiberId.FiberId): Effect.Effect<void>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: FiberUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: FiberUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface FiberUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
Fiber?: () => A[Unify.typeSymbol] extends Fiber<infer A0, infer E0> | infer _ ? Fiber<A0, E0> : never
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface FiberUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* A runtime fiber that is executing an effect. Runtime fibers have an
|
||||
* identity and a trace.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface RuntimeFiber<out A, out E = never> extends Fiber<A, E>, Fiber.RuntimeVariance<A, E> {
|
||||
/**
|
||||
* Reads the current number of ops that have occurred since the last yield
|
||||
*/
|
||||
get currentOpCount(): number
|
||||
|
||||
/**
|
||||
* Reads the current value of a fiber ref
|
||||
*/
|
||||
getFiberRef<X>(fiberRef: FiberRef<X>): X
|
||||
|
||||
/**
|
||||
* The identity of the fiber.
|
||||
*/
|
||||
id(): FiberId.Runtime
|
||||
|
||||
/**
|
||||
* The status of the fiber.
|
||||
*/
|
||||
readonly status: Effect.Effect<FiberStatus.FiberStatus>
|
||||
|
||||
/**
|
||||
* Returns the current `RuntimeFlags` the fiber is running with.
|
||||
*/
|
||||
readonly runtimeFlags: Effect.Effect<RuntimeFlags.RuntimeFlags>
|
||||
|
||||
/**
|
||||
* Adds an observer to the list of observers.
|
||||
*/
|
||||
addObserver(observer: (exit: Exit.Exit<A, E>) => void): void
|
||||
|
||||
/**
|
||||
* Removes the specified observer from the list of observers that will be
|
||||
* notified when the fiber exits.
|
||||
*/
|
||||
removeObserver(observer: (exit: Exit.Exit<A, E>) => void): void
|
||||
|
||||
/**
|
||||
* Retrieves all fiber refs of the fiber.
|
||||
*/
|
||||
getFiberRefs(): FiberRefs.FiberRefs
|
||||
|
||||
/**
|
||||
* Unsafely observes the fiber, but returns immediately if it is not
|
||||
* already done.
|
||||
*/
|
||||
unsafePoll(): Exit.Exit<A, E> | null
|
||||
|
||||
/**
|
||||
* In the background, interrupts the fiber as if interrupted from the
|
||||
* specified fiber. If the fiber has already exited, the returned effect will
|
||||
* resume immediately. Otherwise, the effect will resume when the fiber exits.
|
||||
*/
|
||||
unsafeInterruptAsFork(fiberId: FiberId.FiberId): void
|
||||
|
||||
/**
|
||||
* Gets the current context
|
||||
*/
|
||||
get currentContext(): Context<never>
|
||||
|
||||
/**
|
||||
* Gets the current context
|
||||
*/
|
||||
get currentDefaultServices(): Context<DefaultServices>
|
||||
|
||||
/**
|
||||
* Gets the current scheduler
|
||||
*/
|
||||
get currentScheduler(): Scheduler
|
||||
|
||||
/**
|
||||
* Gets the current tracer
|
||||
*/
|
||||
get currentTracer(): Tracer
|
||||
|
||||
/**
|
||||
* Gets the current span
|
||||
*/
|
||||
get currentSpan(): AnySpan | undefined
|
||||
|
||||
/**
|
||||
* Gets the current supervisor
|
||||
*/
|
||||
get currentSupervisor(): Supervisor<unknown>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: RuntimeFiberUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: RuntimeFiberUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface RuntimeFiberUnify<A extends { [Unify.typeSymbol]?: any }> extends FiberUnify<A> {
|
||||
RuntimeFiber?: () => A[Unify.typeSymbol] extends RuntimeFiber<infer A0, infer E0> | infer _ ? RuntimeFiber<A0, E0>
|
||||
: never
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface RuntimeFiberUnifyIgnore extends FiberUnifyIgnore {
|
||||
Fiber?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Fiber {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Runtime<A, E = never> = RuntimeFiber<A, E>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out A, out E> {
|
||||
readonly [FiberTypeId]: {
|
||||
readonly _A: Types.Covariant<A>
|
||||
readonly _E: Types.Covariant<E>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface RuntimeVariance<out A, out E> {
|
||||
readonly [RuntimeFiberTypeId]: {
|
||||
readonly _A: Types.Covariant<A>
|
||||
readonly _E: Types.Covariant<E>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Dump {
|
||||
/**
|
||||
* The fiber's unique identifier.
|
||||
*/
|
||||
readonly id: FiberId.Runtime
|
||||
/**
|
||||
* The status of the fiber.
|
||||
*/
|
||||
readonly status: FiberStatus.FiberStatus
|
||||
}
|
||||
|
||||
/**
|
||||
* A record containing information about a `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Descriptor {
|
||||
/**
|
||||
* The fiber's unique identifier.
|
||||
*/
|
||||
readonly id: FiberId.FiberId
|
||||
/**
|
||||
* The status of the fiber.
|
||||
*/
|
||||
readonly status: FiberStatus.FiberStatus
|
||||
/**
|
||||
* The set of fibers attempting to interrupt the fiber or its ancestors.
|
||||
*/
|
||||
readonly interruptors: HashSet.HashSet<FiberId.FiberId>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category instances
|
||||
*/
|
||||
export const Order: order.Order<RuntimeFiber<unknown, unknown>> = internal.Order
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Fiber`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFiber: (u: unknown) => u is Fiber<unknown, unknown> = internal.isFiber
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `Fiber` is a `RuntimeFiber`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isRuntimeFiber: <A, E>(self: Fiber<A, E>) => self is RuntimeFiber<A, E> = internal.isRuntimeFiber
|
||||
|
||||
/**
|
||||
* The identity of the fiber.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const id: <A, E>(self: Fiber<A, E>) => FiberId.FiberId = internal.id
|
||||
|
||||
const _await: <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>> = internal._await
|
||||
|
||||
export {
|
||||
/**
|
||||
* Awaits the fiber, which suspends the awaiting fiber until the result of the
|
||||
* fiber has been determined.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
_await as await
|
||||
}
|
||||
|
||||
/**
|
||||
* Awaits on all fibers to be completed, successfully or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const awaitAll: <const T extends Iterable<Fiber<any, any>>>(
|
||||
fibers: T
|
||||
) => Effect.Effect<
|
||||
[T] extends [ReadonlyArray<infer U>]
|
||||
? number extends T["length"] ? Array<U extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never>
|
||||
: { -readonly [K in keyof T]: T[K] extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never }
|
||||
: Array<T extends Iterable<infer U> ? U extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never : never>
|
||||
> = fiberRuntime.fiberAwaitAll
|
||||
|
||||
/**
|
||||
* Retrieves the immediate children of the fiber.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const children: <A, E>(self: Fiber<A, E>) => Effect.Effect<Array<RuntimeFiber<any, any>>> = internal.children
|
||||
|
||||
/**
|
||||
* Collects all fibers into a single fiber producing an in-order list of the
|
||||
* results.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const all: <A, E>(fibers: Iterable<Fiber<A, E>>) => Fiber<ReadonlyArray<A>, E> = fiberRuntime.fiberAll
|
||||
|
||||
/**
|
||||
* A fiber that is done with the specified `Exit` value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const done: <A, E>(exit: Exit.Exit<A, E>) => Fiber<A, E> = internal.done
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const dump: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<Fiber.Dump> = internal.dump
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const dumpAll: (
|
||||
fibers: Iterable<RuntimeFiber<unknown, unknown>>
|
||||
) => Effect.Effect<Array<Fiber.Dump>> = internal.dumpAll
|
||||
|
||||
/**
|
||||
* A fiber that has already failed with the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fail: <E>(error: E) => Fiber<never, E> = internal.fail
|
||||
|
||||
/**
|
||||
* Creates a `Fiber` that has already failed with the specified cause.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const failCause: <E>(cause: Cause.Cause<E>) => Fiber<never, E> = internal.failCause
|
||||
|
||||
/**
|
||||
* Lifts an `Effect` into a `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category conversions
|
||||
*/
|
||||
export const fromEffect: <A, E>(effect: Effect.Effect<A, E>) => Effect.Effect<Fiber<A, E>> = internal.fromEffect
|
||||
|
||||
/**
|
||||
* Gets the current fiber if one is running.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utilities
|
||||
*/
|
||||
export const getCurrentFiber: () => Option.Option<RuntimeFiber<any, any>> = internal.getCurrentFiber
|
||||
|
||||
/**
|
||||
* Inherits values from all `FiberRef` instances into current fiber. This
|
||||
* will resume immediately.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const inheritAll: <A, E>(self: Fiber<A, E>) => Effect.Effect<void> = internal.inheritAll
|
||||
|
||||
/**
|
||||
* Interrupts the fiber from whichever fiber is calling this method. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interrupt: <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>> = core.interruptFiber
|
||||
|
||||
/**
|
||||
* Constructrs a `Fiber` that is already interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const interrupted: (fiberId: FiberId.FiberId) => Fiber<never> = internal.interrupted
|
||||
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interruptAs: {
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
(fiberId: FiberId.FiberId): <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
<A, E>(self: Fiber<A, E>, fiberId: FiberId.FiberId): Effect.Effect<Exit.Exit<A, E>>
|
||||
} = core.interruptAsFiber
|
||||
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interruptAsFork: {
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
(fiberId: FiberId.FiberId): <A, E>(self: Fiber<A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Interrupts the fiber as if interrupted from the specified fiber. If the
|
||||
* fiber has already exited, the returned effect will resume immediately.
|
||||
* Otherwise, the effect will resume when the fiber exits.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
<A, E>(self: Fiber<A, E>, fiberId: FiberId.FiberId): Effect.Effect<void>
|
||||
} = internal.interruptAsFork
|
||||
|
||||
/**
|
||||
* Interrupts all fibers, awaiting their interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interruptAll: (fibers: Iterable<Fiber<any, any>>) => Effect.Effect<void> = internal.interruptAll
|
||||
|
||||
/**
|
||||
* Interrupts all fibers as by the specified fiber, awaiting their
|
||||
* interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interruptAllAs: {
|
||||
/**
|
||||
* Interrupts all fibers as by the specified fiber, awaiting their
|
||||
* interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
(fiberId: FiberId.FiberId): (fibers: Iterable<Fiber<any, any>>) => Effect.Effect<void>
|
||||
/**
|
||||
* Interrupts all fibers as by the specified fiber, awaiting their
|
||||
* interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
(fibers: Iterable<Fiber<any, any>>, fiberId: FiberId.FiberId): Effect.Effect<void>
|
||||
} = internal.interruptAllAs
|
||||
|
||||
/**
|
||||
* Interrupts the fiber from whichever fiber is calling this method. The
|
||||
* interruption will happen in a separate daemon fiber, and the returned
|
||||
* effect will always resume immediately without waiting.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category interruption
|
||||
*/
|
||||
export const interruptFork: <A, E>(self: Fiber<A, E>) => Effect.Effect<void> = fiberRuntime.fiberInterruptFork
|
||||
|
||||
/**
|
||||
* Joins the fiber, which suspends the joining fiber until the result of the
|
||||
* fiber has been determined. Attempting to join a fiber that has erred will
|
||||
* result in a catchable error. Joining an interrupted fiber will result in an
|
||||
* "inner interruption" of this fiber, unlike interruption triggered by
|
||||
* another fiber, "inner interruption" can be caught and recovered.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const join: <A, E>(self: Fiber<A, E>) => Effect.Effect<A, E> = internal.join
|
||||
|
||||
/**
|
||||
* Joins all fibers, awaiting their _successful_ completion. Attempting to
|
||||
* join a fiber that has erred will result in a catchable error, _if_ that
|
||||
* error does not result from interruption.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const joinAll: <A, E>(fibers: Iterable<Fiber<A, E>>) => Effect.Effect<Array<A>, E> = fiberRuntime.fiberJoinAll
|
||||
|
||||
/**
|
||||
* Maps over the value the Fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const map: {
|
||||
/**
|
||||
* Maps over the value the Fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, B>(f: (a: A) => B): <E>(self: Fiber<A, E>) => Fiber<B, E>
|
||||
/**
|
||||
* Maps over the value the Fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, B>(self: Fiber<A, E>, f: (a: A) => B): Fiber<B, E>
|
||||
} = internal.map
|
||||
|
||||
/**
|
||||
* Effectually maps over the value the fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapEffect: {
|
||||
/**
|
||||
* Effectually maps over the value the fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, A2, E2>(f: (a: A) => Effect.Effect<A2, E2>): <E>(self: Fiber<A, E>) => Fiber<A2, E2 | E>
|
||||
/**
|
||||
* Effectually maps over the value the fiber computes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, f: (a: A) => Effect.Effect<A2, E2>): Fiber<A2, E | E2>
|
||||
} = internal.mapEffect
|
||||
|
||||
/**
|
||||
* Passes the success of this fiber to the specified callback, and continues
|
||||
* with the fiber that it returns.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapFiber: {
|
||||
/**
|
||||
* Passes the success of this fiber to the specified callback, and continues
|
||||
* with the fiber that it returns.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<E, E2, A, B>(f: (a: A) => Fiber<B, E2>): (self: Fiber<A, E>) => Effect.Effect<Fiber<B, E | E2>>
|
||||
/**
|
||||
* Passes the success of this fiber to the specified callback, and continues
|
||||
* with the fiber that it returns.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, E, E2, B>(self: Fiber<A, E>, f: (a: A) => Fiber<B, E2>): Effect.Effect<Fiber<B, E | E2>>
|
||||
} = internal.mapFiber
|
||||
|
||||
/**
|
||||
* Folds over the `Fiber` or `RuntimeFiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* Folds over the `Fiber` or `RuntimeFiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A, E, Z>(
|
||||
options: {
|
||||
readonly onFiber: (fiber: Fiber<A, E>) => Z
|
||||
readonly onRuntimeFiber: (fiber: RuntimeFiber<A, E>) => Z
|
||||
}
|
||||
): (self: Fiber<A, E>) => Z
|
||||
/**
|
||||
* Folds over the `Fiber` or `RuntimeFiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A, E, Z>(
|
||||
self: Fiber<A, E>,
|
||||
options: {
|
||||
readonly onFiber: (fiber: Fiber<A, E>) => Z
|
||||
readonly onRuntimeFiber: (fiber: RuntimeFiber<A, E>) => Z
|
||||
}
|
||||
): Z
|
||||
} = internal.match
|
||||
|
||||
/**
|
||||
* A fiber that never fails or succeeds.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const never: Fiber<never> = internal.never
|
||||
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
export const orElse: {
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A2 | A, E2 | E>
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A | A2, E | E2>
|
||||
} = internal.orElse
|
||||
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
export const orElseEither: {
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<Either.Either<A2, A>, E2 | E>
|
||||
/**
|
||||
* Returns a fiber that prefers `this` fiber, but falls back to the `that` one
|
||||
* when `this` one fails. Interrupting the returned fiber will interrupt both
|
||||
* fibers, sequentially, from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category alternatives
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<Either.Either<A2, A>, E | E2>
|
||||
} = internal.orElseEither
|
||||
|
||||
/**
|
||||
* Tentatively observes the fiber, but returns immediately if it is not
|
||||
* already done.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const poll: <A, E>(self: Fiber<A, E>) => Effect.Effect<Option.Option<Exit.Exit<A, E>>> = internal.poll
|
||||
|
||||
/**
|
||||
* Pretty-prints a `RuntimeFiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const pretty: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<string> = internal.pretty
|
||||
|
||||
/**
|
||||
* Returns a chunk containing all root fibers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const roots: Effect.Effect<Array<RuntimeFiber<any, any>>> = internal.roots
|
||||
|
||||
/**
|
||||
* Returns a chunk containing all root fibers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeRoots: (_: void) => Array<RuntimeFiber<any, any>> = internal.unsafeRoots
|
||||
|
||||
/**
|
||||
* Converts this fiber into a scoped effect. The fiber is interrupted when the
|
||||
* scope is closed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const scoped: <A, E>(self: Fiber<A, E>) => Effect.Effect<Fiber<A, E>, never, Scope.Scope> =
|
||||
fiberRuntime.fiberScoped
|
||||
|
||||
/**
|
||||
* Returns the `FiberStatus` of a `RuntimeFiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const status: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<FiberStatus.FiberStatus> = internal.status
|
||||
|
||||
/**
|
||||
* Returns a fiber that has already succeeded with the specified value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const succeed: <A>(value: A) => Fiber<A> = internal.succeed
|
||||
|
||||
const void_: Fiber<void> = internal.void
|
||||
export {
|
||||
/**
|
||||
* A fiber that has already succeeded with unit.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
void_ as void
|
||||
}
|
||||
|
||||
/**
|
||||
* Zips this fiber and the specified fiber together, producing a tuple of
|
||||
* their output.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Zips this fiber and the specified fiber together, producing a tuple of
|
||||
* their output.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<[A, A2], E2 | E>
|
||||
/**
|
||||
* Zips this fiber and the specified fiber together, producing a tuple of
|
||||
* their output.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<[A, A2], E | E2>
|
||||
} = circular.zipFiber
|
||||
|
||||
/**
|
||||
* Same as `zip` but discards the output of that `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipLeft: {
|
||||
/**
|
||||
* Same as `zip` but discards the output of that `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A, E2 | E>
|
||||
/**
|
||||
* Same as `zip` but discards the output of that `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A, E | E2>
|
||||
} = circular.zipLeftFiber
|
||||
|
||||
/**
|
||||
* Same as `zip` but discards the output of this `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipRight: {
|
||||
/**
|
||||
* Same as `zip` but discards the output of this `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A2, E2 | E>
|
||||
/**
|
||||
* Same as `zip` but discards the output of this `Fiber`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A2, E | E2>
|
||||
} = circular.zipRightFiber
|
||||
|
||||
/**
|
||||
* Zips this fiber with the specified fiber, combining their results using the
|
||||
* specified combiner function. Both joins and interruptions are performed in
|
||||
* sequential order from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipWith: {
|
||||
/**
|
||||
* Zips this fiber with the specified fiber, combining their results using the
|
||||
* specified combiner function. Both joins and interruptions are performed in
|
||||
* sequential order from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<B, E2, A, C>(that: Fiber<B, E2>, f: (a: A, b: B) => C): <E>(self: Fiber<A, E>) => Fiber<C, E2 | E>
|
||||
/**
|
||||
* Zips this fiber with the specified fiber, combining their results using the
|
||||
* specified combiner function. Both joins and interruptions are performed in
|
||||
* sequential order from left to right.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<A, E, B, E2, C>(self: Fiber<A, E>, that: Fiber<B, E2>, f: (a: A, b: B) => C): Fiber<C, E | E2>
|
||||
} = circular.zipWithFiber
|
||||
578
_node_modules/effect/src/FiberHandle.ts
generated
Normal file
578
_node_modules/effect/src/FiberHandle.ts
generated
Normal file
@@ -0,0 +1,578 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { NoSuchElementException } from "./Cause.js"
|
||||
import * as Cause from "./Cause.js"
|
||||
import * as Deferred from "./Deferred.js"
|
||||
import * as Effect from "./Effect.js"
|
||||
import * as Exit from "./Exit.js"
|
||||
import * as Fiber from "./Fiber.js"
|
||||
import * as FiberId from "./FiberId.js"
|
||||
import { constFalse, dual } from "./Function.js"
|
||||
import * as HashSet from "./HashSet.js"
|
||||
import * as Inspectable from "./Inspectable.js"
|
||||
import * as Option from "./Option.js"
|
||||
import { type Pipeable, pipeArguments } from "./Pipeable.js"
|
||||
import * as Predicate from "./Predicate.js"
|
||||
import * as Runtime from "./Runtime.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export const TypeId: unique symbol = Symbol.for("effect/FiberHandle")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories models
|
||||
*/
|
||||
export interface FiberHandle<out A = unknown, out E = unknown> extends Pipeable, Inspectable.Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
readonly deferred: Deferred.Deferred<void, unknown>
|
||||
/** @internal */
|
||||
state: {
|
||||
readonly _tag: "Open"
|
||||
fiber: Fiber.RuntimeFiber<A, E> | undefined
|
||||
} | {
|
||||
readonly _tag: "Closed"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories refinements
|
||||
*/
|
||||
export const isFiberHandle = (u: unknown): u is FiberHandle => Predicate.hasProperty(u, TypeId)
|
||||
|
||||
const Proto = {
|
||||
[TypeId]: TypeId,
|
||||
toString(this: FiberHandle) {
|
||||
return Inspectable.format(this.toJSON())
|
||||
},
|
||||
toJSON(this: FiberHandle) {
|
||||
return {
|
||||
_id: "FiberHandle",
|
||||
state: this.state
|
||||
}
|
||||
},
|
||||
[Inspectable.NodeInspectSymbol](this: FiberHandle) {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const unsafeMake = <A = unknown, E = unknown>(
|
||||
deferred: Deferred.Deferred<void, E>
|
||||
): FiberHandle<A, E> => {
|
||||
const self = Object.create(Proto)
|
||||
self.state = { _tag: "Open", fiber: undefined }
|
||||
self.deferred = deferred
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* A FiberHandle can be used to store a single fiber.
|
||||
* When the associated Scope is closed, the contained fiber will be interrupted.
|
||||
*
|
||||
* You can add a fiber to the handle using `FiberHandle.run`, and the fiber will
|
||||
* be automatically removed from the FiberHandle when it completes.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberHandle } from "effect"
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const handle = yield* FiberHandle.make()
|
||||
*
|
||||
* // run some effects
|
||||
* yield* FiberHandle.run(handle, Effect.never)
|
||||
* // this will interrupt the previous fiber
|
||||
* yield* FiberHandle.run(handle, Effect.never)
|
||||
*
|
||||
* yield* Effect.sleep(1000)
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fiber will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const make = <A = unknown, E = unknown>(): Effect.Effect<FiberHandle<A, E>, never, Scope.Scope> =>
|
||||
Effect.acquireRelease(
|
||||
Effect.map(Deferred.make<void, E>(), (deferred) => unsafeMake<A, E>(deferred)),
|
||||
(handle) =>
|
||||
Effect.withFiberRuntime((parent) => {
|
||||
const state = handle.state
|
||||
if (state._tag === "Closed") return Effect.void
|
||||
handle.state = { _tag: "Closed" }
|
||||
return state.fiber ?
|
||||
Effect.intoDeferred(
|
||||
Effect.asVoid(Fiber.interruptAs(state.fiber, FiberId.combine(parent.id(), internalFiberId))),
|
||||
handle.deferred
|
||||
) :
|
||||
Deferred.done(handle.deferred, Exit.void)
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntime = <R, E = unknown, A = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<A, E>(),
|
||||
(self) => runtime(self)<R>()
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberHandle.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntimePromise = <R = never, A = unknown, E = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: Runtime.RunForkOptions | undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<A, E>(),
|
||||
(self) => runtimePromise(self)<R>()
|
||||
)
|
||||
|
||||
const internalFiberIdId = -1
|
||||
const internalFiberId = FiberId.make(internalFiberIdId, 0)
|
||||
const isInternalInterruption = Cause.reduceWithContext(undefined, {
|
||||
emptyCase: constFalse,
|
||||
failCase: constFalse,
|
||||
dieCase: constFalse,
|
||||
interruptCase: (_, fiberId) => HashSet.has(FiberId.ids(fiberId), internalFiberIdId),
|
||||
sequentialCase: (_, left, right) => left || right,
|
||||
parallelCase: (_, left, right) => left || right
|
||||
})
|
||||
|
||||
/**
|
||||
* Set the fiber in a FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber is already running, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeSet: {
|
||||
/**
|
||||
* Set the fiber in a FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber is already running, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): (self: FiberHandle<A, E>) => void
|
||||
/**
|
||||
* Set the fiber in a FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber is already running, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): void
|
||||
} = dual((args) => isFiberHandle(args[0]), <A, E, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): void => {
|
||||
if (self.state._tag === "Closed") {
|
||||
fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
return
|
||||
} else if (self.state.fiber !== undefined) {
|
||||
if (options?.onlyIfMissing === true) {
|
||||
fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
return
|
||||
} else if (self.state.fiber === fiber) {
|
||||
return
|
||||
}
|
||||
self.state.fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
self.state.fiber = undefined
|
||||
}
|
||||
|
||||
self.state.fiber = fiber
|
||||
fiber.addObserver((exit) => {
|
||||
if (self.state._tag === "Open" && fiber === self.state.fiber) {
|
||||
self.state.fiber = undefined
|
||||
}
|
||||
if (
|
||||
Exit.isFailure(exit) &&
|
||||
(
|
||||
options?.propagateInterruption === true ?
|
||||
!isInternalInterruption(exit.cause) :
|
||||
!Cause.isInterruptedOnly(exit.cause)
|
||||
)
|
||||
) {
|
||||
Deferred.unsafeDone(self.deferred, exit as any)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Set the fiber in the FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber already exists in the FiberHandle, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* Set the fiber in the FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber already exists in the FiberHandle, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): (self: FiberHandle<A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Set the fiber in the FiberHandle. When the fiber completes, it will be removed from the FiberHandle.
|
||||
* If a fiber already exists in the FiberHandle, it will be interrupted unless `options.onlyIfMissing` is set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): Effect.Effect<void>
|
||||
} = dual((args) => isFiberHandle(args[0]), <A, E, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): Effect.Effect<void> =>
|
||||
Effect.fiberIdWith(
|
||||
(fiberId) =>
|
||||
Effect.sync(() =>
|
||||
unsafeSet(self, fiber, {
|
||||
interruptAs: fiberId,
|
||||
onlyIfMissing: options?.onlyIfMissing,
|
||||
propagateInterruption: options?.propagateInterruption
|
||||
})
|
||||
)
|
||||
))
|
||||
|
||||
/**
|
||||
* Retrieve the fiber from the FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeGet = <A, E>(self: FiberHandle<A, E>): Option.Option<Fiber.RuntimeFiber<A, E>> =>
|
||||
self.state._tag === "Closed" ? Option.none() : Option.fromNullable(self.state.fiber)
|
||||
|
||||
/**
|
||||
* Retrieve the fiber from the FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const get = <A, E>(self: FiberHandle<A, E>): Effect.Effect<Fiber.RuntimeFiber<A, E>, NoSuchElementException> =>
|
||||
Effect.suspend(() => unsafeGet(self))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const clear = <A, E>(self: FiberHandle<A, E>): Effect.Effect<void> =>
|
||||
Effect.uninterruptibleMask((restore) =>
|
||||
Effect.withFiberRuntime((fiber) => {
|
||||
if (self.state._tag === "Closed" || self.state.fiber === undefined) {
|
||||
return Effect.void
|
||||
}
|
||||
return Effect.zipRight(
|
||||
restore(Fiber.interruptAs(self.state.fiber, FiberId.combine(fiber.id(), internalFiberId))),
|
||||
Effect.sync(() => {
|
||||
if (self.state._tag === "Open") {
|
||||
self.state.fiber = undefined
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
const constInterruptedFiber = (function() {
|
||||
let fiber: Fiber.RuntimeFiber<never, never> | undefined = undefined
|
||||
return () => {
|
||||
if (fiber === undefined) {
|
||||
fiber = Effect.runFork(Effect.interrupt)
|
||||
}
|
||||
return fiber
|
||||
}
|
||||
})()
|
||||
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberHandle.
|
||||
* When the fiber completes, it will be removed from the FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const run: {
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberHandle.
|
||||
* When the fiber completes, it will be removed from the FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E>(
|
||||
self: FiberHandle<A, E>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): <R, XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>
|
||||
) => Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberHandle.
|
||||
* When the fiber completes, it will be removed from the FiberHandle.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
} = function() {
|
||||
const self = arguments[0] as FiberHandle
|
||||
if (Effect.isEffect(arguments[1])) {
|
||||
return runImpl(self, arguments[1], arguments[2]) as any
|
||||
}
|
||||
const options = arguments[1]
|
||||
return (effect: Effect.Effect<unknown, unknown, any>) => runImpl(self, effect, options)
|
||||
}
|
||||
|
||||
const runImpl = <A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberHandle<A, E>,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R> =>
|
||||
Effect.fiberIdWith((fiberId) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.interrupt
|
||||
} else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) {
|
||||
return Effect.sync(constInterruptedFiber)
|
||||
}
|
||||
return Effect.tap(
|
||||
Effect.forkDaemon(effect),
|
||||
(fiber) => unsafeSet(self, fiber, { ...options, interruptAs: fiberId })
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberHandle.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Context, Effect, FiberHandle } from "effect"
|
||||
*
|
||||
* interface Users {
|
||||
* readonly _: unique symbol
|
||||
* }
|
||||
* const Users = Context.GenericTag<Users, {
|
||||
* getAll: Effect.Effect<Array<unknown>>
|
||||
* }>("Users")
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const handle = yield* FiberHandle.make()
|
||||
* const run = yield* FiberHandle.runtime(handle)<Users>()
|
||||
*
|
||||
* // run an effect and set the fiber in the handle
|
||||
* run(Effect.andThen(Users, _ => _.getAll))
|
||||
*
|
||||
* // this will interrupt the previous fiber
|
||||
* run(Effect.andThen(Users, _ => _.getAll))
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fiber will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtime: <A, E>(
|
||||
self: FiberHandle<A, E>
|
||||
) => <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
R
|
||||
> = <A, E>(self: FiberHandle<A, E>) => <R>() =>
|
||||
Effect.map(
|
||||
Effect.runtime<R>(),
|
||||
(runtime) => {
|
||||
const runFork = Runtime.runFork(runtime)
|
||||
return <XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return constInterruptedFiber()
|
||||
} else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) {
|
||||
return constInterruptedFiber()
|
||||
}
|
||||
const fiber = runFork(effect, options)
|
||||
unsafeSet(self, fiber, options)
|
||||
return fiber
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberHandle.
|
||||
*
|
||||
* The returned run function will return Promise's that will resolve when the
|
||||
* fiber completes.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtimePromise = <A, E>(self: FiberHandle<A, E>): <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
R
|
||||
> =>
|
||||
<R>() =>
|
||||
Effect.map(
|
||||
runtime(self)<R>(),
|
||||
(runFork) =>
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
): Promise<XA> =>
|
||||
new Promise((resolve, reject) =>
|
||||
runFork(effect, options).addObserver((exit) => {
|
||||
if (Exit.isSuccess(exit)) {
|
||||
resolve(exit.value)
|
||||
} else {
|
||||
reject(Cause.squash(exit.cause))
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* If any of the Fiber's in the handle terminate with a failure,
|
||||
* the returned Effect will terminate with the first failure that occurred.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberHandle } from "effect";
|
||||
*
|
||||
* Effect.gen(function* (_) {
|
||||
* const handle = yield* _(FiberHandle.make());
|
||||
* yield* _(FiberHandle.set(handle, Effect.runFork(Effect.fail("error"))));
|
||||
*
|
||||
* // parent fiber will fail with "error"
|
||||
* yield* _(FiberHandle.join(handle));
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const join = <A, E>(self: FiberHandle<A, E>): Effect.Effect<void, E> =>
|
||||
Deferred.await(self.deferred as Deferred.Deferred<void, E>)
|
||||
|
||||
/**
|
||||
* Wait for the fiber in the FiberHandle to complete.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const awaitEmpty = <A, E>(self: FiberHandle<A, E>): Effect.Effect<void, E> =>
|
||||
Effect.suspend(() => {
|
||||
if (self.state._tag === "Closed" || self.state.fiber === undefined) {
|
||||
return Effect.void
|
||||
}
|
||||
return Fiber.await(self.state.fiber)
|
||||
})
|
||||
219
_node_modules/effect/src/FiberId.ts
generated
Normal file
219
_node_modules/effect/src/FiberId.ts
generated
Normal file
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Equal from "./Equal.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import * as internal from "./internal/fiberId.js"
|
||||
import type * as Option from "./Option.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FiberIdTypeId: unique symbol = internal.FiberIdTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FiberIdTypeId = typeof FiberIdTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Single = None | Runtime
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type FiberId = Single | Composite
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface None extends Equal.Equal, Inspectable {
|
||||
readonly [FiberIdTypeId]: FiberIdTypeId
|
||||
readonly _tag: "None"
|
||||
readonly id: -1
|
||||
readonly startTimeMillis: -1
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Runtime extends Equal.Equal, Inspectable {
|
||||
readonly [FiberIdTypeId]: FiberIdTypeId
|
||||
readonly _tag: "Runtime"
|
||||
readonly id: number
|
||||
readonly startTimeMillis: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Composite extends Equal.Equal, Inspectable {
|
||||
readonly [FiberIdTypeId]: FiberIdTypeId
|
||||
readonly _tag: "Composite"
|
||||
readonly left: FiberId
|
||||
readonly right: FiberId
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const none: None = internal.none
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const runtime: (id: number, startTimeMillis: number) => Runtime = internal.runtime
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const composite: (left: FiberId, right: FiberId) => Composite = internal.composite
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified unknown value is a `FiberId`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFiberId: (self: unknown) => self is FiberId = internal.isFiberId
|
||||
|
||||
/**
|
||||
* Returns `true` if the `FiberId` is a `None`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isNone: (self: FiberId) => self is None = internal.isNone
|
||||
|
||||
/**
|
||||
* Returns `true` if the `FiberId` is a `Runtime`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isRuntime: (self: FiberId) => self is Runtime = internal.isRuntime
|
||||
|
||||
/**
|
||||
* Returns `true` if the `FiberId` is a `Composite`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isComposite: (self: FiberId) => self is Composite = internal.isComposite
|
||||
|
||||
/**
|
||||
* Combine two `FiberId`s.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* Combine two `FiberId`s.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(that: FiberId): (self: FiberId) => FiberId
|
||||
/**
|
||||
* Combine two `FiberId`s.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: FiberId, that: FiberId): FiberId
|
||||
} = internal.combine
|
||||
|
||||
/**
|
||||
* Combines a set of `FiberId`s into a single `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const combineAll: (fiberIds: HashSet.HashSet<FiberId>) => FiberId = internal.combineAll
|
||||
|
||||
/**
|
||||
* Returns this `FiberId` if it is not `None`, otherwise returns that `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const getOrElse: {
|
||||
/**
|
||||
* Returns this `FiberId` if it is not `None`, otherwise returns that `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(that: FiberId): (self: FiberId) => FiberId
|
||||
/**
|
||||
* Returns this `FiberId` if it is not `None`, otherwise returns that `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: FiberId, that: FiberId): FiberId
|
||||
} = internal.getOrElse
|
||||
|
||||
/**
|
||||
* Get the set of identifiers for this `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const ids: (self: FiberId) => HashSet.HashSet<number> = internal.ids
|
||||
|
||||
/**
|
||||
* Creates a new `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (id: number, startTimeSeconds: number) => FiberId = internal.make
|
||||
|
||||
/**
|
||||
* Creates a string representing the name of the current thread of execution
|
||||
* represented by the specified `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const threadName: (self: FiberId) => string = internal.threadName
|
||||
|
||||
/**
|
||||
* Convert a `FiberId` into an `Option<FiberId>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const toOption: (self: FiberId) => Option.Option<FiberId> = internal.toOption
|
||||
|
||||
/**
|
||||
* Convert a `FiberId` into a `HashSet<FiberId>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const toSet: (self: FiberId) => HashSet.HashSet<Runtime> = internal.toSet
|
||||
|
||||
/**
|
||||
* Unsafely creates a new `FiberId`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeMake: (_: void) => Runtime = internal.unsafeMake
|
||||
775
_node_modules/effect/src/FiberMap.ts
generated
Normal file
775
_node_modules/effect/src/FiberMap.ts
generated
Normal file
@@ -0,0 +1,775 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { NoSuchElementException } from "./Cause.js"
|
||||
import * as Cause from "./Cause.js"
|
||||
import * as Deferred from "./Deferred.js"
|
||||
import * as Effect from "./Effect.js"
|
||||
import * as Exit from "./Exit.js"
|
||||
import * as Fiber from "./Fiber.js"
|
||||
import * as FiberId from "./FiberId.js"
|
||||
import { constFalse, constVoid, dual } from "./Function.js"
|
||||
import * as HashSet from "./HashSet.js"
|
||||
import * as Inspectable from "./Inspectable.js"
|
||||
import * as Iterable from "./Iterable.js"
|
||||
import * as MutableHashMap from "./MutableHashMap.js"
|
||||
import * as Option from "./Option.js"
|
||||
import { type Pipeable, pipeArguments } from "./Pipeable.js"
|
||||
import * as Predicate from "./Predicate.js"
|
||||
import * as Runtime from "./Runtime.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export const TypeId: unique symbol = Symbol.for("effect/FiberMap")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories models
|
||||
*/
|
||||
export interface FiberMap<in out K, out A = unknown, out E = unknown>
|
||||
extends Pipeable, Inspectable.Inspectable, Iterable<[K, Fiber.RuntimeFiber<A, E>]>
|
||||
{
|
||||
readonly [TypeId]: TypeId
|
||||
readonly deferred: Deferred.Deferred<void, unknown>
|
||||
/** @internal */
|
||||
state: {
|
||||
readonly _tag: "Open"
|
||||
readonly backing: MutableHashMap.MutableHashMap<K, Fiber.RuntimeFiber<A, E>>
|
||||
} | {
|
||||
readonly _tag: "Closed"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories refinements
|
||||
*/
|
||||
export const isFiberMap = (u: unknown): u is FiberMap<unknown> => Predicate.hasProperty(u, TypeId)
|
||||
|
||||
const Proto = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator](this: FiberMap<unknown>) {
|
||||
if (this.state._tag === "Closed") {
|
||||
return Iterable.empty()
|
||||
}
|
||||
return this.state.backing[Symbol.iterator]()
|
||||
},
|
||||
toString(this: FiberMap<unknown>) {
|
||||
return Inspectable.format(this.toJSON())
|
||||
},
|
||||
toJSON(this: FiberMap<unknown>) {
|
||||
return {
|
||||
_id: "FiberMap",
|
||||
state: this.state
|
||||
}
|
||||
},
|
||||
[Inspectable.NodeInspectSymbol](this: FiberMap<unknown>) {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const unsafeMake = <K, A = unknown, E = unknown>(
|
||||
backing: MutableHashMap.MutableHashMap<K, Fiber.RuntimeFiber<A, E>>,
|
||||
deferred: Deferred.Deferred<void, E>
|
||||
): FiberMap<K, A, E> => {
|
||||
const self = Object.create(Proto)
|
||||
self.state = { _tag: "Open", backing }
|
||||
self.deferred = deferred
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* A FiberMap can be used to store a collection of fibers, indexed by some key.
|
||||
* When the associated Scope is closed, all fibers in the map will be interrupted.
|
||||
*
|
||||
* You can add fibers to the map using `FiberMap.set` or `FiberMap.run`, and the fibers will
|
||||
* be automatically removed from the FiberMap when they complete.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberMap } from "effect"
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const map = yield* FiberMap.make<string>()
|
||||
*
|
||||
* // run some effects and add the fibers to the map
|
||||
* yield* FiberMap.run(map, "fiber a", Effect.never)
|
||||
* yield* FiberMap.run(map, "fiber b", Effect.never)
|
||||
*
|
||||
* yield* Effect.sleep(1000)
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fibers will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const make = <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope> =>
|
||||
Effect.acquireRelease(
|
||||
Effect.map(Deferred.make<void, E>(), (deferred) =>
|
||||
unsafeMake<K, A, E>(
|
||||
MutableHashMap.empty(),
|
||||
deferred
|
||||
)),
|
||||
(map) =>
|
||||
Effect.withFiberRuntime((parent) => {
|
||||
const state = map.state
|
||||
if (state._tag === "Closed") return Effect.void
|
||||
map.state = { _tag: "Closed" }
|
||||
return Fiber.interruptAllAs(
|
||||
Iterable.map(state.backing, ([, fiber]) => fiber),
|
||||
FiberId.combine(parent.id(), internalFiberId)
|
||||
).pipe(
|
||||
Effect.intoDeferred(map.deferred)
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntime = <R, K, E = unknown, A = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<K, A, E>(),
|
||||
(self) => runtime(self)<R>()
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberMap.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntimePromise = <R, K, A = unknown, E = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<K, A, E>(),
|
||||
(self) => runtimePromise(self)<R>()
|
||||
)
|
||||
|
||||
const internalFiberIdId = -1
|
||||
const internalFiberId = FiberId.make(internalFiberIdId, 0)
|
||||
const isInternalInterruption = Cause.reduceWithContext(undefined, {
|
||||
emptyCase: constFalse,
|
||||
failCase: constFalse,
|
||||
dieCase: constFalse,
|
||||
interruptCase: (_, fiberId) => HashSet.has(FiberId.ids(fiberId), internalFiberIdId),
|
||||
sequentialCase: (_, left, right) => left || right,
|
||||
parallelCase: (_, left, right) => left || right
|
||||
})
|
||||
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeSet: {
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E, XE extends E, XA extends A>(
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): (self: FiberMap<K, A, E>) => void
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): void
|
||||
} = dual((args) => isFiberMap(args[0]), <K, A, E, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): void => {
|
||||
if (self.state._tag === "Closed") {
|
||||
fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
return
|
||||
}
|
||||
|
||||
const previous = MutableHashMap.get(self.state.backing, key)
|
||||
if (previous._tag === "Some") {
|
||||
if (options?.onlyIfMissing === true) {
|
||||
fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
return
|
||||
} else if (previous.value === fiber) {
|
||||
return
|
||||
}
|
||||
previous.value.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
}
|
||||
|
||||
MutableHashMap.set(self.state.backing, key, fiber)
|
||||
fiber.addObserver((exit) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return
|
||||
}
|
||||
const current = MutableHashMap.get(self.state.backing, key)
|
||||
if (Option.isSome(current) && fiber === current.value) {
|
||||
MutableHashMap.remove(self.state.backing, key)
|
||||
}
|
||||
if (
|
||||
Exit.isFailure(exit) &&
|
||||
(
|
||||
options?.propagateInterruption === true ?
|
||||
!isInternalInterruption(exit.cause) :
|
||||
!Cause.isInterruptedOnly(exit.cause)
|
||||
)
|
||||
) {
|
||||
Deferred.unsafeDone(self.deferred, exit as any)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E, XE extends E, XA extends A>(
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): (self: FiberMap<K, A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Add a fiber to the FiberMap. When the fiber completes, it will be removed from the FiberMap.
|
||||
* If the key already exists in the FiberMap, the previous fiber will be interrupted.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<void>
|
||||
} = dual((args) => isFiberMap(args[0]), <K, A, E, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<void> =>
|
||||
Effect.fiberIdWith(
|
||||
(fiberId) =>
|
||||
Effect.sync(() =>
|
||||
unsafeSet(self, key, fiber, {
|
||||
...options,
|
||||
interruptAs: fiberId
|
||||
})
|
||||
)
|
||||
))
|
||||
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeGet: {
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Option.Option<Fiber.RuntimeFiber<A, E>>
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): Option.Option<Fiber.RuntimeFiber<A, E>>
|
||||
} = dual<
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K) => <A, E>(self: FiberMap<K, A, E>) => Option.Option<Fiber.RuntimeFiber<A, E>>,
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K) => Option.Option<Fiber.RuntimeFiber<A, E>>
|
||||
>(2, (self, key) => self.state._tag === "Closed" ? Option.none() : MutableHashMap.get(self.state.backing, key))
|
||||
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, NoSuchElementException>
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Fiber.RuntimeFiber<A, E>, NoSuchElementException>
|
||||
} = dual<
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K) => <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, NoSuchElementException>,
|
||||
/**
|
||||
* Retrieve a fiber from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<Fiber.RuntimeFiber<A, E>, NoSuchElementException>
|
||||
>(2, (self, key) => Effect.suspend(() => unsafeGet(self, key)))
|
||||
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeHas: {
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => boolean
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): boolean
|
||||
} = dual(
|
||||
2,
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): boolean =>
|
||||
self.state._tag === "Closed" ? false : MutableHashMap.has(self.state.backing, key)
|
||||
)
|
||||
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const has: {
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Check if a key exists in the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>
|
||||
} = dual(
|
||||
2,
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean> => Effect.sync(() => unsafeHas(self, key))
|
||||
)
|
||||
|
||||
/**
|
||||
* Remove a fiber from the FiberMap, interrupting it if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const remove: {
|
||||
/**
|
||||
* Remove a fiber from the FiberMap, interrupting it if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Remove a fiber from the FiberMap, interrupting it if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>
|
||||
} = dual<
|
||||
/**
|
||||
* Remove a fiber from the FiberMap, interrupting it if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K>(key: K) => <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>,
|
||||
/**
|
||||
* Remove a fiber from the FiberMap, interrupting it if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<void>
|
||||
>(2, (self, key) =>
|
||||
Effect.withFiberRuntime((removeFiber) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.void
|
||||
}
|
||||
const fiber = MutableHashMap.get(self.state.backing, key)
|
||||
if (fiber._tag === "None") {
|
||||
return Effect.void
|
||||
}
|
||||
// will be removed by the observer
|
||||
return Fiber.interruptAs(fiber.value, FiberId.combine(removeFiber.id(), internalFiberId))
|
||||
}))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const clear = <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void> =>
|
||||
Effect.withFiberRuntime((clearFiber) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.void
|
||||
}
|
||||
|
||||
return Effect.forEach(self.state.backing, ([, fiber]) =>
|
||||
// will be removed by the observer
|
||||
Fiber.interruptAs(fiber, FiberId.combine(clearFiber.id(), internalFiberId)))
|
||||
})
|
||||
|
||||
const constInterruptedFiber = (function() {
|
||||
let fiber: Fiber.RuntimeFiber<never, never> | undefined = undefined
|
||||
return () => {
|
||||
if (fiber === undefined) {
|
||||
fiber = Effect.runFork(Effect.interrupt)
|
||||
}
|
||||
return fiber
|
||||
}
|
||||
})()
|
||||
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberMap.
|
||||
* When the fiber completes, it will be removed from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const run: {
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberMap.
|
||||
* When the fiber completes, it will be removed from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): <R, XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>
|
||||
) => Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
/**
|
||||
* Run an Effect and add the forked fiber to the FiberMap.
|
||||
* When the fiber completes, it will be removed from the FiberMap.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<K, A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
} = function() {
|
||||
const self = arguments[0]
|
||||
if (Effect.isEffect(arguments[2])) {
|
||||
return runImpl(self, arguments[1], arguments[2], arguments[3]) as any
|
||||
}
|
||||
const key = arguments[1]
|
||||
const options = arguments[2]
|
||||
return (effect: Effect.Effect<any, any, any>) => runImpl(self, key, effect, options)
|
||||
}
|
||||
|
||||
const runImpl = <K, A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberMap<K, A, E>,
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly onlyIfMissing?: boolean
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
) =>
|
||||
Effect.fiberIdWith((fiberId) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.interrupt
|
||||
} else if (options?.onlyIfMissing === true && unsafeHas(self, key)) {
|
||||
return Effect.sync(constInterruptedFiber)
|
||||
}
|
||||
return Effect.tap(
|
||||
Effect.forkDaemon(effect),
|
||||
(fiber) => unsafeSet(self, key, fiber, { ...options, interruptAs: fiberId })
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberMap.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Context, Effect, FiberMap } from "effect"
|
||||
*
|
||||
* interface Users {
|
||||
* readonly _: unique symbol
|
||||
* }
|
||||
* const Users = Context.GenericTag<Users, {
|
||||
* getAll: Effect.Effect<Array<unknown>>
|
||||
* }>("Users")
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const map = yield* FiberMap.make<string>()
|
||||
* const run = yield* FiberMap.runtime(map)<Users>()
|
||||
*
|
||||
* // run some effects and add the fibers to the map
|
||||
* run("effect-a", Effect.andThen(Users, _ => _.getAll))
|
||||
* run("effect-b", Effect.andThen(Users, _ => _.getAll))
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fibers will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtime: <K, A, E>(
|
||||
self: FiberMap<K, A, E>
|
||||
) => <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
R
|
||||
> = <K, A, E>(self: FiberMap<K, A, E>) => <R>() =>
|
||||
Effect.map(
|
||||
Effect.runtime<R>(),
|
||||
(runtime) => {
|
||||
const runFork = Runtime.runFork(runtime)
|
||||
return <XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return constInterruptedFiber()
|
||||
} else if (options?.onlyIfMissing === true && unsafeHas(self, key)) {
|
||||
return constInterruptedFiber()
|
||||
}
|
||||
const fiber = runFork(effect, options)
|
||||
unsafeSet(self, key, fiber, options)
|
||||
return fiber
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberMap.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtimePromise = <K, A, E>(self: FiberMap<K, A, E>): <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & {
|
||||
readonly onlyIfMissing?: boolean | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
| undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
R
|
||||
> =>
|
||||
<R>() =>
|
||||
Effect.map(
|
||||
runtime(self)<R>(),
|
||||
(runFork) =>
|
||||
<XE extends E, XA extends A>(
|
||||
key: K,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
): Promise<XA> =>
|
||||
new Promise((resolve, reject) =>
|
||||
runFork(key, effect, options).addObserver((exit) => {
|
||||
if (Exit.isSuccess(exit)) {
|
||||
resolve(exit.value)
|
||||
} else {
|
||||
reject(Cause.squash(exit.cause))
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const size = <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<number> =>
|
||||
Effect.sync(() => self.state._tag === "Closed" ? 0 : MutableHashMap.size(self.state.backing))
|
||||
|
||||
/**
|
||||
* Join all fibers in the FiberMap. If any of the Fiber's in the map terminate with a failure,
|
||||
* the returned Effect will terminate with the first failure that occurred.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberMap } from "effect";
|
||||
*
|
||||
* Effect.gen(function* (_) {
|
||||
* const map = yield* _(FiberMap.make());
|
||||
* yield* _(FiberMap.set(map, "a", Effect.runFork(Effect.fail("error"))));
|
||||
*
|
||||
* // parent fiber will fail with "error"
|
||||
* yield* _(FiberMap.join(map));
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const join = <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E> =>
|
||||
Deferred.await(self.deferred as Deferred.Deferred<void, E>)
|
||||
|
||||
/**
|
||||
* Wait for the FiberMap to be empty.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const awaitEmpty = <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E> =>
|
||||
Effect.whileLoop({
|
||||
while: () => self.state._tag === "Open" && MutableHashMap.size(self.state.backing) > 0,
|
||||
body: () => Fiber.await(Iterable.unsafeHead(self)[1]),
|
||||
step: constVoid
|
||||
})
|
||||
511
_node_modules/effect/src/FiberRef.ts
generated
Normal file
511
_node_modules/effect/src/FiberRef.ts
generated
Normal file
@@ -0,0 +1,511 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type * as Chunk from "./Chunk.js"
|
||||
import type * as Context from "./Context.js"
|
||||
import type * as Differ from "./Differ.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import type * as HashMap from "./HashMap.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as fiberRuntime from "./internal/fiberRuntime.js"
|
||||
import * as query from "./internal/query.js"
|
||||
import type * as List from "./List.js"
|
||||
import type * as Logger from "./Logger.js"
|
||||
import type * as LogLevel from "./LogLevel.js"
|
||||
import type * as LogSpan from "./LogSpan.js"
|
||||
import type * as MetricLabel from "./MetricLabel.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type * as Request from "./Request.js"
|
||||
import type * as RuntimeFlags from "./RuntimeFlags.js"
|
||||
import * as Scheduler from "./Scheduler.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
import type * as Supervisor from "./Supervisor.js"
|
||||
import type * as Tracer from "./Tracer.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FiberRefTypeId: unique symbol = core.FiberRefTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FiberRefTypeId = typeof FiberRefTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface FiberRef<in out A> extends Effect.Effect<A>, Variance<A> {
|
||||
/** @internal */
|
||||
readonly initial: A
|
||||
/** @internal */
|
||||
diff(oldValue: A, newValue: A): unknown
|
||||
/** @internal */
|
||||
combine(first: unknown, second: unknown): unknown
|
||||
/** @internal */
|
||||
patch(patch: unknown): (oldValue: A) => A
|
||||
/** @internal */
|
||||
readonly fork: unknown
|
||||
/** @internal */
|
||||
join(oldValue: A, newValue: A): A
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: FiberRefUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: FiberRefUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface FiberRefUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
FiberRef?: () => Extract<A[Unify.typeSymbol], FiberRef<any>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface FiberRefUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in out A> {
|
||||
readonly [FiberRefTypeId]: {
|
||||
readonly _A: Types.Invariant<A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <A>(
|
||||
initial: A,
|
||||
options?: {
|
||||
readonly fork?: ((a: A) => A) | undefined
|
||||
readonly join?: ((left: A, right: A) => A) | undefined
|
||||
}
|
||||
) => Effect.Effect<FiberRef<A>, never, Scope.Scope> = fiberRuntime.fiberRefMake
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWith: <Value>(ref: LazyArg<FiberRef<Value>>) => Effect.Effect<FiberRef<Value>, never, Scope.Scope> =
|
||||
fiberRuntime.fiberRefMakeWith
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeContext: <A>(
|
||||
initial: Context.Context<A>
|
||||
) => Effect.Effect<FiberRef<Context.Context<A>>, never, Scope.Scope> = fiberRuntime.fiberRefMakeContext
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeRuntimeFlags: (
|
||||
initial: RuntimeFlags.RuntimeFlags
|
||||
) => Effect.Effect<FiberRef<RuntimeFlags.RuntimeFlags>, never, Scope.Scope> = fiberRuntime.fiberRefMakeRuntimeFlags
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMake: <Value>(
|
||||
initial: Value,
|
||||
options?: {
|
||||
readonly fork?: ((a: Value) => Value) | undefined
|
||||
readonly join?: ((left: Value, right: Value) => Value) | undefined
|
||||
}
|
||||
) => FiberRef<Value> = core.fiberRefUnsafeMake
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMakeHashSet: <A>(initial: HashSet.HashSet<A>) => FiberRef<HashSet.HashSet<A>> =
|
||||
core.fiberRefUnsafeMakeHashSet
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMakeContext: <A>(initial: Context.Context<A>) => FiberRef<Context.Context<A>> =
|
||||
core.fiberRefUnsafeMakeContext
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMakeSupervisor: (initial: Supervisor.Supervisor<any>) => FiberRef<Supervisor.Supervisor<any>> =
|
||||
fiberRuntime.fiberRefUnsafeMakeSupervisor
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unsafeMakePatch: <Value, Patch>(
|
||||
initial: Value,
|
||||
options: {
|
||||
readonly differ: Differ.Differ<Value, Patch>
|
||||
readonly fork: Patch
|
||||
readonly join?: ((oldV: Value, newV: Value) => Value) | undefined
|
||||
}
|
||||
) => FiberRef<Value> = core.fiberRefUnsafeMakePatch
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const get: <A>(self: FiberRef<A>) => Effect.Effect<A> = core.fiberRefGet
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const getAndSet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): (self: FiberRef<A>) => Effect.Effect<A>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, value: A): Effect.Effect<A>
|
||||
} = core.fiberRefGetAndSet
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const getAndUpdate: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(f: (a: A) => A): (self: FiberRef<A>) => Effect.Effect<A>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, f: (a: A) => A): Effect.Effect<A>
|
||||
} = core.fiberRefGetAndUpdate
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const getAndUpdateSome: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(pf: (a: A) => Option.Option<A>): (self: FiberRef<A>) => Effect.Effect<A>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, pf: (a: A) => Option.Option<A>): Effect.Effect<A>
|
||||
} = core.fiberRefGetAndUpdateSome
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const getWith: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B, E, R>(f: (a: A) => Effect.Effect<B, E, R>): (self: FiberRef<A>) => Effect.Effect<B, E, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B, E, R>(self: FiberRef<A>, f: (a: A) => Effect.Effect<B, E, R>): Effect.Effect<B, E, R>
|
||||
} = core.fiberRefGetWith
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): (self: FiberRef<A>) => Effect.Effect<void>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, value: A): Effect.Effect<void>
|
||||
} = core.fiberRefSet
|
||||
|
||||
const _delete: <A>(self: FiberRef<A>) => Effect.Effect<void> = core.fiberRefDelete
|
||||
|
||||
export {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
_delete as delete
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const reset: <A>(self: FiberRef<A>) => Effect.Effect<void> = core.fiberRefReset
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const modify: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(f: (a: A) => readonly [B, A]): (self: FiberRef<A>) => Effect.Effect<B>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, B>(self: FiberRef<A>, f: (a: A) => readonly [B, A]): Effect.Effect<B>
|
||||
} = core.fiberRefModify
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const modifySome: <A, B>(
|
||||
self: FiberRef<A>,
|
||||
def: B,
|
||||
f: (a: A) => Option.Option<readonly [B, A]>
|
||||
) => Effect.Effect<B> = core.fiberRefModifySome
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const update: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(f: (a: A) => A): (self: FiberRef<A>) => Effect.Effect<void>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, f: (a: A) => A): Effect.Effect<void>
|
||||
} = core.fiberRefUpdate
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const updateSome: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(pf: (a: A) => Option.Option<A>): (self: FiberRef<A>) => Effect.Effect<void>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, pf: (a: A) => Option.Option<A>): Effect.Effect<void>
|
||||
} = core.fiberRefUpdateSome
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const updateAndGet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(f: (a: A) => A): (self: FiberRef<A>) => Effect.Effect<A>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, f: (a: A) => A): Effect.Effect<A>
|
||||
} = core.fiberRefUpdateAndGet
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const updateSomeAndGet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(pf: (a: A) => Option.Option<A>): (self: FiberRef<A>) => Effect.Effect<A>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: FiberRef<A>, pf: (a: A) => Option.Option<A>): Effect.Effect<A>
|
||||
} = core.fiberRefUpdateSomeAndGet
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentConcurrency: FiberRef<number | "unbounded"> = core.currentConcurrency
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentRequestBatchingEnabled: FiberRef<boolean> = core.currentRequestBatching
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentRequestCache: FiberRef<Request.Cache> = query.currentCache as any
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentRequestCacheEnabled: FiberRef<boolean> = query.currentCacheEnabled
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentContext: FiberRef<Context.Context<never>> = core.currentContext
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentSchedulingPriority: FiberRef<number> = core.currentSchedulingPriority
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentMaxOpsBeforeYield: FiberRef<number> = core.currentMaxOpsBeforeYield
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const unhandledErrorLogLevel: FiberRef<Option.Option<LogLevel.LogLevel>> = core.currentUnhandledErrorLogLevel
|
||||
|
||||
/**
|
||||
* @since 3.17.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const versionMismatchErrorLogLevel: FiberRef<Option.Option<LogLevel.LogLevel>> =
|
||||
core.currentVersionMismatchErrorLogLevel
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentLogAnnotations: FiberRef<HashMap.HashMap<string, unknown>> = core.currentLogAnnotations
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentLoggers: FiberRef<HashSet.HashSet<Logger.Logger<unknown, any>>> = fiberRuntime.currentLoggers
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentLogLevel: FiberRef<LogLevel.LogLevel> = core.currentLogLevel
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentMinimumLogLevel: FiberRef<LogLevel.LogLevel> = fiberRuntime.currentMinimumLogLevel
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentLogSpan: FiberRef<List.List<LogSpan.LogSpan>> = core.currentLogSpan
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentRuntimeFlags: FiberRef<RuntimeFlags.RuntimeFlags> = fiberRuntime.currentRuntimeFlags
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentScheduler: FiberRef<Scheduler.Scheduler> = Scheduler.currentScheduler
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentSupervisor: FiberRef<Supervisor.Supervisor<any>> = fiberRuntime.currentSupervisor
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentMetricLabels: FiberRef<ReadonlyArray<MetricLabel.MetricLabel>> = core.currentMetricLabels
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentTracerEnabled: FiberRef<boolean> = core.currentTracerEnabled
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentTracerTimingEnabled: FiberRef<boolean> = core.currentTracerTimingEnabled
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentTracerSpanAnnotations: FiberRef<HashMap.HashMap<string, unknown>> =
|
||||
core.currentTracerSpanAnnotations
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const currentTracerSpanLinks: FiberRef<Chunk.Chunk<Tracer.SpanLink>> = core.currentTracerSpanLinks
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category fiberRefs
|
||||
*/
|
||||
export const interruptedCause: FiberRef<Cause.Cause<never>> = core.currentInterruptedCause
|
||||
288
_node_modules/effect/src/FiberRefs.ts
generated
Normal file
288
_node_modules/effect/src/FiberRefs.ts
generated
Normal file
@@ -0,0 +1,288 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Arr from "./Array.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type * as FiberRef from "./FiberRef.js"
|
||||
import type * as HashSet from "./HashSet.js"
|
||||
import * as internal from "./internal/fiberRefs.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FiberRefsSym: unique symbol = internal.FiberRefsSym
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FiberRefsSym = typeof FiberRefsSym
|
||||
|
||||
/**
|
||||
* `FiberRefs` is a data type that represents a collection of `FiberRef` values.
|
||||
*
|
||||
* This allows safely propagating `FiberRef` values across fiber boundaries, for
|
||||
* example between an asynchronous producer and consumer.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface FiberRefs extends Pipeable {
|
||||
readonly [FiberRefsSym]: FiberRefsSym
|
||||
readonly locals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Single, any]>>
|
||||
}
|
||||
|
||||
const delete_: {
|
||||
<A>(fiberRef: FiberRef.FiberRef<A>): (self: FiberRefs) => FiberRefs
|
||||
<A>(self: FiberRefs, fiberRef: FiberRef.FiberRef<A>): FiberRefs
|
||||
} = internal.delete_
|
||||
|
||||
export {
|
||||
/**
|
||||
* Deletes the specified `FiberRef` from the `FibterRefs`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
delete_ as delete
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of each `FiberRef` in this collection.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const fiberRefs: (self: FiberRefs) => HashSet.HashSet<FiberRef.FiberRef<any>> = internal.fiberRefs
|
||||
|
||||
/**
|
||||
* Forks this collection of fiber refs as the specified child fiber id. This
|
||||
* will potentially modify the value of the fiber refs, as determined by the
|
||||
* individual fiber refs that make up the collection.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const forkAs: {
|
||||
/**
|
||||
* Forks this collection of fiber refs as the specified child fiber id. This
|
||||
* will potentially modify the value of the fiber refs, as determined by the
|
||||
* individual fiber refs that make up the collection.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(childId: FiberId.Single): (self: FiberRefs) => FiberRefs
|
||||
/**
|
||||
* Forks this collection of fiber refs as the specified child fiber id. This
|
||||
* will potentially modify the value of the fiber refs, as determined by the
|
||||
* individual fiber refs that make up the collection.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: FiberRefs, childId: FiberId.Single): FiberRefs
|
||||
} = internal.forkAs
|
||||
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or `None` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or `None` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<A>(fiberRef: FiberRef.FiberRef<A>): (self: FiberRefs) => Option.Option<A>
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or `None` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<A>(self: FiberRefs, fiberRef: FiberRef.FiberRef<A>): Option.Option<A>
|
||||
} = internal.get
|
||||
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or the `initial` value of the `FiberRef` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const getOrDefault: {
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or the `initial` value of the `FiberRef` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<A>(fiberRef: FiberRef.FiberRef<A>): (self: FiberRefs) => A
|
||||
/**
|
||||
* Gets the value of the specified `FiberRef` in this collection of `FiberRef`
|
||||
* values if it exists or the `initial` value of the `FiberRef` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
<A>(self: FiberRefs, fiberRef: FiberRef.FiberRef<A>): A
|
||||
} = internal.getOrDefault
|
||||
|
||||
/**
|
||||
* Joins this collection of fiber refs to the specified collection, as the
|
||||
* specified fiber id. This will perform diffing and merging to ensure
|
||||
* preservation of maximum information from both child and parent refs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const joinAs: {
|
||||
/**
|
||||
* Joins this collection of fiber refs to the specified collection, as the
|
||||
* specified fiber id. This will perform diffing and merging to ensure
|
||||
* preservation of maximum information from both child and parent refs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(fiberId: FiberId.Single, that: FiberRefs): (self: FiberRefs) => FiberRefs
|
||||
/**
|
||||
* Joins this collection of fiber refs to the specified collection, as the
|
||||
* specified fiber id. This will perform diffing and merging to ensure
|
||||
* preservation of maximum information from both child and parent refs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: FiberRefs, fiberId: FiberId.Single, that: FiberRefs): FiberRefs
|
||||
} = internal.joinAs
|
||||
|
||||
/**
|
||||
* Set each ref to either its value or its default.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const setAll: (self: FiberRefs) => Effect.Effect<void> = internal.setAll
|
||||
|
||||
/**
|
||||
* Updates the value of the specified `FiberRef` using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const updateAs: {
|
||||
/**
|
||||
* Updates the value of the specified `FiberRef` using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(
|
||||
options: {
|
||||
readonly fiberId: FiberId.Single
|
||||
readonly fiberRef: FiberRef.FiberRef<A>
|
||||
readonly value: A
|
||||
}
|
||||
): (self: FiberRefs) => FiberRefs
|
||||
/**
|
||||
* Updates the value of the specified `FiberRef` using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(
|
||||
self: FiberRefs,
|
||||
options: {
|
||||
readonly fiberId: FiberId.Single
|
||||
readonly fiberRef: FiberRef.FiberRef<A>
|
||||
readonly value: A
|
||||
}
|
||||
): FiberRefs
|
||||
} = internal.updateAs
|
||||
|
||||
/**
|
||||
* Updates the values of the specified `FiberRef` & value pairs using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const updateManyAs: {
|
||||
/**
|
||||
* Updates the values of the specified `FiberRef` & value pairs using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(
|
||||
options: {
|
||||
readonly forkAs?: FiberId.Single | undefined
|
||||
readonly entries: readonly [
|
||||
readonly [
|
||||
FiberRef.FiberRef<any>,
|
||||
readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
|
||||
],
|
||||
...Array<
|
||||
readonly [
|
||||
FiberRef.FiberRef<any>,
|
||||
readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
|
||||
]
|
||||
>
|
||||
]
|
||||
}
|
||||
): (self: FiberRefs) => FiberRefs
|
||||
/**
|
||||
* Updates the values of the specified `FiberRef` & value pairs using the provided `FiberId`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(
|
||||
self: FiberRefs,
|
||||
options: {
|
||||
readonly forkAs?: FiberId.Single | undefined
|
||||
readonly entries: readonly [
|
||||
readonly [
|
||||
FiberRef.FiberRef<any>,
|
||||
readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
|
||||
],
|
||||
...Array<
|
||||
readonly [
|
||||
FiberRef.FiberRef<any>,
|
||||
readonly [readonly [FiberId.Single, any], ...Array<readonly [FiberId.Single, any]>]
|
||||
]
|
||||
>
|
||||
]
|
||||
}
|
||||
): FiberRefs
|
||||
} = internal.updateManyAs
|
||||
|
||||
/**
|
||||
* Note: it will not copy the provided Map, make sure to provide a fresh one.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeMake: (
|
||||
fiberRefLocals: Map<FiberRef.FiberRef<any>, Arr.NonEmptyReadonlyArray<readonly [FiberId.Single, any]>>
|
||||
) => FiberRefs = internal.unsafeMake
|
||||
|
||||
/**
|
||||
* The empty collection of `FiberRef` values.
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const empty: () => FiberRefs = internal.empty
|
||||
139
_node_modules/effect/src/FiberRefsPatch.ts
generated
Normal file
139
_node_modules/effect/src/FiberRefsPatch.ts
generated
Normal file
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type * as FiberRef from "./FiberRef.js"
|
||||
import type * as FiberRefs from "./FiberRefs.js"
|
||||
import * as internal from "./internal/fiberRefs/patch.js"
|
||||
|
||||
/**
|
||||
* A `FiberRefsPatch` captures the changes in `FiberRef` values made by a single
|
||||
* fiber as a value. This allows fibers to apply the changes made by a workflow
|
||||
* without inheriting all the `FiberRef` values of the fiber that executed the
|
||||
* workflow.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type FiberRefsPatch = Empty | Add | Remove | Update | AndThen
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Empty {
|
||||
readonly _tag: "Empty"
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Add {
|
||||
readonly _tag: "Add"
|
||||
readonly fiberRef: FiberRef.FiberRef<unknown>
|
||||
readonly value: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Remove {
|
||||
readonly _tag: "Remove"
|
||||
readonly fiberRef: FiberRef.FiberRef<unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Update {
|
||||
readonly _tag: "Update"
|
||||
readonly fiberRef: FiberRef.FiberRef<unknown>
|
||||
readonly patch: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface AndThen {
|
||||
readonly _tag: "AndThen"
|
||||
readonly first: FiberRefsPatch
|
||||
readonly second: FiberRefsPatch
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty: FiberRefsPatch = internal.empty
|
||||
|
||||
/**
|
||||
* Constructs a patch that describes the changes between the specified
|
||||
* collections of `FiberRef`
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const diff: (oldValue: FiberRefs.FiberRefs, newValue: FiberRefs.FiberRefs) => FiberRefsPatch = internal.diff
|
||||
|
||||
/**
|
||||
* Combines this patch and the specified patch to create a new patch that
|
||||
* describes applying the changes from this patch and the specified patch
|
||||
* sequentially.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* Combines this patch and the specified patch to create a new patch that
|
||||
* describes applying the changes from this patch and the specified patch
|
||||
* sequentially.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(that: FiberRefsPatch): (self: FiberRefsPatch) => FiberRefsPatch
|
||||
/**
|
||||
* Combines this patch and the specified patch to create a new patch that
|
||||
* describes applying the changes from this patch and the specified patch
|
||||
* sequentially.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(self: FiberRefsPatch, that: FiberRefsPatch): FiberRefsPatch
|
||||
} = internal.combine
|
||||
|
||||
/**
|
||||
* Applies the changes described by this patch to the specified collection
|
||||
* of `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const patch: {
|
||||
/**
|
||||
* Applies the changes described by this patch to the specified collection
|
||||
* of `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
(fiberId: FiberId.Runtime, oldValue: FiberRefs.FiberRefs): (self: FiberRefsPatch) => FiberRefs.FiberRefs
|
||||
/**
|
||||
* Applies the changes described by this patch to the specified collection
|
||||
* of `FiberRef` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
(
|
||||
self: FiberRefsPatch,
|
||||
fiberId: FiberId.Runtime,
|
||||
oldValue: FiberRefs.FiberRefs
|
||||
): FiberRefs.FiberRefs
|
||||
} = internal.patch
|
||||
529
_node_modules/effect/src/FiberSet.ts
generated
Normal file
529
_node_modules/effect/src/FiberSet.ts
generated
Normal file
@@ -0,0 +1,529 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Cause from "./Cause.js"
|
||||
import * as Deferred from "./Deferred.js"
|
||||
import * as Effect from "./Effect.js"
|
||||
import * as Exit from "./Exit.js"
|
||||
import * as Fiber from "./Fiber.js"
|
||||
import * as FiberId from "./FiberId.js"
|
||||
import { constFalse, constVoid, dual } from "./Function.js"
|
||||
import * as HashSet from "./HashSet.js"
|
||||
import * as Inspectable from "./Inspectable.js"
|
||||
import * as Iterable from "./Iterable.js"
|
||||
import { type Pipeable, pipeArguments } from "./Pipeable.js"
|
||||
import * as Predicate from "./Predicate.js"
|
||||
import * as Runtime from "./Runtime.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export const TypeId: unique symbol = Symbol.for("effect/FiberSet")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories type ids
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories models
|
||||
*/
|
||||
export interface FiberSet<out A = unknown, out E = unknown>
|
||||
extends Pipeable, Inspectable.Inspectable, Iterable<Fiber.RuntimeFiber<A, E>>
|
||||
{
|
||||
readonly [TypeId]: TypeId
|
||||
readonly deferred: Deferred.Deferred<void, unknown>
|
||||
/** @internal */
|
||||
state: {
|
||||
readonly _tag: "Open"
|
||||
readonly backing: Set<Fiber.RuntimeFiber<A, E>>
|
||||
} | {
|
||||
readonly _tag: "Closed"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories refinements
|
||||
*/
|
||||
export const isFiberSet = (u: unknown): u is FiberSet<unknown, unknown> => Predicate.hasProperty(u, TypeId)
|
||||
|
||||
const Proto = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator](this: FiberSet<unknown, unknown>) {
|
||||
if (this.state._tag === "Closed") {
|
||||
return Iterable.empty()
|
||||
}
|
||||
return this.state.backing[Symbol.iterator]()
|
||||
},
|
||||
toString(this: FiberSet<unknown, unknown>) {
|
||||
return Inspectable.format(this.toJSON())
|
||||
},
|
||||
toJSON(this: FiberSet<unknown, unknown>) {
|
||||
return {
|
||||
_id: "FiberMap",
|
||||
state: this.state
|
||||
}
|
||||
},
|
||||
[Inspectable.NodeInspectSymbol](this: FiberSet<unknown, unknown>) {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const unsafeMake = <A, E>(
|
||||
backing: Set<Fiber.RuntimeFiber<A, E>>,
|
||||
deferred: Deferred.Deferred<void, unknown>
|
||||
): FiberSet<A, E> => {
|
||||
const self = Object.create(Proto)
|
||||
self.state = { _tag: "Open", backing }
|
||||
self.deferred = deferred
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* A FiberSet can be used to store a collection of fibers.
|
||||
* When the associated Scope is closed, all fibers in the set will be interrupted.
|
||||
*
|
||||
* You can add fibers to the set using `FiberSet.add` or `FiberSet.run`, and the fibers will
|
||||
* be automatically removed from the FiberSet when they complete.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberSet } from "effect"
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const set = yield* FiberSet.make()
|
||||
*
|
||||
* // run some effects and add the fibers to the set
|
||||
* yield* FiberSet.run(set, Effect.never)
|
||||
* yield* FiberSet.run(set, Effect.never)
|
||||
*
|
||||
* yield* Effect.sleep(1000)
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fibers will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const make = <A = unknown, E = unknown>(): Effect.Effect<FiberSet<A, E>, never, Scope.Scope> =>
|
||||
Effect.acquireRelease(
|
||||
Effect.map(Deferred.make<void, unknown>(), (deferred) => unsafeMake(new Set(), deferred)),
|
||||
(set) =>
|
||||
Effect.withFiberRuntime((parent) => {
|
||||
const state = set.state
|
||||
if (state._tag === "Closed") return Effect.void
|
||||
set.state = { _tag: "Closed" }
|
||||
const fibers = state.backing
|
||||
return Fiber.interruptAllAs(fibers, FiberId.combine(parent.id(), internalFiberId)).pipe(
|
||||
Effect.intoDeferred(set.deferred)
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberSet.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntime = <R = never, A = unknown, E = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: Runtime.RunForkOptions | undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<A, E>(),
|
||||
(self) => runtime(self)<R>()
|
||||
)
|
||||
|
||||
/**
|
||||
* Create an Effect run function that is backed by a FiberSet.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories constructors
|
||||
*/
|
||||
export const makeRuntimePromise = <R = never, A = unknown, E = unknown>(): Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: Runtime.RunForkOptions | undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
Scope.Scope | R
|
||||
> =>
|
||||
Effect.flatMap(
|
||||
make<A, E>(),
|
||||
(self) => runtimePromise(self)<R>()
|
||||
)
|
||||
|
||||
const internalFiberIdId = -1
|
||||
const internalFiberId = FiberId.make(internalFiberIdId, 0)
|
||||
const isInternalInterruption = Cause.reduceWithContext(undefined, {
|
||||
emptyCase: constFalse,
|
||||
failCase: constFalse,
|
||||
dieCase: constFalse,
|
||||
interruptCase: (_, fiberId) => HashSet.has(FiberId.ids(fiberId), internalFiberIdId),
|
||||
sequentialCase: (_, left, right) => left || right,
|
||||
parallelCase: (_, left, right) => left || right
|
||||
})
|
||||
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const unsafeAdd: {
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): (self: FiberSet<A, E>) => void
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): void
|
||||
} = dual((args) => isFiberSet(args[0]), <A, E, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly interruptAs?: FiberId.FiberId | undefined
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): void => {
|
||||
if (self.state._tag === "Closed") {
|
||||
fiber.unsafeInterruptAsFork(FiberId.combine(options?.interruptAs ?? FiberId.none, internalFiberId))
|
||||
return
|
||||
} else if (self.state.backing.has(fiber)) {
|
||||
return
|
||||
}
|
||||
self.state.backing.add(fiber)
|
||||
fiber.addObserver((exit) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return
|
||||
}
|
||||
self.state.backing.delete(fiber)
|
||||
if (
|
||||
Exit.isFailure(exit) &&
|
||||
(
|
||||
options?.propagateInterruption === true ?
|
||||
!isInternalInterruption(exit.cause) :
|
||||
!Cause.isInterruptedOnly(exit.cause)
|
||||
)
|
||||
) {
|
||||
Deferred.unsafeDone(self.deferred, exit as any)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const add: {
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): (self: FiberSet<A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Add a fiber to the FiberSet. When the fiber completes, it will be removed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<void>
|
||||
} = dual(
|
||||
(args) => isFiberSet(args[0]),
|
||||
<A, E, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
fiber: Fiber.RuntimeFiber<XA, XE>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<void> =>
|
||||
Effect.fiberIdWith((fiberId) =>
|
||||
Effect.sync(() =>
|
||||
unsafeAdd(self, fiber, {
|
||||
...options,
|
||||
interruptAs: fiberId
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const clear = <A, E>(self: FiberSet<A, E>): Effect.Effect<void> =>
|
||||
Effect.withFiberRuntime((clearFiber) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.void
|
||||
}
|
||||
return Effect.forEach(self.state.backing, (fiber) =>
|
||||
// will be removed by the observer
|
||||
Fiber.interruptAs(fiber, FiberId.combine(clearFiber.id(), internalFiberId)))
|
||||
})
|
||||
|
||||
const constInterruptedFiber = (function() {
|
||||
let fiber: Fiber.RuntimeFiber<never, never> | undefined = undefined
|
||||
return () => {
|
||||
if (fiber === undefined) {
|
||||
fiber = Effect.runFork(Effect.interrupt)
|
||||
}
|
||||
return fiber
|
||||
}
|
||||
})()
|
||||
|
||||
/**
|
||||
* Fork an Effect and add the forked fiber to the FiberSet.
|
||||
* When the fiber completes, it will be removed from the FiberSet.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const run: {
|
||||
/**
|
||||
* Fork an Effect and add the forked fiber to the FiberSet.
|
||||
* When the fiber completes, it will be removed from the FiberSet.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E>(
|
||||
self: FiberSet<A, E>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): <R, XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>
|
||||
) => Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
/**
|
||||
* Fork an Effect and add the forked fiber to the FiberSet.
|
||||
* When the fiber completes, it will be removed from the FiberSet.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
<A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
|
||||
} = function() {
|
||||
const self = arguments[0] as FiberSet<any, any>
|
||||
if (!Effect.isEffect(arguments[1])) {
|
||||
const options = arguments[1]
|
||||
return (effect: Effect.Effect<any, any, any>) => runImpl(self, effect, options)
|
||||
}
|
||||
return runImpl(self, arguments[1], arguments[2]) as any
|
||||
}
|
||||
|
||||
const runImpl = <A, E, R, XE extends E, XA extends A>(
|
||||
self: FiberSet<A, E>,
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?: {
|
||||
readonly propagateInterruption?: boolean | undefined
|
||||
}
|
||||
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R> =>
|
||||
Effect.fiberIdWith((fiberId) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return Effect.sync(constInterruptedFiber)
|
||||
}
|
||||
return Effect.tap(
|
||||
Effect.forkDaemon(effect),
|
||||
(fiber) =>
|
||||
unsafeAdd(self, fiber, {
|
||||
...options,
|
||||
interruptAs: fiberId
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberSet.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Context, Effect, FiberSet } from "effect"
|
||||
*
|
||||
* interface Users {
|
||||
* readonly _: unique symbol
|
||||
* }
|
||||
* const Users = Context.GenericTag<Users, {
|
||||
* getAll: Effect.Effect<Array<unknown>>
|
||||
* }>("Users")
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const set = yield* FiberSet.make()
|
||||
* const run = yield* FiberSet.runtime(set)<Users>()
|
||||
*
|
||||
* // run some effects and add the fibers to the set
|
||||
* run(Effect.andThen(Users, _ => _.getAll))
|
||||
* }).pipe(
|
||||
* Effect.scoped // The fibers will be interrupted when the scope is closed
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtime: <A, E>(
|
||||
self: FiberSet<A, E>
|
||||
) => <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
) => Fiber.RuntimeFiber<XA, XE>,
|
||||
never,
|
||||
R
|
||||
> = <A, E>(self: FiberSet<A, E>) => <R>() =>
|
||||
Effect.map(
|
||||
Effect.runtime<R>(),
|
||||
(runtime) => {
|
||||
const runFork = Runtime.runFork(runtime)
|
||||
return <XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
) => {
|
||||
if (self.state._tag === "Closed") {
|
||||
return constInterruptedFiber()
|
||||
}
|
||||
const fiber = runFork(effect, options)
|
||||
unsafeAdd(self, fiber)
|
||||
return fiber
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberSet.
|
||||
*
|
||||
* The returned run function will return Promise's.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const runtimePromise = <A, E>(self: FiberSet<A, E>): <R = never>() => Effect.Effect<
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
) => Promise<XA>,
|
||||
never,
|
||||
R
|
||||
> =>
|
||||
<R>() =>
|
||||
Effect.map(
|
||||
runtime(self)<R>(),
|
||||
(runFork) =>
|
||||
<XE extends E, XA extends A>(
|
||||
effect: Effect.Effect<XA, XE, R>,
|
||||
options?:
|
||||
| Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }
|
||||
| undefined
|
||||
): Promise<XA> =>
|
||||
new Promise((resolve, reject) =>
|
||||
runFork(effect, options).addObserver((exit) => {
|
||||
if (Exit.isSuccess(exit)) {
|
||||
resolve(exit.value)
|
||||
} else {
|
||||
reject(Cause.squash(exit.cause))
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const size = <A, E>(self: FiberSet<A, E>): Effect.Effect<number> =>
|
||||
Effect.sync(() => self.state._tag === "Closed" ? 0 : self.state.backing.size)
|
||||
|
||||
/**
|
||||
* Join all fibers in the FiberSet. If any of the Fiber's in the set terminate with a failure,
|
||||
* the returned Effect will terminate with the first failure that occurred.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @categories combinators
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, FiberSet } from "effect";
|
||||
*
|
||||
* Effect.gen(function* (_) {
|
||||
* const set = yield* _(FiberSet.make());
|
||||
* yield* _(FiberSet.add(set, Effect.runFork(Effect.fail("error"))));
|
||||
*
|
||||
* // parent fiber will fail with "error"
|
||||
* yield* _(FiberSet.join(set));
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const join = <A, E>(self: FiberSet<A, E>): Effect.Effect<void, E> =>
|
||||
Deferred.await(self.deferred as Deferred.Deferred<void, E>)
|
||||
|
||||
/**
|
||||
* Wait until the fiber set is empty.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @categories combinators
|
||||
*/
|
||||
export const awaitEmpty = <A, E>(self: FiberSet<A, E>): Effect.Effect<void> =>
|
||||
Effect.whileLoop({
|
||||
while: () => self.state._tag === "Open" && self.state.backing.size > 0,
|
||||
body: () => Fiber.await(Iterable.unsafeHead(self)),
|
||||
step: constVoid
|
||||
})
|
||||
108
_node_modules/effect/src/FiberStatus.ts
generated
Normal file
108
_node_modules/effect/src/FiberStatus.ts
generated
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Equal from "./Equal.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import * as internal from "./internal/fiberStatus.js"
|
||||
import type * as RuntimeFlags from "./RuntimeFlags.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FiberStatusTypeId: unique symbol = internal.FiberStatusTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FiberStatusTypeId = typeof FiberStatusTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type FiberStatus = Done | Running | Suspended
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Done extends Equal.Equal {
|
||||
readonly _tag: "Done"
|
||||
readonly [FiberStatusTypeId]: FiberStatusTypeId
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Running extends Equal.Equal {
|
||||
readonly _tag: "Running"
|
||||
readonly [FiberStatusTypeId]: FiberStatusTypeId
|
||||
readonly runtimeFlags: RuntimeFlags.RuntimeFlags
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Suspended extends Equal.Equal {
|
||||
readonly _tag: "Suspended"
|
||||
readonly [FiberStatusTypeId]: FiberStatusTypeId
|
||||
readonly runtimeFlags: RuntimeFlags.RuntimeFlags
|
||||
readonly blockingOn: FiberId.FiberId
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const done: FiberStatus = internal.done
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const running: (runtimeFlags: RuntimeFlags.RuntimeFlags) => FiberStatus = internal.running
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const suspended: (runtimeFlags: RuntimeFlags.RuntimeFlags, blockingOn: FiberId.FiberId) => FiberStatus =
|
||||
internal.suspended
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `FiberStatus`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFiberStatus: (u: unknown) => u is FiberStatus = internal.isFiberStatus
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `FiberStatus` is `Done`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isDone: (self: FiberStatus) => self is Done = internal.isDone
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `FiberStatus` is `Running`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isRunning: (self: FiberStatus) => self is Running = internal.isRunning
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `FiberStatus` is `Suspended`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSuspended: (self: FiberStatus) => self is Suspended = internal.isSuspended
|
||||
1378
_node_modules/effect/src/Function.ts
generated
Normal file
1378
_node_modules/effect/src/Function.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
_node_modules/effect/src/GlobalValue.ts
generated
Normal file
53
_node_modules/effect/src/GlobalValue.ts
generated
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* The `GlobalValue` module ensures that a single instance of a value is created globally,
|
||||
* even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds)
|
||||
* or during hot-reloading in development environments like Next.js or Remix.
|
||||
*
|
||||
* It achieves this by using a versioned global store, identified by a unique `Symbol` tied to
|
||||
* the current version of the `effect` library. The store holds values that are keyed by an identifier,
|
||||
* allowing the reuse of previously computed instances across imports or reloads.
|
||||
*
|
||||
* This pattern is particularly useful in scenarios where frequent reloading can cause services or
|
||||
* single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
const globalStoreId = `effect/GlobalValue`
|
||||
|
||||
let globalStore: Map<unknown, any>
|
||||
|
||||
/**
|
||||
* Retrieves or computes a global value associated with the given `id`. If the value for this `id`
|
||||
* has already been computed, it will be returned from the global store. If it does not exist yet,
|
||||
* the provided `compute` function will be executed to compute the value, store it, and then return it.
|
||||
*
|
||||
* This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments
|
||||
* like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused
|
||||
* thereafter.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { globalValue } from "effect/GlobalValue"
|
||||
*
|
||||
* // This cache will persist as long as the module is running,
|
||||
* // even if reloaded or imported elsewhere
|
||||
* const myCache = globalValue(
|
||||
* Symbol.for("myCache"),
|
||||
* () => new WeakMap<object, number>()
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const globalValue = <A>(id: unknown, compute: () => A): A => {
|
||||
if (!globalStore) {
|
||||
// @ts-expect-error
|
||||
globalThis[globalStoreId] ??= new Map()
|
||||
// @ts-expect-error
|
||||
globalStore = globalThis[globalStoreId] as Map<unknown, any>
|
||||
}
|
||||
if (!globalStore.has(id)) {
|
||||
globalStore.set(id, compute())
|
||||
}
|
||||
return globalStore.get(id)!
|
||||
}
|
||||
3564
_node_modules/effect/src/Graph.ts
generated
Normal file
3564
_node_modules/effect/src/Graph.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
141
_node_modules/effect/src/GroupBy.ts
generated
Normal file
141
_node_modules/effect/src/GroupBy.ts
generated
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/groupBy.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type { Predicate } from "./Predicate.js"
|
||||
import type * as Queue from "./Queue.js"
|
||||
import type * as Stream from "./Stream.js"
|
||||
import type * as Take from "./Take.js"
|
||||
import type { Covariant, NoInfer } from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const GroupByTypeId: unique symbol = internal.GroupByTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type GroupByTypeId = typeof GroupByTypeId
|
||||
|
||||
/**
|
||||
* Representation of a grouped stream. This allows to filter which groups will
|
||||
* be processed. Once this is applied all groups will be processed in parallel
|
||||
* and the results will be merged in arbitrary order.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface GroupBy<out K, out V, out E = never, out R = never> extends GroupBy.Variance<K, V, E, R>, Pipeable {
|
||||
readonly grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<V, E>>], E, R>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace GroupBy {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out K, out V, out E, out R> {
|
||||
readonly [GroupByTypeId]: {
|
||||
readonly _K: Covariant<K>
|
||||
readonly _V: Covariant<V>
|
||||
readonly _E: Covariant<E>
|
||||
readonly _R: Covariant<R>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the function across all groups, collecting the results in an
|
||||
* arbitrary order.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const evaluate: {
|
||||
/**
|
||||
* Run the function across all groups, collecting the results in an
|
||||
* arbitrary order.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
<K, V, E, A, E2, R2>(
|
||||
f: (key: K, stream: Stream.Stream<V, E, never>) => Stream.Stream<A, E2, R2>,
|
||||
options?: { readonly bufferSize?: number | undefined } | undefined
|
||||
): <R>(self: GroupBy<K, V, E, R>) => Stream.Stream<A, E | E2, R2 | R>
|
||||
/**
|
||||
* Run the function across all groups, collecting the results in an
|
||||
* arbitrary order.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
<K, V, E, R, A, E2, R2>(
|
||||
self: GroupBy<K, V, E, R>,
|
||||
f: (key: K, stream: Stream.Stream<V, E, never>) => Stream.Stream<A, E2, R2>,
|
||||
options?: { readonly bufferSize?: number | undefined } | undefined
|
||||
): Stream.Stream<A, E | E2, R | R2>
|
||||
} = internal.evaluate
|
||||
|
||||
/**
|
||||
* Filter the groups to be processed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const filter: {
|
||||
/**
|
||||
* Filter the groups to be processed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<K>(predicate: Predicate<NoInfer<K>>): <V, E, R>(self: GroupBy<K, V, E, R>) => GroupBy<K, V, E, R>
|
||||
/**
|
||||
* Filter the groups to be processed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<K, V, E, R>(self: GroupBy<K, V, E, R>, predicate: Predicate<K>): GroupBy<K, V, E, R>
|
||||
} = internal.filter
|
||||
|
||||
/**
|
||||
* Only consider the first `n` groups found in the `Stream`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const first: {
|
||||
/**
|
||||
* Only consider the first `n` groups found in the `Stream`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(n: number): <K, V, E, R>(self: GroupBy<K, V, E, R>) => GroupBy<K, V, E, R>
|
||||
/**
|
||||
* Only consider the first `n` groups found in the `Stream`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<K, V, E, R>(self: GroupBy<K, V, E, R>, n: number): GroupBy<K, V, E, R>
|
||||
} = internal.first
|
||||
|
||||
/**
|
||||
* Constructs a `GroupBy` from a `Stream`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <K, V, E, R>(
|
||||
grouped: Stream.Stream<readonly [K, Queue.Dequeue<Take.Take<V, E>>], E, R>
|
||||
) => GroupBy<K, V, E, R> = internal.make
|
||||
45
_node_modules/effect/src/HKT.ts
generated
Normal file
45
_node_modules/effect/src/HKT.ts
generated
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare const URI: unique symbol
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface TypeClass<F extends TypeLambda> {
|
||||
readonly [URI]?: F
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface TypeLambda {
|
||||
readonly In: unknown
|
||||
readonly Out2: unknown
|
||||
readonly Out1: unknown
|
||||
readonly Target: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Kind<F extends TypeLambda, In, Out2, Out1, Target> = F extends {
|
||||
readonly type: unknown
|
||||
} ? (F & {
|
||||
readonly In: In
|
||||
readonly Out2: Out2
|
||||
readonly Out1: Out1
|
||||
readonly Target: Target
|
||||
})["type"]
|
||||
: {
|
||||
readonly F: F
|
||||
readonly In: Types.Contravariant<In>
|
||||
readonly Out2: Types.Covariant<Out2>
|
||||
readonly Out1: Types.Covariant<Out1>
|
||||
readonly Target: Types.Invariant<Target>
|
||||
}
|
||||
200
_node_modules/effect/src/Hash.ts
generated
Normal file
200
_node_modules/effect/src/Hash.ts
generated
Normal file
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import { pipe } from "./Function.js"
|
||||
import { globalValue } from "./GlobalValue.js"
|
||||
import { hasProperty } from "./Predicate.js"
|
||||
import { structuralRegionState } from "./Utils.js"
|
||||
|
||||
/** @internal */
|
||||
const randomHashCache = globalValue(
|
||||
Symbol.for("effect/Hash/randomHashCache"),
|
||||
() => new WeakMap<object, number>()
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const symbol: unique symbol = Symbol.for("effect/Hash")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Hash {
|
||||
[symbol](): number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const hash: <A>(self: A) => number = <A>(self: A) => {
|
||||
if (structuralRegionState.enabled === true) {
|
||||
return 0
|
||||
}
|
||||
|
||||
switch (typeof self) {
|
||||
case "number":
|
||||
return number(self)
|
||||
case "bigint":
|
||||
return string(self.toString(10))
|
||||
case "boolean":
|
||||
return string(String(self))
|
||||
case "symbol":
|
||||
return string(String(self))
|
||||
case "string":
|
||||
return string(self)
|
||||
case "undefined":
|
||||
return string("undefined")
|
||||
case "function":
|
||||
case "object": {
|
||||
if (self === null) {
|
||||
return string("null")
|
||||
} else if (self instanceof Date) {
|
||||
return hash(self.toISOString())
|
||||
} else if (self instanceof URL) {
|
||||
return hash(self.href)
|
||||
} else if (isHash(self)) {
|
||||
return self[symbol]()
|
||||
} else {
|
||||
return random(self)
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new Error(
|
||||
`BUG: unhandled typeof ${typeof self} - please report an issue at https://github.com/Effect-TS/effect/issues`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const random: <A extends object>(self: A) => number = (self) => {
|
||||
if (!randomHashCache.has(self)) {
|
||||
randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)))
|
||||
}
|
||||
return randomHashCache.get(self)!
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const combine: (b: number) => (self: number) => number = (b) => (self) => (self * 53) ^ b
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const optimize = (n: number): number => (n & 0xbfffffff) | ((n >>> 1) & 0x40000000)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isHash = (u: unknown): u is Hash => hasProperty(u, symbol)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const number = (n: number) => {
|
||||
if (n !== n || n === Infinity) {
|
||||
return 0
|
||||
}
|
||||
let h = n | 0
|
||||
if (h !== n) {
|
||||
h ^= n * 0xffffffff
|
||||
}
|
||||
while (n > 0xffffffff) {
|
||||
h ^= n /= 0xffffffff
|
||||
}
|
||||
return optimize(h)
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const string = (str: string) => {
|
||||
let h = 5381, i = str.length
|
||||
while (i) {
|
||||
h = (h * 33) ^ str.charCodeAt(--i)
|
||||
}
|
||||
return optimize(h)
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const structureKeys = <A extends object>(o: A, keys: ReadonlyArray<keyof A>) => {
|
||||
let h = 12289
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
h ^= pipe(string(keys[i]! as string), combine(hash((o as any)[keys[i]!])))
|
||||
}
|
||||
return optimize(h)
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const structure = <A extends object>(o: A) =>
|
||||
structureKeys(o, Object.keys(o) as unknown as ReadonlyArray<keyof A>)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const array = <A>(arr: ReadonlyArray<A>) => {
|
||||
let h = 6151
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
h = pipe(h, combine(hash(arr[i])))
|
||||
}
|
||||
return optimize(h)
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
export const cached: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
(self: object): (hash: number) => number
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category hashing
|
||||
*/
|
||||
(self: object, hash: number): number
|
||||
} = function() {
|
||||
if (arguments.length === 1) {
|
||||
const self = arguments[0] as object
|
||||
return function(hash: number) {
|
||||
Object.defineProperty(self, symbol, {
|
||||
value() {
|
||||
return hash
|
||||
},
|
||||
enumerable: false
|
||||
})
|
||||
return hash
|
||||
} as any
|
||||
}
|
||||
const self = arguments[0] as object
|
||||
const hash = arguments[1] as number
|
||||
Object.defineProperty(self, symbol, {
|
||||
value() {
|
||||
return hash
|
||||
},
|
||||
enumerable: false
|
||||
})
|
||||
|
||||
return hash
|
||||
}
|
||||
919
_node_modules/effect/src/HashMap.ts
generated
Normal file
919
_node_modules/effect/src/HashMap.ts
generated
Normal file
@@ -0,0 +1,919 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
import type { Equal } from "./Equal.js"
|
||||
import type { HashSet } from "./HashSet.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import * as HM from "./internal/hashMap.js"
|
||||
import * as keySet_ from "./internal/hashMap/keySet.js"
|
||||
import type { Option } from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type { NoInfer } from "./Types.js"
|
||||
|
||||
const TypeId: unique symbol = HM.HashMapTypeId as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface HashMap<out Key, out Value> extends Iterable<[Key, Value]>, Equal, Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace HashMap {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type UpdateFn<V> = (option: Option<V>) => Option<V>
|
||||
/**
|
||||
* This type-level utility extracts the key type `K` from a `HashMap<K, V>` type.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* declare const hm: HashMap.HashMap<string, number>
|
||||
*
|
||||
* // $ExpectType string
|
||||
* type K = HashMap.HashMap.Key<typeof hm>
|
||||
*
|
||||
* ```
|
||||
* @since 2.0.0
|
||||
* @category type-level
|
||||
*/
|
||||
export type Key<T extends HashMap<any, any>> = [T] extends [HashMap<infer _K, infer _V>] ? _K : never
|
||||
/**
|
||||
* This type-level utility extracts the value type `V` from a `HashMap<K, V>` type.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* declare const hm: HashMap.HashMap<string, number>
|
||||
*
|
||||
* // $ExpectType number
|
||||
* type V = HashMap.HashMap.Value<typeof hm>
|
||||
*
|
||||
* ```
|
||||
* @since 2.0.0
|
||||
* @category type-level
|
||||
*/
|
||||
export type Value<T extends HashMap<any, any>> = [T] extends [HashMap<infer _K, infer _V>] ? _V : never
|
||||
|
||||
/**
|
||||
* This type-level utility extracts the entry type `[K, V]` from a `HashMap<K, V>` type.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* declare const hm: HashMap.HashMap<string, number>
|
||||
*
|
||||
* // $ExpectType [string, number]
|
||||
* type V = HashMap.HashMap.Entry<typeof hm>
|
||||
*
|
||||
* ```
|
||||
* @since 3.9.0
|
||||
* @category type-level
|
||||
*/
|
||||
export type Entry<T extends HashMap<any, any>> = [Key<T>, Value<T>]
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isHashMap: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
<K, V>(u: Iterable<readonly [K, V]>): u is HashMap<K, V>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
(u: unknown): u is HashMap<unknown, unknown>
|
||||
} = HM.isHashMap
|
||||
|
||||
/**
|
||||
* Creates a new `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty: <K = never, V = never>() => HashMap<K, V> = HM.empty
|
||||
|
||||
/**
|
||||
* Constructs a new `HashMap` from an array of key/value pairs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Entries extends ReadonlyArray<readonly [any, any]>>(
|
||||
...entries: Entries
|
||||
) => HashMap<
|
||||
Entries[number] extends readonly [infer K, any] ? K : never,
|
||||
Entries[number] extends readonly [any, infer V] ? V : never
|
||||
> = HM.make
|
||||
|
||||
/**
|
||||
* Creates a new `HashMap` from an iterable collection of key/value pairs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromIterable: <K, V>(entries: Iterable<readonly [K, V]>) => HashMap<K, V> = HM.fromIterable
|
||||
|
||||
/**
|
||||
* Checks if the `HashMap` contains any entries.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const isEmpty: <K, V>(self: HashMap<K, V>) => boolean = HM.isEmpty
|
||||
|
||||
/**
|
||||
* Safely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* Safely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K>(key: K1): <V>(self: HashMap<K, V>) => Option<V>
|
||||
/**
|
||||
* Safely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): Option<V>
|
||||
} = HM.get
|
||||
|
||||
/**
|
||||
* Lookup the value for the specified key in the `HashMap` using a custom hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const getHash: {
|
||||
/**
|
||||
* Lookup the value for the specified key in the `HashMap` using a custom hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => Option<V>
|
||||
/**
|
||||
* Lookup the value for the specified key in the `HashMap` using a custom hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): Option<V>
|
||||
} = HM.getHash
|
||||
|
||||
/**
|
||||
* Unsafely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeGet: {
|
||||
/**
|
||||
* Unsafely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
<K1 extends K, K>(key: K1): <V>(self: HashMap<K, V>) => V
|
||||
/**
|
||||
* Unsafely lookup the value for the specified key in the `HashMap` using the
|
||||
* internal hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): V
|
||||
} = HM.unsafeGet
|
||||
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const has: {
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K>(key: K1): <K, V>(self: HashMap<K, V>) => boolean
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): boolean
|
||||
} = HM.has
|
||||
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap` using a custom
|
||||
* hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const hasHash: {
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap` using a custom
|
||||
* hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => boolean
|
||||
/**
|
||||
* Checks if the specified key has an entry in the `HashMap` using a custom
|
||||
* hash.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): boolean
|
||||
} = HM.hasHash
|
||||
|
||||
/**
|
||||
* Checks if an element matching the given predicate exists in the given `HashMap`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const hm = HashMap.make([1, 'a'])
|
||||
* HashMap.hasBy(hm, (value, key) => value === 'a' && key === 1); // -> true
|
||||
* HashMap.hasBy(hm, (value) => value === 'b'); // -> false
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category elements
|
||||
*/
|
||||
export const hasBy: {
|
||||
/**
|
||||
* Checks if an element matching the given predicate exists in the given `HashMap`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const hm = HashMap.make([1, 'a'])
|
||||
* HashMap.hasBy(hm, (value, key) => value === 'a' && key === 1); // -> true
|
||||
* HashMap.hasBy(hm, (value) => value === 'b'); // -> false
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean): (self: HashMap<K, V>) => boolean
|
||||
/**
|
||||
* Checks if an element matching the given predicate exists in the given `HashMap`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const hm = HashMap.make([1, 'a'])
|
||||
* HashMap.hasBy(hm, (value, key) => value === 'a' && key === 1); // -> true
|
||||
* HashMap.hasBy(hm, (value) => value === 'b'); // -> false
|
||||
*
|
||||
* ```
|
||||
*
|
||||
* @since 3.16.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(
|
||||
self: HashMap<K, V>,
|
||||
predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean
|
||||
): boolean
|
||||
} = HM.hasBy
|
||||
|
||||
/**
|
||||
* Sets the specified key to the specified value using the internal hashing
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* Sets the specified key to the specified value using the internal hashing
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, value: V): (self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Sets the specified key to the specified value using the internal hashing
|
||||
* function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, key: K, value: V): HashMap<K, V>
|
||||
} = HM.set
|
||||
|
||||
/**
|
||||
* Returns an `IterableIterator` of the keys within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const keys: <K, V>(self: HashMap<K, V>) => IterableIterator<K> = HM.keys
|
||||
|
||||
/**
|
||||
* Returns a `HashSet` of keys within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getter
|
||||
*/
|
||||
export const keySet: <K, V>(self: HashMap<K, V>) => HashSet<K> = keySet_.keySet
|
||||
|
||||
/**
|
||||
* Returns an `IterableIterator` of the values within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const values: <K, V>(self: HashMap<K, V>) => IterableIterator<V> = HM.values
|
||||
|
||||
/**
|
||||
* Returns an `Array` of the values within the `HashMap`.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @category getters
|
||||
*/
|
||||
export const toValues = <K, V>(self: HashMap<K, V>): Array<V> => Array.from(values(self))
|
||||
|
||||
/**
|
||||
* Returns an `IterableIterator` of the entries within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const entries: <K, V>(self: HashMap<K, V>) => IterableIterator<[K, V]> = HM.entries
|
||||
|
||||
/**
|
||||
* Returns an `Array<[K, V]>` of the entries within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const toEntries = <K, V>(self: HashMap<K, V>): Array<[K, V]> => Array.from(entries(self))
|
||||
|
||||
/**
|
||||
* Returns the number of entries within the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const size: <K, V>(self: HashMap<K, V>) => number = HM.size
|
||||
|
||||
/**
|
||||
* Counts all the element of the given HashMap that pass the given predicate
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const map = HashMap.make([1, "a"], [2, "b"], [3, "c"])
|
||||
* const result = HashMap.countBy(map, (_v, key) => key % 2 === 1)
|
||||
* console.log(result) // 2
|
||||
* ```
|
||||
*
|
||||
* @since 3.17.0
|
||||
* @category folding
|
||||
*/
|
||||
export const countBy: {
|
||||
/**
|
||||
* Counts all the element of the given HashMap that pass the given predicate
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const map = HashMap.make([1, "a"], [2, "b"], [3, "c"])
|
||||
* const result = HashMap.countBy(map, (_v, key) => key % 2 === 1)
|
||||
* console.log(result) // 2
|
||||
* ```
|
||||
*
|
||||
* @since 3.17.0
|
||||
* @category folding
|
||||
*/
|
||||
<K, V>(predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean): (self: HashMap<K, V>) => number
|
||||
/**
|
||||
* Counts all the element of the given HashMap that pass the given predicate
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* ```ts
|
||||
* import { HashMap } from "effect"
|
||||
*
|
||||
* const map = HashMap.make([1, "a"], [2, "b"], [3, "c"])
|
||||
* const result = HashMap.countBy(map, (_v, key) => key % 2 === 1)
|
||||
* console.log(result) // 2
|
||||
* ```
|
||||
*
|
||||
* @since 3.17.0
|
||||
* @category folding
|
||||
*/
|
||||
<K, V>(
|
||||
self: HashMap<K, V>,
|
||||
predicate: (value: NoInfer<V>, key: NoInfer<K>) => boolean
|
||||
): number
|
||||
} = HM.countBy
|
||||
|
||||
/**
|
||||
* Marks the `HashMap` as mutable.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const beginMutation: <K, V>(self: HashMap<K, V>) => HashMap<K, V> = HM.beginMutation
|
||||
|
||||
/**
|
||||
* Marks the `HashMap` as immutable.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const endMutation: <K, V>(self: HashMap<K, V>) => HashMap<K, V> = HM.endMutation
|
||||
|
||||
/**
|
||||
* Mutates the `HashMap` within the context of the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const mutate: {
|
||||
/**
|
||||
* Mutates the `HashMap` within the context of the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(f: (self: HashMap<K, V>) => void): (self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Mutates the `HashMap` within the context of the provided function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, f: (self: HashMap<K, V>) => void): HashMap<K, V>
|
||||
} = HM.mutate
|
||||
|
||||
/**
|
||||
* Set or remove the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const modifyAt: {
|
||||
/**
|
||||
* Set or remove the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Set or remove the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>
|
||||
} = HM.modifyAt
|
||||
|
||||
/**
|
||||
* Alter the value of the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* This function will always either update or insert a value into the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const modifyHash: {
|
||||
/**
|
||||
* Alter the value of the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* This function will always either update or insert a value into the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, hash: number, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Alter the value of the specified key in the `HashMap` using the specified
|
||||
* update function. The value of the specified key will be computed using the
|
||||
* provided hash.
|
||||
*
|
||||
* The update function will be invoked with the current value of the key if it
|
||||
* exists, or `None` if no such value exists.
|
||||
*
|
||||
* This function will always either update or insert a value into the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: HashMap.UpdateFn<V>): HashMap<K, V>
|
||||
} = HM.modifyHash
|
||||
|
||||
/**
|
||||
* Updates the value of the specified key within the `HashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const modify: {
|
||||
/**
|
||||
* Updates the value of the specified key within the `HashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: (v: V) => V): (self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Updates the value of the specified key within the `HashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, key: K, f: (v: V) => V): HashMap<K, V>
|
||||
} = HM.modify
|
||||
|
||||
/**
|
||||
* Performs a union of this `HashMap` and that `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const union: {
|
||||
/**
|
||||
* Performs a union of this `HashMap` and that `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K1, V1>(that: HashMap<K1, V1>): <K0, V0>(self: HashMap<K0, V0>) => HashMap<K1 | K0, V1 | V0>
|
||||
/**
|
||||
* Performs a union of this `HashMap` and that `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K0, V0, K1, V1>(self: HashMap<K0, V0>, that: HashMap<K1, V1>): HashMap<K0 | K1, V0 | V1>
|
||||
} = HM.union
|
||||
|
||||
/**
|
||||
* Remove the entry for the specified key in the `HashMap` using the internal
|
||||
* hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const remove: {
|
||||
/**
|
||||
* Remove the entry for the specified key in the `HashMap` using the internal
|
||||
* hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K>(key: K): <V>(self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Remove the entry for the specified key in the `HashMap` using the internal
|
||||
* hashing function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, key: K): HashMap<K, V>
|
||||
} = HM.remove
|
||||
|
||||
/**
|
||||
* Removes all entries in the `HashMap` which have the specified keys.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const removeMany: {
|
||||
/**
|
||||
* Removes all entries in the `HashMap` which have the specified keys.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K>(keys: Iterable<K>): <V>(self: HashMap<K, V>) => HashMap<K, V>
|
||||
/**
|
||||
* Removes all entries in the `HashMap` which have the specified keys.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: HashMap<K, V>, keys: Iterable<K>): HashMap<K, V>
|
||||
} = HM.removeMany
|
||||
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const map: {
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<A, V, K>(f: (value: V, key: K) => A): (self: HashMap<K, V>) => HashMap<K, A>
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<K, V, A>(self: HashMap<K, V>, f: (value: V, key: K) => A): HashMap<K, A>
|
||||
} = HM.map
|
||||
|
||||
/**
|
||||
* Chains over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* **NOTE**: the hash and equal of both maps have to be the same.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
export const flatMap: {
|
||||
/**
|
||||
* Chains over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* **NOTE**: the hash and equal of both maps have to be the same.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<A, K, B>(f: (value: A, key: K) => HashMap<K, B>): (self: HashMap<K, A>) => HashMap<K, B>
|
||||
/**
|
||||
* Chains over the entries of the `HashMap` using the specified function.
|
||||
*
|
||||
* **NOTE**: the hash and equal of both maps have to be the same.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category sequencing
|
||||
*/
|
||||
<K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => HashMap<K, B>): HashMap<K, B>
|
||||
} = HM.flatMap
|
||||
|
||||
/**
|
||||
* Applies the specified function to the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
export const forEach: {
|
||||
/**
|
||||
* Applies the specified function to the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<V, K>(f: (value: V, key: K) => void): (self: HashMap<K, V>) => void
|
||||
/**
|
||||
* Applies the specified function to the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<V, K>(self: HashMap<K, V>, f: (value: V, key: K) => void): void
|
||||
} = HM.forEach
|
||||
|
||||
/**
|
||||
* Reduces the specified state over the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const reduce: {
|
||||
/**
|
||||
* Reduces the specified state over the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<Z, V, K>(zero: Z, f: (accumulator: Z, value: V, key: K) => Z): (self: HashMap<K, V>) => Z
|
||||
/**
|
||||
* Reduces the specified state over the entries of the `HashMap`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<K, V, Z>(self: HashMap<K, V>, zero: Z, f: (accumulator: Z, value: V, key: K) => Z): Z
|
||||
} = HM.reduce
|
||||
|
||||
/**
|
||||
* Filters entries out of a `HashMap` using the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
export const filter: {
|
||||
/**
|
||||
* Filters entries out of a `HashMap` using the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<K, A, B extends A>(f: (a: NoInfer<A>, k: K) => a is B): (self: HashMap<K, A>) => HashMap<K, B>
|
||||
/**
|
||||
* Filters entries out of a `HashMap` using the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<K, A>(f: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => HashMap<K, A>
|
||||
/**
|
||||
* Filters entries out of a `HashMap` using the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<K, A, B extends A>(self: HashMap<K, A>, f: (a: A, k: K) => a is B): HashMap<K, B>
|
||||
/**
|
||||
* Filters entries out of a `HashMap` using the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<K, A>(self: HashMap<K, A>, f: (a: A, k: K) => boolean): HashMap<K, A>
|
||||
} = HM.filter
|
||||
|
||||
/**
|
||||
* Filters out `None` values from a `HashMap` of `Options`s.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
export const compact: <K, A>(self: HashMap<K, Option<A>>) => HashMap<K, A> = HM.compact
|
||||
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified partial function
|
||||
* and filters out `None` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
export const filterMap: {
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified partial function
|
||||
* and filters out `None` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<A, K, B>(f: (value: A, key: K) => Option<B>): (self: HashMap<K, A>) => HashMap<K, B>
|
||||
/**
|
||||
* Maps over the entries of the `HashMap` using the specified partial function
|
||||
* and filters out `None` values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => Option<B>): HashMap<K, B>
|
||||
} = HM.filterMap
|
||||
|
||||
/**
|
||||
* Returns the first element that satisfies the specified
|
||||
* predicate, or `None` if no such element exists.
|
||||
*
|
||||
* @category elements
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const findFirst: {
|
||||
/**
|
||||
* Returns the first element that satisfies the specified
|
||||
* predicate, or `None` if no such element exists.
|
||||
*
|
||||
* @category elements
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, A, B extends A>(predicate: (a: NoInfer<A>, k: K) => a is B): (self: HashMap<K, A>) => Option<[K, B]>
|
||||
/**
|
||||
* Returns the first element that satisfies the specified
|
||||
* predicate, or `None` if no such element exists.
|
||||
*
|
||||
* @category elements
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => Option<[K, A]>
|
||||
/**
|
||||
* Returns the first element that satisfies the specified
|
||||
* predicate, or `None` if no such element exists.
|
||||
*
|
||||
* @category elements
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, A, B extends A>(self: HashMap<K, A>, predicate: (a: A, k: K) => a is B): Option<[K, B]>
|
||||
/**
|
||||
* Returns the first element that satisfies the specified
|
||||
* predicate, or `None` if no such element exists.
|
||||
*
|
||||
* @category elements
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option<[K, A]>
|
||||
} = HM.findFirst
|
||||
|
||||
/**
|
||||
* Checks if any entry in a hashmap meets a specific condition.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @category elements
|
||||
*/
|
||||
export const some: {
|
||||
/**
|
||||
* Checks if any entry in a hashmap meets a specific condition.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => boolean
|
||||
/**
|
||||
* Checks if any entry in a hashmap meets a specific condition.
|
||||
*
|
||||
* @since 3.13.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): boolean
|
||||
} = HM.some
|
||||
|
||||
/**
|
||||
* Checks if all entries in a hashmap meets a specific condition.
|
||||
*
|
||||
* @param self - The hashmap to check.
|
||||
* @param predicate - The condition to test entries (value, key).
|
||||
*
|
||||
* @since 3.14.0
|
||||
* @category elements
|
||||
*/
|
||||
export const every: {
|
||||
/**
|
||||
* Checks if all entries in a hashmap meets a specific condition.
|
||||
*
|
||||
* @param self - The hashmap to check.
|
||||
* @param predicate - The condition to test entries (value, key).
|
||||
*
|
||||
* @since 3.14.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => boolean
|
||||
/**
|
||||
* Checks if all entries in a hashmap meets a specific condition.
|
||||
*
|
||||
* @param self - The hashmap to check.
|
||||
* @param predicate - The condition to test entries (value, key).
|
||||
*
|
||||
* @since 3.14.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): boolean
|
||||
} = HM.every
|
||||
2346
_node_modules/effect/src/HashSet.ts
generated
Normal file
2346
_node_modules/effect/src/HashSet.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
174
_node_modules/effect/src/Inspectable.ts
generated
Normal file
174
_node_modules/effect/src/Inspectable.ts
generated
Normal file
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as FiberRefs from "./FiberRefs.js"
|
||||
import { globalValue } from "./GlobalValue.js"
|
||||
import { hasProperty, isFunction } from "./Predicate.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const NodeInspectSymbol = Symbol.for("nodejs.util.inspect.custom")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type NodeInspectSymbol = typeof NodeInspectSymbol
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Inspectable {
|
||||
toString(): string
|
||||
toJSON(): unknown
|
||||
[NodeInspectSymbol](): unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const toJSON = (x: unknown): unknown => {
|
||||
try {
|
||||
if (
|
||||
hasProperty(x, "toJSON") && isFunction(x["toJSON"]) &&
|
||||
x["toJSON"].length === 0
|
||||
) {
|
||||
return x.toJSON()
|
||||
} else if (Array.isArray(x)) {
|
||||
return x.map(toJSON)
|
||||
}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
return redact(x)
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const format = (x: unknown): string => JSON.stringify(x, null, 2)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const BaseProto: Inspectable = {
|
||||
toJSON() {
|
||||
return toJSON(this)
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export abstract class Class {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
abstract toJSON(): unknown
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
}
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const toStringUnknown = (u: unknown, whitespace: number | string | undefined = 2): string => {
|
||||
if (typeof u === "string") {
|
||||
return u
|
||||
}
|
||||
try {
|
||||
return typeof u === "object" ? stringifyCircular(u, whitespace) : String(u)
|
||||
} catch {
|
||||
return String(u)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const stringifyCircular = (obj: unknown, whitespace?: number | string | undefined): string => {
|
||||
let cache: Array<unknown> = []
|
||||
const retVal = JSON.stringify(
|
||||
obj,
|
||||
(_key, value) =>
|
||||
typeof value === "object" && value !== null
|
||||
? cache.includes(value)
|
||||
? undefined // circular reference
|
||||
: cache.push(value) && (redactableState.fiberRefs !== undefined && isRedactable(value)
|
||||
? value[symbolRedactable](redactableState.fiberRefs)
|
||||
: value)
|
||||
: value,
|
||||
whitespace
|
||||
)
|
||||
;(cache as any) = undefined
|
||||
return retVal
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
* @category redactable
|
||||
*/
|
||||
export interface Redactable {
|
||||
readonly [symbolRedactable]: (fiberRefs: FiberRefs.FiberRefs) => unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
* @category redactable
|
||||
*/
|
||||
export const symbolRedactable: unique symbol = Symbol.for("effect/Inspectable/Redactable")
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
* @category redactable
|
||||
*/
|
||||
export const isRedactable = (u: unknown): u is Redactable =>
|
||||
typeof u === "object" && u !== null && symbolRedactable in u
|
||||
|
||||
const redactableState = globalValue("effect/Inspectable/redactableState", () => ({
|
||||
fiberRefs: undefined as FiberRefs.FiberRefs | undefined
|
||||
}))
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
* @category redactable
|
||||
*/
|
||||
export const withRedactableContext = <A>(context: FiberRefs.FiberRefs, f: () => A): A => {
|
||||
const prev = redactableState.fiberRefs
|
||||
redactableState.fiberRefs = context
|
||||
try {
|
||||
return f()
|
||||
} finally {
|
||||
redactableState.fiberRefs = prev
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
* @category redactable
|
||||
*/
|
||||
export const redact = (u: unknown): unknown => {
|
||||
if (isRedactable(u) && redactableState.fiberRefs !== undefined) {
|
||||
return u[symbolRedactable](redactableState.fiberRefs)
|
||||
}
|
||||
return u
|
||||
}
|
||||
1606
_node_modules/effect/src/Iterable.ts
generated
Normal file
1606
_node_modules/effect/src/Iterable.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
964
_node_modules/effect/src/JSONSchema.ts
generated
Normal file
964
_node_modules/effect/src/JSONSchema.ts
generated
Normal file
@@ -0,0 +1,964 @@
|
||||
/**
|
||||
* @since 3.10.0
|
||||
*/
|
||||
|
||||
import * as Arr from "./Array.js"
|
||||
import * as errors_ from "./internal/schema/errors.js"
|
||||
import * as schemaId_ from "./internal/schema/schemaId.js"
|
||||
import * as Option from "./Option.js"
|
||||
import * as ParseResult from "./ParseResult.js"
|
||||
import * as Predicate from "./Predicate.js"
|
||||
import * as Record from "./Record.js"
|
||||
import type * as Schema from "./Schema.js"
|
||||
import * as AST from "./SchemaAST.js"
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchemaAnnotations {
|
||||
title?: string
|
||||
description?: string
|
||||
default?: unknown
|
||||
examples?: Array<unknown>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.11.5
|
||||
*/
|
||||
export interface JsonSchema7Never extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/never"
|
||||
not: {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Any extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/any"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Unknown extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/unknown"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Void extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/void"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7object extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/object"
|
||||
anyOf: [
|
||||
{ type: "object" },
|
||||
{ type: "array" }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7empty extends JsonSchemaAnnotations {
|
||||
$id: "/schemas/%7B%7D"
|
||||
anyOf: [
|
||||
{ type: "object" },
|
||||
{ type: "array" }
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Ref extends JsonSchemaAnnotations {
|
||||
$ref: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.11.7
|
||||
*/
|
||||
export interface JsonSchema7Null extends JsonSchemaAnnotations {
|
||||
type: "null"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7String extends JsonSchemaAnnotations {
|
||||
type: "string"
|
||||
minLength?: number
|
||||
maxLength?: number
|
||||
pattern?: string
|
||||
format?: string
|
||||
contentMediaType?: string
|
||||
allOf?: Array<{
|
||||
minLength?: number
|
||||
maxLength?: number
|
||||
pattern?: string
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Numeric extends JsonSchemaAnnotations {
|
||||
minimum?: number
|
||||
exclusiveMinimum?: number
|
||||
maximum?: number
|
||||
exclusiveMaximum?: number
|
||||
multipleOf?: number
|
||||
allOf?: Array<{
|
||||
minimum?: number
|
||||
exclusiveMinimum?: number
|
||||
maximum?: number
|
||||
exclusiveMaximum?: number
|
||||
multipleOf?: number
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Number extends JsonSchema7Numeric {
|
||||
type: "number"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Integer extends JsonSchema7Numeric {
|
||||
type: "integer"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Boolean extends JsonSchemaAnnotations {
|
||||
type: "boolean"
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Array extends JsonSchemaAnnotations {
|
||||
type: "array"
|
||||
items?: JsonSchema7 | Array<JsonSchema7>
|
||||
minItems?: number
|
||||
maxItems?: number
|
||||
additionalItems?: JsonSchema7 | boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Enum extends JsonSchemaAnnotations {
|
||||
type?: "string" | "number" | "boolean"
|
||||
enum: Array<string | number | boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Enums extends JsonSchemaAnnotations {
|
||||
$comment: "/schemas/enums"
|
||||
anyOf: Array<{
|
||||
type: "string" | "number"
|
||||
title: string
|
||||
enum: [string | number]
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7AnyOf extends JsonSchemaAnnotations {
|
||||
anyOf: Array<JsonSchema7>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface JsonSchema7Object extends JsonSchemaAnnotations {
|
||||
type: "object"
|
||||
required: Array<string>
|
||||
properties: Record<string, JsonSchema7>
|
||||
additionalProperties?: boolean | JsonSchema7
|
||||
patternProperties?: Record<string, JsonSchema7>
|
||||
propertyNames?: JsonSchema7
|
||||
}
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export type JsonSchema7 =
|
||||
| JsonSchema7Never
|
||||
| JsonSchema7Any
|
||||
| JsonSchema7Unknown
|
||||
| JsonSchema7Void
|
||||
| JsonSchema7object
|
||||
| JsonSchema7empty
|
||||
| JsonSchema7Ref
|
||||
| JsonSchema7Null
|
||||
| JsonSchema7String
|
||||
| JsonSchema7Number
|
||||
| JsonSchema7Integer
|
||||
| JsonSchema7Boolean
|
||||
| JsonSchema7Array
|
||||
| JsonSchema7Enum
|
||||
| JsonSchema7Enums
|
||||
| JsonSchema7AnyOf
|
||||
| JsonSchema7Object
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export type JsonSchema7Root = JsonSchema7 & {
|
||||
$schema?: string
|
||||
$defs?: Record<string, JsonSchema7>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category encoding
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export const make = <A, I, R>(schema: Schema.Schema<A, I, R>): JsonSchema7Root => {
|
||||
const definitions: Record<string, any> = {}
|
||||
const ast = AST.isTransformation(schema.ast) && isParseJsonTransformation(schema.ast.from)
|
||||
// Special case top level `parseJson` transformations
|
||||
? schema.ast.to
|
||||
: schema.ast
|
||||
const jsonSchema = fromAST(ast, {
|
||||
definitions
|
||||
})
|
||||
const out: JsonSchema7Root = {
|
||||
$schema,
|
||||
$defs: {},
|
||||
...jsonSchema
|
||||
}
|
||||
if (Record.isEmptyRecord(definitions)) {
|
||||
delete out.$defs
|
||||
} else {
|
||||
out.$defs = definitions
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type Target = "jsonSchema7" | "jsonSchema2019-09" | "openApi3.1"
|
||||
|
||||
type TopLevelReferenceStrategy = "skip" | "keep"
|
||||
|
||||
type AdditionalPropertiesStrategy = "allow" | "strict"
|
||||
|
||||
/**
|
||||
* Returns a JSON Schema with additional options and definitions.
|
||||
*
|
||||
* **Warning**
|
||||
*
|
||||
* This function is experimental and subject to change.
|
||||
*
|
||||
* **Options**
|
||||
*
|
||||
* - `definitions`: A record of definitions that are included in the schema.
|
||||
* - `definitionPath`: The path to the definitions within the schema (defaults
|
||||
* to "#/$defs/").
|
||||
* - `target`: Which spec to target. Possible values are:
|
||||
* - `'jsonSchema7'`: JSON Schema draft-07 (default behavior).
|
||||
* - `'jsonSchema2019-09'`: JSON Schema draft-2019-09.
|
||||
* - `'openApi3.1'`: OpenAPI 3.1.
|
||||
* - `topLevelReferenceStrategy`: Controls the handling of the top-level
|
||||
* reference. Possible values are:
|
||||
* - `"keep"`: Keep the top-level reference (default behavior).
|
||||
* - `"skip"`: Skip the top-level reference.
|
||||
* - `additionalPropertiesStrategy`: Controls the handling of additional properties. Possible values are:
|
||||
* - `"strict"`: Disallow additional properties (default behavior).
|
||||
* - `"allow"`: Allow additional properties.
|
||||
*
|
||||
* @category encoding
|
||||
* @since 3.11.5
|
||||
* @experimental
|
||||
*/
|
||||
export const fromAST = (ast: AST.AST, options: {
|
||||
readonly definitions: Record<string, JsonSchema7>
|
||||
readonly definitionPath?: string | undefined
|
||||
readonly target?: Target | undefined
|
||||
readonly topLevelReferenceStrategy?: TopLevelReferenceStrategy | undefined
|
||||
readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy | undefined
|
||||
}): JsonSchema7 => {
|
||||
const definitionPath = options.definitionPath ?? "#/$defs/"
|
||||
const getRef = (id: string) => definitionPath + id
|
||||
const target = options.target ?? "jsonSchema7"
|
||||
const topLevelReferenceStrategy = options.topLevelReferenceStrategy ?? "keep"
|
||||
const additionalPropertiesStrategy = options.additionalPropertiesStrategy ?? "strict"
|
||||
return go(
|
||||
ast,
|
||||
options.definitions,
|
||||
"handle-identifier",
|
||||
[],
|
||||
{
|
||||
getRef,
|
||||
target,
|
||||
topLevelReferenceStrategy,
|
||||
additionalPropertiesStrategy
|
||||
},
|
||||
"handle-annotation",
|
||||
"handle-errors"
|
||||
)
|
||||
}
|
||||
|
||||
const constNever: JsonSchema7Never = {
|
||||
$id: "/schemas/never",
|
||||
not: {}
|
||||
}
|
||||
|
||||
const constAny: JsonSchema7Any = {
|
||||
$id: "/schemas/any"
|
||||
}
|
||||
|
||||
const constUnknown: JsonSchema7Unknown = {
|
||||
$id: "/schemas/unknown"
|
||||
}
|
||||
|
||||
const constVoid: JsonSchema7Void = {
|
||||
$id: "/schemas/void"
|
||||
}
|
||||
|
||||
const constObject: JsonSchema7object = {
|
||||
$id: "/schemas/object",
|
||||
"anyOf": [
|
||||
{ "type": "object" },
|
||||
{ "type": "array" }
|
||||
]
|
||||
}
|
||||
|
||||
const constEmptyStruct: JsonSchema7empty = {
|
||||
$id: "/schemas/%7B%7D",
|
||||
"anyOf": [
|
||||
{ "type": "object" },
|
||||
{ "type": "array" }
|
||||
]
|
||||
}
|
||||
|
||||
const $schema = "http://json-schema.org/draft-07/schema#"
|
||||
|
||||
function getRawDescription(annotated: AST.Annotated | undefined): string | undefined {
|
||||
if (annotated !== undefined) return Option.getOrUndefined(AST.getDescriptionAnnotation(annotated))
|
||||
}
|
||||
|
||||
function getRawTitle(annotated: AST.Annotated | undefined): string | undefined {
|
||||
if (annotated !== undefined) return Option.getOrUndefined(AST.getTitleAnnotation(annotated))
|
||||
}
|
||||
|
||||
function getRawDefault(annotated: AST.Annotated | undefined): Option.Option<unknown> {
|
||||
if (annotated !== undefined) return AST.getDefaultAnnotation(annotated)
|
||||
return Option.none()
|
||||
}
|
||||
|
||||
function encodeDefault(ast: AST.AST, def: unknown): Option.Option<unknown> {
|
||||
const getOption = ParseResult.getOption(ast, false)
|
||||
return getOption(def)
|
||||
}
|
||||
|
||||
function getRawExamples(annotated: AST.Annotated | undefined): ReadonlyArray<unknown> | undefined {
|
||||
if (annotated !== undefined) return Option.getOrUndefined(AST.getExamplesAnnotation(annotated))
|
||||
}
|
||||
|
||||
function encodeExamples(ast: AST.AST, examples: ReadonlyArray<unknown>): Array<unknown> | undefined {
|
||||
const getOption = ParseResult.getOption(ast, false)
|
||||
const out = Arr.filterMap(examples, (e) => getOption(e))
|
||||
return out.length > 0 ? out : undefined
|
||||
}
|
||||
|
||||
function filterBuiltIn(ast: AST.AST, annotation: string | undefined, key: symbol): string | undefined {
|
||||
if (annotation !== undefined) {
|
||||
switch (ast._tag) {
|
||||
case "StringKeyword":
|
||||
return annotation !== AST.stringKeyword.annotations[key] ? annotation : undefined
|
||||
case "NumberKeyword":
|
||||
return annotation !== AST.numberKeyword.annotations[key] ? annotation : undefined
|
||||
case "BooleanKeyword":
|
||||
return annotation !== AST.booleanKeyword.annotations[key] ? annotation : undefined
|
||||
}
|
||||
}
|
||||
return annotation
|
||||
}
|
||||
|
||||
function pruneJsonSchemaAnnotations(
|
||||
ast: AST.AST,
|
||||
description: string | undefined,
|
||||
title: string | undefined,
|
||||
def: Option.Option<unknown>,
|
||||
examples: ReadonlyArray<unknown> | undefined
|
||||
): JsonSchemaAnnotations | undefined {
|
||||
const out: JsonSchemaAnnotations = {}
|
||||
if (description !== undefined) out.description = description
|
||||
if (title !== undefined) out.title = title
|
||||
if (Option.isSome(def)) {
|
||||
const o = encodeDefault(ast, def.value)
|
||||
if (Option.isSome(o)) {
|
||||
out.default = o.value
|
||||
}
|
||||
}
|
||||
if (examples !== undefined) {
|
||||
const encodedExamples = encodeExamples(ast, examples)
|
||||
if (encodedExamples !== undefined) {
|
||||
out.examples = encodedExamples
|
||||
}
|
||||
}
|
||||
if (Object.keys(out).length === 0) {
|
||||
return undefined
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function getContextJsonSchemaAnnotations(ast: AST.AST, annotated: AST.Annotated): JsonSchemaAnnotations | undefined {
|
||||
return pruneJsonSchemaAnnotations(
|
||||
ast,
|
||||
getRawDescription(annotated),
|
||||
getRawTitle(annotated),
|
||||
getRawDefault(annotated),
|
||||
getRawExamples(annotated)
|
||||
)
|
||||
}
|
||||
|
||||
function getJsonSchemaAnnotations(ast: AST.AST): JsonSchemaAnnotations | undefined {
|
||||
return pruneJsonSchemaAnnotations(
|
||||
ast,
|
||||
filterBuiltIn(ast, getRawDescription(ast), AST.DescriptionAnnotationId),
|
||||
filterBuiltIn(ast, getRawTitle(ast), AST.TitleAnnotationId),
|
||||
getRawDefault(ast),
|
||||
getRawExamples(ast)
|
||||
)
|
||||
}
|
||||
|
||||
function mergeJsonSchemaAnnotations(
|
||||
jsonSchema: JsonSchema7,
|
||||
jsonSchemaAnnotations: JsonSchemaAnnotations | undefined
|
||||
): JsonSchema7 {
|
||||
if (jsonSchemaAnnotations) {
|
||||
if ("$ref" in jsonSchema) {
|
||||
return { allOf: [jsonSchema], ...jsonSchemaAnnotations } as any
|
||||
}
|
||||
return { ...jsonSchema, ...jsonSchemaAnnotations }
|
||||
}
|
||||
return jsonSchema
|
||||
}
|
||||
|
||||
const pruneUndefined = (ast: AST.AST): AST.AST | undefined => {
|
||||
if (Option.isNone(AST.getJSONSchemaAnnotation(ast))) {
|
||||
return AST.pruneUndefined(ast, pruneUndefined, (ast) => pruneUndefined(ast.from))
|
||||
}
|
||||
}
|
||||
|
||||
const isParseJsonTransformation = (ast: AST.AST): boolean =>
|
||||
ast.annotations[AST.SchemaIdAnnotationId] === AST.ParseJsonSchemaId
|
||||
|
||||
const isOverrideAnnotation = (ast: AST.AST, jsonSchema: JsonSchema7): boolean => {
|
||||
if (AST.isRefinement(ast)) {
|
||||
const schemaId = ast.annotations[AST.SchemaIdAnnotationId]
|
||||
if (schemaId === schemaId_.IntSchemaId) {
|
||||
return "type" in jsonSchema && jsonSchema.type !== "integer"
|
||||
}
|
||||
}
|
||||
return ("type" in jsonSchema) || ("oneOf" in jsonSchema) || ("anyOf" in jsonSchema) || ("$ref" in jsonSchema)
|
||||
}
|
||||
|
||||
const mergeRefinements = (from: any, jsonSchema: any, ast: AST.AST): any => {
|
||||
const out: any = { ...from, ...getJsonSchemaAnnotations(ast), ...jsonSchema }
|
||||
out.allOf ??= []
|
||||
|
||||
const handle = (name: string, filter: (i: any) => boolean) => {
|
||||
if (name in jsonSchema && name in from) {
|
||||
out.allOf.unshift({ [name]: from[name] })
|
||||
out.allOf = out.allOf.filter(filter)
|
||||
}
|
||||
}
|
||||
|
||||
handle("minLength", (i) => i.minLength > jsonSchema.minLength)
|
||||
handle("maxLength", (i) => i.maxLength < jsonSchema.maxLength)
|
||||
handle("pattern", (i) => i.pattern !== jsonSchema.pattern)
|
||||
handle("minItems", (i) => i.minItems > jsonSchema.minItems)
|
||||
handle("maxItems", (i) => i.maxItems < jsonSchema.maxItems)
|
||||
handle("minimum", (i) => i.minimum > jsonSchema.minimum)
|
||||
handle("maximum", (i) => i.maximum < jsonSchema.maximum)
|
||||
handle("exclusiveMinimum", (i) => i.exclusiveMinimum > jsonSchema.exclusiveMinimum)
|
||||
handle("exclusiveMaximum", (i) => i.exclusiveMaximum < jsonSchema.exclusiveMaximum)
|
||||
handle("multipleOf", (i) => i.multipleOf !== jsonSchema.multipleOf)
|
||||
|
||||
if (out.allOf.length === 0) {
|
||||
delete out.allOf
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type GoOptions = {
|
||||
readonly getRef: (id: string) => string
|
||||
readonly target: Target
|
||||
readonly topLevelReferenceStrategy: TopLevelReferenceStrategy
|
||||
readonly additionalPropertiesStrategy: AdditionalPropertiesStrategy
|
||||
}
|
||||
|
||||
function isContentSchemaSupported(options: GoOptions): boolean {
|
||||
switch (options.target) {
|
||||
case "jsonSchema7":
|
||||
return false
|
||||
case "jsonSchema2019-09":
|
||||
case "openApi3.1":
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function getAdditionalProperties(options: GoOptions): boolean {
|
||||
switch (options.additionalPropertiesStrategy) {
|
||||
case "allow":
|
||||
return true
|
||||
case "strict":
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function addASTAnnotations(jsonSchema: JsonSchema7, ast: AST.AST): JsonSchema7 {
|
||||
return addAnnotations(jsonSchema, getJsonSchemaAnnotations(ast))
|
||||
}
|
||||
|
||||
function addAnnotations(jsonSchema: JsonSchema7, annotations: JsonSchemaAnnotations | undefined): JsonSchema7 {
|
||||
if (annotations === undefined || Object.keys(annotations).length === 0) {
|
||||
return jsonSchema
|
||||
}
|
||||
if ("$ref" in jsonSchema) {
|
||||
return { allOf: [jsonSchema], ...annotations } as any
|
||||
}
|
||||
return { ...jsonSchema, ...annotations }
|
||||
}
|
||||
|
||||
function getIdentifierAnnotation(ast: AST.AST): string | undefined {
|
||||
const identifier = Option.getOrUndefined(AST.getJSONIdentifier(ast))
|
||||
if (identifier === undefined) {
|
||||
if (AST.isSuspend(ast)) {
|
||||
return getIdentifierAnnotation(ast.f())
|
||||
}
|
||||
if (AST.isTransformation(ast) && AST.isTypeLiteral(ast.from) && AST.isDeclaration(ast.to)) {
|
||||
const to = ast.to
|
||||
const surrogate = AST.getSurrogateAnnotation(to)
|
||||
if (Option.isSome(surrogate)) {
|
||||
return getIdentifierAnnotation(to)
|
||||
}
|
||||
}
|
||||
}
|
||||
return identifier
|
||||
}
|
||||
|
||||
function go(
|
||||
ast: AST.AST,
|
||||
$defs: Record<string, JsonSchema7>,
|
||||
identifier: "handle-identifier" | "ignore-identifier",
|
||||
path: ReadonlyArray<PropertyKey>,
|
||||
options: GoOptions,
|
||||
annotation: "handle-annotation" | "ignore-annotation",
|
||||
errors: "handle-errors" | "ignore-errors"
|
||||
): JsonSchema7 {
|
||||
if (
|
||||
identifier === "handle-identifier" &&
|
||||
(options.topLevelReferenceStrategy !== "skip" || AST.isSuspend(ast))
|
||||
) {
|
||||
const id = getIdentifierAnnotation(ast)
|
||||
if (id !== undefined) {
|
||||
const escapedId = id.replace(/~/ig, "~0").replace(/\//ig, "~1")
|
||||
const out = { $ref: options.getRef(escapedId) }
|
||||
if (!Record.has($defs, id)) {
|
||||
$defs[id] = out
|
||||
$defs[id] = go(ast, $defs, "ignore-identifier", path, options, "handle-annotation", errors)
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
if (annotation === "handle-annotation") {
|
||||
const hook = AST.getJSONSchemaAnnotation(ast)
|
||||
if (Option.isSome(hook)) {
|
||||
const handler = hook.value as JsonSchema7
|
||||
if (isOverrideAnnotation(ast, handler)) {
|
||||
switch (ast._tag) {
|
||||
case "Declaration":
|
||||
return addASTAnnotations(handler, ast)
|
||||
default:
|
||||
return handler
|
||||
}
|
||||
} else {
|
||||
switch (ast._tag) {
|
||||
case "Refinement": {
|
||||
const t = AST.getTransformationFrom(ast)
|
||||
if (t === undefined) {
|
||||
return mergeRefinements(
|
||||
go(ast.from, $defs, identifier, path, options, "handle-annotation", errors),
|
||||
handler,
|
||||
ast
|
||||
)
|
||||
} else {
|
||||
return go(t, $defs, identifier, path, options, "handle-annotation", errors)
|
||||
}
|
||||
}
|
||||
default:
|
||||
return {
|
||||
...go(ast, $defs, identifier, path, options, "ignore-annotation", errors),
|
||||
...handler
|
||||
} as any
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const surrogate = AST.getSurrogateAnnotation(ast)
|
||||
if (Option.isSome(surrogate)) {
|
||||
return go(surrogate.value, $defs, identifier, path, options, "handle-annotation", errors)
|
||||
}
|
||||
switch (ast._tag) {
|
||||
// Unsupported
|
||||
case "Declaration":
|
||||
case "UndefinedKeyword":
|
||||
case "BigIntKeyword":
|
||||
case "UniqueSymbol":
|
||||
case "SymbolKeyword": {
|
||||
if (errors === "ignore-errors") return addASTAnnotations(constAny, ast)
|
||||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast))
|
||||
}
|
||||
case "Suspend": {
|
||||
if (identifier === "handle-identifier") {
|
||||
if (errors === "ignore-errors") return addASTAnnotations(constAny, ast)
|
||||
throw new Error(errors_.getJSONSchemaMissingIdentifierAnnotationErrorMessage(path, ast))
|
||||
}
|
||||
return go(ast.f(), $defs, "ignore-identifier", path, options, "handle-annotation", errors)
|
||||
}
|
||||
// Primitives
|
||||
case "NeverKeyword":
|
||||
return addASTAnnotations(constNever, ast)
|
||||
case "VoidKeyword":
|
||||
return addASTAnnotations(constVoid, ast)
|
||||
case "UnknownKeyword":
|
||||
return addASTAnnotations(constUnknown, ast)
|
||||
case "AnyKeyword":
|
||||
return addASTAnnotations(constAny, ast)
|
||||
case "ObjectKeyword":
|
||||
return addASTAnnotations(constObject, ast)
|
||||
case "StringKeyword":
|
||||
return addASTAnnotations({ type: "string" }, ast)
|
||||
case "NumberKeyword":
|
||||
return addASTAnnotations({ type: "number" }, ast)
|
||||
case "BooleanKeyword":
|
||||
return addASTAnnotations({ type: "boolean" }, ast)
|
||||
case "Literal": {
|
||||
const literal = ast.literal
|
||||
if (literal === null) {
|
||||
return addASTAnnotations({ type: "null" }, ast)
|
||||
} else if (Predicate.isString(literal)) {
|
||||
return addASTAnnotations({ type: "string", enum: [literal] }, ast)
|
||||
} else if (Predicate.isNumber(literal)) {
|
||||
return addASTAnnotations({ type: "number", enum: [literal] }, ast)
|
||||
} else if (Predicate.isBoolean(literal)) {
|
||||
return addASTAnnotations({ type: "boolean", enum: [literal] }, ast)
|
||||
}
|
||||
if (errors === "ignore-errors") return addASTAnnotations(constAny, ast)
|
||||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast))
|
||||
}
|
||||
case "Enums": {
|
||||
const anyOf = ast.enums.map((e) => {
|
||||
const type: "string" | "number" = Predicate.isNumber(e[1]) ? "number" : "string"
|
||||
return { type, title: e[0], enum: [e[1]] }
|
||||
})
|
||||
return anyOf.length >= 1 ?
|
||||
addASTAnnotations({
|
||||
$comment: "/schemas/enums",
|
||||
anyOf
|
||||
}, ast) :
|
||||
addASTAnnotations(constNever, ast)
|
||||
}
|
||||
case "TupleType": {
|
||||
const elements = ast.elements.map((e, i) =>
|
||||
mergeJsonSchemaAnnotations(
|
||||
go(e.type, $defs, "handle-identifier", path.concat(i), options, "handle-annotation", errors),
|
||||
getContextJsonSchemaAnnotations(e.type, e)
|
||||
)
|
||||
)
|
||||
const rest = ast.rest.map((type) =>
|
||||
mergeJsonSchemaAnnotations(
|
||||
go(type.type, $defs, "handle-identifier", path, options, "handle-annotation", errors),
|
||||
getContextJsonSchemaAnnotations(type.type, type)
|
||||
)
|
||||
)
|
||||
const output: JsonSchema7Array = { type: "array" }
|
||||
// ---------------------------------------------
|
||||
// handle elements
|
||||
// ---------------------------------------------
|
||||
const len = ast.elements.length
|
||||
if (len > 0) {
|
||||
output.minItems = len - ast.elements.filter((element) => element.isOptional).length
|
||||
output.items = elements
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle rest element
|
||||
// ---------------------------------------------
|
||||
const restLength = rest.length
|
||||
if (restLength > 0) {
|
||||
const head = rest[0]
|
||||
const isHomogeneous = restLength === 1 && ast.elements.every((e) => e.type === ast.rest[0].type)
|
||||
if (isHomogeneous) {
|
||||
output.items = head
|
||||
} else {
|
||||
output.additionalItems = head
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// handle post rest elements
|
||||
// ---------------------------------------------
|
||||
if (restLength > 1) {
|
||||
if (errors === "ignore-errors") return addASTAnnotations(constAny, ast)
|
||||
throw new Error(errors_.getJSONSchemaUnsupportedPostRestElementsErrorMessage(path))
|
||||
}
|
||||
} else {
|
||||
if (len > 0) {
|
||||
output.additionalItems = false
|
||||
} else {
|
||||
output.maxItems = 0
|
||||
}
|
||||
}
|
||||
|
||||
return addASTAnnotations(output, ast)
|
||||
}
|
||||
case "TypeLiteral": {
|
||||
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
|
||||
return addASTAnnotations(constEmptyStruct, ast)
|
||||
}
|
||||
const output: JsonSchema7Object = {
|
||||
type: "object",
|
||||
required: [],
|
||||
properties: {},
|
||||
additionalProperties: getAdditionalProperties(options)
|
||||
}
|
||||
let patternProperties: JsonSchema7 | undefined = undefined
|
||||
let propertyNames: JsonSchema7 | undefined = undefined
|
||||
for (const is of ast.indexSignatures) {
|
||||
const pruned = pruneUndefined(is.type) ?? is.type
|
||||
const parameter = is.parameter
|
||||
switch (parameter._tag) {
|
||||
case "StringKeyword": {
|
||||
output.additionalProperties = go(
|
||||
pruned,
|
||||
$defs,
|
||||
"handle-identifier",
|
||||
path,
|
||||
options,
|
||||
"handle-annotation",
|
||||
errors
|
||||
)
|
||||
break
|
||||
}
|
||||
case "TemplateLiteral": {
|
||||
patternProperties = go(pruned, $defs, "handle-identifier", path, options, "handle-annotation", errors)
|
||||
propertyNames = {
|
||||
type: "string",
|
||||
pattern: AST.getTemplateLiteralRegExp(parameter).source
|
||||
}
|
||||
break
|
||||
}
|
||||
case "Refinement": {
|
||||
patternProperties = go(pruned, $defs, "handle-identifier", path, options, "handle-annotation", errors)
|
||||
propertyNames = go(parameter, $defs, "handle-identifier", path, options, "handle-annotation", errors)
|
||||
break
|
||||
}
|
||||
case "SymbolKeyword": {
|
||||
const indexSignaturePath = path.concat("[symbol]")
|
||||
output.additionalProperties = go(
|
||||
pruned,
|
||||
$defs,
|
||||
"handle-identifier",
|
||||
indexSignaturePath,
|
||||
options,
|
||||
"handle-annotation",
|
||||
errors
|
||||
)
|
||||
propertyNames = go(
|
||||
parameter,
|
||||
$defs,
|
||||
"handle-identifier",
|
||||
indexSignaturePath,
|
||||
options,
|
||||
"handle-annotation",
|
||||
errors
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle property signatures
|
||||
// ---------------------------------------------
|
||||
for (let i = 0; i < ast.propertySignatures.length; i++) {
|
||||
const ps = ast.propertySignatures[i]
|
||||
const name = ps.name
|
||||
if (Predicate.isString(name)) {
|
||||
const pruned = pruneUndefined(ps.type)
|
||||
const type = pruned ?? ps.type
|
||||
output.properties[name] = mergeJsonSchemaAnnotations(
|
||||
go(type, $defs, "handle-identifier", path.concat(ps.name), options, "handle-annotation", errors),
|
||||
getContextJsonSchemaAnnotations(type, ps)
|
||||
)
|
||||
// ---------------------------------------------
|
||||
// handle optional property signatures
|
||||
// ---------------------------------------------
|
||||
if (!ps.isOptional && pruned === undefined) {
|
||||
output.required.push(name)
|
||||
}
|
||||
} else {
|
||||
if (errors === "ignore-errors") return addASTAnnotations(constAny, ast)
|
||||
throw new Error(errors_.getJSONSchemaUnsupportedKeyErrorMessage(name, path))
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle index signatures
|
||||
// ---------------------------------------------
|
||||
if (patternProperties !== undefined) {
|
||||
delete output.additionalProperties
|
||||
output.patternProperties = { "": patternProperties }
|
||||
}
|
||||
if (propertyNames !== undefined) {
|
||||
output.propertyNames = propertyNames
|
||||
}
|
||||
|
||||
return addASTAnnotations(output, ast)
|
||||
}
|
||||
case "Union": {
|
||||
const members: Array<JsonSchema7> = ast.types.map((t) =>
|
||||
go(t, $defs, "handle-identifier", path, options, "handle-annotation", errors)
|
||||
)
|
||||
const anyOf = compactUnion(members)
|
||||
switch (anyOf.length) {
|
||||
case 0:
|
||||
return constNever
|
||||
case 1:
|
||||
return addASTAnnotations(anyOf[0], ast)
|
||||
default:
|
||||
return addASTAnnotations({ anyOf }, ast)
|
||||
}
|
||||
}
|
||||
case "Refinement":
|
||||
return go(ast.from, $defs, identifier, path, options, "handle-annotation", errors)
|
||||
case "TemplateLiteral": {
|
||||
const regex = AST.getTemplateLiteralRegExp(ast)
|
||||
return addASTAnnotations({
|
||||
type: "string",
|
||||
title: String(ast),
|
||||
description: "a template literal",
|
||||
pattern: regex.source
|
||||
}, ast)
|
||||
}
|
||||
case "Transformation": {
|
||||
if (isParseJsonTransformation(ast.from)) {
|
||||
const out: JsonSchema7String & { contentSchema?: JsonSchema7 } = {
|
||||
"type": "string",
|
||||
"contentMediaType": "application/json"
|
||||
}
|
||||
if (isContentSchemaSupported(options)) {
|
||||
out["contentSchema"] = go(ast.to, $defs, identifier, path, options, "handle-annotation", errors)
|
||||
}
|
||||
return out
|
||||
}
|
||||
const from = go(ast.from, $defs, identifier, path, options, "handle-annotation", errors)
|
||||
if (
|
||||
ast.transformation._tag === "TypeLiteralTransformation" &&
|
||||
isJsonSchema7Object(from)
|
||||
) {
|
||||
const to = go(ast.to, {}, "ignore-identifier", path, options, "handle-annotation", "ignore-errors")
|
||||
if (isJsonSchema7Object(to)) {
|
||||
for (const t of ast.transformation.propertySignatureTransformations) {
|
||||
const toKey = t.to
|
||||
const fromKey = t.from
|
||||
if (Predicate.isString(toKey) && Predicate.isString(fromKey)) {
|
||||
const toProperty = to.properties[toKey]
|
||||
if (Predicate.isRecord(toProperty)) {
|
||||
const fromProperty = from.properties[fromKey]
|
||||
if (Predicate.isRecord(fromProperty)) {
|
||||
const annotations: JsonSchemaAnnotations = {}
|
||||
if (Predicate.isString(toProperty.title)) annotations.title = toProperty.title
|
||||
if (Predicate.isString(toProperty.description)) annotations.description = toProperty.description
|
||||
if (Array.isArray(toProperty.examples)) annotations.examples = toProperty.examples
|
||||
if (Object.hasOwn(toProperty, "default")) annotations.default = toProperty.default
|
||||
from.properties[fromKey] = addAnnotations(fromProperty, annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return addASTAnnotations(from, ast)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isJsonSchema7Object(jsonSchema: unknown): jsonSchema is JsonSchema7Object {
|
||||
return Predicate.isRecord(jsonSchema) && jsonSchema.type === "object" && Predicate.isRecord(jsonSchema.properties)
|
||||
}
|
||||
|
||||
function isNeverWithoutCustomAnnotations(jsonSchema: JsonSchema7): boolean {
|
||||
return jsonSchema === constNever || (Predicate.hasProperty(jsonSchema, "$id") && jsonSchema.$id === constNever.$id &&
|
||||
Object.keys(jsonSchema).length === 3 && jsonSchema.title === AST.neverKeyword.annotations[AST.TitleAnnotationId])
|
||||
}
|
||||
|
||||
function isAny(jsonSchema: JsonSchema7): jsonSchema is JsonSchema7Any {
|
||||
return "$id" in jsonSchema && jsonSchema.$id === constAny.$id
|
||||
}
|
||||
|
||||
function isUnknown(jsonSchema: JsonSchema7): jsonSchema is JsonSchema7Unknown {
|
||||
return "$id" in jsonSchema && jsonSchema.$id === constUnknown.$id
|
||||
}
|
||||
|
||||
function isVoid(jsonSchema: JsonSchema7): jsonSchema is JsonSchema7Void {
|
||||
return "$id" in jsonSchema && jsonSchema.$id === constVoid.$id
|
||||
}
|
||||
|
||||
function isCompactableLiteral(jsonSchema: JsonSchema7 | undefined): jsonSchema is JsonSchema7Enum {
|
||||
return Predicate.hasProperty(jsonSchema, "enum") && "type" in jsonSchema && Object.keys(jsonSchema).length === 2
|
||||
}
|
||||
|
||||
function compactUnion(members: Array<JsonSchema7>): Array<JsonSchema7> {
|
||||
const out: Array<JsonSchema7> = []
|
||||
for (const m of members) {
|
||||
if (isNeverWithoutCustomAnnotations(m)) continue
|
||||
if (isAny(m) || isUnknown(m) || isVoid(m)) return [m]
|
||||
if (isCompactableLiteral(m) && out.length > 0) {
|
||||
const last = out[out.length - 1]
|
||||
if (isCompactableLiteral(last) && last.type === m.type) {
|
||||
out[out.length - 1] = {
|
||||
type: last.type,
|
||||
enum: [...last.enum, ...m.enum]
|
||||
} as JsonSchema7Enum
|
||||
continue
|
||||
}
|
||||
}
|
||||
out.push(m)
|
||||
}
|
||||
return out
|
||||
}
|
||||
201
_node_modules/effect/src/KeyedPool.ts
generated
Normal file
201
_node_modules/effect/src/KeyedPool.ts
generated
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/keyedPool.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const KeyedPoolTypeId: unique symbol = internal.KeyedPoolTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type KeyedPoolTypeId = typeof KeyedPoolTypeId
|
||||
|
||||
/**
|
||||
* A `KeyedPool<K, A, E>` is a pool of `Pool`s of items of type `A`. Each pool
|
||||
* in the `KeyedPool` is associated with a key of type `K`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface KeyedPool<in K, in out A, out E = never> extends KeyedPool.Variance<K, A, E>, Pipeable {
|
||||
/**
|
||||
* Retrieves an item from the pool belonging to the given key in a scoped
|
||||
* effect. Note that if acquisition fails, then the returned effect will fail
|
||||
* for that same reason. Retrying a failed acquisition attempt will repeat the
|
||||
* acquisition attempt.
|
||||
*/
|
||||
get(key: K): Effect.Effect<A, E, Scope.Scope>
|
||||
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*/
|
||||
invalidate(item: A): Effect.Effect<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace KeyedPool {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in K, in out A, out E> {
|
||||
readonly [KeyedPoolTypeId]: {
|
||||
readonly _K: Types.Contravariant<K>
|
||||
readonly _A: Types.Invariant<A>
|
||||
readonly _E: Types.Covariant<E>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a new pool of the specified fixed size. The pool is returned in a
|
||||
* `Scope`, which governs the lifetime of the pool. When the pool is shutdown
|
||||
* because the `Scope` is closed, the individual items allocated by the pool
|
||||
* will be released in some unspecified order.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <K, A, E, R>(
|
||||
options: {
|
||||
readonly acquire: (key: K) => Effect.Effect<A, E, R>
|
||||
readonly size: number
|
||||
}
|
||||
) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R> = internal.make
|
||||
|
||||
/**
|
||||
* Makes a new pool of the specified fixed size. The pool is returned in a
|
||||
* `Scope`, which governs the lifetime of the pool. When the pool is shutdown
|
||||
* because the `Scope` is closed, the individual items allocated by the pool
|
||||
* will be released in some unspecified order.
|
||||
*
|
||||
* The size of the underlying pools can be configured per key.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWith: <K, A, E, R>(
|
||||
options: {
|
||||
readonly acquire: (key: K) => Effect.Effect<A, E, R>
|
||||
readonly size: (key: K) => number
|
||||
}
|
||||
) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R> = internal.makeWith
|
||||
|
||||
/**
|
||||
* Makes a new pool with the specified minimum and maximum sizes and time to
|
||||
* live before a pool whose excess items are not being used will be shrunk
|
||||
* down to the minimum size. The pool is returned in a `Scope`, which governs
|
||||
* the lifetime of the pool. When the pool is shutdown because the `Scope` is
|
||||
* used, the individual items allocated by the pool will be released in some
|
||||
* unspecified order.
|
||||
*
|
||||
* The size of the underlying pools can be configured per key.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWithTTL: <K, A, E, R>(
|
||||
options: {
|
||||
readonly acquire: (key: K) => Effect.Effect<A, E, R>
|
||||
readonly min: (key: K) => number
|
||||
readonly max: (key: K) => number
|
||||
readonly timeToLive: Duration.DurationInput
|
||||
}
|
||||
) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R> = internal.makeWithTTL
|
||||
|
||||
/**
|
||||
* Makes a new pool with the specified minimum and maximum sizes and time to
|
||||
* live before a pool whose excess items are not being used will be shrunk
|
||||
* down to the minimum size. The pool is returned in a `Scope`, which governs
|
||||
* the lifetime of the pool. When the pool is shutdown because the `Scope` is
|
||||
* used, the individual items allocated by the pool will be released in some
|
||||
* unspecified order.
|
||||
*
|
||||
* The size of the underlying pools can be configured per key.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWithTTLBy: <K, A, E, R>(
|
||||
options: {
|
||||
readonly acquire: (key: K) => Effect.Effect<A, E, R>
|
||||
readonly min: (key: K) => number
|
||||
readonly max: (key: K) => number
|
||||
readonly timeToLive: (key: K) => Duration.DurationInput
|
||||
}
|
||||
) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R> = internal.makeWithTTLBy
|
||||
|
||||
/**
|
||||
* Retrieves an item from the pool belonging to the given key in a scoped
|
||||
* effect. Note that if acquisition fails, then the returned effect will fail
|
||||
* for that same reason. Retrying a failed acquisition attempt will repeat the
|
||||
* acquisition attempt.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* Retrieves an item from the pool belonging to the given key in a scoped
|
||||
* effect. Note that if acquisition fails, then the returned effect will fail
|
||||
* for that same reason. Retrying a failed acquisition attempt will repeat the
|
||||
* acquisition attempt.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<K>(key: K): <A, E>(self: KeyedPool<K, A, E>) => Effect.Effect<A, E, Scope.Scope>
|
||||
/**
|
||||
* Retrieves an item from the pool belonging to the given key in a scoped
|
||||
* effect. Note that if acquisition fails, then the returned effect will fail
|
||||
* for that same reason. Retrying a failed acquisition attempt will repeat the
|
||||
* acquisition attempt.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<K, A, E>(self: KeyedPool<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>
|
||||
} = internal.get
|
||||
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const invalidate: {
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<A>(item: A): <K, E>(self: KeyedPool<K, A, E>) => Effect.Effect<void>
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<K, A, E>(self: KeyedPool<K, A, E>, item: A): Effect.Effect<void>
|
||||
} = internal.invalidate
|
||||
1671
_node_modules/effect/src/Layer.ts
generated
Normal file
1671
_node_modules/effect/src/Layer.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
436
_node_modules/effect/src/LayerMap.ts
generated
Normal file
436
_node_modules/effect/src/LayerMap.ts
generated
Normal file
@@ -0,0 +1,436 @@
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @experimental
|
||||
*/
|
||||
import * as Context from "./Context.js"
|
||||
import type * as Duration from "./Duration.js"
|
||||
import * as Effect from "./Effect.js"
|
||||
import * as FiberRefsPatch from "./FiberRefsPatch.js"
|
||||
import { identity } from "./Function.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as Layer from "./Layer.js"
|
||||
import * as RcMap from "./RcMap.js"
|
||||
import * as Runtime from "./Runtime.js"
|
||||
import * as Scope from "./Scope.js"
|
||||
import type { Mutable, NoExcessProperties } from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Symbols
|
||||
*/
|
||||
export const TypeId: unique symbol = Symbol.for("effect/LayerMap")
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Symbols
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Models
|
||||
* @experimental
|
||||
*/
|
||||
export interface LayerMap<in K, in out I, out E = never> {
|
||||
readonly [TypeId]: TypeId
|
||||
|
||||
/**
|
||||
* The internal RcMap that stores the resources.
|
||||
*/
|
||||
readonly rcMap: RcMap.RcMap<K, {
|
||||
readonly layer: Layer.Layer<I, E>
|
||||
readonly runtimeEffect: Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope>
|
||||
}, E>
|
||||
|
||||
/**
|
||||
* Retrieves a Layer for the resources associated with the key.
|
||||
*/
|
||||
get(key: K): Layer.Layer<I, E>
|
||||
|
||||
/**
|
||||
* Retrieves a Runtime for the resources associated with the key.
|
||||
*/
|
||||
runtime(key: K): Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope>
|
||||
|
||||
/**
|
||||
* Invalidates the resource associated with the key.
|
||||
*/
|
||||
invalidate(key: K): Effect.Effect<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Constructors
|
||||
* @experimental
|
||||
*
|
||||
* A `LayerMap` allows you to create a map of Layer's that can be used to
|
||||
* dynamically access resources based on a key.
|
||||
*
|
||||
* ```ts
|
||||
* import { NodeRuntime } from "@effect/platform-node"
|
||||
* import { Context, Effect, FiberRef, Layer, LayerMap } from "effect"
|
||||
*
|
||||
* class Greeter extends Context.Tag("Greeter")<Greeter, {
|
||||
* greet: Effect.Effect<string>
|
||||
* }>() {}
|
||||
*
|
||||
* // create a service that wraps a LayerMap
|
||||
* class GreeterMap extends LayerMap.Service<GreeterMap>()("GreeterMap", {
|
||||
* // define the lookup function for the layer map
|
||||
* //
|
||||
* // The returned Layer will be used to provide the Greeter service for the
|
||||
* // given name.
|
||||
* lookup: (name: string) =>
|
||||
* Layer.succeed(Greeter, {
|
||||
* greet: Effect.succeed(`Hello, ${name}!`)
|
||||
* }).pipe(
|
||||
* Layer.merge(Layer.locallyScoped(FiberRef.currentConcurrency, 123))
|
||||
* ),
|
||||
*
|
||||
* // If a layer is not used for a certain amount of time, it can be removed
|
||||
* idleTimeToLive: "5 seconds",
|
||||
*
|
||||
* // Supply the dependencies for the layers in the LayerMap
|
||||
* dependencies: []
|
||||
* }) {}
|
||||
*
|
||||
* // usage
|
||||
* const program: Effect.Effect<void, never, GreeterMap> = Effect.gen(function*() {
|
||||
* // access and use the Greeter service
|
||||
* const greeter = yield* Greeter
|
||||
* yield* Effect.log(yield* greeter.greet)
|
||||
* }).pipe(
|
||||
* // use the GreeterMap service to provide a variant of the Greeter service
|
||||
* Effect.provide(GreeterMap.get("John"))
|
||||
* )
|
||||
*
|
||||
* // run the program
|
||||
* program.pipe(
|
||||
* Effect.provide(GreeterMap.Default),
|
||||
* NodeRuntime.runMain
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
export const make: <
|
||||
K,
|
||||
L extends Layer.Layer<any, any, any>,
|
||||
PreloadKeys extends Iterable<K> | undefined = undefined
|
||||
>(
|
||||
lookup: (key: K) => L,
|
||||
options?: {
|
||||
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
||||
readonly preloadKeys?: PreloadKeys
|
||||
} | undefined
|
||||
) => Effect.Effect<
|
||||
LayerMap<
|
||||
K,
|
||||
L extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
|
||||
L extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
|
||||
>,
|
||||
PreloadKeys extends undefined ? never : L extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never,
|
||||
Scope.Scope | (L extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
|
||||
> = Effect.fnUntraced(function*<I, K, EL, RL>(
|
||||
lookup: (key: K) => Layer.Layer<I, EL, RL>,
|
||||
options?: {
|
||||
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
||||
readonly preloadKeys?: Iterable<K> | undefined
|
||||
} | undefined
|
||||
) {
|
||||
const context = yield* Effect.context<never>()
|
||||
|
||||
// If we are inside another layer build, use the current memo map,
|
||||
// otherwise create a new one.
|
||||
const memoMap = context.unsafeMap.has(Layer.CurrentMemoMap.key)
|
||||
? Context.get(context, Layer.CurrentMemoMap)
|
||||
: yield* Layer.makeMemoMap
|
||||
|
||||
const rcMap = yield* RcMap.make({
|
||||
lookup: (key: K) =>
|
||||
Effect.scopeWith((scope) => Effect.diffFiberRefs(Layer.buildWithMemoMap(lookup(key), memoMap, scope))).pipe(
|
||||
Effect.map(([patch, context]) => ({
|
||||
layer: Layer.scopedContext(
|
||||
core.withFiberRuntime<Context.Context<I>, any, Scope.Scope>((fiber) => {
|
||||
const scope = Context.unsafeGet(fiber.currentContext, Scope.Scope)
|
||||
const oldRefs = fiber.getFiberRefs()
|
||||
const newRefs = FiberRefsPatch.patch(patch, fiber.id(), oldRefs)
|
||||
const revert = FiberRefsPatch.diff(newRefs, oldRefs)
|
||||
fiber.setFiberRefs(newRefs)
|
||||
return Effect.as(
|
||||
Scope.addFinalizerExit(scope, () => {
|
||||
fiber.setFiberRefs(FiberRefsPatch.patch(revert, fiber.id(), fiber.getFiberRefs()))
|
||||
return Effect.void
|
||||
}),
|
||||
context
|
||||
)
|
||||
})
|
||||
),
|
||||
runtimeEffect: Effect.withFiberRuntime<Runtime.Runtime<I>, any, Scope.Scope>((fiber) => {
|
||||
const fiberRefs = FiberRefsPatch.patch(patch, fiber.id(), fiber.getFiberRefs())
|
||||
return Effect.succeed(Runtime.make({
|
||||
context,
|
||||
fiberRefs,
|
||||
runtimeFlags: Runtime.defaultRuntime.runtimeFlags
|
||||
}))
|
||||
})
|
||||
} as const))
|
||||
),
|
||||
idleTimeToLive: options?.idleTimeToLive
|
||||
})
|
||||
|
||||
if (options?.preloadKeys) {
|
||||
for (const key of options.preloadKeys) {
|
||||
yield* (RcMap.get(rcMap, key) as Effect.Effect<any, EL, RL | Scope.Scope>)
|
||||
}
|
||||
}
|
||||
|
||||
return identity<LayerMap<K, Exclude<I, Scope.Scope>, any>>({
|
||||
[TypeId]: TypeId,
|
||||
rcMap,
|
||||
get: (key) => Layer.unwrapScoped(Effect.map(RcMap.get(rcMap, key), ({ layer }) => layer)),
|
||||
runtime: (key) => Effect.flatMap(RcMap.get(rcMap, key), ({ runtimeEffect }) => runtimeEffect),
|
||||
invalidate: (key) => RcMap.invalidate(rcMap, key)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Constructors
|
||||
* @experimental
|
||||
*/
|
||||
export const fromRecord = <
|
||||
const Layers extends Record<string, Layer.Layer<any, any, any>>,
|
||||
const Preload extends boolean = false
|
||||
>(
|
||||
layers: Layers,
|
||||
options?: {
|
||||
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
||||
readonly preload?: Preload | undefined
|
||||
} | undefined
|
||||
): Effect.Effect<
|
||||
LayerMap<
|
||||
keyof Layers,
|
||||
Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never,
|
||||
Preload extends true ? never : Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
|
||||
>,
|
||||
Preload extends true ? never : Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never,
|
||||
Scope.Scope | (Layers[keyof Layers] extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
|
||||
> =>
|
||||
make((key: keyof Layers) => layers[key], {
|
||||
...options,
|
||||
preloadKeys: options?.preload ? Object.keys(layers) : undefined
|
||||
}) as any
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
*/
|
||||
export interface TagClass<
|
||||
in out Self,
|
||||
in out Id extends string,
|
||||
in out K,
|
||||
in out I,
|
||||
in out E,
|
||||
in out R,
|
||||
in out LE,
|
||||
in out Deps extends Layer.Layer<any, any, any>
|
||||
> extends Context.TagClass<Self, Id, LayerMap<K, I, E>> {
|
||||
/**
|
||||
* A default layer for the `LayerMap` service.
|
||||
*/
|
||||
readonly Default: Layer.Layer<
|
||||
Self,
|
||||
(Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never) | LE,
|
||||
| Exclude<R, (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never)>
|
||||
| (Deps extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never)
|
||||
>
|
||||
|
||||
/**
|
||||
* A default layer for the `LayerMap` service without the dependencies provided.
|
||||
*/
|
||||
readonly DefaultWithoutDependencies: Layer.Layer<Self, LE, R>
|
||||
|
||||
/**
|
||||
* Retrieves a Layer for the resources associated with the key.
|
||||
*/
|
||||
readonly get: (key: K) => Layer.Layer<I, E, Self>
|
||||
|
||||
/**
|
||||
* Retrieves a Runtime for the resources associated with the key.
|
||||
*/
|
||||
readonly runtime: (key: K) => Effect.Effect<Runtime.Runtime<I>, E, Scope.Scope | Self>
|
||||
|
||||
/**
|
||||
* Invalidates the resource associated with the key.
|
||||
*/
|
||||
readonly invalidate: (key: K) => Effect.Effect<void, never, Self>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*
|
||||
* Create a `LayerMap` service that provides a dynamic set of resources based on
|
||||
* a key.
|
||||
*
|
||||
* ```ts
|
||||
* import { NodeRuntime } from "@effect/platform-node"
|
||||
* import { Context, Effect, FiberRef, Layer, LayerMap } from "effect"
|
||||
*
|
||||
* class Greeter extends Context.Tag("Greeter")<Greeter, {
|
||||
* greet: Effect.Effect<string>
|
||||
* }>() {}
|
||||
*
|
||||
* // create a service that wraps a LayerMap
|
||||
* class GreeterMap extends LayerMap.Service<GreeterMap>()("GreeterMap", {
|
||||
* // define the lookup function for the layer map
|
||||
* //
|
||||
* // The returned Layer will be used to provide the Greeter service for the
|
||||
* // given name.
|
||||
* lookup: (name: string) =>
|
||||
* Layer.succeed(Greeter, {
|
||||
* greet: Effect.succeed(`Hello, ${name}!`)
|
||||
* }).pipe(
|
||||
* Layer.merge(Layer.locallyScoped(FiberRef.currentConcurrency, 123))
|
||||
* ),
|
||||
*
|
||||
* // If a layer is not used for a certain amount of time, it can be removed
|
||||
* idleTimeToLive: "5 seconds",
|
||||
*
|
||||
* // Supply the dependencies for the layers in the LayerMap
|
||||
* dependencies: []
|
||||
* }) {}
|
||||
*
|
||||
* // usage
|
||||
* const program: Effect.Effect<void, never, GreeterMap> = Effect.gen(function*() {
|
||||
* // access and use the Greeter service
|
||||
* const greeter = yield* Greeter
|
||||
* yield* Effect.log(yield* greeter.greet)
|
||||
* }).pipe(
|
||||
* // use the GreeterMap service to provide a variant of the Greeter service
|
||||
* Effect.provide(GreeterMap.get("John"))
|
||||
* )
|
||||
*
|
||||
* // run the program
|
||||
* program.pipe(
|
||||
* Effect.provide(GreeterMap.Default),
|
||||
* NodeRuntime.runMain
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
export const Service = <Self>() =>
|
||||
<
|
||||
const Id extends string,
|
||||
Options extends
|
||||
| NoExcessProperties<
|
||||
{
|
||||
readonly lookup: (key: any) => Layer.Layer<any, any, any>
|
||||
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
|
||||
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
||||
readonly preloadKeys?:
|
||||
| Iterable<Options extends { readonly lookup: (key: infer K) => any } ? K : never>
|
||||
| undefined
|
||||
},
|
||||
Options
|
||||
>
|
||||
| NoExcessProperties<{
|
||||
readonly layers: Record<string, Layer.Layer<any, any, any>>
|
||||
readonly dependencies?: ReadonlyArray<Layer.Layer<any, any, any>>
|
||||
readonly idleTimeToLive?: Duration.DurationInput | undefined
|
||||
readonly preload?: boolean
|
||||
}, Options>
|
||||
>(
|
||||
id: Id,
|
||||
options: Options
|
||||
): TagClass<
|
||||
Self,
|
||||
Id,
|
||||
Options extends { readonly lookup: (key: infer K) => any } ? K
|
||||
: Options extends { readonly layers: infer Layers } ? keyof Layers
|
||||
: never,
|
||||
Service.Success<Options>,
|
||||
Options extends { readonly preload: true } ? never : Service.Error<Options>,
|
||||
Service.Context<Options>,
|
||||
Options extends { readonly preload: true } ? Service.Error<Options>
|
||||
: Options extends { readonly preloadKey: Iterable<any> } ? Service.Error<Options>
|
||||
: never,
|
||||
Options extends { readonly dependencies: ReadonlyArray<any> } ? Options["dependencies"][number] : never
|
||||
> => {
|
||||
const Err = globalThis.Error as any
|
||||
const limit = Err.stackTraceLimit
|
||||
Err.stackTraceLimit = 2
|
||||
const creationError = new Err()
|
||||
Err.stackTraceLimit = limit
|
||||
|
||||
function TagClass() {}
|
||||
const TagClass_ = TagClass as any as Mutable<TagClass<Self, Id, string, any, any, any, any, any>>
|
||||
Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id)))
|
||||
TagClass.key = id
|
||||
Object.defineProperty(TagClass, "stack", {
|
||||
get() {
|
||||
return creationError.stack
|
||||
}
|
||||
})
|
||||
|
||||
TagClass_.DefaultWithoutDependencies = Layer.scoped(
|
||||
TagClass_,
|
||||
"lookup" in options
|
||||
? make(options.lookup, options)
|
||||
: fromRecord(options.layers as any, options)
|
||||
)
|
||||
TagClass_.Default = options.dependencies && options.dependencies.length > 0 ?
|
||||
Layer.provide(TagClass_.DefaultWithoutDependencies, options.dependencies as any) :
|
||||
TagClass_.DefaultWithoutDependencies
|
||||
|
||||
TagClass_.get = (key: string) => Layer.unwrapScoped(Effect.map(TagClass_, (layerMap) => layerMap.get(key)))
|
||||
TagClass_.runtime = (key: string) => Effect.flatMap(TagClass_, (layerMap) => layerMap.runtime(key))
|
||||
TagClass_.invalidate = (key: string) => Effect.flatMap(TagClass_, (layerMap) => layerMap.invalidate(key))
|
||||
|
||||
return TagClass as any
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export declare namespace Service {
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export type Key<Options> = Options extends { readonly lookup: (key: infer K) => any } ? K
|
||||
: Options extends { readonly layers: infer Layers } ? keyof Layers
|
||||
: never
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export type Layers<Options> = Options extends { readonly lookup: (key: infer _K) => infer Layers } ? Layers
|
||||
: Options extends { readonly layers: infer Layers } ? Layers[keyof Layers]
|
||||
: never
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export type Success<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _A : never
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export type Error<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _E : never
|
||||
|
||||
/**
|
||||
* @since 3.14.0
|
||||
* @category Service
|
||||
* @experimental
|
||||
*/
|
||||
export type Context<Options> = Layers<Options> extends Layer.Layer<infer _A, infer _E, infer _R> ? _R : never
|
||||
}
|
||||
1469
_node_modules/effect/src/List.ts
generated
Normal file
1469
_node_modules/effect/src/List.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
387
_node_modules/effect/src/LogLevel.ts
generated
Normal file
387
_node_modules/effect/src/LogLevel.ts
generated
Normal file
@@ -0,0 +1,387 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import { dual, pipe } from "./Function.js"
|
||||
import * as core from "./internal/core.js"
|
||||
import * as number from "./Number.js"
|
||||
import * as order from "./Order.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
|
||||
/**
|
||||
* A `LogLevel` represents the log level associated with an individual logging
|
||||
* operation. Log levels are used both to describe the granularity (or
|
||||
* importance) of individual log statements, as well as to enable tuning
|
||||
* verbosity of log output.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
* @property ordinal - The priority of the log message. Larger values indicate higher priority.
|
||||
* @property label - A label associated with the log level.
|
||||
* @property syslog -The syslog severity level of the log level.
|
||||
*/
|
||||
export type LogLevel = All | Fatal | Error | Warning | Info | Debug | Trace | None
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export type Literal = LogLevel["_tag"]
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface All extends Pipeable {
|
||||
readonly _tag: "All"
|
||||
readonly label: "ALL"
|
||||
readonly syslog: 0
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Fatal extends Pipeable {
|
||||
readonly _tag: "Fatal"
|
||||
readonly label: "FATAL"
|
||||
readonly syslog: 2
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Error extends Pipeable {
|
||||
readonly _tag: "Error"
|
||||
readonly label: "ERROR"
|
||||
readonly syslog: 3
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Warning extends Pipeable {
|
||||
readonly _tag: "Warning"
|
||||
readonly label: "WARN"
|
||||
readonly syslog: 4
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Info extends Pipeable {
|
||||
readonly _tag: "Info"
|
||||
readonly label: "INFO"
|
||||
readonly syslog: 6
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Debug extends Pipeable {
|
||||
readonly _tag: "Debug"
|
||||
readonly label: "DEBUG"
|
||||
readonly syslog: 7
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface Trace extends Pipeable {
|
||||
readonly _tag: "Trace"
|
||||
readonly label: "TRACE"
|
||||
readonly syslog: 7
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface None extends Pipeable {
|
||||
readonly _tag: "None"
|
||||
readonly label: "OFF"
|
||||
readonly syslog: 7
|
||||
readonly ordinal: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const All: LogLevel = core.logLevelAll
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Fatal: LogLevel = core.logLevelFatal
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Error: LogLevel = core.logLevelError
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Warning: LogLevel = core.logLevelWarning
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Info: LogLevel = core.logLevelInfo
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Debug: LogLevel = core.logLevelDebug
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Trace: LogLevel = core.logLevelTrace
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const None: LogLevel = core.logLevelNone
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const allLevels = core.allLogLevels
|
||||
|
||||
/**
|
||||
* Temporarily sets a `LogLevel` for an `Effect` workflow.
|
||||
*
|
||||
* **Details**
|
||||
*
|
||||
* This function allows you to apply a specific `LogLevel` locally to an
|
||||
* `Effect` workflow. Once the workflow completes, the `LogLevel` reverts to its
|
||||
* previous state.
|
||||
*
|
||||
* **When to Use**
|
||||
*
|
||||
* This is particularly useful when you want to adjust the verbosity of logging
|
||||
* for specific parts of your program without affecting the global log level.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("message1")
|
||||
* yield* Effect.gen(function*() {
|
||||
* yield* Effect.log("message2")
|
||||
* yield* Effect.log("message3")
|
||||
* }).pipe(LogLevel.locally(LogLevel.Warning))
|
||||
* })
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=INFO fiber=#0 message=message1
|
||||
* // timestamp=... level=WARN fiber=#0 message=message2
|
||||
* // timestamp=... level=WARN fiber=#0 message=message3
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const locally: {
|
||||
/**
|
||||
* Temporarily sets a `LogLevel` for an `Effect` workflow.
|
||||
*
|
||||
* **Details**
|
||||
*
|
||||
* This function allows you to apply a specific `LogLevel` locally to an
|
||||
* `Effect` workflow. Once the workflow completes, the `LogLevel` reverts to its
|
||||
* previous state.
|
||||
*
|
||||
* **When to Use**
|
||||
*
|
||||
* This is particularly useful when you want to adjust the verbosity of logging
|
||||
* for specific parts of your program without affecting the global log level.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("message1")
|
||||
* yield* Effect.gen(function*() {
|
||||
* yield* Effect.log("message2")
|
||||
* yield* Effect.log("message3")
|
||||
* }).pipe(LogLevel.locally(LogLevel.Warning))
|
||||
* })
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=INFO fiber=#0 message=message1
|
||||
* // timestamp=... level=WARN fiber=#0 message=message2
|
||||
* // timestamp=... level=WARN fiber=#0 message=message3
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(self: LogLevel): <A, E, R>(use: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
||||
/**
|
||||
* Temporarily sets a `LogLevel` for an `Effect` workflow.
|
||||
*
|
||||
* **Details**
|
||||
*
|
||||
* This function allows you to apply a specific `LogLevel` locally to an
|
||||
* `Effect` workflow. Once the workflow completes, the `LogLevel` reverts to its
|
||||
* previous state.
|
||||
*
|
||||
* **When to Use**
|
||||
*
|
||||
* This is particularly useful when you want to adjust the verbosity of logging
|
||||
* for specific parts of your program without affecting the global log level.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("message1")
|
||||
* yield* Effect.gen(function*() {
|
||||
* yield* Effect.log("message2")
|
||||
* yield* Effect.log("message3")
|
||||
* }).pipe(LogLevel.locally(LogLevel.Warning))
|
||||
* })
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=INFO fiber=#0 message=message1
|
||||
* // timestamp=... level=WARN fiber=#0 message=message2
|
||||
* // timestamp=... level=WARN fiber=#0 message=message3
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A, E, R>(use: Effect.Effect<A, E, R>, self: LogLevel): Effect.Effect<A, E, R>
|
||||
} = dual(
|
||||
2,
|
||||
<A, E, R>(use: Effect.Effect<A, E, R>, self: LogLevel): Effect.Effect<A, E, R> =>
|
||||
core.fiberRefLocally(use, core.currentLogLevel, self)
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category instances
|
||||
*/
|
||||
export const Order: order.Order<LogLevel> = pipe(
|
||||
number.Order,
|
||||
order.mapInput((level: LogLevel) => level.ordinal)
|
||||
)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
export const lessThan: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(that: LogLevel): (self: LogLevel) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(self: LogLevel, that: LogLevel): boolean
|
||||
} = order.lessThan(Order)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
export const lessThanEqual: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(that: LogLevel): (self: LogLevel) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(self: LogLevel, that: LogLevel): boolean
|
||||
} = order.lessThanOrEqualTo(Order)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
export const greaterThan: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(that: LogLevel): (self: LogLevel) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(self: LogLevel, that: LogLevel): boolean
|
||||
} = order.greaterThan(Order)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
export const greaterThanEqual: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(that: LogLevel): (self: LogLevel) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category ordering
|
||||
*/
|
||||
(self: LogLevel, that: LogLevel): boolean
|
||||
} = order.greaterThanOrEqualTo(Order)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category conversions
|
||||
*/
|
||||
export const fromLiteral = (literal: Literal): LogLevel => {
|
||||
switch (literal) {
|
||||
case "All":
|
||||
return All
|
||||
case "Debug":
|
||||
return Debug
|
||||
case "Error":
|
||||
return Error
|
||||
case "Fatal":
|
||||
return Fatal
|
||||
case "Info":
|
||||
return Info
|
||||
case "Trace":
|
||||
return Trace
|
||||
case "None":
|
||||
return None
|
||||
case "Warning":
|
||||
return Warning
|
||||
}
|
||||
}
|
||||
25
_node_modules/effect/src/LogSpan.ts
generated
Normal file
25
_node_modules/effect/src/LogSpan.ts
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/logSpan.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface LogSpan {
|
||||
readonly label: string
|
||||
readonly startTime: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (label: string, startTime: number) => LogSpan = internal.make
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category destructors
|
||||
*/
|
||||
export const render: (now: number) => (self: LogSpan) => string = internal.render
|
||||
863
_node_modules/effect/src/Logger.ts
generated
Normal file
863
_node_modules/effect/src/Logger.ts
generated
Normal file
@@ -0,0 +1,863 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type { DurationInput } from "./Duration.js"
|
||||
import type { Effect } from "./Effect.js"
|
||||
import type * as FiberId from "./FiberId.js"
|
||||
import type * as FiberRefs from "./FiberRefs.js"
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import type * as HashMap from "./HashMap.js"
|
||||
import * as fiberRuntime from "./internal/fiberRuntime.js"
|
||||
import * as circular from "./internal/layer/circular.js"
|
||||
import * as internalCircular from "./internal/logger-circular.js"
|
||||
import * as internal from "./internal/logger.js"
|
||||
import type * as Layer from "./Layer.js"
|
||||
import type * as List from "./List.js"
|
||||
import type * as LogLevel from "./LogLevel.js"
|
||||
import type * as LogSpan from "./LogSpan.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type { Scope } from "./Scope.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const LoggerTypeId: unique symbol = internal.LoggerTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type LoggerTypeId = typeof LoggerTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Logger<in Message, out Output> extends Logger.Variance<Message, Output>, Pipeable {
|
||||
log(options: Logger.Options<Message>): Output
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Logger {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in Message, out Output> {
|
||||
readonly [LoggerTypeId]: {
|
||||
readonly _Message: Types.Contravariant<Message>
|
||||
readonly _Output: Types.Covariant<Output>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Options<out Message> {
|
||||
readonly fiberId: FiberId.FiberId
|
||||
readonly logLevel: LogLevel.LogLevel
|
||||
readonly message: Message
|
||||
readonly cause: Cause.Cause<unknown>
|
||||
readonly context: FiberRefs.FiberRefs
|
||||
readonly spans: List.List<LogSpan.LogSpan>
|
||||
readonly annotations: HashMap.HashMap<string, unknown>
|
||||
readonly date: Date
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom logger that formats log messages according to the provided
|
||||
* function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger, LogLevel } from "effect"
|
||||
*
|
||||
* const logger = Logger.make(({ logLevel, message }) => {
|
||||
* globalThis.console.log(`[${logLevel.label}] ${message}`)
|
||||
* })
|
||||
*
|
||||
* const task1 = Effect.logDebug("task1 done")
|
||||
* const task2 = Effect.logDebug("task2 done")
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("start")
|
||||
* yield* task1
|
||||
* yield* task2
|
||||
* yield* Effect.log("done")
|
||||
* }).pipe(
|
||||
* Logger.withMinimumLogLevel(LogLevel.Debug),
|
||||
* Effect.provide(Logger.replace(Logger.defaultLogger, logger))
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // [INFO] start
|
||||
* // [DEBUG] task1 done
|
||||
* // [DEBUG] task2 done
|
||||
* // [INFO] done
|
||||
* ```
|
||||
*
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const make: <Message, Output>(log: (options: Logger.Options<Message>) => Output) => Logger<Message, Output> =
|
||||
internal.makeLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const add: <B>(logger: Logger<unknown, B>) => Layer.Layer<never> = circular.addLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const addEffect: <A, E, R>(effect: Effect<Logger<unknown, A>, E, R>) => Layer.Layer<never, E, R> =
|
||||
circular.addLoggerEffect
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const addScoped: <A, E, R>(
|
||||
effect: Effect<Logger<unknown, A>, E, R>
|
||||
) => Layer.Layer<never, E, Exclude<R, Scope>> = circular.addLoggerScoped
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapInput: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Message, Message2>(f: (message: Message2) => Message): <Output>(self: Logger<Message, Output>) => Logger<Message2, Output>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Output, Message, Message2>(self: Logger<Message, Output>, f: (message: Message2) => Message): Logger<Message2, Output>
|
||||
} = internal.mapInput
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const mapInputOptions: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Message, Message2>(f: (options: Logger.Options<Message2>) => Logger.Options<Message>): <Output>(self: Logger<Message, Output>) => Logger<Message2, Output>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Output, Message, Message2>(
|
||||
self: Logger<Message, Output>,
|
||||
f: (options: Logger.Options<Message2>) => Logger.Options<Message>
|
||||
): Logger<Message2, Output>
|
||||
} = internal.mapInputOptions
|
||||
|
||||
/**
|
||||
* Returns a version of this logger that only logs messages when the log level
|
||||
* satisfies the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
export const filterLogLevel: {
|
||||
/**
|
||||
* Returns a version of this logger that only logs messages when the log level
|
||||
* satisfies the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
(f: (logLevel: LogLevel.LogLevel) => boolean): <Message, Output>(self: Logger<Message, Output>) => Logger<Message, Option.Option<Output>>
|
||||
/**
|
||||
* Returns a version of this logger that only logs messages when the log level
|
||||
* satisfies the specified predicate.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category filtering
|
||||
*/
|
||||
<Message, Output>(self: Logger<Message, Output>, f: (logLevel: LogLevel.LogLevel) => boolean): Logger<Message, Option.Option<Output>>
|
||||
} = internal.filterLogLevel
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const map: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Output, Output2>(f: (output: Output) => Output2): <Message>(self: Logger<Message, Output>) => Logger<Message, Output2>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Message, Output, Output2>(self: Logger<Message, Output>, f: (output: Output) => Output2): Logger<Message, Output2>
|
||||
} = internal.map
|
||||
|
||||
/**
|
||||
* Creates a batched logger that groups log messages together and processes them
|
||||
* in intervals.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Console, Effect, Logger } from "effect"
|
||||
*
|
||||
* const LoggerLive = Logger.replaceScoped(
|
||||
* Logger.defaultLogger,
|
||||
* Logger.logfmtLogger.pipe(
|
||||
* Logger.batched("500 millis", (messages) => Console.log("BATCH", `[\n${messages.join("\n")}\n]`))
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("one")
|
||||
* yield* Effect.log("two")
|
||||
* yield* Effect.log("three")
|
||||
* }).pipe(Effect.provide(LoggerLive))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // BATCH [
|
||||
* // timestamp=... level=INFO fiber=#0 message=one
|
||||
* // timestamp=... level=INFO fiber=#0 message=two
|
||||
* // timestamp=... level=INFO fiber=#0 message=three
|
||||
* // ]
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
export const batched: {
|
||||
/**
|
||||
* Creates a batched logger that groups log messages together and processes them
|
||||
* in intervals.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Console, Effect, Logger } from "effect"
|
||||
*
|
||||
* const LoggerLive = Logger.replaceScoped(
|
||||
* Logger.defaultLogger,
|
||||
* Logger.logfmtLogger.pipe(
|
||||
* Logger.batched("500 millis", (messages) => Console.log("BATCH", `[\n${messages.join("\n")}\n]`))
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("one")
|
||||
* yield* Effect.log("two")
|
||||
* yield* Effect.log("three")
|
||||
* }).pipe(Effect.provide(LoggerLive))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // BATCH [
|
||||
* // timestamp=... level=INFO fiber=#0 message=one
|
||||
* // timestamp=... level=INFO fiber=#0 message=two
|
||||
* // timestamp=... level=INFO fiber=#0 message=three
|
||||
* // ]
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Output, R>(
|
||||
window: DurationInput,
|
||||
f: (messages: Array<Types.NoInfer<Output>>) => Effect<void, never, R>
|
||||
): <Message>(self: Logger<Message, Output>) => Effect<Logger<Message, void>, never, R | Scope>
|
||||
/**
|
||||
* Creates a batched logger that groups log messages together and processes them
|
||||
* in intervals.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Console, Effect, Logger } from "effect"
|
||||
*
|
||||
* const LoggerLive = Logger.replaceScoped(
|
||||
* Logger.defaultLogger,
|
||||
* Logger.logfmtLogger.pipe(
|
||||
* Logger.batched("500 millis", (messages) => Console.log("BATCH", `[\n${messages.join("\n")}\n]`))
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("one")
|
||||
* yield* Effect.log("two")
|
||||
* yield* Effect.log("three")
|
||||
* }).pipe(Effect.provide(LoggerLive))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // BATCH [
|
||||
* // timestamp=... level=INFO fiber=#0 message=one
|
||||
* // timestamp=... level=INFO fiber=#0 message=two
|
||||
* // timestamp=... level=INFO fiber=#0 message=three
|
||||
* // ]
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category mapping
|
||||
*/
|
||||
<Message, Output, R>(
|
||||
self: Logger<Message, Output>,
|
||||
window: DurationInput,
|
||||
f: (messages: Array<Types.NoInfer<Output>>) => Effect<void, never, R>
|
||||
): Effect<Logger<Message, void>, never, Scope | R>
|
||||
} = fiberRuntime.batchedLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category console
|
||||
*/
|
||||
export const withConsoleLog: <M, O>(self: Logger<M, O>) => Logger<M, void> = fiberRuntime.loggerWithConsoleLog
|
||||
|
||||
/**
|
||||
* Takes a `Logger<M, O>` and returns a logger that calls the respective `Console` method
|
||||
* based on the log level.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Logger, Effect } from "effect"
|
||||
*
|
||||
* const loggerLayer = Logger.replace(
|
||||
* Logger.defaultLogger,
|
||||
* Logger.withLeveledConsole(Logger.stringLogger),
|
||||
* )
|
||||
*
|
||||
* Effect.gen(function* () {
|
||||
* yield* Effect.logError("an error")
|
||||
* yield* Effect.logInfo("an info")
|
||||
* }).pipe(Effect.provide(loggerLayer))
|
||||
* ```
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @category console
|
||||
*/
|
||||
export const withLeveledConsole: <M, O>(self: Logger<M, O>) => Logger<M, void> = fiberRuntime.loggerWithLeveledLog
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category console
|
||||
*/
|
||||
export const withConsoleError: <M, O>(self: Logger<M, O>) => Logger<M, void> = fiberRuntime.loggerWithConsoleError
|
||||
|
||||
/**
|
||||
* A logger that does nothing in response to logging events.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const none: Logger<unknown, void> = internal.none
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const remove: <A>(logger: Logger<unknown, A>) => Layer.Layer<never> = circular.removeLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const replace: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<B>(that: Logger<unknown, B>): <A>(self: Logger<unknown, A>) => Layer.Layer<never>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<A, B>(self: Logger<unknown, A>, that: Logger<unknown, B>): Layer.Layer<never>
|
||||
} = circular.replaceLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const replaceEffect: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<B, E, R>(that: Effect<Logger<unknown, B>, E, R>): <A>(self: Logger<unknown, A>) => Layer.Layer<never, E, R>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<A, B, E, R>(self: Logger<unknown, A>, that: Effect<Logger<unknown, B>, E, R>): Layer.Layer<never, E, R>
|
||||
} = circular.replaceLoggerEffect
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const replaceScoped: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<B, E, R>(that: Effect<Logger<unknown, B>, E, R>): <A>(self: Logger<unknown, A>) => Layer.Layer<never, E, Exclude<R, Scope>>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<A, B, E, R>(self: Logger<unknown, A>, that: Effect<Logger<unknown, B>, E, R>): Layer.Layer<never, E, Exclude<R, Scope>>
|
||||
} = circular.replaceLoggerScoped
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const simple: <A, B>(log: (a: A) => B) => Logger<A, B> = internal.simple
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const succeed: <A>(value: A) => Logger<unknown, A> = internal.succeed
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sync: <A>(evaluate: LazyArg<A>) => Logger<unknown, A> = internal.sync
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const test: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<Message>(input: Message): <Output>(self: Logger<Message, Output>) => Output
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<Message, Output>(self: Logger<Message, Output>, input: Message): Output
|
||||
} = internalCircular.test
|
||||
|
||||
/**
|
||||
* Sets the minimum log level for subsequent logging operations, allowing
|
||||
* control over which log messages are displayed based on their severity.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=DEBUG fiber=#0 message=message1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const withMinimumLogLevel: {
|
||||
/**
|
||||
* Sets the minimum log level for subsequent logging operations, allowing
|
||||
* control over which log messages are displayed based on their severity.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=DEBUG fiber=#0 message=message1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
(level: LogLevel.LogLevel): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
||||
/**
|
||||
* Sets the minimum log level for subsequent logging operations, allowing
|
||||
* control over which log messages are displayed based on their severity.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug))
|
||||
*
|
||||
* Effect.runFork(program)
|
||||
* // timestamp=... level=DEBUG fiber=#0 message=message1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
<A, E, R>(self: Effect<A, E, R>, level: LogLevel.LogLevel): Effect<A, E, R>
|
||||
} = circular.withMinimumLogLevel
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category tracing
|
||||
*/
|
||||
export const withSpanAnnotations: <Message, Output>(self: Logger<Message, Output>) => Logger<Message, Output> =
|
||||
fiberRuntime.loggerWithSpanAnnotations
|
||||
|
||||
/**
|
||||
* Combines this logger with the specified logger to produce a new logger that
|
||||
* logs to both this logger and that logger.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Combines this logger with the specified logger to produce a new logger that
|
||||
* logs to both this logger and that logger.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message2, Output2>(that: Logger<Message2, Output2>): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, [Output, Output2]>
|
||||
/**
|
||||
* Combines this logger with the specified logger to produce a new logger that
|
||||
* logs to both this logger and that logger.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message, Output, Message2, Output2>(self: Logger<Message, Output>, that: Logger<Message2, Output2>): Logger<Message & Message2, [Output, Output2]>
|
||||
} = internal.zip
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipLeft: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message2, Output2>(that: Logger<Message2, Output2>): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, Output>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message, Output, Message2, Output2>(self: Logger<Message, Output>, that: Logger<Message2, Output2>): Logger<Message & Message2, Output>
|
||||
} = internal.zipLeft
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
export const zipRight: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message2, Output2>(that: Logger<Message2, Output2>): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, Output2>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category zipping
|
||||
*/
|
||||
<Message, Output, Message2, Output2>(self: Logger<Message, Output>, that: Logger<Message2, Output2>): Logger<Message & Message2, Output2>
|
||||
} = internal.zipRight
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const defaultLogger: Logger<unknown, void> = fiberRuntime.defaultLogger
|
||||
|
||||
/**
|
||||
* The `jsonLogger` logger formats log entries as JSON objects, making them easy to
|
||||
* integrate with logging systems that consume JSON data.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.json)))
|
||||
* // {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"}
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const jsonLogger: Logger<unknown, string> = internal.jsonLogger
|
||||
|
||||
/**
|
||||
* This logger outputs logs in a human-readable format that is easy to read
|
||||
* during development or in a production console.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.logFmt)))
|
||||
* // timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const logfmtLogger: Logger<unknown, string> = internal.logfmtLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const stringLogger: Logger<unknown, string> = internal.stringLogger
|
||||
|
||||
/**
|
||||
* The pretty logger utilizes the capabilities of the console API to generate
|
||||
* visually engaging and color-enhanced log outputs. This feature is
|
||||
* particularly useful for improving the readability of log messages during
|
||||
* development and debugging processes.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.pretty)))
|
||||
* // green --v v-- bold and cyan
|
||||
* // [07:51:54.434] INFO (#0) myspan=1ms: message1
|
||||
* // message2
|
||||
* // v-- bold
|
||||
* // key2: value2
|
||||
* // key1: value1
|
||||
* ```
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const prettyLogger: (
|
||||
options?: {
|
||||
readonly colors?: "auto" | boolean | undefined
|
||||
readonly stderr?: boolean | undefined
|
||||
readonly formatDate?: ((date: Date) => string) | undefined
|
||||
readonly mode?: "browser" | "tty" | "auto" | undefined
|
||||
}
|
||||
) => Logger<unknown, void> = internal.prettyLogger
|
||||
|
||||
/**
|
||||
* A default version of the pretty logger.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const prettyLoggerDefault: Logger<unknown, void> = internal.prettyLoggerDefault
|
||||
|
||||
/**
|
||||
* The structured logger provides detailed log outputs, structured in a way that
|
||||
* retains comprehensive traceability of the events, suitable for deeper
|
||||
* analysis and troubleshooting.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.structured)))
|
||||
* // {
|
||||
* // message: [ 'message1', 'message2' ],
|
||||
* // logLevel: 'INFO',
|
||||
* // timestamp: '2024-07-09T14:05:41.623Z',
|
||||
* // cause: undefined,
|
||||
* // annotations: { key2: 'value2', key1: 'value1' },
|
||||
* // spans: { myspan: 0 },
|
||||
* // fiberId: '#0'
|
||||
* // }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const structuredLogger: Logger<
|
||||
unknown,
|
||||
{
|
||||
readonly logLevel: string
|
||||
readonly fiberId: string
|
||||
readonly timestamp: string
|
||||
readonly message: unknown
|
||||
readonly cause: string | undefined
|
||||
readonly annotations: Record<string, unknown>
|
||||
readonly spans: Record<string, number>
|
||||
}
|
||||
> = internal.structuredLogger
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const tracerLogger: Logger<unknown, void> = fiberRuntime.tracerLogger
|
||||
|
||||
/**
|
||||
* The `json` logger formats log entries as JSON objects, making them easy to
|
||||
* integrate with logging systems that consume JSON data.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.json)))
|
||||
* // {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"}
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const json: Layer.Layer<never> = replace(fiberRuntime.defaultLogger, fiberRuntime.jsonLogger)
|
||||
|
||||
/**
|
||||
* This logger outputs logs in a human-readable format that is easy to read
|
||||
* during development or in a production console.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.logFmt)))
|
||||
* // timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const logFmt: Layer.Layer<never> = replace(fiberRuntime.defaultLogger, fiberRuntime.logFmtLogger)
|
||||
|
||||
/**
|
||||
* The pretty logger utilizes the capabilities of the console API to generate
|
||||
* visually engaging and color-enhanced log outputs. This feature is
|
||||
* particularly useful for improving the readability of log messages during
|
||||
* development and debugging processes.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.pretty)))
|
||||
* // green --v v-- bold and cyan
|
||||
* // [07:51:54.434] INFO (#0) myspan=1ms: message1
|
||||
* // message2
|
||||
* // v-- bold
|
||||
* // key2: value2
|
||||
* // key1: value1
|
||||
* ```
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const pretty: Layer.Layer<never> = replace(fiberRuntime.defaultLogger, fiberRuntime.prettyLogger)
|
||||
|
||||
/**
|
||||
* The structured logger provides detailed log outputs, structured in a way that
|
||||
* retains comprehensive traceability of the events, suitable for deeper
|
||||
* analysis and troubleshooting.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger } from "effect"
|
||||
*
|
||||
* const program = Effect.log("message1", "message2").pipe(
|
||||
* Effect.annotateLogs({ key1: "value1", key2: "value2" }),
|
||||
* Effect.withLogSpan("myspan")
|
||||
* )
|
||||
*
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.structured)))
|
||||
* // {
|
||||
* // message: [ 'message1', 'message2' ],
|
||||
* // logLevel: 'INFO',
|
||||
* // timestamp: '2024-07-09T14:05:41.623Z',
|
||||
* // cause: undefined,
|
||||
* // annotations: { key2: 'value2', key1: 'value1' },
|
||||
* // spans: { myspan: 0 },
|
||||
* // fiberId: '#0'
|
||||
* // }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const structured: Layer.Layer<never> = replace(fiberRuntime.defaultLogger, fiberRuntime.structuredLogger)
|
||||
|
||||
/**
|
||||
* Sets the minimum log level for logging operations, allowing control over
|
||||
* which log messages are displayed based on their severity.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Logger, LogLevel } from "effect"
|
||||
*
|
||||
* const program = Effect.gen(function*() {
|
||||
* yield* Effect.log("Executing task...")
|
||||
* yield* Effect.sleep("100 millis")
|
||||
* console.log("task done")
|
||||
* })
|
||||
*
|
||||
* // Logging disabled using a layer
|
||||
* Effect.runFork(program.pipe(Effect.provide(Logger.minimumLogLevel(LogLevel.None))))
|
||||
* // task done
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const minimumLogLevel: (level: LogLevel.LogLevel) => Layer.Layer<never> = circular.minimumLogLevel
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Logger`, otherwise returns `false`.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isLogger: (u: unknown) => u is Logger<unknown, unknown> = internal.isLogger
|
||||
298
_node_modules/effect/src/Mailbox.ts
generated
Normal file
298
_node_modules/effect/src/Mailbox.ts
generated
Normal file
@@ -0,0 +1,298 @@
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
*/
|
||||
import type { Cause, NoSuchElementException } from "./Cause.js"
|
||||
import type { Channel } from "./Channel.js"
|
||||
import type { Chunk } from "./Chunk.js"
|
||||
import type { Effect } from "./Effect.js"
|
||||
import type { Exit } from "./Exit.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import * as internal from "./internal/mailbox.js"
|
||||
import type { Option } from "./Option.js"
|
||||
import { hasProperty } from "./Predicate.js"
|
||||
import type { Scope } from "./Scope.js"
|
||||
import type { Stream } from "./Stream.js"
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category type ids
|
||||
*/
|
||||
export const TypeId: unique symbol = internal.TypeId
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category type ids
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category type ids
|
||||
*/
|
||||
export const ReadonlyTypeId: unique symbol = internal.ReadonlyTypeId
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category type ids
|
||||
*/
|
||||
export type ReadonlyTypeId = typeof ReadonlyTypeId
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category guards
|
||||
*/
|
||||
export const isMailbox = <A = unknown, E = unknown>(u: unknown): u is Mailbox<A, E> => hasProperty(u, TypeId)
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category guards
|
||||
*/
|
||||
export const isReadonlyMailbox = <A = unknown, E = unknown>(u: unknown): u is ReadonlyMailbox<A, E> =>
|
||||
hasProperty(u, ReadonlyTypeId)
|
||||
|
||||
/**
|
||||
* A `Mailbox` is a queue that can be signaled to be done or failed.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category models
|
||||
*/
|
||||
export interface Mailbox<in out A, in out E = never> extends ReadonlyMailbox<A, E> {
|
||||
readonly [TypeId]: TypeId
|
||||
/**
|
||||
* Add a message to the mailbox. Returns `false` if the mailbox is done.
|
||||
*/
|
||||
readonly offer: (message: A) => Effect<boolean>
|
||||
/**
|
||||
* Add a message to the mailbox. Returns `false` if the mailbox is done.
|
||||
*/
|
||||
readonly unsafeOffer: (message: A) => boolean
|
||||
/**
|
||||
* Add multiple messages to the mailbox. Returns the remaining messages that
|
||||
* were not added.
|
||||
*/
|
||||
readonly offerAll: (messages: Iterable<A>) => Effect<Chunk<A>>
|
||||
/**
|
||||
* Add multiple messages to the mailbox. Returns the remaining messages that
|
||||
* were not added.
|
||||
*/
|
||||
readonly unsafeOfferAll: (messages: Iterable<A>) => Chunk<A>
|
||||
/**
|
||||
* Fail the mailbox with an error. If the mailbox is already done, `false` is
|
||||
* returned.
|
||||
*/
|
||||
readonly fail: (error: E) => Effect<boolean>
|
||||
/**
|
||||
* Fail the mailbox with a cause. If the mailbox is already done, `false` is
|
||||
* returned.
|
||||
*/
|
||||
readonly failCause: (cause: Cause<E>) => Effect<boolean>
|
||||
/**
|
||||
* Signal that the mailbox is complete. If the mailbox is already done, `false` is
|
||||
* returned.
|
||||
*/
|
||||
readonly end: Effect<boolean>
|
||||
/**
|
||||
* Signal that the mailbox is done. If the mailbox is already done, `false` is
|
||||
* returned.
|
||||
*/
|
||||
readonly done: (exit: Exit<void, E>) => Effect<boolean>
|
||||
/**
|
||||
* Signal that the mailbox is done. If the mailbox is already done, `false` is
|
||||
* returned.
|
||||
*/
|
||||
readonly unsafeDone: (exit: Exit<void, E>) => boolean
|
||||
/**
|
||||
* Shutdown the mailbox, canceling any pending operations.
|
||||
* If the mailbox is already done, `false` is returned.
|
||||
*/
|
||||
readonly shutdown: Effect<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* A `ReadonlyMailbox` represents a mailbox that can only be read from.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category models
|
||||
*/
|
||||
export interface ReadonlyMailbox<out A, out E = never>
|
||||
extends Effect<readonly [messages: Chunk<A>, done: boolean], E>, Inspectable
|
||||
{
|
||||
readonly [ReadonlyTypeId]: ReadonlyTypeId
|
||||
/**
|
||||
* Take all messages from the mailbox, returning an empty Chunk if the mailbox
|
||||
* is empty or done.
|
||||
*/
|
||||
readonly clear: Effect<Chunk<A>, E>
|
||||
/**
|
||||
* Take all messages from the mailbox, or wait for messages to be available.
|
||||
*
|
||||
* If the mailbox is done, the `done` flag will be `true`. If the mailbox
|
||||
* fails, the Effect will fail with the error.
|
||||
*/
|
||||
readonly takeAll: Effect<readonly [messages: Chunk<A>, done: boolean], E>
|
||||
/**
|
||||
* Take a specified number of messages from the mailbox. It will only take
|
||||
* up to the capacity of the mailbox.
|
||||
*
|
||||
* If the mailbox is done, the `done` flag will be `true`. If the mailbox
|
||||
* fails, the Effect will fail with the error.
|
||||
*/
|
||||
readonly takeN: (n: number) => Effect<readonly [messages: Chunk<A>, done: boolean], E>
|
||||
/**
|
||||
* Take a single message from the mailbox, or wait for a message to be
|
||||
* available.
|
||||
*
|
||||
* If the mailbox is done, it will fail with `NoSuchElementException`. If the
|
||||
* mailbox fails, the Effect will fail with the error.
|
||||
*/
|
||||
readonly take: Effect<A, E | NoSuchElementException>
|
||||
/** Wait for the mailbox to be done. */
|
||||
readonly await: Effect<void, E>
|
||||
/**
|
||||
* Check the size of the mailbox.
|
||||
*
|
||||
* If the mailbox is complete, it will return `None`.
|
||||
*/
|
||||
readonly size: Effect<Option<number>>
|
||||
/**
|
||||
* Check the size of the mailbox.
|
||||
*
|
||||
* If the mailbox is complete, it will return `None`.
|
||||
*/
|
||||
readonly unsafeSize: () => Option<number>
|
||||
}
|
||||
|
||||
/**
|
||||
* A `Mailbox` is a queue that can be signaled to be done or failed.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category constructors
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Effect, Mailbox } from "effect"
|
||||
*
|
||||
* Effect.gen(function*() {
|
||||
* const mailbox = yield* Mailbox.make<number, string>()
|
||||
*
|
||||
* // add messages to the mailbox
|
||||
* yield* mailbox.offer(1)
|
||||
* yield* mailbox.offer(2)
|
||||
* yield* mailbox.offerAll([3, 4, 5])
|
||||
*
|
||||
* // take messages from the mailbox
|
||||
* const [messages, done] = yield* mailbox.takeAll
|
||||
* assert.deepStrictEqual(messages, [1, 2, 3, 4, 5])
|
||||
* assert.strictEqual(done, false)
|
||||
*
|
||||
* // signal that the mailbox is done
|
||||
* yield* mailbox.end
|
||||
* const [messages2, done2] = yield* mailbox.takeAll
|
||||
* assert.deepStrictEqual(messages2, [])
|
||||
* assert.strictEqual(done2, true)
|
||||
*
|
||||
* // signal that the mailbox has failed
|
||||
* yield* mailbox.fail("boom")
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export const make: <A, E = never>(
|
||||
capacity?: number | {
|
||||
readonly capacity?: number
|
||||
readonly strategy?: "suspend" | "dropping" | "sliding"
|
||||
} | undefined
|
||||
) => Effect<Mailbox<A, E>> = internal.make
|
||||
|
||||
/**
|
||||
* Run an `Effect` into a `Mailbox`, where success ends the mailbox and failure
|
||||
* fails the mailbox.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category combinators
|
||||
*/
|
||||
export const into: {
|
||||
/**
|
||||
* Run an `Effect` into a `Mailbox`, where success ends the mailbox and failure
|
||||
* fails the mailbox.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category combinators
|
||||
*/
|
||||
<A, E>(self: Mailbox<A, E>): <AX, EX extends E, RX>(effect: Effect<AX, EX, RX>) => Effect<boolean, never, RX>
|
||||
/**
|
||||
* Run an `Effect` into a `Mailbox`, where success ends the mailbox and failure
|
||||
* fails the mailbox.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category combinators
|
||||
*/
|
||||
<AX, E, EX extends E, RX, A>(effect: Effect<AX, EX, RX>, self: Mailbox<A, E>): Effect<boolean, never, RX>
|
||||
} = internal.into
|
||||
|
||||
/**
|
||||
* Create a `Channel` from a `Mailbox`.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category conversions
|
||||
*/
|
||||
export const toChannel: <A, E>(self: ReadonlyMailbox<A, E>) => Channel<Chunk<A>, unknown, E> = internal.toChannel
|
||||
|
||||
/**
|
||||
* Create a `Stream` from a `Mailbox`.
|
||||
*
|
||||
* @since 3.8.0
|
||||
* @experimental
|
||||
* @category conversions
|
||||
*/
|
||||
export const toStream: <A, E>(self: ReadonlyMailbox<A, E>) => Stream<A, E> = internal.toStream
|
||||
|
||||
/**
|
||||
* Create a `ReadonlyMailbox` from a `Stream`.
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @experimental
|
||||
* @category conversions
|
||||
*/
|
||||
export const fromStream: {
|
||||
/**
|
||||
* Create a `ReadonlyMailbox` from a `Stream`.
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @experimental
|
||||
* @category conversions
|
||||
*/
|
||||
(
|
||||
options?: {
|
||||
readonly capacity?: number | undefined
|
||||
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
||||
}
|
||||
): <A, E, R>(self: Stream<A, E, R>) => Effect<ReadonlyMailbox<A, E>, never, R | Scope>
|
||||
/**
|
||||
* Create a `ReadonlyMailbox` from a `Stream`.
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @experimental
|
||||
* @category conversions
|
||||
*/
|
||||
<A, E, R>(
|
||||
self: Stream<A, E, R>,
|
||||
options?: {
|
||||
readonly capacity?: number | undefined
|
||||
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
||||
}
|
||||
): Effect<ReadonlyMailbox<A, E>, never, R | Scope>
|
||||
} = internal.fromStream
|
||||
180
_node_modules/effect/src/ManagedRuntime.ts
generated
Normal file
180
_node_modules/effect/src/ManagedRuntime.ts
generated
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import type * as Fiber from "./Fiber.js"
|
||||
import * as internal from "./internal/managedRuntime.js"
|
||||
import * as circular from "./internal/managedRuntime/circular.js"
|
||||
import type * as Layer from "./Layer.js"
|
||||
import type * as Runtime from "./Runtime.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 3.9.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const TypeId: unique symbol = circular.TypeId as TypeId
|
||||
|
||||
/**
|
||||
* @since 3.9.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* Checks if the provided argument is a `ManagedRuntime`.
|
||||
*
|
||||
* @since 3.9.0
|
||||
* @category guards
|
||||
*/
|
||||
export const isManagedRuntime: (input: unknown) => input is ManagedRuntime<unknown, unknown> = internal.isManagedRuntime
|
||||
|
||||
/**
|
||||
* @since 3.4.0
|
||||
*/
|
||||
export declare namespace ManagedRuntime {
|
||||
/**
|
||||
* @category type-level
|
||||
* @since 3.4.0
|
||||
*/
|
||||
export type Context<T extends ManagedRuntime<never, any>> = [T] extends [ManagedRuntime<infer R, infer _E>] ? R
|
||||
: never
|
||||
/**
|
||||
* @category type-level
|
||||
* @since 3.4.0
|
||||
*/
|
||||
export type Error<T extends ManagedRuntime<never, any>> = [T] extends [ManagedRuntime<infer _R, infer E>] ? E : never
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface ManagedRuntime<in R, out ER> extends Effect.Effect<Runtime.Runtime<R>, ER> {
|
||||
readonly [TypeId]: TypeId
|
||||
readonly memoMap: Layer.MemoMap
|
||||
readonly runtimeEffect: Effect.Effect<Runtime.Runtime<R>, ER>
|
||||
readonly runtime: () => Promise<Runtime.Runtime<R>>
|
||||
|
||||
/**
|
||||
* Executes the effect using the provided Scheduler or using the global
|
||||
* Scheduler if not provided
|
||||
*/
|
||||
readonly runFork: <A, E>(
|
||||
self: Effect.Effect<A, E, R>,
|
||||
options?: Runtime.RunForkOptions
|
||||
) => Fiber.RuntimeFiber<A, E | ER>
|
||||
|
||||
/**
|
||||
* Executes the effect synchronously returning the exit.
|
||||
*
|
||||
* This method is effectful and should only be invoked at the edges of your
|
||||
* program.
|
||||
*/
|
||||
readonly runSyncExit: <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, ER | E>
|
||||
|
||||
/**
|
||||
* Executes the effect synchronously throwing in case of errors or async boundaries.
|
||||
*
|
||||
* This method is effectful and should only be invoked at the edges of your
|
||||
* program.
|
||||
*/
|
||||
readonly runSync: <A, E>(effect: Effect.Effect<A, E, R>) => A
|
||||
|
||||
/**
|
||||
* Executes the effect asynchronously, eventually passing the exit value to
|
||||
* the specified callback.
|
||||
*
|
||||
* This method is effectful and should only be invoked at the edges of your
|
||||
* program.
|
||||
*/
|
||||
readonly runCallback: <A, E>(
|
||||
effect: Effect.Effect<A, E, R>,
|
||||
options?: Runtime.RunCallbackOptions<A, E | ER> | undefined
|
||||
) => Runtime.Cancel<A, E | ER>
|
||||
|
||||
/**
|
||||
* Runs the `Effect`, returning a JavaScript `Promise` that will be resolved
|
||||
* with the value of the effect once the effect has been executed, or will be
|
||||
* rejected with the first error or exception throw by the effect.
|
||||
*
|
||||
* This method is effectful and should only be used at the edges of your
|
||||
* program.
|
||||
*/
|
||||
readonly runPromise: <A, E>(effect: Effect.Effect<A, E, R>, options?: {
|
||||
readonly signal?: AbortSignal | undefined
|
||||
}) => Promise<A>
|
||||
|
||||
/**
|
||||
* Runs the `Effect`, returning a JavaScript `Promise` that will be resolved
|
||||
* with the `Exit` state of the effect once the effect has been executed.
|
||||
*
|
||||
* This method is effectful and should only be used at the edges of your
|
||||
* program.
|
||||
*/
|
||||
readonly runPromiseExit: <A, E>(effect: Effect.Effect<A, E, R>, options?: {
|
||||
readonly signal?: AbortSignal | undefined
|
||||
}) => Promise<Exit.Exit<A, ER | E>>
|
||||
|
||||
/**
|
||||
* Dispose of the resources associated with the runtime.
|
||||
*/
|
||||
readonly dispose: () => Promise<void>
|
||||
|
||||
/**
|
||||
* Dispose of the resources associated with the runtime.
|
||||
*/
|
||||
readonly disposeEffect: Effect.Effect<void, never, never>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: ManagedRuntimeUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: ManagedRuntimeUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.9.0
|
||||
*/
|
||||
export interface ManagedRuntimeUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
ManagedRuntime?: () => Extract<A[Unify.typeSymbol], ManagedRuntime<any, any>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.9.0
|
||||
*/
|
||||
export interface ManagedRuntimeUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Layer into an ManagedRuntime, that can be used to run Effect's using
|
||||
* your services.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category runtime class
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Console, Effect, Layer, ManagedRuntime } from "effect"
|
||||
*
|
||||
* class Notifications extends Effect.Tag("Notifications")<
|
||||
* Notifications,
|
||||
* { readonly notify: (message: string) => Effect.Effect<void> }
|
||||
* >() {
|
||||
* static Live = Layer.succeed(this, { notify: (message) => Console.log(message) })
|
||||
* }
|
||||
*
|
||||
* async function main() {
|
||||
* const runtime = ManagedRuntime.make(Notifications.Live)
|
||||
* await runtime.runPromise(Notifications.notify("Hello, world!"))
|
||||
* await runtime.dispose()
|
||||
* }
|
||||
*
|
||||
* main()
|
||||
* ```
|
||||
*/
|
||||
export const make: <R, E>(
|
||||
layer: Layer.Layer<R, E, never>,
|
||||
memoMap?: Layer.MemoMap | undefined
|
||||
) => ManagedRuntime<R, E> = internal.make
|
||||
1493
_node_modules/effect/src/Match.ts
generated
Normal file
1493
_node_modules/effect/src/Match.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
103
_node_modules/effect/src/MergeDecision.ts
generated
Normal file
103
_node_modules/effect/src/MergeDecision.ts
generated
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import * as internal from "./internal/channel/mergeDecision.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MergeDecisionTypeId: unique symbol = internal.MergeDecisionTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MergeDecisionTypeId = typeof MergeDecisionTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MergeDecision<out R, in E0, in Z0, out E, out Z> extends MergeDecision.Variance<R, E0, Z0, E, Z> {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MergeDecision {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out R, in E0, in Z0, out E, out Z> {
|
||||
readonly [MergeDecisionTypeId]: {
|
||||
_R: Types.Covariant<R>
|
||||
_E0: Types.Contravariant<E0>
|
||||
_Z0: Types.Contravariant<Z0>
|
||||
_E: Types.Covariant<E>
|
||||
_Z: Types.Covariant<Z>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Done: <Z, E, R>(effect: Effect.Effect<Z, E, R>) => MergeDecision<R, unknown, unknown, E, Z> = internal.Done
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const Await: <R, E0, Z0, E, Z>(
|
||||
f: (exit: Exit.Exit<Z0, E0>) => Effect.Effect<Z, E, R>
|
||||
) => MergeDecision<R, E0, Z0, E, Z> = internal.Await
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const AwaitConst: <Z, E, R>(effect: Effect.Effect<Z, E, R>) => MergeDecision<R, unknown, unknown, E, Z> =
|
||||
internal.AwaitConst
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `MergeDecision`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMergeDecision: (u: unknown) => u is MergeDecision<unknown, unknown, unknown, unknown, unknown> =
|
||||
internal.isMergeDecision
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<R, E0, Z0, E, Z, Z2>(
|
||||
options: {
|
||||
readonly onDone: (effect: Effect.Effect<Z, E, R>) => Z2
|
||||
readonly onAwait: (f: (exit: Exit.Exit<Z0, E0>) => Effect.Effect<Z, E, R>) => Z2
|
||||
}
|
||||
): (self: MergeDecision<R, E0, Z0, E, Z>) => Z2
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<R, E0, Z0, E, Z, Z2>(
|
||||
self: MergeDecision<R, E0, Z0, E, Z>,
|
||||
options: {
|
||||
readonly onDone: (effect: Effect.Effect<Z, E, R>) => Z2
|
||||
readonly onAwait: (f: (exit: Exit.Exit<Z0, E0>) => Effect.Effect<Z, E, R>) => Z2
|
||||
}
|
||||
): Z2
|
||||
} = internal.match
|
||||
180
_node_modules/effect/src/MergeState.ts
generated
Normal file
180
_node_modules/effect/src/MergeState.ts
generated
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Either from "./Either.js"
|
||||
import type * as Exit from "./Exit.js"
|
||||
import type * as Fiber from "./Fiber.js"
|
||||
import * as internal from "./internal/channel/mergeState.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MergeStateTypeId: unique symbol = internal.MergeStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MergeStateTypeId = typeof MergeStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> =
|
||||
| BothRunning<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
| LeftDone<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
| RightDone<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MergeState {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Proto {
|
||||
readonly [MergeStateTypeId]: MergeStateTypeId
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BothRunning<_Env, out Err, out Err1, _Err2, out Elem, out Done, out Done1, _Done2>
|
||||
extends MergeState.Proto
|
||||
{
|
||||
readonly _tag: "BothRunning"
|
||||
readonly left: Fiber.Fiber<Either.Either<Elem, Done>, Err>
|
||||
readonly right: Fiber.Fiber<Either.Either<Elem, Done1>, Err1>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface LeftDone<out Env, _Err, in Err1, out Err2, _Elem, _Done, in Done1, out Done2>
|
||||
extends MergeState.Proto
|
||||
{
|
||||
readonly _tag: "LeftDone"
|
||||
f(exit: Exit.Exit<Done1, Err1>): Effect.Effect<Done2, Err2, Env>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface RightDone<out Env, in Err, _Err1, out Err2, _Elem, in Done, _Done1, out Done2>
|
||||
extends MergeState.Proto
|
||||
{
|
||||
readonly _tag: "RightDone"
|
||||
f(exit: Exit.Exit<Done, Err>): Effect.Effect<Done2, Err2, Env>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const BothRunning: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
left: Fiber.Fiber<Either.Either<Elem, Done>, Err>,
|
||||
right: Fiber.Fiber<Either.Either<Elem, Done1>, Err1>
|
||||
) => MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.BothRunning
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const LeftDone: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
f: (exit: Exit.Exit<Done1, Err1>) => Effect.Effect<Done2, Err2, Env>
|
||||
) => MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.LeftDone
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const RightDone: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
f: (exit: Exit.Exit<Done, Err>) => Effect.Effect<Done2, Err2, Env>
|
||||
) => MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.RightDone
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `MergeState`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMergeState: (
|
||||
u: unknown
|
||||
) => u is MergeState<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> = internal.isMergeState
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `MergeState` is a `BothRunning`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isBothRunning: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
self: MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
) => self is BothRunning<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.isBothRunning
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `MergeState` is a `LeftDone`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isLeftDone: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
self: MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
) => self is LeftDone<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.isLeftDone
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `MergeState` is a `RightDone`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isRightDone: <Env, Err, Err1, Err2, Elem, Done, Done1, Done2>(
|
||||
self: MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>
|
||||
) => self is RightDone<Env, Err, Err1, Err2, Elem, Done, Done1, Done2> = internal.isRightDone
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<Env, Err, Err1, Err2, Elem, Done, Done1, Done2, Z>(
|
||||
options: {
|
||||
readonly onBothRunning: (
|
||||
left: Fiber.Fiber<Either.Either<Elem, Done>, Err>,
|
||||
right: Fiber.Fiber<Either.Either<Elem, Done1>, Err1>
|
||||
) => Z
|
||||
readonly onLeftDone: (f: (exit: Exit.Exit<Done1, Err1>) => Effect.Effect<Done2, Err2, Env>) => Z
|
||||
readonly onRightDone: (f: (exit: Exit.Exit<Done, Err>) => Effect.Effect<Done2, Err2, Env>) => Z
|
||||
}
|
||||
): (self: MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>) => Z
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<Env, Err, Err1, Err2, Elem, Done, Done1, Done2, Z>(
|
||||
self: MergeState<Env, Err, Err1, Err2, Elem, Done, Done1, Done2>,
|
||||
options: {
|
||||
readonly onBothRunning: (
|
||||
left: Fiber.Fiber<Either.Either<Elem, Done>, Err>,
|
||||
right: Fiber.Fiber<Either.Either<Elem, Done1>, Err1>
|
||||
) => Z
|
||||
readonly onLeftDone: (f: (exit: Exit.Exit<Done1, Err1>) => Effect.Effect<Done2, Err2, Env>) => Z
|
||||
readonly onRightDone: (f: (exit: Exit.Exit<Done, Err>) => Effect.Effect<Done2, Err2, Env>) => Z
|
||||
}
|
||||
): Z
|
||||
} = internal.match
|
||||
124
_node_modules/effect/src/MergeStrategy.ts
generated
Normal file
124
_node_modules/effect/src/MergeStrategy.ts
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/channel/mergeStrategy.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MergeStrategyTypeId: unique symbol = internal.MergeStrategyTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MergeStrategyTypeId = typeof MergeStrategyTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type MergeStrategy = BackPressure | BufferSliding
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MergeStrategy {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Proto {
|
||||
readonly [MergeStrategyTypeId]: MergeStrategyTypeId
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BackPressure extends MergeStrategy.Proto {
|
||||
readonly _tag: "BackPressure"
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BufferSliding extends MergeStrategy.Proto {
|
||||
readonly _tag: "BufferSliding"
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const BackPressure: (_: void) => MergeStrategy = internal.BackPressure
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const BufferSliding: (_: void) => MergeStrategy = internal.BufferSliding
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `MergeStrategy`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMergeStrategy: (u: unknown) => u is MergeStrategy = internal.isMergeStrategy
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `MergeStrategy` is a `BackPressure`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isBackPressure: (self: MergeStrategy) => self is BackPressure = internal.isBackPressure
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified `MergeStrategy` is a `BufferSliding`, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isBufferSliding: (self: MergeStrategy) => self is BufferSliding = internal.isBufferSliding
|
||||
|
||||
/**
|
||||
* Folds an `MergeStrategy` into a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* Folds an `MergeStrategy` into a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
options: {
|
||||
readonly onBackPressure: () => A
|
||||
readonly onBufferSliding: () => A
|
||||
}
|
||||
): (self: MergeStrategy) => A
|
||||
/**
|
||||
* Folds an `MergeStrategy` into a value of type `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category folding
|
||||
*/
|
||||
<A>(
|
||||
self: MergeStrategy,
|
||||
options: {
|
||||
readonly onBackPressure: () => A
|
||||
readonly onBufferSliding: () => A
|
||||
}
|
||||
): A
|
||||
} = internal.match
|
||||
1165
_node_modules/effect/src/Metric.ts
generated
Normal file
1165
_node_modules/effect/src/Metric.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
69
_node_modules/effect/src/MetricBoundaries.ts
generated
Normal file
69
_node_modules/effect/src/MetricBoundaries.ts
generated
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Equal from "./Equal.js"
|
||||
import * as internal from "./internal/metric/boundaries.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricBoundariesTypeId: unique symbol = internal.MetricBoundariesTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricBoundariesTypeId = typeof MetricBoundariesTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricBoundaries extends Equal.Equal, Pipeable {
|
||||
readonly [MetricBoundariesTypeId]: MetricBoundariesTypeId
|
||||
readonly values: ReadonlyArray<number>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMetricBoundaries: (u: unknown) => u is MetricBoundaries = internal.isMetricBoundaries
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromIterable: (iterable: Iterable<number>) => MetricBoundaries = internal.fromIterable
|
||||
|
||||
/**
|
||||
* A helper method to create histogram bucket boundaries for a histogram
|
||||
* with linear increasing values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const linear: (
|
||||
options: {
|
||||
readonly start: number
|
||||
readonly width: number
|
||||
readonly count: number
|
||||
}
|
||||
) => MetricBoundaries = internal.linear
|
||||
|
||||
/**
|
||||
* A helper method to create histogram bucket boundaries for a histogram
|
||||
* with exponentially increasing values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const exponential: (
|
||||
options: {
|
||||
readonly start: number
|
||||
readonly factor: number
|
||||
readonly count: number
|
||||
}
|
||||
) => MetricBoundaries = internal.exponential
|
||||
175
_node_modules/effect/src/MetricHook.ts
generated
Normal file
175
_node_modules/effect/src/MetricHook.ts
generated
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import * as internal from "./internal/metric/hook.js"
|
||||
import type * as MetricKey from "./MetricKey.js"
|
||||
import type * as MetricState from "./MetricState.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricHookTypeId: unique symbol = internal.MetricHookTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricHookTypeId = typeof MetricHookTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricHook<in In, out Out> extends MetricHook.Variance<In, Out>, Pipeable {
|
||||
get(): Out
|
||||
update(input: In): void
|
||||
modify(input: In): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MetricHook {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Root = MetricHook<any, MetricState.MetricState.Untyped>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Untyped = MetricHook<any, any>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Counter<A extends (number | bigint)> = MetricHook<A, MetricState.MetricState.Counter<A>>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Gauge<A extends (number | bigint)> = MetricHook<A, MetricState.MetricState.Gauge<A>>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Frequency = MetricHook<string, MetricState.MetricState.Frequency>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Histogram = MetricHook<number, MetricState.MetricState.Histogram>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Summary = MetricHook<readonly [number, number], MetricState.MetricState.Summary>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in In, out Out> {
|
||||
readonly [MetricHookTypeId]: {
|
||||
readonly _In: Types.Contravariant<In>
|
||||
readonly _Out: Types.Covariant<Out>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <In, Out>(options: {
|
||||
readonly get: LazyArg<Out>
|
||||
readonly update: (input: In) => void
|
||||
readonly modify: (input: In) => void
|
||||
}) => MetricHook<In, Out> = internal.make
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const counter: <A extends (number | bigint)>(key: MetricKey.MetricKey.Counter<A>) => MetricHook.Counter<A> =
|
||||
internal.counter
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const frequency: (_key: MetricKey.MetricKey.Frequency) => MetricHook.Frequency = internal.frequency
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const gauge: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(key: MetricKey.MetricKey.Gauge<number>, startAt: number): MetricHook.Gauge<number>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(key: MetricKey.MetricKey.Gauge<bigint>, startAt: bigint): MetricHook.Gauge<bigint>
|
||||
} = internal.gauge
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const histogram: (key: MetricKey.MetricKey.Histogram) => MetricHook.Histogram = internal.histogram
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const summary: (key: MetricKey.MetricKey.Summary) => MetricHook.Summary = internal.summary
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const onUpdate: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<In, Out>(f: (input: In) => void): (self: MetricHook<In, Out>) => MetricHook<In, Out>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<In, Out>(self: MetricHook<In, Out>, f: (input: In) => void): MetricHook<In, Out>
|
||||
} = internal.onUpdate
|
||||
|
||||
/**
|
||||
* @since 3.6.5
|
||||
* @category utils
|
||||
*/
|
||||
export const onModify: {
|
||||
/**
|
||||
* @since 3.6.5
|
||||
* @category utils
|
||||
*/
|
||||
<In, Out>(f: (input: In) => void): (self: MetricHook<In, Out>) => MetricHook<In, Out>
|
||||
/**
|
||||
* @since 3.6.5
|
||||
* @category utils
|
||||
*/
|
||||
<In, Out>(self: MetricHook<In, Out>, f: (input: In) => void): MetricHook<In, Out>
|
||||
} = internal.onModify
|
||||
266
_node_modules/effect/src/MetricKey.ts
generated
Normal file
266
_node_modules/effect/src/MetricKey.ts
generated
Normal file
@@ -0,0 +1,266 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Equal from "./Equal.js"
|
||||
import * as internal from "./internal/metric/key.js"
|
||||
import type * as MetricBoundaries from "./MetricBoundaries.js"
|
||||
import type * as MetricKeyType from "./MetricKeyType.js"
|
||||
import type * as MetricLabel from "./MetricLabel.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricKeyTypeId: unique symbol = internal.MetricKeyTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricKeyTypeId = typeof MetricKeyTypeId
|
||||
|
||||
/**
|
||||
* A `MetricKey` is a unique key associated with each metric. The key is based
|
||||
* on a combination of the metric type, the name and tags associated with the
|
||||
* metric, an optional description of the key, and any other information to
|
||||
* describe a metric, such as the boundaries of a histogram. In this way, it is
|
||||
* impossible to ever create different metrics with conflicting keys.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricKey<out Type extends MetricKeyType.MetricKeyType<any, any>>
|
||||
extends MetricKey.Variance<Type>, Equal.Equal, Pipeable
|
||||
{
|
||||
readonly name: string
|
||||
readonly keyType: Type
|
||||
readonly description: Option.Option<string>
|
||||
readonly tags: ReadonlyArray<MetricLabel.MetricLabel>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MetricKey {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Untyped = MetricKey<any>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Counter<A extends (number | bigint)> = MetricKey<MetricKeyType.MetricKeyType.Counter<A>>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Gauge<A extends (number | bigint)> = MetricKey<MetricKeyType.MetricKeyType.Gauge<A>>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Frequency = MetricKey<MetricKeyType.MetricKeyType.Frequency>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Histogram = MetricKey<MetricKeyType.MetricKeyType.Histogram>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Summary = MetricKey<MetricKeyType.MetricKeyType.Summary>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out Type> {
|
||||
readonly [MetricKeyTypeId]: {
|
||||
_Type: Types.Covariant<Type>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMetricKey: (u: unknown) => u is MetricKey<MetricKeyType.MetricKeyType<unknown, unknown>> =
|
||||
internal.isMetricKey
|
||||
|
||||
/**
|
||||
* Creates a metric key for a counter, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const counter: {
|
||||
/**
|
||||
* Creates a metric key for a counter, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(
|
||||
name: string,
|
||||
options?: {
|
||||
readonly description?: string | undefined
|
||||
readonly bigint?: false | undefined
|
||||
readonly incremental?: boolean | undefined
|
||||
}
|
||||
): MetricKey.Counter<number>
|
||||
/**
|
||||
* Creates a metric key for a counter, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(
|
||||
name: string,
|
||||
options: {
|
||||
readonly description?: string | undefined
|
||||
readonly bigint: true
|
||||
readonly incremental?: boolean | undefined
|
||||
}
|
||||
): MetricKey.Counter<bigint>
|
||||
} = internal.counter
|
||||
|
||||
/**
|
||||
* Creates a metric key for a categorical frequency table, with the specified
|
||||
* name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const frequency: (
|
||||
name: string,
|
||||
options?:
|
||||
| {
|
||||
readonly description?: string | undefined
|
||||
readonly preregisteredWords?: ReadonlyArray<string> | undefined
|
||||
}
|
||||
| undefined
|
||||
) => MetricKey.Frequency = internal.frequency
|
||||
|
||||
/**
|
||||
* Creates a metric key for a gauge, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const gauge: {
|
||||
/**
|
||||
* Creates a metric key for a gauge, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(
|
||||
name: string,
|
||||
options?: {
|
||||
readonly description?: string | undefined
|
||||
readonly bigint?: false | undefined
|
||||
}
|
||||
): MetricKey.Gauge<number>
|
||||
/**
|
||||
* Creates a metric key for a gauge, with the specified name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(
|
||||
name: string,
|
||||
options: {
|
||||
readonly description?: string | undefined
|
||||
readonly bigint: true
|
||||
}
|
||||
): MetricKey.Gauge<bigint>
|
||||
} = internal.gauge
|
||||
|
||||
/**
|
||||
* Creates a metric key for a histogram, with the specified name and boundaries.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const histogram: (
|
||||
name: string,
|
||||
boundaries: MetricBoundaries.MetricBoundaries,
|
||||
description?: string
|
||||
) => MetricKey.Histogram = internal.histogram
|
||||
|
||||
/**
|
||||
* Creates a metric key for a summary, with the specified name, maxAge,
|
||||
* maxSize, error, and quantiles.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const summary: (
|
||||
options: {
|
||||
readonly name: string
|
||||
readonly maxAge: Duration.DurationInput
|
||||
readonly maxSize: number
|
||||
readonly error: number
|
||||
readonly quantiles: ReadonlyArray<number>
|
||||
readonly description?: string | undefined
|
||||
}
|
||||
) => MetricKey.Summary = internal.summary
|
||||
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tag appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const tagged: {
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tag appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(key: string, value: string): <Type extends MetricKeyType.MetricKeyType<any, any>>(self: MetricKey<Type>) => MetricKey<Type>
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tag appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<Type extends MetricKeyType.MetricKeyType<any, any>>(self: MetricKey<Type>, key: string, value: string): MetricKey<Type>
|
||||
} = internal.tagged
|
||||
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tags appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const taggedWithLabels: {
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tags appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(extraTags: ReadonlyArray<MetricLabel.MetricLabel>): <Type extends MetricKeyType.MetricKeyType<any, any>>(self: MetricKey<Type>) => MetricKey<Type>
|
||||
/**
|
||||
* Returns a new `MetricKey` with the specified tags appended.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<Type extends MetricKeyType.MetricKeyType<any, any>>(self: MetricKey<Type>, extraTags: ReadonlyArray<MetricLabel.MetricLabel>): MetricKey<Type>
|
||||
} = internal.taggedWithLabels
|
||||
262
_node_modules/effect/src/MetricKeyType.ts
generated
Normal file
262
_node_modules/effect/src/MetricKeyType.ts
generated
Normal file
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Equal from "./Equal.js"
|
||||
import * as internal from "./internal/metric/keyType.js"
|
||||
import type * as MetricBoundaries from "./MetricBoundaries.js"
|
||||
import type * as MetricState from "./MetricState.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricKeyTypeTypeId: unique symbol = internal.MetricKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricKeyTypeTypeId = typeof MetricKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const CounterKeyTypeTypeId: unique symbol = internal.CounterKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type CounterKeyTypeTypeId = typeof CounterKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FrequencyKeyTypeTypeId: unique symbol = internal.FrequencyKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FrequencyKeyTypeTypeId = typeof FrequencyKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const GaugeKeyTypeTypeId: unique symbol = internal.GaugeKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type GaugeKeyTypeTypeId = typeof GaugeKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const HistogramKeyTypeTypeId: unique symbol = internal.HistogramKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type HistogramKeyTypeTypeId = typeof HistogramKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const SummaryKeyTypeTypeId: unique symbol = internal.SummaryKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type SummaryKeyTypeTypeId = typeof SummaryKeyTypeTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category modelz
|
||||
*/
|
||||
export interface MetricKeyType<in In, out Out> extends MetricKeyType.Variance<In, Out>, Equal.Equal, Pipeable {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MetricKeyType {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Untyped = MetricKeyType<any, any>
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Counter<A extends (number | bigint)> = MetricKeyType<A, MetricState.MetricState.Counter<A>> & {
|
||||
readonly [CounterKeyTypeTypeId]: CounterKeyTypeTypeId
|
||||
readonly incremental: boolean
|
||||
readonly bigint: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Frequency = MetricKeyType<string, MetricState.MetricState.Frequency> & {
|
||||
readonly [FrequencyKeyTypeTypeId]: FrequencyKeyTypeTypeId
|
||||
readonly preregisteredWords: ReadonlyArray<string>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Gauge<A extends (number | bigint)> = MetricKeyType<A, MetricState.MetricState.Gauge<A>> & {
|
||||
readonly [GaugeKeyTypeTypeId]: GaugeKeyTypeTypeId
|
||||
readonly bigint: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Histogram = MetricKeyType<number, MetricState.MetricState.Histogram> & {
|
||||
readonly [HistogramKeyTypeTypeId]: HistogramKeyTypeTypeId
|
||||
readonly boundaries: MetricBoundaries.MetricBoundaries
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type Summary = MetricKeyType<readonly [number, number], MetricState.MetricState.Summary> & {
|
||||
readonly [SummaryKeyTypeTypeId]: SummaryKeyTypeTypeId
|
||||
readonly maxAge: Duration.Duration
|
||||
readonly maxSize: number
|
||||
readonly error: number
|
||||
readonly quantiles: ReadonlyArray<number>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in In, out Out> {
|
||||
readonly [MetricKeyTypeTypeId]: {
|
||||
readonly _In: Types.Contravariant<In>
|
||||
readonly _Out: Types.Covariant<Out>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type InType<Type extends MetricKeyType<any, any>> = [Type] extends [
|
||||
{
|
||||
readonly [MetricKeyTypeTypeId]: {
|
||||
readonly _In: (_: infer In) => void
|
||||
}
|
||||
}
|
||||
] ? In
|
||||
: never
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export type OutType<Type extends MetricKeyType<any, any>> = [Type] extends [
|
||||
{
|
||||
readonly [MetricKeyTypeTypeId]: {
|
||||
readonly _Out: (_: never) => infer Out
|
||||
}
|
||||
}
|
||||
] ? Out
|
||||
: never
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const counter: <A extends number | bigint>() => MetricKeyType.Counter<A> = internal.counter
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const frequency: (
|
||||
options?: {
|
||||
readonly preregisteredWords?: ReadonlyArray<string> | undefined
|
||||
} | undefined
|
||||
) => MetricKeyType.Frequency = internal.frequency
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const gauge: <A extends number | bigint>() => MetricKeyType.Gauge<A> = internal.gauge
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const histogram: (boundaries: MetricBoundaries.MetricBoundaries) => MetricKeyType.Histogram = internal.histogram
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const summary: (
|
||||
options: {
|
||||
readonly maxAge: Duration.DurationInput
|
||||
readonly maxSize: number
|
||||
readonly error: number
|
||||
readonly quantiles: ReadonlyArray<number>
|
||||
}
|
||||
) => MetricKeyType.Summary = internal.summary
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMetricKeyType: (u: unknown) => u is MetricKeyType<unknown, unknown> = internal.isMetricKeyType
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isCounterKey: (u: unknown) => u is MetricKeyType.Counter<number | bigint> = internal.isCounterKey
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFrequencyKey: (u: unknown) => u is MetricKeyType.Frequency = internal.isFrequencyKey
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isGaugeKey: (u: unknown) => u is MetricKeyType.Gauge<number | bigint> = internal.isGaugeKey
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isHistogramKey: (u: unknown) => u is MetricKeyType.Histogram = internal.isHistogramKey
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSummaryKey: (u: unknown) => u is MetricKeyType.Summary = internal.isSummaryKey
|
||||
47
_node_modules/effect/src/MetricLabel.ts
generated
Normal file
47
_node_modules/effect/src/MetricLabel.ts
generated
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Equal from "./Equal.js"
|
||||
import * as internal from "./internal/metric/label.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricLabelTypeId: unique symbol = internal.MetricLabelTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricLabelTypeId = typeof MetricLabelTypeId
|
||||
|
||||
/**
|
||||
* A `MetricLabel` represents a key value pair that allows analyzing metrics at
|
||||
* an additional level of granularity.
|
||||
*
|
||||
* For example if a metric tracks the response time of a service labels could
|
||||
* be used to create separate versions that track response times for different
|
||||
* clients.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricLabel extends Equal.Equal, Pipeable {
|
||||
readonly [MetricLabelTypeId]: MetricLabelTypeId
|
||||
readonly key: string
|
||||
readonly value: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (key: string, value: string) => MetricLabel = internal.make
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMetricLabel: (u: unknown) => u is MetricLabel = internal.isMetricLabel
|
||||
71
_node_modules/effect/src/MetricPair.ts
generated
Normal file
71
_node_modules/effect/src/MetricPair.ts
generated
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/metric/pair.js"
|
||||
import type * as MetricKey from "./MetricKey.js"
|
||||
import type * as MetricKeyType from "./MetricKeyType.js"
|
||||
import type * as MetricState from "./MetricState.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricPairTypeId: unique symbol = internal.MetricPairTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricPairTypeId = typeof MetricPairTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface MetricPair<out Type extends MetricKeyType.MetricKeyType<any, any>>
|
||||
extends MetricPair.Variance<Type>, Pipeable
|
||||
{
|
||||
readonly metricKey: MetricKey.MetricKey<Type>
|
||||
readonly metricState: MetricState.MetricState<MetricKeyType.MetricKeyType.OutType<Type>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MetricPair {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Untyped extends MetricPair<MetricKeyType.MetricKeyType<any, any>> {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<out Type extends MetricKeyType.MetricKeyType<any, any>> {
|
||||
readonly [MetricPairTypeId]: {
|
||||
readonly _Type: Types.Covariant<Type>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Type extends MetricKeyType.MetricKeyType<any, any>>(
|
||||
metricKey: MetricKey.MetricKey<Type>,
|
||||
metricState: MetricState.MetricState<MetricKeyType.MetricKeyType.OutType<Type>>
|
||||
) => MetricPair.Untyped = internal.make
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category unsafe
|
||||
*/
|
||||
export const unsafeMake: <Type extends MetricKeyType.MetricKeyType<any, any>>(
|
||||
metricKey: MetricKey.MetricKey<Type>,
|
||||
metricState: MetricState.MetricState.Untyped
|
||||
) => MetricPair.Untyped = internal.unsafeMake
|
||||
182
_node_modules/effect/src/MetricPolling.ts
generated
Normal file
182
_node_modules/effect/src/MetricPolling.ts
generated
Normal file
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import type * as Fiber from "./Fiber.js"
|
||||
import * as internal from "./internal/metric/polling.js"
|
||||
import type * as Metric from "./Metric.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Schedule from "./Schedule.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricPollingTypeId: unique symbol = internal.MetricPollingTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricPollingTypeId = typeof MetricPollingTypeId
|
||||
|
||||
/**
|
||||
* A `MetricPolling` is a combination of a metric and an effect that polls for
|
||||
* updates to the metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricPolling<in out Type, in out In, out R, out E, out Out> extends Pipeable {
|
||||
readonly [MetricPollingTypeId]: MetricPollingTypeId
|
||||
/**
|
||||
* The metric that this `MetricPolling` polls to update.
|
||||
*/
|
||||
readonly metric: Metric.Metric<Type, In, Out>
|
||||
/**
|
||||
* An effect that polls a value that may be fed to the metric.
|
||||
*/
|
||||
readonly poll: Effect.Effect<In, E, R>
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new polling metric from a metric and poll effect.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Type, In, Out, R, E>(
|
||||
metric: Metric.Metric<Type, In, Out>,
|
||||
poll: Effect.Effect<In, E, R>
|
||||
) => MetricPolling<Type, In, R, E, Out> = internal.make
|
||||
|
||||
/**
|
||||
* Collects all of the polling metrics into a single polling metric, which
|
||||
* polls for, updates, and produces the outputs of all individual metrics.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const collectAll: <R, E, Out>(
|
||||
iterable: Iterable<MetricPolling<any, any, R, E, Out>>
|
||||
) => MetricPolling<Array<any>, Array<any>, R, E, Array<Out>> = internal.collectAll
|
||||
|
||||
/**
|
||||
* Returns an effect that will launch the polling metric in a background
|
||||
* fiber, using the specified schedule.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const launch: {
|
||||
/**
|
||||
* Returns an effect that will launch the polling metric in a background
|
||||
* fiber, using the specified schedule.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A2, R2>(schedule: Schedule.Schedule<A2, unknown, R2>): <Type, In, R, E, Out>(
|
||||
self: MetricPolling<Type, In, R, E, Out>
|
||||
) => Effect.Effect<Fiber.Fiber<A2, E>, never, R2 | R | Scope.Scope>
|
||||
/**
|
||||
* Returns an effect that will launch the polling metric in a background
|
||||
* fiber, using the specified schedule.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<Type, In, R, E, Out, A2, R2>(
|
||||
self: MetricPolling<Type, In, R, E, Out>,
|
||||
schedule: Schedule.Schedule<A2, unknown, R2>
|
||||
): Effect.Effect<Fiber.Fiber<A2, E>, never, Scope.Scope | R | R2>
|
||||
} = internal.launch
|
||||
|
||||
/**
|
||||
* An effect that polls a value that may be fed to the metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const poll: <Type, In, R, E, Out>(self: MetricPolling<Type, In, R, E, Out>) => Effect.Effect<In, E, R> =
|
||||
internal.poll
|
||||
|
||||
/**
|
||||
* An effect that polls for a value and uses the value to update the metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const pollAndUpdate: <Type, In, R, E, Out>(
|
||||
self: MetricPolling<Type, In, R, E, Out>
|
||||
) => Effect.Effect<void, E, R> = internal.pollAndUpdate
|
||||
|
||||
/**
|
||||
* Returns a new polling metric whose poll function will be retried with the
|
||||
* specified retry policy.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const retry: {
|
||||
/**
|
||||
* Returns a new polling metric whose poll function will be retried with the
|
||||
* specified retry policy.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<X, E, R2>(policy: Schedule.Schedule<X, NoInfer<E>, R2>): <Type, In, R, Out>(self: MetricPolling<Type, In, R, E, Out>) => MetricPolling<Type, In, R2 | R, E, Out>
|
||||
/**
|
||||
* Returns a new polling metric whose poll function will be retried with the
|
||||
* specified retry policy.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
<Type, In, R, E, Out, X, R2>(
|
||||
self: MetricPolling<Type, In, R, E, Out>,
|
||||
policy: Schedule.Schedule<X, E, R2>
|
||||
): MetricPolling<Type, In, R | R2, E, Out>
|
||||
} = internal.retry
|
||||
|
||||
/**
|
||||
* Zips this polling metric with the specified polling metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const zip: {
|
||||
/**
|
||||
* Zips this polling metric with the specified polling metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<Type2, In2, R2, E2, Out2>(that: MetricPolling<Type2, In2, R2, E2, Out2>): <Type, In, R, E, Out>(
|
||||
self: MetricPolling<Type, In, R, E, Out>
|
||||
) => MetricPolling<
|
||||
readonly [Type, Type2], // readonly because invariant
|
||||
readonly [In, In2], // readonly because contravariant
|
||||
R2 | R,
|
||||
E2 | E,
|
||||
[Out, Out2]
|
||||
>
|
||||
/**
|
||||
* Zips this polling metric with the specified polling metric.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<Type, In, R, E, Out, Type2, In2, R2, E2, Out2>(
|
||||
self: MetricPolling<Type, In, R, E, Out>,
|
||||
that: MetricPolling<Type2, In2, R2, E2, Out2>
|
||||
): MetricPolling<
|
||||
readonly [Type, Type2], // readonly because invariant
|
||||
readonly [In, In2], // readonly because contravariant
|
||||
R | R2,
|
||||
E | E2,
|
||||
[Out, Out2]
|
||||
>
|
||||
} = internal.zip
|
||||
48
_node_modules/effect/src/MetricRegistry.ts
generated
Normal file
48
_node_modules/effect/src/MetricRegistry.ts
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as internal from "./internal/metric/registry.js"
|
||||
import type * as MetricHook from "./MetricHook.js"
|
||||
import type * as MetricKey from "./MetricKey.js"
|
||||
import type * as MetricKeyType from "./MetricKeyType.js"
|
||||
import type * as MetricPair from "./MetricPair.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricRegistryTypeId: unique symbol = internal.MetricRegistryTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricRegistryTypeId = typeof MetricRegistryTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricRegistry {
|
||||
readonly [MetricRegistryTypeId]: MetricRegistryTypeId
|
||||
snapshot(): Array<MetricPair.MetricPair.Untyped>
|
||||
get<Type extends MetricKeyType.MetricKeyType<any, any>>(
|
||||
key: MetricKey.MetricKey<Type>
|
||||
): MetricHook.MetricHook<
|
||||
MetricKeyType.MetricKeyType.InType<typeof key["keyType"]>,
|
||||
MetricKeyType.MetricKeyType.OutType<typeof key["keyType"]>
|
||||
>
|
||||
getCounter<A extends (number | bigint)>(
|
||||
key: MetricKey.MetricKey.Counter<A>
|
||||
): MetricHook.MetricHook.Counter<A>
|
||||
getFrequency(key: MetricKey.MetricKey.Frequency): MetricHook.MetricHook.Frequency
|
||||
getGauge<A extends (number | bigint)>(key: MetricKey.MetricKey.Gauge<A>): MetricHook.MetricHook.Gauge<A>
|
||||
getHistogram(key: MetricKey.MetricKey.Histogram): MetricHook.MetricHook.Histogram
|
||||
getSummary(key: MetricKey.MetricKey.Summary): MetricHook.MetricHook.Summary
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (_: void) => MetricRegistry = internal.make
|
||||
273
_node_modules/effect/src/MetricState.ts
generated
Normal file
273
_node_modules/effect/src/MetricState.ts
generated
Normal file
@@ -0,0 +1,273 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Equal from "./Equal.js"
|
||||
import * as internal from "./internal/metric/state.js"
|
||||
import type * as MetricKeyType from "./MetricKeyType.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const MetricStateTypeId: unique symbol = internal.MetricStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type MetricStateTypeId = typeof MetricStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const CounterStateTypeId: unique symbol = internal.CounterStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type CounterStateTypeId = typeof CounterStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const FrequencyStateTypeId: unique symbol = internal.FrequencyStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type FrequencyStateTypeId = typeof FrequencyStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const GaugeStateTypeId: unique symbol = internal.GaugeStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type GaugeStateTypeId = typeof GaugeStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const HistogramStateTypeId: unique symbol = internal.HistogramStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type HistogramStateTypeId = typeof HistogramStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const SummaryStateTypeId: unique symbol = internal.SummaryStateTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type SummaryStateTypeId = typeof SummaryStateTypeId
|
||||
|
||||
/**
|
||||
* A `MetricState` describes the state of a metric. The type parameter of a
|
||||
* metric state corresponds to the type of the metric key (`MetricStateType`).
|
||||
* This phantom type parameter is used to tie keys to their expected states.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MetricState<in A> extends MetricState.Variance<A>, Equal.Equal, Pipeable {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MetricState {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Untyped extends MetricState<any> {}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Counter<in out A extends (number | bigint)>
|
||||
extends MetricState<MetricKeyType.MetricKeyType.Counter<A>>
|
||||
{
|
||||
readonly [CounterStateTypeId]: CounterStateTypeId
|
||||
readonly count: A
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Frequency extends MetricState<MetricKeyType.MetricKeyType.Frequency> {
|
||||
readonly [FrequencyStateTypeId]: FrequencyStateTypeId
|
||||
readonly occurrences: ReadonlyMap<string, number>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Gauge<in out A extends (number | bigint)> extends MetricState<MetricKeyType.MetricKeyType.Gauge<A>> {
|
||||
readonly [GaugeStateTypeId]: GaugeStateTypeId
|
||||
readonly value: A
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Histogram extends MetricState<MetricKeyType.MetricKeyType.Histogram> {
|
||||
readonly [HistogramStateTypeId]: HistogramStateTypeId
|
||||
readonly buckets: ReadonlyArray<readonly [number, number]>
|
||||
readonly count: number
|
||||
readonly min: number
|
||||
readonly max: number
|
||||
readonly sum: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Summary extends MetricState<MetricKeyType.MetricKeyType.Summary> {
|
||||
readonly [SummaryStateTypeId]: SummaryStateTypeId
|
||||
readonly error: number
|
||||
readonly quantiles: ReadonlyArray<readonly [number, Option.Option<number>]>
|
||||
readonly count: number
|
||||
readonly min: number
|
||||
readonly max: number
|
||||
readonly sum: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in A> {
|
||||
readonly [MetricStateTypeId]: {
|
||||
readonly _A: Types.Contravariant<A>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const counter: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(count: number): MetricState.Counter<number>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(count: bigint): MetricState.Counter<bigint>
|
||||
} = internal.counter
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const frequency: (occurrences: ReadonlyMap<string, number>) => MetricState.Frequency = internal.frequency
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const gauge: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(count: number): MetricState.Gauge<number>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
(count: bigint): MetricState.Gauge<bigint>
|
||||
} = internal.gauge
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const histogram: (
|
||||
options: {
|
||||
readonly buckets: ReadonlyArray<readonly [number, number]>
|
||||
readonly count: number
|
||||
readonly min: number
|
||||
readonly max: number
|
||||
readonly sum: number
|
||||
}
|
||||
) => MetricState.Histogram = internal.histogram
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const summary: (
|
||||
options: {
|
||||
readonly error: number
|
||||
readonly quantiles: ReadonlyArray<readonly [number, Option.Option<number>]>
|
||||
readonly count: number
|
||||
readonly min: number
|
||||
readonly max: number
|
||||
readonly sum: number
|
||||
}
|
||||
) => MetricState.Summary = internal.summary
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isMetricState: (u: unknown) => u is MetricState.Counter<number | bigint> = internal.isMetricState
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isCounterState: (u: unknown) => u is MetricState.Counter<number | bigint> = internal.isCounterState
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isFrequencyState: (u: unknown) => u is MetricState.Frequency = internal.isFrequencyState
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isGaugeState: (u: unknown) => u is MetricState.Gauge<number | bigint> = internal.isGaugeState
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isHistogramState: (u: unknown) => u is MetricState.Histogram = internal.isHistogramState
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isSummaryState: (u: unknown) => u is MetricState.Summary = internal.isSummaryState
|
||||
5556
_node_modules/effect/src/Micro.ts
generated
Normal file
5556
_node_modules/effect/src/Micro.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
_node_modules/effect/src/ModuleVersion.ts
generated
Normal file
18
_node_modules/effect/src/ModuleVersion.ts
generated
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*
|
||||
* Enables low level framework authors to run on their own isolated effect version
|
||||
*/
|
||||
import * as internal from "./internal/version.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category version
|
||||
*/
|
||||
export const getCurrentVersion: () => string = internal.getCurrentVersion
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category version
|
||||
*/
|
||||
export const setCurrentVersion: (version: string) => void = internal.setCurrentVersion
|
||||
518
_node_modules/effect/src/MutableHashMap.ts
generated
Normal file
518
_node_modules/effect/src/MutableHashMap.ts
generated
Normal file
@@ -0,0 +1,518 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
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 * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import { pipeArguments } from "./Pipeable.js"
|
||||
|
||||
const TypeId: unique symbol = Symbol.for("effect/MutableHashMap") as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MutableHashMap<out K, out V> extends Iterable<[K, V]>, Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
/** @internal */
|
||||
readonly referential: Map<K, V>
|
||||
/** @internal */
|
||||
readonly buckets: Map<number, NonEmptyArray<readonly [K & Equal.Equal, V]>>
|
||||
/** @internal */
|
||||
bucketsSize: number
|
||||
}
|
||||
|
||||
const MutableHashMapProto: Omit<MutableHashMap<unknown, unknown>, "referential" | "buckets" | "bucketsSize"> = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator](this: MutableHashMap<unknown, unknown>): Iterator<[unknown, unknown]> {
|
||||
return new MutableHashMapIterator(this)
|
||||
},
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON() {
|
||||
return {
|
||||
_id: "MutableHashMap",
|
||||
values: Array.from(this).map(toJSON)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
class MutableHashMapIterator<K, V> implements IterableIterator<[K, V]> {
|
||||
readonly referentialIterator: Iterator<[K, V]>
|
||||
bucketIterator: Iterator<[K, V]> | undefined
|
||||
|
||||
constructor(readonly self: MutableHashMap<K, V>) {
|
||||
this.referentialIterator = self.referential[Symbol.iterator]()
|
||||
}
|
||||
next(): IteratorResult<[K, V]> {
|
||||
if (this.bucketIterator !== undefined) {
|
||||
return this.bucketIterator.next()
|
||||
}
|
||||
const result = this.referentialIterator.next()
|
||||
if (result.done) {
|
||||
this.bucketIterator = new BucketIterator(this.self.buckets.values())
|
||||
return this.next()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[K, V]> {
|
||||
return new MutableHashMapIterator(this.self)
|
||||
}
|
||||
}
|
||||
|
||||
class BucketIterator<K, V> implements Iterator<[K, V]> {
|
||||
constructor(readonly backing: Iterator<NonEmptyArray<readonly [K, V]>>) {}
|
||||
currentBucket: Iterator<readonly [K, V]> | undefined
|
||||
next(): IteratorResult<[K, V]> {
|
||||
if (this.currentBucket === undefined) {
|
||||
const result = this.backing.next()
|
||||
if (result.done) {
|
||||
return result
|
||||
}
|
||||
this.currentBucket = result.value[Symbol.iterator]()
|
||||
}
|
||||
const result = this.currentBucket.next()
|
||||
if (result.done) {
|
||||
this.currentBucket = undefined
|
||||
return this.next()
|
||||
}
|
||||
return result as IteratorResult<[K, V]>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty = <K = never, V = never>(): MutableHashMap<K, V> => {
|
||||
const self = Object.create(MutableHashMapProto)
|
||||
self.referential = new Map()
|
||||
self.buckets = new Map()
|
||||
self.bucketsSize = 0
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <Entries extends Array<readonly [any, any]>>(
|
||||
...entries: Entries
|
||||
) => MutableHashMap<
|
||||
Entries[number] extends readonly [infer K, any] ? K : never,
|
||||
Entries[number] extends readonly [any, infer V] ? V : never
|
||||
> = (...entries) => fromIterable(entries)
|
||||
|
||||
/**
|
||||
* Creates a new `MutableHashMap` from an iterable collection of key/value pairs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromIterable = <K, V>(entries: Iterable<readonly [K, V]>): MutableHashMap<K, V> => {
|
||||
const self = empty<K, V>()
|
||||
for (const [key, value] of entries) {
|
||||
set(self, key, value)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const get: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K>(key: K): <V>(self: MutableHashMap<K, V>) => Option.Option<V>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K): Option.Option<V>
|
||||
} = dual<
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K>(key: K) => <V>(self: MutableHashMap<K, V>) => Option.Option<V>,
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K) => Option.Option<V>
|
||||
>(2, <K, V>(self: MutableHashMap<K, V>, key: K): Option.Option<V> => {
|
||||
if (Equal.isEqual(key) === false) {
|
||||
return self.referential.has(key) ? Option.some(self.referential.get(key)!) : Option.none()
|
||||
}
|
||||
|
||||
const hash = key[Hash.symbol]()
|
||||
const bucket = self.buckets.get(hash)
|
||||
if (bucket === undefined) {
|
||||
return Option.none()
|
||||
}
|
||||
|
||||
return getFromBucket(self, bucket, key)
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @category elements
|
||||
*/
|
||||
export const keys = <K, V>(self: MutableHashMap<K, V>): Array<K> => {
|
||||
const keys = Array.from(self.referential.keys())
|
||||
for (const bucket of self.buckets.values()) {
|
||||
for (let i = 0, len = bucket.length; i < len; i++) {
|
||||
keys.push(bucket[i][0])
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.8.0
|
||||
* @category elements
|
||||
*/
|
||||
export const values = <K, V>(self: MutableHashMap<K, V>): Array<V> => {
|
||||
const values = Array.from(self.referential.values())
|
||||
for (const bucket of self.buckets.values()) {
|
||||
for (let i = 0, len = bucket.length; i < len; i++) {
|
||||
values.push(bucket[i][1])
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
const getFromBucket = <K, V>(
|
||||
self: MutableHashMap<K, V>,
|
||||
bucket: NonEmptyArray<readonly [K & Equal.Equal, V]>,
|
||||
key: K & Equal.Equal,
|
||||
remove = false
|
||||
): Option.Option<V> => {
|
||||
for (let i = 0, len = bucket.length; i < len; i++) {
|
||||
if (key[Equal.symbol](bucket[i][0])) {
|
||||
const value = bucket[i][1]
|
||||
if (remove) {
|
||||
bucket.splice(i, 1)
|
||||
self.bucketsSize--
|
||||
}
|
||||
return Option.some(value)
|
||||
}
|
||||
}
|
||||
|
||||
return Option.none()
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const has: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K>(key: K): <V>(self: MutableHashMap<K, V>) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K): boolean
|
||||
} = dual<
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K>(key: K) => <V>(self: MutableHashMap<K, V>) => boolean,
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K) => boolean
|
||||
>(2, (self, key) => Option.isSome(get(self, key)))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, value: V): (self: MutableHashMap<K, V>) => MutableHashMap<K, V>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K, value: V): MutableHashMap<K, V>
|
||||
} = dual<
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, value: V) => (self: MutableHashMap<K, V>) => MutableHashMap<K, V>,
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K, value: V) => MutableHashMap<K, V>
|
||||
>(3, <K, V>(self: MutableHashMap<K, V>, key: K, value: V) => {
|
||||
if (Equal.isEqual(key) === false) {
|
||||
self.referential.set(key, value)
|
||||
return self
|
||||
}
|
||||
|
||||
const hash = key[Hash.symbol]()
|
||||
const bucket = self.buckets.get(hash)
|
||||
if (bucket === undefined) {
|
||||
self.buckets.set(hash, [[key, value]])
|
||||
self.bucketsSize++
|
||||
return self
|
||||
}
|
||||
|
||||
removeFromBucket(self, bucket, key)
|
||||
bucket.push([key, value])
|
||||
self.bucketsSize++
|
||||
return self
|
||||
})
|
||||
|
||||
const removeFromBucket = <K, V>(
|
||||
self: MutableHashMap<K, V>,
|
||||
bucket: NonEmptyArray<readonly [K & Equal.Equal, V]>,
|
||||
key: K & Equal.Equal
|
||||
) => {
|
||||
for (let i = 0, len = bucket.length; i < len; i++) {
|
||||
if (key[Equal.symbol](bucket[i][0])) {
|
||||
bucket.splice(i, 1)
|
||||
self.bucketsSize--
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the value of the specified key within the `MutableHashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const modify: {
|
||||
/**
|
||||
* Updates the value of the specified key within the `MutableHashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: (v: V) => V): (self: MutableHashMap<K, V>) => MutableHashMap<K, V>
|
||||
/**
|
||||
* Updates the value of the specified key within the `MutableHashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V): MutableHashMap<K, V>
|
||||
} = dual<
|
||||
/**
|
||||
* Updates the value of the specified key within the `MutableHashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: (v: V) => V) => (self: MutableHashMap<K, V>) => MutableHashMap<K, V>,
|
||||
/**
|
||||
* Updates the value of the specified key within the `MutableHashMap` if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V) => MutableHashMap<K, V>
|
||||
>(3, <K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V) => {
|
||||
if (Equal.isEqual(key) === false) {
|
||||
if (self.referential.has(key)) {
|
||||
self.referential.set(key, f(self.referential.get(key)!))
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
const hash = key[Hash.symbol]()
|
||||
const bucket = self.buckets.get(hash)
|
||||
if (bucket === undefined) {
|
||||
return self
|
||||
}
|
||||
|
||||
const value = getFromBucket(self, bucket, key, true)
|
||||
if (Option.isNone(value)) {
|
||||
return self
|
||||
}
|
||||
bucket.push([key, f(value.value)])
|
||||
self.bucketsSize++
|
||||
return self
|
||||
})
|
||||
|
||||
/**
|
||||
* Set or remove the specified key in the `MutableHashMap` using the specified
|
||||
* update function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const modifyAt: {
|
||||
/**
|
||||
* Set or remove the specified key in the `MutableHashMap` using the specified
|
||||
* update function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: (value: Option.Option<V>) => Option.Option<V>): (self: MutableHashMap<K, V>) => MutableHashMap<K, V>
|
||||
/**
|
||||
* Set or remove the specified key in the `MutableHashMap` using the specified
|
||||
* update function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(
|
||||
self: MutableHashMap<K, V>,
|
||||
key: K,
|
||||
f: (value: Option.Option<V>) => Option.Option<V>
|
||||
): MutableHashMap<K, V>
|
||||
} = dual<
|
||||
/**
|
||||
* Set or remove the specified key in the `MutableHashMap` using the specified
|
||||
* update function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(key: K, f: (value: Option.Option<V>) => Option.Option<V>) => (self: MutableHashMap<K, V>) => MutableHashMap<K, V>,
|
||||
/**
|
||||
* Set or remove the specified key in the `MutableHashMap` using the specified
|
||||
* update function.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(
|
||||
self: MutableHashMap<K, V>,
|
||||
key: K,
|
||||
f: (value: Option.Option<V>) => Option.Option<V>
|
||||
) => MutableHashMap<K, V>
|
||||
>(3, (self, key, f) => {
|
||||
if (Equal.isEqual(key) === false) {
|
||||
const result = f(get(self, key))
|
||||
if (Option.isSome(result)) {
|
||||
set(self, key, result.value)
|
||||
} else {
|
||||
remove(self, key)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
const hash = key[Hash.symbol]()
|
||||
const bucket = self.buckets.get(hash)
|
||||
if (bucket === undefined) {
|
||||
const result = f(Option.none())
|
||||
return Option.isSome(result) ? set(self, key, result.value) : self
|
||||
}
|
||||
|
||||
const result = f(getFromBucket(self, bucket, key, true))
|
||||
if (Option.isNone(result)) {
|
||||
if (bucket.length === 0) {
|
||||
self.buckets.delete(hash)
|
||||
}
|
||||
return self
|
||||
}
|
||||
bucket.push([key, result.value])
|
||||
self.bucketsSize++
|
||||
return self
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const remove: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K>(key: K): <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K): MutableHashMap<K, V>
|
||||
} = dual<
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K>(key: K) => <V>(self: MutableHashMap<K, V>) => MutableHashMap<K, V>,
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, key: K) => MutableHashMap<K, V>
|
||||
>(2, <K, V>(self: MutableHashMap<K, V>, key: K) => {
|
||||
if (Equal.isEqual(key) === false) {
|
||||
self.referential.delete(key)
|
||||
return self
|
||||
}
|
||||
|
||||
const hash = key[Hash.symbol]()
|
||||
const bucket = self.buckets.get(hash)
|
||||
if (bucket === undefined) {
|
||||
return self
|
||||
}
|
||||
removeFromBucket(self, bucket, key)
|
||||
if (bucket.length === 0) {
|
||||
self.buckets.delete(hash)
|
||||
}
|
||||
return self
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const clear = <K, V>(self: MutableHashMap<K, V>) => {
|
||||
self.referential.clear()
|
||||
self.buckets.clear()
|
||||
self.bucketsSize = 0
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
*/
|
||||
export const size = <K, V>(self: MutableHashMap<K, V>): number => {
|
||||
return self.referential.size + self.bucketsSize
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const isEmpty = <K, V>(self: MutableHashMap<K, V>): boolean => size(self) === 0
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const forEach: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(f: (value: V, key: K) => void): (self: MutableHashMap<K, V>) => void
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void): void
|
||||
} = dual(2, <K, V>(self: MutableHashMap<K, V>, f: (value: V, key: K) => void) => {
|
||||
self.referential.forEach(f)
|
||||
for (const bucket of self.buckets.values()) {
|
||||
for (const [key, value] of bucket) {
|
||||
f(value, key)
|
||||
}
|
||||
}
|
||||
})
|
||||
706
_node_modules/effect/src/MutableHashSet.ts
generated
Normal file
706
_node_modules/effect/src/MutableHashSet.ts
generated
Normal file
@@ -0,0 +1,706 @@
|
||||
/**
|
||||
* # MutableHashSet
|
||||
*
|
||||
* A mutable `MutableHashSet` provides a collection of unique values with
|
||||
* efficient lookup, insertion and removal. Unlike its immutable sibling
|
||||
* {@link module:HashSet}, a `MutableHashSet` can be modified in-place;
|
||||
* operations like add, remove, and clear directly modify the original set
|
||||
* rather than creating a new one. This mutability offers benefits like improved
|
||||
* performance in scenarios where you need to build or modify a set
|
||||
* incrementally.
|
||||
*
|
||||
* ## What Problem Does It Solve?
|
||||
*
|
||||
* `MutableHashSet` solves the problem of maintaining an unsorted collection
|
||||
* where each value appears exactly once, with fast operations for checking
|
||||
* membership and adding/removing values, in contexts where mutability is
|
||||
* preferred for performance or implementation simplicity.
|
||||
*
|
||||
* ## When to Use
|
||||
*
|
||||
* Use `MutableHashSet` when you need:
|
||||
*
|
||||
* - A collection with no duplicate values
|
||||
* - Efficient membership testing (**`O(1)`** average complexity)
|
||||
* - In-place modifications for better performance
|
||||
* - A set that will be built or modified incrementally
|
||||
* - Local mutability in otherwise immutable code
|
||||
*
|
||||
* ## Advanced Features
|
||||
*
|
||||
* MutableHashSet provides operations for:
|
||||
*
|
||||
* - Adding and removing elements with direct mutation
|
||||
* - Checking for element existence
|
||||
* - Clearing all elements at once
|
||||
* - Converting to/from other collection types
|
||||
*
|
||||
* ## Performance Characteristics
|
||||
*
|
||||
* - **Lookup** operations ({@link module:MutableHashSet.has}): **`O(1)`** average
|
||||
* time complexity
|
||||
* - **Insertion** operations ({@link module:MutableHashSet.add}): **`O(1)`**
|
||||
* average time complexity
|
||||
* - **Removal** operations ({@link module:MutableHashSet.remove}): **`O(1)`**
|
||||
* average time complexity
|
||||
* - **Iteration**: **`O(n)`** where n is the size of the set
|
||||
*
|
||||
* The MutableHashSet data structure implements the following traits:
|
||||
*
|
||||
* - {@link Iterable}: allows iterating over the values in the set
|
||||
* - {@link Pipeable}: allows chaining operations with the pipe operator
|
||||
* - {@link Inspectable}: allows inspecting the contents of the set
|
||||
*
|
||||
* ## Operations Reference
|
||||
*
|
||||
* | Category | Operation | Description | Complexity |
|
||||
* | ------------ | ------------------------------------------ | ----------------------------------- | ---------- |
|
||||
* | constructors | {@link module:MutableHashSet.empty} | Creates an empty MutableHashSet | O(1) |
|
||||
* | constructors | {@link module:MutableHashSet.fromIterable} | Creates a set from an iterable | O(n) |
|
||||
* | constructors | {@link module:MutableHashSet.make} | Creates a set from multiple values | O(n) |
|
||||
* | | | | |
|
||||
* | elements | {@link module:MutableHashSet.has} | Checks if a value exists in the set | O(1) avg |
|
||||
* | elements | {@link module:MutableHashSet.add} | Adds a value to the set | O(1) avg |
|
||||
* | elements | {@link module:MutableHashSet.remove} | Removes a value from the set | O(1) avg |
|
||||
* | elements | {@link module:MutableHashSet.size} | Gets the number of elements | O(1) |
|
||||
* | elements | {@link module:MutableHashSet.clear} | Removes all values from the set | O(1) |
|
||||
*
|
||||
* ## Notes
|
||||
*
|
||||
* ### Mutability Considerations:
|
||||
*
|
||||
* Unlike most data structures in the Effect ecosystem, `MutableHashSet` is
|
||||
* mutable. This means that operations like `add`, `remove`, and `clear` modify
|
||||
* the original set rather than creating a new one. This can lead to more
|
||||
* efficient code in some scenarios, but requires careful handling to avoid
|
||||
* unexpected side effects.
|
||||
*
|
||||
* ### When to Choose `MutableHashSet` vs {@link module:HashSet}:
|
||||
*
|
||||
* - Use `MutableHashSet` when you need to build or modify a set incrementally and
|
||||
* performance is a priority
|
||||
* - Use `HashSet` when you want immutability guarantees and functional
|
||||
* programming patterns
|
||||
* - Consider using {@link module:HashSet}'s bounded mutation context (via
|
||||
* {@link module:HashSet.beginMutation}, {@link module:HashSet.endMutation}, and
|
||||
* {@link module:HashSet.mutate} methods) when you need temporary mutability
|
||||
* within an otherwise immutable context - this approach might be sufficient
|
||||
* for many use cases without requiring a separate `MutableHashSet`
|
||||
* - `MutableHashSet` is often useful for local operations where the mutability is
|
||||
* contained and doesn't leak into the broader application
|
||||
*
|
||||
* @module MutableHashSet
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Dual from "./Function.js"
|
||||
import { 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"
|
||||
|
||||
const TypeId: unique symbol = Symbol.for("effect/MutableHashSet") as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MutableHashSet<out V> extends Iterable<V>, Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
|
||||
/** @internal */
|
||||
readonly keyMap: MutableHashMap.MutableHashMap<V, boolean>
|
||||
}
|
||||
|
||||
const MutableHashSetProto: Omit<MutableHashSet<unknown>, "keyMap"> = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator](this: MutableHashSet<unknown>): Iterator<unknown> {
|
||||
return Array.from(this.keyMap)
|
||||
.map(([_]) => _)[Symbol.iterator]()
|
||||
},
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON() {
|
||||
return {
|
||||
_id: "MutableHashSet",
|
||||
values: Array.from(this).map(toJSON)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const fromHashMap = <V>(
|
||||
keyMap: MutableHashMap.MutableHashMap<V, boolean>
|
||||
): MutableHashSet<V> => {
|
||||
const set = Object.create(MutableHashSetProto)
|
||||
set.keyMap = keyMap
|
||||
return set
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty mutable hash set.
|
||||
*
|
||||
* This function initializes and returns an empty `MutableHashSet` instance,
|
||||
* which allows for efficient storage and manipulation of unique elements.
|
||||
*
|
||||
* Time complexity: **`O(1)`**
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet } from "effect"
|
||||
*
|
||||
* type T = unknown // replace with your type
|
||||
*
|
||||
* // in places where the type can't be inferred, replace with your type
|
||||
* const set: MutableHashSet.MutableHashSet<T> = MutableHashSet.empty<T>()
|
||||
* ```
|
||||
*
|
||||
* @template K - The type of the elements to be stored in the hash set. Defaults
|
||||
* to `never` if not specified.
|
||||
* @returns A new mutable instance of `MutableHashSet` containing no elements
|
||||
* for the specified type `K`.
|
||||
* @see Other `MutableHashSet` constructors are {@link module:MutableHashSet.make} {@link module:MutableHashSet.fromIterable}
|
||||
*/
|
||||
export const empty = <K = never>(): MutableHashSet<K> => fromHashMap(MutableHashMap.empty())
|
||||
|
||||
/**
|
||||
* Creates a new `MutableHashSet` from an iterable collection of values.
|
||||
* Duplicate values are omitted.
|
||||
*
|
||||
* Time complexity: **`O(n)`** where n is the number of elements in the iterable
|
||||
*
|
||||
* Creating a `MutableHashSet` from an {@link Array}
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet } from "effect"
|
||||
*
|
||||
* const array: Iterable<number> = [1, 2, 3, 4, 5, 1, 2, 3] // Array<T> is also Iterable<T>
|
||||
* const mutableHashSet: MutableHashSet.MutableHashSet<number> =
|
||||
* MutableHashSet.fromIterable(array)
|
||||
*
|
||||
* console.log(
|
||||
* // MutableHashSet.MutableHashSet<T> is also an Iterable<T>
|
||||
* Array.from(mutableHashSet)
|
||||
* ) // Output: [1, 2, 3, 4, 5]
|
||||
* ```
|
||||
*
|
||||
* Creating a `MutableHashSet` from a {@link Set}
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* console.log(
|
||||
* pipe(
|
||||
* // Set<string> is an Iterable<string>
|
||||
* new Set(["apple", "banana", "orange", "apple"]),
|
||||
* // constructs MutableHashSet from an Iterable Set
|
||||
* MutableHashSet.fromIterable,
|
||||
* // since MutableHashSet it is itself an Iterable, we can pass it to other functions expecting an Iterable
|
||||
* Array.from
|
||||
* )
|
||||
* ) // Output: ["apple", "banana", "orange"]
|
||||
* ```
|
||||
*
|
||||
* Creating a `MutableHashSet` from a {@link Generator}
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet } from "effect"
|
||||
*
|
||||
* // Generator functions return iterables
|
||||
* function* fibonacci(n: number): Generator<number, void, never> {
|
||||
* let [a, b] = [0, 1]
|
||||
* for (let i = 0; i < n; i++) {
|
||||
* yield a
|
||||
* ;[a, b] = [b, a + b]
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // Create a MutableHashSet from the first 10 Fibonacci numbers
|
||||
* const fibonacciSet = MutableHashSet.fromIterable(fibonacci(10))
|
||||
*
|
||||
* console.log(Array.from(fibonacciSet))
|
||||
* // Outputs: [0, 1, 2, 3, 5, 8, 13, 21, 34] but in unsorted order
|
||||
* ```
|
||||
*
|
||||
* Creating a `MutableHashSet` from another {@link module:MutableHashSet}
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* console.log(
|
||||
* pipe(
|
||||
* MutableHashSet.make(1, 2, 3, 4),
|
||||
* MutableHashSet.fromIterable,
|
||||
* Array.from
|
||||
* )
|
||||
* ) // Output: [1, 2, 3, 4]
|
||||
* ```
|
||||
*
|
||||
* Creating a `MutableHashSet` from an {@link module:HashSet}
|
||||
*
|
||||
* ```ts
|
||||
* import { HashSet, MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* console.log(
|
||||
* pipe(
|
||||
* HashSet.make(1, 2, 3, 4), // it works also with its immutable HashSet sibling
|
||||
* MutableHashSet.fromIterable,
|
||||
* Array.from
|
||||
* )
|
||||
* ) // Output: [1, 2, 3, 4]
|
||||
* ```
|
||||
*
|
||||
* Creating a `MutableHashSet` from other Effect's data structures like
|
||||
* {@link Chunk}
|
||||
*
|
||||
* ```ts
|
||||
* import { Chunk, MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* console.log(
|
||||
* pipe(
|
||||
* Chunk.make(1, 2, 3, 4), // Chunk is also an Iterable<T>
|
||||
* MutableHashSet.fromIterable,
|
||||
* Array.from
|
||||
* )
|
||||
* ) // Outputs: [1, 2, 3, 4]
|
||||
* ```
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
* @template K - The type of elements to be stored in the resulting
|
||||
* `MutableHashSet`.
|
||||
* @param keys - An `Iterable` collection containing the keys to be added to the
|
||||
* `MutableHashSet`.
|
||||
* @returns A new `MutableHashSet` containing just the unique elements from the
|
||||
* provided iterable.
|
||||
* @see Other `MutableHashSet` constructors are {@link module:MutableHashSet.empty} {@link module:MutableHashSet.make}
|
||||
*/
|
||||
export const fromIterable = <K = never>(keys: Iterable<K>): MutableHashSet<K> =>
|
||||
fromHashMap(
|
||||
MutableHashMap.fromIterable(Array.from(keys).map((k) => [k, true]))
|
||||
)
|
||||
|
||||
/**
|
||||
* Construct a new `MutableHashSet` from a variable number of values.
|
||||
*
|
||||
* Time complexity: **`O(n)`** where n is the number of elements
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* import { Equal, Hash, MutableHashSet } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* class Character implements Equal.Equal {
|
||||
* readonly name: string
|
||||
* readonly trait: string
|
||||
*
|
||||
* constructor(name: string, trait: string) {
|
||||
* this.name = name
|
||||
* this.trait = trait
|
||||
* }
|
||||
*
|
||||
* // Define equality based on name, and trait
|
||||
* [Equal.symbol](that: Equal.Equal): boolean {
|
||||
* if (that instanceof Character) {
|
||||
* return (
|
||||
* Equal.equals(this.name, that.name) &&
|
||||
* Equal.equals(this.trait, that.trait)
|
||||
* )
|
||||
* }
|
||||
* return false
|
||||
* }
|
||||
*
|
||||
* // Generate a hash code based on the sum of the character's name and trait
|
||||
* [Hash.symbol](): number {
|
||||
* return Hash.hash(this.name + this.trait)
|
||||
* }
|
||||
*
|
||||
* static readonly of = (name: string, trait: string): Character => {
|
||||
* return new Character(name, trait)
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* const mutableCharacterHashSet = MutableHashSet.make(
|
||||
* Character.of("Alice", "Curious"),
|
||||
* Character.of("Alice", "Curious"),
|
||||
* Character.of("White Rabbit", "Always late"),
|
||||
* Character.of("Mad Hatter", "Tea enthusiast")
|
||||
* )
|
||||
*
|
||||
* assert.equal(
|
||||
* MutableHashSet.has(
|
||||
* mutableCharacterHashSet,
|
||||
* Character.of("Alice", "Curious")
|
||||
* ),
|
||||
* true
|
||||
* )
|
||||
* assert.equal(
|
||||
* MutableHashSet.has(
|
||||
* mutableCharacterHashSet,
|
||||
* Character.of("Fluffy", "Kind")
|
||||
* ),
|
||||
* false
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @see Other `MutableHashSet` constructors are {@link module:MutableHashSet.fromIterable} {@link module:MutableHashSet.empty}
|
||||
*/
|
||||
export const make = <Keys extends ReadonlyArray<unknown>>(
|
||||
...keys: Keys
|
||||
): MutableHashSet<Keys[number]> => fromIterable(keys)
|
||||
|
||||
/**
|
||||
* **Checks** whether the `MutableHashSet` contains the given element, and
|
||||
* **adds** it if not.
|
||||
*
|
||||
* Time complexity: **`O(1)`** average
|
||||
*
|
||||
* **Syntax**
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* // with data-last, a.k.a. pipeable API
|
||||
* pipe(
|
||||
* MutableHashSet.empty(),
|
||||
* MutableHashSet.add(0),
|
||||
* MutableHashSet.add(0)
|
||||
* )
|
||||
*
|
||||
* // or piped with the pipe function
|
||||
* MutableHashSet.empty().pipe(MutableHashSet.add(0))
|
||||
*
|
||||
* // or with data-first API
|
||||
* MutableHashSet.add(MutableHashSet.empty(), 0)
|
||||
* ```
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
* @see Other `MutableHashSet` elements are {@link module:MutableHashSet.remove} {@link module:MutableHashSet.size} {@link module:MutableHashSet.clear} {@link module:MutableHashSet.has}
|
||||
*/
|
||||
export const add: {
|
||||
/**
|
||||
* `data-last` a.k.a. `pipeable` API
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* const mutableHashSet = pipe(
|
||||
* MutableHashSet.empty<number>(), // MutableHashSet.MutableHashSet<number>
|
||||
* MutableHashSet.add(0),
|
||||
* MutableHashSet.add(1),
|
||||
* MutableHashSet.add(1),
|
||||
* MutableHashSet.add(2)
|
||||
* )
|
||||
*
|
||||
* assert.deepStrictEqual(
|
||||
* Array.from(mutableHashSet), // remember that MutableHashSet is also an Iterable
|
||||
* Array.of(0, 1, 2)
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @template V - The type of elements stored in the `MutableHashSet`.
|
||||
* @param key - The key to be added to the `MutableHashSet` if not already
|
||||
* present.
|
||||
* @returns A function that accepts a `MutableHashSet` and returns the
|
||||
* reference of the updated `MutableHashSet` including the key.
|
||||
*/
|
||||
<V>(key: V): (self: MutableHashSet<V>) => MutableHashSet<V>
|
||||
|
||||
/**
|
||||
* `data-first` API
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* const empty = MutableHashSet.empty<number>()
|
||||
* const withZero = MutableHashSet.add(empty, 0)
|
||||
* const withOne = MutableHashSet.add(withZero, 1)
|
||||
* const withTwo = MutableHashSet.add(withOne, 2)
|
||||
* const withTwoTwo = MutableHashSet.add(withTwo, 2)
|
||||
*
|
||||
* assert(Object.is(withTwoTwo, empty)) // proof that it does mutate the original set
|
||||
*
|
||||
* assert.deepStrictEqual(
|
||||
* Array.from(withTwoTwo), // remember that MutableHashSet is also an Iterable
|
||||
* Array.of(0, 1, 2)
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @template V - The type of elements stored in the `MutableHashSet`.
|
||||
* @param self - The `MutableHashSet` instance from which the key should be
|
||||
* added to.
|
||||
* @param key - The key to be added to the `MutableHashSet` if not already
|
||||
* present.
|
||||
* @returns The reference of the updated `MutableHashSet` including the key.
|
||||
*/
|
||||
<V>(self: MutableHashSet<V>, key: V): MutableHashSet<V>
|
||||
} = Dual.dual<
|
||||
<V>(key: V) => (self: MutableHashSet<V>) => MutableHashSet<V>,
|
||||
<V>(self: MutableHashSet<V>, key: V) => MutableHashSet<V>
|
||||
>(2, (self, key) => (MutableHashMap.set(self.keyMap, key, true), self))
|
||||
|
||||
/**
|
||||
* Checks if the specified value exists in the `MutableHashSet`.
|
||||
*
|
||||
* Time complexity: `O(1)` average
|
||||
*
|
||||
* **Syntax**
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* assert.equal(
|
||||
* // with `data-last`, a.k.a. `pipeable` API
|
||||
* pipe(MutableHashSet.make(0, 1, 2), MutableHashSet.has(3)),
|
||||
* false
|
||||
* )
|
||||
*
|
||||
* assert.equal(
|
||||
* // or piped with the pipe function
|
||||
* MutableHashSet.make(0, 1, 2).pipe(MutableHashSet.has(3)),
|
||||
* false
|
||||
* )
|
||||
*
|
||||
* assert.equal(
|
||||
* // or with `data-first` API
|
||||
* MutableHashSet.has(MutableHashSet.make(0, 1, 2), 3),
|
||||
* false
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
* @see Other `MutableHashSet` elements are {@link module:MutableHashSet.add} {@link module:MutableHashSet.remove} {@link module:MutableHashSet.size} {@link module:MutableHashSet.clear}
|
||||
*/
|
||||
export const has: {
|
||||
/**
|
||||
* `data-last` a.k.a. `pipeable` API
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert/strict"
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* const set = MutableHashSet.make(0, 1, 2)
|
||||
*
|
||||
* assert.equal(pipe(set, MutableHashSet.has(0)), true)
|
||||
* assert.equal(pipe(set, MutableHashSet.has(1)), true)
|
||||
* assert.equal(pipe(set, MutableHashSet.has(2)), true)
|
||||
* assert.equal(pipe(set, MutableHashSet.has(3)), false)
|
||||
* ```
|
||||
*/
|
||||
<V>(key: V): (self: MutableHashSet<V>) => boolean
|
||||
|
||||
/**
|
||||
* `data-first` API
|
||||
*
|
||||
* ```ts
|
||||
* import * as assert from "node:assert/strict"
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
*
|
||||
* const set = MutableHashSet.make(0, 1, 2)
|
||||
*
|
||||
* assert.equal(MutableHashSet.has(set, 0), true)
|
||||
* assert.equal(MutableHashSet.has(set, 1), true)
|
||||
* assert.equal(MutableHashSet.has(set, 2), true)
|
||||
* assert.equal(MutableHashSet.has(set, 3), false)
|
||||
* ```
|
||||
*/
|
||||
<V>(self: MutableHashSet<V>, key: V): boolean
|
||||
} = Dual.dual<
|
||||
<V>(key: V) => (self: MutableHashSet<V>) => boolean,
|
||||
<V>(self: MutableHashSet<V>, key: V) => boolean
|
||||
>(2, (self, key) => MutableHashMap.has(self.keyMap, key))
|
||||
|
||||
/**
|
||||
* Removes a value from the `MutableHashSet`.
|
||||
*
|
||||
* Time complexity: **`O(1)`** average
|
||||
*
|
||||
* **Syntax**
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* assert.equal(
|
||||
* // with `data-last`, a.k.a. `pipeable` API
|
||||
* pipe(
|
||||
* MutableHashSet.make(0, 1, 2),
|
||||
* MutableHashSet.remove(0),
|
||||
* MutableHashSet.has(0)
|
||||
* ),
|
||||
* false
|
||||
* )
|
||||
*
|
||||
* assert.equal(
|
||||
* // or piped with the pipe function
|
||||
* MutableHashSet.make(0, 1, 2).pipe(
|
||||
* MutableHashSet.remove(0),
|
||||
* MutableHashSet.has(0)
|
||||
* ),
|
||||
* false
|
||||
* )
|
||||
*
|
||||
* assert.equal(
|
||||
* // or with `data-first` API
|
||||
* MutableHashSet.remove(MutableHashSet.make(0, 1, 2), 0).pipe(
|
||||
* MutableHashSet.has(0)
|
||||
* ),
|
||||
* false
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
* @see Other `MutableHashSet` elements are {@link module:MutableHashSet.add} {@link module:MutableHashSet.has} {@link module:MutableHashSet.size} {@link module:MutableHashSet.clear}
|
||||
*/
|
||||
export const remove: {
|
||||
/**
|
||||
* `data-last` a.k.a. `pipeable` API
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* const set: MutableHashSet.MutableHashSet<number> = MutableHashSet.make(
|
||||
* 0,
|
||||
* 1,
|
||||
* 2
|
||||
* )
|
||||
* const result: MutableHashSet.MutableHashSet<number> = pipe(
|
||||
* set,
|
||||
* MutableHashSet.remove(0)
|
||||
* )
|
||||
*
|
||||
* assert(Object.is(set, result)) // set and result have the same identity
|
||||
* assert.equal(pipe(result, MutableHashSet.has(0)), false) // it has correctly removed 0
|
||||
* assert.equal(pipe(set, MutableHashSet.has(0)), false) // another proof that we are mutating the original MutableHashSet
|
||||
* assert.equal(pipe(result, MutableHashSet.has(1)), true)
|
||||
* assert.equal(pipe(result, MutableHashSet.has(2)), true)
|
||||
* ```
|
||||
*
|
||||
* @template V - The type of the elements in the `MutableHashSet`.
|
||||
* @param key - The key to be removed from the `MutableHashSet`.
|
||||
* @returns A function that takes a `MutableHashSet` as input and returns the
|
||||
* reference to the same `MutableHashSet` with the specified key removed.
|
||||
*/
|
||||
<V>(key: V): (self: MutableHashSet<V>) => MutableHashSet<V>
|
||||
|
||||
/**
|
||||
* `data-first` API
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* const set = MutableHashSet.make(0, 1, 2)
|
||||
* const result = MutableHashSet.remove(set, 0)
|
||||
*
|
||||
* assert(Object.is(set, result)) // set and result have the same identity
|
||||
* assert.equal(MutableHashSet.has(result, 0), false) // it has correctly removed 0
|
||||
* assert.equal(MutableHashSet.has(set, 0), false) // it mutates the original MutableHashSet
|
||||
* assert.equal(MutableHashSet.has(result, 1), true)
|
||||
* assert.equal(MutableHashSet.has(result, 2), true)
|
||||
* ```
|
||||
*
|
||||
* @template V - The type of the elements in the `MutableHashSet`.
|
||||
* @param self - The `MutableHashSet` to which the key will be removed from.
|
||||
* @param key - The value to be removed from the `MutableHashSet` if present.
|
||||
* @returns The reference to the updated `MutableHashSet`.
|
||||
*/
|
||||
<V>(self: MutableHashSet<V>, key: V): MutableHashSet<V>
|
||||
} = Dual.dual<
|
||||
<V>(key: V) => (self: MutableHashSet<V>) => MutableHashSet<V>,
|
||||
<V>(self: MutableHashSet<V>, key: V) => MutableHashSet<V>
|
||||
>(2, (self, key) => (MutableHashMap.remove(self.keyMap, key), self))
|
||||
|
||||
/**
|
||||
* Calculates the number of values in the `HashSet`.
|
||||
*
|
||||
* Time complexity: **`O(1)`**
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* assert.equal(MutableHashSet.size(MutableHashSet.empty()), 0)
|
||||
*
|
||||
* assert.equal(
|
||||
* MutableHashSet.size(MutableHashSet.make(1, 2, 2, 3, 4, 3)),
|
||||
* 4
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @template V - The type of the elements to be stored in the `MutableHashSet`.
|
||||
* @param self - The `MutableHashSet` instance for which the size is to be
|
||||
* determined.
|
||||
* @returns The total number of elements within the `MutableHashSet`.
|
||||
* @see Other `MutableHashSet` elements are {@link module:MutableHashSet.add} {@link module:MutableHashSet.has} {@link module:MutableHashSet.remove} {@link module:MutableHashSet.clear}
|
||||
*/
|
||||
export const size = <V>(self: MutableHashSet<V>): number => MutableHashMap.size(self.keyMap)
|
||||
|
||||
/**
|
||||
* Removes all values from the `MutableHashSet`.
|
||||
*
|
||||
* This function operates by delegating the clearing action to the underlying
|
||||
* key map associated with the given `MutableHashSet`. It ensures that the hash
|
||||
* set becomes empty while maintaining its existence and structure.
|
||||
*
|
||||
* @memberof MutableHashSet
|
||||
* @since 2.0.0
|
||||
* @category elements
|
||||
* @example
|
||||
*
|
||||
* ```ts
|
||||
* import { MutableHashSet, pipe } from "effect"
|
||||
* import assert from "node:assert/strict"
|
||||
*
|
||||
* assert.deepStrictEqual(
|
||||
* pipe(
|
||||
* MutableHashSet.make(1, 2, 3, 4),
|
||||
* MutableHashSet.clear,
|
||||
* MutableHashSet.size
|
||||
* ),
|
||||
* 0
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param self - The `MutableHashSet` to clear.
|
||||
* @returns The same `MutableHashSet` after all elements have been removed.
|
||||
* @see Other `MutableHashSet` elements are {@link module:MutableHashSet.add} {@link module:MutableHashSet.has} {@link module:MutableHashSet.remove} {@link module:MutableHashSet.size}
|
||||
*/
|
||||
export const clear = <V>(self: MutableHashSet<V>): MutableHashSet<V> => (
|
||||
MutableHashMap.clear(self.keyMap), self
|
||||
)
|
||||
333
_node_modules/effect/src/MutableList.ts
generated
Normal file
333
_node_modules/effect/src/MutableList.ts
generated
Normal file
@@ -0,0 +1,333 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Dual from "./Function.js"
|
||||
import { format, NodeInspectSymbol, toJSON } from "./Inspectable.js"
|
||||
import type { Inspectable } from "./Inspectable.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import { pipeArguments } from "./Pipeable.js"
|
||||
|
||||
const TypeId: unique symbol = Symbol.for("effect/MutableList") as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface MutableList<out A> extends Iterable<A>, Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
|
||||
/** @internal */
|
||||
head: LinkedListNode<A> | undefined
|
||||
/** @internal */
|
||||
tail: LinkedListNode<A> | undefined
|
||||
}
|
||||
|
||||
const MutableListProto: Omit<MutableList<unknown>, "head" | "tail"> = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator](this: MutableList<unknown>): Iterator<unknown> {
|
||||
let done = false
|
||||
let head: LinkedListNode<unknown> | undefined = this.head
|
||||
return {
|
||||
next() {
|
||||
if (done) {
|
||||
return this.return!()
|
||||
}
|
||||
if (head == null) {
|
||||
done = true
|
||||
return this.return!()
|
||||
}
|
||||
const value = head.value
|
||||
head = head.next
|
||||
return { done, value }
|
||||
},
|
||||
return(value?: unknown) {
|
||||
if (!done) {
|
||||
done = true
|
||||
}
|
||||
return { done: true, value }
|
||||
}
|
||||
}
|
||||
},
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON() {
|
||||
return {
|
||||
_id: "MutableList",
|
||||
values: Array.from(this).map(toJSON)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
interface MutableListImpl<A> extends MutableList<A> {
|
||||
_length: number
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
interface LinkedListNode<T> {
|
||||
removed: boolean
|
||||
value: T
|
||||
prev: LinkedListNode<T> | undefined
|
||||
next: LinkedListNode<T> | undefined
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
const makeNode = <T>(value: T): LinkedListNode<T> => ({
|
||||
value,
|
||||
removed: false,
|
||||
prev: undefined,
|
||||
next: undefined
|
||||
})
|
||||
|
||||
/**
|
||||
* Creates an empty `MutableList`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const empty = <A = never>(): MutableList<A> => {
|
||||
const list = Object.create(MutableListProto)
|
||||
list.head = undefined
|
||||
list.tail = undefined
|
||||
list._length = 0
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new `MutableList` from an iterable collection of values.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fromIterable = <A>(iterable: Iterable<A>): MutableList<A> => {
|
||||
const list = empty<A>()
|
||||
for (const element of iterable) {
|
||||
append(list, element)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new `MutableList` from the specified elements.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make = <A>(...elements: ReadonlyArray<A>): MutableList<A> => fromIterable(elements)
|
||||
|
||||
/**
|
||||
* Returns `true` if the list contains zero elements, `false`, otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isEmpty = <A>(self: MutableList<A>): boolean => length(self) === 0
|
||||
|
||||
/**
|
||||
* Returns the length of the list.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const length = <A>(self: MutableList<A>): number => (self as MutableListImpl<A>)._length
|
||||
|
||||
/**
|
||||
* Returns the last element of the list, if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const tail = <A>(self: MutableList<A>): A | undefined => self.tail === undefined ? undefined : self.tail.value
|
||||
|
||||
/**
|
||||
* Returns the first element of the list, if it exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const head = <A>(self: MutableList<A>): A | undefined => self.head === undefined ? undefined : self.head.value
|
||||
|
||||
/**
|
||||
* Executes the specified function `f` for each element in the list.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
export const forEach: {
|
||||
/**
|
||||
* Executes the specified function `f` for each element in the list.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<A>(f: (element: A) => void): (self: MutableList<A>) => void
|
||||
/**
|
||||
* Executes the specified function `f` for each element in the list.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category traversing
|
||||
*/
|
||||
<A>(self: MutableList<A>, f: (element: A) => void): void
|
||||
} = Dual.dual<
|
||||
<A>(f: (element: A) => void) => (self: MutableList<A>) => void,
|
||||
<A>(self: MutableList<A>, f: (element: A) => void) => void
|
||||
>(2, (self, f) => {
|
||||
let current = self.head
|
||||
while (current !== undefined) {
|
||||
f(current.value)
|
||||
current = current.next
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Removes all elements from the doubly-linked list.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const reset = <A>(self: MutableList<A>): MutableList<A> => {
|
||||
;(self as MutableListImpl<A>)._length = 0
|
||||
self.head = undefined
|
||||
self.tail = undefined
|
||||
return self
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified element to the end of the `MutableList`.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const append: {
|
||||
/**
|
||||
* Appends the specified element to the end of the `MutableList`.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(value: A): (self: MutableList<A>) => MutableList<A>
|
||||
/**
|
||||
* Appends the specified element to the end of the `MutableList`.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: MutableList<A>, value: A): MutableList<A>
|
||||
} = Dual.dual<
|
||||
<A>(value: A) => (self: MutableList<A>) => MutableList<A>,
|
||||
<A>(self: MutableList<A>, value: A) => MutableList<A>
|
||||
>(2, <A>(self: MutableList<A>, value: A) => {
|
||||
const node = makeNode(value)
|
||||
if (self.head === undefined) {
|
||||
self.head = node
|
||||
}
|
||||
if (self.tail === undefined) {
|
||||
self.tail = node
|
||||
} else {
|
||||
self.tail.next = node
|
||||
node.prev = self.tail
|
||||
self.tail = node
|
||||
}
|
||||
;(self as MutableListImpl<A>)._length += 1
|
||||
return self
|
||||
})
|
||||
|
||||
/**
|
||||
* Removes the first value from the list and returns it, if it exists.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
export const shift = <A>(self: MutableList<A>): A | undefined => {
|
||||
const head = self.head
|
||||
if (head !== undefined) {
|
||||
remove(self, head)
|
||||
return head.value
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last value from the list and returns it, if it exists.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
export const pop = <A>(self: MutableList<A>): A | undefined => {
|
||||
const tail = self.tail
|
||||
if (tail !== undefined) {
|
||||
remove(self, tail)
|
||||
return tail.value
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends the specified value to the beginning of the list.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const prepend: {
|
||||
/**
|
||||
* Prepends the specified value to the beginning of the list.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(value: A): (self: MutableList<A>) => MutableList<A>
|
||||
/**
|
||||
* Prepends the specified value to the beginning of the list.
|
||||
*
|
||||
* @category concatenating
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: MutableList<A>, value: A): MutableList<A>
|
||||
} = Dual.dual<
|
||||
<A>(value: A) => (self: MutableList<A>) => MutableList<A>,
|
||||
<A>(self: MutableList<A>, value: A) => MutableList<A>
|
||||
>(2, <A>(self: MutableList<A>, value: A) => {
|
||||
const node = makeNode(value)
|
||||
node.next = self.head
|
||||
if (self.head !== undefined) {
|
||||
self.head.prev = node
|
||||
}
|
||||
self.head = node
|
||||
if (self.tail === undefined) {
|
||||
self.tail = node
|
||||
}
|
||||
;(self as MutableListImpl<A>)._length += 1
|
||||
return self
|
||||
})
|
||||
|
||||
const remove = <A>(self: MutableList<A>, node: LinkedListNode<A>): void => {
|
||||
if (node.removed) {
|
||||
return
|
||||
}
|
||||
node.removed = true
|
||||
if (node.prev !== undefined && node.next !== undefined) {
|
||||
node.prev.next = node.next
|
||||
node.next.prev = node.prev
|
||||
} else if (node.prev !== undefined) {
|
||||
self.tail = node.prev
|
||||
node.prev.next = undefined
|
||||
} else if (node.next !== undefined) {
|
||||
self.head = node.next
|
||||
node.next.prev = undefined
|
||||
} else {
|
||||
self.tail = undefined
|
||||
self.head = undefined
|
||||
}
|
||||
if ((self as MutableListImpl<A>)._length > 0) {
|
||||
;(self as MutableListImpl<A>)._length -= 1
|
||||
}
|
||||
}
|
||||
289
_node_modules/effect/src/MutableQueue.ts
generated
Normal file
289
_node_modules/effect/src/MutableQueue.ts
generated
Normal file
@@ -0,0 +1,289 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Chunk from "./Chunk.js"
|
||||
import * as Dual from "./Function.js"
|
||||
import { 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"
|
||||
|
||||
const TypeId: unique symbol = Symbol.for("effect/MutableQueue") as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export const EmptyMutableQueue = Symbol.for("effect/mutable/MutableQueue/Empty")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category model
|
||||
*/
|
||||
export interface MutableQueue<out A> extends Iterable<A>, Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
|
||||
/** @internal */
|
||||
queue: MutableList.MutableList<A>
|
||||
/** @internal */
|
||||
capacity: number | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace MutableQueue {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Empty = typeof EmptyMutableQueue
|
||||
}
|
||||
|
||||
const MutableQueueProto: Omit<MutableQueue<unknown>, "queue" | "capacity"> = {
|
||||
[TypeId]: TypeId,
|
||||
[Symbol.iterator]<A>(this: MutableQueue<A>): Iterator<A> {
|
||||
return Array.from(this.queue)[Symbol.iterator]()
|
||||
},
|
||||
toString() {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON() {
|
||||
return {
|
||||
_id: "MutableQueue",
|
||||
values: Array.from(this).map(toJSON)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const make = <A>(capacity: number | undefined): MutableQueue<A> => {
|
||||
const queue = Object.create(MutableQueueProto)
|
||||
queue.queue = MutableList.empty()
|
||||
queue.capacity = capacity
|
||||
return queue
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new bounded `MutableQueue`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const bounded = <A>(capacity: number): MutableQueue<A> => make(capacity)
|
||||
|
||||
/**
|
||||
* Creates a new unbounded `MutableQueue`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unbounded = <A>(): MutableQueue<A> => make(undefined)
|
||||
|
||||
/**
|
||||
* Returns the current number of elements in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const length = <A>(self: MutableQueue<A>): number => MutableList.length(self.queue)
|
||||
|
||||
/**
|
||||
* Returns `true` if the queue is empty, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isEmpty = <A>(self: MutableQueue<A>): boolean => MutableList.isEmpty(self.queue)
|
||||
|
||||
/**
|
||||
* Returns `true` if the queue is full, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isFull = <A>(self: MutableQueue<A>): boolean =>
|
||||
self.capacity === undefined ? false : MutableList.length(self.queue) === self.capacity
|
||||
|
||||
/**
|
||||
* The **maximum** number of elements that a queue can hold.
|
||||
*
|
||||
* **Note**: unbounded queues can still implement this interface with
|
||||
* `capacity = Infinity`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const capacity = <A>(self: MutableQueue<A>): number => self.capacity === undefined ? Infinity : self.capacity
|
||||
|
||||
/**
|
||||
* Offers an element to the queue.
|
||||
*
|
||||
* Returns whether the enqueue was successful or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const offer: {
|
||||
/**
|
||||
* Offers an element to the queue.
|
||||
*
|
||||
* Returns whether the enqueue was successful or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: MutableQueue<A>, value: A): boolean
|
||||
/**
|
||||
* Offers an element to the queue.
|
||||
*
|
||||
* Returns whether the enqueue was successful or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(value: A): (self: MutableQueue<A>) => boolean
|
||||
} = Dual.dual<
|
||||
<A>(value: A) => (self: MutableQueue<A>) => boolean,
|
||||
<A>(self: MutableQueue<A>, value: A) => boolean
|
||||
>(2, <A>(self: MutableQueue<A>, value: A) => {
|
||||
const queueLength = MutableList.length(self.queue)
|
||||
if (self.capacity !== undefined && queueLength === self.capacity) {
|
||||
return false
|
||||
}
|
||||
MutableList.append(value)(self.queue)
|
||||
return true
|
||||
})
|
||||
|
||||
/**
|
||||
* Enqueues a collection of values into the queue.
|
||||
*
|
||||
* Returns a `Chunk` of the values that were **not** able to be enqueued.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const offerAll: {
|
||||
/**
|
||||
* Enqueues a collection of values into the queue.
|
||||
*
|
||||
* Returns a `Chunk` of the values that were **not** able to be enqueued.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(values: Iterable<A>): (self: MutableQueue<A>) => Chunk.Chunk<A>
|
||||
/**
|
||||
* Enqueues a collection of values into the queue.
|
||||
*
|
||||
* Returns a `Chunk` of the values that were **not** able to be enqueued.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: MutableQueue<A>, values: Iterable<A>): Chunk.Chunk<A>
|
||||
} = Dual.dual<
|
||||
<A>(values: Iterable<A>) => (self: MutableQueue<A>) => Chunk.Chunk<A>,
|
||||
<A>(self: MutableQueue<A>, values: Iterable<A>) => Chunk.Chunk<A>
|
||||
>(2, <A>(self: MutableQueue<A>, values: Iterable<A>) => {
|
||||
const iterator = values[Symbol.iterator]()
|
||||
let next: IteratorResult<A> | undefined
|
||||
let remainder = Chunk.empty<A>()
|
||||
let offering = true
|
||||
while (offering && (next = iterator.next()) && !next.done) {
|
||||
offering = offer(next.value)(self)
|
||||
}
|
||||
while (next != null && !next.done) {
|
||||
remainder = Chunk.prepend<A>(next.value)(remainder)
|
||||
next = iterator.next()
|
||||
}
|
||||
return Chunk.reverse(remainder)
|
||||
})
|
||||
|
||||
/**
|
||||
* Dequeues an element from the queue.
|
||||
*
|
||||
* Returns either an element from the queue, or the `def` param.
|
||||
*
|
||||
* **Note**: if there is no meaningful default for your type, you can always
|
||||
* use `poll(MutableQueue.EmptyMutableQueue)`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const poll: {
|
||||
/**
|
||||
* Dequeues an element from the queue.
|
||||
*
|
||||
* Returns either an element from the queue, or the `def` param.
|
||||
*
|
||||
* **Note**: if there is no meaningful default for your type, you can always
|
||||
* use `poll(MutableQueue.EmptyMutableQueue)`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<D>(def: D): <A>(self: MutableQueue<A>) => D | A
|
||||
/**
|
||||
* Dequeues an element from the queue.
|
||||
*
|
||||
* Returns either an element from the queue, or the `def` param.
|
||||
*
|
||||
* **Note**: if there is no meaningful default for your type, you can always
|
||||
* use `poll(MutableQueue.EmptyMutableQueue)`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, D>(self: MutableQueue<A>, def: D): A | D
|
||||
} = Dual.dual<
|
||||
<D>(def: D) => <A>(self: MutableQueue<A>) => A | D,
|
||||
<A, D>(self: MutableQueue<A>, def: D) => A | D
|
||||
>(2, (self, def) => {
|
||||
if (MutableList.isEmpty(self.queue)) {
|
||||
return def
|
||||
}
|
||||
return MutableList.shift(self.queue)!
|
||||
})
|
||||
|
||||
/**
|
||||
* Dequeues up to `n` elements from the queue.
|
||||
*
|
||||
* Returns a `List` of up to `n` elements.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const pollUpTo: {
|
||||
/**
|
||||
* Dequeues up to `n` elements from the queue.
|
||||
*
|
||||
* Returns a `List` of up to `n` elements.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(n: number): <A>(self: MutableQueue<A>) => Chunk.Chunk<A>
|
||||
/**
|
||||
* Dequeues up to `n` elements from the queue.
|
||||
*
|
||||
* Returns a `List` of up to `n` elements.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: MutableQueue<A>, n: number): Chunk.Chunk<A>
|
||||
} = Dual.dual<
|
||||
(n: number) => <A>(self: MutableQueue<A>) => Chunk.Chunk<A>,
|
||||
<A>(self: MutableQueue<A>, n: number) => Chunk.Chunk<A>
|
||||
>(2, <A>(self: MutableQueue<A>, n: number) => {
|
||||
let result = Chunk.empty<A>()
|
||||
let count = 0
|
||||
while (count < n) {
|
||||
const element = poll(EmptyMutableQueue)(self)
|
||||
if (element === EmptyMutableQueue) {
|
||||
break
|
||||
}
|
||||
result = Chunk.prepend(element)(result)
|
||||
count += 1
|
||||
}
|
||||
return Chunk.reverse(result)
|
||||
})
|
||||
258
_node_modules/effect/src/MutableRef.ts
generated
Normal file
258
_node_modules/effect/src/MutableRef.ts
generated
Normal file
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import * as Equal from "./Equal.js"
|
||||
import * as Dual from "./Function.js"
|
||||
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import { pipeArguments } from "./Pipeable.js"
|
||||
|
||||
const TypeId: unique symbol = Symbol.for("effect/MutableRef") as TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbol
|
||||
*/
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface MutableRef<out T> extends Pipeable, Inspectable {
|
||||
readonly [TypeId]: TypeId
|
||||
current: T
|
||||
}
|
||||
|
||||
const MutableRefProto: Omit<MutableRef<unknown>, "current"> = {
|
||||
[TypeId]: TypeId,
|
||||
toString<A>(this: MutableRef<A>): string {
|
||||
return format(this.toJSON())
|
||||
},
|
||||
toJSON<A>(this: MutableRef<A>) {
|
||||
return {
|
||||
_id: "MutableRef",
|
||||
current: toJSON(this.current)
|
||||
}
|
||||
},
|
||||
[NodeInspectSymbol]() {
|
||||
return this.toJSON()
|
||||
},
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make = <T>(value: T): MutableRef<T> => {
|
||||
const ref = Object.create(MutableRefProto)
|
||||
ref.current = value
|
||||
return ref
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const compareAndSet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(oldValue: T, newValue: T): (self: MutableRef<T>) => boolean
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, oldValue: T, newValue: T): boolean
|
||||
} = Dual.dual<
|
||||
<T>(oldValue: T, newValue: T) => (self: MutableRef<T>) => boolean,
|
||||
<T>(self: MutableRef<T>, oldValue: T, newValue: T) => boolean
|
||||
>(3, (self, oldValue, newValue) => {
|
||||
if (Equal.equals(oldValue, self.current)) {
|
||||
self.current = newValue
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const decrement = (self: MutableRef<number>): MutableRef<number> => update(self, (n) => n - 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const decrementAndGet = (self: MutableRef<number>): number => updateAndGet(self, (n) => n - 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const get = <T>(self: MutableRef<T>): T => self.current
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const getAndDecrement = (self: MutableRef<number>): number => getAndUpdate(self, (n) => n - 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const getAndIncrement = (self: MutableRef<number>): number => getAndUpdate(self, (n) => n + 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const getAndSet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(value: T): (self: MutableRef<T>) => T
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, value: T): T
|
||||
} = Dual.dual<
|
||||
<T>(value: T) => (self: MutableRef<T>) => T,
|
||||
<T>(self: MutableRef<T>, value: T) => T
|
||||
>(2, (self, value) => {
|
||||
const ret = self.current
|
||||
self.current = value
|
||||
return ret
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const getAndUpdate: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(f: (value: T) => T): (self: MutableRef<T>) => T
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T): T
|
||||
} = Dual.dual<
|
||||
<T>(f: (value: T) => T) => (self: MutableRef<T>) => T,
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T) => T
|
||||
>(2, (self, f) => getAndSet(self, f(get(self))))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const increment = (self: MutableRef<number>): MutableRef<number> => update(self, (n) => n + 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category numeric
|
||||
*/
|
||||
export const incrementAndGet = (self: MutableRef<number>): number => updateAndGet(self, (n) => n + 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const set: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(value: T): (self: MutableRef<T>) => MutableRef<T>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, value: T): MutableRef<T>
|
||||
} = Dual.dual<
|
||||
<T>(value: T) => (self: MutableRef<T>) => MutableRef<T>,
|
||||
<T>(self: MutableRef<T>, value: T) => MutableRef<T>
|
||||
>(2, (self, value) => {
|
||||
self.current = value
|
||||
return self
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const setAndGet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(value: T): (self: MutableRef<T>) => T
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, value: T): T
|
||||
} = Dual.dual<
|
||||
<T>(value: T) => (self: MutableRef<T>) => T,
|
||||
<T>(self: MutableRef<T>, value: T) => T
|
||||
>(2, (self, value) => {
|
||||
self.current = value
|
||||
return self.current
|
||||
})
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const update: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(f: (value: T) => T): (self: MutableRef<T>) => MutableRef<T>
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T): MutableRef<T>
|
||||
} = Dual.dual<
|
||||
<T>(f: (value: T) => T) => (self: MutableRef<T>) => MutableRef<T>,
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T) => MutableRef<T>
|
||||
>(2, (self, f) => set(self, f(get(self))))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
export const updateAndGet: {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(f: (value: T) => T): (self: MutableRef<T>) => T
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category general
|
||||
*/
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T): T
|
||||
} = Dual.dual<
|
||||
<T>(f: (value: T) => T) => (self: MutableRef<T>) => T,
|
||||
<T>(self: MutableRef<T>, f: (value: T) => T) => T
|
||||
>(2, (self, f) => setAndGet(self, f(get(self))))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category boolean
|
||||
*/
|
||||
export const toggle = (self: MutableRef<boolean>): MutableRef<boolean> => update(self, (_) => !_)
|
||||
32
_node_modules/effect/src/NonEmptyIterable.ts
generated
Normal file
32
_node_modules/effect/src/NonEmptyIterable.ts
generated
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category symbol
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare const nonEmpty: unique symbol
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface NonEmptyIterable<out A> extends Iterable<A> {
|
||||
readonly [nonEmpty]: A
|
||||
}
|
||||
|
||||
/**
|
||||
* @category getters
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const unprepend = <A>(self: NonEmptyIterable<A>): [firstElement: A, remainingElements: Iterator<A>] => {
|
||||
const iterator = self[Symbol.iterator]()
|
||||
const next = iterator.next()
|
||||
if (next.done) {
|
||||
throw new Error(
|
||||
"BUG: NonEmptyIterator should not be empty - please report an issue at https://github.com/Effect-TS/effect/issues"
|
||||
)
|
||||
}
|
||||
return [next.value, iterator]
|
||||
}
|
||||
1440
_node_modules/effect/src/Number.ts
generated
Normal file
1440
_node_modules/effect/src/Number.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
4028
_node_modules/effect/src/Option.ts
generated
Normal file
4028
_node_modules/effect/src/Option.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
397
_node_modules/effect/src/Order.ts
generated
Normal file
397
_node_modules/effect/src/Order.ts
generated
Normal file
@@ -0,0 +1,397 @@
|
||||
/**
|
||||
* This module provides an implementation of the `Order` type class which is used to define a total ordering on some type `A`.
|
||||
* An order is defined by a relation `<=`, which obeys the following laws:
|
||||
*
|
||||
* - either `x <= y` or `y <= x` (totality)
|
||||
* - if `x <= y` and `y <= x`, then `x == y` (antisymmetry)
|
||||
* - if `x <= y` and `y <= z`, then `x <= z` (transitivity)
|
||||
*
|
||||
* The truth table for compare is defined as follows:
|
||||
*
|
||||
* | `x <= y` | `x >= y` | Ordering | |
|
||||
* | -------- | -------- | -------- | --------------------- |
|
||||
* | `true` | `true` | `0` | corresponds to x == y |
|
||||
* | `true` | `false` | `< 0` | corresponds to x < y |
|
||||
* | `false` | `true` | `> 0` | corresponds to x > y |
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import { dual } from "./Function.js"
|
||||
import type { TypeLambda } from "./HKT.js"
|
||||
|
||||
/**
|
||||
* @category type class
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface Order<in A> {
|
||||
(self: A, that: A): -1 | 0 | 1
|
||||
}
|
||||
|
||||
/**
|
||||
* @category type lambdas
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export interface OrderTypeLambda extends TypeLambda {
|
||||
readonly type: Order<this["Target"]>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category constructors
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const make = <A>(
|
||||
compare: (self: A, that: A) => -1 | 0 | 1
|
||||
): Order<A> =>
|
||||
(self, that) => self === that ? 0 : compare(self, that)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const string: Order<string> = make((self, that) => self < that ? -1 : 1)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const number: Order<number> = make((self, that) => self < that ? -1 : 1)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const boolean: Order<boolean> = make((self, that) => self < that ? -1 : 1)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const bigint: Order<bigint> = make((self, that) => self < that ? -1 : 1)
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const reverse = <A>(O: Order<A>): Order<A> => make((self, that) => O(that, self))
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(that: Order<A>): (self: Order<A>) => Order<A>
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: Order<A>, that: Order<A>): Order<A>
|
||||
} = dual(2, <A>(self: Order<A>, that: Order<A>): Order<A> =>
|
||||
make((a1, a2) => {
|
||||
const out = self(a1, a2)
|
||||
if (out !== 0) {
|
||||
return out
|
||||
}
|
||||
return that(a1, a2)
|
||||
}))
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineMany: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<A>
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A>
|
||||
} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<A> =>
|
||||
make((a1, a2) => {
|
||||
let out = self(a1, a2)
|
||||
if (out !== 0) {
|
||||
return out
|
||||
}
|
||||
for (const O of collection) {
|
||||
out = O(a1, a2)
|
||||
if (out !== 0) {
|
||||
return out
|
||||
}
|
||||
}
|
||||
return out
|
||||
}))
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const empty = <A>(): Order<A> => make(() => 0)
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineAll = <A>(collection: Iterable<Order<A>>): Order<A> => combineMany(empty(), collection)
|
||||
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const mapInput: {
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<B, A>(f: (b: B) => A): (self: Order<A>) => Order<B>
|
||||
/**
|
||||
* @category mapping
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B>(self: Order<A>, f: (b: B) => A): Order<B>
|
||||
} = dual(
|
||||
2,
|
||||
<A, B>(self: Order<A>, f: (b: B) => A): Order<B> => make((b1, b2) => self(f(b1), f(b2)))
|
||||
)
|
||||
|
||||
/**
|
||||
* @category instances
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const Date: Order<Date> = mapInput(number, (date) => date.getTime())
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const product: {
|
||||
<B>(that: Order<B>): <A>(self: Order<A>) => Order<readonly [A, B]> // readonly because invariant
|
||||
<A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> // readonly because invariant
|
||||
} = dual(2, <A, B>(self: Order<A>, that: Order<B>): Order<readonly [A, B]> =>
|
||||
make(([xa, xb], [ya, yb]) => {
|
||||
const o = self(xa, ya)
|
||||
return o !== 0 ? o : that(xb, yb)
|
||||
}))
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const all = <A>(collection: Iterable<Order<A>>): Order<ReadonlyArray<A>> => {
|
||||
return make((x, y) => {
|
||||
const len = Math.min(x.length, y.length)
|
||||
let collectionLength = 0
|
||||
for (const O of collection) {
|
||||
if (collectionLength >= len) {
|
||||
break
|
||||
}
|
||||
const o = O(x[collectionLength], y[collectionLength])
|
||||
if (o !== 0) {
|
||||
return o
|
||||
}
|
||||
collectionLength++
|
||||
}
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const productMany: {
|
||||
<A>(collection: Iterable<Order<A>>): (self: Order<A>) => Order<readonly [A, ...Array<A>]> // readonly because invariant
|
||||
<A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> // readonly because invariant
|
||||
} = dual(2, <A>(self: Order<A>, collection: Iterable<Order<A>>): Order<readonly [A, ...Array<A>]> => {
|
||||
const O = all(collection)
|
||||
return make((x, y) => {
|
||||
const o = self(x[0], y[0])
|
||||
return o !== 0 ? o : O(x.slice(1), y.slice(1))
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Similar to `Promise.all` but operates on `Order`s.
|
||||
*
|
||||
* ```
|
||||
* [Order<A>, Order<B>, ...] -> Order<[A, B, ...]>
|
||||
* ```
|
||||
*
|
||||
* This function creates and returns a new `Order` for a tuple of values based on the given `Order`s for each element in the tuple.
|
||||
* The returned `Order` compares two tuples of the same type by applying the corresponding `Order` to each element in the tuple.
|
||||
* It is useful when you need to compare two tuples of the same type and you have a specific way of comparing each element
|
||||
* of the tuple.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const tuple = <T extends ReadonlyArray<Order<any>>>(
|
||||
...elements: T
|
||||
): Order<Readonly<{ [I in keyof T]: [T[I]] extends [Order<infer A>] ? A : never }>> => all(elements) as any
|
||||
|
||||
/**
|
||||
* This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.
|
||||
* The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.
|
||||
* If all elements are equal, the arrays are then compared based on their length.
|
||||
* It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const array = <A>(O: Order<A>): Order<ReadonlyArray<A>> =>
|
||||
make((self, that) => {
|
||||
const aLen = self.length
|
||||
const bLen = that.length
|
||||
const len = Math.min(aLen, bLen)
|
||||
for (let i = 0; i < len; i++) {
|
||||
const o = O(self[i], that[i])
|
||||
if (o !== 0) {
|
||||
return o
|
||||
}
|
||||
}
|
||||
return number(aLen, bLen)
|
||||
})
|
||||
|
||||
/**
|
||||
* This function creates and returns a new `Order` for a struct of values based on the given `Order`s
|
||||
* for each property in the struct.
|
||||
*
|
||||
* @category combinators
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const struct = <R extends { readonly [x: string]: Order<any> }>(
|
||||
fields: R
|
||||
): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> => {
|
||||
const keys = Object.keys(fields)
|
||||
return make((self, that) => {
|
||||
for (const key of keys) {
|
||||
const o = fields[key](self[key], that[key])
|
||||
if (o !== 0) {
|
||||
return o
|
||||
}
|
||||
}
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether one value is _strictly less than_ another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const lessThan = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => boolean
|
||||
(self: A, that: A): boolean
|
||||
} => dual(2, (self: A, that: A) => O(self, that) === -1)
|
||||
|
||||
/**
|
||||
* Test whether one value is _strictly greater than_ another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const greaterThan = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => boolean
|
||||
(self: A, that: A): boolean
|
||||
} => dual(2, (self: A, that: A) => O(self, that) === 1)
|
||||
|
||||
/**
|
||||
* Test whether one value is _non-strictly less than_ another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const lessThanOrEqualTo = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => boolean
|
||||
(self: A, that: A): boolean
|
||||
} => dual(2, (self: A, that: A) => O(self, that) !== 1)
|
||||
|
||||
/**
|
||||
* Test whether one value is _non-strictly greater than_ another.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const greaterThanOrEqualTo = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => boolean
|
||||
(self: A, that: A): boolean
|
||||
} => dual(2, (self: A, that: A) => O(self, that) !== -1)
|
||||
|
||||
/**
|
||||
* Take the minimum of two values. If they are considered equal, the first argument is chosen.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const min = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => A
|
||||
(self: A, that: A): A
|
||||
} => dual(2, (self: A, that: A) => self === that || O(self, that) < 1 ? self : that)
|
||||
|
||||
/**
|
||||
* Take the maximum of two values. If they are considered equal, the first argument is chosen.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const max = <A>(O: Order<A>): {
|
||||
(that: A): (self: A) => A
|
||||
(self: A, that: A): A
|
||||
} => dual(2, (self: A, that: A) => self === that || O(self, that) > -1 ? self : that)
|
||||
|
||||
/**
|
||||
* Clamp a value between a minimum and a maximum.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Order, Number } from "effect"
|
||||
*
|
||||
* const clamp = Order.clamp(Number.Order)({ minimum: 1, maximum: 5 })
|
||||
*
|
||||
* assert.equal(clamp(3), 3)
|
||||
* assert.equal(clamp(0), 1)
|
||||
* assert.equal(clamp(6), 5)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const clamp = <A>(O: Order<A>): {
|
||||
(options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): (self: A) => A
|
||||
(self: A, options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): A
|
||||
} =>
|
||||
dual(
|
||||
2,
|
||||
(self: A, options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): A => min(O)(options.maximum, max(O)(options.minimum, self))
|
||||
)
|
||||
|
||||
/**
|
||||
* Test whether a value is between a minimum and a maximum (inclusive).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const between = <A>(O: Order<A>): {
|
||||
(options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): (self: A) => boolean
|
||||
(self: A, options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): boolean
|
||||
} =>
|
||||
dual(
|
||||
2,
|
||||
(self: A, options: {
|
||||
minimum: A
|
||||
maximum: A
|
||||
}): boolean => !lessThan(O)(self, options.minimum) && !greaterThan(O)(self, options.maximum)
|
||||
)
|
||||
173
_node_modules/effect/src/Ordering.ts
generated
Normal file
173
_node_modules/effect/src/Ordering.ts
generated
Normal file
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { LazyArg } from "./Function.js"
|
||||
import { dual } from "./Function.js"
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export type Ordering = -1 | 0 | 1
|
||||
|
||||
/**
|
||||
* Inverts the ordering of the input `Ordering`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { reverse } from "effect/Ordering"
|
||||
*
|
||||
* assert.deepStrictEqual(reverse(1), -1)
|
||||
* assert.deepStrictEqual(reverse(-1), 1)
|
||||
* assert.deepStrictEqual(reverse(0), 0)
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const reverse = (o: Ordering): Ordering => (o === -1 ? 1 : o === 1 ? -1 : 0)
|
||||
|
||||
/**
|
||||
* Depending on the `Ordering` parameter given to it, returns a value produced by one of the 3 functions provided as parameters.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Ordering } from "effect"
|
||||
* import { constant } from "effect/Function"
|
||||
*
|
||||
* const toMessage = Ordering.match({
|
||||
* onLessThan: constant('less than'),
|
||||
* onEqual: constant('equal'),
|
||||
* onGreaterThan: constant('greater than')
|
||||
* })
|
||||
*
|
||||
* assert.deepStrictEqual(toMessage(-1), "less than")
|
||||
* assert.deepStrictEqual(toMessage(0), "equal")
|
||||
* assert.deepStrictEqual(toMessage(1), "greater than")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const match: {
|
||||
/**
|
||||
* Depending on the `Ordering` parameter given to it, returns a value produced by one of the 3 functions provided as parameters.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Ordering } from "effect"
|
||||
* import { constant } from "effect/Function"
|
||||
*
|
||||
* const toMessage = Ordering.match({
|
||||
* onLessThan: constant('less than'),
|
||||
* onEqual: constant('equal'),
|
||||
* onGreaterThan: constant('greater than')
|
||||
* })
|
||||
*
|
||||
* assert.deepStrictEqual(toMessage(-1), "less than")
|
||||
* assert.deepStrictEqual(toMessage(0), "equal")
|
||||
* assert.deepStrictEqual(toMessage(1), "greater than")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B, C = B>(
|
||||
options: {
|
||||
readonly onLessThan: LazyArg<A>
|
||||
readonly onEqual: LazyArg<B>
|
||||
readonly onGreaterThan: LazyArg<C>
|
||||
}
|
||||
): (self: Ordering) => A | B | C
|
||||
/**
|
||||
* Depending on the `Ordering` parameter given to it, returns a value produced by one of the 3 functions provided as parameters.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Ordering } from "effect"
|
||||
* import { constant } from "effect/Function"
|
||||
*
|
||||
* const toMessage = Ordering.match({
|
||||
* onLessThan: constant('less than'),
|
||||
* onEqual: constant('equal'),
|
||||
* onGreaterThan: constant('greater than')
|
||||
* })
|
||||
*
|
||||
* assert.deepStrictEqual(toMessage(-1), "less than")
|
||||
* assert.deepStrictEqual(toMessage(0), "equal")
|
||||
* assert.deepStrictEqual(toMessage(1), "greater than")
|
||||
* ```
|
||||
*
|
||||
* @category pattern matching
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<A, B, C = B>(
|
||||
o: Ordering,
|
||||
options: {
|
||||
readonly onLessThan: LazyArg<A>
|
||||
readonly onEqual: LazyArg<B>
|
||||
readonly onGreaterThan: LazyArg<C>
|
||||
}
|
||||
): A | B | C
|
||||
} = dual(2, <A, B, C = B>(
|
||||
self: Ordering,
|
||||
{ onEqual, onGreaterThan, onLessThan }: {
|
||||
readonly onLessThan: LazyArg<A>
|
||||
readonly onEqual: LazyArg<B>
|
||||
readonly onGreaterThan: LazyArg<C>
|
||||
}
|
||||
): A | B | C => self === -1 ? onLessThan() : self === 0 ? onEqual() : onGreaterThan())
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combine: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(that: Ordering): (self: Ordering) => Ordering
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: Ordering, that: Ordering): Ordering
|
||||
} = dual(2, (self: Ordering, that: Ordering): Ordering => self !== 0 ? self : that)
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineMany: {
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(collection: Iterable<Ordering>): (self: Ordering) => Ordering
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
(self: Ordering, collection: Iterable<Ordering>): Ordering
|
||||
} = dual(2, (self: Ordering, collection: Iterable<Ordering>): Ordering => {
|
||||
let ordering = self
|
||||
if (ordering !== 0) {
|
||||
return ordering
|
||||
}
|
||||
for (ordering of collection) {
|
||||
if (ordering !== 0) {
|
||||
return ordering
|
||||
}
|
||||
}
|
||||
return ordering
|
||||
})
|
||||
|
||||
/**
|
||||
* @category combining
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const combineAll = (collection: Iterable<Ordering>): Ordering => combineMany(0, collection)
|
||||
2069
_node_modules/effect/src/ParseResult.ts
generated
Normal file
2069
_node_modules/effect/src/ParseResult.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
574
_node_modules/effect/src/Pipeable.ts
generated
Normal file
574
_node_modules/effect/src/Pipeable.ts
generated
Normal file
@@ -0,0 +1,574 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
import type { Ctor } from "./Types.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category Models
|
||||
*/
|
||||
export interface Pipeable {
|
||||
pipe<A>(this: A): A
|
||||
pipe<A, B = never>(this: A, ab: (_: A) => B): B
|
||||
pipe<A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C
|
||||
pipe<A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D
|
||||
pipe<A, B = never, C = never, D = never, E = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E
|
||||
): E
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F
|
||||
): F
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G
|
||||
): G
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H
|
||||
): H
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I
|
||||
): I
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J
|
||||
): J
|
||||
pipe<A, B = never, C = never, D = never, E = never, F = never, G = never, H = never, I = never, J = never, K = never>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K
|
||||
): K
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L
|
||||
): L
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M
|
||||
): M
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N
|
||||
): N
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O
|
||||
): O
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P
|
||||
): P
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q
|
||||
): Q
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never,
|
||||
R = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q,
|
||||
qr: (_: Q) => R
|
||||
): R
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never,
|
||||
R = never,
|
||||
S = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q,
|
||||
qr: (_: Q) => R,
|
||||
rs: (_: R) => S
|
||||
): S
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never,
|
||||
R = never,
|
||||
S = never,
|
||||
T = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q,
|
||||
qr: (_: Q) => R,
|
||||
rs: (_: R) => S,
|
||||
st: (_: S) => T
|
||||
): T
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never,
|
||||
R = never,
|
||||
S = never,
|
||||
T = never,
|
||||
U = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q,
|
||||
qr: (_: Q) => R,
|
||||
rs: (_: R) => S,
|
||||
st: (_: S) => T,
|
||||
tu: (_: T) => U
|
||||
): U
|
||||
pipe<
|
||||
A,
|
||||
B = never,
|
||||
C = never,
|
||||
D = never,
|
||||
E = never,
|
||||
F = never,
|
||||
G = never,
|
||||
H = never,
|
||||
I = never,
|
||||
J = never,
|
||||
K = never,
|
||||
L = never,
|
||||
M = never,
|
||||
N = never,
|
||||
O = never,
|
||||
P = never,
|
||||
Q = never,
|
||||
R = never,
|
||||
S = never,
|
||||
T = never,
|
||||
U = never
|
||||
>(
|
||||
this: A,
|
||||
ab: (_: A) => B,
|
||||
bc: (_: B) => C,
|
||||
cd: (_: C) => D,
|
||||
de: (_: D) => E,
|
||||
ef: (_: E) => F,
|
||||
fg: (_: F) => G,
|
||||
gh: (_: G) => H,
|
||||
hi: (_: H) => I,
|
||||
ij: (_: I) => J,
|
||||
jk: (_: J) => K,
|
||||
kl: (_: K) => L,
|
||||
lm: (_: L) => M,
|
||||
mn: (_: M) => N,
|
||||
no: (_: N) => O,
|
||||
op: (_: O) => P,
|
||||
pq: (_: P) => Q,
|
||||
qr: (_: Q) => R,
|
||||
rs: (_: R) => S,
|
||||
st: (_: S) => T,
|
||||
tu: (_: T) => U
|
||||
): U
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export const pipeArguments = <A>(self: A, args: IArguments): unknown => {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
return self
|
||||
case 1:
|
||||
return args[0](self)
|
||||
case 2:
|
||||
return args[1](args[0](self))
|
||||
case 3:
|
||||
return args[2](args[1](args[0](self)))
|
||||
case 4:
|
||||
return args[3](args[2](args[1](args[0](self))))
|
||||
case 5:
|
||||
return args[4](args[3](args[2](args[1](args[0](self)))))
|
||||
case 6:
|
||||
return args[5](args[4](args[3](args[2](args[1](args[0](self))))))
|
||||
case 7:
|
||||
return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))
|
||||
case 8:
|
||||
return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))))
|
||||
case 9:
|
||||
return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))))
|
||||
default: {
|
||||
let ret = self
|
||||
for (let i = 0, len = args.length; i < len; i++) {
|
||||
ret = args[i](ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.15.0
|
||||
* @category Models
|
||||
*/
|
||||
export interface PipeableConstructor {
|
||||
new(...args: Array<any>): Pipeable
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.15.0
|
||||
* @category Prototypes
|
||||
*/
|
||||
export const Prototype: Pipeable = {
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
const Base: PipeableConstructor = (function() {
|
||||
function PipeableBase() {}
|
||||
PipeableBase.prototype = Prototype
|
||||
return PipeableBase as any
|
||||
})()
|
||||
|
||||
/**
|
||||
* @since 3.15.0
|
||||
* @category Constructors
|
||||
*/
|
||||
export const Class: {
|
||||
/**
|
||||
* @since 3.15.0
|
||||
* @category Constructors
|
||||
*/
|
||||
(): PipeableConstructor
|
||||
/**
|
||||
* @since 3.15.0
|
||||
* @category Constructors
|
||||
*/
|
||||
<TBase extends Ctor>(klass: TBase): TBase & PipeableConstructor
|
||||
} = (klass?: Ctor) =>
|
||||
klass ?
|
||||
class extends klass {
|
||||
pipe() {
|
||||
return pipeArguments(this, arguments)
|
||||
}
|
||||
}
|
||||
: Base
|
||||
220
_node_modules/effect/src/Pool.ts
generated
Normal file
220
_node_modules/effect/src/Pool.ts
generated
Normal file
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Duration from "./Duration.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/pool.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const PoolTypeId: unique symbol = internal.PoolTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type PoolTypeId = typeof PoolTypeId
|
||||
|
||||
/**
|
||||
* A `Pool<A, E>` is a pool of items of type `A`, each of which may be
|
||||
* associated with the acquisition and release of resources. An attempt to get
|
||||
* an item `A` from a pool may fail with an error of type `E`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Pool<in out A, out E = never> extends Pool.Variance<A, E>, Effect.Effect<A, E, Scope.Scope>, Pipeable {
|
||||
/**
|
||||
* Retrieves an item from the pool in a scoped effect. Note that if
|
||||
* acquisition fails, then the returned effect will fail for that same reason.
|
||||
* Retrying a failed acquisition attempt will repeat the acquisition attempt.
|
||||
*/
|
||||
readonly get: Effect.Effect<A, E, Scope.Scope>
|
||||
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*/
|
||||
invalidate(item: A): Effect.Effect<void>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: PoolUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: PoolUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.9.0
|
||||
*/
|
||||
export interface PoolUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
Pool?: () => Extract<A[Unify.typeSymbol], Pool<any, any>> extends Pool<infer A0, infer _E0> | infer _ ?
|
||||
A0 extends any ? Extract<A[Unify.typeSymbol], Pool<A0, any>> extends Pool<A0, infer E1> ? Pool<A0, E1>
|
||||
: never
|
||||
: never :
|
||||
never
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.9.0
|
||||
*/
|
||||
export interface PoolUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Pool {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Variance<in out A, out E> {
|
||||
readonly [PoolTypeId]: {
|
||||
readonly _A: Types.Invariant<A>
|
||||
readonly _E: Types.Covariant<E>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Pool`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isPool: (u: unknown) => u is Pool<unknown, unknown> = internal.isPool
|
||||
|
||||
/**
|
||||
* Makes a new pool of the specified fixed size. The pool is returned in a
|
||||
* `Scope`, which governs the lifetime of the pool. When the pool is shutdown
|
||||
* because the `Scope` is closed, the individual items allocated by the pool
|
||||
* will be released in some unspecified order.
|
||||
*
|
||||
* By setting the `concurrency` parameter, you can control the level of concurrent
|
||||
* access per pool item. By default, the number of permits is set to `1`.
|
||||
*
|
||||
* `targetUtilization` determines when to create new pool items. It is a value
|
||||
* between 0 and 1, where 1 means only create new pool items when all the existing
|
||||
* items are fully utilized.
|
||||
*
|
||||
* A `targetUtilization` of 0.5 will create new pool items when the existing items are
|
||||
* 50% utilized.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <A, E, R>(
|
||||
options: {
|
||||
readonly acquire: Effect.Effect<A, E, R>
|
||||
readonly size: number
|
||||
readonly concurrency?: number | undefined
|
||||
readonly targetUtilization?: number | undefined
|
||||
}
|
||||
) => Effect.Effect<Pool<A, E>, never, Scope.Scope | R> = internal.make
|
||||
|
||||
/**
|
||||
* Makes a new pool with the specified minimum and maximum sizes and time to
|
||||
* live before a pool whose excess items are not being used will be shrunk
|
||||
* down to the minimum size. The pool is returned in a `Scope`, which governs
|
||||
* the lifetime of the pool. When the pool is shutdown because the `Scope` is
|
||||
* used, the individual items allocated by the pool will be released in some
|
||||
* unspecified order.
|
||||
*
|
||||
* By setting the `concurrency` parameter, you can control the level of concurrent
|
||||
* access per pool item. By default, the number of permits is set to `1`.
|
||||
*
|
||||
* `targetUtilization` determines when to create new pool items. It is a value
|
||||
* between 0 and 1, where 1 means only create new pool items when all the existing
|
||||
* items are fully utilized.
|
||||
*
|
||||
* A `targetUtilization` of 0.5 will create new pool items when the existing items are
|
||||
* 50% utilized.
|
||||
*
|
||||
* The `timeToLiveStrategy` determines how items are invalidated. If set to
|
||||
* "creation", then items are invalidated based on their creation time. If set
|
||||
* to "usage", then items are invalidated based on pool usage.
|
||||
*
|
||||
* By default, the `timeToLiveStrategy` is set to "usage".
|
||||
*
|
||||
* ```ts skip-type-checking
|
||||
* import { createConnection } from "mysql2";
|
||||
* import { Duration, Effect, Pool } from "effect"
|
||||
*
|
||||
* const acquireDBConnection = Effect.acquireRelease(
|
||||
* Effect.sync(() => createConnection('mysql://...')),
|
||||
* (connection) => Effect.sync(() => connection.end(() => {})),
|
||||
* )
|
||||
*
|
||||
* const connectionPool = Effect.flatMap(
|
||||
* Pool.makeWithTTL({
|
||||
* acquire: acquireDBConnection,
|
||||
* min: 10,
|
||||
* max: 20,
|
||||
* timeToLive: Duration.seconds(60)
|
||||
* }),
|
||||
* (pool) => pool.get
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const makeWithTTL: <A, E, R>(
|
||||
options: {
|
||||
readonly acquire: Effect.Effect<A, E, R>
|
||||
readonly min: number
|
||||
readonly max: number
|
||||
readonly concurrency?: number | undefined
|
||||
readonly targetUtilization?: number | undefined
|
||||
readonly timeToLive: Duration.DurationInput
|
||||
readonly timeToLiveStrategy?: "creation" | "usage" | undefined
|
||||
}
|
||||
) => Effect.Effect<Pool<A, E>, never, Scope.Scope | R> = internal.makeWithTTL
|
||||
|
||||
/**
|
||||
* Retrieves an item from the pool in a scoped effect. Note that if
|
||||
* acquisition fails, then the returned effect will fail for that same reason.
|
||||
* Retrying a failed acquisition attempt will repeat the acquisition attempt.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const get: <A, E>(self: Pool<A, E>) => Effect.Effect<A, E, Scope.Scope> = internal.get
|
||||
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const invalidate: {
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<A>(value: A): <E>(self: Pool<A, E>) => Effect.Effect<void, never, Scope.Scope>
|
||||
/**
|
||||
* Invalidates the specified item. This will cause the pool to eventually
|
||||
* reallocate the item, although this reallocation may occur lazily rather
|
||||
* than eagerly.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
<A, E>(self: Pool<A, E>, value: A): Effect.Effect<void, never, Scope.Scope>
|
||||
} = internal.invalidate
|
||||
2344
_node_modules/effect/src/Predicate.ts
generated
Normal file
2344
_node_modules/effect/src/Predicate.ts
generated
Normal file
File diff suppressed because it is too large
Load Diff
204
_node_modules/effect/src/Pretty.ts
generated
Normal file
204
_node_modules/effect/src/Pretty.ts
generated
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* @since 3.10.0
|
||||
*/
|
||||
import * as Arr from "./Array.js"
|
||||
import * as errors_ from "./internal/schema/errors.js"
|
||||
import * as util_ from "./internal/schema/util.js"
|
||||
import * as Option from "./Option.js"
|
||||
import * as ParseResult from "./ParseResult.js"
|
||||
import type * as Schema from "./Schema.js"
|
||||
import * as AST from "./SchemaAST.js"
|
||||
|
||||
/**
|
||||
* @category model
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export interface Pretty<To> {
|
||||
(a: To): string
|
||||
}
|
||||
|
||||
/**
|
||||
* @category annotations
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export type PrettyAnnotation<A, TypeParameters extends ReadonlyArray<any> = readonly []> = (
|
||||
...pretties: { readonly [K in keyof TypeParameters]: Pretty<TypeParameters[K]> }
|
||||
) => Pretty<A>
|
||||
|
||||
/**
|
||||
* @category prettify
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export const make = <A, I, R>(schema: Schema.Schema<A, I, R>): (a: A) => string => compile(schema.ast, [])
|
||||
|
||||
const getPrettyAnnotation = AST.getAnnotation<PrettyAnnotation<any, any>>(AST.PrettyAnnotationId)
|
||||
|
||||
const getMatcher = (defaultPretty: Pretty<any>) => (ast: AST.AST): Pretty<any> =>
|
||||
Option.match(getPrettyAnnotation(ast), {
|
||||
onNone: () => defaultPretty,
|
||||
onSome: (handler) => handler()
|
||||
})
|
||||
|
||||
const toString = getMatcher((a) => String(a))
|
||||
|
||||
const stringify = getMatcher((a) => JSON.stringify(a))
|
||||
|
||||
const formatUnknown = getMatcher(util_.formatUnknown)
|
||||
|
||||
/**
|
||||
* @since 3.10.0
|
||||
*/
|
||||
export const match: AST.Match<Pretty<any>> = {
|
||||
"Declaration": (ast, go, path) => {
|
||||
const annotation = getPrettyAnnotation(ast)
|
||||
if (Option.isSome(annotation)) {
|
||||
return annotation.value(...ast.typeParameters.map((tp) => go(tp, path)))
|
||||
}
|
||||
throw new Error(errors_.getPrettyMissingAnnotationErrorMessage(path, ast))
|
||||
},
|
||||
"VoidKeyword": getMatcher(() => "void(0)"),
|
||||
"NeverKeyword": getMatcher(() => {
|
||||
throw new Error(errors_.getPrettyNeverErrorMessage)
|
||||
}),
|
||||
"Literal": getMatcher((literal: AST.LiteralValue): string =>
|
||||
typeof literal === "bigint" ?
|
||||
`${String(literal)}n` :
|
||||
JSON.stringify(literal)
|
||||
),
|
||||
"SymbolKeyword": toString,
|
||||
"UniqueSymbol": toString,
|
||||
"TemplateLiteral": stringify,
|
||||
"UndefinedKeyword": toString,
|
||||
"UnknownKeyword": formatUnknown,
|
||||
"AnyKeyword": formatUnknown,
|
||||
"ObjectKeyword": formatUnknown,
|
||||
"StringKeyword": stringify,
|
||||
"NumberKeyword": toString,
|
||||
"BooleanKeyword": toString,
|
||||
"BigIntKeyword": getMatcher((a) => `${String(a)}n`),
|
||||
"Enums": stringify,
|
||||
"TupleType": (ast, go, path) => {
|
||||
const hook = getPrettyAnnotation(ast)
|
||||
if (Option.isSome(hook)) {
|
||||
return hook.value()
|
||||
}
|
||||
const elements = ast.elements.map((e, i) => go(e.type, path.concat(i)))
|
||||
const rest = ast.rest.map((annotatedAST) => go(annotatedAST.type, path))
|
||||
return (input: ReadonlyArray<unknown>) => {
|
||||
const output: Array<string> = []
|
||||
let i = 0
|
||||
// ---------------------------------------------
|
||||
// handle elements
|
||||
// ---------------------------------------------
|
||||
for (; i < elements.length; i++) {
|
||||
if (input.length < i + 1) {
|
||||
if (ast.elements[i].isOptional) {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
output.push(elements[i](input[i]))
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle rest element
|
||||
// ---------------------------------------------
|
||||
if (Arr.isNonEmptyReadonlyArray(rest)) {
|
||||
const [head, ...tail] = rest
|
||||
for (; i < input.length - tail.length; i++) {
|
||||
output.push(head(input[i]))
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle post rest elements
|
||||
// ---------------------------------------------
|
||||
for (let j = 0; j < tail.length; j++) {
|
||||
i += j
|
||||
output.push(tail[j](input[i]))
|
||||
}
|
||||
}
|
||||
|
||||
return "[" + output.join(", ") + "]"
|
||||
}
|
||||
},
|
||||
"TypeLiteral": (ast, go, path) => {
|
||||
const hook = getPrettyAnnotation(ast)
|
||||
if (Option.isSome(hook)) {
|
||||
return hook.value()
|
||||
}
|
||||
const propertySignaturesTypes = ast.propertySignatures.map((ps) => go(ps.type, path.concat(ps.name)))
|
||||
const indexSignatureTypes = ast.indexSignatures.map((is) => go(is.type, path))
|
||||
const expectedKeys: any = {}
|
||||
for (let i = 0; i < propertySignaturesTypes.length; i++) {
|
||||
expectedKeys[ast.propertySignatures[i].name] = null
|
||||
}
|
||||
return (input: { readonly [x: PropertyKey]: unknown }) => {
|
||||
const output: Array<string> = []
|
||||
// ---------------------------------------------
|
||||
// handle property signatures
|
||||
// ---------------------------------------------
|
||||
for (let i = 0; i < propertySignaturesTypes.length; i++) {
|
||||
const ps = ast.propertySignatures[i]
|
||||
const name = ps.name
|
||||
if (ps.isOptional && !Object.prototype.hasOwnProperty.call(input, name)) {
|
||||
continue
|
||||
}
|
||||
output.push(
|
||||
`${util_.formatPropertyKey(name)}: ${propertySignaturesTypes[i](input[name])}`
|
||||
)
|
||||
}
|
||||
// ---------------------------------------------
|
||||
// handle index signatures
|
||||
// ---------------------------------------------
|
||||
if (indexSignatureTypes.length > 0) {
|
||||
for (let i = 0; i < indexSignatureTypes.length; i++) {
|
||||
const type = indexSignatureTypes[i]
|
||||
const keys = util_.getKeysForIndexSignature(input, ast.indexSignatures[i].parameter)
|
||||
for (const key of keys) {
|
||||
if (Object.prototype.hasOwnProperty.call(expectedKeys, key)) {
|
||||
continue
|
||||
}
|
||||
output.push(`${util_.formatPropertyKey(key)}: ${type(input[key])}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Arr.isNonEmptyReadonlyArray(output) ? "{ " + output.join(", ") + " }" : "{}"
|
||||
}
|
||||
},
|
||||
"Union": (ast, go, path) => {
|
||||
const hook = getPrettyAnnotation(ast)
|
||||
if (Option.isSome(hook)) {
|
||||
return hook.value()
|
||||
}
|
||||
const types = ast.types.map((ast) => [ParseResult.is({ ast } as any), go(ast, path)] as const)
|
||||
return (a) => {
|
||||
const index = types.findIndex(([is]) => is(a))
|
||||
if (index === -1) {
|
||||
throw new Error(errors_.getPrettyNoMatchingSchemaErrorMessage(a, path, ast))
|
||||
}
|
||||
return types[index][1](a)
|
||||
}
|
||||
},
|
||||
"Suspend": (ast, go, path) => {
|
||||
return Option.match(getPrettyAnnotation(ast), {
|
||||
onNone: () => {
|
||||
const get = util_.memoizeThunk(() => go(ast.f(), path))
|
||||
return (a) => get()(a)
|
||||
},
|
||||
onSome: (handler) => handler()
|
||||
})
|
||||
},
|
||||
"Refinement": (ast, go, path) => {
|
||||
return Option.match(getPrettyAnnotation(ast), {
|
||||
onNone: () => go(ast.from, path),
|
||||
onSome: (handler) => handler()
|
||||
})
|
||||
},
|
||||
"Transformation": (ast, go, path) => {
|
||||
return Option.match(getPrettyAnnotation(ast), {
|
||||
onNone: () => go(ast.to, path),
|
||||
onSome: (handler) => handler()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const compile = AST.getCompiler(match)
|
||||
23
_node_modules/effect/src/PrimaryKey.ts
generated
Normal file
23
_node_modules/effect/src/PrimaryKey.ts
generated
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const symbol: unique symbol = Symbol.for("effect/PrimaryKey")
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface PrimaryKey {
|
||||
[symbol](): string
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category accessors
|
||||
*/
|
||||
export const value = (self: PrimaryKey): string => self[symbol]()
|
||||
210
_node_modules/effect/src/PubSub.ts
generated
Normal file
210
_node_modules/effect/src/PubSub.ts
generated
Normal file
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/pubsub.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Queue from "./Queue.js"
|
||||
import type * as Scope from "./Scope.js"
|
||||
|
||||
/**
|
||||
* A `PubSub<A>` is an asynchronous message hub into which publishers can publish
|
||||
* messages of type `A` and subscribers can subscribe to take messages of type
|
||||
* `A`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface PubSub<in out A> extends Queue.Enqueue<A>, Pipeable {
|
||||
/**
|
||||
* Publishes a message to the `PubSub`, returning whether the message was published
|
||||
* to the `PubSub`.
|
||||
*/
|
||||
publish(value: A): Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Publishes all of the specified messages to the `PubSub`, returning whether they
|
||||
* were published to the `PubSub`.
|
||||
*/
|
||||
publishAll(elements: Iterable<A>): Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Subscribes to receive messages from the `PubSub`. The resulting subscription can
|
||||
* be evaluated multiple times within the scope to take a message from the `PubSub`
|
||||
* each time.
|
||||
*/
|
||||
readonly subscribe: Effect.Effect<Queue.Dequeue<A>, never, Scope.Scope>
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a bounded `PubSub` with the back pressure strategy. The `PubSub` will retain
|
||||
* messages until they have been taken by all subscribers, applying back
|
||||
* pressure to publishers if the `PubSub` is at capacity.
|
||||
*
|
||||
* For best performance use capacities that are powers of two.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const bounded: <A>(
|
||||
capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
|
||||
) => Effect.Effect<PubSub<A>> = internal.bounded
|
||||
|
||||
/**
|
||||
* Creates a bounded `PubSub` with the dropping strategy. The `PubSub` will drop new
|
||||
* messages if the `PubSub` is at capacity.
|
||||
*
|
||||
* For best performance use capacities that are powers of two.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const dropping: <A>(
|
||||
capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
|
||||
) => Effect.Effect<PubSub<A>> = internal.dropping
|
||||
|
||||
/**
|
||||
* Creates a bounded `PubSub` with the sliding strategy. The `PubSub` will add new
|
||||
* messages and drop old messages if the `PubSub` is at capacity.
|
||||
*
|
||||
* For best performance use capacities that are powers of two.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sliding: <A>(
|
||||
capacity: number | { readonly capacity: number; readonly replay?: number | undefined }
|
||||
) => Effect.Effect<PubSub<A>> = internal.sliding
|
||||
|
||||
/**
|
||||
* Creates an unbounded `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unbounded: <A>(options?: { readonly replay?: number | undefined }) => Effect.Effect<PubSub<A>> =
|
||||
internal.unbounded
|
||||
|
||||
/**
|
||||
* Returns the number of elements the queue can hold.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const capacity: <A>(self: PubSub<A>) => number = internal.capacity
|
||||
|
||||
/**
|
||||
* Retrieves the size of the queue, which is equal to the number of elements
|
||||
* in the queue. This may be negative if fibers are suspended waiting for
|
||||
* elements to be added to the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const size: <A>(self: PubSub<A>) => Effect.Effect<number> = internal.size
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains at least one element, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isFull: <A>(self: PubSub<A>) => Effect.Effect<boolean> = internal.isFull
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains zero elements, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isEmpty: <A>(self: PubSub<A>) => Effect.Effect<boolean> = internal.isEmpty
|
||||
|
||||
/**
|
||||
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
|
||||
* to `offer*` and `take*` will be interrupted immediately.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const shutdown: <A>(self: PubSub<A>) => Effect.Effect<void> = internal.shutdown
|
||||
|
||||
/**
|
||||
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isShutdown: <A>(self: PubSub<A>) => Effect.Effect<boolean> = internal.isShutdown
|
||||
|
||||
/**
|
||||
* Waits until the queue is shutdown. The `Effect` returned by this method will
|
||||
* not resume until the queue has been shutdown. If the queue is already
|
||||
* shutdown, the `Effect` will resume right away.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const awaitShutdown: <A>(self: PubSub<A>) => Effect.Effect<void> = internal.awaitShutdown
|
||||
|
||||
/**
|
||||
* Publishes a message to the `PubSub`, returning whether the message was published
|
||||
* to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const publish: {
|
||||
/**
|
||||
* Publishes a message to the `PubSub`, returning whether the message was published
|
||||
* to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): (self: PubSub<A>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Publishes a message to the `PubSub`, returning whether the message was published
|
||||
* to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: PubSub<A>, value: A): Effect.Effect<boolean>
|
||||
} = internal.publish
|
||||
|
||||
/**
|
||||
* Publishes all of the specified messages to the `PubSub`, returning whether they
|
||||
* were published to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const publishAll: {
|
||||
/**
|
||||
* Publishes all of the specified messages to the `PubSub`, returning whether they
|
||||
* were published to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(elements: Iterable<A>): (self: PubSub<A>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Publishes all of the specified messages to the `PubSub`, returning whether they
|
||||
* were published to the `PubSub`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: PubSub<A>, elements: Iterable<A>): Effect.Effect<boolean>
|
||||
} = internal.publishAll
|
||||
|
||||
/**
|
||||
* Subscribes to receive messages from the `PubSub`. The resulting subscription can
|
||||
* be evaluated multiple times within the scope to take a message from the `PubSub`
|
||||
* each time.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const subscribe: <A>(self: PubSub<A>) => Effect.Effect<Queue.Dequeue<A>, never, Scope.Scope> = internal.subscribe
|
||||
748
_node_modules/effect/src/Queue.ts
generated
Normal file
748
_node_modules/effect/src/Queue.ts
generated
Normal file
@@ -0,0 +1,748 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Chunk from "./Chunk.js"
|
||||
import type * as Deferred from "./Deferred.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as internal from "./internal/queue.js"
|
||||
import type * as MutableQueue from "./MutableQueue.js"
|
||||
import type * as MutableRef from "./MutableRef.js"
|
||||
import type * as Option from "./Option.js"
|
||||
import type { Pipeable } from "./Pipeable.js"
|
||||
import type * as Types from "./Types.js"
|
||||
import type * as Unify from "./Unify.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const EnqueueTypeId: unique symbol = internal.EnqueueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type EnqueueTypeId = typeof EnqueueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const DequeueTypeId: unique symbol = internal.DequeueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type DequeueTypeId = typeof DequeueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const QueueStrategyTypeId: unique symbol = internal.QueueStrategyTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type QueueStrategyTypeId = typeof QueueStrategyTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const BackingQueueTypeId: unique symbol = internal.BackingQueueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type BackingQueueTypeId = typeof BackingQueueTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Queue<in out A> extends Enqueue<A>, Dequeue<A> {
|
||||
/** @internal */
|
||||
readonly queue: BackingQueue<A>
|
||||
/** @internal */
|
||||
readonly takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
||||
/** @internal */
|
||||
readonly shutdownHook: Deferred.Deferred<void>
|
||||
/** @internal */
|
||||
readonly shutdownFlag: MutableRef.MutableRef<boolean>
|
||||
/** @internal */
|
||||
readonly strategy: Strategy<A>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: QueueUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: QueueUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface QueueUnify<A extends { [Unify.typeSymbol]?: any }> extends DequeueUnify<A> {
|
||||
Queue?: () => Extract<A[Unify.typeSymbol], Queue<any>>
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface QueueUnifyIgnore extends DequeueUnifyIgnore {
|
||||
Dequeue?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Enqueue<in A> extends Queue.EnqueueVariance<A>, BaseQueue, Pipeable {
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*/
|
||||
offer(value: A): Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Places one value in the queue when possible without needing the fiber runtime.
|
||||
*/
|
||||
unsafeOffer(value: A): boolean
|
||||
|
||||
/**
|
||||
* For Bounded Queue: uses the `BackPressure` Strategy, places the values in
|
||||
* the queue and always returns true. If the queue has reached capacity, then
|
||||
* the fiber performing the `offerAll` will be suspended until there is room
|
||||
* in the queue.
|
||||
*
|
||||
* For Unbounded Queue: Places all values in the queue and returns true.
|
||||
*
|
||||
* For Sliding Queue: uses `Sliding` Strategy If there is room in the queue,
|
||||
* it places the values otherwise it removes the old elements and enqueues the
|
||||
* new ones. Always returns true.
|
||||
*
|
||||
* For Dropping Queue: uses `Dropping` Strategy, It places the values in the
|
||||
* queue but if there is no room it will not enqueue them and return false.
|
||||
*/
|
||||
offerAll(iterable: Iterable<A>): Effect.Effect<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Dequeue<out A> extends Effect.Effect<A>, Queue.DequeueVariance<A>, BaseQueue {
|
||||
/**
|
||||
* Takes the oldest value in the queue. If the queue is empty, this will return
|
||||
* a computation that resumes when an item has been added to the queue.
|
||||
*/
|
||||
readonly take: Effect.Effect<A>
|
||||
|
||||
/**
|
||||
* Takes all the values in the queue and returns the values. If the queue is
|
||||
* empty returns an empty collection.
|
||||
*/
|
||||
readonly takeAll: Effect.Effect<Chunk.Chunk<A>>
|
||||
|
||||
/**
|
||||
* Takes up to max number of values from the queue.
|
||||
*/
|
||||
takeUpTo(max: number): Effect.Effect<Chunk.Chunk<A>>
|
||||
|
||||
/**
|
||||
* Takes a number of elements from the queue between the specified minimum and
|
||||
* maximum. If there are fewer than the minimum number of elements available,
|
||||
* suspends until at least the minimum number of elements have been collected.
|
||||
*/
|
||||
takeBetween(min: number, max: number): Effect.Effect<Chunk.Chunk<A>>
|
||||
|
||||
readonly [Unify.typeSymbol]?: unknown
|
||||
readonly [Unify.unifySymbol]?: DequeueUnify<this>
|
||||
readonly [Unify.ignoreSymbol]?: DequeueUnifyIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface DequeueUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
||||
Dequeue?: () => A[Unify.typeSymbol] extends Dequeue<infer A0> | infer _ ? Dequeue<A0> : never
|
||||
}
|
||||
|
||||
/**
|
||||
* @category models
|
||||
* @since 3.8.0
|
||||
*/
|
||||
export interface DequeueUnifyIgnore extends Effect.EffectUnifyIgnore {
|
||||
Effect?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* The base interface that all `Queue`s must implement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BaseQueue {
|
||||
/**
|
||||
* Returns the number of elements the queue can hold.
|
||||
*/
|
||||
capacity(): number
|
||||
|
||||
/**
|
||||
* Returns false if shutdown has been called.
|
||||
*/
|
||||
isActive(): boolean
|
||||
|
||||
/**
|
||||
* Retrieves the size of the queue, which is equal to the number of elements
|
||||
* in the queue. This may be negative if fibers are suspended waiting for
|
||||
* elements to be added to the queue.
|
||||
*/
|
||||
readonly size: Effect.Effect<number>
|
||||
|
||||
/**
|
||||
* Retrieves the size of the queue, which is equal to the number of elements
|
||||
* in the queue. This may be negative if fibers are suspended waiting for
|
||||
* elements to be added to the queue. Returns None if shutdown has been called
|
||||
*/
|
||||
unsafeSize(): Option.Option<number>
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains at least one element, `false`
|
||||
* otherwise.
|
||||
*/
|
||||
readonly isFull: Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains zero elements, `false` otherwise.
|
||||
*/
|
||||
readonly isEmpty: Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
|
||||
* to `offer*` and `take*` will be interrupted immediately.
|
||||
*/
|
||||
readonly shutdown: Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
|
||||
*/
|
||||
readonly isShutdown: Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* Waits until the queue is shutdown. The `Effect` returned by this method will
|
||||
* not resume until the queue has been shutdown. If the queue is already
|
||||
* shutdown, the `Effect` will resume right away.
|
||||
*/
|
||||
readonly awaitShutdown: Effect.Effect<void>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Strategy<in out A> extends Queue.StrategyVariance<A> {
|
||||
/**
|
||||
* Returns the number of surplus values that were unable to be added to the
|
||||
* `Queue`
|
||||
*/
|
||||
surplusSize(): number
|
||||
|
||||
/**
|
||||
* Determines how the `Queue.Strategy` should shut down when the `Queue` is
|
||||
* shut down.
|
||||
*/
|
||||
readonly shutdown: Effect.Effect<void>
|
||||
|
||||
/**
|
||||
* Determines the behavior of the `Queue.Strategy` when there are surplus
|
||||
* values that could not be added to the `Queue` following an `offer`
|
||||
* operation.
|
||||
*/
|
||||
handleSurplus(
|
||||
iterable: Iterable<A>,
|
||||
queue: BackingQueue<A>,
|
||||
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
||||
isShutdown: MutableRef.MutableRef<boolean>
|
||||
): Effect.Effect<boolean>
|
||||
|
||||
/**
|
||||
* It is called when the backing queue is empty but there are some
|
||||
* takers that can be completed
|
||||
*/
|
||||
onCompleteTakersWithEmptyQueue(
|
||||
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
||||
): void
|
||||
|
||||
/**
|
||||
* Determines the behavior of the `Queue.Strategy` when the `Queue` has empty
|
||||
* slots following a `take` operation.
|
||||
*/
|
||||
unsafeOnQueueEmptySpace(
|
||||
queue: BackingQueue<A>,
|
||||
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
||||
): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BackingQueue<in out A> extends Queue.BackingQueueVariance<A> {
|
||||
/**
|
||||
* Dequeues an element from the queue.
|
||||
* Returns either an element from the queue, or the `def` param.
|
||||
*/
|
||||
poll<Def>(def: Def): A | Def
|
||||
/**
|
||||
* Dequeues up to `limit` elements from the queue.
|
||||
*/
|
||||
pollUpTo(limit: number): Chunk.Chunk<A>
|
||||
/**
|
||||
* Enqueues a collection of values into the queue.
|
||||
*
|
||||
* Returns a `Chunk` of the values that were **not** able to be enqueued.
|
||||
*/
|
||||
offerAll(elements: Iterable<A>): Chunk.Chunk<A>
|
||||
/**
|
||||
* Offers an element to the queue.
|
||||
*
|
||||
* Returns whether the enqueue was successful or not.
|
||||
*/
|
||||
offer(element: A): boolean
|
||||
/**
|
||||
* The **maximum** number of elements that a queue can hold.
|
||||
*
|
||||
* **Note**: unbounded queues can still implement this interface with
|
||||
* `capacity = Infinity`.
|
||||
*/
|
||||
capacity(): number
|
||||
/**
|
||||
* Returns the number of elements currently in the queue
|
||||
*/
|
||||
length(): number
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace Queue {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface EnqueueVariance<in A> {
|
||||
readonly [EnqueueTypeId]: {
|
||||
readonly _In: Types.Contravariant<A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface DequeueVariance<out A> {
|
||||
readonly [DequeueTypeId]: {
|
||||
readonly _Out: Types.Covariant<A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface StrategyVariance<in out A> {
|
||||
readonly [QueueStrategyTypeId]: {
|
||||
readonly _A: Types.Invariant<A>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface BackingQueueVariance<in out A> {
|
||||
readonly [BackingQueueTypeId]: {
|
||||
readonly _A: Types.Invariant<A>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Queue`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isQueue: (u: unknown) => u is Queue<unknown> = internal.isQueue
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Dequeue`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isDequeue: (u: unknown) => u is Dequeue<unknown> = internal.isDequeue
|
||||
|
||||
/**
|
||||
* Returns `true` if the specified value is a `Enqueue`, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category refinements
|
||||
*/
|
||||
export const isEnqueue: (u: unknown) => u is Enqueue<unknown> = internal.isEnqueue
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category strategies
|
||||
*/
|
||||
export const backPressureStrategy: <A>() => Strategy<A> = internal.backPressureStrategy
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category strategies
|
||||
*/
|
||||
export const droppingStrategy: <A>() => Strategy<A> = internal.droppingStrategy
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category strategies
|
||||
*/
|
||||
export const slidingStrategy: <A>() => Strategy<A> = internal.slidingStrategy
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <A>(queue: BackingQueue<A>, strategy: Strategy<A>) => Effect.Effect<Queue<A>> = internal.make
|
||||
|
||||
/**
|
||||
* Makes a new bounded `Queue`. When the capacity of the queue is reached, any
|
||||
* additional calls to `offer` will be suspended until there is more room in
|
||||
* the queue.
|
||||
*
|
||||
* **Note**: When possible use only power of 2 capacities; this will provide
|
||||
* better performance by utilising an optimised version of the underlying
|
||||
* `RingBuffer`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const bounded: <A>(requestedCapacity: number) => Effect.Effect<Queue<A>> = internal.bounded
|
||||
|
||||
/**
|
||||
* Makes a new bounded `Queue` with the dropping strategy.
|
||||
*
|
||||
* When the capacity of the queue is reached, new elements will be dropped and the
|
||||
* old elements will remain.
|
||||
*
|
||||
* **Note**: When possible use only power of 2 capacities; this will provide
|
||||
* better performance by utilising an optimised version of the underlying
|
||||
* `RingBuffer`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const dropping: <A>(requestedCapacity: number) => Effect.Effect<Queue<A>> = internal.dropping
|
||||
|
||||
/**
|
||||
* Makes a new bounded `Queue` with the sliding strategy.
|
||||
*
|
||||
* When the capacity of the queue is reached, new elements will be added and the
|
||||
* old elements will be dropped.
|
||||
*
|
||||
* **Note**: When possible use only power of 2 capacities; this will provide
|
||||
* better performance by utilising an optimised version of the underlying
|
||||
* `RingBuffer`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const sliding: <A>(requestedCapacity: number) => Effect.Effect<Queue<A>> = internal.sliding
|
||||
|
||||
/**
|
||||
* Creates a new unbounded `Queue`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const unbounded: <A>() => Effect.Effect<Queue<A>> = internal.unbounded
|
||||
|
||||
/**
|
||||
* Returns the number of elements the queue can hold.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const capacity: <A>(self: Dequeue<A> | Enqueue<A>) => number = internal.capacity
|
||||
|
||||
/**
|
||||
* Retrieves the size of the queue, which is equal to the number of elements
|
||||
* in the queue. This may be negative if fibers are suspended waiting for
|
||||
* elements to be added to the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const size: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<number> = internal.size
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains zero elements, `false` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isEmpty: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<boolean> = internal.isEmpty
|
||||
|
||||
/**
|
||||
* Returns `true` if the `Queue` contains at least one element, `false`
|
||||
* otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isFull: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<boolean> = internal.isFull
|
||||
|
||||
/**
|
||||
* Returns `true` if `shutdown` has been called, otherwise returns `false`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category getters
|
||||
*/
|
||||
export const isShutdown: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<boolean> = internal.isShutdown
|
||||
|
||||
/**
|
||||
* Waits until the queue is shutdown. The `Effect` returned by this method will
|
||||
* not resume until the queue has been shutdown. If the queue is already
|
||||
* shutdown, the `Effect` will resume right away.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const awaitShutdown: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<void> = internal.awaitShutdown
|
||||
|
||||
/**
|
||||
* Interrupts any fibers that are suspended on `offer` or `take`. Future calls
|
||||
* to `offer*` and `take*` will be interrupted immediately.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const shutdown: <A>(self: Dequeue<A> | Enqueue<A>) => Effect.Effect<void> = internal.shutdown
|
||||
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const offer: {
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): (self: Enqueue<A>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Enqueue<A>, value: A): Effect.Effect<boolean>
|
||||
} = internal.offer
|
||||
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const unsafeOffer: {
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(value: A): (self: Enqueue<A>) => boolean
|
||||
/**
|
||||
* Places one value in the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Enqueue<A>, value: A): boolean
|
||||
} = internal.unsafeOffer
|
||||
|
||||
/**
|
||||
* For Bounded Queue: uses the `BackPressure` Strategy, places the values in
|
||||
* the queue and always returns true. If the queue has reached capacity, then
|
||||
* the fiber performing the `offerAll` will be suspended until there is room
|
||||
* in the queue.
|
||||
*
|
||||
* For Unbounded Queue: Places all values in the queue and returns true.
|
||||
*
|
||||
* For Sliding Queue: uses `Sliding` Strategy If there is room in the queue,
|
||||
* it places the values otherwise it removes the old elements and enqueues the
|
||||
* new ones. Always returns true.
|
||||
*
|
||||
* For Dropping Queue: uses `Dropping` Strategy, It places the values in the
|
||||
* queue but if there is no room it will not enqueue them and return false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const offerAll: {
|
||||
/**
|
||||
* For Bounded Queue: uses the `BackPressure` Strategy, places the values in
|
||||
* the queue and always returns true. If the queue has reached capacity, then
|
||||
* the fiber performing the `offerAll` will be suspended until there is room
|
||||
* in the queue.
|
||||
*
|
||||
* For Unbounded Queue: Places all values in the queue and returns true.
|
||||
*
|
||||
* For Sliding Queue: uses `Sliding` Strategy If there is room in the queue,
|
||||
* it places the values otherwise it removes the old elements and enqueues the
|
||||
* new ones. Always returns true.
|
||||
*
|
||||
* For Dropping Queue: uses `Dropping` Strategy, It places the values in the
|
||||
* queue but if there is no room it will not enqueue them and return false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(iterable: Iterable<A>): (self: Enqueue<A>) => Effect.Effect<boolean>
|
||||
/**
|
||||
* For Bounded Queue: uses the `BackPressure` Strategy, places the values in
|
||||
* the queue and always returns true. If the queue has reached capacity, then
|
||||
* the fiber performing the `offerAll` will be suspended until there is room
|
||||
* in the queue.
|
||||
*
|
||||
* For Unbounded Queue: Places all values in the queue and returns true.
|
||||
*
|
||||
* For Sliding Queue: uses `Sliding` Strategy If there is room in the queue,
|
||||
* it places the values otherwise it removes the old elements and enqueues the
|
||||
* new ones. Always returns true.
|
||||
*
|
||||
* For Dropping Queue: uses `Dropping` Strategy, It places the values in the
|
||||
* queue but if there is no room it will not enqueue them and return false.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Enqueue<A>, iterable: Iterable<A>): Effect.Effect<boolean>
|
||||
} = internal.offerAll
|
||||
|
||||
/**
|
||||
* Returns the first value in the `Queue` as a `Some<A>`, or `None` if the queue
|
||||
* is empty.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const poll: <A>(self: Dequeue<A>) => Effect.Effect<Option.Option<A>> = internal.poll
|
||||
|
||||
/**
|
||||
* Takes the oldest value in the queue. If the queue is empty, this will return
|
||||
* a computation that resumes when an item has been added to the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const take: <A>(self: Dequeue<A>) => Effect.Effect<A> = internal.take
|
||||
|
||||
/**
|
||||
* Takes all the values in the queue and returns the values. If the queue is
|
||||
* empty returns an empty collection.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const takeAll: <A>(self: Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>> = internal.takeAll
|
||||
|
||||
/**
|
||||
* Takes up to max number of values from the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const takeUpTo: {
|
||||
/**
|
||||
* Takes up to max number of values from the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(max: number): <A>(self: Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>
|
||||
/**
|
||||
* Takes up to max number of values from the queue.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Dequeue<A>, max: number): Effect.Effect<Chunk.Chunk<A>>
|
||||
} = internal.takeUpTo
|
||||
|
||||
/**
|
||||
* Takes a number of elements from the queue between the specified minimum and
|
||||
* maximum. If there are fewer than the minimum number of elements available,
|
||||
* suspends until at least the minimum number of elements have been collected.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const takeBetween: {
|
||||
/**
|
||||
* Takes a number of elements from the queue between the specified minimum and
|
||||
* maximum. If there are fewer than the minimum number of elements available,
|
||||
* suspends until at least the minimum number of elements have been collected.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(min: number, max: number): <A>(self: Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>
|
||||
/**
|
||||
* Takes a number of elements from the queue between the specified minimum and
|
||||
* maximum. If there are fewer than the minimum number of elements available,
|
||||
* suspends until at least the minimum number of elements have been collected.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Dequeue<A>, min: number, max: number): Effect.Effect<Chunk.Chunk<A>>
|
||||
} = internal.takeBetween
|
||||
|
||||
/**
|
||||
* Takes the specified number of elements from the queue. If there are fewer
|
||||
* than the specified number of elements available, it suspends until they
|
||||
* become available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
export const takeN: {
|
||||
/**
|
||||
* Takes the specified number of elements from the queue. If there are fewer
|
||||
* than the specified number of elements available, it suspends until they
|
||||
* become available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
(n: number): <A>(self: Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>
|
||||
/**
|
||||
* Takes the specified number of elements from the queue. If there are fewer
|
||||
* than the specified number of elements available, it suspends until they
|
||||
* become available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category utils
|
||||
*/
|
||||
<A>(self: Dequeue<A>, n: number): Effect.Effect<Chunk.Chunk<A>>
|
||||
} = internal.takeN
|
||||
204
_node_modules/effect/src/Random.ts
generated
Normal file
204
_node_modules/effect/src/Random.ts
generated
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type * as Array from "./Array.js"
|
||||
import type * as Cause from "./Cause.js"
|
||||
import type * as Chunk from "./Chunk.js"
|
||||
import type * as Context from "./Context.js"
|
||||
import type * as Effect from "./Effect.js"
|
||||
import * as defaultServices from "./internal/defaultServices.js"
|
||||
import * as internal from "./internal/random.js"
|
||||
import type * as NonEmptyIterable from "./NonEmptyIterable.js"
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export const RandomTypeId: unique symbol = internal.RandomTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category symbols
|
||||
*/
|
||||
export type RandomTypeId = typeof RandomTypeId
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Random {
|
||||
readonly [RandomTypeId]: RandomTypeId
|
||||
/**
|
||||
* Returns the next numeric value from the pseudo-random number generator.
|
||||
*/
|
||||
readonly next: Effect.Effect<number>
|
||||
/**
|
||||
* Returns the next boolean value from the pseudo-random number generator.
|
||||
*/
|
||||
readonly nextBoolean: Effect.Effect<boolean>
|
||||
/**
|
||||
* Returns the next integer value from the pseudo-random number generator.
|
||||
*/
|
||||
readonly nextInt: Effect.Effect<number>
|
||||
/**
|
||||
* Returns the next numeric value in the specified range from the
|
||||
* pseudo-random number generator.
|
||||
*/
|
||||
nextRange(min: number, max: number): Effect.Effect<number>
|
||||
/**
|
||||
* Returns the next integer value in the specified range from the
|
||||
* pseudo-random number generator.
|
||||
*/
|
||||
nextIntBetween(min: number, max: number): Effect.Effect<number>
|
||||
/**
|
||||
* Uses the pseudo-random number generator to shuffle the specified iterable.
|
||||
*/
|
||||
shuffle<A>(elements: Iterable<A>): Effect.Effect<Chunk.Chunk<A>>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next numeric value from the pseudo-random number generator.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const next: Effect.Effect<number> = defaultServices.next
|
||||
|
||||
/**
|
||||
* Returns the next integer value from the pseudo-random number generator.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nextInt: Effect.Effect<number> = defaultServices.nextInt
|
||||
|
||||
/**
|
||||
* Returns the next boolean value from the pseudo-random number generator.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nextBoolean: Effect.Effect<boolean> = defaultServices.nextBoolean
|
||||
|
||||
/**
|
||||
* Returns the next numeric value in the specified range from the
|
||||
* pseudo-random number generator.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nextRange: (min: number, max: number) => Effect.Effect<number> = defaultServices.nextRange
|
||||
|
||||
/**
|
||||
* Returns the next integer value in the specified range from the
|
||||
* pseudo-random number generator.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const nextIntBetween: (min: number, max: number) => Effect.Effect<number> = defaultServices.nextIntBetween
|
||||
|
||||
/**
|
||||
* Uses the pseudo-random number generator to shuffle the specified iterable.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const shuffle: <A>(elements: Iterable<A>) => Effect.Effect<Chunk.Chunk<A>> = defaultServices.shuffle
|
||||
|
||||
/**
|
||||
* Get a random element from an iterable.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Random } from "effect"
|
||||
*
|
||||
* Effect.gen(function* () {
|
||||
* const randomItem = yield* Random.choice([1, 2, 3])
|
||||
* console.log(randomItem)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const choice: <Self extends Iterable<unknown>>(
|
||||
elements: Self
|
||||
) => Self extends NonEmptyIterable.NonEmptyIterable<infer A> ? Effect.Effect<A>
|
||||
: Self extends Array.NonEmptyReadonlyArray<infer A> ? Effect.Effect<A>
|
||||
: Self extends Iterable<infer A> ? Effect.Effect<A, Cause.NoSuchElementException>
|
||||
: never = defaultServices.choice
|
||||
|
||||
/**
|
||||
* Retreives the `Random` service from the context and uses it to run the
|
||||
* specified workflow.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const randomWith: <A, E, R>(f: (random: Random) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> =
|
||||
defaultServices.randomWith
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category context
|
||||
*/
|
||||
export const Random: Context.Tag<Random, Random> = internal.randomTag
|
||||
|
||||
/**
|
||||
* Constructs the `Random` service, seeding the pseudo-random number generator
|
||||
* with an hash of the specified seed.
|
||||
* This constructor is useful for generating predictable sequences of random values for specific use cases.
|
||||
*
|
||||
* Example uses:
|
||||
* - Generating random UI data for visual tests.
|
||||
* - Creating data that needs to change daily but remain the same throughout a single day, such as using a date as the seed.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import * as assert from "node:assert"
|
||||
* import { Effect, Random } from "effect"
|
||||
*
|
||||
* const random1 = Random.make("myseed")
|
||||
* const random2 = Random.make("myseed")
|
||||
*
|
||||
* assert.equal(Effect.runSync(random1.next), Effect.runSync(random2.next))
|
||||
* ```
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: <A>(seed: A) => Random = internal.make
|
||||
|
||||
/**
|
||||
* Constructs the `Random` service from an array of literal values.
|
||||
* The service will cycle through the provided values in order when generating random values.
|
||||
* This constructor is useful for creating deterministic sequences for testing or when specific values need to be returned.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Random } from "effect"
|
||||
*
|
||||
* Effect.gen(function* () {
|
||||
* console.log(yield* Random.next) // 0.2
|
||||
* console.log(yield* Random.next) // 0.5
|
||||
* console.log(yield* Random.next) // 0.8
|
||||
* console.log(yield* Random.next) // 0.2 (cycles back)
|
||||
* }).pipe(Effect.withRandom(Random.fixed([0.2, 0.5, 0.8])))
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, Random } from "effect"
|
||||
*
|
||||
* Effect.gen(function* () {
|
||||
* console.log(yield* Random.nextBoolean) // true
|
||||
* console.log(yield* Random.nextBoolean) // false
|
||||
* console.log(yield* Random.nextBoolean) // true
|
||||
* }).pipe(Effect.withRandom(Random.fixed([true, false, true])))
|
||||
* ```
|
||||
*
|
||||
* @since 3.11.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const fixed: <const T extends Array.NonEmptyArray<any>>(values: T) => Random = internal.fixed
|
||||
138
_node_modules/effect/src/RateLimiter.ts
generated
Normal file
138
_node_modules/effect/src/RateLimiter.ts
generated
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Limits the number of calls to a resource to a maximum amount in some interval.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
import type { DurationInput } from "./Duration.js"
|
||||
import type { Effect } from "./Effect.js"
|
||||
import * as internal from "./internal/rateLimiter.js"
|
||||
import type { Scope } from "./Scope.js"
|
||||
|
||||
/**
|
||||
* Limits the number of calls to a resource to a maximum amount in some interval.
|
||||
*
|
||||
* Note that only the moment of starting the effect is rate limited: the number
|
||||
* of concurrent executions is not bounded.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface RateLimiter {
|
||||
<A, E, R>(task: Effect<A, E, R>): Effect<A, E, R>
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
export declare namespace RateLimiter {
|
||||
/**
|
||||
* @since 2.0.0
|
||||
* @category models
|
||||
*/
|
||||
export interface Options {
|
||||
/**
|
||||
* The maximum number of requests that should be allowed.
|
||||
*/
|
||||
readonly limit: number
|
||||
/**
|
||||
* The interval to utilize for rate-limiting requests. The semantics of the
|
||||
* specified `interval` vary depending on the chosen `algorithm`:
|
||||
*
|
||||
* `token-bucket`: The maximum number of requests will be spread out over
|
||||
* the provided interval if no tokens are available.
|
||||
*
|
||||
* For example, for a `RateLimiter` using the `token-bucket` algorithm with
|
||||
* a `limit` of `10` and an `interval` of `1 seconds`, `1` request can be
|
||||
* made every `100 millis`.
|
||||
*
|
||||
* `fixed-window`: The maximum number of requests will be reset during each
|
||||
* interval. For example, for a `RateLimiter` using the `fixed-window`
|
||||
* algorithm with a `limit` of `10` and an `interval` of `1 seconds`, a
|
||||
* maximum of `10` requests can be made each second.
|
||||
*/
|
||||
readonly interval: DurationInput
|
||||
/**
|
||||
* The algorithm to utilize for rate-limiting requests.
|
||||
*
|
||||
* Defaults to `token-bucket`.
|
||||
*/
|
||||
readonly algorithm?: "fixed-window" | "token-bucket"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new `RateLimiter` which will utilize the specified algorithm
|
||||
* to limit requests (defaults to `token-bucket`).
|
||||
*
|
||||
* Notes
|
||||
* - Only the moment of starting the effect is rate limited. The number of concurrent executions is not bounded.
|
||||
* - Instances of `RateLimiter` can be composed.
|
||||
* - The "cost" per effect can be changed. See {@link withCost}
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, RateLimiter } from "effect";
|
||||
* import { compose } from "effect/Function"
|
||||
*
|
||||
* const program = Effect.scoped(
|
||||
* Effect.gen(function* ($) {
|
||||
* const perMinuteRL = yield* $(RateLimiter.make({ limit: 30, interval: "1 minutes" }))
|
||||
* const perSecondRL = yield* $(RateLimiter.make({ limit: 2, interval: "1 seconds" }))
|
||||
*
|
||||
* // This rate limiter respects both the 30 calls per minute
|
||||
* // and the 2 calls per second constraints.
|
||||
* const rateLimit = compose(perMinuteRL, perSecondRL)
|
||||
*
|
||||
* // simulate repeated calls
|
||||
* for (let n = 0; n < 100; n++) {
|
||||
* // wrap the effect we want to limit with rateLimit
|
||||
* yield* $(rateLimit(Effect.log("Calling RateLimited Effect")));
|
||||
* }
|
||||
* })
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category constructors
|
||||
*/
|
||||
export const make: (options: RateLimiter.Options) => Effect<RateLimiter, never, Scope> = internal.make
|
||||
|
||||
/**
|
||||
* Alters the per-effect cost of the rate-limiter.
|
||||
*
|
||||
* This can be used for "credit" based rate-limiting where different API endpoints
|
||||
* cost a different number of credits within a time window.
|
||||
* Eg: 1000 credits / hour, where a query costs 1 credit and a mutation costs 5 credits.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Effect, RateLimiter } from "effect";
|
||||
* import { compose } from "effect/Function";
|
||||
*
|
||||
* const program = Effect.scoped(
|
||||
* Effect.gen(function* ($) {
|
||||
* // Create a rate limiter that has an hourly limit of 1000 credits
|
||||
* const rateLimiter = yield* $(RateLimiter.make({ limit: 1000, interval: "1 hours" }));
|
||||
* // Query API costs 1 credit per call ( 1 is the default cost )
|
||||
* const queryAPIRL = compose(rateLimiter, RateLimiter.withCost(1));
|
||||
* // Mutation API costs 5 credits per call
|
||||
* const mutationAPIRL = compose(rateLimiter, RateLimiter.withCost(5));
|
||||
|
||||
* // Use the pre-defined rate limiters
|
||||
* yield* $(queryAPIRL(Effect.log("Sample Query")));
|
||||
* yield* $(mutationAPIRL(Effect.log("Sample Mutation")));
|
||||
*
|
||||
* // Or set a cost on-the-fly
|
||||
* yield* $(
|
||||
* rateLimiter(Effect.log("Another query with a different cost")).pipe(
|
||||
* RateLimiter.withCost(3)
|
||||
* )
|
||||
* );
|
||||
* })
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @category combinators
|
||||
*/
|
||||
export const withCost: (cost: number) => <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R> = internal.withCost
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user