@opra/cli 0.31.3 → 0.31.5

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.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import '../esm/oprimp-cli.js';
3
+
@@ -74,22 +74,26 @@ export class ${className} {
74
74
  if (resource.actions.size) {
75
75
  tsFile.addImport('@opra/client', ['HttpRequestObservable']);
76
76
  for (const [action, endpoint] of resource.actions.entries()) {
77
- const typeName = endpoint.returnType?.name || 'any';
77
+ let returnTypeDef = endpoint.returnType ?
78
+ await this.resolveTypeNameOrDef(tsFile, endpoint.returnType)
79
+ : 'any';
80
+ if (returnTypeDef.length > 40)
81
+ returnTypeDef = '\n\t\t' + returnTypeDef + '\n\b\b';
78
82
  const actionPath = resource.getFullPath() + '/' + action;
79
83
  let params = '';
80
84
  for (const prm of endpoint.parameters.values()) {
81
- params += ` ${prm.name}: ${prm.type.name || 'any'}`;
85
+ params += `${prm.name}: ${prm.type.name || 'any'}`;
82
86
  if (prm.isArray)
83
87
  params += '[]';
84
88
  params += ';\n';
85
89
  }
86
- params = params ? '{\n' + params + ' }\n ' : '{}';
90
+ params = params ? '\n\t\t\tparams: {\n\t' + params + '\b}\n\b\b' : '';
87
91
  tsFile.content += `
88
92
  /**
89
93
  * ${(0, string_utils_js_1.wrapJSDocString)(endpoint.description || '')}
90
94
  */
91
- ${action}(params: ${params}): HttpRequestObservable<${typeName}> {
92
- return this[kClient].action('${actionPath}', params);
95
+ ${action}(${params}): HttpRequestObservable<${returnTypeDef}> {\b
96
+ return this[kClient].action('${actionPath}'${params ? ', params' : ''});
93
97
  }
94
98
  `;
95
99
  }
@@ -8,7 +8,6 @@ const string_utils_js_1 = require("../utils/string-utils.js");
8
8
  const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string'];
9
9
  /**
10
10
  *
11
- * @param targetDir
12
11
  */
13
12
  async function processTypes() {
14
13
  const { document } = this;
@@ -20,7 +19,6 @@ exports.processTypes = processTypes;
20
19
  /**
21
20
  *
22
21
  * @param dataType
23
- * @param targetDir
24
22
  */
25
23
  async function generateTypeFile(dataType) {
26
24
  const typeName = dataType.name;
@@ -119,7 +117,14 @@ async function generateComplexTypeDefinition(file, dataType, forInterface) {
119
117
  const baseDef = omitFields.length
120
118
  ? `Omit<${base}, ${omitFields.map(x => "'" + x + "'").join(' | ')}>`
121
119
  : `${base}`;
122
- out += forInterface ? `extends ${baseDef} ` : `${baseDef} & `;
120
+ if (forInterface)
121
+ out += `extends ${baseDef} `;
122
+ else {
123
+ out += baseDef;
124
+ if (!dataType.own.fields.size)
125
+ return out;
126
+ out += ' & ';
127
+ }
123
128
  }
124
129
  out += '{\n\t';
125
130
  for (const field of dataType.own.fields.values()) {
@@ -175,8 +180,10 @@ async function generateSimpleTypeDefinition(file, dataType) {
175
180
  return 'string';
176
181
  if (dataType.extendsFrom('number') || dataType.extendsFrom('integer'))
177
182
  return 'number';
178
- if (dataType.extendsFrom('timestamp') || dataType.extendsFrom('date'))
183
+ if (dataType.extendsFrom('date') || dataType.extendsFrom('datetime'))
179
184
  return 'Date';
185
+ if (dataType.extendsFrom('approxdate') || dataType.extendsFrom('approxdatetime'))
186
+ return 'string';
180
187
  if (dataType.extendsFrom('bigint'))
181
188
  return 'bigint';
182
189
  if (dataType.extendsFrom('object'))
@@ -70,22 +70,26 @@ export class ${className} {
70
70
  if (resource.actions.size) {
71
71
  tsFile.addImport('@opra/client', ['HttpRequestObservable']);
72
72
  for (const [action, endpoint] of resource.actions.entries()) {
73
- const typeName = endpoint.returnType?.name || 'any';
73
+ let returnTypeDef = endpoint.returnType ?
74
+ await this.resolveTypeNameOrDef(tsFile, endpoint.returnType)
75
+ : 'any';
76
+ if (returnTypeDef.length > 40)
77
+ returnTypeDef = '\n\t\t' + returnTypeDef + '\n\b\b';
74
78
  const actionPath = resource.getFullPath() + '/' + action;
75
79
  let params = '';
76
80
  for (const prm of endpoint.parameters.values()) {
77
- params += ` ${prm.name}: ${prm.type.name || 'any'}`;
81
+ params += `${prm.name}: ${prm.type.name || 'any'}`;
78
82
  if (prm.isArray)
79
83
  params += '[]';
80
84
  params += ';\n';
81
85
  }
82
- params = params ? '{\n' + params + ' }\n ' : '{}';
86
+ params = params ? '\n\t\t\tparams: {\n\t' + params + '\b}\n\b\b' : '';
83
87
  tsFile.content += `
84
88
  /**
85
89
  * ${wrapJSDocString(endpoint.description || '')}
86
90
  */
87
- ${action}(params: ${params}): HttpRequestObservable<${typeName}> {
88
- return this[kClient].action('${actionPath}', params);
91
+ ${action}(${params}): HttpRequestObservable<${returnTypeDef}> {\b
92
+ return this[kClient].action('${actionPath}'${params ? ', params' : ''});
89
93
  }
90
94
  `;
91
95
  }
@@ -4,7 +4,6 @@ import { wrapJSDocString } from '../utils/string-utils.js';
4
4
  const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string'];
5
5
  /**
6
6
  *
7
- * @param targetDir
8
7
  */
9
8
  export async function processTypes() {
10
9
  const { document } = this;
@@ -15,7 +14,6 @@ export async function processTypes() {
15
14
  /**
16
15
  *
17
16
  * @param dataType
18
- * @param targetDir
19
17
  */
20
18
  export async function generateTypeFile(dataType) {
21
19
  const typeName = dataType.name;
@@ -112,7 +110,14 @@ export async function generateComplexTypeDefinition(file, dataType, forInterface
112
110
  const baseDef = omitFields.length
113
111
  ? `Omit<${base}, ${omitFields.map(x => "'" + x + "'").join(' | ')}>`
114
112
  : `${base}`;
115
- out += forInterface ? `extends ${baseDef} ` : `${baseDef} & `;
113
+ if (forInterface)
114
+ out += `extends ${baseDef} `;
115
+ else {
116
+ out += baseDef;
117
+ if (!dataType.own.fields.size)
118
+ return out;
119
+ out += ' & ';
120
+ }
116
121
  }
117
122
  out += '{\n\t';
118
123
  for (const field of dataType.own.fields.values()) {
@@ -167,8 +172,10 @@ export async function generateSimpleTypeDefinition(file, dataType) {
167
172
  return 'string';
168
173
  if (dataType.extendsFrom('number') || dataType.extendsFrom('integer'))
169
174
  return 'number';
170
- if (dataType.extendsFrom('timestamp') || dataType.extendsFrom('date'))
175
+ if (dataType.extendsFrom('date') || dataType.extendsFrom('datetime'))
171
176
  return 'Date';
177
+ if (dataType.extendsFrom('approxdate') || dataType.extendsFrom('approxdatetime'))
178
+ return 'string';
172
179
  if (dataType.extendsFrom('bigint'))
173
180
  return 'bigint';
174
181
  if (dataType.extendsFrom('object'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/cli",
3
- "version": "0.31.3",
3
+ "version": "0.31.5",
4
4
  "description": "Opra CLI tools",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -22,13 +22,14 @@
22
22
  "check": "madge --circular src/**",
23
23
  "test": "jest",
24
24
  "cover": "jest --collect-coverage",
25
- "clean": "npm run clean:src && npm run clean:dist && npm run clean:cover",
25
+ "clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
26
26
  "clean:src": "ts-cleanup -s src --all",
27
- "clean:dist": "rimraf ../../build/cli ../../build/client",
27
+ "clean:test": "ts-cleanup -s test --all",
28
+ "clean:dist": "rimraf ../../build/client",
28
29
  "clean:cover": "rimraf ../../coverage/client"
29
30
  },
30
31
  "dependencies": {
31
- "@opra/client": "^0.31.2",
32
+ "@opra/client": "^0.31.5",
32
33
  "chalk": "^5.3.0",
33
34
  "commander": "^11.0.0",
34
35
  "js-string-escape": "^1.0.1",
@@ -60,4 +61,4 @@
60
61
  "tool",
61
62
  "oprimp"
62
63
  ]
63
- }
64
+ }
@@ -3,13 +3,11 @@ import type { ApiExporter } from './api-exporter.js';
3
3
  import { TsFile } from './ts-file.js';
4
4
  /**
5
5
  *
6
- * @param targetDir
7
6
  */
8
7
  export declare function processTypes(this: ApiExporter): Promise<void>;
9
8
  /**
10
9
  *
11
10
  * @param dataType
12
- * @param targetDir
13
11
  */
14
12
  export declare function generateTypeFile(this: ApiExporter, dataType: DataType): Promise<TsFile | undefined>;
15
13
  /**