Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dbpath/dal

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dbpath/dal - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

dist/src/path.d.ts

1

dist/src/dal.d.ts

@@ -25,2 +25,3 @@ import { NameAnd } from "@dbpath/utils";

columns: NameAnd<ColumnMetaData>;
pk: string[];
fk: NameAnd<ForeignKeyMetaData>;

@@ -27,0 +28,0 @@ }

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

},
pk: [],
"fk": {

@@ -42,2 +43,3 @@ "fk_driver_aud_driver": {

},
pk: ["driverid"],
"fk": {

@@ -59,2 +61,3 @@ "fk_driver_aud_driver": {

"mission": {
pk: ["id"],
"columns": {

@@ -87,2 +90,3 @@ "driverid": {

"mission_aud": {
pk: [],
"columns": {

@@ -89,0 +93,0 @@ "id": {

import { Summary } from "@dbpath/config";
import { DatabaseMetaData } from "./dal";
import { ErrorsAnd } from "@dbpath/utils";
export interface TwoIds {

@@ -17,2 +18,3 @@ fromId: string;

validateLink: ValidateLinkFn;
useIdsOrSingleFkLinkOrError(fromTableName: string, toTableName: string, idEquals: TwoIds[]): TwoIds[];
}

@@ -22,2 +24,6 @@ export declare const PathValidatorAlwaysOK: PathValidator;

export declare const validateFields: (summary: Summary, m: DatabaseMetaData) => ValidateFieldsFn;
export declare function getSingleFkLink(summary: Summary, m: DatabaseMetaData, fromTableName: string, toTableName: string): ErrorsAnd<TwoIds>;
/** This should not throw an exception if the validation says there is a link */
export declare const useIdsOrSingleFkLinkOrError: (summary: Summary, m: DatabaseMetaData) => (fromTableName: string, toTableName: string, idEquals: TwoIds[]) => TwoIds[];
export declare const validateLinks: (summary: Summary, m: DatabaseMetaData) => ValidateLinkFn;
export declare function DalPathValidator(summary: Summary, m: DatabaseMetaData): PathValidator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateLinks = exports.validateFields = exports.validateTableName = exports.PathValidatorAlwaysOK = void 0;
exports.DalPathValidator = exports.validateLinks = exports.useIdsOrSingleFkLinkOrError = exports.getSingleFkLink = exports.validateFields = exports.validateTableName = exports.PathValidatorAlwaysOK = void 0;
const utils_1 = require("@dbpath/utils");

@@ -8,3 +8,6 @@ exports.PathValidatorAlwaysOK = {

validateFields: () => [],
validateLink: () => []
validateLink: () => [],
useIdsOrSingleFkLinkOrError(fromTableName, toTableName, idEquals) {
return idEquals;
}
};

@@ -46,3 +49,5 @@ function checkFullTableName(m, tableName) {

exports.validateFields = validateFields;
function validateLinksInFks(fromTableName, fromTable, toTableName, toTable) {
function getSingleFkLink(summary, m, fromTableName, toTableName) {
const fromTable = getTableMetaData(summary, m, fromTableName);
const found = (0, utils_1.mapEntries)((0, utils_1.safeObject)(fromTable.fk), fk => fk).filter(table => table.refTable === toTableName);
function error(msg) {

@@ -52,3 +57,2 @@ const nameToFkLinks = (0, utils_1.mapEntries)((0, utils_1.safeObject)(fromTable.fk), v => ` ${fromTableName}.(${v.column},${v.refColumn})${v.refTable}`);

}
const found = (0, utils_1.mapEntries)((0, utils_1.safeObject)(fromTable.fk), fk => fk.refTable).filter(table => table === toTableName);
if (found.length === 0)

@@ -58,2 +62,21 @@ return error(`No foreign key from ${fromTableName} to ${toTableName}`);

return error(`More than one foreign key from ${fromTableName} to ${toTableName}`);
const result = { fromId: found[0].column, toId: found[0].refColumn };
return result;
}
exports.getSingleFkLink = getSingleFkLink;
/** This should not throw an exception if the validation says there is a link */
const useIdsOrSingleFkLinkOrError = (summary, m) => (fromTableName, toTableName, idEquals) => {
if (idEquals.length === 0) {
const found = getSingleFkLink(summary, m, fromTableName, toTableName);
if ((0, utils_1.hasErrors)(found))
throw Error(`Single FK link not found\n${found}`);
return [found];
}
return idEquals;
};
exports.useIdsOrSingleFkLinkOrError = useIdsOrSingleFkLinkOrError;
function validateLinksInFks(summary, m, fromTableName, toTableName) {
const found = getSingleFkLink(summary, m, fromTableName, toTableName);
if ((0, utils_1.hasErrors)(found))
return found;
return [];

@@ -68,6 +91,6 @@ }

return (fromTableName, toTableName, idEquals) => {
if (idEquals.length === 0)
return validateLinksInFks(summary, m, fromTableName, toTableName);
const fromTable = getTableMetaData(summary, m, fromTableName);
const toTable = getTableMetaData(summary, m, toTableName);
if (idEquals.length === 0)
return validateLinksInFks(fromTableName, fromTable, toTableName, toTable);
const notInFromTable = notInError(fromTableName, fromTable)(idEquals.filter(i => !fromTable.columns[i.fromId]).map(t => t.fromId));

@@ -79,1 +102,10 @@ const notInToTable = notInError(toTableName, toTable)(idEquals.filter(i => !toTable.columns[i.toId]).map(t => t.toId));

exports.validateLinks = validateLinks;
function DalPathValidator(summary, m) {
return {
validateTableName: (0, exports.validateTableName)(summary, m),
validateFields: (0, exports.validateFields)(summary, m),
validateLink: (0, exports.validateLinks)(summary, m),
useIdsOrSingleFkLinkOrError: (0, exports.useIdsOrSingleFkLinkOrError)(summary, m)
};
}
exports.DalPathValidator = DalPathValidator;

4

package.json
{
"name": "@dbpath/dal",
"description": "",
"version": "0.2.1",
"version": "0.2.2",
"main": "dist/index",

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

"dependencies": {
"@dbpath/config": "0.2.1"
"@dbpath/config": "0.2.2"
},

@@ -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