@esposter/shared 2.38.1 → 2.40.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.
- package/LICENSE +201 -201
- package/dist/index.d.ts +426 -405
- package/dist/index.js +48 -29
- package/package.json +14 -16
package/dist/index.js
CHANGED
|
@@ -104,8 +104,7 @@ let MentionType = /* @__PURE__ */ function(MentionType) {
|
|
|
104
104
|
const MAX_READ_LIMIT = 1e3;
|
|
105
105
|
const SITE_NAME = "Esposter";
|
|
106
106
|
const KIBIBYTE = 1024;
|
|
107
|
-
const
|
|
108
|
-
const GIBIBYTE = MEGABYTE * KIBIBYTE;
|
|
107
|
+
const GIBIBYTE = KIBIBYTE ** 2 * KIBIBYTE;
|
|
109
108
|
//#endregion
|
|
110
109
|
//#region src/models/router/RoutePath.ts
|
|
111
110
|
const RoutePath = {
|
|
@@ -209,7 +208,7 @@ const toAppError = (error) => {
|
|
|
209
208
|
};
|
|
210
209
|
//#endregion
|
|
211
210
|
//#region src/services/error/getResultAsync.ts
|
|
212
|
-
const getResultAsync = (fn) => ResultAsync.
|
|
211
|
+
const getResultAsync = (fn) => ResultAsync.fromThrowable(fn, toAppError)();
|
|
213
212
|
//#endregion
|
|
214
213
|
//#region src/util/time/sleep.ts
|
|
215
214
|
const sleep = (durationMs) => new Promise((resolve) => {
|
|
@@ -331,6 +330,11 @@ const sanitizeHtml = (...[html, options]) => baseSanitizeHtml(html, {
|
|
|
331
330
|
});
|
|
332
331
|
//#endregion
|
|
333
332
|
//#region src/services/sanitizeHtml/sanitizeTextHtml.ts
|
|
333
|
+
const COLOR_REGEXES = [
|
|
334
|
+
/^#[\da-fA-F]{3,8}$/u,
|
|
335
|
+
/^rgba?\(\d{1,3},\s*\d{1,3},\s*\d{1,3}(?:,\s*[\d.]+)?\)$/u,
|
|
336
|
+
/^[a-z]+$/iu
|
|
337
|
+
];
|
|
334
338
|
const sanitizeTextHtml = (html) => sanitizeHtml(html, {
|
|
335
339
|
allowedAttributes: {
|
|
336
340
|
a: [
|
|
@@ -352,17 +356,9 @@ const sanitizeTextHtml = (html) => sanitizeHtml(html, {
|
|
|
352
356
|
]
|
|
353
357
|
},
|
|
354
358
|
allowedStyles: { span: {
|
|
355
|
-
"background-color":
|
|
356
|
-
/^#[\da-fA-F]{3,8}$/u,
|
|
357
|
-
/^rgba?\(\d{1,3},\s*\d{1,3},\s*\d{1,3}(?:,\s*[\d.]+)?\)$/u,
|
|
358
|
-
/^[a-z]+$/iu
|
|
359
|
-
],
|
|
359
|
+
"background-color": COLOR_REGEXES,
|
|
360
360
|
"border-radius": [/^[\d.]+(?<unit>px|em|rem|%)$/u],
|
|
361
|
-
color:
|
|
362
|
-
/^#[\da-fA-F]{3,8}$/u,
|
|
363
|
-
/^rgba?\(\d{1,3},\s*\d{1,3},\s*\d{1,3}(?:,\s*[\d.]+)?\)$/u,
|
|
364
|
-
/^[a-z]+$/iu
|
|
365
|
-
]
|
|
361
|
+
color: COLOR_REGEXES
|
|
366
362
|
} }
|
|
367
363
|
});
|
|
368
364
|
//#endregion
|
|
@@ -373,6 +369,15 @@ const applyItemMetadataMixin = (Base) => class ItemWithMetadata extends Base {
|
|
|
373
369
|
updatedAt = /* @__PURE__ */ new Date();
|
|
374
370
|
};
|
|
375
371
|
//#endregion
|
|
372
|
+
//#region src/util/text/normalizeString.ts
|
|
373
|
+
const normalizeString = (value) => value?.trim() ?? "";
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region src/services/zod/createNormalizedStringSchema.ts
|
|
376
|
+
const createNormalizedStringSchema = (maxLength, schema = z.string()) => schema.transform(normalizeString).pipe(z.string().max(maxLength));
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/services/zod/createUniqueArraySchema.ts
|
|
379
|
+
const createUniqueArraySchema = (schema, key) => schema.array().refine((array) => new Set(key === void 0 ? array : array.map((item) => item[key])).size === array.length, "Array items must be unique");
|
|
380
|
+
//#endregion
|
|
376
381
|
//#region src/util/array/chunk.ts
|
|
377
382
|
const chunk = (array, size) => {
|
|
378
383
|
const chunks = [];
|
|
@@ -406,8 +411,29 @@ const takeOne = (values, index = 0) => {
|
|
|
406
411
|
return values[index];
|
|
407
412
|
};
|
|
408
413
|
//#endregion
|
|
409
|
-
//#region src/util/
|
|
410
|
-
const
|
|
414
|
+
//#region src/util/date/getZonedDateTime.ts
|
|
415
|
+
const getZonedDateTime = (date) => Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/util/date/getPlainDate.ts
|
|
418
|
+
const getPlainDate = (date) => getZonedDateTime(date).toPlainDate();
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/util/date/checkIsSameDay.ts
|
|
421
|
+
const checkIsSameDay = (date, otherDate) => getPlainDate(date).equals(getPlainDate(otherDate));
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/util/date/checkIsToday.ts
|
|
424
|
+
const checkIsToday = (date) => getPlainDate(date).equals(Temporal.Now.plainDateISO());
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region src/util/date/checkIsYesterday.ts
|
|
427
|
+
const checkIsYesterday = (date) => getPlainDate(date).equals(Temporal.Now.plainDateISO().subtract({ days: 1 }));
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/util/date/getEndOfDay.ts
|
|
430
|
+
const getEndOfDay = (date) => /* @__PURE__ */ new Date(getZonedDateTime(date).startOfDay().add({ days: 1 }).epochMilliseconds - 1);
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/util/date/getStartOfDay.ts
|
|
433
|
+
const getStartOfDay = (date) => new Date(getZonedDateTime(date).startOfDay().epochMilliseconds);
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/util/environment/checkIsServer.ts
|
|
436
|
+
const checkIsServer = () => typeof window === "undefined";
|
|
411
437
|
//#endregion
|
|
412
438
|
//#region src/util/id/constants.ts
|
|
413
439
|
const ID_SEPARATOR = "|";
|
|
@@ -448,7 +474,7 @@ const settleAll = async (tasks, concurrencyLimit = tasks.length) => {
|
|
|
448
474
|
if (tasks.length === 0) return [];
|
|
449
475
|
const values = [];
|
|
450
476
|
for (const tasksChunk of chunk(tasks, concurrencyLimit)) {
|
|
451
|
-
const results = await Promise.allSettled(tasksChunk.map((task) => Promise.
|
|
477
|
+
const results = await Promise.allSettled(tasksChunk.map((task) => Promise.try(task)));
|
|
452
478
|
const reasons = [];
|
|
453
479
|
for (const result of results) if (result.status === "rejected") reasons.push(result.reason);
|
|
454
480
|
else values.push(result.value);
|
|
@@ -474,10 +500,6 @@ const encodeUrlSubDelimiters = (value) => Object.entries(EncodedSubDelimiterMap)
|
|
|
474
500
|
//#region src/util/text/getDecodedUriComponent.ts
|
|
475
501
|
const getDecodedUriComponent = (value, fallback) => getResult(() => decodeURIComponent(value)).unwrapOr(fallback);
|
|
476
502
|
//#endregion
|
|
477
|
-
//#region src/util/text/normalizeString.ts
|
|
478
|
-
const normalizeString = (value) => value?.trim() ?? "";
|
|
479
|
-
const createNormalizedStringSchema = (maxLength, schema = z.string()) => schema.transform(normalizeString).pipe(z.string().max(maxLength));
|
|
480
|
-
//#endregion
|
|
481
503
|
//#region src/util/text/streamToText.ts
|
|
482
504
|
const streamToText = async (readable) => {
|
|
483
505
|
readable.setEncoding("utf8");
|
|
@@ -493,8 +515,8 @@ const toKebabCase = (string) => string.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|
|
|
|
493
515
|
const SUFFIX = "...";
|
|
494
516
|
const truncate = (string, length) => {
|
|
495
517
|
if (string.length <= length) return string;
|
|
496
|
-
if (length < 3) return string.slice(0, length);
|
|
497
|
-
return `${string.slice(0, length - 3)}${SUFFIX}`;
|
|
518
|
+
else if (length < 3) return string.slice(0, length);
|
|
519
|
+
else return `${string.slice(0, length - 3)}${SUFFIX}`;
|
|
498
520
|
};
|
|
499
521
|
//#endregion
|
|
500
522
|
//#region src/util/text/uncapitalize.ts
|
|
@@ -502,7 +524,7 @@ const uncapitalize = (string) => `${string.charAt(0).toLowerCase()}${string.slic
|
|
|
502
524
|
//#endregion
|
|
503
525
|
//#region src/util/time/hrtime.ts
|
|
504
526
|
const hrtime = (previousHrTime) => {
|
|
505
|
-
if (
|
|
527
|
+
if (checkIsServer()) return process.hrtime(previousHrTime);
|
|
506
528
|
const clocktime = performance.now() * .001;
|
|
507
529
|
let seconds = Math.floor(clocktime);
|
|
508
530
|
let nanoseconds = Math.floor(clocktime % 1 * 1e9);
|
|
@@ -530,13 +552,10 @@ const exhaustiveGuard = (value) => {
|
|
|
530
552
|
throw new InvalidOperationError("Read", exhaustiveGuard.name, JSON.stringify(value));
|
|
531
553
|
};
|
|
532
554
|
//#endregion
|
|
533
|
-
//#region src/util/zod/createUniqueArraySchema.ts
|
|
534
|
-
const createUniqueArraySchema = (schema, key) => schema.array().refine((array) => new Set(key === void 0 ? array : array.map((item) => item[key])).size === array.length, "Array items must be unique");
|
|
535
|
-
//#endregion
|
|
536
555
|
//#region src/util/id/uuid/constants.ts
|
|
537
556
|
const UUIDV4_REGEX = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/iu;
|
|
538
557
|
//#endregion
|
|
539
|
-
//#region src/util/id/uuid/
|
|
540
|
-
const
|
|
558
|
+
//#region src/util/id/uuid/checkIsUuidV4.ts
|
|
559
|
+
const checkIsUuidV4 = (uuid) => UUIDV4_REGEX.test(uuid);
|
|
541
560
|
//#endregion
|
|
542
|
-
export { AllSpecialValues, CUSTOM_EMOJI_ID_ATTRIBUTE, CUSTOM_EMOJI_NAME_ATTRIBUTE, CUSTOM_EMOJI_TYPE, ForbiddenError, GIBIBYTE, ID_SEPARATOR, InvalidOperationError, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KIBIBYTE, MAX_READ_LIMIT,
|
|
561
|
+
export { AllSpecialValues, CUSTOM_EMOJI_ID_ATTRIBUTE, CUSTOM_EMOJI_NAME_ATTRIBUTE, CUSTOM_EMOJI_TYPE, ForbiddenError, GIBIBYTE, ID_SEPARATOR, InvalidOperationError, ItemEntityTypePropertyNames, ItemMetadata, ItemMetadataPropertyNames, KIBIBYTE, MAX_READ_LIMIT, MENTION_EVERYONE_ID, MENTION_HERE_ID, MENTION_ID_ATTRIBUTE, MENTION_ITEM_TYPE_ATTRIBUTE, MENTION_LABEL_ATTRIBUTE, MENTION_SELECTOR, MENTION_TYPE, MENTION_TYPE_ATTRIBUTE, MentionType, NotFoundError, NotInitializedError, Operation, RoutePath, SITE_NAME, Serializable, UUIDV4_REGEX, UUID_LENGTH, WordFilteredError, applyItemMetadataMixin, capitalize, checkIsPlainObject, checkIsSameDay, checkIsServer, checkIsToday, checkIsUuidV4, checkIsYesterday, chunk, chunkBySerializedSize, classifyMentions, createExponentialBackoff, createItemEntityTypeSchema, createNormalizedStringSchema, createUniqueArraySchema, css, encodeUrlSubDelimiters, exhaustiveGuard, getDecodedUriComponent, getEndOfDay, getMentions, getOrCreate, getPlainDate, getPropertyNames, getRawData, getResult, getResultAsync, getStartOfDay, getZonedDateTime, hrtime, html, itemMetadataSchema, jsonDateParse, mergeObjectsStrict, noop, normalizeString, now, sanitizeHtml, sanitizeTextHtml, settleAll, sleep, streamToText, takeOne, toAppError, toKebabCase, toRawDeep, truncate, uncapitalize, withFinalizer, withFinalizerAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esposter/shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.40.0",
|
|
4
4
|
"description": "A library that contains shared typescript code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"error-handling",
|
|
@@ -39,39 +39,37 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"export:gen": "
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"export:gen": "generate-exports",
|
|
44
44
|
"format": "oxfmt",
|
|
45
45
|
"format:check": "oxfmt --check",
|
|
46
46
|
"lint": "eslint .",
|
|
47
47
|
"lint:fix": "eslint --fix .",
|
|
48
48
|
"test": "vitest",
|
|
49
|
-
"typecheck": "
|
|
49
|
+
"typecheck": "tsc"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"neverthrow": "^8.2.0",
|
|
53
|
-
"node-html-parser": "^9.0.
|
|
53
|
+
"node-html-parser": "^9.0.4",
|
|
54
54
|
"sanitize-html": "^2.17.7"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@arethetypeswrong/core": "^0.18.5",
|
|
58
58
|
"@azure/data-tables": "^13.3.2",
|
|
59
|
-
"@esposter/configuration": "2.
|
|
60
|
-
"@types/node": "^26.
|
|
59
|
+
"@esposter/configuration": "2.40.0",
|
|
60
|
+
"@types/node": "^26.5.1",
|
|
61
61
|
"@types/sanitize-html": "^2.16.1",
|
|
62
|
-
"ctix": "^2.8.2",
|
|
63
62
|
"publint": "^0.3.24",
|
|
64
|
-
"tsdown": "^0.
|
|
65
|
-
"type-fest": "^5.
|
|
66
|
-
"vitest": "^
|
|
67
|
-
"vue": "^3.5.
|
|
63
|
+
"tsdown": "^0.23.0",
|
|
64
|
+
"type-fest": "^5.9.0",
|
|
65
|
+
"vitest": "^5.0.0",
|
|
66
|
+
"vue": "^3.5.42"
|
|
68
67
|
},
|
|
69
68
|
"peerDependencies": {
|
|
70
|
-
"zod": "^4.
|
|
69
|
+
"zod": "^4.6.1"
|
|
71
70
|
},
|
|
72
71
|
"inlinedDependencies": {
|
|
73
|
-
"
|
|
74
|
-
"type-fest": "5.8.0"
|
|
72
|
+
"type-fest": "5.9.0"
|
|
75
73
|
},
|
|
76
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "09506078db97923eeecb4ff602cf01015f237dc8"
|
|
77
75
|
}
|