@uityu/uityu-shared 1.0.1 → 1.0.4

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.
@@ -0,0 +1 @@
1
+ export * from "./math";
@@ -0,0 +1 @@
1
+ export * from "./math";
@@ -0,0 +1,12 @@
1
+ export interface ClampOptions {
2
+ /** Value to use when the input is undefined or not finite */
3
+ defaultValue: number;
4
+ /** Upper bound; must be a finite number */
5
+ max: number;
6
+ /** Optional lower bound; defaults to 1 */
7
+ min?: number;
8
+ }
9
+ /**
10
+ * Domain-level guard to clamp numeric limits while providing sane defaults.
11
+ */
12
+ export declare function clampLimit(value: number | undefined, options: ClampOptions): number;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Domain-level guard to clamp numeric limits while providing sane defaults.
3
+ */
4
+ export function clampLimit(value, options) {
5
+ const normalized = toFiniteNumber(value, options.defaultValue);
6
+ const min = toFiniteNumber(options.min, 1);
7
+ const max = toFiniteNumber(options.max, min);
8
+ if (max < min) {
9
+ throw new Error("Clamp max must be greater than or equal to min");
10
+ }
11
+ return Math.min(max, Math.max(min, normalized));
12
+ }
13
+ function toFiniteNumber(value, fallback) {
14
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
15
+ }
@@ -0,0 +1 @@
1
+ export * from "./clamp-limit";
@@ -0,0 +1 @@
1
+ export * from "./clamp-limit";
@@ -0,0 +1,2 @@
1
+ export * from "./domain";
2
+ export * from "./infrastructure";
@@ -0,0 +1,2 @@
1
+ export * from "./domain";
2
+ export * from "./infrastructure";
@@ -0,0 +1 @@
1
+ export * from "./logging";
@@ -0,0 +1 @@
1
+ export * from "./logging";
@@ -0,0 +1 @@
1
+ export * from "./serialize-log-payload";
@@ -0,0 +1 @@
1
+ export * from "./serialize-log-payload";
@@ -0,0 +1 @@
1
+ export declare function serializeLogPayload(payload: unknown): Record<string, unknown>;
@@ -0,0 +1,38 @@
1
+ export function serializeLogPayload(payload) {
2
+ if (!isSerializableObject(payload)) {
3
+ return {};
4
+ }
5
+ try {
6
+ const serialized = JSON.parse(JSON.stringify(payload, (_key, value) => normalizeValue(value)));
7
+ if (isSerializableObject(serialized)) {
8
+ return serialized;
9
+ }
10
+ return { value: serialized };
11
+ }
12
+ catch {
13
+ return { value: "[unserializable]" };
14
+ }
15
+ }
16
+ function normalizeValue(value) {
17
+ if (value instanceof Date) {
18
+ return value.toISOString();
19
+ }
20
+ if (typeof value === "bigint") {
21
+ return value.toString();
22
+ }
23
+ if (hasToJSON(value)) {
24
+ try {
25
+ return value.toJSON();
26
+ }
27
+ catch {
28
+ return "[unserializable]";
29
+ }
30
+ }
31
+ return value;
32
+ }
33
+ function hasToJSON(value) {
34
+ return Boolean(value && typeof value === "object" && "toJSON" in value && typeof value.toJSON === "function");
35
+ }
36
+ function isSerializableObject(value) {
37
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
38
+ }
@@ -0,0 +1,4 @@
1
+ export { AppError } from "./app-error";
2
+ export { AppErrorFactory } from "./app-error.factory";
3
+ export { ErrorCode } from "./error-codes";
4
+ export type { ErrorCode as ErrorCodeType } from "./error-codes";
@@ -0,0 +1,3 @@
1
+ export { AppError } from "./app-error";
2
+ export { AppErrorFactory } from "./app-error.factory";
3
+ export { ErrorCode } from "./error-codes";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./errors/error-codes";
2
- export * from "./errors/app-error";
3
- export * from "./errors/app-error.factory";
2
+ export { AppError } from "./errors/app-error";
3
+ export { AppErrorFactory } from "./errors/app-error.factory";
4
4
  export { toApiError } from "./http/error-mapper";
5
5
  export type { ApiErrorResponse } from "./http/error-mapper";
6
- export * from "./search/search-index";
6
+ export { createEmptySearchIndex, normalizeSearchText, buildSearchPrefixes, toSearchPrefix, normalizePhoneDigits, } from "./search/search-index";
7
+ export type { SearchIndex } from "./search/search-index";
8
+ export * from "./common";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./errors/error-codes";
2
- export * from "./errors/app-error";
3
- export * from "./errors/app-error.factory";
2
+ export { AppError } from "./errors/app-error";
3
+ export { AppErrorFactory } from "./errors/app-error.factory";
4
4
  export { toApiError } from "./http/error-mapper";
