@everyonesoftware/common 11.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4280,6 +4280,187 @@ var CharacterTable = class _CharacterTable {
4280
4280
  }
4281
4281
  };
4282
4282
 
4283
+ // sources/luxonDateTime.ts
4284
+ import * as luxon from "luxon";
4285
+ var pctTimeZone = "America/Los_Angeles";
4286
+ var LuxonDateTime = class _LuxonDateTime {
4287
+ dateTime;
4288
+ constructor(dateTime) {
4289
+ this.dateTime = dateTime;
4290
+ }
4291
+ static create(dateTime) {
4292
+ return new _LuxonDateTime(dateTime);
4293
+ }
4294
+ static parse(text) {
4295
+ return _LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
4296
+ }
4297
+ static now() {
4298
+ return _LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
4299
+ }
4300
+ getYear() {
4301
+ return this.dateTime.year;
4302
+ }
4303
+ getMonth() {
4304
+ return this.dateTime.month;
4305
+ }
4306
+ getDay() {
4307
+ return this.dateTime.day;
4308
+ }
4309
+ getHour() {
4310
+ return this.dateTime.hour;
4311
+ }
4312
+ getMinute() {
4313
+ return this.dateTime.minute;
4314
+ }
4315
+ getSecond() {
4316
+ return this.dateTime.second;
4317
+ }
4318
+ addDays(days) {
4319
+ return _LuxonDateTime.create(this.dateTime.plus({ days }));
4320
+ }
4321
+ toString() {
4322
+ return this.dateTime.toISO();
4323
+ }
4324
+ toDateString() {
4325
+ return this.dateTime.toISODate();
4326
+ }
4327
+ toShortDateString() {
4328
+ return `${this.dateTime.monthShort} ${this.dateTime.day}`;
4329
+ }
4330
+ compareTo(dateTime, compareTimes) {
4331
+ return DateTime2.compareTo(this, dateTime, compareTimes);
4332
+ }
4333
+ lessThan(dateTime, compareTimes) {
4334
+ return DateTime2.lessThan(this, dateTime, compareTimes);
4335
+ }
4336
+ lessThanOrEqualTo(dateTime, compareTimes) {
4337
+ return DateTime2.lessThanOrEqualTo(this, dateTime, compareTimes);
4338
+ }
4339
+ equals(dateTime, compareTimes) {
4340
+ return DateTime2.equals(this, dateTime, compareTimes);
4341
+ }
4342
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4343
+ return DateTime2.greaterThanOrEqualTo(this, dateTime, compareTimes);
4344
+ }
4345
+ greaterThan(dateTime, compareTimes) {
4346
+ return DateTime2.greaterThan(this, dateTime, compareTimes);
4347
+ }
4348
+ get debug() {
4349
+ return DateTime2.debug(this);
4350
+ }
4351
+ };
4352
+
4353
+ // sources/dateTime.ts
4354
+ var DateTime2 = class _DateTime {
4355
+ static parse(text) {
4356
+ return LuxonDateTime.parse(text);
4357
+ }
4358
+ static now() {
4359
+ return LuxonDateTime.now();
4360
+ }
4361
+ /**
4362
+ * Compare this {@link DateTime} to the provided {@link DateTime}. If this {@link DateTime} is
4363
+ * less than the provided {@link DateTime}, then a negative number will be returned, 0 if
4364
+ * they're equal, or a positive number if this {@link DateTime} is greater than the provided
4365
+ * {@link DateTime}.
4366
+ * @param dateTime The {@link DateTime} to compare to this {@link DateTime}.
4367
+ */
4368
+ compareTo(dateTime, compareTimes) {
4369
+ return _DateTime.compareTo(this, dateTime, compareTimes);
4370
+ }
4371
+ static compareTo(left, right, compareTimes) {
4372
+ let result = left.getYear() - right.getYear();
4373
+ if (result === 0) {
4374
+ result = left.getMonth() - right.getMonth();
4375
+ if (result === 0) {
4376
+ result = left.getDay() - right.getDay();
4377
+ if (compareTimes && result === 0) {
4378
+ result = left.getHour() - right.getHour();
4379
+ if (result === 0) {
4380
+ result = left.getMinute() - right.getMinute();
4381
+ if (result === 0) {
4382
+ result = left.getSecond();
4383
+ -right.getSecond();
4384
+ }
4385
+ }
4386
+ }
4387
+ }
4388
+ }
4389
+ return result;
4390
+ }
4391
+ lessThan(dateTime, compareTimes) {
4392
+ return _DateTime.lessThan(this, dateTime, compareTimes);
4393
+ }
4394
+ static lessThan(left, right, compareTimes) {
4395
+ return left.compareTo(right, compareTimes) < 0;
4396
+ }
4397
+ lessThanOrEqualTo(dateTime, compareTimes) {
4398
+ return _DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
4399
+ }
4400
+ static lessThanOrEqualTo(left, right, compareTimes) {
4401
+ return left.compareTo(right, compareTimes) <= 0;
4402
+ }
4403
+ equals(dateTime, compareTimes) {
4404
+ return _DateTime.equals(this, dateTime, compareTimes);
4405
+ }
4406
+ static equals(left, right, compareTimes) {
4407
+ return left.compareTo(right, compareTimes) === 0;
4408
+ }
4409
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4410
+ return _DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
4411
+ }
4412
+ static greaterThanOrEqualTo(left, right, compareTimes) {
4413
+ return left.compareTo(right, compareTimes) >= 0;
4414
+ }
4415
+ greaterThan(dateTime, compareTimes) {
4416
+ return _DateTime.greaterThan(this, dateTime, compareTimes);
4417
+ }
4418
+ static greaterThan(left, right, compareTimes) {
4419
+ return left.compareTo(right, compareTimes) > 0;
4420
+ }
4421
+ get debug() {
4422
+ return _DateTime.debug(this);
4423
+ }
4424
+ static debug(dateTime) {
4425
+ return dateTime.toString();
4426
+ }
4427
+ };
4428
+
4429
+ // sources/RealClock.ts
4430
+ var RealClock = class _RealClock {
4431
+ constructor() {
4432
+ }
4433
+ static create() {
4434
+ return new _RealClock();
4435
+ }
4436
+ now() {
4437
+ return DateTime2.now();
4438
+ }
4439
+ };
4440
+
4441
+ // sources/Clock.ts
4442
+ var Clock = class {
4443
+ static create() {
4444
+ return RealClock.create();
4445
+ }
4446
+ };
4447
+
4448
+ // sources/FetchError.ts
4449
+ var FetchError = class extends Error {
4450
+ innerError;
4451
+ constructor(innerError) {
4452
+ PreCondition.assertNotUndefinedAndNotNull(innerError, "innerError");
4453
+ super(innerError.message, { cause: innerError });
4454
+ this.innerError = innerError;
4455
+ }
4456
+ get code() {
4457
+ return "code" in this.innerError ? this.innerError.code : void 0;
4458
+ }
4459
+ get hostname() {
4460
+ return "hostname" in this.innerError ? this.innerError.hostname : void 0;
4461
+ }
4462
+ };
4463
+
4283
4464
  // sources/asyncResult.ts
4284
4465
  var AsyncResult = class {
4285
4466
  static create(actionOrPromise) {
@@ -4661,663 +4842,641 @@ var IndentedCharacterWriteStream = class _IndentedCharacterWriteStream extends C
4661
4842
  }
4662
4843
  };
4663
4844
 
4664
- // sources/TokenType.ts
4665
- var TokenType = class _TokenType {
4845
+ // sources/httpHeader.ts
4846
+ var HttpHeader = class _HttpHeader {
4666
4847
  name;
4667
- constructor(name) {
4848
+ value;
4849
+ constructor(name, value) {
4668
4850
  PreCondition.assertNotEmpty(name, "name");
4851
+ PreCondition.assertNotUndefinedAndNotNull(value, "value");
4669
4852
  this.name = name;
4853
+ this.value = value;
4670
4854
  }
4671
- static create(name) {
4672
- return new _TokenType(name);
4855
+ static create(name, value) {
4856
+ return new _HttpHeader(name, value);
4673
4857
  }
4674
- static Whitespace = _TokenType.create("Whitespace");
4675
- static NewLine = _TokenType.create("NewLine");
4676
- static Letters = _TokenType.create("Letters");
4677
- static Digits = _TokenType.create("Digits");
4678
- static LeftParenthesis = _TokenType.create("LeftParenthesis");
4679
- static RightParenthesis = _TokenType.create("RightParenthesis");
4680
- static Backslash = _TokenType.create("Backslash");
4681
- static ForwardSlash = _TokenType.create("ForwardSlash");
4682
- static Unknown = _TokenType.create("Unknown");
4683
- static Period = _TokenType.create("Period");
4684
- static Underscore = _TokenType.create("Underscore");
4685
- static Colon = _TokenType.create("Colon");
4686
- toString() {
4858
+ getName() {
4687
4859
  return this.name;
4688
4860
  }
4689
- };
4690
-
4691
- // sources/Token.ts
4692
- var Token = class _Token {
4693
- static newLineToken = _Token.create("\n", TokenType.NewLine);
4694
- static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
4695
- static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
4696
- static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
4697
- static backslashToken = _Token.create("\\", TokenType.Backslash);
4698
- static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
4699
- static periodToken = _Token.create(".", TokenType.Period);
4700
- static underscoreToken = _Token.create("_", TokenType.Underscore);
4701
- static colonToken = _Token.create(":", TokenType.Colon);
4702
- text;
4703
- type;
4704
- constructor(text, type) {
4705
- PreCondition.assertNotEmpty(text, "text");
4706
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
4707
- this.text = text;
4708
- this.type = type;
4709
- }
4710
- static create(text, type) {
4711
- return new _Token(text, type);
4861
+ getValue() {
4862
+ return this.value;
4712
4863
  }
4713
- static whitespace(text) {
4714
- return _Token.create(text, TokenType.Whitespace);
4864
+ toString() {
4865
+ return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
4715
4866
  }
4716
- static newLine(text) {
4717
- text ??= "\n";
4718
- let result;
4719
- switch (text) {
4720
- case "\n":
4721
- result = _Token.newLineToken;
4722
- break;
4723
- case "\r\n":
4724
- result = _Token.carriageReturnNewLineToken;
4725
- break;
4726
- default:
4727
- result = _Token.create(text, TokenType.NewLine);
4728
- break;
4867
+ };
4868
+
4869
+ // sources/mutableHttpHeaders.ts
4870
+ var MutableHttpHeaders = class _MutableHttpHeaders {
4871
+ headers;
4872
+ constructor(headers) {
4873
+ this.headers = List.create();
4874
+ if (headers) {
4875
+ this.setAll(headers);
4729
4876
  }
4730
- return result;
4731
- }
4732
- static leftParenthesis() {
4733
- return _Token.leftParenthesisToken;
4734
- }
4735
- static rightParenthesis() {
4736
- return _Token.rightParenthesisToken;
4737
- }
4738
- static backslash() {
4739
- return _Token.backslashToken;
4740
4877
  }
4741
- static forwardSlash() {
4742
- return _Token.forwardSlashToken;
4878
+ static create(headers) {
4879
+ return new _MutableHttpHeaders(headers);
4743
4880
  }
4744
- static period() {
4745
- return _Token.periodToken;
4881
+ iterate() {
4882
+ return this.headers.iterate();
4746
4883
  }
4747
- static underscore() {
4748
- return _Token.underscoreToken;
4749
- }
4750
- static colon() {
4751
- return _Token.colonToken;
4752
- }
4753
- static letters(text) {
4754
- return _Token.create(text, TokenType.Letters);
4755
- }
4756
- static digits(text) {
4757
- return _Token.create(text, TokenType.Digits);
4758
- }
4759
- static unknown(text) {
4760
- return _Token.create(text, TokenType.Unknown);
4761
- }
4762
- getText() {
4763
- return this.text;
4764
- }
4765
- getType() {
4766
- return this.type;
4767
- }
4768
- };
4769
-
4770
- // sources/Tokenizer.ts
4771
- var Tokenizer = class _Tokenizer {
4772
- characters;
4773
- currentToken;
4774
- started;
4775
- constructor(characters) {
4776
- this.characters = characters;
4777
- this.started = false;
4778
- }
4779
- static create(characters) {
4780
- PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
4781
- return new _Tokenizer(isIterator(characters) ? characters : Iterator.create(characters));
4782
- }
4783
- hasStarted() {
4784
- return this.started;
4785
- }
4786
- hasCurrent() {
4787
- return this.currentToken !== void 0;
4788
- }
4789
- getCurrent() {
4790
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
4791
- return this.currentToken;
4792
- }
4793
- next() {
4884
+ get(headerName) {
4885
+ PreCondition.assertNotEmpty(headerName, "headerName");
4794
4886
  return SyncResult.create(() => {
4795
- if (!this.hasStarted()) {
4796
- this.characters.start().await();
4797
- this.started = true;
4798
- }
4799
- if (!this.characters.hasCurrent()) {
4800
- this.currentToken = void 0;
4801
- } else {
4802
- switch (this.characters.getCurrent()) {
4803
- case " ":
4804
- case " ":
4805
- this.currentToken = Token.whitespace(this.readWhile((c) => c === " " || c === " "));
4806
- break;
4807
- case "\n":
4808
- this.characters.next().await();
4809
- this.currentToken = Token.newLine();
4810
- break;
4811
- case "\r":
4812
- if (this.characters.next().await() && this.characters.getCurrent() === "\n") {
4813
- this.characters.next().await();
4814
- this.currentToken = Token.newLine("\r\n");
4815
- } else {
4816
- this.currentToken = Token.whitespace("\r");
4817
- }
4818
- break;
4819
- case "(":
4820
- this.characters.next().await();
4821
- this.currentToken = Token.leftParenthesis();
4822
- break;
4823
- case ")":
4824
- this.characters.next().await();
4825
- this.currentToken = Token.rightParenthesis();
4826
- break;
4827
- case ".":
4828
- this.characters.next().await();
4829
- this.currentToken = Token.period();
4830
- break;
4831
- case "_":
4832
- this.characters.next().await();
4833
- this.currentToken = Token.underscore();
4834
- break;
4835
- case "/":
4836
- this.characters.next().await();
4837
- this.currentToken = Token.forwardSlash();
4838
- break;
4839
- case "\\":
4840
- this.characters.next().await();
4841
- this.currentToken = Token.backslash();
4842
- break;
4843
- case ":":
4844
- this.characters.next().await();
4845
- this.currentToken = Token.colon();
4846
- break;
4847
- default:
4848
- if (isLetter(this.characters.getCurrent())) {
4849
- this.currentToken = Token.letters(this.readWhile(isLetter));
4850
- } else if (isDigit(this.characters.getCurrent())) {
4851
- this.currentToken = Token.digits(this.readWhile(isDigit));
4852
- } else {
4853
- this.currentToken = Token.unknown(this.characters.takeCurrent().await());
4854
- }
4855
- break;
4887
+ let result;
4888
+ const lowerHeaderName = headerName.toLowerCase();
4889
+ for (const header of this.headers) {
4890
+ if (header.getName().toLowerCase() === lowerHeaderName) {
4891
+ result = header;
4892
+ break;
4856
4893
  }
4857
4894
  }
4858
- return this.hasCurrent();
4895
+ if (result === void 0) {
4896
+ throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
4897
+ }
4898
+ return result;
4859
4899
  });
4860
4900
  }
4861
- readWhile(condition) {
4862
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
4863
- PreCondition.assertTrue(this.characters.hasCurrent(), "this.characters.hasCurrent()");
4864
- PreCondition.assertTrue(condition(this.characters.getCurrent()), "condition(this.characters.getCurrent())");
4865
- let result = "";
4866
- do {
4867
- result += this.characters.takeCurrent().await();
4868
- } while (this.characters.hasCurrent() && condition(this.characters.getCurrent()));
4869
- return result;
4901
+ getValue(headerName) {
4902
+ return this.get(headerName).then((header) => header.getValue());
4870
4903
  }
4871
- start() {
4872
- return Iterator.start(this);
4904
+ set(headerOrHeaderName, headerValue) {
4905
+ let headerName;
4906
+ if (isString(headerOrHeaderName)) {
4907
+ headerName = headerOrHeaderName;
4908
+ } else {
4909
+ headerName = headerOrHeaderName.getName();
4910
+ headerValue = headerOrHeaderName.getValue();
4911
+ }
4912
+ PreCondition.assertNotEmpty(headerName, "headerName");
4913
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
4914
+ let insertIndex = 0;
4915
+ for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
4916
+ const header = this.headers.get(insertIndex2).await();
4917
+ if (header.getName() === headerName) {
4918
+ this.headers.removeAt(insertIndex2);
4919
+ break;
4920
+ }
4921
+ }
4922
+ this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
4923
+ return this;
4873
4924
  }
4874
- takeCurrent() {
4875
- return Iterator.takeCurrent(this);
4925
+ setAll(headers) {
4926
+ PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
4927
+ for (const header of headers) {
4928
+ this.set(header);
4929
+ }
4930
+ return this;
4876
4931
  }
4877
- any() {
4878
- return Iterator.any(this);
4932
+ setContentType(contentType) {
4933
+ return this.set(HttpHeaders.contentTypeHeaderName, contentType);
4934
+ }
4935
+ getContentType() {
4936
+ return this.get(HttpHeaders.contentTypeHeaderName);
4937
+ }
4938
+ getContentTypeValue() {
4939
+ return this.getValue(HttpHeaders.contentTypeHeaderName);
4879
4940
  }
4880
4941
  getCount() {
4881
- return Iterator.getCount(this);
4942
+ return this.headers.getCount();
4882
4943
  }
4883
4944
  toArray() {
4884
- return Iterator.toArray(this);
4945
+ return HttpHeaders.toArray(this);
4885
4946
  }
4886
- concatenate(...toConcatenate) {
4887
- return Iterator.concatenate(this, ...toConcatenate);
4947
+ any() {
4948
+ return HttpHeaders.any(this);
4888
4949
  }
4889
- where(condition) {
4890
- return Iterator.where(this, condition);
4950
+ equals(right, equalFunctions) {
4951
+ return HttpHeaders.equals(this, right, equalFunctions);
4952
+ }
4953
+ toString(toStringFunctions) {
4954
+ return HttpHeaders.toString(this, toStringFunctions);
4955
+ }
4956
+ concatenate(...toConcatenate) {
4957
+ return HttpHeaders.concatenate(this, ...toConcatenate);
4891
4958
  }
4892
4959
  map(mapping) {
4893
- return Iterator.map(this, mapping);
4960
+ return HttpHeaders.map(this, mapping);
4894
4961
  }
4895
4962
  flatMap(mapping) {
4896
- return Iterator.flatMap(this, mapping);
4963
+ return HttpHeaders.flatMap(this, mapping);
4897
4964
  }
4898
- whereInstanceOf(typeCheck) {
4899
- return Iterator.whereInstanceOf(this, typeCheck);
4965
+ where(condition) {
4966
+ return HttpHeaders.where(this, condition);
4900
4967
  }
4901
- whereInstanceOfType(type) {
4902
- return Iterator.whereInstanceOfType(this, type);
4968
+ instanceOf(typeOrTypeCheck) {
4969
+ return HttpHeaders.instanceOf(this, typeOrTypeCheck);
4903
4970
  }
4904
4971
  first(condition) {
4905
- return Iterator.first(this, condition);
4972
+ return HttpHeaders.first(this, condition);
4906
4973
  }
4907
4974
  last(condition) {
4908
- return Iterator.last(this, condition);
4909
- }
4910
- take(maximumToTake) {
4911
- return Iterator.take(this, maximumToTake);
4912
- }
4913
- skip(maximumToSkip) {
4914
- return Iterator.skip(this, maximumToSkip);
4975
+ return HttpHeaders.last(this, condition);
4915
4976
  }
4916
4977
  [Symbol.iterator]() {
4917
- return Iterator[Symbol.iterator](this);
4978
+ return HttpHeaders[Symbol.iterator](this);
4979
+ }
4980
+ contains(value, equalFunctions) {
4981
+ return HttpHeaders.contains(this, value, equalFunctions);
4918
4982
  }
4919
4983
  };
4920
4984
 
4921
- // sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts
4922
- var AsyncIteratorToJavascriptAsyncIteratorAdapter = class _AsyncIteratorToJavascriptAsyncIteratorAdapter {
4923
- iterator;
4924
- hasStarted;
4925
- constructor(iterator) {
4926
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
4927
- this.iterator = iterator;
4928
- this.hasStarted = false;
4985
+ // sources/httpHeaders.ts
4986
+ var HttpHeaders = class _HttpHeaders {
4987
+ static contentTypeHeaderName = "Content-Type";
4988
+ static create(headers) {
4989
+ return MutableHttpHeaders.create(headers);
4929
4990
  }
4930
- static create(iterator) {
4931
- return new _AsyncIteratorToJavascriptAsyncIteratorAdapter(iterator);
4991
+ getContentType() {
4992
+ return _HttpHeaders.getContentType(this);
4932
4993
  }
4933
- async next() {
4934
- if (!this.hasStarted) {
4935
- this.hasStarted = true;
4936
- await this.iterator.start();
4937
- } else {
4938
- await this.iterator.next();
4939
- }
4940
- const result = {
4941
- done: !this.iterator.hasCurrent(),
4942
- value: void 0
4943
- };
4944
- if (!result.done) {
4945
- result.value = this.iterator.getCurrent();
4946
- }
4947
- return result;
4994
+ static getContentType(headers) {
4995
+ return headers.get(_HttpHeaders.contentTypeHeaderName);
4948
4996
  }
4949
- };
4950
-
4951
- // sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts
4952
- var JavascriptAsyncIteratorToAsyncIteratorAdapter = class _JavascriptAsyncIteratorToAsyncIteratorAdapter {
4953
- javascriptIterator;
4954
- javascriptIteratorResult;
4955
- constructor(javascriptIterator) {
4956
- PreCondition.assertNotUndefinedAndNotNull(javascriptIterator, "javascriptIterator");
4957
- this.javascriptIterator = javascriptIterator;
4997
+ getContentTypeValue() {
4998
+ return _HttpHeaders.getContentTypeValue(this);
4958
4999
  }
4959
- static create(javascriptIterator) {
4960
- if (isJavascriptAsyncIterable(javascriptIterator)) {
4961
- javascriptIterator = javascriptIterator[Symbol.asyncIterator]();
4962
- }
4963
- return new _JavascriptAsyncIteratorToAsyncIteratorAdapter(javascriptIterator);
5000
+ static getContentTypeValue(headers) {
5001
+ return headers.getValue(_HttpHeaders.contentTypeHeaderName);
4964
5002
  }
4965
- next() {
4966
- return PromiseAsyncResult.create(async () => {
4967
- this.javascriptIteratorResult = await this.javascriptIterator.next();
4968
- return this.hasCurrent();
4969
- });
5003
+ /**
5004
+ * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
5005
+ */
5006
+ toArray() {
5007
+ return _HttpHeaders.toArray(this);
4970
5008
  }
4971
- hasStarted() {
4972
- return this.javascriptIteratorResult !== void 0;
5009
+ static toArray(headers) {
5010
+ return Iterable.toArray(headers);
4973
5011
  }
4974
- hasCurrent() {
4975
- return this.javascriptIteratorResult?.done === false;
5012
+ any() {
5013
+ return _HttpHeaders.any(this);
4976
5014
  }
4977
- getCurrent() {
4978
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
4979
- return this.javascriptIteratorResult.value;
5015
+ static any(headers) {
5016
+ return Iterable.any(headers);
4980
5017
  }
4981
- start() {
4982
- return AsyncIterator.start(this);
5018
+ getCount() {
5019
+ return _HttpHeaders.getCount(this);
4983
5020
  }
4984
- takeCurrent() {
4985
- return AsyncIterator.takeCurrent(this);
5021
+ static getCount(headers) {
5022
+ return Iterable.getCount(headers);
4986
5023
  }
4987
- any() {
4988
- return AsyncIterator.any(this);
5024
+ equals(right, equalFunctions) {
5025
+ return _HttpHeaders.equals(this, right, equalFunctions);
4989
5026
  }
4990
- getCount() {
4991
- return AsyncIterator.getCount(this);
5027
+ static equals(headers, right, equalFunctions) {
5028
+ return Iterable.equals(headers, right, equalFunctions);
4992
5029
  }
4993
- toArray() {
4994
- return AsyncIterator.toArray(this);
5030
+ toString(toStringFunctions) {
5031
+ return _HttpHeaders.toString(this, toStringFunctions);
5032
+ }
5033
+ static toString(headers, toStringFunctions) {
5034
+ return Iterable.toString(headers, toStringFunctions);
5035
+ }
5036
+ concatenate(...toConcatenate) {
5037
+ return _HttpHeaders.concatenate(this, ...toConcatenate);
5038
+ }
5039
+ static concatenate(headers, ...toConcatenate) {
5040
+ return Iterable.concatenate(headers, ...toConcatenate);
4995
5041
  }
4996
5042
  map(mapping) {
4997
- return AsyncIterator.map(this, mapping);
5043
+ return _HttpHeaders.map(this, mapping);
4998
5044
  }
4999
- [Symbol.asyncIterator]() {
5000
- return AsyncIterator[Symbol.asyncIterator](this);
5045
+ static map(headers, mapping) {
5046
+ return Iterable.map(headers, mapping);
5001
5047
  }
5002
- first(condition) {
5003
- return AsyncIterator.first(this, condition);
5048
+ flatMap(mapping) {
5049
+ return _HttpHeaders.flatMap(this, mapping);
5004
5050
  }
5005
- last(condition) {
5006
- return AsyncIterator.last(this, condition);
5051
+ static flatMap(headers, mapping) {
5052
+ return Iterable.flatMap(headers, mapping);
5007
5053
  }
5008
5054
  where(condition) {
5009
- return AsyncIterator.where(this, condition);
5010
- }
5011
- whereInstanceOf(typeCheck) {
5012
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5055
+ return _HttpHeaders.where(this, condition);
5013
5056
  }
5014
- whereInstanceOfType(type) {
5015
- return AsyncIterator.whereInstanceOfType(this, type);
5057
+ static where(headers, condition) {
5058
+ return Iterable.where(headers, condition);
5016
5059
  }
5017
- take(maximumToTake) {
5018
- return AsyncIterator.take(this, maximumToTake);
5060
+ instanceOf(typeOrTypeCheck) {
5061
+ return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
5019
5062
  }
5020
- skip(maximumToSkip) {
5021
- return AsyncIterator.skip(this, maximumToSkip);
5063
+ static instanceOf(headers, typeOrTypeCheck) {
5064
+ return Iterable.instanceOf(headers, typeOrTypeCheck);
5022
5065
  }
5023
- };
5024
-
5025
- // sources/mapAsyncIterator.ts
5026
- var MapAsyncIterator = class _MapAsyncIterator {
5027
- inputIterator;
5028
- mapping;
5029
- current;
5030
- started;
5031
- constructor(inputIterator, mapping) {
5032
- PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
5033
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5034
- this.inputIterator = inputIterator;
5035
- this.mapping = mapping;
5036
- this.started = false;
5066
+ first(condition) {
5067
+ return _HttpHeaders.first(this, condition);
5037
5068
  }
5038
- static create(inputIterator, mapping) {
5039
- return new _MapAsyncIterator(inputIterator, mapping);
5069
+ static first(headers, condition) {
5070
+ return Iterable.first(headers, condition);
5040
5071
  }
5041
- next() {
5042
- return PromiseAsyncResult.create(async () => {
5043
- if (!this.hasStarted()) {
5044
- this.started = true;
5045
- await this.inputIterator.start();
5046
- } else {
5047
- await this.inputIterator.next();
5048
- }
5049
- const result = this.inputIterator.hasCurrent();
5050
- this.current = result ? await this.mapping(this.inputIterator.getCurrent()) : void 0;
5051
- return result;
5052
- });
5072
+ last(condition) {
5073
+ return _HttpHeaders.last(this, condition);
5053
5074
  }
5054
- hasStarted() {
5055
- return this.started;
5075
+ static last(headers, condition) {
5076
+ return Iterable.last(headers, condition);
5056
5077
  }
5057
- hasCurrent() {
5058
- return this.hasStarted() && this.inputIterator.hasCurrent();
5078
+ [Symbol.iterator]() {
5079
+ return _HttpHeaders[Symbol.iterator](this);
5059
5080
  }
5060
- getCurrent() {
5061
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5062
- return this.current;
5081
+ static [Symbol.iterator](headers) {
5082
+ return Iterable[Symbol.iterator](headers);
5063
5083
  }
5064
- start() {
5065
- return AsyncIterator.start(this);
5084
+ contains(value, equalFunctions) {
5085
+ return _HttpHeaders.contains(this, value, equalFunctions);
5066
5086
  }
5067
- takeCurrent() {
5068
- return AsyncIterator.takeCurrent(this);
5087
+ static contains(headers, value, equalFunctions) {
5088
+ return SyncResult.create(() => {
5089
+ if (!equalFunctions) {
5090
+ equalFunctions = EqualFunctions.create();
5091
+ }
5092
+ return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
5093
+ });
5069
5094
  }
5070
- any() {
5071
- return AsyncIterator.any(this);
5095
+ };
5096
+
5097
+ // sources/NodeJSHttpOutgoingResponse.ts
5098
+ var NodeJSHttpOutgoingResponse = class _NodeJSHttpOutgoingResponse {
5099
+ innerResponse;
5100
+ bodyString;
5101
+ constructor(innerResponse) {
5102
+ PreCondition.assertNotUndefinedAndNotNull(innerResponse, "innerResponse");
5103
+ this.innerResponse = innerResponse;
5072
5104
  }
5073
- getCount() {
5074
- return AsyncIterator.getCount(this);
5105
+ static create(innerResponse) {
5106
+ return new _NodeJSHttpOutgoingResponse(innerResponse);
5075
5107
  }
5076
- toArray() {
5077
- return AsyncIterator.toArray(this);
5108
+ setStatusCode(statusCode) {
5109
+ this.innerResponse.statusCode = statusCode;
5110
+ return this;
5078
5111
  }
5079
- map(mapping) {
5080
- return AsyncIterator.map(this, mapping);
5112
+ getStatusCode() {
5113
+ return SyncResult.value(this.innerResponse.statusCode);
5081
5114
  }
5082
- [Symbol.asyncIterator]() {
5083
- return AsyncIterator[Symbol.asyncIterator](this);
5115
+ static headerValueToString(headerValue) {
5116
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5117
+ return isArray(headerValue) ? join(",", headerValue) : headerValue.toString();
5084
5118
  }
5085
- first(condition) {
5086
- return AsyncIterator.first(this, condition);
5119
+ getHeaders() {
5120
+ const result = HttpHeaders.create();
5121
+ for (const rawHeader of Object.entries(this.innerResponse.getHeaders())) {
5122
+ const headerName = rawHeader[0];
5123
+ const headerValue = rawHeader[1];
5124
+ if (headerValue !== void 0) {
5125
+ result.set(headerName, _NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
5126
+ }
5127
+ }
5128
+ return result;
5087
5129
  }
5088
- last() {
5089
- return AsyncIterator.last(this);
5130
+ getHeader(headerName) {
5131
+ PreCondition.assertNotEmpty(headerName, "headerName");
5132
+ const headerValue = this.innerResponse.getHeader(headerName);
5133
+ 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)));
5090
5134
  }
5091
- where(condition) {
5092
- return AsyncIterator.where(this, condition);
5135
+ getHeaderValue(headerName) {
5136
+ const headerValue = this.innerResponse.getHeader(headerName);
5137
+ return headerValue === void 0 ? SyncResult.error(new NotFoundError(`No HTTP header value exists with the name ${escapeAndQuote(headerName)}.`)) : SyncResult.value(_NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
5093
5138
  }
5094
- whereInstanceOf(typeCheck) {
5095
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5139
+ setHeader(headerName, headerValue) {
5140
+ PreCondition.assertNotEmpty(headerName, "headerName");
5141
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5142
+ this.innerResponse.setHeader(headerName, headerValue);
5143
+ return this;
5096
5144
  }
5097
- whereInstanceOfType(type) {
5098
- return AsyncIterator.whereInstanceOfType(this, type);
5145
+ setBodyString(body) {
5146
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5147
+ this.bodyString = body;
5148
+ return this;
5099
5149
  }
5100
- take(maximumToTake) {
5101
- return AsyncIterator.take(this, maximumToTake);
5150
+ setBodyJSON(body) {
5151
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5152
+ return this.setBodyString(JSON.stringify(body));
5102
5153
  }
5103
- skip(maximumToSkip) {
5104
- return AsyncIterator.skip(this, maximumToSkip);
5154
+ end() {
5155
+ return AsyncResult.create(new Promise((resolve, reject) => {
5156
+ this.innerResponse.end(this.bodyString, () => {
5157
+ resolve();
5158
+ });
5159
+ }));
5105
5160
  }
5106
5161
  };
5107
5162
 
5108
- // sources/skipAsyncIterator.ts
5109
- var SkipAsyncIterator = class _SkipAsyncIterator {
5110
- innerIterator;
5111
- started;
5112
- maximumToSkip;
5113
- constructor(innerIterator, maximumToSkip) {
5114
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5115
- PreCondition.assertNotUndefinedAndNotNull(maximumToSkip, "maximumToSkip");
5116
- PreCondition.assertInteger(maximumToSkip, "maximumToSkip");
5117
- PreCondition.assertGreaterThanOrEqualTo(maximumToSkip, 0, "maximumToSkip");
5118
- this.innerIterator = innerIterator;
5119
- this.started = false;
5120
- this.maximumToSkip = maximumToSkip;
5163
+ // sources/TokenType.ts
5164
+ var TokenType = class _TokenType {
5165
+ name;
5166
+ constructor(name) {
5167
+ PreCondition.assertNotEmpty(name, "name");
5168
+ this.name = name;
5121
5169
  }
5122
- static create(innerIterator, maximumToSkip) {
5123
- return new _SkipAsyncIterator(innerIterator, maximumToSkip);
5170
+ static create(name) {
5171
+ return new _TokenType(name);
5124
5172
  }
5125
- next() {
5126
- return PromiseAsyncResult.create(async () => {
5127
- if (!this.hasStarted()) {
5128
- this.started = true;
5129
- await this.innerIterator.start();
5130
- for (let i = 0; i < this.maximumToSkip; i++) {
5131
- if (!await this.innerIterator.next()) {
5132
- break;
5133
- }
5134
- }
5135
- } else {
5136
- await this.innerIterator.next();
5137
- }
5138
- return this.hasCurrent();
5139
- });
5173
+ static Whitespace = _TokenType.create("Whitespace");
5174
+ static NewLine = _TokenType.create("NewLine");
5175
+ static Letters = _TokenType.create("Letters");
5176
+ static Digits = _TokenType.create("Digits");
5177
+ static LeftParenthesis = _TokenType.create("LeftParenthesis");
5178
+ static RightParenthesis = _TokenType.create("RightParenthesis");
5179
+ static Backslash = _TokenType.create("Backslash");
5180
+ static ForwardSlash = _TokenType.create("ForwardSlash");
5181
+ static Unknown = _TokenType.create("Unknown");
5182
+ static Period = _TokenType.create("Period");
5183
+ static Underscore = _TokenType.create("Underscore");
5184
+ static Colon = _TokenType.create("Colon");
5185
+ toString() {
5186
+ return this.name;
5140
5187
  }
5141
- hasStarted() {
5142
- return this.started;
5143
- }
5144
- hasCurrent() {
5145
- return this.hasStarted() && this.innerIterator.hasCurrent();
5188
+ };
5189
+
5190
+ // sources/Token.ts
5191
+ var Token = class _Token {
5192
+ static newLineToken = _Token.create("\n", TokenType.NewLine);
5193
+ static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
5194
+ static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
5195
+ static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
5196
+ static backslashToken = _Token.create("\\", TokenType.Backslash);
5197
+ static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
5198
+ static periodToken = _Token.create(".", TokenType.Period);
5199
+ static underscoreToken = _Token.create("_", TokenType.Underscore);
5200
+ static colonToken = _Token.create(":", TokenType.Colon);
5201
+ text;
5202
+ type;
5203
+ constructor(text, type) {
5204
+ PreCondition.assertNotEmpty(text, "text");
5205
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
5206
+ this.text = text;
5207
+ this.type = type;
5146
5208
  }
5147
- getCurrent() {
5148
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5149
- return this.innerIterator.getCurrent();
5209
+ static create(text, type) {
5210
+ return new _Token(text, type);
5150
5211
  }
5151
- start() {
5152
- return AsyncIterator.start(this);
5212
+ static whitespace(text) {
5213
+ return _Token.create(text, TokenType.Whitespace);
5153
5214
  }
5154
- takeCurrent() {
5155
- return AsyncIterator.takeCurrent(this);
5215
+ static newLine(text) {
5216
+ text ??= "\n";
5217
+ let result;
5218
+ switch (text) {
5219
+ case "\n":
5220
+ result = _Token.newLineToken;
5221
+ break;
5222
+ case "\r\n":
5223
+ result = _Token.carriageReturnNewLineToken;
5224
+ break;
5225
+ default:
5226
+ result = _Token.create(text, TokenType.NewLine);
5227
+ break;
5228
+ }
5229
+ return result;
5156
5230
  }
5157
- any() {
5158
- return AsyncIterator.any(this);
5231
+ static leftParenthesis() {
5232
+ return _Token.leftParenthesisToken;
5159
5233
  }
5160
- getCount() {
5161
- return AsyncIterator.getCount(this);
5234
+ static rightParenthesis() {
5235
+ return _Token.rightParenthesisToken;
5162
5236
  }
5163
- toArray() {
5164
- return AsyncIterator.toArray(this);
5237
+ static backslash() {
5238
+ return _Token.backslashToken;
5165
5239
  }
5166
- where(condition) {
5167
- return AsyncIterator.where(this, condition);
5240
+ static forwardSlash() {
5241
+ return _Token.forwardSlashToken;
5168
5242
  }
5169
- whereInstanceOf(typeCheck) {
5170
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5243
+ static period() {
5244
+ return _Token.periodToken;
5171
5245
  }
5172
- whereInstanceOfType(type) {
5173
- return AsyncIterator.whereInstanceOfType(this, type);
5246
+ static underscore() {
5247
+ return _Token.underscoreToken;
5174
5248
  }
5175
- map(mapping) {
5176
- return AsyncIterator.map(this, mapping);
5249
+ static colon() {
5250
+ return _Token.colonToken;
5177
5251
  }
5178
- first(condition) {
5179
- return AsyncIterator.first(this, condition);
5252
+ static letters(text) {
5253
+ return _Token.create(text, TokenType.Letters);
5180
5254
  }
5181
- last(condition) {
5182
- return AsyncIterator.last(this, condition);
5255
+ static digits(text) {
5256
+ return _Token.create(text, TokenType.Digits);
5183
5257
  }
5184
- [Symbol.asyncIterator]() {
5185
- return AsyncIterator[Symbol.asyncIterator](this);
5258
+ static unknown(text) {
5259
+ return _Token.create(text, TokenType.Unknown);
5186
5260
  }
5187
- take(maximumToTake) {
5188
- return AsyncIterator.take(this, maximumToTake);
5261
+ getText() {
5262
+ return this.text;
5189
5263
  }
5190
- skip(maximumToSkip) {
5191
- return AsyncIterator.skip(this, maximumToSkip);
5264
+ getType() {
5265
+ return this.type;
5192
5266
  }
5193
5267
  };
5194
5268
 
5195
- // sources/takeAsyncIterator.ts
5196
- var TakeAsyncIterator = class _TakeAsyncIterator {
5197
- innerIterator;
5269
+ // sources/Tokenizer.ts
5270
+ var Tokenizer = class _Tokenizer {
5271
+ characters;
5272
+ currentToken;
5198
5273
  started;
5199
- maximumToTake;
5200
- taken;
5201
- constructor(innerIterator, maximumToTake) {
5202
- PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
5203
- this.innerIterator = innerIterator;
5274
+ constructor(characters) {
5275
+ this.characters = characters;
5204
5276
  this.started = false;
5205
- this.maximumToTake = maximumToTake;
5206
- this.taken = 0;
5207
5277
  }
5208
- static create(innerIterator, maximumToTake) {
5209
- return new _TakeAsyncIterator(innerIterator, maximumToTake);
5278
+ static create(characters) {
5279
+ PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
5280
+ return new _Tokenizer(isIterator(characters) ? characters : Iterator.create(characters));
5281
+ }
5282
+ hasStarted() {
5283
+ return this.started;
5210
5284
  }
5211
5285
  hasCurrent() {
5212
- return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
5286
+ return this.currentToken !== void 0;
5287
+ }
5288
+ getCurrent() {
5289
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5290
+ return this.currentToken;
5213
5291
  }
5214
5292
  next() {
5215
- return PromiseAsyncResult.create(async () => {
5216
- if (this.maximumToTake <= 0) {
5217
- return false;
5218
- } else if (!this.hasStarted()) {
5293
+ return SyncResult.create(() => {
5294
+ if (!this.hasStarted()) {
5295
+ this.characters.start().await();
5219
5296
  this.started = true;
5220
- await this.innerIterator.start();
5221
- this.taken++;
5222
- } else if (this.taken <= this.maximumToTake) {
5223
- await this.innerIterator.next();
5224
- this.taken++;
5297
+ }
5298
+ if (!this.characters.hasCurrent()) {
5299
+ this.currentToken = void 0;
5300
+ } else {
5301
+ switch (this.characters.getCurrent()) {
5302
+ case " ":
5303
+ case " ":
5304
+ this.currentToken = Token.whitespace(this.readWhile((c) => c === " " || c === " "));
5305
+ break;
5306
+ case "\n":
5307
+ this.characters.next().await();
5308
+ this.currentToken = Token.newLine();
5309
+ break;
5310
+ case "\r":
5311
+ if (this.characters.next().await() && this.characters.getCurrent() === "\n") {
5312
+ this.characters.next().await();
5313
+ this.currentToken = Token.newLine("\r\n");
5314
+ } else {
5315
+ this.currentToken = Token.whitespace("\r");
5316
+ }
5317
+ break;
5318
+ case "(":
5319
+ this.characters.next().await();
5320
+ this.currentToken = Token.leftParenthesis();
5321
+ break;
5322
+ case ")":
5323
+ this.characters.next().await();
5324
+ this.currentToken = Token.rightParenthesis();
5325
+ break;
5326
+ case ".":
5327
+ this.characters.next().await();
5328
+ this.currentToken = Token.period();
5329
+ break;
5330
+ case "_":
5331
+ this.characters.next().await();
5332
+ this.currentToken = Token.underscore();
5333
+ break;
5334
+ case "/":
5335
+ this.characters.next().await();
5336
+ this.currentToken = Token.forwardSlash();
5337
+ break;
5338
+ case "\\":
5339
+ this.characters.next().await();
5340
+ this.currentToken = Token.backslash();
5341
+ break;
5342
+ case ":":
5343
+ this.characters.next().await();
5344
+ this.currentToken = Token.colon();
5345
+ break;
5346
+ default:
5347
+ if (isLetter(this.characters.getCurrent())) {
5348
+ this.currentToken = Token.letters(this.readWhile(isLetter));
5349
+ } else if (isDigit(this.characters.getCurrent())) {
5350
+ this.currentToken = Token.digits(this.readWhile(isDigit));
5351
+ } else {
5352
+ this.currentToken = Token.unknown(this.characters.takeCurrent().await());
5353
+ }
5354
+ break;
5355
+ }
5225
5356
  }
5226
5357
  return this.hasCurrent();
5227
5358
  });
5228
5359
  }
5229
- hasStarted() {
5230
- return this.started;
5231
- }
5232
- getCurrent() {
5233
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5234
- return this.innerIterator.getCurrent();
5360
+ readWhile(condition) {
5361
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5362
+ PreCondition.assertTrue(this.characters.hasCurrent(), "this.characters.hasCurrent()");
5363
+ PreCondition.assertTrue(condition(this.characters.getCurrent()), "condition(this.characters.getCurrent())");
5364
+ let result = "";
5365
+ do {
5366
+ result += this.characters.takeCurrent().await();
5367
+ } while (this.characters.hasCurrent() && condition(this.characters.getCurrent()));
5368
+ return result;
5235
5369
  }
5236
5370
  start() {
5237
- return AsyncIterator.start(this);
5371
+ return Iterator.start(this);
5238
5372
  }
5239
5373
  takeCurrent() {
5240
- return AsyncIterator.takeCurrent(this);
5374
+ return Iterator.takeCurrent(this);
5241
5375
  }
5242
5376
  any() {
5243
- return AsyncIterator.any(this);
5377
+ return Iterator.any(this);
5244
5378
  }
5245
5379
  getCount() {
5246
- return AsyncIterator.getCount(this);
5380
+ return Iterator.getCount(this);
5247
5381
  }
5248
5382
  toArray() {
5249
- return AsyncIterator.toArray(this);
5383
+ return Iterator.toArray(this);
5384
+ }
5385
+ concatenate(...toConcatenate) {
5386
+ return Iterator.concatenate(this, ...toConcatenate);
5250
5387
  }
5251
5388
  where(condition) {
5252
- return AsyncIterator.where(this, condition);
5389
+ return Iterator.where(this, condition);
5390
+ }
5391
+ map(mapping) {
5392
+ return Iterator.map(this, mapping);
5393
+ }
5394
+ flatMap(mapping) {
5395
+ return Iterator.flatMap(this, mapping);
5253
5396
  }
5254
5397
  whereInstanceOf(typeCheck) {
5255
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5398
+ return Iterator.whereInstanceOf(this, typeCheck);
5256
5399
  }
5257
5400
  whereInstanceOfType(type) {
5258
- return AsyncIterator.whereInstanceOfType(this, type);
5259
- }
5260
- map(mapping) {
5261
- return AsyncIterator.map(this, mapping);
5401
+ return Iterator.whereInstanceOfType(this, type);
5262
5402
  }
5263
5403
  first(condition) {
5264
- return AsyncIterator.first(this, condition);
5404
+ return Iterator.first(this, condition);
5265
5405
  }
5266
5406
  last(condition) {
5267
- return AsyncIterator.last(this, condition);
5268
- }
5269
- [Symbol.asyncIterator]() {
5270
- return AsyncIterator[Symbol.asyncIterator](this);
5407
+ return Iterator.last(this, condition);
5271
5408
  }
5272
5409
  take(maximumToTake) {
5273
- return AsyncIterator.take(this, maximumToTake);
5410
+ return Iterator.take(this, maximumToTake);
5274
5411
  }
5275
5412
  skip(maximumToSkip) {
5276
- return AsyncIterator.skip(this, maximumToSkip);
5413
+ return Iterator.skip(this, maximumToSkip);
5414
+ }
5415
+ [Symbol.iterator]() {
5416
+ return Iterator[Symbol.iterator](this);
5277
5417
  }
5278
5418
  };
5279
5419
 
5280
- // sources/whereAsyncIterator.ts
5281
- var WhereAsyncIterator = class _WhereAsyncIterator {
5282
- innerIterator;
5283
- started;
5284
- condition;
5285
- constructor(innerIterator, condition) {
5286
- PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5287
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5288
- this.innerIterator = innerIterator;
5289
- this.started = false;
5290
- this.condition = condition;
5420
+ // sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts
5421
+ var AsyncIteratorToJavascriptAsyncIteratorAdapter = class _AsyncIteratorToJavascriptAsyncIteratorAdapter {
5422
+ iterator;
5423
+ hasStarted;
5424
+ constructor(iterator) {
5425
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5426
+ this.iterator = iterator;
5427
+ this.hasStarted = false;
5291
5428
  }
5292
- hasStarted() {
5293
- return this.started;
5429
+ static create(iterator) {
5430
+ return new _AsyncIteratorToJavascriptAsyncIteratorAdapter(iterator);
5294
5431
  }
5295
- hasCurrent() {
5296
- return this.hasStarted() && this.innerIterator.hasCurrent();
5432
+ async next() {
5433
+ if (!this.hasStarted) {
5434
+ this.hasStarted = true;
5435
+ await this.iterator.start();
5436
+ } else {
5437
+ await this.iterator.next();
5438
+ }
5439
+ const result = {
5440
+ done: !this.iterator.hasCurrent(),
5441
+ value: void 0
5442
+ };
5443
+ if (!result.done) {
5444
+ result.value = this.iterator.getCurrent();
5445
+ }
5446
+ return result;
5297
5447
  }
5298
- getCurrent() {
5299
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5300
- return this.innerIterator.getCurrent();
5448
+ };
5449
+
5450
+ // sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts
5451
+ var JavascriptAsyncIteratorToAsyncIteratorAdapter = class _JavascriptAsyncIteratorToAsyncIteratorAdapter {
5452
+ javascriptIterator;
5453
+ javascriptIteratorResult;
5454
+ constructor(javascriptIterator) {
5455
+ PreCondition.assertNotUndefinedAndNotNull(javascriptIterator, "javascriptIterator");
5456
+ this.javascriptIterator = javascriptIterator;
5301
5457
  }
5302
- static create(innerIterator, condition) {
5303
- return new _WhereAsyncIterator(innerIterator, condition);
5458
+ static create(javascriptIterator) {
5459
+ if (isJavascriptAsyncIterable(javascriptIterator)) {
5460
+ javascriptIterator = javascriptIterator[Symbol.asyncIterator]();
5461
+ }
5462
+ return new _JavascriptAsyncIteratorToAsyncIteratorAdapter(javascriptIterator);
5304
5463
  }
5305
5464
  next() {
5306
5465
  return PromiseAsyncResult.create(async () => {
5307
- if (!this.hasStarted()) {
5308
- await this.innerIterator.start();
5309
- this.started = true;
5310
- while (this.hasCurrent() && !await this.condition(this.getCurrent())) {
5311
- await this.innerIterator.next();
5312
- }
5313
- } else {
5314
- do {
5315
- await this.innerIterator.next();
5316
- } while (this.hasCurrent() && !await this.condition(this.getCurrent()));
5317
- }
5466
+ this.javascriptIteratorResult = await this.javascriptIterator.next();
5318
5467
  return this.hasCurrent();
5319
5468
  });
5320
5469
  }
5470
+ hasStarted() {
5471
+ return this.javascriptIteratorResult !== void 0;
5472
+ }
5473
+ hasCurrent() {
5474
+ return this.javascriptIteratorResult?.done === false;
5475
+ }
5476
+ getCurrent() {
5477
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5478
+ return this.javascriptIteratorResult.value;
5479
+ }
5321
5480
  start() {
5322
5481
  return AsyncIterator.start(this);
5323
5482
  }
@@ -5333,17 +5492,11 @@ var WhereAsyncIterator = class _WhereAsyncIterator {
5333
5492
  toArray() {
5334
5493
  return AsyncIterator.toArray(this);
5335
5494
  }
5336
- where(condition) {
5337
- return AsyncIterator.where(this, condition);
5338
- }
5339
5495
  map(mapping) {
5340
5496
  return AsyncIterator.map(this, mapping);
5341
5497
  }
5342
- whereInstanceOf(typeCheck) {
5343
- return AsyncIterator.whereInstanceOf(this, typeCheck);
5344
- }
5345
- whereInstanceOfType(type) {
5346
- return AsyncIterator.whereInstanceOfType(this, type);
5498
+ [Symbol.asyncIterator]() {
5499
+ return AsyncIterator[Symbol.asyncIterator](this);
5347
5500
  }
5348
5501
  first(condition) {
5349
5502
  return AsyncIterator.first(this, condition);
@@ -5351,565 +5504,223 @@ var WhereAsyncIterator = class _WhereAsyncIterator {
5351
5504
  last(condition) {
5352
5505
  return AsyncIterator.last(this, condition);
5353
5506
  }
5507
+ where(condition) {
5508
+ return AsyncIterator.where(this, condition);
5509
+ }
5510
+ whereInstanceOf(typeCheck) {
5511
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5512
+ }
5513
+ whereInstanceOfType(type) {
5514
+ return AsyncIterator.whereInstanceOfType(this, type);
5515
+ }
5354
5516
  take(maximumToTake) {
5355
5517
  return AsyncIterator.take(this, maximumToTake);
5356
5518
  }
5357
5519
  skip(maximumToSkip) {
5358
5520
  return AsyncIterator.skip(this, maximumToSkip);
5359
5521
  }
5360
- [Symbol.asyncIterator]() {
5361
- return AsyncIterator[Symbol.asyncIterator](this);
5362
- }
5363
5522
  };
5364
5523
 
5365
- // sources/asyncIterator.ts
5366
- var AsyncIterator = class _AsyncIterator {
5367
- static create(iterator) {
5368
- return JavascriptAsyncIteratorToAsyncIteratorAdapter.create(iterator);
5524
+ // sources/mapAsyncIterator.ts
5525
+ var MapAsyncIterator = class _MapAsyncIterator {
5526
+ inputIterator;
5527
+ mapping;
5528
+ current;
5529
+ started;
5530
+ constructor(inputIterator, mapping) {
5531
+ PreCondition.assertNotUndefinedAndNotNull(inputIterator, "inputIterator");
5532
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5533
+ this.inputIterator = inputIterator;
5534
+ this.mapping = mapping;
5535
+ this.started = false;
5369
5536
  }
5370
- /**
5371
- * Move to the first value if this {@link AsyncIterator} hasn't started yet.
5372
- * @returns This object for method chaining.
5373
- */
5374
- start() {
5375
- return _AsyncIterator.start(this);
5537
+ static create(inputIterator, mapping) {
5538
+ return new _MapAsyncIterator(inputIterator, mapping);
5376
5539
  }
5377
- /**
5378
- * Move the provided {@link AsyncIterator} to its first value if it hasn't started yet.
5379
- */
5380
- static start(iterator) {
5381
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5540
+ next() {
5382
5541
  return PromiseAsyncResult.create(async () => {
5383
- if (!iterator.hasStarted()) {
5384
- await iterator.next();
5542
+ if (!this.hasStarted()) {
5543
+ this.started = true;
5544
+ await this.inputIterator.start();
5545
+ } else {
5546
+ await this.inputIterator.next();
5385
5547
  }
5386
- return iterator;
5548
+ const result = this.inputIterator.hasCurrent();
5549
+ this.current = result ? await this.mapping(this.inputIterator.getCurrent()) : void 0;
5550
+ return result;
5387
5551
  });
5388
5552
  }
5389
- /**
5390
- * Get the current value from this {@link AsyncIterator} and advance this {@link AsyncIterator} to the
5391
- * next value.
5392
- */
5393
- takeCurrent() {
5394
- return _AsyncIterator.takeCurrent(this);
5553
+ hasStarted() {
5554
+ return this.started;
5395
5555
  }
5396
- static takeCurrent(iterator) {
5397
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5398
- PreCondition.assertTrue(iterator.hasCurrent(), "iterator.hasCurrent()");
5399
- return PromiseAsyncResult.create(async () => {
5400
- const result = iterator.getCurrent();
5401
- await iterator.next();
5402
- return result;
5403
- });
5556
+ hasCurrent() {
5557
+ return this.hasStarted() && this.inputIterator.hasCurrent();
5404
5558
  }
5405
- [Symbol.asyncIterator]() {
5406
- return _AsyncIterator[Symbol.asyncIterator](this);
5559
+ getCurrent() {
5560
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5561
+ return this.current;
5407
5562
  }
5408
- /**
5409
- * Convert the provided {@link AsyncIterator} to a {@link IteratorToJavascriptIteratorAdapter}.
5410
- * @param iterator The {@link AsyncIterator} to convert.
5411
- */
5412
- static [Symbol.asyncIterator](iterator) {
5413
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5414
- return AsyncIteratorToJavascriptAsyncIteratorAdapter.create(iterator);
5563
+ start() {
5564
+ return AsyncIterator.start(this);
5415
5565
  }
5416
- /**
5417
- * Get whether this {@link AsyncIterator} contains any values.
5418
- * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5419
- * started yet.
5420
- */
5421
- any() {
5422
- return _AsyncIterator.any(this);
5566
+ takeCurrent() {
5567
+ return AsyncIterator.takeCurrent(this);
5423
5568
  }
5424
- /**
5425
- * Get whether this {@link AsyncIterator} contains any values.
5426
- * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5427
- * started yet.
5428
- */
5429
- static any(iterator) {
5430
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5431
- return PromiseAsyncResult.create(async () => {
5432
- await iterator.start();
5433
- return iterator.hasCurrent();
5434
- });
5569
+ any() {
5570
+ return AsyncIterator.any(this);
5435
5571
  }
5436
- /**
5437
- * Get the number of values in this {@link AsyncIterator}.
5438
- * Note: This will consume all of the values in this {@link AsyncIterator}.
5439
- */
5440
5572
  getCount() {
5441
- return _AsyncIterator.getCount(this);
5442
- }
5443
- /**
5444
- * Get the number of values in the provided {@link AsyncIterator}.
5445
- * Note: This will consume all of the values in the provided {@link AsyncIterator}.
5446
- */
5447
- static getCount(iterator) {
5448
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5449
- return PromiseAsyncResult.create(async () => {
5450
- let result = 0;
5451
- if (iterator.hasCurrent()) {
5452
- result++;
5453
- }
5454
- while (await iterator.next()) {
5455
- result++;
5456
- }
5457
- return result;
5458
- });
5573
+ return AsyncIterator.getCount(this);
5459
5574
  }
5460
- /**
5461
- * Get all of the remaining values in this {@link AsyncIterator} in a {@link T} {@link Array}.
5462
- */
5463
5575
  toArray() {
5464
- return _AsyncIterator.toArray(this);
5465
- }
5466
- /**
5467
- * Get all of the remaining values in the provided {@link AsyncIterator} in a {@link T}
5468
- * {@link Array}.
5469
- */
5470
- static toArray(iterator) {
5471
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5472
- return PromiseAsyncResult.create(async () => {
5473
- const result = [];
5474
- if (iterator.hasCurrent()) {
5475
- result.push(iterator.getCurrent());
5476
- }
5477
- while (await iterator.next()) {
5478
- result.push(iterator.getCurrent());
5479
- }
5480
- return result;
5481
- });
5576
+ return AsyncIterator.toArray(this);
5482
5577
  }
5483
- /**
5484
- * Get an {@link AsyncIterator} that will only return values that match the provided condition.
5485
- * @param condition The condition to run against each of the values in this {@link AsyncIterator}.
5486
- */
5487
- where(condition) {
5488
- return _AsyncIterator.where(this, condition);
5578
+ map(mapping) {
5579
+ return AsyncIterator.map(this, mapping);
5489
5580
  }
5490
- static where(iterator, condition) {
5491
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5492
- PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5493
- return WhereAsyncIterator.create(iterator, condition);
5581
+ [Symbol.asyncIterator]() {
5582
+ return AsyncIterator[Symbol.asyncIterator](this);
5494
5583
  }
5495
- /**
5496
- * Get a {@link MapIterator} that will map all {@link T} values from this {@link AsyncIterator} to
5497
- * {@link TOutput} values.
5498
- * @param mapping The mapping that maps {@link T} values to {@link TOutput} values.
5499
- */
5500
- map(mapping) {
5501
- return _AsyncIterator.map(this, mapping);
5584
+ first(condition) {
5585
+ return AsyncIterator.first(this, condition);
5502
5586
  }
5503
- static map(iterator, mapping) {
5504
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5505
- PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
5506
- return MapAsyncIterator.create(iterator, mapping);
5587
+ last() {
5588
+ return AsyncIterator.last(this);
5507
5589
  }
5508
- /**
5509
- * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
5510
- * instances of {@link U} based on the provided type check {@link Function}.
5511
- * @param typeCheck The {@link Function} that will be used to determine if values are of type
5512
- * {@link U}.
5513
- */
5514
- whereInstanceOf(typeCheck) {
5515
- return _AsyncIterator.whereInstanceOf(this, typeCheck);
5590
+ where(condition) {
5591
+ return AsyncIterator.where(this, condition);
5516
5592
  }
5517
- static whereInstanceOf(iterator, typeCheck) {
5518
- PreCondition.assertNotUndefinedAndNotNull(typeCheck, "typeCheck");
5519
- return iterator.where(typeCheck).map((value) => value);
5593
+ whereInstanceOf(typeCheck) {
5594
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5520
5595
  }
5521
- /**
5522
- * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
5523
- * instances of the provided {@link Type}.
5524
- * @param type The type of values to return from the new {@link AsyncIterator}.
5525
- */
5526
5596
  whereInstanceOfType(type) {
5527
- return _AsyncIterator.whereInstanceOfType(this, type);
5597
+ return AsyncIterator.whereInstanceOfType(this, type);
5528
5598
  }
5529
- static whereInstanceOfType(iterator, type) {
5530
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
5531
- return iterator.whereInstanceOf((value) => instanceOfType(value, type));
5599
+ take(maximumToTake) {
5600
+ return AsyncIterator.take(this, maximumToTake);
5532
5601
  }
5533
- /**
5534
- * If the condition function is undefined, then this function will return the first value in
5535
- * this {@link AsyncIterator}. If this condition function is provided, then this function will return
5536
- * the first value that matches the provided condition.
5537
- * @param condition The condition that the returned value must satisfy.
5538
- */
5539
- first(condition) {
5540
- return _AsyncIterator.first(this, condition);
5602
+ skip(maximumToSkip) {
5603
+ return AsyncIterator.skip(this, maximumToSkip);
5541
5604
  }
5542
- /**
5543
- * If the condition function is undefined, then this function will return the first value in
5544
- * the {@link AsyncIterator}. If this condition function is provided, then this function will return
5545
- * the first value that matches the provided condition.
5546
- * @param iterator The {@link AsyncIterator} to get the first value from.
5547
- */
5548
- static first(iterator, condition) {
5549
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5550
- return PromiseAsyncResult.create(async () => {
5551
- await iterator.start();
5552
- if (isUndefinedOrNull(condition)) {
5553
- if (!iterator.hasCurrent()) {
5554
- throw new EmptyError();
5555
- }
5556
- } else {
5557
- while (iterator.hasCurrent() && !await condition(iterator.getCurrent())) {
5558
- await iterator.next();
5559
- }
5560
- if (!iterator.hasCurrent()) {
5561
- throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
5562
- }
5563
- }
5564
- return iterator.getCurrent();
5565
- });
5605
+ };
5606
+
5607
+ // sources/skipAsyncIterator.ts
5608
+ var SkipAsyncIterator = class _SkipAsyncIterator {
5609
+ innerIterator;
5610
+ started;
5611
+ maximumToSkip;
5612
+ constructor(innerIterator, maximumToSkip) {
5613
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5614
+ PreCondition.assertNotUndefinedAndNotNull(maximumToSkip, "maximumToSkip");
5615
+ PreCondition.assertInteger(maximumToSkip, "maximumToSkip");
5616
+ PreCondition.assertGreaterThanOrEqualTo(maximumToSkip, 0, "maximumToSkip");
5617
+ this.innerIterator = innerIterator;
5618
+ this.started = false;
5619
+ this.maximumToSkip = maximumToSkip;
5566
5620
  }
5567
- /**
5568
- * If the condition function is undefined, then this function will return the last value in this
5569
- * {@link AsyncIterator}. If this condition function is provided, then this function will return the
5570
- * last value that matches the provided condition.
5571
- * @param condition The condition that the returned value must satisfy.
5572
- */
5573
- last(condition) {
5574
- return _AsyncIterator.last(this, condition);
5621
+ static create(innerIterator, maximumToSkip) {
5622
+ return new _SkipAsyncIterator(innerIterator, maximumToSkip);
5575
5623
  }
5576
- /**
5577
- * If the condition function is undefined, then this function will return the last value in the
5578
- * {@link AsyncIterator}. If this condition function is provided, then this function will return the
5579
- * last value that matches the provided condition.
5580
- * @param iterator The {@link AsyncIterator} to get the last value from.
5581
- */
5582
- static last(iterator, condition) {
5583
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5624
+ next() {
5584
5625
  return PromiseAsyncResult.create(async () => {
5585
- await iterator.start();
5586
- if (!iterator.hasCurrent()) {
5587
- throw new EmptyError();
5588
- }
5589
- let result;
5590
- let found = false;
5591
- do {
5592
- if (!condition || await condition(iterator.getCurrent())) {
5593
- result = iterator.getCurrent();
5594
- found = true;
5595
- }
5596
- } while (await iterator.next());
5597
- if (!found) {
5598
- if (!condition) {
5599
- throw new EmptyError();
5600
- } else {
5601
- throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
5626
+ if (!this.hasStarted()) {
5627
+ this.started = true;
5628
+ await this.innerIterator.start();
5629
+ for (let i = 0; i < this.maximumToSkip; i++) {
5630
+ if (!await this.innerIterator.next()) {
5631
+ break;
5632
+ }
5602
5633
  }
5634
+ } else {
5635
+ await this.innerIterator.next();
5603
5636
  }
5604
- return result;
5637
+ return this.hasCurrent();
5605
5638
  });
5606
5639
  }
5607
- /**
5608
- * Find the maximum value in the provided {@link AsyncIterator}.
5609
- * @param iterator The values to find the maximum of.
5610
- */
5611
- static findMaximum(iterator) {
5612
- PreCondition.assertNotUndefinedAndNotNull(iterator, "iterable");
5613
- return PromiseAsyncResult.create(async () => {
5614
- if (isJavascriptAsyncIterator(iterator)) {
5615
- iterator = _AsyncIterator.create(iterator);
5616
- }
5617
- let result = await iterator.first().convertError(EmptyError, () => new EmptyError("Can't find the maximum of an empty Iterator."));
5618
- while (await iterator.next()) {
5619
- const currentValue = iterator.getCurrent();
5620
- if (result.lessThan(currentValue)) {
5621
- result = currentValue;
5622
- }
5623
- }
5624
- return result;
5625
- });
5640
+ hasStarted() {
5641
+ return this.started;
5626
5642
  }
5627
- /**
5628
- * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and only
5629
- * returns a maximum number of values from this {@link AsyncIterator}.
5630
- * @param maximumToTake The maximum number of values to take from this {@link AsyncIterator}.
5631
- */
5632
- take(maximumToTake) {
5633
- return _AsyncIterator.take(this, maximumToTake);
5643
+ hasCurrent() {
5644
+ return this.hasStarted() && this.innerIterator.hasCurrent();
5634
5645
  }
5635
- static take(iterator, maximumToTake) {
5636
- return TakeAsyncIterator.create(iterator, maximumToTake);
5646
+ getCurrent() {
5647
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5648
+ return this.innerIterator.getCurrent();
5637
5649
  }
5638
- /**
5639
- * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and will skip the initial
5640
- * provided number of values before beginning to return values.
5641
- * @param maximumToSkip The maximum number of values to skip from this {@link AsyncIterator}.
5642
- */
5643
- skip(maximumToSkip) {
5644
- return _AsyncIterator.skip(this, maximumToSkip);
5650
+ start() {
5651
+ return AsyncIterator.start(this);
5645
5652
  }
5646
- static skip(iterator, maximumToSkip) {
5647
- return SkipAsyncIterator.create(iterator, maximumToSkip);
5653
+ takeCurrent() {
5654
+ return AsyncIterator.takeCurrent(this);
5648
5655
  }
5649
- };
5650
-
5651
- // sources/basicDisposable.ts
5652
- var SyncDisposable = class _SyncDisposable {
5653
- disposedFunction;
5654
- disposed;
5655
- constructor(disposedFunction) {
5656
- PreCondition.assertNotUndefinedAndNotNull(disposedFunction, "disposedFunction");
5657
- this.disposedFunction = disposedFunction;
5658
- this.disposed = false;
5656
+ any() {
5657
+ return AsyncIterator.any(this);
5659
5658
  }
5660
- /**
5661
- * Create a new {@link Disposable} that will invoke the provided {@link Function} when it is
5662
- * disposed.
5663
- * @param disposedFunction The function to invoke when the returned {@link Disposable} is
5664
- * disposed.
5665
- */
5666
- static create(disposedFunction) {
5667
- return new _SyncDisposable(disposedFunction);
5659
+ getCount() {
5660
+ return AsyncIterator.getCount(this);
5668
5661
  }
5669
- dispose() {
5670
- return SyncResult.create(() => {
5671
- const result = !this.disposed;
5672
- if (result) {
5673
- try {
5674
- this.disposedFunction();
5675
- } finally {
5676
- this.disposed = true;
5677
- }
5678
- }
5679
- return result;
5680
- });
5662
+ toArray() {
5663
+ return AsyncIterator.toArray(this);
5681
5664
  }
5682
- isDisposed() {
5683
- return this.disposed;
5665
+ where(condition) {
5666
+ return AsyncIterator.where(this, condition);
5684
5667
  }
5685
- };
5686
-
5687
- // sources/byteList.ts
5688
- var ByteList = class _ByteList {
5689
- bytes;
5690
- count;
5691
- constructor() {
5692
- this.bytes = new Uint8Array(0);
5693
- this.count = 0;
5668
+ whereInstanceOf(typeCheck) {
5669
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5694
5670
  }
5695
- static create(initialValues) {
5696
- const result = new _ByteList();
5697
- if (initialValues) {
5698
- result.addAll(initialValues);
5699
- }
5700
- return result;
5671
+ whereInstanceOfType(type) {
5672
+ return AsyncIterator.whereInstanceOfType(this, type);
5701
5673
  }
5702
- add(value) {
5703
- return List.add(this, value);
5674
+ map(mapping) {
5675
+ return AsyncIterator.map(this, mapping);
5704
5676
  }
5705
- addAll(values) {
5706
- return List.addAll(this, values);
5707
- }
5708
- insert(index, value) {
5709
- PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
5710
- PreCondition.assertByte(value, "value");
5711
- if (this.count < this.bytes.length) {
5712
- if (index < this.count) {
5713
- this.bytes.copyWithin(index + 1, index, this.count);
5714
- }
5715
- this.bytes[index] = value;
5716
- } else {
5717
- const newCapacity = this.bytes.length * 2 + 1;
5718
- const newBytes = new Uint8Array(newCapacity);
5719
- if (index > 0) {
5720
- newBytes.set(this.bytes.subarray(0, index));
5721
- }
5722
- newBytes[index] = value;
5723
- if (index < this.count) {
5724
- newBytes.set(this.bytes.subarray(index), index + 1);
5725
- }
5726
- this.bytes = newBytes;
5727
- }
5728
- this.count++;
5729
- return this;
5730
- }
5731
- insertAll(index, values) {
5732
- return List.insertAll(this, index, values);
5733
- }
5734
- remove(value, equalFunctions) {
5735
- PreCondition.assertByte(value, "value");
5736
- return List.remove(this, value, equalFunctions);
5737
- }
5738
- removeAt(index) {
5739
- PreCondition.assertAccessIndex(index, this.count, "index");
5740
- const result = this.bytes[index];
5741
- this.bytes.copyWithin(index, index + 1, this.count);
5742
- this.count--;
5743
- return SyncResult.value(result);
5744
- }
5745
- removeFirst() {
5746
- return List.removeFirst(this);
5747
- }
5748
- removeLast() {
5749
- return List.removeLast(this);
5750
- }
5751
- set(index, value) {
5752
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
5753
- PreCondition.assertByte(value, "value");
5754
- this.bytes[index] = value;
5755
- return this;
5756
- }
5757
- iterate() {
5758
- return Iterator.create(this.bytes[Symbol.iterator]().take(this.count));
5759
- }
5760
- get(index) {
5761
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
5762
- return SyncResult.value(this.bytes.at(index));
5763
- }
5764
- toArray() {
5765
- return List.toArray(this);
5766
- }
5767
- any() {
5768
- return this.getCount().then((count) => count > 0);
5769
- }
5770
- getCount() {
5771
- return SyncResult.value(this.count);
5772
- }
5773
- equals(right, equalFunctions) {
5774
- return List.equals(this, right, equalFunctions);
5775
- }
5776
- toString(toStringFunctions) {
5777
- return List.toString(this, toStringFunctions);
5778
- }
5779
- concatenate(...toConcatenate) {
5780
- return List.concatenate(this, ...toConcatenate);
5781
- }
5782
- map(mapping) {
5783
- return List.map(this, mapping);
5784
- }
5785
- flatMap(mapping) {
5786
- return List.flatMap(this, mapping);
5787
- }
5788
- where(condition) {
5789
- return List.where(this, condition);
5790
- }
5791
- instanceOf(typeOrTypeCheck) {
5792
- return List.instanceOf(this, typeOrTypeCheck);
5793
- }
5794
- first(condition) {
5795
- return List.first(this, condition);
5677
+ first(condition) {
5678
+ return AsyncIterator.first(this, condition);
5796
5679
  }
5797
5680
  last(condition) {
5798
- return List.last(this, condition);
5799
- }
5800
- contains(value, equalFunctions) {
5801
- return List.contains(this, value, equalFunctions);
5802
- }
5803
- [Symbol.iterator]() {
5804
- return List[Symbol.iterator](this);
5805
- }
5806
- };
5807
-
5808
- // sources/byteListStream.ts
5809
- var ByteListStream = class _ByteListStream {
5810
- list;
5811
- constructor() {
5812
- this.list = ByteList.create();
5813
- }
5814
- static create(initialValues) {
5815
- const result = new _ByteListStream();
5816
- if (initialValues) {
5817
- result.writeBytes(initialValues).await();
5818
- }
5819
- return result;
5681
+ return AsyncIterator.last(this, condition);
5820
5682
  }
5821
- /**
5822
- * Get the number of bytes that are available to be read.
5823
- */
5824
- getAvailableByteCount() {
5825
- return this.list.getCount().await();
5683
+ [Symbol.asyncIterator]() {
5684
+ return AsyncIterator[Symbol.asyncIterator](this);
5826
5685
  }
5827
- writeBytes(bytes, startIndex, length) {
5828
- PreCondition.assertNotUndefinedAndNotNull(bytes, "bytes");
5829
- if (isArray(bytes)) {
5830
- bytes = new Uint8Array(bytes);
5831
- }
5832
- if (isUndefinedOrNull(startIndex)) {
5833
- startIndex = 0;
5834
- }
5835
- if (isUndefinedOrNull(length)) {
5836
- length = bytes.length - startIndex;
5837
- }
5838
- PreCondition.assertInsertIndex(startIndex, bytes.length, "startIndex");
5839
- PreCondition.assertBetween(0, length, bytes.length - startIndex, "length");
5840
- this.list.addAll(bytes.subarray(startIndex, length + startIndex));
5841
- return SyncResult.value(length);
5686
+ take(maximumToTake) {
5687
+ return AsyncIterator.take(this, maximumToTake);
5842
5688
  }
5843
- readBytes(countOrOutput, startIndex, count) {
5844
- let result;
5845
- if (isNumber(countOrOutput)) {
5846
- PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
5847
- if (!this.list.any().await()) {
5848
- result = SyncResult.error(new EmptyError());
5849
- } else {
5850
- const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
5851
- const output = new Uint8Array(bytesReadCount);
5852
- for (let i = 0; i < bytesReadCount; i++) {
5853
- output[i] = this.list.removeFirst().await();
5854
- }
5855
- result = SyncResult.value(output);
5856
- }
5857
- } else {
5858
- PreCondition.assertNotUndefinedAndNotNull(countOrOutput, "output");
5859
- if (isUndefinedOrNull(startIndex)) {
5860
- startIndex = 0;
5861
- }
5862
- if (isUndefinedOrNull(count)) {
5863
- count = countOrOutput.length - startIndex;
5864
- }
5865
- PreCondition.assertInsertIndex(startIndex, countOrOutput.length, "startIndex");
5866
- PreCondition.assertBetween(0, count, countOrOutput.length - startIndex, "count");
5867
- if (!this.list.any().await()) {
5868
- result = SyncResult.error(new EmptyError());
5869
- } else {
5870
- const bytesReadCount = Math.min(count, this.list.getCount().await());
5871
- for (let i = 0; i < bytesReadCount; i++) {
5872
- countOrOutput[startIndex + i] = this.list.removeFirst().await();
5873
- }
5874
- result = SyncResult.value(bytesReadCount);
5875
- }
5876
- }
5877
- return result;
5689
+ skip(maximumToSkip) {
5690
+ return AsyncIterator.skip(this, maximumToSkip);
5878
5691
  }
5879
5692
  };
5880
5693
 
5881
- // sources/byteReadStream.ts
5882
- var ByteReadStream = class {
5883
- };
5884
-
5885
- // sources/byteWriteStream.ts
5886
- var ByteWriteStream = class {
5887
- };
5888
-
5889
- // sources/stringIterator.ts
5890
- var StringIterator = class _StringIterator {
5891
- value;
5892
- currentIndex;
5694
+ // sources/takeAsyncIterator.ts
5695
+ var TakeAsyncIterator = class _TakeAsyncIterator {
5696
+ innerIterator;
5893
5697
  started;
5894
- constructor(value) {
5895
- this.value = value;
5896
- this.currentIndex = 0;
5698
+ maximumToTake;
5699
+ taken;
5700
+ constructor(innerIterator, maximumToTake) {
5701
+ PreCondition.assertGreaterThanOrEqualTo(maximumToTake, 0, "maximumToTake");
5702
+ this.innerIterator = innerIterator;
5897
5703
  this.started = false;
5704
+ this.maximumToTake = maximumToTake;
5705
+ this.taken = 0;
5898
5706
  }
5899
- static create(value) {
5900
- PreCondition.assertNotUndefinedAndNotNull(value, "value");
5901
- return new _StringIterator(value);
5707
+ static create(innerIterator, maximumToTake) {
5708
+ return new _TakeAsyncIterator(innerIterator, maximumToTake);
5902
5709
  }
5903
- getCurrentIndex() {
5904
- PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5905
- return this.currentIndex;
5710
+ hasCurrent() {
5711
+ return this.hasStarted() && this.taken <= this.maximumToTake && this.innerIterator.hasCurrent();
5906
5712
  }
5907
5713
  next() {
5908
- return SyncResult.create(() => {
5909
- if (!this.hasStarted()) {
5714
+ return PromiseAsyncResult.create(async () => {
5715
+ if (this.maximumToTake <= 0) {
5716
+ return false;
5717
+ } else if (!this.hasStarted()) {
5910
5718
  this.started = true;
5911
- } else if (this.hasCurrent()) {
5912
- this.currentIndex++;
5719
+ await this.innerIterator.start();
5720
+ this.taken++;
5721
+ } else if (this.taken <= this.maximumToTake) {
5722
+ await this.innerIterator.next();
5723
+ this.taken++;
5913
5724
  }
5914
5725
  return this.hasCurrent();
5915
5726
  });
@@ -5917,111 +5728,475 @@ var StringIterator = class _StringIterator {
5917
5728
  hasStarted() {
5918
5729
  return this.started;
5919
5730
  }
5920
- hasCurrent() {
5921
- return this.hasStarted() && this.currentIndex < this.value.length;
5922
- }
5923
5731
  getCurrent() {
5924
5732
  PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5925
- return this.value[this.currentIndex];
5733
+ return this.innerIterator.getCurrent();
5926
5734
  }
5927
5735
  start() {
5928
- return Iterator.start(this);
5736
+ return AsyncIterator.start(this);
5929
5737
  }
5930
5738
  takeCurrent() {
5931
- return Iterator.takeCurrent(this);
5739
+ return AsyncIterator.takeCurrent(this);
5932
5740
  }
5933
5741
  any() {
5934
- return Iterator.any(this);
5742
+ return AsyncIterator.any(this);
5935
5743
  }
5936
5744
  getCount() {
5937
- return Iterator.getCount(this);
5745
+ return AsyncIterator.getCount(this);
5938
5746
  }
5939
5747
  toArray() {
5940
- return Iterator.toArray(this);
5941
- }
5942
- concatenate(...toConcatenate) {
5943
- return Iterator.concatenate(this, ...toConcatenate);
5944
- }
5945
- map(mapping) {
5946
- return Iterator.map(this, mapping);
5947
- }
5948
- flatMap(mapping) {
5949
- return Iterator.flatMap(this, mapping);
5950
- }
5951
- first() {
5952
- return Iterator.first(this);
5953
- }
5954
- last() {
5955
- return Iterator.last(this);
5748
+ return AsyncIterator.toArray(this);
5956
5749
  }
5957
5750
  where(condition) {
5958
- return Iterator.where(this, condition);
5751
+ return AsyncIterator.where(this, condition);
5959
5752
  }
5960
5753
  whereInstanceOf(typeCheck) {
5961
- return Iterator.whereInstanceOf(this, typeCheck);
5754
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5962
5755
  }
5963
5756
  whereInstanceOfType(type) {
5964
- return Iterator.whereInstanceOfType(this, type);
5757
+ return AsyncIterator.whereInstanceOfType(this, type);
5965
5758
  }
5966
- take(maximumToTake) {
5967
- return Iterator.take(this, maximumToTake);
5759
+ map(mapping) {
5760
+ return AsyncIterator.map(this, mapping);
5761
+ }
5762
+ first(condition) {
5763
+ return AsyncIterator.first(this, condition);
5764
+ }
5765
+ last(condition) {
5766
+ return AsyncIterator.last(this, condition);
5767
+ }
5768
+ [Symbol.asyncIterator]() {
5769
+ return AsyncIterator[Symbol.asyncIterator](this);
5770
+ }
5771
+ take(maximumToTake) {
5772
+ return AsyncIterator.take(this, maximumToTake);
5968
5773
  }
5969
5774
  skip(maximumToSkip) {
5970
- return Iterator.skip(this, maximumToSkip);
5775
+ return AsyncIterator.skip(this, maximumToSkip);
5971
5776
  }
5972
- [Symbol.iterator]() {
5973
- return Iterator[Symbol.iterator](this);
5777
+ };
5778
+
5779
+ // sources/whereAsyncIterator.ts
5780
+ var WhereAsyncIterator = class _WhereAsyncIterator {
5781
+ innerIterator;
5782
+ started;
5783
+ condition;
5784
+ constructor(innerIterator, condition) {
5785
+ PreCondition.assertNotUndefinedAndNotNull(innerIterator, "innerIterator");
5786
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5787
+ this.innerIterator = innerIterator;
5788
+ this.started = false;
5789
+ this.condition = condition;
5790
+ }
5791
+ hasStarted() {
5792
+ return this.started;
5793
+ }
5794
+ hasCurrent() {
5795
+ return this.hasStarted() && this.innerIterator.hasCurrent();
5796
+ }
5797
+ getCurrent() {
5798
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
5799
+ return this.innerIterator.getCurrent();
5800
+ }
5801
+ static create(innerIterator, condition) {
5802
+ return new _WhereAsyncIterator(innerIterator, condition);
5803
+ }
5804
+ next() {
5805
+ return PromiseAsyncResult.create(async () => {
5806
+ if (!this.hasStarted()) {
5807
+ await this.innerIterator.start();
5808
+ this.started = true;
5809
+ while (this.hasCurrent() && !await this.condition(this.getCurrent())) {
5810
+ await this.innerIterator.next();
5811
+ }
5812
+ } else {
5813
+ do {
5814
+ await this.innerIterator.next();
5815
+ } while (this.hasCurrent() && !await this.condition(this.getCurrent()));
5816
+ }
5817
+ return this.hasCurrent();
5818
+ });
5819
+ }
5820
+ start() {
5821
+ return AsyncIterator.start(this);
5822
+ }
5823
+ takeCurrent() {
5824
+ return AsyncIterator.takeCurrent(this);
5825
+ }
5826
+ any() {
5827
+ return AsyncIterator.any(this);
5828
+ }
5829
+ getCount() {
5830
+ return AsyncIterator.getCount(this);
5831
+ }
5832
+ toArray() {
5833
+ return AsyncIterator.toArray(this);
5834
+ }
5835
+ where(condition) {
5836
+ return AsyncIterator.where(this, condition);
5837
+ }
5838
+ map(mapping) {
5839
+ return AsyncIterator.map(this, mapping);
5840
+ }
5841
+ whereInstanceOf(typeCheck) {
5842
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
5843
+ }
5844
+ whereInstanceOfType(type) {
5845
+ return AsyncIterator.whereInstanceOfType(this, type);
5846
+ }
5847
+ first(condition) {
5848
+ return AsyncIterator.first(this, condition);
5849
+ }
5850
+ last(condition) {
5851
+ return AsyncIterator.last(this, condition);
5852
+ }
5853
+ take(maximumToTake) {
5854
+ return AsyncIterator.take(this, maximumToTake);
5855
+ }
5856
+ skip(maximumToSkip) {
5857
+ return AsyncIterator.skip(this, maximumToSkip);
5858
+ }
5859
+ [Symbol.asyncIterator]() {
5860
+ return AsyncIterator[Symbol.asyncIterator](this);
5974
5861
  }
5975
5862
  };
5976
5863
 
5977
- // sources/characterList.ts
5978
- var CharacterList = class _CharacterList {
5979
- characters;
5980
- constructor(values) {
5981
- if (isString(values)) {
5982
- this.characters = values;
5983
- } else if (values) {
5984
- this.characters = join("", values);
5985
- } else {
5986
- this.characters = "";
5987
- }
5864
+ // sources/asyncIterator.ts
5865
+ var AsyncIterator = class _AsyncIterator {
5866
+ static create(iterator) {
5867
+ return JavascriptAsyncIteratorToAsyncIteratorAdapter.create(iterator);
5988
5868
  }
5989
- static create(values) {
5990
- return new _CharacterList(values);
5869
+ /**
5870
+ * Move to the first value if this {@link AsyncIterator} hasn't started yet.
5871
+ * @returns This object for method chaining.
5872
+ */
5873
+ start() {
5874
+ return _AsyncIterator.start(this);
5875
+ }
5876
+ /**
5877
+ * Move the provided {@link AsyncIterator} to its first value if it hasn't started yet.
5878
+ */
5879
+ static start(iterator) {
5880
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5881
+ return PromiseAsyncResult.create(async () => {
5882
+ if (!iterator.hasStarted()) {
5883
+ await iterator.next();
5884
+ }
5885
+ return iterator;
5886
+ });
5887
+ }
5888
+ /**
5889
+ * Get the current value from this {@link AsyncIterator} and advance this {@link AsyncIterator} to the
5890
+ * next value.
5891
+ */
5892
+ takeCurrent() {
5893
+ return _AsyncIterator.takeCurrent(this);
5894
+ }
5895
+ static takeCurrent(iterator) {
5896
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5897
+ PreCondition.assertTrue(iterator.hasCurrent(), "iterator.hasCurrent()");
5898
+ return PromiseAsyncResult.create(async () => {
5899
+ const result = iterator.getCurrent();
5900
+ await iterator.next();
5901
+ return result;
5902
+ });
5903
+ }
5904
+ [Symbol.asyncIterator]() {
5905
+ return _AsyncIterator[Symbol.asyncIterator](this);
5991
5906
  }
5907
+ /**
5908
+ * Convert the provided {@link AsyncIterator} to a {@link IteratorToJavascriptIteratorAdapter}.
5909
+ * @param iterator The {@link AsyncIterator} to convert.
5910
+ */
5911
+ static [Symbol.asyncIterator](iterator) {
5912
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5913
+ return AsyncIteratorToJavascriptAsyncIteratorAdapter.create(iterator);
5914
+ }
5915
+ /**
5916
+ * Get whether this {@link AsyncIterator} contains any values.
5917
+ * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5918
+ * started yet.
5919
+ */
5920
+ any() {
5921
+ return _AsyncIterator.any(this);
5922
+ }
5923
+ /**
5924
+ * Get whether this {@link AsyncIterator} contains any values.
5925
+ * Note: This may advance the {@link AsyncIterator} to the first value if it hasn't been
5926
+ * started yet.
5927
+ */
5928
+ static any(iterator) {
5929
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5930
+ return PromiseAsyncResult.create(async () => {
5931
+ await iterator.start();
5932
+ return iterator.hasCurrent();
5933
+ });
5934
+ }
5935
+ /**
5936
+ * Get the number of values in this {@link AsyncIterator}.
5937
+ * Note: This will consume all of the values in this {@link AsyncIterator}.
5938
+ */
5992
5939
  getCount() {
5993
- return SyncResult.value(this.characters.length);
5940
+ return _AsyncIterator.getCount(this);
5994
5941
  }
5995
- insert(index, value) {
5996
- PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
5997
- PreCondition.assertCharacter(value, "value");
5998
- if (index === 0) {
5999
- this.characters = value + this.characters;
6000
- } else if (index === this.getCount().await()) {
6001
- this.characters += value;
6002
- } else {
6003
- this.characters = this.characters.slice(0, index) + value + this.characters.slice(index);
6004
- }
6005
- return this;
5942
+ /**
5943
+ * Get the number of values in the provided {@link AsyncIterator}.
5944
+ * Note: This will consume all of the values in the provided {@link AsyncIterator}.
5945
+ */
5946
+ static getCount(iterator) {
5947
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5948
+ return PromiseAsyncResult.create(async () => {
5949
+ let result = 0;
5950
+ if (iterator.hasCurrent()) {
5951
+ result++;
5952
+ }
5953
+ while (await iterator.next()) {
5954
+ result++;
5955
+ }
5956
+ return result;
5957
+ });
5958
+ }
5959
+ /**
5960
+ * Get all of the remaining values in this {@link AsyncIterator} in a {@link T} {@link Array}.
5961
+ */
5962
+ toArray() {
5963
+ return _AsyncIterator.toArray(this);
5964
+ }
5965
+ /**
5966
+ * Get all of the remaining values in the provided {@link AsyncIterator} in a {@link T}
5967
+ * {@link Array}.
5968
+ */
5969
+ static toArray(iterator) {
5970
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5971
+ return PromiseAsyncResult.create(async () => {
5972
+ const result = [];
5973
+ if (iterator.hasCurrent()) {
5974
+ result.push(iterator.getCurrent());
5975
+ }
5976
+ while (await iterator.next()) {
5977
+ result.push(iterator.getCurrent());
5978
+ }
5979
+ return result;
5980
+ });
5981
+ }
5982
+ /**
5983
+ * Get an {@link AsyncIterator} that will only return values that match the provided condition.
5984
+ * @param condition The condition to run against each of the values in this {@link AsyncIterator}.
5985
+ */
5986
+ where(condition) {
5987
+ return _AsyncIterator.where(this, condition);
5988
+ }
5989
+ static where(iterator, condition) {
5990
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
5991
+ PreCondition.assertNotUndefinedAndNotNull(condition, "condition");
5992
+ return WhereAsyncIterator.create(iterator, condition);
5993
+ }
5994
+ /**
5995
+ * Get a {@link MapIterator} that will map all {@link T} values from this {@link AsyncIterator} to
5996
+ * {@link TOutput} values.
5997
+ * @param mapping The mapping that maps {@link T} values to {@link TOutput} values.
5998
+ */
5999
+ map(mapping) {
6000
+ return _AsyncIterator.map(this, mapping);
6001
+ }
6002
+ static map(iterator, mapping) {
6003
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6004
+ PreCondition.assertNotUndefinedAndNotNull(mapping, "mapping");
6005
+ return MapAsyncIterator.create(iterator, mapping);
6006
+ }
6007
+ /**
6008
+ * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
6009
+ * instances of {@link U} based on the provided type check {@link Function}.
6010
+ * @param typeCheck The {@link Function} that will be used to determine if values are of type
6011
+ * {@link U}.
6012
+ */
6013
+ whereInstanceOf(typeCheck) {
6014
+ return _AsyncIterator.whereInstanceOf(this, typeCheck);
6015
+ }
6016
+ static whereInstanceOf(iterator, typeCheck) {
6017
+ PreCondition.assertNotUndefinedAndNotNull(typeCheck, "typeCheck");
6018
+ return iterator.where(typeCheck).map((value) => value);
6019
+ }
6020
+ /**
6021
+ * Get an {@link AsyncIterator} that will filter this {@link AsyncIterator} to only the values that are
6022
+ * instances of the provided {@link Type}.
6023
+ * @param type The type of values to return from the new {@link AsyncIterator}.
6024
+ */
6025
+ whereInstanceOfType(type) {
6026
+ return _AsyncIterator.whereInstanceOfType(this, type);
6027
+ }
6028
+ static whereInstanceOfType(iterator, type) {
6029
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
6030
+ return iterator.whereInstanceOf((value) => instanceOfType(value, type));
6031
+ }
6032
+ /**
6033
+ * If the condition function is undefined, then this function will return the first value in
6034
+ * this {@link AsyncIterator}. If this condition function is provided, then this function will return
6035
+ * the first value that matches the provided condition.
6036
+ * @param condition The condition that the returned value must satisfy.
6037
+ */
6038
+ first(condition) {
6039
+ return _AsyncIterator.first(this, condition);
6040
+ }
6041
+ /**
6042
+ * If the condition function is undefined, then this function will return the first value in
6043
+ * the {@link AsyncIterator}. If this condition function is provided, then this function will return
6044
+ * the first value that matches the provided condition.
6045
+ * @param iterator The {@link AsyncIterator} to get the first value from.
6046
+ */
6047
+ static first(iterator, condition) {
6048
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6049
+ return PromiseAsyncResult.create(async () => {
6050
+ await iterator.start();
6051
+ if (isUndefinedOrNull(condition)) {
6052
+ if (!iterator.hasCurrent()) {
6053
+ throw new EmptyError();
6054
+ }
6055
+ } else {
6056
+ while (iterator.hasCurrent() && !await condition(iterator.getCurrent())) {
6057
+ await iterator.next();
6058
+ }
6059
+ if (!iterator.hasCurrent()) {
6060
+ throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
6061
+ }
6062
+ }
6063
+ return iterator.getCurrent();
6064
+ });
6065
+ }
6066
+ /**
6067
+ * If the condition function is undefined, then this function will return the last value in this
6068
+ * {@link AsyncIterator}. If this condition function is provided, then this function will return the
6069
+ * last value that matches the provided condition.
6070
+ * @param condition The condition that the returned value must satisfy.
6071
+ */
6072
+ last(condition) {
6073
+ return _AsyncIterator.last(this, condition);
6074
+ }
6075
+ /**
6076
+ * If the condition function is undefined, then this function will return the last value in the
6077
+ * {@link AsyncIterator}. If this condition function is provided, then this function will return the
6078
+ * last value that matches the provided condition.
6079
+ * @param iterator The {@link AsyncIterator} to get the last value from.
6080
+ */
6081
+ static last(iterator, condition) {
6082
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterator");
6083
+ return PromiseAsyncResult.create(async () => {
6084
+ await iterator.start();
6085
+ if (!iterator.hasCurrent()) {
6086
+ throw new EmptyError();
6087
+ }
6088
+ let result;
6089
+ let found = false;
6090
+ do {
6091
+ if (!condition || await condition(iterator.getCurrent())) {
6092
+ result = iterator.getCurrent();
6093
+ found = true;
6094
+ }
6095
+ } while (await iterator.next());
6096
+ if (!found) {
6097
+ if (!condition) {
6098
+ throw new EmptyError();
6099
+ } else {
6100
+ throw new NotFoundError("No value was found in the AsyncIterator that matched the provided condition.");
6101
+ }
6102
+ }
6103
+ return result;
6104
+ });
6105
+ }
6106
+ /**
6107
+ * Find the maximum value in the provided {@link AsyncIterator}.
6108
+ * @param iterator The values to find the maximum of.
6109
+ */
6110
+ static findMaximum(iterator) {
6111
+ PreCondition.assertNotUndefinedAndNotNull(iterator, "iterable");
6112
+ return PromiseAsyncResult.create(async () => {
6113
+ if (isJavascriptAsyncIterator(iterator)) {
6114
+ iterator = _AsyncIterator.create(iterator);
6115
+ }
6116
+ let result = await iterator.first().convertError(EmptyError, () => new EmptyError("Can't find the maximum of an empty Iterator."));
6117
+ while (await iterator.next()) {
6118
+ const currentValue = iterator.getCurrent();
6119
+ if (result.lessThan(currentValue)) {
6120
+ result = currentValue;
6121
+ }
6122
+ }
6123
+ return result;
6124
+ });
6125
+ }
6126
+ /**
6127
+ * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and only
6128
+ * returns a maximum number of values from this {@link AsyncIterator}.
6129
+ * @param maximumToTake The maximum number of values to take from this {@link AsyncIterator}.
6130
+ */
6131
+ take(maximumToTake) {
6132
+ return _AsyncIterator.take(this, maximumToTake);
6133
+ }
6134
+ static take(iterator, maximumToTake) {
6135
+ return TakeAsyncIterator.create(iterator, maximumToTake);
6136
+ }
6137
+ /**
6138
+ * Get a new {@link AsyncIterator} that wraps around this {@link AsyncIterator} and will skip the initial
6139
+ * provided number of values before beginning to return values.
6140
+ * @param maximumToSkip The maximum number of values to skip from this {@link AsyncIterator}.
6141
+ */
6142
+ skip(maximumToSkip) {
6143
+ return _AsyncIterator.skip(this, maximumToSkip);
6144
+ }
6145
+ static skip(iterator, maximumToSkip) {
6146
+ return SkipAsyncIterator.create(iterator, maximumToSkip);
6147
+ }
6148
+ };
6149
+
6150
+ // sources/basicDisposable.ts
6151
+ var SyncDisposable = class _SyncDisposable {
6152
+ disposedFunction;
6153
+ disposed;
6154
+ constructor(disposedFunction) {
6155
+ PreCondition.assertNotUndefinedAndNotNull(disposedFunction, "disposedFunction");
6156
+ this.disposedFunction = disposedFunction;
6157
+ this.disposed = false;
6006
6158
  }
6007
- removeAt(index) {
6008
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6009
- const result = this.get(index).await();
6010
- this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6011
- return SyncResult.value(result);
6159
+ /**
6160
+ * Create a new {@link Disposable} that will invoke the provided {@link Function} when it is
6161
+ * disposed.
6162
+ * @param disposedFunction The function to invoke when the returned {@link Disposable} is
6163
+ * disposed.
6164
+ */
6165
+ static create(disposedFunction) {
6166
+ return new _SyncDisposable(disposedFunction);
6012
6167
  }
6013
- set(index, value) {
6014
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6015
- PreCondition.assertCharacter(value, "value");
6016
- this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + value + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6017
- return this;
6168
+ dispose() {
6169
+ return SyncResult.create(() => {
6170
+ const result = !this.disposed;
6171
+ if (result) {
6172
+ try {
6173
+ this.disposedFunction();
6174
+ } finally {
6175
+ this.disposed = true;
6176
+ }
6177
+ }
6178
+ return result;
6179
+ });
6018
6180
  }
6019
- iterate() {
6020
- return StringIterator.create(this.characters);
6181
+ isDisposed() {
6182
+ return this.disposed;
6021
6183
  }
6022
- get(index) {
6023
- PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6024
- return SyncResult.value(this.characters.charAt(index));
6184
+ };
6185
+
6186
+ // sources/byteList.ts
6187
+ var ByteList = class _ByteList {
6188
+ bytes;
6189
+ count;
6190
+ constructor() {
6191
+ this.bytes = new Uint8Array(0);
6192
+ this.count = 0;
6193
+ }
6194
+ static create(initialValues) {
6195
+ const result = new _ByteList();
6196
+ if (initialValues) {
6197
+ result.addAll(initialValues);
6198
+ }
6199
+ return result;
6025
6200
  }
6026
6201
  add(value) {
6027
6202
  return List.add(this, value);
@@ -6029,23 +6204,70 @@ var CharacterList = class _CharacterList {
6029
6204
  addAll(values) {
6030
6205
  return List.addAll(this, values);
6031
6206
  }
6207
+ insert(index, value) {
6208
+ PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
6209
+ PreCondition.assertByte(value, "value");
6210
+ if (this.count < this.bytes.length) {
6211
+ if (index < this.count) {
6212
+ this.bytes.copyWithin(index + 1, index, this.count);
6213
+ }
6214
+ this.bytes[index] = value;
6215
+ } else {
6216
+ const newCapacity = this.bytes.length * 2 + 1;
6217
+ const newBytes = new Uint8Array(newCapacity);
6218
+ if (index > 0) {
6219
+ newBytes.set(this.bytes.subarray(0, index));
6220
+ }
6221
+ newBytes[index] = value;
6222
+ if (index < this.count) {
6223
+ newBytes.set(this.bytes.subarray(index), index + 1);
6224
+ }
6225
+ this.bytes = newBytes;
6226
+ }
6227
+ this.count++;
6228
+ return this;
6229
+ }
6032
6230
  insertAll(index, values) {
6033
6231
  return List.insertAll(this, index, values);
6034
6232
  }
6035
6233
  remove(value, equalFunctions) {
6234
+ PreCondition.assertByte(value, "value");
6036
6235
  return List.remove(this, value, equalFunctions);
6037
6236
  }
6237
+ removeAt(index) {
6238
+ PreCondition.assertAccessIndex(index, this.count, "index");
6239
+ const result = this.bytes[index];
6240
+ this.bytes.copyWithin(index, index + 1, this.count);
6241
+ this.count--;
6242
+ return SyncResult.value(result);
6243
+ }
6038
6244
  removeFirst() {
6039
6245
  return List.removeFirst(this);
6040
6246
  }
6041
6247
  removeLast() {
6042
6248
  return List.removeLast(this);
6043
6249
  }
6250
+ set(index, value) {
6251
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6252
+ PreCondition.assertByte(value, "value");
6253
+ this.bytes[index] = value;
6254
+ return this;
6255
+ }
6256
+ iterate() {
6257
+ return Iterator.create(this.bytes[Symbol.iterator]().take(this.count));
6258
+ }
6259
+ get(index) {
6260
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6261
+ return SyncResult.value(this.bytes.at(index));
6262
+ }
6044
6263
  toArray() {
6045
6264
  return List.toArray(this);
6046
6265
  }
6047
6266
  any() {
6048
- return List.any(this);
6267
+ return this.getCount().then((count) => count > 0);
6268
+ }
6269
+ getCount() {
6270
+ return SyncResult.value(this.count);
6049
6271
  }
6050
6272
  equals(right, equalFunctions) {
6051
6273
  return List.equals(this, right, equalFunctions);
@@ -6082,100 +6304,42 @@ var CharacterList = class _CharacterList {
6082
6304
  }
6083
6305
  };
6084
6306
 
6085
- // sources/characterReadStream.ts
6086
- var CharacterReadStream = class _CharacterReadStream {
6087
- readCharacters(count) {
6088
- return _CharacterReadStream.readCharacters(this, count);
6089
- }
6090
- static readCharacters(readStream, count) {
6091
- let characters = "";
6092
- function readUntilCount(countRemaining) {
6093
- return readStream.readCharacter().then((character) => {
6094
- characters += character;
6095
- return countRemaining === 0 ? SyncResult.value(characters) : readUntilCount(countRemaining - 1);
6096
- });
6097
- }
6098
- return readUntilCount(count);
6099
- }
6100
- /**
6101
- * Read characters from this stream until the provided {@link searchString} is found or the end
6102
- * of the stream is reached. The {@link searchString} will be included in the returned string if
6103
- * it is found..
6104
- * @param searchString The string to search for.
6105
- */
6106
- readUntil(searchString) {
6107
- return _CharacterReadStream.readUntil(this, searchString);
6108
- }
6109
- static readUntil(readStream, searchString) {
6110
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6111
- PreCondition.assertNotEmpty(searchString, "searchString");
6112
- let characters = "";
6113
- function readUntilSearchString() {
6114
- return readStream.readCharacter().then((character) => {
6115
- characters += character;
6116
- return characters.endsWith(searchString) ? SyncResult.value(characters) : readUntilSearchString();
6117
- });
6118
- }
6119
- return readUntilSearchString();
6120
- }
6121
- /**
6122
- * Read a sequence of characters from this stream until either a newline character ('\\n') or
6123
- * the end of the stream is reached. Terminating newline characters will be included in the
6124
- * returned string.
6125
- */
6126
- readLine() {
6127
- return _CharacterReadStream.readLine(this);
6128
- }
6129
- static readLine(readStream) {
6130
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6131
- return readStream.readUntil("\n");
6132
- }
6133
- };
6134
-
6135
- // sources/characterListStream.ts
6136
- var CharacterListStream = class _CharacterListStream {
6307
+ // sources/byteListStream.ts
6308
+ var ByteListStream = class _ByteListStream {
6137
6309
  list;
6138
6310
  constructor() {
6139
- this.list = CharacterList.create();
6311
+ this.list = ByteList.create();
6140
6312
  }
6141
6313
  static create(initialValues) {
6142
- const result = new _CharacterListStream();
6314
+ const result = new _ByteListStream();
6143
6315
  if (initialValues) {
6144
- result.writeCharacters(initialValues).await();
6316
+ result.writeBytes(initialValues).await();
6145
6317
  }
6146
6318
  return result;
6147
6319
  }
6148
- writeCharacters(characters, startIndex, length) {
6149
- PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
6150
- const characterString = isString(characters) ? characters : join("", characters);
6320
+ /**
6321
+ * Get the number of bytes that are available to be read.
6322
+ */
6323
+ getAvailableByteCount() {
6324
+ return this.list.getCount().await();
6325
+ }
6326
+ writeBytes(bytes, startIndex, length) {
6327
+ PreCondition.assertNotUndefinedAndNotNull(bytes, "bytes");
6328
+ if (isArray(bytes)) {
6329
+ bytes = new Uint8Array(bytes);
6330
+ }
6151
6331
  if (isUndefinedOrNull(startIndex)) {
6152
6332
  startIndex = 0;
6153
6333
  }
6154
6334
  if (isUndefinedOrNull(length)) {
6155
- length = characterString.length - startIndex;
6335
+ length = bytes.length - startIndex;
6156
6336
  }
6157
- PreCondition.assertInsertIndex(startIndex, characterString.length, "startIndex");
6158
- PreCondition.assertBetween(0, length, characterString.length - startIndex, "length");
6159
- this.list.addAll(characterString.slice(startIndex, length + startIndex));
6337
+ PreCondition.assertInsertIndex(startIndex, bytes.length, "startIndex");
6338
+ PreCondition.assertBetween(0, length, bytes.length - startIndex, "length");
6339
+ this.list.addAll(bytes.subarray(startIndex, length + startIndex));
6160
6340
  return SyncResult.value(length);
6161
6341
  }
6162
- writeString(text) {
6163
- this.list.addAll(text);
6164
- return SyncResult.value(text.length);
6165
- }
6166
- writeLine(text) {
6167
- return CharacterWriteStream.writeLine(this, text);
6168
- }
6169
- /**
6170
- * Get the number of characters that are available to be read.
6171
- */
6172
- getAvailableCharacterCount() {
6173
- return this.list.getCount().await();
6174
- }
6175
- readCharacter() {
6176
- return !this.list.any().await() ? SyncResult.error(new EmptyError()) : SyncResult.value(this.list.removeFirst().await());
6177
- }
6178
- readCharacters(countOrOutput, startIndex, count) {
6342
+ readBytes(countOrOutput, startIndex, count) {
6179
6343
  let result;
6180
6344
  if (isNumber(countOrOutput)) {
6181
6345
  PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
@@ -6183,9 +6347,9 @@ var CharacterListStream = class _CharacterListStream {
6183
6347
  result = SyncResult.error(new EmptyError());
6184
6348
  } else {
6185
6349
  const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
6186
- let output = "";
6350
+ const output = new Uint8Array(bytesReadCount);
6187
6351
  for (let i = 0; i < bytesReadCount; i++) {
6188
- output += this.list.removeFirst().await();
6352
+ output[i] = this.list.removeFirst().await();
6189
6353
  }
6190
6354
  result = SyncResult.value(output);
6191
6355
  }
@@ -6211,32 +6375,41 @@ var CharacterListStream = class _CharacterListStream {
6211
6375
  }
6212
6376
  return result;
6213
6377
  }
6214
- readUntil(searchString) {
6215
- return CharacterReadStream.readUntil(this, searchString);
6216
- }
6217
- readLine() {
6218
- return CharacterReadStream.readLine(this);
6219
- }
6220
6378
  };
6221
6379
 
6222
- // sources/characterReadStreamIterator.ts
6223
- var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6224
- readStream;
6225
- current;
6380
+ // sources/byteReadStream.ts
6381
+ var ByteReadStream = class {
6382
+ };
6383
+
6384
+ // sources/byteWriteStream.ts
6385
+ var ByteWriteStream = class {
6386
+ };
6387
+
6388
+ // sources/stringIterator.ts
6389
+ var StringIterator = class _StringIterator {
6390
+ value;
6391
+ currentIndex;
6226
6392
  started;
6227
- constructor(readStream) {
6228
- PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6229
- this.readStream = readStream;
6230
- this.current = "";
6393
+ constructor(value) {
6394
+ this.value = value;
6395
+ this.currentIndex = 0;
6231
6396
  this.started = false;
6232
6397
  }
6233
- static create(readStream) {
6234
- return new _CharacterReadStreamAsyncIterator(readStream);
6398
+ static create(value) {
6399
+ PreCondition.assertNotUndefinedAndNotNull(value, "value");
6400
+ return new _StringIterator(value);
6401
+ }
6402
+ getCurrentIndex() {
6403
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6404
+ return this.currentIndex;
6235
6405
  }
6236
6406
  next() {
6237
- return PromiseAsyncResult.create(async () => {
6238
- this.started = true;
6239
- this.current = await this.readStream.readCharacter().catch(NotFoundError, () => "");
6407
+ return SyncResult.create(() => {
6408
+ if (!this.hasStarted()) {
6409
+ this.started = true;
6410
+ } else if (this.hasCurrent()) {
6411
+ this.currentIndex++;
6412
+ }
6240
6413
  return this.hasCurrent();
6241
6414
  });
6242
6415
  }
@@ -6244,638 +6417,712 @@ var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6244
6417
  return this.started;
6245
6418
  }
6246
6419
  hasCurrent() {
6247
- return this.current !== "";
6420
+ return this.hasStarted() && this.currentIndex < this.value.length;
6248
6421
  }
6249
6422
  getCurrent() {
6250
6423
  PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6251
- return this.current;
6424
+ return this.value[this.currentIndex];
6252
6425
  }
6253
6426
  start() {
6254
- return AsyncIterator.start(this);
6427
+ return Iterator.start(this);
6255
6428
  }
6256
6429
  takeCurrent() {
6257
- return AsyncIterator.takeCurrent(this);
6430
+ return Iterator.takeCurrent(this);
6258
6431
  }
6259
6432
  any() {
6260
- return AsyncIterator.any(this);
6433
+ return Iterator.any(this);
6261
6434
  }
6262
6435
  getCount() {
6263
- return AsyncIterator.getCount(this);
6436
+ return Iterator.getCount(this);
6264
6437
  }
6265
6438
  toArray() {
6266
- return AsyncIterator.toArray(this);
6439
+ return Iterator.toArray(this);
6267
6440
  }
6268
- where(condition) {
6269
- return AsyncIterator.where(this, condition);
6441
+ concatenate(...toConcatenate) {
6442
+ return Iterator.concatenate(this, ...toConcatenate);
6270
6443
  }
6271
6444
  map(mapping) {
6272
- return AsyncIterator.map(this, mapping);
6445
+ return Iterator.map(this, mapping);
6273
6446
  }
6274
- whereInstanceOf(typeCheck) {
6275
- return AsyncIterator.whereInstanceOf(this, typeCheck);
6447
+ flatMap(mapping) {
6448
+ return Iterator.flatMap(this, mapping);
6276
6449
  }
6277
- whereInstanceOfType(type) {
6278
- return AsyncIterator.whereInstanceOfType(this, type);
6450
+ first() {
6451
+ return Iterator.first(this);
6279
6452
  }
6280
- first(condition) {
6281
- return AsyncIterator.first(this, condition);
6453
+ last() {
6454
+ return Iterator.last(this);
6282
6455
  }
6283
- last(condition) {
6284
- return AsyncIterator.last(this, condition);
6456
+ where(condition) {
6457
+ return Iterator.where(this, condition);
6458
+ }
6459
+ whereInstanceOf(typeCheck) {
6460
+ return Iterator.whereInstanceOf(this, typeCheck);
6461
+ }
6462
+ whereInstanceOfType(type) {
6463
+ return Iterator.whereInstanceOfType(this, type);
6285
6464
  }
6286
6465
  take(maximumToTake) {
6287
- return AsyncIterator.take(this, maximumToTake);
6466
+ return Iterator.take(this, maximumToTake);
6288
6467
  }
6289
6468
  skip(maximumToSkip) {
6290
- return AsyncIterator.skip(this, maximumToSkip);
6469
+ return Iterator.skip(this, maximumToSkip);
6291
6470
  }
6292
- [Symbol.asyncIterator]() {
6293
- return AsyncIterator[Symbol.asyncIterator](this);
6471
+ [Symbol.iterator]() {
6472
+ return Iterator[Symbol.iterator](this);
6294
6473
  }
6295
6474
  };
6296
6475
 
6297
- // sources/english.ts
6298
- function andList(values) {
6299
- return list("and", values);
6300
- }
6301
- function orList(values) {
6302
- return list("or", values);
6303
- }
6304
- function list(conjunction, values) {
6305
- PreCondition.assertNotEmpty(conjunction, "conjunction");
6306
- PreCondition.assertNotUndefinedAndNotNull(values, "values");
6307
- let result = "";
6308
- let index = 0;
6309
- const iterator = Iterator.create(values).start().await();
6310
- while (iterator.hasCurrent()) {
6311
- const currentValue = iterator.takeCurrent().await();
6312
- if (index >= 1) {
6313
- if (iterator.hasCurrent()) {
6314
- result += `, `;
6315
- } else {
6316
- if (index >= 2) {
6317
- result += `,`;
6318
- }
6319
- result += ` ${conjunction} `;
6320
- }
6476
+ // sources/characterList.ts
6477
+ var CharacterList = class _CharacterList {
6478
+ characters;
6479
+ constructor(values) {
6480
+ if (isString(values)) {
6481
+ this.characters = values;
6482
+ } else if (values) {
6483
+ this.characters = join("", values);
6484
+ } else {
6485
+ this.characters = "";
6321
6486
  }
6322
- result += currentValue;
6323
- index++;
6324
6487
  }
6325
- return result;
6326
- }
6327
-
6328
- // sources/commandLineParameters.ts
6329
- var CommandLineParameters = class _CommandLineParameters {
6330
- args;
6331
- parameters;
6332
- constructor(argv) {
6333
- PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
6334
- this.args = isIterable(argv) ? argv : Iterable.create(argv);
6335
- this.parameters = List.create();
6488
+ static create(values) {
6489
+ return new _CharacterList(values);
6336
6490
  }
6337
- static create(args) {
6338
- return new _CommandLineParameters(args);
6491
+ getCount() {
6492
+ return SyncResult.value(this.characters.length);
6339
6493
  }
6340
- static getArgumentName(arg) {
6341
- return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
6494
+ insert(index, value) {
6495
+ PreCondition.assertInsertIndex(index, this.getCount().await(), "index");
6496
+ PreCondition.assertCharacter(value, "value");
6497
+ if (index === 0) {
6498
+ this.characters = value + this.characters;
6499
+ } else if (index === this.getCount().await()) {
6500
+ this.characters += value;
6501
+ } else {
6502
+ this.characters = this.characters.slice(0, index) + value + this.characters.slice(index);
6503
+ }
6504
+ return this;
6342
6505
  }
6343
- getArguments() {
6344
- return this.args;
6506
+ removeAt(index) {
6507
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6508
+ const result = this.get(index).await();
6509
+ this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6510
+ return SyncResult.value(result);
6345
6511
  }
6346
- /**
6347
- * Get the value of the first argument that matches one of the provided names.
6348
- * @param names The possible names to look for.
6349
- */
6350
- getNamedArgumentStringValue(nameOrNames) {
6351
- PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
6352
- return SyncResult.create(() => {
6353
- let foundArgName = false;
6354
- let result;
6355
- if (isString(nameOrNames)) {
6356
- nameOrNames = [nameOrNames];
6357
- }
6358
- const searchNames = Iterable.create(nameOrNames);
6359
- for (const arg of this.args) {
6360
- if (!foundArgName) {
6361
- const argName = _CommandLineParameters.getArgumentName(arg);
6362
- foundArgName = !!(argName && searchNames.contains(argName));
6363
- } else {
6364
- result = arg;
6365
- break;
6366
- }
6367
- }
6368
- if (result === void 0) {
6369
- const toStringFunctions = ToStringFunctions.create();
6370
- throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
6371
- }
6372
- return result;
6373
- });
6512
+ set(index, value) {
6513
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6514
+ PreCondition.assertCharacter(value, "value");
6515
+ this.characters = (index === 0 ? "" : this.characters.slice(0, index)) + value + (index === this.getCount().await() - 1 ? "" : this.characters.slice(index + 1));
6516
+ return this;
6374
6517
  }
6375
- nameOrAliasExists(nameOrAlias) {
6376
- PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
6377
- let result = false;
6378
- for (const parameter of this.parameters) {
6379
- if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
6380
- result = true;
6381
- break;
6382
- }
6383
- }
6384
- return result;
6518
+ iterate() {
6519
+ return StringIterator.create(this.characters);
6385
6520
  }
6386
- add(name) {
6387
- const result = CommandLineParameter.create({
6388
- owner: this,
6389
- name
6390
- });
6391
- this.parameters.add(result);
6392
- return result;
6521
+ get(index) {
6522
+ PreCondition.assertAccessIndex(index, this.getCount().await(), "index");
6523
+ return SyncResult.value(this.characters.charAt(index));
6393
6524
  }
6394
- };
6395
-
6396
- // sources/commandLineParameter.ts
6397
- var CommandLineParameter = class _CommandLineParameter {
6398
- owner;
6399
- name;
6400
- aliases;
6401
- description;
6402
- constructor(owner, name) {
6403
- PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
6404
- PreCondition.assertNotEmpty(name, "name");
6405
- PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
6406
- this.owner = owner;
6407
- this.name = name;
6525
+ add(value) {
6526
+ return List.add(this, value);
6408
6527
  }
6409
- static create(ownerOrProperties, name) {
6410
- let owner;
6411
- if (ownerOrProperties instanceof CommandLineParameters) {
6412
- owner = ownerOrProperties;
6413
- name = name;
6414
- } else {
6415
- owner = ownerOrProperties.owner;
6416
- name = ownerOrProperties.name;
6417
- }
6418
- return new _CommandLineParameter(owner, name);
6528
+ addAll(values) {
6529
+ return List.addAll(this, values);
6419
6530
  }
6420
- /**
6421
- * Get the name of this {@link CommandLineParameter}.
6422
- */
6423
- getName() {
6424
- return this.name;
6531
+ insertAll(index, values) {
6532
+ return List.insertAll(this, index, values);
6425
6533
  }
6426
- getAliases() {
6427
- return this.aliases ?? Iterable.create();
6534
+ remove(value, equalFunctions) {
6535
+ return List.remove(this, value, equalFunctions);
6428
6536
  }
6429
- nameOrAliasExists(nameOrAlias) {
6430
- return this.owner.nameOrAliasExists(nameOrAlias);
6537
+ removeFirst() {
6538
+ return List.removeFirst(this);
6431
6539
  }
6432
- addAlias(alias) {
6433
- PreCondition.assertNotEmpty(alias, "alias");
6434
- PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
6435
- if (this.aliases === void 0) {
6436
- this.aliases = List.create();
6437
- }
6438
- this.aliases.add(alias);
6439
- return this;
6540
+ removeLast() {
6541
+ return List.removeLast(this);
6542
+ }
6543
+ toArray() {
6544
+ return List.toArray(this);
6545
+ }
6546
+ any() {
6547
+ return List.any(this);
6548
+ }
6549
+ equals(right, equalFunctions) {
6550
+ return List.equals(this, right, equalFunctions);
6551
+ }
6552
+ toString(toStringFunctions) {
6553
+ return List.toString(this, toStringFunctions);
6554
+ }
6555
+ concatenate(...toConcatenate) {
6556
+ return List.concatenate(this, ...toConcatenate);
6557
+ }
6558
+ map(mapping) {
6559
+ return List.map(this, mapping);
6560
+ }
6561
+ flatMap(mapping) {
6562
+ return List.flatMap(this, mapping);
6563
+ }
6564
+ where(condition) {
6565
+ return List.where(this, condition);
6566
+ }
6567
+ instanceOf(typeOrTypeCheck) {
6568
+ return List.instanceOf(this, typeOrTypeCheck);
6440
6569
  }
6441
- addAliases(aliases) {
6442
- for (const alias of aliases) {
6443
- this.addAlias(alias);
6444
- }
6445
- return this;
6570
+ first(condition) {
6571
+ return List.first(this, condition);
6446
6572
  }
6447
- getNameAndAliases() {
6448
- return List.create().add(this.getName()).addAll(this.getAliases());
6573
+ last(condition) {
6574
+ return List.last(this, condition);
6449
6575
  }
6450
- getDescription() {
6451
- return this.description ?? "";
6576
+ contains(value, equalFunctions) {
6577
+ return List.contains(this, value, equalFunctions);
6452
6578
  }
6453
- setDescription(description) {
6454
- PreCondition.assertNotUndefinedAndNotNull(description, "description");
6455
- this.description = description;
6456
- return this;
6579
+ [Symbol.iterator]() {
6580
+ return List[Symbol.iterator](this);
6457
6581
  }
6458
6582
  };
6459
6583
 
6460
- // sources/comparable.ts
6461
- var Comparable = class _Comparable {
6462
- constructor() {
6463
- }
6464
- /**
6465
- * Get whether this value is less than the provided value.
6466
- * @param value The value to compare against.
6467
- */
6468
- lessThan(value) {
6469
- return _Comparable.lessThan(this, value);
6584
+ // sources/characterReadStream.ts
6585
+ var CharacterReadStream = class _CharacterReadStream {
6586
+ readCharacters(count) {
6587
+ return _CharacterReadStream.readCharacters(this, count);
6470
6588
  }
6471
- /**
6472
- * Get whether the left value is less than the right value.
6473
- * @param left The left value in the comparison.
6474
- * @param right The right value in the comparison.
6475
- */
6476
- static lessThan(left, right) {
6477
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6478
- return left.compareTo(right) === 0 /* LessThan */;
6589
+ static readCharacters(readStream, count) {
6590
+ let characters = "";
6591
+ function readUntilCount(countRemaining) {
6592
+ return readStream.readCharacter().then((character) => {
6593
+ characters += character;
6594
+ return countRemaining === 0 ? SyncResult.value(characters) : readUntilCount(countRemaining - 1);
6595
+ });
6596
+ }
6597
+ return readUntilCount(count);
6479
6598
  }
6480
6599
  /**
6481
- * Get whether this value is less than or equal to the provided value.
6482
- * @param value The value to compare against.
6600
+ * Read characters from this stream until the provided {@link searchString} is found or the end
6601
+ * of the stream is reached. The {@link searchString} will be included in the returned string if
6602
+ * it is found..
6603
+ * @param searchString The string to search for.
6483
6604
  */
6484
- lessThanOrEqualTo(value) {
6485
- return _Comparable.lessThanOrEqualTo(this, value);
6605
+ readUntil(searchString) {
6606
+ return _CharacterReadStream.readUntil(this, searchString);
6486
6607
  }
6487
- /**
6488
- * Get whether the left value is less than or equal to the right value.
6489
- * @param left The left value in the comparison.
6490
- * @param right The right value in the comparison.
6491
- */
6492
- static lessThanOrEqualTo(left, right) {
6493
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6494
- return left.compareTo(right) !== 2 /* GreaterThan */;
6608
+ static readUntil(readStream, searchString) {
6609
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6610
+ PreCondition.assertNotEmpty(searchString, "searchString");
6611
+ let characters = "";
6612
+ function readUntilSearchString() {
6613
+ return readStream.readCharacter().then((character) => {
6614
+ characters += character;
6615
+ return characters.endsWith(searchString) ? SyncResult.value(characters) : readUntilSearchString();
6616
+ });
6617
+ }
6618
+ return readUntilSearchString();
6495
6619
  }
6496
6620
  /**
6497
- * Get whether this value equals the provided value.
6498
- * @param value The value to compare against.
6621
+ * Read a sequence of characters from this stream until either a newline character ('\\n') or
6622
+ * the end of the stream is reached. Terminating newline characters will be included in the
6623
+ * returned string.
6499
6624
  */
6500
- equals(value) {
6501
- return _Comparable.equals(this, value);
6625
+ readLine() {
6626
+ return _CharacterReadStream.readLine(this);
6502
6627
  }
6503
- /**
6504
- * Get whether the left value equals the right value.
6505
- * @param left The left value in the comparison.
6506
- * @param right The right value in the comparison.
6507
- */
6508
- static equals(left, right) {
6509
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6510
- return left.compareTo(right) === 1 /* Equal */;
6628
+ static readLine(readStream) {
6629
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6630
+ return readStream.readUntil("\n");
6511
6631
  }
6512
- /**
6513
- * Get whether this value is not equal to the provided value.
6514
- * @param value The value to compare against.
6515
- */
6516
- notEquals(value) {
6517
- return _Comparable.notEquals(this, value);
6632
+ };
6633
+
6634
+ // sources/characterListStream.ts
6635
+ var CharacterListStream = class _CharacterListStream {
6636
+ list;
6637
+ constructor() {
6638
+ this.list = CharacterList.create();
6518
6639
  }
6519
- /**
6520
- * Get whether the left value is not equal to the right value.
6521
- * @param left The left value in the comparison.
6522
- * @param right The right value in the comparison.
6523
- */
6524
- static notEquals(left, right) {
6525
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6526
- return left.compareTo(right) !== 1 /* Equal */;
6640
+ static create(initialValues) {
6641
+ const result = new _CharacterListStream();
6642
+ if (initialValues) {
6643
+ result.writeCharacters(initialValues).await();
6644
+ }
6645
+ return result;
6527
6646
  }
6528
- /**
6529
- * Get whether this value is greater than or equal to the provided value.
6530
- * @param value The value to compare against.
6531
- */
6532
- greaterThanOrEqualTo(value) {
6533
- return _Comparable.greaterThanOrEqualTo(this, value);
6647
+ writeCharacters(characters, startIndex, length) {
6648
+ PreCondition.assertNotUndefinedAndNotNull(characters, "characters");
6649
+ const characterString = isString(characters) ? characters : join("", characters);
6650
+ if (isUndefinedOrNull(startIndex)) {
6651
+ startIndex = 0;
6652
+ }
6653
+ if (isUndefinedOrNull(length)) {
6654
+ length = characterString.length - startIndex;
6655
+ }
6656
+ PreCondition.assertInsertIndex(startIndex, characterString.length, "startIndex");
6657
+ PreCondition.assertBetween(0, length, characterString.length - startIndex, "length");
6658
+ this.list.addAll(characterString.slice(startIndex, length + startIndex));
6659
+ return SyncResult.value(length);
6534
6660
  }
6535
- /**
6536
- * Get whether the left value is greater than or equal to the right value.
6537
- * @param left The left value in the comparison.
6538
- * @param right The right value in the comparison.
6539
- */
6540
- static greaterThanOrEqualTo(left, right) {
6541
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6542
- return left.compareTo(right) !== 0 /* LessThan */;
6661
+ writeString(text) {
6662
+ this.list.addAll(text);
6663
+ return SyncResult.value(text.length);
6543
6664
  }
6544
- /**
6545
- * Get whether this value is greater than the provided value.
6546
- * @param value The value to compare against.
6547
- */
6548
- greaterThan(value) {
6549
- return _Comparable.greaterThan(this, value);
6665
+ writeLine(text) {
6666
+ return CharacterWriteStream.writeLine(this, text);
6550
6667
  }
6551
6668
  /**
6552
- * Get whether the left value is greater than the right value.
6553
- * @param left The left value in the comparison.
6554
- * @param right The right value in the comparison.
6669
+ * Get the number of characters that are available to be read.
6555
6670
  */
6556
- static greaterThan(left, right) {
6557
- PreCondition.assertNotUndefinedAndNotNull(left, "left");
6558
- return left.compareTo(right) === 2 /* GreaterThan */;
6559
- }
6560
- };
6561
-
6562
- // sources/nodeJSCharacterWriteStream.ts
6563
- var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
6564
- nodeJSWriteStream;
6565
- constructor(nodeJSWriteStream) {
6566
- PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
6567
- super();
6568
- this.nodeJSWriteStream = nodeJSWriteStream;
6671
+ getAvailableCharacterCount() {
6672
+ return this.list.getCount().await();
6569
6673
  }
6570
- static create(nodeJSWriteStream) {
6571
- return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
6674
+ readCharacter() {
6675
+ return !this.list.any().await() ? SyncResult.error(new EmptyError()) : SyncResult.value(this.list.removeFirst().await());
6572
6676
  }
6573
- writeString(text) {
6574
- PreCondition.assertNotUndefinedAndNotNull(text, "text");
6575
- return PromiseAsyncResult.create(new Promise((resolve, reject) => {
6576
- this.nodeJSWriteStream.write(text, (error) => {
6577
- if (error) {
6578
- reject(error);
6579
- } else {
6580
- resolve(text.length);
6677
+ readCharacters(countOrOutput, startIndex, count) {
6678
+ let result;
6679
+ if (isNumber(countOrOutput)) {
6680
+ PreCondition.assertGreaterThanOrEqualTo(countOrOutput, 0, "count");
6681
+ if (!this.list.any().await()) {
6682
+ result = SyncResult.error(new EmptyError());
6683
+ } else {
6684
+ const bytesReadCount = Math.min(countOrOutput, this.list.getCount().await());
6685
+ let output = "";
6686
+ for (let i = 0; i < bytesReadCount; i++) {
6687
+ output += this.list.removeFirst().await();
6581
6688
  }
6582
- });
6583
- }));
6584
- }
6585
- };
6586
-
6587
- // sources/property.ts
6588
- var Property = class _Property {
6589
- getter;
6590
- setter;
6591
- constructor(getter, setter) {
6592
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
6593
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
6594
- this.getter = getter;
6595
- this.setter = setter;
6596
- }
6597
- static create(getterOptionsOrInitialValue, setter) {
6598
- let getter;
6599
- if (isFunction(getterOptionsOrInitialValue)) {
6600
- getter = getterOptionsOrInitialValue;
6601
- } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
6602
- const options = getterOptionsOrInitialValue;
6603
- getter = options.getter;
6604
- setter = options.setter;
6689
+ result = SyncResult.value(output);
6690
+ }
6605
6691
  } else {
6606
- let initialValue = getterOptionsOrInitialValue;
6607
- getter = () => {
6608
- return initialValue;
6609
- };
6610
- setter = (value) => {
6611
- initialValue = value;
6612
- };
6692
+ PreCondition.assertNotUndefinedAndNotNull(countOrOutput, "output");
6693
+ if (isUndefinedOrNull(startIndex)) {
6694
+ startIndex = 0;
6695
+ }
6696
+ if (isUndefinedOrNull(count)) {
6697
+ count = countOrOutput.length - startIndex;
6698
+ }
6699
+ PreCondition.assertInsertIndex(startIndex, countOrOutput.length, "startIndex");
6700
+ PreCondition.assertBetween(0, count, countOrOutput.length - startIndex, "count");
6701
+ if (!this.list.any().await()) {
6702
+ result = SyncResult.error(new EmptyError());
6703
+ } else {
6704
+ const bytesReadCount = Math.min(count, this.list.getCount().await());
6705
+ for (let i = 0; i < bytesReadCount; i++) {
6706
+ countOrOutput[startIndex + i] = this.list.removeFirst().await();
6707
+ }
6708
+ result = SyncResult.value(bytesReadCount);
6709
+ }
6613
6710
  }
6614
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
6615
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
6616
- return new _Property(getter, setter);
6617
- }
6618
- getValue() {
6619
- return this.getter();
6711
+ return result;
6620
6712
  }
6621
- setValue(value) {
6622
- this.setter(value);
6623
- return this;
6713
+ readUntil(searchString) {
6714
+ return CharacterReadStream.readUntil(this, searchString);
6624
6715
  }
6625
- toString() {
6626
- return `${this.getValue()}`;
6716
+ readLine() {
6717
+ return CharacterReadStream.readLine(this);
6627
6718
  }
6628
6719
  };
6629
6720
 
6630
- // sources/httpHeader.ts
6631
- var HttpHeader = class _HttpHeader {
6632
- name;
6633
- value;
6634
- constructor(name, value) {
6635
- PreCondition.assertNotEmpty(name, "name");
6636
- PreCondition.assertNotUndefinedAndNotNull(value, "value");
6637
- this.name = name;
6638
- this.value = value;
6639
- }
6640
- static create(name, value) {
6641
- return new _HttpHeader(name, value);
6721
+ // sources/characterReadStreamIterator.ts
6722
+ var CharacterReadStreamAsyncIterator = class _CharacterReadStreamAsyncIterator {
6723
+ readStream;
6724
+ current;
6725
+ started;
6726
+ constructor(readStream) {
6727
+ PreCondition.assertNotUndefinedAndNotNull(readStream, "readStream");
6728
+ this.readStream = readStream;
6729
+ this.current = "";
6730
+ this.started = false;
6642
6731
  }
6643
- getName() {
6644
- return this.name;
6732
+ static create(readStream) {
6733
+ return new _CharacterReadStreamAsyncIterator(readStream);
6645
6734
  }
6646
- getValue() {
6647
- return this.value;
6735
+ next() {
6736
+ return PromiseAsyncResult.create(async () => {
6737
+ this.started = true;
6738
+ this.current = await this.readStream.readCharacter().catch(NotFoundError, () => "");
6739
+ return this.hasCurrent();
6740
+ });
6648
6741
  }
6649
- toString() {
6650
- return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
6742
+ hasStarted() {
6743
+ return this.started;
6651
6744
  }
6652
- };
6653
-
6654
- // sources/mutableHttpHeaders.ts
6655
- var MutableHttpHeaders = class _MutableHttpHeaders {
6656
- headers;
6657
- constructor(headers) {
6658
- this.headers = List.create();
6659
- if (headers) {
6660
- this.setAll(headers);
6661
- }
6745
+ hasCurrent() {
6746
+ return this.current !== "";
6662
6747
  }
6663
- static create(headers) {
6664
- return new _MutableHttpHeaders(headers);
6748
+ getCurrent() {
6749
+ PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
6750
+ return this.current;
6665
6751
  }
6666
- iterate() {
6667
- return this.headers.iterate();
6752
+ start() {
6753
+ return AsyncIterator.start(this);
6668
6754
  }
6669
- get(headerName) {
6670
- PreCondition.assertNotEmpty(headerName, "headerName");
6671
- return SyncResult.create(() => {
6672
- let result;
6673
- const lowerHeaderName = headerName.toLowerCase();
6674
- for (const header of this.headers) {
6675
- if (header.getName().toLowerCase() === lowerHeaderName) {
6676
- result = header;
6677
- break;
6678
- }
6679
- }
6680
- if (result === void 0) {
6681
- throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
6682
- }
6683
- return result;
6684
- });
6755
+ takeCurrent() {
6756
+ return AsyncIterator.takeCurrent(this);
6685
6757
  }
6686
- getValue(headerName) {
6687
- return this.get(headerName).then((header) => header.getValue());
6758
+ any() {
6759
+ return AsyncIterator.any(this);
6688
6760
  }
6689
- set(headerOrHeaderName, headerValue) {
6690
- let headerName;
6691
- if (isString(headerOrHeaderName)) {
6692
- headerName = headerOrHeaderName;
6693
- } else {
6694
- headerName = headerOrHeaderName.getName();
6695
- headerValue = headerOrHeaderName.getValue();
6696
- }
6697
- PreCondition.assertNotEmpty(headerName, "headerName");
6698
- PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
6699
- let insertIndex = 0;
6700
- for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
6701
- const header = this.headers.get(insertIndex2).await();
6702
- if (header.getName() === headerName) {
6703
- this.headers.removeAt(insertIndex2);
6704
- break;
6705
- }
6706
- }
6707
- this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
6708
- return this;
6761
+ getCount() {
6762
+ return AsyncIterator.getCount(this);
6709
6763
  }
6710
- setAll(headers) {
6711
- PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
6712
- for (const header of headers) {
6713
- this.set(header);
6714
- }
6715
- return this;
6764
+ toArray() {
6765
+ return AsyncIterator.toArray(this);
6716
6766
  }
6717
- setContentType(contentType) {
6718
- return this.set(HttpHeaders.contentTypeHeaderName, contentType);
6767
+ where(condition) {
6768
+ return AsyncIterator.where(this, condition);
6719
6769
  }
6720
- getContentType() {
6721
- return this.get(HttpHeaders.contentTypeHeaderName);
6770
+ map(mapping) {
6771
+ return AsyncIterator.map(this, mapping);
6722
6772
  }
6723
- getContentTypeValue() {
6724
- return this.getValue(HttpHeaders.contentTypeHeaderName);
6773
+ whereInstanceOf(typeCheck) {
6774
+ return AsyncIterator.whereInstanceOf(this, typeCheck);
6725
6775
  }
6726
- getCount() {
6727
- return this.headers.getCount();
6776
+ whereInstanceOfType(type) {
6777
+ return AsyncIterator.whereInstanceOfType(this, type);
6728
6778
  }
6729
- toArray() {
6730
- return HttpHeaders.toArray(this);
6779
+ first(condition) {
6780
+ return AsyncIterator.first(this, condition);
6731
6781
  }
6732
- any() {
6733
- return HttpHeaders.any(this);
6782
+ last(condition) {
6783
+ return AsyncIterator.last(this, condition);
6734
6784
  }
6735
- equals(right, equalFunctions) {
6736
- return HttpHeaders.equals(this, right, equalFunctions);
6785
+ take(maximumToTake) {
6786
+ return AsyncIterator.take(this, maximumToTake);
6737
6787
  }
6738
- toString(toStringFunctions) {
6739
- return HttpHeaders.toString(this, toStringFunctions);
6788
+ skip(maximumToSkip) {
6789
+ return AsyncIterator.skip(this, maximumToSkip);
6740
6790
  }
6741
- concatenate(...toConcatenate) {
6742
- return HttpHeaders.concatenate(this, ...toConcatenate);
6791
+ [Symbol.asyncIterator]() {
6792
+ return AsyncIterator[Symbol.asyncIterator](this);
6743
6793
  }
6744
- map(mapping) {
6745
- return HttpHeaders.map(this, mapping);
6794
+ };
6795
+
6796
+ // sources/english.ts
6797
+ function andList(values) {
6798
+ return list("and", values);
6799
+ }
6800
+ function orList(values) {
6801
+ return list("or", values);
6802
+ }
6803
+ function list(conjunction, values) {
6804
+ PreCondition.assertNotEmpty(conjunction, "conjunction");
6805
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
6806
+ let result = "";
6807
+ let index = 0;
6808
+ const iterator = Iterator.create(values).start().await();
6809
+ while (iterator.hasCurrent()) {
6810
+ const currentValue = iterator.takeCurrent().await();
6811
+ if (index >= 1) {
6812
+ if (iterator.hasCurrent()) {
6813
+ result += `, `;
6814
+ } else {
6815
+ if (index >= 2) {
6816
+ result += `,`;
6817
+ }
6818
+ result += ` ${conjunction} `;
6819
+ }
6820
+ }
6821
+ result += currentValue;
6822
+ index++;
6746
6823
  }
6747
- flatMap(mapping) {
6748
- return HttpHeaders.flatMap(this, mapping);
6824
+ return result;
6825
+ }
6826
+
6827
+ // sources/commandLineParameters.ts
6828
+ var CommandLineParameters = class _CommandLineParameters {
6829
+ args;
6830
+ parameters;
6831
+ constructor(argv) {
6832
+ PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
6833
+ this.args = isIterable(argv) ? argv : Iterable.create(argv);
6834
+ this.parameters = List.create();
6749
6835
  }
6750
- where(condition) {
6751
- return HttpHeaders.where(this, condition);
6836
+ static create(args) {
6837
+ return new _CommandLineParameters(args);
6752
6838
  }
6753
- instanceOf(typeOrTypeCheck) {
6754
- return HttpHeaders.instanceOf(this, typeOrTypeCheck);
6839
+ static getArgumentName(arg) {
6840
+ return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
6755
6841
  }
6756
- first(condition) {
6757
- return HttpHeaders.first(this, condition);
6842
+ getArguments() {
6843
+ return this.args;
6758
6844
  }
6759
- last(condition) {
6760
- return HttpHeaders.last(this, condition);
6845
+ /**
6846
+ * Get the value of the first argument that matches one of the provided names.
6847
+ * @param names The possible names to look for.
6848
+ */
6849
+ getNamedArgumentStringValue(nameOrNames) {
6850
+ PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
6851
+ return SyncResult.create(() => {
6852
+ let foundArgName = false;
6853
+ let result;
6854
+ if (isString(nameOrNames)) {
6855
+ nameOrNames = [nameOrNames];
6856
+ }
6857
+ const searchNames = Iterable.create(nameOrNames);
6858
+ for (const arg of this.args) {
6859
+ if (!foundArgName) {
6860
+ const argName = _CommandLineParameters.getArgumentName(arg);
6861
+ foundArgName = !!(argName && searchNames.contains(argName));
6862
+ } else {
6863
+ result = arg;
6864
+ break;
6865
+ }
6866
+ }
6867
+ if (result === void 0) {
6868
+ const toStringFunctions = ToStringFunctions.create();
6869
+ throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
6870
+ }
6871
+ return result;
6872
+ });
6761
6873
  }
6762
- [Symbol.iterator]() {
6763
- return HttpHeaders[Symbol.iterator](this);
6874
+ nameOrAliasExists(nameOrAlias) {
6875
+ PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
6876
+ let result = false;
6877
+ for (const parameter of this.parameters) {
6878
+ if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
6879
+ result = true;
6880
+ break;
6881
+ }
6882
+ }
6883
+ return result;
6764
6884
  }
6765
- contains(value, equalFunctions) {
6766
- return HttpHeaders.contains(this, value, equalFunctions);
6885
+ add(name) {
6886
+ const result = CommandLineParameter.create({
6887
+ owner: this,
6888
+ name
6889
+ });
6890
+ this.parameters.add(result);
6891
+ return result;
6767
6892
  }
6768
6893
  };
6769
6894
 
6770
- // sources/httpHeaders.ts
6771
- var HttpHeaders = class _HttpHeaders {
6772
- static contentTypeHeaderName = "Content-Type";
6773
- static create(headers) {
6774
- return MutableHttpHeaders.create(headers);
6775
- }
6776
- getContentType() {
6777
- return _HttpHeaders.getContentType(this);
6778
- }
6779
- static getContentType(headers) {
6780
- return headers.get(_HttpHeaders.contentTypeHeaderName);
6781
- }
6782
- getContentTypeValue() {
6783
- return _HttpHeaders.getContentTypeValue(this);
6895
+ // sources/commandLineParameter.ts
6896
+ var CommandLineParameter = class _CommandLineParameter {
6897
+ owner;
6898
+ name;
6899
+ aliases;
6900
+ description;
6901
+ constructor(owner, name) {
6902
+ PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
6903
+ PreCondition.assertNotEmpty(name, "name");
6904
+ PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
6905
+ this.owner = owner;
6906
+ this.name = name;
6784
6907
  }
6785
- static getContentTypeValue(headers) {
6786
- return headers.getValue(_HttpHeaders.contentTypeHeaderName);
6908
+ static create(ownerOrProperties, name) {
6909
+ let owner;
6910
+ if (ownerOrProperties instanceof CommandLineParameters) {
6911
+ owner = ownerOrProperties;
6912
+ name = name;
6913
+ } else {
6914
+ owner = ownerOrProperties.owner;
6915
+ name = ownerOrProperties.name;
6916
+ }
6917
+ return new _CommandLineParameter(owner, name);
6787
6918
  }
6788
6919
  /**
6789
- * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
6920
+ * Get the name of this {@link CommandLineParameter}.
6790
6921
  */
6791
- toArray() {
6792
- return _HttpHeaders.toArray(this);
6922
+ getName() {
6923
+ return this.name;
6793
6924
  }
6794
- static toArray(headers) {
6795
- return Iterable.toArray(headers);
6925
+ getAliases() {
6926
+ return this.aliases ?? Iterable.create();
6796
6927
  }
6797
- any() {
6798
- return _HttpHeaders.any(this);
6928
+ nameOrAliasExists(nameOrAlias) {
6929
+ return this.owner.nameOrAliasExists(nameOrAlias);
6799
6930
  }
6800
- static any(headers) {
6801
- return Iterable.any(headers);
6931
+ addAlias(alias) {
6932
+ PreCondition.assertNotEmpty(alias, "alias");
6933
+ PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
6934
+ if (this.aliases === void 0) {
6935
+ this.aliases = List.create();
6936
+ }
6937
+ this.aliases.add(alias);
6938
+ return this;
6802
6939
  }
6803
- getCount() {
6804
- return _HttpHeaders.getCount(this);
6940
+ addAliases(aliases) {
6941
+ for (const alias of aliases) {
6942
+ this.addAlias(alias);
6943
+ }
6944
+ return this;
6805
6945
  }
6806
- static getCount(headers) {
6807
- return Iterable.getCount(headers);
6946
+ getNameAndAliases() {
6947
+ return List.create().add(this.getName()).addAll(this.getAliases());
6808
6948
  }
6809
- equals(right, equalFunctions) {
6810
- return _HttpHeaders.equals(this, right, equalFunctions);
6949
+ getDescription() {
6950
+ return this.description ?? "";
6811
6951
  }
6812
- static equals(headers, right, equalFunctions) {
6813
- return Iterable.equals(headers, right, equalFunctions);
6952
+ setDescription(description) {
6953
+ PreCondition.assertNotUndefinedAndNotNull(description, "description");
6954
+ this.description = description;
6955
+ return this;
6814
6956
  }
6815
- toString(toStringFunctions) {
6816
- return _HttpHeaders.toString(this, toStringFunctions);
6957
+ };
6958
+
6959
+ // sources/comparable.ts
6960
+ var Comparable = class _Comparable {
6961
+ constructor() {
6817
6962
  }
6818
- static toString(headers, toStringFunctions) {
6819
- return Iterable.toString(headers, toStringFunctions);
6963
+ /**
6964
+ * Get whether this value is less than the provided value.
6965
+ * @param value The value to compare against.
6966
+ */
6967
+ lessThan(value) {
6968
+ return _Comparable.lessThan(this, value);
6820
6969
  }
6821
- concatenate(...toConcatenate) {
6822
- return _HttpHeaders.concatenate(this, ...toConcatenate);
6970
+ /**
6971
+ * Get whether the left value is less than the right value.
6972
+ * @param left The left value in the comparison.
6973
+ * @param right The right value in the comparison.
6974
+ */
6975
+ static lessThan(left, right) {
6976
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
6977
+ return left.compareTo(right) === 0 /* LessThan */;
6823
6978
  }
6824
- static concatenate(headers, ...toConcatenate) {
6825
- return Iterable.concatenate(headers, ...toConcatenate);
6979
+ /**
6980
+ * Get whether this value is less than or equal to the provided value.
6981
+ * @param value The value to compare against.
6982
+ */
6983
+ lessThanOrEqualTo(value) {
6984
+ return _Comparable.lessThanOrEqualTo(this, value);
6826
6985
  }
6827
- map(mapping) {
6828
- return _HttpHeaders.map(this, mapping);
6986
+ /**
6987
+ * Get whether the left value is less than or equal to the right value.
6988
+ * @param left The left value in the comparison.
6989
+ * @param right The right value in the comparison.
6990
+ */
6991
+ static lessThanOrEqualTo(left, right) {
6992
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
6993
+ return left.compareTo(right) !== 2 /* GreaterThan */;
6829
6994
  }
6830
- static map(headers, mapping) {
6831
- return Iterable.map(headers, mapping);
6995
+ /**
6996
+ * Get whether this value equals the provided value.
6997
+ * @param value The value to compare against.
6998
+ */
6999
+ equals(value) {
7000
+ return _Comparable.equals(this, value);
6832
7001
  }
6833
- flatMap(mapping) {
6834
- return _HttpHeaders.flatMap(this, mapping);
7002
+ /**
7003
+ * Get whether the left value equals the right value.
7004
+ * @param left The left value in the comparison.
7005
+ * @param right The right value in the comparison.
7006
+ */
7007
+ static equals(left, right) {
7008
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7009
+ return left.compareTo(right) === 1 /* Equal */;
6835
7010
  }
6836
- static flatMap(headers, mapping) {
6837
- return Iterable.flatMap(headers, mapping);
7011
+ /**
7012
+ * Get whether this value is not equal to the provided value.
7013
+ * @param value The value to compare against.
7014
+ */
7015
+ notEquals(value) {
7016
+ return _Comparable.notEquals(this, value);
6838
7017
  }
6839
- where(condition) {
6840
- return _HttpHeaders.where(this, condition);
7018
+ /**
7019
+ * Get whether the left value is not equal to the right value.
7020
+ * @param left The left value in the comparison.
7021
+ * @param right The right value in the comparison.
7022
+ */
7023
+ static notEquals(left, right) {
7024
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7025
+ return left.compareTo(right) !== 1 /* Equal */;
6841
7026
  }
6842
- static where(headers, condition) {
6843
- return Iterable.where(headers, condition);
7027
+ /**
7028
+ * Get whether this value is greater than or equal to the provided value.
7029
+ * @param value The value to compare against.
7030
+ */
7031
+ greaterThanOrEqualTo(value) {
7032
+ return _Comparable.greaterThanOrEqualTo(this, value);
6844
7033
  }
6845
- instanceOf(typeOrTypeCheck) {
6846
- return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
7034
+ /**
7035
+ * Get whether the left value is greater than or equal to the right value.
7036
+ * @param left The left value in the comparison.
7037
+ * @param right The right value in the comparison.
7038
+ */
7039
+ static greaterThanOrEqualTo(left, right) {
7040
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7041
+ return left.compareTo(right) !== 0 /* LessThan */;
6847
7042
  }
6848
- static instanceOf(headers, typeOrTypeCheck) {
6849
- return Iterable.instanceOf(headers, typeOrTypeCheck);
7043
+ /**
7044
+ * Get whether this value is greater than the provided value.
7045
+ * @param value The value to compare against.
7046
+ */
7047
+ greaterThan(value) {
7048
+ return _Comparable.greaterThan(this, value);
6850
7049
  }
6851
- first(condition) {
6852
- return _HttpHeaders.first(this, condition);
7050
+ /**
7051
+ * Get whether the left value is greater than the right value.
7052
+ * @param left The left value in the comparison.
7053
+ * @param right The right value in the comparison.
7054
+ */
7055
+ static greaterThan(left, right) {
7056
+ PreCondition.assertNotUndefinedAndNotNull(left, "left");
7057
+ return left.compareTo(right) === 2 /* GreaterThan */;
6853
7058
  }
6854
- static first(headers, condition) {
6855
- return Iterable.first(headers, condition);
7059
+ };
7060
+
7061
+ // sources/nodeJSCharacterWriteStream.ts
7062
+ var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
7063
+ nodeJSWriteStream;
7064
+ constructor(nodeJSWriteStream) {
7065
+ PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
7066
+ super();
7067
+ this.nodeJSWriteStream = nodeJSWriteStream;
6856
7068
  }
6857
- last(condition) {
6858
- return _HttpHeaders.last(this, condition);
7069
+ static create(nodeJSWriteStream) {
7070
+ return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
6859
7071
  }
6860
- static last(headers, condition) {
6861
- return Iterable.last(headers, condition);
7072
+ writeString(text) {
7073
+ PreCondition.assertNotUndefinedAndNotNull(text, "text");
7074
+ return PromiseAsyncResult.create(new Promise((resolve, reject) => {
7075
+ this.nodeJSWriteStream.write(text, (error) => {
7076
+ if (error) {
7077
+ reject(error);
7078
+ } else {
7079
+ resolve(text.length);
7080
+ }
7081
+ });
7082
+ }));
6862
7083
  }
6863
- [Symbol.iterator]() {
6864
- return _HttpHeaders[Symbol.iterator](this);
7084
+ };
7085
+
7086
+ // sources/property.ts
7087
+ var Property = class _Property {
7088
+ getter;
7089
+ setter;
7090
+ constructor(getter, setter) {
7091
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
7092
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
7093
+ this.getter = getter;
7094
+ this.setter = setter;
7095
+ }
7096
+ static create(getterOptionsOrInitialValue, setter) {
7097
+ let getter;
7098
+ if (isFunction(getterOptionsOrInitialValue)) {
7099
+ getter = getterOptionsOrInitialValue;
7100
+ } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
7101
+ const options = getterOptionsOrInitialValue;
7102
+ getter = options.getter;
7103
+ setter = options.setter;
7104
+ } else {
7105
+ let initialValue = getterOptionsOrInitialValue;
7106
+ getter = () => {
7107
+ return initialValue;
7108
+ };
7109
+ setter = (value) => {
7110
+ initialValue = value;
7111
+ };
7112
+ }
7113
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
7114
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
7115
+ return new _Property(getter, setter);
6865
7116
  }
6866
- static [Symbol.iterator](headers) {
6867
- return Iterable[Symbol.iterator](headers);
7117
+ getValue() {
7118
+ return this.getter();
6868
7119
  }
6869
- contains(value, equalFunctions) {
6870
- return _HttpHeaders.contains(this, value, equalFunctions);
7120
+ setValue(value) {
7121
+ this.setter(value);
7122
+ return this;
6871
7123
  }
6872
- static contains(headers, value, equalFunctions) {
6873
- return SyncResult.create(() => {
6874
- if (!equalFunctions) {
6875
- equalFunctions = EqualFunctions.create();
6876
- }
6877
- return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
6878
- });
7124
+ toString() {
7125
+ return `${this.getValue()}`;
6879
7126
  }
6880
7127
  };
6881
7128
 
@@ -7120,14 +7367,27 @@ var FetchHttpClient = class _FetchHttpClient {
7120
7367
  }
7121
7368
  sendRequest(request) {
7122
7369
  PreCondition.assertNotUndefinedAndNotNull(request, "request");
7123
- return PromiseAsyncResult.create(async () => {
7370
+ return AsyncResult.create(async () => {
7371
+ const fetchURL = request.getURL();
7372
+ const fetchMethod = _FetchHttpClient.convertMethod(request.getMethod());
7373
+ const fetchHeaders = request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await();
7374
+ const fetchBody = request.getBody() || void 0;
7124
7375
  const requestInit = {
7125
- method: _FetchHttpClient.convertMethod(request.getMethod()),
7126
- headers: request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await(),
7127
- body: request.getBody() || void 0
7376
+ method: fetchMethod,
7377
+ headers: fetchHeaders,
7378
+ body: fetchBody
7128
7379
  };
7129
- const fetchResponse = await fetch(request.getURL(), requestInit);
7130
- return FetchHttpIncomingResponse.create(fetchResponse);
7380
+ let result;
7381
+ try {
7382
+ const fetchResponse = await fetch(fetchURL, requestInit);
7383
+ result = FetchHttpIncomingResponse.create(fetchResponse);
7384
+ } catch (error) {
7385
+ if (error instanceof Error && error.cause instanceof Error) {
7386
+ throw new FetchError(error.cause);
7387
+ }
7388
+ throw error;
7389
+ }
7390
+ return result;
7131
7391
  });
7132
7392
  }
7133
7393
  sendGetRequest(url) {
@@ -7181,83 +7441,6 @@ import * as http from "http";
7181
7441
  var HttpServer = class {
7182
7442
  };
7183
7443
 
7184
- // sources/httpOutgoingResponse.ts
7185
- var HttpOutgoingResponse = class _HttpOutgoingResponse {
7186
- statusCode;
7187
- headers;
7188
- body;
7189
- constructor() {
7190
- this.statusCode = 200;
7191
- this.headers = MutableHttpHeaders.create();
7192
- this.body = "";
7193
- }
7194
- static create() {
7195
- return new _HttpOutgoingResponse();
7196
- }
7197
- /**
7198
- * Get the status code of this {@link HttpOutgoingResponse}.
7199
- */
7200
- getStatusCode() {
7201
- return this.statusCode;
7202
- }
7203
- /**
7204
- * Set the status code of this {@link HttpOutgoingResponse}.
7205
- * @param statusCode The status code of this {@link HttpOutgoingResponse}.
7206
- */
7207
- setStatusCode(statusCode) {
7208
- PreCondition.assertBetween(100, statusCode, 599, "statusCode");
7209
- this.statusCode = statusCode;
7210
- return this;
7211
- }
7212
- getHeaders() {
7213
- return this.headers;
7214
- }
7215
- /**
7216
- * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
7217
- * doesn't exist.
7218
- * @param headerName The name of the header to get.
7219
- */
7220
- getHeader(headerName) {
7221
- return this.headers.get(headerName);
7222
- }
7223
- /**
7224
- * Get the value of the header with the provided name or return a {@link NotFoundError} if the
7225
- * header doesn't exist.
7226
- * @param headerName The name of the header value to get.
7227
- */
7228
- getHeaderValue(headerName) {
7229
- return this.headers.getValue(headerName);
7230
- }
7231
- /**
7232
- * Set the HTTP header in this {@link HttpOutgoingResponse}.
7233
- * @param headerName The name of the HTTP header.
7234
- * @param headerValue The value of the HTTP header.
7235
- */
7236
- setHeader(headerName, headerValue) {
7237
- this.headers.set(headerName, headerValue);
7238
- return this;
7239
- }
7240
- setContentTypeHeader(contentType) {
7241
- this.headers.setContentType(contentType);
7242
- return this;
7243
- }
7244
- /**
7245
- * Get the body of this {@link HttpOutgoingResponse}.
7246
- */
7247
- getBody() {
7248
- return this.body;
7249
- }
7250
- /**
7251
- * Set the body of this {@link HttpOutgoingResponse}.
7252
- * @param body The body for this {@link HttpOutgoingResponse}.
7253
- */
7254
- setBody(body) {
7255
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
7256
- this.body = body;
7257
- return this;
7258
- }
7259
- };
7260
-
7261
7444
  // sources/nodeJSHttpServer.ts
7262
7445
  var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
7263
7446
  httpServer;
@@ -7310,16 +7493,9 @@ var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
7310
7493
  reject(new Error("Can't run a HttpServer multiple times."));
7311
7494
  } else {
7312
7495
  this.httpServer = http.createServer();
7313
- this.httpServer.on("request", (request, response) => {
7314
- const httpResponse = HttpOutgoingResponse.create().setStatusCode(200).setHeader("Content-Type", "text/plain").setBody("Hello world!");
7315
- const statusCode = httpResponse.getStatusCode();
7316
- const headers = httpResponse.getHeaders();
7317
- const responseHeaders = {};
7318
- for (const header of headers) {
7319
- responseHeaders[header.getName()] = header.getValue();
7320
- }
7321
- response.writeHead(statusCode, responseHeaders);
7322
- response.end(httpResponse.getBody());
7496
+ this.httpServer.on("request", async (rawRequest, rawResponse) => {
7497
+ const response = NodeJSHttpOutgoingResponse.create(rawResponse).setStatusCode(200).setHeader("Content-Type", "text/plain").setBodyString("Hello world!");
7498
+ await response.end();
7323
7499
  });
7324
7500
  this.httpServer.on("close", () => {
7325
7501
  resolve();
@@ -7446,149 +7622,6 @@ var CurrentProcess = class _CurrentProcess {
7446
7622
  }
7447
7623
  };
7448
7624
 
7449
- // sources/luxonDateTime.ts
7450
- import * as luxon from "luxon";
7451
- var pctTimeZone = "America/Los_Angeles";
7452
- var LuxonDateTime = class _LuxonDateTime {
7453
- dateTime;
7454
- constructor(dateTime) {
7455
- this.dateTime = dateTime;
7456
- }
7457
- static create(dateTime) {
7458
- return new _LuxonDateTime(dateTime);
7459
- }
7460
- static parse(text) {
7461
- return _LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
7462
- }
7463
- static now() {
7464
- return _LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
7465
- }
7466
- getYear() {
7467
- return this.dateTime.year;
7468
- }
7469
- getMonth() {
7470
- return this.dateTime.month;
7471
- }
7472
- getDay() {
7473
- return this.dateTime.day;
7474
- }
7475
- getHour() {
7476
- return this.dateTime.hour;
7477
- }
7478
- getMinute() {
7479
- return this.dateTime.minute;
7480
- }
7481
- getSecond() {
7482
- return this.dateTime.second;
7483
- }
7484
- addDays(days) {
7485
- return _LuxonDateTime.create(this.dateTime.plus({ days }));
7486
- }
7487
- toString() {
7488
- return this.dateTime.toISO();
7489
- }
7490
- toDateString() {
7491
- return this.dateTime.toISODate();
7492
- }
7493
- compareTo(dateTime, compareTimes) {
7494
- return DateTime2.compareTo(this, dateTime, compareTimes);
7495
- }
7496
- lessThan(dateTime, compareTimes) {
7497
- return DateTime2.lessThan(this, dateTime, compareTimes);
7498
- }
7499
- lessThanOrEqualTo(dateTime, compareTimes) {
7500
- return DateTime2.lessThanOrEqualTo(this, dateTime, compareTimes);
7501
- }
7502
- equals(dateTime, compareTimes) {
7503
- return DateTime2.equals(this, dateTime, compareTimes);
7504
- }
7505
- greaterThanOrEqualTo(dateTime, compareTimes) {
7506
- return DateTime2.greaterThanOrEqualTo(this, dateTime, compareTimes);
7507
- }
7508
- greaterThan(dateTime, compareTimes) {
7509
- return DateTime2.greaterThan(this, dateTime, compareTimes);
7510
- }
7511
- get debug() {
7512
- return DateTime2.debug(this);
7513
- }
7514
- };
7515
-
7516
- // sources/dateTime.ts
7517
- var DateTime2 = class _DateTime {
7518
- static parse(text) {
7519
- return LuxonDateTime.parse(text);
7520
- }
7521
- static now() {
7522
- return LuxonDateTime.now();
7523
- }
7524
- /**
7525
- * Compare this {@link DateTime} to the provided {@link DateTime}. If this {@link DateTime} is
7526
- * less than the provided {@link DateTime}, then a negative number will be returned, 0 if
7527
- * they're equal, or a positive number if this {@link DateTime} is greater than the provided
7528
- * {@link DateTime}.
7529
- * @param dateTime The {@link DateTime} to compare to this {@link DateTime}.
7530
- */
7531
- compareTo(dateTime, compareTimes) {
7532
- return _DateTime.compareTo(this, dateTime, compareTimes);
7533
- }
7534
- static compareTo(left, right, compareTimes) {
7535
- let result = left.getYear() - right.getYear();
7536
- if (result === 0) {
7537
- result = left.getMonth() - right.getMonth();
7538
- if (result === 0) {
7539
- result = left.getDay() - right.getDay();
7540
- if (compareTimes && result === 0) {
7541
- result = left.getHour() - right.getHour();
7542
- if (result === 0) {
7543
- result = left.getMinute() - right.getMinute();
7544
- if (result === 0) {
7545
- result = left.getSecond();
7546
- -right.getSecond();
7547
- }
7548
- }
7549
- }
7550
- }
7551
- }
7552
- return result;
7553
- }
7554
- lessThan(dateTime, compareTimes) {
7555
- return _DateTime.lessThan(this, dateTime, compareTimes);
7556
- }
7557
- static lessThan(left, right, compareTimes) {
7558
- return left.compareTo(right, compareTimes) < 0;
7559
- }
7560
- lessThanOrEqualTo(dateTime, compareTimes) {
7561
- return _DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
7562
- }
7563
- static lessThanOrEqualTo(left, right, compareTimes) {
7564
- return left.compareTo(right, compareTimes) <= 0;
7565
- }
7566
- equals(dateTime, compareTimes) {
7567
- return _DateTime.equals(this, dateTime, compareTimes);
7568
- }
7569
- static equals(left, right, compareTimes) {
7570
- return left.compareTo(right, compareTimes) === 0;
7571
- }
7572
- greaterThanOrEqualTo(dateTime, compareTimes) {
7573
- return _DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
7574
- }
7575
- static greaterThanOrEqualTo(left, right, compareTimes) {
7576
- return left.compareTo(right, compareTimes) >= 0;
7577
- }
7578
- greaterThan(dateTime, compareTimes) {
7579
- return _DateTime.greaterThan(this, dateTime, compareTimes);
7580
- }
7581
- static greaterThan(left, right, compareTimes) {
7582
- return left.compareTo(right, compareTimes) > 0;
7583
- }
7584
- get debug() {
7585
- return _DateTime.debug(this);
7586
- }
7587
- static debug(dateTime) {
7588
- return dateTime.toString();
7589
- }
7590
- };
7591
-
7592
7625
  // sources/listStack.ts
7593
7626
  var ListStack = class _ListStack {
7594
7627
  list;
@@ -7948,6 +7981,10 @@ var HttpClient = class _HttpClient {
7948
7981
  var HttpIncomingRequest = class {
7949
7982
  };
7950
7983
 
7984
+ // sources/httpOutgoingResponse.ts
7985
+ var HttpOutgoingResponse = class {
7986
+ };
7987
+
7951
7988
  // sources/inMemoryCharacterWriteStream.ts
7952
7989
  var InMemoryCharacterWriteStream = class _InMemoryCharacterWriteStream extends CharacterWriteStream {
7953
7990
  writtenText;
@@ -9472,11 +9509,20 @@ export {
9472
9509
  Iterable,
9473
9510
  Indexable,
9474
9511
  CharacterTable,
9512
+ LuxonDateTime,
9513
+ DateTime2 as DateTime,
9514
+ RealClock,
9515
+ Clock,
9516
+ FetchError,
9475
9517
  AsyncResult,
9476
9518
  PostConditionError,
9477
9519
  PostCondition,
9478
9520
  CharacterWriteStream,
9479
9521
  IndentedCharacterWriteStream,
9522
+ HttpHeader,
9523
+ MutableHttpHeaders,
9524
+ HttpHeaders,
9525
+ NodeJSHttpOutgoingResponse,
9480
9526
  TokenType,
9481
9527
  Token,
9482
9528
  Tokenizer,
@@ -9504,9 +9550,6 @@ export {
9504
9550
  Comparable,
9505
9551
  NodeJSCharacterWriteStream,
9506
9552
  Property,
9507
- HttpHeader,
9508
- MutableHttpHeaders,
9509
- HttpHeaders,
9510
9553
  HttpIncomingResponse,
9511
9554
  FetchHttpIncomingResponse,
9512
9555
  HttpMethod,
@@ -9516,12 +9559,9 @@ export {
9516
9559
  FetchHttpClient,
9517
9560
  Network,
9518
9561
  HttpServer,
9519
- HttpOutgoingResponse,
9520
9562
  NodeJSHttpServer,
9521
9563
  RealNetwork,
9522
9564
  CurrentProcess,
9523
- LuxonDateTime,
9524
- DateTime2 as DateTime,
9525
9565
  ListStack,
9526
9566
  Stack,
9527
9567
  depthFirstSearch,
@@ -9529,6 +9569,7 @@ export {
9529
9569
  Generator,
9530
9570
  HttpClient,
9531
9571
  HttpIncomingRequest,
9572
+ HttpOutgoingResponse,
9532
9573
  InMemoryCharacterWriteStream,
9533
9574
  ListQueue,
9534
9575
  Node,
@@ -9549,4 +9590,4 @@ export {
9549
9590
  WonderlandTrailItinerary,
9550
9591
  WonderlandTrailClient
9551
9592
  };
9552
- //# sourceMappingURL=chunk-U7O7WS5F.js.map
9593
+ //# sourceMappingURL=chunk-TUBXFCG4.js.map