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