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

[feat] Add browser support back in #668

Closed
Toxicable opened this issue Aug 23, 2019 · 4 comments · Fixed by #673
Closed

[feat] Add browser support back in #668

Toxicable opened this issue Aug 23, 2019 · 4 comments · Fixed by #673

Comments

@Toxicable
Copy link
Contributor

It would appear in the 1.0.0 merge the generate-browser.js script was skipped over.
This was the latest version: https://github.com/RobinBuschmann/sequelize-typescript/blob/a05f4fcaa619ab04455ca87a39dacbeb8447a2c1/generate-browser.js

Would be great to have browser support back in for 1.0.0

@RobinBuschmann
Copy link
Member

Hey @Toxicable, thanks for bringing this up. In Version 1.0.0 the folder structure completely changed compared to 0.6.X. So that much more manual work is needed to bring this feature back alive.

Are you using real implementations (e.g. class functions) or just the types of models in your client? I'm asking because if the latter, maybe a mapped type would be a better solution?

@RobinBuschmann
Copy link
Member

And sorry for the late reply

@Toxicable
Copy link
Contributor Author

Toxicable commented Sep 27, 2019

It's all good.
I came up with a far more simplified version here: #673

As for how we use them, we only use properties, we don't define any functions in our Models.

We actually go a bit further than that and noop out all the Sequalize types on Model like this:

class NoopClass {}
const BaseModel: typeof NoopClass = Model as any;

@Table
export class Person extends BaseModel {
  @Colunm  
  name: string
}

This is so you don't get methods like findById(), which wont work in the browser.
Instead on the server we have a repository wrapper which to access the DB

@RobinBuschmann
Copy link
Member

RobinBuschmann commented Sep 27, 2019

I'm just wondering, that the bundler tries to bundle the models at all, since you only use them as types. Actually they should be omitted in general.

// some.ts
import {User} from './models/user';
import _ from 'lodash';

const user: User = _.assign({}, {...});

should become something like:

// some.js
var _ = require('lodash');

var user = _.assign({}, {...});

Nevertheless, I'm totally fine with your solution (#673). Thanks for implementing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants