@vpmedia/simplify 1.74.0 → 1.76.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 (167) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/dist/const/http_status.d.ts +66 -0
  3. package/dist/const/http_status.d.ts.map +1 -0
  4. package/dist/index.d.ts +34 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +1119 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/logging/AbstractLogHandler.d.ts +17 -0
  9. package/dist/logging/AbstractLogHandler.d.ts.map +1 -0
  10. package/dist/logging/ConsoleLogHandler.d.ts +13 -0
  11. package/dist/logging/ConsoleLogHandler.d.ts.map +1 -0
  12. package/dist/logging/Logger.d.ts +19 -0
  13. package/dist/logging/Logger.d.ts.map +1 -0
  14. package/dist/logging/OpenTelemetryLogHandler.d.ts +15 -0
  15. package/dist/logging/OpenTelemetryLogHandler.d.ts.map +1 -0
  16. package/dist/logging/SentryLogHandler.d.ts +13 -0
  17. package/dist/logging/SentryLogHandler.d.ts.map +1 -0
  18. package/dist/logging/const.d.ts +14 -0
  19. package/dist/logging/const.d.ts.map +1 -0
  20. package/dist/logging/util.d.ts +14 -0
  21. package/dist/logging/util.d.ts.map +1 -0
  22. package/dist/pagelifecycle/const.d.ts +15 -0
  23. package/dist/pagelifecycle/const.d.ts.map +1 -0
  24. package/dist/pagelifecycle/typedef.d.ts +4 -0
  25. package/dist/pagelifecycle/typedef.d.ts.map +1 -0
  26. package/dist/pagelifecycle/util.d.ts +31 -0
  27. package/dist/pagelifecycle/util.d.ts.map +1 -0
  28. package/dist/typecheck/TypeCheckError.d.ts +11 -0
  29. package/dist/typecheck/TypeCheckError.d.ts.map +1 -0
  30. package/dist/typecheck/TypeChecker.d.ts +27 -0
  31. package/dist/typecheck/TypeChecker.d.ts.map +1 -0
  32. package/dist/typecheck/util.d.ts +17 -0
  33. package/dist/typecheck/util.d.ts.map +1 -0
  34. package/dist/util/async.d.ts +13 -0
  35. package/dist/util/async.d.ts.map +1 -0
  36. package/dist/util/error.d.ts +16 -0
  37. package/dist/util/error.d.ts.map +1 -0
  38. package/dist/util/event_emitter.d.ts +42 -0
  39. package/dist/util/event_emitter.d.ts.map +1 -0
  40. package/dist/util/fetch.d.ts +22 -0
  41. package/dist/util/fetch.d.ts.map +1 -0
  42. package/dist/util/number.d.ts +23 -0
  43. package/dist/util/number.d.ts.map +1 -0
  44. package/dist/util/object.d.ts +24 -0
  45. package/dist/util/object.d.ts.map +1 -0
  46. package/dist/util/query.d.ts +11 -0
  47. package/dist/util/query.d.ts.map +1 -0
  48. package/dist/util/state.d.ts +5 -0
  49. package/dist/util/state.d.ts.map +1 -0
  50. package/dist/util/string.d.ts +25 -0
  51. package/dist/util/string.d.ts.map +1 -0
  52. package/dist/util/uuid.d.ts +13 -0
  53. package/dist/util/uuid.d.ts.map +1 -0
  54. package/dist/util/validate.d.ts +106 -0
  55. package/dist/util/validate.d.ts.map +1 -0
  56. package/package.json +32 -16
  57. package/src/const/http_status.test.ts +7 -0
  58. package/src/const/{http_status.js → http_status.ts} +1 -1
  59. package/src/{index.js → index.ts} +8 -0
  60. package/src/logging/AbstractLogHandler.ts +31 -0
  61. package/src/logging/{ConsoleLogHandler.js → ConsoleLogHandler.ts} +15 -13
  62. package/src/logging/Logger.test.ts +69 -0
  63. package/src/logging/Logger.ts +77 -0
  64. package/src/logging/OpenTelemetryLogHandler.ts +40 -0
  65. package/src/logging/SentryLogHandler.ts +44 -0
  66. package/src/logging/{const.js → const.ts} +1 -1
  67. package/src/logging/util.test.ts +33 -0
  68. package/src/logging/util.ts +36 -0
  69. package/src/pagelifecycle/{const.js → const.ts} +2 -2
  70. package/src/pagelifecycle/typedef.ts +5 -0
  71. package/src/pagelifecycle/util.test.ts +99 -0
  72. package/src/pagelifecycle/{util.js → util.ts} +14 -27
  73. package/src/typecheck/{TypeCheckError.js → TypeCheckError.ts} +7 -3
  74. package/src/typecheck/TypeChecker.test.ts +70 -0
  75. package/src/typecheck/{TypeChecker.js → TypeChecker.ts} +10 -27
  76. package/src/typecheck/util.test.ts +36 -0
  77. package/src/typecheck/util.ts +50 -0
  78. package/src/util/async.test.ts +74 -0
  79. package/src/util/{async.js → async.ts} +3 -12
  80. package/src/util/error.test.ts +32 -0
  81. package/src/util/error.ts +37 -0
  82. package/src/util/event_emitter.test.ts +228 -0
  83. package/src/util/event_emitter.ts +147 -0
  84. package/src/util/fetch.test.ts +62 -0
  85. package/src/util/{fetch.js → fetch.ts} +40 -31
  86. package/src/util/number.test.ts +124 -0
  87. package/src/util/number.ts +58 -0
  88. package/src/util/object.test.ts +203 -0
  89. package/src/util/{object.js → object.ts} +14 -21
  90. package/src/util/query.test.ts +71 -0
  91. package/src/util/query.ts +35 -0
  92. package/src/util/state.test.ts +47 -0
  93. package/src/util/{state.js → state.ts} +3 -6
  94. package/src/util/string.test.ts +64 -0
  95. package/src/util/string.ts +65 -0
  96. package/src/util/uuid.test.ts +53 -0
  97. package/src/util/uuid.ts +31 -0
  98. package/src/util/validate.test.ts +309 -0
  99. package/src/util/validate.ts +230 -0
  100. package/.vscode/extensions.json +0 -6
  101. package/.vscode/settings.json +0 -27
  102. package/src/logging/AbstractLogHandler.js +0 -23
  103. package/src/logging/Logger.js +0 -115
  104. package/src/logging/OpenTelemetryLogHandler.js +0 -30
  105. package/src/logging/SentryLogHandler.js +0 -46
  106. package/src/logging/util.js +0 -41
  107. package/src/pagelifecycle/typedef.js +0 -9
  108. package/src/typecheck/util.js +0 -60
  109. package/src/util/error.js +0 -33
  110. package/src/util/event_emitter.js +0 -196
  111. package/src/util/number.js +0 -118
  112. package/src/util/query.js +0 -32
  113. package/src/util/string.js +0 -76
  114. package/src/util/uuid.js +0 -35
  115. package/src/util/validate.js +0 -247
  116. package/types/const/http_status.d.ts +0 -131
  117. package/types/const/http_status.d.ts.map +0 -1
  118. package/types/index.d.ts +0 -26
  119. package/types/index.d.ts.map +0 -1
  120. package/types/logging/AbstractLogHandler.d.ts +0 -20
  121. package/types/logging/AbstractLogHandler.d.ts.map +0 -1
  122. package/types/logging/ConsoleLogHandler.d.ts +0 -9
  123. package/types/logging/ConsoleLogHandler.d.ts.map +0 -1
  124. package/types/logging/Logger.d.ts +0 -66
  125. package/types/logging/Logger.d.ts.map +0 -1
  126. package/types/logging/OpenTelemetryLogHandler.d.ts +0 -11
  127. package/types/logging/OpenTelemetryLogHandler.d.ts.map +0 -1
  128. package/types/logging/SentryLogHandler.d.ts +0 -9
  129. package/types/logging/SentryLogHandler.d.ts.map +0 -1
  130. package/types/logging/const.d.ts +0 -14
  131. package/types/logging/const.d.ts.map +0 -1
  132. package/types/logging/util.d.ts +0 -4
  133. package/types/logging/util.d.ts.map +0 -1
  134. package/types/pagelifecycle/const.d.ts +0 -15
  135. package/types/pagelifecycle/const.d.ts.map +0 -1
  136. package/types/pagelifecycle/typedef.d.ts +0 -4
  137. package/types/pagelifecycle/typedef.d.ts.map +0 -1
  138. package/types/pagelifecycle/util.d.ts +0 -8
  139. package/types/pagelifecycle/util.d.ts.map +0 -1
  140. package/types/typecheck/TypeCheckError.d.ts +0 -13
  141. package/types/typecheck/TypeCheckError.d.ts.map +0 -1
  142. package/types/typecheck/TypeChecker.d.ts +0 -40
  143. package/types/typecheck/TypeChecker.d.ts.map +0 -1
  144. package/types/typecheck/util.d.ts +0 -4
  145. package/types/typecheck/util.d.ts.map +0 -1
  146. package/types/util/async.d.ts +0 -4
  147. package/types/util/async.d.ts.map +0 -1
  148. package/types/util/error.d.ts +0 -3
  149. package/types/util/error.d.ts.map +0 -1
  150. package/types/util/event_emitter.d.ts +0 -69
  151. package/types/util/event_emitter.d.ts.map +0 -1
  152. package/types/util/fetch.d.ts +0 -22
  153. package/types/util/fetch.d.ts.map +0 -1
  154. package/types/util/number.d.ts +0 -11
  155. package/types/util/number.d.ts.map +0 -1
  156. package/types/util/object.d.ts +0 -6
  157. package/types/util/object.d.ts.map +0 -1
  158. package/types/util/query.d.ts +0 -3
  159. package/types/util/query.d.ts.map +0 -1
  160. package/types/util/state.d.ts +0 -2
  161. package/types/util/state.d.ts.map +0 -1
  162. package/types/util/string.d.ts +0 -7
  163. package/types/util/string.d.ts.map +0 -1
  164. package/types/util/uuid.d.ts +0 -4
  165. package/types/util/uuid.d.ts.map +0 -1
  166. package/types/util/validate.d.ts +0 -45
  167. package/types/util/validate.d.ts.map +0 -1