5
- export * from "./search/search-index";
5
+ export { createEmptySearchIndex, normalizeSearchText, buildSearchPrefixes, toSearchPrefix, normalizePhoneDigits, } from "./search/search-index";
6
+ export * from "./common";
package/package.json CHANGED
@@ -1,10 +1,29 @@
1
1
  {
2
2
  "name": "@uityu/uityu-shared",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./errors": {
14
+ "types": "./dist/errors/index.d.ts",
15
+ "import": "./dist/errors/index.js"
16
+ },
17
+ "./search-index": {
18
+ "types": "./dist/search/search-index.d.ts",
19
+ "import": "./dist/search/search-index.js"
20
+ },
21
+ "./common": {
22
+ "types": "./dist/common/index.d.ts",
23
+ "import": "./dist/common/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
8
27
  "scripts": {
9
28
  "build": "tsc -p tsconfig.json"
10
29
  }
@@ -0,0 +1 @@
1
+ export * from "./math";
@@ -0,0 +1,27 @@
1
+ export interface ClampOptions {
2
+ /** Value to use when the input is undefined or not finite */
3
+ defaultValue: number;
4
+ /** Upper bound; must be a finite number */
5
+ max: number;
6
+ /** Optional lower bound; defaults to 1 */
7
+ min?: number;
8
+ }
9
+
10
+ /**
11
+ * Domain-level guard to clamp numeric limits while providing sane defaults.
12
+ */
13
+ export function clampLimit(value: number | undefined, options: ClampOptions): number {
14
+ const normalized = toFiniteNumber(value, options.defaultValue);
15
+ const min = toFiniteNumber(options.min, 1);
16
+ const max = toFiniteNumber(options.max, min);
17
+
18
+ if (max < min) {
19
+ throw new Error("Clamp max must be greater than or equal to min");
20
+ }
21
+
22
+ return Math.min(max, Math.max(min, normalized));
23
+ }
24
+
25
+ function toFiniteNumber(value: number | undefined, fallback: number): number {
26
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
27
+ }
@@ -0,0 +1 @@
1
+ export * from "./clamp-limit";
@@ -0,0 +1,2 @@
1
+ export * from "./domain";
2
+ export * from "./infrastructure";
@@ -0,0 +1 @@
1
+ export * from "./logging";
@@ -0,0 +1 @@
1
+ export * from "./serialize-log-payload";
@@ -0,0 +1,49 @@
1
+ export function serializeLogPayload(payload: unknown): Record<string, unknown> {
2
+ if (!isSerializableObject(payload)) {
3
+ return {};
4
+ }
5
+
6
+ try {
7
+ const serialized = JSON.parse(
8
+ JSON.stringify(payload, (_key, value) => normalizeValue(value)),
9
+ );
10
+
11
+ if (isSerializableObject(serialized)) {
12
+ return serialized;
13
+ }
14
+
15
+ return { value: serialized };
16
+ } catch {
17
+ return { value: "[unserializable]" };
18
+ }
19
+ }
20
+
21
+ function normalizeValue(value: unknown): unknown {
22
+ if (value instanceof Date) {
23
+ return value.toISOString();
24
+ }
25
+
26
+ if (typeof value === "bigint") {
27
+ return value.toString();
28
+ }
29
+
30
+ if (hasToJSON(value)) {
31
+ try {
32
+ return value.toJSON();
33
+ } catch {
34
+ return "[unserializable]";
35
+ }
36
+ }
37
+
38
+ return value;
39
+ }
40
+
41
+ function hasToJSON(value: unknown): value is { toJSON: () => unknown } {
42
+ return Boolean(
43
+ value && typeof value === "object" && "toJSON" in value && typeof (value as { toJSON?: unknown }).toJSON === "function",
44
+ );
45
+ }
46
+
47
+ function isSerializableObject(value: unknown): value is Record<string, unknown> {
48
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
49
+ }
@@ -0,0 +1,4 @@
1
+ export { AppError } from "./app-error";
2
+ export { AppErrorFactory } from "./app-error.factory";
3
+ export { ErrorCode } from "./error-codes";
4
+ export type { ErrorCode as ErrorCodeType } from "./error-codes";
package/src/index.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  export * from "./errors/error-codes";
2
- export * from "./errors/app-error";
3
- export * from "./errors/app-error.factory";
2
+ export { AppError } from "./errors/app-error";
3
+ export { AppErrorFactory } from "./errors/app-error.factory";
4
4
  export { toApiError } from "./http/error-mapper";
5
5
  export type { ApiErrorResponse } from "./http/error-mapper";
6
- export * from "./search/search-index";
6
+ export {
7
+ createEmptySearchIndex,
8
+ normalizeSearchText,
9
+ buildSearchPrefixes,
10
+ toSearchPrefix,
11
+ normalizePhoneDigits,
12
+ } from "./search/search-index";
13
+ export type { SearchIndex } from "./search/search-index";
14
+ export * from "./common";