@wooksjs/event-core 0.2.18 → 0.2.20
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 +1 -2
- package/dist/index.cjs +26 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +26 -12
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,9 @@ function useEventContext(expectedTypes) {
|
|
|
41
41
|
const type = (_a = cc.event) === null || _a === void 0 ? void 0 : _a.type;
|
|
42
42
|
const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
|
|
43
43
|
if (!types.includes(type))
|
|
44
|
-
new Error(`Event context type mismatch: expected ${types
|
|
44
|
+
new Error(`Event context type mismatch: expected ${types
|
|
45
|
+
.map((t) => `"${t}"`)
|
|
46
|
+
.join(', ')}, received "${type}"`);
|
|
45
47
|
}
|
|
46
48
|
return _getCtxHelpers(cc);
|
|
47
49
|
}
|
|
@@ -65,7 +67,7 @@ function _getCtxHelpers(cc) {
|
|
|
65
67
|
clear,
|
|
66
68
|
};
|
|
67
69
|
attachHook(obj, {
|
|
68
|
-
set: v => set(key, v),
|
|
70
|
+
set: (v) => set(key, v),
|
|
69
71
|
get: () => get(key),
|
|
70
72
|
});
|
|
71
73
|
function init(key2, getter) {
|
|
@@ -79,7 +81,7 @@ function _getCtxHelpers(cc) {
|
|
|
79
81
|
isDefined: null,
|
|
80
82
|
};
|
|
81
83
|
attachHook(obj, {
|
|
82
|
-
set: v => setNested(key2, v),
|
|
84
|
+
set: (v) => setNested(key2, v),
|
|
83
85
|
get: () => getNested(key2),
|
|
84
86
|
});
|
|
85
87
|
attachHook(obj, {
|
|
@@ -97,10 +99,18 @@ function _getCtxHelpers(cc) {
|
|
|
97
99
|
function delNested(key2) {
|
|
98
100
|
setNested(key2, undefined);
|
|
99
101
|
}
|
|
100
|
-
function getNested(key2) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function
|
|
102
|
+
function getNested(key2) {
|
|
103
|
+
return (obj.value || {})[key2];
|
|
104
|
+
}
|
|
105
|
+
function hasNested(key2) {
|
|
106
|
+
return typeof (obj.value || {})[key2] !== 'undefined';
|
|
107
|
+
}
|
|
108
|
+
function entries() {
|
|
109
|
+
return Object.entries(obj.value || {});
|
|
110
|
+
}
|
|
111
|
+
function clear() {
|
|
112
|
+
obj.value = {};
|
|
113
|
+
}
|
|
104
114
|
return obj;
|
|
105
115
|
}
|
|
106
116
|
/**
|
|
@@ -108,14 +118,18 @@ function _getCtxHelpers(cc) {
|
|
|
108
118
|
*
|
|
109
119
|
* @returns whole context object
|
|
110
120
|
*/
|
|
111
|
-
function getCtx() {
|
|
121
|
+
function getCtx() {
|
|
122
|
+
return cc;
|
|
123
|
+
}
|
|
112
124
|
/**
|
|
113
125
|
* Get value of event store property
|
|
114
126
|
*
|
|
115
127
|
* @param key property name
|
|
116
128
|
* @returns value of property by name
|
|
117
129
|
*/
|
|
118
|
-
function get(key) {
|
|
130
|
+
function get(key) {
|
|
131
|
+
return getCtx()[key];
|
|
132
|
+
}
|
|
119
133
|
/**
|
|
120
134
|
* Set value of event store property
|
|
121
135
|
*
|
|
@@ -123,12 +137,12 @@ function _getCtxHelpers(cc) {
|
|
|
123
137
|
* @param v property value
|
|
124
138
|
*/
|
|
125
139
|
function set(key, v) {
|
|
126
|
-
|
|
140
|
+
getCtx()[key] = v;
|
|
127
141
|
}
|
|
128
142
|
return {
|
|
129
143
|
getCtx,
|
|
130
|
-
restoreCtx: () => currentContext = cc,
|
|
131
|
-
clearCtx: () => cc === currentContext ? currentContext = null : null,
|
|
144
|
+
restoreCtx: () => (currentContext = cc),
|
|
145
|
+
clearCtx: () => cc === currentContext ? (currentContext = null) : null,
|
|
132
146
|
store,
|
|
133
147
|
getStore: get,
|
|
134
148
|
setStore: set,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProstoLogger } from '@prostojs/logger';
|
|
2
2
|
import { TProstoLoggerOptions } from '@prostojs/logger';
|
|
3
3
|
|
|
4
|
-
export declare function attachHook<V = unknown, T extends
|
|
4
|
+
export declare function attachHook<V = unknown, T extends object | Function = object, P extends PropertyKey = 'value'>(target: T, opts: {
|
|
5
5
|
get: () => V | undefined;
|
|
6
6
|
set?: (value: V) => void;
|
|
7
7
|
}, name?: P): T & { [name in P]?: V | undefined; };
|
package/dist/index.mjs
CHANGED
|
@@ -39,7 +39,9 @@ function useEventContext(expectedTypes) {
|
|
|
39
39
|
const type = (_a = cc.event) === null || _a === void 0 ? void 0 : _a.type;
|
|
40
40
|
const types = typeof expectedTypes === 'string' ? [expectedTypes] : expectedTypes;
|
|
41
41
|
if (!types.includes(type))
|
|
42
|
-
new Error(`Event context type mismatch: expected ${types
|
|
42
|
+
new Error(`Event context type mismatch: expected ${types
|
|
43
|
+
.map((t) => `"${t}"`)
|
|
44
|
+
.join(', ')}, received "${type}"`);
|
|
43
45
|
}
|
|
44
46
|
return _getCtxHelpers(cc);
|
|
45
47
|
}
|
|
@@ -63,7 +65,7 @@ function _getCtxHelpers(cc) {
|
|
|
63
65
|
clear,
|
|
64
66
|
};
|
|
65
67
|
attachHook(obj, {
|
|
66
|
-
set: v => set(key, v),
|
|
68
|
+
set: (v) => set(key, v),
|
|
67
69
|
get: () => get(key),
|
|
68
70
|
});
|
|
69
71
|
function init(key2, getter) {
|
|
@@ -77,7 +79,7 @@ function _getCtxHelpers(cc) {
|
|
|
77
79
|
isDefined: null,
|
|
78
80
|
};
|
|
79
81
|
attachHook(obj, {
|
|
80
|
-
set: v => setNested(key2, v),
|
|
82
|
+
set: (v) => setNested(key2, v),
|
|
81
83
|
get: () => getNested(key2),
|
|
82
84
|
});
|
|
83
85
|
attachHook(obj, {
|
|
@@ -95,10 +97,18 @@ function _getCtxHelpers(cc) {
|
|
|
95
97
|
function delNested(key2) {
|
|
96
98
|
setNested(key2, undefined);
|
|
97
99
|
}
|
|
98
|
-
function getNested(key2) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
function
|
|
100
|
+
function getNested(key2) {
|
|
101
|
+
return (obj.value || {})[key2];
|
|
102
|
+
}
|
|
103
|
+
function hasNested(key2) {
|
|
104
|
+
return typeof (obj.value || {})[key2] !== 'undefined';
|
|
105
|
+
}
|
|
106
|
+
function entries() {
|
|
107
|
+
return Object.entries(obj.value || {});
|
|
108
|
+
}
|
|
109
|
+
function clear() {
|
|
110
|
+
obj.value = {};
|
|
111
|
+
}
|
|
102
112
|
return obj;
|
|
103
113
|
}
|
|
104
114
|
/**
|
|
@@ -106,14 +116,18 @@ function _getCtxHelpers(cc) {
|
|
|
106
116
|
*
|
|
107
117
|
* @returns whole context object
|
|
108
118
|
*/
|
|
109
|
-
function getCtx() {
|
|
119
|
+
function getCtx() {
|
|
120
|
+
return cc;
|
|
121
|
+
}
|
|
110
122
|
/**
|
|
111
123
|
* Get value of event store property
|
|
112
124
|
*
|
|
113
125
|
* @param key property name
|
|
114
126
|
* @returns value of property by name
|
|
115
127
|
*/
|
|
116
|
-
function get(key) {
|
|
128
|
+
function get(key) {
|
|
129
|
+
return getCtx()[key];
|
|
130
|
+
}
|
|
117
131
|
/**
|
|
118
132
|
* Set value of event store property
|
|
119
133
|
*
|
|
@@ -121,12 +135,12 @@ function _getCtxHelpers(cc) {
|
|
|
121
135
|
* @param v property value
|
|
122
136
|
*/
|
|
123
137
|
function set(key, v) {
|
|
124
|
-
|
|
138
|
+
getCtx()[key] = v;
|
|
125
139
|
}
|
|
126
140
|
return {
|
|
127
141
|
getCtx,
|
|
128
|
-
restoreCtx: () => currentContext = cc,
|
|
129
|
-
clearCtx: () => cc === currentContext ? currentContext = null : null,
|
|
142
|
+
restoreCtx: () => (currentContext = cc),
|
|
143
|
+
clearCtx: () => cc === currentContext ? (currentContext = null) : null,
|
|
130
144
|
store,
|
|
131
145
|
getStore: get,
|
|
132
146
|
setStore: set,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "@wooksjs/event-core",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@prostojs/logger": "^0.3.
|
|
34
|
+
"@prostojs/logger": "^0.3.6"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-core#readme"
|
|
37
37
|
}
|