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

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 (45) 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 +6 -3
  8. package/dist/src/FlinkApp.js +109 -78
  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 +17 -8
  16. package/dist/src/FlinkRepo.js +44 -20
  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 +7 -7
  25. package/spec/FlinkRepo.spec.ts +11 -0
  26. package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
  27. package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
  29. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
  30. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
  31. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
  32. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
  34. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
  36. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
  37. package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
  38. package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
  39. package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
  40. package/spec/mock-project/dist/src/index.js +6 -2
  41. package/src/FlinkApp.ts +33 -8
  42. package/src/FlinkRepo.ts +30 -11
  43. package/src/TypeScriptCompiler.ts +13 -2
  44. package/src/TypeScriptUtils.ts +110 -164
  45. package/cli/generate-schemas.ts +0 -153
@@ -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;
@@ -1,22 +1,31 @@
1
- import { Collection, Db, Document, ObjectId } from "mongodb";
1
+ import { Collection, Db, Document, MongoClient, ObjectId } from "mongodb";
2
2
  import { FlinkContext } from "./FlinkContext";
3
+ /**
4
+ * Partial model to have intellisense for partial updates but
5
+ * also allow any other properties to be set such as nested objects etc.
6
+ */
7
+ type PartialModel<Model> = Partial<Model> & {
8
+ [x: string]: any;
9
+ };
3
10
  export declare abstract class FlinkRepo<C extends FlinkContext, Model extends Document> {
4
- private collectionName;
5
- private db;
11
+ collectionName: string;
12
+ db: Db;
13
+ client?: MongoClient | undefined;
6
14
  collection: Collection;
7
15
  private _ctx?;
8
16
  set ctx(ctx: FlinkContext);
9
17
  get ctx(): FlinkContext;
10
- constructor(collectionName: string, db: Db);
18
+ constructor(collectionName: string, db: Db, client?: MongoClient | undefined);
11
19
  findAll(query?: {}): Promise<Model[]>;
12
- getById(id: string | ObjectId): Promise<any>;
13
- getOne(query?: {}): Promise<any>;
20
+ getById(id: string | ObjectId): Promise<Model | null>;
21
+ getOne(query?: {}): Promise<Model | null>;
14
22
  create<C = Omit<Model, "_id">>(model: C): Promise<C & {
15
23
  _id: string;
16
24
  }>;
17
- updateOne(id: string | ObjectId, model: Partial<Model>): Promise<Model | null>;
18
- updateMany<U = Partial<Model>>(query: any, model: U): Promise<number>;
25
+ updateOne(id: string | ObjectId, model: PartialModel<Model>): Promise<Model | null>;
26
+ updateMany<U = PartialModel<Model>>(query: any, model: U): Promise<number>;
19
27
  deleteById(id: string | ObjectId): Promise<number>;
20
28
  private buildId;
21
29
  private objectIdToString;
22
30
  }
31
+ export {};
@@ -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,13 +46,25 @@ 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 __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
49
60
  Object.defineProperty(exports, "__esModule", { value: true });
50
61
  exports.FlinkRepo = void 0;
51
62
  var mongodb_1 = require("mongodb");
52
63
  var FlinkRepo = /** @class */ (function () {
53
- function FlinkRepo(collectionName, db) {
64
+ function FlinkRepo(collectionName, db, client) {
54
65
  this.collectionName = collectionName;
55
66
  this.db = db;
67
+ this.client = client;
56
68
  this.collection = db.collection(this.collectionName);
57
69
  }
58
70
  Object.defineProperty(FlinkRepo.prototype, "ctx", {
@@ -67,10 +79,10 @@ var FlinkRepo = /** @class */ (function () {
67
79
  enumerable: false,
68
80
  configurable: true
69
81
  });
70
- FlinkRepo.prototype.findAll = function (query) {
71
- if (query === void 0) { query = {}; }
72
- return __awaiter(this, void 0, void 0, function () {
82
+ FlinkRepo.prototype.findAll = function () {
83
+ return __awaiter(this, arguments, void 0, function (query) {
73
84
  var res;
85
+ if (query === void 0) { query = {}; }
74
86
  return __generator(this, function (_a) {
75
87
  switch (_a.label) {
76
88
  case 0: return [4 /*yield*/, this.collection.find(query).toArray()];
@@ -89,21 +101,27 @@ var FlinkRepo = /** @class */ (function () {
89
101
  case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.buildId(id) })];
90
102
  case 1:
91
103
  res = _a.sent();
92
- return [2 /*return*/, this.objectIdToString(res)];
104
+ if (res) {
105
+ return [2 /*return*/, this.objectIdToString(res)];
106
+ }
107
+ return [2 /*return*/, null];
93
108
  }
94
109
  });
95
110
  });
96
111
  };
97
- FlinkRepo.prototype.getOne = function (query) {
98
- if (query === void 0) { query = {}; }
99
- return __awaiter(this, void 0, void 0, function () {
112
+ FlinkRepo.prototype.getOne = function () {
113
+ return __awaiter(this, arguments, void 0, function (query) {
100
114
  var res;
115
+ if (query === void 0) { query = {}; }
101
116
  return __generator(this, function (_a) {
102
117
  switch (_a.label) {
103
118
  case 0: return [4 /*yield*/, this.collection.findOne(query)];
104
119
  case 1:
105
120
  res = _a.sent();
106
- return [2 /*return*/, this.objectIdToString(res)];
121
+ if (res) {
122
+ return [2 /*return*/, this.objectIdToString(res)];
123
+ }
124
+ return [2 /*return*/, null];
107
125
  }
108
126
  });
109
127
  });
@@ -123,32 +141,38 @@ var FlinkRepo = /** @class */ (function () {
123
141
  };
124
142
  FlinkRepo.prototype.updateOne = function (id, model) {
125
143
  return __awaiter(this, void 0, void 0, function () {
126
- var oid, res;
144
+ var oid, _id, modelWithoutId, res;
127
145
  return __generator(this, function (_a) {
128
146
  switch (_a.label) {
129
147
  case 0:
130
148
  oid = this.buildId(id);
131
- return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: model })];
149
+ _id = model._id, modelWithoutId = __rest(model, ["_id"]);
150
+ return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: modelWithoutId })];
132
151
  case 1:
133
152
  _a.sent();
134
153
  return [4 /*yield*/, this.collection.findOne({ _id: oid })];
135
154
  case 2:
136
155
  res = _a.sent();
137
- return [2 /*return*/, this.objectIdToString(res)];
156
+ if (res) {
157
+ return [2 /*return*/, this.objectIdToString(res)];
158
+ }
159
+ return [2 /*return*/, null];
138
160
  }
139
161
  });
140
162
  });
141
163
  };
142
164
  FlinkRepo.prototype.updateMany = function (query, model) {
143
165
  return __awaiter(this, void 0, void 0, function () {
144
- var modifiedCount;
145
- return __generator(this, function (_a) {
146
- switch (_a.label) {
147
- case 0: return [4 /*yield*/, this.collection.updateMany(query, {
148
- $set: model,
149
- })];
166
+ var _a, _id, modelWithoutId, modifiedCount;
167
+ return __generator(this, function (_b) {
168
+ switch (_b.label) {
169
+ case 0:
170
+ _a = model, _id = _a._id, modelWithoutId = __rest(_a, ["_id"]);
171
+ return [4 /*yield*/, this.collection.updateMany(query, {
172
+ $set: modelWithoutId,
173
+ })];
150
174
  case 1:
151
- modifiedCount = (_a.sent()).modifiedCount;
175
+ modifiedCount = (_b.sent()).modifiedCount;
152
176
  return [2 /*return*/, modifiedCount];
153
177
  }
154
178
  });
@@ -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;