@karmaniverous/entity-manager 5.0.9 → 6.0.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/README.md +17 -437
- package/dist/cjs/_virtual/_commonjsHelpers.js +7 -0
- package/dist/cjs/_virtual/lz-string.js +5 -0
- package/dist/cjs/node_modules/@karmaniverous/entity-tools/dist/mjs/Nil.js +14 -0
- package/dist/cjs/node_modules/@karmaniverous/entity-tools/dist/mjs/defaultTranscodes.js +94 -0
- package/dist/cjs/node_modules/@karmaniverous/entity-tools/dist/mjs/sort.js +52 -0
- package/dist/cjs/node_modules/lz-string/libs/lz-string.js +517 -0
- package/dist/cjs/node_modules/radash/dist/esm/array.js +90 -0
- package/dist/cjs/node_modules/radash/dist/esm/async.js +62 -0
- package/dist/cjs/node_modules/radash/dist/esm/object.js +25 -0
- package/dist/cjs/node_modules/radash/dist/esm/typed.js +35 -0
- package/dist/cjs/node_modules/string-hash/index.js +23 -0
- package/dist/cjs/node_modules/tslib/tslib.es6.js +39 -0
- package/dist/cjs/node_modules/zod/lib/index.js +4342 -0
- package/dist/cjs/src/EntityManager.js +93 -0
- package/dist/cjs/src/ParsedConfig.js +227 -0
- package/dist/cjs/src/addKeys.js +47 -0
- package/dist/cjs/src/decodeEntityElement.js +37 -0
- package/dist/cjs/src/decodeGeneratedProperty.js +48 -0
- package/dist/cjs/src/dehydrateIndexItem.js +52 -0
- package/dist/cjs/src/dehydratePageKeyMap.js +75 -0
- package/dist/cjs/src/encodeEntityElement.js +36 -0
- package/dist/cjs/src/encodeGeneratedProperty.js +44 -0
- package/dist/cjs/src/getHashKeySpace.js +41 -0
- package/dist/cjs/src/getShardBump.js +24 -0
- package/dist/cjs/src/index.js +7 -0
- package/dist/cjs/src/query.js +104 -0
- package/dist/cjs/src/rehydrateIndexItem.js +48 -0
- package/dist/cjs/src/rehydratePageKeyMap.js +66 -0
- package/dist/cjs/src/removeKeys.js +33 -0
- package/dist/cjs/src/unwrapIndex.js +40 -0
- package/dist/cjs/src/updateItemHashKey.js +55 -0
- package/dist/cjs/src/updateItemRangeKey.js +45 -0
- package/dist/cjs/src/validateEntityGeneratedProperty.js +29 -0
- package/dist/cjs/src/validateEntityIndexToken.js +22 -0
- package/dist/cjs/src/validateEntityToken.js +17 -0
- package/dist/index.d.cts +826 -0
- package/dist/index.d.mts +826 -0
- package/dist/index.d.ts +826 -0
- package/dist/mjs/_virtual/_commonjsHelpers.js +5 -0
- package/dist/mjs/_virtual/lz-string.js +3 -0
- package/dist/mjs/node_modules/@karmaniverous/entity-tools/dist/mjs/Nil.js +12 -0
- package/dist/mjs/node_modules/@karmaniverous/entity-tools/dist/mjs/defaultTranscodes.js +92 -0
- package/dist/mjs/node_modules/@karmaniverous/entity-tools/dist/mjs/sort.js +50 -0
- package/dist/mjs/node_modules/lz-string/libs/lz-string.js +515 -0
- package/dist/mjs/node_modules/radash/dist/esm/array.js +80 -0
- package/dist/mjs/node_modules/radash/dist/esm/async.js +58 -0
- package/dist/mjs/node_modules/radash/dist/esm/object.js +22 -0
- package/dist/mjs/node_modules/radash/dist/esm/typed.js +28 -0
- package/dist/mjs/node_modules/string-hash/index.js +21 -0
- package/dist/mjs/node_modules/tslib/tslib.es6.js +36 -0
- package/dist/mjs/node_modules/zod/lib/index.js +4233 -0
- package/dist/mjs/src/EntityManager.js +91 -0
- package/dist/mjs/src/ParsedConfig.js +225 -0
- package/dist/mjs/src/addKeys.js +45 -0
- package/dist/mjs/src/decodeEntityElement.js +35 -0
- package/dist/mjs/src/decodeGeneratedProperty.js +46 -0
- package/dist/mjs/src/dehydrateIndexItem.js +50 -0
- package/dist/mjs/src/dehydratePageKeyMap.js +73 -0
- package/dist/mjs/src/encodeEntityElement.js +34 -0
- package/dist/mjs/src/encodeGeneratedProperty.js +42 -0
- package/dist/mjs/src/getHashKeySpace.js +39 -0
- package/dist/mjs/src/getShardBump.js +22 -0
- package/dist/mjs/src/index.js +1 -0
- package/dist/mjs/src/query.js +102 -0
- package/dist/mjs/src/rehydrateIndexItem.js +46 -0
- package/dist/mjs/src/rehydratePageKeyMap.js +64 -0
- package/dist/mjs/src/removeKeys.js +31 -0
- package/dist/mjs/src/unwrapIndex.js +38 -0
- package/dist/mjs/src/updateItemHashKey.js +53 -0
- package/dist/mjs/src/updateItemRangeKey.js +43 -0
- package/dist/mjs/src/validateEntityGeneratedProperty.js +27 -0
- package/dist/mjs/src/validateEntityIndexToken.js +20 -0
- package/dist/mjs/src/validateEntityToken.js +15 -0
- package/package.json +107 -58
- package/.env +0 -1
- package/.github/FUNDING.yml +0 -3
- package/dist/default/lib/EntityManager/EntityManager.js +0 -423
- package/dist/default/lib/EntityManager/PrivateEntityManager.js +0 -421
- package/dist/default/lib/index.js +0 -12
- package/dist/package.json +0 -3
- package/lib/EntityManager/EntityManager.js +0 -396
- package/lib/EntityManager/PrivateEntityManager.js +0 -436
- package/lib/index.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests whether a value is {@link Nil | `Nil`}.
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value.
|
|
5
|
+
*
|
|
6
|
+
* @returns true if `value` is `null` or `undefined`.
|
|
7
|
+
*
|
|
8
|
+
* @category Utilities
|
|
9
|
+
*/
|
|
10
|
+
const isNil = (value) => value === null || value === undefined;
|
|
11
|
+
|
|
12
|
+
export { isNil };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isString, isNumber, isInt } from '../../../../radash/dist/esm/typed.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* {@link Transcodes | `Transcodes`} for {@link DefaultTranscodeMap | `DefaultTranscodeMap`}.
|
|
5
|
+
*
|
|
6
|
+
* See {@link https://github.com/karmaniverous/entity-tools/blob/main/src/defaultTranscodes.ts | implementation details}.
|
|
7
|
+
*
|
|
8
|
+
* @category Transcoding
|
|
9
|
+
*/
|
|
10
|
+
const defaultTranscodes = {
|
|
11
|
+
bigint20: {
|
|
12
|
+
encode: (value) => {
|
|
13
|
+
if (typeof value !== 'bigint' ||
|
|
14
|
+
value > 99999999999999999999n ||
|
|
15
|
+
value < -99999999999999999999n)
|
|
16
|
+
throw new Error('invalid bigint20');
|
|
17
|
+
const [prefix, abs] = value < 0n ? ['n', -value] : ['p', value];
|
|
18
|
+
return `${prefix}${abs.toString().padStart(20, '0')}`;
|
|
19
|
+
},
|
|
20
|
+
decode: (value) => {
|
|
21
|
+
if (!isString(value) || !/^[np][0-9]{20}$/.test(value))
|
|
22
|
+
throw new Error('invalid encoded bigint20');
|
|
23
|
+
return (value.startsWith('n') ? -1n : 1n) * BigInt(value.slice(1));
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
boolean: {
|
|
27
|
+
encode: (value) => {
|
|
28
|
+
if (typeof value !== 'boolean')
|
|
29
|
+
throw new Error('invalid boolean');
|
|
30
|
+
return value.toString();
|
|
31
|
+
},
|
|
32
|
+
decode: (value) => {
|
|
33
|
+
if (!isString(value) || !/^(true|false)$/.test(value))
|
|
34
|
+
throw new Error('invalid encoded boolean');
|
|
35
|
+
return value === 'true';
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
fix6: {
|
|
39
|
+
encode: (value) => {
|
|
40
|
+
if (!isNumber(value) ||
|
|
41
|
+
value > Number.MAX_SAFE_INTEGER / 1000000 ||
|
|
42
|
+
value < Number.MIN_SAFE_INTEGER / 1000000)
|
|
43
|
+
throw new Error('invalid fix6');
|
|
44
|
+
const [prefix, abs] = value < 0 ? ['n', -value] : ['p', value];
|
|
45
|
+
return `${prefix}${abs.toFixed(6).padStart(17, '0')}`;
|
|
46
|
+
},
|
|
47
|
+
decode: (value) => {
|
|
48
|
+
if (!isString(value) || !/^[np][0-9]{10}\.[0-9]{6}$/.test(value))
|
|
49
|
+
throw new Error('invalid encoded fix6');
|
|
50
|
+
return (value.startsWith('n') ? -1 : 1) * Number(value.slice(1));
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
int: {
|
|
54
|
+
encode: (value) => {
|
|
55
|
+
if (!isInt(value))
|
|
56
|
+
throw new Error('invalid int');
|
|
57
|
+
const [prefix, abs] = value < 0 ? ['n', -value] : ['p', value];
|
|
58
|
+
return `${prefix}${abs.toString().padStart(16, '0')}`;
|
|
59
|
+
},
|
|
60
|
+
decode: (value) => {
|
|
61
|
+
if (!isString(value) || !/^[np][0-9]{16}$/.test(value))
|
|
62
|
+
throw new Error('invalid encoded int');
|
|
63
|
+
return (value.startsWith('n') ? -1 : 1) * Number(value.slice(1));
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
string: {
|
|
67
|
+
encode: (value) => {
|
|
68
|
+
if (!isString(value))
|
|
69
|
+
throw new Error('invalid string');
|
|
70
|
+
return value;
|
|
71
|
+
},
|
|
72
|
+
decode: (value) => {
|
|
73
|
+
if (!isString(value))
|
|
74
|
+
throw new Error('invalid encoded string');
|
|
75
|
+
return value;
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
timestamp: {
|
|
79
|
+
encode: (value) => {
|
|
80
|
+
if (!isInt(value) || value < 0 || value > 9999999999999)
|
|
81
|
+
throw new Error('invalid timestamp');
|
|
82
|
+
return value.toString().padStart(13, '0');
|
|
83
|
+
},
|
|
84
|
+
decode: (value) => {
|
|
85
|
+
if (!isString(value) || !/^[0-9]{13}$/.test(value))
|
|
86
|
+
throw new Error('invalid encoded timestamp');
|
|
87
|
+
return Number(value);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export { defaultTranscodes };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isNil } from './Nil.js';
|
|
2
|
+
import { isNumber, isString } from '../../../../radash/dist/esm/typed.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sort an array of `Item` progressively by `sort`.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam Item - Item type. Must extend {@link Entity | `Entity`}.
|
|
8
|
+
*
|
|
9
|
+
* @param items - Array of `Item`.
|
|
10
|
+
* @param sortOrder - {@link SortOrder | `SortOrder`} array.
|
|
11
|
+
*
|
|
12
|
+
* @returns Sorted `items`.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Sorts `items` progresively by the elements of `sortOrder`, passing to the next element if values at the current element are equal.
|
|
16
|
+
*
|
|
17
|
+
* Comparisons are made as expected for `number`, `string`, and `bigint` types.
|
|
18
|
+
*
|
|
19
|
+
* `null` and `undefined` values are considered equivalent and less than any other value.
|
|
20
|
+
*
|
|
21
|
+
* Other types are compared by truthiness, where truthy is greater than falsy.
|
|
22
|
+
*
|
|
23
|
+
* @category Sort
|
|
24
|
+
*/
|
|
25
|
+
const sort = (items = [], sortOrder = []) => [...items].sort((a, b) => {
|
|
26
|
+
let comp = 0;
|
|
27
|
+
for (const { property, desc } of sortOrder) {
|
|
28
|
+
if (isNumber(a[property]) && isNumber(b[property]))
|
|
29
|
+
comp = a[property] - b[property];
|
|
30
|
+
else if (isString(a[property]) && isString(b[property]))
|
|
31
|
+
comp = a[property].localeCompare(b[property]);
|
|
32
|
+
else if (typeof a[property] === 'bigint' &&
|
|
33
|
+
typeof b[property] === 'bigint')
|
|
34
|
+
comp =
|
|
35
|
+
a[property] < b[property] ? -1 : a[property] > b[property] ? 1 : 0;
|
|
36
|
+
else if (!isNil(a[property]) && isNil(b[property]))
|
|
37
|
+
comp = 1;
|
|
38
|
+
else if (isNil(a[property]) && !isNil(b[property]))
|
|
39
|
+
comp = -1;
|
|
40
|
+
else if (a[property] && !b[property])
|
|
41
|
+
comp = 1;
|
|
42
|
+
else if (!a[property] && b[property])
|
|
43
|
+
comp = -1;
|
|
44
|
+
if (comp)
|
|
45
|
+
return desc ? -comp : comp;
|
|
46
|
+
}
|
|
47
|
+
return comp;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export { sort };
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { getDefaultExportFromCjs } from '../../../_virtual/_commonjsHelpers.js';
|
|
2
|
+
import { __module as lzString$1 } from '../../../_virtual/lz-string.js';
|
|
3
|
+
|
|
4
|
+
lzString$1.exports;
|
|
5
|
+
|
|
6
|
+
(function (module) {
|
|
7
|
+
// Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
|
|
8
|
+
// This work is free. You can redistribute it and/or modify it
|
|
9
|
+
// under the terms of the WTFPL, Version 2
|
|
10
|
+
// For more information see LICENSE.txt or http://www.wtfpl.net/
|
|
11
|
+
//
|
|
12
|
+
// For more information, the home page:
|
|
13
|
+
// http://pieroxy.net/blog/pages/lz-string/testing.html
|
|
14
|
+
//
|
|
15
|
+
// LZ-based compression algorithm, version 1.4.5
|
|
16
|
+
var LZString = (function() {
|
|
17
|
+
|
|
18
|
+
// private property
|
|
19
|
+
var f = String.fromCharCode;
|
|
20
|
+
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
21
|
+
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
22
|
+
var baseReverseDic = {};
|
|
23
|
+
|
|
24
|
+
function getBaseValue(alphabet, character) {
|
|
25
|
+
if (!baseReverseDic[alphabet]) {
|
|
26
|
+
baseReverseDic[alphabet] = {};
|
|
27
|
+
for (var i=0 ; i<alphabet.length ; i++) {
|
|
28
|
+
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return baseReverseDic[alphabet][character];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var LZString = {
|
|
35
|
+
compressToBase64 : function (input) {
|
|
36
|
+
if (input == null) return "";
|
|
37
|
+
var res = LZString._compress(input, 6, function(a){return keyStrBase64.charAt(a);});
|
|
38
|
+
switch (res.length % 4) { // To produce valid Base64
|
|
39
|
+
default: // When could this happen ?
|
|
40
|
+
case 0 : return res;
|
|
41
|
+
case 1 : return res+"===";
|
|
42
|
+
case 2 : return res+"==";
|
|
43
|
+
case 3 : return res+"=";
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
decompressFromBase64 : function (input) {
|
|
48
|
+
if (input == null) return "";
|
|
49
|
+
if (input == "") return null;
|
|
50
|
+
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrBase64, input.charAt(index)); });
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
compressToUTF16 : function (input) {
|
|
54
|
+
if (input == null) return "";
|
|
55
|
+
return LZString._compress(input, 15, function(a){return f(a+32);}) + " ";
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
decompressFromUTF16: function (compressed) {
|
|
59
|
+
if (compressed == null) return "";
|
|
60
|
+
if (compressed == "") return null;
|
|
61
|
+
return LZString._decompress(compressed.length, 16384, function(index) { return compressed.charCodeAt(index) - 32; });
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
//compress into uint8array (UCS-2 big endian format)
|
|
65
|
+
compressToUint8Array: function (uncompressed) {
|
|
66
|
+
var compressed = LZString.compress(uncompressed);
|
|
67
|
+
var buf=new Uint8Array(compressed.length*2); // 2 bytes per character
|
|
68
|
+
|
|
69
|
+
for (var i=0, TotalLen=compressed.length; i<TotalLen; i++) {
|
|
70
|
+
var current_value = compressed.charCodeAt(i);
|
|
71
|
+
buf[i*2] = current_value >>> 8;
|
|
72
|
+
buf[i*2+1] = current_value % 256;
|
|
73
|
+
}
|
|
74
|
+
return buf;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
//decompress from uint8array (UCS-2 big endian format)
|
|
78
|
+
decompressFromUint8Array:function (compressed) {
|
|
79
|
+
if (compressed===null || compressed===undefined){
|
|
80
|
+
return LZString.decompress(compressed);
|
|
81
|
+
} else {
|
|
82
|
+
var buf=new Array(compressed.length/2); // 2 bytes per character
|
|
83
|
+
for (var i=0, TotalLen=buf.length; i<TotalLen; i++) {
|
|
84
|
+
buf[i]=compressed[i*2]*256+compressed[i*2+1];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var result = [];
|
|
88
|
+
buf.forEach(function (c) {
|
|
89
|
+
result.push(f(c));
|
|
90
|
+
});
|
|
91
|
+
return LZString.decompress(result.join(''));
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
//compress into a string that is already URI encoded
|
|
99
|
+
compressToEncodedURIComponent: function (input) {
|
|
100
|
+
if (input == null) return "";
|
|
101
|
+
return LZString._compress(input, 6, function(a){return keyStrUriSafe.charAt(a);});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
//decompress from an output of compressToEncodedURIComponent
|
|
105
|
+
decompressFromEncodedURIComponent:function (input) {
|
|
106
|
+
if (input == null) return "";
|
|
107
|
+
if (input == "") return null;
|
|
108
|
+
input = input.replace(/ /g, "+");
|
|
109
|
+
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrUriSafe, input.charAt(index)); });
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
compress: function (uncompressed) {
|
|
113
|
+
return LZString._compress(uncompressed, 16, function(a){return f(a);});
|
|
114
|
+
},
|
|
115
|
+
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
116
|
+
if (uncompressed == null) return "";
|
|
117
|
+
var i, value,
|
|
118
|
+
context_dictionary= {},
|
|
119
|
+
context_dictionaryToCreate= {},
|
|
120
|
+
context_c="",
|
|
121
|
+
context_wc="",
|
|
122
|
+
context_w="",
|
|
123
|
+
context_enlargeIn= 2, // Compensate for the first entry which should not count
|
|
124
|
+
context_dictSize= 3,
|
|
125
|
+
context_numBits= 2,
|
|
126
|
+
context_data=[],
|
|
127
|
+
context_data_val=0,
|
|
128
|
+
context_data_position=0,
|
|
129
|
+
ii;
|
|
130
|
+
|
|
131
|
+
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
132
|
+
context_c = uncompressed.charAt(ii);
|
|
133
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionary,context_c)) {
|
|
134
|
+
context_dictionary[context_c] = context_dictSize++;
|
|
135
|
+
context_dictionaryToCreate[context_c] = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
context_wc = context_w + context_c;
|
|
139
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionary,context_wc)) {
|
|
140
|
+
context_w = context_wc;
|
|
141
|
+
} else {
|
|
142
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
|
|
143
|
+
if (context_w.charCodeAt(0)<256) {
|
|
144
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
145
|
+
context_data_val = (context_data_val << 1);
|
|
146
|
+
if (context_data_position == bitsPerChar-1) {
|
|
147
|
+
context_data_position = 0;
|
|
148
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
149
|
+
context_data_val = 0;
|
|
150
|
+
} else {
|
|
151
|
+
context_data_position++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
value = context_w.charCodeAt(0);
|
|
155
|
+
for (i=0 ; i<8 ; i++) {
|
|
156
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
157
|
+
if (context_data_position == bitsPerChar-1) {
|
|
158
|
+
context_data_position = 0;
|
|
159
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
160
|
+
context_data_val = 0;
|
|
161
|
+
} else {
|
|
162
|
+
context_data_position++;
|
|
163
|
+
}
|
|
164
|
+
value = value >> 1;
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
value = 1;
|
|
168
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
169
|
+
context_data_val = (context_data_val << 1) | value;
|
|
170
|
+
if (context_data_position ==bitsPerChar-1) {
|
|
171
|
+
context_data_position = 0;
|
|
172
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
173
|
+
context_data_val = 0;
|
|
174
|
+
} else {
|
|
175
|
+
context_data_position++;
|
|
176
|
+
}
|
|
177
|
+
value = 0;
|
|
178
|
+
}
|
|
179
|
+
value = context_w.charCodeAt(0);
|
|
180
|
+
for (i=0 ; i<16 ; i++) {
|
|
181
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
182
|
+
if (context_data_position == bitsPerChar-1) {
|
|
183
|
+
context_data_position = 0;
|
|
184
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
185
|
+
context_data_val = 0;
|
|
186
|
+
} else {
|
|
187
|
+
context_data_position++;
|
|
188
|
+
}
|
|
189
|
+
value = value >> 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
context_enlargeIn--;
|
|
193
|
+
if (context_enlargeIn == 0) {
|
|
194
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
195
|
+
context_numBits++;
|
|
196
|
+
}
|
|
197
|
+
delete context_dictionaryToCreate[context_w];
|
|
198
|
+
} else {
|
|
199
|
+
value = context_dictionary[context_w];
|
|
200
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
201
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
202
|
+
if (context_data_position == bitsPerChar-1) {
|
|
203
|
+
context_data_position = 0;
|
|
204
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
205
|
+
context_data_val = 0;
|
|
206
|
+
} else {
|
|
207
|
+
context_data_position++;
|
|
208
|
+
}
|
|
209
|
+
value = value >> 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
context_enlargeIn--;
|
|
215
|
+
if (context_enlargeIn == 0) {
|
|
216
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
217
|
+
context_numBits++;
|
|
218
|
+
}
|
|
219
|
+
// Add wc to the dictionary.
|
|
220
|
+
context_dictionary[context_wc] = context_dictSize++;
|
|
221
|
+
context_w = String(context_c);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Output the code for w.
|
|
226
|
+
if (context_w !== "") {
|
|
227
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
|
|
228
|
+
if (context_w.charCodeAt(0)<256) {
|
|
229
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
230
|
+
context_data_val = (context_data_val << 1);
|
|
231
|
+
if (context_data_position == bitsPerChar-1) {
|
|
232
|
+
context_data_position = 0;
|
|
233
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
234
|
+
context_data_val = 0;
|
|
235
|
+
} else {
|
|
236
|
+
context_data_position++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
value = context_w.charCodeAt(0);
|
|
240
|
+
for (i=0 ; i<8 ; i++) {
|
|
241
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
242
|
+
if (context_data_position == bitsPerChar-1) {
|
|
243
|
+
context_data_position = 0;
|
|
244
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
245
|
+
context_data_val = 0;
|
|
246
|
+
} else {
|
|
247
|
+
context_data_position++;
|
|
248
|
+
}
|
|
249
|
+
value = value >> 1;
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
value = 1;
|
|
253
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
254
|
+
context_data_val = (context_data_val << 1) | value;
|
|
255
|
+
if (context_data_position == bitsPerChar-1) {
|
|
256
|
+
context_data_position = 0;
|
|
257
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
258
|
+
context_data_val = 0;
|
|
259
|
+
} else {
|
|
260
|
+
context_data_position++;
|
|
261
|
+
}
|
|
262
|
+
value = 0;
|
|
263
|
+
}
|
|
264
|
+
value = context_w.charCodeAt(0);
|
|
265
|
+
for (i=0 ; i<16 ; i++) {
|
|
266
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
267
|
+
if (context_data_position == bitsPerChar-1) {
|
|
268
|
+
context_data_position = 0;
|
|
269
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
270
|
+
context_data_val = 0;
|
|
271
|
+
} else {
|
|
272
|
+
context_data_position++;
|
|
273
|
+
}
|
|
274
|
+
value = value >> 1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
context_enlargeIn--;
|
|
278
|
+
if (context_enlargeIn == 0) {
|
|
279
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
280
|
+
context_numBits++;
|
|
281
|
+
}
|
|
282
|
+
delete context_dictionaryToCreate[context_w];
|
|
283
|
+
} else {
|
|
284
|
+
value = context_dictionary[context_w];
|
|
285
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
286
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
287
|
+
if (context_data_position == bitsPerChar-1) {
|
|
288
|
+
context_data_position = 0;
|
|
289
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
290
|
+
context_data_val = 0;
|
|
291
|
+
} else {
|
|
292
|
+
context_data_position++;
|
|
293
|
+
}
|
|
294
|
+
value = value >> 1;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
}
|
|
299
|
+
context_enlargeIn--;
|
|
300
|
+
if (context_enlargeIn == 0) {
|
|
301
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
302
|
+
context_numBits++;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Mark the end of the stream
|
|
307
|
+
value = 2;
|
|
308
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
309
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
310
|
+
if (context_data_position == bitsPerChar-1) {
|
|
311
|
+
context_data_position = 0;
|
|
312
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
313
|
+
context_data_val = 0;
|
|
314
|
+
} else {
|
|
315
|
+
context_data_position++;
|
|
316
|
+
}
|
|
317
|
+
value = value >> 1;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Flush the last char
|
|
321
|
+
while (true) {
|
|
322
|
+
context_data_val = (context_data_val << 1);
|
|
323
|
+
if (context_data_position == bitsPerChar-1) {
|
|
324
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
else context_data_position++;
|
|
328
|
+
}
|
|
329
|
+
return context_data.join('');
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
decompress: function (compressed) {
|
|
333
|
+
if (compressed == null) return "";
|
|
334
|
+
if (compressed == "") return null;
|
|
335
|
+
return LZString._decompress(compressed.length, 32768, function(index) { return compressed.charCodeAt(index); });
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
_decompress: function (length, resetValue, getNextValue) {
|
|
339
|
+
var dictionary = [],
|
|
340
|
+
enlargeIn = 4,
|
|
341
|
+
dictSize = 4,
|
|
342
|
+
numBits = 3,
|
|
343
|
+
entry = "",
|
|
344
|
+
result = [],
|
|
345
|
+
i,
|
|
346
|
+
w,
|
|
347
|
+
bits, resb, maxpower, power,
|
|
348
|
+
c,
|
|
349
|
+
data = {val:getNextValue(0), position:resetValue, index:1};
|
|
350
|
+
|
|
351
|
+
for (i = 0; i < 3; i += 1) {
|
|
352
|
+
dictionary[i] = i;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
bits = 0;
|
|
356
|
+
maxpower = Math.pow(2,2);
|
|
357
|
+
power=1;
|
|
358
|
+
while (power!=maxpower) {
|
|
359
|
+
resb = data.val & data.position;
|
|
360
|
+
data.position >>= 1;
|
|
361
|
+
if (data.position == 0) {
|
|
362
|
+
data.position = resetValue;
|
|
363
|
+
data.val = getNextValue(data.index++);
|
|
364
|
+
}
|
|
365
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
366
|
+
power <<= 1;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
switch (bits) {
|
|
370
|
+
case 0:
|
|
371
|
+
bits = 0;
|
|
372
|
+
maxpower = Math.pow(2,8);
|
|
373
|
+
power=1;
|
|
374
|
+
while (power!=maxpower) {
|
|
375
|
+
resb = data.val & data.position;
|
|
376
|
+
data.position >>= 1;
|
|
377
|
+
if (data.position == 0) {
|
|
378
|
+
data.position = resetValue;
|
|
379
|
+
data.val = getNextValue(data.index++);
|
|
380
|
+
}
|
|
381
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
382
|
+
power <<= 1;
|
|
383
|
+
}
|
|
384
|
+
c = f(bits);
|
|
385
|
+
break;
|
|
386
|
+
case 1:
|
|
387
|
+
bits = 0;
|
|
388
|
+
maxpower = Math.pow(2,16);
|
|
389
|
+
power=1;
|
|
390
|
+
while (power!=maxpower) {
|
|
391
|
+
resb = data.val & data.position;
|
|
392
|
+
data.position >>= 1;
|
|
393
|
+
if (data.position == 0) {
|
|
394
|
+
data.position = resetValue;
|
|
395
|
+
data.val = getNextValue(data.index++);
|
|
396
|
+
}
|
|
397
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
398
|
+
power <<= 1;
|
|
399
|
+
}
|
|
400
|
+
c = f(bits);
|
|
401
|
+
break;
|
|
402
|
+
case 2:
|
|
403
|
+
return "";
|
|
404
|
+
}
|
|
405
|
+
dictionary[3] = c;
|
|
406
|
+
w = c;
|
|
407
|
+
result.push(c);
|
|
408
|
+
while (true) {
|
|
409
|
+
if (data.index > length) {
|
|
410
|
+
return "";
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
bits = 0;
|
|
414
|
+
maxpower = Math.pow(2,numBits);
|
|
415
|
+
power=1;
|
|
416
|
+
while (power!=maxpower) {
|
|
417
|
+
resb = data.val & data.position;
|
|
418
|
+
data.position >>= 1;
|
|
419
|
+
if (data.position == 0) {
|
|
420
|
+
data.position = resetValue;
|
|
421
|
+
data.val = getNextValue(data.index++);
|
|
422
|
+
}
|
|
423
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
424
|
+
power <<= 1;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
switch (c = bits) {
|
|
428
|
+
case 0:
|
|
429
|
+
bits = 0;
|
|
430
|
+
maxpower = Math.pow(2,8);
|
|
431
|
+
power=1;
|
|
432
|
+
while (power!=maxpower) {
|
|
433
|
+
resb = data.val & data.position;
|
|
434
|
+
data.position >>= 1;
|
|
435
|
+
if (data.position == 0) {
|
|
436
|
+
data.position = resetValue;
|
|
437
|
+
data.val = getNextValue(data.index++);
|
|
438
|
+
}
|
|
439
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
440
|
+
power <<= 1;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
dictionary[dictSize++] = f(bits);
|
|
444
|
+
c = dictSize-1;
|
|
445
|
+
enlargeIn--;
|
|
446
|
+
break;
|
|
447
|
+
case 1:
|
|
448
|
+
bits = 0;
|
|
449
|
+
maxpower = Math.pow(2,16);
|
|
450
|
+
power=1;
|
|
451
|
+
while (power!=maxpower) {
|
|
452
|
+
resb = data.val & data.position;
|
|
453
|
+
data.position >>= 1;
|
|
454
|
+
if (data.position == 0) {
|
|
455
|
+
data.position = resetValue;
|
|
456
|
+
data.val = getNextValue(data.index++);
|
|
457
|
+
}
|
|
458
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
459
|
+
power <<= 1;
|
|
460
|
+
}
|
|
461
|
+
dictionary[dictSize++] = f(bits);
|
|
462
|
+
c = dictSize-1;
|
|
463
|
+
enlargeIn--;
|
|
464
|
+
break;
|
|
465
|
+
case 2:
|
|
466
|
+
return result.join('');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (enlargeIn == 0) {
|
|
470
|
+
enlargeIn = Math.pow(2, numBits);
|
|
471
|
+
numBits++;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (dictionary[c]) {
|
|
475
|
+
entry = dictionary[c];
|
|
476
|
+
} else {
|
|
477
|
+
if (c === dictSize) {
|
|
478
|
+
entry = w + w.charAt(0);
|
|
479
|
+
} else {
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
result.push(entry);
|
|
484
|
+
|
|
485
|
+
// Add w+entry[0] to the dictionary.
|
|
486
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
487
|
+
enlargeIn--;
|
|
488
|
+
|
|
489
|
+
w = entry;
|
|
490
|
+
|
|
491
|
+
if (enlargeIn == 0) {
|
|
492
|
+
enlargeIn = Math.pow(2, numBits);
|
|
493
|
+
numBits++;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
return LZString;
|
|
500
|
+
})();
|
|
501
|
+
|
|
502
|
+
if( module != null ) {
|
|
503
|
+
module.exports = LZString;
|
|
504
|
+
} else if( typeof angular !== 'undefined' && angular != null ) {
|
|
505
|
+
angular.module('LZString', [])
|
|
506
|
+
.factory('LZString', function () {
|
|
507
|
+
return LZString;
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
} (lzString$1));
|
|
511
|
+
|
|
512
|
+
var lzStringExports = lzString$1.exports;
|
|
513
|
+
var lzString = /*@__PURE__*/getDefaultExportFromCjs(lzStringExports);
|
|
514
|
+
|
|
515
|
+
export { lzString as default };
|