typedrest 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +41 -5
  2. package/endpoints/{CachingEndpoint.ts → CachingEndpoint.d.ts} +0 -1
  3. package/endpoints/Endpoint.d.ts +121 -0
  4. package/endpoints/Endpoint.js +1 -1
  5. package/endpoints/{EntryEndpoint.ts → EntryEndpoint.d.ts} +7 -27
  6. package/endpoints/generic/{CollectionEndpoint.ts → CollectionEndpoint.d.ts} +2 -5
  7. package/endpoints/generic/{ETagEndpointBase.ts → ETagEndpointBase.d.ts} +8 -38
  8. package/endpoints/generic/ETagEndpointBase.js +16 -4
  9. package/endpoints/generic/{ElementEndpoint.ts → ElementEndpoint.d.ts} +12 -70
  10. package/endpoints/generic/{GenericCollectionEndpoint.ts → GenericCollectionEndpoint.d.ts} +21 -106
  11. package/endpoints/generic/{IndexerEndpoint.ts → IndexerEndpoint.d.ts} +4 -11
  12. package/endpoints/generic/PartialResponse.d.ts +19 -0
  13. package/endpoints/{index.ts → index.d.ts} +1 -2
  14. package/endpoints/raw/{BlobEndpoint.ts → BlobEndpoint.d.ts} +9 -29
  15. package/endpoints/raw/{UploadEndpoint.ts → UploadEndpoint.d.ts} +4 -18
  16. package/endpoints/reactive/Delay.d.ts +7 -0
  17. package/endpoints/reactive/GenericStreamingCollectionEndpoint.d.ts +32 -0
  18. package/endpoints/reactive/{PollingEndpoint.ts → PollingEndpoint.d.ts} +7 -34
  19. package/endpoints/reactive/SseStreamingEndpoint.d.ts +50 -0
  20. package/endpoints/reactive/{StreamingCollectionEndpoint.ts → StreamingCollectionEndpoint.d.ts} +2 -5
  21. package/endpoints/reactive/{StreamingEndpoint.ts → StreamingEndpoint.d.ts} +5 -27
  22. package/endpoints/rpc/{ActionEndpoint.ts → ActionEndpoint.d.ts} +3 -10
  23. package/endpoints/rpc/{ConsumerEndpoint.ts → ConsumerEndpoint.d.ts} +3 -12
  24. package/endpoints/rpc/{FunctionEndpoint.ts → FunctionEndpoint.d.ts} +3 -14
  25. package/endpoints/rpc/{ProducerEndpoint.ts → ProducerEndpoint.d.ts} +3 -11
  26. package/endpoints/rpc/{RpcEndpointBase.ts → RpcEndpointBase.d.ts} +4 -12
  27. package/errors/DefaultErrorHandler.d.ts +21 -0
  28. package/errors/{Errors.ts → Errors.d.ts} +20 -21
  29. package/http/EntityStream.d.ts +10 -0
  30. package/http/FetchHttpClient.d.ts +15 -0
  31. package/http/FetchHttpClient.js +1 -1
  32. package/http/{HttpClient.ts → HttpClient.d.ts} +1 -3
  33. package/http/HttpContentRange.d.ts +23 -0
  34. package/http/{HttpHeader.ts → HttpHeader.d.ts} +1 -1
  35. package/http/{HttpMethod.ts → HttpMethod.d.ts} +1 -1
  36. package/http/{HttpStatusCode.ts → HttpStatusCode.d.ts} +1 -1
  37. package/http/ResponseCache.d.ts +19 -0
  38. package/http/RetryAfter.d.ts +6 -0
  39. package/http/ServerSentEvents.d.ts +50 -0
  40. package/links/AggregateLinkExtractor.d.ts +17 -0
  41. package/links/HalLinkExtractor.d.ts +13 -0
  42. package/links/HeaderLinkExtractor.d.ts +13 -0
  43. package/links/{Link.ts → Link.d.ts} +6 -2
  44. package/links/{LinkExtractor.ts → LinkExtractor.d.ts} +0 -1
  45. package/package.json +64 -14
  46. package/serializers/JsonSerializer.d.ts +18 -0
  47. package/serializers/{Serializer.ts → Serializer.d.ts} +0 -2
  48. package/endpoints/Endpoint.test.ts +0 -300
  49. package/endpoints/Endpoint.ts +0 -247
  50. package/endpoints/generic/CollectionEndpoint.test.ts +0 -215
  51. package/endpoints/generic/ElementEndpoint.test.ts +0 -262
  52. package/endpoints/generic/GenericCollectionEndpoint.test.ts +0 -123
  53. package/endpoints/generic/IndexerEndpoint.test.ts +0 -12
  54. package/endpoints/generic/PartialResponse.ts +0 -28
  55. package/endpoints/raw/BlobEndpoint.test.ts +0 -52
  56. package/endpoints/raw/UploadEndpoint.test.ts +0 -47
  57. package/endpoints/reactive/Delay.ts +0 -26
  58. package/endpoints/reactive/GenericStreamingCollectionEndpoint.ts +0 -73
  59. package/endpoints/reactive/PollingEndpoint.test.ts +0 -84
  60. package/endpoints/reactive/SseStreamingEndpoint.test.ts +0 -169
  61. package/endpoints/reactive/SseStreamingEndpoint.ts +0 -115
  62. package/endpoints/reactive/StreamingCollectionEndpoint.test.ts +0 -110
  63. package/endpoints/reactive/StreamingEndpoint.test.ts +0 -130
  64. package/endpoints/rpc/ActionEndpoint.test.ts +0 -36
  65. package/endpoints/rpc/ConsumerEndpoint.test.ts +0 -29
  66. package/endpoints/rpc/FunctionEndpoint.test.ts +0 -29
  67. package/endpoints/rpc/ProducerEndpoint.test.ts +0 -32
  68. package/errors/DefaultErrorHandler.ts +0 -65
  69. package/http/EntityStream.ts +0 -40
  70. package/http/FetchHttpClient.ts +0 -26
  71. package/http/HttpContentRange.ts +0 -41
  72. package/http/ResponseCache.ts +0 -25
  73. package/http/RetryAfter.ts +0 -19
  74. package/http/ServerSentEvents.ts +0 -145
  75. package/jest.config.js +0 -12
  76. package/links/AggregateLinkExtractor.ts +0 -28
  77. package/links/HalLinkExtractor.ts +0 -45
  78. package/links/HeaderLinkExtractor.ts +0 -56
  79. package/serializers/JsonSerializer.ts +0 -25
  80. /package/endpoints/generic/{index.ts → index.d.ts} +0 -0
  81. /package/endpoints/raw/{index.ts → index.d.ts} +0 -0
  82. /package/endpoints/reactive/{index.ts → index.d.ts} +0 -0
  83. /package/endpoints/rpc/{index.ts → index.d.ts} +0 -0
  84. /package/errors/{ErrorHandler.ts → ErrorHandler.d.ts} +0 -0
  85. /package/errors/{index.ts → index.d.ts} +0 -0
  86. /package/http/{index.ts → index.d.ts} +0 -0
  87. /package/{index.ts → index.d.ts} +0 -0
  88. /package/links/{index.ts → index.d.ts} +0 -0
  89. /package/serializers/{index.ts → index.d.ts} +0 -0
