effect 4.0.0-beta.50 → 4.0.0-beta.52

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 (135) hide show
  1. package/dist/BigDecimal.d.ts.map +1 -1
  2. package/dist/BigDecimal.js +18 -14
  3. package/dist/BigDecimal.js.map +1 -1
  4. package/dist/BigInt.d.ts.map +1 -1
  5. package/dist/BigInt.js +4 -4
  6. package/dist/BigInt.js.map +1 -1
  7. package/dist/Brand.d.ts +2 -4
  8. package/dist/Brand.d.ts.map +1 -1
  9. package/dist/Brand.js.map +1 -1
  10. package/dist/Data.js +2 -2
  11. package/dist/Data.js.map +1 -1
  12. package/dist/Duration.js +1 -1
  13. package/dist/Duration.js.map +1 -1
  14. package/dist/Schema.d.ts +77 -10
  15. package/dist/Schema.d.ts.map +1 -1
  16. package/dist/Schema.js +119 -18
  17. package/dist/Schema.js.map +1 -1
  18. package/dist/SchemaAST.d.ts +6 -0
  19. package/dist/SchemaAST.d.ts.map +1 -1
  20. package/dist/SchemaAST.js +216 -229
  21. package/dist/SchemaAST.js.map +1 -1
  22. package/dist/SchemaGetter.d.ts +3 -5
  23. package/dist/SchemaGetter.d.ts.map +1 -1
  24. package/dist/SchemaGetter.js +3 -2
  25. package/dist/SchemaGetter.js.map +1 -1
  26. package/dist/SchemaIssue.d.ts.map +1 -1
  27. package/dist/SchemaIssue.js +29 -11
  28. package/dist/SchemaIssue.js.map +1 -1
  29. package/dist/SchemaParser.js +14 -2
  30. package/dist/SchemaParser.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +3 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/effect.js +142 -65
  36. package/dist/internal/effect.js.map +1 -1
  37. package/dist/internal/schema/representation.js +1 -2
  38. package/dist/internal/schema/representation.js.map +1 -1
  39. package/dist/internal/schema/schema.d.ts.map +1 -1
  40. package/dist/internal/schema/schema.js +37 -0
  41. package/dist/internal/schema/schema.js.map +1 -1
  42. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  43. package/dist/unstable/ai/McpServer.js +7 -0
  44. package/dist/unstable/ai/McpServer.js.map +1 -1
  45. package/dist/unstable/cli/index.d.ts +2 -0
  46. package/dist/unstable/cli/index.d.ts.map +1 -1
  47. package/dist/unstable/cli/index.js +2 -0
  48. package/dist/unstable/cli/index.js.map +1 -1
  49. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  50. package/dist/unstable/cluster/Runners.js +3 -2
  51. package/dist/unstable/cluster/Runners.js.map +1 -1
  52. package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
  53. package/dist/unstable/cluster/SqlMessageStorage.js +1 -0
  54. package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
  55. package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
  56. package/dist/unstable/cluster/SqlRunnerStorage.js +6 -6
  57. package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
  58. package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
  59. package/dist/unstable/eventlog/SqlEventJournal.js +9 -8
  60. package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
  61. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  62. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +6 -5
  63. package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  64. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
  65. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +6 -5
  66. package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  68. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
  70. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
  72. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  74. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +17 -18
  75. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  76. package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
  77. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  78. package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
  79. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  80. package/dist/unstable/httpapi/HttpApiError.js +28 -15
  81. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  82. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  84. package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/OpenApi.d.ts +1 -10
  87. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/OpenApi.js +2 -11
  89. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  90. package/dist/unstable/observability/OtlpMetrics.js +1 -1
  91. package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
  92. package/dist/unstable/observability/internal/protobuf.js +4 -4
  93. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  94. package/dist/unstable/rpc/RpcSerialization.d.ts +11 -0
  95. package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
  96. package/dist/unstable/rpc/RpcSerialization.js +14 -9
  97. package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
  98. package/package.json +1 -1
  99. package/src/BigDecimal.ts +20 -16
  100. package/src/BigInt.ts +4 -4
  101. package/src/Brand.ts +2 -4
  102. package/src/Data.ts +1 -1
  103. package/src/Duration.ts +1 -1
  104. package/src/Schema.ts +183 -23
  105. package/src/SchemaAST.ts +315 -267
  106. package/src/SchemaGetter.ts +4 -6
  107. package/src/SchemaIssue.ts +28 -15
  108. package/src/SchemaParser.ts +8 -2
  109. package/src/index.ts +3 -0
  110. package/src/internal/effect.ts +196 -69
  111. package/src/internal/schema/representation.ts +1 -2
  112. package/src/internal/schema/schema.ts +43 -0
  113. package/src/unstable/ai/McpServer.ts +8 -0
  114. package/src/unstable/cli/index.ts +2 -0
  115. package/src/unstable/cluster/Runners.ts +8 -5
  116. package/src/unstable/cluster/SqlMessageStorage.ts +1 -0
  117. package/src/unstable/cluster/SqlRunnerStorage.ts +12 -6
  118. package/src/unstable/eventlog/SqlEventJournal.ts +10 -2
  119. package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +8 -3
  120. package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +9 -3
  121. package/src/unstable/httpapi/HttpApi.ts +1 -1
  122. package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
  123. package/src/unstable/httpapi/HttpApiClient.ts +5 -6
  124. package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
  125. package/src/unstable/httpapi/HttpApiError.ts +43 -22
  126. package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
  127. package/src/unstable/httpapi/OpenApi.ts +3 -15
  128. package/src/unstable/observability/OtlpMetrics.ts +1 -1
  129. package/src/unstable/observability/internal/protobuf.ts +4 -4
  130. package/src/unstable/rpc/RpcSerialization.ts +41 -36
  131. package/dist/internal/schema/to-codec.d.ts +0 -2
  132. package/dist/internal/schema/to-codec.d.ts.map +0 -1
  133. package/dist/internal/schema/to-codec.js +0 -126
  134. package/dist/internal/schema/to-codec.js.map +0 -1
  135. package/src/internal/schema/to-codec.ts +0 -138
