@flink-app/flink 0.4.2 → 0.4.5
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/cli/build.ts +18 -22
- package/cli/run.ts +12 -2
- package/dist/bin/flink.js +2 -2
- package/dist/cli/build.js +4 -8
- package/dist/cli/clean.js +2 -2
- package/dist/cli/cli-utils.js +1 -1
- package/dist/cli/forked-compiler.d.ts +2 -0
- package/dist/cli/forked-compiler.js +33 -0
- package/dist/cli/generate-schemas.js +16 -20
- package/dist/cli/run.js +10 -3
- package/dist/src/FlinkApp.d.ts +1 -1
- package/dist/src/FlinkApp.js +54 -54
- package/dist/src/FlinkErrors.d.ts +1 -1
- package/dist/src/FlinkErrors.js +5 -5
- package/dist/src/FlinkHttpHandler.d.ts +7 -7
- package/dist/src/FlinkJob.d.ts +2 -2
- package/dist/src/FlinkRepo.js +1 -1
- package/dist/src/FlinkResponse.d.ts +2 -2
- package/dist/src/FsUtils.js +4 -4
- package/dist/src/TypeScriptCompiler.js +63 -67
- package/dist/src/TypeScriptUtils.js +1 -1
- package/dist/src/index.js +1 -5
- package/dist/src/mock-data-generator.js +1 -1
- package/dist/src/utils.js +27 -9
- package/package.json +2 -2
- package/spec/utils.spec.ts +245 -201
- package/src/utils.ts +111 -105
package/cli/build.ts
CHANGED
|
@@ -3,10 +3,10 @@ import TypeScriptCompiler from "../src/TypeScriptCompiler";
|
|
|
3
3
|
import { getOption } from "./cli-utils";
|
|
4
4
|
|
|
5
5
|
module.exports = async function run(args: string[]) {
|
|
6
|
-
|
|
6
|
+
const startTime = Date.now();
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if (args.includes("--help")) {
|
|
9
|
+
console.log(`
|
|
10
10
|
Description
|
|
11
11
|
Builds the application.
|
|
12
12
|
Will generate intermediates files in .flink and compile/transpile
|
|
@@ -22,31 +22,27 @@ module.exports = async function run(args: string[]) {
|
|
|
22
22
|
--help Displays this message
|
|
23
23
|
`);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
process.exit(0);
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
let dir = "./";
|
|
29
|
+
if (args[0] && !args[0].startsWith("--")) {
|
|
30
|
+
dir = args[0];
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const exclude = getOption(args, "exclude", "/spec") as string;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
await TypeScriptCompiler.clean(dir);
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const compiler = new TypeScriptCompiler(dir);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (!compiler.getPreEmitDiagnostics()) {
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
compiler.parseRepos(),
|
|
45
|
-
compiler.parseHandlers(exclude.split(",")),
|
|
46
|
-
compiler.generateStartScript(),
|
|
47
|
-
]);
|
|
43
|
+
await Promise.all([compiler.parseRepos(), compiler.parseHandlers(exclude.split(",")), compiler.parseJobs(), compiler.generateStartScript()]);
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
console.log(`Compilation done, took ${Date.now() - startTime}ms`);
|
|
50
46
|
|
|
51
|
-
|
|
47
|
+
compiler.emit();
|
|
52
48
|
};
|
package/cli/run.ts
CHANGED
|
@@ -16,8 +16,9 @@ module.exports = async function run(args: string[]) {
|
|
|
16
16
|
If no directory is provided, the current directory will be used.
|
|
17
17
|
|
|
18
18
|
Options
|
|
19
|
-
--entry
|
|
20
|
-
--help
|
|
19
|
+
--entry Entry script for app, default "/src/index.ts"
|
|
20
|
+
--help Displays this message
|
|
21
|
+
--precompiled Will run a precompiled app, default false
|
|
21
22
|
`);
|
|
22
23
|
|
|
23
24
|
process.exit(0);
|
|
@@ -34,6 +35,15 @@ module.exports = async function run(args: string[]) {
|
|
|
34
35
|
entry = entry.startsWith("/") ? entry : "/" + entry;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
if (args.includes("--precompiled")) {
|
|
39
|
+
if (args.includes("--entry")) {
|
|
40
|
+
console.warn("WARNING: --entry is ignored when using --precompiled");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
require("child_process").fork(dir + "/dist/.flink/start.js");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
await TypeScriptCompiler.clean(dir);
|
|
38
48
|
|
|
39
49
|
const compiler = new TypeScriptCompiler(dir);
|
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 ["
|
|
15
|
+
console.log("Usage: flink [" + commands.join("|") + "]");
|
|
16
16
|
process.exit();
|
|
17
17
|
}
|
|
18
18
|
if (!commands.includes(argv[0])) {
|
|
19
|
-
console.log("Invalid command: "
|
|
19
|
+
console.log("Invalid command: " + 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 (
|
|
18
|
+
while (_) 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 =
|
|
60
|
+
exclude = 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();
|
|
@@ -65,14 +65,10 @@ module.exports = function run(args) {
|
|
|
65
65
|
if (!compiler.getPreEmitDiagnostics()) {
|
|
66
66
|
process.exit(1);
|
|
67
67
|
}
|
|
68
|
-
return [4 /*yield*/, Promise.all([
|
|
69
|
-
compiler.parseRepos(),
|
|
70
|
-
compiler.parseHandlers(exclude.split(",")),
|
|
71
|
-
compiler.generateStartScript(),
|
|
72
|
-
])];
|
|
68
|
+
return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(exclude.split(",")), compiler.parseJobs(), compiler.generateStartScript()])];
|
|
73
69
|
case 2:
|
|
74
70
|
_a.sent();
|
|
75
|
-
console.log("Compilation done, took "
|
|
71
|
+
console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
|
|
76
72
|
compiler.emit();
|
|
77
73
|
return [2 /*return*/];
|
|
78
74
|
}
|
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 (
|
|
18
|
+
while (_) 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 "
|
|
61
|
+
console.log("Cleaned directory " + cleanedFolder);
|
|
62
62
|
return [2 /*return*/];
|
|
63
63
|
}
|
|
64
64
|
});
|
package/dist/cli/cli-utils.js
CHANGED
|
@@ -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 = "--"
|
|
6
|
+
var option = "--" + name;
|
|
7
7
|
if (args.includes(option)) {
|
|
8
8
|
if (opts.isBoolean && args[args.indexOf(option) + 1] !== "false") {
|
|
9
9
|
return true;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
var TypeScriptCompiler_1 = __importDefault(require("../src/TypeScriptCompiler"));
|
|
8
|
+
var startTime = Date.now();
|
|
9
|
+
var args = process.argv.slice(2);
|
|
10
|
+
var dir = args[0];
|
|
11
|
+
var actions = args[1];
|
|
12
|
+
console.log("Parallel compilation enabled, will fork 3 processes");
|
|
13
|
+
var compiler = new TypeScriptCompiler_1.default(dir);
|
|
14
|
+
if (actions.includes("preEmit")) {
|
|
15
|
+
// Only emit diagnostics for the first compiler
|
|
16
|
+
if (!compiler.getPreEmitDiagnostics()) {
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (actions.includes("parseRepos")) {
|
|
21
|
+
compiler.parseRepos();
|
|
22
|
+
}
|
|
23
|
+
if (actions.includes("parseHandlers")) {
|
|
24
|
+
compiler.parseHandlers();
|
|
25
|
+
}
|
|
26
|
+
if (actions.includes("parseJobs")) {
|
|
27
|
+
compiler.parseJobs();
|
|
28
|
+
}
|
|
29
|
+
if (actions.includes("generateStartScript")) {
|
|
30
|
+
compiler.generateStartScript();
|
|
31
|
+
}
|
|
32
|
+
console.log("Forked compiler done with ".concat(actions.replaceAll(",", ", "), ", took ").concat(Date.now() - startTime, "ms"));
|
|
33
|
+
compiler.emit();
|
|
@@ -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 (
|
|
29
|
+
while (_) 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,14 +47,10 @@ 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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
ar[i] = from[i];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
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;
|
|
58
54
|
};
|
|
59
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
56
|
var path_1 = require("path");
|
|
@@ -76,19 +72,19 @@ module.exports = function run(args) {
|
|
|
76
72
|
if (args[0] && !args[0].startsWith("--")) {
|
|
77
73
|
dir = args[0];
|
|
78
74
|
}
|
|
79
|
-
verbose =
|
|
75
|
+
verbose = cli_utils_1.getOption(args, "verbose", false, {
|
|
80
76
|
isBoolean: true,
|
|
81
77
|
});
|
|
82
|
-
typesDir =
|
|
83
|
-
outFile =
|
|
78
|
+
typesDir = cli_utils_1.getOption(args, "types-dir", "./src/schemas");
|
|
79
|
+
outFile = cli_utils_1.getOption(args, "out-file", "./.flink/generated-schemas.json");
|
|
84
80
|
project = new ts_morph_1.Project({
|
|
85
|
-
tsConfigFilePath:
|
|
81
|
+
tsConfigFilePath: path_1.join(dir, "tsconfig.json"),
|
|
86
82
|
skipAddingFilesFromTsConfig: true,
|
|
87
83
|
compilerOptions: {
|
|
88
84
|
noEmit: true,
|
|
89
85
|
},
|
|
90
86
|
});
|
|
91
|
-
project.addSourceFilesAtPaths(
|
|
87
|
+
project.addSourceFilesAtPaths(path_1.join(dir, typesDir, "**/*.ts"));
|
|
92
88
|
console.log("Found", project.getSourceFiles().length, "files");
|
|
93
89
|
schemaDeclarations = [];
|
|
94
90
|
generator = initJsonSchemaGenerator(project);
|
|
@@ -96,11 +92,11 @@ module.exports = function run(args) {
|
|
|
96
92
|
for (_i = 0, _a = project.getSourceFiles(); _i < _a.length; _i++) {
|
|
97
93
|
sf = _a[_i];
|
|
98
94
|
if (sf.getDefaultExportSymbol()) {
|
|
99
|
-
console.warn("WARN: Schema file "
|
|
95
|
+
console.warn("WARN: Schema file " + sf.getBaseName() + " has default export, but only named exports are picked up by json schemas parser");
|
|
100
96
|
}
|
|
101
97
|
sourceFileInterfaceDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration);
|
|
102
98
|
sourceFileEnumDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.EnumDeclaration);
|
|
103
|
-
sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations
|
|
99
|
+
sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations), sourceFileInterfaceDeclarations);
|
|
104
100
|
schemaDeclarations.push.apply(schemaDeclarations, sourceFileDeclarations.map(function (d) { return d.compilerNode; }));
|
|
105
101
|
verbose &&
|
|
106
102
|
console.log("Found", sourceFileDeclarations.length, "schema(s) in file", sf.getBaseName());
|
|
@@ -124,8 +120,8 @@ module.exports = function run(args) {
|
|
|
124
120
|
$ref: "#/definitions/Schemas",
|
|
125
121
|
definitions: {},
|
|
126
122
|
});
|
|
127
|
-
file =
|
|
128
|
-
return [4 /*yield*/,
|
|
123
|
+
file = path_1.join(dir, outFile);
|
|
124
|
+
return [4 /*yield*/, FsUtils_1.writeJsonFile(file, mergedSchemas, {
|
|
129
125
|
ensureDir: true,
|
|
130
126
|
})];
|
|
131
127
|
case 1:
|
|
@@ -137,8 +133,8 @@ module.exports = function run(args) {
|
|
|
137
133
|
});
|
|
138
134
|
};
|
|
139
135
|
function initJsonSchemaGenerator(project) {
|
|
140
|
-
var formatter =
|
|
141
|
-
var parser =
|
|
136
|
+
var formatter = ts_json_schema_generator_1.createFormatter({});
|
|
137
|
+
var parser = ts_json_schema_generator_1.createParser(project.getProgram().compilerObject, {});
|
|
142
138
|
var generator = new ts_json_schema_generator_1.SchemaGenerator(project.getProgram().compilerObject, parser, formatter, { expose: "export" });
|
|
143
139
|
return generator;
|
|
144
140
|
}
|
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 (
|
|
18
|
+
while (_) 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]) {
|
|
@@ -49,7 +49,7 @@ module.exports = function run(args) {
|
|
|
49
49
|
case 0:
|
|
50
50
|
startTime = Date.now();
|
|
51
51
|
if (args.includes("--help")) {
|
|
52
|
-
console.log("\n Description\n Compiles and starts the application.\n\n Usage\n $ flink run <dir>\n\n <dir> represents the directory of the Flink application.\n If no directory is provided, the current directory will be used.\n \n Options \n --entry
|
|
52
|
+
console.log("\n Description\n Compiles and starts the application.\n\n Usage\n $ flink run <dir>\n\n <dir> represents the directory of the Flink application.\n If no directory is provided, the current directory will be used.\n \n Options \n --entry Entry script for app, default \"/src/index.ts\"\n --help Displays this message\n --precompiled Will run a precompiled app, default false\n ");
|
|
53
53
|
process.exit(0);
|
|
54
54
|
}
|
|
55
55
|
dir = "./";
|
|
@@ -61,6 +61,13 @@ module.exports = function run(args) {
|
|
|
61
61
|
entry = args[args.indexOf("--entry") + 1];
|
|
62
62
|
entry = entry.startsWith("/") ? entry : "/" + entry;
|
|
63
63
|
}
|
|
64
|
+
if (args.includes("--precompiled")) {
|
|
65
|
+
if (args.includes("--entry")) {
|
|
66
|
+
console.warn("WARNING: --entry is ignored when using --precompiled");
|
|
67
|
+
}
|
|
68
|
+
require("child_process").fork(dir + "/dist/.flink/start.js");
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
64
71
|
return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
|
|
65
72
|
case 1:
|
|
66
73
|
_a.sent();
|
|
@@ -71,7 +78,7 @@ module.exports = function run(args) {
|
|
|
71
78
|
return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(), compiler.parseJobs(), compiler.generateStartScript(entry)])];
|
|
72
79
|
case 2:
|
|
73
80
|
_a.sent();
|
|
74
|
-
console.log("Compilation done, took "
|
|
81
|
+
console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
|
|
75
82
|
compiler.emit();
|
|
76
83
|
require("child_process").fork(dir + "/dist/.flink/start.js");
|
|
77
84
|
return [2 /*return*/];
|
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { HandlerFile, HttpMethod, QueryParamMetadata, RouteProps } from "./Flink
|
|
|
9
9
|
import { FlinkJobFile } from "./FlinkJob";
|
|
10
10
|
import { FlinkPlugin } from "./FlinkPlugin";
|
|
11
11
|
import { FlinkRepo } from "./FlinkRepo";
|
|
12
|
-
export type JSONSchema = JSONSchema7;
|
|
12
|
+
export declare type JSONSchema = JSONSchema7;
|
|
13
13
|
/**
|
|
14
14
|
* This will be populated at compile time when the apps handlers
|
|
15
15
|
* are picked up by TypeScript compiler
|