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:
1 parent
824639976f
commit
1e41c72d60
62 files changed
+718
-898
No files matched your search
+13
-22
@@ -1,14 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const url = require("url");
|
||||
import http from "http";
|
||||
import https from "https";
|
||||
import url from "url";
|
||||
import * as config from "../config";
|
||||
import * as db from "./db";
|
||||
import * as mongodbFunctions from "./mongodb-functions";
|
||||
|
||||
const config = require("../config");
|
||||
const db = require("./db");
|
||||
const mongodbFunctions = require("./mongodb-functions");
|
||||
|
||||
function filterToMongoQuery(filter, negate = false, res = {}) {
|
||||
export function filterToMongoQuery(filter, negate = false, res = {}) {
|
||||
const op = filter[0];
|
||||
|
||||
if ((!negate && op === "AND") || (negate && op === "OR")) {
|
||||
@@ -66,7 +65,7 @@ function filterToMongoQuery(filter, negate = false, res = {}) {
|
||||
return res;
|
||||
}
|
||||
|
||||
function deleteResource(resource, id) {
|
||||
export function deleteResource(resource, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const resourceUrl =
|
||||
resource === "virtualParameters" ? "virtual_parameters" : resource;
|
||||
@@ -142,7 +141,7 @@ function postTask(task, connectionRequest, callback) {
|
||||
.end(JSON.stringify(task));
|
||||
}
|
||||
|
||||
function postTasks(deviceId, tasks) {
|
||||
export function postTasks(deviceId, tasks) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let connectionRequestStatus;
|
||||
const promises = [];
|
||||
@@ -206,7 +205,7 @@ function postTasks(deviceId, tasks) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateTags(deviceId, tags) {
|
||||
export function updateTags(deviceId, tags) {
|
||||
return Promise.all(
|
||||
Object.entries(tags).map(
|
||||
([tag, onOff]) =>
|
||||
@@ -235,7 +234,7 @@ function updateTags(deviceId, tags) {
|
||||
);
|
||||
}
|
||||
|
||||
function ping(host) {
|
||||
export function ping(host) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = url.parse(
|
||||
`http://127.0.0.1:${config.get("NBI_PORT")}/ping/${encodeURIComponent(
|
||||
@@ -295,7 +294,7 @@ function ping(host) {
|
||||
});
|
||||
}
|
||||
|
||||
function putResource(resource, id, data) {
|
||||
export function putResource(resource, id, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const resourceUrl =
|
||||
resource === "virtualParameters" ? "virtual_parameters" : resource;
|
||||
@@ -348,7 +347,7 @@ function putResource(resource, id, data) {
|
||||
});
|
||||
}
|
||||
|
||||
function putFile(id, metadata, fileStream) {
|
||||
export function putFile(id, metadata, fileStream) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = url.parse(
|
||||
`http://127.0.0.1:${config.get("NBI_PORT")}/files/${encodeURIComponent(
|
||||
@@ -372,11 +371,3 @@ function putFile(id, metadata, fileStream) {
|
||||
fileStream.pipe(req);
|
||||
});
|
||||
}
|
||||
|
||||
exports.postTasks = postTasks;
|
||||
exports.deleteResource = deleteResource;
|
||||
exports.putResource = putResource;
|
||||
exports.updateTags = updateTags;
|
||||
exports.filterToMongoQuery = filterToMongoQuery;
|
||||
exports.ping = ping;
|
||||
exports.putFile = putFile;
|
||||
Reference in new issue
Block a user