@wooksjs/event-core 0.2.1 → 0.2.2
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/index.cjs +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +10 -1
- package/package.json +1 -1
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
|
-
|
|
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 };
|