jsonschema-key-compression
Advanced tools
Comparing version
@@ -0,1 +1,17 @@ | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
/** | ||
@@ -80,18 +96,29 @@ * compress the keys of an object via the compression-table | ||
if (query.sort) { | ||
ret.sort = query.sort.map(function (item) { | ||
if (typeof item === 'string') { | ||
var hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
if (Array.isArray(query.sort)) { | ||
ret.sort = query.sort.map(function (item) { | ||
if (typeof item === 'string') { | ||
var hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
} | ||
var compressedField = compressedPath(table, item); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
} | ||
return compressedField; | ||
} | ||
var compressedField = compressedPath(table, item); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
else { | ||
return compressQuerySelector(table, item); | ||
} | ||
return compressedField; | ||
} | ||
else { | ||
return compressQuerySelector(table, item); | ||
} | ||
}); | ||
}); | ||
} | ||
else { | ||
var compressedSort_1 = {}; | ||
Object.entries(query.sort).forEach(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], direction = _b[1]; | ||
var compressedField = compressedPath(table, key); | ||
compressedSort_1[compressedField] = direction; | ||
}); | ||
ret.sort = compressedSort_1; | ||
} | ||
} | ||
@@ -98,0 +125,0 @@ return ret; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -86,18 +102,29 @@ /** | ||
if (query.sort) { | ||
ret.sort = query.sort.map(function (item) { | ||
if (typeof item === 'string') { | ||
var hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
if (Array.isArray(query.sort)) { | ||
ret.sort = query.sort.map(function (item) { | ||
if (typeof item === 'string') { | ||
var hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
} | ||
var compressedField = compressedPath(table, item); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
} | ||
return compressedField; | ||
} | ||
var compressedField = compressedPath(table, item); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
else { | ||
return compressQuerySelector(table, item); | ||
} | ||
return compressedField; | ||
} | ||
else { | ||
return compressQuerySelector(table, item); | ||
} | ||
}); | ||
}); | ||
} | ||
else { | ||
var compressedSort_1 = {}; | ||
Object.entries(query.sort).forEach(function (_a) { | ||
var _b = __read(_a, 2), key = _b[0], direction = _b[1]; | ||
var compressedField = compressedPath(table, key); | ||
compressedSort_1[compressedField] = direction; | ||
}); | ||
ret.sort = compressedSort_1; | ||
} | ||
} | ||
@@ -104,0 +131,0 @@ return ret; |
{ | ||
"name": "jsonschema-key-compression", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Compress json-data based on it's json-schema", | ||
@@ -37,5 +37,5 @@ "author": "pubkey", | ||
"devDependencies": { | ||
"@types/faker": "4.1.10", | ||
"@types/faker": "4.1.11", | ||
"@types/mocha": "7.0.2", | ||
"@types/node": "12.12.21", | ||
"@types/node": "13.11.1", | ||
"@types/node-gzip": "1.1.0", | ||
@@ -45,7 +45,7 @@ "assert": "2.0.0", | ||
"faker": "4.1.0", | ||
"mocha": "7.1.0", | ||
"mocha": "7.1.1", | ||
"node-gzip": "1.1.2", | ||
"rimraf": "3.0.2", | ||
"ts-node": "8.6.2", | ||
"tslint": "6.1.0", | ||
"ts-node": "8.8.2", | ||
"tslint": "6.1.1", | ||
"typescript": "3.8.3" | ||
@@ -52,0 +52,0 @@ }, |
@@ -125,23 +125,35 @@ import { | ||
if (query.sort) { | ||
ret.sort = (query.sort as any[]).map((item: string | any) => { | ||
if (typeof item === 'string') { | ||
const hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
if (Array.isArray(query.sort)) { | ||
ret.sort = (query.sort as any[]).map((item: string | any) => { | ||
if (typeof item === 'string') { | ||
const hasMinus = item.startsWith('-'); | ||
if (hasMinus) { | ||
item = item.substr(1); | ||
} | ||
let compressedField = compressedPath( | ||
table, | ||
item | ||
); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
} | ||
return compressedField; | ||
} else { | ||
return compressQuerySelector( | ||
table, | ||
item | ||
); | ||
} | ||
let compressedField = compressedPath( | ||
}); | ||
} else { | ||
const compressedSort: {} = {}; | ||
Object.entries(query.sort).forEach(([key, direction]) => { | ||
const compressedField = compressedPath( | ||
table, | ||
item | ||
key | ||
); | ||
if (hasMinus) { | ||
compressedField = '-' + compressedField; | ||
} | ||
return compressedField; | ||
} else { | ||
return compressQuerySelector( | ||
table, | ||
item | ||
); | ||
} | ||
}); | ||
compressedSort[compressedField] = direction; | ||
}); | ||
ret.sort = compressedSort; | ||
} | ||
} | ||
@@ -148,0 +160,0 @@ return ret; |
@@ -0,1 +1,3 @@ | ||
export type SortDirection = 'asc' | 'desc' | 1 | -1; | ||
export type MangoQuery = { | ||
@@ -6,3 +8,3 @@ selector: any; | ||
fields?: string[]; | ||
sort?: { [k: string]: 1 | -1 }[] | string[]; | ||
sort?: { [k: string]: 1 | -1 }[] | string[] | { [k: string]: SortDirection }; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
74124
4.73%1116
6.39%0
-100%