nerdbank-streams 2.9.112 → 2.10.37-alpha

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.
Files changed (44) hide show
  1. package/js/Channel.d.ts +9 -8
  2. package/js/Channel.js +21 -14
  3. package/js/Channel.js.map +1 -1
  4. package/js/ControlCode.d.ts +6 -6
  5. package/js/ControlCode.js +6 -6
  6. package/js/ControlCode.js.map +1 -1
  7. package/js/Deferred.js.map +1 -1
  8. package/js/FrameHeader.d.ts +2 -2
  9. package/js/FrameHeader.js +2 -2
  10. package/js/FrameHeader.js.map +1 -1
  11. package/js/FullDuplexStream.d.ts +1 -1
  12. package/js/FullDuplexStream.js +2 -0
  13. package/js/FullDuplexStream.js.map +1 -1
  14. package/js/MultiplexingStream.d.ts +19 -19
  15. package/js/MultiplexingStream.js +67 -63
  16. package/js/MultiplexingStream.js.map +1 -1
  17. package/js/MultiplexingStreamFormatters.d.ts +9 -7
  18. package/js/MultiplexingStreamFormatters.js +50 -22
  19. package/js/MultiplexingStreamFormatters.js.map +1 -1
  20. package/js/MultiplexingStreamOptions.d.ts +1 -1
  21. package/js/QualifiedChannelId.js +10 -4
  22. package/js/QualifiedChannelId.js.map +1 -1
  23. package/js/Utilities.d.ts +3 -3
  24. package/js/Utilities.js +61 -18
  25. package/js/Utilities.js.map +1 -1
  26. package/js/index.d.ts +8 -8
  27. package/js/index.js.map +1 -1
  28. package/package.json +16 -6
  29. package/src/AcceptanceParameters.ts +2 -2
  30. package/src/Channel.ts +279 -277
  31. package/src/ChannelOptions.ts +2 -2
  32. package/src/ControlCode.ts +25 -25
  33. package/src/Deferred.ts +61 -61
  34. package/src/FrameHeader.ts +35 -35
  35. package/src/FullDuplexStream.ts +25 -23
  36. package/src/IChannelOfferEventArgs.ts +12 -12
  37. package/src/IDisposableObservable.ts +2 -2
  38. package/src/MultiplexingStream.ts +731 -727
  39. package/src/MultiplexingStreamFormatters.ts +355 -326
  40. package/src/MultiplexingStreamOptions.ts +16 -16
  41. package/src/OfferParameters.ts +4 -4
  42. package/src/QualifiedChannelId.ts +27 -21
  43. package/src/Utilities.ts +159 -114
  44. package/src/index.ts +8 -8
package/src/Deferred.ts CHANGED
@@ -2,74 +2,74 @@
2
2
  * A TaskCompletionSource-like class that allows promises to be resolved or rejected whenever.
3
3
  */
4
4
  export class Deferred<T> {
5
- public readonly promise: Promise<T>;
6
- private resolvePromise!: (value: T | PromiseLike<T>) => void;
7
- private rejectPromise!: (reason?: any) => void;
8
- private _isResolved: boolean = false;
9
- private _isRejected: boolean = false;
10
- private _error: any;
5
+ public readonly promise: Promise<T>
6
+ private resolvePromise!: (value: T | PromiseLike<T>) => void
7
+ private rejectPromise!: (reason?: any) => void
8
+ private _isResolved: boolean = false
9
+ private _isRejected: boolean = false
10
+ private _error: any
11
11
 
12
- constructor(public state?: any) {
13
- this.promise = new Promise<T>((resolve, reject) => {
14
- this.resolvePromise = resolve;
15
- this.rejectPromise = reject;
16
- });
17
- }
12
+ constructor(public state?: any) {
13
+ this.promise = new Promise<T>((resolve, reject) => {
14
+ this.resolvePromise = resolve
15
+ this.rejectPromise = reject
16
+ })
17
+ }
18
18
 
19
- /**
20
- * Gets a value indicating whether this promise has been completed.
21
- */
22
- public get isCompleted() {
23
- return this._isResolved || this._isRejected;
24
- }
19
+ /**
20
+ * Gets a value indicating whether this promise has been completed.
21
+ */
22
+ public get isCompleted() {
23
+ return this._isResolved || this._isRejected
24
+ }
25
25
 
26
- /**
27
- * Gets a value indicating whether this promise is resolved.
28
- */
29
- public get isResolved() {
30
- return this._isResolved;
31
- }
26
+ /**
27
+ * Gets a value indicating whether this promise is resolved.
28
+ */
29
+ public get isResolved() {
30
+ return this._isResolved
31
+ }
32
32
 
33
- /**
34
- * Gets a value indicating whether this promise is rejected.
35
- */
36
- public get isRejected() {
37
- return this._isRejected;
38
- }
33
+ /**
34
+ * Gets a value indicating whether this promise is rejected.
35
+ */
36
+ public get isRejected() {
37
+ return this._isRejected
38
+ }
39
39
 
40
- /**
41
- * Gets the reason for promise rejection, if applicable.
42
- */
43
- public get error() {
44
- return this._error;
45
- }
40
+ /**
41
+ * Gets the reason for promise rejection, if applicable.
42
+ */
43
+ public get error() {
44
+ return this._error
45
+ }
46
46
 
47
- /**
48
- * Resolves the promise.
49
- * @param value The result of the promise.
50
- */
51
- public resolve(value: T | PromiseLike<T>): boolean {
52
- if (this.isCompleted) {
53
- return false;
54
- }
47
+ /**
48
+ * Resolves the promise.
49
+ * @param value The result of the promise.
50
+ */
51
+ public resolve(value: T | PromiseLike<T>): boolean {
52
+ if (this.isCompleted) {
53
+ return false
54
+ }
55
55
 
56
- this.resolvePromise(value);
57
- this._isResolved = true;
58
- return true;
59
- }
56
+ this.resolvePromise(value)
57
+ this._isResolved = true
58
+ return true
59
+ }
60
60
 
61
- /**
62
- * Rejects the promise.
63
- * @param reason The reason for rejecting the promise.
64
- */
65
- public reject(reason?: any): boolean {
66
- if (this.isCompleted) {
67
- return false;
68
- }
61
+ /**
62
+ * Rejects the promise.
63
+ * @param reason The reason for rejecting the promise.
64
+ */
65
+ public reject(reason?: any): boolean {
66
+ if (this.isCompleted) {
67
+ return false
68
+ }
69
69
 
70
- this.rejectPromise(reason);
71
- this._error = reason;
72
- this._isRejected = true;
73
- return true;
74
- }
70
+ this.rejectPromise(reason)
71
+ this._error = reason
72
+ this._isRejected = true
73
+ return true
74
+ }
75
75
  }
@@ -1,44 +1,44 @@
1
- import { ControlCode } from "./ControlCode";
2
- import { requireInteger } from "./Utilities";
3
- import { QualifiedChannelId } from "./QualifiedChannelId";
1
+ import { ControlCode } from './ControlCode'
2
+ import { requireInteger } from './Utilities'
3
+ import { QualifiedChannelId } from './QualifiedChannelId'
4
4
 
5
5
  export class FrameHeader {
6
- private _channel?: QualifiedChannelId;
6
+ private _channel?: QualifiedChannelId
7
7
 
8
- /**
9
- * Initializes a new instance of the `FrameHeader` class.
10
- * @param code The kind of frame this is.
11
- * @param channel The channel that this frame refers to or carries a payload for.
12
- */
13
- constructor(public readonly code: ControlCode, channel?: QualifiedChannelId) {
14
- if (channel) {
15
- requireInteger("channelId", channel.id, 4, "signed");
16
- }
8
+ /**
9
+ * Initializes a new instance of the `FrameHeader` class.
10
+ * @param code The kind of frame this is.
11
+ * @param channel The channel that this frame refers to or carries a payload for.
12
+ */
13
+ constructor(public readonly code: ControlCode, channel?: QualifiedChannelId) {
14
+ if (channel) {
15
+ requireInteger('channelId', channel.id, 4, 'signed')
16
+ }
17
17
 
18
- this.code = code;
19
- this._channel = channel;
20
- }
18
+ this.code = code
19
+ this._channel = channel
20
+ }
21
21
 
22
- /** The channel that this frame refers to or carries a payload for. */
23
- get channel(): QualifiedChannelId | undefined {
24
- return this._channel;
25
- }
22
+ /** The channel that this frame refers to or carries a payload for. */
23
+ get channel(): QualifiedChannelId | undefined {
24
+ return this._channel
25
+ }
26
26
 
27
- /**
28
- * Gets the channel that this frame refers to or carries a payload for.
29
- */
30
- public get requiredChannel(): QualifiedChannelId {
31
- if (this.channel) {
32
- return this.channel;
33
- }
27
+ /**
28
+ * Gets the channel that this frame refers to or carries a payload for.
29
+ */
30
+ public get requiredChannel(): QualifiedChannelId {
31
+ if (this.channel) {
32
+ return this.channel
33
+ }
34
34
 
35
- throw new Error("Expected channel not present in frame header.");
36
- }
35
+ throw new Error('Expected channel not present in frame header.')
36
+ }
37
37
 
38
- /** Changes the channel.source property to reflect the opposite perspective (i.e. remote and local values switch). */
39
- public flipChannelPerspective() {
40
- if (this._channel) {
41
- this._channel = { id: this._channel.id, source: this._channel.source * -1 };
42
- }
43
- }
38
+ /** Changes the channel.source property to reflect the opposite perspective (i.e. remote and local values switch). */
39
+ public flipChannelPerspective() {
40
+ if (this._channel) {
41
+ this._channel = { id: this._channel.id, source: this._channel.source * -1 }
42
+ }
43
+ }
44
44
  }
@@ -1,30 +1,32 @@
1
- import { Duplex, PassThrough } from "stream";
1
+ import { Duplex, PassThrough } from 'stream'
2
2
 
3
3
  export class FullDuplexStream {
4
- public static CreatePair(): { first: Duplex, second: Duplex } {
5
- const pass1 = new PassThrough();
6
- const pass2 = new PassThrough();
7
- return {
8
- first: FullDuplexStream.Splice(pass1, pass2),
9
- second: FullDuplexStream.Splice(pass2, pass1),
10
- };
11
- }
4
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5
+ public static CreatePair(): { first: Duplex; second: Duplex } {
6
+ const pass1 = new PassThrough()
7
+ const pass2 = new PassThrough()
8
+ return {
9
+ first: FullDuplexStream.Splice(pass1, pass2),
10
+ second: FullDuplexStream.Splice(pass2, pass1),
11
+ }
12
+ }
12
13
 
13
- public static Splice(readable: NodeJS.ReadableStream, writable: NodeJS.WritableStream): Duplex {
14
- const duplex = new Duplex({
15
- write(chunk, encoding, callback) {
16
- writable.write(chunk, encoding, callback);
17
- },
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention
15
+ public static Splice(readable: NodeJS.ReadableStream, writable: NodeJS.WritableStream): Duplex {
16
+ const duplex = new Duplex({
17
+ write(chunk, encoding, callback) {
18
+ writable.write(chunk, encoding, callback)
19
+ },
18
20
 
19
- final(callback) {
20
- writable.end(callback);
21
- },
22
- });
21
+ final(callback) {
22
+ writable.end(callback)
23
+ },
24
+ })
23
25
 
24
- // All reads and events come directly from the readable stream.
25
- duplex.read = readable.read.bind(readable);
26
- duplex.on = readable.on.bind(readable) as any;
26
+ // All reads and events come directly from the readable stream.
27
+ duplex.read = readable.read.bind(readable)
28
+ duplex.on = readable.on.bind(readable) as any
27
29
 
28
- return duplex;
29
- }
30
+ return duplex
31
+ }
30
32
  }
@@ -2,18 +2,18 @@
2
2
  * Describes an offer for a channel.
3
3
  */
4
4
  export interface IChannelOfferEventArgs {
5
- /**
6
- * Gets the unique ID of the channel.
7
- */
8
- readonly id: number;
5
+ /**
6
+ * Gets the unique ID of the channel.
7
+ */
8
+ readonly id: number
9
9
 
10
- /**
11
- * Gets the name of the channel.
12
- */
13
- readonly name: string;
10
+ /**
11
+ * Gets the name of the channel.
12
+ */
13
+ readonly name: string
14
14
 
15
- /**
16
- * Gets a value indicating whether the channel has already been accepted.
17
- */
18
- readonly isAccepted: boolean;
15
+ /**
16
+ * Gets a value indicating whether the channel has already been accepted.
17
+ */
18
+ readonly isAccepted: boolean
19
19
  }
@@ -1,4 +1,4 @@
1
1
  export interface IDisposableObservable {
2
- readonly isDisposed: boolean;
3
- dispose();
2
+ readonly isDisposed: boolean
3
+ dispose()
4
4
  }