@opra/cli 0.31.1 → 0.31.2

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.
@@ -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
- out += forInterface ? `extends ${base} ` : `${base} & `;
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\n\t';
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 += `/**\n${jsDoc} */\n`;
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
- out += `${field.fixed}`;
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\n`;
158
+ `${field.isArray ? '[]' : ''};\n`;
150
159
  }
151
160
  }
152
161
  if (dataType.additionalFields)
@@ -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
- out += forInterface ? `extends ${base} ` : `${base} & `;
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\n\t';
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 += `/**\n${jsDoc} */\n`;
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
- out += `${field.fixed}`;
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\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.1",
3
+ "version": "0.31.2",
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.1",
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",