@wooksjs/event-core 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  **!!! This is work-in-progress library, breaking changes are expected !!!**
4
4
 
5
5
  <p align="center">
6
- <img src="../../logo.png" width="128px"><br>
6
+ <img src="../../wooks-logo.png" style="width: 100%; max-width: 450px"><br>
7
7
  <a href="https://github.com/wooksjs/wooksjs/blob/main/LICENSE">
8
8
  <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" />
9
9
  </a>
package/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var crypto = require('crypto');
4
+
3
5
  const banner = () => `[${"@wooksjs/event-core"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
4
6
 
5
7
  /* istanbul ignore file */
@@ -156,7 +158,15 @@ function useRouteParams() {
156
158
  };
157
159
  }
158
160
 
161
+ function useEventId() {
162
+ const { store } = useEventContext();
163
+ const { init } = store('event');
164
+ const getId = () => init('id', () => crypto.randomUUID());
165
+ return { getId };
166
+ }
167
+
159
168
  exports.attachHook = attachHook;
160
169
  exports.createEventContext = createEventContext;
161
170
  exports.useEventContext = useEventContext;
171
+ exports.useEventId = useEventId;
162
172
  exports.useRouteParams = useRouteParams;
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare type TGenericContextStore<E extends TGenericEvent = TGenericEvent
38
38
 
39
39
  export declare interface TGenericEvent {
40
40
  type: string;
41
+ id?: string;
41
42
  }
42
43
 
43
44
  /**
@@ -69,6 +70,10 @@ export declare function useEventContext<S extends TGenericContextStore>(expected
69
70
  setStore: <K_2 extends keyof S>(key: K_2, v: S[K_2]) => void;
70
71
  };
71
72
 
73
+ export declare function useEventId(): {
74
+ getId: () => string;
75
+ };
76
+
72
77
  export declare function useRouteParams<T extends object = Record<string, string | string[]>>(): {
73
78
  params: T;
74
79
  get: <K extends keyof T>(name: K) => T[K];
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { randomUUID } from 'crypto';
2
+
1
3
  const banner = () => `[${"@wooksjs/event-core"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
2
4
 
3
5
  /* istanbul ignore file */
@@ -154,4 +156,11 @@ function useRouteParams() {
154
156
  };
155
157
  }
156
158
 
157
- export { attachHook, createEventContext, useEventContext, useRouteParams };
159
+ function useEventId() {
160
+ const { store } = useEventContext();
161
+ const { init } = store('event');
162
+ const getId = () => init('id', () => randomUUID());
163
+ return { getId };
164
+ }
165
+
166
+ export { attachHook, createEventContext, useEventContext, useEventId, useRouteParams };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "@wooksjs/event-core",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",