Update linting
This commit is contained in:
1 parent
4f2dfb4f48
commit
0c9c027a77
112 files changed
+3781
-4125
No files matched your search
+9
-9
@@ -104,12 +104,12 @@ router.get(`/devices/:id.csv`, async (ctx) => {
|
||||
ctx.attachment(
|
||||
`device-${ctx.params.id}-${new Date()
|
||||
.toISOString()
|
||||
.replace(/[:.]/g, "")}.csv`
|
||||
.replace(/[:.]/g, "")}.csv`,
|
||||
);
|
||||
|
||||
ctx.body = new PassThrough();
|
||||
ctx.body.write(
|
||||
"Parameter,Object,Object timestamp,Writable,Writable timestamp,Value,Value type,Value timestamp,Notification,Notification timestamp,Access list,Access list timestamp\n"
|
||||
"Parameter,Object,Object timestamp,Writable,Writable timestamp,Value,Value type,Value timestamp,Notification,Notification timestamp,Access list,Access list timestamp\n",
|
||||
);
|
||||
|
||||
for (const k of Object.keys(device).sort()) {
|
||||
@@ -259,7 +259,7 @@ for (const [resource, flags] of Object.entries(resources)) {
|
||||
}
|
||||
|
||||
const columns: Record<string, Expression> = JSON.parse(
|
||||
singleParam(ctx.request.query.columns)
|
||||
singleParam(ctx.request.query.columns),
|
||||
);
|
||||
const now = Date.now();
|
||||
|
||||
@@ -282,11 +282,11 @@ for (const [resource, flags] of Object.entries(resources)) {
|
||||
ctx.body = new PassThrough();
|
||||
ctx.type = "text/csv";
|
||||
ctx.attachment(
|
||||
`${resource}-${new Date(now).toISOString().replace(/[:.]/g, "")}.csv`
|
||||
`${resource}-${new Date(now).toISOString().replace(/[:.]/g, "")}.csv`,
|
||||
);
|
||||
|
||||
ctx.body.write(
|
||||
Object.keys(columns).map((k) => `"${k.replace(/"/, '""')}"`) + "\n"
|
||||
Object.keys(columns).map((k) => `"${k.replace(/"/, '""')}"`) + "\n",
|
||||
);
|
||||
for await (const obj of db.query(resource, filter, options)) {
|
||||
const arr = Object.values(columns).map((exp) => {
|
||||
@@ -633,7 +633,7 @@ router.post("/devices/:id/tasks", async (ctx) => {
|
||||
}
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
},
|
||||
) as number;
|
||||
|
||||
const lastInform = device["Events.Inform"].value[0] as number;
|
||||
@@ -643,7 +643,7 @@ router.post("/devices/:id/tasks", async (ctx) => {
|
||||
const sessionStarted = await apiFunctions.awaitSessionStart(
|
||||
deviceId,
|
||||
lastInform,
|
||||
onlineThreshold
|
||||
onlineThreshold,
|
||||
);
|
||||
if (!sessionStarted) {
|
||||
status = "No contact from CPE";
|
||||
@@ -655,7 +655,7 @@ router.post("/devices/:id/tasks", async (ctx) => {
|
||||
|
||||
if (!status) {
|
||||
const promises = statuses.map((t) =>
|
||||
collections.faults.count({ _id: `${deviceId}:task_${t._id}` })
|
||||
collections.faults.count({ _id: `${deviceId}:task_${t._id}` }),
|
||||
);
|
||||
|
||||
const res = await Promise.all(promises);
|
||||
@@ -746,7 +746,7 @@ router.put("/users/:id/password", async (ctx) => {
|
||||
!(await apiFunctions.authLocal(
|
||||
ctx.state.configSnapshot,
|
||||
username,
|
||||
ctx.request.body.authPassword
|
||||
ctx.request.body.authPassword,
|
||||
))
|
||||
) {
|
||||
logUnauthorizedWarning(log);
|
||||
|
||||
+20
-20
@@ -30,7 +30,7 @@ import { Script } from "vm";
|
||||
import { Readable } from "stream";
|
||||
|
||||
function processDeviceProjection(
|
||||
projection: Record<string, 1>
|
||||
projection: Record<string, 1>,
|
||||
): Record<string, 1> {
|
||||
if (!projection) return projection;
|
||||
const p = {};
|
||||
@@ -58,7 +58,7 @@ function processDeviceProjection(
|
||||
}
|
||||
|
||||
function processDeviceSort(
|
||||
sort: Record<string, number>
|
||||
sort: Record<string, number>,
|
||||
): Record<string, number> {
|
||||
if (!sort) return sort;
|
||||
const s = {};
|
||||
@@ -93,7 +93,7 @@ interface FlatAttributes {
|
||||
accessListTimestamp?: number;
|
||||
}
|
||||
|
||||
interface FlatDevice {
|
||||
export interface FlatDevice {
|
||||
[param: string]: FlatAttributes;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export function flattenDevice(device: Record<string, unknown>): FlatDevice {
|
||||
input,
|
||||
root: string,
|
||||
output: FlatDevice,
|
||||
timestamp: number
|
||||
timestamp: number,
|
||||
): void {
|
||||
for (const [name, tree] of Object.entries(input)) {
|
||||
if (!root) {
|
||||
@@ -272,7 +272,7 @@ function flattenTask(task: unknown): Task {
|
||||
}
|
||||
|
||||
function flattenPreset(
|
||||
preset: Record<string, unknown>
|
||||
preset: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
const p = Object.assign({}, preset);
|
||||
if (p.precondition) {
|
||||
@@ -281,7 +281,7 @@ function flattenPreset(
|
||||
parse(p.precondition as string);
|
||||
} catch (error) {
|
||||
p.precondition = convertOldPrecondition(
|
||||
JSON.parse(p.precondition as string)
|
||||
JSON.parse(p.precondition as string),
|
||||
);
|
||||
p.precondition = (p.precondition as string).length
|
||||
? stringify(p.precondition as Expression)
|
||||
@@ -377,7 +377,7 @@ interface QueryOptions {
|
||||
export async function* query(
|
||||
resource: string,
|
||||
filter: Expression,
|
||||
options?: QueryOptions
|
||||
options?: QueryOptions,
|
||||
): AsyncGenerator<any, void, undefined> {
|
||||
options = options || {};
|
||||
filter = evaluate(filter, null, Date.now());
|
||||
@@ -407,7 +407,7 @@ export async function* query(
|
||||
.reduce(
|
||||
(obj, [k, v]) =>
|
||||
Object.assign(obj, { [k]: Math.min(Math.max(v, -1), 1) }),
|
||||
{}
|
||||
{},
|
||||
);
|
||||
|
||||
if (resource === "devices") s = processDeviceSort(s);
|
||||
@@ -435,7 +435,7 @@ export function count(resource: string, filter: Expression): Promise<number> {
|
||||
|
||||
export async function updateDeviceTags(
|
||||
deviceId: string,
|
||||
tags: Record<string, boolean>
|
||||
tags: Record<string, boolean>,
|
||||
): Promise<void> {
|
||||
const add = [];
|
||||
const pull = [];
|
||||
@@ -455,7 +455,7 @@ export async function updateDeviceTags(
|
||||
|
||||
export async function putPreset(
|
||||
id: string,
|
||||
object: Record<string, unknown>
|
||||
object: Record<string, unknown>,
|
||||
): Promise<void> {
|
||||
const p = preProcessPreset(object);
|
||||
await collections.presets.replaceOne({ _id: id }, p, { upsert: true });
|
||||
@@ -467,7 +467,7 @@ export async function deletePreset(id: string): Promise<void> {
|
||||
|
||||
export async function putProvision(
|
||||
id: string,
|
||||
object: { script: string }
|
||||
object: { script: string },
|
||||
): Promise<void> {
|
||||
if (!object.script) object.script = "";
|
||||
try {
|
||||
@@ -478,7 +478,7 @@ export async function putProvision(
|
||||
} catch (err) {
|
||||
if (err.stack?.startsWith(`${id}:`)) {
|
||||
return Promise.reject(
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`)
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`),
|
||||
);
|
||||
}
|
||||
return Promise.reject(err);
|
||||
@@ -494,7 +494,7 @@ export async function deleteProvision(id: string): Promise<void> {
|
||||
|
||||
export async function putVirtualParameter(
|
||||
id: string,
|
||||
object: { script: string }
|
||||
object: { script: string },
|
||||
): Promise<void> {
|
||||
if (!object.script) object.script = "";
|
||||
try {
|
||||
@@ -505,7 +505,7 @@ export async function putVirtualParameter(
|
||||
} catch (err) {
|
||||
if (err.stack?.startsWith(`${id}:`)) {
|
||||
return Promise.reject(
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`)
|
||||
new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`),
|
||||
);
|
||||
}
|
||||
return Promise.reject(err);
|
||||
@@ -521,7 +521,7 @@ export async function deleteVirtualParameter(id: string): Promise<void> {
|
||||
|
||||
export async function putConfig(
|
||||
id: string,
|
||||
object: WithoutId<MongoTypes.Config>
|
||||
object: WithoutId<MongoTypes.Config>,
|
||||
): Promise<void> {
|
||||
await collections.config.replaceOne({ _id: id }, object, { upsert: true });
|
||||
}
|
||||
@@ -532,7 +532,7 @@ export async function deleteConfig(id: string): Promise<void> {
|
||||
|
||||
export async function putPermission(
|
||||
id: string,
|
||||
object: WithoutId<MongoTypes.Permission>
|
||||
object: WithoutId<MongoTypes.Permission>,
|
||||
): Promise<void> {
|
||||
await collections.permissions.replaceOne({ _id: id }, object, {
|
||||
upsert: true,
|
||||
@@ -545,13 +545,13 @@ export async function deletePermission(id: string): Promise<void> {
|
||||
|
||||
export async function putUser(
|
||||
id: string,
|
||||
object: Partial<WithoutId<MongoTypes.User>>
|
||||
object: Partial<WithoutId<MongoTypes.User>>,
|
||||
): Promise<void> {
|
||||
// update instead of replace to keep the password if not set by user
|
||||
await collections.users.updateOne(
|
||||
{ _id: id },
|
||||
{ $set: object },
|
||||
{ upsert: true }
|
||||
{ upsert: true },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ export function downloadFile(filename: string): Readable {
|
||||
export function putFile(
|
||||
filename: string,
|
||||
metadata: Record<string, string>,
|
||||
contentStream: Readable
|
||||
contentStream: Readable,
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const uploadStream = filesBucket.openUploadStreamWithId(
|
||||
@@ -574,7 +574,7 @@ export function putFile(
|
||||
filename,
|
||||
{
|
||||
metadata: metadata,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let readableEnded = false;
|
||||
|
||||
@@ -125,7 +125,7 @@ export function getConfig(
|
||||
key: string,
|
||||
context: Record<string, unknown>,
|
||||
now: number,
|
||||
cb?: (e: Expression) => Expression
|
||||
cb?: (e: Expression) => Expression,
|
||||
): string | number | boolean | null {
|
||||
const snapshot = localCache.get(revision);
|
||||
if (!snapshot) throw new Error("Cache snapshot does not exist");
|
||||
|
||||
Reference in new issue
Block a user