@dbpath/pathparser
Advanced tools
Comparing version 0.2.4 to 0.2.6
@@ -1,3 +0,2 @@ | ||
export * from './src/path'; | ||
export * from './src/parser'; | ||
export * from './src/tokeniser'; |
@@ -17,4 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./src/path"), exports); | ||
__exportStar(require("./src/parser"), exports); | ||
__exportStar(require("./src/tokeniser"), exports); |
import { Token } from "./tokeniser"; | ||
import { ErrorsAnd } from "@dbpath/utils"; | ||
import { PathValidator, TwoIds } from "@dbpath/dal"; | ||
import { LinkInPath, PathItem, TableInPath } from "./path"; | ||
import { PathValidator } from "@dbpath/dal"; | ||
import { LinkInPath, PathItem, TableInPath, TwoIds } from "@dbpath/types"; | ||
export interface TableAndFullTableName { | ||
@@ -28,3 +28,3 @@ table: string; | ||
export declare const parseTable: (context: ParserContext) => ResultAndContext<TableInPath>; | ||
export declare const parseTableAndNextLink: (previousTable: TableInPath | undefined, idEquals: TwoIds[]) => PathParser<LinkInPath>; | ||
export declare const parseTableAndNextLink: (previousLink: TableInPath | undefined, idEquals: TwoIds[]) => PathParser<LinkInPath>; | ||
export declare const parseLink: (previousTable: TableInPath | undefined) => PathParser<LinkInPath>; | ||
@@ -31,0 +31,0 @@ export declare const parseTableAndLinks: PathParser<PathItem>; |
@@ -86,7 +86,4 @@ "use strict"; | ||
return mapParser((0, exports.identifier)('table name')(context), (c, tableName) => { | ||
if (isNextChar(c, '!')) { | ||
return mapParser(nextChar(c, '!'), (c) => mapParser((0, exports.identifier)('full table name')(c), (c, fullTableName) => validateAndReturn(context, c, { table: tableName, fullTable: fullTableName }, context.validator.validateTableName(tableName, fullTableName)))); | ||
} | ||
else | ||
return validateAndReturn(context, c, { table: tableName }, c.validator.validateTableName(tableName)); | ||
const table = context.validator.actualTableName(tableName); | ||
return validateAndReturn(context, c, { table }, c.validator.validateTableName(table)); | ||
}); | ||
@@ -97,5 +94,6 @@ } | ||
exports.parseTable = parseTable; | ||
const parseTableAndNextLink = (previousTable, idEquals) => context => mapParser((0, exports.parseTable)(context), (c, table) => { | ||
let thisLink = Object.assign(Object.assign({}, table), { previousTable, idEquals }); | ||
const errors = c.validator.validateLink(previousTable === null || previousTable === void 0 ? void 0 : previousTable.table, table.table, idEquals); | ||
const parseTableAndNextLink = (previousLink, idEquals) => context => mapParser((0, exports.parseTable)(context), (c, table) => { | ||
const realIdEquals = c.validator.useIdsOrSingleFkLinkOrError(previousLink === null || previousLink === void 0 ? void 0 : previousLink.table, table.table, idEquals); | ||
let thisLink = Object.assign(Object.assign({}, table), { idEquals: realIdEquals, previousLink }); | ||
const errors = c.validator.validateLink(previousLink === null || previousLink === void 0 ? void 0 : previousLink.table, table.table, realIdEquals); | ||
if (errors.length > 0) | ||
@@ -108,3 +106,3 @@ return liftError(context, errors); | ||
exports.parseTableAndNextLink = parseTableAndNextLink; | ||
const parseLink = (previousTable) => c => mapParser(nextChar(c, '.'), c => mapParser(parseBracketedCommaSeparated(c, "(", ',', exports.parseIdEqualsId, ')'), (c, idEquals) => mapParser((0, exports.parseTableAndNextLink)(previousTable, idEquals)(c), (c, link) => lift(c, Object.assign(Object.assign({}, link), { idEquals }))))); | ||
const parseLink = (previousTable) => c => mapParser(nextChar(c, '.'), c => mapParser(parseBracketedCommaSeparated(c, "(", ',', exports.parseIdEqualsId, ')'), (c, idEquals) => (0, exports.parseTableAndNextLink)(previousTable, idEquals)(c))); | ||
exports.parseLink = parseLink; | ||
@@ -111,0 +109,0 @@ const parseTableAndLinks = c => mapParser((0, exports.parseTable)(c), (c, previousLink) => { |
@@ -6,2 +6,4 @@ "use strict"; | ||
const dal_1 = require("@dbpath/dal"); | ||
const fixtures_1 = require("@dbpath/fixtures"); | ||
const validator = Object.assign(Object.assign({}, dal_1.PathValidatorAlwaysOK), { actualTableName: t => (0, dal_1.fullTableName)(fixtures_1.sampleSummary, t) }); | ||
function makeContext(s) { | ||
@@ -11,3 +13,3 @@ return { | ||
pos: 2, | ||
validator: dal_1.PathValidatorAlwaysOK | ||
validator: validator | ||
}; | ||
@@ -42,35 +44,29 @@ } | ||
it("should parse drive", () => { | ||
expect(pt("driver", 1)).toEqual({ table: "driver", fields: [] }); | ||
expect(pt("driver.", 1)).toEqual({ table: "driver", fields: [] }); | ||
expect(pt("driver", 1)).toEqual({ table: "drivertable", fields: [] }); | ||
expect(pt("driver.", 1)).toEqual({ table: "drivertable", fields: [] }); | ||
}); | ||
it("should parse drive!drivertable", () => { | ||
expect(pt("driver!drivertable", 3)).toEqual({ table: "driver", "fullTable": "drivertable", fields: [] }); | ||
expect(pt("driver!drivertable,", 3)).toEqual({ table: "driver", "fullTable": "drivertable", fields: [] }); | ||
it("should parse mission", () => { | ||
expect(pt("mission", 1)).toEqual({ table: "mission", fields: [] }); | ||
expect(pt("mission.", 1)).toEqual({ table: "mission", fields: [] }); | ||
}); | ||
it("should parse driver[field1,field2]", () => { | ||
expect(pt("driver[field1]", 4)).toEqual({ table: "driver", fields: ["field1"] }); | ||
expect(pt("driver[field1,field2]", 6)).toEqual({ table: "driver", fields: ["field1", "field2"] }); | ||
expect(pt("driver[field1]", 4)).toEqual({ table: "drivertable", fields: ["field1"] }); | ||
expect(pt("driver[field1,field2]", 6)).toEqual({ table: "drivertable", fields: ["field1", "field2"] }); | ||
}); | ||
it("should parse drive!drivertable[field1,field2]", () => { | ||
expect(pt("driver[field1,field2]", 6)).toEqual({ table: "driver", fields: ["field1", "field2"] }); | ||
}); | ||
it("should report nice error messages", () => { | ||
// expect ( ptError ( "driver!", 7 ) ).toEqual ( ["Expected a full table name but got to end"] ); | ||
expect(ptError("driver![", 7)).toEqual(["Expected a full table name unexpected character ["]); | ||
expect(ptError("driver!dt[", 10)).toEqual(["Expected a field but got to end"]); | ||
expect(ptError("driver!dt[(]", 10)).toEqual(["Expected a field unexpected character ("]); | ||
expect(ptError("driver[", 7)).toEqual(["Expected a field but got to end"]); | ||
expect(ptError("driver[(]", 7)).toEqual(["Expected a field unexpected character ("]); | ||
}); | ||
}); | ||
describe("parseLink", () => { | ||
it("should parse .drive", () => { | ||
expect(pl(".driver", 2)).toEqual({ table: "driver", fields: [], "idEquals": [], }); | ||
expect(pl(".driver,", 2)).toEqual({ table: "driver", fields: [], "idEquals": [], }); | ||
it("should parse .{table}}", () => { | ||
expect(pl(".driver", 2)).toEqual({ table: "drivertable", fields: [], "idEquals": [], }); | ||
expect(pl(".mission,", 2)).toEqual({ table: "mission", fields: [], "idEquals": [], }); | ||
}); | ||
it("should parse .drive!name[f1,f2]", () => { | ||
const previousTable = pt("someTable", 1); | ||
expect(pl(".driver!name[f1,f2]!!", 9, previousTable)).toEqual({ | ||
"fullTable": "name", | ||
"table": "driver", | ||
it("should parse .driver[f1,f2]", () => { | ||
const previousLink = pt("someTable", 1); | ||
expect(pl(".driver[f1,f2]", 7, previousLink)).toEqual({ | ||
"table": "drivertable", | ||
"fields": ["f1", "f2"], | ||
previousTable, | ||
previousLink, | ||
"idEquals": [], | ||
@@ -80,20 +76,6 @@ }); | ||
it("should parse .drive.mission.audit", () => { | ||
expect(pl(".drive.mission.audit", 6)).toEqual({ | ||
"fields": [], | ||
"idEquals": [], | ||
"previousTable": { | ||
"fields": [], | ||
"idEquals": [], | ||
"previousTable": { | ||
"fields": [], | ||
"idEquals": [], | ||
"table": "drive" | ||
}, | ||
"table": "mission" | ||
}, | ||
"table": "audit" | ||
}); | ||
expect(pl(".driver.mission.audit", 6)).toEqual(fixtures_1.driverMissionAuditPath); | ||
}); | ||
it("should parse .(id1=id2)drive", () => { | ||
expect(pl(".(id1=id2)drive", 7)).toEqual({ | ||
expect(pl(".(id1=id2)driver", 7)).toEqual({ | ||
"fields": [], | ||
@@ -106,32 +88,30 @@ "idEquals": [ | ||
], | ||
"table": "drive" | ||
"table": "drivertable" | ||
}); | ||
}); | ||
it("should parse .drive!fullDrive.mission.audit", () => { | ||
expect(pl(".drive!fullDrive.mission.audit", 8)).toEqual({ | ||
it("should parse .driver.mission.audit", () => { | ||
expect(pl(".driver.mission.audit", 6)).toEqual({ | ||
"fields": [], | ||
"idEquals": [], | ||
"previousTable": { | ||
"previousLink": { | ||
"fields": [], | ||
"idEquals": [], | ||
"previousTable": { | ||
"previousLink": { | ||
"fields": [], | ||
"fullTable": "fullDrive", | ||
"idEquals": [], | ||
"table": "drive" | ||
"table": "drivertable" | ||
}, | ||
"table": "mission" | ||
}, | ||
"table": "audit" | ||
"table": "driver_aud" | ||
}); | ||
}); | ||
it("should parse .drive!fullDrive[f1,f2].(id1=id2)mission[f3].(id3=id4)audit", () => { | ||
expect(pl(".drive!full[f1,f2].mission.audit", 13)).toEqual({ | ||
expect(pl(".driver[f1,f2].mission.audit", 11)).toEqual({ | ||
"fields": [], | ||
"previousTable": { | ||
"previousLink": { | ||
"fields": [], | ||
"previousTable": { | ||
"previousLink": { | ||
"fields": ["f1", "f2"], | ||
"fullTable": "full", | ||
"table": "drive", | ||
"table": "drivertable", | ||
"idEquals": [], | ||
@@ -142,3 +122,3 @@ }, | ||
}, | ||
"table": "audit", | ||
"table": "driver_aud", | ||
"idEquals": [], | ||
@@ -156,29 +136,14 @@ }); | ||
it("should parse a complex path", () => { | ||
expect((0, parser_1.parsePath)(dal_1.PathValidatorAlwaysOK)("driver!full.(id1=id2)mission.audit[f3,f4]")).toEqual({ | ||
"fields": [ | ||
"f3", | ||
"f4" | ||
], | ||
"idEquals": [ | ||
{ | ||
"fromId": "id1", | ||
"toId": "id2" | ||
} | ||
], | ||
"previousTable": { | ||
expect((0, parser_1.parsePath)(validator)("driver.(id1=id2)mission.audit[f3,f4]")).toEqual({ | ||
"fields": ["f3", "f4"], "idEquals": [], | ||
"previousLink": { | ||
"fields": [], | ||
"idEquals": [ | ||
{ | ||
"fromId": "id1", | ||
"toId": "id2" | ||
} | ||
], | ||
"previousTable": { | ||
"idEquals": [{ "fromId": "id1", "toId": "id2" }], | ||
"previousLink": { | ||
"fields": [], | ||
"fullTable": "full", | ||
"table": "driver" | ||
"table": "drivertable" | ||
}, | ||
"table": "mission" | ||
}, | ||
"table": "audit" | ||
"table": "driver_aud" | ||
}); | ||
@@ -188,3 +153,3 @@ }); | ||
it("should process a()", () => { | ||
expect((0, parser_1.parsePath)(dal_1.PathValidatorAlwaysOK)("a()")).toEqual([ | ||
expect((0, parser_1.parsePath)(validator)("a()")).toEqual([ | ||
"a()", | ||
@@ -196,3 +161,3 @@ " ^", | ||
it("should process a.()", () => { | ||
expect((0, parser_1.parsePath)(dal_1.PathValidatorAlwaysOK)("a.()")).toEqual([ | ||
expect((0, parser_1.parsePath)(validator)("a.()")).toEqual([ | ||
"a.()", | ||
@@ -204,3 +169,3 @@ " ^", | ||
it("should process a.[]", () => { | ||
expect((0, parser_1.parsePath)(dal_1.PathValidatorAlwaysOK)("a.[]")).toEqual([ | ||
expect((0, parser_1.parsePath)(validator)("a.[]")).toEqual([ | ||
"a.[]", | ||
@@ -212,3 +177,3 @@ " ^", | ||
it("should process a.(noequals)b", () => { | ||
expect((0, parser_1.parsePath)(dal_1.PathValidatorAlwaysOK)("a.(noequals)b")).toEqual([ | ||
expect((0, parser_1.parsePath)(validator)("a.(noequals)b")).toEqual([ | ||
"a.(noequals)b", | ||
@@ -233,13 +198,22 @@ " ^", | ||
}, | ||
validateTableName(tableName, fullTableName) { | ||
remembered.push(`vTable(${tableName},${fullTableName})`); | ||
validateTableName(tableName) { | ||
remembered.push(`vTable(${tableName})`); | ||
return []; | ||
}, | ||
useIdsOrSingleFkLinkOrError: (fromTableName, toTableName, idEquals) => { | ||
remembered.push(`useIdsOrSingleFkLinkOrError(${fromTableName},${toTableName}) ${idEquals}`); | ||
remembered.push(`useIdsOrSingleFkLinkOrError(${fromTableName},${toTableName}) ${JSON.stringify(idEquals)}`); | ||
return idEquals; | ||
}, | ||
actualTableName(tableName) { | ||
remembered.push(`actualTableName(${tableName})`); | ||
return tableName; | ||
} | ||
}; | ||
(0, parser_1.parsePath)(rem)("driver!full.(id1=id2)mission.audit[f3,f4]"); | ||
(0, parser_1.parsePath)(rem)("driver.(id1=id2)mission.audit[f3,f4]"); | ||
expect(remembered.sort()).toEqual([ | ||
"actualTableName(audit)", | ||
"actualTableName(driver)", | ||
"actualTableName(mission)", | ||
"useIdsOrSingleFkLinkOrError(driver,mission) [{\"fromId\":\"id1\",\"toId\":\"id2\"}]", | ||
"useIdsOrSingleFkLinkOrError(mission,audit) []", | ||
"vFields(audit)[f3,f4]", | ||
@@ -250,5 +224,5 @@ "vFields(driver)[]", | ||
"vLink(mission,audit)[]", | ||
"vTable(audit,undefined)", | ||
"vTable(driver,full)", | ||
"vTable(mission,undefined)" | ||
"vTable(audit)", | ||
"vTable(driver)", | ||
"vTable(mission)" | ||
]); | ||
@@ -255,0 +229,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tokenise = exports.tokeniseNext = void 0; | ||
const specials = "[](),.!="; | ||
const specials = "[](),.="; | ||
function tokeniseNext(context) { | ||
@@ -6,0 +6,0 @@ const initialPos = context.pos; |
@@ -31,3 +31,2 @@ "use strict"; | ||
expect(nt(")asd", 1)).toEqual({ type: 'char', value: ')', pos: 6 }); | ||
expect(nt("!asd", 1)).toEqual({ type: 'char', value: '!', pos: 6 }); | ||
}); | ||
@@ -40,3 +39,2 @@ it("should return a string up to the next special character - not escaped", () => { | ||
expect(nt("hello[world", 5)).toEqual({ type: 'string', value: 'hello', pos: 6 }); | ||
expect(nt("hello!world", 5)).toEqual({ type: 'string', value: 'hello', pos: 6 }); | ||
expect(nt("hello.world", 5)).toEqual({ type: 'string', value: 'hello', pos: 6 }); | ||
@@ -43,0 +41,0 @@ }); |
{ | ||
"name": "@dbpath/pathparser", | ||
"description": "", | ||
"version": "0.2.4", | ||
"version": "0.2.6", | ||
"main": "dist/index", | ||
@@ -20,4 +20,5 @@ "types": "dist/index", | ||
"dependencies": { | ||
"@dbpath/types": "0.2.4", | ||
"@dbpath/utils": "0.2.4" | ||
"@dbpath/types": "0.2.6", | ||
"@dbpath/utils": "0.2.6", | ||
"@dbpath/fixtures": "0.2.6" | ||
}, | ||
@@ -24,0 +25,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27786
3
11
609
+ Added@dbpath/fixtures@0.2.6
+ Added@dbpath/fixtures@0.2.6(transitive)
+ Added@dbpath/types@0.2.6(transitive)
+ Added@dbpath/utils@0.2.6(transitive)
- Removed@dbpath/types@0.2.4(transitive)
- Removed@dbpath/utils@0.2.4(transitive)
Updated@dbpath/types@0.2.6
Updated@dbpath/utils@0.2.6