effect-app 1.32.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/_cjs/Array.cjs +132 -0
- package/_cjs/Array.cjs.map +1 -0
- package/_cjs/Chunk.cjs +128 -0
- package/_cjs/Chunk.cjs.map +1 -0
- package/_cjs/Config/SecretURL.cjs +3 -3
- package/_cjs/Config/SecretURL.cjs.map +1 -1
- package/_cjs/Config/internal/configSecretURL.cjs +2 -2
- package/_cjs/Config/internal/configSecretURL.cjs.map +1 -1
- package/_cjs/Context.cjs +243 -0
- package/_cjs/Context.cjs.map +1 -0
- package/_cjs/Dictionary.cjs +522 -0
- package/_cjs/Dictionary.cjs.map +1 -0
- package/_cjs/Effect.cjs +202 -0
- package/_cjs/Effect.cjs.map +1 -0
- package/_cjs/Function.cjs +107 -0
- package/_cjs/Function.cjs.map +1 -0
- package/_cjs/NonEmptySet.cjs +26 -0
- package/_cjs/NonEmptySet.cjs.map +1 -0
- package/_cjs/NonEmptySetAspects.cjs +17 -0
- package/_cjs/NonEmptySetAspects.cjs.map +1 -0
- package/_cjs/NonEmptySetBase.cjs +82 -0
- package/_cjs/NonEmptySetBase.cjs.map +1 -0
- package/_cjs/Object.cjs +24 -0
- package/_cjs/Object.cjs.map +1 -0
- package/_cjs/Operations.cjs +1 -1
- package/_cjs/Option.cjs +88 -0
- package/_cjs/Option.cjs.map +1 -0
- package/_cjs/Prelude.cjs +53 -0
- package/_cjs/Prelude.cjs.map +1 -0
- package/_cjs/Prelude.code.cjs +53 -0
- package/_cjs/Prelude.code.cjs.map +1 -0
- package/_cjs/Pure.cjs +39 -36
- package/_cjs/Pure.cjs.map +1 -1
- package/_cjs/Schema/Class.cjs +61 -0
- package/_cjs/Schema/Class.cjs.map +1 -0
- package/_cjs/Schema/FastCheck.cjs +39 -0
- package/_cjs/Schema/FastCheck.cjs.map +1 -0
- package/_cjs/Schema/Methods.cjs +6 -0
- package/_cjs/Schema/Methods.cjs.map +1 -0
- package/_cjs/Schema/brand.cjs +17 -0
- package/_cjs/Schema/brand.cjs.map +1 -0
- package/_cjs/Schema/email.cjs +20 -0
- package/_cjs/Schema/email.cjs.map +1 -0
- package/_cjs/Schema/ext.cjs +174 -0
- package/_cjs/Schema/ext.cjs.map +1 -0
- package/_cjs/Schema/moreStrings.cjs +124 -0
- package/_cjs/Schema/moreStrings.cjs.map +1 -0
- package/_cjs/Schema/numbers.cjs +52 -0
- package/_cjs/Schema/numbers.cjs.map +1 -0
- package/_cjs/Schema/phoneNumber.cjs +22 -0
- package/_cjs/Schema/phoneNumber.cjs.map +1 -0
- package/_cjs/Schema/schema.cjs +15 -0
- package/_cjs/Schema/schema.cjs.map +1 -0
- package/_cjs/Schema/strings.cjs +32 -0
- package/_cjs/Schema/strings.cjs.map +1 -0
- package/_cjs/Schema.cjs +334 -0
- package/_cjs/Schema.cjs.map +1 -0
- package/_cjs/Set.cjs +567 -0
- package/_cjs/Set.cjs.map +1 -0
- package/_cjs/Struct.cjs +51 -0
- package/_cjs/Struct.cjs.map +1 -0
- package/_cjs/Tag.cjs +25 -0
- package/_cjs/Tag.cjs.map +1 -0
- package/_cjs/Unify.cjs +40 -0
- package/_cjs/Unify.cjs.map +1 -0
- package/_cjs/_ext/misc.cjs +16 -16
- package/_cjs/_ext/misc.cjs.map +1 -1
- package/_cjs/_ext/ord.ext.cjs +52 -0
- package/_cjs/_ext/ord.ext.cjs.map +1 -0
- package/_cjs/builtin.cjs +6 -0
- package/_cjs/builtin.cjs.map +1 -0
- package/_cjs/client/clientFor.cjs +5 -3
- package/_cjs/client/clientFor.cjs.map +1 -1
- package/_cjs/client/config.cjs +4 -4
- package/_cjs/client/config.cjs.map +1 -1
- package/_cjs/client/errors.cjs +9 -9
- package/_cjs/client/errors.cjs.map +1 -1
- package/_cjs/http/http-client.cjs +35 -0
- package/_cjs/http/http-client.cjs.map +1 -0
- package/_cjs/ids.cjs +5 -5
- package/_cjs/ids.cjs.map +1 -1
- package/_cjs/index.cjs +1 -1
- package/_cjs/lib.cjs +178 -9
- package/_cjs/lib.cjs.map +1 -1
- package/_cjs/logger.cjs +1 -1
- package/_cjs/transform.cjs +45 -0
- package/_cjs/transform.cjs.map +1 -0
- package/_cjs/utils/effectify.cjs +25 -0
- package/_cjs/utils/effectify.cjs.map +1 -0
- package/_cjs/utils/extend.cjs +17 -0
- package/_cjs/utils/extend.cjs.map +1 -0
- package/_cjs/utils/logger.cjs +23 -0
- package/_cjs/utils/logger.cjs.map +1 -0
- package/_cjs/utils.cjs +431 -4
- package/_cjs/utils.cjs.map +1 -1
- package/_cjs/validation/validators.cjs +32 -0
- package/_cjs/validation/validators.cjs.map +1 -0
- package/_cjs/validation.cjs +45 -0
- package/_cjs/validation.cjs.map +1 -0
- package/dist/Array.d.ts +64 -0
- package/dist/Array.d.ts.map +1 -0
- package/dist/Array.js +89 -0
- package/dist/Chunk.d.ts +68 -0
- package/dist/Chunk.d.ts.map +1 -0
- package/dist/Chunk.js +93 -0
- package/dist/Config/SecretURL.d.ts +3 -3
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -2
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Context.d.ts +55 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +204 -0
- package/dist/Dictionary.d.ts +260 -0
- package/dist/Dictionary.d.ts.map +1 -0
- package/dist/Dictionary.js +448 -0
- package/dist/Effect.d.ts +115 -0
- package/dist/Effect.d.ts.map +1 -0
- package/dist/Effect.js +153 -0
- package/dist/Function.d.ts +72 -0
- package/dist/Function.d.ts.map +1 -0
- package/dist/Function.js +71 -0
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Inputify.type.d.ts.map +1 -1
- package/dist/NonEmptySet.d.ts +3 -0
- package/dist/NonEmptySet.d.ts.map +1 -0
- package/dist/NonEmptySet.js +3 -0
- package/dist/NonEmptySetAspects.d.ts +2 -0
- package/dist/NonEmptySetAspects.d.ts.map +1 -0
- package/dist/NonEmptySetAspects.js +2 -0
- package/dist/NonEmptySetBase.d.ts +39 -0
- package/dist/NonEmptySetBase.d.ts.map +1 -0
- package/dist/NonEmptySetBase.js +63 -0
- package/dist/Object.d.ts +7 -0
- package/dist/Object.d.ts.map +1 -0
- package/dist/Object.js +7 -0
- package/dist/Operations.d.ts +2 -2
- package/dist/Operations.js +1 -1
- package/dist/Option.d.ts +39 -0
- package/dist/Option.d.ts.map +1 -0
- package/dist/Option.js +55 -0
- package/dist/Prelude.code.d.ts +25 -0
- package/dist/Prelude.code.d.ts.map +1 -0
- package/dist/Prelude.code.js +24 -0
- package/dist/Prelude.d.ts +163 -0
- package/dist/Prelude.d.ts.map +1 -0
- package/dist/Prelude.js +24 -0
- package/dist/Pure.d.ts +13 -12
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +18 -17
- package/dist/Schema/Class.d.ts +45 -0
- package/dist/Schema/Class.d.ts.map +1 -0
- package/dist/Schema/Class.js +50 -0
- package/dist/Schema/FastCheck.d.ts +10 -0
- package/dist/Schema/FastCheck.d.ts.map +1 -0
- package/dist/Schema/FastCheck.js +12 -0
- package/dist/Schema/Methods.d.ts +6 -0
- package/dist/Schema/Methods.d.ts.map +1 -0
- package/dist/Schema/Methods.js +2 -0
- package/dist/Schema/brand.d.ts +35 -0
- package/dist/Schema/brand.d.ts.map +1 -0
- package/dist/Schema/brand.js +7 -0
- package/dist/Schema/email.d.ts +9 -0
- package/dist/Schema/email.d.ts.map +1 -0
- package/dist/Schema/email.js +12 -0
- package/dist/Schema/ext.d.ts +89 -0
- package/dist/Schema/ext.d.ts.map +1 -0
- package/dist/Schema/ext.js +111 -0
- package/dist/Schema/moreStrings.d.ts +109 -0
- package/dist/Schema/moreStrings.d.ts.map +1 -0
- package/dist/Schema/moreStrings.js +108 -0
- package/dist/Schema/numbers.d.ts +46 -0
- package/dist/Schema/numbers.d.ts.map +1 -0
- package/dist/Schema/numbers.js +28 -0
- package/dist/Schema/phoneNumber.d.ts +9 -0
- package/dist/Schema/phoneNumber.d.ts.map +1 -0
- package/dist/Schema/phoneNumber.js +14 -0
- package/dist/Schema/schema.d.ts +6 -0
- package/dist/Schema/schema.d.ts.map +1 -0
- package/dist/Schema/schema.js +5 -0
- package/dist/Schema/strings.d.ts +19 -0
- package/dist/Schema/strings.d.ts.map +1 -0
- package/dist/Schema/strings.js +32 -0
- package/dist/{schema.d.ts → Schema.d.ts} +25 -9
- package/dist/Schema.d.ts.map +1 -0
- package/dist/Schema.js +89 -0
- package/dist/Set.d.ts +221 -0
- package/dist/Set.d.ts.map +1 -0
- package/dist/Set.js +516 -0
- package/dist/Struct.d.ts +44 -0
- package/dist/Struct.d.ts.map +1 -0
- package/dist/Struct.js +29 -0
- package/dist/Tag.d.ts +9 -0
- package/dist/Tag.d.ts.map +1 -0
- package/dist/Tag.js +18 -0
- package/dist/Unify.d.ts +43 -0
- package/dist/Unify.d.ts.map +1 -0
- package/dist/Unify.js +31 -0
- package/dist/Widen.type.d.ts +1 -1
- package/dist/Widen.type.d.ts.map +1 -1
- package/dist/_ext/misc.d.ts +11 -11
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +8 -8
- package/dist/_ext/ord.ext.d.ts +23 -0
- package/dist/_ext/ord.ext.d.ts.map +1 -0
- package/dist/_ext/ord.ext.js +44 -0
- package/dist/builtin.d.ts +51 -0
- package/dist/builtin.d.ts.map +1 -0
- package/dist/builtin.js +2 -0
- package/dist/client/clientFor.d.ts +1 -1
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +2 -2
- package/dist/client/config.d.ts +1 -1
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js +2 -2
- package/dist/client/errors.js +1 -1
- package/dist/http/http-client.d.ts +43 -0
- package/dist/http/http-client.d.ts.map +1 -0
- package/dist/http/http-client.js +30 -0
- package/dist/ids.d.ts +3 -3
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib.d.ts +22 -4
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +20 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +2 -2
- package/dist/transform.d.ts +12 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +39 -0
- package/dist/utils/effectify.d.ts +210 -0
- package/dist/utils/effectify.d.ts.map +1 -0
- package/dist/utils/effectify.js +19 -0
- package/dist/utils/extend.d.ts +3 -0
- package/dist/utils/extend.d.ts.map +1 -0
- package/dist/utils/extend.js +9 -0
- package/dist/utils/logger.d.ts +12 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +15 -0
- package/dist/utils.d.ts +192 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +332 -2
- package/dist/validation/validators.d.ts +11 -0
- package/dist/validation/validators.d.ts.map +1 -0
- package/dist/validation/validators.js +26 -0
- package/dist/validation.d.ts +13 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +14 -0
- package/package.json +360 -9
- package/src/Array.ts +127 -0
- package/src/Chunk.ts +112 -0
- package/src/Config/SecretURL.ts +3 -3
- package/src/Config/internal/configSecretURL.ts +1 -1
- package/src/Context.ts +293 -0
- package/src/Dictionary.ts +669 -0
- package/src/Effect.ts +265 -0
- package/src/Function.ts +175 -0
- package/src/Inputify.type.ts +1 -1
- package/src/NonEmptySet.ts +3 -0
- package/src/NonEmptySetAspects.ts +1 -0
- package/src/NonEmptySetBase.ts +109 -0
- package/src/Object.ts +19 -0
- package/src/Operations.ts +1 -1
- package/src/Option.ts +82 -0
- package/src/Prelude.code.ts +27 -0
- package/src/Prelude.ts +220 -0
- package/src/Pure.ts +37 -30
- package/src/Schema/Class.ts +225 -0
- package/src/Schema/FastCheck.ts +23 -0
- package/src/Schema/Methods.ts +8 -0
- package/src/Schema/brand.ts +50 -0
- package/src/Schema/email.ts +22 -0
- package/src/Schema/ext.ts +273 -0
- package/src/Schema/moreStrings.ts +260 -0
- package/src/Schema/numbers.ts +83 -0
- package/src/Schema/phoneNumber.ts +24 -0
- package/src/Schema/schema.ts +6 -0
- package/src/Schema/strings.ts +60 -0
- package/src/{schema.ts → Schema.ts} +52 -20
- package/src/Set.ts +674 -0
- package/src/Struct.ts +54 -0
- package/src/Tag.ts +20 -0
- package/src/Unify.ts +56 -0
- package/src/Widen.type.ts +1 -1
- package/src/_ext/misc.ts +22 -22
- package/src/_ext/ord.ext.ts +49 -0
- package/src/builtin.ts +64 -0
- package/src/client/clientFor.ts +1 -1
- package/src/client/config.ts +1 -1
- package/src/client/errors.ts +1 -1
- package/src/http/http-client.ts +73 -0
- package/src/ids.ts +3 -3
- package/src/index.ts +1 -1
- package/src/lib.ts +88 -4
- package/src/logger.ts +1 -1
- package/src/transform.ts +80 -0
- package/src/utils/effectify.ts +259 -0
- package/src/utils/extend.ts +9 -0
- package/src/utils/logger.ts +24 -0
- package/src/utils.ts +805 -1
- package/src/validation/validators.ts +32 -0
- package/src/validation.ts +18 -0
- package/tsconfig.src.json +1 -5
- package/_cjs/schema.cjs +0 -110
- package/_cjs/schema.cjs.map +0 -1
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -73
package/src/Chunk.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { pipe, type Predicate, type Refinement } from "./Function.js"
|
|
2
|
+
import * as Option from "./Option.js"
|
|
3
|
+
|
|
4
|
+
import * as Chunk from "effect/Chunk"
|
|
5
|
+
import * as Array from "./Array.js"
|
|
6
|
+
import type { Equivalence } from "./index.js"
|
|
7
|
+
|
|
8
|
+
export * from "effect/Chunk"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @tsplus getter Array toChunk
|
|
12
|
+
* @tsplus getter ReadonlyArray toChunk
|
|
13
|
+
* @tsplus getter Iterable toChunk
|
|
14
|
+
* @tsplus getter Iterator toChunk
|
|
15
|
+
* @tsplus getter Generator toChunk
|
|
16
|
+
*/
|
|
17
|
+
export const fromIterable = Chunk.fromIterable
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @tsplus fluent effect/data/Chunk groupByT
|
|
21
|
+
*/
|
|
22
|
+
export function groupByTChunk_<A, Key extends PropertyKey>(c: Chunk.Chunk<A>, f: (a: A) => Key) {
|
|
23
|
+
return pipe(Chunk.toReadonlyArray(c), Array.groupByT(f), Chunk.fromIterable)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the first element that satisfies the predicate.
|
|
28
|
+
*
|
|
29
|
+
* @tsplus static effect/data/Chunk.Ops findFirstMap
|
|
30
|
+
* @tsplus pipeable effect/data/Chunk findFirstMap
|
|
31
|
+
*/
|
|
32
|
+
export function findFirstMap<A, B>(
|
|
33
|
+
f: (a: A) => Option.Option<B>
|
|
34
|
+
) {
|
|
35
|
+
return (as: Chunk.Chunk<A>) => {
|
|
36
|
+
const ass = Chunk.toReadonlyArray(as)
|
|
37
|
+
const len = ass.length
|
|
38
|
+
for (let i = 0; i < len; i++) {
|
|
39
|
+
const v = f(ass[i]!)
|
|
40
|
+
if (Option.isSome(v)) {
|
|
41
|
+
return v
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Option.none()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @tsplus getter effect/data/Chunk toArray
|
|
50
|
+
*/
|
|
51
|
+
export function toArray<T>(c: Chunk.Chunk<T>): T[] {
|
|
52
|
+
return Chunk.toReadonlyArray(c) as T[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Remove duplicates from an array, keeping the first occurrence of an element.
|
|
57
|
+
*
|
|
58
|
+
* @tsplus static effect/data/Chunk.Ops uniq
|
|
59
|
+
* @tsplus pipeable effect/data/Chunk uniq
|
|
60
|
+
*/
|
|
61
|
+
export function uniq<A>(E: Equivalence<A>) {
|
|
62
|
+
return (self: Chunk.Chunk<A>): Chunk.Chunk<A> => {
|
|
63
|
+
let out = Chunk.fromIterable([] as A[])
|
|
64
|
+
for (let i = 0; i < self.length; i++) {
|
|
65
|
+
const a = Chunk.unsafeGet(self, i)
|
|
66
|
+
if (!elem(E, a)(out)) {
|
|
67
|
+
out = Chunk.append(out, a)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return self.length === out.length ? self : out
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Test if a value is a member of an array. Takes a `Equivalence<A>` as a single
|
|
76
|
+
* argument which returns the function to use to search for a value of type `A`
|
|
77
|
+
* in an array of type `Chunk<A>`.
|
|
78
|
+
*
|
|
79
|
+
* @tsplus static effect/data/Chunk.Ops elem2
|
|
80
|
+
* @tsplus pipeable effect/data/Chunk elem2
|
|
81
|
+
*/
|
|
82
|
+
export function elem<A>(E: Equivalence<A>, value: A) {
|
|
83
|
+
return (self: Chunk.Chunk<A>): boolean => {
|
|
84
|
+
for (let i = 0; i < self.length; i++) {
|
|
85
|
+
if (E(Chunk.unsafeGet(self, i), value)) {
|
|
86
|
+
return true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @tsplus pipeable effect/data/Chunk partition
|
|
95
|
+
*/
|
|
96
|
+
export const ChunkPartition = Chunk.partition
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @tsplus fluent effect/data/Chunk findFirst
|
|
100
|
+
*/
|
|
101
|
+
export const findFirstSimple: {
|
|
102
|
+
<A, B extends A>(self: Chunk.Chunk<A>, refinement: Refinement<A, B>): Option.Option<B>
|
|
103
|
+
<A>(self: Chunk.Chunk<A>, predicate: Predicate<A>): Option.Option<A>
|
|
104
|
+
} = Chunk.findFirst
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @tsplus fluent effect/data/Chunk findLast
|
|
108
|
+
*/
|
|
109
|
+
export const findLastSimple: {
|
|
110
|
+
<A, B extends A>(self: Chunk.Chunk<A>, refinement: Refinement<A, B>): Option.Option<B>
|
|
111
|
+
<A>(self: Chunk.Chunk<A>, predicate: Predicate<A>): Option.Option<A>
|
|
112
|
+
} = Chunk.findLast
|
package/src/Config/SecretURL.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import type { Equal, Redacted } from "
|
|
5
|
-
import { Config } from "
|
|
4
|
+
import type { Equal, Redacted } from "effect"
|
|
5
|
+
import { Config } from "effect"
|
|
6
6
|
import type * as Chunk from "effect/Chunk"
|
|
7
7
|
import * as Either from "effect/Either"
|
|
8
8
|
import type { SecretTypeId } from "effect/Secret"
|
|
@@ -97,7 +97,7 @@ export const unsafeWipe: (self: SecretURL) => void = internal.unsafeWipe
|
|
|
97
97
|
/**
|
|
98
98
|
* @tsplus static effect/io/Config.Ops secretURL
|
|
99
99
|
*/
|
|
100
|
-
export const secretURL = (name?: string): Config<SecretURL> => {
|
|
100
|
+
export const secretURL = (name?: string): Config.Config<SecretURL> => {
|
|
101
101
|
const config = Config.primitive(
|
|
102
102
|
"a secret property",
|
|
103
103
|
(text) => Either.right(fromString(text))
|
package/src/Context.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/**
|
|
3
|
+
* We're doing the long way around here with assignTag, TagBase & TagBaseTagged,
|
|
4
|
+
* because there's a typescript compiler issue where it will complain about Equal.symbol, and Hash.symbol not being accessible.
|
|
5
|
+
* https://github.com/microsoft/TypeScript/issues/52644
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Scope } from "effect"
|
|
9
|
+
import { Effect, Layer } from "effect"
|
|
10
|
+
import * as Context from "effect/Context"
|
|
11
|
+
|
|
12
|
+
export * from "effect/Context"
|
|
13
|
+
|
|
14
|
+
export const ServiceTag = Symbol()
|
|
15
|
+
export type ServiceTag = typeof ServiceTag
|
|
16
|
+
|
|
17
|
+
export abstract class PhantomTypeParameter<Identifier extends keyof any, InstantiatedType> {
|
|
18
|
+
protected abstract readonly [ServiceTag]: {
|
|
19
|
+
readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ServiceShape<T extends Context.TagClassShape<any, any>> = Omit<
|
|
24
|
+
T,
|
|
25
|
+
keyof Context.TagClassShape<any, any>
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @tsplus type ServiceTagged
|
|
30
|
+
*/
|
|
31
|
+
export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @tsplus static ServiceTagged make
|
|
35
|
+
*/
|
|
36
|
+
export function makeService<T extends ServiceTagged<any>>(_: Omit<T, ServiceTag>) {
|
|
37
|
+
return _ as T
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let i = 0
|
|
41
|
+
const randomId = () => "unknown-service-" + i++
|
|
42
|
+
|
|
43
|
+
export function assignTag<Id, Service = Id>(key?: string, creationError?: Error) {
|
|
44
|
+
return <S extends object>(cls: S): S & Context.Tag<Id, Service> => {
|
|
45
|
+
const tag = Context.GenericTag<Id, Service>(key ?? randomId())
|
|
46
|
+
let fields = tag
|
|
47
|
+
if (Reflect.ownKeys(cls).includes("key")) {
|
|
48
|
+
const { key, ...rest } = tag
|
|
49
|
+
fields = rest as any
|
|
50
|
+
}
|
|
51
|
+
const t = Object.assign(cls, Object.getPrototypeOf(tag), fields)
|
|
52
|
+
if (!creationError) {
|
|
53
|
+
const limit = Error.stackTraceLimit
|
|
54
|
+
Error.stackTraceLimit = 2
|
|
55
|
+
creationError = new Error()
|
|
56
|
+
Error.stackTraceLimit = limit
|
|
57
|
+
}
|
|
58
|
+
// the stack is used to get the location of the tag definition, if a service is not found in the registry
|
|
59
|
+
Object.defineProperty(t, "stack", {
|
|
60
|
+
get() {
|
|
61
|
+
return creationError!.stack
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
return t
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type ServiceAcessorShape<Self, Type> =
|
|
69
|
+
& (Type extends Record<PropertyKey, any> ? {
|
|
70
|
+
[
|
|
71
|
+
k in keyof Type as Type[k] extends ((...args: [...infer Args]) => infer Ret)
|
|
72
|
+
? ((...args: Readonly<Args>) => Ret) extends Type[k] ? k : never
|
|
73
|
+
: k
|
|
74
|
+
]: Type[k] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
|
|
75
|
+
? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
|
|
76
|
+
: Type[k] extends (...args: [...infer Args]) => infer A
|
|
77
|
+
? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
|
|
78
|
+
: Type[k] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
|
|
79
|
+
: Effect.Effect<Type[k], never, Self>
|
|
80
|
+
}
|
|
81
|
+
: {})
|
|
82
|
+
& {
|
|
83
|
+
use: <X>(
|
|
84
|
+
body: (_: Type) => X
|
|
85
|
+
) => X extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, R | Self>
|
|
86
|
+
: Effect.Effect<X, never, Self>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const proxify = <T extends object>(Tag: T) =>
|
|
90
|
+
<Self, Shape>():
|
|
91
|
+
& T
|
|
92
|
+
& ServiceAcessorShape<Self, Shape> =>
|
|
93
|
+
{
|
|
94
|
+
const cache = new Map()
|
|
95
|
+
const done = new Proxy(Tag, {
|
|
96
|
+
get(_target: any, prop: any, _receiver) {
|
|
97
|
+
if (prop === "use") {
|
|
98
|
+
// @ts-expect-error abc
|
|
99
|
+
return (body) => Effect.andThen(Tag, body)
|
|
100
|
+
}
|
|
101
|
+
if (prop in Tag) {
|
|
102
|
+
return (Tag as any)[prop]
|
|
103
|
+
}
|
|
104
|
+
if (cache.has(prop)) {
|
|
105
|
+
return cache.get(prop)
|
|
106
|
+
}
|
|
107
|
+
const fn = (...args: Array<any>) => Effect.andThen(Tag as any, (s: any) => s[prop](...args))
|
|
108
|
+
// @ts-expect-error abc
|
|
109
|
+
const cn = Effect.andThen(Tag, (s) => s[prop])
|
|
110
|
+
Object.assign(fn, cn)
|
|
111
|
+
Object.setPrototypeOf(fn, Object.getPrototypeOf(cn))
|
|
112
|
+
cache.set(prop, fn)
|
|
113
|
+
return fn
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
return done
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// export const TagMake = <ServiceImpl, R, E, const Key extends string>(
|
|
120
|
+
// key: Key,
|
|
121
|
+
// make: Effect.Effect<ServiceImpl, E, R>
|
|
122
|
+
// ) =>
|
|
123
|
+
// <Id>() => {
|
|
124
|
+
// const limit = Error.stackTraceLimit
|
|
125
|
+
// Error.stackTraceLimit = 2
|
|
126
|
+
// const creationError = new Error()
|
|
127
|
+
// Error.stackTraceLimit = limit
|
|
128
|
+
// const c: {
|
|
129
|
+
// new(): Context.TagClassShape<Key, ServiceImpl>
|
|
130
|
+
// toLayer: () => Layer<Id, E, R>
|
|
131
|
+
// toLayerScoped: () => Layer<Id, E, Exclude<R, Scope>>
|
|
132
|
+
// } = class {
|
|
133
|
+
// static toLayer = () => {
|
|
134
|
+
// return Layer.effect(this as any, make)
|
|
135
|
+
// }
|
|
136
|
+
|
|
137
|
+
// static toLayerScoped = () => {
|
|
138
|
+
// return Layer.scoped(this as any, make)
|
|
139
|
+
// }
|
|
140
|
+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
// } as any
|
|
142
|
+
|
|
143
|
+
// return proxify(assignTag<Id, ServiceImpl>(key, creationError)(c))<Id, ServiceImpl>()
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
// export function Tag<Id, ServiceImpl, Service = Id>(key?: string) {
|
|
147
|
+
// const limit = Error.stackTraceLimit
|
|
148
|
+
// Error.stackTraceLimit = 2
|
|
149
|
+
// const creationError = new Error()
|
|
150
|
+
// Error.stackTraceLimit = limit
|
|
151
|
+
// const c: (abstract new(impl: ServiceImpl) => Readonly<ServiceImpl>) & {
|
|
152
|
+
// toLayer: <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => Layer<Id, E, R>
|
|
153
|
+
// toLayerScoped: <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => Layer<Id, E, Exclude<R, Scope>>
|
|
154
|
+
// } = class {
|
|
155
|
+
// constructor(service: ServiceImpl) {
|
|
156
|
+
// Object.assign(this, service)
|
|
157
|
+
// }
|
|
158
|
+
// static _key?: string
|
|
159
|
+
// static toLayer = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
160
|
+
// return Layer.effect(this as any, eff)
|
|
161
|
+
// }
|
|
162
|
+
// static toLayerScoped = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
163
|
+
// return Layer.scoped(this as any, eff)
|
|
164
|
+
// }
|
|
165
|
+
// static get key() {
|
|
166
|
+
// return this._key ?? (this._key = key ?? creationError.stack?.split("\n")[2] ?? this.name)
|
|
167
|
+
// }
|
|
168
|
+
// } as any
|
|
169
|
+
|
|
170
|
+
// return proxify(assignTag<Id, Service>(key, creationError)(c))<Id, ServiceImpl>()
|
|
171
|
+
// }
|
|
172
|
+
|
|
173
|
+
// export const TagMake = <ServiceImpl, R, E>(
|
|
174
|
+
// make: Effect.Effect<ServiceImpl, E, R>,
|
|
175
|
+
// key?: string
|
|
176
|
+
// ) =>
|
|
177
|
+
// <Id, Service = Id>() => {
|
|
178
|
+
// const limit = Error.stackTraceLimit
|
|
179
|
+
// Error.stackTraceLimit = 2
|
|
180
|
+
// const creationError = new Error()
|
|
181
|
+
// Error.stackTraceLimit = limit
|
|
182
|
+
// const c: (abstract new(impl: ServiceImpl) => Readonly<ServiceImpl>) & {
|
|
183
|
+
// toLayer: { (): Layer<Id, E, R>; <E, R>(eff: Effect.Effect<ServiceImpl, E, R>): Layer<Id, E, R> }
|
|
184
|
+
// toLayerScoped: {
|
|
185
|
+
// (): Layer<Id, E, Exclude<R, Scope>>
|
|
186
|
+
// <E, R>(eff: Effect.Effect<ServiceImpl, E, R>): Layer<Id, E, Exclude<R, Scope>>
|
|
187
|
+
// }
|
|
188
|
+
// make: Effect.Effect<Id, E, R>
|
|
189
|
+
// } = class {
|
|
190
|
+
// constructor(service: ServiceImpl) {
|
|
191
|
+
// Object.assign(this, service)
|
|
192
|
+
// }
|
|
193
|
+
// static _key: string
|
|
194
|
+
// static make = make
|
|
195
|
+
// // works around an issue where defining layer on the class messes up and causes the Tag to infer to `any, any` :/
|
|
196
|
+
// static toLayer = (arg?: any) => {
|
|
197
|
+
// return Layer.effect(this as any, arg ?? this.make)
|
|
198
|
+
// }
|
|
199
|
+
|
|
200
|
+
// static toLayerScoped = (arg?: any) => {
|
|
201
|
+
// return Layer.scoped(this as any, arg ?? this.make)
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// static get key() {
|
|
205
|
+
// return this._key ?? (this._key = key ?? creationError.stack?.split("\n")[2] ?? this.name)
|
|
206
|
+
// }
|
|
207
|
+
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
208
|
+
// } as any
|
|
209
|
+
|
|
210
|
+
// return proxify(assignTag<Id, Service>(key, creationError)(c))<Id, ServiceImpl>()
|
|
211
|
+
// }
|
|
212
|
+
|
|
213
|
+
export function TagId<const Key extends string>(key: Key) {
|
|
214
|
+
return <Id, ServiceImpl>() => {
|
|
215
|
+
const limit = Error.stackTraceLimit
|
|
216
|
+
Error.stackTraceLimit = 2
|
|
217
|
+
const creationError = new Error()
|
|
218
|
+
Error.stackTraceLimit = limit
|
|
219
|
+
const c:
|
|
220
|
+
& (abstract new(
|
|
221
|
+
service: ServiceImpl
|
|
222
|
+
) => Readonly<ServiceImpl> & Context.TagClassShape<Key, ServiceImpl>)
|
|
223
|
+
& {
|
|
224
|
+
toLayer: <E, R>(
|
|
225
|
+
eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>
|
|
226
|
+
) => Layer.Layer<Id, E, R>
|
|
227
|
+
toLayerScoped: <E, R>(
|
|
228
|
+
eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>
|
|
229
|
+
) => Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
230
|
+
of: (service: Omit<Id, keyof Context.TagClassShape<any, any>>) => Id
|
|
231
|
+
} = class {
|
|
232
|
+
constructor(service: any) {
|
|
233
|
+
// TODO: instead, wrap the service, and direct calls?
|
|
234
|
+
Object.assign(this, service)
|
|
235
|
+
}
|
|
236
|
+
static of = (service: ServiceImpl) => service
|
|
237
|
+
static toLayer = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
238
|
+
return Layer.effect(this as any, eff)
|
|
239
|
+
}
|
|
240
|
+
static toLayerScoped = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
241
|
+
return Layer.scoped(this as any, eff)
|
|
242
|
+
}
|
|
243
|
+
} as any
|
|
244
|
+
|
|
245
|
+
return proxify(assignTag<Id, Id>(key, creationError)(c))<Id, ServiceImpl>()
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const TagMakeId = <ServiceImpl, R, E, const Key extends string>(
|
|
250
|
+
key: Key,
|
|
251
|
+
make: Effect.Effect<ServiceImpl, E, R>
|
|
252
|
+
) =>
|
|
253
|
+
<Id>() => {
|
|
254
|
+
const limit = Error.stackTraceLimit
|
|
255
|
+
Error.stackTraceLimit = 2
|
|
256
|
+
const creationError = new Error()
|
|
257
|
+
Error.stackTraceLimit = limit
|
|
258
|
+
const c:
|
|
259
|
+
& (abstract new(
|
|
260
|
+
service: ServiceImpl
|
|
261
|
+
) => Readonly<ServiceImpl> & Context.TagClassShape<Key, ServiceImpl>)
|
|
262
|
+
& {
|
|
263
|
+
toLayer: {
|
|
264
|
+
(): Layer.Layer<Id, E, R>
|
|
265
|
+
<E, R>(eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>): Layer.Layer<Id, E, R>
|
|
266
|
+
}
|
|
267
|
+
toLayerScoped: {
|
|
268
|
+
(): Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
269
|
+
<E, R>(eff: Effect.Effect<Context.TagClassShape<any, any>, E, R>): Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
270
|
+
}
|
|
271
|
+
of: (service: Context.TagClassShape<any, any>) => Id
|
|
272
|
+
make: Effect.Effect<Id, E, R>
|
|
273
|
+
} = class {
|
|
274
|
+
constructor(service: any) {
|
|
275
|
+
// TODO: instead, wrap the service, and direct calls?
|
|
276
|
+
Object.assign(this, service)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
static of = (service: ServiceImpl) => service
|
|
280
|
+
static make = make
|
|
281
|
+
// works around an issue where defining layer on the class messes up and causes the Tag to infer to `any, any` :/
|
|
282
|
+
static toLayer = (arg?: any) => {
|
|
283
|
+
return Layer.effect(this as any, arg ?? this.make)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
static toLayerScoped = (arg?: any) => {
|
|
287
|
+
return Layer.scoped(this as any, arg ?? this.make)
|
|
288
|
+
}
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
|
+
} as any
|
|
291
|
+
|
|
292
|
+
return proxify(assignTag<Id, Id>(key, creationError)(c))<Id, ServiceImpl>()
|
|
293
|
+
}
|