Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mayahq/maya-db

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mayahq/maya-db - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

5

lib/src/db.d.ts

@@ -9,1 +9,6 @@ import { Collection } from "./storage/collection";

}): Collection;
export declare function httpAdapter({ apiUrl, root, headers }: {
apiUrl: string;
root: string;
headers: any;
}): Collection;

13

lib/src/db.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mongoDbAdapter = exports.localDb = void 0;
exports.httpAdapter = exports.mongoDbAdapter = exports.localDb = void 0;
var fileio_1 = require("./io/filesystem/fileio");
var collection_1 = require("./storage/collection");
var mongoIo_1 = require("./io/mongo/mongoIo");
var http_1 = require("./io/http/http");
function localDb(_a) {

@@ -21,1 +22,11 @@ var encryptionKey = _a.encryptionKey, root = _a.root;

exports.mongoDbAdapter = mongoDbAdapter;
function httpAdapter(_a) {
var apiUrl = _a.apiUrl, root = _a.root, headers = _a.headers;
var io = new http_1.HttpIoClient({
apiUrl: apiUrl,
headers: headers
});
var db = new collection_1.Collection({ absPath: root, io: io });
return db;
}
exports.httpAdapter = httpAdapter;

2

lib/src/index.d.ts

@@ -1,4 +0,4 @@

export { localDb, mongoDbAdapter } from './db';
export { localDb, mongoDbAdapter, httpAdapter } from './db';
export { generateSecretKey } from './io/filesystem/encrypt';
export { DatabaseTree } from './storage/storage';
export { MongoLock } from './io/mongo/lock';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongoLock = exports.generateSecretKey = exports.mongoDbAdapter = exports.localDb = void 0;
exports.MongoLock = exports.generateSecretKey = exports.httpAdapter = exports.mongoDbAdapter = exports.localDb = void 0;
var db_1 = require("./db");
Object.defineProperty(exports, "localDb", { enumerable: true, get: function () { return db_1.localDb; } });
Object.defineProperty(exports, "mongoDbAdapter", { enumerable: true, get: function () { return db_1.mongoDbAdapter; } });
Object.defineProperty(exports, "httpAdapter", { enumerable: true, get: function () { return db_1.httpAdapter; } });
var encrypt_1 = require("./io/filesystem/encrypt");

@@ -8,0 +9,0 @@ Object.defineProperty(exports, "generateSecretKey", { enumerable: true, get: function () { return encrypt_1.generateSecretKey; } });

@@ -143,3 +143,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var op, response;
var op, response, e_1, error;
return __generator(this, function (_a) {

@@ -149,6 +149,20 @@ switch (_a.label) {

op = { path: blockPath, operation: 'readFromBlock' };
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this._executeOperation(op)];
case 1:
case 2:
response = _a.sent();
return [2 /*return*/, response.data.result];
case 3:
e_1 = _a.sent();
if (e_1.response) {
if (e_1.response.data.error.name === 'BLOCK_NOT_FOUND') {
error = new Error('Block not found');
error.name = 'BLOCK_NOT_FOUND';
throw error;
}
}
throw e_1;
case 4: return [2 /*return*/];
}

@@ -160,3 +174,3 @@ });

return __awaiter(this, void 0, void 0, function () {
var op, response;
var op, response, e_2, error;
return __generator(this, function (_a) {

@@ -170,6 +184,20 @@ switch (_a.label) {

};
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, this._executeOperation(op)];
case 1:
case 2:
response = _a.sent();
return [2 /*return*/, response.data.result];
case 3:
e_2 = _a.sent();
if (e_2.response) {
if (e_2.response.data.error.name === 'BLOCK_NOT_FOUND') {
error = new Error('Block not found');
error.name = 'BLOCK_NOT_FOUND';
throw error;
}
}
throw e_2;
case 4: return [2 /*return*/];
}

@@ -348,3 +376,3 @@ });

};
return [4 /*yield*/, callback()];
return [4 /*yield*/, callback(response.data.lockDocument)];
case 2:

