@flink-app/flink 0.12.1-alpha.0 → 0.12.1-alpha.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.
Files changed (46) hide show
  1. package/bin/flink.ts +6 -13
  2. package/dist/bin/flink.js +3 -10
  3. package/dist/cli/build.js +3 -3
  4. package/dist/cli/clean.js +2 -2
  5. package/dist/cli/cli-utils.js +1 -1
  6. package/dist/cli/run.js +2 -2
  7. package/dist/src/FlinkApp.d.ts +1 -1
  8. package/dist/src/FlinkApp.js +77 -77
  9. package/dist/src/FlinkErrors.d.ts +1 -1
  10. package/dist/src/FlinkErrors.js +5 -5
  11. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  12. package/dist/src/FlinkHttpHandler.js +1 -1
  13. package/dist/src/FlinkJob.d.ts +2 -2
  14. package/dist/src/FlinkLog.d.ts +2 -2
  15. package/dist/src/FlinkRepo.d.ts +6 -2
  16. package/dist/src/FlinkRepo.js +19 -10
  17. package/dist/src/FlinkResponse.d.ts +2 -2
  18. package/dist/src/FsUtils.js +7 -7
  19. package/dist/src/TypeScriptCompiler.js +83 -68
  20. package/dist/src/TypeScriptUtils.js +11 -33
  21. package/dist/src/index.js +5 -1
  22. package/dist/src/mock-data-generator.js +1 -1
  23. package/dist/src/utils.js +6 -6
  24. package/package.json +6 -6
  25. package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
  26. package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
  27. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
  29. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
  30. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
  31. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
  32. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
  34. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
  36. package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
  37. package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
  38. package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
  39. package/spec/mock-project/dist/src/index.js +6 -2
  40. package/src/FlinkApp.ts +5 -5
  41. package/src/FlinkRepo.ts +13 -4
  42. package/src/TypeScriptCompiler.ts +13 -2
  43. package/src/TypeScriptUtils.ts +110 -164
  44. package/cli/generate-schemas.ts +0 -153
  45. package/dist/cli/generate-schemas.d.ts +0 -2
  46. package/dist/cli/generate-schemas.js +0 -140
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
29
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
30
  if (y = 0, t) op = [op[0] & 2, t.value];
31
31
  switch (op[0]) {
@@ -46,10 +46,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
50
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
51
- to[j] = from[i];
52
- return to;
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
53
57
  };
