-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(syndesi): introduce client for hypermedia-like JSON/HTTP #238
base: master
Are you sure you want to change the base?
Conversation
* constructor(private api: ApiClient) | ||
* | ||
* fetchNextPage(res: Respurce<Entity>) { | ||
* return this.api.call(res).get('next').send<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weak link in the Call
api. From <R>send()
, you always get a Call<R>
with a Resource<R>
. What about Call<R, D>
to get a R extends Resource<D>
?
I think we need:
call()
w/o generics to get an any-typedResource<any>
<R>call()
w/ generic type to get anR extends Resource<?>
Thus, the Call<R extends Resource<?>>
call class would work with Resource....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export class Call2<R> {
constructor(
public resource: R & ResourceMetadata
) {}
// PROBLEM: only one of the method declaration overrides seems to work...
//public next(): Call2<ResourceMetadata>;
public next<NextResource>(): Call2<NextResource> {
return new Call2(this.resource);
}
}
interface FooRes extends Resource {
bar: string;
}
const resource1: Resource = {};
const call2 = new Call2({}); // <-- good, compile error
call2.resource._links; // <-- good, type ResourceMetadata found
const next1 = call2.next();
const next2 = call2.next<FooRes>();
next1.resource._links.self; // <-- bad, type ResourceMetadata not recognized
next2.resource._links.self; // <-- good
next2.resource.bar; // <-- good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In typescript playground, it's supposed to work in TypeScript 3.3
* @return Embedded resource or an `undefined` value | ||
* @stable | ||
*/ | ||
export function embedded<T>(rel: string, res: any, opts?: EmbeddedOpts<T>): Resource<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
*/ | ||
export function embeddeds<T>(rel: string, res: any, opts?: EmbeddedOpts<T>): Resource<T>[] { | ||
if (hasEmbedded(res)) { | ||
const em = res._embedded[rel]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.