@genapi/presets 3.0.0 → 3.2.0
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/package.json +17 -14
- package/src/axios/index.ts +0 -2
- package/src/axios/js/config/index.ts +0 -19
- package/src/axios/js/index.ts +0 -19
- package/src/axios/js/parser/index.ts +0 -96
- package/src/axios/ts/config/index.ts +0 -24
- package/src/axios/ts/index.ts +0 -20
- package/src/axios/ts/parser/index.ts +0 -95
- package/src/fetch/index.ts +0 -2
- package/src/fetch/js/config/index.ts +0 -12
- package/src/fetch/js/index.ts +0 -19
- package/src/fetch/js/parser/index.ts +0 -107
- package/src/fetch/ts/config/index.ts +0 -11
- package/src/fetch/ts/index.ts +0 -20
- package/src/fetch/ts/parser/index.ts +0 -98
- package/src/got/index.ts +0 -2
- package/src/got/js/config/index.ts +0 -19
- package/src/got/js/index.ts +0 -20
- package/src/got/js/parser/index.ts +0 -101
- package/src/got/ts/config/index.ts +0 -24
- package/src/got/ts/index.ts +0 -20
- package/src/got/ts/parser/index.ts +0 -102
- package/src/index.ts +0 -21
- package/src/ky/index.ts +0 -2
- package/src/ky/js/config/index.ts +0 -19
- package/src/ky/js/index.ts +0 -20
- package/src/ky/js/parser/index.ts +0 -97
- package/src/ky/ts/config/index.ts +0 -24
- package/src/ky/ts/index.ts +0 -20
- package/src/ky/ts/parser/index.ts +0 -97
- package/src/ofetch/index.ts +0 -2
- package/src/ofetch/js/config/index.ts +0 -19
- package/src/ofetch/js/index.ts +0 -20
- package/src/ofetch/js/parser/index.ts +0 -97
- package/src/ofetch/ts/config/index.ts +0 -24
- package/src/ofetch/ts/index.ts +0 -20
- package/src/ofetch/ts/parser/index.ts +0 -96
- package/tsup.config.ts +0 -18
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
literalFieldsToString,
|
|
5
|
-
parseHeaderCommits,
|
|
6
|
-
parseMethodMetadata,
|
|
7
|
-
parseMethodParameters,
|
|
8
|
-
parseOpenapiSpecification,
|
|
9
|
-
transformBaseURL,
|
|
10
|
-
transformDefinitions,
|
|
11
|
-
transformParameters,
|
|
12
|
-
transformQueryParams,
|
|
13
|
-
transformUrlSyntax,
|
|
14
|
-
traversePaths,
|
|
15
|
-
} from '@genapi/parser'
|
|
16
|
-
|
|
17
|
-
export interface PathsTransformOptions {
|
|
18
|
-
configRead: ApiPipeline.ConfigRead
|
|
19
|
-
interfaces: StatementInterface[]
|
|
20
|
-
functions: StatementFunction[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
24
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
25
|
-
|
|
26
|
-
const comments = parseHeaderCommits(source)
|
|
27
|
-
|
|
28
|
-
const interfaces: StatementInterface[] = []
|
|
29
|
-
const functions: StatementFunction[] = []
|
|
30
|
-
|
|
31
|
-
transformBaseURL(source, {
|
|
32
|
-
configRead,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
transformDefinitions(source.definitions, {
|
|
36
|
-
interfaces,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
transformPaths(source.paths, {
|
|
40
|
-
configRead,
|
|
41
|
-
functions,
|
|
42
|
-
interfaces,
|
|
43
|
-
})
|
|
44
|
-
configRead.graphs.comments = comments
|
|
45
|
-
configRead.graphs.functions = functions
|
|
46
|
-
configRead.graphs.interfaces = interfaces
|
|
47
|
-
|
|
48
|
-
return configRead
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
52
|
-
traversePaths(paths, (config) => {
|
|
53
|
-
/**
|
|
54
|
-
* function params/function options/function use interfaces
|
|
55
|
-
*/
|
|
56
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
57
|
-
formData: 'body',
|
|
58
|
-
query: 'params',
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
let { name, description, url, responseType, body } = parseMethodMetadata(config)
|
|
62
|
-
|
|
63
|
-
interfaces.push(...attachInters)
|
|
64
|
-
parameters.push({
|
|
65
|
-
name: 'options',
|
|
66
|
-
type: 'import(\'ofetch\').FetchOptions',
|
|
67
|
-
required: false,
|
|
68
|
-
})
|
|
69
|
-
options.push(['...', 'options'])
|
|
70
|
-
options.unshift(['method', `"${config.method}"`])
|
|
71
|
-
if (configRead.config.baseURL)
|
|
72
|
-
options.unshift('baseURL')
|
|
73
|
-
|
|
74
|
-
transformParameters(parameters, {
|
|
75
|
-
syntax: 'ecmascript',
|
|
76
|
-
configRead,
|
|
77
|
-
description,
|
|
78
|
-
interfaces,
|
|
79
|
-
responseType,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
url = transformQueryParams('query', { body, options, url })
|
|
83
|
-
url = transformUrlSyntax(url, { baseURL: configRead.config.baseURL })
|
|
84
|
-
|
|
85
|
-
functions.push({
|
|
86
|
-
export: true,
|
|
87
|
-
async: true,
|
|
88
|
-
name,
|
|
89
|
-
description,
|
|
90
|
-
parameters,
|
|
91
|
-
body: [
|
|
92
|
-
...body,
|
|
93
|
-
`return ofetch(${url}, {${literalFieldsToString(options)}})`,
|
|
94
|
-
],
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import { config as _config } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
export function config(userConfig: ApiPipeline.Config): ApiPipeline.ConfigRead {
|
|
5
|
-
userConfig.import = userConfig.import || {}
|
|
6
|
-
userConfig.import.http = userConfig.import.http || 'ofetch'
|
|
7
|
-
|
|
8
|
-
const configRead = _config(userConfig)
|
|
9
|
-
|
|
10
|
-
configRead.graphs.imports.push({
|
|
11
|
-
name: 'ofetch',
|
|
12
|
-
names: userConfig.import.http === 'ofetch' ? ['FetchOptions'] : undefined,
|
|
13
|
-
value: userConfig.import.http,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
if (userConfig.import.http !== 'ofetch') {
|
|
17
|
-
configRead.graphs.imports.push({
|
|
18
|
-
names: ['FetchOptions'],
|
|
19
|
-
value: 'ofetch',
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return configRead
|
|
24
|
-
}
|
package/src/ofetch/ts/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline } from '@genapi/shared'
|
|
2
|
-
import pipeline, { compiler, dest, generate, original } from '@genapi/pipeline'
|
|
3
|
-
|
|
4
|
-
import { config } from './config'
|
|
5
|
-
import { parser } from './parser'
|
|
6
|
-
|
|
7
|
-
function openapiPipeline(userConfig: ApiPipeline.Config) {
|
|
8
|
-
const process = pipeline(
|
|
9
|
-
userConfig => config(userConfig),
|
|
10
|
-
configRead => original(configRead),
|
|
11
|
-
configRead => parser(configRead),
|
|
12
|
-
configRead => compiler(configRead),
|
|
13
|
-
configRead => generate(configRead),
|
|
14
|
-
configRead => dest(configRead),
|
|
15
|
-
)
|
|
16
|
-
return process(userConfig)
|
|
17
|
-
}
|
|
18
|
-
export { compiler, config, dest, generate, original, parser }
|
|
19
|
-
|
|
20
|
-
export default openapiPipeline
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { ApiPipeline, StatementFunction, StatementInterface } from '@genapi/shared'
|
|
2
|
-
import type { Paths } from 'openapi-specification-types'
|
|
3
|
-
import {
|
|
4
|
-
literalFieldsToString,
|
|
5
|
-
parseHeaderCommits,
|
|
6
|
-
parseMethodMetadata,
|
|
7
|
-
parseMethodParameters,
|
|
8
|
-
parseOpenapiSpecification,
|
|
9
|
-
transformBaseURL,
|
|
10
|
-
transformDefinitions,
|
|
11
|
-
transformParameters,
|
|
12
|
-
transformQueryParams,
|
|
13
|
-
transformUrlSyntax,
|
|
14
|
-
traversePaths,
|
|
15
|
-
} from '@genapi/parser'
|
|
16
|
-
|
|
17
|
-
export interface PathsTransformOptions {
|
|
18
|
-
configRead: ApiPipeline.ConfigRead
|
|
19
|
-
interfaces: StatementInterface[]
|
|
20
|
-
functions: StatementFunction[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function parser(configRead: ApiPipeline.ConfigRead) {
|
|
24
|
-
const source = parseOpenapiSpecification(configRead.source)
|
|
25
|
-
|
|
26
|
-
const comments = parseHeaderCommits(source)
|
|
27
|
-
|
|
28
|
-
const interfaces: StatementInterface[] = []
|
|
29
|
-
const functions: StatementFunction[] = []
|
|
30
|
-
|
|
31
|
-
transformBaseURL(source, {
|
|
32
|
-
configRead,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
transformDefinitions(source.definitions, {
|
|
36
|
-
interfaces,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
transformPaths(source.paths, {
|
|
40
|
-
configRead,
|
|
41
|
-
functions,
|
|
42
|
-
interfaces,
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
configRead.graphs.comments = comments
|
|
46
|
-
configRead.graphs.functions = functions
|
|
47
|
-
configRead.graphs.interfaces = interfaces
|
|
48
|
-
|
|
49
|
-
return configRead
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function transformPaths(paths: Paths, { configRead, functions, interfaces }: PathsTransformOptions) {
|
|
53
|
-
traversePaths(paths, (config) => {
|
|
54
|
-
/**
|
|
55
|
-
* function params/function options/function use interfaces
|
|
56
|
-
*/
|
|
57
|
-
const { parameters, interfaces: attachInters, options } = parseMethodParameters(config, {
|
|
58
|
-
formData: 'body',
|
|
59
|
-
query: 'params',
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
let { name, description, url, responseType, body } = parseMethodMetadata(config)
|
|
63
|
-
|
|
64
|
-
interfaces.push(...attachInters)
|
|
65
|
-
parameters.push({
|
|
66
|
-
name: 'options',
|
|
67
|
-
type: 'FetchOptions',
|
|
68
|
-
required: false,
|
|
69
|
-
})
|
|
70
|
-
options.push(['...', 'options'])
|
|
71
|
-
options.unshift(['method', `"${config.method}"`])
|
|
72
|
-
if (configRead.config.baseURL)
|
|
73
|
-
options.unshift('baseURL')
|
|
74
|
-
|
|
75
|
-
const { spaceResponseType } = transformParameters(parameters, {
|
|
76
|
-
syntax: 'typescript',
|
|
77
|
-
configRead,
|
|
78
|
-
description,
|
|
79
|
-
interfaces,
|
|
80
|
-
responseType,
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
url = transformQueryParams('query', { body, options, url })
|
|
84
|
-
url = transformUrlSyntax(url)
|
|
85
|
-
|
|
86
|
-
functions.push({
|
|
87
|
-
export: true,
|
|
88
|
-
name,
|
|
89
|
-
description,
|
|
90
|
-
parameters,
|
|
91
|
-
body: [
|
|
92
|
-
`return ofetch<${spaceResponseType}>(${url}, {${literalFieldsToString(options)}})`,
|
|
93
|
-
],
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions'
|
|
2
|
-
import { defineConfig } from 'tsup'
|
|
3
|
-
import { dependencies, name } from './package.json'
|
|
4
|
-
|
|
5
|
-
export default defineConfig((_options) => {
|
|
6
|
-
return {
|
|
7
|
-
esbuildPlugins: [esbuildPluginFilePathExtensions()],
|
|
8
|
-
outExtension: () => ({ js: '.mjs' }),
|
|
9
|
-
entry: ['src/**/*.ts'],
|
|
10
|
-
format: ['esm'],
|
|
11
|
-
clean: true,
|
|
12
|
-
dts: true,
|
|
13
|
-
name,
|
|
14
|
-
bundle: true,
|
|
15
|
-
// minify: !options.watch,
|
|
16
|
-
external: Object.keys(dependencies || {}),
|
|
17
|
-
}
|
|
18
|
-
})
|