@effect/platform 0.70.1 → 0.70.3

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 (39) hide show
  1. package/dist/cjs/HttpApi.js +12 -2
  2. package/dist/cjs/HttpApi.js.map +1 -1
  3. package/dist/cjs/HttpApiClient.js +7 -3
  4. package/dist/cjs/HttpApiClient.js.map +1 -1
  5. package/dist/cjs/HttpApiEndpoint.js.map +1 -1
  6. package/dist/cjs/OpenApi.js +18 -11
  7. package/dist/cjs/OpenApi.js.map +1 -1
  8. package/dist/cjs/UrlParams.js +4 -0
  9. package/dist/cjs/UrlParams.js.map +1 -1
  10. package/dist/cjs/internal/httpRouter.js.map +1 -1
  11. package/dist/dts/HttpApi.d.ts +8 -2
  12. package/dist/dts/HttpApi.d.ts.map +1 -1
  13. package/dist/dts/HttpApiClient.d.ts.map +1 -1
  14. package/dist/dts/HttpApiEndpoint.d.ts +12 -1
  15. package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
  16. package/dist/dts/HttpRouter.d.ts +1 -1
  17. package/dist/dts/HttpRouter.d.ts.map +1 -1
  18. package/dist/dts/OpenApi.d.ts +3 -6
  19. package/dist/dts/OpenApi.d.ts.map +1 -1
  20. package/dist/dts/UrlParams.d.ts +4 -0
  21. package/dist/dts/UrlParams.d.ts.map +1 -1
  22. package/dist/esm/HttpApi.js +12 -2
  23. package/dist/esm/HttpApi.js.map +1 -1
  24. package/dist/esm/HttpApiClient.js +7 -3
  25. package/dist/esm/HttpApiClient.js.map +1 -1
  26. package/dist/esm/HttpApiEndpoint.js.map +1 -1
  27. package/dist/esm/OpenApi.js +18 -11
  28. package/dist/esm/OpenApi.js.map +1 -1
  29. package/dist/esm/UrlParams.js +4 -0
  30. package/dist/esm/UrlParams.js.map +1 -1
  31. package/dist/esm/internal/httpRouter.js.map +1 -1
  32. package/package.json +2 -2
  33. package/src/HttpApi.ts +40 -13
  34. package/src/HttpApiClient.ts +11 -5
  35. package/src/HttpApiEndpoint.ts +20 -1
  36. package/src/HttpRouter.ts +1 -1
  37. package/src/OpenApi.ts +19 -31
  38. package/src/UrlParams.ts +4 -0
  39. package/src/internal/httpRouter.ts +1 -1
package/src/OpenApi.ts CHANGED
@@ -6,7 +6,6 @@ import { globalValue } from "effect/GlobalValue"
6
6
  import * as Option from "effect/Option"
7
7
  import type { ReadonlyRecord } from "effect/Record"
8
8
  import * as Schema from "effect/Schema"
9
- import * as AST from "effect/SchemaAST"
10
9
  import type { DeepMutable, Mutable } from "effect/Types"
11
10
  import * as HttpApi from "./HttpApi.js"
12
11
  import * as HttpApiMiddleware from "./HttpApiMiddleware.js"
@@ -90,9 +89,10 @@ export class Override extends Context.Tag("@effect/platform/OpenApi/Override")<O
90
89
  * @since 1.0.0
91
90
  * @category annotations
92
91
  */
93
- export class Transform
94
- extends Context.Tag("@effect/platform/OpenApi/Transform")<Transform, (openApiSpec: OpenAPISpec) => OpenAPISpec>()
95
- {}
92
+ export class Transform extends Context.Tag("@effect/platform/OpenApi/Transform")<
93
+ Transform,
94
+ (openApiSpec: Record<string, any>) => Record<string, any>
95
+ >() {}
96
96
 
