@cccsaurora/clue-ui 1.2.3-dev.266 → 1.2.3

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.
Files changed (183) hide show
  1. package/ActionForm-DlOXqMUx.js +4460 -0
  2. package/AnnotationDetails-Bk-p0F6h.js +160 -0
  3. package/AnnotationPreview-jzZvkCxJ.js +140 -0
  4. package/ClueEnrichContext-KqRuuWNS.js +418 -0
  5. package/FlexOne-BXWFOd1T.js +6 -0
  6. package/_MapCache-BiTi0iqu.js +180 -0
  7. package/_Uint8Array-BQNOM9Rr.js +101 -0
  8. package/_baseAssignValue-CNMLQZco.js +20 -0
  9. package/_baseClone-BnT-6pyM.js +207 -0
  10. package/_baseExtremum-Ca2EHgy2.js +16 -0
  11. package/_baseFlatten-Bfr_Molw.js +72 -0
  12. package/_baseGet-DSZygzyq.js +79 -0
  13. package/_baseIsEqual-VgvaAFZG.js +147 -0
  14. package/_baseIteratee-Dbfsw5z8.js +95 -0
  15. package/_baseSlice-M5RKzt1A.js +10 -0
  16. package/_baseSum-wEbgNeUs.js +10 -0
  17. package/_baseUniq-BJcj69PL.js +79 -0
  18. package/_commonjsHelpers-DaMA6jEr.js +8 -0
  19. package/_createAggregator-k3TuAnxT.js +53 -0
  20. package/_getPrototype-Cr1Mk7BC.js +5 -0
  21. package/_getTag-CK2Sffaq.js +90 -0
  22. package/_isIterateeCall-DkJP7Rbx.js +13 -0
  23. package/_setToArray-C7yMOeww.js +29 -0
  24. package/cloneDeep-CF8TtLHr.js +8 -0
  25. package/components/AnnotationBody.js +35 -49
  26. package/components/AnnotationDetailPopover.js +30 -36
  27. package/components/AnnotationDetails.js +7 -7
  28. package/components/AnnotationEntry.js +35 -35
  29. package/components/AnnotationPreview.js +5 -5
  30. package/components/ClassificationChip.js +23 -44
  31. package/components/CountBadge.js +26 -31
  32. package/components/EnrichedCard.js +97 -110
  33. package/components/EnrichedChip.js +105 -130
  34. package/components/EnrichedTypography.js +107 -133
  35. package/components/ErrorBoundary.js +24 -28
  36. package/components/RetryFailedEnrichments.js +9 -10
  37. package/components/SourcePicker.js +49 -57
  38. package/components/actions/ActionForm.js +4 -4
  39. package/components/actions/ExecutePopover.js +59 -75
  40. package/components/actions/ResultModal.js +4 -4
  41. package/components/actions/form/schemaAdapter.js +23 -39
  42. package/components/actions/formats/FileResult.js +59 -86
  43. package/components/actions/formats/index.js +10 -21
  44. package/components/display/graph/ExpandMoreButton.js +10 -10
  45. package/components/display/graph/elements/NodeCard.js +91 -111
  46. package/components/display/graph/elements/NodeTag.js +13 -15
  47. package/components/display/graph/index.js +202 -261
  48. package/components/display/graph/visualizations/Leaf.js +69 -88
  49. package/components/display/graph/visualizations/cloud/index.js +81 -98
  50. package/components/display/graph/visualizations/icons/BaseIcon.js +21 -26
  51. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  52. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  53. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  54. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  55. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  56. package/components/display/graph/visualizations/icons/index.js +13 -14
  57. package/components/display/graph/visualizations/panels/NodePanel.js +8 -10
  58. package/components/display/graph/visualizations/tree/BundleLine.js +81 -108
  59. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  60. package/components/display/graph/visualizations/tree/index.js +306 -408
  61. package/components/display/icons/Iconified.js +12 -27
  62. package/components/display/json/index.js +4 -4
  63. package/components/display/markdown/index.js +5770 -8678
  64. package/components/enrichment/EnrichPopover.js +46 -54
  65. package/components/fetchers/Fetcher.js +119 -158
  66. package/components/fetchers/PreviewModal.js +17 -20
  67. package/components/fetchers/StatusChip.js +17 -21
  68. package/components/group/Entry.js +11 -13
  69. package/components/group/Group.js +10 -13
  70. package/components/group/GroupControl.js +65 -76
  71. package/components/stats/QueryStatus.js +33 -43
  72. package/countBy-CdYegFSu.js +8 -0
  73. package/data/event.js +4 -6
  74. package/database/index.js +2 -2
  75. package/debounce-DryYcbJ4.js +56 -0
  76. package/get-CH7kz5Ix.js +8 -0
  77. package/groupBy-br8xmD2R.js +8 -0
  78. package/hooks/ClueActionContext.js +6 -6
  79. package/hooks/ClueComponentContext.js +23 -29
  80. package/hooks/ClueConfigProvider.js +12 -14
  81. package/hooks/ClueDatabaseContext.js +13 -19
  82. package/hooks/ClueEnrichContext.js +8 -8
  83. package/hooks/ClueFetcherContext.js +56 -83
  84. package/hooks/ClueGroupContext.js +14 -17
  85. package/hooks/CluePopupContext.js +5 -5
  86. package/hooks/ClueProvider.js +10 -12
  87. package/hooks/selectors.js +7 -7
  88. package/hooks/useActionResult.js +2 -2
  89. package/hooks/useAnnotations.js +31 -47
  90. package/hooks/useClue.js +4 -6
  91. package/hooks/useClueActions.js +3 -3
  92. package/hooks/useClueConfig.js +4 -6
  93. package/hooks/useClueTypeConfig.js +3 -3
  94. package/hooks/useComparator.js +435 -722
  95. package/hooks/useErrors.js +18 -22
  96. package/hooks/useFetcherResult.js +24 -33
  97. package/hooks/useMyHighlights.js +36 -66
  98. package/hooks/useMyLocalStorage.js +37 -66
  99. package/iconify-BBckr5AQ.js +1263 -0
  100. package/icons/Action.js +49 -66
  101. package/icons/Assessment.js +69 -85
  102. package/icons/Context.js +63 -77
  103. package/icons/Opinion.js +60 -76
  104. package/icons/iconMap.js +2 -2
  105. package/identity-ByMq8VxU.js +6 -0
  106. package/index-BHAe_V9n.js +12768 -0
  107. package/index-BK-zfYhR.js +358 -0
  108. package/index-CA5CUNZO.js +975 -0
  109. package/index-Dj5C04IX.js +568 -0
  110. package/index-p5_wX7q1.js +11729 -0
  111. package/isNil-CjWwlQS3.js +6 -0
  112. package/isObject-B53jY8Qg.js +7 -0
  113. package/isObjectLike-BatpeCIi.js +29 -0
  114. package/isSymbol-C3_SC0Qp.js +8 -0
  115. package/last-7CdUxN0r.js +7 -0
  116. package/main.js +60 -60
  117. package/maxBy-Bc0dYHcO.js +8 -0
  118. package/package.json +1 -1
  119. package/sortBy-DY2JBf9n.js +75 -0
  120. package/sumBy-DuMASLPd.js +8 -0
  121. package/text/Frequency.js +23 -42
  122. package/toFinite-BMy6GObD.js +14 -0
  123. package/toNumber-YVhnnJv4.js +31 -0
  124. package/useClueTypeConfig-Ct9Ygter.js +2292 -0
  125. package/utils/chain.js +65 -92
  126. package/utils/classificationParser.js +256 -519
  127. package/utils/constants.js +10 -35
  128. package/utils/graph.js +45 -72
  129. package/utils/hashUtil.js +7 -7
  130. package/utils/line.js +81 -131
  131. package/utils/loggerUtil.js +3 -5
  132. package/utils/sessionStorage.js +27 -41
  133. package/utils/time.js +423 -423
  134. package/utils/utils.js +9 -9
  135. package/utils/window.js +10 -21
  136. package/utils-DmwSUrum.js +129 -0
  137. package/ActionForm-uDp92tN2.js +0 -5941
  138. package/AnnotationDetails-DGYfOiWm.js +0 -175
  139. package/AnnotationPreview-bHObsb3P.js +0 -188
  140. package/ClueEnrichContext-CJEJxrgs.js +0 -541
  141. package/FlexOne-BSYAhhtG.js +0 -9
  142. package/_MapCache-WmuDdwuH.js +0 -222
  143. package/_Uint8Array-B7JqpgFX.js +0 -128
  144. package/_baseAssignValue-CGTuELqU.js +0 -25
  145. package/_baseClone-CkNrTyhm.js +0 -283
  146. package/_baseExtremum-kob8QXyt.js +0 -18
  147. package/_baseFlatten-jIR_sN_-.js +0 -92
  148. package/_baseGet-Bx3A4Qfp.js +0 -108
  149. package/_baseIsEqual-C5OTWzTk.js +0 -208
  150. package/_baseIteratee-avi7MX2o.js +0 -126
  151. package/_baseSlice-GAv_YFTT.js +0 -20
  152. package/_baseSum-D0WC1dN0.js +0 -13
  153. package/_baseUniq-BI9GIHMF.js +0 -115
  154. package/_commonjsHelpers-DWwsNxpa.js +0 -8
  155. package/_createAggregator-QD8MzKwe.js +0 -63
  156. package/_getPrototype-CU0j_POw.js +0 -5
  157. package/_getTag-Ckxxfr88.js +0 -126
  158. package/_isIterateeCall-Ds3sw2SF.js +0 -17
  159. package/_setToArray-CaPKQhcz.js +0 -33
  160. package/cloneDeep-DJrLSw8W.js +0 -8
  161. package/countBy-c6S3dvSW.js +0 -14
  162. package/debounce-bV0h5FC5.js +0 -92
  163. package/get-DSsNkRQs.js +0 -8
  164. package/groupBy-xqz-n0Vd.js +0 -14
  165. package/iconify-CXMreGTg.js +0 -1782
  166. package/identity-CPGTqrE4.js +0 -6
  167. package/index-AMfoEg_6.js +0 -696
  168. package/index-B6C2a_Lg.js +0 -1172
  169. package/index-C12gPw2W.js +0 -17698
  170. package/index-DCKkHTvx.js +0 -15750
  171. package/index-JcKyZeoY.js +0 -465
  172. package/isNil-CIubwp4T.js +0 -6
  173. package/isObject-FTY-5JQX.js +0 -7
  174. package/isObjectLike-OAgjjZye.js +0 -48
  175. package/isSymbol-Xd2FsJyp.js +0 -8
  176. package/last-CUCl67Im.js +0 -7
  177. package/maxBy-IKHzFrCS.js +0 -8
  178. package/sortBy-DfSj8IoJ.js +0 -96
  179. package/sumBy-D-hb_NY-.js +0 -8
  180. package/toFinite-Bc55msYj.js +0 -16
  181. package/toNumber-DPxy1FBy.js +0 -39
  182. package/useClueTypeConfig-Z1LFp01b.js +0 -3289
  183. package/utils-HmNPuoDB.js +0 -199
