change linter to standard

This commit is contained in:
Unknown
2018-11-12 10:28:59 +00:00
parent 19f3edf55a
commit 04d80c7c2f
19 changed files with 837 additions and 691 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable */
/**
* Model is a class whose sole responsibility is to save and load blueprints.
* It allows for different storage mechanisms for different kinds of blueprints.
@@ -9,7 +10,7 @@ class Model {
* @param {type} blueprint the Blueprint to be saved.
* @return {type} Promise which returns True.
*/
save(blueprint) {}
save (blueprint) {}
/**
* load - load a resource from a data model, using a Blueprint object as
@@ -19,5 +20,5 @@ class Model {
* @param {type} blueprint Blueprint object (desaturated?).
* @return {type} Object containing the resource data.
*/
load(url, blueprint) {}
load (url, blueprint) {}
}

View File

@@ -1,12 +1,10 @@
import fs from "mz/fs";
import hash from "object-hash";
import {fmtSourceTitle} from "../lib/util";
import path from "path";
import fs from 'mz/fs'
import { fmtSourceTitle } from '../lib/util'
const STORAGE_DIRNAME = "temp";
const STORAGE_DIRNAME = 'temp'
class StoreJson {
save(bp) {
save (bp) {
return Promise.all(
Object.keys(bp.routes).map(route =>
fs.writeFile(
@@ -16,50 +14,50 @@ class StoreJson {
JSON.stringify(bp.routes[route].data)
)
)
);
)
}
load(url, bp) {
const parts = url.split("/");
load (url) {
const parts = url.split('/')
const fname = `${STORAGE_DIRNAME}/${parts[0]}__${parts[1]}__${
parts[2]
}.json`;
}.json`
return fs
.exists(fname)
.then(isAvailable => {
if (isAvailable) return fs.readFile(fname, "utf8");
if (isAvailable) return fs.readFile(fname, 'utf8')
else {
throw new Error("No resource exists");
throw new Error('No resource exists')
}
})
.then(data => JSON.parse(data))
.then(data => {
if (parts.length === 3) {
// No lookup if the requested url doesn't have a fragment
return data;
} else if (parts[2] === "ids") {
return data
} else if (parts[2] === 'ids') {
// Do a lookup if fragment is included to filter a relevant item
// When the resource requested is 'ids'
const id = parseInt(parts[3]);
const id = parseInt(parts[3])
if (!isNaN(id) && id >= 0 && id < data.length) {
return data[id];
return data[id]
} else {
throw new Error(`Fragment index does not exist`);
throw new Error(`Fragment index does not exist`)
}
} else {
// Do a lookup if fragment is included to filter a relevant item
const index = parseInt(parts[3]);
const index = parseInt(parts[3])
if (!isNaN(index) && index >= 0 && index < data.length) {
console.log(data, index);
return data.filter((vl, idx) => idx === index)[0];
console.log(data, index)
return data.filter((vl, idx) => idx === index)[0]
} else {
throw new Error(`Fragment index does not exist`);
throw new Error(`Fragment index does not exist`)
}
}
});
})
}
// TODO: add method to build blueprint from data source
}
export default StoreJson;
export default StoreJson