@looker/sdk-codegen 21.7.4 → 21.8.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.
- package/CHANGELOG.md +20 -0
- package/lib/codeGen.d.ts +1 -1
- package/lib/codeGen.js +28 -154
- package/lib/codeGen.js.map +1 -1
- package/lib/codeGenerators.js +0 -16
- package/lib/codeGenerators.js.map +1 -1
- package/lib/csharp.gen.js +3 -71
- package/lib/csharp.gen.js.map +1 -1
- package/lib/declarationInfo.js +0 -7
- package/lib/declarationInfo.js.map +1 -1
- package/lib/esm/codeGen.js +48 -157
- package/lib/esm/codeGen.js.map +1 -1
- package/lib/esm/codeGenerators.js +28 -20
- package/lib/esm/codeGenerators.js.map +1 -1
- package/lib/esm/csharp.gen.js +19 -75
- package/lib/esm/csharp.gen.js.map +1 -1
- package/lib/esm/declarationInfo.js +10 -7
- package/lib/esm/declarationInfo.js.map +1 -1
- package/lib/esm/exampleInfo.js +24 -23
- package/lib/esm/exampleInfo.js.map +1 -1
- package/lib/esm/go.gen.js +18 -92
- package/lib/esm/go.gen.js.map +1 -1
- package/lib/esm/index.js +148 -13
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/kotlin.gen.js +23 -118
- package/lib/esm/kotlin.gen.js.map +1 -1
- package/lib/esm/pseudo.gen.js +14 -24
- package/lib/esm/pseudo.gen.js.map +1 -1
- package/lib/esm/python.gen.js +19 -138
- package/lib/esm/python.gen.js.map +1 -1
- package/lib/esm/sdkModels.js +103 -435
- package/lib/esm/sdkModels.js.map +1 -1
- package/lib/esm/specConverter.js +58 -88
- package/lib/esm/specConverter.js.map +1 -1
- package/lib/esm/specDiff.js +39 -54
- package/lib/esm/specDiff.js.map +1 -1
- package/lib/esm/swift.gen.js +25 -137
- package/lib/esm/swift.gen.js.map +1 -1
- package/lib/esm/testUtils/index.js +17 -0
- package/lib/esm/testUtils/index.js.map +1 -0
- package/lib/esm/testUtils/testUtils.js +66 -0
- package/lib/esm/testUtils/testUtils.js.map +1 -0
- package/lib/esm/typescript.gen.js +24 -125
- package/lib/esm/typescript.gen.js.map +1 -1
- package/lib/exampleInfo.js +1 -31
- package/lib/exampleInfo.js.map +1 -1
- package/lib/go.gen.js +3 -87
- package/lib/go.gen.js.map +1 -1
- package/lib/index.js +0 -26
- package/lib/index.js.map +1 -1
- package/lib/kotlin.gen.js +7 -113
- package/lib/kotlin.gen.js.map +1 -1
- package/lib/pseudo.gen.js +3 -24
- package/lib/pseudo.gen.js.map +1 -1
- package/lib/python.gen.js +3 -133
- package/lib/python.gen.js.map +1 -1
- package/lib/sdkModels.js +20 -450
- package/lib/sdkModels.js.map +1 -1
- package/lib/specConverter.js +6 -106
- package/lib/specConverter.js.map +1 -1
- package/lib/specDiff.js +4 -59
- package/lib/specDiff.js.map +1 -1
- package/lib/swift.gen.js +3 -128
- package/lib/swift.gen.js.map +1 -1
- package/lib/testUtils/index.js +0 -2
- package/lib/testUtils/index.js.map +1 -1
- package/lib/testUtils/testUtils.js +1 -17
- package/lib/testUtils/testUtils.js.map +1 -1
- package/lib/typescript.gen.js +5 -117
- package/lib/typescript.gen.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,198 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TypescriptGen = void 0;
|
|
7
|
+
var _sdkModels = require("./sdkModels");
|
|
8
|
+
var _codeGen = require("./codeGen");
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
class TypescriptGen extends _codeGen.CodeGen {
|
|
10
15
|
constructor() {
|
|
11
16
|
super(...arguments);
|
|
12
|
-
|
|
13
17
|
_defineProperty(this, "codePath", './packages/');
|
|
14
|
-
|
|
15
18
|
_defineProperty(this, "useFunctions", true);
|
|
16
|
-
|
|
17
19
|
_defineProperty(this, "useInterfaces", true);
|
|
18
|
-
|
|
19
20
|
_defineProperty(this, "packagePath", 'sdk/src');
|
|
20
|
-
|
|
21
21
|
_defineProperty(this, "itself", 'this');
|
|
22
|
-
|
|
23
22
|
_defineProperty(this, "fileExtension", '.ts');
|
|
24
|
-
|
|
25
23
|
_defineProperty(this, "commentStr", '// ');
|
|
26
|
-
|
|
27
24
|
_defineProperty(this, "nullStr", 'null');
|
|
28
|
-
|
|
29
25
|
_defineProperty(this, "transport", 'transport');
|
|
30
|
-
|
|
31
26
|
_defineProperty(this, "argDelimiter", ', ');
|
|
32
|
-
|
|
33
27
|
_defineProperty(this, "paramDelimiter", ',\n');
|
|
34
|
-
|
|
35
28
|
_defineProperty(this, "propDelimiter", '\n');
|
|
36
|
-
|
|
37
29
|
_defineProperty(this, "indentStr", ' ');
|
|
38
|
-
|
|
39
30
|
_defineProperty(this, "endTypeStr", '\n}');
|
|
40
|
-
|
|
41
31
|
_defineProperty(this, "willItStream", true);
|
|
42
|
-
|
|
43
32
|
_defineProperty(this, "useNamedParameters", false);
|
|
44
|
-
|
|
45
33
|
_defineProperty(this, "useNamedArguments", false);
|
|
46
|
-
|
|
47
34
|
_defineProperty(this, "rtlNeeds", new Set());
|
|
48
35
|
}
|
|
49
|
-
|
|
50
36
|
reset() {
|
|
51
37
|
this.rtlNeeds = new Set();
|
|
52
38
|
}
|
|
53
|
-
|
|
54
39
|
sdkFileName(baseFileName) {
|
|
55
40
|
var _this$versions;
|
|
56
|
-
|
|
57
41
|
return this.fileName("".concat((_this$versions = this.versions) === null || _this$versions === void 0 ? void 0 : _this$versions.spec.key, "/").concat(baseFileName));
|
|
58
42
|
}
|
|
59
|
-
|
|
60
43
|
rtlImports() {
|
|
61
44
|
var rtl = Array.from(this.rtlNeeds).join(', ');
|
|
62
|
-
|
|
63
45
|
if (rtl) {
|
|
64
46
|
rtl += ', ';
|
|
65
47
|
}
|
|
66
|
-
|
|
67
48
|
return rtl;
|
|
68
49
|
}
|
|
69
|
-
|
|
70
50
|
rtlImportStatement() {
|
|
71
51
|
var rtl = this.rtlImports();
|
|
72
52
|
return rtl ? "\nimport type { ".concat(rtl, " } from '@looker/sdk-rtl'\n") : '';
|
|
73
53
|
}
|
|
74
|
-
|
|
75
54
|
methodsPrologue(_indent) {
|
|
76
55
|
return "\nimport type { ".concat(this.rtlImports(), "IAuthSession, ITransportSettings, SDKResponse } from '@looker/sdk-rtl'\nimport { APIMethods, encodeParam } from '@looker/sdk-rtl'\n/**\n * ").concat(this.warnEditing(), "\n *\n */\nimport { sdkVersion } from '../constants'\nimport type { I").concat(this.packageName, " } from './methodsInterface'\nimport type { ").concat(this.typeNames().join(', '), " } from './models'\n\nexport class ").concat(this.packageName, " extends APIMethods implements I").concat(this.packageName, " {\n static readonly ApiVersion = '").concat(this.apiVersion, "'\n constructor(authSession: IAuthSession) {\n super(authSession, sdkVersion)\n this.apiVersion = ").concat(this.packageName, ".ApiVersion\n this.apiPath =\n authSession.settings.base_url === ''\n ? ''\n : authSession.settings.base_url + '/api/' + this.apiVersion\n }\n\n");
|
|
77
56
|
}
|
|
78
|
-
|
|
79
57
|
functionsPrologue(_indent) {
|
|
80
58
|
return "\nimport type { ".concat(this.rtlImports(), "IAPIMethods, IAuthSession, ITransportSettings, SDKResponse } from '@looker/sdk-rtl'\nimport { encodeParam, functionalSdk } from '@looker/sdk-rtl'\n\n/**\n * ").concat(this.warnEditing(), "\n *\n */\n\nimport { sdkVersion } from '../constants'\nimport type { ").concat(this.typeNames().join(', '), " } from './models'\n\n/**\n * Creates a \"functional sdk\" that knows the API and Looker release version\n * @param authSession authentication session\n */\nexport const functionalSdk").concat(this.apiRef, " = (\n authSession: IAuthSession,\n) => {\n return functionalSdk(authSession, '").concat(this.apiVersion, "', sdkVersion)\n}\n\n");
|
|
81
59
|
}
|
|
82
|
-
|
|
83
60
|
interfacesPrologue(_indent) {
|
|
84
61
|
return "\nimport type { ".concat(this.rtlImports(), " IAPIMethods, ITransportSettings, SDKResponse } from '@looker/sdk-rtl'\n/**\n * ").concat(this.warnEditing(), "\n *\n */\nimport type { ").concat(this.typeNames().join(', '), " } from './models'\n\nexport interface I").concat(this.packageName, " extends IAPIMethods {\n\n");
|
|
85
62
|
}
|
|
86
|
-
|
|
87
63
|
streamsPrologue(_indent) {
|
|
88
64
|
return "\nimport type { Readable } from 'readable-stream'\nimport type { ".concat(this.rtlImports(), "IAuthSession, ITransportSettings } from '@looker/sdk-rtl'\nimport { APIMethods, encodeParam } from '@looker/sdk-rtl'\n\n/**\n * ").concat(this.warnEditing(), "\n *\n */\nimport { sdkVersion } from '../constants'\nimport type { ").concat(this.typeNames().join(', '), " } from './models'\n\nexport class ").concat(this.packageName, "Stream extends APIMethods {\n static readonly ApiVersion = '").concat(this.apiVersion, "'\n constructor(authSession: IAuthSession) {\n super(authSession, sdkVersion)\n this.apiVersion = ").concat(this.packageName, "Stream.ApiVersion\n this.apiPath =\n authSession.settings.base_url === ''\n ? ''\n : authSession.settings.base_url + '/api/' + this.apiVersion\n }\n");
|
|
89
65
|
}
|
|
90
|
-
|
|
91
66
|
methodsEpilogue(_indent) {
|
|
92
67
|
return '\n}';
|
|
93
68
|
}
|
|
94
|
-
|
|
95
69
|
modelsPrologue(_indent) {
|
|
96
70
|
return "".concat(this.rtlImportStatement(), "\n/*\n * ").concat(this.warnEditing(), "\n */\n\n");
|
|
97
71
|
}
|
|
98
|
-
|
|
99
72
|
modelsEpilogue(_indent) {
|
|
100
73
|
return '';
|
|
101
74
|
}
|
|
102
|
-
|
|
103
75
|
commentHeader(indent, text) {
|
|
104
76
|
var commentStr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' * ';
|
|
105
77
|
if (this.noComment || !text) return '';
|
|
106
78
|
var commentPrefix = text.includes(' License') && text.includes('Copyright (c)') ? '/*' : '/**';
|
|
107
|
-
|
|
108
79
|
if (commentStr === ' ') {
|
|
109
|
-
return "".concat(indent).concat(commentPrefix, "\n\n").concat(commentBlock(text, indent, commentStr), "\n").concat(indent, " */\n");
|
|
80
|
+
return "".concat(indent).concat(commentPrefix, "\n\n").concat((0, _codeGen.commentBlock)(text, indent, commentStr), "\n").concat(indent, " */\n");
|
|
110
81
|
}
|
|
111
|
-
|
|
112
|
-
return "".concat(indent).concat(commentPrefix, "\n").concat(commentBlock(text, indent, commentStr), "\n").concat(indent, " */\n");
|
|
82
|
+
return "".concat(indent).concat(commentPrefix, "\n").concat((0, _codeGen.commentBlock)(text, indent, commentStr), "\n").concat(indent, " */\n");
|
|
113
83
|
}
|
|
114
|
-
|
|
115
84
|
beginRegion(indent, description) {
|
|
116
85
|
return "".concat(indent, "//#region ").concat(description);
|
|
117
86
|
}
|
|
118
|
-
|
|
119
87
|
endRegion(indent, description) {
|
|
120
88
|
return "".concat(indent, "//#endregion ").concat(description);
|
|
121
89
|
}
|
|
122
|
-
|
|
123
90
|
declareProperty(indent, property) {
|
|
124
91
|
var optional = !property.required ? '?' : '';
|
|
125
92
|
var nullify = property.nullable ? ' | null' : '';
|
|
126
|
-
|
|
127
|
-
if (property.name === strBody) {
|
|
93
|
+
if (property.name === _sdkModels.strBody) {
|
|
128
94
|
property.type.refCount++;
|
|
129
95
|
return this.commentHeader(indent, property.description || 'body parameter for dynamically created request type') + "".concat(indent).concat(property.name).concat(optional, ": ").concat(this.typeName(property.type)).concat(nullify);
|
|
130
96
|
}
|
|
131
|
-
|
|
132
97
|
var mapped = this.typeMap(property.type);
|
|
133
98
|
return this.commentHeader(indent, this.describeProperty(property)) + "".concat(indent).concat(this.reserve(property.name)).concat(optional, ": ").concat(mapped.name).concat(nullify);
|
|
134
99
|
}
|
|
135
|
-
|
|
136
100
|
impartial(param, mapped) {
|
|
137
|
-
if (param.type.intrinsic || param.location !== strBody) return mapped.name;
|
|
101
|
+
if (param.type.intrinsic || param.location !== _sdkModels.strBody) return mapped.name;
|
|
138
102
|
return "Partial<".concat(mapped.name, ">");
|
|
139
103
|
}
|
|
140
|
-
|
|
141
104
|
paramComment(param, mapped) {
|
|
142
105
|
var desc = param.description || param.type.description;
|
|
143
|
-
|
|
144
106
|
if (!desc) {
|
|
145
107
|
desc = this.impartial(param, mapped);
|
|
146
108
|
}
|
|
147
|
-
|
|
148
|
-
return "@param ".concat(param.name, " ").concat(describeParam(_objectSpread(_objectSpread({}, param), {
|
|
109
|
+
return "@param ".concat(param.name, " ").concat((0, _sdkModels.describeParam)(_objectSpread(_objectSpread({}, param), {
|
|
149
110
|
description: desc
|
|
150
111
|
})));
|
|
151
112
|
}
|
|
152
|
-
|
|
153
113
|
declareParameter(indent, method, param) {
|
|
154
|
-
var type = param.location === strBody ? this.writeableType(param.type, method) || param.type : param.type;
|
|
114
|
+
var type = param.location === _sdkModels.strBody ? this.writeableType(param.type, method) || param.type : param.type;
|
|
155
115
|
var mapped = this.typeMap(type);
|
|
156
116
|
var pOpt = '';
|
|
157
117
|
mapped.name = this.impartial(param, mapped);
|
|
158
|
-
|
|
159
118
|
if (!param.required) {
|
|
160
119
|
pOpt = mapped.default ? '' : '?';
|
|
161
120
|
}
|
|
162
|
-
|
|
163
121
|
return "".concat(indent).concat(this.reserve(param.name)).concat(pOpt, ": ").concat(mapped.name) + (param.required ? '' : mapped.default ? " = ".concat(mapped.default) : '');
|
|
164
122
|
}
|
|
165
|
-
|
|
166
123
|
makeTheCall(method, inputs) {
|
|
167
|
-
inputs = trimInputs(inputs);
|
|
168
124
|
var args = this.assignParams(method, inputs);
|
|
169
125
|
var fun = "// functional SDK syntax is recommended for minimizing browser payloads\nlet response = await sdk.ok(".concat(method.name, "(sdk").concat(args ? ',' : '');
|
|
170
126
|
var mono = "// monolithic SDK syntax can also be used for Node apps\nlet response = await sdk.ok(sdk.".concat(method.name, "(");
|
|
171
127
|
return "".concat(fun).concat(args, "))\n").concat(mono).concat(args, "))");
|
|
172
128
|
}
|
|
173
|
-
|
|
174
129
|
methodHeaderComment(method) {
|
|
175
130
|
var _method$description;
|
|
176
|
-
|
|
177
131
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
178
132
|
if (this.noComment) return '';
|
|
179
133
|
var lines = [];
|
|
180
134
|
var desc = (_method$description = method.description) === null || _method$description === void 0 ? void 0 : _method$description.trim();
|
|
181
|
-
|
|
182
135
|
if (desc) {
|
|
183
136
|
lines.push(desc);
|
|
184
137
|
lines.push('');
|
|
185
138
|
}
|
|
186
|
-
|
|
187
139
|
var resultType = this.typeMap(method.type).name;
|
|
188
140
|
lines.push("".concat(method.httpMethod, " ").concat(method.endpoint, " -> ").concat(resultType));
|
|
189
141
|
lines.push('');
|
|
190
|
-
|
|
191
142
|
if (method.deprecated) {
|
|
192
143
|
lines.push('@deprecated');
|
|
193
144
|
lines.push('');
|
|
194
145
|
}
|
|
195
|
-
|
|
196
146
|
if (method.responseIsBoth()) {
|
|
197
147
|
lines.push('@remarks');
|
|
198
148
|
lines.push('**NOTE**: Binary content may be returned by this function.');
|
|
@@ -202,13 +152,10 @@ export class TypescriptGen extends CodeGen {
|
|
|
202
152
|
lines.push('**NOTE**: Binary content is returned by this function.');
|
|
203
153
|
lines.push('');
|
|
204
154
|
}
|
|
205
|
-
|
|
206
155
|
params.forEach(p => lines.push("@param ".concat(p)));
|
|
207
156
|
var args = method.allParams;
|
|
208
|
-
|
|
209
157
|
if (args.length) {
|
|
210
158
|
var requestType = this.requestTypeName(method);
|
|
211
|
-
|
|
212
159
|
if (requestType) {
|
|
213
160
|
requestType = method.httpMethod === 'PATCH' ? "Partial<I".concat(requestType, ">") : "I".concat(requestType);
|
|
214
161
|
lines.push("@param request composed interface \"".concat(requestType, "\" for complex method parameters"));
|
|
@@ -216,12 +163,10 @@ export class TypescriptGen extends CodeGen {
|
|
|
216
163
|
args.forEach(p => lines.push(this.paramComment(p, this.paramMappedType(p, method))));
|
|
217
164
|
}
|
|
218
165
|
}
|
|
219
|
-
|
|
220
166
|
lines.push('@param options one-time API call overrides');
|
|
221
167
|
lines.push('');
|
|
222
168
|
return lines.join('\n');
|
|
223
169
|
}
|
|
224
|
-
|
|
225
170
|
methodHeaderDeclaration(indent, method) {
|
|
226
171
|
var streamer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
227
172
|
var params = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
@@ -230,7 +175,6 @@ export class TypescriptGen extends CodeGen {
|
|
|
230
175
|
var requestType = this.requestTypeName(method);
|
|
231
176
|
var bump = this.bumper(indent);
|
|
232
177
|
var headComment = streamer ? this.methodHeaderComment(method, ['callback streaming output function']) : this.methodHeaderComment(method, params);
|
|
233
|
-
|
|
234
178
|
if (requestType) {
|
|
235
179
|
fragment = method.httpMethod === 'PATCH' ? "request: Partial<I".concat(requestType, ">") : "request: I".concat(requestType);
|
|
236
180
|
params.push(fragment);
|
|
@@ -240,24 +184,19 @@ export class TypescriptGen extends CodeGen {
|
|
|
240
184
|
if (args && args.length > 0) args.forEach(p => params.push(this.declareParameter(bump, method, p)));
|
|
241
185
|
fragment = params.length > 0 ? "\n".concat(params.join(this.paramDelimiter)) : '';
|
|
242
186
|
}
|
|
243
|
-
|
|
244
187
|
var callback = "callback: (readable: Readable) => Promise<".concat(mapped.name, ">,");
|
|
245
188
|
var header = this.commentHeader(indent, headComment) + "".concat(indent, "async ").concat(method.name, "(") + (streamer ? "\n".concat(bump).concat(callback) : '');
|
|
246
189
|
var returns = streamer ? '' : ": ".concat(this.returnType(indent, method));
|
|
247
190
|
return header + fragment + (fragment ? ', ' : '') + "options?: Partial<ITransportSettings>)".concat(returns, " {\n");
|
|
248
191
|
}
|
|
249
|
-
|
|
250
192
|
methodSignature(indent, method) {
|
|
251
193
|
return this.methodHeaderDeclaration(indent, method, false);
|
|
252
194
|
}
|
|
253
|
-
|
|
254
195
|
encodePathParams(indent, method) {
|
|
255
196
|
var bump = indent + this.indentStr;
|
|
256
197
|
var encodings = '';
|
|
257
|
-
|
|
258
198
|
if (method.pathParams.length > 0) {
|
|
259
199
|
var prefix = this.useRequest(method) ? 'request' : '';
|
|
260
|
-
|
|
261
200
|
for (var param of method.pathParams) {
|
|
262
201
|
if (param.doEncode()) {
|
|
263
202
|
var name = this.accessor(param.name, prefix);
|
|
@@ -265,28 +204,23 @@ export class TypescriptGen extends CodeGen {
|
|
|
265
204
|
}
|
|
266
205
|
}
|
|
267
206
|
}
|
|
268
|
-
|
|
269
207
|
return encodings;
|
|
270
208
|
}
|
|
271
|
-
|
|
272
209
|
declareMethod(indent, method) {
|
|
273
210
|
var bump = this.bumper(indent);
|
|
274
211
|
return this.methodSignature(indent, method) + this.encodePathParams(indent, method) + this.httpCall(bump, method) + "\n".concat(indent, "}");
|
|
275
212
|
}
|
|
276
|
-
|
|
277
213
|
returnType(indent, method) {
|
|
278
214
|
var mapped = this.typeMap(method.type);
|
|
279
215
|
var errors = this.errorResponses(indent, method);
|
|
280
216
|
return "Promise<SDKResponse<".concat(mapped.name, ", ").concat(errors, ">>");
|
|
281
217
|
}
|
|
282
|
-
|
|
283
218
|
functionSignature(indent, method) {
|
|
284
219
|
var fragment;
|
|
285
220
|
var requestType = this.requestTypeName(method);
|
|
286
221
|
var bump = this.bumper(indent);
|
|
287
222
|
var params = ['sdk: IAPIMethods'];
|
|
288
223
|
var headComment = this.methodHeaderComment(method, ['sdk IAPIMethods implementation']);
|
|
289
|
-
|
|
290
224
|
if (requestType) {
|
|
291
225
|
fragment = method.httpMethod === 'PATCH' ? "request: Partial<I".concat(requestType, ">") : "request: I".concat(requestType);
|
|
292
226
|
params.push(fragment);
|
|
@@ -296,12 +230,10 @@ export class TypescriptGen extends CodeGen {
|
|
|
296
230
|
if (args && args.length > 0) args.forEach(p => params.push(this.declareParameter(bump, method, p)));
|
|
297
231
|
fragment = params.length > 0 ? "\n".concat(params.join(this.paramDelimiter)) : '';
|
|
298
232
|
}
|
|
299
|
-
|
|
300
233
|
var header = this.commentHeader(indent, headComment) + "".concat(indent, "export const ").concat(method.name, " = async (");
|
|
301
234
|
var returns = this.returnType(indent, method);
|
|
302
235
|
return header + fragment + (fragment ? ', ' : '') + "options?: Partial<ITransportSettings>): ".concat(returns, " => {\n");
|
|
303
236
|
}
|
|
304
|
-
|
|
305
237
|
declareFunction(indent, method) {
|
|
306
238
|
var bump = this.bumper(indent);
|
|
307
239
|
this.itself = 'sdk';
|
|
@@ -309,92 +241,73 @@ export class TypescriptGen extends CodeGen {
|
|
|
309
241
|
this.itself = 'this';
|
|
310
242
|
return result;
|
|
311
243
|
}
|
|
312
|
-
|
|
313
244
|
declareInterface(indent, method) {
|
|
314
245
|
var sig = this.methodSignature(indent, method).trimRight();
|
|
315
246
|
sig = sig.replace(/^\s*async /gm, '');
|
|
316
247
|
sig = sig.substr(0, sig.length - 2);
|
|
317
248
|
return "".concat(sig, "\n");
|
|
318
249
|
}
|
|
319
|
-
|
|
320
250
|
streamerSignature(indent, method) {
|
|
321
251
|
return this.methodHeaderDeclaration(indent, method, true);
|
|
322
252
|
}
|
|
323
|
-
|
|
324
253
|
declareStreamer(indent, method) {
|
|
325
254
|
var bump = this.bumper(indent);
|
|
326
255
|
return this.streamerSignature(indent, method) + this.encodePathParams(bump, method) + this.streamCall(bump, method) + "\n".concat(indent, "}");
|
|
327
256
|
}
|
|
328
|
-
|
|
329
257
|
reserve(name) {
|
|
330
|
-
if (!isSpecialName(name)) return name;
|
|
258
|
+
if (!(0, _sdkModels.isSpecialName)(name)) return name;
|
|
331
259
|
return "'".concat(name, "'");
|
|
332
260
|
}
|
|
333
|
-
|
|
334
261
|
typeName(type) {
|
|
335
262
|
type.refCount++;
|
|
336
|
-
|
|
337
|
-
if (type.customType && !(type instanceof EnumType)) {
|
|
263
|
+
if (type.customType && !(type instanceof _sdkModels.EnumType)) {
|
|
338
264
|
return this.reserve("I".concat(type.name));
|
|
339
265
|
}
|
|
340
|
-
|
|
341
266
|
return this.reserve(type.name);
|
|
342
267
|
}
|
|
343
|
-
|
|
344
268
|
typeSignature(indent, type) {
|
|
345
|
-
var meta = type instanceof EnumType ? 'enum' : 'interface';
|
|
269
|
+
var meta = type instanceof _sdkModels.EnumType ? 'enum' : 'interface';
|
|
346
270
|
return this.commentHeader(indent, type.description) + "".concat(indent, "export ").concat(meta, " ").concat(this.typeName(type), " ").concat(this.typeOpen, "\n");
|
|
347
271
|
}
|
|
348
|
-
|
|
349
272
|
errorResponses(_indent, method) {
|
|
350
273
|
var results = method.errorResponses.map(r => "".concat(this.typeName(r.type)));
|
|
351
274
|
return results.join(' | ');
|
|
352
275
|
}
|
|
353
|
-
|
|
354
276
|
httpPath(path, prefix) {
|
|
355
277
|
prefix = prefix || '';
|
|
356
278
|
if (path.indexOf('{') >= 0) return "`".concat(path.replace(/{/gi, '${' + prefix), "`");
|
|
357
279
|
return "'".concat(path, "'");
|
|
358
280
|
}
|
|
359
|
-
|
|
360
281
|
argGroup(_indent, args, prefix) {
|
|
361
282
|
if (!args || args.length === 0) return this.nullStr;
|
|
362
283
|
var hash = [];
|
|
363
|
-
|
|
364
284
|
for (var arg of args) {
|
|
365
285
|
var reserved = this.reserve(arg);
|
|
366
|
-
|
|
367
286
|
if (prefix) {
|
|
368
287
|
hash.push("".concat(reserved, ": ").concat(this.accessor(arg, prefix)));
|
|
369
288
|
} else {
|
|
370
289
|
hash.push(reserved);
|
|
371
290
|
}
|
|
372
291
|
}
|
|
373
|
-
|
|
374
292
|
return "{".concat(hash.join(this.argDelimiter), "}");
|
|
375
293
|
}
|
|
376
|
-
|
|
377
294
|
accessor(name, prefix) {
|
|
378
295
|
var reserved = this.reserve(name);
|
|
379
296
|
if (!prefix) return reserved;
|
|
380
297
|
if (reserved === name) return "".concat(prefix, ".").concat(name);
|
|
381
298
|
return "".concat(prefix, "[").concat(reserved, "]");
|
|
382
299
|
}
|
|
383
|
-
|
|
384
300
|
argList(indent, args, prefix) {
|
|
385
301
|
prefix = prefix || '';
|
|
386
302
|
var bits = args.map(a => this.accessor(a, prefix));
|
|
387
303
|
return args && args.length !== 0 ? "\n".concat(indent).concat(bits.join(this.argDelimiter)) : this.nullStr;
|
|
388
304
|
}
|
|
389
|
-
|
|
390
305
|
argFill(current, args) {
|
|
391
306
|
if (!current && args.trim() === this.nullStr) {
|
|
392
307
|
return '';
|
|
393
308
|
}
|
|
394
|
-
|
|
395
309
|
return "".concat(args).concat(current ? this.argDelimiter : '').concat(current);
|
|
396
310
|
}
|
|
397
|
-
|
|
398
311
|
httpArgs(indent, method) {
|
|
399
312
|
var request = this.useRequest(method) ? 'request' : '';
|
|
400
313
|
var result = this.argFill('', 'options');
|
|
@@ -402,7 +315,6 @@ export class TypescriptGen extends CodeGen {
|
|
|
402
315
|
result = this.argFill(result, this.argGroup(indent, method.queryArgs, request));
|
|
403
316
|
return result;
|
|
404
317
|
}
|
|
405
|
-
|
|
406
318
|
httpCall(indent, method) {
|
|
407
319
|
var request = this.useRequest(method) ? 'request.' : '';
|
|
408
320
|
var mapped = this.typeMap(method.type);
|
|
@@ -411,7 +323,6 @@ export class TypescriptGen extends CodeGen {
|
|
|
411
323
|
var errors = this.errorResponses(indent, method);
|
|
412
324
|
return "".concat(indent, "return ").concat(this.it(method.httpMethod.toLowerCase())) + "<".concat(mapped.name, ", ").concat(errors, ">(") + this.httpPath(method.endpoint, request) + "".concat(args ? ', ' + args : '', ")");
|
|
413
325
|
}
|
|
414
|
-
|
|
415
326
|
streamCall(indent, method) {
|
|
416
327
|
var request = this.useRequest(method) ? 'request.' : '';
|
|
417
328
|
var mapped = this.typeMap(method.type);
|
|
@@ -419,11 +330,9 @@ export class TypescriptGen extends CodeGen {
|
|
|
419
330
|
var args = this.httpArgs(bump, method);
|
|
420
331
|
return "".concat(indent, "return ").concat(this.it('authStream'), "<").concat(mapped.name, ">(callback, '").concat(method.httpMethod.toUpperCase(), "', ").concat(this.httpPath(method.endpoint, request)).concat(args ? ', ' + args : '', ")");
|
|
421
332
|
}
|
|
422
|
-
|
|
423
333
|
summary(indent, text) {
|
|
424
334
|
return this.commentHeader(indent, text);
|
|
425
335
|
}
|
|
426
|
-
|
|
427
336
|
typeNames() {
|
|
428
337
|
var names = [];
|
|
429
338
|
if (!this.api) return names;
|
|
@@ -431,13 +340,10 @@ export class TypescriptGen extends CodeGen {
|
|
|
431
340
|
Object.values(types).filter(type => type.refCount > 0 && !type.intrinsic).forEach(type => names.push(this.typeName(type)));
|
|
432
341
|
return names;
|
|
433
342
|
}
|
|
434
|
-
|
|
435
343
|
typeMap(type) {
|
|
436
344
|
super.typeMap(type);
|
|
437
345
|
var mt = '';
|
|
438
|
-
|
|
439
346
|
var asString = (_, v) => "'".concat(v, "'");
|
|
440
|
-
|
|
441
347
|
var tsTypes = {
|
|
442
348
|
any: {
|
|
443
349
|
default: mt,
|
|
@@ -513,24 +419,20 @@ export class TypescriptGen extends CodeGen {
|
|
|
513
419
|
asVal: (_i, _v) => ''
|
|
514
420
|
}
|
|
515
421
|
};
|
|
516
|
-
|
|
517
422
|
if (type.elementType) {
|
|
518
423
|
var map = this.typeMap(type.elementType);
|
|
519
|
-
|
|
520
424
|
switch (type.className) {
|
|
521
425
|
case 'ArrayType':
|
|
522
426
|
return {
|
|
523
427
|
default: '[]',
|
|
524
428
|
name: "".concat(map.name, "[]")
|
|
525
429
|
};
|
|
526
|
-
|
|
527
430
|
case 'HashType':
|
|
528
431
|
this.rtlNeeds.add('IDictionary');
|
|
529
432
|
return {
|
|
530
433
|
default: '',
|
|
531
434
|
name: "IDictionary<".concat(map.name, ">")
|
|
532
435
|
};
|
|
533
|
-
|
|
534
436
|
case 'DelimArrayType':
|
|
535
437
|
this.rtlNeeds.add('DelimArray');
|
|
536
438
|
return {
|
|
@@ -538,7 +440,6 @@ export class TypescriptGen extends CodeGen {
|
|
|
538
440
|
name: "DelimArray<".concat(map.name, ">"),
|
|
539
441
|
asVal: (_, v) => "new DelimArray<".concat(map.name, ">([").concat(v, "])")
|
|
540
442
|
};
|
|
541
|
-
|
|
542
443
|
case 'EnumType':
|
|
543
444
|
return {
|
|
544
445
|
default: '',
|
|
@@ -546,10 +447,8 @@ export class TypescriptGen extends CodeGen {
|
|
|
546
447
|
asVal: (_, v) => "".concat(type.name, ".").concat(v)
|
|
547
448
|
};
|
|
548
449
|
}
|
|
549
|
-
|
|
550
450
|
throw new Error("Don't know how to handle: ".concat(JSON.stringify(type)));
|
|
551
451
|
}
|
|
552
|
-
|
|
553
452
|
if (type.name) {
|
|
554
453
|
var mapped = tsTypes[type.name];
|
|
555
454
|
if (mapped && mapped.name === 'Url') this.rtlNeeds.add(mapped.name);
|
|
@@ -561,6 +460,6 @@ export class TypescriptGen extends CodeGen {
|
|
|
561
460
|
throw new Error('Cannot output a nameless type.');
|
|
562
461
|
}
|
|
563
462
|
}
|
|
564
|
-
|
|
565
463
|
}
|
|
464
|
+
exports.TypescriptGen = TypescriptGen;
|
|
566
465
|
//# sourceMappingURL=typescript.gen.js.map
|