@flink-app/flink 0.3.7 → 0.3.11
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/dist/bin/flink.js +2 -2
- package/dist/cli/build.js +3 -3
- package/dist/cli/clean.js +2 -2
- package/dist/cli/cli-utils.js +1 -1
- package/dist/cli/generate-schemas.js +20 -16
- package/dist/cli/run.js +2 -2
- package/dist/src/FlinkApp.d.ts +1 -1
- package/dist/src/FlinkApp.js +54 -50
- 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/FlinkLog.js +5 -5
- 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 +67 -63
- package/dist/src/TypeScriptUtils.js +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/mock-data-generator.js +1 -1
- package/dist/src/utils.js +9 -9
- package/package.json +2 -2
- package/readme.md +14 -10
- package/src/FlinkApp.ts +446 -510
package/dist/src/FlinkLog.js
CHANGED
|
@@ -8,28 +8,28 @@ exports.log = {
|
|
|
8
8
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
9
|
args[_i] = arguments[_i];
|
|
10
10
|
}
|
|
11
|
-
return node_color_log_1.debug(args);
|
|
11
|
+
return (0, node_color_log_1.debug)(args);
|
|
12
12
|
},
|
|
13
13
|
info: function () {
|
|
14
14
|
var args = [];
|
|
15
15
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
16
16
|
args[_i] = arguments[_i];
|
|
17
17
|
}
|
|
18
|
-
return node_color_log_1.info(args);
|
|
18
|
+
return (0, node_color_log_1.info)(args);
|
|
19
19
|
},
|
|
20
20
|
warn: function () {
|
|
21
21
|
var args = [];
|
|
22
22
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
23
|
args[_i] = arguments[_i];
|
|
24
24
|
}
|
|
25
|
-
return node_color_log_1.warn(args);
|
|
25
|
+
return (0, node_color_log_1.warn)(args);
|
|
26
26
|
},
|
|
27
27
|
error: function () {
|
|
28
28
|
var args = [];
|
|
29
29
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
30
30
|
args[_i] = arguments[_i];
|
|
31
31
|
}
|
|
32
|
-
return node_color_log_1.error(args);
|
|
32
|
+
return (0, node_color_log_1.error)(args);
|
|
33
33
|
},
|
|
34
34
|
json: function () {
|
|
35
35
|
var args = [];
|
|
@@ -41,5 +41,5 @@ exports.log = {
|
|
|
41
41
|
console.log(JSON.stringify(o, null, 2));
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
|
-
setLevel: function (level) { return node_color_log_1.setLevel(level); },
|
|
44
|
+
setLevel: function (level) { return (0, node_color_log_1.setLevel)(level); },
|
|
45
45
|
};
|
package/dist/src/FlinkRepo.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]) {
|
package/dist/src/FsUtils.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]) {
|
|
@@ -70,7 +70,7 @@ function readJsonFiles(globPattern) {
|
|
|
70
70
|
var files, readPromises;
|
|
71
71
|
return __generator(this, function (_a) {
|
|
72
72
|
switch (_a.label) {
|
|
73
|
-
case 0: return [4 /*yield*/, tiny_glob_1.default(globPattern)];
|
|
73
|
+
case 0: return [4 /*yield*/, (0, tiny_glob_1.default)(globPattern)];
|
|
74
74
|
case 1:
|
|
75
75
|
files = _a.sent();
|
|
76
76
|
readPromises = files.map(function (file) {
|
|
@@ -78,7 +78,7 @@ function readJsonFiles(globPattern) {
|
|
|
78
78
|
.readFile(file)
|
|
79
79
|
.then(function (data) { return JSON.parse(data.toString()); })
|
|
80
80
|
.catch(function (err) {
|
|
81
|
-
FlinkLog_1.log.error("Failed reading file "
|
|
81
|
+
FlinkLog_1.log.error("Failed reading file ".concat(file, ": ").concat(err));
|
|
82
82
|
return {};
|
|
83
83
|
});
|
|
84
84
|
});
|
|
@@ -99,7 +99,7 @@ function writeJsonFile(path, content, opts) {
|
|
|
99
99
|
if (!opts.ensureDir) return [3 /*break*/, 2];
|
|
100
100
|
i = path.lastIndexOf(path_1.sep);
|
|
101
101
|
if (!(i > 0 && i < path.length - 1)) return [3 /*break*/, 2];
|
|
102
|
-
return [4 /*yield*/, fs_extra_1.ensureDir(path.substr(0, i))];
|
|
102
|
+
return [4 /*yield*/, (0, fs_extra_1.ensureDir)(path.substr(0, i))];
|
|
103
103
|
case 1:
|
|
104
104
|
_a.sent();
|
|
105
105
|
_a.label = 2;
|
|
@@ -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,
|
|
51
|
-
|
|
52
|
-
|
|
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,13 +159,13 @@ 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] "
|
|
159
|
-
.getSourceFile()) === null || _a === void 0 ? void 0 : _a.getBaseName()
|
|
162
|
+
console.error("[ERROR] ".concat((_a = diag
|
|
163
|
+
.getSourceFile()) === null || _a === void 0 ? void 0 : _a.getBaseName(), " (line ").concat(diag.getLineNumber(), "):"), message);
|
|
160
164
|
hasError = true;
|
|
161
165
|
}
|
|
162
166
|
if (diag.getCategory() === ts_morph_1.DiagnosticCategory.Warning) {
|
|
163
|
-
console.warn("[WARNING] "
|
|
164
|
-
.getSourceFile()) === null || _b === void 0 ? void 0 : _b.getBaseName()
|
|
167
|
+
console.warn("[WARNING] ".concat((_b = diag
|
|
168
|
+
.getSourceFile()) === null || _b === void 0 ? void 0 : _b.getBaseName(), " (line ").concat(diag.getLineNumber(), "):"), message);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
if (hasError) {
|
|
@@ -185,7 +189,7 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
185
189
|
return __generator(this, function (_a) {
|
|
186
190
|
switch (_a.label) {
|
|
187
191
|
case 0:
|
|
188
|
-
generatedFile = this.createSourceFile(["generatedHandlers.ts"], "// Generated "
|
|
192
|
+
generatedFile = this.createSourceFile(["generatedHandlers.ts"], "// Generated ".concat(new Date(), "\nimport { autoRegisteredHandlers, HttpMethod } from \"@flink-app/flink\";\nexport const handlers = [];\nautoRegisteredHandlers.push(...handlers);\n "));
|
|
189
193
|
handlersArr = generatedFile
|
|
190
194
|
.getVariableDeclarationOrThrow("handlers")
|
|
191
195
|
.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
@@ -229,13 +233,13 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
229
233
|
return [3 /*break*/, 3];
|
|
230
234
|
}
|
|
231
235
|
isAutoRegister = this.isAutoRegisterableHandler(sf);
|
|
232
|
-
console.log("Detected handler "
|
|
236
|
+
console.log("Detected handler ".concat(sf.getBaseName(), " ").concat(!isAutoRegister ? "(requires manual registration)" : ""));
|
|
233
237
|
namespaceImport = sf.getBaseNameWithoutExtension().replace(/\./g, "_") + "_" + i;
|
|
234
238
|
imports.push({
|
|
235
239
|
namespaceImport: namespaceImport,
|
|
236
240
|
moduleSpecifier: generatedFile.getRelativePathAsModuleSpecifierTo(sf),
|
|
237
241
|
});
|
|
238
|
-
assumedHttpMethod = utils_1.getHttpMethodFromHandlerName(sf.getBaseName());
|
|
242
|
+
assumedHttpMethod = (0, utils_1.getHttpMethodFromHandlerName)(sf.getBaseName());
|
|
239
243
|
return [4 /*yield*/, this.extractSchemasFromHandlerSourceFile(sf)];
|
|
240
244
|
case 2:
|
|
241
245
|
schemaTypes = _b.sent();
|
|
@@ -246,34 +250,34 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
246
250
|
declarations: [
|
|
247
251
|
{
|
|
248
252
|
name: "__assumedHttpMethod",
|
|
249
|
-
initializer: "\""
|
|
253
|
+
initializer: "\"".concat(assumedHttpMethod || "", "\""),
|
|
250
254
|
},
|
|
251
255
|
{
|
|
252
256
|
name: "__file",
|
|
253
|
-
initializer: "\""
|
|
257
|
+
initializer: "\"".concat(sf.getBaseName(), "\""),
|
|
254
258
|
},
|
|
255
259
|
{
|
|
256
260
|
name: "__query",
|
|
257
|
-
initializer: "["
|
|
261
|
+
initializer: "[".concat(((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.queryMetadata) || [])
|
|
258
262
|
.map(function (_a) {
|
|
259
263
|
var description = _a.description, name = _a.name;
|
|
260
|
-
return "{description: \""
|
|
264
|
+
return "{description: \"".concat(description, "\", name: \"").concat(name, "\"}");
|
|
261
265
|
})
|
|
262
|
-
.join(",")
|
|
266
|
+
.join(","), "]"),
|
|
263
267
|
},
|
|
264
268
|
{
|
|
265
269
|
name: "__params",
|
|
266
|
-
initializer: "["
|
|
270
|
+
initializer: "[".concat(((schemaTypes === null || schemaTypes === void 0 ? void 0 : schemaTypes.paramsMetadata) || [])
|
|
267
271
|
.map(function (_a) {
|
|
268
272
|
var description = _a.description, name = _a.name;
|
|
269
|
-
return "{description: \""
|
|
273
|
+
return "{description: \"".concat(description, "\", name: \"").concat(name, "\"}");
|
|
270
274
|
})
|
|
271
|
-
.join(",")
|
|
275
|
+
.join(","), "]"),
|
|
272
276
|
},
|
|
273
277
|
],
|
|
274
278
|
});
|
|
275
279
|
if (isAutoRegister) {
|
|
276
|
-
handlersArr.insertElement(i, "{handler: "
|
|
280
|
+
handlersArr.insertElement(i, "{handler: ".concat(namespaceImport, ", assumedHttpMethod: ").concat(assumedHttpMethod ? "HttpMethod." + assumedHttpMethod : undefined, "}"));
|
|
277
281
|
i++;
|
|
278
282
|
}
|
|
279
283
|
if (schemaTypes) {
|
|
@@ -297,7 +301,7 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
297
301
|
return __generator(this, function (_b) {
|
|
298
302
|
switch (_b.label) {
|
|
299
303
|
case 0:
|
|
300
|
-
generatedFile = this.createSourceFile(["generatedRepos.ts"], "// Generated "
|
|
304
|
+
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 "));
|
|
301
305
|
reposArr = generatedFile
|
|
302
306
|
.getVariableDeclarationOrThrow("repos")
|
|
303
307
|
.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
@@ -308,12 +312,12 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
308
312
|
if (!sf.getFilePath().includes("src/repos/")) {
|
|
309
313
|
continue;
|
|
310
314
|
}
|
|
311
|
-
console.log("Detected repo "
|
|
315
|
+
console.log("Detected repo ".concat(sf.getBaseName()));
|
|
312
316
|
imports.push({
|
|
313
317
|
defaultImport: sf.getBaseNameWithoutExtension(),
|
|
314
318
|
moduleSpecifier: generatedFile.getRelativePathAsModuleSpecifierTo(sf),
|
|
315
319
|
});
|
|
316
|
-
reposArr.insertElement(i, "{collectionName: \""
|
|
320
|
+
reposArr.insertElement(i, "{collectionName: \"".concat((0, utils_1.getCollectionNameForRepo)(sf.getBaseName()), "\", repoInstanceName: \"").concat((0, utils_1.getRepoInstanceName)(sf.getBaseName()), "\", Repo: ").concat(sf.getBaseNameWithoutExtension(), "}"));
|
|
317
321
|
i++;
|
|
318
322
|
}
|
|
319
323
|
generatedFile.addImportDeclarations(imports);
|
|
@@ -342,10 +346,10 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
342
346
|
if (!this.project.getSourceFile(function (sf) {
|
|
343
347
|
return sf.getFilePath().endsWith(appEntryScript);
|
|
344
348
|
})) {
|
|
345
|
-
console.error("Cannot find entry script '"
|
|
349
|
+
console.error("Cannot find entry script '".concat(appEntryScript, "'"));
|
|
346
350
|
return [2 /*return*/, process.exit(1)];
|
|
347
351
|
}
|
|
348
|
-
sf = this.createSourceFile(["start.ts"], "// Generated "
|
|
352
|
+
sf = this.createSourceFile(["start.ts"], "// Generated ".concat(new Date(), "\nimport \"./generatedHandlers\";\nimport \"./generatedRepos\";\nimport \"..").concat(appEntryScript.replace(/\.ts/g, ""), "\";\n"));
|
|
349
353
|
return [4 /*yield*/, sf.save()];
|
|
350
354
|
case 1:
|
|
351
355
|
_a.sent();
|
|
@@ -355,7 +359,7 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
355
359
|
});
|
|
356
360
|
};
|
|
357
361
|
TypeScriptCompiler.prototype.createSourceFile = function (filename, contents) {
|
|
358
|
-
return this.project.createSourceFile(path_1.join.apply(void 0, __spreadArray([this.cwd, ".flink"], filename)), contents, {
|
|
362
|
+
return this.project.createSourceFile(path_1.join.apply(void 0, __spreadArray([this.cwd, ".flink"], filename, false)), contents, {
|
|
359
363
|
overwrite: true,
|
|
360
364
|
});
|
|
361
365
|
};
|
|
@@ -387,13 +391,13 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
387
391
|
return __awaiter(this, void 0, void 0, function () {
|
|
388
392
|
var defaultExport, handlerTypeRef;
|
|
389
393
|
return __generator(this, function (_a) {
|
|
390
|
-
defaultExport = TypeScriptUtils_1.getDefaultExport(handlerSourceFile);
|
|
394
|
+
defaultExport = (0, TypeScriptUtils_1.getDefaultExport)(handlerSourceFile);
|
|
391
395
|
if (defaultExport) {
|
|
392
396
|
handlerTypeRef = defaultExport.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.TypeReference);
|
|
393
397
|
return [2 /*return*/, this.extractSchemaTypeFromHandler(handlerTypeRef)];
|
|
394
398
|
}
|
|
395
399
|
else {
|
|
396
|
-
console.warn("Handler "
|
|
400
|
+
console.warn("Handler ".concat(handlerSourceFile.getBaseName(), " is missing default exported handler function"));
|
|
397
401
|
}
|
|
398
402
|
return [2 /*return*/];
|
|
399
403
|
});
|
|
@@ -411,25 +415,25 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
411
415
|
.getBaseNameWithoutExtension()
|
|
412
416
|
.replace(/\./g, "_");
|
|
413
417
|
generatedSchemaInterfaceStr = "";
|
|
414
|
-
schemaInterfaceName = handlerFileName
|
|
418
|
+
schemaInterfaceName = "".concat(handlerFileName, "_").concat(suffix);
|
|
415
419
|
if (schema.isInterface()) {
|
|
416
420
|
schemaSymbol = schema.getSymbolOrThrow();
|
|
417
|
-
interfaceName = TypeScriptUtils_1.getInterfaceName(schemaSymbol);
|
|
421
|
+
interfaceName = (0, TypeScriptUtils_1.getInterfaceName)(schemaSymbol);
|
|
418
422
|
declaration = schemaSymbol.getDeclarations()[0];
|
|
419
423
|
if (declaration.getSourceFile() === handlerFile) {
|
|
420
424
|
// Interface is declared within handler file
|
|
421
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
425
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " { \n ").concat(schema
|
|
422
426
|
.getProperties()
|
|
423
427
|
.map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
|
|
424
|
-
.join("\n")
|
|
425
|
-
for (_i = 0, _a = TypeScriptUtils_1.getTypesToImport(declaration); _i < _a.length; _i++) {
|
|
428
|
+
.join("\n"), "\n }");
|
|
429
|
+
for (_i = 0, _a = (0, TypeScriptUtils_1.getTypesToImport)(declaration); _i < _a.length; _i++) {
|
|
426
430
|
typeToImport = _a[_i];
|
|
427
431
|
this.tsSchemasSymbolsToImports.push(typeToImport.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
|
|
428
432
|
}
|
|
429
433
|
}
|
|
430
434
|
else {
|
|
431
435
|
// Interface is imported from other file
|
|
432
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
436
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends ").concat(interfaceName, " {}");
|
|
433
437
|
this.tsSchemasSymbolsToImports.push(schemaSymbol);
|
|
434
438
|
}
|
|
435
439
|
}
|
|
@@ -439,7 +443,7 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
439
443
|
interfaceName = schemaSymbol.getEscapedName();
|
|
440
444
|
declaration = schemaSymbol.getDeclarations()[0];
|
|
441
445
|
if (declaration.getSourceFile() !== handlerFile) {
|
|
442
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
446
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<").concat(interfaceName, "> {}");
|
|
443
447
|
this.tsSchemasSymbolsToImports.push(schemaSymbol);
|
|
444
448
|
}
|
|
445
449
|
else {
|
|
@@ -448,12 +452,12 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
448
452
|
.getProperties()
|
|
449
453
|
.map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
|
|
450
454
|
.join(" ");
|
|
451
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
455
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<{").concat(props, "}> {}");
|
|
452
456
|
}
|
|
453
457
|
else {
|
|
454
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
458
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " extends Array<").concat(declaration.getText(), "> {}");
|
|
455
459
|
}
|
|
456
|
-
for (_b = 0, _c = TypeScriptUtils_1.getTypesToImport(declaration); _b < _c.length; _b++) {
|
|
460
|
+
for (_b = 0, _c = (0, TypeScriptUtils_1.getTypesToImport)(declaration); _b < _c.length; _b++) {
|
|
457
461
|
typeToImport = _c[_b];
|
|
458
462
|
this.tsSchemasSymbolsToImports.push(typeToImport.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
|
|
459
463
|
}
|
|
@@ -469,10 +473,10 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
469
473
|
typeRefIdentifiers.forEach(function (tr) {
|
|
470
474
|
_this.tsSchemasSymbolsToImports.push(tr.getSymbolOrThrow().getDeclaredType().getSymbolOrThrow());
|
|
471
475
|
});
|
|
472
|
-
generatedSchemaInterfaceStr = "export interface "
|
|
476
|
+
generatedSchemaInterfaceStr = "export interface ".concat(schemaInterfaceName, " { ").concat(schema
|
|
473
477
|
.getProperties()
|
|
474
478
|
.map(function (p) { return p.getValueDeclarationOrThrow().getText(); })
|
|
475
|
-
.join("\n")
|
|
479
|
+
.join("\n"), " }");
|
|
476
480
|
}
|
|
477
481
|
else {
|
|
478
482
|
console.log("[WARN] Unknown schema type", schema.getText());
|
|
@@ -490,8 +494,8 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
490
494
|
// expose: "",
|
|
491
495
|
// topRef: false,
|
|
492
496
|
};
|
|
493
|
-
var formatter = ts_json_schema_generator_1.createFormatter(conf);
|
|
494
|
-
var parser = ts_json_schema_generator_1.createParser(this.project.getProgram().compilerObject, conf);
|
|
497
|
+
var formatter = (0, ts_json_schema_generator_1.createFormatter)(conf);
|
|
498
|
+
var parser = (0, ts_json_schema_generator_1.createParser)(this.project.getProgram().compilerObject, conf);
|
|
495
499
|
var generator = new ts_json_schema_generator_1.SchemaGenerator(this.project.getProgram().compilerObject, parser, formatter, conf);
|
|
496
500
|
return generator;
|
|
497
501
|
};
|
|
@@ -521,8 +525,8 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
521
525
|
$ref: "#/definitions/Schemas",
|
|
522
526
|
definitions: {},
|
|
523
527
|
});
|
|
524
|
-
filePath = path_1.join(this.cwd, ".flink", "schemas", "schemas.json");
|
|
525
|
-
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)];
|
|
526
530
|
case 1:
|
|
527
531
|
_b.sent();
|
|
528
532
|
this.project.addSourceFileAtPath(filePath);
|
|
@@ -563,16 +567,16 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
563
567
|
query = handlerTypeArgs[3];
|
|
564
568
|
}
|
|
565
569
|
else {
|
|
566
|
-
throw new Error("Unknown handler type "
|
|
570
|
+
throw new Error("Unknown handler type ".concat(handlerType, " in ").concat(handlerTypeReference
|
|
567
571
|
.getSourceFile()
|
|
568
|
-
.getBaseName()
|
|
572
|
+
.getBaseName(), " - should be Handler or GetHandler"));
|
|
569
573
|
}
|
|
570
574
|
sf = handlerTypeReference.getSourceFile();
|
|
571
575
|
createReqSchemaPromise = reqSchema
|
|
572
|
-
? this.saveIntermediateTsSchema(reqSchema, sf, handlerTypeReference.getStartLineNumber()
|
|
576
|
+
? this.saveIntermediateTsSchema(reqSchema, sf, "".concat(handlerTypeReference.getStartLineNumber(), "_ReqSchema"))
|
|
573
577
|
: Promise.resolve("");
|
|
574
578
|
createResSchemaPromise = resSchema
|
|
575
|
-
? this.saveIntermediateTsSchema(resSchema, sf, handlerTypeReference.getStartLineNumber()
|
|
579
|
+
? this.saveIntermediateTsSchema(resSchema, sf, "".concat(handlerTypeReference.getStartLineNumber(), "_ResSchema"))
|
|
576
580
|
: Promise.resolve("");
|
|
577
581
|
return [4 /*yield*/, Promise.all([
|
|
578
582
|
createReqSchemaPromise,
|
|
@@ -583,8 +587,8 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
583
587
|
return [2 /*return*/, {
|
|
584
588
|
reqSchemaType: reqSchemaType,
|
|
585
589
|
resSchemaType: resSchemaType,
|
|
586
|
-
queryMetadata: TypeScriptUtils_1.getTypeMetadata(query),
|
|
587
|
-
paramsMetadata: TypeScriptUtils_1.getTypeMetadata(params),
|
|
590
|
+
queryMetadata: (0, TypeScriptUtils_1.getTypeMetadata)(query),
|
|
591
|
+
paramsMetadata: (0, TypeScriptUtils_1.getTypeMetadata)(params),
|
|
588
592
|
}];
|
|
589
593
|
}
|
|
590
594
|
});
|
|
@@ -598,8 +602,8 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
598
602
|
return __awaiter(this, void 0, void 0, function () {
|
|
599
603
|
var schemaSourceFile;
|
|
600
604
|
return __generator(this, function (_a) {
|
|
601
|
-
schemaSourceFile = this.createSourceFile(["schemas", "schemas.ts"], "// Generated "
|
|
602
|
-
TypeScriptUtils_1.addImports(schemaSourceFile, this.tsSchemasSymbolsToImports);
|
|
605
|
+
schemaSourceFile = this.createSourceFile(["schemas", "schemas.ts"], "// Generated ".concat(new Date(), "\n").concat(this.parsedTsSchemas.join("\n\n")));
|
|
606
|
+
(0, TypeScriptUtils_1.addImports)(schemaSourceFile, this.tsSchemasSymbolsToImports);
|
|
603
607
|
return [2 /*return*/, schemaSourceFile.save()];
|
|
604
608
|
});
|
|
605
609
|
});
|
|
@@ -631,18 +635,18 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
631
635
|
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
|
|
632
636
|
var _a = handlers_1[_i], sourceFile = _a.sourceFile, reqSchemaType = _a.reqSchemaType, resSchemaType = _a.resSchemaType;
|
|
633
637
|
if (reqSchemaType && !jsonSchemaDefs[reqSchemaType]) {
|
|
634
|
-
console.error("Handler "
|
|
638
|
+
console.error("Handler ".concat(sourceFile.getBaseName, " has request schema\u00A0(").concat(reqSchemaType, ") defined, but JSON schema has been generated"));
|
|
635
639
|
continue;
|
|
636
640
|
}
|
|
637
641
|
if (resSchemaType && !jsonSchemaDefs[resSchemaType]) {
|
|
638
|
-
console.error("Handler "
|
|
642
|
+
console.error("Handler ".concat(sourceFile.getBaseName, " has response schema\u00A0(").concat(resSchemaType, ") defined, but JSON schema has been generated"));
|
|
639
643
|
continue;
|
|
640
644
|
}
|
|
641
645
|
var reqJsonSchema = JSON.stringify(reqSchemaType
|
|
642
|
-
? utils_1.deRefSchema(jsonSchemaDefs[reqSchemaType], jsonSchemas)
|
|
646
|
+
? (0, utils_1.deRefSchema)(jsonSchemaDefs[reqSchemaType], jsonSchemas)
|
|
643
647
|
: undefined);
|
|
644
648
|
var resJsonSchema = JSON.stringify(resSchemaType
|
|
645
|
-
? utils_1.deRefSchema(jsonSchemaDefs[resSchemaType], jsonSchemas)
|
|
649
|
+
? (0, utils_1.deRefSchema)(jsonSchemaDefs[resSchemaType], jsonSchemas)
|
|
646
650
|
: undefined);
|
|
647
651
|
sourceFile.addVariableStatement({
|
|
648
652
|
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
@@ -651,7 +655,7 @@ var TypeScriptCompiler = /** @class */ (function () {
|
|
|
651
655
|
{
|
|
652
656
|
name: "__schemas",
|
|
653
657
|
type: "any",
|
|
654
|
-
initializer: "{ reqSchema: "
|
|
658
|
+
initializer: "{ reqSchema: ".concat(reqJsonSchema, ", resSchema: ").concat(resJsonSchema, " }"),
|
|
655
659
|
},
|
|
656
660
|
],
|
|
657
661
|
});
|
|
@@ -183,7 +183,7 @@ function getTypeMetadata(type) {
|
|
|
183
183
|
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertySignature)
|
|
184
184
|
.map(function (prop) {
|
|
185
185
|
var _a;
|
|
186
|
-
var description = utils_1.getJsDocComment(((_a = prop.getLeadingCommentRanges()[0]) === null || _a === void 0 ? void 0 : _a.getText()) || "");
|
|
186
|
+
var description = (0, utils_1.getJsDocComment)(((_a = prop.getLeadingCommentRanges()[0]) === null || _a === void 0 ? void 0 : _a.getText()) || "");
|
|
187
187
|
return {
|
|
188
188
|
description: description,
|
|
189
189
|
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.
|
|
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: "
|
|
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
|
})];
|
|
@@ -159,7 +159,7 @@ function deRefSchema(schemaToDeRef, jsonSchemas) {
|
|
|
159
159
|
schemaToDeRef.items = deRefSchema(refedSchema, jsonSchemas);
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
|
-
console.warn("Failed to find deref "
|
|
162
|
+
console.warn("Failed to find deref ".concat(schemaToDeRef.$ref));
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
@@ -179,7 +179,7 @@ function deRefSchema(schemaToDeRef, jsonSchemas) {
|
|
|
179
179
|
schemaToDeRef.properties[k] = deRefSchema(refedSchema, jsonSchemas);
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
|
-
console.warn("Failed to find deref "
|
|
182
|
+
console.warn("Failed to find deref ".concat(prop.$ref));
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
else if (prop.type === "array" && prop.items.$ref) {
|
|
@@ -189,7 +189,7 @@ function deRefSchema(schemaToDeRef, jsonSchemas) {
|
|
|
189
189
|
schemaToDeRef.properties[k].items = deRefSchema(refedSchema, jsonSchemas);
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
|
-
console.warn("Failed to find deref "
|
|
192
|
+
console.warn("Failed to find deref ".concat(prop.$ref));
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
else if (prop.type === "object" || prop.type === "array") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/flink",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"rimraf": "^3.0.2",
|
|
63
63
|
"ts-node": "^9.1.1"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "87a2e1bef163645b98f9b5dd1b4add1c64e525fd"
|
|
66
66
|
}
|