Update Prettier
This commit is contained in:
1 parent
9e1d7eca9b
commit
9706026ea5
16 files changed
+83
-86
No files matched your search
+3
-3
@@ -52,9 +52,9 @@ function parseHeaderFeilds(str: string): Record<string, string> {
|
||||
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 };
|
||||
|
||||
+1
-1
@@ -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" }
|
||||
);
|
||||
|
||||
@@ -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];
|
||||
|
||||
+17
-13
@@ -497,10 +497,11 @@ async function applyPresets(sessionContext: SessionContext): Promise<void> {
|
||||
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<void> {
|
||||
|
||||
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<void> {
|
||||
}
|
||||
|
||||
async function nextRpc(sessionContext: SessionContext): Promise<void> {
|
||||
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];
|
||||
|
||||
@@ -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<Permission[]> {
|
||||
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<User[]> {
|
||||
return (usersCollection.find().toArray() as unknown) as User[];
|
||||
return usersCollection.find().toArray() as unknown as User[];
|
||||
}
|
||||
+2
-6
@@ -266,9 +266,7 @@ async function fetchProvisions(): Promise<Provisions> {
|
||||
.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<VirtualParameters> {
|
||||
.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 }
|
||||
);
|
||||
|
||||
+3
-5
@@ -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<string, unknown>): void {
|
||||
|
||||
+7
-5
@@ -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<string, Collection> = {
|
||||
@@ -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);
|
||||
|
||||
+8
-4
@@ -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:
|
||||
|
||||
+7
-12
@@ -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]);
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Generated
+3
-3
@@ -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": {
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
@@ -65,7 +65,7 @@ function putActionHandler(prefix: string[], dataYaml: string): Promise<any> {
|
||||
store.putResource(
|
||||
"config",
|
||||
obj._id,
|
||||
(obj as unknown) as Record<string, unknown>
|
||||
obj as unknown as Record<string, unknown>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user