From 9706026ea53c52d76c0a09cdc50e1110a113eb28 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 16 Aug 2021 14:25:18 -0700 Subject: [PATCH] Update Prettier --- lib/auth.ts | 6 ++--- lib/cache.ts | 2 +- lib/common/boolean-expression.ts | 38 ++++++++++++++++---------------- lib/cwmp.ts | 30 ++++++++++++++----------- lib/db.ts | 14 +++++------- lib/local-cache.ts | 8 ++----- lib/logger.ts | 8 +++---- lib/nbi.ts | 12 +++++----- lib/ping.ts | 12 ++++++---- lib/session.ts | 19 ++++++---------- lib/ui.ts | 3 ++- lib/ui/db.ts | 2 +- npm-shrinkwrap.json | 6 ++--- package.json | 2 +- ui/store.ts | 5 ++--- ui/ui-config-component.ts | 2 +- 16 files changed, 83 insertions(+), 86 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index 28fa512..75e3adc 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -52,9 +52,9 @@ function parseHeaderFeilds(str: string): Record { return res; } -export function parseAuthorizationHeader( - authHeader: string -): { method: string } { +export function parseAuthorizationHeader(authHeader: string): { + method: string; +} { authHeader = authHeader.trim(); const method = authHeader.split(" ", 1)[0]; const res = { method: method }; diff --git a/lib/cache.ts b/lib/cache.ts index 2bc539c..fb8223a 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -78,7 +78,7 @@ export async function acquireLock( value: token, expire: new Date(now + ttl + CLOCK_SKEW_TOLERANCE), }, - $currentDate: { timestamp: (true as unknown) as Date }, + $currentDate: { timestamp: true as unknown as Date }, }, { upsert: true, returnDocument: "after" } ); diff --git a/lib/common/boolean-expression.ts b/lib/common/boolean-expression.ts index 2177fcb..54f57b0 100644 --- a/lib/common/boolean-expression.ts +++ b/lib/common/boolean-expression.ts @@ -662,10 +662,10 @@ function normalizeCallback(exp: Expression): Expression { if (p == null) return null; args.push(p); } - return (args.reduce( + return args.reduce( (previousValue, currentValue) => previousValue.add(currentValue), ADDITIVE_IDENTITY - ) as unknown) as Expression; + ) as unknown as Expression; } else if (op === "*") { const args: Polynomial[] = []; for (let i = 1; i < exp.length; ++i) { @@ -673,10 +673,10 @@ function normalizeCallback(exp: Expression): Expression { if (p == null) return null; args.push(p); } - return (args.reduce( + return args.reduce( (previousValue, currentValue) => previousValue.multiply(currentValue), MULTIPLICATIVE_IDENTITY - ) as unknown) as Expression; + ) as unknown as Expression; } else if (op === "-") { const args: Polynomial[] = []; for (let i = 1; i < exp.length; ++i) { @@ -684,9 +684,9 @@ function normalizeCallback(exp: Expression): Expression { if (p == null) return null; args.push(p); } - return (args.reduce((previousValue, currentValue) => + return args.reduce((previousValue, currentValue) => previousValue.subtract(currentValue) - ) as unknown) as Expression; + ) as unknown as Expression; } else if (op === "/") { const args: Polynomial[] = []; for (let i = 1; i < exp.length; ++i) { @@ -694,9 +694,9 @@ function normalizeCallback(exp: Expression): Expression { if (p == null) return null; args.push(p); } - return (args.reduce((previousValue, currentValue) => + return args.reduce((previousValue, currentValue) => previousValue.divide(currentValue) - ) as unknown) as Expression; + ) as unknown as Expression; } else if (["=", "<>", ">", ">=", "<", "<="].includes(op)) { if (exp[1] == null || exp[2] == null) return null; let lhs: Polynomial, rhs: Polynomial; @@ -1072,22 +1072,22 @@ function mapCallback(exp: Expression | BoolExprSynth): Expression { const op = exp[0]; if (op === "IS NULL") - return (new IsNullSynth(toBoolExprSynth(exp[1])) as unknown) as Expression; + return new IsNullSynth(toBoolExprSynth(exp[1])) as unknown as Expression; if (op === "IS NOT NULL") { - return (new NotSynth( + return new NotSynth( new IsNullSynth(toBoolExprSynth(exp[1])) - ) as unknown) as Expression; + ) as unknown as Expression; } else if (op === "NOT") { - return (new NotSynth(toBoolExprSynth(exp[1])) as unknown) as Expression; + return new NotSynth(toBoolExprSynth(exp[1])) as unknown as Expression; } else if (op === "OR") { - return (new OrSynth( + return new OrSynth( ...exp.slice(1).map((a) => toBoolExprSynth(a)) - ) as unknown) as Expression; + ) as unknown as Expression; } else if (op === "AND") { - return (new AndSynth( + return new AndSynth( ...exp.slice(1).map((a) => toBoolExprSynth(a)) - ) as unknown) as Expression; + ) as unknown as Expression; } for (let i = 1; i < exp.length; ++i) { if (exp[i] instanceof BoolExprSynth) { @@ -1152,10 +1152,10 @@ export function minimize(expr: Expression, boolean = false): Expression { if (res.length < 3) return null; return res; } - expr = (toBoolExprSynth(expr) as unknown) as Expression; + expr = toBoolExprSynth(expr) as unknown as Expression; } - if (boolean) expr = (toBoolExprSynth(expr) as unknown) as Expression; + if (boolean) expr = toBoolExprSynth(expr) as unknown as Expression; if (expr instanceof BoolExprSynth) expr = boolExprSynthToExpression(expr); return expr; @@ -1173,7 +1173,7 @@ export function unionDiff( if (!expr1) { if (Array.isArray(expr2) && expr2[0] === "CASE") - expr2 = (toBoolExprSynth(expr2) as unknown) as Expression; + expr2 = toBoolExprSynth(expr2) as unknown as Expression; if (expr2 instanceof BoolExprSynth) expr2 = boolExprSynthToExpression(expr2); return [expr2, expr2]; diff --git a/lib/cwmp.ts b/lib/cwmp.ts index 5cc5d2c..6168e6e 100644 --- a/lib/cwmp.ts +++ b/lib/cwmp.ts @@ -497,10 +497,11 @@ async function applyPresets(sessionContext: SessionContext): Promise { defer: true, })); - const { fault: flt, rpcId: reqId, rpc: acsReq } = await session.rpcRequest( - sessionContext, - declarations - ); + const { + fault: flt, + rpcId: reqId, + rpc: acsReq, + } = await session.rpcRequest(sessionContext, declarations); if (flt) { recordFault(sessionContext, flt); @@ -572,10 +573,11 @@ async function applyPresets(sessionContext: SessionContext): Promise { deviceData.timestamps.dirty = 0; deviceData.attributes.dirty = 0; - const { fault: fault, rpcId: id, rpc: acsRequest } = await session.rpcRequest( - sessionContext, - null - ); + const { + fault: fault, + rpcId: id, + rpc: acsRequest, + } = await session.rpcRequest(sessionContext, null); if (fault) { recordFault(sessionContext, fault); @@ -605,10 +607,11 @@ async function applyPresets(sessionContext: SessionContext): Promise { } async function nextRpc(sessionContext: SessionContext): Promise { - const { fault: fault, rpcId: id, rpc: acsRequest } = await session.rpcRequest( - sessionContext, - null - ); + const { + fault: fault, + rpcId: id, + rpc: acsRequest, + } = await session.rpcRequest(sessionContext, null); if (fault) { recordFault(sessionContext, fault); @@ -1370,7 +1373,8 @@ async function listenerAsync( let sessionId; // Separation by comma is important as some devices don't comform to standard - const COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g; + const COOKIE_REGEX = + /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g; let match; while ((match = COOKIE_REGEX.exec(httpRequest.headers.cookie))) if (match[1] === "session") sessionId = match[2]; diff --git a/lib/db.ts b/lib/db.ts index 52d1419..b9be591 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -534,9 +534,8 @@ export async function saveDevice( } if (attributesTimestamp2 !== attributesTimestamp1) { - update["$set"][ - path.toString() + "._attributesTimestamp" - ] = new Date(attributesTimestamp2); + update["$set"][path.toString() + "._attributesTimestamp"] = + new Date(attributesTimestamp2); } break; @@ -554,9 +553,8 @@ export async function saveDevice( } if (attributesTimestamp2 !== attributesTimestamp1) { - update["$set"][ - path.toString() + "._attributesTimestamp" - ] = new Date(attributesTimestamp2); + update["$set"][path.toString() + "._attributesTimestamp"] = + new Date(attributesTimestamp2); } } } @@ -804,7 +802,7 @@ interface Permission { } export async function getPermissions(): Promise { - return (permissionsCollection.find().toArray() as unknown) as Permission[]; + return permissionsCollection.find().toArray() as unknown as Permission[]; } interface User { @@ -815,5 +813,5 @@ interface User { } export async function getUsers(): Promise { - return (usersCollection.find().toArray() as unknown) as User[]; + return usersCollection.find().toArray() as unknown as User[]; } diff --git a/lib/local-cache.ts b/lib/local-cache.ts index 386871a..5994d57 100644 --- a/lib/local-cache.ts +++ b/lib/local-cache.ts @@ -266,9 +266,7 @@ async function fetchProvisions(): Promise { .createHash("md5") .update(r["script"]) .digest("hex"); - provisions[ - r["_id"] - ].script = new vm.Script( + provisions[r["_id"]].script = new vm.Script( `"use strict";(function(){\n${r["script"]}\n})();`, { filename: r["_id"], lineOffset: -1, timeout: 50 } ); @@ -287,9 +285,7 @@ async function fetchVirtualParameters(): Promise { .createHash("md5") .update(r["script"]) .digest("hex"); - virtualParameters[ - r["_id"] - ].script = new vm.Script( + virtualParameters[r["_id"]].script = new vm.Script( `"use strict";(function(){\n${r["script"]}\n})();`, { filename: r["_id"], lineOffset: -1, timeout: 50 } ); diff --git a/lib/logger.ts b/lib/logger.ts index 57bfabc..f812bf3 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -292,11 +292,9 @@ function formatSimple( return `${severity}${remote}${details.message}${meta}${os.EOL}`; } - return `${ - details.timestamp - } [${(details.severity as string).toUpperCase()}] ${remote}${ - details.message - }${meta}${os.EOL}`; + return `${details.timestamp} [${( + details.severity as string + ).toUpperCase()}] ${remote}${details.message}${meta}${os.EOL}`; } function log(details: Record): void { diff --git a/lib/nbi.ts b/lib/nbi.ts index 02c32a5..e53c18a 100644 --- a/lib/nbi.ts +++ b/lib/nbi.ts @@ -33,7 +33,8 @@ import { flattenDevice } from "./mongodb-functions"; const DEVICE_TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/tasks\/?$/; const TASKS_REGEX = /^\/tasks\/([a-zA-Z0-9\-_%]+)(\/[a-zA-Z_]*)?$/; -const TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/tags\/([a-zA-Z0-9\-_%]+)\/?$/; +const TAGS_REGEX = + /^\/devices\/([a-zA-Z0-9\-_%]+)\/tags\/([a-zA-Z0-9\-_%]+)\/?$/; const PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-_%]+)\/?$/; const OBJECTS_REGEX = /^\/objects\/([a-zA-Z0-9\-_%]+)\/?$/; const FILES_REGEX = /^\/files\/([a-zA-Z0-9%!*'();:@&=+$,?#[\]\-_.~]+)\/?$/; @@ -41,7 +42,8 @@ const PING_REGEX = /^\/ping\/([a-zA-Z0-9\-_.:]+)\/?$/; const QUERY_REGEX = /^\/([a-zA-Z0-9_]+)\/?$/; const DELETE_DEVICE_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/?$/; const PROVISIONS_REGEX = /^\/provisions\/([a-zA-Z0-9\-_%]+)\/?$/; -const VIRTUAL_PARAMETERS_REGEX = /^\/virtual_parameters\/([a-zA-Z0-9\-_%]+)\/?$/; +const VIRTUAL_PARAMETERS_REGEX = + /^\/virtual_parameters\/([a-zA-Z0-9\-_%]+)\/?$/; const FAULTS_REGEX = /^\/faults\/([a-zA-Z0-9\-_%:]+)\/?$/; const collections: Record = { @@ -680,9 +682,9 @@ export function listener( productClass: request.headers.productclass, version: request.headers.version, }; - filesBucket.delete((filename as unknown) as ObjectId, () => { + filesBucket.delete(filename as unknown as ObjectId, () => { const uploadStream = filesBucket.openUploadStreamWithId( - (filename as unknown) as ObjectId, + filename as unknown as ObjectId, filename, { metadata: metadata, @@ -699,7 +701,7 @@ export function listener( }); }); } else if (request.method === "DELETE") { - filesBucket.delete((filename as unknown) as ObjectId, (err) => { + filesBucket.delete(filename as unknown as ObjectId, (err) => { if (err) { if (err.message.startsWith("FileNotFound")) { response.writeHead(404); diff --git a/lib/ping.ts b/lib/ping.ts index e2801a5..6bf9ca5 100644 --- a/lib/ping.ts +++ b/lib/ping.ts @@ -39,16 +39,20 @@ export function ping( switch (platform()) { case "linux": cmd = `ping -w 1 -i 0.2 -c 3 ${host}`; - parseRegExp1 = /(\d+) packets transmitted, (\d+) received, ([\d.]+)% packet loss[^]*([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+)/; - parseRegExp2 = /(\d+) packets transmitted, (\d+) received, ([\d.]+)% packet loss/; + parseRegExp1 = + /(\d+) packets transmitted, (\d+) received, ([\d.]+)% packet loss[^]*([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+)/; + parseRegExp2 = + /(\d+) packets transmitted, (\d+) received, ([\d.]+)% packet loss/; break; case "freebsd": // Send a single packet because on FreeBSD only superuser can send // packets that are only 200 ms apart. cmd = `ping -t 1 -c 3 ${host}`; - parseRegExp1 = /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss\nround-trip min\/avg\/max\/stddev = ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+) ms/; - parseRegExp2 = /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss/; + parseRegExp1 = + /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss\nround-trip min\/avg\/max\/stddev = ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+) ms/; + parseRegExp2 = + /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss/; break; default: diff --git a/lib/session.ts b/lib/session.ts index 8c5d756..e5f4271 100644 --- a/lib/session.ts +++ b/lib/session.ts @@ -1113,9 +1113,8 @@ export async function rpcRequest( if (_declarations?.length) { delete sessionContext.syncState; if (!sessionContext.declarations[0]) sessionContext.declarations[0] = []; - sessionContext.declarations[0] = sessionContext.declarations[0].concat( - _declarations - ); + sessionContext.declarations[0] = + sessionContext.declarations[0].concat(_declarations); return rpcRequest(sessionContext, null); } @@ -2933,13 +2932,9 @@ export async function rpcFault( (p) => [Path.parse(p.replace(/\.$/, "")), timestamp] as Clear ); } else if (rpcReq.name === "SetParameterValues") { - toClear = (rpcReq.parameterList as [ - string, - string | number | boolean, - string - ][]).map( - (p) => [Path.parse(p[0].replace(/\.$/, "")), timestamp] as Clear - ); + toClear = ( + rpcReq.parameterList as [string, string | number | boolean, string][] + ).map((p) => [Path.parse(p[0].replace(/\.$/, "")), timestamp] as Clear); } else if (rpcReq.name === "AddObject") { toClear = [[Path.parse(rpcReq.objectName.replace(/\.$/, "")), timestamp]]; } else if (rpcReq.name === "DeleteObject") { @@ -2976,10 +2971,10 @@ export async function deserialize( const sessionContext = JSON.parse(sessionContextString) as SessionContext; for (const decs of sessionContext.declarations) - for (const d of decs) d.path = Path.parse((d.path as unknown) as string); + for (const d of decs) d.path = Path.parse(d.path as unknown as string); const deviceData = initDeviceData(); - for (const r of (sessionContext.deviceData as unknown) as any[]) { + for (const r of sessionContext.deviceData as unknown as any[]) { const path = deviceData.paths.add(Path.parse(r[0])); if (r[1]) deviceData.trackers.set(path, r[1]); diff --git a/lib/ui.ts b/lib/ui.ts index dff76a1..994959a 100644 --- a/lib/ui.ts +++ b/lib/ui.ts @@ -221,7 +221,8 @@ router.post("/init", async (ctx) => { }); router.get("/", async (ctx) => { - const permissionSets: PermissionSet[] = ctx.state.authorizer.getPermissionSets(); + const permissionSets: PermissionSet[] = + ctx.state.authorizer.getPermissionSets(); let wizard = ""; if (!Object.keys(localCache.getUsers(ctx.state.configSnapshot)).length) diff --git a/lib/ui/db.ts b/lib/ui/db.ts index cdacbb4..17ba630 100644 --- a/lib/ui/db.ts +++ b/lib/ui/db.ts @@ -339,7 +339,7 @@ export function putFile( return new Promise((resolve, reject) => { const bucket = new GridFSBucket(db); const uploadStream = bucket.openUploadStreamWithId( - (filename as unknown) as ObjectId, + filename as unknown as ObjectId, filename, { metadata: metadata, diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 86aeed7..9a74d34 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -10023,9 +10023,9 @@ "dev": true }, "prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz", + "integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==", "dev": true }, "pretty-ms": { diff --git a/package.json b/package.json index c355908..0aef89e 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "postcss": "^8.2.8", "postcss-import": "^14.0.0", "postcss-preset-env": "^6.7.0", - "prettier": "^2.2.1", + "prettier": "^2.4.1", "rollup": "^2.41.2", "rollup-plugin-terser": "^7.0.2", "sql.js": "^1.6.1", diff --git a/ui/store.ts b/ui/store.ts index c2353e9..1107bec 100644 --- a/ui/store.ts +++ b/ui/store.ts @@ -609,9 +609,8 @@ export function postTasks( if (xhr.status === 403) throw new Error("Not authorized"); if (!xhr.status) throw new Error("Server is unreachable"); if (xhr.status !== 200) throw new Error(xhr.response); - const connectionRequestStatus = xhr.getResponseHeader( - "Connection-Request" - ); + const connectionRequestStatus = + xhr.getResponseHeader("Connection-Request"); const st = JSON.parse(xhr.response); for (const [i, t] of st.entries()) { tasks[i]._id = t._id; diff --git a/ui/ui-config-component.ts b/ui/ui-config-component.ts index 7bff810..0ed6ca6 100644 --- a/ui/ui-config-component.ts +++ b/ui/ui-config-component.ts @@ -65,7 +65,7 @@ function putActionHandler(prefix: string[], dataYaml: string): Promise { store.putResource( "config", obj._id, - (obj as unknown) as Record + obj as unknown as Record ) ); }