@@ -71,7 +71,7 @@ export const make = (options?: {
71
71
  payload BLOB NOT NULL,
72
72
  timestamp INTEGER NOT NULL
73
73
  )`
74
- })
74
+ }).pipe(withTracerDisabled)
75
75
 
76
76
  yield* sql.onDialectOrElse({
77
77
  pg: () =>
@@ -106,7 +106,7 @@ export const make = (options?: {
106
106
  sequence INT NOT NULL,
107
107
  PRIMARY KEY (remote_id, entry_id)
108
108
  )`
109
- })
109
+ }).pipe(withTracerDisabled)
110
110
 
111
111
  const decodeEntryRows = Schema.decodeUnknownEffect(EntryRowArray)
112
112
  const toEntries = (rows: ReadonlyArray<EntryRow>): ReadonlyArray<EventJournal.Entry> => rows.map(toEntry)
@@ -193,6 +193,7 @@ export const make = (options?: {
193
193
 
194
194
  return EventJournal.EventJournal.of({
195
195
  entries: sql`SELECT * FROM ${entryTableSql} ORDER BY timestamp ASC`.pipe(
196
+ withTracerDisabled,
196
197
  Effect.flatMap(decodeEntryRows),
197
198
  Effect.map(toEntries),
198
199
  Effect.mapError((cause) => new EventJournal.EventJournalError({ cause, method: "entries" }))
@@ -210,10 +211,12 @@ export const make = (options?: {
210
211
  yield* PubSub.publish(pubsub, entry)
211
212
  return value
212
213
  },
214
+ withTracerDisabled,
213
215
  Effect.mapError((cause) => new EventJournal.EventJournalError({ cause, method: "write" }))
214
216
  ),
215
217
  writeFromRemote: (options) =>
216
218
  writeFromRemote(options).pipe(
219
+ withTracerDisabled,
217
220
  Effect.catchIf(
218
221
  (e) => e._tag !== "EventJournalError",
219
222
  (cause) => Effect.fail(new EventJournal.EventJournalError({ cause, method: "writeFromRemote" }))
@@ -232,6 +235,7 @@ export const make = (options?: {
232
235
  )
233
236
  return yield* f(entries)
234
237
  },
238
+ withTracerDisabled,
235
239
  Effect.mapError((cause) => new EventJournal.EventJournalError({ cause, method: "withRemoteUncommited" }))
236
240
  ),
237
241
  nextRemoteSequence: (remoteId) =>
@@ -242,6 +246,7 @@ export const make = (options?: {
242
246
  if (value === null || value === undefined) return 0
243
247
  return Number(value) + 1
244
248
  }),
249
+ withTracerDisabled,
245
250
  Effect.mapError((cause) => new EventJournal.EventJournalError({ cause, method: "nextRemoteSequence" }))
246
251
  ),
247
252
  changes: PubSub.subscribe(pubsub),
@@ -249,6 +254,7 @@ export const make = (options?: {
249
254
  yield* sql`DROP TABLE ${entryTableSql}`
250
255
  yield* sql`DROP TABLE ${remotesTableSql}`
251
256
  }).pipe(
257
+ withTracerDisabled,
252
258
  Effect.mapError((cause) => new EventJournal.EventJournalError({ cause, method: "destroy" }))
253
259
  ),
254
260
  withLock(_storeId) {
@@ -305,3 +311,5 @@ const RemoteRow = Schema.Struct({
305
311
  })
306
312
 
307
313
  const RemoteRowArray = Schema.Array(RemoteRow)
314
+
315
+ const withTracerDisabled = Effect.withTracerEnabled(false)
@@ -148,7 +148,7 @@ export const makeStorage = (options?: {
148
148
  PubSub.shutdown
149
149
  )
150
150
  return { pubsub, table } as const
151
- }),
151
+ }, withTracerDisabled),
152
152
  idleTimeToLive: "5 minutes"
153
153
  })
154
154
 
@@ -182,6 +182,7 @@ export const makeStorage = (options?: {
182
182
  )
183
183
  },
184
184
  sql.withTransaction,
185
+ withTracerDisabled,
185
186
  Effect.orDie
186
187
  ),
187
188
  write: Effect.fnUntraced(
@@ -228,7 +229,8 @@ export const makeStorage = (options?: {
228
229
  return allEntries
229
230
  },
230
231
  Effect.orDie,
231
- Effect.scoped
232
+ Effect.scoped,
233
+ withTracerDisabled
232
234
  ),
233
235
  changes: Effect.fnUntraced(
234
236
  function*(publicKey, storeId, startSequence) {
@@ -243,10 +245,11 @@ export const makeStorage = (options?: {
243
245
  return Stream.fromArray(initial).pipe(Stream.concat(Stream.fromSubscription(subscription)))
244
246
  },
245
247
  Effect.orDie,
248
+ withTracerDisabled,
246
249
  Stream.unwrap
247
250
  )
248
251
  })
249
- })
252
+ }).pipe(withTracerDisabled)
250
253
 
251
254
  const EncryptedRemoteEntrySql = Schema.Struct({
252
255
  sequence: Schema.Number,
@@ -314,3 +317,5 @@ const makeEncryptedScopeKey = (
314
317
  publicKey: string,
315
318
  storeId: string
316
319
  ): string => `${publicKey}/${storeId}`
320
+
321
+ const withTracerDisabled = Effect.withTracerEnabled(false)
@@ -322,7 +322,8 @@ export const makeStorage = (options?: {
322
322
  )
323
323
  },
324
324
  sql.withTransaction,
325
- Effect.orDie
325
+ Effect.orDie,
326
+ withTracerDisabled
326
327
  ),
327
328
  entriesAfter: (storeId, entry) =>
328
329
  sql`
@@ -333,7 +334,8 @@ export const makeStorage = (options?: {
333
334
  `.pipe(
334
335
  Effect.flatMap(decodeRemoteEntries),
335
336
  Effect.map(Arr.map((r) => r.entry)),
336
- Effect.orDie
337
+ Effect.orDie,
338
+ withTracerDisabled
337
339
  ),
338
340
  write: Effect.fnUntraced(
339
341
  function*(storeId, entries) {
@@ -389,6 +391,7 @@ export const makeStorage = (options?: {
389
391
  },
390
392
  Effect.scoped,
391
393
  sql.withTransaction,
394
+ withTracerDisabled,
392
395
  Effect.orDie
393
396
  ),
394
397
  changes: Effect.fnUntraced(
@@ -410,6 +413,7 @@ export const makeStorage = (options?: {
410
413
  )
411
414
  },
412
415
  Effect.orDie,
416
+ withTracerDisabled,
413
417
  Stream.unwrap
414
418
  ),
415
419
  withTransaction: (effect) =>
@@ -417,7 +421,7 @@ export const makeStorage = (options?: {
417
421
  Effect.catchIf(SqlError.isSqlError, Effect.die)
418
422
  )
419
423
  })
420
- })
424
+ }).pipe(withTracerDisabled)
421
425
 
