@opra/cli 0.33.11 → 1.0.0-alpha.7
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.
- package/bin/bin/oprimp.mjs +1 -1
- package/bin/oprimp.mjs +1 -1
- package/cjs/code-block.js +17 -0
- package/cjs/index.js +1 -1
- package/cjs/oprimp-cli.js +9 -9
- package/cjs/ts-generator/http-controller-node.js +21 -0
- package/cjs/{api-exporter → ts-generator}/index.js +1 -1
- package/cjs/ts-generator/processors/clean-directory.js +35 -0
- package/cjs/ts-generator/processors/process-data-types.js +252 -0
- package/cjs/ts-generator/processors/process-document.js +60 -0
- package/cjs/ts-generator/processors/process-http-api.js +45 -0
- package/cjs/ts-generator/processors/process-http-controller.js +189 -0
- package/cjs/ts-generator/ts-file.js +101 -0
- package/cjs/ts-generator/ts-generator.js +108 -0
- package/cjs/ts-generator/utils/locate-named-type.js +16 -0
- package/cjs/{utils → ts-generator/utils}/string-utils.js +17 -16
- package/esm/code-block.js +13 -0
- package/esm/index.js +1 -1
- package/esm/oprimp-cli.js +9 -9
- package/esm/ts-generator/http-controller-node.js +18 -0
- package/esm/ts-generator/index.js +1 -0
- package/esm/ts-generator/processors/clean-directory.js +30 -0
- package/esm/ts-generator/processors/process-data-types.js +241 -0
- package/esm/ts-generator/processors/process-document.js +55 -0
- package/esm/ts-generator/processors/process-http-api.js +40 -0
- package/esm/ts-generator/processors/process-http-controller.js +184 -0
- package/esm/ts-generator/ts-file.js +96 -0
- package/esm/ts-generator/ts-generator.js +103 -0
- package/esm/ts-generator/utils/locate-named-type.js +12 -0
- package/esm/{utils → ts-generator/utils}/string-utils.js +17 -16
- package/package.json +8 -6
- package/types/code-block.d.ts +5 -0
- package/types/{api-exporter/file-writer.d.ts → file-writer.d.ts} +1 -1
- package/types/index.d.ts +1 -1
- package/types/ts-generator/http-controller-node.d.ts +1 -0
- package/types/ts-generator/index.d.ts +1 -0
- package/types/ts-generator/processors/clean-directory.d.ts +2 -0
- package/types/ts-generator/processors/process-data-types.d.ts +30 -0
- package/types/ts-generator/processors/process-document.d.ts +8 -0
- package/types/ts-generator/processors/process-http-api.d.ts +3 -0
- package/types/ts-generator/processors/process-http-controller.d.ts +3 -0
- package/types/{api-exporter → ts-generator}/ts-file.d.ts +4 -4
- package/types/ts-generator/ts-generator.d.ts +70 -0
- package/types/ts-generator/utils/locate-named-type.d.ts +2 -0
- package/cjs/api-exporter/api-exporter.js +0 -115
- package/cjs/api-exporter/process-resources.js +0 -125
- package/cjs/api-exporter/process-types.js +0 -261
- package/cjs/api-exporter/ts-file.js +0 -104
- package/cjs/utils/get-caller-file.util.js +0 -24
- package/esm/api-exporter/api-exporter.js +0 -110
- package/esm/api-exporter/index.js +0 -1
- package/esm/api-exporter/process-resources.js +0 -120
- package/esm/api-exporter/process-types.js +0 -249
- package/esm/api-exporter/ts-file.js +0 -99
- package/esm/utils/get-caller-file.util.js +0 -20
- package/types/api-exporter/api-exporter.d.ts +0 -46
- package/types/api-exporter/index.d.ts +0 -1
- package/types/api-exporter/process-resources.d.ts +0 -4
- package/types/api-exporter/process-types.d.ts +0 -62
- package/types/utils/get-caller-file.util.d.ts +0 -1
- /package/cjs/{api-exporter/file-writer.js → file-writer.js} +0 -0
- /package/esm/{api-exporter/file-writer.js → file-writer.js} +0 -0
- /package/types/{utils → ts-generator/utils}/string-utils.d.ts +0 -0
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { ComplexType, EnumType, MappedType, MixinType, SimpleType } from '@opra/common';
|
|
3
|
-
import { wrapJSDocString } from '../utils/string-utils.js';
|
|
4
|
-
const internalTypeNames = ['any', 'boolean', 'bigint', 'number', 'null', 'string', 'object'];
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export async function processTypes() {
|
|
9
|
-
const { document } = this;
|
|
10
|
-
for (const dataType of document.types.values()) {
|
|
11
|
-
await this.generateTypeFile(dataType);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param dataType
|
|
17
|
-
*/
|
|
18
|
-
export async function generateTypeFile(dataType) {
|
|
19
|
-
const typeName = dataType.name;
|
|
20
|
-
if (typeName === 'any')
|
|
21
|
-
return;
|
|
22
|
-
if (!typeName)
|
|
23
|
-
throw new TypeError(`DataType has no name`);
|
|
24
|
-
const typesTs = this.addFile('/types.ts', true);
|
|
25
|
-
let filePath = '';
|
|
26
|
-
if (dataType instanceof SimpleType)
|
|
27
|
-
filePath = '/simple-types.ts';
|
|
28
|
-
else {
|
|
29
|
-
if (dataType instanceof EnumType)
|
|
30
|
-
filePath = path.join('/enums', typeName + '.ts');
|
|
31
|
-
else
|
|
32
|
-
filePath = path.join('/types', typeName + '.ts');
|
|
33
|
-
}
|
|
34
|
-
const file = this.addFile(filePath, true);
|
|
35
|
-
if (file.exportTypes.includes(typeName))
|
|
36
|
-
return file;
|
|
37
|
-
file.exportTypes.push(typeName);
|
|
38
|
-
const indexTs = this.addFile('/index.ts', true);
|
|
39
|
-
indexTs.addExport(file.filename);
|
|
40
|
-
file.content += `
|
|
41
|
-
/**
|
|
42
|
-
* ${typeName}`;
|
|
43
|
-
if (dataType.description)
|
|
44
|
-
file.content += `
|
|
45
|
-
* ${wrapJSDocString(dataType.description || '')}`;
|
|
46
|
-
file.content += `
|
|
47
|
-
* @url ${path.posix.join(this.client.serviceUrl, '#types/' + typeName)}
|
|
48
|
-
*/
|
|
49
|
-
export `;
|
|
50
|
-
if (dataType instanceof EnumType)
|
|
51
|
-
file.content += await this.generateEnumTypeDefinition({ file, dataType, intent: 'scope' });
|
|
52
|
-
else if (dataType instanceof ComplexType)
|
|
53
|
-
file.content += await this.generateComplexTypeDefinition({ file, dataType, intent: 'scope' });
|
|
54
|
-
else if (dataType instanceof SimpleType)
|
|
55
|
-
file.content += await this.generateSimpleTypeDefinition({ file, dataType, intent: 'scope' });
|
|
56
|
-
else
|
|
57
|
-
throw new TypeError(`${dataType.kind} data type (${typeName}) can not be directly exported`);
|
|
58
|
-
file.content += '\n';
|
|
59
|
-
typesTs.addExport(file.filename);
|
|
60
|
-
return file;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
export async function resolveTypeNameOrDef(args) {
|
|
66
|
-
const { dataType } = args;
|
|
67
|
-
if (dataType.name && !dataType.isEmbedded) {
|
|
68
|
-
if (internalTypeNames.includes(dataType.name))
|
|
69
|
-
return dataType.name;
|
|
70
|
-
const f = await this.generateTypeFile(dataType);
|
|
71
|
-
if (!f)
|
|
72
|
-
return '';
|
|
73
|
-
args.file.addImport(f.filename, [dataType.name], true);
|
|
74
|
-
return dataType.name;
|
|
75
|
-
}
|
|
76
|
-
if (dataType instanceof SimpleType)
|
|
77
|
-
return this.generateSimpleTypeDefinition({ ...args, dataType });
|
|
78
|
-
if (dataType instanceof EnumType)
|
|
79
|
-
return this.generateEnumTypeDefinition({ ...args, dataType });
|
|
80
|
-
if (dataType instanceof MixinType)
|
|
81
|
-
return this.generateMixinTypeDefinition({ ...args, dataType });
|
|
82
|
-
if (dataType instanceof MappedType)
|
|
83
|
-
return this.generateMappedTypeDefinition({ ...args, dataType });
|
|
84
|
-
if (dataType instanceof ComplexType)
|
|
85
|
-
return this.generateComplexTypeDefinition({ ...args, dataType });
|
|
86
|
-
return '';
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
*/
|
|
91
|
-
export async function generateEnumTypeDefinition(args) {
|
|
92
|
-
const { dataType } = args;
|
|
93
|
-
if (args.intent === 'field')
|
|
94
|
-
return '(' +
|
|
95
|
-
Object.keys(dataType.values)
|
|
96
|
-
.map(t => `'${t}'`)
|
|
97
|
-
.join(' | ') +
|
|
98
|
-
')';
|
|
99
|
-
if (args.intent !== 'scope')
|
|
100
|
-
throw new TypeError(`Can't generate EnumType for "${args.intent}" intent`);
|
|
101
|
-
if (!dataType.name)
|
|
102
|
-
throw new TypeError(`Name required to generate EnumType for "${args.intent}" intent`);
|
|
103
|
-
let out = `enum ${dataType.name} {\n\t`;
|
|
104
|
-
for (const [value, info] of Object.entries(dataType.values)) {
|
|
105
|
-
// Print JSDoc
|
|
106
|
-
let jsDoc = '';
|
|
107
|
-
if (dataType.values[value].description)
|
|
108
|
-
jsDoc += ` * ${dataType.values[value].description}\n`;
|
|
109
|
-
if (jsDoc)
|
|
110
|
-
out += `/**\n${jsDoc} */\n`;
|
|
111
|
-
out += `${info.key || value} = ` +
|
|
112
|
-
(typeof value === 'number' ? value : ('\'' + (String(value)).replace('\'', '\\\'')) + '\'');
|
|
113
|
-
out += ',\n\n';
|
|
114
|
-
}
|
|
115
|
-
return out + '\b}';
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
*
|
|
119
|
-
*/
|
|
120
|
-
export async function generateComplexTypeDefinition(args) {
|
|
121
|
-
const { intent, dataType } = args;
|
|
122
|
-
if (intent === 'scope' && !dataType.name)
|
|
123
|
-
throw new TypeError(`Name required to generate ComplexType for "${args.intent}" intent`);
|
|
124
|
-
let out = intent === 'scope' ? `interface ${dataType.name} ` : '';
|
|
125
|
-
if (dataType.base) {
|
|
126
|
-
const base = await this.resolveTypeNameOrDef({ file: args.file, dataType: dataType.base, intent: 'extends' });
|
|
127
|
-
const omitFields = [...dataType.own.fields.keys()]
|
|
128
|
-
.filter(k => dataType.base?.fields.has(k));
|
|
129
|
-
const baseDef = omitFields.length
|
|
130
|
-
? `Omit<${base}, ${omitFields.map(x => "'" + x + "'").join(' | ')}>`
|
|
131
|
-
: `${base}`;
|
|
132
|
-
if (intent === 'scope')
|
|
133
|
-
out += `extends ${baseDef} `;
|
|
134
|
-
else {
|
|
135
|
-
out += baseDef;
|
|
136
|
-
if (!dataType.own.fields.size)
|
|
137
|
-
return out;
|
|
138
|
-
out += ' & ';
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
out += '{\n\t';
|
|
142
|
-
let i = 0;
|
|
143
|
-
for (const field of dataType.own.fields.values()) {
|
|
144
|
-
if (i++)
|
|
145
|
-
out += '\n';
|
|
146
|
-
// Print JSDoc
|
|
147
|
-
out += `/**\n * ${field.description || ''}\n`;
|
|
148
|
-
if (field.default)
|
|
149
|
-
out += ` * @default ` + field.default + '\n';
|
|
150
|
-
// if (field.format)
|
|
151
|
-
// jsDoc += ` * @format ` + field.format + '\n';
|
|
152
|
-
if (field.exclusive)
|
|
153
|
-
out += ` * @exclusive\n`;
|
|
154
|
-
if (field.readonly)
|
|
155
|
-
out += ` * @readonly\n`;
|
|
156
|
-
if (field.writeonly)
|
|
157
|
-
out += ` * @writeonly\n`;
|
|
158
|
-
if (field.deprecated)
|
|
159
|
-
out += ` * @deprecated ` + (typeof field.deprecated === 'string' ? field.deprecated : '') + '\n';
|
|
160
|
-
out += ' */\n';
|
|
161
|
-
// Print field name
|
|
162
|
-
if (field.readonly)
|
|
163
|
-
out += 'readonly ';
|
|
164
|
-
out += `${field.name}${field.required ? '' : '?'}: `;
|
|
165
|
-
if (field.fixed) {
|
|
166
|
-
const t = typeof field.fixed;
|
|
167
|
-
out += `${t === 'number' || t === 'boolean' || t === 'bigint' ? field.fixed : "'" + field.fixed + "'"}\n`;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
out += await this.resolveTypeNameOrDef({ file: args.file, dataType: field.type, intent: 'field' }) +
|
|
171
|
-
`${field.isArray ? '[]' : ''};\n`;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (dataType.additionalFields)
|
|
175
|
-
out += '[key: string]: any;\n';
|
|
176
|
-
return out + '\b}';
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
*
|
|
180
|
-
*/
|
|
181
|
-
export async function generateSimpleTypeDefinition(args) {
|
|
182
|
-
const { intent, dataType } = args;
|
|
183
|
-
if (intent === 'scope' && !dataType.name)
|
|
184
|
-
throw new TypeError(`Name required to generate SimpleType for "${args.intent}" intent`);
|
|
185
|
-
let out = intent === 'scope' ? `type ${dataType.name} = ` : '';
|
|
186
|
-
if (dataType.extendsFrom('boolean'))
|
|
187
|
-
out += 'boolean';
|
|
188
|
-
else if (dataType.extendsFrom('string'))
|
|
189
|
-
out += 'string';
|
|
190
|
-
else if (dataType.extendsFrom('number') || dataType.extendsFrom('integer'))
|
|
191
|
-
out += 'number';
|
|
192
|
-
else if (dataType.extendsFrom('date') || dataType.extendsFrom('datetime'))
|
|
193
|
-
out += 'Date';
|
|
194
|
-
else if (dataType.extendsFrom('approxdate') || dataType.extendsFrom('approxdatetime'))
|
|
195
|
-
out += 'string';
|
|
196
|
-
else if (dataType.extendsFrom('bigint'))
|
|
197
|
-
out += 'bigint';
|
|
198
|
-
else if (dataType.extendsFrom('object'))
|
|
199
|
-
out += 'object';
|
|
200
|
-
else
|
|
201
|
-
out += 'any';
|
|
202
|
-
return intent === 'scope' ? out + ';' : out;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
*/
|
|
207
|
-
export async function generateMixinTypeDefinition(args) {
|
|
208
|
-
const { file, dataType, intent } = args;
|
|
209
|
-
return (await Promise.all(dataType.types
|
|
210
|
-
.map(t => this.resolveTypeNameOrDef({ file, dataType: t, intent })))).map(t => t.includes('|') ? '(' + t + ')' : t)
|
|
211
|
-
.join(intent === 'extends' ? ', ' : ' & ');
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
export async function generateMappedTypeDefinition(args) {
|
|
217
|
-
const { dataType } = args;
|
|
218
|
-
const typeDef = await this.resolveTypeNameOrDef({ ...args, dataType: dataType.base });
|
|
219
|
-
const pick = dataType.pick?.length ? dataType.pick : undefined;
|
|
220
|
-
const omit = !pick && dataType.omit?.length ? dataType.omit : undefined;
|
|
221
|
-
const partial = dataType.partial === true || Array.isArray(dataType.partial) && dataType.partial.length > 0
|
|
222
|
-
? dataType.partial
|
|
223
|
-
: undefined;
|
|
224
|
-
if (!(pick || omit || partial))
|
|
225
|
-
return typeDef;
|
|
226
|
-
let out = '';
|
|
227
|
-
if (partial)
|
|
228
|
-
out += 'Partial<';
|
|
229
|
-
if (pick)
|
|
230
|
-
out += 'Pick<';
|
|
231
|
-
else if (omit)
|
|
232
|
-
out += 'Omit<';
|
|
233
|
-
out += typeDef;
|
|
234
|
-
if (omit || pick)
|
|
235
|
-
out += ', ' + (omit || pick)
|
|
236
|
-
.filter(x => !!x)
|
|
237
|
-
.map(x => `'${x}'`)
|
|
238
|
-
.join(' | ') +
|
|
239
|
-
'>';
|
|
240
|
-
if (partial) {
|
|
241
|
-
if (Array.isArray(partial))
|
|
242
|
-
out += ', ' + partial
|
|
243
|
-
.filter(x => !!x)
|
|
244
|
-
.map(x => `'${x}'`)
|
|
245
|
-
.join(' | ');
|
|
246
|
-
out += '>';
|
|
247
|
-
}
|
|
248
|
-
return out;
|
|
249
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import flattenText from 'putil-flattentext';
|
|
3
|
-
export class TsFile {
|
|
4
|
-
constructor(filename) {
|
|
5
|
-
this.filename = filename;
|
|
6
|
-
this.imports = {};
|
|
7
|
-
this.exportFiles = {};
|
|
8
|
-
this.exportTypes = [];
|
|
9
|
-
this.header = '';
|
|
10
|
-
this.content = '';
|
|
11
|
-
this.addImport = (filename, items, typeImport) => {
|
|
12
|
-
if (isLocalFile(filename)) {
|
|
13
|
-
filename = path.relative(this.dirname, path.resolve(this.dirname, filename));
|
|
14
|
-
if (!filename.startsWith('.'))
|
|
15
|
-
filename = './' + filename;
|
|
16
|
-
}
|
|
17
|
-
if (filename.endsWith('.d.ts'))
|
|
18
|
-
filename = filename.substring(0, filename.length - 5);
|
|
19
|
-
if (filename.endsWith('.ts') || filename.endsWith('.js'))
|
|
20
|
-
filename = filename.substring(0, filename.length - 3);
|
|
21
|
-
const imp = (this.imports[filename] = this.imports[filename] || { items: [], typeImport });
|
|
22
|
-
if (!typeImport)
|
|
23
|
-
imp.typeImport = false;
|
|
24
|
-
items?.forEach(x => {
|
|
25
|
-
if (!imp.items.includes(x))
|
|
26
|
-
imp.items.push(x);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
this.addExport = (filename, types) => {
|
|
30
|
-
if (isLocalFile(filename)) {
|
|
31
|
-
filename = path.relative(this.dirname, path.resolve(this.dirname, filename));
|
|
32
|
-
if (!filename.startsWith('.'))
|
|
33
|
-
filename = './' + filename;
|
|
34
|
-
}
|
|
35
|
-
if (filename.endsWith('.d.ts'))
|
|
36
|
-
filename = filename.substring(0, filename.length - 5);
|
|
37
|
-
if (filename.endsWith('.ts') || filename.endsWith('.js'))
|
|
38
|
-
filename = filename.substring(0, filename.length - 3);
|
|
39
|
-
this.exportFiles[filename] = this.exportFiles[filename] || [];
|
|
40
|
-
types?.forEach(x => {
|
|
41
|
-
if (!this.exportFiles[filename].includes(x))
|
|
42
|
-
this.exportFiles[filename].push(x);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
this.dirname = path.dirname(filename);
|
|
46
|
-
}
|
|
47
|
-
generate(options) {
|
|
48
|
-
let output = '/* #!oprimp_auto_generated!# !! Do NOT remove this line */\n' +
|
|
49
|
-
(this.header ? flattenText(this.header) + '\n\n' : '\n');
|
|
50
|
-
const importStr = Object.keys(this.imports)
|
|
51
|
-
.sort((a, b) => {
|
|
52
|
-
if (a.startsWith('@'))
|
|
53
|
-
return -1;
|
|
54
|
-
if (b.startsWith('@'))
|
|
55
|
-
return 1;
|
|
56
|
-
if (!a.startsWith('.'))
|
|
57
|
-
return -1;
|
|
58
|
-
if (!b.startsWith('.'))
|
|
59
|
-
return 1;
|
|
60
|
-
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
61
|
-
})
|
|
62
|
-
.map(filename => {
|
|
63
|
-
const imp = this.imports[filename];
|
|
64
|
-
let relFile = filename;
|
|
65
|
-
if (!isPackageName(filename)) {
|
|
66
|
-
if (options?.importExt)
|
|
67
|
-
relFile += '.js';
|
|
68
|
-
}
|
|
69
|
-
return `import${imp.typeImport ? ' type' : ''} ${imp.items.length ? '{ ' + imp.items.join(', ') + ' } from ' : ''}'${relFile}';`;
|
|
70
|
-
})
|
|
71
|
-
.join('\n');
|
|
72
|
-
if (importStr)
|
|
73
|
-
output += flattenText(importStr) + '\n';
|
|
74
|
-
output += flattenText(this.content);
|
|
75
|
-
const exportStr = Object.keys(this.exportFiles)
|
|
76
|
-
.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()))
|
|
77
|
-
.map(filename => {
|
|
78
|
-
const types = this.exportFiles[filename];
|
|
79
|
-
let relFile = filename;
|
|
80
|
-
if (!isPackageName(filename)) {
|
|
81
|
-
if (options?.importExt)
|
|
82
|
-
relFile += '.js';
|
|
83
|
-
}
|
|
84
|
-
return `export ${types.length ? '{ ' + types.join(', ') + ' }' : '*'} from '${relFile}';`;
|
|
85
|
-
})
|
|
86
|
-
.join('\n');
|
|
87
|
-
if (exportStr)
|
|
88
|
-
output += flattenText(exportStr) + '\n';
|
|
89
|
-
return output;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function isLocalFile(s) {
|
|
93
|
-
return typeof s === 'string' &&
|
|
94
|
-
(s.startsWith('.') || s.startsWith('/'));
|
|
95
|
-
}
|
|
96
|
-
const PACKAGENAME_PATTERN = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
97
|
-
function isPackageName(s) {
|
|
98
|
-
return PACKAGENAME_PATTERN.test(s);
|
|
99
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const PATH_PATTERN = /^(?:file:\/\/)?(.+)$/;
|
|
2
|
-
export function getCallerFile(position = 1) {
|
|
3
|
-
if (position >= Error.stackTraceLimit) {
|
|
4
|
-
throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' +
|
|
5
|
-
position + '` and Error.stackTraceLimit was: `' + Error.stackTraceLimit + '`');
|
|
6
|
-
}
|
|
7
|
-
const oldPrepareStackTrace = Error.prepareStackTrace;
|
|
8
|
-
Error.prepareStackTrace = (_, stack) => stack;
|
|
9
|
-
const stack = new Error().stack;
|
|
10
|
-
Error.prepareStackTrace = oldPrepareStackTrace;
|
|
11
|
-
if (stack !== null && typeof stack === 'object') {
|
|
12
|
-
// stack[0] holds this file
|
|
13
|
-
// stack[1] holds where this function was called
|
|
14
|
-
const s = stack[position] ?
|
|
15
|
-
stack[position].getFileName() : undefined;
|
|
16
|
-
const m = s ? PATH_PATTERN.exec(s) : undefined;
|
|
17
|
-
return m ? m[1] : '';
|
|
18
|
-
}
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { OpraHttpClient } from '@opra/client';
|
|
2
|
-
import { ApiDocument } from '@opra/common';
|
|
3
|
-
import { IFileWriter } from '../interfaces/file-writer.interface.js';
|
|
4
|
-
import { ILogger } from '../interfaces/logger.interface.js';
|
|
5
|
-
import { processResource } from './process-resources.js';
|
|
6
|
-
import { generateComplexTypeDefinition, generateEnumTypeDefinition, generateMappedTypeDefinition, generateMixinTypeDefinition, generateSimpleTypeDefinition, generateTypeFile, processTypes, resolveTypeNameOrDef } from './process-types.js';
|
|
7
|
-
import { TsFile } from './ts-file.js';
|
|
8
|
-
export declare namespace ApiExporter {
|
|
9
|
-
interface Config {
|
|
10
|
-
serviceUrl: string;
|
|
11
|
-
outDir: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
cwd?: string;
|
|
14
|
-
logger?: ILogger;
|
|
15
|
-
writer?: IFileWriter;
|
|
16
|
-
fileHeader?: string;
|
|
17
|
-
importExt?: boolean;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export declare class ApiExporter {
|
|
21
|
-
protected client: OpraHttpClient;
|
|
22
|
-
protected document: ApiDocument;
|
|
23
|
-
protected logger: ILogger;
|
|
24
|
-
protected outDir: string;
|
|
25
|
-
protected cwd: string;
|
|
26
|
-
protected serviceClassName?: string;
|
|
27
|
-
protected fileHeader: string;
|
|
28
|
-
protected writer: IFileWriter;
|
|
29
|
-
protected files: Record<string, TsFile>;
|
|
30
|
-
protected importExt?: boolean;
|
|
31
|
-
protected processResource: typeof processResource;
|
|
32
|
-
protected processTypes: typeof processTypes;
|
|
33
|
-
protected generateTypeFile: typeof generateTypeFile;
|
|
34
|
-
protected generateComplexTypeDefinition: typeof generateComplexTypeDefinition;
|
|
35
|
-
protected generateSimpleTypeDefinition: typeof generateSimpleTypeDefinition;
|
|
36
|
-
protected resolveTypeNameOrDef: typeof resolveTypeNameOrDef;
|
|
37
|
-
protected generateEnumTypeDefinition: typeof generateEnumTypeDefinition;
|
|
38
|
-
protected generateMixinTypeDefinition: typeof generateMixinTypeDefinition;
|
|
39
|
-
protected generateMappedTypeDefinition: typeof generateMappedTypeDefinition;
|
|
40
|
-
protected constructor(config: ApiExporter.Config);
|
|
41
|
-
protected execute(): Promise<void>;
|
|
42
|
-
protected getFile(filePath: string): TsFile;
|
|
43
|
-
protected addFile(filePath: string, returnExists?: boolean): TsFile;
|
|
44
|
-
protected cleanDirectory(dirname: string): void;
|
|
45
|
-
static execute(config: ApiExporter.Config): Promise<void>;
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './api-exporter.js';
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { ComplexType, DataType, EnumType, MappedType, MixinType, SimpleType } from '@opra/common';
|
|
2
|
-
import type { ApiExporter } from './api-exporter.js';
|
|
3
|
-
import { TsFile } from './ts-file.js';
|
|
4
|
-
type Intent = 'scope' | 'extends' | 'field';
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export declare function processTypes(this: ApiExporter): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param dataType
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateTypeFile(this: ApiExporter, dataType: DataType): Promise<TsFile | undefined>;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolveTypeNameOrDef(this: ApiExporter, args: {
|
|
18
|
-
file: TsFile;
|
|
19
|
-
dataType: DataType;
|
|
20
|
-
intent: Intent;
|
|
21
|
-
}): Promise<string>;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
export declare function generateEnumTypeDefinition(this: ApiExporter, args: {
|
|
26
|
-
file: TsFile;
|
|
27
|
-
dataType: EnumType;
|
|
28
|
-
intent: Intent;
|
|
29
|
-
}): Promise<string>;
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
export declare function generateComplexTypeDefinition(this: ApiExporter, args: {
|
|
34
|
-
file: TsFile;
|
|
35
|
-
dataType: ComplexType;
|
|
36
|
-
intent: Intent;
|
|
37
|
-
}): Promise<string>;
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
export declare function generateSimpleTypeDefinition(this: ApiExporter, args: {
|
|
42
|
-
file: TsFile;
|
|
43
|
-
dataType: SimpleType;
|
|
44
|
-
intent: Intent;
|
|
45
|
-
}): Promise<string>;
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
export declare function generateMixinTypeDefinition(this: ApiExporter, args: {
|
|
50
|
-
file: TsFile;
|
|
51
|
-
dataType: MixinType;
|
|
52
|
-
intent: Intent;
|
|
53
|
-
}): Promise<string>;
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
export declare function generateMappedTypeDefinition(this: ApiExporter, args: {
|
|
58
|
-
file: TsFile;
|
|
59
|
-
dataType: MappedType;
|
|
60
|
-
intent: Intent;
|
|
61
|
-
}): Promise<string>;
|
|
62
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCallerFile(position?: number): string;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|