54
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
55
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -80,10 +84,10 @@ var TypeScriptCompiler = /** @class */ (function () {
80
84
  */
81
85
  this.tsSchemasSymbolsToImports = [];
82
86
  this.project = new ts_morph_1.Project({
83
- tsConfigFilePath: path_1.join(cwd, "tsconfig.json"),
87
+ tsConfigFilePath: (0, path_1.join)(cwd, "tsconfig.json"),
84
88
  compilerOptions: {
85
89
  noEmit: false,
86
- outDir: path_1.join(cwd, "dist"),
90
+ outDir: (0, path_1.join)(cwd, "dist"),
87
91
  // incremental: true,
88
92
  },
89
93
  });
@@ -99,7 +103,7 @@ var TypeScriptCompiler = /** @class */ (function () {
99
103
  return __generator(this, function (_a) {
100
104
  switch (_a.label) {
101
105
  case 0:
102
- flinkDir = path_1.join(cwd, ".flink");
106
+ flinkDir = (0, path_1.join)(cwd, ".flink");
103
107
  _a.label = 1;
104
108
  case 1:
105
109
  _a.trys.push([1, 3, , 5]);
@@ -113,7 +117,7 @@ var TypeScriptCompiler = /** @class */ (function () {
113
117
  case 4:
114
118
  _a.sent();
115
119
  return [3 /*break*/, 5];
116
- case 5: return [4 /*yield*/, tiny_glob_1.default(".flink/**/*.ts", { cwd: cwd })];
120
+ case 5: return [4 /*yield*/, (0, tiny_glob_1.default)(".flink/**/*.ts", { cwd: cwd })];
117
121
  case 6:
118
122
  files = _a.sent();
119
123
  _i = 0, files_1 = files;
@@ -121,7 +125,7 @@ var TypeScriptCompiler = /** @class */ (function () {
121
125
  case 7:
122
126
  if (!(_i < files_1.length)) return [3 /*break*/, 10];
123
127
  file = files_1[_i];
124
- return [4 /*yield*/, fs_1.promises.rm(path_1.join(cwd, file))];
128
+ return [4 /*yield*/, fs_1.promises.rm((0, path_1.join)(cwd, file))];
125
129
  case 8:
126
130
  _a.sent();
127
131
  _a.label = 9;
@@ -155,11 +159,11 @@ var TypeScriptCompiler = /** @class */ (function () {
155
159
  message = message.getMessageText();
156
160
  }
157
161
  if (diag.getCategory() === ts_morph_1.DiagnosticCategory.Error) {
158
- console.error("[ERROR] " + ((_a = diag.getSourceFile()) === null || _a === void 0 ? void 0 : _a.getBaseName()) + " (line " + diag.getLineNumber() + "):", message);
162
+ console.error("[ERROR] ".concat((_a = diag.getSourceFile()) === null || _a === void 0 ? void 0 : _a.getBaseName(), " (line ").concat(diag.getLineNumber(), "):"), message);
159
163
  hasError = true;
160
164
  }
161
165
  if (diag.getCategory() === ts_morph_1.DiagnosticCategory.Warning) {
162
- console.warn("[WARNING] " + ((_b = diag.getSourceFile()) === null || _b === void 0 ? void 0 : _b.getBaseName()) + " (line " + diag.getLineNumber() + "):", message);
166
+ console.warn("[WARNING] ".concat((_b = diag.getSourceFile()) === null || _b === void 0 ? void 0 : _b.getBaseName(), " (line ").concat(diag.getLineNumber(), "):"), message);
163
167
  }
164
168
  }
165
169
  if (hasError) {
@@ -176,14 +180,14 @@ var TypeScriptCompiler = /** @class */ (function () {
176
180
  * Also extract handlers request and response schemas from Handler
177
181
  * type arguments.
178
182
  */
179
- TypeScriptCompiler.prototype.parseHandlers = function (excludeDirs) {
180
- if (excludeDirs === void 0) { excludeDirs = []; }
181
- return __awaiter(this, void 0, void 0, function () {
183
+ TypeScriptCompiler.prototype.parseHandlers = function () {
184
+ return __awaiter(this, arguments, void 0, function (excludeDirs) {
182
185
  var generatedFile, handlersArr, handlers, jsonSchemas;
186
+ if (excludeDirs === void 0) { excludeDirs = []; }
183
187
  return __generator(this, function (_a) {
184
188
  switch (_a.label) {
185
189
  case 0:
186
- generatedFile = this.createSourceFile(["generatedHandlers.ts"], "// Generated " + new Date() + "\nimport { autoRegisteredHandlers, HttpMethod } from \"@flink-app/flink\";\nexport const handlers = [];\nautoRegisteredHandlers.push(...handlers);\n ");
190
+ generatedFile = this.createSourceFile(["generatedHandlers.ts"], "// Generated ".concat(new Date(), "\nimport { autoRegisteredHandlers, HttpMethod } from \"@flink-app/flink\";\nexport const handlers = [];\nautoRegisteredHandlers.push(...handlers);\n "));
187
191
  handlersArr = generatedFile.getVariableDeclarationOrThrow("handlers").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
188
192
  return [4 /*yield*/, this.parseHandlerDir(generatedFile, handlersArr)];
189
193
  case 1:
@@ -225,13 +229,13 @@ var TypeScriptCompiler = /** @class */ (function () {
225
229
  return [3 /*break*/, 3];
226
230
  }
227
231
  isAutoRegister = this.isAutoRegisterableHandler(sf);
228
- console.log("Detected handler " + sf.getBaseName() + " " + (!isAutoRegister ? "(requires manual registration)" : ""));
232
+ console.log("Detected handler ".concat(sf.getBaseName(), " ").concat(!isAutoRegister ? "(requires manual registration)" : ""));
229
233
  namespaceImport = sf.getBaseNameWithoutExtension().replace(/\./g, "_") + "_" + i;
230
234
  imports.push({
231
235
  defaultImport: "* as " + namespaceImport,
232
236
  moduleSpecifier: generatedFile.getRelativePathAsModuleSpecifierTo(sf),
233
237
  });
234
- assumedHttpMethod = utils_1.getHttpMethodFromHandlerName(sf.getBaseName());
238
+ assumedHttpMethod = (0, utils_1.getHttpMethodFromHandlerName)(sf.getBaseName());
235
239
  return [4 /*yield*/, this.extractSchemasFromHandlerSourceFile(sf)];
236
240
  case 2:
237
241
  schemaTypes = _b.sent();
@@ -242,34 +246,34 @@ var TypeScriptCompiler = /** @class */ (function () {
242
246
  declarations: [
243
247
  {
244
248
  name: "__assumedHttpMethod",
245
- initializer: "\"" + (assumedHttpMethod || "") + "\"",
249
+ initializer: "\"".concat(assumedHttpMethod || "", "\""),
246
250
  },
247
251
  {
248
252
  name: "__file",
249
- initializer: "\"" + sf.getBaseName() + "\"",
253
+ initializer: "\"".concat(sf.getBaseName(), "\""),
250
254
  },
251
255
  {
252
256
  name: "__query",
253
- initializer: "[" + ((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.queryMetadata) || [])
257
+ initializer: "[".concat(((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.queryMetadata) || [])
254
258
  .map(function (_a) {
255
259
  var description = _a.description, name = _a.name;
256
- return "{description: \"" + description + "\", name: \"" + name + "\"}";
260
+ return "{description: \"".concat(description, "\", name: \"").concat(name, "\"}");
257
261
  })
258
- .join(",") + "]",
262
+ .join(","), "]"),
259
263
  },
260
264
  {
261
265
  name: "__params",
262
- initializer: "[" + ((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.paramsMetadata) || [])
266
+ initializer: "[".concat(((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.paramsMetadata) || [])
263
267
  .map(function (_a) {
264
268
  var description = _a.description, name = _a.name;
265
- return "{description: \"" + description + "\", name: \"" + name + "\"}";
269
+ return "{description: \"".concat(description, "\", name: \"").concat(name, "\"}");
266
270
  })
267
- .join(",") + "]",
271
+ .join(","), "]"),
268
272
  },
269
273
  ],
270
274
  });
271
275
  if (isAutoRegister) {
272
- handlersArr.insertElement(i, "{handler: " + namespaceImport + ", assumedHttpMethod: " + (assumedHttpMethod ? "HttpMethod." + assumedHttpMethod : undefined) + "}");
276
+ handlersArr.insertElement(i, "{handler: ".concat(namespaceImport, ", assumedHttpMethod: ").concat(assumedHttpMethod ? "HttpMethod." + assumedHttpMethod : undefined, "}"));
273
277
  i++;
274
278
  }
275
279
  if (schemaTypes) {
@@ -293,7 +297,7 @@ var TypeScriptCompiler = /** @class */ (function () {
293
297
  return __generator(this, function (_b) {
294
298
  switch (_b.label) {
295
299
  case 0:
296
- generatedFile = this.createSourceFile(["generatedRepos.ts"], "// Generated " + new Date() + "\n import { autoRegisteredRepos } from \"@flink-app/flink\";\n export const repos = [];\n autoRegisteredRepos.push(...repos);\n ");
300
+ generatedFile = this.createSourceFile(["generatedRepos.ts"], "// Generated ".concat(new Date(), "\n import { autoRegisteredRepos } from \"@flink-app/flink\";\n export const repos = [];\n autoRegisteredRepos.push(...repos);\n "));
297
301
  reposArr = generatedFile.getVariableDeclarationOrThrow("repos").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
298
302
  imports = [];
299
303
  i = 0;
@@ -302,12 +306,12 @@ var TypeScriptCompiler = /** @class */ (function () {
302
306
  if (!sf.getFilePath().includes("src/repos/")) {
303
307
  continue;
304
308
  }
305
- console.log("Detected repo " + sf.getBaseName());
309
+ console.log("Detected repo ".concat(sf.getBaseName()));
306
310
  imports.push({
307
311
  defaultImport: sf.getBaseNameWithoutExtension(),
308
312
  moduleSpecifier: generatedFile.getRelativePathAsModuleSpecifierTo(sf),
309
313
  });
310
- reposArr.insertElement(i, "{collectionName: \"" + utils_1.getCollectionNameForRepo(sf.getBaseName()) + "\", repoInstanceName: \"" + utils_1.getRepoInstanceName(sf.getBaseName()) + "\", Repo: " + sf.getBaseNameWithoutExtension() + "}");
314
+ reposArr.insertElement(i, "{collectionName: \"".concat((0, utils_1.getCollectionNameForRepo)(sf.getBaseName()), "\", repoInstanceName: \"").concat((0, utils_1.getRepoInstanceName)(sf.getBaseName()), "\", Repo: ").concat(sf.getBaseNameWithoutExtension(), "}"));
311
315
  i++;
312
316
  }
313
317
  generatedFile.addImportDeclarations(imports);
@@ -326,18 +330,18 @@ var TypeScriptCompiler = /** @class */ (function () {
326
330
  * Note that order is of importance so generated metadata are imported and initialized before start of flink app.
327
331
  * Otherwise singletons `autoRegisteredRepos` and `autoRegisteredHandlers` will not have been set.
328
332
  */
329
- TypeScriptCompiler.prototype.generateStartScript = function (appEntryScript) {
330
- if (appEntryScript === void 0) { appEntryScript = "/src/index.ts"; }
331
- return __awaiter(this, void 0, void 0, function () {
333
+ TypeScriptCompiler.prototype.generateStartScript = function () {
334
+ return __awaiter(this, arguments, void 0, function (appEntryScript) {
332
335
  var sf;
336
+ if (appEntryScript === void 0) { appEntryScript = "/src/index.ts"; }
333
337
  return __generator(this, function (_a) {
334
338
  switch (_a.label) {
335
339
  case 0:
336
340
  if (!this.project.getSourceFile(function (sf) { return sf.getFilePath().endsWith(appEntryScript); })) {
337
- console.error("Cannot find entry script '" + appEntryScript + "'");
341
+ console.error("Cannot find entry script '".concat(appEntryScript, "'"));
338
342
  return [2 /*return*/, process.exit(1)];
339
343
  }
340
- sf = this.createSourceFile(["start.ts"], "// Generated " + new Date() + "\nimport \"./generatedHandlers\";\nimport \"./generatedRepos\";\nimport \"./generatedJobs\";\nimport \".." + appEntryScript.replace(/\.ts/g, "") + "\";\n");
344
+ sf = this.createSourceFile(["start.ts"], "// Generated ".concat(new Date(), "\nimport \"./generatedHandlers\";\nimport \"./generatedRepos\";\nimport \"./generatedJobs\";\nimport \"..").concat(appEntryScript.replace(/\.ts/g, ""), "\";\n"));
341
345
  return [4 /*yield*/, sf.save()];
342
346
  case 1:
343
347
  _a.sent();
@@ -347,7 +351,7 @@ var TypeScriptCompiler = /** @class */ (function () {
347
351
  });
348
352
  };
349
353
  TypeScriptCompiler.prototype.createSourceFile = function (filename, contents) {
350
- return this.project.createSourceFile(path_1.join.apply(void 0, __spreadArray([this.cwd, ".flink"], filename)), contents, {
354
+ return this.project.createSourceFile(path_1.join.apply(void 0, __spreadArray([this.cwd, ".flink"], filename, false)), contents, {
351
355
  overwrite: true,
352
356
  });
353
357
  };
@@ -379,13 +383,13 @@ var TypeScriptCompiler = /** @class */ (function () {
379
383
  return __awaiter(this, void 0, void 0, function () {
380
384
  var defaultExport, handlerTypeRef;
381
385
  return __generator(this, function (_a) {
382
- defaultExport = TypeScriptUtils_1.getDefaultExport(handlerSourceFile);
386
+ defaultExport = (0, TypeScriptUtils_1.getDefaultExport)(handlerSourceFile);
383
387
  if (defaultExport) {
384
388
  handlerTypeRef = defaultExport.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.TypeReference);
385
389
  return [2 /*return*/, this.extractSchemaTypeFromHandler(handlerTypeRef)];
386
390
  }
387
391
  else {
388
- console.warn("Handler " + handlerSourceFile.getBaseName() + " is missing default exported handler function");
392
+ console.warn("Handler ".concat(handlerSourceFile.getBaseName(), " is missing default exported handler function"));
389
393
  }
390
394
  return [2 /*return*/];
391
395
  });
@@ -401,25 +405,25 @@ var TypeScriptCompiler = /** @class */ (function () {
401
405
  }
402
406
  handlerFileName = handlerFile.getBaseNameWithoutExtension().replace(/\./g, "_");
403
407
  generatedSchemaInterfaceStr = "";
404
- schemaInterfaceName = handlerFileName + "_" + suffix;
408
+ schemaInterfaceName = "".concat(handlerFileName, "_").concat(suffix);
405
409
  if (schema.isInterface()) {
406
410
  schemaSymbol = schema.getSymbolOrThrow();
407
- interfaceName = TypeScriptUtils_1.getInterfaceName(schemaSymbol);
411
+ interfaceName = (0, TypeScriptUtils_1.getInterfaceName)(schemaSymbol);
408
412
  declaration = schemaSymbol.getDeclarations()[0];
409
413
  if (declaration.getSourceFile() === handlerFile) {
410
414
  // Interface is declared within handler file
411
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " { \n " + schema
415
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " { \n ").concat(schema
412
416
  .getProperties()
413
417
  .map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
414
- .join("\n") + "\n }";
415
- for (_i = 0, _a = TypeScriptUtils_1.getTypesToImport(declaration); _i < _a.length; _i++) {
418
+ .join("\n"), "\n }");
419
+ for (_i = 0, _a = (0, TypeScriptUtils_1.getTypesToImport)(declaration); _i < _a.length; _i++) {
416
420
  typeToImport = _a[_i];
417
421
  this.tsSchemasSymbolsToImports.push(typeToImport.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
418
422
  }
419
423
  }
420
424
  else {
421
425
  // Interface is imported from other file
422
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " extends " + interfaceName + " {}";
426
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends ").concat(interfaceName, " {}");
423
427
  this.tsSchemasSymbolsToImports.push(schemaSymbol);
424
428
  }
425
429
  }
@@ -429,7 +433,7 @@ var TypeScriptCompiler = /** @class */ (function () {
429
433
  interfaceName = schemaSymbol.getEscapedName();
430
434
  declaration = schemaSymbol.getDeclarations()[0];
431
435
  if (declaration.getSourceFile() !== handlerFile) {
432
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " extends Array<" + interfaceName + "> {}";
436
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<").concat(interfaceName, "> {}");
433
437
  this.tsSchemasSymbolsToImports.push(schemaSymbol);
434
438
  }
435
439
  else {
@@ -438,12 +442,12 @@ var TypeScriptCompiler = /** @class */ (function () {
438
442
  .getProperties()
439
443
  .map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
440
444
  .join(" ");
441
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " extends Array<{" + props + "}> {}";
445
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<{").concat(props, "}> {}");
442
446
  }
443
447
  else {
444
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " extends Array<" + declaration.getText() + "> {}";
448
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<").concat(declaration.getText(), "> {}");
445
449
  }
446
- for (_b = 0, _c = TypeScriptUtils_1.getTypesToImport(declaration); _b < _c.length; _b++) {
450
+ for (_b = 0, _c = (0, TypeScriptUtils_1.getTypesToImport)(declaration); _b < _c.length; _b++) {
447
451
  typeToImport = _c[_b];
448
452
  this.tsSchemasSymbolsToImports.push(typeToImport.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
449
453
  }
@@ -457,10 +461,10 @@ var TypeScriptCompiler = /** @class */ (function () {
457
461
  typeRefIdentifiers.forEach(function (tr) {
458
462
  _this.tsSchemasSymbolsToImports.push(tr.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
459
463
  });
460
- generatedSchemaInterfaceStr = "export interface " + schemaInterfaceName + " { " + schema
464
+ generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " { ").concat(schema
461
465
  .getProperties()
462
466
  .map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
463
- .join("\n") + " }";
467
+ .join("\n"), " }");
464
468
  }
465
469
  else {
466
470
  console.log("[WARN] Unknown schema type", schema.getText());
@@ -475,11 +479,22 @@ var TypeScriptCompiler = /** @class */ (function () {
475
479
  };
476
480
  TypeScriptCompiler.prototype.initJsonSchemaGenerator = function () {
477
481
  var conf = {
478
- expose: "none",
482
+ expose: "none", // Do not create shared $ref definitions.
479
483
  topRef: false, // Removes the wrapper object around the schema.
484
+ additionalProperties: false,
485
+ jsDoc: "basic",
486
+ sortProps: false,
487
+ strictTuples: false,
488
+ minify: false,
489
+ markdownDescription: false,
490
+ skipTypeCheck: false,
491
+ encodeRefs: false,
492
+ extraTags: [],
493
+ functions: "fail",
494
+ discriminatorType: "json-schema",
480
495
  };
481
- var formatter = ts_json_schema_generator_1.createFormatter(conf);
482
- var parser = ts_json_schema_generator_1.createParser(this.project.getProgram().compilerObject, conf);
496
+ var formatter = (0, ts_json_schema_generator_1.createFormatter)(conf);
497
+ var parser = (0, ts_json_schema_generator_1.createParser)(this.project.getProgram().compilerObject, conf);
483
498
  var generator = new ts_json_schema_generator_1.SchemaGenerator(this.project.getProgram().compilerObject, parser, formatter, conf);
484
499
  return generator;
485
500
  };
@@ -510,8 +525,8 @@ var TypeScriptCompiler = /** @class */ (function () {
510
525
  $ref: "#/definitions/Schemas",
511
526
  definitions: {},
512
527
  });
513
- filePath = path_1.join(this.cwd, ".flink", "schemas", "schemas.json");
514
- return [4 /*yield*/, FsUtils_1.writeJsonFile(filePath, mergedSchemas)];
528
+ filePath = (0, path_1.join)(this.cwd, ".flink", "schemas", "schemas.json");
529
+ return [4 /*yield*/, (0, FsUtils_1.writeJsonFile)(filePath, mergedSchemas)];
515
530
  case 1:
516
531
  _d.sent();
517
532
  this.project.addSourceFileAtPath(filePath);
@@ -550,14 +565,14 @@ var TypeScriptCompiler = /** @class */ (function () {
550
565
  query = handlerTypeArgs[3];
551
566
  }
552
567
  else {
553
- throw new Error("Unknown handler type " + handlerType + " in " + handlerTypeReference.getSourceFile().getBaseName() + " - should be Handler or GetHandler");
568
+ throw new Error("Unknown handler type ".concat(handlerType, " in ").concat(handlerTypeReference.getSourceFile().getBaseName(), " - should be Handler or GetHandler"));
554
569
  }
555
570
  sf = handlerTypeReference.getSourceFile();
556
571
  createReqSchemaPromise = reqSchema
557
- ? this.saveIntermediateTsSchema(reqSchema, sf, handlerTypeReference.getStartLineNumber() + "_ReqSchema")
572
+ ? this.saveIntermediateTsSchema(reqSchema, sf, "".concat(handlerTypeReference.getStartLineNumber(), "_ReqSchema"))
558
573
  : Promise.resolve("");
559
574
  createResSchemaPromise = resSchema
560
- ? this.saveIntermediateTsSchema(resSchema, sf, handlerTypeReference.getStartLineNumber() + "_ResSchema")
575
+ ? this.saveIntermediateTsSchema(resSchema, sf, "".concat(handlerTypeReference.getStartLineNumber(), "_ResSchema"))
561
576
  : Promise.resolve("");
562
577
  return [4 /*yield*/, Promise.all([createReqSchemaPromise, createResSchemaPromise])];
563
578
  case 1:
@@ -565,8 +580,8 @@ var TypeScriptCompiler = /** @class */ (function () {
565
580
  return [2 /*return*/, {
566
581
  reqSchemaType: reqSchemaType,
567
582
  resSchemaType: resSchemaType,
568
- queryMetadata: TypeScriptUtils_1.getTypeMetadata(query),
569
- paramsMetadata: TypeScriptUtils_1.getTypeMetadata(params),
583
+ queryMetadata: (0, TypeScriptUtils_1.getTypeMetadata)(query),
584
+ paramsMetadata: (0, TypeScriptUtils_1.getTypeMetadata)(params),
570
585
  }];
571
586
  }
572
587
  });
@@ -580,8 +595,8 @@ var TypeScriptCompiler = /** @class */ (function () {
580
595
  return __awaiter(this, void 0, void 0, function () {
581
596
  var schemaSourceFile;
582
597
  return __generator(this, function (_a) {
583
- schemaSourceFile = this.createSourceFile(["schemas", "schemas.ts"], "// Generated " + new Date() + "\n" + this.parsedTsSchemas.join("\n\n"));
584
- TypeScriptUtils_1.addImports(schemaSourceFile, this.tsSchemasSymbolsToImports);
598
+ schemaSourceFile = this.createSourceFile(["schemas", "schemas.ts"], "// Generated ".concat(new Date(), "\n").concat(this.parsedTsSchemas.join("\n\n")));
599
+ (0, TypeScriptUtils_1.addImports)(schemaSourceFile, this.tsSchemasSymbolsToImports);
585
600
  return [2 /*return*/, schemaSourceFile.save()];
586
601
  });
587
602
  });
@@ -613,11 +628,11 @@ var TypeScriptCompiler = /** @class */ (function () {
613
628
  for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
614
629
  var _a = handlers_1[_i], sourceFile = _a.sourceFile, reqSchemaType = _a.reqSchemaType, resSchemaType = _a.resSchemaType;
615
630
  if (reqSchemaType && !jsonSchemaDefs[reqSchemaType]) {
616
- console.error("Handler " + sourceFile.getBaseName() + " has request schema\u00A0(" + reqSchemaType + ") defined, but no JSON schema has been generated");
631
+ console.error("Handler ".concat(sourceFile.getBaseName(), " has request schema\u00A0(").concat(reqSchemaType, ") defined, but no JSON schema has been generated"));
617
632
  continue;
618
633
  }
619
634
  if (resSchemaType && !jsonSchemaDefs[resSchemaType]) {
620
- console.error("Handler " + sourceFile.getBaseName() + " has response schema\u00A0(" + resSchemaType + ") defined, but no JSON schema has been generated");
635
+ console.error("Handler ".concat(sourceFile.getBaseName(), " has response schema\u00A0(").concat(resSchemaType, ") defined, but no JSON schema has been generated"));
621
636
  continue;
622
637
  }
623
638
  var reqJsonSchema = JSON.stringify(reqSchemaType ? jsonSchemaDefs[reqSchemaType] : undefined);
@@ -629,7 +644,7 @@ var TypeScriptCompiler = /** @class */ (function () {
629
644
  {
630
645
  name: "__schemas",
631
646
  type: "any",
632
- initializer: "{ reqSchema: " + reqJsonSchema + ", resSchema: " + resJsonSchema + " }",
647
+ initializer: "{ reqSchema: ".concat(reqJsonSchema, ", resSchema: ").concat(resJsonSchema, " }"),
633
648
  },
634
649
  ],
635
650
  });
@@ -644,7 +659,7 @@ var TypeScriptCompiler = /** @class */ (function () {
644
659
  return __generator(this, function (_b) {
645
660
  switch (_b.label) {
646
661
  case 0:
647
- generatedFile = this.createSourceFile(["generatedJobs.ts"], "// Generated " + new Date() + "\nimport { autoRegisteredJobs } from \"@flink-app/flink\";\nexport const jobs = [];\nautoRegisteredJobs.push(...jobs);\n ");
662
+ generatedFile = this.createSourceFile(["generatedJobs.ts"], "// Generated ".concat(new Date(), "\nimport { autoRegisteredJobs } from \"@flink-app/flink\";\nexport const jobs = [];\nautoRegisteredJobs.push(...jobs);\n "));
648
663
  jobsArr = generatedFile.getVariableDeclarationOrThrow("jobs").getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
649
664
  imports = [];
650
665
  i = 0;
@@ -653,7 +668,7 @@ var TypeScriptCompiler = /** @class */ (function () {
653
668
  if (!sf.getFilePath().includes("src/jobs/")) {
654
669
  continue;
655
670
  }
656
- console.log("Detected job " + sf.getBaseName());
671
+ console.log("Detected job ".concat(sf.getBaseName()));
657
672
  namespaceImport = sf.getBaseNameWithoutExtension().replace(/\./g, "_") + "_" + i;
658
673
  imports.push({
659
674
  defaultImport: "* as " + namespaceImport,
@@ -666,7 +681,7 @@ var TypeScriptCompiler = /** @class */ (function () {
666
681
  declarations: [
667
682
  {
668
683
  name: "__file",
669
- initializer: "\"" + sf.getBaseName() + "\"",
684
+ initializer: "\"".concat(sf.getBaseName(), "\""),
670
685
  },
671
686
  ],
672
687
  });
@@ -15,9 +15,7 @@ function getTypesToImport(node) {
15
15
  var typeRefIdentifiers = node
16
16
  .getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeReference)
17
17
  .filter(function (typeRefNode) { return !!typeRefNode.getFirstChildIfKind(ts_morph_1.SyntaxKind.Identifier); })
18
- .map(function (typeRefNode) {
19
- return typeRefNode.getFirstChildIfKindOrThrow(ts_morph_1.SyntaxKind.Identifier);
20
- });
18
+ .map(function (typeRefNode) { return typeRefNode.getFirstChildIfKindOrThrow(ts_morph_1.SyntaxKind.Identifier); });
21
19
  var typesToImport = [];
22
20
  for (var _i = 0, typeRefIdentifiers_1 = typeRefIdentifiers; _i < typeRefIdentifiers_1.length; _i++) {
23
21
  var typeRefIdentifier = typeRefIdentifiers_1[_i];
@@ -44,15 +42,8 @@ function addImport(toSourceFile, symbol) {
44
42
  }
45
43
  var importName = symbol.getEscapedName();
46
44
  var symbolSourceFile = symbolDeclaration.getSourceFile();
47
- var isDefaultExport = symbol
48
- .getDeclaredType()
49
- .getText()
50
- .endsWith(".default");
51
- var importDec = toSourceFile
52
- .getImportDeclarations()
53
- .find(function (importDeclarataion) {
54
- return importDeclarataion.getModuleSpecifierSourceFile() === symbolSourceFile;
55
- });
45
+ var isDefaultExport = symbol.getDeclaredType().getText().endsWith(".default");
46
+ var importDec = toSourceFile.getImportDeclarations().find(function (importDeclarataion) { return importDeclarataion.getModuleSpecifierSourceFile() === symbolSourceFile; });
56
47
  if (importDec) {
57
48
  // File already has import to file
58
49
  if (isDefaultExport) {
@@ -61,9 +52,7 @@ function addImport(toSourceFile, symbol) {
61
52
  }
62
53
  }
63
54
  else {
64
- if (!importDec
65
- .getNamedImports()
66
- .find(function (specifier) { return specifier.getText() === importName; })) {
55
+ if (!importDec.getNamedImports().find(function (specifier) { return specifier.getText() === importName; })) {
67
56
  importDec.addNamedImport(importName);
68
57
  }
69
58
  }
@@ -92,14 +81,9 @@ function addImports(toSourceFile, symbols) {
92
81
  if (!symbolDeclaration) {
93
82
  throw new Error("Missing declaration for symbol " + symbol.getFullyQualifiedName());
94
83
  }
95
- var importName = symbol.getDeclaredType().isInterface()
96
- ? getInterfaceName(symbol)
97
- : symbol.getEscapedName();
84
+ var importName = symbol.getDeclaredType().isInterface() ? getInterfaceName(symbol) : symbol.getEscapedName();
98
85
  var symbolSourceFile = symbolDeclaration.getSourceFile();
99
- var isDefaultExport = symbol
100
- .getDeclaredType()
101
- .getText()
102
- .endsWith(".default");
86
+ var isDefaultExport = symbol.getDeclaredType().getText().endsWith(".default");
103
87
  var moduleSpecifier = toSourceFile.getRelativePathAsModuleSpecifierTo(symbolSourceFile);
104
88
  var aImport = importsByModuleSpecifier.get(moduleSpecifier);
105
89
  if (!aImport) {
@@ -122,9 +106,7 @@ function addImports(toSourceFile, symbols) {
122
106
  return ({
123
107
  moduleSpecifier: moduleSpecifier,
124
108
  defaultImport: aImport.defaultImportName,
125
- namedImports: aImport.namedImports.length
126
- ? aImport.namedImports
127
- : undefined,
109
+ namedImports: aImport.namedImports.length ? aImport.namedImports : undefined,
128
110
  });
129
111
  }));
130
112
  }
@@ -158,9 +140,7 @@ function getInterfaceName(symbol) {
158
140
  if (!declaration) {
159
141
  throw new Error("Missing declaration of interface symbol");
160
142
  }
161
- return declaration
162
- .getFirstChildByKindOrThrow(ts_morph_1.SyntaxKind.Identifier)
163
- .getText();
143
+ return declaration.getFirstChildByKindOrThrow(ts_morph_1.SyntaxKind.Identifier).getText();
164
144
  }
165
145
  exports.getInterfaceName = getInterfaceName;
166
146
  function getSymbolOrAlias(type) {
@@ -168,7 +148,7 @@ function getSymbolOrAlias(type) {
168
148
  }
169
149
  exports.getSymbolOrAlias = getSymbolOrAlias;
170
150
  function getTypeMetadata(type) {
171
- if (["void", "any"].includes(type.getText())) {
151
+ if (!type || ["void", "any"].includes(type.getText())) {
172
152
  return [];
173
153
  }
174
154
  var symbol = getSymbolOrAlias(type);
@@ -179,11 +159,9 @@ function getTypeMetadata(type) {
179
159
  if (!declaration) {
180
160
  throw new Error("Could not get declaration for type: " + type.getText());
181
161
  }
182
- return declaration
183
- .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertySignature)
184
- .map(function (prop) {
162
+ return declaration.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertySignature).map(function (prop) {
185
163
  var _a;
186
- var description = utils_1.getJsDocComment(((_a = prop.getLeadingCommentRanges()[0]) === null || _a === void 0 ? void 0 : _a.getText()) || "");
164
+ var description = (0, utils_1.getJsDocComment)(((_a = prop.getLeadingCommentRanges()[0]) === null || _a === void 0 ? void 0 : _a.getText()) || "");
187
165
  return {
188
166
  description: description,
189
167
  name: prop.getName(),
package/dist/src/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var mock_json_schema_1 = require("mock-json-schema");
4
4
  var generateMockData = function (schema) {
5
5
  // TODO: mock-json-schema does not seem to handle `examples` array, might want to switch to json-schema-faker
6
- var mockData = mock_json_schema_1.mock(schema);
6
+ var mockData = (0, mock_json_schema_1.mock)(schema);
7
7
  return mockData;
8
8
  };
9
9
  exports.default = generateMockData;
package/dist/src/utils.js CHANGED
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -45,11 +45,11 @@ var tiny_glob_1 = __importDefault(require("tiny-glob"));
45
45
  var FlinkHttpHandler_1 = require("./FlinkHttpHandler");
46
46
  var FlinkLog_1 = require("./FlinkLog");
47
47
  function handlersPath(appRoot) {
48
- return path_1.join(appRoot, "src", "handlers");
48
+ return (0, path_1.join)(appRoot, "src", "handlers");
49
49
  }
50
50
  exports.handlersPath = handlersPath;
51
51
  function schemasPath(appRoot) {
52
- return path_1.join(appRoot, "src", "schemas");
52
+ return (0, path_1.join)(appRoot, "src", "schemas");
53
53
  }
54
54
  exports.schemasPath = schemasPath;
55
55
  function isRouteMatch(req, routes) {
@@ -73,14 +73,14 @@ function getHandlerFiles(appRoot) {
73
73
  switch (_a.label) {
74
74
  case 0:
75
75
  _a.trys.push([0, 2, , 3]);
76
- return [4 /*yield*/, tiny_glob_1.default("**/*.ts", {
76
+ return [4 /*yield*/, (0, tiny_glob_1.default)("**/*.ts", {
77
77
  cwd: handlersPath(appRoot),
78
78
  absolute: true,
79
79
  })];
80
80
  case 1: return [2 /*return*/, _a.sent()];
81
81
  case 2:
82
82
  err_1 = _a.sent();
83
- FlinkLog_1.log.debug("Failed getting handler files: " + err_1);
83
+ FlinkLog_1.log.debug("Failed getting handler files: ".concat(err_1));
84
84
  return [2 /*return*/, []];
85
85
  case 3: return [2 /*return*/];
86
86
  }
@@ -95,7 +95,7 @@ function getSchemaFiles(appRoot) {
95
95
  switch (_a.label) {
96
96
  case 0:
97
97
  _a.trys.push([0, 2, , 3]);
98
- return [4 /*yield*/, tiny_glob_1.default("**/*.ts", {
98
+ return [4 /*yield*/, (0, tiny_glob_1.default)("**/*.ts", {
99
99
  cwd: schemasPath(appRoot),
100
100
  absolute: true,
101
101
  })];