Commit b163ec2b authored by Tristan Cavelier's avatar Tristan Cavelier

gidstorage.js docstring added

parent bc8ddc7c
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* JIO GID Storage. Type = 'gid'. * JIO GID Storage. Type = 'gid'.
* Identifies document with their global identifier représentation * Identifies document with their global identifier représentation
* *
* Sub storages must support complex queries. * Sub storages must support complex queries and include_docs options.
* *
* Storage Description: * Storage Description:
* *
...@@ -63,14 +63,23 @@ ...@@ -63,14 +63,23 @@
'Text': 'Text' 'Text': 'Text'
}; };
metadata_actions = { metadata_actions = {
/**
* Returns the metadata value
*/
json: function (value) { json: function (value) {
return value; return value;
}, },
/**
* Returns the metadata if it is a string
*/
string: function (value) { string: function (value) {
if (typeof value === 'string') { if (typeof value === 'string') {
return value; return value;
} }
}, },
/**
* Returns the metadata in a array format
*/
list: function (value) { list: function (value) {
var i, new_value = []; var i, new_value = [];
if (Array.isArray(value)) { if (Array.isArray(value)) {
...@@ -86,9 +95,15 @@ ...@@ -86,9 +95,15 @@
} }
return value; return value;
}, },
/**
* Returns the metadata if it is a string equal to a DCMIType
*/
DCMIType: function (value) { DCMIType: function (value) {
return dcmi_types[value]; return dcmi_types[value];
}, },
/**
* Returns the metadata content type if exist
*/
contentType: function (value) { contentType: function (value) {
var i; var i;
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
...@@ -214,6 +229,14 @@ ...@@ -214,6 +229,14 @@
} }
}; };
/**
* Creates a gid from metadata and constraints.
*
* @param {Object} metadata The metadata to use
* @param {Object} constraints The constraints
* @return {String} The gid or undefined if metadata doesn't respect the
* constraints
*/
function gidFormat(metadata, constraints) { function gidFormat(metadata, constraints) {
var types, i, meta_key, result = {}, tmp; var types, i, meta_key, result = {}, tmp;
types = ['default', metadata.type]; types = ['default', metadata.type];
...@@ -233,6 +256,13 @@ ...@@ -233,6 +256,13 @@
return JSON.stringify(result); return JSON.stringify(result);
} }
/**
* Convert a gid to a complex query.
*
* @param {Object,String} gid The gid
* @param {Object} constraints The constraints
* @return {Object} A complex serialized object
*/
function gidToComplexQuery(gid, contraints) { function gidToComplexQuery(gid, contraints) {
var k, i, result = [], meta, content; var k, i, result = [], meta, content;
if (typeof gid === 'string') { if (typeof gid === 'string') {
...@@ -265,6 +295,13 @@ ...@@ -265,6 +295,13 @@
}; };
} }
/**
* Parse the gid and returns a metadata object containing gid keys and values.
*
* @param {String} gid The gid to convert
* @param {Object} constraints The constraints
* @return {Object} The gid metadata
*/
function gidParse(gid, constraints) { function gidParse(gid, constraints) {
var object; var object;
try { try {
...@@ -278,8 +315,19 @@ ...@@ -278,8 +315,19 @@
return object; return object;
} }
/**
* The gid storage used by JIO.
*
* This storage change the id of a document with its global id. A global id
* is representation of a document metadata used to define it as uniq. The way
* to generate global ids can be define in the storage description. It allows
* us use duplicating storage with different sub storage kind.
*
* @class gidStorage
*/
function gidStorage(spec, my) { function gidStorage(spec, my) {
var that = my.basicStorage(spec, my), priv = {}; var that = my.basicStorage(spec, my), priv = {};
priv.sub_storage = spec.sub_storage; priv.sub_storage = spec.sub_storage;
priv.constraints = spec.constraints || { priv.constraints = spec.constraints || {
"default": { "default": {
...@@ -288,6 +336,8 @@ ...@@ -288,6 +336,8 @@
} }
}; };
// Overrides
that.specToStore = function () { that.specToStore = function () {
return { return {
"sub_storage": priv.sub_storage, "sub_storage": priv.sub_storage,
...@@ -295,6 +345,21 @@ ...@@ -295,6 +345,21 @@
}; };
}; };
// JIO Commands
/**
* Generic command for post or put one.
*
* This command will check if the document already exist with an allDocs
* and a complex query. If exist, then post will fail. Put will update the
* retrieved document thanks to its real id. If no documents are found, post
* and put will create a new document with the sub storage id generator.
*
* @method putOrPost
* @private
* @param {Command} command The JIO command
* @param {String} method The command method
*/
priv.putOrPost = function (command, method) { priv.putOrPost = function (command, method) {
setTimeout(function () { setTimeout(function () {
var gid, complex_query, doc = command.cloneDoc(); var gid, complex_query, doc = command.cloneDoc();
...@@ -346,14 +411,32 @@ ...@@ -346,14 +411,32 @@
}); });
}; };
/**
* See {{#crossLink "gidStorage/putOrPost:method"}}{{/#crossLink}}.
*
* @method post
* @param {Command} command The JIO command
*/
that.post = function (command) { that.post = function (command) {
priv.putOrPost(command, 'post'); priv.putOrPost(command, 'post');
}; };
/**
* See {{#crossLink "gidStorage/putOrPost:method"}}{{/#crossLink}}.
*
* @method put
* @param {Command} command The JIO command
*/
that.put = function (command) { that.put = function (command) {
priv.putOrPost(command, 'put'); priv.putOrPost(command, 'put');
}; };
/**
* Gets a document thank to its gid, a sub allDocs and a complex query.
*
* @method get
* @param {Command} command The JIO command
*/
that.get = function (command) { that.get = function (command) {
setTimeout(function () { setTimeout(function () {
var gid_object, complex_query; var gid_object, complex_query;
...@@ -390,6 +473,12 @@ ...@@ -390,6 +473,12 @@
}); });
}; };
/**
* Remove a document thank to its gid, sub allDocs and a complex query.
*
* @method remove
* @param {Command} command The JIO command.
*/
that.remove = function (command) { that.remove = function (command) {
setTimeout(function () { setTimeout(function () {
var gid_object, complex_query, doc = command.cloneDoc(); var gid_object, complex_query, doc = command.cloneDoc();
...@@ -434,6 +523,12 @@ ...@@ -434,6 +523,12 @@
}); });
}; };
/**
* Retrieve a list of document which respect gid constraints.
*
* @method allDocs
* @param {Command} command The JIO command
*/
that.allDocs = function (command) { that.allDocs = function (command) {
setTimeout(function () { setTimeout(function () {
var options = command.cloneOption(), include_docs; var options = command.cloneOption(), include_docs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment