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