Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
d504e90e47 | |||
7079340657 | |||
63ceded1b8 | |||
b45e7ee206 | |||
715709f3ec | |||
0b8adea736 | |||
90d9a25b3f | |||
e49811eecd | |||
9cbdf317dc | |||
d55339013a |
22
README.md
22
README.md
@ -2,12 +2,28 @@
|
|||||||
|
|
||||||
> Note: Still in Beta
|
> Note: Still in Beta
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/smartdata)
|
||||||
|
[](https://gitlab.com/pushrocks/smartdata)
|
||||||
|
[](https://github.com/pushrocks/smartdata)
|
||||||
|
[](https://pushrocks.gitlab.io/smartdata/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartdata/commits/master)
|
||||||
|
[](https://gitlab.com/pushrocks/smartdata/commits/master)
|
||||||
|
[](https://david-dm.org/pushrocks/smartdata)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartdata/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartdata)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
smartdata is an ODM that adheres to TypeScript practices and uses classes to organize data.
|
smartdata is an ODM that adheres to TypeScript practices and uses classes to organize data.
|
||||||
It uses MongoDB or NeDb as persistent storage.
|
It uses MongoDB or NeDb as persistent storage.
|
||||||
|
|
||||||
## Intention
|
## Intention
|
||||||
There are many ODMs out there, however when we searched for an ODM that uses TypeScript,
|
There are many ODMs out there, however when we searched for an ODM that uses TypeScript,
|
||||||
acts smart while still embracing an the NoSQL idea... we didn't find a matching solution.
|
acts smart while still embracing the NoSQL idea we didn't find a matching solution.
|
||||||
This is why we started smartdata.
|
This is why we started smartdata.
|
||||||
|
|
||||||
How MongoDB terms map to smartdata classes
|
How MongoDB terms map to smartdata classes
|
||||||
@ -47,8 +63,8 @@ So to get to get access to a specific collection you document
|
|||||||
|
|
||||||
@Collection(myDb1)
|
@Collection(myDb1)
|
||||||
class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
|
class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
|
||||||
property1:string
|
@smartdata.svDb() property1: string // @smartdata.svDb() marks the property for db save
|
||||||
property2:number
|
property2: number // this one is not marked, so it won't be save upon calling this.save()
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
property1: string,
|
property1: string,
|
||||||
property2: number
|
property2: number
|
||||||
|
27
dist/smartdata.classes.dbdoc.d.ts
vendored
27
dist/smartdata.classes.dbdoc.d.ts
vendored
@ -1,9 +1,34 @@
|
|||||||
import { DbCollection } from './smartdata.classes.dbcollection';
|
import { DbCollection } from './smartdata.classes.dbcollection';
|
||||||
export declare type TDocCreation = 'db' | 'data' | 'mixed';
|
export declare type TDocCreation = 'db' | 'new' | 'mixed';
|
||||||
|
/**
|
||||||
|
* saveable - saveable decorator to be used on class properties
|
||||||
|
*/
|
||||||
|
export declare function svDb(): (target: DbDoc<any>, key: string) => void;
|
||||||
export declare class DbDoc<T> {
|
export declare class DbDoc<T> {
|
||||||
|
/**
|
||||||
|
* the collection object an Doc belongs to
|
||||||
|
*/
|
||||||
collection: DbCollection<T>;
|
collection: DbCollection<T>;
|
||||||
|
/**
|
||||||
|
* how the Doc in memory was created, may prove useful later.
|
||||||
|
*/
|
||||||
creationType: TDocCreation;
|
creationType: TDocCreation;
|
||||||
|
/**
|
||||||
|
* an array of saveable properties of a doc
|
||||||
|
*/
|
||||||
|
saveableProperties: string[];
|
||||||
|
/**
|
||||||
|
* class constructor
|
||||||
|
*/
|
||||||
constructor();
|
constructor();
|
||||||
|
/**
|
||||||
|
* saves this instance but not any connected items
|
||||||
|
* may lead to data inconsistencies, but is faster
|
||||||
|
*/
|
||||||
save(): void;
|
save(): void;
|
||||||
|
/**
|
||||||
|
* also store any referenced objects to DB
|
||||||
|
* better for data consistency
|
||||||
|
*/
|
||||||
saveDeep(): void;
|
saveDeep(): void;
|
||||||
}
|
}
|
||||||
|
38
dist/smartdata.classes.dbdoc.js
vendored
38
dist/smartdata.classes.dbdoc.js
vendored
@ -1,12 +1,48 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
/**
|
||||||
|
* 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 DbDoc {
|
||||||
|
/**
|
||||||
|
* class constructor
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.collection = this.constructor['dbCollection'];
|
this.collection = this.constructor['dbCollection'];
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* saves this instance but not any connected items
|
||||||
|
* may lead to data inconsistencies, but is faster
|
||||||
|
*/
|
||||||
save() {
|
save() {
|
||||||
|
let saveableObject = {};
|
||||||
|
for (let propertyNameString of this.saveableProperties) {
|
||||||
|
saveableObject[propertyNameString] = this[propertyNameString];
|
||||||
}
|
}
|
||||||
|
switch (this.creationType) {
|
||||||
|
case 'db':
|
||||||
|
this.collection; // TODO implement collection.update()
|
||||||
|
break;
|
||||||
|
case 'new':
|
||||||
|
this.collection.insertOne(saveableObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* also store any referenced objects to DB
|
||||||
|
* better for data consistency
|
||||||
|
*/
|
||||||
saveDeep() {
|
saveDeep() {
|
||||||
|
this.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.DbDoc = DbDoc;
|
exports.DbDoc = DbDoc;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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JQUN0RCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsSUFBSTtRQUNBLElBQUksY0FBYyxHQUFHLEVBQUUsQ0FBQTtRQUN2QixHQUFHLENBQUMsQ0FBQyxJQUFJLGtCQUFrQixJQUFJLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7WUFDckQsY0FBYyxDQUFDLGtCQUFrQixDQUFDLEdBQUcsSUFBSSxDQUFDLGtCQUFrQixDQUFDLENBQUE7UUFDakUsQ0FBQztRQUNELE1BQU0sQ0FBQyxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQyxDQUFDO1lBQ3hCLEtBQUssSUFBSTtnQkFDTCxJQUFJLENBQUMsVUFBVSxDQUFBLENBQUMscUNBQXFDO2dCQUNyRCxLQUFLLENBQUE7WUFDVCxLQUFLLEtBQUs7Z0JBQ04sSUFBSSxDQUFDLFVBQVUsQ0FBQyxTQUFTLENBQUMsY0FBYyxDQUFDLENBQUE7UUFDakQsQ0FBQztJQUNMLENBQUM7SUFFRDs7O09BR0c7SUFDSCxRQUFRO1FBQ0osSUFBSSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ2YsQ0FBQztDQUNKO0FBakRELHNCQWlEQyJ9
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "smartdata",
|
"name": "smartdata",
|
||||||
"version": "1.0.17",
|
"version": "1.0.22",
|
||||||
"description": "do more with data",
|
"description": "do more with data",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
File diff suppressed because one or more lines are too long
@ -72,6 +72,7 @@ describe('smartdata', function () {
|
|||||||
it('should create an extended class', function () {
|
it('should create an extended class', function () {
|
||||||
@smartdata.Collection(testDb)
|
@smartdata.Collection(testDb)
|
||||||
class TestCar extends smartdata.DbDoc<TestCar> {
|
class TestCar extends smartdata.DbDoc<TestCar> {
|
||||||
|
@smartdata.svDb()
|
||||||
color: string
|
color: string
|
||||||
constructor(optionsArg: {
|
constructor(optionsArg: {
|
||||||
color: string,
|
color: string,
|
||||||
@ -85,6 +86,8 @@ describe('smartdata', function () {
|
|||||||
color: 'red',
|
color: 'red',
|
||||||
property2: 2
|
property2: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
should(testCarInstance.saveableProperties[0]).equal('color')
|
||||||
console.log(TestCar)
|
console.log(TestCar)
|
||||||
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection)
|
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection)
|
||||||
should(testCarInstance).be.instanceof(smartdata.DbDoc)
|
should(testCarInstance).be.instanceof(smartdata.DbDoc)
|
||||||
|
@ -3,19 +3,66 @@ import * as plugins from './smartdata.plugins'
|
|||||||
import { Db } from './smartdata.classes.db'
|
import { Db } from './smartdata.classes.db'
|
||||||
import { DbCollection } from './smartdata.classes.dbcollection'
|
import { DbCollection } from './smartdata.classes.dbcollection'
|
||||||
|
|
||||||
export type TDocCreation = 'db' | 'data' | 'mixed'
|
export type TDocCreation = 'db' | 'new' | 'mixed'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveable - saveable decorator to be used on class properties
|
||||||
|
*/
|
||||||
|
export function svDb() {
|
||||||
|
return (target: DbDoc<any>, key: string) => {
|
||||||
|
console.log('called sva')
|
||||||
|
if (!target.saveableProperties) { target.saveableProperties = [] }
|
||||||
|
target.saveableProperties.push(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DbDoc<T> {
|
export class DbDoc<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the collection object an Doc belongs to
|
||||||
|
*/
|
||||||
collection: DbCollection<T>
|
collection: DbCollection<T>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* how the Doc in memory was created, may prove useful later.
|
||||||
|
*/
|
||||||
creationType: TDocCreation
|
creationType: TDocCreation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* an array of saveable properties of a doc
|
||||||
|
*/
|
||||||
|
saveableProperties: string[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class constructor
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.collection = this.constructor['dbCollection']
|
this.collection = this.constructor['dbCollection']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves this instance but not any connected items
|
||||||
|
* may lead to data inconsistencies, but is faster
|
||||||
|
*/
|
||||||
save() {
|
save() {
|
||||||
|
let saveableObject = {}
|
||||||
|
for (let propertyNameString of this.saveableProperties) {
|
||||||
|
saveableObject[propertyNameString] = this[propertyNameString]
|
||||||
}
|
}
|
||||||
|
switch (this.creationType) {
|
||||||
|
case 'db':
|
||||||
|
this.collection // TODO implement collection.update()
|
||||||
|
break
|
||||||
|
case 'new':
|
||||||
|
this.collection.insertOne(saveableObject)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* also store any referenced objects to DB
|
||||||
|
* better for data consistency
|
||||||
|
*/
|
||||||
saveDeep() {
|
saveDeep() {
|
||||||
|
this.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
tsconfig.json
Normal file
5
tsconfig.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user