effect-app 0.152.0

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 (169) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/.prettierignore +6 -0
  3. package/CHANGELOG.md +4106 -0
  4. package/_cjs/Config/SecretURL.cjs +58 -0
  5. package/_cjs/Config/SecretURL.cjs.map +1 -0
  6. package/_cjs/Config/internal/configSecretURL.cjs +88 -0
  7. package/_cjs/Config/internal/configSecretURL.cjs.map +1 -0
  8. package/_cjs/Inputify.type.cjs +6 -0
  9. package/_cjs/Inputify.type.cjs.map +1 -0
  10. package/_cjs/Operations.cjs +76 -0
  11. package/_cjs/Operations.cjs.map +1 -0
  12. package/_cjs/Pure.cjs +201 -0
  13. package/_cjs/Pure.cjs.map +1 -0
  14. package/_cjs/Request.cjs +76 -0
  15. package/_cjs/Request.cjs.map +1 -0
  16. package/_cjs/Widen.type.cjs +6 -0
  17. package/_cjs/Widen.type.cjs.map +1 -0
  18. package/_cjs/_ext/date.cjs +64 -0
  19. package/_cjs/_ext/date.cjs.map +1 -0
  20. package/_cjs/_ext/misc.cjs +121 -0
  21. package/_cjs/_ext/misc.cjs.map +1 -0
  22. package/_cjs/_global.cjs +24 -0
  23. package/_cjs/_global.cjs.map +1 -0
  24. package/_cjs/_global.ext.cjs +5 -0
  25. package/_cjs/_global.ext.cjs.map +1 -0
  26. package/_cjs/_global.schema.cjs +4 -0
  27. package/_cjs/_global.schema.cjs.map +1 -0
  28. package/_cjs/client/QueryResult.cjs +116 -0
  29. package/_cjs/client/QueryResult.cjs.map +1 -0
  30. package/_cjs/client/clientFor.cjs +159 -0
  31. package/_cjs/client/clientFor.cjs.map +1 -0
  32. package/_cjs/client/config.cjs +21 -0
  33. package/_cjs/client/config.cjs.map +1 -0
  34. package/_cjs/client/errors.cjs +116 -0
  35. package/_cjs/client/errors.cjs.map +1 -0
  36. package/_cjs/client/fetch.cjs +178 -0
  37. package/_cjs/client/fetch.cjs.map +1 -0
  38. package/_cjs/client.cjs +61 -0
  39. package/_cjs/client.cjs.map +1 -0
  40. package/_cjs/faker.cjs +31 -0
  41. package/_cjs/faker.cjs.map +1 -0
  42. package/_cjs/ids.cjs +24 -0
  43. package/_cjs/ids.cjs.map +1 -0
  44. package/_cjs/index.cjs +27 -0
  45. package/_cjs/index.cjs.map +1 -0
  46. package/_cjs/refinements.cjs +97 -0
  47. package/_cjs/refinements.cjs.map +1 -0
  48. package/_cjs/schema.cjs +50 -0
  49. package/_cjs/schema.cjs.map +1 -0
  50. package/_cjs/schema.test.cjs +9 -0
  51. package/_cjs/schema.test.cjs.map +1 -0
  52. package/_cjs/service.cjs +97 -0
  53. package/_cjs/service.cjs.map +1 -0
  54. package/_cjs/utils.cjs +17 -0
  55. package/_cjs/utils.cjs.map +1 -0
  56. package/_src/Config/SecretURL.ts +103 -0
  57. package/_src/Config/internal/configSecretURL.ts +85 -0
  58. package/_src/Inputify.type.ts +13 -0
  59. package/_src/Operations.ts +70 -0
  60. package/_src/Pure.ts +525 -0
  61. package/_src/Request.ts +106 -0
  62. package/_src/Widen.type.ts +28 -0
  63. package/_src/_ext/date.ts +84 -0
  64. package/_src/_ext/misc.ts +161 -0
  65. package/_src/_global/stm.ts.bak +35 -0
  66. package/_src/_global.ext.ts +3 -0
  67. package/_src/_global.schema.ts +106 -0
  68. package/_src/_global.ts +119 -0
  69. package/_src/client/QueryResult.ts +120 -0
  70. package/_src/client/clientFor.ts +260 -0
  71. package/_src/client/config.ts +13 -0
  72. package/_src/client/errors.ts +129 -0
  73. package/_src/client/fetch.ts +253 -0
  74. package/_src/client.ts +7 -0
  75. package/_src/faker.ts +32 -0
  76. package/_src/ids.ts +35 -0
  77. package/_src/index.ts +4 -0
  78. package/_src/refinements.ts +92 -0
  79. package/_src/schema/_schema.ts.bak +208 -0
  80. package/_src/schema/api/date.ts.bak +78 -0
  81. package/_src/schema/api.ts.bak +20 -0
  82. package/_src/schema/overrides.ts.bak +76 -0
  83. package/_src/schema/shared.ts.bak +334 -0
  84. package/_src/schema.test.ts +3 -0
  85. package/_src/schema.ts +37 -0
  86. package/_src/service.ts +119 -0
  87. package/_src/utils.ts +1 -0
  88. package/dist/Config/SecretURL.d.ts +82 -0
  89. package/dist/Config/SecretURL.d.ts.map +1 -0
  90. package/dist/Config/SecretURL.js +49 -0
  91. package/dist/Config/internal/configSecretURL.d.ts +24 -0
  92. package/dist/Config/internal/configSecretURL.d.ts.map +1 -0
  93. package/dist/Config/internal/configSecretURL.js +75 -0
  94. package/dist/Inputify.type.d.ts +10 -0
  95. package/dist/Inputify.type.d.ts.map +1 -0
  96. package/dist/Inputify.type.js +2 -0
  97. package/dist/Operations.d.ts +170 -0
  98. package/dist/Operations.d.ts.map +1 -0
  99. package/dist/Operations.js +87 -0
  100. package/dist/Pure.d.ts +169 -0
  101. package/dist/Pure.d.ts.map +1 -0
  102. package/dist/Pure.js +167 -0
  103. package/dist/Request.d.ts +49 -0
  104. package/dist/Request.d.ts.map +1 -0
  105. package/dist/Request.js +58 -0
  106. package/dist/Widen.type.d.ts +19 -0
  107. package/dist/Widen.type.d.ts.map +1 -0
  108. package/dist/Widen.type.js +2 -0
  109. package/dist/_ext/date.d.ts +71 -0
  110. package/dist/_ext/date.d.ts.map +1 -0
  111. package/dist/_ext/date.js +58 -0
  112. package/dist/_ext/misc.d.ts +77 -0
  113. package/dist/_ext/misc.d.ts.map +1 -0
  114. package/dist/_ext/misc.js +98 -0
  115. package/dist/_global.d.ts +70 -0
  116. package/dist/_global.d.ts.map +1 -0
  117. package/dist/_global.ext.d.ts +3 -0
  118. package/dist/_global.ext.d.ts.map +1 -0
  119. package/dist/_global.ext.js +4 -0
  120. package/dist/_global.js +76 -0
  121. package/dist/_global.schema.d.ts +6 -0
  122. package/dist/_global.schema.d.ts.map +1 -0
  123. package/dist/_global.schema.js +6 -0
  124. package/dist/client/QueryResult.d.ts +85 -0
  125. package/dist/client/QueryResult.d.ts.map +1 -0
  126. package/dist/client/QueryResult.js +85 -0
  127. package/dist/client/clientFor.d.ts +44 -0
  128. package/dist/client/clientFor.d.ts.map +1 -0
  129. package/dist/client/clientFor.js +144 -0
  130. package/dist/client/config.d.ts +14 -0
  131. package/dist/client/config.d.ts.map +1 -0
  132. package/dist/client/config.js +11 -0
  133. package/dist/client/errors.d.ts +206 -0
  134. package/dist/client/errors.d.ts.map +1 -0
  135. package/dist/client/errors.js +130 -0
  136. package/dist/client/fetch.d.ts +61 -0
  137. package/dist/client/fetch.d.ts.map +1 -0
  138. package/dist/client/fetch.js +127 -0
  139. package/dist/client.d.ts +6 -0
  140. package/dist/client.d.ts.map +1 -0
  141. package/dist/client.js +7 -0
  142. package/dist/faker.d.ts +7 -0
  143. package/dist/faker.d.ts.map +1 -0
  144. package/dist/faker.js +24 -0
  145. package/dist/ids.d.ts +32 -0
  146. package/dist/ids.d.ts.map +1 -0
  147. package/dist/ids.js +17 -0
  148. package/dist/index.d.ts +4 -0
  149. package/dist/index.d.ts.map +1 -0
  150. package/dist/index.js +4 -0
  151. package/dist/refinements.d.ts +57 -0
  152. package/dist/refinements.d.ts.map +1 -0
  153. package/dist/refinements.js +85 -0
  154. package/dist/schema.d.ts +7 -0
  155. package/dist/schema.d.ts.map +1 -0
  156. package/dist/schema.js +22 -0
  157. package/dist/schema.test.d.ts.map +1 -0
  158. package/dist/service.d.ts +47 -0
  159. package/dist/service.d.ts.map +1 -0
  160. package/dist/service.js +83 -0
  161. package/dist/utils.d.ts +2 -0
  162. package/dist/utils.d.ts.map +1 -0
  163. package/dist/utils.js +2 -0
  164. package/package.json +315 -0
  165. package/tsconfig.json +114 -0
  166. package/tsconfig.json.bak +47 -0
  167. package/tsplus.config.json +7 -0
  168. package/vitest.config.ts +5 -0
  169. package/wallaby.cjs +1 -0
