@thi.ng/csp 3.0.0 → 3.1.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 +8 -1
- package/README.md +34 -6
- package/ops.d.ts +1 -0
- package/ops.js +9 -0
- package/package.json +2 -2
- package/pubsub.d.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-04-
|
|
3
|
+
- **Last updated**: 2024-04-26T13:32:20Z
|
|
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,13 @@ 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
|
+
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/csp@3.1.0) (2024-04-26)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add opt. generics for PubSub.subscribe()/unsubscribe() ([b4e9d20](https://github.com/thi-ng/umbrella/commit/b4e9d20))
|
|
17
|
+
- add into() to feed (async) iterables into a channel ([c7c1f6d](https://github.com/thi-ng/umbrella/commit/c7c1f6d))
|
|
18
|
+
|
|
12
19
|
# [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/csp@3.0.0) (2024-04-25)
|
|
13
20
|
|
|
14
21
|
#### 🛑 Breaking changes
|
package/README.md
CHANGED
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
16
16
|
|
|
17
17
|
- [About](#about)
|
|
18
|
+
- [Channel operators](#channel-operators)
|
|
18
19
|
- [Status](#status)
|
|
19
20
|
- [Related packages](#related-packages)
|
|
20
21
|
- [Installation](#installation)
|
|
21
22
|
- [Dependencies](#dependencies)
|
|
23
|
+
- [Usage examples](#usage-examples)
|
|
22
24
|
- [API](#api)
|
|
23
25
|
- [PubSub](#pubsub)
|
|
24
26
|
- [Authors](#authors)
|
|
@@ -49,6 +51,23 @@ Provided are:
|
|
|
49
51
|
- [`PubSub`](https://docs.thi.ng/umbrella/csp/classes/PubSub.html) for
|
|
50
52
|
topic-based subscriptions, each topic implemented as `Mult`
|
|
51
53
|
|
|
54
|
+
### Channel operators
|
|
55
|
+
|
|
56
|
+
- [`broadcast()`](https://docs.thi.ng/umbrella/csp/functions/broadcast.html)
|
|
57
|
+
- [`channel()`](https://docs.thi.ng/umbrella/csp/functions/channel.html)
|
|
58
|
+
- [`concat()`](https://docs.thi.ng/umbrella/csp/functions/concat.html)
|
|
59
|
+
- [`consume()`](https://docs.thi.ng/umbrella/csp/functions/consume.html)
|
|
60
|
+
- [`consumeWith()`](https://docs.thi.ng/umbrella/csp/functions/consumeWith.html)
|
|
61
|
+
- [`drain()`](https://docs.thi.ng/umbrella/csp/functions/drain.html)
|
|
62
|
+
- [`fromAsyncIterable()`](https://docs.thi.ng/umbrella/csp/functions/fromAsyncIterable.html)
|
|
63
|
+
- [`into()`](https://docs.thi.ng/umbrella/csp/functions/into.html)
|
|
64
|
+
- [`merge()`](https://docs.thi.ng/umbrella/csp/functions/merge.html)
|
|
65
|
+
- [`mult()`](https://docs.thi.ng/umbrella/csp/functions/mult.html)
|
|
66
|
+
- [`pipe()`](https://docs.thi.ng/umbrella/csp/functions/pipe.html)
|
|
67
|
+
- [`pubsub()`](https://docs.thi.ng/umbrella/csp/functions/pubsub.html)
|
|
68
|
+
- [`select()`](https://docs.thi.ng/umbrella/csp/functions/select.html)
|
|
69
|
+
- [`timeout()`](https://docs.thi.ng/umbrella/csp/functions/timeout.html)
|
|
70
|
+
|
|
52
71
|
## Status
|
|
53
72
|
|
|
54
73
|
**BETA** - possibly breaking changes forthcoming
|
|
@@ -87,7 +106,7 @@ For Node.js REPL:
|
|
|
87
106
|
const csp = await import("@thi.ng/csp");
|
|
88
107
|
```
|
|
89
108
|
|
|
90
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
109
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.79 KB
|
|
91
110
|
|
|
92
111
|
## Dependencies
|
|
93
112
|
|
|
@@ -96,6 +115,16 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.77 KB
|
|
|
96
115
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
97
116
|
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
98
117
|
|
|
118
|
+
## Usage examples
|
|
119
|
+
|
|
120
|
+
One project in this repo's
|
|
121
|
+
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
122
|
+
directory is using this package:
|
|
123
|
+
|
|
124
|
+
| Screenshot | Description | Live demo | Source |
|
|
125
|
+
|:---------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------|:----------------------------------------------|:---------------------------------------------------------------------------|
|
|
126
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/csp-bus.png" width="240"/> | CSP channel-based event handling, async transducers & reactive UI components | [Demo](https://demo.thi.ng/umbrella/csp-bus/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/csp-bus) |
|
|
127
|
+
|
|
99
128
|
## API
|
|
100
129
|
|
|
101
130
|
[Generated API docs](https://docs.thi.ng/umbrella/csp/)
|
|
@@ -103,7 +132,7 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.77 KB
|
|
|
103
132
|
### PubSub
|
|
104
133
|
|
|
105
134
|
```ts tangle:export/readme-pubsub.ts
|
|
106
|
-
import { channel, consumeWith, pubsub } from "@thi.ng/csp";
|
|
135
|
+
import { channel, consumeWith, into, pubsub } from "@thi.ng/csp";
|
|
107
136
|
|
|
108
137
|
// input channel (optional)
|
|
109
138
|
const src = channel<string>({ id: "users" });
|
|
@@ -120,10 +149,9 @@ for (let i of "abc") {
|
|
|
120
149
|
consumeWith(pub.subscribeTopic(i), (x, ch) => console.log(ch.id, x));
|
|
121
150
|
}
|
|
122
151
|
|
|
123
|
-
// start processing
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
152
|
+
// start processing by feeding an iterable of names
|
|
153
|
+
await into(src, ["alice", "bert", "bella", "charlie", "arthur"]);
|
|
154
|
+
|
|
127
155
|
// users-a-tap0 alice
|
|
128
156
|
// users-b-tap1 bert
|
|
129
157
|
// users-b-tap1 bella
|
package/ops.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const consumeWith: <T>(chan: Channel<T>, fn: Fn2<T, Channel<T>, v
|
|
|
17
17
|
export declare const drain: <T>(chan: Channel<T>) => Promise<Awaited<T>[]>;
|
|
18
18
|
export declare const fromAsyncIterable: <T>(src: AsyncIterable<T>, close?: boolean) => Channel<T>;
|
|
19
19
|
export declare const merge: <T>(src: Channel<T>[], dest?: Channel<T>, close?: boolean) => Channel<T>;
|
|
20
|
+
export declare const into: <T, DEST extends IWriteable<T> & IClosable>(chan: DEST, src: Iterable<T> | AsyncIterable<T>, close?: boolean) => Promise<void>;
|
|
20
21
|
export declare const pipe: <T, DEST extends IWriteable<T> & IClosable>(src: Channel<T>, dest: DEST, close?: boolean) => DEST;
|
|
21
22
|
export declare const select: <T>(input: Channel<T>, ...xs: Channel<T>[]) => Promise<[Maybe<T>, Channel<T>]>;
|
|
22
23
|
export declare const timeout: (delay: number) => Channel<any>;
|
package/ops.js
CHANGED
|
@@ -73,6 +73,14 @@ const merge = (src, dest, close = true) => {
|
|
|
73
73
|
})();
|
|
74
74
|
return dest;
|
|
75
75
|
};
|
|
76
|
+
const into = async (chan, src, close = false) => {
|
|
77
|
+
for await (let x of src) {
|
|
78
|
+
if (!chan.writable())
|
|
79
|
+
break;
|
|
80
|
+
await chan.write(x);
|
|
81
|
+
}
|
|
82
|
+
close && chan.close();
|
|
83
|
+
};
|
|
76
84
|
const pipe = (src, dest, close = true) => {
|
|
77
85
|
(async () => {
|
|
78
86
|
for await (let x of src) {
|
|
@@ -110,6 +118,7 @@ export {
|
|
|
110
118
|
consumeWith,
|
|
111
119
|
drain,
|
|
112
120
|
fromAsyncIterable,
|
|
121
|
+
into,
|
|
113
122
|
merge,
|
|
114
123
|
pipe,
|
|
115
124
|
select,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/csp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Primitives & operators for Communicating Sequential Processes based on async/await and async iterables",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"status": "beta",
|
|
107
107
|
"year": 2016
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "0bec55821066c18eb977a7eabd42c0bb2b096d98\n"
|
|
110
110
|
}
|
package/pubsub.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function pubsub<T>(src: Channel<T>, fn: TopicFn<T>): PubSub<T>;
|
|
|
7
7
|
export declare class PubSub<T> implements IWriteable<T>, IClosable {
|
|
8
8
|
protected src: Channel<T>;
|
|
9
9
|
protected fn: TopicFn<T>;
|
|
10
|
-
protected topics: IObjectOf<Mult<
|
|
10
|
+
protected topics: IObjectOf<Mult<any>>;
|
|
11
11
|
constructor(fn: TopicFn<T>);
|
|
12
12
|
constructor(src: Channel<T>, fn: TopicFn<T>);
|
|
13
13
|
writable(): boolean;
|
|
@@ -21,8 +21,8 @@ export declare class PubSub<T> implements IWriteable<T>, IClosable {
|
|
|
21
21
|
*
|
|
22
22
|
* @param id - topic id
|
|
23
23
|
*/
|
|
24
|
-
subscribeTopic(id: string): Channel<
|
|
25
|
-
unsubscribeTopic(id: string, ch: Channel<
|
|
24
|
+
subscribeTopic<S extends T = T>(id: string): Channel<S>;
|
|
25
|
+
unsubscribeTopic<S extends T = T>(id: string, ch: Channel<S>): boolean;
|
|
26
26
|
unsubscribeAll(id: string, close?: boolean): void;
|
|
27
27
|
protected process(): Promise<void>;
|
|
28
28
|
}
|