@@ -1,45 +0,0 @@
1
- import { Link } from "./Link";
2
- import { LinkExtractor } from "./LinkExtractor";
3
- import { HttpHeader } from "../http";
4
-
5
- /**
6
- * Extracts links from JSON bodies according to the Hypertext Application Language (HAL) specification.
7
- */
8
- export class HalLinkExtractor implements LinkExtractor {
9
- /**
10
- * @inheritDoc
11
- */
12
- async getLinks(response: Response): Promise<Link[]> {
13
- const contentType = response.headers.get(HttpHeader.ContentType);
14
- if (contentType?.startsWith("application/hal+json")) {
15
- return this.parseJsonBody(await response.clone().json());
16
- } else {
17
- return [];
18
- }
19
- }
20
-
21
- private parseJsonBody(body: any) {
22
- const links: Link[] = [];
23
-
24
- const linkContainer: { [key: string]: any; } = body._links;
25
- if (linkContainer) {
26
- for (const rel in linkContainer) {
27
- if (Array.isArray(linkContainer[rel])) {
28
- for (const link of linkContainer[rel]) {
29
- links.push(this.parseLink(rel, link));
30
- }
31
- } else {
32
- links.push(this.parseLink(rel, linkContainer[rel]));
33
- }
34
- }
35
- }
36
-
37
- return links;
38
- }
39
-
40
- private parseLink(rel: string, obj: any) {
41
- if (!obj.href)
42
- throw new Error("The link header is lacking the mandatory 'href' field.");
43
- return new Link(rel, obj.href, obj.title, obj.templated ? true : false);
44
- }
45
- }
@@ -1,56 +0,0 @@
1
- import { Link } from "./Link";
2
- import { LinkExtractor } from "./LinkExtractor";
3
- import { HttpHeader } from "../http";
4
-
5
- /**
6
- * Extracts links from HTTP headers.
7
- */
8
- export class HeaderLinkExtractor implements LinkExtractor {
9
- /**
10
- * @inheritDoc
11
- */
12
- async getLinks(response: Response) {
13
- return response.headers.get(HttpHeader.Link)
14
- ?.match(/<[^>]*>\s*(\s*;\s*[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*")))*(,|$)/g)
15
- ?.map(value => this.parseLink(value))
16
- ?? [];
17
- }
18
-
19
- private parseLink(value: string) {
20
- const split = this.split(value, ">");
21
- const href = split.left.substring(1);
22
- let rel: string | undefined;
23
- let title: string | undefined;
24
- let templated = false;
25
-
26
- split.right.match(/[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*"))/g)?.forEach(param => {
27
- const paramSplit = this.split(param, "=");
28
- if (paramSplit.left === "rel") {
29
- rel = paramSplit.right;
30
- } else if (paramSplit.left === "title") {
31
- title = paramSplit.right;
32
- if (title.startsWith('"') && title.endsWith('"')) {
33
- title = title.substring(1, title.length - 1);
34
- }
35
- } else if (paramSplit.left === "templated" && paramSplit.right === "true") {
36
- templated = true;
37
- }
38
- });
39
-
40
- if (!rel) throw new Error("The link header is lacking the mandatory 'rel' field.");
41
- return new Link(rel, href, title, templated);
42
- }
43
-
44
- private split(str: string, separator: string): { left: string, right: string } {
45
- const result = str.split(separator, 2);
46
- return (result.length === 2)
47
- ? {
48
- left: result[0],
49
- right: result[1] + str.slice(result.join(separator).length)
50
- }
51
- : {
52
- left: result[0],
53
- right: ''
54
- };
55
- }
56
- }
@@ -1,25 +0,0 @@
1
- import { Serializer } from "./Serializer";
2
-
3
- /**
4
- * Serializes and deserializes entities as JSON.
5
- */
6
- export class JsonSerializer implements Serializer {
7
- /**
8
- * @inheritDoc
9
- */
10
- readonly supportedMediaTypes = ["application/json"];
11
-
12
- /**
13
- * @inheritDoc
14
- */
15
- serialize<T>(entity: T) {
16
- return JSON.stringify(entity);
17
- }
18
-
19
- /**
20
- * @inheritDoc
21
- */
22
- deserialize<T>(text: string) {
23
- return JSON.parse(text) as T;
24
- }
25
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes