@opra/cli 0.18.5 → 0.20.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.
|
@@ -6,7 +6,7 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
|
6
6
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
7
|
const common_1 = require("@opra/common");
|
|
8
8
|
const string_utils_js_1 = require("../utils/string-utils.js");
|
|
9
|
-
const internalTypeNames = ['boolean', 'bigint', 'number', 'null', 'string'];
|
|
9
|
+
const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string'];
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
12
12
|
* @param targetDir
|
|
@@ -17,7 +17,8 @@ async function processTypes(targetDir = '') {
|
|
|
17
17
|
const typesTs = this.addFile(node_path_1.default.join(targetDir, 'types.ts'));
|
|
18
18
|
for (const dataType of document.types.values()) {
|
|
19
19
|
const expFile = await this.generateTypeFile(dataType, targetDir);
|
|
20
|
-
|
|
20
|
+
if (expFile)
|
|
21
|
+
typesTs.addExportFile(expFile.filename);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
exports.processTypes = processTypes;
|
|
@@ -28,6 +29,8 @@ exports.processTypes = processTypes;
|
|
|
28
29
|
*/
|
|
29
30
|
async function generateTypeFile(dataType, targetDir = '') {
|
|
30
31
|
const typeName = dataType.name;
|
|
32
|
+
if (typeName === 'any')
|
|
33
|
+
return;
|
|
31
34
|
if (!typeName)
|
|
32
35
|
throw new TypeError(`DataType has no name`);
|
|
33
36
|
let filePath;
|
|
@@ -74,6 +77,8 @@ async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
|
74
77
|
if (internalTypeNames.includes(dataType.name))
|
|
75
78
|
return dataType.name;
|
|
76
79
|
const f = await this.generateTypeFile(dataType);
|
|
80
|
+
if (!f)
|
|
81
|
+
return '';
|
|
77
82
|
file.addImportFile(f.filename, [dataType.name]);
|
|
78
83
|
return dataType.name;
|
|
79
84
|
}
|
|
@@ -87,7 +92,7 @@ async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
|
87
92
|
return this.generateUnionTypeDefinition(file, dataType, forInterface);
|
|
88
93
|
if (dataType instanceof common_1.MappedType)
|
|
89
94
|
return this.generateMappedTypeDefinition(file, dataType, forInterface);
|
|
90
|
-
return '
|
|
95
|
+
return '';
|
|
91
96
|
}
|
|
92
97
|
exports.resolveTypeNameOrDef = resolveTypeNameOrDef;
|
|
93
98
|
/**
|
|
@@ -138,16 +143,16 @@ exports.generateComplexTypeDefinition = generateComplexTypeDefinition;
|
|
|
138
143
|
* @param dataType
|
|
139
144
|
*/
|
|
140
145
|
async function generateSimpleTypeDefinition(file, dataType) {
|
|
141
|
-
if (dataType.
|
|
146
|
+
if (dataType.extendsFrom('boolean'))
|
|
142
147
|
return 'boolean';
|
|
143
|
-
if (dataType.
|
|
148
|
+
if (dataType.extendsFrom('string'))
|
|
144
149
|
return 'string';
|
|
145
|
-
if (dataType.
|
|
150
|
+
if (dataType.extendsFrom('number') || dataType.extendsFrom('integer'))
|
|
146
151
|
return 'number';
|
|
147
|
-
if (dataType.
|
|
152
|
+
if (dataType.extendsFrom('timestamp') || dataType.extendsFrom('date'))
|
|
148
153
|
return 'Date';
|
|
149
154
|
if (dataType.extendsFrom('bigint'))
|
|
150
|
-
return '
|
|
155
|
+
return 'bigint';
|
|
151
156
|
if (dataType.extendsFrom('object'))
|
|
152
157
|
return 'object';
|
|
153
158
|
return 'any';
|
|
@@ -194,11 +199,10 @@ exports.generateUnionTypeDefinition = generateUnionTypeDefinition;
|
|
|
194
199
|
* @param forInterface
|
|
195
200
|
*/
|
|
196
201
|
async function generateMappedTypeDefinition(file, dataType, forInterface) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
'>';
|
|
202
|
+
const typeName = await this.resolveTypeNameOrDef(file, dataType.type, forInterface);
|
|
203
|
+
const keys = (dataType.pick || dataType.omit || []);
|
|
204
|
+
if (!keys.length)
|
|
205
|
+
return typeName;
|
|
206
|
+
return `${dataType.pick ? 'Pick<' : 'Omit<'}${typeName}, ${keys.map(x => `'${x}'`).join(' | ')}>`;
|
|
203
207
|
}
|
|
204
208
|
exports.generateMappedTypeDefinition = generateMappedTypeDefinition;
|
package/cjs/oprimp-cli.js
CHANGED
|
@@ -28,7 +28,7 @@ commander_1.program
|
|
|
28
28
|
name: options.name,
|
|
29
29
|
importExt: options.ext,
|
|
30
30
|
fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
|
|
31
|
-
'/* eslint-disable
|
|
31
|
+
'/* eslint-disable */\n'
|
|
32
32
|
});
|
|
33
33
|
console.log(chalk_1.default.greenBright('Completed'));
|
|
34
34
|
});
|
|
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { ComplexType, EnumType, joinPath, MappedType, SimpleType, UnionType } from '@opra/common';
|
|
4
4
|
import { wrapJSDocString } from '../utils/string-utils.js';
|
|
5
|
-
const internalTypeNames = ['boolean', 'bigint', 'number', 'null', 'string'];
|
|
5
|
+
const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string'];
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* @param targetDir
|
|
@@ -13,7 +13,8 @@ export async function processTypes(targetDir = '') {
|
|
|
13
13
|
const typesTs = this.addFile(path.join(targetDir, 'types.ts'));
|
|
14
14
|
for (const dataType of document.types.values()) {
|
|
15
15
|
const expFile = await this.generateTypeFile(dataType, targetDir);
|
|
16
|
-
|
|
16
|
+
if (expFile)
|
|
17
|
+
typesTs.addExportFile(expFile.filename);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
@@ -23,6 +24,8 @@ export async function processTypes(targetDir = '') {
|
|
|
23
24
|
*/
|
|
24
25
|
export async function generateTypeFile(dataType, targetDir = '') {
|
|
25
26
|
const typeName = dataType.name;
|
|
27
|
+
if (typeName === 'any')
|
|
28
|
+
return;
|
|
26
29
|
if (!typeName)
|
|
27
30
|
throw new TypeError(`DataType has no name`);
|
|
28
31
|
let filePath;
|
|
@@ -68,6 +71,8 @@ export async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
|
68
71
|
if (internalTypeNames.includes(dataType.name))
|
|
69
72
|
return dataType.name;
|
|
70
73
|
const f = await this.generateTypeFile(dataType);
|
|
74
|
+
if (!f)
|
|
75
|
+
return '';
|
|
71
76
|
file.addImportFile(f.filename, [dataType.name]);
|
|
72
77
|
return dataType.name;
|
|
73
78
|
}
|
|
@@ -81,7 +86,7 @@ export async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
|
81
86
|
return this.generateUnionTypeDefinition(file, dataType, forInterface);
|
|
82
87
|
if (dataType instanceof MappedType)
|
|
83
88
|
return this.generateMappedTypeDefinition(file, dataType, forInterface);
|
|
84
|
-
return '
|
|
89
|
+
return '';
|
|
85
90
|
}
|
|
86
91
|
/**
|
|
87
92
|
*
|
|
@@ -130,16 +135,16 @@ export async function generateComplexTypeDefinition(file, dataType, forInterface
|
|
|
130
135
|
* @param dataType
|
|
131
136
|
*/
|
|
132
137
|
export async function generateSimpleTypeDefinition(file, dataType) {
|
|
133
|
-
if (dataType.
|
|
138
|
+
if (dataType.extendsFrom('boolean'))
|
|
134
139
|
return 'boolean';
|
|
135
|
-
if (dataType.
|
|
140
|
+
if (dataType.extendsFrom('string'))
|
|
136
141
|
return 'string';
|
|
137
|
-
if (dataType.
|
|
142
|
+
if (dataType.extendsFrom('number') || dataType.extendsFrom('integer'))
|
|
138
143
|
return 'number';
|
|
139
|
-
if (dataType.
|
|
144
|
+
if (dataType.extendsFrom('timestamp') || dataType.extendsFrom('date'))
|
|
140
145
|
return 'Date';
|
|
141
146
|
if (dataType.extendsFrom('bigint'))
|
|
142
|
-
return '
|
|
147
|
+
return 'bigint';
|
|
143
148
|
if (dataType.extendsFrom('object'))
|
|
144
149
|
return 'object';
|
|
145
150
|
return 'any';
|
|
@@ -183,10 +188,9 @@ export async function generateUnionTypeDefinition(file, dataType, forInterface)
|
|
|
183
188
|
* @param forInterface
|
|
184
189
|
*/
|
|
185
190
|
export async function generateMappedTypeDefinition(file, dataType, forInterface) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
'>';
|
|
191
|
+
const typeName = await this.resolveTypeNameOrDef(file, dataType.type, forInterface);
|
|
192
|
+
const keys = (dataType.pick || dataType.omit || []);
|
|
193
|
+
if (!keys.length)
|
|
194
|
+
return typeName;
|
|
195
|
+
return `${dataType.pick ? 'Pick<' : 'Omit<'}${typeName}, ${keys.map(x => `'${x}'`).join(' | ')}>`;
|
|
192
196
|
}
|
package/esm/oprimp-cli.js
CHANGED
|
@@ -25,7 +25,7 @@ program
|
|
|
25
25
|
name: options.name,
|
|
26
26
|
importExt: options.ext,
|
|
27
27
|
fileHeader: '/* Generated by OPRA Service Generator, Version ' + pkgJson.version + '*/\n' +
|
|
28
|
-
'/* eslint-disable
|
|
28
|
+
'/* eslint-disable */\n'
|
|
29
29
|
});
|
|
30
30
|
console.log(chalk.greenBright('Completed'));
|
|
31
31
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"clean:cover": "rimraf ../../coverage/client"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@opra/client": "^0.
|
|
32
|
-
"chalk": "^5.
|
|
33
|
-
"commander": "^
|
|
31
|
+
"@opra/client": "^0.20.0",
|
|
32
|
+
"chalk": "^5.3.0",
|
|
33
|
+
"commander": "^11.0.0",
|
|
34
34
|
"js-string-escape": "^1.0.1",
|
|
35
35
|
"putil-flattentext": "^2.1.1",
|
|
36
36
|
"putil-varhelpers": "^1.6.5"
|
|
@@ -64,4 +64,4 @@
|
|
|
64
64
|
"tool",
|
|
65
65
|
"oprimp"
|
|
66
66
|
]
|
|
67
|
-
}
|
|
67
|
+
}
|
|
@@ -11,7 +11,7 @@ export declare function processTypes(this: ApiExporter, targetDir?: string): Pro
|
|
|
11
11
|
* @param dataType
|
|
12
12
|
* @param targetDir
|
|
13
13
|
*/
|
|
14
|
-
export declare function generateTypeFile(this: ApiExporter, dataType: DataType, targetDir?: string): Promise<TsFile>;
|
|
14
|
+
export declare function generateTypeFile(this: ApiExporter, dataType: DataType, targetDir?: string): Promise<TsFile | undefined>;
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
17
17
|
* @param file
|