backup..
This commit is contained in:
parent
a8aa18d01d
commit
36f9e7c64f
|
@ -1,7 +1,6 @@
|
||||||
import {promisify} from 'es6-promisify';
|
const {promisify} = require('util');
|
||||||
|
const fs = require("fs");
|
||||||
import fs from "fs";
|
const {join} = require("path");
|
||||||
import {join} from "path";
|
|
||||||
|
|
||||||
const readFile = promisify(fs.readFile);
|
const readFile = promisify(fs.readFile);
|
||||||
const writeFile = (path, content) =>
|
const writeFile = (path, content) =>
|
||||||
|
@ -41,7 +40,7 @@ const createFolder = root => async (path) =>
|
||||||
await mkdir(
|
await mkdir(
|
||||||
join(root, path));
|
join(root, path));
|
||||||
|
|
||||||
export const deleteFile = root => async (path) =>
|
module.exports.deleteFile = root => async (path) =>
|
||||||
await unlink(
|
await unlink(
|
||||||
join(root, path)
|
join(root, path)
|
||||||
);
|
);
|
||||||
|
@ -72,16 +71,35 @@ const renameFile = root => async (oldPath, newPath) =>
|
||||||
join(root, newPath)
|
join(root, newPath)
|
||||||
);
|
);
|
||||||
|
|
||||||
const createEmptyDb = root = async (type, productSetId, productId, productInstanceId) => {
|
const datastoreFolder = (type, productSetId, productId, productInstanceId) =>
|
||||||
const folder = !productSetId ? type
|
!productSetId ? type
|
||||||
: !productInstanceId ? `${type}.${productSetId}`
|
: !productInstanceId ? `${type}.${productSetId}`
|
||||||
: `${type}.${productSetId}.${productId}.${productInstanceId}`;
|
: `${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;
|
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),
|
createFile : createFile(rootFolderPath),
|
||||||
updateFile : updateFile(rootFolderPath),
|
updateFile : updateFile(rootFolderPath),
|
||||||
loadFile : loadFile(rootFolderPath),
|
loadFile : loadFile(rootFolderPath),
|
||||||
|
@ -97,4 +115,3 @@ export default rootFolderPath => ({
|
||||||
datastoreType : "local",
|
datastoreType : "local",
|
||||||
datastoreDescription: rootFolderPath
|
datastoreDescription: rootFolderPath
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
const {initialiseData, getTemplateApi,
|
const {initialiseData,
|
||||||
getAppApis} = require("budibase-core");
|
getTemplateApi} = require("budibase-core");
|
||||||
const crypto = require("../server/nodeCrypto");
|
const {newField, getDatabaseManager,
|
||||||
|
getApisWithFullAccess} = require("./helpers");
|
||||||
|
|
||||||
module.exports = async (datastoreFactory, dataRootOpts,
|
module.exports = async (datastoreModule, username, password) => {
|
||||||
username, password) => {
|
|
||||||
const rootDatastore = datastoreFactory(dataRootOpts);
|
|
||||||
const masterDatastoreOpts = await rootDatastore.createEmptyMasterDb();
|
|
||||||
const datastore = datastoreFactory(masterDatastoreOpts);
|
|
||||||
|
|
||||||
/*const bb = getAppApis(
|
const databaseManager = getDatabaseManager(datastoreModule);
|
||||||
datastore, {},
|
|
||||||
null, null,
|
const masterDbConfig = await databaseManager.createEmptyMasterDb();
|
||||||
crypto
|
const datastore = datastoreModule.getDatastore(masterDbConfig);
|
||||||
);*/
|
|
||||||
|
|
||||||
const templateApi = getTemplateApi();
|
const templateApi = getTemplateApi();
|
||||||
|
|
||||||
const root = templateApi.getNewRootLevel();
|
const root = templateApi.getNewRootLevel();
|
||||||
const productSets = templateApi.getNewCollectionTemplate(root);
|
const productSets = templateApi.getNewCollectionTemplate(root);
|
||||||
productSets.name = "ProductSets";
|
productSets.name = "ProductSets";
|
||||||
|
@ -25,6 +20,7 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
||||||
|
|
||||||
const newProductSetField = newField(templateApi, productSet);
|
const newProductSetField = newField(templateApi, productSet);
|
||||||
newProductSetField("name", "string", true);
|
newProductSetField("name", "string", true);
|
||||||
|
newProductSetField("dbRootConfig", "string");
|
||||||
|
|
||||||
const products = templateApi.getNewCollectionTemplate(productSet);
|
const products = templateApi.getNewCollectionTemplate(productSet);
|
||||||
products.name = "Products";
|
products.name = "Products";
|
||||||
|
@ -35,19 +31,14 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
||||||
const newProductField = newField(templateApi, product);
|
const newProductField = newField(templateApi, product);
|
||||||
newProductField("name", "string", true);
|
newProductField("name", "string", true);
|
||||||
newProductField("domain", "string", true);
|
newProductField("domain", "string", true);
|
||||||
|
newProductField("datastoreConfig", "string", true);
|
||||||
|
|
||||||
|
|
||||||
await initialiseData(datastore, {
|
await initialiseData(datastore, {
|
||||||
heirarchy:root, actions:[], triggers:[]
|
heirarchy:root, actions:[], triggers:[]
|
||||||
});
|
});
|
||||||
|
|
||||||
const bb = await getAppApis(
|
const bb = await getApisWithFullAccess(datastore);
|
||||||
datastore,
|
|
||||||
null, null, null,
|
|
||||||
crypto
|
|
||||||
);
|
|
||||||
|
|
||||||
bb.asFullAccess();
|
|
||||||
|
|
||||||
const fullAccess = bb.authApi.getNewAccessLevel();
|
const fullAccess = bb.authApi.getNewAccessLevel();
|
||||||
fullAccess.permissions = bb.authApi.generateFullPermissions();
|
fullAccess.permissions = bb.authApi.generateFullPermissions();
|
||||||
|
@ -58,19 +49,6 @@ module.exports = async (datastoreFactory, dataRootOpts,
|
||||||
seedUser.accessLevels = ["Full Access"];
|
seedUser.accessLevels = ["Full Access"];
|
||||||
await bb.authApi.createUser(seedUser, password);
|
await bb.authApi.createUser(seedUser, password);
|
||||||
|
|
||||||
const initialProductSet = bb.recordApi.getNew("/ProductSets", "ProductSet");
|
return masterDbConfig;
|
||||||
initialProductSet.name = "Dev Products";
|
|
||||||
|
|
||||||
return await bb.recordApi.save(initialProductSet);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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":
|
"budibase-core@git+ssh://git@gitlab.com/budibase-dist/budibase-core.git":
|
||||||
version "1.0.0"
|
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:
|
dependencies:
|
||||||
"@nx-js/compiler-util" "^2.0.0"
|
"@nx-js/compiler-util" "^2.0.0"
|
||||||
date-fns "^1.29.0"
|
date-fns "^1.29.0"
|
||||||
|
|
Loading…
Reference in New Issue