From 30c0ea5e84652afac0cbe552a571e77cbb9501fe Mon Sep 17 00:00:00 2001 From: mhwheeler Date: Tue, 23 Sep 2014 16:01:57 -0700 Subject: [PATCH] Meteor 0.9.1+ compatibility take 1 --- README.md | 6 +++--- graviton.js | 12 ++++++----- lib/model.js | 4 ++-- lib/relations.js | 2 +- package.js | 6 ++++++ test/legacy-test.js | 2 +- test/relation-test.js | 2 +- versions.json | 46 ++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 64 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a830e2f..d6d6cd9 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,14 @@ $ mrt add graviton # API Docs -## Meteor.Collection.prototype +## Mongo.Collection.prototype The following are added to all your meteor collections: * `all()` is an alias for `find().fetch()` * `build()` returns a new local `Gravition.Model` based on your collection definition. Does not save to db. The instance can be saved using `Model.save()`. * `create()` calls build() to generate a Model instance then inserts it into the db. ## Graviton -* `Graviton.define(collectionName, options)` Use to define your collections. Returns a Meteor.Collection instantiated with a transform function based on the options passed. +* `Graviton.define(collectionName, options)` Use to define your collections. Returns a Mongo.Collection instantiated with a transform function based on the options passed. *Options* * `persist` Passing false will define a local collection. defaults to `true` @@ -119,7 +119,7 @@ car.windows.at(2); // only builds one model Graviton transforms collection objects into Models for you. This allows them to carry useful metadata and functions with the data. The vanilla Graviton.Model allows for basic functionality. Defining an extension of the Graviton.Model allows you to specify details of the collection's relationships or other custom functionality. -* `Graviton.Model.extend({Options}, {ExtensionPrototype});` Use to define your collections. Returns a Meteor.Collection instantiated with a transform function based on the options passed. +* `Graviton.Model.extend({Options}, {ExtensionPrototype});` Use to define your collections. Returns a Mongo.Collection instantiated with a transform function based on the options passed. *Options* * `defaults`: an object containing default key:value pairs for the collection. These key:values will be added to all model instances where there is not already a stored value with the same key. Functions should not be placed here as stored records cannot have functions as values. diff --git a/graviton.js b/graviton.js index 6bedbdf..1612705 100644 --- a/graviton.js +++ b/graviton.js @@ -11,16 +11,18 @@ Meteor.startup(function() { /** * - * Meteor.Collection.prototype + * Mongo.Collection.prototype * */ +CollectionClass = (typeof Mongo !== 'undefined') ? Mongo.Collection : Meteor.Collection; + // all() convenience method == find().fetch() -Meteor.Collection.prototype.all = ManyRelation.prototype.all; +CollectionClass.prototype.all = ManyRelation.prototype.all; // build an instance of this collections model type but do not save it to the db // returns the built model. -Meteor.Collection.prototype.build = function(obj) { +CollectionClass.prototype.build = function(obj) { if (!_.isObject(obj)) obj = {}; var mdl = this._graviton.model(obj); mdl._id = obj._id; @@ -28,7 +30,7 @@ Meteor.Collection.prototype.build = function(obj) { }; // does an insert but builds a model first, returns the model instead of an id -Meteor.Collection.prototype.create = function(obj, callback) { +CollectionClass.prototype.create = function(obj, callback) { var model = this.build(obj); var id; if (callback) { @@ -155,7 +157,7 @@ Graviton.define = function(collectionName, options) { var colName = (options.persist) ? collectionName : null; - var collection = new Meteor.Collection(colName, { + var collection = new CollectionClass(colName, { transform: options.model }); diff --git a/lib/model.js b/lib/model.js index 64b960c..e2e658b 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3,8 +3,8 @@ // model instances have a reference to the collection they came from // relations are also defined with collections and added to models when they are instantiated Model = function(collection, obj) { - if (!(collection instanceof Meteor.Collection)) - throw new Error("Models must be instantiated with a Meteor.Collection"); + if (!(collection instanceof CollectionClass)) + throw new Error("Models must be instantiated with a Mongo.Collection"); if (!_.isObject(obj) || _.isFunction(obj)) obj = new Object; diff --git a/lib/relations.js b/lib/relations.js index 12ce4f7..9b2053b 100644 --- a/lib/relations.js +++ b/lib/relations.js @@ -1,7 +1,7 @@ // return a defined collection based on relation configuration var getCollection = function(config) { var collection; - if (config.collection && (config.collection instanceof Meteor.Collection)) { + if (config.collection && (config.collection instanceof CollectionClass)) { collection = config.collection; } else { var name = config.collectionName || config.collection || config.klass; diff --git a/package.js b/package.js index ba8b2a8..e9bf6f5 100644 --- a/package.js +++ b/package.js @@ -3,6 +3,12 @@ Package.describe({ }); Package.on_use(function (api, where) { + + if (api.versionsFrom) { // 0.9.0+ litmus test + api.versionsFrom("0.9.1"); + api.use('mongo', ['client', 'server']); + } + api.use(['underscore', 'minimongo', 'async'], ['client', 'server']); api.add_files(['lib/relations.js', 'lib/model.js', 'graviton.js'], ['client', 'server']); diff --git a/test/legacy-test.js b/test/legacy-test.js index 51e0265..e8e16e3 100644 --- a/test/legacy-test.js +++ b/test/legacy-test.js @@ -92,7 +92,7 @@ Driver = Graviton.define("drivers", { init(Driver); Plate = Graviton.define("plates", { - persist: false // sends null as mongo collection name to Meteor.Collection + persist: false // sends null as mongo collection name to Mongo.Collection }); Window = Graviton.define("windows", { diff --git a/test/relation-test.js b/test/relation-test.js index 7838730..fd3e927 100644 --- a/test/relation-test.js +++ b/test/relation-test.js @@ -95,7 +95,7 @@ var Driver = Graviton.define("rt-drivers", { init(Driver); var Plate = Graviton.define("rt-plates", { - persist: false // sends null as mongo collection name to Meteor.Collection + persist: false // sends null as mongo collection name to Mongo.Collection }); var Window = Graviton.define("rt-windows", { diff --git a/versions.json b/versions.json index 02340b5..63325ca 100644 --- a/versions.json +++ b/versions.json @@ -1,11 +1,39 @@ { "dependencies": [ + [ + "application-configuration", + "1.0.2" + ], [ "async", "0.0.0" ], + [ + "base64", + "1.0.0" + ], + [ + "binary-heap", + "1.0.0" + ], + [ + "callback-hook", + "1.0.0" + ], + [ + "check", + "1.0.0" + ], + [ + "ddp", + "1.0.8" + ], [ "ejson", + "1.0.2" + ], + [ + "follower-livedata", "1.0.1" ], [ @@ -21,12 +49,20 @@ "1.0.0" ], [ - "meteor", + "logging", "1.0.3" ], + [ + "meteor", + "1.1.0" + ], [ "minimongo", - "1.0.2" + "1.0.3" + ], + [ + "mongo", + "1.0.5" ], [ "ordered-dict", @@ -36,6 +72,10 @@ "random", "1.0.0" ], + [ + "retry", + "1.0.0" + ], [ "tracker", "1.0.2" @@ -46,6 +86,6 @@ ] ], "pluginDependencies": [], - "toolVersion": "meteor-tool@1.0.28", + "toolVersion": "meteor-tool@1.0.31", "format": "1.0" } \ No newline at end of file