Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

edx-modulestore

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edx-modulestore - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

lib/location.js

102

lib/base.js

@@ -7,2 +7,3 @@ 'use strict';

var Location = require('./location');
var factory = require('./factory');

@@ -13,2 +14,12 @@ var models = require('./models');

var _assignAttributes = function (prop, super_) {
return _.assign(
prop.attributes,
super_.attributes,
function (a, b) {
return _.isUndefined(a) ? b : a;
}
);
};
/*

@@ -21,25 +32,3 @@ ** Constructor

/*
** Utilities
*/
var parseModulestoreIdentifier = function (string) {
var r = /^i4x:\/\/([^\/]+)\/([^\/]+)\/([^\/]+)\/(.+)$/;
var fields = r.exec(string);
if (fields.length === 5) {
return {
tag: 'i4x',
org: fields[1],
course: fields[2],
category: fields[3],
name: fields[4],
revision: null
};
}
};
/*
** Static methods

@@ -70,2 +59,5 @@ */

}
else if (name === 'attributes') {
prototype[name] = _assignAttributes(prop, _super);
}
else {

@@ -76,2 +68,3 @@ prototype[name] = prop[name];

var Class = function () {

@@ -96,8 +89,37 @@ // Define properties, based on `this.attributes`.

Base.getFromLocation = function (location, options) {
var deferred = Q.defer();
var loc = Location.parse(location);
if (loc) {
models.Module.findOne({
'_id': loc.toJSON()
}, function (err, model) {
if (err) {
deferred.reject(err);
}
else if (!model) {
deferred.resolve();
}
else {
model = model.upcast();
var C = factory.getClass(loc.category);
if (C && C.load) {
deferred.resolve(C.load(model, null, options));
}
else {
deferred.resolve();
}
}
});
}
return deferred.promise;
};
Base.prototype = {
parent: null,
attributes: {},
/*

@@ -117,2 +139,32 @@ ** Private methods

/*
** Public attributes
*/
attributes: {
id: {
get: function () {
return this._get('_id.name');
}
},
location: {
get: function () {
return Location
.fromID(this._get('_id'))
.toString();
}
},
name: {
get: function () {
return this._get('metadata.display_name');
},
set: function (value) {
this._set('metadata.display_name', value);
}
}
},
/*
** Public methods

@@ -144,3 +196,3 @@ */

.map(function (c) {
return parseModulestoreIdentifier(c);
return Location.parse(c).toJSON();
});

@@ -147,0 +199,0 @@

'use strict';
var Q = require('kew');
var Base = require('./base');

@@ -23,11 +25,2 @@ var utils = require('./utils');

attributes: {
name: {
get: function () {
return this._get('metadata.display_name');
},
set: function (value) {
this._set('metadata.display_name', value);
}
},
startDate: {

@@ -50,5 +43,25 @@ get: function () {

Chapter.get = function (id, options) {
var deferred = Q.defer();
models.Chapter.findOne({
'_id.name': id
}, function (err, model) {
if (err) {
deferred.reject(err);
}
else if (!model) {
deferred.resolve();
}
else {
deferred.resolve(Chapter.load(model, null, options));
}
});
return deferred.promise;
};
// ## //
module.exports = Chapter;

@@ -163,12 +163,2 @@ 'use strict';

// Course name
name: {
get: function () {
return this._get('metadata.display_name');
},
set: function (value) {
this._set('metadata.display_name', value);
}
},
// Course number

@@ -175,0 +165,0 @@ number: {

'use strict';
// ## //
var _map = {
'course': './course',
'about': './about',
'chapter': './chapter',
'sequential': './sequential'
};
var getClass = function (type) {
return {
'course': function () { return require('./course'); },
'about': function () { return require('./about'); },
'chapter': function () { return require('./chapter'); },
'sequential': function () { return require('./sequential'); }
}[type]();
if (type in _map) {
return require(_map[type]);
}
return require('./module');
};

@@ -11,0 +19,0 @@

@@ -69,9 +69,14 @@ 'use strict';

ModuleSchema.methods.upcast = function () {
var Class = this.constructor.discriminators[this._id.category];
if (this._id.category in this.constructor.discriminators) {
var Class = this.constructor.discriminators[this._id.category];
// Taken from Model.hydrate
var doc = new Class(this);
doc.$__reset();
doc.isNew = false;
return doc;
// Taken from Model.hydrate
var doc = new Class(this);
doc.$__reset();
doc.isNew = false;
return doc;
}
// Cannot upcast, returning actual model
return this;
};

@@ -78,0 +83,0 @@

@@ -11,3 +11,6 @@ 'use strict';

var models = require('./models');
var Base = require('./base');
var Course = require('./course');
var Chapter = require('./chapter');
var Sequential = require('./sequential');

@@ -55,3 +58,3 @@ // ## //

this.detachConnection();
deferred.reject(new Error(err));
deferred.reject(err);
}, this));

@@ -82,3 +85,2 @@

Modulestore.prototype.getCourse = function (id, options) {

@@ -88,4 +90,16 @@ return Course.get(id, _.merge(this.options, options));

Modulestore.prototype.getChapter = function (id, options) {
return Chapter.get(id, _.merge(this.options, options));
};
Modulestore.prototype.getSequential = function (id, options) {
return Sequential.get(id, _.merge(this.options, options));
};
Modulestore.prototype.getLocation = function (location, options) {
return Base.getFromLocation(location, _.merge(this.options, options));
};
// ## //
module.exports = Modulestore;
'use strict';
var Q = require('kew');
var Base = require('./base');

@@ -22,11 +24,2 @@ var models = require('./models');

attributes: {
name: {
get: function () {
return this._get('metadata.display_name');
},
set: function (value) {
this._set('metadata.display_name', value);
}
},
graded: {

@@ -75,5 +68,24 @@ get: function () {

Sequential.get = function (id, options) {
var deferred = Q.defer();
models.Sequential.findOne({
'_id.name': id
}, function (err, model) {
if (err) {
deferred.reject(err);
}
else if (!model) {
deferred.resolve();
}
else {
deferred.resolve(Sequential.load(model, null, options));
}
});
return deferred.promise;
};
// ## //
module.exports = Sequential;
{
"name": "edx-modulestore",
"version": "0.1.2",
"version": "0.1.3",
"description": "Easy browsing of Open edX modulestores",

@@ -5,0 +5,0 @@ "author": "Bertrand Marron",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc