@flink-app/flink 0.3.7 → 0.3.8

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 (28) hide show
  1. package/dist/cli/generate-schema.d.ts +2 -0
  2. package/{spec/mock-project/dist/src/handlers/PostLogin.js → dist/cli/generate-schema.js} +14 -18
  3. package/dist/cli/generate.d.ts +2 -0
  4. package/{spec/mock-project/dist/src/handlers/GetCarWithOmitSchema.js → dist/cli/generate.js} +14 -19
  5. package/dist/src/FlinkTsParser.d.ts +2 -0
  6. package/dist/src/FlinkTsParser.js +219 -0
  7. package/dist/src/FlinkTsUtils.d.ts +16 -0
  8. package/dist/src/FlinkTsUtils.js +118 -0
  9. package/package.json +2 -2
  10. package/.vscode/notes.txt +0 -11
  11. package/spec/mock-project/dist/src/handlers/GetCar.js +0 -59
  12. package/spec/mock-project/dist/src/handlers/GetCar2.js +0 -61
  13. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +0 -55
  14. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +0 -55
  15. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +0 -55
  16. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +0 -57
  17. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +0 -57
  18. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +0 -60
  19. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +0 -60
  20. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +0 -56
  21. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +0 -58
  22. package/spec/mock-project/dist/src/handlers/PostCar.js +0 -57
  23. package/spec/mock-project/dist/src/handlers/PutCar.js +0 -57
  24. package/spec/mock-project/dist/src/index.js +0 -79
  25. package/spec/mock-project/dist/src/repos/CarRepo.js +0 -26
  26. package/spec/mock-project/dist/src/schemas/Car.js +0 -2
  27. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +0 -2
  28. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +0 -2
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function run(): Promise<void>;
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -36,23 +37,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
37
  }
37
38
  };
38
39
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.Route = void 0;
40
- exports.Route = {
41
- path: "/login",
42
- };
43
- var PostLogin = function (_a) {
44
- var ctx = _a.ctx, req = _a.req;
45
- return __awaiter(void 0, void 0, void 0, function () {
46
- return __generator(this, function (_b) {
47
- return [2 /*return*/, {
48
- data: {},
49
- headers: {
50
- "x-test": "hello world",
51
- },
52
- }];
40
+ exports.run = void 0;
41
+ var FlinkTsParser_1 = require("../src/FlinkTsParser");
42
+ function run() {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0: return [4 /*yield*/, FlinkTsParser_1.parseAndWriteSchemas()];
47
+ case 1:
48
+ _a.sent();
49
+ return [2 /*return*/];
50
+ }
53
51
  });
54
52
  });
55
- };
56
- exports.default = PostLogin;
57
- exports.__assumedHttpMethod = "post", exports.__file = "PostLogin.ts", exports.__query = [], exports.__params = [];
58
- exports.__schemas = { reqSchema: undefined, resSchema: undefined };
53
+ }
54
+ exports.run = run;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function run(): Promise<void>;
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -36,24 +37,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
37
  }
37
38
  };
38
39
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.Route = void 0;
40
- exports.Route = {
41
- path: "/car-with-omit-schema",
42
- };
43
- // interface CarWithoutId extends Omit<Car, "_id"> {}
44
- var GetCarWithOmitSchema = function (_a) {
45
- var ctx = _a.ctx, req = _a.req;
46
- return __awaiter(void 0, void 0, void 0, function () {
47
- return __generator(this, function (_b) {
48
- return [2 /*return*/, {
49
- data: {
50
- model: "Volvo",
51
- foo: 1,
52
- },
53
- }];
40
+ exports.run = void 0;
41
+ var FlinkTsParser_1 = require("../src/FlinkTsParser");
42
+ function run() {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0: return [4 /*yield*/, FlinkTsParser_1.parseSourceFiles()];
47
+ case 1:
48
+ _a.sent();
49
+ return [2 /*return*/];
50
+ }
54
51
  });
55
52
  });
56
- };
57
- exports.default = GetCarWithOmitSchema;
58
- exports.__assumedHttpMethod = "get", exports.__file = "GetCarWithOmitSchema.ts", exports.__query = [], exports.__params = [];
59
- exports.__schemas = { reqSchema: undefined, resSchema: undefined };
53
+ }
54
+ exports.run = run;
@@ -0,0 +1,2 @@
1
+ export declare function parseSourceFiles(appRoot?: string): Promise<void>;
2
+ export declare function parseAndWriteSchemas(appRoot?: string): Promise<void>;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (_) try {
48
+ 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;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ var __importDefault = (this && this.__importDefault) || function (mod) {
69
+ return (mod && mod.__esModule) ? mod : { "default": mod };
70
+ };
71
+ Object.defineProperty(exports, "__esModule", { value: true });
72
+ exports.parseAndWriteSchemas = exports.parseSourceFiles = void 0;
73
+ var fs_1 = require("fs");
74
+ var mkdirp_1 = __importDefault(require("mkdirp"));
75
+ var path_1 = require("path");
76
+ var ts_morph_1 = require("ts-morph");
77
+ var TJS = __importStar(require("typescript-json-schema"));
78
+ var FlinkLog_1 = require("./FlinkLog");
79
+ var FlinkTsUtils_1 = require("./FlinkTsUtils");
80
+ var utils_1 = require("./utils");
81
+ var flinkDir = ".flink";
82
+ function parseSourceFiles(appRoot) {
83
+ if (appRoot === void 0) { appRoot = "./"; }
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var schemas, handlers;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0: return [4 /*yield*/, parseSchemas(appRoot)];
89
+ case 1:
90
+ schemas = _a.sent();
91
+ return [4 /*yield*/, parseHandlers(appRoot, schemas || {})];
92
+ case 2:
93
+ handlers = _a.sent();
94
+ return [4 /*yield*/, writeParsedHandlers(handlers)];
95
+ case 3:
96
+ _a.sent();
97
+ return [2 /*return*/];
98
+ }
99
+ });
100
+ });
101
+ }
102
+ exports.parseSourceFiles = parseSourceFiles;
103
+ function parseAndWriteSchemas(appRoot) {
104
+ if (appRoot === void 0) { appRoot = "./"; }
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var schemas;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, parseSchemas(appRoot)];
110
+ case 1:
111
+ schemas = _a.sent();
112
+ return [4 /*yield*/, writeParsedSchemas(schemas)];
113
+ case 2:
114
+ _a.sent();
115
+ return [2 /*return*/];
116
+ }
117
+ });
118
+ });
119
+ }
120
+ exports.parseAndWriteSchemas = parseAndWriteSchemas;
121
+ function parseHandlers(appRoot, schemas) {
122
+ return __awaiter(this, void 0, void 0, function () {
123
+ var handlers, tsProject, handlerConfigs;
124
+ return __generator(this, function (_a) {
125
+ switch (_a.label) {
126
+ case 0: return [4 /*yield*/, utils_1.getHandlerFiles(appRoot)];
127
+ case 1:
128
+ handlers = _a.sent();
129
+ if (!handlers.length) {
130
+ return [2 /*return*/];
131
+ }
132
+ tsProject = new ts_morph_1.Project({
133
+ compilerOptions: {
134
+ esModuleInterop: true,
135
+ skipLibCheck: true, // Mainly due to https://github.com/DefinitelyTyped/DefinitelyTyped/issues/46639
136
+ },
137
+ });
138
+ tsProject.addSourceFilesAtPaths(handlers);
139
+ handlerConfigs = tsProject
140
+ .getSourceFiles()
141
+ .map(function (handlerFile) {
142
+ var _a = handlerFile
143
+ .getFilePath()
144
+ .split("src/handlers/"), handlerRelativeName = _a[1];
145
+ var schema = FlinkTsUtils_1.getSchemaFromHandlerSourceFile(handlerFile);
146
+ return {
147
+ schema: {
148
+ reqSchema: schema.reqSchema ? schemas[schema.reqSchema] : undefined,
149
+ resSchema: schema.resSchema ? schemas[schema.resSchema] : undefined,
150
+ },
151
+ routeProps: __assign({}, FlinkTsUtils_1.getRoutePropsFromHandlerSourceFile(handlerFile)),
152
+ origin: handlerRelativeName,
153
+ };
154
+ });
155
+ return [2 /*return*/, handlerConfigs];
156
+ }
157
+ });
158
+ });
159
+ }
160
+ function parseSchemas(appRoot) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var schemas, programFiles, settings, schemaProgram, generatedSchemas, schemaNames;
163
+ return __generator(this, function (_a) {
164
+ switch (_a.label) {
165
+ case 0: return [4 /*yield*/, utils_1.getSchemaFiles(appRoot)];
166
+ case 1:
167
+ schemas = _a.sent();
168
+ if (!schemas.length) {
169
+ // log.warn("No schemas nor handlers found");
170
+ return [2 /*return*/];
171
+ }
172
+ programFiles = [];
173
+ if (schemas.length) {
174
+ programFiles.push.apply(programFiles, schemas);
175
+ }
176
+ settings = {
177
+ required: true,
178
+ ref: false,
179
+ noExtraProps: true,
180
+ };
181
+ schemaProgram = TJS.getProgramFromFiles(schemas, {
182
+ esModuleInterop: true,
183
+ skipLibCheck: true, // Mainly due to https://github.com/DefinitelyTyped/DefinitelyTyped/issues/46639
184
+ }, process.cwd());
185
+ generatedSchemas = TJS.generateSchema(schemaProgram, "*", settings);
186
+ if (generatedSchemas && generatedSchemas.definitions) {
187
+ schemaNames = Object.keys(generatedSchemas.definitions);
188
+ FlinkLog_1.log.info("Generated " + schemaNames.length + " schemas");
189
+ return [2 /*return*/, generatedSchemas.definitions];
190
+ }
191
+ return [2 /*return*/];
192
+ }
193
+ });
194
+ });
195
+ }
196
+ function writeParsedHandlers(handlers) {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0: return [4 /*yield*/, mkdirp_1.default(flinkDir)];
201
+ case 1:
202
+ _a.sent();
203
+ return [2 /*return*/, fs_1.promises.writeFile(path_1.join(flinkDir, "handlers.json"), JSON.stringify(handlers, null, 2))];
204
+ }
205
+ });
206
+ });
207
+ }
208
+ function writeParsedSchemas(schemas) {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0: return [4 /*yield*/, mkdirp_1.default(flinkDir)];
213
+ case 1:
214
+ _a.sent();
215
+ return [2 /*return*/, fs_1.promises.writeFile(path_1.join(flinkDir, "schemas.json"), JSON.stringify(schemas, null, 2))];
216
+ }
217
+ });
218
+ });
219
+ }
@@ -0,0 +1,16 @@
1
+ import { SourceFile } from "ts-morph";
2
+ import { RouteProps } from "./FlinkHttpHandler";
3
+ declare type ReqResSchemas = {
4
+ reqSchema: string | undefined;
5
+ resSchema: string | undefined;
6
+ };
7
+ /**
8
+ * Derives schema that is part of handlers generic type argument
9
+ * by inspecting nodes in handler source file.
10
+ */
11
+ export declare function getSchemaFromHandlerSourceFile(file: SourceFile): ReqResSchemas;
12
+ /**
13
+ * Reads Route props from handler source file.
14
+ */
15
+ export declare function getRoutePropsFromHandlerSourceFile(file: SourceFile): RouteProps;
16
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRoutePropsFromHandlerSourceFile = exports.getSchemaFromHandlerSourceFile = void 0;
4
+ var path_1 = require("path");
5
+ var ts_morph_1 = require("ts-morph");
6
+ var FlinkHttpHandler_1 = require("./FlinkHttpHandler");
7
+ var FlinkLog_1 = require("./FlinkLog");
8
+ /**
9
+ * Derives schema that is part of handlers generic type argument
10
+ * by inspecting nodes in handler source file.
11
+ */
12
+ function getSchemaFromHandlerSourceFile(file) {
13
+ var _a, _b;
14
+ var handlerFnExport = file
15
+ .getDefaultExportSymbolOrThrow()
16
+ .getDeclarations()[0];
17
+ var handlerFnType = handlerFnExport
18
+ .getSymbolOrThrow()
19
+ .getTypeAtLocation(handlerFnExport);
20
+ var isHandlerWithoutReqBody = !handlerFnType
21
+ .getText()
22
+ .includes(".Handler<");
23
+ var typeArgs = handlerFnType.getAliasTypeArguments();
24
+ var reqSchemaArg = !isHandlerWithoutReqBody ? typeArgs[1] : undefined;
25
+ var resSchemaArg = typeArgs[isHandlerWithoutReqBody ? 1 : 2];
26
+ if (reqSchemaArg && !isValidSchemaType(reqSchemaArg)) {
27
+ throw new Error("Handler " + file.compilerNode.fileName + " contains invalid request schema. Schema must be an interface or type that resides in 'src/schemas/' directory. Instead detected type '" + reqSchemaArg.getText() + "'");
28
+ }
29
+ if (resSchemaArg && !isValidSchemaType(resSchemaArg)) {
30
+ throw new Error("Handler " + file.compilerNode.fileName + " contains invalid response schema. Schema must be an interface or type that resides in 'src/schemas/' directory. Instead detected type '" + resSchemaArg.getText() + "'");
31
+ }
32
+ return {
33
+ reqSchema: (_a = reqSchemaArg === null || reqSchemaArg === void 0 ? void 0 : reqSchemaArg.getSymbol()) === null || _a === void 0 ? void 0 : _a.getName(),
34
+ resSchema: (_b = resSchemaArg === null || resSchemaArg === void 0 ? void 0 : resSchemaArg.getSymbol()) === null || _b === void 0 ? void 0 : _b.getName(),
35
+ };
36
+ }
37
+ exports.getSchemaFromHandlerSourceFile = getSchemaFromHandlerSourceFile;
38
+ function isValidSchemaType(type) {
39
+ return type.isAny() || type.isInterface();
40
+ }
41
+ /**
42
+ * Reads Route props from handler source file.
43
+ */
44
+ function getRoutePropsFromHandlerSourceFile(file) {
45
+ // Inspiration: https://stackoverflow.com/a/61218889
46
+ var objectLiteral = file
47
+ .getVariableDeclarationOrThrow("Route")
48
+ .getInitializerIfKindOrThrow(ts_morph_1.ts.SyntaxKind.ObjectLiteralExpression)
49
+ .getProperties();
50
+ var routeProps = {};
51
+ objectLiteral.forEach(function (ol) {
52
+ if (ts_morph_1.Node.isShorthandPropertyAssignment(ol)) {
53
+ // TODO: Have not yet figured out how to do this
54
+ throw new Error("Short hand property assignments in handler Routes is not supported at the moment");
55
+ }
56
+ else if (ts_morph_1.Node.isPropertyAssignment(ol)) {
57
+ var initializer = ol.getInitializerOrThrow();
58
+ if (ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
59
+ var val = void 0;
60
+ if (ol.getType().isEnumLiteral()) {
61
+ val = ol.getType().getLiteralValue();
62
+ }
63
+ else {
64
+ // TODO
65
+ }
66
+ // @ts-ignore
67
+ routeProps[ol.getName()] = val;
68
+ }
69
+ else if ([
70
+ ts_morph_1.ts.SyntaxKind.StringLiteral,
71
+ ts_morph_1.ts.SyntaxKind.TrueKeyword,
72
+ ts_morph_1.ts.SyntaxKind.FalseKeyword,
73
+ ].includes(initializer.getKind())) {
74
+ // @ts-ignore
75
+ routeProps[ol.getName()] = initializer.getLiteralValue();
76
+ }
77
+ else if (ts_morph_1.Node.isArrayLiteralExpression(initializer)) {
78
+ // @ts-ignore
79
+ routeProps[ol.getName()] = initializer
80
+ .getElements()
81
+ .map(function (el) { return el.getLiteralText(); });
82
+ }
83
+ else {
84
+ FlinkLog_1.log.warn("Unhandled route props property: " + ol.getKindName());
85
+ }
86
+ }
87
+ });
88
+ if (!routeProps.path) {
89
+ throw new Error("Handler " + file.getBaseName() + " Props is missing 'path'");
90
+ }
91
+ if (!routeProps.method) {
92
+ routeProps.method = getHttpMethodFromHandlerName(file.getBaseName());
93
+ if (!routeProps.method) {
94
+ FlinkLog_1.log.error("Handler " + file.getBaseName() + " should either be prefixed with HTTP method in its filename, such as 'PostFoo', or have 'method' set in RouteProps");
95
+ }
96
+ }
97
+ return routeProps;
98
+ }
99
+ exports.getRoutePropsFromHandlerSourceFile = getRoutePropsFromHandlerSourceFile;
100
+ /**
101
+ * Get http method from props or convention based on file name
102
+ * if it starts with i.e "GetFoo"
103
+ */
104
+ function getHttpMethodFromHandlerName(handlerFilename) {
105
+ if (handlerFilename.includes(path_1.sep)) {
106
+ var split = handlerFilename.split(path_1.sep);
107
+ handlerFilename = split[split.length - 1];
108
+ }
109
+ handlerFilename = handlerFilename.toLocaleLowerCase();
110
+ if (handlerFilename.startsWith(FlinkHttpHandler_1.HttpMethod.get))
111
+ return FlinkHttpHandler_1.HttpMethod.get;
112
+ if (handlerFilename.startsWith(FlinkHttpHandler_1.HttpMethod.post))
113
+ return FlinkHttpHandler_1.HttpMethod.post;
114
+ if (handlerFilename.startsWith(FlinkHttpHandler_1.HttpMethod.put))
115
+ return FlinkHttpHandler_1.HttpMethod.put;
116
+ if (handlerFilename.startsWith(FlinkHttpHandler_1.HttpMethod.delete))
117
+ return FlinkHttpHandler_1.HttpMethod.delete;
118
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
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": "e61be35839aa8d459dc07613d9bfa919570361f2"
65
+ "gitHead": "9c45e69ffff300482f9945074c5ecc3e1d661467"
66
66
  }
package/.vscode/notes.txt DELETED
@@ -1,11 +0,0 @@
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
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
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
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.Route = void 0;
40
- var flink_1 = require("@flink-app/flink");
41
- exports.Route = {
42
- path: "/car/:id",
43
- method: flink_1.HttpMethod.get,
44
- };
45
- var GetCar = function (_a) {
46
- var ctx = _a.ctx, req = _a.req;
47
- return __awaiter(void 0, void 0, void 0, function () {
48
- return __generator(this, function (_b) {
49
- return [2 /*return*/, {
50
- data: {
51
- model: "Volvo",
52
- },
53
- }];
54
- });
55
- });
56
- };
57
- exports.default = GetCar;
58
- exports.__assumedHttpMethod = "get", exports.__file = "GetCar.ts", exports.__query = [{ description: "For pagination", name: "page" }], exports.__params = [{ description: "", name: "id" }];
59
- exports.__schemas = { reqSchema: undefined, resSchema: { "type": "object", "additionalProperties": false, "properties": { "model": { "type": "string" }, "metadata": { "type": "object", "properties": { "created": { "type": "string", "format": "date-time" } }, "additionalProperties": false } }, "required": ["model"] } };
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
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
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.Route = void 0;
40
- var flink_1 = require("@flink-app/flink");
41
- exports.Route = {
42
- path: "/car2",
43
- method: flink_1.HttpMethod.get,
44
- permissions: "*",
45
- };
46
- var GetCar2 = function (_a) {
47
- var ctx = _a.ctx, req = _a.req;
48
- return __awaiter(void 0, void 0, void 0, function () {
49
- return __generator(this, function (_b) {
50
- return [2 /*return*/, {
51
- data: {
52
- model: { name: "Mercedes" },
53
- engine: { name: "Rolls Royce" },
54
- },
55
- }];
56
- });
57
- });
58
- };
59
- exports.default = GetCar2;
60
- exports.__assumedHttpMethod = "get", exports.__file = "GetCar2.ts", exports.__query = [], exports.__params = [];
61
- exports.__schemas = { reqSchema: undefined, resSchema: { "type": "object", "properties": { "model": { "type": "object", "properties": { "name": { "type": "string" }, "metadata": { "type": "object", "properties": { "created": { "type": "string", "format": "date-time" } }, "additionalProperties": false } }, "required": ["name"], "additionalProperties": false }, "engine": { "type": "object", "properties": { "name": { "type": "string" } }, "required": ["name"], "additionalProperties": false } }, "required": ["model", "engine"], "additionalProperties": false } };