jsonschema-key-compression 1.3.0 → 1.6.1
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/dist/es/compress.d.ts +26 -0
- package/dist/es/compress.js +3 -18
- package/dist/es/compress.js.map +1 -1
- package/dist/es/create-compressed-json-schema.d.ts +2 -0
- package/dist/es/create-compressed-json-schema.js +3 -18
- package/dist/es/create-compressed-json-schema.js.map +1 -1
- package/dist/es/create-compression-table.d.ts +16 -0
- package/dist/es/create-compression-table.js +2 -1
- package/dist/es/create-compression-table.js.map +1 -1
- package/dist/es/decompress.d.ts +11 -0
- package/dist/es/index.d.ts +5 -0
- package/dist/es/types.d.ts +75 -0
- package/dist/es/util.d.ts +13 -0
- package/dist/lib/compress.d.ts +26 -0
- package/dist/lib/compress.js +3 -18
- package/dist/lib/compress.js.map +1 -1
- package/dist/lib/create-compressed-json-schema.d.ts +2 -0
- package/dist/lib/create-compressed-json-schema.js +7 -22
- package/dist/lib/create-compressed-json-schema.js.map +1 -1
- package/dist/lib/create-compression-table.d.ts +16 -0
- package/dist/lib/create-compression-table.js +3 -2
- package/dist/lib/create-compression-table.js.map +1 -1
- package/dist/lib/decompress.d.ts +11 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/types.d.ts +75 -0
- package/dist/lib/util.d.ts +13 -0
- package/package.json +12 -11
- package/src/compress.ts +3 -1
- package/src/create-compressed-json-schema.ts +3 -1
- package/src/create-compression-table.ts +2 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PlainJsonObject, CompressionTable, MangoQuery } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* compress the keys of an object via the compression-table
|
|
4
|
+
* @recursive
|
|
5
|
+
*/
|
|
6
|
+
export declare function compressObject(table: CompressionTable, obj: PlainJsonObject): PlainJsonObject;
|
|
7
|
+
/**
|
|
8
|
+
* transform an object-path
|
|
9
|
+
* into its compressed version
|
|
10
|
+
* e.g:
|
|
11
|
+
* - input: 'names[1].firstName'
|
|
12
|
+
* - ouput: '|a[1].|b'
|
|
13
|
+
*/
|
|
14
|
+
export declare function compressedPath(table: CompressionTable, path: string): string;
|
|
15
|
+
export declare function throwErrorIfCompressionFlagUsed(table: CompressionTable, key: string): void;
|
|
16
|
+
export declare function compressedAndFlaggedKey(table: CompressionTable, key: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* compress a mango-query
|
|
19
|
+
* so that it can be used to find documents
|
|
20
|
+
* in a database where all documents are compressed
|
|
21
|
+
*/
|
|
22
|
+
export declare function compressQuery(table: CompressionTable, query: MangoQuery): MangoQuery;
|
|
23
|
+
/**
|
|
24
|
+
* @recursive
|
|
25
|
+
*/
|
|
26
|
+
export declare function compressQuerySelector(table: CompressionTable, selector: any): any;
|
package/dist/es/compress.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
1
|
/**
|
|
18
2
|
* compress the keys of an object via the compression-table
|
|
19
3
|
* @recursive
|
|
@@ -113,8 +97,9 @@ export function compressQuery(table, query) {
|
|
|
113
97
|
}
|
|
114
98
|
else {
|
|
115
99
|
var compressedSort_1 = {};
|
|
116
|
-
Object.entries
|
|
117
|
-
|
|
100
|
+
// do not use Object.entries, it is transpiled shitty
|
|
101
|
+
Object.keys(query.sort).forEach(function (key) {
|
|
102
|
+
var direction = query.sort[key];
|
|
118
103
|
var compressedField = compressedPath(table, key);
|
|
119
104
|
compressedSort_1[compressedField] = direction;
|
|
120
105
|
});
|
package/dist/es/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":"AAMA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC1B,KAAuB,EACvB,GAAoB;IAEpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;SACnD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACzB,QAAQ;QACR,OAAO,GAAG;aACL,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,EAA3B,CAA2B,CAAC,CAAC;KACjD;SAAM;QACH,SAAS;QACT,IAAM,KAAG,GAAoB,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YACxB,IAAM,aAAa,GAAG,uBAAuB,CACzC,KAAK,EACL,GAAG,CACN,CAAC;YACF,IAAM,KAAK,GAAG,cAAc,CACxB,KAAK,EACL,GAAG,CAAC,GAAG,CAAC,CACX,CAAC;YACF,KAAG,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC,CAAC;QACH,OAAO,KAAG,CAAC;KACd;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC1B,KAAuB,EACvB,IAAY;IAEZ,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,QAAQ;SACV,GAAG,CAAC,UAAA,MAAM;QACP,IAAM,aAAa,GAAG,uBAAuB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S,CAAC;YAChD,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,IAAI,GAAG,gBAAc,CAAC;SAC7B;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACjC,KAAuB,EACvB,QAAa;IAEb,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACzB,OAAO,QAAQ,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAlC,CAAkC,CAAC,CAAC;KACnE;SAAM,IAAI,QAAQ,YAAY,MAAM,EAAE;QACnC,OAAO,QAAQ,CAAC;KACnB;SAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE;QAC1D,IAAM,KAAG,GAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,IAAI,MAAM,CAAC;YACX,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACrB,WAAW;gBACX,MAAM,GAAG,GAAG,CAAC;aAChB;iBAAM;gBACH,gBAAgB;gBAChB,MAAM,GAAG,cAAc,CACnB,KAAK,EACL,GAAG,CACN,CAAC;aACL;YACD,KAAG,CAAC,MAAM,CAAC,GAAG,qBAAqB,CAC/B,KAAK,EACL,QAAQ,CAAC,GAAG,CAAC,CAChB,CAAC;QACN,CAAC,CAAC,CAAC;QACH,OAAO,KAAG,CAAC;KACd;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC"}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
1
|
import { flatClone } from './util';
|
|
18
2
|
import { compressedPath } from './compress';
|
|
19
3
|
export function createCompressedJsonSchema(compressionTable, schema) {
|
|
@@ -33,8 +17,9 @@ export function createCompressedJsonSchema(compressionTable, schema) {
|
|
|
33
17
|
var cloned = flatClone(schema);
|
|
34
18
|
// compress all property names
|
|
35
19
|
var newProperties_1 = {};
|
|
36
|
-
Object.entries
|
|
37
|
-
|
|
20
|
+
// do not use Object.entries, it is transpiled shitty
|
|
21
|
+
Object.keys(schema.properties).forEach(function (key) {
|
|
22
|
+
var property = schema.properties[key];
|
|
38
23
|
var compressedKey = compressedPath(compressionTable, key);
|
|
39
24
|
newProperties_1[compressedKey] = createCompressedJsonSchema(compressionTable, property);
|
|
40
25
|
});
|
|
@@ -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":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,UAAU,0BAA0B,CACtC,gBAAkC,EAClC,MAAkB;IAElB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE;QACzC,IAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,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AAiC;QACjC,OAAO,MAAM,CAAC;KACjB;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CompressionTable, JsonSchema, TableType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Compressed property-names begin with the compression-flag
|
|
4
|
+
* it indicates that the name is compressed.
|
|
5
|
+
* If an object is compressed, where one attribute starts with the
|
|
6
|
+
* compression-flag, an error will be thrown.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_COMPRESSION_FLAG = "|";
|
|
9
|
+
export declare function createCompressionTable(schema: JsonSchema, compressionFlag?: string, ignoreProperties?: string[]): CompressionTable;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a list of all property names that occur in the schema.
|
|
12
|
+
* @returns Set of strings to ensure uniqueness.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getPropertiesOfSchema(schema: JsonSchema): Set<string>;
|
|
15
|
+
export declare function compressedToUncompressedTable(schema: JsonSchema, ignoreProperties: string[]): TableType;
|
|
16
|
+
export declare function uncompressedToCompressedTable(table: TableType, compressionFlag: string, ignoreProperties: string[]): TableType;
|
|
@@ -28,12 +28,13 @@ export function getPropertiesOfSchema(schema) {
|
|
|
28
28
|
Array.from(keys).forEach(function (k) { return ret.add(k); });
|
|
29
29
|
}
|
|
30
30
|
if (schema.properties) {
|
|
31
|
+
// do not use Object.entries, it is transpiled shitty
|
|
31
32
|
Object.keys(schema.properties).forEach(function (property) {
|
|
33
|
+
var deepSchema = schema.properties[property];
|
|
32
34
|
ret.add(property);
|
|
33
35
|
if (!schema.properties) {
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
|
-
var deepSchema = schema.properties[property];
|
|
37
38
|
addSchema(deepSchema);
|
|
38
39
|
});
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,cAAc,EACd,iBAAiB,EACpB,MAAM,QAAQ,CAAC;AAEhB;;;;;GAKG;AACH,MAAM,CAAC,IAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,MAAM,UAAU,sBAAsB,CAClC,MAAkB,EAClB,eAAkD,EAClD,gBAA+B;IAD/B,gCAAA,EAAA,0CAAkD;IAClD,iCAAA,EAAA,qBAA+B;IAE/B,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,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAkB;IACpD,IAAM,GAAG,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEnC,SAAS,SAAS,CAAC,WAAuB;QACtC,IAAM,IAAI,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAV,CAAU,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,QAAQ;YAC3C,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;gBACpB,OAAO;aACV;YACD,
|
|
1
|
+
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,cAAc,EACd,iBAAiB,EACpB,MAAM,QAAQ,CAAC;AAEhB;;;;;GAKG;AACH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AAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnC,YAAY,CAAC,GAAG,CAAC,eAAe,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;SAClD;IACL,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PlainJsonObject, CompressionTable } from './types';
|
|
2
|
+
export declare function decompressObject(table: CompressionTable, obj: PlainJsonObject): PlainJsonObject;
|
|
3
|
+
/**
|
|
4
|
+
* transform a compressed object-path
|
|
5
|
+
* into its non-compressed version
|
|
6
|
+
* e.g:
|
|
7
|
+
* - input: '|a.|b'
|
|
8
|
+
* - output: 'name.firstName'
|
|
9
|
+
*/
|
|
10
|
+
export declare function decompressedPath(table: CompressionTable, path: string): string;
|
|
11
|
+
export declare function decompressedKey(table: CompressionTable, key: string): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { TableType, CompressionTable, PlainJsonObjectNotArray, PlainJsonObject, SortDirection, MangoQuery, JsonSchemaTypes, JsonSchema } from './types';
|
|
2
|
+
export { createCompressionTable, DEFAULT_COMPRESSION_FLAG } from './create-compression-table';
|
|
3
|
+
export { compressObject, compressedPath, compressQuerySelector, compressQuery } from './compress';
|
|
4
|
+
export { decompressObject, decompressedPath, } from './decompress';
|
|
5
|
+
export { createCompressedJsonSchema } from './create-compressed-json-schema';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type TableType = Map<string, string>;
|
|
2
|
+
|
|
3
|
+
export type CompressionTable = {
|
|
4
|
+
compressedToUncompressed: TableType;
|
|
5
|
+
uncompressedToCompressed: TableType;
|
|
6
|
+
compressionFlag: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An object that contains plain json-data
|
|
12
|
+
* which can be fully json-stringified and parsed
|
|
13
|
+
* TODO
|
|
14
|
+
*/
|
|
15
|
+
export type PlainJsonObjectNotArray = {
|
|
16
|
+
[k: string]: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type PlainJsonObject = PlainJsonObjectNotArray | PlainJsonObjectNotArray[];
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export type SortDirection = 'asc' | 'desc' | 1 | -1;
|
|
23
|
+
|
|
24
|
+
export type MangoQuery = {
|
|
25
|
+
selector: any;
|
|
26
|
+
skip?: number;
|
|
27
|
+
limit?: number;
|
|
28
|
+
fields?: string[];
|
|
29
|
+
sort?: { [k: string]: 1 | -1 }[] | string[] | { [k: string]: SortDirection };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @link https://github.com/types/lib-json-schema/blob/master/v4/index.d.ts
|
|
35
|
+
*/
|
|
36
|
+
export type JsonSchemaTypes = 'array' | 'boolean' | 'integer' | 'number' | 'null' | 'object' | 'string';
|
|
37
|
+
export interface JsonSchema {
|
|
38
|
+
allOf?: JsonSchema[];
|
|
39
|
+
anyOf?: JsonSchema[];
|
|
40
|
+
oneOf?: JsonSchema[];
|
|
41
|
+
additionalItems?: boolean | JsonSchema;
|
|
42
|
+
additionalProperties?: boolean;
|
|
43
|
+
type?: JsonSchemaTypes | JsonSchemaTypes[];
|
|
44
|
+
description?: string;
|
|
45
|
+
dependencies?: {
|
|
46
|
+
[key: string]: JsonSchema | string[];
|
|
47
|
+
};
|
|
48
|
+
exclusiveMinimum?: boolean;
|
|
49
|
+
exclusiveMaximum?: boolean;
|
|
50
|
+
items?: JsonSchema | JsonSchema[];
|
|
51
|
+
multipleOf?: number;
|
|
52
|
+
maxProperties?: number;
|
|
53
|
+
maximum?: number;
|
|
54
|
+
minimum?: number;
|
|
55
|
+
maxLength?: number;
|
|
56
|
+
minLength?: number;
|
|
57
|
+
maxItems?: number;
|
|
58
|
+
minItems?: number;
|
|
59
|
+
minProperties?: number;
|
|
60
|
+
pattern?: string;
|
|
61
|
+
patternProperties?: {
|
|
62
|
+
[key: string]: JsonSchema;
|
|
63
|
+
};
|
|
64
|
+
properties?: {
|
|
65
|
+
[key: string]: JsonSchema;
|
|
66
|
+
};
|
|
67
|
+
required?: string[];
|
|
68
|
+
uniqueItems?: boolean;
|
|
69
|
+
enum?: any[];
|
|
70
|
+
not?: JsonSchema;
|
|
71
|
+
definitions?: {
|
|
72
|
+
[key: string]: JsonSchema;
|
|
73
|
+
};
|
|
74
|
+
format?: 'date-time' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'uri' | string;
|
|
75
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform a number to a string by using only base58 chars
|
|
3
|
+
* @link https://github.com/matthewmueller/number-to-letter/blob/master/index.js
|
|
4
|
+
*/
|
|
5
|
+
export declare function numberToLetter(nr: number): string;
|
|
6
|
+
export declare type SortComparator<T = any> = (a: T, y: T) => -1 | 1 | 0;
|
|
7
|
+
export declare const alphabeticCompare: SortComparator;
|
|
8
|
+
/**
|
|
9
|
+
* does a flat copy on the objects,
|
|
10
|
+
* is about 3 times faster then using deepClone
|
|
11
|
+
* @link https://jsperf.com/object-rest-spread-vs-clone/2
|
|
12
|
+
*/
|
|
13
|
+
export declare function flatClone<T>(obj: T): T;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PlainJsonObject, CompressionTable, MangoQuery } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* compress the keys of an object via the compression-table
|
|
4
|
+
* @recursive
|
|
5
|
+
*/
|
|
6
|
+
export declare function compressObject(table: CompressionTable, obj: PlainJsonObject): PlainJsonObject;
|
|
7
|
+
/**
|
|
8
|
+
* transform an object-path
|
|
9
|
+
* into its compressed version
|
|
10
|
+
* e.g:
|
|
11
|
+
* - input: 'names[1].firstName'
|
|
12
|
+
* - ouput: '|a[1].|b'
|
|
13
|
+
*/
|
|
14
|
+
export declare function compressedPath(table: CompressionTable, path: string): string;
|
|
15
|
+
export declare function throwErrorIfCompressionFlagUsed(table: CompressionTable, key: string): void;
|
|
16
|
+
export declare function compressedAndFlaggedKey(table: CompressionTable, key: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* compress a mango-query
|
|
19
|
+
* so that it can be used to find documents
|
|
20
|
+
* in a database where all documents are compressed
|
|
21
|
+
*/
|
|
22
|
+
export declare function compressQuery(table: CompressionTable, query: MangoQuery): MangoQuery;
|
|
23
|
+
/**
|
|
24
|
+
* @recursive
|
|
25
|
+
*/
|
|
26
|
+
export declare function compressQuerySelector(table: CompressionTable, selector: any): any;
|
package/dist/lib/compress.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.compressQuerySelector = exports.compressQuery = exports.compressedAndFlaggedKey = exports.throwErrorIfCompressionFlagUsed = exports.compressedPath = exports.compressObject = void 0;
|
|
20
4
|
/**
|
|
@@ -120,8 +104,9 @@ function compressQuery(table, query) {
|
|
|
120
104
|
}
|
|
121
105
|
else {
|
|
122
106
|
var compressedSort_1 = {};
|
|
123
|
-
Object.entries
|
|
124
|
-
|
|
107
|
+
// do not use Object.entries, it is transpiled shitty
|
|
108
|
+
Object.keys(query.sort).forEach(function (key) {
|
|
109
|
+
var direction = query.sort[key];
|
|
125
110
|
var compressedField = compressedPath(table, key);
|
|
126
111
|
compressedSort_1[compressedField] = direction;
|
|
127
112
|
});
|
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":";;;AAMA;;;GAGG;AACH,SAAgB,cAAc,CAC1B,KAAuB,EACvB,GAAoB;IAEpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC;SACnD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACzB,QAAQ;QACR,OAAO,GAAG;aACL,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,EAA3B,CAA2B,CAAC,CAAC;KACjD;SAAM;QACH,SAAS;QACT,IAAM,KAAG,GAAoB,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YACxB,IAAM,aAAa,GAAG,uBAAuB,CACzC,KAAK,EACL,GAAG,CACN,CAAC;YACF,IAAM,KAAK,GAAG,cAAc,CACxB,KAAK,EACL,GAAG,CAAC,GAAG,CAAC,CACX,CAAC;YACF,KAAG,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC,CAAC;QACH,OAAO,KAAG,CAAC;KACd;AACL,CAAC;AAzBD,wCAyBC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAC1B,KAAuB,EACvB,IAAY;IAEZ,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,QAAQ;SACV,GAAG,CAAC,UAAA,MAAM;QACP,IAAM,aAAa,GAAG,uBAAuB,CACzC,KAAK,EACL,MAAM,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SAAS,CAAC;YAChD,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,IAAI,GAAG,gBAAc,CAAC;SAC7B;KACJ;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AA3DD,sCA2DC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACjC,KAAuB,EACvB,QAAa;IAEb,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACzB,OAAO,QAAQ,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAlC,CAAkC,CAAC,CAAC;KACnE;SAAM,IAAI,QAAQ,YAAY,MAAM,EAAE;QACnC,OAAO,QAAQ,CAAC;KACnB;SAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,EAAE;QAC1D,IAAM,KAAG,GAAQ,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,IAAI,MAAM,CAAC;YACX,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACrB,WAAW;gBACX,MAAM,GAAG,GAAG,CAAC;aAChB;iBAAM;gBACH,gBAAgB;gBAChB,MAAM,GAAG,cAAc,CACnB,KAAK,EACL,GAAG,CACN,CAAC;aACL;YACD,KAAG,CAAC,MAAM,CAAC,GAAG,qBAAqB,CAC/B,KAAK,EACL,QAAQ,CAAC,GAAG,CAAC,CAChB,CAAC;QACN,CAAC,CAAC,CAAC;QACH,OAAO,KAAG,CAAC;KACd;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC;AA/BD,sDA+BC"}
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
3
|
exports.createCompressedJsonSchema = void 0;
|
|
20
4
|
var util_1 = require("./util");
|
|
21
5
|
var compress_1 = require("./compress");
|
|
22
6
|
function createCompressedJsonSchema(compressionTable, schema) {
|
|
23
7
|
if (schema.type === 'array' && schema.items) {
|
|
24
|
-
var cloned = util_1.flatClone(schema);
|
|
8
|
+
var cloned = (0, util_1.flatClone)(schema);
|
|
25
9
|
if (Array.isArray(schema.items)) {
|
|
26
10
|
var newItems = schema.items.map(function (item) { return createCompressedJsonSchema(compressionTable, item); });
|
|
27
11
|
cloned.items = newItems;
|
|
@@ -33,18 +17,19 @@ function createCompressedJsonSchema(compressionTable, schema) {
|
|
|
33
17
|
return cloned;
|
|
34
18
|
}
|
|
35
19
|
else if (schema.type === 'object' && schema.properties) {
|
|
36
|
-
var cloned = util_1.flatClone(schema);
|
|
20
|
+
var cloned = (0, util_1.flatClone)(schema);
|
|
37
21
|
// compress all property names
|
|
38
22
|
var newProperties_1 = {};
|
|
39
|
-
Object.entries
|
|
40
|
-
|
|
41
|
-
var
|
|
23
|
+
// do not use Object.entries, it is transpiled shitty
|
|
24
|
+
Object.keys(schema.properties).forEach(function (key) {
|
|
25
|
+
var property = schema.properties[key];
|
|
26
|
+
var compressedKey = (0, compress_1.compressedPath)(compressionTable, key);
|
|
42
27
|
newProperties_1[compressedKey] = createCompressedJsonSchema(compressionTable, property);
|
|
43
28
|
});
|
|
44
29
|
cloned.properties = newProperties_1;
|
|
45
30
|
// also compress the required array
|
|
46
31
|
if (cloned.required) {
|
|
47
|
-
cloned.required = cloned.required.map(function (key) { return compress_1.compressedPath(compressionTable, key); });
|
|
32
|
+
cloned.required = cloned.required.map(function (key) { return (0, compress_1.compressedPath)(compressionTable, key); });
|
|
48
33
|
}
|
|
49
34
|
return cloned;
|
|
50
35
|
}
|
|
@@ -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":";;;AAIA,+BAAmC;AACnC,uCAA4C;AAE5C,SAAgB,0BAA0B,CACtC,gBAAkC,EAClC,MAAkB;IAElB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE;QACzC,IAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,MAAM,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,0BAA0B,CAChE,gBAAgB,EAChB,IAAI,CACP,EAHyC,CAGzC,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC;SAC3B;aAAM;YACH,IAAM,QAAQ,GAAG,0BAA0B,CACvC,gBAAgB,EAChB,MAAM,CAAC,KAAK,CACf,CAAC;YACF,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC;SAC3B;QACD,OAAO,MAAM,CAAC;KACjB;SAAM,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE;QACtD,IAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,MAAM,CAAC,CAAC;QAEjC,8BAA8B;QAC9B,IAAM,eAAa,GAEf,EAAE,CAAC;QACP,qDAAqD;QACrD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YACtC,IAAM,QAAQ,GAAI,MAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACjD,IAAM,aAAa,GAAG,IAAA,yBAAc,EAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;YAC5D,eAAa,CAAC,aAAa,CAAC,GAAG,0BAA0B,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,UAAU,GAAG,eAAa,CAAC;QAElC,mCAAmC;QACnC,IAAI,MAAM,CAAC,QAAQ,EAAE;YACjB,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,IAAA,yBAAc,EAAC,gBAAgB,EAAE,GAAG,CAAC,EAArC,CAAqC,CAAC,CAAC;SACvF;QAED,OAAO,MAAM,CAAC;KACjB;SAAM;QACH,iCAAiC;QACjC,OAAO,MAAM,CAAC;KACjB;AACL,CAAC;AA7CD,gEA6CC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CompressionTable, JsonSchema, TableType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Compressed property-names begin with the compression-flag
|
|
4
|
+
* it indicates that the name is compressed.
|
|
5
|
+
* If an object is compressed, where one attribute starts with the
|
|
6
|
+
* compression-flag, an error will be thrown.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_COMPRESSION_FLAG = "|";
|
|
9
|
+
export declare function createCompressionTable(schema: JsonSchema, compressionFlag?: string, ignoreProperties?: string[]): CompressionTable;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a list of all property names that occur in the schema.
|
|
12
|
+
* @returns Set of strings to ensure uniqueness.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getPropertiesOfSchema(schema: JsonSchema): Set<string>;
|
|
15
|
+
export declare function compressedToUncompressedTable(schema: JsonSchema, ignoreProperties: string[]): TableType;
|
|
16
|
+
export declare function uncompressedToCompressedTable(table: TableType, compressionFlag: string, ignoreProperties: string[]): TableType;
|
|
@@ -32,12 +32,13 @@ function getPropertiesOfSchema(schema) {
|
|
|
32
32
|
Array.from(keys).forEach(function (k) { return ret.add(k); });
|
|
33
33
|
}
|
|
34
34
|
if (schema.properties) {
|
|
35
|
+
// do not use Object.entries, it is transpiled shitty
|
|
35
36
|
Object.keys(schema.properties).forEach(function (property) {
|
|
37
|
+
var deepSchema = schema.properties[property];
|
|
36
38
|
ret.add(property);
|
|
37
39
|
if (!schema.properties) {
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
var deepSchema = schema.properties[property];
|
|
41
42
|
addSchema(deepSchema);
|
|
42
43
|
});
|
|
43
44
|
}
|
|
@@ -62,7 +63,7 @@ function compressedToUncompressedTable(schema, ignoreProperties) {
|
|
|
62
63
|
schemaKeysSorted
|
|
63
64
|
.filter(function (k) { return k.length > 3 && !ignoreProperties.includes(k); })
|
|
64
65
|
.forEach(function (k) {
|
|
65
|
-
var compressKey = util_1.numberToLetter(lastKeyNumber);
|
|
66
|
+
var compressKey = (0, util_1.numberToLetter)(lastKeyNumber);
|
|
66
67
|
lastKeyNumber++;
|
|
67
68
|
table.set(k, compressKey);
|
|
68
69
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":";;;AAKA,+BAGgB;AAEhB;;;;;GAKG;AACU,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,SAAgB,sBAAsB,CAClC,MAAkB,EAClB,eAAkD,EAClD,gBAA+B;IAD/B,gCAAA,EAAA,kBAA0B,gCAAwB;IAClD,iCAAA,EAAA,qBAA+B;IAE/B,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,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AApBD,wDAoBC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,MAAkB;IACpD,IAAM,GAAG,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEnC,SAAS,SAAS,CAAC,WAAuB;QACtC,IAAM,IAAI,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAV,CAAU,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAA,QAAQ;YAC3C,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;gBACpB,OAAO;aACV;YACD,
|
|
1
|
+
{"version":3,"file":"create-compression-table.js","sourceRoot":"","sources":["../../src/create-compression-table.ts"],"names":[],"mappings":";;;AAKA,+BAGgB;AAEhB;;;;;GAKG;AACU,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAE5C,SAAgB,sBAAsB,CAClC,MAAkB,EAClB,eAAkD,EAClD,gBAA+B;IAD/B,gCAAA,EAAA,kBAA0B,gCAAwB;IAClD,iCAAA,EAAA,qBAA+B;IAE/B,IAAM,KAAK,GAAG,6BAA6B,CACvC,MAAM,EACN,gBAAgB,CACnB,CAAC;IACF,IAAM,gBAAgB,GAAqB;QACvC,wBAAwB,EAAE,KAAK;Q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'./types';
|
|
2
|
+
export declare function decompressObject(table: CompressionTable, obj: PlainJsonObject): PlainJsonObject;
|
|
3
|
+
/**
|
|
4
|
+
* transform a compressed object-path
|
|
5
|
+
* into its non-compressed version
|
|
6
|
+
* e.g:
|
|
7
|
+
* - input: '|a.|b'
|
|
8
|
+
* - output: 'name.firstName'
|
|
9
|
+
*/
|
|
10
|
+
export declare function decompressedPath(table: CompressionTable, path: string): string;
|
|
11
|
+
export declare function decompressedKey(table: CompressionTable, key: string): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { TableType, CompressionTable, PlainJsonObjectNotArray, PlainJsonObject, SortDirection, MangoQuery, JsonSchemaTypes, JsonSchema } from './types';
|
|
2
|
+
export { createCompressionTable, DEFAULT_COMPRESSION_FLAG } from './create-compression-table';
|
|
3
|
+
export { compressObject, compressedPath, compressQuerySelector, compressQuery } from './compress';
|
|
4
|
+
export { decompressObject, decompressedPath, } from './decompress';
|
|
5
|
+
export { createCompressedJsonSchema } from './create-compressed-json-schema';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type TableType = Map<string, string>;
|
|
2
|
+
|
|
3
|
+
export type CompressionTable = {
|
|
4
|
+
compressedToUncompressed: TableType;
|
|
5
|
+
uncompressedToCompressed: TableType;
|
|
6
|
+
compressionFlag: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An object that contains plain json-data
|
|
12
|
+
* which can be fully json-stringified and parsed
|
|
13
|
+
* TODO
|
|
14
|
+
*/
|
|
15
|
+
export type PlainJsonObjectNotArray = {
|
|
16
|
+
[k: string]: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type PlainJsonObject = PlainJsonObjectNotArray | PlainJsonObjectNotArray[];
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export type SortDirection = 'asc' | 'desc' | 1 | -1;
|
|
23
|
+
|
|
24
|
+
export type MangoQuery = {
|
|
25
|
+
selector: any;
|
|
26
|
+
skip?: number;
|
|
27
|
+
limit?: number;
|
|
28
|
+
fields?: string[];
|
|
29
|
+
sort?: { [k: string]: 1 | -1 }[] | string[] | { [k: string]: SortDirection };
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @link https://github.com/types/lib-json-schema/blob/master/v4/index.d.ts
|
|
35
|
+
*/
|
|
36
|
+
export type JsonSchemaTypes = 'array' | 'boolean' | 'integer' | 'number' | 'null' | 'object' | 'string';
|
|
37
|
+
export interface JsonSchema {
|
|
38
|
+
allOf?: JsonSchema[];
|
|
39
|
+
anyOf?: JsonSchema[];
|
|
40
|
+
oneOf?: JsonSchema[];
|
|
41
|
+
additionalItems?: boolean | JsonSchema;
|
|
42
|
+
additionalProperties?: boolean;
|
|
43
|
+
type?: JsonSchemaTypes | JsonSchemaTypes[];
|
|
44
|
+
description?: string;
|
|
45
|
+
dependencies?: {
|
|
46
|
+
[key: string]: JsonSchema | string[];
|
|
47
|
+
};
|
|
48
|
+
exclusiveMinimum?: boolean;
|
|
49
|
+
exclusiveMaximum?: boolean;
|
|
50
|
+
items?: JsonSchema | JsonSchema[];
|
|
51
|
+
multipleOf?: number;
|
|
52
|
+
maxProperties?: number;
|
|
53
|
+
maximum?: number;
|
|
54
|
+
minimum?: number;
|
|
55
|
+
maxLength?: number;
|
|
56
|
+
minLength?: number;
|
|
57
|
+
maxItems?: number;
|
|
58
|
+
minItems?: number;
|
|
59
|
+
minProperties?: number;
|
|
60
|
+
pattern?: string;
|
|
61
|
+
patternProperties?: {
|
|
62
|
+
[key: string]: JsonSchema;
|
|
63
|
+
};
|
|
64
|
+
properties?: {
|
|
65
|
+
[key: string]: JsonSchema;
|
|
66
|
+
};
|
|
67
|
+
required?: string[];
|
|
68
|
+
uniqueItems?: boolean;
|
|
69
|
+
enum?: any[];
|
|
70
|
+
not?: JsonSchema;
|
|
71
|
+
definitions?: {
|
|
72
|
+
[key: string]: JsonSchema;
|
|
73
|
+
};
|
|
74
|
+
format?: 'date-time' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'uri' | string;
|
|
75
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transform a number to a string by using only base58 chars
|
|
3
|
+
* @link https://github.com/matthewmueller/number-to-letter/blob/master/index.js
|
|
4
|
+
*/
|
|
5
|
+
export declare function numberToLetter(nr: number): string;
|
|
6
|
+
export declare type SortComparator<T = any> = (a: T, y: T) => -1 | 1 | 0;
|
|
7
|
+
export declare const alphabeticCompare: SortComparator;
|
|
8
|
+
/**
|
|
9
|
+
* does a flat copy on the objects,
|
|
10
|
+
* is about 3 times faster then using deepClone
|
|
11
|
+
* @link https://jsperf.com/object-rest-spread-vs-clone/2
|
|
12
|
+
*/
|
|
13
|
+
export declare function flatClone<T>(obj: T): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsonschema-key-compression",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Compress json-data based on its json-schema",
|
|
5
5
|
"author": "pubkey",
|
|
6
6
|
"keywords": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"main": "./dist/lib/index.js",
|
|
14
14
|
"jsnext:main": "./dist/es/index.js",
|
|
15
15
|
"module": "./dist/es/index.js",
|
|
16
|
-
"types": "./
|
|
16
|
+
"types": "./dist/es/index.d.ts",
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"lint": "tslint --project .",
|
|
29
29
|
"lint:fix": "tslint --project . --fix",
|
|
30
|
-
"transpile": "tsc -p ./ && echo '# transpile es5 (require) sucess!'",
|
|
31
|
-
"transpile:es": "tsc -p ./ --target ES5 --module ES6 --outDir ./dist/es && echo '# transpile es6 (modules) sucess!'",
|
|
30
|
+
"transpile": "tsc -p ./ && copyfiles -u 1 \"src/**/*.d.ts\" dist/lib && echo '# transpile es5 (require) sucess!'",
|
|
31
|
+
"transpile:es": "tsc -p ./ --target ES5 --module ES6 --outDir ./dist/es && copyfiles -u 1 \"src/**/*.d.ts\" dist/es && echo '# transpile es6 (modules) sucess!'",
|
|
32
32
|
"build": "rimraf -r ./dist && npm run transpile && npm run transpile:es",
|
|
33
33
|
"test": "mocha -r ts-node/register test/unit/index.test.ts",
|
|
34
34
|
"test:performance": "mocha -r ts-node/register --bail --exit ./test/performance.test.ts",
|
|
@@ -36,18 +36,19 @@
|
|
|
36
36
|
"dev": "mocha -r ts-node/register test/unit/index.test.ts --watch --watch-extensions ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/faker": "5.5.
|
|
40
|
-
"@types/mocha": "
|
|
41
|
-
"@types/node": "
|
|
39
|
+
"@types/faker": "5.5.9",
|
|
40
|
+
"@types/mocha": "9.0.0",
|
|
41
|
+
"@types/node": "16.11.6",
|
|
42
42
|
"@types/node-gzip": "1.1.0",
|
|
43
43
|
"assert": "2.0.0",
|
|
44
|
-
"async-test-util": "
|
|
44
|
+
"async-test-util": "2.0.0",
|
|
45
|
+
"copyfiles": "2.4.1",
|
|
45
46
|
"faker": "5.5.3",
|
|
46
|
-
"mocha": "
|
|
47
|
+
"mocha": "9.1.3",
|
|
47
48
|
"node-gzip": "1.1.2",
|
|
48
49
|
"rimraf": "3.0.2",
|
|
49
|
-
"ts-node": "10.
|
|
50
|
+
"ts-node": "10.4.0",
|
|
50
51
|
"tslint": "6.1.3",
|
|
51
|
-
"typescript": "4.
|
|
52
|
+
"typescript": "4.4.4"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/src/compress.ts
CHANGED
|
@@ -146,7 +146,9 @@ export function compressQuery(
|
|
|
146
146
|
});
|
|
147
147
|
} else {
|
|
148
148
|
const compressedSort: any = {};
|
|
149
|
-
Object.entries
|
|
149
|
+
// do not use Object.entries, it is transpiled shitty
|
|
150
|
+
Object.keys(query.sort).forEach(key => {
|
|
151
|
+
const direction = (query as any).sort[key];
|
|
150
152
|
const compressedField = compressedPath(
|
|
151
153
|
table,
|
|
152
154
|
key
|
|
@@ -32,7 +32,9 @@ export function createCompressedJsonSchema(
|
|
|
32
32
|
const newProperties: {
|
|
33
33
|
[k: string]: JsonSchema
|
|
34
34
|
} = {};
|
|
35
|
-
Object.entries
|
|
35
|
+
// do not use Object.entries, it is transpiled shitty
|
|
36
|
+
Object.keys(schema.properties).forEach(key => {
|
|
37
|
+
const property = (schema as any).properties[key];
|
|
36
38
|
const compressedKey = compressedPath(compressionTable, key);
|
|
37
39
|
newProperties[compressedKey] = createCompressedJsonSchema(compressionTable, property);
|
|
38
40
|
});
|
|
@@ -51,12 +51,13 @@ export function getPropertiesOfSchema(schema: JsonSchema): Set<string> {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (schema.properties) {
|
|
54
|
+
// do not use Object.entries, it is transpiled shitty
|
|
54
55
|
Object.keys(schema.properties).forEach(property => {
|
|
56
|
+
const deepSchema = (schema as any).properties[property];
|
|
55
57
|
ret.add(property);
|
|
56
58
|
if (!schema.properties) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
|
-
const deepSchema = schema.properties[property];
|
|
60
61
|
addSchema(deepSchema);
|
|
61
62
|
});
|
|
62
63
|
}
|