@mayahq/maya-db
Advanced tools
Comparing version 0.0.2 to 0.0.3
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,3 +6,2 @@ exports.localDb = void 0; | ||
var collection_1 = require("./storage/collection"); | ||
var path_1 = __importDefault(require("path")); | ||
function localDb(_a) { | ||
@@ -18,64 +14,1 @@ var encryptionKey = _a.encryptionKey, root = _a.root; | ||
exports.localDb = localDb; | ||
var dbroot = path_1.default.resolve(process.env.HOME, 'maya/testdb1'); | ||
var db = localDb({ | ||
encryptionKey: 'eda344e1ab8b9e122aab3350eec33e95802c7fe68aac8ad85c5c64d97e45ef1a', | ||
root: dbroot | ||
}); | ||
var targetJson = { | ||
name: 'Dushyant', | ||
education: { | ||
college: 'BITS Pilani', | ||
graduation: 2022, | ||
degree: { | ||
type: 'single', | ||
branch: 'CS' | ||
} | ||
}, | ||
address: 'C-154 HKM Nagar' | ||
}; | ||
var tree = { | ||
tokens: [ | ||
{ | ||
safe: [ | ||
{ | ||
spotify: 'BLOCK', | ||
}, | ||
{ | ||
google: 'ENCRYPTED_BLOCK', | ||
}, | ||
{ | ||
testcol: [] | ||
} | ||
] | ||
}, | ||
{ | ||
unsafe: [ | ||
{ | ||
spotify: 'ENCRYPTED_BLOCK', | ||
}, | ||
{ | ||
testcol: [] | ||
} | ||
] | ||
} | ||
], | ||
global: 'BLOCK' | ||
}; | ||
// console.log(db.collection('global').getAllBlocks()) | ||
db.ensureHierarchy(tree); | ||
// const block = db.createNewCollection('global').createNewBlock('spotify', {encrypted: false}) | ||
// const block = db.block('global/spotify') | ||
// const block = db.collection('global').block('spotify') | ||
// block.set(targetJson, { | ||
// overwrite: true | ||
// }) | ||
// const result = block.get({ | ||
// name: null, | ||
// lastName: 'Jain', | ||
// education: { | ||
// college: null, | ||
// degreeType: 'single' | ||
// } | ||
// }).then((result) => { | ||
// console.log(result) | ||
// }) |
@@ -65,3 +65,10 @@ "use strict"; | ||
if (!this.includesCollection(dirPath)) { | ||
fs_1.default.mkdirSync(dirPath, { recursive: true }); | ||
try { | ||
fs_1.default.mkdirSync(dirPath, { recursive: true }); | ||
} | ||
catch (e) { | ||
if (!e.message.includes('EEXIST')) { | ||
throw e; | ||
} | ||
} | ||
} | ||
@@ -85,3 +92,3 @@ for (var _c = 0, val_1 = val; _c < val_1.length; _c++) { | ||
else { | ||
this.createBlock(blockPath, { encrypted: shouldBeEncrypted }); | ||
this.createBlock(blockPath, { encrypted: shouldBeEncrypted, strict: false }); | ||
} | ||
@@ -203,5 +210,9 @@ } | ||
if (fs_1.default.existsSync(blockPath + ".json")) { | ||
var err = new Error("Block already exists at path: " + blockPath + ".json"); | ||
err.name = 'BLOCK_ALREADY_EXISTS'; | ||
throw err; | ||
if (opts.strict) { | ||
var err = new Error("Block already exists at path: " + blockPath + ".json"); | ||
err.name = 'BLOCK_ALREADY_EXISTS'; | ||
throw err; | ||
} | ||
var block_2 = this.getBlock(blockPath); | ||
return block_2; | ||
} | ||
@@ -208,0 +219,0 @@ var dir = path_1.default.dirname(blockPath); |
import { DatabaseTree, StorageBlock, StorageCollection } from "../storage/storage"; | ||
export interface blockCreateOpts { | ||
encrypted: boolean; | ||
strict: boolean; | ||
} | ||
@@ -5,0 +6,0 @@ export declare type AsyncFunction = (...args: any) => Promise<any>; |
@@ -9,3 +9,4 @@ "use strict"; | ||
var DEFAULT_BLOCK_OPTS = { | ||
encrypted: true | ||
encrypted: true, | ||
strict: false | ||
}; | ||
@@ -12,0 +13,0 @@ var Collection = /** @class */ (function () { |
{ | ||
"name": "@mayahq/maya-db", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A small, encrypted simple document database meant for client-side use.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
45054
889