@dbpath/pathparser
Advanced tools
Comparing version 0.2.18 to 0.2.19
@@ -97,3 +97,3 @@ "use strict"; | ||
exports.parseTableName = parseTableName; | ||
const parseTable = (context) => mapParser(parseTableName(context), (cEndOfTable, tableName) => mapParser(parseBracketedCommaSeparated(cEndOfTable, '[', ',', (0, exports.identifier)('field'), ']'), (c, fields) => validateAndReturn(cEndOfTable, c, Object.assign(Object.assign({}, tableName), { fields }), c.validator.validateFields(tableName.table, fields)))); | ||
const parseTable = (context) => mapParser(parseTableName(context), (cEndOfTable, tableName) => mapParser(parseBracketedCommaSeparated(cEndOfTable, '[', ',', (0, exports.identifier)('field'), ']'), (c, fields) => validateAndReturn(cEndOfTable, c, Object.assign(Object.assign({}, tableName), { fields, pk: c.validator.pkFor(tableName.table) }), c.validator.validateFields(tableName.table, fields)))); | ||
exports.parseTable = parseTable; | ||
@@ -100,0 +100,0 @@ const parseTableAndNextLink = (previousLink, idEquals) => context => mapParser((0, exports.parseTable)(context), (c, table) => { |
@@ -7,3 +7,9 @@ "use strict"; | ||
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) }); | ||
const name2Pk = { | ||
driver: ['driverId'], | ||
drivertable: ['driverId'], | ||
mission: ['id'], | ||
driver_aud: ['id'], | ||
}; | ||
const validator = Object.assign(Object.assign({}, dal_1.PathValidatorAlwaysOK), { actualTableName: t => (0, dal_1.fullTableName)(fixtures_1.sampleSummary, t), pkFor: tableName => name2Pk[tableName] }); | ||
function makeContext(s) { | ||
@@ -43,12 +49,12 @@ return { | ||
it("should parse drive", () => { | ||
expect(pt("driver", 1)).toEqual({ table: "drivertable", fields: [] }); | ||
expect(pt("driver.", 1)).toEqual({ table: "drivertable", fields: [] }); | ||
expect(pt("driver", 1)).toEqual({ table: "drivertable", fields: [], "pk": ["driverId"], }); | ||
expect(pt("driver.", 1)).toEqual({ table: "drivertable", fields: [], "pk": ["driverId"], }); | ||
}); | ||
it("should parse mission", () => { | ||
expect(pt("mission", 1)).toEqual({ table: "mission", fields: [] }); | ||
expect(pt("mission.", 1)).toEqual({ table: "mission", fields: [] }); | ||
expect(pt("mission", 1)).toEqual({ table: "mission", fields: [], "pk": ["id"] }); | ||
expect(pt("mission.", 1)).toEqual({ table: "mission", fields: [], "pk": ["id"] }); | ||
}); | ||
it("should parse driver[field1,field2]", () => { | ||
expect(pt("driver[field1]", 4)).toEqual({ table: "drivertable", fields: ["field1"] }); | ||
expect(pt("driver[field1,field2]", 6)).toEqual({ table: "drivertable", fields: ["field1", "field2"] }); | ||
expect(pt("driver[field1]", 4)).toEqual({ table: "drivertable", fields: ["field1"], "pk": ["driverId"] }); | ||
expect(pt("driver[field1,field2]", 6)).toEqual({ table: "drivertable", fields: ["field1", "field2"], "pk": ["driverId"] }); | ||
}); | ||
@@ -62,4 +68,4 @@ it("should report nice error messages", () => { | ||
it("should parse .{table}}", () => { | ||
expect(pl(".driver", 2)).toEqual({ table: "drivertable", fields: [], "idEquals": [], }); | ||
expect(pl(".mission,", 2)).toEqual({ table: "mission", fields: [], "idEquals": [], }); | ||
expect(pl(".driver", 2)).toEqual({ table: "drivertable", fields: [], "idEquals": [], "pk": ["driverId"] }); | ||
expect(pl(".mission,", 2)).toEqual({ table: "mission", fields: [], "idEquals": [], "pk": ["id"] }); | ||
}); | ||
@@ -70,2 +76,3 @@ it("should parse .driver[f1,f2]", () => { | ||
"table": "drivertable", | ||
"pk": ["driverId"], | ||
"fields": ["f1", "f2"], | ||
@@ -81,15 +88,12 @@ previousLink, | ||
expect(pl(".driver.(driver)mission", 7)).toEqual({ | ||
"fields": [], | ||
"idEquals": [ | ||
{ | ||
"fromId": "driver", | ||
"toId": "driver" | ||
} | ||
], | ||
"previousLink": { | ||
"fields": [], | ||
"idEquals": [], | ||
pk: ["driverId"], | ||
"table": "drivertable" | ||
}, | ||
"table": "mission" | ||
"table": "mission", | ||
"fields": [], | ||
pk: ["id"], | ||
"idEquals": [{ "fromId": "driver", "toId": "driver" }], | ||
}); | ||
@@ -100,8 +104,4 @@ }); | ||
"fields": [], | ||
"idEquals": [ | ||
{ | ||
"fromId": "id1", | ||
"toId": "id2" | ||
} | ||
], | ||
"idEquals": [{ "fromId": "id1", "toId": "id2" }], | ||
pk: ["driverId"], | ||
"table": "drivertable" | ||
@@ -112,15 +112,18 @@ }); | ||
expect(pl(".driver.mission.audit", 6)).toEqual({ | ||
"fields": [], | ||
"idEquals": [], | ||
"previousLink": { | ||
"fields": [], | ||
"idEquals": [], | ||
"previousLink": { | ||
"fields": [], | ||
"idEquals": [], | ||
pk: ["driverId"], | ||
"table": "drivertable" | ||
}, | ||
"table": "mission" | ||
"table": "mission", | ||
pk: ["id"], | ||
"fields": [], | ||
"idEquals": [], | ||
}, | ||
"table": "driver_aud" | ||
"table": "driver_aud", | ||
pk: ["id"], | ||
"fields": [], | ||
"idEquals": [], | ||
}); | ||
@@ -130,15 +133,18 @@ }); | ||
expect(pl(".driver[f1,f2].mission.audit", 11)).toEqual({ | ||
"fields": [], | ||
"previousLink": { | ||
"fields": [], | ||
"previousLink": { | ||
"fields": ["f1", "f2"], | ||
"table": "drivertable", | ||
pk: ["driverId"], | ||
"idEquals": [], | ||
}, | ||
"table": "mission", | ||
pk: ["id"], | ||
"idEquals": [], | ||
"fields": [], | ||
}, | ||
"table": "driver_aud", | ||
pk: ["id"], | ||
"idEquals": [], | ||
"fields": [], | ||
}); | ||
@@ -151,3 +157,4 @@ }); | ||
"fields": [], | ||
"table": "driver" | ||
"table": "driver", | ||
pk: ["id"], | ||
}); | ||
@@ -157,13 +164,16 @@ }); | ||
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" }], | ||
"previousLink": { | ||
"fields": [], | ||
"table": "drivertable" | ||
"table": "drivertable", | ||
pk: ["driverId"], | ||
}, | ||
"table": "mission" | ||
"table": "mission", | ||
"fields": [], | ||
pk: ["id"], | ||
"idEquals": [{ "fromId": "id1", "toId": "id2" }], | ||
}, | ||
"table": "driver_aud" | ||
"table": "driver_aud", | ||
pk: ["id"], | ||
"fields": ["f3", "f4"], "idEquals": [], | ||
}); | ||
@@ -226,2 +236,6 @@ }); | ||
return tableName; | ||
}, | ||
pkFor(tableName) { | ||
remembered.push(`pkFor(${tableName})`); | ||
return ['id']; | ||
} | ||
@@ -234,2 +248,5 @@ }; | ||
"actualTableName(mission)", | ||
"pkFor(audit)", | ||
"pkFor(driver)", | ||
"pkFor(mission)", | ||
"useIdsOrSingleFkLinkOrError(driver,mission) [{\"fromId\":\"id1\",\"toId\":\"id2\"}]", | ||
@@ -236,0 +253,0 @@ "useIdsOrSingleFkLinkOrError(mission,audit) []", |
{ | ||
"name": "@dbpath/pathparser", | ||
"description": "", | ||
"version": "0.2.18", | ||
"version": "0.2.19", | ||
"main": "dist/index", | ||
@@ -20,5 +20,5 @@ "types": "dist/index", | ||
"dependencies": { | ||
"@dbpath/types": "0.2.18", | ||
"@dbpath/utils": "0.2.18", | ||
"@dbpath/fixtures": "0.2.18" | ||
"@dbpath/types": "0.2.19", | ||
"@dbpath/utils": "0.2.19", | ||
"@dbpath/fixtures": "0.2.19" | ||
}, | ||
@@ -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
29496
652
+ Added@dbpath/fixtures@0.2.19(transitive)
+ Added@dbpath/types@0.2.19(transitive)
+ Added@dbpath/utils@0.2.19(transitive)
- Removed@dbpath/fixtures@0.2.18(transitive)
- Removed@dbpath/types@0.2.18(transitive)
- Removed@dbpath/utils@0.2.18(transitive)
Updated@dbpath/fixtures@0.2.19
Updated@dbpath/types@0.2.19
Updated@dbpath/utils@0.2.19