backup..
This commit is contained in:
parent
a8aa18d01d
commit
36f9e7c64f
|
@ -1,7 +1,6 @@
|
|||
import {promisify} from 'es6-promisify';
|
||||
|
||||
import fs from "fs";
|
||||
import {join} from "path";
|
||||
const {promisify} = require('util');
|
||||
const fs = require("fs");
|
||||
const {join} = require("path");
|
||||
|
||||
const readFile = promisify(fs.readFile);
|
||||
const writeFile = (path, content) =>
|
||||
|
@ -41,7 +40,7 @@ const createFolder = root => async (path) =>
|
|||
await mkdir(
|
||||
join(root, path));
|
||||
|
||||
export const deleteFile = root => async (path) =>
|
||||
module.exports.deleteFile = root => async (path) =>
|
||||
await unlink(
|
||||
join(root, path)
|
||||
);
|
||||
|
@ -72,16 +71,35 @@ const renameFile = root => async (oldPath, newPath) =>
|
|||
join(root, newPath)
|
||||
);
|
||||
|
||||
const createEmptyDb = root = async (type, productSetId, productId, productInstanceId) => {
|
||||
const folder = !productSetId ? type
|
||||
: !productInstanceId ? `${type}.${productSetId}`
|
||||
: `${type}.${productSetId}.${productId}.${productInstanceId}`;
|
||||
const datastoreFolder = (type, productSetId, productId, productInstanceId) =>
|
||||
!productSetId ? type
|
||||
: !productInstanceId ? `${type}.${productSetId}`
|
||||
: `${type}.${productSetId}.${productId}.${productInstanceId}`;
|
||||
|
||||
await createFolder(root)(folder);
|
||||
const createEmptyDb = async (dbRootConfig, type, productSetId, productId, productInstanceId) => {
|
||||
const folder = datastoreFolder(type, productSetId, productId, productInstanceId);
|
||||
await createFolder(dbRootConfig)(folder);
|
||||
return folder;
|
||||
}
|
||||
};
|
||||
|
||||
export default rootFolderPath => ({
|
||||
const getDatastoreConfig = (dbRootConfig, type, productSetId, productId, productInstanceId) =>
|
||||
join(dbRootConfig,
|
||||
datastoreFolder(
|
||||
type, productSetId, productId, productInstanceId
|
||||
));
|
||||
|
||||
const getMasterDbRootConfig = () => "./data";
|
||||
const getProductSetDbRootConfig = async (productSetId) => "./data";
|
||||
const getProductInstanceDbRootConfig =
|
||||
async (productSetId, productId, productInstanceId) => "./data";
|
||||
|
||||
module.exports.databaseManager = {
|
||||
createEmptyDb, getDatastoreConfig,
|
||||
getMasterDbRootConfig, getProductSetDbRootConfig,
|
||||
getProductInstanceDbRootConfig
|
||||
};
|
||||
|
||||
module.exports.getDatastore = rootFolderPath => ({
|
||||
createFile : createFile(rootFolderPath),
|
||||
updateFile : updateFile(rootFolderPath),
|
||||
loadFile : loadFile(rootFolderPath),
|
||||
|
@ -97,4 +115,3 @@ export default rootFolderPath => ({
|
|||
datastoreType : "local",
|
||||
datastoreDescription: rootFolderPath
|
||||
});
|
||||
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
const {initialiseData, getTemplateApi,
|
||||
getAppApis} = require("budibase-core");
|
||||
const crypto = require("../server/nodeCrypto");
|
||||
const {initialiseData,
|
||||
getTemplateApi} = require("budibase-core");
|
||||
const {newField, getDatabaseManager,
|
||||
getApisWithFullAccess} = require("./helpers");
|
||||
|
||||
module.exports = async (datastoreFactory, dataRootOpts,
|
||||
username, password) => {
|
||||
const rootDatastore = datastoreFactory(dataRootOpts);
|
||||
const masterDatastoreOpts = await rootDatastore.createEmptyMasterDb();
|
||||
const datastore = datastoreFactory(masterDatastoreOpts);
|
||||
module.exports = async (datastoreModule, username, password) => {
|
||||
|
||||
/*const bb = getAppApis(
|
||||
datastore, {},
|
||||
null, null,
|
||||
crypto
|
||||
);*/
|
||||
const databaseManager = getDatabaseManager(datastoreModule);
|
||||
|
||||
const masterDbConfig = await databaseManager.createEmptyMasterDb();
|
||||
const datastore = datastoreModule.getDatastore(masterDbConfig);
|
||||
|
||||
const templateApi = getTemplateApi();
|
||||
|
||||
const root = templateApi.getNewRootLevel();
|
||||
const productSets = templateApi.getNewCollectionTemplate(root);
|
||||
productSets.name = "ProductSets";
|
||||
|
@ -25,6 +20,7 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
|||
|
||||
const newProductSetField = newField(templateApi, productSet);
|
||||
newProductSetField("name", "string", true);
|
||||
newProductSetField("dbRootConfig", "string");
|
||||
|
||||
const products = templateApi.getNewCollectionTemplate(productSet);
|
||||
products.name = "Products";
|
||||
|
@ -35,19 +31,14 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
|||
const newProductField = newField(templateApi, product);
|
||||
newProductField("name", "string", true);
|
||||
newProductField("domain", "string", true);
|
||||
newProductField("datastoreConfig", "string", true);
|
||||
|
||||
|
||||
await initialiseData(datastore, {
|
||||
heirarchy:root, actions:[], triggers:[]
|
||||
});
|
||||
|
||||
const bb = await getAppApis(
|
||||
datastore,
|
||||
null, null, null,
|
||||
crypto
|
||||
);
|
||||
|
||||
bb.asFullAccess();
|
||||
const bb = await getApisWithFullAccess(datastore);
|
||||
|
||||
const fullAccess = bb.authApi.getNewAccessLevel();
|
||||
fullAccess.permissions = bb.authApi.generateFullPermissions();
|
||||
|
@ -58,19 +49,6 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
|||
seedUser.accessLevels = ["Full Access"];
|
||||
await bb.authApi.createUser(seedUser, password);
|
||||
|
||||
const initialProductSet = bb.recordApi.getNew("/ProductSets", "ProductSet");
|
||||
initialProductSet.name = "Dev Products";
|
||||
|
||||
return await bb.recordApi.save(initialProductSet);
|
||||
return masterDbConfig;
|
||||
};
|
||||
|
||||
const newField = (templateApi, recordNode) => (name, type, mandatory=false) => {
|
||||
const field = templateApi.getNewField(type);
|
||||
field.name = name;
|
||||
templateApi.addField(recordNode, field);
|
||||
if(mandatory) {
|
||||
templateApi.addRecordValidationRule(recordNode)
|
||||
(templateApi.commonValidationRules.fieldNotEmpty)
|
||||
}
|
||||
return field;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
const {common, getAppApis} = require("budibase-core");
|
||||
const {getDatabaseManager} = require("./helpers");
|
||||
|
||||
module.exports = async (productSetId, productId, versionId) => {
|
||||
const databaseManager = getDatabaseManager(datastoreModule);
|
||||
const masterDatastore = datastoreModule.getDatastore(
|
||||
databaseManager.masterDatastoreConfig
|
||||
);
|
||||
|
||||
const master = await getAppApis(masterDatastore);
|
||||
|
||||
const productSet = await master.recordApi.load(
|
||||
common.joinKey("ProductSets", productSetId)
|
||||
);
|
||||
|
||||
const prodcutSetDatastore = datastoreModule.getDatastore(
|
||||
productSet.datastoreConfig
|
||||
);
|
||||
|
||||
const productSetApis = await getAppApis(prodcutSetDatastore);
|
||||
const product = await productSetApis.recordApi.load(
|
||||
common.joinKey("Products", productId)
|
||||
);
|
||||
|
||||
const version = await productSetApis.recordApi.load(
|
||||
common.joinKey("Products", productId, "Versions", versionId)
|
||||
);
|
||||
|
||||
const instance = await productSetApis.recordApi.getNew(
|
||||
common.joinKey(product.key, "Versions", )
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,8 +1,78 @@
|
|||
const {initialiseData, getTemplateApi,
|
||||
getAppApis} = require("budibase-core");
|
||||
const {newField, getDatabaseManager} = require("./helpers");
|
||||
|
||||
module.exports = async (datastoreModule, productSetName,
|
||||
username, password) => {
|
||||
|
||||
module.exports = async (datastoreFactory, productDbOpts) => {
|
||||
const databaseManager = getDatabaseManager(datastoreModule);
|
||||
const masterDatastore = datastoreModule.getDatastore(
|
||||
databaseManager.masterDatastoreConfig
|
||||
);
|
||||
|
||||
const masterApi = await getAppApis(masterDatastore);
|
||||
const ps = masterApi.recordApi.getNew("/ProductSets", "ProductSet");
|
||||
|
||||
const psDatastoreConfig = await databaseManager.createEmptyProductSetDb(ps.id);
|
||||
ps.datastoreConfig = psDatastoreConfig;
|
||||
ps.name = productSetName;
|
||||
await bb.recordApi.save(ps);
|
||||
|
||||
const datastore = datastoreFactory(psDatastoreConfig);
|
||||
const templateApi = getTemplateApi();
|
||||
|
||||
const root = templateApi.getNewRootLevel();
|
||||
const products = templateApi.getNewCollectionTemplate(root, "Products");
|
||||
|
||||
const product = templateApi.getNewRecordTemplate(products);
|
||||
product.name = "Product";
|
||||
|
||||
const newProductField = newField(templateApi, product);
|
||||
newProductField("name", "string", true);
|
||||
newProductField("domain", "string", true);
|
||||
newProductField("certificate", "string", true);
|
||||
|
||||
var productVersionsRefIndex = templateApi.getNewIndexTemplate(products);
|
||||
|
||||
const versions = templateApi.getNewCollectionTemplate(product, "versions", false);
|
||||
const version = templateApi.getNewRecordTemplate(versions);
|
||||
const newVersionField = newField(templateApi, version);
|
||||
newVersionField("date", "datetime", true);
|
||||
newVersionField("description", "string", false);
|
||||
newVersionField("appDefinition", "file", false);
|
||||
newVersionField("publicFiles", "array<file>", false);
|
||||
const deployable = newVersionField("deployable", "bool", false)
|
||||
deployable.getInitialValue = "false";
|
||||
deployable.typeOptions.allowNulls = false;
|
||||
|
||||
const versionLookup = templateApi.getNewIndexTemplate(product);
|
||||
versionLookup.name = "versionLookup";
|
||||
versionLookup.map = "return ({description:record.description, deployable:record.deployable});";
|
||||
versionLookup.allowedRecordNodeIds = [version.recordNodeId];
|
||||
|
||||
|
||||
|
||||
const productInstances = templateApi.getNewCollectionTemplate(product);
|
||||
productInstances.name = "ProductInstances";
|
||||
const productInstance = templateApi.getNewRecordTemplate(productInstances);
|
||||
productInstance.name = "ProductInstance";
|
||||
const newProductInstanceField = newField(templateApi, productInstance);
|
||||
newProductInstanceField("description", "string", true);
|
||||
const versionReference = newProductInstanceField("version", "reference");
|
||||
versionReference.typeOptions.indexNodeKey = versions.indexes[0].nodeKey();
|
||||
|
||||
await initialiseData(datastore, {
|
||||
heirarchy:root, actions:[], triggers:[]
|
||||
});
|
||||
|
||||
const bb = await getApisWithFullAccess(datastore);
|
||||
const fullAccess = bb.authApi.getNewAccessLevel();
|
||||
fullAccess.permissions = bb.authApi.generateFullPermissions();
|
||||
fullAccess.name = "Full Access";
|
||||
await bb.authApi.saveAccessLevels([fullAccess]);
|
||||
const seedUser = bb.authApi.getNewUser();
|
||||
seedUser.name = username;
|
||||
seedUser.accessLevels = ["Full Access"];
|
||||
await bb.authApi.createUser(seedUser, password);
|
||||
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
const crypto = require("../server/nodeCrypto");
|
||||
const {
|
||||
getDatabaseFactory} = require("budibase-core");
|
||||
|
||||
module.exports.newField = (templateApi, recordNode) => (name, type, mandatory=false) => {
|
||||
const field = templateApi.getNewField(type);
|
||||
field.name = name;
|
||||
templateApi.addField(recordNode, field);
|
||||
if(mandatory) {
|
||||
templateApi.addRecordValidationRule(recordNode)
|
||||
(templateApi.commonValidationRules.fieldNotEmpty)
|
||||
}
|
||||
return field;
|
||||
};
|
||||
|
||||
module.exports.getApisWithFullAccess = async (datastore) => {
|
||||
const bb = await getAppApis(
|
||||
datastore,
|
||||
null, null, null,
|
||||
crypto
|
||||
);
|
||||
|
||||
bb.asFullAccess();
|
||||
|
||||
return bb;
|
||||
};
|
||||
|
||||
module.exports.getDatabaseManager = (datastoreModule) =>
|
||||
getDatabaseFactory(datastoreModule.databaseManager);
|
|
@ -0,0 +1,41 @@
|
|||
const {getAppApis} = require("budibase-core");
|
||||
|
||||
module.exports = (datastoreConfig, datastoreModule, method, path) => {
|
||||
|
||||
const datastore = datastoreModule.getDatastore(
|
||||
datastoreConfig);
|
||||
|
||||
const bb = getAppApis(
|
||||
datastore
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* api Routes (all /api/..)
|
||||
|
||||
POST executeAction/<name> {}
|
||||
POST authenticate {}
|
||||
POST authenticateTemporaryAccess {}
|
||||
POST createUser {}
|
||||
POST enabledUser {}
|
||||
POST disableUser {}
|
||||
GET users
|
||||
GET accessLevels
|
||||
POST accessLevels {}
|
||||
POST changeMyPassword {}
|
||||
POST setPasswordFromTemporaryCode {}
|
||||
POST listItems/index/key {}
|
||||
POST aggregates/index/key {}
|
||||
POST record/key/to/rec {}
|
||||
GET record/key/to/rec
|
||||
DELETE record/key/to/rec
|
||||
POST appHeirarchy {}
|
||||
POST actionsAndTriggers {}
|
||||
GET appDefinition
|
||||
|
||||
*/
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
"budibase-core@git+ssh://git@gitlab.com/budibase-dist/budibase-core.git":
|
||||
version "1.0.0"
|
||||
resolved "git+ssh://git@gitlab.com/budibase-dist/budibase-core.git#99f1604b1314a3687312820b783256440c3a57f1"
|
||||
resolved "git+ssh://git@gitlab.com/budibase-dist/budibase-core.git#7d0b44b6f7439b4b4f48b7b9c12e9eb3fa045203"
|
||||
dependencies:
|
||||
"@nx-js/compiler-util" "^2.0.0"
|
||||
date-fns "^1.29.0"
|
||||
|
|
Loading…
Reference in New Issue