effect 4.0.0-beta.97 → 4.0.0-beta.98

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 (166) hide show
  1. package/dist/LayerRef.d.ts +4 -6
  2. package/dist/LayerRef.d.ts.map +1 -1
  3. package/dist/LayerRef.js +4 -6
  4. package/dist/LayerRef.js.map +1 -1
  5. package/dist/Number.d.ts.map +1 -1
  6. package/dist/Number.js +28 -10
  7. package/dist/Number.js.map +1 -1
  8. package/dist/Schema.d.ts +22 -22
  9. package/dist/Schema.d.ts.map +1 -1
  10. package/dist/Schema.js +36 -33
  11. package/dist/Schema.js.map +1 -1
  12. package/dist/SchemaAST.d.ts.map +1 -1
  13. package/dist/SchemaAST.js +25 -10
  14. package/dist/SchemaAST.js.map +1 -1
  15. package/dist/SchemaError.d.ts +53 -0
  16. package/dist/SchemaError.d.ts.map +1 -0
  17. package/dist/SchemaError.js +61 -0
  18. package/dist/SchemaError.js.map +1 -0
  19. package/dist/SchemaGetter.d.ts.map +1 -1
  20. package/dist/SchemaGetter.js +17 -12
  21. package/dist/SchemaGetter.js.map +1 -1
  22. package/dist/SchemaRepresentation.d.ts.map +1 -1
  23. package/dist/SchemaRepresentation.js +186 -224
  24. package/dist/SchemaRepresentation.js.map +1 -1
  25. package/dist/index.d.ts +8 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +8 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/internal/effect.js +26 -8
  30. package/dist/internal/effect.js.map +1 -1
  31. package/dist/internal/schema/equivalence.js +1 -2
  32. package/dist/internal/schema/equivalence.js.map +1 -1
  33. package/dist/internal/schema/representation.js +1 -3
  34. package/dist/internal/schema/representation.js.map +1 -1
  35. package/dist/internal/schema/schema.d.ts +0 -13
  36. package/dist/internal/schema/schema.d.ts.map +1 -1
  37. package/dist/internal/schema/schema.js +4 -29
  38. package/dist/internal/schema/schema.js.map +1 -1
  39. package/dist/unstable/ai/McpSchema.d.ts +128 -128
  40. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  41. package/dist/unstable/cli/CliError.d.ts +8 -16
  42. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  43. package/dist/unstable/cli/CliError.js +8 -16
  44. package/dist/unstable/cli/CliError.js.map +1 -1
  45. package/dist/unstable/cli/Command.d.ts +4 -3
  46. package/dist/unstable/cli/Command.d.ts.map +1 -1
  47. package/dist/unstable/cli/Command.js +3 -3
  48. package/dist/unstable/cli/Command.js.map +1 -1
  49. package/dist/unstable/cli/GlobalFlag.d.ts +6 -8
  50. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  51. package/dist/unstable/cli/GlobalFlag.js +6 -6
  52. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  53. package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
  54. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  55. package/dist/unstable/cluster/EntityProxyServer.js +2 -4
  56. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  57. package/dist/unstable/cluster/internal/entityManager.js +15 -12
  58. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  59. package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
  60. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  61. package/dist/unstable/httpapi/HttpApi.js +19 -20
  62. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  63. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
  64. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  65. package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
  66. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
  68. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiClient.js +40 -30
  70. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
  72. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
  74. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  75. package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
  76. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  77. package/dist/unstable/httpapi/HttpApiError.js +31 -0
  78. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  79. package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
  80. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  81. package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
  82. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
  84. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  87. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
  89. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  90. package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
  91. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  92. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  93. package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
  94. package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
  95. package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
  96. package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
  97. package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
  98. package/dist/unstable/httpapi/HttpApiTest.js +9 -8
  99. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  100. package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
  101. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  102. package/dist/unstable/httpapi/OpenApi.js +77 -37
  103. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  104. package/dist/unstable/httpapi/internal/html.js +6 -2
  105. package/dist/unstable/httpapi/internal/html.js.map +1 -1
  106. package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
  107. package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
  108. package/dist/unstable/httpapi/internal/mediaType.js +7 -0
  109. package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
  110. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  111. package/dist/unstable/persistence/PersistedQueue.js +16 -12
  112. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  113. package/dist/unstable/reactivity/Atom.js +1 -1
  114. package/dist/unstable/reactivity/Atom.js.map +1 -1
  115. package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
  116. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  117. package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
  118. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  119. package/dist/unstable/rpc/RpcServer.d.ts +3 -1
  120. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  121. package/dist/unstable/rpc/RpcServer.js +6 -3
  122. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  123. package/dist/unstable/workflow/DurableDeferred.js +1 -1
  124. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  125. package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
  126. package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
  127. package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
  128. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/LayerRef.ts +4 -6
  131. package/src/Number.ts +29 -10
  132. package/src/Schema.ts +42 -34
  133. package/src/SchemaAST.ts +25 -13
  134. package/src/SchemaError.ts +64 -0
  135. package/src/SchemaGetter.ts +22 -16
  136. package/src/SchemaRepresentation.ts +165 -202
  137. package/src/index.ts +10 -0
  138. package/src/internal/effect.ts +39 -22
  139. package/src/internal/schema/equivalence.ts +1 -2
  140. package/src/internal/schema/representation.ts +4 -4
  141. package/src/internal/schema/schema.ts +4 -37
  142. package/src/unstable/cli/CliError.ts +24 -16
  143. package/src/unstable/cli/Command.ts +8 -8
  144. package/src/unstable/cli/GlobalFlag.ts +22 -33
  145. package/src/unstable/cluster/EntityProxyServer.ts +15 -17
  146. package/src/unstable/cluster/internal/entityManager.ts +48 -34
  147. package/src/unstable/httpapi/HttpApi.ts +72 -47
  148. package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
  149. package/src/unstable/httpapi/HttpApiClient.ts +196 -151
  150. package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
  151. package/src/unstable/httpapi/HttpApiError.ts +33 -0
  152. package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
  153. package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
  154. package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
  155. package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
  156. package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
  157. package/src/unstable/httpapi/HttpApiTest.ts +15 -14
  158. package/src/unstable/httpapi/OpenApi.ts +74 -36
  159. package/src/unstable/httpapi/internal/html.ts +9 -2
  160. package/src/unstable/httpapi/internal/mediaType.ts +6 -0
  161. package/src/unstable/persistence/PersistedQueue.ts +16 -14
  162. package/src/unstable/reactivity/Atom.ts +1 -1
  163. package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
  164. package/src/unstable/rpc/RpcServer.ts +10 -4
  165. package/src/unstable/workflow/DurableDeferred.ts +1 -1
  166. package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
@@ -10,12 +10,12 @@
10
10
  */
11
11
  import type { NonEmptyReadonlyArray } from "../../Array.ts"
12
12
  import * as Context from "../../Context.ts"
13
+ import * as internalRecord from "../../internal/record.ts"
13
14
  import { type Pipeable, pipeArguments } from "../../Pipeable.ts"
14
15
  import * as Predicate from "../../Predicate.ts"
15
16
  import * as Record from "../../Record.ts"
16
17
  import type * as Schema from "../../Schema.ts"
17
18
  import type * as SchemaAST from "../../SchemaAST.ts"
18
- import type { Mutable } from "../../Types.ts"
19
19
  import type { PathInput } from "../http/HttpRouter.ts"
20
20
  import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
21
21
  import type * as HttpApiGroup from "./HttpApiGroup.ts"
@@ -30,7 +30,14 @@ const TypeId = "~effect/httpapi/HttpApi"
30
30
  * @category guards
31
31
  * @since 4.0.0
32
32
  */
33
- export const isHttpApi = (u: unknown): u is Any => Predicate.hasProperty(u, TypeId)
33
+ export const isHttpApi = (u: unknown): u is Top => Predicate.hasProperty(u, TypeId)
34
+
35
+ /**
36
+ * Groups indexed by their identifier.
37
+ */
38
+ type GroupMap<Groups> = {
39
+ readonly [Group in Groups as HttpApiGroup.Identifier<Group>]: Group
40
+ }
34
41
 
35
42
  /**
36
43
  * An `HttpApi` is a collection of HTTP API groups and endpoints that represents a
@@ -46,23 +53,38 @@ export const isHttpApi = (u: unknown): u is Any => Predicate.hasProperty(u, Type
46
53
  */
47
54
  export interface HttpApi<
48
55
  out Id extends string,
49
- out Groups extends HttpApiGroup.Any = never
56
+ in out Groups extends HttpApiGroup.Constraint = never
50
57
  > extends Pipeable {
51
58
  new(_: never): {}
52
59
  readonly [TypeId]: typeof TypeId
53
60
  readonly identifier: Id
54
- readonly groups: Record.ReadonlyRecord<string, Groups>
61
+ readonly groups: GroupMap<Groups>
55
62
  readonly annotations: Context.Context<never>
56
63
 
57
64
  /**
58
65
  * Add a `HttpApiGroup` to the `HttpApi`.
59
66
  */
60
- add<const A extends NonEmptyReadonlyArray<HttpApiGroup.Any>>(...groups: A): HttpApi<Id, Groups | A[number]>
67
+ add<const A extends NonEmptyReadonlyArray<HttpApiGroup.Constraint>>(...groups: A): HttpApi<Id, Groups | A[number]>
61
68
 
62
69
  /**
63
- * Add another `HttpApi` to the `HttpApi`.
70
+ * Adds every group from another `HttpApi` while preserving its annotation scope.
71
+ *
72
+ * **When to use**
73
+ *
74
+ * Use when you want to compose an API from groups declared and annotated under another API.
75
+ *
76
+ * **Details**
77
+ *
78
+ * The added API is flattened into this API rather than retained as a nested value. Each added group
79
+ * is copied with the added API's annotations, leaving the added API unchanged. Annotation precedence
80
+ * from least to most specific is this API, the added API, the group, and then the endpoint.
81
+ *
82
+ * **Gotchas**
83
+ *
84
+ * Annotations from the added API do not become top-level annotations of the result and do not affect
85
+ * groups already present in this API. They remain scoped to the groups and endpoints being added.
64
86
  */
65
- addHttpApi<Id2 extends string, Groups2 extends HttpApiGroup.Any>(
87
+ addHttpApi<Id2 extends string, Groups2 extends HttpApiGroup.Constraint>(
66
88
  api: HttpApi<Id2, Groups2>
67
89
  ): HttpApi<Id, Groups | Groups2>
68
90
 
@@ -99,7 +121,7 @@ export interface HttpApi<
99
121
  * @category models
100
122
  * @since 4.0.0
101
123
  */
102
- export interface Any {
124
+ export interface Constraint {
103
125
  readonly [TypeId]: typeof TypeId
104
126
  }
105
127
 
@@ -110,7 +132,7 @@ export interface Any {
110
132
  * @category models
111
133
  * @since 4.0.0
112
134
  */
113
- export type AnyWithProps = HttpApi<string, HttpApiGroup.AnyWithProps>
135
+ export interface Top extends HttpApi<string, HttpApiGroup.Top> {}
114
136
 
115
137
  const Proto = {
116
138
  [TypeId]: TypeId,
@@ -118,69 +140,72 @@ const Proto = {
118
140
  return pipeArguments(this, arguments)
119
141
  },
120
142
  add(
121
- this: AnyWithProps,
122
- ...toAdd: NonEmptyReadonlyArray<HttpApiGroup.AnyWithProps>
143
+ this: Top,
144
+ ...toAdd: NonEmptyReadonlyArray<HttpApiGroup.Top>
123
145
  ) {
124
146
  const groups = { ...this.groups }
125
147
  for (const group of toAdd) {
126
- groups[group.identifier] = group
148
+ internalRecord.set(groups, group.identifier, group)
127
149
  }
128
150
  return makeProto({
129
- identifier: this.identifier,
130
- groups,
131
- annotations: this.annotations
151
+ ...optionsFromApi(this),
152
+ groups
132
153
  })
133
154
  },
134
155
  addHttpApi(
135
- this: AnyWithProps,
136
- api: AnyWithProps
156
+ this: Top,
157
+ api: Top
137
158
  ) {
138
159
  const newGroups = { ...this.groups }
139
160
  for (const key in api.groups) {
140
- const newGroup: Mutable<HttpApiGroup.AnyWithProps> = api.groups[key]
141
- newGroup.annotations = Context.merge(api.annotations, newGroup.annotations)
142
- newGroups[key] = newGroup as any
161
+ const group = api.groups[key]
162
+ internalRecord.set(
163
+ newGroups,
164
+ key,
165
+ group.annotateMerge(Context.merge(api.annotations, group.annotations))
166
+ )
143
167
  }
144
168
  return makeProto({
145
- identifier: this.identifier,
146
- groups: newGroups,
147
- annotations: this.annotations
169
+ ...optionsFromApi(this),
170
+ groups: newGroups
148
171
  })
149
172
  },
150
- prefix(this: AnyWithProps, prefix: PathInput) {
173
+ prefix(this: Top, prefix: PathInput) {
151
174
  return makeProto({
152
- identifier: this.identifier,
153
- groups: Record.map(this.groups, (group) => group.prefix(prefix)),
154
- annotations: this.annotations
175
+ ...optionsFromApi(this),
176
+ groups: Record.map(this.groups, (group) => group.prefix(prefix))
155
177
  })
156
178
  },
157
- middleware(this: AnyWithProps, tag: HttpApiMiddleware.AnyService) {
179
+ middleware(this: Top, tag: HttpApiMiddleware.AnyService) {
158
180
  return makeProto({
159
- identifier: this.identifier,
160
- groups: Record.map(this.groups, (group) => group.middleware(tag as any)),
161
- annotations: this.annotations
181
+ ...optionsFromApi(this),
182
+ groups: Record.map(this.groups, (group) => group.middleware(tag as any))
162
183
  })
163
184
  },
164
- annotate(this: AnyWithProps, key: Context.Key<any, any>, value: any) {
185
+ annotate(this: Top, key: Context.Key<any, any>, value: any) {
165
186
  return makeProto({
166
- identifier: this.identifier,
167
- groups: this.groups,
187
+ ...optionsFromApi(this),
168
188
  annotations: Context.add(this.annotations, key, value)
169
189
  })
170
190
  },
171
- annotateMerge(this: AnyWithProps, annotations: Context.Context<never>) {
191
+ annotateMerge(this: Top, annotations: Context.Context<never>) {
172
192
  return makeProto({
173
- identifier: this.identifier,
174
- groups: this.groups,
193
+ ...optionsFromApi(this),
175
194
  annotations: Context.merge(this.annotations, annotations)
176
195
  })
177
196
  }
178
197
  }
179
198
 
180
- const makeProto = <Id extends string, Groups extends HttpApiGroup.Any>(
199
+ const optionsFromApi = (api: Top) => ({
200
+ identifier: api.identifier,
201
+ groups: api.groups,
202
+ annotations: api.annotations
203
+ })
204
+
205
+ const makeProto = <Id extends string, Groups extends HttpApiGroup.Constraint>(
181
206
  options: {
182
207
  readonly identifier: Id
183
- readonly groups: Record.ReadonlyRecord<string, Groups>
208
+ readonly groups: Record.ReadonlyRecord<string, HttpApiGroup.Constraint>
184
209
  readonly annotations: Context.Context<never>
185
210
  }
186
211
  ): HttpApi<Id, Groups> => {
@@ -219,22 +244,22 @@ export const make = <const Id extends string>(identifier: Id): HttpApi<Id, never
219
244
  * @category reflection
220
245
  * @since 4.0.0
221
246
  */
222
- export const reflect = <Id extends string, Groups extends HttpApiGroup.Any>(
247
+ export const reflect = <Id extends string, Groups extends HttpApiGroup.Constraint>(
223
248
  self: HttpApi<Id, Groups>,
224
249
  options: {
225
250
  readonly predicate?:
226
251
  | Predicate.Predicate<{
227
- readonly endpoint: HttpApiEndpoint.AnyWithProps
228
- readonly group: HttpApiGroup.AnyWithProps
252
+ readonly endpoint: HttpApiEndpoint.Top
253
+ readonly group: HttpApiGroup.Top
229
254
  }>
230
255
  | undefined
231
256
  readonly onGroup: (options: {
232
- readonly group: HttpApiGroup.AnyWithProps
257
+ readonly group: HttpApiGroup.Top
233
258
  readonly mergedAnnotations: Context.Context<never>
234
259
  }) => void
235
260
  readonly onEndpoint: (options: {
236
- readonly group: HttpApiGroup.AnyWithProps
237
- readonly endpoint: HttpApiEndpoint.AnyWithProps
261
+ readonly group: HttpApiGroup.Top
262
+ readonly endpoint: HttpApiEndpoint.Top
238
263
  readonly mergedAnnotations: Context.Context<never>
239
264
  readonly middleware: ReadonlySet<HttpApiMiddleware.AnyService>
240
265
  readonly successes: ReadonlyMap<number, readonly [Schema.Top, ...Array<Schema.Top>]>
@@ -242,14 +267,14 @@ export const reflect = <Id extends string, Groups extends HttpApiGroup.Any>(
242
267
  }) => void
243
268
  }
244
269
  ) => {
245
- const groups = Object.values(self.groups) as any as Array<HttpApiGroup.AnyWithProps>
270
+ const groups = Object.values(self.groups) as any as Array<HttpApiGroup.Top>
246
271
  for (const group of groups) {
247
272
  const groupAnnotations = Context.merge(self.annotations, group.annotations)
248
273
  options.onGroup({
249
274
  group,
250
275
  mergedAnnotations: groupAnnotations
251
276
  })
252
- const endpoints = Object.values(group.endpoints) as Iterable<HttpApiEndpoint.AnyWithProps>
277
+ const endpoints = Object.values(group.endpoints) as Iterable<HttpApiEndpoint.Top>
253
278
  for (const endpoint of endpoints) {
254
279
  if (
255
280
  options.predicate && !options.predicate({