422
426
  /**
423
427
  * @since 4.0.0
@@ -498,3 +502,5 @@ const decodeStoreSequence = (rows: unknown): Effect.Effect<number, Schema.Schema
498
502
  const decodeSessionAuthBindings = (
499
503
  rows: unknown
500
504
  ): Effect.Effect<ReadonlyArray<SessionAuthBindingSql>, Schema.SchemaError> => decodeSessionAuthBindingRows(rows)
505
+
506
+ const withTracerDisabled = Effect.withTracerEnabled(false)
@@ -255,7 +255,7 @@ export const reflect = <Id extends string, Groups extends HttpApiGroup.Any>(
255
255
  // -------------------------------------------------------------------------------------
256
256
 
257
257
  const extractResponseContent = (
258
- schemas: readonly [Schema.Top, ...Array<Schema.Top>],
258
+ schemas: Array<Schema.Top>,
259
259
  getStatus: (ast: AST.AST) => number
260
260
  ): ReadonlyMap<number, [Schema.Top, ...Array<Schema.Top>]> => {
261
261
  const map = new Map<number, [Schema.Top, ...Array<Schema.Top>]>()
@@ -36,6 +36,7 @@ import * as Multipart from "../http/Multipart.ts"
36
36
  import * as UrlParams from "../http/UrlParams.ts"
37
37
  import type * as HttpApi from "./HttpApi.ts"
38
38
  import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
39
+ import { HttpApiSchemaError } from "./HttpApiError.ts"
39
40
  import type * as HttpApiGroup from "./HttpApiGroup.ts"
40
41
  import * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
41
42
  import * as HttpApiSchema from "./HttpApiSchema.ts"
@@ -589,13 +590,13 @@ function handlerToHttpEffect(
589
590
  group
590
591
  }
591
592
  if (decodeParams) {
592
- request.params = yield* decodeParams(routeContext.params)
593
+ request.params = yield* HttpApiSchemaError.wrap("Params", decodeParams(routeContext.params))
593
594
  }
594
595
  if (decodeHeaders) {
595
- request.headers = yield* decodeHeaders(httpRequest.headers)
596
+ request.headers = yield* HttpApiSchemaError.wrap("Headers", decodeHeaders(httpRequest.headers))
596
597
  }
597
598
  if (decodeQuery) {
598
- request.query = yield* decodeQuery(query)
599
+ request.query = yield* HttpApiSchemaError.wrap("Query", decodeQuery(query))
599
600
  }
600
601
  if (payloadBy) {
601
602
  const result = decodePayload(payloadBy, httpRequest, query)
@@ -603,15 +604,20 @@ function handlerToHttpEffect(
603
604
  return result
604
605
  }
605
606
  if (result !== undefined) {
606
- request.payload = yield* result
607
+ request.payload = yield* HttpApiSchemaError.wrap("Payload", result)
607
608
  }
608
609
  }
609
610
  const response = yield* handler(request)
610
- return Response.isHttpServerResponse(response) ? response : yield* encodeSuccess(response)
611
+ return Response.isHttpServerResponse(response)
612
+ ? response
613
+ : yield* HttpApiSchemaError.wrap("Body", encodeSuccess(response))
611
614
  })
612
615
  ).pipe(
613
616
  Effect.withErrorReporting,
614
- Effect.catch((error) => Effect.orDie(encodeError(error))),
617
+ Effect.catch((error) => {
618
+ if (HttpApiSchemaError.is(error)) return Effect.die(error)
619
+ return Effect.orDie(encodeError(error))
620
+ }),
615
621
  Effect.provideContext(context)
616
622
  )
617
623
  }
@@ -719,6 +725,7 @@ function makeSuccessSchema(endpoint: HttpApiEndpoint.AnyWithProps): Schema.Encod
719
725
 
720
726
  function makeErrorSchema(endpoint: HttpApiEndpoint.AnyWithProps): Schema.Encoder<HttpServerResponse, unknown> {
721
727
  const schemas = HttpApiEndpoint.getErrorSchemas(endpoint).map(toResponseErrorSchema)
728
+ if (schemas.length === 0) return Schema.Never
722
729
  return schemas.length === 1 ? schemas[0] : Schema.Union(schemas)
723
730
  }
724
731
 
@@ -23,7 +23,6 @@ import * as HttpMethod from "../http/HttpMethod.ts"
23
23
  import * as UrlParams from "../http/UrlParams.ts"
24
24
  import * as HttpApi from "./HttpApi.ts"
25
25
  import * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
26
- import type { BadRequest } from "./HttpApiError.ts"
27
26
  import type * as HttpApiGroup from "./HttpApiGroup.ts"
28
27
  import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
29
28
  import * as HttpApiSchema from "./HttpApiSchema.ts"
@@ -32,7 +31,7 @@ import * as HttpApiSchema from "./HttpApiSchema.ts"
32
31
  * @since 4.0.0
33
32
  * @category models
34
33
  */
35
- export type Client<Groups extends HttpApiGroup.Any, E = BadRequest, R = never> = Simplify<
34
+ export type Client<Groups extends HttpApiGroup.Any, E = never, R = never> = Simplify<
36
35
  & {
37
36
  readonly [Group in Extract<Groups, { readonly topLevel: false }> as HttpApiGroup.Name<Group>]: Client.Group<
38
37
  Group,
@@ -50,7 +49,7 @@ export type Client<Groups extends HttpApiGroup.Any, E = BadRequest, R = never> =
50
49
  * @since 4.0.0
51
50
  * @category models
52
51
  */
53
- export type ForApi<Api extends HttpApi.Any, E = BadRequest, R = never> = Api extends
52
+ export type ForApi<Api extends HttpApi.Any, E = never, R = never> = Api extends
54
53
  HttpApi.HttpApi<infer _Id, infer Groups> ? Client<Groups, E, R> :
55
54
  never
56
55
 
@@ -405,7 +404,7 @@ export const makeWith = <ApiId extends string, Groups extends HttpApiGroup.Any,
405
404
  | undefined
406
405
  readonly baseUrl?: URL | string | undefined
407
406
  }
