@opra/client 0.11.8 → 0.12.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.
- package/cjs/index.min.mjs +1572 -1046
- package/esm/index.min.mjs +1558 -1046
- package/package.json +11 -11
- package/typings/common/filter/antlr/OpraFilterLexer.d.ts +1 -1
- package/typings/common/filter/antlr/OpraFilterListener.d.ts +1 -1
- package/typings/common/filter/ast/expressions/arithmetic-expression.d.ts +1 -1
- package/typings/common/filter/ast/expressions/comparison-expression.d.ts +1 -1
- package/typings/common/filter/ast/expressions/logical-expression.d.ts +1 -1
- package/typings/common/filter/build.d.ts +3 -3
- package/typings/common/filter/errors.d.ts +2 -0
- package/typings/common/filter/filter-tree-visitor.d.ts +2 -1
- package/typings/common/helpers/responsive-map.d.ts +19 -5
- package/typings/common/http/enums/{http-headers.enum.d.ts → http-headers-codes.enum.d.ts} +1 -1
- package/typings/common/http/enums/{http-status.enum.d.ts → http-status-codes.enum.d.ts} +1 -1
- package/typings/common/http/http-headers.d.ts +70 -0
- package/typings/common/http/http-param-codec.d.ts +4 -0
- package/typings/common/http/http-params.d.ts +99 -0
- package/typings/common/http/http-request-node.d.ts +34 -0
- package/typings/common/http/http-request.d.ts +73 -31
- package/typings/common/http/http-response.d.ts +41 -0
- package/typings/common/http/index.d.ts +13 -2
- package/typings/common/http/interfaces/client-http-headers.interface.d.ts +1 -1
- package/typings/common/http/interfaces/server-http-headers.interface.d.ts +1 -1
- package/typings/common/http/multipart/batch-multipart.d.ts +1 -1
- package/typings/common/http/multipart/http-request-content.d.ts +1 -1
- package/typings/common/http/multipart/http-response-content.d.ts +1 -1
- package/typings/common/http/param-codec/boolean-codec.d.ts +5 -0
- package/typings/common/http/param-codec/date-codec.d.ts +16 -0
- package/typings/common/http/param-codec/filter-codec.d.ts +6 -0
- package/typings/common/http/param-codec/integer-codec.d.ts +9 -0
- package/typings/common/http/param-codec/number-codec.d.ts +12 -0
- package/typings/common/http/param-codec/string-codec.d.ts +14 -0
- package/typings/common/http/utils/encodeURIParam.d.ts +1 -0
- package/typings/common/i18n/i18n.d.ts +6 -6
- package/typings/common/schema/decorators/opr-collection-resource.decorator.d.ts +1 -1
- package/typings/common/schema/decorators/opr-complex-type.decorator.d.ts +1 -1
- package/typings/common/schema/decorators/opr-simple-type.decorator.d.ts +1 -1
- package/typings/common/schema/decorators/opr-singleton-resource.decorator.d.ts +1 -1
- package/typings/common/schema/implementation/data-type/complex-type.d.ts +1 -1
- package/typings/common/schema/implementation/data-type/union-type.d.ts +1 -1
- package/typings/common/schema/implementation/document-builder.d.ts +1 -1
- package/typings/common/schema/implementation/opra-document.d.ts +2 -2
- package/typings/common/schema/implementation/query/collection-count-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-create-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-delete-many-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-get-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-search-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-update-many-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/collection-update-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/field-get-query.d.ts +1 -1
- package/typings/common/schema/implementation/query/index.d.ts +4 -4
- package/typings/common/schema/implementation/query/singleton-get-query.d.ts +1 -1
- package/typings/common/schema/implementation/resource/collection-resource-info.d.ts +2 -0
- package/typings/common/schema/interfaces/data-type.metadata.d.ts +4 -4
- package/typings/common/schema/interfaces/resource.metadata.d.ts +9 -9
- package/typings/common/schema/types.d.ts +8 -8
- package/typings/common/url/opra-url-path-component.d.ts +1 -1
- package/typings/common/url/opra-url-path.d.ts +24 -18
- package/typings/common/url/opra-url-search-params.d.ts +3 -42
- package/typings/common/url/opra-url.d.ts +38 -28
- package/typings/http/http-client.d.ts +30 -13
- package/typings/http/http-collection-service.d.ts +67 -13
- package/typings/http/http-request-host.d.ts +18 -0
- package/typings/http/http-singleton-service.d.ts +24 -6
- package/typings/http/http-types.d.ts +44 -21
- package/typings/http/requests/batch-request.d.ts +0 -18
- package/typings/http/requests/collection-create-request.d.ts +5 -10
- package/typings/http/requests/collection-delete-many-request.d.ts +5 -9
- package/typings/http/requests/collection-delete-request.d.ts +5 -10
- package/typings/http/requests/collection-get-request.d.ts +5 -10
- package/typings/http/requests/collection-search-request.d.ts +5 -9
- package/typings/http/requests/collection-update-many-request.d.ts +5 -10
- package/typings/http/requests/collection-update-request.d.ts +5 -11
- package/typings/http/requests/singleton-create-request.d.ts +7 -0
- package/typings/http/requests/singleton-delete-request.d.ts +7 -0
- package/typings/http/requests/singleton-get-request.d.ts +7 -0
- package/typings/index.d.ts +3 -4
- package/typings/interfaces/http-options.interface.d.ts +1 -1
- package/typings/interfaces/http-request-config.interface.d.ts +1 -1
- package/typings/http/http-request.d.ts +0 -25
- package/typings/http/http-response.d.ts +0 -14
- package/typings/http/requests/http-singleton-get-request.d.ts +0 -11
- 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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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.
|
|
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
|
|
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.
|
|
3800
|
-
(function (
|
|
3811
|
+
exports.HttpHeaderCodes = void 0;
|
|
3812
|
+
(function (HttpHeaderCodes) {
|
|
3801
3813
|
/* *** Custom Headers *** */
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
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
|
-
|
|
3821
|
+
HttpHeaderCodes["WWW_Authenticate"] = "WWW-Authenticate";
|
|
3810
3822
|
/**
|
|
3811
3823
|
* Contains the credentials to authenticate a user-agent with a server.
|
|
3812
3824
|
*/
|
|
3813
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3838
|
+
HttpHeaderCodes["Age"] = "Age";
|
|
3827
3839
|
/**
|
|
3828
3840
|
* Directives for caching mechanisms in both requests and responses.
|
|
3829
3841
|
*/
|
|
3830
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3900
|
+
HttpHeaderCodes["Connection"] = "Connection";
|
|
3889
3901
|
/**
|
|
3890
3902
|
* Controls how long a persistent connection should stay open.
|
|
3891
3903
|
*/
|
|
3892
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3930
|
+
HttpHeaderCodes["Cookie"] = "Cookie";
|
|
3919
3931
|
/**
|
|
3920
3932
|
* Send cookies from the server to the user-agent.
|
|
3921
3933
|
*/
|
|
3922
|
-
|
|
3934
|
+
HttpHeaderCodes["Set_Cookie"] = "Set-Cookie";
|
|
3923
3935
|
/* *** CORS *** */
|
|
3924
3936
|
/**
|
|
3925
3937
|
* Indicates whether the response can be shared.
|
|
3926
3938
|
*/
|
|
3927
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3969
|
+
HttpHeaderCodes["Access_Control_Request_Method"] = "Access-Control-Request-Method";
|
|
3958
3970
|
/**
|
|
3959
3971
|
* Indicates where a fetch originates from.
|
|
3960
3972
|
*/
|
|
3961
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3989
|
+
HttpHeaderCodes["Content_ID"] = "Content-ID";
|
|
3978
3990
|
/**
|
|
3979
3991
|
* The size of the resource, in decimal number of bytes.
|
|
3980
3992
|
*/
|
|
3981
|
-
|
|
3993
|
+
HttpHeaderCodes["Content_Length"] = "Content-Length";
|
|
3982
3994
|
/**
|
|
3983
3995
|
* Indicates the media type of the resource.
|
|
3984
3996
|
*/
|
|
3985
|
-
|
|
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
|
-
|
|
4002
|
+
HttpHeaderCodes["Content_Transfer_Encoding"] = "Content-Transfer-Encoding";
|
|
3991
4003
|
/**
|
|
3992
4004
|
* Used to specify the compression algorithm.
|
|
3993
4005
|
*/
|
|
3994
|
-
|
|
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
|
-
|
|
4011
|
+
HttpHeaderCodes["Content_Language"] = "Content-Language";
|
|
4000
4012
|
/**
|
|
4001
4013
|
* Indicates an alternate location for the returned data.
|
|
4002
4014
|
*/
|
|
4003
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4038
|
+
HttpHeaderCodes["Via"] = "Via";
|
|
4027
4039
|
/* *** Redirects *** */
|
|
4028
4040
|
/**
|
|
4029
4041
|
* Indicates the URL to redirect a page to.
|
|
4030
4042
|
*/
|
|
4031
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4080
|
+
HttpHeaderCodes["Accept_Ranges"] = "Accept-Ranges";
|
|
4069
4081
|
/**
|
|
4070
4082
|
* Indicates the part of a document that the server should return.
|
|
4071
4083
|
*/
|
|
4072
|
-
|
|
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
|
-
|
|
4089
|
+
HttpHeaderCodes["If_Range"] = "If-Range";
|
|
4078
4090
|
/**
|
|
4079
4091
|
* Indicates where in a full body message a partial message belongs.
|
|
4080
4092
|
*/
|
|
4081
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4127
|
+
HttpHeaderCodes["Feature_Policy"] = "Feature-Policy";
|
|
4116
4128
|
/**
|
|
4117
4129
|
* Force communication using HTTPS instead of HTTP.
|
|
4118
4130
|
*/
|
|
4119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4164
|
+
HttpHeaderCodes["X_Powered_By"] = "X-Powered-By";
|
|
4153
4165
|
/**
|
|
4154
4166
|
* Enables cross-site scripting filtering.
|
|
4155
4167
|
*/
|
|
4156
|
-
|
|
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
|
-
|
|
4173
|
+
HttpHeaderCodes["Transfer_Encoding"] = "Transfer-Encoding";
|
|
4162
4174
|
/**
|
|
4163
4175
|
* Specifies the transfer encodings the user agent is willing to accept.
|
|
4164
4176
|
*/
|
|
4165
|
-
|
|
4177
|
+
HttpHeaderCodes["TE"] = "TE";
|
|
4166
4178
|
/**
|
|
4167
4179
|
* Allows the sender to include additional fields at the end of chunked message.
|
|
4168
4180
|
*/
|
|
4169
|
-
|
|
4181
|
+
HttpHeaderCodes["Trailer"] = "Trailer";
|
|
4170
4182
|
/* *** WebSockets *** */
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4195
|
-
})(exports.
|
|
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.
|
|
4202
|
-
(function (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4234
|
+
HttpStatusCodes[HttpStatusCodes["EARLYHINTS"] = 103] = "EARLYHINTS";
|
|
4223
4235
|
/* *** Successful responses *** */
|
|
4224
4236
|
/**
|
|
4225
4237
|
* The request succeeded.
|
|
4226
4238
|
*/
|
|
4227
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4293
|
+
HttpStatusCodes[HttpStatusCodes["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
4282
4294
|
/**
|
|
4283
4295
|
*
|
|
4284
4296
|
*/
|
|
4285
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4418
|
+
HttpStatusCodes[HttpStatusCodes["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
4407
4419
|
/**
|
|
4408
4420
|
* The resource that is being accessed is locked.
|
|
4409
4421
|
*/
|
|
4410
|
-
|
|
4422
|
+
HttpStatusCodes[HttpStatusCodes["LOCKED"] = 423] = "LOCKED";
|
|
4411
4423
|
/**
|
|
4412
4424
|
* The request failed due to failure of a previous request.
|
|
4413
4425
|
*/
|
|
4414
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4493
|
-
})(exports.
|
|
4504
|
+
HttpStatusCodes[HttpStatusCodes["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
4505
|
+
})(exports.HttpStatusCodes || (exports.HttpStatusCodes = {}));
|
|
4494
4506
|
|
|
4495
|
-
const knownKeys = Object.keys(exports.
|
|
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.
|
|
4547
|
-
[exports.
|
|
4558
|
+
[exports.HttpHeaderCodes.Content_Type]: 'application/http',
|
|
4559
|
+
[exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
4548
4560
|
};
|
|
4549
4561
|
if (part?.contentId)
|
|
4550
|
-
headers[exports.
|
|
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.
|
|
4562
|
-
[exports.
|
|
4573
|
+
[exports.HttpHeaderCodes.Content_Type]: 'application/http',
|
|
4574
|
+
[exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
4563
4575
|
};
|
|
4564
4576
|
if (part?.contentId)
|
|
4565
|
-
headers[exports.
|
|
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.
|
|
4577
|
-
[exports.
|
|
4588
|
+
[exports.HttpHeaderCodes.Content_Type]: 'application/http',
|
|
4589
|
+
[exports.HttpHeaderCodes.Content_Transfer_Encoding]: 'binary'
|
|
4578
4590
|
};
|
|
4579
4591
|
if (part?.contentId)
|
|
4580
|
-
headers[exports.
|
|
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.
|
|
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(
|
|
4908
|
+
constructor(init, options) {
|
|
4886
4909
|
super();
|
|
4887
|
-
this
|
|
4888
|
-
this
|
|
4889
|
-
this
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
if (
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
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.
|
|
4901
|
-
this
|
|
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.
|
|
4933
|
+
return this[kKeyMap].has(this._getStoringKey(key));
|
|
4909
4934
|
}
|
|
4910
4935
|
set(key, value) {
|
|
4911
4936
|
key = this._getOriginalKey(key);
|
|
4912
|
-
this.
|
|
4913
|
-
if (!this.
|
|
4914
|
-
this.
|
|
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.
|
|
4943
|
+
return this[kKeyOrder].values();
|
|
4919
4944
|
}
|
|
4920
4945
|
values() {
|
|
4921
4946
|
let i = -1;
|
|
4922
|
-
const arr = this
|
|
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
|
|
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.
|
|
4957
|
-
this.
|
|
4958
|
-
const i = this.
|
|
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.
|
|
4985
|
+
this[kKeyOrder].splice(i, 1);
|
|
4961
4986
|
return super.delete(orgKey);
|
|
4962
4987
|
}
|
|
4963
4988
|
sort(compareFn) {
|
|
4964
|
-
this.
|
|
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.
|
|
4973
|
-
(this.
|
|
4999
|
+
return this[kKeyMap].get(key.toLowerCase()) ??
|
|
5000
|
+
(this[kWellKnownKeys].get(key.toLowerCase()) ?? key);
|
|
4974
5001
|
return key;
|
|
4975
5002
|
}
|
|
4976
|
-
|
|
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;
|
|
@@ -5726,6 +5755,9 @@ class CollectionResourceInfo extends ResourceInfo {
|
|
|
5726
5755
|
metadata.search.sortFields = normalizeFieldArray(document, dataType, metadata.search.sortFields);
|
|
5727
5756
|
}
|
|
5728
5757
|
}
|
|
5758
|
+
get instance() {
|
|
5759
|
+
return this.metadata.instance;
|
|
5760
|
+
}
|
|
5729
5761
|
get keyFields() {
|
|
5730
5762
|
return this.metadata.keyFields;
|
|
5731
5763
|
}
|
|
@@ -5753,6 +5785,10 @@ class CollectionResourceInfo extends ResourceInfo {
|
|
|
5753
5785
|
get search() {
|
|
5754
5786
|
return this.metadata.search;
|
|
5755
5787
|
}
|
|
5788
|
+
getHandler(method) {
|
|
5789
|
+
const r = this.metadata[method];
|
|
5790
|
+
return r && r.handler;
|
|
5791
|
+
}
|
|
5756
5792
|
getSchema(jsonOnly) {
|
|
5757
5793
|
const out = super.getSchema(jsonOnly);
|
|
5758
5794
|
if (out.keyFields.length < 2)
|
|
@@ -5824,25 +5860,25 @@ class OpraDocument {
|
|
|
5824
5860
|
const t = this.types.get(name);
|
|
5825
5861
|
if (t)
|
|
5826
5862
|
return t;
|
|
5827
|
-
throw new
|
|
5863
|
+
throw new NotFoundError(`Data type "${name}" does not exists`);
|
|
5828
5864
|
}
|
|
5829
5865
|
getComplexDataType(name) {
|
|
5830
5866
|
const t = this.getDataType(name);
|
|
5831
5867
|
if (t && t instanceof ComplexType)
|
|
5832
5868
|
return t;
|
|
5833
|
-
throw new
|
|
5869
|
+
throw new NotAcceptableError(`Data type "${name}" is not a ComplexType`);
|
|
5834
5870
|
}
|
|
5835
5871
|
getSimpleDataType(name) {
|
|
5836
5872
|
const t = this.getDataType(name);
|
|
5837
5873
|
if (t && t instanceof SimpleType)
|
|
5838
5874
|
return t;
|
|
5839
|
-
throw new
|
|
5875
|
+
throw new NotAcceptableError(`Data type "${name}" is not a SimpleType`);
|
|
5840
5876
|
}
|
|
5841
5877
|
getUnionDataType(name) {
|
|
5842
5878
|
const t = this.getDataType(name);
|
|
5843
5879
|
if (t && t instanceof UnionType)
|
|
5844
5880
|
return t;
|
|
5845
|
-
throw new
|
|
5881
|
+
throw new NotAcceptableError(`Data type "${name}" is not a UnionType`);
|
|
5846
5882
|
}
|
|
5847
5883
|
get resources() {
|
|
5848
5884
|
return this._resources;
|
|
@@ -5853,19 +5889,19 @@ class OpraDocument {
|
|
|
5853
5889
|
getResource(name) {
|
|
5854
5890
|
const t = this.resources.get(name);
|
|
5855
5891
|
if (!t)
|
|
5856
|
-
throw new
|
|
5892
|
+
throw new NotFoundError(`Resource "${name}" does not exists`);
|
|
5857
5893
|
return t;
|
|
5858
5894
|
}
|
|
5859
5895
|
getCollectionResource(name) {
|
|
5860
5896
|
const t = this.getResource(name);
|
|
5861
5897
|
if (!(t instanceof CollectionResourceInfo))
|
|
5862
|
-
throw new
|
|
5898
|
+
throw new NotAcceptableError(`"${name}" is not a CollectionResource`);
|
|
5863
5899
|
return t;
|
|
5864
5900
|
}
|
|
5865
5901
|
getSingletonResource(name) {
|
|
5866
5902
|
const t = this.getResource(name);
|
|
5867
5903
|
if (!(t instanceof SingletonResourceInfo))
|
|
5868
|
-
throw new
|
|
5904
|
+
throw new NotAcceptableError(`"${name}" is not a SingletonResource`);
|
|
5869
5905
|
return t;
|
|
5870
5906
|
}
|
|
5871
5907
|
getMetadata(jsonOnly) {
|
|
@@ -5906,7 +5942,7 @@ class OpraDocument {
|
|
|
5906
5942
|
dataType = new UnionType(this, name, { ...schema, types: [] });
|
|
5907
5943
|
}
|
|
5908
5944
|
else
|
|
5909
|
-
throw new
|
|
5945
|
+
throw new InternalServerError(`Invalid data type schema`);
|
|
5910
5946
|
this._types.set(name, dataType);
|
|
5911
5947
|
if (isOwn)
|
|
5912
5948
|
this._ownTypes.set(name, dataType);
|
|
@@ -5916,16 +5952,16 @@ class OpraDocument {
|
|
|
5916
5952
|
if (exports.OpraSchema.isCollectionResource(schema) || exports.OpraSchema.isSingletonResource(schema)) {
|
|
5917
5953
|
const dataType = this.getDataType(schema.type);
|
|
5918
5954
|
if (!dataType)
|
|
5919
|
-
throw new
|
|
5955
|
+
throw new InternalServerError(`Datatype "${schema.type}" declared in CollectionResource (${name}) does not exists`);
|
|
5920
5956
|
if (!(dataType instanceof ComplexType))
|
|
5921
|
-
throw new
|
|
5957
|
+
throw new InternalServerError(`${schema.type} is not an ComplexType`);
|
|
5922
5958
|
if (exports.OpraSchema.isCollectionResource(schema))
|
|
5923
5959
|
this.resources.set(name, new CollectionResourceInfo(this, name, dataType, schema));
|
|
5924
5960
|
else
|
|
5925
5961
|
this.resources.set(name, new SingletonResourceInfo(this, name, dataType, schema));
|
|
5926
5962
|
}
|
|
5927
5963
|
else
|
|
5928
|
-
throw new
|
|
5964
|
+
throw new InternalServerError(`Unknown resource kind (${schema.kind})`);
|
|
5929
5965
|
}
|
|
5930
5966
|
_initTypes() {
|
|
5931
5967
|
for (const dataType of this._types.values()) {
|
|
@@ -6446,51 +6482,42 @@ class OpraURLPathComponent {
|
|
|
6446
6482
|
}
|
|
6447
6483
|
}
|
|
6448
6484
|
|
|
6485
|
+
var _a$3;
|
|
6449
6486
|
const nodeInspectCustom$2 = Symbol.for('nodejs.util.inspect.custom');
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
this._entries.push(...x._entries);
|
|
6462
|
-
else
|
|
6463
|
-
this.add(x);
|
|
6464
|
-
}
|
|
6487
|
+
const kEntries$2 = Symbol('kEntries');
|
|
6488
|
+
const kOptions$2 = Symbol('kOptions');
|
|
6489
|
+
class OpraURLPath {
|
|
6490
|
+
constructor(init, options) {
|
|
6491
|
+
this[_a$3] = [];
|
|
6492
|
+
this[kOptions$2] = { ...options, onChange: undefined };
|
|
6493
|
+
if (Array.isArray(init))
|
|
6494
|
+
this.join(...init);
|
|
6495
|
+
else if (init)
|
|
6496
|
+
this.join(init);
|
|
6497
|
+
this[kOptions$2].onChange = options?.onChange;
|
|
6465
6498
|
}
|
|
6466
6499
|
get size() {
|
|
6467
|
-
return this.
|
|
6500
|
+
return this[kEntries$2].length;
|
|
6468
6501
|
}
|
|
6469
|
-
|
|
6470
|
-
this.
|
|
6471
|
-
|
|
6502
|
+
changed() {
|
|
6503
|
+
if (this[kOptions$2].onChange)
|
|
6504
|
+
this[kOptions$2].onChange();
|
|
6472
6505
|
}
|
|
6473
6506
|
clear() {
|
|
6474
|
-
this
|
|
6475
|
-
this.
|
|
6507
|
+
this[kEntries$2] = [];
|
|
6508
|
+
this.changed();
|
|
6476
6509
|
}
|
|
6477
6510
|
get(index) {
|
|
6478
|
-
return this
|
|
6511
|
+
return this[kEntries$2][index];
|
|
6479
6512
|
}
|
|
6480
|
-
join(
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
});
|
|
6484
|
-
for (const x of pathTokenizer) {
|
|
6485
|
-
const p = decodePathComponent(x);
|
|
6486
|
-
this._add(p);
|
|
6487
|
-
}
|
|
6488
|
-
this.emit('change');
|
|
6513
|
+
join(...source) {
|
|
6514
|
+
source.forEach(x => this._join(this[kEntries$2], x));
|
|
6515
|
+
this.changed();
|
|
6489
6516
|
return this;
|
|
6490
6517
|
}
|
|
6491
6518
|
entries() {
|
|
6492
6519
|
let i = -1;
|
|
6493
|
-
const arr = [...this
|
|
6520
|
+
const arr = [...this[kEntries$2]];
|
|
6494
6521
|
return {
|
|
6495
6522
|
[Symbol.iterator]() {
|
|
6496
6523
|
return this;
|
|
@@ -6504,9 +6531,46 @@ class OpraURLPath extends events.EventEmitter {
|
|
|
6504
6531
|
}
|
|
6505
6532
|
};
|
|
6506
6533
|
}
|
|
6534
|
+
forEach(callback) {
|
|
6535
|
+
for (const item of this[kEntries$2]) {
|
|
6536
|
+
callback.call(this, item, this);
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
getResource(index) {
|
|
6540
|
+
const v = this[kEntries$2][index];
|
|
6541
|
+
return v == null ? undefined : v.resource;
|
|
6542
|
+
}
|
|
6543
|
+
getKey(index) {
|
|
6544
|
+
const v = this[kEntries$2][index];
|
|
6545
|
+
return v == null ? undefined : v.key;
|
|
6546
|
+
}
|
|
6547
|
+
pop() {
|
|
6548
|
+
const out = this[kEntries$2].pop();
|
|
6549
|
+
this.changed();
|
|
6550
|
+
return out;
|
|
6551
|
+
}
|
|
6552
|
+
shift() {
|
|
6553
|
+
const out = this[kEntries$2].shift();
|
|
6554
|
+
this.changed();
|
|
6555
|
+
return out;
|
|
6556
|
+
}
|
|
6557
|
+
slice(start, end) {
|
|
6558
|
+
return new OpraURLPath(this[kEntries$2].slice(start, end));
|
|
6559
|
+
}
|
|
6560
|
+
splice(start, deleteCount, join) {
|
|
6561
|
+
const items = (join ? this._join([], join) : []);
|
|
6562
|
+
this[kEntries$2].splice(start, deleteCount, ...items);
|
|
6563
|
+
this.changed();
|
|
6564
|
+
}
|
|
6565
|
+
unshift(join) {
|
|
6566
|
+
return this.splice(0, 0, join);
|
|
6567
|
+
}
|
|
6568
|
+
toString() {
|
|
6569
|
+
return this[kEntries$2].map(x => encodePathComponent(x.resource, x.key, x.typeCast)).join('/');
|
|
6570
|
+
}
|
|
6507
6571
|
values() {
|
|
6508
6572
|
let i = -1;
|
|
6509
|
-
const arr = [...this
|
|
6573
|
+
const arr = [...this[kEntries$2]];
|
|
6510
6574
|
return {
|
|
6511
6575
|
[Symbol.iterator]() {
|
|
6512
6576
|
return this;
|
|
@@ -6520,59 +6584,56 @@ class OpraURLPath extends events.EventEmitter {
|
|
|
6520
6584
|
}
|
|
6521
6585
|
};
|
|
6522
6586
|
}
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6587
|
+
_join(target, source) {
|
|
6588
|
+
if (typeof source === 'string') {
|
|
6589
|
+
const pathTokenizer = fastTokenizer.tokenize(normalizePath(source, true), {
|
|
6590
|
+
delimiters: '/', quotes: true, brackets: true,
|
|
6591
|
+
});
|
|
6592
|
+
for (const x of pathTokenizer) {
|
|
6593
|
+
const p = decodePathComponent(x);
|
|
6594
|
+
target.push(new OpraURLPathComponent(p));
|
|
6595
|
+
}
|
|
6596
|
+
return;
|
|
6526
6597
|
}
|
|
6598
|
+
if (source instanceof OpraURLPath) {
|
|
6599
|
+
target.push(...source[kEntries$2].map(x => new OpraURLPathComponent(x)));
|
|
6600
|
+
return;
|
|
6601
|
+
}
|
|
6602
|
+
if (typeof source === 'object' && source.path instanceof OpraURLPath) {
|
|
6603
|
+
this._join(target, source.path);
|
|
6604
|
+
return;
|
|
6605
|
+
}
|
|
6606
|
+
if (isURL(source)) {
|
|
6607
|
+
this._join(target, source.pathname);
|
|
6608
|
+
return;
|
|
6609
|
+
}
|
|
6610
|
+
if (Array.isArray(source)) {
|
|
6611
|
+
source.forEach(x => this._join(target, x));
|
|
6612
|
+
return;
|
|
6613
|
+
}
|
|
6614
|
+
target.push(new OpraURLPathComponent(source));
|
|
6527
6615
|
}
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
return
|
|
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('/');
|
|
6616
|
+
/* istanbul ignore next */
|
|
6617
|
+
[(_a$3 = kEntries$2, nodeInspectCustom$2)]() {
|
|
6618
|
+
return this[kEntries$2];
|
|
6538
6619
|
}
|
|
6539
6620
|
[Symbol.iterator]() {
|
|
6540
6621
|
return this.entries();
|
|
6541
6622
|
}
|
|
6542
|
-
|
|
6543
|
-
|
|
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');
|
|
6623
|
+
get [Symbol.toStringTag]() {
|
|
6624
|
+
return 'OpraURLPath';
|
|
6566
6625
|
}
|
|
6567
6626
|
}
|
|
6627
|
+
OpraURLPath.kEntries = kEntries$2;
|
|
6628
|
+
OpraURLPath.kOptions = kOptions$2;
|
|
6568
6629
|
|
|
6569
|
-
class
|
|
6630
|
+
class HttpParamCodec {
|
|
6570
6631
|
}
|
|
6571
6632
|
|
|
6572
6633
|
const trueValues = ['true', 't', 'yes', 'y', '1'];
|
|
6573
6634
|
const falseValues = ['false', 'f', 'no', 'n', '0'];
|
|
6574
|
-
class
|
|
6575
|
-
|
|
6635
|
+
class BooleanCodec extends HttpParamCodec {
|
|
6636
|
+
decode(value) {
|
|
6576
6637
|
if (value === '')
|
|
6577
6638
|
return true;
|
|
6578
6639
|
// noinspection SuspiciousTypeOfGuard
|
|
@@ -6584,7 +6645,7 @@ class BooleanFormat extends Format {
|
|
|
6584
6645
|
return false;
|
|
6585
6646
|
throw new TypeError(`"${value}" is not a valid boolean`);
|
|
6586
6647
|
}
|
|
6587
|
-
|
|
6648
|
+
encode(value) {
|
|
6588
6649
|
return typeof value === 'boolean' ?
|
|
6589
6650
|
(value ? 'true' : 'false') : '';
|
|
6590
6651
|
}
|
|
@@ -6593,7 +6654,7 @@ class BooleanFormat extends Format {
|
|
|
6593
6654
|
/* eslint-disable max-len */
|
|
6594
6655
|
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
6595
6656
|
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
|
|
6657
|
+
class DateCodec extends HttpParamCodec {
|
|
6597
6658
|
constructor(options) {
|
|
6598
6659
|
super();
|
|
6599
6660
|
this.max = options?.max ? coerceToDateString(options.max) : undefined;
|
|
@@ -6601,7 +6662,7 @@ class DateFormat extends Format {
|
|
|
6601
6662
|
this.time = options?.time ?? true;
|
|
6602
6663
|
this.timeZone = options?.timeZone ?? true;
|
|
6603
6664
|
}
|
|
6604
|
-
|
|
6665
|
+
decode(value) {
|
|
6605
6666
|
const v = coerceToDateString(value, this.time, this.timeZone);
|
|
6606
6667
|
if (this.min != null && v < this.min)
|
|
6607
6668
|
throw new TypeError(`Value must be ${this.min} or greater.`);
|
|
@@ -6609,7 +6670,7 @@ class DateFormat extends Format {
|
|
|
6609
6670
|
throw new TypeError(`Value must be ${this.max} or less.`);
|
|
6610
6671
|
return v;
|
|
6611
6672
|
}
|
|
6612
|
-
|
|
6673
|
+
encode(value) {
|
|
6613
6674
|
return coerceToDateString(value, this.time, this.timeZone);
|
|
6614
6675
|
}
|
|
6615
6676
|
}
|
|
@@ -6630,25 +6691,25 @@ function coerceToDateString(value, time, timeZone) {
|
|
|
6630
6691
|
return v;
|
|
6631
6692
|
}
|
|
6632
6693
|
|
|
6633
|
-
class
|
|
6634
|
-
|
|
6694
|
+
class FilterCodec extends HttpParamCodec {
|
|
6695
|
+
decode(value) {
|
|
6635
6696
|
if (value instanceof Expression)
|
|
6636
6697
|
return value;
|
|
6637
6698
|
return parseFilter(value);
|
|
6638
6699
|
}
|
|
6639
|
-
|
|
6700
|
+
encode(value) {
|
|
6640
6701
|
// @ts-ignore
|
|
6641
6702
|
return value ? '' + value : '';
|
|
6642
6703
|
}
|
|
6643
6704
|
}
|
|
6644
6705
|
|
|
6645
|
-
class
|
|
6706
|
+
class NumberCodec extends HttpParamCodec {
|
|
6646
6707
|
constructor(options) {
|
|
6647
6708
|
super();
|
|
6648
6709
|
this.max = options?.max;
|
|
6649
6710
|
this.min = options?.min;
|
|
6650
6711
|
}
|
|
6651
|
-
|
|
6712
|
+
decode(value) {
|
|
6652
6713
|
// noinspection SuspiciousTypeOfGuard
|
|
6653
6714
|
const v = typeof value === 'number' ? value : parseFloat(value);
|
|
6654
6715
|
if (isNaN(v))
|
|
@@ -6659,18 +6720,18 @@ class NumberFormat extends Format {
|
|
|
6659
6720
|
throw new TypeError(`Value must be ${this.max} or less.`);
|
|
6660
6721
|
return v;
|
|
6661
6722
|
}
|
|
6662
|
-
|
|
6723
|
+
encode(value) {
|
|
6663
6724
|
return typeof value === 'number' ? '' + value : '';
|
|
6664
6725
|
}
|
|
6665
6726
|
}
|
|
6666
6727
|
|
|
6667
|
-
class
|
|
6728
|
+
class IntegerCodec extends NumberCodec {
|
|
6668
6729
|
constructor(options) {
|
|
6669
6730
|
super(options);
|
|
6670
6731
|
this.enum = options?.enum;
|
|
6671
6732
|
}
|
|
6672
|
-
|
|
6673
|
-
const v = super.
|
|
6733
|
+
decode(value) {
|
|
6734
|
+
const v = super.decode(value);
|
|
6674
6735
|
if (!Number.isInteger(v))
|
|
6675
6736
|
throw new TypeError(`"${value}" is not a valid integer`);
|
|
6676
6737
|
if (this.enum && !this.enum.includes(v))
|
|
@@ -6679,14 +6740,14 @@ class IntegerFormat extends NumberFormat {
|
|
|
6679
6740
|
}
|
|
6680
6741
|
}
|
|
6681
6742
|
|
|
6682
|
-
class
|
|
6743
|
+
class StringCodec extends HttpParamCodec {
|
|
6683
6744
|
constructor(options) {
|
|
6684
6745
|
super();
|
|
6685
6746
|
this.maxLength = options?.maxLength;
|
|
6686
6747
|
this.minLength = options?.minLength;
|
|
6687
6748
|
this.enum = options?.enum;
|
|
6688
6749
|
}
|
|
6689
|
-
|
|
6750
|
+
decode(value) {
|
|
6690
6751
|
if (this.minLength != null && value.length < this.minLength)
|
|
6691
6752
|
throw new TypeError(`Value must be at least ${this.minLength} character${this.minLength > 1 ? 's' : ''} long.`);
|
|
6692
6753
|
if (this.maxLength != null && value.length > this.maxLength)
|
|
@@ -6695,406 +6756,588 @@ class StringFormat extends Format {
|
|
|
6695
6756
|
throw new TypeError(`"${value}" is not one of allowed enum values (${this.enum}).`);
|
|
6696
6757
|
return value;
|
|
6697
6758
|
}
|
|
6698
|
-
|
|
6759
|
+
encode(value) {
|
|
6699
6760
|
return value == null ? '' : '' + value;
|
|
6700
6761
|
}
|
|
6701
6762
|
}
|
|
6702
6763
|
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
'
|
|
6709
|
-
'
|
|
6764
|
+
/**
|
|
6765
|
+
* Encode input string with standard encodeURIComponent and then un-encode specific characters.
|
|
6766
|
+
*/
|
|
6767
|
+
const ENCODING_REGEX = /%(\d[a-f0-9])/gi;
|
|
6768
|
+
const ENCODING_REPLACEMENTS = {
|
|
6769
|
+
'2C': ',',
|
|
6770
|
+
'2F': '/',
|
|
6771
|
+
'24': '$',
|
|
6772
|
+
'3A': ':',
|
|
6773
|
+
'3B': ';',
|
|
6774
|
+
'3D': '=',
|
|
6775
|
+
'3F': '?',
|
|
6776
|
+
'40': '@'
|
|
6710
6777
|
};
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6778
|
+
function encodeURIParam(v) {
|
|
6779
|
+
return encodeURIComponent(v).replace(ENCODING_REGEX, (s, t) => ENCODING_REPLACEMENTS[t] ?? s);
|
|
6780
|
+
}
|
|
6781
|
+
|
|
6782
|
+
var _a$2, _b$1, _c;
|
|
6783
|
+
const kEntries$1 = Symbol('kEntries');
|
|
6784
|
+
const kSize$1 = Symbol('kSize');
|
|
6785
|
+
const kParamDefs = Symbol('kParamDefs');
|
|
6786
|
+
const kOptions$1 = Symbol('kOptions');
|
|
6787
|
+
const defaultKeyDecoder = (s) => decodeURIComponent(s);
|
|
6788
|
+
const defaultValueDecoder = (s) => decodeURIComponent(s);
|
|
6789
|
+
const defaultKeyEncoder = (s) => encodeURIParam(s);
|
|
6790
|
+
const defaultValueEncoder = (s) => encodeURIParam(s);
|
|
6791
|
+
const internalCodecs = {
|
|
6792
|
+
'boolean': new BooleanCodec(),
|
|
6793
|
+
'date': new DateCodec(),
|
|
6794
|
+
'filter': new FilterCodec(),
|
|
6795
|
+
'integer': new IntegerCodec(),
|
|
6796
|
+
'number': new NumberCodec(),
|
|
6797
|
+
'string': new StringCodec()
|
|
6798
|
+
};
|
|
6799
|
+
class HttpParams {
|
|
6800
|
+
constructor(init, options) {
|
|
6801
|
+
this[_a$2] = new ResponsiveMap();
|
|
6802
|
+
this[_b$1] = 0;
|
|
6803
|
+
this[_c] = new Map();
|
|
6804
|
+
this[kOptions$1] = { ...options, onChange: undefined };
|
|
6805
|
+
const defineParams = options?.params;
|
|
6806
|
+
if (defineParams)
|
|
6807
|
+
Object.keys(defineParams).forEach(key => this.define(key, defineParams[key]));
|
|
6808
|
+
if (init)
|
|
6809
|
+
this.appendAll(init);
|
|
6810
|
+
this[kOptions$1].onChange = options?.onChange;
|
|
6733
6811
|
}
|
|
6734
6812
|
get size() {
|
|
6735
|
-
return this
|
|
6813
|
+
return this[kSize$1];
|
|
6736
6814
|
}
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6815
|
+
/**
|
|
6816
|
+
* Appends a new value to the existing set of values for a parameter
|
|
6817
|
+
* and returns this instance
|
|
6818
|
+
*/
|
|
6819
|
+
append(name, value) {
|
|
6820
|
+
this._append(name, value);
|
|
6821
|
+
this.changed();
|
|
6822
|
+
return this;
|
|
6823
|
+
}
|
|
6824
|
+
appendAll(input) {
|
|
6825
|
+
if (typeof input === 'string') {
|
|
6826
|
+
if (input && input.startsWith('?'))
|
|
6827
|
+
input = input.substring(1);
|
|
6828
|
+
if (!input)
|
|
6829
|
+
return this;
|
|
6830
|
+
const tokenizer = fastTokenizer.tokenize(input, { delimiters: '&', quotes: true, brackets: true });
|
|
6831
|
+
for (const token of tokenizer) {
|
|
6832
|
+
if (!token)
|
|
6833
|
+
continue;
|
|
6834
|
+
const itemTokenizer = fastTokenizer.tokenize(token, {
|
|
6835
|
+
delimiters: '=',
|
|
6836
|
+
quotes: true,
|
|
6837
|
+
brackets: true
|
|
6838
|
+
});
|
|
6839
|
+
const k = this.decodeKey(itemTokenizer.next() || '');
|
|
6840
|
+
const v = this.decodeValue(itemTokenizer.join('='), k);
|
|
6841
|
+
this._append(k, v);
|
|
6842
|
+
}
|
|
6743
6843
|
}
|
|
6744
|
-
else if (typeof
|
|
6844
|
+
else if (input.forEach && typeof input.forEach === 'function')
|
|
6845
|
+
input.forEach((value, name) => this._append(name, value));
|
|
6745
6846
|
else
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
this.emit('change');
|
|
6847
|
+
Object.keys(input).forEach(name => this._append(name, input[name]));
|
|
6848
|
+
return this;
|
|
6749
6849
|
}
|
|
6750
|
-
|
|
6751
|
-
if (this.
|
|
6752
|
-
this.
|
|
6850
|
+
changed() {
|
|
6851
|
+
if (this[kOptions$1].onChange)
|
|
6852
|
+
this[kOptions$1].onChange();
|
|
6753
6853
|
}
|
|
6754
6854
|
clear() {
|
|
6755
|
-
this.
|
|
6756
|
-
|
|
6757
|
-
|
|
6855
|
+
if (this[kEntries$1].size) {
|
|
6856
|
+
this[kEntries$1].clear();
|
|
6857
|
+
this[kSize$1] = 0;
|
|
6858
|
+
this.changed();
|
|
6859
|
+
}
|
|
6758
6860
|
}
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
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);
|
|
6861
|
+
/**
|
|
6862
|
+
* Deletes values for a given parameter
|
|
6863
|
+
*/
|
|
6864
|
+
delete(name, value) {
|
|
6865
|
+
if (this._delete(name, value))
|
|
6866
|
+
this.changed();
|
|
6771
6867
|
return this;
|
|
6772
6868
|
}
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
}
|
|
6869
|
+
/**
|
|
6870
|
+
* Returns an iterable of key, value pairs for every entry in the map.
|
|
6871
|
+
*/
|
|
6777
6872
|
entries() {
|
|
6778
|
-
const
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
return
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6873
|
+
const iter = this[kEntries$1].entries();
|
|
6874
|
+
let i = 0;
|
|
6875
|
+
let key;
|
|
6876
|
+
let values;
|
|
6877
|
+
return {
|
|
6878
|
+
[Symbol.iterator]() {
|
|
6879
|
+
return this;
|
|
6880
|
+
},
|
|
6881
|
+
next() {
|
|
6882
|
+
if (values) {
|
|
6883
|
+
if (i >= values.length) {
|
|
6884
|
+
values = undefined;
|
|
6885
|
+
i = 0;
|
|
6886
|
+
}
|
|
6887
|
+
}
|
|
6888
|
+
if (!values) {
|
|
6889
|
+
const n = iter.next();
|
|
6890
|
+
if (n.done)
|
|
6891
|
+
return { done: true, value: undefined };
|
|
6892
|
+
key = n.value[0];
|
|
6893
|
+
values = n.value[1];
|
|
6894
|
+
}
|
|
6895
|
+
return {
|
|
6896
|
+
done: false,
|
|
6897
|
+
value: [key, values[i++]]
|
|
6898
|
+
};
|
|
6788
6899
|
}
|
|
6900
|
+
};
|
|
6901
|
+
}
|
|
6902
|
+
forEach(callbackFn, thisArg) {
|
|
6903
|
+
const iterator = this.entries();
|
|
6904
|
+
let entry = iterator.next();
|
|
6905
|
+
while (!entry.done) {
|
|
6906
|
+
callbackFn.call(thisArg || this, entry.value[1], entry.value[0], this);
|
|
6907
|
+
entry = iterator.next();
|
|
6789
6908
|
}
|
|
6790
6909
|
}
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6910
|
+
/**
|
|
6911
|
+
* Retrieves value of a given parameter at given index
|
|
6912
|
+
*/
|
|
6913
|
+
get(name, index = 0) {
|
|
6914
|
+
const values = this[kEntries$1].get(name.toLowerCase());
|
|
6915
|
+
return values && values.length > index ? values[index] : null;
|
|
6795
6916
|
}
|
|
6917
|
+
/**
|
|
6918
|
+
* Retrieves an array of values for a given parameter.
|
|
6919
|
+
*/
|
|
6796
6920
|
getAll(name) {
|
|
6797
|
-
const entry = this.
|
|
6798
|
-
return entry ? entry.slice(0) :
|
|
6799
|
-
}
|
|
6800
|
-
has(name) {
|
|
6801
|
-
return this._entries.has(name);
|
|
6921
|
+
const entry = this[kEntries$1].get(name);
|
|
6922
|
+
return entry ? entry.slice(0) : null;
|
|
6802
6923
|
}
|
|
6924
|
+
/**
|
|
6925
|
+
* Retrieves the names of the parameters.
|
|
6926
|
+
*/
|
|
6803
6927
|
keys() {
|
|
6804
|
-
return this.
|
|
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');
|
|
6928
|
+
return this[kEntries$1].keys();
|
|
6814
6929
|
}
|
|
6930
|
+
/**
|
|
6931
|
+
* Retrieves the names of the parameters.
|
|
6932
|
+
*/
|
|
6815
6933
|
values() {
|
|
6816
6934
|
const items = [];
|
|
6817
6935
|
this.forEach((value) => items.push(value));
|
|
6818
6936
|
return items.values();
|
|
6819
6937
|
}
|
|
6938
|
+
/**
|
|
6939
|
+
* Checks for existence of a parameter.
|
|
6940
|
+
*/
|
|
6941
|
+
has(name) {
|
|
6942
|
+
return this[kEntries$1].has(name);
|
|
6943
|
+
}
|
|
6944
|
+
/**
|
|
6945
|
+
* Sets or modifies a value for a given parameter.
|
|
6946
|
+
* If the header already exists, its value is replaced with the given value
|
|
6947
|
+
*/
|
|
6948
|
+
set(name, value) {
|
|
6949
|
+
this._set(name, value);
|
|
6950
|
+
this.changed();
|
|
6951
|
+
return this;
|
|
6952
|
+
}
|
|
6953
|
+
sort(compareFn) {
|
|
6954
|
+
this[kEntries$1].sort(compareFn);
|
|
6955
|
+
this.changed();
|
|
6956
|
+
return this;
|
|
6957
|
+
}
|
|
6958
|
+
/**
|
|
6959
|
+
* Serializes the body to an encoded string, where key-value pairs (separated by `=`) are
|
|
6960
|
+
* separated by `&`s.
|
|
6961
|
+
*/
|
|
6820
6962
|
toString() {
|
|
6821
|
-
|
|
6963
|
+
const out = [];
|
|
6822
6964
|
this.forEach((v, k) => {
|
|
6823
|
-
|
|
6824
|
-
|
|
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
|
-
}
|
|
6965
|
+
out.push(this.encodeKey(k) +
|
|
6966
|
+
(v ? '=' + this.encodeValue(v, k) : ''));
|
|
6836
6967
|
});
|
|
6837
|
-
return out;
|
|
6968
|
+
return out.join('&');
|
|
6838
6969
|
}
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
if (
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6970
|
+
define(name, options) {
|
|
6971
|
+
if (!name)
|
|
6972
|
+
throw new Error('Parameter name required');
|
|
6973
|
+
if (typeof options?.codec === 'string' && !internalCodecs[options.codec])
|
|
6974
|
+
throw new Error(`Unknown url parameter format name "${options.codec}"`);
|
|
6975
|
+
const codec = (typeof options?.codec === 'string'
|
|
6976
|
+
? internalCodecs[options.codec]
|
|
6977
|
+
: options?.codec) || internalCodecs.string;
|
|
6978
|
+
const meta = {
|
|
6979
|
+
...options,
|
|
6980
|
+
codec
|
|
6981
|
+
};
|
|
6982
|
+
this[kParamDefs].set(name, meta);
|
|
6983
|
+
return this;
|
|
6984
|
+
}
|
|
6985
|
+
encodeKey(key) {
|
|
6986
|
+
return (this[kOptions$1].encodeKey || defaultKeyEncoder)(key);
|
|
6987
|
+
}
|
|
6988
|
+
decodeKey(key) {
|
|
6989
|
+
return (this[kOptions$1].decodeKey || defaultKeyDecoder)(key);
|
|
6990
|
+
}
|
|
6991
|
+
encodeValue(value, key) {
|
|
6992
|
+
const prmDef = this[kParamDefs].get(key);
|
|
6993
|
+
if (prmDef) {
|
|
6994
|
+
const delimReplace = '%' + (prmDef.arrayDelimiter || ',').charCodeAt(0).toString(16).toUpperCase();
|
|
6995
|
+
const fn = (x) => encodeURIParam(prmDef.codec.encode(x)).replaceAll(',', delimReplace);
|
|
6996
|
+
return Array.isArray(value)
|
|
6997
|
+
? value.map((v) => fn(v)).join(prmDef.arrayDelimiter || ',')
|
|
6998
|
+
: fn(value);
|
|
6999
|
+
}
|
|
7000
|
+
return (this[kOptions$1].encodeValue || defaultValueEncoder)(value);
|
|
7001
|
+
}
|
|
7002
|
+
decodeValue(value, key) {
|
|
7003
|
+
const prmDef = this[kParamDefs].get(key);
|
|
7004
|
+
const valueDecoder = (this[kOptions$1].decodeValue || defaultValueDecoder);
|
|
7005
|
+
let val = value;
|
|
7006
|
+
if (prmDef) {
|
|
7007
|
+
if (prmDef.array) {
|
|
7008
|
+
val = fastTokenizer.splitString(value, {
|
|
7009
|
+
delimiters: prmDef.arrayDelimiter || ',',
|
|
6861
7010
|
brackets: true,
|
|
6862
|
-
quotes: true
|
|
6863
|
-
|
|
6864
|
-
|
|
7011
|
+
quotes: true,
|
|
7012
|
+
keepQuotes: false
|
|
7013
|
+
}).map((x) => valueDecoder(x));
|
|
6865
7014
|
}
|
|
6866
|
-
else
|
|
6867
|
-
|
|
7015
|
+
else
|
|
7016
|
+
val = valueDecoder(val);
|
|
7017
|
+
const fn = (x) => prmDef.codec.decode(valueDecoder(x));
|
|
7018
|
+
val = Array.isArray(val) ? val.map(fn) : fn(val);
|
|
7019
|
+
if (prmDef.array === 'strict')
|
|
7020
|
+
val = Array.isArray(val) ? val : [val];
|
|
7021
|
+
else if (prmDef.array)
|
|
7022
|
+
val = Array.isArray(val) && val.length === 1 ? val[0] : val;
|
|
7023
|
+
if (Array.isArray(val)) {
|
|
7024
|
+
if (prmDef.minArrayItems && val.length < prmDef.minArrayItems)
|
|
7025
|
+
throw new Error(`"${key}" parameter requires at least ${prmDef.minArrayItems} values`);
|
|
7026
|
+
if (prmDef.maxArrayItems && val.length > prmDef.maxArrayItems)
|
|
7027
|
+
throw new Error(`"${key}" parameter accepts up to ${prmDef.maxArrayItems} values`);
|
|
6868
7028
|
}
|
|
7029
|
+
return val;
|
|
6869
7030
|
}
|
|
6870
|
-
|
|
7031
|
+
return valueDecoder(value);
|
|
6871
7032
|
}
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
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;
|
|
7033
|
+
_append(name, value) {
|
|
7034
|
+
let values = this[kEntries$1].get(name);
|
|
7035
|
+
if (!values) {
|
|
7036
|
+
values = [];
|
|
7037
|
+
this[kEntries$1].set(name, values);
|
|
7038
|
+
}
|
|
7039
|
+
values.push(value ?? null);
|
|
7040
|
+
this[kSize$1] += 1;
|
|
6886
7041
|
}
|
|
6887
|
-
|
|
6888
|
-
|
|
7042
|
+
_delete(name, value) {
|
|
7043
|
+
const oldValues = this[kEntries$1].get(name);
|
|
7044
|
+
if (!oldValues)
|
|
7045
|
+
return false;
|
|
7046
|
+
const oldSize = this[kSize$1];
|
|
7047
|
+
if (value) {
|
|
7048
|
+
const valueToDelete = Array.isArray(value) ? value : [value];
|
|
7049
|
+
const newValues = oldValues.filter(x => !valueToDelete.includes(x));
|
|
7050
|
+
this[kEntries$1].set(name, newValues);
|
|
7051
|
+
this[kSize$1] += -oldValues.length + newValues.length;
|
|
7052
|
+
}
|
|
7053
|
+
else {
|
|
7054
|
+
this[kEntries$1].delete(name);
|
|
7055
|
+
this[kSize$1] -= oldValues.length;
|
|
7056
|
+
}
|
|
7057
|
+
return oldSize !== this[kSize$1];
|
|
6889
7058
|
}
|
|
6890
|
-
|
|
6891
|
-
|
|
7059
|
+
_set(name, value, index) {
|
|
7060
|
+
if (value == null) {
|
|
7061
|
+
this._delete(name);
|
|
7062
|
+
return;
|
|
7063
|
+
}
|
|
7064
|
+
const values = this[kEntries$1].get(name);
|
|
7065
|
+
if (!values) {
|
|
7066
|
+
this[kEntries$1].set(name, [value]);
|
|
7067
|
+
this[kSize$1] += 1;
|
|
7068
|
+
return;
|
|
7069
|
+
}
|
|
7070
|
+
if (index == null || index < 0) {
|
|
7071
|
+
this[kEntries$1].set(name, [value]);
|
|
7072
|
+
this[kSize$1] += -(values.length) + 1;
|
|
7073
|
+
return;
|
|
7074
|
+
}
|
|
7075
|
+
const oldLen = values.length;
|
|
7076
|
+
values[Math.min(index, values.length)] = value;
|
|
7077
|
+
this[kSize$1] += -oldLen + values.length;
|
|
6892
7078
|
}
|
|
6893
|
-
[
|
|
6894
|
-
return this.
|
|
7079
|
+
[(_a$2 = kEntries$1, _b$1 = kSize$1, _c = kParamDefs, Symbol.iterator)]() {
|
|
7080
|
+
return this.entries();
|
|
6895
7081
|
}
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
if (!a)
|
|
6899
|
-
return false;
|
|
6900
|
-
this._size -= a.length;
|
|
6901
|
-
this._entries.delete(name);
|
|
6902
|
-
return true;
|
|
7082
|
+
get [Symbol.toStringTag]() {
|
|
7083
|
+
return 'HttpParams';
|
|
6903
7084
|
}
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
7085
|
+
}
|
|
7086
|
+
HttpParams.kEntries = kEntries$1;
|
|
7087
|
+
HttpParams.kSize = kSize$1;
|
|
7088
|
+
HttpParams.kParamDefs = kParamDefs;
|
|
7089
|
+
HttpParams.kOptions = kOptions$1;
|
|
7090
|
+
|
|
7091
|
+
class OpraURLSearchParams extends HttpParams {
|
|
7092
|
+
constructor(init, options) {
|
|
7093
|
+
super(init, {
|
|
7094
|
+
...options,
|
|
7095
|
+
params: {
|
|
7096
|
+
'$filter': { codec: 'filter' },
|
|
7097
|
+
'$limit': { codec: new IntegerCodec({ min: 0 }) },
|
|
7098
|
+
'$skip': { codec: new IntegerCodec({ min: 0 }) },
|
|
7099
|
+
'$pick': { codec: 'string', array: 'strict' },
|
|
7100
|
+
'$omit': { codec: 'string', array: 'strict' },
|
|
7101
|
+
'$include': { codec: 'string', array: 'strict' },
|
|
7102
|
+
'$sort': { codec: 'string', array: 'strict' },
|
|
7103
|
+
'$distinct': { codec: 'boolean' },
|
|
7104
|
+
'$count': { codec: 'boolean' },
|
|
7105
|
+
...options?.params
|
|
6920
7106
|
}
|
|
6921
|
-
}
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
this._entries.set(name, entry);
|
|
6926
|
-
}
|
|
6927
|
-
entry.push(v);
|
|
6928
|
-
this._size++;
|
|
6929
|
-
return true;
|
|
7107
|
+
});
|
|
7108
|
+
}
|
|
7109
|
+
get [Symbol.toStringTag]() {
|
|
7110
|
+
return 'URLSearchParams';
|
|
6930
7111
|
}
|
|
6931
7112
|
}
|
|
6932
7113
|
|
|
6933
|
-
|
|
7114
|
+
var _a$1;
|
|
7115
|
+
const nodeInspectCustom$1 = Symbol.for('nodejs.util.inspect.custom');
|
|
6934
7116
|
const urlRegEx = /^(?:((?:[A-Z][A-Z+-.]+:)+)\/\/([^/?]+))?(.*)?$/i;
|
|
6935
7117
|
const schemeRegEx = /^([A-Z][A-Z+-.]+:?)+$/i;
|
|
6936
7118
|
const hostRegEx = /^([^/:]+)(?::(\d+))?$/;
|
|
6937
7119
|
const hostnameRegEx = /^([^/:]+)$/;
|
|
6938
|
-
const
|
|
6939
|
-
const
|
|
6940
|
-
const
|
|
7120
|
+
const kContext = Symbol('kContext');
|
|
7121
|
+
const kPath = Symbol('kPath');
|
|
7122
|
+
const kSearchParams = Symbol('kSearchParams');
|
|
6941
7123
|
class OpraURL {
|
|
6942
|
-
constructor(input,
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
7124
|
+
constructor(input, arg1) {
|
|
7125
|
+
this[_a$1] = {
|
|
7126
|
+
protocol: '',
|
|
7127
|
+
username: '',
|
|
7128
|
+
pathname: '',
|
|
7129
|
+
prefix: '',
|
|
7130
|
+
hostname: '',
|
|
7131
|
+
port: '',
|
|
7132
|
+
hash: '',
|
|
7133
|
+
password: '',
|
|
7134
|
+
search: '',
|
|
7135
|
+
address: '',
|
|
7136
|
+
needUpdate: true
|
|
7137
|
+
};
|
|
7138
|
+
this[kPath] = new OpraURLPath('', {
|
|
7139
|
+
onChange: () => this._changed()
|
|
6954
7140
|
});
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
configurable: true,
|
|
6958
|
-
enumerable: false,
|
|
6959
|
-
value: new OpraURLSearchParams()
|
|
7141
|
+
this[kSearchParams] = new OpraURLSearchParams('', {
|
|
7142
|
+
onChange: () => this._changed()
|
|
6960
7143
|
});
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
7144
|
+
const base = typeof arg1 === 'object' ? arg1.base : arg1;
|
|
7145
|
+
if (typeof arg1 === 'object') {
|
|
7146
|
+
const defineParams = arg1?.params;
|
|
7147
|
+
if (defineParams)
|
|
7148
|
+
Object.keys(defineParams).forEach(key => this.searchParams.define(key, defineParams[key]));
|
|
7149
|
+
}
|
|
6965
7150
|
if (input)
|
|
6966
|
-
this.parse(input);
|
|
7151
|
+
this.parse(typeof input === 'object' ? input.toString() : input);
|
|
7152
|
+
if (base) {
|
|
7153
|
+
const baseUrl = base instanceof OpraURL ? base : new OpraURL(base);
|
|
7154
|
+
this[kContext].protocol = baseUrl.protocol;
|
|
7155
|
+
this[kContext].hostname = baseUrl.hostname;
|
|
7156
|
+
this[kContext].port = baseUrl.port;
|
|
7157
|
+
this[kContext].prefix = baseUrl.pathname;
|
|
7158
|
+
}
|
|
6967
7159
|
}
|
|
6968
7160
|
get address() {
|
|
6969
7161
|
this._update();
|
|
6970
|
-
|
|
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;
|
|
6977
|
-
}
|
|
6978
|
-
return out + this.pathPrefix + this.pathname;
|
|
7162
|
+
return this[kContext].address;
|
|
6979
7163
|
}
|
|
6980
|
-
get
|
|
6981
|
-
return this.
|
|
7164
|
+
get host() {
|
|
7165
|
+
return this.hostname ? (this.hostname + (this.port ? ':' + this.port : '')) : '';
|
|
6982
7166
|
}
|
|
6983
|
-
|
|
6984
|
-
|
|
7167
|
+
set host(v) {
|
|
7168
|
+
if (v) {
|
|
7169
|
+
const m = hostRegEx.exec(v);
|
|
7170
|
+
if (!m)
|
|
7171
|
+
throw Object.assign(new TypeError('Invalid host'), {
|
|
7172
|
+
host: v,
|
|
7173
|
+
code: 'ERR_INVALID_URL'
|
|
7174
|
+
});
|
|
7175
|
+
this[kContext].hostname = m[1];
|
|
7176
|
+
this[kContext].port = m[2] || '';
|
|
7177
|
+
}
|
|
7178
|
+
else {
|
|
7179
|
+
this[kContext].hostname = '';
|
|
7180
|
+
this[kContext].port = '';
|
|
7181
|
+
}
|
|
7182
|
+
this._changed();
|
|
6985
7183
|
}
|
|
6986
|
-
|
|
6987
|
-
|
|
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(':') ? '' : ':');
|
|
7184
|
+
get hostname() {
|
|
7185
|
+
return this[kContext].hostname || '';
|
|
6993
7186
|
}
|
|
6994
|
-
|
|
6995
|
-
|
|
7187
|
+
set hostname(v) {
|
|
7188
|
+
if (v) {
|
|
7189
|
+
if (!hostnameRegEx.test(v))
|
|
7190
|
+
throw Object.assign(new TypeError('Invalid hostname'), {
|
|
7191
|
+
hostname: v,
|
|
7192
|
+
code: 'ERR_INVALID_URL'
|
|
7193
|
+
});
|
|
7194
|
+
this[kContext].hostname = v;
|
|
7195
|
+
}
|
|
7196
|
+
else
|
|
7197
|
+
this[kContext].hostname = '';
|
|
7198
|
+
this._changed();
|
|
6996
7199
|
}
|
|
6997
|
-
|
|
6998
|
-
this
|
|
7200
|
+
get href() {
|
|
7201
|
+
return this.address + this.search + this.hash;
|
|
6999
7202
|
}
|
|
7000
7203
|
get password() {
|
|
7001
|
-
return this[
|
|
7204
|
+
return this[kContext].password;
|
|
7002
7205
|
}
|
|
7003
7206
|
set password(v) {
|
|
7004
|
-
this[
|
|
7207
|
+
this[kContext].password = v || '';
|
|
7208
|
+
this._changed();
|
|
7005
7209
|
}
|
|
7006
|
-
get
|
|
7007
|
-
return this.
|
|
7210
|
+
get port() {
|
|
7211
|
+
return this[kContext].port;
|
|
7008
7212
|
}
|
|
7009
|
-
set
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7213
|
+
set port(value) {
|
|
7214
|
+
if (value) {
|
|
7215
|
+
// noinspection SuspiciousTypeOfGuard
|
|
7216
|
+
const v = parseInt(value, 10);
|
|
7217
|
+
if (isNaN(v) || v < 1 || v > 35535 || v % 1 > 0)
|
|
7218
|
+
throw Object.assign(new TypeError('Invalid port'), {
|
|
7219
|
+
hostname: v,
|
|
7220
|
+
code: 'ERR_INVALID_URL'
|
|
7221
|
+
});
|
|
7222
|
+
this[kContext].port = value;
|
|
7223
|
+
}
|
|
7224
|
+
else
|
|
7225
|
+
this[kContext].port = '';
|
|
7226
|
+
this._changed();
|
|
7018
7227
|
}
|
|
7019
|
-
get
|
|
7020
|
-
return this[
|
|
7228
|
+
get prefix() {
|
|
7229
|
+
return this[kContext].prefix;
|
|
7021
7230
|
}
|
|
7022
|
-
set
|
|
7023
|
-
if (
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7231
|
+
set prefix(value) {
|
|
7232
|
+
if (value) {
|
|
7233
|
+
const url = new OpraURL(value);
|
|
7234
|
+
this[kContext].prefix = url.pathname;
|
|
7235
|
+
}
|
|
7236
|
+
else
|
|
7237
|
+
this[kContext].prefix = '';
|
|
7238
|
+
this._changed();
|
|
7029
7239
|
}
|
|
7030
|
-
get
|
|
7031
|
-
|
|
7032
|
-
return v == null ? null : v;
|
|
7240
|
+
get protocol() {
|
|
7241
|
+
return this[kContext].protocol || 'http:';
|
|
7033
7242
|
}
|
|
7034
|
-
set
|
|
7035
|
-
if (v
|
|
7036
|
-
|
|
7037
|
-
|
|
7243
|
+
set protocol(v) {
|
|
7244
|
+
if (v) {
|
|
7245
|
+
if (!schemeRegEx.test(v))
|
|
7246
|
+
throw Object.assign(new TypeError('Invalid protocol'), {
|
|
7247
|
+
protocol: v,
|
|
7248
|
+
code: 'ERR_INVALID_URL'
|
|
7249
|
+
});
|
|
7250
|
+
this[kContext].protocol = v + (v.endsWith(':') ? '' : ':');
|
|
7038
7251
|
}
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
hostname: v,
|
|
7043
|
-
code: 'ERR_INVALID_URL'
|
|
7044
|
-
});
|
|
7045
|
-
this[CONTEXT_KEY].port = v;
|
|
7252
|
+
else
|
|
7253
|
+
this[kContext].protocol = '';
|
|
7254
|
+
this._changed();
|
|
7046
7255
|
}
|
|
7047
|
-
get
|
|
7048
|
-
return this.
|
|
7256
|
+
get username() {
|
|
7257
|
+
return this[kContext].username;
|
|
7049
7258
|
}
|
|
7050
|
-
|
|
7051
|
-
|
|
7259
|
+
set username(v) {
|
|
7260
|
+
this[kContext].username = v || '';
|
|
7261
|
+
this._changed();
|
|
7052
7262
|
}
|
|
7053
|
-
|
|
7054
|
-
|
|
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 : '';
|
|
7263
|
+
get origin() {
|
|
7264
|
+
return this.hostname ? (this.protocol + '//' + this.hostname) : '';
|
|
7063
7265
|
}
|
|
7064
7266
|
get path() {
|
|
7065
|
-
return this[
|
|
7267
|
+
return this[kPath];
|
|
7066
7268
|
}
|
|
7067
7269
|
get pathname() {
|
|
7068
7270
|
this._update();
|
|
7069
|
-
return this[
|
|
7271
|
+
return this[kContext].pathname || '';
|
|
7070
7272
|
}
|
|
7071
7273
|
set pathname(v) {
|
|
7072
7274
|
this._setPathname(v, false);
|
|
7073
7275
|
}
|
|
7074
7276
|
get searchParams() {
|
|
7075
|
-
return this[
|
|
7277
|
+
return this[kSearchParams];
|
|
7076
7278
|
}
|
|
7077
7279
|
get hash() {
|
|
7078
|
-
return this[
|
|
7280
|
+
return this[kContext].hash || '';
|
|
7079
7281
|
}
|
|
7080
7282
|
set hash(v) {
|
|
7081
|
-
this[
|
|
7283
|
+
this[kContext].hash = v ? (v.startsWith('#') ? v : '#' + v) : '';
|
|
7284
|
+
this._changed();
|
|
7082
7285
|
}
|
|
7083
7286
|
get search() {
|
|
7084
7287
|
this._update();
|
|
7085
|
-
return this[
|
|
7288
|
+
return this[kContext].search || '';
|
|
7086
7289
|
}
|
|
7087
7290
|
set search(v) {
|
|
7088
|
-
this.searchParams.
|
|
7291
|
+
this.searchParams.clear();
|
|
7292
|
+
this.searchParams.appendAll(v);
|
|
7089
7293
|
}
|
|
7090
|
-
|
|
7091
|
-
|
|
7294
|
+
parse(input) {
|
|
7295
|
+
const m = urlRegEx.exec(input);
|
|
7296
|
+
if (!m)
|
|
7297
|
+
throw Object.assign(new TypeError('Invalid URL'), {
|
|
7298
|
+
input,
|
|
7299
|
+
code: 'ERR_INVALID_URL'
|
|
7300
|
+
});
|
|
7301
|
+
this.protocol = m[1];
|
|
7302
|
+
const isAbsolute = !!m[2];
|
|
7303
|
+
if (isAbsolute) {
|
|
7304
|
+
let tokens = fastTokenizer.splitString(m[2], { delimiters: '@' });
|
|
7305
|
+
if (tokens.length > 1) {
|
|
7306
|
+
this.host = tokens[1];
|
|
7307
|
+
tokens = fastTokenizer.splitString(tokens[0], { delimiters: ':' });
|
|
7308
|
+
this.username = tokens[0] ? decodeURIComponent(tokens[0]) : '';
|
|
7309
|
+
this.password = tokens[1] ? decodeURIComponent(tokens[1]) : '';
|
|
7310
|
+
}
|
|
7311
|
+
else
|
|
7312
|
+
this.host = tokens[0];
|
|
7313
|
+
}
|
|
7314
|
+
else {
|
|
7315
|
+
this.host = '';
|
|
7316
|
+
this.username = '';
|
|
7317
|
+
this.password = '';
|
|
7318
|
+
}
|
|
7319
|
+
input = m[3] || '';
|
|
7320
|
+
let tokenizer = fastTokenizer.tokenize(input, { delimiters: '#', quotes: true, brackets: true });
|
|
7321
|
+
input = tokenizer.next() || '';
|
|
7322
|
+
this.hash = tokenizer.join('#');
|
|
7323
|
+
tokenizer = fastTokenizer.tokenize(input, { delimiters: '?', quotes: true, brackets: true });
|
|
7324
|
+
this._setPathname(tokenizer.next() || '', isAbsolute);
|
|
7325
|
+
this.searchParams.clear();
|
|
7326
|
+
this.searchParams.appendAll(tokenizer.join('&'));
|
|
7327
|
+
this._changed();
|
|
7328
|
+
}
|
|
7329
|
+
join(...source) {
|
|
7330
|
+
this.path.join(...source);
|
|
7092
7331
|
return this;
|
|
7093
7332
|
}
|
|
7094
|
-
|
|
7333
|
+
addParam(name, value) {
|
|
7095
7334
|
this.searchParams.append(name, value);
|
|
7096
7335
|
return this;
|
|
7097
7336
|
}
|
|
7337
|
+
setParam(name, value) {
|
|
7338
|
+
this.searchParams.set(name, value);
|
|
7339
|
+
return this;
|
|
7340
|
+
}
|
|
7098
7341
|
setHost(v) {
|
|
7099
7342
|
this.host = v;
|
|
7100
7343
|
return this;
|
|
@@ -7108,11 +7351,11 @@ class OpraURL {
|
|
|
7108
7351
|
return this;
|
|
7109
7352
|
}
|
|
7110
7353
|
setPort(v) {
|
|
7111
|
-
this.port = v;
|
|
7354
|
+
this.port = v ? String(v) : '';
|
|
7112
7355
|
return this;
|
|
7113
7356
|
}
|
|
7114
7357
|
setPrefix(v) {
|
|
7115
|
-
this.
|
|
7358
|
+
this.prefix = v;
|
|
7116
7359
|
return this;
|
|
7117
7360
|
}
|
|
7118
7361
|
setPathname(v) {
|
|
@@ -7127,46 +7370,11 @@ class OpraURL {
|
|
|
7127
7370
|
this.search = v;
|
|
7128
7371
|
return this;
|
|
7129
7372
|
}
|
|
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
7373
|
toString() {
|
|
7166
7374
|
return this.href;
|
|
7167
7375
|
}
|
|
7168
7376
|
/* istanbul ignore next */
|
|
7169
|
-
[nodeInspectCustom]() {
|
|
7377
|
+
[(_a$1 = kContext, nodeInspectCustom$1)]() {
|
|
7170
7378
|
this._update();
|
|
7171
7379
|
return {
|
|
7172
7380
|
protocol: this.protocol,
|
|
@@ -7175,7 +7383,7 @@ class OpraURL {
|
|
|
7175
7383
|
host: this.host,
|
|
7176
7384
|
hostname: this.hostname,
|
|
7177
7385
|
origin: this.origin,
|
|
7178
|
-
pathPrefix: this.
|
|
7386
|
+
pathPrefix: this.prefix,
|
|
7179
7387
|
path: this.path,
|
|
7180
7388
|
pathname: this.pathname,
|
|
7181
7389
|
search: this.search,
|
|
@@ -7183,27 +7391,34 @@ class OpraURL {
|
|
|
7183
7391
|
hash: this.hash,
|
|
7184
7392
|
};
|
|
7185
7393
|
}
|
|
7186
|
-
_invalidate() {
|
|
7187
|
-
this[CONTEXT_KEY].needUpdate = true;
|
|
7188
|
-
}
|
|
7189
7394
|
_update() {
|
|
7190
|
-
if (!this[
|
|
7395
|
+
if (!this[kContext].needUpdate)
|
|
7191
7396
|
return;
|
|
7192
|
-
this[
|
|
7397
|
+
const ctx = this[kContext];
|
|
7398
|
+
ctx.needUpdate = false;
|
|
7193
7399
|
let s = this.path.toString();
|
|
7194
|
-
|
|
7400
|
+
ctx.pathname = s ? '/' + s : '';
|
|
7195
7401
|
s = this.searchParams.toString();
|
|
7196
|
-
|
|
7402
|
+
ctx.search = s ? '?' + s : '';
|
|
7403
|
+
let address = '';
|
|
7404
|
+
if (ctx.hostname) {
|
|
7405
|
+
address += (ctx.protocol || 'http:') + '//' +
|
|
7406
|
+
(ctx.username || ctx.password
|
|
7407
|
+
? ((ctx.username ? encodeURIComponent(ctx.username) : '') +
|
|
7408
|
+
(ctx.password ? ':' + encodeURIComponent(ctx.password) : '') + '@')
|
|
7409
|
+
: '') + this.host;
|
|
7410
|
+
}
|
|
7411
|
+
ctx.address = address + ctx.prefix + ctx.pathname;
|
|
7197
7412
|
}
|
|
7198
|
-
_setPathname(v,
|
|
7413
|
+
_setPathname(v, trimPrefix) {
|
|
7199
7414
|
this.path.clear();
|
|
7200
7415
|
if (!v)
|
|
7201
7416
|
return;
|
|
7202
7417
|
const pathTokenizer = fastTokenizer.tokenize(normalizePath(v, true), {
|
|
7203
7418
|
delimiters: '/', quotes: true, brackets: true,
|
|
7204
7419
|
});
|
|
7205
|
-
if (
|
|
7206
|
-
const prefixTokenizer = fastTokenizer.tokenize(normalizePath(this.
|
|
7420
|
+
if (trimPrefix && this.prefix) {
|
|
7421
|
+
const prefixTokenizer = fastTokenizer.tokenize(normalizePath(this.prefix, true), {
|
|
7207
7422
|
delimiters: '/', quotes: true, brackets: true,
|
|
7208
7423
|
});
|
|
7209
7424
|
for (const a of prefixTokenizer) {
|
|
@@ -7214,12 +7429,428 @@ class OpraURL {
|
|
|
7214
7429
|
}
|
|
7215
7430
|
for (const x of pathTokenizer) {
|
|
7216
7431
|
const p = decodePathComponent(x);
|
|
7217
|
-
this.path.
|
|
7432
|
+
this.path.join(p);
|
|
7218
7433
|
}
|
|
7434
|
+
this._changed();
|
|
7435
|
+
}
|
|
7436
|
+
_changed() {
|
|
7437
|
+
this[kContext].needUpdate = true;
|
|
7219
7438
|
}
|
|
7220
7439
|
}
|
|
7440
|
+
OpraURL.kContext = kContext;
|
|
7441
|
+
OpraURL.kPath = kPath;
|
|
7442
|
+
OpraURL.kSearchParams = kSearchParams;
|
|
7221
7443
|
|
|
7222
|
-
buffer.Buffer.from('\r\n');
|
|
7444
|
+
const crlfBuffer = buffer.Buffer.from('\r\n');
|
|
7445
|
+
const kHeaders = Symbol('kHeaders');
|
|
7446
|
+
const kHeadersCount = Symbol('kHeadersCount');
|
|
7447
|
+
const kTrailers = Symbol('kTrailers');
|
|
7448
|
+
const kTrailersCount = Symbol('kTrailersCount');
|
|
7449
|
+
// todo: Check is this class should be in common library
|
|
7450
|
+
class HttpRequestNode extends stream.Readable {
|
|
7451
|
+
constructor() {
|
|
7452
|
+
super(...arguments);
|
|
7453
|
+
this.aborted = false;
|
|
7454
|
+
}
|
|
7455
|
+
get headers() {
|
|
7456
|
+
if (!this[kHeaders])
|
|
7457
|
+
this[kHeaders] = arrayToHeaders(this.rawHeaders);
|
|
7458
|
+
return this[kHeaders];
|
|
7459
|
+
}
|
|
7460
|
+
get headersCount() {
|
|
7461
|
+
return this[kHeadersCount];
|
|
7462
|
+
}
|
|
7463
|
+
get trailers() {
|
|
7464
|
+
if (!this[kTrailers])
|
|
7465
|
+
this[kTrailers] = arrayToHeaders(this.rawTrailers);
|
|
7466
|
+
return this[kTrailers];
|
|
7467
|
+
}
|
|
7468
|
+
get trailersCount() {
|
|
7469
|
+
return this[kTrailersCount];
|
|
7470
|
+
}
|
|
7471
|
+
_read() {
|
|
7472
|
+
if (this.data) {
|
|
7473
|
+
this.push(this.data);
|
|
7474
|
+
}
|
|
7475
|
+
this.push(null);
|
|
7476
|
+
}
|
|
7477
|
+
static parse(input) {
|
|
7478
|
+
const parser = new httpParser.HTTPParser(httpParser.HTTPParser.REQUEST);
|
|
7479
|
+
const out = new HttpRequestNode();
|
|
7480
|
+
const bodyChunks = [];
|
|
7481
|
+
parser[httpParser.HTTPParser.kOnHeadersComplete] = function (req) {
|
|
7482
|
+
out.shouldKeepAlive = req.shouldKeepAlive;
|
|
7483
|
+
out.upgrade = req.upgrade;
|
|
7484
|
+
out.method = httpParser.HTTPParser.methods[req.method];
|
|
7485
|
+
out.url = req.url;
|
|
7486
|
+
out.originalUrl = req.url;
|
|
7487
|
+
out.httpVersionMajor = req.versionMajor;
|
|
7488
|
+
out.httpVersionMinor = req.versionMinor;
|
|
7489
|
+
out.httpVersion = req.versionMajor + '.' + req.versionMinor;
|
|
7490
|
+
out.rawHeaders = req.headers;
|
|
7491
|
+
out[kHeadersCount] = Math.ceil(req.headers.length / 2);
|
|
7492
|
+
out[kTrailersCount] = 0;
|
|
7493
|
+
};
|
|
7494
|
+
parser[httpParser.HTTPParser.kOnBody] = function (chunk, offset, length) {
|
|
7495
|
+
bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
7496
|
+
};
|
|
7497
|
+
// This is actually the event for trailers, go figure.
|
|
7498
|
+
parser[httpParser.HTTPParser.kOnHeaders] = function (t) {
|
|
7499
|
+
out.rawTrailers = t;
|
|
7500
|
+
out[kTrailersCount] = Math.ceil(t.length / 2);
|
|
7501
|
+
};
|
|
7502
|
+
parser[httpParser.HTTPParser.kOnMessageComplete] = function () {
|
|
7503
|
+
out.complete = true;
|
|
7504
|
+
};
|
|
7505
|
+
// Since we are sending the entire Buffer at once here all callbacks above happen synchronously.
|
|
7506
|
+
// The parser does not do _anything_ asynchronous.
|
|
7507
|
+
// However, you can of course call execute() multiple times with multiple chunks, e.g. from a stream.
|
|
7508
|
+
// But then you have to refactor the entire logic to be async (e.g. resolve a Promise in kOnMessageComplete and add timeout logic).
|
|
7509
|
+
parser.execute(input);
|
|
7510
|
+
if (!out.complete)
|
|
7511
|
+
parser.execute(crlfBuffer);
|
|
7512
|
+
parser.finish();
|
|
7513
|
+
if (!out.complete) {
|
|
7514
|
+
throw new Error('Could not parse request');
|
|
7515
|
+
}
|
|
7516
|
+
out.rawTrailers = out.rawTrailers || [];
|
|
7517
|
+
if (bodyChunks.length)
|
|
7518
|
+
out.data = buffer.Buffer.concat(bodyChunks);
|
|
7519
|
+
out.resume();
|
|
7520
|
+
return out;
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
function arrayToHeaders(arr) {
|
|
7524
|
+
const headers = {};
|
|
7525
|
+
for (let i = 0; i < arr.length; i++) {
|
|
7526
|
+
const k = arr[i].toLowerCase();
|
|
7527
|
+
const v = arr[++i];
|
|
7528
|
+
const trgV = headers[k];
|
|
7529
|
+
// Array header -- only Set-Cookie at the moment
|
|
7530
|
+
if (trgV && k === 'set-cookie') {
|
|
7531
|
+
const a = Array.isArray(trgV) ? trgV : [trgV];
|
|
7532
|
+
a.push(v);
|
|
7533
|
+
headers[k] = a;
|
|
7534
|
+
}
|
|
7535
|
+
else if (typeof trgV === 'string') {
|
|
7536
|
+
headers[k] += (k === 'cookie' ? '; ' : ', ') + v;
|
|
7537
|
+
}
|
|
7538
|
+
else
|
|
7539
|
+
headers[k] = v;
|
|
7540
|
+
}
|
|
7541
|
+
return headers;
|
|
7542
|
+
}
|
|
7543
|
+
|
|
7544
|
+
var _a, _b;
|
|
7545
|
+
const knownKeys = Object.keys(exports.HttpHeaderCodes);
|
|
7546
|
+
const knownKeysLower = knownKeys.map(x => x.toLowerCase());
|
|
7547
|
+
const nodeInspectCustom = Symbol.for('nodejs.util.inspect.custom');
|
|
7548
|
+
const kEntries = Symbol('kEntries');
|
|
7549
|
+
const kSize = Symbol('kSize');
|
|
7550
|
+
const kOptions = Symbol('kOptions');
|
|
7551
|
+
class HttpHeaders {
|
|
7552
|
+
constructor(init, options) {
|
|
7553
|
+
this[_a] = new ResponsiveMap();
|
|
7554
|
+
this[_b] = 0;
|
|
7555
|
+
this[kOptions] = { ...options, onChange: undefined };
|
|
7556
|
+
if (init)
|
|
7557
|
+
this.appendAll(init);
|
|
7558
|
+
this[kOptions].onChange = options?.onChange;
|
|
7559
|
+
}
|
|
7560
|
+
get size() {
|
|
7561
|
+
return this[kSize];
|
|
7562
|
+
}
|
|
7563
|
+
/**
|
|
7564
|
+
* Appends a new value to the existing set of values for a header
|
|
7565
|
+
* and returns this instance
|
|
7566
|
+
*/
|
|
7567
|
+
append(name, value) {
|
|
7568
|
+
this._append(name, value);
|
|
7569
|
+
this.changed();
|
|
7570
|
+
return this;
|
|
7571
|
+
}
|
|
7572
|
+
/**
|
|
7573
|
+
* Appends multiple values to the existing set of values for a header
|
|
7574
|
+
* and returns this instance
|
|
7575
|
+
*/
|
|
7576
|
+
appendAll(headers) {
|
|
7577
|
+
if (typeof headers === 'string') {
|
|
7578
|
+
headers.split('\n').forEach(line => {
|
|
7579
|
+
const index = line.indexOf(':');
|
|
7580
|
+
if (index > 0) {
|
|
7581
|
+
const name = line.slice(0, index);
|
|
7582
|
+
const value = line.slice(index + 1).trim();
|
|
7583
|
+
this._append(name, value);
|
|
7584
|
+
}
|
|
7585
|
+
});
|
|
7586
|
+
}
|
|
7587
|
+
else if (headers.forEach && typeof headers.forEach === 'function')
|
|
7588
|
+
headers.forEach((value, name) => this._append(name, value));
|
|
7589
|
+
else
|
|
7590
|
+
Object.keys(headers).forEach(name => this._append(name, headers[name]));
|
|
7591
|
+
this.changed();
|
|
7592
|
+
return this;
|
|
7593
|
+
}
|
|
7594
|
+
changed() {
|
|
7595
|
+
if (this[kOptions].onChange)
|
|
7596
|
+
this[kOptions].onChange();
|
|
7597
|
+
}
|
|
7598
|
+
clear() {
|
|
7599
|
+
if (this[kEntries].size) {
|
|
7600
|
+
this[kEntries].clear();
|
|
7601
|
+
this[kSize] = 0;
|
|
7602
|
+
this.changed();
|
|
7603
|
+
}
|
|
7604
|
+
}
|
|
7605
|
+
/**
|
|
7606
|
+
* Deletes values for a given header
|
|
7607
|
+
*/
|
|
7608
|
+
delete(name, value) {
|
|
7609
|
+
if (this._delete(name, value))
|
|
7610
|
+
this.changed();
|
|
7611
|
+
return this;
|
|
7612
|
+
}
|
|
7613
|
+
/**
|
|
7614
|
+
* Returns an iterable of key, value pairs for every entry in the map.
|
|
7615
|
+
*/
|
|
7616
|
+
entries() {
|
|
7617
|
+
const iter = this[kEntries].entries();
|
|
7618
|
+
let i = 0;
|
|
7619
|
+
let key;
|
|
7620
|
+
let values;
|
|
7621
|
+
return {
|
|
7622
|
+
[Symbol.iterator]() {
|
|
7623
|
+
return this;
|
|
7624
|
+
},
|
|
7625
|
+
next() {
|
|
7626
|
+
if (values) {
|
|
7627
|
+
if (i >= values.length) {
|
|
7628
|
+
values = undefined;
|
|
7629
|
+
i = 0;
|
|
7630
|
+
}
|
|
7631
|
+
}
|
|
7632
|
+
if (!values) {
|
|
7633
|
+
const n = iter.next();
|
|
7634
|
+
if (n.done)
|
|
7635
|
+
return { done: true, value: undefined };
|
|
7636
|
+
key = n.value[0];
|
|
7637
|
+
values = n.value[1];
|
|
7638
|
+
}
|
|
7639
|
+
return {
|
|
7640
|
+
done: false,
|
|
7641
|
+
value: [key, values[i++]]
|
|
7642
|
+
};
|
|
7643
|
+
}
|
|
7644
|
+
};
|
|
7645
|
+
}
|
|
7646
|
+
forEach(callbackFn, thisArg) {
|
|
7647
|
+
const iterator = this.entries();
|
|
7648
|
+
let entry = iterator.next();
|
|
7649
|
+
while (!entry.done) {
|
|
7650
|
+
callbackFn.call(thisArg || this, entry.value[1], entry.value[0], this);
|
|
7651
|
+
entry = iterator.next();
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
/**
|
|
7655
|
+
* Retrieves value of a given header at given index
|
|
7656
|
+
*/
|
|
7657
|
+
get(name, index = 0) {
|
|
7658
|
+
const values = this[kEntries].get(name.toLowerCase());
|
|
7659
|
+
return values && values.length > index ? values[index] : null;
|
|
7660
|
+
}
|
|
7661
|
+
/**
|
|
7662
|
+
* Retrieves an array of values for a given header.
|
|
7663
|
+
*/
|
|
7664
|
+
getAll(name) {
|
|
7665
|
+
const entry = this[kEntries].get(name);
|
|
7666
|
+
return entry ? entry.slice(0) : null;
|
|
7667
|
+
}
|
|
7668
|
+
/**
|
|
7669
|
+
* Retrieves the names of the headers.
|
|
7670
|
+
*/
|
|
7671
|
+
keys() {
|
|
7672
|
+
return this[kEntries].keys();
|
|
7673
|
+
}
|
|
7674
|
+
/**
|
|
7675
|
+
* Checks for existence of a given header.
|
|
7676
|
+
*/
|
|
7677
|
+
has(name) {
|
|
7678
|
+
return this[kEntries].has(name);
|
|
7679
|
+
}
|
|
7680
|
+
/**
|
|
7681
|
+
* Sets or modifies a value for a given header.
|
|
7682
|
+
* If the header already exists, its value is replaced with the given value
|
|
7683
|
+
*/
|
|
7684
|
+
set(name, value) {
|
|
7685
|
+
this._set(name, String(value));
|
|
7686
|
+
this.changed();
|
|
7687
|
+
return this;
|
|
7688
|
+
}
|
|
7689
|
+
sort(compareFn) {
|
|
7690
|
+
this[kEntries].sort(compareFn);
|
|
7691
|
+
this.changed();
|
|
7692
|
+
return this;
|
|
7693
|
+
}
|
|
7694
|
+
_append(name, value) {
|
|
7695
|
+
const i = knownKeysLower.indexOf(name);
|
|
7696
|
+
const normalizedName = knownKeys[i] || name;
|
|
7697
|
+
let values = this[kEntries].get(normalizedName);
|
|
7698
|
+
if (!values) {
|
|
7699
|
+
values = [];
|
|
7700
|
+
this[kEntries].set(normalizedName, values);
|
|
7701
|
+
}
|
|
7702
|
+
const oldSize = values.length;
|
|
7703
|
+
if (Array.isArray(value))
|
|
7704
|
+
values.push(...value.map(x => String(x)));
|
|
7705
|
+
else
|
|
7706
|
+
values.push(String(value));
|
|
7707
|
+
this[kSize] = -oldSize + values.length;
|
|
7708
|
+
}
|
|
7709
|
+
_delete(name, value) {
|
|
7710
|
+
const oldValues = this[kEntries].get(name);
|
|
7711
|
+
if (!oldValues)
|
|
7712
|
+
return false;
|
|
7713
|
+
const oldSize = this[kSize];
|
|
7714
|
+
if (value) {
|
|
7715
|
+
const valueToDelete = Array.isArray(value) ? value.map(x => String(x)) : [String(value)];
|
|
7716
|
+
const newValues = oldValues.filter(x => !valueToDelete.includes(x));
|
|
7717
|
+
this[kEntries].set(name, newValues);
|
|
7718
|
+
this[kSize] += -oldValues.length + newValues.length;
|
|
7719
|
+
}
|
|
7720
|
+
else {
|
|
7721
|
+
this[kEntries].delete(name);
|
|
7722
|
+
this[kSize] -= oldValues.length;
|
|
7723
|
+
}
|
|
7724
|
+
return oldSize !== this[kSize];
|
|
7725
|
+
}
|
|
7726
|
+
_set(name, value) {
|
|
7727
|
+
if (value == null) {
|
|
7728
|
+
this._delete(name);
|
|
7729
|
+
return;
|
|
7730
|
+
}
|
|
7731
|
+
const oldValues = this[kEntries].get(name);
|
|
7732
|
+
const i = knownKeysLower.indexOf(name);
|
|
7733
|
+
const normalizedName = knownKeys[i] || name;
|
|
7734
|
+
const newValues = Array.isArray(value) ? value : [value];
|
|
7735
|
+
this[kEntries].set(normalizedName, newValues);
|
|
7736
|
+
this[kSize] += -(oldValues?.length || 0) + newValues.length;
|
|
7737
|
+
}
|
|
7738
|
+
[(_a = kEntries, _b = kSize, nodeInspectCustom)]() {
|
|
7739
|
+
return this[kEntries];
|
|
7740
|
+
}
|
|
7741
|
+
[Symbol.iterator]() {
|
|
7742
|
+
return this.entries();
|
|
7743
|
+
}
|
|
7744
|
+
get [Symbol.toStringTag]() {
|
|
7745
|
+
return 'HttpHeaders';
|
|
7746
|
+
}
|
|
7747
|
+
}
|
|
7748
|
+
HttpHeaders.kEntries = kEntries;
|
|
7749
|
+
HttpHeaders.kSize = kSize;
|
|
7750
|
+
HttpHeaders.kOptions = kOptions;
|
|
7751
|
+
|
|
7752
|
+
/// <reference lib="dom" />
|
|
7753
|
+
const directCopyProperties = ['cache', 'credentials', 'destination', 'headers', 'integrity',
|
|
7754
|
+
'keepalive', 'mode', 'redirect', 'referrer', 'referrerPolicy'];
|
|
7755
|
+
class HttpRequest {
|
|
7756
|
+
constructor(init) {
|
|
7757
|
+
this.cache = init?.cache || 'default';
|
|
7758
|
+
this.credentials = init?.credentials || 'same-origin';
|
|
7759
|
+
this.destination = init?.destination || '';
|
|
7760
|
+
this.headers = new HttpHeaders(init?.headers);
|
|
7761
|
+
this.integrity = init?.integrity || '';
|
|
7762
|
+
this.keepalive = init?.keepalive ?? false;
|
|
7763
|
+
this.method = (init?.method || 'GET').toUpperCase();
|
|
7764
|
+
this.mode = init?.mode || 'cors';
|
|
7765
|
+
this.redirect = init?.redirect || 'follow';
|
|
7766
|
+
this.mode = init?.mode || 'cors';
|
|
7767
|
+
this.referrer = init?.referrer || '';
|
|
7768
|
+
this.referrerPolicy = init?.referrerPolicy || '';
|
|
7769
|
+
this.signal = init?.signal || new AbortController().signal;
|
|
7770
|
+
this.body = init?.body;
|
|
7771
|
+
this.urlInstance = new OpraURL(init?.url);
|
|
7772
|
+
if (init?.params)
|
|
7773
|
+
this.params.appendAll(init.params);
|
|
7774
|
+
}
|
|
7775
|
+
/** Returns the URL of request as a string. */
|
|
7776
|
+
get url() {
|
|
7777
|
+
return this.urlInstance.href;
|
|
7778
|
+
}
|
|
7779
|
+
set url(value) {
|
|
7780
|
+
this.urlInstance.parse(value);
|
|
7781
|
+
}
|
|
7782
|
+
/** Returns the searchParams of the URL as OpraURLSearchParams */
|
|
7783
|
+
get params() {
|
|
7784
|
+
return this.urlInstance.searchParams;
|
|
7785
|
+
}
|
|
7786
|
+
/** Returns the path part of URL as OpraURLPath */
|
|
7787
|
+
get path() {
|
|
7788
|
+
return this.urlInstance.path;
|
|
7789
|
+
}
|
|
7790
|
+
clone(...update) {
|
|
7791
|
+
const out = new HttpRequest();
|
|
7792
|
+
out.merge(this);
|
|
7793
|
+
for (const upd of update) {
|
|
7794
|
+
out.merge(upd);
|
|
7795
|
+
}
|
|
7796
|
+
return out;
|
|
7797
|
+
}
|
|
7798
|
+
merge(update) {
|
|
7799
|
+
directCopyProperties.forEach(k => {
|
|
7800
|
+
if (update[k] != null)
|
|
7801
|
+
this[k] = update[k];
|
|
7802
|
+
});
|
|
7803
|
+
if (update.headers) {
|
|
7804
|
+
const h = update.headers instanceof HttpHeaders
|
|
7805
|
+
? update.headers
|
|
7806
|
+
: new HttpHeaders(update.headers);
|
|
7807
|
+
h.forEach((v, k) => {
|
|
7808
|
+
if (k.toLowerCase() === 'set-cookie') {
|
|
7809
|
+
this.headers.append(k, v);
|
|
7810
|
+
}
|
|
7811
|
+
else
|
|
7812
|
+
this.headers.set(k, v);
|
|
7813
|
+
});
|
|
7814
|
+
}
|
|
7815
|
+
}
|
|
7816
|
+
inset(src) {
|
|
7817
|
+
directCopyProperties.forEach(k => {
|
|
7818
|
+
if (this[k] == null && src[k] != null)
|
|
7819
|
+
this[k] = src[k];
|
|
7820
|
+
});
|
|
7821
|
+
if (src.headers) {
|
|
7822
|
+
const h = src.headers instanceof HttpHeaders
|
|
7823
|
+
? src.headers
|
|
7824
|
+
: new HttpHeaders(src.headers);
|
|
7825
|
+
h.forEach((v, k) => {
|
|
7826
|
+
if (k.toLowerCase() === 'set-cookie') {
|
|
7827
|
+
this.headers.append(k, v);
|
|
7828
|
+
}
|
|
7829
|
+
else if (!this.headers.has(k))
|
|
7830
|
+
this.headers.set(k, v);
|
|
7831
|
+
});
|
|
7832
|
+
}
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
|
|
7836
|
+
class HttpResponse {
|
|
7837
|
+
constructor(init) {
|
|
7838
|
+
/**
|
|
7839
|
+
* Returns true if response has body to be received
|
|
7840
|
+
*/
|
|
7841
|
+
this.hasBody = false;
|
|
7842
|
+
this.headers = new HttpHeaders(init?.headers);
|
|
7843
|
+
this.status = init?.status || 200;
|
|
7844
|
+
this.statusText = init?.statusText || 'OK';
|
|
7845
|
+
this.url = init?.url || null;
|
|
7846
|
+
this.ok = this.status >= 200 && this.status < 300;
|
|
7847
|
+
this.body = init?.body;
|
|
7848
|
+
this.hasBody = init?.body != null || !!init?.hasBody;
|
|
7849
|
+
}
|
|
7850
|
+
clone(update) {
|
|
7851
|
+
return new HttpResponse({ ...this, ...update });
|
|
7852
|
+
}
|
|
7853
|
+
}
|
|
7223
7854
|
|
|
7224
7855
|
class ClientError extends Error {
|
|
7225
7856
|
constructor(init, cause) {
|
|
@@ -7239,259 +7870,146 @@ const JSON_CONTENT_TYPE_PATTERN = /^application\/([\w-]+\+)?\bjson\b/i;
|
|
|
7239
7870
|
const TEXT_CONTENT_TYPE_PATTERN = /^text\/.*$/i;
|
|
7240
7871
|
const FORMDATA_CONTENT_TYPE_PATTERN = /^multipart\/\bform-data\b/i;
|
|
7241
7872
|
|
|
7242
|
-
|
|
7243
|
-
|
|
7873
|
+
const kHandler = Symbol('kHandler');
|
|
7874
|
+
const kRequest = Symbol('kRequest');
|
|
7875
|
+
class HttpRequestHost extends rxjs.Observable {
|
|
7876
|
+
constructor(handler, options) {
|
|
7244
7877
|
super((subscriber) => {
|
|
7245
|
-
|
|
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));
|
|
7878
|
+
handler(options?.observe || 'body', this[kRequest]).subscribe((subscriber));
|
|
7256
7879
|
});
|
|
7257
|
-
this
|
|
7258
|
-
this
|
|
7880
|
+
this[kHandler] = handler;
|
|
7881
|
+
this[kRequest] = new HttpRequest(options?.http);
|
|
7259
7882
|
this.contentId = uid.uid(6);
|
|
7260
|
-
this.options = options;
|
|
7261
7883
|
}
|
|
7262
7884
|
header(name, value) {
|
|
7263
|
-
this.
|
|
7264
|
-
this._headers[name] = value;
|
|
7885
|
+
this[kRequest].headers.append(name, value);
|
|
7265
7886
|
return this;
|
|
7266
7887
|
}
|
|
7267
|
-
|
|
7268
|
-
|
|
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;
|
|
7888
|
+
param(name, value) {
|
|
7889
|
+
this[kRequest].params.append(name, value);
|
|
7890
|
+
return this;
|
|
7277
7891
|
}
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
*/
|
|
7281
|
-
async resolve() {
|
|
7282
|
-
const resp = await this.fetch();
|
|
7283
|
-
return resp.data;
|
|
7892
|
+
async fetch(observe) {
|
|
7893
|
+
return rxjs.lastValueFrom(this[kHandler](observe || 'body', this[kRequest]));
|
|
7284
7894
|
}
|
|
7285
7895
|
with(cb) {
|
|
7286
7896
|
cb(this);
|
|
7287
7897
|
return this;
|
|
7288
7898
|
}
|
|
7289
|
-
binding() {
|
|
7290
|
-
return {};
|
|
7291
|
-
}
|
|
7292
|
-
async _execute() {
|
|
7293
|
-
const req = this.prepare();
|
|
7294
|
-
return await this._handler(req);
|
|
7295
|
-
}
|
|
7296
|
-
}
|
|
7297
|
-
|
|
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
7899
|
}
|
|
7900
|
+
HttpRequestHost.kHandler = kHandler;
|
|
7901
|
+
HttpRequestHost.kRequest = kRequest;
|
|
7322
7902
|
|
|
7323
|
-
class CollectionCreateRequest extends
|
|
7324
|
-
constructor(
|
|
7325
|
-
super(
|
|
7326
|
-
this._handler = _handler;
|
|
7903
|
+
class CollectionCreateRequest extends HttpRequestHost {
|
|
7904
|
+
constructor(handler, resource, data, options) {
|
|
7905
|
+
super(handler, options);
|
|
7327
7906
|
this.resource = resource;
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
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;
|
|
7352
|
-
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);
|
|
7907
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7908
|
+
request.method = 'POST';
|
|
7909
|
+
request.url = this.resource.name;
|
|
7910
|
+
request.body = data;
|
|
7911
|
+
if (options?.include)
|
|
7912
|
+
request.params.set('$include', options.include);
|
|
7913
|
+
if (options?.pick)
|
|
7914
|
+
request.params.set('$pick', options.pick);
|
|
7915
|
+
if (options?.omit)
|
|
7916
|
+
request.params.set('$omit', options.omit);
|
|
7364
7917
|
}
|
|
7365
7918
|
}
|
|
7366
7919
|
|
|
7367
|
-
class
|
|
7368
|
-
constructor(
|
|
7369
|
-
super(
|
|
7370
|
-
this._handler = _handler;
|
|
7920
|
+
class CollectionDeleteManyRequest extends HttpRequestHost {
|
|
7921
|
+
constructor(handler, resource, options) {
|
|
7922
|
+
super(handler, options);
|
|
7371
7923
|
this.resource = resource;
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
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);
|
|
7924
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7925
|
+
request.method = 'DELETE';
|
|
7926
|
+
request.url = this.resource.name;
|
|
7927
|
+
if (options?.filter)
|
|
7928
|
+
request.params.set('$filter', options.filter);
|
|
7383
7929
|
}
|
|
7384
7930
|
}
|
|
7385
7931
|
|
|
7386
|
-
class
|
|
7387
|
-
constructor(
|
|
7388
|
-
super(
|
|
7389
|
-
this._handler = _handler;
|
|
7932
|
+
class CollectionDeleteRequest extends HttpRequestHost {
|
|
7933
|
+
constructor(handler, resource, id, options) {
|
|
7934
|
+
super(handler, options);
|
|
7390
7935
|
this.resource = resource;
|
|
7391
|
-
|
|
7392
|
-
|
|
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);
|
|
7936
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7937
|
+
request.method = 'DELETE';
|
|
7938
|
+
request.path.join({ resource: this.resource.name, key: id });
|
|
7410
7939
|
}
|
|
7411
7940
|
}
|
|
7412
7941
|
|
|
7413
|
-
class
|
|
7414
|
-
constructor(
|
|
7415
|
-
super(
|
|
7416
|
-
this._handler = _handler;
|
|
7942
|
+
class CollectionGetRequest extends HttpRequestHost {
|
|
7943
|
+
constructor(handler, resource, id, options) {
|
|
7944
|
+
super(handler, options);
|
|
7417
7945
|
this.resource = resource;
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
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);
|
|
7946
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7947
|
+
request.method = 'GET';
|
|
7948
|
+
request.path.join({ resource: this.resource.name, key: id });
|
|
7949
|
+
if (options?.include)
|
|
7950
|
+
request.params.set('$include', options.include);
|
|
7951
|
+
if (options?.pick)
|
|
7952
|
+
request.params.set('$pick', options.pick);
|
|
7953
|
+
if (options?.omit)
|
|
7954
|
+
request.params.set('$omit', options.omit);
|
|
7445
7955
|
}
|
|
7446
7956
|
}
|
|
7447
7957
|
|
|
7448
|
-
class
|
|
7449
|
-
constructor(
|
|
7450
|
-
super(
|
|
7451
|
-
this._handler = _handler;
|
|
7958
|
+
class CollectionSearchRequest extends HttpRequestHost {
|
|
7959
|
+
constructor(handler, resource, options) {
|
|
7960
|
+
super(handler, options);
|
|
7452
7961
|
this.resource = resource;
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
if (
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
params
|
|
7464
|
-
|
|
7465
|
-
|
|
7962
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7963
|
+
request.method = 'GET';
|
|
7964
|
+
request.url = this.resource.name;
|
|
7965
|
+
if (options?.include)
|
|
7966
|
+
request.params.set('$include', options.include);
|
|
7967
|
+
if (options?.pick)
|
|
7968
|
+
request.params.set('$pick', options.pick);
|
|
7969
|
+
if (options?.omit)
|
|
7970
|
+
request.params.set('$omit', options.omit);
|
|
7971
|
+
if (options?.sort)
|
|
7972
|
+
request.params.set('$sort', options.sort);
|
|
7973
|
+
if (options?.filter)
|
|
7974
|
+
request.params.set('$filter', options.filter);
|
|
7975
|
+
if (options?.limit != null)
|
|
7976
|
+
request.params.set('$limit', options.limit);
|
|
7977
|
+
if (options?.skip != null)
|
|
7978
|
+
request.params.set('$skip', options.skip);
|
|
7979
|
+
if (options?.count != null)
|
|
7980
|
+
request.params.set('$count', options.count);
|
|
7981
|
+
if (options?.distinct != null)
|
|
7982
|
+
request.params.set('$distinct', options.distinct);
|
|
7983
|
+
}
|
|
7984
|
+
}
|
|
7985
|
+
|
|
7986
|
+
class CollectionUpdateManyRequest extends HttpRequestHost {
|
|
7987
|
+
constructor(handler, resource, data, options) {
|
|
7988
|
+
super(handler, options);
|
|
7989
|
+
this.resource = resource;
|
|
7990
|
+
const request = this[HttpRequestHost.kRequest];
|
|
7991
|
+
request.method = 'PATCH';
|
|
7992
|
+
request.url = this.resource.name;
|
|
7993
|
+
request.body = data;
|
|
7994
|
+
if (options?.filter)
|
|
7995
|
+
request.params.set('$filter', options.filter);
|
|
7466
7996
|
}
|
|
7467
7997
|
}
|
|
7468
7998
|
|
|
7469
|
-
class CollectionUpdateRequest extends
|
|
7470
|
-
constructor(
|
|
7471
|
-
super(
|
|
7472
|
-
this._handler = _handler;
|
|
7999
|
+
class CollectionUpdateRequest extends HttpRequestHost {
|
|
8000
|
+
constructor(handler, resource, id, data, options) {
|
|
8001
|
+
super(handler, options);
|
|
7473
8002
|
this.resource = resource;
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
this.
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
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);
|
|
8003
|
+
const request = this[HttpRequestHost.kRequest];
|
|
8004
|
+
request.method = 'PATCH';
|
|
8005
|
+
request.path.join({ resource: this.resource.name, key: id });
|
|
8006
|
+
request.body = data;
|
|
8007
|
+
if (options?.include)
|
|
8008
|
+
request.params.set('$include', options.include);
|
|
8009
|
+
if (options?.pick)
|
|
8010
|
+
request.params.set('$pick', options.pick);
|
|
8011
|
+
if (options?.omit)
|
|
8012
|
+
request.params.set('$omit', options.omit);
|
|
7495
8013
|
}
|
|
7496
8014
|
}
|
|
7497
8015
|
|
|
@@ -7503,133 +8021,68 @@ class HttpCollectionService {
|
|
|
7503
8021
|
create(data, options) {
|
|
7504
8022
|
return new CollectionCreateRequest(this._handler, this.resource, data, options);
|
|
7505
8023
|
}
|
|
7506
|
-
delete(
|
|
7507
|
-
return new CollectionDeleteRequest(this._handler, this.resource,
|
|
8024
|
+
delete(id, options) {
|
|
8025
|
+
return new CollectionDeleteRequest(this._handler, this.resource, id, options);
|
|
7508
8026
|
}
|
|
7509
8027
|
deleteMany(options) {
|
|
7510
8028
|
return new CollectionDeleteManyRequest(this._handler, this.resource, options);
|
|
7511
8029
|
}
|
|
7512
|
-
get(
|
|
7513
|
-
return new CollectionGetRequest(this._handler, this.resource,
|
|
8030
|
+
get(id, options) {
|
|
8031
|
+
return new CollectionGetRequest(this._handler, this.resource, id, options);
|
|
7514
8032
|
}
|
|
7515
8033
|
search(options) {
|
|
7516
8034
|
return new CollectionSearchRequest(this._handler, this.resource, options);
|
|
7517
8035
|
}
|
|
7518
|
-
update(
|
|
7519
|
-
return new CollectionUpdateRequest(this._handler, this.resource,
|
|
8036
|
+
update(id, data, options) {
|
|
8037
|
+
return new CollectionUpdateRequest(this._handler, this.resource, id, data, options);
|
|
7520
8038
|
}
|
|
7521
8039
|
updateMany(data, options) {
|
|
7522
8040
|
return new CollectionUpdateManyRequest(this._handler, this.resource, data, options);
|
|
7523
8041
|
}
|
|
7524
8042
|
}
|
|
7525
8043
|
|
|
7526
|
-
class
|
|
7527
|
-
constructor(
|
|
7528
|
-
super(
|
|
7529
|
-
this._handler = _handler;
|
|
8044
|
+
class SingletonDeleteRequest extends HttpRequestHost {
|
|
8045
|
+
constructor(handler, resource, options) {
|
|
8046
|
+
super(handler, options);
|
|
7530
8047
|
this.resource = resource;
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
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);
|
|
8048
|
+
const request = this[HttpRequestHost.kRequest];
|
|
8049
|
+
request.method = 'DELETE';
|
|
8050
|
+
request.url = this.resource.name;
|
|
7546
8051
|
}
|
|
7547
8052
|
}
|
|
7548
8053
|
|
|
7549
|
-
class
|
|
7550
|
-
constructor(resource,
|
|
8054
|
+
class SingletonGetRequest extends HttpRequestHost {
|
|
8055
|
+
constructor(handler, resource, options) {
|
|
8056
|
+
super(handler, options);
|
|
7551
8057
|
this.resource = resource;
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
8058
|
+
const request = this[HttpRequestHost.kRequest];
|
|
8059
|
+
request.method = 'GET';
|
|
8060
|
+
request.url = this.resource.name;
|
|
8061
|
+
if (options?.include)
|
|
8062
|
+
request.params.set('$include', options.include);
|
|
8063
|
+
if (options?.pick)
|
|
8064
|
+
request.params.set('$pick', options.pick);
|
|
8065
|
+
if (options?.omit)
|
|
8066
|
+
request.params.set('$omit', options.omit);
|
|
7556
8067
|
}
|
|
7557
8068
|
}
|
|
7558
8069
|
|
|
7559
|
-
class
|
|
7560
|
-
constructor(
|
|
7561
|
-
|
|
8070
|
+
class HttpSingletonService {
|
|
8071
|
+
constructor(resource, _handler) {
|
|
8072
|
+
this.resource = resource;
|
|
7562
8073
|
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
8074
|
}
|
|
7593
|
-
|
|
7594
|
-
|
|
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;
|
|
8075
|
+
get(options) {
|
|
8076
|
+
return new SingletonGetRequest(this._handler, this.resource, options);
|
|
7622
8077
|
}
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
const resp = await this._handler(req);
|
|
7626
|
-
return resp;
|
|
8078
|
+
delete(options) {
|
|
8079
|
+
return new SingletonDeleteRequest(this._handler, this.resource, options);
|
|
7627
8080
|
}
|
|
7628
8081
|
}
|
|
7629
8082
|
|
|
7630
8083
|
const documentCache = new Map();
|
|
7631
8084
|
const documentResolverCaches = new Map();
|
|
7632
|
-
class
|
|
8085
|
+
class OpraHttpClientBase {
|
|
7633
8086
|
constructor(serviceUrl, options) {
|
|
7634
8087
|
this._serviceUrl = serviceUrl;
|
|
7635
8088
|
this._metadata = options?.document;
|
|
@@ -7638,7 +8091,13 @@ class OpraHttpClient {
|
|
|
7638
8091
|
if (document)
|
|
7639
8092
|
this._metadata = document;
|
|
7640
8093
|
}
|
|
7641
|
-
this.defaults =
|
|
8094
|
+
this.defaults = {
|
|
8095
|
+
...options?.defaults,
|
|
8096
|
+
headers: options?.defaults?.headers instanceof HttpHeaders
|
|
8097
|
+
? options?.defaults?.headers : new HttpHeaders(options?.defaults?.headers),
|
|
8098
|
+
params: options?.defaults?.params instanceof HttpParams
|
|
8099
|
+
? options?.defaults?.params : new HttpParams(options?.defaults?.headers)
|
|
8100
|
+
};
|
|
7642
8101
|
}
|
|
7643
8102
|
get serviceUrl() {
|
|
7644
8103
|
return this._serviceUrl;
|
|
@@ -7666,17 +8125,17 @@ class OpraHttpClient {
|
|
|
7666
8125
|
.catch(() => void 0)
|
|
7667
8126
|
.finally(() => documentResolverCaches.delete(cacheName));
|
|
7668
8127
|
}
|
|
7669
|
-
batch(requests) {
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
}
|
|
8128
|
+
// batch(requests: HttpRequestHost<any>[]): BatchRequest {
|
|
8129
|
+
// this._assertMetadata();
|
|
8130
|
+
// return new BatchRequest(request => this._sendRequest('response', request, requests);
|
|
8131
|
+
// }
|
|
7673
8132
|
collection(name) {
|
|
7674
8133
|
this._assertMetadata();
|
|
7675
8134
|
// If name argument is a class, we extract name from the class
|
|
7676
8135
|
if (typeof name === 'function')
|
|
7677
8136
|
name = name.name;
|
|
7678
8137
|
const resource = this.metadata.getCollectionResource(name);
|
|
7679
|
-
return new HttpCollectionService(resource,
|
|
8138
|
+
return new HttpCollectionService(resource, this._sendRequest.bind(this));
|
|
7680
8139
|
}
|
|
7681
8140
|
singleton(name) {
|
|
7682
8141
|
this._assertMetadata();
|
|
@@ -7684,87 +8143,138 @@ class OpraHttpClient {
|
|
|
7684
8143
|
if (typeof name === 'function')
|
|
7685
8144
|
name = name.name;
|
|
7686
8145
|
const resource = this.metadata.getSingletonResource(name);
|
|
7687
|
-
return new HttpSingletonService(resource,
|
|
8146
|
+
return new HttpSingletonService(resource, this._sendRequest.bind(this));
|
|
7688
8147
|
}
|
|
7689
8148
|
async _resolveMetadata() {
|
|
7690
|
-
const
|
|
8149
|
+
const body = await rxjs.lastValueFrom(this._sendRequest('body', new HttpRequest({
|
|
7691
8150
|
method: 'GET',
|
|
7692
|
-
|
|
7693
|
-
headers: { 'accept': 'application/json' }
|
|
7694
|
-
});
|
|
7695
|
-
this._metadata = new OpraDocument(
|
|
7696
|
-
}
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
if (
|
|
7706
|
-
|
|
7707
|
-
|
|
8151
|
+
url: '$metadata',
|
|
8152
|
+
headers: new HttpHeaders({ 'accept': 'application/json' })
|
|
8153
|
+
})));
|
|
8154
|
+
this._metadata = new OpraDocument(body);
|
|
8155
|
+
}
|
|
8156
|
+
_sendRequest(observe, request) {
|
|
8157
|
+
return new rxjs.Observable(subscriber => {
|
|
8158
|
+
try {
|
|
8159
|
+
request.inset(this.defaults);
|
|
8160
|
+
const url = request.url.includes('://') ? request.url : joinPath(this.serviceUrl, request.url);
|
|
8161
|
+
let body;
|
|
8162
|
+
if (request.body) {
|
|
8163
|
+
let contentType = request.headers.get('Content-Type');
|
|
8164
|
+
if (typeof request.body === 'string' || typeof request.body === 'number' || typeof request.body === 'boolean') {
|
|
8165
|
+
contentType = 'text/plain;charset=UTF-8"';
|
|
8166
|
+
body = String(request.body);
|
|
8167
|
+
request.headers.delete('Content-Size');
|
|
8168
|
+
delete request.duplex;
|
|
8169
|
+
}
|
|
8170
|
+
else if (isReadableStreamLike(request.body)) {
|
|
8171
|
+
contentType = 'application/octet-stream';
|
|
8172
|
+
body = request.body;
|
|
8173
|
+
request.duplex = 'half';
|
|
8174
|
+
}
|
|
8175
|
+
else if (isReadable(request.body)) {
|
|
8176
|
+
contentType = 'application/octet-stream';
|
|
8177
|
+
body = stream.Readable.toWeb(request.body);
|
|
8178
|
+
request.duplex = 'half';
|
|
8179
|
+
}
|
|
8180
|
+
else if (buffer.Buffer.isBuffer(request.body)) {
|
|
8181
|
+
contentType = 'application/octet-stream';
|
|
8182
|
+
body = request.body;
|
|
8183
|
+
request.headers.set('Content-Size', request.body.length);
|
|
8184
|
+
delete request.duplex;
|
|
7708
8185
|
}
|
|
7709
|
-
|
|
8186
|
+
else if (isBlob(request.body)) {
|
|
8187
|
+
contentType = request.body.type || 'application/octet-stream';
|
|
8188
|
+
body = request.body;
|
|
8189
|
+
request.headers.set('Content-Size', request.body.length);
|
|
8190
|
+
delete request.duplex;
|
|
8191
|
+
}
|
|
8192
|
+
else {
|
|
8193
|
+
contentType = 'application/json';
|
|
8194
|
+
body = JSON.stringify(request.body);
|
|
8195
|
+
request.headers.delete('Content-Size');
|
|
8196
|
+
delete request.duplex;
|
|
8197
|
+
}
|
|
8198
|
+
if (!request.headers.has('Content-Type') && contentType)
|
|
8199
|
+
request.headers.set('Content-Type', contentType);
|
|
8200
|
+
request.body = body;
|
|
7710
8201
|
}
|
|
8202
|
+
this._fetch(url, request)
|
|
8203
|
+
.then(response => this._handleResponse(observe, subscriber, request, response))
|
|
8204
|
+
.catch(error => subscriber.error(error));
|
|
8205
|
+
if (observe === 'events')
|
|
8206
|
+
subscriber.next({ event: 'sent', request });
|
|
7711
8207
|
}
|
|
7712
|
-
|
|
7713
|
-
|
|
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);
|
|
8208
|
+
catch (error) {
|
|
8209
|
+
subscriber.error(error);
|
|
7723
8210
|
}
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
8211
|
+
});
|
|
8212
|
+
}
|
|
8213
|
+
_fetch(url, init = {}) {
|
|
8214
|
+
return fetch(url, init);
|
|
8215
|
+
}
|
|
8216
|
+
_createResponse(init) {
|
|
8217
|
+
return new HttpResponse(init);
|
|
8218
|
+
}
|
|
8219
|
+
_handleResponse(observe, subscriber, request, fetchResponse) {
|
|
8220
|
+
const headers = new HttpHeaders(fetchResponse.headers);
|
|
8221
|
+
if (observe === 'events') {
|
|
8222
|
+
const response = this._createResponse({
|
|
8223
|
+
url: fetchResponse.url,
|
|
8224
|
+
headers,
|
|
8225
|
+
status: fetchResponse.status,
|
|
8226
|
+
statusText: fetchResponse.statusText,
|
|
8227
|
+
hasBody: !!fetchResponse.body
|
|
7736
8228
|
});
|
|
8229
|
+
subscriber.next({ event: 'headers-received', request, response });
|
|
7737
8230
|
}
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7745
|
-
|
|
7746
|
-
|
|
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;
|
|
8231
|
+
Promise
|
|
8232
|
+
.resolve(fetchResponse.body)
|
|
8233
|
+
.then(async (inputStream) => {
|
|
8234
|
+
if (!inputStream)
|
|
8235
|
+
return;
|
|
8236
|
+
if (JSON_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || '')) {
|
|
8237
|
+
const body = await fetchResponse.json();
|
|
8238
|
+
if (typeof body === 'string')
|
|
8239
|
+
return JSON.parse(body);
|
|
8240
|
+
return body;
|
|
7765
8241
|
}
|
|
7766
|
-
|
|
7767
|
-
|
|
8242
|
+
if (TEXT_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
|
|
8243
|
+
return await fetchResponse.text();
|
|
8244
|
+
if (FORMDATA_CONTENT_TYPE_PATTERN.test(fetchResponse.headers.get('Content-Type') || ''))
|
|
8245
|
+
return await fetchResponse.formData();
|
|
8246
|
+
const buf = await fetchResponse.arrayBuffer();
|
|
8247
|
+
return buf.byteLength ? buf : undefined;
|
|
8248
|
+
})
|
|
8249
|
+
.then(body => {
|
|
8250
|
+
if (fetchResponse.status >= 400 && fetchResponse.status < 600) {
|
|
8251
|
+
subscriber.error(new ClientError({
|
|
8252
|
+
message: fetchResponse.status + ' ' + fetchResponse.statusText,
|
|
8253
|
+
status: fetchResponse.status,
|
|
8254
|
+
issues: body?.errors
|
|
8255
|
+
}));
|
|
8256
|
+
subscriber.complete();
|
|
8257
|
+
return;
|
|
8258
|
+
}
|
|
8259
|
+
if (observe === 'body') {
|
|
8260
|
+
subscriber.next(body);
|
|
8261
|
+
}
|
|
8262
|
+
else {
|
|
8263
|
+
const response = this._createResponse({
|
|
8264
|
+
url: fetchResponse.url,
|
|
8265
|
+
headers,
|
|
8266
|
+
status: fetchResponse.status,
|
|
8267
|
+
statusText: fetchResponse.statusText,
|
|
8268
|
+
body
|
|
8269
|
+
});
|
|
8270
|
+
if (observe === 'events')
|
|
8271
|
+
subscriber.next({ event: 'response', request, response });
|
|
8272
|
+
else
|
|
8273
|
+
subscriber.next(response);
|
|
8274
|
+
}
|
|
8275
|
+
subscriber.complete();
|
|
8276
|
+
})
|
|
8277
|
+
.catch(error => subscriber.error(error));
|
|
7768
8278
|
}
|
|
7769
8279
|
_assertMetadata() {
|
|
7770
8280
|
if (!this._metadata)
|
|
@@ -7777,6 +8287,8 @@ class OpraHttpClient {
|
|
|
7777
8287
|
return client;
|
|
7778
8288
|
}
|
|
7779
8289
|
}
|
|
8290
|
+
class OpraHttpClient extends OpraHttpClientBase {
|
|
8291
|
+
}
|
|
7780
8292
|
|
|
7781
8293
|
Object.defineProperty(exports, 'uid', {
|
|
7782
8294
|
enumerable: true,
|
|
@@ -7810,7 +8322,7 @@ exports.Ast = Ast;
|
|
|
7810
8322
|
exports.BadRequestError = BadRequestError;
|
|
7811
8323
|
exports.BaseI18n = BaseI18n;
|
|
7812
8324
|
exports.BatchMultipart = BatchMultipart;
|
|
7813
|
-
exports.
|
|
8325
|
+
exports.BooleanCodec = BooleanCodec;
|
|
7814
8326
|
exports.BooleanLiteral = BooleanLiteral;
|
|
7815
8327
|
exports.COMPLEXTYPE_FIELDS = COMPLEXTYPE_FIELDS;
|
|
7816
8328
|
exports.ClientError = ClientError;
|
|
@@ -7835,18 +8347,27 @@ exports.ComplexType = ComplexType;
|
|
|
7835
8347
|
exports.ContainerResourceInfo = ContainerResourceInfo;
|
|
7836
8348
|
exports.DATATYPE_METADATA = DATATYPE_METADATA;
|
|
7837
8349
|
exports.DataType = DataType;
|
|
8350
|
+
exports.DateCodec = DateCodec;
|
|
7838
8351
|
exports.DateLiteral = DateLiteral;
|
|
7839
8352
|
exports.DocumentBuilder = DocumentBuilder;
|
|
7840
8353
|
exports.Expression = Expression;
|
|
7841
8354
|
exports.FailedDependencyError = FailedDependencyError;
|
|
7842
8355
|
exports.FieldGetQuery = FieldGetQuery;
|
|
8356
|
+
exports.FilterCodec = FilterCodec;
|
|
7843
8357
|
exports.FilterTreeVisitor = FilterTreeVisitor;
|
|
7844
8358
|
exports.ForbiddenError = ForbiddenError;
|
|
7845
8359
|
exports.HttpCollectionService = HttpCollectionService;
|
|
7846
|
-
exports.
|
|
8360
|
+
exports.HttpHeaders = HttpHeaders;
|
|
8361
|
+
exports.HttpParamCodec = HttpParamCodec;
|
|
8362
|
+
exports.HttpParams = HttpParams;
|
|
8363
|
+
exports.HttpRequest = HttpRequest;
|
|
8364
|
+
exports.HttpRequestHost = HttpRequestHost;
|
|
8365
|
+
exports.HttpRequestNode = HttpRequestNode;
|
|
8366
|
+
exports.HttpResponse = HttpResponse;
|
|
7847
8367
|
exports.HttpSingletonService = HttpSingletonService;
|
|
7848
8368
|
exports.I18n = I18n;
|
|
7849
8369
|
exports.IGNORE_RESOLVER_METHOD = IGNORE_RESOLVER_METHOD;
|
|
8370
|
+
exports.IntegerCodec = IntegerCodec;
|
|
7850
8371
|
exports.InternalServerError = InternalServerError;
|
|
7851
8372
|
exports.Literal = Literal;
|
|
7852
8373
|
exports.LogicalExpression = LogicalExpression;
|
|
@@ -7856,6 +8377,7 @@ exports.MixinType = MixinType;
|
|
|
7856
8377
|
exports.NotAcceptableError = NotAcceptableError;
|
|
7857
8378
|
exports.NotFoundError = NotFoundError;
|
|
7858
8379
|
exports.NullLiteral = NullLiteral;
|
|
8380
|
+
exports.NumberCodec = NumberCodec;
|
|
7859
8381
|
exports.NumberLiteral = NumberLiteral;
|
|
7860
8382
|
exports.OmitType = OmitType;
|
|
7861
8383
|
exports.OprCollectionResource = OprCollectionResource;
|
|
@@ -7873,6 +8395,7 @@ exports.OpraDocument = OpraDocument;
|
|
|
7873
8395
|
exports.OpraErrorListener = OpraErrorListener;
|
|
7874
8396
|
exports.OpraException = OpraException;
|
|
7875
8397
|
exports.OpraHttpClient = OpraHttpClient;
|
|
8398
|
+
exports.OpraHttpClientBase = OpraHttpClientBase;
|
|
7876
8399
|
exports.OpraURL = OpraURL;
|
|
7877
8400
|
exports.OpraURLPath = OpraURLPath;
|
|
7878
8401
|
exports.OpraURLPathComponent = OpraURLPathComponent;
|
|
@@ -7887,8 +8410,11 @@ exports.ResourceInfo = ResourceInfo;
|
|
|
7887
8410
|
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
7888
8411
|
exports.ResponsiveMap = ResponsiveMap;
|
|
7889
8412
|
exports.SimpleType = SimpleType;
|
|
8413
|
+
exports.SingletonDeleteRequest = SingletonDeleteRequest;
|
|
7890
8414
|
exports.SingletonGetQuery = SingletonGetQuery;
|
|
8415
|
+
exports.SingletonGetRequest = SingletonGetRequest;
|
|
7891
8416
|
exports.SingletonResourceInfo = SingletonResourceInfo;
|
|
8417
|
+
exports.StringCodec = StringCodec;
|
|
7892
8418
|
exports.StringLiteral = StringLiteral;
|
|
7893
8419
|
exports.Term = Term;
|
|
7894
8420
|
exports.TimeLiteral = TimeLiteral;
|