kodepandai / lunox

Laravel-Flavoured Nodejs Framework
https://lunox.js.org
MIT License
77 stars 8 forks source link

[lunox-eloquent] Need Documentation of How to use `@lunoxjs/eloquent` #56

Closed djamez closed 8 months ago

djamez commented 9 months ago

Hello. Thank you for this wonderful package. It appears that in package next, you install the typeorm DatabaseServiceProvider. Installing eloquent and subsequently replacing the provider in app/config fails with dependency errors:

TypeError: Cannot read properties of undefined (reading 'make')
    at Proxy.resolveFacadeInstance (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+eloquent@2.0.0-next_@lunoxjs+core@2.0.0-beta.1_bcrypt@5.1.1_knex@2.5.1_objection@3.1.4/node_modules/@lunoxjs/eloquent/node_modules/@lunoxjs/core/dist/ViewFactory-bbd4d106.mjs:1:8753)
    at Proxy.<anonymous> (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+eloquent@2.0.0-next_@lunoxjs+core@2.0.0-beta.1_bcrypt@5.1.1_knex@2.5.1_objection@3.1.4/node_modules/@lunoxjs/eloquent/node_modules/@lunoxjs/core/dist/ViewFactory-bbd4d106.mjs:1:8310)
    at b.boot (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+eloquent@2.0.0-next_@lunoxjs+core@2.0.0-beta.1_bcrypt@5.1.1_knex@2.5.1_objection@3.1.4/node_modules/@lunoxjs/eloquent/dist/index.mjs:1:8928)
    at se.boot (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+core@2.0.0-beta.1/node_modules/@lunoxjs/core/dist/index.js:1:2878)
    at async d.bootstrap (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+core@2.0.0-beta.1/node_modules/@lunoxjs/core/dist/chunk-5JSYJ6R5.js:1:263)
    at async se.bootstrapWith (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+core@2.0.0-beta.1/node_modules/@lunoxjs/core/dist/index.js:1:2538)
    at async Kernel2.start (file:///lunox-app/src/node/lunox/lunox-002/node_modules/.pnpm/@lunoxjs+core@2.0.0-beta.1/node_modules/@lunoxjs/core/dist/index.js:1:4066)
    at async file:///lunox-app/src/node/lunox/lunox-002/dist/index.js:15:1

I know some prefer TypeORM or even Drizzle, but is eloquent still a viable option for those that may prefer it?

axmad386 commented 9 months ago

Oh thank you for reporting this. Indeed I didn't expect people try to run this project :rofl:. And thank you for remind me that Objection and Knex (which is lunox eloquent dependency) is the best legacy ORM ever. I will take a look and try to reproduce this

axmad386 commented 9 months ago

Hi @djamez, can you create some repo to reproduce this. I cannot reproduce the issue. To use @lunoxjs/eloquent as ORM, you also need to configure the config/database.ts file. This is the example https://github.com/kodepandai/lunox/blob/5c0c60afb9461889153584c271964db41535607b/packages/lunox-eloquent/test/config/database.ts

axmad386 commented 9 months ago

Hi @djamez, I've created a repository as an example of how to use @lunoxjs/eloquent as a database manager. Here is the link https://github.com/axmad386/lunox-api-eloquent Unfortunately, we can't currently use @lunoxjs/event and @lunoxjs/mail with eloquent because I haven't developed the driver for eloquent yet. If you're interested in using it, we can discuss and work together to create the driver. Basic usage of objection (knex) is supported, you can create Model and relation to it plus additional function like Laravel eloquent (appends, hidden attribute). Please take a look of the User Model. I am sorry for lack of documentation, since only me that mantain this monorepo :cry:

When you run the example project, don't forget to setup the .env, run the migration first and seeder

pnpm artisan migrate
pnpm artisan db:seed
djamez commented 9 months ago

Hello

I tried again today and it appears there is a new fast-xml-parser dependency that is not being installed:

Require stack:
- /old-data/src/node/lunox/lunox-003/node_modules/.pnpm/@aws-sdk+core@3.529.0/node_modules/@aws-sdk/core/dist-cjs/index.js
- /old-data/src/node/lunox/lunox-003/node_modules/.pnpm/@aws-sdk+client-s3@3.529.0/node_modules/@aws-sdk/client-s3/dist-cjs/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/old-data/src/node/lunox/lunox-003/node_modules/.pnpm/@aws-sdk+core@3.529.0/node_modules/@aws-sdk/core/dist-cjs/index.js:372:30)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Module.require (node:internal/modules/cjs/loader:1115:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/old-data/src/node/lunox/lunox-003/node_modules/.pnpm/@aws-sdk+core@3.529.0/node_modules/@aws-sdk/core/dist-cjs/index.js',
    '/old-data/src/node/lunox/lunox-003/node_modules/.pnpm/@aws-sdk+client-s3@3.529.0/node_modules/@aws-sdk/client-s3/dist-cjs/index.js'
  ]
}

I went ahead and installed it: pnpm install fast-xml-parser.

Now there is another dependency problem with flydrive:

 WARN  Issues with peer dependencies found
.
└─┬ @kodepandai/flydrive-s3 3.0.1
  └── ✕ unmet peer @kodepandai/flydrive@3.0.0: found 3.0.1

The flydrive-s3 package published on NPM has the version hard-coded to 3.0.0:

"peerDependencies": {
    "@kodepandai/flydrive": "3.0.0"
  },

  "devDependencies": {
    "@aws-sdk/types": "^3.357.0",
    "@kodepandai/flydrive": "3.0.0",
    "@types/fs-extra": "^9.0.7",
    "fs-extra": "^9.1.0"
  },

Kindly update the dependencies on the published NPM package.

djamez commented 9 months ago

I temporarily removed flydrive and flydrive-s3 from package.json. The default typeorm driver works as expected and I can access the /api/users route.

Next, I attempted to install the eloquent driver using pnpm install @lunoxjs/eloquent.

Now I get another dependency issue:

 WARN  Issues with peer dependencies found
.
└─┬ @lunoxjs/eloquent 2.0.0-next
  └── ✕ unmet peer @lunoxjs/core@2.0.0-next: found 2.0.0-beta.1
axmad386 commented 8 months ago

@djamez I am sorry for lack of documentation. You should install the same packages version, for example if you use @lunoxjs/core v2.0.0-beta.1 then you should install @lunoxjs/eloquent v2.0.0-beta.1. Or you can install with proper tag.

pnpm add @lunoxjs/eloquent@beta

When all packages is stable enough, I will publish them under latest release.

For better example, please take a look on this example repo https://github.com/axmad386/lunox-api-eloquent

And yes, I should fix the peer dependencies version, thanks for reporting this

djamez commented 8 months ago

I've cloned the repo to https://github.com/djamez/lunox-api-eloquent by implementing a simple todo API.

All is good so far, except that the documentation for validation appears to be in PHP format. Converting it to JS format (app/Model/Todo.rules) seems to solve the problem.

I will continue with subsequent tests and report my findings accordingly.

axmad386 commented 8 months ago

Oh, that's my bad, haha. I should focus on writing good documentation for now 😅. This project was initially used for my personal needs, but it seems it could become a great framework with proper maintenance and documentation. Thanks @djamez for the experiment of lunoxjs