@intrig/plugin-sdk 0.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/README.md +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/lib/plugin-sdk.d.ts +159 -0
- package/dist/lib/plugin-sdk.d.ts.map +1 -0
- package/dist/lib/plugin-sdk.js +10 -0
- package/dist/lib/template/json-literal.d.ts +5 -0
- package/dist/lib/template/json-literal.d.ts.map +1 -0
- package/dist/lib/template/json-literal.js +14 -0
- package/dist/lib/template/md-literal.d.ts +5 -0
- package/dist/lib/template/md-literal.d.ts.map +1 -0
- package/dist/lib/template/md-literal.js +14 -0
- package/dist/lib/template/template-util.d.ts +32 -0
- package/dist/lib/template/template-util.d.ts.map +1 -0
- package/dist/lib/template/template-util.js +192 -0
- package/dist/lib/template/ts-literal.d.ts +5 -0
- package/dist/lib/template/ts-literal.d.ts.map +1 -0
- package/dist/lib/template/ts-literal.js +19 -0
- package/dist/lib/util/change-case.d.ts +80 -0
- package/dist/lib/util/change-case.d.ts.map +1 -0
- package/dist/lib/util/change-case.js +208 -0
- package/package.json +28 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './lib/plugin-sdk.js';
|
|
2
|
+
export * from './lib/template/json-literal.js';
|
|
3
|
+
export * from './lib/template/template-util.js';
|
|
4
|
+
export * from './lib/template/md-literal.js';
|
|
5
|
+
export * from './lib/template/ts-literal.js';
|
|
6
|
+
export * from './lib/util/change-case.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './lib/plugin-sdk.js';
|
|
2
|
+
export * from './lib/template/json-literal.js';
|
|
3
|
+
export * from './lib/template/template-util.js';
|
|
4
|
+
export * from './lib/template/md-literal.js';
|
|
5
|
+
export * from './lib/template/ts-literal.js';
|
|
6
|
+
export * from './lib/util/change-case.js';
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { OpenAPIV3_1 } from "openapi-types";
|
|
2
|
+
export type IntrigVersion = `^${number}.${number}.${number}`;
|
|
3
|
+
type PackageOverride = {
|
|
4
|
+
[key: string]: string | PackageOverride;
|
|
5
|
+
};
|
|
6
|
+
export interface PackageJson {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
license?: string;
|
|
10
|
+
private?: boolean;
|
|
11
|
+
scripts?: Record<string, string>;
|
|
12
|
+
type?: 'module' | 'commonjs';
|
|
13
|
+
main?: string;
|
|
14
|
+
types?: string;
|
|
15
|
+
typings?: string;
|
|
16
|
+
module?: string;
|
|
17
|
+
exports?: string | Record<string, string | {
|
|
18
|
+
types?: string;
|
|
19
|
+
require?: string;
|
|
20
|
+
import?: string;
|
|
21
|
+
development?: string;
|
|
22
|
+
default?: string;
|
|
23
|
+
}>;
|
|
24
|
+
dependencies?: Record<string, string>;
|
|
25
|
+
devDependencies?: Record<string, string>;
|
|
26
|
+
optionalDependencies?: Record<string, string>;
|
|
27
|
+
peerDependencies?: Record<string, string>;
|
|
28
|
+
peerDependenciesMeta?: Record<string, {
|
|
29
|
+
optional: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
resolutions?: Record<string, string>;
|
|
32
|
+
pnpm?: {
|
|
33
|
+
overrides?: PackageOverride;
|
|
34
|
+
};
|
|
35
|
+
overrides?: PackageOverride;
|
|
36
|
+
bin?: Record<string, string> | string;
|
|
37
|
+
workspaces?: string[] | {
|
|
38
|
+
packages: string[];
|
|
39
|
+
};
|
|
40
|
+
publishConfig?: Record<string, string>;
|
|
41
|
+
files?: string[];
|
|
42
|
+
generators?: string;
|
|
43
|
+
schematics?: string;
|
|
44
|
+
builders?: string;
|
|
45
|
+
executors?: string;
|
|
46
|
+
packageManager?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
keywords?: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface IntrigSourceConfig {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
specUrl: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ResourceDescriptor<T> {
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
type: string;
|
|
59
|
+
source: string;
|
|
60
|
+
path: string;
|
|
61
|
+
data: T;
|
|
62
|
+
lastAccessed?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface SchemaDocumentation {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
jsonSchema: any;
|
|
69
|
+
tabs: any[];
|
|
70
|
+
relatedTypes: any[];
|
|
71
|
+
relatedEndpoints: any[];
|
|
72
|
+
}
|
|
73
|
+
export interface RestDocumentation {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
method: string;
|
|
77
|
+
path: string;
|
|
78
|
+
description: string | undefined;
|
|
79
|
+
requestBody: RelatedType | undefined;
|
|
80
|
+
contentType: string | undefined;
|
|
81
|
+
response: RelatedType | undefined;
|
|
82
|
+
responseType: string | undefined;
|
|
83
|
+
requestUrl: string;
|
|
84
|
+
variables: Variable[];
|
|
85
|
+
responseExamples: Record<string, string>;
|
|
86
|
+
tabs: Tab[];
|
|
87
|
+
}
|
|
88
|
+
export interface CompiledContent {
|
|
89
|
+
path: string;
|
|
90
|
+
content: string;
|
|
91
|
+
}
|
|
92
|
+
export interface RestOptions {
|
|
93
|
+
basePath?: string;
|
|
94
|
+
}
|
|
95
|
+
export type RestData = {
|
|
96
|
+
method: string;
|
|
97
|
+
paths: string[];
|
|
98
|
+
operationId: string;
|
|
99
|
+
requestBody?: string;
|
|
100
|
+
contentType?: string;
|
|
101
|
+
response?: string;
|
|
102
|
+
responseHeaders?: Record<string, string>;
|
|
103
|
+
responseType?: string;
|
|
104
|
+
requestUrl?: string;
|
|
105
|
+
variables?: Variable[];
|
|
106
|
+
description?: string;
|
|
107
|
+
summary?: string;
|
|
108
|
+
responseExamples?: Record<string, string>;
|
|
109
|
+
errorResponses?: Record<string, ErrorResponse>;
|
|
110
|
+
isDownloadable?: boolean;
|
|
111
|
+
};
|
|
112
|
+
export interface Schema {
|
|
113
|
+
name: string;
|
|
114
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
115
|
+
}
|
|
116
|
+
export type Variable = {
|
|
117
|
+
name: string;
|
|
118
|
+
in: string;
|
|
119
|
+
ref: string;
|
|
120
|
+
};
|
|
121
|
+
export type ErrorResponse = {
|
|
122
|
+
response?: string;
|
|
123
|
+
responseType?: string;
|
|
124
|
+
};
|
|
125
|
+
export type RelatedType = {
|
|
126
|
+
name: string;
|
|
127
|
+
id: string;
|
|
128
|
+
};
|
|
129
|
+
export type Tab = {
|
|
130
|
+
name: string;
|
|
131
|
+
content: string;
|
|
132
|
+
};
|
|
133
|
+
export interface GeneratorContext {
|
|
134
|
+
sources: IntrigSourceConfig[];
|
|
135
|
+
restDescriptors: ResourceDescriptor<RestData>[];
|
|
136
|
+
schemaDescriptors: ResourceDescriptor<Schema>[];
|
|
137
|
+
dump(content: Promise<CompiledContent>): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
export declare class StatsCounter {
|
|
140
|
+
readonly sourceId: string;
|
|
141
|
+
counters: Record<string, number>;
|
|
142
|
+
constructor(sourceId: string);
|
|
143
|
+
inc(key: string): void;
|
|
144
|
+
}
|
|
145
|
+
export interface IntrigGeneratorPlugin {
|
|
146
|
+
meta(): {
|
|
147
|
+
name: string;
|
|
148
|
+
version: string;
|
|
149
|
+
compat: IntrigVersion;
|
|
150
|
+
displayName?: string;
|
|
151
|
+
};
|
|
152
|
+
setup?(): Promise<void> | void;
|
|
153
|
+
generate(ctx: GeneratorContext): Promise<StatsCounter[]>;
|
|
154
|
+
getSchemaDocumentation(result: ResourceDescriptor<Schema>): Promise<SchemaDocumentation>;
|
|
155
|
+
getEndpointDocumentation(result: ResourceDescriptor<RestData>, schemas: ResourceDescriptor<Schema>[]): Promise<RestDocumentation>;
|
|
156
|
+
dispose?(): Promise<void> | void;
|
|
157
|
+
}
|
|
158
|
+
export {};
|
|
159
|
+
//# sourceMappingURL=plugin-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-sdk.d.ts","sourceRoot":"","sources":["../../src/lib/plugin-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAE7D,KAAK,eAAe,GAAG;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,eAAe,CAAC;CACzC,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MA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AAI,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-literal.d.ts","sourceRoot":"","sources":["../../../src/lib/template/json-literal.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,aACf,oBAAoB,aAAa,GAAG,EAAE;;;GAc9D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as prettier from 'prettier';
|
|
2
|
+
export function jsonLiteral(path) {
|
|
3
|
+
return async (strings, ...values) => {
|
|
4
|
+
const rawCode = strings.reduce((acc, str, i) => acc + str + (values[i] || ''), '');
|
|
5
|
+
const content = await prettier.format(rawCode, {
|
|
6
|
+
parser: 'json',
|
|
7
|
+
singleQuote: true
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
path,
|
|
11
|
+
content
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"md-literal.d.ts","sourceRoot":"","sources":["../../../src/lib/template/md-literal.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,aACb,oBAAoB,aAAa,GAAG,EAAE;;;GAe9D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as prettier from 'prettier';
|
|
2
|
+
export function mdLiteral(path) {
|
|
3
|
+
return async (strings, ...values) => {
|
|
4
|
+
let rawCode = strings.reduce((acc, str, i) => acc + str + (values[i] || ''), '');
|
|
5
|
+
rawCode = rawCode.replace("<hint>", "<hint style='display:none'>");
|
|
6
|
+
const content = await prettier.format(rawCode, {
|
|
7
|
+
parser: 'markdown'
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
path,
|
|
11
|
+
content
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ErrorResponse, RestData, Variable } from "../plugin-sdk.js";
|
|
2
|
+
export declare function getVariableName(ref: string): string | undefined;
|
|
3
|
+
export declare function getVariableImports(variables: Variable[], source: string, prefix: string): string;
|
|
4
|
+
export declare function getVariableTypes(variables: Variable[]): string;
|
|
5
|
+
export declare function isParamMandatory(variables: Variable[]): boolean;
|
|
6
|
+
export declare function getParamExplodeExpression(variables: Variable[]): string;
|
|
7
|
+
export declare function decodeVariables(_variables: Variable[], source: string, prefix?: string): {
|
|
8
|
+
variableImports: string;
|
|
9
|
+
variableTypes: string;
|
|
10
|
+
isParamMandatory: boolean;
|
|
11
|
+
variableExplodeExpression: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function getDispatchParams(operationId: string, requestBody?: string, isParamMandatory?: boolean): string;
|
|
14
|
+
export declare function getDispatchParamExpansion(requestBody?: string, isParamMandatory?: boolean): string;
|
|
15
|
+
export declare function extractParams(properties: RestData): {
|
|
16
|
+
shape: string;
|
|
17
|
+
shapeImport: string;
|
|
18
|
+
dispatchParams: string;
|
|
19
|
+
dispatchParamExpansion: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function decodeDispatchParams(operationId: string, requestBody?: string, isParamMandatory?: boolean): {
|
|
22
|
+
dispatchParams: string;
|
|
23
|
+
dispatchParamExpansion: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function getDataTransformer(contentType?: string): string;
|
|
26
|
+
export declare function generatePostfix(contentType: string | undefined, responseType: string | undefined): string;
|
|
27
|
+
export declare function decodeErrorSections(errorResponses: Record<string, ErrorResponse>, source: string, prefix?: string): {
|
|
28
|
+
imports: string;
|
|
29
|
+
def: string;
|
|
30
|
+
schemaValidation: string;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=template-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-util.d.ts","sourceRoot":"","sources":["../../../src/lib/template/template-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAC;A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lH"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export function getVariableName(ref) {
|
|
2
|
+
return ref.split('/').pop();
|
|
3
|
+
}
|
|
4
|
+
export function getVariableImports(variables, source, prefix) {
|
|
5
|
+
return variables
|
|
6
|
+
.map(a => getVariableName(a.ref))
|
|
7
|
+
.map((ref) => `import { ${ref} } from "${prefix}/${source}/components/schemas/${ref}.js"`)
|
|
8
|
+
.join("\n");
|
|
9
|
+
}
|
|
10
|
+
export function getVariableTypes(variables) {
|
|
11
|
+
return variables.map((p) => `${p.name}${p.in === "path" ? "" : "?"}: ${getVariableName(p.ref)}`)
|
|
12
|
+
.join("\n");
|
|
13
|
+
}
|
|
14
|
+
export function isParamMandatory(variables) {
|
|
15
|
+
return variables.some(a => a.in === 'path');
|
|
16
|
+
}
|
|
17
|
+
export function getParamExplodeExpression(variables) {
|
|
18
|
+
return [
|
|
19
|
+
...variables.filter(a => a.in === "path").map(a => a.name),
|
|
20
|
+
"...params"
|
|
21
|
+
].join(",");
|
|
22
|
+
}
|
|
23
|
+
export function decodeVariables(_variables, source, prefix = "@root") {
|
|
24
|
+
const variables = _variables.filter(a => ["path", "query"].includes(a.in));
|
|
25
|
+
return {
|
|
26
|
+
variableImports: getVariableImports(variables, source, prefix),
|
|
27
|
+
variableTypes: getVariableTypes(variables),
|
|
28
|
+
isParamMandatory: isParamMandatory(variables),
|
|
29
|
+
variableExplodeExpression: getParamExplodeExpression(variables)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function getDispatchParams(operationId, requestBody, isParamMandatory = false) {
|
|
33
|
+
return [
|
|
34
|
+
requestBody ? `data: RequestBody` : undefined,
|
|
35
|
+
`params: Params${isParamMandatory ? '' : ' | undefined'}`
|
|
36
|
+
]
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join(', ');
|
|
39
|
+
}
|
|
40
|
+
export function getDispatchParamExpansion(requestBody, isParamMandatory) {
|
|
41
|
+
return [
|
|
42
|
+
requestBody && 'data',
|
|
43
|
+
`p${isParamMandatory ? '' : ' = {}'}`
|
|
44
|
+
].filter(Boolean).join(', ');
|
|
45
|
+
}
|
|
46
|
+
export function extractParams(properties) {
|
|
47
|
+
const paramMandatory = isParamMandatory(properties.variables ?? []);
|
|
48
|
+
if (properties.response) {
|
|
49
|
+
if (properties.requestBody) {
|
|
50
|
+
if (paramMandatory) {
|
|
51
|
+
return {
|
|
52
|
+
shape: `BinaryFunctionHook<Params, RequestBody, Response, _ErrorType>`,
|
|
53
|
+
shapeImport: `BinaryFunctionHook`,
|
|
54
|
+
dispatchParamExpansion: `data, p`,
|
|
55
|
+
dispatchParams: "data: RequestBody, params: Params"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return {
|
|
60
|
+
shape: `BinaryFunctionHook<Params, RequestBody, Response, _ErrorType>`,
|
|
61
|
+
shapeImport: `BinaryFunctionHook`,
|
|
62
|
+
dispatchParamExpansion: `data, p = {}`,
|
|
63
|
+
dispatchParams: "data: RequestBody, params?: Params"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (paramMandatory) {
|
|
69
|
+
return {
|
|
70
|
+
shape: `UnaryFunctionHook<Params, Response, _ErrorType>`,
|
|
71
|
+
shapeImport: `UnaryFunctionHook`,
|
|
72
|
+
dispatchParamExpansion: `p`,
|
|
73
|
+
dispatchParams: "params: Params"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return {
|
|
78
|
+
shape: `UnaryFunctionHook<Params, Response, _ErrorType>`,
|
|
79
|
+
shapeImport: `UnaryFunctionHook`,
|
|
80
|
+
dispatchParamExpansion: `p = {}`,
|
|
81
|
+
dispatchParams: "params?: Params"
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (properties.requestBody) {
|
|
88
|
+
if (paramMandatory) {
|
|
89
|
+
return {
|
|
90
|
+
shape: `BinaryProduceHook<Params, RequestBody, _ErrorType>`,
|
|
91
|
+
shapeImport: `BinaryProduceHook`,
|
|
92
|
+
dispatchParamExpansion: `data, p`,
|
|
93
|
+
dispatchParams: "data: RequestBody, params: Params"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return {
|
|
98
|
+
shape: `BinaryProduceHook<Params, RequestBody, _ErrorType>`,
|
|
99
|
+
shapeImport: `BinaryProduceHook`,
|
|
100
|
+
dispatchParamExpansion: `data, p = {}`,
|
|
101
|
+
dispatchParams: "data: RequestBody, params?: Params"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
if (paramMandatory) {
|
|
107
|
+
return {
|
|
108
|
+
shape: `UnaryProduceHook<Params, _ErrorType>`,
|
|
109
|
+
shapeImport: `UnaryProduceHook`,
|
|
110
|
+
dispatchParamExpansion: `p`,
|
|
111
|
+
dispatchParams: "params: Params"
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return {
|
|
116
|
+
shape: `UnaryProduceHook<Params, _ErrorType>`,
|
|
117
|
+
shapeImport: `UnaryProduceHook`,
|
|
118
|
+
dispatchParamExpansion: `p = {}`,
|
|
119
|
+
dispatchParams: "params?: Params"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export function decodeDispatchParams(operationId, requestBody, isParamMandatory) {
|
|
126
|
+
return {
|
|
127
|
+
dispatchParams: getDispatchParams(operationId, requestBody, isParamMandatory),
|
|
128
|
+
dispatchParamExpansion: getDispatchParamExpansion(requestBody, isParamMandatory)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function getDataTransformer(contentType) {
|
|
132
|
+
let finalRequestBodyBlock = 'data';
|
|
133
|
+
switch (contentType) {
|
|
134
|
+
case "application/json":
|
|
135
|
+
case "application/octet-stream":
|
|
136
|
+
case "text/plain":
|
|
137
|
+
finalRequestBodyBlock = `data`;
|
|
138
|
+
break;
|
|
139
|
+
case "multipart/form-data":
|
|
140
|
+
finalRequestBodyBlock = `data: (function(){
|
|
141
|
+
let formData = new FormData()
|
|
142
|
+
Object.entries(data).filter(a => !!a[1]).forEach(([key, value]) => formData.append(key, value))
|
|
143
|
+
return formData;
|
|
144
|
+
})()`;
|
|
145
|
+
break;
|
|
146
|
+
case "application/x-www-form-urlencoded":
|
|
147
|
+
finalRequestBodyBlock = `data: qs.stringify(data)`;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
return finalRequestBodyBlock;
|
|
151
|
+
}
|
|
152
|
+
const contentTypePostfixMap = {
|
|
153
|
+
'application/json': undefined,
|
|
154
|
+
'multipart/form-data': 'form',
|
|
155
|
+
'application/octet-stream': 'binary',
|
|
156
|
+
'application/x-www-form-urlencoded': 'form',
|
|
157
|
+
'application/xml': 'xml',
|
|
158
|
+
'text/plain': 'txt',
|
|
159
|
+
'text/html': 'html',
|
|
160
|
+
'text/css': 'css',
|
|
161
|
+
'text/javascript': 'js',
|
|
162
|
+
};
|
|
163
|
+
export function generatePostfix(contentType, responseType) {
|
|
164
|
+
return [
|
|
165
|
+
contentType && contentTypePostfixMap[contentType] ? `$${contentTypePostfixMap[contentType]}` : undefined,
|
|
166
|
+
responseType && contentTypePostfixMap[responseType] ? `_${contentTypePostfixMap[responseType]}` : undefined,
|
|
167
|
+
].filter(Boolean)
|
|
168
|
+
.join('');
|
|
169
|
+
}
|
|
170
|
+
export function decodeErrorSections(errorResponses, source, prefix = '@root') {
|
|
171
|
+
const errorTypes = Array.from(new Set(Object.values(errorResponses ?? {}).map(a => a.response)));
|
|
172
|
+
const imports = errorTypes.map(ref => `import {${ref}, ${ref}Schema } from "${prefix}/${source}/components/schemas/${ref}.js"`)
|
|
173
|
+
.join('\n');
|
|
174
|
+
let schemaValidation = "z.any()";
|
|
175
|
+
switch (errorTypes.length) {
|
|
176
|
+
case 0:
|
|
177
|
+
schemaValidation = "z.any()";
|
|
178
|
+
break;
|
|
179
|
+
case 1:
|
|
180
|
+
schemaValidation = `${errorTypes[0]}Schema`;
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
schemaValidation = `z.union([${errorTypes.map(a => `${a}Schema`).join(', ')}])`;
|
|
184
|
+
}
|
|
185
|
+
const s = errorTypes.join(' | ');
|
|
186
|
+
const def = `${s.trim().length ? s : 'any'}`;
|
|
187
|
+
return {
|
|
188
|
+
imports,
|
|
189
|
+
def,
|
|
190
|
+
schemaValidation,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-literal.d.ts","sourceRoot":"","sources":["../../../src/lib/template/ts-literal.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,aACd,oBAAoB,aAAa,GAAG,EAAE;;;GAiB9D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as prettier from 'prettier';
|
|
2
|
+
export function typescript(path) {
|
|
3
|
+
return async (strings, ...values) => {
|
|
4
|
+
const rawCode = strings.reduce((acc, str, i) => {
|
|
5
|
+
if (str.startsWith("*/"))
|
|
6
|
+
str = str.slice(2);
|
|
7
|
+
const [before] = str.split("/*!");
|
|
8
|
+
return acc + before + (values?.[i] || '');
|
|
9
|
+
}, '');
|
|
10
|
+
const content = await prettier.format(rawCode, {
|
|
11
|
+
parser: 'typescript',
|
|
12
|
+
singleQuote: true
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
path,
|
|
16
|
+
content
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported locale values. Use `false` to ignore locale.
|
|
3
|
+
* Defaults to `undefined`, which uses the host environment.
|
|
4
|
+
*/
|
|
5
|
+
export type Locale = string[] | string | false | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Options used for converting strings to pascal/camel case.
|
|
8
|
+
*/
|
|
9
|
+
export interface PascalCaseOptions extends Options {
|
|
10
|
+
mergeAmbiguousCharacters?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Options used for converting strings to any case.
|
|
14
|
+
*/
|
|
15
|
+
export interface Options {
|
|
16
|
+
locale?: Locale;
|
|
17
|
+
split?: (value: string) => string[];
|
|
18
|
+
/** @deprecated Pass `split: splitSeparateNumbers` instead. */
|
|
19
|
+
separateNumbers?: boolean;
|
|
20
|
+
delimiter?: string;
|
|
21
|
+
prefixCharacters?: string;
|
|
22
|
+
suffixCharacters?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Split any cased input strings into an array of words.
|
|
26
|
+
*/
|
|
27
|
+
export declare function split(value: string): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Split the input string into an array of words, separating numbers.
|
|
30
|
+
*/
|
|
31
|
+
export declare function splitSeparateNumbers(value: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Convert a string to space separated lower case (`foo bar`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function noCase(input: string, options?: Options): string;
|
|
36
|
+
/**
|
|
37
|
+
* Convert a string to camel case (`fooBar`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function camelCase(input: string, options?: PascalCaseOptions): string;
|
|
40
|
+
/**
|
|
41
|
+
* Convert a string to pascal case (`FooBar`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function pascalCase(input: string, options?: PascalCaseOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Convert a string to pascal snake case (`Foo_Bar`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function pascalSnakeCase(input: string, options?: Options): string;
|
|
48
|
+
/**
|
|
49
|
+
* Convert a string to capital case (`Foo Bar`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function capitalCase(input: string, options?: Options): string;
|
|
52
|
+
/**
|
|
53
|
+
* Convert a string to constant case (`FOO_BAR`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function constantCase(input: string, options?: Options): string;
|
|
56
|
+
/**
|
|
57
|
+
* Convert a string to dot case (`foo.bar`).
|
|
58
|
+
*/
|
|
59
|
+
export declare function dotCase(input: string, options?: Options): string;
|
|
60
|
+
/**
|
|
61
|
+
* Convert a string to kebab case (`foo-bar`).
|
|
62
|
+
*/
|
|
63
|
+
export declare function kebabCase(input: string, options?: Options): string;
|
|
64
|
+
/**
|
|
65
|
+
* Convert a string to path case (`foo/bar`).
|
|
66
|
+
*/
|
|
67
|
+
export declare function pathCase(input: string, options?: Options): string;
|
|
68
|
+
/**
|
|
69
|
+
* Convert a string to path case (`Foo bar`).
|
|
70
|
+
*/
|
|
71
|
+
export declare function sentenceCase(input: string, options?: Options): string;
|
|
72
|
+
/**
|
|
73
|
+
* Convert a string to snake case (`foo_bar`).
|
|
74
|
+
*/
|
|
75
|
+
export declare function snakeCase(input: string, options?: Options): string;
|
|
76
|
+
/**
|
|
77
|
+
* Convert a string to header case (`Foo-Bar`).
|
|
78
|
+
*/
|
|
79
|
+
export declare function trainCase(input: string, options?: Options): string;
|
|
80
|
+
//# sourceMappingURL=change-case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-case.d.ts","sourceRoot":"","sources":["../../../src/lib/util/change-case.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IAChD,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IACpC,8DAA8D;IAC9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,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,UAEzD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,UAEzD"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Regexps involved with splitting words in various case formats.
|
|
2
|
+
const SPLIT_LOWER_UPPER_RE = /([a-z0-9])([A-Z])/g;
|
|
3
|
+
const SPLIT_UPPER_UPPER_RE = /([A-Z])([A-Z][a-z])/g;
|
|
4
|
+
// Used to iterate over the initial split result and separate numbers.
|
|
5
|
+
const SPLIT_SEPARATE_NUMBER_RE = /(\d)[a-z]|([a-zA-Z])\d/g;
|
|
6
|
+
// Regexp involved with stripping non-word characters from the result.
|
|
7
|
+
const DEFAULT_STRIP_REGEXP = /[^a-zA-Z0-9]+/g;
|
|
8
|
+
// The replacement value for splits.
|
|
9
|
+
const SPLIT_REPLACE_VALUE = "$1\0$2";
|
|
10
|
+
// The default characters to keep after transforming case.
|
|
11
|
+
const DEFAULT_PREFIX_SUFFIX_CHARACTERS = "";
|
|
12
|
+
/**
|
|
13
|
+
* Split any cased input strings into an array of words.
|
|
14
|
+
*/
|
|
15
|
+
export function split(value) {
|
|
16
|
+
let result = value.trim();
|
|
17
|
+
result = result
|
|
18
|
+
.replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)
|
|
19
|
+
.replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);
|
|
20
|
+
result = result.replace(DEFAULT_STRIP_REGEXP, "\0");
|
|
21
|
+
let start = 0;
|
|
22
|
+
let end = result.length;
|
|
23
|
+
// Trim the delimiter from around the output string.
|
|
24
|
+
while (result.charAt(start) === "\0")
|
|
25
|
+
start++;
|
|
26
|
+
if (start === end)
|
|
27
|
+
return [];
|
|
28
|
+
while (result.charAt(end - 1) === "\0")
|
|
29
|
+
end--;
|
|
30
|
+
return result.slice(start, end).split(/\0/g);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Split the input string into an array of words, separating numbers.
|
|
34
|
+
*/
|
|
35
|
+
export function splitSeparateNumbers(value) {
|
|
36
|
+
const words = split(value);
|
|
37
|
+
for (let i = 0; i < words.length; i++) {
|
|
38
|
+
const word = words[i];
|
|
39
|
+
const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);
|
|
40
|
+
if (match) {
|
|
41
|
+
const offset = match.index + (match[1] ?? match[2]).length;
|
|
42
|
+
words.splice(i, 1, word.slice(0, offset), word.slice(offset));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return words;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convert a string to space separated lower case (`foo bar`).
|
|
49
|
+
*/
|
|
50
|
+
export function noCase(input, options) {
|
|
51
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
52
|
+
return (prefix +
|
|
53
|
+
words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? " ") +
|
|
54
|
+
suffix);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convert a string to camel case (`fooBar`).
|
|
58
|
+
*/
|
|
59
|
+
export function camelCase(input, options) {
|
|
60
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
61
|
+
const lower = lowerFactory(options?.locale);
|
|
62
|
+
const upper = upperFactory(options?.locale);
|
|
63
|
+
const transform = options?.mergeAmbiguousCharacters
|
|
64
|
+
? capitalCaseTransformFactory(lower, upper)
|
|
65
|
+
: pascalCaseTransformFactory(lower, upper);
|
|
66
|
+
return (prefix +
|
|
67
|
+
words
|
|
68
|
+
.map((word, index) => {
|
|
69
|
+
if (index === 0)
|
|
70
|
+
return lower(word);
|
|
71
|
+
return transform(word, index);
|
|
72
|
+
})
|
|
73
|
+
.join(options?.delimiter ?? "") +
|
|
74
|
+
suffix);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert a string to pascal case (`FooBar`).
|
|
78
|
+
*/
|
|
79
|
+
export function pascalCase(input, options) {
|
|
80
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
81
|
+
const lower = lowerFactory(options?.locale);
|
|
82
|
+
const upper = upperFactory(options?.locale);
|
|
83
|
+
const transform = options?.mergeAmbiguousCharacters
|
|
84
|
+
? capitalCaseTransformFactory(lower, upper)
|
|
85
|
+
: pascalCaseTransformFactory(lower, upper);
|
|
86
|
+
return prefix + words.map(transform).join(options?.delimiter ?? "") + suffix;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convert a string to pascal snake case (`Foo_Bar`).
|
|
90
|
+
*/
|
|
91
|
+
export function pascalSnakeCase(input, options) {
|
|
92
|
+
return capitalCase(input, { delimiter: "_", ...options });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert a string to capital case (`Foo Bar`).
|
|
96
|
+
*/
|
|
97
|
+
export function capitalCase(input, options) {
|
|
98
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
99
|
+
const lower = lowerFactory(options?.locale);
|
|
100
|
+
const upper = upperFactory(options?.locale);
|
|
101
|
+
return (prefix +
|
|
102
|
+
words
|
|
103
|
+
.map(capitalCaseTransformFactory(lower, upper))
|
|
104
|
+
.join(options?.delimiter ?? " ") +
|
|
105
|
+
suffix);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Convert a string to constant case (`FOO_BAR`).
|
|
109
|
+
*/
|
|
110
|
+
export function constantCase(input, options) {
|
|
111
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
112
|
+
return (prefix +
|
|
113
|
+
words.map(upperFactory(options?.locale)).join(options?.delimiter ?? "_") +
|
|
114
|
+
suffix);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Convert a string to dot case (`foo.bar`).
|
|
118
|
+
*/
|
|
119
|
+
export function dotCase(input, options) {
|
|
120
|
+
return noCase(input, { delimiter: ".", ...options });
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Convert a string to kebab case (`foo-bar`).
|
|
124
|
+
*/
|
|
125
|
+
export function kebabCase(input, options) {
|
|
126
|
+
return noCase(input, { delimiter: "-", ...options });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Convert a string to path case (`foo/bar`).
|
|
130
|
+
*/
|
|
131
|
+
export function pathCase(input, options) {
|
|
132
|
+
return noCase(input, { delimiter: "/", ...options });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert a string to path case (`Foo bar`).
|
|
136
|
+
*/
|
|
137
|
+
export function sentenceCase(input, options) {
|
|
138
|
+
const [prefix, words, suffix] = splitPrefixSuffix(input, options);
|
|
139
|
+
const lower = lowerFactory(options?.locale);
|
|
140
|
+
const upper = upperFactory(options?.locale);
|
|
141
|
+
const transform = capitalCaseTransformFactory(lower, upper);
|
|
142
|
+
return (prefix +
|
|
143
|
+
words
|
|
144
|
+
.map((word, index) => {
|
|
145
|
+
if (index === 0)
|
|
146
|
+
return transform(word);
|
|
147
|
+
return lower(word);
|
|
148
|
+
})
|
|
149
|
+
.join(options?.delimiter ?? " ") +
|
|
150
|
+
suffix);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Convert a string to snake case (`foo_bar`).
|
|
154
|
+
*/
|
|
155
|
+
export function snakeCase(input, options) {
|
|
156
|
+
return noCase(input, { delimiter: "_", ...options });
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Convert a string to header case (`Foo-Bar`).
|
|
160
|
+
*/
|
|
161
|
+
export function trainCase(input, options) {
|
|
162
|
+
return capitalCase(input, { delimiter: "-", ...options });
|
|
163
|
+
}
|
|
164
|
+
function lowerFactory(locale) {
|
|
165
|
+
return locale === false
|
|
166
|
+
? (input) => input.toLowerCase()
|
|
167
|
+
: (input) => input.toLocaleLowerCase(locale);
|
|
168
|
+
}
|
|
169
|
+
function upperFactory(locale) {
|
|
170
|
+
return locale === false
|
|
171
|
+
? (input) => input.toUpperCase()
|
|
172
|
+
: (input) => input.toLocaleUpperCase(locale);
|
|
173
|
+
}
|
|
174
|
+
function capitalCaseTransformFactory(lower, upper) {
|
|
175
|
+
return (word) => `${upper(word[0])}${lower(word.slice(1))}`;
|
|
176
|
+
}
|
|
177
|
+
function pascalCaseTransformFactory(lower, upper) {
|
|
178
|
+
return (word, index) => {
|
|
179
|
+
const char0 = word[0];
|
|
180
|
+
const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper(char0);
|
|
181
|
+
return initial + lower(word.slice(1));
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function splitPrefixSuffix(input, options = {}) {
|
|
185
|
+
const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);
|
|
186
|
+
const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
187
|
+
const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;
|
|
188
|
+
let prefixIndex = 0;
|
|
189
|
+
let suffixIndex = input.length;
|
|
190
|
+
while (prefixIndex < input.length) {
|
|
191
|
+
const char = input.charAt(prefixIndex);
|
|
192
|
+
if (!prefixCharacters.includes(char))
|
|
193
|
+
break;
|
|
194
|
+
prefixIndex++;
|
|
195
|
+
}
|
|
196
|
+
while (suffixIndex > prefixIndex) {
|
|
197
|
+
const index = suffixIndex - 1;
|
|
198
|
+
const char = input.charAt(index);
|
|
199
|
+
if (!suffixCharacters.includes(char))
|
|
200
|
+
break;
|
|
201
|
+
suffixIndex = index;
|
|
202
|
+
}
|
|
203
|
+
return [
|
|
204
|
+
input.slice(0, prefixIndex),
|
|
205
|
+
splitFn(input.slice(prefixIndex, suffixIndex)),
|
|
206
|
+
input.slice(suffixIndex),
|
|
207
|
+
];
|
|
208
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intrig/plugin-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"development": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!**/*.tsbuildinfo"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"tslib": "^2.3.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
}
|
|
28
|
+
}
|