@@ -351,0 +379,0 @@ result = _a.sent();

@@ -46,3 +46,4 @@ "use strict";

var blockSchema_1 = __importDefault(require("../mongo/blockSchema"));
var API_URL = "http://localhost:5000/api/v2/mayadb/db-operation";
// const API_URL = `http://localhost:5000/api/v2/mayadb/db-operation`
var API_URL = "http://localhost:9000/db-operation";
var ioClient = new http_1.HttpIoClient({

@@ -83,54 +84,54 @@ apiUrl: API_URL,

switch (_a.label) {
case 0: return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/col1' })];
case 0: return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/col1" })];
case 1:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/col2' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/col2" })];
case 2:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/col2/col3' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/col2/col3" })];
case 3:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/col2/col4' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/col2/col4" })];
case 4:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/colToDelete' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/colToDelete" })];
case 5:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/colToDelete/col5' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/colToDelete/col5" })];
case 6:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/hierarchyCol' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/hierarchyCol" })];
case 7:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/hierarchyCol/hcol1' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/hierarchyCol/hcol1" })];
case 8:
_a.sent();
return [4 /*yield*/, collectionSchema_1.default.create({ path: '/httptest/hierarchyCol/hcol2' })];
return [4 /*yield*/, collectionSchema_1.default.create({ path: "/httptest/hierarchyCol/hcol2" })];
case 9:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/col1/block1', data: '{"a": 1}' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/col1/block1", data: '{"a": 1}' })];
case 10:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/col1/block2' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/col1/block2" })];
case 11:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/col2/col3/block3' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/col2/col3/block3" })];
case 12:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/col2/col3/block4' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/col2/col3/block4" })];
case 13:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/col1/blockToDelete' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/col1/blockToDelete" })];
case 14:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/colToDelete/ctdBlock1' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/colToDelete/ctdBlock1" })];
case 15:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/colToDelete/ctdBlock2' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/colToDelete/ctdBlock2" })];
case 16:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/colToDelete/col5/ctdBlock3' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/colToDelete/col5/ctdBlock3" })];
case 17:
_a.sent();
return [4 /*yield*/, blockSchema_1.default.create({ path: '/httptest/hierarchyCol/hcol1/hblock1' })];
return [4 /*yield*/, blockSchema_1.default.create({ path: "/httptest/hierarchyCol/hcol1/hblock1" })];
case 18:

@@ -400,3 +401,3 @@ _a.sent();

}); });
test('Acquiring lock on block works', function () { return __awaiter(void 0, void 0, void 0, function () {
test.only('Acquiring lock on block works', function () { return __awaiter(void 0, void 0, void 0, function () {
var sleep, increment, t1, t2, blockDoc;

@@ -411,3 +412,3 @@ return __generator(this, function (_a) {

switch (_a.label) {
case 0: return [4 /*yield*/, ioClient.acquireLockOnBlock('/httptest/col1/block1', function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, ioClient.acquireLockOnBlock('/httptest/col1/block1', function (lockDocument) { return __awaiter(void 0, void 0, void 0, function () {
var blockDoc, data;

@@ -496,3 +497,3 @@ return __generator(this, function (_a) {

}); });
test.only('Localization middleware works', function () { return __awaiter(void 0, void 0, void 0, function () {
test('Localization middleware works', function () { return __awaiter(void 0, void 0, void 0, function () {
var authIoClient, col;

@@ -511,2 +512,3 @@ return __generator(this, function (_a) {

col = _a.sent();
console.log('collection', col);
expect(col).toBeTruthy();

@@ -513,0 +515,0 @@ return [2 /*return*/];

@@ -59,3 +59,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var lockId_1, now_1, lockDocument, releaseFunction, e_1, e_2;
var lockId, releaseFunction, now_1, lockDocument, ld, error, e_1, e_2;
var _this = this;

@@ -65,16 +65,3 @@ return __generator(this, function (_a) {

case 0:
_a.trys.push([0, 6, , 7]);
lockId_1 = this.generateId();
now_1 = Date.now();
return [4 /*yield*/, blockSchema_1.default.findOneAndUpdate({
path: path,
lockExpiresAt: { $lt: now_1 }
}, {
$set: {
lockExpiresAt: now_1 + opts.acquireFor,
lockAcquiredBy: lockId_1
}
})];
case 1:
lockDocument = _a.sent();
lockId = this.generateId();
releaseFunction = function () { return __awaiter(_this, void 0, void 0, function () {

@@ -85,3 +72,3 @@ return __generator(this, function (_a) {

path: path,
lockAcquiredBy: lockId_1
lockAcquiredBy: lockId
}, {

@@ -101,6 +88,29 @@ $set: {

}); };
if (!!lockDocument) return [3 /*break*/, 5];
_a.label = 2;
_a.label = 1;
case 1:
_a.trys.push([1, 8, , 9]);
now_1 = Date.now();
return [4 /*yield*/, blockSchema_1.default.findOneAndUpdate({
path: path,
lockExpiresAt: { $lt: now_1 }
}, {
$set: {
lockExpiresAt: now_1 + opts.acquireFor,
lockAcquiredBy: lockId
}
})];
case 2:
_a.trys.push([2, 4, , 5]);
lockDocument = _a.sent();
if (!!lockDocument) return [3 /*break*/, 7];
return [4 /*yield*/, blockSchema_1.default.findOne({ path: path }).select('_id').lean()];
case 3:
ld = _a.sent();
if (!ld) {
error = new Error('Block does not exist');
error.name = 'BLOCK_NOT_FOUND';
throw error;
}
_a.label = 4;
case 4:
_a.trys.push([4, 6, , 7]);
return [4 /*yield*/, new Promise(function (resolve, reject) {

@@ -117,3 +127,3 @@ var interval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {

lockExpiresAt: Date.now() + opts.acquireFor,
lockAcquiredBy: lockId_1
lockAcquiredBy: lockId
}

@@ -140,13 +150,13 @@ }, {

})];
case 3:
case 5:
lockDocument = _a.sent();
return [2 /*return*/, callback(null, releaseFunction, lockDocument, lockId_1)];
case 4:
return [2 /*return*/, callback(null, releaseFunction, lockDocument, lockId)];
case 6:
e_1 = _a.sent();
return [2 /*return*/, callback(e_1, null, null, null)];
case 5: return [2 /*return*/, callback(null, releaseFunction, lockDocument, lockId_1)];
case 6:
return [2 /*return*/, callback(e_1, releaseFunction, null, null)];
case 7: return [2 /*return*/, callback(null, releaseFunction, lockDocument, lockId)];
case 8:
e_2 = _a.sent();
return [2 /*return*/, callback(e_2, null, null, null)];
case 7: return [2 /*return*/];
return [2 /*return*/, callback(e_2, releaseFunction, null, null)];
case 9: return [2 /*return*/];
}

@@ -153,0 +163,0 @@ });

@@ -45,3 +45,3 @@ "use strict";

beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
var db;
var db, connectionString;
return __generator(this, function (_a) {

@@ -57,3 +57,9 @@ switch (_a.label) {

};
return [4 /*yield*/, mongoose_1.default.connect("mongodb+srv://".concat(db.user, ":").concat(db.password, "@").concat(db.host, "/").concat(db.database))];
connectionString = 'mongodb://localhost:27017/mayatest';
return [4 /*yield*/, mongoose_1.default.connect(connectionString, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
})];
case 1:

@@ -60,0 +66,0 @@ _a.sent();

{
"name": "@mayahq/maya-db",
"version": "0.0.11",
"version": "0.0.12",
"description": "A small, encrypted simple document database meant for client-side use.",

@@ -5,0 +5,0 @@ "main": "lib/src/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc