gid-oss / dataui-nestjs-crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
129 stars 31 forks source link

Why don't you raise the version of Typeorm? #17

Open SuzGori opened 1 year ago

SuzGori commented 1 year ago

I am having trouble with the following error. The version of Typescript seems to be old.

https://github.com/typeorm/typeorm/pull/9357

zaro commented 1 year ago

@SuzGori can you provide a bit more information what exactly is your problem ?

The issue linked is really about TypeORM, and there is nothing stopping you from using this library with newer typescript version.

SuzGori commented 1 year ago

@zaro Thanks for the reply. I may have mistakenly thought it was a Typescript issue from the Issue. I got the following error message and arrived at the ↑ link.

Error content

node_modules/@dataui/crud-typeorm/lib/typeorm-crud.service.d.ts:15:32 - error TS2344: Type 'T' does not satisfy the constraint 'ObjectLiteral'.

15     protected repo: Repository<T>;
zaro commented 1 year ago

@SuzGori what versions or TypeORM and TypeScript are you using ?

If possible it will be very helpful if you can provide with a minimal reproduction example repo.

SuzGori commented 1 year ago

Typescript and TypeORM versions are as follows

├── typeorm@0.3.17 ├── typescript@5.0.4

SuzGori commented 1 year ago

@zaro I edited the following source and it was cured. Do I need to pull it?

typeorm-crud.service.d.ts

export declare class TypeOrmCrudService<T extends ObjectLiteral> extends CrudService<T, DeepPartial<T>> {

Add extends ObjectLiteral

zaro commented 1 year ago

@SuzGori I just released 5.3.1-alpha.0

It has Typescript, nestjs, etc. updated.

Can you please confirm that the problem is resolved?

SuzGori commented 1 year ago

@zaro Thanks for the reply. The errors did not change.

zaro commented 1 year ago

@SuzGori I updated typescript & typeorm in the alpha because I assumed the older versions were the cause for the error.

Thank you for opening the PR, but I want to first understand how is this error happening ?

Generally the TypeORM models do NOT extend ObjectLiteral , so I am very curious why is this happening in your case .

Can you also provide the model you get this error from ?

SuzGori commented 1 year ago

@zaro Is that what you mean? I had assumed that others would have the same symptoms.

Then maybe it is a special case.

I am using Angular Universal to run NestJS this time. That may have something to do with it.

Model is very simple.


    @PrimaryGeneratedColumn('uuid')
    uuid: string | undefined;

    @Column({ type: 'text', nullable: true })
    name: string | undefined;

    @CreateDateColumn({ type: 'timestamp', nullable: true })
    created_at: Date | undefined;

    @UpdateDateColumn({ type: 'timestamp', nullable: true })
    updated_at: Date | undefined;
zaro commented 1 year ago

@SuzGori OK I have no idea what angular universal is 😊

I meant the whole model class, the actual columns are irrelevant, but any parent classes will definitely matter. You see, if it was simply typeorm / typescript version this would have shown in the tests. But it doesn't, and I think it somewhat specific to your setup.

The bets thing you can do is create a minimal reproduction example, so that I can debug it myself. Else please at least provide a complete model definition that causes the error and also how exactly do you run it ( angular universal, etc.)

SuzGori commented 1 year ago

@zaro Thankyou! A minimal repository was created. See below.

https://github.com/SuzGori/angular-universal-nest

You can also JIT compile with the following command.

npm ci
npm run dev:ssr

Note: This repository does not contain DB libraries.

SuzGori commented 1 year ago

@zaro Is there anything I can do to help you?

zaro commented 1 year ago

@SuzGori I just got time to check your repo and I am trying to figure out what is the issue exactly.

SuzGori commented 1 year ago

@zaro Oh wow! Thanks for your excellent reply! I would be happy to do something for you too!

zaro commented 1 year ago

@SuzGori please check version 5.3.1-alpha.3 . I did test with your repo and seems fine.

Once you confirm, I am going to publish it as release version.

SuzGori commented 1 year ago

@zaro Thank you very much! I will check it out!

SuzGori commented 1 year ago

@zaro

I am having trouble with the following webpack error.

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
   at objKeys (/Users/user/dir/project/dist/app/server/vendor.js:1795:31)

vendor.js:1795:31 is below

/***/ 6844:
/*!********************************************************!*\
  !*** ./node_modules/@dataui/crud-util/lib/obj.util.js ***!
  \********************************************************/
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({
  value: true
}));
exports.getOwnPropNames = exports.objKeys = void 0;
const objKeys = val => Object.keys(val); //  <--- Error
exports.objKeys = objKeys;
const getOwnPropNames = val => Object.getOwnPropertyNames(val);
exports.getOwnPropNames = getOwnPropNames;

/***/ }),

another

at Object.26414 (/Users/user/dir/project/dist/app/server/vendor.js:230:35)

/***/ 26414:
/*!************************************************************************!*\
  !*** ./node_modules/@dataui/crud-request/lib/request-query.builder.js ***!
  \************************************************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({
  value: true
}));
exports.RequestQueryBuilder = void 0;
const crud_util_1 = __webpack_require__(/*! @dataui/crud-util */ 80308);
const qs_1 = __webpack_require__(/*! qs */ 29754);
const request_query_validator_1 = __webpack_require__(/*! ./request-query.validator */ 57996); // <-- Error
class RequestQueryBuilder {
  constructor() {

and another

at Object.70722 (/Users/user/dir/project/dist/app/server/vendor.js:3474:24)

/***/ 70722:
/*!********************************************************************************!*\
  !*** ./node_modules/@dataui/crud/lib/interceptors/crud-request.interceptor.js ***!
  \********************************************************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";

var __decorate = this && this.__decorate || function (decorators, target, key, desc) {
  var c = arguments.length,
    r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
    d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", ({
  value: true
}));
exports.CrudRequestInterceptor = void 0;
const common_1 = __webpack_require__(/*! @nestjs/common */ 49086);
const crud_request_1 = __webpack_require__(/*! @dataui/crud-request */ 68230); //<---Error
zaro commented 1 year ago

@SuzGori Now this is most probably because of different TS module settings for your project and the library.

Unfortunately I can't help you with that, but her is what I think about the problem ( take it with a gain of salt, it might be rubbish):

The library is compiled with "commonjs" (https://github.com/gid-oss/dataui-nestjs-crud/blob/master/tsconfig.json#L3) as the module system for most wide compatibility, and andgular universal uses the much newer : https://github.com/SuzGori/angular-universal-nest/blob/main/tsconfig.json#L20

I have no idea how to resolve that currently, usually what helps is using require() instead of import, or you can try a different import syntax like import CRUD from '@dataui/...'.

SuzGori commented 1 year ago

@zaro Thank you very much. I will check a little on my end. The server version of tsconfig for AngularUniversal was commonjs. https://github.com/SuzGori/angular-universal-nest/blob/829ce5de2790b1e629fc003daf74e20535668dc7/tsconfig.server.json#L5C7-L5C7

SuzGori commented 1 year ago

@zaro It's still unresolved. Worst case scenario, I'll clone the repository and continue development, but I hope there's a solution.