@dbpath/pathparser
Advanced tools
Comparing version 0.2.20 to 0.3.0
@@ -124,3 +124,3 @@ "use strict"; | ||
exports.parseTableAndNextLink = parseTableAndNextLink; | ||
const parseLink = (previousTable) => c => mapParser(nextChar(c, '.'), c => mapParser(parseBracketedCommaSeparated(c, "(", ',', exports.parseIdEqualsId, ')'), (c, idEquals) => (0, exports.parseTableAndNextLink)(previousTable, idEquals)(c))); | ||
const parseLink = (previousTable) => c => mapParser(nextChar(c, '.'), c => mapParser(parseBracketedCommaSeparated(c, "{", ',', exports.parseIdEqualsId, '}'), (c, idEquals) => (0, exports.parseTableAndNextLink)(previousTable, idEquals)(c))); | ||
exports.parseLink = parseLink; | ||
@@ -127,0 +127,0 @@ const parseTableAndLinks = c => mapParser((0, exports.parseTable)(c), (c, previousLink) => { |
@@ -61,7 +61,7 @@ "use strict"; | ||
expect(ptError("driver[", 7)).toEqual(["Expected a field but got to end"]); | ||
expect(ptError("driver[(]", 7)).toEqual(["Expected a field unexpected character ("]); | ||
expect(ptError("driver[{]", 7)).toEqual(["Expected a field unexpected character {"]); | ||
}); | ||
}); | ||
describe("parseLink", () => { | ||
it("should parse .{table}}", () => { | ||
it("should parse .table}", () => { | ||
expect(pl(".driver", 2)).toEqual({ table: "drivertable", fields: [], "idEquals": [], "pk": ["driverId"] }); | ||
@@ -84,3 +84,3 @@ expect(pl(".mission,", 2)).toEqual({ table: "mission", fields: [], "idEquals": [], "pk": ["id"] }); | ||
it("should handle just an id in the id=id part", () => { | ||
expect(pl(".driver.(driver)mission", 7)).toEqual({ | ||
expect(pl(".driver.{driver}mission", 7)).toEqual({ | ||
"previousLink": { | ||
@@ -98,4 +98,4 @@ "fields": [], | ||
}); | ||
it("should parse .(id1=id2)drive", () => { | ||
expect(pl(".(id1=id2)driver", 7)).toEqual({ | ||
it("should parse .{id1=id2}drive", () => { | ||
expect(pl(".{id1=id2}driver", 7)).toEqual({ | ||
"fields": [], | ||
@@ -127,3 +127,3 @@ "idEquals": [{ "fromId": "id1", "toId": "id2" }], | ||
}); | ||
it("should parse .drive[f1,f2].(id1=id2)mission[f3].audit", () => { | ||
it("should parse .drive[f1,f2].{id1=id2}mission[f3].audit", () => { | ||
expect(pl(".driver[f1,f2].mission.audit", 11)).toEqual({ | ||
@@ -158,3 +158,3 @@ "previousLink": { | ||
it("should parse a complex path", () => { | ||
expect((0, parser_1.parsePath)(validator)("driver.(id1=id2)mission.audit[f3,f4]")).toEqual({ | ||
expect((0, parser_1.parsePath)(validator)("driver.{id1=id2}mission.audit[f3,f4]")).toEqual({ | ||
"previousLink": { | ||
@@ -177,5 +177,5 @@ "previousLink": { | ||
describe("error message", () => { | ||
it("should process a()", () => { | ||
expect((0, parser_1.parsePath)(validator)("a()")).toEqual([ | ||
"a()", | ||
it("should process a{}", () => { | ||
expect((0, parser_1.parsePath)(validator)("a{}")).toEqual([ | ||
"a{}", | ||
" ^", | ||
@@ -185,7 +185,7 @@ "Expected '.'" | ||
}); | ||
it("should process a.()", () => { | ||
expect((0, parser_1.parsePath)(validator)("a.()")).toEqual([ | ||
"a.()", | ||
it("should process a.{}", () => { | ||
expect((0, parser_1.parsePath)(validator)("a.{}")).toEqual([ | ||
"a.{}", | ||
" ^", | ||
"Expected a 'from id'='to id' unexpected character )" | ||
"Expected a 'from id'='to id' unexpected character }" | ||
]); | ||
@@ -201,3 +201,3 @@ }); | ||
it("should process a.(noequals)b", () => { | ||
expect((0, parser_1.parsePath)(validator)("a.(noequals)b")).toEqual({ | ||
expect((0, parser_1.parsePath)(validator)("a.{noequals}b")).toEqual({ | ||
"fields": [], | ||
@@ -212,4 +212,4 @@ "idEquals": [{ "fromId": "noequals", "toId": "noequals" }], | ||
describe("schemas", () => { | ||
it("should process s0:driver.(driverId=id)s1:mission.s2:audit", () => { | ||
expect((0, parser_1.parsePath)(validator)(" s0:driver.(driverId=id)s1:mission.s2:audit")).toEqual({ | ||
it("should process s0:driver.{driverId=id}s1:mission.s2:audit", () => { | ||
expect((0, parser_1.parsePath)(validator)(" s0:driver.{driverId=id}s1:mission.s2:audit")).toEqual({ | ||
"fields": [], | ||
@@ -276,3 +276,3 @@ "idEquals": [], | ||
}; | ||
(0, parser_1.parsePath)(rem)("driver.(id1=id2)mission.audit[f3,f4]"); | ||
(0, parser_1.parsePath)(rem)("driver.{id1=id2}mission.audit[f3,f4]"); | ||
expect(remembered.sort()).toEqual([ | ||
@@ -323,4 +323,4 @@ "actualTableName(audit)", | ||
const pv = Object.assign(Object.assign({}, dal_1.PathValidatorAlwaysOK), { validateLink: (table1, table2, ids) => [`link ${table1}.${table2} error ${JSON.stringify(ids)}`] }); | ||
expect((0, parser_1.parsePath)(pv)("driver.(id1=id2)mission.audit")).toEqual([ | ||
"driver.(id1=id2)mission.audit", | ||
expect((0, parser_1.parsePath)(pv)("driver.{id1=id2}mission.audit")).toEqual([ | ||
"driver.{id1=id2}mission.audit", | ||
" ^", | ||
@@ -327,0 +327,0 @@ "link driver.mission error [{\"fromId\":\"id1\",\"toId\":\"id2\"}]" |
"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; |
@@ -24,3 +24,3 @@ "use strict"; | ||
}); | ||
it("should return a character if [](),", () => { | ||
it("should return a character if []{},", () => { | ||
expect(nt(",", 1)).toEqual({ type: 'char', value: ',', pos: 6 }); | ||
@@ -30,8 +30,8 @@ expect(nt(",asd", 1)).toEqual({ type: 'char', value: ',', pos: 6 }); | ||
expect(nt("]asd", 1)).toEqual({ type: 'char', value: ']', pos: 6 }); | ||
expect(nt("(asd", 1)).toEqual({ type: 'char', value: '(', pos: 6 }); | ||
expect(nt(")asd", 1)).toEqual({ type: 'char', value: ')', pos: 6 }); | ||
expect(nt("{asd", 1)).toEqual({ type: 'char', value: '{', pos: 6 }); | ||
expect(nt("}asd", 1)).toEqual({ type: 'char', value: '}', pos: 6 }); | ||
}); | ||
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 }); | ||
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,3 +43,3 @@ expect(nt("hello]world", 5)).toEqual({ type: 'string', value: 'hello', pos: 6 }); | ||
it("should escape strings", () => { | ||
const txt = "`hello[,](.)!world`"; | ||
const txt = "`hello[,]{.}!world`"; | ||
expect(nt(txt + "rest", txt.length)).toEqual({ type: 'string', value: txt, pos: 6 }); | ||
@@ -49,3 +49,3 @@ expect(nt(txt, txt.length)).toEqual({ type: 'string', value: txt, pos: 6 }); | ||
it('should report if the escaped string is unterminated', () => { | ||
const txt = "`hello[,](,)!world"; | ||
const txt = "`hello[,]{,}!world"; | ||
expect(nt(txt + "rest", txt.length + 4)).toEqual({ type: 'error', value: 'Unterminated string', pos: 6 }); | ||
@@ -56,4 +56,6 @@ expect(nt(txt, txt.length)).toEqual({ type: 'error', value: 'Unterminated string', pos: 6 }); | ||
describe('tokenise', function () { | ||
it("should return an array of tokens", () => { | ||
it("for string", () => { | ||
expect((0, tokeniser_1.tokenise)("hello")).toEqual([{ type: 'string', value: 'hello', pos: 0 }]); | ||
}); | ||
it("for string,string", () => { | ||
expect((0, tokeniser_1.tokenise)("hello,world")).toEqual([ | ||
@@ -64,2 +66,4 @@ { "pos": 0, "type": "string", "value": "hello" }, | ||
]); | ||
}); | ||
it("for escaped", () => { | ||
expect((0, tokeniser_1.tokenise)("`hello,world`[a]")).toEqual([ | ||
@@ -71,3 +75,5 @@ { "pos": 0, "type": "string", "value": "`hello,world`" }, | ||
]); | ||
expect((0, tokeniser_1.tokenise)("[a]b(c)")).toEqual([ | ||
}); | ||
it("for a few characters and strings", () => { | ||
expect((0, tokeniser_1.tokenise)("[a]b{c}")).toEqual([ | ||
{ "pos": 0, "type": "char", "value": "[" }, | ||
@@ -77,7 +83,9 @@ { "pos": 1, "type": "string", "value": "a" }, | ||
{ "pos": 3, "type": "string", "value": "b" }, | ||
{ "pos": 4, "type": "char", "value": "(" }, | ||
{ "pos": 4, "type": "char", "value": "{" }, | ||
{ "pos": 5, "type": "string", "value": "c" }, | ||
{ "pos": 6, "type": "char", "value": ")" } | ||
{ "pos": 6, "type": "char", "value": "}" } | ||
]); | ||
expect((0, tokeniser_1.tokenise)("[a]b(`c[](),`)")).toEqual([ | ||
}); | ||
it("for a mixed set", () => { | ||
expect((0, tokeniser_1.tokenise)("[a]b{`c[]{},`}")).toEqual([ | ||
{ "pos": 0, "type": "char", "value": "[" }, | ||
@@ -87,7 +95,7 @@ { "pos": 1, "type": "string", "value": "a" }, | ||
{ "pos": 3, "type": "string", "value": "b" }, | ||
{ "pos": 4, "type": "char", "value": "(" }, | ||
{ "pos": 5, "type": "string", "value": "`c[](),`" }, | ||
{ "pos": 13, "type": "char", "value": ")" } | ||
{ "pos": 4, "type": "char", "value": "{" }, | ||
{ "pos": 5, "type": "string", "value": "`c[]{},`" }, | ||
{ "pos": 13, "type": "char", "value": "}" } | ||
]); | ||
}); | ||
}); |
{ | ||
"name": "@dbpath/pathparser", | ||
"description": "", | ||
"version": "0.2.20", | ||
"version": "0.3.0", | ||
"main": "dist/index", | ||
@@ -20,5 +20,5 @@ "types": "dist/index", | ||
"dependencies": { | ||
"@dbpath/types": "0.2.20", | ||
"@dbpath/utils": "0.2.20", | ||
"@dbpath/fixtures": "0.2.20" | ||
"@dbpath/types": "0.3.0", | ||
"@dbpath/utils": "0.3.0", | ||
"@dbpath/fixtures": "0.3.0" | ||
}, | ||
@@ -25,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
31649
709
+ Added@dbpath/fixtures@0.3.0(transitive)
+ Added@dbpath/types@0.3.0(transitive)
+ Added@dbpath/utils@0.3.0(transitive)
- Removed@dbpath/fixtures@0.2.20(transitive)
- Removed@dbpath/types@0.2.20(transitive)
- Removed@dbpath/utils@0.2.20(transitive)
Updated@dbpath/fixtures@0.3.0
Updated@dbpath/types@0.3.0
Updated@dbpath/utils@0.3.0