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

lowkie

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lowkie - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

dist/lowkie.js

350

Gruntfile.js
'use strict';
/*
* manuscript
* http://github.com/typesettin/manuscript
* lowkie
* http://github.com/typesettin/lowkie
*
* Copyright (c) 2014 Yaw Joseph Etse. All rights reserved.
* Copyright (c) 2017 Yaw Joseph Etse. All rights reserved.
*/
const path = require('path');
const Config = require('./app/lib/config');
const fs = require('fs-extra');
let config = new Config();
let themename = config.settings().theme;
let testPaths = [];
const testPaths = ['./test/**/*.js',];
if (typeof themename === 'string') {
try {
let themePath = path.join(__dirname, './content/themes/' + themename + '/test');
// console.log(themePath);
if (fs.existsSync(themePath)) {
let dirResults = fs.readdirSync(themePath);
if (Array.isArray(dirResults)) {
var themeTestPath = themePath + '/**/*.js';
testPaths.push(themeTestPath);
}
}
}
catch (e) {
console.log('Theme test path does not exist', e);
}
}
var periodicTestPath = path.join(__dirname, './test') + '/**/*.js';
testPaths.unshift(periodicTestPath);
module.exports = function (grunt) {
grunt.initConfig({
jsbeautifier: {
files: ['<%= jshint.all %>'],
options: {
config: '.jsbeautify'
}
},
mocha_istanbul: {
// coverage: {
// src: testPaths, // a folder works nicely
// options: {
// }
// },
// coverageSpecial: {
// src: ['testSpecial/*/*.js', 'testUnique/*/*.js'], // specifying file patterns works as well
// options: {
// coverageFolder: 'coverageSpecial',
// mask: '*.spec.js',
// mochaOptions: ['--harmony','--async-only'], // any extra options
// istanbulOptions: ['--harmony','--handle-sigint']
// }
// },
grunt.initConfig({
jsbeautifier: {
files: ['<%= jshint.all %>',],
options: {
config: '.jsbeautify',
},
},
mocha_istanbul: {
coveralls: {
src: testPaths, // multiple folders also works
options: {
coverageFolder: 'coverage', // will check both coverage folders and merge the coverage results
coverageFolder: 'coverage', // will check both coverage folders and merge the coverage results
coverage:true, // this will make the grunt.event.on('coverage') event listener to be triggered

@@ -68,8 +30,8 @@ check: {

functions: 5,
statements: 5
statements: 5,
},
// root: './lib', // define where the cover task should consider the root of libraries that are covered by tests
reportFormats: ['cobertura','lcovonly']
}
}
reportFormats: ['cobertura', 'lcovonly',],
},
},
},

@@ -84,190 +46,102 @@ istanbul_check_coverage: {

functions: 80,
statements: 80
}
}
}
statements: 80,
},
},
},
},
coveralls: {
// Options relevant to all targets
options: {
// When true, grunt-coveralls will only print a warning rather than
// an error, to prevent CI builds from failing unnecessarily (e.g. if
// coveralls.io is down). Optional, defaults to false.
force: false
},
options: {
// When true, grunt-coveralls will only print a warning rather than
// an error, to prevent CI builds from failing unnecessarily (e.g. if
// coveralls.io is down). Optional, defaults to false.
force: false,
},
all: {
// LCOV coverage file (can be string, glob or array)
src: 'coverage/*.info',
options: {
// Any options for just this target
}
},
},
simplemocha: {
options: {
globals: ['should', 'navigator','x'],
timeout: 3000,
ignoreLeaks: true,
ui: 'bdd',
reporter: 'spec'
},
all: {
src: testPaths
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'index.js',
'app/**/*.js',
'!app/doc/**/*.js',
'test/**/*.js',
'package.json',
'config/**/*.js'
]
},
jsdoc: {
dist: {
src: ['app/**/*.js', 'scripts/**/*.js', 'test/**/*.js', 'index.js'],
options: {
destination: 'doc/html',
configure: 'jsdoc.json'
}
}
},
browserify: {
dist: {
files: [{
expand: true,
cwd: 'scripts',
src: ['resources/js/*_src.js'],
dest: 'node_modules',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('_src', '_build');
finallocation = finallocation.replace('resources', 'public');
finallocation = path.resolve(finallocation);
return finallocation;
}
}],
options: {
transform: [
["babelify", {
presets: ["es2015"]
}]
]
},
},
extension_resources: {
files: [{
expand: true,
cwd: 'node_modules',
src: ['lowkie*/resources/js/*_src.js'],
dest: 'node_modules',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('_src', '_build');
finallocation = finallocation.replace('resources', 'public');
finallocation = path.resolve(finallocation);
return finallocation;
}
}],
options: {}
}
},
uglify: {
options: {
sourceMap: true,
compress: {
drop_console: false
}
},
all: {
files: [{
expand: true,
cwd: 'scripts',
src: ['public/js/*_build.js'],
dest: 'node_modules',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('_build', '.min');
finallocation = path.resolve(finallocation);
return finallocation;
}
}]
},
extension_resources: {
files: [{
expand: true,
cwd: 'node_modules',
src: ['lowkie*/public/js/*_build.js'],
dest: 'node_modules',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('_build', '.min');
finallocation = path.resolve(finallocation);
return finallocation;
}
}]
}
},
less: {
development: {
options: {
sourceMap: true,
yuicompress: true,
compress: true
},
files: {
'public/stylesheets/default/periodic.css': 'public/stylesheets/default/periodic.less'
}
}
},
copy: {
main: {
files: [{
expand: true,
cwd: 'node_modules',
src: ['lowkie*/public/**/*.*', '!**/node_modules/**/*.*'],
// src: ['**/public/**/*.*', '!**/public/**/*_build.js', '!**/node_modules/**/*.*'],
dest: 'public/extensions/',
rename: function (dest, src) {
var finallocation = path.join(dest, src.replace('public', ''));
// finallocation = finallocation;
finallocation = path.resolve(finallocation);
// console.log("dest", dest, "src", src, "finallocation", finallocation);
return finallocation;
}
}]
}
},
watch: {
options: {
interrupt: true
},
css: {
files: ['public/stylesheets/**/*.less'],
tasks: ['newer:less']
},
js: {
files: ['<%= jshint.all %>'],
tasks: ['newer:simplemocha:all', 'newer:jshint:all', 'newer:jsbeautifier', 'newer:browserify', 'newer:uglify:all', 'newer:copy:main', 'doc']
}
}
});
all: {
// LCOV coverage file (can be string, glob or array)
src: 'coverage/*.info',
options: {
// Any options for just this target
},
},
},
simplemocha: {
options: {
globals: ['should', 'navigator', 'x',],
timeout: 3000,
ignoreLeaks: true,
ui: 'bdd',
reporter: 'spec',
},
all: {
src: testPaths,
},
},
jsdoc: {
dist: {
src: ['lib/**/*.js', 'index.js',],
options: {
destination: 'doc/html',
configure: 'jsdoc.json',
},
},
},
browserify: {
dist: {
files: [ {
expand: true,
// cwd: 'scripts',
src: [ 'index.js', ],
dest: './dist',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('index.js', 'lowkie.js');
// finallocation = finallocation.replace('resources', 'public');
finallocation = path.resolve(finallocation);
return finallocation;
},
}, ],
options: {
transform: [
[ 'babelify', {
presets: [ 'es2015', 'es2016', 'es2017', ],
}, ],
],
},
},
},
uglify: {
options: {
sourceMap: true,
compress: {
drop_console: false,
},
},
all: {
files: [{
expand: true,
// cwd: 'scripts',
src: ['dist/lowkie.js',],
dest: './dist',
rename: function (dest, src) {
var finallocation = path.join(dest, src);
finallocation = finallocation.replace('lowkie.js', 'lowkie.min.js');
finallocation = path.resolve(finallocation);
return finallocation;
},
},],
},
},
});
// Loading dependencies
for (var key in grunt.file.readJSON('package.json').devDependencies) {
if (key.indexOf('grunt') === 0 && key !== 'grunt') {
grunt.loadNpmTasks(key);
}
}
grunt.registerTask('doc', 'jsdoc');
grunt.registerTask('test', 'mocha_istanbul');
grunt.registerTask('lint', 'jshint');
grunt.registerTask('default', ['lint', 'browserify', 'doc', 'uglify', 'test', 'less']);
// Loading dependencies
for (var key in grunt.file.readJSON('package.json').devDependencies) {
if (key.indexOf('grunt') === 0 && key !== 'grunt') {
grunt.loadNpmTasks(key);
}
}
grunt.registerTask('doc', 'jsdoc');
grunt.registerTask('test', 'mocha_istanbul');
grunt.registerTask('default', [/*'lint',*/'test', 'browserify', 'doc', 'uglify', ]);
};
'use strict';
require('babel-polyfill');
require('proxy-polyfill');
module.exports = require('./lib/lowkie');

@@ -10,3 +10,3 @@ 'use strict';

* @param {class} Schema instance of lokieSchema
* @returns
* @returns Proxy
*/

@@ -13,0 +13,0 @@ function model(model, Schema, collectionOptions = {}) {

'use strict';
const crypto = require('crypto');
/**
* helper class for generating Ids
*
* @class ObjectId
*/
class ObjectId{
/**
* generates a unique ID
*
* @static
*
* @memberOf ObjectId
*/
static createId() {

@@ -6,0 +18,0 @@ let _id = crypto.createHash('md5').update(`${new Date().valueOf}${Math.random()}`).digest('hex');

@@ -21,5 +21,10 @@ 'use strict';

}
// getValidNames(scheme) {
// }
/**
* returns validated document for lokijs
*
* @param {any} doc
* @returns object
*
* @memberOf lowkieSchema
*/
createDocument(doc) {

@@ -52,2 +57,10 @@ let newDoc = Object.assign({

}
/**
* overwrites the default insert method
*
* @param {any} options
* @returns Promise
*
* @memberOf lowkieSchema
*/
insert(options) {

@@ -75,2 +88,5 @@ let lokiCollectionInsert = options.target;

/**
* schema data types
*/
lowkieSchema.Types = {

@@ -77,0 +93,0 @@ String,

{
"name": "lowkie",
"version": "0.0.2",
"version": "0.1.0",
"license": "MIT",

@@ -43,5 +43,7 @@ "main": "index.js",

"dependencies": {
"babel-polyfill": "^6.23.0",
"flat": "^2.0.1",
"fs-extra": "^2.1.2",
"lokijs": "^1.4.3",
"proxy-polyfill": "0.1.6",
"pluralize": "^4.0.0"

@@ -51,3 +53,7 @@ },

"devDependencies": {
"babel": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2016": "^6.22.0",
"babel-preset-es2017": "^6.22.0",
"babelify": "7.3.0",

@@ -76,5 +82,2 @@ "browserify": "^13.0.0",

"mocha-lcov-reporter": "^1.2.0",
"node-mocks-http": "^1.5.0",
"pow-mongodb-fixtures": "^0.13.0",
"proxy-polyfill": "0.1.6",
"sinon": "^1.17.4",

@@ -81,0 +84,0 @@ "sinon-chai": "^2.8.0",

# lowkie
ORM for Lokijs
[![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)
### Description
Lowkie is a lokijs object modeling tool designed to work in an asynchronous environment.
### Installation
```sh
$ npm i lowkie
```
### [Full Documentation](https://github.com/typesettin/lowkie/blob/master/doc/api.md)
### Usage (basic)
```javascript
//lowkie singleton
const lowkie = require('lowkie');
//connect to lowkie (includes loki connection configuration), options can include other loki adapters besides structured file adapters
lowkie.connect(path.join(__dirname, './sampledb.json'),options)
.then((db) => {
console.log('connected db');
})
.catch(e => {
console.log('connection error', e);
});
//listen for connection errors
lowkie.connection.on('connectionError', (e)=>{
console.log('error connecting to the db',e);
});
//listen for connecting status, dbname is the path to the db json file
lowkie.connection.on('connecting', (dbname, options)=>{
console.log('now trying to connect to db');
});
//once connected, create models, query the db, etc
lowkie.connection.once('connected', (db, options)=>{
console.log('now connected to db');
//create a new schema
const UserSchema = lowkie.Schema({
email:String,
username:String,
age:Number,
});
//register db models, each model is a proxied loki collection with additional helpers
const User = lowkie.model('User',UserSchema);
//write data to db
User.insert({
email:'test@domain.com',
username:'testuser',
age:30,
invalidProp:'whatever', //removes invalid schema props on creates
})
.then(newuser => {
//created db
/*
{
"_id":"fbd8080a9272ecaa15d1bb6d0f4b3314",
"email":"test@domain.com",
"username":"testuser",
"age":30,
"meta":{
"revision":0,
"created":1490576236063,
"version":0
},
"$loki":201
}
*/
console.log({ newuser });
})
.catch(e => {
console.log(e);
});
//insert multiple documents
User.insert([
{
email:'john@domain.com',
username:'jsmith',
age:37,
},
{
email:'jane@domain.com',
username:'jdoe',
age:45,
},
{
email:'chris@domain.com',
username:'clane',
age:17,
},
])
.then((newusers)=>{
console.log(newusers);
})
.catch(e =>{
console.log(e);
})
//query loki for data
let userQueryResults = User.find({ id: { '$gte': 1 } });
console.log({userQueryResults}) //result of user query
});
```
### Development
*Make sure you have grunt installed*
```sh
$ npm i -g grunt-cli jsdoc-to-markdown
```
For generating documentation
```sh
$ grunt doc
$ jsdoc2md lib/**/*.js utility/**/*.js index.js > doc/api.md
```
### Notes
* Check out [https://github.com/typesettin/lowkie](https://github.com/typesettin/lowkie) for the full Lowkie Documentation
### Testing
```sh
$ npm i
$ grunt test
```
### Contributing
License
----
MIT

Sorry, the diff of this file is not supported yet

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