Comparing version 0.1.0 to 0.1.1
@@ -1,1 +0,1 @@ | ||
{"filename":"/Users/yawetse/Developer/github/typesettin/other-projects/lowkie/example/sampledb.json","collections":[{"name":"kittens","data":[],"idIndex":[201,202,203,204,205,206,207],"binaryIndices":{},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"kittens","dirty":true,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableChangesApi":true,"autoupdate":false,"ttl":null,"maxId":207,"DynamicViews":[],"events":{"insert":[null],"update":[null],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[]}],"databaseVersion":1.1,"engineVersion":1.1,"autosave":false,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} | ||
{"filename":"/Users/yawetse/Developer/github/typesettin/lowkie/example/sampledb.json","collections":[{"name":"kittens","data":[],"idIndex":[201,202,208,209,210,211],"binaryIndices":{},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"kittens","dirty":true,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableChangesApi":true,"autoupdate":false,"ttl":null,"maxId":211,"DynamicViews":[],"events":{"insert":[null],"update":[null],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[]}],"databaseVersion":1.1,"engineVersion":1.1,"autosave":false,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"serializationMethod":"normal","destructureDelimiter":"$<\n"},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"} |
@@ -58,3 +58,2 @@ 'use strict'; | ||
}, | ||
all: { | ||
@@ -61,0 +60,0 @@ // LCOV coverage file (can be string, glob or array) |
@@ -7,42 +7,4 @@ 'use strict'; | ||
const lowkieProxyHandler = require('./lowkieProxyHandler'); | ||
/** | ||
* lowkie ORM singleton class | ||
* | ||
* @class lowkie | ||
*/ | ||
class lowkie { | ||
/** | ||
* Creates an instance of lowkie. | ||
* @param {any} [options={}] | ||
* | ||
* @memberOf lowkie | ||
*/ | ||
constructor(options = {}) { | ||
this.config = Object.assign({ | ||
adapterType: 'file', | ||
debug: false, | ||
strictSchemas: true, | ||
}, options); | ||
this.connections = new Map(); | ||
this.db = undefined; | ||
this.models = undefined; | ||
this.connection = new events.EventEmitter(); | ||
this.model = lowkieModel.bind(this); | ||
this.connect = lowkieConnect.bind(this); | ||
this.Schema.Types = lowkieSchema.Types; | ||
return new Proxy(this, lowkieProxyHandler.call(this)); | ||
} | ||
/** | ||
* creates lowkie schema, also includes helpers for document validations | ||
* | ||
* @param {object} scheme | ||
* @returns instance of lowkieSchema | ||
* | ||
* @memberOf lowkie | ||
*/ | ||
Schema(scheme) { | ||
return new lowkieSchema(scheme, this); | ||
} | ||
} | ||
const lowkieClass = require('./lowkieClass'); | ||
module.exports = new lowkie({}); | ||
module.exports = new lowkieClass({}); |
@@ -16,2 +16,3 @@ 'use strict'; | ||
if (!this.connections.size) throw new Error('There has to be an active lowkie connection before creating models, lowkie.connect is asynchronous'); | ||
if (!model || typeof model !=='string') throw new Error('model name must be a valid string'); | ||
if (!(Schema instanceof lowkieSchema)) throw new Error(`${model} must be an instance of a lowkieSchema`); | ||
@@ -22,3 +23,3 @@ let modelName = pluralize(model); | ||
? existingCollection | ||
: this.db.addCollection(modelName,collectionOptions); | ||
: this.db.addCollection(modelName, collectionOptions); | ||
let modelHandler = { | ||
@@ -32,3 +33,5 @@ /*get: function (target, name) {return target[ name ];},*/ | ||
}); | ||
return new Proxy(modelProxy, modelHandler); | ||
let newModelProxy = new Proxy(modelProxy, modelHandler); | ||
this.models[ modelName ] = newModelProxy; | ||
return newModelProxy; | ||
} catch (e) { | ||
@@ -35,0 +38,0 @@ if (this.debug) { |
@@ -17,3 +17,3 @@ 'use strict'; | ||
this.validNames.push('_id'); | ||
console.log(this.lowkie.config); | ||
// console.log(this.lowkie.config); | ||
// this.properties = properties; | ||
@@ -43,3 +43,3 @@ return this; | ||
result[ key ] = newDoc[ key ].toString(); | ||
} else if (typeof newDoc[ key ] === 'boolean' && this.scheme[ key ] === Boolean) { | ||
} else if (this.scheme[ key ] === Boolean) { | ||
result[ key ] = (newDoc[ key ]) ? true : false; | ||
@@ -66,3 +66,3 @@ } else if (this.scheme[ key ] === Number) { | ||
*/ | ||
insert(options) { | ||
insert(options = {}) { | ||
let lokiCollectionInsert = options.target; | ||
@@ -69,0 +69,0 @@ let lowkieInstance = options.thisArg; |
{ | ||
"name": "lowkie", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# lowkie | ||
# Lowkie | ||
[![Build Status](https://travis-ci.org/typesettin/lowkie.svg?branch=master)](https://travis-ci.org/typesettin/lowkie) [![NPM version](https://badge.fury.io/js/lowkie.svg)](http://badge.fury.io/js/lowkie) [![Coverage Status](https://coveralls.io/repos/github/typesettin/lowkie/badge.svg?branch=master)](https://coveralls.io/github/typesettin/lowkie?branch=master) [![Join the chat at https://gitter.im/typesettin/lowkie](https://badges.gitter.im/typesettin/lowkie.svg)](https://gitter.im/typesettin/lowkie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -7,2 +7,5 @@ | ||
<p style="text-align:center;"><img src="https://raw.githubusercontent.com/typesettin/lowkie/master/doc/lowkie.png" alt="Promisie Logo" width="300px" height="auto" style="margin:auto; text-align:center;"></p> | ||
### Installation | ||
@@ -120,3 +123,3 @@ ```sh | ||
$ grunt doc | ||
$ jsdoc2md lib/**/*.js utility/**/*.js index.js > doc/api.md | ||
$ jsdoc2md lib/**/*.js index.js > doc/api.md | ||
``` | ||
@@ -123,0 +126,0 @@ ### Notes |
'use strict'; | ||
/*jshint expr: true*/ | ||
const path = require('path'), | ||
// fs = require('fs-extra'), | ||
chai = require('chai'), | ||
expect = require('chai').expect; | ||
const path = require('path'); | ||
const events = require('events'); | ||
const chai = require('chai'); | ||
const expect = require('chai').expect; | ||
let lowkie = require('../../index'); | ||
let lowkieSchema = require('../../lib/schema'); | ||
let lowkieClass = require('../../lib/lowkieClass'); | ||
describe('lowkie', function () { | ||
describe('#indexOf()', function () { | ||
it('should return -1 when the value is not present', function () { | ||
expect([1, 2, 3].indexOf(5)).to.equal(-1 ); | ||
// should.equal(-1, [1, 2, 3].indexOf(0)); | ||
}); | ||
}); | ||
describe('Lowkie', function () { | ||
describe('Represents a singleton module', function () { | ||
it('should always reference the same instance of lowkie when required', function () { | ||
let lowkie2 = require('../../index'); | ||
expect(lowkie) | ||
.to.deep.equal(lowkie2) | ||
.and.to.be.an.instanceof(lowkieClass); | ||
}); | ||
it('should be implemented with configurable default settings', () => { | ||
expect(Object.keys(lowkie.config).length).to.be.greaterThan(0); | ||
}); | ||
it('should export schema types', () => { | ||
expect(lowkie.Schema.Types).to.be.an('object'); | ||
expect(lowkie.Schema.Types).to.have.property('String'); | ||
expect(lowkie.Schema.Types.String).to.deep.equal(String); | ||
expect(lowkie.Schema.Types).to.have.property('ObjectId'); | ||
}); | ||
it('should have connection that emit events', () => { | ||
expect(lowkie.connection).to.be.an.instanceof(events.EventEmitter); | ||
}); | ||
it('should expose a method for creating schemas', () => { | ||
let testUserSchema = { | ||
name: String, | ||
email: String, | ||
profile: { | ||
type: String, | ||
default: 'no profile', | ||
}, | ||
}; | ||
expect(lowkie.Schema).to.be.an.a('function'); | ||
expect(lowkie.Schema(testUserSchema)).to.be.an.an('object'); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2394782
72
37648
136
10
6