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.
Files changed (174) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/Array.js +1 -1
  3. package/dist/Chunk.d.ts +2 -4
  4. package/dist/Chunk.d.ts.map +1 -1
  5. package/dist/Chunk.js +2 -2
  6. package/dist/Config/SecretURL.d.ts +2 -12
  7. package/dist/Config/SecretURL.d.ts.map +1 -1
  8. package/dist/Config/SecretURL.js +2 -4
  9. package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
  10. package/dist/Config/internal/configSecretURL.js +3 -4
  11. package/dist/Effect.d.ts +12 -10
  12. package/dist/Effect.d.ts.map +1 -1
  13. package/dist/Effect.js +6 -15
  14. package/dist/Layer.d.ts +15 -9
  15. package/dist/Layer.d.ts.map +1 -1
  16. package/dist/Layer.js +2 -2
  17. package/dist/Operations.d.ts +37 -47
  18. package/dist/Operations.d.ts.map +1 -1
  19. package/dist/Option.js +3 -3
  20. package/dist/Pure.d.ts +17 -6
  21. package/dist/Pure.d.ts.map +1 -1
  22. package/dist/Pure.js +35 -17
  23. package/dist/Schema/Class.d.ts +13 -16
  24. package/dist/Schema/Class.d.ts.map +1 -1
  25. package/dist/Schema/Class.js +5 -27
  26. package/dist/Schema/brand.d.ts +7 -10
  27. package/dist/Schema/brand.d.ts.map +1 -1
  28. package/dist/Schema/brand.js +3 -2
  29. package/dist/Schema/email.d.ts +1 -1
  30. package/dist/Schema/email.d.ts.map +1 -1
  31. package/dist/Schema/email.js +2 -2
  32. package/dist/Schema/ext.d.ts +42 -45
  33. package/dist/Schema/ext.d.ts.map +1 -1
  34. package/dist/Schema/ext.js +49 -63
  35. package/dist/Schema/moreStrings.d.ts +17 -17
  36. package/dist/Schema/moreStrings.d.ts.map +1 -1
  37. package/dist/Schema/moreStrings.js +10 -10
  38. package/dist/Schema/numbers.d.ts +14 -14
  39. package/dist/Schema/numbers.js +5 -5
  40. package/dist/Schema/phoneNumber.d.ts +1 -1
  41. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  42. package/dist/Schema/phoneNumber.js +2 -2
  43. package/dist/Schema/schema.d.ts +2 -3
  44. package/dist/Schema/schema.d.ts.map +1 -1
  45. package/dist/Schema/schema.js +3 -4
  46. package/dist/Schema/strings.d.ts +4 -4
  47. package/dist/Schema/strings.d.ts.map +1 -1
  48. package/dist/Schema/strings.js +4 -4
  49. package/dist/Schema.d.ts +27 -25
  50. package/dist/Schema.d.ts.map +1 -1
  51. package/dist/Schema.js +22 -21
  52. package/dist/ServiceMap.d.ts +44 -0
  53. package/dist/ServiceMap.d.ts.map +1 -0
  54. package/dist/ServiceMap.js +91 -0
  55. package/dist/Set.d.ts +4 -4
  56. package/dist/Set.d.ts.map +1 -1
  57. package/dist/Set.js +14 -14
  58. package/dist/Struct.d.ts +4 -4
  59. package/dist/Struct.d.ts.map +1 -1
  60. package/dist/_ext/Array.d.ts.map +1 -1
  61. package/dist/_ext/Array.js +4 -4
  62. package/dist/_ext/misc.d.ts +2 -2
  63. package/dist/_ext/misc.js +4 -4
  64. package/dist/_ext/ord.ext.js +2 -2
  65. package/dist/builtin.d.ts +0 -8
  66. package/dist/builtin.d.ts.map +1 -1
  67. package/dist/builtin.js +3 -1
  68. package/dist/client/apiClientFactory.d.ts +14 -16
  69. package/dist/client/apiClientFactory.d.ts.map +1 -1
  70. package/dist/client/apiClientFactory.js +38 -23
  71. package/dist/client/clientFor.d.ts +7 -4
  72. package/dist/client/clientFor.d.ts.map +1 -1
  73. package/dist/client/errors.d.ts +36 -48
  74. package/dist/client/errors.d.ts.map +1 -1
  75. package/dist/client/errors.js +19 -9
  76. package/dist/client/makeClient.d.ts +34 -50
  77. package/dist/client/makeClient.d.ts.map +1 -1
  78. package/dist/client/makeClient.js +28 -18
  79. package/dist/http/Request.d.ts +3 -3
  80. package/dist/http/Request.d.ts.map +1 -1
  81. package/dist/http/Request.js +5 -8
  82. package/dist/http/internal/lib.d.ts +12 -13
  83. package/dist/http/internal/lib.d.ts.map +1 -1
  84. package/dist/http/internal/lib.js +14 -14
  85. package/dist/ids.d.ts +9 -9
  86. package/dist/ids.d.ts.map +1 -1
  87. package/dist/ids.js +1 -1
  88. package/dist/index.d.ts +7 -1
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +8 -2
  91. package/dist/logger.d.ts +1 -1
  92. package/dist/middleware.d.ts +2 -2
  93. package/dist/middleware.d.ts.map +1 -1
  94. package/dist/middleware.js +3 -3
  95. package/dist/rpc/MiddlewareMaker.d.ts +17 -16
  96. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  97. package/dist/rpc/MiddlewareMaker.js +27 -18
  98. package/dist/rpc/RpcContextMap.d.ts +4 -4
  99. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  100. package/dist/rpc/RpcContextMap.js +4 -4
  101. package/dist/rpc/RpcMiddleware.d.ts +24 -40
  102. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  103. package/dist/rpc/RpcMiddleware.js +3 -10
  104. package/dist/utils/effectify.js +2 -2
  105. package/dist/utils/gen.d.ts +4 -5
  106. package/dist/utils/gen.d.ts.map +1 -1
  107. package/dist/utils/logLevel.d.ts +1 -1
  108. package/dist/utils/logLevel.d.ts.map +1 -1
  109. package/dist/utils/logLevel.js +6 -7
  110. package/dist/utils/logger.d.ts +4 -3
  111. package/dist/utils/logger.d.ts.map +1 -1
  112. package/dist/utils/logger.js +10 -9
  113. package/dist/utils.d.ts +4 -5
  114. package/dist/utils.d.ts.map +1 -1
  115. package/dist/utils.js +10 -9
  116. package/package.json +12 -21
  117. package/src/Array.ts +1 -1
  118. package/src/Chunk.ts +2 -2
  119. package/src/Config/SecretURL.ts +3 -18
  120. package/src/Config/internal/configSecretURL.ts +2 -3
  121. package/src/Effect.ts +17 -37
  122. package/src/Layer.ts +16 -11
  123. package/src/Option.ts +2 -2
  124. package/src/Pure.ts +60 -26
  125. package/src/Schema/Class.ts +17 -73
  126. package/src/Schema/brand.ts +11 -12
  127. package/src/Schema/email.ts +2 -2
  128. package/src/Schema/ext.ts +114 -167
  129. package/src/Schema/moreStrings.ts +20 -23
  130. package/src/Schema/numbers.ts +4 -4
  131. package/src/Schema/phoneNumber.ts +2 -2
  132. package/src/Schema/schema.ts +2 -3
  133. package/src/Schema/strings.ts +3 -3
  134. package/src/Schema.ts +49 -47
  135. package/src/ServiceMap.ts +187 -0
  136. package/src/Set.ts +19 -19
  137. package/src/Struct.ts +4 -4
  138. package/src/_ext/Array.ts +4 -5
  139. package/src/_ext/misc.ts +4 -4
  140. package/src/_ext/ord.ext.ts +2 -2
  141. package/src/builtin.ts +2 -8
  142. package/src/client/apiClientFactory.ts +74 -59
  143. package/src/client/clientFor.ts +10 -7
  144. package/src/client/errors.ts +28 -22
  145. package/src/client/makeClient.ts +75 -100
  146. package/src/http/Request.ts +5 -8
  147. package/src/http/internal/lib.ts +13 -13
  148. package/src/ids.ts +1 -1
  149. package/src/index.ts +10 -1
  150. package/src/middleware.ts +2 -2
  151. package/src/rpc/MiddlewareMaker.ts +76 -47
  152. package/src/rpc/RpcContextMap.ts +7 -7
  153. package/src/rpc/RpcMiddleware.ts +28 -54
  154. package/src/utils/effectify.ts +1 -1
  155. package/src/utils/gen.ts +8 -6
  156. package/src/utils/logLevel.ts +6 -6
  157. package/src/utils/logger.ts +15 -20
  158. package/src/utils.ts +12 -12
  159. package/test/dist/rpc.test.d.ts.map +1 -1
  160. package/test/schema.test.ts +8 -8
  161. package/test/utils.test.ts +2 -2
  162. package/tsconfig.json +1 -27
  163. package/dist/Context.d.ts +0 -67
  164. package/dist/Context.d.ts.map +0 -1
  165. package/dist/Context.js +0 -207
  166. package/dist/Tag.d.ts +0 -6
  167. package/dist/Tag.d.ts.map +0 -1
  168. package/dist/Tag.js +0 -9
  169. package/dist/Unify.d.ts +0 -27
  170. package/dist/Unify.d.ts.map +0 -1
  171. package/dist/Unify.js +0 -15
  172. package/src/Context.ts +0 -351
  173. package/src/Tag.ts +0 -11
  174. 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, Either, Layer } from "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 = Context.GenericTag<{ env: PureEnv<never, unknown, never> }>("PureEnv")
89
+ const tagg = ServiceMap.Service<{ env: PureEnv<never, unknown, never> }>("PureEnv")
90
90
  function castTag<W, S, S2>() {
91
- return tagg as any as Context.Tag<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
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 Context.ServiceTagged<typeof PureEnvEnv> {
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 Effect.map(castTag<never, S, S>(), (_) => _.env.state)
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 Effect.map(castTag<never, S, S>(), (_) => _.env.state = s)
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 Effect.map(castTag<W, unknown, never>(), (_) => _.env.log = Chunk.append(_.env.log, w))
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 Effect.map(castTag<W, unknown, never>(), (_) => _.env.log = Chunk.appendAll(_.env.log, Chunk.fromIterable(w)))
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>, Either.Either<readonly [S3, A], E>],
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, Either.right(tuple(state, x)))
160
+ ({ log, state }: any) => tuple(log, Result.succeed(tuple(state, x)))
134
161
  )
135
162
  ))
136
- .pipe(Effect.catchAll((err) => Effect.map(tagg, (env) => tuple(env.env.log, Either.left(err)))))
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, Effect.map(r, ([s]) => s)))
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(runAll(self, s), ([evts, r]) => Effect.map(r, ([s3, a]) => tuple(s3, Chunk.toArray(evts), a)))
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, Effect.map(r, ([, a]) => a)))
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 Effect.map(castTag<never, S3, S2>(), (_) =>
172
- Effect.map(Effect.sync(() => mod(_.env.state)), ([s, a]) => {
173
- _.env.state = s as any
174
- return a
175
- })) as any
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
- (_) => Effect.map(mod(_.env.state), ([s, a]) => Effect.map(Effect.sync(() => _.env.state = s as any), () => a))
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
 
