@wooksjs/event-core 0.7.11 → 0.7.12
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 +20 -49
- package/dist/index.mjs +17 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key$1; i < n; i++) {
|
|
10
|
-
key$1 = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key$1) && key$1 !== except) __defProp(to, key$1, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key$1),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key$1)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const node_async_hooks = __toESM(require("node:async_hooks"));
|
|
25
|
-
const node_crypto = __toESM(require("node:crypto"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_async_hooks = require("node:async_hooks");
|
|
3
|
+
let node_crypto = require("node:crypto");
|
|
26
4
|
|
|
27
5
|
//#region packages/event-core/src/key.ts
|
|
28
6
|
let nextId = 0;
|
|
@@ -106,12 +84,8 @@ var CachedError = class {
|
|
|
106
84
|
* ```
|
|
107
85
|
*/
|
|
108
86
|
var EventContext = class {
|
|
109
|
-
/** Logger instance for this event. */
|
|
110
|
-
logger;
|
|
111
|
-
/** Parent context for read-through and scoped writes. */
|
|
112
|
-
parent;
|
|
113
|
-
slots = /* @__PURE__ */ new Map();
|
|
114
87
|
constructor(options) {
|
|
88
|
+
this.slots = /* @__PURE__ */ new Map();
|
|
115
89
|
this.logger = options.logger;
|
|
116
90
|
this.parent = options.parent;
|
|
117
91
|
}
|
|
@@ -140,7 +114,7 @@ var EventContext = class {
|
|
|
140
114
|
if (val !== void 0) {
|
|
141
115
|
if (val === COMPUTING) throw new Error(`Circular dependency detected for "${accessor._name}"`);
|
|
142
116
|
if (val instanceof CachedError) throw val.error;
|
|
143
|
-
if (val === UNDEFINED) return
|
|
117
|
+
if (val === UNDEFINED) return;
|
|
144
118
|
return val;
|
|
145
119
|
}
|
|
146
120
|
if (isCached(accessor)) {
|
|
@@ -160,14 +134,14 @@ var EventContext = class {
|
|
|
160
134
|
* Writes a value to a typed slot. If the slot already exists somewhere in the
|
|
161
135
|
* parent chain, the value is written there. Otherwise, it is written locally.
|
|
162
136
|
*/
|
|
163
|
-
set(key
|
|
137
|
+
set(key, value) {
|
|
164
138
|
const encoded = value === void 0 ? UNDEFINED : value;
|
|
165
|
-
if (this.slots.has(key
|
|
166
|
-
this.slots.set(key
|
|
139
|
+
if (this.slots.has(key._id)) {
|
|
140
|
+
this.slots.set(key._id, encoded);
|
|
167
141
|
return;
|
|
168
142
|
}
|
|
169
|
-
if (this.parent && this._shouldTraverseParent(key
|
|
170
|
-
this.slots.set(key
|
|
143
|
+
if (this.parent && this._shouldTraverseParent(key._id) && this.parent._setIfExists(key._id, encoded)) return;
|
|
144
|
+
this.slots.set(key._id, encoded);
|
|
171
145
|
}
|
|
172
146
|
/**
|
|
173
147
|
* Returns `true` if the slot has been set or computed in this context or any parent.
|
|
@@ -188,7 +162,7 @@ var EventContext = class {
|
|
|
188
162
|
if (val !== void 0) {
|
|
189
163
|
if (val === COMPUTING) throw new Error(`Circular dependency detected for "${accessor._name}"`);
|
|
190
164
|
if (val instanceof CachedError) throw val.error;
|
|
191
|
-
if (val === UNDEFINED) return
|
|
165
|
+
if (val === UNDEFINED) return;
|
|
192
166
|
return val;
|
|
193
167
|
}
|
|
194
168
|
if (isCached(accessor)) {
|
|
@@ -207,8 +181,8 @@ var EventContext = class {
|
|
|
207
181
|
/**
|
|
208
182
|
* Writes a value to a typed slot in this context only, ignoring parents.
|
|
209
183
|
*/
|
|
210
|
-
setOwn(key
|
|
211
|
-
this.slots.set(key
|
|
184
|
+
setOwn(key, value) {
|
|
185
|
+
this.slots.set(key._id, value === void 0 ? UNDEFINED : value);
|
|
212
186
|
}
|
|
213
187
|
/**
|
|
214
188
|
* Returns `true` if the slot has been set or computed in this context only.
|
|
@@ -254,8 +228,7 @@ var EventContext = class {
|
|
|
254
228
|
*/
|
|
255
229
|
var ContextInjector = class {
|
|
256
230
|
with(name, attributes, cb) {
|
|
257
|
-
|
|
258
|
-
return fn();
|
|
231
|
+
return (typeof attributes === "function" ? attributes : cb)();
|
|
259
232
|
}
|
|
260
233
|
/**
|
|
261
234
|
* Hook called by adapters at specific lifecycle points (e.g., after route lookup).
|
|
@@ -305,7 +278,7 @@ function resetContextInjector() {
|
|
|
305
278
|
//#region packages/event-core/src/storage.ts
|
|
306
279
|
const STORAGE_KEY = Symbol.for("wooks.core.asyncStorage");
|
|
307
280
|
const VERSION_KEY = Symbol.for("wooks.core.asyncStorage.version");
|
|
308
|
-
const CURRENT_VERSION = "0.7.
|
|
281
|
+
const CURRENT_VERSION = "0.7.11";
|
|
309
282
|
const _g = globalThis;
|
|
310
283
|
if (_g[STORAGE_KEY]) {
|
|
311
284
|
if (_g[VERSION_KEY] !== CURRENT_VERSION) throw new Error(`[wooks] Incompatible versions of @wooksjs/event-core detected: existing v${_g[VERSION_KEY]}, loading v${CURRENT_VERSION}. All packages must use the same @wooksjs/event-core version.`);
|
|
@@ -356,8 +329,7 @@ function tryGetCurrent() {
|
|
|
356
329
|
return storage.getStore();
|
|
357
330
|
}
|
|
358
331
|
function useLogger(topicOrCtx, maybeCtx) {
|
|
359
|
-
const
|
|
360
|
-
const logger = ctx.logger;
|
|
332
|
+
const logger = ((typeof topicOrCtx === "string" ? maybeCtx : topicOrCtx) ?? current()).logger;
|
|
361
333
|
if (typeof topicOrCtx === "string" && logger.createTopic) return logger.createTopic(topicOrCtx);
|
|
362
334
|
return logger;
|
|
363
335
|
}
|
|
@@ -366,8 +338,8 @@ function createEventContext(options, kindOrFn, seedsOrUndefined, maybeFn) {
|
|
|
366
338
|
if (typeof kindOrFn === "function") return run(ctx, kindOrFn);
|
|
367
339
|
return run(ctx, () => {
|
|
368
340
|
ctx.seed(kindOrFn, seedsOrUndefined);
|
|
369
|
-
const ci
|
|
370
|
-
return ci
|
|
341
|
+
const ci = getContextInjector();
|
|
342
|
+
return ci ? ci.with("Event:start", { eventType: kindOrFn.name }, maybeFn) : maybeFn();
|
|
371
343
|
});
|
|
372
344
|
}
|
|
373
345
|
|
|
@@ -483,7 +455,7 @@ function defineEventKind(name, schema) {
|
|
|
483
455
|
*/
|
|
484
456
|
function defineWook(factory) {
|
|
485
457
|
const _slot = cached(factory);
|
|
486
|
-
return Object.assign((ctx) => (ctx ?? current()).get(_slot), { _slot });
|
|
458
|
+
return Object.assign(((ctx) => (ctx ?? current()).get(_slot)), { _slot });
|
|
487
459
|
}
|
|
488
460
|
|
|
489
461
|
//#endregion
|
|
@@ -505,8 +477,7 @@ const eventIdSlot = cached(() => (0, node_crypto.randomUUID)());
|
|
|
505
477
|
* ```
|
|
506
478
|
*/
|
|
507
479
|
function useRouteParams(ctx) {
|
|
508
|
-
const
|
|
509
|
-
const params = c.get(routeParamsKey);
|
|
480
|
+
const params = (ctx ?? current()).get(routeParamsKey);
|
|
510
481
|
return {
|
|
511
482
|
params,
|
|
512
483
|
get: (name) => params[name]
|
package/dist/index.mjs
CHANGED
|
@@ -83,12 +83,8 @@ var CachedError = class {
|
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
85
|
var EventContext = class {
|
|
86
|
-
/** Logger instance for this event. */
|
|
87
|
-
logger;
|
|
88
|
-
/** Parent context for read-through and scoped writes. */
|
|
89
|
-
parent;
|
|
90
|
-
slots = /* @__PURE__ */ new Map();
|
|
91
86
|
constructor(options) {
|
|
87
|
+
this.slots = /* @__PURE__ */ new Map();
|
|
92
88
|
this.logger = options.logger;
|
|
93
89
|
this.parent = options.parent;
|
|
94
90
|
}
|
|
@@ -117,7 +113,7 @@ var EventContext = class {
|
|
|
117
113
|
if (val !== void 0) {
|
|
118
114
|
if (val === COMPUTING) throw new Error(`Circular dependency detected for "${accessor._name}"`);
|
|
119
115
|
if (val instanceof CachedError) throw val.error;
|
|
120
|
-
if (val === UNDEFINED) return
|
|
116
|
+
if (val === UNDEFINED) return;
|
|
121
117
|
return val;
|
|
122
118
|
}
|
|
123
119
|
if (isCached(accessor)) {
|
|
@@ -137,14 +133,14 @@ var EventContext = class {
|
|
|
137
133
|
* Writes a value to a typed slot. If the slot already exists somewhere in the
|
|
138
134
|
* parent chain, the value is written there. Otherwise, it is written locally.
|
|
139
135
|
*/
|
|
140
|
-
set(key
|
|
136
|
+
set(key, value) {
|
|
141
137
|
const encoded = value === void 0 ? UNDEFINED : value;
|
|
142
|
-
if (this.slots.has(key
|
|
143
|
-
this.slots.set(key
|
|
138
|
+
if (this.slots.has(key._id)) {
|
|
139
|
+
this.slots.set(key._id, encoded);
|
|
144
140
|
return;
|
|
145
141
|
}
|
|
146
|
-
if (this.parent && this._shouldTraverseParent(key
|
|
147
|
-
this.slots.set(key
|
|
142
|
+
if (this.parent && this._shouldTraverseParent(key._id) && this.parent._setIfExists(key._id, encoded)) return;
|
|
143
|
+
this.slots.set(key._id, encoded);
|
|
148
144
|
}
|
|
149
145
|
/**
|
|
150
146
|
* Returns `true` if the slot has been set or computed in this context or any parent.
|
|
@@ -165,7 +161,7 @@ var EventContext = class {
|
|
|
165
161
|
if (val !== void 0) {
|
|
166
162
|
if (val === COMPUTING) throw new Error(`Circular dependency detected for "${accessor._name}"`);
|
|
167
163
|
if (val instanceof CachedError) throw val.error;
|
|
168
|
-
if (val === UNDEFINED) return
|
|
164
|
+
if (val === UNDEFINED) return;
|
|
169
165
|
return val;
|
|
170
166
|
}
|
|
171
167
|
if (isCached(accessor)) {
|
|
@@ -184,8 +180,8 @@ var EventContext = class {
|
|
|
184
180
|
/**
|
|
185
181
|
* Writes a value to a typed slot in this context only, ignoring parents.
|
|
186
182
|
*/
|
|
187
|
-
setOwn(key
|
|
188
|
-
this.slots.set(key
|
|
183
|
+
setOwn(key, value) {
|
|
184
|
+
this.slots.set(key._id, value === void 0 ? UNDEFINED : value);
|
|
189
185
|
}
|
|
190
186
|
/**
|
|
191
187
|
* Returns `true` if the slot has been set or computed in this context only.
|
|
@@ -231,8 +227,7 @@ var EventContext = class {
|
|
|
231
227
|
*/
|
|
232
228
|
var ContextInjector = class {
|
|
233
229
|
with(name, attributes, cb) {
|
|
234
|
-
|
|
235
|
-
return fn();
|
|
230
|
+
return (typeof attributes === "function" ? attributes : cb)();
|
|
236
231
|
}
|
|
237
232
|
/**
|
|
238
233
|
* Hook called by adapters at specific lifecycle points (e.g., after route lookup).
|
|
@@ -282,7 +277,7 @@ function resetContextInjector() {
|
|
|
282
277
|
//#region packages/event-core/src/storage.ts
|
|
283
278
|
const STORAGE_KEY = Symbol.for("wooks.core.asyncStorage");
|
|
284
279
|
const VERSION_KEY = Symbol.for("wooks.core.asyncStorage.version");
|
|
285
|
-
const CURRENT_VERSION = "0.7.
|
|
280
|
+
const CURRENT_VERSION = "0.7.11";
|
|
286
281
|
const _g = globalThis;
|
|
287
282
|
if (_g[STORAGE_KEY]) {
|
|
288
283
|
if (_g[VERSION_KEY] !== CURRENT_VERSION) throw new Error(`[wooks] Incompatible versions of @wooksjs/event-core detected: existing v${_g[VERSION_KEY]}, loading v${CURRENT_VERSION}. All packages must use the same @wooksjs/event-core version.`);
|
|
@@ -333,8 +328,7 @@ function tryGetCurrent() {
|
|
|
333
328
|
return storage.getStore();
|
|
334
329
|
}
|
|
335
330
|
function useLogger(topicOrCtx, maybeCtx) {
|
|
336
|
-
const
|
|
337
|
-
const logger = ctx.logger;
|
|
331
|
+
const logger = ((typeof topicOrCtx === "string" ? maybeCtx : topicOrCtx) ?? current()).logger;
|
|
338
332
|
if (typeof topicOrCtx === "string" && logger.createTopic) return logger.createTopic(topicOrCtx);
|
|
339
333
|
return logger;
|
|
340
334
|
}
|
|
@@ -343,8 +337,8 @@ function createEventContext(options, kindOrFn, seedsOrUndefined, maybeFn) {
|
|
|
343
337
|
if (typeof kindOrFn === "function") return run(ctx, kindOrFn);
|
|
344
338
|
return run(ctx, () => {
|
|
345
339
|
ctx.seed(kindOrFn, seedsOrUndefined);
|
|
346
|
-
const ci
|
|
347
|
-
return ci
|
|
340
|
+
const ci = getContextInjector();
|
|
341
|
+
return ci ? ci.with("Event:start", { eventType: kindOrFn.name }, maybeFn) : maybeFn();
|
|
348
342
|
});
|
|
349
343
|
}
|
|
350
344
|
|
|
@@ -460,7 +454,7 @@ function defineEventKind(name, schema) {
|
|
|
460
454
|
*/
|
|
461
455
|
function defineWook(factory) {
|
|
462
456
|
const _slot = cached(factory);
|
|
463
|
-
return Object.assign((ctx) => (ctx ?? current()).get(_slot), { _slot });
|
|
457
|
+
return Object.assign(((ctx) => (ctx ?? current()).get(_slot)), { _slot });
|
|
464
458
|
}
|
|
465
459
|
|
|
466
460
|
//#endregion
|
|
@@ -482,8 +476,7 @@ const eventIdSlot = cached(() => randomUUID());
|
|
|
482
476
|
* ```
|
|
483
477
|
*/
|
|
484
478
|
function useRouteParams(ctx) {
|
|
485
|
-
const
|
|
486
|
-
const params = c.get(routeParamsKey);
|
|
479
|
+
const params = (ctx ?? current()).get(routeParamsKey);
|
|
487
480
|
return {
|
|
488
481
|
params,
|
|
489
482
|
get: (name) => params[name]
|