Convert backend code to ES modules

Bundling code now with Rollup for its flat bundling and tree shaking
support. Front end code still goes through Webpack for browser support.
This commit is contained in:
Zaid Abdulla committed 2019-02-04 23:47:54 -08:00
1 parent 824639976f
commit 1e41c72d60
62 files changed
+718 -898

No files matched your search

+9 -14
View File
@@ -1,9 +1,9 @@
"use strict";
const mongodb = require("mongodb");
const config = require("../config");
const mongodbFunctions = require("./mongodb-functions");
const expression = require("../common/expression");
import { MongoClient } from "mongodb";
import * as config from "../config";
import * as mongodbFunctions from "./mongodb-functions";
import * as expression from "../common/expression";
const CACHE_TTL = 300000;
@@ -24,7 +24,7 @@ function getClient() {
if (!_clientPromise) {
_clientPromise = new Promise((resolve, reject) => {
const CONNECTION_URL = config.get("MONGODB_CONNECTION_URL");
mongodb.MongoClient.connect(
MongoClient.connect(
CONNECTION_URL,
{ useNewUrlParser: true },
(err, client) => {
@@ -39,7 +39,7 @@ function getClient() {
return _clientPromise;
}
function cache(key, valueGetter, ttl) {
export function cache(key, valueGetter, ttl) {
return new Promise((resolve, reject) => {
getClient()
.then(client => {
@@ -72,7 +72,7 @@ function cache(key, valueGetter, ttl) {
});
}
function query(resource, filter, options, callback) {
export function query(resource, filter, options, callback) {
options = options || {};
let q;
filter = expression.evaluate(filter, null, Date.now());
@@ -158,7 +158,7 @@ function query(resource, filter, options, callback) {
});
}
function count(resource, filter) {
export function count(resource, filter) {
let q;
filter = expression.evaluate(filter, null, Date.now());
@@ -187,15 +187,10 @@ function count(resource, filter) {
});
}
function disconnect() {
export function disconnect() {
if (_clientPromise) {
_clientPromise.then(client => {
client.close();
});
}
}
exports.query = query;
exports.count = count;
exports.cache = cache;
exports.disconnect = disconnect;