@opra/cli 0.31.1 → 0.31.3
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,9 +6,7 @@ const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
|
6
6
|
const common_1 = require("@opra/common");
|
|
7
7
|
const string_utils_js_1 = require("../utils/string-utils.js");
|
|
8
8
|
async function processResource(resource, className, tsFile) {
|
|
9
|
-
tsFile.addImport('@opra/client', ['kClient', '
|
|
10
|
-
const indexTs = this.addFile('/index.ts', true);
|
|
11
|
-
indexTs.addExport(tsFile.filename);
|
|
9
|
+
tsFile.addImport('@opra/client', ['kClient', 'OpraHttpClient']);
|
|
12
10
|
tsFile.content = `\n
|
|
13
11
|
/**
|
|
14
12
|
* ${(0, string_utils_js_1.wrapJSDocString)(resource.description || '')}
|
|
@@ -49,7 +47,7 @@ export class ${className} {
|
|
|
49
47
|
tsFile.addImport('@opra/client', ['HttpCollectionNode']);
|
|
50
48
|
const typeName = resource.type.name || '';
|
|
51
49
|
tsFile.addImport(`/types/${typeName}`, [typeName], true);
|
|
52
|
-
constructorBody += ` const node = this[kClient].collection('${resource.
|
|
50
|
+
constructorBody += ` const node = this[kClient].collection('${resource.getFullPath()}');\n`;
|
|
53
51
|
for (const [operation, endpoint] of resource.operations.entries()) {
|
|
54
52
|
tsFile.content += `
|
|
55
53
|
/**
|
|
@@ -63,7 +61,7 @@ export class ${className} {
|
|
|
63
61
|
tsFile.addImport('@opra/client', ['HttpSingletonNode']);
|
|
64
62
|
const typeName = resource.type.name || '';
|
|
65
63
|
tsFile.addImport(`/types/${typeName}`, [typeName], true);
|
|
66
|
-
constructorBody += ` const node = this[kClient].singleton('${resource.
|
|
64
|
+
constructorBody += ` const node = this[kClient].singleton('${resource.getFullPath()}');\n`;
|
|
67
65
|
for (const [operation, endpoint] of resource.operations.entries()) {
|
|
68
66
|
tsFile.content += `
|
|
69
67
|
/**
|
|
@@ -82,7 +82,7 @@ exports.generateTypeFile = generateTypeFile;
|
|
|
82
82
|
* @param forInterface
|
|
83
83
|
*/
|
|
84
84
|
async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
85
|
-
if (dataType.name) {
|
|
85
|
+
if (dataType.name && !dataType.isAnonymous) {
|
|
86
86
|
if (internalTypeNames.includes(dataType.name))
|
|
87
87
|
return dataType.name;
|
|
88
88
|
const f = await this.generateTypeFile(dataType);
|
|
@@ -114,9 +114,14 @@ async function generateComplexTypeDefinition(file, dataType, forInterface) {
|
|
|
114
114
|
let out = '';
|
|
115
115
|
if (dataType.base) {
|
|
116
116
|
const base = await this.resolveTypeNameOrDef(file, dataType.base, forInterface);
|
|
117
|
-
|
|
117
|
+
const omitFields = [...dataType.own.fields.keys()]
|
|
118
|
+
.filter(k => dataType.base?.fields.has(k));
|
|
119
|
+
const baseDef = omitFields.length
|
|
120
|
+
? `Omit<${base}, ${omitFields.map(x => "'" + x + "'").join(' | ')}>`
|
|
121
|
+
: `${base}`;
|
|
122
|
+
out += forInterface ? `extends ${baseDef} ` : `${baseDef} & `;
|
|
118
123
|
}
|
|
119
|
-
out += '{\n\
|
|
124
|
+
out += '{\n\t';
|
|
120
125
|
for (const field of dataType.own.fields.values()) {
|
|
121
126
|
// Print JSDoc
|
|
122
127
|
let jsDoc = '';
|
|
@@ -137,16 +142,20 @@ async function generateComplexTypeDefinition(file, dataType, forInterface) {
|
|
|
137
142
|
if (field.deprecated)
|
|
138
143
|
jsDoc += ` * @deprecated ` + (typeof field.deprecated === 'string' ? field.deprecated : '') + '\n';
|
|
139
144
|
if (jsDoc)
|
|
140
|
-
out +=
|
|
145
|
+
out += `\n/**\n${jsDoc} */\n`;
|
|
146
|
+
else
|
|
147
|
+
out += `\n`;
|
|
141
148
|
// Print field name
|
|
142
149
|
if (field.readonly)
|
|
143
150
|
out += 'readonly ';
|
|
144
151
|
out += `${field.name}${field.required ? '' : '?'}: `;
|
|
145
|
-
if (field.fixed)
|
|
146
|
-
|
|
152
|
+
if (field.fixed) {
|
|
153
|
+
const t = typeof field.fixed;
|
|
154
|
+
out += `${t === 'number' || t === 'boolean' || t === 'bigint' ? field.fixed : "'" + field.fixed + "'"}\n`;
|
|
155
|
+
}
|
|
147
156
|
else {
|
|
148
157
|
out += await this.resolveTypeNameOrDef(file, field.type) +
|
|
149
|
-
`${field.isArray ? '[]' : ''};\n
|
|
158
|
+
`${field.isArray ? '[]' : ''};\n`;
|
|
150
159
|
}
|
|
151
160
|
}
|
|
152
161
|
if (dataType.additionalFields)
|
|
@@ -2,9 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { Collection, Container, Singleton } from '@opra/common';
|
|
3
3
|
import { wrapJSDocString } from '../utils/string-utils.js';
|
|
4
4
|
export async function processResource(resource, className, tsFile) {
|
|
5
|
-
tsFile.addImport('@opra/client', ['kClient', '
|
|
6
|
-
const indexTs = this.addFile('/index.ts', true);
|
|
7
|
-
indexTs.addExport(tsFile.filename);
|
|
5
|
+
tsFile.addImport('@opra/client', ['kClient', 'OpraHttpClient']);
|
|
8
6
|
tsFile.content = `\n
|
|
9
7
|
/**
|
|
10
8
|
* ${wrapJSDocString(resource.description || '')}
|
|
@@ -45,7 +43,7 @@ export class ${className} {
|
|
|
45
43
|
tsFile.addImport('@opra/client', ['HttpCollectionNode']);
|
|
46
44
|
const typeName = resource.type.name || '';
|
|
47
45
|
tsFile.addImport(`/types/${typeName}`, [typeName], true);
|
|
48
|
-
constructorBody += ` const node = this[kClient].collection('${resource.
|
|
46
|
+
constructorBody += ` const node = this[kClient].collection('${resource.getFullPath()}');\n`;
|
|
49
47
|
for (const [operation, endpoint] of resource.operations.entries()) {
|
|
50
48
|
tsFile.content += `
|
|
51
49
|
/**
|
|
@@ -59,7 +57,7 @@ export class ${className} {
|
|
|
59
57
|
tsFile.addImport('@opra/client', ['HttpSingletonNode']);
|
|
60
58
|
const typeName = resource.type.name || '';
|
|
61
59
|
tsFile.addImport(`/types/${typeName}`, [typeName], true);
|
|
62
|
-
constructorBody += ` const node = this[kClient].singleton('${resource.
|
|
60
|
+
constructorBody += ` const node = this[kClient].singleton('${resource.getFullPath()}');\n`;
|
|
63
61
|
for (const [operation, endpoint] of resource.operations.entries()) {
|
|
64
62
|
tsFile.content += `
|
|
65
63
|
/**
|
|
@@ -76,7 +76,7 @@ export type ${typeName} = ` + await this.generateSimpleTypeDefinition(file, data
|
|
|
76
76
|
* @param forInterface
|
|
77
77
|
*/
|
|
78
78
|
export async function resolveTypeNameOrDef(file, dataType, forInterface) {
|
|
79
|
-
if (dataType.name) {
|
|
79
|
+
if (dataType.name && !dataType.isAnonymous) {
|
|
80
80
|
if (internalTypeNames.includes(dataType.name))
|
|
81
81
|
return dataType.name;
|
|
82
82
|
const f = await this.generateTypeFile(dataType);
|
|
@@ -107,9 +107,14 @@ export async function generateComplexTypeDefinition(file, dataType, forInterface
|
|
|
107
107
|
let out = '';
|
|
108
108
|
if (dataType.base) {
|
|
109
109
|
const base = await this.resolveTypeNameOrDef(file, dataType.base, forInterface);
|
|
110
|
-
|
|
110
|
+
const omitFields = [...dataType.own.fields.keys()]
|
|
111
|
+
.filter(k => dataType.base?.fields.has(k));
|
|
112
|
+
const baseDef = omitFields.length
|
|
113
|
+
? `Omit<${base}, ${omitFields.map(x => "'" + x + "'").join(' | ')}>`
|
|
114
|
+
: `${base}`;
|
|
115
|
+
out += forInterface ? `extends ${baseDef} ` : `${baseDef} & `;
|
|
111
116
|
}
|
|
112
|
-
out += '{\n\
|
|
117
|
+
out += '{\n\t';
|
|
113
118
|
for (const field of dataType.own.fields.values()) {
|
|
114
119
|
// Print JSDoc
|
|
115
120
|
let jsDoc = '';
|
|
@@ -130,16 +135,20 @@ export async function generateComplexTypeDefinition(file, dataType, forInterface
|
|
|
130
135
|
if (field.deprecated)
|
|
131
136
|
jsDoc += ` * @deprecated ` + (typeof field.deprecated === 'string' ? field.deprecated : '') + '\n';
|
|
132
137
|
if (jsDoc)
|
|
133
|
-
out +=
|
|
138
|
+
out += `\n/**\n${jsDoc} */\n`;
|
|
139
|
+
else
|
|
140
|
+
out += `\n`;
|
|
134
141
|
// Print field name
|
|
135
142
|
if (field.readonly)
|
|
136
143
|
out += 'readonly ';
|
|
137
144
|
out += `${field.name}${field.required ? '' : '?'}: `;
|
|
138
|
-
if (field.fixed)
|
|
139
|
-
|
|
145
|
+
if (field.fixed) {
|
|
146
|
+
const t = typeof field.fixed;
|
|
147
|
+
out += `${t === 'number' || t === 'boolean' || t === 'bigint' ? field.fixed : "'" + field.fixed + "'"}\n`;
|
|
148
|
+
}
|
|
140
149
|
else {
|
|
141
150
|
out += await this.resolveTypeNameOrDef(file, field.type) +
|
|
142
|
-
`${field.isArray ? '[]' : ''};\n
|
|
151
|
+
`${field.isArray ? '[]' : ''};\n`;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
if (dataType.additionalFields)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/cli",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.3",
|
|
4
4
|
"description": "Opra CLI tools",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"clean:cover": "rimraf ../../coverage/client"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@opra/client": "^0.31.
|
|
31
|
+
"@opra/client": "^0.31.2",
|
|
32
32
|
"chalk": "^5.3.0",
|
|
33
33
|
"commander": "^11.0.0",
|
|
34
34
|
"js-string-escape": "^1.0.1",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"tool",
|
|
61
61
|
"oprimp"
|
|
62
62
|
]
|
|
63
|
-
}
|
|
63
|
+
}
|