@knpkv/jira-api-client 0.4.0 → 1.0.1
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/CHANGELOG.md +22 -0
- package/README.md +88 -65
- package/dist/JiraApiClient.d.ts +20 -86
- package/dist/JiraApiClient.d.ts.map +1 -1
- package/dist/JiraApiClient.js +26 -75
- package/dist/JiraApiClient.js.map +1 -1
- package/dist/generated/JiraApi.d.ts +103977 -0
- package/dist/generated/JiraApi.d.ts.map +1 -0
- package/dist/generated/JiraApi.js +7608 -0
- package/dist/generated/JiraApi.js.map +1 -0
- package/dist/index.d.ts +3 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -11
- package/dist/index.js.map +1 -1
- package/package.json +13 -16
- package/scripts/regenerate.ts +209 -201
- package/scripts/tsconfig.json +13 -0
- package/src/JiraApiClient.ts +74 -104
- package/src/generated/JiraApi.ts +19596 -0
- package/src/index.ts +3 -14
- package/test/JiraApiClient.test.ts +154 -153
- package/.specs/VERSION_V3 +0 -1
- package/.specs/jira-v3-1001.0.0-SNAPSHOT-05f20e18d9bde3de68f911b4915970482f536d4e.json +0 -56275
- package/.specs/jira-v3-1001.0.0-SNAPSHOT-d7cd03e966bb408ad32ffe870114289c528f56fd.json +0 -56129
- package/.specs/jira-v3-1001.0.0-SNAPSHOT-ea9913a8c4412d2bfb1911480b023a04544e19d8.json +0 -55618
- package/dist/OpenApiFetchClient.d.ts +0 -55
- package/dist/OpenApiFetchClient.d.ts.map +0 -1
- package/dist/OpenApiFetchClient.js +0 -68
- package/dist/OpenApiFetchClient.js.map +0 -1
- package/dist/generated/v3/index.d.ts +0 -7
- package/dist/generated/v3/index.d.ts.map +0 -1
- package/dist/generated/v3/index.js +0 -2
- package/dist/generated/v3/index.js.map +0 -1
- package/dist/generated/v3/schema.d.ts +0 -64454
- package/src/OpenApiFetchClient.ts +0 -102
- package/src/generated/v3/index.ts +0 -6
- package/src/generated/v3/schema.d.ts +0 -64454
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic Effect wrapper for openapi-fetch clients.
|
|
3
|
-
*
|
|
4
|
-
* Exposes a type-safe `Client<Paths>` and a `toEffect` helper that wraps
|
|
5
|
-
* any `Promise<FetchResponse>` in Effect with error mapping.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const page = yield* toEffect(client.GET("/pages/{id}", {
|
|
10
|
-
* params: { path: { id: 123 } }
|
|
11
|
-
* }))
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @module
|
|
15
|
-
*/
|
|
16
|
-
import * as Data from "effect/Data"
|
|
17
|
-
import * as Effect from "effect/Effect"
|
|
18
|
-
import createClient, { type Client, type FetchResponse } from "openapi-fetch"
|
|
19
|
-
import type { MediaType } from "openapi-typescript-helpers"
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Error from openapi-fetch operations.
|
|
23
|
-
*
|
|
24
|
-
* @category Errors
|
|
25
|
-
*/
|
|
26
|
-
export class FetchClientError extends Data.TaggedError("FetchClientError")<{
|
|
27
|
-
readonly error: unknown
|
|
28
|
-
readonly status: number
|
|
29
|
-
readonly message: string
|
|
30
|
-
}> {}
|
|
31
|
-
|
|
32
|
-
/** Extract success `data` from a FetchResponse discriminated union. */
|
|
33
|
-
export type SuccessData<T> = T extends { data: infer D; error?: undefined } ? D
|
|
34
|
-
: T extends { data?: infer D } ? D | undefined
|
|
35
|
-
: undefined
|
|
36
|
-
|
|
37
|
-
const isRecord = (value: unknown): value is Readonly<Record<PropertyKey, unknown>> =>
|
|
38
|
-
typeof value === "object" && value !== null
|
|
39
|
-
|
|
40
|
-
const errorPayload = (value: unknown): unknown => isRecord(value) && "error" in value ? value.error : value
|
|
41
|
-
|
|
42
|
-
const errorStatus = (value: unknown): number => isRecord(value) && typeof value.status === "number" ? value.status : 0
|
|
43
|
-
|
|
44
|
-
const errorMessage = (value: unknown): string => {
|
|
45
|
-
const payload = errorPayload(value)
|
|
46
|
-
return typeof payload === "string" ? payload : JSON.stringify(payload)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Wrap an openapi-fetch `Promise<FetchResponse>` in Effect.
|
|
51
|
-
*
|
|
52
|
-
* Extracts `data` on success, maps errors to `FetchClientError`.
|
|
53
|
-
* Fully type-safe — path/body constraints come from the `Client<Paths>` call site.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const page = yield* toEffect(client.GET("/pages/{id}", { params: { path: { id: 123 } } }))
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @category Utilities
|
|
61
|
-
*/
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches FetchResponse generic constraint
|
|
63
|
-
export const toEffect = <T extends Record<string | number, any>, O, M extends MediaType>(
|
|
64
|
-
promise: Promise<FetchResponse<T, O, M>>
|
|
65
|
-
): Effect.Effect<SuccessData<FetchResponse<T, O, M>>, FetchClientError> =>
|
|
66
|
-
Effect.tryPromise({
|
|
67
|
-
try: () =>
|
|
68
|
-
promise.then(({ data, error, response }) => {
|
|
69
|
-
if (error !== undefined || !response.ok) {
|
|
70
|
-
throw { error, status: response.status }
|
|
71
|
-
}
|
|
72
|
-
return data
|
|
73
|
-
}),
|
|
74
|
-
catch: (e) =>
|
|
75
|
-
new FetchClientError({
|
|
76
|
-
error: errorPayload(e),
|
|
77
|
-
status: errorStatus(e),
|
|
78
|
-
message: errorMessage(e)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* openapi-fetch client paired with the `toEffect` helper.
|
|
84
|
-
*
|
|
85
|
-
* @category Client
|
|
86
|
-
*/
|
|
87
|
-
export interface OpenApiFetchClient<Paths extends {}> {
|
|
88
|
-
/** Type-safe openapi-fetch client. Use with `toEffect()` to get Effect. */
|
|
89
|
-
readonly client: Client<Paths>
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Create an openapi-fetch client with auth headers pre-configured.
|
|
94
|
-
*
|
|
95
|
-
* @category Constructors
|
|
96
|
-
*/
|
|
97
|
-
export const makeOpenApiFetchClient = <Paths extends {}>(
|
|
98
|
-
baseUrl: string,
|
|
99
|
-
headers: Record<string, string>
|
|
100
|
-
): OpenApiFetchClient<Paths> => ({
|
|
101
|
-
client: createClient<Paths>({ baseUrl, headers })
|
|
102
|
-
})
|