@looker/sdk-codegen 21.7.4 → 21.8.0

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/codeGen.d.ts +1 -1
  3. package/lib/codeGen.js +28 -154
  4. package/lib/codeGen.js.map +1 -1
  5. package/lib/codeGenerators.js +0 -16
  6. package/lib/codeGenerators.js.map +1 -1
  7. package/lib/csharp.gen.js +3 -71
  8. package/lib/csharp.gen.js.map +1 -1
  9. package/lib/declarationInfo.js +0 -7
  10. package/lib/declarationInfo.js.map +1 -1
  11. package/lib/esm/codeGen.js +48 -157
  12. package/lib/esm/codeGen.js.map +1 -1
  13. package/lib/esm/codeGenerators.js +28 -20
  14. package/lib/esm/codeGenerators.js.map +1 -1
  15. package/lib/esm/csharp.gen.js +19 -75
  16. package/lib/esm/csharp.gen.js.map +1 -1
  17. package/lib/esm/declarationInfo.js +10 -7
  18. package/lib/esm/declarationInfo.js.map +1 -1
  19. package/lib/esm/exampleInfo.js +24 -23
  20. package/lib/esm/exampleInfo.js.map +1 -1
  21. package/lib/esm/go.gen.js +18 -92
  22. package/lib/esm/go.gen.js.map +1 -1
  23. package/lib/esm/index.js +148 -13
  24. package/lib/esm/index.js.map +1 -1
  25. package/lib/esm/kotlin.gen.js +23 -118
  26. package/lib/esm/kotlin.gen.js.map +1 -1
  27. package/lib/esm/pseudo.gen.js +14 -24
  28. package/lib/esm/pseudo.gen.js.map +1 -1
  29. package/lib/esm/python.gen.js +19 -138
  30. package/lib/esm/python.gen.js.map +1 -1
  31. package/lib/esm/sdkModels.js +100 -432
  32. package/lib/esm/sdkModels.js.map +1 -1
  33. package/lib/esm/specConverter.js +58 -88
  34. package/lib/esm/specConverter.js.map +1 -1
  35. package/lib/esm/specDiff.js +36 -51
  36. package/lib/esm/specDiff.js.map +1 -1
  37. package/lib/esm/swift.gen.js +25 -137
  38. package/lib/esm/swift.gen.js.map +1 -1
  39. package/lib/esm/testUtils/index.js +17 -0
  40. package/lib/esm/testUtils/index.js.map +1 -0
  41. package/lib/esm/testUtils/testUtils.js +66 -0
  42. package/lib/esm/testUtils/testUtils.js.map +1 -0
  43. package/lib/esm/typescript.gen.js +24 -125
  44. package/lib/esm/typescript.gen.js.map +1 -1
  45. package/lib/exampleInfo.js +1 -31
  46. package/lib/exampleInfo.js.map +1 -1
  47. package/lib/go.gen.js +3 -87
  48. package/lib/go.gen.js.map +1 -1
  49. package/lib/index.js +0 -26
  50. package/lib/index.js.map +1 -1
  51. package/lib/kotlin.gen.js +7 -113
  52. package/lib/kotlin.gen.js.map +1 -1
  53. package/lib/pseudo.gen.js +3 -24
  54. package/lib/pseudo.gen.js.map +1 -1
  55. package/lib/python.gen.js +3 -133
  56. package/lib/python.gen.js.map +1 -1
  57. package/lib/sdkModels.js +8 -438
  58. package/lib/sdkModels.js.map +1 -1
  59. package/lib/specConverter.js +6 -106
  60. package/lib/specConverter.js.map +1 -1
  61. package/lib/specDiff.js +1 -56
  62. package/lib/specDiff.js.map +1 -1
  63. package/lib/swift.gen.js +3 -128
  64. package/lib/swift.gen.js.map +1 -1
  65. package/lib/testUtils/index.js +0 -2
  66. package/lib/testUtils/index.js.map +1 -1
  67. package/lib/testUtils/testUtils.js +1 -17
  68. package/lib/testUtils/testUtils.js.map +1 -1
  69. package/lib/typescript.gen.js +5 -117
  70. package/lib/typescript.gen.js.map +1 -1
  71. package/package.json +3 -3
