Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

namespace conflict when using simpl-schema (npm, 2.x) #348

Closed hyperborea closed 6 years ago

hyperborea commented 8 years ago

I'm using the aldeed:collection2 package and have recently switched to the simpl-schema (2.0) npm module. Sadly as collection2 also implies aldeed:simple-schema (1.x) that causes a namespace conflict resulting in meteor-schema-index to extend the wrong library.

For now I'm duplicating the following code, but is there a better way?

import SimpleSchema from 'simpl-schema';

SimpleSchema.extendOptions({
  index: Match.Optional(Match.OneOf(Number, String, Boolean)),
  unique: Match.Optional(Boolean),
  sparse: Match.Optional(Boolean),
});
hyperborea commented 8 years ago

In fact the namespace issue is already problematic for collection2 itself as it invokes the wrong library. Am I using it wrong?

For now I'll be using the meteor wrapper (aldeed:simple-schema@2.0.0-rc.1) instead, I'm not really sure how to make it work with the npm module.

yanickrochon commented 8 years ago

This package should drop it's dependency to simpl-schema and tell the user to import their own. I am having problem using SimpleSchema as this package imports a version that is not compatible with the npm implementation (e.g. error when using SimpleSchema.oneOf, no support for foo.$.bar, etc.)

Make this package use the correct simpl-schema package, or make users import it from npm directly. In any case, this will make maintenance easier for everyone.

See this related issue.

Gervwyk commented 7 years ago

Any updates on this issue? What is the possibility for a npm collection2 module?

ramijarrar commented 7 years ago

@Gervwyk this was addressed in https://github.com/aldeed/node-simple-schema/issues/8

Collection2 is inherently a isomorphic Meteor package so there isn't any reason for now to move it to NPM, and it couldn't be done easily until MDG standardizes some kind of pattern for putting isomorphic code on NPM.

You should be able to import and use the npm SS instead of the one from the package. I can do an update to Collection2 to switch it to a weak dependency on the SS Meteor package.

aldeed commented 6 years ago

Closing old issues. Please comment if this is still an issue and should be reopened.