@everyonesoftware/common 11.0.0 → 13.0.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.
@@ -45,6 +45,7 @@ __export(sources_exports, {
45
45
  CharacterReadStreamAsyncIterator: () => CharacterReadStreamAsyncIterator,
46
46
  CharacterTable: () => CharacterTable,
47
47
  CharacterWriteStream: () => CharacterWriteStream,
48
+ Clock: () => Clock,
48
49
  CommandLineParameter: () => CommandLineParameter,
49
50
  CommandLineParameters: () => CommandLineParameters,
50
51
  Comparable: () => Comparable,
@@ -58,6 +59,7 @@ __export(sources_exports, {
58
59
  Disposable: () => Disposable,
59
60
  EmptyError: () => EmptyError,
60
61
  EqualFunctions: () => EqualFunctions,
62
+ FetchError: () => FetchError,
61
63
  FetchHttpClient: () => FetchHttpClient,
62
64
  FetchHttpIncomingResponse: () => FetchHttpIncomingResponse,
63
65
  FlatMapIterable: () => FlatMapIterable,
@@ -101,6 +103,7 @@ __export(sources_exports, {
101
103
  Node: () => Node,
102
104
  NodeJSCharacterWriteStream: () => NodeJSCharacterWriteStream,
103
105
  NodeJSHttpIncomingRequest: () => NodeJSHttpIncomingRequest,
106
+ NodeJSHttpOutgoingResponse: () => NodeJSHttpOutgoingResponse,
104
107
  NodeJSHttpServer: () => NodeJSHttpServer,
105
108
  NotFoundError: () => NotFoundError,
106
109
  PostCondition: () => PostCondition,
@@ -110,6 +113,7 @@ __export(sources_exports, {
110
113
  PromiseAsyncResult: () => PromiseAsyncResult,
111
114
  Property: () => Property,
112
115
  Queue: () => Queue,
116
+ RealClock: () => RealClock,
113
117
  RealNetwork: () => RealNetwork,
114
118
  RecreationDotGovClient: () => RecreationDotGovClient,
115
119
  RecreationDotGovDivisionAvailability: () => RecreationDotGovDivisionAvailability,
@@ -4477,6 +4481,187 @@ var CharacterTable = class _CharacterTable {
4477
4481
  }
4478
4482
  };
4479
4483
 
4484
+ // sources/luxonDateTime.ts
4485
+ var luxon = __toESM(require("luxon"), 1);
4486
+ var pctTimeZone = "America/Los_Angeles";
4487
+ var LuxonDateTime = class _LuxonDateTime {
4488
+ dateTime;
4489
+ constructor(dateTime) {
4490
+ this.dateTime = dateTime;
4491
+ }
4492
+ static create(dateTime) {
4493
+ return new _LuxonDateTime(dateTime);
4494
+ }
4495
+ static parse(text) {
4496
+ return _LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
4497
+ }
4498
+ static now() {
4499
+ return _LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
4500
+ }
4501
+ getYear() {
4502
+ return this.dateTime.year;
4503
+ }
4504
+ getMonth() {
4505
+ return this.dateTime.month;
4506
+ }
4507
+ getDay() {
4508
+ return this.dateTime.day;
4509
+ }
4510
+ getHour() {
4511
+ return this.dateTime.hour;
4512
+ }
4513
+ getMinute() {
4514
+ return this.dateTime.minute;
4515
+ }
4516
+ getSecond() {
4517
+ return this.dateTime.second;
4518
+ }
4519
+ addDays(days) {
4520
+ return _LuxonDateTime.create(this.dateTime.plus({ days }));
4521
+ }
4522
+ toString() {
4523
+ return this.dateTime.toISO();
4524
+ }
4525
+ toDateString() {
4526
+ return this.dateTime.toISODate();
4527
+ }
4528
+ toShortDateString() {
4529
+ return `${this.dateTime.monthShort} ${this.dateTime.day}`;
4530
+ }
4531
+ compareTo(dateTime, compareTimes) {
4532
+ return DateTime2.compareTo(this, dateTime, compareTimes);
4533
+ }
4534
+ lessThan(dateTime, compareTimes) {
4535
+ return DateTime2.lessThan(this, dateTime, compareTimes);
4536
+ }
4537
+ lessThanOrEqualTo(dateTime, compareTimes) {
4538
+ return DateTime2.lessThanOrEqualTo(this, dateTime, compareTimes);
4539
+ }
4540
+ equals(dateTime, compareTimes) {
4541
+ return DateTime2.equals(this, dateTime, compareTimes);
4542
+ }
4543
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4544
+ return DateTime2.greaterThanOrEqualTo(this, dateTime, compareTimes);
4545
+ }
4546
+ greaterThan(dateTime, compareTimes) {
4547
+ return DateTime2.greaterThan(this, dateTime, compareTimes);
4548
+ }
4549
+ get debug() {
4550
+ return DateTime2.debug(this);
4551
+ }
4552
+ };
4553
+
4554
+ // sources/dateTime.ts
4555
+ var DateTime2 = class _DateTime {
4556
+ static parse(text) {
4557
+ return LuxonDateTime.parse(text);
4558
+ }
4559
+ static now() {
4560
+ return LuxonDateTime.now();
4561
+ }
4562
+ /**
4563
+ * Compare this {@link DateTime} to the provided {@link DateTime}. If this {@link DateTime} is
4564
+ * less than the provided {@link DateTime}, then a negative number will be returned, 0 if
4565
+ * they're equal, or a positive number if this {@link DateTime} is greater than the provided
4566
+ * {@link DateTime}.
4567
+ * @param dateTime The {@link DateTime} to compare to this {@link DateTime}.
4568
+ */
4569
+ compareTo(dateTime, compareTimes) {
4570
+ return _DateTime.compareTo(this, dateTime, compareTimes);
4571
+ }
4572
+ static compareTo(left, right, compareTimes) {
4573
+ let result = left.getYear() - right.getYear();
4574
+ if (result === 0) {
4575
+ result = left.getMonth() - right.getMonth();
4576
+ if (result === 0) {
4577
+ result = left.getDay() - right.getDay();
4578
+ if (compareTimes && result === 0) {
4579
+ result = left.getHour() - right.getHour();
4580
+ if (result === 0) {
4581
+ result = left.getMinute() - right.getMinute();
4582
+ if (result === 0) {
4583
+ result = left.getSecond();
4584
+ -right.getSecond();
4585
+ }
4586
+ }
4587
+ }
4588
+ }
4589
+ }
4590
+ return result;
4591
+ }
4592
+ lessThan(dateTime, compareTimes) {
4593
+ return _DateTime.lessThan(this, dateTime, compareTimes);
4594
+ }
4595
+ static lessThan(left, right, compareTimes) {
4596
+ return left.compareTo(right, compareTimes) < 0;
4597
+ }
4598
+ lessThanOrEqualTo(dateTime, compareTimes) {
4599
+ return _DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
4600
+ }
4601
+ static lessThanOrEqualTo(left, right, compareTimes) {
4602
+ return left.compareTo(right, compareTimes) <= 0;
4603
+ }
4604
+ equals(dateTime, compareTimes) {
4605
+ return _DateTime.equals(this, dateTime, compareTimes);
4606
+ }
4607
+ static equals(left, right, compareTimes) {
4608
+ return left.compareTo(right, compareTimes) === 0;
4609
+ }
4610
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4611
+ return _DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
4612
+ }
4613
+ static greaterThanOrEqualTo(left, right, compareTimes) {
4614
+ return left.compareTo(right, compareTimes) >= 0;
4615
+ }
4616
+ greaterThan(dateTime, compareTimes) {
4617
+ return _DateTime.greaterThan(this, dateTime, compareTimes);
4618
+ }
4619
+ static greaterThan(left, right, compareTimes) {
4620
+ return left.compareTo(right, compareTimes) > 0;
4621
+ }
4622
+ get debug() {
4623
+ return _DateTime.debug(this);
4624
+ }
4625
+ static debug(dateTime) {
4626
+ return dateTime.toString();
4627
+ }
4628
+ };
4629
+
4630
+ // sources/RealClock.ts
4631
+ var RealClock = class _RealClock {
4632
+ constructor() {
4633
+ }
4634
+ static create() {
4635
+ return new _RealClock();
4636
+ }
4637
+ now() {
4638
+ return DateTime2.now();
4639
+ }
4640
+ };
4641
+
4642
+ // sources/Clock.ts
4643
+ var Clock = class {
4644
+ static create() {
4645
+ return RealClock.create();
4646
+ }
4647
+ };
4648
+
4649
+ // sources/FetchError.ts
4650
+ var FetchError = class extends Error {
4651
+ innerError;
4652
+ constructor(innerError) {
4653
+ PreCondition.assertNotUndefinedAndNotNull(innerError, "innerError");
4654
+ super(innerError.message, { cause: innerError });
4655
+ this.innerError = innerError;
4656
+ }
4657
+ get code() {
4658
+ return "code" in this.innerError ? this.innerError.code : void 0;
4659
+ }
4660
+ get hostname() {
4661
+ return "hostname" in this.innerError ? this.innerError.hostname : void 0;
4662
+ }
4663
+ };
4664
+
4480
4665
  // sources/asyncResult.ts
4481
4666
  var AsyncResult = class {
4482
4667
  static create(actionOrPromise) {
@@ -4858,663 +5043,641 @@ var IndentedCharacterWriteStream = class _IndentedCharacterWriteStream extends C
4858
5043
  }
4859
5044
  };
4860
5045
 
4861
- // sources/TokenType.ts
4862
- var TokenType = class _TokenType {
5046
+ // sources/httpHeader.ts
5047
+ var HttpHeader = class _HttpHeader {
4863
5048
  name;
4864
- constructor(name) {
5049
+ value;
5050
+ constructor(name, value) {
4865
5051
  PreCondition.assertNotEmpty(name, "name");
5052
+ PreCondition.assertNotUndefinedAndNotNull(value, "value");
4866
5053
  this.name = name;
5054
+ this.value = value;
4867
5055
  }
4868
- static create(name) {
4869
- return new _TokenType(name);
5056
+ static create(name, value) {
5057
+ return new _HttpHeader(name, value);
4870
5058
  }
4871
- static Whitespace = _TokenType.create("Whitespace");
4872
- static NewLine = _TokenType.create("NewLine");
4873
- static Letters = _TokenType.create("Letters");
4874
- static Digits = _TokenType.create("Digits");
4875
- static LeftParenthesis = _TokenType.create("LeftParenthesis");
4876
- static RightParenthesis = _TokenType.create("RightParenthesis");
4877
- static Backslash = _TokenType.create("Backslash");
4878
- static ForwardSlash = _TokenType.create("ForwardSlash");
4879
- static Unknown = _TokenType.create("Unknown");
4880
- static Period = _TokenType.create("Period");
4881
- static Underscore = _TokenType.create("Underscore");
4882
- static Colon = _TokenType.create("Colon");
4883
- toString() {
5059
+ getName() {
4884
5060
  return this.name;
4885
5061
  }
4886
- };
4887
-
4888
- // sources/Token.ts
4889
- var Token = class _Token {
4890
- static newLineToken = _Token.create("\n", TokenType.NewLine);
4891
- static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
4892
- static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
4893
- static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
4894
- static backslashToken = _Token.create("\\", TokenType.Backslash);
4895
- static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
4896
- static periodToken = _Token.create(".", TokenType.Period);
4897
- static underscoreToken = _Token.create("_", TokenType.Underscore);
4898
- static colonToken = _Token.create(":", TokenType.Colon);
4899
- text;
4900
- type;
4901
- constructor(text, type) {
4902
- PreCondition.assertNotEmpty(text, "text");
4903
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
4904
- this.text = text;
4905
- this.type = type;
4906
- }
4907
- static create(text, type) {
4908
- return new _Token(text, type);
5062
+ getValue() {
5063
+ return this.value;
4909
5064
  }
4910
- static whitespace(text) {
4911
- return _Token.create(text, TokenType.Whitespace);
5065
+ toString() {
5066
+ return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
4912
5067
  }
4913
- static newLine(text) {
4914
- text ??= "\n";
4915
- let result;
4916
- switch (text) {
4917
- case "\n":
4918
- result = _Token.newLineToken;
4919
- break;
4920
- case "\r\n":
4921
- result = _Token.carriageReturnNewLineToken;
4922
- break;
4923
- default:
4924
- result = _Token.create(text, TokenType.NewLine);
4925
- break;
5068
+ };
5069
+
5070
+ // sources/mutableHttpHeaders.ts
5071
+ var MutableHttpHeaders = class _MutableHttpHeaders {
5072
+ headers;
5073
+ constructor(headers) {
5074
+ this.headers = List.create();
5075
+ if (headers) {
5076
+ this.setAll(headers);
4926
5077
  }
4927
- return result;
4928
- }
4929
- static leftParenthesis() {
4930
- return _Token.leftParenthesisToken;
4931
- }
4932
- static rightParenthesis() {
4933
- return _Token.rightParenthesisToken;
4934
- }
4935
- static backslash() {
4936
- return _Token.backslashToken;
4937
5078
  }
4938
- static forwardSlash() {
4939
- return _Token.forwardSlashToken;
5079
+ static create(headers) {
5080
+ return new _MutableHttpHeaders(headers);
4940
5081
  }
4941
- static period() {
4942
- return _Token.periodToken;
5082
+ iterate() {
5083
+ return this.headers.iterate();
4943
5084
  }
4944
- static underscore() {
4945
- return _Token.underscoreToken;
4946
- }
4947
- static colon() {
4948
- return _Token.colonToken;
4949
- }
4950
- static letters(text) {
4951
- return _Token.create(text, TokenType.Letters);
4952
- }
4953
- static digits(text) {
4954
- return _Token.create(text, TokenType.Digits);
4955
- }
4956
- static unknown(text) {
4957
- return _Token.create(text, TokenType.Unknown);
4958
- }
4959
- getText() {
4960
- return this.text;
4961
- }
4962
- getType() {
4963
- return this.type;
4964
- }
4965
- };
4966
-
4967
- // sources/Tokenizer.ts
4968
- var Tokenizer = class _Tokenizer {
4969
- characters;
4970
- currentToken;
4971
- started;
4972
- constructor(characters) {
4973
- this.characters = characters;
4974
- this.started = false;
4975
- }
4976
- static create(characters) {
4977
- PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
4978
- return new _Tokenizer(isIterator(characters) ? characters : Iterator.create(characters));
4979
- }
4980
- hasStarted() {
4981
- return this.started;
4982
- }
4983
- hasCurrent() {
4984
- return this.currentToken !== void 0;
4985
- }
4986
- getCurrent() {
4987
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
4988
- return this.currentToken;
4989
- }
4990
- next() {
5085
+ get(headerName) {
5086
+ PreCondition.assertNotEmpty(headerName, "headerName");
4991
5087
  return SyncResult.create(() => {
4992
- if (!this.hasStarted()) {
4993
- this.characters.start().await();
4994
- this.started = true;
4995
- }
4996
- if (!this.characters.hasCurrent()) {
4997
- this.currentToken = void 0;
4998
- } else {
4999
- switch (this.characters.getCurrent()) {
5000
- case " ":
5001
- case " ":
5002
- this.currentToken = Token.whitespace(this.readWhile((c) => c === " " || c === " "));
5003
- break;
5004
- case "\n":
5005
- this.characters.next().await();
5006
- this.currentToken = Token.newLine();
5007
- break;
5008
- case "\r":
5009
- if (this.characters.next().await() && this.characters.getCurrent() === "\n") {
5010
- this.characters.next().await();
5011
- this.currentToken = Token.newLine("\r\n");
5012
- } else {
5013
- this.currentToken = Token.whitespace("\r");
5014
- }
5015
- break;
5016
- case "(":
5017
- this.characters.next().await();
5018
- this.currentToken = Token.leftParenthesis();
5019
- break;
5020
- case ")":
5021
- this.characters.next().await();
5022
- this.currentToken = Token.rightParenthesis();
5023
- break;
5024
- case ".":
5025
- this.characters.next().await();
5026
- this.currentToken = Token.period();
5027
- break;
5028
- case "_":
5029
- this.characters.next().await();
5030
- this.currentToken = Token.underscore();
5031
- break;
5032
- case "/":
5033
- this.characters.next().await();
5034
- this.currentToken = Token.forwardSlash();
5035
- break;
5036
- case "\\":
5037
- this.characters.next().await();
5038
- this.currentToken = Token.backslash();
5039
- break;
5040
- case ":":
5041
- this.characters.next().await();
5042
- this.currentToken = Token.colon();
5043
- break;
5044
- default:
5045
- if (isLetter(this.characters.getCurrent())) {
5046
- this.currentToken = Token.letters(this.readWhile(isLetter));
5047
- } else if (isDigit(this.characters.getCurrent())) {
5048
- this.currentToken = Token.digits(this.readWhile(isDigit));
5049
- } else {
5050
- this.currentToken = Token.unknown(this.characters.takeCurrent().await());
5051
- }
5052
- break;
5088
+ let result;
5089
+ const lowerHeaderName = headerName.toLowerCase();
5090
+ for (const header of this.headers) {
5091
+ if (header.getName().toLowerCase() === lowerHeaderName) {
5092
+ result = header;
5093
+ break;
5053
5094
  }
5054
5095
  }
5055
- return this.hasCurrent();
5096
+ if (result === void 0) {
5097
+ throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
5098
+ }
5099
+ return result;
5056
5100
  });
5057
5101
  }
5058
- readWhile(condition) {
5059
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5060
- PreCondition.assertTrue(this.characters.hasCurrent(), "this.characters.hasCurrent()");
5061
- PreCondition.assertTrue(condition(this.characters.getCurrent()), "condition(this.characters.getCurrent())");
5062
- let result = "";
5063
- do {
5064
- result += this.characters.takeCurrent().await();
5065
- } while (this.characters.hasCurrent() && condition(this.characters.getCurrent()));
5066
- return result;
5102
+ getValue(headerName) {
5103
+ return this.get(headerName).then((header) => header.getValue());
5067
5104
  }
5068
- start() {
5069
- return Iterator.start(this);
5105
+ set(headerOrHeaderName, headerValue) {
5106
+ let headerName;
5107
+ if (isString(headerOrHeaderName)) {
5108
+ headerName = headerOrHeaderName;
5109
+ } else {
5110
+ headerName = headerOrHeaderName.getName();
5111
+ headerValue = headerOrHeaderName.getValue();
5112
+ }
5113
+ PreCondition.assertNotEmpty(headerName, "headerName");
5114
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5115
+ let insertIndex = 0;
5116
+ for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
5117
+ const header = this.headers.get(insertIndex2).await();
5118
+ if (header.getName() === headerName) {
5119
+ this.headers.removeAt(insertIndex2);
5120
+ break;
5121
+ }
5122
+ }
5123
+ this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
5124
+ return this;
5070
5125
  }
5071
- takeCurrent() {
5072
- return Iterator.takeCurrent(this);
5126
+ setAll(headers) {
5127
+ PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
5128
+ for (const header of headers) {
5129
+ this.set(header);
5130
+ }
5131
+ return this;
5073
5132
  }
5074
- any() {
5075
- return Iterator.any(this);
5133
+ setContentType(contentType) {
5134
+ return this.set(HttpHeaders.contentTypeHeaderName, contentType);
5135
+ }
5136
+ getContentType() {
5137
+ return this.get(HttpHeaders.contentTypeHeaderName);
5138
+ }
5139
+ getContentTypeValue() {
5140
+ return this.getValue(HttpHeaders.contentTypeHeaderName);
5076
5141
  }
5077
5142
  getCount() {
5078
- return Iterator.getCount(this);
5143
+ return this.headers.getCount();
5079
5144
  }
5080
5145
  toArray() {
5081
- return Iterator.toArray(this);
5146
+ return HttpHeaders.toArray(this);
5082
5147
  }
5083
- concatenate(...toConcatenate) {
5084
- return Iterator.concatenate(this, ...toConcatenate);
5148
+ any() {
5149
+ return HttpHeaders.any(this);
5085
5150
  }
5086
- where(condition) {
5087
- return Iterator.where(this, condition);
5151
+ equals(right, equalFunctions) {
5152
+ return HttpHeaders.equals(this, right, equalFunctions);
5153
+ }
5154
+ toString(toStringFunctions) {
5155
+ return HttpHeaders.toString(this, toStringFunctions);
5156
+ }
5157
+ concatenate(...toConcatenate) {
5158
+ return HttpHeaders.concatenate(this, ...toConcatenate);
5088
5159
  }
5089
5160
  map(mapping) {
5090
- return Iterator.map(this, mapping);
5161
+ return HttpHeaders.map(this, mapping);
5091
5162
  }
5092
5163
  flatMap(mapping) {
5093
- return Iterator.flatMap(this, mapping);
5164
+ return HttpHeaders.flatMap(this, mapping);
5094
5165
  }
5095
- whereInstanceOf(typeCheck) {
5096
- return Iterator.whereInstanceOf(this, typeCheck);
5166
+ where(condition) {
5167
+ return HttpHeaders.where(this, condition);
5097
5168
  }
5098
- whereInstanceOfType(type) {
5099
- return Iterator.whereInstanceOfType(this, type);
5169
+ instanceOf(typeOrTypeCheck) {
5170
+ return HttpHeaders.instanceOf(this, typeOrTypeCheck);
5100
5171
  }
5101
5172
  first(condition) {
5102
- return Iterator.first(this, condition);
5173
+ return HttpHeaders.first(this, condition);
5103
5174
  }
5104
5175
  last(condition) {
5105
- return Iterator.last(this, condition);
5106
- }
5107
- take(maximumToTake) {
5108
- return Iterator.take(this, maximumToTake);
5109
- }
5110
- skip(maximumToSkip) {
5111
- return Iterator.skip(this, maximumToSkip);
5176
+ return HttpHeaders.last(this, condition);
5112
5177
  }
5113
5178
  [Symbol.iterator]() {
5114
- return Iterator[Symbol.iterator](this);
5179
+ return HttpHeaders[Symbol.iterator](this);
5180
+ }
5181
+ contains(value, equalFunctions) {
5182
+ return HttpHeaders.contains(this, value, equalFunctions);
5115
5183
  }
5116
5184
  };
5117
5185
 
5118
- // sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts
5119
- var AsyncIteratorToJavascriptAsyncIteratorAdapter = class _AsyncIteratorToJavascriptAsyncIteratorAdapter {
5120
- iterator;
5121
- hasStarted;
5122
- constructor(iterator) {
5123
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5124
- this.iterator = iterator;
5125
- this.hasStarted = false;
5186
+ // sources/httpHeaders.ts
5187
+ var HttpHeaders = class _HttpHeaders {
5188
+ static contentTypeHeaderName = "Content-Type";
5189
+ static create(headers) {
5190
+ return MutableHttpHeaders.create(headers);
5126
5191
  }
5127
- static create(iterator) {
5128
- return new _AsyncIteratorToJavascriptAsyncIteratorAdapter(iterator);
5192
+ getContentType() {
5193
+ return _HttpHeaders.getContentType(this);
5129
5194
  }
5130
- async next() {
5131
- if (!this.hasStarted) {
5132
- this.hasStarted = true;
5133
- await this.iterator.start();
5134
- } else {
5135
- await this.iterator.next();
5136
- }
5137
- const result = {
5138
- done: !this.iterator.hasCurrent(),
5139
- value: void 0
5140
- };
5141
- if (!result.done) {
5142
- result.value = this.iterator.getCurrent();
5143
- }
5144
- return result;
5195
+ static getContentType(headers) {
5196
+ return headers.get(_HttpHeaders.contentTypeHeaderName);
5145
5197
  }
5146
- };
5147
-
5148
- // sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts
5149
- var JavascriptAsyncIteratorToAsyncIteratorAdapter = class _JavascriptAsyncIteratorToAsyncIteratorAdapter {
5150
- javascriptIterator;
5151
- javascriptIteratorResult;
5152
- constructor(javascriptIterator) {
5153
- PreCondition.assertNotUndefinedAndNotNull(javascriptIterator, "javascriptIterator");
5154
- this.javascriptIterator = javascriptIterator;
5198
+ getContentTypeValue() {
5199
+ return _HttpHeaders.getContentTypeValue(this);
5155
5200
  }
5156
- static create(javascriptIterator) {
5157
- if (isJavascriptAsyncIterable(javascriptIterator)) {
5158
- javascriptIterator = javascriptIterator[Symbol.asyncIterator]();
5159
- }
5160
- return new _JavascriptAsyncIteratorToAsyncIteratorAdapter(javascriptIterator);
5201
+ static getContentTypeValue(headers) {
5202
+ return headers.getValue(_HttpHeaders.contentTypeHeaderName);
5161
5203
  }
5162
- next() {
5163
- return PromiseAsyncResult.create(async () => {
5164
- this.javascriptIteratorResult = await this.javascriptIterator.next();
5165
- return this.hasCurrent();
5166
- });
5204
+ /**
5205
+ * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
5206
+ */
5207
+ toArray() {
5208
+ return _HttpHeaders.toArray(this);
5167
5209
  }
5168
- hasStarted() {
5169
- return this.javascriptIteratorResult !== void 0;
5210
+ static toArray(headers) {
5211
+ return Iterable.toArray(headers);
5170
5212
  }
5171
- hasCurrent() {
5172
- return this.javascriptIteratorResult?.done === false;
5213
+ any() {
5214
+ return _HttpHeaders.any(this);
5173
5215
  }
5174
- getCurrent() {
5175
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5176
- return this.javascriptIteratorResult.value;
5216
+ static any(headers) {
5217
+ return Iterable.any(headers);
5177
5218
  }
5178
- start() {
5179
- return AsyncIterator.start(this);
5219
+ getCount() {
5220
+ return _HttpHeaders.getCount(this);
5180
5221
  }
5181
- takeCurrent() {
5182
- return AsyncIterator.takeCurrent(this);
5222
+ static getCount(headers) {
5223
+ return Iterable.getCount(headers);
5183
5224
  }
5184
- any() {
5185
- return AsyncIterator.any(this);
5225
+ equals(right, equalFunctions) {
5226
+ return _HttpHeaders.equals(this, right, equalFunctions);
5186
5227
  }
5187
- getCount() {
5188
- return AsyncIterator.getCount(this);
5228
+ static equals(headers, right, equalFunctions) {
5229
+ return Iterable.equals(headers, right, equalFunctions);
5189
5230
  }
5190
- toArray() {
5191
- return AsyncIterator.toArray(this);
5231
+ toString(toStringFunctions) {
5232
+ return _HttpHeaders.toString(this, toStringFunctions);
5233
+ }
5234
+ static toString(headers, toStringFunctions) {
5235
+ return Iterable.toString(headers, toStringFunctions);
5236
+ }
5237
+ concatenate(...toConcatenate) {
5238
+ return _HttpHeaders.concatenate(this, ...toConcatenate);
5239
+ }
5240
+ static concatenate(headers, ...toConcatenate) {
5241
+ return Iterable.concatenate(headers, ...toConcatenate);
5192
5242
  }
5193
5243
  map(mapping) {
5194
- return AsyncIterator.map(this, mapping);
5244
+ return _HttpHeaders.map(this, mapping);
5195
5245
  }
5196
- [Symbol.asyncIterator]() {
5197
- return AsyncIterator[Symbol.asyncIterator](this);
5246
+ static map(headers, mapping) {
5247
+ return Iterable.map(headers, mapping);
5198
5248
  }
5199
- first(condition) {
5200
- return AsyncIterator.first(this, condition);
5249
+ flatMap(mapping) {
5250
+ return _HttpHeaders.flatMap(this, mapping);
5201
5251
  }
5202
- last(condition) {
5203
- return AsyncIterator.last(this, condition);
5252
+ static flatMap(headers, mapping) {
5253
+ return Iterable.flatMap(headers, mapping);
5204
5254
  }
5205
5255
  where(condition) {
5206
- return AsyncIterator.where(this, condition);
5207
- }
5208
- whereInstanceOf(typeCheck) {
5209
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5256
+ return _HttpHeaders.where(this, condition);
5210
5257
  }
5211
- whereInstanceOfType(type) {
5212
- return AsyncIterator.whereInstanceOfType(this, type);
5258
+ static where(headers, condition) {
5259
+ return Iterable.where(headers, condition);
5213
5260
  }
5214
- take(maximumToTake) {
5215
- return AsyncIterator.take(this, maximumToTake);
5261
+ instanceOf(typeOrTypeCheck) {
5262
+ return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
5216
5263
  }
5217
- skip(maximumToSkip) {
5218
- return AsyncIterator.skip(this, maximumToSkip);
5264
+ static instanceOf(headers, typeOrTypeCheck) {
5265
+ return Iterable.instanceOf(headers, typeOrTypeCheck);
5219
5266
  }
5220
- };
5221
-
5222
- // sources/mapAsyncIterator.ts
5223
- var MapAsyncIterator = class _MapAsyncIterator {
5224
- inputIterator;
5225
- mapping;
5226
- current;
5227
- started;
5228
- constructor(inputIterator, mapping) {
5229
- PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
5230
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5231
- this.inputIterator = inputIterator;
5232
- this.mapping = mapping;
5233
- this.started = false;
5267
+ first(condition) {
5268
+ return _HttpHeaders.first(this, condition);
5234
5269
  }
5235
- static create(inputIterator, mapping) {
5236
- return new _MapAsyncIterator(inputIterator, mapping);
5270
+ static first(headers, condition) {
5271
+ return Iterable.first(headers, condition);
5237
5272
  }
5238
- next() {
5239
- return PromiseAsyncResult.create(async () => {
5240
- if (!this.hasStarted()) {
5241
- this.started = true;
5242
- await this.inputIterator.start();
5243
- } else {
5244
- await this.inputIterator.next();
5245
- }
5246
- const result = this.inputIterator.hasCurrent();
5247
- this.current = result ? await this.mapping(this.inputIterator.getCurrent()) : void 0;
5248
- return result;
5249
- });
5273
+ last(condition) {
5274
+ return _HttpHeaders.last(this, condition);
5250
5275
  }
5251
- hasStarted() {
5252
- return this.started;
5276
+ static last(headers, condition) {
5277
+ return Iterable.last(headers, condition);
5253
5278
  }
5254
- hasCurrent() {
5255
- return this.hasStarted() && this.inputIterator.hasCurrent();
5279
+ [Symbol.iterator]() {
5280
+ return _HttpHeaders[Symbol.iterator](this);
5256
5281
  }
5257
- getCurrent() {
5258
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5259
- return this.current;
5282
+ static [Symbol.iterator](headers) {
5283
+ return Iterable[Symbol.iterator](headers);
5260
5284
  }
5261
- start() {
5262
- return AsyncIterator.start(this);
5285
+ contains(value, equalFunctions) {
5286
+ return _HttpHeaders.contains(this, value, equalFunctions);
5263
5287
  }
5264
- takeCurrent() {
5265
- return AsyncIterator.takeCurrent(this);
5288
+ static contains(headers, value, equalFunctions) {
5289
+ return SyncResult.create(() => {
5290
+ if (!equalFunctions) {
5291
+ equalFunctions = EqualFunctions.create();
5292
+ }
5293
+ return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
5294
+ });
5266
5295
  }
5267
- any() {
5268
- return AsyncIterator.any(this);
5296
+ };
5297
+
5298
+ // sources/NodeJSHttpOutgoingResponse.ts
5299
+ var NodeJSHttpOutgoingResponse = class _NodeJSHttpOutgoingResponse {
5300
+ innerResponse;
5301
+ bodyString;
5302
+ constructor(innerResponse) {
5303
+ PreCondition.assertNotUndefinedAndNotNull(innerResponse, "innerResponse");
5304
+ this.innerResponse = innerResponse;
5269
5305
  }
5270
- getCount() {
5271
- return AsyncIterator.getCount(this);
5306
+ static create(innerResponse) {
5307
+ return new _NodeJSHttpOutgoingResponse(innerResponse);
5272
5308
  }
5273
- toArray() {
5274
- return AsyncIterator.toArray(this);
5309
+ setStatusCode(statusCode) {
5310
+ this.innerResponse.statusCode = statusCode;
5311
+ return this;
5275
5312
  }
5276
- map(mapping) {
5277
- return AsyncIterator.map(this, mapping);
5313
+ getStatusCode() {
5314
+ return SyncResult.value(this.innerResponse.statusCode);
5278
5315
  }
5279
- [Symbol.asyncIterator]() {
5280
- return AsyncIterator[Symbol.asyncIterator](this);
5316
+ static headerValueToString(headerValue) {
5317
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5318
+ return isArray(headerValue) ? join(",", headerValue) : headerValue.toString();
5281
5319
  }
5282
- first(condition) {
5283
- return AsyncIterator.first(this, condition);
5320
+ getHeaders() {
5321
+ const result = HttpHeaders.create();
5322
+ for (const rawHeader of Object.entries(this.innerResponse.getHeaders())) {
5323
+ const headerName = rawHeader[0];
5324
+ const headerValue = rawHeader[1];
5325
+ if (headerValue !== void 0) {
5326
+ result.set(headerName, _NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
5327
+ }
5328
+ }
5329
+ return result;
5284
5330
  }
5285
- last() {
5286
- return AsyncIterator.last(this);
5331
+ getHeader(headerName) {
5332
+ PreCondition.assertNotEmpty(headerName, "headerName");
5333
+ const headerValue = this.innerResponse.getHeader(headerName);
5334
+ return headerValue === void 0 ? SyncResult.error(new NotFoundError(`No HTTP header value exists with the name ${escapeAndQuote(headerName)}.`)) : SyncResult.value(HttpHeader.create(headerName, _NodeJSHttpOutgoingResponse.headerValueToString(headerValue)));
5287
5335
  }
5288
- where(condition) {
5289
- return AsyncIterator.where(this, condition);
5336
+ getHeaderValue(headerName) {
5337
+ const headerValue = this.innerResponse.getHeader(headerName);
5338
+ return headerValue === void 0 ? SyncResult.error(new NotFoundError(`No HTTP header value exists with the name ${escapeAndQuote(headerName)}.`)) : SyncResult.value(_NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
5290
5339
  }
5291
- whereInstanceOf(typeCheck) {
5292
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5340
+ setHeader(headerName, headerValue) {
5341
+ PreCondition.assertNotEmpty(headerName, "headerName");
5342
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5343
+ this.innerResponse.setHeader(headerName, headerValue);
5344
+ return this;
5293
5345
  }
5294
- whereInstanceOfType(type) {
5295
- return AsyncIterator.whereInstanceOfType(this, type);
5346
+ setBodyString(body) {
5347
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5348
+ this.bodyString = body;
5349
+ return this;
5296
5350
  }
5297
- take(maximumToTake) {
5298
- return AsyncIterator.take(this, maximumToTake);
5351
+ setBodyJSON(body) {
5352
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5353
+ return this.setBodyString(JSON.stringify(body));
5299
5354
  }
5300
- skip(maximumToSkip) {
5301
- return AsyncIterator.skip(this, maximumToSkip);
5355
+ end() {
5356
+ return AsyncResult.create(new Promise((resolve, reject) => {
5357
+ this.innerResponse.end(this.bodyString, () => {
5358
+ resolve();
5359
+ });
5360
+ }));
5302
5361
  }
5303
5362
  };
5304
5363
 
5305
- // sources/skipAsyncIterator.ts
5306
- var SkipAsyncIterator = class _SkipAsyncIterator {
5307
- innerIterator;
5308
- started;
5309
- maximumToSkip;
5310
- constructor(innerIterator, maximumToSkip) {
5311
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5312
- PreCondition.assertNotUndefinedAndNotNull(maximumToSkip, "maximumToSkip");
5313
- PreCondition.assertInteger(maximumToSkip, "maximumToSkip");
5314
- PreCondition.assertGreaterThanOrEqualTo(maximumToSkip, 0, "maximumToSkip");
5315
- this.innerIterator = innerIterator;
5316
- this.started = false;
5317
- this.maximumToSkip = maximumToSkip;
5364
+ // sources/TokenType.ts
5365
+ var TokenType = class _TokenType {
5366
+ name;
5367
+ constructor(name) {
5368
+ PreCondition.assertNotEmpty(name, "name");
5369
+ this.name = name;
5318
5370
  }
5319
- static create(innerIterator, maximumToSkip) {
5320
- return new _SkipAsyncIterator(innerIterator, maximumToSkip);
5371
+ static create(name) {
5372
+ return new _TokenType(name);
5321
5373
  }
5322
- next() {
5323
- return PromiseAsyncResult.create(async () => {
5324
- if (!this.hasStarted()) {
5325
- this.started = true;
5326
- await this.innerIterator.start();
5327
- for (let i = 0; i < this.maximumToSkip; i++) {
5328
- if (!await this.innerIterator.next()) {
5329
- break;
5330
- }
5331
- }
5332
- } else {
5333
- await this.innerIterator.next();
5334
- }
5335
- return this.hasCurrent();
5336
- });
5374
+ static Whitespace = _TokenType.create("Whitespace");
5375
+ static NewLine = _TokenType.create("NewLine");
5376
+ static Letters = _TokenType.create("Letters");
5377
+ static Digits = _TokenType.create("Digits");
5378
+ static LeftParenthesis = _TokenType.create("LeftParenthesis");
5379
+ static RightParenthesis = _TokenType.create("RightParenthesis");
5380
+ static Backslash = _TokenType.create("Backslash");
5381
+ static ForwardSlash = _TokenType.create("ForwardSlash");
5382
+ static Unknown = _TokenType.create("Unknown");
5383
+ static Period = _TokenType.create("Period");
5384
+ static Underscore = _TokenType.create("Underscore");
5385
+ static Colon = _TokenType.create("Colon");
5386
+ toString() {
5387
+ return this.name;
5337
5388
  }
5338
- hasStarted() {
5339
- return this.started;
5340
- }
5341
- hasCurrent() {
5342
- return this.hasStarted() && this.innerIterator.hasCurrent();
5389
+ };
5390
+
5391
+ // sources/Token.ts
5392
+ var Token = class _Token {
5393
+ static newLineToken = _Token.create("\n", TokenType.NewLine);
5394
+ static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
5395
+ static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
5396
+ static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
5397
+ static backslashToken = _Token.create("\\", TokenType.Backslash);
5398
+ static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
5399
+ static periodToken = _Token.create(".", TokenType.Period);
5400
+ static underscoreToken = _Token.create("_", TokenType.Underscore);
5401
+ static colonToken = _Token.create(":", TokenType.Colon);
5402
+ text;
5403
+ type;
5404
+ constructor(text, type) {
5405
+ PreCondition.assertNotEmpty(text, "text");
5406
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
5407
+ this.text = text;
5408
+ this.type = type;
5343
5409
  }
5344
- getCurrent() {
5345
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5346
- return this.innerIterator.getCurrent();
5410
+ static create(text, type) {
5411
+ return new _Token(text, type);
5347
5412
  }
5348
- start() {
5349
- return AsyncIterator.start(this);
5413
+ static whitespace(text) {
5414
+ return _Token.create(text, TokenType.Whitespace);
5350
5415
  }
5351
- takeCurrent() {
5352
- return AsyncIterator.takeCurrent(this);
5416
+ static newLine(text) {
5417
+ text ??= "\n";
5418
+ let result;
5419
+ switch (text) {
5420
+ case "\n":
5421
+ result = _Token.newLineToken;
5422
+ break;
5423
+ case "\r\n":
5424
+ result = _Token.carriageReturnNewLineToken;
5425
+ break;
5426
+ default:
5427
+ result = _Token.create(text, TokenType.NewLine);
5428
+ break;
5429
+ }
5430
+ return result;
5353
5431
  }
5354
- any() {
5355
- return AsyncIterator.any(this);
5432
+ static leftParenthesis() {
5433
+ return _Token.leftParenthesisToken;
5356
5434
  }
5357
- getCount() {
5358
- return AsyncIterator.getCount(this);
5435
+ static rightParenthesis() {
5436
+ return _Token.rightParenthesisToken;
5359
5437
  }
5360
- toArray() {
5361
- return AsyncIterator.toArray(this);
5438
+ static backslash() {
5439
+ return _Token.backslashToken;
5362
5440
  }
5363
- where(condition) {
5364
- return AsyncIterator.where(this, condition);
5441
+ static forwardSlash() {
5442
+ return _Token.forwardSlashToken;
5365
5443
  }
5366
- whereInstanceOf(typeCheck) {
5367
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5444
+ static period() {
5445
+ return _Token.periodToken;
5368
5446
  }
5369
- whereInstanceOfType(type) {
5370
- return AsyncIterator.whereInstanceOfType(this, type);
5447
+ static underscore() {
5448
+ return _Token.underscoreToken;
5371
5449
  }
5372
- map(mapping) {
5373
- return AsyncIterator.map(this, mapping);
5450
+ static colon() {
5451
+ return _Token.colonToken;
5374
5452
  }
5375
- first(condition) {
5376
- return AsyncIterator.first(this, condition);
5453
+ static letters(text) {
5454
+ return _Token.create(text, TokenType.Letters);
5377
5455
  }
5378
- last(condition) {
5379
- return AsyncIterator.last(this, condition);
5456
+ static digits(text) {
5457
+ return _Token.create(text, TokenType.Digits);
5380
5458
  }
5381
- [Symbol.asyncIterator]() {
5382
- return AsyncIterator[Symbol.asyncIterator](this);
5459
+ static unknown(text) {
5460
+ return _Token.create(text, TokenType.Unknown);
5383
5461
  }
5384
- take(maximumToTake) {
5385
- return AsyncIterator.take(this, maximumToTake);
5462
+ getText() {
5463
+ return this.text;
5386
5464
  }
5387
- skip(maximumToSkip) {
5388
- return AsyncIterator.skip(this, maximumToSkip);
5465
+ getType() {
5466
+ return this.type;
5389
5467
  }
5390
5468
  };
5391
5469
 
5392
- // sources/takeAsyncIterator.ts
5393
- var TakeAsyncIterator = class _TakeAsyncIterator {
5394
- innerIterator;
5470
+ // sources/Tokenizer.ts
5471
+ var Tokenizer = class _Tokenizer {
5472
+ characters;
5473
+ currentToken;
5395
5474
  started;
5396
- maximumToTake;
5397
- taken;
5398
- constructor(innerIterator, maximumToTake) {
5399
- PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
5400
- this.innerIterator = innerIterator;
5475
+ constructor(characters) {
5476
+ this.characters = characters;
5401
5477
  this.started = false;
5402
- this.maximumToTake = maximumToTake;
5403
- this.taken = 0;
5404
5478
  }
5405
- static create(innerIterator, maximumToTake) {
5406
- return new _TakeAsyncIterator(innerIterator, maximumToTake);
5479
+ static create(characters) {
5480
+ PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
5481
+ return new _Tokenizer(isIterator(characters) ? characters : Iterator.create(characters));
5482
+ }
5483
+ hasStarted() {
5484
+ return this.started;
5407
5485
  }
5408
5486
  hasCurrent() {
5409
- return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
5487
+ return this.currentToken !== void 0;
5488
+ }
5489
+ getCurrent() {
5490
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5491
+ return this.currentToken;
5410
5492
  }
5411
5493
  next() {
5412
- return PromiseAsyncResult.create(async () => {
5413
- if (this.maximumToTake <= 0) {
5414
- return false;
5415
- } else if (!this.hasStarted()) {
5494
+ return SyncResult.create(() => {
5495
+ if (!this.hasStarted()) {
5496
+ this.characters.start().await();
5416
5497
  this.started = true;
5417
- await this.innerIterator.start();
5418
- this.taken++;
5419
- } else if (this.taken <= this.maximumToTake) {
5420
- await this.innerIterator.next();
5421
- this.taken++;
5498
+ }
5499
+ if (!this.characters.hasCurrent()) {
5500
+ this.currentToken = void 0;
5501
+ } else {
5502
+ switch (this.characters.getCurrent()) {
5503
+ case " ":
5504
+ case " ":
5505
+ this.currentToken = Token.whitespace(this.readWhile((c) => c === " " || c === " "));
5506
+ break;
5507
+ case "\n":
5508
+ this.characters.next().await();
5509
+ this.currentToken = Token.newLine();
5510
+ break;
5511
+ case "\r":
5512
+ if (this.characters.next().await() && this.characters.getCurrent() === "\n") {
5513
+ this.characters.next().await();
5514
+ this.currentToken = Token.newLine("\r\n");
5515
+ } else {
5516
+ this.currentToken = Token.whitespace("\r");
5517
+ }
5518
+ break;
5519
+ case "(":
5520
+ this.characters.next().await();
5521
+ this.currentToken = Token.leftParenthesis();
5522
+ break;
5523
+ case ")":
5524
+ this.characters.next().await();
5525
+ this.currentToken = Token.rightParenthesis();
5526
+ break;
5527
+ case ".":
5528
+ this.characters.next().await();
5529
+ this.currentToken = Token.period();
5530
+ break;
5531
+ case "_":
5532
+ this.characters.next().await();
5533
+ this.currentToken = Token.underscore();
5534
+ break;
5535
+ case "/":
5536
+ this.characters.next().await();
5537
+ this.currentToken = Token.forwardSlash();
5538
+ break;
5539
+ case "\\":
5540
+ this.characters.next().await();
5541
+ this.currentToken = Token.backslash();
5542
+ break;
5543
+ case ":":
5544
+ this.characters.next().await();
5545
+ this.currentToken = Token.colon();
5546
+ break;
5547
+ default:
5548
+ if (isLetter(this.characters.getCurrent())) {
5549
+ this.currentToken = Token.letters(this.readWhile(isLetter));
5550
+ } else if (isDigit(this.characters.getCurrent())) {
5551
+ this.currentToken = Token.digits(this.readWhile(isDigit));
5552
+ } else {
5553
+ this.currentToken = Token.unknown(this.characters.takeCurrent().await());
5554
+ }
5555
+ break;
5556
+ }
5422
5557
  }
5423
5558
  return this.hasCurrent();
5424
5559
  });
5425
5560
  }
5426
- hasStarted() {
5427
- return this.started;
5428
- }
5429
- getCurrent() {
5430
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5431
- return this.innerIterator.getCurrent();
5561
+ readWhile(condition) {
5562
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5563
+ PreCondition.assertTrue(this.characters.hasCurrent(), "this.characters.hasCurrent()");
5564
+ PreCondition.assertTrue(condition(this.characters.getCurrent()), "condition(this.characters.getCurrent())");
5565
+ let result = "";
5566
+ do {
5567
+ result += this.characters.takeCurrent().await();
5568
+ } while (this.characters.hasCurrent() && condition(this.characters.getCurrent()));
5569
+ return result;
5432
5570
  }
5433
5571
  start() {
5434
- return AsyncIterator.start(this);
5572
+ return Iterator.start(this);
5435
5573
  }
5436
5574
  takeCurrent() {
5437
- return AsyncIterator.takeCurrent(this);
5575
+ return Iterator.takeCurrent(this);
5438
5576
  }
5439
5577
  any() {
5440
- return AsyncIterator.any(this);
5578
+ return Iterator.any(this);
5441
5579
  }
5442
5580
  getCount() {
5443
- return AsyncIterator.getCount(this);
5581
+ return Iterator.getCount(this);
5444
5582
  }
5445
5583
  toArray() {
5446
- return AsyncIterator.toArray(this);
5584
+ return Iterator.toArray(this);
5585
+ }
5586
+ concatenate(...toConcatenate) {
5587
+ return Iterator.concatenate(this, ...toConcatenate);
5447
5588
  }
5448
5589
  where(condition) {
5449
- return AsyncIterator.where(this, condition);
5590
+ return Iterator.where(this, condition);
5591
+ }
5592
+ map(mapping) {
5593
+ return Iterator.map(this, mapping);
5594
+ }
5595
+ flatMap(mapping) {
5596
+ return Iterator.flatMap(this, mapping);
5450
5597
  }
5451
5598
  whereInstanceOf(typeCheck) {
5452
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5599
+ return Iterator.whereInstanceOf(this, typeCheck);
5453
5600
  }
5454
5601
  whereInstanceOfType(type) {
5455
- return AsyncIterator.whereInstanceOfType(this, type);
5456
- }
5457
- map(mapping) {
5458
- return AsyncIterator.map(this, mapping);
5602
+ return Iterator.whereInstanceOfType(this, type);
5459
5603
  }
5460
5604
  first(condition) {
5461
- return AsyncIterator.first(this, condition);
5605
+ return Iterator.first(this, condition);
5462
5606
  }
5463
5607
  last(condition) {
5464
- return AsyncIterator.last(this, condition);
5465
- }
5466
- [Symbol.asyncIterator]() {
5467
- return AsyncIterator[Symbol.asyncIterator](this);
5608
+ return Iterator.last(this, condition);
5468
5609
  }
5469
5610
  take(maximumToTake) {
5470
- return AsyncIterator.take(this, maximumToTake);
5611
+ return Iterator.take(this, maximumToTake);
5471
5612
  }
5472
5613
  skip(maximumToSkip) {
5473
- return AsyncIterator.skip(this, maximumToSkip);
5614
+ return Iterator.skip(this, maximumToSkip);
5615
+ }
5616
+ [Symbol.iterator]() {
5617
+ return Iterator[Symbol.iterator](this);
5474
5618
  }
5475
5619
  };
5476
5620
 
5477
- // sources/whereAsyncIterator.ts
5478
- var WhereAsyncIterator = class _WhereAsyncIterator {
5479
- innerIterator;
5480
- started;
5481
- condition;
5482
- constructor(innerIterator, condition) {
5483
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5484
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5485
- this.innerIterator = innerIterator;
5486
- this.started = false;
5487
- this.condition = condition;
5621
+ // sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts
5622
+ var AsyncIteratorToJavascriptAsyncIteratorAdapter = class _AsyncIteratorToJavascriptAsyncIteratorAdapter {
5623
+ iterator;
5624
+ hasStarted;
5625
+ constructor(iterator) {
5626
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5627
+ this.iterator = iterator;
5628
+ this.hasStarted = false;
5488
5629
  }
5489
- hasStarted() {
5490
- return this.started;
5630
+ static create(iterator) {
5631
+ return new _AsyncIteratorToJavascriptAsyncIteratorAdapter(iterator);
5491
5632
  }
5492
- hasCurrent() {
5493
- return this.hasStarted() && this.innerIterator.hasCurrent();
5633
+ async next() {
5634
+ if (!this.hasStarted) {
5635
+ this.hasStarted = true;
5636
+ await this.iterator.start();
5637
+ } else {
5638
+ await this.iterator.next();
5639
+ }
5640
+ const result = {
5641
+ done: !this.iterator.hasCurrent(),
5642
+ value: void 0
5643
+ };
5644
+ if (!result.done) {
5645
+ result.value = this.iterator.getCurrent();
5646
+ }
5647
+ return result;
5494
5648
  }
5495
- getCurrent() {
5496
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5497
- return this.innerIterator.getCurrent();
5649
+ };
5650
+
5651
+ // sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts
5652
+ var JavascriptAsyncIteratorToAsyncIteratorAdapter = class _JavascriptAsyncIteratorToAsyncIteratorAdapter {
5653
+ javascriptIterator;
5654
+ javascriptIteratorResult;
5655
+ constructor(javascriptIterator) {
5656
+ PreCondition.assertNotUndefinedAndNotNull(javascriptIterator, "javascriptIterator");
5657
+ this.javascriptIterator = javascriptIterator;
5498
5658
  }
5499
- static create(innerIterator, condition) {
5500
- return new _WhereAsyncIterator(innerIterator, condition);
5659
+ static create(javascriptIterator) {
5660
+ if (isJavascriptAsyncIterable(javascriptIterator)) {
5661
+ javascriptIterator = javascriptIterator[Symbol.asyncIterator]();
5662
+ }
5663
+ return new _JavascriptAsyncIteratorToAsyncIteratorAdapter(javascriptIterator);
5501
5664
  }
5502
5665
  next() {
5503
5666
  return PromiseAsyncResult.create(async () => {
5504
- if (!this.hasStarted()) {
5505
- await this.innerIterator.start();
5506
- this.started = true;
5507
- while (this.hasCurrent() && !await this.condition(this.getCurrent())) {
5508
- await this.innerIterator.next();
5509
- }
5510
- } else {
5511
- do {
5512
- await this.innerIterator.next();
5513
- } while (this.hasCurrent() && !await this.condition(this.getCurrent()));
5514
- }
5667
+ this.javascriptIteratorResult = await this.javascriptIterator.next();
5515
5668
  return this.hasCurrent();
5516
5669
  });
5517
5670
  }
5671
+ hasStarted() {
5672
+ return this.javascriptIteratorResult !== void 0;
5673
+ }
5674
+ hasCurrent() {
5675
+ return this.javascriptIteratorResult?.done === false;
5676
+ }
5677
+ getCurrent() {
5678
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5679
+ return this.javascriptIteratorResult.value;
5680
+ }
5518
5681
  start() {
5519
5682
  return AsyncIterator.start(this);
5520
5683
  }
@@ -5530,17 +5693,11 @@ var WhereAsyncIterator = class _WhereAsyncIterator {
5530
5693
  toArray() {
5531
5694
  return AsyncIterator.toArray(this);
5532
5695
  }
5533
- where(condition) {
5534
- return AsyncIterator.where(this, condition);
5535
- }
5536
5696
  map(mapping) {
5537
5697
  return AsyncIterator.map(this, mapping);
5538
5698
  }
5539
- whereInstanceOf(typeCheck) {
5540
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5541
- }
5542
- whereInstanceOfType(type) {
5543
- return AsyncIterator.whereInstanceOfType(this, type);
5699
+ [Symbol.asyncIterator]() {
5700
+ return AsyncIterator[Symbol.asyncIterator](this);
5544
5701
  }
5545
5702
  first(condition) {
5546
5703
  return AsyncIterator.first(this, condition);
@@ -5548,565 +5705,223 @@ var WhereAsyncIterator = class _WhereAsyncIterator {
5548
5705
  last(condition) {
5549
5706
  return AsyncIterator.last(this, condition);
5550
5707
  }
5708
+ where(condition) {
5709
+ return AsyncIterator.where(this, condition);
5710
+ }
5711
+ whereInstanceOf(typeCheck) {
5712
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5713
+ }
5714
+ whereInstanceOfType(type) {
5715
+ return AsyncIterator.whereInstanceOfType(this, type);
5716
+ }
5551
5717
  take(maximumToTake) {
5552
5718
  return AsyncIterator.take(this, maximumToTake);
5553
5719
  }
5554
5720
  skip(maximumToSkip) {
5555
5721
  return AsyncIterator.skip(this, maximumToSkip);
5556
5722
  }
5557
- [Symbol.asyncIterator]() {
5558
- return AsyncIterator[Symbol.asyncIterator](this);
5559
- }
5560
5723
  };
5561
5724
 
5562
- // sources/asyncIterator.ts
5563
- var AsyncIterator = class _AsyncIterator {
5564
- static create(iterator) {
5565
- return JavascriptAsyncIteratorToAsyncIteratorAdapter.create(iterator);
5725
+ // sources/mapAsyncIterator.ts
5726
+ var MapAsyncIterator = class _MapAsyncIterator {
5727
+ inputIterator;
5728
+ mapping;
5729
+ current;
5730
+ started;
5731
+ constructor(inputIterator, mapping) {
5732
+ PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
5733
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5734
+ this.inputIterator = inputIterator;
5735
+ this.mapping = mapping;
5736
+ this.started = false;
5566
5737
  }
5567
- /**
5568
- * Move to the first value if this {@link AsyncIterator} hasn't started yet.
5569
- * @returns This object for method chaining.
5570
- */
5571
- start() {
5572
- return _AsyncIterator.start(this);
5738
+ static create(inputIterator, mapping) {
5739
+ return new _MapAsyncIterator(inputIterator, mapping);
5573
5740
  }
5574
- /**
5575
- * Move the provided {@link AsyncIterator} to its first value if it hasn't started yet.
5576
- */
5577
- static start(iterator) {
5578
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5741
+ next() {
5579
5742
  return PromiseAsyncResult.create(async () => {
5580
- if (!iterator.hasStarted()) {
5581
- await iterator.next();
5743
+ if (!this.hasStarted()) {
5744
+ this.started = true;
5745
+ await this.inputIterator.start();
5746
+ } else {
5747
+ await this.inputIterator.next();
5582
5748
  }
5583
- return iterator;
5749
+ const result = this.inputIterator.hasCurrent();
5750
+ this.current = result ? await this.mapping(this.inputIterator.getCurrent()) : void 0;
5751
+ return result;
5584
5752
  });
5585
5753
  }
5586
- /**
5587
- * Get the current value from this {@link AsyncIterator} and advance this {@link AsyncIterator} to the
5588
- * next value.
5589
- */
5590
- takeCurrent() {
5591
- return _AsyncIterator.takeCurrent(this);
5754
+ hasStarted() {
5755
+ return this.started;
5592
5756
  }
5593
- static takeCurrent(iterator) {
5594
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5595
- PreCondition.assertTrue(iterator.hasCurrent(), "iterator.hasCurrent()");
5596
- return PromiseAsyncResult.create(async () => {
5597
- const result = iterator.getCurrent();
5598
- await iterator.next();
5599
- return result;
5600
- });
5757
+ hasCurrent() {
5758
+ return this.hasStarted() && this.inputIterator.hasCurrent();
5601
5759
  }
5602
- [Symbol.asyncIterator]() {
5603
- return _AsyncIterator[Symbol.asyncIterator](this);
5760
+ getCurrent() {
5761
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5762
+ return this.current;
5604
5763
  }
5605
- /**
5606
- * Convert the provided {@link AsyncIterator} to a {@link IteratorToJavascriptIteratorAdapter}.
5607
- * @param iterator The {@link AsyncIterator} to convert.
5608
- */
5609
- static [Symbol.asyncIterator](iterator) {
5610
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5611
- return AsyncIteratorToJavascriptAsyncIteratorAdapter.create(iterator);
5764
+ start() {
5765
+ return AsyncIterator.start(this);
5612
5766
  }
5613
- /**
5614
- * Get whether this {@link AsyncIterator} contains any values.
5615
- * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5616
- * started yet.
5617
- */
5618
- any() {
5619
- return _AsyncIterator.any(this);
5767
+ takeCurrent() {
5768
+ return AsyncIterator.takeCurrent(this);
5620
5769
  }
5621
- /**
5622
- * Get whether this {@link AsyncIterator} contains any values.
5623
- * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5624
- * started yet.
5625
- */
5626
- static any(iterator) {
5627
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5628
- return PromiseAsyncResult.create(async () => {
5629
- await iterator.start();
5630
- return iterator.hasCurrent();
5631
- });
5770
+ any() {
5771
+ return AsyncIterator.any(this);
5632
5772
  }
5633
- /**
5634
- * Get the number of values in this {@link AsyncIterator}.
5635
- * Note: This will consume all of the values in this {@link AsyncIterator}.
5636
- */
5637
5773
  getCount() {
5638
- return _AsyncIterator.getCount(this);
5639
- }
5640
- /**
5641
- * Get the number of values in the provided {@link AsyncIterator}.
5642
- * Note: This will consume all of the values in the provided {@link AsyncIterator}.
5643
- */
5644
- static getCount(iterator) {
5645
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5646
- return PromiseAsyncResult.create(async () => {
5647
- let result = 0;
5648
- if (iterator.hasCurrent()) {
5649
- result++;
5650
- }
5651
- while (await iterator.next()) {
5652
- result++;
5653
- }
5654
- return result;
5655
- });
5774
+ return AsyncIterator.getCount(this);
5656
5775
  }
5657
- /**
5658
- * Get all of the remaining values in this {@link AsyncIterator} in a {@link T} {@link Array}.
5659
- */
5660
5776
  toArray() {
5661
- return _AsyncIterator.toArray(this);
5662
- }
5663
- /**
5664
- * Get all of the remaining values in the provided {@link AsyncIterator} in a {@link T}
5665
- * {@link Array}.
5666
- */
5667
- static toArray(iterator) {
5668
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5669
- return PromiseAsyncResult.create(async () => {
5670
- const result = [];
5671
- if (iterator.hasCurrent()) {
5672
- result.push(iterator.getCurrent());
5673
- }
5674
- while (await iterator.next()) {
5675
- result.push(iterator.getCurrent());
5676
- }
5677
- return result;
5678
- });
5777
+ return AsyncIterator.toArray(this);
5679
5778
  }
5680
- /**
5681
- * Get an {@link AsyncIterator} that will only return values that match the provided condition.
5682
- * @param condition The condition to run against each of the values in this {@link AsyncIterator}.
5683
- */
5684
- where(condition) {
5685
- return _AsyncIterator.where(this, condition);
5779
+ map(mapping) {
5780
+ return AsyncIterator.map(this, mapping);
5686
5781
  }
5687
- static where(iterator, condition) {
5688
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5689
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5690
- return WhereAsyncIterator.create(iterator, condition);
5782
+ [Symbol.asyncIterator]() {
5783
+ return AsyncIterator[Symbol.asyncIterator](this);
5691
5784
  }
5692
- /**
5693
- * Get a {@link MapIterator} that will map all {@link T} values from this {@link AsyncIterator} to
5694
- * {@link TOutput} values.
5695
- * @param mapping The mapping that maps {@link T} values to {@link TOutput} values.
5696
- */
5697
- map(mapping) {
5698
- return _AsyncIterator.map(this, mapping);
5785
+ first(condition) {
5786
+ return AsyncIterator.first(this, condition);
5699
5787
  }
5700
- static map(iterator, mapping) {
5701
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5702
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5703
- return MapAsyncIterator.create(iterator, mapping);
5788
+ last() {
5789
+ return AsyncIterator.last(this);
5704
5790
  }
5705
- /**
5706
- * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
5707
- * instances of {@link U} based on the provided type check {@link Function}.
5708
- * @param typeCheck The {@link Function} that will be used to determine if values are of type
5709
- * {@link U}.
5710
- */
5711
- whereInstanceOf(typeCheck) {
5712
- return _AsyncIterator.whereInstanceOf(this, typeCheck);
5791
+ where(condition) {
5792
+ return AsyncIterator.where(this, condition);
5713
5793
  }
5714
- static whereInstanceOf(iterator, typeCheck) {
5715
- PreCondition.assertNotUndefinedAndNotNull(typeCheck, "typeCheck");
5716
- return iterator.where(typeCheck).map((value) => value);
5794
+ whereInstanceOf(typeCheck) {
5795
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5717
5796
  }
5718
- /**
5719
- * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
5720
- * instances of the provided {@link Type}.
5721
- * @param type The type of values to return from the new {@link AsyncIterator}.
5722
- */
5723
5797
  whereInstanceOfType(type) {
5724
- return _AsyncIterator.whereInstanceOfType(this, type);
5798
+ return AsyncIterator.whereInstanceOfType(this, type);
5725
5799
  }
5726
- static whereInstanceOfType(iterator, type) {
5727
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
5728
- return iterator.whereInstanceOf((value) => instanceOfType(value, type));
5800
+ take(maximumToTake) {
5801
+ return AsyncIterator.take(this, maximumToTake);
5729
5802
  }
5730
- /**
5731
- * If the condition function is undefined, then this function will return the first value in
5732
- * this {@link AsyncIterator}. If this condition function is provided, then this function will return
5733
- * the first value that matches the provided condition.
5734
- * @param condition The condition that the returned value must satisfy.
5735
- */
5736
- first(condition) {
5737
- return _AsyncIterator.first(this, condition);
5803
+ skip(maximumToSkip) {
5804
+ return AsyncIterator.skip(this, maximumToSkip);
5738
5805
  }
5739
- /**
5740
- * If the condition function is undefined, then this function will return the first value in
5741
- * the {@link AsyncIterator}. If this condition function is provided, then this function will return
5742
- * the first value that matches the provided condition.
5743
- * @param iterator The {@link AsyncIterator} to get the first value from.
5744
- */
5745
- static first(iterator, condition) {
5746
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5747
- return PromiseAsyncResult.create(async () => {
5748
- await iterator.start();
5749
- if (isUndefinedOrNull(condition)) {
5750
- if (!iterator.hasCurrent()) {
5751
- throw new EmptyError();
5752
- }
5753
- } else {
5754
- while (iterator.hasCurrent() && !await condition(iterator.getCurrent())) {
5755
- await iterator.next();
5756
- }
5757
- if (!iterator.hasCurrent()) {
5758
- throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
5759
- }
5760
- }
5761
- return iterator.getCurrent();
5762
- });
5806
+ };
5807
+
5808
+ // sources/skipAsyncIterator.ts
5809
+ var SkipAsyncIterator = class _SkipAsyncIterator {
5810
+ innerIterator;
5811
+ started;
5812
+ maximumToSkip;
5813
+ constructor(innerIterator, maximumToSkip) {
5814
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5815
+ PreCondition.assertNotUndefinedAndNotNull(maximumToSkip, "maximumToSkip");
5816
+ PreCondition.assertInteger(maximumToSkip, "maximumToSkip");
5817
+ PreCondition.assertGreaterThanOrEqualTo(maximumToSkip, 0, "maximumToSkip");
5818
+ this.innerIterator = innerIterator;
5819
+ this.started = false;
5820
+ this.maximumToSkip = maximumToSkip;
5763
5821
  }
5764
- /**
5765
- * If the condition function is undefined, then this function will return the last value in this
5766
- * {@link AsyncIterator}. If this condition function is provided, then this function will return the
5767
- * last value that matches the provided condition.
5768
- * @param condition The condition that the returned value must satisfy.
5769
- */
5770
- last(condition) {
5771
- return _AsyncIterator.last(this, condition);
5822
+ static create(innerIterator, maximumToSkip) {
5823
+ return new _SkipAsyncIterator(innerIterator, maximumToSkip);
5772
5824
  }
5773
- /**
5774
- * If the condition function is undefined, then this function will return the last value in the
5775
- * {@link AsyncIterator}. If this condition function is provided, then this function will return the
5776
- * last value that matches the provided condition.
5777
- * @param iterator The {@link AsyncIterator} to get the last value from.
5778
- */
5779
- static last(iterator, condition) {
5780
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5825
+ next() {
5781
5826
  return PromiseAsyncResult.create(async () => {
5782
- await iterator.start();
5783
- if (!iterator.hasCurrent()) {
5784
- throw new EmptyError();
5785
- }
5786
- let result;
5787
- let found = false;
5788
- do {
5789
- if (!condition || await condition(iterator.getCurrent())) {
5790
- result = iterator.getCurrent();
5791
- found = true;
5792
- }
5793
- } while (await iterator.next());
5794
- if (!found) {
5795
- if (!condition) {
5796
- throw new EmptyError();
5797
- } else {
5798
- throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
5827
+ if (!this.hasStarted()) {
5828
+ this.started = true;
5829
+ await this.innerIterator.start();
5830
+ for (let i = 0; i < this.maximumToSkip; i++) {
5831
+ if (!await this.innerIterator.next()) {
5832
+ break;
5833
+ }
5799
5834
  }
5835
+ } else {
5836
+ await this.innerIterator.next();
5800
5837
  }
5801
- return result;
5838
+ return this.hasCurrent();
5802
5839
  });
5803
5840
  }
5804
- /**
5805
- * Find the maximum value in the provided {@link AsyncIterator}.
5806
- * @param iterator The values to find the maximum of.
5807
- */
5808
- static findMaximum(iterator) {
5809
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterable");
5810
- return PromiseAsyncResult.create(async () => {
5811
- if (isJavascriptAsyncIterator(iterator)) {
5812
- iterator = _AsyncIterator.create(iterator);
5813
- }
5814
- let result = await iterator.first().convertError(EmptyError, () => new EmptyError("Can't find the maximum of an empty Iterator."));
5815
- while (await iterator.next()) {
5816
- const currentValue = iterator.getCurrent();
5817
- if (result.lessThan(currentValue)) {
5818
- result = currentValue;
5819
- }
5820
- }
5821
- return result;
5822
- });
5841
+ hasStarted() {
5842
+ return this.started;
5823
5843
  }
5824
- /**
5825
- * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and only
5826
- * returns a maximum number of values from this {@link AsyncIterator}.
5827
- * @param maximumToTake The maximum number of values to take from this {@link AsyncIterator}.
5828
- */
5829
- take(maximumToTake) {
5830
- return _AsyncIterator.take(this, maximumToTake);
5844
+ hasCurrent() {
5845
+ return this.hasStarted() && this.innerIterator.hasCurrent();
5831
5846
  }
5832
- static take(iterator, maximumToTake) {
5833
- return TakeAsyncIterator.create(iterator, maximumToTake);
5847
+ getCurrent() {
5848
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5849
+ return this.innerIterator.getCurrent();
5834
5850
  }
5835
- /**
5836
- * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and will skip the initial
5837
- * provided number of values before beginning to return values.
5838
- * @param maximumToSkip The maximum number of values to skip from this {@link AsyncIterator}.
5839
- */
5840
- skip(maximumToSkip) {
5841
- return _AsyncIterator.skip(this, maximumToSkip);
5851
+ start() {
5852
+ return AsyncIterator.start(this);
5842
5853
  }
5843
- static skip(iterator, maximumToSkip) {
5844
- return SkipAsyncIterator.create(iterator, maximumToSkip);
5854
+ takeCurrent() {
5855
+ return AsyncIterator.takeCurrent(this);
5845
5856
  }
5846
- };
5847
-
5848
- // sources/basicDisposable.ts
5849
- var SyncDisposable = class _SyncDisposable {
5850
- disposedFunction;
5851
- disposed;
5852
- constructor(disposedFunction) {
5853
- PreCondition.assertNotUndefinedAndNotNull(disposedFunction, "disposedFunction");
5854
- this.disposedFunction = disposedFunction;
5855
- this.disposed = false;
5857
+ any() {
5858
+ return AsyncIterator.any(this);
5856
5859
  }
5857
- /**
5858
- * Create a new {@link Disposable} that will invoke the provided {@link Function} when it is
5859
- * disposed.
5860
- * @param disposedFunction The function to invoke when the returned {@link Disposable} is
5861
- * disposed.
5862
- */
5863
- static create(disposedFunction) {
5864
- return new _SyncDisposable(disposedFunction);
5860
+ getCount() {
5861
+ return AsyncIterator.getCount(this);
5865
5862
  }
5866
- dispose() {
5867
- return SyncResult.create(() => {
5868
- const result = !this.disposed;
5869
- if (result) {
5870
- try {
5871
- this.disposedFunction();
5872
- } finally {
5873
- this.disposed = true;
5874
- }
5875
- }
5876
- return result;
5877
- });
5863
+ toArray() {
5864
+ return AsyncIterator.toArray(this);
5878
5865
  }
5879
- isDisposed() {
5880
- return this.disposed;
5866
+ where(condition) {
5867
+ return AsyncIterator.where(this, condition);
5881
5868
  }
5882
- };
5883
-
5884
- // sources/byteList.ts
5885
- var ByteList = class _ByteList {
5886
- bytes;
5887
- count;
5888
- constructor() {
5889
- this.bytes = new Uint8Array(0);
5890
- this.count = 0;
5869
+ whereInstanceOf(typeCheck) {
5870
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5891
5871
  }
5892
- static create(initialValues) {
5893
- const result = new _ByteList();
5894
- if (initialValues) {
5895
- result.addAll(initialValues);
5896
- }
5897
- return result;
5872
+ whereInstanceOfType(type) {
5873
+ return AsyncIterator.whereInstanceOfType(this, type);
5898
5874
  }
5899
- add(value) {
5900
- return List.add(this, value);
5875
+ map(mapping) {
5876
+ return AsyncIterator.map(this, mapping);
5901
5877
  }
5902
- addAll(values) {
5903
- return List.addAll(this, values);
5904
- }
5905
- insert(index, value) {
5906
- PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
5907
- PreCondition.assertByte(value, "value");
5908
- if (this.count < this.bytes.length) {
5909
- if (index < this.count) {
5910
- this.bytes.copyWithin(index + 1, index, this.count);
5911
- }
5912
- this.bytes[index] = value;
5913
- } else {
5914
- const newCapacity = this.bytes.length * 2 + 1;
5915
- const newBytes = new Uint8Array(newCapacity);
5916
- if (index > 0) {
5917
- newBytes.set(this.bytes.subarray(0, index));
5918
- }
5919
- newBytes[index] = value;
5920
- if (index < this.count) {
5921
- newBytes.set(this.bytes.subarray(index), index + 1);
5922
- }
5923
- this.bytes = newBytes;
5924
- }
5925
- this.count++;
5926
- return this;
5927
- }
5928
- insertAll(index, values) {
5929
- return List.insertAll(this, index, values);
5930
- }
5931
- remove(value, equalFunctions) {
5932
- PreCondition.assertByte(value, "value");
5933
- return List.remove(this, value, equalFunctions);
5934
- }
5935
- removeAt(index) {
5936
- PreCondition.assertAccessIndex(index, this.count, "index");
5937
- const result = this.bytes[index];
5938
- this.bytes.copyWithin(index, index + 1, this.count);
5939
- this.count--;
5940
- return SyncResult.value(result);
5941
- }
5942
- removeFirst() {
5943
- return List.removeFirst(this);
5944
- }
5945
- removeLast() {
5946
- return List.removeLast(this);
5947
- }
5948
- set(index, value) {
5949
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
5950
- PreCondition.assertByte(value, "value");
5951
- this.bytes[index] = value;
5952
- return this;
5953
- }
5954
- iterate() {
5955
- return Iterator.create(this.bytes[Symbol.iterator]().take(this.count));
5956
- }
5957
- get(index) {
5958
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
5959
- return SyncResult.value(this.bytes.at(index));
5960
- }
5961
- toArray() {
5962
- return List.toArray(this);
5963
- }
5964
- any() {
5965
- return this.getCount().then((count) => count > 0);
5966
- }
5967
- getCount() {
5968
- return SyncResult.value(this.count);
5969
- }
5970
- equals(right, equalFunctions) {
5971
- return List.equals(this, right, equalFunctions);
5972
- }
5973
- toString(toStringFunctions) {
5974
- return List.toString(this, toStringFunctions);
5975
- }
5976
- concatenate(...toConcatenate) {
5977
- return List.concatenate(this, ...toConcatenate);
5978
- }
5979
- map(mapping) {
5980
- return List.map(this, mapping);
5981
- }
5982
- flatMap(mapping) {
5983
- return List.flatMap(this, mapping);
5984
- }
5985
- where(condition) {
5986
- return List.where(this, condition);
5987
- }
5988
- instanceOf(typeOrTypeCheck) {
5989
- return List.instanceOf(this, typeOrTypeCheck);
5990
- }
5991
- first(condition) {
5992
- return List.first(this, condition);
5878
+ first(condition) {
5879
+ return AsyncIterator.first(this, condition);
5993
5880
  }
5994
5881
  last(condition) {
5995
- return List.last(this, condition);
5996
- }
5997
- contains(value, equalFunctions) {
5998
- return List.contains(this, value, equalFunctions);
5999
- }
6000
- [Symbol.iterator]() {
6001
- return List[Symbol.iterator](this);
6002
- }
6003
- };
6004
-
6005
- // sources/byteListStream.ts
6006
- var ByteListStream = class _ByteListStream {
6007
- list;
6008
- constructor() {
6009
- this.list = ByteList.create();
6010
- }
6011
- static create(initialValues) {
6012
- const result = new _ByteListStream();
6013
- if (initialValues) {
6014
- result.writeBytes(initialValues).await();
6015
- }
6016
- return result;
5882
+ return AsyncIterator.last(this, condition);
6017
5883
  }
6018
- /**
6019
- * Get the number of bytes that are available to be read.
6020
- */
6021
- getAvailableByteCount() {
6022
- return this.list.getCount().await();
5884
+ [Symbol.asyncIterator]() {
5885
+ return AsyncIterator[Symbol.asyncIterator](this);
6023
5886
  }
6024
- writeBytes(bytes, startIndex, length) {
6025
- PreCondition.assertNotUndefinedAndNotNull(bytes, "bytes");
6026
- if (isArray(bytes)) {
6027
- bytes = new Uint8Array(bytes);
6028
- }
6029
- if (isUndefinedOrNull(startIndex)) {
6030
- startIndex = 0;
6031
- }
6032
- if (isUndefinedOrNull(length)) {
6033
- length = bytes.length - startIndex;
6034
- }
6035
- PreCondition.assertInsertIndex(startIndex, bytes.length, "startIndex");
6036
- PreCondition.assertBetween(0, length, bytes.length - startIndex, "length");
6037
- this.list.addAll(bytes.subarray(startIndex, length + startIndex));
6038
- return SyncResult.value(length);
5887
+ take(maximumToTake) {
5888
+ return AsyncIterator.take(this, maximumToTake);
6039
5889
  }
6040
- readBytes(countOrOutput, startIndex, count) {
6041
- let result;
6042
- if (isNumber(countOrOutput)) {
6043
- PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
6044
- if (!this.list.any().await()) {
6045
- result = SyncResult.error(new EmptyError());
6046
- } else {
6047
- const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
6048
- const output = new Uint8Array(bytesReadCount);
6049
- for (let i = 0; i < bytesReadCount; i++) {
6050
- output[i] = this.list.removeFirst().await();
6051
- }
6052
- result = SyncResult.value(output);
6053
- }
6054
- } else {
6055
- PreCondition.assertNotUndefinedAndNotNull(countOrOutput, "output");
6056
- if (isUndefinedOrNull(startIndex)) {
6057
- startIndex = 0;
6058
- }
6059
- if (isUndefinedOrNull(count)) {
6060
- count = countOrOutput.length - startIndex;
6061
- }
6062
- PreCondition.assertInsertIndex(startIndex, countOrOutput.length, "startIndex");
6063
- PreCondition.assertBetween(0, count, countOrOutput.length - startIndex, "count");
6064
- if (!this.list.any().await()) {
6065
- result = SyncResult.error(new EmptyError());
6066
- } else {
6067
- const bytesReadCount = Math.min(count, this.list.getCount().await());
6068
- for (let i = 0; i < bytesReadCount; i++) {
6069
- countOrOutput[startIndex + i] = this.list.removeFirst().await();
6070
- }
6071
- result = SyncResult.value(bytesReadCount);
6072
- }
6073
- }
6074
- return result;
5890
+ skip(maximumToSkip) {
5891
+ return AsyncIterator.skip(this, maximumToSkip);
6075
5892
  }
6076
5893
  };
6077
5894
 
6078
- // sources/byteReadStream.ts
6079
- var ByteReadStream = class {
6080
- };
6081
-
6082
- // sources/byteWriteStream.ts
6083
- var ByteWriteStream = class {
6084
- };
6085
-
6086
- // sources/stringIterator.ts
6087
- var StringIterator = class _StringIterator {
6088
- value;
6089
- currentIndex;
5895
+ // sources/takeAsyncIterator.ts
5896
+ var TakeAsyncIterator = class _TakeAsyncIterator {
5897
+ innerIterator;
6090
5898
  started;
6091
- constructor(value) {
6092
- this.value = value;
6093
- this.currentIndex = 0;
5899
+ maximumToTake;
5900
+ taken;
5901
+ constructor(innerIterator, maximumToTake) {
5902
+ PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
5903
+ this.innerIterator = innerIterator;
6094
5904
  this.started = false;
5905
+ this.maximumToTake = maximumToTake;
5906
+ this.taken = 0;
6095
5907
  }
6096
- static create(value) {
6097
- PreCondition.assertNotUndefinedAndNotNull(value, "value");
6098
- return new _StringIterator(value);
5908
+ static create(innerIterator, maximumToTake) {
5909
+ return new _TakeAsyncIterator(innerIterator, maximumToTake);
6099
5910
  }
6100
- getCurrentIndex() {
6101
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6102
- return this.currentIndex;
5911
+ hasCurrent() {
5912
+ return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
6103
5913
  }
6104
5914
  next() {
6105
- return SyncResult.create(() => {
6106
- if (!this.hasStarted()) {
5915
+ return PromiseAsyncResult.create(async () => {
5916
+ if (this.maximumToTake <= 0) {
5917
+ return false;
5918
+ } else if (!this.hasStarted()) {
6107
5919
  this.started = true;
6108
- } else if (this.hasCurrent()) {
6109
- this.currentIndex++;
5920
+ await this.innerIterator.start();
5921
+ this.taken++;
5922
+ } else if (this.taken <= this.maximumToTake) {
5923
+ await this.innerIterator.next();
5924
+ this.taken++;
6110
5925
  }
6111
5926
  return this.hasCurrent();
6112
5927
  });
@@ -6114,135 +5929,546 @@ var StringIterator = class _StringIterator {
6114
5929
  hasStarted() {
6115
5930
  return this.started;
6116
5931
  }
6117
- hasCurrent() {
6118
- return this.hasStarted() && this.currentIndex < this.value.length;
6119
- }
6120
5932
  getCurrent() {
6121
5933
  PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6122
- return this.value[this.currentIndex];
5934
+ return this.innerIterator.getCurrent();
6123
5935
  }
6124
5936
  start() {
6125
- return Iterator.start(this);
5937
+ return AsyncIterator.start(this);
6126
5938
  }
6127
5939
  takeCurrent() {
6128
- return Iterator.takeCurrent(this);
5940
+ return AsyncIterator.takeCurrent(this);
6129
5941
  }
6130
5942
  any() {
6131
- return Iterator.any(this);
5943
+ return AsyncIterator.any(this);
6132
5944
  }
6133
5945
  getCount() {
6134
- return Iterator.getCount(this);
5946
+ return AsyncIterator.getCount(this);
6135
5947
  }
6136
5948
  toArray() {
6137
- return Iterator.toArray(this);
6138
- }
6139
- concatenate(...toConcatenate) {
6140
- return Iterator.concatenate(this, ...toConcatenate);
6141
- }
6142
- map(mapping) {
6143
- return Iterator.map(this, mapping);
6144
- }
6145
- flatMap(mapping) {
6146
- return Iterator.flatMap(this, mapping);
6147
- }
6148
- first() {
6149
- return Iterator.first(this);
6150
- }
6151
- last() {
6152
- return Iterator.last(this);
5949
+ return AsyncIterator.toArray(this);
6153
5950
  }
6154
5951
  where(condition) {
6155
- return Iterator.where(this, condition);
5952
+ return AsyncIterator.where(this, condition);
6156
5953
  }
6157
5954
  whereInstanceOf(typeCheck) {
6158
- return Iterator.whereInstanceOf(this, typeCheck);
5955
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
6159
5956
  }
6160
5957
  whereInstanceOfType(type) {
6161
- return Iterator.whereInstanceOfType(this, type);
5958
+ return AsyncIterator.whereInstanceOfType(this, type);
6162
5959
  }
6163
- take(maximumToTake) {
6164
- return Iterator.take(this, maximumToTake);
5960
+ map(mapping) {
5961
+ return AsyncIterator.map(this, mapping);
5962
+ }
5963
+ first(condition) {
5964
+ return AsyncIterator.first(this, condition);
5965
+ }
5966
+ last(condition) {
5967
+ return AsyncIterator.last(this, condition);
5968
+ }
5969
+ [Symbol.asyncIterator]() {
5970
+ return AsyncIterator[Symbol.asyncIterator](this);
5971
+ }
5972
+ take(maximumToTake) {
5973
+ return AsyncIterator.take(this, maximumToTake);
6165
5974
  }
6166
5975
  skip(maximumToSkip) {
6167
- return Iterator.skip(this, maximumToSkip);
5976
+ return AsyncIterator.skip(this, maximumToSkip);
5977
+ }
5978
+ };
5979
+
5980
+ // sources/whereAsyncIterator.ts
5981
+ var WhereAsyncIterator = class _WhereAsyncIterator {
5982
+ innerIterator;
5983
+ started;
5984
+ condition;
5985
+ constructor(innerIterator, condition) {
5986
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5987
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5988
+ this.innerIterator = innerIterator;
5989
+ this.started = false;
5990
+ this.condition = condition;
5991
+ }
5992
+ hasStarted() {
5993
+ return this.started;
5994
+ }
5995
+ hasCurrent() {
5996
+ return this.hasStarted() && this.innerIterator.hasCurrent();
5997
+ }
5998
+ getCurrent() {
5999
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6000
+ return this.innerIterator.getCurrent();
6001
+ }
6002
+ static create(innerIterator, condition) {
6003
+ return new _WhereAsyncIterator(innerIterator, condition);
6004
+ }
6005
+ next() {
6006
+ return PromiseAsyncResult.create(async () => {
6007
+ if (!this.hasStarted()) {
6008
+ await this.innerIterator.start();
6009
+ this.started = true;
6010
+ while (this.hasCurrent() && !await this.condition(this.getCurrent())) {
6011
+ await this.innerIterator.next();
6012
+ }
6013
+ } else {
6014
+ do {
6015
+ await this.innerIterator.next();
6016
+ } while (this.hasCurrent() && !await this.condition(this.getCurrent()));
6017
+ }
6018
+ return this.hasCurrent();
6019
+ });
6020
+ }
6021
+ start() {
6022
+ return AsyncIterator.start(this);
6023
+ }
6024
+ takeCurrent() {
6025
+ return AsyncIterator.takeCurrent(this);
6026
+ }
6027
+ any() {
6028
+ return AsyncIterator.any(this);
6029
+ }
6030
+ getCount() {
6031
+ return AsyncIterator.getCount(this);
6032
+ }
6033
+ toArray() {
6034
+ return AsyncIterator.toArray(this);
6035
+ }
6036
+ where(condition) {
6037
+ return AsyncIterator.where(this, condition);
6038
+ }
6039
+ map(mapping) {
6040
+ return AsyncIterator.map(this, mapping);
6041
+ }
6042
+ whereInstanceOf(typeCheck) {
6043
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
6044
+ }
6045
+ whereInstanceOfType(type) {
6046
+ return AsyncIterator.whereInstanceOfType(this, type);
6047
+ }
6048
+ first(condition) {
6049
+ return AsyncIterator.first(this, condition);
6050
+ }
6051
+ last(condition) {
6052
+ return AsyncIterator.last(this, condition);
6053
+ }
6054
+ take(maximumToTake) {
6055
+ return AsyncIterator.take(this, maximumToTake);
6056
+ }
6057
+ skip(maximumToSkip) {
6058
+ return AsyncIterator.skip(this, maximumToSkip);
6059
+ }
6060
+ [Symbol.asyncIterator]() {
6061
+ return AsyncIterator[Symbol.asyncIterator](this);
6062
+ }
6063
+ };
6064
+
6065
+ // sources/asyncIterator.ts
6066
+ var AsyncIterator = class _AsyncIterator {
6067
+ static create(iterator) {
6068
+ return JavascriptAsyncIteratorToAsyncIteratorAdapter.create(iterator);
6069
+ }
6070
+ /**
6071
+ * Move to the first value if this {@link AsyncIterator} hasn't started yet.
6072
+ * @returns This object for method chaining.
6073
+ */
6074
+ start() {
6075
+ return _AsyncIterator.start(this);
6076
+ }
6077
+ /**
6078
+ * Move the provided {@link AsyncIterator} to its first value if it hasn't started yet.
6079
+ */
6080
+ static start(iterator) {
6081
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6082
+ return PromiseAsyncResult.create(async () => {
6083
+ if (!iterator.hasStarted()) {
6084
+ await iterator.next();
6085
+ }
6086
+ return iterator;
6087
+ });
6088
+ }
6089
+ /**
6090
+ * Get the current value from this {@link AsyncIterator} and advance this {@link AsyncIterator} to the
6091
+ * next value.
6092
+ */
6093
+ takeCurrent() {
6094
+ return _AsyncIterator.takeCurrent(this);
6095
+ }
6096
+ static takeCurrent(iterator) {
6097
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6098
+ PreCondition.assertTrue(iterator.hasCurrent(), "iterator.hasCurrent()");
6099
+ return PromiseAsyncResult.create(async () => {
6100
+ const result = iterator.getCurrent();
6101
+ await iterator.next();
6102
+ return result;
6103
+ });
6104
+ }
6105
+ [Symbol.asyncIterator]() {
6106
+ return _AsyncIterator[Symbol.asyncIterator](this);
6107
+ }
6108
+ /**
6109
+ * Convert the provided {@link AsyncIterator} to a {@link IteratorToJavascriptIteratorAdapter}.
6110
+ * @param iterator The {@link AsyncIterator} to convert.
6111
+ */
6112
+ static [Symbol.asyncIterator](iterator) {
6113
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6114
+ return AsyncIteratorToJavascriptAsyncIteratorAdapter.create(iterator);
6115
+ }
6116
+ /**
6117
+ * Get whether this {@link AsyncIterator} contains any values.
6118
+ * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
6119
+ * started yet.
6120
+ */
6121
+ any() {
6122
+ return _AsyncIterator.any(this);
6123
+ }
6124
+ /**
6125
+ * Get whether this {@link AsyncIterator} contains any values.
6126
+ * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
6127
+ * started yet.
6128
+ */
6129
+ static any(iterator) {
6130
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6131
+ return PromiseAsyncResult.create(async () => {
6132
+ await iterator.start();
6133
+ return iterator.hasCurrent();
6134
+ });
6135
+ }
6136
+ /**
6137
+ * Get the number of values in this {@link AsyncIterator}.
6138
+ * Note: This will consume all of the values in this {@link AsyncIterator}.
6139
+ */
6140
+ getCount() {
6141
+ return _AsyncIterator.getCount(this);
6142
+ }
6143
+ /**
6144
+ * Get the number of values in the provided {@link AsyncIterator}.
6145
+ * Note: This will consume all of the values in the provided {@link AsyncIterator}.
6146
+ */
6147
+ static getCount(iterator) {
6148
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6149
+ return PromiseAsyncResult.create(async () => {
6150
+ let result = 0;
6151
+ if (iterator.hasCurrent()) {
6152
+ result++;
6153
+ }
6154
+ while (await iterator.next()) {
6155
+ result++;
6156
+ }
6157
+ return result;
6158
+ });
6159
+ }
6160
+ /**
6161
+ * Get all of the remaining values in this {@link AsyncIterator} in a {@link T} {@link Array}.
6162
+ */
6163
+ toArray() {
6164
+ return _AsyncIterator.toArray(this);
6165
+ }
6166
+ /**
6167
+ * Get all of the remaining values in the provided {@link AsyncIterator} in a {@link T}
6168
+ * {@link Array}.
6169
+ */
6170
+ static toArray(iterator) {
6171
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6172
+ return PromiseAsyncResult.create(async () => {
6173
+ const result = [];
6174
+ if (iterator.hasCurrent()) {
6175
+ result.push(iterator.getCurrent());
6176
+ }
6177
+ while (await iterator.next()) {
6178
+ result.push(iterator.getCurrent());
6179
+ }
6180
+ return result;
6181
+ });
6182
+ }
6183
+ /**
6184
+ * Get an {@link AsyncIterator} that will only return values that match the provided condition.
6185
+ * @param condition The condition to run against each of the values in this {@link AsyncIterator}.
6186
+ */
6187
+ where(condition) {
6188
+ return _AsyncIterator.where(this, condition);
6189
+ }
6190
+ static where(iterator, condition) {
6191
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6192
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
6193
+ return WhereAsyncIterator.create(iterator, condition);
6194
+ }
6195
+ /**
6196
+ * Get a {@link MapIterator} that will map all {@link T} values from this {@link AsyncIterator} to
6197
+ * {@link TOutput} values.
6198
+ * @param mapping The mapping that maps {@link T} values to {@link TOutput} values.
6199
+ */
6200
+ map(mapping) {
6201
+ return _AsyncIterator.map(this, mapping);
6202
+ }
6203
+ static map(iterator, mapping) {
6204
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6205
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
6206
+ return MapAsyncIterator.create(iterator, mapping);
6207
+ }
6208
+ /**
6209
+ * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
6210
+ * instances of {@link U} based on the provided type check {@link Function}.
6211
+ * @param typeCheck The {@link Function} that will be used to determine if values are of type
6212
+ * {@link U}.
6213
+ */
6214
+ whereInstanceOf(typeCheck) {
6215
+ return _AsyncIterator.whereInstanceOf(this, typeCheck);
6216
+ }
6217
+ static whereInstanceOf(iterator, typeCheck) {
6218
+ PreCondition.assertNotUndefinedAndNotNull(typeCheck, "typeCheck");
6219
+ return iterator.where(typeCheck).map((value) => value);
6220
+ }
6221
+ /**
6222
+ * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
6223
+ * instances of the provided {@link Type}.
6224
+ * @param type The type of values to return from the new {@link AsyncIterator}.
6225
+ */
6226
+ whereInstanceOfType(type) {
6227
+ return _AsyncIterator.whereInstanceOfType(this, type);
6228
+ }
6229
+ static whereInstanceOfType(iterator, type) {
6230
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
6231
+ return iterator.whereInstanceOf((value) => instanceOfType(value, type));
6232
+ }
6233
+ /**
6234
+ * If the condition function is undefined, then this function will return the first value in
6235
+ * this {@link AsyncIterator}. If this condition function is provided, then this function will return
6236
+ * the first value that matches the provided condition.
6237
+ * @param condition The condition that the returned value must satisfy.
6238
+ */
6239
+ first(condition) {
6240
+ return _AsyncIterator.first(this, condition);
6241
+ }
6242
+ /**
6243
+ * If the condition function is undefined, then this function will return the first value in
6244
+ * the {@link AsyncIterator}. If this condition function is provided, then this function will return
6245
+ * the first value that matches the provided condition.
6246
+ * @param iterator The {@link AsyncIterator} to get the first value from.
6247
+ */
6248
+ static first(iterator, condition) {
6249
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6250
+ return PromiseAsyncResult.create(async () => {
6251
+ await iterator.start();
6252
+ if (isUndefinedOrNull(condition)) {
6253
+ if (!iterator.hasCurrent()) {
6254
+ throw new EmptyError();
6255
+ }
6256
+ } else {
6257
+ while (iterator.hasCurrent() && !await condition(iterator.getCurrent())) {
6258
+ await iterator.next();
6259
+ }
6260
+ if (!iterator.hasCurrent()) {
6261
+ throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
6262
+ }
6263
+ }
6264
+ return iterator.getCurrent();
6265
+ });
6266
+ }
6267
+ /**
6268
+ * If the condition function is undefined, then this function will return the last value in this
6269
+ * {@link AsyncIterator}. If this condition function is provided, then this function will return the
6270
+ * last value that matches the provided condition.
6271
+ * @param condition The condition that the returned value must satisfy.
6272
+ */
6273
+ last(condition) {
6274
+ return _AsyncIterator.last(this, condition);
6275
+ }
6276
+ /**
6277
+ * If the condition function is undefined, then this function will return the last value in the
6278
+ * {@link AsyncIterator}. If this condition function is provided, then this function will return the
6279
+ * last value that matches the provided condition.
6280
+ * @param iterator The {@link AsyncIterator} to get the last value from.
6281
+ */
6282
+ static last(iterator, condition) {
6283
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6284
+ return PromiseAsyncResult.create(async () => {
6285
+ await iterator.start();
6286
+ if (!iterator.hasCurrent()) {
6287
+ throw new EmptyError();
6288
+ }
6289
+ let result;
6290
+ let found = false;
6291
+ do {
6292
+ if (!condition || await condition(iterator.getCurrent())) {
6293
+ result = iterator.getCurrent();
6294
+ found = true;
6295
+ }
6296
+ } while (await iterator.next());
6297
+ if (!found) {
6298
+ if (!condition) {
6299
+ throw new EmptyError();
6300
+ } else {
6301
+ throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
6302
+ }
6303
+ }
6304
+ return result;
6305
+ });
6306
+ }
6307
+ /**
6308
+ * Find the maximum value in the provided {@link AsyncIterator}.
6309
+ * @param iterator The values to find the maximum of.
6310
+ */
6311
+ static findMaximum(iterator) {
6312
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterable");
6313
+ return PromiseAsyncResult.create(async () => {
6314
+ if (isJavascriptAsyncIterator(iterator)) {
6315
+ iterator = _AsyncIterator.create(iterator);
6316
+ }
6317
+ let result = await iterator.first().convertError(EmptyError, () => new EmptyError("Can't find the maximum of an empty Iterator."));
6318
+ while (await iterator.next()) {
6319
+ const currentValue = iterator.getCurrent();
6320
+ if (result.lessThan(currentValue)) {
6321
+ result = currentValue;
6322
+ }
6323
+ }
6324
+ return result;
6325
+ });
6326
+ }
6327
+ /**
6328
+ * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and only
6329
+ * returns a maximum number of values from this {@link AsyncIterator}.
6330
+ * @param maximumToTake The maximum number of values to take from this {@link AsyncIterator}.
6331
+ */
6332
+ take(maximumToTake) {
6333
+ return _AsyncIterator.take(this, maximumToTake);
6334
+ }
6335
+ static take(iterator, maximumToTake) {
6336
+ return TakeAsyncIterator.create(iterator, maximumToTake);
6337
+ }
6338
+ /**
6339
+ * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and will skip the initial
6340
+ * provided number of values before beginning to return values.
6341
+ * @param maximumToSkip The maximum number of values to skip from this {@link AsyncIterator}.
6342
+ */
6343
+ skip(maximumToSkip) {
6344
+ return _AsyncIterator.skip(this, maximumToSkip);
6345
+ }
6346
+ static skip(iterator, maximumToSkip) {
6347
+ return SkipAsyncIterator.create(iterator, maximumToSkip);
6348
+ }
6349
+ };
6350
+
6351
+ // sources/basicDisposable.ts
6352
+ var SyncDisposable = class _SyncDisposable {
6353
+ disposedFunction;
6354
+ disposed;
6355
+ constructor(disposedFunction) {
6356
+ PreCondition.assertNotUndefinedAndNotNull(disposedFunction, "disposedFunction");
6357
+ this.disposedFunction = disposedFunction;
6358
+ this.disposed = false;
6359
+ }
6360
+ /**
6361
+ * Create a new {@link Disposable} that will invoke the provided {@link Function} when it is
6362
+ * disposed.
6363
+ * @param disposedFunction The function to invoke when the returned {@link Disposable} is
6364
+ * disposed.
6365
+ */
6366
+ static create(disposedFunction) {
6367
+ return new _SyncDisposable(disposedFunction);
6368
+ }
6369
+ dispose() {
6370
+ return SyncResult.create(() => {
6371
+ const result = !this.disposed;
6372
+ if (result) {
6373
+ try {
6374
+ this.disposedFunction();
6375
+ } finally {
6376
+ this.disposed = true;
6377
+ }
6378
+ }
6379
+ return result;
6380
+ });
6168
6381
  }
6169
- [Symbol.iterator]() {
6170
- return Iterator[Symbol.iterator](this);
6382
+ isDisposed() {
6383
+ return this.disposed;
6171
6384
  }
6172
6385
  };
6173
6386
 
6174
- // sources/characterList.ts
6175
- var CharacterList = class _CharacterList {
6176
- characters;
6177
- constructor(values) {
6178
- if (isString(values)) {
6179
- this.characters = values;
6180
- } else if (values) {
6181
- this.characters = join("", values);
6182
- } else {
6183
- this.characters = "";
6387
+ // sources/byteList.ts
6388
+ var ByteList = class _ByteList {
6389
+ bytes;
6390
+ count;
6391
+ constructor() {
6392
+ this.bytes = new Uint8Array(0);
6393
+ this.count = 0;
6394
+ }
6395
+ static create(initialValues) {
6396
+ const result = new _ByteList();
6397
+ if (initialValues) {
6398
+ result.addAll(initialValues);
6184
6399
  }
6400
+ return result;
6185
6401
  }
6186
- static create(values) {
6187
- return new _CharacterList(values);
6402
+ add(value) {
6403
+ return List.add(this, value);
6188
6404
  }
6189
- getCount() {
6190
- return SyncResult.value(this.characters.length);
6405
+ addAll(values) {
6406
+ return List.addAll(this, values);
6191
6407
  }
6192
6408
  insert(index, value) {
6193
6409
  PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
6194
- PreCondition.assertCharacter(value, "value");
6195
- if (index === 0) {
6196
- this.characters = value + this.characters;
6197
- } else if (index === this.getCount().await()) {
6198
- this.characters += value;
6410
+ PreCondition.assertByte(value, "value");
6411
+ if (this.count < this.bytes.length) {
6412
+ if (index < this.count) {
6413
+ this.bytes.copyWithin(index + 1, index, this.count);
6414
+ }
6415
+ this.bytes[index] = value;
6199
6416
  } else {
6200
- this.characters = this.characters.slice(0, index) + value + this.characters.slice(index);
6417
+ const newCapacity = this.bytes.length * 2 + 1;
6418
+ const newBytes = new Uint8Array(newCapacity);
6419
+ if (index > 0) {
6420
+ newBytes.set(this.bytes.subarray(0, index));
6421
+ }
6422
+ newBytes[index] = value;
6423
+ if (index < this.count) {
6424
+ newBytes.set(this.bytes.subarray(index), index + 1);
6425
+ }
6426
+ this.bytes = newBytes;
6201
6427
  }
6428
+ this.count++;
6202
6429
  return this;
6203
6430
  }
6204
- removeAt(index) {
6205
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6206
- const result = this.get(index).await();
6207
- this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6208
- return SyncResult.value(result);
6209
- }
6210
- set(index, value) {
6211
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6212
- PreCondition.assertCharacter(value, "value");
6213
- this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + value + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6214
- return this;
6215
- }
6216
- iterate() {
6217
- return StringIterator.create(this.characters);
6218
- }
6219
- get(index) {
6220
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6221
- return SyncResult.value(this.characters.charAt(index));
6222
- }
6223
- add(value) {
6224
- return List.add(this, value);
6225
- }
6226
- addAll(values) {
6227
- return List.addAll(this, values);
6228
- }
6229
6431
  insertAll(index, values) {
6230
6432
  return List.insertAll(this, index, values);
6231
6433
  }
6232
6434
  remove(value, equalFunctions) {
6435
+ PreCondition.assertByte(value, "value");
6233
6436
  return List.remove(this, value, equalFunctions);
6234
6437
  }
6438
+ removeAt(index) {
6439
+ PreCondition.assertAccessIndex(index, this.count, "index");
6440
+ const result = this.bytes[index];
6441
+ this.bytes.copyWithin(index, index + 1, this.count);
6442
+ this.count--;
6443
+ return SyncResult.value(result);
6444
+ }
6235
6445
  removeFirst() {
6236
6446
  return List.removeFirst(this);
6237
6447
  }
6238
6448
  removeLast() {
6239
6449
  return List.removeLast(this);
6240
6450
  }
6451
+ set(index, value) {
6452
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6453
+ PreCondition.assertByte(value, "value");
6454
+ this.bytes[index] = value;
6455
+ return this;
6456
+ }
6457
+ iterate() {
6458
+ return Iterator.create(this.bytes[Symbol.iterator]().take(this.count));
6459
+ }
6460
+ get(index) {
6461
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6462
+ return SyncResult.value(this.bytes.at(index));
6463
+ }
6241
6464
  toArray() {
6242
6465
  return List.toArray(this);
6243
6466
  }
6244
6467
  any() {
6245
- return List.any(this);
6468
+ return this.getCount().then((count) => count > 0);
6469
+ }
6470
+ getCount() {
6471
+ return SyncResult.value(this.count);
6246
6472
  }
6247
6473
  equals(right, equalFunctions) {
6248
6474
  return List.equals(this, right, equalFunctions);
@@ -6279,100 +6505,42 @@ var CharacterList = class _CharacterList {
6279
6505
  }
6280
6506
  };
6281
6507
 
6282
- // sources/characterReadStream.ts
6283
- var CharacterReadStream = class _CharacterReadStream {
6284
- readCharacters(count) {
6285
- return _CharacterReadStream.readCharacters(this, count);
6286
- }
6287
- static readCharacters(readStream, count) {
6288
- let characters = "";
6289
- function readUntilCount(countRemaining) {
6290
- return readStream.readCharacter().then((character) => {
6291
- characters += character;
6292
- return countRemaining === 0 ? SyncResult.value(characters) : readUntilCount(countRemaining - 1);
6293
- });
6294
- }
6295
- return readUntilCount(count);
6296
- }
6297
- /**
6298
- * Read characters from this stream until the provided {@link searchString} is found or the end
6299
- * of the stream is reached. The {@link searchString} will be included in the returned string if
6300
- * it is found..
6301
- * @param searchString The string to search for.
6302
- */
6303
- readUntil(searchString) {
6304
- return _CharacterReadStream.readUntil(this, searchString);
6305
- }
6306
- static readUntil(readStream, searchString) {
6307
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6308
- PreCondition.assertNotEmpty(searchString, "searchString");
6309
- let characters = "";
6310
- function readUntilSearchString() {
6311
- return readStream.readCharacter().then((character) => {
6312
- characters += character;
6313
- return characters.endsWith(searchString) ? SyncResult.value(characters) : readUntilSearchString();
6314
- });
6315
- }
6316
- return readUntilSearchString();
6317
- }
6318
- /**
6319
- * Read a sequence of characters from this stream until either a newline character ('\\n') or
6320
- * the end of the stream is reached. Terminating newline characters will be included in the
6321
- * returned string.
6322
- */
6323
- readLine() {
6324
- return _CharacterReadStream.readLine(this);
6325
- }
6326
- static readLine(readStream) {
6327
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6328
- return readStream.readUntil("\n");
6329
- }
6330
- };
6331
-
6332
- // sources/characterListStream.ts
6333
- var CharacterListStream = class _CharacterListStream {
6508
+ // sources/byteListStream.ts
6509
+ var ByteListStream = class _ByteListStream {
6334
6510
  list;
6335
6511
  constructor() {
6336
- this.list = CharacterList.create();
6512
+ this.list = ByteList.create();
6337
6513
  }
6338
6514
  static create(initialValues) {
6339
- const result = new _CharacterListStream();
6515
+ const result = new _ByteListStream();
6340
6516
  if (initialValues) {
6341
- result.writeCharacters(initialValues).await();
6517
+ result.writeBytes(initialValues).await();
6342
6518
  }
6343
6519
  return result;
6344
6520
  }
6345
- writeCharacters(characters, startIndex, length) {
6346
- PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
6347
- const characterString = isString(characters) ? characters : join("", characters);
6521
+ /**
6522
+ * Get the number of bytes that are available to be read.
6523
+ */
6524
+ getAvailableByteCount() {
6525
+ return this.list.getCount().await();
6526
+ }
6527
+ writeBytes(bytes, startIndex, length) {
6528
+ PreCondition.assertNotUndefinedAndNotNull(bytes, "bytes");
6529
+ if (isArray(bytes)) {
6530
+ bytes = new Uint8Array(bytes);
6531
+ }
6348
6532
  if (isUndefinedOrNull(startIndex)) {
6349
6533
  startIndex = 0;
6350
6534
  }
6351
6535
  if (isUndefinedOrNull(length)) {
6352
- length = characterString.length - startIndex;
6536
+ length = bytes.length - startIndex;
6353
6537
  }
6354
- PreCondition.assertInsertIndex(startIndex, characterString.length, "startIndex");
6355
- PreCondition.assertBetween(0, length, characterString.length - startIndex, "length");
6356
- this.list.addAll(characterString.slice(startIndex, length + startIndex));
6538
+ PreCondition.assertInsertIndex(startIndex, bytes.length, "startIndex");
6539
+ PreCondition.assertBetween(0, length, bytes.length - startIndex, "length");
6540
+ this.list.addAll(bytes.subarray(startIndex, length + startIndex));
6357
6541
  return SyncResult.value(length);
6358
6542
  }
6359
- writeString(text) {
6360
- this.list.addAll(text);
6361
- return SyncResult.value(text.length);
6362
- }
6363
- writeLine(text) {
6364
- return CharacterWriteStream.writeLine(this, text);
6365
- }
6366
- /**
6367
- * Get the number of characters that are available to be read.
6368
- */
6369
- getAvailableCharacterCount() {
6370
- return this.list.getCount().await();
6371
- }
6372
- readCharacter() {
6373
- return !this.list.any().await() ? SyncResult.error(new EmptyError()) : SyncResult.value(this.list.removeFirst().await());
6374
- }
6375
- readCharacters(countOrOutput, startIndex, count) {
6543
+ readBytes(countOrOutput, startIndex, count) {
6376
6544
  let result;
6377
6545
  if (isNumber(countOrOutput)) {
6378
6546
  PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
@@ -6380,9 +6548,9 @@ var CharacterListStream = class _CharacterListStream {
6380
6548
  result = SyncResult.error(new EmptyError());
6381
6549
  } else {
6382
6550
  const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
6383
- let output = "";
6551
+ const output = new Uint8Array(bytesReadCount);
6384
6552
  for (let i = 0; i < bytesReadCount; i++) {
6385
- output += this.list.removeFirst().await();
6553
+ output[i] = this.list.removeFirst().await();
6386
6554
  }
6387
6555
  result = SyncResult.value(output);
6388
6556
  }
@@ -6408,32 +6576,41 @@ var CharacterListStream = class _CharacterListStream {
6408
6576
  }
6409
6577
  return result;
6410
6578
  }
6411
- readUntil(searchString) {
6412
- return CharacterReadStream.readUntil(this, searchString);
6413
- }
6414
- readLine() {
6415
- return CharacterReadStream.readLine(this);
6416
- }
6417
6579
  };
6418
6580
 
6419
- // sources/characterReadStreamIterator.ts
6420
- var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6421
- readStream;
6422
- current;
6581
+ // sources/byteReadStream.ts
6582
+ var ByteReadStream = class {
6583
+ };
6584
+
6585
+ // sources/byteWriteStream.ts
6586
+ var ByteWriteStream = class {
6587
+ };
6588
+
6589
+ // sources/stringIterator.ts
6590
+ var StringIterator = class _StringIterator {
6591
+ value;
6592
+ currentIndex;
6423
6593
  started;
6424
- constructor(readStream) {
6425
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6426
- this.readStream = readStream;
6427
- this.current = "";
6594
+ constructor(value) {
6595
+ this.value = value;
6596
+ this.currentIndex = 0;
6428
6597
  this.started = false;
6429
6598
  }
6430
- static create(readStream) {
6431
- return new _CharacterReadStreamAsyncIterator(readStream);
6599
+ static create(value) {
6600
+ PreCondition.assertNotUndefinedAndNotNull(value, "value");
6601
+ return new _StringIterator(value);
6602
+ }
6603
+ getCurrentIndex() {
6604
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6605
+ return this.currentIndex;
6432
6606
  }
6433
6607
  next() {
6434
- return PromiseAsyncResult.create(async () => {
6435
- this.started = true;
6436
- this.current = await this.readStream.readCharacter().catch(NotFoundError, () => "");
6608
+ return SyncResult.create(() => {
6609
+ if (!this.hasStarted()) {
6610
+ this.started = true;
6611
+ } else if (this.hasCurrent()) {
6612
+ this.currentIndex++;
6613
+ }
6437
6614
  return this.hasCurrent();
6438
6615
  });
6439
6616
  }
@@ -6441,638 +6618,712 @@ var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6441
6618
  return this.started;
6442
6619
  }
6443
6620
  hasCurrent() {
6444
- return this.current !== "";
6621
+ return this.hasStarted() && this.currentIndex < this.value.length;
6445
6622
  }
6446
6623
  getCurrent() {
6447
6624
  PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6448
- return this.current;
6625
+ return this.value[this.currentIndex];
6449
6626
  }
6450
6627
  start() {
6451
- return AsyncIterator.start(this);
6628
+ return Iterator.start(this);
6452
6629
  }
6453
6630
  takeCurrent() {
6454
- return AsyncIterator.takeCurrent(this);
6631
+ return Iterator.takeCurrent(this);
6455
6632
  }
6456
6633
  any() {
6457
- return AsyncIterator.any(this);
6634
+ return Iterator.any(this);
6458
6635
  }
6459
6636
  getCount() {
6460
- return AsyncIterator.getCount(this);
6637
+ return Iterator.getCount(this);
6461
6638
  }
6462
6639
  toArray() {
6463
- return AsyncIterator.toArray(this);
6640
+ return Iterator.toArray(this);
6464
6641
  }
6465
- where(condition) {
6466
- return AsyncIterator.where(this, condition);
6642
+ concatenate(...toConcatenate) {
6643
+ return Iterator.concatenate(this, ...toConcatenate);
6467
6644
  }
6468
6645
  map(mapping) {
6469
- return AsyncIterator.map(this, mapping);
6646
+ return Iterator.map(this, mapping);
6470
6647
  }
6471
- whereInstanceOf(typeCheck) {
6472
- return AsyncIterator.whereInstanceOf(this, typeCheck);
6648
+ flatMap(mapping) {
6649
+ return Iterator.flatMap(this, mapping);
6473
6650
  }
6474
- whereInstanceOfType(type) {
6475
- return AsyncIterator.whereInstanceOfType(this, type);
6651
+ first() {
6652
+ return Iterator.first(this);
6476
6653
  }
6477
- first(condition) {
6478
- return AsyncIterator.first(this, condition);
6654
+ last() {
6655
+ return Iterator.last(this);
6479
6656
  }
6480
- last(condition) {
6481
- return AsyncIterator.last(this, condition);
6657
+ where(condition) {
6658
+ return Iterator.where(this, condition);
6659
+ }
6660
+ whereInstanceOf(typeCheck) {
6661
+ return Iterator.whereInstanceOf(this, typeCheck);
6662
+ }
6663
+ whereInstanceOfType(type) {
6664
+ return Iterator.whereInstanceOfType(this, type);
6482
6665
  }
6483
6666
  take(maximumToTake) {
6484
- return AsyncIterator.take(this, maximumToTake);
6667
+ return Iterator.take(this, maximumToTake);
6485
6668
  }
6486
6669
  skip(maximumToSkip) {
6487
- return AsyncIterator.skip(this, maximumToSkip);
6670
+ return Iterator.skip(this, maximumToSkip);
6488
6671
  }
6489
- [Symbol.asyncIterator]() {
6490
- return AsyncIterator[Symbol.asyncIterator](this);
6672
+ [Symbol.iterator]() {
6673
+ return Iterator[Symbol.iterator](this);
6491
6674
  }
6492
6675
  };
6493
6676
 
6494
- // sources/english.ts
6495
- function andList(values) {
6496
- return list("and", values);
6497
- }
6498
- function orList(values) {
6499
- return list("or", values);
6500
- }
6501
- function list(conjunction, values) {
6502
- PreCondition.assertNotEmpty(conjunction, "conjunction");
6503
- PreCondition.assertNotUndefinedAndNotNull(values, "values");
6504
- let result = "";
6505
- let index = 0;
6506
- const iterator = Iterator.create(values).start().await();
6507
- while (iterator.hasCurrent()) {
6508
- const currentValue = iterator.takeCurrent().await();
6509
- if (index >= 1) {
6510
- if (iterator.hasCurrent()) {
6511
- result += `, `;
6512
- } else {
6513
- if (index >= 2) {
6514
- result += `,`;
6515
- }
6516
- result += ` ${conjunction} `;
6517
- }
6677
+ // sources/characterList.ts
6678
+ var CharacterList = class _CharacterList {
6679
+ characters;
6680
+ constructor(values) {
6681
+ if (isString(values)) {
6682
+ this.characters = values;
6683
+ } else if (values) {
6684
+ this.characters = join("", values);
6685
+ } else {
6686
+ this.characters = "";
6518
6687
  }
6519
- result += currentValue;
6520
- index++;
6521
6688
  }
6522
- return result;
6523
- }
6524
-
6525
- // sources/commandLineParameters.ts
6526
- var CommandLineParameters = class _CommandLineParameters {
6527
- args;
6528
- parameters;
6529
- constructor(argv) {
6530
- PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
6531
- this.args = isIterable(argv) ? argv : Iterable.create(argv);
6532
- this.parameters = List.create();
6689
+ static create(values) {
6690
+ return new _CharacterList(values);
6533
6691
  }
6534
- static create(args) {
6535
- return new _CommandLineParameters(args);
6692
+ getCount() {
6693
+ return SyncResult.value(this.characters.length);
6536
6694
  }
6537
- static getArgumentName(arg) {
6538
- return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
6695
+ insert(index, value) {
6696
+ PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
6697
+ PreCondition.assertCharacter(value, "value");
6698
+ if (index === 0) {
6699
+ this.characters = value + this.characters;
6700
+ } else if (index === this.getCount().await()) {
6701
+ this.characters += value;
6702
+ } else {
6703
+ this.characters = this.characters.slice(0, index) + value + this.characters.slice(index);
6704
+ }
6705
+ return this;
6539
6706
  }
6540
- getArguments() {
6541
- return this.args;
6707
+ removeAt(index) {
6708
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6709
+ const result = this.get(index).await();
6710
+ this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6711
+ return SyncResult.value(result);
6542
6712
  }
6543
- /**
6544
- * Get the value of the first argument that matches one of the provided names.
6545
- * @param names The possible names to look for.
6546
- */
6547
- getNamedArgumentStringValue(nameOrNames) {
6548
- PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
6549
- return SyncResult.create(() => {
6550
- let foundArgName = false;
6551
- let result;
6552
- if (isString(nameOrNames)) {
6553
- nameOrNames = [nameOrNames];
6554
- }
6555
- const searchNames = Iterable.create(nameOrNames);
6556
- for (const arg of this.args) {
6557
- if (!foundArgName) {
6558
- const argName = _CommandLineParameters.getArgumentName(arg);
6559
- foundArgName = !!(argName && searchNames.contains(argName));
6560
- } else {
6561
- result = arg;
6562
- break;
6563
- }
6564
- }
6565
- if (result === void 0) {
6566
- const toStringFunctions = ToStringFunctions.create();
6567
- throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
6568
- }
6569
- return result;
6570
- });
6713
+ set(index, value) {
6714
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6715
+ PreCondition.assertCharacter(value, "value");
6716
+ this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + value + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6717
+ return this;
6571
6718
  }
6572
- nameOrAliasExists(nameOrAlias) {
6573
- PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
6574
- let result = false;
6575
- for (const parameter of this.parameters) {
6576
- if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
6577
- result = true;
6578
- break;
6579
- }
6580
- }
6581
- return result;
6719
+ iterate() {
6720
+ return StringIterator.create(this.characters);
6582
6721
  }
6583
- add(name) {
6584
- const result = CommandLineParameter.create({
6585
- owner: this,
6586
- name
6587
- });
6588
- this.parameters.add(result);
6589
- return result;
6722
+ get(index) {
6723
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6724
+ return SyncResult.value(this.characters.charAt(index));
6590
6725
  }
6591
- };
6592
-
6593
- // sources/commandLineParameter.ts
6594
- var CommandLineParameter = class _CommandLineParameter {
6595
- owner;
6596
- name;
6597
- aliases;
6598
- description;
6599
- constructor(owner, name) {
6600
- PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
6601
- PreCondition.assertNotEmpty(name, "name");
6602
- PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
6603
- this.owner = owner;
6604
- this.name = name;
6726
+ add(value) {
6727
+ return List.add(this, value);
6605
6728
  }
6606
- static create(ownerOrProperties, name) {
6607
- let owner;
6608
- if (ownerOrProperties instanceof CommandLineParameters) {
6609
- owner = ownerOrProperties;
6610
- name = name;
6611
- } else {
6612
- owner = ownerOrProperties.owner;
6613
- name = ownerOrProperties.name;
6614
- }
6615
- return new _CommandLineParameter(owner, name);
6729
+ addAll(values) {
6730
+ return List.addAll(this, values);
6616
6731
  }
6617
- /**
6618
- * Get the name of this {@link CommandLineParameter}.
6619
- */
6620
- getName() {
6621
- return this.name;
6732
+ insertAll(index, values) {
6733
+ return List.insertAll(this, index, values);
6622
6734
  }
6623
- getAliases() {
6624
- return this.aliases ?? Iterable.create();
6735
+ remove(value, equalFunctions) {
6736
+ return List.remove(this, value, equalFunctions);
6625
6737
  }
6626
- nameOrAliasExists(nameOrAlias) {
6627
- return this.owner.nameOrAliasExists(nameOrAlias);
6738
+ removeFirst() {
6739
+ return List.removeFirst(this);
6628
6740
  }
6629
- addAlias(alias) {
6630
- PreCondition.assertNotEmpty(alias, "alias");
6631
- PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
6632
- if (this.aliases === void 0) {
6633
- this.aliases = List.create();
6634
- }
6635
- this.aliases.add(alias);
6636
- return this;
6741
+ removeLast() {
6742
+ return List.removeLast(this);
6637
6743
  }
6638
- addAliases(aliases) {
6639
- for (const alias of aliases) {
6640
- this.addAlias(alias);
6641
- }
6642
- return this;
6744
+ toArray() {
6745
+ return List.toArray(this);
6746
+ }
6747
+ any() {
6748
+ return List.any(this);
6749
+ }
6750
+ equals(right, equalFunctions) {
6751
+ return List.equals(this, right, equalFunctions);
6643
6752
  }
6644
- getNameAndAliases() {
6645
- return List.create().add(this.getName()).addAll(this.getAliases());
6753
+ toString(toStringFunctions) {
6754
+ return List.toString(this, toStringFunctions);
6646
6755
  }
6647
- getDescription() {
6648
- return this.description ?? "";
6756
+ concatenate(...toConcatenate) {
6757
+ return List.concatenate(this, ...toConcatenate);
6649
6758
  }
6650
- setDescription(description) {
6651
- PreCondition.assertNotUndefinedAndNotNull(description, "description");
6652
- this.description = description;
6653
- return this;
6759
+ map(mapping) {
6760
+ return List.map(this, mapping);
6654
6761
  }
6655
- };
6656
-
6657
- // sources/comparable.ts
6658
- var Comparable = class _Comparable {
6659
- constructor() {
6762
+ flatMap(mapping) {
6763
+ return List.flatMap(this, mapping);
6660
6764
  }
6661
- /**
6662
- * Get whether this value is less than the provided value.
6663
- * @param value The value to compare against.
6664
- */
6665
- lessThan(value) {
6666
- return _Comparable.lessThan(this, value);
6765
+ where(condition) {
6766
+ return List.where(this, condition);
6667
6767
  }
6668
- /**
6669
- * Get whether the left value is less than the right value.
6670
- * @param left The left value in the comparison.
6671
- * @param right The right value in the comparison.
6672
- */
6673
- static lessThan(left, right) {
6674
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6675
- return left.compareTo(right) === 0 /* LessThan */;
6768
+ instanceOf(typeOrTypeCheck) {
6769
+ return List.instanceOf(this, typeOrTypeCheck);
6676
6770
  }
6677
- /**
6678
- * Get whether this value is less than or equal to the provided value.
6679
- * @param value The value to compare against.
6680
- */
6681
- lessThanOrEqualTo(value) {
6682
- return _Comparable.lessThanOrEqualTo(this, value);
6771
+ first(condition) {
6772
+ return List.first(this, condition);
6683
6773
  }
6684
- /**
6685
- * Get whether the left value is less than or equal to the right value.
6686
- * @param left The left value in the comparison.
6687
- * @param right The right value in the comparison.
6688
- */
6689
- static lessThanOrEqualTo(left, right) {
6690
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6691
- return left.compareTo(right) !== 2 /* GreaterThan */;
6774
+ last(condition) {
6775
+ return List.last(this, condition);
6692
6776
  }
6693
- /**
6694
- * Get whether this value equals the provided value.
6695
- * @param value The value to compare against.
6696
- */
6697
- equals(value) {
6698
- return _Comparable.equals(this, value);
6777
+ contains(value, equalFunctions) {
6778
+ return List.contains(this, value, equalFunctions);
6699
6779
  }
6700
- /**
6701
- * Get whether the left value equals the right value.
6702
- * @param left The left value in the comparison.
6703
- * @param right The right value in the comparison.
6704
- */
6705
- static equals(left, right) {
6706
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6707
- return left.compareTo(right) === 1 /* Equal */;
6780
+ [Symbol.iterator]() {
6781
+ return List[Symbol.iterator](this);
6708
6782
  }
6709
- /**
6710
- * Get whether this value is not equal to the provided value.
6711
- * @param value The value to compare against.
6712
- */
6713
- notEquals(value) {
6714
- return _Comparable.notEquals(this, value);
6783
+ };
6784
+
6785
+ // sources/characterReadStream.ts
6786
+ var CharacterReadStream = class _CharacterReadStream {
6787
+ readCharacters(count) {
6788
+ return _CharacterReadStream.readCharacters(this, count);
6715
6789
  }
6716
- /**
6717
- * Get whether the left value is not equal to the right value.
6718
- * @param left The left value in the comparison.
6719
- * @param right The right value in the comparison.
6720
- */
6721
- static notEquals(left, right) {
6722
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6723
- return left.compareTo(right) !== 1 /* Equal */;
6790
+ static readCharacters(readStream, count) {
6791
+ let characters = "";
6792
+ function readUntilCount(countRemaining) {
6793
+ return readStream.readCharacter().then((character) => {
6794
+ characters += character;
6795
+ return countRemaining === 0 ? SyncResult.value(characters) : readUntilCount(countRemaining - 1);
6796
+ });
6797
+ }
6798
+ return readUntilCount(count);
6724
6799
  }
6725
6800
  /**
6726
- * Get whether this value is greater than or equal to the provided value.
6727
- * @param value The value to compare against.
6801
+ * Read characters from this stream until the provided {@link searchString} is found or the end
6802
+ * of the stream is reached. The {@link searchString} will be included in the returned string if
6803
+ * it is found..
6804
+ * @param searchString The string to search for.
6728
6805
  */
6729
- greaterThanOrEqualTo(value) {
6730
- return _Comparable.greaterThanOrEqualTo(this, value);
6806
+ readUntil(searchString) {
6807
+ return _CharacterReadStream.readUntil(this, searchString);
6731
6808
  }
6732
- /**
6733
- * Get whether the left value is greater than or equal to the right value.
6734
- * @param left The left value in the comparison.
6735
- * @param right The right value in the comparison.
6736
- */
6737
- static greaterThanOrEqualTo(left, right) {
6738
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6739
- return left.compareTo(right) !== 0 /* LessThan */;
6809
+ static readUntil(readStream, searchString) {
6810
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6811
+ PreCondition.assertNotEmpty(searchString, "searchString");
6812
+ let characters = "";
6813
+ function readUntilSearchString() {
6814
+ return readStream.readCharacter().then((character) => {
6815
+ characters += character;
6816
+ return characters.endsWith(searchString) ? SyncResult.value(characters) : readUntilSearchString();
6817
+ });
6818
+ }
6819
+ return readUntilSearchString();
6740
6820
  }
6741
6821
  /**
6742
- * Get whether this value is greater than the provided value.
6743
- * @param value The value to compare against.
6822
+ * Read a sequence of characters from this stream until either a newline character ('\\n') or
6823
+ * the end of the stream is reached. Terminating newline characters will be included in the
6824
+ * returned string.
6744
6825
  */
6745
- greaterThan(value) {
6746
- return _Comparable.greaterThan(this, value);
6826
+ readLine() {
6827
+ return _CharacterReadStream.readLine(this);
6747
6828
  }
6748
- /**
6749
- * Get whether the left value is greater than the right value.
6750
- * @param left The left value in the comparison.
6751
- * @param right The right value in the comparison.
6752
- */
6753
- static greaterThan(left, right) {
6754
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6755
- return left.compareTo(right) === 2 /* GreaterThan */;
6829
+ static readLine(readStream) {
6830
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6831
+ return readStream.readUntil("\n");
6756
6832
  }
6757
6833
  };
6758
6834
 
6759
- // sources/nodeJSCharacterWriteStream.ts
6760
- var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
6761
- nodeJSWriteStream;
6762
- constructor(nodeJSWriteStream) {
6763
- PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
6764
- super();
6765
- this.nodeJSWriteStream = nodeJSWriteStream;
6835
+ // sources/characterListStream.ts
6836
+ var CharacterListStream = class _CharacterListStream {
6837
+ list;
6838
+ constructor() {
6839
+ this.list = CharacterList.create();
6766
6840
  }
6767
- static create(nodeJSWriteStream) {
6768
- return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
6841
+ static create(initialValues) {
6842
+ const result = new _CharacterListStream();
6843
+ if (initialValues) {
6844
+ result.writeCharacters(initialValues).await();
6845
+ }
6846
+ return result;
6847
+ }
6848
+ writeCharacters(characters, startIndex, length) {
6849
+ PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
6850
+ const characterString = isString(characters) ? characters : join("", characters);
6851
+ if (isUndefinedOrNull(startIndex)) {
6852
+ startIndex = 0;
6853
+ }
6854
+ if (isUndefinedOrNull(length)) {
6855
+ length = characterString.length - startIndex;
6856
+ }
6857
+ PreCondition.assertInsertIndex(startIndex, characterString.length, "startIndex");
6858
+ PreCondition.assertBetween(0, length, characterString.length - startIndex, "length");
6859
+ this.list.addAll(characterString.slice(startIndex, length + startIndex));
6860
+ return SyncResult.value(length);
6769
6861
  }
6770
6862
  writeString(text) {
6771
- PreCondition.assertNotUndefinedAndNotNull(text, "text");
6772
- return PromiseAsyncResult.create(new Promise((resolve, reject) => {
6773
- this.nodeJSWriteStream.write(text, (error) => {
6774
- if (error) {
6775
- reject(error);
6776
- } else {
6777
- resolve(text.length);
6778
- }
6779
- });
6780
- }));
6863
+ this.list.addAll(text);
6864
+ return SyncResult.value(text.length);
6781
6865
  }
6782
- };
6783
-
6784
- // sources/property.ts
6785
- var Property = class _Property {
6786
- getter;
6787
- setter;
6788
- constructor(getter, setter) {
6789
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
6790
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
6791
- this.getter = getter;
6792
- this.setter = setter;
6866
+ writeLine(text) {
6867
+ return CharacterWriteStream.writeLine(this, text);
6793
6868
  }
6794
- static create(getterOptionsOrInitialValue, setter) {
6795
- let getter;
6796
- if (isFunction(getterOptionsOrInitialValue)) {
6797
- getter = getterOptionsOrInitialValue;
6798
- } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
6799
- const options = getterOptionsOrInitialValue;
6800
- getter = options.getter;
6801
- setter = options.setter;
6869
+ /**
6870
+ * Get the number of characters that are available to be read.
6871
+ */
6872
+ getAvailableCharacterCount() {
6873
+ return this.list.getCount().await();
6874
+ }
6875
+ readCharacter() {
6876
+ return !this.list.any().await() ? SyncResult.error(new EmptyError()) : SyncResult.value(this.list.removeFirst().await());
6877
+ }
6878
+ readCharacters(countOrOutput, startIndex, count) {
6879
+ let result;
6880
+ if (isNumber(countOrOutput)) {
6881
+ PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
6882
+ if (!this.list.any().await()) {
6883
+ result = SyncResult.error(new EmptyError());
6884
+ } else {
6885
+ const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
6886
+ let output = "";
6887
+ for (let i = 0; i < bytesReadCount; i++) {
6888
+ output += this.list.removeFirst().await();
6889
+ }
6890
+ result = SyncResult.value(output);
6891
+ }
6802
6892
  } else {
6803
- let initialValue = getterOptionsOrInitialValue;
6804
- getter = () => {
6805
- return initialValue;
6806
- };
6807
- setter = (value) => {
6808
- initialValue = value;
6809
- };
6893
+ PreCondition.assertNotUndefinedAndNotNull(countOrOutput, "output");
6894
+ if (isUndefinedOrNull(startIndex)) {
6895
+ startIndex = 0;
6896
+ }
6897
+ if (isUndefinedOrNull(count)) {
6898
+ count = countOrOutput.length - startIndex;
6899
+ }
6900
+ PreCondition.assertInsertIndex(startIndex, countOrOutput.length, "startIndex");
6901
+ PreCondition.assertBetween(0, count, countOrOutput.length - startIndex, "count");
6902
+ if (!this.list.any().await()) {
6903
+ result = SyncResult.error(new EmptyError());
6904
+ } else {
6905
+ const bytesReadCount = Math.min(count, this.list.getCount().await());
6906
+ for (let i = 0; i < bytesReadCount; i++) {
6907
+ countOrOutput[startIndex + i] = this.list.removeFirst().await();
6908
+ }
6909
+ result = SyncResult.value(bytesReadCount);
6910
+ }
6810
6911
  }
6811
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
6812
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
6813
- return new _Property(getter, setter);
6814
- }
6815
- getValue() {
6816
- return this.getter();
6912
+ return result;
6817
6913
  }
6818
- setValue(value) {
6819
- this.setter(value);
6820
- return this;
6914
+ readUntil(searchString) {
6915
+ return CharacterReadStream.readUntil(this, searchString);
6821
6916
  }
6822
- toString() {
6823
- return `${this.getValue()}`;
6917
+ readLine() {
6918
+ return CharacterReadStream.readLine(this);
6824
6919
  }
6825
6920
  };
6826
6921
 
6827
- // sources/httpHeader.ts
6828
- var HttpHeader = class _HttpHeader {
6829
- name;
6830
- value;
6831
- constructor(name, value) {
6832
- PreCondition.assertNotEmpty(name, "name");
6833
- PreCondition.assertNotUndefinedAndNotNull(value, "value");
6834
- this.name = name;
6835
- this.value = value;
6836
- }
6837
- static create(name, value) {
6838
- return new _HttpHeader(name, value);
6922
+ // sources/characterReadStreamIterator.ts
6923
+ var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6924
+ readStream;
6925
+ current;
6926
+ started;
6927
+ constructor(readStream) {
6928
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6929
+ this.readStream = readStream;
6930
+ this.current = "";
6931
+ this.started = false;
6839
6932
  }
6840
- getName() {
6841
- return this.name;
6933
+ static create(readStream) {
6934
+ return new _CharacterReadStreamAsyncIterator(readStream);
6842
6935
  }
6843
- getValue() {
6844
- return this.value;
6936
+ next() {
6937
+ return PromiseAsyncResult.create(async () => {
6938
+ this.started = true;
6939
+ this.current = await this.readStream.readCharacter().catch(NotFoundError, () => "");
6940
+ return this.hasCurrent();
6941
+ });
6845
6942
  }
6846
- toString() {
6847
- return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
6943
+ hasStarted() {
6944
+ return this.started;
6848
6945
  }
6849
- };
6850
-
6851
- // sources/mutableHttpHeaders.ts
6852
- var MutableHttpHeaders = class _MutableHttpHeaders {
6853
- headers;
6854
- constructor(headers) {
6855
- this.headers = List.create();
6856
- if (headers) {
6857
- this.setAll(headers);
6858
- }
6946
+ hasCurrent() {
6947
+ return this.current !== "";
6859
6948
  }
6860
- static create(headers) {
6861
- return new _MutableHttpHeaders(headers);
6949
+ getCurrent() {
6950
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6951
+ return this.current;
6862
6952
  }
6863
- iterate() {
6864
- return this.headers.iterate();
6953
+ start() {
6954
+ return AsyncIterator.start(this);
6865
6955
  }
6866
- get(headerName) {
6867
- PreCondition.assertNotEmpty(headerName, "headerName");
6868
- return SyncResult.create(() => {
6869
- let result;
6870
- const lowerHeaderName = headerName.toLowerCase();
6871
- for (const header of this.headers) {
6872
- if (header.getName().toLowerCase() === lowerHeaderName) {
6873
- result = header;
6874
- break;
6875
- }
6876
- }
6877
- if (result === void 0) {
6878
- throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
6879
- }
6880
- return result;
6881
- });
6956
+ takeCurrent() {
6957
+ return AsyncIterator.takeCurrent(this);
6882
6958
  }
6883
- getValue(headerName) {
6884
- return this.get(headerName).then((header) => header.getValue());
6959
+ any() {
6960
+ return AsyncIterator.any(this);
6885
6961
  }
6886
- set(headerOrHeaderName, headerValue) {
6887
- let headerName;
6888
- if (isString(headerOrHeaderName)) {
6889
- headerName = headerOrHeaderName;
6890
- } else {
6891
- headerName = headerOrHeaderName.getName();
6892
- headerValue = headerOrHeaderName.getValue();
6893
- }
6894
- PreCondition.assertNotEmpty(headerName, "headerName");
6895
- PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
6896
- let insertIndex = 0;
6897
- for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
6898
- const header = this.headers.get(insertIndex2).await();
6899
- if (header.getName() === headerName) {
6900
- this.headers.removeAt(insertIndex2);
6901
- break;
6902
- }
6903
- }
6904
- this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
6905
- return this;
6962
+ getCount() {
6963
+ return AsyncIterator.getCount(this);
6906
6964
  }
6907
- setAll(headers) {
6908
- PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
6909
- for (const header of headers) {
6910
- this.set(header);
6911
- }
6912
- return this;
6965
+ toArray() {
6966
+ return AsyncIterator.toArray(this);
6913
6967
  }
6914
- setContentType(contentType) {
6915
- return this.set(HttpHeaders.contentTypeHeaderName, contentType);
6968
+ where(condition) {
6969
+ return AsyncIterator.where(this, condition);
6916
6970
  }
6917
- getContentType() {
6918
- return this.get(HttpHeaders.contentTypeHeaderName);
6971
+ map(mapping) {
6972
+ return AsyncIterator.map(this, mapping);
6919
6973
  }
6920
- getContentTypeValue() {
6921
- return this.getValue(HttpHeaders.contentTypeHeaderName);
6974
+ whereInstanceOf(typeCheck) {
6975
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
6922
6976
  }
6923
- getCount() {
6924
- return this.headers.getCount();
6977
+ whereInstanceOfType(type) {
6978
+ return AsyncIterator.whereInstanceOfType(this, type);
6925
6979
  }
6926
- toArray() {
6927
- return HttpHeaders.toArray(this);
6980
+ first(condition) {
6981
+ return AsyncIterator.first(this, condition);
6928
6982
  }
6929
- any() {
6930
- return HttpHeaders.any(this);
6983
+ last(condition) {
6984
+ return AsyncIterator.last(this, condition);
6931
6985
  }
6932
- equals(right, equalFunctions) {
6933
- return HttpHeaders.equals(this, right, equalFunctions);
6986
+ take(maximumToTake) {
6987
+ return AsyncIterator.take(this, maximumToTake);
6934
6988
  }
6935
- toString(toStringFunctions) {
6936
- return HttpHeaders.toString(this, toStringFunctions);
6989
+ skip(maximumToSkip) {
6990
+ return AsyncIterator.skip(this, maximumToSkip);
6937
6991
  }
6938
- concatenate(...toConcatenate) {
6939
- return HttpHeaders.concatenate(this, ...toConcatenate);
6992
+ [Symbol.asyncIterator]() {
6993
+ return AsyncIterator[Symbol.asyncIterator](this);
6940
6994
  }
6941
- map(mapping) {
6942
- return HttpHeaders.map(this, mapping);
6995
+ };
6996
+
6997
+ // sources/english.ts
6998
+ function andList(values) {
6999
+ return list("and", values);
7000
+ }
7001
+ function orList(values) {
7002
+ return list("or", values);
7003
+ }
7004
+ function list(conjunction, values) {
7005
+ PreCondition.assertNotEmpty(conjunction, "conjunction");
7006
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
7007
+ let result = "";
7008
+ let index = 0;
7009
+ const iterator = Iterator.create(values).start().await();
7010
+ while (iterator.hasCurrent()) {
7011
+ const currentValue = iterator.takeCurrent().await();
7012
+ if (index >= 1) {
7013
+ if (iterator.hasCurrent()) {
7014
+ result += `, `;
7015
+ } else {
7016
+ if (index >= 2) {
7017
+ result += `,`;
7018
+ }
7019
+ result += ` ${conjunction} `;
7020
+ }
7021
+ }
7022
+ result += currentValue;
7023
+ index++;
6943
7024
  }
6944
- flatMap(mapping) {
6945
- return HttpHeaders.flatMap(this, mapping);
7025
+ return result;
7026
+ }
7027
+
7028
+ // sources/commandLineParameters.ts
7029
+ var CommandLineParameters = class _CommandLineParameters {
7030
+ args;
7031
+ parameters;
7032
+ constructor(argv) {
7033
+ PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
7034
+ this.args = isIterable(argv) ? argv : Iterable.create(argv);
7035
+ this.parameters = List.create();
6946
7036
  }
6947
- where(condition) {
6948
- return HttpHeaders.where(this, condition);
7037
+ static create(args) {
7038
+ return new _CommandLineParameters(args);
6949
7039
  }
6950
- instanceOf(typeOrTypeCheck) {
6951
- return HttpHeaders.instanceOf(this, typeOrTypeCheck);
7040
+ static getArgumentName(arg) {
7041
+ return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
6952
7042
  }
6953
- first(condition) {
6954
- return HttpHeaders.first(this, condition);
7043
+ getArguments() {
7044
+ return this.args;
6955
7045
  }
6956
- last(condition) {
6957
- return HttpHeaders.last(this, condition);
7046
+ /**
7047
+ * Get the value of the first argument that matches one of the provided names.
7048
+ * @param names The possible names to look for.
7049
+ */
7050
+ getNamedArgumentStringValue(nameOrNames) {
7051
+ PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
7052
+ return SyncResult.create(() => {
7053
+ let foundArgName = false;
7054
+ let result;
7055
+ if (isString(nameOrNames)) {
7056
+ nameOrNames = [nameOrNames];
7057
+ }
7058
+ const searchNames = Iterable.create(nameOrNames);
7059
+ for (const arg of this.args) {
7060
+ if (!foundArgName) {
7061
+ const argName = _CommandLineParameters.getArgumentName(arg);
7062
+ foundArgName = !!(argName && searchNames.contains(argName));
7063
+ } else {
7064
+ result = arg;
7065
+ break;
7066
+ }
7067
+ }
7068
+ if (result === void 0) {
7069
+ const toStringFunctions = ToStringFunctions.create();
7070
+ throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
7071
+ }
7072
+ return result;
7073
+ });
6958
7074
  }
6959
- [Symbol.iterator]() {
6960
- return HttpHeaders[Symbol.iterator](this);
7075
+ nameOrAliasExists(nameOrAlias) {
7076
+ PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
7077
+ let result = false;
7078
+ for (const parameter of this.parameters) {
7079
+ if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
7080
+ result = true;
7081
+ break;
7082
+ }
7083
+ }
7084
+ return result;
6961
7085
  }
6962
- contains(value, equalFunctions) {
6963
- return HttpHeaders.contains(this, value, equalFunctions);
7086
+ add(name) {
7087
+ const result = CommandLineParameter.create({
7088
+ owner: this,
7089
+ name
7090
+ });
7091
+ this.parameters.add(result);
7092
+ return result;
6964
7093
  }
6965
7094
  };
6966
7095
 
6967
- // sources/httpHeaders.ts
6968
- var HttpHeaders = class _HttpHeaders {
6969
- static contentTypeHeaderName = "Content-Type";
6970
- static create(headers) {
6971
- return MutableHttpHeaders.create(headers);
6972
- }
6973
- getContentType() {
6974
- return _HttpHeaders.getContentType(this);
6975
- }
6976
- static getContentType(headers) {
6977
- return headers.get(_HttpHeaders.contentTypeHeaderName);
6978
- }
6979
- getContentTypeValue() {
6980
- return _HttpHeaders.getContentTypeValue(this);
7096
+ // sources/commandLineParameter.ts
7097
+ var CommandLineParameter = class _CommandLineParameter {
7098
+ owner;
7099
+ name;
7100
+ aliases;
7101
+ description;
7102
+ constructor(owner, name) {
7103
+ PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
7104
+ PreCondition.assertNotEmpty(name, "name");
7105
+ PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
7106
+ this.owner = owner;
7107
+ this.name = name;
6981
7108
  }
6982
- static getContentTypeValue(headers) {
6983
- return headers.getValue(_HttpHeaders.contentTypeHeaderName);
7109
+ static create(ownerOrProperties, name) {
7110
+ let owner;
7111
+ if (ownerOrProperties instanceof CommandLineParameters) {
7112
+ owner = ownerOrProperties;
7113
+ name = name;
7114
+ } else {
7115
+ owner = ownerOrProperties.owner;
7116
+ name = ownerOrProperties.name;
7117
+ }
7118
+ return new _CommandLineParameter(owner, name);
6984
7119
  }
6985
7120
  /**
6986
- * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
7121
+ * Get the name of this {@link CommandLineParameter}.
6987
7122
  */
6988
- toArray() {
6989
- return _HttpHeaders.toArray(this);
7123
+ getName() {
7124
+ return this.name;
6990
7125
  }
6991
- static toArray(headers) {
6992
- return Iterable.toArray(headers);
7126
+ getAliases() {
7127
+ return this.aliases ?? Iterable.create();
6993
7128
  }
6994
- any() {
6995
- return _HttpHeaders.any(this);
7129
+ nameOrAliasExists(nameOrAlias) {
7130
+ return this.owner.nameOrAliasExists(nameOrAlias);
6996
7131
  }
6997
- static any(headers) {
6998
- return Iterable.any(headers);
7132
+ addAlias(alias) {
7133
+ PreCondition.assertNotEmpty(alias, "alias");
7134
+ PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
7135
+ if (this.aliases === void 0) {
7136
+ this.aliases = List.create();
7137
+ }
7138
+ this.aliases.add(alias);
7139
+ return this;
6999
7140
  }
7000
- getCount() {
7001
- return _HttpHeaders.getCount(this);
7141
+ addAliases(aliases) {
7142
+ for (const alias of aliases) {
7143
+ this.addAlias(alias);
7144
+ }
7145
+ return this;
7002
7146
  }
7003
- static getCount(headers) {
7004
- return Iterable.getCount(headers);
7147
+ getNameAndAliases() {
7148
+ return List.create().add(this.getName()).addAll(this.getAliases());
7005
7149
  }
7006
- equals(right, equalFunctions) {
7007
- return _HttpHeaders.equals(this, right, equalFunctions);
7150
+ getDescription() {
7151
+ return this.description ?? "";
7008
7152
  }
7009
- static equals(headers, right, equalFunctions) {
7010
- return Iterable.equals(headers, right, equalFunctions);
7153
+ setDescription(description) {
7154
+ PreCondition.assertNotUndefinedAndNotNull(description, "description");
7155
+ this.description = description;
7156
+ return this;
7011
7157
  }
7012
- toString(toStringFunctions) {
7013
- return _HttpHeaders.toString(this, toStringFunctions);
7158
+ };
7159
+
7160
+ // sources/comparable.ts
7161
+ var Comparable = class _Comparable {
7162
+ constructor() {
7014
7163
  }
7015
- static toString(headers, toStringFunctions) {
7016
- return Iterable.toString(headers, toStringFunctions);
7164
+ /**
7165
+ * Get whether this value is less than the provided value.
7166
+ * @param value The value to compare against.
7167
+ */
7168
+ lessThan(value) {
7169
+ return _Comparable.lessThan(this, value);
7017
7170
  }
7018
- concatenate(...toConcatenate) {
7019
- return _HttpHeaders.concatenate(this, ...toConcatenate);
7171
+ /**
7172
+ * Get whether the left value is less than the right value.
7173
+ * @param left The left value in the comparison.
7174
+ * @param right The right value in the comparison.
7175
+ */
7176
+ static lessThan(left, right) {
7177
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7178
+ return left.compareTo(right) === 0 /* LessThan */;
7020
7179
  }
7021
- static concatenate(headers, ...toConcatenate) {
7022
- return Iterable.concatenate(headers, ...toConcatenate);
7180
+ /**
7181
+ * Get whether this value is less than or equal to the provided value.
7182
+ * @param value The value to compare against.
7183
+ */
7184
+ lessThanOrEqualTo(value) {
7185
+ return _Comparable.lessThanOrEqualTo(this, value);
7023
7186
  }
7024
- map(mapping) {
7025
- return _HttpHeaders.map(this, mapping);
7187
+ /**
7188
+ * Get whether the left value is less than or equal to the right value.
7189
+ * @param left The left value in the comparison.
7190
+ * @param right The right value in the comparison.
7191
+ */
7192
+ static lessThanOrEqualTo(left, right) {
7193
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7194
+ return left.compareTo(right) !== 2 /* GreaterThan */;
7026
7195
  }
7027
- static map(headers, mapping) {
7028
- return Iterable.map(headers, mapping);
7196
+ /**
7197
+ * Get whether this value equals the provided value.
7198
+ * @param value The value to compare against.
7199
+ */
7200
+ equals(value) {
7201
+ return _Comparable.equals(this, value);
7029
7202
  }
7030
- flatMap(mapping) {
7031
- return _HttpHeaders.flatMap(this, mapping);
7203
+ /**
7204
+ * Get whether the left value equals the right value.
7205
+ * @param left The left value in the comparison.
7206
+ * @param right The right value in the comparison.
7207
+ */
7208
+ static equals(left, right) {
7209
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7210
+ return left.compareTo(right) === 1 /* Equal */;
7032
7211
  }
7033
- static flatMap(headers, mapping) {
7034
- return Iterable.flatMap(headers, mapping);
7212
+ /**
7213
+ * Get whether this value is not equal to the provided value.
7214
+ * @param value The value to compare against.
7215
+ */
7216
+ notEquals(value) {
7217
+ return _Comparable.notEquals(this, value);
7035
7218
  }
7036
- where(condition) {
7037
- return _HttpHeaders.where(this, condition);
7219
+ /**
7220
+ * Get whether the left value is not equal to the right value.
7221
+ * @param left The left value in the comparison.
7222
+ * @param right The right value in the comparison.
7223
+ */
7224
+ static notEquals(left, right) {
7225
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7226
+ return left.compareTo(right) !== 1 /* Equal */;
7038
7227
  }
7039
- static where(headers, condition) {
7040
- return Iterable.where(headers, condition);
7228
+ /**
7229
+ * Get whether this value is greater than or equal to the provided value.
7230
+ * @param value The value to compare against.
7231
+ */
7232
+ greaterThanOrEqualTo(value) {
7233
+ return _Comparable.greaterThanOrEqualTo(this, value);
7041
7234
  }
7042
- instanceOf(typeOrTypeCheck) {
7043
- return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
7235
+ /**
7236
+ * Get whether the left value is greater than or equal to the right value.
7237
+ * @param left The left value in the comparison.
7238
+ * @param right The right value in the comparison.
7239
+ */
7240
+ static greaterThanOrEqualTo(left, right) {
7241
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7242
+ return left.compareTo(right) !== 0 /* LessThan */;
7044
7243
  }
7045
- static instanceOf(headers, typeOrTypeCheck) {
7046
- return Iterable.instanceOf(headers, typeOrTypeCheck);
7244
+ /**
7245
+ * Get whether this value is greater than the provided value.
7246
+ * @param value The value to compare against.
7247
+ */
7248
+ greaterThan(value) {
7249
+ return _Comparable.greaterThan(this, value);
7047
7250
  }
7048
- first(condition) {
7049
- return _HttpHeaders.first(this, condition);
7251
+ /**
7252
+ * Get whether the left value is greater than the right value.
7253
+ * @param left The left value in the comparison.
7254
+ * @param right The right value in the comparison.
7255
+ */
7256
+ static greaterThan(left, right) {
7257
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7258
+ return left.compareTo(right) === 2 /* GreaterThan */;
7050
7259
  }
7051
- static first(headers, condition) {
7052
- return Iterable.first(headers, condition);
7260
+ };
7261
+
7262
+ // sources/nodeJSCharacterWriteStream.ts
7263
+ var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
7264
+ nodeJSWriteStream;
7265
+ constructor(nodeJSWriteStream) {
7266
+ PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
7267
+ super();
7268
+ this.nodeJSWriteStream = nodeJSWriteStream;
7053
7269
  }
7054
- last(condition) {
7055
- return _HttpHeaders.last(this, condition);
7270
+ static create(nodeJSWriteStream) {
7271
+ return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
7056
7272
  }
7057
- static last(headers, condition) {
7058
- return Iterable.last(headers, condition);
7273
+ writeString(text) {
7274
+ PreCondition.assertNotUndefinedAndNotNull(text, "text");
7275
+ return PromiseAsyncResult.create(new Promise((resolve, reject) => {
7276
+ this.nodeJSWriteStream.write(text, (error) => {
7277
+ if (error) {
7278
+ reject(error);
7279
+ } else {
7280
+ resolve(text.length);
7281
+ }
7282
+ });
7283
+ }));
7284
+ }
7285
+ };
7286
+
7287
+ // sources/property.ts
7288
+ var Property = class _Property {
7289
+ getter;
7290
+ setter;
7291
+ constructor(getter, setter) {
7292
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
7293
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
7294
+ this.getter = getter;
7295
+ this.setter = setter;
7059
7296
  }
7060
- [Symbol.iterator]() {
7061
- return _HttpHeaders[Symbol.iterator](this);
7297
+ static create(getterOptionsOrInitialValue, setter) {
7298
+ let getter;
7299
+ if (isFunction(getterOptionsOrInitialValue)) {
7300
+ getter = getterOptionsOrInitialValue;
7301
+ } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
7302
+ const options = getterOptionsOrInitialValue;
7303
+ getter = options.getter;
7304
+ setter = options.setter;
7305
+ } else {
7306
+ let initialValue = getterOptionsOrInitialValue;
7307
+ getter = () => {
7308
+ return initialValue;
7309
+ };
7310
+ setter = (value) => {
7311
+ initialValue = value;
7312
+ };
7313
+ }
7314
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
7315
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
7316
+ return new _Property(getter, setter);
7062
7317
  }
7063
- static [Symbol.iterator](headers) {
7064
- return Iterable[Symbol.iterator](headers);
7318
+ getValue() {
7319
+ return this.getter();
7065
7320
  }
7066
- contains(value, equalFunctions) {
7067
- return _HttpHeaders.contains(this, value, equalFunctions);
7321
+ setValue(value) {
7322
+ this.setter(value);
7323
+ return this;
7068
7324
  }
7069
- static contains(headers, value, equalFunctions) {
7070
- return SyncResult.create(() => {
7071
- if (!equalFunctions) {
7072
- equalFunctions = EqualFunctions.create();
7073
- }
7074
- return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
7075
- });
7325
+ toString() {
7326
+ return `${this.getValue()}`;
7076
7327
  }
7077
7328
  };
7078
7329
 
@@ -7317,14 +7568,27 @@ var FetchHttpClient = class _FetchHttpClient {
7317
7568
  }
7318
7569
  sendRequest(request) {
7319
7570
  PreCondition.assertNotUndefinedAndNotNull(request, "request");
7320
- return PromiseAsyncResult.create(async () => {
7571
+ return AsyncResult.create(async () => {
7572
+ const fetchURL = request.getURL();
7573
+ const fetchMethod = _FetchHttpClient.convertMethod(request.getMethod());
7574
+ const fetchHeaders = request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await();
7575
+ const fetchBody = request.getBody() || void 0;
7321
7576
  const requestInit = {
7322
- method: _FetchHttpClient.convertMethod(request.getMethod()),
7323
- headers: request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await(),
7324
- body: request.getBody() || void 0
7577
+ method: fetchMethod,
7578
+ headers: fetchHeaders,
7579
+ body: fetchBody
7325
7580
  };
7326
- const fetchResponse = await fetch(request.getURL(), requestInit);
7327
- return FetchHttpIncomingResponse.create(fetchResponse);
7581
+ let result;
7582
+ try {
7583
+ const fetchResponse = await fetch(fetchURL, requestInit);
7584
+ result = FetchHttpIncomingResponse.create(fetchResponse);
7585
+ } catch (error) {
7586
+ if (error instanceof Error && error.cause instanceof Error) {
7587
+ throw new FetchError(error.cause);
7588
+ }
7589
+ throw error;
7590
+ }
7591
+ return result;
7328
7592
  });
7329
7593
  }
7330
7594
  sendGetRequest(url) {
@@ -7378,83 +7642,6 @@ var http = __toESM(require("http"), 1);
7378
7642
  var HttpServer = class {
7379
7643
  };
7380
7644
 
7381
- // sources/httpOutgoingResponse.ts
7382
- var HttpOutgoingResponse = class _HttpOutgoingResponse {
7383
- statusCode;
7384
- headers;
7385
- body;
7386
- constructor() {
7387
- this.statusCode = 200;
7388
- this.headers = MutableHttpHeaders.create();
7389
- this.body = "";
7390
- }
7391
- static create() {
7392
- return new _HttpOutgoingResponse();
7393
- }
7394
- /**
7395
- * Get the status code of this {@link HttpOutgoingResponse}.
7396
- */
7397
- getStatusCode() {
7398
- return this.statusCode;
7399
- }
7400
- /**
7401
- * Set the status code of this {@link HttpOutgoingResponse}.
7402
- * @param statusCode The status code of this {@link HttpOutgoingResponse}.
7403
- */
7404
- setStatusCode(statusCode) {
7405
- PreCondition.assertBetween(100, statusCode, 599, "statusCode");
7406
- this.statusCode = statusCode;
7407
- return this;
7408
- }
7409
- getHeaders() {
7410
- return this.headers;
7411
- }
7412
- /**
7413
- * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
7414
- * doesn't exist.
7415
- * @param headerName The name of the header to get.
7416
- */
7417
- getHeader(headerName) {
7418
- return this.headers.get(headerName);
7419
- }
7420
- /**
7421
- * Get the value of the header with the provided name or return a {@link NotFoundError} if the
7422
- * header doesn't exist.
7423
- * @param headerName The name of the header value to get.
7424
- */
7425
- getHeaderValue(headerName) {
7426
- return this.headers.getValue(headerName);
7427
- }
7428
- /**
7429
- * Set the HTTP header in this {@link HttpOutgoingResponse}.
7430
- * @param headerName The name of the HTTP header.
7431
- * @param headerValue The value of the HTTP header.
7432
- */
7433
- setHeader(headerName, headerValue) {
7434
- this.headers.set(headerName, headerValue);
7435
- return this;
7436
- }
7437
- setContentTypeHeader(contentType) {
7438
- this.headers.setContentType(contentType);
7439
- return this;
7440
- }
7441
- /**
7442
- * Get the body of this {@link HttpOutgoingResponse}.
7443
- */
7444
- getBody() {
7445
- return this.body;
7446
- }
7447
- /**
7448
- * Set the body of this {@link HttpOutgoingResponse}.
7449
- * @param body The body for this {@link HttpOutgoingResponse}.
7450
- */
7451
- setBody(body) {
7452
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
7453
- this.body = body;
7454
- return this;
7455
- }
7456
- };
7457
-
7458
7645
  // sources/nodeJSHttpServer.ts
7459
7646
  var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
7460
7647
  httpServer;
@@ -7507,16 +7694,9 @@ var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
7507
7694
  reject(new Error("Can't run a HttpServer multiple times."));
7508
7695
  } else {
7509
7696
  this.httpServer = http.createServer();
7510
- this.httpServer.on("request", (request, response) => {
7511
- const httpResponse = HttpOutgoingResponse.create().setStatusCode(200).setHeader("Content-Type", "text/plain").setBody("Hello world!");
7512
- const statusCode = httpResponse.getStatusCode();
7513
- const headers = httpResponse.getHeaders();
7514
- const responseHeaders = {};
7515
- for (const header of headers) {
7516
- responseHeaders[header.getName()] = header.getValue();
7517
- }
7518
- response.writeHead(statusCode, responseHeaders);
7519
- response.end(httpResponse.getBody());
7697
+ this.httpServer.on("request", async (rawRequest, rawResponse) => {
7698
+ const response = NodeJSHttpOutgoingResponse.create(rawResponse).setStatusCode(200).setHeader("Content-Type", "text/plain").setBodyString("Hello world!");
7699
+ await response.end();
7520
7700
  });
7521
7701
  this.httpServer.on("close", () => {
7522
7702
  resolve();
@@ -7643,149 +7823,6 @@ var CurrentProcess = class _CurrentProcess {
7643
7823
  }
7644
7824
  };
7645
7825
 
7646
- // sources/luxonDateTime.ts
7647
- var luxon = __toESM(require("luxon"), 1);
7648
- var pctTimeZone = "America/Los_Angeles";
7649
- var LuxonDateTime = class _LuxonDateTime {
7650
- dateTime;
7651
- constructor(dateTime) {
7652
- this.dateTime = dateTime;
7653
- }
7654
- static create(dateTime) {
7655
- return new _LuxonDateTime(dateTime);
7656
- }
7657
- static parse(text) {
7658
- return _LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
7659
- }
7660
- static now() {
7661
- return _LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
7662
- }
7663
- getYear() {
7664
- return this.dateTime.year;
7665
- }
7666
- getMonth() {
7667
- return this.dateTime.month;
7668
- }
7669
- getDay() {
7670
- return this.dateTime.day;
7671
- }
7672
- getHour() {
7673
- return this.dateTime.hour;
7674
- }
7675
- getMinute() {
7676
- return this.dateTime.minute;
7677
- }
7678
- getSecond() {
7679
- return this.dateTime.second;
7680
- }
7681
- addDays(days) {
7682
- return _LuxonDateTime.create(this.dateTime.plus({ days }));
7683
- }
7684
- toString() {
7685
- return this.dateTime.toISO();
7686
- }
7687
- toDateString() {
7688
- return this.dateTime.toISODate();
7689
- }
7690
- compareTo(dateTime, compareTimes) {
7691
- return DateTime2.compareTo(this, dateTime, compareTimes);
7692
- }
7693
- lessThan(dateTime, compareTimes) {
7694
- return DateTime2.lessThan(this, dateTime, compareTimes);
7695
- }
7696
- lessThanOrEqualTo(dateTime, compareTimes) {
7697
- return DateTime2.lessThanOrEqualTo(this, dateTime, compareTimes);
7698
- }
7699
- equals(dateTime, compareTimes) {
7700
- return DateTime2.equals(this, dateTime, compareTimes);
7701
- }
7702
- greaterThanOrEqualTo(dateTime, compareTimes) {
7703
- return DateTime2.greaterThanOrEqualTo(this, dateTime, compareTimes);
7704
- }
7705
- greaterThan(dateTime, compareTimes) {
7706
- return DateTime2.greaterThan(this, dateTime, compareTimes);
7707
- }
7708
- get debug() {
7709
- return DateTime2.debug(this);
7710
- }
7711
- };
7712
-
7713
- // sources/dateTime.ts
7714
- var DateTime2 = class _DateTime {
7715
- static parse(text) {
7716
- return LuxonDateTime.parse(text);
7717
- }
7718
- static now() {
7719
- return LuxonDateTime.now();
7720
- }
7721
- /**
7722
- * Compare this {@link DateTime} to the provided {@link DateTime}. If this {@link DateTime} is
7723
- * less than the provided {@link DateTime}, then a negative number will be returned, 0 if
7724
- * they're equal, or a positive number if this {@link DateTime} is greater than the provided
7725
- * {@link DateTime}.
7726
- * @param dateTime The {@link DateTime} to compare to this {@link DateTime}.
7727
- */
7728
- compareTo(dateTime, compareTimes) {
7729
- return _DateTime.compareTo(this, dateTime, compareTimes);
7730
- }
7731
- static compareTo(left, right, compareTimes) {
7732
- let result = left.getYear() - right.getYear();
7733
- if (result === 0) {
7734
- result = left.getMonth() - right.getMonth();
7735
- if (result === 0) {
7736
- result = left.getDay() - right.getDay();
7737
- if (compareTimes && result === 0) {
7738
- result = left.getHour() - right.getHour();
7739
- if (result === 0) {
7740
- result = left.getMinute() - right.getMinute();
7741
- if (result === 0) {
7742
- result = left.getSecond();
7743
- -right.getSecond();
7744
- }
7745
- }
7746
- }
7747
- }
7748
- }
7749
- return result;
7750
- }
7751
- lessThan(dateTime, compareTimes) {
7752
- return _DateTime.lessThan(this, dateTime, compareTimes);
7753
- }
7754
- static lessThan(left, right, compareTimes) {
7755
- return left.compareTo(right, compareTimes) < 0;
7756
- }
7757
- lessThanOrEqualTo(dateTime, compareTimes) {
7758
- return _DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
7759
- }
7760
- static lessThanOrEqualTo(left, right, compareTimes) {
7761
- return left.compareTo(right, compareTimes) <= 0;
7762
- }
7763
- equals(dateTime, compareTimes) {
7764
- return _DateTime.equals(this, dateTime, compareTimes);
7765
- }
7766
- static equals(left, right, compareTimes) {
7767
- return left.compareTo(right, compareTimes) === 0;
7768
- }
7769
- greaterThanOrEqualTo(dateTime, compareTimes) {
7770
- return _DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
7771
- }
7772
- static greaterThanOrEqualTo(left, right, compareTimes) {
7773
- return left.compareTo(right, compareTimes) >= 0;
7774
- }
7775
- greaterThan(dateTime, compareTimes) {
7776
- return _DateTime.greaterThan(this, dateTime, compareTimes);
7777
- }
7778
- static greaterThan(left, right, compareTimes) {
7779
- return left.compareTo(right, compareTimes) > 0;
7780
- }
7781
- get debug() {
7782
- return _DateTime.debug(this);
7783
- }
7784
- static debug(dateTime) {
7785
- return dateTime.toString();
7786
- }
7787
- };
7788
-
7789
7826
  // sources/listStack.ts
7790
7827
  var ListStack = class _ListStack {
7791
7828
  list;
@@ -8145,6 +8182,10 @@ var HttpClient = class _HttpClient {
8145
8182
  var HttpIncomingRequest = class {
8146
8183
  };
8147
8184
 
8185
+ // sources/httpOutgoingResponse.ts
8186
+ var HttpOutgoingResponse = class {
8187
+ };
8188
+
8148
8189
  // sources/inMemoryCharacterWriteStream.ts
8149
8190
  var InMemoryCharacterWriteStream = class _InMemoryCharacterWriteStream extends CharacterWriteStream {
8150
8191
  writtenText;
@@ -9591,6 +9632,7 @@ var WonderlandTrailClient = class _WonderlandTrailClient {
9591
9632
  CharacterReadStreamAsyncIterator,
9592
9633
  CharacterTable,
9593
9634
  CharacterWriteStream,
9635
+ Clock,
9594
9636
  CommandLineParameter,
9595
9637
  CommandLineParameters,
9596
9638
  Comparable,
@@ -9604,6 +9646,7 @@ var WonderlandTrailClient = class _WonderlandTrailClient {
9604
9646
  Disposable,
9605
9647
  EmptyError,
9606
9648
  EqualFunctions,
9649
+ FetchError,
9607
9650
  FetchHttpClient,
9608
9651
  FetchHttpIncomingResponse,
9609
9652
  FlatMapIterable,
@@ -9647,6 +9690,7 @@ var WonderlandTrailClient = class _WonderlandTrailClient {
9647
9690
  Node,
9648
9691
  NodeJSCharacterWriteStream,
9649
9692
  NodeJSHttpIncomingRequest,
9693
+ NodeJSHttpOutgoingResponse,
9650
9694
  NodeJSHttpServer,
9651
9695
  NotFoundError,
9652
9696
  PostCondition,
@@ -9656,6 +9700,7 @@ var WonderlandTrailClient = class _WonderlandTrailClient {
9656
9700
  PromiseAsyncResult,
9657
9701
  Property,
9658
9702
  Queue,
9703
+ RealClock,
9659
9704
  RealNetwork,
9660
9705
  RecreationDotGovClient,
9661
9706
  RecreationDotGovDivisionAvailability,