@hpcc-js/util 2.45.0 → 2.46.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/LICENSE +43 -43
- package/dist/index.js +2290 -2289
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib-es6/__package__.js +3 -3
- package/lib-es6/array.js +84 -84
- package/lib-es6/array.js.map +1 -1
- package/lib-es6/cache.js +60 -60
- package/lib-es6/debounce.js +85 -85
- package/lib-es6/dictionary.js +61 -61
- package/lib-es6/dispatch.js +101 -101
- package/lib-es6/esp.js +32 -32
- package/lib-es6/graph.js +348 -348
- package/lib-es6/graph.js.map +1 -1
- package/lib-es6/graph2.js +603 -603
- package/lib-es6/graph2.js.map +1 -1
- package/lib-es6/hashSum.js +49 -49
- package/lib-es6/immutable.js +54 -54
- package/lib-es6/index.js +21 -21
- package/lib-es6/logging.js +177 -177
- package/lib-es6/logging.js.map +1 -1
- package/lib-es6/math.js +90 -90
- package/lib-es6/object.js +121 -121
- package/lib-es6/object.js.map +1 -1
- package/lib-es6/observer.js +79 -79
- package/lib-es6/platform.js +17 -17
- package/lib-es6/saxParser.js +125 -125
- package/lib-es6/stack.js +41 -41
- package/lib-es6/stateful.js +170 -170
- package/lib-es6/string.js +22 -22
- package/lib-es6/url.js +32 -32
- package/lib-es6/url.js.map +1 -1
- package/package.json +6 -21
- package/src/__package__.ts +2 -2
- package/src/array.ts +98 -98
- package/src/cache.ts +65 -65
- package/src/debounce.ts +88 -88
- package/src/dictionary.ts +69 -69
- package/src/dispatch.ts +119 -119
- package/src/esp.ts +32 -32
- package/src/graph.ts +353 -353
- package/src/graph2.ts +661 -661
- package/src/hashSum.ts +55 -55
- package/src/immutable.ts +57 -57
- package/src/index.ts +21 -21
- package/src/logging.ts +211 -211
- package/src/math.ts +92 -92
- package/src/object.ts +117 -117
- package/src/observer.ts +91 -91
- package/src/platform.ts +20 -20
- package/src/saxParser.ts +135 -135
- package/src/stack.ts +41 -41
- package/src/stateful.ts +178 -178
- package/src/string.ts +21 -21
- package/src/url.ts +27 -27
- package/types/__package__.d.ts +3 -3
- package/types/array.d.ts +13 -13
- package/types/cache.d.ts +20 -20
- package/types/debounce.d.ts +12 -12
- package/types/dictionary.d.ts +20 -20
- package/types/dispatch.d.ts +26 -26
- package/types/esp.d.ts +1 -1
- package/types/graph.d.ts +73 -73
- package/types/graph2.d.ts +111 -111
- package/types/hashSum.d.ts +1 -1
- package/types/immutable.d.ts +2 -2
- package/types/index.d.ts +21 -21
- package/types/logging.d.ts +57 -57
- package/types/math.d.ts +70 -70
- package/types/object.d.ts +48 -48
- package/types/observer.d.ts +18 -18
- package/types/platform.d.ts +5 -5
- package/types/saxParser.d.ts +28 -28
- package/types/stack.d.ts +28 -28
- package/types/stateful.d.ts +33 -33
- package/types/string.d.ts +2 -2
- package/types/url.d.ts +2 -2
- package/types-3.4/__package__.d.ts +2 -2
package/lib-es6/string.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export function trim(str, char) {
|
|
2
|
-
if (typeof char !== "string")
|
|
3
|
-
return str;
|
|
4
|
-
if (char.length === 0)
|
|
5
|
-
return str;
|
|
6
|
-
while (str.indexOf(char) === 0) {
|
|
7
|
-
str = str.substring(1);
|
|
8
|
-
}
|
|
9
|
-
while (endsWith(str, char)) {
|
|
10
|
-
str = str.substring(0, str.length - 1);
|
|
11
|
-
}
|
|
12
|
-
return str;
|
|
13
|
-
}
|
|
14
|
-
export function endsWith(origString, searchString, position) {
|
|
15
|
-
var subjectString = origString.toString();
|
|
16
|
-
if (typeof position !== "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
|
|
17
|
-
position = subjectString.length;
|
|
18
|
-
}
|
|
19
|
-
position -= searchString.length;
|
|
20
|
-
var lastIndex = subjectString.lastIndexOf(searchString, position);
|
|
21
|
-
return lastIndex !== -1 && lastIndex === position;
|
|
22
|
-
}
|
|
1
|
+
export function trim(str, char) {
|
|
2
|
+
if (typeof char !== "string")
|
|
3
|
+
return str;
|
|
4
|
+
if (char.length === 0)
|
|
5
|
+
return str;
|
|
6
|
+
while (str.indexOf(char) === 0) {
|
|
7
|
+
str = str.substring(1);
|
|
8
|
+
}
|
|
9
|
+
while (endsWith(str, char)) {
|
|
10
|
+
str = str.substring(0, str.length - 1);
|
|
11
|
+
}
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
export function endsWith(origString, searchString, position) {
|
|
15
|
+
var subjectString = origString.toString();
|
|
16
|
+
if (typeof position !== "number" || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
|
|
17
|
+
position = subjectString.length;
|
|
18
|
+
}
|
|
19
|
+
position -= searchString.length;
|
|
20
|
+
var lastIndex = subjectString.lastIndexOf(searchString, position);
|
|
21
|
+
return lastIndex !== -1 && lastIndex === position;
|
|
22
|
+
}
|
|
23
23
|
//# sourceMappingURL=string.js.map
|
package/lib-es6/url.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { __spreadArray } from "tslib";
|
|
2
|
-
export function join() {
|
|
3
|
-
var segments = [];
|
|
4
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5
|
-
segments[_i] = arguments[_i];
|
|
6
|
-
}
|
|
7
|
-
var parts = segments.reduce(function (parts, segment) {
|
|
8
|
-
// Remove leading slashes from non-first part.
|
|
9
|
-
if (parts.length > 0) {
|
|
10
|
-
segment = segment.replace(/^\//, "");
|
|
11
|
-
}
|
|
12
|
-
// Remove trailing slashes.
|
|
13
|
-
segment = segment.replace(/\/$/, "");
|
|
14
|
-
return __spreadArray(__spreadArray([], parts), segment.split("/"));
|
|
15
|
-
}, []);
|
|
16
|
-
var resultParts = [];
|
|
17
|
-
for (var _a = 0, parts_1 = parts; _a < parts_1.length; _a++) {
|
|
18
|
-
var part = parts_1[_a];
|
|
19
|
-
if (part === ".") {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (part === "..") {
|
|
23
|
-
resultParts.pop();
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
resultParts.push(part);
|
|
27
|
-
}
|
|
28
|
-
return resultParts.join("/");
|
|
29
|
-
}
|
|
30
|
-
export function dirname(path) {
|
|
31
|
-
return join(path, "..");
|
|
32
|
-
}
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
export function join() {
|
|
3
|
+
var segments = [];
|
|
4
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5
|
+
segments[_i] = arguments[_i];
|
|
6
|
+
}
|
|
7
|
+
var parts = segments.reduce(function (parts, segment) {
|
|
8
|
+
// Remove leading slashes from non-first part.
|
|
9
|
+
if (parts.length > 0) {
|
|
10
|
+
segment = segment.replace(/^\//, "");
|
|
11
|
+
}
|
|
12
|
+
// Remove trailing slashes.
|
|
13
|
+
segment = segment.replace(/\/$/, "");
|
|
14
|
+
return __spreadArray(__spreadArray([], parts, true), segment.split("/"), true);
|
|
15
|
+
}, []);
|
|
16
|
+
var resultParts = [];
|
|
17
|
+
for (var _a = 0, parts_1 = parts; _a < parts_1.length; _a++) {
|
|
18
|
+
var part = parts_1[_a];
|
|
19
|
+
if (part === ".") {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (part === "..") {
|
|
23
|
+
resultParts.pop();
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
resultParts.push(part);
|
|
27
|
+
}
|
|
28
|
+
return resultParts.join("/");
|
|
29
|
+
}
|
|
30
|
+
export function dirname(path) {
|
|
31
|
+
return join(path, "..");
|
|
32
|
+
}
|
|
33
33
|
//# sourceMappingURL=url.js.map
|
package/lib-es6/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":";AAAA,MAAM,UAAU,IAAI;IAAC,kBAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,6BAAqB;;IACtC,IAAM,KAAK,GAAa,QAAQ,CAAC,MAAM,CAAC,UAAC,KAAK,EAAE,OAAO;QACnD,8CAA8C;QAC9C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAClB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SACxC;QACD,2BAA2B;QAC3B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrC,uCAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":";AAAA,MAAM,UAAU,IAAI;IAAC,kBAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,6BAAqB;;IACtC,IAAM,KAAK,GAAa,QAAQ,CAAC,MAAM,CAAC,UAAC,KAAK,EAAE,OAAO;QACnD,8CAA8C;QAC9C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;YAClB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SACxC;QACD,2BAA2B;QAC3B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACrC,uCAAW,KAAK,SAAK,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,QAAE;IAC7C,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,IAAM,WAAW,GAAG,EAAE,CAAC;IACvB,KAAmB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE;QAArB,IAAM,IAAI,cAAA;QACX,IAAI,IAAI,KAAK,GAAG,EAAE;YACd,SAAS;SACZ;QACD,IAAI,IAAI,KAAK,IAAI,EAAE;YACf,WAAW,CAAC,GAAG,EAAE,CAAC;YAClB,SAAS;SACZ;QACD,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC1B;IACD,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/util",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.46.1",
|
|
4
4
|
"description": "hpcc-js - Utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib-es6/index",
|
|
@@ -33,32 +33,17 @@
|
|
|
33
33
|
"gen-legacy-types": "downlevel-dts ./types ./types-3.4",
|
|
34
34
|
"build": "npm run compile-es6 && npm run bundle",
|
|
35
35
|
"watch": "npm-run-all compile-es6 -p compile-es6-watch bundle-watch",
|
|
36
|
-
"stamp": "node node_modules/@hpcc-js/bundle/src/stamp.js",
|
|
36
|
+
"stamp": "node ../../node_modules/@hpcc-js/bundle/src/stamp.js",
|
|
37
37
|
"lint": "eslint src/**/*.ts",
|
|
38
38
|
"docs": "typedoc --options tdoptions.json .",
|
|
39
39
|
"update": "npx npm-check-updates -u -t minor"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"tslib": "2.3.
|
|
42
|
+
"tslib": "2.3.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@hpcc-js/bundle": "^2.
|
|
46
|
-
"
|
|
47
|
-
"@rollup/plugin-commonjs": "12.0.0",
|
|
48
|
-
"@rollup/plugin-node-resolve": "8.0.0",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "4.31.0",
|
|
50
|
-
"@typescript-eslint/parser": "4.31.0",
|
|
51
|
-
"downlevel-dts": "0.6.0",
|
|
52
|
-
"eslint": "7.32.0",
|
|
53
|
-
"eslint-plugin-react-hooks": "^4.3.0",
|
|
54
|
-
"npm-run-all": "4.1.5",
|
|
55
|
-
"rimraf": "2.6.3",
|
|
56
|
-
"rollup": "2.10.7",
|
|
57
|
-
"rollup-plugin-postcss": "3.1.1",
|
|
58
|
-
"rollup-plugin-sourcemaps": "0.6.2",
|
|
59
|
-
"terser": "4.0.0",
|
|
60
|
-
"typedoc": "0.14.2",
|
|
61
|
-
"typescript": "4.3.4"
|
|
45
|
+
"@hpcc-js/bundle": "^2.11.1",
|
|
46
|
+
"rimraf": "2.7.1"
|
|
62
47
|
},
|
|
63
48
|
"repository": {
|
|
64
49
|
"type": "git",
|
|
@@ -71,5 +56,5 @@
|
|
|
71
56
|
"url": "https://github.com/hpcc-systems/Visualization/issues"
|
|
72
57
|
},
|
|
73
58
|
"homepage": "https://github.com/hpcc-systems/Visualization",
|
|
74
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "bc245d3dccc358e21bc1b2103f6d88bb75b9f999"
|
|
75
60
|
}
|
package/src/__package__.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const PKG_NAME = "@hpcc-js/util";
|
|
2
|
-
export const PKG_VERSION = "2.
|
|
3
|
-
export const BUILD_VERSION = "2.
|
|
2
|
+
export const PKG_VERSION = "2.46.1";
|
|
3
|
+
export const BUILD_VERSION = "2.102.1";
|
package/src/array.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
// Based on: https://tc39.github.io/ecma262/#sec-array.prototype.find
|
|
2
|
-
export function find<T>(o: ReadonlyArray<T>, predicate: (value: T, index: number) => boolean) {
|
|
3
|
-
// 1. Let O be ? ToObject(this value).
|
|
4
|
-
if (o == null) {
|
|
5
|
-
throw new TypeError('"o" is null or not defined');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// 2. Let len be ? ToLength(? Get(O, "length")).
|
|
9
|
-
const len = o.length >>> 0;
|
|
10
|
-
|
|
11
|
-
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
|
12
|
-
if (typeof predicate !== "function") {
|
|
13
|
-
throw new TypeError("predicate must be a function");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
17
|
-
const thisArg = arguments[1];
|
|
18
|
-
|
|
19
|
-
// 5. Let k be 0.
|
|
20
|
-
let k = 0;
|
|
21
|
-
|
|
22
|
-
// 6. Repeat, while k < len
|
|
23
|
-
while (k < len) {
|
|
24
|
-
// a. Let Pk be ! ToString(k).
|
|
25
|
-
// b. Let kValue be ? Get(O, Pk).
|
|
26
|
-
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
|
27
|
-
// d. If testResult is true, return kValue.
|
|
28
|
-
const kValue = o[k];
|
|
29
|
-
if (predicate.call(thisArg, kValue, k, o)) {
|
|
30
|
-
return kValue;
|
|
31
|
-
}
|
|
32
|
-
// e. Increase k by 1.
|
|
33
|
-
k++;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 7. Return undefined.
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface IDifferences2<T> {
|
|
41
|
-
update: T[];
|
|
42
|
-
exit: T[];
|
|
43
|
-
enter: T[];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function compare<T>(before: readonly T[], after: readonly T[]): IDifferences2<T> {
|
|
47
|
-
const retVal: IDifferences2<T> = {
|
|
48
|
-
update: [],
|
|
49
|
-
exit: [],
|
|
50
|
-
enter: [...after]
|
|
51
|
-
};
|
|
52
|
-
for (const row of before) {
|
|
53
|
-
const otherIdx = retVal.enter.indexOf(row);
|
|
54
|
-
if (otherIdx >= 0) {
|
|
55
|
-
retVal.update.push(row);
|
|
56
|
-
retVal.enter.splice(otherIdx, 1);
|
|
57
|
-
} else {
|
|
58
|
-
retVal.exit.push(row);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return retVal;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface IDifferences2<T> {
|
|
65
|
-
enter: T[];
|
|
66
|
-
update: T[];
|
|
67
|
-
exit: T[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function compare2<T>(before: readonly T[], after: readonly T[], idFunc: (itme: T) => string | number, updateFunc: (before: T, after: T) => T = (before, after) => after): IDifferences2<T> {
|
|
71
|
-
const retVal: IDifferences2<T> = {
|
|
72
|
-
update: [],
|
|
73
|
-
exit: [],
|
|
74
|
-
enter: []
|
|
75
|
-
};
|
|
76
|
-
if (before === after) {
|
|
77
|
-
retVal.update = before as T[];
|
|
78
|
-
return retVal;
|
|
79
|
-
}
|
|
80
|
-
const unknownMap: { [key: string]: T } = {};
|
|
81
|
-
after.forEach(item => {
|
|
82
|
-
unknownMap[idFunc(item)] = item;
|
|
83
|
-
});
|
|
84
|
-
for (const row of before) {
|
|
85
|
-
const id = idFunc(row);
|
|
86
|
-
const item = unknownMap[id];
|
|
87
|
-
if (item !== undefined) {
|
|
88
|
-
delete unknownMap[id];
|
|
89
|
-
retVal.update.push(updateFunc(row, item));
|
|
90
|
-
} else {
|
|
91
|
-
retVal.exit.push(row);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
for (const key in unknownMap) {
|
|
95
|
-
retVal.enter.push(unknownMap[key]);
|
|
96
|
-
}
|
|
97
|
-
return retVal;
|
|
98
|
-
}
|
|
1
|
+
// Based on: https://tc39.github.io/ecma262/#sec-array.prototype.find
|
|
2
|
+
export function find<T>(o: ReadonlyArray<T>, predicate: (value: T, index: number) => boolean) {
|
|
3
|
+
// 1. Let O be ? ToObject(this value).
|
|
4
|
+
if (o == null) {
|
|
5
|
+
throw new TypeError('"o" is null or not defined');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// 2. Let len be ? ToLength(? Get(O, "length")).
|
|
9
|
+
const len = o.length >>> 0;
|
|
10
|
+
|
|
11
|
+
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
|
12
|
+
if (typeof predicate !== "function") {
|
|
13
|
+
throw new TypeError("predicate must be a function");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
17
|
+
const thisArg = arguments[1];
|
|
18
|
+
|
|
19
|
+
// 5. Let k be 0.
|
|
20
|
+
let k = 0;
|
|
21
|
+
|
|
22
|
+
// 6. Repeat, while k < len
|
|
23
|
+
while (k < len) {
|
|
24
|
+
// a. Let Pk be ! ToString(k).
|
|
25
|
+
// b. Let kValue be ? Get(O, Pk).
|
|
26
|
+
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
|
27
|
+
// d. If testResult is true, return kValue.
|
|
28
|
+
const kValue = o[k];
|
|
29
|
+
if (predicate.call(thisArg, kValue, k, o)) {
|
|
30
|
+
return kValue;
|
|
31
|
+
}
|
|
32
|
+
// e. Increase k by 1.
|
|
33
|
+
k++;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 7. Return undefined.
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IDifferences2<T> {
|
|
41
|
+
update: T[];
|
|
42
|
+
exit: T[];
|
|
43
|
+
enter: T[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function compare<T>(before: readonly T[], after: readonly T[]): IDifferences2<T> {
|
|
47
|
+
const retVal: IDifferences2<T> = {
|
|
48
|
+
update: [],
|
|
49
|
+
exit: [],
|
|
50
|
+
enter: [...after]
|
|
51
|
+
};
|
|
52
|
+
for (const row of before) {
|
|
53
|
+
const otherIdx = retVal.enter.indexOf(row);
|
|
54
|
+
if (otherIdx >= 0) {
|
|
55
|
+
retVal.update.push(row);
|
|
56
|
+
retVal.enter.splice(otherIdx, 1);
|
|
57
|
+
} else {
|
|
58
|
+
retVal.exit.push(row);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return retVal;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface IDifferences2<T> {
|
|
65
|
+
enter: T[];
|
|
66
|
+
update: T[];
|
|
67
|
+
exit: T[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function compare2<T>(before: readonly T[], after: readonly T[], idFunc: (itme: T) => string | number, updateFunc: (before: T, after: T) => T = (before, after) => after): IDifferences2<T> {
|
|
71
|
+
const retVal: IDifferences2<T> = {
|
|
72
|
+
update: [],
|
|
73
|
+
exit: [],
|
|
74
|
+
enter: []
|
|
75
|
+
};
|
|
76
|
+
if (before === after) {
|
|
77
|
+
retVal.update = before as T[];
|
|
78
|
+
return retVal;
|
|
79
|
+
}
|
|
80
|
+
const unknownMap: { [key: string]: T } = {};
|
|
81
|
+
after.forEach(item => {
|
|
82
|
+
unknownMap[idFunc(item)] = item;
|
|
83
|
+
});
|
|
84
|
+
for (const row of before) {
|
|
85
|
+
const id = idFunc(row);
|
|
86
|
+
const item = unknownMap[id];
|
|
87
|
+
if (item !== undefined) {
|
|
88
|
+
delete unknownMap[id];
|
|
89
|
+
retVal.update.push(updateFunc(row, item));
|
|
90
|
+
} else {
|
|
91
|
+
retVal.exit.push(row);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const key in unknownMap) {
|
|
95
|
+
retVal.enter.push(unknownMap[key]);
|
|
96
|
+
}
|
|
97
|
+
return retVal;
|
|
98
|
+
}
|
package/src/cache.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { hashSum } from "./hashSum";
|
|
2
|
-
|
|
3
|
-
export class Cache<I, C> {
|
|
4
|
-
private _cache: { [id: string]: C } = {};
|
|
5
|
-
private _calcID: (espObj: I | C) => string;
|
|
6
|
-
|
|
7
|
-
static hash(...args: any[]) {
|
|
8
|
-
return hashSum({ ...args });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor(calcID: (espObj: I | C) => string) {
|
|
12
|
-
this._calcID = calcID;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
has(espObj: I): boolean {
|
|
16
|
-
return this._calcID(espObj) in this._cache;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set(obj: C): C {
|
|
20
|
-
this._cache[this._calcID(obj)] = obj;
|
|
21
|
-
return obj;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get(espObj: I): C | null;
|
|
25
|
-
get(espObj: I, factory: () => C): C;
|
|
26
|
-
get(espObj: I, factory?: () => C): C | null {
|
|
27
|
-
const retVal = this._cache[this._calcID(espObj)];
|
|
28
|
-
if (!retVal) {
|
|
29
|
-
return factory ? this.set(factory()) : null;
|
|
30
|
-
}
|
|
31
|
-
return retVal;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class AsyncCache<I, C> {
|
|
36
|
-
private _cache: { [id: string]: Promise<C> } = {};
|
|
37
|
-
private _calcID: (espObj: I | C) => string;
|
|
38
|
-
|
|
39
|
-
static hash(...args: any[]) {
|
|
40
|
-
return hashSum({ ...args });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
constructor(calcID: (espObj: I | C) => string) {
|
|
44
|
-
this._calcID = calcID;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
has(espObj: I): boolean {
|
|
48
|
-
return this._calcID(espObj) in this._cache;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
set(espObj: I, obj: Promise<C>): Promise<C> {
|
|
52
|
-
this._cache[this._calcID(espObj)] = obj;
|
|
53
|
-
return obj;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get(espObj: I): Promise<C | null>;
|
|
57
|
-
get(espObj: I, factory: () => Promise<C>): Promise<C>;
|
|
58
|
-
get(espObj: I, factory?: () => Promise<C>): Promise<C | null> {
|
|
59
|
-
const retVal = this._cache[this._calcID(espObj)];
|
|
60
|
-
if (!retVal) {
|
|
61
|
-
return factory ? this.set(espObj, factory()) : Promise.resolve(null);
|
|
62
|
-
}
|
|
63
|
-
return retVal;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
import { hashSum } from "./hashSum";
|
|
2
|
+
|
|
3
|
+
export class Cache<I, C> {
|
|
4
|
+
private _cache: { [id: string]: C } = {};
|
|
5
|
+
private _calcID: (espObj: I | C) => string;
|
|
6
|
+
|
|
7
|
+
static hash(...args: any[]) {
|
|
8
|
+
return hashSum({ ...args });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor(calcID: (espObj: I | C) => string) {
|
|
12
|
+
this._calcID = calcID;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
has(espObj: I): boolean {
|
|
16
|
+
return this._calcID(espObj) in this._cache;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set(obj: C): C {
|
|
20
|
+
this._cache[this._calcID(obj)] = obj;
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get(espObj: I): C | null;
|
|
25
|
+
get(espObj: I, factory: () => C): C;
|
|
26
|
+
get(espObj: I, factory?: () => C): C | null {
|
|
27
|
+
const retVal = this._cache[this._calcID(espObj)];
|
|
28
|
+
if (!retVal) {
|
|
29
|
+
return factory ? this.set(factory()) : null;
|
|
30
|
+
}
|
|
31
|
+
return retVal;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class AsyncCache<I, C> {
|
|
36
|
+
private _cache: { [id: string]: Promise<C> } = {};
|
|
37
|
+
private _calcID: (espObj: I | C) => string;
|
|
38
|
+
|
|
39
|
+
static hash(...args: any[]) {
|
|
40
|
+
return hashSum({ ...args });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
constructor(calcID: (espObj: I | C) => string) {
|
|
44
|
+
this._calcID = calcID;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
has(espObj: I): boolean {
|
|
48
|
+
return this._calcID(espObj) in this._cache;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set(espObj: I, obj: Promise<C>): Promise<C> {
|
|
52
|
+
this._cache[this._calcID(espObj)] = obj;
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get(espObj: I): Promise<C | null>;
|
|
57
|
+
get(espObj: I, factory: () => Promise<C>): Promise<C>;
|
|
58
|
+
get(espObj: I, factory?: () => Promise<C>): Promise<C | null> {
|
|
59
|
+
const retVal = this._cache[this._calcID(espObj)];
|
|
60
|
+
if (!retVal) {
|
|
61
|
+
return factory ? this.set(espObj, factory()) : Promise.resolve(null);
|
|
62
|
+
}
|
|
63
|
+
return retVal;
|
|
64
|
+
}
|
|
65
|
+
}
|