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.
- package/README.md +41 -5
- package/endpoints/{CachingEndpoint.ts → CachingEndpoint.d.ts} +0 -1
- package/endpoints/Endpoint.d.ts +121 -0
- package/endpoints/Endpoint.js +1 -1
- package/endpoints/{EntryEndpoint.ts → EntryEndpoint.d.ts} +7 -27
- package/endpoints/generic/{CollectionEndpoint.ts → CollectionEndpoint.d.ts} +2 -5
- package/endpoints/generic/{ETagEndpointBase.ts → ETagEndpointBase.d.ts} +8 -38
- package/endpoints/generic/ETagEndpointBase.js +16 -4
- package/endpoints/generic/{ElementEndpoint.ts → ElementEndpoint.d.ts} +12 -70
- package/endpoints/generic/{GenericCollectionEndpoint.ts → GenericCollectionEndpoint.d.ts} +21 -106
- package/endpoints/generic/{IndexerEndpoint.ts → IndexerEndpoint.d.ts} +4 -11
- package/endpoints/generic/PartialResponse.d.ts +19 -0
- package/endpoints/{index.ts → index.d.ts} +1 -2
- package/endpoints/raw/{BlobEndpoint.ts → BlobEndpoint.d.ts} +9 -29
- package/endpoints/raw/{UploadEndpoint.ts → UploadEndpoint.d.ts} +4 -18
- package/endpoints/reactive/Delay.d.ts +7 -0
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.d.ts +32 -0
- package/endpoints/reactive/{PollingEndpoint.ts → PollingEndpoint.d.ts} +7 -34
- package/endpoints/reactive/SseStreamingEndpoint.d.ts +50 -0
- package/endpoints/reactive/{StreamingCollectionEndpoint.ts → StreamingCollectionEndpoint.d.ts} +2 -5
- package/endpoints/reactive/{StreamingEndpoint.ts → StreamingEndpoint.d.ts} +5 -27
- package/endpoints/rpc/{ActionEndpoint.ts → ActionEndpoint.d.ts} +3 -10
- package/endpoints/rpc/{ConsumerEndpoint.ts → ConsumerEndpoint.d.ts} +3 -12
- package/endpoints/rpc/{FunctionEndpoint.ts → FunctionEndpoint.d.ts} +3 -14
- package/endpoints/rpc/{ProducerEndpoint.ts → ProducerEndpoint.d.ts} +3 -11
- package/endpoints/rpc/{RpcEndpointBase.ts → RpcEndpointBase.d.ts} +4 -12
- package/errors/DefaultErrorHandler.d.ts +21 -0
- package/errors/{Errors.ts → Errors.d.ts} +20 -21
- package/http/EntityStream.d.ts +10 -0
- package/http/FetchHttpClient.d.ts +15 -0
- package/http/FetchHttpClient.js +1 -1
- package/http/{HttpClient.ts → HttpClient.d.ts} +1 -3
- package/http/HttpContentRange.d.ts +23 -0
- package/http/{HttpHeader.ts → HttpHeader.d.ts} +1 -1
- package/http/{HttpMethod.ts → HttpMethod.d.ts} +1 -1
- package/http/{HttpStatusCode.ts → HttpStatusCode.d.ts} +1 -1
- package/http/ResponseCache.d.ts +19 -0
- package/http/RetryAfter.d.ts +6 -0
- package/http/ServerSentEvents.d.ts +50 -0
- package/links/AggregateLinkExtractor.d.ts +17 -0
- package/links/HalLinkExtractor.d.ts +13 -0
- package/links/HeaderLinkExtractor.d.ts +13 -0
- package/links/{Link.ts → Link.d.ts} +6 -2
- package/links/{LinkExtractor.ts → LinkExtractor.d.ts} +0 -1
- package/package.json +64 -14
- package/serializers/JsonSerializer.d.ts +18 -0
- package/serializers/{Serializer.ts → Serializer.d.ts} +0 -2
- package/endpoints/Endpoint.test.ts +0 -300
- package/endpoints/Endpoint.ts +0 -247
- package/endpoints/generic/CollectionEndpoint.test.ts +0 -215
- package/endpoints/generic/ElementEndpoint.test.ts +0 -262
- package/endpoints/generic/GenericCollectionEndpoint.test.ts +0 -123
- package/endpoints/generic/IndexerEndpoint.test.ts +0 -12
- package/endpoints/generic/PartialResponse.ts +0 -28
- package/endpoints/raw/BlobEndpoint.test.ts +0 -52
- package/endpoints/raw/UploadEndpoint.test.ts +0 -47
- package/endpoints/reactive/Delay.ts +0 -26
- package/endpoints/reactive/GenericStreamingCollectionEndpoint.ts +0 -73
- package/endpoints/reactive/PollingEndpoint.test.ts +0 -84
- package/endpoints/reactive/SseStreamingEndpoint.test.ts +0 -169
- package/endpoints/reactive/SseStreamingEndpoint.ts +0 -115
- package/endpoints/reactive/StreamingCollectionEndpoint.test.ts +0 -110
- package/endpoints/reactive/StreamingEndpoint.test.ts +0 -130
- package/endpoints/rpc/ActionEndpoint.test.ts +0 -36
- package/endpoints/rpc/ConsumerEndpoint.test.ts +0 -29
- package/endpoints/rpc/FunctionEndpoint.test.ts +0 -29
- package/endpoints/rpc/ProducerEndpoint.test.ts +0 -32
- package/errors/DefaultErrorHandler.ts +0 -65
- package/http/EntityStream.ts +0 -40
- package/http/FetchHttpClient.ts +0 -26
- package/http/HttpContentRange.ts +0 -41
- package/http/ResponseCache.ts +0 -25
- package/http/RetryAfter.ts +0 -19
- package/http/ServerSentEvents.ts +0 -145
- package/jest.config.js +0 -12
- package/links/AggregateLinkExtractor.ts +0 -28
- package/links/HalLinkExtractor.ts +0 -45
- package/links/HeaderLinkExtractor.ts +0 -56
- package/serializers/JsonSerializer.ts +0 -25
- /package/endpoints/generic/{index.ts → index.d.ts} +0 -0
- /package/endpoints/raw/{index.ts → index.d.ts} +0 -0
- /package/endpoints/reactive/{index.ts → index.d.ts} +0 -0
- /package/endpoints/rpc/{index.ts → index.d.ts} +0 -0
- /package/errors/{ErrorHandler.ts → ErrorHandler.d.ts} +0 -0
- /package/errors/{index.ts → index.d.ts} +0 -0
- /package/http/{index.ts → index.d.ts} +0 -0
- /package/{index.ts → index.d.ts} +0 -0
- /package/links/{index.ts → index.d.ts} +0 -0
- /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
|
/package/{index.ts → index.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|