effect-app 3.16.0 → 4.0.0-beta.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/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 +12 -21
- 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 -27
- 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/Pure.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Chunk, Effect,
|
|
3
|
-
import * as Context from "./Context.js"
|
|
2
|
+
import { Chunk, Effect, Layer, Result } from "effect"
|
|
4
3
|
import { tuple } from "./Function.js"
|
|
4
|
+
import * as ServiceMap from "./ServiceMap.js"
|
|
5
5
|
|
|
6
6
|
const S1 = Symbol()
|
|
7
7
|
const S2 = Symbol()
|
|
@@ -86,54 +86,81 @@ export function GMU<W, S, S2, GA, MR, ME>(modify: (i: GA) => Pure<W, S, S2, MR,
|
|
|
86
86
|
) => GMU_(get, modify, update)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const tagg =
|
|
89
|
+
const tagg = ServiceMap.Service<{ env: PureEnv<never, unknown, never> }>("PureEnv")
|
|
90
90
|
function castTag<W, S, S2>() {
|
|
91
|
-
return tagg as any as
|
|
91
|
+
return tagg as any as ServiceMap.Service<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const ServiceTag = Symbol()
|
|
95
|
+
export type ServiceTag = typeof ServiceTag
|
|
96
|
+
|
|
97
|
+
export abstract class PhantomTypeParameter<Identifier extends keyof any, InstantiatedType> {
|
|
98
|
+
protected abstract readonly [ServiceTag]: {
|
|
99
|
+
readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type ServiceShape<T extends ServiceMap.ServiceClass.Shape<any, any>> = Omit<
|
|
104
|
+
T,
|
|
105
|
+
keyof ServiceMap.ServiceClass.Shape<any, any>
|
|
106
|
+
>
|
|
107
|
+
|
|
108
|
+
export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
|
|
109
|
+
|
|
110
|
+
export function makeService<T extends ServiceTagged<any>>(_: Omit<T, ServiceTag>) {
|
|
111
|
+
return _ as T
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
export const PureEnvEnv = Symbol()
|
|
95
|
-
export interface PureEnvEnv<W, S, S2> extends
|
|
115
|
+
export interface PureEnvEnv<W, S, S2> extends ServiceTagged<typeof PureEnvEnv> {
|
|
96
116
|
env: PureEnv<W, S, S2>
|
|
97
117
|
}
|
|
98
118
|
|
|
99
119
|
export function get<S>(): Pure<never, S, S, never, never, S> {
|
|
100
|
-
return
|
|
120
|
+
return (castTag<never, S, S>() as any).use((_: any) => _.env.state)
|
|
101
121
|
}
|
|
102
122
|
|
|
103
123
|
export function set<S>(s: S): Pure<never, S, S, never, never, void> {
|
|
104
|
-
return
|
|
124
|
+
return (castTag<never, S, S>() as any).use((_: any) => {
|
|
125
|
+
_.env.state = s
|
|
126
|
+
})
|
|
105
127
|
}
|
|
106
128
|
|
|
107
129
|
export type PureLogT<W> = Pure<W, unknown, never, never, never, void>
|
|
108
130
|
|
|
109
131
|
export function log<W>(w: W): PureLogT<W> {
|
|
110
|
-
return
|
|
132
|
+
return (castTag<W, unknown, never>() as any).use((_: any) => {
|
|
133
|
+
_.env.log = Chunk.append(_.env.log, w)
|
|
134
|
+
})
|
|
111
135
|
}
|
|
112
136
|
|
|
113
137
|
export function logMany<W>(w: Iterable<W>): PureLogT<W> {
|
|
114
|
-
return
|
|
138
|
+
return (castTag<W, unknown, never>() as any).use((_: any) => {
|
|
139
|
+
_.env.log = Chunk.appendAll(_.env.log, Chunk.fromIterable(w))
|
|
140
|
+
})
|
|
115
141
|
}
|
|
116
142
|
|
|
117
143
|
export function runAll<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
118
144
|
self: Effect.Effect<A, E, FixEnv<R, W3, S1, S3>>,
|
|
119
145
|
s: S4
|
|
120
146
|
): Effect.Effect<
|
|
121
|
-
readonly [Chunk.Chunk<W3>,
|
|
147
|
+
readonly [Chunk.Chunk<W3>, Result.Result<readonly [S3, A], E>],
|
|
122
148
|
never,
|
|
123
149
|
Exclude<R, { env: PureEnv<W3, S1, S3> }>
|
|
124
150
|
> {
|
|
125
151
|
const a = Effect
|
|
126
152
|
.flatMap(self, (x) =>
|
|
127
|
-
castTag<W3, S1, S3>()
|
|
153
|
+
(castTag<W3, S1, S3>() as any)
|
|
154
|
+
.use(
|
|
155
|
+
({ env: _ }: any) => Effect.sync(() => ({ log: _.log, state: _.state }))
|
|
156
|
+
)
|
|
128
157
|
.pipe(
|
|
129
|
-
Effect.flatMap(
|
|
130
|
-
({ env: _ }) => Effect.sync(() => ({ log: _.log, state: _.state })) // Ref.get(_.log).flatMap(log => Ref.get(_.state).map(state => ({ log, state })))
|
|
131
|
-
),
|
|
158
|
+
Effect.flatMap((_: any) => Effect.succeed(_)),
|
|
132
159
|
Effect.map(
|
|
133
|
-
({ log, state }) => tuple(log,
|
|
160
|
+
({ log, state }: any) => tuple(log, Result.succeed(tuple(state, x)))
|
|
134
161
|
)
|
|
135
162
|
))
|
|
136
|
-
.pipe(Effect.
|
|
163
|
+
.pipe(Effect.catch((err: any) => (tagg as any).use((env: any) => tuple(env.env.log, Result.fail(err)))))
|
|
137
164
|
return Effect.provide(a, Layer.succeed(tagg, { env: makePureEnv<W3, S3, S4>(s) as any }) as any) as any
|
|
138
165
|
}
|
|
139
166
|
|
|
@@ -141,14 +168,17 @@ export function runResult<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
|
141
168
|
self: Effect.Effect<A, E, FixEnv<R, W3, S1, S3>>,
|
|
142
169
|
s: S4
|
|
143
170
|
) {
|
|
144
|
-
return Effect.map(runAll(self, s), ([log, r]) => tuple(log,
|
|
171
|
+
return Effect.map(runAll(self, s), ([log, r]) => tuple(log, Result.map(r, ([s]) => s)))
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
export function runTerm<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
148
175
|
self: Effect.Effect<A, E, FixEnv<R, W3, S1, S3>>,
|
|
149
176
|
s: S4
|
|
150
177
|
) {
|
|
151
|
-
return Effect.flatMap(
|
|
178
|
+
return Effect.flatMap(
|
|
179
|
+
runAll(self, s),
|
|
180
|
+
([evts, r]) => Effect.map(Effect.fromResult(r), ([s3, a]) => tuple(s3, Chunk.toArray(evts), a))
|
|
181
|
+
)
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
export function runTermDiscard<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
@@ -162,17 +192,17 @@ export function runA<R, E, A, W3, S1, S3, S4 extends S1>(
|
|
|
162
192
|
self: Effect.Effect<A, E, FixEnv<R, W3, S1, S3>>,
|
|
163
193
|
s: S4
|
|
164
194
|
) {
|
|
165
|
-
return Effect.map(runAll(self, s), ([log, r]) => tuple(log,
|
|
195
|
+
return Effect.map(runAll(self, s), ([log, r]) => tuple(log, Result.map(r, ([, a]) => a)))
|
|
166
196
|
}
|
|
167
197
|
|
|
168
198
|
export function modify<S2, A, S3>(
|
|
169
199
|
mod: (s: S2) => readonly [S3, A]
|
|
170
200
|
): Effect.Effect<A, never, { env: PureEnv<never, S2, S3> }> {
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
201
|
+
return (castTag<never, S3, S2>() as any).use((_: any) => {
|
|
202
|
+
const [s, a] = mod(_.env.state)
|
|
203
|
+
_.env.state = s as any
|
|
204
|
+
return a
|
|
205
|
+
}) as any
|
|
176
206
|
}
|
|
177
207
|
|
|
178
208
|
export function modifyM<W, R, E, A, S2, S3>(
|
|
@@ -180,8 +210,12 @@ export function modifyM<W, R, E, A, S2, S3>(
|
|
|
180
210
|
): Effect.Effect<A, E, FixEnv<R, W, S2, S3>> {
|
|
181
211
|
// return serviceWithEffect(_ => Ref.modifyM_(_.state, mod))
|
|
182
212
|
return Effect.flatMap(
|
|
183
|
-
castTag<W, S3, S2>(),
|
|
184
|
-
(_
|
|
213
|
+
(castTag<W, S3, S2>() as any).use((_: any) => _),
|
|
214
|
+
(_: any) =>
|
|
215
|
+
Effect.map(mod(_.env.state), ([s, a]: any) => {
|
|
216
|
+
_.env.state = s as any
|
|
217
|
+
return a
|
|
218
|
+
})
|
|
185
219
|
) as any
|
|
186
220
|
}
|
|
187
221
|
|
package/src/Schema/Class.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { pipe, Struct as Struct2 } from "effect"
|
|
3
|
-
import type {
|
|
3
|
+
import type { Struct } from "effect/Schema"
|
|
4
4
|
import * as S from "effect/Schema"
|
|
5
|
-
import type { Simplify } from "effect/Types"
|
|
6
5
|
|
|
7
|
-
type ClassAnnotations<Self,
|
|
8
|
-
| S.Annotations.Schema<Self>
|
|
9
|
-
| readonly [
|
|
10
|
-
// Annotations for the "to" schema
|
|
11
|
-
S.Annotations.Schema<Self> | undefined,
|
|
12
|
-
// Annotations for the "transformation schema
|
|
13
|
-
(S.Annotations.Schema<Self> | undefined)?,
|
|
14
|
-
// Annotations for the "from" schema
|
|
15
|
-
S.Annotations.Schema<A>?
|
|
16
|
-
]
|
|
6
|
+
type ClassAnnotations<Self> = S.Annotations.Declaration<Self, readonly [any]>
|
|
17
7
|
|
|
18
|
-
export interface EnhancedClass<Self,
|
|
19
|
-
extends S.Class<Self,
|
|
8
|
+
export interface EnhancedClass<Self, SchemaS extends S.Top & { readonly fields: Struct.Fields }, Inherited>
|
|
9
|
+
extends S.Class<Self, SchemaS, Inherited>, /* Reason for enhancement */ PropsExtensions<SchemaS["fields"]>
|
|
20
10
|
{
|
|
21
11
|
}
|
|
22
12
|
type MissingSelfGeneric<Usage extends string, Params extends string = ""> =
|
|
@@ -36,47 +26,13 @@ type HasFields<Fields extends Struct.Fields> = {
|
|
|
36
26
|
readonly from: HasFields<Fields>
|
|
37
27
|
}
|
|
38
28
|
|
|
39
|
-
// const isPropertySignature = (u: unknown): u is PropertySignature.All =>
|
|
40
|
-
// Predicate.hasProperty(u, PropertySignatureTypeId)
|
|
41
|
-
|
|
42
|
-
// const isField = (u: unknown) => S.isSchema(u) || S.isPropertySignature(u)
|
|
43
|
-
|
|
44
|
-
// const isFields = <Fields extends Struct.Fields>(fields: object): fields is Fields =>
|
|
45
|
-
// ownKeys(fields).every((key) => isField((fields as any)[key]))
|
|
46
|
-
|
|
47
|
-
// const getFields = <Fields extends Struct.Fields>(hasFields: HasFields<Fields>): Fields =>
|
|
48
|
-
// "fields" in hasFields ? hasFields.fields : getFields(hasFields.from)
|
|
49
|
-
|
|
50
|
-
// const getSchemaFromFieldsOr = <Fields extends Struct.Fields>(fieldsOr: Fields | HasFields<Fields>): Schema.Any =>
|
|
51
|
-
// isFields(fieldsOr) ? Struct(fieldsOr) : S.isSchema(fieldsOr) ? fieldsOr : Struct(getFields(fieldsOr))
|
|
52
|
-
|
|
53
|
-
// const getFieldsFromFieldsOr = <Fields extends Struct.Fields>(fieldsOr: Fields | HasFields<Fields>): Fields =>
|
|
54
|
-
// isFields(fieldsOr) ? fieldsOr : getFields(fieldsOr)
|
|
55
|
-
|
|
56
|
-
// export function include<Fields extends S.Struct.Fields>(fields: Fields | HasFields<Fields>) {
|
|
57
|
-
// return <NewProps extends S.Struct.Fields>(
|
|
58
|
-
// fnc: (fields: Fields) => NewProps
|
|
59
|
-
// ) => include_(fields, fnc)
|
|
60
|
-
// }
|
|
61
|
-
|
|
62
|
-
// export function include_<
|
|
63
|
-
// Fields extends S.Struct.Fields,
|
|
64
|
-
// NewProps extends S.Struct.Fields
|
|
65
|
-
// >(fields: Fields | HasFields<Fields>, fnc: (fields: Fields) => NewProps) {
|
|
66
|
-
// return fnc("fields" in fields ? fields.fields : fields)
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
29
|
export const Class: <Self = never>(identifier: string) => <Fields extends S.Struct.Fields>(
|
|
70
30
|
fieldsOr: Fields | HasFields<Fields>,
|
|
71
|
-
annotations?: ClassAnnotations<Self
|
|
31
|
+
annotations?: ClassAnnotations<Self>
|
|
72
32
|
) => [Self] extends [never] ? MissingSelfGeneric<"Class">
|
|
73
33
|
: EnhancedClass<
|
|
74
34
|
Self,
|
|
75
|
-
Fields
|
|
76
|
-
Simplify<Struct.Encoded<Fields>>,
|
|
77
|
-
Struct.Context<Fields>,
|
|
78
|
-
Simplify<S.Struct.Constructor<Fields>>,
|
|
79
|
-
{},
|
|
35
|
+
S.Struct<Fields>,
|
|
80
36
|
{}
|
|
81
37
|
> = (identifier) => (fields, annotations) => {
|
|
82
38
|
const cls = S.Class as any
|
|
@@ -85,23 +41,19 @@ export const Class: <Self = never>(identifier: string) => <Fields extends S.Stru
|
|
|
85
41
|
super(a, b)
|
|
86
42
|
}
|
|
87
43
|
// static readonly include = include(fields)
|
|
88
|
-
static readonly pick = (...selection: any[]) => pipe(this["fields"], Struct2.pick(
|
|
89
|
-
static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(
|
|
44
|
+
static readonly pick = (...selection: any[]) => pipe(this["fields"], Struct2.pick(selection))
|
|
45
|
+
static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(selection))
|
|
90
46
|
} as any
|
|
91
47
|
}
|
|
92
48
|
|
|
93
49
|
export const TaggedClass: <Self = never>(identifier?: string) => <Tag extends string, Fields extends S.Struct.Fields>(
|
|
94
50
|
tag: Tag,
|
|
95
51
|
fieldsOr: Fields | HasFields<Fields>,
|
|
96
|
-
annotations?: ClassAnnotations<Self
|
|
52
|
+
annotations?: ClassAnnotations<Self>
|
|
97
53
|
) => [Self] extends [never] ? MissingSelfGeneric<"Class">
|
|
98
54
|
: EnhancedClass<
|
|
99
55
|
Self,
|
|
100
|
-
{ readonly _tag: S.tag<Tag> } & Fields
|
|
101
|
-
Simplify<{ readonly _tag: Tag } & Struct.Encoded<Fields>>,
|
|
102
|
-
Schema.Context<Fields[keyof Fields]>,
|
|
103
|
-
Simplify<S.Struct.Constructor<Fields>>,
|
|
104
|
-
{},
|
|
56
|
+
S.Struct<{ readonly _tag: S.tag<Tag> } & Fields>,
|
|
105
57
|
{}
|
|
106
58
|
> = (identifier) => (tag, fields, annotations) => {
|
|
107
59
|
const cls = S.TaggedClass as any
|
|
@@ -110,21 +62,17 @@ export const TaggedClass: <Self = never>(identifier?: string) => <Tag extends st
|
|
|
110
62
|
super(a, b)
|
|
111
63
|
}
|
|
112
64
|
// static readonly include = include(fields)
|
|
113
|
-
static readonly pick = (...selection: any[]) => pipe(this["fields"], Struct2.pick(
|
|
114
|
-
static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(
|
|
65
|
+
static readonly pick = (...selection: any[]) => pipe(this["fields"], Struct2.pick(selection))
|
|
66
|
+
static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(selection))
|
|
115
67
|
} as any
|
|
116
68
|
}
|
|
117
69
|
|
|
118
|
-
export const ExtendedClass: <Self,
|
|
70
|
+
export const ExtendedClass: <Self, _SelfFrom>(identifier: string) => <Fields extends S.Struct.Fields>(
|
|
119
71
|
fieldsOr: Fields | HasFields<Fields>,
|
|
120
|
-
annotations?: ClassAnnotations<Self
|
|
72
|
+
annotations?: ClassAnnotations<Self>
|
|
121
73
|
) => EnhancedClass<
|
|
122
74
|
Self,
|
|
123
|
-
Fields
|
|
124
|
-
SelfFrom,
|
|
125
|
-
Schema.Context<Fields[keyof Fields]>,
|
|
126
|
-
Simplify<S.Struct.Constructor<Fields>>,
|
|
127
|
-
{},
|
|
75
|
+
S.Struct<Fields>,
|
|
128
76
|
{}
|
|
129
77
|
> = Class as any
|
|
130
78
|
|
|
@@ -132,11 +80,7 @@ export interface EnhancedTaggedClass<Self, Tag extends string, Fields extends St
|
|
|
132
80
|
extends
|
|
133
81
|
EnhancedClass<
|
|
134
82
|
Self,
|
|
135
|
-
Fields,
|
|
136
|
-
SelfFrom,
|
|
137
|
-
Struct.Context<Fields>,
|
|
138
|
-
Struct.Constructor<Omit<Fields, "_tag">>,
|
|
139
|
-
{},
|
|
83
|
+
S.Struct<Fields> & { readonly Encoded: SelfFrom },
|
|
140
84
|
{}
|
|
141
85
|
>
|
|
142
86
|
{
|
|
@@ -148,7 +92,7 @@ export const ExtendedTaggedClass: <Self, SelfFrom>(
|
|
|
148
92
|
) => <Tag extends string, Fields extends S.Struct.Fields>(
|
|
149
93
|
tag: Tag,
|
|
150
94
|
fieldsOr: Fields | HasFields<Fields>,
|
|
151
|
-
annotations?: ClassAnnotations<Self
|
|
95
|
+
annotations?: ClassAnnotations<Self>
|
|
152
96
|
) => EnhancedTaggedClass<
|
|
153
97
|
Self,
|
|
154
98
|
Tag,
|
package/src/Schema/brand.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
/* eslint-disable import/no-duplicates */
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
2
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
4
3
|
import type { Option } from "effect"
|
|
5
4
|
import * as B from "effect/Brand"
|
|
6
5
|
import type * as Brand from "effect/Brand"
|
|
7
|
-
import type * as
|
|
6
|
+
import type * as Result from "effect/Result"
|
|
8
7
|
import * as S from "effect/Schema"
|
|
9
8
|
|
|
10
9
|
export interface Constructor<in out A extends B.Brand<any>> {
|
|
11
|
-
readonly [B.RefinedConstructorsTypeId]: B.RefinedConstructorsTypeId
|
|
12
10
|
/**
|
|
13
11
|
* Constructs a branded type from a value of type `A`, throwing an error if
|
|
14
12
|
* the provided `A` is not valid.
|
|
@@ -20,10 +18,10 @@ export interface Constructor<in out A extends B.Brand<any>> {
|
|
|
20
18
|
*/
|
|
21
19
|
option(args: Unbranded<A>): Option.Option<A>
|
|
22
20
|
/**
|
|
23
|
-
* Constructs a branded type from a value of type `A`, returning `
|
|
24
|
-
* if the provided `A` is valid, `
|
|
21
|
+
* Constructs a branded type from a value of type `A`, returning `Result.succeed`
|
|
22
|
+
* if the provided `A` is valid, `Result.fail` otherwise.
|
|
25
23
|
*/
|
|
26
|
-
|
|
24
|
+
result(args: Unbranded<A>): Result.Result<A, Brand.BrandError>
|
|
27
25
|
/**
|
|
28
26
|
* Attempts to refine the provided value of type `A`, returning `true` if
|
|
29
27
|
* the provided `A` is valid, `false` otherwise.
|
|
@@ -31,18 +29,19 @@ export interface Constructor<in out A extends B.Brand<any>> {
|
|
|
31
29
|
is(a: Unbranded<A>): a is Unbranded<A> & A
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
export const fromBrand = <C extends Brand.Brand<string
|
|
32
|
+
export const fromBrand = <C extends Brand.Brand<string>>(
|
|
35
33
|
constructor: Constructor<C>,
|
|
36
|
-
options?: S.Annotations.Filter
|
|
34
|
+
options?: S.Annotations.Filter
|
|
37
35
|
) =>
|
|
38
|
-
<
|
|
39
|
-
|
|
36
|
+
<Self extends S.Top>(self: Self): S.brand<Self["~rebuild.out"], Brand.Brand.Keys<C>> => {
|
|
37
|
+
const branded = S.fromBrand(options?.identifier ?? "Brand", constructor as any)(self as any)
|
|
38
|
+
return options ? (branded as any).pipe(S.annotate(options)) : branded as any
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
export type Brands<P> = P extends B.Brand<any> ?
|
|
41
|
+
export type Brands<P> = P extends B.Brand<any> ? Brand.Brand.Brands<P>
|
|
43
42
|
: never
|
|
44
43
|
|
|
45
|
-
export type Unbranded<P> = P extends
|
|
44
|
+
export type Unbranded<P> = P extends B.Brand<any> ? Brand.Brand.Unbranded<P> : P
|
|
46
45
|
|
|
47
46
|
export const nominal: <A extends B.Brand<any>>() => Constructor<A> = <
|
|
48
47
|
A extends B.Brand<any>
|
package/src/Schema/email.ts
CHANGED
|
@@ -12,11 +12,11 @@ export type Email = string & EmailBrand
|
|
|
12
12
|
export const Email = S
|
|
13
13
|
.String
|
|
14
14
|
.pipe(
|
|
15
|
-
S.
|
|
15
|
+
S.refine(isValidEmail as Refinement<string, Email>, {
|
|
16
16
|
identifier: "Email",
|
|
17
17
|
title: "Email",
|
|
18
18
|
description: "an email according to RFC 5322",
|
|
19
19
|
jsonSchema: { format: "email", minLength: 3, /* a@b */ maxLength: 998 },
|
|
20
|
-
arbitrary: () => (fc) => fc.emailAddress().map((_) => _ as Email)
|
|
20
|
+
arbitrary: () => (fc: any) => fc.emailAddress().map((_: any) => _ as Email)
|
|
21
21
|
})
|
|
22
22
|
)
|