@wovin/core 0.0.1-RC5 → 0.0.1-RC6
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/applog.d.ts +70 -0
- package/dist/applog.js +85 -0
- package/dist/applog.js.map +1 -0
- package/dist/chunk-F3FYYIAV.js +11 -0
- package/dist/chunk-F3FYYIAV.js.map +1 -0
- package/dist/chunk-HWWMVYRI.js +56 -0
- package/dist/chunk-HWWMVYRI.js.map +1 -0
- package/dist/chunk-TYTIT5QO.js +768 -0
- package/dist/chunk-TYTIT5QO.js.map +1 -0
- package/dist/chunk-W5MZGTNK.js +577 -0
- package/dist/chunk-W5MZGTNK.js.map +1 -0
- package/dist/chunk-ZWEMUC65.js +59 -0
- package/dist/chunk-ZWEMUC65.js.map +1 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +76 -14438
- package/dist/index.js.map +1 -0
- package/dist/ipfs.d.ts +36 -0
- package/dist/ipfs.js +28 -0
- package/dist/ipfs.js.map +1 -0
- package/dist/{stream/mapped.d.ts → mapped-X-JaKwfX.d.ts} +7 -5
- package/dist/pubsub.d.ts +41 -0
- package/dist/pubsub.js +14 -0
- package/dist/pubsub.js.map +1 -0
- package/dist/queries.d.ts +141 -0
- package/dist/queries.js +112 -0
- package/dist/queries.js.map +1 -0
- package/dist/stream.d.ts +44 -0
- package/dist/stream.js +37 -0
- package/dist/stream.js.map +1 -0
- package/dist/types-B8KPeyK1.d.ts +153 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +46 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/dist/{stream/writeable.d.ts → writeable-rCfOnOTa.d.ts} +7 -5
- package/package.json +35 -19
- package/dist/data/applog-helpers.d.ts +0 -24
- package/dist/data/applog-helpers.d.ts.map +0 -1
- package/dist/data/applog-utils.d.ts +0 -42
- package/dist/data/applog-utils.d.ts.map +0 -1
- package/dist/data/datom-types.d.ts +0 -84
- package/dist/data/datom-types.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/ipfs/ipfs-utils.d.ts +0 -17
- package/dist/ipfs/ipfs-utils.d.ts.map +0 -1
- package/dist/mobx/mobx-utils.d.ts +0 -67
- package/dist/mobx/mobx-utils.d.ts.map +0 -1
- package/dist/queries/divergences.d.ts +0 -12
- package/dist/queries/divergences.d.ts.map +0 -1
- package/dist/queries/matchers.d.ts +0 -4
- package/dist/queries/matchers.d.ts.map +0 -1
- package/dist/queries/queries.d.ts +0 -58
- package/dist/queries/queries.d.ts.map +0 -1
- package/dist/stream/filters.d.ts +0 -38
- package/dist/stream/filters.d.ts.map +0 -1
- package/dist/stream/mapped.d.ts.map +0 -1
- package/dist/stream/writeable.d.ts.map +0 -1
- package/dist/types/typescript-utils.d.ts +0 -27
- package/dist/types/typescript-utils.d.ts.map +0 -1
- package/src/index.ts +0 -6
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-F3FYYIAV.js";
|
|
4
|
+
|
|
5
|
+
// src/data/applog-utils.ts
|
|
6
|
+
import { Logger } from "besonders-logger/src";
|
|
7
|
+
import { isBefore } from "date-fns";
|
|
8
|
+
import { comparer } from "mobx";
|
|
9
|
+
import stringify from "safe-stable-stringify";
|
|
10
|
+
var { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.DEBUG);
|
|
11
|
+
var isoDateStrCompare = (strA, strB, dir = "asc") => dir === "asc" ? strA.localeCompare(strB, "en-US") : strB.localeCompare(strA, "en-US");
|
|
12
|
+
function sortApplogsByTs(appLogArray, dir = "asc") {
|
|
13
|
+
return appLogArray.sort((a, b) => isoDateStrCompare(a.ts, b.ts, dir));
|
|
14
|
+
}
|
|
15
|
+
var isTsBefore = (log, logToCompare) => isBefore(new Date(log.ts), new Date(logToCompare.ts));
|
|
16
|
+
var uniqueEnFromAppLogs = (appLogArray) => [...new Set(appLogArray.map((eachLog) => eachLog.en))];
|
|
17
|
+
var areApplogsEqual = (logA, logB) => comparer.structural(logA, logB);
|
|
18
|
+
var removeDuplicateAppLogs = (appLogArray) => {
|
|
19
|
+
const logMap = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const eachLog of appLogArray) {
|
|
21
|
+
if (!eachLog) {
|
|
22
|
+
ERROR(`falsy entry in applogs`, appLogArray);
|
|
23
|
+
throw new Error(`falsy entry in applogs`);
|
|
24
|
+
}
|
|
25
|
+
logMap.set(stringify(eachLog), eachLog);
|
|
26
|
+
}
|
|
27
|
+
return Array.from(logMap.values());
|
|
28
|
+
};
|
|
29
|
+
var getHashID = (stringifiable, lngth = 8) => cyrb53hash(stringify(stringifiable), 31, lngth);
|
|
30
|
+
function isVariable(x) {
|
|
31
|
+
return typeof x === "string" && x.startsWith("?");
|
|
32
|
+
}
|
|
33
|
+
function variableNameWithoutQuestionmark(str) {
|
|
34
|
+
return str.slice(1);
|
|
35
|
+
}
|
|
36
|
+
function isStaticPattern(x) {
|
|
37
|
+
if (!["string", "boolean", "number", "function"].includes(typeof x))
|
|
38
|
+
WARN(`Unhandled pattern value type:`, typeof x, x);
|
|
39
|
+
return !isVariable(x) && ["string", "boolean", "number"].includes(typeof x);
|
|
40
|
+
}
|
|
41
|
+
function resolveOrRemoveVariables(pattern, candidate) {
|
|
42
|
+
let variablesToFill = {};
|
|
43
|
+
const newPattern = Object.entries(pattern).reduce((acc, [patternKey, patternValue]) => {
|
|
44
|
+
if (isVariable(patternValue)) {
|
|
45
|
+
const varName = variableNameWithoutQuestionmark(patternValue);
|
|
46
|
+
const candidateValue = candidate[varName];
|
|
47
|
+
if (candidateValue) {
|
|
48
|
+
acc[patternKey] = candidateValue;
|
|
49
|
+
} else {
|
|
50
|
+
variablesToFill[patternKey] = varName;
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
acc[patternKey] = patternValue;
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
return [newPattern, variablesToFill];
|
|
58
|
+
}
|
|
59
|
+
function matchVariable(variable, triplePart, context) {
|
|
60
|
+
if (context.hasOwnProperty(variable)) {
|
|
61
|
+
const bound = context[variable];
|
|
62
|
+
const match = matchPart(bound, triplePart, context);
|
|
63
|
+
VERBOSE("[matchVariable] match?", variable, bound, match);
|
|
64
|
+
return match;
|
|
65
|
+
}
|
|
66
|
+
VERBOSE("[matchVariable] initializing variable", variable, "to", triplePart);
|
|
67
|
+
return { ...context, [variable]: triplePart };
|
|
68
|
+
}
|
|
69
|
+
function matchPartStatic(field, patternPart, atomPart) {
|
|
70
|
+
VERBOSE("[matchPartStatic]", field, patternPart, patternPart === atomPart ? "===" : "!==", atomPart);
|
|
71
|
+
const result = (() => {
|
|
72
|
+
if (typeof patternPart === "function") {
|
|
73
|
+
return patternPart(atomPart);
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(patternPart) && !Array.isArray(atomPart)) {
|
|
76
|
+
return patternPart.includes(atomPart);
|
|
77
|
+
}
|
|
78
|
+
return patternPart === atomPart;
|
|
79
|
+
})();
|
|
80
|
+
VERBOSE("[matchPartStatic] =>", field.startsWith("!") ? "!" : "", result);
|
|
81
|
+
if (field.startsWith("!")) {
|
|
82
|
+
return !result;
|
|
83
|
+
} else {
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function matchPart(patternPart, atomPart, context) {
|
|
88
|
+
if (!context) {
|
|
89
|
+
VERBOSE("[matchPart] no context");
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (typeof patternPart === "string") {
|
|
93
|
+
if (isVariable(patternPart)) {
|
|
94
|
+
return matchVariable(patternPart, atomPart, context);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
VERBOSE("[matchPart]", patternPart, patternPart === atomPart ? "===" : "!==", atomPart);
|
|
98
|
+
if (typeof patternPart === "function") {
|
|
99
|
+
return patternPart(atomPart) ? context : null;
|
|
100
|
+
}
|
|
101
|
+
return patternPart === atomPart ? context : null;
|
|
102
|
+
}
|
|
103
|
+
function matchPattern(pattern, applog, context) {
|
|
104
|
+
return Object.entries(pattern).reduce((context2, [field, patternValue]) => {
|
|
105
|
+
const applogValue = applog[field];
|
|
106
|
+
const patternValT = patternValue;
|
|
107
|
+
return matchPart(patternValT, applogValue, context2);
|
|
108
|
+
}, context);
|
|
109
|
+
}
|
|
110
|
+
function actualize(context, find) {
|
|
111
|
+
return Object.fromEntries(find.map((findField) => {
|
|
112
|
+
if (context === null) {
|
|
113
|
+
throw new Error(`actualize context is null ${find}`);
|
|
114
|
+
}
|
|
115
|
+
return [
|
|
116
|
+
isVariable(findField) ? findField.replace(/^\?/, "") : findField,
|
|
117
|
+
isVariable(findField) ? context[findField] : findField
|
|
118
|
+
];
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
var sum = function sum2(array) {
|
|
122
|
+
var num = 0;
|
|
123
|
+
for (var i = 0, l = array.length; i < l; i++)
|
|
124
|
+
num += array[i];
|
|
125
|
+
return num;
|
|
126
|
+
};
|
|
127
|
+
var mean = function mean2(array) {
|
|
128
|
+
return sum(array) / array.length;
|
|
129
|
+
};
|
|
130
|
+
var arrStats = {
|
|
131
|
+
max: function(array) {
|
|
132
|
+
return Math.max.apply(null, array);
|
|
133
|
+
},
|
|
134
|
+
min: function(array) {
|
|
135
|
+
return Math.min.apply(null, array);
|
|
136
|
+
},
|
|
137
|
+
range: function(array) {
|
|
138
|
+
return arrStats.max(array) - arrStats.min(array);
|
|
139
|
+
},
|
|
140
|
+
midrange: function(array) {
|
|
141
|
+
return arrStats.range(array) / 2;
|
|
142
|
+
},
|
|
143
|
+
sum,
|
|
144
|
+
mean,
|
|
145
|
+
average: mean,
|
|
146
|
+
median: function(array) {
|
|
147
|
+
array.sort(function(a, b) {
|
|
148
|
+
return a - b;
|
|
149
|
+
});
|
|
150
|
+
var mid = array.length / 2;
|
|
151
|
+
return mid % 1 ? array[mid - 0.5] : (array[mid - 1] + array[mid]) / 2;
|
|
152
|
+
},
|
|
153
|
+
modes: function(array) {
|
|
154
|
+
if (!array.length)
|
|
155
|
+
return [];
|
|
156
|
+
var modeMap = {}, maxCount = 0, modes = [];
|
|
157
|
+
array.forEach(function(val) {
|
|
158
|
+
if (!modeMap[val])
|
|
159
|
+
modeMap[val] = 1;
|
|
160
|
+
else
|
|
161
|
+
modeMap[val]++;
|
|
162
|
+
if (modeMap[val] > maxCount) {
|
|
163
|
+
modes = [val];
|
|
164
|
+
maxCount = modeMap[val];
|
|
165
|
+
} else if (modeMap[val] === maxCount) {
|
|
166
|
+
modes.push(val);
|
|
167
|
+
maxCount = modeMap[val];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
return modes;
|
|
171
|
+
},
|
|
172
|
+
variance: function(array) {
|
|
173
|
+
var mean3 = arrStats.mean(array);
|
|
174
|
+
return arrStats.mean(array.map(function(num) {
|
|
175
|
+
return Math.pow(num - mean3, 2);
|
|
176
|
+
}));
|
|
177
|
+
},
|
|
178
|
+
standardDeviation: function(array) {
|
|
179
|
+
return Math.sqrt(arrStats.variance(array));
|
|
180
|
+
},
|
|
181
|
+
meanAbsoluteDeviation: function(array) {
|
|
182
|
+
var mean3 = arrStats.mean(array);
|
|
183
|
+
return arrStats.mean(array.map(function(num) {
|
|
184
|
+
return Math.abs(num - mean3);
|
|
185
|
+
}));
|
|
186
|
+
},
|
|
187
|
+
zScores: function(array) {
|
|
188
|
+
var mean3 = arrStats.mean(array);
|
|
189
|
+
var standardDeviation = arrStats.standardDeviation(array);
|
|
190
|
+
return array.map(function(num) {
|
|
191
|
+
return (num - mean3) / standardDeviation;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
arrStats.average = arrStats.mean;
|
|
196
|
+
var tsNearlySame = (timeA, timeB) => timeB.startsWith(timeA.slice(0, timeA.length - 4));
|
|
197
|
+
var cyrb53hash = function(str, seed = 13, strLength) {
|
|
198
|
+
if (!str?.length) {
|
|
199
|
+
throw new Error(`Empty string: ${str}`);
|
|
200
|
+
}
|
|
201
|
+
let h1 = 3735928559 ^ seed;
|
|
202
|
+
let h2 = 1103547991 ^ seed;
|
|
203
|
+
for (let i = 0, ch; i < str.length; i++) {
|
|
204
|
+
ch = str.charCodeAt(i);
|
|
205
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
206
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
207
|
+
}
|
|
208
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
209
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
210
|
+
const asHex = (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);
|
|
211
|
+
return asHex.slice(-strLength).padStart(strLength, "0");
|
|
212
|
+
};
|
|
213
|
+
function arraysContainSameElements(arr1, arr2) {
|
|
214
|
+
if (arr1.length !== arr2.length) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
const sortedArr1 = [...arr1].sort();
|
|
218
|
+
const sortedArr2 = [...arr2].sort();
|
|
219
|
+
for (let i = 0; i < sortedArr1.length; i++) {
|
|
220
|
+
if (sortedArr1[i] !== sortedArr2[i]) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
function dateNowIso() {
|
|
227
|
+
const now = /* @__PURE__ */ new Date();
|
|
228
|
+
return now.toISOString();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/mobx/mobx-utils.ts
|
|
232
|
+
import { Logger as Logger2 } from "besonders-logger/src";
|
|
233
|
+
import {
|
|
234
|
+
_getGlobalState,
|
|
235
|
+
_isComputingDerivation,
|
|
236
|
+
comparer as comparer2,
|
|
237
|
+
computed,
|
|
238
|
+
configure,
|
|
239
|
+
getDependencyTree,
|
|
240
|
+
getObserverTree,
|
|
241
|
+
isAction,
|
|
242
|
+
observable,
|
|
243
|
+
onBecomeUnobserved,
|
|
244
|
+
Reaction,
|
|
245
|
+
runInAction,
|
|
246
|
+
spy,
|
|
247
|
+
trace,
|
|
248
|
+
untracked
|
|
249
|
+
} from "mobx";
|
|
250
|
+
import stringify2 from "safe-stable-stringify";
|
|
251
|
+
var { WARN: WARN2, LOG: LOG2, DEBUG: DEBUG2, VERBOSE: VERBOSE2, ERROR: ERROR2 } = Logger2.setup(Logger2.INFO);
|
|
252
|
+
configure({
|
|
253
|
+
enforceActions: "always"
|
|
254
|
+
// disableErrorBoundaries: true // (i) this can be useful in case of exceptions to see where they were caused - https://mobx.js.org/configuration.html#disableerrorboundaries-boolean
|
|
255
|
+
// computedRequiresReaction: true,
|
|
256
|
+
// reactionRequiresObservable: true,
|
|
257
|
+
// observableRequiresReaction: true,
|
|
258
|
+
});
|
|
259
|
+
if (!new class {
|
|
260
|
+
constructor() {
|
|
261
|
+
__publicField(this, "xyz");
|
|
262
|
+
}
|
|
263
|
+
}().hasOwnProperty("xyz"))
|
|
264
|
+
throw new Error("Transpiler is not configured correctly");
|
|
265
|
+
if (typeof window === "object") {
|
|
266
|
+
window.getDependencyTree = getDependencyTree;
|
|
267
|
+
window.getObserverTree = getObserverTree;
|
|
268
|
+
}
|
|
269
|
+
VERBOSE2.isDisabled || spy((event) => {
|
|
270
|
+
VERBOSE2(`[mobx]`, event);
|
|
271
|
+
});
|
|
272
|
+
var createDebugName = ({ caller, stream, pattern: args }) => {
|
|
273
|
+
const str = `${stream?.name ? stream.name + " | " : ""}${caller ?? "caller?"}${args ? `{${typeof args === "string" ? args : stringify2(args)}}` : ""}`;
|
|
274
|
+
return str;
|
|
275
|
+
};
|
|
276
|
+
var createDebugNameObj = (args) => {
|
|
277
|
+
return { name: createDebugName(args) };
|
|
278
|
+
};
|
|
279
|
+
function computedStructuralComparer(a, b) {
|
|
280
|
+
return untracked(() => comparer2.structural(a.get(), b.get()));
|
|
281
|
+
}
|
|
282
|
+
function applogStreamComparer(a, b) {
|
|
283
|
+
return comparer2.shallow(a.applogs, b.applogs);
|
|
284
|
+
}
|
|
285
|
+
function queryNodesComparer(a, b) {
|
|
286
|
+
if (a.size !== b.size)
|
|
287
|
+
return false;
|
|
288
|
+
for (let i = 0; i < a.size; i++) {
|
|
289
|
+
const nodeA = a.nodes[i];
|
|
290
|
+
const nodeB = b.nodes[i];
|
|
291
|
+
VERBOSE2(`queryNodesComparer`, i, nodeA, nodeB);
|
|
292
|
+
if (!comparer2.structural(nodeA.variables, nodeB.variables)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
if (!applogStreamComparer(nodeA.logsOfThisNode, nodeB.logsOfThisNode)) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
var observableArrayMapID = 0;
|
|
302
|
+
function observableArrayMap(fn, { name, equals } = {}) {
|
|
303
|
+
VERBOSE2(`[observableArrayMap] create`, { fnname: fn.name, fn, name, equals });
|
|
304
|
+
const debugName = `observableArrayMap@${++observableArrayMapID}{${name}}`;
|
|
305
|
+
let observableArr;
|
|
306
|
+
let items;
|
|
307
|
+
function runAndTrack() {
|
|
308
|
+
reaction2.track(() => {
|
|
309
|
+
DEBUG2(`[${debugName}] runAndTrack:`, { name: name ?? fn.name, fn });
|
|
310
|
+
items = fn();
|
|
311
|
+
VERBOSE2(`[${debugName}] runAndTrack =>`, items);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const reaction2 = new Reaction(debugName, (...args) => {
|
|
315
|
+
VERBOSE2(`[${debugName}] reaction.invalidate`, args);
|
|
316
|
+
runAndTrack();
|
|
317
|
+
runInAction(() => {
|
|
318
|
+
if (!(equals ?? comparer2.structural)(observableArr, items)) {
|
|
319
|
+
observableArr.replace(items);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
runAndTrack();
|
|
324
|
+
observableArr = observable.array(
|
|
325
|
+
items,
|
|
326
|
+
/* ['NEVER'] as T[] */
|
|
327
|
+
{ deep: false, name }
|
|
328
|
+
);
|
|
329
|
+
VERBOSE2(`[${debugName}] deps of reaction`, getDependencyTree(reaction2), "array:", getDependencyTree(observableArr), {
|
|
330
|
+
reaction: reaction2,
|
|
331
|
+
observableArr
|
|
332
|
+
});
|
|
333
|
+
const unobserveUnobserving = onBecomeUnobserved(observableArr, () => {
|
|
334
|
+
VERBOSE2(`[observableArrayMap] dispose`);
|
|
335
|
+
reaction2.dispose();
|
|
336
|
+
unobserveUnobserving();
|
|
337
|
+
});
|
|
338
|
+
return observableArr;
|
|
339
|
+
}
|
|
340
|
+
function computedFnDeepCompare(fn, keepAliveOrOptions = false) {
|
|
341
|
+
if (isAction(fn))
|
|
342
|
+
throw new Error("computedFnDeepCompare shouldn't be used on actions");
|
|
343
|
+
let memoWarned = false;
|
|
344
|
+
let i = 0;
|
|
345
|
+
const opts = typeof keepAliveOrOptions === "boolean" ? { keepAlive: keepAliveOrOptions } : keepAliveOrOptions;
|
|
346
|
+
const map = /* @__PURE__ */ new Map();
|
|
347
|
+
return function(...args) {
|
|
348
|
+
let existing;
|
|
349
|
+
const untrackedArgs = untracked(() => args);
|
|
350
|
+
const debugName = `computedFnDeepCompare(${opts.name || fn.name}#${++i})${opts.argsDebugName ? `{${opts.argsDebugName(...args)}}` : ""}`;
|
|
351
|
+
for (let [existingArgs, computation2] of map.entries()) {
|
|
352
|
+
if (comparer2.structural(existingArgs, untrackedArgs)) {
|
|
353
|
+
existing = computation2;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (existing) {
|
|
358
|
+
const cachedResult = existing.get();
|
|
359
|
+
VERBOSE2(`[${debugName}] cache hit`, { untrackedArgs, cachedResult });
|
|
360
|
+
return cachedResult;
|
|
361
|
+
}
|
|
362
|
+
if (!opts.keepAlive && !_isComputingDerivation()) {
|
|
363
|
+
if (!memoWarned && _getGlobalState().computedRequiresReaction) {
|
|
364
|
+
console.warn(
|
|
365
|
+
"invoking a computedFn from outside an reactive context won't be memoized, unless keepAlive is set"
|
|
366
|
+
);
|
|
367
|
+
memoWarned = true;
|
|
368
|
+
}
|
|
369
|
+
return fn.apply(this, args);
|
|
370
|
+
}
|
|
371
|
+
VERBOSE2(`[${debugName}] new computation`, { untrackedArgs });
|
|
372
|
+
let latestValue;
|
|
373
|
+
const computation = computed(
|
|
374
|
+
() => {
|
|
375
|
+
VERBOSE2(`[${debugName}] update->rerun`, untracked(() => ({ args })), fn);
|
|
376
|
+
VERBOSE2.isDisabled || trace();
|
|
377
|
+
return latestValue = fn.apply(this, args);
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
...opts,
|
|
381
|
+
name: debugName
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
VERBOSE2(`[${debugName}] deps`, getDependencyTree(computation), { untrackedArgs });
|
|
385
|
+
map.set(untrackedArgs, computation);
|
|
386
|
+
if (!opts.keepAlive) {
|
|
387
|
+
const unobserveUnobserving = onBecomeUnobserved(computation, () => {
|
|
388
|
+
VERBOSE2(`[${debugName}] dispose`, computation);
|
|
389
|
+
map.delete(untrackedArgs);
|
|
390
|
+
if (opts.onCleanup)
|
|
391
|
+
opts.onCleanup(latestValue, ...args);
|
|
392
|
+
latestValue = void 0;
|
|
393
|
+
unobserveUnobserving();
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return computation.get();
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function prettifyStreamName(input) {
|
|
400
|
+
let depth = 0;
|
|
401
|
+
let result = "";
|
|
402
|
+
let insideCurlyBraces = 0;
|
|
403
|
+
for (let i = 0; i < input.length; i++) {
|
|
404
|
+
const char = input[i];
|
|
405
|
+
if (char === "(") {
|
|
406
|
+
result += char + "\n" + " ".repeat(++depth);
|
|
407
|
+
} else if (char === ")") {
|
|
408
|
+
result += "\n" + " ".repeat(--depth) + char;
|
|
409
|
+
} else if (char === "," && insideCurlyBraces === 0) {
|
|
410
|
+
result += char + "\n" + " ".repeat(depth);
|
|
411
|
+
} else if (char === "{" && insideCurlyBraces === 0) {
|
|
412
|
+
insideCurlyBraces++;
|
|
413
|
+
result += char + "\n" + " ".repeat(depth + 1);
|
|
414
|
+
} else if (char === "}" && insideCurlyBraces === 1) {
|
|
415
|
+
insideCurlyBraces--;
|
|
416
|
+
result += "\n" + " ".repeat(depth) + char;
|
|
417
|
+
} else if (char === "{" && insideCurlyBraces > 0) {
|
|
418
|
+
insideCurlyBraces++;
|
|
419
|
+
result += char;
|
|
420
|
+
} else if (char === "}" && insideCurlyBraces > 1) {
|
|
421
|
+
insideCurlyBraces--;
|
|
422
|
+
result += char;
|
|
423
|
+
} else {
|
|
424
|
+
result += char;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/stream/basic.ts
|
|
431
|
+
import { computed as computed2, makeObservable, untracked as untracked2 } from "mobx";
|
|
432
|
+
import { Logger as Logger3 } from "besonders-logger/src";
|
|
433
|
+
var { WARN: WARN3, LOG: LOG3, DEBUG: DEBUG3, VERBOSE: VERBOSE3, ERROR: ERROR3 } = Logger3.setup(Logger3.INFO, { prefix: "[stream]" });
|
|
434
|
+
function isInitEvent(event) {
|
|
435
|
+
return event.init !== void 0;
|
|
436
|
+
}
|
|
437
|
+
var ApplogStream = class {
|
|
438
|
+
constructor(parents, filters, _applogs = [], name) {
|
|
439
|
+
this._applogs = _applogs;
|
|
440
|
+
this.name = name;
|
|
441
|
+
__publicField(this, "filters");
|
|
442
|
+
__publicField(this, "parents");
|
|
443
|
+
__publicField(this, "_subscribers", []);
|
|
444
|
+
this.parents = parents && !Array.isArray(parents) ? [parents] : parents;
|
|
445
|
+
this.filters = filters;
|
|
446
|
+
if (this.parents?.length === 0) {
|
|
447
|
+
throw new Error(`Unhandled: empty parents`);
|
|
448
|
+
}
|
|
449
|
+
makeObservable(this, {
|
|
450
|
+
// applogs: computed, //observable.shallow,
|
|
451
|
+
// applogsSorted: computed,
|
|
452
|
+
size: computed2,
|
|
453
|
+
isEmpty: computed2,
|
|
454
|
+
firstLog: computed2,
|
|
455
|
+
latestLog: computed2
|
|
456
|
+
}, { name: `Stream{${name}}` });
|
|
457
|
+
}
|
|
458
|
+
subscribe(callback) {
|
|
459
|
+
this._subscribers.push(callback);
|
|
460
|
+
return this.unsubscribe.bind(this, callback);
|
|
461
|
+
}
|
|
462
|
+
unsubscribe(callback) {
|
|
463
|
+
const index = this._subscribers.indexOf(callback);
|
|
464
|
+
if (index !== -1) {
|
|
465
|
+
this._subscribers.splice(index, 1);
|
|
466
|
+
} else
|
|
467
|
+
WARN3(`unsubscribe called for non-existent`, callback);
|
|
468
|
+
}
|
|
469
|
+
notifySubscribers(event) {
|
|
470
|
+
DEBUG3(`[stream: ${this.name}] notifying`, this._subscribers.length, "subscribers of", { ...event, subs: this._subscribers });
|
|
471
|
+
for (const subscriber of this._subscribers) {
|
|
472
|
+
subscriber(event);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
get applogs() {
|
|
476
|
+
return this._applogs;
|
|
477
|
+
}
|
|
478
|
+
map(fn) {
|
|
479
|
+
if (!this.applogs.map)
|
|
480
|
+
ERROR3(`applogs arr?!`, this.applogs);
|
|
481
|
+
return this.applogs.map(fn);
|
|
482
|
+
}
|
|
483
|
+
get firstLog() {
|
|
484
|
+
return this.applogs[0];
|
|
485
|
+
}
|
|
486
|
+
get latestLog() {
|
|
487
|
+
return this.applogs[this.applogs.length - 1];
|
|
488
|
+
}
|
|
489
|
+
hasApplog(applog, byRef) {
|
|
490
|
+
if (byRef) {
|
|
491
|
+
return this.applogs.includes(applog);
|
|
492
|
+
} else {
|
|
493
|
+
const keySet = Object.keys(applog);
|
|
494
|
+
return !!this.applogs.find((log) => {
|
|
495
|
+
if (!arraysContainSameElements(keySet, Object.keys(log))) {
|
|
496
|
+
throw ERROR3(`[hasApplog] field set mismatch:`, { applog, log });
|
|
497
|
+
}
|
|
498
|
+
return areApplogsEqual(log, applog);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
hasApplogWithDiffTs(applog) {
|
|
503
|
+
return this.applogs.find((existing) => existing.en === applog.en && existing.at === applog.at && existing.vl === applog.vl && existing.ag === applog.ag);
|
|
504
|
+
}
|
|
505
|
+
get isEmpty() {
|
|
506
|
+
return this.size === 0;
|
|
507
|
+
}
|
|
508
|
+
get size() {
|
|
509
|
+
return this.applogs.length;
|
|
510
|
+
}
|
|
511
|
+
get untrackedSize() {
|
|
512
|
+
return untracked2(() => this.size);
|
|
513
|
+
}
|
|
514
|
+
get nameAndSizeUntracked() {
|
|
515
|
+
return untracked2(() => `${this.name} (${this.size})`);
|
|
516
|
+
}
|
|
517
|
+
get prettyName() {
|
|
518
|
+
return prettifyStreamName(this.name);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/stream/mapped.ts
|
|
523
|
+
import { Logger as Logger4 } from "besonders-logger/src";
|
|
524
|
+
import { sortedIndexBy } from "lodash-es";
|
|
525
|
+
import { action, getDependencyTree as getDependencyTree2, makeObservable as makeObservable2, observable as observable2, toJS, untracked as untracked3 } from "mobx";
|
|
526
|
+
var { WARN: WARN4, LOG: LOG4, DEBUG: DEBUG4, VERBOSE: VERBOSE4, ERROR: ERROR4 } = Logger4.setup(Logger4.INFO);
|
|
527
|
+
var MappedApplogStream = class extends ApplogStream {
|
|
528
|
+
constructor(parents, filters, _initialLogs, _eventMapper, name) {
|
|
529
|
+
super(
|
|
530
|
+
parents,
|
|
531
|
+
filters,
|
|
532
|
+
observable2.array([..._initialLogs], { deep: false, name: `${name}.array` }),
|
|
533
|
+
// ? not sure if array clone is totally necessary - but I also don't want to risk weird bugs
|
|
534
|
+
name
|
|
535
|
+
);
|
|
536
|
+
this._initialLogs = _initialLogs;
|
|
537
|
+
this._eventMapper = _eventMapper;
|
|
538
|
+
this.name = name;
|
|
539
|
+
__publicField(this, "_parentSubscriptions", /* @__PURE__ */ new Map());
|
|
540
|
+
makeObservable2(this, {
|
|
541
|
+
// @ts-expect-error bc it's private
|
|
542
|
+
onParentUpdate: action
|
|
543
|
+
});
|
|
544
|
+
this.subscribeToParent();
|
|
545
|
+
}
|
|
546
|
+
get readOnly() {
|
|
547
|
+
if (this.parents.length !== 1)
|
|
548
|
+
return true;
|
|
549
|
+
return this.parents[0].readOnly;
|
|
550
|
+
}
|
|
551
|
+
subscribeToParent() {
|
|
552
|
+
if (!this.parents.length) {
|
|
553
|
+
WARN4(`MappedStream has no parents`, this);
|
|
554
|
+
}
|
|
555
|
+
if (this._parentSubscriptions.size) {
|
|
556
|
+
throw ERROR4(`parents subs must not be called twice`, this);
|
|
557
|
+
}
|
|
558
|
+
VERBOSE4(`[MappedStream: ${this.name}] subscribing to parents:`, this.parents.map((p) => p.name));
|
|
559
|
+
this.parents.forEach((p) => {
|
|
560
|
+
const sub = this.onParentUpdate.bind(this, p);
|
|
561
|
+
p.subscribe(sub);
|
|
562
|
+
this._parentSubscriptions.set(p, sub);
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* // HACK to trigger remap on pattern change in rollingFilter
|
|
567
|
+
* should not be used lightly
|
|
568
|
+
*/
|
|
569
|
+
triggerRemap() {
|
|
570
|
+
VERBOSE4(`MappedStream{${this.nameAndSizeUntracked}} triggerRemap`);
|
|
571
|
+
this.parents.forEach((p) => {
|
|
572
|
+
this.onParentUpdate(p, { init: untracked3(() => toJS(p.applogs)) });
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
onParentUpdate(stream, event) {
|
|
576
|
+
VERBOSE4(`MappedStream{${this.nameAndSizeUntracked}} parentUpdate`, event);
|
|
577
|
+
const mapResult = this._eventMapper(event, stream);
|
|
578
|
+
VERBOSE4(`MappedStream{${this.nameAndSizeUntracked}} parentUpdate => mapped`, mapResult);
|
|
579
|
+
if (isInitEvent(mapResult)) {
|
|
580
|
+
;
|
|
581
|
+
this._applogs.replace([...mapResult.init]);
|
|
582
|
+
} else {
|
|
583
|
+
for (const log of mapResult.added) {
|
|
584
|
+
this._applogs.splice(sortedIndexBy(this._applogs, log, "ts"), 0, log);
|
|
585
|
+
}
|
|
586
|
+
if (mapResult.removed) {
|
|
587
|
+
for (const toRemove of mapResult.removed) {
|
|
588
|
+
if (!this._applogs.remove(toRemove)) {
|
|
589
|
+
if (!isInitEvent(event) && event.removed?.includes(toRemove)) {
|
|
590
|
+
DEBUG4(`Ignoring remove event for non-existent because it was part of parent event's removed`, toRemove, event);
|
|
591
|
+
} else {
|
|
592
|
+
throw ERROR4(`MappedStream{${this.name}} toRemove contained log that doesn't exist`, toRemove, {
|
|
593
|
+
stream: this,
|
|
594
|
+
event,
|
|
595
|
+
mapResult
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
VERBOSE4(`MappedStream{${this.nameAndSizeUntracked}} parentUpdate => deps?`, getDependencyTree2(this._applogs));
|
|
603
|
+
this.notifySubscribers(mapResult);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/stream/filters.ts
|
|
608
|
+
import { Logger as Logger5 } from "besonders-logger/src";
|
|
609
|
+
import { action as action2, observable as observable3, onBecomeUnobserved as onBecomeUnobserved2, reaction, toJS as toJS2, untracked as untracked4 } from "mobx";
|
|
610
|
+
import stringify3 from "safe-stable-stringify";
|
|
611
|
+
var { WARN: WARN5, LOG: LOG5, DEBUG: DEBUG5, VERBOSE: VERBOSE5, ERROR: ERROR5 } = Logger5.setup(Logger5.INFO);
|
|
612
|
+
var rollingFilter = computedFnDeepCompare(function rollingFilter2(stream, pattern, opts = {}) {
|
|
613
|
+
let untrackedPattern = getUntrackedPattern(pattern);
|
|
614
|
+
let filter = makeFilter(untrackedPattern);
|
|
615
|
+
const observableArr = observable3.array(
|
|
616
|
+
untracked4(() => filter(stream.applogs)),
|
|
617
|
+
{ deep: false, name: `${stream.name} | ${opts.name || `rollingFilter.array{${stringify3(untrackedPattern)}}`}` }
|
|
618
|
+
);
|
|
619
|
+
const filterAdded = (event) => {
|
|
620
|
+
let mappedEvent;
|
|
621
|
+
if (isInitEvent(event)) {
|
|
622
|
+
mappedEvent = { init: filter(event.init) };
|
|
623
|
+
} else {
|
|
624
|
+
mappedEvent = {
|
|
625
|
+
added: filter(event.added),
|
|
626
|
+
removed: event.removed
|
|
627
|
+
// whatever's removed shall be removed
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
VERBOSE5(
|
|
631
|
+
`rollingFilter{${stream.nameAndSizeUntracked} | ${opts.name ? ` '${opts.name}'}` : ""} parentUpdate`,
|
|
632
|
+
untrackedPattern,
|
|
633
|
+
event,
|
|
634
|
+
"=>",
|
|
635
|
+
mappedEvent
|
|
636
|
+
);
|
|
637
|
+
return mappedEvent;
|
|
638
|
+
};
|
|
639
|
+
const mappedStream = new MappedApplogStream(
|
|
640
|
+
stream,
|
|
641
|
+
[...stream.filters, ...opts.extraFilterName ? [opts.extraFilterName] : []],
|
|
642
|
+
observableArr,
|
|
643
|
+
filterAdded,
|
|
644
|
+
`${stream.name} | ${opts.name || `rollingFilter{${stringify3(untrackedPattern)}}`}`
|
|
645
|
+
);
|
|
646
|
+
const cancelPatternReaction = reaction(() => JSON.parse(JSON.stringify(pattern)), (pat) => {
|
|
647
|
+
VERBOSE5(
|
|
648
|
+
`rollingFilter<${stream.nameAndSizeUntracked}>${opts.name ? ` '${opts.name}'` : ""} patternUpdate`,
|
|
649
|
+
untrackedPattern,
|
|
650
|
+
"=>",
|
|
651
|
+
pat
|
|
652
|
+
/* , getDependencyTree(pat) */
|
|
653
|
+
);
|
|
654
|
+
untrackedPattern = pat;
|
|
655
|
+
filter = makeFilter(untrackedPattern);
|
|
656
|
+
mappedStream.triggerRemap();
|
|
657
|
+
});
|
|
658
|
+
const unobserveUnobserving = onBecomeUnobserved2(observableArr, () => {
|
|
659
|
+
VERBOSE5(`rollingFilter<${stream.nameAndSizeUntracked}>${opts.name ? ` '${opts.name}'` : ""} unobserve`, untrackedPattern);
|
|
660
|
+
cancelPatternReaction();
|
|
661
|
+
unobserveUnobserving();
|
|
662
|
+
});
|
|
663
|
+
return mappedStream;
|
|
664
|
+
}, { equals: applogStreamComparer, argsDebugName: (_, pattern, opts) => `${stringify3(pattern)}, ${stringify3(opts)}` });
|
|
665
|
+
var rollingMapper = computedFnDeepCompare(function rollingMapper2(stream, eventMapper, opts = {}) {
|
|
666
|
+
const initialMapResult = untracked4(() => eventMapper.call(null, { init: stream.applogs }, stream));
|
|
667
|
+
if (!isInitEvent(initialMapResult)) {
|
|
668
|
+
throw ERROR5("Initial run must return init event");
|
|
669
|
+
}
|
|
670
|
+
const initialLogs = initialMapResult.init;
|
|
671
|
+
return new MappedApplogStream(
|
|
672
|
+
stream,
|
|
673
|
+
[...stream.filters, ...opts.extraFilterName ? [opts.extraFilterName] : []],
|
|
674
|
+
initialLogs,
|
|
675
|
+
eventMapper,
|
|
676
|
+
`${stream.name} | ${opts.name || `rollingMapper`}`
|
|
677
|
+
);
|
|
678
|
+
}, { equals: applogStreamComparer, argsDebugName: (_, pattern, opts) => `${stringify3(pattern)}, ${stringify3(opts)}` });
|
|
679
|
+
var rollingAcc = computedFnDeepCompare(function rollingAcc2(stream, acc, eventMapper) {
|
|
680
|
+
eventMapper = action2(eventMapper);
|
|
681
|
+
eventMapper({ init: stream.applogs }, acc);
|
|
682
|
+
stream.subscribe((event) => {
|
|
683
|
+
eventMapper(event, acc);
|
|
684
|
+
});
|
|
685
|
+
return acc;
|
|
686
|
+
}, { argsDebugName: (stream) => `rollingAcc{${stream.nameAndSizeUntracked}}` });
|
|
687
|
+
var getUntrackedPattern = function getUntrackedPattern2(pattern) {
|
|
688
|
+
const untrackedPattern = untracked4(() => Object.fromEntries(Object.entries(toJS2(pattern)).map(([k, v]) => [toJS2(k), toJS2(v)])));
|
|
689
|
+
if (!Object.entries(untrackedPattern).length) {
|
|
690
|
+
throw new Error(`Pattern is empty`);
|
|
691
|
+
}
|
|
692
|
+
return untrackedPattern;
|
|
693
|
+
};
|
|
694
|
+
function makeFilter(pattern) {
|
|
695
|
+
return (logs) => logs.filter((applog) => {
|
|
696
|
+
for (const [field, patternValue] of Object.entries(pattern)) {
|
|
697
|
+
const applogValue = applog[field.startsWith("!") ? field.slice(1) : field];
|
|
698
|
+
const patternValT = patternValue;
|
|
699
|
+
if (!matchPartStatic(field, patternValT, applogValue)) {
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return true;
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
var getUntrackedFilterResults = function getUntrackedFilterResults2(stream, pattern, opts = {}) {
|
|
707
|
+
const untrackedPattern = getUntrackedPattern(pattern);
|
|
708
|
+
const filter = makeFilter(untrackedPattern);
|
|
709
|
+
return untracked4(() => filter(stream.applogs));
|
|
710
|
+
};
|
|
711
|
+
function hasFilter(stream, filter) {
|
|
712
|
+
return stream.filters.includes(filter);
|
|
713
|
+
}
|
|
714
|
+
function assertRaw(stream) {
|
|
715
|
+
if (stream.filters.length) {
|
|
716
|
+
throw ERROR5(`should be unfiltered stream, but is:`, stream.filters);
|
|
717
|
+
}
|
|
718
|
+
return stream;
|
|
719
|
+
}
|
|
720
|
+
function assertOnlyCurrent(stream) {
|
|
721
|
+
if (!hasFilter(stream, "withoutHistory") || !hasFilter(stream, "withoutDeleted"))
|
|
722
|
+
throw ERROR5(`should be filtered stream, but is:`, stream.filters);
|
|
723
|
+
return stream;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export {
|
|
727
|
+
isoDateStrCompare,
|
|
728
|
+
sortApplogsByTs,
|
|
729
|
+
isTsBefore,
|
|
730
|
+
uniqueEnFromAppLogs,
|
|
731
|
+
areApplogsEqual,
|
|
732
|
+
removeDuplicateAppLogs,
|
|
733
|
+
getHashID,
|
|
734
|
+
isVariable,
|
|
735
|
+
variableNameWithoutQuestionmark,
|
|
736
|
+
isStaticPattern,
|
|
737
|
+
resolveOrRemoveVariables,
|
|
738
|
+
matchPartStatic,
|
|
739
|
+
matchPart,
|
|
740
|
+
matchPattern,
|
|
741
|
+
actualize,
|
|
742
|
+
arrStats,
|
|
743
|
+
tsNearlySame,
|
|
744
|
+
cyrb53hash,
|
|
745
|
+
arraysContainSameElements,
|
|
746
|
+
dateNowIso,
|
|
747
|
+
createDebugName,
|
|
748
|
+
createDebugNameObj,
|
|
749
|
+
computedStructuralComparer,
|
|
750
|
+
applogStreamComparer,
|
|
751
|
+
queryNodesComparer,
|
|
752
|
+
observableArrayMap,
|
|
753
|
+
computedFnDeepCompare,
|
|
754
|
+
prettifyStreamName,
|
|
755
|
+
isInitEvent,
|
|
756
|
+
ApplogStream,
|
|
757
|
+
MappedApplogStream,
|
|
758
|
+
rollingFilter,
|
|
759
|
+
rollingMapper,
|
|
760
|
+
rollingAcc,
|
|
761
|
+
getUntrackedPattern,
|
|
762
|
+
makeFilter,
|
|
763
|
+
getUntrackedFilterResults,
|
|
764
|
+
hasFilter,
|
|
765
|
+
assertRaw,
|
|
766
|
+
assertOnlyCurrent
|
|
767
|
+
};
|
|
768
|
+
//# sourceMappingURL=chunk-TYTIT5QO.js.map
|