From 2585832406b48d1764ac335d9fcf9c07560e4b11 Mon Sep 17 00:00:00 2001 From: Lars-Erik Roald Date: Sun, 7 Jul 2024 11:13:08 +0200 Subject: [PATCH] lint --- package.json | 6 +- src/getManyDto.js | 293 ++-------------------------------------------- 2 files changed, 12 insertions(+), 287 deletions(-) diff --git a/package.json b/package.json index 00dd4e59..2ebe4ea5 100644 --- a/package.json +++ b/package.json @@ -104,11 +104,11 @@ "devDependencies": { "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-node-resolve": "^13.0.0", - "@typescript-eslint/eslint-plugin": "^5.42.1", - "@typescript-eslint/parser": "^5.42.1", + "@typescript-eslint/eslint-plugin": "^6.x", + "@typescript-eslint/parser": "^6.x", "@vitest/coverage-v8": "^0.34.1", "cors": "^2.8.5", - "eslint": "^8.6.0", + "eslint": "^8.57.0", "eslint-plugin-jest": "^27.1.7", "express": "^4.18.2", "msnodesqlv8": "^4.1.0", diff --git a/src/getManyDto.js b/src/getManyDto.js index 7fe01ef5..139651c4 100644 --- a/src/getManyDto.js +++ b/src/getManyDto.js @@ -28,7 +28,7 @@ function newCreateRow(span) { const c = {}; c.visitJoin = () => { }; c.visitOne = () => { }; - c.visitMany = function (leg) { + c.visitMany = function(leg) { manyNames.push(leg.name); }; @@ -58,11 +58,11 @@ function createProto(columns, span) { } const c = {}; - c.visitJoin = function (leg) { + c.visitJoin = function(leg) { obj[leg.name] = null; }; c.visitOne = c.visitJoin; - c.visitMany = function (leg) { + c.visitMany = function(leg) { obj[leg.name] = null; }; @@ -80,7 +80,7 @@ function hasManyRelations(span) { const c = {}; c.visitJoin = () => { }; c.visitOne = c.visitJoin; - c.visitMany = function () { + c.visitMany = function() { result = true; }; @@ -108,7 +108,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys const outRows = new Array(rowsLength); const createRow = newCreateRow(span); const shouldCreateMap = hasManyRelations(span); - let all = [];; + let all = []; for (let i = 0; i < rowsLength; i++) { const row = rows[i]; @@ -161,58 +161,6 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys if (span.legs.toArray().length === 0) return outRows; - //alt 1 - // 3.1 sec - // await new Promise((resolve, reject) => { - // setTimeout(() => { - // if (shouldCreateMap) - // decodeManyRelations(strategy, span, rows, outRows, keys) - // .then(() => decodeRelations2(strategy, span, rows, outRows, keys)) - // .then(resolve) - // .catch(reject); - // else - // decodeRelations2(strategy, span, rows, outRows, keys) - // .then(resolve) - // .catch(reject); - // }, 0); - // }); - - - //alt 1 - // 3.2 sec - // await new Promise((resolve, reject) => { - // setTimeout(() => { - // const all = []; - // if (shouldCreateMap) - // all.push(decodeManyRelations(strategy, span, rows, outRows, keys)) - - // all.push(new Promise((resolve, reject) => { - // setTimeout(async () => { - // await decodeRelations2(strategy, span, rows, outRows, keys); - // resolve(); - - // }, 0); - // })); - // // const p2 = decodeRelations2(strategy, span, rows, outRows, keys); - // Promise.all(all).then(resolve, reject); - // }, 0); - // }); - - - // let all = [];; - // if(shouldCreateMap) { - - // await decodeManyRelations(strategy, span, rows, outRows, keys).then(() => decodeRelations2(strategy, span, rows, outRows, keys)); - // } - // else - // await decodeRelations2(strategy, span, rows, outRows, keys); - - // await Promise.all(all); - - - - //alt 3 - // 3.05 sec if (shouldCreateMap) { // all.push( decodeRelations2(strategy, span, rows, outRows, keys).then(() => decodeManyRelations(strategy, span))); @@ -221,50 +169,15 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys // all.push( decodeManyRelations(strategy, span).then(() => decodeRelations2(strategy, span, rows, outRows, keys))); // all.push( decodeManyRelations(strategy, span)); // all.push(decodeRelations2(strategy, span, rows, outRows, keys)); - // all.push( decodeRelations2(strategy, span, rows, outRows, keys) ); + // all.push( decodeRelations2(strategy, span, rows, outRows, keys) ); } else all.push(decodeRelations2(strategy, span, rows, outRows, keys)); await Promise.all(all); - - //alt 4 - // 3.02 sec - // const all = []; - // if (shouldCreateMap) - // // all.push(new Promise((resolve, reject) => { - // // setTimeout(async () => { - // // await decodeManyRelations(strategy, span); - // // resolve(); - - // // }, 0) - // // })); - // all.push(decodeManyRelations(strategy, span)); - // all.push(new Promise((resolve, reject) => { - // setTimeout(async () => { - // await decodeRelations2(strategy, span, rows, outRows, keys); - // resolve(); - - // }, 0); - // })); - // await Promise.all(all); - - // all.push(decodeRelations2(strategy, span, rows, outRows, keys)); - - //alt 4 - // 3.3 sec - // if(shouldCreateMap) - // await decodeRelations(strategy, span, rows, outRows, keys); - // else - // await decodeRelations2(strategy, span, rows, outRows, keys); - - // await decodeRelationsNext(strategy, span, rows, outRows, keys); - // await decodeRelations(strategy, span, rows, outRows, keys); - return outRows; - function createGetIds() { const primaryColumns = table._primaryColumns; const length = primaryColumns.length; @@ -289,7 +202,7 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) { return; const promises = []; const c = {}; - c.visitJoin = function (leg) { + c.visitJoin = function(leg) { const name = leg.name; const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => { for (let i = 0; i < rows.length; i++) { @@ -321,41 +234,15 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) { await Promise.all(promises); } -async function decodeRelations3(strategy, span, rawRows, resultRows, keys) { - const promises = []; - const c = {}; - c.visitJoin = function (leg) { - const name = leg.name; - const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => { - for (let i = 0; i < rows.length; i++) { - resultRows[i][name] = rows[i]; - } - }); - promises.push(p); - }; - - c.visitOne = c.visitJoin; - - c.visitMany = () => { }; - - - span.legs.forEach(onEachLeg); - - function onEachLeg(leg) { - leg.accept(c); - } - - await Promise.all(promises); -} -async function decodeManyRelations(strategy, span, rawRows, resultRows, keys) { +async function decodeManyRelations(strategy, span) { const promises = []; const c = {}; c.visitJoin = () => { }; c.visitOne = c.visitJoin; - c.visitMany = function (leg) { + c.visitMany = function(leg) { const name = leg.name; const table = span.table; const relation = table._relations[name]; @@ -371,168 +258,6 @@ async function decodeManyRelations(strategy, span, rawRows, resultRows, keys) { promises.push(p); }; - span.legs.forEach(onEachLeg); - - function onEachLeg(leg) { - leg.accept(c); - } - - // await Promise.all(promises); - // } - - // async function decodeRelations2(strategy, span, rawRows, resultRows, keys) { - // const promises = []; - // const c = {}; - // c.visitJoin = function (leg) { - // const name = leg.name; - // //todo avoid traverse twice noMany relations below - // const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => { - // for (let i = 0; i < rows.length; i++) { - // resultRows[i][name] = rows[i]; - // } - // }); - // promises.push(p); - // }; - - // c.visitOne = c.visitJoin; - - // c.visitMany = () => { }; - - // span.legs.forEach(onEachLeg); - - // function onEachLeg(leg) { - // leg.accept(c); - // } - - await Promise.all(promises); -} - -async function decodeRelations3(strategy, span, rawRows, resultRows, keys) { - - let previous = new Promise((resolve) => setImmediate(() => resolve())); - const c = {}; - - c.visitJoin = function (leg) { - const name = leg.name; - const p = new Promise((resolve) => { - setImmediate(() => { - decode(strategy[name], leg.span, rawRows, keys).then((rows) => { - for (let i = 0; i < rows.length; i++) { - resultRows[i][name] = rows[i]; - } - resolve(); - }); - }); - }); - previous = previous.then(() => p); - }; - - c.visitOne = c.visitJoin; - - c.visitMany = () => { }; - - span.legs.forEach(onEachLeg); - - function onEachLeg(leg) { - leg.accept(c); - } - - await previous; - -} - - -async function decodeRelationsNext(strategy, span, rawRows, resultRows, keys) { - // const promises = []; - let previous = new Promise((resolve) => setImmediate(() => resolve())); - const c = {}; - - c.visitJoin = function (leg) { - const name = leg.name; - const p = new Promise((resolve) => { - setImmediate(() => { - decode(strategy[name], leg.span, rawRows, keys).then((rows) => { - for (let i = 0; i < rows.length; i++) { - resultRows[i][name] = rows[i]; - } - resolve(); - }); - }); - }); - previous = previous.then(() => p); - }; - - c.visitOne = c.visitJoin; - - c.visitMany = function (leg) { - const p = new Promise((resolve, reject) => { - setImmediate(() => { - - const name = leg.name; - const table = span.table; - const relation = table._relations[name]; - const filter = createOneFilter(relation, span._ids); - const rowsMap = span._rowsMap; - - getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => { - for (let i = 0; i < subRows.length; i++) { - const key = leg.columns.map(column => subRows[i][column.alias]); - const parentRow = getFromMap(rowsMap, table._primaryColumns, key); - parentRow[name].push(subRows[i]); - } - }).then(() => resolve(), reject); - - - }); - }); - - - previous = previous.then(() => p); - // promises.push(p); - }; - - span.legs.forEach(onEachLeg); - - function onEachLeg(leg) { - leg.accept(c); - } - - await previous -} - - -async function decodeRelations(strategy, span, rawRows, resultRows, keys) { - const promises = []; - const c = {}; - c.visitJoin = function (leg) { - const name = leg.name; - const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => { - for (let i = 0; i < rows.length; i++) { - resultRows[i][name] = rows[i]; - } - }); - promises.push(p); - }; - - c.visitOne = c.visitJoin; - - c.visitMany = function (leg) { - const name = leg.name; - const table = span.table; - const relation = table._relations[name]; - const filter = createOneFilter(relation, span._ids); - const rowsMap = span._rowsMap; - const p = getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => { - for (let i = 0; i < subRows.length; i++) { - const key = leg.columns.map(column => subRows[i][column.alias]); - const parentRow = getFromMap(rowsMap, table._primaryColumns, key); - parentRow[name].push(subRows[i]); - } - }); - promises.push(p); - }; - - span.legs.forEach(onEachLeg); function onEachLeg(leg) {