@thi.ng/csp 2.0.1 → 2.0.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
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.0.3](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@2.0.2...@thi.ng/csp@2.0.3) (2021-10-15)
7
+
8
+ **Note:** Version bump only for package @thi.ng/csp
9
+
10
+
11
+
12
+
13
+
14
+ ## [2.0.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@2.0.1...@thi.ng/csp@2.0.2) (2021-10-15)
15
+
16
+ **Note:** Version bump only for package @thi.ng/csp
17
+
18
+
19
+
20
+
21
+
6
22
  ## [2.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/csp@2.0.0...@thi.ng/csp@2.0.1) (2021-10-13)
7
23
 
8
24
  **Note:** Version bump only for package @thi.ng/csp
package/README.md CHANGED
@@ -78,7 +78,7 @@ node --experimental-repl-await
78
78
  > const csp = await import("@thi.ng/csp");
79
79
  ```
80
80
 
81
- Package sizes (gzipped, pre-treeshake): ESM: 2.69 KB
81
+ Package sizes (gzipped, pre-treeshake): ESM: 2.64 KB
82
82
 
83
83
  ## Dependencies
84
84
 
package/buffer.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { DCons } from "@thi.ng/dcons/dcons";
2
2
  export class FixedBuffer {
3
- buf;
4
- limit;
5
3
  constructor(limit = 1) {
6
4
  this.buf = new DCons();
7
5
  this.limit = limit;
package/channel.js CHANGED
@@ -8,6 +8,62 @@ import { range } from "@thi.ng/transducers/range";
8
8
  import { isReduced, unreduced } from "@thi.ng/transducers/reduced";
9
9
  import { FixedBuffer } from "./buffer.js";
10
10
  export class Channel {
11
+ constructor(...args) {
12
+ let id, buf, tx, err;
13
+ let [a, b] = args;
14
+ switch (args.length) {
15
+ case 0:
16
+ break;
17
+ case 1:
18
+ if (typeof a === "string") {
19
+ id = a;
20
+ }
21
+ else if (maybeBuffer(a)) {
22
+ buf = a;
23
+ }
24
+ else {
25
+ tx = a;
26
+ }
27
+ break;
28
+ case 2:
29
+ if (typeof a === "string") {
30
+ id = a;
31
+ if (maybeBuffer(b)) {
32
+ buf = b;
33
+ }
34
+ else {
35
+ tx = b;
36
+ }
37
+ }
38
+ else {
39
+ [tx, err] = args;
40
+ }
41
+ break;
42
+ case 3:
43
+ if (isFunction(args[1]) && isFunction(args[2])) {
44
+ [id, tx, err] = args;
45
+ }
46
+ else {
47
+ [id, buf, tx] = args;
48
+ }
49
+ break;
50
+ case 4:
51
+ [id, buf, tx, err] = args;
52
+ break;
53
+ default:
54
+ illegalArity(args.length);
55
+ }
56
+ this.id = id || `chan-${Channel.NEXT_ID++}`;
57
+ buf = buf || 1;
58
+ this.buf = typeof buf === "number" ? new FixedBuffer(buf) : buf;
59
+ this.writes = new DCons();
60
+ this.reads = new DCons();
61
+ this.txbuf = new DCons();
62
+ this.tx = tx ? tx(Channel.RFN) : null;
63
+ this.onerror = tx && (err || defaultErrorHandler);
64
+ this.state = 0 /* OPEN */;
65
+ this.isBusy = false;
66
+ }
11
67
  static constantly(x, delay) {
12
68
  const chan = new Channel(delay ? delayed(delay) : null);
13
69
  chan.produce(() => x);
@@ -207,79 +263,6 @@ export class Channel {
207
263
  })();
208
264
  return out;
209
265
  }
210
- static MAX_WRITES = 1024;
211
- static NEXT_ID = 0;
212
- static SCHEDULE = typeof setImmediate === "function" ? setImmediate : setTimeout;
213
- static RFN = [
214
- (() => null),
215
- (acc) => acc,
216
- (acc, x) => acc.push(x),
217
- ];
218
- id;
219
- onerror;
220
- state;
221
- buf;
222
- tx;
223
- writes;
224
- reads;
225
- txbuf;
226
- isBusy;
227
- constructor(...args) {
228
- let id, buf, tx, err;
229
- let [a, b] = args;
230
- switch (args.length) {
231
- case 0:
232
- break;
233
- case 1:
234
- if (typeof a === "string") {
235
- id = a;
236
- }
237
- else if (maybeBuffer(a)) {
238
- buf = a;
239
- }
240
- else {
241
- tx = a;
242
- }
243
- break;
244
- case 2:
245
- if (typeof a === "string") {
246
- id = a;
247
- if (maybeBuffer(b)) {
248
- buf = b;
249
- }
250
- else {
251
- tx = b;
252
- }
253
- }
254
- else {
255
- [tx, err] = args;
256
- }
257
- break;
258
- case 3:
259
- if (isFunction(args[1]) && isFunction(args[2])) {
260
- [id, tx, err] = args;
261
- }
262
- else {
263
- [id, buf, tx] = args;
264
- }
265
- break;
266
- case 4:
267
- [id, buf, tx, err] = args;
268
- break;
269
- default:
270
- illegalArity(args.length);
271
- }
272
- this.id = id || `chan-${Channel.NEXT_ID++}`;
273
- buf = buf || 1;
274
- this.buf = typeof buf === "number" ? new FixedBuffer(buf) : buf;
275
- this.writes = new DCons();
276
- this.reads = new DCons();
277
- this.txbuf = new DCons();
278
- this.tx = tx ? tx(Channel.RFN) : null;
279
- this.onerror = tx && (err || defaultErrorHandler);
280
- this.state = 0 /* OPEN */;
281
- this.isBusy = false;
282
- }
283
266
  channel() {
284
267
  return this;
285
268
  }
@@ -507,5 +490,13 @@ export class Channel {
507
490
  this.buf.release();
508
491
  }
509
492
  }
493
+ Channel.MAX_WRITES = 1024;
494
+ Channel.NEXT_ID = 0;
495
+ Channel.SCHEDULE = typeof setImmediate === "function" ? setImmediate : setTimeout;
496
+ Channel.RFN = [
497
+ (() => null),
498
+ (acc) => acc,
499
+ (acc, x) => acc.push(x),
500
+ ];
510
501
  const defaultErrorHandler = (e, chan, val) => console.log(chan.id, "error occurred", e.message, val !== undefined ? val : "");
511
502
  const maybeBuffer = (x) => x instanceof FixedBuffer || typeof x === "number";
package/mult.js CHANGED
@@ -2,11 +2,8 @@ import { DCons } from "@thi.ng/dcons/dcons";
2
2
  import { illegalArity } from "@thi.ng/errors/illegal-arity";
3
3
  import { Channel } from "./channel.js";
4
4
  export class Mult {
5
- static nextID = 0;
6
- src;
7
- taps;
8
- tapID = 0;
9
5
  constructor(...args) {
6
+ this.tapID = 0;
10
7
  let id, src;
11
8
  switch (args.length) {
12
9
  case 2:
@@ -107,3 +104,4 @@ export class Mult {
107
104
  delete this.tapID;
108
105
  }
109
106
  }
107
+ Mult.nextID = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/csp",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "ES6 promise based CSP primitives & operations",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -38,15 +38,15 @@
38
38
  "testnode": "tsc -p test && node build/test/node.js"
39
39
  },
40
40
  "dependencies": {
41
- "@thi.ng/api": "^8.0.1",
42
- "@thi.ng/arrays": "^2.0.1",
43
- "@thi.ng/checks": "^3.0.1",
44
- "@thi.ng/dcons": "^3.0.1",
45
- "@thi.ng/errors": "^2.0.1",
46
- "@thi.ng/transducers": "^8.0.1"
41
+ "@thi.ng/api": "^8.0.3",
42
+ "@thi.ng/arrays": "^2.0.3",
43
+ "@thi.ng/checks": "^3.0.3",
44
+ "@thi.ng/dcons": "^3.0.3",
45
+ "@thi.ng/errors": "^2.0.3",
46
+ "@thi.ng/transducers": "^8.0.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@thi.ng/testament": "^0.1.1"
49
+ "@thi.ng/testament": "^0.1.3"
50
50
  },
51
51
  "keywords": [
52
52
  "async",
@@ -97,5 +97,5 @@
97
97
  "status": "deprecated",
98
98
  "year": 2016
99
99
  },
100
- "gitHead": "2e6b3d7c0f4c5686c1e9bdb4902ed7d3f90bcc19"
100
+ "gitHead": "1fb38cac74d6c009d96855c28784a267a81badf1"
101
101
  }
package/pubsub.js CHANGED
@@ -2,10 +2,6 @@ import { illegalArity } from "@thi.ng/errors/illegal-arity";
2
2
  import { Channel } from "./channel.js";
3
3
  import { Mult } from "./mult.js";
4
4
  export class PubSub {
5
- static NEXT_ID = 0;
6
- src;
7
- fn;
8
- topics;
9
5
  constructor(...args) {
10
6
  switch (args.length) {
11
7
  case 2:
@@ -90,3 +86,4 @@ export class PubSub {
90
86
  delete this.fn;
91
87
  }
92
88
  }
89
+ PubSub.NEXT_ID = 0;