@hkdigital/lib-core 0.4.46 → 0.4.47
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/logging/README.md
CHANGED
|
@@ -12,13 +12,14 @@ pnpm add -D pino-pretty
|
|
|
12
12
|
|
|
13
13
|
```javascript
|
|
14
14
|
import { createServerLogger,
|
|
15
|
-
createClientLogger
|
|
15
|
+
createClientLogger,
|
|
16
|
+
DEBUG } from '@hkdigital/lib-core/logging/index.js';
|
|
16
17
|
|
|
17
18
|
// Server-side logging (uses pino)
|
|
18
|
-
const serverLogger = createServerLogger('app');
|
|
19
|
+
const serverLogger = createServerLogger('app', DEBUG);
|
|
19
20
|
|
|
20
21
|
// Client-side logging (uses console)
|
|
21
|
-
const clientLogger = createClientLogger('app');
|
|
22
|
+
const clientLogger = createClientLogger('app', DEBUG);
|
|
22
23
|
|
|
23
24
|
// Log at different levels
|
|
24
25
|
serverLogger.debug('Debug info', { data: 'details' });
|
|
@@ -32,13 +33,13 @@ serverLogger.error('Error message', { error: new Error('Something went wrong') }
|
|
|
32
33
|
### Server-side logging (src/hooks.server.js)
|
|
33
34
|
|
|
34
35
|
```javascript
|
|
35
|
-
import { createServerLogger } from '@hkdigital/lib-core/logging/index.js';
|
|
36
|
+
import { createServerLogger, DEBUG } from '@hkdigital/lib-core/logging/index.js';
|
|
36
37
|
|
|
37
38
|
let logger;
|
|
38
39
|
|
|
39
40
|
// Initialize server logging and services
|
|
40
41
|
export async function init() {
|
|
41
|
-
logger = createServerLogger('server');
|
|
42
|
+
logger = createServerLogger('server', DEBUG);
|
|
42
43
|
|
|
43
44
|
try {
|
|
44
45
|
logger.info('Initializing server');
|
|
@@ -90,7 +90,7 @@ export default class SceneBase {
|
|
|
90
90
|
const state = this.#state;
|
|
91
91
|
|
|
92
92
|
$effect(() => {
|
|
93
|
-
if (this
|
|
93
|
+
if (this.state === STATE_LOADING) {
|
|
94
94
|
const { sourcesLoaded, numberOfSources } = this.#progress;
|
|
95
95
|
|
|
96
96
|
if (sourcesLoaded === numberOfSources && numberOfSources > 0) {
|
|
@@ -100,7 +100,7 @@ export default class SceneBase {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
$effect(() => {
|
|
103
|
-
if (this
|
|
103
|
+
if (this.state === STATE_ABORTING) {
|
|
104
104
|
const { sourcesAborted, numberOfSources } = this.#abortProgress;
|
|
105
105
|
|
|
106
106
|
if (sourcesAborted === numberOfSources && numberOfSources > 0) {
|
|
@@ -289,8 +289,10 @@ export default class SceneBase {
|
|
|
289
289
|
/* ==== Internal methods */
|
|
290
290
|
|
|
291
291
|
#startLoading() {
|
|
292
|
-
for (
|
|
292
|
+
for (let i = 0; i < this.sources.length; i++) {
|
|
293
|
+
const source = this.sources[i];
|
|
293
294
|
const loader = this.getLoaderFromSource(source);
|
|
295
|
+
|
|
294
296
|
loader.load();
|
|
295
297
|
}
|
|
296
298
|
}
|
|
@@ -29,8 +29,7 @@ import { ERROR_NOT_LOADED, ERROR_TRANSFERRED } from './constants.js';
|
|
|
29
29
|
* - Loaded data can be transferred to an AudioBufferSourceNode
|
|
30
30
|
*/
|
|
31
31
|
export default class NetworkLoader {
|
|
32
|
-
|
|
33
|
-
_state = new LoadingStateMachine();
|
|
32
|
+
_state = $state(new LoadingStateMachine());
|
|
34
33
|
|
|
35
34
|
state = $derived.by(() => {
|
|
36
35
|
return this._state.current;
|
|
@@ -90,34 +89,22 @@ export default class NetworkLoader {
|
|
|
90
89
|
const state = this._state;
|
|
91
90
|
// const progress = this.progress;
|
|
92
91
|
|
|
93
|
-
this._state.onenter = () => {
|
|
92
|
+
this._state.onenter = (currentState) => {
|
|
94
93
|
switch (state.current) {
|
|
95
94
|
case STATE_LOADING:
|
|
96
95
|
{
|
|
97
|
-
// console.log('**** NetworkLoader:loading');
|
|
98
96
|
this.#load();
|
|
99
97
|
}
|
|
100
98
|
break;
|
|
101
99
|
|
|
102
100
|
case STATE_UNLOADING:
|
|
103
101
|
{
|
|
104
|
-
// console.log('NetworkLoader:unloading');
|
|
105
102
|
this.#unload();
|
|
106
103
|
}
|
|
107
104
|
break;
|
|
108
105
|
|
|
109
106
|
case STATE_LOADED:
|
|
110
107
|
{
|
|
111
|
-
// console.debug('NetworkLoader:loaded', $state.snapshot(state));
|
|
112
|
-
|
|
113
|
-
// setTimeout(() => {
|
|
114
|
-
// console.debug(
|
|
115
|
-
// 'NetworkLoader:loaded',
|
|
116
|
-
// $state.snapshot(state),
|
|
117
|
-
// progress
|
|
118
|
-
// );
|
|
119
|
-
// }, 500);
|
|
120
|
-
|
|
121
108
|
// Abort function is no longer needed
|
|
122
109
|
this._abortLoading = null;
|
|
123
110
|
}
|
|
@@ -125,7 +112,6 @@ export default class NetworkLoader {
|
|
|
125
112
|
|
|
126
113
|
case STATE_ABORTING:
|
|
127
114
|
{
|
|
128
|
-
// console.log('NetworkLoader:aborting');
|
|
129
115
|
if (this._abortLoading) {
|
|
130
116
|
this._abortLoading();
|
|
131
117
|
this._abortLoading = null;
|
|
@@ -148,7 +134,6 @@ export default class NetworkLoader {
|
|
|
148
134
|
* Start loading all network data
|
|
149
135
|
*/
|
|
150
136
|
load() {
|
|
151
|
-
// console.debug('NetworkLoader: load() called');
|
|
152
137
|
this._state.send(LOAD);
|
|
153
138
|
}
|
|
154
139
|
|
|
@@ -273,10 +258,7 @@ export default class NetworkLoader {
|
|
|
273
258
|
*/
|
|
274
259
|
async #load() {
|
|
275
260
|
try {
|
|
276
|
-
// console.log('>>>> NetworkLoader:#load', this._url);
|
|
277
|
-
|
|
278
261
|
if (this._abortLoading) {
|
|
279
|
-
// console.log('Abort loading');
|
|
280
262
|
this._abortLoading();
|
|
281
263
|
this._abortLoading = null;
|
|
282
264
|
}
|
|
@@ -300,9 +282,6 @@ export default class NetworkLoader {
|
|
|
300
282
|
|
|
301
283
|
this._headers = response.headers;
|
|
302
284
|
|
|
303
|
-
// console.log('headers', this._headers);
|
|
304
|
-
// console.log('response', response);
|
|
305
|
-
|
|
306
285
|
const { bufferPromise, abort: abortLoadBody } = loadResponseBuffer(
|
|
307
286
|
response,
|
|
308
287
|
({ bytesLoaded, size }) => {
|
|
@@ -318,7 +297,11 @@ export default class NetworkLoader {
|
|
|
318
297
|
|
|
319
298
|
this._buffer = await bufferPromise;
|
|
320
299
|
|
|
321
|
-
//
|
|
300
|
+
// if (this._size === 0 && this._buffer) {
|
|
301
|
+
// // Fallback: if size was unknown (0),
|
|
302
|
+
// // => set it to actual buffer size when loaded
|
|
303
|
+
// this._size = this._buffer.byteLength;
|
|
304
|
+
// }
|
|
322
305
|
|
|
323
306
|
this._state.send(LOADED);
|
|
324
307
|
} catch (e) {
|
package/dist/services/README.md
CHANGED
|
@@ -296,10 +296,10 @@ Forward all service log events to a centralised logger:
|
|
|
296
296
|
|
|
297
297
|
```javascript
|
|
298
298
|
import { ServiceManager } from '$lib/services/index.js';
|
|
299
|
-
import { createServerLogger } from '$lib/logging/index.js';
|
|
299
|
+
import { createServerLogger, DEBUG } from '$lib/logging/index.js';
|
|
300
300
|
|
|
301
301
|
const manager = new ServiceManager();
|
|
302
|
-
const logger = createServerLogger('SystemLogger');
|
|
302
|
+
const logger = createServerLogger('SystemLogger', DEBUG);
|
|
303
303
|
|
|
304
304
|
// Listen to all log events and forward them to the logger
|
|
305
305
|
const unsubscribe = manager.onLogEvent((logEvent) => {
|