package/_src/Pure.ts ADDED
@@ -0,0 +1,525 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import * as Either from "effect/Either"
3
+ import type { ServiceTagged } from "./service.js"
4
+
5
+ const S1 = Symbol()
6
+ const S2 = Symbol()
7
+ const W = Symbol()
8
+
9
+ /**
10
+ * @tsplus type PureEnv
11
+ */
12
+ export interface PureState<S, S2 = S> {
13
+ readonly [S1]: (_: S) => void
14
+ readonly [S2]: () => S2
15
+
16
+ state: S2
17
+ }
18
+
19
+ /**
20
+ * @tsplus type PureEnv
21
+ */
22
+ export interface PureLog<W> {
23
+ readonly [W]: () => W
24
+ log: Chunk<W>
25
+ }
26
+
27
+ /**
28
+ * @tsplus type PureEnv
29
+ */
30
+ export interface PureEnv<W, S, S2 = S> extends PureState<S, S2>, PureLog<W> {}
31
+
32
+ export interface PureEnvTest extends PureState<any>, PureLog<any> {}
33
+
34
+ class PureEnvBase<W, S, S2 = S> implements PureEnv<W, S, S2> {
35
+ readonly [W]!: () => W
36
+ readonly [S1]!: (_: S) => void
37
+ readonly [S2]!: () => S2
38
+ readonly state: S2
39
+ readonly log: Chunk<W>
40
+
41
+ constructor(s: S2) {
42
+ this.state = s
43
+ this.log = Chunk.empty<W>()
44
+ }
45
+ }
46
+
47
+ export function makePureEnv<W, S, S2 = S>(s: S2): PureEnv<W, S, S2> {
48
+ return new PureEnvBase<W, S, S2>(s)
49
+ }
50
+
51
+ /**
52
+ * @tsplus unify PureEnv
53
+ */
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ export function unifyPureEnv<X extends PureEnv<any, any, any>>(
56
+ self: X
57
+ ): PureEnv<
58
+ [X] extends [{ [W]: () => infer W }] ? W : never,
59
+ [X] extends [{ [S1]: (_: infer S) => void }] ? S : never,
60
+ [X] extends [{ [S2]: () => infer S2 }] ? S2 : never
61
+ > {
62
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
63
+ return self
64
+ }
65
+
66
+ /**
67
+ * @tsplus type Pure
68
+ */
69
+ export type Pure<W, S, S2, R, E, A> = Effect<A, E, PureEnvEnv<W, S, S2> | R>
70
+
71
+ // type dsl<W, S, S2> = ProgramDSL<W, S, S2>
72
+
73
+ /**
74
+ * @tsplus static Pure.Ops GMUA_
75
+ */
76
+ export function GMUA_<W, S, S2, GR, GE, GA, MR, ME, MA, UR, UE, UA>(
77
+ get: Pure<W, S, S2, GR, GE, GA>,
78
+ modify: (i: GA) => Pure<W, S, S2, MR, ME, readonly [GA, MA]>,
79
+ update: (i: GA) => Pure<W, S, S2, UR, UE, UA>
80
+ ): Pure<W, S, S2, GR | MR | UR, GE | ME | UE, MA> {
81
+ return get.flatMap(modify).flatMap(([s, a]) => update(s).map(() => a))
82
+ }
83
+
84
+ /**
85
+ * @tsplus static Pure.Ops GMUA
86
+ */
87
+ export function GMUA<W, S, S2, GA, MR, ME, MA>(modify: (i: GA) => Pure<W, S, S2, MR, ME, readonly [GA, MA]>) {
88
+ return <GR, GE, UR, UE, UA>(
89
+ get: Pure<W, S, S2, GR, GE, GA>,
90
+ update: (i: GA) => Pure<W, S, S2, UR, UE, UA>
91
+ ) => GMUA_(get, modify, update)
92
+ }
93
+
94
+ /**
95
+ * @tsplus static Pure.Ops GMU_
96
+ */
97
+
98
+ export function GMU_<W, S, S2, GR, GE, GA, MR, ME, UR, UE, UA>(
99
+ get: Pure<W, S, S2, GR, GE, GA>,
100
+ modify: (i: GA) => Pure<W, S, S2, MR, ME, GA>,
101
+ update: (i: GA) => Pure<W, S, S2, UR, UE, UA>
102
+ ): Pure<W, S, S2, GR | MR | UR, GE | ME | UE, UA> {
103
+ return get.flatMap(modify).flatMap(update)
104
+ }
105
+
106
+ /**
107
+ * @tsplus static Pure.Ops GMU
108
+ */
109
+ export function GMU<W, S, S2, GA, MR, ME>(modify: (i: GA) => Pure<W, S, S2, MR, ME, GA>) {
110
+ return <GR, GE, UR, UE, UA>(
111
+ get: Pure<W, S, S2, GR, GE, GA>,
112
+ update: (i: GA) => Pure<W, S, S2, UR, UE, UA>
113
+ ) => GMU_(get, modify, update)
114
+ }
115
+
116
+ const tagg = GenericTag<{ env: PureEnv<never, unknown, never> }>("@services/tagg")
117
+ function castTag<W, S, S2>() {
118
+ return tagg as any as Tag<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
119
+ }
120
+
121
+ export const PureEnvEnv = Symbol()
122
+ export interface PureEnvEnv<W, S, S2> extends ServiceTagged<typeof PureEnvEnv> {
123
+ env: PureEnv<W, S, S2>
124
+ }
125
+
126
+ /**
127
+ * @tsplus static Pure.Ops get
128
+ */
129
+ export function get<S>(): Pure<never, S, S, never, never, S> {
130
+ return castTag<never, S, S>().map((_) => _.env.state)
131
+ }
132
+
133
+ /**
134
+ * @tsplus static Pure.Ops set
135
+ */
136
+ export function set<S>(s: S): Pure<never, S, S, never, never, void> {
137
+ return castTag<never, S, S>().map((_) => _.env.state = s)
138
+ }
139
+
140
+ export type PureLogT<W> = Pure<W, unknown, never, never, never, void>
141
+
142
+ /**
143
+ * @tsplus static Pure.Ops log
144
+ */
145
+ export function log<W>(w: W): PureLogT<W> {
146
+ return castTag<W, unknown, never>().map((_) => _.env.log = _.env.log.append(w))
147
+ }
148
+
149
+ /**
150
+ * @tsplus static Pure.Ops logMany
151
+ */
152
+ export function logMany<W>(w: Iterable<W>): PureLogT<W> {
153
+ return castTag<W, unknown, never>().map((_) => _.env.log = _.env.log.appendAll(w.toChunk))
154
+ }
155
+
156
+ /**
157
+ * @tsplus static Pure.Ops runAll
158
+ * @tsplus fluent effect/io/Effect runAll
159
+ */
160
+ export function runAll<R, E, A, W3, S1, S3, S4 extends S1>(
161
+ self: Effect<A, E, FixEnv<R, W3, S1, S3>>,
162
+ s: S4
163
+ ): Effect<readonly [Chunk<W3>, Either.Either<E, readonly [S3, A]>], never, Exclude<R, { env: PureEnv<W3, S1, S3> }>> {
164
+ const a = self
165
+ .flatMap((x) =>
166
+ castTag<W3, S1, S3>()
167
+ .flatMap(
168
+ ({ env: _ }) => Effect.sync(() => ({ log: _.log, state: _.state })) // Ref.get(_.log).flatMap(log => Ref.get(_.state).map(state => ({ log, state })))
169
+ )
170
+ .map(
171
+ (
172
+ { log, state }
173
+ ) => tuple(log, Either.right(tuple(state, x)) as Either.Either<E, readonly [S3, A]>)
174
+ )
175
+ )
176
+ .catchAll(
177
+ (err) => tagg.map((env) => tuple(env.env.log, Either.left(err) as Either.Either<E, readonly [S3, A]>))
178
+ )
179
+ return a
180
+ .provide(tagg.makeLayer({ env: makePureEnv<W3, S3, S4>(s) as any }) as any)
181
+ }
182
+
183
+ /**
184
+ * @tsplus static Pure.Ops runResult
185
+ * @tsplus fluent effect/io/Effect runResult
186
+ */
187
+ export function runResult<R, E, A, W3, S1, S3, S4 extends S1>(
188
+ self: Effect<A, E, FixEnv<R, W3, S1, S3>>,
189
+ s: S4
190
+ ) {
191
+ return runAll(self, s).map(([log, r]) => tuple(log, r.map(([s]) => s)))
192
+ }
193
+
194
+ /**
195
+ * @tsplus static Pure.Ops runTerm
196
+ * @tsplus fluent effect/io/Effect runTerm
197
+ */
198
+ export function runTerm<R, E, A, W3, S1, S3, S4 extends S1>(
199
+ self: Effect<A, E, FixEnv<R, W3, S1, S3>>,
200
+ s: S4
201
+ ) {
202
+ return runAll(self, s)
203
+ .flatMap(([evts, r]) =>
204
+ r
205
+ .map(([s3, a]) => tuple(s3, evts.toArray, a))
206
+ )
207
+ }
208
+
209
+ /**
210
+ * @tsplus static Pure.Ops runTermDiscard
211
+ * @tsplus fluent effect/io/Effect runTermDiscard
212
+ */
213
+ export function runTermDiscard<R, E, A, W3, S1, S3, S4 extends S1>(
214
+ self: Effect<A, E, FixEnv<R, W3, S1, S3>>,
215
+ s: S4
216
+ ) {
217
+ return self.runTerm(s).map(([s3, w3]) => tuple(s3, w3))
218
+ }
219
+
220
+ /**
221
+ * @tsplus static Pure.Ops runA
222
+ * @tsplus fluent effect/io/Effect runA
223
+ */
224
+ export function runA<R, E, A, W3, S1, S3, S4 extends S1>(
225
+ self: Effect<A, E, FixEnv<R, W3, S1, S3>>,
226
+ s: S4
227
+ ) {
228
+ return runAll(self, s).map(([log, r]) => tuple(log, r.map(([, a]) => a)))
229
+ }
230
+
231
+ /**
232
+ * @tsplus static Pure.Ops modifyWith
233
+ */
234
+ export function modify<S2, A, S3>(mod: (s: S2) => readonly [S3, A]): Effect<A, never, { env: PureEnv<never, S2, S3> }> {
235
+ return castTag<never, S3, S2>().map(
236
+ (_) =>
237
+ Effect.sync(() => mod(_.env.state)).map(([s, a]) => {
238
+ _.env.state = s as any
239
+ return a
240
+ })
241
+ ) as any
242
+ }
243
+
244
+ /**
245
+ * @tsplus static Pure.Ops modifyWithEffect
246
+ */
247
+ export function modifyM<W, R, E, A, S2, S3>(
248
+ mod: (s: S2) => Effect<readonly [S3, A], E, FixEnv<R, W, S2, S3>>
249
+ ): Effect<A, E, FixEnv<R, W, S2, S3>> {
250
+ // return serviceWithEffect(_ => Ref.modifyM_(_.state, mod))
251
+ return castTag<W, S3, S2>().flatMap(
252
+ (_) => mod(_.env.state).map(([s, a]) => Effect.sync(() => _.env.state = s as any).map(() => a))
253
+ ) as any
254
+ }
255
+
256
+ /**
257
+ * @tsplus static Pure.Ops updateWith
258
+ */
259
+ export function update<S2, S3>(upd: (s: S2) => S3) {
260
+ return modify((_: S2) => {
261
+ const r = upd(_)
262
+ return tuple(r, r)
263
+ })
264
+ }
265
+
266
+ export type FixEnv<R, W, S, S2> =
267
+ | Exclude<R, PureEnvEnv<any, any, any>>
268
+ | PureEnvEnv<W, S, S2>
269
+
270
+ /**
271
+ * @tsplus static Pure.Ops updateWithEffect
272
+ */
273
+ export function updateM<W, R, E, S2, S3>(
274
+ upd: (s: S2, log: (evt: W) => PureLogT<W>) => Effect<S3, E, FixEnv<R, W, S2, S3>>
275
+ ): Effect<S3, E, FixEnv<R, W, S2, S3>> {
276
+ return modifyM((_: S2) => upd(_, Pure.log).map((_) => tuple(_, _)))
277
+ }
278
+
279
+ // export function getMA<W, S, A>(self: (s: S) => A): Pure<W, S, never, never, A> {
280
+ // return Effect.accessM((_: PureState<S>) => Ref.get(_.state).map(self))
281
+ // }
282
+
283
+ // /**
284
+ // * @tsplus static Pure.Ops getM
285
+ // */
286
+ // export function getM<W, S, R, E, A>(self: (s: S) => Pure<W, S, R, E, A>): Pure<W, S, R, E, A> {
287
+ // return Effect.accessM((_: PureState<S>) => Ref.get(_.state).flatMap(self))
288
+ // }
289
+
290
+ // export function getTM__<W, S, R, E, A>(self: (s: S) => Pure<W, S, R, E, A>) {
291
+ // return (tag: Tag<PureEnv<W, S>>) => Effect.accessServiceM(tag)(_ => Ref.get(_.state).flatMap(self))
292
+ // }
293
+
294
+ // export function getTM_<W, S, R, E, A>(tag: Tag<PureEnv<W, S>>, self: (s: S) => Pure<W, S, R, E, A>) {
295
+ // return Effect.accessServiceM(tag)(_ => Ref.get(_.state).flatMap(self))
296
+ // }
297
+
298
+ // export function getTM<W, S, R, E, A>(tag: Tag<PureEnv<W, S>>) {
299
+ // const access = Effect.accessServiceM(tag)
300
+ // return (self: (s: S) => Pure<W, S, R, E, A>) => access(_ => Ref.get(_.state).flatMap(self))
301
+ // }
302
+
303
+ /**
304
+ * @tsplus type Pure.Ops
305
+ */
306
+ export interface PureOps {
307
+ // $: PureAspects
308
+ }
309
+
310
+ // /**
311
+ // * @tsplus type Pure.Ops
312
+ // */
313
+
314
+ // export interface PureAspects {}
315
+ export const Pure: PureOps = {
316
+ // $: {}
317
+ }
318
+
319
+ // /**
320
+ // * @tsplus static Pure.Ops makeDSL
321
+ // */
322
+ // export function makeProgramDSL<W, S, S2 = S>(): ProgramDSL<W, S, S2> {
323
+ // return makeDSL_<W,S, S2>()
324
+ // }
325
+
326
+ // function makeDSL_<W, S, S2 = S>() {
327
+ // const tag = tagg as unknown as Tag<PureEnvEnv<W, S, S2>>
328
+ // const get = Effect.serviceWithEffect(tag, _ => _.env.state.get)
329
+ // function getM<R, E, A>(self: (s: S2) => Effect<R, E, A>) { return get.flatMap(self) }
330
+ // function get_<A>(self: (s: S2) => A) { return get.map(self)}
331
+ // function set(s: S2) {
332
+ // return Effect.serviceWithEffect(tag, _ => _.env.state.set(s))
333
+ // }
334
+ // function log<W2>(w: W2): Effect<{
335
+ // env: PureEnv<W | W2, never, never>;
336
+ // }, never, void> {
337
+ // return Effect.serviceWithEffect(tag, _ => _.env.log.update(l => l.append(w as any))) as any
338
+ // }
339
+
340
+ // const baseDSL = {
341
+ // get,
342
+ // log,
343
+ // set
344
+ // }
345
+
346
+ // function modify<A, S3>(mod: (s: S2) => readonly [S3, A]): Effect<{
347
+ // env: PureEnv<W, S, S3>;
348
+ // }, never, A> {
349
+ // return Effect.serviceWithEffect(tag, _ =>
350
+ // _.env.state.get.map(_ => mod(_)).flatMap(([s, a]) => _.env.state.set(s as any ).map(() => a))
351
+ // ) as any
352
+ // }
353
+
354
+ // function modifyM<R, E, A, S3>(mod: (s: S2) => Effect<R, E, readonly [S3, A]>): Effect<{
355
+ // env: PureEnv<W, S, S3>;
356
+ // } | R, E, A> {
357
+ // // return serviceWithEffect(_ => Ref.modifyM_(_.state, mod))
358
+ // return Effect.serviceWithEffect(tag, _ =>
359
+ // _.env.state.get.flatMap(_ => mod(_ as unknown as S2)).flatMap(([s, a]) => _.env.state.set(s as any).map(() => a))
360
+ // ) as any
361
+ // }
362
+
363
+ // function update<S3>(upd: (s: S2) => S3) {
364
+ // return modify(_ => tuple(upd(_), void 0 as void))
365
+ // }
366
+
367
+ // function updateM<R, E, S3>(upd: (s: S2) => Effect<R, E, S3>) {
368
+ // return modifyM(_ => upd(_).map(_ => tuple(_, void 0 as void)))
369
+ // }
370
+
371
+ // const accessLog = Effect.serviceWithEffect(tag, _ => _.env.log.get)
372
+
373
+ // function runAll<R, E, A, W3, S1, S3, S4 extends S1>(
374
+ // self: Effect<FixEnv<R, W3, S1, S3>, E, A>,
375
+ // s: S4
376
+ // ): Effect<Exclude<R, { env: PureEnv<W3, S1, S3>}>, never, readonly [Chunk<W3>, Either.Either<E, readonly [S3, A]>]> {
377
+ // return self.flatMap(x =>
378
+ // Effect.serviceWithEffect(tag, ({ env: _ }) =>
379
+ // Effect.all({ log: _.log.get, state: _.state.get })
380
+ // // Ref.get(_.log).flatMap(log => Ref.get(_.state).map(state => ({ log, state })))
381
+ // ).map(
382
+ // (
383
+ // { log, state }
384
+ // ) => tuple(log, Either.right(tuple(state, x)) as Either.Either<E, readonly [S3, A]>)
385
+ // )
386
+ // ).catchAll(
387
+ // err =>
388
+ // accessLog.map(log =>
389
+ // tuple(log, Either.left(err) as Either.Either<E, readonly [S3, A]>)
390
+ // )
391
+ // ).provideService(tag, { env: makePureEnv<W3, S3, S4>(s) as any }) as any
392
+ // }
393
+
394
+ // function runResult<R, E, A, W3, S1, S3, S4 extends S1>(
395
+ // self: Effect<FixEnv<R, W3, S1, S3>, E, A>,
396
+ // s: S4
397
+ // ) {
398
+ // return runAll(self, s).map(([log, r]) => tuple(log, r.map(([s]) => s)))
399
+ // }
400
+
401
+ // function runA<R, E, A, W3, S1, S3, S4 extends S1>(
402
+ // self: Effect<FixEnv<R, W3, S1, S3>, E, A>,
403
+ // s: S4
404
+ // ) {
405
+ // return runAll(self, s).map(([log, r]) => tuple(log, r.map(([, a]) => a)))
406
+ // }
407
+
408
+ // return {
409
+ // ...baseDSL,
410
+
411
+ // getM,
412
+ // get_,
413
+ // accessLog,
414
+ // runAll,
415
+ // runA,
416
+ // runResult,
417
+
418
+ // modify,
419
+ // modifyM,
420
+ // update,
421
+ // updateM
422
+ // }
423
+ // }
424
+
425
+ // type dsl_<W,S, S2 = S> = ReturnType<typeof makeDSL_<W, S, S2>>
426
+
427
+ // /**
428
+ // * @tsplus type Pure/DSL
429
+ // */
430
+ // export interface ProgramDSL<W, S, S2 = S> extends dsl_<W, S, S2> { }
431
+
432
+ // /**
433
+ // * @tsplus fluent Pure/DSL modifyWithEffect
434
+ // */
435
+ // export function dslmodifyM<W, S, R, E, A>(dsl: ProgramDSL<W, S>, mod: (s: S, dsl: ProgramDSL<W, S>) => Effect<R, E, readonly [S, A]>) {
436
+ // return dsl.modifyM(_ => mod(_, dsl))
437
+ // }
438
+
439
+ // /**
440
+ // * @tsplus fluent Pure/DSL modifyWith
441
+ // */
442
+ // export function dslmodify<W, S, A>(dsl: ProgramDSL<W, S>, mod: (s: S, dsl: ProgramDSL<W, S>) => readonly [S, A]) {
443
+ // return dsl.modify(_ => mod(_, dsl))
444
+ // }
445
+
446
+ // /**
447
+ // * @tsplus fluent Pure/DSL updateWithEffect
448
+ // */
449
+ // export function dslupdateM<W, S, R, E, S2, S3>(dsl: ProgramDSL<W, S, S2>, upd: (s: S2, dsl: ProgramDSL<W, S, S2>) => Effect<R, E, S3>) {
450
+ // return dsl.updateM(_ => upd(_, dsl))
451
+ // }
452
+
453
+ // /**
454
+ // * @tsplus fluent Pure/DSL updateWith
455
+ // */
456
+ // export function dslupdate<W, S>(dsl: ProgramDSL<W, S>, upd: (s: S, dsl: ProgramDSL<W, S>) => S) {
457
+ // return dsl.update(_ => upd(_, dsl))
458
+ // }
459
+
460
+ // export interface ZPure<out W, in S1, out S2, in R, out E, out A> {}
461
+
462
+ // export class ZPureImpl<out W, in S1, out S2, in R, out E, out A> implements ZPure<W, S1, S2, R, E, A> {
463
+ // zipRight<W1, S3, R1, E1, B>(
464
+ // f: ZPure<W1, S2, S3, R1, E1, B>
465
+ // ): ZPure<W1 | W, S1, S3, R1 | R, E | E1, B> {
466
+ // throw new Error("not implemented")
467
+ // }
468
+
469
+ // flatMap<W1, S3, R1, E1, B>(
470
+ // f: (a: A) => ZPure<W1, S2, S3, R1, E1, B>
471
+ // ): ZPure<W1 | W, S1, S3, R1 | R, E | E1, B> {
472
+ // throw new Error("not implemented")
473
+
474
+ // }
475
+ // }
476
+
477
+ // declare type Eff1 = Effect<PureEnv2<string, PrintingPickItem, PickItem>, never, void>
478
+
479
+ // function flatMap<R, R2, E, E2, A, A2, W, S, S2>(self: Effect<R| PureEnv2<W, S, S2>, E, A>, (s: S) => Effect<R2 | PureEnv2>) {
480
+ // }
481
+
482
+ // export interface PureEnv2<W, S, S2> extends PureState2<S, S2>, PureLog<W> {}
483
+
484
+ // const S1 = Symbol()
485
+ // const S2 = Symbol()
486
+ // const W = Symbol()
487
+ // export interface PureState2<S, S2> {
488
+ // readonly [S1]: () => S
489
+ // readonly [S2]: () => S2
490
+
491
+ // readonly state: Ref<S>
492
+ // }
493
+
494
+ // const abc = Do($ => {
495
+ // const s = $(Pure.get<{ a: 1 }>())
496
+ // console.log(s)
497
+ // // const a = $(Pure.log("hello"))
498
+ // $(Pure.log("hallo" as const))
499
+ // $(Pure.log("hello" as const))
500
+ // $(Pure.log<"hallo" | "hello" | 5>(5))
501
+ // })
502
+
503
+ // declare const a: Effect<
504
+ // | {
505
+ // env: PureEnv<never, never, {
506
+ // a: 1
507
+ // }>
508
+ // }
509
+ // | { env: PureEnv<string, never, never> }
510
+ // | { env: PureEnv<number, never, never> },
511
+ // never,
512
+ // never
513
+ // >
514
+ // type R = _R<typeof a>
515
+ // type Env<T> = T extends { env: infer rr } ? rr : never
516
+
517
+ // type RRRR = Env<R>
518
+
519
+ // const abcc = unifyPureEnv(
520
+ // undefined as any as RRRR
521
+ // )
522
+ // const test = Pure.runAll(
523
+ // abc,
524
+ // { a: 1 }
525
+ // )
@@ -0,0 +1,106 @@
1
+ // @ts-expect-error wtf
2
+ import { HttpClientError } from "@effect/platform/Http/ClientError"
3
+ import type { ClientResponse } from "@effect/platform/Http/ClientResponse"
4
+ import type { Headers } from "@effect/platform/Http/Headers"
5
+
6
+ // there are issues with global imports with "as", so we re export here
7
+ export { Client as HttpClient } from "@effect/platform/Http/Client"
8
+ export { Cache as EffectCache } from "effect/Cache"
9
+ export { Request as EffectRequest } from "effect/Request"
10
+
11
+ export interface ResponseWithBody<A> extends Pick<ClientResponse, "headers" | "status" | "remoteAddress"> {
12
+ readonly body: A
13
+ }
14
+
15
+ // TODO: consider rebuilding the text/json helpers to use a cached effect
16
+ // https://discord.com/channels/795981131316985866/1098177242598756412/1168565257569046712
17
+
18
+ /**
19
+ * @tsplus getter effect/platform/Http/ClientResponse responseWithJsonBody
20
+ */
21
+ export const responseWithJsonBody = (
22
+ response: ClientResponse
23
+ ) =>
24
+ response.json.map((body): ResponseWithBody<unknown> => ({
25
+ body,
26
+ headers: response.headers,
27
+ status: response.status,
28
+ remoteAddress: response.remoteAddress
29
+ }))
30
+
31
+ /**
32
+ * @tsplus fluent effect/platform/Http/Client schemaJsonBody
33
+ */
34
+ export const schemaJsonBody = <R, To, From, A, B>(
35
+ client: HttpClient<A, B, ClientResponse>,
36
+ schema: Schema<To, From, R>
37
+ ) => {
38
+ return client.mapEffect((_) => _.json.flatMap(schema.decodeUnknown))
39
+ }
40
+
41
+ /**
42
+ * @tsplus fluent effect/platform/Http/Client schemaJsonBodyUnsafe
43
+ */
44
+ export const schemaJsonBodyUnsafe = <To, From, A, B>(
45
+ client: HttpClient<A, B, ClientResponse>,
46
+ schema: Schema<To, From>
47
+ ) => {
48
+ return client.mapEffect((_) => _.json.map(schema.decodeUnknownSync))
49
+ }
50
+
51
+ /**
52
+ * @tsplus fluent effect/platform/Http/Client schemaJson
53
+ */
54
+ export const schemaJson = <
55
+ R,
56
+ From extends {
57
+ readonly status?: number
58
+ readonly headers?: Headers
59
+ readonly body?: unknown
60
+ },
61
+ To,
62
+ A,
63
+ B
64
+ >(
65
+ client: HttpClient<A, B, ClientResponse>,
66
+ schema: Schema<To, From, R>
67
+ ) => {
68
+ return client.mapEffect((_) => _.responseWithJsonBody.flatMap(schema.decodeUnknown))
69
+ }
70
+
71
+ /**
72
+ * @tsplus fluent effect/platform/Http/Client schemaJsonUnsafe
73
+ */
74
+ export const schemaJsonUnsafe = <
75
+ R,
76
+ From extends {
77
+ readonly status?: number
78
+ readonly headers?: Headers
79
+ readonly body?: unknown
80
+ },
81
+ To,
82
+ A,
83
+ B
84
+ >(
85
+ client: HttpClient<A, B, ClientResponse>,
86
+ schema: Schema<To, From, R>
87
+ ) => {
88
+ return client.mapEffect((_) => _.responseWithJsonBody.flatMap(schema.decodeUnknown))
89
+ }
90
+
91
+ /** @tsplus getter effect/platform/Http/Client demandJson */
92
+ export const demandJson = <R, E>(client: HttpClient<R, E, ClientResponse>) =>
93
+ client
94
+ .mapRequest((_) => _.acceptJson)
95
+ .transform((r, request) =>
96
+ r.tap((response) =>
97
+ response.headers.get("Content-Type").value?.startsWith("application/json")
98
+ ? Effect.unit
99
+ : Effect.fail(HttpClientError.ResponseError({
100
+ request,
101
+ response,
102
+ reason: "Decode",
103
+ error: "not json response: " + response.headers.get("Content-Type").value
104
+ }))
105
+ )
106
+ )
@@ -0,0 +1,28 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import type { BuiltInObject } from "@effect-app/core/utils"
3
+
4
+ type AllKeys<T> = T extends any ? keyof T : never
5
+
6
+ type OptionalKeys<T> = T extends any // eslint-disable-next-line @typescript-eslint/ban-types
7
+ ? { [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T]
8
+ : never
9
+
10
+ type Idx<T, K extends PropertyKey, D = never> = T extends any ? K extends keyof T ? T[K]
11
+ : D
12
+ : never
13
+
14
+ type PartialKeys<T, K extends keyof T> =
15
+ & Omit<T, K>
16
+ & Partial<Pick<T, K>> extends infer O ? { [P in keyof O]: O[P] }
17
+ : never
18
+
19
+ export type Primitive = boolean | string | number | bigint | symbol | undefined | null
20
+ export type Widen<T> = [T] extends [BuiltInObject] | [Primitive] ? T
21
+ : [T] extends [Array<unknown>] ? { [K in keyof T]: Widen<T[K]> }
22
+ : [T] extends [ReadonlyArray<unknown>] ? { [K in keyof T]: Widen<T[K]> }
23
+ // eslint-disable-next-line @typescript-eslint/ban-types
24
+ : [T] extends [object] ? PartialKeys<
25
+ { [K in AllKeys<T>]: Widen<Idx<T, K>> },
26
+ Exclude<AllKeys<T>, keyof T> | OptionalKeys<T>
27
+ >
28
+ : T