diff --git a/HISTORY.md b/HISTORY.md index 379323f..60708be 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ ## Revision history +#### NEXT + +* Package updated to CoffeeScript 2. Now is required to create an instance + of the class with `new JobCollection`, just calling `JobCollection` does + not work anymore. Same for `new Job`. + #### 1.5.2 * Fixed an issue under some circumstances when `job.cancel()` was run on a job with option `{ dependents: false }`. Thanks @gbhrdt. diff --git a/README.md b/README.md index a786327..31c4893 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ on such jobs. // Server if (Meteor.isServer) { - var myJobs = JobCollection('myJobQueue'); + var myJobs = new JobCollection('myJobQueue'); myJobs.allow({ // Grant full permission to any authenticated user admin: function (userId, method, params) { @@ -94,7 +94,7 @@ Alright, the server is set-up and running, now let's add some client code to cre // Client if (Meteor.isClient) { - var myJobs = JobCollection('myJobQueue'); + var myJobs = new JobCollection('myJobQueue'); Meteor.startup(function () { Meteor.subscribe('allJobs'); @@ -348,8 +348,8 @@ methods, which may be secured using allow/deny rules specific to `JobCollection` documentation for `jc.allow()` and `jc.deny()` for more information. ```javascript -// the "new" is optional -jc = JobCollection('defaultJobCollection'); +// the "new" is required +jc = new JobCollection('defaultJobCollection'); ``` ### jc.setLogStream(writeStream) - *Server only* diff --git a/package.js b/package.js index 30c9975..465ab11 100644 --- a/package.js +++ b/package.js @@ -15,7 +15,8 @@ Package.describe({ Package.onUse(function(api) { api.use('mrt:later@1.6.1', ['server','client']); - api.use('coffeescript@1.12.6_1', ['server','client']); + api.use('coffeescript@2.0.3_3', ['server','client']); + api.use('ecmascript@0.9.0', ['server','client']); api.use('mongo@1.1.18', ['server','client']); api.use('check@1.2.5', ['server','client']); api.addFiles('job/src/job_class.coffee', ['server','client']); @@ -29,7 +30,8 @@ Package.onUse(function(api) { Package.onTest(function (api) { api.use('vsivsi:job-collection@' + currentVersion, ['server','client']); api.use('mrt:later@1.6.1', ['server','client']); - api.use('coffeescript@1.12.6_1', ['server','client']); + api.use('coffeescript@2.0.3_3', ['server','client']); + api.use('ecmascript@0.9.0', ['server','client']); api.use('check@1.2.5', ['server','client']); api.use('tinytest@1.0.12', ['server','client']); api.use('test-helpers@1.0.11', ['server','client']); diff --git a/src/client.coffee b/src/client.coffee index d235397..c4d5592 100644 --- a/src/client.coffee +++ b/src/client.coffee @@ -30,9 +30,6 @@ if Meteor.isClient class JobCollection extends share.JobCollectionBase constructor: (root = 'queue', options = {}) -> - unless @ instanceof JobCollection - return new JobCollection(root, options) - # Call super's constructor super root, options diff --git a/src/server.coffee b/src/server.coffee index cc71675..dc7ac1e 100644 --- a/src/server.coffee +++ b/src/server.coffee @@ -20,9 +20,6 @@ if Meteor.isServer class JobCollection extends share.JobCollectionBase constructor: (root = 'queue', options = {}) -> - unless @ instanceof JobCollection - return new JobCollection(root, options) - # Call super's constructor super root, options @@ -43,7 +40,7 @@ if Meteor.isServer @stopped = true # No client mutators allowed - share.JobCollectionBase.__super__.deny.bind(@) + Meteor.Collection.prototype.deny.bind(@) update: () => true insert: () => true remove: () => true diff --git a/src/shared.coffee b/src/shared.coffee index 8fefdd2..2771a36 100644 --- a/src/shared.coffee +++ b/src/shared.coffee @@ -78,23 +78,22 @@ _validJobDoc = () -> repeatWait: Match.OneOf(Match.Where(_validIntGTEZero), Match.Where(_validLaterJSObj)) created: Date -class JobCollectionBase extends Mongo.Collection - - constructor: (@root = 'queue', options = {}) -> - unless @ instanceof JobCollectionBase - return new JobCollectionBase(@root, options) +_getAllProperties = (obj) -> + names = new Set() + properties = [] + while obj + for name in Object.getOwnPropertyNames(obj) when name not in names + properties.push([name, obj[name]]) + names.add(name) + obj = Object.getPrototypeOf(obj) + properties - unless @ instanceof Mongo.Collection - throw new Meteor.Error 'The global definition of Mongo.Collection has changed since the job-collection package was loaded. Please ensure that any packages that redefine Mongo.Collection are loaded before job-collection.' - - unless Mongo.Collection is Mongo.Collection.prototype.constructor - throw new Meteor.Error 'The global definition of Mongo.Collection has been patched by another package, and the prototype constructor has been left in an inconsistent state. Please see this link for a workaround: https://github.com/vsivsi/meteor-file-sample-app/issues/2#issuecomment-120780592' - - @later = later # later object, for convenience +class JobCollectionBase extends Mongo.Collection + constructor: (root = 'queue', options = {}) -> options.noCollectionSuffix ?= false - collectionName = @root + collectionName = root unless options.noCollectionSuffix collectionName += '.jobs' @@ -103,7 +102,20 @@ class JobCollectionBase extends Mongo.Collection # calling Mongo.Collection constructor delete options.noCollectionSuffix - Job.setDDP(options.connection, @root) + Job.setDDP(options.connection, root) + + # Call super's constructor + super collectionName, options + + unless @ instanceof Mongo.Collection + throw new Meteor.Error 'The global definition of Mongo.Collection has changed since the job-collection package was loaded. Please ensure that any packages that redefine Mongo.Collection are loaded before job-collection.' + + unless Mongo.Collection is Mongo.Collection.prototype.constructor + throw new Meteor.Error 'The global definition of Mongo.Collection has been patched by another package, and the prototype constructor has been left in an inconsistent state. Please see this link for a workaround: https://github.com/vsivsi/meteor-file-sample-app/issues/2#issuecomment-120780592' + + @root = root + + @later = later # later object, for convenience @_createLogEntry = (message = '', runId = null, level = 'info', time = new Date(), data = null) -> l = { time: time, runId: runId, message: message, level: level } @@ -128,9 +140,6 @@ class JobCollectionBase extends Mongo.Collection level = if fatal then 'danger' else 'warning' @_createLogEntry msg, runId, level).bind(@) - # Call super's constructor - super collectionName, options - _validNumGTEZero: _validNumGTEZero _validNumGTZero: _validNumGTZero _validNumGTEOne: _validNumGTEOne @@ -222,7 +231,7 @@ class JobCollectionBase extends Mongo.Collection _generateMethods: () -> methodsOut = {} methodPrefix = '_DDPMethod_' - for methodName, methodFunc of @ when methodName[0...methodPrefix.length] is methodPrefix + for [methodName, methodFunc] in _getAllProperties(@) when methodName[0...methodPrefix.length] is methodPrefix baseMethodName = methodName[methodPrefix.length..] methodsOut["#{@root}_#{baseMethodName}"] = @_methodWrapper(baseMethodName, methodFunc.bind(@)) return methodsOut