effect 4.0.0-beta.37 → 4.0.0-beta.39

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 (104) hide show
  1. package/dist/ErrorReporter.d.ts.map +1 -1
  2. package/dist/ErrorReporter.js +3 -2
  3. package/dist/ErrorReporter.js.map +1 -1
  4. package/dist/Queue.d.ts +5 -2
  5. package/dist/Queue.d.ts.map +1 -1
  6. package/dist/Queue.js +5 -2
  7. package/dist/Queue.js.map +1 -1
  8. package/dist/References.d.ts +235 -224
  9. package/dist/References.d.ts.map +1 -1
  10. package/dist/References.js +234 -246
  11. package/dist/References.js.map +1 -1
  12. package/dist/Schedule.d.ts +6 -202
  13. package/dist/Schedule.d.ts.map +1 -1
  14. package/dist/Schedule.js +6 -71
  15. package/dist/Schedule.js.map +1 -1
  16. package/dist/Schema.d.ts +6 -6
  17. package/dist/Schema.d.ts.map +1 -1
  18. package/dist/Schema.js +9 -13
  19. package/dist/Schema.js.map +1 -1
  20. package/dist/SchemaAST.d.ts +5 -0
  21. package/dist/SchemaAST.d.ts.map +1 -1
  22. package/dist/SchemaAST.js.map +1 -1
  23. package/dist/SchemaParser.d.ts.map +1 -1
  24. package/dist/SchemaParser.js +7 -2
  25. package/dist/SchemaParser.js.map +1 -1
  26. package/dist/Stream.d.ts +1 -1
  27. package/dist/Stream.js +1 -1
  28. package/dist/Struct.d.ts +7 -7
  29. package/dist/Struct.d.ts.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/internal/effect.js +1 -5
  33. package/dist/internal/effect.js.map +1 -1
  34. package/dist/internal/references.d.ts +2 -0
  35. package/dist/internal/references.d.ts.map +1 -0
  36. package/dist/internal/references.js +51 -0
  37. package/dist/internal/references.js.map +1 -0
  38. package/dist/unstable/cluster/EntityAddress.d.ts.map +1 -1
  39. package/dist/unstable/cluster/EntityAddress.js +1 -1
  40. package/dist/unstable/cluster/EntityAddress.js.map +1 -1
  41. package/dist/unstable/cluster/Runner.d.ts.map +1 -1
  42. package/dist/unstable/cluster/Runner.js +1 -1
  43. package/dist/unstable/cluster/Runner.js.map +1 -1
  44. package/dist/unstable/cluster/RunnerAddress.d.ts.map +1 -1
  45. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  46. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  47. package/dist/unstable/cluster/ShardId.js +3 -3
  48. package/dist/unstable/cluster/ShardId.js.map +1 -1
  49. package/dist/unstable/eventlog/EventJournal.js +2 -2
  50. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  51. package/dist/unstable/eventlog/EventLog.js +1 -1
  52. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  53. package/dist/unstable/eventlog/SqlEventLogJournal.js +2 -2
  54. package/dist/unstable/eventlog/SqlEventLogJournal.js.map +1 -1
  55. package/dist/unstable/httpapi/HttpApiBuilder.js +9 -8
  56. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  57. package/dist/unstable/httpapi/HttpApiClient.d.ts +36 -20
  58. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  59. package/dist/unstable/httpapi/HttpApiClient.js +49 -18
  60. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  61. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +186 -67
  62. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  63. package/dist/unstable/httpapi/HttpApiEndpoint.js +44 -29
  64. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  65. package/dist/unstable/httpapi/HttpApiSchema.d.ts +5 -0
  66. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  67. package/dist/unstable/httpapi/HttpApiSchema.js +20 -2
  68. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  69. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  70. package/dist/unstable/httpapi/OpenApi.js +2 -5
  71. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  72. package/dist/unstable/reactivity/AtomHttpApi.d.ts +11 -7
  73. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  74. package/dist/unstable/reactivity/AtomHttpApi.js +6 -6
  75. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  76. package/dist/unstable/schema/VariantSchema.d.ts +1 -1
  77. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  78. package/package.json +1 -1
  79. package/src/ErrorReporter.ts +3 -2
  80. package/src/Queue.ts +5 -2
  81. package/src/References.ts +276 -285
  82. package/src/Schedule.ts +7 -212
  83. package/src/Schema.ts +8 -12
  84. package/src/SchemaAST.ts +6 -0
  85. package/src/SchemaParser.ts +7 -2
  86. package/src/Stream.ts +1 -1
  87. package/src/Struct.ts +7 -7
  88. package/src/index.ts +1 -1
  89. package/src/internal/effect.ts +14 -21
  90. package/src/internal/references.ts +72 -0
  91. package/src/unstable/cluster/EntityAddress.ts +1 -1
  92. package/src/unstable/cluster/Runner.ts +1 -1
  93. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  94. package/src/unstable/cluster/ShardId.ts +2 -2
  95. package/src/unstable/eventlog/EventJournal.ts +2 -2
  96. package/src/unstable/eventlog/EventLog.ts +1 -1
  97. package/src/unstable/eventlog/SqlEventLogJournal.ts +2 -2
  98. package/src/unstable/httpapi/HttpApiBuilder.ts +15 -9
  99. package/src/unstable/httpapi/HttpApiClient.ts +118 -55
  100. package/src/unstable/httpapi/HttpApiEndpoint.ts +164 -36
  101. package/src/unstable/httpapi/HttpApiSchema.ts +20 -2
  102. package/src/unstable/httpapi/OpenApi.ts +2 -6
  103. package/src/unstable/reactivity/AtomHttpApi.ts +22 -17
  104. package/src/unstable/schema/VariantSchema.ts +1 -1
@@ -31,6 +31,7 @@ import { constVoid, type LazyArg } from "../../Function.ts"
31
31
  import * as Schema from "../../Schema.ts"
32
32
  import * as AST from "../../SchemaAST.ts"
33
33
  import * as Transformation from "../../SchemaTransformation.ts"
34
+ import { hasBody, type HttpMethod } from "../http/HttpMethod.ts"
34
35
  import type * as Multipart_ from "../http/Multipart.ts"
35
36
 
36
37
  declare module "../../Schema.ts" {
@@ -332,6 +333,17 @@ export function asUint8Array(options?: {
332
333
  return <S extends Schema.Top & { readonly Encoded: Uint8Array }>(self: S) =>
333
334
  asNonMultipartEncoding(self, { _tag: "Uint8Array", ...options })
334
335
  }
336
+ /**
337
+ * @since 4.0.0
338
+ */
339
+ export const isNoContent = (ast: AST.AST): boolean => {
340
+ if (AST.isVoid(ast)) return true
341
+ const encoded = AST.toEncoded(ast)
342
+ if (AST.isVoid(encoded)) return true
343
+ const target = ast.encoding?.[0].to
344
+ if (target === undefined) return false
345
+ return AST.isVoid(target)
346
+ }
335
347
 
336
348
  const resolveHttpApiEncoding = AST.resolveAt<Encoding>("~httpApiEncoding")
337
349
 
@@ -341,14 +353,20 @@ const defaultJsonEncoding: Encoding = {
341
353
  _tag: "Json",
342
354
  contentType: "application/json"
343
355
  }
356
+ const defaultUrlEncodedEncoding: Encoding = {
357
+ _tag: "FormUrlEncoded",
358
+ contentType: "application/x-www-form-urlencoded"
359
+ }
344
360
 
345
361
  function getEncoding(ast: AST.AST): Encoding {
346
362
  return resolveHttpApiEncoding(ast) ?? defaultJsonEncoding
347
363
  }
348
364
 
349
365
  /** @internal */
350
- export function getPayloadEncoding(ast: AST.AST): PayloadEncoding {
351
- return getEncoding(ast)
366
+ export function getPayloadEncoding(ast: AST.AST, method: HttpMethod): PayloadEncoding {
367
+ const encoding = resolveHttpApiEncoding(ast)
368
+ if (encoding) return encoding
369
+ return hasBody(method) ? defaultJsonEncoding : defaultUrlEncodedEncoding
352
370
  }
353
371
 
354
372
  /** @internal */
@@ -314,7 +314,7 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
314
314
  const c: OpenApiSpecContent = {}
315
315
  let hasContent = false
316
316
  payloadMap.forEach(({ encoding, schemas }, contentType) => {
317
- const filtered = schemas.filter((s) => !isNoContent(s.ast))
317
+ const filtered = schemas.filter((s) => !HttpApiSchema.isNoContent(s.ast))
318
318
  if (filtered.length === 0) return
319
319
  hasContent = true
320
320
  const asts = filtered.map(AST.getAST)
@@ -529,10 +529,6 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
529
529
  return spec
530
530
  }
531
531
 
532
- function isNoContent(ast: AST.AST): boolean {
533
- return AST.isVoid(AST.toEncoded(ast))
534
- }
535
-
536
532
  type ResponseBodies = Map<
537
533
  number, // status
538
534
  {
@@ -558,7 +554,7 @@ function extractResponseBodies(
558
554
  function process(schema: Schema.Top) {
559
555
  const ast = schema.ast
560
556
  const status = getStatus(ast)
561
- if (isNoContent(ast)) {
557
+ if (HttpApiSchema.isNoContent(ast)) {
562
558
  addNoContent(status, getDescription(schema.ast) ?? "<No Content>")
563
559
  } else {
564
560
  addContent(schema, status, HttpApiSchema.getResponseEncoding(ast))
@@ -41,12 +41,12 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
41
41
  HttpApiGroup.Endpoints<Group>,
42
42
  Name
43
43
  >,
44
- const WithResponse extends boolean = false
44
+ const ResponseMode extends HttpApiEndpoint.ClientResponseMode = HttpApiEndpoint.ClientResponseMode
45
45
  >(
46
46
  group: GroupName,
47
47
  endpoint: Name,
48
48
  options?: {
49
- readonly withResponse?: WithResponse | undefined
49
+ readonly responseMode?: ResponseMode | undefined
50
50
  }
51
51
  ) => [Endpoint] extends [
52
52
  HttpApiEndpoint.HttpApiEndpoint<
@@ -64,11 +64,11 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
64
64
  >
65
65
  ] ? Atom.AtomResultFn<
66
66
  Simplify<
67
- HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, false> & {
67
+ HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, "decoded-only"> & {
68
68
  readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
69
69
  }
70
70
  >,
71
- WithResponse extends true ? [_Success["Type"], HttpClientResponse] : _Success["Type"],
71
+ ResponseByMode<_Success["Type"], ResponseMode>,
72
72
  _Error["Type"]
73
73
  >
74
74
  : never
@@ -81,7 +81,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
81
81
  HttpApiGroup.Endpoints<Group>,
82
82
  Name
83
83
  >,
84
- const WithResponse extends boolean = false
84
+ const ResponseMode extends HttpApiEndpoint.ClientResponseMode = "decoded-only"
85
85
  >(
86
86
  group: GroupName,
87
87
  endpoint: Name,
@@ -100,7 +100,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
100
100
  infer _RE
101
101
  >
102
102
  ] ? Simplify<
103
- HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, WithResponse> & {
103
+ HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, ResponseMode> & {
104
104
  readonly reactivityKeys?:
105
105
  | ReadonlyArray<unknown>
106
106
  | ReadonlyRecord<string, ReadonlyArray<unknown>>
@@ -125,7 +125,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
125
125
  >
126
126
  ] ? Atom.Atom<
127
127
  AsyncResult.AsyncResult<
128
- WithResponse extends true ? [_Success["Type"], HttpClientResponse] : _Success["Type"],
128
+ ResponseByMode<_Success["Type"], ResponseMode>,
129
129
  _Error["Type"]
130
130
  >
131
131
  >
@@ -175,7 +175,7 @@ export const Service = <Self>() =>
175
175
  Schema.isSchemaError(e) || HttpClientError.isHttpClientError(e) ? Effect.die(e) : Effect.fail(e)
176
176
  )
177
177
 
178
- const mutationFamily = Atom.family(({ endpoint, group, withResponse }: MutationKey) => {
178
+ const mutationFamily = Atom.family(({ endpoint, group, responseMode }: MutationKey) => {
179
179
  const atom = self.runtime.fn<{
180
180
  params: any
181
181
  query: any
@@ -187,14 +187,14 @@ export const Service = <Self>() =>
187
187
  const client = (yield* self) as any
188
188
  const effect = catchErrors(client[group][endpoint]({
189
189
  ...opts,
190
- withResponse
190
+ responseMode
191
191
  }) as Effect.Effect<any>)
192
192
  return yield* opts.reactivityKeys
193
193
  ? Reactivity.mutation(effect, opts.reactivityKeys)
194
194
  : effect
195
195
  })
196
196
  )
197
- if (withResponse === false) {
197
+ if (responseMode === "decoded-only") {
198
198
  const definition = options.api.groups[group]!.endpoints[endpoint]! as HttpApiEndpoint.AnyWithProps
199
199
  return Atom.serializable(atom, {
200
200
  key: `AtomHttpApi:mutation:${group}:${endpoint}`,
@@ -208,12 +208,12 @@ export const Service = <Self>() =>
208
208
  }) as any
209
209
 
210
210
  self.mutation = ((group: string, endpoint: string, options?: {
211
- readonly withResponse?: boolean | undefined
211
+ readonly responseMode?: HttpApiEndpoint.ClientResponseMode | undefined
212
212
  }) =>
213
213
  mutationFamily({
214
214
  group,
215
215
  endpoint,
216
- withResponse: options?.withResponse ?? false
216
+ responseMode: options?.responseMode ?? "decoded-only"
217
217
  })) as any
218
218
 
219
219
  const queryFamily = Atom.family((opts: QueryKey) => {
@@ -224,7 +224,7 @@ export const Service = <Self>() =>
224
224
  HttpClientError.HttpClientError | SchemaError
225
225
  >)
226
226
  }))
227
- if (opts.withResponse === false) {
227
+ if (opts.responseMode === "decoded-only") {
228
228
  const endpoint = options.api.groups[opts.group]!.endpoints[opts.endpoint]! as HttpApiEndpoint.AnyWithProps
229
229
  atom = Atom.serializable(atom, {
230
230
  key: makeSerializableKey(opts),
@@ -252,7 +252,7 @@ export const Service = <Self>() =>
252
252
  readonly query?: any
253
253
  readonly payload?: any
254
254
  readonly headers?: any
255
- readonly withResponse?: boolean
255
+ readonly responseMode?: HttpApiEndpoint.ClientResponseMode
256
256
  readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
257
257
  readonly timeToLive?: Duration.Input | undefined
258
258
  }
@@ -264,7 +264,7 @@ export const Service = <Self>() =>
264
264
  query: request.query,
265
265
  payload: request.payload,
266
266
  headers: request.headers,
267
- withResponse: request.withResponse ?? false,
267
+ responseMode: request.responseMode ?? "decoded-only",
268
268
  reactivityKeys: request.reactivityKeys,
269
269
  timeToLive: request.timeToLive
270
270
  ? Duration.fromInputUnsafe(request.timeToLive)
@@ -277,7 +277,7 @@ export const Service = <Self>() =>
277
277
  interface MutationKey {
278
278
  group: string
279
279
  endpoint: string
280
- withResponse: boolean
280
+ responseMode: HttpApiEndpoint.ClientResponseMode
281
281
  }
282
282
 
283
283
  interface QueryKey {
@@ -287,11 +287,16 @@ interface QueryKey {
287
287
  query: any
288
288
  headers: any
289
289
  payload: any
290
- withResponse: boolean
290
+ responseMode: HttpApiEndpoint.ClientResponseMode
291
291
  reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
292
292
  timeToLive?: Duration.Duration | undefined
293
293
  }
294
294
 
295
+ type ResponseByMode<Success, ResponseMode extends HttpApiEndpoint.ClientResponseMode> = [ResponseMode] extends
296
+ ["decoded-and-response"] ? [Success, HttpClientResponse]
297
+ : [ResponseMode] extends ["response-only"] ? HttpClientResponse
298
+ : Success
299
+
295
300
  const makeSerializableKey = (
296
301
  key: QueryKey
297
302
  ): string => `AtomHttpApi:${key.group}:${key.endpoint}:${Hash.hash(key)}`
@@ -238,7 +238,7 @@ export interface Class<
238
238
  new(
239
239
  props: S["~type.make.in"],
240
240
  options?: {
241
- readonly disableValidation?: boolean
241
+ readonly disableChecks?: boolean
242
242
  } | undefined
243
243
  ): S["Type"]
244
244