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

+19 -30
View File
@@ -18,16 +18,16 @@
*/
"use strict";
const vm = require("vm");
const crypto = require("crypto");
import vm from "vm";
import crypto from "crypto";
const config = require("./config");
const db = require("./db");
const cache = require("./cache");
const query = require("./query");
const logger = require("./logger");
const scheduling = require("./scheduling");
const expression = require("./common/expression");
import * as config from "./config";
import * as db from "./db";
import * as cache from "./cache";
import * as query from "./query";
import * as logger from "./logger";
import * as scheduling from "./scheduling";
import * as expression from "./common/expression";
const REFRESH = 3000;
const EVICT_TIMEOUT = 60000;
@@ -369,7 +369,7 @@ function refresh(callback) {
});
}
function getCurrentSnapshot(callback) {
export function getCurrentSnapshot(callback) {
if (Date.now() < nextRefresh) {
if (callback) return callback(null, currentSnapshot);
return Promise.resolve(currentSnapshot);
@@ -389,35 +389,35 @@ function getCurrentSnapshot(callback) {
});
}
function hasSnapshot(hash) {
export function hasSnapshot(hash) {
return snapshots.has(hash);
}
function getPresets(snapshotKey) {
export function getPresets(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.presets;
}
function getProvisions(snapshotKey) {
export function getProvisions(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.provisions;
}
function getVirtualParameters(snapshotKey) {
export function getVirtualParameters(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.virtualParameters;
}
function getFiles(snapshotKey) {
export function getFiles(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.files;
}
function getConfig(snapshotKey, key, context, now) {
export function getConfig(snapshotKey, key, context, now) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
@@ -445,34 +445,23 @@ function getConfig(snapshotKey, key, context, now) {
return expression.evaluate(snapshot.config[key], context, now || Date.now());
}
function getAuthConfig(snapshotKey) {
export function getAuthConfig(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.config.auth;
}
function getPermissionsConfig(snapshotKey) {
export function getPermissionsConfig(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.config.permissions;
}
function getUiConfig(snapshotKey) {
export function getUiConfig(snapshotKey) {
const snapshot = snapshots.get(snapshotKey);
if (!snapshot) throw new Error("Cache snapshot does not exist");
return snapshot.config.ui;
}
exports.getCurrentSnapshot = getCurrentSnapshot;
exports.hasSnapshot = hasSnapshot;
exports.getPresets = getPresets;
exports.getProvisions = getProvisions;
exports.getVirtualParameters = getVirtualParameters;
exports.getFiles = getFiles;
exports.getConfig = getConfig;
exports.getAuthConfig = getAuthConfig;
exports.getPermissionsConfig = getPermissionsConfig;
exports.getUiConfig = getUiConfig;