@@ -1,541 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { a as addAPIProvider } from "./iconify-CXMreGTg.js";
3
- import { b as useClueTypeConfig, a as api, p as post, u as uniq } from "./useClueTypeConfig-Z1LFp01b.js";
4
- import { clueDebugLogger } from "./utils/loggerUtil.js";
5
- import { b as baseSlice } from "./_baseSlice-GAv_YFTT.js";
6
- import { t as toFinite } from "./toFinite-Bc55msYj.js";
7
- import { d as debounce } from "./debounce-bV0h5FC5.js";
8
- import { g as groupBy } from "./groupBy-xqz-n0Vd.js";
9
- import { b as baseIteratee } from "./_baseIteratee-avi7MX2o.js";
10
- import { b as baseUniq } from "./_baseUniq-BI9GIHMF.js";
11
- import { useContext, useState, useMemo, useCallback, useRef, useEffect } from "react";
12
- import { c as createContext } from "./index-AMfoEg_6.js";
13
- import { ClueDatabaseContext } from "./hooks/ClueDatabaseContext.js";
14
- import useClueConfig from "./hooks/useClueConfig.js";
15
- function toInteger(value) {
16
- var result = toFinite(value), remainder = result % 1;
17
- return result === result ? remainder ? result - remainder : result : 0;
18
- }
19
- var nativeCeil = Math.ceil, nativeMax = Math.max;
20
- function chunk(array, size, guard) {
21
- if (size === void 0) {
22
- size = 1;
23
- } else {
24
- size = nativeMax(toInteger(size), 0);
25
- }
26
- var length = array == null ? 0 : array.length;
27
- if (!length || size < 1) {
28
- return [];
29
- }
30
- var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
31
- while (index < length) {
32
- result[resIndex++] = baseSlice(array, index, index += size);
33
- }
34
- return result;
35
- }
36
- function uniqBy(array, iteratee) {
37
- return array && array.length ? baseUniq(array, baseIteratee(iteratee)) : [];
38
- }
39
- let getRandomValues;
40
- const rnds8 = new Uint8Array(16);
41
- function rng() {
42
- if (!getRandomValues) {
43
- getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
44
- if (!getRandomValues) {
45
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
46
- }
47
- }
48
- return getRandomValues(rnds8);
49
- }
50
- const byteToHex = [];
51
- for (let i = 0; i < 256; ++i) {
52
- byteToHex.push((i + 256).toString(16).slice(1));
53
- }
54
- function unsafeStringify(arr, offset = 0) {
55
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
56
- }
57
- const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
58
- const native = {
59
- randomUUID
60
- };
61
- function v4(options, buf, offset) {
62
- if (native.randomUUID && true && !options) {
63
- return native.randomUUID();
64
- }
65
- options = options || {};
66
- const rnds = options.random || (options.rng || rng)();
67
- rnds[6] = rnds[6] & 15 | 64;
68
- rnds[8] = rnds[8] & 63 | 128;
69
- return unsafeStringify(rnds);
70
- }
71
- const ClueEnrichContext = createContext(null);
72
- const ClueEnrichProvider = ({
73
- children,
74
- classification: _defaultClassification,
75
- baseURL,
76
- getToken,
77
- onNetworkCall,
78
- pickSources,
79
- chunkSize = 15,
80
- maxRequestCount = 4,
81
- defaultTimeout = 5,
82
- enabled = true,
83
- ready = false,
84
- publicIconify = true,
85
- skipConfigCall = false,
86
- customIconify: _customIconify,
87
- debugLogging = true
88
- }) => {
89
- var _a, _b, _c, _d, _e;
90
- const clueConfig = useClueConfig();
91
- const database = useContext(ClueDatabaseContext);
92
- const [configuredDefaultClassification, setConfiguredDefaultClassification] = useState(null);
93
- const defaultClassification = useMemo(
94
- () => {
95
- var _a2, _b2;
96
- return configuredDefaultClassification ?? _defaultClassification ?? ((_b2 = (_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef) == null ? void 0 : _b2.RESTRICTED);
97
- },
98
- [_defaultClassification, (_b = (_a = clueConfig.config) == null ? void 0 : _a.c12nDef) == null ? void 0 : _b.RESTRICTED, configuredDefaultClassification]
99
- );
100
- const setDefaultClassification = useCallback(
101
- (func) => {
102
- var _a2;
103
- return setConfiguredDefaultClassification(func((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef));
104
- },
105
- [(_c = clueConfig.config) == null ? void 0 : _c.c12nDef]
106
- );
107
- const [isReady, setIsReady] = useState(ready);
108
- const runningRequestCount = useRef(0);
109
- const [sources, setSources] = useState([]);
110
- const { availableSources, typesDetection, supportedTypes } = useClueTypeConfig(
111
- enabled && isReady,
112
- baseURL,
113
- debugLogging,
114
- getToken,
115
- onNetworkCall
116
- );
117
- useEffect(() => {
118
- if (skipConfigCall || !enabled || !isReady) {
119
- return;
120
- }
121
- const headers = {};
122
- const token = getToken == null ? void 0 : getToken();
123
- if (token) {
124
- headers.Authorization = `Bearer ${token}`;
125
- }
126
- let requestConfig = { baseURL, headers };
127
- if (onNetworkCall) {
128
- requestConfig = onNetworkCall(requestConfig);
129
- }
130
- api.configs.get(requestConfig).then(clueConfig.setConfig);
131
- }, [baseURL, onNetworkCall, skipConfigCall, isReady]);
132
- const [customIconify, setCustomIconify] = useState(_customIconify);
133
- useEffect(() => {
134
- if (_customIconify) {
135
- setCustomIconify(_customIconify);
136
- }
137
- }, [_customIconify]);
138
- useEffect(() => {
139
- if (publicIconify) {
140
- return;
141
- }
142
- let iconURL = customIconify ?? void 0 ?? (baseURL == null ? void 0 : baseURL.replace(/^[^.]+/, "icons"));
143
- if (!iconURL && typeof window !== "undefined" && !!window && !window.location.origin.includes("localhost")) {
144
- iconURL = window.location.protocol + "//" + window.location.origin.replace(/^[^.]+/, "icons");
145
- }
146
- if (iconURL) {
147
- clueDebugLogger(`Using ${iconURL} for iconify`, debugLogging);
148
- addAPIProvider("", {
149
- resources: [iconURL]
150
- });
151
- }
152
- }, [baseURL, customIconify, debugLogging, publicIconify]);
153
- const _addEntries = useCallback(
154
- async (entries) => {
155
- const newRecords = [];
156
- for (const entry of entries) {
157
- const { latency, source, type, value: value2, items, error } = entry;
158
- if (error) {
159
- newRecords.push({
160
- id: v4(),
161
- source,
162
- type,
163
- value: value2,
164
- annotations: [],
165
- classification: defaultClassification,
166
- latency,
167
- count: 0,
168
- error
169
- });
170
- }
171
- for (const item of items) {
172
- const { classification, count, link, annotations } = item;
173
- await database.selectors.find({ selector: { type, value: value2, source, classification } }).incrementalRemove();
174
- const record = {
175
- id: v4(),
176
- source,
177
- type,
178
- value: value2,
179
- annotations,
180
- classification,
181
- latency,
182
- count,
183
- link,
184
- error
185
- };
186
- if (newRecords.some((_entry) => _entry.id === record.id)) {
187
- record.id = v4();
188
- }
189
- newRecords.push(record);
190
- }
191
- }
192
- const result = await database.selectors.bulkInsert(newRecords);
193
- if (result.error.length > 0) {
194
- console.warn("Errors on upsert:");
195
- result.error.forEach((err) => console.warn(err.documentId, err.validationErrors ?? err.status));
196
- }
197
- },
198
- [database, defaultClassification]
199
- );
200
- const enrich = useCallback(
201
- async (type, value2, _options = {}) => {
202
- var _a2, _b2;
203
- if (!type || !value2) {
204
- console.error(`Type (${type}) or value (${value2}) is empty, returning empty response`);
205
- return {};
206
- }
207
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, [{ type, value: value2, classification: _options.classification }])) ?? sources;
208
- const options = {
209
- timeout: defaultTimeout,
210
- force: false,
211
- includeRaw: false,
212
- noCache: false,
213
- classification: defaultClassification,
214
- sources: _sources,
215
- ..._options
216
- };
217
- const headers = {};
218
- const token = getToken == null ? void 0 : getToken();
219
- if (token) {
220
- headers.Authorization = `Bearer ${token}`;
221
- }
222
- let requestConfig = { baseURL, headers };
223
- if (onNetworkCall) {
224
- requestConfig = onNetworkCall(requestConfig);
225
- }
226
- const selector = {
227
- type,
228
- value: value2,
229
- classification: options.classification
230
- };
231
- let statusRecord = await ((_a2 = database.status) == null ? void 0 : _a2.findOne({ selector: { ...selector } }).exec());
232
- if (!statusRecord) {
233
- statusRecord = await ((_b2 = database.status) == null ? void 0 : _b2.insert({
234
- id: v4(),
235
- type: selector.type,
236
- value: selector.value,
237
- classification: selector.classification ?? defaultClassification,
238
- status: "in-progress"
239
- }));
240
- } else {
241
- await statusRecord.incrementalPatch({ status: "in-progress" });
242
- }
243
- try {
244
- const enrichmentResult = await post([selector], options.sources, options, requestConfig);
245
- const enrichData = Object.values(Object.values(enrichmentResult)[0])[0];
246
- await _addEntries(Object.values(enrichData));
247
- return enrichData;
248
- } catch (e) {
249
- console.error(e);
250
- return {};
251
- } finally {
252
- await (statusRecord == null ? void 0 : statusRecord.incrementalPatch({ status: "complete" }));
253
- }
254
- },
255
- [
256
- _addEntries,
257
- availableSources,
258
- baseURL,
259
- database,
260
- defaultClassification,
261
- defaultTimeout,
262
- getToken,
263
- onNetworkCall,
264
- pickSources,
265
- sources
266
- ]
267
- );
268
- const bulkEnrich = useCallback(
269
- async (bulkRequest, _options) => {
270
- const _sources = (pickSources == null ? void 0 : pickSources(sources, availableSources, bulkRequest)) ?? sources;
271
- const options = {
272
- timeout: defaultTimeout,
273
- includeRaw: false,
274
- noCache: false,
275
- classification: defaultClassification,
276
- sources: _sources,
277
- ..._options
278
- };
279
- const headers = {};
280
- const token = getToken == null ? void 0 : getToken();
281
- if (token) {
282
- headers.Authorization = `Bearer ${token}`;
283
- }
284
- let requestConfig = { baseURL, headers };
285
- if (onNetworkCall) {
286
- requestConfig = onNetworkCall(requestConfig);
287
- }
288
- const statuses = [];
289
- for (const selector of bulkRequest) {
290
- const query = { type: selector.type, value: selector.value, classification: options.classification };
291
- let statusRecord = await database.status.findOne({
292
- selector: query
293
- }).incrementalPatch({
294
- status: "in-progress"
295
- });
296
- if (!statusRecord) {
297
- statusRecord = await database.status.insert({
298
- id: v4(),
299
- ...query,
300
- status: "in-progress",
301
- sources: options.sources
302
- });
303
- }
304
- statuses.push(statusRecord.toMutableJSON());
305
- }
306
- try {
307
- const result = await post(bulkRequest, options.sources, options, requestConfig);
308
- const entries = Object.values(result).flatMap(Object.values).flatMap(Object.values);
309
- await _addEntries(entries);
310
- return result;
311
- } catch (e) {
312
- console.error(e);
313
- return {};
314
- } finally {
315
- database.status.bulkUpsert(
316
- uniqBy(statuses, (_record) => _record.id).map((record) => {
317
- record.status = "complete";
318
- return record;
319
- })
320
- );
321
- }
322
- },
323
- [
324
- pickSources,
325
- sources,
326
- availableSources,
327
- defaultTimeout,
328
- defaultClassification,
329
- getToken,
330
- baseURL,
331
- onNetworkCall,
332
- database,
333
- _addEntries
334
- ]
335
- );
336
- const enrichFailedEnrichments = useCallback(async () => {
337
- if (!(database == null ? void 0 : database.selectors) || database.selectors.closed) {
338
- return;
339
- }
340
- const failedEnrichments = await database.selectors.find({ selector: { error: { $exists: true } } }).exec();
341
- const byClassification = groupBy(failedEnrichments, "classification");
342
- const newRequests = [];
343
- for (const [classification, selectors] of Object.entries(byClassification)) {
344
- const bySelector = groupBy(selectors, (_selector) => `${_selector.type}:${_selector.value}`);
345
- Object.values(bySelector).forEach((records) => {
346
- newRequests.push({
347
- id: v4(),
348
- type: records[0].type,
349
- value: records[0].value,
350
- classification,
351
- sources: uniq(records.map((_record) => _record.source)).sort(),
352
- status: "pending"
353
- });
354
- });
355
- }
356
- await database.status.bulkInsert(newRequests);
357
- await database.selectors.bulkRemove(failedEnrichments);
358
- }, [database]);
359
- const enrichQueued = useMemo(
360
- () => debounce(
361
- async () => {
362
- if (!(database == null ? void 0 : database.status)) {
363
- return;
364
- } else if (database.status.closed) {
365
- console.warn("Status database is closed, will not enrich");
366
- return;
367
- }
368
- const selectors = await database.status.find({ selector: { status: "pending" } }).update({ $set: { status: "in-progress" } });
369
- if (selectors.length < 1) {
370
- return;
371
- }
372
- const chunks = chunk(selectors, chunkSize);
373
- clueDebugLogger(
374
- `Enriching ${selectors.length} selectors in ${chunks.length} chunks of ${chunkSize}.`,
375
- debugLogging
376
- );
377
- await Promise.all(
378
- // For performance reasons, we chunk the requests. This will allow us to take advantage of parellelization in the
379
- // backend, both on the pod level and kubernetes level
380
- chunks.map(async (reqsChunk) => {
381
- let _interval = null;
382
- if (runningRequestCount.current <= maxRequestCount) {
383
- runningRequestCount.current += 1;
384
- } else {
385
- let startOfWait = Date.now();
386
- await new Promise((res) => {
387
- _interval = setInterval(() => {
388
- clueDebugLogger(
389
- `Waiting on ${runningRequestCount.current} existing requests to complete (total delay: ${Date.now() - startOfWait}ms)`,
390
- debugLogging
391
- );
392
- if (runningRequestCount.current < maxRequestCount) {
393
- res();
394
- }
395
- }, 400);
396
- }).finally(() => {
397
- runningRequestCount.current += 1;
398
- clearInterval(_interval);
399
- });
400
- }
401
- try {
402
- const options = {};
403
- const _sources = uniq(reqsChunk.flatMap((record) => record.sources ?? []));
404
- if (_sources.length > 0) {
405
- options.sources = _sources;
406
- }
407
- await bulkEnrich(
408
- reqsChunk.map((record) => record.toSelector()),
409
- options
410
- );
411
- await database.status.findByIds(reqsChunk.map((selector) => selector.id)).update({ $set: { status: "complete" } });
412
- } catch (e) {
413
- console.error(e);
414
- } finally {
415
- runningRequestCount.current -= 1;
416
- if (_interval) {
417
- clearInterval(_interval);
418
- }
419
- }
420
- })
421
- );
422
- },
423
- 200,
424
- { maxWait: 500, leading: false }
425
- ),
426
- [bulkEnrich, chunkSize, database, debugLogging, maxRequestCount]
427
- );
428
- useEffect(() => {
429
- {
430
- return;
431
- }
432
- }, [database, debugLogging]);
433
- useEffect(() => {
434
- if (!enabled || !isReady || !(database == null ? void 0 : database.status)) {
435
- return;
436
- }
437
- if (database == null ? void 0 : database.status.closed) {
438
- console.warn("Status collection is closed");
439
- return;
440
- }
441
- const observer = database.status.find({
442
- selector: {
443
- status: "pending"
444
- }
445
- }).$.subscribe(() => enrichQueued());
446
- return () => {
447
- try {
448
- observer == null ? void 0 : observer.unsubscribe();
449
- } catch (e) {
450
- console.warn(e);
451
- }
452
- };
453
- }, [enabled, isReady, database, debugLogging, enrichQueued, (_d = database == null ? void 0 : database.status) == null ? void 0 : _d.closed]);
454
- const queueEnrich = useCallback(
455
- async (type, value2, classification) => {
456
- if (!type) {
457
- throw new Error("Type cannot be null");
458
- }
459
- if (!value2) {
460
- throw new Error("Value cannot be null");
461
- }
462
- const query = { type, value: value2, classification: classification ?? defaultClassification };
463
- let statusRecord = await database.status.findOne({
464
- selector: query
465
- }).exec();
466
- if (!statusRecord) {
467
- statusRecord = await database.status.queueInsert({
468
- id: v4(),
469
- ...query,
470
- status: "pending"
471
- });
472
- }
473
- return statusRecord;
474
- },
475
- [defaultClassification, database]
476
- );
477
- const guessType = useCallback(
478
- (value2) => {
479
- var _a2, _b2;
480
- if (!value2) {
481
- return null;
482
- }
483
- const types = Object.entries(typesDetection);
484
- const regularCheck = (_a2 = types.find(([_type, _regexp]) => _regexp.exec(value2))) == null ? void 0 : _a2[0];
485
- if (regularCheck) {
486
- return regularCheck;
487
- }
488
- const lowercased = value2.toLowerCase();
489
- const lowercaseCheck = (_b2 = types.find(([_type, _regexp]) => _regexp.exec(lowercased))) == null ? void 0 : _b2[0];
490
- if (lowercaseCheck) {
491
- return lowercaseCheck;
492
- }
493
- return null;
494
- },
495
- [typesDetection]
496
- );
497
- const value = useMemo(
498
- () => {
499
- var _a2;
500
- return {
501
- bulkEnrich,
502
- enrich,
503
- enrichFailedEnrichments,
504
- sources,
505
- setSources,
506
- typesDetection,
507
- supportedTypes,
508
- availableSources,
509
- guessType,
510
- queueEnrich,
511
- setCustomIconify,
512
- setDefaultClassification,
513
- setReady: setIsReady,
514
- defaultClassification,
515
- ready: isReady && !!database && !!((_a2 = clueConfig.config) == null ? void 0 : _a2.c12nDef)
516
- };
517
- },
518
- [
519
- bulkEnrich,
520
- enrich,
521
- enrichFailedEnrichments,
522
- sources,
523
- typesDetection,
524
- supportedTypes,
525
- availableSources,
526
- guessType,
527
- queueEnrich,
528
- setDefaultClassification,
529
- defaultClassification,
530
- isReady,
531
- database,
532
- (_e = clueConfig.config) == null ? void 0 : _e.c12nDef
533
- ]
534
- );
535
- return /* @__PURE__ */ jsx(ClueEnrichContext.Provider, { value, children });
536
- };
537
- export {
538
- ClueEnrichContext as C,
539
- ClueEnrichProvider as a,
540
- uniqBy as u
541
- };
@@ -1,9 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { memo } from "react";
3
- const FlexOne = ({ children = null }) => {
4
- return /* @__PURE__ */ jsx("div", { style: { flex: 1 }, children });
5
- };
6
- const FlexOne$1 = memo(FlexOne);
7
- export {
8
- FlexOne$1 as F
9
- };