More consistent variable naming
This commit is contained in:
parent
dea739ff07
commit
faa4b9700a
|
@ -27,7 +27,7 @@ Command.prototype.execute = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// Check parameters
|
// Check parameters
|
||||||
if(this.params.length < 2) {
|
if(this.params.length < 2) {
|
||||||
return "Missing pathname and/or bagname";
|
return "Missing pathname and/or bag name";
|
||||||
}
|
}
|
||||||
var tiddlersPath = this.params[0],
|
var tiddlersPath = this.params[0],
|
||||||
bagName = this.params[1];
|
bagName = this.params[1];
|
||||||
|
|
|
@ -38,7 +38,7 @@ exports.handler = function(request,response,state) {
|
||||||
store: $tw.mws.store,
|
store: $tw.mws.store,
|
||||||
state: state,
|
state: state,
|
||||||
response: response,
|
response: response,
|
||||||
bagname: bag_name,
|
bag_name: bag_name,
|
||||||
callback: function(err,results) {
|
callback: function(err,results) {
|
||||||
// If application/json is requested then this is an API request, and gets the response in JSON
|
// If application/json is requested then this is an API request, and gets the response in JSON
|
||||||
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
if(request.headers.accept && request.headers.accept.indexOf("application/json") !== -1) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ Process an incoming new multipart/form-data stream. Options include:
|
||||||
store - tiddler store
|
store - tiddler store
|
||||||
state - provided by server.js
|
state - provided by server.js
|
||||||
response - provided by server.js
|
response - provided by server.js
|
||||||
bagname - name of bag to write to
|
bag_name - name of bag to write to
|
||||||
callback - invoked as callback(err,results). Results is an array of titles of imported tiddlers
|
callback - invoked as callback(err,results). Results is an array of titles of imported tiddlers
|
||||||
*/
|
*/
|
||||||
exports.processIncomingStream = function(options) {
|
exports.processIncomingStream = function(options) {
|
||||||
|
@ -85,7 +85,7 @@ exports.processIncomingStream = function(options) {
|
||||||
tiddlerFields[part.name.slice(tiddlerFieldPrefix.length)] = part.value.trim();
|
tiddlerFields[part.name.slice(tiddlerFieldPrefix.length)] = part.value.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.store.saveBagTiddlerWithAttachment(tiddlerFields,options.bagname,{
|
options.store.saveBagTiddlerWithAttachment(tiddlerFields,options.bag_name,{
|
||||||
filepath: partFile.inboxFilename,
|
filepath: partFile.inboxFilename,
|
||||||
type: type,
|
type: type,
|
||||||
hash: partFile.hash
|
hash: partFile.hash
|
||||||
|
|
|
@ -42,9 +42,9 @@ function AttachmentStore(options) {
|
||||||
/*
|
/*
|
||||||
Check if an attachment name is valid
|
Check if an attachment name is valid
|
||||||
*/
|
*/
|
||||||
AttachmentStore.prototype.isValidAttachmentName = function(attachmentname) {
|
AttachmentStore.prototype.isValidAttachmentName = function(attachment_name) {
|
||||||
const re = new RegExp('^[a-f0-9]{64}$');
|
const re = new RegExp('^[a-f0-9]{64}$');
|
||||||
return re.test(attachmentname);
|
return re.test(attachment_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -107,13 +107,13 @@ Get an attachment ready to stream. Returns null if there is an error or:
|
||||||
stream: filestream of file
|
stream: filestream of file
|
||||||
type: type of file
|
type: type of file
|
||||||
*/
|
*/
|
||||||
AttachmentStore.prototype.getAttachmentStream = function(attachmentname) {
|
AttachmentStore.prototype.getAttachmentStream = function(attachment_name) {
|
||||||
const path = require("path"),
|
const path = require("path"),
|
||||||
fs = require("fs");
|
fs = require("fs");
|
||||||
// Check the attachment name
|
// Check the attachment name
|
||||||
if(this.isValidAttachmentName(attachmentname)) {
|
if(this.isValidAttachmentName(attachment_name)) {
|
||||||
// Construct the path to the attachment directory
|
// Construct the path to the attachment directory
|
||||||
const attachmentPath = path.resolve(this.storePath,"files",attachmentname);
|
const attachmentPath = path.resolve(this.storePath,"files",attachment_name);
|
||||||
// Read the meta.json file
|
// Read the meta.json file
|
||||||
const metaJsonPath = path.resolve(attachmentPath,"meta.json");
|
const metaJsonPath = path.resolve(attachmentPath,"meta.json");
|
||||||
if(fs.existsSync(metaJsonPath) && fs.statSync(metaJsonPath).isFile()) {
|
if(fs.existsSync(metaJsonPath) && fs.statSync(metaJsonPath).isFile()) {
|
||||||
|
|
|
@ -94,14 +94,14 @@ SqlTiddlerDatabase.prototype.listBags = function() {
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerDatabase.prototype.createBag = function(bagname,description,accesscontrol) {
|
SqlTiddlerDatabase.prototype.createBag = function(bag_name,description,accesscontrol) {
|
||||||
accesscontrol = accesscontrol || "";
|
accesscontrol = accesscontrol || "";
|
||||||
// Run the queries
|
// Run the queries
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
INSERT OR IGNORE INTO bags (bag_name, accesscontrol, description)
|
INSERT OR IGNORE INTO bags (bag_name, accesscontrol, description)
|
||||||
VALUES ($bag_name, '', '')
|
VALUES ($bag_name, '', '')
|
||||||
`,{
|
`,{
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
UPDATE bags
|
UPDATE bags
|
||||||
|
@ -109,7 +109,7 @@ SqlTiddlerDatabase.prototype.createBag = function(bagname,description,accesscont
|
||||||
description = $description
|
description = $description
|
||||||
WHERE bag_name = $bag_name
|
WHERE bag_name = $bag_name
|
||||||
`,{
|
`,{
|
||||||
$bag_name: bagname,
|
$bag_name: bag_name,
|
||||||
$accesscontrol: accesscontrol,
|
$accesscontrol: accesscontrol,
|
||||||
$description: description
|
$description: description
|
||||||
});
|
});
|
||||||
|
@ -143,20 +143,20 @@ SqlTiddlerDatabase.prototype.listRecipes = function() {
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerDatabase.prototype.createRecipe = function(recipename,bagnames,description) {
|
SqlTiddlerDatabase.prototype.createRecipe = function(recipe_name,bag_names,description) {
|
||||||
// Run the queries
|
// Run the queries
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
-- Delete existing recipe_bags entries for this recipe
|
-- Delete existing recipe_bags entries for this recipe
|
||||||
DELETE FROM recipe_bags WHERE recipe_id = (SELECT recipe_id FROM recipes WHERE recipe_name = $recipe_name)
|
DELETE FROM recipe_bags WHERE recipe_id = (SELECT recipe_id FROM recipes WHERE recipe_name = $recipe_name)
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
-- Create the entry in the recipes table if required
|
-- Create the entry in the recipes table if required
|
||||||
INSERT OR REPLACE INTO recipes (recipe_name, description)
|
INSERT OR REPLACE INTO recipes (recipe_name, description)
|
||||||
VALUES ($recipe_name, $description)
|
VALUES ($recipe_name, $description)
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename,
|
$recipe_name: recipe_name,
|
||||||
$description: description
|
$description: description
|
||||||
});
|
});
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
|
@ -167,15 +167,15 @@ SqlTiddlerDatabase.prototype.createRecipe = function(recipename,bagnames,descrip
|
||||||
INNER JOIN json_each($bag_names) AS j ON j.value = b.bag_name
|
INNER JOIN json_each($bag_names) AS j ON j.value = b.bag_name
|
||||||
WHERE r.recipe_name = $recipe_name
|
WHERE r.recipe_name = $recipe_name
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename,
|
$recipe_name: recipe_name,
|
||||||
$bag_names: JSON.stringify(bagnames)
|
$bag_names: JSON.stringify(bag_names)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Returns {tiddler_id:}
|
Returns {tiddler_id:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.saveBagTiddler = function(tiddlerFields,bagname,attachment_blob) {
|
SqlTiddlerDatabase.prototype.saveBagTiddler = function(tiddlerFields,bag_name,attachment_blob) {
|
||||||
attachment_blob = attachment_blob || null;
|
attachment_blob = attachment_blob || null;
|
||||||
// Update the tiddlers table
|
// Update the tiddlers table
|
||||||
var info = this.engine.runStatement(`
|
var info = this.engine.runStatement(`
|
||||||
|
@ -189,7 +189,7 @@ SqlTiddlerDatabase.prototype.saveBagTiddler = function(tiddlerFields,bagname,att
|
||||||
`,{
|
`,{
|
||||||
$title: tiddlerFields.title,
|
$title: tiddlerFields.title,
|
||||||
$attachment_blob: attachment_blob,
|
$attachment_blob: attachment_blob,
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
// Update the fields table
|
// Update the fields table
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
|
@ -210,7 +210,7 @@ SqlTiddlerDatabase.prototype.saveBagTiddler = function(tiddlerFields,bagname,att
|
||||||
JOIN json_each($field_values) AS json_each
|
JOIN json_each($field_values) AS json_each
|
||||||
`,{
|
`,{
|
||||||
$title: tiddlerFields.title,
|
$title: tiddlerFields.title,
|
||||||
$bag_name: bagname,
|
$bag_name: bag_name,
|
||||||
$field_values: JSON.stringify(Object.assign({},tiddlerFields,{title: undefined}))
|
$field_values: JSON.stringify(Object.assign({},tiddlerFields,{title: undefined}))
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
@ -221,7 +221,7 @@ SqlTiddlerDatabase.prototype.saveBagTiddler = function(tiddlerFields,bagname,att
|
||||||
/*
|
/*
|
||||||
Returns {tiddler_id:,bag_name:} or null if the recipe is empty
|
Returns {tiddler_id:,bag_name:} or null if the recipe is empty
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.saveRecipeTiddler = function(tiddlerFields,recipename,attachment_blob) {
|
SqlTiddlerDatabase.prototype.saveRecipeTiddler = function(tiddlerFields,recipe_name,attachment_blob) {
|
||||||
// Find the topmost bag in the recipe
|
// Find the topmost bag in the recipe
|
||||||
var row = this.engine.runStatementGet(`
|
var row = this.engine.runStatementGet(`
|
||||||
SELECT b.bag_name
|
SELECT b.bag_name
|
||||||
|
@ -239,7 +239,7 @@ SqlTiddlerDatabase.prototype.saveRecipeTiddler = function(tiddlerFields,recipena
|
||||||
) AS selected_bag
|
) AS selected_bag
|
||||||
ON b.bag_id = selected_bag.bag_id
|
ON b.bag_id = selected_bag.bag_id
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
if(!row) {
|
if(!row) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -252,7 +252,7 @@ SqlTiddlerDatabase.prototype.saveRecipeTiddler = function(tiddlerFields,recipena
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerDatabase.prototype.deleteTiddler = function(title,bagname) {
|
SqlTiddlerDatabase.prototype.deleteTiddler = function(title,bag_name) {
|
||||||
// Delete the fields of this tiddler
|
// Delete the fields of this tiddler
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
DELETE FROM fields
|
DELETE FROM fields
|
||||||
|
@ -264,7 +264,7 @@ SqlTiddlerDatabase.prototype.deleteTiddler = function(title,bagname) {
|
||||||
)
|
)
|
||||||
`,{
|
`,{
|
||||||
$title: title,
|
$title: title,
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
// Mark the tiddler itself as deleted
|
// Mark the tiddler itself as deleted
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
|
@ -277,14 +277,14 @@ SqlTiddlerDatabase.prototype.deleteTiddler = function(title,bagname) {
|
||||||
)
|
)
|
||||||
`,{
|
`,{
|
||||||
$title: title,
|
$title: title,
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
returns {tiddler_id:,tiddler:,attachment_blob:}
|
returns {tiddler_id:,tiddler:,attachment_blob:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.getBagTiddler = function(title,bagname) {
|
SqlTiddlerDatabase.prototype.getBagTiddler = function(title,bag_name) {
|
||||||
const rowTiddler = this.engine.runStatementGet(`
|
const rowTiddler = this.engine.runStatementGet(`
|
||||||
SELECT t.tiddler_id, t.attachment_blob
|
SELECT t.tiddler_id, t.attachment_blob
|
||||||
FROM bags AS b
|
FROM bags AS b
|
||||||
|
@ -292,7 +292,7 @@ SqlTiddlerDatabase.prototype.getBagTiddler = function(title,bagname) {
|
||||||
WHERE t.title = $title AND b.bag_name = $bag_name AND t.is_deleted = FALSE
|
WHERE t.title = $title AND b.bag_name = $bag_name AND t.is_deleted = FALSE
|
||||||
`,{
|
`,{
|
||||||
$title: title,
|
$title: title,
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
if(!rowTiddler) {
|
if(!rowTiddler) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -321,7 +321,7 @@ SqlTiddlerDatabase.prototype.getBagTiddler = function(title,bagname) {
|
||||||
/*
|
/*
|
||||||
Returns {bag_name:, tiddler: {fields}, tiddler_id:, attachment_blob:}
|
Returns {bag_name:, tiddler: {fields}, tiddler_id:, attachment_blob:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.getRecipeTiddler = function(title,recipename) {
|
SqlTiddlerDatabase.prototype.getRecipeTiddler = function(title,recipe_name) {
|
||||||
const rowTiddlerId = this.engine.runStatementGet(`
|
const rowTiddlerId = this.engine.runStatementGet(`
|
||||||
SELECT t.tiddler_id, t.attachment_blob, b.bag_name
|
SELECT t.tiddler_id, t.attachment_blob, b.bag_name
|
||||||
FROM bags AS b
|
FROM bags AS b
|
||||||
|
@ -335,7 +335,7 @@ SqlTiddlerDatabase.prototype.getRecipeTiddler = function(title,recipename) {
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`,{
|
`,{
|
||||||
$title: title,
|
$title: title,
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
if(!rowTiddlerId) {
|
if(!rowTiddlerId) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -362,7 +362,7 @@ SqlTiddlerDatabase.prototype.getRecipeTiddler = function(title,recipename) {
|
||||||
/*
|
/*
|
||||||
Get the titles of the tiddlers in a bag. Returns an empty array for bags that do not exist
|
Get the titles of the tiddlers in a bag. Returns an empty array for bags that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.getBagTiddlers = function(bagname) {
|
SqlTiddlerDatabase.prototype.getBagTiddlers = function(bag_name) {
|
||||||
const rows = this.engine.runStatementGetAll(`
|
const rows = this.engine.runStatementGetAll(`
|
||||||
SELECT DISTINCT title
|
SELECT DISTINCT title
|
||||||
FROM tiddlers
|
FROM tiddlers
|
||||||
|
@ -374,7 +374,7 @@ SqlTiddlerDatabase.prototype.getBagTiddlers = function(bagname) {
|
||||||
AND tiddlers.is_deleted = FALSE
|
AND tiddlers.is_deleted = FALSE
|
||||||
ORDER BY title ASC
|
ORDER BY title ASC
|
||||||
`,{
|
`,{
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
return rows.map(value => value.title);
|
return rows.map(value => value.title);
|
||||||
};
|
};
|
||||||
|
@ -382,11 +382,11 @@ SqlTiddlerDatabase.prototype.getBagTiddlers = function(bagname) {
|
||||||
/*
|
/*
|
||||||
Get the titles of the tiddlers in a recipe as {title:,bag_name:}. Returns null for recipes that do not exist
|
Get the titles of the tiddlers in a recipe as {title:,bag_name:}. Returns null for recipes that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.getRecipeTiddlers = function(recipename) {
|
SqlTiddlerDatabase.prototype.getRecipeTiddlers = function(recipe_name) {
|
||||||
const rowsCheckRecipe = this.engine.runStatementGetAll(`
|
const rowsCheckRecipe = this.engine.runStatementGetAll(`
|
||||||
SELECT * FROM recipes WHERE recipes.recipe_name = $recipe_name
|
SELECT * FROM recipes WHERE recipes.recipe_name = $recipe_name
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
if(rowsCheckRecipe.length === 0) {
|
if(rowsCheckRecipe.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -405,12 +405,12 @@ SqlTiddlerDatabase.prototype.getRecipeTiddlers = function(recipename) {
|
||||||
ORDER BY t.title
|
ORDER BY t.title
|
||||||
)
|
)
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
return rows;
|
return rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerDatabase.prototype.deleteAllTiddlersInBag = function(bagname) {
|
SqlTiddlerDatabase.prototype.deleteAllTiddlersInBag = function(bag_name) {
|
||||||
// Delete the fields
|
// Delete the fields
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
DELETE FROM fields
|
DELETE FROM fields
|
||||||
|
@ -421,7 +421,7 @@ SqlTiddlerDatabase.prototype.deleteAllTiddlersInBag = function(bagname) {
|
||||||
AND is_deleted = FALSE
|
AND is_deleted = FALSE
|
||||||
)
|
)
|
||||||
`,{
|
`,{
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
// Mark the tiddlers as deleted
|
// Mark the tiddlers as deleted
|
||||||
this.engine.runStatement(`
|
this.engine.runStatement(`
|
||||||
|
@ -430,14 +430,14 @@ SqlTiddlerDatabase.prototype.deleteAllTiddlersInBag = function(bagname) {
|
||||||
WHERE bag_id = (SELECT bag_id FROM bags WHERE bag_name = $bag_name)
|
WHERE bag_id = (SELECT bag_id FROM bags WHERE bag_name = $bag_name)
|
||||||
AND is_deleted = FALSE
|
AND is_deleted = FALSE
|
||||||
`,{
|
`,{
|
||||||
$bag_name: bagname
|
$bag_name: bag_name
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist
|
Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerDatabase.prototype.getRecipeBags = function(recipename) {
|
SqlTiddlerDatabase.prototype.getRecipeBags = function(recipe_name) {
|
||||||
const rows = this.engine.runStatementGetAll(`
|
const rows = this.engine.runStatementGetAll(`
|
||||||
SELECT bags.bag_name
|
SELECT bags.bag_name
|
||||||
FROM bags
|
FROM bags
|
||||||
|
@ -450,7 +450,7 @@ SqlTiddlerDatabase.prototype.getRecipeBags = function(recipename) {
|
||||||
) AS bag_priority ON bags.bag_id = bag_priority.bag_id
|
) AS bag_priority ON bags.bag_id = bag_priority.bag_id
|
||||||
ORDER BY position
|
ORDER BY position
|
||||||
`,{
|
`,{
|
||||||
$recipe_name: recipename
|
$recipe_name: recipe_name
|
||||||
});
|
});
|
||||||
return rows.map(value => value.bag_name);
|
return rows.map(value => value.bag_name);
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,7 +112,7 @@ SqlTiddlerStore.prototype.updateAdminWiki = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Given tiddler fields, tiddler_id and a bagname, return the tiddler fields after the following process:
|
Given tiddler fields, tiddler_id and a bag_name, return the tiddler fields after the following process:
|
||||||
- Apply the tiddler_id as the revision field
|
- Apply the tiddler_id as the revision field
|
||||||
- Apply the bag_name as the bag field
|
- Apply the bag_name as the bag field
|
||||||
*/
|
*/
|
||||||
|
@ -174,17 +174,17 @@ SqlTiddlerStore.prototype.listBags = function() {
|
||||||
return this.sqlTiddlerDatabase.listBags();
|
return this.sqlTiddlerDatabase.listBags();
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerStore.prototype.createBag = function(bagname,description) {
|
SqlTiddlerStore.prototype.createBag = function(bag_name,description) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.sqlTiddlerDatabase.transaction(function() {
|
return this.sqlTiddlerDatabase.transaction(function() {
|
||||||
const validationBagName = self.validateItemName(bagname);
|
const validationBagName = self.validateItemName(bag_name);
|
||||||
if(validationBagName) {
|
if(validationBagName) {
|
||||||
return {message: validationBagName};
|
return {message: validationBagName};
|
||||||
}
|
}
|
||||||
self.sqlTiddlerDatabase.createBag(bagname,description);
|
self.sqlTiddlerDatabase.createBag(bag_name,description);
|
||||||
self.saveEntityStateTiddler({
|
self.saveEntityStateTiddler({
|
||||||
title: "bags/" + bagname,
|
title: "bags/" + bag_name,
|
||||||
"bag-name": bagname,
|
"bag-name": bag_name,
|
||||||
text: description
|
text: description
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
@ -198,28 +198,28 @@ SqlTiddlerStore.prototype.listRecipes = function() {
|
||||||
/*
|
/*
|
||||||
Returns null on success, or {message:} on error
|
Returns null on success, or {message:} on error
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.createRecipe = function(recipename,bagnames,description) {
|
SqlTiddlerStore.prototype.createRecipe = function(recipe_name,bag_names,description) {
|
||||||
bagnames = bagnames || [];
|
bag_names = bag_names || [];
|
||||||
description = description || "";
|
description = description || "";
|
||||||
const validationRecipeName = this.validateItemName(recipename);
|
const validationRecipeName = this.validateItemName(recipe_name);
|
||||||
if(validationRecipeName) {
|
if(validationRecipeName) {
|
||||||
return {message: validationRecipeName};
|
return {message: validationRecipeName};
|
||||||
}
|
}
|
||||||
const validationBagNames = this.validateItemNames(bagnames);
|
const validationBagNames = this.validateItemNames(bag_names);
|
||||||
if(validationBagNames) {
|
if(validationBagNames) {
|
||||||
return {message: validationBagNames};
|
return {message: validationBagNames};
|
||||||
}
|
}
|
||||||
if(bagnames.length === 0) {
|
if(bag_names.length === 0) {
|
||||||
return {message: "Recipes must contain at least one bag"};
|
return {message: "Recipes must contain at least one bag"};
|
||||||
}
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.sqlTiddlerDatabase.transaction(function() {
|
return this.sqlTiddlerDatabase.transaction(function() {
|
||||||
self.sqlTiddlerDatabase.createRecipe(recipename,bagnames,description);
|
self.sqlTiddlerDatabase.createRecipe(recipe_name,bag_names,description);
|
||||||
self.saveEntityStateTiddler({
|
self.saveEntityStateTiddler({
|
||||||
title: "recipes/" + recipename,
|
title: "recipes/" + recipe_name,
|
||||||
"recipe-name": recipename,
|
"recipe-name": recipe_name,
|
||||||
text: description,
|
text: description,
|
||||||
list: $tw.utils.stringifyList(bagnames.map(bag_name => {
|
list: $tw.utils.stringifyList(bag_names.map(bag_name => {
|
||||||
return self.entityStateTiddlerPrefix + "bags/" + bag_name;
|
return self.entityStateTiddlerPrefix + "bags/" + bag_name;
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
@ -230,9 +230,9 @@ SqlTiddlerStore.prototype.createRecipe = function(recipename,bagnames,descriptio
|
||||||
/*
|
/*
|
||||||
Returns {tiddler_id:}
|
Returns {tiddler_id:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.saveBagTiddler = function(incomingTiddlerFields,bagname) {
|
SqlTiddlerStore.prototype.saveBagTiddler = function(incomingTiddlerFields,bag_name) {
|
||||||
const {tiddlerFields, attachment_blob} = this.processIncomingTiddler(incomingTiddlerFields);
|
const {tiddlerFields, attachment_blob} = this.processIncomingTiddler(incomingTiddlerFields);
|
||||||
return this.sqlTiddlerDatabase.saveBagTiddler(tiddlerFields,bagname,attachment_blob);
|
return this.sqlTiddlerDatabase.saveBagTiddler(tiddlerFields,bag_name,attachment_blob);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -245,10 +245,10 @@ type - content type of file as uploaded
|
||||||
|
|
||||||
Returns {tiddler_id:}
|
Returns {tiddler_id:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.saveBagTiddlerWithAttachment = function(incomingTiddlerFields,bagname,options) {
|
SqlTiddlerStore.prototype.saveBagTiddlerWithAttachment = function(incomingTiddlerFields,bag_name,options) {
|
||||||
const attachment_blob = this.attachmentStore.adoptAttachment(options.filepath,options.type,options.hash);
|
const attachment_blob = this.attachmentStore.adoptAttachment(options.filepath,options.type,options.hash);
|
||||||
if(attachment_blob) {
|
if(attachment_blob) {
|
||||||
return this.sqlTiddlerDatabase.saveBagTiddler(incomingTiddlerFields,bagname,attachment_blob);
|
return this.sqlTiddlerDatabase.saveBagTiddler(incomingTiddlerFields,bag_name,attachment_blob);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -257,26 +257,26 @@ SqlTiddlerStore.prototype.saveBagTiddlerWithAttachment = function(incomingTiddle
|
||||||
/*
|
/*
|
||||||
Returns {tiddler_id:,bag_name:}
|
Returns {tiddler_id:,bag_name:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.saveRecipeTiddler = function(incomingTiddlerFields,recipename) {
|
SqlTiddlerStore.prototype.saveRecipeTiddler = function(incomingTiddlerFields,recipe_name) {
|
||||||
const {tiddlerFields, attachment_blob} = this.processIncomingTiddler(incomingTiddlerFields);
|
const {tiddlerFields, attachment_blob} = this.processIncomingTiddler(incomingTiddlerFields);
|
||||||
return this.sqlTiddlerDatabase.saveRecipeTiddler(tiddlerFields,recipename,attachment_blob);
|
return this.sqlTiddlerDatabase.saveRecipeTiddler(tiddlerFields,recipe_name,attachment_blob);
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerStore.prototype.deleteTiddler = function(title,bagname) {
|
SqlTiddlerStore.prototype.deleteTiddler = function(title,bag_name) {
|
||||||
this.sqlTiddlerDatabase.deleteTiddler(title,bagname);
|
this.sqlTiddlerDatabase.deleteTiddler(title,bag_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
returns {tiddler_id:,tiddler:}
|
returns {tiddler_id:,tiddler:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getBagTiddler = function(title,bagname) {
|
SqlTiddlerStore.prototype.getBagTiddler = function(title,bag_name) {
|
||||||
var tiddlerInfo = this.sqlTiddlerDatabase.getBagTiddler(title,bagname);
|
var tiddlerInfo = this.sqlTiddlerDatabase.getBagTiddler(title,bag_name);
|
||||||
if(tiddlerInfo) {
|
if(tiddlerInfo) {
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{},
|
{},
|
||||||
tiddlerInfo,
|
tiddlerInfo,
|
||||||
{
|
{
|
||||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bagname,tiddlerInfo.attachment_blob)
|
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bag_name,tiddlerInfo.attachment_blob)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -288,8 +288,8 @@ Get an attachment ready to stream. Returns null if there is an error or:
|
||||||
stream: stream of file
|
stream: stream of file
|
||||||
type: type of file
|
type: type of file
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bagname) {
|
SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bag_name) {
|
||||||
const tiddlerInfo = this.sqlTiddlerDatabase.getBagTiddler(title,bagname);
|
const tiddlerInfo = this.sqlTiddlerDatabase.getBagTiddler(title,bag_name);
|
||||||
if(tiddlerInfo) {
|
if(tiddlerInfo) {
|
||||||
if(tiddlerInfo.attachment_blob) {
|
if(tiddlerInfo.attachment_blob) {
|
||||||
return this.attachmentStore.getAttachmentStream(tiddlerInfo.attachment_blob);
|
return this.attachmentStore.getAttachmentStream(tiddlerInfo.attachment_blob);
|
||||||
|
@ -316,8 +316,8 @@ SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bagname) {
|
||||||
/*
|
/*
|
||||||
Returns {bag_name:, tiddler: {fields}, tiddler_id:}
|
Returns {bag_name:, tiddler: {fields}, tiddler_id:}
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getRecipeTiddler = function(title,recipename) {
|
SqlTiddlerStore.prototype.getRecipeTiddler = function(title,recipe_name) {
|
||||||
var tiddlerInfo = this.sqlTiddlerDatabase.getRecipeTiddler(title,recipename);
|
var tiddlerInfo = this.sqlTiddlerDatabase.getRecipeTiddler(title,recipe_name);
|
||||||
if(tiddlerInfo) {
|
if(tiddlerInfo) {
|
||||||
return Object.assign(
|
return Object.assign(
|
||||||
{},
|
{},
|
||||||
|
@ -333,29 +333,29 @@ SqlTiddlerStore.prototype.getRecipeTiddler = function(title,recipename) {
|
||||||
/*
|
/*
|
||||||
Get the titles of the tiddlers in a bag. Returns an empty array for bags that do not exist
|
Get the titles of the tiddlers in a bag. Returns an empty array for bags that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getBagTiddlers = function(bagname) {
|
SqlTiddlerStore.prototype.getBagTiddlers = function(bag_name) {
|
||||||
return this.sqlTiddlerDatabase.getBagTiddlers(bagname);
|
return this.sqlTiddlerDatabase.getBagTiddlers(bag_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the titles of the tiddlers in a recipe as {title:,bag_name:}. Returns null for recipes that do not exist
|
Get the titles of the tiddlers in a recipe as {title:,bag_name:}. Returns null for recipes that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getRecipeTiddlers = function(recipename) {
|
SqlTiddlerStore.prototype.getRecipeTiddlers = function(recipe_name) {
|
||||||
return this.sqlTiddlerDatabase.getRecipeTiddlers(recipename);
|
return this.sqlTiddlerDatabase.getRecipeTiddlers(recipe_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
SqlTiddlerStore.prototype.deleteAllTiddlersInBag = function(bagname) {
|
SqlTiddlerStore.prototype.deleteAllTiddlersInBag = function(bag_name) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.sqlTiddlerDatabase.transaction(function() {
|
return this.sqlTiddlerDatabase.transaction(function() {
|
||||||
return self.sqlTiddlerDatabase.deleteAllTiddlersInBag(bagname);
|
return self.sqlTiddlerDatabase.deleteAllTiddlersInBag(bag_name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist
|
Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist
|
||||||
*/
|
*/
|
||||||
SqlTiddlerStore.prototype.getRecipeBags = function(recipename) {
|
SqlTiddlerStore.prototype.getRecipeBags = function(recipe_name) {
|
||||||
return this.sqlTiddlerDatabase.getRecipeBags(recipename);
|
return this.sqlTiddlerDatabase.getRecipeBags(recipe_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.SqlTiddlerStore = SqlTiddlerStore;
|
exports.SqlTiddlerStore = SqlTiddlerStore;
|
||||||
|
|
Loading…
Reference in New Issue