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

couch-init2

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couch-init2 - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0

lib/main.js

2

lib/couchdb_error.js

@@ -1,2 +0,2 @@

module.exports = async (res, context) => {
export async function couchdbError (res, context) {
const body = await res.text()

@@ -3,0 +3,0 @@ let errorText

@@ -1,6 +0,6 @@

const fetch = require('node-fetch')
const putSecurityDoc = require('./put_security_doc')
const syncDesignDocs = require('./sync_design_docs')
import fetch from 'node-fetch'
import { putSecurityDoc } from './put_security_doc.js'
import { syncDesignDocs } from './sync_design_docs.js'
module.exports = (couchdbHost, designDocFolder) => async dbData => {
export const InitDb = (couchdbHost, designDocFolder) => async dbData => {
const { name: dbName, designDocs } = dbData

@@ -12,3 +12,3 @@ const dbUrl = `${couchdbHost}/${dbName}`

syncDesignDocs(dbUrl, designDocs, designDocFolder),
putSecurityDoc(dbUrl, dbName)
putSecurityDoc(dbUrl, dbName),
])

@@ -15,0 +15,0 @@

@@ -1,8 +0,9 @@

const promiseProps = require('./promise_props')
import { InitDb } from './init_db.js'
import { objectPromise } from './promise_props.js'
module.exports = async (dbBaseUrl, dbsList, designDocFolder) => {
const initDb = require('./init_db')(dbBaseUrl, designDocFolder)
export async function initDbs (dbBaseUrl, dbsList, designDocFolder) {
const initDb = InitDb(dbBaseUrl, designDocFolder)
try {
const operations = await promiseProps(dbsList.reduce(aggregateInitDb(initDb), {}))
const operations = await objectPromise(dbsList.reduce(aggregateInitDb(initDb), {}))
return { ok: true, operations: minimzeOperationsReport(operations) }

@@ -16,3 +17,3 @@ } catch (err) {

}
}
};

@@ -19,0 +20,0 @@ const aggregateInitDb = initDb => (index, dbData) => {

@@ -1,2 +0,2 @@

module.exports = async obj => {
export async function objectPromise (obj) {
let key

@@ -19,2 +19,2 @@ const keys = []

return resultObj
}
};

@@ -1,5 +0,5 @@

const fetch = require('node-fetch')
const couchdbError = require('./couchdb_error')
import fetch from 'node-fetch'
import { couchdbError } from './couchdb_error.js'
module.exports = async (dbUrl, dbName) => {
export async function putSecurityDoc (dbUrl, dbName) {
const username = parseUsername(dbUrl)

@@ -11,3 +11,3 @@ const url = `${dbUrl}/_security`

method: 'PUT',
body: securityDoc(username)
body: securityDoc(username),
})

@@ -41,4 +41,4 @@

// Thus we just copy the admin there too to limit database access
members: { names: [ username ] }
members: { names: [ username ] },
})
}

@@ -1,9 +0,9 @@

const { readFile, writeFile } = require('fs').promises
const fetch = require('node-fetch')
const promiseProps = require('./promise_props')
const couchdbError = require('./couchdb_error')
import { readFile } from 'fs/promises'
import fetch from 'node-fetch'
import { couchdbError } from './couchdb_error.js'
import { objectPromise } from './promise_props.js'
// This verifies that the database design documents are up-to-date
// with the design docs files
module.exports = async (dbUrl, designDocsNames, designDocFolder) => {
export async function syncDesignDocs (dbUrl, designDocsNames, designDocFolder) {
const ops = {}

@@ -13,3 +13,3 @@ designDocsNames.forEach(designDocName => {

})
return promiseProps(ops)
return objectPromise(ops)
}

@@ -46,3 +46,3 @@

const designDocPath = `${designDocFolder}/${designDocName}.js`
let jsDesignDoc = require(designDocPath)
let { default: jsDesignDoc } = await import(designDocPath)
// Allow to pass just the view object

@@ -101,3 +101,3 @@ if (!jsDesignDoc._id) {

method: 'PUT',
body: JSON.stringify(update)
body: JSON.stringify(update),
})

@@ -112,7 +112,2 @@

const emtpyDesignDoc = designDocName => ({
_id: `_design/${designDocName}`,
language: 'javascript'
})
const removeSpaces = string => string.replace(/\s/g, '')

@@ -1,7 +0,10 @@

const fetch = require('node-fetch')
const { name: packageName } = require('../package.json')
const { yellow } = require('tiny-chalk')
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
import path from 'node:path'
import fetch from 'node-fetch'
import { yellow } from 'tiny-chalk'
import { getDirname, getJsonSync, wait } from './utils.js'
module.exports = dbBaseUrl => {
const dirname = getDirname(import.meta.url)
const { name: packageName } = getJsonSync(path.resolve(dirname, '../package.json'))
export function waitForCouchdb (dbBaseUrl) {
const testAvailability = async delay => {

@@ -8,0 +11,0 @@ await wait(delay)

{
"name": "couch-init2",
"version": "5.0.1",
"version": "6.0.0",
"type": "module",
"description": "Opiniated CouchDB databases initializer",
"main": "index.js",
"main": "lib/main.js",
"scripts": {
"lint": "eslint -c ./.eslintrc lib test",
"lint-fix": "eslint --fix -c ./.eslintrc lib test",
"test": "mocha",

@@ -12,3 +15,2 @@ "prepublishOnly": "npm test",

"files": [
"index.js",
"lib"

@@ -20,6 +22,11 @@ ],

"node-fetch": "^2.6.0",
"tiny-chalk": "^2.0.0"
"tiny-chalk": "^3.0.1"
},
"devDependencies": {
"config": "^1.26.2",
"config": "^3.3.8",
"eslint": "^8.31.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^9.1.3",

@@ -26,0 +33,0 @@ "should": "^13.2.3"

@@ -14,3 +14,6 @@ # couch-init2

```sh
# ESM
npm install couch-init2
# CommonJS
npm install couch-init2@5
```

@@ -21,4 +24,6 @@

```javascript
var dbUrl = 'http://username:password@localhost:5984'
var dbsList = [
import couchInit from 'couch-init2'
const dbUrl = 'http://username:password@localhost:5984'
const dbsList = [
{

@@ -40,13 +45,9 @@ name: 'dbname1',

// If a design doc file changed, the database design doc will be updated
var designDocFolder = '/path/to/your/design/docs/folder'
const designDocFolder = '/path/to/your/design/docs/folder'
couchInit(dbUrl, dbsList, designDocFolder)
// returns a promise
.then(res => {
console.log('ok', res.ok)
console.log('operations', res.operations)
// dbs were successfully initialized!
// time to start your server or whatever crazy thing you're building :)
})
.catch(err => { // handle the error })
const { ok, operations } = await couchInit(dbUrl, dbsList, designDocFolder)
console.log('ok', res.ok)
console.log('operations', res.operations)
// dbs were successfully initialized!
// time to start your server or whatever crazy thing you're building :)
```

@@ -72,3 +73,3 @@

```js
module.exports = {
export default {
byFoo: {

@@ -75,0 +76,0 @@ map: function (doc) {

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