@outfoxx/sunday 1.1.0-alpha.9 → 1.1.0-beta.2
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/LICENSE.txt +203 -0
- package/README.md +6 -7
- package/dist/any-type.js +13 -0
- package/dist/any-type.js.map +1 -1
- package/dist/class-type.js +13 -0
- package/dist/class-type.js.map +1 -1
- package/dist/date-time-types.js +13 -0
- package/dist/date-time-types.js.map +1 -1
- package/dist/event-parser.js +13 -0
- package/dist/event-parser.js.map +1 -1
- package/dist/fetch-event-source.d.ts +4 -0
- package/dist/fetch-event-source.js +13 -0
- package/dist/fetch-event-source.js.map +1 -1
- package/dist/fetch-request-factory.d.ts +3 -0
- package/dist/fetch-request-factory.js +42 -2
- package/dist/fetch-request-factory.js.map +1 -1
- package/dist/fetch.js +24 -5
- package/dist/fetch.js.map +1 -1
- package/dist/header-parameters.js +13 -0
- package/dist/header-parameters.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.js +13 -0
- package/dist/logger.js.map +1 -1
- package/dist/media-type-codecs/any-text-decoder.d.ts +7 -0
- package/dist/media-type-codecs/any-text-decoder.js +29 -0
- package/dist/media-type-codecs/any-text-decoder.js.map +1 -0
- package/dist/media-type-codecs/any-text-encoder.d.ts +5 -0
- package/dist/media-type-codecs/any-text-encoder.js +23 -0
- package/dist/media-type-codecs/any-text-encoder.js.map +1 -0
- package/dist/media-type-codecs/binary-decoder.js +13 -0
- package/dist/media-type-codecs/binary-decoder.js.map +1 -1
- package/dist/media-type-codecs/binary-encoder.js +13 -0
- package/dist/media-type-codecs/binary-encoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-decoder.js +13 -0
- package/dist/media-type-codecs/cbor-decoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-encoder.js +13 -0
- package/dist/media-type-codecs/cbor-encoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-tags.js +13 -0
- package/dist/media-type-codecs/cbor-tags.js.map +1 -1
- package/dist/media-type-codecs/json-decoder.js +13 -0
- package/dist/media-type-codecs/json-decoder.js.map +1 -1
- package/dist/media-type-codecs/json-encoder.js +13 -0
- package/dist/media-type-codecs/json-encoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-decoder.js +13 -0
- package/dist/media-type-codecs/media-type-decoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-decoders.js +21 -3
- package/dist/media-type-codecs/media-type-decoders.js.map +1 -1
- package/dist/media-type-codecs/media-type-encoder.js +13 -0
- package/dist/media-type-codecs/media-type-encoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-encoders.js +21 -3
- package/dist/media-type-codecs/media-type-encoders.js.map +1 -1
- package/dist/media-type-codecs/www-form-url-encoder.js +56 -6
- package/dist/media-type-codecs/www-form-url-encoder.js.map +1 -1
- package/dist/media-type.d.ts +4 -2
- package/dist/media-type.js +34 -5
- package/dist/media-type.js.map +1 -1
- package/dist/problem.js +19 -2
- package/dist/problem.js.map +1 -1
- package/dist/request-factory.d.ts +6 -0
- package/dist/request-factory.js +13 -0
- package/dist/request-factory.js.map +1 -1
- package/dist/result-response.d.ts +4 -0
- package/dist/result-response.js +15 -0
- package/dist/result-response.js.map +1 -0
- package/dist/sunday-error.js +13 -0
- package/dist/sunday-error.js.map +1 -1
- package/dist/url-template.js +13 -0
- package/dist/url-template.js.map +1 -1
- package/dist/util/any.js +13 -0
- package/dist/util/any.js.map +1 -1
- package/dist/util/base64.js +13 -0
- package/dist/util/base64.js.map +1 -1
- package/dist/util/error.d.ts +2 -0
- package/dist/util/error.js +26 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/hex.js +13 -0
- package/dist/util/hex.js.map +1 -1
- package/dist/util/rxjs.js +13 -0
- package/dist/util/rxjs.js.map +1 -1
- package/dist/util/stream-rxjs.js +13 -0
- package/dist/util/stream-rxjs.js.map +1 -1
- package/dist/util/temporal.js +13 -0
- package/dist/util/temporal.js.map +1 -1
- package/package.json +31 -28
- package/src/any-type.ts +14 -0
- package/src/class-type.ts +16 -2
- package/src/date-time-types.ts +14 -0
- package/src/event-parser.ts +18 -4
- package/src/fetch-event-source.ts +36 -7
- package/src/fetch-request-factory.ts +87 -24
- package/src/fetch.ts +27 -8
- package/src/header-parameters.ts +16 -2
- package/src/index.ts +15 -0
- package/src/logger.ts +14 -0
- package/src/media-type-codecs/any-text-decoder.ts +34 -0
- package/src/media-type-codecs/any-text-encoder.ts +26 -0
- package/src/media-type-codecs/binary-decoder.ts +15 -1
- package/src/media-type-codecs/binary-encoder.ts +15 -1
- package/src/media-type-codecs/cbor-decoder.ts +30 -16
- package/src/media-type-codecs/cbor-encoder.ts +28 -14
- package/src/media-type-codecs/cbor-tags.ts +14 -0
- package/src/media-type-codecs/json-decoder.ts +29 -15
- package/src/media-type-codecs/json-encoder.ts +21 -7
- package/src/media-type-codecs/media-type-decoder.ts +15 -1
- package/src/media-type-codecs/media-type-decoders.ts +26 -7
- package/src/media-type-codecs/media-type-encoder.ts +17 -3
- package/src/media-type-codecs/media-type-encoders.ts +26 -7
- package/src/media-type-codecs/www-form-url-encoder.ts +81 -17
- package/src/media-type.ts +44 -11
- package/src/problem.ts +21 -3
- package/src/request-factory.ts +46 -7
- package/src/result-response.ts +18 -0
- package/src/sunday-error.ts +18 -4
- package/src/url-template.ts +15 -1
- package/src/util/any.ts +14 -0
- package/src/util/base64.ts +15 -1
- package/src/util/error.ts +28 -0
- package/src/util/hex.ts +14 -0
- package/src/util/rxjs.ts +17 -3
- package/src/util/stream-rxjs.ts +15 -1
- package/src/util/temporal.ts +14 -0
package/dist/util/stream-rxjs.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
import { Observable } from 'rxjs';
|
|
2
15
|
export function fromStream(stream) {
|
|
3
16
|
return new Observable((subscriber) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-rxjs.js","sourceRoot":"","sources":["../../src/util/stream-rxjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,UAAU,UAAU,CACxB,MAAkC;IAElC,OAAO,IAAI,UAAU,CAAC,CAAC,UAAU,EAAE,EAAE;QACnC,IAAI,MAA+C,CAAC;QACpD,CAAC,KAAK,UAAU,QAAQ;YACtB,IAAI;gBACF,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;gBAC5B,OAAO,IAAI,EAAE;oBACX,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC5C,IAAI,KAAK,KAAK,SAAS,EAAE;wBACvB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACxB;oBAED,IAAI,IAAI,EAAE;wBACR,UAAU,CAAC,QAAQ,EAAE,CAAC;wBACtB,OAAO;qBACR;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,GAAG,EAAE,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"stream-rxjs.js","sourceRoot":"","sources":["../../src/util/stream-rxjs.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,UAAU,UAAU,CACxB,MAAkC;IAElC,OAAO,IAAI,UAAU,CAAC,CAAC,UAAU,EAAE,EAAE;QACnC,IAAI,MAA+C,CAAC;QACpD,CAAC,KAAK,UAAU,QAAQ;YACtB,IAAI;gBACF,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;gBAC5B,OAAO,IAAI,EAAE;oBACX,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBAC5C,IAAI,KAAK,KAAK,SAAS,EAAE;wBACvB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACxB;oBAED,IAAI,IAAI,EAAE;wBACR,UAAU,CAAC,QAAQ,EAAE,CAAC;wBACtB,OAAO;qBACR;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACrB;QACH,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,GAAG,EAAE,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/util/temporal.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
export function secondsToNumber(seconds, nanos) {
|
|
2
15
|
if (nanos == 0) {
|
|
3
16
|
return seconds;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/util/temporal.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAa;IAC5D,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,OAAO,OAAO,CAAC;KAChB;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjC,OAAO,UAAU,CAAC,GAAG,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,QAAgB;IAC7D,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,QAAQ,IAAI,CAAC,EAAE;YACjB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACvB;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/util/temporal.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAa;IAC5D,IAAI,KAAK,IAAI,CAAC,EAAE;QACd,OAAO,OAAO,CAAC;KAChB;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IACjC,OAAO,UAAU,CAAC,GAAG,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,QAAgB;IAC7D,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,OAAO,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,QAAQ,IAAI,CAAC,EAAE;YACjB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACvB;KACF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfoxx/sunday",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0-beta.2",
|
|
4
4
|
"description": "Sunday 🙏 The framework of REST for TypeScript/JavaScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"build": "tsc --build tsconfig.dist.json",
|
|
12
12
|
"clean": "rimraf build dist",
|
|
13
13
|
"prepublishOnly": "npm run clean && npm run lint && npm run build && npm run test",
|
|
14
|
-
"lint": "eslint src test",
|
|
15
|
-
"pretty": "prettier src test"
|
|
14
|
+
"lint": "eslint -f json -o reports/lint.json src test",
|
|
15
|
+
"pretty": "prettier src test",
|
|
16
|
+
"docs": "typedoc --excludeInternal --excludePrivate src/index.ts"
|
|
16
17
|
},
|
|
17
18
|
"husky": {
|
|
18
19
|
"hooks": {
|
|
@@ -26,47 +27,49 @@
|
|
|
26
27
|
},
|
|
27
28
|
"keywords": [],
|
|
28
29
|
"author": "kdubb",
|
|
29
|
-
"license": "
|
|
30
|
+
"license": "Apache-2.0",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@js-joda/core": "
|
|
32
|
-
"@outfoxx/cbor-redux": "
|
|
33
|
-
"@outfoxx/jackson-js": "
|
|
34
|
-
"common-tags": "
|
|
35
|
-
"
|
|
32
|
+
"@js-joda/core": "5.2.x",
|
|
33
|
+
"@outfoxx/cbor-redux": "0.3.x",
|
|
34
|
+
"@outfoxx/jackson-js": "1.4.x",
|
|
35
|
+
"common-tags": "1.8.x",
|
|
36
|
+
"tslib": "2.4.x",
|
|
37
|
+
"uri-template-lite": "^22.9.0"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
|
-
"rxjs": "
|
|
40
|
+
"rxjs": "7.x"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
|
-
"@types/common-tags": "
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint": "^
|
|
49
|
-
"eslint-
|
|
50
|
-
"eslint-plugin-prettier": "^3.4.0",
|
|
43
|
+
"@types/common-tags": "1.8.x",
|
|
44
|
+
"@types/jasmine": "4.0.x",
|
|
45
|
+
"@types/uri-template-lite": "19.12.x",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
48
|
+
"eslint": "^8.15.0",
|
|
49
|
+
"eslint-config-prettier": "^8.5.0",
|
|
50
|
+
"eslint-plugin-header": "^3.1.1",
|
|
51
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
51
52
|
"fetch-mock": "^9.11.0",
|
|
52
53
|
"fsevents": "^2.1.3",
|
|
53
54
|
"husky": "^4.3.0",
|
|
54
55
|
"install": "^0.13.0",
|
|
55
|
-
"karma": "^6.3.
|
|
56
|
-
"karma-chrome-launcher": "^3.1.
|
|
56
|
+
"karma": "^6.3.20",
|
|
57
|
+
"karma-chrome-launcher": "^3.1.1",
|
|
57
58
|
"karma-cli": "^2.0.0",
|
|
58
|
-
"karma-coverage": "^2.0
|
|
59
|
-
"karma-jasmine": "^
|
|
59
|
+
"karma-coverage": "^2.2.0",
|
|
60
|
+
"karma-jasmine": "^5.0.1",
|
|
61
|
+
"karma-junit-reporter": "^2.0.1",
|
|
62
|
+
"karma-sonarqube-unit-reporter": "^0.0.23",
|
|
60
63
|
"karma-source-map-support": "^1.4.0",
|
|
61
64
|
"karma-sourcemap-loader": "^0.3.8",
|
|
62
|
-
"karma-typescript": "^5.5.
|
|
63
|
-
"karma-typescript-es6-transform": "^5.5.
|
|
65
|
+
"karma-typescript": "^5.5.3",
|
|
66
|
+
"karma-typescript-es6-transform": "^5.5.3",
|
|
64
67
|
"lint-staged": "^10.4.0",
|
|
65
|
-
"npm": "^7.13.0",
|
|
66
68
|
"prettier": "^2.1.2",
|
|
67
69
|
"pretty-quick": "^3.0.2",
|
|
68
70
|
"rimraf": "^3.0.2",
|
|
69
|
-
"
|
|
71
|
+
"typedoc": "^0.22.18",
|
|
72
|
+
"typescript": "~4.4",
|
|
70
73
|
"web-streams-polyfill": "^3.0.0"
|
|
71
74
|
},
|
|
72
75
|
"files": [
|
package/src/any-type.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { ClassList, ClassType } from '@outfoxx/jackson-js/dist/@types';
|
|
2
16
|
import { ConstructableClassType } from './class-type';
|
|
3
17
|
|
package/src/class-type.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export type ClassType<T> =
|
|
2
|
-
| (abstract new () => T)
|
|
16
|
+
| (abstract new () => T)
|
|
3
17
|
| (abstract new (...args: any[]) => T); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
4
18
|
|
|
5
19
|
export declare type ConstructableClassType<T> =
|
|
6
|
-
| (new () => T)
|
|
20
|
+
| (new () => T)
|
|
7
21
|
| (new (...args: any[]) => T); // eslint-disable-line @typescript-eslint/no-explicit-any
|
package/src/date-time-types.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import {
|
|
2
16
|
Duration,
|
|
3
17
|
Instant,
|
package/src/event-parser.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export interface EventInfo {
|
|
2
16
|
id?: string;
|
|
3
17
|
event?: string;
|
|
@@ -11,7 +25,7 @@ export class EventParser {
|
|
|
11
25
|
|
|
12
26
|
process(
|
|
13
27
|
buffer: ArrayBuffer,
|
|
14
|
-
dispatcher: (eventInfo: EventInfo) => void
|
|
28
|
+
dispatcher: (eventInfo: EventInfo) => void,
|
|
15
29
|
): void {
|
|
16
30
|
const availableBuffer = this.buildAvailableBuffer(buffer);
|
|
17
31
|
if (!availableBuffer) {
|
|
@@ -38,7 +52,7 @@ export class EventParser {
|
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
const newBuffer = new Uint8Array(
|
|
41
|
-
unprocessedBuffer.byteLength + buffer.byteLength
|
|
55
|
+
unprocessedBuffer.byteLength + buffer.byteLength,
|
|
42
56
|
);
|
|
43
57
|
newBuffer.set(new Uint8Array(unprocessedBuffer), 0);
|
|
44
58
|
newBuffer.set(new Uint8Array(buffer), unprocessedBuffer.byteLength);
|
|
@@ -74,7 +88,7 @@ export class EventParser {
|
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
private static findEventSeparator(
|
|
77
|
-
buffer: ArrayBuffer
|
|
91
|
+
buffer: ArrayBuffer,
|
|
78
92
|
): [number, number] | undefined {
|
|
79
93
|
const bytes = new Uint8Array(buffer);
|
|
80
94
|
|
|
@@ -121,7 +135,7 @@ export class EventParser {
|
|
|
121
135
|
|
|
122
136
|
private static parseAndDispatchEvents(
|
|
123
137
|
eventStrings: string[],
|
|
124
|
-
dispatcher: (eventInfo: EventInfo) => void
|
|
138
|
+
dispatcher: (eventInfo: EventInfo) => void,
|
|
125
139
|
) {
|
|
126
140
|
for (const eventString of eventStrings) {
|
|
127
141
|
if (!eventString.length) {
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { EMPTY, map, Observable, of, Subscription, switchMap, tap } from 'rxjs';
|
|
2
16
|
import { EventInfo, EventParser } from './event-parser';
|
|
3
17
|
import { validate } from './fetch';
|
|
@@ -7,6 +21,21 @@ import { ExtEventSource } from './request-factory';
|
|
|
7
21
|
import { unknownSet } from './util/any';
|
|
8
22
|
import { fromStream } from './util/stream-rxjs';
|
|
9
23
|
|
|
24
|
+
export interface FetchEventSource {
|
|
25
|
+
addEventListener<K extends keyof EventSourceEventMap>(
|
|
26
|
+
type: K,
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
|
|
29
|
+
options?: boolean | AddEventListenerOptions,
|
|
30
|
+
): void;
|
|
31
|
+
removeEventListener<K extends keyof EventSourceEventMap>(
|
|
32
|
+
type: K,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
|
|
35
|
+
options?: boolean | EventListenerOptions,
|
|
36
|
+
): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
10
39
|
export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
11
40
|
private static LAST_EVENT_ID_HEADER = 'Last-Event-ID';
|
|
12
41
|
private static MAX_RETRY_TIME_MULTIPLE = 30;
|
|
@@ -30,7 +59,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
30
59
|
|
|
31
60
|
private adapter: (
|
|
32
61
|
url: string,
|
|
33
|
-
requestInit: RequestInit
|
|
62
|
+
requestInit: RequestInit,
|
|
34
63
|
) => Observable<Request>;
|
|
35
64
|
private connectionSubscription?: Subscription;
|
|
36
65
|
private internalRetryTime = 100;
|
|
@@ -53,7 +82,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
53
82
|
eventTimeout?: number;
|
|
54
83
|
logger?: Logger;
|
|
55
84
|
abortController?: AbortController;
|
|
56
|
-
}
|
|
85
|
+
},
|
|
57
86
|
) {
|
|
58
87
|
super();
|
|
59
88
|
this.url = url;
|
|
@@ -117,7 +146,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
117
146
|
|
|
118
147
|
return fromStream(body);
|
|
119
148
|
}),
|
|
120
|
-
map((value) => this.receivedData(value))
|
|
149
|
+
map((value) => this.receivedData(value)),
|
|
121
150
|
)
|
|
122
151
|
.subscribe({
|
|
123
152
|
error: (error: unknown) => {
|
|
@@ -170,7 +199,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
170
199
|
|
|
171
200
|
this.eventTimeoutCheckHandle = window.setInterval(
|
|
172
201
|
() => this.checkEventTimeout(),
|
|
173
|
-
FetchEventSource.EVENT_TIMEOUT_CHECK_INTERVAL * 1000
|
|
202
|
+
FetchEventSource.EVENT_TIMEOUT_CHECK_INTERVAL * 1000,
|
|
174
203
|
);
|
|
175
204
|
}
|
|
176
205
|
|
|
@@ -285,7 +314,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
285
314
|
const backOffDelay = Math.pow(this.retryAttempt, 2) * this.retryTime;
|
|
286
315
|
let retryDelay = Math.min(
|
|
287
316
|
this.retryTime + backOffDelay,
|
|
288
|
-
this.retryTime * FetchEventSource.MAX_RETRY_TIME_MULTIPLE
|
|
317
|
+
this.retryTime * FetchEventSource.MAX_RETRY_TIME_MULTIPLE,
|
|
289
318
|
);
|
|
290
319
|
|
|
291
320
|
// Adjust delay by amount of time last connect
|
|
@@ -304,7 +333,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
304
333
|
|
|
305
334
|
this.reconnectTimeoutHandle = window.setTimeout(
|
|
306
335
|
() => this.internalConnect(),
|
|
307
|
-
retryDelay
|
|
336
|
+
retryDelay,
|
|
308
337
|
);
|
|
309
338
|
}
|
|
310
339
|
|
|
@@ -353,7 +382,7 @@ export class FetchEventSource extends EventTarget implements ExtEventSource {
|
|
|
353
382
|
this.lastEventId = eventInfo.id;
|
|
354
383
|
} else {
|
|
355
384
|
this.logger?.debug?.(
|
|
356
|
-
'event id contains null, unable to use for last-event-id'
|
|
385
|
+
'event id contains null, unable to use for last-event-id',
|
|
357
386
|
);
|
|
358
387
|
}
|
|
359
388
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { defer, map, Observable, of, switchMap } from 'rxjs';
|
|
2
16
|
import { AnyType } from './any-type';
|
|
3
17
|
import { ConstructableClassType } from './class-type';
|
|
@@ -17,8 +31,10 @@ import {
|
|
|
17
31
|
RequestFactory,
|
|
18
32
|
RequestSpec,
|
|
19
33
|
} from './request-factory';
|
|
34
|
+
import { ResultResponse } from './result-response';
|
|
20
35
|
import { SundayError } from './sunday-error';
|
|
21
36
|
import { URLTemplate } from './url-template';
|
|
37
|
+
import { errorToMessage } from './util/error';
|
|
22
38
|
|
|
23
39
|
export class FetchRequestFactory implements RequestFactory {
|
|
24
40
|
public baseUrl: URLTemplate;
|
|
@@ -35,7 +51,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
35
51
|
mediaTypeEncoders?: MediaTypeEncoders;
|
|
36
52
|
mediaTypeDecoders?: MediaTypeDecoders;
|
|
37
53
|
logger?: Logger;
|
|
38
|
-
}
|
|
54
|
+
},
|
|
39
55
|
) {
|
|
40
56
|
this.baseUrl =
|
|
41
57
|
typeof baseUrl === 'string' ? new URLTemplate(baseUrl) : baseUrl;
|
|
@@ -49,7 +65,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
49
65
|
|
|
50
66
|
registerProblem(
|
|
51
67
|
type: URL | string,
|
|
52
|
-
problemType: ConstructableClassType<Problem
|
|
68
|
+
problemType: ConstructableClassType<Problem>,
|
|
53
69
|
): void {
|
|
54
70
|
const typeStr = type instanceof URL ? type.toString() : type;
|
|
55
71
|
this.problemTypes.set(typeStr, problemType);
|
|
@@ -57,26 +73,26 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
57
73
|
|
|
58
74
|
request(
|
|
59
75
|
requestSpec: RequestSpec<unknown>,
|
|
60
|
-
requestInit?: RequestInit
|
|
76
|
+
requestInit?: RequestInit,
|
|
61
77
|
): Observable<Request> {
|
|
62
78
|
//
|
|
63
79
|
return defer(() => {
|
|
64
80
|
const url = this.baseUrl.complete(
|
|
65
81
|
requestSpec.pathTemplate,
|
|
66
|
-
requestSpec.pathParameters ?? {}
|
|
82
|
+
requestSpec.pathParameters ?? {},
|
|
67
83
|
);
|
|
68
84
|
|
|
69
85
|
if (requestSpec.queryParameters) {
|
|
70
86
|
const encoder = this.mediaTypeEncoders.find(
|
|
71
|
-
MediaType.WWWFormUrlEncoded
|
|
87
|
+
MediaType.WWWFormUrlEncoded,
|
|
72
88
|
);
|
|
73
89
|
if (!isURLQueryParamsEncoder(encoder)) {
|
|
74
90
|
throw Error(
|
|
75
|
-
`MediaTypeEncoder for ${MediaType.WWWFormUrlEncoded} must be an instance of URLQueryParamsEncoder
|
|
91
|
+
`MediaTypeEncoder for ${MediaType.WWWFormUrlEncoded} must be an instance of URLQueryParamsEncoder`,
|
|
76
92
|
);
|
|
77
93
|
}
|
|
78
94
|
url.search = `?${encoder.encodeQueryString(
|
|
79
|
-
requestSpec.queryParameters
|
|
95
|
+
requestSpec.queryParameters,
|
|
80
96
|
)}`;
|
|
81
97
|
}
|
|
82
98
|
|
|
@@ -85,12 +101,12 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
85
101
|
// Determine & add accept header
|
|
86
102
|
if (requestSpec.acceptTypes) {
|
|
87
103
|
const supportedAcceptTypes = requestSpec.acceptTypes.filter((type) =>
|
|
88
|
-
this.mediaTypeDecoders.supports(type)
|
|
104
|
+
this.mediaTypeDecoders.supports(type),
|
|
89
105
|
);
|
|
90
106
|
|
|
91
107
|
if (!supportedAcceptTypes.length) {
|
|
92
108
|
throw Error(
|
|
93
|
-
'None of the provided accept types has a reqistered decoder'
|
|
109
|
+
'None of the provided accept types has a reqistered decoder',
|
|
94
110
|
);
|
|
95
111
|
}
|
|
96
112
|
|
|
@@ -101,7 +117,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
101
117
|
|
|
102
118
|
// Determine content type
|
|
103
119
|
const contentType = requestSpec.contentTypes?.find((type) =>
|
|
104
|
-
this.mediaTypeEncoders.supports(type)
|
|
120
|
+
this.mediaTypeEncoders.supports(type),
|
|
105
121
|
);
|
|
106
122
|
|
|
107
123
|
// If matched, add content type (even if body is nil, to match any expected server requirements)
|
|
@@ -114,7 +130,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
114
130
|
if (requestSpec.body) {
|
|
115
131
|
if (!contentType) {
|
|
116
132
|
throw Error(
|
|
117
|
-
'None of the provided content types has a registered encoder'
|
|
133
|
+
'None of the provided content types has a registered encoder',
|
|
118
134
|
);
|
|
119
135
|
}
|
|
120
136
|
|
|
@@ -137,23 +153,70 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
137
153
|
|
|
138
154
|
response(
|
|
139
155
|
request: Request | RequestSpec<unknown>,
|
|
140
|
-
dataExpected?: boolean
|
|
156
|
+
dataExpected?: boolean,
|
|
141
157
|
): Observable<Response> {
|
|
142
158
|
const request$ =
|
|
143
159
|
request instanceof Request ? of(request) : this.request(request);
|
|
144
160
|
return request$.pipe(
|
|
145
161
|
switchMap((req) => fetch(req)),
|
|
146
162
|
switchMap((response) =>
|
|
147
|
-
validate(response, dataExpected ?? false, this.problemTypes)
|
|
148
|
-
)
|
|
163
|
+
validate(response, dataExpected ?? false, this.problemTypes),
|
|
164
|
+
),
|
|
149
165
|
);
|
|
150
166
|
}
|
|
151
167
|
|
|
168
|
+
resultResponse<B, R>(
|
|
169
|
+
requestSpec: RequestSpec<B>,
|
|
170
|
+
resultType: AnyType,
|
|
171
|
+
): Observable<ResultResponse<R>>;
|
|
172
|
+
resultResponse<B>(
|
|
173
|
+
requestSpec: RequestSpec<B>,
|
|
174
|
+
): Observable<ResultResponse<void>>;
|
|
175
|
+
resultResponse(
|
|
176
|
+
request: RequestSpec<unknown>,
|
|
177
|
+
responseType?: AnyType,
|
|
178
|
+
): Observable<ResultResponse<unknown>> {
|
|
179
|
+
const response$ = this.response(request, !!responseType);
|
|
180
|
+
|
|
181
|
+
if (!responseType) {
|
|
182
|
+
return response$.pipe(
|
|
183
|
+
map((response) => {
|
|
184
|
+
return {
|
|
185
|
+
result: undefined,
|
|
186
|
+
response,
|
|
187
|
+
};
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
190
|
+
} else {
|
|
191
|
+
return response$.pipe(
|
|
192
|
+
switchMap(async (response) => {
|
|
193
|
+
try {
|
|
194
|
+
const contentType = MediaType.from(
|
|
195
|
+
response.headers.get('content-type'),
|
|
196
|
+
MediaType.OctetStream,
|
|
197
|
+
);
|
|
198
|
+
const decoder = this.mediaTypeDecoders.find(contentType);
|
|
199
|
+
const result = await decoder.decode(response, responseType);
|
|
200
|
+
return {
|
|
201
|
+
result,
|
|
202
|
+
response,
|
|
203
|
+
};
|
|
204
|
+
} catch (error) {
|
|
205
|
+
throw await SundayError.fromResponse(
|
|
206
|
+
errorToMessage(error, 'Response Decoding Failed'),
|
|
207
|
+
response,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
152
215
|
result<B, R>(requestSpec: RequestSpec<B>, resultType: AnyType): Observable<R>;
|
|
153
216
|
result<B>(requestSpec: RequestSpec<B>): Observable<void>;
|
|
154
217
|
result(
|
|
155
218
|
request: RequestSpec<unknown>,
|
|
156
|
-
responseType?: AnyType
|
|
219
|
+
responseType?: AnyType,
|
|
157
220
|
): Observable<unknown> {
|
|
158
221
|
const response$ = this.response(request, !!responseType);
|
|
159
222
|
|
|
@@ -165,17 +228,17 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
165
228
|
try {
|
|
166
229
|
const contentType = MediaType.from(
|
|
167
230
|
response.headers.get('content-type'),
|
|
168
|
-
MediaType.OctetStream
|
|
231
|
+
MediaType.OctetStream,
|
|
169
232
|
);
|
|
170
233
|
const decoder = this.mediaTypeDecoders.find(contentType);
|
|
171
234
|
return await decoder.decode(response, responseType);
|
|
172
235
|
} catch (error) {
|
|
173
236
|
throw await SundayError.fromResponse(
|
|
174
|
-
error
|
|
175
|
-
response
|
|
237
|
+
errorToMessage(error, 'Response Decoding Failed'),
|
|
238
|
+
response,
|
|
176
239
|
);
|
|
177
240
|
}
|
|
178
|
-
})
|
|
241
|
+
}),
|
|
179
242
|
);
|
|
180
243
|
}
|
|
181
244
|
}
|
|
@@ -184,7 +247,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
184
247
|
//
|
|
185
248
|
const adapter = (
|
|
186
249
|
url: string,
|
|
187
|
-
requestInit: RequestInit
|
|
250
|
+
requestInit: RequestInit,
|
|
188
251
|
): Observable<Request> => {
|
|
189
252
|
const eventSourceSpec = Object.assign({}, requestSpec, {
|
|
190
253
|
pathTemplate: url,
|
|
@@ -205,13 +268,13 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
205
268
|
event: string | undefined,
|
|
206
269
|
id: string | undefined,
|
|
207
270
|
data: string,
|
|
208
|
-
logger?: Logger
|
|
209
|
-
) => E | undefined
|
|
271
|
+
logger?: Logger,
|
|
272
|
+
) => E | undefined,
|
|
210
273
|
): Observable<E> {
|
|
211
274
|
const eventSource = this.eventSource(requestSpec);
|
|
212
275
|
|
|
213
276
|
const jsonDecoder = this.mediaTypeDecoders.find(
|
|
214
|
-
MediaType.JSON
|
|
277
|
+
MediaType.JSON,
|
|
215
278
|
) as TextMediaTypeDecoder;
|
|
216
279
|
|
|
217
280
|
return new Observable((subscriber) => {
|
|
@@ -226,7 +289,7 @@ export class FetchRequestFactory implements RequestFactory {
|
|
|
226
289
|
event.type,
|
|
227
290
|
event.lastEventId,
|
|
228
291
|
event.data,
|
|
229
|
-
this.logger
|
|
292
|
+
this.logger,
|
|
230
293
|
);
|
|
231
294
|
if (!decodedEvent) {
|
|
232
295
|
return;
|