@flink-app/flink 0.2.0-beta.18 → 0.2.0-beta.19

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.
@@ -1,6 +1,6 @@
1
1
  import { Express } from "express";
2
2
  import { JSONSchema7 } from "json-schema";
3
- import { Db } from "mongodb";
3
+ import { Db, MongoClient } from "mongodb";
4
4
  import { FlinkAuthPlugin } from "./auth/FlinkAuthPlugin";
5
5
  import { FlinkContext } from "./FlinkContext";
6
6
  import { HandlerFile, HttpMethod, QueryParamMetadata, RouteProps } from "./FlinkHttpHandler";
@@ -113,6 +113,7 @@ export declare class FlinkApp<C extends FlinkContext> {
113
113
  name: string;
114
114
  expressApp?: Express;
115
115
  db?: Db;
116
+ dbClient?: MongoClient;
116
117
  handlers: HandlerConfig[];
117
118
  port?: number;
118
119
  started: boolean;
@@ -386,7 +386,7 @@ var FlinkApp = /** @class */ (function () {
386
386
  if (this.dbOpts) {
387
387
  for (_i = 0, autoRegisteredRepos_1 = exports.autoRegisteredRepos; _i < autoRegisteredRepos_1.length; _i++) {
388
388
  _a = autoRegisteredRepos_1[_i], collectionName = _a.collectionName, repoInstanceName = _a.repoInstanceName, Repo = _a.Repo;
389
- repoInstance = new Repo(collectionName, this.db);
389
+ repoInstance = new Repo(collectionName, this.db, this.dbClient);
390
390
  this.repos[repoInstanceName] = repoInstance;
391
391
  node_color_log_1.default.info("Registered repo " + repoInstanceName);
392
392
  }
@@ -431,6 +431,7 @@ var FlinkApp = /** @class */ (function () {
431
431
  case 2:
432
432
  client = _a.sent();
433
433
  this.db = client.db();
434
+ this.dbClient = client;
434
435
  return [3 /*break*/, 4];
435
436
  case 3:
436
437
  err_2 = _a.sent();
@@ -1,13 +1,14 @@
1
- import { Collection, Db } from "mongodb";
1
+ import { Collection, Db, MongoClient } from "mongodb";
2
2
  import { FlinkContext } from "./FlinkContext";
3
3
  export declare abstract class FlinkRepo<C extends FlinkContext, Model = any> {
4
4
  private collectionName;
5
5
  db: Db;
6
+ client?: MongoClient | undefined;
6
7
  collection: Collection;
7
8
  private _ctx?;
8
9
  set ctx(ctx: FlinkContext);
9
10
  get ctx(): FlinkContext;
10
- constructor(collectionName: string, db: Db);
11
+ constructor(collectionName: string, db: Db, client?: MongoClient | undefined);
11
12
  findAll(query?: {}): Promise<Model[]>;
12
13
  getById(id: string): Promise<Model | null>;
13
14
  getOne(query?: {}): Promise<Model | null>;
@@ -39,9 +39,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.FlinkRepo = void 0;
40
40
  var mongodb_1 = require("mongodb");
41
41
  var FlinkRepo = /** @class */ (function () {
42
- function FlinkRepo(collectionName, db) {
42
+ function FlinkRepo(collectionName, db, client) {
43
43
  this.collectionName = collectionName;
44
44
  this.db = db;
45
+ this.client = client;
45
46
  this.collection = db.collection(this.collectionName);
46
47
  }
47
48
  Object.defineProperty(FlinkRepo.prototype, "ctx", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "0.2.0-beta.18",
3
+ "version": "0.2.0-beta.19",
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",
@@ -61,5 +61,5 @@
61
61
  "rimraf": "^3.0.2",
62
62
  "ts-node": "^9.1.1"
63
63
  },
64
- "gitHead": "aaeadba35673b13654a54bf752fef3ecc4c94b52"
64
+ "gitHead": "6fc91bfb6c1987d395384a2f488829fd4546417e"
65
65
  }
package/src/FlinkApp.ts CHANGED
@@ -4,7 +4,7 @@ import bodyParser from "body-parser";
4
4
  import cors from "cors";
5
5
  import express, { Express, Request } from "express";
6
6
  import { JSONSchema7 } from "json-schema";
7
- import mongodb, { Db } from "mongodb";
7
+ import mongodb, { Db, MongoClient } from "mongodb";
8
8
  import log from "node-color-log";
9
9
  import { v4 } from "uuid";
10
10
  import { FlinkAuthPlugin } from "./auth/FlinkAuthPlugin";
@@ -155,6 +155,7 @@ export class FlinkApp<C extends FlinkContext> {
155
155
  public name: string;
156
156
  public expressApp?: Express;
157
157
  public db?: Db;
158
+ public dbClient?: MongoClient;
158
159
  public handlers: HandlerConfig[] = [];
159
160
  public port?: number;
160
161
  public started = false;
@@ -534,7 +535,11 @@ export class FlinkApp<C extends FlinkContext> {
534
535
  repoInstanceName,
535
536
  Repo,
536
537
  } of autoRegisteredRepos) {
537
- const repoInstance: FlinkRepo<C> = new Repo(collectionName, this.db);
538
+ const repoInstance: FlinkRepo<C> = new Repo(
539
+ collectionName,
540
+ this.db,
541
+ this.dbClient
542
+ );
538
543
 
539
544
  this.repos[repoInstanceName] = repoInstance;
540
545
 
@@ -574,6 +579,7 @@ export class FlinkApp<C extends FlinkContext> {
574
579
  connectTimeoutMS: 4000,
575
580
  });
576
581
  this.db = client.db();
582
+ this.dbClient = client;
577
583
  } catch (err) {
578
584
  log.error("Failed to connect to db: " + err);
579
585
  process.exit(1);
package/src/FlinkRepo.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Collection, Db, ObjectId } from "mongodb";
1
+ import { Collection, Db, ObjectId, MongoClient } from "mongodb";
2
2
  import { FlinkContext } from "./FlinkContext";
3
3
 
4
4
  export abstract class FlinkRepo<C extends FlinkContext, Model = any> {
@@ -15,7 +15,11 @@ export abstract class FlinkRepo<C extends FlinkContext, Model = any> {
15
15
  return this._ctx;
16
16
  }
17
17
 
18
- constructor(private collectionName: string, public db: Db) {
18
+ constructor(
19
+ private collectionName: string,
20
+ public db: Db,
21
+ public client?: MongoClient
22
+ ) {
19
23
  this.collection = db.collection(this.collectionName);
20
24
  }
21
25