From 191ea5d3c61061fb2a3c7cefcdddfddcdbdbf044 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 10 Jul 2018 00:02:04 +0200 Subject: [PATCH] update to mongodb --- README.md | 29 ++-- dist/index.d.ts | 3 - dist/index.js | 9 - dist/smartdata.classes.db.d.ts | 36 ---- dist/smartdata.classes.db.js | 76 --------- dist/smartdata.classes.dbdoc.d.ts | 46 ----- dist/smartdata.classes.dbdoc.js | 109 ------------ dist/smartdata.classes.dbtable.d.ts | 51 ------ dist/smartdata.classes.dbtable.js | 116 ------------- dist/smartdata.plugins.d.ts | 7 - dist/smartdata.plugins.js | 15 -- package-lock.json | 160 +++++++++++------- package.json | 12 +- test/test.ts | 12 +- ts/index.ts | 4 +- ...ble.ts => smartdata.classes.collection.ts} | 16 +- ts/smartdata.classes.db.ts | 13 +- ...sses.dbdoc.ts => smartdata.classes.doc.ts} | 18 +- tsconfig.json | 7 + 19 files changed, 153 insertions(+), 586 deletions(-) delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/smartdata.classes.db.d.ts delete mode 100644 dist/smartdata.classes.db.js delete mode 100644 dist/smartdata.classes.dbdoc.d.ts delete mode 100644 dist/smartdata.classes.dbdoc.js delete mode 100644 dist/smartdata.classes.dbtable.d.ts delete mode 100644 dist/smartdata.classes.dbtable.js delete mode 100644 dist/smartdata.plugins.d.ts delete mode 100644 dist/smartdata.plugins.js rename ts/{smartdata.classes.dbtable.ts => smartdata.classes.collection.ts} (83%) rename ts/{smartdata.classes.dbdoc.ts => smartdata.classes.doc.ts} (82%) create mode 100644 tsconfig.json diff --git a/README.md b/README.md index d552eff..6d43cad 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,11 @@ This is why we started smartdata. How RethinkDB's terms map to the ones of smartdata: -| RethinkDB term | smartdata class | -| -------------- | ----------------- | -| Database | smartdata.Db | -| Table | smartdata.DbTable | -| Document | smartdata.DbDoc | +| MongoDb term | smartdata class | +| -------------- | ------------------------------| +| Database | smartdata.SmartdataDb | +| Collection | smartdata.SmartdataCollection | +| Document | smartdata.SmartadataDoc | ### class Db @@ -50,18 +50,13 @@ represents a Database. Naturally it has .connect() etc. methods on it. ```typescript import * as smartdata from 'smartdata'; -let myRethinkDb1 = new smartdata.Db({ - db: 'test', - host: 'https://some', - user: 'testuser', - password: 'testpass', - port: 1234 +const smartdataDb = new smartdata.SmartdataDb({ + mongoDbUrl: '//someurl', + mongoDbName: 'myDatabase', + mongoDbPass: 'mypassword' }); -// in case you need to support a proprietory ssl cert (e.g. compose.com): -myRethinkDb1.setSsl(process.env.RDB_CERT, 'base64'); - -myDb1.connect(); +smartdataDb.connect(); ``` ### class DbCollection @@ -74,8 +69,8 @@ So to get to get access to a specific collection you document ```typescript // continues from the block before... -@smartdata.Table(myRethinkDb1) -class MyObject extends smartdata.DbDoc { +@smartdata.Collection(smartdataDb) +class MyObject extends smartdata.DbDoc { // read the next block about DbDoc @smartdata.svDb() property1: string; // @smartdata.svDb() marks the property for db save property2: number; // this one is not marked, so it won't be save upon calling this.save() diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 84fc995..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./smartdata.classes.db"; -export * from "./smartdata.classes.dbtable"; -export * from "./smartdata.classes.dbdoc"; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 6751eee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -__export(require("./smartdata.classes.db")); -__export(require("./smartdata.classes.dbtable")); -__export(require("./smartdata.classes.dbdoc")); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDRDQUF1QztBQUN2QyxpREFBNEM7QUFDNUMsK0NBQTBDIn0= \ No newline at end of file diff --git a/dist/smartdata.classes.db.d.ts b/dist/smartdata.classes.db.d.ts deleted file mode 100644 index 54f0cdc..0000000 --- a/dist/smartdata.classes.db.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -import * as plugins from "./smartdata.plugins"; -import { Objectmap } from "lik"; -import { DbTable } from "./smartdata.classes.dbtable"; -import { ConnectionOptions as IConnectionOptions } from "rethinkdb"; -export { IConnectionOptions }; -/** - * interface - indicates the connection status of the db - */ -export declare type TConnectionStatus = "initial" | "disconnected" | "connected" | "failed"; -export declare class Db { - dbName: string; - connectionOptions: plugins.rethinkDb.ConnectionOptions; - dbConnection: plugins.rethinkDb.Connection; - status: TConnectionStatus; - dbTablesMap: Objectmap>; - constructor(connectionOptionsArg: IConnectionOptions); - /** - * supply additional SSl options needed to connect to certain Rethink DB servers (e.g. compose.io) - */ - setSsl(certificateStringArg: string, formatArg: "base64" | "clearText"): void; - /** - * connects to the database that was specified during instance creation - */ - connect(): Promise; - /** - * closes the connection to the databse - */ - close(): Promise; - addTable(dbTableArg: DbTable): void; - /** - * Gets a table's name and returns smartdata's DbTable class - * @param nameArg - * @returns DbTable - */ - getDbTableByName(nameArg: string): Promise>; -} diff --git a/dist/smartdata.classes.db.js b/dist/smartdata.classes.db.js deleted file mode 100644 index 54d575e..0000000 --- a/dist/smartdata.classes.db.js +++ /dev/null @@ -1,76 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const plugins = require("./smartdata.plugins"); -const lik_1 = require("lik"); -class Db { - constructor(connectionOptionsArg) { - this.dbTablesMap = new lik_1.Objectmap(); - this.dbName = connectionOptionsArg.db; - this.connectionOptions = connectionOptionsArg; - this.status = "initial"; - } - /** - * supply additional SSl options needed to connect to certain Rethink DB servers (e.g. compose.io) - */ - setSsl(certificateStringArg, formatArg) { - let certificateString; - if ((formatArg = "base64")) { - certificateString = plugins.smartstring.base64.decode(certificateStringArg); - } - else { - certificateString = certificateStringArg; - } - this.connectionOptions["ssl"] = { - ca: Buffer.from(certificateString) - }; - } - // basic connection stuff ---------------------------------------------- - /** - * connects to the database that was specified during instance creation - */ - connect() { - return __awaiter(this, void 0, void 0, function* () { - this.dbConnection = yield plugins.rethinkDb.connect(this.connectionOptions); - this.dbConnection.use(this.dbName); - this.status = "connected"; - plugins.beautylog.ok(`Connected to database ${this.dbName}`); - }); - } - /** - * closes the connection to the databse - */ - close() { - return __awaiter(this, void 0, void 0, function* () { - yield this.dbConnection.close(); - this.status = "disconnected"; - plugins.beautylog.ok(`disconnected from database ${this.dbName}`); - }); - } - // handle table to class distribution - addTable(dbTableArg) { - this.dbTablesMap.add(dbTableArg); - } - /** - * Gets a table's name and returns smartdata's DbTable class - * @param nameArg - * @returns DbTable - */ - getDbTableByName(nameArg) { - return __awaiter(this, void 0, void 0, function* () { - let resultCollection = this.dbTablesMap.find(dbTableArg => { - return dbTableArg.tableName === nameArg; - }); - return resultCollection; - }); - } -} -exports.Db = Db; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsK0NBQStDO0FBQy9DLDZCQUFnQztBQ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RyxXQUFXLENBQUM7WUFDMUIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMseUJBQXlCLElBQUksQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDO1FBQy9ELENBQUM7S0FBQTtJQUVEOztPQUVHO0lBQ0csS0FBSzs7WUFDVCxNQUFNLElBQUksQ0FBQyxZQUFZLENBQUMsS0FBSyxFQUFFLENBQUM7WUFDaEMsSUFBSSxDQUFDLE1BQU0sR0FBRyxjQUFjLENBQUM7WUFDN0IsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsOEJBQThCLElBQUksQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDO1FBQ3BFLENBQUM7S0FBQTtJQUVELHFDQUFxQztJQUVyQyxRQUFRLENBQUMsVUFBd0I7UUFDL0IsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDbkMsQ0FBQztJQUVEOzs7O09BSUc7SUFDRyxnQkFBZ0IsQ0FBSSxPQUFlOztZQUN2QyxJQUFJLGdCQUFnQixHQUFHLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxFQUFFO2dCQUN4RCxNQUFNLENBQUMsVUFBVSxDQUFDLFNBQVMsS0FBSyxPQUFPLENBQUM7WUFDMUMsQ0FBQyxDQUFDLENBQUM7WUFDSCxNQUFNLENBQUMsZ0JBQWdCLENBQUM7UUFDMUIsQ0FBQztLQUFBO0NBQ0Y7QUFwRUQsZ0JBb0VDIn0= \ No newline at end of file diff --git a/dist/smartdata.classes.dbdoc.d.ts b/dist/smartdata.classes.dbdoc.d.ts deleted file mode 100644 index 1682769..0000000 --- a/dist/smartdata.classes.dbdoc.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Objectmap } from "lik"; -import { DbTable } from "./smartdata.classes.dbtable"; -export declare type TDocCreation = "db" | "new" | "mixed"; -/** - * saveable - saveable decorator to be used on class properties - */ -export declare function svDb(): (target: DbDoc, key: string) => void; -export declare class DbDoc { - /** - * the collection object an Doc belongs to - */ - collection: DbTable; - /** - * how the Doc in memory was created, may prove useful later. - */ - creationStatus: TDocCreation; - /** - * an array of saveable properties of a doc - */ - saveableProperties: string[]; - /** - * name - */ - name: string; - /** - * primary id in the database - */ - dbId: string; - /** - * class constructor - */ - constructor(); - static getInstances(filterArg: any): Promise; - static getInstance(filterArg: any): Promise; - /** - * saves this instance but not any connected items - * may lead to data inconsistencies, but is faster - */ - save(): Promise; - /** - * also store any referenced objects to DB - * better for data consistency - */ - saveDeep(savedMapArg?: Objectmap>): void; - createSavableObject(): any; -} diff --git a/dist/smartdata.classes.dbdoc.js b/dist/smartdata.classes.dbdoc.js deleted file mode 100644 index 5a561ae..0000000 --- a/dist/smartdata.classes.dbdoc.js +++ /dev/null @@ -1,109 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const lik_1 = require("lik"); -/** - * saveable - saveable decorator to be used on class properties - */ -function svDb() { - return (target, key) => { - console.log("called sva"); - if (!target.saveableProperties) { - target.saveableProperties = []; - } - target.saveableProperties.push(key); - }; -} -exports.svDb = svDb; -class DbDoc { - /** - * class constructor - */ - constructor() { - /** - * how the Doc in memory was created, may prove useful later. - */ - this.creationStatus = "new"; - this.name = this.constructor["name"]; - this.collection = this.constructor["dbTable"]; - } - static getInstances(filterArg) { - return __awaiter(this, void 0, void 0, function* () { - let self = this; // fool typesystem - let referenceTable = self.dbTable; - const foundDocs = yield referenceTable.find(filterArg); - const returnArray = []; - for (let item of foundDocs) { - let newInstance = new this(); - for (let key in item) { - if (key !== 'id') { - newInstance[key] = item[key]; - } - } - returnArray.push(newInstance); - } - return returnArray; - }); - } - static getInstance(filterArg) { - return __awaiter(this, void 0, void 0, function* () { - let result = yield this.getInstances(filterArg); - if (result && result.length > 0) { - return result[0]; - } - }); - } - /** - * saves this instance but not any connected items - * may lead to data inconsistencies, but is faster - */ - save() { - return __awaiter(this, void 0, void 0, function* () { - let self = this; - switch (this.creationStatus) { - case "db": - yield this.collection.update(self); - break; - case "new": - let writeResult = yield this.collection.insert(self); - this.creationStatus = "db"; - break; - default: - console.error("neither new nor in db?"); - } - }); - } - /** - * also store any referenced objects to DB - * better for data consistency - */ - saveDeep(savedMapArg = null) { - if (!savedMapArg) { - savedMapArg = new lik_1.Objectmap(); - } - savedMapArg.add(this); - this.save(); - for (let propertyKey in this) { - let property = this[propertyKey]; - if (property instanceof DbDoc && !savedMapArg.checkForObject(property)) { - property.saveDeep(savedMapArg); - } - } - } - createSavableObject() { - let saveableObject = {}; // is not exposed to outside, so any is ok here - for (let propertyNameString of this.saveableProperties) { - saveableObject[propertyNameString] = this[propertyNameString]; - } - return saveableObject; - } -} -exports.DbDoc = DbDoc; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUEsNkJBQWdDO0FBT2hDOztHQUVHO0FBQ0g7SUFDRSxNQUFNLENBQUMsQ0FBQyxNQUFrQixFQUFFLEdBQVcsRUFBRSxFQUFFO1FBQ3pDLE9BQU8sQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUM7UUFDMUIsRUFBRSxDQUFDLENBQUMs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able.d.ts deleted file mode 100644 index e1d3a23..0000000 --- a/dist/smartdata.classes.dbtable.d.ts +++ /dev/null @@ -1,51 +0,0 @@ -import * as plugins from "./smartdata.plugins"; -import { Db } from "./smartdata.classes.db"; -import { DbDoc } from "./smartdata.classes.dbdoc"; -import { WriteResult } from "rethinkdb"; -export interface IFindOptions { - limit?: number; -} -/** - * - */ -export interface IDocValidationFunc { - (doc: T): boolean; -} -/** - * This is a decorator that will tell the decorated class what dbTable to use - * @param db - */ -export declare function Table(db: Db): (constructor: any) => void; -export declare class DbTable { - /** - * the collection that is used - */ - table: plugins.rethinkDb.Table; - objectValidation: IDocValidationFunc; - tableName: string; - db: Db; - constructor(collectedClassArg: T & DbDoc, dbArg: Db); - init(): Promise; - /** - * adds a validation function that all newly inserted and updated objects have to pass - */ - addDocValidation(funcArg: IDocValidationFunc): void; - /** - * finds an object in the DbCollection - */ - find(filterObject: any): Promise; - /** - * create an object in the database - */ - insert(dbDocArg: T & DbDoc): Promise; - /** - * inserts object into the DbCollection - */ - update(dbDocArg: T & DbDoc): Promise; - /** - * checks a Doc for constraints - * if this.objectValidation is not set it passes. - */ - private checkDoc(docArg); - extractKey(writeResult: WriteResult): void; -} diff --git a/dist/smartdata.classes.dbtable.js b/dist/smartdata.classes.dbtable.js deleted file mode 100644 index 5ba6bbb..0000000 --- a/dist/smartdata.classes.dbtable.js +++ /dev/null @@ -1,116 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const plugins = require("./smartdata.plugins"); -/** - * This is a decorator that will tell the decorated class what dbTable to use - * @param db - */ -function Table(db) { - return function (constructor) { - constructor["dbTable"] = new DbTable(constructor, db); - }; -} -exports.Table = Table; -class DbTable { - constructor(collectedClassArg, dbArg) { - this.objectValidation = null; - // tell the collection where it belongs - this.tableName = collectedClassArg.name; - this.db = dbArg; - // tell the db class about it (important since Db uses different systems under the hood) - this.db.addTable(this); - } - init() { - return __awaiter(this, void 0, void 0, function* () { - if (!this.table) { - // connect this instance to a RethinkDB table - const availableTables = yield plugins.rethinkDb - .db(this.db.dbName) - .tableList() - .run(this.db.dbConnection); - if (availableTables.indexOf(this.tableName)) { - yield plugins.rethinkDb - .db(this.db.dbName) - .tableCreate(this.tableName) - .run(this.db.dbConnection); - } - } - this.table = plugins.rethinkDb.table(this.tableName); - }); - } - /** - * adds a validation function that all newly inserted and updated objects have to pass - */ - addDocValidation(funcArg) { - this.objectValidation = funcArg; - } - /** - * finds an object in the DbCollection - */ - find(filterObject) { - return __awaiter(this, void 0, void 0, function* () { - yield this.init(); - let cursor = yield plugins.rethinkDb - .table(this.tableName) - .filter(filterObject) - .run(this.db.dbConnection); - return yield cursor.toArray(); - }); - } - /** - * create an object in the database - */ - insert(dbDocArg) { - return __awaiter(this, void 0, void 0, function* () { - yield this.init(); - yield this.checkDoc(dbDocArg); - return yield plugins.rethinkDb - .table(this.tableName) - .insert(dbDocArg.createSavableObject()) - .run(this.db.dbConnection); - }); - } - /** - * inserts object into the DbCollection - */ - update(dbDocArg) { - return __awaiter(this, void 0, void 0, function* () { - yield this.init(); - yield this.checkDoc(dbDocArg); - console.log(this.tableName, dbDocArg.createSavableObject()); - return yield plugins.rethinkDb - .table(this.tableName) - .update(dbDocArg.createSavableObject()) - .run(this.db.dbConnection); - }); - } - /** - * checks a Doc for constraints - * if this.objectValidation is not set it passes. - */ - checkDoc(docArg) { - let done = plugins.smartq.defer(); - let validationResult = true; - if (this.objectValidation) { - validationResult = this.objectValidation(docArg); - } - if (validationResult) { - done.resolve(); - } - else { - done.reject("validation of object did not pass"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3hDLElBQUksZ0JBQWdCLEdBQUcsSUFBSSxDQUFDO1FBQzVCLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7WUFDMUIsZ0JBQWdCLEdBQUcsSUFBSSxDQUFDLGdCQUFnQixDQUFDLE1BQU0sQ0FBQyxDQUFDO1FBQ25ELENBQUM7UUFDRCxFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7WUFDckIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ2pCLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLElBQUksQ0FBQyxNQUFNLENBQUMsbUNBQW1DLENBQUMsQ0FBQztRQUNuRCxDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDdEIsQ0FBQztJQUVELFVBQVUsQ0FBQyxXQUF3QixJQUFHLENBQUM7Q0FDeEM7QUFsR0QsMEJBa0dDIn0= \ No newline at end of file diff --git a/dist/smartdata.plugins.d.ts b/dist/smartdata.plugins.d.ts deleted file mode 100644 index e8cb1a7..0000000 --- a/dist/smartdata.plugins.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as assert from "assert"; -import * as beautylog from "beautylog"; -import * as lodash from "lodash"; -import * as rethinkDb from "rethinkdb"; -import * as smartq from "smartq"; -import * as smartstring from "smartstring"; -export { assert, beautylog, lodash, smartq, rethinkDb, smartstring }; diff --git a/dist/smartdata.plugins.js b/dist/smartdata.plugins.js deleted file mode 100644 index 4d09d8e..0000000 --- a/dist/smartdata.plugins.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const assert = require("assert"); -exports.assert = assert; -const beautylog = require("beautylog"); -exports.beautylog = beautylog; -const lodash = require("lodash"); -exports.lodash = lodash; -const rethinkDb = require("rethinkdb"); -exports.rethinkDb = rethinkDb; -const smartq = require("smartq"); -exports.smartq = smartq; -const smartstring = require("smartstring"); -exports.smartstring = smartstring; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGlDQUFpQztBQU94Qix3QkFBTTtBQU5mLHVDQUF1QztBQU10Qiw4QkFBUztBQUwxQixpQ0FBaUM7QUFLTCx3QkFBTTtBQUpsQyx1Q0FBdUM7QUFJSyw4QkFBUztBQUhyRCxpQ0FBaUM7QUFHRyx3QkFBTTtBQUYxQywyQ0FBMkM7QUFFWSxrQ0FBVyJ9 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 133a60d..9179118 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "smartdata", + "name": "@pushrocks/smartdata", "version": "3.0.1", "lockfileVersion": 1, "requires": true, @@ -14,6 +14,17 @@ "nan": "^2.9.2" } }, + "@gitzone/tsrun": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.2.tgz", + "integrity": "sha512-EqzaSd30hGC6wz8blC148nWQzdBFgvmbfAtjpaho7JXiPRaRsgDHv+iH8f2i6Xvpy1GWD0eXCUzwZoLoNvXkJA==", + "dev": true, + "requires": { + "smartfile": "^4.2.28", + "ts-node": "^7.0.0", + "typescript": "^2.9.1" + } + }, "@pushrocks/smartlog": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-1.0.6.tgz", @@ -78,17 +89,6 @@ "@types/node": "*" } }, - "@types/glob": { - "version": "5.0.35", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-5.0.35.tgz", - "integrity": "sha512-wc+VveszMLyMWFvXLkloixT4n0harUIVZjnpzztaZ0nKLuul7Z32iMt2fUFGAaZ4y1XWjFRMtCI5ewvyh4aIeg==", - "dev": true, - "requires": { - "@types/events": "*", - "@types/minimatch": "*", - "@types/node": "*" - } - }, "@types/lodash": { "version": "4.14.110", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.110.tgz", @@ -114,16 +114,6 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz", "integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q==" }, - "@types/shelljs": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.0.tgz", - "integrity": "sha512-vs1hCC8RxLHRu2bwumNyYRNrU3o8BtZhLysH5A4I98iYmA2APl6R3uNQb5ihl+WiwH0xdC9LLO+vRrXLs/Kyxg==", - "dev": true, - "requires": { - "@types/glob": "*", - "@types/node": "*" - } - }, "@types/vinyl": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@types/vinyl/-/vinyl-2.0.2.tgz", @@ -148,6 +138,12 @@ "sprintf-js": "~1.0.2" } }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -189,6 +185,12 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.9.tgz", "integrity": "sha512-IQX9/h7WdMBIW/q/++tGd+emQr0XMdeZ6icnT/74Xk9fnabWn+gZgpE+9V+gujL3hhJOoNrnDVY7tWdzc7NUTg==" }, + "buffer-from": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz", + "integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==", + "dev": true + }, "chai": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz", @@ -287,6 +289,12 @@ "object-keys": "^1.0.8" } }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, "early": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/early/-/early-2.1.1.tgz", @@ -427,12 +435,6 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, - "interpret": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.1.0.tgz", - "integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=", - "dev": true - }, "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", @@ -560,6 +562,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" }, + "make-error": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.4.tgz", + "integrity": "sha512-0Dab5btKVPhibSalc9QGXb559ED7G7iLjFXBaj9Wq8O3vorueR5K5jaE3hkG6ZQINyhA/JgG6Qk4qdFQjsYV6g==", + "dev": true + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -574,6 +582,23 @@ "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, "mongodb": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.1.1.tgz", @@ -638,12 +663,6 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, - "path-parse": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", - "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", - "dev": true - }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", @@ -703,15 +722,6 @@ "util-deprecate": "~1.0.1" } }, - "rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "dev": true, - "requires": { - "resolve": "^1.1.6" - } - }, "reflect-metadata": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.12.tgz", @@ -744,15 +754,6 @@ "semver": "^5.1.0" } }, - "resolve": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", - "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", - "dev": true, - "requires": { - "path-parse": "^1.0.5" - } - }, "resolve-from": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", @@ -783,17 +784,6 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, - "shelljs": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.2.tgz", - "integrity": "sha512-pRXeNrCA2Wd9itwhvLp5LZQvPJ0wU6bcjaTMywHHGX5XWhVN2nzSu7WV0q+oUY7mGK3mgSkDDzP3MgjqdyIgbQ==", - "dev": true, - "requires": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - } - }, "smartchai": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/smartchai/-/smartchai-2.0.1.tgz", @@ -876,6 +866,22 @@ "typings-global": "^1.0.20" } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.6.tgz", + "integrity": "sha512-N4KXEz7jcKqPf2b2vZF11lQIz9W5ZMuUcIOGj243lduidkf2fjkVKJS9vNxVWn3u/uxX38AcE8U9nnH9FPcq+g==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -942,12 +948,34 @@ "smartq": "^1.1.8" } }, + "ts-node": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.0.tgz", + "integrity": "sha512-klJsfswHP0FuOLsvBZ/zzCfUvakOSSxds78mVeK7I+qP76YWtxf16hEZsp3U+b0kIo82R5UatGFeblYMqabb2Q==", + "dev": true, + "requires": { + "arrify": "^1.0.0", + "buffer-from": "^1.1.0", + "diff": "^3.1.0", + "make-error": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "source-map-support": "^0.5.6", + "yn": "^2.0.0" + } + }, "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "typescript": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", + "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", + "dev": true + }, "typings-global": { "version": "1.0.28", "resolved": "https://registry.npmjs.org/typings-global/-/typings-global-1.0.28.tgz", @@ -1006,6 +1034,12 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true + }, + "yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "dev": true } } } diff --git a/package.json b/package.json index 6433187..9a518a0 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "main": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "test": "(npmts)", + "test": "tsrun test/test.ts", "testLocal": "(npmdocker)", - "build": "echo \"Not needed for now\"" + "build": "(npmts)" }, "repository": { "type": "git", @@ -32,15 +32,9 @@ "smartstring": "^2.0.28" }, "devDependencies": { + "@gitzone/tsrun": "^1.1.2", "@types/node": "^10.5.2", - "@types/shelljs": "^0.8.0", "qenv": "^1.1.7", - "shelljs": "^0.8.2", "tapbundle": "^2.0.2" - }, - "config": { - "commitizen": { - "path": "./node_modules/cz-conventional-changelog" - } } } diff --git a/test/test.ts b/test/test.ts index 69467db..365e068 100644 --- a/test/test.ts +++ b/test/test.ts @@ -5,7 +5,7 @@ import { Qenv } from 'qenv'; let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/'); // the tested module -import * as smartdata from '../ts/index'; +import * as smartdata from '../ts'; import { smartstring } from '../ts/smartdata.plugins'; // ======================================= @@ -15,7 +15,7 @@ import { smartstring } from '../ts/smartdata.plugins'; let testDb = new smartdata.SmartdataDb({ mongoDbName: process.env.MONGO_DBNAME, mongoDbUrl: process.env.MONGO_URL, - mongoPass: process.env.MONGO_PASS + mongoDbPass: process.env.MONGO_PASS }); tap.test('should establish a connection to the rethink Db cluster', async () => { @@ -30,8 +30,8 @@ tap.test('should establish a connection to the rethink Db cluster', async () => // Collections // ------ -@smartdata.Table(testDb) -class Car extends smartdata.smartDataDbDoc { +@smartdata.Collection(testDb) +class Car extends smartdata.SmartDataDbDoc { @smartdata.svDb() color: string; @smartdata.svDb() brand: string; constructor(colorArg: string, brandArg: string) { @@ -47,10 +47,10 @@ tap.test('should save the car to the db', async () => { }); tap.test('expect to get instance of Car', async () => { - let myCar = await Car.getInstances({ + let myCars = await Car.getInstances({ brand: 'Volvo' }); - expect(myCar[0].color).to.equal('red'); + expect(myCars[0].color).to.equal('red'); }); // ======================================= diff --git a/ts/index.ts b/ts/index.ts index 742edcb..5c717af 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,3 @@ export * from './smartdata.classes.db'; -export * from './smartdata.classes.dbtable'; -export * from './smartdata.classes.dbdoc'; +export * from './smartdata.classes.collection'; +export * from './smartdata.classes.doc'; diff --git a/ts/smartdata.classes.dbtable.ts b/ts/smartdata.classes.collection.ts similarity index 83% rename from ts/smartdata.classes.dbtable.ts rename to ts/smartdata.classes.collection.ts index 5e09e9c..8c9f9eb 100644 --- a/ts/smartdata.classes.dbtable.ts +++ b/ts/smartdata.classes.collection.ts @@ -1,6 +1,6 @@ import * as plugins from './smartdata.plugins'; import { SmartdataDb } from './smartdata.classes.db'; -import { smartDataDbDoc } from './smartdata.classes.dbdoc'; +import { SmartDataDbDoc } from './smartdata.classes.doc'; export interface IFindOptions { limit?: number; @@ -17,9 +17,9 @@ export interface IDocValidationFunc { * This is a decorator that will tell the decorated class what dbTable to use * @param db */ -export function Table(db: SmartdataDb) { +export function Collection(db: SmartdataDb) { return function(constructor) { - constructor['mongoDbCollection'] = new SmartdataCollection(constructor, db); + constructor['smartdataCollection'] = new SmartdataCollection(constructor, db); }; } @@ -32,7 +32,7 @@ export class SmartdataCollection { collectionName: string; smartdataDb: SmartdataDb; - constructor(collectedClassArg: T & smartDataDbDoc, smartDataDbArg: SmartdataDb) { + constructor(collectedClassArg: T & SmartDataDbDoc, smartDataDbArg: SmartdataDb) { // tell the collection where it belongs this.collectionName = collectedClassArg.name; this.smartdataDb = smartDataDbArg; @@ -55,6 +55,7 @@ export class SmartdataCollection { await this.smartdataDb.mongoDb.createCollection(this.collectionName); } this.mongoDbCollection = await this.smartdataDb.mongoDb.collection(this.collectionName); + console.log(`Successfully initiated Collection ${this.collectionName}`) } } @@ -70,15 +71,18 @@ export class SmartdataCollection { */ async find(filterObject: any): Promise { await this.init(); + const result = await this.mongoDbCollection.find(filterObject).toArray(); + return result; } /** * create an object in the database */ - async insert(dbDocArg: T & smartDataDbDoc): Promise { + async insert(dbDocArg: T & SmartDataDbDoc): Promise { await this.init(); await this.checkDoc(dbDocArg); const saveableObject = await dbDocArg.createSavableObject(); + console.log(saveableObject); const result = await this.mongoDbCollection.insertOne(saveableObject); return result; } @@ -86,7 +90,7 @@ export class SmartdataCollection { /** * inserts object into the DbCollection */ - async update(dbDocArg: T & smartDataDbDoc): Promise { + async update(dbDocArg: T & SmartDataDbDoc): Promise { await this.init(); await this.checkDoc(dbDocArg); const saveableObject = await dbDocArg.createSavableObject(); diff --git a/ts/smartdata.classes.db.ts b/ts/smartdata.classes.db.ts index b2e451e..63e1e01 100644 --- a/ts/smartdata.classes.db.ts +++ b/ts/smartdata.classes.db.ts @@ -1,7 +1,7 @@ import * as plugins from './smartdata.plugins'; import { Objectmap } from 'lik'; -import { SmartdataCollection } from './smartdata.classes.dbtable'; +import { SmartdataCollection } from './smartdata.classes.collection'; import * as mongoHelpers from './smartdata.mongohelpers'; @@ -48,19 +48,20 @@ export class SmartdataDb { let finalConnectionUrl = this.smartdataOptions.mongoDbUrl; if (this.smartdataOptions.mongoDbPass) { finalConnectionUrl = mongoHelpers.addPassword( - this.smartdataOptions.mongoDbName, + this.smartdataOptions.mongoDbUrl, this.smartdataOptions.mongoDbPass ); } + console.log(finalConnectionUrl); this.mongoDbClient = await plugins.mongodb.MongoClient.connect( finalConnectionUrl, - {} + { + useNewUrlParser: true + } ); this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName); this.status = 'connected'; - plugins.smartlog - .getDefaultLogger() - .info(`Connected to database ${this.smartdataOptions.mongoDbName}`); + console.log(`Connected to database ${this.smartdataOptions.mongoDbName}`); } /** diff --git a/ts/smartdata.classes.dbdoc.ts b/ts/smartdata.classes.doc.ts similarity index 82% rename from ts/smartdata.classes.dbdoc.ts rename to ts/smartdata.classes.doc.ts index 92e6a9c..b414fa6 100644 --- a/ts/smartdata.classes.dbdoc.ts +++ b/ts/smartdata.classes.doc.ts @@ -3,7 +3,7 @@ import * as plugins from './smartdata.plugins'; import { Objectmap } from 'lik'; import { SmartdataDb } from './smartdata.classes.db'; -import { SmartdataCollection } from './smartdata.classes.dbtable'; +import { SmartdataCollection } from './smartdata.classes.collection'; export type TDocCreation = 'db' | 'new' | 'mixed'; @@ -11,7 +11,7 @@ export type TDocCreation = 'db' | 'new' | 'mixed'; * saveable - saveable decorator to be used on class properties */ export function svDb() { - return (target: smartDataDbDoc, key: string) => { + return (target: SmartDataDbDoc, key: string) => { console.log('called sva'); if (!target.saveableProperties) { target.saveableProperties = []; @@ -20,7 +20,7 @@ export function svDb() { }; } -export class smartDataDbDoc { +export class SmartDataDbDoc { /** * the collection object an Doc belongs to */ @@ -51,13 +51,13 @@ export class smartDataDbDoc { */ constructor() { this.name = this.constructor['name']; - this.collection = this.constructor['dbTable']; + this.collection = this.constructor['smartdataCollection']; } static async getInstances(filterArg): Promise { let self: any = this; // fool typesystem - let referenceTable: SmartdataCollection = self.dbTable; - const foundDocs = await referenceTable.find(filterArg); + let referenceMongoDBCollection: SmartdataCollection = self.smartdataCollection; + const foundDocs = await referenceMongoDBCollection.find(filterArg); const returnArray = []; for (let item of foundDocs) { let newInstance = new this(); @@ -101,15 +101,15 @@ export class smartDataDbDoc { * also store any referenced objects to DB * better for data consistency */ - saveDeep(savedMapArg: Objectmap> = null) { + saveDeep(savedMapArg: Objectmap> = null) { if (!savedMapArg) { - savedMapArg = new Objectmap>(); + savedMapArg = new Objectmap>(); } savedMapArg.add(this); this.save(); for (let propertyKey in this) { let property: any = this[propertyKey]; - if (property instanceof smartDataDbDoc && !savedMapArg.checkForObject(property)) { + if (property instanceof SmartDataDbDoc && !savedMapArg.checkForObject(property)) { property.saveDeep(savedMapArg); } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..bcdbae1 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "target": "es2017", + "module": "commonjs" + } +} \ No newline at end of file