@thi.ng/rstream 8.3.19 → 8.4.0
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/CHANGELOG.md +13 -1
- package/README.md +10 -4
- package/api.d.ts +1 -1
- package/async.d.ts +17 -0
- package/async.js +57 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +14 -10
- package/subscription.d.ts +1 -1
- package/transduce.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-04-11T12:32:44Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,18 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [8.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@8.4.0) (2024-04-11)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add fromAsync() / asAsync() converters & tests ([df57056](https://github.com/thi-ng/umbrella/commit/df57056))
|
|
17
|
+
|
|
18
|
+
### [8.3.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@8.3.20) (2024-04-08)
|
|
19
|
+
|
|
20
|
+
#### ♻️ Refactoring
|
|
21
|
+
|
|
22
|
+
- update reducer handling due to updates in [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/main/packages/transducers) pkg ([e0e5654](https://github.com/thi-ng/umbrella/commit/e0e5654))
|
|
23
|
+
|
|
12
24
|
### [8.3.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@8.3.6) (2024-02-22)
|
|
13
25
|
|
|
14
26
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 192 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -194,7 +194,13 @@ src.transformTopic("foo", map((e) => e.value), { error: handleError })
|
|
|
194
194
|
yarn add @thi.ng/rstream
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
ESM import:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import * as rs from "@thi.ng/rstream";
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Browser ESM import:
|
|
198
204
|
|
|
199
205
|
```html
|
|
200
206
|
<script type="module" src="https://cdn.skypack.dev/@thi.ng/rstream"></script>
|
|
@@ -205,10 +211,10 @@ ES module import:
|
|
|
205
211
|
For Node.js REPL:
|
|
206
212
|
|
|
207
213
|
```js
|
|
208
|
-
const
|
|
214
|
+
const rs = await import("@thi.ng/rstream");
|
|
209
215
|
```
|
|
210
216
|
|
|
211
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 6.
|
|
217
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 6.32 KB
|
|
212
218
|
|
|
213
219
|
## Dependencies
|
|
214
220
|
|
package/api.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface TransformableOpts<A, B> extends CommonOpts, WithTransform<A, B>
|
|
|
75
75
|
export type ErrorHandler = Fn<any, boolean>;
|
|
76
76
|
export interface WithErrorHandler {
|
|
77
77
|
/**
|
|
78
|
-
* Optional error handler to use for this
|
|
78
|
+
* Optional error handler to use for this stream/subscription
|
|
79
79
|
*/
|
|
80
80
|
error: ErrorHandler;
|
|
81
81
|
}
|
package/async.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ISubscription, type WithErrorHandlerOpts } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new {@link stream} from given async iterable `src` and `opts`.
|
|
4
|
+
*
|
|
5
|
+
* @param src
|
|
6
|
+
* @param opts
|
|
7
|
+
*/
|
|
8
|
+
export declare const fromAsync: <T>(src: AsyncIterable<T>, opts?: Partial<WithErrorHandlerOpts>) => import("./stream.js").Stream<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Reverse operation of {@link fromAsync}. Returns an async iterator which
|
|
11
|
+
* subscribes to given `src` sub and yields values as long as the `src` is
|
|
12
|
+
* intact.
|
|
13
|
+
*
|
|
14
|
+
* @param src
|
|
15
|
+
*/
|
|
16
|
+
export declare function asAsync<T>(src: ISubscription<any, T>): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
17
|
+
//# sourceMappingURL=async.d.ts.map
|
package/async.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SEMAPHORE } from "@thi.ng/api/api";
|
|
2
|
+
import { State } from "./api.js";
|
|
3
|
+
import { stream } from "./stream.js";
|
|
4
|
+
const fromAsync = (src, opts) => stream(($stream) => {
|
|
5
|
+
let active = true;
|
|
6
|
+
(async () => {
|
|
7
|
+
try {
|
|
8
|
+
for await (let x of src) {
|
|
9
|
+
if (!active)
|
|
10
|
+
return;
|
|
11
|
+
$stream.next(x);
|
|
12
|
+
}
|
|
13
|
+
$stream.done();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
$stream.error(e);
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
return () => active = false;
|
|
19
|
+
}, opts);
|
|
20
|
+
async function* asAsync(src) {
|
|
21
|
+
let resolve;
|
|
22
|
+
let initial;
|
|
23
|
+
const $newInitial = () => {
|
|
24
|
+
return initial = new Promise(($resolve) => {
|
|
25
|
+
resolve = $resolve;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const promises = [$newInitial()];
|
|
29
|
+
src.subscribe({
|
|
30
|
+
next(x) {
|
|
31
|
+
if (initial) {
|
|
32
|
+
resolve(x);
|
|
33
|
+
initial = void 0;
|
|
34
|
+
} else
|
|
35
|
+
promises.push(Promise.resolve(x));
|
|
36
|
+
},
|
|
37
|
+
done() {
|
|
38
|
+
if (initial) {
|
|
39
|
+
resolve(SEMAPHORE);
|
|
40
|
+
initial = void 0;
|
|
41
|
+
} else
|
|
42
|
+
promises.push(Promise.resolve(SEMAPHORE));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
while (promises.length && src.getState() < State.ERROR) {
|
|
46
|
+
const res = await promises.shift();
|
|
47
|
+
if (res === SEMAPHORE)
|
|
48
|
+
break;
|
|
49
|
+
if (!promises.length)
|
|
50
|
+
promises[0] = $newInitial();
|
|
51
|
+
yield res;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
asAsync,
|
|
56
|
+
fromAsync
|
|
57
|
+
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/associative": "^6.3.
|
|
46
|
-
"@thi.ng/atom": "^5.2.
|
|
47
|
-
"@thi.ng/checks": "^3.
|
|
48
|
-
"@thi.ng/errors": "^2.5.
|
|
49
|
-
"@thi.ng/logger": "^3.0.
|
|
50
|
-
"@thi.ng/transducers": "^
|
|
43
|
+
"@thi.ng/api": "^8.10.1",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.3",
|
|
45
|
+
"@thi.ng/associative": "^6.3.56",
|
|
46
|
+
"@thi.ng/atom": "^5.2.43",
|
|
47
|
+
"@thi.ng/checks": "^3.6.1",
|
|
48
|
+
"@thi.ng/errors": "^2.5.4",
|
|
49
|
+
"@thi.ng/logger": "^3.0.9",
|
|
50
|
+
"@thi.ng/transducers": "^9.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@microsoft/api-extractor": "^7.43.0",
|
|
@@ -94,6 +94,9 @@
|
|
|
94
94
|
"./asidechain": {
|
|
95
95
|
"default": "./asidechain.js"
|
|
96
96
|
},
|
|
97
|
+
"./async": {
|
|
98
|
+
"default": "./async.js"
|
|
99
|
+
},
|
|
97
100
|
"./atom": {
|
|
98
101
|
"default": "./atom.js"
|
|
99
102
|
},
|
|
@@ -207,6 +210,7 @@
|
|
|
207
210
|
}
|
|
208
211
|
},
|
|
209
212
|
"thi.ng": {
|
|
213
|
+
"alias": "rs",
|
|
210
214
|
"related": [
|
|
211
215
|
"atom",
|
|
212
216
|
"hdom",
|
|
@@ -215,5 +219,5 @@
|
|
|
215
219
|
],
|
|
216
220
|
"year": 2017
|
|
217
221
|
},
|
|
218
|
-
"gitHead": "
|
|
222
|
+
"gitHead": "18a0c063a7b33d790e5bc2486c106f45f663ac28\n"
|
|
219
223
|
}
|
package/subscription.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare class Subscription<A, B> implements ISubscription<A, B> {
|
|
|
60
60
|
closeOut: CloseMode;
|
|
61
61
|
parent?: ISubscription<any, A>;
|
|
62
62
|
__owner?: ISubscription<any, any>;
|
|
63
|
-
protected xform?: Reducer<B[]
|
|
63
|
+
protected xform?: Reducer<A, B[]>;
|
|
64
64
|
protected cacheLast: boolean;
|
|
65
65
|
protected last: any;
|
|
66
66
|
protected state: State;
|
package/transduce.d.ts
CHANGED
|
@@ -27,5 +27,5 @@ import type { Subscription } from "./subscription.js";
|
|
|
27
27
|
* @param rfn -
|
|
28
28
|
* @param init -
|
|
29
29
|
*/
|
|
30
|
-
export declare const transduce: <A, B, C>(src: Subscription<any, A>, xform: Transducer<A, B>, rfn: Reducer<
|
|
30
|
+
export declare const transduce: <A, B, C>(src: Subscription<any, A>, xform: Transducer<A, B>, rfn: Reducer<B, C>, init?: C) => Promise<C>;
|
|
31
31
|
//# sourceMappingURL=transduce.d.ts.map
|