@devisfuture/mega-collection 2.4.3 → 2.4.5
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/chunk-BJZg_1dI.mjs +183 -0
- package/dist/chunk-BURK5sks.mjs +505 -0
- package/dist/chunk-C5Zpu_ol.mjs +18 -0
- package/dist/filter/index.d.mts +4 -110
- package/dist/filter/index.mjs +891 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +2 -1
- package/dist/merge/index.d.mts +4 -127
- package/dist/merge/index.mjs +2 -1
- package/dist/search/index.d.mts +4 -189
- package/dist/search/index.mjs +1010 -5
- package/dist/sort/index.d.mts +4 -54
- package/dist/sort/index.mjs +416 -1
- package/package.json +19 -8
- package/dist/State-2vKzwNrQ.d.mts +0 -44
- package/dist/chunk-IZXO22NQ.mjs +0 -1
- package/dist/chunk-MB56OSRQ.mjs +0 -1
- package/dist/types-DONld7xY.d.mts +0 -74
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
//#region src/State.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor(e = [], t = {}) {
|
|
4
|
+
this.itemIndexLookup = /* @__PURE__ */ new WeakMap(), this.mutationVersion = 0, this.namespaceSequence = 0, this.previousResultState = null, this.indexMaps = /* @__PURE__ */ new Map(), this.scopedRegistry = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.originData = e, this.filterByPreviousResult = t.filterByPreviousResult ?? !1, this.rebuildItemIndexLookup();
|
|
5
|
+
}
|
|
6
|
+
subscribe(e) {
|
|
7
|
+
return this.listeners.add(e), () => {
|
|
8
|
+
this.listeners.delete(e);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
getOriginData() {
|
|
12
|
+
return this.originData;
|
|
13
|
+
}
|
|
14
|
+
getItemIndex(e) {
|
|
15
|
+
return this.itemIndexLookup.get(e);
|
|
16
|
+
}
|
|
17
|
+
getMutationVersion() {
|
|
18
|
+
return this.mutationVersion;
|
|
19
|
+
}
|
|
20
|
+
isFilterByPreviousResultEnabled() {
|
|
21
|
+
return this.filterByPreviousResult;
|
|
22
|
+
}
|
|
23
|
+
setFilterByPreviousResult(e) {
|
|
24
|
+
this.filterByPreviousResult = e, e || this.clearPreviousResult();
|
|
25
|
+
}
|
|
26
|
+
getPreviousResult() {
|
|
27
|
+
return this.getPreviousResultState()?.result ?? null;
|
|
28
|
+
}
|
|
29
|
+
getPreviousResultState() {
|
|
30
|
+
return this.previousResultState === null || this.previousResultState.version !== this.mutationVersion ? null : this.previousResultState;
|
|
31
|
+
}
|
|
32
|
+
setPreviousResult(e, t) {
|
|
33
|
+
this.previousResultState = {
|
|
34
|
+
result: e,
|
|
35
|
+
sourceData: t,
|
|
36
|
+
version: this.mutationVersion
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
clearPreviousResult() {
|
|
40
|
+
this.previousResultState = null;
|
|
41
|
+
}
|
|
42
|
+
createNamespace(e = "scope") {
|
|
43
|
+
return this.namespaceSequence += 1, `${e}:${this.namespaceSequence}`;
|
|
44
|
+
}
|
|
45
|
+
getScopedValue(e, t) {
|
|
46
|
+
return this.scopedRegistry.get(e)?.get(t);
|
|
47
|
+
}
|
|
48
|
+
getOrCreateScopedValue(e, t, n) {
|
|
49
|
+
let r = this.getScopedValue(e, t);
|
|
50
|
+
if (r !== void 0) return r;
|
|
51
|
+
let i = this.getOrCreateScope(e), a = n();
|
|
52
|
+
return i.set(t, a), a;
|
|
53
|
+
}
|
|
54
|
+
setScopedValue(e, t, n) {
|
|
55
|
+
return this.getOrCreateScope(e).set(t, n), n;
|
|
56
|
+
}
|
|
57
|
+
deleteScopedValue(e, t) {
|
|
58
|
+
let n = this.scopedRegistry.get(e);
|
|
59
|
+
n && (n.delete(t), n.size === 0 && this.scopedRegistry.delete(e));
|
|
60
|
+
}
|
|
61
|
+
clearScope(e) {
|
|
62
|
+
this.scopedRegistry.delete(e);
|
|
63
|
+
}
|
|
64
|
+
data(e) {
|
|
65
|
+
this.originData = e, this.bumpMutationVersion(), this.rebuildItemIndexLookup();
|
|
66
|
+
for (let e of this.indexMaps.keys()) this.rebuildIndexMap(e);
|
|
67
|
+
this.emit({
|
|
68
|
+
type: "data",
|
|
69
|
+
data: e
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
add(e) {
|
|
73
|
+
if (e.length === 0) return;
|
|
74
|
+
let t = this.originData.length;
|
|
75
|
+
for (let n = 0; n < e.length; n++) this.originData.push(e[n]), this.itemIndexLookup.set(e[n], t + n);
|
|
76
|
+
this.bumpMutationVersion();
|
|
77
|
+
for (let [n, r] of this.indexMaps) for (let i = 0; i < e.length; i++) r.set(e[i][n], t + i);
|
|
78
|
+
this.emit({
|
|
79
|
+
type: "add",
|
|
80
|
+
items: e,
|
|
81
|
+
startIndex: t
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
update(e) {
|
|
85
|
+
let { field: t, data: n } = e, r = n[t];
|
|
86
|
+
if (r == null) return;
|
|
87
|
+
let i = this.getOrCreateIndexMap(t).get(r);
|
|
88
|
+
if (i === void 0) return;
|
|
89
|
+
let a = this.originData[i];
|
|
90
|
+
this.originData[i] = n, this.itemIndexLookup.delete(a), this.itemIndexLookup.set(n, i), this.bumpMutationVersion();
|
|
91
|
+
for (let [e, t] of this.indexMaps) {
|
|
92
|
+
let r = a[e], o = n[e];
|
|
93
|
+
r !== o && (t.get(r) === i && t.delete(r), t.set(o, i));
|
|
94
|
+
}
|
|
95
|
+
this.emit({
|
|
96
|
+
type: "update",
|
|
97
|
+
field: t,
|
|
98
|
+
index: i,
|
|
99
|
+
previousItem: a,
|
|
100
|
+
nextItem: n
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
clearData() {
|
|
104
|
+
let e = [];
|
|
105
|
+
this.originData = e, this.itemIndexLookup = /* @__PURE__ */ new WeakMap(), this.bumpMutationVersion();
|
|
106
|
+
for (let e of this.indexMaps.values()) e.clear();
|
|
107
|
+
this.emit({
|
|
108
|
+
type: "clearData",
|
|
109
|
+
data: e
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
removeByFieldValue(e, t) {
|
|
113
|
+
let n = this.getOrCreateIndexMap(e).get(t);
|
|
114
|
+
if (n === void 0) return;
|
|
115
|
+
let r = this.originData.length - 1, i = this.originData[n], a = n === r ? null : this.originData[r];
|
|
116
|
+
n !== r && a && (this.originData[n] = a, this.itemIndexLookup.set(a, n)), this.originData.pop(), this.itemIndexLookup.delete(i), this.bumpMutationVersion();
|
|
117
|
+
for (let [e, t] of this.indexMaps) {
|
|
118
|
+
let r = i[e];
|
|
119
|
+
t.get(r) === n && t.delete(r), a && t.set(a[e], n);
|
|
120
|
+
}
|
|
121
|
+
this.emit({
|
|
122
|
+
type: "remove",
|
|
123
|
+
field: e,
|
|
124
|
+
value: t,
|
|
125
|
+
removedItem: i,
|
|
126
|
+
removedIndex: n,
|
|
127
|
+
movedItem: a,
|
|
128
|
+
movedFromIndex: a ? r : null
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
removeByFieldValues(e, t) {
|
|
132
|
+
if (t.length === 0) return;
|
|
133
|
+
let n = this.getOrCreateIndexMap(e), r = [];
|
|
134
|
+
for (let e = 0; e < t.length; e++) {
|
|
135
|
+
let i = t[e], a = n.get(i);
|
|
136
|
+
if (a === void 0) continue;
|
|
137
|
+
let o = this.originData.length - 1, s = this.originData[a], c = a === o ? null : this.originData[o];
|
|
138
|
+
a !== o && c && (this.originData[a] = c, this.itemIndexLookup.set(c, a)), this.originData.pop(), this.itemIndexLookup.delete(s);
|
|
139
|
+
for (let [e, t] of this.indexMaps) {
|
|
140
|
+
let n = s[e];
|
|
141
|
+
t.get(n) === a && t.delete(n), c && t.set(c[e], a);
|
|
142
|
+
}
|
|
143
|
+
r.push({
|
|
144
|
+
value: i,
|
|
145
|
+
removedItem: s,
|
|
146
|
+
removedIndex: a,
|
|
147
|
+
movedItem: c,
|
|
148
|
+
movedFromIndex: c ? o : null
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
r.length !== 0 && (this.bumpMutationVersion(), this.emit({
|
|
152
|
+
type: "removeMany",
|
|
153
|
+
field: e,
|
|
154
|
+
entries: r
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
emit(e) {
|
|
158
|
+
for (let t of this.listeners) t(e);
|
|
159
|
+
}
|
|
160
|
+
getOrCreateScope(e) {
|
|
161
|
+
let t = this.scopedRegistry.get(e);
|
|
162
|
+
if (t) return t;
|
|
163
|
+
let n = /* @__PURE__ */ new Map();
|
|
164
|
+
return this.scopedRegistry.set(e, n), n;
|
|
165
|
+
}
|
|
166
|
+
bumpMutationVersion() {
|
|
167
|
+
this.mutationVersion += 1, this.clearPreviousResult();
|
|
168
|
+
}
|
|
169
|
+
getOrCreateIndexMap(e) {
|
|
170
|
+
return this.indexMaps.get(e) || this.rebuildIndexMap(e);
|
|
171
|
+
}
|
|
172
|
+
rebuildIndexMap(e) {
|
|
173
|
+
let t = /* @__PURE__ */ new Map();
|
|
174
|
+
for (let n = 0; n < this.originData.length; n++) t.set(this.originData[n][e], n);
|
|
175
|
+
return this.indexMaps.set(e, t), t;
|
|
176
|
+
}
|
|
177
|
+
rebuildItemIndexLookup() {
|
|
178
|
+
this.itemIndexLookup = /* @__PURE__ */ new WeakMap();
|
|
179
|
+
for (let e = 0; e < this.originData.length; e++) this.itemIndexLookup.set(this.originData[e], e);
|
|
180
|
+
}
|
|
181
|
+
}, t = "__merge__", n = "deferFilterMutationIndexUpdates", r = "deferSearchMutationIndexUpdates", i = "deferSortMutationCacheUpdates";
|
|
182
|
+
//#endregion
|
|
183
|
+
export { e as a, t as i, r as n, i as r, n as t };
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./chunk-BJZg_1dI.mjs";
|
|
2
|
+
import { t as a } from "./chunk-C5Zpu_ol.mjs";
|
|
3
|
+
//#region src/merge/chain.ts
|
|
4
|
+
var o = class {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.callbacks = e;
|
|
7
|
+
}
|
|
8
|
+
create(e) {
|
|
9
|
+
let t = e;
|
|
10
|
+
return Object.defineProperties(t, {
|
|
11
|
+
search: a((e, t) => t === void 0 ? this.callbacks.search(e) : this.callbacks.search(e, t)),
|
|
12
|
+
sort: a((t, n, r) => n === void 0 ? this.callbacks.sort(e, t, r) : this.callbacks.sort(t, n, r)),
|
|
13
|
+
filter: a((t, n) => n === void 0 ? this.callbacks.filter(e, t) : this.callbacks.filter(t, n)),
|
|
14
|
+
add: a((e) => this.callbacks.add(e)),
|
|
15
|
+
update: a((e) => this.callbacks.update(e)),
|
|
16
|
+
clearIndexes: a((t) => (this.callbacks.clearIndexes(t), this.create(e))),
|
|
17
|
+
clearData: a((t) => (this.callbacks.clearData(t), this.create(e))),
|
|
18
|
+
data: a((e) => this.callbacks.data(e)),
|
|
19
|
+
getOriginData: a(() => this.callbacks.getOriginData())
|
|
20
|
+
}), t;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/merge/module-adapters.ts
|
|
25
|
+
function s(e) {
|
|
26
|
+
return typeof e == "object" && !!e;
|
|
27
|
+
}
|
|
28
|
+
function c(e, t) {
|
|
29
|
+
return s(e) && typeof e[t] == "function";
|
|
30
|
+
}
|
|
31
|
+
function l(e) {
|
|
32
|
+
return c(e, "search") && c(e, "getOriginData");
|
|
33
|
+
}
|
|
34
|
+
function u(e) {
|
|
35
|
+
return c(e, "sort") && c(e, "getOriginData");
|
|
36
|
+
}
|
|
37
|
+
function d(e) {
|
|
38
|
+
return c(e, "rawFilter") && c(e, "getOriginData");
|
|
39
|
+
}
|
|
40
|
+
var f = (e) => {
|
|
41
|
+
let { prototype: t } = e;
|
|
42
|
+
return d(t) ? "filter" : u(t) ? "sort" : l(t) ? "search" : null;
|
|
43
|
+
}, p = (e, t, n, r) => {
|
|
44
|
+
let i = new e({
|
|
45
|
+
data: t,
|
|
46
|
+
state: n,
|
|
47
|
+
...r
|
|
48
|
+
});
|
|
49
|
+
return d(i) ? {
|
|
50
|
+
moduleName: "filter",
|
|
51
|
+
executeFilter: (e, t) => t === void 0 ? i.rawFilter(e) : i.rawFilter(e, t),
|
|
52
|
+
clearIndexes: () => i.clearIndexes()
|
|
53
|
+
} : u(i) ? {
|
|
54
|
+
moduleName: "sort",
|
|
55
|
+
executeSort: (e, t, n) => t === void 0 ? i.sort(e) : i.sort(e, t, n),
|
|
56
|
+
clearIndexes: () => i.clearIndexes()
|
|
57
|
+
} : l(i) ? {
|
|
58
|
+
moduleName: "search",
|
|
59
|
+
executeSearch: (e, t) => t === void 0 ? i.search(e) : i.search(e, t),
|
|
60
|
+
clearIndexes: () => i.clearIndexes()
|
|
61
|
+
} : null;
|
|
62
|
+
}, m = {
|
|
63
|
+
search: "TextSearchEngine",
|
|
64
|
+
sort: "SortEngine",
|
|
65
|
+
filter: "FilterEngine"
|
|
66
|
+
}, h = class e extends Error {
|
|
67
|
+
constructor(e) {
|
|
68
|
+
super(e), this.name = "MergeEnginesError";
|
|
69
|
+
}
|
|
70
|
+
static unavailableEngine(t) {
|
|
71
|
+
let n = m[t];
|
|
72
|
+
return new e(`MergeEngines: ${n} is not available.`);
|
|
73
|
+
}
|
|
74
|
+
static unavailableGetOriginData() {
|
|
75
|
+
return new e("MergeEngines: getOriginData is not available.");
|
|
76
|
+
}
|
|
77
|
+
static invalidFilterByPreviousResultOption() {
|
|
78
|
+
return new e("MergeEngines: \"filter.filterByPreviousResult\" is not supported. Configure \"filterByPreviousResult\" on the MergeEngines root options.");
|
|
79
|
+
}
|
|
80
|
+
}, g = class {
|
|
81
|
+
constructor(a) {
|
|
82
|
+
this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
|
|
83
|
+
let { imports: s, data: c, filterByPreviousResult: l = !1, ...u } = a;
|
|
84
|
+
this.validateFilterByPreviousResultOptions(u.filter), this.state = new e(c, { filterByPreviousResult: l });
|
|
85
|
+
let d = new Set(s), m = null, h = null, g = null;
|
|
86
|
+
for (let e of d) {
|
|
87
|
+
let t = f(e);
|
|
88
|
+
if (!t) continue;
|
|
89
|
+
let n = this.getModuleInitOptions(t, e.name, u), r = p(e, c, this.state, n);
|
|
90
|
+
r && (r.moduleName === "search" && !m && (m = r), r.moduleName === "sort" && !h && (h = r), r.moduleName === "filter" && !g && (g = r));
|
|
91
|
+
}
|
|
92
|
+
this.searchModule = m, this.sortModule = h, this.filterModule = g, this.sortModule && this.state.setScopedValue(t, r, !0), this.searchModule && this.state.setScopedValue(t, n, !0), this.filterModule && this.state.setScopedValue(t, i, !0), this.state.subscribe((e) => this.handleStateMutation(e)), this.chainBuilder = new o({
|
|
93
|
+
search: (e, t) => t === void 0 ? this.search(e) : this.search(e, t),
|
|
94
|
+
sort: (e, t, n) => this.sort(e, t, n),
|
|
95
|
+
filter: (e, t) => this.filter(e, t),
|
|
96
|
+
getOriginData: () => this.getOriginData(),
|
|
97
|
+
add: (e) => this.add(e),
|
|
98
|
+
update: (e) => this.update(e),
|
|
99
|
+
data: (e) => this.data(e),
|
|
100
|
+
clearIndexes: (e) => this.clearIndexes(e),
|
|
101
|
+
clearData: (e) => this.clearData(e)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
getAdapter(e) {
|
|
105
|
+
return e === "search" ? this.searchModule : e === "sort" ? this.sortModule : this.filterModule;
|
|
106
|
+
}
|
|
107
|
+
getModuleInitOptions(e, t, n) {
|
|
108
|
+
let r = {};
|
|
109
|
+
for (let i of [e, t]) {
|
|
110
|
+
let e = n[i];
|
|
111
|
+
s(e) && Object.assign(r, e);
|
|
112
|
+
}
|
|
113
|
+
return r;
|
|
114
|
+
}
|
|
115
|
+
validateFilterByPreviousResultOptions(e) {
|
|
116
|
+
if (s(e) && Object.prototype.hasOwnProperty.call(e, "filterByPreviousResult")) throw h.invalidFilterByPreviousResultOption();
|
|
117
|
+
}
|
|
118
|
+
isPreviousResultEnabled() {
|
|
119
|
+
return this.state.isFilterByPreviousResultEnabled();
|
|
120
|
+
}
|
|
121
|
+
getPreviousResultInput() {
|
|
122
|
+
return this.isPreviousResultEnabled() ? this.state.getPreviousResult() : null;
|
|
123
|
+
}
|
|
124
|
+
trackPreviousResult(e, t) {
|
|
125
|
+
return this.isPreviousResultEnabled() && this.state.setPreviousResult(e, t), e;
|
|
126
|
+
}
|
|
127
|
+
clearOperationState(e) {
|
|
128
|
+
(!e || e === "search") && (this.previousSearchState = null), (!e || e === "filter") && (this.previousFilterState = null), (!e || e === "sort") && (this.previousSortState = null);
|
|
129
|
+
}
|
|
130
|
+
createSearchCacheKey(e, t) {
|
|
131
|
+
return JSON.stringify([e, t ?? null]);
|
|
132
|
+
}
|
|
133
|
+
createSortCacheKey(e, t) {
|
|
134
|
+
return JSON.stringify({
|
|
135
|
+
descriptors: e,
|
|
136
|
+
inPlace: t ?? !1
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
createFilterCacheKey(e) {
|
|
140
|
+
return JSON.stringify(e);
|
|
141
|
+
}
|
|
142
|
+
handleStateMutation(e) {
|
|
143
|
+
switch (e.type) {
|
|
144
|
+
case "add":
|
|
145
|
+
this.queueSearchCacheMutation(e), this.queueFilterCacheMutation(e), this.queueSortCacheMutation(e);
|
|
146
|
+
return;
|
|
147
|
+
case "update":
|
|
148
|
+
this.queueSearchCacheMutation(e), this.queueFilterCacheMutation(e), this.queueSortCacheMutation(e);
|
|
149
|
+
return;
|
|
150
|
+
case "remove":
|
|
151
|
+
this.previousSearchState = null, this.previousFilterState = null, this.queueSortCacheMutation(e);
|
|
152
|
+
return;
|
|
153
|
+
case "removeMany":
|
|
154
|
+
this.previousSearchState = null, this.previousFilterState = null, this.queueSortCacheMutation(e);
|
|
155
|
+
return;
|
|
156
|
+
case "data":
|
|
157
|
+
case "clearData":
|
|
158
|
+
this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
queueSearchCacheMutation(e) {
|
|
163
|
+
let t = this.previousSearchState;
|
|
164
|
+
if (t !== null) {
|
|
165
|
+
if (!this.canPatchStoredDatasetSearch(t)) {
|
|
166
|
+
this.previousSearchState = null;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.previousSearchState = {
|
|
170
|
+
...t,
|
|
171
|
+
version: this.state.getMutationVersion(),
|
|
172
|
+
pendingMutations: t.pendingMutations.concat(e)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
queueFilterCacheMutation(e) {
|
|
177
|
+
let t = this.previousFilterState;
|
|
178
|
+
if (t !== null) {
|
|
179
|
+
if (!this.canPatchStoredDatasetFilter(t)) {
|
|
180
|
+
this.previousFilterState = null;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.previousFilterState = {
|
|
184
|
+
...t,
|
|
185
|
+
version: this.state.getMutationVersion(),
|
|
186
|
+
pendingMutations: t.pendingMutations.concat(e)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
queueSortCacheMutation(e) {
|
|
191
|
+
let t = this.previousSortState;
|
|
192
|
+
if (t !== null) {
|
|
193
|
+
if (!this.canPatchStoredDatasetSort(t)) {
|
|
194
|
+
this.previousSortState = null;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.previousSortState = {
|
|
198
|
+
...t,
|
|
199
|
+
version: this.state.getMutationVersion(),
|
|
200
|
+
pendingMutations: t.pendingMutations.concat(e)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
resolvePendingSortCache(e) {
|
|
205
|
+
if (e.pendingMutations.length === 0) return e;
|
|
206
|
+
let t = {
|
|
207
|
+
...e,
|
|
208
|
+
pendingMutations: []
|
|
209
|
+
};
|
|
210
|
+
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applySortCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
211
|
+
return t;
|
|
212
|
+
}
|
|
213
|
+
resolvePendingSearchCache(e) {
|
|
214
|
+
if (e.pendingMutations.length === 0) return e;
|
|
215
|
+
let t = {
|
|
216
|
+
...e,
|
|
217
|
+
pendingMutations: []
|
|
218
|
+
};
|
|
219
|
+
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applySearchCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
220
|
+
return t;
|
|
221
|
+
}
|
|
222
|
+
resolvePendingFilterCache(e) {
|
|
223
|
+
if (e.pendingMutations.length === 0) return e;
|
|
224
|
+
let t = {
|
|
225
|
+
...e,
|
|
226
|
+
pendingMutations: []
|
|
227
|
+
};
|
|
228
|
+
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applyFilterCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
229
|
+
return t;
|
|
230
|
+
}
|
|
231
|
+
applySortCacheMutation(e, t) {
|
|
232
|
+
switch (t.type) {
|
|
233
|
+
case "add": return this.patchSortCacheForAddedItems(e, t.items);
|
|
234
|
+
case "update": return this.patchSortCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
235
|
+
case "remove": return this.patchSortCacheForRemovedItems(e, [t.removedItem]);
|
|
236
|
+
case "removeMany": return this.patchSortCacheForRemovedItems(e, t.entries.map((e) => e.removedItem));
|
|
237
|
+
case "data":
|
|
238
|
+
case "clearData": return null;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
applySearchCacheMutation(e, t) {
|
|
242
|
+
switch (t.type) {
|
|
243
|
+
case "add": return this.patchSearchCacheForAddedItems(e, t.items);
|
|
244
|
+
case "update": return this.patchSearchCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
245
|
+
case "remove":
|
|
246
|
+
case "removeMany":
|
|
247
|
+
case "data":
|
|
248
|
+
case "clearData": return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
applyFilterCacheMutation(e, t) {
|
|
252
|
+
switch (t.type) {
|
|
253
|
+
case "add": return this.patchFilterCacheForAddedItems(e, t.items);
|
|
254
|
+
case "update": return this.patchFilterCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
255
|
+
case "remove":
|
|
256
|
+
case "removeMany":
|
|
257
|
+
case "data":
|
|
258
|
+
case "clearData": return null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
canPatchStoredDatasetSearch(e) {
|
|
262
|
+
return e.originData === this.state.getOriginData() && e.field !== null;
|
|
263
|
+
}
|
|
264
|
+
canPatchStoredDatasetFilter(e) {
|
|
265
|
+
if (e.sourceData !== this.state.getOriginData()) return !1;
|
|
266
|
+
for (let t = 0; t < e.criteria.length; t++) if (!this.isPatchableFilterCriterion(e.criteria[t])) return !1;
|
|
267
|
+
return !0;
|
|
268
|
+
}
|
|
269
|
+
canPatchStoredDatasetSort(e) {
|
|
270
|
+
return e.sourceData === this.state.getOriginData();
|
|
271
|
+
}
|
|
272
|
+
compareItemsByDescriptors(e, t, n) {
|
|
273
|
+
for (let r = 0; r < n.length; r++) {
|
|
274
|
+
let { field: i, direction: a } = n[r], o = e[i], s = t[i];
|
|
275
|
+
if (o < s) return a === "asc" ? -1 : 1;
|
|
276
|
+
if (o > s) return a === "asc" ? 1 : -1;
|
|
277
|
+
}
|
|
278
|
+
return (this.state.getItemIndex(e) ?? -1) - (this.state.getItemIndex(t) ?? -1);
|
|
279
|
+
}
|
|
280
|
+
findSortInsertPosition(e, t, n) {
|
|
281
|
+
let r = 0, i = e.length;
|
|
282
|
+
for (; r < i;) {
|
|
283
|
+
let a = r + i >> 1;
|
|
284
|
+
this.compareItemsByDescriptors(e[a], t, n) <= 0 ? r = a + 1 : i = a;
|
|
285
|
+
}
|
|
286
|
+
return r;
|
|
287
|
+
}
|
|
288
|
+
findDatasetInsertPosition(e, t) {
|
|
289
|
+
let n = this.state.getItemIndex(t) ?? 2 ** 53 - 1;
|
|
290
|
+
for (let t = 0; t < e.length; t++) if ((this.state.getItemIndex(e[t]) ?? 2 ** 53 - 1) > n) return t;
|
|
291
|
+
return e.length;
|
|
292
|
+
}
|
|
293
|
+
doesItemMatchSearchCache(e, t) {
|
|
294
|
+
if (e.field === null || e.lowerQuery.length === 0) return !1;
|
|
295
|
+
let n = t[e.field];
|
|
296
|
+
return typeof n == "string" && n.toLowerCase().includes(e.lowerQuery);
|
|
297
|
+
}
|
|
298
|
+
patchSearchCacheForAddedItems(e, t) {
|
|
299
|
+
if (!this.canPatchStoredDatasetSearch(e)) return null;
|
|
300
|
+
let n = e.result.slice();
|
|
301
|
+
for (let r = 0; r < t.length; r++) {
|
|
302
|
+
let i = t[r];
|
|
303
|
+
this.doesItemMatchSearchCache(e, i) && n.push(i);
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
...e,
|
|
307
|
+
result: n,
|
|
308
|
+
pendingMutations: [],
|
|
309
|
+
version: this.state.getMutationVersion()
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
patchSearchCacheForUpdatedItem(e, t, n) {
|
|
313
|
+
if (!this.canPatchStoredDatasetSearch(e)) return null;
|
|
314
|
+
let r = e.result.slice(), i = r.indexOf(t), a = this.doesItemMatchSearchCache(e, n);
|
|
315
|
+
if (i !== -1) a ? r[i] = n : r.splice(i, 1);
|
|
316
|
+
else if (a) {
|
|
317
|
+
let e = this.findDatasetInsertPosition(r, n);
|
|
318
|
+
r.splice(e, 0, n);
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
...e,
|
|
322
|
+
result: r,
|
|
323
|
+
pendingMutations: [],
|
|
324
|
+
version: this.state.getMutationVersion()
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
isPatchableFilterCriterion(e) {
|
|
328
|
+
return !String(e.field).includes(".");
|
|
329
|
+
}
|
|
330
|
+
doesItemMatchFilterCache(e, t) {
|
|
331
|
+
for (let n = 0; n < e.criteria.length; n++) {
|
|
332
|
+
let r = e.criteria[n];
|
|
333
|
+
if (!this.isPatchableFilterCriterion(r)) return !1;
|
|
334
|
+
let i = t[r.field];
|
|
335
|
+
if (r.values !== void 0 && r.values.length > 0 && !r.values.includes(i) || r.exclude !== void 0 && r.exclude.length > 0 && r.exclude.includes(i)) return !1;
|
|
336
|
+
}
|
|
337
|
+
return !0;
|
|
338
|
+
}
|
|
339
|
+
patchFilterCacheForAddedItems(e, t) {
|
|
340
|
+
if (!this.canPatchStoredDatasetFilter(e)) return null;
|
|
341
|
+
let n = e.result.slice();
|
|
342
|
+
for (let r = 0; r < t.length; r++) {
|
|
343
|
+
let i = t[r];
|
|
344
|
+
this.doesItemMatchFilterCache(e, i) && n.push(i);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
...e,
|
|
348
|
+
result: n,
|
|
349
|
+
pendingMutations: [],
|
|
350
|
+
version: this.state.getMutationVersion()
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
patchFilterCacheForUpdatedItem(e, t, n) {
|
|
354
|
+
if (!this.canPatchStoredDatasetFilter(e)) return null;
|
|
355
|
+
let r = e.result.slice(), i = r.indexOf(t), a = this.doesItemMatchFilterCache(e, n);
|
|
356
|
+
if (i !== -1) a ? r[i] = n : r.splice(i, 1);
|
|
357
|
+
else if (a) {
|
|
358
|
+
let e = this.findDatasetInsertPosition(r, n);
|
|
359
|
+
r.splice(e, 0, n);
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
...e,
|
|
363
|
+
result: r,
|
|
364
|
+
pendingMutations: [],
|
|
365
|
+
version: this.state.getMutationVersion()
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
patchSortCacheForAddedItems(e, t) {
|
|
369
|
+
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
370
|
+
let n = e.result.slice();
|
|
371
|
+
for (let r = 0; r < t.length; r++) {
|
|
372
|
+
let i = t[r], a = this.findSortInsertPosition(n, i, e.descriptors);
|
|
373
|
+
n.splice(a, 0, i);
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
...e,
|
|
377
|
+
result: n,
|
|
378
|
+
pendingMutations: [],
|
|
379
|
+
version: this.state.getMutationVersion()
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
patchSortCacheForUpdatedItem(e, t, n) {
|
|
383
|
+
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
384
|
+
let r = e.result.slice(), i = r.indexOf(t);
|
|
385
|
+
if (i === -1) return e.result.indexOf(n) === -1 ? null : {
|
|
386
|
+
...e,
|
|
387
|
+
pendingMutations: [],
|
|
388
|
+
version: this.state.getMutationVersion()
|
|
389
|
+
};
|
|
390
|
+
if (!e.descriptors.some(({ field: e }) => t[e] !== n[e])) return r[i] = n, {
|
|
391
|
+
...e,
|
|
392
|
+
result: r,
|
|
393
|
+
pendingMutations: [],
|
|
394
|
+
version: this.state.getMutationVersion()
|
|
395
|
+
};
|
|
396
|
+
r.splice(i, 1);
|
|
397
|
+
let a = this.findSortInsertPosition(r, n, e.descriptors);
|
|
398
|
+
return r.splice(a, 0, n), {
|
|
399
|
+
...e,
|
|
400
|
+
result: r,
|
|
401
|
+
pendingMutations: [],
|
|
402
|
+
version: this.state.getMutationVersion()
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
patchSortCacheForRemovedItems(e, t) {
|
|
406
|
+
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
407
|
+
let n = new Set(t);
|
|
408
|
+
return {
|
|
409
|
+
...e,
|
|
410
|
+
result: Array.prototype.filter.call(e.result, (e) => !n.has(e)),
|
|
411
|
+
pendingMutations: [],
|
|
412
|
+
version: this.state.getMutationVersion()
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
search(e, t) {
|
|
416
|
+
if (!this.searchModule) throw h.unavailableEngine("search");
|
|
417
|
+
let n = this.state.getOriginData(), r = this.state.getMutationVersion(), i = this.createSearchCacheKey(e, t), a = this.previousSearchState;
|
|
418
|
+
if (a?.originData === n && a.key === i && a.version === r) {
|
|
419
|
+
let e = this.resolvePendingSearchCache(a);
|
|
420
|
+
if (e !== null) return this.previousSearchState = e, this.withChain(this.trackPreviousResult(e.result, n));
|
|
421
|
+
this.previousSearchState = null;
|
|
422
|
+
}
|
|
423
|
+
let o = t === void 0 ? this.searchModule.executeSearch(e) : this.searchModule.executeSearch(e, t);
|
|
424
|
+
return this.previousSearchState = {
|
|
425
|
+
key: i,
|
|
426
|
+
originData: n,
|
|
427
|
+
result: o,
|
|
428
|
+
version: r,
|
|
429
|
+
field: t === void 0 ? null : e,
|
|
430
|
+
lowerQuery: (t ?? e).trim().toLowerCase(),
|
|
431
|
+
pendingMutations: []
|
|
432
|
+
}, this.withChain(this.trackPreviousResult(o, n));
|
|
433
|
+
}
|
|
434
|
+
sort(e, t, n) {
|
|
435
|
+
if (!this.sortModule) throw h.unavailableEngine("sort");
|
|
436
|
+
let r, i;
|
|
437
|
+
if (t === void 0 ? (i = e, r = this.getPreviousResultInput() ?? this.state.getOriginData()) : (r = e, i = t), !n) {
|
|
438
|
+
let e = this.state.getMutationVersion(), a = this.createSortCacheKey(i, n), o = this.previousSortState;
|
|
439
|
+
if (o?.sourceData === r && o.key === a && o.version === e) {
|
|
440
|
+
let e = this.resolvePendingSortCache(o);
|
|
441
|
+
if (e !== null) return this.previousSortState = e, this.withChain(this.trackPreviousResult(e.result, r));
|
|
442
|
+
this.previousSortState = null;
|
|
443
|
+
}
|
|
444
|
+
let s = t === void 0 && r === this.state.getOriginData() ? this.sortModule.executeSort(i) : this.sortModule.executeSort(r, i, n);
|
|
445
|
+
return this.previousSortState = {
|
|
446
|
+
key: a,
|
|
447
|
+
sourceData: r,
|
|
448
|
+
result: s,
|
|
449
|
+
version: e,
|
|
450
|
+
descriptors: i,
|
|
451
|
+
pendingMutations: []
|
|
452
|
+
}, this.withChain(this.trackPreviousResult(s, r));
|
|
453
|
+
}
|
|
454
|
+
return this.withChain(this.trackPreviousResult(this.sortModule.executeSort(r, i, n), r));
|
|
455
|
+
}
|
|
456
|
+
filter(e, t) {
|
|
457
|
+
if (!this.filterModule) throw h.unavailableEngine("filter");
|
|
458
|
+
if (t === void 0) {
|
|
459
|
+
let t = this.getPreviousResultInput(), n = t ?? this.state.getOriginData(), r = e, i = this.state.getMutationVersion(), a = this.createFilterCacheKey(r), o = this.previousFilterState;
|
|
460
|
+
if (o?.sourceData === n && o.key === a && o.version === i) {
|
|
461
|
+
let e = this.resolvePendingFilterCache(o);
|
|
462
|
+
if (e !== null) return this.previousFilterState = e, this.withChain(this.trackPreviousResult(e.result, n));
|
|
463
|
+
this.previousFilterState = null;
|
|
464
|
+
}
|
|
465
|
+
let s = t === null ? this.filterModule.executeFilter(r) : this.filterModule.executeFilter(t, r);
|
|
466
|
+
return this.previousFilterState = {
|
|
467
|
+
key: a,
|
|
468
|
+
sourceData: n,
|
|
469
|
+
result: s,
|
|
470
|
+
version: i,
|
|
471
|
+
criteria: r,
|
|
472
|
+
pendingMutations: []
|
|
473
|
+
}, this.withChain(this.trackPreviousResult(s, n));
|
|
474
|
+
}
|
|
475
|
+
let n = e;
|
|
476
|
+
return this.withChain(this.trackPreviousResult(this.filterModule.executeFilter(n, t), n));
|
|
477
|
+
}
|
|
478
|
+
withChain(e) {
|
|
479
|
+
return this.chainBuilder.create(e);
|
|
480
|
+
}
|
|
481
|
+
getOriginData() {
|
|
482
|
+
if (this.searchModule || this.sortModule || this.filterModule) return this.state.getOriginData();
|
|
483
|
+
throw h.unavailableGetOriginData();
|
|
484
|
+
}
|
|
485
|
+
add(e) {
|
|
486
|
+
return e.length === 0 || this.state.add(e), this;
|
|
487
|
+
}
|
|
488
|
+
update(e) {
|
|
489
|
+
return this.state.update(e), this;
|
|
490
|
+
}
|
|
491
|
+
clearIndexes(e) {
|
|
492
|
+
let t = this.getAdapter(e);
|
|
493
|
+
if (t) return t.clearIndexes(), this.clearOperationState(e), this;
|
|
494
|
+
throw h.unavailableEngine(e);
|
|
495
|
+
}
|
|
496
|
+
data(e) {
|
|
497
|
+
return this.state.data(e), this;
|
|
498
|
+
}
|
|
499
|
+
clearData(e) {
|
|
500
|
+
if (this.getAdapter(e)) return this.state.clearData(), this;
|
|
501
|
+
throw h.unavailableEngine(e);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
//#endregion
|
|
505
|
+
export { g as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/internal.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return {
|
|
4
|
+
value: e,
|
|
5
|
+
enumerable: !1,
|
|
6
|
+
configurable: !0,
|
|
7
|
+
writable: !0
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function t(e) {
|
|
11
|
+
let t = e.indexOf(".");
|
|
12
|
+
return t === -1 ? null : {
|
|
13
|
+
collectionKey: e.substring(0, t),
|
|
14
|
+
nestedKey: e.substring(t + 1)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { t as n, e as t };
|