@opra/client 0.11.8 → 0.13.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.
Files changed (85) hide show
  1. package/cjs/index.min.mjs +1597 -1049
  2. package/esm/index.min.mjs +1583 -1049
  3. package/package.json +11 -11
  4. package/typings/common/filter/antlr/OpraFilterLexer.d.ts +1 -1
  5. package/typings/common/filter/antlr/OpraFilterListener.d.ts +1 -1
  6. package/typings/common/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
  7. package/typings/common/filter/ast/expressions/comparison-expression.d.ts +1 -1
  8. package/typings/common/filter/ast/expressions/logical-expression.d.ts +1 -1
  9. package/typings/common/filter/build.d.ts +3 -3
  10. package/typings/common/filter/errors.d.ts +2 -0
  11. package/typings/common/filter/filter-tree-visitor.d.ts +2 -1
  12. package/typings/common/helpers/responsive-map.d.ts +19 -5
  13. package/typings/common/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
  14. package/typings/common/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
  15. package/typings/common/http/http-headers.d.ts +70 -0
  16. package/typings/common/http/http-param-codec.d.ts +4 -0
  17. package/typings/common/http/http-params.d.ts +99 -0
  18. package/typings/common/http/http-request-node.d.ts +34 -0
  19. package/typings/common/http/http-request.d.ts +73 -31
  20. package/typings/common/http/http-response.d.ts +41 -0
  21. package/typings/common/http/index.d.ts +13 -2
  22. package/typings/common/http/interfaces/client-http-headers.interface.d.ts +1 -1
  23. package/typings/common/http/interfaces/server-http-headers.interface.d.ts +1 -1
  24. package/typings/common/http/multipart/batch-multipart.d.ts +1 -1
  25. package/typings/common/http/multipart/http-request-content.d.ts +1 -1
  26. package/typings/common/http/multipart/http-response-content.d.ts +1 -1
  27. package/typings/common/http/param-codec/boolean-codec.d.ts +5 -0
  28. package/typings/common/http/param-codec/date-codec.d.ts +16 -0
  29. package/typings/common/http/param-codec/filter-codec.d.ts +6 -0
  30. package/typings/common/http/param-codec/integer-codec.d.ts +9 -0
  31. package/typings/common/http/param-codec/number-codec.d.ts +12 -0
  32. package/typings/common/http/param-codec/string-codec.d.ts +14 -0
  33. package/typings/common/http/utils/encodeURIParam.d.ts +1 -0
  34. package/typings/common/i18n/i18n.d.ts +6 -6
  35. package/typings/common/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
  36. package/typings/common/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
  37. package/typings/common/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
  38. package/typings/common/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
  39. package/typings/common/schema/implementation/data-type/complex-type.d.ts +1 -1
  40. package/typings/common/schema/implementation/data-type/data-type.d.ts +1 -0
  41. package/typings/common/schema/implementation/data-type/union-type.d.ts +1 -1
  42. package/typings/common/schema/implementation/document-builder.d.ts +1 -1
  43. package/typings/common/schema/implementation/opra-document.d.ts +2 -2
  44. package/typings/common/schema/implementation/query/collection-count-query.d.ts +1 -1
  45. package/typings/common/schema/implementation/query/collection-create-query.d.ts +1 -1
  46. package/typings/common/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
  47. package/typings/common/schema/implementation/query/collection-get-query.d.ts +1 -1
  48. package/typings/common/schema/implementation/query/collection-search-query.d.ts +1 -1
  49. package/typings/common/schema/implementation/query/collection-update-many-query.d.ts +1 -1
  50. package/typings/common/schema/implementation/query/collection-update-query.d.ts +1 -1
  51. package/typings/common/schema/implementation/query/field-get-query.d.ts +1 -1
  52. package/typings/common/schema/implementation/query/index.d.ts +4 -4
  53. package/typings/common/schema/implementation/query/singleton-get-query.d.ts +1 -1
  54. package/typings/common/schema/implementation/resource/collection-resource-info.d.ts +3 -0
  55. package/typings/common/schema/implementation/resource/singleton-resource-info.d.ts +1 -0
  56. package/typings/common/schema/interfaces/data-type.metadata.d.ts +4 -4
  57. package/typings/common/schema/interfaces/resource.metadata.d.ts +9 -9
  58. package/typings/common/schema/types.d.ts +8 -8
  59. package/typings/common/url/opra-url-path-component.d.ts +1 -1
  60. package/typings/common/url/opra-url-path.d.ts +24 -18
  61. package/typings/common/url/opra-url-search-params.d.ts +3 -42
  62. package/typings/common/url/opra-url.d.ts +38 -28
  63. package/typings/http/http-client.d.ts +30 -13
  64. package/typings/http/http-collection-service.d.ts +67 -13
  65. package/typings/http/http-request-host.d.ts +18 -0
  66. package/typings/http/http-singleton-service.d.ts +24 -6
  67. package/typings/http/http-types.d.ts +44 -21
  68. package/typings/http/requests/batch-request.d.ts +0 -18
  69. package/typings/http/requests/collection-create-request.d.ts +5 -10
  70. package/typings/http/requests/collection-delete-many-request.d.ts +5 -9
  71. package/typings/http/requests/collection-delete-request.d.ts +5 -10
  72. package/typings/http/requests/collection-get-request.d.ts +5 -10
  73. package/typings/http/requests/collection-search-request.d.ts +5 -9
  74. package/typings/http/requests/collection-update-many-request.d.ts +5 -10
  75. package/typings/http/requests/collection-update-request.d.ts +5 -11
  76. package/typings/http/requests/singleton-create-request.d.ts +7 -0
  77. package/typings/http/requests/singleton-delete-request.d.ts +7 -0
  78. package/typings/http/requests/singleton-get-request.d.ts +7 -0
  79. package/typings/index.d.ts +3 -4
  80. package/typings/interfaces/http-options.interface.d.ts +1 -1
  81. package/typings/interfaces/http-request-config.interface.d.ts +1 -1
  82. package/typings/http/http-request.d.ts +0 -25
  83. package/typings/http/http-response.d.ts +0 -14
  84. package/typings/http/requests/http-singleton-get-request.d.ts +0 -11
  85. package/typings/http/utils/merge-raw-http-requests.util.d.ts +0 -2
package/cjs/index.min.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var buffer = require('buffer');
4
+ var stream = require('@browsery/stream');
5
+ var rxjs = require('rxjs');
6
+ require('tslib');
4
7
  var fastTokenizer = require('fast-tokenizer');
5
8
  var fs = require('@browsery/fs');
6
9
  var i18next = require('@browsery/i18next');
@@ -14,10 +17,15 @@ var omit = require('lodash.omit');
14
17
  var promisify = require('putil-promisify');
15
18
  var isPlainObject = require('putil-isplainobject');
16
19
  var merge = require('putil-merge');
17
- var events = require('events');
18
- require('@browsery/http-parser');
19
- require('@browsery/stream');
20
- var rxjs = require('rxjs');
20
+ var httpParser = require('@browsery/http-parser');
21
+
22
+ function isFunction(value) {
23
+ return typeof value === 'function';
24
+ }
25
+
26
+ function isReadableStreamLike(obj) {
27
+ return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
28
+ }
21
29
 
22
30
  const dotPattern$1 = /^([^.]+)\.(.*)$/;
