effect-app 4.0.0-beta.17 → 4.0.0-beta.170

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 (207) hide show
  1. package/CHANGELOG.md +683 -0
  2. package/dist/Array.d.ts +1 -1
  3. package/dist/Chunk.d.ts +1 -1
  4. package/dist/Chunk.d.ts.map +1 -1
  5. package/dist/Config/SecretURL.d.ts +1 -1
  6. package/dist/Config/SecretURL.d.ts.map +1 -1
  7. package/dist/Config/SecretURL.js +2 -2
  8. package/dist/Config/internal/configSecretURL.d.ts +1 -1
  9. package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
  10. package/dist/Config.d.ts +7 -0
  11. package/dist/Config.d.ts.map +1 -0
  12. package/dist/Config.js +6 -0
  13. package/dist/ConfigProvider.d.ts +39 -0
  14. package/dist/ConfigProvider.d.ts.map +1 -0
  15. package/dist/ConfigProvider.js +42 -0
  16. package/dist/Context.d.ts +40 -0
  17. package/dist/Context.d.ts.map +1 -0
  18. package/dist/Context.js +67 -0
  19. package/dist/Effect.d.ts +9 -10
  20. package/dist/Effect.d.ts.map +1 -1
  21. package/dist/Effect.js +3 -6
  22. package/dist/Function.d.ts +1 -1
  23. package/dist/Function.d.ts.map +1 -1
  24. package/dist/Inputify.type.d.ts +1 -1
  25. package/dist/Layer.d.ts +6 -5
  26. package/dist/Layer.d.ts.map +1 -1
  27. package/dist/Layer.js +1 -1
  28. package/dist/NonEmptySet.d.ts +1 -1
  29. package/dist/NonEmptySet.d.ts.map +1 -1
  30. package/dist/Operations.d.ts +369 -47
  31. package/dist/Operations.d.ts.map +1 -1
  32. package/dist/Operations.js +10 -10
  33. package/dist/Option.d.ts +1 -1
  34. package/dist/Option.d.ts.map +1 -1
  35. package/dist/Pure.d.ts +5 -5
  36. package/dist/Pure.d.ts.map +1 -1
  37. package/dist/Pure.js +13 -13
  38. package/dist/Schema/Class.d.ts +69 -20
  39. package/dist/Schema/Class.d.ts.map +1 -1
  40. package/dist/Schema/Class.js +190 -22
  41. package/dist/Schema/FastCheck.d.ts +1 -1
  42. package/dist/Schema/FastCheck.d.ts.map +1 -1
  43. package/dist/Schema/Methods.d.ts +1 -1
  44. package/dist/Schema/SchemaParser.d.ts +5 -0
  45. package/dist/Schema/SchemaParser.d.ts.map +1 -0
  46. package/dist/Schema/SchemaParser.js +6 -0
  47. package/dist/Schema/SpecialJsonSchema.d.ts +33 -0
  48. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
  49. package/dist/Schema/SpecialJsonSchema.js +122 -0
  50. package/dist/Schema/SpecialOpenApi.d.ts +32 -0
  51. package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
  52. package/dist/Schema/SpecialOpenApi.js +123 -0
  53. package/dist/Schema/brand.d.ts +7 -2
  54. package/dist/Schema/brand.d.ts.map +1 -1
  55. package/dist/Schema/brand.js +1 -1
  56. package/dist/Schema/email.d.ts +1 -1
  57. package/dist/Schema/email.d.ts.map +1 -1
  58. package/dist/Schema/email.js +7 -4
  59. package/dist/Schema/ext.d.ts +121 -48
  60. package/dist/Schema/ext.d.ts.map +1 -1
  61. package/dist/Schema/ext.js +129 -53
  62. package/dist/Schema/moreStrings.d.ts +111 -11
  63. package/dist/Schema/moreStrings.d.ts.map +1 -1
  64. package/dist/Schema/moreStrings.js +14 -15
  65. package/dist/Schema/numbers.d.ts +127 -15
  66. package/dist/Schema/numbers.d.ts.map +1 -1
  67. package/dist/Schema/numbers.js +10 -12
  68. package/dist/Schema/phoneNumber.d.ts +1 -1
  69. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  70. package/dist/Schema/phoneNumber.js +6 -3
  71. package/dist/Schema/schema.d.ts +1 -1
  72. package/dist/Schema/strings.d.ts +37 -5
  73. package/dist/Schema/strings.d.ts.map +1 -1
  74. package/dist/Schema/strings.js +1 -5
  75. package/dist/Schema.d.ts +102 -56
  76. package/dist/Schema.d.ts.map +1 -1
  77. package/dist/Schema.js +128 -64
  78. package/dist/Set.d.ts +1 -1
  79. package/dist/Set.d.ts.map +1 -1
  80. package/dist/TypeTest.d.ts +1 -1
  81. package/dist/Types.d.ts +1 -1
  82. package/dist/Widen.type.d.ts +1 -1
  83. package/dist/_ext/Array.d.ts +1 -1
  84. package/dist/_ext/Array.d.ts.map +1 -1
  85. package/dist/_ext/date.d.ts +1 -1
  86. package/dist/_ext/misc.d.ts +1 -1
  87. package/dist/_ext/ord.ext.d.ts +1 -1
  88. package/dist/_ext/ord.ext.d.ts.map +1 -1
  89. package/dist/builtin.d.ts +1 -1
  90. package/dist/builtin.d.ts.map +1 -1
  91. package/dist/client/apiClientFactory.d.ts +14 -30
  92. package/dist/client/apiClientFactory.d.ts.map +1 -1
  93. package/dist/client/apiClientFactory.js +18 -19
  94. package/dist/client/clientFor.d.ts +30 -11
  95. package/dist/client/clientFor.d.ts.map +1 -1
  96. package/dist/client/clientFor.js +9 -1
  97. package/dist/client/errors.d.ts +44 -19
  98. package/dist/client/errors.d.ts.map +1 -1
  99. package/dist/client/errors.js +35 -10
  100. package/dist/client/makeClient.d.ts +243 -29
  101. package/dist/client/makeClient.d.ts.map +1 -1
  102. package/dist/client/makeClient.js +53 -23
  103. package/dist/client.d.ts +1 -1
  104. package/dist/faker.d.ts +1 -1
  105. package/dist/faker.d.ts.map +1 -1
  106. package/dist/http/Request.d.ts +2 -2
  107. package/dist/http/Request.d.ts.map +1 -1
  108. package/dist/http/Request.js +5 -5
  109. package/dist/http/internal/lib.d.ts +1 -1
  110. package/dist/http.d.ts +1 -1
  111. package/dist/ids.d.ts +3 -3
  112. package/dist/ids.d.ts.map +1 -1
  113. package/dist/ids.js +3 -2
  114. package/dist/index.d.ts +5 -8
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +6 -8
  117. package/dist/logger.d.ts +1 -1
  118. package/dist/middleware.d.ts +8 -8
  119. package/dist/middleware.d.ts.map +1 -1
  120. package/dist/middleware.js +8 -8
  121. package/dist/rpc/MiddlewareMaker.d.ts +5 -4
  122. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  123. package/dist/rpc/MiddlewareMaker.js +26 -27
  124. package/dist/rpc/RpcContextMap.d.ts +3 -3
  125. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  126. package/dist/rpc/RpcContextMap.js +4 -4
  127. package/dist/rpc/RpcMiddleware.d.ts +5 -4
  128. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  129. package/dist/rpc/RpcMiddleware.js +1 -1
  130. package/dist/rpc.d.ts +1 -2
  131. package/dist/rpc.d.ts.map +1 -1
  132. package/dist/rpc.js +1 -2
  133. package/dist/transform.d.ts +1 -1
  134. package/dist/transform.d.ts.map +1 -1
  135. package/dist/transform.js +3 -3
  136. package/dist/utils/effectify.d.ts +1 -1
  137. package/dist/utils/extend.d.ts +1 -1
  138. package/dist/utils/extend.d.ts.map +1 -1
  139. package/dist/utils/gen.d.ts +2 -2
  140. package/dist/utils/gen.d.ts.map +1 -1
  141. package/dist/utils/logLevel.d.ts +2 -2
  142. package/dist/utils/logLevel.d.ts.map +1 -1
  143. package/dist/utils/logger.d.ts +3 -3
  144. package/dist/utils/logger.d.ts.map +1 -1
  145. package/dist/utils/logger.js +3 -3
  146. package/dist/utils.d.ts +30 -10
  147. package/dist/utils.d.ts.map +1 -1
  148. package/dist/utils.js +10 -4
  149. package/dist/validation/validators.d.ts +1 -1
  150. package/dist/validation/validators.d.ts.map +1 -1
  151. package/dist/validation.d.ts +1 -1
  152. package/dist/validation.d.ts.map +1 -1
  153. package/eslint.config.mjs +2 -2
  154. package/package.json +39 -19
  155. package/src/Config/SecretURL.ts +2 -1
  156. package/src/Config.ts +14 -0
  157. package/src/ConfigProvider.ts +48 -0
  158. package/src/{ServiceMap.ts → Context.ts} +52 -59
  159. package/src/Effect.ts +12 -14
  160. package/src/Layer.ts +5 -4
  161. package/src/Operations.ts +14 -14
  162. package/src/Pure.ts +17 -18
  163. package/src/Schema/Class.ts +279 -62
  164. package/src/Schema/SchemaParser.ts +12 -0
  165. package/src/Schema/SpecialJsonSchema.ts +137 -0
  166. package/src/Schema/SpecialOpenApi.ts +130 -0
  167. package/src/Schema/brand.ts +9 -1
  168. package/src/Schema/email.ts +7 -2
  169. package/src/Schema/ext.ts +217 -87
  170. package/src/Schema/moreStrings.ts +22 -20
  171. package/src/Schema/numbers.ts +14 -16
  172. package/src/Schema/phoneNumber.ts +5 -1
  173. package/src/Schema/strings.ts +4 -8
  174. package/src/Schema.ts +265 -105
  175. package/src/client/apiClientFactory.ts +107 -113
  176. package/src/client/clientFor.ts +45 -12
  177. package/src/client/errors.ts +42 -17
  178. package/src/client/makeClient.ts +319 -63
  179. package/src/http/Request.ts +7 -4
  180. package/src/ids.ts +2 -1
  181. package/src/index.ts +5 -10
  182. package/src/middleware.ts +7 -9
  183. package/src/rpc/MiddlewareMaker.ts +36 -47
  184. package/src/rpc/README.md +2 -2
  185. package/src/rpc/RpcContextMap.ts +6 -5
  186. package/src/rpc/RpcMiddleware.ts +5 -4
  187. package/src/rpc.ts +0 -1
  188. package/src/transform.ts +2 -2
  189. package/src/utils/gen.ts +1 -1
  190. package/src/utils/logger.ts +2 -2
  191. package/src/utils.ts +47 -11
  192. package/test/dist/rpc.test.d.ts.map +1 -1
  193. package/test/dist/secretURL.test.d.ts.map +1 -0
  194. package/test/dist/special.test.d.ts.map +1 -0
  195. package/test/rpc.test.ts +38 -6
  196. package/test/schema.test.ts +591 -17
  197. package/test/secretURL.test.ts +157 -0
  198. package/test/special.test.ts +1023 -0
  199. package/test/utils.test.ts +6 -6
  200. package/tsconfig.base.json +3 -4
  201. package/tsconfig.json +0 -1
  202. package/tsconfig.json.bak +2 -2
  203. package/tsconfig.src.json +29 -29
  204. package/tsconfig.test.json +2 -2
  205. package/dist/ServiceMap.d.ts +0 -44
  206. package/dist/ServiceMap.d.ts.map +0 -1
  207. package/dist/ServiceMap.js +0 -91
@@ -1,3 +1,5 @@
1
+ import { SchemaTransformation } from "effect"
2
+ import type * as Exit from "effect/Exit"
1
3
  import { type GetContextConfig, type GetEffectError, type RequestContextMapTagAny } from "../rpc/RpcContextMap.js"
2
4
  import * as S from "../Schema.js"
3
5
  import { AST } from "../Schema.js"
@@ -8,33 +10,105 @@ const merge = (a: any, b: Array<any>) =>
8
10
  /**
9
11
  * Whatever the input, we will only decode or encode to void
10
12
  */
11
- const ForceVoid: S.Codec<void> = S.Void as any
13
+ export const ForceVoid = S
14
+ .declare((_: unknown): _ is unknown => true)
15
+ .pipe(
16
+ S.decodeTo(S.Any, SchemaTransformation.transform<unknown, unknown>({ decode: () => void 0, encode: () => void 0 }))
17
+ )
12
18
 
13
19
  type SchemaOrFields<T> = T extends S.Top ? T : T extends S.Struct.Fields ? S.Struct<T> : S.Void
14
20
 
15
- type TaggedRequestResult<
21
+ type TaggedRequestSchema<Tag extends string, Payload extends S.Struct.Fields> = S.Struct<
22
+ { readonly _tag: S.tag<Tag> } & Payload
23
+ >
24
+
25
+ type QueryOnlyRequests<Resource> = {
26
+ [K in keyof Resource as Resource[K] extends { readonly type: "query" } ? K : never]: Resource[K]
27
+ }
28
+
29
+ type QueryOnlyResources<Resources> = {
30
+ [K in keyof Resources]: QueryOnlyRequests<Resources[K]>
31
+ }
32
+
33
+ type InputFromPayload<Payload extends S.Struct.Fields> = keyof Payload extends never ? void
34
+ : S.Schema.Type<S.Struct<Payload>>
35
+
36
+ type OutputFromSuccess<Success extends S.Top> = Success extends typeof ForceVoid ? void : S.Schema.Type<Success>
37
+
38
+ type InvalidationResources = Record<string, Record<string, unknown>>
39
+
40
+ export type InvalidateQueryInstruction = {
41
+ readonly filters?: Record<string, unknown>
42
+ readonly options?: Record<string, unknown>
43
+ }
44
+
45
+ export type InvalidationCallback<Resources, Input = unknown, Success = unknown, Failure = unknown> = (
46
+ queryKey: readonly string[],
47
+ resources: QueryOnlyResources<Resources>,
48
+ ...args: [Input] extends [void] ? [exit: Exit.Exit<Success, Failure>]
49
+ : [input: Input, exit: Exit.Exit<Success, Failure>]
50
+ ) => ReadonlyArray<InvalidateQueryInstruction>
51
+
52
+ export type InvalidationConfig<Resources, Input = unknown, Success = unknown, Failure = unknown> = {
53
+ readonly invalidatesQueries: InvalidationCallback<Resources, Input, Success, Failure>
54
+ readonly invalidationResources?: Resources
55
+ }
56
+
57
+ type InvalidationConfigForCommand<
58
+ Resources,
59
+ Payload extends S.Struct.Fields,
60
+ Success extends S.Top,
61
+ Error extends S.Top
62
+ > = InvalidationConfig<
63
+ Resources,
64
+ InputFromPayload<Payload>,
65
+ OutputFromSuccess<Success>,
66
+ S.Schema.Type<Error>
67
+ >
68
+
69
+ export const configureInvalidation = <Resources>() =>
70
+ <Input, Success, Failure>(
71
+ invalidatesQueries: InvalidationCallback<Resources, NoInfer<Input>, NoInfer<Success>, NoInfer<Failure>>
72
+ ): InvalidationConfig<Resources, Input, Success, Failure> => ({ invalidatesQueries })
73
+
74
+ export const configureInvalidationCallback = <Resources>() =>
75
+ <Input, Success, Failure>(
76
+ invalidatesQueries: InvalidationCallback<Resources, NoInfer<Input>, NoInfer<Success>, NoInfer<Failure>>
77
+ ): InvalidationCallback<Resources, Input, Success, Failure> => invalidatesQueries
78
+
79
+ export const configureInvalidationResources = <Resources>() =>
80
+ ({}) as Pick<InvalidationConfig<Resources>, "invalidationResources">
81
+
82
+ type TaggedRequestForResult<
83
+ Self,
16
84
  Tag extends string,
17
85
  Payload extends S.Struct.Fields,
18
86
  Success extends S.Top,
19
87
  Error extends S.Top,
20
- Config = Record<string, never>
88
+ Config,
89
+ ModuleName extends string,
90
+ Type extends "command" | "query",
91
+ Resources = never
21
92
  > =
22
- & S.TaggedStruct<Tag, Payload>
93
+ & S.EnhancedClass<Self, TaggedRequestSchema<Tag, Payload>, {}>
23
94
  & {
24
- new(...args: any[]): any
25
95
  readonly _tag: Tag
26
- readonly fields: { readonly _tag: S.tag<Tag> } & Payload
27
96
  readonly success: Success
28
97
  readonly error: Error
29
98
  readonly config: Config
30
99
  readonly "~decodingServices": S.Codec.DecodingServices<Success> | S.Codec.DecodingServices<Error>
100
+ readonly "~encodingServices": S.Codec.EncodingServices<Success> | S.Codec.EncodingServices<Error>
101
+ readonly id: `${ModuleName}.${Tag}`
102
+ readonly moduleName: ModuleName
103
+ readonly type: Type
104
+ readonly "~invalidationResources"?: Resources
31
105
  }
32
106
 
33
107
  export const makeRpcClient = <
34
108
  RequestContextMap extends RequestContextMapTagAny,
