jsonschema-key-compression 1.6.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +65 -5
- package/dist/es/compress.d.ts +3 -1
- package/dist/es/compress.js +164 -26
- package/dist/es/compress.js.map +1 -1
- package/dist/es/create-compressed-json-schema.d.ts +9 -0
- package/dist/es/create-compressed-json-schema.js +136 -26
- package/dist/es/create-compressed-json-schema.js.map +1 -1
- package/dist/es/create-compression-table.d.ts +7 -1
- package/dist/es/create-compression-table.js +56 -30
- package/dist/es/create-compression-table.js.map +1 -1
- package/dist/es/decompress.js +41 -21
- package/dist/es/decompress.js.map +1 -1
- package/dist/es/enum-compression.d.ts +35 -0
- package/dist/es/enum-compression.js +217 -0
- package/dist/es/enum-compression.js.map +1 -0
- package/dist/es/index.d.ts +1 -1
- package/dist/es/index.js.map +1 -1
- package/dist/es/types.d.ts +11 -0
- package/dist/es/util.d.ts +1 -1
- package/dist/es/util.js.map +1 -1
- package/dist/lib/compress.d.ts +3 -1
- package/dist/lib/compress.js +170 -33
- package/dist/lib/compress.js.map +1 -1
- package/dist/lib/create-compressed-json-schema.d.ts +9 -0
- package/dist/lib/create-compressed-json-schema.js +136 -27
- package/dist/lib/create-compressed-json-schema.js.map +1 -1
- package/dist/lib/create-compression-table.d.ts +7 -1
- package/dist/lib/create-compression-table.js +61 -35
- package/dist/lib/create-compression-table.js.map +1 -1
- package/dist/lib/decompress.js +44 -25
- package/dist/lib/decompress.js.map +1 -1
- package/dist/lib/enum-compression.d.ts +35 -0
- package/dist/lib/enum-compression.js +223 -0
- package/dist/lib/enum-compression.js.map +1 -0
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/types.d.ts +11 -0
- package/dist/lib/util.d.ts +1 -1
- package/dist/lib/util.js +3 -3
- package/dist/lib/util.js.map +1 -1
- package/package.json +14 -12
- package/src/compress.ts +184 -34
- package/src/create-compressed-json-schema.ts +158 -35
- package/src/create-compression-table.ts +59 -31
- package/src/decompress.ts +42 -27
- package/src/enum-compression.ts +240 -0
- package/src/index.ts +1 -0
- package/src/types.d.ts +11 -0
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DEFAULT_COMPRESSION_FLAG = void 0;
|
|
4
|
+
exports.createCompressionTable = createCompressionTable;
|
|
5
|
+
exports.getPropertiesOfSchema = getPropertiesOfSchema;
|
|
6
|
+
exports.compressedToUncompressedTable = compressedToUncompressedTable;
|
|
7
|
+
exports.uncompressedToCompressedTable = uncompressedToCompressedTable;
|
|
4
8
|
var util_1 = require("./util");
|
|
9
|
+
var enum_compression_1 = require("./enum-compression");
|
|
5
10
|
/**
|
|
6
11
|
* Compressed property-names begin with the compression-flag
|
|
7
12
|
* it indicates that the name is compressed.
|
|
@@ -9,76 +14,97 @@ var util_1 = require("./util");
|
|
|
9
14
|
* compression-flag, an error will be thrown.
|
|
10
15
|
*/
|
|
11
16
|
exports.DEFAULT_COMPRESSION_FLAG = '|';
|
|
12
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param compressEnums If true, the values of string-enums are compressed
|
|
19
|
+
* into the index of the value inside of the enum.
|
|
20
|
+
* This changes the stored format, so it is opt-in
|
|
21
|
+
* to keep already compressed data readable.
|
|
22
|
+
*/
|
|
23
|
+
function createCompressionTable(schema, compressionFlag, ignoreProperties, compressEnums) {
|
|
13
24
|
if (compressionFlag === void 0) { compressionFlag = exports.DEFAULT_COMPRESSION_FLAG; }
|
|
14
25
|
if (ignoreProperties === void 0) { ignoreProperties = []; }
|
|
26
|
+
if (compressEnums === void 0) { compressEnums = false; }
|
|
15
27
|
var table = compressedToUncompressedTable(schema, ignoreProperties);
|
|
16
28
|
var compressionTable = {
|
|
17
29
|
compressedToUncompressed: table,
|
|
18
30
|
uncompressedToCompressed: uncompressedToCompressedTable(table, compressionFlag, ignoreProperties),
|
|
19
31
|
compressionFlag: compressionFlag
|
|
20
32
|
};
|
|
33
|
+
if (compressEnums) {
|
|
34
|
+
var enumCompression = (0, enum_compression_1.getEnumCompressionTable)(schema, ignoreProperties);
|
|
35
|
+
/**
|
|
36
|
+
* The field stays undefined when there is nothing to compress,
|
|
37
|
+
* so that the compression does not have to look it up on each key.
|
|
38
|
+
*/
|
|
39
|
+
if (enumCompression.size > 0) {
|
|
40
|
+
compressionTable.enumCompression = enumCompression;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
21
43
|
return compressionTable;
|
|
22
44
|
}
|
|
23
|
-
exports.createCompressionTable = createCompressionTable;
|
|
24
45
|
/**
|
|
25
46
|
* Returns a list of all property names that occur in the schema.
|
|
26
47
|
* @returns Set of strings to ensure uniqueness.
|
|
27
48
|
*/
|
|
28
49
|
function getPropertiesOfSchema(schema) {
|
|
29
50
|
var ret = new Set();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
addPropertiesOfSchema(schema, ret);
|
|
52
|
+
return ret;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Adds all property names of the schema to the given set.
|
|
56
|
+
* Using a single accumulator set avoids creating
|
|
57
|
+
* a new set and array copy on each nesting level.
|
|
58
|
+
*/
|
|
59
|
+
function addPropertiesOfSchema(schema, ret) {
|
|
60
|
+
var properties = schema.properties;
|
|
61
|
+
if (properties) {
|
|
35
62
|
// do not use Object.entries, it is transpiled shitty
|
|
36
|
-
Object.keys(
|
|
37
|
-
|
|
63
|
+
var propertyNames = Object.keys(properties);
|
|
64
|
+
for (var i = 0; i < propertyNames.length; i++) {
|
|
65
|
+
var property = propertyNames[i];
|
|
38
66
|
ret.add(property);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
addSchema(deepSchema);
|
|
43
|
-
});
|
|
67
|
+
addPropertiesOfSchema(properties[property], ret);
|
|
68
|
+
}
|
|
44
69
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
var items = schema.items;
|
|
71
|
+
if (items) {
|
|
72
|
+
if (Array.isArray(items)) {
|
|
73
|
+
for (var i = 0; i < items.length; i++) {
|
|
74
|
+
addPropertiesOfSchema(items[i], ret);
|
|
75
|
+
}
|
|
50
76
|
}
|
|
51
77
|
else {
|
|
52
|
-
|
|
78
|
+
addPropertiesOfSchema(items, ret);
|
|
53
79
|
}
|
|
54
80
|
}
|
|
55
|
-
return ret;
|
|
56
81
|
}
|
|
57
|
-
exports.getPropertiesOfSchema = getPropertiesOfSchema;
|
|
58
82
|
function compressedToUncompressedTable(schema, ignoreProperties) {
|
|
59
83
|
var attributes = getPropertiesOfSchema(schema);
|
|
60
84
|
var schemaKeysSorted = Array.from(attributes).sort(util_1.alphabeticCompare);
|
|
61
85
|
var table = new Map();
|
|
62
86
|
var lastKeyNumber = 0;
|
|
63
|
-
schemaKeysSorted
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
87
|
+
for (var i = 0; i < schemaKeysSorted.length; i++) {
|
|
88
|
+
var k = schemaKeysSorted[i];
|
|
89
|
+
if (k.length > 3 && !ignoreProperties.includes(k)) {
|
|
90
|
+
table.set(k, (0, util_1.numberToLetter)(lastKeyNumber));
|
|
91
|
+
lastKeyNumber++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
70
94
|
return table;
|
|
71
95
|
}
|
|
72
|
-
exports.compressedToUncompressedTable = compressedToUncompressedTable;
|
|
73
96
|
function uncompressedToCompressedTable(table, compressionFlag, ignoreProperties) {
|
|
74
97
|
var reverseTable = new Map();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
98
|
+
table.forEach(function (value, key) {
|
|
99
|
+
/**
|
|
100
|
+
* The ignored properties are property names,
|
|
101
|
+
* so they must be compared to the key and not to the
|
|
102
|
+
* compressed value which could randomly be equal to an ignored name.
|
|
103
|
+
*/
|
|
104
|
+
if (!ignoreProperties.includes(key)) {
|
|
78
105
|
reverseTable.set(compressionFlag + value, key);
|
|
79
106
|
}
|
|
80
107
|
});
|
|
81
108
|
return reverseTable;
|
|
82
109
|
}
|
|
83
|
-
exports.uncompressedToCompressedTable = uncompressedToCompressedTable;
|
|
84
110
|
//# sourceMappingURL=create-compression-table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":";;;AAyBA,wDAmCC;AAMD,sDAIC;AA+BD,sEAgBC;AAED,sEAiBC;AAnID,+BAGgB;AAChB,uDAA6D;AAE7D;;;;;GAKG;AACU,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C;;;;;GAKG;AACH,SAAgB,sBAAsB,CAClC,MAAkB,EAClB,eAAkD,EAClD,gBAA+B,EAC/B,aAA8B;IAF9B,gCAAA,EAAA,kBAA0B,gCAAwB;IAClD,iCAAA,EAAA,qBAA+B;IAC/B,8BAAA,EAAA,qBAA8B;IAE9B,IAAM,KAAK,GAAG,6BAA6B,CACvC,MAAM,EACN,gBAAgB,CACnB,CAAC;IACF,IAAM,gBAAgB,GAAqB;QACvC,wBAAwB,EAAE,KAAK;QAC/B,wBAAwB,EAAE,6BAA6B,CACnD,KAAK,EACL,eAAe,EACf,gBAAgB,CACnB;QACD,eAAe,iBAAA;KAClB,CAAC;IAEF,IAAI,aAAa,EAAE,CAAC;QAChB,IAAM,eAAe,GAAG,IAAA,0CAAuB,EAC3C,MAAM,EACN,gBAAgB,CACnB,CAAC;QACF;;;WAGG;QACH,IAAI,eAAe,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC3B,gBAAgB,CAAC,eAAe,GAA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|
3
|
+
exports.decompressObject = decompressObject;
|
|
4
|
+
exports.decompressedPath = decompressedPath;
|
|
5
|
+
exports.decompressedKey = decompressedKey;
|
|
6
|
+
var enum_compression_1 = require("./enum-compression");
|
|
4
7
|
function decompressObject(table, obj) {
|
|
5
8
|
if (typeof obj !== 'object' || obj === null)
|
|
6
9
|
return obj;
|
|
7
|
-
|
|
10
|
+
if (Array.isArray(obj)) {
|
|
8
11
|
// array
|
|
9
|
-
|
|
12
|
+
var retArray = new Array(obj.length);
|
|
13
|
+
for (var index = 0; index < obj.length; index++) {
|
|
14
|
+
var item = obj[index];
|
|
15
|
+
// primitives do not need a recursive call
|
|
16
|
+
retArray[index] = (typeof item === 'object' && item !== null) ? decompressObject(table, item) : item;
|
|
17
|
+
}
|
|
18
|
+
return retArray;
|
|
10
19
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// object
|
|
21
|
+
var ret = {};
|
|
22
|
+
var keys = Object.keys(obj);
|
|
23
|
+
var enumCompression = table.enumCompression;
|
|
24
|
+
for (var index = 0; index < keys.length; index++) {
|
|
25
|
+
var key = keys[index];
|
|
26
|
+
var value = obj[key];
|
|
27
|
+
var decompressed = decompressedKey(table, key);
|
|
28
|
+
var enumValues = enumCompression && enumCompression.get(decompressed);
|
|
29
|
+
if (enumValues && (typeof value === 'number' || Array.isArray(value))) {
|
|
30
|
+
ret[decompressed] = (0, enum_compression_1.decompressEnumValue)(enumValues, value);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// primitives do not need a recursive call
|
|
34
|
+
ret[decompressed] = (typeof value === 'object' && value !== null) ?
|
|
35
|
+
decompressObject(table, value) :
|
|
36
|
+
value;
|
|
37
|
+
}
|
|
20
38
|
}
|
|
39
|
+
return ret;
|
|
21
40
|
}
|
|
22
|
-
exports.decompressObject = decompressObject;
|
|
23
41
|
/**
|
|
24
42
|
* transform a compressed object-path
|
|
25
43
|
* into its non-compressed version
|
|
@@ -35,22 +53,23 @@ function decompressedPath(table, path) {
|
|
|
35
53
|
return compressedKey;
|
|
36
54
|
}).join('.');
|
|
37
55
|
}
|
|
38
|
-
exports.decompressedPath = decompressedPath;
|
|
39
56
|
function decompressedKey(table, key) {
|
|
40
57
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
58
|
+
* keys could be array-accessors like myArray[4]
|
|
59
|
+
* so the part before the squared bracket is looked up
|
|
60
|
+
* and the bracket part is re-added.
|
|
61
|
+
* Most keys have no bracket, so the plain lookup is the fast path.
|
|
62
|
+
*/
|
|
63
|
+
var bracketIndex = key.indexOf('[');
|
|
64
|
+
if (bracketIndex === -1) {
|
|
65
|
+
var directDecompressed = table.uncompressedToCompressed.get(key);
|
|
66
|
+
return directDecompressed ? directDecompressed : key;
|
|
67
|
+
}
|
|
68
|
+
var plainKey = key.slice(0, bracketIndex);
|
|
69
|
+
var decompressed = table.uncompressedToCompressed.get(plainKey);
|
|
47
70
|
if (!decompressed) {
|
|
48
71
|
return key;
|
|
49
72
|
}
|
|
50
|
-
|
|
51
|
-
var readdSquared = splitSquaredBrackets.length ? '[' + splitSquaredBrackets.join('[') : '';
|
|
52
|
-
return decompressed + readdSquared;
|
|
53
|
-
}
|
|
73
|
+
return decompressed + key.slice(bracketIndex);
|
|
54
74
|
}
|
|
55
|
-
exports.decompressedKey = decompressedKey;
|
|
56
75
|
//# sourceMappingURL=decompress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../../src/decompress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../../src/decompress.ts"],"names":[],"mappings":";;AAOA,4CAkCC;AASD,4CAaC;AAED,0CAsBC;AAlFD,uDAAyD;AAEzD,SAAgB,gBAAgB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,CAAC,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClE,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACf,CAAC;IACD,OAAO,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EnumCompressionTable, JsonSchema } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Enum-compression replaces the value of a property
|
|
4
|
+
* by the index of that value inside of the enum of the property.
|
|
5
|
+
* For example with the enum ['admin', 'editor', 'viewer']
|
|
6
|
+
* the value 'editor' is stored as the number 1.
|
|
7
|
+
*
|
|
8
|
+
* Only enums where all values are strings can be compressed:
|
|
9
|
+
* - The compressed value is a number, so a number inside of the enum
|
|
10
|
+
* could not be told apart from an index.
|
|
11
|
+
* - Strings are also where the saved space actually is.
|
|
12
|
+
*
|
|
13
|
+
* The values are sorted before the indexes are assigned, so that the order
|
|
14
|
+
* of the indexes is equal to the alphabetic order of the values.
|
|
15
|
+
* This keeps sorting and range-queries like $gt working on compressed data.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compressibleEnumValues(values: any[]): string[] | null;
|
|
18
|
+
/**
|
|
19
|
+
* Creates the table that maps a property name to the enum of its values.
|
|
20
|
+
* A property name is only compressed when it has the same compressible enum
|
|
21
|
+
* at every place where it occurs in the schema. Otherwise the same value
|
|
22
|
+
* could mean different things depending on where it is stored.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEnumCompressionTable(schema: JsonSchema, ignoreProperties: string[]): EnumCompressionTable;
|
|
25
|
+
/**
|
|
26
|
+
* Replaces the enum-value by its index.
|
|
27
|
+
* Values that are not part of the enum are kept as they are,
|
|
28
|
+
* so that data which does not match the schema is not destroyed.
|
|
29
|
+
*/
|
|
30
|
+
export declare function compressEnumValue(enumValues: string[], value: any): any;
|
|
31
|
+
/**
|
|
32
|
+
* Replaces the index by its enum-value.
|
|
33
|
+
* The exact counterpart of compressEnumValue().
|
|
34
|
+
*/
|
|
35
|
+
export declare function decompressEnumValue(enumValues: string[], value: any): any;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compressibleEnumValues = compressibleEnumValues;
|
|
4
|
+
exports.getEnumCompressionTable = getEnumCompressionTable;
|
|
5
|
+
exports.compressEnumValue = compressEnumValue;
|
|
6
|
+
exports.decompressEnumValue = decompressEnumValue;
|
|
7
|
+
var util_1 = require("./util");
|
|
8
|
+
/**
|
|
9
|
+
* Enum-compression replaces the value of a property
|
|
10
|
+
* by the index of that value inside of the enum of the property.
|
|
11
|
+
* For example with the enum ['admin', 'editor', 'viewer']
|
|
12
|
+
* the value 'editor' is stored as the number 1.
|
|
13
|
+
*
|
|
14
|
+
* Only enums where all values are strings can be compressed:
|
|
15
|
+
* - The compressed value is a number, so a number inside of the enum
|
|
16
|
+
* could not be told apart from an index.
|
|
17
|
+
* - Strings are also where the saved space actually is.
|
|
18
|
+
*
|
|
19
|
+
* The values are sorted before the indexes are assigned, so that the order
|
|
20
|
+
* of the indexes is equal to the alphabetic order of the values.
|
|
21
|
+
* This keeps sorting and range-queries like $gt working on compressed data.
|
|
22
|
+
*/
|
|
23
|
+
function compressibleEnumValues(values) {
|
|
24
|
+
if (values.length === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
var unique = [];
|
|
28
|
+
for (var i = 0; i < values.length; i++) {
|
|
29
|
+
var value = values[i];
|
|
30
|
+
if (typeof value !== 'string') {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!unique.includes(value)) {
|
|
34
|
+
unique.push(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return unique.sort(util_1.alphabeticCompare);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the enum that applies to the values which are stored
|
|
41
|
+
* at a property, or null if the property has no compressible enum.
|
|
42
|
+
* The enum can either be defined at the property itself,
|
|
43
|
+
* or at the items of an array-property.
|
|
44
|
+
*/
|
|
45
|
+
function valueEnumOfSchema(schema) {
|
|
46
|
+
if (Array.isArray(schema.enum)) {
|
|
47
|
+
return compressibleEnumValues(schema.enum);
|
|
48
|
+
}
|
|
49
|
+
var items = schema.items;
|
|
50
|
+
if (items && !Array.isArray(items) && Array.isArray(items.enum)) {
|
|
51
|
+
return compressibleEnumValues(items.enum);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function equalEnumValues(a, b) {
|
|
56
|
+
if (a.length !== b.length) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
for (var i = 0; i < a.length; i++) {
|
|
60
|
+
if (a[i] !== b[i]) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Collects the enum of each property name for every place
|
|
68
|
+
* where the name occurs in the schema.
|
|
69
|
+
* All sub-schema keywords are walked, not only the ones that
|
|
70
|
+
* the key-compression uses, so that a property name which is used
|
|
71
|
+
* with different enums is detected as ambiguous.
|
|
72
|
+
* @recursive
|
|
73
|
+
*/
|
|
74
|
+
function addEnumCandidates(schema, candidates) {
|
|
75
|
+
var properties = schema.properties;
|
|
76
|
+
if (properties) {
|
|
77
|
+
// do not use Object.entries, it is transpiled shitty
|
|
78
|
+
var propertyNames = Object.keys(properties);
|
|
79
|
+
for (var i = 0; i < propertyNames.length; i++) {
|
|
80
|
+
var property = propertyNames[i];
|
|
81
|
+
var subSchema = properties[property];
|
|
82
|
+
var found = candidates.get(property);
|
|
83
|
+
if (!found) {
|
|
84
|
+
found = [];
|
|
85
|
+
candidates.set(property, found);
|
|
86
|
+
}
|
|
87
|
+
found.push(valueEnumOfSchema(subSchema));
|
|
88
|
+
addEnumCandidates(subSchema, candidates);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var items = schema.items;
|
|
92
|
+
if (items) {
|
|
93
|
+
if (Array.isArray(items)) {
|
|
94
|
+
for (var i = 0; i < items.length; i++) {
|
|
95
|
+
addEnumCandidates(items[i], candidates);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
addEnumCandidates(items, candidates);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (schema.additionalItems && typeof schema.additionalItems === 'object') {
|
|
103
|
+
addEnumCandidates(schema.additionalItems, candidates);
|
|
104
|
+
}
|
|
105
|
+
var subSchemaLists = [schema.allOf, schema.anyOf, schema.oneOf];
|
|
106
|
+
for (var i = 0; i < subSchemaLists.length; i++) {
|
|
107
|
+
var subSchemas = subSchemaLists[i];
|
|
108
|
+
if (subSchemas) {
|
|
109
|
+
for (var j = 0; j < subSchemas.length; j++) {
|
|
110
|
+
addEnumCandidates(subSchemas[j], candidates);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (schema.not) {
|
|
115
|
+
addEnumCandidates(schema.not, candidates);
|
|
116
|
+
}
|
|
117
|
+
var subSchemaMaps = [schema.patternProperties, schema.definitions];
|
|
118
|
+
var _loop_1 = function (i) {
|
|
119
|
+
var schemaMap = subSchemaMaps[i];
|
|
120
|
+
if (schemaMap) {
|
|
121
|
+
Object.keys(schemaMap).forEach(function (key) { return addEnumCandidates(schemaMap[key], candidates); });
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
for (var i = 0; i < subSchemaMaps.length; i++) {
|
|
125
|
+
_loop_1(i);
|
|
126
|
+
}
|
|
127
|
+
var dependencies = schema.dependencies;
|
|
128
|
+
if (dependencies) {
|
|
129
|
+
Object.keys(dependencies).forEach(function (key) {
|
|
130
|
+
var dependency = dependencies[key];
|
|
131
|
+
if (!Array.isArray(dependency)) {
|
|
132
|
+
addEnumCandidates(dependency, candidates);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates the table that maps a property name to the enum of its values.
|
|
139
|
+
* A property name is only compressed when it has the same compressible enum
|
|
140
|
+
* at every place where it occurs in the schema. Otherwise the same value
|
|
141
|
+
* could mean different things depending on where it is stored.
|
|
142
|
+
*/
|
|
143
|
+
function getEnumCompressionTable(schema, ignoreProperties) {
|
|
144
|
+
var candidates = new Map();
|
|
145
|
+
addEnumCandidates(schema, candidates);
|
|
146
|
+
var table = new Map();
|
|
147
|
+
var propertyNames = Array.from(candidates.keys()).sort(util_1.alphabeticCompare);
|
|
148
|
+
for (var i = 0; i < propertyNames.length; i++) {
|
|
149
|
+
var property = propertyNames[i];
|
|
150
|
+
if (ignoreProperties.includes(property)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
var occurrences = candidates.get(property);
|
|
154
|
+
var first = occurrences[0];
|
|
155
|
+
if (!first) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
var isAmbiguous = false;
|
|
159
|
+
for (var j = 1; j < occurrences.length; j++) {
|
|
160
|
+
var other = occurrences[j];
|
|
161
|
+
if (!other || !equalEnumValues(first, other)) {
|
|
162
|
+
isAmbiguous = true;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!isAmbiguous) {
|
|
167
|
+
table.set(property, first);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return table;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns true if the given number can be an index of the enum.
|
|
174
|
+
* Number.isInteger() is not used to stay usable on old runtimes.
|
|
175
|
+
*/
|
|
176
|
+
function isEnumIndex(value, enumValues) {
|
|
177
|
+
return value >= 0 && value < enumValues.length && value % 1 === 0;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Replaces the enum-value by its index.
|
|
181
|
+
* Values that are not part of the enum are kept as they are,
|
|
182
|
+
* so that data which does not match the schema is not destroyed.
|
|
183
|
+
*/
|
|
184
|
+
function compressEnumValue(enumValues, value) {
|
|
185
|
+
if (typeof value === 'string') {
|
|
186
|
+
var index = enumValues.indexOf(value);
|
|
187
|
+
return index === -1 ? value : index;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(value)) {
|
|
190
|
+
var ret = new Array(value.length);
|
|
191
|
+
for (var i = 0; i < value.length; i++) {
|
|
192
|
+
var item = value[i];
|
|
193
|
+
if (typeof item === 'string') {
|
|
194
|
+
var index = enumValues.indexOf(item);
|
|
195
|
+
ret[i] = index === -1 ? item : index;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
ret[i] = item;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return ret;
|
|
202
|
+
}
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Replaces the index by its enum-value.
|
|
207
|
+
* The exact counterpart of compressEnumValue().
|
|
208
|
+
*/
|
|
209
|
+
function decompressEnumValue(enumValues, value) {
|
|
210
|
+
if (typeof value === 'number') {
|
|
211
|
+
return isEnumIndex(value, enumValues) ? enumValues[value] : value;
|
|
212
|
+
}
|
|
213
|
+
if (Array.isArray(value)) {
|
|
214
|
+
var ret = new Array(value.length);
|
|
215
|
+
for (var i = 0; i < value.length; i++) {
|
|
216
|
+
var item = value[i];
|
|
217
|
+
ret[i] = (typeof item === 'number' && isEnumIndex(item, enumValues)) ? enumValues[item] : item;
|
|
218
|
+
}
|
|
219
|
+
return ret;
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=enum-compression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-compression.js","sourceRoot":"","sources":["../../src/enum-compression.ts"],"names":[],"mappings":";;AAqBA,wDAeC;AAgHD,0DAgCC;AAeD,8CAsBC;AAMD,kDAgBC;AA3OD,+BAA2C;AAE3C;;;;;;;;;;;;;;GA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C,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACnG,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { TableType, CompressionTable, PlainJsonObjectNotArray, PlainJsonObject, SortDirection, MangoQuery, JsonSchemaTypes, JsonSchema } from './types';
|
|
1
|
+
export type { TableType, CompressionTable, EnumCompressionTable, PlainJsonObjectNotArray, PlainJsonObject, SortDirection, MangoQuery, JsonSchemaTypes, JsonSchema } from './types';
|
|
2
2
|
export { createCompressionTable, DEFAULT_COMPRESSION_FLAG } from './create-compression-table';
|
|
3
3
|
export { compressObject, compressedPath, compressQuerySelector, compressQuery } from './compress';
|
|
4
4
|
export { decompressObject, decompressedPath, } from './decompress';
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAYA,uEAGoC;AAFhC,kIAAA,sBAAsB,OAAA;AACtB,oIAAA,wBAAwB,OAAA;AAG5B,uCAKoB;AAJhB,0GAAA,cAAc,OAAA;AACd,0GAAA,cAAc,OAAA;AACd,iHAAA,qBAAqB,OAAA;AACrB,yGAAA,aAAa,OAAA;AAGjB,2CAGsB;AAFlB,8GAAA,gBAAgB,OAAA;AAChB,8GAAA,gBAAgB,OAAA;AAGpB,iFAEyC;AADrC,2IAAA,0BAA0B,OAAA"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
export type TableType = Map<string, string>;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Maps a property name to the sorted enum-values of that property.
|
|
5
|
+
* A value is compressed by replacing it with its index in this list.
|
|
6
|
+
*/
|
|
7
|
+
export type EnumCompressionTable = Map<string, string[]>;
|
|
8
|
+
|
|
3
9
|
export type CompressionTable = {
|
|
4
10
|
compressedToUncompressed: TableType;
|
|
5
11
|
uncompressedToCompressed: TableType;
|
|
6
12
|
compressionFlag: string;
|
|
13
|
+
/**
|
|
14
|
+
* Only set when enum-compression is enabled
|
|
15
|
+
* and the schema has at least one compressible enum.
|
|
16
|
+
*/
|
|
17
|
+
enumCompression?: EnumCompressionTable;
|
|
7
18
|
};
|
|
8
19
|
|
|
9
20
|
|
package/dist/lib/util.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @link https://github.com/matthewmueller/number-to-letter/blob/master/index.js
|
|
4
4
|
*/
|
|
5
5
|
export declare function numberToLetter(nr: number): string;
|
|
6
|
-
export
|
|
6
|
+
export type SortComparator<T = any> = (a: T, y: T) => -1 | 1 | 0;
|
|
7
7
|
export declare const alphabeticCompare: SortComparator;
|
|
8
8
|
/**
|
|
9
9
|
* does a flat copy on the objects,
|
package/dist/lib/util.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.alphabeticCompare = void 0;
|
|
4
|
+
exports.numberToLetter = numberToLetter;
|
|
5
|
+
exports.flatClone = flatClone;
|
|
4
6
|
/**
|
|
5
7
|
* @link https://de.wikipedia.org/wiki/Base58
|
|
6
8
|
* this does not start with the numbers to generate valid variable-names
|
|
@@ -23,7 +25,6 @@ function numberToLetter(nr) {
|
|
|
23
25
|
.map(function (d) { return base58Chars[d]; })
|
|
24
26
|
.join('');
|
|
25
27
|
}
|
|
26
|
-
exports.numberToLetter = numberToLetter;
|
|
27
28
|
var alphabeticCompare = function (a, b) {
|
|
28
29
|
if (a < b) {
|
|
29
30
|
return -1;
|
|
@@ -42,5 +43,4 @@ exports.alphabeticCompare = alphabeticCompare;
|
|
|
42
43
|
function flatClone(obj) {
|
|
43
44
|
return Object.assign({}, obj);
|
|
44
45
|
}
|
|
45
|
-
exports.flatClone = flatClone;
|
|
46
46
|
//# sourceMappingURL=util.js.map
|
package/dist/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;;AAWA,wCAYC;AAmBD,8BAEC;AA5CD;;;GAGG;AACH,IAAM,WAAW,GAAG,4DAA4D,CAAC;AACjF,IAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC;AAExC;;;GAGG;AACH,SAAgB,cAAc,CAAC,EAAU;IACrC,IAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,GAAG,CAAC;QACA,IAAM,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACf,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IACvC,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,EAAE;IAEnB,OAAO,MAAM;SACR,OAAO,EAAE;SACT,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,WAAW,CAAC,CAAC,CAAC,EAAd,CAAc,CAAC;SACxB,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAIM,IAAM,iBAAiB,GAAmB,UAAC,CAAC,EAAE,CAAC;IAClD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACR,OAAO,CAAC,CAAC,CAAC;IACd,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACR,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,CAAC,CAAC;AACb,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B;AAEF;;;;GAIG;AACH,SAAgB,SAAS,CAAI,GAAM;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|