23
31
  function pathToTree$1(arr, lowerCaseKeys) {
@@ -158,10 +166,8 @@ class I18n extends BaseI18n {
158
166
  async loadResourceDir(dirnames, deep, overwrite) {
159
167
  for (const dirname of Array.isArray(dirnames) ? dirnames : [dirnames]) {
160
168
  /* istanbul ignore next */
161
- if (!(fs.statSync(dirname)).isDirectory()) {
162
- // eslint-disable-next-line no-console
169
+ if (!(fs.existsSync(dirname)))
163
170
  continue;
164
- }
165
171
  const languageDirs = fs.readdirSync(dirname);
166
172
  for (const lang of languageDirs) {
167
173
  const langDir = path.join(dirname, lang);
@@ -1119,10 +1125,6 @@ OpraFilterLexer.DecisionsToDFA = OpraFilterLexer._ATN.decisionToState.map((ds, i
1119
1125
 
1120
1126
  /* eslint-disable */
1121
1127
  class OpraFilterParser extends antlr4.Parser {
1122
- constructor(input) {
1123
- super(input);
1124
- this._interp = new antlr4.ParserATNSimulator(this, OpraFilterParser._ATN, OpraFilterParser.DecisionsToDFA, new antlr4.PredictionContextCache());
1125
- }
1126
1128
  get grammarFileName() {
1127
1129
  return "OpraFilter.g4";
1128
1130
  }
@@ -1141,6 +1143,10 @@ class OpraFilterParser extends antlr4.Parser {
1141
1143
  createFailedPredicateException(predicate, message) {
1142
1144
  return new antlr4.FailedPredicateException(this, predicate, message);
1143
1145
  }
1146
+ constructor(input) {
1147
+ super(input);
1148
+ this._interp = new antlr4.ParserATNSimulator(this, OpraFilterParser._ATN, OpraFilterParser.DecisionsToDFA, new antlr4.PredictionContextCache());
1149
+ }
1144
1150
  // @RuleVersion(0)
1145
1151
  root() {
1146
1152
  let localctx = new RootContext(this, this._ctx, this.state);
@@ -3544,13 +3550,19 @@ class ExternalConstant extends Literal {
3544
3550
  }
3545
3551
  }
3546
3552
 
3547
- // Fix: antlr4 d.ts files is invalid
3553
+ // Fix: antlr4 d.ts files are invalid
3548
3554
  const ParseTreeVisitor = antlr4.tree.ParseTreeVisitor;
3549
3555
  class FilterTreeVisitor extends ParseTreeVisitor {
3550
3556
  constructor(options) {
3551
3557
  super();
3552
3558
  this._timeZone = options?.timeZone;
3553
3559
  }
3560
+ visitChildren(node) {
3561
+ const result = super.visitChildren(node);
3562
+ if (Array.isArray(result) && result.length < 2)
3563
+ return result[0];
3564
+ return result;
3565
+ }
3554
3566
  defaultResult() {
3555
3567
  return undefined;
3556
3568
  }
@@ -3655,7 +3667,7 @@ class OpraErrorListener extends antlr4.ErrorListener {
3655
3667
  this.errors = errors;
3656
3668
  }
3657
3669
  syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
3658
- this.errors.push(new FilterParseError(msg, { recognizer, offendingSymbol, line, e }));
3670
+ this.errors.push(new FilterParseError(msg, { recognizer, offendingSymbol, line, column, e }));
3659
3671
  }
3660
3672
  }
3661
3673
 
@@ -3796,51 +3808,51 @@ const _wrapEntryValue = (v) => {
3796
3808
  /**
3797
3809
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers#controls
3798
3810
  */
3799
- exports.HttpHeaders = void 0;
3800
- (function (HttpHeaders) {
3811
+ exports.HttpHeaderCodes = void 0;
3812
+ (function (HttpHeaderCodes) {
3801
3813
  /* *** Custom Headers *** */
3802
- HttpHeaders["X_Opra_Version"] = "X-Opra-Version";
3803
- HttpHeaders["X_Opra_DataType"] = "X-Opra-DataType";
3804
- HttpHeaders["X_Opra_Count"] = "X-Opra-Count";
3814
+ HttpHeaderCodes["X_Opra_Version"] = "X-Opra-Version";
3815
+ HttpHeaderCodes["X_Opra_DataType"] = "X-Opra-DataType";
3816
+ HttpHeaderCodes["X_Opra_Count"] = "X-Opra-Count";
3805
3817
  /* *** Authentication *** */
3806
3818
  /**
3807
3819
  * Defines the authentication method that should be used to access a resource.
3808
3820
  */
3809
- HttpHeaders["WWW_Authenticate"] = "WWW-Authenticate";
3821
+ HttpHeaderCodes["WWW_Authenticate"] = "WWW-Authenticate";
3810
3822
  /**
3811
3823
  * Contains the credentials to authenticate a user-agent with a server.
3812
3824
  */
3813
- HttpHeaders["Authorization"] = "Authorization";
3825
+ HttpHeaderCodes["Authorization"] = "Authorization";
3814
3826
  /**
3815
3827
  * Defines the authentication method that should be used to access a resource behind a proxy server.
3816
3828
  */
3817
- HttpHeaders["Proxy_Authenticate"] = "Proxy-Authenticate";
3829
+ HttpHeaderCodes["Proxy_Authenticate"] = "Proxy-Authenticate";
3818
3830
  /**
3819
3831
  * Contains the credentials to authenticate a user agent with a proxy server.
3820
3832
  */
3821
- HttpHeaders["Proxy_Authorization"] = "Proxy-Authorization";
3833
+ HttpHeaderCodes["Proxy_Authorization"] = "Proxy-Authorization";
3822
3834
  /* *** Caching *** */
3823
3835
  /**
3824
3836
  * The time, in seconds, that the object has been in a proxy cache.
3825
3837
  */
3826
- HttpHeaders["Age"] = "Age";
3838
+ HttpHeaderCodes["Age"] = "Age";
3827
3839
  /**
3828
3840
  * Directives for caching mechanisms in both requests and responses.
3829
3841
  */
3830
- HttpHeaders["Cache_Control"] = "Cache-Control";
3842
+ HttpHeaderCodes["Cache_Control"] = "Cache-Control";
3831
3843
  /**
3832
3844
  * Clears browsing data (e.g. cookies, storage, cache) associated with the requesting website.
3833
3845
  */
3834
- HttpHeaders["Clear_Site_Data"] = "Clear-Site-Data";
3846
+ HttpHeaderCodes["Clear_Site_Data"] = "Clear-Site-Data";
3835
3847
  /**
3836
3848
  * The date/time after which the response is considered stale.
3837
3849
  */
3838
- HttpHeaders["Expires"] = "Expires";
3850
+ HttpHeaderCodes["Expires"] = "Expires";
3839
3851
  /**
3840
3852
  * Implementation-specific header that may have various effects anywhere along the request-response chain.
3841
3853
  * Used for backwards compatibility with HTTP/1.0 caches where the Cache-Control header is not yet present.
3842
3854
  */
3843
- HttpHeaders["Pragma"] = "Pragma";
3855
+ HttpHeaderCodes["Pragma"] = "Pragma";
3844
3856
  /* *** Conditionals *** */
3845
3857
  /**
3846
3858
  * The last modification date of the resource, used to compare several versions of the same resource.
@@ -3848,294 +3860,294 @@ exports.HttpHeaders = void 0;
3848
3860
  * Conditional requests using If-Modified-Since and If-Unmodified-Since
3849
3861
  * use this value to change the behavior of the request.
3850
3862
  */
3851
- HttpHeaders["Last_Modified"] = "Last-Modified";
3863
+ HttpHeaderCodes["Last_Modified"] = "Last-Modified";
3852
3864
  /**
3853
3865
  * A unique string identifying the version of the resource.
3854
3866
  * Conditional requests using If-Match and If-None-Match use this value to change the behavior of the request.
3855
3867
  */
3856
- HttpHeaders["ETag"] = "ETag";
3868
+ HttpHeaderCodes["ETag"] = "ETag";
3857
3869
  /**
3858
3870
  * Makes the request conditional, and applies the method only if the stored resource matches one of the given ETags.
3859
3871
  */
3860
- HttpHeaders["If_Match"] = "If-Match";
3872
+ HttpHeaderCodes["If_Match"] = "If-Match";
3861
3873
  /**
3862
3874
  * Makes the request conditional, and applies the method only if the stored resource doesn't match
3863
3875
  * any of the given ETags. This is used to update caches (for safe requests), or to prevent uploading
3864
3876
  * a new resource when one already exists.
3865
3877
  */
3866
- HttpHeaders["If_None_Match"] = "If-None-Match";
3878
+ HttpHeaderCodes["If_None_Match"] = "If-None-Match";
3867
3879
  /**
3868
3880
  * Makes the request conditional, and expects the resource to be transmitted only if it has been modified
3869
3881
  * after the given date. This is used to transmit data only when the cache is out of date.
3870
3882
  */
3871
- HttpHeaders["If_Modified_Since"] = "If-Modified-Since";
3883
+ HttpHeaderCodes["If_Modified_Since"] = "If-Modified-Since";
3872
3884
  /**
3873
3885
  * Makes the request conditional, and expects the resource to be transmitted only if
3874
3886
  * it has not been modified after the given date. This ensures the coherence of a new
3875
3887
  * fragment of a specific range with previous ones, or to implement an optimistic
3876
3888
  * concurrency control system when modifying existing documents.
3877
3889
  */
3878
- HttpHeaders["If_Unmodified_Since"] = "If-Unmodified-Since";
3890
+ HttpHeaderCodes["If_Unmodified_Since"] = "If-Unmodified-Since";
3879
3891
  /**
3880
3892
  * Determines how to match request headers to decide whether a cached response can be used
3881
3893
  * rather than requesting a fresh one from the origin server.
3882
3894
  */
3883
- HttpHeaders["Vary"] = "Vary";
3895
+ HttpHeaderCodes["Vary"] = "Vary";
3884
3896
  /* *** Connection management *** */
3885
3897
  /**
3886
3898
  * Controls whether the network connection stays open after the current transaction finishes.
3887
3899
  */
3888
- HttpHeaders["Connection"] = "Connection";
3900
+ HttpHeaderCodes["Connection"] = "Connection";
3889
3901
  /**
3890
3902
  * Controls how long a persistent connection should stay open.
3891
3903
  */
3892
- HttpHeaders["Keep_Alive"] = "Keep-Alive";
3904
+ HttpHeaderCodes["Keep_Alive"] = "Keep-Alive";
3893
3905
  // Content negotiation
3894
3906
  /**
3895
3907
  * Informs the server about the types of data that can be sent back.
3896
3908
  */
3897
- HttpHeaders["Accept"] = "Accept";
3909
+ HttpHeaderCodes["Accept"] = "Accept";
3898
3910
  /**
3899
3911
  * The encoding algorithm, usually a compression algorithm, that can be used on the resource sent back.
3900
3912
  */
3901
- HttpHeaders["Accept_Encoding"] = "Accept-Encoding";
3913
+ HttpHeaderCodes["Accept_Encoding"] = "Accept-Encoding";
3902
3914
  /**
3903
3915
  * Informs the server about the human language the server is expected to send back.
3904
3916
  * This is a hint and is not necessarily under the full control of the user:
3905
3917
  * the server should always pay attention not to override an explicit user choice
3906
3918
  * (like selecting a language from a dropdown).
3907
3919
  */
3908
- HttpHeaders["Accept_Language"] = "Accept-Language";
3920
+ HttpHeaderCodes["Accept_Language"] = "Accept-Language";
3909
3921
  /* *** Controls *** */
3910
3922
  /**
3911
3923
  * Indicates expectations that need to be fulfilled by the server to properly handle the request.
3912
3924
  */
3913
- HttpHeaders["Expect"] = "Expect";
3925
+ HttpHeaderCodes["Expect"] = "Expect";
3914
3926
  /* *** Cookies *** */
3915
3927
  /**
3916
3928
  * Contains stored HTTP cookies previously sent by the server with the Set-Cookie header.
3917
3929
  */
3918
- HttpHeaders["Cookie"] = "Cookie";
3930
+ HttpHeaderCodes["Cookie"] = "Cookie";
3919
3931
  /**
3920
3932
  * Send cookies from the server to the user-agent.
3921
3933
  */
3922
- HttpHeaders["Set_Cookie"] = "Set-Cookie";
3934
+ HttpHeaderCodes["Set_Cookie"] = "Set-Cookie";
3923
3935
  /* *** CORS *** */
3924
3936
  /**
3925
3937
  * Indicates whether the response can be shared.
3926
3938
  */
3927
- HttpHeaders["Access_Control_Allow_Origin"] = "Access-Control-Allow-Origin";
3939
+ HttpHeaderCodes["Access_Control_Allow_Origin"] = "Access-Control-Allow-Origin";
3928
3940
  /**
3929
3941
  * Indicates whether the response to the request can be exposed when the credentials flag is true.
3930
3942
  */
3931
- HttpHeaders["Access_Control_Allow_Credentials"] = "Access-Control-Allow-Credentials";
3943
+ HttpHeaderCodes["Access_Control_Allow_Credentials"] = "Access-Control-Allow-Credentials";
3932
3944
  /**
3933
3945
  * Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request.
3934
3946
  */
3935
- HttpHeaders["Access_Control_Allow_Headers"] = "Access-Control-Allow-Headers";
3947
+ HttpHeaderCodes["Access_Control_Allow_Headers"] = "Access-Control-Allow-Headers";
3936
3948
  /**
3937
3949
  * Specifies the methods allowed when accessing the resource in response to a preflight request.
3938
3950
  */
3939
- HttpHeaders["Access_Control_Allow_Methods"] = "Access-Control-Allow-Methods";
3951
+ HttpHeaderCodes["Access_Control_Allow_Methods"] = "Access-Control-Allow-Methods";
3940
3952
  /**
3941
3953
  * Indicates which headers can be exposed as part of the response by listing their names.
3942
3954
  */
3943
- HttpHeaders["Access_Control_Expose_Headers"] = "Access-Control-Expose-Headers";
3955
+ HttpHeaderCodes["Access_Control_Expose_Headers"] = "Access-Control-Expose-Headers";
3944
3956
  /**
3945
3957
  * Indicates how long the results of a preflight request can be cached.
3946
3958
  */
3947
- HttpHeaders["Access_Control_Max_Age"] = "Access-Control-Max-Age";
3959
+ HttpHeaderCodes["Access_Control_Max_Age"] = "Access-Control-Max-Age";
3948
3960
  /**
3949
3961
  * Used when issuing a preflight request to let the server know which HTTP headers will be
3950
3962
  * used when the actual request is made.
3951
3963
  */
3952
- HttpHeaders["Access_Control_Request_Headers"] = "Access-Control-Request-Headers";
3964
+ HttpHeaderCodes["Access_Control_Request_Headers"] = "Access-Control-Request-Headers";
3953
3965
  /**
3954
3966
  * Used when issuing a preflight request to let the server know which HTTP method
3955
3967
  * will be used when the actual request is made.
3956
3968
  */
3957
- HttpHeaders["Access_Control_Request_Method"] = "Access-Control-Request-Method";
3969
+ HttpHeaderCodes["Access_Control_Request_Method"] = "Access-Control-Request-Method";
3958
3970
  /**
3959
3971
  * Indicates where a fetch originates from.
3960
3972
  */
3961
- HttpHeaders["Origin"] = "Origin";
3973
+ HttpHeaderCodes["Origin"] = "Origin";
3962
3974
  /**
3963
3975
  * Specifies origins that are allowed to see values of attributes retrieved via features of the Resource Timing API,
3964
3976
  * which would otherwise be reported as zero due to cross-origin restrictions.
3965
3977
  */
3966
- HttpHeaders["Timing_Allow_Origin"] = "Timing-Allow-Origin";
3978
+ HttpHeaderCodes["Timing_Allow_Origin"] = "Timing-Allow-Origin";
3967
3979
  /* *** Downloads *** */
3968
3980
  /**
3969
3981
  * Indicates if the resource transmitted should be displayed inline (default behavior without the header),
3970
3982
  * or if it should be handled like a download and the browser should present a "Save As" dialog.
3971
3983
  */
3972
- HttpHeaders["Content_Disposition"] = "Content-Disposition";
3984
+ HttpHeaderCodes["Content_Disposition"] = "Content-Disposition";
3973
3985
  /* *** Message body information *** */
3974
3986
  /**
3975
3987
  * Indicates to uniquely identifies MIME entities in several contexts.
3976
3988
  */
3977
- HttpHeaders["Content_ID"] = "Content-ID";
3989
+ HttpHeaderCodes["Content_ID"] = "Content-ID";
3978
3990
  /**
3979
3991
  * The size of the resource, in decimal number of bytes.
3980
3992
  */
3981
- HttpHeaders["Content_Length"] = "Content-Length";
3993
+ HttpHeaderCodes["Content_Length"] = "Content-Length";
3982
3994
  /**
3983
3995
  * Indicates the media type of the resource.
3984
3996
  */
3985
- HttpHeaders["Content_Type"] = "Content-Type";
3997
+ HttpHeaderCodes["Content_Type"] = "Content-Type";
3986
3998
  /**
3987
3999
  * Indicates to specify how a MIME message or body part has been encoded,
3988
4000
  * so that it can be decoded by its recipient.
3989
4001
  */
3990
- HttpHeaders["Content_Transfer_Encoding"] = "Content-Transfer-Encoding";
4002
+ HttpHeaderCodes["Content_Transfer_Encoding"] = "Content-Transfer-Encoding";
3991
4003
  /**
3992
4004
  * Used to specify the compression algorithm.
3993
4005
  */
3994
- HttpHeaders["Content_Encoding"] = "Content-Encoding";
4006
+ HttpHeaderCodes["Content_Encoding"] = "Content-Encoding";
3995
4007
  /**
3996
4008
  * Describes the human language(s) intended for the audience, so that it allows a user to
3997
4009
  * differentiate according to the users' own preferred language.
3998
4010
  */
3999
- HttpHeaders["Content_Language"] = "Content-Language";
4011
+ HttpHeaderCodes["Content_Language"] = "Content-Language";
4000
4012
  /**
4001
4013
  * Indicates an alternate location for the returned data.
4002
4014
  */
4003
- HttpHeaders["Content_Location"] = "Content-Location";
4015
+ HttpHeaderCodes["Content_Location"] = "Content-Location";
4004
4016
  // Proxies
4005
4017
  /**
4006
4018
  * Contains information from the client-facing side of proxy servers that is altered or
4007
4019
  * lost when a proxy is involved in the path of the request.
4008
4020
  */
4009
- HttpHeaders["Forwarded"] = "Forwarded";
4021
+ HttpHeaderCodes["Forwarded"] = "Forwarded";
4010
4022
  /**
4011
4023
  * Identifies the originating IP addresses of a client connecting to a web server
4012
4024
  * through an HTTP proxy or a load balancer.
4013
4025
  */
4014
- HttpHeaders["X_Forwarded_For"] = "X-Forwarded-For";
4026
+ HttpHeaderCodes["X_Forwarded_For"] = "X-Forwarded-For";
4015
4027
  /**
4016
4028
  * Identifies the original host requested that a client used to connect to your proxy or load balancer.
4017
4029
  */
4018
- HttpHeaders["X_Forwarded_Host"] = "X-Forwarded-Host";
4030
+ HttpHeaderCodes["X_Forwarded_Host"] = "X-Forwarded-Host";
4019
4031
  /**
4020
4032
  * Identifies the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer.
4021
4033
  */
4022
- HttpHeaders["X_Forwarded_Proto"] = "X-Forwarded-Proto";
4034
+ HttpHeaderCodes["X_Forwarded_Proto"] = "X-Forwarded-Proto";
4023
4035
  /**
4024
4036
  * Added by proxies, both forward and reverse proxies, and can appear in the request headers and the response headers.
4025
4037
  */
4026
- HttpHeaders["Via"] = "Via";
4038
+ HttpHeaderCodes["Via"] = "Via";
4027
4039
  /* *** Redirects *** */
4028
4040
  /**
4029
4041
  * Indicates the URL to redirect a page to.
4030
4042
  */
4031
- HttpHeaders["Location"] = "Location";
4043
+ HttpHeaderCodes["Location"] = "Location";
4032
4044
  /* *** Request context *** */
4033
4045
  /**
4034
4046
  * Contains an Internet email address for a human user who controls the requesting user agent.
4035
4047
  */
4036
- HttpHeaders["From"] = "From";
4048
+ HttpHeaderCodes["From"] = "From";
4037
4049
  /**
4038
4050
  * Specifies the domain name of the server (for virtual hosting), and (optionally)
4039
4051
  * the TCP port number on which the server is listening.
4040
4052
  */
4041
- HttpHeaders["Host"] = "Host";
4053
+ HttpHeaderCodes["Host"] = "Host";
4042
4054
  /**
4043
4055
  * The address of the previous web page from which a link to the currently requested page was followed.
4044
4056
  */
4045
- HttpHeaders["Referer"] = "Referer";
4057
+ HttpHeaderCodes["Referer"] = "Referer";
4046
4058
  /**
4047
4059
  * Governs which referrer information sent in the Referer header should be included with requests made.
4048
4060
  */
4049
- HttpHeaders["Referrer_Policy"] = "Referrer-Policy";
4061
+ HttpHeaderCodes["Referrer_Policy"] = "Referrer-Policy";
4050
4062
  /**
4051
4063
  * Contains a characteristic string that allows the network protocol peers to identify the application type,
4052
4064
  * operating system, software vendor or software version of the requesting software user agent.
4053
4065
  */
4054
- HttpHeaders["User_Agent"] = "User-Agent";
4066
+ HttpHeaderCodes["User_Agent"] = "User-Agent";
4055
4067
  /* *** Response context *** */
4056
4068
  /**
4057
4069
  * Lists the set of HTTP request methods supported by a resource.
4058
4070
  */
4059
- HttpHeaders["Allow"] = "Allow";
4071
+ HttpHeaderCodes["Allow"] = "Allow";
4060
4072
  /**
4061
4073
  * Contains information about the software used by the origin server to handle the request.
4062
4074
  */
4063
- HttpHeaders["Server"] = "Server";
4075
+ HttpHeaderCodes["Server"] = "Server";
4064
4076
  /* *** Range requests *** */
4065
4077
  /**
4066
4078
  * Indicates if the server supports range requests, and if so in which unit the range can be expressed.
4067
4079
  */
4068
- HttpHeaders["Accept_Ranges"] = "Accept-Ranges";
4080
+ HttpHeaderCodes["Accept_Ranges"] = "Accept-Ranges";
4069
4081
  /**
4070
4082
  * Indicates the part of a document that the server should return.
4071
4083
  */
4072
- HttpHeaders["Range"] = "Range";
4084
+ HttpHeaderCodes["Range"] = "Range";
4073
4085
  /**
4074
4086
  * Creates a conditional range request that is only fulfilled if the given etag or date matches
4075
4087
  * the remote resource. Used to prevent downloading two ranges from incompatible version of the resource.
4076
4088
  */
4077
- HttpHeaders["If_Range"] = "If-Range";
4089
+ HttpHeaderCodes["If_Range"] = "If-Range";
4078
4090
  /**
4079
4091
  * Indicates where in a full body message a partial message belongs.
4080
4092
  */
4081
- HttpHeaders["Content_Range"] = "Content-Range";
4093
+ HttpHeaderCodes["Content_Range"] = "Content-Range";
4082
4094
  /* *** Security *** */
4083
4095
  /**
4084
4096
  * Allows a server to declare an embedder policy for a given document.
4085
4097
  */
4086
- HttpHeaders["Cross_Origin_Embedder_Policy"] = "Cross-Origin-Embedder-Policy";
4098
+ HttpHeaderCodes["Cross_Origin_Embedder_Policy"] = "Cross-Origin-Embedder-Policy";
4087
4099
  /**
4088
4100
  * Prevents other domains from opening/controlling a window.
4089
4101
  */
4090
- HttpHeaders["Cross_Origin_Opener_Policy"] = "Cross-Origin-Opener-Policy";
4102
+ HttpHeaderCodes["Cross_Origin_Opener_Policy"] = "Cross-Origin-Opener-Policy";
4091
4103
  /**
4092
4104
  * Prevents other domains from reading the response of the resources to which this header is applied.
4093
4105
  */
4094
- HttpHeaders["Cross_Origin_Resource_Policy"] = "Cross-Origin-Resource-Policy";
4106
+ HttpHeaderCodes["Cross_Origin_Resource_Policy"] = "Cross-Origin-Resource-Policy";
4095
4107
  /**
4096
4108
  * Controls resources the user agent is allowed to load for a given page.
4097
4109
  */
4098
- HttpHeaders["Content_Security_Policy"] = "Content-Security-Policy";
4110
+ HttpHeaderCodes["Content_Security_Policy"] = "Content-Security-Policy";
4099
4111
  /**
4100
4112
  * Allows web developers to experiment with policies by monitoring, but not enforcing, their effects.
4101
4113
  * These violation reports consist of JSON documents sent via an HTTP POST request to the specified URI.
4102
4114
  */
4103
- HttpHeaders["Content_Security_Policy_Report_Only"] = "Content-Security-Policy-Report-Only";
4115
+ HttpHeaderCodes["Content_Security_Policy_Report_Only"] = "Content-Security-Policy-Report-Only";
4104
4116
  /**
4105
4117
  * Allows sites to opt in to reporting and/or enforcement of Certificate Transparency requirements,
4106
4118
  * which prevents the use of misissued certificates for that site from going unnoticed.
4107
4119
  * When a site enables the Expect-CT header, they are requesting that Chrome check that
4108
4120
  * any certificate for that site appears in public CT logs.
4109
4121
  */
4110
- HttpHeaders["Expect_CT"] = "Expect-CT";
4122
+ HttpHeaderCodes["Expect_CT"] = "Expect-CT";
4111
4123
  /**
4112
4124
  * Provides a mechanism to allow and deny the use of browser features in its own frame,
4113
4125
  * and in iframes that it embeds.
4114
4126
  */
4115
- HttpHeaders["Feature_Policy"] = "Feature-Policy";
4127
+ HttpHeaderCodes["Feature_Policy"] = "Feature-Policy";
4116
4128
  /**
4117
4129
  * Force communication using HTTPS instead of HTTP.
4118
4130
  */
4119
- HttpHeaders["Strict_Transport_Security"] = "Strict-Transport-Security";
4131
+ HttpHeaderCodes["Strict_Transport_Security"] = "Strict-Transport-Security";
4120
4132
  /**
4121
4133
  * Sends a signal to the server expressing the client's preference for an encrypted and authenticated response,
4122
4134
  * and that it can successfully handle the upgrade-insecure-requests directive.
4123
4135
  */
4124
- HttpHeaders["Upgrade_Insecure_Requests"] = "Upgrade-Insecure-Requests";
4136
+ HttpHeaderCodes["Upgrade_Insecure_Requests"] = "Upgrade-Insecure-Requests";
4125
4137
  /**
4126
4138
  * Disables MIME sniffing and forces browser to use the type given in Content-Type.
4127
4139
  */
4128
- HttpHeaders["X_Content_Type_Options"] = "X-Content-Type-Options";
4140
+ HttpHeaderCodes["X_Content_Type_Options"] = "X-Content-Type-Options";
4129
4141
  /**
4130
4142
  * The X-Download-Options HTTP header indicates that the browser (Internet Explorer)
4131
4143
  * should not display the option to "Open" a file that has been downloaded from an application,
4132
4144
  * to prevent phishing attacks as the file otherwise would gain access to execute in the context of the application.
4133
4145
  */
4134
- HttpHeaders["X_Download_Options"] = "X-Download-Options";
4146
+ HttpHeaderCodes["X_Download_Options"] = "X-Download-Options";
4135
4147
  /**
4136
4148
  * Indicates whether a browser should be allowed to render a page in a <frame>, <iframe>, <embed> or <object>.
4137
4149
  */
4138
- HttpHeaders["X_Frame_Options"] = "X-Frame-Options";
4150
+ HttpHeaderCodes["X_Frame_Options"] = "X-Frame-Options";
4139
4151
  /**
4140
4152
  * Specifies if a cross-domain policy file (crossdomain.xml) is allowed.
4141
4153
  * The file may define a policy to grant clients, such as Adobe's Flash Player (now obsolete),
@@ -4143,182 +4155,182 @@ exports.HttpHeaders = void 0;
4143
4155
  * permission to handle data across domains that would otherwise be restricted
4144
4156
  * due to the Same-Origin Policy. See the Cross-domain Policy File Specification for more information.
4145
4157
  */
4146
- HttpHeaders["X_Permitted_Cross_Domain_Policies"] = "X-Permitted-Cross-Domain-Policies";
4158
+ HttpHeaderCodes["X_Permitted_Cross_Domain_Policies"] = "X-Permitted-Cross-Domain-Policies";
4147
4159
  /**
4148
4160
  * May be set by hosting environments or other frameworks and contains information about
4149
4161
  * them while not providing any usefulness to the application or its visitors.
4150
4162
  * Unset this header to avoid exposing potential vulnerabilities.
4151
4163
  */
4152
- HttpHeaders["X_Powered_By"] = "X-Powered-By";
4164
+ HttpHeaderCodes["X_Powered_By"] = "X-Powered-By";
4153
4165
  /**
4154
4166
  * Enables cross-site scripting filtering.
4155
4167
  */
4156
- HttpHeaders["X_XSS_Protection"] = "X-XSS-Protection";
4168
+ HttpHeaderCodes["X_XSS_Protection"] = "X-XSS-Protection";
4157
4169
  /* *** Transfer coding *** */
4158
4170
  /**
4159
4171
  * Specifies the form of encoding used to safely transfer the resource to the user.
4160
4172
  */
4161
- HttpHeaders["Transfer_Encoding"] = "Transfer-Encoding";
4173
+ HttpHeaderCodes["Transfer_Encoding"] = "Transfer-Encoding";
4162
4174
  /**
4163
4175
  * Specifies the transfer encodings the user agent is willing to accept.
4164
4176
  */
4165
- HttpHeaders["TE"] = "TE";
4177
+ HttpHeaderCodes["TE"] = "TE";
4166
4178
  /**
4167
4179
  * Allows the sender to include additional fields at the end of chunked message.
4168
4180
  */
4169
- HttpHeaders["Trailer"] = "Trailer";
4181
+ HttpHeaderCodes["Trailer"] = "Trailer";
4170
4182
  /* *** WebSockets *** */
4171
- HttpHeaders["Sec_WebSocket_Key"] = "Sec-WebSocket-Key";
4172
- HttpHeaders["Sec_WebSocket_Extensions"] = "Sec-WebSocket-Extensions";
4173
- HttpHeaders["Sec_WebSocket_Accept"] = "Sec-WebSocket-Accept";
4174
- HttpHeaders["Sec_WebSocket_Protocol"] = "Sec-WebSocket-Protocol";
4175
- HttpHeaders["Sec_WebSocket_Version"] = "Sec-WebSocket-Version";
4183
+ HttpHeaderCodes["Sec_WebSocket_Key"] = "Sec-WebSocket-Key";
4184
+ HttpHeaderCodes["Sec_WebSocket_Extensions"] = "Sec-WebSocket-Extensions";
4185
+ HttpHeaderCodes["Sec_WebSocket_Accept"] = "Sec-WebSocket-Accept";
4186
+ HttpHeaderCodes["Sec_WebSocket_Protocol"] = "Sec-WebSocket-Protocol";
4187
+ HttpHeaderCodes["Sec_WebSocket_Version"] = "Sec-WebSocket-Version";
4176
4188
  /* *** Other *** */
4177
4189
  /**
4178
4190
  * Contains the date and time at which the message was originated.
4179
4191
  */
4180
- HttpHeaders["Date"] = "Date";
4192
+ HttpHeaderCodes["Date"] = "Date";
4181
4193
  /**
4182
4194
  * Indicates how long the user agent should wait before making a follow-up request.
4183
4195
  */
4184
- HttpHeaders["Retry_After"] = "Retry-After";
4196
+ HttpHeaderCodes["Retry_After"] = "Retry-After";
4185
4197
  /**
4186
4198
  * Communicates one or more metrics and descriptions for the given request-response cycle.
4187
4199
  */
4188
- HttpHeaders["Server_Timing"] = "Server-Timing";
4200
+ HttpHeaderCodes["Server_Timing"] = "Server-Timing";
4189
4201
  /**
4190
4202
  * Controls DNS prefetching, a feature by which browsers proactively perform domain name
4191
4203
  * resolution on both links that the user may choose to follow as well as URLs for items
4192
4204
  * referenced by the document, including images, CSS, JavaScript, and so forth.
4193
4205
  */
4194
- HttpHeaders["X_DNS_Prefetch_Control"] = "X-DNS-Prefetch-Control";
4195
- })(exports.HttpHeaders || (exports.HttpHeaders = {}));
4206
+ HttpHeaderCodes["X_DNS_Prefetch_Control"] = "X-DNS-Prefetch-Control";
4207
+ })(exports.HttpHeaderCodes || (exports.HttpHeaderCodes = {}));
4196
4208
 
4197
4209
  // noinspection JSUnusedGlobalSymbols
4198
4210
  /**
4199
4211
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses
4200
4212
  */
4201
- exports.HttpStatus = void 0;
4202
- (function (HttpStatus) {
4213
+ exports.HttpStatusCodes = void 0;
4214
+ (function (HttpStatusCodes) {
4203
4215
  /* *** Information responses *** */
4204
4216
  /**
4205
4217
  * This interim response indicates that the client should continue the request or
4206
4218
  * ignore the response if the request is already finished.
4207
4219
  */
4208
- HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
4220
+ HttpStatusCodes[HttpStatusCodes["CONTINUE"] = 100] = "CONTINUE";
4209
4221
  /**
4210
4222
  * This code is sent in response to an Upgrade request header from the client and
4211
4223
  * indicates the protocol the server is switching to.
4212
4224
  */
4213
- HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
4225
+ HttpStatusCodes[HttpStatusCodes["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
4214
4226
  /**
4215
4227
  * This code indicates that the server has received and is processing the request, but no response is available yet.
4216
4228
  */
4217
- HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
4229
+ HttpStatusCodes[HttpStatusCodes["PROCESSING"] = 102] = "PROCESSING";
4218
4230
  /**
4219
4231
  * This status code is primarily intended to be used with the Link header, letting the user agent
4220
4232
  * start preloading resources while the server prepares a response.
4221
4233
  */
4222
- HttpStatus[HttpStatus["EARLYHINTS"] = 103] = "EARLYHINTS";
4234
+ HttpStatusCodes[HttpStatusCodes["EARLYHINTS"] = 103] = "EARLYHINTS";
4223
4235
  /* *** Successful responses *** */
4224
4236
  /**
4225
4237
  * The request succeeded.
4226
4238
  */
4227
- HttpStatus[HttpStatus["OK"] = 200] = "OK";
4239
+ HttpStatusCodes[HttpStatusCodes["OK"] = 200] = "OK";
4228
4240
  /**
4229
4241
  * The request succeeded, and a new resource was created as a result.
4230
4242
  * This is typically the response sent after POST requests, or some PUT requests.
4231
4243
  */
4232
- HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
4244
+ HttpStatusCodes[HttpStatusCodes["CREATED"] = 201] = "CREATED";
4233
4245
  /**
4234
4246
  * The request has been received but not yet acted upon. It is noncommittal,
4235
4247
  * since there is no way in HTTP to later send an asynchronous response indicating
4236
4248
  * the outcome of the request. It is intended for cases where another process or
4237
4249
  * server handles the request, or for batch processing.
4238
4250
  */
4239
- HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
4251
+ HttpStatusCodes[HttpStatusCodes["ACCEPTED"] = 202] = "ACCEPTED";
4240
4252
  /**
4241
4253
  * This response code means the returned metadata is not exactly the same as is available from
4242
4254
  * the origin server, but is collected from a local or a third-party copy. This is mostly used
4243
4255
  * for mirrors or backups of another resource. Except for that specific case, the 200 OK
4244
4256
  * response is preferred to this status.
4245
4257
  */
4246
- HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
4258
+ HttpStatusCodes[HttpStatusCodes["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
4247
4259
  /**
4248
4260
  * There is no content to send for this request, but the headers may be useful.
4249
4261
  * The user agent may update its cached headers for this resource with the new ones.
4250
4262
  */
4251
- HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
4263
+ HttpStatusCodes[HttpStatusCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
4252
4264
  /**
4253
4265
  * Tells the user agent to reset the document which sent this request.
4254
4266
  */
4255
- HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
4267
+ HttpStatusCodes[HttpStatusCodes["RESET_CONTENT"] = 205] = "RESET_CONTENT";
4256
4268
  /**
4257
4269
  * This response code is used when the Range header is sent from the client to request only part of a resource.
4258
4270
  */
4259
- HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
4271
+ HttpStatusCodes[HttpStatusCodes["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
4260
4272
  /* *** Redirection messages *** */
4261
4273
  /**
4262
4274
  * The request has more than one possible response. The user agent or user should choose one of them.
4263
4275
  * (There is no standardized way of choosing one of the responses, but HTML links to the possibilities
4264
4276
  * are recommended so the user can pick.)
4265
4277
  */
4266
- HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
4278
+ HttpStatusCodes[HttpStatusCodes["AMBIGUOUS"] = 300] = "AMBIGUOUS";
4267
4279
  /**
4268
4280
  * The URL of the requested resource has been changed permanently. The new URL is given in the response.
4269
4281
  */
4270
- HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
4282
+ HttpStatusCodes[HttpStatusCodes["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
4271
4283
  /**
4272
4284
  * This response code means that the URI of requested resource has been changed temporarily.
4273
4285
  * Further changes in the URI might be made in the future. Therefore, this same URI should
4274
4286
  * be used by the client in future requests.
4275
4287
  */
4276
- HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
4288
+ HttpStatusCodes[HttpStatusCodes["FOUND"] = 302] = "FOUND";
4277
4289
  /**
4278
4290
  * This is used for caching purposes. It tells the client that the response has not been modified,
4279
4291
  * so the client can continue to use the same cached version of the response.
4280
4292
  */
4281
- HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
4293
+ HttpStatusCodes[HttpStatusCodes["SEE_OTHER"] = 303] = "SEE_OTHER";
4282
4294
  /**
4283
4295
  *
4284
4296
  */
4285
- HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
4297
+ HttpStatusCodes[HttpStatusCodes["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
4286
4298
  /**
4287
4299
  * The server sends this response to direct the client to get the requested resource at another
4288
4300
  * URI with same method that was used in the prior request. This has the same semantics as
4289
4301
  * the 302 Found HTTP response code, with the exception that the user agent must not change
4290
4302
  * the HTTP method used: if a POST was used in the first request, a POST must be used in the second request.
4291
4303
  */
4292
- HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
4304
+ HttpStatusCodes[HttpStatusCodes["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
4293
4305
  /**
4294
4306
  * This means that the resource is now permanently located at another URI, specified by the Location:
4295
4307
  * HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code,
4296
4308
  * with the exception that the user agent must not change the HTTP method used: if a POST was used
4297
4309
  * in the first request, a POST must be used in the second request.
4298
4310
  */
4299
- HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
4311
+ HttpStatusCodes[HttpStatusCodes["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
4300
4312
  /* *** Client error responses *** */
4301
4313
  /**
4302
4314
  * The server cannot or will not process the request due to something that is perceived to be a client error
4303
4315
  * (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
4304
4316
  */
4305
- HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
4317
+ HttpStatusCodes[HttpStatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
4306
4318
  /**
4307
4319
  * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated".
4308
4320
  * That is, the client must authenticate itself to get the requested response.
4309
4321
  */
4310
- HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
4322
+ HttpStatusCodes[HttpStatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
4311
4323
  /**
4312
4324
  * This response code is reserved for future use. The initial aim for creating this code was using
4313
4325
  * it for digital payment systems, however this status code is used very rarely and no standard convention exists.
4314
4326
  */
4315
- HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
4327
+ HttpStatusCodes[HttpStatusCodes["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
4316
4328
  /**
4317
4329
  * The client does not have access rights to the content; that is, it is unauthorized,
4318
4330
  * so the server is refusing to give the requested resource. Unlike 401 Unauthorized,
4319
4331
  * the client's identity is known to the server.
4320
4332
  */
4321
- HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
4333
+ HttpStatusCodes[HttpStatusCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
4322
4334
  /**
4323
4335
  * The server can not find the requested resource. In the browser, this means the URL is not recognized.
4324
4336
  * In an API, this can also mean that the endpoint is valid but the resource itself does not exist.
@@ -4326,21 +4338,21 @@ exports.HttpStatus = void 0;
4326
4338
  * from an unauthorized client. This response code is probably the most well known due to its
4327
4339
  * frequent occurrence on the web.
4328
4340
  */
4329
- HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
4341
+ HttpStatusCodes[HttpStatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
4330
4342
  /**
4331
4343
  * The request method is known by the server but is not supported by the target resource.
4332
4344
  * For example, an API may not allow calling DELETE to remove a resource.
4333
4345
  */
4334
- HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
4346
+ HttpStatusCodes[HttpStatusCodes["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
4335
4347
  /**
4336
4348
  * This response is sent when the web server, after performing server-driven content negotiation,
4337
4349
  * doesn't find any content that conforms to the criteria given by the user agent.
4338
4350
  */
4339
- HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
4351
+ HttpStatusCodes[HttpStatusCodes["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
4340
4352
  /**
4341
4353
  * This is similar to 401 Unauthorized but authentication is needed to be done by a proxy.
4342
4354
  */
4343
- HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
4355
+ HttpStatusCodes[HttpStatusCodes["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
4344
4356
  /**
4345
4357
  * This response is sent on an idle connection by some servers, even without any previous request by the client.
4346
4358
  * It means that the server would like to shut down this unused connection.
@@ -4348,107 +4360,107 @@ exports.HttpStatus = void 0;
4348
4360
  * like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing.
4349
4361
  * Also note that some servers merely shut down the connection without sending this message.
4350
4362
  */
4351
- HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
4363
+ HttpStatusCodes[HttpStatusCodes["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
4352
4364
  /**
4353
4365
  * This response is sent when a request conflicts with the current state of the server.
4354
4366
  */
4355
- HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
4367
+ HttpStatusCodes[HttpStatusCodes["CONFLICT"] = 409] = "CONFLICT";
4356
4368
  /**
4357
4369
  * This response is sent when the requested content has been permanently deleted from server,
4358
4370
  * with no forwarding address. Clients are expected to remove their caches and links to the resource.
4359
4371
  * The HTTP specification intends this status code to be used for "limited-time, promotional services".
4360
4372
  * APIs should not feel compelled to indicate resources that have been deleted with this status code.
4361
4373
  */
4362
- HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
4374
+ HttpStatusCodes[HttpStatusCodes["GONE"] = 410] = "GONE";
4363
4375
  /**
4364
4376
  * Server rejected the request because the Content-Length header field is not defined and the server requires it.
4365
4377
  */
4366
- HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
4378
+ HttpStatusCodes[HttpStatusCodes["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
4367
4379
  /**
4368
4380
  * The client has indicated preconditions in its headers which the server does not meet.
4369
4381
  */
4370
- HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
4382
+ HttpStatusCodes[HttpStatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
4371
4383
  /**
4372
4384
  * Request entity is larger than limits defined by server. The server might close the connection or
4373
4385
  * return an Retry-After header field.
4374
4386
  */
4375
- HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
4387
+ HttpStatusCodes[HttpStatusCodes["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
4376
4388
  /**
4377
4389
  * The URI requested by the client is longer than the server is willing to interpret.
4378
4390
  */
4379
- HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
4391
+ HttpStatusCodes[HttpStatusCodes["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
4380
4392
  /**
4381
4393
  * The media format of the requested data is not supported by the server, so the server is rejecting the request.
4382
4394
  */
4383
- HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
4395
+ HttpStatusCodes[HttpStatusCodes["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
4384
4396
  /**
4385
4397
  * The range specified by the Range header field in the request cannot be fulfilled.
4386
4398
  * It's possible that the range is outside the size of the target URI's data.
4387
4399
  */
4388
- HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
4400
+ HttpStatusCodes[HttpStatusCodes["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
4389
4401
  /**
4390
4402
  * This response code means the expectation indicated by the Expect request header field cannot be met by the server.
4391
4403
  */
4392
- HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
4404
+ HttpStatusCodes[HttpStatusCodes["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
4393
4405
  /**
4394
4406
  * The server refuses the attempt to brew coffee with a teapot.
4395
4407
  */
4396
- HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
4408
+ HttpStatusCodes[HttpStatusCodes["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
4397
4409
  /**
4398
4410
  * The request was directed at a server that is not able to produce a response.
4399
4411
  * This can be sent by a server that is not configured to produce responses for
4400
4412
  * the combination of scheme and authority that are included in the request URI.
4401
4413
  */
4402
- HttpStatus[HttpStatus["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
4414
+ HttpStatusCodes[HttpStatusCodes["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
4403
4415
  /**
4404
4416
  * The request was well-formed but was unable to be followed due to semantic errors.
4405
4417
  */
4406
- HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
4418
+ HttpStatusCodes[HttpStatusCodes["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
4407
4419
  /**
4408
4420
  * The resource that is being accessed is locked.
4409
4421
  */
4410
- HttpStatus[HttpStatus["LOCKED"] = 423] = "LOCKED";
4422
+ HttpStatusCodes[HttpStatusCodes["LOCKED"] = 423] = "LOCKED";
4411
4423
  /**
4412
4424
  * The request failed due to failure of a previous request.
4413
4425
  */
4414
- HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
4426
+ HttpStatusCodes[HttpStatusCodes["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
4415
4427
  /**
4416
4428
  * Indicates that the server is unwilling to risk processing a request that might be replayed.
4417
4429
  */
4418
- HttpStatus[HttpStatus["TOO_EARLY"] = 425] = "TOO_EARLY";
4430
+ HttpStatusCodes[HttpStatusCodes["TOO_EARLY"] = 425] = "TOO_EARLY";
4419
4431
  /**
4420
4432
  * The server refuses to perform the request using the current protocol but might be willing
4421
4433
  * to do so after the client upgrades to a different protocol. The server sends an Upgrade
4422
4434
  * header in a 426 response to indicate the required protocol(s).
4423
4435
  */
4424
- HttpStatus[HttpStatus["UPGRADE_REQUIRED"] = 428] = "UPGRADE_REQUIRED";
4436
+ HttpStatusCodes[HttpStatusCodes["UPGRADE_REQUIRED"] = 428] = "UPGRADE_REQUIRED";
4425
4437
  /**
4426
4438
  * The origin server requires the request to be conditional. This response is intended to prevent
4427
4439
  * the 'lost update' problem, where a client GETs a resource's state, modifies it and PUTs
4428
4440
  * it back to the server, when meanwhile a third party has modified the state on the server,
4429
4441
  * leading to a conflict.
4430
4442
  */
4431
- HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
4443
+ HttpStatusCodes[HttpStatusCodes["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
4432
4444
  /**
4433
4445
  * The user has sent too many requests in a given amount of time ("rate limiting").
4434
4446
  */
4435
- HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
4447
+ HttpStatusCodes[HttpStatusCodes["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
4436
4448
  /* *** Server error responses *** */
4437
4449
  /**
4438
4450
  * The server has encountered a situation it does not know how to handle.
4439
4451
  */
4440
- HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
4452
+ HttpStatusCodes[HttpStatusCodes["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
4441
4453
  /**
4442
4454
  * The request method is not supported by the server and cannot be handled.
4443
4455
  * The only methods that servers are required to support (and therefore that must not return this code)
4444
4456
  * are GET and HEAD.
4445
4457
  */
4446
- HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
4458
+ HttpStatusCodes[HttpStatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
4447
4459
  /**
4448
4460
  * This error response means that the server, while working as a gateway to get
4449
4461
  * a response needed to handle the request, got an invalid response.
4450
4462
  */
4451
- HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
4463
+ HttpStatusCodes[HttpStatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
4452
4464
  /**
4453
4465
  * The server is not ready to handle the request. Common causes are a server that is down for maintenance
4454
4466
  * or that is overloaded. Note that together with this response, a user-friendly page explaining
@@ -4458,49 +4470,49 @@ exports.HttpStatus = void 0;
4458
4470
  * headers that are sent along with this response, as these temporary condition responses
4459
4471
  * should usually not be cached.
4460
4472
  */
4461
- HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
4473
+ HttpStatusCodes[HttpStatusCodes["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
4462
4474
  /**
4463
4475
  * This error response is given when the server is acting as a gateway and cannot get a response in time.
4464
4476
  */
4465
- HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
4477
+ HttpStatusCodes[HttpStatusCodes["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
4466
4478
  /**
4467
4479
  * The HTTP version used in the request is not supported by the server.
4468
4480
  */
4469
- HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
4481
+ HttpStatusCodes[HttpStatusCodes["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
4470
4482
  /**
4471
4483
  * The server has an internal configuration error: the chosen variant resource is configured
4472
4484
  * to engage in transparent content negotiation itself, and is therefore not a proper end
4473
4485
  * point in the negotiation process.
4474
4486
  */
4475
- HttpStatus[HttpStatus["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
4487
+ HttpStatusCodes[HttpStatusCodes["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
4476
4488
  /**
4477
4489
  * The method could not be performed on the resource because the server is unable to store
4478
4490
  * the representation needed to successfully complete the request.
4479
4491
  */
4480
- HttpStatus[HttpStatus["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
4492
+ HttpStatusCodes[HttpStatusCodes["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
4481
4493
  /**
4482
4494
  * The server detected an infinite loop while processing the request.
4483
4495
  */
4484
- HttpStatus[HttpStatus["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
4496
+ HttpStatusCodes[HttpStatusCodes["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
4485
4497
  /**
4486
4498
  * Further extensions to the request are required for the server to fulfill it.
4487
4499
  */
4488
- HttpStatus[HttpStatus["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
4500
+ HttpStatusCodes[HttpStatusCodes["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
4489
4501
  /**
4490
4502
  * Indicates that the client needs to authenticate to gain network access.
4491
4503
  */
4492
- HttpStatus[HttpStatus["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
4493
- })(exports.HttpStatus || (exports.HttpStatus = {}));
4504
+ HttpStatusCodes[HttpStatusCodes["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
4505
+ })(exports.HttpStatusCodes || (exports.HttpStatusCodes = {}));
4494
4506
 
4495
- const knownKeys = Object.keys(exports.HttpHeaders);
4496
- const knownKeysLower = knownKeys.map(x => x.toLowerCase());
4507
+ const knownKeys$1 = Object.keys(exports.HttpHeaderCodes);
4508
+ const knownKeysLower$1 = knownKeys$1.map(x => x.toLowerCase());
4497
4509
  function normalizeHeaders(headers, normalCase) {
4498
4510
  if (!headers)
4499
4511
  return {};
4500
4512
  return Object.keys(headers).reduce((o, k) => {
4501
4513
  const v = headers[k];
4502
4514
  const key = normalCase
4503
- ? knownKeys[knownKeysLower.indexOf(k.toLowerCase())] || camelize(k) :
4515
+ ? knownKeys$1[knownKeysLower$1.indexOf(k.toLowerCase())] || camelize(k) :
4504
4516
  k.toLowerCase();
4505
4517
  if (k.toLowerCase() === 'set-cookie')
4506
4518
  o[key] = Array.isArray(v) ? v : [v];
@@ -4543,11 +4555,11 @@ class BatchMultipart {
4543
4555
  addRequestPart(content, part) {
4544
4556
  const headers = {
4545
4557
  ...normalizeHeaders(part?.headers || {}, true),
4546
- [exports.HttpHeaders.Content_Type]: 'application/http',
4547
- [exports.HttpHeaders.Content_Transfer_Encoding]: 'binary'
4558
+ [exports.HttpHeaderCodes.Content_Type]: 'application/http',
4559
+ [exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
4548
4560
  };
4549
4561
  if (part?.contentId)
4550
- headers[exports.HttpHeaders.Content_ID] = part.contentId;
4562
+ headers[exports.HttpHeaderCodes.Content_ID] = part.contentId;
4551
4563
  this._parts.push({
4552
4564
  headers,
4553
4565
  contentId: part?.contentId,
@@ -4558,11 +4570,11 @@ class BatchMultipart {
4558
4570
  addHttpResponse(content, part) {
4559
4571
  const headers = {
4560
4572
  ...normalizeHeaders(part?.headers || {}, true),
4561
- [exports.HttpHeaders.Content_Type]: 'application/http',
4562
- [exports.HttpHeaders.Content_Transfer_Encoding]: 'binary'
4573
+ [exports.HttpHeaderCodes.Content_Type]: 'application/http',
4574
+ [exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
4563
4575
  };
4564
4576
  if (part?.contentId)
4565
- headers[exports.HttpHeaders.Content_ID] = part.contentId;
4577
+ headers[exports.HttpHeaderCodes.Content_ID] = part.contentId;
4566
4578
  this._parts.push({
4567
4579
  headers,
4568
4580
  contentId: part?.contentId,
@@ -4573,11 +4585,11 @@ class BatchMultipart {
4573
4585
  addBatch(batch, part) {
4574
4586
  const headers = {
4575
4587
  ...normalizeHeaders(part?.headers || {}, true),
4576
- [exports.HttpHeaders.Content_Type]: 'application/http',
4577
- [exports.HttpHeaders.Content_Transfer_Encoding]: 'binary'
4588
+ [exports.HttpHeaderCodes.Content_Type]: 'application/http',
4589
+ [exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
4578
4590
  };
4579
4591
  if (part?.contentId)
4580
- headers[exports.HttpHeaders.Content_ID] = part.contentId;
4592
+ headers[exports.HttpHeaderCodes.Content_ID] = part.contentId;
4581
4593
  this._parts.push({
4582
4594
  headers,
4583
4595
  contentId: part?.contentId,
@@ -4649,7 +4661,7 @@ class BatchMultipart {
4649
4661
  if (part.content instanceof HttpRequestContent)
4650
4662
  s += (part.content.method || 'GET').toUpperCase() + ' ' + part.content.url + ' HTTP/1.1' + CRLF;
4651
4663
  else
4652
- s += 'HTTP/1.1 ' + part.content.status + (exports.HttpStatus[part.content.status] || 'Unknown') + CRLF;
4664
+ s += 'HTTP/1.1 ' + part.content.status + (exports.HttpStatusCodes[part.content.status] || 'Unknown') + CRLF;
4653
4665
  if (part.content.headers) {
4654
4666
  for (const [k, v] of Object.entries(part.content.headers)) {
4655
4667
  if (v === '' || v == null)
@@ -4881,45 +4893,58 @@ function OprSearchResolver(options) {
4881
4893
  };
4882
4894
  }
4883
4895
 
4896
+ var _a$4, _b$2, _c$1, _d;
4897
+ function isMap(v) {
4898
+ return v && typeof v.forEach === 'function';
4899
+ }
4900
+ const kKeyMap = Symbol('kKeyMap');
4901
+ const kKeyOrder = Symbol('kKeyOrder');
4902
+ const kWellKnownKeys = Symbol('kWellKnownKeys');
4903
+ const kOptions$3 = Symbol('kOptions');
4904
+ /**
4905
+ * A Map implementation that supports case-insensitivity and ordered keys
4906
+ */
4884
4907
  class ResponsiveMap extends Map {
4885
- constructor(data, wellKnownKeys) {
4908
+ constructor(init, options) {
4886
4909
  super();
4887
- this._keyMap = new Map();
4888
- this._keyOrder = [];
4889
- this._wellKnownKeyMap = new Map();
4890
- if (wellKnownKeys)
4891
- wellKnownKeys.forEach(k => this._wellKnownKeyMap.set(k.toLowerCase(), k));
4892
- if (typeof data?.forEach === 'function') {
4893
- data.forEach((v, k) => this.set(k, v));
4894
- }
4895
- else if (data && typeof data === 'object')
4896
- Object.keys(data).forEach(k => this.set(k, data[k]));
4910
+ this[_a$4] = new Map();
4911
+ this[_b$2] = [];
4912
+ this[_c$1] = new Map();
4913
+ this[_d] = { caseSensitive: false };
4914
+ this[kOptions$3].caseSensitive = !!options?.caseSensitive;
4915
+ if (options?.wellKnownKeys)
4916
+ options.wellKnownKeys.forEach(k => this[kWellKnownKeys].set(k.toLowerCase(), k));
4917
+ if (isMap(init)) {
4918
+ init.forEach((v, k) => this.set(k, v));
4919
+ }
4920
+ else if (init && typeof init === 'object')
4921
+ Object.keys(init).forEach(k => this.set(k, init[k]));
4897
4922
  }
4898
4923
  clear() {
4899
4924
  super.clear();
4900
- this._keyMap.clear();
4901
- this._keyOrder = [];
4925
+ this[kKeyMap].clear();
4926
+ this[kKeyOrder] = [];
4902
4927
  }
4903
4928
  get(key) {
4904
4929
  const orgKey = this._getOriginalKey(key);
4905
4930
  return super.get(orgKey);
4906
4931
  }
4907
4932
  has(key) {
4908
- return this._keyMap.has(this._getLowerKey(key));
4933
+ return this[kKeyMap].has(this._getStoringKey(key));
4909
4934
  }
4910
4935
  set(key, value) {
4911
4936
  key = this._getOriginalKey(key);
4912
- this._keyMap.set(this._getLowerKey(key), key);
4913
- if (!this._keyOrder.includes(key))
4914
- this._keyOrder.push(key);
4937
+ this[kKeyMap].set(this._getStoringKey(key), key);
4938
+ if (!this[kKeyOrder].includes(key))
4939
+ this[kKeyOrder].push(key);
4915
4940
  return super.set(key, value);
4916
4941
  }
4917
4942
  keys() {
4918
- return this._keyOrder.values();
4943
+ return this[kKeyOrder].values();
4919
4944
  }
4920
4945
  values() {
4921
4946
  let i = -1;
4922
- const arr = this._keyOrder;
4947
+ const arr = this[kKeyOrder];
4923
4948
  const map = this;
4924
4949
  return {
4925
4950
  [Symbol.iterator]() {
@@ -4936,7 +4961,7 @@ class ResponsiveMap extends Map {
4936
4961
  }
4937
4962
  entries() {
4938
4963
  let i = -1;
4939
- const arr = this._keyOrder;
4964
+ const arr = this[kKeyOrder];
4940
4965
  const map = this;
4941
4966
  return {
4942
4967
  [Symbol.iterator]() {
@@ -4953,27 +4978,31 @@ class ResponsiveMap extends Map {
4953
4978
  }
4954
4979
  delete(key) {
4955
4980
  const orgKey = this._getOriginalKey(key);
4956
- const k = this._getLowerKey(key);
4957
- this._keyMap.delete(k);
4958
- const i = this._keyOrder.indexOf(orgKey);
4981
+ const k = this._getStoringKey(key);
4982
+ this[kKeyMap].delete(k);
4983
+ const i = this[kKeyOrder].indexOf(orgKey);
4959
4984
  if (i >= 0)
4960
- this._keyOrder.splice(i, 1);
4985
+ this[kKeyOrder].splice(i, 1);
4961
4986
  return super.delete(orgKey);
4962
4987
  }
4963
4988
  sort(compareFn) {
4964
- this._keyOrder.sort(compareFn);
4989
+ this[kKeyOrder].sort(compareFn);
4965
4990
  return this;
4966
4991
  }
4967
- [Symbol.iterator]() {
4992
+ [(_a$4 = kKeyMap, _b$2 = kKeyOrder, _c$1 = kWellKnownKeys, _d = kOptions$3, Symbol.iterator)]() {
4968
4993
  return this.entries();
4969
4994
  }
4970
4995
  _getOriginalKey(key) {
4996
+ if (this[kOptions$3].caseSensitive)
4997
+ return key;
4971
4998
  if (typeof key === 'string')
4972
- return this._keyMap.get(key.toLowerCase()) ??
4973
- (this._wellKnownKeyMap.get(key.toLowerCase()) ?? key);
4999
+ return this[kKeyMap].get(key.toLowerCase()) ??
5000
+ (this[kWellKnownKeys].get(key.toLowerCase()) ?? key);
4974
5001
  return key;
4975
5002
  }
4976
- _getLowerKey(key) {
5003
+ _getStoringKey(key) {
5004
+ if (this[kOptions$3].caseSensitive)
5005
+ return key;
4977
5006
  if (typeof key === 'string')
4978
5007
  return key.toLowerCase();
4979
5008
  return key;
@@ -5479,6 +5508,9 @@ class DataType {
5479
5508
  get ctor() {
5480
5509
  return this._metadata.ctor;
5481
5510
  }
5511
+ get isBuiltin() {
5512
+ return builtInTypes.has(this._name);
5513
+ }
5482
5514
  parse(value) {
5483
5515
  return this._metadata.parse ? this._metadata.parse(value) : value;
5484
5516
  }
@@ -5726,6 +5758,9 @@ class CollectionResourceInfo extends ResourceInfo {
5726
5758
  metadata.search.sortFields = normalizeFieldArray(document, dataType, metadata.search.sortFields);
5727
5759
  }
5728
5760
  }
5761
+ get instance() {
5762
+ return this.metadata.instance;
5763
+ }
5729
5764
  get keyFields() {
5730
5765
  return this.metadata.keyFields;
5731
5766
  }
@@ -5753,6 +5788,18 @@ class CollectionResourceInfo extends ResourceInfo {
5753
5788
  get search() {
5754
5789
  return this.metadata.search;
5755
5790
  }
5791
+ getHandlerNames() {
5792
+ const out = [];
5793
+ collectionMethods.forEach(m => {
5794
+ if (this.metadata[m])
5795
+ out.push(m);
5796
+ });
5797
+ return out;
5798
+ }
5799
+ getHandler(method) {
5800
+ const r = this.metadata[method];
5801
+ return r && r.handler;
5802
+ }
5756
5803
  getSchema(jsonOnly) {
5757
5804
  const out = super.getSchema(jsonOnly);
5758
5805
  if (out.keyFields.length < 2)
@@ -5785,6 +5832,14 @@ class SingletonResourceInfo extends ResourceInfo {
5785
5832
  get update() {
5786
5833
  return this.metadata.update;
5787
5834
  }
5835
+ getHandlerNames() {
5836
+ const out = [];
5837
+ singletonMethods.forEach(m => {
5838
+ if (this.metadata[m])
5839
+ out.push(m);
5840
+ });
5841
+ return out;
5842
+ }
5788
5843
  getSchema(jsonOnly) {
5789
5844
  const out = super.getSchema(jsonOnly);
5790
5845
  for (const k of singletonMethods) {
@@ -5824,25 +5879,25 @@ class OpraDocument {
5824
5879
  const t = this.types.get(name);
5825
5880
  if (t)
5826
5881
  return t;
5827
- throw new Error(`Data type "${name}" does not exists`);
5882
+ throw new NotFoundError(`Data type "${name}" does not exists`);
5828
5883
  }
5829
5884
  getComplexDataType(name) {
5830
5885
  const t = this.getDataType(name);
5831
5886
  if (t && t instanceof ComplexType)
5832
5887
  return t;
5833
- throw new Error(`Data type "${name}" is not a ComplexType`);
5888
+ throw new NotAcceptableError(`Data type "${name}" is not a ComplexType`);
5834
5889
  }
5835
5890
  getSimpleDataType(name) {
5836
5891
  const t = this.getDataType(name);
5837
5892
  if (t && t instanceof SimpleType)
5838
5893
  return t;
5839
- throw new Error(`Data type "${name}" is not a SimpleType`);
5894
+ throw new NotAcceptableError(`Data type "${name}" is not a SimpleType`);
5840
5895
  }
5841
5896
  getUnionDataType(name) {
5842
5897
  const t = this.getDataType(name);
5843
5898
  if (t && t instanceof UnionType)
5844
5899
  return t;
5845
- throw new Error(`Data type "${name}" is not a UnionType`);
5900
+ throw new NotAcceptableError(`Data type "${name}" is not a UnionType`);
5846
5901
  }
5847
5902
  get resources() {
5848
5903
  return this._resources;
@@ -5853,19 +5908,19 @@ class OpraDocument {
5853
5908
  getResource(name) {
5854
5909
  const t = this.resources.get(name);
5855
5910
  if (!t)
5856
- throw new Error(`Resource "${name}" does not exists`);
5911
+ throw new NotFoundError(`Resource "${name}" does not exists`);
5857
5912
  return t;
5858
5913
  }
5859
5914
  getCollectionResource(name) {
5860
5915
  const t = this.getResource(name);
5861
5916
  if (!(t instanceof CollectionResourceInfo))
5862
- throw new Error(`"${name}" is not a CollectionResource`);
5917
+ throw new NotAcceptableError(`"${name}" is not a CollectionResource`);
5863
5918
  return t;
5864
5919
  }
5865
5920
  getSingletonResource(name) {
5866
5921
  const t = this.getResource(name);
5867
5922
  if (!(t instanceof SingletonResourceInfo))
5868
- throw new Error(`"${name}" is not a SingletonResource`);
5923
+ throw new NotAcceptableError(`"${name}" is not a SingletonResource`);
5869
5924
  return t;
5870
5925
  }
5871
5926
  getMetadata(jsonOnly) {
@@ -5906,7 +5961,7 @@ class OpraDocument {
5906
5961
  dataType = new UnionType(this, name, { ...schema, types: [] });
5907
5962
  }
5908
5963
  else
5909
- throw new TypeError(`Invalid data type schema`);
5964
+ throw new InternalServerError(`Invalid data type schema`);
5910
5965
  this._types.set(name, dataType);
5911
5966
  if (isOwn)
5912
5967
  this._ownTypes.set(name, dataType);
@@ -5916,16 +5971,16 @@ class OpraDocument {
5916
5971
  if (exports.OpraSchema.isCollectionResource(schema) || exports.OpraSchema.isSingletonResource(schema)) {
5917
5972
  const dataType = this.getDataType(schema.type);
5918
5973
  if (!dataType)
5919
- throw new TypeError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
5974
+ throw new InternalServerError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
5920
5975
  if (!(dataType instanceof ComplexType))
5921
- throw new TypeError(`${schema.type} is not an ComplexType`);
5976
+ throw new InternalServerError(`${schema.type} is not an ComplexType`);
5922
5977
  if (exports.OpraSchema.isCollectionResource(schema))
5923
5978
  this.resources.set(name, new CollectionResourceInfo(this, name, dataType, schema));
5924
5979
  else
5925
5980
  this.resources.set(name, new SingletonResourceInfo(this, name, dataType, schema));
5926
5981
  }
5927
5982
  else
5928
- throw new TypeError(`Unknown resource kind (${schema.kind})`);
5983
+ throw new InternalServerError(`Unknown resource kind (${schema.kind})`);
5929
5984
  }
5930
5985
  _initTypes() {
5931
5986
  for (const dataType of this._types.values()) {
@@ -6446,51 +6501,42 @@ class OpraURLPathComponent {
6446
6501
  }
6447
6502
  }
6448
6503
 
6504
+ var _a$3;
6449
6505
  const nodeInspectCustom$2 = Symbol.for('nodejs.util.inspect.custom');
6450
- class OpraURLPath extends events.EventEmitter {
6451
- constructor(...args) {
6452
- super();
6453
- this._entries = [];
6454
- for (const x of args) {
6455
- if (isURL(x)) {
6456
- this._parse(x.pathname);
6457
- continue;
6458
- }
6459
- // noinspection SuspiciousTypeOfGuard
6460
- if (x instanceof OpraURLPath)
6461
- this._entries.push(...x._entries);
6462
- else
6463
- this.add(x);
6464
- }
6506
+ const kEntries$2 = Symbol('kEntries');
6507
+ const kOptions$2 = Symbol('kOptions');
6508
+ class OpraURLPath {
6509
+ constructor(init, options) {
6510
+ this[_a$3] = [];
6511
+ this[kOptions$2] = { ...options, onChange: undefined };
6512
+ if (Array.isArray(init))
6513
+ this.join(...init);
6514
+ else if (init)
6515
+ this.join(init);
6516
+ this[kOptions$2].onChange = options?.onChange;
6465
6517
  }
6466
6518
  get size() {
6467
- return this._entries.length;
6519
+ return this[kEntries$2].length;
6468
6520
  }
6469
- add(component, key, typeCast) {
6470
- this._add(component, key, typeCast);
6471
- this.emit('change');
6521
+ changed() {
6522
+ if (this[kOptions$2].onChange)
6523
+ this[kOptions$2].onChange();
6472
6524
  }
6473
6525
  clear() {
6474
- this._entries = [];
6475
- this.emit('change');
6526
+ this[kEntries$2] = [];
6527
+ this.changed();
6476
6528
  }
6477
6529
  get(index) {
6478
- return this._entries[index];
6530
+ return this[kEntries$2][index];
6479
6531
  }
6480
- join(pathString) {
6481
- const pathTokenizer = fastTokenizer.tokenize(normalizePath(pathString, true), {
6482
- delimiters: '/', quotes: true, brackets: true,
6483
- });
6484
- for (const x of pathTokenizer) {
6485
- const p = decodePathComponent(x);
6486
- this._add(p);
6487
- }
6488
- this.emit('change');
6532
+ join(...source) {
6533
+ source.forEach(x => this._join(this[kEntries$2], x));
6534
+ this.changed();
6489
6535
  return this;
6490
6536
  }
6491
6537
  entries() {
6492
6538
  let i = -1;
6493
- const arr = [...this._entries];
6539
+ const arr = [...this[kEntries$2]];
6494
6540
  return {
6495
6541
  [Symbol.iterator]() {
6496
6542
  return this;
@@ -6504,9 +6550,46 @@ class OpraURLPath extends events.EventEmitter {
6504
6550
  }
6505
6551
  };
6506
6552
  }
6553
+ forEach(callback) {
6554
+ for (const item of this[kEntries$2]) {
6555
+ callback.call(this, item, this);
6556
+ }
6557
+ }
6558
+ getResource(index) {
6559
+ const v = this[kEntries$2][index];
6560
+ return v == null ? undefined : v.resource;
6561
+ }
6562
+ getKey(index) {
6563
+ const v = this[kEntries$2][index];
6564
+ return v == null ? undefined : v.key;
6565
+ }
6566
+ pop() {
6567
+ const out = this[kEntries$2].pop();
6568
+ this.changed();
6569
+ return out;
6570
+ }
6571
+ shift() {
6572
+ const out = this[kEntries$2].shift();
6573
+ this.changed();
6574
+ return out;
6575
+ }
6576
+ slice(start, end) {
6577
+ return new OpraURLPath(this[kEntries$2].slice(start, end));
6578
+ }
6579
+ splice(start, deleteCount, join) {
6580
+ const items = (join ? this._join([], join) : []);
6581
+ this[kEntries$2].splice(start, deleteCount, ...items);
6582
+ this.changed();
6583
+ }
6584
+ unshift(join) {
6585
+ return this.splice(0, 0, join);
6586
+ }
6587
+ toString() {
6588
+ return this[kEntries$2].map(x => encodePathComponent(x.resource, x.key, x.typeCast)).join('/');
6589
+ }
6507
6590
  values() {
6508
6591
  let i = -1;
6509
- const arr = [...this._entries];
6592
+ const arr = [...this[kEntries$2]];
6510
6593
  return {
6511
6594
  [Symbol.iterator]() {
6512
6595
  return this;
@@ -6520,59 +6603,56 @@ class OpraURLPath extends events.EventEmitter {
6520
6603
  }
6521
6604
  };
6522
6605
  }
6523
- forEach(callback) {
6524
- for (const item of this._entries) {
6525
- callback.call(this, item.resource, item.key, this);
6606
+ _join(target, source) {
6607
+ if (typeof source === 'string') {
6608
+ const pathTokenizer = fastTokenizer.tokenize(normalizePath(source, true), {
6609
+ delimiters: '/', quotes: true, brackets: true,
6610
+ });
6611
+ for (const x of pathTokenizer) {
6612
+ const p = decodePathComponent(x);
6613
+ target.push(new OpraURLPathComponent(p));
6614
+ }
6615
+ return;
6526
6616
  }
6617
+ if (source instanceof OpraURLPath) {
6618
+ target.push(...source[kEntries$2].map(x => new OpraURLPathComponent(x)));
6619
+ return;
6620
+ }
6621
+ if (typeof source === 'object' && source.path instanceof OpraURLPath) {
6622
+ this._join(target, source.path);
6623
+ return;
6624
+ }
6625
+ if (isURL(source)) {
6626
+ this._join(target, source.pathname);
6627
+ return;
6628
+ }
6629
+ if (Array.isArray(source)) {
6630
+ source.forEach(x => this._join(target, x));
6631
+ return;
6632
+ }
6633
+ target.push(new OpraURLPathComponent(source));
6527
6634
  }
6528
- getResource(index) {
6529
- const v = this._entries[index];
6530
- return v == null ? undefined : v.resource;
6531
- }
6532
- getKey(index) {
6533
- const v = this._entries[index];
6534
- return v == null ? undefined : v.key;
6535
- }
6536
- toString() {
6537
- return this._entries.map(x => encodePathComponent(x.resource, x.key, x.typeCast)).join('/');
6635
+ /* istanbul ignore next */
6636
+ [(_a$3 = kEntries$2, nodeInspectCustom$2)]() {
6637
+ return this[kEntries$2];
6538
6638
  }
6539
6639
  [Symbol.iterator]() {
6540
6640
  return this.entries();
6541
6641
  }
6542
- /* istanbul ignore next */
6543
- [nodeInspectCustom$2]() {
6544
- return this._entries;
6545
- }
6546
- _add(component, key, typeCast) {
6547
- if (component instanceof OpraURLPathComponent) {
6548
- this._entries.push(component);
6549
- }
6550
- else if (typeof component === 'object')
6551
- this._entries.push(new OpraURLPathComponent(component));
6552
- else
6553
- this._entries.push(new OpraURLPathComponent({ resource: component, key, typeCast }));
6554
- }
6555
- _parse(v) {
6556
- if (!v)
6557
- return;
6558
- const pathTokenizer = fastTokenizer.tokenize(v, { delimiters: '/', quotes: true, brackets: true });
6559
- for (const x of pathTokenizer) {
6560
- if (!x)
6561
- continue;
6562
- const p = decodePathComponent(x);
6563
- this._add(p);
6564
- }
6565
- this.emit('change');
6642
+ get [Symbol.toStringTag]() {
6643
+ return 'OpraURLPath';
6566
6644
  }
6567
6645
  }
6646
+ OpraURLPath.kEntries = kEntries$2;
6647
+ OpraURLPath.kOptions = kOptions$2;
6568
6648
 
6569
- class Format {
6649
+ class HttpParamCodec {
6570
6650
  }
6571
6651
 
6572
6652
  const trueValues = ['true', 't', 'yes', 'y', '1'];
6573
6653
  const falseValues = ['false', 'f', 'no', 'n', '0'];
6574
- class BooleanFormat extends Format {
6575
- parse(value) {
6654
+ class BooleanCodec extends HttpParamCodec {
6655
+ decode(value) {
6576
6656
  if (value === '')
6577
6657
  return true;
6578
6658
  // noinspection SuspiciousTypeOfGuard
@@ -6584,7 +6664,7 @@ class BooleanFormat extends Format {
6584
6664
  return false;
6585
6665
  throw new TypeError(`"${value}" is not a valid boolean`);
6586
6666
  }
6587
- stringify(value) {
6667
+ encode(value) {
6588
6668
  return typeof value === 'boolean' ?
6589
6669
  (value ? 'true' : 'false') : '';
6590
6670
  }
@@ -6593,7 +6673,7 @@ class BooleanFormat extends Format {
6593
6673
  /* eslint-disable max-len */
6594
6674
  // noinspection RegExpUnnecessaryNonCapturingGroup
6595
6675
  const DATE_FORMAT_PATTERN = /^(\d{4})(?:-?(0[1-9]|1[012])(?:-?([123]0|[012][1-9]|31))?)?(?:[T ]?([01][0-9]|2[0-3]):?([0-5][0-9]):?([0-5][0-9])?(?:\.(\d+))?(?:(Z)|(?:([+-])([01]?[0-9]|2[0-3]):?([0-5][0-9])?))?)?$/;
6596
- class DateFormat extends Format {
6676
+ class DateCodec extends HttpParamCodec {
6597
6677
  constructor(options) {
6598
6678
  super();
6599
6679
  this.max = options?.max ? coerceToDateString(options.max) : undefined;
@@ -6601,7 +6681,7 @@ class DateFormat extends Format {
6601
6681
  this.time = options?.time ?? true;
6602
6682
  this.timeZone = options?.timeZone ?? true;
6603
6683
  }
6604
- parse(value) {
6684
+ decode(value) {
6605
6685
  const v = coerceToDateString(value, this.time, this.timeZone);
6606
6686
  if (this.min != null && v < this.min)
6607
6687
  throw new TypeError(`Value must be ${this.min} or greater.`);
@@ -6609,7 +6689,7 @@ class DateFormat extends Format {
6609
6689
  throw new TypeError(`Value must be ${this.max} or less.`);
6610
6690
  return v;
6611
6691
  }
6612
- stringify(value) {
6692
+ encode(value) {
6613
6693
  return coerceToDateString(value, this.time, this.timeZone);
6614
6694
  }
6615
6695
  }
@@ -6630,25 +6710,25 @@ function coerceToDateString(value, time, timeZone) {
6630
6710
  return v;
6631
6711
  }
6632
6712
 
6633
- class FilterFormat extends Format {
6634
- parse(value) {
6713
+ class FilterCodec extends HttpParamCodec {
6714
+ decode(value) {
6635
6715
  if (value instanceof Expression)
6636
6716
  return value;
6637
6717
  return parseFilter(value);
6638
6718
  }
6639
- stringify(value) {
6719
+ encode(value) {
6640
6720
  // @ts-ignore
6641
6721
  return value ? '' + value : '';
6642
6722
  }
6643
6723
  }
6644
6724
 
6645
- class NumberFormat extends Format {
6725
+ class NumberCodec extends HttpParamCodec {
6646
6726
  constructor(options) {
6647
6727
  super();
6648
6728
  this.max = options?.max;
6649
6729
  this.min = options?.min;
6650
6730
  }
6651
- parse(value) {
6731
+ decode(value) {
6652
6732
  // noinspection SuspiciousTypeOfGuard
6653
6733
  const v = typeof value === 'number' ? value : parseFloat(value);
6654
6734
  if (isNaN(v))
@@ -6659,18 +6739,18 @@ class NumberFormat extends Format {
6659
6739
  throw new TypeError(`Value must be ${this.max} or less.`);
6660
6740
  return v;
6661
6741
  }
6662
- stringify(value) {
6742
+ encode(value) {
6663
6743
  return typeof value === 'number' ? '' + value : '';
6664
6744
  }
6665
6745
  }
6666
6746
 
6667
- class IntegerFormat extends NumberFormat {
6747
+ class IntegerCodec extends NumberCodec {
6668
6748
  constructor(options) {
6669
6749
  super(options);
6670
6750
  this.enum = options?.enum;
6671
6751
  }
6672
- parse(value) {
6673
- const v = super.parse(value);
6752
+ decode(value) {
6753
+ const v = super.decode(value);
6674
6754
  if (!Number.isInteger(v))
6675
6755
  throw new TypeError(`"${value}" is not a valid integer`);
6676
6756
  if (this.enum && !this.enum.includes(v))
@@ -6679,14 +6759,14 @@ class IntegerFormat extends NumberFormat {
6679
6759
  }
6680
6760
  }
6681
6761
 
6682
- class StringFormat extends Format {
6762
+ class StringCodec extends HttpParamCodec {
6683
6763
  constructor(options) {
6684
6764
  super();
6685
6765
  this.maxLength = options?.maxLength;
6686
6766
  this.minLength = options?.minLength;
6687
6767
  this.enum = options?.enum;
6688
6768
  }
6689
- parse(value) {
6769
+ decode(value) {
6690
6770
  if (this.minLength != null && value.length < this.minLength)
6691
6771
  throw new TypeError(`Value must be at least ${this.minLength} character${this.minLength > 1 ? 's' : ''} long.`);
6692
6772
  if (this.maxLength != null && value.length > this.maxLength)
@@ -6695,406 +6775,588 @@ class StringFormat extends Format {
6695
6775
  throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
6696
6776
  return value;
6697
6777
  }
6698
- stringify(value) {
6778
+ encode(value) {
6699
6779
  return value == null ? '' : '' + value;
6700
6780
  }
6701
6781
  }
6702
6782
 
6703
- const internalFormats = {
6704
- 'integer': new IntegerFormat(),
6705
- 'number': new NumberFormat(),
6706
- 'string': new StringFormat(),
6707
- 'boolean': new BooleanFormat(),
6708
- 'date': new DateFormat(),
6709
- 'filter': new FilterFormat()
6783
+ /**
6784
+ * Encode input string with standard encodeURIComponent and then un-encode specific characters.
6785
+ */
6786
+ const ENCODING_REGEX = /%(\d[a-f0-9])/gi;
6787
+ const ENCODING_REPLACEMENTS = {
6788
+ '2C': ',',
6789
+ '2F': '/',
6790
+ '24': '$',
6791
+ '3A': ':',
6792
+ '3B': ';',
6793
+ '3D': '=',
6794
+ '3F': '?',
6795
+ '40': '@'
6710
6796
  };
6711
- const nodeInspectCustom$1 = Symbol.for('nodejs.util.inspect.custom');
6712
- class OpraURLSearchParams extends events.EventEmitter {
6713
- constructor(init) {
6714
- super();
6715
- this._params = new ResponsiveMap();
6716
- this._entries = new ResponsiveMap();
6717
- this._size = 0;
6718
- this.defineParam('$filter', { format: 'filter' });
6719
- this.defineParam('$limit', { format: new IntegerFormat({ min: 0 }) });
6720
- this.defineParam('$skip', { format: new IntegerFormat({ min: 0 }) });
6721
- this.defineParam('$pick', { format: 'string', array: 'strict' });
6722
- this.defineParam('$omit', { format: 'string', array: 'strict' });
6723
- this.defineParam('$include', { format: 'string', array: 'strict' });
6724
- this.defineParam('$sort', { format: 'string', array: 'strict' });
6725
- this.defineParam('$distinct', { format: 'boolean' });
6726
- this.defineParam('$count', { format: 'boolean' });
6727
- if (init) {
6728
- if (typeof init === 'string')
6729
- this.parse(init);
6730
- else
6731
- this.addAll(init);
6732
- }
6797
+ function encodeURIParam(v) {
6798
+ return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
6799
+ }
6800
+
6801
+ var _a$2, _b$1, _c;
6802
+ const kEntries$1 = Symbol('kEntries');
6803
+ const kSize$1 = Symbol('kSize');
6804
+ const kParamDefs = Symbol('kParamDefs');
6805
+ const kOptions$1 = Symbol('kOptions');
6806
+ const defaultKeyDecoder = (s) => decodeURIComponent(s);
6807
+ const defaultValueDecoder = (s) => decodeURIComponent(s);
6808
+ const defaultKeyEncoder = (s) => encodeURIParam(s);
6809
+ const defaultValueEncoder = (s) => encodeURIParam(s);
6810
+ const internalCodecs = {
6811
+ 'boolean': new BooleanCodec(),
6812
+ 'date': new DateCodec(),
6813
+ 'filter': new FilterCodec(),
6814
+ 'integer': new IntegerCodec(),
6815
+ 'number': new NumberCodec(),
6816
+ 'string': new StringCodec()
6817
+ };
6818
+ class HttpParams {
6819
+ constructor(init, options) {
6820
+ this[_a$2] = new ResponsiveMap();
6821
+ this[_b$1] = 0;
6822
+ this[_c] = new Map();
6823
+ this[kOptions$1] = { ...options, onChange: undefined };
6824
+ const defineParams = options?.params;
6825
+ if (defineParams)
6826
+ Object.keys(defineParams).forEach(key => this.define(key, defineParams[key]));
6827
+ if (init)
6828
+ this.appendAll(init);
6829
+ this[kOptions$1].onChange = options?.onChange;
6733
6830
  }
6734
6831
  get size() {
6735
- return this._size;
6832
+ return this[kSize$1];
6736
6833
  }
6737
- addAll(values) {
6738
- let changed = false;
6739
- if (typeof values.forEach === 'function') {
6740
- values.forEach((value, name) => {
6741
- changed = this._add(name, value) || changed;
6742
- });
6834
+ /**
6835
+ * Appends a new value to the existing set of values for a parameter
6836
+ * and returns this instance
6837
+ */
6838
+ append(name, value) {
6839
+ this._append(name, value);
6840
+ this.changed();
6841
+ return this;
6842
+ }
6843
+ appendAll(input) {
6844
+ if (typeof input === 'string') {
6845
+ if (input && input.startsWith('?'))
6846
+ input = input.substring(1);
6847
+ if (!input)
6848
+ return this;
6849
+ const tokenizer = fastTokenizer.tokenize(input, { delimiters: '&', quotes: true, brackets: true });
6850
+ for (const token of tokenizer) {
6851
+ if (!token)
6852
+ continue;
6853
+ const itemTokenizer = fastTokenizer.tokenize(token, {
6854
+ delimiters: '=',
6855
+ quotes: true,
6856
+ brackets: true
6857
+ });
6858
+ const k = this.decodeKey(itemTokenizer.next() || '');
6859
+ const v = this.decodeValue(itemTokenizer.join('='), k);
6860
+ this._append(k, v);
6861
+ }
6743
6862
  }
6744
- else if (typeof values === 'object') ;
6863
+ else if (input.forEach && typeof input.forEach === 'function')
6864
+ input.forEach((value, name) => this._append(name, value));
6745
6865
  else
6746
- throw new TypeError(`Invalid argument`);
6747
- if (changed)
6748
- this.emit('change');
6866
+ Object.keys(input).forEach(name => this._append(name, input[name]));
6867
+ return this;
6749
6868
  }
6750
- append(name, value) {
6751
- if (this._add(name, value))
6752
- this.emit('change');
6869
+ changed() {
6870
+ if (this[kOptions$1].onChange)
6871
+ this[kOptions$1].onChange();
6753
6872
  }
6754
6873
  clear() {
6755
- this._entries.clear();
6756
- this._size = 0;
6757
- this.emit('change');
6874
+ if (this[kEntries$1].size) {
6875
+ this[kEntries$1].clear();
6876
+ this[kSize$1] = 0;
6877
+ this.changed();
6878
+ }
6758
6879
  }
6759
- defineParam(name, options) {
6760
- if (!name)
6761
- throw new Error('Parameter name required');
6762
- const meta = {
6763
- ...options,
6764
- name,
6765
- format: options?.format || 'string'
6766
- };
6767
- if (typeof meta.format === 'string' && !internalFormats[meta.format])
6768
- throw new Error(`Unknown data format "${meta.format}"`);
6769
- meta.format = meta.format || 'string';
6770
- this._params.set(name, meta);
6880
+ /**
6881
+ * Deletes values for a given parameter
6882
+ */
6883
+ delete(name, value) {
6884
+ if (this._delete(name, value))
6885
+ this.changed();
6771
6886
  return this;
6772
6887
  }
6773
- delete(name) {
6774
- if (this._delete(name))
6775
- this.emit('change');
6776
- }
6888
+ /**
6889
+ * Returns an iterable of key, value pairs for every entry in the map.
6890
+ */
6777
6891
  entries() {
6778
- const items = [];
6779
- this.forEach((value, name) => {
6780
- items.push([name, value]);
6781
- });
6782
- return items.values();
6783
- }
6784
- forEach(callback) {
6785
- for (const [name, entry] of this._entries.entries()) {
6786
- for (let i = 0; i < entry.length; i++) {
6787
- callback(entry[i], name, this);
6892
+ const iter = this[kEntries$1].entries();
6893
+ let i = 0;
6894
+ let key;
6895
+ let values;
6896
+ return {
6897
+ [Symbol.iterator]() {
6898
+ return this;
6899
+ },
6900
+ next() {
6901
+ if (values) {
6902
+ if (i >= values.length) {
6903
+ values = undefined;
6904
+ i = 0;
6905
+ }
6906
+ }
6907
+ if (!values) {
6908
+ const n = iter.next();
6909
+ if (n.done)
6910
+ return { done: true, value: undefined };
6911
+ key = n.value[0];
6912
+ values = n.value[1];
6913
+ }
6914
+ return {
6915
+ done: false,
6916
+ value: [key, values[i++]]
6917
+ };
6788
6918
  }
6919
+ };
6920
+ }
6921
+ forEach(callbackFn, thisArg) {
6922
+ const iterator = this.entries();
6923
+ let entry = iterator.next();
6924
+ while (!entry.done) {
6925
+ callbackFn.call(thisArg || this, entry.value[1], entry.value[0], this);
6926
+ entry = iterator.next();
6789
6927
  }
6790
6928
  }
6791
- get(name, index) {
6792
- const entry = this._entries.get(name);
6793
- const v = entry && entry[index || 0];
6794
- return v == null ? null : v;
6929
+ /**
6930
+ * Retrieves value of a given parameter at given index
6931
+ */
6932
+ get(name, index = 0) {
6933
+ const values = this[kEntries$1].get(name.toLowerCase());
6934
+ return values && values.length > index ? values[index] : null;
6795
6935
  }
6936
+ /**
6937
+ * Retrieves an array of values for a given parameter.
6938
+ */
6796
6939
  getAll(name) {
6797
- const entry = this._entries.get(name);
6798
- return entry ? entry.slice(0) : [];
6799
- }
6800
- has(name) {
6801
- return this._entries.has(name);
6940
+ const entry = this[kEntries$1].get(name);
6941
+ return entry ? entry.slice(0) : null;
6802
6942
  }
6943
+ /**
6944
+ * Retrieves the names of the parameters.
6945
+ */
6803
6946
  keys() {
6804
- return this._entries.keys();
6805
- }
6806
- set(name, value) {
6807
- this._delete(name);
6808
- this._add(name, value);
6809
- this.emit('change');
6810
- }
6811
- sort(compareFn) {
6812
- this._entries.sort(compareFn);
6813
- this.emit('change');
6947
+ return this[kEntries$1].keys();
6814
6948
  }
6949
+ /**
6950
+ * Retrieves the names of the parameters.
6951
+ */
6815
6952
  values() {
6816
6953
  const items = [];
6817
6954
  this.forEach((value) => items.push(value));
6818
6955
  return items.values();
6819
6956
  }
6957
+ /**
6958
+ * Checks for existence of a parameter.
6959
+ */
6960
+ has(name) {
6961
+ return this[kEntries$1].has(name);
6962
+ }
6963
+ /**
6964
+ * Sets or modifies a value for a given parameter.
6965
+ * If the header already exists, its value is replaced with the given value
6966
+ */
6967
+ set(name, value) {
6968
+ this._set(name, value);
6969
+ this.changed();
6970
+ return this;
6971
+ }
6972
+ sort(compareFn) {
6973
+ this[kEntries$1].sort(compareFn);
6974
+ this.changed();
6975
+ return this;
6976
+ }
6977
+ /**
6978
+ * Serializes the body to an encoded string, where key-value pairs (separated by `=`) are
6979
+ * separated by `&`s.
6980
+ */
6820
6981
  toString() {
6821
- let out = '';
6982
+ const out = [];
6822
6983
  this.forEach((v, k) => {
6823
- const qi = this._params.get(k);
6824
- const format = qi
6825
- ? (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format)
6826
- : undefined;
6827
- const stringify = (x) => encodeURIComponent(format ? format.stringify(x, k) : (x == null ? '' : '' + x));
6828
- const val = Array.isArray(v)
6829
- ? v.map(stringify).join(qi?.arrayDelimiter || ',')
6830
- : stringify(v);
6831
- if (val) {
6832
- if (out.length > 0)
6833
- out += '&';
6834
- out += k + '=' + val;
6835
- }
6984
+ out.push(this.encodeKey(k) +
6985
+ (v ? '=' + this.encodeValue(v, k) : ''));
6836
6986
  });
6837
- return out;
6987
+ return out.join('&');
6838
6988
  }
6839
- parse(input) {
6840
- this._entries.clear();
6841
- this._size = 0;
6842
- if (input && input.startsWith('?'))
6843
- input = input.substring(1);
6844
- if (!input)
6845
- return;
6846
- const tokenizer = fastTokenizer.tokenize(input, { delimiters: '&', quotes: true, brackets: true });
6847
- for (const token of tokenizer) {
6848
- if (!token)
6849
- continue;
6850
- const itemTokenizer = fastTokenizer.tokenize(token, {
6851
- delimiters: '=',
6852
- quotes: true,
6853
- brackets: true,
6854
- });
6855
- const k = decodeURIComponent(itemTokenizer.next() || '');
6856
- const v = itemTokenizer.join('=');
6857
- const qi = this._params.get(k);
6858
- if (qi?.array) {
6859
- const values = fastTokenizer.splitString(v, {
6860
- delimiters: qi?.arrayDelimiter || ',',
6989
+ define(name, options) {
6990
+ if (!name)
6991
+ throw new Error('Parameter name required');
6992
+ if (typeof options?.codec === 'string' && !internalCodecs[options.codec])
6993
+ throw new Error(`Unknown url parameter format name "${options.codec}"`);
6994
+ const codec = (typeof options?.codec === 'string'
6995
+ ? internalCodecs[options.codec]
6996
+ : options?.codec) || internalCodecs.string;
6997
+ const meta = {
6998
+ ...options,
6999
+ codec
7000
+ };
7001
+ this[kParamDefs].set(name, meta);
7002
+ return this;
7003
+ }
7004
+ encodeKey(key) {
7005
+ return (this[kOptions$1].encodeKey || defaultKeyEncoder)(key);
7006
+ }
7007
+ decodeKey(key) {
7008
+ return (this[kOptions$1].decodeKey || defaultKeyDecoder)(key);
7009
+ }
7010
+ encodeValue(value, key) {
7011
+ const prmDef = this[kParamDefs].get(key);
7012
+ if (prmDef) {
7013
+ const delimReplace = '%' + (prmDef.arrayDelimiter || ',').charCodeAt(0).toString(16).toUpperCase();
7014
+ const fn = (x) => encodeURIParam(prmDef.codec.encode(x)).replaceAll(',', delimReplace);
7015
+ return Array.isArray(value)
7016
+ ? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
7017
+ : fn(value);
7018
+ }
7019
+ return (this[kOptions$1].encodeValue || defaultValueEncoder)(value);
7020
+ }
7021
+ decodeValue(value, key) {
7022
+ const prmDef = this[kParamDefs].get(key);
7023
+ const valueDecoder = (this[kOptions$1].decodeValue || defaultValueDecoder);
7024
+ let val = value;
7025
+ if (prmDef) {
7026
+ if (prmDef.array) {
7027
+ val = fastTokenizer.splitString(value, {
7028
+ delimiters: prmDef.arrayDelimiter || ',',
6861
7029
  brackets: true,
6862
- quotes: true
6863
- }).map((x) => decodeURIComponent(x));
6864
- this._add(k, values);
7030
+ quotes: true,
7031
+ keepQuotes: false
7032
+ }).map((x) => valueDecoder(x));
6865
7033
  }
6866
- else {
6867
- this._add(k, decodeURIComponent(v));
7034
+ else
7035
+ val = valueDecoder(val);
7036
+ const fn = (x) => prmDef.codec.decode(valueDecoder(x));
7037
+ val = Array.isArray(val) ? val.map(fn) : fn(val);
7038
+ if (prmDef.array === 'strict')
7039
+ val = Array.isArray(val) ? val : [val];
7040
+ else if (prmDef.array)
7041
+ val = Array.isArray(val) && val.length === 1 ? val[0] : val;
7042
+ if (Array.isArray(val)) {
7043
+ if (prmDef.minArrayItems && val.length < prmDef.minArrayItems)
7044
+ throw new Error(`"${key}" parameter requires at least ${prmDef.minArrayItems} values`);
7045
+ if (prmDef.maxArrayItems && val.length > prmDef.maxArrayItems)
7046
+ throw new Error(`"${key}" parameter accepts up to ${prmDef.maxArrayItems} values`);
6868
7047
  }
7048
+ return val;
6869
7049
  }
6870
- this.emit('change');
7050
+ return valueDecoder(value);
6871
7051
  }
6872
- toURLSearchParams() {
6873
- const out = new URLSearchParams();
6874
- this.forEach((v, k) => {
6875
- const qi = this._params.get(k);
6876
- const format = qi
6877
- ? (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format)
6878
- : undefined;
6879
- const stringify = (x) => format ? format.stringify(x, k) : (x == null ? '' : '' + x);
6880
- const val = Array.isArray(v)
6881
- ? v.map(stringify).join(qi?.arrayDelimiter || ',')
6882
- : stringify(v);
6883
- out.append(k, val);
6884
- });
6885
- return out;
7052
+ _append(name, value) {
7053
+ let values = this[kEntries$1].get(name);
7054
+ if (!values) {
7055
+ values = [];
7056
+ this[kEntries$1].set(name, values);
7057
+ }
7058
+ values.push(value ?? null);
7059
+ this[kSize$1] += 1;
6886
7060
  }
6887
- [Symbol.iterator]() {
6888
- return this.entries();
7061
+ _delete(name, value) {
7062
+ const oldValues = this[kEntries$1].get(name);
7063
+ if (!oldValues)
7064
+ return false;
7065
+ const oldSize = this[kSize$1];
7066
+ if (value) {
7067
+ const valueToDelete = Array.isArray(value) ? value : [value];
7068
+ const newValues = oldValues.filter(x => !valueToDelete.includes(x));
7069
+ this[kEntries$1].set(name, newValues);
7070
+ this[kSize$1] += -oldValues.length + newValues.length;
7071
+ }
7072
+ else {
7073
+ this[kEntries$1].delete(name);
7074
+ this[kSize$1] -= oldValues.length;
7075
+ }
7076
+ return oldSize !== this[kSize$1];
6889
7077
  }
6890
- get [Symbol.toStringTag]() {
6891
- return 'URLSearchParams';
7078
+ _set(name, value, index) {
7079
+ if (value == null) {
7080
+ this._delete(name);
7081
+ return;
7082
+ }
7083
+ const values = this[kEntries$1].get(name);
7084
+ if (!values) {
7085
+ this[kEntries$1].set(name, [value]);
7086
+ this[kSize$1] += 1;
7087
+ return;
7088
+ }
7089
+ if (index == null || index < 0) {
7090
+ this[kEntries$1].set(name, [value]);
7091
+ this[kSize$1] += -(values.length) + 1;
7092
+ return;
7093
+ }
7094
+ const oldLen = values.length;
7095
+ values[Math.min(index, values.length)] = value;
7096
+ this[kSize$1] += -oldLen + values.length;
6892
7097
  }
6893
- [nodeInspectCustom$1]() {
6894
- return this._entries;
7098
+ [(_a$2 = kEntries$1, _b$1 = kSize$1, _c = kParamDefs, Symbol.iterator)]() {
7099
+ return this.entries();
6895
7100
  }
6896
- _delete(name) {
6897
- const a = this._entries.get(name);
6898
- if (!a)
6899
- return false;
6900
- this._size -= a.length;
6901
- this._entries.delete(name);
6902
- return true;
7101
+ get [Symbol.toStringTag]() {
7102
+ return 'HttpParams';
6903
7103
  }
6904
- _add(name, value) {
6905
- const qi = this._params.get(name);
6906
- const format = qi ?
6907
- (typeof qi.format === 'string' ? internalFormats[qi.format] : qi.format) : undefined;
6908
- const fn = (x) => format ? format.parse(x, name) : x;
6909
- let v = Array.isArray(value) ? value.map(fn) : fn(value);
6910
- if (qi) {
6911
- if (qi.array === 'strict')
6912
- v = Array.isArray(v) ? v : [v];
6913
- else if (qi.array)
6914
- v = Array.isArray(v) && v.length === 1 ? v[0] : v;
6915
- if (Array.isArray(v)) {
6916
- if (qi.minArrayItems && v.length < qi.minArrayItems)
6917
- throw new Error(`"${name}" parameter requires at least ${qi.minArrayItems} values`);
6918
- if (qi.maxArrayItems && v.length > qi.maxArrayItems)
6919
- throw new Error(`"${name}" parameter accepts up to ${qi.maxArrayItems} values`);
7104
+ }
7105
+ HttpParams.kEntries = kEntries$1;
7106
+ HttpParams.kSize = kSize$1;
7107
+ HttpParams.kParamDefs = kParamDefs;
7108
+ HttpParams.kOptions = kOptions$1;
7109
+
7110
+ class OpraURLSearchParams extends HttpParams {
7111
+ constructor(init, options) {
7112
+ super(init, {
7113
+ ...options,
7114
+ params: {
7115
+ '$filter': { codec: 'filter' },
7116
+ '$limit': { codec: new IntegerCodec({ min: 0 }) },
7117
+ '$skip': { codec: new IntegerCodec({ min: 0 }) },
7118
+ '$pick': { codec: 'string', array: 'strict' },
7119
+ '$omit': { codec: 'string', array: 'strict' },
7120
+ '$include': { codec: 'string', array: 'strict' },
7121
+ '$sort': { codec: 'string', array: 'strict' },
7122
+ '$distinct': { codec: 'boolean' },
7123
+ '$count': { codec: 'boolean' },
7124
+ ...options?.params
6920
7125
  }
6921
- }
6922
- let entry = this._entries.get(name);
6923
- if (!entry) {
6924
- entry = [];
6925
- this._entries.set(name, entry);
6926
- }
6927
- entry.push(v);
6928
- this._size++;
6929
- return true;
7126
+ });
7127
+ }
7128
+ get [Symbol.toStringTag]() {
7129
+ return 'URLSearchParams';
6930
7130
  }
6931
7131
  }
6932
7132
 
6933
- const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
7133
+ var _a$1;
7134
+ const nodeInspectCustom$1 = Symbol.for('nodejs.util.inspect.custom');
6934
7135
  const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
6935
7136
  const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
6936
7137
  const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
6937
7138
  const hostnameRegEx = /^([^/:]+)$/;
6938
- const CONTEXT_KEY = Symbol.for('opra.url.context');
6939
- const PATH_KEY = Symbol.for('opra.url.path');
6940
- const SEARCHPARAMS_KEY = Symbol.for('opra.url.searchparams');
7139
+ const kContext = Symbol('kContext');
7140
+ const kPath = Symbol('kPath');
7141
+ const kSearchParams = Symbol('kSearchParams');
6941
7142
  class OpraURL {
6942
- constructor(input, pathPrefix) {
6943
- Object.defineProperty(this, CONTEXT_KEY, {
6944
- writable: true,
6945
- configurable: true,
6946
- enumerable: false,
6947
- value: {}
6948
- });
6949
- Object.defineProperty(this, PATH_KEY, {
6950
- writable: true,
6951
- configurable: true,
6952
- enumerable: false,
6953
- value: new OpraURLPath()
7143
+ constructor(input, arg1) {
7144
+ this[_a$1] = {
7145
+ protocol: '',
7146
+ username: '',
7147
+ pathname: '',
7148
+ prefix: '',
7149
+ hostname: '',
7150
+ port: '',
7151
+ hash: '',
7152
+ password: '',
7153
+ search: '',
7154
+ address: '',
7155
+ needUpdate: true
7156
+ };
7157
+ this[kPath] = new OpraURLPath('', {
7158
+ onChange: () => this._changed()
6954
7159
  });
6955
- Object.defineProperty(this, SEARCHPARAMS_KEY, {
6956
- writable: true,
6957
- configurable: true,
6958
- enumerable: false,
6959
- value: new OpraURLSearchParams()
7160
+ this[kSearchParams] = new OpraURLSearchParams('', {
7161
+ onChange: () => this._changed()
6960
7162
  });
6961
- this.searchParams.on('change', () => this._invalidate());
6962
- this.path.on('change', () => this._invalidate());
6963
- if (pathPrefix)
6964
- this.setPrefix(pathPrefix);
7163
+ const base = typeof arg1 === 'object' ? arg1.base : arg1;
7164
+ if (typeof arg1 === 'object') {
7165
+ const defineParams = arg1?.params;
7166
+ if (defineParams)
7167
+ Object.keys(defineParams).forEach(key => this.searchParams.define(key, defineParams[key]));
7168
+ }
6965
7169
  if (input)
6966
- this.parse(input);
7170
+ this.parse(typeof input === 'object' ? input.toString() : input);
7171
+ if (base) {
7172
+ const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
7173
+ this[kContext].protocol = baseUrl.protocol;
7174
+ this[kContext].hostname = baseUrl.hostname;
7175
+ this[kContext].port = baseUrl.port;
7176
+ this[kContext].prefix = baseUrl.pathname;
7177
+ }
6967
7178
  }
6968
7179
  get address() {
6969
7180
  this._update();
6970
- let out = '';
6971
- if (this.hostname) {
6972
- out += this.protocol + '//' +
6973
- (this.username || this.password
6974
- ? ((this.username ? encodeURIComponent(this.username) : '') +
6975
- (this.password ? ':' + encodeURIComponent(this.password) : '') + '@')
6976
- : '') + this.host;
7181
+ return this[kContext].address;
7182
+ }
7183
+ get host() {
7184
+ return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
7185
+ }
7186
+ set host(v) {
7187
+ if (v) {
7188
+ const m = hostRegEx.exec(v);
7189
+ if (!m)
7190
+ throw Object.assign(new TypeError('Invalid host'), {
7191
+ host: v,
7192
+ code: 'ERR_INVALID_URL'
7193
+ });
7194
+ this[kContext].hostname = m[1];
7195
+ this[kContext].port = m[2] || '';
7196
+ }
7197
+ else {
7198
+ this[kContext].hostname = '';
7199
+ this[kContext].port = '';
7200
+ }
7201
+ this._changed();
7202
+ }
7203
+ get hostname() {
7204
+ return this[kContext].hostname || '';
7205
+ }
7206
+ set hostname(v) {
7207
+ if (v) {
7208
+ if (!hostnameRegEx.test(v))
7209
+ throw Object.assign(new TypeError('Invalid hostname'), {
7210
+ hostname: v,
7211
+ code: 'ERR_INVALID_URL'
7212
+ });
7213
+ this[kContext].hostname = v;
6977
7214
  }
6978
- return out + this.pathPrefix + this.pathname;
7215
+ else
7216
+ this[kContext].hostname = '';
7217
+ this._changed();
6979
7218
  }
6980
7219
  get href() {
6981
7220
  return this.address + this.search + this.hash;
6982
7221
  }
6983
- get protocol() {
6984
- return this[CONTEXT_KEY].protocol || 'http:';
6985
- }
6986
- set protocol(v) {
6987
- if (!schemeRegEx.test(v))
6988
- throw Object.assign(new TypeError('Invalid protocol'), {
6989
- protocol: v,
6990
- code: 'ERR_INVALID_URL'
6991
- });
6992
- this[CONTEXT_KEY].protocol = v + (v.endsWith(':') ? '' : ':');
6993
- }
6994
- get username() {
6995
- return this[CONTEXT_KEY].username || '';
6996
- }
6997
- set username(v) {
6998
- this[CONTEXT_KEY].username = v;
6999
- }
7000
- get password() {
7001
- return this[CONTEXT_KEY].password || '';
7222
+ get password() {
7223
+ return this[kContext].password;
7002
7224
  }
7003
7225
  set password(v) {
7004
- this[CONTEXT_KEY].password = v;
7226
+ this[kContext].password = v || '';
7227
+ this._changed();
7005
7228
  }
7006
- get host() {
7007
- return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
7229
+ get port() {
7230
+ return this[kContext].port;
7008
7231
  }
7009
- set host(v) {
7010
- const m = hostRegEx.exec(v);
7011
- if (!m)
7012
- throw Object.assign(new TypeError('Invalid host'), {
7013
- host: v,
7014
- code: 'ERR_INVALID_URL'
7015
- });
7016
- this[CONTEXT_KEY].hostname = m[1];
7017
- this[CONTEXT_KEY].port = m[2] ? parseInt(m[2], 10) : null;
7232
+ set port(value) {
7233
+ if (value) {
7234
+ // noinspection SuspiciousTypeOfGuard
7235
+ const v = parseInt(value, 10);
7236
+ if (isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
7237
+ throw Object.assign(new TypeError('Invalid port'), {
7238
+ hostname: v,
7239
+ code: 'ERR_INVALID_URL'
7240
+ });
7241
+ this[kContext].port = value;
7242
+ }
7243
+ else
7244
+ this[kContext].port = '';
7245
+ this._changed();
7018
7246
  }
7019
- get hostname() {
7020
- return this[CONTEXT_KEY].hostname || '';
7247
+ get prefix() {
7248
+ return this[kContext].prefix;
7021
7249
  }
7022
- set hostname(v) {
7023
- if (!hostnameRegEx.test(v))
7024
- throw Object.assign(new TypeError('Invalid hostname'), {
7025
- hostname: v,
7026
- code: 'ERR_INVALID_URL'
7027
- });
7028
- this[CONTEXT_KEY].hostname = v;
7250
+ set prefix(value) {
7251
+ if (value) {
7252
+ const url = new OpraURL(value);
7253
+ this[kContext].prefix = url.pathname;
7254
+ }
7255
+ else
7256
+ this[kContext].prefix = '';
7257
+ this._changed();
7029
7258
  }
7030
- get port() {
7031
- const v = this[CONTEXT_KEY].port;
7032
- return v == null ? null : v;
7259
+ get protocol() {
7260
+ return this[kContext].protocol || 'http:';
7033
7261
  }
7034
- set port(v) {
7035
- if (v == null) {
7036
- this[CONTEXT_KEY].port = null;
7037
- return;
7262
+ set protocol(v) {
7263
+ if (v) {
7264
+ if (!schemeRegEx.test(v))
7265
+ throw Object.assign(new TypeError('Invalid protocol'), {
7266
+ protocol: v,
7267
+ code: 'ERR_INVALID_URL'
7268
+ });
7269
+ this[kContext].protocol = v + (v.endsWith(':') ? '' : ':');
7038
7270
  }
7039
- // noinspection SuspiciousTypeOfGuard
7040
- if (typeof v !== 'number' || isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
7041
- throw Object.assign(new TypeError('Invalid port'), {
7042
- hostname: v,
7043
- code: 'ERR_INVALID_URL'
7044
- });
7045
- this[CONTEXT_KEY].port = v;
7271
+ else
7272
+ this[kContext].protocol = '';
7273
+ this._changed();
7046
7274
  }
7047
- get origin() {
7048
- return this.hostname ? (this.protocol + '//' + this.hostname) : '';
7275
+ get username() {
7276
+ return this[kContext].username;
7049
7277
  }
7050
- get pathPrefix() {
7051
- return this[CONTEXT_KEY].pathPrefix || '';
7278
+ set username(v) {
7279
+ this[kContext].username = v || '';
7280
+ this._changed();
7052
7281
  }
7053
- set pathPrefix(v) {
7054
- if (!v) {
7055
- this[CONTEXT_KEY].pathPrefix = '';
7056
- return;
7057
- }
7058
- v = normalizePath(fastTokenizer.tokenize(v, { delimiters: '#?', quotes: true, brackets: true }).next() || '', true);
7059
- if (v.includes('://'))
7060
- this[CONTEXT_KEY].pathPrefix = v;
7061
- else
7062
- this[CONTEXT_KEY].pathPrefix = v ? '/' + v : '';
7282
+ get origin() {
7283
+ return this.hostname ? (this.protocol + '//' + this.hostname) : '';
7063
7284
  }
7064
7285
  get path() {
7065
- return this[PATH_KEY];
7286
+ return this[kPath];
7066
7287
  }
7067
7288
  get pathname() {
7068
7289
  this._update();
7069
- return this[CONTEXT_KEY].pathname || '';
7290
+ return this[kContext].pathname || '';
7070
7291
  }
7071
7292
  set pathname(v) {
7072
7293
  this._setPathname(v, false);
7073
7294
  }
7074
7295
  get searchParams() {
7075
- return this[SEARCHPARAMS_KEY];
7296
+ return this[kSearchParams];
7076
7297
  }
7077
7298
  get hash() {
7078
- return this[CONTEXT_KEY].hash || '';
7299
+ return this[kContext].hash || '';
7079
7300
  }
7080
7301
  set hash(v) {
7081
- this[CONTEXT_KEY].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
7302
+ this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
7303
+ this._changed();
7082
7304
  }
7083
7305
  get search() {
7084
7306
  this._update();
7085
- return this[CONTEXT_KEY].search || '';
7307
+ return this[kContext].search || '';
7086
7308
  }
7087
7309
  set search(v) {
7088
- this.searchParams.parse(v);
7310
+ this.searchParams.clear();
7311
+ this.searchParams.appendAll(v);
7089
7312
  }
7090
- addPath(name, key) {
7091
- this.path.add(name, key);
7313
+ parse(input) {
7314
+ const m = urlRegEx.exec(input);
7315
+ if (!m)
7316
+ throw Object.assign(new TypeError('Invalid URL'), {
7317
+ input,
7318
+ code: 'ERR_INVALID_URL'
7319
+ });
7320
+ this.protocol = m[1];
7321
+ const isAbsolute = !!m[2];
7322
+ if (isAbsolute) {
7323
+ let tokens = fastTokenizer.splitString(m[2], { delimiters: '@' });
7324
+ if (tokens.length > 1) {
7325
+ this.host = tokens[1];
7326
+ tokens = fastTokenizer.splitString(tokens[0], { delimiters: ':' });
7327
+ this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
7328
+ this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
7329
+ }
7330
+ else
7331
+ this.host = tokens[0];
7332
+ }
7333
+ else {
7334
+ this.host = '';
7335
+ this.username = '';
7336
+ this.password = '';
7337
+ }
7338
+ input = m[3] || '';
7339
+ let tokenizer = fastTokenizer.tokenize(input, { delimiters: '#', quotes: true, brackets: true });
7340
+ input = tokenizer.next() || '';
7341
+ this.hash = tokenizer.join('#');
7342
+ tokenizer = fastTokenizer.tokenize(input, { delimiters: '?', quotes: true, brackets: true });
7343
+ this._setPathname(tokenizer.next() || '', isAbsolute);
7344
+ this.searchParams.clear();
7345
+ this.searchParams.appendAll(tokenizer.join('&'));
7346
+ this._changed();
7347
+ }
7348
+ join(...source) {
7349
+ this.path.join(...source);
7092
7350
  return this;
7093
7351
  }
7094
- addSearchParam(name, value) {
7352
+ addParam(name, value) {
7095
7353
  this.searchParams.append(name, value);
7096
7354
  return this;
7097
7355
  }
7356
+ setParam(name, value) {
7357
+ this.searchParams.set(name, value);
7358
+ return this;
7359
+ }
7098
7360
  setHost(v) {
7099
7361
  this.host = v;
7100
7362
  return this;
@@ -7108,11 +7370,11 @@ class OpraURL {
7108
7370
  return this;
7109
7371
  }
7110
7372
  setPort(v) {
7111
- this.port = v;
7373
+ this.port = v ? String(v) : '';
7112
7374
  return this;
7113
7375
  }
7114
7376
  setPrefix(v) {
7115
- this.pathPrefix = v;
7377
+ this.prefix = v;
7116
7378
  return this;
7117
7379
  }
7118
7380
  setPathname(v) {
@@ -7127,46 +7389,11 @@ class OpraURL {
7127
7389
  this.search = v;
7128
7390
  return this;
7129
7391
  }
7130
- setSearchParam(name, value) {
7131
- this.searchParams.set(name, value);
7132
- return this;
7133
- }
7134
- parse(input) {
7135
- const m = urlRegEx.exec(input);
7136
- if (!m)
7137
- throw Object.assign(new TypeError('Invalid URL'), {
7138
- input,
7139
- code: 'ERR_INVALID_URL'
7140
- });
7141
- if (m[1])
7142
- this.protocol = m[1];
7143
- if (m[2]) {
7144
- let tokens = fastTokenizer.splitString(m[2], { delimiters: '@' });
7145
- if (tokens.length > 1) {
7146
- this.host = tokens[1];
7147
- tokens = fastTokenizer.splitString(tokens[0], { delimiters: ':' });
7148
- this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
7149
- this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
7150
- }
7151
- else
7152
- this.host = tokens[0];
7153
- }
7154
- input = m[3] || '';
7155
- let tokenizer = fastTokenizer.tokenize(input, { delimiters: '#', quotes: true, brackets: true });
7156
- input = tokenizer.next() || '';
7157
- this.hash = tokenizer.join('#');
7158
- tokenizer = fastTokenizer.tokenize(input, { delimiters: '?', quotes: true, brackets: true });
7159
- this._setPathname(tokenizer.next() || '', true);
7160
- // this.path.join()
7161
- this.searchParams.clear();
7162
- this.searchParams.parse(tokenizer.join('&'));
7163
- return this;
7164
- }
7165
7392
  toString() {
7166
7393
  return this.href;
7167
7394
  }
7168
7395
  /* istanbul ignore next */
7169
- [nodeInspectCustom]() {
7396
+ [(_a$1 = kContext, nodeInspectCustom$1)]() {
7170
7397
  this._update();
7171
7398
  return {
7172
7399
  protocol: this.protocol,
@@ -7175,7 +7402,7 @@ class OpraURL {
7175
7402
  host: this.host,
7176
7403
  hostname: this.hostname,
7177
7404
  origin: this.origin,
7178
- pathPrefix: this.pathPrefix,
7405
+ pathPrefix: this.prefix,
7179
7406
  path: this.path,
7180
7407
  pathname: this.pathname,
7181
7408
  search: this.search,
@@ -7183,27 +7410,34 @@ class OpraURL {
7183
7410
  hash: this.hash,
7184
7411
  };
7185
7412
  }
7186
- _invalidate() {
7187
- this[CONTEXT_KEY].needUpdate = true;
7188
- }
7189
7413
  _update() {
7190
- if (!this[CONTEXT_KEY].needUpdate)
7414
+ if (!this[kContext].needUpdate)
7191
7415
  return;
7192
- this[CONTEXT_KEY].needUpdate = false;
7416
+ const ctx = this[kContext];
7417
+ ctx.needUpdate = false;
7193
7418
  let s = this.path.toString();
7194
- this[CONTEXT_KEY].pathname = s ? '/' + s : '';
7419
+ ctx.pathname = s ? '/' + s : '';
7195
7420
  s = this.searchParams.toString();
7196
- this[CONTEXT_KEY].search = s ? '?' + s : '';
7421
+ ctx.search = s ? '?' + s : '';
7422
+ let address = '';
7423
+ if (ctx.hostname) {
7424
+ address += (ctx.protocol || 'http:') + '//' +
7425
+ (ctx.username || ctx.password
7426
+ ? ((ctx.username ? encodeURIComponent(ctx.username) : '') +
7427
+ (ctx.password ? ':' + encodeURIComponent(ctx.password) : '') + '@')
7428
+ : '') + this.host;
7429
+ }
7430
+ ctx.address = address + ctx.prefix + ctx.pathname;
7197
7431
  }
7198
- _setPathname(v, inclSvcRoot) {
7432
+ _setPathname(v, trimPrefix) {
7199
7433
  this.path.clear();
7200
7434
  if (!v)
7201
7435
  return;
7202
7436
  const pathTokenizer = fastTokenizer.tokenize(normalizePath(v, true), {
7203
7437
  delimiters: '/', quotes: true, brackets: true,
7204
7438
  });
7205
- if (inclSvcRoot && this.pathPrefix) {
7206
- const prefixTokenizer = fastTokenizer.tokenize(normalizePath(this.pathPrefix, true), {
7439
+ if (trimPrefix && this.prefix) {
7440
+ const prefixTokenizer = fastTokenizer.tokenize(normalizePath(this.prefix, true), {
7207
7441
  delimiters: '/', quotes: true, brackets: true,
7208
7442
  });
7209
7443
  for (const a of prefixTokenizer) {
@@ -7214,12 +7448,428 @@ class OpraURL {
7214
7448
  }
7215
7449
  for (const x of pathTokenizer) {
7216
7450
  const p = decodePathComponent(x);
7217
- this.path.add(p);
7451
+ this.path.join(p);
7218
7452
  }
7453
+ this._changed();
7454
+ }
7455
+ _changed() {
7456
+ this[kContext].needUpdate = true;
7219
7457
  }
7220
7458
  }
7459
+ OpraURL.kContext = kContext;
7460
+ OpraURL.kPath = kPath;
7461
+ OpraURL.kSearchParams = kSearchParams;
7221
7462
 
7222
- buffer.Buffer.from('\r\n');
7463
+ const crlfBuffer = buffer.Buffer.from('\r\n');
7464
+ const kHeaders = Symbol('kHeaders');
7465
+ const kHeadersCount = Symbol('kHeadersCount');
7466
+ const kTrailers = Symbol('kTrailers');
7467
+ const kTrailersCount = Symbol('kTrailersCount');
7468
+ // todo: Check is this class should be in common library
7469
+ class HttpRequestNode extends stream.Readable {
7470
+ constructor() {
7471
+ super(...arguments);
7472
+ this.aborted = false;
7473
+ }
7474
+ get headers() {
7475
+ if (!this[kHeaders])
7476
+ this[kHeaders] = arrayToHeaders(this.rawHeaders);
7477
+ return this[kHeaders];
7478
+ }
7479
+ get headersCount() {
7480
+ return this[kHeadersCount];
7481
+ }
7482
+ get trailers() {
7483
+ if (!this[kTrailers])
7484
+ this[kTrailers] = arrayToHeaders(this.rawTrailers);
7485
+ return this[kTrailers];
7486
+ }
7487
+ get trailersCount() {
7488
+ return this[kTrailersCount];
7489
+ }
7490
+ _read() {
7491
+ if (this.data) {
7492
+ this.push(this.data);
7493
+ }
7494
+ this.push(null);
7495
+ }
7496
+ static parse(input) {
7497
+ const parser = new httpParser.HTTPParser(httpParser.HTTPParser.REQUEST);
7498
+ const out = new HttpRequestNode();
7499
+ const bodyChunks = [];
7500
+ parser[httpParser.HTTPParser.kOnHeadersComplete] = function (req) {
7501
+ out.shouldKeepAlive = req.shouldKeepAlive;
7502
+ out.upgrade = req.upgrade;
7503
+ out.method = httpParser.HTTPParser.methods[req.method];
7504
+ out.url = req.url;
7505
+ out.originalUrl = req.url;
7506
+ out.httpVersionMajor = req.versionMajor;
7507
+ out.httpVersionMinor = req.versionMinor;
7508
+ out.httpVersion = req.versionMajor + '.' + req.versionMinor;
7509
+ out.rawHeaders = req.headers;
7510
+ out[kHeadersCount] = Math.ceil(req.headers.length / 2);
7511
+ out[kTrailersCount] = 0;
7512
+ };
7513
+ parser[httpParser.HTTPParser.kOnBody] = function (chunk, offset, length) {
7514
+ bodyChunks.push(chunk.subarray(offset, offset + length));
7515
+ };
7516
+ // This is actually the event for trailers, go figure.
7517
+ parser[httpParser.HTTPParser.kOnHeaders] = function (t) {
7518
+ out.rawTrailers = t;
7519
+ out[kTrailersCount] = Math.ceil(t.length / 2);
7520
+ };
7521
+ parser[httpParser.HTTPParser.kOnMessageComplete] = function () {
7522
+ out.complete = true;
7523
+ };
7524
+ // Since we are sending the entire Buffer at once here all callbacks above happen synchronously.
7525
+ // The parser does not do _anything_ asynchronous.
7526
+ // However, you can of course call execute() multiple times with multiple chunks, e.g. from a stream.
7527
+ // But then you have to refactor the entire logic to be async (e.g. resolve a Promise in kOnMessageComplete and add timeout logic).
7528
+ parser.execute(input);
7529
+ if (!out.complete)
7530
+ parser.execute(crlfBuffer);
7531
+ parser.finish();
7532
+ if (!out.complete) {
7533
+ throw new Error('Could not parse request');
7534
+ }
7535
+ out.rawTrailers = out.rawTrailers || [];
7536
+ if (bodyChunks.length)
7537
+ out.data = buffer.Buffer.concat(bodyChunks);
7538
+ out.resume();
7539
+ return out;
7540
+ }
7541
+ }
7542
+ function arrayToHeaders(arr) {
7543
+ const headers = {};
7544
+ for (let i = 0; i < arr.length; i++) {
7545
+ const k = arr[i].toLowerCase();
7546
+ const v = arr[++i];
7547
+ const trgV = headers[k];
7548
+ // Array header -- only Set-Cookie at the moment
7549
+ if (trgV && k === 'set-cookie') {
7550
+ const a = Array.isArray(trgV) ? trgV : [trgV];
7551
+ a.push(v);
7552
+ headers[k] = a;
7553
+ }
7554
+ else if (typeof trgV === 'string') {
7555
+ headers[k] += (k === 'cookie' ? '; ' : ', ') + v;
7556
+ }
7557
+ else
7558
+ headers[k] = v;
7559
+ }
7560
+ return headers;
7561
+ }
7562
+
7563
+ var _a, _b;
7564
+ const knownKeys = Object.keys(exports.HttpHeaderCodes);
7565
+ const knownKeysLower = knownKeys.map(x => x.toLowerCase());
7566
+ const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
7567
+ const kEntries = Symbol('kEntries');
7568
+ const kSize = Symbol('kSize');
7569
+ const kOptions = Symbol('kOptions');
7570
+ class HttpHeaders {
7571
+ constructor(init, options) {
7572
+ this[_a] = new ResponsiveMap();
7573
+ this[_b] = 0;
7574
+ this[kOptions] = { ...options, onChange: undefined };
7575
+ if (init)
7576
+ this.appendAll(init);
7577
+ this[kOptions].onChange = options?.onChange;
7578
+ }
7579
+ get size() {
7580
+ return this[kSize];
7581
+ }
7582
+ /**
7583
+ * Appends a new value to the existing set of values for a header
7584
+ * and returns this instance
7585
+ */
7586
+ append(name, value) {
7587
+ this._append(name, value);
7588
+ this.changed();
7589
+ return this;
7590
+ }
7591
+ /**
7592
+ * Appends multiple values to the existing set of values for a header
7593
+ * and returns this instance
7594
+ */
7595
+ appendAll(headers) {
7596
+ if (typeof headers === 'string') {
7597
+ headers.split('\n').forEach(line => {
7598
+ const index = line.indexOf(':');
7599
+ if (index > 0) {
7600
+ const name = line.slice(0, index);
7601
+ const value = line.slice(index + 1).trim();
7602
+ this._append(name, value);
7603
+ }
7604
+ });
7605
+ }
7606
+ else if (headers.forEach && typeof headers.forEach === 'function')
7607
+ headers.forEach((value, name) => this._append(name, value));
7608
+ else
7609
+ Object.keys(headers).forEach(name => this._append(name, headers[name]));
7610
+ this.changed();
7611
+ return this;
7612
+ }
7613
+ changed() {
7614
+ if (this[kOptions].onChange)
7615
+ this[kOptions].onChange();
7616
+ }
7617
+ clear() {
7618
+ if (this[kEntries].size) {
7619
+ this[kEntries].clear();
7620
+ this[kSize] = 0;
7621
+ this.changed();
7622
+ }
7623
+ }
7624
+ /**
7625
+ * Deletes values for a given header
7626
+ */
7627
+ delete(name, value) {
7628
+ if (this._delete(name, value))
7629
+ this.changed();
7630
+ return this;
7631
+ }
7632
+ /**
7633
+ * Returns an iterable of key, value pairs for every entry in the map.
7634
+ */
7635
+ entries() {
7636
+ const iter = this[kEntries].entries();
7637
+ let i = 0;
7638
+ let key;
7639
+ let values;
7640
+ return {
7641
+ [Symbol.iterator]() {
7642
+ return this;
7643
+ },
7644
+ next() {
7645
+ if (values) {
7646
+ if (i >= values.length) {
7647
+ values = undefined;
7648
+ i = 0;
7649
+ }
7650
+ }
7651
+ if (!values) {
7652
+ const n = iter.next();
7653
+ if (n.done)
7654
+ return { done: true, value: undefined };
7655
+ key = n.value[0];
7656
+ values = n.value[1];
7657
+ }
7658
+ return {
7659
+ done: false,
7660
+ value: [key, values[i++]]
7661
+ };
7662
+ }
7663
+ };
7664
+ }
7665
+ forEach(callbackFn, thisArg) {
7666
+ const iterator = this.entries();
7667
+ let entry = iterator.next();
7668
+ while (!entry.done) {
7669
+ callbackFn.call(thisArg || this, entry.value[1], entry.value[0], this);
7670
+ entry = iterator.next();
7671
+ }
7672
+ }
7673
+ /**
7674
+ * Retrieves value of a given header at given index
7675
+ */
7676
+ get(name, index = 0) {
7677
+ const values = this[kEntries].get(name.toLowerCase());
7678
+ return values && values.length > index ? values[index] : null;
7679
+ }
7680
+ /**
7681
+ * Retrieves an array of values for a given header.
7682
+ */
7683
+ getAll(name) {
7684
+ const entry = this[kEntries].get(name);
7685
+ return entry ? entry.slice(0) : null;
7686
+ }
7687
+ /**
7688
+ * Retrieves the names of the headers.
7689
+ */
7690
+ keys() {
7691
+ return this[kEntries].keys();
7692
+ }
7693
+ /**
7694
+ * Checks for existence of a given header.
7695
+ */
7696
+ has(name) {
7697
+ return this[kEntries].has(name);
7698
+ }
7699
+ /**
7700
+ * Sets or modifies a value for a given header.
7701
+ * If the header already exists, its value is replaced with the given value
7702
+ */
7703
+ set(name, value) {
7704
+ this._set(name, String(value));
7705
+ this.changed();
7706
+ return this;
7707
+ }
7708
+ sort(compareFn) {
7709
+ this[kEntries].sort(compareFn);
7710
+ this.changed();
7711
+ return this;
7712
+ }
7713
+ _append(name, value) {
7714
+ const i = knownKeysLower.indexOf(name);
7715
+ const normalizedName = knownKeys[i] || name;
7716
+ let values = this[kEntries].get(normalizedName);
7717
+ if (!values) {
7718
+ values = [];
7719
+ this[kEntries].set(normalizedName, values);
7720
+ }
7721
+ const oldSize = values.length;
7722
+ if (Array.isArray(value))
7723
+ values.push(...value.map(x => String(x)));
7724
+ else
7725
+ values.push(String(value));
7726
+ this[kSize] = -oldSize + values.length;
7727
+ }
7728
+ _delete(name, value) {
7729
+ const oldValues = this[kEntries].get(name);
7730
+ if (!oldValues)
7731
+ return false;
7732
+ const oldSize = this[kSize];
7733
+ if (value) {
7734
+ const valueToDelete = Array.isArray(value) ? value.map(x => String(x)) : [String(value)];
7735
+ const newValues = oldValues.filter(x => !valueToDelete.includes(x));
7736
+ this[kEntries].set(name, newValues);
7737
+ this[kSize] += -oldValues.length + newValues.length;
7738
+ }
7739
+ else {
7740
+ this[kEntries].delete(name);
7741
+ this[kSize] -= oldValues.length;
7742
+ }
7743
+ return oldSize !== this[kSize];
7744
+ }
7745
+ _set(name, value) {
7746
+ if (value == null) {
7747
+ this._delete(name);
7748
+ return;
7749
+ }
7750
+ const oldValues = this[kEntries].get(name);
7751
+ const i = knownKeysLower.indexOf(name);
7752
+ const normalizedName = knownKeys[i] || name;
7753
+ const newValues = Array.isArray(value) ? value : [value];
7754
+ this[kEntries].set(normalizedName, newValues);
7755
+ this[kSize] += -(oldValues?.length || 0) + newValues.length;
7756
+ }
7757
+ [(_a = kEntries, _b = kSize, nodeInspectCustom)]() {
7758
+ return this[kEntries];
7759
+ }
7760
+ [Symbol.iterator]() {
7761
+ return this.entries();
7762
+ }
7763
+ get [Symbol.toStringTag]() {
7764
+ return 'HttpHeaders';
7765
+ }
7766
+ }
7767
+ HttpHeaders.kEntries = kEntries;
7768
+ HttpHeaders.kSize = kSize;
7769
+ HttpHeaders.kOptions = kOptions;
7770
+
7771
+ /// <reference lib="dom" />
7772
+ const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
7773
+ 'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
7774
+ class HttpRequest {
7775
+ constructor(init) {
7776
+ this.cache = init?.cache || 'default';
7777
+ this.credentials = init?.credentials || 'same-origin';
7778
+ this.destination = init?.destination || '';
7779
+ this.headers = new HttpHeaders(init?.headers);
7780
+ this.integrity = init?.integrity || '';
7781
+ this.keepalive = init?.keepalive ?? false;
7782
+ this.method = (init?.method || 'GET').toUpperCase();
7783
+ this.mode = init?.mode || 'cors';
7784
+ this.redirect = init?.redirect || 'follow';
7785
+ this.mode = init?.mode || 'cors';
7786
+ this.referrer = init?.referrer || '';
7787
+ this.referrerPolicy = init?.referrerPolicy || '';
7788
+ this.signal = init?.signal || new AbortController().signal;
7789
+ this.body = init?.body;
7790
+ this.urlInstance = new OpraURL(init?.url);
7791
+ if (init?.params)
7792
+ this.params.appendAll(init.params);
7793
+ }
7794
+ /** Returns the URL of request as a string. */
7795
+ get url() {
7796
+ return this.urlInstance.href;
7797
+ }
7798
+ set url(value) {
7799
+ this.urlInstance.parse(value);
7800
+ }
7801
+ /** Returns the searchParams of the URL as OpraURLSearchParams */
7802
+ get params() {
7803
+ return this.urlInstance.searchParams;
7804
+ }
7805
+ /** Returns the path part of URL as OpraURLPath */
7806
+ get path() {
7807
+ return this.urlInstance.path;
7808
+ }
7809
+ clone(...update) {
7810
+ const out = new HttpRequest();
7811
+ out.merge(this);
7812
+ for (const upd of update) {
7813
+ out.merge(upd);
7814
+ }
7815
+ return out;
7816
+ }
7817
+ merge(update) {
7818
+ directCopyProperties.forEach(k => {
7819
+ if (update[k] != null)
7820
+ this[k] = update[k];
7821
+ });
7822
+ if (update.headers) {
7823
+ const h = update.headers instanceof HttpHeaders
7824
+ ? update.headers
7825
+ : new HttpHeaders(update.headers);
7826
+ h.forEach((v, k) => {
7827
+ if (k.toLowerCase() === 'set-cookie') {
7828
+ this.headers.append(k, v);
7829
+ }
7830
+ else
7831
+ this.headers.set(k, v);
7832
+ });
7833
+ }
7834
+ }
7835
+ inset(src) {
7836
+ directCopyProperties.forEach(k => {
7837
+ if (this[k] == null && src[k] != null)
7838
+ this[k] = src[k];
7839
+ });
7840
+ if (src.headers) {
7841
+ const h = src.headers instanceof HttpHeaders
7842
+ ? src.headers
7843
+ : new HttpHeaders(src.headers);
7844
+ h.forEach((v, k) => {
7845
+ if (k.toLowerCase() === 'set-cookie') {
7846
+ this.headers.append(k, v);
7847
+ }
7848
+ else if (!this.headers.has(k))
7849
+ this.headers.set(k, v);
7850
+ });
7851
+ }
7852
+ }
7853
+ }
7854
+
7855
+ class HttpResponse {
7856
+ constructor(init) {
7857
+ /**
7858
+ * Returns true if response has body to be received
7859
+ */
7860
+ this.hasBody = false;
7861
+ this.headers = new HttpHeaders(init?.headers);
7862
+ this.status = init?.status || 200;
7863
+ this.statusText = init?.statusText || 'OK';
7864
+ this.url = init?.url || null;
7865
+ this.ok = this.status >= 200 && this.status < 300;
7866
+ this.body = init?.body;
7867
+ this.hasBody = init?.body != null || !!init?.hasBody;
7868
+ }
7869
+ clone(update) {
7870
+ return new HttpResponse({ ...this, ...update });
7871
+ }
7872
+ }
7223
7873
 
7224
7874
  class ClientError extends Error {
7225
7875
  constructor(init, cause) {
@@ -7239,259 +7889,146 @@ const JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
7239
7889
  const TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
7240
7890
  const FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
7241
7891
 
7242
- class HttpRequest extends rxjs.Observable {
7243
- constructor(_handler, options = {}) {
7892
+ const kHandler = Symbol('kHandler');
7893
+ const kRequest = Symbol('kRequest');
7894
+ class HttpRequestHost extends rxjs.Observable {
7895
+ constructor(handler, options) {
7244
7896
  super((subscriber) => {
7245
- if (options.observe === 'response') {
7246
- this.fetch().then(v => {
7247
- subscriber.next(v);
7248
- subscriber.complete();
7249
- }).catch(e => subscriber.error(e));
7250
- return;
7251
- }
7252
- this.resolve().then(v => {
7253
- subscriber.next(v);
7254
- subscriber.complete();
7255
- }).catch(e => subscriber.error(e));
7897
+ handler(options?.observe || 'body', this[kRequest]).subscribe((subscriber));
7256
7898
  });
7257
- this._handler = _handler;
7258
- this.options = options;
7899
+ this[kHandler] = handler;
7900
+ this[kRequest] = new HttpRequest(options?.http);
7259
7901
  this.contentId = uid.uid(6);
7260
- this.options = options;
7261
7902
  }
7262
7903
  header(name, value) {
7263
- this._headers = this._headers || {};
7264
- this._headers[name] = value;
7904
+ this[kRequest].headers.append(name, value);
7265
7905
  return this;
7266
7906
  }
7267
- /**
7268
- * Sends the request
7269
- */
7270
- async fetch() {
7271
- const promise = this._promise || (this._promise = new Promise((resolve, reject) => {
7272
- setTimeout(() => {
7273
- this._execute().then(resolve).catch(reject);
7274
- }, 0);
7275
- }));
7276
- return await promise;
7907
+ param(name, value) {
7908
+ this[kRequest].params.append(name, value);
7909
+ return this;
7277
7910
  }
7278
- /**
7279
- * Sends the request and returns response data
7280
- */
7281
- async resolve() {
7282
- const resp = await this.fetch();
7283
- return resp.data;
7911
+ async fetch(observe) {
7912
+ return rxjs.lastValueFrom(this[kHandler](observe || 'body', this[kRequest]));
7284
7913
  }
7285
7914
  with(cb) {
7286
7915
  cb(this);
7287
7916
  return this;
7288
7917
  }
7289
- binding() {
7290
- return {};
7291
- }
7292
- async _execute() {
7293
- const req = this.prepare();
7294
- return await this._handler(req);
7295
- }
7296
7918
  }
7919
+ HttpRequestHost.kHandler = kHandler;
7920
+ HttpRequestHost.kRequest = kRequest;
7297
7921
 
7298
- function mergeRawHttpRequests(target, ...other) {
7299
- let params;
7300
- const arr = [target, ...other];
7301
- let headers;
7302
- for (let i = arr.length - 1; i >= 0; i--) {
7303
- const o = arr[i];
7304
- if (o?.headers) {
7305
- headers = headers || {};
7306
- Object.assign(headers, normalizeHeaders(o.headers));
7307
- }
7308
- }
7309
- for (const o of arr) {
7310
- if (!o)
7311
- continue;
7312
- Object.assign(target, o);
7313
- if (o?.params) {
7314
- params = params || new OpraURLSearchParams();
7315
- o.params.forEach((v, n) => params?.append(n, v));
7316
- }
7317
- }
7318
- target.headers = headers;
7319
- target.params = params;
7320
- return target;
7321
- }
7322
-
7323
- class CollectionCreateRequest extends HttpRequest {
7324
- constructor(_handler, resource, data, options = {}) {
7325
- super(_handler, options);
7326
- this._handler = _handler;
7327
- this.resource = resource;
7328
- this.data = data;
7329
- this.options = options;
7330
- }
7331
- prepare() {
7332
- const searchParams = new OpraURLSearchParams();
7333
- if (this.options.include)
7334
- searchParams.set('$include', this.options.include);
7335
- if (this.options.pick)
7336
- searchParams.set('$pick', this.options.pick);
7337
- if (this.options.omit)
7338
- searchParams.set('$omit', this.options.omit);
7339
- return mergeRawHttpRequests({
7340
- method: 'POST',
7341
- path: this.resource.name,
7342
- params: searchParams,
7343
- body: this.data,
7344
- }, this.options.http);
7345
- }
7346
- }
7347
-
7348
- class CollectionDeleteManyRequest extends HttpRequest {
7349
- constructor(_handler, resource, options = {}) {
7350
- super(_handler, options);
7351
- this._handler = _handler;
7922
+ class CollectionCreateRequest extends HttpRequestHost {
7923
+ constructor(handler, resource, data, options) {
7924
+ super(handler, options);
7352
7925
  this.resource = resource;
7353
- this.options = options;
7354
- }
7355
- prepare() {
7356
- const searchParams = new OpraURLSearchParams();
7357
- if (this.options.filter)
7358
- searchParams.set('$filter', this.options.filter);
7359
- return mergeRawHttpRequests({
7360
- method: 'DELETE',
7361
- path: this.resource.name,
7362
- params: searchParams,
7363
- }, this.options.http);
7926
+ const request = this[HttpRequestHost.kRequest];
7927
+ request.method = 'POST';
7928
+ request.url = this.resource.name;
7929
+ request.body = data;
7930
+ if (options?.include)
7931
+ request.params.set('$include', options.include);
7932
+ if (options?.pick)
7933
+ request.params.set('$pick', options.pick);
7934
+ if (options?.omit)
7935
+ request.params.set('$omit', options.omit);
7364
7936
  }
7365
7937
  }
7366
7938
 
7367
- class CollectionDeleteRequest extends HttpRequest {
7368
- constructor(_handler, resource, keyValue, options = {}) {
7369
- super(_handler, options);
7370
- this._handler = _handler;
7939
+ class CollectionDeleteManyRequest extends HttpRequestHost {
7940
+ constructor(handler, resource, options) {
7941
+ super(handler, options);
7371
7942
  this.resource = resource;
7372
- this.keyValue = keyValue;
7373
- this.options = options;
7374
- }
7375
- prepare() {
7376
- if (this.keyValue == null || this.keyValue === '')
7377
- throw new TypeError('Key value required to perform "delete" request');
7378
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
7379
- return mergeRawHttpRequests({
7380
- method: 'DELETE',
7381
- path: path.toString(),
7382
- }, this.options.http);
7943
+ const request = this[HttpRequestHost.kRequest];
7944
+ request.method = 'DELETE';
7945
+ request.url = this.resource.name;
7946
+ if (options?.filter)
7947
+ request.params.set('$filter', options.filter);
7383
7948
  }
7384
7949
  }
7385
7950
 
7386
- class CollectionGetRequest extends HttpRequest {
7387
- constructor(_handler, resource, keyValue, options = {}) {
7388
- super(_handler, options);
7389
- this._handler = _handler;
7951
+ class CollectionDeleteRequest extends HttpRequestHost {
7952
+ constructor(handler, resource, id, options) {
7953
+ super(handler, options);
7390
7954
  this.resource = resource;
7391
- this.keyValue = keyValue;
7392
- this.options = options;
7393
- }
7394
- prepare() {
7395
- if (this.keyValue == null || this.keyValue === '')
7396
- throw new TypeError('Key value required to perform "get" request');
7397
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
7398
- const searchParams = new OpraURLSearchParams();
7399
- if (this.options.include)
7400
- searchParams.set('$include', this.options.include);
7401
- if (this.options.pick)
7402
- searchParams.set('$pick', this.options.pick);
7403
- if (this.options.omit)
7404
- searchParams.set('$omit', this.options.omit);
7405
- return mergeRawHttpRequests({
7406
- method: 'GET',
7407
- path: path.toString(),
7408
- params: searchParams
7409
- }, this.options.http);
7955
+ const request = this[HttpRequestHost.kRequest];
7956
+ request.method = 'DELETE';
7957
+ request.path.join({ resource: this.resource.name, key: id });
7410
7958
  }
7411
7959
  }
7412
7960
 
7413
- class CollectionSearchRequest extends HttpRequest {
7414
- constructor(_handler, resource, options = {}) {
7415
- super(_handler, options);
7416
- this._handler = _handler;
7961
+ class CollectionGetRequest extends HttpRequestHost {
7962
+ constructor(handler, resource, id, options) {
7963
+ super(handler, options);
7417
7964
  this.resource = resource;
7418
- this.options = options;
7419
- }
7420
- prepare() {
7421
- const searchParams = new OpraURLSearchParams();
7422
- if (this.options.include)
7423
- searchParams.set('$include', this.options.include);
7424
- if (this.options.pick)
7425
- searchParams.set('$pick', this.options.pick);
7426
- if (this.options.omit)
7427
- searchParams.set('$omit', this.options.omit);
7428
- if (this.options.sort)
7429
- searchParams.set('$sort', this.options.sort);
7430
- if (this.options.filter)
7431
- searchParams.set('$filter', this.options.filter);
7432
- if (this.options.limit != null)
7433
- searchParams.set('$limit', this.options.limit);
7434
- if (this.options.skip != null)
7435
- searchParams.set('$skip', this.options.skip);
7436
- if (this.options.count != null)
7437
- searchParams.set('$count', this.options.count);
7438
- if (this.options.distinct != null)
7439
- searchParams.set('$distinct', this.options.distinct);
7440
- return mergeRawHttpRequests({
7441
- method: 'GET',
7442
- path: this.resource.name,
7443
- params: searchParams
7444
- }, this.options.http);
7965
+ const request = this[HttpRequestHost.kRequest];
7966
+ request.method = 'GET';
7967
+ request.path.join({ resource: this.resource.name, key: id });
7968
+ if (options?.include)
7969
+ request.params.set('$include', options.include);
7970
+ if (options?.pick)
7971
+ request.params.set('$pick', options.pick);
7972
+ if (options?.omit)
7973
+ request.params.set('$omit', options.omit);
7445
7974
  }
7446
7975
  }
7447
7976
 
7448
- class CollectionUpdateManyRequest extends HttpRequest {
7449
- constructor(_handler, resource, data, options = {}) {
7450
- super(_handler, options);
7451
- this._handler = _handler;
7977
+ class CollectionSearchRequest extends HttpRequestHost {
7978
+ constructor(handler, resource, options) {
7979
+ super(handler, options);
7452
7980
  this.resource = resource;
7453
- this.data = data;
7454
- this.options = options;
7455
- }
7456
- prepare() {
7457
- const searchParams = new OpraURLSearchParams();
7458
- if (this.options.filter)
7459
- searchParams.set('$filter', this.options.filter);
7460
- return mergeRawHttpRequests({
7461
- method: 'PATCH',
7462
- path: this.resource.name,
7463
- params: searchParams,
7464
- body: this.data
7465
- }, this.options.http);
7981
+ const request = this[HttpRequestHost.kRequest];
7982
+ request.method = 'GET';
7983
+ request.url = this.resource.name;
7984
+ if (options?.include)
7985
+ request.params.set('$include', options.include);
7986
+ if (options?.pick)
7987
+ request.params.set('$pick', options.pick);
7988
+ if (options?.omit)
7989
+ request.params.set('$omit', options.omit);
7990
+ if (options?.sort)
7991
+ request.params.set('$sort', options.sort);
7992
+ if (options?.filter)
7993
+ request.params.set('$filter', options.filter);
7994
+ if (options?.limit != null)
7995
+ request.params.set('$limit', options.limit);
7996
+ if (options?.skip != null)
7997
+ request.params.set('$skip', options.skip);
7998
+ if (options?.count != null)
7999
+ request.params.set('$count', options.count);
8000
+ if (options?.distinct != null)
8001
+ request.params.set('$distinct', options.distinct);
8002
+ }
8003
+ }
8004
+
8005
+ class CollectionUpdateManyRequest extends HttpRequestHost {
8006
+ constructor(handler, resource, data, options) {
8007
+ super(handler, options);
8008
+ this.resource = resource;
8009
+ const request = this[HttpRequestHost.kRequest];
8010
+ request.method = 'PATCH';
8011
+ request.url = this.resource.name;
8012
+ request.body = data;
8013
+ if (options?.filter)
8014
+ request.params.set('$filter', options.filter);
7466
8015
  }
7467
8016
  }
7468
8017
 
7469
- class CollectionUpdateRequest extends HttpRequest {
7470
- constructor(_handler, resource, keyValue, data, options = {}) {
7471
- super(_handler, options);
7472
- this._handler = _handler;
8018
+ class CollectionUpdateRequest extends HttpRequestHost {
8019
+ constructor(handler, resource, id, data, options) {
8020
+ super(handler, options);
7473
8021
  this.resource = resource;
7474
- this.keyValue = keyValue;
7475
- this.data = data;
7476
- this.options = options;
7477
- }
7478
- prepare() {
7479
- if (this.keyValue == null || this.keyValue === '')
7480
- throw new TypeError('Key value required to perform "get" request');
7481
- const path = new OpraURLPath({ resource: this.resource.name, key: this.keyValue });
7482
- const searchParams = new OpraURLSearchParams();
7483
- if (this.options.include)
7484
- searchParams.set('$include', this.options.include);
7485
- if (this.options.pick)
7486
- searchParams.set('$pick', this.options.pick);
7487
- if (this.options.omit)
7488
- searchParams.set('$omit', this.options.omit);
7489
- return mergeRawHttpRequests({
7490
- method: 'PATCH',
7491
- path: path.toString(),
7492
- params: searchParams,
7493
- body: this.data
7494
- }, this.options.http);
8022
+ const request = this[HttpRequestHost.kRequest];
8023
+ request.method = 'PATCH';
8024
+ request.path.join({ resource: this.resource.name, key: id });
8025
+ request.body = data;
8026
+ if (options?.include)
8027
+ request.params.set('$include', options.include);
8028
+ if (options?.pick)
8029
+ request.params.set('$pick', options.pick);
8030
+ if (options?.omit)
8031
+ request.params.set('$omit', options.omit);
7495
8032
  }
7496
8033
  }
7497
8034
 
@@ -7503,133 +8040,68 @@ class HttpCollectionService {
7503
8040
  create(data, options) {
7504
8041
  return new CollectionCreateRequest(this._handler, this.resource, data, options);
7505
8042
  }
7506
- delete(keyValue, options) {
7507
- return new CollectionDeleteRequest(this._handler, this.resource, keyValue, options);
8043
+ delete(id, options) {
8044
+ return new CollectionDeleteRequest(this._handler, this.resource, id, options);
7508
8045
  }
7509
8046
  deleteMany(options) {
7510
8047
  return new CollectionDeleteManyRequest(this._handler, this.resource, options);
7511
8048
  }
7512
- get(keyValue, options) {
7513
- return new CollectionGetRequest(this._handler, this.resource, keyValue, options);
8049
+ get(id, options) {
8050
+ return new CollectionGetRequest(this._handler, this.resource, id, options);
7514
8051
  }
7515
8052
  search(options) {
7516
8053
  return new CollectionSearchRequest(this._handler, this.resource, options);
7517
8054
  }
7518
- update(keyValue, data, options) {
7519
- return new CollectionUpdateRequest(this._handler, this.resource, keyValue, data, options);
8055
+ update(id, data, options) {
8056
+ return new CollectionUpdateRequest(this._handler, this.resource, id, data, options);
7520
8057
  }
7521
8058
  updateMany(data, options) {
7522
8059
  return new CollectionUpdateManyRequest(this._handler, this.resource, data, options);
7523
8060
  }
7524
8061
  }
7525
8062
 
7526
- class HttpSingletonGetRequest extends HttpRequest {
7527
- constructor(_handler, resource, options = {}) {
7528
- super(_handler, options);
7529
- this._handler = _handler;
8063
+ class SingletonDeleteRequest extends HttpRequestHost {
8064
+ constructor(handler, resource, options) {
8065
+ super(handler, options);
7530
8066
  this.resource = resource;
7531
- this.options = options;
7532
- }
7533
- prepare() {
7534
- const searchParams = new URLSearchParams();
7535
- if (this.options.include)
7536
- searchParams.set('$include', '' + this.options.include);
7537
- if (this.options.pick)
7538
- searchParams.set('$pick', '' + this.options.pick);
7539
- if (this.options.omit)
7540
- searchParams.set('$omit', '' + this.options.omit);
7541
- return mergeRawHttpRequests({
7542
- method: 'GET',
7543
- path: this.resource.name,
7544
- params: searchParams
7545
- }, this.options.http);
8067
+ const request = this[HttpRequestHost.kRequest];
8068
+ request.method = 'DELETE';
8069
+ request.url = this.resource.name;
7546
8070
  }
7547
8071
  }
7548
8072
 
7549
- class HttpSingletonService {
7550
- constructor(resource, _handler) {
8073
+ class SingletonGetRequest extends HttpRequestHost {
8074
+ constructor(handler, resource, options) {
8075
+ super(handler, options);
7551
8076
  this.resource = resource;
7552
- this._handler = _handler;
7553
- }
7554
- get(options) {
7555
- return new HttpSingletonGetRequest(this._handler, this.resource, options);
8077
+ const request = this[HttpRequestHost.kRequest];
8078
+ request.method = 'GET';
8079
+ request.url = this.resource.name;
8080
+ if (options?.include)
8081
+ request.params.set('$include', options.include);
8082
+ if (options?.pick)
8083
+ request.params.set('$pick', options.pick);
8084
+ if (options?.omit)
8085
+ request.params.set('$omit', options.omit);
7556
8086
  }
7557
8087
  }
7558
8088
 
7559
- class BatchRequest extends HttpRequest {
7560
- constructor(_handler, requests, options = {}) {
7561
- super(_handler, options);
8089
+ class HttpSingletonService {
8090
+ constructor(resource, _handler) {
8091
+ this.resource = resource;
7562
8092
  this._handler = _handler;
7563
- this.requests = requests;
7564
- this.options = options;
7565
- this._results = new WeakMap();
7566
- this._listeners = new Set();
7567
- requests.forEach(request => {
7568
- // Overwrite the _execute method
7569
- Object.defineProperty(request, '_execute', {
7570
- writable: true,
7571
- enumerable: false,
7572
- configurable: true,
7573
- value: () => {
7574
- return new Promise((resolve, reject) => {
7575
- const x = this._results.get(request);
7576
- if (x) {
7577
- if (x.error)
7578
- return reject(x.error);
7579
- return resolve(x.response);
7580
- }
7581
- const callback = (error, response) => {
7582
- this._listeners.delete(callback);
7583
- if (error)
7584
- return reject(error);
7585
- resolve(response);
7586
- };
7587
- this._listeners.add(callback);
7588
- });
7589
- }
7590
- });
7591
- });
7592
8093
  }
7593
- prepare() {
7594
- const batch = this._buildBatchMultipart(this);
7595
- const headers = {
7596
- 'content-type': 'multipart/mixed;boundary=' + batch.boundary
7597
- };
7598
- return mergeRawHttpRequests({
7599
- method: 'POST',
7600
- path: '/$batch',
7601
- headers,
7602
- body: batch.stream()
7603
- }, this.options.http);
7604
- }
7605
- _buildBatchMultipart(batch) {
7606
- const multipart = new BatchMultipart();
7607
- for (const req of batch.requests) {
7608
- const prepared = req.prepare();
7609
- if (req instanceof BatchRequest) {
7610
- const subMultipart = this._buildBatchMultipart(req);
7611
- multipart.addBatch(subMultipart);
7612
- continue;
7613
- }
7614
- multipart.addRequestPart({
7615
- method: prepared.method,
7616
- url: prepared.path,
7617
- headers: prepared.headers,
7618
- data: prepared.body
7619
- });
7620
- }
7621
- return multipart;
8094
+ get(options) {
8095
+ return new SingletonGetRequest(this._handler, this.resource, options);
7622
8096
  }
7623
- async _execute() {
7624
- const req = this.prepare();
7625
- const resp = await this._handler(req);
7626
- return resp;
8097
+ delete(options) {
8098
+ return new SingletonDeleteRequest(this._handler, this.resource, options);
7627
8099
  }
7628
8100
  }
7629
8101
 
7630
8102
  const documentCache = new Map();
7631
8103
  const documentResolverCaches = new Map();
7632
- class OpraHttpClient {
8104
+ class OpraHttpClientBase {
7633
8105
  constructor(serviceUrl, options) {
7634
8106
  this._serviceUrl = serviceUrl;
7635
8107
  this._metadata = options?.document;
@@ -7638,7 +8110,13 @@ class OpraHttpClient {
7638
8110
  if (document)
7639
8111
  this._metadata = document;
7640
8112
  }
7641
- this.defaults = options?.defaults || {};
8113
+ this.defaults = {
8114
+ ...options?.defaults,
8115
+ headers: options?.defaults?.headers instanceof HttpHeaders
8116
+ ? options?.defaults?.headers : new HttpHeaders(options?.defaults?.headers),
8117
+ params: options?.defaults?.params instanceof HttpParams
8118
+ ? options?.defaults?.params : new HttpParams(options?.defaults?.headers)
8119
+ };
7642
8120
  }
7643
8121
  get serviceUrl() {
7644
8122
  return this._serviceUrl;
@@ -7663,20 +8141,23 @@ class OpraHttpClient {
7663
8141
  promise = this._resolveMetadata();
7664
8142
  documentResolverCaches.set(cacheName, promise);
7665
8143
  return promise
7666
- .catch(() => void 0)
8144
+ .catch((e) => {
8145
+ // @ts-ignore
8146
+ throw new Error('Unable to fetch metadata from ' + this.serviceUrl, e);
8147
+ })
7667
8148
  .finally(() => documentResolverCaches.delete(cacheName));
7668
8149
  }
7669
- batch(requests) {
7670
- this._assertMetadata();
7671
- return new BatchRequest(req => this._handleRequest(req), requests);
7672
- }
8150
+ // batch(requests: HttpRequestHost<any>[]): BatchRequest {
8151
+ // this._assertMetadata();
8152
+ // return new BatchRequest(request => this._sendRequest('response', request, requests);
8153
+ // }
7673
8154
  collection(name) {
7674
8155
  this._assertMetadata();
7675
8156
  // If name argument is a class, we extract name from the class
7676
8157
  if (typeof name === 'function')
7677
8158
  name = name.name;
7678
8159
  const resource = this.metadata.getCollectionResource(name);
7679
- return new HttpCollectionService(resource, req => this._handleRequest(req));
8160
+ return new HttpCollectionService(resource, this._sendRequest.bind(this));
7680
8161
  }
7681
8162
  singleton(name) {
7682
8163
  this._assertMetadata();
@@ -7684,87 +8165,138 @@ class OpraHttpClient {
7684
8165
  if (typeof name === 'function')
7685
8166
  name = name.name;
7686
8167
  const resource = this.metadata.getSingletonResource(name);
7687
- return new HttpSingletonService(resource, req => this._handleRequest(req));
8168
+ return new HttpSingletonService(resource, this._sendRequest.bind(this));
7688
8169
  }
7689
8170
  async _resolveMetadata() {
7690
- const resp = await this._handleRequest({
8171
+ const body = await rxjs.lastValueFrom(this._sendRequest('body', new HttpRequest({
7691
8172
  method: 'GET',
7692
- path: '/$metadata',
7693
- headers: { 'accept': 'application/json' }
7694
- });
7695
- this._metadata = new OpraDocument(resp.data);
7696
- }
7697
- async _handleRequest(req) {
7698
- mergeRawHttpRequests(req, this.defaults);
7699
- let url = joinPath(this.serviceUrl, req.path);
7700
- if (req.params)
7701
- url += '?' + req.params.toString();
7702
- if (req.body) {
7703
- if (typeof req.body === 'object') {
7704
- if (!(isReadable(req.body) || isReadableStream(req.body) || buffer.Buffer.isBuffer(req.body))) {
7705
- if (!req.headers?.['content-type']) {
7706
- req.headers = req.headers || {};
7707
- req.headers['content-type'] = 'application/json';
8173
+ url: '$metadata',
8174
+ headers: new HttpHeaders({ 'accept': 'application/json' })
8175
+ })));
8176
+ this._metadata = new OpraDocument(body);
8177
+ }
8178
+ _sendRequest(observe, request) {
8179
+ return new rxjs.Observable(subscriber => {
8180
+ try {
8181
+ request.inset(this.defaults);
8182
+ const url = request.url.includes('://') ? request.url : joinPath(this.serviceUrl, request.url);
8183
+ let body;
8184
+ if (request.body) {
8185
+ let contentType = request.headers.get('Content-Type');
8186
+ if (typeof request.body === 'string' || typeof request.body === 'number' || typeof request.body === 'boolean') {
8187
+ contentType = 'text/plain;charset=UTF-8"';
8188
+ body = String(request.body);
8189
+ request.headers.delete('Content-Size');
8190
+ delete request.duplex;
8191
+ }
8192
+ else if (isReadableStreamLike(request.body)) {
8193
+ contentType = 'application/octet-stream';
8194
+ body = request.body;
8195
+ request.duplex = 'half';
8196
+ }
8197
+ else if (isReadable(request.body)) {
8198
+ contentType = 'application/octet-stream';
8199
+ body = stream.Readable.toWeb(request.body);
8200
+ request.duplex = 'half';
7708
8201
  }
7709
- req.body = JSON.stringify(req.body);
8202
+ else if (buffer.Buffer.isBuffer(request.body)) {
8203
+ contentType = 'application/octet-stream';
8204
+ body = request.body;
8205
+ request.headers.set('Content-Size', request.body.length);
8206
+ delete request.duplex;
8207
+ }
8208
+ else if (isBlob(request.body)) {
8209
+ contentType = request.body.type || 'application/octet-stream';
8210
+ body = request.body;
8211
+ request.headers.set('Content-Size', request.body.length);
8212
+ delete request.duplex;
8213
+ }
8214
+ else {
8215
+ contentType = 'application/json';
8216
+ body = JSON.stringify(request.body);
8217
+ request.headers.delete('Content-Size');
8218
+ delete request.duplex;
8219
+ }
8220
+ if (!request.headers.has('Content-Type') && contentType)
8221
+ request.headers.set('Content-Type', contentType);
8222
+ request.body = body;
7710
8223
  }
8224
+ this._fetch(url, request)
8225
+ .then(response => this._handleResponse(observe, subscriber, request, response))
8226
+ .catch(error => subscriber.error(error));
8227
+ if (observe === 'events')
8228
+ subscriber.next({ event: 'sent', request });
7711
8229
  }
7712
- }
7713
- return this._fetch(url, req);
7714
- }
7715
- async _fetch(url, req) {
7716
- const resp = await fetch(url, req);
7717
- let data;
7718
- if (resp.body) {
7719
- if (JSON_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || '')) {
7720
- data = await resp.json();
7721
- if (typeof data === 'string')
7722
- data = JSON.parse(data);
8230
+ catch (error) {
8231
+ subscriber.error(error);
7723
8232
  }
7724
- else if (TEXT_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
7725
- data = await resp.text();
7726
- else if (FORMDATA_CONTENT_TYPE_PATTERN.test(resp.headers.get('Content-Type') || ''))
7727
- data = await resp.formData();
7728
- else
7729
- data = await resp.arrayBuffer();
7730
- }
7731
- if (resp.status >= 400 && resp.status < 600) {
7732
- throw new ClientError({
7733
- message: resp.status + ' ' + resp.statusText,
7734
- status: resp.status,
7735
- issues: data?.errors
8233
+ });
8234
+ }
8235
+ _fetch(url, init = {}) {
8236
+ return fetch(url, init);
8237
+ }
8238
+ _createResponse(init) {
8239
+ return new HttpResponse(init);
8240
+ }
8241
+ _handleResponse(observe, subscriber, request, fetchResponse) {
8242
+ const headers = new HttpHeaders(fetchResponse.headers);
8243
+ if (observe === 'events') {
8244
+ const response = this._createResponse({
8245
+ url: fetchResponse.url,
8246
+ headers,
8247
+ status: fetchResponse.status,
8248
+ statusText: fetchResponse.statusText,
8249
+ hasBody: !!fetchResponse.body
7736
8250
  });
8251
+ subscriber.next({ event: 'headers-received', request, response });
7737
8252
  }
7738
- const out = {
7739
- get headers() {
7740
- return resp.headers;
7741
- },
7742
- get ok() {
7743
- return resp.ok;
7744
- },
7745
- get redirected() {
7746
- return resp.redirected;
7747
- },
7748
- get status() {
7749
- return resp.status;
7750
- },
7751
- get statusText() {
7752
- return resp.statusText;
7753
- },
7754
- get type() {
7755
- return resp.type;
7756
- },
7757
- get url() {
7758
- return resp.url;
7759
- },
7760
- get contentId() {
7761
- return resp.headers.get('Content-ID');
7762
- },
7763
- get data() {
7764
- return data;
8253
+ Promise
8254
+ .resolve(fetchResponse.body)
8255
+ .then(async (inputStream) => {
8256
+ if (!inputStream)
8257
+ return;
8258
+ if (JSON_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || '')) {
8259
+ const body = await fetchResponse.json();
8260
+ if (typeof body === 'string')
8261
+ return JSON.parse(body);
8262
+ return body;
7765
8263
  }
7766
- };
7767
- return out;
8264
+ if (TEXT_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
8265
+ return await fetchResponse.text();
8266
+ if (FORMDATA_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
8267
+ return await fetchResponse.formData();
8268
+ const buf = await fetchResponse.arrayBuffer();
8269
+ return buf.byteLength ? buf : undefined;
8270
+ })
8271
+ .then(body => {
8272
+ if (fetchResponse.status >= 400 && fetchResponse.status < 600) {
8273
+ subscriber.error(new ClientError({
8274
+ message: fetchResponse.status + ' ' + fetchResponse.statusText,
8275
+ status: fetchResponse.status,
8276
+ issues: body?.errors
8277
+ }));
8278
+ subscriber.complete();
8279
+ return;
8280
+ }
8281
+ if (observe === 'body') {
8282
+ subscriber.next(body);
8283
+ }
8284
+ else {
8285
+ const response = this._createResponse({
8286
+ url: fetchResponse.url,
8287
+ headers,
8288
+ status: fetchResponse.status,
8289
+ statusText: fetchResponse.statusText,
8290
+ body
8291
+ });
8292
+ if (observe === 'events')
8293
+ subscriber.next({ event: 'response', request, response });
8294
+ else
8295
+ subscriber.next(response);
8296
+ }
8297
+ subscriber.complete();
8298
+ })
8299
+ .catch(error => subscriber.error(error));
7768
8300
  }
7769
8301
  _assertMetadata() {
7770
8302
  if (!this._metadata)
@@ -7777,6 +8309,8 @@ class OpraHttpClient {
7777
8309
  return client;
7778
8310
  }
7779
8311
  }
8312
+ class OpraHttpClient extends OpraHttpClientBase {
8313
+ }
7780
8314
 
7781
8315
  Object.defineProperty(exports, 'uid', {
7782
8316
  enumerable: true,
@@ -7810,7 +8344,7 @@ exports.Ast = Ast;
7810
8344
  exports.BadRequestError = BadRequestError;
7811
8345
  exports.BaseI18n = BaseI18n;
7812
8346
  exports.BatchMultipart = BatchMultipart;
7813
- exports.BatchRequest = BatchRequest;
8347
+ exports.BooleanCodec = BooleanCodec;
7814
8348
  exports.BooleanLiteral = BooleanLiteral;
7815
8349
  exports.COMPLEXTYPE_FIELDS = COMPLEXTYPE_FIELDS;
7816
8350
  exports.ClientError = ClientError;
@@ -7835,18 +8369,27 @@ exports.ComplexType = ComplexType;
7835
8369
  exports.ContainerResourceInfo = ContainerResourceInfo;
7836
8370
  exports.DATATYPE_METADATA = DATATYPE_METADATA;
7837
8371
  exports.DataType = DataType;
8372
+ exports.DateCodec = DateCodec;
7838
8373
  exports.DateLiteral = DateLiteral;
7839
8374
  exports.DocumentBuilder = DocumentBuilder;
7840
8375
  exports.Expression = Expression;
7841
8376
  exports.FailedDependencyError = FailedDependencyError;
7842
8377
  exports.FieldGetQuery = FieldGetQuery;
8378
+ exports.FilterCodec = FilterCodec;
7843
8379
  exports.FilterTreeVisitor = FilterTreeVisitor;
7844
8380
  exports.ForbiddenError = ForbiddenError;
7845
8381
  exports.HttpCollectionService = HttpCollectionService;
7846
- exports.HttpSingletonGetRequest = HttpSingletonGetRequest;
8382
+ exports.HttpHeaders = HttpHeaders;
8383
+ exports.HttpParamCodec = HttpParamCodec;
8384
+ exports.HttpParams = HttpParams;
8385
+ exports.HttpRequest = HttpRequest;
8386
+ exports.HttpRequestHost = HttpRequestHost;
8387
+ exports.HttpRequestNode = HttpRequestNode;
8388
+ exports.HttpResponse = HttpResponse;
7847
8389
  exports.HttpSingletonService = HttpSingletonService;
7848
8390
  exports.I18n = I18n;
7849
8391
  exports.IGNORE_RESOLVER_METHOD = IGNORE_RESOLVER_METHOD;
8392
+ exports.IntegerCodec = IntegerCodec;
7850
8393
  exports.InternalServerError = InternalServerError;
7851
8394
  exports.Literal = Literal;
7852
8395
  exports.LogicalExpression = LogicalExpression;
@@ -7856,6 +8399,7 @@ exports.MixinType = MixinType;
7856
8399
  exports.NotAcceptableError = NotAcceptableError;
7857
8400
  exports.NotFoundError = NotFoundError;
7858
8401
  exports.NullLiteral = NullLiteral;
8402
+ exports.NumberCodec = NumberCodec;
7859
8403
  exports.NumberLiteral = NumberLiteral;
7860
8404
  exports.OmitType = OmitType;
7861
8405
  exports.OprCollectionResource = OprCollectionResource;
@@ -7873,6 +8417,7 @@ exports.OpraDocument = OpraDocument;
7873
8417
  exports.OpraErrorListener = OpraErrorListener;
7874
8418
  exports.OpraException = OpraException;
7875
8419
  exports.OpraHttpClient = OpraHttpClient;
8420
+ exports.OpraHttpClientBase = OpraHttpClientBase;
7876
8421
  exports.OpraURL = OpraURL;
7877
8422
  exports.OpraURLPath = OpraURLPath;
7878
8423
  exports.OpraURLPathComponent = OpraURLPathComponent;
@@ -7887,8 +8432,11 @@ exports.ResourceInfo = ResourceInfo;
7887
8432
  exports.ResourceNotFoundError = ResourceNotFoundError;
7888
8433
  exports.ResponsiveMap = ResponsiveMap;
7889
8434
  exports.SimpleType = SimpleType;
8435
+ exports.SingletonDeleteRequest = SingletonDeleteRequest;
7890
8436
  exports.SingletonGetQuery = SingletonGetQuery;
8437
+ exports.SingletonGetRequest = SingletonGetRequest;
7891
8438
  exports.SingletonResourceInfo = SingletonResourceInfo;
8439
+ exports.StringCodec = StringCodec;
7892
8440
  exports.StringLiteral = StringLiteral;
7893
8441
  exports.Term = Term;
7894
8442
  exports.TimeLiteral = TimeLiteral;