@cccsaurora/clue-ui 1.2.0-dev.254 → 1.2.0

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 (179) hide show
  1. package/ActionForm-pWyIi01Z.js +4460 -0
  2. package/AnnotationDetails-11P7yhyx.js +160 -0
  3. package/AnnotationPreview-BGqlBBcp.js +140 -0
  4. package/ClueEnrichContext-DDZf646J.js +418 -0
  5. package/FlexOne-BXWFOd1T.js +6 -0
  6. package/_MapCache-BiTi0iqu.js +180 -0
  7. package/_Uint8Array-TJBs9NS2.js +101 -0
  8. package/_baseAssignValue-CNMLQZco.js +20 -0
  9. package/_baseClone-DajKHDCs.js +207 -0
  10. package/_baseExtremum-DhV10dXG.js +27 -0
  11. package/_baseFlatten-C8CjmqQ-.js +72 -0
  12. package/_baseGet-DSZygzyq.js +79 -0
  13. package/_baseIsEqual-C08cUUpA.js +147 -0
  14. package/_baseIteratee-DGZdhdqr.js +95 -0
  15. package/_baseSlice-M5RKzt1A.js +10 -0
  16. package/_baseSum-wEbgNeUs.js +10 -0
  17. package/_baseUniq-CGlHphLr.js +79 -0
  18. package/_commonjsHelpers-DaMA6jEr.js +8 -0
  19. package/_createAggregator-BvcoTZto.js +53 -0
  20. package/_getPrototype-Dm06JiGv.js +5 -0
  21. package/_getTag-Cfxlub3L.js +90 -0
  22. package/_setToArray-C7yMOeww.js +29 -0
  23. package/cloneDeep-wjl3XmFj.js +8 -0
  24. package/components/AnnotationBody.js +35 -49
  25. package/components/AnnotationDetailPopover.js +30 -36
  26. package/components/AnnotationDetails.js +7 -7
  27. package/components/AnnotationEntry.js +35 -35
  28. package/components/AnnotationPreview.js +5 -5
  29. package/components/ClassificationChip.js +23 -44
  30. package/components/CountBadge.js +26 -31
  31. package/components/EnrichedCard.js +97 -110
  32. package/components/EnrichedChip.js +105 -130
  33. package/components/EnrichedTypography.js +107 -133
  34. package/components/ErrorBoundary.js +24 -28
  35. package/components/RetryFailedEnrichments.js +9 -10
  36. package/components/SourcePicker.js +49 -57
  37. package/components/actions/ActionForm.js +4 -4
  38. package/components/actions/ExecutePopover.js +59 -75
  39. package/components/actions/ResultModal.js +4 -4
  40. package/components/actions/form/schemaAdapter.js +23 -39
  41. package/components/actions/formats/FileResult.js +59 -86
  42. package/components/actions/formats/index.js +10 -21
  43. package/components/display/graph/ExpandMoreButton.js +10 -10
  44. package/components/display/graph/elements/NodeCard.js +91 -111
  45. package/components/display/graph/elements/NodeTag.js +13 -15
  46. package/components/display/graph/index.js +202 -261
  47. package/components/display/graph/visualizations/Leaf.js +69 -88
  48. package/components/display/graph/visualizations/cloud/index.js +81 -98
  49. package/components/display/graph/visualizations/icons/BaseIcon.js +21 -26
  50. package/components/display/graph/visualizations/icons/BugIcon.js +12 -12
  51. package/components/display/graph/visualizations/icons/HostIcon.js +12 -12
  52. package/components/display/graph/visualizations/icons/NetworkIcon.js +12 -12
  53. package/components/display/graph/visualizations/icons/ProcessIcon.js +12 -12
  54. package/components/display/graph/visualizations/icons/TargetIcon.js +13 -13
  55. package/components/display/graph/visualizations/icons/index.js +13 -14
  56. package/components/display/graph/visualizations/panels/NodePanel.js +8 -10
  57. package/components/display/graph/visualizations/tree/BundleLine.js +81 -108
  58. package/components/display/graph/visualizations/tree/Triangle.js +13 -13
  59. package/components/display/graph/visualizations/tree/index.js +305 -407
  60. package/components/display/icons/Iconified.js +12 -27
  61. package/components/display/json/index.js +4 -4
  62. package/components/display/markdown/index.js +5770 -8678
  63. package/components/enrichment/EnrichPopover.js +46 -54
  64. package/components/fetchers/Fetcher.js +117 -155
  65. package/components/fetchers/PreviewModal.js +17 -20
  66. package/components/fetchers/StatusChip.js +17 -21
  67. package/components/group/Entry.js +11 -13
  68. package/components/group/Group.js +10 -13
  69. package/components/group/GroupControl.js +65 -76
  70. package/components/stats/QueryStatus.js +33 -43
  71. package/countBy-pIyxNZhO.js +8 -0
  72. package/data/event.js +4 -6
  73. package/database/index.js +2 -2
  74. package/debounce-DryYcbJ4.js +56 -0
  75. package/get-CH7kz5Ix.js +8 -0
  76. package/groupBy-yNrpdipq.js +8 -0
  77. package/hooks/ClueActionContext.js +6 -6
  78. package/hooks/ClueComponentContext.js +23 -29
  79. package/hooks/ClueConfigProvider.js +12 -14
  80. package/hooks/ClueDatabaseContext.js +13 -19
  81. package/hooks/ClueEnrichContext.js +8 -8
  82. package/hooks/ClueFetcherContext.js +56 -83
  83. package/hooks/ClueGroupContext.js +14 -17
  84. package/hooks/CluePopupContext.js +5 -5
  85. package/hooks/ClueProvider.js +10 -12
  86. package/hooks/selectors.js +7 -7
  87. package/hooks/useActionResult.js +2 -2
  88. package/hooks/useAnnotations.js +31 -47
  89. package/hooks/useClue.js +4 -6
  90. package/hooks/useClueActions.js +3 -3
  91. package/hooks/useClueConfig.js +4 -6
  92. package/hooks/useClueTypeConfig.js +3 -3
  93. package/hooks/useComparator.js +435 -722
  94. package/hooks/useErrors.js +18 -22
  95. package/hooks/useFetcherResult.js +24 -33
  96. package/hooks/useMyHighlights.js +36 -66
  97. package/hooks/useMyLocalStorage.js +37 -66
  98. package/iconify-BBckr5AQ.js +1263 -0
  99. package/icons/Action.js +49 -66
  100. package/icons/Assessment.js +68 -84
  101. package/icons/Context.js +63 -77
  102. package/icons/Opinion.js +65 -77
  103. package/icons/iconMap.js +2 -2
  104. package/identity-ByMq8VxU.js +6 -0
  105. package/index-BHAe_V9n.js +12768 -0
  106. package/index-CA5CUNZO.js +975 -0
  107. package/index-D_ZywK71.js +358 -0
  108. package/index-Dj5C04IX.js +568 -0
  109. package/index-p5_wX7q1.js +11729 -0
  110. package/isNil-CjWwlQS3.js +6 -0
  111. package/isObject-B53jY8Qg.js +7 -0
  112. package/isObjectLike-BatpeCIi.js +29 -0
  113. package/isSymbol-C3_SC0Qp.js +8 -0
  114. package/last-7CdUxN0r.js +7 -0
  115. package/main.js +60 -60
  116. package/package.json +1 -1
  117. package/sortBy-0BpKRt8p.js +79 -0
  118. package/sumBy-Do6Ff4Bw.js +8 -0
  119. package/text/Frequency.js +23 -42
  120. package/toFinite-BMy6GObD.js +14 -0
  121. package/toNumber-YVhnnJv4.js +31 -0
  122. package/useClueTypeConfig-77zd_zdF.js +2292 -0
  123. package/utils/chain.js +64 -91
  124. package/utils/classificationParser.js +256 -519
  125. package/utils/constants.js +10 -35
  126. package/utils/graph.js +45 -72
  127. package/utils/hashUtil.js +7 -7
  128. package/utils/line.js +81 -131
  129. package/utils/loggerUtil.js +3 -5
  130. package/utils/sessionStorage.js +27 -41
  131. package/utils/time.js +423 -423
  132. package/utils/utils.js +9 -9
  133. package/utils/window.js +10 -21
  134. package/utils-D5hPDE7N.js +129 -0
  135. package/ActionForm-C0aE9HUv.js +0 -5941
  136. package/AnnotationDetails-CEou0vCc.js +0 -175
  137. package/AnnotationPreview-CLMVD6Ec.js +0 -188
  138. package/ClueEnrichContext-BkD9ZwM9.js +0 -541
  139. package/FlexOne-BSYAhhtG.js +0 -9
  140. package/_MapCache-WmuDdwuH.js +0 -222
  141. package/_Uint8Array-DdG4KLKn.js +0 -128
  142. package/_baseAssignValue-CGTuELqU.js +0 -25
  143. package/_baseClone-BpWiBnMp.js +0 -283
  144. package/_baseExtremum-BY663UjY.js +0 -33
  145. package/_baseFlatten-B69cDsaV.js +0 -92
  146. package/_baseGet-Bx3A4Qfp.js +0 -108
  147. package/_baseIsEqual-B4IufFlL.js +0 -208
  148. package/_baseIteratee-7AQvAy1o.js +0 -126
  149. package/_baseSlice-GAv_YFTT.js +0 -20
  150. package/_baseSum-D0WC1dN0.js +0 -13
  151. package/_baseUniq-B8fK6hI-.js +0 -115
  152. package/_commonjsHelpers-DWwsNxpa.js +0 -8
  153. package/_createAggregator-CwGPThny.js +0 -63
  154. package/_getPrototype-CblfEidB.js +0 -5
  155. package/_getTag-jwz4XLoZ.js +0 -126
  156. package/_setToArray-CaPKQhcz.js +0 -33
  157. package/cloneDeep-DmUylbkM.js +0 -8
  158. package/countBy-DqlU5OwT.js +0 -14
  159. package/debounce-bV0h5FC5.js +0 -92
  160. package/get-DSsNkRQs.js +0 -8
  161. package/groupBy-ChDRT7uy.js +0 -14
  162. package/iconify-CXMreGTg.js +0 -1782
  163. package/identity-CPGTqrE4.js +0 -6
  164. package/index-AMfoEg_6.js +0 -696
  165. package/index-B6C2a_Lg.js +0 -1172
  166. package/index-C12gPw2W.js +0 -17698
  167. package/index-DCKkHTvx.js +0 -15750
  168. package/index-UkW8Sur3.js +0 -465
  169. package/isNil-CIubwp4T.js +0 -6
  170. package/isObject-FTY-5JQX.js +0 -7
  171. package/isObjectLike-OAgjjZye.js +0 -48
  172. package/isSymbol-Xd2FsJyp.js +0 -8
  173. package/last-CUCl67Im.js +0 -7
  174. package/sortBy-C7mGPI_D.js +0 -100
  175. package/sumBy-CGALjmwQ.js +0 -8
  176. package/toFinite-Bc55msYj.js +0 -16
  177. package/toNumber-DPxy1FBy.js +0 -39
  178. package/useClueTypeConfig-D2tf4-NM.js +0 -3289
  179. package/utils-71DpzFrA.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-D2tf4-NM.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-ChDRT7uy.js";
9
- import { b as baseIteratee } from "./_baseIteratee-7AQvAy1o.js";
10
- import { b as baseUniq } from "./_baseUniq-B8fK6hI-.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
- };