Skip to content

Commit ac02ca1

Browse files
committed
fix(syndesi): try to keep type declaration for resource metadata
1 parent ba54cb7 commit ac02ca1

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

libs/syndesi/src/lib/call.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpClient, HttpResponse } from '@angular/common/http';
22
import { Observable } from 'rxjs';
33
import { map } from 'rxjs/operators';
4-
import { Resource } from './resource.interfaces';
4+
import { Resource, ResourceMetadata } from './resource.interfaces';
55
import { expand, UriParams } from './uri';
66

77
const toNextCall = <S, T>(call: Call<S>) => {
@@ -15,7 +15,7 @@ const toNextCall = <S, T>(call: Call<S>) => {
1515
};
1616

1717
/**
18-
* A `Call` is a single HTTP interaction
18+
* A `Call` is a single HTTP interaction for exchanging a resource between client and server.
1919
*
2020
* ### How To Use
2121
*
@@ -45,6 +45,7 @@ export class Call<T> {
4545
private _method: string;
4646
private _options = {};
4747

48+
// TODO: public resource: T & ResourceMetadata
4849
constructor(
4950
http: HttpClient | Call<any>,
5051
public resource: Resource<T>,

libs/syndesi/src/lib/embedded.functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function hasEmbedded<T>(value: any): value is ResourceWithEmbedded<T> {
88
export interface EmbeddedOpts<T> {
99
guard?: (value: any) => value is T;
1010
shouldThrow?: boolean;
11-
};
11+
}
1212

1313
/**
1414
* Return the embedded resource identified by relation `rel` from parent `res`.

libs/syndesi/src/lib/link.functions.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ export function isLinks(value: any): value is Link[] {
1414

1515
export interface LinkOpts {
1616
shouldThrow?: boolean;
17-
};
17+
}
1818

19+
/**
20+
* Return the link identified by relation `rel` from resource `res`.
21+
*
22+
* @param rel Relation name
23+
* @param res Parent resource
24+
* @param opts Set `shouldThrow`, if you want an error instead of an `undefined` return value
25+
* @return An object of type `Link` or an `undefined` value
26+
* @stable
27+
*/
1928
export function link(rel: string, res: any, opts?: LinkOpts): Link {
2029
if (hasLinks(res)) {
2130
const linkForRel = res._links[rel];
@@ -30,6 +39,15 @@ export function link(rel: string, res: any, opts?: LinkOpts): Link {
3039
}
3140
}
3241

42+
/**
43+
* Return an array of links identified by relation `rel` from resource `res`.
44+
*
45+
* @param rel Relation name
46+
* @param res Parent resource
47+
* @param opts Set `shouldThrow`, if you want an error instead of an `undefined` return value
48+
* @return Array of `Link` or an `undefined` value
49+
* @stable
50+
*/
3351
export function links(rel: string, res: any, opts?: LinkOpts): Link[] {
3452
if (hasLinks(res)) {
3553
const linkForRel = res._links[rel];

libs/syndesi/src/lib/resource.interfaces.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export interface Link {
5757
*
5858
* @stable
5959
*/
60-
export type Resource<T> = T & {
60+
export type Resource<T> = T & ResourceMetadata;
61+
62+
export interface ResourceMetadata {
6163
_links: {
6264
self: Link;
6365
[key: string]: Link | Link[];

0 commit comments

Comments
 (0)