diff --git a/documentation.yml b/documentation.yml index df2cbf72..f5ff75a1 100644 --- a/documentation.yml +++ b/documentation.yml @@ -1,6 +1,8 @@ toc: - name: Master Server API - clusterioMaster + - name: Type declarations + - itemStack - name: Internal modules description: | Here are some helper functions for navigation. diff --git a/lib/typedef.js b/lib/typedef.js new file mode 100644 index 00000000..1e888ab7 --- /dev/null +++ b/lib/typedef.js @@ -0,0 +1,11 @@ +/** +An item with a count specified + +@typedef {object} itemStack +@property {string} name The name of the item in the stack +@property {(number|string)} count The amount of items in the stack + +@example +itemStack = {name:"iron-plate", count:"12"} +itemStack = {name:"copper-plate", count:972} +*/ \ No newline at end of file diff --git a/master.js b/master.js index 563b036a..51bf9a50 100644 --- a/master.js +++ b/master.js @@ -231,7 +231,18 @@ var recievedItemStatistics = new averagedTimeSeries({ maxEntries: config.itemStats.maxEntries, entriesPerSecond: config.itemStats.entriesPerSecond, }, console.log);*/ -// endpoint to send items to +// +/** +POST endpoint for storing items in master's inventory. + +@memberof clusterioMaster +@instance +@alias api/place +@param {itemStack} itemStack the number and type of items to store (see typedef) +@param {string} [itemStack.instanceID="unknown"] the unique/instanceID which is a numerical value for an instance +@param {string} [itemStack.instanceName="unknown"] the name of an instance for identification in statistics, as provided when launching it. ex node client.js start [name] +@returns {string} status either "success" or "failure" +*/ app.post("/api/place", function(req, res) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); @@ -283,7 +294,17 @@ app.post("/api/place", function(req, res) { res.send("failure"); } }); -// endpoint to remove items from DB when client orders items +/** +POST endpoint to remove items from DB when client orders items. + +@memberof clusterioMaster +@instance +@alias api/remove +@param {itemStack} itemStack the name of and the number of items to remove (see typedef) +@param {string} [itemStack.instanceID="unknown"] the unique/instanceID which is a numerical value for an instance +@param {string} [itemStack.instanceName="unknown"] the name of an instance for identification in statistics, as provided when launching it. ex node client.js start [name] +@returns {itemStack} the number of items actually removed, may be lower than what was asked for due to shortages. +*/ _doleDivisionFactor = {}; //If the server regularly can't fulfill requests, this number grows until it can. Then it slowly shrinks back down. app.post("/api/remove", function(req, res) { const doleDivisionRetardation = 10; //lower rates will equal more dramatic swings @@ -570,7 +591,14 @@ app.post("/api/getTimelineStats", function(req,res) { }); } }); +/** +GET endpoint. Returns factorio's base locale as a JSON object. +@memberof clusterioMaster +@instance +@alias api/getFactorioLocale +@returns {object{}} 2 deep nested object with base game factorio locale as key:value pairs +*/ app.get("/api/getFactorioLocale", function(req,res){ getFactorioLocale.asObject(config.factorioDirectory, "en", (err, factorioLocale) => res.send(factorioLocale)); }); diff --git a/package.json b/package.json index 60d80b10..3bde9aa4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "echo Run node client.js start [instance] to start slaves && node master.js", "cover": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- \"./{,!(node_modules)/**/}*.spec.js\" -R spec || echo . && codecov -t f7b38085-36eb-4d72-84e6-64721910171e", "docs": "documentation build index.js --config documentation.yml -f html -o docs", - "livedocs": "documentation serve --watch *.js --config documentation.yml" + "livedocs": "documentation serve --watch *.js lib/** --config documentation.yml" }, "keywords": [ "factorio"