Skip to content
This repository was archived by the owner on Apr 12, 2026. It is now read-only.

feat(syndesi): introduce client for hypermedia-like JSON/HTTP - #238

Open
dherges wants to merge 5 commits into
masterfrom
syndesi
Open

feat(syndesi): introduce client for hypermedia-like JSON/HTTP#238
dherges wants to merge 5 commits into
masterfrom
syndesi

Conversation

@dherges

@dherges dherges commented Feb 16, 2019

Copy link
Copy Markdown
Contributor

No description provided.

@dherges
dherges marked this pull request as ready for review February 18, 2019 06:25
* constructor(private api: ApiClient)
*
* fetchNextPage(res: Respurce<Entity>) {
* return this.api.call(res).get('next').send<>();

Copy link
Copy Markdown
Contributor Author

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-typed Resource<any>
  • <R>call() w/ generic type to get an R extends Resource<?>

Thus, the Call<R extends Resource<?>> call class would work with Resource....

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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> {

Copy link
Copy Markdown
Contributor Author

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];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread libs/syndesi/src/lib/link.functions.ts
Comment thread libs/syndesi/src/lib/link.functions.ts
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant