Roughing out the demo app

This commit is contained in:
Nate Taylor
2019-10-23 07:41:03 -05:00
parent 5bc58a2d40
commit 94be06d3c4
2841 changed files with 274065 additions and 2 deletions

37
node_modules/lodash-id/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,37 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history

4
node_modules/lodash-id/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,4 @@
language: node_js
node_js:
- "stable"
- "4"

20
node_modules/lodash-id/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 typicode
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

146
node_modules/lodash-id/README.md generated vendored Normal file
View File

@@ -0,0 +1,146 @@
# lodash-id [![Build Status](https://travis-ci.org/typicode/lodash-id.svg)](https://travis-ci.org/typicode/lodash-id) [![NPM version](https://badge.fury.io/js/lodash-id.svg)](http://badge.fury.io/js/lodash-id)
> `lodash-id` makes it easy to manipulate id-based resources with [lodash](https://lodash.com/) or [lowdb](https://github.com/typicode/lowdb)
* `getById`
* `insert`
* `upsert`
* `updateById`
* `updateWhere`
* `replaceById`
* `removeById`
* `removeWhere`
* `createId`
## Install
```bash
# with lodash
npm install lodash lodash-id --save
# with lowdb
npm install lowdb lodash-id --save
```
__Note__ `lodash-id` is also compatible with [underscore](http://underscorejs.org/)
## API
In the API examples, we're assuming `db` to be:
```js
const db = {
posts: [
{id: 1, body: 'one', published: false},
{id: 2, body: 'two', published: true}
],
comments: [
{id: 1, body: 'foo', postId: 1},
{id: 2, body: 'bar', postId: 2}
]
}
```
__getById(collection, id)__
Finds and returns document by id or undefined.
```js
const post = _.getById(db.posts, 1)
```
__insert(collection, document)__
Adds document to collection, sets an id and returns created document.
```js
const post = _.insert(db.posts, { body: 'New post' })
```
If the document already has an id, and it is the same as an existing document in the collection, an error is thrown.
```js
_.insert(db.posts, { id: 1, body: 'New post' })
_.insert(db.posts, { id: 1, title: 'New title' }) // Throws an error
```
__upsert(collection, document)__
Adds document to collection, sets an id and returns created document.
```js
const post = _.upsert(db.posts, { body: 'New post' })
```
If the document already has an id, it will be used to insert or replace.
```js
_.upsert(db.posts, { id: 1, body: 'New post' })
_.upsert(db.posts, { id: 1, title: 'New title' })
_.getById(db.posts, 1) // { id: 1, title: 'New title' }
```
__updateById(collection, id, attrs)__
Finds document by id, copies properties to it and returns updated document or undefined.
```js
const post = _.updateById(db.posts, 1, { body: 'Updated body' })
```
__updateWhere(collection, whereAttrs, attrs)__
Finds documents using `_.where`, updates documents and returns updated documents or an empty array.
```js
// Publish all unpublished posts
const posts = _.updateWhere(db.posts, { published: false }, { published: true })
```
__replaceById(collection, id, attrs)__
Finds document by id, replaces properties and returns document or undefined.
```js
const post = _.replaceById(db.posts, 1, { foo: 'bar' })
```
__removeById(collection, id)__
Removes document from collection and returns it or undefined.
```js
const comment = _.removeById(db.comments, 1)
```
__removeWhere(collection, whereAttrs)__
Removes documents from collection using `_.where` and returns removed documents or an empty array.
```js
const comments = _.removeWhere(db.comments, { postId: 1 })
```
__id__
Overwrite it if you want to use another id property.
```js
_.id = '_id'
```
__createId(collectionName, doc)__
Called by lodash-id when a document is inserted. Overwrite it if you want to change id generation algorithm.
```js
_.createId = (collectionName, item) => `${collectionName}-${item.prop}-${Date.now()}`
```
## Changelog
See details changes for each version in the [release notes](https://github.com/typicode/lodash-id/releases).
## License
MIT - [Typicode :cactus:](https://github.com/typicode)

76
node_modules/lodash-id/package.json generated vendored Normal file
View File

@@ -0,0 +1,76 @@
{
"_from": "lodash-id@^0.14.0",
"_id": "lodash-id@0.14.0",
"_inBundle": false,
"_integrity": "sha1-uvSJNOVDobXWNG+MhGmLGoyAOJY=",
"_location": "/lodash-id",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "lodash-id@^0.14.0",
"name": "lodash-id",
"escapedName": "lodash-id",
"rawSpec": "^0.14.0",
"saveSpec": null,
"fetchSpec": "^0.14.0"
},
"_requiredBy": [
"/json-server"
],
"_resolved": "https://registry.npmjs.org/lodash-id/-/lodash-id-0.14.0.tgz",
"_shasum": "baf48934e543a1b5d6346f8c84698b1a8c803896",
"_spec": "lodash-id@^0.14.0",
"_where": "/Users/nate/code/pluralsight/async-programming-promises/node_modules/json-server",
"author": {
"name": "Typicode",
"email": "typicode@gmail.com"
},
"bugs": {
"url": "https://github.com/typicode/lodash-id/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Use JavaScript objects as databases",
"devDependencies": {
"husky": "^0.11.8",
"lodash": "^4.6.1",
"mocha": "^3.2.0",
"pkg-ok": "^1.0.1",
"sinon": "~1.8.1",
"standard": "^8.6.0",
"underscore": "^1.8.3",
"webpack": "^2.2.1"
},
"engines": {
"node": ">= 4"
},
"homepage": "https://github.com/typicode/lodash-id#readme",
"keywords": [
"lodash",
"lowdb",
"underscore",
"id",
"resource",
"mixin"
],
"license": "MIT",
"main": "src/index.js",
"name": "lodash-id",
"repository": {
"type": "git",
"url": "git+https://github.com/typicode/lodash-id.git"
},
"scripts": {
"prepublish": "npm test",
"prepush": "npm test",
"test": "mocha && standard && pkg-ok"
},
"standard": {
"fix": true,
"env": {
"mocha": true
}
},
"version": "0.14.0"
}

126
node_modules/lodash-id/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
// UUID
// https://gist.github.com/LeverOne/1308368
/* jshint ignore:start */
function uuid (a, b) { for (b = a = ''; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-');return b }
/* jshint ignore:end */
module.exports = {
// Empties properties
__empty: function (doc) {
this.forEach(doc, function (value, key) {
delete doc[key]
})
},
// Copies properties from an object to another
__update: function (dest, src) {
this.forEach(src, function (value, key) {
dest[key] = value
})
},
// Removes an item from an array
__remove: function (array, item) {
var index = this.indexOf(array, item)
if (index !== -1) array.splice(index, 1)
},
__id: function () {
var id = this.id || 'id'
return id
},
getById: function (collection, id) {
var self = this
return this.find(collection, function (doc) {
if (self.has(doc, self.__id())) {
return doc[self.__id()].toString() === id.toString()
}
})
},
createId: function (collection, doc) {
return uuid()
},
insert: function (collection, doc) {
doc[this.__id()] = doc[this.__id()] || this.createId(collection, doc)
var d = this.getById(collection, doc[this.__id()])
if (d) throw new Error('Insert failed, duplicate id')
collection.push(doc)
return doc
},
upsert: function (collection, doc) {
if (doc[this.__id()]) {
// id is set
var d = this.getById(collection, doc[this.__id()])
if (d) {
// replace properties of existing object
this.__empty(d)
this.assign(d, doc)
} else {
// push new object
collection.push(doc)
}
} else {
// create id and push new object
doc[this.__id()] = this.createId(collection, doc)
collection.push(doc)
}
return doc
},
updateById: function (collection, id, attrs) {
var doc = this.getById(collection, id)
if (doc) {
this.assign(doc, attrs, {id: doc.id})
}
return doc
},
updateWhere: function (collection, predicate, attrs) {
var self = this
var docs = this.filter(collection, predicate)
docs.forEach(function (doc) {
self.assign(doc, attrs, {id: doc.id})
})
return docs
},
replaceById: function (collection, id, attrs) {
var doc = this.getById(collection, id)
if (doc) {
var docId = doc.id
this.__empty(doc)
this.assign(doc, attrs, {id: docId})
}
return doc
},
removeById: function (collection, id) {
var doc = this.getById(collection, id)
this.__remove(collection, doc)
return doc
},
removeWhere: function (collection, predicate) {
var self = this
var docs = this.filter(collection, predicate)
docs.forEach(function (doc) {
self.__remove(collection, doc)
})
return docs
}
}

236
node_modules/lodash-id/test/test.js generated vendored Normal file
View File

@@ -0,0 +1,236 @@
var assert = require('assert')
var _db = require('../src')
// Test lodash-id against Undersocre and Lo-Dash
var libs = {
underscore: require('underscore'),
lodash: require('lodash')
}
Object.keys(libs).forEach(function (name) {
describe(name + ' + lodash-id', function () {
var db
var _ = libs[name]
beforeEach(function () {
_.mixin(_db)
db = {
posts: [
{ id: 1, body: 'one', published: true },
{ id: 2, body: 'two', published: false },
{ id: 3, body: 'three', published: false }
],
comments: [
{ id: 1, body: 'foo', postId: 1 },
{ id: 2, body: 'bar', postId: 2 }
],
authors: [
{ id: '1', name: 'foo' },
{ id: '2', name: 'bar' }
]
}
})
describe('id', function () {
beforeEach(function () { _.id = 'body' })
afterEach(function () { delete _.id })
it('is the property used by get to find document', function () {
var expect = db.posts[0]
var doc = _.getById(db.posts, 'one')
assert.deepEqual(doc, expect)
})
})
describe('createId', function () {
it('returns an id', function () {
assert(_.createId())
})
})
describe('getById', function () {
it('returns doc by id', function () {
var expect = db.posts[0]
var doc = _.getById(db.posts, 1)
assert.deepEqual(doc, expect)
})
it('returns doc by id with string param', function () {
var expect = db.posts[0]
var doc = _.getById(db.posts, '1')
assert.deepEqual(doc, expect)
})
it('returns doc by id with string id', function () {
var expect = db.authors[0]
var doc = _.getById(db.authors, 1)
assert.deepEqual(doc, expect)
})
it('returns undefined if doc is not found', function () {
var doc = _.getById(db.posts, 9999)
assert.equal(doc, undefined)
})
})
describe('insert', function () {
describe('and id is set', function () {
it('inserts and returns inserted doc', function () {
var doc = _.insert(db.posts, { id: 'foo', body: 'one' })
assert.equal(db.posts.length, 4)
assert.deepEqual(doc, { id: 'foo', body: 'one' })
assert.deepEqual(_.getById(db.posts, doc.id), { id: 'foo', body: 'one' })
})
it('does not replace in place and throws an error', function () {
var length = db.posts.length
assert.throws(function () {
_.insert(db.posts, { id: 2, title: 'one' })
}, /duplicate/)
assert.equal(db.posts.length, length)
assert.deepEqual(_.getById(db.posts, 2), { id: 2, body: 'two', published: false })
assert.deepEqual(_.map(db.posts, 'id'), [ 1, 2, 3 ])
})
})
describe('and id is not set', function () {
it('inserts, sets an id and returns inserted doc', function () {
var doc = _.insert(db.posts, { body: 'one' })
assert.equal(db.posts.length, 4)
assert(doc.id)
assert.equal(doc.body, 'one')
})
})
})
describe('upsert', function () {
describe('and id is set', function () {
it('inserts and returns inserted doc', function () {
var doc = _.upsert(db.posts, { id: 'foo', body: 'one' })
assert.equal(db.posts.length, 4)
assert.deepEqual(doc, { id: 'foo', body: 'one' })
assert.deepEqual(_.getById(db.posts, doc.id), { id: 'foo', body: 'one' })
})
it('replaces in place and returns inserted doc', function () {
var length = db.posts.length
var doc = _.upsert(db.posts, {id: 2, title: 'one'})
assert.equal(db.posts.length, length)
assert.deepEqual(doc, { id: 2, title: 'one' })
assert.deepEqual(_.getById(db.posts, doc.id), { id: 2, title: 'one' })
assert.deepEqual(_.map(db.posts, 'id'), [1, 2, 3])
})
})
describe('and id is not set', function () {
it('inserts, sets an id and returns inserted doc', function () {
var doc = _.upsert(db.posts, {body: 'one'})
assert.equal(db.posts.length, 4)
assert(doc.id)
assert.equal(doc.body, 'one')
})
})
})
describe('updateById', function () {
it('updates doc and returns updated doc', function () {
var doc = _.updateById(db.posts, 1, { published: false })
assert(!db.posts[0].published)
assert(!doc.published)
})
it('keeps initial id type', function () {
var doc = _.updateById(db.posts, '1', { published: false })
assert.strictEqual(doc.id, 1)
})
it('returns undefined if doc is not found', function () {
var doc = _.updateById(db.posts, 9999, { published: false })
assert.equal(doc, undefined)
})
})
describe('updateWhere', function () {
it('updates docs and returns updated docs', function () {
var docs = _.updateWhere(db.posts, { published: false }, { published: true })
assert.equal(docs.length, 2)
assert(db.posts[1].published)
assert(db.posts[2].published)
})
it('returns an empty array if no docs match', function () {
var docs = _.updateWhere(db.posts, { published: 'draft' }, { published: true })
assert.equal(docs.length, 0)
})
})
describe('replaceById', function () {
it('replaces doc and returns it', function () {
var doc = _.replaceById(db.posts, 1, { foo: 'bar' })
assert.deepEqual(doc, db.posts[0])
assert.deepEqual(db.posts[0], { id: 1, foo: 'bar' })
})
it('keeps initial id type', function () {
var doc = _.replaceById(db.posts, '1', { published: false })
assert.strictEqual(doc.id, 1)
})
it('returns undefined if doc is not found', function () {
var doc = _.replaceById(db.posts, 9999, {})
assert.equal(doc, undefined)
})
})
describe('removeById', function () {
it('removes and returns doc ', function () {
var expected = db.posts[0]
var doc = _.removeById(db.posts, 1)
assert.equal(db.posts.length, 2)
assert.deepEqual(doc, expected)
})
it('returns undefined if doc is not found', function () {
var doc = _.removeById(db.posts, 9999)
assert.equal(doc, undefined)
})
})
describe('removeWhere', function () {
it('removes docs', function () {
var expected = [db.comments[0]]
var docs = _.removeWhere(db.comments, { postId: 1 })
assert.equal(db.comments.length, 1)
assert.deepEqual(docs, expected)
})
it('returns an empty array if no docs match', function () {
var docs = _.removeWhere(db.comments, { postId: 9999 })
assert.equal(docs.length, 0)
})
})
})
})