New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@db-auto/tables

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@db-auto/tables - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

dist/src/queryParams.d.ts

1

dist/index.d.ts

@@ -7,1 +7,2 @@ export * from './src/tables';

export * from './src/query.fixture';
export * from './src/queryParams';

@@ -24,1 +24,2 @@ "use strict";

__exportStar(require("./src/query.fixture"), exports);
__exportStar(require("./src/queryParams"), exports);

22

dist/src/clean.spec.js

@@ -56,24 +56,14 @@ "use strict";

expect((0, tables_1.cleanTable)(query_fixture_1.tables.mission, "mission")).toEqual({
"dataColumns": {
"age": { "type": "integer" },
"dateOfBirth": { "type": "date" },
"livesIn": { "type": "string" },
"personalCar": {}
},
"links": {
"audit": { "idHereAndThere": "driverId", "type": "one-to-many", "table": "driver_aud" },
"mission": { "idHereAndThere": "driverId", "type": "one-to-many" }
"driver": { "idHereAndThere": "driverId", "type": "many-to-one" },
"mission_aud": { "idHereAndThere": "missionId", "type": "one-to-many" }
},
"primary": { "name": "id", "type": "integer" },
"primary": "id",
"queries": {
"employeeNum": { "type": "string" },
"name": { "description": "driver name ", "type": "string" }
"date": { "type": "date" }
},
"table": "DriverTable",
"views": {
"all": "*",
"short": ["id", "name"]
}
"table": "mission",
"views": { "all": "*", "short": ["id", "driverId"] }
});
});
});

@@ -9,2 +9,3 @@ "use strict";

"links": { title: "Links", dataFn: (t) => (0, utils_1.mapEntries)(t[1].links, (l, name) => name).join(',') },
"params": { title: "Params", dataFn: (t) => (0, utils_1.mapEntries)(t[1].queries, (q, name) => name).join(',') },
"views": { title: "Views", dataFn: (t) => (0, utils_1.mapEntries)(t[1].views, (v, name) => name).join(',') }

@@ -11,0 +12,0 @@ };

@@ -18,2 +18,2 @@ import { ErrorsAnd, NameAnd } from "@db-auto/utils";

}
export declare function buildPlan(tables: NameAnd<CleanTable>, path: string[], id?: string): ErrorsAnd<Plan | undefined>;
export declare function buildPlan(tables: NameAnd<CleanTable>, path: string[], id?: string, queryParams?: NameAnd<string>): ErrorsAnd<Plan | undefined>;

@@ -6,12 +6,22 @@ "use strict";

function quoteIfNeeded(type, s) {
return type === 'string' || type.includes('char') ? `'${s}'` : s;
return type === 'string' || type.includes('char') || type.includes('date') || type.includes('time') ? `'${s}'` : s;
}
function buildPlan(tables, path, id) {
function makeWhere(id, queryParams, alias, table) {
const whereFromId = id ? [`${alias}.${table.primary}=${quoteIfNeeded(table.keys[table.primary].type, id)}`] : [];
const whereFromParams = (0, utils_1.flatMapEntries)(table.queries, (q, n) => {
const name = q.name || n;
const inParams = queryParams[name];
return inParams !== undefined ? [`${alias}.${n}=${quoteIfNeeded(q.type, inParams)}`] : [];
});
return [...whereFromId, ...whereFromParams];
}
function buildPlan(tables, path, id, queryParams) {
if (path.length === 0)
return ['Cannot build plan for empty path'];
const params = queryParams || {};
let table = tables[path[0]];
let alias = `T${0}`;
const where = id ? [`${alias}.${table.primary}=${quoteIfNeeded(table.keys[table.primary].type, id)}`] : [];
const where = makeWhere(id, params, alias, table);
const plan = { table, alias: alias, where };
return buildNextStep(tables, path, plan, 1);
return buildNextStep(tables, path, params, plan, 1);
}

@@ -25,3 +35,3 @@ exports.buildPlan = buildPlan;

}
function buildNextStep(tables, path, previousPlan, index) {
function buildNextStep(tables, path, params, previousPlan, index) {
if (index >= path.length)

@@ -35,6 +45,8 @@ return previousPlan;

const table = tables[link.table];
let alias = `T${index}`;
const where = makeWhere(undefined, params, alias, table);
if (table === undefined)
return [`Cannot find table ${p} in tables. Path is ${path.slice(0, index)}. Available tables are: ${Object.keys(tables)}`];
const plan = { table, alias: `T${index}`, linkToPrevious: { link, linkTo: previousPlan }, where: [] };
return buildNextStep(tables, path, plan, index + 1);
const plan = { table, alias, linkToPrevious: { link, linkTo: previousPlan }, where };
return buildNextStep(tables, path, params, plan, index + 1);
}
{
"name": "@db-auto/tables",
"description": "",
"version": "0.0.11",
"version": "0.0.12",
"main": "dist/index",

@@ -20,3 +20,3 @@ "types": "dist/index",

"dependencies": {
"@db-auto/utils": "0.0.11"
"@db-auto/utils": "0.0.12"
},

@@ -23,0 +23,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc