update
This commit is contained in:
parent
154dc5c1b3
commit
68c0ceeb14
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,3 +0,0 @@
|
|||||||
export * from './smartdata.classes.db';
|
|
||||||
export * from './smartdata.classes.dbcollection';
|
|
||||||
export * from './smartdata.classes.dbdoc';
|
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -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.dbcollection"));
|
|
||||||
__export(require("./smartdata.classes.dbdoc"));
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDRDQUFzQztBQUN0QyxzREFBZ0Q7QUFDaEQsK0NBQXlDIn0=
|
|
32
dist/smartdata.classes.db.d.ts
vendored
32
dist/smartdata.classes.db.d.ts
vendored
@ -1,32 +0,0 @@
|
|||||||
import * as plugins from './smartdata.plugins';
|
|
||||||
import { Objectmap } from 'lik';
|
|
||||||
import { DbCollection } from './smartdata.classes.dbcollection';
|
|
||||||
/**
|
|
||||||
* interface - indicates the connection status of the db
|
|
||||||
*/
|
|
||||||
export declare type TConnectionStatus = 'disconnected' | 'connected' | 'failed';
|
|
||||||
export declare class Db {
|
|
||||||
dbUrl: string;
|
|
||||||
db: plugins.mongodb.Db;
|
|
||||||
status: TConnectionStatus;
|
|
||||||
classCollections: Objectmap<DbCollection<any>>;
|
|
||||||
objectCollections: Objectmap<DbCollection<any>>;
|
|
||||||
constructor(dbUrlArg: string);
|
|
||||||
/**
|
|
||||||
* connects to the database that was specified during instance creation
|
|
||||||
*/
|
|
||||||
connect(): Promise<any>;
|
|
||||||
/**
|
|
||||||
* closes the connection to the databse
|
|
||||||
*/
|
|
||||||
close(): Promise<any>;
|
|
||||||
/**
|
|
||||||
* gets a class based collection by name: string
|
|
||||||
*/
|
|
||||||
getClassCollectionByName<T>(nameArg: string): Promise<DbCollection<T>>;
|
|
||||||
/**
|
|
||||||
* gets an object collection by name
|
|
||||||
*/
|
|
||||||
getObjectCollectionByName<T>(nameArg: string, dbArg: Db, makeNewArg?: boolean): Promise<DbCollection<T>>;
|
|
||||||
addCollection(dbCollectionArg: DbCollection<any>): void;
|
|
||||||
}
|
|
81
dist/smartdata.classes.db.js
vendored
81
dist/smartdata.classes.db.js
vendored
@ -1,81 +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");
|
|
||||||
const smartdata_classes_dbobjectdoc_1 = require("./smartdata.classes.dbobjectdoc");
|
|
||||||
class Db {
|
|
||||||
constructor(dbUrlArg) {
|
|
||||||
this.classCollections = new lik_1.Objectmap();
|
|
||||||
this.objectCollections = new lik_1.Objectmap();
|
|
||||||
this.dbUrl = dbUrlArg;
|
|
||||||
}
|
|
||||||
// basic connection stuff ----------------------------------------------
|
|
||||||
/**
|
|
||||||
* connects to the database that was specified during instance creation
|
|
||||||
*/
|
|
||||||
connect() {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
plugins.assert.equal(null, err);
|
|
||||||
this.db = db;
|
|
||||||
plugins.beautylog.success(`connected to database at ${this.dbUrl}`);
|
|
||||||
done.resolve(this.db);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* closes the connection to the databse
|
|
||||||
*/
|
|
||||||
close() {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
this.db.close();
|
|
||||||
plugins.beautylog.ok(`disconnected to database at ${this.dbUrl}`);
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
// advanced communication with the database --------------------------------
|
|
||||||
/**
|
|
||||||
* gets a class based collection by name: string
|
|
||||||
*/
|
|
||||||
getClassCollectionByName(nameArg) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let resultCollection = this.classCollections.find((dbCollectionArg) => {
|
|
||||||
return dbCollectionArg.name === nameArg;
|
|
||||||
});
|
|
||||||
return resultCollection;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets an object collection by name
|
|
||||||
*/
|
|
||||||
getObjectCollectionByName(nameArg, dbArg, makeNewArg = false) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let resultCollection = this.objectCollections.find((dbCollectionArg) => {
|
|
||||||
return dbCollectionArg.name === nameArg;
|
|
||||||
});
|
|
||||||
if (!resultCollection && makeNewArg) {
|
|
||||||
resultCollection = smartdata_classes_dbobjectdoc_1.getObjectDoc(nameArg, this).collection;
|
|
||||||
return resultCollection;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return resultCollection;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
addCollection(dbCollectionArg) {
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QUNqRSxNQUFNLENBQUMsZUFBZSxDQUFDLElBQUksS0FBSyxPQUFPLENBQUE7WUFDekMsQ0FBQyxDQUFDLENBQUE7WUFDRixFQUFFLENBQUMsQ0FBQyxDQUFDLGdCQUFnQixJQUFJLFVBQVUsQ0FBQyxDQUFDLENBQUM7Z0JBQ3BDLGdCQUFnQixHQUFHLDRDQUFZLENBQUMsT0FBTyxFQUFFLElBQUksQ0FBQyxDQUFDLFVBQVUsQ0FBQTtnQkFDekQsTUFBTSxDQUFDLGdCQUFnQixDQUFBO1lBQ3pCLENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDTixNQUFNLENBQUMsZ0JBQWdCLENBQUE7WUFDekIsQ0FBQztRQUNILENBQUM7S0FBQTtJQUVELGFBQWEsQ0FBRSxlQUFrQztRQUMvQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxDQUFBO0lBQzVDLENBQUM7Q0FFRjtBQXRFRCxnQkFzRUMifQ==
|
|
42
dist/smartdata.classes.dbcollection.d.ts
vendored
42
dist/smartdata.classes.dbcollection.d.ts
vendored
@ -1,42 +0,0 @@
|
|||||||
import * as plugins from './smartdata.plugins';
|
|
||||||
import { Db } from './smartdata.classes.db';
|
|
||||||
import { DbDoc } from './smartdata.classes.dbdoc';
|
|
||||||
export interface IFindOptions {
|
|
||||||
limit?: number;
|
|
||||||
}
|
|
||||||
export interface IDocValidation<T> {
|
|
||||||
(doc: T): boolean;
|
|
||||||
}
|
|
||||||
export declare function Collection(db: Db): (constructor: any) => void;
|
|
||||||
export declare class DbCollection<T> {
|
|
||||||
/**
|
|
||||||
* the collection that is used, defaults to mongodb collection,
|
|
||||||
* can be nedb datastore (sub api of mongodb)
|
|
||||||
*/
|
|
||||||
collection: plugins.mongodb.Collection;
|
|
||||||
collectedClass: T & DbDoc<T>;
|
|
||||||
objectValidation: IDocValidation<T>;
|
|
||||||
name: string;
|
|
||||||
db: Db;
|
|
||||||
constructor(collectedClassArg: T & DbDoc<T>, dbArg: Db);
|
|
||||||
/**
|
|
||||||
* adds a validation function that all newly inserted and updated objects have to pass
|
|
||||||
*/
|
|
||||||
addDocValidation(funcArg: IDocValidation<T>): void;
|
|
||||||
/**
|
|
||||||
* finds an object in the DbCollection
|
|
||||||
*/
|
|
||||||
find(docMatchArg: T | any, optionsArg?: IFindOptions): Promise<T[]>;
|
|
||||||
/**
|
|
||||||
* inserts object into the DbCollection
|
|
||||||
*/
|
|
||||||
insertOne(docArg: T): Promise<void>;
|
|
||||||
/**
|
|
||||||
* inserts many objects at once into the DbCollection
|
|
||||||
*/
|
|
||||||
insertMany(docArrayArg: T[]): Promise<void>;
|
|
||||||
/**
|
|
||||||
* checks a Doc for constraints
|
|
||||||
*/
|
|
||||||
private checkDoc(docArg);
|
|
||||||
}
|
|
95
dist/smartdata.classes.dbcollection.js
vendored
95
dist/smartdata.classes.dbcollection.js
vendored
@ -1,95 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const plugins = require("./smartdata.plugins");
|
|
||||||
function Collection(db) {
|
|
||||||
return function (constructor) {
|
|
||||||
constructor['dbCollection'] = new DbCollection(constructor, db);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
exports.Collection = Collection;
|
|
||||||
class DbCollection {
|
|
||||||
constructor(collectedClassArg, dbArg) {
|
|
||||||
this.objectValidation = null;
|
|
||||||
// tell the collection where it belongs
|
|
||||||
this.collectedClass = collectedClassArg;
|
|
||||||
this.name = collectedClassArg.name;
|
|
||||||
this.db = dbArg;
|
|
||||||
// make sure it actually exists
|
|
||||||
this.collection = dbArg.db.collection(this.name);
|
|
||||||
// tell the db class about it (important since Db uses different systems under the hood)
|
|
||||||
this.db.addCollection(this);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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(docMatchArg, optionsArg) {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
let findCursor = this.collection.find(docMatchArg);
|
|
||||||
if (optionsArg) {
|
|
||||||
if (optionsArg.limit) {
|
|
||||||
findCursor = findCursor.limit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
findCursor.toArray((err, docs) => {
|
|
||||||
if (err) {
|
|
||||||
done.reject(err);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
done.resolve(docs);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* inserts object into the DbCollection
|
|
||||||
*/
|
|
||||||
insertOne(docArg) {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
this.checkDoc(docArg).then(() => {
|
|
||||||
this.collection.insertOne(docArg)
|
|
||||||
.then(() => { done.resolve(); });
|
|
||||||
}, () => {
|
|
||||||
done.reject(new Error('one the docs did not pass validation'));
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* inserts many objects at once into the DbCollection
|
|
||||||
*/
|
|
||||||
insertMany(docArrayArg) {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
let checkDocPromiseArray = [];
|
|
||||||
for (let docArg of docArrayArg) {
|
|
||||||
checkDocPromiseArray.push(this.checkDoc(docArg));
|
|
||||||
}
|
|
||||||
Promise.all(checkDocPromiseArray).then(() => {
|
|
||||||
this.collection.insertMany(docArrayArg)
|
|
||||||
.then(() => { done.resolve(); });
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* checks a Doc for constraints
|
|
||||||
*/
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.DbCollection = DbCollection;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0NBQThDO0FBWTlDLG9CQUE0QixFQUFNO0lBQ2hDLE1BQU0sQ0FBQyxVQUFVLFdBQVc7UUFDMUIsV0FBVyxDQUFFLGNBQWMsQ0FBRSxHQUFHLElBQUksWUFBWSxDQUFDLFdBQVcsRUFBRSxFQUFFLENBQUMsQ0FBQTtJQUNuRSxDQUFDLENBQUE7QUFDSCxDQUFDO0FBSkQsZ0NBSUM7QUFFRDtJQVdFLFlBQWEsaUJBQStCLEVBQUUsS0FBUztRQUp2RCxxQkFBZ0IsR0FBc0IsSUFBSSxDQUFBO1FBS3hDLHVDQUF1QztRQUN2QyxJQUFJLENBQUMsY0FBYyxHQUFHLGlCQUFpQixDQUFBO1FBQ3ZDLElBQUksQ0FBQyxJQUFJLEdBQUcsaUJBQWlCLENBQUMsSUFBSSxDQUFBO1FBQ2xDLElBQUksQ0FBQyxFQUFFLEdBQUcsS0FBSyxDQUFBO1FBRWYsK0JBQStCO1FBQy9CLElBQUksQ0FBQyxVQUFVLEdBQUcsS0FBSyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1FBRWhELHdGQUF3RjtRQUN4RixJQUFJLENBQUMsRUFBRS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MsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNLLFFBQVEsQ0FBRSxNQUFTO1FBQ3pCLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDdkMsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUE7UUFDM0IsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQztZQUMxQixnQkFBZ0IsR0FBRyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsTUFBTSxDQUFDLENBQUE7UUFDbEQsQ0FBQztRQUNELEVBQUUsQ0FBQyxDQUFDLGdCQUFnQixDQUFDLENBQUMsQ0FBQztZQUNyQixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDaEIsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sSUFBSSxDQUFDLE1BQU0sQ0FBQyxtQ0FBbUMsQ0FBQyxDQUFBO1FBQ2xELENBQUM7UUFDRCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0NBQ0Y7QUFsR0Qsb0NBa0dDIn0=
|
|
39
dist/smartdata.classes.dbdoc.d.ts
vendored
39
dist/smartdata.classes.dbdoc.d.ts
vendored
@ -1,39 +0,0 @@
|
|||||||
import { Objectmap } from 'lik';
|
|
||||||
import { DbCollection } from './smartdata.classes.dbcollection';
|
|
||||||
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> {
|
|
||||||
/**
|
|
||||||
* the collection object an Doc belongs to
|
|
||||||
*/
|
|
||||||
collection: DbCollection<T>;
|
|
||||||
/**
|
|
||||||
* how the Doc in memory was created, may prove useful later.
|
|
||||||
*/
|
|
||||||
creationType: TDocCreation;
|
|
||||||
/**
|
|
||||||
* an array of saveable properties of a doc
|
|
||||||
*/
|
|
||||||
saveableProperties: string[];
|
|
||||||
/**
|
|
||||||
* name
|
|
||||||
*/
|
|
||||||
name: string;
|
|
||||||
/**
|
|
||||||
* class constructor
|
|
||||||
*/
|
|
||||||
constructor();
|
|
||||||
/**
|
|
||||||
* saves this instance but not any connected items
|
|
||||||
* may lead to data inconsistencies, but is faster
|
|
||||||
*/
|
|
||||||
save(): void;
|
|
||||||
/**
|
|
||||||
* also store any referenced objects to DB
|
|
||||||
* better for data consistency
|
|
||||||
*/
|
|
||||||
saveDeep(savedMapArg?: Objectmap<DbDoc<any>>): void;
|
|
||||||
}
|
|
61
dist/smartdata.classes.dbdoc.js
vendored
61
dist/smartdata.classes.dbdoc.js
vendored
@ -1,61 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
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() {
|
|
||||||
this.name = this.constructor['name'];
|
|
||||||
this.collection = this.constructor['dbCollection'];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* saves this instance but not any connected items
|
|
||||||
* may lead to data inconsistencies, but is faster
|
|
||||||
*/
|
|
||||||
save() {
|
|
||||||
let saveableObject = {}; // is not exposed to outside, so any is ok here
|
|
||||||
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(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.DbDoc = DbDoc;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLDZCQUErQjtBQU8vQjs7R0FFRztBQUNIO0lBQ0UsTUFBTSxDQUFDLENBQUMsTUFBa0IsRUFBRSxHQUFXO1FBQ3JDLE9BQU8sQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUE7UUFDekIsRUFBRSxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDO1lBQUMsTUFBTSxDQUFDLGtCQUFrQixHQUFHLEVBQUUsQ0FBQTtRQUFDLENBQUM7UUFDbEUsTUFBTSxDQUFDLGtCQU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FHLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDckIsSUFBSSxDQUFDLElBQUksRUFBRSxDQUFBO1FBQ1gsR0FBRyxDQUFDLENBQUMsSUFBSSxXQUFXLElBQUksSUFBSSxDQUFDLENBQUMsQ0FBQztZQUM3QixJQUFJLFFBQVEsR0FBRyxJQUFJLENBQUUsV0FBVyxDQUFFLENBQUE7WUFDbEMsRUFBRSxDQUFDLENBQUMsUUFBUSxZQUFZLEtBQUssSUFBSSxDQUFDLFdBQVcsQ0FBQyxjQUFjLENBQUMsUUFBUSxDQUFDLENBQUMsQ0FBQyxDQUFDO2dCQUN2RSxRQUFRLENBQUMsUUFBUSxDQUFDLFdBQVcsQ0FBQyxDQUFBO1lBQ2hDLENBQUM7UUFDSCxDQUFDO0lBQ0gsQ0FBQztDQUNGO0FBakVELHNCQWlFQyJ9
|
|
3
dist/smartdata.classes.dbobjectdoc.d.ts
vendored
3
dist/smartdata.classes.dbobjectdoc.d.ts
vendored
@ -1,3 +0,0 @@
|
|||||||
import { Db } from './smartdata.classes.db';
|
|
||||||
import { DbDoc } from './smartdata.classes.dbdoc';
|
|
||||||
export declare let getObjectDoc: (nameArg: any, dbArg: Db) => DbDoc<{}>;
|
|
11
dist/smartdata.classes.dbobjectdoc.js
vendored
11
dist/smartdata.classes.dbobjectdoc.js
vendored
@ -1,11 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const smartdata_classes_dbdoc_1 = require("./smartdata.classes.dbdoc");
|
|
||||||
const smartdata_classes_dbcollection_1 = require("./smartdata.classes.dbcollection");
|
|
||||||
exports.getObjectDoc = (nameArg, dbArg) => {
|
|
||||||
let objectDoc = new smartdata_classes_dbdoc_1.DbDoc();
|
|
||||||
objectDoc.name = nameArg;
|
|
||||||
objectDoc.collection = new smartdata_classes_dbcollection_1.DbCollection(objectDoc, dbArg);
|
|
||||||
return objectDoc;
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJvYmplY3Rkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYm9iamVjdGRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBLHVFQUFpRDtBQUNqRCxxRkFBK0Q7QUFFcEQsUUFBQSxZQUFZLEdBQUcsQ0FBQyxPQUFPLEVBQUMsS0FBUztJQUMxQyxJQUFJLFNBQVMsR0FBRyxJQUFJLCtCQUFLLEVBQUUsQ0FBQTtJQUMzQixTQUFTLENBQUMsSUFBSSxHQUFHLE9BQU8sQ0FBQTtJQUN4QixTQUFTLENBQUMsVUFBVSxHQUFHLElBQUksNkNBQVksQ0FBQyxTQUFTLEVBQUUsS0FBSyxDQUFDLENBQUE7SUFDekQsTUFBTSxDQUFDLFNBQVMsQ0FBQTtBQUNsQixDQUFDLENBQUEifQ==
|
|
7
dist/smartdata.plugins.d.ts
vendored
7
dist/smartdata.plugins.d.ts
vendored
@ -1,7 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
import * as assert from 'assert';
|
|
||||||
import * as beautylog from 'beautylog';
|
|
||||||
import * as lodash from 'lodash';
|
|
||||||
import * as mongodb from 'mongodb';
|
|
||||||
import * as smartq from 'smartq';
|
|
||||||
export { assert, beautylog, lodash, mongodb, smartq };
|
|
14
dist/smartdata.plugins.js
vendored
14
dist/smartdata.plugins.js
vendored
@ -1,14 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
const assert = require("assert");
|
|
||||||
exports.assert = assert;
|
|
||||||
const beautylog = require("beautylog");
|
|
||||||
exports.beautylog = beautylog;
|
|
||||||
const lodash = require("lodash");
|
|
||||||
exports.lodash = lodash;
|
|
||||||
const mongodb = require("mongodb");
|
|
||||||
exports.mongodb = mongodb;
|
|
||||||
const smartq = require("smartq");
|
|
||||||
exports.smartq = smartq;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QixpQ0FBZ0M7QUFPNUIsd0JBQU07QUFOVix1Q0FBc0M7QUFPbEMsOEJBQVM7QUFOYixpQ0FBZ0M7QUFPNUIsd0JBQU07QUFOVixtQ0FBa0M7QUFPOUIsMEJBQU87QUFOWCxpQ0FBZ0M7QUFPNUIsd0JBQU0ifQ==
|
|
Loading…
Reference in New Issue
Block a user