oip-common 0.0.33 → 0.0.36
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/assets/i18n/ru.json +223 -223
- package/assets/layout/_core.scss +30 -30
- package/fesm2022/oip-common.mjs +171 -184
- package/fesm2022/oip-common.mjs.map +1 -1
- package/index.d.ts +7 -3
- package/package.json +1 -4
- package/scripts/generate-api.mjs +147 -163
- package/templates/api.ejs +4 -0
- package/templates/http-client.ejs +4 -0
package/index.d.ts
CHANGED
|
@@ -695,6 +695,12 @@ interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
|
695
695
|
cancelToken?: CancelToken;
|
|
696
696
|
}
|
|
697
697
|
type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
698
|
+
interface ApiConfig<SecurityDataType = unknown> {
|
|
699
|
+
baseUrl?: string;
|
|
700
|
+
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
|
|
701
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
702
|
+
customFetch?: typeof fetch;
|
|
703
|
+
}
|
|
698
704
|
type CancelToken = Symbol | string | number;
|
|
699
705
|
declare enum ContentType {
|
|
700
706
|
Json = "application/json",
|
|
@@ -704,15 +710,13 @@ declare enum ContentType {
|
|
|
704
710
|
Text = "text/plain"
|
|
705
711
|
}
|
|
706
712
|
declare class HttpClient<SecurityDataType = unknown> {
|
|
707
|
-
protected securityService: SecurityService;
|
|
708
|
-
protected layoutService: LayoutService;
|
|
709
713
|
baseUrl: string;
|
|
710
714
|
private securityData;
|
|
711
715
|
private securityWorker?;
|
|
712
716
|
private abortControllers;
|
|
713
717
|
private customFetch;
|
|
714
718
|
private baseApiParams;
|
|
715
|
-
constructor();
|
|
719
|
+
constructor(apiConfig?: ApiConfig<SecurityDataType>);
|
|
716
720
|
setSecurityData: (data: SecurityDataType | null) => void;
|
|
717
721
|
protected encodeQueryParam(key: string, value: any): string;
|
|
718
722
|
protected addQueryParam(query: QueryParamsType, key: string): string;
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oip-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "A template for cross-platform web applications based on sakai-ng and primeNG",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"oip",
|
|
8
8
|
"template"
|
|
9
9
|
],
|
|
10
|
-
"bin": {
|
|
11
|
-
"oip-generate-api": "./dist/oip-common/scripts/generate-api.mjs"
|
|
12
|
-
},
|
|
13
10
|
"author": "Igor Tyulyakov aka g101k",
|
|
14
11
|
"license": "MIT",
|
|
15
12
|
"repository": {
|
package/scripts/generate-api.mjs
CHANGED
|
@@ -1,163 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
parser.add_argument(
|
|
13
|
-
parser.add_argument(
|
|
14
|
-
parser.add_argument(
|
|
15
|
-
|
|
16
|
-
parser.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
a
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
.catch((e) => console.error(e));
|
|
153
|
-
|
|
154
|
-
/*
|
|
155
|
-
generateTemplates({
|
|
156
|
-
cleanOutput: false,
|
|
157
|
-
output: './output/',
|
|
158
|
-
httpClientType: "fetch",
|
|
159
|
-
modular: true,
|
|
160
|
-
silent: false,
|
|
161
|
-
rewrite: false,
|
|
162
|
-
});
|
|
163
|
-
*/
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { generateApi, generateTemplates } from "swagger-typescript-api";
|
|
4
|
+
import { ArgumentParser } from "argparse";
|
|
5
|
+
|
|
6
|
+
const parser = new ArgumentParser({
|
|
7
|
+
description: "Argparse example"
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
parser.add_argument("-o", "--output", { help: "Output path" });
|
|
11
|
+
parser.add_argument("-i", "--input", { help: "Input swagger file path" });
|
|
12
|
+
parser.add_argument("-t", "--templates", { help: "Templates" });
|
|
13
|
+
parser.add_argument("-d", "--data-contract-prefix", { help: "Data Contract Prefix" });
|
|
14
|
+
parser.add_argument("-c", "--use-common-client", { action: "store_true", help: "Use common http client" });
|
|
15
|
+
|
|
16
|
+
let a = parser.parse_args();
|
|
17
|
+
a.data_contract_prefix ??= "";
|
|
18
|
+
|
|
19
|
+
console.log(a);
|
|
20
|
+
/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
|
|
21
|
+
|
|
22
|
+
let config = {
|
|
23
|
+
input: path.resolve(process.cwd(), a.input),
|
|
24
|
+
templates: path.resolve(process.cwd(), a.templates),
|
|
25
|
+
httpClientType: "fetch", // or "fetch"
|
|
26
|
+
defaultResponseAsSuccess: false,
|
|
27
|
+
generateClient: true,
|
|
28
|
+
useCommonClient: a.use_common_client,
|
|
29
|
+
generateRouteTypes: false,
|
|
30
|
+
generateResponses: true,
|
|
31
|
+
toJS: false,
|
|
32
|
+
extractRequestParams: true,
|
|
33
|
+
extractRequestBody: true,
|
|
34
|
+
extractEnums: true,
|
|
35
|
+
unwrapResponseData: true,
|
|
36
|
+
modular: true,
|
|
37
|
+
prettier: {
|
|
38
|
+
printWidth: 120,
|
|
39
|
+
tabWidth: 2,
|
|
40
|
+
trailingComma: "all",
|
|
41
|
+
parser: "typescript"
|
|
42
|
+
},
|
|
43
|
+
defaultResponseType: "void",
|
|
44
|
+
singleHttpClient: false,
|
|
45
|
+
cleanOutput: false,
|
|
46
|
+
enumNamesAsValues: false,
|
|
47
|
+
moduleNameFirstTag: true,
|
|
48
|
+
generateUnionEnums: false,
|
|
49
|
+
dataContractPrefix: a.data_contract_prefix,
|
|
50
|
+
typePrefix: "",
|
|
51
|
+
typeSuffix: "",
|
|
52
|
+
enumKeyPrefix: "",
|
|
53
|
+
enumKeySuffix: "",
|
|
54
|
+
addReadonly: false,
|
|
55
|
+
sortTypes: false,
|
|
56
|
+
sortRouters: false,
|
|
57
|
+
extractingOptions: {
|
|
58
|
+
requestBodySuffix: ["Payload", "Body", "Input"],
|
|
59
|
+
requestParamsSuffix: ["Params"],
|
|
60
|
+
responseBodySuffix: ["Data", "Result", "Output"],
|
|
61
|
+
responseErrorSuffix: ["Error", "Fail", "Fails", "ErrorData", "HttpError", "BadResponse"]
|
|
62
|
+
},
|
|
63
|
+
/** allow to generate extra files based with this extra templates, see more below */
|
|
64
|
+
extraTemplates: [],
|
|
65
|
+
anotherArrayType: false,
|
|
66
|
+
fixInvalidTypeNamePrefix: "Type",
|
|
67
|
+
fixInvalidEnumKeyPrefix: "Value",
|
|
68
|
+
codeGenConstructs: (constructs) => ({
|
|
69
|
+
...constructs,
|
|
70
|
+
RecordType: (key, value) => `MyRecord<key, value>`
|
|
71
|
+
}),
|
|
72
|
+
primitiveTypeConstructs: (constructs) => ({
|
|
73
|
+
...constructs,
|
|
74
|
+
string: {
|
|
75
|
+
"date-time": "Date"
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
hooks: {
|
|
79
|
+
onCreateComponent: (component) => {},
|
|
80
|
+
onCreateRequestParams: (rawType) => {},
|
|
81
|
+
onCreateRoute: (routeData) => {},
|
|
82
|
+
onCreateRouteName: (routeNameInfo, rawRouteInfo) => {
|
|
83
|
+
if (routeNameInfo.usage.startsWith(rawRouteInfo.moduleName)) {
|
|
84
|
+
const str = routeNameInfo.usage.substring(rawRouteInfo.moduleName.length);
|
|
85
|
+
routeNameInfo.usage = str[0].toLowerCase() + str.slice(1);
|
|
86
|
+
routeNameInfo.original = routeNameInfo.usage;
|
|
87
|
+
}
|
|
88
|
+
return routeNameInfo;
|
|
89
|
+
},
|
|
90
|
+
onFormatRouteName: (routeInfo, templateRouteName) => {},
|
|
91
|
+
onFormatTypeName: (typeName, rawTypeName, schemaType) => {},
|
|
92
|
+
onInit: (configuration) => {},
|
|
93
|
+
onPreParseSchema: (originalSchema, typeName, schemaType) => {},
|
|
94
|
+
onParseSchema: (originalSchema, parsedSchema) => {},
|
|
95
|
+
onPrepareConfig: (currentConfiguration) => {}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const toKebabCase = (str) =>
|
|
99
|
+
str &&
|
|
100
|
+
str
|
|
101
|
+
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
102
|
+
.map((x) => x.toLowerCase())
|
|
103
|
+
.join("-");
|
|
104
|
+
|
|
105
|
+
generateApi(config)
|
|
106
|
+
.then(async ({ files, configuration }) => {
|
|
107
|
+
let dir = path.join(process.cwd(), a.output);
|
|
108
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
|
|
109
|
+
|
|
110
|
+
for (const f of files) {
|
|
111
|
+
if (f.fileContent) {
|
|
112
|
+
if (a.use_common_client && f.fileName === "http-client") {
|
|
113
|
+
console.log("Use common http client from oip, skip generate http-client.ts");
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (f.fileName === "data-contracts") {
|
|
118
|
+
f.fileName = config.dataContractPrefix + f.fileName;
|
|
119
|
+
} else if (f.fileName.endsWith("http-client")) {
|
|
120
|
+
// do nothing
|
|
121
|
+
} else {
|
|
122
|
+
f.fileName = `${toKebabCase(f.fileName)}.api`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const absolutePath = path.join(dir, `${f.fileName}${f.fileExtension}`);
|
|
126
|
+
fs.writeFile(absolutePath, f.fileContent, (err) => {
|
|
127
|
+
if (err) {
|
|
128
|
+
console.log(err);
|
|
129
|
+
} else {
|
|
130
|
+
console.log(`File create: ${f.fileName}${f.fileExtension}`);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
.catch((e) => console.error(e));
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
generateTemplates({
|
|
140
|
+
cleanOutput: false,
|
|
141
|
+
output: './output/',
|
|
142
|
+
httpClientType: "fetch",
|
|
143
|
+
modular: true,
|
|
144
|
+
silent: false,
|
|
145
|
+
rewrite: false,
|
|
146
|
+
});
|
|
147
|
+
*/
|
package/templates/api.ejs
CHANGED