@thi.ng/csp 3.2.1 → 3.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:31Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
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,15 @@ 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.2.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/csp@3.2.2) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
17
+ - dedupe pipe() logic, deprecate into() ([5979527](https://github.com/thi-ng/umbrella/commit/5979527))
18
+ - update fromAsyncIterable()
19
+ - add docstrings
20
+
12
21
  ## [3.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/csp@3.2.0) (2024-04-28)
13
22
 
14
23
  #### 🚀 Features
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 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
  >
@@ -35,13 +35,14 @@
35
35
 
36
36
  Primitives & operators for Communicating Sequential Processes based on async/await and async iterables.
37
37
 
38
- This package was temporarily deprecated (throughout most of 2023), but meanwhile
39
- has been **reanimated in the form of a complete rewrite**, using a new, more
40
- simple and more modern approach afforded by contemporary ES language features
41
- (and widespread support for them).
42
-
43
- **This new/current implementation is in most cases NOT compatible with earlier
44
- versions**.
38
+ > [!IMPORTANT]
39
+ > This package was temporarily deprecated (throughout most of 2023), but
40
+ > meanwhile has been **reanimated in the form of a complete rewrite**, using a
41
+ > new, more simple and more modern approach afforded by contemporary ES language
42
+ > features (and widespread support for them).
43
+ >
44
+ > **This new/current implementation is in most cases NOT compatible with earlier
45
+ > versions**.
45
46
 
46
47
  ### What is CSP?
47
48
 
@@ -157,7 +158,7 @@ For Node.js REPL:
157
158
  const csp = await import("@thi.ng/csp");
158
159
  ```
159
160
 
160
- Package sizes (brotli'd, pre-treeshake): ESM: 1.81 KB
161
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.80 KB
161
162
 
162
163
  ## Dependencies
163
164
 
package/ops.d.ts CHANGED
@@ -33,26 +33,40 @@ export declare const consumeWith: <T>(chan: Channel<T>, fn: Fn2<T, Channel<T>, v
33
33
  export declare const drain: <T>(chan: Channel<T>) => Promise<Awaited<T>[]>;
34
34
  /**
35
35
  * Takes an async iterable and returns a new CSP {@link Channel}, which receives
36
- * all values from `src`. If `close` is true (default), the channel will be
37
- * automatically closed once the iterable is exhausted.
36
+ * all values from `src` (via {@link pipe}). If `close` is true (default), the
37
+ * channel will be automatically closed once the iterable is exhausted. Returns
38
+ * the new channel.
38
39
  *
39
40
  * @param src
40
41
  * @param close
41
42
  */
42
43
  export declare const fromAsyncIterable: <T>(src: AsyncIterable<T>, close?: boolean) => Channel<T>;
43
44
  export declare const merge: <T>(src: Channel<T>[], dest?: Channel<T>, close?: boolean) => Channel<T>;
45
+ /**
46
+ * @deprecated use {@link pipe} instead.
47
+ */
44
48
  export declare const into: <T, DEST extends IWriteable<T> & IClosable>(chan: DEST, src: Iterable<T> | AsyncIterable<T>, close?: boolean) => Promise<void>;
45
- export declare const pipe: <T, DEST extends IWriteable<T> & IClosable>(src: Channel<T>, dest: DEST, close?: boolean) => DEST;
49
+ /**
50
+ * Receives values from `src` and writes them to `dest` for as long as it's
51
+ * accepting new writes (i.e. isn't closed from elsewhere). If `close` is true
52
+ * (default), the `dest` channel will be automatically closed once the `src` is
53
+ * exhausted. Returns `dest` channel.
54
+ *
55
+ * @param src
56
+ * @param dest
57
+ * @param close
58
+ */
59
+ export declare const pipe: <T, DEST extends IWriteable<T> & IClosable>(src: AsyncIterable<T>, dest: DEST, close?: boolean) => DEST;
46
60
  /**
47
61
  * Takes one or more input channels and attempts to read from all of them at
48
62
  * once (via {@link Channel.race}, a blocking op). Returns a promise which
49
63
  * resolves once one of the inputs becomes available or was closed, selects that
50
64
  * channel to read from it and returns tuple of `[value, channel]`.
51
65
  *
52
- * @param input
53
- * @param xs
66
+ * @param input - first input
67
+ * @param rest - other inputs
54
68
  */
55
- export declare const select: <T>(input: Channel<T>, ...xs: Channel<T>[]) => Promise<[Maybe<T>, Channel<T>]>;
69
+ export declare const select: <T>(input: Channel<T>, ...rest: Channel<T>[]) => Promise<[Maybe<T>, Channel<T>]>;
56
70
  /**
57
71
  * Returns a new {@link Channel} which will automatically close after `delay`
58
72
  * milliseconds.
package/ops.js CHANGED
@@ -38,17 +38,7 @@ const drain = async (chan) => await (async () => {
38
38
  }
39
39
  return Promise.all(ops);
40
40
  })();
41
- const fromAsyncIterable = (src, close = true) => {
42
- const chan = new Channel();
43
- (async () => {
44
- for await (let x of src) {
45
- await chan.write(x);
46
- if (!chan.writable()) break;
47
- }
48
- close && chan.close();
49
- })();
50
- return chan;
51
- };
41
+ const fromAsyncIterable = (src, close = true) => pipe(src, new Channel(), close);
52
42
  const merge = (src, dest, close = true) => {
53
43
  assert(src.length > 0, "no inputs given");
54
44
  dest = dest || new Channel();
@@ -85,8 +75,8 @@ const pipe = (src, dest, close = true) => {
85
75
  })();
86
76
  return dest;
87
77
  };
88
- const select = async (input, ...xs) => {
89
- const inputs = [input, ...xs];
78
+ const select = async (input, ...rest) => {
79
+ const inputs = [input, ...rest];
90
80
  const sel = await Promise.race(inputs.map((x) => x.race()));
91
81
  for (let chan of inputs) {
92
82
  if (chan !== sel) chan.races.shift();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/csp",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
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",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/csp#readme",
13
+ "homepage": "https://thi.ng/csp",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -40,16 +40,16 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/api": "^8.11.2",
44
- "@thi.ng/buffers": "^0.1.3",
45
- "@thi.ng/checks": "^3.6.4",
46
- "@thi.ng/errors": "^2.5.7"
43
+ "@thi.ng/api": "^8.11.4",
44
+ "@thi.ng/buffers": "^0.1.5",
45
+ "@thi.ng/checks": "^3.6.6",
46
+ "@thi.ng/errors": "^2.5.9"
47
47
  },
48
48
  "devDependencies": {
49
- "@microsoft/api-extractor": "^7.43.2",
50
- "esbuild": "^0.21.1",
49
+ "@microsoft/api-extractor": "^7.47.0",
50
+ "esbuild": "^0.21.5",
51
51
  "typedoc": "^0.25.13",
52
- "typescript": "^5.4.5"
52
+ "typescript": "^5.5.2"
53
53
  },
54
54
  "keywords": [
55
55
  "async",
@@ -106,5 +106,5 @@
106
106
  "status": "beta",
107
107
  "year": 2016
108
108
  },
109
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
109
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
110
110
  }