@everyonesoftware/common 11.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,7 @@ __export(tests_exports, {
34
34
  BasicTestSkip: () => BasicTestSkip,
35
35
  ConsoleTestRunner: () => ConsoleTestRunner,
36
36
  FailedTest: () => FailedTest,
37
+ FakeClock: () => FakeClock,
37
38
  SkippedTest: () => SkippedTest,
38
39
  Test: () => Test,
39
40
  TestAction: () => TestAction,
@@ -4165,6 +4166,187 @@ var ANSIStyles = class {
4165
4166
  }
4166
4167
  };
4167
4168
 
4169
+ // sources/luxonDateTime.ts
4170
+ var luxon = __toESM(require("luxon"), 1);
4171
+ var pctTimeZone = "America/Los_Angeles";
4172
+ var LuxonDateTime = class _LuxonDateTime {
4173
+ dateTime;
4174
+ constructor(dateTime) {
4175
+ this.dateTime = dateTime;
4176
+ }
4177
+ static create(dateTime) {
4178
+ return new _LuxonDateTime(dateTime);
4179
+ }
4180
+ static parse(text) {
4181
+ return _LuxonDateTime.create(luxon.DateTime.fromISO(text, { zone: pctTimeZone }));
4182
+ }
4183
+ static now() {
4184
+ return _LuxonDateTime.create(luxon.DateTime.now().setZone(pctTimeZone));
4185
+ }
4186
+ getYear() {
4187
+ return this.dateTime.year;
4188
+ }
4189
+ getMonth() {
4190
+ return this.dateTime.month;
4191
+ }
4192
+ getDay() {
4193
+ return this.dateTime.day;
4194
+ }
4195
+ getHour() {
4196
+ return this.dateTime.hour;
4197
+ }
4198
+ getMinute() {
4199
+ return this.dateTime.minute;
4200
+ }
4201
+ getSecond() {
4202
+ return this.dateTime.second;
4203
+ }
4204
+ addDays(days) {
4205
+ return _LuxonDateTime.create(this.dateTime.plus({ days }));
4206
+ }
4207
+ toString() {
4208
+ return this.dateTime.toISO();
4209
+ }
4210
+ toDateString() {
4211
+ return this.dateTime.toISODate();
4212
+ }
4213
+ toShortDateString() {
4214
+ return `${this.dateTime.monthShort} ${this.dateTime.day}`;
4215
+ }
4216
+ compareTo(dateTime, compareTimes) {
4217
+ return DateTime2.compareTo(this, dateTime, compareTimes);
4218
+ }
4219
+ lessThan(dateTime, compareTimes) {
4220
+ return DateTime2.lessThan(this, dateTime, compareTimes);
4221
+ }
4222
+ lessThanOrEqualTo(dateTime, compareTimes) {
4223
+ return DateTime2.lessThanOrEqualTo(this, dateTime, compareTimes);
4224
+ }
4225
+ equals(dateTime, compareTimes) {
4226
+ return DateTime2.equals(this, dateTime, compareTimes);
4227
+ }
4228
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4229
+ return DateTime2.greaterThanOrEqualTo(this, dateTime, compareTimes);
4230
+ }
4231
+ greaterThan(dateTime, compareTimes) {
4232
+ return DateTime2.greaterThan(this, dateTime, compareTimes);
4233
+ }
4234
+ get debug() {
4235
+ return DateTime2.debug(this);
4236
+ }
4237
+ };
4238
+
4239
+ // sources/dateTime.ts
4240
+ var DateTime2 = class _DateTime {
4241
+ static parse(text) {
4242
+ return LuxonDateTime.parse(text);
4243
+ }
4244
+ static now() {
4245
+ return LuxonDateTime.now();
4246
+ }
4247
+ /**
4248
+ * Compare this {@link DateTime} to the provided {@link DateTime}. If this {@link DateTime} is
4249
+ * less than the provided {@link DateTime}, then a negative number will be returned, 0 if
4250
+ * they're equal, or a positive number if this {@link DateTime} is greater than the provided
4251
+ * {@link DateTime}.
4252
+ * @param dateTime The {@link DateTime} to compare to this {@link DateTime}.
4253
+ */
4254
+ compareTo(dateTime, compareTimes) {
4255
+ return _DateTime.compareTo(this, dateTime, compareTimes);
4256
+ }
4257
+ static compareTo(left, right, compareTimes) {
4258
+ let result = left.getYear() - right.getYear();
4259
+ if (result === 0) {
4260
+ result = left.getMonth() - right.getMonth();
4261
+ if (result === 0) {
4262
+ result = left.getDay() - right.getDay();
4263
+ if (compareTimes && result === 0) {
4264
+ result = left.getHour() - right.getHour();
4265
+ if (result === 0) {
4266
+ result = left.getMinute() - right.getMinute();
4267
+ if (result === 0) {
4268
+ result = left.getSecond();
4269
+ -right.getSecond();
4270
+ }
4271
+ }
4272
+ }
4273
+ }
4274
+ }
4275
+ return result;
4276
+ }
4277
+ lessThan(dateTime, compareTimes) {
4278
+ return _DateTime.lessThan(this, dateTime, compareTimes);
4279
+ }
4280
+ static lessThan(left, right, compareTimes) {
4281
+ return left.compareTo(right, compareTimes) < 0;
4282
+ }
4283
+ lessThanOrEqualTo(dateTime, compareTimes) {
4284
+ return _DateTime.lessThanOrEqualTo(this, dateTime, compareTimes);
4285
+ }
4286
+ static lessThanOrEqualTo(left, right, compareTimes) {
4287
+ return left.compareTo(right, compareTimes) <= 0;
4288
+ }
4289
+ equals(dateTime, compareTimes) {
4290
+ return _DateTime.equals(this, dateTime, compareTimes);
4291
+ }
4292
+ static equals(left, right, compareTimes) {
4293
+ return left.compareTo(right, compareTimes) === 0;
4294
+ }
4295
+ greaterThanOrEqualTo(dateTime, compareTimes) {
4296
+ return _DateTime.greaterThanOrEqualTo(this, dateTime, compareTimes);
4297
+ }
4298
+ static greaterThanOrEqualTo(left, right, compareTimes) {
4299
+ return left.compareTo(right, compareTimes) >= 0;
4300
+ }
4301
+ greaterThan(dateTime, compareTimes) {
4302
+ return _DateTime.greaterThan(this, dateTime, compareTimes);
4303
+ }
4304
+ static greaterThan(left, right, compareTimes) {
4305
+ return left.compareTo(right, compareTimes) > 0;
4306
+ }
4307
+ get debug() {
4308
+ return _DateTime.debug(this);
4309
+ }
4310
+ static debug(dateTime) {
4311
+ return dateTime.toString();
4312
+ }
4313
+ };
4314
+
4315
+ // sources/RealClock.ts
4316
+ var RealClock = class _RealClock {
4317
+ constructor() {
4318
+ }
4319
+ static create() {
4320
+ return new _RealClock();
4321
+ }
4322
+ now() {
4323
+ return DateTime2.now();
4324
+ }
4325
+ };
4326
+
4327
+ // sources/Clock.ts
4328
+ var Clock = class {
4329
+ static create() {
4330
+ return RealClock.create();
4331
+ }
4332
+ };
4333
+
4334
+ // sources/FetchError.ts
4335
+ var FetchError = class extends Error {
4336
+ innerError;
4337
+ constructor(innerError) {
4338
+ PreCondition.assertNotUndefinedAndNotNull(innerError, "innerError");
4339
+ super(innerError.message, { cause: innerError });
4340
+ this.innerError = innerError;
4341
+ }
4342
+ get code() {
4343
+ return "code" in this.innerError ? this.innerError.code : void 0;
4344
+ }
4345
+ get hostname() {
4346
+ return "hostname" in this.innerError ? this.innerError.hostname : void 0;
4347
+ }
4348
+ };
4349
+
4168
4350
  // sources/asyncResult.ts
4169
4351
  var AsyncResult = class {
4170
4352
  static create(actionOrPromise) {
@@ -4546,592 +4728,658 @@ var IndentedCharacterWriteStream = class _IndentedCharacterWriteStream extends C
4546
4728
  }
4547
4729
  };
4548
4730
 
4549
- // sources/TokenType.ts
4550
- var TokenType = class _TokenType {
4731
+ // sources/httpHeader.ts
4732
+ var HttpHeader = class _HttpHeader {
4551
4733
  name;
4552
- constructor(name) {
4734
+ value;
4735
+ constructor(name, value) {
4553
4736
  PreCondition.assertNotEmpty(name, "name");
4737
+ PreCondition.assertNotUndefinedAndNotNull(value, "value");
4554
4738
  this.name = name;
4739
+ this.value = value;
4555
4740
  }
4556
- static create(name) {
4557
- return new _TokenType(name);
4741
+ static create(name, value) {
4742
+ return new _HttpHeader(name, value);
4558
4743
  }
4559
- static Whitespace = _TokenType.create("Whitespace");
4560
- static NewLine = _TokenType.create("NewLine");
4561
- static Letters = _TokenType.create("Letters");
4562
- static Digits = _TokenType.create("Digits");
4563
- static LeftParenthesis = _TokenType.create("LeftParenthesis");
4564
- static RightParenthesis = _TokenType.create("RightParenthesis");
4565
- static Backslash = _TokenType.create("Backslash");
4566
- static ForwardSlash = _TokenType.create("ForwardSlash");
4567
- static Unknown = _TokenType.create("Unknown");
4568
- static Period = _TokenType.create("Period");
4569
- static Underscore = _TokenType.create("Underscore");
4570
- static Colon = _TokenType.create("Colon");
4571
- toString() {
4744
+ getName() {
4572
4745
  return this.name;
4573
4746
  }
4747
+ getValue() {
4748
+ return this.value;
4749
+ }
4750
+ toString() {
4751
+ return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
4752
+ }
4574
4753
  };
4575
4754
 
4576
- // sources/Token.ts
4577
- var Token = class _Token {
4578
- static newLineToken = _Token.create("\n", TokenType.NewLine);
4579
- static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
4580
- static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
4581
- static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
4582
- static backslashToken = _Token.create("\\", TokenType.Backslash);
4583
- static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
4584
- static periodToken = _Token.create(".", TokenType.Period);
4585
- static underscoreToken = _Token.create("_", TokenType.Underscore);
4586
- static colonToken = _Token.create(":", TokenType.Colon);
4587
- text;
4588
- type;
4589
- constructor(text, type) {
4590
- PreCondition.assertNotEmpty(text, "text");
4591
- PreCondition.assertNotUndefinedAndNotNull(type, "type");
4592
- this.text = text;
4593
- this.type = type;
4755
+ // sources/mutableHttpHeaders.ts
4756
+ var MutableHttpHeaders = class _MutableHttpHeaders {
4757
+ headers;
4758
+ constructor(headers) {
4759
+ this.headers = List.create();
4760
+ if (headers) {
4761
+ this.setAll(headers);
4762
+ }
4594
4763
  }
4595
- static create(text, type) {
4596
- return new _Token(text, type);
4764
+ static create(headers) {
4765
+ return new _MutableHttpHeaders(headers);
4597
4766
  }
4598
- static whitespace(text) {
4599
- return _Token.create(text, TokenType.Whitespace);
4767
+ iterate() {
4768
+ return this.headers.iterate();
4600
4769
  }
4601
- static newLine(text) {
4602
- text ??= "\n";
4603
- let result;
4604
- switch (text) {
4605
- case "\n":
4606
- result = _Token.newLineToken;
4607
- break;
4608
- case "\r\n":
4609
- result = _Token.carriageReturnNewLineToken;
4610
- break;
4611
- default:
4612
- result = _Token.create(text, TokenType.NewLine);
4770
+ get(headerName) {
4771
+ PreCondition.assertNotEmpty(headerName, "headerName");
4772
+ return SyncResult.create(() => {
4773
+ let result;
4774
+ const lowerHeaderName = headerName.toLowerCase();
4775
+ for (const header of this.headers) {
4776
+ if (header.getName().toLowerCase() === lowerHeaderName) {
4777
+ result = header;
4778
+ break;
4779
+ }
4780
+ }
4781
+ if (result === void 0) {
4782
+ throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
4783
+ }
4784
+ return result;
4785
+ });
4786
+ }
4787
+ getValue(headerName) {
4788
+ return this.get(headerName).then((header) => header.getValue());
4789
+ }
4790
+ set(headerOrHeaderName, headerValue) {
4791
+ let headerName;
4792
+ if (isString(headerOrHeaderName)) {
4793
+ headerName = headerOrHeaderName;
4794
+ } else {
4795
+ headerName = headerOrHeaderName.getName();
4796
+ headerValue = headerOrHeaderName.getValue();
4797
+ }
4798
+ PreCondition.assertNotEmpty(headerName, "headerName");
4799
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
4800
+ let insertIndex = 0;
4801
+ for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
4802
+ const header = this.headers.get(insertIndex2).await();
4803
+ if (header.getName() === headerName) {
4804
+ this.headers.removeAt(insertIndex2);
4613
4805
  break;
4806
+ }
4614
4807
  }
4615
- return result;
4808
+ this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
4809
+ return this;
4616
4810
  }
4617
- static leftParenthesis() {
4618
- return _Token.leftParenthesisToken;
4811
+ setAll(headers) {
4812
+ PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
4813
+ for (const header of headers) {
4814
+ this.set(header);
4815
+ }
4816
+ return this;
4619
4817
  }
4620
- static rightParenthesis() {
4621
- return _Token.rightParenthesisToken;
4818
+ setContentType(contentType) {
4819
+ return this.set(HttpHeaders.contentTypeHeaderName, contentType);
4622
4820
  }
4623
- static backslash() {
4624
- return _Token.backslashToken;
4821
+ getContentType() {
4822
+ return this.get(HttpHeaders.contentTypeHeaderName);
4625
4823
  }
4626
- static forwardSlash() {
4627
- return _Token.forwardSlashToken;
4824
+ getContentTypeValue() {
4825
+ return this.getValue(HttpHeaders.contentTypeHeaderName);
4628
4826
  }
4629
- static period() {
4630
- return _Token.periodToken;
4827
+ getCount() {
4828
+ return this.headers.getCount();
4631
4829
  }
4632
- static underscore() {
4633
- return _Token.underscoreToken;
4830
+ toArray() {
4831
+ return HttpHeaders.toArray(this);
4634
4832
  }
4635
- static colon() {
4636
- return _Token.colonToken;
4833
+ any() {
4834
+ return HttpHeaders.any(this);
4637
4835
  }
4638
- static letters(text) {
4639
- return _Token.create(text, TokenType.Letters);
4836
+ equals(right, equalFunctions) {
4837
+ return HttpHeaders.equals(this, right, equalFunctions);
4640
4838
  }
4641
- static digits(text) {
4642
- return _Token.create(text, TokenType.Digits);
4839
+ toString(toStringFunctions) {
4840
+ return HttpHeaders.toString(this, toStringFunctions);
4643
4841
  }
4644
- static unknown(text) {
4645
- return _Token.create(text, TokenType.Unknown);
4842
+ concatenate(...toConcatenate) {
4843
+ return HttpHeaders.concatenate(this, ...toConcatenate);
4646
4844
  }
4647
- getText() {
4648
- return this.text;
4845
+ map(mapping) {
4846
+ return HttpHeaders.map(this, mapping);
4649
4847
  }
4650
- getType() {
4651
- return this.type;
4848
+ flatMap(mapping) {
4849
+ return HttpHeaders.flatMap(this, mapping);
4850
+ }
4851
+ where(condition) {
4852
+ return HttpHeaders.where(this, condition);
4853
+ }
4854
+ instanceOf(typeOrTypeCheck) {
4855
+ return HttpHeaders.instanceOf(this, typeOrTypeCheck);
4856
+ }
4857
+ first(condition) {
4858
+ return HttpHeaders.first(this, condition);
4859
+ }
4860
+ last(condition) {
4861
+ return HttpHeaders.last(this, condition);
4862
+ }
4863
+ [Symbol.iterator]() {
4864
+ return HttpHeaders[Symbol.iterator](this);
4865
+ }
4866
+ contains(value, equalFunctions) {
4867
+ return HttpHeaders.contains(this, value, equalFunctions);
4652
4868
  }
4653
4869
  };
4654
4870
 
4655
- // sources/english.ts
4656
- function andList(values) {
4657
- return list("and", values);
4658
- }
4659
- function orList(values) {
4660
- return list("or", values);
4661
- }
4662
- function list(conjunction, values) {
4663
- PreCondition.assertNotEmpty(conjunction, "conjunction");
4664
- PreCondition.assertNotUndefinedAndNotNull(values, "values");
4665
- let result = "";
4666
- let index = 0;
4667
- const iterator = Iterator.create(values).start().await();
4668
- while (iterator.hasCurrent()) {
4669
- const currentValue = iterator.takeCurrent().await();
4670
- if (index >= 1) {
4671
- if (iterator.hasCurrent()) {
4672
- result += `, `;
4673
- } else {
4674
- if (index >= 2) {
4675
- result += `,`;
4676
- }
4677
- result += ` ${conjunction} `;
4678
- }
4679
- }
4680
- result += currentValue;
4681
- index++;
4871
+ // sources/httpHeaders.ts
4872
+ var HttpHeaders = class _HttpHeaders {
4873
+ static contentTypeHeaderName = "Content-Type";
4874
+ static create(headers) {
4875
+ return MutableHttpHeaders.create(headers);
4682
4876
  }
4683
- return result;
4684
- }
4685
-
4686
- // sources/commandLineParameters.ts
4687
- var CommandLineParameters = class _CommandLineParameters {
4688
- args;
4689
- parameters;
4690
- constructor(argv) {
4691
- PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
4692
- this.args = isIterable(argv) ? argv : Iterable.create(argv);
4693
- this.parameters = List.create();
4877
+ getContentType() {
4878
+ return _HttpHeaders.getContentType(this);
4694
4879
  }
4695
- static create(args) {
4696
- return new _CommandLineParameters(args);
4880
+ static getContentType(headers) {
4881
+ return headers.get(_HttpHeaders.contentTypeHeaderName);
4697
4882
  }
4698
- static getArgumentName(arg) {
4699
- return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
4883
+ getContentTypeValue() {
4884
+ return _HttpHeaders.getContentTypeValue(this);
4700
4885
  }
4701
- getArguments() {
4702
- return this.args;
4886
+ static getContentTypeValue(headers) {
4887
+ return headers.getValue(_HttpHeaders.contentTypeHeaderName);
4703
4888
  }
4704
4889
  /**
4705
- * Get the value of the first argument that matches one of the provided names.
4706
- * @param names The possible names to look for.
4890
+ * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
4707
4891
  */
4708
- getNamedArgumentStringValue(nameOrNames) {
4709
- PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
4710
- return SyncResult.create(() => {
4711
- let foundArgName = false;
4712
- let result;
4713
- if (isString(nameOrNames)) {
4714
- nameOrNames = [nameOrNames];
4715
- }
4716
- const searchNames = Iterable.create(nameOrNames);
4717
- for (const arg of this.args) {
4718
- if (!foundArgName) {
4719
- const argName = _CommandLineParameters.getArgumentName(arg);
4720
- foundArgName = !!(argName && searchNames.contains(argName));
4721
- } else {
4722
- result = arg;
4723
- break;
4724
- }
4725
- }
4726
- if (result === void 0) {
4727
- const toStringFunctions = ToStringFunctions.create();
4728
- throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
4729
- }
4730
- return result;
4731
- });
4732
- }
4733
- nameOrAliasExists(nameOrAlias) {
4734
- PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
4735
- let result = false;
4736
- for (const parameter of this.parameters) {
4737
- if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
4738
- result = true;
4739
- break;
4740
- }
4741
- }
4742
- return result;
4743
- }
4744
- add(name) {
4745
- const result = CommandLineParameter.create({
4746
- owner: this,
4747
- name
4748
- });
4749
- this.parameters.add(result);
4750
- return result;
4892
+ toArray() {
4893
+ return _HttpHeaders.toArray(this);
4751
4894
  }
4752
- };
4753
-
4754
- // sources/commandLineParameter.ts
4755
- var CommandLineParameter = class _CommandLineParameter {
4756
- owner;
4757
- name;
4758
- aliases;
4759
- description;
4760
- constructor(owner, name) {
4761
- PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
4762
- PreCondition.assertNotEmpty(name, "name");
4763
- PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
4764
- this.owner = owner;
4765
- this.name = name;
4895
+ static toArray(headers) {
4896
+ return Iterable.toArray(headers);
4766
4897
  }
4767
- static create(ownerOrProperties, name) {
4768
- let owner;
4769
- if (ownerOrProperties instanceof CommandLineParameters) {
4770
- owner = ownerOrProperties;
4771
- name = name;
4772
- } else {
4773
- owner = ownerOrProperties.owner;
4774
- name = ownerOrProperties.name;
4775
- }
4776
- return new _CommandLineParameter(owner, name);
4898
+ any() {
4899
+ return _HttpHeaders.any(this);
4777
4900
  }
4778
- /**
4779
- * Get the name of this {@link CommandLineParameter}.
4780
- */
4781
- getName() {
4782
- return this.name;
4901
+ static any(headers) {
4902
+ return Iterable.any(headers);
4783
4903
  }
4784
- getAliases() {
4785
- return this.aliases ?? Iterable.create();
4904
+ getCount() {
4905
+ return _HttpHeaders.getCount(this);
4786
4906
  }
4787
- nameOrAliasExists(nameOrAlias) {
4788
- return this.owner.nameOrAliasExists(nameOrAlias);
4907
+ static getCount(headers) {
4908
+ return Iterable.getCount(headers);
4789
4909
  }
4790
- addAlias(alias) {
4791
- PreCondition.assertNotEmpty(alias, "alias");
4792
- PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
4793
- if (this.aliases === void 0) {
4794
- this.aliases = List.create();
4795
- }
4796
- this.aliases.add(alias);
4797
- return this;
4910
+ equals(right, equalFunctions) {
4911
+ return _HttpHeaders.equals(this, right, equalFunctions);
4798
4912
  }
4799
- addAliases(aliases) {
4800
- for (const alias of aliases) {
4801
- this.addAlias(alias);
4802
- }
4803
- return this;
4913
+ static equals(headers, right, equalFunctions) {
4914
+ return Iterable.equals(headers, right, equalFunctions);
4804
4915
  }
4805
- getNameAndAliases() {
4806
- return List.create().add(this.getName()).addAll(this.getAliases());
4916
+ toString(toStringFunctions) {
4917
+ return _HttpHeaders.toString(this, toStringFunctions);
4807
4918
  }
4808
- getDescription() {
4809
- return this.description ?? "";
4919
+ static toString(headers, toStringFunctions) {
4920
+ return Iterable.toString(headers, toStringFunctions);
4810
4921
  }
4811
- setDescription(description) {
4812
- PreCondition.assertNotUndefinedAndNotNull(description, "description");
4813
- this.description = description;
4814
- return this;
4922
+ concatenate(...toConcatenate) {
4923
+ return _HttpHeaders.concatenate(this, ...toConcatenate);
4815
4924
  }
4816
- };
4817
-
4818
- // sources/nodeJSCharacterWriteStream.ts
4819
- var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
4820
- nodeJSWriteStream;
4821
- constructor(nodeJSWriteStream) {
4822
- PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
4823
- super();
4824
- this.nodeJSWriteStream = nodeJSWriteStream;
4925
+ static concatenate(headers, ...toConcatenate) {
4926
+ return Iterable.concatenate(headers, ...toConcatenate);
4825
4927
  }
4826
- static create(nodeJSWriteStream) {
4827
- return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
4928
+ map(mapping) {
4929
+ return _HttpHeaders.map(this, mapping);
4828
4930
  }
4829
- writeString(text) {
4830
- PreCondition.assertNotUndefinedAndNotNull(text, "text");
4831
- return PromiseAsyncResult.create(new Promise((resolve, reject) => {
4832
- this.nodeJSWriteStream.write(text, (error) => {
4833
- if (error) {
4834
- reject(error);
4835
- } else {
4836
- resolve(text.length);
4837
- }
4838
- });
4839
- }));
4931
+ static map(headers, mapping) {
4932
+ return Iterable.map(headers, mapping);
4840
4933
  }
4841
- };
4842
-
4843
- // sources/property.ts
4844
- var Property = class _Property {
4845
- getter;
4846
- setter;
4847
- constructor(getter, setter) {
4848
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
4849
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
4850
- this.getter = getter;
4851
- this.setter = setter;
4934
+ flatMap(mapping) {
4935
+ return _HttpHeaders.flatMap(this, mapping);
4852
4936
  }
4853
- static create(getterOptionsOrInitialValue, setter) {
4854
- let getter;
4855
- if (isFunction(getterOptionsOrInitialValue)) {
4856
- getter = getterOptionsOrInitialValue;
4857
- } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
4858
- const options = getterOptionsOrInitialValue;
4859
- getter = options.getter;
4860
- setter = options.setter;
4861
- } else {
4862
- let initialValue = getterOptionsOrInitialValue;
4863
- getter = () => {
4864
- return initialValue;
4865
- };
4866
- setter = (value) => {
4867
- initialValue = value;
4868
- };
4869
- }
4870
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
4871
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
4872
- return new _Property(getter, setter);
4937
+ static flatMap(headers, mapping) {
4938
+ return Iterable.flatMap(headers, mapping);
4873
4939
  }
4874
- getValue() {
4875
- return this.getter();
4940
+ where(condition) {
4941
+ return _HttpHeaders.where(this, condition);
4876
4942
  }
4877
- setValue(value) {
4878
- this.setter(value);
4879
- return this;
4943
+ static where(headers, condition) {
4944
+ return Iterable.where(headers, condition);
4880
4945
  }
4881
- toString() {
4882
- return `${this.getValue()}`;
4946
+ instanceOf(typeOrTypeCheck) {
4947
+ return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
4883
4948
  }
4884
- };
4885
-
4886
- // sources/httpHeader.ts
4887
- var HttpHeader = class _HttpHeader {
4888
- name;
4889
- value;
4890
- constructor(name, value) {
4891
- PreCondition.assertNotEmpty(name, "name");
4892
- PreCondition.assertNotUndefinedAndNotNull(value, "value");
4893
- this.name = name;
4894
- this.value = value;
4949
+ static instanceOf(headers, typeOrTypeCheck) {
4950
+ return Iterable.instanceOf(headers, typeOrTypeCheck);
4895
4951
  }
4896
- static create(name, value) {
4897
- return new _HttpHeader(name, value);
4952
+ first(condition) {
4953
+ return _HttpHeaders.first(this, condition);
4898
4954
  }
4899
- getName() {
4900
- return this.name;
4955
+ static first(headers, condition) {
4956
+ return Iterable.first(headers, condition);
4901
4957
  }
4902
- getValue() {
4903
- return this.value;
4958
+ last(condition) {
4959
+ return _HttpHeaders.last(this, condition);
4904
4960
  }
4905
- toString() {
4906
- return `${escapeAndQuote(this.name)}:${escapeAndQuote(this.value)}`;
4961
+ static last(headers, condition) {
4962
+ return Iterable.last(headers, condition);
4907
4963
  }
4908
- };
4909
-
4910
- // sources/mutableHttpHeaders.ts
4911
- var MutableHttpHeaders = class _MutableHttpHeaders {
4912
- headers;
4913
- constructor(headers) {
4914
- this.headers = List.create();
4915
- if (headers) {
4916
- this.setAll(headers);
4917
- }
4964
+ [Symbol.iterator]() {
4965
+ return _HttpHeaders[Symbol.iterator](this);
4918
4966
  }
4919
- static create(headers) {
4920
- return new _MutableHttpHeaders(headers);
4967
+ static [Symbol.iterator](headers) {
4968
+ return Iterable[Symbol.iterator](headers);
4921
4969
  }
4922
- iterate() {
4923
- return this.headers.iterate();
4970
+ contains(value, equalFunctions) {
4971
+ return _HttpHeaders.contains(this, value, equalFunctions);
4924
4972
  }
4925
- get(headerName) {
4926
- PreCondition.assertNotEmpty(headerName, "headerName");
4973
+ static contains(headers, value, equalFunctions) {
4927
4974
  return SyncResult.create(() => {
4928
- let result;
4929
- const lowerHeaderName = headerName.toLowerCase();
4930
- for (const header of this.headers) {
4931
- if (header.getName().toLowerCase() === lowerHeaderName) {
4932
- result = header;
4933
- break;
4934
- }
4935
- }
4936
- if (result === void 0) {
4937
- throw new NotFoundError(`No HttpHeader found with the name ${escapeAndQuote(headerName)}.`);
4938
- }
4939
- return result;
4940
- });
4941
- }
4942
- getValue(headerName) {
4943
- return this.get(headerName).then((header) => header.getValue());
4944
- }
4945
- set(headerOrHeaderName, headerValue) {
4946
- let headerName;
4947
- if (isString(headerOrHeaderName)) {
4948
- headerName = headerOrHeaderName;
4949
- } else {
4950
- headerName = headerOrHeaderName.getName();
4951
- headerValue = headerOrHeaderName.getValue();
4952
- }
4953
- PreCondition.assertNotEmpty(headerName, "headerName");
4954
- PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
4955
- let insertIndex = 0;
4956
- for (let insertIndex2 = 0; insertIndex2 < this.headers.getCount().await(); insertIndex2++) {
4957
- const header = this.headers.get(insertIndex2).await();
4958
- if (header.getName() === headerName) {
4959
- this.headers.removeAt(insertIndex2);
4960
- break;
4975
+ if (!equalFunctions) {
4976
+ equalFunctions = EqualFunctions.create();
4961
4977
  }
4962
- }
4963
- this.headers.insert(insertIndex, HttpHeader.create(headerName, headerValue));
4978
+ return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
4979
+ });
4980
+ }
4981
+ };
4982
+
4983
+ // sources/NodeJSHttpOutgoingResponse.ts
4984
+ var NodeJSHttpOutgoingResponse = class _NodeJSHttpOutgoingResponse {
4985
+ innerResponse;
4986
+ bodyString;
4987
+ constructor(innerResponse) {
4988
+ PreCondition.assertNotUndefinedAndNotNull(innerResponse, "innerResponse");
4989
+ this.innerResponse = innerResponse;
4990
+ }
4991
+ static create(innerResponse) {
4992
+ return new _NodeJSHttpOutgoingResponse(innerResponse);
4993
+ }
4994
+ setStatusCode(statusCode) {
4995
+ this.innerResponse.statusCode = statusCode;
4964
4996
  return this;
4965
4997
  }
4966
- setAll(headers) {
4967
- PreCondition.assertNotUndefinedAndNotNull(headers, "headers");
4968
- for (const header of headers) {
4969
- this.set(header);
4998
+ getStatusCode() {
4999
+ return SyncResult.value(this.innerResponse.statusCode);
5000
+ }
5001
+ static headerValueToString(headerValue) {
5002
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5003
+ return isArray(headerValue) ? join(",", headerValue) : headerValue.toString();
5004
+ }
5005
+ getHeaders() {
5006
+ const result = HttpHeaders.create();
5007
+ for (const rawHeader of Object.entries(this.innerResponse.getHeaders())) {
5008
+ const headerName = rawHeader[0];
5009
+ const headerValue = rawHeader[1];
5010
+ if (headerValue !== void 0) {
5011
+ result.set(headerName, _NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
5012
+ }
4970
5013
  }
4971
- return this;
5014
+ return result;
4972
5015
  }
4973
- setContentType(contentType) {
4974
- return this.set(HttpHeaders.contentTypeHeaderName, contentType);
5016
+ getHeader(headerName) {
5017
+ PreCondition.assertNotEmpty(headerName, "headerName");
5018
+ const headerValue = this.innerResponse.getHeader(headerName);
5019
+ 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)));
4975
5020
  }
4976
- getContentType() {
4977
- return this.get(HttpHeaders.contentTypeHeaderName);
5021
+ getHeaderValue(headerName) {
5022
+ const headerValue = this.innerResponse.getHeader(headerName);
5023
+ return headerValue === void 0 ? SyncResult.error(new NotFoundError(`No HTTP header value exists with the name ${escapeAndQuote(headerName)}.`)) : SyncResult.value(_NodeJSHttpOutgoingResponse.headerValueToString(headerValue));
4978
5024
  }
4979
- getContentTypeValue() {
4980
- return this.getValue(HttpHeaders.contentTypeHeaderName);
5025
+ setHeader(headerName, headerValue) {
5026
+ PreCondition.assertNotEmpty(headerName, "headerName");
5027
+ PreCondition.assertNotUndefinedAndNotNull(headerValue, "headerValue");
5028
+ this.innerResponse.setHeader(headerName, headerValue);
5029
+ return this;
4981
5030
  }
4982
- getCount() {
4983
- return this.headers.getCount();
5031
+ setBodyString(body) {
5032
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5033
+ this.bodyString = body;
5034
+ return this;
4984
5035
  }
4985
- toArray() {
4986
- return HttpHeaders.toArray(this);
5036
+ setBodyJSON(body) {
5037
+ PreCondition.assertNotUndefinedAndNotNull(body, "body");
5038
+ return this.setBodyString(JSON.stringify(body));
4987
5039
  }
4988
- any() {
4989
- return HttpHeaders.any(this);
5040
+ end() {
5041
+ return AsyncResult.create(new Promise((resolve, reject) => {
5042
+ this.innerResponse.end(this.bodyString, () => {
5043
+ resolve();
5044
+ });
5045
+ }));
4990
5046
  }
4991
- equals(right, equalFunctions) {
4992
- return HttpHeaders.equals(this, right, equalFunctions);
5047
+ };
5048
+
5049
+ // sources/TokenType.ts
5050
+ var TokenType = class _TokenType {
5051
+ name;
5052
+ constructor(name) {
5053
+ PreCondition.assertNotEmpty(name, "name");
5054
+ this.name = name;
4993
5055
  }
4994
- toString(toStringFunctions) {
4995
- return HttpHeaders.toString(this, toStringFunctions);
5056
+ static create(name) {
5057
+ return new _TokenType(name);
4996
5058
  }
4997
- concatenate(...toConcatenate) {
4998
- return HttpHeaders.concatenate(this, ...toConcatenate);
5059
+ static Whitespace = _TokenType.create("Whitespace");
5060
+ static NewLine = _TokenType.create("NewLine");
5061
+ static Letters = _TokenType.create("Letters");
5062
+ static Digits = _TokenType.create("Digits");
5063
+ static LeftParenthesis = _TokenType.create("LeftParenthesis");
5064
+ static RightParenthesis = _TokenType.create("RightParenthesis");
5065
+ static Backslash = _TokenType.create("Backslash");
5066
+ static ForwardSlash = _TokenType.create("ForwardSlash");
5067
+ static Unknown = _TokenType.create("Unknown");
5068
+ static Period = _TokenType.create("Period");
5069
+ static Underscore = _TokenType.create("Underscore");
5070
+ static Colon = _TokenType.create("Colon");
5071
+ toString() {
5072
+ return this.name;
4999
5073
  }
5000
- map(mapping) {
5001
- return HttpHeaders.map(this, mapping);
5074
+ };
5075
+
5076
+ // sources/Token.ts
5077
+ var Token = class _Token {
5078
+ static newLineToken = _Token.create("\n", TokenType.NewLine);
5079
+ static carriageReturnNewLineToken = _Token.create("\r\n", TokenType.NewLine);
5080
+ static leftParenthesisToken = _Token.create("(", TokenType.LeftParenthesis);
5081
+ static rightParenthesisToken = _Token.create(")", TokenType.RightParenthesis);
5082
+ static backslashToken = _Token.create("\\", TokenType.Backslash);
5083
+ static forwardSlashToken = _Token.create("/", TokenType.ForwardSlash);
5084
+ static periodToken = _Token.create(".", TokenType.Period);
5085
+ static underscoreToken = _Token.create("_", TokenType.Underscore);
5086
+ static colonToken = _Token.create(":", TokenType.Colon);
5087
+ text;
5088
+ type;
5089
+ constructor(text, type) {
5090
+ PreCondition.assertNotEmpty(text, "text");
5091
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
5092
+ this.text = text;
5093
+ this.type = type;
5002
5094
  }
5003
- flatMap(mapping) {
5004
- return HttpHeaders.flatMap(this, mapping);
5095
+ static create(text, type) {
5096
+ return new _Token(text, type);
5005
5097
  }
5006
- where(condition) {
5007
- return HttpHeaders.where(this, condition);
5098
+ static whitespace(text) {
5099
+ return _Token.create(text, TokenType.Whitespace);
5008
5100
  }
5009
- instanceOf(typeOrTypeCheck) {
5010
- return HttpHeaders.instanceOf(this, typeOrTypeCheck);
5101
+ static newLine(text) {
5102
+ text ??= "\n";
5103
+ let result;
5104
+ switch (text) {
5105
+ case "\n":
5106
+ result = _Token.newLineToken;
5107
+ break;
5108
+ case "\r\n":
5109
+ result = _Token.carriageReturnNewLineToken;
5110
+ break;
5111
+ default:
5112
+ result = _Token.create(text, TokenType.NewLine);
5113
+ break;
5114
+ }
5115
+ return result;
5011
5116
  }
5012
- first(condition) {
5013
- return HttpHeaders.first(this, condition);
5117
+ static leftParenthesis() {
5118
+ return _Token.leftParenthesisToken;
5014
5119
  }
5015
- last(condition) {
5016
- return HttpHeaders.last(this, condition);
5120
+ static rightParenthesis() {
5121
+ return _Token.rightParenthesisToken;
5017
5122
  }
5018
- [Symbol.iterator]() {
5019
- return HttpHeaders[Symbol.iterator](this);
5123
+ static backslash() {
5124
+ return _Token.backslashToken;
5020
5125
  }
5021
- contains(value, equalFunctions) {
5022
- return HttpHeaders.contains(this, value, equalFunctions);
5126
+ static forwardSlash() {
5127
+ return _Token.forwardSlashToken;
5023
5128
  }
5024
- };
5025
-
5026
- // sources/httpHeaders.ts
5027
- var HttpHeaders = class _HttpHeaders {
5028
- static contentTypeHeaderName = "Content-Type";
5029
- static create(headers) {
5030
- return MutableHttpHeaders.create(headers);
5129
+ static period() {
5130
+ return _Token.periodToken;
5031
5131
  }
5032
- getContentType() {
5033
- return _HttpHeaders.getContentType(this);
5132
+ static underscore() {
5133
+ return _Token.underscoreToken;
5034
5134
  }
5035
- static getContentType(headers) {
5036
- return headers.get(_HttpHeaders.contentTypeHeaderName);
5135
+ static colon() {
5136
+ return _Token.colonToken;
5037
5137
  }
5038
- getContentTypeValue() {
5039
- return _HttpHeaders.getContentTypeValue(this);
5138
+ static letters(text) {
5139
+ return _Token.create(text, TokenType.Letters);
5040
5140
  }
5041
- static getContentTypeValue(headers) {
5042
- return headers.getValue(_HttpHeaders.contentTypeHeaderName);
5141
+ static digits(text) {
5142
+ return _Token.create(text, TokenType.Digits);
5043
5143
  }
5044
- /**
5045
- * Get the {@link HttpHeader}s in this {@link HttpHeaders} object as an array.
5046
- */
5047
- toArray() {
5048
- return _HttpHeaders.toArray(this);
5144
+ static unknown(text) {
5145
+ return _Token.create(text, TokenType.Unknown);
5049
5146
  }
5050
- static toArray(headers) {
5051
- return Iterable.toArray(headers);
5147
+ getText() {
5148
+ return this.text;
5052
5149
  }
5053
- any() {
5054
- return _HttpHeaders.any(this);
5150
+ getType() {
5151
+ return this.type;
5055
5152
  }
5056
- static any(headers) {
5057
- return Iterable.any(headers);
5153
+ };
5154
+
5155
+ // sources/english.ts
5156
+ function andList(values) {
5157
+ return list("and", values);
5158
+ }
5159
+ function orList(values) {
5160
+ return list("or", values);
5161
+ }
5162
+ function list(conjunction, values) {
5163
+ PreCondition.assertNotEmpty(conjunction, "conjunction");
5164
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
5165
+ let result = "";
5166
+ let index = 0;
5167
+ const iterator = Iterator.create(values).start().await();
5168
+ while (iterator.hasCurrent()) {
5169
+ const currentValue = iterator.takeCurrent().await();
5170
+ if (index >= 1) {
5171
+ if (iterator.hasCurrent()) {
5172
+ result += `, `;
5173
+ } else {
5174
+ if (index >= 2) {
5175
+ result += `,`;
5176
+ }
5177
+ result += ` ${conjunction} `;
5178
+ }
5179
+ }
5180
+ result += currentValue;
5181
+ index++;
5058
5182
  }
5059
- getCount() {
5060
- return _HttpHeaders.getCount(this);
5183
+ return result;
5184
+ }
5185
+
5186
+ // sources/commandLineParameters.ts
5187
+ var CommandLineParameters = class _CommandLineParameters {
5188
+ args;
5189
+ parameters;
5190
+ constructor(argv) {
5191
+ PreCondition.assertNotUndefinedAndNotNull(argv, "argv");
5192
+ this.args = isIterable(argv) ? argv : Iterable.create(argv);
5193
+ this.parameters = List.create();
5061
5194
  }
5062
- static getCount(headers) {
5063
- return Iterable.getCount(headers);
5195
+ static create(args) {
5196
+ return new _CommandLineParameters(args);
5064
5197
  }
5065
- equals(right, equalFunctions) {
5066
- return _HttpHeaders.equals(this, right, equalFunctions);
5198
+ static getArgumentName(arg) {
5199
+ return arg[0] === "-" ? arg.substring(arg[1] === "-" ? 2 : 1) : void 0;
5067
5200
  }
5068
- static equals(headers, right, equalFunctions) {
5069
- return Iterable.equals(headers, right, equalFunctions);
5201
+ getArguments() {
5202
+ return this.args;
5203
+ }
5204
+ /**
5205
+ * Get the value of the first argument that matches one of the provided names.
5206
+ * @param names The possible names to look for.
5207
+ */
5208
+ getNamedArgumentStringValue(nameOrNames) {
5209
+ PreCondition.assertNotEmpty(nameOrNames, "nameOrNames");
5210
+ return SyncResult.create(() => {
5211
+ let foundArgName = false;
5212
+ let result;
5213
+ if (isString(nameOrNames)) {
5214
+ nameOrNames = [nameOrNames];
5215
+ }
5216
+ const searchNames = Iterable.create(nameOrNames);
5217
+ for (const arg of this.args) {
5218
+ if (!foundArgName) {
5219
+ const argName = _CommandLineParameters.getArgumentName(arg);
5220
+ foundArgName = !!(argName && searchNames.contains(argName));
5221
+ } else {
5222
+ result = arg;
5223
+ break;
5224
+ }
5225
+ }
5226
+ if (result === void 0) {
5227
+ const toStringFunctions = ToStringFunctions.create();
5228
+ throw new NotFoundError(`No argument found that matches ${orList(searchNames.map((n) => toStringFunctions.toString(n)))}.`);
5229
+ }
5230
+ return result;
5231
+ });
5070
5232
  }
5071
- toString(toStringFunctions) {
5072
- return _HttpHeaders.toString(this, toStringFunctions);
5233
+ nameOrAliasExists(nameOrAlias) {
5234
+ PreCondition.assertNotEmpty(nameOrAlias, "nameOrAlias");
5235
+ let result = false;
5236
+ for (const parameter of this.parameters) {
5237
+ if (parameter.getNameAndAliases().contains(nameOrAlias).await()) {
5238
+ result = true;
5239
+ break;
5240
+ }
5241
+ }
5242
+ return result;
5073
5243
  }
5074
- static toString(headers, toStringFunctions) {
5075
- return Iterable.toString(headers, toStringFunctions);
5244
+ add(name) {
5245
+ const result = CommandLineParameter.create({
5246
+ owner: this,
5247
+ name
5248
+ });
5249
+ this.parameters.add(result);
5250
+ return result;
5076
5251
  }
5077
- concatenate(...toConcatenate) {
5078
- return _HttpHeaders.concatenate(this, ...toConcatenate);
5252
+ };
5253
+
5254
+ // sources/commandLineParameter.ts
5255
+ var CommandLineParameter = class _CommandLineParameter {
5256
+ owner;
5257
+ name;
5258
+ aliases;
5259
+ description;
5260
+ constructor(owner, name) {
5261
+ PreCondition.assertNotUndefinedAndNotNull(owner, "owner");
5262
+ PreCondition.assertNotEmpty(name, "name");
5263
+ PreCondition.assertFalse(owner.nameOrAliasExists(name), "owner.nameOrAliasExists(name)");
5264
+ this.owner = owner;
5265
+ this.name = name;
5079
5266
  }
5080
- static concatenate(headers, ...toConcatenate) {
5081
- return Iterable.concatenate(headers, ...toConcatenate);
5267
+ static create(ownerOrProperties, name) {
5268
+ let owner;
5269
+ if (ownerOrProperties instanceof CommandLineParameters) {
5270
+ owner = ownerOrProperties;
5271
+ name = name;
5272
+ } else {
5273
+ owner = ownerOrProperties.owner;
5274
+ name = ownerOrProperties.name;
5275
+ }
5276
+ return new _CommandLineParameter(owner, name);
5082
5277
  }
5083
- map(mapping) {
5084
- return _HttpHeaders.map(this, mapping);
5278
+ /**
5279
+ * Get the name of this {@link CommandLineParameter}.
5280
+ */
5281
+ getName() {
5282
+ return this.name;
5085
5283
  }
5086
- static map(headers, mapping) {
5087
- return Iterable.map(headers, mapping);
5284
+ getAliases() {
5285
+ return this.aliases ?? Iterable.create();
5088
5286
  }
5089
- flatMap(mapping) {
5090
- return _HttpHeaders.flatMap(this, mapping);
5287
+ nameOrAliasExists(nameOrAlias) {
5288
+ return this.owner.nameOrAliasExists(nameOrAlias);
5091
5289
  }
5092
- static flatMap(headers, mapping) {
5093
- return Iterable.flatMap(headers, mapping);
5290
+ addAlias(alias) {
5291
+ PreCondition.assertNotEmpty(alias, "alias");
5292
+ PreCondition.assertFalse(this.nameOrAliasExists(alias), "this.nameOrAliasExists(alias)");
5293
+ if (this.aliases === void 0) {
5294
+ this.aliases = List.create();
5295
+ }
5296
+ this.aliases.add(alias);
5297
+ return this;
5094
5298
  }
5095
- where(condition) {
5096
- return _HttpHeaders.where(this, condition);
5299
+ addAliases(aliases) {
5300
+ for (const alias of aliases) {
5301
+ this.addAlias(alias);
5302
+ }
5303
+ return this;
5097
5304
  }
5098
- static where(headers, condition) {
5099
- return Iterable.where(headers, condition);
5305
+ getNameAndAliases() {
5306
+ return List.create().add(this.getName()).addAll(this.getAliases());
5100
5307
  }
5101
- instanceOf(typeOrTypeCheck) {
5102
- return _HttpHeaders.instanceOf(this, typeOrTypeCheck);
5308
+ getDescription() {
5309
+ return this.description ?? "";
5103
5310
  }
5104
- static instanceOf(headers, typeOrTypeCheck) {
5105
- return Iterable.instanceOf(headers, typeOrTypeCheck);
5311
+ setDescription(description) {
5312
+ PreCondition.assertNotUndefinedAndNotNull(description, "description");
5313
+ this.description = description;
5314
+ return this;
5106
5315
  }
5107
- first(condition) {
5108
- return _HttpHeaders.first(this, condition);
5316
+ };
5317
+
5318
+ // sources/nodeJSCharacterWriteStream.ts
5319
+ var NodeJSCharacterWriteStream = class _NodeJSCharacterWriteStream extends CharacterWriteStream {
5320
+ nodeJSWriteStream;
5321
+ constructor(nodeJSWriteStream) {
5322
+ PreCondition.assertNotUndefinedAndNotNull(nodeJSWriteStream, "nodeJSWriteStream");
5323
+ super();
5324
+ this.nodeJSWriteStream = nodeJSWriteStream;
5109
5325
  }
5110
- static first(headers, condition) {
5111
- return Iterable.first(headers, condition);
5326
+ static create(nodeJSWriteStream) {
5327
+ return new _NodeJSCharacterWriteStream(nodeJSWriteStream);
5112
5328
  }
5113
- last(condition) {
5114
- return _HttpHeaders.last(this, condition);
5329
+ writeString(text) {
5330
+ PreCondition.assertNotUndefinedAndNotNull(text, "text");
5331
+ return PromiseAsyncResult.create(new Promise((resolve, reject) => {
5332
+ this.nodeJSWriteStream.write(text, (error) => {
5333
+ if (error) {
5334
+ reject(error);
5335
+ } else {
5336
+ resolve(text.length);
5337
+ }
5338
+ });
5339
+ }));
5115
5340
  }
5116
- static last(headers, condition) {
5117
- return Iterable.last(headers, condition);
5341
+ };
5342
+
5343
+ // sources/property.ts
5344
+ var Property = class _Property {
5345
+ getter;
5346
+ setter;
5347
+ constructor(getter, setter) {
5348
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
5349
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
5350
+ this.getter = getter;
5351
+ this.setter = setter;
5118
5352
  }
5119
- [Symbol.iterator]() {
5120
- return _HttpHeaders[Symbol.iterator](this);
5353
+ static create(getterOptionsOrInitialValue, setter) {
5354
+ let getter;
5355
+ if (isFunction(getterOptionsOrInitialValue)) {
5356
+ getter = getterOptionsOrInitialValue;
5357
+ } else if (isObject(getterOptionsOrInitialValue) && hasProperty(getterOptionsOrInitialValue, "getter") && hasProperty(getterOptionsOrInitialValue, "setter")) {
5358
+ const options = getterOptionsOrInitialValue;
5359
+ getter = options.getter;
5360
+ setter = options.setter;
5361
+ } else {
5362
+ let initialValue = getterOptionsOrInitialValue;
5363
+ getter = () => {
5364
+ return initialValue;
5365
+ };
5366
+ setter = (value) => {
5367
+ initialValue = value;
5368
+ };
5369
+ }
5370
+ PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
5371
+ PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
5372
+ return new _Property(getter, setter);
5121
5373
  }
5122
- static [Symbol.iterator](headers) {
5123
- return Iterable[Symbol.iterator](headers);
5374
+ getValue() {
5375
+ return this.getter();
5124
5376
  }
5125
- contains(value, equalFunctions) {
5126
- return _HttpHeaders.contains(this, value, equalFunctions);
5377
+ setValue(value) {
5378
+ this.setter(value);
5379
+ return this;
5127
5380
  }
5128
- static contains(headers, value, equalFunctions) {
5129
- return SyncResult.create(() => {
5130
- if (!equalFunctions) {
5131
- equalFunctions = EqualFunctions.create();
5132
- }
5133
- return headers.getValue(value.getName()).then((headerValue) => equalFunctions.areEqual(headerValue, value.getValue()).await()).catch(NotFoundError, () => false).await();
5134
- });
5381
+ toString() {
5382
+ return `${this.getValue()}`;
5135
5383
  }
5136
5384
  };
5137
5385
 
@@ -5289,14 +5537,27 @@ var FetchHttpClient = class _FetchHttpClient {
5289
5537
  }
5290
5538
  sendRequest(request) {
5291
5539
  PreCondition.assertNotUndefinedAndNotNull(request, "request");
5292
- return PromiseAsyncResult.create(async () => {
5540
+ return AsyncResult.create(async () => {
5541
+ const fetchURL = request.getURL();
5542
+ const fetchMethod = _FetchHttpClient.convertMethod(request.getMethod());
5543
+ const fetchHeaders = request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await();
5544
+ const fetchBody = request.getBody() || void 0;
5293
5545
  const requestInit = {
5294
- method: _FetchHttpClient.convertMethod(request.getMethod()),
5295
- headers: request.getHeaders().map((header) => [header.getName(), header.getValue()]).toArray().await(),
5296
- body: request.getBody() || void 0
5546
+ method: fetchMethod,
5547
+ headers: fetchHeaders,
5548
+ body: fetchBody
5297
5549
  };
5298
- const fetchResponse = await fetch(request.getURL(), requestInit);
5299
- return FetchHttpIncomingResponse.create(fetchResponse);
5550
+ let result;
5551
+ try {
5552
+ const fetchResponse = await fetch(fetchURL, requestInit);
5553
+ result = FetchHttpIncomingResponse.create(fetchResponse);
5554
+ } catch (error) {
5555
+ if (error instanceof Error && error.cause instanceof Error) {
5556
+ throw new FetchError(error.cause);
5557
+ }
5558
+ throw error;
5559
+ }
5560
+ return result;
5300
5561
  });
5301
5562
  }
5302
5563
  sendGetRequest(url) {
@@ -5350,83 +5611,6 @@ var http = __toESM(require("http"), 1);
5350
5611
  var HttpServer = class {
5351
5612
  };
5352
5613
 
5353
- // sources/httpOutgoingResponse.ts
5354
- var HttpOutgoingResponse = class _HttpOutgoingResponse {
5355
- statusCode;
5356
- headers;
5357
- body;
5358
- constructor() {
5359
- this.statusCode = 200;
5360
- this.headers = MutableHttpHeaders.create();
5361
- this.body = "";
5362
- }
5363
- static create() {
5364
- return new _HttpOutgoingResponse();
5365
- }
5366
- /**
5367
- * Get the status code of this {@link HttpOutgoingResponse}.
5368
- */
5369
- getStatusCode() {
5370
- return this.statusCode;
5371
- }
5372
- /**
5373
- * Set the status code of this {@link HttpOutgoingResponse}.
5374
- * @param statusCode The status code of this {@link HttpOutgoingResponse}.
5375
- */
5376
- setStatusCode(statusCode) {
5377
- PreCondition.assertBetween(100, statusCode, 599, "statusCode");
5378
- this.statusCode = statusCode;
5379
- return this;
5380
- }
5381
- getHeaders() {
5382
- return this.headers;
5383
- }
5384
- /**
5385
- * Get the HTTP header with the provided name or return a {@link NotFoundError} if the header
5386
- * doesn't exist.
5387
- * @param headerName The name of the header to get.
5388
- */
5389
- getHeader(headerName) {
5390
- return this.headers.get(headerName);
5391
- }
5392
- /**
5393
- * Get the value of the header with the provided name or return a {@link NotFoundError} if the
5394
- * header doesn't exist.
5395
- * @param headerName The name of the header value to get.
5396
- */
5397
- getHeaderValue(headerName) {
5398
- return this.headers.getValue(headerName);
5399
- }
5400
- /**
5401
- * Set the HTTP header in this {@link HttpOutgoingResponse}.
5402
- * @param headerName The name of the HTTP header.
5403
- * @param headerValue The value of the HTTP header.
5404
- */
5405
- setHeader(headerName, headerValue) {
5406
- this.headers.set(headerName, headerValue);
5407
- return this;
5408
- }
5409
- setContentTypeHeader(contentType) {
5410
- this.headers.setContentType(contentType);
5411
- return this;
5412
- }
5413
- /**
5414
- * Get the body of this {@link HttpOutgoingResponse}.
5415
- */
5416
- getBody() {
5417
- return this.body;
5418
- }
5419
- /**
5420
- * Set the body of this {@link HttpOutgoingResponse}.
5421
- * @param body The body for this {@link HttpOutgoingResponse}.
5422
- */
5423
- setBody(body) {
5424
- PreCondition.assertNotUndefinedAndNotNull(body, "body");
5425
- this.body = body;
5426
- return this;
5427
- }
5428
- };
5429
-
5430
5614
  // sources/nodeJSHttpServer.ts
5431
5615
  var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
5432
5616
  httpServer;
@@ -5479,16 +5663,9 @@ var NodeJSHttpServer = class _NodeJSHttpServer extends HttpServer {
5479
5663
  reject(new Error("Can't run a HttpServer multiple times."));
5480
5664
  } else {
5481
5665
  this.httpServer = http.createServer();
5482
- this.httpServer.on("request", (request, response) => {
5483
- const httpResponse = HttpOutgoingResponse.create().setStatusCode(200).setHeader("Content-Type", "text/plain").setBody("Hello world!");
5484
- const statusCode = httpResponse.getStatusCode();
5485
- const headers = httpResponse.getHeaders();
5486
- const responseHeaders = {};
5487
- for (const header of headers) {
5488
- responseHeaders[header.getName()] = header.getValue();
5489
- }
5490
- response.writeHead(statusCode, responseHeaders);
5491
- response.end(httpResponse.getBody());
5666
+ this.httpServer.on("request", async (rawRequest, rawResponse) => {
5667
+ const response = NodeJSHttpOutgoingResponse.create(rawResponse).setStatusCode(200).setHeader("Content-Type", "text/plain").setBodyString("Hello world!");
5668
+ await response.end();
5492
5669
  });
5493
5670
  this.httpServer.on("close", () => {
5494
5671
  resolve();
@@ -5615,9 +5792,6 @@ var CurrentProcess = class _CurrentProcess {
5615
5792
  }
5616
5793
  };
5617
5794
 
5618
- // sources/luxonDateTime.ts
5619
- var luxon = __toESM(require("luxon"), 1);
5620
-
5621
5795
  // sources/listStack.ts
5622
5796
  var ListStack = class _ListStack {
5623
5797
  list;
@@ -6834,12 +7008,37 @@ var ConsoleTestRunner = class _ConsoleTestRunner {
6834
7008
  return this.ui.writeSummary(this.passedTestCount, this.getSkippedTests(), this.getFailedTests());
6835
7009
  }
6836
7010
  };
7011
+
7012
+ // tests/FakeClock.ts
7013
+ var FakeClock = class _FakeClock extends Clock {
7014
+ currentTime;
7015
+ constructor(currentTime) {
7016
+ PreCondition.assertNotUndefinedAndNotNull(currentTime, "currentTime");
7017
+ super();
7018
+ this.currentTime = currentTime;
7019
+ }
7020
+ static create(currentTime) {
7021
+ return new _FakeClock(currentTime ?? DateTime2.now());
7022
+ }
7023
+ /**
7024
+ * Set the {@link DateTime} that this {@link FakeClock} will return.
7025
+ * @param currentTime The {@link DateTime} that this {@link FakeClock} will return.
7026
+ */
7027
+ setCurrentTime(currentTime) {
7028
+ this.currentTime = currentTime;
7029
+ return this;
7030
+ }
7031
+ now() {
7032
+ return this.currentTime;
7033
+ }
7034
+ };
6837
7035
  // Annotate the CommonJS export names for ESM import in node:
6838
7036
  0 && (module.exports = {
6839
7037
  AssertTest,
6840
7038
  BasicTestSkip,
6841
7039
  ConsoleTestRunner,
6842
7040
  FailedTest,
7041
+ FakeClock,
6843
7042
  SkippedTest,
6844
7043
  Test,
6845
7044
  TestAction,