@effect/platform 0.69.28 → 0.69.30
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.
- package/dist/cjs/HttpApi.js +33 -0
- package/dist/cjs/HttpApi.js.map +1 -1
- package/dist/cjs/HttpApiBuilder.js +17 -1
- package/dist/cjs/HttpApiBuilder.js.map +1 -1
- package/dist/cjs/HttpApiClient.js +64 -5
- package/dist/cjs/HttpApiClient.js.map +1 -1
- package/dist/cjs/OpenApi.js +10 -22
- package/dist/cjs/OpenApi.js.map +1 -1
- package/dist/cjs/UrlParams.js +35 -1
- package/dist/cjs/UrlParams.js.map +1 -1
- package/dist/dts/HttpApi.d.ts +5 -0
- package/dist/dts/HttpApi.d.ts.map +1 -1
- package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
- package/dist/dts/HttpApiClient.d.ts.map +1 -1
- package/dist/dts/OpenApi.d.ts +1 -1
- package/dist/dts/OpenApi.d.ts.map +1 -1
- package/dist/dts/UrlParams.d.ts +24 -0
- package/dist/dts/UrlParams.d.ts.map +1 -1
- package/dist/esm/HttpApi.js +33 -0
- package/dist/esm/HttpApi.js.map +1 -1
- package/dist/esm/HttpApiBuilder.js +17 -1
- package/dist/esm/HttpApiBuilder.js.map +1 -1
- package/dist/esm/HttpApiClient.js +64 -5
- package/dist/esm/HttpApiClient.js.map +1 -1
- package/dist/esm/OpenApi.js +10 -22
- package/dist/esm/OpenApi.js.map +1 -1
- package/dist/esm/UrlParams.js +33 -0
- package/dist/esm/UrlParams.js.map +1 -1
- package/package.json +1 -1
- package/src/HttpApi.ts +45 -0
- package/src/HttpApiBuilder.ts +19 -6
- package/src/HttpApiClient.ts +74 -8
- package/src/OpenApi.ts +10 -30
- package/src/UrlParams.ts +34 -0
package/src/OpenApi.ts
CHANGED
|
@@ -159,7 +159,7 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
|
|
|
159
159
|
const api = self as unknown as HttpApi.HttpApi.AnyWithProps
|
|
160
160
|
const jsonSchemaDefs: Record<string, JsonSchema.JsonSchema> = {}
|
|
161
161
|
let spec: DeepMutable<OpenAPISpec> = {
|
|
162
|
-
openapi: "3.0
|
|
162
|
+
openapi: "3.1.0",
|
|
163
163
|
info: {
|
|
164
164
|
title: Context.getOrElse(api.annotations, Title, () => "Api"),
|
|
165
165
|
version: Context.getOrElse(api.annotations, Version, () => "0.0.1")
|
|
@@ -231,7 +231,7 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
|
|
|
231
231
|
})
|
|
232
232
|
spec.tags!.push(tag)
|
|
233
233
|
},
|
|
234
|
-
onEndpoint({ endpoint, errors, group, middleware, successes }) {
|
|
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
237
|
const op: DeepMutable<OpenAPISpecOperation> = {
|
|
@@ -266,35 +266,15 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
|
|
|
266
266
|
op.security!.push({ [name]: [] })
|
|
267
267
|
}
|
|
268
268
|
})
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const jsonTypes: Array<AST.AST> = []
|
|
275
|
-
const multipartTypes: Array<AST.AST> = []
|
|
276
|
-
|
|
277
|
-
for (const member of members) {
|
|
278
|
-
if (HttpApiSchema.getMultipart(member)) {
|
|
279
|
-
multipartTypes.push(member)
|
|
280
|
-
} else {
|
|
281
|
-
jsonTypes.push(member)
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (jsonTypes.length > 0) {
|
|
286
|
-
content["application/json"] = {
|
|
287
|
-
schema: makeJsonSchemaOrRef(Schema.make(AST.Union.make(jsonTypes)))
|
|
288
|
-
}
|
|
269
|
+
if (payloads.size > 0) {
|
|
270
|
+
const content: Mutable<OpenApiSpecContent> = {}
|
|
271
|
+
payloads.forEach(({ ast }, contentType) => {
|
|
272
|
+
content[contentType as OpenApiSpecContentType] = {
|
|
273
|
+
schema: makeJsonSchemaOrRef(Schema.make(ast))
|
|
289
274
|
}
|
|
290
|
-
if (multipartTypes.length > 0) {
|
|
291
|
-
content["multipart/form-data"] = {
|
|
292
|
-
schema: makeJsonSchemaOrRef(Schema.make(AST.Union.make(multipartTypes)))
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
op.requestBody = { content, required: true }
|
|
296
275
|
})
|
|
297
|
-
|
|
276
|
+
op.requestBody = { content, required: true }
|
|
277
|
+
}
|
|
298
278
|
for (const [status, ast] of successes) {
|
|
299
279
|
if (op.responses![status]) continue
|
|
300
280
|
op.responses![status] = {
|
|
@@ -454,7 +434,7 @@ const getDescriptionOrIdentifier = (ast: Option.Option<AST.PropertySignature | A
|
|
|
454
434
|
* @since 1.0.0
|
|
455
435
|
*/
|
|
456
436
|
export interface OpenAPISpec {
|
|
457
|
-
readonly openapi: "3.0
|
|
437
|
+
readonly openapi: "3.1.0"
|
|
458
438
|
readonly info: OpenAPISpecInfo
|
|
459
439
|
readonly servers?: Array<OpenAPISpecServer>
|
|
460
440
|
readonly paths: OpenAPISpecPaths
|
package/src/UrlParams.ts
CHANGED
|
@@ -274,6 +274,40 @@ const baseUrl = (): string | undefined => {
|
|
|
274
274
|
return undefined
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Builds a `Record` containing all the key-value pairs in the given `UrlParams`
|
|
279
|
+
* as `string` (if only one value for a key) or a `NonEmptyArray<string>`
|
|
280
|
+
* (when more than one value for a key)
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* import { UrlParams } from "@effect/platform"
|
|
284
|
+
*
|
|
285
|
+
* const urlParams = UrlParams.fromInput({ a: 1, b: true, c: "string", e: [1, 2, 3] })
|
|
286
|
+
* const result = UrlParams.toRecord(urlParams)
|
|
287
|
+
*
|
|
288
|
+
* assert.deepStrictEqual(
|
|
289
|
+
* result,
|
|
290
|
+
* { "a": "1", "b": "true", "c": "string", "e": ["1", "2", "3"] }
|
|
291
|
+
* )
|
|
292
|
+
*
|
|
293
|
+
* @since 1.0.0
|
|
294
|
+
* @category conversions
|
|
295
|
+
*/
|
|
296
|
+
export const toRecord = (self: UrlParams): Record<string, string | Arr.NonEmptyArray<string>> => {
|
|
297
|
+
const out: Record<string, string | Arr.NonEmptyArray<string>> = {}
|
|
298
|
+
for (const [k, value] of self) {
|
|
299
|
+
const curr = out[k]
|
|
300
|
+
if (curr === undefined) {
|
|
301
|
+
out[k] = value
|
|
302
|
+
} else if (typeof curr === "string") {
|
|
303
|
+
out[k] = [curr, value]
|
|
304
|
+
} else {
|
|
305
|
+
curr.push(value)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return out
|
|
309
|
+
}
|
|
310
|
+
|
|
277
311
|
/**
|
|
278
312
|
* @since 1.0.0
|
|
279
313
|
* @category schema
|