@hkdigital/lib-core 0.4.12 → 0.4.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.
Files changed (133) hide show
  1. package/README.md +4 -1
  2. package/dist/auth/errors.d.ts +1 -1
  3. package/dist/auth/errors.js +1 -1
  4. package/dist/auth/jwt/constants.d.ts +6 -0
  5. package/dist/auth/jwt/constants.js +13 -0
  6. package/dist/auth/jwt/core.d.ts +38 -0
  7. package/dist/auth/jwt/core.js +114 -0
  8. package/dist/auth/jwt/errors.d.ts +39 -0
  9. package/dist/auth/jwt/errors.js +74 -0
  10. package/dist/auth/jwt/generators.d.ts +29 -0
  11. package/dist/auth/jwt/generators.js +53 -0
  12. package/dist/auth/jwt/typedef.d.ts +159 -0
  13. package/dist/auth/jwt/typedef.js +72 -0
  14. package/dist/auth/jwt/util.d.ts +6 -0
  15. package/dist/auth/jwt/util.js +43 -0
  16. package/dist/auth/jwt.d.ts +4 -0
  17. package/dist/auth/jwt.js +12 -0
  18. package/dist/generic/data/classes/IterableTree.js +1 -1
  19. package/dist/generic/data/classes/Selector.js +1 -1
  20. package/dist/generic/promises/classes/HkPromise.js +1 -1
  21. package/dist/generic/streaming/classes/ServerEventsStore.js +1 -1
  22. package/dist/generic/typedef.d.ts +2 -0
  23. package/dist/generic/typedef.js +2 -0
  24. package/dist/logging/internal/adapters/console.js +3 -3
  25. package/dist/logging/internal/adapters/pino.js +17 -3
  26. package/dist/logging/internal/adapters/pino.js__ +260 -0
  27. package/dist/logging/internal/test-errors.js +3 -2
  28. package/dist/network/http/errors.js +10 -4
  29. package/dist/network/http/headers.js +1 -1
  30. package/dist/network/http/http-request.js +1 -1
  31. package/dist/network/http/json-request.js +1 -1
  32. package/dist/network/http/response.js +1 -1
  33. package/dist/network/loaders/audio/AudioScene.svelte.js +1 -1
  34. package/dist/network/loaders/image/ImageScene.svelte.js +1 -1
  35. package/dist/network/loaders/image/utils/index.js +1 -1
  36. package/dist/network/states/NetworkLoader.svelte.js +1 -1
  37. package/dist/network/typedef.d.ts +2 -0
  38. package/dist/network/typedef.js +3 -1
  39. package/dist/services/service-base/ServiceBase.js +1 -3
  40. package/dist/services/typedef.d.ts +2 -0
  41. package/dist/services/typedef.js +2 -0
  42. package/dist/state/typedef.d.ts +3 -0
  43. package/dist/state/typedef.js +3 -0
  44. package/dist/ui/components/drag-drop/drag-state.svelte.d.ts +3 -3
  45. package/dist/ui/components/hk-app-layout/HkAppLayout.state.svelte.d.ts +3 -3
  46. package/dist/ui/components/presenter/util.js +1 -1
  47. package/dist/ui/components/tab-bar/HkTabBar.state.svelte.d.ts +3 -3
  48. package/dist/ui/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +3 -3
  49. package/dist/util/array/index.d.ts +0 -4
  50. package/dist/util/array/index.js +1 -5
  51. package/dist/util/array.d.ts +1 -0
  52. package/dist/util/array.js +9 -0
  53. package/dist/util/bases/base64.d.ts +8 -0
  54. package/dist/util/bases/base64.js +23 -0
  55. package/dist/util/bases/index.d.ts +0 -1
  56. package/dist/util/bases/index.js +0 -1
  57. package/dist/util/bases.d.ts +2 -0
  58. package/dist/util/bases.js +10 -0
  59. package/dist/util/compare.d.ts +1 -0
  60. package/dist/util/compare.js +9 -0
  61. package/dist/util/css/index.d.ts +0 -1
  62. package/dist/util/css/index.js +0 -1
  63. package/dist/util/css.d.ts +1 -0
  64. package/dist/util/css.js +8 -0
  65. package/dist/util/env.d.ts +1 -0
  66. package/dist/util/env.js +8 -0
  67. package/dist/util/exceptions.d.ts +1 -0
  68. package/dist/util/exceptions.js +8 -0
  69. package/dist/util/expect/arrays.js +2 -0
  70. package/dist/util/expect/compounds.d.ts +20 -0
  71. package/dist/util/expect/compounds.js +48 -0
  72. package/dist/util/expect/objects.d.ts +28 -0
  73. package/dist/util/expect/objects.js +70 -0
  74. package/dist/util/expect/primitives.d.ts +31 -1
  75. package/dist/util/expect/primitives.js +56 -0
  76. package/dist/util/expect/values.d.ts +26 -0
  77. package/dist/util/expect/values.js +48 -0
  78. package/dist/util/expect.d.ts +6 -0
  79. package/dist/util/expect.js +31 -0
  80. package/dist/util/function/index.js +1 -1
  81. package/dist/util/function.d.ts +1 -0
  82. package/dist/util/function.js +8 -0
  83. package/dist/util/geometry.d.ts +1 -0
  84. package/dist/util/geometry.js +9 -0
  85. package/dist/util/is.d.ts +1 -0
  86. package/dist/util/is.js +8 -0
  87. package/dist/util/iterate/index.js +1 -1
  88. package/dist/util/iterate.d.ts +1 -0
  89. package/dist/util/iterate.js +8 -0
  90. package/dist/util/object/index.js +2 -2
  91. package/dist/util/object.d.ts +1 -0
  92. package/dist/util/object.js +8 -0
  93. package/dist/util/random/bytes.d.ts +28 -0
  94. package/dist/util/random/bytes.js +72 -0
  95. package/dist/util/random.d.ts +1 -0
  96. package/dist/util/random.js +9 -0
  97. package/dist/util/singleton/index.js +1 -1
  98. package/dist/util/singleton.d.ts +1 -0
  99. package/dist/util/singleton.js +8 -0
  100. package/dist/util/ssr.d.ts +1 -0
  101. package/dist/util/ssr.js +8 -0
  102. package/dist/util/string/convert.js +1 -1
  103. package/dist/util/string/index.d.ts +0 -5
  104. package/dist/util/string/index.js +0 -5
  105. package/dist/util/string/interpolate.js +1 -1
  106. package/dist/util/string.d.ts +5 -0
  107. package/dist/util/string.js +12 -0
  108. package/dist/util/svelte/index.d.ts +0 -3
  109. package/dist/util/svelte/index.js +0 -4
  110. package/dist/util/svelte.d.ts +3 -0
  111. package/dist/util/svelte.js +11 -0
  112. package/dist/util/sveltekit/index.d.ts +0 -1
  113. package/dist/util/sveltekit/index.js +0 -1
  114. package/dist/util/sveltekit/route-folders/index.js +1 -1
  115. package/dist/util/sveltekit.d.ts +1 -0
  116. package/dist/util/sveltekit.js +8 -0
  117. package/dist/util/time/index.d.ts +7 -0
  118. package/dist/util/time/index.js +12 -1
  119. package/dist/util/time.d.ts +1 -0
  120. package/dist/util/time.js +1 -0
  121. package/dist/util/unique.d.ts +1 -0
  122. package/dist/util/unique.js +8 -0
  123. package/dist/valibot/{index.d.ts → valibot.d.ts} +1 -2
  124. package/dist/valibot/{index.js → valibot.js} +1 -6
  125. package/package.json +3 -1
  126. package/dist/auth/errors/jwt.d.ts +0 -8
  127. package/dist/auth/errors/jwt.js +0 -5
  128. package/dist/util/expect/index.d.ts +0 -103
  129. package/dist/util/expect/index.js +0 -259
  130. package/dist/util/index.d.ts +0 -10
  131. /package/dist/util/{geo → geometry}/index.d.ts +0 -0
  132. /package/dist/util/{geo → geometry}/index.js +0 -0
  133. /package/dist/util/{index.js → index.js__} +0 -0
@@ -0,0 +1,72 @@
1
+ /**
2
+ * bytes.js
3
+ *
4
+ * @description
5
+ * Cross-platform random byte generation utilities using Web Crypto API
6
+ */
7
+
8
+ import * as expect from '../expect.js';
9
+
10
+ /**
11
+ * Generate cryptographically secure random bytes
12
+ * - Uses Web Crypto API (works in Node.js 16+ and all modern browsers)
13
+ * - Returns Uint8Array for maximum compatibility
14
+ *
15
+ * @param {number} length - Number of bytes to generate
16
+ *
17
+ * @returns {Uint8Array} Random bytes
18
+ */
19
+ export function randomBytes(length) {
20
+ expect.positiveNumber(length);
21
+
22
+ if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
23
+ // Modern browsers + Node.js 16+
24
+ return crypto.getRandomValues(new Uint8Array(length));
25
+ } else if (typeof require !== 'undefined') {
26
+ // Fallback for older Node.js environments
27
+ try {
28
+ const { randomBytes: nodeRandomBytes } = require('crypto');
29
+ return new Uint8Array(nodeRandomBytes(length));
30
+ } catch (error) {
31
+ throw new Error('No secure random generator available');
32
+ }
33
+ } else {
34
+ throw new Error('No secure random generator available');
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Generate random bytes and return as base64 string
40
+ * - Cross-platform base64 encoding
41
+ *
42
+ * @param {number} length - Number of bytes to generate
43
+ *
44
+ * @returns {string} Base64 encoded random bytes
45
+ */
46
+ export function randomBytesBase64(length) {
47
+ const bytes = randomBytes(length);
48
+
49
+ // Convert to base64 using available method
50
+ if (typeof Buffer !== 'undefined') {
51
+ // Node.js - most efficient
52
+ return Buffer.from(bytes).toString('base64');
53
+ } else {
54
+ // Browser - use btoa
55
+ return btoa(String.fromCharCode(...bytes));
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Generate random bytes and return as hex string
61
+ * - Cross-platform hex encoding
62
+ *
63
+ * @param {number} length - Number of bytes to generate
64
+ *
65
+ * @returns {string} Hex encoded random bytes
66
+ */
67
+ export function randomBytesHex(length) {
68
+ const bytes = randomBytes(length);
69
+
70
+ // Convert to hex string
71
+ return Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
72
+ }
@@ -0,0 +1 @@
1
+ export * from "./random/bytes.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Random utilities main export
3
+ *
4
+ * @description
5
+ * This module provides cross-platform random generation utilities
6
+ * using the Web Crypto API for maximum compatibility.
7
+ */
8
+
9
+ export * from './random/bytes.js';
@@ -1,4 +1,4 @@
1
- import { expect } from '../index.js';
1
+ import * as expect from '../expect.js';
2
2
 
3
3
  const instancesByNeedle = new Map();
4
4
 
@@ -0,0 +1 @@
1
+ export * from "./singleton/index.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Singleton utilities main export
3
+ *
4
+ * @description
5
+ * This module provides singleton pattern utilities.
6
+ */
7
+
8
+ export * from './singleton/index.js';
@@ -0,0 +1 @@
1
+ export * from "./ssr/index.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Server-side rendering utilities main export
3
+ *
4
+ * @description
5
+ * This module provides SSR-related utilities for SvelteKit applications.
6
+ */
7
+
8
+ export * from './ssr/index.js';
@@ -1,4 +1,4 @@
1
- import * as expect from '../expect/index.js';
1
+ import * as expect from '../expect.js';
2
2
 
3
3
  /**
4
4
  * Remove strange characters from a string and replace whitespace by
@@ -1,5 +0,0 @@
1
- export * from "./array-path.js";
2
- export * from "./convert.js";
3
- export * from "./fs.js";
4
- export * from "./interpolate.js";
5
- export * from "./pad.js";
@@ -1,5 +0,0 @@
1
- export * from './array-path.js';
2
- export * from './convert.js';
3
- export * from './fs.js';
4
- export * from './interpolate.js';
5
- export * from './pad.js';
@@ -1,4 +1,4 @@
1
- import * as expect from '../expect/index.js';
1
+ import * as expect from '../expect.js';
2
2
 
3
3
  import { toArrayPath } from '../array/index.js';
4
4
 
@@ -0,0 +1,5 @@
1
+ export * from "./string/array-path.js";
2
+ export * from "./string/convert.js";
3
+ export * from "./string/fs.js";
4
+ export * from "./string/interpolate.js";
5
+ export * from "./string/pad.js";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * String utilities main export
3
+ *
4
+ * @description
5
+ * This module provides string manipulation and processing utilities.
6
+ */
7
+
8
+ export * from './string/array-path.js';
9
+ export * from './string/convert.js';
10
+ export * from './string/fs.js';
11
+ export * from './string/interpolate.js';
12
+ export * from './string/pad.js';
@@ -1,3 +0,0 @@
1
- export * as observe from "./observe/index.js";
2
- export * as stateContext from "../../state/context/state-context.js";
3
- export * as loading from "./loading/loading-tracker.svelte.js";
@@ -1,4 +0,0 @@
1
- export * as observe from './observe/index.js';
2
- export * as stateContext from '../../state/context/state-context.js';
3
-
4
- export * as loading from './loading/loading-tracker.svelte.js';
@@ -0,0 +1,3 @@
1
+ export * from "./svelte/loading/loading-tracker.svelte.js";
2
+ export * from "./svelte/observe/index.js";
3
+ export * from "./svelte/wait/index.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Svelte utilities main export
3
+ *
4
+ * @description
5
+ * This module provides Svelte-specific utilities including loading trackers,
6
+ * observers, and waiting utilities.
7
+ */
8
+
9
+ export * from './svelte/loading/loading-tracker.svelte.js';
10
+ export * from './svelte/observe/index.js';
11
+ export * from './svelte/wait/index.js';
@@ -1 +0,0 @@
1
- export * from "./route-folders/index.js";
@@ -1 +0,0 @@
1
- export * from './route-folders/index.js';
@@ -1,7 +1,7 @@
1
1
  import { readdir } from 'node:fs/promises';
2
2
  import { join, resolve } from 'node:path';
3
3
 
4
- import { kebabToTitleCase, basename } from '../../string/index.js';
4
+ import { kebabToTitleCase, basename } from '../../string.js';
5
5
 
6
6
  /**
7
7
  * Validates if a path is within the project's src/routes directory
@@ -0,0 +1 @@
1
+ export * from "./sveltekit/route-folders/index.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * SvelteKit utilities main export
3
+ *
4
+ * @description
5
+ * This module provides SvelteKit-specific utilities including route management.
6
+ */
7
+
8
+ export * from './sveltekit/route-folders/index.js';
@@ -13,6 +13,13 @@
13
13
  * @returns {HkPromise} promise that resolves after a specified timeout
14
14
  */
15
15
  export function delay(delayOrMinDelayMs: number, maxDelayMs?: number): HkPromise<any>;
16
+ /**
17
+ * Returns Date.now(), later this method may be extended with time
18
+ * synchronisaiton
19
+ *
20
+ * @return {number} date timestamp
21
+ */
22
+ export function now(): number;
16
23
  /**
17
24
  * Get the number of milliseconds since the specified time stamp of the default
18
25
  * reference time stamp TIME_2025_01_01
@@ -85,6 +85,17 @@ export function delay(delayOrMinDelayMs, maxDelayMs) {
85
85
  return promise;
86
86
  }
87
87
 
88
+ /**
89
+ * Returns Date.now(), later this method may be extended with time
90
+ * synchronisaiton
91
+ *
92
+ * @return {number} date timestamp
93
+ */
94
+ export function now()
95
+ {
96
+ return Date.now();
97
+ }
98
+
88
99
  /**
89
100
  * Get the number of milliseconds since the specified time stamp of the default
90
101
  * reference time stamp TIME_2025_01_01
@@ -94,7 +105,7 @@ export function delay(delayOrMinDelayMs, maxDelayMs) {
94
105
  * @returns {number} number of milliseconds since the specified time
95
106
  */
96
107
  export function sinceMs(sinceMs = TIME_2025_01_01) {
97
- return Date.now() - sinceMs;
108
+ return now() - sinceMs;
98
109
  }
99
110
 
100
111
  /**
@@ -0,0 +1 @@
1
+ export * from "./time/index.js";
@@ -0,0 +1 @@
1
+ export * from './time/index.js';
@@ -0,0 +1 @@
1
+ export * from "./unique/index.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Unique value utilities main export
3
+ *
4
+ * @description
5
+ * This module provides utilities for generating and working with unique values.
6
+ */
7
+
8
+ export * from './unique/index.js';
@@ -1,4 +1,3 @@
1
- export * from "./parsers.js";
2
- export default valibot;
3
1
  export const v: any;
4
2
  import * as valibot from 'valibot';
3
+ export { valibot };
@@ -1,9 +1,5 @@
1
1
  import * as valibot from 'valibot';
2
2
 
3
- // export * from './date.js';
4
-
5
- export * from './parsers.js';
6
-
7
3
  /**
8
4
  * Custom parse function that wraps valibot's original parse
9
5
  * for better stack trace detection in error logging
@@ -30,5 +26,4 @@ Object.defineProperty(v, 'parse', {
30
26
  configurable: true
31
27
  });
32
28
 
33
- export { v };
34
- export default valibot;
29
+ export { v, valibot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.4.12",
3
+ "version": "0.4.13",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"
@@ -77,6 +77,7 @@
77
77
  "@steeze-ui/heroicons": "^2.4.2",
78
78
  "@sveltejs/kit": "^2.28.0",
79
79
  "eslint-plugin-import": "^2.32.0",
80
+ "jsonwebtoken": "^9.0.0",
80
81
  "pino": "^9.8.0",
81
82
  "pino-pretty": "^13.1.1",
82
83
  "runed": "^0.31.1",
@@ -107,6 +108,7 @@
107
108
  "fake-indexeddb": "^6.1.0",
108
109
  "globals": "^16.3.0",
109
110
  "jsdom": "^26.1.0",
111
+ "jsonwebtoken": "^9.0.0",
110
112
  "npm-check-updates": "^18.0.2",
111
113
  "npm-run-all": "^4.1.5",
112
114
  "pino": "^9.8.0",
@@ -1,8 +0,0 @@
1
- export class SecretKeyError extends Error {
2
- }
3
- export class TokenExpiredError extends Error {
4
- }
5
- export class JsonWebTokenError extends Error {
6
- }
7
- export class InvalidSignatureError extends Error {
8
- }
@@ -1,5 +0,0 @@
1
- export class SecretKeyError extends Error {}
2
- export class TokenExpiredError extends Error {}
3
-
4
- export class JsonWebTokenError extends Error {}
5
- export class InvalidSignatureError extends Error {}
@@ -1,103 +0,0 @@
1
- /**
2
- * Throws a validation error if value is not an Error instance
3
- *
4
- * @param {any} value
5
- */
6
- export function error_(value: any): void;
7
- /**
8
- * Expect a value not to be null
9
- *
10
- * @param {any} value
11
- */
12
- export function notNull(value: any): void;
13
- /**
14
- * Expect a value to be a boolean and true
15
- *
16
- * @param {any} value
17
- */
18
- export function _true(value: any): void;
19
- /**
20
- * Expect a positive number
21
- *
22
- * @param {any} value
23
- */
24
- export function positiveNumber(value: any): void;
25
- /**
26
- * Throws a validation error if value is not a string
27
- *
28
- * @param {any} value
29
- */
30
- export function notEmptyString(value: any): void;
31
- /**
32
- * Throws a validation error if value is not iterable
33
- *
34
- * @param {any} value
35
- */
36
- export function iterable(value: any): void;
37
- /**
38
- * Throws a validation error if value is not a a store (has not subscribe
39
- * method)
40
- *
41
- * @param {any} value
42
- */
43
- export function store(value: any): void;
44
- /**
45
- * Throws a validation error if value is not an object or the value
46
- * is an array
47
- *
48
- * @param {any} value
49
- */
50
- export function objectNoArray(value: any): void;
51
- /**
52
- * Throws a validation error if value is not an object or the value
53
- * is a function
54
- *
55
- * @param {any} value
56
- */
57
- export function objectNoFunction(value: any): void;
58
- /**
59
- * Throws a validation error if value is not an object or null
60
- *
61
- * @param {any} value
62
- */
63
- export function objectOrNull(value: any): void;
64
- /**
65
- * Throws a validation error if value is not an array or Set
66
- *
67
- * @param {any} value
68
- */
69
- export function arrayOrSet(value: any): void;
70
- export * from "./arrays.js";
71
- export * from "./primitives.js";
72
- export * from "./url.js";
73
- /**
74
- * Throws a validation error if value is not an object
75
- *
76
- * @param {any} value
77
- */
78
- declare function object_(value: any): void;
79
- /**
80
- * Throws a validation error if value is not a function
81
- *
82
- * @param {any} value
83
- */
84
- declare function function_(value: any): void;
85
- /**
86
- * Throws a validation error if value is not a Promise
87
- *
88
- * @param {any} value
89
- */
90
- declare function promise_(value: any): void;
91
- /**
92
- * Throws a validation error if value is not a Map
93
- *
94
- * @param {any} value
95
- */
96
- declare function map_(value: any): void;
97
- /**
98
- * Throws a validation error if value is not a Set
99
- *
100
- * @param {any} value
101
- */
102
- declare function set_(value: any): void;
103
- export { object_ as object, function_ as function, _function as function, function_ as class, _class as class, promise_ as promise, map_ as map, set_ as set, error_ as error, _true as true, _true as true };