@flink-app/flink 0.3.12 → 0.4.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 (59) hide show
  1. package/.vscode/notes.txt +11 -0
  2. package/cli/run.ts +23 -27
  3. package/dist/bin/flink.js +2 -2
  4. package/dist/cli/build.js +3 -3
  5. package/dist/cli/clean.js +2 -2
  6. package/dist/cli/cli-utils.js +1 -1
  7. package/dist/cli/generate-schemas.js +20 -16
  8. package/dist/cli/run.js +3 -7
  9. package/dist/src/FlinkApp.d.ts +21 -3
  10. package/dist/src/FlinkApp.js +163 -53
  11. package/dist/src/FlinkErrors.d.ts +1 -1
  12. package/dist/src/FlinkErrors.js +5 -5
  13. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  14. package/dist/src/FlinkJob.d.ts +58 -0
  15. package/dist/src/FlinkJob.js +2 -0
  16. package/dist/src/FlinkLog.d.ts +16 -0
  17. package/dist/src/FlinkLog.js +11 -30
  18. package/dist/src/FlinkRepo.js +1 -1
  19. package/dist/src/FlinkResponse.d.ts +2 -2
  20. package/dist/src/FsUtils.js +4 -4
  21. package/dist/src/TypeScriptCompiler.d.ts +5 -1
  22. package/dist/src/TypeScriptCompiler.js +119 -91
  23. package/dist/src/TypeScriptUtils.js +1 -1
  24. package/dist/src/index.d.ts +2 -1
  25. package/dist/src/index.js +7 -2
  26. package/dist/src/mock-data-generator.js +1 -1
  27. package/dist/src/utils.js +9 -9
  28. package/package.json +7 -3
  29. package/spec/mock-project/dist/src/handlers/GetCar.js +59 -0
  30. package/spec/mock-project/dist/src/handlers/GetCar2.js +61 -0
  31. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +55 -0
  32. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +55 -0
  33. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +55 -0
  34. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +57 -0
  35. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +57 -0
  36. package/{dist/cli/generate.js → spec/mock-project/dist/src/handlers/GetCarWithOmitSchema.js} +19 -14
  37. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +60 -0
  38. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +60 -0
  39. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +56 -0
  40. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +58 -0
  41. package/spec/mock-project/dist/src/handlers/PostCar.js +57 -0
  42. package/{dist/cli/generate-schema.js → spec/mock-project/dist/src/handlers/PostLogin.js} +18 -14
  43. package/spec/mock-project/dist/src/handlers/PutCar.js +57 -0
  44. package/spec/mock-project/dist/src/index.js +79 -0
  45. package/spec/mock-project/dist/src/repos/CarRepo.js +26 -0
  46. package/spec/mock-project/dist/src/schemas/Car.js +2 -0
  47. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +2 -0
  48. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +2 -0
  49. package/src/FlinkApp.ts +146 -11
  50. package/src/FlinkJob.ts +64 -0
  51. package/src/FlinkLog.ts +13 -11
  52. package/src/TypeScriptCompiler.ts +593 -663
  53. package/src/index.ts +2 -1
  54. package/dist/cli/generate-schema.d.ts +0 -2
  55. package/dist/cli/generate.d.ts +0 -2
  56. package/dist/src/FlinkTsParser.d.ts +0 -2
  57. package/dist/src/FlinkTsParser.js +0 -219
  58. package/dist/src/FlinkTsUtils.d.ts +0 -16
  59. package/dist/src/FlinkTsUtils.js +0 -118
@@ -0,0 +1,11 @@
1
+ 1. Build time: Convert interfaces to JSON schemas
2
+
3
+
4
+ ./.flink/schemas
5
+
6
+ 2. Run time: Read JSON schemas from dir ./.flink/schemas/*.ts
7
+
8
+
9
+
10
+
11
+ flink prepare
package/cli/run.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  import TypeScriptCompiler from "../src/TypeScriptCompiler";
3
3
 
4
4
  module.exports = async function run(args: string[]) {
5
- const startTime = Date.now();
5
+ const startTime = Date.now();
6
6
 
7
- if (args.includes("--help")) {
8
- console.log(`
7
+ if (args.includes("--help")) {
8
+ console.log(`
9
9
  Description
10
10
  Compiles and starts the application.
11
11
 
@@ -20,37 +20,33 @@ module.exports = async function run(args: string[]) {
20
20
  --help Displays this message
21
21
  `);
22
22
 
23
- process.exit(0);
24
- }
23
+ process.exit(0);
24
+ }
25
25
 
26
- let dir = "./";
27
- if (args[0] && !args[0].startsWith("--")) {
28
- dir = args[0];
29
- }
26
+ let dir = "./";
27
+ if (args[0] && !args[0].startsWith("--")) {
28
+ dir = args[0];
29
+ }
30
30
 
31
- let entry = "/src/index.ts";
32
- if (args.includes("--entry")) {
33
- entry = args[args.indexOf("--entry") + 1];
34
- entry = entry.startsWith("/") ? entry : "/" + entry;
35
- }
31
+ let entry = "/src/index.ts";
32
+ if (args.includes("--entry")) {
33
+ entry = args[args.indexOf("--entry") + 1];
34
+ entry = entry.startsWith("/") ? entry : "/" + entry;
35
+ }
36
36
 
37
- await TypeScriptCompiler.clean(dir);
37
+ await TypeScriptCompiler.clean(dir);
38
38
 
39
- const compiler = new TypeScriptCompiler(dir);
39
+ const compiler = new TypeScriptCompiler(dir);
40
40
 
41
- if (!compiler.getPreEmitDiagnostics()) {
42
- process.exit(1);
43
- }
41
+ if (!compiler.getPreEmitDiagnostics()) {
42
+ process.exit(1);
43
+ }
44
44
 
45
- await Promise.all([
46
- compiler.parseRepos(),
47
- compiler.parseHandlers(),
48
- compiler.generateStartScript(entry),
49
- ]);
45
+ await Promise.all([compiler.parseRepos(), compiler.parseHandlers(), compiler.parseJobs(), compiler.generateStartScript(entry)]);
50
46
 
51
- console.log(`Compilation done, took ${Date.now() - startTime}ms`);
47
+ console.log(`Compilation done, took ${Date.now() - startTime}ms`);
52
48
 
53
- compiler.emit();
49
+ compiler.emit();
54
50
 
55
- require("child_process").fork(dir + "/dist/.flink/start.js");
51
+ require("child_process").fork(dir + "/dist/.flink/start.js");
56
52
  };
package/dist/bin/flink.js CHANGED
@@ -12,11 +12,11 @@ var commands = [
12
12
  var argv = process.argv.slice(2);
13
13
  var argCommand = argv[0];
14
14
  if (!argCommand || argv[0] === "help") {
15
- console.log("Usage: flink [" + commands.join("|") + "]");
15
+ console.log("Usage: flink [".concat(commands.join("|"), "]"));
16
16
  process.exit();
17
17
  }
18
18
  if (!commands.includes(argv[0])) {
19
- console.log("Invalid command: " + argCommand);
19
+ console.log("Invalid command: ".concat(argCommand));
20
20
  process.exit(1);
21
21
  }
22
22
  if (argCommand === "generate") {
package/dist/cli/build.js CHANGED
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
15
15
  function verb(n) { return function (v) { return step([n, v]); }; }
16
16
  function step(op) {
17
17
  if (f) throw new TypeError("Generator is already executing.");
18
- while (_) try {
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
19
  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;
20
20
  if (y = 0, t) op = [op[0] & 2, t.value];
21
21
  switch (op[0]) {
@@ -57,7 +57,7 @@ module.exports = function run(args) {
57
57
  if (args[0] && !args[0].startsWith("--")) {
58
58
  dir = args[0];
59
59
  }
60
- exclude = cli_utils_1.getOption(args, "exclude", "/spec");
60
+ exclude = (0, cli_utils_1.getOption)(args, "exclude", "/spec");
61
61
  return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
62
62
  case 1:
63
63
  _a.sent();
@@ -72,7 +72,7 @@ module.exports = function run(args) {
72
72
  ])];
73
73
  case 2:
74
74
  _a.sent();
75
- console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
75
+ console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
76
76
  compiler.emit();
77
77
  return [2 /*return*/];
78
78
  }
package/dist/cli/clean.js CHANGED
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
15
15
  function verb(n) { return function (v) { return step([n, v]); }; }
16
16
  function step(op) {
17
17
  if (f) throw new TypeError("Generator is already executing.");
18
- while (_) try {
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
19
  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;
20
20
  if (y = 0, t) op = [op[0] & 2, t.value];
21
21
  switch (op[0]) {
@@ -58,7 +58,7 @@ module.exports = function run(args) {
58
58
  return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
59
59
  case 1:
60
60
  cleanedFolder = _a.sent();
61
- console.log("Cleaned directory " + cleanedFolder);
61
+ console.log("Cleaned directory ".concat(cleanedFolder));
62
62
  return [2 /*return*/];
63
63
  }
64
64
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOption = void 0;
4
4
  function getOption(args, name, defaultValue, opts) {
5
5
  if (opts === void 0) { opts = {}; }
6
- var option = "--" + name;
6
+ var option = "--".concat(name);
7
7
  if (args.includes(option)) {
8
8
  if (opts.isBoolean && args[args.indexOf(option) + 1] !== "false") {
9
9
  return true;
@@ -26,7 +26,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
26
26
  function verb(n) { return function (v) { return step([n, v]); }; }
27
27
  function step(op) {
28
28
  if (f) throw new TypeError("Generator is already executing.");
29
- while (_) try {
29
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
30
  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;
31
31
  if (y = 0, t) op = [op[0] & 2, t.value];
32
32
  switch (op[0]) {
@@ -47,10 +47,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
48
  }
49
49
  };
50
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
51
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
52
- to[j] = from[i];
53
- return to;
50
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
51
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
52
+ if (ar || !(i in from)) {
53
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
54
+ ar[i] = from[i];
55
+ }
56
+ }
57
+ return to.concat(ar || Array.prototype.slice.call(from));
54
58
  };
55
59
  Object.defineProperty(exports, "__esModule", { value: true });
56
60
  var path_1 = require("path");
@@ -72,19 +76,19 @@ module.exports = function run(args) {
72
76
  if (args[0] && !args[0].startsWith("--")) {
73
77
  dir = args[0];
74
78
  }
75
- verbose = cli_utils_1.getOption(args, "verbose", false, {
79
+ verbose = (0, cli_utils_1.getOption)(args, "verbose", false, {
76
80
  isBoolean: true,
77
81
  });
78
- typesDir = cli_utils_1.getOption(args, "types-dir", "./src/schemas");
79
- outFile = cli_utils_1.getOption(args, "out-file", "./.flink/generated-schemas.json");
82
+ typesDir = (0, cli_utils_1.getOption)(args, "types-dir", "./src/schemas");
83
+ outFile = (0, cli_utils_1.getOption)(args, "out-file", "./.flink/generated-schemas.json");
80
84
  project = new ts_morph_1.Project({
81
- tsConfigFilePath: path_1.join(dir, "tsconfig.json"),
85
+ tsConfigFilePath: (0, path_1.join)(dir, "tsconfig.json"),
82
86
  skipAddingFilesFromTsConfig: true,
83
87
  compilerOptions: {
84
88
  noEmit: true,
85
89
  },
86
90
  });
87
- project.addSourceFilesAtPaths(path_1.join(dir, typesDir, "**/*.ts"));
91
+ project.addSourceFilesAtPaths((0, path_1.join)(dir, typesDir, "**/*.ts"));
88
92
  console.log("Found", project.getSourceFiles().length, "files");
89
93
  schemaDeclarations = [];
90
94
  generator = initJsonSchemaGenerator(project);
@@ -92,11 +96,11 @@ module.exports = function run(args) {
92
96
  for (_i = 0, _a = project.getSourceFiles(); _i < _a.length; _i++) {
93
97
  sf = _a[_i];
94
98
  if (sf.getDefaultExportSymbol()) {
95
- console.warn("WARN: Schema file " + sf.getBaseName() + " has default export, but only named exports are picked up by json schemas parser");
99
+ console.warn("WARN: Schema file ".concat(sf.getBaseName(), " has default export, but only named exports are picked up by json schemas parser"));
96
100
  }
97
101
  sourceFileInterfaceDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration);
98
102
  sourceFileEnumDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.EnumDeclaration);
99
- sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations), sourceFileInterfaceDeclarations);
103
+ sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations, true), sourceFileInterfaceDeclarations, true);
100
104
  schemaDeclarations.push.apply(schemaDeclarations, sourceFileDeclarations.map(function (d) { return d.compilerNode; }));
101
105
  verbose &&
102
106
  console.log("Found", sourceFileDeclarations.length, "schema(s) in file", sf.getBaseName());
@@ -120,8 +124,8 @@ module.exports = function run(args) {
120
124
  $ref: "#/definitions/Schemas",
121
125
  definitions: {},
122
126
  });
123
- file = path_1.join(dir, outFile);
124
- return [4 /*yield*/, FsUtils_1.writeJsonFile(file, mergedSchemas, {
127
+ file = (0, path_1.join)(dir, outFile);
128
+ return [4 /*yield*/, (0, FsUtils_1.writeJsonFile)(file, mergedSchemas, {
125
129
  ensureDir: true,
126
130
  })];
127
131
  case 1:
@@ -133,8 +137,8 @@ module.exports = function run(args) {
133
137
  });
134
138
  };
135
139
  function initJsonSchemaGenerator(project) {
136
- var formatter = ts_json_schema_generator_1.createFormatter({});
137
- var parser = ts_json_schema_generator_1.createParser(project.getProgram().compilerObject, {});
140
+ var formatter = (0, ts_json_schema_generator_1.createFormatter)({});
141
+ var parser = (0, ts_json_schema_generator_1.createParser)(project.getProgram().compilerObject, {});
138
142
  var generator = new ts_json_schema_generator_1.SchemaGenerator(project.getProgram().compilerObject, parser, formatter, { expose: "export" });
139
143
  return generator;
140
144
  }
package/dist/cli/run.js CHANGED
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
15
15
  function verb(n) { return function (v) { return step([n, v]); }; }
16
16
  function step(op) {
17
17
  if (f) throw new TypeError("Generator is already executing.");
18
- while (_) try {
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
19
  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;
20
20
  if (y = 0, t) op = [op[0] & 2, t.value];
21
21
  switch (op[0]) {
@@ -68,14 +68,10 @@ module.exports = function run(args) {
68
68
  if (!compiler.getPreEmitDiagnostics()) {
69
69
  process.exit(1);
70
70
  }
71
- return [4 /*yield*/, Promise.all([
72
- compiler.parseRepos(),
73
- compiler.parseHandlers(),
74
- compiler.generateStartScript(entry),
75
- ])];
71
+ return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(), compiler.parseJobs(), compiler.generateStartScript(entry)])];
76
72
  case 2:
77
73
  _a.sent();
78
- console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
74
+ console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
79
75
  compiler.emit();
80
76
  require("child_process").fork(dir + "/dist/.flink/start.js");
81
77
  return [2 /*return*/];
@@ -2,15 +2,17 @@ import { OptionsJson } from "body-parser";
2
2
  import { Express } from "express";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  import { Db } from "mongodb";
5
+ import { ToadScheduler } from "toad-scheduler";
5
6
  import { FlinkAuthPlugin } from "./auth/FlinkAuthPlugin";
6
7
  import { FlinkContext } from "./FlinkContext";
7
8
  import { HandlerFile, HttpMethod, QueryParamMetadata, RouteProps } from "./FlinkHttpHandler";
9
+ import { FlinkJobFile } from "./FlinkJob";
8
10
  import { FlinkPlugin } from "./FlinkPlugin";
9
11
  import { FlinkRepo } from "./FlinkRepo";
10
- export declare type JSONSchema = JSONSchema7;
12
+ export type JSONSchema = JSONSchema7;
11
13
  /**
12
14
  * This will be populated at compile time when the apps handlers
13
- * are picked up by typescript compiler
15
+ * are picked up by TypeScript compiler
14
16
  */
15
17
  export declare const autoRegisteredHandlers: {
16
18
  handler: HandlerFile;
@@ -18,13 +20,18 @@ export declare const autoRegisteredHandlers: {
18
20
  }[];
19
21
  /**
20
22
  * This will be populated at compile time when the apps repos
21
- * are picked up by typescript compiler
23
+ * are picked up by TypeScript compiler
22
24
  */
23
25
  export declare const autoRegisteredRepos: {
24
26
  collectionName: string;
25
27
  repoInstanceName: string;
26
28
  Repo: any;
27
29
  }[];
30
+ /**
31
+ * This will be populated at compile time when the apps jobs
32
+ * are picked up by TypeScript compiler
33
+ */
34
+ export declare const autoRegisteredJobs: FlinkJobFile[];
28
35
  export interface FlinkOptions {
29
36
  /**
30
37
  * Name of application, will only show in logs and in HTTP header.
@@ -93,6 +100,13 @@ export interface FlinkOptions {
93
100
  * Options for json body parser
94
101
  */
95
102
  jsonOptions?: OptionsJson;
103
+ scheduling?: {
104
+ /**
105
+ * If true, the scheduler will be enabled.
106
+ * Defaults to true.
107
+ */
108
+ enabled?: boolean;
109
+ };
96
110
  }
97
111
  export interface HandlerConfig {
98
112
  schema?: {
@@ -130,11 +144,13 @@ export declare class FlinkApp<C extends FlinkContext> {
130
144
  private corsOpts;
131
145
  private routingConfigured;
132
146
  private jsonOptions?;
147
+ private schedulingOptions?;
133
148
  private repos;
134
149
  /**
135
150
  * Internal cache used to track registered handlers and potentially any overlapping routes
136
151
  */
137
152
  private handlerRouteCache;
153
+ scheduler?: ToadScheduler;
138
154
  constructor(opts: FlinkOptions);
139
155
  get ctx(): C;
140
156
  start(): Promise<this>;
@@ -153,6 +169,7 @@ export declare class FlinkApp<C extends FlinkContext> {
153
169
  * Will not register any handlers added programmatically.
154
170
  */
155
171
  private registerAutoRegisterableHandlers;
172
+ private registerAutoRegisterableJobs;
156
173
  addRepo(instanceName: string, repoInstance: FlinkRepo<C>): void;
157
174
  /**
158
175
  * Constructs the app context. Will inject context in all components
@@ -169,4 +186,5 @@ export declare class FlinkApp<C extends FlinkContext> {
169
186
  private initPluginDb;
170
187
  private authenticate;
171
188
  getRegisteredRoutes(): string[];
189
+ private get isSchedulingEnabled();
172
190
  }