35
109
  GeneralErrors extends S.Top = never
36
110
  >(rcs: RequestContextMap, generalErrors?: GeneralErrors) => {
37
- // Long way around ServiceMap/C extends etc to support actual jsdoc from passed in RequestConfig etc... (??)
111
+ // Long way around Context/C extends etc to support actual jsdoc from passed in RequestConfig etc... (??)
38
112
  type ServiceMap = {
39
113
  success: S.Top | S.Struct.Fields // SchemaOrFields will make a Schema type out of Struct.Fields
40
114
  error: S.Top | S.Struct.Fields // SchemaOrFields will make a Schema type out of Struct.Fields
@@ -47,64 +121,246 @@ export const makeRpcClient = <
47
121
  : [GeneralErrors] extends [never] ? GetEffectError<RequestContextMap["config"], C>
48
122
  : MergeError<GetEffectError<RequestContextMap["config"], C>>
49
123
 
50
- function TaggedRequest<_Self>(): {
51
- <Tag extends string, Payload extends S.Struct.Fields, C extends ServiceMap>(
52
- tag: Tag,
53
- fields: Payload,
54
- config: RequestConfig & C
55
- ): TaggedRequestResult<Tag, Payload, SchemaOrFields<C["success"]>, ErrorResult<C>, Omit<C, "success" | "error">>
56
- <Tag extends string, Payload extends S.Struct.Fields, C extends Pick<ServiceMap, "success">>(
57
- tag: Tag,
58
- fields: Payload,
59
- config: RequestConfig & C
60
- ): TaggedRequestResult<Tag, Payload, SchemaOrFields<C["success"]>, ErrorResult<C>, Omit<C, "success" | "error">>
61
- <Tag extends string, Payload extends S.Struct.Fields, C extends Pick<ServiceMap, "error">>(
62
- tag: Tag,
63
- fields: Payload,
64
- config: RequestConfig & C
65
- ): TaggedRequestResult<Tag, Payload, S.Codec<void>, ErrorResult<C>, Omit<C, "success" | "error">>
66
- <Tag extends string, Payload extends S.Struct.Fields, C extends Record<string, any>>(
67
- tag: Tag,
68
- fields: Payload,
69
- config: C & RequestConfig
70
- ): TaggedRequestResult<Tag, Payload, S.Codec<void>, ErrorResult<C>, Omit<C, "success" | "error">>
71
- <Tag extends string, Payload extends S.Struct.Fields>(
72
- tag: Tag,
73
- fields: Payload
74
- ): TaggedRequestResult<Tag, Payload, S.Codec<void>, ErrorResult<never>, Record<string, never>>
75
- } {
76
- // TODO: filter errors based on config + take care of inversion
77
- const errorSchemas = Object.values(rcs.config).map((_) => _.error)
78
- return (<Tag extends string, Fields extends S.Struct.Fields, C extends ServiceMap>(
79
- tag: Tag,
80
- fields: Fields,
81
- config?: C
82
- ) => {
83
- // TODO: S.TaggedRequest removed in v4 needs rework to use Rpc.make or Request.TaggedClass
84
- // For now, creating a simple tagged struct class with success/failure properties
85
- const failureSchema = merge(
86
- config?.error ? S.isSchema(config.error) ? config.error : S.Struct(config.error) : undefined,
87
- [...errorSchemas, generalErrors].filter(Boolean)
88
- )
89
- const successSchema = config?.success
90
- ? S.isSchema(config.success)
91
- ? AST.isVoid(config.success.ast) ? ForceVoid : config.success
92
- : S.Struct(config.success)
93
- : ForceVoid
94
-
95
- const RequestClass = S.TaggedClass<any>()(tag, fields)
96
- Object.assign(RequestClass, {
97
- _tag: tag,
98
- success: successSchema,
99
- error: failureSchema,
100
- config
101
- })
102
-
103
- return RequestClass
104
- }) as any
124
+ // TODO: filter errors based on config + take care of inversion
125
+ const errorSchemas = Object.values(rcs.config).map((_) => _.error)
126
+
127
+ function makeRequestClass<Tag extends string, Fields extends S.Struct.Fields, C extends Partial<ServiceMap>>(
128
+ tag: Tag,
129
+ fields: Fields,
130
+ config?: C
131
+ ) {
132
+ const failureSchema = merge(
133
+ config?.error ? S.isSchema(config.error) ? config.error : S.Struct(config.error) : undefined,
134
+ [...errorSchemas, generalErrors].filter(Boolean)
135
+ )
136
+ const successSchema = config?.success
137
+ ? S.isSchema(config.success)
138
+ ? AST.isVoid(config.success.ast) ? ForceVoid : config.success
139
+ : S.Struct(config.success)
140
+ : ForceVoid
141
+
142
+ const RequestClass = S.TaggedClass<any>()(tag, fields)
143
+ Object.assign(RequestClass, {
144
+ _tag: tag,
145
+ success: successSchema,
146
+ error: failureSchema,
147
+ config
148
+ })
149
+
150
+ return RequestClass
151
+ }
152
+
153
+ function makeTaggedRequestWithMeta<ModuleName extends string, Type extends "command" | "query">(
154
+ moduleName: ModuleName,
155
+ type: Type
156
+ ) {
157
+ function TaggedRequestWithMeta<Self, Resources extends InvalidationResources = never>(): {
158
+ <
159
+ Tag extends string,
160
+ Payload extends S.Struct.Fields,
161
+ Success extends S.Top | S.Struct.Fields,
162
+ Error extends S.Top | S.Struct.Fields,
163
+ C extends RequestConfig & Record<string, any>
164
+ >(
165
+ tag: Tag,
166
+ fields: Payload,
167
+ config:
168
+ & Omit<C, "invalidatesQueries">
169
+ & { success: Success; error: Error },
170
+ invalidatesQueries?: InvalidationCallback<
171
+ Resources,
172
+ InputFromPayload<Payload>,
173
+ OutputFromSuccess<SchemaOrFields<Success>>,
174
+ S.Schema.Type<ErrorResult<C & { success: Success; error: Error }>>
175
+ >
176
+ ): TaggedRequestForResult<
177
+ Self,
178
+ Tag,
179
+ Payload,
180
+ SchemaOrFields<Success>,
181
+ ErrorResult<C & { success: Success; error: Error }>,
182
+ Omit<
183
+ & Omit<C, "invalidatesQueries">
184
+ & {
185
+ success: Success
186
+ error: Error
187
+ }
188
+ & Partial<
189
+ InvalidationConfigForCommand<
190
+ Resources,
191
+ Payload,
192
+ SchemaOrFields<Success>,
193
+ ErrorResult<C & { success: Success; error: Error }>
194
+ >
195
+ >,
196
+ "success" | "error"
197
+ >,
198
+ ModuleName,
199
+ Type,
200
+ Resources
201
+ >
202
+ <
203
+ Tag extends string,
204
+ Payload extends S.Struct.Fields,
205
+ Success extends S.Top | S.Struct.Fields,
206
+ C extends RequestConfig & Record<string, any> & { error?: never }
207
+ >(
208
+ tag: Tag,
209
+ fields: Payload,
210
+ config:
211
+ & Omit<C, "invalidatesQueries">
212
+ & { success: Success },
213
+ invalidatesQueries?: InvalidationCallback<
214
+ Resources,
215
+ InputFromPayload<Payload>,
216
+ OutputFromSuccess<SchemaOrFields<Success>>,
217
+ S.Schema.Type<ErrorResult<C & { success: Success }>>
218
+ >
219
+ ): TaggedRequestForResult<
220
+ Self,
221
+ Tag,
222
+ Payload,
223
+ SchemaOrFields<Success>,
224
+ ErrorResult<C & { success: Success }>,
225
+ Omit<
226
+ & Omit<C, "invalidatesQueries">
227
+ & {
228
+ success: Success
229
+ }
230
+ & Partial<
231
+ InvalidationConfigForCommand<
232
+ Resources,
233
+ Payload,
234
+ SchemaOrFields<Success>,
235
+ ErrorResult<C & { success: Success }>
236
+ >
237
+ >,
238
+ "success" | "error"
239
+ >,
240
+ ModuleName,
241
+ Type,
242
+ Resources
243
+ >
244
+ <
245
+ Tag extends string,
246
+ Payload extends S.Struct.Fields,
247
+ Error extends S.Top | S.Struct.Fields,
248
+ C extends RequestConfig & Record<string, any> & { success?: never }
249
+ >(
250
+ tag: Tag,
251
+ fields: Payload,
252
+ config:
253
+ & Omit<C, "invalidatesQueries">
254
+ & { error: Error },
255
+ invalidatesQueries?: InvalidationCallback<
256
+ Resources,
257
+ InputFromPayload<Payload>,
258
+ void,
259
+ S.Schema.Type<ErrorResult<C & { error: Error }>>
260
+ >
261
+ ): TaggedRequestForResult<
262
+ Self,
263
+ Tag,
264
+ Payload,
265
+ typeof ForceVoid,
266
+ ErrorResult<C & { error: Error }>,
267
+ Omit<
268
+ & Omit<C, "invalidatesQueries">
269
+ & {
270
+ error: Error
271
+ }
272
+ & Partial<
273
+ InvalidationConfigForCommand<
274
+ Resources,
275
+ Payload,
276
+ typeof ForceVoid,
277
+ ErrorResult<C & { error: Error }>
278
+ >
279
+ >,
280
+ "success" | "error"
281
+ >,
282
+ ModuleName,
283
+ Type,
284
+ Resources
285
+ >
286
+ <
287
+ Tag extends string,
288
+ Payload extends S.Struct.Fields,
289
+ C extends RequestConfig & Record<string, any> & { success?: never; error?: never }
290
+ >(
291
+ tag: Tag,
292
+ fields: Payload,
293
+ config: Omit<C, "invalidatesQueries">,
294
+ invalidatesQueries?: InvalidationCallback<
295
+ Resources,
296
+ InputFromPayload<Payload>,
297
+ void,
298
+ S.Schema.Type<ErrorResult<C>>
299
+ >
300
+ ): TaggedRequestForResult<
301
+ Self,
302
+ Tag,
303
+ Payload,
304
+ typeof ForceVoid,
305
+ ErrorResult<C>,
306
+ Omit<
307
+ & Omit<C, "invalidatesQueries">
308
+ & Partial<InvalidationConfigForCommand<Resources, Payload, typeof ForceVoid, ErrorResult<C>>>,
309
+ "success" | "error"
310
+ >,
311
+ ModuleName,
312
+ Type,
313
+ Resources
314
+ >
315
+ <Tag extends string, Payload extends S.Struct.Fields>(
316
+ tag: Tag,
317
+ fields: Payload
318
+ ): TaggedRequestForResult<
319
+ Self,
320
+ Tag,
321
+ Payload,
322
+ typeof ForceVoid,
323
+ ErrorResult<{}>,
324
+ Record<string, never>,
325
+ ModuleName,
326
+ Type
327
+ >
328
+ } {
329
+ return (<Tag extends string, Fields extends S.Struct.Fields, C extends ServiceMap>(
330
+ tag: Tag,
331
+ fields: Fields,
332
+ config?: C,
333
+ invalidatesQueries?: InvalidationCallback<Resources, unknown, unknown, unknown>
334
+ ) => {
335
+ const requestConfig = invalidatesQueries === undefined ? config : { ...config, invalidatesQueries }
336
+ const cls = makeRequestClass(tag, fields, requestConfig)
337
+ Object.assign(cls, { id: `${moduleName}.${tag}`, moduleName, type })
338
+ return cls
339
+ }) as any
340
+ }
341
+ return Object.assign(TaggedRequestWithMeta, { moduleName, type } as const)
342
+ }
343
+
344
+ function TaggedRequestFor<ModuleName extends string>(moduleName: ModuleName) {
345
+ const Query = makeTaggedRequestWithMeta(moduleName, "query")
346
+ const Command = makeTaggedRequestWithMeta(moduleName, "command")
347
+
348
+ return {
349
+ moduleName,
350
+ /**
351
+ * Create query request classes for this module.
352
+ * Queries read state and should not mutate server state.
353
+ */
354
+ Query,
355
+ /**
356
+ * Create command request classes for this module.
357
+ * Commands mutate state and should avoid returning complex read models.
358
+ */
359
+ Command
360
+ } as const
105
361
  }
106
362
 
107
363
  return {
108
- TaggedRequest
364
+ TaggedRequestFor
109
365
  }
110
366
  }
@@ -1,3 +1,4 @@
1
+ import { Option } from "effect"
1
2
  import type { HttpClientResponse } from "effect/unstable/http/HttpClientResponse"
2
3
  import * as Effect from "../Effect.js"
3
4
  import { HttpClient, HttpClientError, HttpClientRequest, HttpHeaders } from "./internal/lib.js"
@@ -24,16 +25,18 @@ export const demandJson = (client: HttpClient.HttpClient) =>
24
25
  .mapRequest(client, (_) => HttpClientRequest.acceptJson(_))
25
26
  .pipe(HttpClient.transform((r, request) =>
26
27
  Effect.tap(r, (response) =>
27
- HttpHeaders
28
- .get(response.headers, "Content-Type")
29
- ?.startsWith("application/json")
28
+ Option
29
+ .exists(
30
+ HttpHeaders.get(response.headers, "Content-Type"),
31
+ (_) => _.startsWith("application/json")
32
+ )
30
33
  ? Effect.void
31
34
  : Effect.fail(
32
35
  new HttpClientError.DecodeError({
33
36
  request,
34
37
  response,
35
38
  description: "not json response: "
36
- + HttpHeaders.get(response.headers, "Content-Type")
39
+ + Option.getOrElse(HttpHeaders.get(response.headers, "Content-Type"), () => "<missing>")
37
40
  })
38
41
  ))
39
42
  ))
package/src/ids.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Effect } from "effect"
1
2
  import { brandedStringId, type Codec, NonEmptyString255, StringId, type StringIdBrand, withDefaultMake } from "effect-app/Schema"
2
3
  import type { B } from "effect-app/Schema/schema"
3
4
  import type { Simplify } from "effect/Types"
@@ -17,7 +18,7 @@ export const RequestId = extendM(
17
18
  const make = StringId.make as () => NonEmptyString255
18
19
  return ({
19
20
  make,
20
- withDefault: s.pipe(S.withDefaultConstructor(make))
21
+ withDefault: S.withConstructorDefault(Effect.sync(make))(s as typeof s & S.WithoutConstructorDefault)
21
22
  })
22
23
  }
23
24
  )
package/src/index.ts CHANGED
@@ -1,24 +1,18 @@
1
+ // eslint-disable-next-line import/no-unassigned-import
1
2
  import "./builtin.js"
2
3
 
3
- import * as ServiceMap from "./ServiceMap.js"
4
-
5
4
  export * as Fnc from "./Function.js"
6
5
  export * as Utils from "./utils.js"
7
6
 
8
7
  export * as Array from "./Array.js"
8
+ export * as Config from "./Config.js"
9
+ export * as ConfigProvider from "./ConfigProvider.js"
10
+ export * as Context from "./Context.js"
9
11
  export * as Effect from "./Effect.js"
10
12
  export * as Layer from "./Layer.js"
11
13
  export * as NonEmptySet from "./NonEmptySet.js"
12
- export * as ServiceMap from "./ServiceMap.js"
13
14
  export * as Set from "./Set.js"
14
15
 
15
- export {
16
- /**
17
- * @deprecated use ServiceMap directly instead
18
- */
19
- ServiceMap as Context
20
- }
21
-
22
16
  export { type NonEmptyArray, type NonEmptyReadonlyArray } from "./Array.js"
23
17
 
24
18
  export * from "effect"
@@ -26,5 +20,6 @@ export * from "effect"
26
20
  export type * as Types from "./Types.js"
27
21
 
28
22
  export * as SecretURL from "./Config/SecretURL.js"
23
+ export * as RpcX from "./rpc.js"
29
24
  export * as S from "./Schema.js"
30
25
  export { copy } from "./utils.js"
package/src/middleware.ts CHANGED
@@ -1,20 +1,18 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ServiceMap } from "effect-app"
3
- import { RpcX } from "./rpc.js"
2
+ import { Context } from "effect-app"
3
+ import { RpcMiddleware } from "./rpc.js"
4
4
 
5
- export class DevMode extends ServiceMap.Reference("DevMode", { defaultValue: () => false }) {}
5
+ export class DevMode extends Context.Reference("DevMode", { defaultValue: () => false }) {}
6
6
 
7
- export class RequestCacheMiddleware
8
- extends RpcX.RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware")
9
- {}
7
+ export class RequestCacheMiddleware extends RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware") {}
10
8
 
11
9
  export class ConfigureInterruptibilityMiddleware
12
- extends RpcX.RpcMiddleware.Tag<ConfigureInterruptibilityMiddleware>()("ConfigureInterruptibilityMiddleware")
10
+ extends RpcMiddleware.Tag<ConfigureInterruptibilityMiddleware>()("ConfigureInterruptibilityMiddleware")
13
11
  {}
14
12
 
15
- export class LoggerMiddleware extends RpcX.RpcMiddleware.Tag<LoggerMiddleware>()("LoggerMiddleware") {}
13
+ export class LoggerMiddleware extends RpcMiddleware.Tag<LoggerMiddleware>()("LoggerMiddleware") {}
16
14
 
17
- export class DevModeMiddleware extends RpcX.RpcMiddleware.Tag<DevModeMiddleware>()("DevModeMiddleware") {}
15
+ export class DevModeMiddleware extends RpcMiddleware.Tag<DevModeMiddleware>()("DevModeMiddleware") {}
18
16
 
19
17
  export const DefaultGenericMiddlewares = [
20
18
  RequestCacheMiddleware,