@jsb188/app 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +17 -6
- package/src/constants/agent.ts +44 -57
- package/src/constants/app.ts +43 -0
- package/src/constants/wsActions.ts +1 -15
- package/src/i18n/account.ts +1 -1
- package/src/i18n/agent.ts +321 -96
- package/src/i18n/agentToolBusiness.ts +340 -0
- package/src/i18n/agentToolGrid.ts +121 -0
- package/src/i18n/agentToolWorkflow.ts +101 -0
- package/src/i18n/agent_note.ts +110 -0
- package/src/i18n/app.ts +23 -17
- package/src/i18n/auth.ts +25 -30
- package/src/i18n/billing.ts +3 -85
- package/src/i18n/c.ts +953 -0
- package/src/i18n/campaign.ts +164 -211
- package/src/i18n/datetime.ts +6 -0
- package/src/i18n/editor.ts +56 -0
- package/src/i18n/email_outreach_editor.ts +526 -0
- package/src/i18n/error.ts +430 -202
- package/src/i18n/field_doc_editor.ts +21 -0
- package/src/i18n/field_doc_programs.ts +51 -0
- package/src/i18n/field_docs.ts +171 -8
- package/src/i18n/form.ts +7 -491
- package/src/i18n/index.ts +23 -3
- package/src/i18n/log.ts +234 -39
- package/src/i18n/memory.ts +18 -5
- package/src/i18n/message.ts +1 -0
- package/src/i18n/note.ts +5 -3
- package/src/i18n/org.ts +97 -45
- package/src/i18n/schedule.ts +133 -0
- package/src/i18n/sheet.ts +105 -161
- package/src/i18n/sheet_formula.ts +165 -0
- package/src/i18n/workflow.ts +112 -11
- package/src/main.ts +2 -2
- package/src/platform.ts +89 -49
- package/src/types/ai.d.ts +16 -1
- package/src/types/app.d.ts +29 -73
- package/src/types/auth.d.ts +1 -1
- package/src/types/other.d.ts +8 -1
- package/src/utils/api.ts +60 -10
- package/src/utils/clientIP.ts +213 -0
- package/src/utils/color.ts +95 -0
- package/src/utils/csv.ts +19 -0
- package/src/utils/datetime.ts +207 -31
- package/src/utils/deferredSave.ts +89 -0
- package/src/utils/email.ts +50 -0
- package/src/utils/expression.helpers.ts +470 -0
- package/src/utils/expression.ts +1633 -239
- package/src/utils/language.ts +9 -0
- package/src/utils/logic.ts +9 -162
- package/src/utils/number.ts +30 -11
- package/src/utils/object.ts +69 -127
- package/src/utils/promise.ts +78 -7
- package/src/utils/queryReset.ts +110 -61
- package/src/utils/string.ts +80 -143
- package/src/utils/url_client.ts +115 -15
- package/src/constants/billing.ts +0 -146
- package/src/i18n/agentDoc.ts +0 -110
- package/src/types/form.d.ts +0 -101
- package/src/utils/billing.ts +0 -141
- package/src/utils/managedSessionBff.test.ts +0 -60
- package/src/utils/string.test.ts +0 -293
- package/tsconfig.json +0 -12
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SUPPORTED_LOG_LANGUAGES, type SupportedLogLanguage } from '../constants/app.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Resolve a supported log language to its canonical locale key without losing script subtags.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeLogLanguage(value: unknown): SupportedLogLanguage | null {
|
|
7
|
+
const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
8
|
+
return SUPPORTED_LOG_LANGUAGES.find((language) => language.toLowerCase() === normalized) ?? null;
|
|
9
|
+
}
|
package/src/utils/logic.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d.ts';
|
|
2
|
-
import { isFutureCalDate, isValidCalDate } from './datetime.ts';
|
|
3
1
|
import { sortObjectByKeys, stringifyJSON } from './object.ts';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -16,13 +14,6 @@ type DatabaseActionResult = {
|
|
|
16
14
|
const COMPACT_CACHE_KEY_SEGMENT_BYTE_LIMIT = 1800;
|
|
17
15
|
const UTF8_ENCODER = new TextEncoder();
|
|
18
16
|
|
|
19
|
-
export interface GetFiltersFromURLResult {
|
|
20
|
-
filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'> | null;
|
|
21
|
-
sort: string | null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type FilterOptionURLMode = 'INDEXED' | 'KEYS';
|
|
25
|
-
|
|
26
17
|
/**
|
|
27
18
|
* Check if database document needs an update, insert, or do nothing based on the user API arguments
|
|
28
19
|
* NOTE: There is a copy paste of this function in @jsb188/react/utils/hooks.ts
|
|
@@ -176,159 +167,6 @@ export function createThrottledInvoke<T extends any[]>(
|
|
|
176
167
|
return { invoke, cancel };
|
|
177
168
|
}
|
|
178
169
|
|
|
179
|
-
/**
|
|
180
|
-
* Convert an indexed bit-string into a list of selected values.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
function getIndexedValues(value: string | null, options?: string[]) {
|
|
184
|
-
if (!value || !options?.length) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const selectedValues = options
|
|
189
|
-
.map((option, i) => {
|
|
190
|
-
return value.charAt(i) === '1' ? option : null;
|
|
191
|
-
})
|
|
192
|
-
.filter(Boolean) as string[];
|
|
193
|
-
|
|
194
|
-
return selectedValues.length ? selectedValues : null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Convert a comma-separated filter value into validated stable option keys.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
function getKeyValues(value: string | null, options?: string[]) {
|
|
202
|
-
if (!value || !options?.length) {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const optionSet = new Set(options);
|
|
207
|
-
const selectedValues = Array.from(
|
|
208
|
-
new Set(
|
|
209
|
-
value
|
|
210
|
-
.split(',')
|
|
211
|
-
.map((option) => option.trim())
|
|
212
|
-
.filter((option) => optionSet.has(option)),
|
|
213
|
-
),
|
|
214
|
-
).sort();
|
|
215
|
-
|
|
216
|
-
return selectedValues.length ? selectedValues : null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Parse one filter search-param using either the legacy indexed encoding or
|
|
221
|
-
* stable literal registry keys.
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
function getFilterOptionValues(
|
|
225
|
-
value: string | null,
|
|
226
|
-
options?: string[],
|
|
227
|
-
optionURLMode: FilterOptionURLMode = 'INDEXED',
|
|
228
|
-
) {
|
|
229
|
-
return optionURLMode === 'KEYS'
|
|
230
|
-
? getKeyValues(value, options)
|
|
231
|
-
: getIndexedValues(value, options);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Check whether a URL search-param value is a serialized generic ID.
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
export function isValidGenericIdSearchParam(
|
|
239
|
-
value?: string | number | bigint | null,
|
|
240
|
-
) {
|
|
241
|
-
if (!value) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const stringValue = String(value);
|
|
246
|
-
return stringValue !== '0' && /^\d+$/.test(stringValue);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Validate parsed URL filters using the same date and timezone rules as the logs filter schema.
|
|
251
|
-
*/
|
|
252
|
-
|
|
253
|
-
function parsedFilterIsValid(
|
|
254
|
-
filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'>,
|
|
255
|
-
) {
|
|
256
|
-
if (!isValidGenericIdSearchParam(filter.siteId)) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (filter.startDate) {
|
|
261
|
-
if (!isValidCalDate(filter.startDate)) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (filter.endDate && !isValidCalDate(filter.endDate)) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (filter.endDate && !filter.startDate) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Parse legacy indexed or registry-key filters and sort values from URL
|
|
279
|
-
* search params without including operation in the output.
|
|
280
|
-
*/
|
|
281
|
-
|
|
282
|
-
export function getFiltersFromURL(
|
|
283
|
-
searchQuery: string,
|
|
284
|
-
sortOptions?: string[],
|
|
285
|
-
types?: string[],
|
|
286
|
-
activities?: string[],
|
|
287
|
-
optionURLMode: FilterOptionURLMode = 'INDEXED',
|
|
288
|
-
): GetFiltersFromURLResult {
|
|
289
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
290
|
-
|
|
291
|
-
let startDate = urlParams.get('sd');
|
|
292
|
-
let endDate = urlParams.get('ed');
|
|
293
|
-
if (startDate && !endDate) {
|
|
294
|
-
endDate = startDate;
|
|
295
|
-
} else if (endDate && !startDate) {
|
|
296
|
-
startDate = endDate;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'> = {
|
|
300
|
-
siteId: urlParams.get('sid') || null,
|
|
301
|
-
types: getFilterOptionValues(
|
|
302
|
-
urlParams.get('t'),
|
|
303
|
-
types,
|
|
304
|
-
optionURLMode,
|
|
305
|
-
) as FilterLogEntriesArgs['types'],
|
|
306
|
-
activities: getFilterOptionValues(
|
|
307
|
-
urlParams.get('a'),
|
|
308
|
-
activities,
|
|
309
|
-
optionURLMode,
|
|
310
|
-
) as FilterLogEntriesArgs['activities'],
|
|
311
|
-
startDate,
|
|
312
|
-
endDate,
|
|
313
|
-
query: urlParams.get('q') || '',
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const sortIndex = urlParams.get('s');
|
|
317
|
-
const sort = sortOptions?.[Number(sortIndex) - 1] || null;
|
|
318
|
-
|
|
319
|
-
if (!parsedFilterIsValid(filter)) {
|
|
320
|
-
return {
|
|
321
|
-
filter: null,
|
|
322
|
-
sort,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return {
|
|
327
|
-
filter,
|
|
328
|
-
sort,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
170
|
/**
|
|
333
171
|
* Promise with timeout
|
|
334
172
|
*/
|
|
@@ -379,6 +217,15 @@ function getStableVariablesKeyValue(value: any): any {
|
|
|
379
217
|
return value;
|
|
380
218
|
}
|
|
381
219
|
|
|
220
|
+
/*
|
|
221
|
+
* Key GraphQL variables exactly as JSON sends them: preserve case, scalar
|
|
222
|
+
* types, null and empty strings, omit undefined, and sort object keys. The
|
|
223
|
+
* prefix distinguishes this format from legacy delimiter-based cache keys.
|
|
224
|
+
*/
|
|
225
|
+
export function makeGraphQLVariablesKey(variables?: Record<string, any> | null): string {
|
|
226
|
+
return '@' + JSON.stringify(getStableVariablesKeyValue(variables || {}));
|
|
227
|
+
}
|
|
228
|
+
|
|
382
229
|
/*
|
|
383
230
|
* Return a compact deterministic hash for a cache key segment.
|
|
384
231
|
*/
|
package/src/utils/number.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scale dimensions proportionally to fit inside the provided bounds.
|
|
3
|
+
*/
|
|
4
|
+
export function getContainedDimensions(
|
|
5
|
+
width: number,
|
|
6
|
+
height: number,
|
|
7
|
+
maxWidth: number,
|
|
8
|
+
maxHeight: number,
|
|
9
|
+
) {
|
|
10
|
+
if (
|
|
11
|
+
!Number.isFinite(width) ||
|
|
12
|
+
!Number.isFinite(height) ||
|
|
13
|
+
!Number.isFinite(maxWidth) ||
|
|
14
|
+
!Number.isFinite(maxHeight) ||
|
|
15
|
+
width <= 0 ||
|
|
16
|
+
height <= 0 ||
|
|
17
|
+
maxWidth <= 0 ||
|
|
18
|
+
maxHeight <= 0
|
|
19
|
+
) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const scale = Math.min(maxWidth / width, maxHeight / height);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
width: Math.round(width * scale),
|
|
27
|
+
height: Math.round(height * scale),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
1
31
|
/**
|
|
2
32
|
* Convert string value to BigInt safely
|
|
3
33
|
*/
|
|
@@ -137,17 +167,6 @@ export function secondsToTime(secs: number) {
|
|
|
137
167
|
};
|
|
138
168
|
}
|
|
139
169
|
|
|
140
|
-
/**
|
|
141
|
-
* Get percentage between 2 values
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
export function calculateDiscount(
|
|
145
|
-
normalPrice: number,
|
|
146
|
-
discountedPrice: number,
|
|
147
|
-
) {
|
|
148
|
-
return Math.round(((normalPrice - discountedPrice) / normalPrice) * 100);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
170
|
/**
|
|
152
171
|
* Format decimal number to a string without decimal places or the first non-zero digit
|
|
153
172
|
*
|
package/src/utils/object.ts
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* Filter array and return only unique values
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export function uniq(
|
|
6
|
-
arr: Array<any>,
|
|
7
|
-
fn?: (value: any, index: number, self: Array<any>) => boolean,
|
|
8
|
-
) {
|
|
5
|
+
export function uniq(arr: Array<any>, fn?: (value: any, index: number, self: Array<any>) => boolean) {
|
|
9
6
|
return arr.filter((value, index, self) => {
|
|
10
7
|
return self.indexOf(value) === index && (!fn || fn(value, index, self));
|
|
11
8
|
});
|
|
@@ -32,18 +29,10 @@ export function uniq(
|
|
|
32
29
|
* Remove undefined (and/or null) values from an object
|
|
33
30
|
*/
|
|
34
31
|
|
|
35
|
-
export function removeUndefined<T>(
|
|
36
|
-
obj: T,
|
|
37
|
-
removeNull?: boolean,
|
|
38
|
-
removeFalsy?: boolean,
|
|
39
|
-
): T {
|
|
32
|
+
export function removeUndefined<T>(obj: T, removeNull?: boolean, removeFalsy?: boolean): T {
|
|
40
33
|
for (const key in obj) {
|
|
41
34
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
-
if (
|
|
43
|
-
obj[key] === undefined ||
|
|
44
|
-
(removeNull && obj[key] === null) ||
|
|
45
|
-
(removeFalsy && !obj[key])
|
|
46
|
-
) {
|
|
35
|
+
if (obj[key] === undefined || (removeNull && obj[key] === null) || (removeFalsy && !obj[key])) {
|
|
47
36
|
delete obj[key];
|
|
48
37
|
} else if (obj[key] && typeof obj[key] === 'object') {
|
|
49
38
|
removeUndefined(obj[key], removeNull, removeFalsy);
|
|
@@ -163,11 +152,7 @@ export function normalizeArrayLikeValue<T = any>(value: unknown): T[] | null {
|
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
154
|
|
|
166
|
-
if (
|
|
167
|
-
arrayValue &&
|
|
168
|
-
typeof arrayValue === 'object' &&
|
|
169
|
-
!Array.isArray(arrayValue)
|
|
170
|
-
) {
|
|
155
|
+
if (arrayValue && typeof arrayValue === 'object' && !Array.isArray(arrayValue)) {
|
|
171
156
|
arrayValue = mapArrayLikeObjects(arrayValue);
|
|
172
157
|
}
|
|
173
158
|
|
|
@@ -179,36 +164,60 @@ export function normalizeArrayLikeValue<T = any>(value: unknown): T[] | null {
|
|
|
179
164
|
* conversion is the default; callers must opt into lossy number conversion.
|
|
180
165
|
*/
|
|
181
166
|
|
|
182
|
-
export function stringifyJSON(
|
|
183
|
-
obj: any,
|
|
184
|
-
preserveBigIntPrecision: boolean = true,
|
|
185
|
-
): string {
|
|
167
|
+
export function stringifyJSON(obj: any, preserveBigIntPrecision: boolean = true): string {
|
|
186
168
|
return JSON.stringify(obj, (_key, value) =>
|
|
187
|
-
typeof value === 'bigint'
|
|
188
|
-
? preserveBigIntPrecision
|
|
189
|
-
? value.toString()
|
|
190
|
-
: Number(value)
|
|
191
|
-
: value,
|
|
169
|
+
typeof value === 'bigint' ? (preserveBigIntPrecision ? value.toString() : Number(value)) : value,
|
|
192
170
|
);
|
|
193
171
|
}
|
|
194
172
|
|
|
195
173
|
/**
|
|
196
|
-
*
|
|
174
|
+
* Normalize a JSON-like value for order-insensitive serialization: object keys
|
|
175
|
+
* sorted by UTF-16 code unit (never by locale), array order kept, and BigInt
|
|
176
|
+
* and Date values converted to their JSON text forms.
|
|
197
177
|
*/
|
|
198
178
|
|
|
199
|
-
export function
|
|
200
|
-
if (
|
|
201
|
-
|
|
179
|
+
export function canonicalJSONValue(value: unknown): unknown {
|
|
180
|
+
if (typeof value === 'bigint') return String(value);
|
|
181
|
+
if (value instanceof Date) return value.toISOString();
|
|
182
|
+
if (Array.isArray(value)) return value.map(canonicalJSONValue);
|
|
183
|
+
if (value && typeof value === 'object') {
|
|
184
|
+
return Object.fromEntries(
|
|
185
|
+
Object.entries(value)
|
|
186
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
187
|
+
.map(([key, item]) => [key, canonicalJSONValue(item)]),
|
|
188
|
+
);
|
|
202
189
|
}
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Serialize JSON with sorted object keys (see canonicalJSONValue), so equal
|
|
195
|
+
* content always produces the same text regardless of property order.
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
export function stableJSONText(value: unknown): string {
|
|
199
|
+
return JSON.stringify(canonicalJSONValue(value));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Merge own object properties while excluding prototype-related keys at every merged level.
|
|
204
|
+
*/
|
|
203
205
|
|
|
206
|
+
export function mergeNestedObjects(obj1: any, obj2: any) {
|
|
204
207
|
const newObj = { ...obj1 };
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
208
|
+
delete newObj.__proto__;
|
|
209
|
+
delete newObj.constructor;
|
|
210
|
+
delete newObj.prototype;
|
|
211
|
+
|
|
212
|
+
for (const key of Object.keys(obj2 ?? {})) {
|
|
213
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (typeof obj2[key] === 'object' && obj2[key] !== null) {
|
|
217
|
+
const previousValue = obj1 && Object.prototype.hasOwnProperty.call(obj1, key) ? obj1[key] : undefined;
|
|
218
|
+
newObj[key] = mergeNestedObjects(previousValue, obj2[key]);
|
|
219
|
+
} else {
|
|
220
|
+
newObj[key] = obj2[key];
|
|
212
221
|
}
|
|
213
222
|
}
|
|
214
223
|
|
|
@@ -219,19 +228,11 @@ export function mergeNestedObjects(obj1: any, obj2: any) {
|
|
|
219
228
|
* Check if objects are equal
|
|
220
229
|
*/
|
|
221
230
|
|
|
222
|
-
export function areObjectsEqual(
|
|
223
|
-
obj1: any,
|
|
224
|
-
obj2: any,
|
|
225
|
-
isNested: boolean = false,
|
|
226
|
-
) {
|
|
231
|
+
export function areObjectsEqual(obj1: any, obj2: any, isNested: boolean = false) {
|
|
227
232
|
if (isNested) {
|
|
228
233
|
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
|
229
234
|
} else if (obj1 && obj2) {
|
|
230
|
-
return Object.keys(obj1).every(
|
|
231
|
-
(key: string) =>
|
|
232
|
-
Object.prototype.hasOwnProperty.call(obj2, key) &&
|
|
233
|
-
obj1[key] === obj2[key],
|
|
234
|
-
);
|
|
235
|
+
return Object.keys(obj1).every((key: string) => Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key]);
|
|
235
236
|
}
|
|
236
237
|
return obj1 === obj2;
|
|
237
238
|
}
|
|
@@ -240,11 +241,7 @@ export function areObjectsEqual(
|
|
|
240
241
|
* Order an array of objects by a key
|
|
241
242
|
*/
|
|
242
243
|
|
|
243
|
-
export function orderBy(
|
|
244
|
-
arr: Array<any>,
|
|
245
|
-
key: ((obj: any) => any) | string,
|
|
246
|
-
order: 'asc' | 'desc' = 'asc',
|
|
247
|
-
) {
|
|
244
|
+
export function orderBy(arr: Array<any>, key: ((obj: any) => any) | string, order: 'asc' | 'desc' = 'asc') {
|
|
248
245
|
const compareFn = (a: any, b: any) => {
|
|
249
246
|
const valueA = typeof key === 'function' ? key(a) : a[key];
|
|
250
247
|
const valueB = typeof key === 'function' ? key(b) : b[key];
|
|
@@ -311,11 +308,7 @@ export function randomItem(arr: Array<any>) {
|
|
|
311
308
|
* Rearrange an array left or right
|
|
312
309
|
*/
|
|
313
310
|
|
|
314
|
-
export function rearrangeArray(
|
|
315
|
-
arr: Array<any>,
|
|
316
|
-
loop: number = 1,
|
|
317
|
-
shiftRight?: boolean,
|
|
318
|
-
) {
|
|
311
|
+
export function rearrangeArray(arr: Array<any>, loop: number = 1, shiftRight?: boolean) {
|
|
319
312
|
if (shiftRight) {
|
|
320
313
|
for (let i = 0; i < loop; i++) {
|
|
321
314
|
arr.unshift(arr.pop());
|
|
@@ -340,10 +333,7 @@ export function get(object: any, path: string) {
|
|
|
340
333
|
* NOTE: Use this after Redis.hgetall()
|
|
341
334
|
*/
|
|
342
335
|
|
|
343
|
-
export function hgetZipObject(
|
|
344
|
-
arr: Array<string>,
|
|
345
|
-
mapperFn?: (value: string, index: number) => any,
|
|
346
|
-
) {
|
|
336
|
+
export function hgetZipObject(arr: Array<string>, mapperFn?: (value: string, index: number) => any) {
|
|
347
337
|
const obj: Record<string, any> = {};
|
|
348
338
|
for (let i = 0; i < arr.length; i += 2) {
|
|
349
339
|
if (mapperFn) {
|
|
@@ -372,10 +362,7 @@ export function zipObject(keys: Array<string>, values: Array<any>) {
|
|
|
372
362
|
* NOTE: Use this for best NodeJS and browser compatibility
|
|
373
363
|
*/
|
|
374
364
|
|
|
375
|
-
export function findLastIndex(
|
|
376
|
-
arr: Array<any>,
|
|
377
|
-
fn: (value: any, index: number, array: any[]) => boolean,
|
|
378
|
-
) {
|
|
365
|
+
export function findLastIndex(arr: Array<any>, fn: (value: any, index: number, array: any[]) => boolean) {
|
|
379
366
|
if (typeof arr.findLastIndex === 'function') {
|
|
380
367
|
return arr.findLastIndex(fn);
|
|
381
368
|
}
|
|
@@ -404,9 +391,7 @@ export function intersection(arr1: unknown, arr2: unknown) {
|
|
|
404
391
|
*/
|
|
405
392
|
|
|
406
393
|
export function toggleArrayValue<T>(arr: Array<T>, value: T): Array<T> {
|
|
407
|
-
return arr.includes(value)
|
|
408
|
-
? arr.filter((currentValue) => currentValue !== value)
|
|
409
|
-
: [...arr, value];
|
|
394
|
+
return arr.includes(value) ? arr.filter((currentValue) => currentValue !== value) : [...arr, value];
|
|
410
395
|
}
|
|
411
396
|
|
|
412
397
|
/**
|
|
@@ -451,10 +436,7 @@ export function groupCollections(
|
|
|
451
436
|
}
|
|
452
437
|
|
|
453
438
|
for (const key in obj) {
|
|
454
|
-
if (
|
|
455
|
-
!Object.prototype.hasOwnProperty.call(obj, key) ||
|
|
456
|
-
key.startsWith('__')
|
|
457
|
-
) {
|
|
439
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key) || key.startsWith('__')) {
|
|
458
440
|
continue;
|
|
459
441
|
}
|
|
460
442
|
|
|
@@ -470,11 +452,7 @@ export function groupCollections(
|
|
|
470
452
|
* Build a stable key for dedupe checks.
|
|
471
453
|
*/
|
|
472
454
|
|
|
473
|
-
function makeMergeKey(
|
|
474
|
-
obj: any,
|
|
475
|
-
pkFn?: (obj: any) => string,
|
|
476
|
-
pkName?: string,
|
|
477
|
-
): string | number | undefined {
|
|
455
|
+
function makeMergeKey(obj: any, pkFn?: (obj: any) => string, pkName?: string): string | number | undefined {
|
|
478
456
|
if (!obj) {
|
|
479
457
|
return undefined;
|
|
480
458
|
}
|
|
@@ -586,17 +564,11 @@ export function groupCollections(
|
|
|
586
564
|
}
|
|
587
565
|
return (
|
|
588
566
|
(o.id && o.id === innerObj.id) ||
|
|
589
|
-
(!o.id &&
|
|
590
|
-
Object.entries(o).flat().join('|') ===
|
|
591
|
-
Object.entries(innerObj).flat().join('|'))
|
|
567
|
+
(!o.id && Object.entries(o).flat().join('|') === Object.entries(innerObj).flat().join('|'))
|
|
592
568
|
);
|
|
593
569
|
})
|
|
594
570
|
) {
|
|
595
|
-
setObject(
|
|
596
|
-
acc[i],
|
|
597
|
-
name,
|
|
598
|
-
Array.isArray(ref) ? ref.concat(innerObj) : innerObj,
|
|
599
|
-
);
|
|
571
|
+
setObject(acc[i], name, Array.isArray(ref) ? ref.concat(innerObj) : innerObj);
|
|
600
572
|
}
|
|
601
573
|
|
|
602
574
|
// Old version, but this doesn't support merged array collections
|
|
@@ -629,15 +601,9 @@ export function groupCollections(
|
|
|
629
601
|
collections.forEach((obj) => {
|
|
630
602
|
const innerObj = getObject(obj, flatName);
|
|
631
603
|
const primaryKey = obj[primaryKeyName];
|
|
632
|
-
const i = groupedCollections.findIndex(
|
|
633
|
-
(o: any) => o[primaryKeyName] === primaryKey,
|
|
634
|
-
);
|
|
604
|
+
const i = groupedCollections.findIndex((o: any) => o[primaryKeyName] === primaryKey);
|
|
635
605
|
const innerParent = getObject(obj, beforeHash);
|
|
636
|
-
const innerParentId = makeMergeKey(
|
|
637
|
-
innerParent,
|
|
638
|
-
parentPKFn,
|
|
639
|
-
primaryKeyName,
|
|
640
|
-
);
|
|
606
|
+
const innerParentId = makeMergeKey(innerParent, parentPKFn, primaryKeyName);
|
|
641
607
|
|
|
642
608
|
if (!innerObj || !hasMeaningfulValue(innerObj)) {
|
|
643
609
|
return;
|
|
@@ -645,10 +611,7 @@ export function groupCollections(
|
|
|
645
611
|
|
|
646
612
|
if (innerParentId && i >= 0) {
|
|
647
613
|
const innerArr = getObject(groupedCollections[i], beforeHash) || [];
|
|
648
|
-
const j = innerArr.findIndex(
|
|
649
|
-
(o: any) =>
|
|
650
|
-
makeMergeKey(o, parentPKFn, primaryKeyName) === innerParentId,
|
|
651
|
-
);
|
|
614
|
+
const j = innerArr.findIndex((o: any) => makeMergeKey(o, parentPKFn, primaryKeyName) === innerParentId);
|
|
652
615
|
|
|
653
616
|
if (j >= 0) {
|
|
654
617
|
const currentValue = innerArr[j][afterHash];
|
|
@@ -658,17 +621,10 @@ export function groupCollections(
|
|
|
658
621
|
|
|
659
622
|
let newValue;
|
|
660
623
|
if (currentValueIsArray) {
|
|
661
|
-
if (
|
|
662
|
-
!currentValue.find(
|
|
663
|
-
(o) => makeMergeKey(o, childPKFn) === nextInnerObjKey,
|
|
664
|
-
)
|
|
665
|
-
) {
|
|
624
|
+
if (!currentValue.find((o) => makeMergeKey(o, childPKFn) === nextInnerObjKey)) {
|
|
666
625
|
newValue = currentValue.concat(innerObj);
|
|
667
626
|
}
|
|
668
|
-
} else if (
|
|
669
|
-
currentValue &&
|
|
670
|
-
makeMergeKey(currentValue, childPKFn) !== nextInnerObjKey
|
|
671
|
-
) {
|
|
627
|
+
} else if (currentValue && makeMergeKey(currentValue, childPKFn) !== nextInnerObjKey) {
|
|
672
628
|
newValue = [currentValue].concat(innerObj);
|
|
673
629
|
} else if (!currentValue) {
|
|
674
630
|
newValue = [innerObj];
|
|
@@ -722,10 +678,7 @@ export function groupCollections(
|
|
|
722
678
|
*/
|
|
723
679
|
|
|
724
680
|
export function cloneArrayLike(obj: any) {
|
|
725
|
-
if (
|
|
726
|
-
!Array.isArray(obj) &&
|
|
727
|
-
Object.keys(obj).every((key, i) => key === i.toString())
|
|
728
|
-
) {
|
|
681
|
+
if (!Array.isArray(obj) && Object.keys(obj).every((key, i) => key === i.toString())) {
|
|
729
682
|
return Object.values(obj);
|
|
730
683
|
}
|
|
731
684
|
return { ...obj };
|
|
@@ -740,12 +693,7 @@ export function cloneArrayLike(obj: any) {
|
|
|
740
693
|
*/
|
|
741
694
|
|
|
742
695
|
export function mapArrayLikeObjects(obj: any) {
|
|
743
|
-
if (
|
|
744
|
-
!Array.isArray(obj) &&
|
|
745
|
-
obj !== null &&
|
|
746
|
-
typeof obj === 'object' &&
|
|
747
|
-
Object.keys(obj).every((key, i) => key === i.toString())
|
|
748
|
-
) {
|
|
696
|
+
if (!Array.isArray(obj) && obj !== null && typeof obj === 'object' && Object.keys(obj).every((key, i) => key === i.toString())) {
|
|
749
697
|
return Object.values(obj);
|
|
750
698
|
}
|
|
751
699
|
return obj;
|
|
@@ -819,9 +767,7 @@ export function setObject(obj: any, path: string, value: any): any {
|
|
|
819
767
|
return obj;
|
|
820
768
|
}
|
|
821
769
|
const keys = path.split('.');
|
|
822
|
-
if (
|
|
823
|
-
keys.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))
|
|
824
|
-
) {
|
|
770
|
+
if (keys.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))) {
|
|
825
771
|
return obj;
|
|
826
772
|
}
|
|
827
773
|
const lastKey = keys.pop();
|
|
@@ -836,9 +782,7 @@ export function setObject(obj: any, path: string, value: any): any {
|
|
|
836
782
|
if (typeof nestedObj === 'object' && nestedObj !== null) {
|
|
837
783
|
nestedObj[lastKey] = value;
|
|
838
784
|
} else {
|
|
839
|
-
console.warn(
|
|
840
|
-
`(!1) Cannot assign value to ${lastKey} because its reference is not an object.`,
|
|
841
|
-
);
|
|
785
|
+
console.warn(`(!1) Cannot assign value to ${lastKey} because its reference is not an object.`);
|
|
842
786
|
}
|
|
843
787
|
}
|
|
844
788
|
|
|
@@ -871,9 +815,7 @@ export function hasObject(obj: any, namespace: string): boolean {
|
|
|
871
815
|
* @returns - Returns a new object with keys sorted alphabetically
|
|
872
816
|
*/
|
|
873
817
|
|
|
874
|
-
export function sortObjectByKeys(
|
|
875
|
-
obj: Record<string, any>,
|
|
876
|
-
): Record<string, any> {
|
|
818
|
+
export function sortObjectByKeys(obj: Record<string, any>): Record<string, any> {
|
|
877
819
|
if (!obj || typeof obj !== 'object') {
|
|
878
820
|
return obj;
|
|
879
821
|
}
|