Skip to content
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

TypeScript - Backing store support #2613

Closed
sebastienlevert opened this issue Apr 26, 2023 · 5 comments · Fixed by #3543
Closed

TypeScript - Backing store support #2613

sebastienlevert opened this issue Apr 26, 2023 · 5 comments · Fixed by #3543
Assignees
Labels
TypeScript Pull requests that update Javascript code WIP
Milestone

Comments

@sebastienlevert
Copy link
Contributor

No description provided.

@sebastienlevert sebastienlevert converted this from a draft issue Apr 26, 2023
@sebastienlevert sebastienlevert added TypeScript Pull requests that update Javascript code and removed Needs: Triage 🔍 labels Apr 26, 2023
@baywet
Copy link
Member

baywet commented Apr 26, 2023

To restore backing store capabilities since we migrated to interfaces we probably need the do the following:

  1. in abstractions implement IBackedModel with a proxy. That proxy would take an IBackingStore as a constructor parameter and route calls to the backing store accordingly.
  2. there might not actually be any changes needed to the generation work at this point (or we should remove the backing store assignment from the model constructore/factory)
  3. in the serialization library instantiate the implementation from point 1 here when the backing store is in use (we could add a constructor parameter/readonly field in all parseNode implementations, and that field would be set by the respective factory. In turns the factory could have a property (getter/setter) in the ParseNodeFactory interface, which in turns would be set by the proxy factory )

@koros
Copy link
Contributor

koros commented Sep 8, 2023

This is a rough draft of how to accomplish the task:

on the abstraction library I'll have the following classes:

export interface IBackedModel {
  /**
   * Gets the store that is backing the model.
   */
  backingStore: BackingStore;
}

class BackedModel implements IBackedModel {
  private backingStore: BackingStore;

  constructor(backingStore: BackingStore) {
    this.backingStore = backingStore;
  }
}

NB: the other classes e.g. InMemoryBackingStore and factory have been omitted, Once that is set up the generator should then generate a model interface (same as current) and a class implementation that extends a BackedModel above and implements the respective interface e.g.

// Generated code
export interface Foo extends Entity, Parsable {
  name?: string | undefined;
}

export class FooBackedModel extends BackedModel implements Foo {
  get name(): string | undefined {
    return this.backingStore.get(name);
  }
  set name(value: string | undefined) {
    this.backingStore.name = value;
  }
}

@koros
Copy link
Contributor

koros commented Sep 8, 2023

@baywet let me know if the above steps need any changes

@baywet
Copy link
Member

baywet commented Sep 8, 2023

this would require people to use classes again, which we'd like to avoid.
What if we designed in the abstractions a proxy, that implements BackedModel using the provided backing store (singleton factory)?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy

@sebastienlevert
Copy link
Contributor Author

Adding @gavinbarron for more insights and potentially workshopping with @koros

@baywet baywet modified the milestones: Kiota v1.7, Kiota v1.8 Oct 3, 2023
@koros koros moved this from Todo to In Progress in Kiota Oct 24, 2023
@baywet baywet closed this as completed Oct 24, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Kiota Oct 24, 2023
@baywet baywet linked a pull request Oct 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TypeScript Pull requests that update Javascript code WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants