@flink-app/flink 0.12.1-alpha.0 → 0.12.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/bin/flink.ts +6 -13
  2. package/dist/bin/flink.js +3 -10
  3. package/dist/cli/build.js +3 -3
  4. package/dist/cli/clean.js +2 -2
  5. package/dist/cli/cli-utils.js +1 -1
  6. package/dist/cli/run.js +2 -2
  7. package/dist/src/FlinkApp.d.ts +1 -1
  8. package/dist/src/FlinkApp.js +77 -77
  9. package/dist/src/FlinkErrors.d.ts +1 -1
  10. package/dist/src/FlinkErrors.js +5 -5
  11. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  12. package/dist/src/FlinkHttpHandler.js +1 -1
  13. package/dist/src/FlinkJob.d.ts +2 -2
  14. package/dist/src/FlinkLog.d.ts +2 -2
  15. package/dist/src/FlinkRepo.d.ts +6 -2
  16. package/dist/src/FlinkRepo.js +19 -10
  17. package/dist/src/FlinkResponse.d.ts +2 -2
  18. package/dist/src/FsUtils.js +7 -7
  19. package/dist/src/TypeScriptCompiler.js +83 -68
  20. package/dist/src/TypeScriptUtils.js +11 -33
  21. package/dist/src/index.js +5 -1
  22. package/dist/src/mock-data-generator.js +1 -1
  23. package/dist/src/utils.js +6 -6
  24. package/package.json +6 -6
  25. package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
  26. package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
  27. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
  29. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
  30. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
  31. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
  32. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
  34. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
  36. package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
  37. package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
  38. package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
  39. package/spec/mock-project/dist/src/index.js +6 -2
  40. package/src/FlinkApp.ts +5 -5
  41. package/src/FlinkRepo.ts +13 -4
  42. package/src/TypeScriptCompiler.ts +13 -2
  43. package/src/TypeScriptUtils.ts +110 -164
  44. package/cli/generate-schemas.ts +0 -153
  45. package/dist/cli/generate-schemas.d.ts +0 -2
  46. package/dist/cli/generate-schemas.js +0 -140
@@ -6,7 +6,7 @@ function notFound(detail, code) {
6
6
  return {
7
7
  status: 404,
8
8
  error: {
9
- id: uuid_1.v4(),
9
+ id: (0, uuid_1.v4)(),
10
10
  title: "Not Found",
11
11
  detail: detail || "The requested resource does not exist",
12
12
  code: code || "notFound"
@@ -18,7 +18,7 @@ function conflict(detail, code) {
18
18
  return {
19
19
  status: 409,
20
20
  error: {
21
- id: uuid_1.v4(),
21
+ id: (0, uuid_1.v4)(),
22
22
  title: "Conflict",
23
23
  detail: detail || "An identical entity exits",
24
24
  code: code || "conflict"
@@ -30,7 +30,7 @@ function badRequest(detail, code) {
30
30
  return {
31
31
  status: 400,
32
32
  error: {
33
- id: uuid_1.v4(),
33
+ id: (0, uuid_1.v4)(),
34
34
  title: "Bad Request",
35
35
  detail: detail || "Invalid request",
36
36
  code: code || "badRequest"
@@ -42,7 +42,7 @@ function unauthorized(detail, code) {
42
42
  return {
43
43
  status: 401,
44
44
  error: {
45
- id: uuid_1.v4(),
45
+ id: (0, uuid_1.v4)(),
46
46
  title: "Unauthorized",
47
47
  detail: detail || "User not logged in or or not allowed to access resource",
48
48
  code: code || "badRequest"
@@ -54,7 +54,7 @@ function internalServerError(detail, code) {
54
54
  return {
55
55
  status: 500,
56
56
  error: {
57
- id: uuid_1.v4(),
57
+ id: (0, uuid_1.v4)(),
58
58
  title: "Internal Server Error",
59
59
  detail: detail || "Something unexpected went wrong",
60
60
  code: code || "internalServerError"
@@ -9,12 +9,12 @@ export declare enum HttpMethod {
9
9
  put = "put",
10
10
  delete = "delete"
11
11
  }
12
- declare type Params = Request["params"];
13
- declare type Query = Request["query"];
12
+ type Params = Request["params"];
13
+ type Query = Request["query"];
14
14
  /**
15
15
  * Flink request extends express Request but adds reqId and user object.
16
16
  */
17
- export declare type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
17
+ export type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
18
18
  reqId: string;
19
19
  user?: any;
20
20
  };
@@ -68,7 +68,7 @@ export interface RouteProps {
68
68
  * Http handler function that handlers implements in order to
69
69
  * handle HTTP requests and return a JSON response.
70
70
  */
71
- export declare type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema = any, P extends Params = Params, Q extends Query = Query> = (props: {
71
+ export type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema = any, P extends Params = Params, Q extends Query = Query> = (props: {
72
72
  req: FlinkRequest<ReqSchema, P, Q>;
73
73
  ctx: Ctx;
74
74
  origin?: string;
@@ -79,14 +79,14 @@ export declare type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema
79
79
  *
80
80
  * Just syntactic sugar on top op `HandlerFn`
81
81
  */
82
- export declare type GetHandler<Ctx extends FlinkContext, ResSchema = any, P extends Params = Params, Q extends Query = Query> = Handler<Ctx, any, ResSchema, P, Q>;
82
+ export type GetHandler<Ctx extends FlinkContext, ResSchema = any, P extends Params = Params, Q extends Query = Query> = Handler<Ctx, any, ResSchema, P, Q>;
83
83
  /**
84
84
  * Type for Handler file. Describes shape of exports when using
85
85
  * syntax like:
86
86
  *
87
87
  * `import * as FooHandler from "./src/handlers/FooHandler"
88
88
  */
89
- export declare type HandlerFile = {
89
+ export type HandlerFile = {
90
90
  default: Handler<any, any, any, any, any>;
91
91
  Route?: RouteProps;
92
92
  /**
@@ -109,7 +109,7 @@ export declare type HandlerFile = {
109
109
  */
110
110
  __params?: QueryParamMetadata[];
111
111
  };
112
- export declare type QueryParamMetadata = {
112
+ export type QueryParamMetadata = {
113
113
  name: string;
114
114
  description: string;
115
115
  };
@@ -7,4 +7,4 @@ var HttpMethod;
7
7
  HttpMethod["post"] = "post";
8
8
  HttpMethod["put"] = "put";
9
9
  HttpMethod["delete"] = "delete";
10
- })(HttpMethod = exports.HttpMethod || (exports.HttpMethod = {}));
10
+ })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
@@ -1,5 +1,5 @@
1
1
  import { FlinkContext } from "./FlinkContext";
2
- export declare type FlinkJobProps = {
2
+ export type FlinkJobProps = {
3
3
  /**
4
4
  * Id of job, must be unique
5
5
  */
@@ -48,7 +48,7 @@ export interface FlinkJob<C extends FlinkContext> {
48
48
  *
49
49
  * `import * as FooJob from "./src/jobs/FooJob"
50
50
  */
51
- export declare type FlinkJobFile = {
51
+ export type FlinkJobFile = {
52
52
  default: FlinkJob<any>;
53
53
  Job: FlinkJobProps;
54
54
  /**
@@ -5,19 +5,19 @@ export declare const log: {
5
5
  error: (...args: any[]) => void;
6
6
  json: (...args: any) => void;
7
7
  bgColorLog: (ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
8
+ reverse?: boolean | undefined;
8
9
  bold?: boolean | undefined;
9
10
  italic?: boolean | undefined;
10
11
  dim?: boolean | undefined;
11
12
  underscore?: boolean | undefined;
12
- reverse?: boolean | undefined;
13
13
  strikethrough?: boolean | undefined;
14
14
  } | undefined) => void;
15
15
  fontColorLog: (ticket: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white", text: string, setting?: {
16
+ reverse?: boolean | undefined;
16
17
  bold?: boolean | undefined;
17
18
  italic?: boolean | undefined;
18
19
  dim?: boolean | undefined;
19
20
  underscore?: boolean | undefined;
20
- reverse?: boolean | undefined;
21
21
  strikethrough?: boolean | undefined;
22
22
  } | undefined) => void;
23
23
  setLevel: (level: "debug" | "info" | "warn" | "error") => void;
@@ -9,8 +9,12 @@ export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Do
9
9
  get ctx(): FlinkContext;
10
10
  constructor(collectionName: string, db: Db);
11
11
  findAll(query?: {}): Promise<Model[]>;
12
- getById(id: string | ObjectId): Promise<any>;
13
- getOne(query?: {}): Promise<any>;
12
+ getById(id: string | ObjectId): Promise<(Model & {
13
+ _id?: any;
14
+ }) | null>;
15
+ getOne(query?: {}): Promise<(Model & {
16
+ _id?: any;
17
+ }) | null>;
14
18
  create<C = Omit<Model, "_id">>(model: C): Promise<C & {
15
19
  _id: string;
16
20
  }>;
@@ -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]) {
@@ -67,10 +67,10 @@ var FlinkRepo = /** @class */ (function () {
67
67
  enumerable: false,
68
68
  configurable: true
69
69
  });
70
- FlinkRepo.prototype.findAll = function (query) {
71
- if (query === void 0) { query = {}; }
72
- return __awaiter(this, void 0, void 0, function () {
70
+ FlinkRepo.prototype.findAll = function () {
71
+ return __awaiter(this, arguments, void 0, function (query) {
73
72
  var res;
73
+ if (query === void 0) { query = {}; }
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
76
  case 0: return [4 /*yield*/, this.collection.find(query).toArray()];
@@ -89,21 +89,27 @@ var FlinkRepo = /** @class */ (function () {
89
89
  case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.buildId(id) })];
90
90
  case 1:
91
91
  res = _a.sent();
92
- return [2 /*return*/, this.objectIdToString(res)];
92
+ if (res) {
93
+ return [2 /*return*/, this.objectIdToString(res)];
94
+ }
95
+ return [2 /*return*/, null];
93
96
  }
94
97
  });
95
98
  });
96
99
  };
97
- FlinkRepo.prototype.getOne = function (query) {
98
- if (query === void 0) { query = {}; }
99
- return __awaiter(this, void 0, void 0, function () {
100
+ FlinkRepo.prototype.getOne = function () {
101
+ return __awaiter(this, arguments, void 0, function (query) {
100
102
  var res;
103
+ if (query === void 0) { query = {}; }
101
104
  return __generator(this, function (_a) {
102
105
  switch (_a.label) {
103
106
  case 0: return [4 /*yield*/, this.collection.findOne(query)];
104
107
  case 1:
105
108
  res = _a.sent();
106
- return [2 /*return*/, this.objectIdToString(res)];
109
+ if (res) {
110
+ return [2 /*return*/, this.objectIdToString(res)];
111
+ }
112
+ return [2 /*return*/, null];
107
113
  }
108
114
  });
109
115
  });
@@ -134,7 +140,10 @@ var FlinkRepo = /** @class */ (function () {
134
140
  return [4 /*yield*/, this.collection.findOne({ _id: oid })];
135
141
  case 2:
136
142
  res = _a.sent();
137
- return [2 /*return*/, this.objectIdToString(res)];
143
+ if (res) {
144
+ return [2 /*return*/, this.objectIdToString(res)];
145
+ }
146
+ return [2 /*return*/, null];
138
147
  }
139
148
  });
140
149
  });
@@ -37,5 +37,5 @@ export interface FlinkResponse<T = any> {
37
37
  [x: string]: string;
38
38
  };
39
39
  }
40
- export declare type ExpressResponse = Response;
41
- export declare type ExpressRequest = Request;
40
+ export type ExpressResponse = Response;
41
+ export type ExpressRequest = Request;
@@ -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 " + file + ": " + err);
81
+ FlinkLog_1.log.error("Failed reading file ".concat(file, ": ").concat(err));
82
82
  return {};
83
83
  });
84
84
  });
@@ -89,17 +89,17 @@ function readJsonFiles(globPattern) {
89
89
  });
90
90
  }
91
91
  exports.readJsonFiles = readJsonFiles;
92
- function writeJsonFile(path, content, opts) {
93
- if (opts === void 0) { opts = {}; }
94
- return __awaiter(this, void 0, void 0, function () {
92
+ function writeJsonFile(path_2, content_1) {
93
+ return __awaiter(this, arguments, void 0, function (path, content, opts) {
95
94
  var i, jsonStr;
95
+ if (opts === void 0) { opts = {}; }
96
96
  return __generator(this, function (_a) {
97
97
  switch (_a.label) {
98
98
  case 0:
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;