97
97
  const contextPartial = <Tags extends Record<string, Context.Tag<any, any>>>(tags: Tags): (
98
98
  options: {
@@ -119,18 +119,15 @@ export const annotations: (
119
119
  options: {
120
120
  readonly identifier?: string | undefined
121
121
  readonly title?: string | undefined
122
- readonly summary?: string | undefined
123
122
  readonly version?: string | undefined
124
123
  readonly description?: string | undefined
125
124
  readonly license?: OpenAPISpecLicense | undefined
125
+ readonly summary?: string | undefined
126
126
  readonly externalDocs?: OpenAPISpecExternalDocs | undefined
127
127
  readonly servers?: ReadonlyArray<OpenAPISpecServer> | undefined
128
128
  readonly format?: string | undefined
129
129
  readonly override?: Record<string, unknown> | undefined
130
- /**
131
- * Transforms the generated OpenAPI specification
132
- */
133
- readonly transform?: ((openApiSpec: OpenAPISpec) => OpenAPISpec) | undefined
130
+ readonly transform?: ((openApiSpec: Record<string, any>) => Record<string, any>) | undefined
134
131
  }
135
132
  ) => Context.Context<never> = contextPartial({
136
133
  identifier: Identifier,
@@ -217,7 +214,7 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
217
214
  })
218
215
  HttpApi.reflect(api as any, {
219
216
  onGroup({ group }) {
220
- const tag: Mutable<OpenAPISpecTag> = {
217
+ let tag: Mutable<OpenAPISpecTag> = {
221
218
  name: Context.getOrElse(group.annotations, Title, () => group.identifier)
222
219
  }
223
220
  Option.map(Context.getOption(group.annotations, Description), (description) => {
@@ -229,12 +226,15 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
229
226
  Option.map(Context.getOption(group.annotations, Override), (override) => {
230
227
  Object.assign(tag, override)
231
228
  })
229
+ Option.map(Context.getOption(group.annotations, Transform), (fn) => {
230
+ tag = fn(tag) as OpenAPISpecTag
231
+ })
232
232
  spec.tags!.push(tag)
233
233
  },
234
234
  onEndpoint({ endpoint, errors, group, middleware, payloads, successes }) {
235
235
  const path = endpoint.path.replace(/:(\w+)[^/]*/g, "{$1}")
236
236
  const method = endpoint.method.toLowerCase() as OpenAPISpecMethodName
237
- const op: DeepMutable<OpenAPISpecOperation> = {
237
+ let op: DeepMutable<OpenAPISpecOperation> = {
238
238
  tags: [Context.getOrElse(group.annotations, Title, () => group.identifier)],
239
239
  operationId: Context.getOrElse(
240
240
  endpoint.annotations,
@@ -275,10 +275,10 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
275
275
  })
276
276
  op.requestBody = { content, required: true }
277
277
  }
278
- for (const [status, ast] of successes) {
278
+ for (const [status, { ast, description }] of successes) {
279
279
  if (op.responses![status]) continue
280
280
  op.responses![status] = {
281
- description: Option.getOrElse(getDescriptionOrIdentifier(ast), () => "Success")
281
+ description: Option.getOrElse(description, () => "Success")
282
282
  }
283
283
  ast.pipe(
284
284
  Option.filter((ast) => !HttpApiSchema.getEmptyDecodeable(ast)),
@@ -343,10 +343,10 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
343
343
  })
344
344
  }
345
345
  }
346
- for (const [status, ast] of errors) {
346
+ for (const [status, { ast, description }] of errors) {
347
347
  if (op.responses![status]) continue
348
348
  op.responses![status] = {
349
- description: Option.getOrElse(getDescriptionOrIdentifier(ast), () => "Error")
349
+ description: Option.getOrElse(description, () => "Error")
350
350
  }
351
351
  ast.pipe(
352
352
  Option.filter((ast) => !HttpApiSchema.getEmptyDecodeable(ast)),
@@ -365,12 +365,15 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
365
365
  Option.map(Context.getOption(endpoint.annotations, Override), (override) => {
366
366
  Object.assign(op, override)
367
367
  })
368
+ Option.map(Context.getOption(endpoint.annotations, Transform), (transformFn) => {
369
+ op = transformFn(op)
370
+ })
368
371
  spec.paths[path][method] = op
369
372
  }
370
373
  })
371
374
 
372
375
  Option.map(Context.getOption(api.annotations, Transform), (transformFn) => {
373
- spec = transformFn(spec)
376
+ spec = transformFn(spec) as OpenAPISpec
374
377
  })
375
378
 
376
379
  apiCache.set(self, spec)
@@ -414,21 +417,6 @@ const makeSecurityScheme = (security: HttpApiSecurity): OpenAPISecurityScheme =>
414
417
  }
415
418
  }
416
419
 
417
- const getDescriptionOrIdentifier = (ast: Option.Option<AST.PropertySignature | AST.AST>): Option.Option<string> =>
418
- ast.pipe(
419
- Option.map((ast) =>
420
- "to" in ast ?
421
- {
422
- ...ast.to.annotations,
423
- ...ast.annotations
424
- } :
425
- ast.annotations
426
- ),
427
- Option.flatMapNullable((annotations) =>
428
- annotations[AST.DescriptionAnnotationId] ?? annotations[AST.IdentifierAnnotationId] as any
429
- )
430
- )
431
-
432
420
  /**
433
421
  * @category models
434
422
  * @since 1.0.0
package/src/UrlParams.ts CHANGED
@@ -280,6 +280,7 @@ const baseUrl = (): string | undefined => {
280
280
  * (when more than one value for a key)
281
281
  *
282
282
  * @example
283
+ * ```ts
283
284
  * import { UrlParams } from "@effect/platform"
284
285
  *
285
286
  * const urlParams = UrlParams.fromInput({ a: 1, b: true, c: "string", e: [1, 2, 3] })
@@ -289,6 +290,7 @@ const baseUrl = (): string | undefined => {
289
290
  * result,
290
291
  * { "a": "1", "b": "true", "c": "string", "e": ["1", "2", "3"] }
291
292
  * )
293
+ * ```
292
294
  *
293
295
  * @since 1.0.0
294
296
  * @category conversions
@@ -332,6 +334,7 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: Pa
332
334
  * Extract schema from all key-value pairs in the given `UrlParams`.
333
335
  *
334
336
  * @example
337
+ * ```ts
335
338
  * import { Effect, Schema } from "effect"
336
339
  * import { UrlParams } from "@effect/platform"
337
340
  *
@@ -347,6 +350,7 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: Pa
347
350
  * b: false
348
351
  * })
349
352
  * })
353
+ * ```
350
354
  *
351
355
  * @since 1.0.0
352
356
  * @category schema
@@ -342,7 +342,7 @@ export const fromIterable = <R extends Router.Route<any, any>>(
342
342
 
343
343
  /** @internal */
344
344
  export const makeRoute = <E, R>(
345
- method: Method.HttpMethod,
345
+ method: Method.HttpMethod | "*",
346
346
  path: Router.PathInput,
347
347
  handler: Router.Route.Handler<E, R>,
348
348
  options?: {