@hkdigital/lib-core 0.5.55 → 0.5.57

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.
@@ -264,7 +264,7 @@ export default class Logger extends EventEmitter {
264
264
  ...this.#defaultContext
265
265
  };
266
266
 
267
- const childName = `${this.name}:${name}`;
267
+ const childName = `${this.name}>${name}`;
268
268
 
269
269
  const child = new Logger(childName, level ?? this.level, context);
270
270
 
@@ -161,6 +161,19 @@ export default class PageMachine {
161
161
  * ```
162
162
  */
163
163
  hasVisited(state: string): boolean;
164
+ /**
165
+ * Check if the start state has been visited
166
+ *
167
+ * @returns {boolean} True if the start state has been visited
168
+ *
169
+ * @example
170
+ * ```javascript
171
+ * if (machine.hasVisitedStart) {
172
+ * // User has been to the start page
173
+ * }
174
+ * ```
175
+ */
176
+ get hasVisitedStart(): boolean;
164
177
  /**
165
178
  * Get all visited states
166
179
  *
@@ -195,8 +195,17 @@ export default class PageMachine {
195
195
  this.#data = initialData;
196
196
  this.#onEnterHooks = this.#normalizeOnEnterHooks(onEnterHooks);
197
197
 
198
- // Build reverse map (path -> state)
198
+ // Build reverse map (path -> state) and validate no duplicates
199
199
  for (const [state, path] of Object.entries(routeMap)) {
200
+ // Check if this path is already mapped to a different state
201
+ const existingState = this.#pathToStateMap[path];
202
+ if (existingState && existingState !== state) {
203
+ throw new Error(
204
+ `PageMachine: Duplicate route mapping detected. ` +
205
+ `Path "${path}" is mapped to both "${existingState}" and "${state}". ` +
206
+ `Each route path must map to exactly one state.`
207
+ );
208
+ }
200
209
  this.#pathToStateMap[path] = state;
201
210
  }
202
211
 
@@ -516,6 +525,22 @@ export default class PageMachine {
516
525
  return this.#visitedStates.has(state);
517
526
  }
518
527
 
528
+ /**
529
+ * Check if the start state has been visited
530
+ *
531
+ * @returns {boolean} True if the start state has been visited
532
+ *
533
+ * @example
534
+ * ```javascript
535
+ * if (machine.hasVisitedStart) {
536
+ * // User has been to the start page
537
+ * }
538
+ * ```
539
+ */
540
+ get hasVisitedStart() {
541
+ return this.hasVisited(this.#startState);
542
+ }
543
+
519
544
  /**
520
545
  * Get all visited states
521
546
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-core",
3
- "version": "0.5.55",
3
+ "version": "0.5.57",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"