uneventful 0.0.11 → 0.0.13
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/call-or-wait-CvOF0pao.mjs +22 -0
- package/dist/ext.d.ts +35 -47
- package/dist/ext.mjs +32 -24
- package/dist/hooks-BnMYHRlM.mjs +583 -0
- package/dist/{jobutils-Dvu-e99o.mjs → jobutils-O9tOTNKC.mjs} +116 -36
- package/dist/mod.d.ts +16 -54
- package/dist/mod.mjs +8 -8
- package/dist/shared.d.ts +88 -50
- package/dist/shared.mjs +51 -3
- package/dist/signals.d.ts +202 -46
- package/dist/signals.mjs +86 -528
- package/dist/{sinks-5TuxCRtX.d.ts → sinks-B_LfTZgF.d.ts} +1 -1
- package/dist/{types-N2ua11te.d.ts → types-pElgImr7.d.ts} +8 -57
- package/dist/{utils-cyEhnyp7.mjs → utils-BgqyDPjA.mjs} +33 -3
- package/dist/utils.d.ts +52 -7
- package/dist/utils.mjs +1 -1
- package/package.json +11 -12
- package/dist/call-or-wait-EzXJX5Dq.mjs +0 -111
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { s as start, j as connect, p as isValue, h as isError, f as markHandled } from './jobutils-O9tOTNKC.mjs';
|
|
2
|
+
import { i as isFunction } from './utils-BgqyDPjA.mjs';
|
|
3
|
+
|
|
4
|
+
function callOrWait(source, method, handler, noArgs) {
|
|
5
|
+
if (source && isFunction(source[method]))
|
|
6
|
+
return source[method]();
|
|
7
|
+
if (!isFunction(source))
|
|
8
|
+
mustBeSourceOrSignal();
|
|
9
|
+
return (source.length === 0 ? noArgs(source) : false) || start((job) => {
|
|
10
|
+
connect(source, (v) => handler(job, v)).do((r) => {
|
|
11
|
+
if (isValue(r))
|
|
12
|
+
job.throw(new Error("Stream ended"));
|
|
13
|
+
else if (isError(r))
|
|
14
|
+
job.throw(markHandled(r));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function mustBeSourceOrSignal() {
|
|
19
|
+
throw new TypeError("not a source or signal");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { callOrWait as c, mustBeSourceOrSignal as m };
|
package/dist/ext.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PlainFunction } from './types-
|
|
1
|
+
import { P as PlainFunction } from './types-pElgImr7.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This module provides helpers for creating *extensions*: a way of extending
|
|
@@ -15,8 +15,7 @@ import { P as PlainFunction } from './types-N2ua11te.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @module uneventful/ext
|
|
17
17
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
18
|
+
* @disableGroups
|
|
20
19
|
* @summary Tools for extending objects with extra state and behavior, without
|
|
21
20
|
* directly modifying them.
|
|
22
21
|
*/
|
|
@@ -100,23 +99,19 @@ declare function ext<Target extends WeakKey, ExtType extends Object>(factory: (t
|
|
|
100
99
|
* arguments (minus an initial `target` argument).
|
|
101
100
|
*/
|
|
102
101
|
declare function method<Target extends object, Method extends PlainFunction>(factory: (tgt: Target, map: WeakMap<Target, Method>) => Method, map?: WeakMap<Target, Method>): (tgt: Target, ...args: Parameters<Method>) => ReturnType<Method>;
|
|
103
|
-
/** Helper types for working with {@link Ext} Subclasses */
|
|
102
|
+
/** Helper types for working with {@link Ext} Subclasses @experimental */
|
|
104
103
|
declare namespace Ext {
|
|
105
104
|
/** Get the target type of an {@link Ext} subclass constructor */
|
|
106
105
|
type Target<T extends Ext.Class> = InstanceType<T>["of"];
|
|
107
106
|
/**
|
|
108
107
|
* Get the type of extension that will be returned by the static API.
|
|
109
108
|
*
|
|
110
|
-
* Defaults to the subclass instance type, but can be
|
|
111
|
-
*
|
|
112
|
-
* {@link Ext.__new__ `__new__()`} method is also overridden to return that
|
|
113
|
-
* type.
|
|
109
|
+
* Defaults to the subclass instance type, but can be changed by overriding
|
|
110
|
+
* {@link Ext.__new__ `__new__()`} to return a different type.
|
|
114
111
|
*/
|
|
115
112
|
type Type<T extends Ext.Class> = InstanceType<T> extends {
|
|
116
|
-
|
|
113
|
+
__new__(ob: any): infer R;
|
|
117
114
|
} ? (unknown extends R ? InstanceType<T> : R) : InstanceType<T>;
|
|
118
|
-
/** The type of weakmap passed to {@link Ext.__new__ `__new__()`} */
|
|
119
|
-
type Map<Class extends Ext.Class> = WeakMap<Ext.Target<Class>, any>;
|
|
120
115
|
/**
|
|
121
116
|
* The type constraint for static generics in the API; you probably won't use this directly.
|
|
122
117
|
*/
|
|
@@ -148,6 +143,8 @@ declare namespace Ext {
|
|
|
148
143
|
*
|
|
149
144
|
* Instance and static members you can override to customize extension creation,
|
|
150
145
|
* deletion, target and return types.
|
|
146
|
+
*
|
|
147
|
+
* @experimental
|
|
151
148
|
*/
|
|
152
149
|
declare abstract class Ext<Target extends WeakKey = WeakKey> {
|
|
153
150
|
/**
|
|
@@ -160,28 +157,13 @@ declare abstract class Ext<Target extends WeakKey = WeakKey> {
|
|
|
160
157
|
*/
|
|
161
158
|
readonly of: Target;
|
|
162
159
|
/**
|
|
163
|
-
*
|
|
164
|
-
* interface's return type. For example, if a subclass does `declare readonly __type__:
|
|
165
|
-
* Promise<this>`, and overrides `__new__`() to return a promise, then the
|
|
166
|
-
* static APIs for the subclass (like `.for()`) will return promises instead
|
|
167
|
-
* of instances. (See the {@link __new__ `__new__`} method for more
|
|
168
|
-
* details.)
|
|
160
|
+
* @deprecated Use `.for()` or `prototype.__inst__()` instead!
|
|
169
161
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*/
|
|
176
|
-
readonly __type__: unknown;
|
|
177
|
-
/**
|
|
178
|
-
* @deprecated Use .for() instead!
|
|
179
|
-
*
|
|
180
|
-
* Never directly call the constructor of an Ext subclass except from the
|
|
181
|
-
* {@link __new__ `__new__()`} method - otherwise you run the risk of having
|
|
182
|
-
* multiple instances for the same target. (And it may accept invalid
|
|
183
|
-
* parameter values if you've redefined the type of the {@link Ext.of `of`}
|
|
184
|
-
* property in a sub-subclass.)
|
|
162
|
+
* Never directly call the constructor of an Ext subclass. If you're
|
|
163
|
+
* creating an instance in {@link __new__ `__new__()`}, use the
|
|
164
|
+
* {@link __inst__ `__inst__()`} method instead. Otherwise,
|
|
165
|
+
* you should use the .for or .get methods, as they are properly typed
|
|
166
|
+
* and won't create multiple instances for the same target.
|
|
185
167
|
*/
|
|
186
168
|
constructor(of: Target);
|
|
187
169
|
/**
|
|
@@ -215,22 +197,16 @@ declare abstract class Ext<Target extends WeakKey = WeakKey> {
|
|
|
215
197
|
* behavior, e.g. to execute the constructor within a job, or create a
|
|
216
198
|
* promise for an extension instance to be asynchronously initiaized, etc.
|
|
217
199
|
*
|
|
218
|
-
*
|
|
219
|
-
* you must also redeclare the type of the {@link __type__ `__type__`}
|
|
220
|
-
* property. For example:
|
|
200
|
+
* For example:
|
|
221
201
|
*
|
|
222
202
|
* ```ts
|
|
223
|
-
* class AsyncExt extends Ext {
|
|
224
|
-
* declare readonly __type__: Job<this>
|
|
225
|
-
*
|
|
203
|
+
* class AsyncExt extends Ext<SomeType> {
|
|
226
204
|
* // simulate slow initialization
|
|
227
205
|
* *setup() { yield *sleep(100); return this; }
|
|
228
206
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* const ext = new this(tgt);
|
|
233
|
-
* map.set(tgt, root.start(ext.setup()) as Ext.Type<Class>);
|
|
207
|
+
* __new__(tgt: SomeType): Job<this> {
|
|
208
|
+
* const ext = this.__inst__(tgt);
|
|
209
|
+
* return start(this.__inst__(tgt).setup())
|
|
234
210
|
* }
|
|
235
211
|
* }
|
|
236
212
|
* ```
|
|
@@ -239,13 +215,25 @@ declare abstract class Ext<Target extends WeakKey = WeakKey> {
|
|
|
239
215
|
* extension whose `setup()` has finished. (And subclasses of `AsyncExt`
|
|
240
216
|
* will share the same behavior, while being subtyped appropriately.)
|
|
241
217
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
218
|
+
* @remarks Note that while this is technically an instance method, it's
|
|
219
|
+
* actually called with the class *prototype*, so you should not use any
|
|
220
|
+
* properties or methods of `this` other than `__inst__`. Think of it
|
|
221
|
+
* as a function that's just on the class as a convenient way of configuring
|
|
222
|
+
* it.
|
|
223
|
+
*
|
|
224
|
+
* @category Lifecycle Hooks
|
|
225
|
+
*/
|
|
226
|
+
__new__<C extends Ext>(this: C, tgt: C["of"]): unknown;
|
|
227
|
+
/**
|
|
228
|
+
* Given a target, create an extension instance.
|
|
229
|
+
*
|
|
230
|
+
* You do not need to override this, nor should you: it's just a type-safe
|
|
231
|
+
* way to construct an extension instance, since an Ext subclass's
|
|
232
|
+
* constructor may accept a wider type than the class actually requires.
|
|
245
233
|
*
|
|
246
234
|
* @category Lifecycle Hooks
|
|
247
235
|
*/
|
|
248
|
-
|
|
236
|
+
__inst__<T extends Ext>(this: T, tgt: T["of"]): T;
|
|
249
237
|
/**
|
|
250
238
|
* This method is called by {@link delete}() if it finds an existing
|
|
251
239
|
* extension for the target. You can override it in a subclass to do any
|
package/dist/ext.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as setMap } from './utils-
|
|
1
|
+
import { s as setMap } from './utils-BgqyDPjA.mjs';
|
|
2
2
|
|
|
3
3
|
function ext(factory, map = /* @__PURE__ */ new WeakMap()) {
|
|
4
4
|
return (tgt) => map.has(tgt) ? map.get(tgt) : setMap(map, tgt, factory(tgt, map));
|
|
@@ -9,13 +9,13 @@ function method(factory, map = /* @__PURE__ */ new WeakMap()) {
|
|
|
9
9
|
const classMap = /* @__PURE__ */ ext((cls) => /* @__PURE__ */ new WeakMap());
|
|
10
10
|
class Ext {
|
|
11
11
|
/**
|
|
12
|
-
* @deprecated Use
|
|
12
|
+
* @deprecated Use `.for()` or `prototype.__inst__()` instead!
|
|
13
13
|
*
|
|
14
|
-
* Never directly call the constructor of an Ext subclass
|
|
15
|
-
* {@link __new__ `__new__()`}
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* Never directly call the constructor of an Ext subclass. If you're
|
|
15
|
+
* creating an instance in {@link __new__ `__new__()`}, use the
|
|
16
|
+
* {@link __inst__ `__inst__()`} method instead. Otherwise,
|
|
17
|
+
* you should use the .for or .get methods, as they are properly typed
|
|
18
|
+
* and won't create multiple instances for the same target.
|
|
19
19
|
*/
|
|
20
20
|
constructor(of) {
|
|
21
21
|
this.of = of;
|
|
@@ -26,7 +26,7 @@ class Ext {
|
|
|
26
26
|
*/
|
|
27
27
|
static for(tgt) {
|
|
28
28
|
const map = classMap(this);
|
|
29
|
-
return map.get(tgt) ?? (
|
|
29
|
+
return map.get(tgt) ?? setMap(map, tgt, this.prototype.__new__(tgt));
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Get the current extension instance for the given target, or `undefined`
|
|
@@ -64,22 +64,16 @@ class Ext {
|
|
|
64
64
|
* behavior, e.g. to execute the constructor within a job, or create a
|
|
65
65
|
* promise for an extension instance to be asynchronously initiaized, etc.
|
|
66
66
|
*
|
|
67
|
-
*
|
|
68
|
-
* you must also redeclare the type of the {@link __type__ `__type__`}
|
|
69
|
-
* property. For example:
|
|
67
|
+
* For example:
|
|
70
68
|
*
|
|
71
69
|
* ```ts
|
|
72
|
-
* class AsyncExt extends Ext {
|
|
73
|
-
* declare readonly __type__: Job<this>
|
|
74
|
-
*
|
|
70
|
+
* class AsyncExt extends Ext<SomeType> {
|
|
75
71
|
* // simulate slow initialization
|
|
76
72
|
* *setup() { yield *sleep(100); return this; }
|
|
77
73
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* const ext = new this(tgt);
|
|
82
|
-
* map.set(tgt, root.start(ext.setup()) as Ext.Type<Class>);
|
|
74
|
+
* __new__(tgt: SomeType): Job<this> {
|
|
75
|
+
* const ext = this.__inst__(tgt);
|
|
76
|
+
* return start(this.__inst__(tgt).setup())
|
|
83
77
|
* }
|
|
84
78
|
* }
|
|
85
79
|
* ```
|
|
@@ -88,14 +82,28 @@ class Ext {
|
|
|
88
82
|
* extension whose `setup()` has finished. (And subclasses of `AsyncExt`
|
|
89
83
|
* will share the same behavior, while being subtyped appropriately.)
|
|
90
84
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
85
|
+
* @remarks Note that while this is technically an instance method, it's
|
|
86
|
+
* actually called with the class *prototype*, so you should not use any
|
|
87
|
+
* properties or methods of `this` other than `__inst__`. Think of it
|
|
88
|
+
* as a function that's just on the class as a convenient way of configuring
|
|
89
|
+
* it.
|
|
90
|
+
*
|
|
91
|
+
* @category Lifecycle Hooks
|
|
92
|
+
*/
|
|
93
|
+
__new__(tgt) {
|
|
94
|
+
return this.__inst__(tgt);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Given a target, create an extension instance.
|
|
98
|
+
*
|
|
99
|
+
* You do not need to override this, nor should you: it's just a type-safe
|
|
100
|
+
* way to construct an extension instance, since an Ext subclass's
|
|
101
|
+
* constructor may accept a wider type than the class actually requires.
|
|
94
102
|
*
|
|
95
103
|
* @category Lifecycle Hooks
|
|
96
104
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
__inst__(tgt) {
|
|
106
|
+
return new this.constructor(tgt);
|
|
99
107
|
}
|
|
100
108
|
/**
|
|
101
109
|
* This method is called by {@link delete}() if it finds an existing
|