Giter VIP home page Giter VIP logo

davinci's Introduction

davinci's People

Contributors

annabel-dev avatar billywhizz avatar dependabot[bot] avatar figueras avatar javifraile avatar jferrl avatar jonathanprl avatar joseandrespg avatar juanjoseruiz avatar newtdogg avatar oneflow-build avatar pereiraguilherme avatar pierissimo avatar sekforde avatar szvitek avatar thekiwi avatar ugzuzg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

davinci's Issues

Counting all the elements of a large collection is breaking

Summary

While migrating the ship-api to DaVinci we discovered that trying to list all the shipments was timing out.
The problem seems to be coming from trying to get an exact count of the documents in a very large collection in this line.
According to mongoose's documentation, the countDocuments method doesn't use any index, and it suggests to user estimatedDocumentCount() for large collections.

Problems

  • Using an estimated document count could break pagination -> This could be acceptable for very large collections where it is very unlikely that anyone will get to the last page. A possible solution could be to enable/disable the estimated count through the configuration.
  • Previously, of-base-api was using a mongoose plugin to handle pagination (feathers-mongoose). Using a plugin could be another solution.

Not specifying basepath causes OpenAPI and Express routes to differ

When excluding a controller's base path, it seems the logic for OpenAPI Resource Path generation differs from the Express routing logic.

From what I can tell, the OpenAPI logic attempts to use the basepath if defined (via the @controller decorator) and it falls back to the resourceName (which can be explicitly specified, but if not, it is derived from the Controller name).

The Express logic doesn't respect that same fallback logic however, so it ends up mounting the route without the resourceName.

/*
  DISCLAIMER: the following code may not be 100% accurate, I'll revise it later
*/

// @controller({ basepath: '/api/greet' }) // <-- Commented out!
class GreetController {
	@route.get({ path: '/hello', summary: 'This is the hello method' })
	hello() {
		return { hello: 'yet again' };
	}
}

const createContext = () => ({});
createApp(app, options, (app: express.Application) => {
	createRouter(GreetController, null, createContext, app);
});

Using the above code snippet, I see the Swagger Explorer describing the following:
image

whereas the Express route is mounted at http://localhost:3000/hello (and as a result, the "Try it out" functionality in the Explorer is returned a 404)

If I make a request to just that URL, it works as expected:

image

Entity definition broken

Upgrading DaVinci reflector to latest version @davinci/[email protected] is throwing an exception when starting the API:

{"name":"app","error":{},"msg":"Fatal error during module registration"}
/.../node_modules/@davinci/core/src/entity/EntityDefinition.ts:281
                return reflection.decorators.find(d => d[DecoratorId] === 'entity');
                               ^
TypeError: Cannot read properties of undefined (reading 'find')

Looks like this started happening since this upgrade to @plumier/refect:

#230

We tracked the release of plumier that starts to fail, and the code is working if we downgrade to 1.0.6 and starts to fail if we use 1.1.0:

https://github.com/plumier/plumier/releases/tag/v1.1.0

Maximum request json limit size 1MB

There is a static limit for 1MB of request JSON payload, configured with express middleware. Is it possible to add some framework option to affect this default value? Source

Something like this, for instance:

interface DaVinciOptions {
    ...
    express: {
        json: OptionsJson;
        urlencoded: OptionsUrlencoded;
    }
}

Unable to create virtual in array property

Given the following code:

@openapi.definition({ title: 'Discount', hidden: configOpenapi.internalEndpointsHidden })
@mgoose.schema({ _id: false })
export class Discount {
	@mgoose.prop({ required: true, type: Schema.Types.ObjectId, ref: 'DiscountProfile' })
	@openapi.prop({ required: true })
	discountProfileId?: string;
}

@openapi.definition({ title: 'BrandCreationRequest', hidden: configOpenapi.internalEndpointsHidden })
export class BrandCreationRequest {
	@openapi.prop({ required: true })
	_id: string;

	@mgoose.prop({ required: false, type: [Discount], default: [] })
	@openapi.prop({ required: false, default: [], type: 'array' })
	discounts?: Discount[];
}

Currently it is not possible to create a virtual property using the @mgoose.populate decorator. Tried several options:

  • Using populate decorator directly in the property
  • Using virtual decorator creating a property in the Discounts class.

These options doesn't work either if I add the virtual by code to the Discounts, so it's probably a mongoose limitation.

	@mgoose.prop({ required: true, type: Schema.Types.ObjectId, ref: 'DiscountProfile' })
	@mgoose.populate({
		name: 'discountProfile',
		opts: { ref: 'DiscountProfile', foreignField: '_id', justOne: true },
	})
	@openapi.prop({ required: true })
	discountProfileId?: string;

	@mgoose.virtual({ ref: 'DiscountProfile', localField: 'discountProfileId', foreignField: '_id', justOne: true })
	discountProfile?: DiscountProfileSchema;

  • Using virtual decorator directly in the parent

In this case there is a collision between properties

	@mgoose.prop({ required: false, type: [Discount], default: [] })
	@openapi.prop({ required: false, default: [], type: 'array' })
	@mgoose.virtual({ ref: 'DiscountProfile', localField: 'discounts.discountProfileId', foreignField: '_id', justOne: true })
	discounts?: Discount[];

  • Using populate decorator directly in the property

This might work, but the localField is override internally in the decorator (it is not an input option)

	@mgoose.prop({ required: false, type: [Discount], default: [] })
	@openapi.prop({ required: false, default: [], type: 'array' })
	@mgoose.populate({
		name: 'discounts.discountProfile',
		opts: { ref: 'DiscountProfile', foreignField: '_id', localField: 'discounts.discountProfile', justOne: true },
	})
	discounts?: Discount[];

Doing in this way by code it works:

schema.virtual('discounts.discountProfile', {
	ref: 'DiscountProfile',
	localField: 'discounts.discountProfileId',
	foreignField: '_id',
	justOne: true,
});

So an option would be to add the localField as an input of the @mgoose.populate decorator but we should make sure current code is not using it or could have undesired consequences.

As reference, mongoose discussion about this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.