@hkdigital/lib-core 0.4.14 → 0.4.16
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/dist/auth/jwt/util.js +2 -0
- package/dist/auth/jwt.d.ts +1 -0
- package/dist/auth/jwt.js +1 -1
- package/dist/constants/bases.d.ts +1 -0
- package/dist/constants/bases.js +1 -0
- package/dist/constants/http.d.ts +2 -0
- package/dist/constants/http.js +2 -0
- package/dist/constants/mime.d.ts +4 -0
- package/dist/constants/mime.js +4 -0
- package/dist/constants/regexp.d.ts +3 -0
- package/dist/constants/regexp.js +3 -0
- package/dist/constants/states/drag.d.ts +1 -1
- package/dist/constants/states/drag.js +1 -1
- package/dist/constants/states/submit.d.ts +1 -1
- package/dist/constants/states/submit.js +1 -1
- package/dist/constants/states.d.ts +4 -0
- package/dist/constants/states.js +4 -0
- package/dist/constants/time.d.ts +1 -0
- package/dist/constants/time.js +1 -0
- package/dist/logging/README.md +5 -14
- package/dist/logging/internal/logger/Logger.d.ts +7 -3
- package/dist/logging/internal/logger/Logger.js +83 -25
- package/dist/logging/internal/logger/util.d.ts +13 -0
- package/dist/logging/internal/logger/util.js +47 -0
- package/dist/network/http/errors.js +2 -2
- package/dist/network/http/index.js +2 -2
- package/dist/network/http/mocks.js +2 -2
- package/dist/network/loaders/audio/mocks.js +1 -1
- package/dist/network/loaders/image/mocks.js +1 -1
- package/dist/network/states/NetworkLoader.svelte.js +1 -1
- package/dist/network/states/mocks.js +1 -1
- package/dist/services/README.md +2 -2
- package/dist/ui/components/drag-drop/Draggable.svelte +7 -7
- package/dist/util/is/events.d.ts +16 -0
- package/dist/util/is/events.js +25 -0
- package/dist/util/is/index.d.ts +1 -0
- package/dist/util/is/index.js +2 -0
- package/package.json +1 -1
- package/dist/constants/index.d.ts +0 -6
- package/dist/constants/index.js +0 -6
package/dist/auth/jwt/util.js
CHANGED
package/dist/auth/jwt.d.ts
CHANGED
package/dist/auth/jwt.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./bases/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './bases/index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Draggable states
|
|
2
|
-
export const
|
|
2
|
+
export const DRAG_IDLE = 'idle'; // Not being dragged
|
|
3
3
|
export const DRAGGING = 'dragging'; // Currently being dragged
|
|
4
4
|
export const DRAG_PREVIEW = 'drag-preview'; // Mouse down, before drag
|
|
5
5
|
export const DROPPING = 'dropping'; // Just dropped, animating
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./time/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './time/index.js';
|
package/dist/logging/README.md
CHANGED
|
@@ -109,11 +109,9 @@ const logger = createClientLogger('client');
|
|
|
109
109
|
|
|
110
110
|
/** @type {import('@sveltejs/kit').HandleClientError} */
|
|
111
111
|
export function handleError({ error, event }) {
|
|
112
|
-
logger.error(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
url: event.url?.pathname,
|
|
116
|
-
userAgent: navigator.userAgent
|
|
112
|
+
logger.error(error, {
|
|
113
|
+
url: event.url?.pathname,
|
|
114
|
+
userAgent: navigator.userAgent
|
|
117
115
|
});
|
|
118
116
|
}
|
|
119
117
|
|
|
@@ -126,19 +124,12 @@ export function init() {
|
|
|
126
124
|
|
|
127
125
|
// Log unhandled errors
|
|
128
126
|
window.addEventListener('error', (event) => {
|
|
129
|
-
logger.error(
|
|
130
|
-
message: event.error?.message || event.message,
|
|
131
|
-
filename: event.filename,
|
|
132
|
-
lineno: event.lineno,
|
|
133
|
-
colno: event.colno
|
|
134
|
-
});
|
|
127
|
+
logger.error(event, { url: window.location.pathname });
|
|
135
128
|
});
|
|
136
129
|
|
|
137
130
|
// Log unhandled promise rejections
|
|
138
131
|
window.addEventListener('unhandledrejection', (event) => {
|
|
139
|
-
logger.error(
|
|
140
|
-
reason: event.reason
|
|
141
|
-
});
|
|
132
|
+
logger.error(event, { url: window.location.pathname });
|
|
142
133
|
});
|
|
143
134
|
}
|
|
144
135
|
|
|
@@ -49,12 +49,16 @@ export default class Logger extends EventEmitter {
|
|
|
49
49
|
/**
|
|
50
50
|
* Log an error message
|
|
51
51
|
*
|
|
52
|
-
* @param {Error|string}
|
|
53
|
-
*
|
|
52
|
+
* @param {Error|ErrorEvent|PromiseRejectionEvent|string}
|
|
53
|
+
* originalErrorOrMessage
|
|
54
|
+
* @param {Error|Object} [originalErrorOrDetails]
|
|
55
|
+
* Error object (when first param is string) or details object
|
|
56
|
+
* @param {Object} [details]
|
|
57
|
+
* Additional context details (when using string + error pattern)
|
|
54
58
|
*
|
|
55
59
|
* @returns {boolean} True if the log was emitted
|
|
56
60
|
*/
|
|
57
|
-
error(originalErrorOrMessage: Error | string,
|
|
61
|
+
error(originalErrorOrMessage: Error | ErrorEvent | PromiseRejectionEvent | string, originalErrorOrDetails?: Error | any, details?: any, ...args: any[]): boolean;
|
|
58
62
|
/**
|
|
59
63
|
* Create a child logger with additional context
|
|
60
64
|
*
|
|
@@ -48,6 +48,13 @@ import { LoggerError } from '../../errors.js';
|
|
|
48
48
|
|
|
49
49
|
import { toArray } from '../../../util/array/index.js';
|
|
50
50
|
|
|
51
|
+
import {
|
|
52
|
+
castErrorEventToDetailedError,
|
|
53
|
+
castPromiseRejectionToDetailedError
|
|
54
|
+
} from './util.js';
|
|
55
|
+
|
|
56
|
+
import * as is from '../../../util/is.js';
|
|
57
|
+
|
|
51
58
|
/**
|
|
52
59
|
* Logger class for consistent logging
|
|
53
60
|
* @extends EventEmitter
|
|
@@ -126,41 +133,92 @@ export default class Logger extends EventEmitter {
|
|
|
126
133
|
/**
|
|
127
134
|
* Log an error message
|
|
128
135
|
*
|
|
129
|
-
* @param {Error|string}
|
|
130
|
-
*
|
|
136
|
+
* @param {Error|ErrorEvent|PromiseRejectionEvent|string}
|
|
137
|
+
* originalErrorOrMessage
|
|
138
|
+
* @param {Error|Object} [originalErrorOrDetails]
|
|
139
|
+
* Error object (when first param is string) or details object
|
|
140
|
+
* @param {Object} [details]
|
|
141
|
+
* Additional context details (when using string + error pattern)
|
|
131
142
|
*
|
|
132
143
|
* @returns {boolean} True if the log was emitted
|
|
133
144
|
*/
|
|
134
|
-
error(originalErrorOrMessage,
|
|
145
|
+
error(originalErrorOrMessage, originalErrorOrDetails, details) {
|
|
146
|
+
// Detection logic - set clear internal variables
|
|
147
|
+
let message;
|
|
148
|
+
let errorDetails;
|
|
149
|
+
let cause;
|
|
150
|
+
|
|
151
|
+
// Handle browser ErrorEvent
|
|
152
|
+
if (is.ErrorEvent(originalErrorOrMessage)) {
|
|
153
|
+
const errorEvent = /** @type {ErrorEvent} */ (originalErrorOrMessage);
|
|
154
|
+
|
|
155
|
+
message =
|
|
156
|
+
errorEvent.error?.message || errorEvent.message || 'Unknown error';
|
|
157
|
+
|
|
158
|
+
// Use provided details or auto-generate from event
|
|
159
|
+
|
|
160
|
+
errorDetails = originalErrorOrDetails || {
|
|
161
|
+
filename: errorEvent.filename,
|
|
162
|
+
lineno: errorEvent.lineno,
|
|
163
|
+
colno: errorEvent.colno,
|
|
164
|
+
type: 'ErrorEvent'
|
|
165
|
+
};
|
|
135
166
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
167
|
+
cause = errorEvent.error;
|
|
168
|
+
}
|
|
169
|
+
// Handle browser PromiseRejectionEvent
|
|
170
|
+
else if (is.PromiseRejectionEvent(originalErrorOrMessage)) {
|
|
171
|
+
const promiseRejectionEvent =
|
|
172
|
+
/** @type {PromiseRejectionEvent} */ (originalErrorOrMessage);
|
|
173
|
+
|
|
174
|
+
const reason = promiseRejectionEvent.reason;
|
|
140
175
|
|
|
141
|
-
|
|
176
|
+
if (reason instanceof Error) {
|
|
177
|
+
message = reason.message;
|
|
178
|
+
cause = reason;
|
|
179
|
+
} else {
|
|
180
|
+
message = String(reason);
|
|
181
|
+
cause = null;
|
|
182
|
+
}
|
|
142
183
|
|
|
143
|
-
|
|
184
|
+
// Use provided details or auto-generate from event
|
|
185
|
+
errorDetails = originalErrorOrDetails || {
|
|
186
|
+
type: 'PromiseRejectionEvent',
|
|
187
|
+
reasonType: typeof reason
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// Handle regular Error
|
|
191
|
+
else if (originalErrorOrMessage instanceof Error) {
|
|
192
|
+
message = originalErrorOrMessage.message;
|
|
193
|
+
errorDetails = originalErrorOrDetails || null;
|
|
194
|
+
cause = originalErrorOrMessage;
|
|
195
|
+
}
|
|
196
|
+
// Handle string + Error pattern
|
|
197
|
+
else if (
|
|
198
|
+
typeof originalErrorOrMessage === 'string' &&
|
|
199
|
+
originalErrorOrDetails instanceof Error
|
|
200
|
+
) {
|
|
201
|
+
message = originalErrorOrMessage;
|
|
202
|
+
errorDetails = details || null;
|
|
203
|
+
cause = originalErrorOrDetails;
|
|
144
204
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
originalError
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
return this.#log(ERROR, detailedError.message, detailedError);
|
|
205
|
+
// Handle string only
|
|
206
|
+
else if (typeof originalErrorOrMessage === 'string') {
|
|
207
|
+
message = originalErrorOrMessage;
|
|
208
|
+
errorDetails = originalErrorOrDetails || null;
|
|
209
|
+
cause = null;
|
|
154
210
|
}
|
|
211
|
+
// Invalid parameters
|
|
155
212
|
else {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
toArray(arguments)
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
return this.#log(ERROR, detailedError.message, detailedError);
|
|
213
|
+
message = 'Invalid parameters supplied to Logger.error';
|
|
214
|
+
errorDetails = toArray(arguments);
|
|
215
|
+
cause = null;
|
|
163
216
|
}
|
|
217
|
+
|
|
218
|
+
// Create consistent DetailedError for all cases
|
|
219
|
+
const detailedError = new DetailedError(message, errorDetails, cause);
|
|
220
|
+
|
|
221
|
+
return this.#log(ERROR, detailedError.message, detailedError);
|
|
164
222
|
}
|
|
165
223
|
|
|
166
224
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast ErrorEvent to DetailedError
|
|
3
|
+
* @param {ErrorEvent} errorEvent - Browser ErrorEvent object
|
|
4
|
+
* @returns {DetailedError}
|
|
5
|
+
*/
|
|
6
|
+
export function castErrorEventToDetailedError(errorEvent: ErrorEvent): DetailedError;
|
|
7
|
+
/**
|
|
8
|
+
* Cast PromiseRejectionEvent to DetailedError
|
|
9
|
+
* @param {PromiseRejectionEvent} rejectionEvent - Browser promise rejection
|
|
10
|
+
* @returns {DetailedError}
|
|
11
|
+
*/
|
|
12
|
+
export function castPromiseRejectionToDetailedError(rejectionEvent: PromiseRejectionEvent): DetailedError;
|
|
13
|
+
import { DetailedError } from '../../../generic/errors/generic.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DetailedError } from '../../../generic/errors/generic.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cast ErrorEvent to DetailedError
|
|
5
|
+
* @param {ErrorEvent} errorEvent - Browser ErrorEvent object
|
|
6
|
+
* @returns {DetailedError}
|
|
7
|
+
*/
|
|
8
|
+
export function castErrorEventToDetailedError(errorEvent) {
|
|
9
|
+
const message = errorEvent.error?.message ||
|
|
10
|
+
errorEvent.message ||
|
|
11
|
+
'Unknown error';
|
|
12
|
+
|
|
13
|
+
const details = {
|
|
14
|
+
filename: errorEvent.filename,
|
|
15
|
+
lineno: errorEvent.lineno,
|
|
16
|
+
colno: errorEvent.colno,
|
|
17
|
+
type: 'ErrorEvent'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return new DetailedError(message, details, errorEvent.error);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Cast PromiseRejectionEvent to DetailedError
|
|
25
|
+
* @param {PromiseRejectionEvent} rejectionEvent - Browser promise rejection
|
|
26
|
+
* @returns {DetailedError}
|
|
27
|
+
*/
|
|
28
|
+
export function castPromiseRejectionToDetailedError(rejectionEvent) {
|
|
29
|
+
const reason = rejectionEvent.reason;
|
|
30
|
+
let message, cause;
|
|
31
|
+
|
|
32
|
+
if (reason instanceof Error) {
|
|
33
|
+
message = reason.message;
|
|
34
|
+
cause = reason;
|
|
35
|
+
} else {
|
|
36
|
+
message = String(reason);
|
|
37
|
+
cause = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const details = {
|
|
41
|
+
type: 'PromiseRejectionEvent',
|
|
42
|
+
reasonType: typeof reason
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return new DetailedError(message, details, cause);
|
|
46
|
+
}
|
|
47
|
+
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as expect from '../../util/expect.js';
|
|
2
2
|
import { DetailedError } from '../../generic/errors.js';
|
|
3
3
|
|
|
4
|
-
import { CONTENT_TYPE } from '../../constants/http
|
|
4
|
+
import { CONTENT_TYPE } from '../../constants/http.js';
|
|
5
5
|
|
|
6
|
-
import { APPLICATION_JSON, TEXT_PLAIN } from '../../constants/mime
|
|
6
|
+
import { APPLICATION_JSON, TEXT_PLAIN } from '../../constants/mime.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Try to get error information from the server error response
|
|
@@ -17,6 +17,6 @@ export * from './response.js';
|
|
|
17
17
|
export * from './http-request.js';
|
|
18
18
|
export * from './json-request.js';
|
|
19
19
|
|
|
20
|
-
// import { CONTENT_TYPE, METHOD_GET, METHOD_POST } from '../../constants/http
|
|
20
|
+
// import { CONTENT_TYPE, METHOD_GET, METHOD_POST } from '../../constants/http.js';
|
|
21
21
|
|
|
22
|
-
// import { APPLICATION_JSON } from '../../constants/mime
|
|
22
|
+
// import { APPLICATION_JSON } from '../../constants/mime.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http
|
|
1
|
+
import { CONTENT_TYPE, CONTENT_LENGTH } from '../../constants/http.js';
|
|
2
2
|
|
|
3
|
-
import { OCTET_STREAM } from '../../constants/mime
|
|
3
|
+
import { OCTET_STREAM } from '../../constants/mime.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a response value that can be used by a mocked fetch function
|
package/dist/services/README.md
CHANGED
|
@@ -104,7 +104,7 @@ Manages multiple services with dependency resolution and coordinated lifecycle o
|
|
|
104
104
|
### Usage
|
|
105
105
|
|
|
106
106
|
```javascript
|
|
107
|
-
import { ServiceManager } from '$
|
|
107
|
+
import { ServiceManager } from '$hklib-core/services/index.js';
|
|
108
108
|
import DatabaseService from './services/DatabaseService.js';
|
|
109
109
|
import AuthService from './services/AuthService.js';
|
|
110
110
|
|
|
@@ -197,4 +197,4 @@ Services include comprehensive test suites demonstrating:
|
|
|
197
197
|
- Health monitoring
|
|
198
198
|
- Event emission
|
|
199
199
|
|
|
200
|
-
Run tests with your project's test command to ensure service reliability.
|
|
200
|
+
Run tests with your project's test command to ensure service reliability.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { DragController } from './DragController.js';
|
|
7
7
|
import { onDestroy } from 'svelte';
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
DRAG_IDLE,
|
|
10
10
|
DRAGGING,
|
|
11
11
|
DRAG_PREVIEW,
|
|
12
12
|
DROPPING
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
let draggableElement;
|
|
92
92
|
|
|
93
93
|
let dragTimeout = null;
|
|
94
|
-
let currentState = $state(
|
|
94
|
+
let currentState = $state(DRAG_IDLE);
|
|
95
95
|
|
|
96
96
|
// Custom preview follower state
|
|
97
97
|
let showPreview = $state(false);
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
|
|
113
113
|
// Computed state object for CSS classes
|
|
114
114
|
let stateObject = $derived({
|
|
115
|
-
idle: currentState ===
|
|
115
|
+
idle: currentState === DRAG_IDLE,
|
|
116
116
|
dragging: currentState === DRAGGING,
|
|
117
117
|
'drag-preview': currentState === DRAG_PREVIEW,
|
|
118
118
|
dropping: currentState === DROPPING,
|
|
@@ -295,10 +295,10 @@
|
|
|
295
295
|
|
|
296
296
|
// Brief dropping state before returning to idle
|
|
297
297
|
setTimeout(() => {
|
|
298
|
-
currentState =
|
|
298
|
+
currentState = DRAG_IDLE;
|
|
299
299
|
}, 100);
|
|
300
300
|
} else {
|
|
301
|
-
currentState =
|
|
301
|
+
currentState = DRAG_IDLE;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
onDragEnd?.({ event, item, wasDropped });
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
function handleMouseUp(event) {
|
|
322
322
|
if (dragTimeout) {
|
|
323
323
|
clearTimeout(dragTimeout);
|
|
324
|
-
currentState =
|
|
324
|
+
currentState = DRAG_IDLE;
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
|
|
@@ -456,7 +456,7 @@
|
|
|
456
456
|
|
|
457
457
|
// Clean up
|
|
458
458
|
touchDragging = false;
|
|
459
|
-
currentState =
|
|
459
|
+
currentState = DRAG_IDLE;
|
|
460
460
|
showPreview = false;
|
|
461
461
|
dragState.end(draggableId);
|
|
462
462
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if object is an ErrorEvent
|
|
3
|
+
*
|
|
4
|
+
* @param {any} obj
|
|
5
|
+
*
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function ErrorEvent(obj: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Check if object is a PromiseRejectionEvent
|
|
11
|
+
*
|
|
12
|
+
* @param {any} obj
|
|
13
|
+
*
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function PromiseRejectionEvent(obj: any): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if object is an ErrorEvent
|
|
3
|
+
*
|
|
4
|
+
* @param {any} obj
|
|
5
|
+
*
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function ErrorEvent(obj) {
|
|
9
|
+
return Boolean(obj &&
|
|
10
|
+
typeof obj === 'object' &&
|
|
11
|
+
obj.constructor?.name === 'ErrorEvent');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check if object is a PromiseRejectionEvent
|
|
16
|
+
*
|
|
17
|
+
* @param {any} obj
|
|
18
|
+
*
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export function PromiseRejectionEvent(obj) {
|
|
22
|
+
return Boolean(obj &&
|
|
23
|
+
typeof obj === 'object' &&
|
|
24
|
+
obj.constructor?.name === 'PromiseRejectionEvent');
|
|
25
|
+
}
|
package/dist/util/is/index.d.ts
CHANGED
package/dist/util/is/index.js
CHANGED
package/package.json
CHANGED
package/dist/constants/index.js
DELETED