@@ -0,0 +1,24 @@
1
+ type AnyRecord = Record<string, any>;
2
+ /**
3
+ * Purges object properties to free up memory.
4
+ */
5
+ export declare const purgeObject: (target: AnyRecord | null | undefined) => void;
6
+ /**
7
+ * Merge two objects.
8
+ */
9
+ export declare const deepMerge: (target: AnyRecord | null, source: AnyRecord | null) => AnyRecord | null;
10
+ /**
11
+ * Returns the sum value of an array of objects field.
12
+ */
13
+ export declare const getObjArrayPropSum: (arr: AnyRecord[], prop: string) => number;
14
+ /**
15
+ * Get object value by path.
16
+ */
17
+ export declare const getObjValueByPath: (obj: AnyRecord | null | undefined, path: string | null | undefined) => unknown;
18
+ /**
19
+ * Set object value by path.
20
+ * @throws {SyntaxError} Error when illegal path value has been provided.
21
+ */
22
+ export declare const setObjValueByPath: (obj: AnyRecord | null | undefined, path: string | null | undefined, value: unknown) => void;
23
+ export {};
24
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/util/object.ts"],"names":[],"mappings":"AAEA,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAErC;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,SAAS,GAAG,IAAI,GAAG,SAAS,KAAG,IAOlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,SAAS,GAAG,IAAI,EAAE,QAAQ,SAAS,GAAG,IAAI,KAAG,SAAS,GAAG,IAsB1F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,SAAS,EAAE,EAAE,MAAM,MAAM,KAAG,MACY,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAatG,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,EACjC,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,OAAO,OAAO,KACb,IAiBF,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sanitizes URL parameters allowing only alpha-numeric characters and dash.
3
+ */
4
+ export declare function sanitizeURLParam(input: string): string;
5
+ export declare function sanitizeURLParam(input: null | undefined): null | undefined;
6
+ export declare function sanitizeURLParam(input: string | null | undefined): string | null | undefined;
7
+ /**
8
+ * Get a URL parameter value.
9
+ */
10
+ export declare function getURLParam<T = null>(key: string | null | undefined, defaultValue?: T, isSanitize?: boolean): string | T;
11
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/util/query.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AACxD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;AAC5E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAQ9F;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAG,IAAI,EAClC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,YAAY,CAAC,EAAE,CAAC,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,MAAM,GAAG,CAAC,CAYZ"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Maps server data to client data.
3
+ */
4
+ export declare const serverDataToState: (data: unknown, isRecursive?: boolean) => any;
5
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/util/state.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,OAAO,EAAE,qBAAmB,KAAG,GAetE,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Add leading zeros to a value to ensure it has a minimum width.
3
+ */
4
+ export declare const addLeadingZero: (value: number | string | null | undefined, size?: number) => string | null;
5
+ /**
6
+ * Capitalize a string.
7
+ */
8
+ export declare const capitalize: (value: string | null | undefined) => string | null;
9
+ /**
10
+ * Converts underscore case string to camel case.
11
+ */
12
+ export declare const underscoreToCamelCase: (value: string) => string;
13
+ /**
14
+ * Saves text file.
15
+ */
16
+ export declare const saveAsFile: (filename: string, text: string) => void;
17
+ /**
18
+ * Get type from value in human readable format.
19
+ */
20
+ export declare const getTypeFromValue: (value: unknown) => string;
21
+ /**
22
+ * Get value in human readable format.
23
+ */
24
+ export declare const getDisplayValue: (value: unknown) => string;
25
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,aAAQ,KAAG,MAAM,GAAG,IAS7F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,MAAM,GAAG,IAStE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MACG,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,EAAE,MAAM,MAAM,KAAG,IAQ3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,MACgB,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAQhD,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Convert a byte (0–255) to a 2-character hex string.
3
+ */
4
+ export declare const byteToHex: (byte: number) => string;
5
+ /**
6
+ * UUIDv4 fallback generator (RFC 4122 compliant).
7
+ */
8
+ export declare const randomUUIDFallback: () => string;
9
+ /**
10
+ * Crypto UUIDv4 wrapper with fallback.
11
+ */
12
+ export declare const uuidv4: () => string;
13
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/util/uuid.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,MAAkE,CAAC;AAE5G;;GAEG;AACH,eAAO,MAAM,kBAAkB,QAAO,MAgBrC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,QAAO,MAC4D,CAAC"}
@@ -0,0 +1,106 @@
1
+ export type Validator<T> = (value: unknown) => value is T;
2
+ /**
3
+ * Validates `value` as `boolean`.
4
+ */
5
+ export declare const isBoolean: (value: unknown) => value is boolean;
6
+ /**
7
+ * Validates `value` as `number`.
8
+ */
9
+ export declare const isNumber: (value: unknown) => value is number;
10
+ /**
11
+ * Validates `value` as positive `number`.
12
+ */
13
+ export declare const isPositiveNumber: (value: unknown) => value is number;
14
+ /**
15
+ * Validates `value` as non-negative `number`.
16
+ */
17
+ export declare const isNonNegativeNumber: (value: unknown) => value is number;
18
+ /**
19
+ * Validates `value` as `integer`.
20
+ */
21
+ export declare const isInteger: (value: unknown) => value is number;
22
+ /**
23
+ * Validates `value` as positive `integer`.
24
+ */
25
+ export declare const isPositiveInteger: (value: unknown) => value is number;
26
+ /**
27
+ * Validates `value` as non-negative `integer`.
28
+ */
29
+ export declare const isNonNegativeInteger: (value: unknown) => value is number;
30
+ /**
31
+ * Validates `value` as `string`.
32
+ */
33
+ export declare const isString: (value: unknown) => value is string;
34
+ /**
35
+ * Validates `value` as `array`.
36
+ */
37
+ export declare const isArray: <T = unknown>(value: unknown) => value is T[];
38
+ /**
39
+ * Validates `value` as `null`.
40
+ */
41
+ export declare const isNull: (value: unknown) => value is null;
42
+ /**
43
+ * Validates `value` as `undefined`.
44
+ */
45
+ export declare const isUndefined: (value: unknown) => value is undefined;
46
+ /**
47
+ * Validates `value` as `null` or `undefined`.
48
+ */
49
+ export declare const isNullOrUndefined: (value: unknown) => value is null | undefined;
50
+ /**
51
+ * Validates `value` as plain `object`.
52
+ */
53
+ export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
54
+ /**
55
+ * Validates `value` as `function`.
56
+ */
57
+ export declare const isFunction: (value: unknown) => value is (...args: any[]) => any;
58
+ /**
59
+ * Validates `value` as `type`.
60
+ */
61
+ export declare const isInstance: <T>(value: unknown, type: new (...args: any[]) => T) => value is T;
62
+ /**
63
+ * Validates `value` as `enum`.
64
+ */
65
+ export declare const isEnum: (value: unknown, choices: ReadonlyArray<string | number> | ReadonlySet<string | number> | Readonly<Record<string | number, string | number>> | null | undefined) => boolean;
66
+ /**
67
+ * Type check an array of values using a validator.
68
+ */
69
+ export declare const isArrayOf: <T>(values: unknown, validator: Validator<T>) => values is T[];
70
+ /**
71
+ * Type check a plain object of values using a validator.
72
+ */
73
+ export declare const isPlainObjectOf: <T>(record: unknown, validator: Validator<T>) => record is Record<string | number, T>;
74
+ /**
75
+ * Refine a base validator with an extra condition.
76
+ */
77
+ export declare const refineValidator: <T>(base: Validator<T>, predicate: (value: T) => boolean, name?: string | null) => Validator<T>;
78
+ /**
79
+ * Logical OR of two validators.
80
+ */
81
+ export declare const isAnyOf: <A, B>(a: Validator<A>, b: Validator<B>) => Validator<A | B>;
82
+ export declare const isNumberGreater: (min: number) => Validator<number>;
83
+ export declare const isNumberGreaterOrEqual: (min: number) => Validator<number>;
84
+ export declare const isNumberLess: (min: number) => Validator<number>;
85
+ export declare const isNumberLessOrEqual: (min: number) => Validator<number>;
86
+ export declare const isNumberInRange: (min: number, max: number) => Validator<number>;
87
+ export declare const isNumberEqual: (expected: number) => Validator<number>;
88
+ export declare const isIntegerGreater: (min: number) => Validator<number>;
89
+ export declare const isIntegerGreaterOrEqual: (min: number) => Validator<number>;
90
+ export declare const isIntegerLess: (min: number) => Validator<number>;
91
+ export declare const isIntegerLessOrEqual: (min: number) => Validator<number>;
92
+ export declare const isIntegerInRange: (min: number, max: number) => Validator<number>;
93
+ export declare const isIntegerEqual: (expected: number) => Validator<number>;
94
+ export declare const isStringLengthGreater: (min: number) => Validator<string>;
95
+ export declare const isStringLengthGreaterOrEqual: (min: number) => Validator<string>;
96
+ export declare const isStringLengthLess: (min: number) => Validator<string>;
97
+ export declare const isStringLengthLessOrEqual: (min: number) => Validator<string>;
98
+ export declare const isStringLengthInRange: (min: number, max: number) => Validator<string>;
99
+ export declare const isStringLengthEqual: (expected: number) => Validator<string>;
100
+ export declare const isArrayLengthGreater: (min: number) => Validator<unknown[]>;
101
+ export declare const isArrayLengthGreaterOrEqual: (min: number) => Validator<unknown[]>;
102
+ export declare const isArrayLengthLess: (min: number) => Validator<unknown[]>;
103
+ export declare const isArrayLengthLessOrEqual: (min: number) => Validator<unknown[]>;
104
+ export declare const isArrayLengthInRange: (min: number, max: number) => Validator<unknown[]>;
105
+ export declare const isArrayLengthEqual: (expected: number) => Validator<unknown[]>;
106
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/util/validate.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KA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,CAAC,MAAM,CACA,CAAC;AAElE,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,SAAS,CAAC,MAAM,CACA,CAAC;AAEzE,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,SAAS,CAAC,MAAM,CACR,CAAC;AAE1E,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,SAAS,CAAC,MAAM,CACA,CAAC;AAExE,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACH,CAAC;AAEpE,eAAO,MAAM,2BAA2B,GAAI,KAAK,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACH,CAAC;AAE3E,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACH,CAAC;AAEjE,eAAO,MAAM,wBAAwB,GAAI,KAAK,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACH,CAAC;AAExE,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACX,CAAC;AAEzE,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,SAAS,CAAC,OAAO,EAAE,CACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/simplify",
3
- "version": "1.74.0",
3
+ "version": "1.76.0",
4
4
  "description": "@vpmedia/simplify",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
@@ -15,27 +15,43 @@
15
15
  "keywords": [
16
16
  "utils"
17
17
  ],
18
- "main": "./src/index.js",
19
- "types": "./types/index.d.ts",
18
+ "main": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "default": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src",
30
+ "LICENSE",
31
+ "README.md",
32
+ "CHANGELOG.md",
33
+ "SECURITY.md"
34
+ ],
20
35
  "type": "module",
21
36
  "optionalDependencies": {
22
- "@sentry/browser": "^10.40.0"
37
+ "@sentry/browser": "^10.52.0"
23
38
  },
24
39
  "devDependencies": {
25
- "@commitlint/cli": "^20.4.2",
26
- "@commitlint/config-conventional": "^20.4.2",
27
- "@types/node": "^25.3.3",
28
- "@vitest/coverage-v8": "^4.0.18",
29
- "jsdom": "^28.1.0",
30
- "msw": "^2.12.10",
31
- "oxfmt": "^0.35.0",
32
- "oxlint": "^1.50.0",
33
- "oxlint-tsgolint": "^0.15.0",
34
- "typescript": "^5.9.3",
35
- "vitest": "^4.0.18"
40
+ "@commitlint/cli": "^21.0.0",
41
+ "@commitlint/config-conventional": "^21.0.0",
42
+ "@types/node": "^25.6.2",
43
+ "@vitest/coverage-v8": "^4.1.5",
44
+ "jsdom": "^29.1.1",
45
+ "msw": "^2.14.5",
46
+ "oxfmt": "^0.48.0",
47
+ "oxlint": "^1.63.0",
48
+ "oxlint-tsgolint": "^0.22.1",
49
+ "rolldown": "^1.0.0",
50
+ "typescript": "^6.0.3",
51
+ "vitest": "^4.1.5"
36
52
  },
37
53
  "scripts": {
38
- "build": "rm -rf types && tsc -p ./tsconfig.build.json",
54
+ "build": "rm -rf dist && rolldown -c && tsc -p tsconfig.json --emitDeclarationOnly",
39
55
  "check": "pnpm build && pnpm lint && pnpm test && pnpm typecheck",
40
56
  "format": "oxfmt --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json,css}\"",
41
57
  "lint": "oxlint src",
@@ -0,0 +1,7 @@
1
+ import { HTTP_100_CONTINUE, HTTP_STATUS_MAP } from './http_status.js';
2
+
3
+ describe('http_status', () => {
4
+ test('HTTP status name from code', () => {
5
+ expect(HTTP_STATUS_MAP[HTTP_100_CONTINUE]).toBe('HTTP_100_CONTINUE');
6
+ });
7
+ });
@@ -66,7 +66,7 @@ export const HTTP_508_LOOP_DETECTED = 508;
66
66
  export const HTTP_510_NOT_EXTENDED = 510;
67
67
  export const HTTP_511_NETWORK_AUTHENTICATION_REQUIRED = 511;
68
68
 
69
- export const HTTP_STATUS_MAP = {
69
+ export const HTTP_STATUS_MAP: Record<number, string> = {
70
70
  [HTTP_100_CONTINUE]: 'HTTP_100_CONTINUE',
71
71
  [HTTP_101_SWITCHING_PROTOCOLS]: 'HTTP_101_SWITCHING_PROTOCOLS',
72
72
  [HTTP_102_PROCESSING]: 'HTTP_102_PROCESSING',
@@ -1,9 +1,11 @@
1
1
  export * from './const/http_status.js';
2
2
  export { AbstractLogHandler } from './logging/AbstractLogHandler.js';
3
+ export type { LogExtra } from './logging/AbstractLogHandler.js';
3
4
  export { ConsoleLogHandler } from './logging/ConsoleLogHandler.js';
4
5
  export * from './logging/const.js';
5
6
  export { Logger } from './logging/Logger.js';
6
7
  export { OpenTelemetryLogHandler } from './logging/OpenTelemetryLogHandler.js';
8
+ export type { OpenTelemetryLogEmitter } from './logging/OpenTelemetryLogHandler.js';
7
9
  export { SentryLogHandler } from './logging/SentryLogHandler.js';
8
10
  export { formatLogMessage, getLogLevelName } from './logging/util.js';
9
11
  export * from './pagelifecycle/const.js';
@@ -18,11 +20,16 @@ export {
18
20
  } from './pagelifecycle/util.js';
19
21
  export { typeChecker } from './typecheck/TypeChecker.js';
20
22
  export { TypeCheckError } from './typecheck/TypeCheckError.js';
23
+ export type { TypeCheckErrorOptions } from './typecheck/TypeCheckError.js';
21
24
  export { typeCheck, typeCheckArray, typeCheckEnum } from './typecheck/util.js';
25
+ export type { EnumChoices } from './typecheck/util.js';
22
26
  export { delayPromise, loadJSON, retryAsync } from './util/async.js';
23
27
  export { getErrorDetails, getTypedError } from './util/error.js';
28
+ export type { ErrorDetails } from './util/error.js';
24
29
  export { EventEmitter } from './util/event_emitter.js';
30
+ export type { EventListener } from './util/event_emitter.js';
25
31
  export { FetchError, fetchRetry, HTTP_0_ANY } from './util/fetch.js';
32
+ export type { FetchRetryOptions } from './util/fetch.js';
26
33
  export {
27
34
  deg2rad,
28
35
  fixFloatPrecision,
@@ -41,3 +48,4 @@ export { serverDataToState } from './util/state.js';
41
48
  export { addLeadingZero, capitalize, getTypeFromValue, saveAsFile, underscoreToCamelCase } from './util/string.js';
42
49
  export { uuidv4 } from './util/uuid.js';
43
50
  export * from './util/validate.js';
51
+ export type { Validator } from './util/validate.js';
@@ -0,0 +1,31 @@
1
+ import type { Logger } from './Logger.js';
2
+
3
+ export interface LogExtra {
4
+ tags?: Record<string, string | number | boolean | null | undefined>;
5
+ [key: string]: unknown;
6
+ }
7
+
8
+ export class AbstractLogHandler {
9
+ level: number;
10
+
11
+ /**
12
+ * Abstract log handler.
13
+ */
14
+ constructor(level: number) {
15
+ this.level = level;
16
+ }
17
+
18
+ /**
19
+ * Emit log record.
20
+ */
21
+ emit(
22
+ _logger: Logger,
23
+ _timestamp: number,
24
+ _level: number,
25
+ _message: string,
26
+ _extra: LogExtra | null | undefined,
27
+ _error: Error | null | undefined
28
+ ): void {
29
+ throw new Error('Not implemented.');
30
+ }
31
+ }
@@ -1,8 +1,11 @@
1
- import { AbstractLogHandler } from './AbstractLogHandler.js';
1
+ import { AbstractLogHandler, type LogExtra } from './AbstractLogHandler.js';
2
2
  import { LOG_LEVEL_DEBUG } from './const.js';
3
+ import type { Logger } from './Logger.js';
3
4
  import { formatLogMessage } from './util.js';
4
5
 
5
- const CONSOLE_FUNCTIONS = [
6
+ type ConsoleFn = (...data: unknown[]) => void;
7
+
8
+ const CONSOLE_FUNCTIONS: ReadonlyArray<ConsoleFn | null> = [
6
9
  null, // silent
7
10
  console.error, // fatal
8
11
  console.error, // error
@@ -14,29 +17,28 @@ const CONSOLE_FUNCTIONS = [
14
17
  export class ConsoleLogHandler extends AbstractLogHandler {
15
18
  /**
16
19
  * Console log handler.
17
- * @param {number} level - Log handler level.
18
20
  */
19
- constructor(level = LOG_LEVEL_DEBUG) {
21
+ constructor(level: number = LOG_LEVEL_DEBUG) {
20
22
  super(level);
21
23
  }
22
24
 
23
25
  /**
24
26
  * Emit log record.
25
- * @param {import('./Logger.js').Logger} logger - Logger instance.
26
- * @param {number} timestamp - Log timestamp.
27
- * @param {number} level - Log level.
28
- * @param {string} message - Log message.
29
- * @param {object | null | undefined} extra - Log extra data.
30
- * @param {Error | null | undefined} error - Log error.
31
- * @throws {Error}
32
27
  */
33
- emit(logger, timestamp, level, message, extra, error) {
28
+ override emit(
29
+ logger: Logger,
30
+ timestamp: number,
31
+ level: number,
32
+ message: string,
33
+ extra: LogExtra | null | undefined,
34
+ error: Error | null | undefined
35
+ ): void {
34
36
  if (logger.level < level) {
35
37
  return;
36
38
  }
37
39
  const logMessage = formatLogMessage(logger, timestamp, level, message);
38
40
  const consoleFunction = CONSOLE_FUNCTIONS[level];
39
- if (consoleFunction === null) {
41
+ if (consoleFunction === null || consoleFunction === undefined) {
40
42
  return;
41
43
  }
42
44
  if (error) {
@@ -0,0 +1,69 @@
1
+ import { AbstractLogHandler, type LogExtra } from './AbstractLogHandler.js';
2
+ import { LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_INFO, LOG_LEVEL_WARNING } from './const.js';
3
+ import { Logger } from './Logger.js';
4
+
5
+ class TestLogHandler extends AbstractLogHandler {
6
+ emitLogLogger: Logger | null = null;
7
+ emitLogTimestamp: number | null = null;
8
+ emitLogLevel: number | null = null;
9
+ emitLogMessage: string | null = null;
10
+ emitLogExtra: LogExtra | null | undefined = null;
11
+ emitLogError: Error | null | undefined = null;
12
+
13
+ constructor() {
14
+ super(LOG_LEVEL_DEBUG);
15
+ }
16
+
17
+ override emit(
18
+ logger: Logger,
19
+ timestamp: number,
20
+ level: number,
21
+ message: string,
22
+ extra: LogExtra | null | undefined,
23
+ error: Error | null | undefined
24
+ ): void {
25
+ this.emitLogLogger = logger;
26
+ this.emitLogTimestamp = timestamp;
27
+ this.emitLogLevel = level;
28
+ this.emitLogMessage = message;
29
+ this.emitLogExtra = extra;
30
+ this.emitLogError = error;
31
+ }
32
+ }
33
+
34
+ test('Tests Logger default level', () => {
35
+ const logger = new Logger('test');
36
+ expect(logger.level).toBe(LOG_LEVEL_DEBUG);
37
+ });
38
+
39
+ test('Tests Logger custom handler', () => {
40
+ const logger = new Logger('test');
41
+ const testLogHandler = new TestLogHandler();
42
+ Logger.addHandler(testLogHandler);
43
+ // debug
44
+ logger.debug('debug');
45
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_DEBUG);
46
+ expect(testLogHandler.emitLogMessage).toBe('debug');
47
+ // info
48
+ logger.info('info');
49
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_INFO);
50
+ expect(testLogHandler.emitLogMessage).toBe('info');
51
+ // warning
52
+ logger.warn('warning');
53
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_WARNING);
54
+ expect(testLogHandler.emitLogMessage).toBe('warning');
55
+ logger.warning('warning');
56
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_WARNING);
57
+ expect(testLogHandler.emitLogMessage).toBe('warning');
58
+ // error
59
+ logger.error('error');
60
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_ERROR);
61
+ expect(testLogHandler.emitLogMessage).toBe('error');
62
+ // exception
63
+ logger.exception('test', new Error('test_error'), { context: 'ctx' });
64
+ expect(testLogHandler.emitLogLevel).toBe(LOG_LEVEL_FATAL);
65
+ expect(testLogHandler.emitLogMessage).toBe('test');
66
+ expect(testLogHandler.emitLogError?.message).toBe('test_error');
67
+ expect(testLogHandler.emitLogLogger).toBe(logger);
68
+ expect(testLogHandler.emitLogExtra?.['context']).toBe('ctx');
69
+ });
@@ -0,0 +1,77 @@
1
+ import { getURLParam } from '../util/query.js';
2
+ import type { AbstractLogHandler, LogExtra } from './AbstractLogHandler.js';
3
+ import {
4
+ LOG_LEVEL_DEBUG,
5
+ LOG_LEVEL_ERROR,
6
+ LOG_LEVEL_FATAL,
7
+ LOG_LEVEL_INFO,
8
+ LOG_LEVEL_SILENT,
9
+ LOG_LEVEL_WARNING,
10
+ } from './const.js';
11
+ import { getAppEnvironment } from './util.js';
12
+
13
+ const ROOT_LOGGER_NAME = 'root';
14
+
15
+ export class Logger {
16
+ static handlers: AbstractLogHandler[] = [];
17
+
18
+ name: string;
19
+ level: number;
20
+
21
+ /**
22
+ * Creates a new Logger instance.
23
+ */
24
+ constructor(name: string = ROOT_LOGGER_NAME) {
25
+ this.name = name ?? ROOT_LOGGER_NAME;
26
+ const appEnvironment = getAppEnvironment();
27
+ const isProduction = appEnvironment === 'production' || appEnvironment === 'release';
28
+ const defaultLevel = isProduction ? LOG_LEVEL_SILENT : LOG_LEVEL_DEBUG;
29
+ const parameterName = `log_${this.name.toLowerCase()}`;
30
+ const paramLevel =
31
+ getURLParam(parameterName, getURLParam('log_all', defaultLevel.toString())) ?? defaultLevel.toString();
32
+ this.level = Number.parseInt(paramLevel, 10);
33
+ }
34
+
35
+ static addHandler = (handler: AbstractLogHandler): void => {
36
+ Logger.handlers.push(handler);
37
+ };
38
+
39
+ static emit = (
40
+ logger: Logger,
41
+ level: number,
42
+ message: string,
43
+ extra?: LogExtra | null,
44
+ error?: Error | null
45
+ ): void => {
46
+ const timestamp = Date.now();
47
+ for (const handler of Logger.handlers) {
48
+ if (handler.level >= level) {
49
+ handler.emit(logger, timestamp, level, message, extra, error);
50
+ }
51
+ }
52
+ };
53
+
54
+ debug(message: string, extra?: LogExtra | null): void {
55
+ Logger.emit(this, LOG_LEVEL_DEBUG, message, extra);
56
+ }
57
+
58
+ info(message: string, extra?: LogExtra | null): void {
59
+ Logger.emit(this, LOG_LEVEL_INFO, message, extra);
60
+ }
61
+
62
+ warn(message: string, extra?: LogExtra | null): void {
63
+ Logger.emit(this, LOG_LEVEL_WARNING, message, extra);
64
+ }
65
+
66
+ warning(message: string, extra?: LogExtra | null): void {
67
+ Logger.emit(this, LOG_LEVEL_WARNING, message, extra);
68
+ }
69
+
70
+ error(message: string, extra?: LogExtra | null): void {
71
+ Logger.emit(this, LOG_LEVEL_ERROR, message, extra);
72
+ }
73
+
74
+ exception(message: string, error: Error, extra?: LogExtra | null): void {
75
+ Logger.emit(this, LOG_LEVEL_FATAL, message, extra, error);
76
+ }
77
+ }
@@ -0,0 +1,40 @@
1
+ import { AbstractLogHandler, type LogExtra } from './AbstractLogHandler.js';
2
+ import type { Logger } from './Logger.js';
3
+
4
+ export type OpenTelemetryLogEmitter = (
5
+ logger: Logger,
6
+ timestamp: number,
7
+ level: number,
8
+ message: string,
9
+ extra: LogExtra | null | undefined,
10
+ error: Error | null | undefined
11
+ ) => void;
12
+
13
+ export class OpenTelemetryLogHandler extends AbstractLogHandler {
14
+ emitter: OpenTelemetryLogEmitter;
15
+
16
+ /**
17
+ * Open Telemetry log handler.
18
+ */
19
+ constructor(level: number, emitter: OpenTelemetryLogEmitter) {
20
+ super(level);
21
+ this.emitter = emitter;
22
+ }
23
+
24
+ /**
25
+ * Emit log record.
26
+ */
27
+ override emit(
28
+ logger: Logger,
29
+ timestamp: number,
30
+ level: number,
31
+ message: string,
32
+ extra: LogExtra | null | undefined,
33
+ error: Error | null | undefined
34
+ ): void {
35
+ if (!this.emitter) {
36
+ return;
37
+ }
38
+ this.emitter(logger, timestamp, level, message, extra, error);
39
+ }
40
+ }
@@ -0,0 +1,44 @@
1
+ import { addBreadcrumb, captureException, captureMessage, type SeverityLevel } from '@sentry/browser';
2
+ import { AbstractLogHandler, type LogExtra } from './AbstractLogHandler.js';
3
+ import { LOG_LEVEL_DEBUG, LOG_LEVEL_WARNING } from './const.js';
4
+ import type { Logger } from './Logger.js';
5
+ import { getLogLevelName } from './util.js';
6
+
7
+ export class SentryLogHandler extends AbstractLogHandler {
8
+ /**
9
+ * Sentry log handler.
10
+ */
11
+ constructor(level: number = LOG_LEVEL_DEBUG) {
12
+ super(level);
13
+ }
14
+
15
+ /**
16
+ * Emit log record.
17
+ */
18
+ override emit(
19
+ logger: Logger,
20
+ _timestamp: number,
21
+ level: number,
22
+ message: string,
23
+ extra: LogExtra | null | undefined,
24
+ error: Error | null | undefined
25
+ ): void {
26
+ const levelName = getLogLevelName(level) as SeverityLevel;
27
+ const logMessage = `[${logger.name}] ${message}`;
28
+ const breadcrumb = {
29
+ type: 'default',
30
+ category: 'console',
31
+ message: logMessage,
32
+ level: levelName,
33
+ data: extra ?? undefined,
34
+ };
35
+ addBreadcrumb(breadcrumb);
36
+ if (error) {
37
+ extra?.tags ? captureException(error, { tags: extra.tags }) : captureException(error);
38
+ } else if (level === LOG_LEVEL_WARNING) {
39
+ extra?.tags
40
+ ? captureMessage(logMessage, { level: 'warning', tags: extra.tags })
41
+ : captureMessage(logMessage, { level: 'warning' });
42
+ }
43
+ }
44
+ }