effect-app 3.15.1 → 4.0.0-beta.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.
- package/CHANGELOG.md +12 -0
- package/dist/Array.js +1 -1
- package/dist/Chunk.d.ts +2 -4
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +2 -2
- package/dist/Config/SecretURL.d.ts +2 -12
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -4
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +3 -4
- package/dist/Effect.d.ts +12 -10
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +6 -15
- package/dist/Layer.d.ts +15 -9
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +2 -2
- package/dist/Operations.d.ts +37 -47
- package/dist/Operations.d.ts.map +1 -1
- package/dist/Option.js +3 -3
- package/dist/Pure.d.ts +17 -6
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +35 -17
- package/dist/Schema/Class.d.ts +13 -16
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +5 -27
- package/dist/Schema/brand.d.ts +7 -10
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -2
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +2 -2
- package/dist/Schema/ext.d.ts +42 -45
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +49 -63
- package/dist/Schema/moreStrings.d.ts +17 -17
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +10 -10
- package/dist/Schema/numbers.d.ts +14 -14
- package/dist/Schema/numbers.js +5 -5
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +2 -2
- package/dist/Schema/schema.d.ts +2 -3
- package/dist/Schema/schema.d.ts.map +1 -1
- package/dist/Schema/schema.js +3 -4
- package/dist/Schema/strings.d.ts +4 -4
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +4 -4
- package/dist/Schema.d.ts +27 -25
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +22 -21
- package/dist/ServiceMap.d.ts +44 -0
- package/dist/ServiceMap.d.ts.map +1 -0
- package/dist/ServiceMap.js +91 -0
- package/dist/Set.d.ts +4 -4
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +14 -14
- package/dist/Struct.d.ts +4 -4
- package/dist/Struct.d.ts.map +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -4
- package/dist/_ext/misc.d.ts +2 -2
- package/dist/_ext/misc.js +4 -4
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/builtin.d.ts +0 -8
- package/dist/builtin.d.ts.map +1 -1
- package/dist/builtin.js +3 -1
- package/dist/client/apiClientFactory.d.ts +14 -16
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +38 -23
- package/dist/client/clientFor.d.ts +7 -4
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/errors.d.ts +36 -48
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +19 -9
- package/dist/client/makeClient.d.ts +34 -50
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +28 -18
- package/dist/http/Request.d.ts +3 -3
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +5 -8
- package/dist/http/internal/lib.d.ts +12 -13
- package/dist/http/internal/lib.d.ts.map +1 -1
- package/dist/http/internal/lib.js +14 -14
- package/dist/ids.d.ts +9 -9
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +3 -3
- package/dist/rpc/MiddlewareMaker.d.ts +17 -16
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +27 -18
- package/dist/rpc/RpcContextMap.d.ts +4 -4
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +24 -40
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +3 -10
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/gen.d.ts +4 -5
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +1 -1
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logLevel.js +6 -7
- package/dist/utils/logger.d.ts +4 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +10 -9
- package/dist/utils.d.ts +4 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -9
- package/package.json +16 -25
- package/src/Array.ts +1 -1
- package/src/Chunk.ts +2 -2
- package/src/Config/SecretURL.ts +3 -18
- package/src/Config/internal/configSecretURL.ts +2 -3
- package/src/Effect.ts +17 -37
- package/src/Layer.ts +16 -11
- package/src/Option.ts +2 -2
- package/src/Pure.ts +60 -26
- package/src/Schema/Class.ts +17 -73
- package/src/Schema/brand.ts +11 -12
- package/src/Schema/email.ts +2 -2
- package/src/Schema/ext.ts +114 -167
- package/src/Schema/moreStrings.ts +20 -23
- package/src/Schema/numbers.ts +4 -4
- package/src/Schema/phoneNumber.ts +2 -2
- package/src/Schema/schema.ts +2 -3
- package/src/Schema/strings.ts +3 -3
- package/src/Schema.ts +49 -47
- package/src/ServiceMap.ts +187 -0
- package/src/Set.ts +19 -19
- package/src/Struct.ts +4 -4
- package/src/_ext/Array.ts +4 -5
- package/src/_ext/misc.ts +4 -4
- package/src/_ext/ord.ext.ts +2 -2
- package/src/builtin.ts +2 -8
- package/src/client/apiClientFactory.ts +74 -59
- package/src/client/clientFor.ts +10 -7
- package/src/client/errors.ts +28 -22
- package/src/client/makeClient.ts +75 -100
- package/src/http/Request.ts +5 -8
- package/src/http/internal/lib.ts +13 -13
- package/src/ids.ts +1 -1
- package/src/index.ts +10 -1
- package/src/middleware.ts +2 -2
- package/src/rpc/MiddlewareMaker.ts +76 -47
- package/src/rpc/RpcContextMap.ts +7 -7
- package/src/rpc/RpcMiddleware.ts +28 -54
- package/src/utils/effectify.ts +1 -1
- package/src/utils/gen.ts +8 -6
- package/src/utils/logLevel.ts +6 -6
- package/src/utils/logger.ts +15 -20
- package/src/utils.ts +12 -12
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/schema.test.ts +8 -8
- package/test/utils.test.ts +2 -2
- package/tsconfig.json +1 -25
- package/dist/Context.d.ts +0 -67
- package/dist/Context.d.ts.map +0 -1
- package/dist/Context.js +0 -207
- package/dist/Tag.d.ts +0 -6
- package/dist/Tag.d.ts.map +0 -1
- package/dist/Tag.js +0 -9
- package/dist/Unify.d.ts +0 -27
- package/dist/Unify.d.ts.map +0 -1
- package/dist/Unify.js +0 -15
- package/src/Context.ts +0 -351
- package/src/Tag.ts +0 -11
- package/src/Unify.ts +0 -40
package/src/Context.ts
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
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 { Effect, Layer, type Scope } from "effect"
|
|
9
|
-
import { type NonEmptyReadonlyArray } from "effect/Array"
|
|
10
|
-
import * as Context from "effect/Context"
|
|
11
|
-
import { type Service } from "effect/Effect"
|
|
12
|
-
|
|
13
|
-
export * from "effect/Context"
|
|
14
|
-
|
|
15
|
-
export const ServiceTag = Symbol()
|
|
16
|
-
export type ServiceTag = typeof ServiceTag
|
|
17
|
-
|
|
18
|
-
export abstract class PhantomTypeParameter<Identifier extends keyof any, InstantiatedType> {
|
|
19
|
-
protected abstract readonly [ServiceTag]: {
|
|
20
|
-
readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type ServiceShape<T extends Context.TagClassShape<any, any>> = Omit<
|
|
25
|
-
T,
|
|
26
|
-
keyof Context.TagClassShape<any, any>
|
|
27
|
-
>
|
|
28
|
-
|
|
29
|
-
export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
|
|
30
|
-
|
|
31
|
-
export function makeService<T extends ServiceTagged<any>>(_: Omit<T, ServiceTag>) {
|
|
32
|
-
return _ as T
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let i = 0
|
|
36
|
-
const randomId = () => "unknown-service-" + i++
|
|
37
|
-
|
|
38
|
-
export function assignTag<Id, Service = Id>(key?: string, creationError?: Error) {
|
|
39
|
-
return <S extends object>(cls: S): S & Context.Tag<Id, Service> => {
|
|
40
|
-
const tag = Context.GenericTag<Id, Service>(key ?? randomId())
|
|
41
|
-
let fields = tag
|
|
42
|
-
if (Reflect.ownKeys(cls).includes("key")) {
|
|
43
|
-
const { key, ...rest } = tag
|
|
44
|
-
fields = rest as any
|
|
45
|
-
}
|
|
46
|
-
const t = Object.assign(cls, Object.getPrototypeOf(tag), fields)
|
|
47
|
-
if (!creationError) {
|
|
48
|
-
const limit = Error.stackTraceLimit
|
|
49
|
-
Error.stackTraceLimit = 2
|
|
50
|
-
creationError = new Error()
|
|
51
|
-
Error.stackTraceLimit = limit
|
|
52
|
-
}
|
|
53
|
-
// the stack is used to get the location of the tag definition, if a service is not found in the registry
|
|
54
|
-
Object.defineProperty(t, "stack", {
|
|
55
|
-
get() {
|
|
56
|
-
return creationError!.stack
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
return t
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type ServiceUse<Self, Type> = {
|
|
64
|
-
use: <X>(
|
|
65
|
-
body: (_: Type) => X
|
|
66
|
-
) => X extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, R | Self>
|
|
67
|
-
: Effect.Effect<X, never, Self>
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type ServiceAcessorShape<Self, Type> =
|
|
71
|
-
& (Type extends Record<PropertyKey, any> ? {
|
|
72
|
-
[
|
|
73
|
-
k in keyof Type as Type[k] extends ((...args: [...infer Args]) => infer Ret)
|
|
74
|
-
? ((...args: Readonly<Args>) => Ret) extends Type[k] ? k : never
|
|
75
|
-
: k
|
|
76
|
-
]: Type[k] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
|
|
77
|
-
? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
|
|
78
|
-
: Type[k] extends (...args: [...infer Args]) => infer A
|
|
79
|
-
? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
|
|
80
|
-
: Type[k] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
|
|
81
|
-
: Effect.Effect<Type[k], never, Self>
|
|
82
|
-
}
|
|
83
|
-
: {})
|
|
84
|
-
& ServiceUse<Self, Type>
|
|
85
|
-
|
|
86
|
-
export const useify = <T extends Context.Tag<any, any>>(Tag: T) => <Self, Shape>(): T & ServiceUse<Self, Shape> => {
|
|
87
|
-
return Object.assign(Tag, { use: (body: any) => Effect.andThen(Tag, body) } as ServiceUse<Self, Shape>)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const proxify = <T extends object>(Tag: T) =>
|
|
91
|
-
<Self, Shape>():
|
|
92
|
-
& T
|
|
93
|
-
& ServiceAcessorShape<Self, Shape> =>
|
|
94
|
-
{
|
|
95
|
-
const cache = new Map()
|
|
96
|
-
const done = new Proxy(Tag, {
|
|
97
|
-
get(_target: any, prop: any, _receiver) {
|
|
98
|
-
if (prop === "use") {
|
|
99
|
-
// @ts-expect-error abc
|
|
100
|
-
return (body) => Effect.andThen(Tag, body)
|
|
101
|
-
}
|
|
102
|
-
if (prop in Tag) {
|
|
103
|
-
return (Tag as any)[prop]
|
|
104
|
-
}
|
|
105
|
-
if (cache.has(prop)) {
|
|
106
|
-
return cache.get(prop)
|
|
107
|
-
}
|
|
108
|
-
const fn = (...args: Array<any>) => Effect.andThen(Tag as any, (s: any) => s[prop](...args))
|
|
109
|
-
// @ts-expect-error abc
|
|
110
|
-
const cn = Effect.andThen(Tag, (s) => s[prop])
|
|
111
|
-
// @effect-diagnostics effect/floatingEffect:off
|
|
112
|
-
Object.assign(fn, cn)
|
|
113
|
-
Object.setPrototypeOf(fn, Object.getPrototypeOf(cn))
|
|
114
|
-
cache.set(prop, fn)
|
|
115
|
-
return fn
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
return done
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// export const TagMake = <ServiceImpl, R, E, const Key extends string>(
|
|
122
|
-
// key: Key,
|
|
123
|
-
// make: Effect.Effect<ServiceImpl, E, R>
|
|
124
|
-
// ) =>
|
|
125
|
-
// <Id>() => {
|
|
126
|
-
// const limit = Error.stackTraceLimit
|
|
127
|
-
// Error.stackTraceLimit = 2
|
|
128
|
-
// const creationError = new Error()
|
|
129
|
-
// Error.stackTraceLimit = limit
|
|
130
|
-
// const c: {
|
|
131
|
-
// new(): Context.TagClassShape<Key, ServiceImpl>
|
|
132
|
-
// toLayer: () => Layer<Id, E, R>
|
|
133
|
-
// toLayerScoped: () => Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
134
|
-
// } = class {
|
|
135
|
-
// static toLayer = () => {
|
|
136
|
-
// return Layer.effect(this as any, make)
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
// static toLayerScoped = () => {
|
|
140
|
-
// return Layer.scoped(this as any, make)
|
|
141
|
-
// }
|
|
142
|
-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
-
// } as any
|
|
144
|
-
|
|
145
|
-
// return proxify(assignTag<Id, ServiceImpl>(key, creationError)(c))<Id, ServiceImpl>()
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
// export function Tag<Id, ServiceImpl, Service = Id>(key?: string) {
|
|
149
|
-
// const limit = Error.stackTraceLimit
|
|
150
|
-
// Error.stackTraceLimit = 2
|
|
151
|
-
// const creationError = new Error()
|
|
152
|
-
// Error.stackTraceLimit = limit
|
|
153
|
-
// const c: (abstract new(impl: ServiceImpl) => Readonly<ServiceImpl>) & {
|
|
154
|
-
// toLayer: <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => Layer<Id, E, R>
|
|
155
|
-
// toLayerScoped: <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
156
|
-
// } = class {
|
|
157
|
-
// constructor(service: ServiceImpl) {
|
|
158
|
-
// Object.assign(this, service)
|
|
159
|
-
// }
|
|
160
|
-
// static _key?: string
|
|
161
|
-
// static toLayer = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
162
|
-
// return Layer.effect(this as any, eff)
|
|
163
|
-
// }
|
|
164
|
-
// static toLayerScoped = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
165
|
-
// return Layer.scoped(this as any, eff)
|
|
166
|
-
// }
|
|
167
|
-
// static get key() {
|
|
168
|
-
// return this._key ?? (this._key = key ?? creationError.stack?.split("\n")[2] ?? this.name)
|
|
169
|
-
// }
|
|
170
|
-
// } as any
|
|
171
|
-
|
|
172
|
-
// return proxify(assignTag<Id, Service>(key, creationError)(c))<Id, ServiceImpl>()
|
|
173
|
-
// }
|
|
174
|
-
|
|
175
|
-
// export const TagMake = <ServiceImpl, R, E>(
|
|
176
|
-
// make: Effect.Effect<ServiceImpl, E, R>,
|
|
177
|
-
// key?: string
|
|
178
|
-
// ) =>
|
|
179
|
-
// <Id, Service = Id>() => {
|
|
180
|
-
// const limit = Error.stackTraceLimit
|
|
181
|
-
// Error.stackTraceLimit = 2
|
|
182
|
-
// const creationError = new Error()
|
|
183
|
-
// Error.stackTraceLimit = limit
|
|
184
|
-
// const c: (abstract new(impl: ServiceImpl) => Readonly<ServiceImpl>) & {
|
|
185
|
-
// toLayer: { (): Layer<Id, E, R>; <E, R>(eff: Effect.Effect<ServiceImpl, E, R>): Layer<Id, E, R> }
|
|
186
|
-
// toLayerScoped: {
|
|
187
|
-
// (): Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
188
|
-
// <E, R>(eff: Effect.Effect<ServiceImpl, E, R>): Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
189
|
-
// }
|
|
190
|
-
// make: Effect.Effect<Id, E, R>
|
|
191
|
-
// } = class {
|
|
192
|
-
// constructor(service: ServiceImpl) {
|
|
193
|
-
// Object.assign(this, service)
|
|
194
|
-
// }
|
|
195
|
-
// static _key: string
|
|
196
|
-
// static make = make
|
|
197
|
-
// // works around an issue where defining layer on the class messes up and causes the Tag to infer to `any, any` :/
|
|
198
|
-
// static toLayer = (arg?: any) => {
|
|
199
|
-
// return Layer.effect(this as any, arg ?? this.make)
|
|
200
|
-
// }
|
|
201
|
-
|
|
202
|
-
// static toLayerScoped = (arg?: any) => {
|
|
203
|
-
// return Layer.scoped(this as any, arg ?? this.make)
|
|
204
|
-
// }
|
|
205
|
-
|
|
206
|
-
// static get key() {
|
|
207
|
-
// return this._key ?? (this._key = key ?? creationError.stack?.split("\n")[2] ?? this.name)
|
|
208
|
-
// }
|
|
209
|
-
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
-
// } as any
|
|
211
|
-
|
|
212
|
-
// return proxify(assignTag<Id, Service>(key, creationError)(c))<Id, ServiceImpl>()
|
|
213
|
-
// }
|
|
214
|
-
|
|
215
|
-
export function TagId<const Key extends string>(key: Key) {
|
|
216
|
-
return <Id, ServiceImpl>() => {
|
|
217
|
-
const limit = Error.stackTraceLimit
|
|
218
|
-
Error.stackTraceLimit = 2
|
|
219
|
-
const creationError = new Error()
|
|
220
|
-
Error.stackTraceLimit = limit
|
|
221
|
-
const c:
|
|
222
|
-
& (abstract new(
|
|
223
|
-
service: ServiceImpl
|
|
224
|
-
) => Readonly<ServiceImpl> & Context.TagClassShape<Key, ServiceImpl>)
|
|
225
|
-
& {
|
|
226
|
-
toLayer: <E, R>(
|
|
227
|
-
eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>
|
|
228
|
-
) => Layer.Layer<Id, E, R>
|
|
229
|
-
toLayerScoped: <E, R>(
|
|
230
|
-
eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>
|
|
231
|
-
) => Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
232
|
-
of: (service: Omit<Id, keyof Context.TagClassShape<any, any>>) => Id
|
|
233
|
-
} = class {
|
|
234
|
-
constructor(service: any) {
|
|
235
|
-
// TODO: instead, wrap the service, and direct calls?
|
|
236
|
-
Object.assign(this, service)
|
|
237
|
-
}
|
|
238
|
-
static of = (service: ServiceImpl) => service
|
|
239
|
-
static toLayer = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
240
|
-
return Layer.effect(this as any, eff)
|
|
241
|
-
}
|
|
242
|
-
static toLayerScoped = <E, R>(eff: Effect.Effect<ServiceImpl, E, R>) => {
|
|
243
|
-
return Layer.scoped(this as any, eff)
|
|
244
|
-
}
|
|
245
|
-
} as any
|
|
246
|
-
|
|
247
|
-
return useify(assignTag<Id, Id>(key, creationError)(c))<Id, ServiceImpl>()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export const TagMakeId = <ServiceImpl, R, E, const Key extends string>(
|
|
252
|
-
key: Key,
|
|
253
|
-
make: Effect.Effect<ServiceImpl, E, R>
|
|
254
|
-
) =>
|
|
255
|
-
<Id>() => {
|
|
256
|
-
const limit = Error.stackTraceLimit
|
|
257
|
-
Error.stackTraceLimit = 2
|
|
258
|
-
const creationError = new Error()
|
|
259
|
-
Error.stackTraceLimit = limit
|
|
260
|
-
const c:
|
|
261
|
-
& (abstract new(
|
|
262
|
-
service: ServiceImpl
|
|
263
|
-
) => Readonly<ServiceImpl> & Context.TagClassShape<Key, ServiceImpl>)
|
|
264
|
-
& {
|
|
265
|
-
toLayer: {
|
|
266
|
-
(): Layer.Layer<Id, E, R>
|
|
267
|
-
<E, R>(eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>): Layer.Layer<Id, E, R>
|
|
268
|
-
}
|
|
269
|
-
toLayerScoped: {
|
|
270
|
-
(): Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
271
|
-
<E, R>(
|
|
272
|
-
eff: Effect.Effect<Omit<Id, keyof Context.TagClassShape<any, any>>, E, R>
|
|
273
|
-
): Layer.Layer<Id, E, Exclude<R, Scope.Scope>>
|
|
274
|
-
}
|
|
275
|
-
of: (service: Context.TagClassShape<any, any>) => Id
|
|
276
|
-
make: Effect.Effect<Id, E, R>
|
|
277
|
-
} = class {
|
|
278
|
-
constructor(service: any) {
|
|
279
|
-
// TODO: instead, wrap the service, and direct calls?
|
|
280
|
-
Object.assign(this, service)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
static of = (service: ServiceImpl) => service
|
|
284
|
-
static make = make
|
|
285
|
-
// works around an issue where defining layer on the class messes up and causes the Tag to infer to `any, any` :/
|
|
286
|
-
static toLayer = (arg?: any) => {
|
|
287
|
-
return Layer.effect(this as any, arg ?? this.make)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
static toLayerScoped = (arg?: any) => {
|
|
291
|
-
return Layer.scoped(this as any, arg ?? this.make)
|
|
292
|
-
}
|
|
293
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
294
|
-
} as any
|
|
295
|
-
|
|
296
|
-
return useify(assignTag<Id, Id>(key, creationError)(c))<Id, ServiceImpl>()
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export const ServiceDef = <Tag extends Context.Tag<any, any>>(self: Tag) =>
|
|
300
|
-
<A>() =>
|
|
301
|
-
<
|
|
302
|
-
LayerOpts extends {
|
|
303
|
-
effect: Effect.Effect<
|
|
304
|
-
A,
|
|
305
|
-
any,
|
|
306
|
-
any
|
|
307
|
-
>
|
|
308
|
-
dependencies?: NonEmptyReadonlyArray<Layer.Layer.Any>
|
|
309
|
-
}
|
|
310
|
-
>(opts: LayerOpts): Layer.Layer<
|
|
311
|
-
Tag,
|
|
312
|
-
| (LayerOpts extends { effect: Effect.Effect<infer _A, infer _E, infer _R> } ? _E
|
|
313
|
-
: never)
|
|
314
|
-
| Service.MakeDepsE<LayerOpts>,
|
|
315
|
-
| Exclude<
|
|
316
|
-
LayerOpts extends { effect: Effect.Effect<infer _A, infer _E, infer _R> } ? _R : never,
|
|
317
|
-
Service.MakeDepsOut<LayerOpts>
|
|
318
|
-
>
|
|
319
|
-
| Service.MakeDepsIn<LayerOpts>
|
|
320
|
-
> =>
|
|
321
|
-
Layer.scoped(self, opts.effect as any).pipe(
|
|
322
|
-
Layer.provide([Layer.empty, ...opts.dependencies ?? []])
|
|
323
|
-
) as any
|
|
324
|
-
|
|
325
|
-
/** @deprecated; use `static Default = Layer.make(this, { effect, dependencies })` instead */
|
|
326
|
-
export const DefineService = <
|
|
327
|
-
Tag extends Context.TagClass<any, any, any>,
|
|
328
|
-
LayerOpts extends {
|
|
329
|
-
effect: Effect.Effect<
|
|
330
|
-
Context.Tag.Service<Tag>,
|
|
331
|
-
any,
|
|
332
|
-
any
|
|
333
|
-
>
|
|
334
|
-
dependencies?: NonEmptyReadonlyArray<Layer.Layer.Any>
|
|
335
|
-
}
|
|
336
|
-
>(tag: Tag, opts: LayerOpts): Tag & {
|
|
337
|
-
Default: Layer.Layer<
|
|
338
|
-
Context.Tag.Identifier<Tag>,
|
|
339
|
-
| (LayerOpts extends { effect: Effect.Effect<infer _A, infer _E, infer _R> } ? _E
|
|
340
|
-
: never)
|
|
341
|
-
| Service.MakeDepsE<LayerOpts>,
|
|
342
|
-
| Exclude<
|
|
343
|
-
LayerOpts extends { effect: Effect.Effect<infer _A, infer _E, infer _R> } ? _R : never,
|
|
344
|
-
Service.MakeDepsOut<LayerOpts>
|
|
345
|
-
>
|
|
346
|
-
| Service.MakeDepsIn<LayerOpts>
|
|
347
|
-
>
|
|
348
|
-
} =>
|
|
349
|
-
class extends (tag as any) {
|
|
350
|
-
static readonly Default = ServiceDef<Tag>(tag)<Context.Tag.Service<Tag>>()(opts)
|
|
351
|
-
} as any
|
package/src/Tag.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// export function accessM_<T, I, R, E, A>(self: Tag<T, I>, f: (x: T) => Effect.Effect<R, E, A>) {
|
|
2
|
-
// return Effect.serviceWithEffect(self)(f)
|
|
3
|
-
// }
|
|
4
|
-
|
|
5
|
-
import { Layer } from "effect"
|
|
6
|
-
|
|
7
|
-
// export function access_<T, I, B>(self: Tag<T, I>, f: (x: T) => B) {
|
|
8
|
-
// return Effect.serviceWith(self)(f)
|
|
9
|
-
// }
|
|
10
|
-
|
|
11
|
-
export const makeLayer = Layer.succeed
|
package/src/Unify.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
// TODO: Add effect cause/exit etc
|
|
3
|
-
|
|
4
|
-
import type { Chunk, Either, Option } from "effect"
|
|
5
|
-
import type { Effect, EffectTypeId } from "effect/Effect"
|
|
6
|
-
|
|
7
|
-
export function unifyEffect<X extends { readonly [EffectTypeId]: Effect.VarianceStruct<any, any, any> }>(
|
|
8
|
-
self: X
|
|
9
|
-
): Effect<
|
|
10
|
-
[X] extends [{ readonly [EffectTypeId]: { _A: (_: never) => infer A } }] ? A : never,
|
|
11
|
-
[X] extends [{ readonly [EffectTypeId]: { _E: (_: never) => infer E } }] ? E : never,
|
|
12
|
-
[X] extends [{ readonly [EffectTypeId]: { _R: (_: never) => infer R } }] ? R : never
|
|
13
|
-
> {
|
|
14
|
-
return self as any
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function unifyChunk<X extends Chunk.Chunk<any>>(
|
|
18
|
-
self: X
|
|
19
|
-
): Chunk.Chunk<[X] extends [Chunk.Chunk<infer A>] ? A : never> {
|
|
20
|
-
return self
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function unifyEither<X extends Either.Either<any, any>>(
|
|
24
|
-
self: X
|
|
25
|
-
): Either.Either<
|
|
26
|
-
X extends Either.Right<any, infer AX> ? AX : X extends Either.Left<any, infer AX> ? AX : never,
|
|
27
|
-
X extends Either.Left<infer EX, any> ? EX : X extends Either.Right<infer EX, any> ? EX : never
|
|
28
|
-
> {
|
|
29
|
-
return self
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function unifyOption<X extends Option.Option<any>>(
|
|
33
|
-
self: X
|
|
34
|
-
): Option.Option<
|
|
35
|
-
X extends Option.Some<infer A> ? A
|
|
36
|
-
: X extends Option.None<infer A> ? A
|
|
37
|
-
: never
|
|
38
|
-
> {
|
|
39
|
-
return self
|
|
40
|
-
}
|