@wooksjs/event-core 0.4.10 → 0.4.11

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 CHANGED
@@ -19,7 +19,7 @@ let currentContext = null;
19
19
  * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
20
20
  */
21
21
  function createEventContext(data) {
22
- const newContext = Object.assign({}, data);
22
+ const newContext = { ...data };
23
23
  currentContext = newContext;
24
24
  return _getCtxHelpers(newContext);
25
25
  }
@@ -31,13 +31,12 @@ function createEventContext(data) {
31
31
  * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
32
32
  */
33
33
  function useEventContext(expectedTypes) {
34
- var _a;
35
34
  if (!currentContext) {
36
35
  throw new Error('Event context does not exist. Use event context synchronously within the runtime of the event.');
37
36
  }
38
37
  const cc = currentContext;
39
38
  if (expectedTypes || typeof expectedTypes === 'string') {
40
- const type = (_a = cc.event) === null || _a === void 0 ? void 0 : _a.type;
39
+ const type = cc.event?.type;
41
40
  const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
42
41
  if (!types.includes(type))
43
42
  new Error(`Event context type mismatch: expected ${types
@@ -173,7 +172,10 @@ class EventLogger extends logger.ProstoLogger {
173
172
  level: 4,
174
173
  };
175
174
  if (!_opts.mapper) {
176
- _opts.mapper = (msg) => (Object.assign(Object.assign({}, msg), { eventId }));
175
+ _opts.mapper = (msg) => ({
176
+ ...msg,
177
+ eventId,
178
+ });
177
179
  }
178
180
  if (!_opts.transports) {
179
181
  _opts.transports = [
@@ -182,7 +184,7 @@ class EventLogger extends logger.ProstoLogger {
182
184
  }),
183
185
  ];
184
186
  }
185
- super(_opts, (opts === null || opts === void 0 ? void 0 : opts.topic) || 'event');
187
+ super(_opts, opts?.topic || 'event');
186
188
  }
187
189
  }
188
190
 
@@ -191,7 +193,7 @@ function useEventLogger(topic) {
191
193
  const { store, getCtx } = useEventContext();
192
194
  const { init } = store('event');
193
195
  const ctx = getCtx();
194
- const get = () => init('logger', () => { var _a; return new EventLogger(getId(), (_a = ctx.options) === null || _a === void 0 ? void 0 : _a.eventLogger); });
196
+ const get = () => init('logger', () => new EventLogger(getId(), ctx.options?.eventLogger));
195
197
  return topic ? get().createTopic(topic) : get();
196
198
  }
197
199
 
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ let currentContext = null;
17
17
  * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
18
18
  */
19
19
  function createEventContext(data) {
20
- const newContext = Object.assign({}, data);
20
+ const newContext = { ...data };
21
21
  currentContext = newContext;
22
22
  return _getCtxHelpers(newContext);
23
23
  }
@@ -29,13 +29,12 @@ function createEventContext(data) {
29
29
  * @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
30
30
  */
31
31
  function useEventContext(expectedTypes) {
32
- var _a;
33
32
  if (!currentContext) {
34
33
  throw new Error('Event context does not exist. Use event context synchronously within the runtime of the event.');
35
34
  }
36
35
  const cc = currentContext;
37
36
  if (expectedTypes || typeof expectedTypes === 'string') {
38
- const type = (_a = cc.event) === null || _a === void 0 ? void 0 : _a.type;
37
+ const type = cc.event?.type;
39
38
  const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
40
39
  if (!types.includes(type))
41
40
  new Error(`Event context type mismatch: expected ${types
@@ -171,7 +170,10 @@ class EventLogger extends ProstoLogger {
171
170
  level: 4,
172
171
  };
173
172
  if (!_opts.mapper) {
174
- _opts.mapper = (msg) => (Object.assign(Object.assign({}, msg), { eventId }));
173
+ _opts.mapper = (msg) => ({
174
+ ...msg,
175
+ eventId,
176
+ });
175
177
  }
176
178
  if (!_opts.transports) {
177
179
  _opts.transports = [
@@ -180,7 +182,7 @@ class EventLogger extends ProstoLogger {
180
182
  }),
181
183
  ];
182
184
  }
183
- super(_opts, (opts === null || opts === void 0 ? void 0 : opts.topic) || 'event');
185
+ super(_opts, opts?.topic || 'event');
184
186
  }
185
187
  }
186
188
 
@@ -189,7 +191,7 @@ function useEventLogger(topic) {
189
191
  const { store, getCtx } = useEventContext();
190
192
  const { init } = store('event');
191
193
  const ctx = getCtx();
192
- const get = () => init('logger', () => { var _a; return new EventLogger(getId(), (_a = ctx.options) === null || _a === void 0 ? void 0 : _a.eventLogger); });
194
+ const get = () => init('logger', () => new EventLogger(getId(), ctx.options?.eventLogger));
193
195
  return topic ? get().createTopic(topic) : get();
194
196
  }
195
197
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-core",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "@wooksjs/event-core",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",