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.
Files changed (310) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/Array.cjs +132 -0
  3. package/_cjs/Array.cjs.map +1 -0
  4. package/_cjs/Chunk.cjs +128 -0
  5. package/_cjs/Chunk.cjs.map +1 -0
  6. package/_cjs/Config/SecretURL.cjs +3 -3
  7. package/_cjs/Config/SecretURL.cjs.map +1 -1
  8. package/_cjs/Config/internal/configSecretURL.cjs +2 -2
  9. package/_cjs/Config/internal/configSecretURL.cjs.map +1 -1
  10. package/_cjs/Context.cjs +243 -0
  11. package/_cjs/Context.cjs.map +1 -0
  12. package/_cjs/Dictionary.cjs +522 -0
  13. package/_cjs/Dictionary.cjs.map +1 -0
  14. package/_cjs/Effect.cjs +202 -0
  15. package/_cjs/Effect.cjs.map +1 -0
  16. package/_cjs/Function.cjs +107 -0
  17. package/_cjs/Function.cjs.map +1 -0
  18. package/_cjs/NonEmptySet.cjs +26 -0
  19. package/_cjs/NonEmptySet.cjs.map +1 -0
  20. package/_cjs/NonEmptySetAspects.cjs +17 -0
  21. package/_cjs/NonEmptySetAspects.cjs.map +1 -0
  22. package/_cjs/NonEmptySetBase.cjs +82 -0
  23. package/_cjs/NonEmptySetBase.cjs.map +1 -0
  24. package/_cjs/Object.cjs +24 -0
  25. package/_cjs/Object.cjs.map +1 -0
  26. package/_cjs/Operations.cjs +1 -1
  27. package/_cjs/Option.cjs +88 -0
  28. package/_cjs/Option.cjs.map +1 -0
  29. package/_cjs/Prelude.cjs +53 -0
  30. package/_cjs/Prelude.cjs.map +1 -0
  31. package/_cjs/Prelude.code.cjs +53 -0
  32. package/_cjs/Prelude.code.cjs.map +1 -0
  33. package/_cjs/Pure.cjs +39 -36
  34. package/_cjs/Pure.cjs.map +1 -1
  35. package/_cjs/Schema/Class.cjs +61 -0
  36. package/_cjs/Schema/Class.cjs.map +1 -0
  37. package/_cjs/Schema/FastCheck.cjs +39 -0
  38. package/_cjs/Schema/FastCheck.cjs.map +1 -0
  39. package/_cjs/Schema/Methods.cjs +6 -0
  40. package/_cjs/Schema/Methods.cjs.map +1 -0
  41. package/_cjs/Schema/brand.cjs +17 -0
  42. package/_cjs/Schema/brand.cjs.map +1 -0
  43. package/_cjs/Schema/email.cjs +20 -0
  44. package/_cjs/Schema/email.cjs.map +1 -0
  45. package/_cjs/Schema/ext.cjs +174 -0
  46. package/_cjs/Schema/ext.cjs.map +1 -0
  47. package/_cjs/Schema/moreStrings.cjs +124 -0
  48. package/_cjs/Schema/moreStrings.cjs.map +1 -0
  49. package/_cjs/Schema/numbers.cjs +52 -0
  50. package/_cjs/Schema/numbers.cjs.map +1 -0
  51. package/_cjs/Schema/phoneNumber.cjs +22 -0
  52. package/_cjs/Schema/phoneNumber.cjs.map +1 -0
  53. package/_cjs/Schema/schema.cjs +15 -0
  54. package/_cjs/Schema/schema.cjs.map +1 -0
  55. package/_cjs/Schema/strings.cjs +32 -0
  56. package/_cjs/Schema/strings.cjs.map +1 -0
  57. package/_cjs/Schema.cjs +334 -0
  58. package/_cjs/Schema.cjs.map +1 -0
  59. package/_cjs/Set.cjs +567 -0
  60. package/_cjs/Set.cjs.map +1 -0
  61. package/_cjs/Struct.cjs +51 -0
  62. package/_cjs/Struct.cjs.map +1 -0
  63. package/_cjs/Tag.cjs +25 -0
  64. package/_cjs/Tag.cjs.map +1 -0
  65. package/_cjs/Unify.cjs +40 -0
  66. package/_cjs/Unify.cjs.map +1 -0
  67. package/_cjs/_ext/misc.cjs +16 -16
  68. package/_cjs/_ext/misc.cjs.map +1 -1
  69. package/_cjs/_ext/ord.ext.cjs +52 -0
  70. package/_cjs/_ext/ord.ext.cjs.map +1 -0
  71. package/_cjs/builtin.cjs +6 -0
  72. package/_cjs/builtin.cjs.map +1 -0
  73. package/_cjs/client/clientFor.cjs +5 -3
  74. package/_cjs/client/clientFor.cjs.map +1 -1
  75. package/_cjs/client/config.cjs +4 -4
  76. package/_cjs/client/config.cjs.map +1 -1
  77. package/_cjs/client/errors.cjs +9 -9
  78. package/_cjs/client/errors.cjs.map +1 -1
  79. package/_cjs/http/http-client.cjs +35 -0
  80. package/_cjs/http/http-client.cjs.map +1 -0
  81. package/_cjs/ids.cjs +5 -5
  82. package/_cjs/ids.cjs.map +1 -1
  83. package/_cjs/index.cjs +1 -1
  84. package/_cjs/lib.cjs +178 -9
  85. package/_cjs/lib.cjs.map +1 -1
  86. package/_cjs/logger.cjs +1 -1
  87. package/_cjs/transform.cjs +45 -0
  88. package/_cjs/transform.cjs.map +1 -0
  89. package/_cjs/utils/effectify.cjs +25 -0
  90. package/_cjs/utils/effectify.cjs.map +1 -0
  91. package/_cjs/utils/extend.cjs +17 -0
  92. package/_cjs/utils/extend.cjs.map +1 -0
  93. package/_cjs/utils/logger.cjs +23 -0
  94. package/_cjs/utils/logger.cjs.map +1 -0
  95. package/_cjs/utils.cjs +431 -4
  96. package/_cjs/utils.cjs.map +1 -1
  97. package/_cjs/validation/validators.cjs +32 -0
  98. package/_cjs/validation/validators.cjs.map +1 -0
  99. package/_cjs/validation.cjs +45 -0
  100. package/_cjs/validation.cjs.map +1 -0
  101. package/dist/Array.d.ts +64 -0
  102. package/dist/Array.d.ts.map +1 -0
  103. package/dist/Array.js +89 -0
  104. package/dist/Chunk.d.ts +68 -0
  105. package/dist/Chunk.d.ts.map +1 -0
  106. package/dist/Chunk.js +93 -0
  107. package/dist/Config/SecretURL.d.ts +3 -3
  108. package/dist/Config/SecretURL.d.ts.map +1 -1
  109. package/dist/Config/SecretURL.js +2 -2
  110. package/dist/Config/internal/configSecretURL.js +2 -2
  111. package/dist/Context.d.ts +55 -0
  112. package/dist/Context.d.ts.map +1 -0
  113. package/dist/Context.js +204 -0
  114. package/dist/Dictionary.d.ts +260 -0
  115. package/dist/Dictionary.d.ts.map +1 -0
  116. package/dist/Dictionary.js +448 -0
  117. package/dist/Effect.d.ts +115 -0
  118. package/dist/Effect.d.ts.map +1 -0
  119. package/dist/Effect.js +153 -0
  120. package/dist/Function.d.ts +72 -0
  121. package/dist/Function.d.ts.map +1 -0
  122. package/dist/Function.js +71 -0
  123. package/dist/Inputify.type.d.ts +1 -1
  124. package/dist/Inputify.type.d.ts.map +1 -1
  125. package/dist/NonEmptySet.d.ts +3 -0
  126. package/dist/NonEmptySet.d.ts.map +1 -0
  127. package/dist/NonEmptySet.js +3 -0
  128. package/dist/NonEmptySetAspects.d.ts +2 -0
  129. package/dist/NonEmptySetAspects.d.ts.map +1 -0
  130. package/dist/NonEmptySetAspects.js +2 -0
  131. package/dist/NonEmptySetBase.d.ts +39 -0
  132. package/dist/NonEmptySetBase.d.ts.map +1 -0
  133. package/dist/NonEmptySetBase.js +63 -0
  134. package/dist/Object.d.ts +7 -0
  135. package/dist/Object.d.ts.map +1 -0
  136. package/dist/Object.js +7 -0
  137. package/dist/Operations.d.ts +2 -2
  138. package/dist/Operations.js +1 -1
  139. package/dist/Option.d.ts +39 -0
  140. package/dist/Option.d.ts.map +1 -0
  141. package/dist/Option.js +55 -0
  142. package/dist/Prelude.code.d.ts +25 -0
  143. package/dist/Prelude.code.d.ts.map +1 -0
  144. package/dist/Prelude.code.js +24 -0
  145. package/dist/Prelude.d.ts +163 -0
  146. package/dist/Prelude.d.ts.map +1 -0
  147. package/dist/Prelude.js +24 -0
  148. package/dist/Pure.d.ts +13 -12
  149. package/dist/Pure.d.ts.map +1 -1
  150. package/dist/Pure.js +18 -17
  151. package/dist/Schema/Class.d.ts +45 -0
  152. package/dist/Schema/Class.d.ts.map +1 -0
  153. package/dist/Schema/Class.js +50 -0
  154. package/dist/Schema/FastCheck.d.ts +10 -0
  155. package/dist/Schema/FastCheck.d.ts.map +1 -0
  156. package/dist/Schema/FastCheck.js +12 -0
  157. package/dist/Schema/Methods.d.ts +6 -0
  158. package/dist/Schema/Methods.d.ts.map +1 -0
  159. package/dist/Schema/Methods.js +2 -0
  160. package/dist/Schema/brand.d.ts +35 -0
  161. package/dist/Schema/brand.d.ts.map +1 -0
  162. package/dist/Schema/brand.js +7 -0
  163. package/dist/Schema/email.d.ts +9 -0
  164. package/dist/Schema/email.d.ts.map +1 -0
  165. package/dist/Schema/email.js +12 -0
  166. package/dist/Schema/ext.d.ts +89 -0
  167. package/dist/Schema/ext.d.ts.map +1 -0
  168. package/dist/Schema/ext.js +111 -0
  169. package/dist/Schema/moreStrings.d.ts +109 -0
  170. package/dist/Schema/moreStrings.d.ts.map +1 -0
  171. package/dist/Schema/moreStrings.js +108 -0
  172. package/dist/Schema/numbers.d.ts +46 -0
  173. package/dist/Schema/numbers.d.ts.map +1 -0
  174. package/dist/Schema/numbers.js +28 -0
  175. package/dist/Schema/phoneNumber.d.ts +9 -0
  176. package/dist/Schema/phoneNumber.d.ts.map +1 -0
  177. package/dist/Schema/phoneNumber.js +14 -0
  178. package/dist/Schema/schema.d.ts +6 -0
  179. package/dist/Schema/schema.d.ts.map +1 -0
  180. package/dist/Schema/schema.js +5 -0
  181. package/dist/Schema/strings.d.ts +19 -0
  182. package/dist/Schema/strings.d.ts.map +1 -0
  183. package/dist/Schema/strings.js +32 -0
  184. package/dist/{schema.d.ts → Schema.d.ts} +25 -9
  185. package/dist/Schema.d.ts.map +1 -0
  186. package/dist/Schema.js +89 -0
  187. package/dist/Set.d.ts +221 -0
  188. package/dist/Set.d.ts.map +1 -0
  189. package/dist/Set.js +516 -0
  190. package/dist/Struct.d.ts +44 -0
  191. package/dist/Struct.d.ts.map +1 -0
  192. package/dist/Struct.js +29 -0
  193. package/dist/Tag.d.ts +9 -0
  194. package/dist/Tag.d.ts.map +1 -0
  195. package/dist/Tag.js +18 -0
  196. package/dist/Unify.d.ts +43 -0
  197. package/dist/Unify.d.ts.map +1 -0
  198. package/dist/Unify.js +31 -0
  199. package/dist/Widen.type.d.ts +1 -1
  200. package/dist/Widen.type.d.ts.map +1 -1
  201. package/dist/_ext/misc.d.ts +11 -11
  202. package/dist/_ext/misc.d.ts.map +1 -1
  203. package/dist/_ext/misc.js +8 -8
  204. package/dist/_ext/ord.ext.d.ts +23 -0
  205. package/dist/_ext/ord.ext.d.ts.map +1 -0
  206. package/dist/_ext/ord.ext.js +44 -0
  207. package/dist/builtin.d.ts +51 -0
  208. package/dist/builtin.d.ts.map +1 -0
  209. package/dist/builtin.js +2 -0
  210. package/dist/client/clientFor.d.ts +1 -1
  211. package/dist/client/clientFor.d.ts.map +1 -1
  212. package/dist/client/clientFor.js +2 -2
  213. package/dist/client/config.d.ts +1 -1
  214. package/dist/client/config.d.ts.map +1 -1
  215. package/dist/client/config.js +2 -2
  216. package/dist/client/errors.js +1 -1
  217. package/dist/http/http-client.d.ts +43 -0
  218. package/dist/http/http-client.d.ts.map +1 -0
  219. package/dist/http/http-client.js +30 -0
  220. package/dist/ids.d.ts +3 -3
  221. package/dist/ids.d.ts.map +1 -1
  222. package/dist/ids.js +2 -2
  223. package/dist/index.d.ts +1 -1
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js +2 -2
  226. package/dist/lib.d.ts +22 -4
  227. package/dist/lib.d.ts.map +1 -1
  228. package/dist/lib.js +20 -5
  229. package/dist/logger.d.ts.map +1 -1
  230. package/dist/logger.js +2 -2
  231. package/dist/transform.d.ts +12 -0
  232. package/dist/transform.d.ts.map +1 -0
  233. package/dist/transform.js +39 -0
  234. package/dist/utils/effectify.d.ts +210 -0
  235. package/dist/utils/effectify.d.ts.map +1 -0
  236. package/dist/utils/effectify.js +19 -0
  237. package/dist/utils/extend.d.ts +3 -0
  238. package/dist/utils/extend.d.ts.map +1 -0
  239. package/dist/utils/extend.js +9 -0
  240. package/dist/utils/logger.d.ts +12 -0
  241. package/dist/utils/logger.d.ts.map +1 -0
  242. package/dist/utils/logger.js +15 -0
  243. package/dist/utils.d.ts +192 -1
  244. package/dist/utils.d.ts.map +1 -1
  245. package/dist/utils.js +332 -2
  246. package/dist/validation/validators.d.ts +11 -0
  247. package/dist/validation/validators.d.ts.map +1 -0
  248. package/dist/validation/validators.js +26 -0
  249. package/dist/validation.d.ts +13 -0
  250. package/dist/validation.d.ts.map +1 -0
  251. package/dist/validation.js +14 -0
  252. package/package.json +360 -9
  253. package/src/Array.ts +127 -0
  254. package/src/Chunk.ts +112 -0
  255. package/src/Config/SecretURL.ts +3 -3
  256. package/src/Config/internal/configSecretURL.ts +1 -1
  257. package/src/Context.ts +293 -0
  258. package/src/Dictionary.ts +669 -0
  259. package/src/Effect.ts +265 -0
  260. package/src/Function.ts +175 -0
  261. package/src/Inputify.type.ts +1 -1
  262. package/src/NonEmptySet.ts +3 -0
  263. package/src/NonEmptySetAspects.ts +1 -0
  264. package/src/NonEmptySetBase.ts +109 -0
  265. package/src/Object.ts +19 -0
  266. package/src/Operations.ts +1 -1
  267. package/src/Option.ts +82 -0
  268. package/src/Prelude.code.ts +27 -0
  269. package/src/Prelude.ts +220 -0
  270. package/src/Pure.ts +37 -30
  271. package/src/Schema/Class.ts +225 -0
  272. package/src/Schema/FastCheck.ts +23 -0
  273. package/src/Schema/Methods.ts +8 -0
  274. package/src/Schema/brand.ts +50 -0
  275. package/src/Schema/email.ts +22 -0
  276. package/src/Schema/ext.ts +273 -0
  277. package/src/Schema/moreStrings.ts +260 -0
  278. package/src/Schema/numbers.ts +83 -0
  279. package/src/Schema/phoneNumber.ts +24 -0
  280. package/src/Schema/schema.ts +6 -0
  281. package/src/Schema/strings.ts +60 -0
  282. package/src/{schema.ts → Schema.ts} +52 -20
  283. package/src/Set.ts +674 -0
  284. package/src/Struct.ts +54 -0
  285. package/src/Tag.ts +20 -0
  286. package/src/Unify.ts +56 -0
  287. package/src/Widen.type.ts +1 -1
  288. package/src/_ext/misc.ts +22 -22
  289. package/src/_ext/ord.ext.ts +49 -0
  290. package/src/builtin.ts +64 -0
  291. package/src/client/clientFor.ts +1 -1
  292. package/src/client/config.ts +1 -1
  293. package/src/client/errors.ts +1 -1
  294. package/src/http/http-client.ts +73 -0
  295. package/src/ids.ts +3 -3
  296. package/src/index.ts +1 -1
  297. package/src/lib.ts +88 -4
  298. package/src/logger.ts +1 -1
  299. package/src/transform.ts +80 -0
  300. package/src/utils/effectify.ts +259 -0
  301. package/src/utils/extend.ts +9 -0
  302. package/src/utils/logger.ts +24 -0
  303. package/src/utils.ts +805 -1
  304. package/src/validation/validators.ts +32 -0
  305. package/src/validation.ts +18 -0
  306. package/tsconfig.src.json +1 -5
  307. package/_cjs/schema.cjs +0 -110
  308. package/_cjs/schema.cjs.map +0 -1
  309. package/dist/schema.d.ts.map +0 -1
  310. 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
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
- import type { Equal, Redacted } from "@effect-app/core"
5
- import { Config } from "@effect-app/core"
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))
@@ -1,4 +1,4 @@
1
- import { Redacted } from "@effect-app/core"
1
+ import { Redacted } from "effect"
2
2
  import * as Chunk from "effect/Chunk"
3
3
  import { SecretTypeId } from "effect/Secret"
4
4
  import type * as SecretURL from "../SecretURL.js"
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
+ }