408
- ): Effect.Effect<Client<Groups, BadRequest | E, R>, never, HttpApiGroup.MiddlewareClient<Groups>> => {
407
+ ): Effect.Effect<Client<Groups, E, R>, never, HttpApiGroup.MiddlewareClient<Groups>> => {
409
408
  const client: Record<string, Record<string, any>> = {}
410
409
  return makeClient(api, {
411
410
  ...options,
@@ -440,7 +439,7 @@ export const group = <
440
439
  readonly baseUrl?: URL | string | undefined
441
440
  }
442
441
  ): Effect.Effect<
443
- Client.Group<Groups, GroupName, BadRequest | E, R>,
442
+ Client.Group<Groups, GroupName, E, R>,
444
443
  never,
445
444
  HttpApiGroup.MiddlewareClient<HttpApiGroup.WithName<Groups, GroupName>>
446
445
  > => {
@@ -480,7 +479,7 @@ export const endpoint = <
480
479
  ): Effect.Effect<
481
480
  Client.Method<
482
481
  HttpApiEndpoint.WithName<HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>, EndpointName>,
483
- BadRequest | E,
482
+ E,
484
483
  R
485
484
  >,
486
485
  never,
@@ -16,7 +16,6 @@ import * as HttpRouter from "../http/HttpRouter.ts"
16
16
  import type { HttpServerRequest } from "../http/HttpServerRequest.ts"
17
17
  import type { HttpServerResponse } from "../http/HttpServerResponse.ts"
18
18
  import type * as Multipart from "../http/Multipart.ts"
19
- import { BadRequestFromSchemaError, type BadRequestNoContent } from "./HttpApiError.ts"
20
19
  import type * as HttpApiGroup from "./HttpApiGroup.ts"
21
20
  import type * as HttpApiMiddleware from "./HttpApiMiddleware.ts"
22
21
  import * as HttpApiSchema from "./HttpApiSchema.ts"
@@ -54,7 +53,7 @@ export interface HttpApiEndpoint<
54
53
  out Payload extends Schema.Top = never,
55
54
  out Headers extends Schema.Top = never,
56
55
  out Success extends Schema.Top = typeof HttpApiSchema.NoContent,
57
- out Error extends Schema.Top = typeof BadRequestNoContent,
56
+ out Error extends Schema.Top = never,
58
57
  in out Middleware = never,
59
58
  out MiddlewareR = never
60
59
  > extends Pipeable {
@@ -172,7 +171,7 @@ export function getSuccessSchemas(endpoint: AnyWithProps): [Schema.Top, ...Array
172
171
  }
173
172
 
174
173
  /** @internal */
175
- export function getErrorSchemas(endpoint: AnyWithProps): [Schema.Top, ...Array<Schema.Top>] {
174
+ export function getErrorSchemas(endpoint: AnyWithProps): Array<Schema.Top> {
176
175
  const schemas = new Set<Schema.Top>(endpoint.error)
177
176
  for (const middleware of endpoint.middlewares) {
178
177
  const key = middleware as any as HttpApiMiddleware.AnyService
@@ -180,7 +179,7 @@ export function getErrorSchemas(endpoint: AnyWithProps): [Schema.Top, ...Array<S
180
179
  schemas.add(schema)
181
180
  }
182
181
  }
183
- return Arr.append(Array.from(schemas), BadRequestFromSchemaError)
182
+ return Array.from(schemas)
184
183
  }
185
184
 
186
185
  /**
@@ -951,7 +950,7 @@ export const make = <Method extends HttpMethod>(method: Method): {
951
950
  : StringTree<ExtractSchemaOrArray<Payload>>,
952
951
  StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>,
953
952
  Json<Success extends ReadonlyArray<Schema.Top> ? Success[number] : Success>,
954
- Json<(Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error) | typeof BadRequestNoContent>
953
+ Json<Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error>
955
954
  >
956
955
  <
957
956
  const Name extends string,
@@ -983,7 +982,7 @@ export const make = <Method extends HttpMethod>(method: Method): {
983
982
  ExtractSchemaOrArray<Payload>,
984
983
  ExtractSchemaOrArray<Headers>,
985
984
  Success extends ReadonlyArray<Schema.Top> ? Success[number] : Success,
986
- (Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error) | typeof BadRequestNoContent
985
+ Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error
987
986
  >
988
987
  } =>
989
988
  <
@@ -1018,7 +1017,7 @@ export const make = <Method extends HttpMethod>(method: Method): {
1018
1017
  : Payload,
1019
1018
  Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers,
1020
1019
  Success extends ReadonlyArray<Schema.Top> ? Success[number] : Success,
1021
- (Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error) | typeof BadRequestNoContent
1020
+ Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error
1022
1021
  > => {
1023
1022
  const disableCodecs = options?.disableCodecs ?? false
1024
1023
  const transformStringTree = disableCodecs ? identity : Schema.toCodecStringTree
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * @since 4.0.0
3
3
  */
4
+ import * as Data from "../../Data.ts"
4
5
  import * as Effect from "../../Effect.ts"
5
6
  import * as ErrorReporter from "../../ErrorReporter.ts"
6
- import { identity } from "../../Function.ts"
7
+ import { hasProperty } from "../../Predicate.ts"
7
8
  import * as Schema from "../../Schema.ts"
8
- import * as Transformation from "../../SchemaTransformation.ts"
9
9
  import * as HttpServerRespondable from "../http/HttpServerRespondable.ts"
10
10
  import * as HttpServerResponse from "../http/HttpServerResponse.ts"
11
11
  import * as HttpApiSchema from "./HttpApiSchema.ts"
@@ -48,26 +48,6 @@ export const BadRequestNoContent = BadRequest.pipe(HttpApiSchema.asNoContent({
48
48
  decode: () => new BadRequest({})
49
49
  }))
50
50
 
51
- /**
52
- * @category Built-in errors
53
- * @since 4.0.0
54
- */
55
- export const BadRequestFromSchemaError = BadRequest.pipe(
56
- Schema.decodeTo(
57
- Schema.Union([Schema.declare(Schema.isSchemaError), BadRequest]),
58
- Transformation.transform({
59
- encode: (_) => BadRequest.singleton,
60
- decode: identity
61
- })
62
- ),
63
- HttpApiSchema.asNoContent({
64
- decode: () => new BadRequest({})
65
- })
66
- ).annotate({
67
- httpApiStatus: 400,
68
- description: "BadRequest"
69
- })
70
-
71
51
  /**
72
52
  * @category Built-in errors
73
53
  * @since 4.0.0
@@ -332,3 +312,44 @@ export class ServiceUnavailable
332
312
  export const ServiceUnavailableNoContent = ServiceUnavailable.pipe(HttpApiSchema.asNoContent({
333
313
  decode: () => new ServiceUnavailable({})
334
314
  }))
315
+
316
+ /**
317
+ * @category Parsing errors
318
+ * @since 4.0.0
319
+ */
320
+ export type HttpApiSchemaErrorTypeId = "~effect/httpapi/HttpApiError/HttpApiSchemaError"
321
+
322
+ /**
323
+ * @category Parsing errors
324
+ * @since 4.0.0
325
+ */
326
+ export const HttpApiSchemaErrorTypeId: HttpApiSchemaErrorTypeId = "~effect/httpapi/HttpApiError/HttpApiSchemaError"
327
+
328
+ /**
329
+ * @category Parsing errors
330
+ * @since 4.0.0
331
+ */
332
+ export class HttpApiSchemaError extends Data.TaggedClass("HttpApiSchemaError")<{
333
+ readonly kind: "Params" | "Headers" | "Query" | "Body" | "Payload"
334
+ readonly cause: Schema.SchemaError
335
+ }> {
336
+ readonly [HttpApiSchemaErrorTypeId]: HttpApiSchemaErrorTypeId = HttpApiSchemaErrorTypeId
337
+
338
+ static is(u: unknown): u is HttpApiSchemaError {
339
+ return hasProperty(u, HttpApiSchemaErrorTypeId)
340
+ }
341
+
342
+ static wrap<A, R>(
343
+ kind: HttpApiSchemaError["kind"],
344
+ effect: Effect.Effect<A, Schema.SchemaError, R>
345
+ ): Effect.Effect<A, HttpApiSchemaError, R> {
346
+ return Effect.mapError(effect, (error) => new HttpApiSchemaError({ kind, cause: error }))
347
+ }
348
+
349
+ readonly name = "HttpApiSchemaError"
350
+ readonly message = this.kind;
351
+
352
+ [HttpServerRespondable.symbol]() {
353
+ return Effect.succeed(badRequestResponse)
354
+ }
355
+ }
@@ -5,7 +5,7 @@ import * as Context from "../../Context.ts"
5
5
  import * as Effect from "../../Effect.ts"
6
6
  import * as Layer from "../../Layer.ts"
7
7
  import { hasProperty } from "../../Predicate.ts"
8
- import * as Schema from "../../Schema.ts"
8
+ import type * as Schema from "../../Schema.ts"
9
9
  import { Scope } from "../../Scope.ts"
10
10
  import type { unhandled } from "../../Types.ts"
11
11
  import type * as HttpClientError from "../http/HttpClientError.ts"
@@ -14,6 +14,7 @@ import type * as HttpClientResponse from "../http/HttpClientResponse.ts"
14
14
  import type * as HttpRouter from "../http/HttpRouter.ts"
15
15
  import type { HttpServerResponse } from "../http/HttpServerResponse.ts"
16
16
  import type * as HttpApiEndpoint from "./HttpApiEndpoint.ts"
17
+ import { HttpApiSchemaError } from "./HttpApiError.ts"
17
18
  import type * as HttpApiGroup from "./HttpApiGroup.ts"
18
19
  import type * as HttpApiSecurity from "./HttpApiSecurity.ts"
19
20
 
@@ -333,11 +334,11 @@ function getError(error: ErrorConstraint | undefined): ReadonlySet<Schema.Top> {
333
334
  export const layerSchemaErrorTransform = <Id, E extends ErrorConstraint, Requires>(
334
335
  service: Context.Service<Id, HttpApiMiddleware<never, E, Requires>>,
335
336
  transform: (
336
- error: Schema.SchemaError,
337
+ error: HttpApiSchemaError,
337
338
  context: { readonly endpoint: HttpApiEndpoint.AnyWithProps; readonly group: HttpApiGroup.AnyWithProps }
338
339
  ) => Effect.Effect<
339
340
  HttpServerResponse,
340
- ErrorSchemaFromConstraint<E>["Type"] | Schema.SchemaError,
341
+ ErrorSchemaFromConstraint<E>["Type"] | HttpApiSchemaError,
341
342
  Requires | HttpRouter.Provided
342
343
  >
343
344
  ): Layer.Layer<Id> =>
@@ -348,9 +349,9 @@ export const layerSchemaErrorTransform = <Id, E extends ErrorConstraint, Require
348
349
  httpEffect,
349
350
  (e): Effect.Effect<
350
351
  HttpServerResponse,
351
- unhandled | Schema.SchemaError | ErrorSchemaFromConstraint<E>["Type"],
352
+ unhandled | HttpApiSchemaError | ErrorSchemaFromConstraint<E>["Type"],
352
353
  Requires | HttpRouter.Provided
353
- > => Schema.isSchemaError(e) ? transform(e, options) : Effect.fail(e)
354
+ > => HttpApiSchemaError.is(e) ? transform(e, options) : Effect.fail(e)
354
355
  )
355
356
  )
356
357
 
@@ -199,21 +199,11 @@ function processAnnotation<Services, S, I>(
199
199
  * and overrides. Cached results are used for better performance when the same
200
200
  * `HttpApi` instance is processed multiple times.
201
201
  *
202
- * **Options**
203
- *
204
- * - `additionalProperties`: Controls how additional properties are handled while resolving the JSON schema. Possible values include:
205
- * - `false`: Disallow additional properties (default)
206
- * - `true`: Allow additional properties
207
- * - `JsonSchema`: Use the provided JSON Schema for additional properties
208
- *
209
202
  * @category constructors
210
203
  * @since 4.0.0
211
204
  */
212
205
  export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
213
- api: HttpApi.HttpApi<Id, Groups>,
214
- options?: {
215
- readonly additionalProperties?: boolean | JsonSchema.JsonSchema | undefined
216
- } | undefined
206
+ api: HttpApi.HttpApi<Id, Groups>
217
207
  ): OpenAPISpec {
218
208
  const cached = apiCache.get(api)
219
209
  if (cached !== undefined) {
@@ -484,9 +474,7 @@ export function fromApi<Id extends string, Groups extends HttpApiGroup.Any>(
484
474
  Arr.map(pathOps, (op) => op.ast)
485
475
  )
486
476
  const jsonSchemaMultiDocument = JsonSchema.toMultiDocumentOpenApi3_1(
487
- SchemaRepresentation.toJsonSchemaMultiDocument(multiDocument, {
488
- additionalProperties: options?.additionalProperties
489
- })
477
+ SchemaRepresentation.toJsonSchemaMultiDocument(multiDocument)
490
478
  )
491
479
  const patchOps: Array<JsonPatch.JsonPatchOperation> = pathOps.map((op, i) => {
492
480
  const oppath = escapePath(op.path)
@@ -536,7 +524,7 @@ type ResponseBodies = Map<
536
524
  >
537
525
 
538
526
  function extractResponseBodies(
539
- schemas: readonly [Schema.Top, ...Array<Schema.Top>],
527
+ schemas: Array<Schema.Top>,
540
528
  getStatus: (ast: AST.AST) => number,
541
529
  getDescription: (ast: AST.AST) => string | undefined
542
530
  ): ResponseBodies {
@@ -124,7 +124,7 @@ export const make: (options: {
124
124
  if (typeof currentCount === "bigint" && typeof previousCount === "bigint") {
125
125
  reportValue = currentCount - previousCount
126
126
  // Handle reset: if current < previous, report current value
127
- if (reportValue < 0n) {
127
+ if (reportValue < BigInt(0)) {
128
128
  reportValue = currentCount
129
129
  }
130
130
  } else {
@@ -29,9 +29,9 @@ const encodeTag = (fieldNumber: number, wireType: WireType): number => (fieldNum
29
29
  export const encodeVarint = (value: number | bigint): Uint8Array => {
30
30
  const bytes: Array<number> = []
31
31
  let n = typeof value === "bigint" ? value : BigInt(value)
32
- while (n > 0x7fn) {
33
- bytes.push(Number(n & 0x7fn) | 0x80)
34
- n >>= 7n
32
+ while (n > BigInt(127)) {
33
+ bytes.push(Number(n & BigInt(127)) | 0x80)
34
+ n >>= BigInt(7)
35
35
  }
36
36
  bytes.push(Number(n))
37
37
  return new Uint8Array(bytes)
@@ -44,7 +44,7 @@ export const encodeVarint = (value: number | bigint): Uint8Array => {
44
44
  */
45
45
  export const encodeSint = (value: number | bigint): Uint8Array => {
46
46
  const n = typeof value === "bigint" ? value : BigInt(value)
47
- const zigzag = (n << 1n) ^ (n >> 63n)
47
+ const zigzag = (n << BigInt(1)) ^ (n >> BigInt(63))
48
48
  return encodeVarint(zigzag)
49
49
  }
50
50
 
@@ -400,47 +400,52 @@ interface JsonRpcResponse {
400
400
  type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse
401
401
 
402
402
  /**
403
+ * Create a MessagePack serialization with custom msgpackr options.
404
+ *
403
405
  * @since 4.0.0
404
406
  * @category serialization
405
407
  */
406
- export const msgPack: RpcSerialization["Service"] = RpcSerialization.of({
407
- contentType: "application/msgpack",
408
- includesFraming: true,
409
- makeUnsafe: () => {
410
- const unpackr = new Msgpackr.Unpackr({
411
- useRecords: true
412
- })
413
- const packr = new Msgpackr.Packr({
414
- useRecords: true
415
- })
416
- const encoder = new TextEncoder()
417
- let incomplete: Uint8Array | undefined = undefined
418
- return {
419
- decode: (bytes) => {
420
- let buf = typeof bytes === "string" ? encoder.encode(bytes) : bytes
421
- if (incomplete !== undefined) {
422
- const prev = buf
423
- bytes = new Uint8Array(incomplete.length + buf.length)
424
- bytes.set(incomplete)
425
- bytes.set(prev, incomplete.length)
426
- buf = bytes
427
- incomplete = undefined
428
- }
429
- try {
430
- return unpackr.unpackMultiple(buf)
431
- } catch (error_) {
432
- const error = error_ as any
433
- if (error.incomplete) {
434
- incomplete = buf.subarray(error.lastPosition)
435
- return error.values ?? []
408
+ export const makeMsgPack = (options?: Msgpackr.Options | undefined): RpcSerialization["Service"] =>
409
+ RpcSerialization.of({
410
+ contentType: "application/msgpack",
411
+ includesFraming: true,
412
+ makeUnsafe: () => {
413
+ const unpackr = new Msgpackr.Unpackr(options)
414
+ const packr = new Msgpackr.Packr(options)
415
+ const encoder = new TextEncoder()
416
+ let incomplete: Uint8Array | undefined = undefined
417
+ return {
418
+ decode(bytes) {
419
+ let buf = typeof bytes === "string" ? encoder.encode(bytes) : bytes
420
+ if (incomplete !== undefined) {
421
+ const prev = buf
422
+ bytes = new Uint8Array(incomplete.length + buf.length)
423
+ bytes.set(incomplete)
424
+ bytes.set(prev, incomplete.length)
425
+ buf = bytes
426
+ incomplete = undefined
436
427
  }
437
- return []
438
- }
439
- },
440
- encode: (response) => packr.pack(response)
428
+ try {
429
+ return unpackr.unpackMultiple(buf)
430
+ } catch (error_) {
431
+ const error = error_ as any
432
+ if (error.incomplete) {
433
+ incomplete = buf.subarray(error.lastPosition)
434
+ return error.values ?? []
435
+ }
436
+ throw error_
437
+ }
438
+ },
439
+ encode: (response) => packr.pack(response)
440
+ }
441
441
  }
442
- }
443
- })
442
+ })
443
+
444
+ /**
445
+ * @since 4.0.0
446
+ * @category serialization
447
+ */
448
+ export const msgPack: RpcSerialization["Service"] = makeMsgPack({ useRecords: true })
444
449
 
445
450
  /**
446
451
  * A rpc serialization layer that uses JSON for serialization.
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=to-codec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to-codec.d.ts","sourceRoot":"","sources":["../../../src/internal/schema/to-codec.ts"],"names":[],"mappings":""}