jsonschema-key-compression 1.7.0 → 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 +161 -25
- 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 +39 -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/lib/compress.d.ts +3 -1
- package/dist/lib/compress.js +167 -32
- 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 +42 -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.js +3 -3
- package/dist/lib/util.js.map +1 -1
- package/package.json +9 -7
- package/src/compress.ts +183 -33
- package/src/create-compressed-json-schema.ts +158 -35
- package/src/create-compression-table.ts +59 -31
- package/src/decompress.ts +40 -27
- package/src/enum-compression.ts +240 -0
- package/src/index.ts +1 -0
- package/src/types.d.ts +11 -0
package/dist/lib/compress.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.compressObject = compressObject;
|
|
4
|
+
exports.compressedPath = compressedPath;
|
|
5
|
+
exports.throwErrorIfCompressionFlagUsed = throwErrorIfCompressionFlagUsed;
|
|
6
|
+
exports.compressedAndFlaggedKey = compressedAndFlaggedKey;
|
|
7
|
+
exports.compressQuery = compressQuery;
|
|
8
|
+
exports.compressQuerySelector = compressQuerySelector;
|
|
9
|
+
var enum_compression_1 = require("./enum-compression");
|
|
4
10
|
/**
|
|
5
11
|
* compress the keys of an object via the compression-table
|
|
6
12
|
* @recursive
|
|
@@ -8,25 +14,36 @@ exports.compressQuerySelector = exports.compressQuery = exports.compressedAndFla
|
|
|
8
14
|
function compressObject(table, obj) {
|
|
9
15
|
if (typeof obj !== 'object' || obj === null)
|
|
10
16
|
return obj;
|
|
11
|
-
|
|
17
|
+
if (Array.isArray(obj)) {
|
|
12
18
|
// array
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
var retArray = new Array(obj.length);
|
|
20
|
+
for (var index = 0; index < obj.length; index++) {
|
|
21
|
+
var item = obj[index];
|
|
22
|
+
// primitives do not need a recursive call
|
|
23
|
+
retArray[index] = (typeof item === 'object' && item !== null) ? compressObject(table, item) : item;
|
|
24
|
+
}
|
|
25
|
+
return retArray;
|
|
15
26
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
// object
|
|
28
|
+
var ret = {};
|
|
29
|
+
var keys = Object.keys(obj);
|
|
30
|
+
var enumCompression = table.enumCompression;
|
|
31
|
+
for (var index = 0; index < keys.length; index++) {
|
|
32
|
+
var key = keys[index];
|
|
33
|
+
var value = obj[key];
|
|
34
|
+
var enumValues = enumCompression && enumCompression.get(key);
|
|
35
|
+
if (enumValues && (typeof value === 'string' || Array.isArray(value))) {
|
|
36
|
+
ret[compressedAndFlaggedKey(table, key)] = (0, enum_compression_1.compressEnumValue)(enumValues, value);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// primitives do not need a recursive call
|
|
40
|
+
ret[compressedAndFlaggedKey(table, key)] = (typeof value === 'object' && value !== null) ?
|
|
41
|
+
compressObject(table, value) :
|
|
42
|
+
value;
|
|
25
43
|
}
|
|
26
|
-
return ret;
|
|
27
44
|
}
|
|
45
|
+
return ret;
|
|
28
46
|
}
|
|
29
|
-
exports.compressObject = compressObject;
|
|
30
47
|
/**
|
|
31
48
|
* transform an object-path
|
|
32
49
|
* into its compressed version
|
|
@@ -42,32 +59,52 @@ function compressedPath(table, path) {
|
|
|
42
59
|
return compressedKey;
|
|
43
60
|
}).join('.');
|
|
44
61
|
}
|
|
45
|
-
exports.compressedPath = compressedPath;
|
|
46
62
|
function throwErrorIfCompressionFlagUsed(table, key) {
|
|
47
63
|
if (key.startsWith(table.compressionFlag)) {
|
|
48
64
|
throw new Error('cannot compress objects that start with the compression-flag: ' +
|
|
49
65
|
table.compressionFlag + ' on key ' + key);
|
|
50
66
|
}
|
|
51
67
|
}
|
|
52
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Cache of the flagged compressed keys per table,
|
|
70
|
+
* so that the flag does not have to be concatenated on each use.
|
|
71
|
+
* The cache is keyed by the table object, so a table must not be
|
|
72
|
+
* mutated after it has been used for compression.
|
|
73
|
+
*/
|
|
74
|
+
var flaggedKeysCache = new WeakMap();
|
|
75
|
+
function getFlaggedKeys(table) {
|
|
76
|
+
var flaggedKeys = flaggedKeysCache.get(table);
|
|
77
|
+
if (!flaggedKeys) {
|
|
78
|
+
var newFlaggedKeys_1 = new Map();
|
|
79
|
+
table.compressedToUncompressed.forEach(function (compressedKey, key) {
|
|
80
|
+
newFlaggedKeys_1.set(key, table.compressionFlag + compressedKey);
|
|
81
|
+
});
|
|
82
|
+
flaggedKeysCache.set(table, newFlaggedKeys_1);
|
|
83
|
+
flaggedKeys = newFlaggedKeys_1;
|
|
84
|
+
}
|
|
85
|
+
return flaggedKeys;
|
|
86
|
+
}
|
|
53
87
|
function compressedAndFlaggedKey(table, key) {
|
|
54
88
|
throwErrorIfCompressionFlagUsed(table, key);
|
|
55
89
|
/**
|
|
56
90
|
* keys could be array-accessors like myArray[4]
|
|
57
|
-
*
|
|
91
|
+
* so the part before the squared bracket is looked up
|
|
92
|
+
* and the bracket part is re-added.
|
|
93
|
+
* Most keys have no bracket, so the plain lookup is the fast path.
|
|
58
94
|
*/
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return key;
|
|
95
|
+
var flaggedKeys = getFlaggedKeys(table);
|
|
96
|
+
var bracketIndex = key.indexOf('[');
|
|
97
|
+
if (bracketIndex === -1) {
|
|
98
|
+
var directFlaggedKey = flaggedKeys.get(key);
|
|
99
|
+
return directFlaggedKey ? directFlaggedKey : key;
|
|
64
100
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
101
|
+
var plainKey = key.slice(0, bracketIndex);
|
|
102
|
+
var flaggedKey = flaggedKeys.get(plainKey);
|
|
103
|
+
if (!flaggedKey) {
|
|
104
|
+
return key;
|
|
68
105
|
}
|
|
106
|
+
return flaggedKey + key.slice(bracketIndex);
|
|
69
107
|
}
|
|
70
|
-
exports.compressedAndFlaggedKey = compressedAndFlaggedKey;
|
|
71
108
|
/**
|
|
72
109
|
* compress a mango-query
|
|
73
110
|
* so that it can be used to find documents
|
|
@@ -117,36 +154,134 @@ function compressQuery(table, query) {
|
|
|
117
154
|
}
|
|
118
155
|
return ret;
|
|
119
156
|
}
|
|
120
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Operators whose value is a document-value and therefore
|
|
159
|
+
* has to be enum-compressed like the documents themselves.
|
|
160
|
+
* Any other operator, like $type or $mod, gets its value unchanged.
|
|
161
|
+
*/
|
|
162
|
+
var ENUM_VALUE_OPERATORS = [
|
|
163
|
+
'$eq',
|
|
164
|
+
'$ne',
|
|
165
|
+
'$gt',
|
|
166
|
+
'$gte',
|
|
167
|
+
'$lt',
|
|
168
|
+
'$lte',
|
|
169
|
+
'$in',
|
|
170
|
+
'$nin',
|
|
171
|
+
'$all',
|
|
172
|
+
'$not',
|
|
173
|
+
'$elemMatch'
|
|
174
|
+
];
|
|
175
|
+
/**
|
|
176
|
+
* Returns the enum of the property that the path points to,
|
|
177
|
+
* or undefined when that property is not enum-compressed.
|
|
178
|
+
*/
|
|
179
|
+
function enumValuesOfPath(table, path) {
|
|
180
|
+
var enumCompression = table.enumCompression;
|
|
181
|
+
if (!enumCompression) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
var splitted = path.split('.');
|
|
185
|
+
var lastKey = splitted[splitted.length - 1];
|
|
186
|
+
var bracketIndex = lastKey.indexOf('[');
|
|
187
|
+
if (bracketIndex !== -1) {
|
|
188
|
+
lastKey = lastKey.slice(0, bracketIndex);
|
|
189
|
+
}
|
|
190
|
+
return enumCompression.get(lastKey);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A regular expression cannot run on the compressed number of an enum-value,
|
|
194
|
+
* so it is resolved up front into the indexes of the matching enum-values.
|
|
195
|
+
*/
|
|
196
|
+
function enumIndexesOfRegex(enumValues, pattern, options) {
|
|
197
|
+
var source;
|
|
198
|
+
var flags;
|
|
199
|
+
if (pattern instanceof RegExp) {
|
|
200
|
+
source = pattern.source;
|
|
201
|
+
flags = (pattern.ignoreCase ? 'i' : '') + (pattern.multiline ? 'm' : '');
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
source = String(pattern);
|
|
205
|
+
flags = '';
|
|
206
|
+
}
|
|
207
|
+
if (typeof options === 'string') {
|
|
208
|
+
flags = options;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The global flags make .test() stateful
|
|
212
|
+
* and are meaningless for a full check of a single value.
|
|
213
|
+
*/
|
|
214
|
+
flags = flags.replace(/[gy]/g, '');
|
|
215
|
+
var regex = new RegExp(source, flags);
|
|
216
|
+
var indexes = [];
|
|
217
|
+
for (var i = 0; i < enumValues.length; i++) {
|
|
218
|
+
if (regex.test(enumValues[i])) {
|
|
219
|
+
indexes.push(i);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return indexes;
|
|
223
|
+
}
|
|
121
224
|
/**
|
|
122
225
|
* @recursive
|
|
226
|
+
* @param enumValues The enum of the property that the selector belongs to,
|
|
227
|
+
* so that the compared values can be enum-compressed.
|
|
123
228
|
*/
|
|
124
|
-
function compressQuerySelector(table, selector) {
|
|
229
|
+
function compressQuerySelector(table, selector, enumValues) {
|
|
125
230
|
if (Array.isArray(selector)) {
|
|
126
|
-
return selector.map(function (item) { return compressQuerySelector(table, item); });
|
|
231
|
+
return selector.map(function (item) { return compressQuerySelector(table, item, enumValues); });
|
|
127
232
|
}
|
|
128
233
|
else if (selector instanceof RegExp) {
|
|
129
234
|
return selector;
|
|
130
235
|
}
|
|
131
236
|
else if (typeof selector === 'object' && selector !== null) {
|
|
132
237
|
var ret_1 = {};
|
|
238
|
+
/**
|
|
239
|
+
* $regex and its $options are replaced by a single $in
|
|
240
|
+
* with the indexes of the matching enum-values.
|
|
241
|
+
*/
|
|
242
|
+
var regexIndexes_1;
|
|
243
|
+
if (enumValues && typeof selector['$regex'] !== 'undefined') {
|
|
244
|
+
regexIndexes_1 = enumIndexesOfRegex(enumValues, selector['$regex'], selector['$options']);
|
|
245
|
+
}
|
|
133
246
|
Object.keys(selector).forEach(function (key) {
|
|
247
|
+
if (regexIndexes_1 && (key === '$regex' || key === '$options')) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
134
250
|
var useKey;
|
|
251
|
+
var useEnumValues;
|
|
135
252
|
if (key.startsWith('$')) {
|
|
136
253
|
// operator
|
|
137
254
|
useKey = key;
|
|
255
|
+
useEnumValues = ENUM_VALUE_OPERATORS.indexOf(key) === -1 ? undefined : enumValues;
|
|
138
256
|
}
|
|
139
257
|
else {
|
|
140
258
|
// property path
|
|
141
259
|
useKey = compressedPath(table, key);
|
|
260
|
+
useEnumValues = enumValuesOfPath(table, key);
|
|
261
|
+
}
|
|
262
|
+
var value = selector[key];
|
|
263
|
+
if (useEnumValues && value instanceof RegExp) {
|
|
264
|
+
ret_1[useKey] = {
|
|
265
|
+
$in: enumIndexesOfRegex(useEnumValues, value, undefined)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
ret_1[useKey] = compressQuerySelector(table, value, useEnumValues);
|
|
142
270
|
}
|
|
143
|
-
ret_1[useKey] = compressQuerySelector(table, selector[key]);
|
|
144
271
|
});
|
|
272
|
+
if (regexIndexes_1) {
|
|
273
|
+
var alreadyIn_1 = ret_1['$in'];
|
|
274
|
+
ret_1['$in'] = Array.isArray(alreadyIn_1) ?
|
|
275
|
+
regexIndexes_1.filter(function (index) { return alreadyIn_1.includes(index); }) :
|
|
276
|
+
regexIndexes_1;
|
|
277
|
+
}
|
|
145
278
|
return ret_1;
|
|
146
279
|
}
|
|
147
280
|
else {
|
|
281
|
+
if (enumValues) {
|
|
282
|
+
return (0, enum_compression_1.compressEnumValue)(enumValues, selector);
|
|
283
|
+
}
|
|
148
284
|
return selector;
|
|
149
285
|
}
|
|
150
286
|
}
|
|
151
|
-
exports.compressQuerySelector = compressQuerySelector;
|
|
152
287
|
//# sourceMappingURL=compress.js.map
|
package/dist/lib/compress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../../src/compress.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../../src/compress.ts"],"names":[],"mappings":";;AAYA,wCAiCC;AASD,wCAaC;AAED,0EAUC;A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AC5B,IAAI,aAAa,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;gBAC3C,KAAG,CAAC,MAAM,CAAC,GAAG;oBACV,GAAG,EAAE,kBAAkB,CAAC,aAAa,EAAE,KAAK,EAAE,SAAS,CAAC;iBAC3D,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,KAAG,CAAC,MAAM,CAAC,GAAG,qBAAqB,CAC/B,KAAK,EACL,KAAK,EACL,aAAa,CAChB,CAAC;YACN,CAAC;QACL,CAAC,CAAC,CAAC;QACH,IAAI,cAAY,EAAE,CAAC;YACf,IAAM,WAAS,GAAG,KAAG,CAAC,KAAK,CAAC,CAAC;YAC7B,KAAG,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,WAAS,CAAC,CAAC,CAAC;gBACnC,cAAY,CAAC,MAAM,CAAC,UAAA,KAAK,IAAI,OAAA,WAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAzB,CAAyB,CAAC,CAAC,CAAC;gBACzD,cAAY,CAAC;QACrB,CAAC;QACD,OAAO,KAAG,CAAC;IACf,CAAC;SAAM,CAAC;QACJ,IAAI,UAAU,EAAE,CAAC;YACb,OAAO,IAAA,oCAAiB,EAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;AACL,CAAC"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import type { JsonSchema, CompressionTable } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the schema so that it describes the compressed objects.
|
|
4
|
+
* It recurses into all keywords that can contain sub-schemas,
|
|
5
|
+
* independent of the 'type' field. This mirrors how compressObject() works,
|
|
6
|
+
* which compresses every key that is known to the compression-table,
|
|
7
|
+
* wherever the key occurs in the document. For example a nullable nested object
|
|
8
|
+
* has type: ['object', 'null'] and its properties must still be compressed,
|
|
9
|
+
* and properties inside of oneOf/anyOf/allOf must be compressed as well.
|
|
10
|
+
*/
|
|
2
11
|
export declare function createCompressedJsonSchema(compressionTable: CompressionTable, schema: JsonSchema): JsonSchema;
|
|
@@ -1,42 +1,151 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCompressedJsonSchema =
|
|
3
|
+
exports.createCompressedJsonSchema = createCompressedJsonSchema;
|
|
4
4
|
var util_1 = require("./util");
|
|
5
5
|
var compress_1 = require("./compress");
|
|
6
|
+
/**
|
|
7
|
+
* A value that is enum-compressed is stored as the index of the value,
|
|
8
|
+
* so the type of the property changes from string to number.
|
|
9
|
+
*/
|
|
10
|
+
function toNumberType(type) {
|
|
11
|
+
if (!type) {
|
|
12
|
+
return type;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(type)) {
|
|
15
|
+
return type.map(function (single) { return single === 'string' ? 'number' : single; });
|
|
16
|
+
}
|
|
17
|
+
return type === 'string' ? 'number' : type;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Replaces the enum-values of an enum-compressed property
|
|
21
|
+
* by the indexes that the compressed documents contain.
|
|
22
|
+
* The enum can sit at the property itself or at the items of an array-property.
|
|
23
|
+
* @recursive
|
|
24
|
+
*/
|
|
25
|
+
function compressEnumOfSchema(schema, enumValues) {
|
|
26
|
+
var ret = schema;
|
|
27
|
+
if (Array.isArray(schema.enum)) {
|
|
28
|
+
ret = (0, util_1.flatClone)(schema);
|
|
29
|
+
ret.enum = enumValues.map(function (_value, index) { return index; });
|
|
30
|
+
ret.type = toNumberType(schema.type);
|
|
31
|
+
}
|
|
32
|
+
var items = ret.items;
|
|
33
|
+
if (items && !Array.isArray(items) && Array.isArray(items.enum)) {
|
|
34
|
+
if (ret === schema) {
|
|
35
|
+
ret = (0, util_1.flatClone)(schema);
|
|
36
|
+
}
|
|
37
|
+
ret.items = compressEnumOfSchema(items, enumValues);
|
|
38
|
+
}
|
|
39
|
+
return ret;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Transforms the schema so that it describes the compressed objects.
|
|
43
|
+
* It recurses into all keywords that can contain sub-schemas,
|
|
44
|
+
* independent of the 'type' field. This mirrors how compressObject() works,
|
|
45
|
+
* which compresses every key that is known to the compression-table,
|
|
46
|
+
* wherever the key occurs in the document. For example a nullable nested object
|
|
47
|
+
* has type: ['object', 'null'] and its properties must still be compressed,
|
|
48
|
+
* and properties inside of oneOf/anyOf/allOf must be compressed as well.
|
|
49
|
+
*/
|
|
6
50
|
function createCompressedJsonSchema(compressionTable, schema) {
|
|
7
|
-
|
|
8
|
-
|
|
51
|
+
var hasNested = schema.items ||
|
|
52
|
+
schema.additionalItems ||
|
|
53
|
+
schema.properties ||
|
|
54
|
+
schema.patternProperties ||
|
|
55
|
+
schema.required ||
|
|
56
|
+
schema.allOf ||
|
|
57
|
+
schema.anyOf ||
|
|
58
|
+
schema.oneOf ||
|
|
59
|
+
schema.not ||
|
|
60
|
+
schema.dependencies ||
|
|
61
|
+
schema.definitions ||
|
|
62
|
+
schema.enum;
|
|
63
|
+
if (!hasNested) {
|
|
64
|
+
// no deeper fields in the schema
|
|
65
|
+
return schema;
|
|
66
|
+
}
|
|
67
|
+
var cloned = (0, util_1.flatClone)(schema);
|
|
68
|
+
var enumCompression = compressionTable.enumCompression;
|
|
69
|
+
var compressSchema = function (subSchema) { return createCompressedJsonSchema(compressionTable, subSchema); };
|
|
70
|
+
var compressKey = function (key) { return (0, compress_1.compressedPath)(compressionTable, key); };
|
|
71
|
+
var compressSchemaMap = function (schemaMap, compressKeys) {
|
|
72
|
+
var ret = {};
|
|
73
|
+
// do not use Object.entries, it is transpiled shitty
|
|
74
|
+
Object.keys(schemaMap).forEach(function (key) {
|
|
75
|
+
var useKey = compressKeys ? compressKey(key) : key;
|
|
76
|
+
var subSchema = compressSchema(schemaMap[key]);
|
|
77
|
+
/**
|
|
78
|
+
* Only real property names can be enum-compressed,
|
|
79
|
+
* the keys of patternProperties and definitions are no property names.
|
|
80
|
+
*/
|
|
81
|
+
var enumValues = (compressKeys && enumCompression) ? enumCompression.get(key) : undefined;
|
|
82
|
+
ret[useKey] = enumValues ? compressEnumOfSchema(subSchema, enumValues) : subSchema;
|
|
83
|
+
});
|
|
84
|
+
return ret;
|
|
85
|
+
};
|
|
86
|
+
if (schema.items) {
|
|
9
87
|
if (Array.isArray(schema.items)) {
|
|
10
|
-
|
|
11
|
-
cloned.items = newItems;
|
|
88
|
+
cloned.items = schema.items.map(compressSchema);
|
|
12
89
|
}
|
|
13
90
|
else {
|
|
14
|
-
|
|
15
|
-
cloned.items = newItems;
|
|
91
|
+
cloned.items = compressSchema(schema.items);
|
|
16
92
|
}
|
|
17
|
-
return cloned;
|
|
18
93
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
94
|
+
if (schema.additionalItems && typeof schema.additionalItems === 'object') {
|
|
95
|
+
cloned.additionalItems = compressSchema(schema.additionalItems);
|
|
96
|
+
}
|
|
97
|
+
// compress all property names
|
|
98
|
+
if (schema.properties) {
|
|
99
|
+
cloned.properties = compressSchemaMap(schema.properties, true);
|
|
100
|
+
}
|
|
101
|
+
// the patterns are not property names, only the sub-schemas are compressed
|
|
102
|
+
if (schema.patternProperties) {
|
|
103
|
+
cloned.patternProperties = compressSchemaMap(schema.patternProperties, false);
|
|
104
|
+
}
|
|
105
|
+
// also compress the required array
|
|
106
|
+
if (schema.required) {
|
|
107
|
+
cloned.required = schema.required.map(compressKey);
|
|
108
|
+
}
|
|
109
|
+
if (schema.allOf) {
|
|
110
|
+
cloned.allOf = schema.allOf.map(compressSchema);
|
|
111
|
+
}
|
|
112
|
+
if (schema.anyOf) {
|
|
113
|
+
cloned.anyOf = schema.anyOf.map(compressSchema);
|
|
114
|
+
}
|
|
115
|
+
if (schema.oneOf) {
|
|
116
|
+
cloned.oneOf = schema.oneOf.map(compressSchema);
|
|
117
|
+
}
|
|
118
|
+
if (schema.not) {
|
|
119
|
+
cloned.not = compressSchema(schema.not);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* dependencies are keyed by property name
|
|
123
|
+
* and contain either a list of property names
|
|
124
|
+
* or a sub-schema
|
|
125
|
+
*/
|
|
126
|
+
if (schema.dependencies) {
|
|
127
|
+
var dependencies_1 = schema.dependencies;
|
|
128
|
+
var newDependencies_1 = {};
|
|
129
|
+
Object.keys(dependencies_1).forEach(function (key) {
|
|
130
|
+
var dependency = dependencies_1[key];
|
|
131
|
+
newDependencies_1[compressKey(key)] = Array.isArray(dependency) ?
|
|
132
|
+
dependency.map(compressKey) :
|
|
133
|
+
compressSchema(dependency);
|
|
28
134
|
});
|
|
29
|
-
cloned.
|
|
30
|
-
// also compress the required array
|
|
31
|
-
if (cloned.required) {
|
|
32
|
-
cloned.required = cloned.required.map(function (key) { return (0, compress_1.compressedPath)(compressionTable, key); });
|
|
33
|
-
}
|
|
34
|
-
return cloned;
|
|
135
|
+
cloned.dependencies = newDependencies_1;
|
|
35
136
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
137
|
+
// definition names are not property names, only the sub-schemas are compressed
|
|
138
|
+
if (schema.definitions) {
|
|
139
|
+
cloned.definitions = compressSchemaMap(schema.definitions, false);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* enum values are document fragments,
|
|
143
|
+
* so object values contain property names that must be compressed.
|
|
144
|
+
* Primitive values are returned unchanged by compressObject().
|
|
145
|
+
*/
|
|
146
|
+
if (schema.enum) {
|
|
147
|
+
cloned.enum = schema.enum.map(function (value) { return (0, compress_1.compressObject)(compressionTable, value); });
|
|
39
148
|
}
|
|
149
|
+
return cloned;
|
|
40
150
|
}
|
|
41
|
-
exports.createCompressedJsonSchema = createCompressedJsonSchema;
|
|
42
151
|
//# sourceMappingURL=create-compressed-json-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-compressed-json-schema.js","sourceRoot":"","sources":["../../src/create-compressed-json-schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-compressed-json-schema.js","sourceRoot":"","sources":["../../src/create-compressed-json-schema.ts"],"names":[],"mappings":";;AA8DA,gEAiHC;AA1KD,+BAAmC;AACnC,uCAGoB;AAEpB;;;GAGG;AACH,SAAS,YAAY,CACjB,IAAqD;IAErD,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAvC,CAAuC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CACzB,MAAkB,EAClB,UAAoB;IAEpB,IAAI,GAAG,GAAG,MAAM,CAAC;IACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,GAAG,GAAG,IAAA,gBAAS,EAAC,MAAM,CAAC,CAAC;QACxB,GAAG,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,UAAC,MAAM,EAAE,KAAK,IAAK,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;QACpD,GAAG,CAAC,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IACD,IAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IACxB,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,C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,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,YAAY,GAAG,iBAAe,CAAC;IAC1C,CAAC;IAED,+EAA+E;IAC/E,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QACd,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,IAAA,yBAAc,EAAC,gBAAgB,EAAE,KAAK,CAAC,EAAvC,CAAuC,CAAC,CAAC;IACpF,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -6,7 +6,13 @@ import type { CompressionTable, JsonSchema, TableType } from './types';
|
|
|
6
6
|
* compression-flag, an error will be thrown.
|
|
7
7
|
*/
|
|
8
8
|
export declare const DEFAULT_COMPRESSION_FLAG = "|";
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param compressEnums If true, the values of string-enums are compressed
|
|
11
|
+
* into the index of the value inside of the enum.
|
|
12
|
+
* This changes the stored format, so it is opt-in
|
|
13
|
+
* to keep already compressed data readable.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCompressionTable(schema: JsonSchema, compressionFlag?: string, ignoreProperties?: string[], compressEnums?: boolean): CompressionTable;
|
|
10
16
|
/**
|
|
11
17
|
* Returns a list of all property names that occur in the schema.
|
|
12
18
|
* @returns Set of strings to ensure uniqueness.
|