@@ -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 { Schema, Struct } from "effect/Schema"
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, A> =
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, Fields extends Struct.Fields, I, R, C, Inherited, Proto>
19
- extends S.Class<Self, Fields, I, R, C, Inherited, Proto>, /* Reason for enhancement */ PropsExtensions<Fields>
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, Struct.Type<Fields>>
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(...selection))
89
- static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(...selection))
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, Struct.Type<Fields>>
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(...selection))
114
- static readonly omit = (...selection: any[]) => pipe(this["fields"], Struct2.omit(...selection))
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, SelfFrom>(identifier: string) => <Fields extends S.Struct.Fields>(
70
+ export const ExtendedClass: <Self, _SelfFrom>(identifier: string) => <Fields extends S.Struct.Fields>(
119
71
  fieldsOr: Fields | HasFields<Fields>,
120
- annotations?: ClassAnnotations<Self, Struct.Type<Fields>>
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, Struct.Type<Fields>>
95
+ annotations?: ClassAnnotations<Self>
152
96
  ) => EnhancedTaggedClass<
153
97
  Self,
154
98
  Tag,
@@ -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 Either from "effect/Either"
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 `Right<A>`
24
- * if the provided `A` is valid, `Left<BrandError>` otherwise.
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
- either(args: Unbranded<A>): Either.Either<A, Brand.Brand.BrandErrors>
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 | symbol>>(
32
+ export const fromBrand = <C extends Brand.Brand<string>>(
35
33
  constructor: Constructor<C>,
36
- options?: S.Annotations.Filter<Unbranded<C>>
34
+ options?: S.Annotations.Filter
37
35
  ) =>
38
- <R, I, A extends Unbranded<C>>(self: S.Schema<A, I, R>): S.Schema<A & C, I, R> => {
39
- return S.fromBrand(constructor as any, options as any)(self as any) as any
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> ? { readonly [B.BrandTypeId]: P[B.BrandTypeId] }
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 infer Q & Brands<P> ? Q : P
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>
@@ -12,11 +12,11 @@ export type Email = string & EmailBrand
12
12
  export const Email = S
13
13
  .String
14
14
  .pipe(
15
- S.filter(isValidEmail as Refinement<string, Email>, {
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
  )