@everyonesoftware/common 11.0.0 → 12.0.0

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