@opra/cli 0.29.0 → 0.29.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.
@@ -6,7 +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', ['HttpServiceBase', 'kClient', 'kContext']);
9
+ tsFile.addImport('@opra/client', ['kClient', 'kContext', 'OpraHttpClient']);
10
10
  const indexTs = this.addFile('/index.ts', true);
11
11
  indexTs.addExport(tsFile.filename);
12
12
  tsFile.content = `\n
@@ -15,15 +15,19 @@ async function processResource(resource, className, tsFile) {
15
15
  * @class ${className}
16
16
  * @url ${node_path_1.default.posix.join(this.client.serviceUrl, '#resources/' + className)}
17
17
  */
18
- export class ${className} extends HttpServiceBase {\n`;
18
+ export class ${className} {
19
+ readonly [kClient]: OpraHttpClient;\n`;
20
+ let constructorBody = `
21
+ constructor(client: OpraHttpClient) {
22
+ this[kClient] = client;\n`;
19
23
  if (resource instanceof common_1.Container) {
20
24
  for (const child of resource.resources.values()) {
21
25
  // Determine class name of child resource
22
- let childClassName = '';
26
+ let childClassName = child.name.charAt(0).toUpperCase() + child.name.substring(1);
23
27
  if (child instanceof common_1.Container)
24
- childClassName = child.name.charAt(0).toUpperCase() + child.name.substring(1) + 'Container';
28
+ childClassName += 'Container';
25
29
  else
26
- childClassName = child.name + 'Resource';
30
+ childClassName += 'Resource';
27
31
  // Create TsFile for child resource
28
32
  const dir = node_path_1.default.dirname(tsFile.filename);
29
33
  const basename = dir === '/'
@@ -37,45 +41,36 @@ export class ${className} extends HttpServiceBase {\n`;
37
41
  * ${(0, string_utils_js_1.wrapJSDocString)(child.description || '')}
38
42
  * @url ${node_path_1.default.posix.join(this.client.serviceUrl, '#resources/' + child.name)}
39
43
  */
40
- get ${child.name}(): ${childClassName} {
41
- if (!this[kContext].resources.${child.name})
42
- this[kContext].resources.${child.name} = new ${childClassName}(this[kClient]);
43
- return this[kContext].resources.${child.name};
44
- }\n`;
44
+ readonly ${child.name}: ${childClassName};\n`;
45
+ constructorBody += ` this.${child.name} = new ${childClassName}(client);\n`;
45
46
  }
46
47
  }
47
48
  else if (resource instanceof common_1.Collection) {
48
49
  tsFile.addImport('@opra/client', ['HttpCollectionNode']);
49
50
  const typeName = resource.type.name || '';
50
51
  tsFile.addImport(`/types/${typeName}`, [typeName], true);
52
+ constructorBody += ` const node = this[kClient].collection('${resource.name}');\n`;
51
53
  for (const [operation, endpoint] of resource.operations.entries()) {
52
54
  tsFile.content += `
53
55
  /**
54
56
  * ${(0, string_utils_js_1.wrapJSDocString)(endpoint.description || '')}
55
57
  */
56
- get ${operation}(): HttpCollectionNode<${typeName}>['${operation}'] {
57
- if (!this[kContext].node)
58
- this[kContext].node = this[kClient].collection('${resource.name}');
59
- return this[kContext].node.${operation};
60
- }
61
- `;
58
+ readonly ${operation}: HttpCollectionNode<${typeName}>['${operation}'];\n`;
59
+ constructorBody += ` this.${operation} = node.${operation}.bind(node);\n`;
62
60
  }
63
61
  }
64
62
  else if (resource instanceof common_1.Singleton) {
65
63
  tsFile.addImport('@opra/client', ['HttpSingletonNode']);
66
64
  const typeName = resource.type.name || '';
67
65
  tsFile.addImport(`/types/${typeName}`, [typeName], true);
66
+ constructorBody += ` const node = this[kClient].singleton('${resource.name}');\n`;
68
67
  for (const [operation, endpoint] of resource.operations.entries()) {
69
68
  tsFile.content += `
70
69
  /**
71
70
  * ${(0, string_utils_js_1.wrapJSDocString)(endpoint.description || '')}
72
71
  */
73
- get ${operation}(): HttpSingletonNode<${typeName}>['${operation}'] {
74
- if (!this[kContext].node)
75
- this[kContext].node = this[kClient].singleton('${resource.name}');
76
- return this[kContext].node.${operation};
77
- }
78
- `;
72
+ readonly ${operation}: HttpSingletonNode<${typeName}>['${operation}'];\n`;
73
+ constructorBody += ` this.${operation} = node.${operation}.bind(node);\n`;
79
74
  }
80
75
  }
81
76
  if (resource.actions.size) {
@@ -101,7 +96,7 @@ export class ${className} extends HttpServiceBase {\n`;
101
96
  `;
102
97
  }
103
98
  }
104
- tsFile.content += `}\n`;
99
+ tsFile.content += constructorBody + ` }\n\n}\n`;
105
100
  return tsFile.content;
106
101
  }
107
102
  exports.processResource = processResource;
@@ -2,7 +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', ['HttpServiceBase', 'kClient', 'kContext']);
5
+ tsFile.addImport('@opra/client', ['kClient', 'kContext', 'OpraHttpClient']);
6
6
  const indexTs = this.addFile('/index.ts', true);
7
7
  indexTs.addExport(tsFile.filename);
8
8
  tsFile.content = `\n
@@ -11,15 +11,19 @@ export async function processResource(resource, className, tsFile) {
11
11
  * @class ${className}
12
12
  * @url ${path.posix.join(this.client.serviceUrl, '#resources/' + className)}
13
13
  */
14
- export class ${className} extends HttpServiceBase {\n`;
14
+ export class ${className} {
15
+ readonly [kClient]: OpraHttpClient;\n`;
16
+ let constructorBody = `
17
+ constructor(client: OpraHttpClient) {
18
+ this[kClient] = client;\n`;
15
19
  if (resource instanceof Container) {
16
20
  for (const child of resource.resources.values()) {
17
21
  // Determine class name of child resource
18
- let childClassName = '';
22
+ let childClassName = child.name.charAt(0).toUpperCase() + child.name.substring(1);
19
23
  if (child instanceof Container)
20
- childClassName = child.name.charAt(0).toUpperCase() + child.name.substring(1) + 'Container';
24
+ childClassName += 'Container';
21
25
  else
22
- childClassName = child.name + 'Resource';
26
+ childClassName += 'Resource';
23
27
  // Create TsFile for child resource
24
28
  const dir = path.dirname(tsFile.filename);
25
29
  const basename = dir === '/'
@@ -33,45 +37,36 @@ export class ${className} extends HttpServiceBase {\n`;
33
37
  * ${wrapJSDocString(child.description || '')}
34
38
  * @url ${path.posix.join(this.client.serviceUrl, '#resources/' + child.name)}
35
39
  */
36
- get ${child.name}(): ${childClassName} {
37
- if (!this[kContext].resources.${child.name})
38
- this[kContext].resources.${child.name} = new ${childClassName}(this[kClient]);
39
- return this[kContext].resources.${child.name};
40
- }\n`;
40
+ readonly ${child.name}: ${childClassName};\n`;
41
+ constructorBody += ` this.${child.name} = new ${childClassName}(client);\n`;
41
42
  }
42
43
  }
43
44
  else if (resource instanceof Collection) {
44
45
  tsFile.addImport('@opra/client', ['HttpCollectionNode']);
45
46
  const typeName = resource.type.name || '';
46
47
  tsFile.addImport(`/types/${typeName}`, [typeName], true);
48
+ constructorBody += ` const node = this[kClient].collection('${resource.name}');\n`;
47
49
  for (const [operation, endpoint] of resource.operations.entries()) {
48
50
  tsFile.content += `
49
51
  /**
50
52
  * ${wrapJSDocString(endpoint.description || '')}
51
53
  */
52
- get ${operation}(): HttpCollectionNode<${typeName}>['${operation}'] {
53
- if (!this[kContext].node)
54
- this[kContext].node = this[kClient].collection('${resource.name}');
55
- return this[kContext].node.${operation};
56
- }
57
- `;
54
+ readonly ${operation}: HttpCollectionNode<${typeName}>['${operation}'];\n`;
55
+ constructorBody += ` this.${operation} = node.${operation}.bind(node);\n`;
58
56
  }
59
57
  }
60
58
  else if (resource instanceof Singleton) {
61
59
  tsFile.addImport('@opra/client', ['HttpSingletonNode']);
62
60
  const typeName = resource.type.name || '';
63
61
  tsFile.addImport(`/types/${typeName}`, [typeName], true);
62
+ constructorBody += ` const node = this[kClient].singleton('${resource.name}');\n`;
64
63
  for (const [operation, endpoint] of resource.operations.entries()) {
65
64
  tsFile.content += `
66
65
  /**
67
66
  * ${wrapJSDocString(endpoint.description || '')}
68
67
  */
69
- get ${operation}(): HttpSingletonNode<${typeName}>['${operation}'] {
70
- if (!this[kContext].node)
71
- this[kContext].node = this[kClient].singleton('${resource.name}');
72
- return this[kContext].node.${operation};
73
- }
74
- `;
68
+ readonly ${operation}: HttpSingletonNode<${typeName}>['${operation}'];\n`;
69
+ constructorBody += ` this.${operation} = node.${operation}.bind(node);\n`;
75
70
  }
76
71
  }
77
72
  if (resource.actions.size) {
@@ -97,6 +92,6 @@ export class ${className} extends HttpServiceBase {\n`;
97
92
  `;
98
93
  }
99
94
  }
100
- tsFile.content += `}\n`;
95
+ tsFile.content += constructorBody + ` }\n\n}\n`;
101
96
  return tsFile.content;
102
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/cli",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
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.29.0",
31
+ "@opra/client": "^0.29.1",
32
32
  "chalk": "^5.3.0",
33
33
  "commander": "^11.0.0",
34
34
  "js-string-escape": "^1.0.1",