@@ -1,148 +1,112 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
- import { describeParam, EnumType, mayQuote, strBody, TypeOfType, typeOfType } from './sdkModels';
4
- import { CodeGen, commentBlock } from './codeGen';
5
- export class SwiftGen extends CodeGen {
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SwiftGen = void 0;
7
+ var _sdkModels = require("./sdkModels");
8
+ var _codeGen = require("./codeGen");
9
+ 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; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ 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); }
12
+ class SwiftGen extends _codeGen.CodeGen {
6
13
  constructor() {
7
14
  super(...arguments);
8
-
9
15
  _defineProperty(this, "anyString", true);
10
-
11
16
  _defineProperty(this, "codePath", './swift/');
12
-
13
17
  _defineProperty(this, "packagePath", 'looker');
14
-
15
18
  _defineProperty(this, "itself", 'self');
16
-
17
19
  _defineProperty(this, "fileExtension", '.swift');
18
-
19
20
  _defineProperty(this, "commentStr", '// ');
20
-
21
21
  _defineProperty(this, "nullStr", 'nil');
22
-
23
22
  _defineProperty(this, "transport", 'transport');
24
-
25
23
  _defineProperty(this, "argDelimiter", ', ');
26
-
27
24
  _defineProperty(this, "paramDelimiter", ',\n');
28
-
29
25
  _defineProperty(this, "propDelimiter", '\n');
30
-
31
26
  _defineProperty(this, "enumDelimiter", '\n');
32
-
33
27
  _defineProperty(this, "codeQuote", '"');
34
-
35
28
  _defineProperty(this, "indentStr", ' ');
36
-
37
29
  _defineProperty(this, "endTypeStr", "\n}");
38
-
39
30
  _defineProperty(this, "needsRequestTypes", false);
40
-
41
31
  _defineProperty(this, "willItStream", true);
42
-
43
32
  _defineProperty(this, "keywords", new Set(['associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate', 'func', 'import', 'init', 'inout', 'internal', 'let', 'open', 'operator', 'private', 'protocol', 'public', 'static', 'struct', 'subscript', 'typealias', 'var', 'break', 'case', 'continue', 'default', 'defer', 'do', 'else', 'fallthrough', 'for', 'guard', 'if', 'in', 'repeat', 'return', 'switch', 'where', 'while', 'as', 'Any', 'catch', 'false', 'is', 'nil', 'rethrows', 'super', 'self', 'Self', 'throw', 'throws', 'true', 'try', '_', '#available', '#colorLiteral', '#column', '#else', '#elseif', '#endif', '#file', '#fileLiteral', '#function', '#if', '#imageLiteral', '#line', '#selector', 'and #sourceLocation', 'associativity', 'convenience', 'dynamic', 'didSet', 'final', 'get', 'infix', 'indirect', 'lazy', 'left', 'mutating', 'none', 'nonmutating', 'optional', 'override', 'postfix', 'precedence', 'prefix', 'Protocol', 'right', 'set', 'Type', 'unowned', 'weak', 'willSet']));
44
33
  }
45
-
46
34
  supportsMultiApi() {
47
35
  return false;
48
36
  }
49
-
50
37
  methodsPrologue(_indent) {
51
38
  return "\n/// ".concat(this.warnEditing(), "\n\nimport Foundation\n\n@available(OSX 10.15, *)\nopen class ").concat(this.packageName, ": APIMethods {\n\n").concat(this.indentStr, "public lazy var stream = ").concat(this.packageName, "Stream(authSession)\n");
52
39
  }
53
-
54
40
  streamsPrologue(_indent) {
55
41
  return "\n/// ".concat(this.warnEditing(), "\n\nimport Foundation\n\n@available(OSX 10.15, *)\nopen class ").concat(this.packageName, "Stream: APIMethods {\n");
56
42
  }
57
-
58
43
  methodsEpilogue(_indent) {
59
44
  return '\n}';
60
45
  }
61
-
62
46
  modelsPrologue(_indent) {
63
47
  return "\n/// ".concat(this.warnEditing(), "\n\nimport Foundation\n");
64
48
  }
65
-
66
49
  modelsEpilogue(_indent) {
67
50
  return '\n';
68
51
  }
69
-
70
52
  reserve(name) {
71
53
  if (this.keywords.has(name)) {
72
54
  return "`".concat(name, "`");
73
55
  }
74
-
75
56
  return name;
76
57
  }
77
-
78
58
  sdkFileName(baseFileName) {
79
59
  return this.fileName("sdk/".concat(baseFileName));
80
60
  }
81
-
82
61
  commentHeader(indent, text) {
83
62
  var commentStr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' * ';
84
63
  if (this.noComment || !text) return '';
85
-
86
64
  if (commentStr === ' ') {
87
- return "".concat(indent, "/**\n\n").concat(commentBlock(text, indent, commentStr), "\n").concat(indent, " */\n");
65
+ return "".concat(indent, "/**\n\n").concat((0, _codeGen.commentBlock)(text, indent, commentStr), "\n").concat(indent, " */\n");
88
66
  }
89
-
90
- return "".concat(indent, "/**\n").concat(commentBlock(text, indent, commentStr), "\n").concat(indent, " */\n");
67
+ return "".concat(indent, "/**\n").concat((0, _codeGen.commentBlock)(text, indent, commentStr), "\n").concat(indent, " */\n");
91
68
  }
92
-
93
69
  beginRegion(indent, description) {
94
70
  return "".concat(indent, "// MARK ").concat(description);
95
71
  }
96
-
97
72
  endRegion(_indent, _description) {
98
73
  return '';
99
74
  }
100
-
101
75
  isIdProp(_property) {
102
76
  return true;
103
77
  }
104
-
105
78
  itemType(property) {
106
- if (typeOfType(property.type) === TypeOfType.Array && property.type.elementType) {
79
+ if ((0, _sdkModels.typeOfType)(property.type) === _sdkModels.TypeOfType.Array && property.type.elementType) {
107
80
  return property.type.elementType;
108
81
  }
109
-
110
82
  return property.type;
111
83
  }
112
-
113
84
  useAnyString(property) {
114
85
  var typeCheck = this.itemType(property).name.toLowerCase();
115
86
  return this.anyString && typeCheck === 'string' && this.isIdProp(property);
116
87
  }
117
-
118
88
  useAnyInt(property) {
119
89
  var typeCheck = this.itemType(property).name.toLowerCase();
120
90
  return this.anyString && (typeCheck === 'integer' || typeCheck === 'int64') && this.isIdProp(property);
121
91
  }
122
-
123
92
  privy(name) {
124
93
  return this.reserve('_' + name.replace(/`/g, ''));
125
94
  }
126
-
127
95
  getSpecialHandling(property) {
128
96
  return this.useAnyString(property) ? 'AnyString' : this.useAnyInt(property) ? 'AnyInt' : '';
129
97
  }
130
-
131
98
  declareProperty(indent, property) {
132
99
  var optional = property.required ? '' : '?';
133
-
134
- if (property.name === strBody) {
100
+ if (property.name === _sdkModels.strBody) {
135
101
  property.type.refCount++;
136
102
  return this.commentHeader(indent, property.description || 'body parameter for dynamically created request type') + "".concat(indent, "var ").concat(this.reserve(property.name), ": ").concat(property.type.name).concat(optional);
137
103
  }
138
-
139
104
  var type = this.typeMap(property.type);
140
105
  var specialHandling = this.getSpecialHandling(property);
141
106
  var munge = '';
142
107
  var declaration = "".concat(indent, "public var ").concat(this.reserve(property.name), ": ").concat(type.name).concat(optional, "\n");
143
-
144
108
  if (specialHandling) {
145
- var ra = typeOfType(property.type) === TypeOfType.Array;
109
+ var ra = (0, _sdkModels.typeOfType)(property.type) === _sdkModels.TypeOfType.Array;
146
110
  var privy = this.reserve('_' + property.name);
147
111
  var bump = this.bumper(indent);
148
112
  var setter = property.required ? ra ? "".concat(privy, " = newValue.map { ").concat(specialHandling, ".init($0) }") : "".concat(privy, " = ").concat(specialHandling, ".init(newValue)") : ra ? "if let v = newValue { ".concat(privy, " = v.map { ").concat(specialHandling, ".init($0) } } else { ").concat(privy, " = nil }") : "".concat(privy, " = newValue.map(").concat(specialHandling, ".init)");
@@ -150,61 +114,48 @@ export class SwiftGen extends CodeGen {
150
114
  munge = ra ? "".concat(indent, "private var ").concat(privy, ": [").concat(specialHandling, "]").concat(optional, "\n") : "".concat(indent, "private var ").concat(privy, ": ").concat(specialHandling).concat(optional, "\n");
151
115
  declaration = "".concat(indent, "public var ").concat(this.reserve(property.name), ": ").concat(type.name).concat(optional, " {\n").concat(bump, "get { ").concat(getter, " }\n").concat(bump, "set { ").concat(setter, " }\n").concat(indent, "}\n");
152
116
  }
153
-
154
117
  return munge + this.commentHeader(indent, this.describeProperty(property)) + declaration;
155
118
  }
156
-
157
119
  paramComment(param, mapped) {
158
- return "@param {".concat(mapped.name, "} ").concat(param.name, " ").concat(describeParam(param));
120
+ return "@param {".concat(mapped.name, "} ").concat(param.name, " ").concat((0, _sdkModels.describeParam)(param));
159
121
  }
160
-
161
122
  declareParameter(indent, method, param) {
162
- var type = param.location === strBody ? this.writeableType(param.type, method) || param.type : param.type;
123
+ var type = param.location === _sdkModels.strBody ? this.writeableType(param.type, method) || param.type : param.type;
163
124
  var mapped = this.typeMap(type);
164
125
  var pOpt = '';
165
126
  var line = '';
166
-
167
- if (param.location === strBody) {
127
+ if (param.location === _sdkModels.strBody) {
168
128
  mapped.name = "".concat(mapped.name);
169
129
  }
170
-
171
130
  if (!param.required) {
172
131
  pOpt = '?';
173
132
  } else {
174
133
  line = '_ ';
175
134
  }
176
-
177
135
  return this.commentHeader(indent, this.paramComment(param, mapped)) + "".concat(indent).concat(line).concat(this.reserve(param.name), ": ").concat(mapped.name).concat(pOpt) + (param.required ? '' : mapped.default ? " = ".concat(mapped.default) : '');
178
136
  }
179
-
180
137
  initProp(prop) {
181
138
  var propName = this.reserve(prop.name);
182
139
  var specialHandling = this.getSpecialHandling(prop);
183
-
184
140
  if (specialHandling) {
185
- var ra = typeOfType(prop.type) === TypeOfType.Array;
141
+ var ra = (0, _sdkModels.typeOfType)(prop.type) === _sdkModels.TypeOfType.Array;
186
142
  var varName = this.privy(propName);
187
-
188
143
  if (prop.required) {
189
144
  if (ra) {
190
145
  return "".concat(this.it(varName), " = ").concat(propName, ".map { ").concat(specialHandling, ".init($0) }");
191
146
  }
192
-
193
147
  return "".concat(this.it(varName), " = ").concat(specialHandling, ".init(").concat(propName, ")");
194
148
  } else {
195
149
  if (ra) {
196
150
  return "if let v = ".concat(propName, " { ").concat(varName, " = v.map { ").concat(specialHandling, ".init($0) } } else { ").concat(varName, " = nil }");
197
151
  }
198
-
199
152
  return "".concat(this.it(varName), " = ").concat(propName, ".map(").concat(specialHandling, ".init)");
200
153
  }
201
154
  }
202
-
203
155
  return "".concat(this.it(propName), " = ").concat(propName);
204
156
  }
205
-
206
157
  construct(indent, type) {
207
- if (type instanceof EnumType) return '';
158
+ if (type instanceof _sdkModels.EnumType) return '';
208
159
  indent = this.bumper(indent);
209
160
  var bump = this.bumper(indent);
210
161
  var args = [];
@@ -221,47 +172,37 @@ export class SwiftGen extends CodeGen {
221
172
  });
222
173
  var namedInit = "".concat(indent, "public init(") + "".concat(args.join(this.argDelimiter), ") {\n") + inits.join('\n') + "\n".concat(indent, "}");
223
174
  var posInit = '';
224
-
225
175
  if (props.some(p => p.required)) {
226
176
  posInit = "\n".concat(indent, "public init(") + "".concat(posArgs.join(this.argDelimiter), ") {\n") + "".concat(bump).concat(this.it('init'), "(").concat(posInits.join(', '), ")") + "\n".concat(indent, "}\n");
227
177
  }
228
-
229
178
  return "\n".concat(namedInit, "\n").concat(posInit);
230
179
  }
231
-
232
180
  declarePositionalArg(indent, property) {
233
181
  var mappedType = this.typeMap(property.type);
234
182
  var propType;
235
183
  var line = '_ ';
236
-
237
184
  if (property.required) {
238
185
  propType = mappedType.name;
239
186
  } else {
240
187
  line = '';
241
188
  propType = "".concat(mappedType.name, "? = ").concat(this.nullStr);
242
189
  }
243
-
244
190
  var propName = this.reserve(property.name);
245
191
  return "".concat(indent).concat(line).concat(propName, ": ").concat(propType);
246
192
  }
247
-
248
193
  declareConstructorArg(indent, property) {
249
194
  var mappedType = this.typeMap(property.type);
250
195
  var propType;
251
-
252
196
  if (property.required) {
253
197
  propType = mappedType.name;
254
198
  } else {
255
199
  propType = "".concat(mappedType.name, "? = ").concat(this.nullStr);
256
200
  }
257
-
258
201
  var propName = this.reserve(property.name);
259
202
  return "".concat(indent).concat(propName, ": ").concat(propType);
260
203
  }
261
-
262
204
  methodHeaderDeclaration(indent, method) {
263
205
  var _method$description;
264
-
265
206
  var streamer = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
266
207
  var type = this.typeMap(method.type);
267
208
  var resultType = streamer ? 'Data' : type.name;
@@ -271,7 +212,6 @@ export class SwiftGen extends CodeGen {
271
212
  var fragment;
272
213
  var requestType = this.requestTypeName(method);
273
214
  var bump = indent + this.indentStr;
274
-
275
215
  if (requestType) {
276
216
  fragment = "request: I".concat(requestType);
277
217
  } else {
@@ -280,55 +220,44 @@ export class SwiftGen extends CodeGen {
280
220
  if (args && args.length > 0) args.forEach(p => params.push(this.declareParameter(bump, method, p)));
281
221
  fragment = params.length > 0 ? "\n".concat(params.join(this.paramDelimiter)) : '';
282
222
  }
283
-
284
223
  if (method.responseIsBoth()) {
285
224
  headComment += "\n\n**Note**: Binary content may be returned by this method.";
286
225
  } else if (method.responseIsBinary()) {
287
226
  headComment += "\n\n**Note**: Binary content is returned by this method.\n";
288
227
  }
289
-
290
228
  var dep = method.deprecated ? "".concat(indent, "@available(*, deprecated)\n") : '';
291
229
  var header = this.commentHeader(indent, headComment) + dep + "".concat(indent, "public func ").concat(method.name, "(");
292
230
  return header + fragment + "".concat(fragment ? ',' : '', "\n").concat(bump, "options: ITransportSettings? = nil\n").concat(indent, ") -> ").concat(returnType, " {\n");
293
231
  }
294
-
295
232
  methodSignature(indent, method) {
296
233
  return this.methodHeaderDeclaration(indent, method, false);
297
234
  }
298
-
299
235
  encodePathParams(indent, method) {
300
236
  var encodings = '';
301
-
302
237
  if (method.pathParams.length > 0) {
303
238
  for (var param of method.pathParams) {
304
239
  encodings += "".concat(indent, "let path_").concat(param.name, " = encodeParam(").concat(param.name, ")\n");
305
240
  }
306
241
  }
307
-
308
242
  return encodings;
309
243
  }
310
-
311
244
  declareMethod(indent, method) {
312
245
  var bump = this.bumper(indent);
313
246
  return this.methodSignature(indent, method) + this.encodePathParams(bump, method) + this.httpCall(bump, method) + "\n".concat(indent, "}");
314
247
  }
315
-
316
248
  streamerSignature(indent, method) {
317
249
  return this.methodHeaderDeclaration(indent, method, true);
318
250
  }
319
-
320
251
  declareStreamer(indent, method) {
321
252
  var bump = this.bumper(indent);
322
253
  return this.streamerSignature(indent, method) + this.encodePathParams(bump, method) + this.streamCall(bump, method) + "\n".concat(indent, "}");
323
254
  }
324
-
325
255
  codingKeys(indent, type) {
326
256
  var special = false;
327
257
  var keys = Object.values(type.properties).map(p => {
328
258
  var name = this.reserve(p.name);
329
259
  var alias = '';
330
260
  var useIt = this.useAnyString(p) || this.useAnyInt(p);
331
-
332
261
  if (useIt) {
333
262
  name = this.privy(name);
334
263
  special = true;
@@ -337,7 +266,6 @@ export class SwiftGen extends CodeGen {
337
266
  special = true;
338
267
  alias = p.jsonName;
339
268
  }
340
-
341
269
  return name + (alias ? " = \"".concat(alias, "\"") : '');
342
270
  });
343
271
  if (!special) return '';
@@ -346,54 +274,42 @@ export class SwiftGen extends CodeGen {
346
274
  var cases = keys.join("\n".concat(bump2, "case "));
347
275
  return "\n".concat(bump, "private enum CodingKeys : String, CodingKey {") + "\n".concat(bump2, "case ").concat(cases) + "\n".concat(bump, "}\n");
348
276
  }
349
-
350
277
  declareEnumValue(indent, value) {
351
278
  var quote = typeof value === 'string' ? this.codeQuote : '';
352
- return "".concat(indent, "case ").concat(mayQuote(value), " = ").concat(quote).concat(value).concat(quote);
279
+ return "".concat(indent, "case ").concat((0, _sdkModels.mayQuote)(value), " = ").concat(quote).concat(value).concat(quote);
353
280
  }
354
-
355
281
  typeSignature(indent, type) {
356
282
  var recursive = type.isRecursive();
357
283
  var typeName = recursive ? 'class' : 'struct';
358
284
  var access = recursive ? 'open' : 'public';
359
285
  var baseClass = 'SDKModel';
360
- var isEnum = type instanceof EnumType;
361
-
286
+ var isEnum = type instanceof _sdkModels.EnumType;
362
287
  if (isEnum) {
363
288
  typeName = 'enum';
364
289
  var num = type;
365
-
366
290
  var _mapped = this.typeMap(num.elementType);
367
-
368
291
  baseClass = "".concat(_mapped.name, ", Codable");
369
292
  }
370
-
371
293
  var keys = this.codingKeys(indent, type);
372
294
  var needClass = recursive ? '\nRecursive type references must use Class instead of Struct' : '';
373
295
  var mapped = this.typeMap(type);
374
296
  return this.commentHeader(indent, type.description + needClass) + "".concat(indent).concat(access, " ").concat(typeName, " ").concat(mapped.name, ": ").concat(baseClass, " {\n").concat(keys);
375
297
  }
376
-
377
298
  errorResponses(_indent, _method) {
378
299
  return 'SDKError';
379
300
  }
380
-
381
301
  httpPath(path, prefix) {
382
302
  prefix = prefix || '';
383
-
384
303
  if (path.indexOf('{') >= 0) {
385
304
  var tweak = path.replace(/{/gi, '\\(path_' + prefix);
386
305
  tweak = tweak.replace(/}/gi, ')');
387
306
  return "\"".concat(tweak, "\"");
388
307
  }
389
-
390
308
  return "\"".concat(path, "\"");
391
309
  }
392
-
393
310
  argGroup(indent, args, prefix) {
394
311
  if (!args || args.length === 0) return this.nullStr;
395
312
  var hash = [];
396
-
397
313
  for (var arg of args) {
398
314
  if (prefix) {
399
315
  hash.push("\"".concat(arg, "\": ").concat(prefix).concat(arg));
@@ -401,36 +317,28 @@ export class SwiftGen extends CodeGen {
401
317
  hash.push("\"".concat(arg, "\": ").concat(arg));
402
318
  }
403
319
  }
404
-
405
320
  return "\n".concat(indent, "[").concat(hash.join(this.argDelimiter), "]");
406
321
  }
407
-
408
322
  queryGroup(indent, method, prefix) {
409
323
  var params = method.getParams('query');
410
324
  if (!params || params.length === 0) return this.nullStr;
411
325
  var hash = [];
412
-
413
326
  for (var param of params) {
414
327
  var arg = this.asAny(param);
415
-
416
328
  if (prefix) {
417
329
  hash.push("\"".concat(param.name, "\": ").concat(prefix).concat(arg));
418
330
  } else {
419
331
  hash.push("\"".concat(param.name, "\": ").concat(arg));
420
332
  }
421
333
  }
422
-
423
334
  return "\n".concat(indent, "[").concat(hash.join(this.argDelimiter), "]");
424
335
  }
425
-
426
336
  asAny(param) {
427
337
  var castIt;
428
-
429
338
  if (param.type.elementType) {
430
339
  castIt = true;
431
340
  } else {
432
341
  var mapped = this.typeMap(param.type);
433
-
434
342
  switch (mapped.name.toLowerCase()) {
435
343
  case 'date':
436
344
  case 'datetime':
@@ -438,29 +346,23 @@ export class SwiftGen extends CodeGen {
438
346
  case 'bool':
439
347
  castIt = true;
440
348
  break;
441
-
442
349
  default:
443
350
  castIt = false;
444
351
  break;
445
352
  }
446
353
  }
447
-
448
354
  return param.name + (castIt ? ' as Any?' : '');
449
355
  }
450
-
451
356
  argList(indent, args, prefix) {
452
357
  prefix = prefix || '';
453
358
  return args && args.length !== 0 ? "\n".concat(indent).concat(prefix).concat(args.join(this.argDelimiter + prefix)) : this.nullStr;
454
359
  }
455
-
456
360
  argFill(current, args) {
457
361
  if (!current && args.trim() === this.nullStr) {
458
362
  return '';
459
363
  }
460
-
461
364
  return "".concat(args).concat(current ? this.argDelimiter : '').concat(current);
462
365
  }
463
-
464
366
  httpArgs(indent, method) {
465
367
  var request = this.useRequest(method) ? 'request.' : '';
466
368
  var result = this.argFill('', 'options');
@@ -468,7 +370,6 @@ export class SwiftGen extends CodeGen {
468
370
  result = this.argFill(result, this.queryGroup(indent, method, request));
469
371
  return result;
470
372
  }
471
-
472
373
  httpCall(indent, method) {
473
374
  var request = this.useRequest(method) ? 'request.' : '';
474
375
  var type = this.typeMap(method.type);
@@ -477,7 +378,6 @@ export class SwiftGen extends CodeGen {
477
378
  var errors = this.errorResponses(indent, method);
478
379
  return "".concat(indent, "let result: SDKResponse<").concat(type.name, ", ").concat(errors, "> = ").concat(this.it(method.httpMethod.toLowerCase()), "(").concat(this.httpPath(method.endpoint, request)).concat(args ? ', ' + args : '', ")\n").concat(indent, "return result");
479
380
  }
480
-
481
381
  streamCall(indent, method) {
482
382
  var request = this.useRequest(method) ? 'request.' : '';
483
383
  var bump = indent + this.indentStr;
@@ -485,27 +385,22 @@ export class SwiftGen extends CodeGen {
485
385
  var errors = this.errorResponses(indent, method);
486
386
  return "".concat(indent, "let result: SDKResponse<Data, ").concat(errors, "> = ").concat(this.it(method.httpMethod.toLowerCase()), "(").concat(this.httpPath(method.endpoint, request)).concat(args ? ', ' + args : '', ")\n").concat(indent, "return result");
487
387
  }
488
-
489
388
  summary(indent, text) {
490
389
  return this.commentHeader(indent, text);
491
390
  }
492
-
493
391
  typeNames() {
494
392
  var countError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
495
393
  var names = [];
496
394
  if (!this.api) return names;
497
-
498
395
  if (countError) {
499
396
  this.api.types.Error.refCount++;
500
397
  } else {
501
398
  this.api.types.Error.refCount = 0;
502
399
  }
503
-
504
400
  var types = this.api.types;
505
401
  Object.values(types).filter(type => type.refCount > 0 && !type.intrinsic).forEach(type => names.push("I".concat(type.name)));
506
402
  return names;
507
403
  }
508
-
509
404
  typeMap(type) {
510
405
  super.typeMap(type);
511
406
  var ns = 'Lk';
@@ -591,17 +486,14 @@ export class SwiftGen extends CodeGen {
591
486
  name: 'Voidable'
592
487
  }
593
488
  };
594
-
595
489
  if (type.elementType) {
596
490
  var map = this.typeMap(type.elementType);
597
-
598
491
  switch (type.className) {
599
492
  case 'ArrayType':
600
493
  return {
601
494
  default: '[]',
602
495
  name: "[".concat(map.name, "]")
603
496
  };
604
-
605
497
  case 'HashType':
606
498
  {
607
499
  var mapName = type.elementType.name === 'string' ? 'AnyCodable' : map.name;
@@ -610,23 +502,19 @@ export class SwiftGen extends CodeGen {
610
502
  name: "StringDictionary<".concat(mapName, ">")
611
503
  };
612
504
  }
613
-
614
505
  case 'DelimArrayType':
615
506
  return {
616
507
  default: 'nil',
617
508
  name: "DelimArray<".concat(map.name, ">")
618
509
  };
619
-
620
510
  case 'EnumType':
621
511
  return {
622
512
  default: 'nil',
623
513
  name: type.name
624
514
  };
625
515
  }
626
-
627
516
  throw new Error("Don't know how to handle: ".concat(JSON.stringify(type)));
628
517
  }
629
-
630
518
  if (type.name) {
631
519
  return swiftTypes[type.name] || {
632
520
  default: '',
@@ -636,6 +524,6 @@ export class SwiftGen extends CodeGen {
636
524
  throw new Error('Cannot output a nameless type.');
637
525
  }
638
526
  }
639
-
640
527
  }
528
+ exports.SwiftGen = SwiftGen;
641
529
  //# sourceMappingURL=swift.gen.js.map