You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, first of all wanted to say thank you for working on such a complex project. I know people create many issues for this project but I couldnt find any specifically for the problem I encountered and I think this could be an interesting bug report & constructive feedback for the initial dev experience.
The code below could also be a nice test case for treeshaking and top-level async/await feature when parcel ships them by default, since I published the universal ORM @memoria/model on npm, it is a very flexible and intuitive, advanced/universal ORM for JS.
I followed bunch of treeshaking related issues here, it took me some time to dig down which one to look at, had found one but than again it also wasn't clear if/when it will get implemented or what is today causing the blocking, would be helpful if we perhaps shortly explain/warn in the README in the meantime.
// sketchpad.ts// by default memoria Model uses in-memory adapter for CRUD operations:importModel,{Config,PrimaryGeneratedColumn,Generated,PrimaryColumn,Column,BelongsTo,HasMany,CreateDateColumn,}from"@memoria/model";classPhotoextendsModel{
@PrimaryGeneratedColumn()id: number;
@Column()name: string;
@Column()href: string;
@Column("bool")is_public: boolean;
@BelongsTo((type)=>User,(user)=>user.photos)user: User;}classUserextendsModel{
@PrimaryGeneratedColumn("increment")id: number;
@Column()first_name: string;
@Column()last_name: string;
@CreateDateColumn()created_at: string;
@Column("int")
@Generated()points: number;
@HasMany((type)=>Photo,(photo)=>photo.user)photos: Photo[];}leta=newUser();console.log("new User() output:");console.log(a);asyncfunctionmain(){try{awaitConfig.resetForTests();// console.log(Config.Schemas[1].relations);letuser=awaitUser.insert({first_name: "Izel",last_name: "Nakri"});console.log("User insert:");console.log(user);letupdatedUser=awaitUser.update({id: user.id,first_name: "Moris"});console.log("User update:");console.log(updatedUser);letsavedUser=awaitUser.update({id: user.id,first_name: "Mo"});console.log("User save:");console.log(savedUser);letfoundUser=awaitUser.find(user.id);console.log("foundUser:");console.log(foundUser);console.log("User.count:",awaitUser.count());letdeletedUser=awaitUser.delete(user);console.log("deletedUser:");console.log(deletedUser);console.log("User.count:",awaitUser.count());letinsertedUsers=awaitUser.insertAll([{first_name: "Yukihiro",last_name: "Matsumoto"},{first_name: "Yehuda",last_name: "Katz"},]);console.log("insertedUsers:");console.log(insertedUsers);console.log("User.count:",awaitUser.count());letfoundUsers=awaitUser.findAll();console.log("foundUsers:");console.log(foundUsers);letchangedUsers=awaitUser.updateAll(foundUsers.map((foundUser)=>{foundUser.first_name="Changed";returnfoundUser;}));console.log("changedUsers:");console.log(changedUsers);letsavedUsers=awaitUser.saveAll(foundUsers.map((foundUser)=>{foundUser.first_name="Changed2";returnfoundUser;}));console.log("savedUsers:");console.log(savedUsers);console.log("User.count:",awaitUser.count());letallDeletedUsers=awaitUser.deleteAll(changedUsers);console.log("allDeletedUsers:");console.log(allDeletedUsers);console.log("User.count:",awaitUser.count());// Relationships}catch(error){console.log("error:");console.log(error);}console.log("-------------- THE END ---------------");}main();// without wrapping it in main(top-level async/await) caused a build error.
<!DOCTYPE html><html><head><metacharset="UTF-8"><metaname="viewport" content="width=device-width, initial-scale=1"><title></title><scriptsrc="./sketchpad.ts" type="module"></script></head><body><h1>This is index.html</h1></body></html>
$ parcel index.html
This succeeeds in the terminal but when viewed on localhost:1234:
index.js:255 Uncaught TypeError: Cannot read properties of undefined (reading 'MongoEntityManager')
at Object.MongoEntityManager (index.js:255)
at esmodule-helpers.js:16
at Array.forEach (<anonymous>)
at Object.exports.exportAll (esmodule-helpers.js:10)
at Object.gBE0e.reflect-metadata (index.ts:97)
at newRequire (index.c88dcc78.js:71)
at localRequire (index.c88dcc78.js:83)
at Object.42dNh.typeorm (index.js:1)
at newRequire (index.c88dcc78.js:71)
at localRequire (index.c88dcc78.js:83)
This happens because code is not properly tree-shaked, @memoria/adapters include SQLAdapter export which probably triggers this error.
I just run them on the latest nightly and it works! Thank you for quick response, would appreciate if we cut a new release candidate version soon with this.
I still had to wrap the script in an async function main() {, the top-level await transpilation for a typescript file still doesn't work. I get Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules is this intentional? What is the latest decision on top-level await for parcel currently? I'm curious because top-level await scripts work on node.js currently.
🐛 bug report
Hi there, first of all wanted to say thank you for working on such a complex project. I know people create many issues for this project but I couldnt find any specifically for the problem I encountered and I think this could be an interesting bug report & constructive feedback for the initial dev experience.
The code below could also be a nice test case for treeshaking and top-level async/await feature when parcel ships them by default, since I published the universal ORM
@memoria/model
on npm, it is a very flexible and intuitive, advanced/universal ORM for JS.I followed bunch of treeshaking related issues here, it took me some time to dig down which one to look at, had found one but than again it also wasn't clear if/when it will get implemented or what is today causing the blocking, would be helpful if we perhaps shortly explain/warn in the README in the meantime.
🎛 Configuration (.babelrc, package.json, cli command)
No configuration
🤔 Expected Behavior
Program runs correctly, zero-config.
😯 Current Behavior
Given these two files:
$ parcel index.html
This succeeeds in the terminal but when viewed on
localhost:1234
:This happens because code is not properly tree-shaked,
@memoria/adapters
includeSQLAdapter
export which probably triggers this error.WIP @Memoria API: https://github.com/izelnakri/memoria
💁 Possible Solution
Both top-level await and treeshaking should work zero config.
🔦 Context
Provided above. Let me know if we should amend anything here, I can edit.
💻 Code Sample
Provided above.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: